Skip to content

Commit 0a0c9f3

Browse files
committed
feature: create plan-builder-agent skill, delete delegate-agent, fix invocation workflow
1 parent c377cda commit 0a0c9f3

12 files changed

Lines changed: 356 additions & 1301 deletions

File tree

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# State
22

3-
- **Status:** in-progress
4-
- **Progress:** 0%
3+
- **Status:** closed
4+
- **Progress:** 100%
55
- **Dependencies:** []
66
- **Blocks:** []
77
- **Target Branch:** v2.1
8+
- **Last Updated:** 2026-03-07
9+
- **Completed Waves:** Wave 1, Wave 2

client/src/main/java/io/github/cowwoc/cat/hooks/util/IssueCreator.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,27 @@ public String execute(String jsonInput, Path workingDirectory) throws IOExceptio
7070
throw new IOException("Input must be a JSON object, got: " + parsedNode.getNodeType());
7171
ObjectNode data = (ObjectNode) parsedNode;
7272

73-
String[] required = {"major", "minor", "issue_name", "state_content", "plan_content"};
73+
String[] required = {"major", "minor", "issue_name", "state_content"};
7474
for (String field : required)
7575
{
7676
if (!data.has(field))
7777
throw new IOException("Missing required field: " + field);
7878
}
79+
if (!data.has("plan_content") && !data.has("plan_file"))
80+
throw new IOException("Missing required field: plan_content or plan_file (provide one)");
7981

8082
int major = data.get("major").asInt();
8183
int minor = data.get("minor").asInt();
8284
String issueName = data.get("issue_name").asString();
8385
String stateContent = data.get("state_content").asString();
84-
String planContent = data.get("plan_content").asString();
86+
String planContent;
87+
if (data.has("plan_file"))
88+
{
89+
Path planSourceFile = Path.of(data.get("plan_file").asString());
90+
planContent = Files.readString(planSourceFile, StandardCharsets.UTF_8);
91+
}
92+
else
93+
planContent = data.get("plan_content").asString();
8594
String commitDesc;
8695
if (data.has("commit_description"))
8796
commitDesc = data.get("commit_description").asString();

plugin/concepts/subagent-delegation.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,68 @@ TaskCreate:
5757
description: "..."
5858
```
5959

60+
## Model Selection for Subagents
61+
62+
**MANDATORY: Always specify a model explicitly. Never use the default.**
63+
64+
Choose the model based on issue complexity:
65+
66+
| Issue Type | Model | Reasoning |
67+
|-----------|-------|-----------|
68+
| Skill invocation (orchestration only) | `haiku` | Skill is pure orchestration, subagent just runs it |
69+
| Skill invocation (skill exposes algorithm) | `sonnet` | Skill doc shows HOW to do it; haiku will apply algorithm manually |
70+
| Simple file operations | `haiku` | Explicit instructions, no reasoning needed |
71+
| Run commands, check output | `haiku` | Purely mechanical execution |
72+
| Code refactoring | `sonnet` | Requires understanding patterns and context |
73+
| Multi-file changes | `sonnet` | Needs to maintain consistency across files |
74+
| Exploration/research | `sonnet` | Requires judgment about what's relevant |
75+
| Complex logic changes | `sonnet` | Must reason about correctness |
76+
| Critical validation gates | `opus` | Asymmetric failure costs justify higher accuracy |
77+
78+
**Decision rule:** If the execution plan can be followed with zero reasoning (copy-paste level
79+
explicit), use `haiku`. If the subagent needs to understand WHY to do something correctly,
80+
use `sonnet`. If failure would be very costly or the task requires generating novel approaches,
81+
consider `opus`.
82+
83+
### When to Use Opus (Rare Cases)
84+
85+
**Opus is the exception, not the default.** Most delegated work should use haiku or sonnet.
86+
87+
Use Opus only when:
88+
89+
1. **Critical validation gates** - When the cost of a false positive (incorrectly passing) is much
90+
higher than the cost of running a more capable model. Examples:
91+
- Security review of authentication changes
92+
- Validating semantic equivalence of compressed documentation
93+
- Final quality gate before production deployment
94+
95+
2. **Complex architectural analysis** - Evaluating tradeoffs across multiple systems, identifying
96+
non-obvious dependencies, or reasoning about emergent behavior.
97+
98+
**Signal to reconsider delegation:** If you find yourself reaching for Opus, ask whether this work
99+
should be delegated at all. Work requiring Opus-level reasoning often benefits from:
100+
- Main agent handling it directly (with user oversight)
101+
- Breaking into smaller pieces that sonnet can handle
102+
- More explicit specifications that reduce reasoning requirements
103+
104+
**Anti-pattern:**
105+
```
106+
❌ model: "opus" for mechanical file operations (wasteful)
107+
❌ model: "opus" for straightforward code changes (sonnet suffices)
108+
❌ model: "opus" as a "just to be safe" default (defeats cost efficiency)
109+
✅ model: "opus" for security-critical validation gates
110+
```
111+
112+
**Anti-pattern:**
113+
```
114+
❌ Task tool: subagent_type: "general-purpose" (missing model - uses expensive default)
115+
❌ Task tool: model: "haiku" for code refactoring (will likely fail)
116+
❌ Task tool: model: "haiku" for "/cat:optimize-doc file.md" (skill exposes algorithm)
117+
✅ Task tool: model: "sonnet" for "/cat:optimize-doc file.md" (skill doc shows HOW, needs reasoning)
118+
✅ Task tool: model: "sonnet" for "refactor these 4 handlers" (needs reasoning)
119+
✅ Task tool: model: "haiku" for "/cat:status" (pure orchestration, no algorithm exposed)
120+
```
121+
60122
## Core Constraint
61123

62124
**Claude Code does not allow users to supervise subagent execution.**

plugin/skills/add/first-use.md

Lines changed: 21 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -818,116 +818,35 @@ Use appropriate template format:
818818
- **Blocks:** []
819819
```
820820

