@alecsibilia/luca 13.0.0-alpha.1
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/LICENSE +201 -0
- package/README.md +47 -0
- package/bin/luca.js +3 -0
- package/dist/chunks/branch.mjs +47 -0
- package/dist/chunks/bun-runtime.mjs +46 -0
- package/dist/chunks/checks.mjs +53 -0
- package/dist/chunks/claim-verify.mjs +465 -0
- package/dist/chunks/classify.mjs +105 -0
- package/dist/chunks/confidence.mjs +199 -0
- package/dist/chunks/doctor.mjs +158 -0
- package/dist/chunks/hook.mjs +696 -0
- package/dist/chunks/init.mjs +715 -0
- package/dist/chunks/muninndb-health.mjs +66 -0
- package/dist/chunks/phase.mjs +38 -0
- package/dist/chunks/pr-review.mjs +122 -0
- package/dist/chunks/preferences.mjs +61 -0
- package/dist/chunks/repair.mjs +111 -0
- package/dist/chunks/repo.mjs +58 -0
- package/dist/chunks/retro.mjs +86 -0
- package/dist/chunks/roadmap.mjs +58 -0
- package/dist/chunks/rules.mjs +527 -0
- package/dist/chunks/stale-mcp-server.mjs +90 -0
- package/dist/chunks/state.mjs +57 -0
- package/dist/chunks/stray-local-install.mjs +200 -0
- package/dist/chunks/telemetry.mjs +165 -0
- package/dist/chunks/todo.mjs +151 -0
- package/dist/chunks/vault-init.mjs +300 -0
- package/dist/chunks/verification.mjs +95 -0
- package/dist/chunks/version.mjs +70 -0
- package/dist/chunks/workflow.mjs +47 -0
- package/dist/claude/.claude/agents/architect.md +410 -0
- package/dist/claude/.claude/agents/build.md +111 -0
- package/dist/claude/.claude/agents/discuss.md +93 -0
- package/dist/claude/.claude/agents/discussion.md +149 -0
- package/dist/claude/.claude/agents/execute.md +416 -0
- package/dist/claude/.claude/agents/executor.md +161 -0
- package/dist/claude/.claude/agents/fast.md +84 -0
- package/dist/claude/.claude/agents/finalize.md +484 -0
- package/dist/claude/.claude/agents/learner.md +160 -0
- package/dist/claude/.claude/agents/plan-reviewer.md +129 -0
- package/dist/claude/.claude/agents/plan.md +96 -0
- package/dist/claude/.claude/agents/research.md +327 -0
- package/dist/claude/.claude/agents/researcher.md +78 -0
- package/dist/claude/.claude/agents/review.md +283 -0
- package/dist/claude/.claude/agents/reviewer.md +163 -0
- package/dist/claude/.claude/agents/shadow-scanner.md +257 -0
- package/dist/claude/.claude/agents/triage.md +230 -0
- package/dist/claude/.claude/agents/verifier.md +131 -0
- package/dist/claude/.claude/commands/bug-diagnose.md +12 -0
- package/dist/claude/.claude/commands/gh-issue-triage.md +14 -0
- package/dist/claude/.claude/commands/gh-pr-address.md +235 -0
- package/dist/claude/.claude/commands/gh-prepare.md +12 -0
- package/dist/claude/.claude/commands/grill-me.md +12 -0
- package/dist/claude/.claude/commands/lu-review.md +51 -0
- package/dist/claude/.claude/commands/lu.md +75 -0
- package/dist/claude/.claude/commands/luca-init.md +14 -0
- package/dist/claude/.claude/commands/luca-telemetry-report.md +12 -0
- package/dist/claude/.claude/commands/memory-audit.md +12 -0
- package/dist/claude/.claude/commands/milestone-new.md +122 -0
- package/dist/claude/.claude/commands/phase-discuss.md +45 -0
- package/dist/claude/.claude/commands/phase-execute.md +39 -0
- package/dist/claude/.claude/commands/phase-plan.md +53 -0
- package/dist/claude/.claude/commands/repo-cleanup.md +80 -0
- package/dist/claude/.claude/commands/todo-add.md +28 -0
- package/dist/claude/.claude/commands/todo-check.md +36 -0
- package/dist/claude/.claude/hooks/context-refresher.ts +285 -0
- package/dist/claude/.claude/hooks/continuation-messages.ts +215 -0
- package/dist/claude/.claude/hooks/pipeline-guard.ts +182 -0
- package/dist/claude/.claude/settings.json +41 -0
- package/dist/claude/skills/arch-audit/SKILL.md +161 -0
- package/dist/claude/skills/autopilot/SKILL.md +1299 -0
- package/dist/claude/skills/bug-diagnose/SKILL.md +102 -0
- package/dist/claude/skills/choose/SKILL.md +124 -0
- package/dist/claude/skills/gh-issue-triage/SKILL.md +97 -0
- package/dist/claude/skills/gh-pr-address/SKILL.md +235 -0
- package/dist/claude/skills/gh-prepare/SKILL.md +209 -0
- package/dist/claude/skills/grill-me/SKILL.md +46 -0
- package/dist/claude/skills/lu/SKILL.md +112 -0
- package/dist/claude/skills/lu-review/SKILL.md +51 -0
- package/dist/claude/skills/luca-init/SKILL.md +91 -0
- package/dist/claude/skills/luca-telemetry-report/SKILL.md +145 -0
- package/dist/claude/skills/luca-write-surface/SKILL.md +213 -0
- package/dist/claude/skills/memory-audit/SKILL.md +217 -0
- package/dist/claude/skills/milestone-audit/SKILL.md +545 -0
- package/dist/claude/skills/milestone-complete/SKILL.md +168 -0
- package/dist/claude/skills/milestone-gaps/SKILL.md +60 -0
- package/dist/claude/skills/milestone-new/SKILL.md +125 -0
- package/dist/claude/skills/note/SKILL.md +162 -0
- package/dist/claude/skills/phase-add/SKILL.md +91 -0
- package/dist/claude/skills/phase-assumptions/SKILL.md +92 -0
- package/dist/claude/skills/phase-discuss/SKILL.md +165 -0
- package/dist/claude/skills/phase-execute/SKILL.md +1786 -0
- package/dist/claude/skills/phase-insert/SKILL.md +100 -0
- package/dist/claude/skills/phase-plan/SKILL.md +461 -0
- package/dist/claude/skills/phase-remove/SKILL.md +113 -0
- package/dist/claude/skills/phase-research/SKILL.md +80 -0
- package/dist/claude/skills/post-init-tour/SKILL.md +58 -0
- package/dist/claude/skills/progress/SKILL.md +271 -0
- package/dist/claude/skills/project-new/SKILL.md +609 -0
- package/dist/claude/skills/quick/SKILL.md +256 -0
- package/dist/claude/skills/rename-audit/SKILL.md +52 -0
- package/dist/claude/skills/repo-audit/SKILL.md +88 -0
- package/dist/claude/skills/repo-cleanup/SKILL.md +80 -0
- package/dist/claude/skills/seed-memory/SKILL.md +235 -0
- package/dist/claude/skills/session-pause/SKILL.md +126 -0
- package/dist/claude/skills/session-plan/SKILL.md +112 -0
- package/dist/claude/skills/session-resume/SKILL.md +75 -0
- package/dist/claude/skills/todo-add/SKILL.md +85 -0
- package/dist/claude/skills/todo-check/SKILL.md +77 -0
- package/dist/claude/skills/workflow-save/SKILL.md +277 -0
- package/dist/index.d.mts +33 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.mjs +69 -0
- package/dist/shared/luca.B3Mimc0P.mjs +52 -0
- package/dist/shared/luca.B3saVjJm.mjs +163 -0
- package/dist/shared/luca.BYdjkfnz.mjs +217 -0
- package/dist/shared/luca.BmhNkYe2.mjs +56 -0
- package/dist/shared/luca.C4gMUoBd.mjs +358 -0
- package/dist/shared/luca.CQ3g1xrD.mjs +19 -0
- package/dist/shared/luca.CRmaAfXR.mjs +713 -0
- package/dist/shared/luca.CrXzXueR.mjs +57 -0
- package/dist/shared/luca.DTomPq7I.mjs +91 -0
- package/dist/shared/luca.DjDTeDCi.mjs +1904 -0
- package/dist/shared/luca.HZxBTBgD.mjs +201 -0
- package/dist/shared/luca.TSMg1t7I.mjs +10 -0
- package/dist/shared/luca.dM-MKlNE.mjs +25 -0
- package/dist/shared/luca.naWEcQ4B.mjs +7 -0
- package/package.json +76 -0
|
@@ -0,0 +1,1786 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: phase-execute
|
|
3
|
+
description: Execute all plans in a phase with wave-based parallelization and harness verification.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
<main>
|
|
7
|
+
# Luca Execute Phase
|
|
8
|
+
|
|
9
|
+
Execute all plans in a phase using wave-based parallel execution, then verify with code review and UAT.
|
|
10
|
+
|
|
11
|
+
Orchestrator stays lean: discover plans, analyze dependencies, group into waves, spawn subagents, collect results. Each subagent loads the full execute-plan context and handles its own plan.
|
|
12
|
+
|
|
13
|
+
**Arguments:** `<phase-number> [--gaps-only] [--quality-fixes] [--skip-review] [--skip-uat] [--skip-memory] [--skip-replay]`
|
|
14
|
+
|
|
15
|
+
## Sub-agent Delegation Requirements
|
|
16
|
+
|
|
17
|
+
This skill is an **orchestrator**. YOU MUST delegate work to sub-agents using the Task tool.
|
|
18
|
+
|
|
19
|
+
**Required sub-agents for this skill:**
|
|
20
|
+
|
|
21
|
+
- `executor` - Executes individual tasks (PARALLEL per wave)
|
|
22
|
+
- `verifier` - Verifies the phase goal is achieved
|
|
23
|
+
- `learner` - Extracts learnings after verification
|
|
24
|
+
- `reviewer` - Multi-perspective code review (one Task() spawn per perspective)
|
|
25
|
+
- `shadow-scanner` - Scans for AI-session debris at milestone boundaries
|
|
26
|
+
- For "plan a fix" cycles: re-invoke the architect mode-agent (which performs planning in v13 — the v12-era `lu-planner` subagent was dropped per plan §5.6).
|
|
27
|
+
- For plan-validation cycles: spawn the `plan-reviewer` subagent.
|
|
28
|
+
|
|
29
|
+
**DO NOT** attempt to execute plans, verify, or review code yourself. Spawn the appropriate subagent via the `Task` tool, or invoke the appropriate mode-agent.
|
|
30
|
+
|
|
31
|
+
## Context-Aware Sub-Agent Spawning (Phase 16+)
|
|
32
|
+
|
|
33
|
+
Each sub-agent receives only the context documents appropriate for its role and the current task complexity. The orchestrator assembles context per these rules:
|
|
34
|
+
|
|
35
|
+
**Context Tiers:**
|
|
36
|
+
| Tier | Documents Loaded |
|
|
37
|
+
|------|-----------------|
|
|
38
|
+
| T0 | Plan content only |
|
|
39
|
+
| T1 | + project identity summary (from MuninnDB brain:*) |
|
|
40
|
+
| T2 | + workflow state (state.json) + selective learnings + session context (from MuninnDB) |
|
|
41
|
+
| T3 | + full project identity + full learnings + agent summaries (from MuninnDB) |
|
|
42
|
+
|
|
43
|
+
**Isolation Modes:**
|
|
44
|
+
| Mode | Restriction | Used By |
|
|
45
|
+
|------|------------|---------|
|
|
46
|
+
| none | Full context per tier | executor, learner |
|
|
47
|
+
| cold | Only git diff + project identity | reviewer perspectives (architect, security, simplification, dx) |
|
|
48
|
+
| warm | Plans + summaries, NO session context | verifier |
|
|
49
|
+
|
|
50
|
+
**Complexity promotes context:** At MODERATE+, sub-agents may receive one tier higher than their default.
|
|
51
|
+
|
|
52
|
+
## Always Verify & Learning Capture (NEW)
|
|
53
|
+
|
|
54
|
+
**Luca mandates verification at all levels.** After execution completes:
|
|
55
|
+
|
|
56
|
+
### Verification
|
|
57
|
+
|
|
58
|
+
Invoke lu-verifier with mode based on phase complexity:
|
|
59
|
+
|
|
60
|
+
| Phase Scope | Verification Mode |
|
|
61
|
+
| ------------------ | ------------------------------- |
|
|
62
|
+
| Simple (1-2 plans) | Standard verification |
|
|
63
|
+
| Complex (3+ plans) | Full goal-backward verification |
|
|
64
|
+
|
|
65
|
+
**Verification always runs** - there is no skip option for verification in Luca.
|
|
66
|
+
|
|
67
|
+
### Learning Capture
|
|
68
|
+
|
|
69
|
+
After verification (pass or fail):
|
|
70
|
+
|
|
71
|
+
**MANDATORY**: You MUST spawn a lu-learner sub-agent. Do NOT attempt to capture learnings yourself.
|
|
72
|
+
|
|
73
|
+
First, read the required context:
|
|
74
|
+
|
|
75
|
+
Use MuninnDB to recall session context and past learnings:
|
|
76
|
+
|
|
77
|
+
```
|
|
78
|
+
# Recall current session findings
|
|
79
|
+
mcp__muninn__muninn_recall(vault: "default", context: "current session context and findings")
|
|
80
|
+
|
|
81
|
+
# Recall relevant patterns and past decisions
|
|
82
|
+
mcp__muninn__muninn_recall(vault: "default", context: "relevant patterns and past decisions for this phase")
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
VERIFICATION_RESULT="[from verifier return value]"
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Then spawn the learner:
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
Task(
|
|
93
|
+
prompt="""
|
|
94
|
+
<learning_context>
|
|
95
|
+
|
|
96
|
+
**Phase:** {phase_number}
|
|
97
|
+
**Verification Result:** {verification_result}
|
|
98
|
+
|
|
99
|
+
**Working Memory (session findings):**
|
|
100
|
+
{working_content}
|
|
101
|
+
|
|
102
|
+
**Current Long-Term Memory:**
|
|
103
|
+
{memory_content}
|
|
104
|
+
|
|
105
|
+
</learning_context>
|
|
106
|
+
|
|
107
|
+
<extraction_targets>
|
|
108
|
+
1. **Patterns**: What execution approaches worked well?
|
|
109
|
+
2. **Decisions**: What implementation choices were made?
|
|
110
|
+
3. **Pitfalls**: What issues were encountered during execution?
|
|
111
|
+
4. **Preferences**: What conventions emerged from this phase?
|
|
112
|
+
</extraction_targets>
|
|
113
|
+
|
|
114
|
+
<output_requirements>
|
|
115
|
+
- Extract ONLY validated learnings (verified by outcome)
|
|
116
|
+
- Write curated insights to MuninnDB via muninn_remember
|
|
117
|
+
- Clear session context via muninn_forget after extraction
|
|
118
|
+
- Return summary of learnings captured
|
|
119
|
+
</output_requirements>
|
|
120
|
+
|
|
121
|
+
Extract learnings from this phase execution and store in MuninnDB.
|
|
122
|
+
""",
|
|
123
|
+
subagent_type="lu-learner",
|
|
124
|
+
model="{learner_model}",
|
|
125
|
+
description="Capture phase learnings"
|
|
126
|
+
)
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
**Do NOT proceed until the Task returns.**
|
|
130
|
+
|
|
131
|
+
**Learning capture always runs.** The lu-learner model tier is resolved from the routing table based on complexity:
|
|
132
|
+
|
|
133
|
+
| Complexity | Learning Depth | Model Tier (from routing table) |
|
|
134
|
+
| ---------- | ----------------------------------------------- | ------------------------------- |
|
|
135
|
+
| TRIVIAL | Standard (spawn with minimal context) | fast |
|
|
136
|
+
| SIMPLE | Standard (spawn with minimal context) | fast |
|
|
137
|
+
| MODERATE | Standard (current behavior) | fast |
|
|
138
|
+
| COMPLEX | Full (include all working memory) | fast |
|
|
139
|
+
| CRITICAL | Full + debrief (include retrospective analysis) | balanced |
|
|
140
|
+
|
|
141
|
+
For TRIVIAL/SIMPLE: Include only execution summary, not full working memory.
|
|
142
|
+
For MODERATE and above: Use the current lu-learner spawn as-is.
|
|
143
|
+
For CRITICAL: Add to the lu-learner prompt: "Include a retrospective analysis: what went well, what didn't, what would you do differently?"
|
|
144
|
+
|
|
145
|
+
The model tier for lu-learner is resolved via `resolveModelForAgent("lu-learner", complexity)` from the centralized routing table in `src/complexity/__helpers/model-routing.ts`.
|
|
146
|
+
|
|
147
|
+
### Session Logging During Execution
|
|
148
|
+
|
|
149
|
+
Throughout execution, log findings to MuninnDB:
|
|
150
|
+
|
|
151
|
+
Log execution progress to MuninnDB:
|
|
152
|
+
|
|
153
|
+
```
|
|
154
|
+
mcp__muninn__muninn_remember(vault: "default", concept: "session:findings", content: "[timestamp] [Plan X complete - finding Y]")
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Track:
|
|
158
|
+
|
|
159
|
+
- Execution findings and observations
|
|
160
|
+
- Issues encountered and how resolved
|
|
161
|
+
- Patterns that worked well (learning candidates)
|
|
162
|
+
- Decisions made during implementation
|
|
163
|
+
|
|
164
|
+
## Process
|
|
165
|
+
|
|
166
|
+
### 0. Resolve Model Profile
|
|
167
|
+
|
|
168
|
+
```bash
|
|
169
|
+
MODEL_PROFILE=$(cat .luca/config.json 2>/dev/null | grep -o '"model_profile"[[:space:]]*:[[:space:]]*"[^"]*"' | grep -o '"[^"]*"$' | tr -d '"' || echo "balanced")
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
Models are resolved at runtime via `resolveModelForAgent(agentName, complexity)` from the centralized routing table (`src/complexity/__helpers/model-routing.ts`) — the orchestrator does not pick model strings. Lightweight agents (e.g. `learner`) inherit the fast tier; reasoning-intensive subagents (`executor`, `verifier`, `plan-reviewer`, `reviewer`) inherit the balanced or capable tier depending on complexity.
|
|
173
|
+
|
|
174
|
+
### 0.5. Verify GitHub Tracking (Gate)
|
|
175
|
+
|
|
176
|
+
**Before executing any plans, verify issue/branch tracking is configured.**
|
|
177
|
+
|
|
178
|
+
Recall the GitHub issue reference from MuninnDB (`session:milestone-*` or `session:project-init` in repo vault) — issue metadata lives there in v13, not on `.luca/state.json`.
|
|
179
|
+
|
|
180
|
+
**If issue exists and is valid:**
|
|
181
|
+
|
|
182
|
+
- Extract issue number for commit messages
|
|
183
|
+
- Continue to phase validation
|
|
184
|
+
|
|
185
|
+
**If issue is "None" or missing:**
|
|
186
|
+
|
|
187
|
+
```
|
|
188
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
189
|
+
Luca ► GITHUB TRACKING MISSING ⚠
|
|
190
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
191
|
+
|
|
192
|
+
No GitHub issue is configured for this milestone.
|
|
193
|
+
Commits will not reference issues and PR creation will require manual setup.
|
|
194
|
+
|
|
195
|
+
1. **Create issue now** — Set up tracking before execution
|
|
196
|
+
2. **Continue without tracking** — Proceed anyway (not recommended)
|
|
197
|
+
3. **Abort** — Stop and run /milestone-new to set up properly
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
**If "Create issue now" selected:**
|
|
201
|
+
|
|
202
|
+
1. Generate issue from MuninnDB recall: `brain:project-identity` (for milestone identity) + `brain:project-requirements` (for scope)
|
|
203
|
+
2. Create issue: `gh issue create --title "feat({scope}): {milestone}" --body "{body}"`
|
|
204
|
+
3. Create branch: `git checkout -b {issue_number}--{milestone-slug}`
|
|
205
|
+
4. Push: `git push -u origin {branch_name}`
|
|
206
|
+
5. Record issue/branch references in MuninnDB: `mcp__muninn__muninn_remember(vault: "<repo_vault>", concept: "session:milestone-issue", content: "GitHub issue #{issue_number} / branch {branch_name}", tags: ["session","milestone","github"])`
|
|
207
|
+
6. Continue execution
|
|
208
|
+
|
|
209
|
+
**If "Continue without" selected:**
|
|
210
|
+
|
|
211
|
+
1. Warn: commits will use placeholder `#0` for issue reference
|
|
212
|
+
2. Log warning to phase SUMMARY
|
|
213
|
+
3. Continue execution
|
|
214
|
+
|
|
215
|
+
**If "Abort" selected:**
|
|
216
|
+
|
|
217
|
+
1. Exit with message to run `/milestone-new` or manually create issue
|
|
218
|
+
|
|
219
|
+
### 0.6. Procedure Replay Check
|
|
220
|
+
|
|
221
|
+
**Skip if:** `--skip-replay` flag passed.
|
|
222
|
+
|
|
223
|
+
Before executing plans, check for replayable procedures that match the phase objective. High-confidence procedures (composite score >= 0.7, success_rate >= 0.5, 3+ executions) are surfaced as suggested pre-plans for lu-executor.
|
|
224
|
+
|
|
225
|
+
```bash
|
|
226
|
+
# Read phase objective from the roadmap or plan files
|
|
227
|
+
PHASE_OBJECTIVE=$(grep -A 2 "Phase {phase_number}" .luca/roadmap.md | tail -1 | sed 's/^[[:space:]]*//')
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
Recall replayable procedures from MuninnDB:
|
|
231
|
+
|
|
232
|
+
```
|
|
233
|
+
REPLAY_RESULT = mcp__muninn__muninn_recall(vault: "default", context: "replayable procedures for $PHASE_OBJECTIVE")
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
Parse the recall result to determine if relevant procedures exist (REPLAY_COUNT).
|
|
237
|
+
|
|
238
|
+
**If replayable procedures found (REPLAY_COUNT > 0):**
|
|
239
|
+
|
|
240
|
+
Store `REPLAY_JSON` for injection into lu-executor context. When spawning lu-executor for each plan, include the pre-plans as additional context:
|
|
241
|
+
|
|
242
|
+
```
|
|
243
|
+
<procedure_replay_context>
|
|
244
|
+
The following pre-plans are suggested approaches from past successful executions.
|
|
245
|
+
They are ADVISORY, not mandatory. Use them as guidance if they match the current task.
|
|
246
|
+
|
|
247
|
+
{pre_plans from REPLAY_JSON}
|
|
248
|
+
</procedure_replay_context>
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
Track which pre-plans were injected for feedback recording in Step 6.7.
|
|
252
|
+
|
|
253
|
+
**If no replayable procedures found:**
|
|
254
|
+
|
|
255
|
+
Continue normally. No pre-plan context is injected.
|
|
256
|
+
|
|
257
|
+
### 1. Validate Phase Exists
|
|
258
|
+
|
|
259
|
+
- Find phase directory matching argument
|
|
260
|
+
- Count plan.md files
|
|
261
|
+
- Error if no plans found
|
|
262
|
+
|
|
263
|
+
### 2. Discover Plans
|
|
264
|
+
|
|
265
|
+
- List all \*-plan.md files in phase directory
|
|
266
|
+
- Check which have \*-SUMMARY.md (already complete)
|
|
267
|
+
- If `--gaps-only`: filter to only plans with `gap_closure: true`
|
|
268
|
+
- Build list of incomplete plans
|
|
269
|
+
|
|
270
|
+
### 3. Group by Wave
|
|
271
|
+
|
|
272
|
+
- Read `wave` from each plan's frontmatter
|
|
273
|
+
- Group plans by wave number
|
|
274
|
+
- Report wave structure to user
|
|
275
|
+
|
|
276
|
+
### 4. Execute Waves
|
|
277
|
+
|
|
278
|
+
For each wave in order:
|
|
279
|
+
|
|
280
|
+
- Read plan contents (@ syntax doesn't work across Task boundaries)
|
|
281
|
+
- Spawn `lu-executor` for each plan in wave (parallel Task calls)
|
|
282
|
+
- Wait for completion
|
|
283
|
+
- Verify SUMMARYs created
|
|
284
|
+
- Proceed to next wave
|
|
285
|
+
|
|
286
|
+
**MANDATORY**: You MUST spawn lu-executor sub-agents for each plan. Do NOT attempt to execute plans yourself.
|
|
287
|
+
|
|
288
|
+
First, read plan contents (required because @ syntax doesn't work across Task boundaries):
|
|
289
|
+
|
|
290
|
+
```bash
|
|
291
|
+
PLAN_01_CONTENT=$(cat "{plan_01_path}")
|
|
292
|
+
PLAN_02_CONTENT=$(cat "{plan_02_path}")
|
|
293
|
+
PLAN_03_CONTENT=$(cat "{plan_03_path}")
|
|
294
|
+
# Read workflow state from .luca/state.json via the luca CLI
|
|
295
|
+
STATE_JSON=$(luca state read 2>/dev/null || echo '{"initialized":false}')
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
Recall session context from MuninnDB:
|
|
299
|
+
|
|
300
|
+
```
|
|
301
|
+
mcp__muninn__muninn_recall(vault: "default", context: "current session context and findings")
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
Then spawn all executors for the wave in PARALLEL (same message, multiple Task calls):
|
|
305
|
+
|
|
306
|
+
```python
|
|
307
|
+
# Wave N executors - these MUST be called in PARALLEL (same message)
|
|
308
|
+
Task(
|
|
309
|
+
prompt="""
|
|
310
|
+
<execution_context>
|
|
311
|
+
|
|
312
|
+
**Plan:** {plan_01_name}
|
|
313
|
+
**Phase:** {phase_number}
|
|
314
|
+
**Wave:** {wave_number}
|
|
315
|
+
|
|
316
|
+
**Plan Content:**
|
|
317
|
+
{plan_01_content}
|
|
318
|
+
|
|
319
|
+
**Project State:**
|
|
320
|
+
{state_content}
|
|
321
|
+
|
|
322
|
+
**Working Memory:**
|
|
323
|
+
{working_content}
|
|
324
|
+
|
|
325
|
+
</execution_context>
|
|
326
|
+
|
|
327
|
+
**TDD Mode:** {tdd_enabled_or_disabled — read plan frontmatter for `tdd: true`. If present: "ENABLED", else: "DISABLED (standard execution)"}
|
|
328
|
+
|
|
329
|
+
<execution_rules>
|
|
330
|
+
- Execute each task in the plan sequentially
|
|
331
|
+
- Commit atomically after each task (git add . && bun run commit)
|
|
332
|
+
- Create SUMMARY.md when complete
|
|
333
|
+
- Log findings to MuninnDB session memory
|
|
334
|
+
- Handle deviations per deviation rules
|
|
335
|
+
- If TDD Mode is ENABLED: follow TDD execution flow (generate tests -> confirm RED -> implement -> confirm GREEN) for each task
|
|
336
|
+
- If a task has `testable: false`: skip TDD for that task, execute normally
|
|
337
|
+
</execution_rules>
|
|
338
|
+
|
|
339
|
+
Execute this plan. Return SUMMARY when complete.
|
|
340
|
+
""",
|
|
341
|
+
subagent_type="lu-executor",
|
|
342
|
+
model="{executor_model}",
|
|
343
|
+
description="Execute {plan_01_name}"
|
|
344
|
+
)
|
|
345
|
+
|
|
346
|
+
Task(
|
|
347
|
+
prompt="""
|
|
348
|
+
<execution_context>
|
|
349
|
+
|
|
350
|
+
**Plan:** {plan_02_name}
|
|
351
|
+
**Phase:** {phase_number}
|
|
352
|
+
**Wave:** {wave_number}
|
|
353
|
+
|
|
354
|
+
**Plan Content:**
|
|
355
|
+
{plan_02_content}
|
|
356
|
+
|
|
357
|
+
**Project State:**
|
|
358
|
+
{state_content}
|
|
359
|
+
|
|
360
|
+
**Working Memory:**
|
|
361
|
+
{working_content}
|
|
362
|
+
|
|
363
|
+
</execution_context>
|
|
364
|
+
|
|
365
|
+
**TDD Mode:** {tdd_enabled_or_disabled — read plan frontmatter for `tdd: true`. If present: "ENABLED", else: "DISABLED (standard execution)"}
|
|
366
|
+
|
|
367
|
+
<execution_rules>
|
|
368
|
+
- Execute each task in the plan sequentially
|
|
369
|
+
- Commit atomically after each task (git add . && bun run commit)
|
|
370
|
+
- Create SUMMARY.md when complete
|
|
371
|
+
- Log findings to MuninnDB session memory
|
|
372
|
+
- Handle deviations per deviation rules
|
|
373
|
+
- If TDD Mode is ENABLED: follow TDD execution flow (generate tests -> confirm RED -> implement -> confirm GREEN) for each task
|
|
374
|
+
- If a task has `testable: false`: skip TDD for that task, execute normally
|
|
375
|
+
</execution_rules>
|
|
376
|
+
|
|
377
|
+
Execute this plan. Return SUMMARY when complete.
|
|
378
|
+
""",
|
|
379
|
+
subagent_type="lu-executor",
|
|
380
|
+
model="{executor_model}",
|
|
381
|
+
description="Execute {plan_02_name}"
|
|
382
|
+
)
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
**Do NOT proceed to next wave until all Task calls return.**
|
|
386
|
+
|
|
387
|
+
### 4.5. Suspend/Resume Support
|
|
388
|
+
|
|
389
|
+
**Before each wave**, check context usage to decide if suspension is needed:
|
|
390
|
+
|
|
391
|
+
```bash
|
|
392
|
+
# Check context usage zone from context monitor
|
|
393
|
+
CONTEXT_JSON=$(bun run src/memory/context-monitor.ts --project-dir=. 2>/dev/null || echo '{"zone":"peak"}')
|
|
394
|
+
ZONE=$(echo "$CONTEXT_JSON" | bun -e "const d=JSON.parse(await Bun.stdin.text()); console.log(d.zone)" 2>/dev/null || echo "peak")
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
**If zone is "stop"** (context exhaustion imminent):
|
|
398
|
+
|
|
399
|
+
1. **Create checkpoint:** Record current progress so a new session can resume. Emit a telemetry suspend event and persist the wave/task progress to the active phase's `execute/progress.jsonl` so the next session can resume from there:
|
|
400
|
+
|
|
401
|
+
```bash
|
|
402
|
+
luca telemetry emit --kind=phase.suspend --data='{"phase":"{phase_number}","reason":"context_exhaustion","wave":{current_wave_index},"completed":"{comma_separated_completed_task_ids}"}' 2>/dev/null || true
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
The execute step appends per-wave progress to `.luca/phases/<currentPhaseSlug>/execute/progress.jsonl` — that JSONL is the durable resume record.
|
|
406
|
+
|
|
407
|
+
2. **Write `.continue-here.md`** as a handoff document for the next session:
|
|
408
|
+
|
|
409
|
+
```
|
|
410
|
+
# Continue Here
|
|
411
|
+
|
|
412
|
+
**Phase:** {phase_number}
|
|
413
|
+
**Suspended at wave:** {current_wave_index}
|
|
414
|
+
**Reason:** Context exhaustion (zone: stop)
|
|
415
|
+
**Completed plans:** {list of completed plan IDs}
|
|
416
|
+
**Remaining waves:** {list of remaining wave numbers}
|
|
417
|
+
|
|
418
|
+
## Resume Instructions
|
|
419
|
+
|
|
420
|
+
Run: `/phase-execute {phase_number}`
|
|
421
|
+
|
|
422
|
+
The phase-execute skill will detect the suspend checkpoint and resume
|
|
423
|
+
from the last incomplete wave automatically.
|
|
424
|
+
```
|
|
425
|
+
|
|
426
|
+
3. **Stop execution** and inform the user:
|
|
427
|
+
|
|
428
|
+
```
|
|
429
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
430
|
+
Luca ► PHASE SUSPENDED
|
|
431
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
432
|
+
|
|
433
|
+
Context usage is in the "stop" zone. Suspending to preserve quality.
|
|
434
|
+
|
|
435
|
+
Checkpoint saved. Resume in a new session with:
|
|
436
|
+
/phase-execute {phase_number}
|
|
437
|
+
```
|
|
438
|
+
|
|
439
|
+
**On resume** (the active phase's progress.jsonl indicates partial completion):
|
|
440
|
+
|
|
441
|
+
At the start of phase execution, check for an existing progress ledger:
|
|
442
|
+
|
|
443
|
+
```bash
|
|
444
|
+
PROGRESS_PATH=".luca/phases/{phase_slug}/execute/progress.jsonl"
|
|
445
|
+
CHECKPOINT_EXISTS=$([ -s "$PROGRESS_PATH" ] && echo "true" || echo "false")
|
|
446
|
+
```
|
|
447
|
+
|
|
448
|
+
If a checkpoint exists:
|
|
449
|
+
|
|
450
|
+
1. Read `$PROGRESS_PATH` (JSONL) and reconstruct the completed wave index + task IDs from the last successful wave entry.
|
|
451
|
+
2. Skip waves that were already completed.
|
|
452
|
+
3. Resume execution from the first incomplete wave.
|
|
453
|
+
4. The progress ledger is append-only — no explicit clear step is needed.
|
|
454
|
+
|
|
455
|
+
### 5. Aggregate Results
|
|
456
|
+
|
|
457
|
+
- Collect summaries from all plans
|
|
458
|
+
- Report phase completion status
|
|
459
|
+
|
|
460
|
+
### 5.1 Parse Sub-Agent Results
|
|
461
|
+
|
|
462
|
+
When sub-agents return, attempt to parse their output as a result envelope:
|
|
463
|
+
|
|
464
|
+
```json
|
|
465
|
+
{
|
|
466
|
+
"status": "success|partial|failed|timeout",
|
|
467
|
+
"summary": "Brief description of what was accomplished",
|
|
468
|
+
"artifacts": [{ "path": "file.ts", "action": "created" }],
|
|
469
|
+
"issues": [
|
|
470
|
+
{ "severity": "medium", "message": "...", "source_agent": "lu-executor" }
|
|
471
|
+
],
|
|
472
|
+
"metadata": { "agent_name": "lu-executor", "context_tier": "T2" }
|
|
473
|
+
}
|
|
474
|
+
```
|
|
475
|
+
|
|
476
|
+
If a sub-agent returns plain text instead of JSON, wrap it as:
|
|
477
|
+
|
|
478
|
+
- status: "partial"
|
|
479
|
+
- summary: the raw text (truncated to 2000 chars)
|
|
480
|
+
- artifacts: []
|
|
481
|
+
- issues: []
|
|
482
|
+
|
|
483
|
+
This ensures all sub-agent outputs can be uniformly aggregated.
|
|
484
|
+
|
|
485
|
+
### 5.2 Prune Sub-Agent Output (Context Preservation)
|
|
486
|
+
|
|
487
|
+
**CRITICAL: After parsing each sub-agent result, immediately discard the raw output and retain ONLY the parsed envelope fields.**
|
|
488
|
+
|
|
489
|
+
Sub-agents can return very large outputs (50-100k+ tokens each). If you keep the full raw output in your working context while planning the next steps (harness, verification, code review, learning capture), you will exhaust the context window and freeze.
|
|
490
|
+
|
|
491
|
+
**Rules:**
|
|
492
|
+
|
|
493
|
+
1. Parse the result envelope per Step 5.1
|
|
494
|
+
2. Store ONLY these fields per agent: `status`, `summary` (max 500 chars), `artifacts` (paths only), `issues` (severity + message, max 10)
|
|
495
|
+
3. **Discard** the full raw output text — do NOT reference it again
|
|
496
|
+
4. Build a compact phase summary table for downstream steps:
|
|
497
|
+
|
|
498
|
+
```
|
|
499
|
+
| Plan | Status | Summary | Issues |
|
|
500
|
+
|------|--------|---------|--------|
|
|
501
|
+
| 01-01 | success | Brief summary | 0 |
|
|
502
|
+
| 01-02 | success | Brief summary | 1 |
|
|
503
|
+
```
|
|
504
|
+
|
|
505
|
+
5. Pass ONLY this compact summary to downstream agents (verifier, reviewers, learner)
|
|
506
|
+
|
|
507
|
+
**Why:** Parallel sub-agents returning ~200k+ combined tokens cause the orchestrator context to spike into the degradation zone (70%+), leading to freezes or extremely slow responses. This pruning step keeps the orchestrator lean for the remaining 6+ steps it must complete.
|
|
508
|
+
|
|
509
|
+
> **Future work:** A structured context-budget system will replace this manual pruning. See `docs/decisions/orchestrator-context-pruning.md` for the decision record and migration plan.
|
|
510
|
+
|
|
511
|
+
### 6. Commit Orchestrator Corrections
|
|
512
|
+
|
|
513
|
+
```bash
|
|
514
|
+
git status --porcelain
|
|
515
|
+
```
|
|
516
|
+
|
|
517
|
+
If changes exist:
|
|
518
|
+
|
|
519
|
+
```bash
|
|
520
|
+
git add .
|
|
521
|
+
bun run commit --message="orchestrator corrections" --type=fix --scope={phase} --no-push --skip-checks
|
|
522
|
+
```
|
|
523
|
+
|
|
524
|
+
### 6.5. Run Verification Harness
|
|
525
|
+
|
|
526
|
+
**Run automated quality checks before agent verification.**
|
|
527
|
+
|
|
528
|
+
Run the harness runner:
|
|
529
|
+
|
|
530
|
+
```bash
|
|
531
|
+
# Run harness (outputs JSON to stdout)
|
|
532
|
+
HARNESS_OUTPUT=$(bun run ./src/harness/runner.ts --project-dir=.)
|
|
533
|
+
HARNESS_EXIT=$?
|
|
534
|
+
echo "$HARNESS_OUTPUT"
|
|
535
|
+
```
|
|
536
|
+
|
|
537
|
+
Parse the JSON output:
|
|
538
|
+
|
|
539
|
+
- If `status: "passed"` -- display results and continue to Step 7
|
|
540
|
+
- If `status: "failed"` -- enter failure-to-fix loop (Step 6.6)
|
|
541
|
+
|
|
542
|
+
Display:
|
|
543
|
+
|
|
544
|
+
```
|
|
545
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
546
|
+
Luca ► VERIFICATION HARNESS
|
|
547
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
548
|
+
|
|
549
|
+
| Check | Status | Errors | Duration |
|
|
550
|
+
|-----------|--------|--------|----------|
|
|
551
|
+
| {name} | {pass/fail} | {N} | {Ns} |
|
|
552
|
+
|
|
553
|
+
Overall: {PASSED/FAILED}
|
|
554
|
+
```
|
|
555
|
+
|
|
556
|
+
### 6.6. Loop A: Harness Fix Loop
|
|
557
|
+
|
|
558
|
+
**When harness checks fail (Step 6.5), run the unified iteration loop for mechanical failures.**
|
|
559
|
+
|
|
560
|
+
**This loop uses decision-support utilities from `src/iteration/`. You (the orchestrator) ARE the loop controller. Call the CLI utilities for convergence detection, error classification, checkpoint management, and budget tracking.**
|
|
561
|
+
|
|
562
|
+
#### 6.6.1. Initialize Loop A
|
|
563
|
+
|
|
564
|
+
Read iteration configuration:
|
|
565
|
+
|
|
566
|
+
```bash
|
|
567
|
+
# Read complexity from the canonical workflow state
|
|
568
|
+
COMPLEXITY=$(luca state read 2>/dev/null | jq -r '.complexity // "MODERATE"')
|
|
569
|
+
|
|
570
|
+
# Read iteration config
|
|
571
|
+
CONFIG=$(cat .luca/config.json)
|
|
572
|
+
|
|
573
|
+
# Extract limits: harnessFixIterations from complexity matrix
|
|
574
|
+
MAX_ITERATIONS=$(echo "$CONFIG" | bun -e "
|
|
575
|
+
const c = JSON.parse(require('fs').readFileSync('/dev/stdin','utf8'));
|
|
576
|
+
const level = '${COMPLEXITY}' || 'MODERATE';
|
|
577
|
+
console.log(c.complexity?.matrix?.[level]?.harnessFixIterations ?? 3);
|
|
578
|
+
")
|
|
579
|
+
|
|
580
|
+
# Extract iteration settings
|
|
581
|
+
DEFAULT_MODE=$(echo "$CONFIG" | bun -e "
|
|
582
|
+
const c = JSON.parse(require('fs').readFileSync('/dev/stdin','utf8'));
|
|
583
|
+
console.log(c.iteration?.default_mode ?? 'afk');
|
|
584
|
+
")
|
|
585
|
+
SOFT_STOP=$(echo "$CONFIG" | bun -e "
|
|
586
|
+
const c = JSON.parse(require('fs').readFileSync('/dev/stdin','utf8'));
|
|
587
|
+
console.log(c.iteration?.soft_stop_percent ?? 80);
|
|
588
|
+
")
|
|
589
|
+
STALE_THRESHOLD=$(echo "$CONFIG" | bun -e "
|
|
590
|
+
const c = JSON.parse(require('fs').readFileSync('/dev/stdin','utf8'));
|
|
591
|
+
console.log(c.iteration?.stale_threshold ?? 2);
|
|
592
|
+
")
|
|
593
|
+
PROMOTION_THRESHOLD=$(echo "$CONFIG" | bun -e "
|
|
594
|
+
const c = JSON.parse(require('fs').readFileSync('/dev/stdin','utf8'));
|
|
595
|
+
console.log(c.iteration?.promotion_threshold ?? 3);
|
|
596
|
+
")
|
|
597
|
+
|
|
598
|
+
# Extract stall debate setting (default: true)
|
|
599
|
+
STALL_DEBATE_ENABLED=$(echo "$CONFIG" | bun -e "
|
|
600
|
+
const c = JSON.parse(require('fs').readFileSync('/dev/stdin','utf8'));
|
|
601
|
+
console.log(c.iteration?.stall_debate_enabled ?? true);
|
|
602
|
+
")
|
|
603
|
+
|
|
604
|
+
# Override mode if --mode flag was passed
|
|
605
|
+
MODE="${MODE_FLAG:-$DEFAULT_MODE}"
|
|
606
|
+
```
|
|
607
|
+
|
|
608
|
+
Initialize tracking state:
|
|
609
|
+
|
|
610
|
+
```bash
|
|
611
|
+
# Create initial budget state
|
|
612
|
+
BUDGET=$(bun run src/iteration/budget.ts create \
|
|
613
|
+
--max-iterations="$MAX_ITERATIONS" \
|
|
614
|
+
--soft-stop-percent="$SOFT_STOP")
|
|
615
|
+
|
|
616
|
+
# Initialize empty fingerprint ledger for error classification
|
|
617
|
+
LEDGER='{}'
|
|
618
|
+
|
|
619
|
+
# Initialize previous errors as empty (first iteration has no previous)
|
|
620
|
+
PREVIOUS_ERRORS='[]'
|
|
621
|
+
STALE_COUNT=0
|
|
622
|
+
PHASE_NUM={phase_number}
|
|
623
|
+
```
|
|
624
|
+
|
|
625
|
+
Display loop start:
|
|
626
|
+
|
|
627
|
+
```
|
|
628
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
629
|
+
Luca ITER ► LOOP A: HARNESS FIX (max {MAX_ITERATIONS} iterations, mode: {MODE})
|
|
630
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
631
|
+
```
|
|
632
|
+
|
|
633
|
+
#### 6.6.2. Loop A Iteration Cycle
|
|
634
|
+
|
|
635
|
+
For each iteration, follow these steps IN ORDER:
|
|
636
|
+
|
|
637
|
+
**Step A: Budget Pre-Check**
|
|
638
|
+
|
|
639
|
+
```bash
|
|
640
|
+
BUDGET_CHECK=$(bun run src/iteration/budget.ts should-start --state="$BUDGET")
|
|
641
|
+
ALLOWED=$(echo "$BUDGET_CHECK" | bun -e "console.log(JSON.parse(require('fs').readFileSync('/dev/stdin','utf8')).allowed)")
|
|
642
|
+
REASON=$(echo "$BUDGET_CHECK" | bun -e "console.log(JSON.parse(require('fs').readFileSync('/dev/stdin','utf8')).reason)")
|
|
643
|
+
```
|
|
644
|
+
|
|
645
|
+
If `ALLOWED` is false: display reason, exit loop with outcome "budget_exhausted".
|
|
646
|
+
|
|
647
|
+
**Step B: Classify Errors**
|
|
648
|
+
|
|
649
|
+
Classify the harness errors from the most recent harness run:
|
|
650
|
+
|
|
651
|
+
```bash
|
|
652
|
+
CLASSIFIED=$(bun run src/iteration/classifier.ts \
|
|
653
|
+
--harness-result="$HARNESS_OUTPUT" \
|
|
654
|
+
--ledger="$LEDGER" \
|
|
655
|
+
--promotion-threshold="$PROMOTION_THRESHOLD")
|
|
656
|
+
|
|
657
|
+
# Extract classified errors and updated ledger
|
|
658
|
+
CURRENT_ERRORS=$(echo "$CLASSIFIED" | bun -e "console.log(JSON.stringify(JSON.parse(require('fs').readFileSync('/dev/stdin','utf8')).classified))")
|
|
659
|
+
LEDGER=$(echo "$CLASSIFIED" | bun -e "console.log(JSON.stringify(JSON.parse(require('fs').readFileSync('/dev/stdin','utf8')).updated_ledger))")
|
|
660
|
+
```
|
|
661
|
+
|
|
662
|
+
Check for permanent errors. If any errors were newly promoted to permanent, log them:
|
|
663
|
+
|
|
664
|
+
```
|
|
665
|
+
◆ Permanent errors (excluded from convergence):
|
|
666
|
+
- {file}:{line} — {message} (seen {N} iterations)
|
|
667
|
+
```
|
|
668
|
+
|
|
669
|
+
**Step C: Convergence Check** (skip for iteration 1 — no previous to compare)
|
|
670
|
+
|
|
671
|
+
If this is iteration 2+:
|
|
672
|
+
|
|
673
|
+
```bash
|
|
674
|
+
# Get artifact delta from previous checkpoint
|
|
675
|
+
PREV_TAG="iter/${PHASE_NUM}/harness/$((ITERATION - 1))"
|
|
676
|
+
ARTIFACT_DELTA=$(bun run src/iteration/checkpoint.ts artifact-delta --from-ref="$PREV_TAG")
|
|
677
|
+
|
|
678
|
+
# Assess convergence
|
|
679
|
+
CONVERGENCE=$(bun run src/iteration/convergence.ts \
|
|
680
|
+
--current="$CURRENT_ERRORS" \
|
|
681
|
+
--previous="$PREVIOUS_ERRORS" \
|
|
682
|
+
--artifact-delta="$ARTIFACT_DELTA" \
|
|
683
|
+
--previous-stale-count="$STALE_COUNT" \
|
|
684
|
+
--stale-threshold="$STALE_THRESHOLD")
|
|
685
|
+
|
|
686
|
+
CONV_STATUS=$(echo "$CONVERGENCE" | bun -e "console.log(JSON.parse(require('fs').readFileSync('/dev/stdin','utf8')).status)")
|
|
687
|
+
SHOULD_HALT=$(echo "$CONVERGENCE" | bun -e "console.log(JSON.parse(require('fs').readFileSync('/dev/stdin','utf8')).should_halt)")
|
|
688
|
+
STALE_COUNT=$(echo "$CONVERGENCE" | bun -e "console.log(JSON.parse(require('fs').readFileSync('/dev/stdin','utf8')).consecutive_stale)")
|
|
689
|
+
```
|
|
690
|
+
|
|
691
|
+
**Stall Debate (when enabled):**
|
|
692
|
+
|
|
693
|
+
If `SHOULD_HALT` is true AND `STALL_DEBATE_ENABLED` is true:
|
|
694
|
+
|
|
695
|
+
1. Extract the debate result from CONVERGENCE JSON: `DEBATE_STRATEGY`, `DEBATE_CONFIDENCE`, `DEBATE_REASONING`
|
|
696
|
+
2. If `DEBATE_STRATEGY` is NOT "halt": override `SHOULD_HALT=false`
|
|
697
|
+
3. Display debate outcome:
|
|
698
|
+
```
|
|
699
|
+
◆ Stall Debate: {DEBATE_STRATEGY} (confidence: {DEBATE_CONFIDENCE})
|
|
700
|
+
Reasoning: {DEBATE_REASONING}
|
|
701
|
+
```
|
|
702
|
+
4. Act on strategy:
|
|
703
|
+
- `retry_with_context_promotion`: Promote executor context tier for next iteration
|
|
704
|
+
- `retry_with_error_focus`: Include top error patterns in next executor prompt
|
|
705
|
+
- `retry_with_rollback`: Rollback to previous checkpoint before next iteration
|
|
706
|
+
|
|
707
|
+
If `SHOULD_HALT` is true (after debate, if applicable): display convergence failure, exit loop with outcome "convergence_failure".
|
|
708
|
+
|
|
709
|
+
Display convergence status:
|
|
710
|
+
|
|
711
|
+
```
|
|
712
|
+
◆ Convergence: {CONV_STATUS} (stale count: {STALE_COUNT}/{STALE_THRESHOLD})
|
|
713
|
+
```
|
|
714
|
+
|
|
715
|
+
**Step D: Create Checkpoint**
|
|
716
|
+
|
|
717
|
+
```bash
|
|
718
|
+
COMMIT_HASH=$(bun run src/iteration/checkpoint.ts commit-hash)
|
|
719
|
+
TAG="iter/${PHASE_NUM}/harness/${ITERATION}"
|
|
720
|
+
|
|
721
|
+
# Build iteration record JSON and create checkpoint
|
|
722
|
+
RECORD='{ "tag": "'$TAG'", "phase": '$PHASE_NUM', "loop": "harness", "iteration": '$ITERATION', ... }'
|
|
723
|
+
bun run src/iteration/checkpoint.ts create --record="$RECORD"
|
|
724
|
+
```
|
|
725
|
+
|
|
726
|
+
Fill in the full IterationRecord fields: error_count, error_delta, error_fingerprints, convergence_status, stale_count, permanent_errors, correctable_errors, transient_errors, artifacts_delta, commit_hash, agent_invoked, duration_ms, timestamp.
|
|
727
|
+
|
|
728
|
+
**Step E: HITL/AFK Decision Point**
|
|
729
|
+
|
|
730
|
+
If `MODE` is "hitl":
|
|
731
|
+
|
|
732
|
+
Display iteration summary table:
|
|
733
|
+
|
|
734
|
+
```
|
|
735
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
736
|
+
Luca ITER ► ITERATION {N} COMPLETE
|
|
737
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
738
|
+
|
|
739
|
+
| Metric | Previous | Current | Delta |
|
|
740
|
+
|-----------------|----------|---------|-------|
|
|
741
|
+
| Active errors | {N} | {N} | {+/-} |
|
|
742
|
+
| Files changed | {N} | {N} | {+/-} |
|
|
743
|
+
| Permanent | {N} | {N} | {+/-} |
|
|
744
|
+
|
|
745
|
+
Status: {improved / stalled / regressed}
|
|
746
|
+
Budget: {N}/{MAX} iterations ({percent}%)
|
|
747
|
+
|
|
748
|
+
Options:
|
|
749
|
+
1. Continue — Proceed to iteration {N+1}
|
|
750
|
+
2. Rollback — Revert to iteration {N-1} checkpoint
|
|
751
|
+
3. Abort — Stop loop, keep current state
|
|
752
|
+
4. Skip — Skip remaining iterations, proceed to verification
|
|
753
|
+
```
|
|
754
|
+
|
|
755
|
+
Wait for user input. Route by choice:
|
|
756
|
+
|
|
757
|
+
- **Continue**: Proceed to Step F
|
|
758
|
+
- **Rollback**: Run `bun run src/iteration/checkpoint.ts rollback --tag="iter/${PHASE_NUM}/harness/$((ITERATION-1))"`. Decrement iteration counter. Re-run harness. Return to Step A.
|
|
759
|
+
- **Abort**: Exit loop with outcome "user_abort"
|
|
760
|
+
- **Skip**: Exit loop with outcome "user_skip"
|
|
761
|
+
|
|
762
|
+
If `MODE` is "afk": Skip to Step F (no pause).
|
|
763
|
+
|
|
764
|
+
**Step F: Spawn Executor with Fix Context**
|
|
765
|
+
|
|
766
|
+
Prepare fix context from classified errors. Include only correctable and transient errors (permanent are skipped):
|
|
767
|
+
|
|
768
|
+
```python
|
|
769
|
+
Task(
|
|
770
|
+
prompt="""
|
|
771
|
+
<fix_context>
|
|
772
|
+
**Harness failures (Loop A, iteration {N}/{MAX}):**
|
|
773
|
+
|
|
774
|
+
**Correctable errors (retry with context):**
|
|
775
|
+
{correctable_errors_json}
|
|
776
|
+
|
|
777
|
+
**Transient errors (retry):**
|
|
778
|
+
{transient_errors_json}
|
|
779
|
+
|
|
780
|
+
**Permanent errors (SKIP — do not attempt to fix):**
|
|
781
|
+
{permanent_errors_summary}
|
|
782
|
+
|
|
783
|
+
**Instructions:**
|
|
784
|
+
- Fix ONLY the correctable and transient errors listed above
|
|
785
|
+
- Do NOT attempt to fix permanent errors — they have been tried {N}+ times
|
|
786
|
+
- Do NOT refactor or improve unrelated code
|
|
787
|
+
- Do NOT modify test expectations to make tests pass
|
|
788
|
+
- Commit fixes atomically
|
|
789
|
+
</fix_context>
|
|
790
|
+
|
|
791
|
+
Fix these harness failures.
|
|
792
|
+
""",
|
|
793
|
+
subagent_type="lu-executor",
|
|
794
|
+
model="{executor_model}",
|
|
795
|
+
description="Fix harness failures (Loop A, iteration {N})"
|
|
796
|
+
)
|
|
797
|
+
```
|
|
798
|
+
|
|
799
|
+
**Step G: Re-run Harness**
|
|
800
|
+
|
|
801
|
+
```bash
|
|
802
|
+
HARNESS_OUTPUT=$(bun run ./src/harness/runner.ts --project-dir=.)
|
|
803
|
+
HARNESS_EXIT=$?
|
|
804
|
+
```
|
|
805
|
+
|
|
806
|
+
If harness passes (status: "passed"): Exit loop with outcome "all_passed".
|
|
807
|
+
|
|
808
|
+
If harness fails: Update `PREVIOUS_ERRORS = CURRENT_ERRORS`, advance budget:
|
|
809
|
+
|
|
810
|
+
```bash
|
|
811
|
+
BUDGET=$(bun run src/iteration/budget.ts advance --state="$BUDGET")
|
|
812
|
+
```
|
|
813
|
+
|
|
814
|
+
Return to Step A for next iteration.
|
|
815
|
+
|
|
816
|
+
#### 6.6.3. Loop A Termination
|
|
817
|
+
|
|
818
|
+
When the loop exits (any outcome), display:
|
|
819
|
+
|
|
820
|
+
```
|
|
821
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
822
|
+
Luca ITER ► LOOP A COMPLETE
|
|
823
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
824
|
+
|
|
825
|
+
Outcome: {outcome}
|
|
826
|
+
Iterations: {N}/{MAX}
|
|
827
|
+
Active errors remaining: {count}
|
|
828
|
+
Permanent errors: {count}
|
|
829
|
+
```
|
|
830
|
+
|
|
831
|
+
Pass results to Step 7 (verifier context):
|
|
832
|
+
|
|
833
|
+
- `harness_status`: "passed" if outcome is "all_passed", else "failed_after_fixes"
|
|
834
|
+
- `harness_checks`: from last harness run
|
|
835
|
+
- `remaining_errors`: classified errors still active
|
|
836
|
+
- `loop_a_outcome`: the outcome string
|
|
837
|
+
- `loop_a_iterations`: count
|
|
838
|
+
|
|
839
|
+
### 6.7. Record Procedure Replay Feedback
|
|
840
|
+
|
|
841
|
+
**Skip if:** `--skip-replay` flag passed OR no pre-plans were injected in Step 0.6.
|
|
842
|
+
|
|
843
|
+
After harness verification completes, record feedback for each pre-plan that was followed. This closes the learning loop: procedure replays feed back into procedure scoring.
|
|
844
|
+
|
|
845
|
+
For each pre-plan that was injected during execution, record the outcome in MuninnDB:
|
|
846
|
+
|
|
847
|
+
```
|
|
848
|
+
# For each procedure that was replayed:
|
|
849
|
+
# HARNESS_PASSED is true if harness_status === "passed", false otherwise
|
|
850
|
+
# EXECUTION_DURATION_MS is computed from phase start time
|
|
851
|
+
|
|
852
|
+
for each PROC_ID in INJECTED_PROCEDURE_IDS:
|
|
853
|
+
mcp__muninn__muninn_evolve(vault: "default", id: "procedure:$PROC_ID", content: "replay outcome: success=$HARNESS_PASSED, duration_ms=$EXECUTION_DURATION_MS")
|
|
854
|
+
```
|
|
855
|
+
|
|
856
|
+
This ensures that:
|
|
857
|
+
- Successful replays boost procedure confidence (success_count incremented)
|
|
858
|
+
- Failed replays degrade procedure confidence (only execution_count incremented)
|
|
859
|
+
- Consistently failing procedures are auto-retired (success_rate < 0.4 after 5+ executions)
|
|
860
|
+
|
|
861
|
+
### 7. Verify Phase Goal
|
|
862
|
+
|
|
863
|
+
**MANDATORY**: You MUST spawn a lu-verifier sub-agent. Do NOT attempt to verify yourself.
|
|
864
|
+
|
|
865
|
+
First, read the required context:
|
|
866
|
+
|
|
867
|
+
```bash
|
|
868
|
+
PHASE_DIR=".luca/phases/{phase_number}-*"
|
|
869
|
+
ROADMAP_CONTENT=$(cat .luca/roadmap.md)
|
|
870
|
+
# Read workflow state from .luca/state.json via the luca CLI
|
|
871
|
+
STATE_JSON=$(luca state read 2>/dev/null || echo '{"initialized":false}')
|
|
872
|
+
SUMMARIES=$(find $PHASE_DIR -path "*/execute/summary.md" -exec cat {} \;)
|
|
873
|
+
PLAN_CONTENTS=$(find $PHASE_DIR -name "plan.md" -exec cat {} \;)
|
|
874
|
+
```
|
|
875
|
+
|
|
876
|
+
Recall session context from MuninnDB:
|
|
877
|
+
|
|
878
|
+
```
|
|
879
|
+
mcp__muninn__muninn_recall(vault: "default", context: "current session context and findings for phase verification")
|
|
880
|
+
```
|
|
881
|
+
|
|
882
|
+
Then spawn the verifier:
|
|
883
|
+
|
|
884
|
+
```python
|
|
885
|
+
Task(
|
|
886
|
+
prompt="""
|
|
887
|
+
<verification_context>
|
|
888
|
+
|
|
889
|
+
**Phase:** {phase_number}
|
|
890
|
+
**Phase Directory:** {phase_dir}
|
|
891
|
+
**Mode:** full (goal-backward verification)
|
|
892
|
+
|
|
893
|
+
**Phase Goal (from roadmap.md):**
|
|
894
|
+
{phase_goal}
|
|
895
|
+
|
|
896
|
+
**Execution Summaries:**
|
|
897
|
+
{summaries}
|
|
898
|
+
|
|
899
|
+
**Plan Contents (for specification anchoring):**
|
|
900
|
+
{plan_contents}
|
|
901
|
+
|
|
902
|
+
**Project State:**
|
|
903
|
+
{state_content}
|
|
904
|
+
|
|
905
|
+
<!-- WARM ISOLATION: Verifier does NOT receive session context to prevent bias from executor's session notes -->
|
|
906
|
+
<!-- The working_content variable below should be empty or omitted when using context-aware spawning -->
|
|
907
|
+
**Working Memory:**
|
|
908
|
+
{working_content}
|
|
909
|
+
|
|
910
|
+
**Harness Results:**
|
|
911
|
+
{harness_status}
|
|
912
|
+
{harness_checks_summary}
|
|
913
|
+
{remaining_errors_if_any}
|
|
914
|
+
|
|
915
|
+
</verification_context>
|
|
916
|
+
|
|
917
|
+
<specification_anchoring>
|
|
918
|
+
plan.md contents are included above. Use them in Step 2.5 (Specification Anchoring) to trace must-haves to plan objectives, and in Step 9.5 (Goal-Backward Objective Check) to confirm each plan's objective was achieved. If plan contents are empty, skip these steps gracefully.
|
|
919
|
+
</specification_anchoring>
|
|
920
|
+
|
|
921
|
+
<verification_levels>
|
|
922
|
+
1. EXISTS: Do deliverables exist in codebase?
|
|
923
|
+
2. SUBSTANTIVE: Do they work correctly?
|
|
924
|
+
3. WIRED: Are they properly integrated?
|
|
925
|
+
</verification_levels>
|
|
926
|
+
|
|
927
|
+
<output_requirements>
|
|
928
|
+
- Create VERIFICATION.md in phase directory
|
|
929
|
+
- Return status: passed | human_needed | gaps_found
|
|
930
|
+
- List any gaps or issues found
|
|
931
|
+
- If harness passed: Note "All automated checks passed" in your report under an "Automated Checks" section.
|
|
932
|
+
- If harness failed after fix attempts: Include remaining mechanical errors as gaps in your verification.
|
|
933
|
+
</output_requirements>
|
|
934
|
+
|
|
935
|
+
Verify the phase goal was achieved using goal-backward analysis.
|
|
936
|
+
""",
|
|
937
|
+
subagent_type="lu-verifier",
|
|
938
|
+
model="{verifier_model}",
|
|
939
|
+
description="Verify Phase {phase_number}"
|
|
940
|
+
)
|
|
941
|
+
```
|
|
942
|
+
|
|
943
|
+
**Do NOT proceed until the Task returns.**
|
|
944
|
+
|
|
945
|
+
Route by returned status:
|
|
946
|
+
|
|
947
|
+
- `passed` → continue to Step 8 (Code Quality Review)
|
|
948
|
+
- `human_needed` → present items, get approval, then continue to Step 8
|
|
949
|
+
- `gaps_found` → proceed to Step 7.5 (Loop B: Verify Fix Loop)
|
|
950
|
+
- `human_needed` with T1/T3 conflict → proceed to Step 7.25 (Verification Tribunal)
|
|
951
|
+
|
|
952
|
+
**Note:** When gaps are found, Loop B will attempt automated gap resolution. Only if Loop B fails to resolve all gaps will the user be offered `/phase-plan {X} --gaps`.
|
|
953
|
+
|
|
954
|
+
### 7.25. Verification Tribunal (Conditional)
|
|
955
|
+
|
|
956
|
+
**Skip if:** `workflow.verification_tribunal_enabled: false` in config (default: true), OR complexity is below COMPLEX, OR no T1/T3 conflict detected.
|
|
957
|
+
|
|
958
|
+
**When to trigger:** The verifier returned `human_needed` AND the verification report shows a T1/T3 signal conflict (T1 STRONG PASS with T3 PARTIAL or FAIL, or T1 PARTIAL with T3 PARTIAL).
|
|
959
|
+
|
|
960
|
+
**Gate check:**
|
|
961
|
+
|
|
962
|
+
```bash
|
|
963
|
+
VT_ENABLED=$(echo "$CONFIG" | bun -e "
|
|
964
|
+
const c = JSON.parse(require('fs').readFileSync('/dev/stdin','utf8'));
|
|
965
|
+
console.log(c.workflow?.verification_tribunal_enabled ?? true);
|
|
966
|
+
")
|
|
967
|
+
```
|
|
968
|
+
|
|
969
|
+
**When enabled at COMPLEX+ complexity with T1/T3 conflict:**
|
|
970
|
+
|
|
971
|
+
1. **Extract conflict signal**: Parse the verifier's T1 and T3 signal statuses and evidence from VERIFICATION.md
|
|
972
|
+
2. **Build diagnostic prompts**: Generate three prompts using the conflict signal — one for each diagnostic agent
|
|
973
|
+
3. **Spawn three diagnostic agents in PARALLEL**:
|
|
974
|
+
|
|
975
|
+
```python
|
|
976
|
+
# Spawn lu-test-writer diagnostic
|
|
977
|
+
Task(
|
|
978
|
+
prompt="""
|
|
979
|
+
<diagnostic_context>
|
|
980
|
+
{test_writer_diagnostic_prompt}
|
|
981
|
+
|
|
982
|
+
**Phase:** {phase_number}
|
|
983
|
+
**VERIFICATION.md:** {verification_content}
|
|
984
|
+
|
|
985
|
+
Analyze the T1/T3 conflict from your perspective as test coverage expert.
|
|
986
|
+
</diagnostic_context>
|
|
987
|
+
""",
|
|
988
|
+
subagent_type="lu-test-writer",
|
|
989
|
+
model="{diagnostic_model}",
|
|
990
|
+
description="Test Writer Diagnostic"
|
|
991
|
+
)
|
|
992
|
+
|
|
993
|
+
# Spawn lu-verifier diagnostic (IN PARALLEL)
|
|
994
|
+
Task(
|
|
995
|
+
prompt="""
|
|
996
|
+
<diagnostic_context>
|
|
997
|
+
{verifier_diagnostic_prompt}
|
|
998
|
+
|
|
999
|
+
**Phase:** {phase_number}
|
|
1000
|
+
**VERIFICATION.md:** {verification_content}
|
|
1001
|
+
|
|
1002
|
+
Re-examine your T3 analysis for potential over-specification.
|
|
1003
|
+
</diagnostic_context>
|
|
1004
|
+
""",
|
|
1005
|
+
subagent_type="lu-verifier",
|
|
1006
|
+
model="{diagnostic_model}",
|
|
1007
|
+
description="Verifier Diagnostic"
|
|
1008
|
+
)
|
|
1009
|
+
|
|
1010
|
+
# Spawn lu-integration-checker diagnostic (IN PARALLEL)
|
|
1011
|
+
Task(
|
|
1012
|
+
prompt="""
|
|
1013
|
+
<diagnostic_context>
|
|
1014
|
+
{integration_diagnostic_prompt}
|
|
1015
|
+
|
|
1016
|
+
**Phase:** {phase_number}
|
|
1017
|
+
**VERIFICATION.md:** {verification_content}
|
|
1018
|
+
|
|
1019
|
+
Analyze cross-component wiring for integration gaps.
|
|
1020
|
+
</diagnostic_context>
|
|
1021
|
+
""",
|
|
1022
|
+
subagent_type="lu-integration-checker",
|
|
1023
|
+
model="{diagnostic_model}",
|
|
1024
|
+
description="Integration Diagnostic"
|
|
1025
|
+
)
|
|
1026
|
+
```
|
|
1027
|
+
|
|
1028
|
+
**Do NOT proceed until ALL three diagnostic Tasks return.**
|
|
1029
|
+
|
|
1030
|
+
4. **Parse diagnostic responses**: Extract CATEGORY, CONFIDENCE, EVIDENCE, and ACTION from each agent's response
|
|
1031
|
+
5. **Resolve tribunal**: Majority vote determines consensus category. If three-way split, use highest confidence as tiebreaker
|
|
1032
|
+
6. **Route by consensus category**:
|
|
1033
|
+
|
|
1034
|
+
| Category | Action |
|
|
1035
|
+
|----------|--------|
|
|
1036
|
+
| `tests_incomplete` | Flag for test augmentation — existing tests don't cover the goal specification |
|
|
1037
|
+
| `goal_over_specified` | Adjust verification — T3 must-haves exceed plan scope |
|
|
1038
|
+
| `wiring_issue` | Flag for integration fix — components exist but aren't connected |
|
|
1039
|
+
|
|
1040
|
+
**Display tribunal results:**
|
|
1041
|
+
|
|
1042
|
+
```
|
|
1043
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
1044
|
+
Luca > VERIFICATION TRIBUNAL RESULTS
|
|
1045
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
1046
|
+
|
|
1047
|
+
| Metric | Value |
|
|
1048
|
+
| --------------------- | ------------------------------ |
|
|
1049
|
+
| Conflict type | {conflict_type} |
|
|
1050
|
+
| T1 status | {t1_status} |
|
|
1051
|
+
| T3 status | {t3_status} |
|
|
1052
|
+
| Consensus category | {consensus_category} |
|
|
1053
|
+
| Consensus confidence | {consensus_confidence} |
|
|
1054
|
+
| Dissenting agent | {dissent_agent or "None"} |
|
|
1055
|
+
| Token cost | ~{estimated_token_cost} |
|
|
1056
|
+
```
|
|
1057
|
+
|
|
1058
|
+
7. **Append tribunal result to VERIFICATION.md**:
|
|
1059
|
+
|
|
1060
|
+
Add a new section `### Verification Tribunal` to the existing VERIFICATION.md with the tribunal results, perspectives, and recommended remediation.
|
|
1061
|
+
|
|
1062
|
+
8. **Continue based on category**:
|
|
1063
|
+
- If `tests_incomplete`: Present to user with recommendation to augment tests, then continue to Step 8
|
|
1064
|
+
- If `goal_over_specified`: Note that verification may be overly strict, adjust status to `passed` if user approves, then continue to Step 8
|
|
1065
|
+
- If `wiring_issue`: Proceed to Step 7.5 (Loop B) with integration fix focus
|
|
1066
|
+
|
|
1067
|
+
### 7.5. Loop B: Verify Fix Loop
|
|
1068
|
+
|
|
1069
|
+
**When the verifier finds gaps (status: gaps_found), run the unified iteration loop for semantic gaps.**
|
|
1070
|
+
|
|
1071
|
+
**This loop re-executes ONLY the plans identified by the verifier's `source_plan` attribution.** Plans without gaps are NOT re-executed.
|
|
1072
|
+
|
|
1073
|
+
**Skip this step if:**
|
|
1074
|
+
|
|
1075
|
+
- Verifier status is "passed" or "human_needed"
|
|
1076
|
+
- `verifyFixIterations` for the current complexity is 0 (e.g., TRIVIAL)
|
|
1077
|
+
- `--skip-verify-loop` flag was passed
|
|
1078
|
+
|
|
1079
|
+
#### 7.5.1. Initialize Loop B
|
|
1080
|
+
|
|
1081
|
+
```bash
|
|
1082
|
+
# Extract verifyFixIterations from complexity matrix
|
|
1083
|
+
VERIFY_MAX=$(echo "$CONFIG" | bun -e "
|
|
1084
|
+
const c = JSON.parse(require('fs').readFileSync('/dev/stdin','utf8'));
|
|
1085
|
+
const level = '${COMPLEXITY}' || 'MODERATE';
|
|
1086
|
+
console.log(c.complexity?.matrix?.[level]?.verifyFixIterations ?? 1);
|
|
1087
|
+
")
|
|
1088
|
+
```
|
|
1089
|
+
|
|
1090
|
+
If `VERIFY_MAX` is 0: Skip Loop B, proceed to Step 8.
|
|
1091
|
+
|
|
1092
|
+
```bash
|
|
1093
|
+
# Create budget state for Loop B
|
|
1094
|
+
VERIFY_BUDGET=$(bun run src/iteration/budget.ts create \
|
|
1095
|
+
--max-iterations="$VERIFY_MAX" \
|
|
1096
|
+
--soft-stop-percent="$SOFT_STOP")
|
|
1097
|
+
|
|
1098
|
+
VERIFY_STALE_COUNT=0
|
|
1099
|
+
VERIFY_ITERATION=0
|
|
1100
|
+
```
|
|
1101
|
+
|
|
1102
|
+
Display:
|
|
1103
|
+
|
|
1104
|
+
```
|
|
1105
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
1106
|
+
Luca ITER ► LOOP B: VERIFY FIX (max {VERIFY_MAX} iterations, mode: {MODE})
|
|
1107
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
1108
|
+
```
|
|
1109
|
+
|
|
1110
|
+
#### 7.5.2. Extract Gap-Targeted Plans
|
|
1111
|
+
|
|
1112
|
+
Parse the verifier's VERIFICATION.md frontmatter to extract gaps with source_plan attribution:
|
|
1113
|
+
|
|
1114
|
+
```bash
|
|
1115
|
+
# Read VERIFICATION.md and extract gaps with source_plan
|
|
1116
|
+
VERIFICATION_MD=$(cat .luca/phases/{phase_dir}/*-VERIFICATION.md)
|
|
1117
|
+
```
|
|
1118
|
+
|
|
1119
|
+
From the YAML frontmatter, extract unique `source_plan` values from the gaps. These are the plans that need re-execution.
|
|
1120
|
+
|
|
1121
|
+
If no `source_plan` fields are present (verifier did not attribute gaps to plans): Re-execute ALL plans in the last wave with gap context. This is the backward-compatible fallback.
|
|
1122
|
+
|
|
1123
|
+
#### 7.5.3. Loop B Iteration Cycle
|
|
1124
|
+
|
|
1125
|
+
Follow the same pre-check/execute/evaluate cycle as Loop A, with these differences:
|
|
1126
|
+
|
|
1127
|
+
**Step B-A: Budget Pre-Check**
|
|
1128
|
+
|
|
1129
|
+
Same as Loop A Step A, using `VERIFY_BUDGET`.
|
|
1130
|
+
|
|
1131
|
+
**Step B-B: Spawn Targeted Executors**
|
|
1132
|
+
|
|
1133
|
+
For each plan with gaps, spawn a fix executor with gap-targeted instructions:
|
|
1134
|
+
|
|
1135
|
+
```python
|
|
1136
|
+
Task(
|
|
1137
|
+
prompt="""
|
|
1138
|
+
<gap_fix_context>
|
|
1139
|
+
**Verify Loop B (iteration {N}/{MAX}):**
|
|
1140
|
+
**Plan:** {plan_name}
|
|
1141
|
+
|
|
1142
|
+
**Verifier Gaps for this plan:**
|
|
1143
|
+
{gap_details_for_this_plan}
|
|
1144
|
+
|
|
1145
|
+
**Original Plan Content:**
|
|
1146
|
+
{plan_content}
|
|
1147
|
+
|
|
1148
|
+
**Instructions:**
|
|
1149
|
+
- Address ONLY the gaps listed above
|
|
1150
|
+
- The verifier found that the plan's objectives were not fully met
|
|
1151
|
+
- Refer to the original plan for context on what was intended
|
|
1152
|
+
- Do NOT refactor or change unrelated code
|
|
1153
|
+
- Commit fixes atomically
|
|
1154
|
+
</gap_fix_context>
|
|
1155
|
+
|
|
1156
|
+
Fix the verification gaps for this plan.
|
|
1157
|
+
""",
|
|
1158
|
+
subagent_type="lu-executor",
|
|
1159
|
+
model="{executor_model}",
|
|
1160
|
+
description="Fix verify gaps for {plan_name} (Loop B, iteration {N})"
|
|
1161
|
+
)
|
|
1162
|
+
```
|
|
1163
|
+
|
|
1164
|
+
Spawn all gap-targeted executors in PARALLEL (same message, multiple Task calls).
|
|
1165
|
+
|
|
1166
|
+
**Step B-C: Re-run Harness**
|
|
1167
|
+
|
|
1168
|
+
After executors return, re-run the harness to ensure fixes didn't break mechanical checks:
|
|
1169
|
+
|
|
1170
|
+
```bash
|
|
1171
|
+
HARNESS_OUTPUT=$(bun run ./src/harness/runner.ts --project-dir=.)
|
|
1172
|
+
```
|
|
1173
|
+
|
|
1174
|
+
If harness fails: Enter Loop A mini-loop (1 iteration only) to fix mechanical breakage, then continue Loop B.
|
|
1175
|
+
|
|
1176
|
+
**Step B-D: Re-run Verifier**
|
|
1177
|
+
|
|
1178
|
+
Spawn the verifier again (same context as Step 7, updated with new summaries):
|
|
1179
|
+
|
|
1180
|
+
```python
|
|
1181
|
+
Task(
|
|
1182
|
+
prompt="""
|
|
1183
|
+
<verification_context>
|
|
1184
|
+
**Phase:** {phase_number}
|
|
1185
|
+
**Phase Directory:** {phase_dir}
|
|
1186
|
+
**Mode:** full (re-verification after gap fixes)
|
|
1187
|
+
...same context as Step 7...
|
|
1188
|
+
</verification_context>
|
|
1189
|
+
|
|
1190
|
+
Re-verify the phase goal after gap fix iteration {N}.
|
|
1191
|
+
""",
|
|
1192
|
+
subagent_type="lu-verifier",
|
|
1193
|
+
model="{verifier_model}",
|
|
1194
|
+
description="Re-verify Phase {phase_number} (Loop B, iteration {N})"
|
|
1195
|
+
)
|
|
1196
|
+
```
|
|
1197
|
+
|
|
1198
|
+
If verifier returns "passed": Exit Loop B with outcome "all_passed".
|
|
1199
|
+
If verifier returns "gaps_found": Continue to convergence check.
|
|
1200
|
+
If verifier returns "human_needed": Exit Loop B, proceed to human verification.
|
|
1201
|
+
|
|
1202
|
+
**Step B-E: Convergence Check**
|
|
1203
|
+
|
|
1204
|
+
Compare current gaps to previous gaps. Use gap count as the error signal:
|
|
1205
|
+
|
|
1206
|
+
- `error_count_delta`: current gap count - previous gap count
|
|
1207
|
+
- `fingerprint_overlap`: Compare gap truth strings (hashed) for identity
|
|
1208
|
+
- `artifact_change_delta`: from git diff --stat
|
|
1209
|
+
|
|
1210
|
+
Assess convergence same as Loop A. If should_halt: exit with "convergence_failure".
|
|
1211
|
+
|
|
1212
|
+
**Step B-F: Checkpoint & HITL**
|
|
1213
|
+
|
|
1214
|
+
Create checkpoint (same as Loop A, using "verify" loop type).
|
|
1215
|
+
If HITL mode: display iteration summary and 4-choice menu.
|
|
1216
|
+
Advance budget.
|
|
1217
|
+
|
|
1218
|
+
Return to Step B-A for next iteration.
|
|
1219
|
+
|
|
1220
|
+
#### 7.5.4. Loop B Termination
|
|
1221
|
+
|
|
1222
|
+
When Loop B exits, display summary same as Loop A.
|
|
1223
|
+
|
|
1224
|
+
If outcome is "all_passed": Continue to Step 8 (Code Quality Review).
|
|
1225
|
+
If outcome is anything else: Display remaining gaps and offer `/phase-plan {X} --gaps` to the user.
|
|
1226
|
+
|
|
1227
|
+
### 8. Code Quality Review
|
|
1228
|
+
|
|
1229
|
+
**Skip if:** `--skip-review` flag passed OR `workflow.code_review: false` in config.
|
|
1230
|
+
|
|
1231
|
+
**Always runs** (model tier resolved from routing table per complexity). Each reviewer agent resolves its model tier via `resolveModelForAgent(agentName, complexity)`.
|
|
1232
|
+
|
|
1233
|
+
Get changed files for this phase:
|
|
1234
|
+
|
|
1235
|
+
```bash
|
|
1236
|
+
# Get TypeScript/TSX files changed in this branch vs main
|
|
1237
|
+
CHANGED_FILES=$(git diff --name-only main...HEAD -- '*.ts' '*.tsx' 2>/dev/null | head -50)
|
|
1238
|
+
FILE_COUNT=$(echo "$CHANGED_FILES" | grep -c '.' || echo "0")
|
|
1239
|
+
```
|
|
1240
|
+
|
|
1241
|
+
**If no changed files:** Skip to step 9.
|
|
1242
|
+
|
|
1243
|
+
Display:
|
|
1244
|
+
|
|
1245
|
+
```
|
|
1246
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
1247
|
+
Luca ► CODE QUALITY REVIEW
|
|
1248
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
1249
|
+
|
|
1250
|
+
◆ Reviewing {FILE_COUNT} changed files...
|
|
1251
|
+
```
|
|
1252
|
+
|
|
1253
|
+
**Determine which reviewers to spawn:**
|
|
1254
|
+
|
|
1255
|
+
**Always spawn ALL reviewers.** Each reviewer resolves its model tier from the routing table based on complexity:
|
|
1256
|
+
|
|
1257
|
+
| Agent | TRIVIAL | SIMPLE | MODERATE | COMPLEX | CRITICAL |
|
|
1258
|
+
| ---------------- | ------- | ------- | -------- | ------- | -------- |
|
|
1259
|
+
| dx-advocate | fast | balanced | capable | capable | capable |
|
|
1260
|
+
| code-simplifier | fast | balanced | capable | capable | capable |
|
|
1261
|
+
| code-architect | fast | balanced | capable | capable | capable |
|
|
1262
|
+
| performance-auditor | fast | balanced | capable | capable | capable |
|
|
1263
|
+
| security-auditor | fast | balanced | capable | capable | capable |
|
|
1264
|
+
|
|
1265
|
+
At lower complexity, reviewers run with lighter models (fast tier), making them low-cost but still active. The `--skip-review` flag and `workflow.code_review: false` config override still allow skipping entirely.
|
|
1266
|
+
|
|
1267
|
+
Conditionally spawn `security-auditor` if files match patterns:
|
|
1268
|
+
|
|
1269
|
+
```bash
|
|
1270
|
+
echo "$CHANGED_FILES" | grep -E '(auth|api|convex|mutation|query|middleware|proxy)' && NEEDS_SECURITY=true
|
|
1271
|
+
```
|
|
1272
|
+
|
|
1273
|
+
**MANDATORY**: Spawn ALL applicable reviewers in a SINGLE message with multiple Task calls (PARALLEL).
|
|
1274
|
+
|
|
1275
|
+
**Context isolation:** Code reviewers operate in COLD isolation. They receive:
|
|
1276
|
+
|
|
1277
|
+
- Git diff of changed files (not full file contents)
|
|
1278
|
+
- Project identity summary (conventions only, from MuninnDB brain:*)
|
|
1279
|
+
- NO workflow state, NO session context, NO long-term learnings
|
|
1280
|
+
|
|
1281
|
+
This prevents reviewer bias from executor session context.
|
|
1282
|
+
|
|
1283
|
+
First, read project standards:
|
|
1284
|
+
|
|
1285
|
+
```bash
|
|
1286
|
+
CLAUDE_CONTENT=$(cat CLAUDE.md 2>/dev/null || echo "No CLAUDE.md")
|
|
1287
|
+
```
|
|
1288
|
+
|
|
1289
|
+
Then spawn all reviewers in PARALLEL:
|
|
1290
|
+
|
|
1291
|
+
````python
|
|
1292
|
+
# DX Advocate - conventions, coding standards
|
|
1293
|
+
Task(
|
|
1294
|
+
prompt="""
|
|
1295
|
+
Review the following changed files for code quality issues.
|
|
1296
|
+
|
|
1297
|
+
**Changed files:**
|
|
1298
|
+
{CHANGED_FILES}
|
|
1299
|
+
|
|
1300
|
+
**Project standards:**
|
|
1301
|
+
{claude_content}
|
|
1302
|
+
|
|
1303
|
+
**Your focus:** Naming conventions, coding standards, Lodash vs native methods, snake_case API keys, import organization.
|
|
1304
|
+
|
|
1305
|
+
**Return format:**
|
|
1306
|
+
```yaml
|
|
1307
|
+
issues:
|
|
1308
|
+
- severity: CRITICAL|HIGH|MEDIUM|LOW
|
|
1309
|
+
file: path/to/file.ts
|
|
1310
|
+
line: 42
|
|
1311
|
+
issue: Brief description
|
|
1312
|
+
suggestion: How to fix
|
|
1313
|
+
source_agent: dx-advocate
|
|
1314
|
+
````
|
|
1315
|
+
|
|
1316
|
+
If no issues found, return: `issues: []`
|
|
1317
|
+
""",
|
|
1318
|
+
subagent_type="dx-advocate",
|
|
1319
|
+
model="{reviewer_model}",
|
|
1320
|
+
description="DX review"
|
|
1321
|
+
)
|
|
1322
|
+
|
|
1323
|
+
# Code Simplifier - DRY violations, complexity
|
|
1324
|
+
|
|
1325
|
+
Task(
|
|
1326
|
+
prompt="""
|
|
1327
|
+
Review the following changed files for complexity and duplication.
|
|
1328
|
+
|
|
1329
|
+
**Changed files:**
|
|
1330
|
+
{CHANGED_FILES}
|
|
1331
|
+
|
|
1332
|
+
**Your focus:** DRY violations, duplicated code, unnecessary complexity, code that could be simplified.
|
|
1333
|
+
|
|
1334
|
+
**Return format:**
|
|
1335
|
+
|
|
1336
|
+
```yaml
|
|
1337
|
+
issues:
|
|
1338
|
+
- severity: CRITICAL|HIGH|MEDIUM|LOW
|
|
1339
|
+
file: path/to/file.ts
|
|
1340
|
+
line: 42
|
|
1341
|
+
issue: Brief description
|
|
1342
|
+
suggestion: How to fix
|
|
1343
|
+
source_agent: code-simplifier
|
|
1344
|
+
```
|
|
1345
|
+
|
|
1346
|
+
If no issues found, return: `issues: []`
|
|
1347
|
+
""",
|
|
1348
|
+
subagent_type="code-simplifier",
|
|
1349
|
+
model="{reviewer_model}",
|
|
1350
|
+
description="Simplification review"
|
|
1351
|
+
)
|
|
1352
|
+
|
|
1353
|
+
# Code Architect - architecture, patterns
|
|
1354
|
+
|
|
1355
|
+
Task(
|
|
1356
|
+
prompt="""
|
|
1357
|
+
Review the following changed files for architecture issues.
|
|
1358
|
+
|
|
1359
|
+
**Changed files:**
|
|
1360
|
+
{CHANGED_FILES}
|
|
1361
|
+
|
|
1362
|
+
**Your focus:** Architecture patterns, module boundaries, component structure, separation of concerns.
|
|
1363
|
+
|
|
1364
|
+
**Return format:**
|
|
1365
|
+
|
|
1366
|
+
```yaml
|
|
1367
|
+
issues:
|
|
1368
|
+
- severity: CRITICAL|HIGH|MEDIUM|LOW
|
|
1369
|
+
file: path/to/file.ts
|
|
1370
|
+
line: 42
|
|
1371
|
+
issue: Brief description
|
|
1372
|
+
suggestion: How to fix
|
|
1373
|
+
source_agent: code-architect
|
|
1374
|
+
```
|
|
1375
|
+
|
|
1376
|
+
If no issues found, return: `issues: []`
|
|
1377
|
+
""",
|
|
1378
|
+
subagent_type="code-architect",
|
|
1379
|
+
model="{reviewer_model}",
|
|
1380
|
+
description="Architecture review"
|
|
1381
|
+
)
|
|
1382
|
+
|
|
1383
|
+
# Tailwind Auditor - styling patterns
|
|
1384
|
+
|
|
1385
|
+
Task(
|
|
1386
|
+
prompt="""
|
|
1387
|
+
Review the following changed files for Tailwind and styling issues.
|
|
1388
|
+
|
|
1389
|
+
**Changed files:**
|
|
1390
|
+
{CHANGED_FILES}
|
|
1391
|
+
|
|
1392
|
+
**Your focus:** Dynamic color system usage, Tailwind patterns, shadcn anti-patterns, MUI deprecation compliance.
|
|
1393
|
+
|
|
1394
|
+
**Return format:**
|
|
1395
|
+
|
|
1396
|
+
```yaml
|
|
1397
|
+
issues:
|
|
1398
|
+
- severity: CRITICAL|HIGH|MEDIUM|LOW
|
|
1399
|
+
file: path/to/file.ts
|
|
1400
|
+
line: 42
|
|
1401
|
+
issue: Brief description
|
|
1402
|
+
suggestion: How to fix
|
|
1403
|
+
source_agent: tailwind-auditor
|
|
1404
|
+
```
|
|
1405
|
+
|
|
1406
|
+
If no issues found, return: `issues: []`
|
|
1407
|
+
""",
|
|
1408
|
+
subagent_type="ui",
|
|
1409
|
+
model="{reviewer_model}",
|
|
1410
|
+
description="Tailwind review"
|
|
1411
|
+
)
|
|
1412
|
+
|
|
1413
|
+
# Security Auditor - ONLY if auth/api files changed
|
|
1414
|
+
|
|
1415
|
+
# (Spawn this only if NEEDS_SECURITY=true from earlier check)
|
|
1416
|
+
|
|
1417
|
+
Task(
|
|
1418
|
+
prompt="""
|
|
1419
|
+
Review the following changed files for security issues.
|
|
1420
|
+
|
|
1421
|
+
**Changed files:**
|
|
1422
|
+
{CHANGED_FILES}
|
|
1423
|
+
|
|
1424
|
+
**Your focus:** Authentication, authorization, injection vulnerabilities, XSS, data validation, API security.
|
|
1425
|
+
|
|
1426
|
+
**Return format:**
|
|
1427
|
+
|
|
1428
|
+
```yaml
|
|
1429
|
+
issues:
|
|
1430
|
+
- severity: CRITICAL|HIGH|MEDIUM|LOW
|
|
1431
|
+
file: path/to/file.ts
|
|
1432
|
+
line: 42
|
|
1433
|
+
issue: Brief description
|
|
1434
|
+
suggestion: How to fix
|
|
1435
|
+
source_agent: security-auditor
|
|
1436
|
+
```
|
|
1437
|
+
|
|
1438
|
+
If no issues found, return: `issues: []`
|
|
1439
|
+
""",
|
|
1440
|
+
subagent_type="security-auditor",
|
|
1441
|
+
model="{reviewer_model}",
|
|
1442
|
+
description="Security review"
|
|
1443
|
+
)
|
|
1444
|
+
|
|
1445
|
+
```
|
|
1446
|
+
|
|
1447
|
+
**Do NOT proceed until ALL reviewer Tasks return.**
|
|
1448
|
+
|
|
1449
|
+
**Merge findings:** Combine all issues, deduplicate by file:line.
|
|
1450
|
+
|
|
1451
|
+
### 8.5. Design Tribunal (Conditional)
|
|
1452
|
+
|
|
1453
|
+
**Skip if:** Complexity is below COMPLEX, OR `workflow.tribunal_enabled: false` in config (default: true), OR no disagreements detected.
|
|
1454
|
+
|
|
1455
|
+
**Gate check:**
|
|
1456
|
+
|
|
1457
|
+
```bash
|
|
1458
|
+
TRIBUNAL_ENABLED=$(echo "$CONFIG" | bun -e "
|
|
1459
|
+
const c = JSON.parse(require('fs').readFileSync('/dev/stdin','utf8'));
|
|
1460
|
+
console.log(c.workflow?.tribunal_enabled ?? true);
|
|
1461
|
+
")
|
|
1462
|
+
```
|
|
1463
|
+
|
|
1464
|
+
**When enabled at COMPLEX+ complexity:**
|
|
1465
|
+
|
|
1466
|
+
1. **Normalize findings**: Parse all reviewer outputs into structured ReviewFinding format
|
|
1467
|
+
2. **Detect disagreements**: Group findings by file:line and identify severity mismatches, scope overlaps, and contradictions
|
|
1468
|
+
3. **Gate check**: If no disagreements involve CRITICAL or HIGH findings, skip tribunal
|
|
1469
|
+
4. **Build rebuttal prompts**: For each disagreement, generate challenger/defender prompt pairs
|
|
1470
|
+
5. **Spawn rebuttal agents**: Send prompts to challenger and defender agents in PARALLEL
|
|
1471
|
+
6. **Resolve rebuttals**: Aggregate rebuttal outcomes into unified recommendations with confidence scores
|
|
1472
|
+
7. **Build tribunal result**: Compile final result with metrics
|
|
1473
|
+
|
|
1474
|
+
**Display tribunal results:**
|
|
1475
|
+
|
|
1476
|
+
```
|
|
1477
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
1478
|
+
Luca > DESIGN TRIBUNAL RESULTS
|
|
1479
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
1480
|
+
|
|
1481
|
+
| Metric | Value |
|
|
1482
|
+
| --------------------- | ----- |
|
|
1483
|
+
| Total findings | {N} |
|
|
1484
|
+
| Disagreements found | {N} |
|
|
1485
|
+
| Rebuttals conducted | {N} |
|
|
1486
|
+
| Findings withdrawn | {N} |
|
|
1487
|
+
| Findings modified | {N} |
|
|
1488
|
+
| Debate token cost | ~{N} |
|
|
1489
|
+
```
|
|
1490
|
+
|
|
1491
|
+
**Record tribunal metrics** using `buildReviewMetrics` from 91-A (set `debate_enabled: true`, `disagreements_detected: N`).
|
|
1492
|
+
|
|
1493
|
+
**Replace merged findings** with the tribunal's unified recommendations for Step 8.1.
|
|
1494
|
+
|
|
1495
|
+
### 8.1. Handle Code Review Results
|
|
1496
|
+
|
|
1497
|
+
**Route based on findings:**
|
|
1498
|
+
|
|
1499
|
+
| Severity | Action |
|
|
1500
|
+
|----------|--------|
|
|
1501
|
+
| CRITICAL | Block - must fix before continuing |
|
|
1502
|
+
| HIGH | Strong warning - recommend fixing |
|
|
1503
|
+
| MEDIUM | Warning - note for later |
|
|
1504
|
+
| LOW | Informational only |
|
|
1505
|
+
|
|
1506
|
+
**If CRITICAL issues found:**
|
|
1507
|
+
|
|
1508
|
+
```
|
|
1509
|
+
|
|
1510
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
1511
|
+
Luca ► CRITICAL CODE ISSUES ✗
|
|
1512
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
1513
|
+
|
|
1514
|
+
{N} critical issues must be fixed before continuing.
|
|
1515
|
+
|
|
1516
|
+
| File | Line | Issue |
|
|
1517
|
+
| ------ | ------ | ------- |
|
|
1518
|
+
| {file} | {line} | {issue} |
|
|
1519
|
+
|
|
1520
|
+
## ▶ Next Up
|
|
1521
|
+
|
|
1522
|
+
Planning fixes automatically...
|
|
1523
|
+
|
|
1524
|
+
```
|
|
1525
|
+
|
|
1526
|
+
- Re-invoke the architect mode-agent (in quality-fixes context) to produce a fix plan
|
|
1527
|
+
- Spawn the `plan-reviewer` subagent to verify the fix plan
|
|
1528
|
+
- Present ready status for `/phase-execute {phase} --quality-fixes`
|
|
1529
|
+
- **EXIT** (user must run execute again with --quality-fixes)
|
|
1530
|
+
|
|
1531
|
+
**If HIGH/MEDIUM only:**
|
|
1532
|
+
|
|
1533
|
+
```
|
|
1534
|
+
|
|
1535
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
1536
|
+
Luca ► CODE REVIEW WARNINGS ⚠
|
|
1537
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
1538
|
+
|
|
1539
|
+
| Severity | Count | Examples |
|
|
1540
|
+
| -------- | ----- | ------------- |
|
|
1541
|
+
| HIGH | {N} | {first issue} |
|
|
1542
|
+
| MEDIUM | {N} | {first issue} |
|
|
1543
|
+
|
|
1544
|
+
## Options
|
|
1545
|
+
|
|
1546
|
+
1. **Fix now** — plan and execute fixes before UAT
|
|
1547
|
+
2. **Continue to UAT** — address later
|
|
1548
|
+
3. **Review details** — see full findings
|
|
1549
|
+
|
|
1550
|
+
````
|
|
1551
|
+
|
|
1552
|
+
Wait for user response, then proceed accordingly.
|
|
1553
|
+
|
|
1554
|
+
**If clean (or LOW only):** Continue to step 9.
|
|
1555
|
+
|
|
1556
|
+
### 9. Signal Verification and Update State
|
|
1557
|
+
|
|
1558
|
+
Advance the workflow state to the next pipeline step. Do NOT advance straight to `complete` here — the pipeline transitions through `learn` (postmortem capture) before commit:
|
|
1559
|
+
|
|
1560
|
+
```bash
|
|
1561
|
+
luca state advance --to-step learn 2>/dev/null || true
|
|
1562
|
+
```
|
|
1563
|
+
|
|
1564
|
+
The state machine's `pipelineStep` field in `.luca/state.json` is the authoritative signal.
|
|
1565
|
+
|
|
1566
|
+
### 10. Update Requirements
|
|
1567
|
+
|
|
1568
|
+
Mark phase requirements as Complete in the active phase's `audits/` traceability artifact (or in the active milestone audit at `.luca/milestones/v<SEMVER>-audit.md` once milestone is open). Requirements live in MuninnDB engrams; the per-phase `audits/` files surface them durably.
|
|
1569
|
+
|
|
1570
|
+
### 10.5. Checkpoint Cleanup
|
|
1571
|
+
|
|
1572
|
+
After the phase passes verification (Loop A + Loop B both succeeded or were not needed):
|
|
1573
|
+
|
|
1574
|
+
```bash
|
|
1575
|
+
# Prune all iteration checkpoints for this phase
|
|
1576
|
+
bun run src/iteration/checkpoint.ts prune --phase={phase_number}
|
|
1577
|
+
```
|
|
1578
|
+
|
|
1579
|
+
This removes all `iter/{phase}/*` git tags and `.luca/checkpoints/iter-{phase}-*.json` metadata files, keeping the git tag namespace and checkpoint directory clean for future phases.
|
|
1580
|
+
|
|
1581
|
+
### 11. Commit Phase Completion
|
|
1582
|
+
|
|
1583
|
+
```bash
|
|
1584
|
+
git add .
|
|
1585
|
+
bun run commit --message="complete {phase-name} phase" --type=docs --scope={phase} --no-push --skip-checks
|
|
1586
|
+
````
|
|
1587
|
+
|
|
1588
|
+
Advance the workflow state after the actual commit succeeds. From `learn` the next step is typically `milestone` or `complete` per the pipeline-transitions table:
|
|
1589
|
+
|
|
1590
|
+
```bash
|
|
1591
|
+
luca state advance --to-step complete 2>/dev/null || true
|
|
1592
|
+
```
|
|
1593
|
+
|
|
1594
|
+
### 12. User Acceptance Testing (UAT)
|
|
1595
|
+
|
|
1596
|
+
**Skip if:** `--skip-uat` flag passed OR `workflow.uat_required: false` in config.
|
|
1597
|
+
|
|
1598
|
+
**Always runs** (verification depth scales with complexity via `verificationMode`). The `--skip-uat` flag and `workflow.uat_required: false` config override still allow skipping entirely.
|
|
1599
|
+
|
|
1600
|
+
| Complexity | UAT | Verification Mode |
|
|
1601
|
+
| ---------- | --------------------------------- | ----------------- |
|
|
1602
|
+
| TRIVIAL | Run (quick) | quick |
|
|
1603
|
+
| SIMPLE | Run (quick) | quick |
|
|
1604
|
+
| MODERATE | Run (standard) | standard |
|
|
1605
|
+
| COMPLEX | Run (full) | full |
|
|
1606
|
+
| CRITICAL | Run (full + thorough) | full+human |
|
|
1607
|
+
|
|
1608
|
+
**Auto-transition into UAT mode:**
|
|
1609
|
+
|
|
1610
|
+
```
|
|
1611
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
1612
|
+
Luca ► PHASE {Z} EXECUTION COMPLETE
|
|
1613
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
1614
|
+
|
|
1615
|
+
**Phase {Z}: {Name}**
|
|
1616
|
+
{Y} plans executed
|
|
1617
|
+
Goal verified ✓
|
|
1618
|
+
Code review passed ✓
|
|
1619
|
+
|
|
1620
|
+
## ▶ Starting UAT
|
|
1621
|
+
|
|
1622
|
+
Testing deliverables from this phase...
|
|
1623
|
+
```
|
|
1624
|
+
|
|
1625
|
+
**Follow the verify-work flow inline:** spawn the `verifier` subagent with the per-task acceptance criteria, parse its `verify.json` output, and route per the recommendation field (`pass`, `fix`, `escalate`).
|
|
1626
|
+
|
|
1627
|
+
1. **Find SUMMARY.md files** for the phase
|
|
1628
|
+
2. **Extract testable deliverables** (user-observable outcomes)
|
|
1629
|
+
3. **Create {phase}-UAT.md** with test list
|
|
1630
|
+
4. **Present tests one at a time** — show expected behavior, wait for response
|
|
1631
|
+
5. **Process responses:**
|
|
1632
|
+
- "yes/y/pass/next" → pass
|
|
1633
|
+
- Anything else → issue (severity inferred)
|
|
1634
|
+
6. **Update UAT.md** after each response
|
|
1635
|
+
|
|
1636
|
+
### 13. Handle UAT Results
|
|
1637
|
+
|
|
1638
|
+
**Route A: All tests pass, more phases remain**
|
|
1639
|
+
|
|
1640
|
+
```
|
|
1641
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
1642
|
+
Luca ► PHASE {Z} VERIFIED ✓
|
|
1643
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
1644
|
+
|
|
1645
|
+
{N}/{N} UAT tests passed ✓
|
|
1646
|
+
Code review passed ✓
|
|
1647
|
+
|
|
1648
|
+
## ▶ Next Up
|
|
1649
|
+
|
|
1650
|
+
**Phase {Z+1}: {Name}** — {Goal from roadmap.md}
|
|
1651
|
+
|
|
1652
|
+
/phase-discuss {Z+1} — gather context and clarify approach
|
|
1653
|
+
```
|
|
1654
|
+
|
|
1655
|
+
**Route B: All tests pass, milestone complete**
|
|
1656
|
+
|
|
1657
|
+
```
|
|
1658
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
1659
|
+
Luca ► MILESTONE COMPLETE 🎉
|
|
1660
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
1661
|
+
|
|
1662
|
+
{N} phases completed
|
|
1663
|
+
All UAT tests passed ✓
|
|
1664
|
+
All code reviews passed ✓
|
|
1665
|
+
|
|
1666
|
+
## ▶ Next Up
|
|
1667
|
+
|
|
1668
|
+
/milestone-audit
|
|
1669
|
+
```
|
|
1670
|
+
|
|
1671
|
+
**Route C: UAT issues found**
|
|
1672
|
+
|
|
1673
|
+
```
|
|
1674
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
1675
|
+
Luca ► PHASE {Z} ISSUES FOUND ⚠
|
|
1676
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
1677
|
+
|
|
1678
|
+
{N}/{M} tests passed
|
|
1679
|
+
{X} issues found
|
|
1680
|
+
|
|
1681
|
+
## ▶ Diagnosing and Planning Fixes...
|
|
1682
|
+
```
|
|
1683
|
+
|
|
1684
|
+
- Spawn parallel debug agents to diagnose root causes
|
|
1685
|
+
- **Root Cause Tribunal (conditional):** When debug agents return ROOT CAUSE FOUND during UAT diagnosis, check tribunal gating conditions before creating fix plans:
|
|
1686
|
+
- Gate: `root_cause_tribunal_enabled` in config (default: true) AND complexity is COMPLEX+ AND multi-issue debugging (issue_count >= 2)
|
|
1687
|
+
- When gated in: Spawn three tribunal agents in parallel (lu-debugger as defender, lu-verifier as challenger, lu-integration-checker as arbiter) to validate the proposed fix before planning
|
|
1688
|
+
- Resolution: "verified_fix" proceeds to fix planning; "needs_deeper_investigation" re-runs diagnosis with tribunal findings as additional context
|
|
1689
|
+
- Re-invoke the architect mode-agent (in --gaps context) to create fix plans
|
|
1690
|
+
- Spawn the `plan-reviewer` subagent to verify fix plans
|
|
1691
|
+
- Present ready status:
|
|
1692
|
+
|
|
1693
|
+
```
|
|
1694
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
1695
|
+
Luca ► FIXES READY ✓
|
|
1696
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
1697
|
+
|
|
1698
|
+
{N} gap(s) diagnosed, {M} fix plan(s) created
|
|
1699
|
+
|
|
1700
|
+
## ▶ Next Up
|
|
1701
|
+
|
|
1702
|
+
/clear then /phase-execute {Z} --gaps-only
|
|
1703
|
+
```
|
|
1704
|
+
|
|
1705
|
+
**Route D: Verifier gaps found (before UAT)**
|
|
1706
|
+
|
|
1707
|
+
```
|
|
1708
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
1709
|
+
Luca ► PHASE {Z} GAPS FOUND ⚠
|
|
1710
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
1711
|
+
|
|
1712
|
+
Score: {N}/{M} must-haves verified
|
|
1713
|
+
|
|
1714
|
+
## ▶ Next Up
|
|
1715
|
+
|
|
1716
|
+
/phase-plan {Z} --gaps
|
|
1717
|
+
```
|
|
1718
|
+
|
|
1719
|
+
## Deviation Rules
|
|
1720
|
+
|
|
1721
|
+
During execution, handle discoveries automatically:
|
|
1722
|
+
|
|
1723
|
+
1. **Auto-fix bugs** - Fix immediately, document in Summary
|
|
1724
|
+
2. **Auto-add critical** - Security/correctness gaps, add and document
|
|
1725
|
+
3. **Auto-fix blockers** - Can't proceed without fix, do it and document
|
|
1726
|
+
4. **Ask about architectural** - Major structural changes, stop and ask user
|
|
1727
|
+
|
|
1728
|
+
## Commit Rules
|
|
1729
|
+
|
|
1730
|
+
**IMPORTANT:** Always use `bun run commit` with flags. Always stage ALL files with `git add .` before committing. Partial commits are not allowed in standard workflow.
|
|
1731
|
+
|
|
1732
|
+
**Per-Task Commits:**
|
|
1733
|
+
|
|
1734
|
+
```bash
|
|
1735
|
+
git add .
|
|
1736
|
+
bun run commit --message="{task-name}" --type={type} --scope={phase}-{plan} --no-push --skip-checks
|
|
1737
|
+
```
|
|
1738
|
+
|
|
1739
|
+
**Plan Metadata Commit:**
|
|
1740
|
+
|
|
1741
|
+
```bash
|
|
1742
|
+
git add .
|
|
1743
|
+
bun run commit --message="complete {plan-name} plan" --type=docs --scope={phase}-{plan} --no-push --skip-checks
|
|
1744
|
+
```
|
|
1745
|
+
|
|
1746
|
+
**Phase Completion Commit:**
|
|
1747
|
+
|
|
1748
|
+
```bash
|
|
1749
|
+
git add .
|
|
1750
|
+
bun run commit --message="complete {phase-name} phase" --type=docs --scope={phase} --no-push --skip-checks
|
|
1751
|
+
```
|
|
1752
|
+
|
|
1753
|
+
## Success Criteria
|
|
1754
|
+
|
|
1755
|
+
- [ ] All incomplete plans in phase executed
|
|
1756
|
+
- [ ] Each plan has SUMMARY.md
|
|
1757
|
+
- [ ] Phase goal verified (must_haves checked against codebase)
|
|
1758
|
+
- [ ] VERIFICATION.md created in phase directory
|
|
1759
|
+
- [ ] Code review subagents spawned (dx-advocate, code-simplifier, code-architect, tailwind-auditor, security-auditor)
|
|
1760
|
+
- [ ] CRITICAL code issues block until fixed
|
|
1761
|
+
- [ ] HIGH/MEDIUM code issues presented with options
|
|
1762
|
+
- [ ] UAT.md created with tests from SUMMARY.md
|
|
1763
|
+
- [ ] UAT tests presented one at a time
|
|
1764
|
+
- [ ] UAT issues diagnosed and fix plans created (if any)
|
|
1765
|
+
- [ ] `.luca/state.json` reflects phase completion (advanced through learn/milestone steps)
|
|
1766
|
+
- [ ] `.luca/roadmap.md` updated (phase marked complete)
|
|
1767
|
+
- [ ] MuninnDB `brain:project-requirements` traceability updated (per-phase REQ-IDs marked complete)
|
|
1768
|
+
- [ ] User routed to next phase or fix execution
|
|
1769
|
+
|
|
1770
|
+
## Next Steps
|
|
1771
|
+
|
|
1772
|
+
| Condition | Action | Command |
|
|
1773
|
+
| ------------------------------ | --------------------- | --------------------------------------- |
|
|
1774
|
+
| UAT passed, more phases | Discuss next phase | `/phase-discuss {N+1}` |
|
|
1775
|
+
| UAT passed, milestone complete | Audit milestone | `/milestone-audit` |
|
|
1776
|
+
| UAT gaps found | Execute gap fixes | `/phase-execute {N} --gaps-only` |
|
|
1777
|
+
| Code review critical issues | Execute quality fixes | `/phase-execute {N} --quality-fixes` |
|
|
1778
|
+
| Verifier gaps found | Plan gap closure | `/phase-plan {N} --gaps` |
|
|
1779
|
+
|
|
1780
|
+
**Primary:** `/progress` — Check status and get smart routing
|
|
1781
|
+
|
|
1782
|
+
**Also available:**
|
|
1783
|
+
|
|
1784
|
+
- `/verify {phase}` — Run UAT separately
|
|
1785
|
+
- `/session-pause` — Create handoff if stopping mid-work
|
|
1786
|
+
</main>
|