@haposoft/cafekit 0.14.0 → 0.14.2
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/README.md +27 -3
- package/bin/__tests__/installer-safety.test.js +145 -0
- package/bin/install.js +9 -1
- package/bin/lib/backup.js +60 -16
- package/bin/lib/context.js +1 -1
- package/bin/phases/claude-runtime.js +57 -4
- package/bin/phases/post-install.js +39 -26
- package/bin/phases/root-config.js +24 -5
- package/bin/phases/select-platform.js +14 -9
- package/package.json +1 -1
- package/src/claude/CLAUDE.md +1 -1
- package/src/claude/agents/code-auditor.md +1 -1
- package/src/claude/agents/debugger.md +1 -0
- package/src/claude/agents/god-developer.md +10 -1
- package/src/claude/agents/inspector.md +1 -0
- package/src/claude/agents/spec-maker.md +1 -1
- package/src/claude/agents/test-runner.md +2 -2
- package/src/claude/gitignore +11 -4
- package/src/claude/hooks/__tests__/privacy-block.test.js +50 -10
- package/src/claude/hooks/__tests__/spec-gate.test.js +75 -1
- package/src/claude/hooks/__tests__/state.test.js +65 -0
- package/src/claude/hooks/docs-sync.cjs +15 -21
- package/src/claude/hooks/inspect-block.cjs +1 -1
- package/src/claude/hooks/lib/config.cjs +0 -5
- package/src/claude/hooks/privacy-block.cjs +39 -62
- package/src/claude/hooks/spec-gate.cjs +18 -7
- package/src/claude/hooks/spec-state.cjs +4 -0
- package/src/claude/hooks/state.cjs +13 -3
- package/src/claude/hooks/usage.cjs +6 -0
- package/src/claude/migration-manifest.json +1 -0
- package/src/claude/rules/orchestrator.md +2 -2
- package/src/claude/rules/skill-domain-routing.md +27 -86
- package/src/claude/rules/skill-workflow-routing.md +11 -74
- package/src/claude/rules/state-sync.md +1 -1
- package/src/claude/runtime.json +7 -7
- package/src/claude/scripts/validate-spec-output.cjs +6 -0
- package/src/claude/skills/code-review/references/spec-compliance-review.md +1 -1
- package/src/claude/skills/delegate/SKILL.md +124 -0
- package/src/claude/skills/delegate/references/codex-delegation.md +71 -0
- package/src/claude/skills/delegate/references/grok-delegation.md +84 -0
- package/src/claude/skills/develop/SKILL.md +26 -5
- package/src/claude/skills/develop/references/parallel-waves.md +112 -0
- package/src/claude/skills/develop/references/quality-gate.md +10 -2
- package/src/claude/skills/hotfix/references/parallel-patterns.md +1 -1
- package/src/claude/skills/inspect/SKILL.md +42 -113
- package/src/claude/skills/inspect/references/internal-inspection.md +16 -135
- package/src/claude/skills/specs/SKILL.md +134 -386
- package/src/claude/skills/specs/rules/tasks-generation.md +1 -1
- package/src/claude/skills/specs/templates/task.md +3 -1
- package/src/claude/skills/sync/SKILL.md +2 -2
- package/src/claude/skills/sync/references/sync-protocols.md +4 -4
- package/src/claude/skills/test/SKILL.md +1 -1
- package/src/claude/status.cjs +9 -6
- package/src/opencode/plugins/docs-sync.ts +10 -16
- package/src/claude/archive-command/code/SKILL.md +0 -55
- package/src/claude/archive-command/code/references/execution-loop.md +0 -21
- package/src/claude/archive-command/code.md +0 -17
- package/src/claude/archive-command/docs.md +0 -609
- package/src/claude/archive-command/review/codebase/parallel.md +0 -76
- package/src/claude/archive-command/spec-design.md +0 -247
- package/src/claude/archive-command/spec-init.md +0 -120
- package/src/claude/archive-command/spec-requirements.md +0 -138
- package/src/claude/archive-command/spec-status.md +0 -98
- package/src/claude/archive-command/spec-tasks.md +0 -173
- package/src/claude/archive-command/spec-validate.md +0 -118
- package/src/claude/archive-command/test.md +0 -8
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# Delegating to Grok CLI (Grok Build)
|
|
2
|
+
|
|
3
|
+
Verified against grok 0.2.101 (2026-07). Re-check `grok --help` if flags fail.
|
|
4
|
+
|
|
5
|
+
## Preflight
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
which grok && grok --version
|
|
9
|
+
grok models # available model IDs
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Non-interactive dispatch
|
|
13
|
+
|
|
14
|
+
Two forms:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
# single-turn from a brief file (preferred for delegation)
|
|
18
|
+
grok --prompt-file plans/<slug>-task.md \
|
|
19
|
+
--worktree=<slug> \
|
|
20
|
+
--check \
|
|
21
|
+
--permission-mode acceptEdits \
|
|
22
|
+
--allow "Bash(npm:*)" --allow "Bash(node:*)" \
|
|
23
|
+
--output-format plain
|
|
24
|
+
|
|
25
|
+
# short single-turn prompt
|
|
26
|
+
grok -p "<prompt>"
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Run in a background shell and poll the output.
|
|
30
|
+
|
|
31
|
+
### Key flags
|
|
32
|
+
|
|
33
|
+
| Flag | Notes |
|
|
34
|
+
|---|---|
|
|
35
|
+
| `--prompt-file <path>` | single-turn prompt from file |
|
|
36
|
+
| `-p, --single <prompt>` | single-turn inline prompt |
|
|
37
|
+
| `--worktree=<name>` | built-in git worktree isolation (grok-managed; see pitfalls) |
|
|
38
|
+
| `--check` | appends a self-verification loop (headless only) — use it |
|
|
39
|
+
| `--permission-mode <mode>` | `default` \| `acceptEdits` \| `auto` \| `dontAsk` \| `bypassPermissions` \| `plan` |
|
|
40
|
+
| `--allow "<RULE>"` / `--deny "<RULE>"` | permission rules, Claude Code syntax: `Bash(npm:*)`, `Write`, `Edit` |
|
|
41
|
+
| `-m <model>` / `--reasoning-effort` | model + effort overrides |
|
|
42
|
+
| `--max-turns <N>` | hard cap on agent turns |
|
|
43
|
+
| `--json-schema '<schema>'` | structured final output |
|
|
44
|
+
| `--output-format plain\|json\|streaming-json` | headless output format |
|
|
45
|
+
| `--resume <SESSION_ID>` | continue a session (context preserved) |
|
|
46
|
+
| `--best-of-n <N>` | run task N ways in parallel, pick best (headless) |
|
|
47
|
+
|
|
48
|
+
## Permission model — the #1 pitfall
|
|
49
|
+
|
|
50
|
+
`--permission-mode acceptEdits` **does not reliably unblock file writes in headless runs**; grok may report "Write tool blocked" and quietly degrade to a **design-only** response that reads like progress. It still exits 0.
|
|
51
|
+
|
|
52
|
+
Mitigations:
|
|
53
|
+
- Add explicit allow rules for write tools on the first dispatch: `--allow "Write" --allow "Edit" --allow "StrReplace"` alongside `--allow "Bash(npm:*)" --allow "Bash(node:*)"`.
|
|
54
|
+
- After ~30s, grep the output for `blocked`/`chặn` — catch degradation early.
|
|
55
|
+
- If the run finished design-only: **resume the same session** with widened allows and an explicit apply instruction; grok picks up its own design and implements without re-exploring:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
grok --resume <SESSION_ID> --no-plan \
|
|
59
|
+
--permission-mode acceptEdits \
|
|
60
|
+
--allow "Write" --allow "Edit" --allow "StrReplace" \
|
|
61
|
+
--allow "Bash(npm:*)" --allow "Bash(node:*)" \
|
|
62
|
+
--check -p "Continue: apply the designed changes, run tests, report results."
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Even with allows granted, shell may still be policy-restricted (runs finish with "npm test BLOCKED — shell not pre-approved"). That's fine: **you run the Evidence commands yourself during verification** — do not loosen to `bypassPermissions` just to make the agent self-verify.
|
|
66
|
+
|
|
67
|
+
## Worktree pitfalls
|
|
68
|
+
|
|
69
|
+
- `--worktree=<name>` worktrees are **grok-managed**: they may not appear in the target repo's `git worktree list` and `grok worktree list` may still say "No worktrees found". **Do not trust either listing** — after the run, check `git status` in the main repo to find where changes actually landed. In practice (0.2.101, resumed sessions) grok can write **directly into the main working tree** despite the flag.
|
|
70
|
+
- Consequence: always take a stash-backup snapshot before dispatch (`git stash push -u -m "backup: ..." && git stash apply -q`), and treat the main tree as potentially modified.
|
|
71
|
+
|
|
72
|
+
## Session management
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
grok sessions list # ids + summaries
|
|
76
|
+
grok --resume <SESSION_ID> [flags] -p "..." # continue with same context
|
|
77
|
+
grok export <SESSION_ID> # transcript as Markdown
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Quirks
|
|
81
|
+
|
|
82
|
+
- Grok reads the target repo's `CLAUDE.md` and obeys it (including tone rules) — repo constraints apply automatically, but so do repo-wide bans; account for that in the brief.
|
|
83
|
+
- `--check` produces a self-verification section in the final report — useful signal, **not** a substitute for your independent verification.
|
|
84
|
+
- Exit code 0 means the CLI ran, not that the task succeeded. Judge by diff + your own Evidence runs.
|
|
@@ -5,7 +5,7 @@ user-invocable: true
|
|
|
5
5
|
when_to_use: "Invoke to implement specs and tasks end-to-end after scope is clear."
|
|
6
6
|
category: utilities
|
|
7
7
|
keywords: [implementation, specs, build, orchestration]
|
|
8
|
-
argument-hint: "[feature-name|specs-directory-path] [task-file] [--flash] [--no-notes]"
|
|
8
|
+
argument-hint: "[feature-name|specs-directory-path] [task-file] [--flash] [--parallel [N]] [--no-notes]"
|
|
9
9
|
metadata:
|
|
10
10
|
author: haposoft
|
|
11
11
|
version: "1.0.0"
|
|
@@ -48,6 +48,27 @@ Triggered by `/hapo:develop <feature>` or `/hapo:develop specs/<feature>`.
|
|
|
48
48
|
- STOP the overall run on the first blocked task, unresolved gate failure, or missing proof.
|
|
49
49
|
- In `--flash` mode, missing full test proof does not stop the loop; record `FLASH_UNVERIFIED` and continue to the next unblocked task.
|
|
50
50
|
|
|
51
|
+
### 2b. Parallel Wave Mode (opt-in)
|
|
52
|
+
Triggered by adding `--parallel [N]` to Full-Spec mode. Load `references/parallel-waves.md` and follow it exactly — it is the operating procedure (wave planning, dispatch, merge, cleanup).
|
|
53
|
+
|
|
54
|
+
Contracts: WAVE_CONFIG
|
|
55
|
+
|
|
56
|
+
<!-- contract:WAVE_CONFIG -->
|
|
57
|
+
```jsonc
|
|
58
|
+
// .claude/runtime.json — develop parallel toggle (missing key = allowed)
|
|
59
|
+
"develop": {
|
|
60
|
+
"parallel": true // false = --parallel refused, sequential run + notice
|
|
61
|
+
}
|
|
62
|
+
// Flag: /hapo:develop <feature> --parallel [N] (N = wave cap, 1..5, default 3)
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
- Preconditions first: if `runtime.json` sets `develop.parallel: false`, refuse `--parallel`, name the key, and run the sequential loop. If the work context is not a git repository or worktree isolation is unavailable, state the reason and fall back sequential (see parallel-waves.md §1).
|
|
66
|
+
- Waves are computed from `task_registry.dependencies` with the single-writer-per-file rule; wave cap = N (1..5, default 3).
|
|
67
|
+
- Dispatch one `god-developer` per wave task — worktree isolation, background, self-contained prompt per `rules/orchestrator.md`, plus the mandatory lines in parallel-waves.md §3 (commit mandate; never edit `spec.json`/`tasks/*.md`; never touch files outside the task's `Related Files`).
|
|
68
|
+
- Quality gate (Stage A+B, unchanged) runs inside each task's worktree BEFORE merge; merge = sequential `git cherry-pick` of agent commits with explicit worktree/branch cleanup (spike-verified — see parallel-waves.md §5); post-merge integration check gates the next wave.
|
|
69
|
+
- The orchestrator is the single writer of spec state: registry/task-md/receipts update after each cherry-pick, exactly as in sequential mode.
|
|
70
|
+
- Without `--parallel`, nothing in this section applies — the sequential Full-Spec loop below is unchanged.
|
|
71
|
+
|
|
51
72
|
### 3. Flash Mode
|
|
52
73
|
Triggered by adding `--flash` to either specific-task or full-spec mode.
|
|
53
74
|
|
|
@@ -76,7 +97,7 @@ DO NOT write implementation code until an approved spec exists.
|
|
|
76
97
|
|
|
77
98
|
<DEFINITION-OF-DONE>
|
|
78
99
|
A task is NOT done because code compiles or a placeholder renders.
|
|
79
|
-
A task is done only when the task file's Completion Criteria AND Evidence
|
|
100
|
+
A task is done only when the task file's Completion Criteria AND `## Evidence` (legacy heading aliases still parse) are satisfied with real execution proof.
|
|
80
101
|
`--flash` is the only exception: it records fast implementation closeout with `FLASH_UNVERIFIED`, not full Definition of Done.
|
|
81
102
|
</DEFINITION-OF-DONE>
|
|
82
103
|
|
|
@@ -95,7 +116,7 @@ You MUST implement all scoped behavior for the active task, MUST NOT add out-of-
|
|
|
95
116
|
| Thought (Excuse) | Reality (Rule) |
|
|
96
117
|
|-------------------|----------------|
|
|
97
118
|
| "No need to scout first" | Coding without knowing the architecture is blind. ALWAYS call the `inspector` agent to scan files. |
|
|
98
|
-
| "Review process is too tedious, let me just finish it myself" | The system needs an audit trail through agents. ALWAYS delegate via `
|
|
119
|
+
| "Review process is too tedious, let me just finish it myself" | The system needs an audit trail through agents. ALWAYS delegate via the `Agent` tool. |
|
|
99
120
|
|
|
100
121
|
## Absolute Workflow
|
|
101
122
|
|
|
@@ -132,7 +153,7 @@ flowchart TD
|
|
|
132
153
|
- Objective + Constraints
|
|
133
154
|
- Related Files
|
|
134
155
|
- Completion Criteria
|
|
135
|
-
-
|
|
156
|
+
- `## Evidence` (legacy heading aliases still parse)
|
|
136
157
|
- Exact executable verification commands named in the task
|
|
137
158
|
- Requirement IDs referenced by the task
|
|
138
159
|
- Named technologies, frameworks, protocols, and data stores that the task/spec explicitly requires
|
|
@@ -192,7 +213,7 @@ The moment you finish coding, DO NOT proceed further. Switch to `references/qual
|
|
|
192
213
|
If `--flash` is active, use **Step 4F: Flash Gate** instead of the full automatic review loop.
|
|
193
214
|
|
|
194
215
|
- Passing Step 4 requires ALL of the following:
|
|
195
|
-
1. Automated verification passes, including preflight compile/typecheck/build health and every exact command named in the task's
|
|
216
|
+
1. Automated verification passes, including preflight compile/typecheck/build health and every exact command named in the task's `## Evidence` (legacy heading aliases still parse)
|
|
196
217
|
2. Spec compliance review passes: every scoped requirement and active task criterion is implemented, with no extras and no omissions
|
|
197
218
|
3. Code quality review passes
|
|
198
219
|
4. Task evidence passes (artifacts/runtime surfaces/reachability/negative-path checks from the task file are proven)
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# Parallel Waves — hapo:develop `--parallel` operating procedure
|
|
2
|
+
|
|
3
|
+
Normative protocol for executing independent spec tasks concurrently. Loaded by
|
|
4
|
+
`develop/SKILL.md` when Full-Spec mode runs with `--parallel [N]`. Verified against
|
|
5
|
+
live worktree-subagent behavior (spec `develop-parallel-wave`,
|
|
6
|
+
`reports/worktree-spike.md`, 2026-07-19).
|
|
7
|
+
|
|
8
|
+
## 1. Preconditions (check before anything else)
|
|
9
|
+
|
|
10
|
+
1. `.claude/runtime.json` → `develop.parallel` is not `false` (escape hatch; missing
|
|
11
|
+
key = allowed). If `false`: refuse `--parallel`, tell the user the hatch is active
|
|
12
|
+
and which key controls it, then run the standard sequential loop.
|
|
13
|
+
2. The work context is a git repository and worktree isolation is available.
|
|
14
|
+
Otherwise: state the reason ("not a git repo" / "isolation unavailable") and run
|
|
15
|
+
the standard **sequential fallback**.
|
|
16
|
+
3. `--parallel N`: **wave cap** = N clamped to 1..5; default 3. Never exceed 5 —
|
|
17
|
+
each subagent carries a ~200K context budget (orchestrator.md resource rule).
|
|
18
|
+
|
|
19
|
+
## 2. Wave planning (normative)
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
ready(t) = t.status == "pending" AND every dep in task_registry[t].dependencies
|
|
23
|
+
has status == "done"
|
|
24
|
+
candidates = ready tasks in task_registry order
|
|
25
|
+
wave = first ≤cap candidates, EXCLUDING any task that shares a Create or Modify
|
|
26
|
+
path (exact normalized string match over its Related Files table) with an
|
|
27
|
+
earlier task already in the wave — the excluded task returns to the pool
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
**Single writer per file per wave** is absolute. `Read` rows never conflict.
|
|
31
|
+
If the wave is empty but pending tasks remain, dependencies are unsatisfiable in
|
|
32
|
+
parallel — finish them with the sequential loop and say so.
|
|
33
|
+
|
|
34
|
+
### Worked example
|
|
35
|
+
|
|
36
|
+
Registry: A (deps: –), B (deps: –), C (deps: A), D (deps: – but shares
|
|
37
|
+
`src/api/users.ts` Modify with B). Cap 3.
|
|
38
|
+
|
|
39
|
+
- Wave 1 = A, B (D excluded: path collision with B; C excluded: dep on A)
|
|
40
|
+
- Wave 2 = C, D (A done unblocks C; B done releases D's path)
|
|
41
|
+
|
|
42
|
+
## 3. Dispatch (one god-developer per wave task)
|
|
43
|
+
|
|
44
|
+
Every dispatch uses worktree isolation + background execution and a
|
|
45
|
+
self-contained prompt per `rules/orchestrator.md` (task file content, design and
|
|
46
|
+
requirements excerpts, work-context/specs/docs paths, acceptance criteria) plus
|
|
47
|
+
these mandatory lines:
|
|
48
|
+
|
|
49
|
+
1. "You are in an isolated git worktree. Implement ONLY this task."
|
|
50
|
+
2. "Do NOT edit `spec.json` or any `tasks/*.md` — the orchestrator owns spec state."
|
|
51
|
+
3. "Do NOT touch files outside this task's `Related Files`."
|
|
52
|
+
4. "When done, `git add` your changes and `git commit -m \"task(<id>): <title>\"` —
|
|
53
|
+
an uncommitted worktree cannot be merged."
|
|
54
|
+
5. End with the standard `Status: DONE|CONCERNS|BLOCKED|NEEDS_INFO` block, plus
|
|
55
|
+
your worktree path, branch, and commit hash(es).
|
|
56
|
+
|
|
57
|
+
The Agent result returns `worktreePath` and `worktreeBranch` — record both per task.
|
|
58
|
+
|
|
59
|
+
## 4. Quality gate — inside the worktree, before merge
|
|
60
|
+
|
|
61
|
+
Run the unchanged Stage A + Stage B gate (`references/quality-gate.md`) per task
|
|
62
|
+
**with the task's worktree as working directory**. Gate evidence from that run
|
|
63
|
+
feeds the task receipt. 3 failed rounds → COLLAPSE protocol for that task only;
|
|
64
|
+
sibling tasks in the wave keep running.
|
|
65
|
+
|
|
66
|
+
## 5. Merge protocol (spike-verified — do not improvise)
|
|
67
|
+
|
|
68
|
+
⚠️ Spike finding: worktree branches are based on **`origin/<default-branch>`**
|
|
69
|
+
(`worktree.baseRef: "fresh"` default), NOT the session HEAD. On repos whose origin
|
|
70
|
+
default diverges, `git merge <agent-branch>` explodes into unrelated conflicts.
|
|
71
|
+
|
|
72
|
+
Therefore, for each gate-passed task, **sequentially** (one at a time, registry order):
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
git cherry-pick <agent-commit> # base-agnostic: applies only the agent's diff
|
|
76
|
+
# conflict? → git cherry-pick --abort
|
|
77
|
+
# → task_registry[task].status = "blocked", blocker = one-line conflict summary
|
|
78
|
+
# → continue with the next passed task
|
|
79
|
+
git worktree remove --force .claude/worktrees/agent-<id> # NOT auto-cleaned —
|
|
80
|
+
git branch -D worktree-agent-<id> # explicit cleanup, always
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Cleanup runs for unchanged/failed worktrees too (spike: even a read-only run
|
|
84
|
+
leaves its worktree and branch behind). Optionally set `worktree.baseRef: "head"`
|
|
85
|
+
in settings; cherry-pick remains the recipe regardless.
|
|
86
|
+
|
|
87
|
+
## 6. Post-merge integration check (per wave)
|
|
88
|
+
|
|
89
|
+
After the wave's last cherry-pick: run the project build or the affected test
|
|
90
|
+
subset (never the full suite mid-flight — that runs once at develop completion).
|
|
91
|
+
Failure = fix before computing the next wave. This is the wave gate of
|
|
92
|
+
`quality-gate.md`.
|
|
93
|
+
|
|
94
|
+
## 7. State sync — orchestrator is the single writer
|
|
95
|
+
|
|
96
|
+
Only the orchestrator writes `spec.json` and task markdown, after each task's
|
|
97
|
+
cherry-pick: registry `status`/`completed_at`/`last_updated_at`, task-md `Status`,
|
|
98
|
+
checkbox ticks, and a verification receipt citing the worktree gate evidence plus
|
|
99
|
+
the post-merge check result. The Stop completion gate (`spec-gate.cjs`) applies
|
|
100
|
+
unchanged — a receipt-less done blocks the turn. After syncing the wave, recompute
|
|
101
|
+
§2 and continue until no pending tasks remain.
|
|
102
|
+
|
|
103
|
+
## 8. Failure summary
|
|
104
|
+
|
|
105
|
+
| Event | Action |
|
|
106
|
+
|---|---|
|
|
107
|
+
| Escape hatch on / not a git repo / no isolation | Sequential fallback + stated reason |
|
|
108
|
+
| Same-wave path collision | Defer the later task to next wave (§2) |
|
|
109
|
+
| Gate fails 3× for a task | COLLAPSE for that task; wave continues |
|
|
110
|
+
| Cherry-pick conflict | Abort pick; task `blocked` + conflict blocker; wave continues |
|
|
111
|
+
| Post-merge check fails | No next wave until fixed |
|
|
112
|
+
| Empty wave, tasks pending | Sequential loop for the remainder + notice |
|
|
@@ -12,7 +12,7 @@ Green tests are NOT enough. The gate requires four proofs:
|
|
|
12
12
|
|
|
13
13
|
## Automation Semantics
|
|
14
14
|
|
|
15
|
-
- If the task names exact commands in
|
|
15
|
+
- If the task names exact commands in `## Evidence` (legacy heading aliases still parse), those exact commands are mandatory and must run before any fallback repo defaults.
|
|
16
16
|
- Preflight compile/typecheck/build health is mandatory. If compile/typecheck/build fails before tests are meaningful, the gate result is `PRECHECK_FAIL`, not `NO_TESTS`.
|
|
17
17
|
- `NO_TESTS` is never an automatic PASS.
|
|
18
18
|
- `NO_TESTS` is acceptable only when the task does **not** require a dedicated test suite command and every other required automated command/evidence item passes.
|
|
@@ -55,7 +55,7 @@ Variable: retry_count = 0
|
|
|
55
55
|
|
|
56
56
|
Before START_LOOP:
|
|
57
57
|
- Read the active task file(s)
|
|
58
|
-
- Extract Related Files, Completion Criteria, Evidence (
|
|
58
|
+
- Extract Related Files, Completion Criteria, `## Evidence` (legacy heading aliases still parse)
|
|
59
59
|
- Extract the exact executable verification commands in declaration order
|
|
60
60
|
- Extract relevant design contracts/invariants for the touched area
|
|
61
61
|
- Extract scope_lock, requirement IDs, runtime entrypoints/callers, and reachability proof obligations
|
|
@@ -129,3 +129,11 @@ Must log the Quality Gate result to the terminal for user visibility:
|
|
|
129
129
|
- **Preflight Fail:** `[x] Step 4 Quality Gate: PRECHECK_FAIL → compile/typecheck/build failed before tests mattered`
|
|
130
130
|
- **Fix Needed:** `[~] Step 4 Quality Gate: Tests/spec/evidence failed → returned to god-developer`
|
|
131
131
|
- **Awaiting Rescue:** `[!] Step 4 Quality Gate: Failed 3 rounds! Awaiting user intervention...`
|
|
132
|
+
|
|
133
|
+
## Working directory (parallel mode)
|
|
134
|
+
|
|
135
|
+
When `hapo:develop` runs in Parallel Wave Mode (`references/parallel-waves.md`), every Stage A and Stage B command for a task executes **with that task's worktree as the working directory**. Gate evidence recorded from the worktree run feeds the task's verification receipt. Thresholds, retry counter, and the COLLAPSE protocol are identical to sequential mode. A COLLAPSE of one task does not cancel other in-flight tasks of the wave.
|
|
136
|
+
|
|
137
|
+
## Post-merge integration check (per wave)
|
|
138
|
+
|
|
139
|
+
After the orchestrator cherry-picks the last gate-passed task of a wave: run the project build **or** the affected test subset (never the full suite mid-flight — it runs once at develop completion). While this check fails, the next wave MUST NOT start.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Parallel Patterns & Task Coordination
|
|
2
2
|
|
|
3
|
-
How to effectively leverage multiple subagents and native
|
|
3
|
+
How to effectively leverage multiple subagents (the `Agent` tool) and native task tracking (`TaskCreate`/`TaskUpdate`) during fix workflows.
|
|
4
4
|
|
|
5
5
|
## When to Go Parallel
|
|
6
6
|
|
|
@@ -20,12 +20,9 @@ Fast, token-efficient codebase discovery using parallel agents to find files nee
|
|
|
20
20
|
|
|
21
21
|
## When to Use
|
|
22
22
|
|
|
23
|
-
-
|
|
24
|
-
-
|
|
25
|
-
-
|
|
26
|
-
- User asks about project structure or where functionality lives
|
|
27
|
-
- Before changes that might affect multiple codebase parts
|
|
28
|
-
- Before review/debug/impact analysis when affected files are unclear
|
|
23
|
+
- Feature spanning multiple directories; user wants to find/locate/search files
|
|
24
|
+
- Debugging that needs file relationships; project structure questions
|
|
25
|
+
- Before multi-area changes, review, debug, or impact analysis
|
|
29
26
|
|
|
30
27
|
## Preflight Scope Gate (MANDATORY - All Modes)
|
|
31
28
|
|
|
@@ -34,87 +31,34 @@ Before scanning with ANY mode (internal or external):
|
|
|
34
31
|
2. Apply the built-in no-scan lists below.
|
|
35
32
|
3. Prefer file-type or glob hints whenever possible.
|
|
36
33
|
|
|
37
|
-
**When scope is too broad:**
|
|
38
|
-
|
|
39
|
-
Instead of rejecting, use a **2-phase approach**: first run a lightweight Structure Scout to understand the real layout, then divide work among parallel agents based on actual findings.
|
|
34
|
+
**When scope is too broad:** use a **2-phase approach** — lightweight Structure Scout first, then parallel agents on real sub-scopes.
|
|
40
35
|
|
|
41
36
|
### Phase 1 — Structure Scout (Single Agent, Run First)
|
|
42
37
|
|
|
43
|
-
Spawn **one
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
- Key config files (README.md, package.json, tsconfig.json, pyproject.toml, go.mod, etc.)
|
|
48
|
-
- Monorepo markers (packages/*, apps/*, lerna.json, pnpm-workspace.yaml, turbo.json)
|
|
49
|
-
2. **Estimate sub-scope sizes** - For each discovered directory, do a rough file count (no deep read needed)
|
|
50
|
-
3. **Return a division plan** - Scout outputs a structured list of logical sub-scopes (1-6), each with:
|
|
51
|
-
- Path or glob pattern
|
|
52
|
-
- Estimated file count
|
|
53
|
-
- Suggested focus area description
|
|
38
|
+
Spawn **one scout** to map top-level layout before dividing work:
|
|
39
|
+
1. List immediate children of the scope root (dirs + key config; monorepo markers)
|
|
40
|
+
2. Rough file count per discovered directory
|
|
41
|
+
3. Return a division plan of 1–6 logical sub-scopes (path/glob, est. files, focus)
|
|
54
42
|
|
|
55
|
-
|
|
43
|
+
Wait for Scout before Phase 2.
|
|
56
44
|
|
|
57
45
|
### Phase 2 — Parallel Explore Agents (Based on Scout Results)
|
|
58
46
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
- Merging sub-scopes that are too small (< 10 files)
|
|
63
|
-
- Splitting sub-scopes that are too large (> 100 files)
|
|
64
|
-
2. **Spawn parallel Explore agents** - One agent per sub-scope (SCALE 3-6 recommended)
|
|
65
|
-
3. **Aggregate findings** - Collect results from all agents into unified report
|
|
66
|
-
4. **Suggest next steps** - Based on findings, ask if user wants deeper investigation of specific areas
|
|
67
|
-
|
|
68
|
-
**Example flow:**
|
|
69
|
-
```
|
|
70
|
-
User: "scan entire ~/Desktop/project"
|
|
71
|
-
|
|
72
|
-
Phase 1 — Scout discovers:
|
|
73
|
-
- README.md, package.json, turbo.json → monorepo root
|
|
74
|
-
- packages/ → 3 sub-packages (~40 files each)
|
|
75
|
-
- apps/web/ → React frontend (~120 files)
|
|
76
|
-
- apps/api/ → NestJS backend (~80 files)
|
|
77
|
-
|
|
78
|
-
Scout outputs division plan:
|
|
79
|
-
- Scope A: root config files (README.md, package.json, turbo.json)
|
|
80
|
-
- Scope B: packages/* (shared libs)
|
|
81
|
-
- Scope C: apps/web/ (frontend)
|
|
82
|
-
- Scope D: apps/api/ (backend)
|
|
47
|
+
1. Follow Scout's plan; merge scopes < 10 files; split scopes > 100 files
|
|
48
|
+
2. Spawn parallel Explore agents (SCALE 3–6 recommended), one per sub-scope
|
|
49
|
+
3. Aggregate into the Inspect Report; offer deeper follow-up on specific areas
|
|
83
50
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
Result: "This is a monorepo with 2 apps, NestJS backend, React frontend, 3 shared packages..."
|
|
87
|
-
Follow-up: "Want to investigate deeper? Choose: backend API | frontend components | shared packages"
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
**Fallback to AskUserQuestion:**
|
|
91
|
-
- If Scout result is ambiguous (flat structure, no obvious divisions, < 3 distinguishable areas)
|
|
92
|
-
- Use `AskUserQuestion` with 2-4 concrete scope suggestions derived from Scout findings
|
|
93
|
-
- After user selects, re-invoke inspect with chosen scope
|
|
51
|
+
**Fallback to AskUserQuestion:** if Scout is ambiguous (flat layout, < 3 areas), offer 2–4 concrete scopes from findings, then re-invoke with the chosen scope.
|
|
94
52
|
|
|
95
53
|
## Built-in No-Scan Guidance
|
|
96
54
|
|
|
97
55
|
### `NO_SCAN_PATHS`
|
|
98
|
-
- `.git/`
|
|
99
|
-
- `
|
|
100
|
-
- `dist/`
|
|
101
|
-
- `build/`
|
|
102
|
-
- `.next/`
|
|
103
|
-
- `coverage/`
|
|
104
|
-
- `tmp/`
|
|
105
|
-
- `temp/`
|
|
106
|
-
- `vendor/`
|
|
107
|
-
- `artifacts/`
|
|
108
|
-
- `secrets/`
|
|
109
|
-
- `private/`
|
|
56
|
+
- `.git/`, `node_modules/`, `dist/`, `build/`, `.next/`, `coverage/`
|
|
57
|
+
- `tmp/`, `temp/`, `vendor/`, `artifacts/`, `secrets/`, `private/`
|
|
110
58
|
|
|
111
59
|
### `NO_SCAN_CONTENT_HINTS`
|
|
112
|
-
- private keys
|
|
113
|
-
-
|
|
114
|
-
- credential exports
|
|
115
|
-
- `.env` secrets
|
|
116
|
-
- generated bundles
|
|
117
|
-
- binary blobs
|
|
60
|
+
- private keys, token dumps, credential exports, `.env` secrets
|
|
61
|
+
- generated bundles, binary blobs
|
|
118
62
|
|
|
119
63
|
## Configuration
|
|
120
64
|
|
|
@@ -127,69 +71,54 @@ Read from `.claude/runtime.json`:
|
|
|
127
71
|
}
|
|
128
72
|
```
|
|
129
73
|
|
|
130
|
-
Default model: `gemma-4-31b-it`
|
|
131
|
-
|
|
132
|
-
**Note:** This file is automatically installed when you run `npx @haposoft/cafekit`.
|
|
74
|
+
Default model: `gemma-4-31b-it` (installed with `npx @haposoft/cafekit`).
|
|
133
75
|
|
|
134
76
|
## Workflow
|
|
135
77
|
|
|
136
78
|
### 1. Analyze Task
|
|
137
|
-
- Parse
|
|
138
|
-
-
|
|
139
|
-
- Determine optimal SCALE value of subagents to spawn
|
|
79
|
+
- Parse search targets; identify directories, patterns, file types
|
|
80
|
+
- Determine SCALE of subagents
|
|
140
81
|
|
|
141
82
|
**SCALE Calculation:**
|
|
142
83
|
```
|
|
143
84
|
SCALE = ceil(estimated_files_to_scan / 50)
|
|
144
85
|
```
|
|
145
86
|
|
|
146
|
-
|
|
147
|
-
-
|
|
148
|
-
-
|
|
149
|
-
-
|
|
150
|
-
|
|
151
|
-
**SCALE Thresholds:**
|
|
152
|
-
- SCALE 1-2: Simple, focused searches (< 100 files)
|
|
153
|
-
- SCALE 3-5: Medium scope, suitable for external Gemini CLI
|
|
154
|
-
- SCALE 6-10: Large scope, requires internal Explore agents
|
|
87
|
+
- Min SCALE = 1; Max SCALE = 10
|
|
88
|
+
- SCALE 1-2: focused (< 100 files)
|
|
89
|
+
- SCALE 3-5: medium (suitable for external Gemini CLI)
|
|
90
|
+
- SCALE 6-10: large (internal Explore agents)
|
|
155
91
|
|
|
156
92
|
### 2. Divide and Conquer
|
|
157
|
-
- Split
|
|
158
|
-
- Assign each agent specific directories or patterns
|
|
159
|
-
- Ensure no overlap, maximize coverage
|
|
93
|
+
- Split into logical segments; assign distinct directories/patterns; no overlap
|
|
160
94
|
|
|
161
95
|
### 3. Register Inspect Tasks
|
|
162
|
-
- **Skip if:** Agent count ≤ 2
|
|
163
|
-
- `TaskList` first
|
|
164
|
-
-
|
|
165
|
-
- See `./references/internal-inspection.md` for patterns and examples
|
|
96
|
+
- **Skip if:** Agent count ≤ 2
|
|
97
|
+
- `TaskList` first; if none, `TaskCreate` per agent with scope metadata
|
|
98
|
+
- See `./references/internal-inspection.md` for patterns
|
|
166
99
|
|
|
167
100
|
### 4. Choose Mode
|
|
168
101
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
102
|
+
| Condition | Mode |
|
|
103
|
+
|---|---|
|
|
104
|
+
| No `ext` argument | Internal Explore agents |
|
|
105
|
+
| `ext` + SCALE ≤ 5 | Gemini CLI (if available + scope gate passed) |
|
|
106
|
+
| `ext` + SCALE ≥ 6 | Internal Explore agents |
|
|
107
|
+
| Gemini unavailable/fails | Fallback to internal Explore |
|
|
174
108
|
|
|
175
|
-
Load
|
|
176
|
-
- **Internal (Default):** `./references/internal-inspection.md` (Explore subagents)
|
|
177
|
-
- **External:** `./references/external-gemini-inspection.md` (Gemini CLI)
|
|
109
|
+
Load: **Internal** `./references/internal-inspection.md` or **External** `./references/external-gemini-inspection.md`.
|
|
178
110
|
|
|
179
111
|
### 5. Spawn Parallel Agents
|
|
180
112
|
|
|
181
|
-
**
|
|
182
|
-
|
|
183
|
-
-
|
|
184
|
-
-
|
|
185
|
-
-
|
|
186
|
-
- Each subagent must return a detailed summary report to a main agent
|
|
113
|
+
**Internal mode:** dispatch native Explore agents with breadth medium/very-thorough + the Scope Gate above. Details: `./references/internal-inspection.md`.
|
|
114
|
+
|
|
115
|
+
- `TaskUpdate` each task to `in_progress` before spawn
|
|
116
|
+
- Prompt each subagent with exact directories/files; each has < 200K context
|
|
117
|
+
- Agent count follows resources + file volume; each returns a summary to the main agent
|
|
187
118
|
|
|
188
119
|
### 6. Collect Results
|
|
189
|
-
- Timeout: 3 minutes per agent (skip non-responders)
|
|
190
|
-
- `TaskUpdate` completed tasks;
|
|
191
|
-
- Aggregate findings into single report
|
|
192
|
-
- List unresolved questions at end
|
|
120
|
+
- Timeout: 3 minutes per agent (skip non-responders; log in report)
|
|
121
|
+
- `TaskUpdate` completed tasks; aggregate; list unresolved questions at end
|
|
193
122
|
|
|
194
123
|
## Report Format
|
|
195
124
|
|