Add orchestrator_guidance field to the gate response — a computed plain-language string that tells the orchestrator what to do next based on score trajectory, flag quality, and loop state. Then rewrite instructions.md from 174 lines to ~70 by removing the manual interpretation guidance that orchestrator_guidance replaces. Keep overrides, replan, commands sections.
User notes and answers:
Context from prior planning:
build_orchestrator_guidance() is a pure function in evaluation.py, no LLM call. Takes gate signals + state, returns a plain-language string.
Logic (first match wins): first iteration -> follow gate; PROCEED+passed -> proceed to execute; PROCEED+failed -> fix preflight; ESCALATE+auto-force conditions -> give exact override command; ESCALATE otherwise -> ask user; ITERATE+plateaued -> suggest force-proceed with investigation hint; ITERATE+improving -> continue; ITERATE+worsening -> warn.
Append contextual investigation hints: unresolved flags -> verify against plan/code; recurring critiques -> loop cant fix these; scope creep -> compare against original idea.
Wire into handle_gate() and build_gate_artifact(). Include in gate response.
Rewrite instructions.md to ~70 lines. Remove: 9 signal field definitions, 5 judgment bullets, 5 file paths, 3 conditional rules, per-step descriptions. Keep: triage, init, gate principle (you can investigate and override), replan, overrides, commands.
The key principle: the gate response tells the orchestrator what to do. The instructions just say follow it unless you disagree after investigating.
Answers: 1. Yes, auto-force only uses robustness==light and weighted_score<=4.0. suggested_override was from the old evaluate system and doesnt exist in gate. 2. Only after gate. Revise just shows delta/flags and loops back to critique->gate where fresh guidance is generated.
code
Approved plan:
Implementation Plan: orchestrator_guidance Field + Instructions Rewrite
Overview
Add a computed orchestrator_guidance string to the gate response that tells the orchestrator exactly what to do next. Then slim instructions.md from ~174 lines to ~70 by removing the manual interpretation guidance that orchestrator_guidance replaces.
Assistant
Step 1: Add build_orchestrator_guidance() to evaluation.py
Pure function, no LLM call. Signature:
python
def build_orchestrator_guidance(
gate_payload: dict, # recommendation, rationale, signals_assessment
signals: dict, # the signals dict from build_gate_signals
preflight_passed: bool,
preflight_results: dict, # {check_name: bool} — for listing failing checks
robustness: str,
plan_name: str, # for exact override commands
) -> str:
Pass orchestrator_guidance=guidance to build_gate_artifact()
_override_force_proceed() changes (line ~990):
Call build_orchestrator_guidance() with the synthetic PROCEED payload and override_forced=True context. Since this is a user-initiated force-proceed, the guidance is straightforward: "Override applied. Proceed to execute."
Simpler approach: pass a static string directly: orchestrator_guidance="Force-proceed override applied. Proceed to execute."
Pass to build_gate_artifact(..., orchestrator_guidance=...)
StepResponse TypedDict update (_core.py):
Add orchestrator_guidance: str to StepResponse
Step 3: Verify schema handling
The gate JSON schema in schemas.py validates LLM worker output before build_gate_artifact() merges it. orchestrator_guidance is added post-validation — no schema change needed. Confirm by reading the validation call in the worker path.
Step 4: Update tests
tests/test_evaluation.py: Add tests for build_orchestrator_guidance() covering all 8+ branches plus contextual hints. Test that plan_name appears in override commands and failing checks appear in preflight-failed guidance.
tests/test_megaplan.py: Update gate integration tests to assert orchestrator_guidance present in response. Update _override_force_proceed tests to assert field present.
tests/test_schemas.py: No change expected (schema unchanged).
Step 5: Rewrite instructions.md to ~70 lines
Remove (replaced by orchestrator_guidance):
9 signal field definitions (weighted_score, unresolved_flags, etc.)
5 judgment bullets (score trajectory, flag quality, etc.)
Per-step detailed descriptions that duplicate what the gate response now provides
Keep (compressed):
Triage section (~10 lines)
Start/init section (~8 lines)
Workflow step list (~10 lines, one line each)
Gate principle (~8 lines): "The gate response includes orchestrator_guidance. Follow it unless you disagree after investigating the project code. You can always override."
Execute section with review-mode pause (~6 lines)
Overrides section (~8 lines)
Replan section (~8 lines)
Sessions + Autonomy (~6 lines)
Target: 65-75 lines
Step 6: Run full test suite, fix breakage
bash
python -m pytest tests/ -v
Ordering and Risk
Step 1 + Step 4 (evaluation tests) — pure function, easy to validate
Step 2 — wiring both call sites, mechanical
Step 3 — schema check, likely a no-op
Step 5 — instructions rewrite
Step 6 — full validation
code
Plan metadata:
{
"version": 2,
"timestamp": "2026-03-23T02:27:17Z",
"hash": "sha256:35955f152847fd41705a4b54f17727a1101dbee302faa7bfcc5b71e4859cf3b3",
"changes_summary": "FLAG-001 fix: Step 2 now explicitly covers both build_gate_artifact() call sites \u2014 handle_gate() and _override_force_proceed(). The override path uses a static guidance string since it's a user-initiated force-proceed. The build_gate_artifact() signature change uses a default parameter (orchestrator_guidance=\"\") so both callers work cleanly.\n\nFLAG-002 fix: Added preflight_results: dict and plan_name: str parameters to build_orchestrator_guidance() signature. Preflight-failed guidance now lists failing check names from the dict. Override commands now include the real plan name instead of a placeholder. Updated Step 4 tests to verify both.",
"flags_addressed": [
"FLAG-001",
"FLAG-002"
],
"questions": [],
"success_criteria": [
"build_orchestrator_guidance() exists in evaluation.py as a pure function with no LLM calls",
"All 8+ decision branches have corresponding unit tests that pass",
"gate.json artifact and StepResponse include orchestrator_guidance string field",
"orchestrator_guidance includes real plan name in override commands and failing check names in preflight guidance",
"Both build_gate_artifact() call sites (handle_gate and _override_force_proceed) produce orchestrator_guidance",
"instructions.md is between 60-80 lines down from ~174",
"instructions.md retains triage, init, gate principle, overrides, replan, sessions, autonomy",
"instructions.md no longer contains signal field definitions or manual score interpretation rules",
"python -m pytest tests/ -v passes with no failures",
"Existing gate workflow produces identical recommendations \u2014 orchestrator_guidance is additive"
],
"assumptions": [
"The gate JSON schema in schemas.py is only used to validate raw LLM worker output, not the merged artifact. No schema change needed.",
"Auto-force for ESCALATE uses robustness == light and weighted_score <= 4.0 (confirmed by user).",
"Plateau detection: current score >= last score in weighted_history. No sliding window needed.",
"orchestrator_guidance is only generated after the gate step, not after revise (confirmed by user).",
"Contextual hints are appended as sentences to the main guidance string, not a separate field.",
"For _override_force_proceed(), a static guidance string is sufficient since the user already chose to force-proceed."
],
"delta_from_previous_percent": 22.13
}
code
Execution summary:
{
"output": "Implemented orchestrator_guidance end to end.\n\nKey changes:\n- Added pure build_orchestrator_guidance() with first-match branch logic and contextual hint appending in megaplan/evaluation.py.\n- Wired orchestrator_guidance into gate artifacts and responses in megaplan/cli.py, megaplan/cli.py, and megaplan/cli.py.\n- Added the field to StepResponse in megaplan/_core.py.\n- Rewrote instructions.md to 74 lines and explicitly replaced manual gate interpretation with orchestrator_guidance as the default post-gate rule.\n- Added branch coverage and integration assertions in tests/test_evaluation.py and tests/test_megaplan.py.\n\nVerification:\n- python -m pytest tests/test_evaluation.py tests/test_megaplan.py -q -> 120 passed\n- python -m pytest tests/ -v -> 183 passed\n\nUnrelated existing worktree changes were present in tests/test_prompts.py, tests/test_schemas.py, and tests/test_workers.py; I left them untouched.",
"files_changed": [
[REDACTED],
[REDACTED],
[REDACTED],
[REDACTED],
[REDACTED],
[REDACTED],
[REDACTED]
],
"commands_run": [
"pwd",
"rg -n "build_gate_artifact|handle_gate|override_force_proceed|StepResponse|orchestrator_guidance|next_step|valid_next" megaplan tests",
"wc -l megaplan/data/instructions.md",
"sed -n '1,260p' megaplan/evaluation.py",
"sed -n '334,790p' megaplan/cli.py",
"sed -n '120,170p' megaplan/_core.py",
"sed -n '1,260p' megaplan/data/instructions.md",
"sed -n '1,260p' tests/test_evaluation.py",
"sed -n '1,760p' tests/test_megaplan.py",
"rg -n "validate_payload|schema|gate" megaplan/schemas.py megaplan -g '!tests'",
"sed -n '971,1018p' megaplan/cli.py",
"sed -n '168,185p' megaplan/_core.py",
"sed -n '1,120p' megaplan/schemas.py",
"sed -n '240,330p' megaplan/workers.py",
"python -m pytest tests/test_evaluation.py tests/test_megaplan.py -q",
"python -m pytest tests/ -v",
"git status --short",
"git diff -- megaplan/evaluation.py megaplan/cli.py megaplan/_core.py megaplan/init.py megaplan/data/instructions.md tests/test_evaluation.py tests/test_megaplan.py",
"nl -ba megaplan/evaluation.py | sed -n '165,250p'",
"nl -ba megaplan/cli.py | sed -n '334,780p'",
"nl -ba megaplan/cli.py | sed -n '971,1035p'",
"nl -ba megaplan/_core.py | sed -n '168,182p'",
"nl -ba megaplan/data/instructions.md | sed -n '1,120p'",
"rg -n "build_orchestrator_guidance|orchestrator_guidance|Force-proceed override applied" tests/test_evaluation.py tests/test_megaplan.py"
],
"deviations": [
"Added orchestrator_guidance to state[\"last_gate\"] as an additive convenience field so state mirrors the gate artifact more closely.",
"Exported build_orchestrator_guidance from megaplan/__init__.py for parity with other evaluation helpers; the approved plan did not require that export.",
"The repository had unrelated pre-existing modifications in tests/test_prompts.py, tests/test_schemas.py, and tests/test_workers.py; I did not modify or revert them."
]
}
code
Git diff summary:
M megaplan/__init__.py
M megaplan/_core.py
M megaplan/cli.py
M megaplan/data/instructions.md
M megaplan/evaluation.py
M tests/test_evaluation.py
M tests/test_megaplan.py
M tests/test_prompts.py
M tests/test_schemas.py
M tests/test_workers.py
code
Requirements:
- Be critical.
- Verify each success criterion explicitly.
- Call out any concrete gaps or regressions in issues.
{"criteria":[{"name":"build_orchestrator_guidance() exists in evaluation.py as a pure function with no LLM calls","pass":true,"evidence":"Pass. Defined at evaluation.py:174. It only reads its arguments and builds a string; there is no worker/LLM/file interaction in the function body."},{"name":"All 8+ decision branches have corresponding unit tests that pass","pass":false,"evidence":"Partially verified. I found 9 branch tests covering first-iteration, proceed/pass, proceed/fail, escalate/auto-force, escalate/ask-user, iterate/plateaued, iterate/improving, iterate/worsening, and iterate/fallthrough in test_evaluation.py:271. I could not independently confirm they pass because pytest cannot start in this sandbox: FileNotFoundError: No usable temporary directory found."},{"name":"gate.json artifact and StepResponse include orchestrator_guidance string field","pass":true,"evidence":"Pass. build_gate_artifact() adds orchestrator_guidance at cli.py:355, and StepResponse includes it at _core.py:175."},{"name":"orchestrator_guidance includes real plan name in override commands and failing check names in preflight guidance","pass":true,"evidence":"Pass. Preflight failures are joined from preflight_results at evaluation.py:200, and auto-force guidance includes --plan {plan_name} at evaluation.py:207. Tests assert both behaviors at test_evaluation.py:317 and test_evaluation.py:330."},{"name":"Both build_gate_artifact() call sites (handle_gate and _override_force_proceed) produce orchestrator_guidance","pass":true,"evidence":"Pass. handle_gate() computes and passes guidance at cli.py:718 and cli.py:730. _override_force_proceed() passes a static guidance string at cli.py:1016. Integration assertions exist at test_megaplan.py:200 and test_megaplan.py:615."},{"name":"instructions.md is between 60-80 lines down from ~174","pass":true,"evidence":"Pass. wc -l reports 74 lines, and the file content is at instructions.md:1."},{"name":"instructions.md retains triage, init, gate principle, overrides, replan, sessions, autonomy","pass":true,"evidence":"Pass. Present at instructions.md:3, instructions.md:7, instructions.md:30, instructions.md:40, instructions.md:46, and instructions.md:52."},{"name":"instructions.md no longer contains signal field definitions or manual score interpretation rules","pass":true,"evidence":"Pass by inspection. The detailed signal glossary is gone; the only remaining mention is the rule to avoid manual reinterpretation at instructions.md:33, which is consistent with the new design."},{"name":"python -m pytest tests/ -v passes with no failures","pass":false,"evidence":"Unverified locally. The implementation summary says the suite passed, but my independent run failed before test collection because the sandbox has no writable temp directory."},{"name":"Existing gate workflow produces identical recommendations — orchestrator_guidance is additive","pass":true,"evidence":"Pass by inspection. The worker recommendation is still copied straight into the gate artifact/response at cli.py:343, cli.py:350, and cli.py:791. The new guidance is computed after the worker returns and does not feed back into recommendation generation."}],"issues":["Medium: the gate response is internally inconsistent for ESCALATE cases. build_orchestrator_guidance() can explicitly instruct override force-proceed for auto-force or plateau scenarios at evaluation.py:205 and evaluation.py:213, but handle_gate() still hardcodes next_step = \"override add-note\" for every ESCALATE at cli.py:763. That conflicts with the stated principle in instructions.md:23 and instructions.md:31 that the gate response should tell the orchestrator what to do next."],"summary":"One substantive issue: orchestrator_guidance is wired correctly, but next_step can still point the orchestrator at the wrong override path on ESCALATE. Aside from that, the implementation meets the code and documentation criteria by inspection. I could not independently verify the pytest-pass criterion in this read-only sandbox because pytest cannot obtain a usable temp directory."}