@haposoft/cafekit 0.14.1 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/README.md +86 -11
  2. package/bin/__tests__/codex-hooks.test.js +331 -0
  3. package/bin/__tests__/codex-native.test.js +458 -0
  4. package/bin/__tests__/installer-safety.test.js +259 -0
  5. package/bin/install.js +30 -8
  6. package/bin/lib/backup.js +82 -18
  7. package/bin/lib/codex-frontmatter.js +56 -0
  8. package/bin/lib/codex-install.js +195 -0
  9. package/bin/lib/context.js +65 -8
  10. package/bin/lib/copy-utils.js +1 -1
  11. package/bin/lib/i18n.js +12 -3
  12. package/bin/lib/managed-writer.js +17 -2
  13. package/bin/lib/manifest.js +21 -4
  14. package/bin/lib/opencode-install.js +21 -19
  15. package/bin/lib/path-safety.js +40 -0
  16. package/bin/lib/version-check.js +25 -12
  17. package/bin/phases/claude-runtime.js +60 -9
  18. package/bin/phases/codex-runtime.js +110 -0
  19. package/bin/phases/copy-payload.js +36 -16
  20. package/bin/phases/post-install.js +98 -48
  21. package/bin/phases/root-config.js +4 -2
  22. package/bin/phases/select-platform.js +105 -66
  23. package/bin/phases/summary.js +6 -1
  24. package/package.json +3 -2
  25. package/src/claude/CLAUDE.md +1 -1
  26. package/src/claude/agents/code-auditor.md +1 -1
  27. package/src/claude/agents/debugger.md +1 -0
  28. package/src/claude/agents/god-developer.md +10 -1
  29. package/src/claude/agents/inspector.md +1 -0
  30. package/src/claude/agents/spec-maker.md +1 -1
  31. package/src/claude/agents/test-runner.md +2 -2
  32. package/src/claude/hooks/__tests__/privacy-block.test.js +50 -10
  33. package/src/claude/hooks/__tests__/spec-gate.test.js +75 -1
  34. package/src/claude/hooks/__tests__/state.test.js +65 -0
  35. package/src/claude/hooks/docs-sync.cjs +15 -21
  36. package/src/claude/hooks/inspect-block.cjs +1 -1
  37. package/src/claude/hooks/lib/config.cjs +0 -5
  38. package/src/claude/hooks/privacy-block.cjs +39 -62
  39. package/src/claude/hooks/spec-gate.cjs +18 -7
  40. package/src/claude/hooks/spec-state.cjs +4 -0
  41. package/src/claude/hooks/state.cjs +13 -3
  42. package/src/claude/hooks/usage.cjs +6 -0
  43. package/src/claude/rules/orchestrator.md +2 -2
  44. package/src/claude/rules/skill-domain-routing.md +27 -86
  45. package/src/claude/rules/skill-workflow-routing.md +11 -82
  46. package/src/claude/rules/state-sync.md +1 -1
  47. package/src/claude/runtime.json +7 -7
  48. package/src/claude/scripts/generate-skill-catalog.cjs +8 -3
  49. package/src/claude/scripts/validate-spec-output.cjs +6 -0
  50. package/src/claude/skills/code-review/references/spec-compliance-review.md +1 -1
  51. package/src/claude/skills/develop/SKILL.md +26 -5
  52. package/src/claude/skills/develop/references/parallel-waves.md +112 -0
  53. package/src/claude/skills/develop/references/quality-gate.md +10 -2
  54. package/src/claude/skills/hotfix/references/parallel-patterns.md +1 -1
  55. package/src/claude/skills/inspect/SKILL.md +42 -113
  56. package/src/claude/skills/inspect/references/internal-inspection.md +16 -135
  57. package/src/claude/skills/specs/SKILL.md +134 -386
  58. package/src/claude/skills/specs/rules/tasks-generation.md +1 -1
  59. package/src/claude/skills/specs/templates/task.md +3 -1
  60. package/src/claude/skills/sync/SKILL.md +2 -2
  61. package/src/claude/skills/sync/references/sync-protocols.md +4 -4
  62. package/src/claude/skills/test/SKILL.md +1 -1
  63. package/src/claude/status.cjs +9 -6
  64. package/src/codex/AGENTS.md +30 -0
  65. package/src/codex/agents-gitignore +11 -0
  66. package/src/codex/gitignore +12 -0
  67. package/src/codex/hooks/agent.cjs +66 -0
  68. package/src/codex/hooks/docs-sync.cjs +66 -0
  69. package/src/codex/hooks/inspect-block.cjs +40 -0
  70. package/src/codex/hooks/lib/hook-context.cjs +93 -0
  71. package/src/codex/hooks/lib/inspect-paths.cjs +199 -0
  72. package/src/codex/hooks/lib/privacy-state.cjs +199 -0
  73. package/src/codex/hooks/lib/spec-receipt.cjs +78 -0
  74. package/src/codex/hooks/lib/spec-utils.cjs +50 -0
  75. package/src/codex/hooks/lib/state-store.cjs +166 -0
  76. package/src/codex/hooks/privacy-approval.cjs +59 -0
  77. package/src/codex/hooks/privacy-block.cjs +182 -0
  78. package/src/codex/hooks/rules.cjs +79 -0
  79. package/src/codex/hooks/session.cjs +114 -0
  80. package/src/codex/hooks/spec-gate.cjs +80 -0
  81. package/src/codex/hooks/spec-state.cjs +73 -0
  82. package/src/codex/hooks/state.cjs +157 -0
  83. package/src/codex/hooks/task-scaffold-guard.cjs +63 -0
  84. package/src/codex/hooks.json +122 -0
  85. package/src/codex/rules/hook-protocols.md +32 -0
  86. package/src/codex/rules/state-sync.md +41 -0
  87. package/src/codex/runtime.json +28 -0
  88. package/src/opencode/plugins/docs-sync.ts +10 -16
  89. package/src/claude/archive-command/code/SKILL.md +0 -55
  90. package/src/claude/archive-command/code/references/execution-loop.md +0 -21
  91. package/src/claude/archive-command/code.md +0 -17
  92. package/src/claude/archive-command/docs.md +0 -609
  93. package/src/claude/archive-command/review/codebase/parallel.md +0 -76
  94. package/src/claude/archive-command/spec-design.md +0 -247
  95. package/src/claude/archive-command/spec-init.md +0 -120
  96. package/src/claude/archive-command/spec-requirements.md +0 -138
  97. package/src/claude/archive-command/spec-status.md +0 -98
  98. package/src/claude/archive-command/spec-tasks.md +0 -173
  99. package/src/claude/archive-command/spec-validate.md +0 -118
  100. package/src/claude/archive-command/test.md +0 -8