821-
**Generate PLAN.md content based on issue type:**
821+
**Generate PLAN.md via plan-builder-agent:**
822822

823-
Use appropriate template (Feature, Bugfix, or Refactor) from issue-plan.md reference.
823+
Invoke the plan-builder-agent skill to generate the PLAN.md. This centralizes all planning logic (effort-based depth,
824+
comprehensiveness requirements, sub-agent waves, templates) in one place.
824825

825-
**CRITICAL:** Follow template guidance to separate Sub-Agent Waves/Steps (actions only) from Success Criteria
826-
(measurable outcomes). Do NOT include expected values like "score = 1.0" in Execution sections as this primes subagents
827-
to fabricate
828-
results.
826+
1. Write a temporary context file with the issue details:
829827

830-
**PLAN.md Comprehensiveness:** The PLAN.md must be comprehensive enough for a haiku-level
831-
model to implement mechanically without making architectural decisions. Include:
832-
- Exact file paths to create/modify
833-
- Specific code patterns or formats to use
834-
- Complete lists (all files, all references to update, all post-conditions)
835-
- Research findings that inform implementation decisions
836-
837-
If the execution subagent needs to make judgment calls about "how" to implement, the PLAN.md
838-
is not detailed enough. The subagent should only decide "how to write the code", not "what approach to take".
839-
840-
**Effort-Based Planning Depth:**
841-
842-
Use the EFFORT value set in issue_read_config to calibrate planning thoroughness.
843-
844-
Apply the following depth to PLAN.md content based on `$EFFORT`:
845-
846-
- `low`: Generate a concise plan. Assume the obvious approach. Skip alternative analysis. List only essential steps
847-
and post-conditions.
848-
- `medium`: Explore two or three alternative approaches before settling on one. Note key trade-offs in a brief
849-
section. Execution steps should cover non-obvious edge cases.
850-
- `high`: Perform deep research on the problem space. Document the reasoning for the chosen approach and explicitly
851-
list rejected alternatives with rationale. Execution steps must cover all known edge cases and failure modes.
852-
853-
**Batch Execution Check:** When the issue involves multiple files AND a skill (e.g., compress 9 files with
854-
/cat:optimize-doc-agent):
855-
1. Read the target skill's documentation for batch/parallel execution patterns
856-
2. If the skill documents using `/cat:delegate-agent` for multiple files, write execution steps to use delegate
857-
3. Example: Instead of "For each file: Run /cat:optimize-doc-agent", use "/cat:delegate-agent --skill optimize-doc-agent file1.md file2.md
858-
..."
859-
860-
This ensures batch tasks leverage parallel execution rather than sequential processing.
861-
862-
**Sub-Agent Waves for Parallel Execution:** When the issue has clearly independent work that can run simultaneously,
863-
use `## Sub-Agent Waves` with `### Wave N` sections to enable parallel subagent spawning. Use sparingly — only when
864-
items genuinely don't depend on each other and won't modify the same files.
865-
866-
Rules for sub-agent waves:
867-
- Create `## Sub-Agent Waves` section (replaces `## Execution Steps`)
868-
- Each `### Wave N` subsection contains bullet items for parallel execution
869-
- Waves execute sequentially (Wave 1 completes before Wave 2 starts)
870-
- All items within a wave run in parallel
871-
- Waves must not modify the same files (to avoid merge conflicts)
872-
- The last wave is responsible for updating STATE.md
873-
874-
**Main Agent Waves (optional):** If the issue requires skills that spawn their own subagents (e.g.,
875-
`/cat:optimize-doc`, `/cat:compare-docs`, `/cat:stakeholder-review-agent`), add a `## Main Agent Waves` section
876-
**above** `## Sub-Agent Waves`. The main agent executes these skills directly before spawning implementation
877-
subagents. Each bullet is a skill invocation:
878-
879-
```markdown
880-
## Main Agent Waves
881-
882-
- /cat:optimize-doc path/to/file.md
883-
```
884-
885-
Omit `## Main Agent Waves` entirely when the issue has no pre-delegation skills.
886-
887-
Example valid sub-agent wave structure (independent modules):
888-
889-
```markdown
890-
## Sub-Agent Waves
891-
892-
### Wave 1
893-
- Implement parser module
894-
- Add parser tests
895-
896-
### Wave 2
897-
- Implement formatter module
898-
- Add formatter tests
899-
- Run full test suite
828+
```bash
829+
PLAN_CONTEXT="/tmp/plan-context-${ISSUE_NAME}.json"
830+
cat > "$PLAN_CONTEXT" << EOF
831+
{
832+
"issue_type": "${ISSUE_TYPE}",
833+
"description": "${ISSUE_DESCRIPTION}",
834+
"postconditions": ${POSTCONDITIONS_JSON},
835+
"research_findings": "${RESEARCH_FINDINGS:-}",
836+
"impact_notes": "${IMPACT_NOTES:-}"
837+
}
838+
EOF
900839
```
901840

902-
Do NOT use multiple waves if items share files or if the sequential dependency is unclear. In such cases, use a single
903-
`## Sub-Agent Waves` / `### Wave 1` section or revert to `## Execution Steps` for sequential execution.
904-
905-
**If RESEARCH_FINDINGS exists:**
906-
907-
Add a Research Findings section to PLAN.md after the Goal/Problem section:
841+
2. Invoke plan-builder-agent:
908842

