Execute the approved plan in the repository. Project directory:…
- User
Execute the approved plan in the repository.
codeProject directory: /Users/user_c042661f/Documents/megaplan Idea:Add a megaplan step CLI command for managing plan steps without editing JSON directly. Subcommands: megaplan step add --plan NAME --after S3 'description' (inserts a new step with auto-generated ID), megaplan step remove --plan NAME S4 (removes a step and renumbers), megaplan step move --plan NAME S4 --after S2 (reorders steps). These operate on the plan markdown (plan_v*.md) by parsing ## Step N sections with fence-aware boundary detection. After editing, the command must preserve plan_v*.meta.json fields (questions, success_criteria, assumptions) and update the plan_versions record. The command resets the plan to STATE_PLANNED so it re-enters the critique loop after edits.
User notes and answers:
-
This was deferred from the plan template work. Key design issues identified: (1) versioning/state - edits should bump plan version and reset to STATE_PLANNED so it re-enters critique, (2) meta preservation - edited plans must carry forward questions/success_criteria/assumptions, (3) fence-aware section parsing - need a boundary finder that tracks fence state while returning original line numbers. The structural validator (validate_plan_structure in evaluation.py) and _strip_fenced_blocks already exist. Build on those.
-
Make sure to add the megaplan step command to instructions.md (the orchestrator-facing docs) and to the CLI help text. Also update the skill file at ~/.claude/skills/megaplan/instructions.md if it exists. The command should be documented alongside the existing override commands since it's a plan-editing tool.
codeExecution tracking source of truth (`finalize.json`): {"tasks": [ { "id": "T1", "description": "Build fence-aware section parser in megaplan/evaluation.py. Add PlanSection dataclass, parse_plan_sections(plan_text) -> list[PlanSection], reassemble_plan(sections) -> str, and renumber_steps(sections) -> list[PlanSection]. Place after _strip_fenced_blocks (line 93). The parser reuses the fence-tracking pattern (line 83-92) but tracks inside_fence state while scanning for ^##\s+Step\s+\d+:\s+ and ^##\s+ boundaries \u2014 only matching headings when inside_fence is False. Non-step ## headings become sections with id=None. Content before the first ## heading becomes a leading section with id=None, heading=''. reassemble_plan joins section.body values. renumber_steps updates id fields and heading text via re.sub on step sections only.", "depends_on": [], "status": "pending", "executor_notes": "", "reviewer_verdict": "" }, { "id": "T2", "description": "Add unit tests for the section parser in tests/test_evaluation.py: test_parse_plan_sections_basic (standard plan, verify section count/IDs/boundaries), test_parse_plan_sections_fenced (code blocks containing ## Step headers are not treated as boundaries), test_renumber_steps (verify renumbering after removal/insertion), test_reassemble_roundtrip (reassemble(parse(text)) == text). Run these tests to validate T1 in isolation before proceeding.", "depends_on": [ "T1" ], "status": "pending", "executor_notes": "", "reviewer_verdict": "" }, { "id": "T3", "description": "Wire the step CLI subparser in megaplan/cli.py. Add a 'step' subparser at line 301 (before override_parser) with subparsers for add/remove/move. 'add' takes --plan, --after (optional), and positional description. 'remove' takes --plan and positional step_id. 'move' takes --plan, positional step_id, and required --after. Add 'step': handle_step to COMMAND_HANDLERS dict (line 310). Import handle_step from megaplan.handlers alongside existing imports.", "depends_on": [], "status": "pending", "executor_notes": "", "reviewer_verdict": "" }, { "id": "T4", "description": "Implement handle_step and helpers in megaplan/handlers.py. Add handle_step(root, args) dispatching to _step_add, _step_remove, _step_move based on args.step_action. Allowed states: {STATE_PLANNED, STATE_CRITIQUED, STATE_GATED, STATE_FINALIZED}. _step_add: parse latest plan via parse_plan_sections, build scaffold section (## Step 0: description / Small / 1. Fill in implementation details ().), insert after --after step or after last step section if omitted, renumber, reassemble, validate, commit. _step_remove: find and remove named step, reject if only one step remains, renumber, reassemble, validate, commit. _step_move: extract step, insert after --after target, renumber, reassemble, validate, commit. Common _commit_step_edit helper: use next_plan_artifact_name(plan_dir, state['iteration']) for same-iteration subversioning (do NOT increment iteration), run validate_plan_structure \u2014 raise CliError only when zero step sections found (PLAN_STRUCTURE_REQUIRED_STEP_ISSUE), store other warnings in meta, write new plan file, carry forward questions/success_criteria/assumptions from previous meta, add step_edit field, append to plan_versions, set state to STATE_PLANNED, clear last_gate, record in history, save_state.", "depends_on": [ "T1", "T3" ], "status": "pending", "executor_notes": "", "reviewer_verdict": "" }, { "id": "T5", "description": "Update exports and state machine. Add handle_step to megaplan/.py imports (line 24-37) and (line 44-67). Update infer_next_steps in megaplan/_core.py (line 403): add 'step' as an available action for STATE_PLANNED (append to ['plan', 'critique']), STATE_CRITIQUED (append to relevant lists), STATE_GATED (append to ['finalize', 'override replan']), and STATE_FINALIZED (append to ['execute', 'override replan']).", "depends_on": [ "T4" ], "status": "pending", "executor_notes": "", "reviewer_verdict": "" }, { "id": "T6", "description": "Update documentation in megaplan/data/instructions.md. Add a ## Step Editing section after ## Replan (line 53) with usage examples for all three subcommands. Add the three megaplan step commands to the ## Commands block (lines 61-77). Then run to propagate to the skill file at ~/.claude/skills/megaplan/SKILL.md (the _GLOBAL_TARGETS path, not instructions.md).", "depends_on": [ "T4" ], "status": "pending", "executor_notes": "", "reviewer_verdict": "" }, { "id": "T7", "description": "Add integration tests in tests/test_megaplan.py: test_step_add (new plan file uses subversion naming like plan_v1a.md, iteration unchanged, meta carryforward, state reset to STATE_PLANNED), test_step_add_scaffold_passes_validation (generated scaffold passes validate_plan_structure), test_step_remove (middle step removed, renumbering correct, subversion bump), test_step_move (step relocated, renumbering correct), test_step_remove_last_step_rejected (removing only step raises CliError), test_step_invalid_state (fails on STATE_DONE/STATE_ABORTED), test_step_preserves_meta (questions/success_criteria/assumptions carry forward). Run full test suite: python -m pytest tests/.", "depends_on": [ "T4", "T5" ], "status": "pending", "executor_notes": "", "reviewer_verdict": "" } ], "watch_items": [ "Validation semantics: validate_plan_structure returns warnings, not hard errors. Only raise CliError when PLAN_STRUCTURE_REQUIRED_STEP_ISSUE (zero steps) is present. All other warnings go into meta.structure_warnings. Do NOT block on missing Overview/Execution Order warnings \u2014 match existing codebase pattern.", "Versioning: use next_plan_artifact_name(plan_dir, state['iteration']) for same-iteration subversioning (plan_v1a.md). Do NOT increment state['iteration'] \u2014 iteration bumps belong to worker-generated content only. This matches handle_plan rerun pattern at handlers.py:434-435.", "Skill file path: the repo installs to ~/.claude/skills/megaplan/SKILL.md via _GLOBAL_TARGETS (cli.py:150-153), NOT instructions.md. Run megaplan setup to propagate; do not manually copy to a wrong path.", "Scaffold must pass validation: the step add scaffold needs at least one numbered substep (1. ...) and one backticked file reference () to satisfy validate_plan_structure checks at evaluation.py:122-125.", "Fence-aware parsing: code blocks can contain ## Step headers. The parser must track inside_fence state like _strip_fenced_blocks does (line 83-92) and only match headings outside fences.", "Allowed states for step command: {STATE_PLANNED, STATE_CRITIQUED, STATE_GATED, STATE_FINALIZED}. This is _override_replan's set (line 1074) plus STATE_PLANNED itself. Terminal states (DONE, ABORTED) must be rejected.", "Meta carryforward: read previous plan_v*.meta.json, copy questions/success_criteria/assumptions into new meta. Set structure_warnings from fresh validation. Add step_edit: action_summary field.", "Round-trip invariant: reassemble_plan(parse_plan_sections(text)) must equal text for all well-formed plans. This is a critical correctness property \u2014 test it thoroughly." ], "sense_checks": [ { "id": "SC1", "task_id": "T1", "question": "Does parse_plan_sections correctly ignore ## Step headings inside fenced code blocks, and does reassemble_plan(parse_plan_sections(text)) == text for the test plans?", "verdict": "" }, { "id": "SC2", "task_id": "T2", "question": "Do all four parser unit tests pass, including the fence-aware test with code blocks containing ## Step headers?", "verdict": "" }, { "id": "SC3", "task_id": "T3", "question": "Does show add/remove/move subcommands with correct argument shapes, and is handle_step in COMMAND_HANDLERS?", "verdict": "" }, { "id": "SC4", "task_id": "T4", "question": "Does _commit_step_edit use next_plan_artifact_name without incrementing iteration, carry forward meta fields, only raise CliError on zero-steps, and reset state to STATE_PLANNED with last_gate cleared?", "verdict": "" }, { "id": "SC5", "task_id": "T5", "question": "Does infer_next_steps include 'step' for all four allowed states (PLANNED, CRITIQUED, GATED, FINALIZED) and is handle_step properly exported in ?", "verdict": "" }, { "id": "SC6", "task_id": "T6", "question": "Does instructions.md document all three step subcommands with examples, and does successfully propagate to ~/.claude/skills/megaplan/SKILL.md?", "verdict": "" }, { "id": "SC7", "task_id": "T7", "question": "Do all integration tests pass, including subversion naming (plan_v1a.md), meta preservation, scaffold validation, last-step rejection, and invalid-state rejection? Does the full test suite (python -m pytest tests/) pass with no regressions?", "verdict": "" } ], "meta_commentary": "Execution order: T1 and T3 are independent and can be done in parallel. T2 follows T1 (validate parser before building on it). T4 depends on both T1 and T3. T5 and T6 follow T4. T7 is last.\n\nKey judgment calls: (1) The 'version-bump-semantic' flag is resolved by design \u2014 same-iteration subversioning DOES produce a new versioned file (plan_v1a.md), which satisfies 'bump plan version'. The iteration counter belongs to worker-generated content. (2) The 'structure-pass-vs-warning' flag is resolved by following existing codebase pattern: only the zero-steps issue (PLAN_STRUCTURE_REQUIRED_STEP_ISSUE) is blocking; all other validate_plan_structure issues are warnings stored in meta. This matches how handle_plan uses _validate_generated_plan_or_raise. (3) The step add scaffold is minimal but validator-compliant: one numbered substep with and one backticked path reference.\n\nGotchas: The PlanSection.body field must include the heading line itself so reassemble works by simple concatenation. The leading section (before first ##) must capture any trailing newlines to maintain round-trip fidelity. When renumbering, update both the id field AND the first line of body (the heading). For step move, extract-then-insert must handle the case where --after target is the step being moved (no-op or error)." }
-
- Assistant