| description | Refine an annotated implementation plan and generate a QA ledger | |||||||
|---|---|---|---|---|---|---|---|---|
| argument-hint | --input <path/to/annotated-plan.md> [--output <path/to/refined-plan.md>] [--qa-dir <path/to/qa-dir>] [--alt-language <language-or-code>] [--discussion|--direct] | |||||||
| allowed-tools |
|
|||||||
| hide-from-slash-command-tool | true |
Read and execute below with ultrathink.
This command MUST ONLY refine plan artifacts. It MUST NOT implement repository code, modify source files unrelated to the plan outputs, start RLCR automatically, or create a new plan schema.
Permitted writes are limited to:
- The refined plan output file (
--output, or--inputin in-place mode) - The QA document under
--qa-dir - Optional translated language variants for the refined plan and QA document
The refined plan MUST reuse the existing gen-plan schema. Do not invent new top-level sections. Keep required sections intact, preserve optional sections when present, and preserve any --- Original Design Draft Start --- appendix or other non-comment content unless a comment explicitly requires a plan-level change there.
Sequential Execution Constraint: Execute the phases strictly in order. Do NOT parallelize work across phases. Finish each phase before moving to the next one.
- Execution Mode Setup: Parse CLI arguments and derive output paths
- Load Project Config: Resolve
alternative_plan_languageand mode defaults usingconfig-loader.shsemantics - IO Validation: Run
validate-refine-plan-io.sh - Comment Extraction: Scan the annotated plan and extract valid comment blocks (
CMT:/ENDCMT,<cmt>/</cmt>,<comment>/</comment>) - Comment Classification: Classify each extracted comment for downstream handling
- Comment Processing: Answer questions, apply requested plan edits, and perform targeted research
- Plan Refinement: Produce the comment-free refined plan while preserving the
gen-planstructure - QA Generation: Populate the QA template with the comment ledger and outcomes
- Atomic Write: Commit the refined plan, QA document, and optional variants as one transaction
Parse $ARGUMENTS and set the following variables:
INPUT_FILEfrom--input(required)OUTPUT_FILEfrom--outputQA_DIRfrom--qa-dirCLI_ALT_LANGUAGE_RAWfrom--alt-languageREFINE_PLAN_MODE_DISCUSSION=trueif--discussionis presentREFINE_PLAN_MODE_DIRECT=trueif--directis present
Argument rules:
--input <path>is required.--output <path>is optional. If omitted, setOUTPUT_FILE=INPUT_FILEfor in-place mode.--qa-dir <path>is optional. If omitted, setQA_DIR=.humanize/plan_qa.--alt-language <language-or-code>is optional. If present without a value, reportInvalid arguments: --alt-language requires a valueand stop.--discussionand--directare mutually exclusive. If both are present, reportCannot use --discussion and --direct togetherand stop.
Derived paths:
- Compute
IN_PLACE_MODE=truewhenOUTPUT_FILEequalsINPUT_FILE; otherwisefalse. - Compute
QA_FILEfrom the input basename, not the output basename:plan.mdbecomes<QA_DIR>/plan-qa.mddocs/my-plan.mdbecomes<QA_DIR>/my-plan-qa.mdplanbecomes<QA_DIR>/plan-qa.md
- Keep
--alt-languageout of the validator invocation becausevalidate-refine-plan-io.shdoes not accept it. Pass only:--input--outputwhen provided--qa-dirwhen provided--discussionor--directwhen provided
Scope rules for v1:
- Do not introduce
--languageor--qa-output - Do not add new config keys
- Do not auto-start RLCR after refinement
Resolve configuration by following the same precedence and merge semantics defined in ${CLAUDE_PLUGIN_ROOT}/scripts/lib/config-loader.sh. Reuse that behavior; do not invent a separate refine-plan config model.
Use the same layer order as load_merged_config:
- Required default config:
${CLAUDE_PLUGIN_ROOT}/config/default_config.json - Optional user config:
${XDG_CONFIG_HOME:-$HOME/.config}/humanize/config.json - Optional project config:
${HUMANIZE_CONFIG:-$PROJECT_ROOT/.humanize/config.json}
Later layers override earlier layers. Malformed optional JSON objects are treated as warnings and ignored. A malformed required default config is a fatal configuration error.
Read the merged config and resolve:
CONFIG_ALT_LANGUAGE_RAWfromalternative_plan_languageCONFIG_GEN_PLAN_MODE_RAWfromgen_plan_mode
Resolve REFINE_PLAN_MODE with this priority:
- CLI
--discussion=>discussion - CLI
--direct=>direct - Valid config value
gen_plan_mode(discussionordirect, case-insensitive) - Default =>
discussion
If gen_plan_mode is present but invalid, log a warning and fall back to the next rule.
Resolve the variant language with this priority:
- CLI
--alt-language - Config
alternative_plan_language - No variant
Normalize the value case-insensitively using this mapping table:
| Language | Code | Suffix |
|---|---|---|
| Chinese | zh | _zh |
| Korean | ko | _ko |
| Japanese | ja | _ja |
| Spanish | es | _es |
| French | fr | _fr |
| German | de | _de |
| Portuguese | pt | _pt |
| Russian | ru | _ru |
| Arabic | ar | _ar |
Normalization rules:
- Trim leading and trailing whitespace before matching.
- Accept either the full language name or the ISO code from the table.
- Treat
English/enas a no-op: no translated variant is generated. - If the CLI value is unsupported, report
Unsupported --alt-language "<value>"and stop. - If the config value is unsupported, log a warning and disable variant generation.
Set:
ALT_PLAN_LANGUAGEto the normalized language name or empty stringALT_PLAN_LANG_CODEto the normalized code or empty string
Do not depend on deprecated chinese_plan. refine-plan only uses alternative_plan_language.
Run the validator with the parsed arguments, excluding --alt-language:
"${CLAUDE_PLUGIN_ROOT}/scripts/validate-refine-plan-io.sh" <validated-arguments>Handle exit codes exactly:
- Exit code 0: Continue to Phase 2
- Exit code 1: Report
Input file not foundand stop - Exit code 2: Report
Input file is emptyand stop - Exit code 3: Report
Input file has no comment blocksand stop - Exit code 4: Report
Input file is missing required gen-plan sectionsand stop - Exit code 5: Report
Output directory does not exist or is not writable - please fix itand stop - Exit code 6: Report
QA directory is not writableand stop - Exit code 7: Report
Invalid argumentsand show the validator usage, then stop
Validation notes:
validate-refine-plan-io.shmay createQA_DIRwhen it does not exist. Treat that as expected setup, not as a side effect to undo.- After validation succeeds, read the input file and preserve its exact contents as
ORIGINAL_PLAN_TEXT. - Do not mutate the validated input yet. All writes happen in Phase 7 only.
Extract comments using a stateful scanner equivalent to POSIX awk wrapped by bash, not a naive regular expression pass. The scanner behavior must match the Task 3 findings.
Track these states while scanning the validated input in document order:
IN_FENCEwith the active fence marker (```or~~~)IN_HTML_COMMENTfor<!-- ... -->IN_CMT_BLOCKNEAREST_HEADING
Extraction rules:
- Support three comment formats:
- Classic:
CMT:as start marker andENDCMTas end marker - Short tag:
<cmt>as start marker and</cmt>as end marker - Long tag:
<comment>as start marker and</comment>as end marker
- Classic:
- Support both inline and multi-line blocks for all formats:
- Inline:
Text before CMT: comment text ENDCMT text after - Inline:
Text before <cmt>comment text</cmt> text after - Inline:
Text before <comment>comment text</comment> text after - Multi-line:
CMT: comment text ENDCMT
<cmt> comment text </cmt>
<comment> comment text </comment>
- Inline:
- Ignore comment markers inside fenced code blocks.
- Ignore comment markers inside HTML comments.
- Update
NEAREST_HEADINGwhenever a Markdown heading is encountered outside fenced code and HTML comments. - Preserve surrounding non-comment text when removing inline comment blocks from the working plan text.
- Assign raw comment IDs in document order as
CMT-1,CMT-2, ... only for non-empty blocks. - If a block is empty after trimming whitespace, remove it from the working plan text but do not create a ledger item and do not consume an ID.
For each non-empty comment block, capture:
id(CMT-N)original_textexactly as written between the comment markersnormalized_textwith surrounding whitespace trimmedstart_line,start_columnend_line,end_columnnearest_headingorPreamblewhen no heading exists yetlocation_labelfor QA outputform=inlineormultilinecontext_excerptfrom the nearest non-comment source text
These are fatal extraction errors:
- Nested comment start marker while already inside a comment block
- Comment end marker encountered while not inside a comment block or wrong end marker for the format
- End of file reached while still inside a comment block
Every fatal parse error MUST report:
- The error kind
- The exact line and column
- The nearest heading
- A short context excerpt
Examples of acceptable messages:
Comment parse error: nested comment block at line 48, column 3 near "## Acceptance Criteria" (context: "<cmt>split AC-2...")Comment parse error: stray comment end marker at line 109, column 1 near "## Task Breakdown" (context: "</comment>")Comment parse error: missing end marker for block opened at line 72, column 5 near "## Dependencies and Sequence"
Produce:
EXTRACTED_COMMENTS: ordered list of comment recordsPLAN_WITH_COMMENTS_REMOVED: the original plan text with every valid comment block removed and surrounding inline text preserved
If EXTRACTED_COMMENTS is empty after removing no-op blocks, report No non-empty CMT blocks remain after parsing and stop.
Classify every extracted comment for downstream handling.
Each raw comment block must receive exactly one primary classification:
questionchange_requestresearch_request
Use these heuristics first:
question: asks why, how, what, explain, clarify, or says the plan is unclearchange_request: asks to add, remove, delete, rewrite, restore, rename, split, merge, or otherwise modify the planresearch_request: asks to investigate the repository, compare existing patterns, confirm current behavior, or gather evidence before deciding
When more than one intent appears in the same raw block:
- Keep the raw ledger ID unchanged (
CMT-N) - Create deterministic processing sub-items in textual order:
CMT-N.1,CMT-N.2, ... - Assign each sub-item one of the three classifications above
- Assign the raw block a dominant classification for the QA ledger using this precedence:
research_requestchange_requestquestion
If classification is still ambiguous after applying the heuristics:
- In
discussionmode: useAskUserQuestionto confirm the classification before continuing - In
directmode: choose the most action-driving interpretation and record the assumption in the QA document
Examples:
Why do we need two config layers here?=>questionDelete task5 and fold its work into task4.=>change_requestInvestigate how config loading works in this repo before deciding whether AC-3 should change.=>research_request, or split into research plus follow-up change sub-items if the block clearly contains both intents
For each raw comment block and any sub-items, record:
idparent_idwhen applicableclassificationclassification_rationaleneeds_user_confirmation(trueorfalse)resolved_via_discussion(trueorfalse)
Process comments in document order. When a raw block has sub-items, process the sub-items in order before moving to the next raw block.
Default behavior:
- Answer the question in the QA document.
- Apply only minimal clarifying plan edits when the current plan text is genuinely ambiguous or misleading.
- Do not use a question as an excuse to expand scope, add implementation detail, or rewrite unrelated sections.
Preferred destinations for light clarification:
## Goal Description## Feasibility Hints and Suggestions## Dependencies and Sequence## Implementation Notes
Default behavior:
- Apply the requested plan edits directly to the refined plan draft.
- Keep the
gen-planstructure intact. - Propagate changes across all affected sections so the plan stays internally consistent.
Consistency obligations:
- Acceptance criteria still match referenced tasks
- Task Breakdown still points to existing ACs
- Task dependencies still reference existing task IDs or
- - Milestones and sequencing remain aligned with the changed scope
Claude-Codex DeliberationandPending User Decisionsreflect the new state- Task routing tags remain exactly
codingoranalyze
Default behavior:
- Perform targeted repository research using only
Read,Glob, andGrep. - Keep the research tightly scoped to the comment. Do not drift into implementation work.
- Summarize the files and patterns examined in the QA document.
- Integrate the conclusion into the refined plan if the evidence supports a clear plan update.
- If the research narrows the issue but still requires a human choice, add or update a
DEC-Nitem in## Pending User Decisionsand record the same decision in the QA document.
- Every raw
CMT-Nmust end with one disposition:answeredappliedresearcheddeferredresolved
- Preserve the original comment text in the QA document exactly as captured in Phase 2.
- If a comment cannot be fully resolved without user input:
- In
discussionmode, ask only the minimum necessary question - In
directmode, make the smallest safe assumption, mark it explicitly in QA, and add a pending decision when the assumption materially affects the plan
- In
- If unresolved user decisions remain after processing, the plan convergence status must be
partially_converged - If all comments are fully resolved and no pending decisions remain, preserve or set convergence status to
converged
Starting from PLAN_WITH_COMMENTS_REMOVED, apply the accepted refinements from Phase 4 and produce REFINED_PLAN_TEXT.
The refined plan MUST retain these required sections:
## Goal Description## Acceptance Criteria## Path Boundaries## Feasibility Hints and Suggestions## Dependencies and Sequence## Task Breakdown## Claude-Codex Deliberation## Pending User Decisions## Implementation Notes
Optional sections that MUST be preserved when present in the input:
## Codex Team Workflow## Convergence Log--- Original Design Draft Start ---appendix and its matching end marker
- Remove every resolved comment marker and all enclosed comment text from the refined plan.
- Do not add any new top-level schema section.
- Preserve
AC-X/AC-X.Yformatting. - Preserve task IDs unless a comment explicitly requests a structural change.
- If task IDs or AC IDs change, update all references consistently across the plan.
- Keep task routing tags restricted to
codingoranalyze. - Keep the refined plan in the same main language as the input plan. Only normalize mixed-language content when the input is ambiguous and discussion-mode user input explicitly requests normalization.
Determine the primary language of the input plan after comment removal.
Rules:
- Use the dominant language of headings and prose as the default main language.
- If the plan is clearly mixed-language and the dominant language is ambiguous:
- In
discussionmode, ask the user whether to keep the current mix or normalize to the dominant language - In
directmode, keep the dominant language inferred from headings and body text; if still tied, default to English
- In
- The QA document MUST use the same main language as the refined plan.
- If
ALT_PLAN_LANGUAGEresolves to the same language as the main language, skip variant generation.
Before generating the QA document, verify:
- All required sections are still present
- No comment markers remain
- Every referenced
AC-*exists - Every task dependency references an existing task ID or
- - Every task row has exactly one valid routing tag:
codingoranalyze ## Pending User Decisionsand### Convergence Statusagree with the actual unresolved state
If a validation issue can be fixed by reconciling the plan, fix it before continuing. If it cannot be fixed without inventing requirements, stop and report the blocking inconsistency.
Read ${CLAUDE_PLUGIN_ROOT}/prompt-template/plan/refine-plan-qa-template.md and populate it completely. The QA document is not optional.
Populate all template sections:
## Summary## Comment Ledger## Answers## Research Findings## Plan Changes Applied## Remaining Decisions## Refinement Metadata
The Comment Ledger MUST contain exactly one row per raw CMT-N extracted in Phase 2, in document order.
Each row must include:
CMT-ID- Dominant classification
- Location
- Original text excerpt
- Final disposition
If a raw block was split into processing sub-items, keep one ledger row for the raw ID and describe the sub-item handling in the detailed sections.
Answers: include allquestionitems and any clarifying edits made to the planResearch Findings: include allresearch_requestitems, the files or patterns examined, and the impact on the planPlan Changes Applied: include allchange_requestitems and cross-reference updatesRemaining Decisions: include every unresolved or assumption-heavy item that still needs user choice
Language rules:
- Write the main QA document in the same main language as
REFINED_PLAN_TEXT - Keep identifiers unchanged:
AC-*, task IDs, file paths, API names, command flags, config keys - Preserve the original comment text verbatim inside fenced code blocks
Metadata rules:
- Record the resolved input path, output path, QA path, date, and counts by classification
- Record the final convergence status as
convergedorpartially_converged - Record the set of plan sections modified during refinement
Do not write any final output until all content is fully prepared.
Always prepare:
- Main refined plan at
OUTPUT_FILE - Main QA document at
QA_FILE
Conditionally prepare:
- Plan variant at
OUTPUT_FILEwith_<ALT_PLAN_LANG_CODE>inserted before the extension - QA variant at
QA_FILEwith_<ALT_PLAN_LANG_CODE>inserted before the extension
Filename construction rule for variants:
- If the filename has an extension, insert
_<code>before the last. - If the filename has no extension, append
_<code>
Examples:
plan.md->plan_zh.mdfeature-a-qa.md->feature-a-qa_zh.mdoutput->output_zh
If ALT_PLAN_LANGUAGE is non-empty and different from the main language:
- Translate the main refined plan into
ALT_PLAN_LANGUAGE - Translate the main QA document into
ALT_PLAN_LANGUAGE - Keep identifiers unchanged
- For Chinese, default to Simplified Chinese
If ALT_PLAN_LANGUAGE is empty or equals the main language, do not create variant files.
- Prepare all final content in memory first:
REFINED_PLAN_TEXTQA_TEXT- Optional
REFINED_PLAN_VARIANT_TEXT - Optional
QA_VARIANT_TEXT
- Write each output to a temporary file in the same directory as its final destination.
- Use temp naming patterns equivalent to:
.refine-plan-XXXXXX.refine-qa-XXXXXX.refine-plan-variant-XXXXXX.refine-qa-variant-XXXXXX
- If any temp write or translation step fails:
- Delete all temp files
- Leave existing final outputs untouched
- Report the failure
- Only after every temp file is written successfully may you replace final outputs.
- Replace auxiliary outputs before replacing the main in-place plan file, so the primary plan is updated last.
- If finalization fails after any destination was replaced, restore from backups if the environment allows it; otherwise report the partial-finalization risk explicitly.
Success condition:
- Main refined plan written successfully
- Main QA document written successfully
- Every requested variant written successfully
- No stale temp files remain
Report:
- Path to the refined plan
- Path to the QA document
- Paths to any generated variants
- Number of raw comments processed
- Counts by classification
- Whether pending decisions remain
- Final convergence status
- Whether refinement ran in
discussionordirectmode
If a blocking issue occurs:
- Report the exact phase where it failed
- Include the concrete reason
- Include any relevant line/column/context detail for parse errors
- Do not leave partially refined plan artifacts behind
If a user decision is needed in discussion mode:
- Ask only the narrowest question needed to proceed
- Record the decision in the QA document and, when still unresolved, in
## Pending User Decisions
If a decision is deferred in direct mode:
- Make the smallest safe assumption
- Record the assumption explicitly in the QA document
- Mark the plan as
partially_convergedwhen the deferred item materially affects implementation direction