@@ -37,9 +37,14 @@ function parseArgs(argv) {
37
37
  }
38
38
 
39
39
  function defaultSkillsRoot() {
40
- const installed = path.resolve(process.cwd(), '.claude', 'skills');
41
- if (fs.existsSync(installed)) return installed;
42
- return path.resolve(__dirname, '..', 'skills');
40
+ const candidates = [
41
+ path.resolve(process.cwd(), '.claude', 'skills'),
42
+ path.resolve(process.cwd(), '.agents', 'skills'),
43
+ path.resolve(process.cwd(), '.opencode', 'skills'),
44
+ path.resolve(__dirname, '..', 'skills'),
45
+ path.resolve(__dirname, '..', '..', '.agents', 'skills')
46
+ ];
47
+ return candidates.find((candidate) => fs.existsSync(candidate)) || candidates[0];
43
48
  }
44
49
 
45
50
  function readText(filePath) {
@@ -113,6 +113,7 @@ function validateTaskSections(taskPath, content, errors) {
113
113
  hasHeading(content, 'Requirements') || /_Requirements:\s*[^_\n]+_/i.test(content);
114
114
  const hasRelatedFiles = hasHeading(content, 'Related Files');
115
115
  const hasCompletionCriteria = hasHeading(content, 'Completion Criteria');
116
+ // legacy heading aliases: read-compat only, no longer advertised
116
117
  const hasEvidence =
117
118
  hasHeading(content, 'Evidence') ||
118
119
  hasHeading(content, 'Task Test Plan & Verification Evidence') ||
@@ -365,6 +366,11 @@ function validateSpec(specDir) {
365
366
  const contractDefs = fs.existsSync(designPath)
366
367
  ? extractContractDefs(fs.readFileSync(designPath, 'utf8'))
367
368
  : new Map();
369
+ if (taskFiles.length >= 5 && contractDefs.size === 0) {
370
+ warnings.push(
371
+ 'design.md declares no contract blocks; specs spanning BE/FE must declare shared shapes (<!-- contract:NAME -->)',
372
+ );
373
+ }
368
374
  for (const taskFile of taskFiles) {
369
375
  const fullPath = path.join(specDir, taskFile);
370
376
  const content = fs.readFileSync(fullPath, 'utf8');
@@ -24,7 +24,7 @@ Do not attempt a standard text-based review if the project includes Visual Specs
24
24
  3. If NO (Markdown Spec only): Read the spec directly and extract:
25
25
  - requirement bullets
26
26
  - task `Completion Criteria`
27
- - task `Evidence` (or `Task Test Plan & Verification Evidence` / legacy `Verification & Evidence`)
27
+ - task `## Evidence` (legacy heading aliases still parse)
28
28
  - canonical contracts/invariants from `design.md`
29
29
  Then verify the changed files against those concrete obligations.
30
30
 
@@ -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 section are satisfied with real execution proof. Existing specs may use `Task Test Plan & Verification Evidence` or legacy `Verification & Evidence`; treat those as the same contract.
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 `Task` tool. |
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
- - Evidence (or `Task Test Plan & Verification Evidence` / legacy `Verification & Evidence`)
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 `Evidence` section (or `Task Test Plan & Verification Evidence` / legacy `Verification & Evidence`)
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 `Evidence` (or `Task Test Plan & Verification Evidence` / legacy `Verification & Evidence`), those exact commands are mandatory and must run before any fallback repo defaults.
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 (or Task Test Plan & Verification Evidence / legacy Verification & 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 Task tools during fix workflows.
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
- - Beginning work on feature spanning multiple directories
24
- - User mentions needing to "find", "locate", or "search for" files
25
- - Starting debugging session requiring file relationships understanding
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 dedicated scout agent** to map the top-level structure before any work is divided:
44
-
45
- 1. **Discover top-level layout** - Use `Glob` or `Bash` `ls` to list immediate children of the scope root:
46
- - Top-level directories (src/, apps/, backend/, frontend/, packages/, etc.)
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
- > Wait for Scout to complete before proceeding to Phase 2.
43
+ Wait for Scout before Phase 2.
56
44
 
57
45
  ### Phase 2 — Parallel Explore Agents (Based on Scout Results)
58
46
 
59
- Use the Scout's division plan to spawn parallel agents — one per sub-scope:
60
-
61
- 1. **Auto-divide into sub-scopes** - Follow Scout's plan, adjusted for:
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
- Phase 2 — 4 agents run in parallel on Scope A–D
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
- - `node_modules/`
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
- - token dumps
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 user prompt for search targets
138
- - Identify key directories, patterns, file types, lines of code
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
- Where:
147
- - `estimated_files_to_scan` = rough count of files matching scope
148
- - Minimum SCALE = 1 (single agent)
149
- - Maximum SCALE = 10 (practical limit for coordination overhead)
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 codebase into logical segments per agent
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 (overhead exceeds benefit)
163
- - `TaskList` first — check for existing inspect tasks in session
164
- - If not found, `TaskCreate` per agent with scope metadata
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
- Decision table:
170
- - **No `ext` argument** → Use internal Explore agents
171
- - **`ext` argument + SCALE ≤ 5** → Use Gemini CLI (if scope gate passed and Gemini available)
172
- - **`ext` argument + SCALE ≥ 6** → Use internal Explore agents (external not suitable for large scale)
173
- - **Gemini unavailable or fails** → Fallback to internal Explore agents
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 appropriate reference:
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
- **Notes:**
182
- - `TaskUpdate` each task to `in_progress` before spawning its agent
183
- - Prompt detailed instructions for each subagent with exact directories or files it should read
184
- - Remember that each subagent has less than 200K tokens of context window
185
- - Amount of subagents to-be-spawned depends on the current system resources available and amount of files to be scanned
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; log timed-out agents in report
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