909-
```markdown
910-
## Research Findings
911-
{RESEARCH_FINDINGS}
912843
```
913-
914-
This section should appear before the "Parent Requirements" section in all templates.
915-
916-
**If IMPACT_NOTES is non-empty:**
917-
918-
Add an Impact Notes section to PLAN.md after the Research Findings section (or after the Goal/Problem section if no
919-
Research Findings):
920-
921-
```markdown
922-
## Impact Notes
923-
{IMPACT_NOTES}
844+
Skill tool:
845+
skill: "cat:plan-builder-agent"
846+
args: "${CAT_AGENT_ID} ${EFFORT} initial ${PLAN_CONTEXT}"
924847
```
925848

926-
This section documents the potential impact of this issue on existing features, identified during issue creation.
927-
928-
**After generating STATE.md and PLAN.md content, create the issue:**
929-
930-
Call the create-issue binary with JSON input:
849+
3. Create the issue, passing the generated PLAN.md file path:
931850

932851
```bash
933852
"${CLAUDE_PLUGIN_ROOT}/client/bin/create-issue" --json '{
@@ -937,7 +856,7 @@ Call the create-issue binary with JSON input:
937856
"issue_type": "{issue-type}",
938857
"dependencies": ["{dep1}", "{dep2}"],
939858
"state_content": "{full STATE.md content}",
940-
"plan_content": "{full PLAN.md content}",
859+
"plan_file": "'"${PLAN_CONTEXT%.json}.plan.md"'",
941860
"commit_description": "{one-line description}"
942861
}'
943862
```

plugin/skills/consolidate-doc-agent/first-use.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ Extracted **56 semantic units** from original document, categorized as:
248248

249249
| Category | Count | Examples |
250250
|----------|-------|----------|
251-
| REQUIREMENT | 18 | Main agent only, report validation status, use delegate-agent |
251+
| REQUIREMENT | 18 | Main agent only, report validation status, spawn parallel subagents |
252252
| PROHIBITION | 8 | Never manually compress, cannot invoke from subagent |
253253
| SEQUENCE | 10 | Check baseline, save original, validate, iterate |
254254
| CONDITIONAL | 8 | If EQUIVALENT then approve, if NOT_EQUIVALENT then iterate |
@@ -302,7 +302,7 @@ GOAL: Complete compression with validation and optional iteration
302302
- **Missing from consolidated**: Validation Context explanation, exact decision logic algorithm,
303303
"don't ask user if ITERATE" requirement
304304
7. **Step 6: Iteration Loop** (u32-u37, u49-u50): Re-invoke with feedback, self-check, max 3 attempts
305-
8. **Step 7: Multiple Files** (u38-u40): Batch processing via delegate-agent
305+
8. **Step 7: Multiple Files** (u38-u40): Batch processing via parallel subagents
306306
9. **Supporting Details**: References (u44-u46), **u55-u56 missing** (File Operations, Rollback)
307307

308308
---

plugin/skills/delegate-agent/SKILL.md

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)