@dtlabs/ai-toolkit 0.1.6 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/agents/define-feature.md +1 -0
- package/.claude/agents/dependency-injection-refactoring.md +1 -0
- package/.claude/agents/dependency-supply-chain-security.md +1 -0
- package/.claude/agents/developer-backend.md +1 -0
- package/.claude/agents/developer-frontend.md +1 -0
- package/.claude/agents/developer-testing.md +1 -0
- package/.claude/agents/domain-model-refactoring.md +1 -0
- package/.claude/agents/god-class-decomposition.md +1 -0
- package/.claude/agents/init-agents-md.md +1 -0
- package/.claude/agents/install-toolkit.md +134 -3
- package/.claude/agents/intervention-documentation-standard.md +1 -0
- package/.claude/agents/review-solution.md +1 -0
- package/.claude/agents/security-hardening.md +1 -0
- package/.claude/commands/check-interventions.md +152 -0
- package/.claude/commands/next-intervention.md +113 -0
- package/.claude/settings.json +5 -0
- package/.claude/skills/assess-codebase/SKILL.md +139 -60
- package/.claude/skills/implement-feature/SKILL.md +208 -26
- package/.claude/workflows/am-phase1.js +304 -0
- package/.claude/workflows/am-phase2.js +166 -0
- package/.claude/workflows/pm-phase1.js +163 -0
- package/.claude/workflows/pm-phase2.js +108 -0
- package/.claude/workflows/pm-phase3.js +309 -0
- package/CHANGELOG.md +101 -3
- package/CLAUDE.md +34 -0
- package/README.md +26 -0
- package/bin/cli.js +64 -5
- package/docs/token-optimization-backlog.md +115 -0
- package/docs/token-optimization.md +274 -0
- package/package.json +1 -1
- package/.claude/agents/assessment-manager.md +0 -416
- package/.claude/agents/project-manager.md +0 -309
|
@@ -5,66 +5,150 @@ argument-hint: "[path] [--scope=architecture,security,quality,concurrency,devops
|
|
|
5
5
|
|
|
6
6
|
# Assess Codebase
|
|
7
7
|
|
|
8
|
-
Orchestrates the full codebase assessment pipeline by
|
|
9
|
-
|
|
8
|
+
Orchestrates the full codebase assessment pipeline by invoking two sequential workflow phases
|
|
9
|
+
(`am-phase1`, `am-phase2`), handling the Findings Gate in the main loop between the phases,
|
|
10
|
+
and recording the real token consumption at the end.
|
|
11
|
+
|
|
12
|
+
Each workflow phase runs as a real subagent boundary, ensuring assessment agents are dispatched
|
|
13
|
+
with accurate per-agent `usage` data and their declared `model:` frontmatter honoured.
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## Step 1 — Determine assessment prefix
|
|
18
|
+
|
|
19
|
+
Scan `docs/assessments/` for folders matching `ASSESS-[0-9]+*`. Increment the highest number
|
|
20
|
+
found, or start at `ASSESS-001`. This prefix is used for all output files in this run.
|
|
10
21
|
|
|
11
22
|
---
|
|
12
23
|
|
|
13
|
-
## Step
|
|
24
|
+
## Step 2 — Invoke am-phase1 (Assessment Phase)
|
|
14
25
|
|
|
15
|
-
|
|
26
|
+
Invoke the `am-phase1` workflow:
|
|
16
27
|
|
|
17
28
|
```
|
|
18
|
-
subagent_type:
|
|
19
|
-
prompt: <path> [--scope
|
|
29
|
+
subagent_type: am-phase1
|
|
30
|
+
prompt: <path> [--scope=<areas>] --prefix ASSESS-NNN [--force]
|
|
20
31
|
```
|
|
21
32
|
|
|
22
|
-
If no path
|
|
33
|
+
If no path was provided by the user, use `.` (current working directory).
|
|
34
|
+
Always pass `--prefix ASSESS-NNN` with the prefix determined in Step 1.
|
|
35
|
+
|
|
36
|
+
Wait for the workflow to complete. Capture its full result, including the `<usage>` block
|
|
37
|
+
(format: `subagent_tokens: N`). Extract from the result:
|
|
38
|
+
- `prefix` — confirmed assessment prefix
|
|
39
|
+
- `output_dir` — path to `docs/assessments/ASSESS-NNN/`
|
|
40
|
+
- `assessment_summaries` — list of `{ agent, output_file }` for each completed assessment
|
|
41
|
+
- `interventions_index_path` — path to `{PREFIX}-Interventions-Index.md`
|
|
42
|
+
- `severity_counts` — `{ CRITICAL, HIGH, MEDIUM, LOW }`
|
|
43
|
+
- `total_interventions` — total intervention count
|
|
44
|
+
- `remediation_hours_est` — estimated remediation hours
|
|
45
|
+
- `effort_estimate_path` — path to `{PREFIX}-Effort-Estimate.md`
|
|
46
|
+
- `token_estimate_path` — path to `{PREFIX}-Token-Estimate.md`
|
|
47
|
+
- `errors` — any agent failures during phase 1
|
|
48
|
+
|
|
49
|
+
If `errors` is non-empty, report them to the user before presenting the Findings Gate.
|
|
50
|
+
Partial assessments are acceptable — present the Findings Gate with available data.
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## Step 3 — Present Findings Gate (HARD STOP — present in main loop)
|
|
55
|
+
|
|
56
|
+
The Findings Gate has two mandatory steps.
|
|
57
|
+
|
|
58
|
+
### Step 3a — Acknowledge
|
|
59
|
+
|
|
60
|
+
Present the findings summary to the user:
|
|
61
|
+
|
|
62
|
+
```
|
|
63
|
+
Assessment complete for {prefix} — {output_dir}
|
|
64
|
+
────────────────────────────────────────────────────────────
|
|
65
|
+
Findings: {CRITICAL} CRITICAL | {HIGH} HIGH | {MEDIUM} MEDIUM | {LOW} LOW
|
|
66
|
+
Interventions: {total_interventions} proposed
|
|
67
|
+
────────────────────────────────────────────────────────────
|
|
68
|
+
Estimated remediation effort: {remediation_hours_est}h (human sequential)
|
|
69
|
+
Reference: {effort_estimate_path} for full breakdown
|
|
70
|
+
────────────────────────────────────────────────────────────
|
|
71
|
+
{list each assessment agent and its output file}
|
|
72
|
+
────────────────────────────────────────────────────────────
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Then output this hard-stop message and **wait for any non-empty text reply from the user**:
|
|
76
|
+
|
|
77
|
+
```
|
|
78
|
+
⛔ FINDINGS GATE — ASSESSMENT ACKNOWLEDGEMENT — HARD STOP
|
|
79
|
+
|
|
80
|
+
Please review the assessment findings above.
|
|
81
|
+
|
|
82
|
+
Reply with any text to acknowledge (e.g. "Acknowledged", "OK", "Proceed").
|
|
83
|
+
You will then be asked which interventions to flag for feature delivery.
|
|
84
|
+
|
|
85
|
+
The pipeline CANNOT continue until you reply directly.
|
|
86
|
+
```
|
|
23
87
|
|
|
24
|
-
|
|
25
|
-
that appears at the end of the tool result (format: `subagent_tokens: N`).
|
|
88
|
+
Capture the acknowledgement text.
|
|
26
89
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
90
|
+
### Step 3b — Flag interventions
|
|
91
|
+
|
|
92
|
+
After acknowledgement, read `{PREFIX}-Interventions-Index.md` and list all INT-NNN identifiers.
|
|
93
|
+
Present them to the user and prompt:
|
|
94
|
+
|
|
95
|
+
```
|
|
96
|
+
Which interventions do you want to flag for feature delivery?
|
|
97
|
+
|
|
98
|
+
{list of INT-NNN — title — criticality}
|
|
99
|
+
|
|
100
|
+
Reply with a comma-separated list of INT-NNN identifiers (e.g. "INT-001, INT-003"),
|
|
101
|
+
or reply "None" to flag nothing.
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Wait for a text reply. Validate each supplied identifier against the Interventions Index.
|
|
105
|
+
If any are unknown, list them and re-prompt once. Accept "None" for zero flagged.
|
|
106
|
+
|
|
107
|
+
Capture the flagged identifiers (as a comma-separated string, or "none").
|
|
30
108
|
|
|
31
109
|
---
|
|
32
110
|
|
|
33
|
-
## Step
|
|
111
|
+
## Step 4 — Invoke am-phase2 (Approvals and Registry Phase)
|
|
34
112
|
|
|
35
|
-
|
|
36
|
-
- `subagent_tokens` — total tokens consumed by the assessment-manager agent itself (input + output)
|
|
37
|
-
- `duration_ms` — wall-clock duration of the assessment-manager run
|
|
113
|
+
Invoke the `am-phase2` workflow:
|
|
38
114
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
115
|
+
```
|
|
116
|
+
subagent_type: am-phase2
|
|
117
|
+
prompt: --prefix {prefix} --output-dir {output_dir} --flagged {flagged_ids} --ack "{acknowledgement_text}"
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Where `{flagged_ids}` is the comma-separated list of INT-NNN identifiers (or "none").
|
|
121
|
+
|
|
122
|
+
Wait for the workflow to complete. Extract from the result:
|
|
123
|
+
- `approvals_path` — path to `{PREFIX}-Approvals.md`
|
|
124
|
+
- `registry_updated` — registry write result string
|
|
125
|
+
- `summary` — full assessment summary text
|
|
42
126
|
|
|
43
127
|
---
|
|
44
128
|
|
|
45
|
-
## Step
|
|
129
|
+
## Step 5 — Complete Token Estimate file
|
|
46
130
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
131
|
+
From the `<usage>` block of the am-phase1 result, read:
|
|
132
|
+
- `subagent_tokens` — total tokens consumed by the am-phase1 workflow
|
|
133
|
+
- `duration_ms` — wall-clock duration of am-phase1
|
|
50
134
|
|
|
51
|
-
|
|
135
|
+
If the `<usage>` block is missing: log warning
|
|
136
|
+
`"am-phase1 produced no <usage> block; orchestrator token data unavailable"`
|
|
137
|
+
and set `actual_tokens = "N/A"`.
|
|
52
138
|
|
|
53
|
-
|
|
139
|
+
Read `{token_estimate_path}`. Append the following in order:
|
|
54
140
|
|
|
55
|
-
|
|
141
|
+
### 5a — Orchestrator row (for use in 5b only)
|
|
56
142
|
|
|
143
|
+
Compute values:
|
|
57
144
|
- Estimated tokens: 80,000 (baseline from estimation model)
|
|
58
|
-
- Estimated cost: $0.4320 —
|
|
59
|
-
|
|
60
|
-
- Actual
|
|
61
|
-
- Actual cost: `(actual_tokens / 1,000) × blended_rate_per_1k`, formatted to 4 decimal places; `"N/A"` if actual_tokens is `"N/A"` or pricing data is unavailable
|
|
145
|
+
- Estimated cost: $0.4320 — `80,000 × $0.005400 / 1,000` using sonnet blended rate
|
|
146
|
+
- Actual tokens: `subagent_tokens` from `<usage>` block; `"N/A"` if missing
|
|
147
|
+
- Actual cost: `(actual_tokens / 1,000) × 0.005400` at 4 decimal places; `"N/A"` if unavailable
|
|
62
148
|
|
|
63
|
-
###
|
|
149
|
+
### 5b — Actuals vs Estimate section
|
|
64
150
|
|
|
65
|
-
Append a horizontal rule (`---`) followed by
|
|
66
|
-
row for every agent that ran: all assessment agents, intervention-documentation-standard,
|
|
67
|
-
and the assessment-manager orchestrator.
|
|
151
|
+
Append a horizontal rule (`---`) followed by:
|
|
68
152
|
|
|
69
153
|
```markdown
|
|
70
154
|
## Actuals vs Estimate
|
|
@@ -72,19 +156,18 @@ and the assessment-manager orchestrator.
|
|
|
72
156
|
| Agent | Task/Scope | Model | Est. tokens | Actual tokens | Delta | Est. cost ($) | Actual cost ($) | Duration |
|
|
73
157
|
|-------|------------|-------|-------------|---------------|-------|---------------|-----------------|----------|
|
|
74
158
|
| {agent} | {scope} | {model} | {est} | {actual} | {±delta} | {est_cost} | {actual_cost} | {Xmin Ys} |
|
|
159
|
+
...
|
|
160
|
+
| assessment-manager/am-phase1 (orchestrator) | — | sonnet | 80,000 | {actual} | ±{delta} | $0.4320 | ${actual_cost} | {duration} |
|
|
75
161
|
```
|
|
76
162
|
|
|
77
163
|
Column rules:
|
|
78
|
-
- **Delta**: `actual_tokens − est_tokens`; show as `+N` or `−N`. Show `"N/A"` if either
|
|
79
|
-
value is missing.
|
|
164
|
+
- **Delta**: `actual_tokens − est_tokens`; show as `+N` or `−N`. Show `"N/A"` if either missing.
|
|
80
165
|
- **Duration**: convert `duration_ms` to `Xmin Ys` where available; use `"—"` where not.
|
|
81
|
-
- Rows with `"N/A"` actual tokens are still shown
|
|
82
|
-
aggregate calculations.
|
|
166
|
+
- Rows with `"N/A"` actual tokens are still shown but excluded from aggregate calculations.
|
|
83
167
|
|
|
84
|
-
###
|
|
168
|
+
### 5c — Estimation accuracy by agent type (conditional)
|
|
85
169
|
|
|
86
|
-
If 2
|
|
87
|
-
(e.g., haiku AND sonnet), append:
|
|
170
|
+
If 2+ distinct model tiers appear with non-N/A actuals, append:
|
|
88
171
|
|
|
89
172
|
```markdown
|
|
90
173
|
## Estimation accuracy by agent type
|
|
@@ -94,16 +177,13 @@ If 2 or more distinct model tiers appear in the rows that have non-`"N/A"` actua
|
|
|
94
177
|
| {model} | {N} | {avg_est} | {avg_actual} | {avg_delta} | {trend} |
|
|
95
178
|
```
|
|
96
179
|
|
|
97
|
-
Column rules:
|
|
98
180
|
- One row per model tier (e.g., `haiku`, `sonnet`)
|
|
99
|
-
- Exclude
|
|
100
|
-
- **Trend**: `"over-target"` if avg delta > +20% of avg est; `"under-target"` if
|
|
101
|
-
< −20% of avg est; otherwise `"on-target"`
|
|
181
|
+
- Exclude N/A rows from averages
|
|
182
|
+
- **Trend**: `"over-target"` if avg delta > +20% of avg est; `"under-target"` if < −20%; else `"on-target"`
|
|
102
183
|
|
|
103
|
-
###
|
|
184
|
+
### 5d — Grand Total section
|
|
104
185
|
|
|
105
|
-
Update the Grand Total section
|
|
106
|
-
`"partial — updated at pipeline end"` marker with `"Final"` and fill in the computed values:
|
|
186
|
+
Update the Grand Total section: replace `"partial — updated at pipeline end"` with Final values:
|
|
107
187
|
|
|
108
188
|
```markdown
|
|
109
189
|
## Grand Total (Final)
|
|
@@ -115,27 +195,26 @@ Update the Grand Total section already written in the file: replace the
|
|
|
115
195
|
| Total wall-clock | — | {Xmin Ys} | — | — |
|
|
116
196
|
```
|
|
117
197
|
|
|
118
|
-
|
|
119
|
-
- **Delta %**: `(delta / estimated) × 100` at 1 decimal place; show `"N/A"` if estimated is 0
|
|
120
|
-
|
|
121
|
-
Summation rules:
|
|
198
|
+
- **Delta %**: `(delta / estimated) × 100` at 1 decimal place; `"N/A"` if estimated is 0
|
|
122
199
|
- Sum all agents' tokens and costs; exclude `"N/A"` rows from sums
|
|
123
|
-
- Cost
|
|
124
|
-
- The "Remediation" section
|
|
125
|
-
- Wall-clock: convert `duration_ms` from
|
|
200
|
+
- Cost: 2 decimal places for totals; 4 decimal places for per-row costs
|
|
201
|
+
- The "Remediation" section contains a static note — leave it as-is
|
|
202
|
+
- Wall-clock: convert `duration_ms` from am-phase1 `<usage>` to minutes/seconds
|
|
126
203
|
|
|
127
204
|
---
|
|
128
205
|
|
|
129
|
-
## Step
|
|
206
|
+
## Step 6 — Report to user
|
|
130
207
|
|
|
131
208
|
After writing to the Token Estimate file, report:
|
|
132
209
|
|
|
133
210
|
```
|
|
134
211
|
Assessment pipeline complete.
|
|
135
|
-
Token estimate + actuals → {
|
|
136
|
-
Approvals →
|
|
137
|
-
Process log →
|
|
212
|
+
Token estimate + actuals → {token_estimate_path}
|
|
213
|
+
Approvals → {approvals_path}
|
|
214
|
+
Process log → {output_dir}/{prefix}-process-log.txt
|
|
215
|
+
|
|
216
|
+
{summary from am-phase2}
|
|
138
217
|
```
|
|
139
218
|
|
|
140
|
-
If the Token Estimate file does not exist (
|
|
219
|
+
If the Token Estimate file does not exist (am-phase1 failed before writing it):
|
|
141
220
|
note this in the report but do not halt — the skill has completed its work.
|
|
@@ -5,65 +5,247 @@ argument-hint: <path-to-feature.md> [--force]
|
|
|
5
5
|
|
|
6
6
|
# Implement Feature
|
|
7
7
|
|
|
8
|
-
Orchestrates the full feature delivery pipeline by
|
|
9
|
-
|
|
8
|
+
Orchestrates the full feature delivery pipeline by invoking three sequential workflow phases
|
|
9
|
+
(`pm-phase1`, `pm-phase2`, `pm-phase3`), handling approval gates in the main loop between
|
|
10
|
+
each phase, and recording the real token consumption at the end.
|
|
11
|
+
|
|
12
|
+
Each workflow phase runs as a real subagent boundary, ensuring worker agents are dispatched
|
|
13
|
+
with their declared `model:` frontmatter honoured and producing accurate per-agent `usage` data.
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## Step 1 — Invoke pm-phase1 (Documentation Phase)
|
|
18
|
+
|
|
19
|
+
Invoke the `pm-phase1` workflow with the feature path:
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
subagent_type: pm-phase1
|
|
23
|
+
prompt: <path-to-feature.md>
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Wait for the workflow to complete. Do NOT proceed until it returns.
|
|
27
|
+
|
|
28
|
+
Extract from the result:
|
|
29
|
+
- `prefix` — feature prefix (e.g. `FTR-009`)
|
|
30
|
+
- `requirements.summary` — requirements file summary
|
|
31
|
+
- `tech_spec.summary` — tech-spec file summary
|
|
32
|
+
- `validation.summary` — validation result (gaps or clean)
|
|
33
|
+
- `token_ledger` — array of per-agent token data from phase 1
|
|
34
|
+
- `errors` — any agent failures during phase 1
|
|
35
|
+
|
|
36
|
+
If `errors` is non-empty, report them to the user but continue to Gate 1 if the
|
|
37
|
+
required documents were produced.
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## Step 2 — Present Gate 1 (HARD STOP — present in main loop)
|
|
42
|
+
|
|
43
|
+
Present the following to the user:
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
Documents generated for {PREFIX}:
|
|
47
|
+
|
|
48
|
+
{PREFIX}-Requirements.md — {requirements.summary}
|
|
49
|
+
{PREFIX}-Tech-Spec.md — {tech_spec.summary}
|
|
50
|
+
{PREFIX}-Validation-Report.md — {validation.summary}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Then output this hard-stop message and **wait for a text reply from the user**:
|
|
54
|
+
|
|
55
|
+
```
|
|
56
|
+
⛔ GATE 1 — DOCS APPROVAL — HARD STOP
|
|
57
|
+
|
|
58
|
+
Please review the documents above and reply with one of:
|
|
59
|
+
|
|
60
|
+
"Approve — proceed to Work Breakdown"
|
|
61
|
+
"Request changes: <describe what to change>"
|
|
62
|
+
"Approve with notes: <your comments>"
|
|
63
|
+
|
|
64
|
+
The pipeline CANNOT continue until you reply directly.
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
**If the user requests changes:** note them and stop. Do not invoke pm-phase2.
|
|
68
|
+
|
|
69
|
+
**If the user approves:** immediately write `{PREFIX}-Approvals.md`:
|
|
70
|
+
|
|
71
|
+
```markdown
|
|
72
|
+
# Approval Record — {PREFIX}
|
|
73
|
+
|
|
74
|
+
## Gate 1 — Document Approvals
|
|
75
|
+
|
|
76
|
+
| Document | Status | Date | Notes |
|
|
77
|
+
|----------|--------|------|-------|
|
|
78
|
+
| {PREFIX}-Requirements.md | ✅ Approved | {today} | {notes or —} |
|
|
79
|
+
| {PREFIX}-Tech-Spec.md | ✅ Approved | {today} | {notes or —} |
|
|
80
|
+
| {PREFIX}-Validation-Report.md | ✅ Approved | {today} | {notes or —} |
|
|
81
|
+
|
|
82
|
+
## Approval History
|
|
83
|
+
|
|
84
|
+
| Cycle | Action | Date | Details |
|
|
85
|
+
|-------|--------|------|---------|
|
|
86
|
+
| 1 | Approved | {today} | {user reply text} |
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Read back `{PREFIX}-Approvals.md` and verify it exists with Gate 1 ✅ before continuing.
|
|
90
|
+
If the file is missing or incomplete, write it again before proceeding.
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
## Step 3 — Invoke pm-phase2 (Work Breakdown Phase)
|
|
95
|
+
|
|
96
|
+
Invoke the `pm-phase2` workflow:
|
|
97
|
+
|
|
98
|
+
```
|
|
99
|
+
subagent_type: pm-phase2
|
|
100
|
+
prompt: <path-to-feature.md>
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Wait for the workflow to complete. Extract from the result:
|
|
104
|
+
- `user_stories` — number of User Stories
|
|
105
|
+
- `total_tasks` — total task count
|
|
106
|
+
- `domain_breakdown` — tasks per domain
|
|
107
|
+
- `implementation_phases` — number of phases
|
|
108
|
+
- `human_estimate` — human sequential estimate
|
|
109
|
+
- `agent_estimate` — agent parallel estimate
|
|
110
|
+
- `token_ledger` — per-agent token data from phase 2
|
|
10
111
|
|
|
11
112
|
---
|
|
12
113
|
|
|
13
|
-
## Step
|
|
114
|
+
## Step 4 — Present Gate 2 (HARD STOP — present in main loop)
|
|
115
|
+
|
|
116
|
+
Pre-condition check: read `{PREFIX}-Approvals.md` and verify Gate 1 ✅ is present.
|
|
117
|
+
If missing, return to Step 2.
|
|
118
|
+
|
|
119
|
+
Present the following to the user:
|
|
120
|
+
|
|
121
|
+
```
|
|
122
|
+
Work Breakdown for {PREFIX}:
|
|
123
|
+
|
|
124
|
+
User Stories: {user_stories} (US-01 ÷ US-{NN})
|
|
125
|
+
Total tasks: {total_tasks} ({domain_breakdown})
|
|
126
|
+
Implementation phases: {implementation_phases}
|
|
127
|
+
Human estimate: {human_estimate} | Agent estimate: {agent_estimate}
|
|
128
|
+
Reference: {PREFIX}-Effort-Estimate.md for full detail
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Then output this hard-stop message and **wait for a text reply from the user**:
|
|
132
|
+
|
|
133
|
+
```
|
|
134
|
+
⛔ GATE 2 — WORK BREAKDOWN APPROVAL — HARD STOP
|
|
135
|
+
|
|
136
|
+
Please review the Work Breakdown above and reply with one of:
|
|
137
|
+
|
|
138
|
+
"Approve — start implementation"
|
|
139
|
+
"Request changes: <describe what to change>"
|
|
140
|
+
"Approve with notes: <your comments>"
|
|
14
141
|
|
|
15
|
-
|
|
142
|
+
Implementation CANNOT start until you reply directly.
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
**If the user requests changes:** note them and stop. Do not invoke pm-phase3.
|
|
146
|
+
|
|
147
|
+
**If the user approves:** append Gate 2 to `{PREFIX}-Approvals.md`:
|
|
148
|
+
|
|
149
|
+
```markdown
|
|
150
|
+
## Gate 2 — Work Breakdown Approval
|
|
16
151
|
|
|
152
|
+
| Document | Status | Date | Notes |
|
|
153
|
+
|----------|--------|------|-------|
|
|
154
|
+
| {PREFIX}-Work-Breakdown.md | ✅ Approved | {today} | {total_tasks} tasks, {implementation_phases} phases |
|
|
17
155
|
```
|
|
18
|
-
|
|
19
|
-
|
|
156
|
+
|
|
157
|
+
Read back `{PREFIX}-Approvals.md` and verify Gate 2 ✅ is present before continuing.
|
|
158
|
+
|
|
159
|
+
---
|
|
160
|
+
|
|
161
|
+
## Step 5 — Create feature branch
|
|
162
|
+
|
|
163
|
+
Before invoking pm-phase3, create the feature branch:
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
git checkout -b feature/{PREFIX}-{short-slug}
|
|
20
167
|
```
|
|
21
168
|
|
|
22
|
-
|
|
23
|
-
|
|
169
|
+
If the branch already exists, switch to it without recreating:
|
|
170
|
+
|
|
171
|
+
```bash
|
|
172
|
+
git checkout feature/{PREFIX}-{short-slug}
|
|
173
|
+
```
|
|
24
174
|
|
|
25
175
|
---
|
|
26
176
|
|
|
27
|
-
## Step
|
|
177
|
+
## Step 6 — Invoke pm-phase3 (Implementation Phase)
|
|
178
|
+
|
|
179
|
+
Pre-condition check: read `{PREFIX}-Approvals.md` and verify BOTH Gate 1 ✅ and Gate 2 ✅.
|
|
180
|
+
If either is missing, return to the missing gate.
|
|
181
|
+
|
|
182
|
+
Invoke the `pm-phase3` workflow:
|
|
28
183
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
184
|
+
```
|
|
185
|
+
subagent_type: pm-phase3
|
|
186
|
+
prompt: <path-to-feature.md> --branch feature/{PREFIX}-{short-slug}
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
Wait for the workflow to complete. Capture its full result, including the `<usage>` block
|
|
190
|
+
(format: `subagent_tokens: N`). Extract from the result:
|
|
191
|
+
- `pr_url` — the created pull request URL
|
|
192
|
+
- `token_ledger` — all per-agent token data from phase 3
|
|
193
|
+
- `issues_summary` — escalation and issues counts
|
|
194
|
+
|
|
195
|
+
If `issues_summary.escalations > 0`, report the escalation details to the user.
|
|
32
196
|
|
|
33
197
|
---
|
|
34
198
|
|
|
35
|
-
## Step
|
|
199
|
+
## Step 7 — Complete Token Estimate file
|
|
200
|
+
|
|
201
|
+
From the `<usage>` block of the pm-phase3 result, read:
|
|
202
|
+
- `subagent_tokens` — total tokens consumed by the pm-phase3 workflow
|
|
203
|
+
- `duration_ms` — wall-clock duration of pm-phase3
|
|
36
204
|
|
|
37
|
-
|
|
38
|
-
upfront estimate and the child agents' actuals. Read that file, then **append**
|
|
39
|
-
the orchestrator row and the grand total:
|
|
205
|
+
Read `{PREFIX}-Token-Estimate.md`. Append the orchestrator row and grand total:
|
|
40
206
|
|
|
41
207
|
```markdown
|
|
42
|
-
| project-manager (orchestrator) | — | sonnet |
|
|
208
|
+
| project-manager/pm-phase3 (orchestrator) | — | sonnet | 80,000 (estimated) | {subagent_tokens} (actual) | ±{delta} | {duration} |
|
|
43
209
|
|
|
44
210
|
---
|
|
45
211
|
|
|
46
|
-
|
|
212
|
+
## Actuals vs Estimate
|
|
213
|
+
|
|
214
|
+
| Agent | Task / Scope | Model | Est. tokens | Actual tokens | Delta | Est. cost ($) | Actual cost ($) | Duration |
|
|
215
|
+
|-------|-------------|-------|------------|---------------|-------|--------------|----------------|----------|
|
|
216
|
+
{one row per entry in token_ledger — from phase 1, 2, and 3}
|
|
217
|
+
| project-manager/pm-phase3 (orchestrator) | — | sonnet | 80,000 | {subagent_tokens} | ±{delta} | $0.4320 | ${actual_cost} | {duration} |
|
|
218
|
+
|
|
219
|
+
## Estimation accuracy by agent type
|
|
220
|
+
|
|
221
|
+
| Model | Count | Avg est. tokens | Avg actual tokens | Avg delta | Trend |
|
|
222
|
+
|-------|-------|----------------|------------------|-----------|-------|
|
|
223
|
+
{one row per model tier (haiku, sonnet) — exclude N/A rows from averages}
|
|
224
|
+
|
|
225
|
+
## Grand Total
|
|
47
226
|
|
|
48
227
|
| Metric | Estimated | Actual | Delta |
|
|
49
228
|
|--------|-----------|--------|-------|
|
|
50
|
-
| Total tokens (all agents) |
|
|
51
|
-
| Total
|
|
52
|
-
|
|
|
229
|
+
| Total tokens (all agents) | {sum_est} | {sum_actual} | ±{delta} |
|
|
230
|
+
| Total cost ($) | ${sum_est_cost} | ${sum_actual_cost} | ±${delta_cost} |
|
|
231
|
+
| Total wall-clock | — | {total_duration} | — |
|
|
53
232
|
```
|
|
54
233
|
|
|
55
|
-
|
|
56
|
-
|
|
234
|
+
> Per-agent values marked *(proportional)* are estimated distributions of the phase total.
|
|
235
|
+
> Phase totals and grand total are exact measurements from workflow subagent_tokens.
|
|
236
|
+
|
|
237
|
+
If the Token Estimate file does not exist (pm-phase3 failed before writing it), create it
|
|
238
|
+
from scratch using the data available in the token_ledger.
|
|
57
239
|
|
|
58
240
|
---
|
|
59
241
|
|
|
60
|
-
## Step
|
|
242
|
+
## Step 8 — Report to user
|
|
61
243
|
|
|
62
244
|
After writing the token file, report:
|
|
63
245
|
|
|
64
246
|
```
|
|
65
|
-
|
|
247
|
+
Feature pipeline complete.
|
|
66
248
|
Token estimate + actuals → {PREFIX}-Token-Estimate.md
|
|
67
249
|
Effort estimate + actuals → {PREFIX}-Effort-Estimate.md
|
|
68
|
-
Pull Request → {
|
|
250
|
+
Pull Request → {pr_url}
|
|
69
251
|
```
|