@haposoft/cafekit 0.14.1 → 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.
Files changed (60) hide show
  1. package/README.md +7 -3
  2. package/bin/__tests__/installer-safety.test.js +145 -0
  3. package/bin/install.js +9 -1
  4. package/bin/lib/backup.js +60 -16
  5. package/bin/lib/context.js +1 -1
  6. package/bin/phases/claude-runtime.js +57 -4
  7. package/bin/phases/post-install.js +39 -26
  8. package/bin/phases/select-platform.js +14 -9
  9. package/package.json +1 -1
  10. package/src/claude/CLAUDE.md +1 -1
  11. package/src/claude/agents/code-auditor.md +1 -1
  12. package/src/claude/agents/debugger.md +1 -0
  13. package/src/claude/agents/god-developer.md +10 -1
  14. package/src/claude/agents/inspector.md +1 -0
  15. package/src/claude/agents/spec-maker.md +1 -1
  16. package/src/claude/agents/test-runner.md +2 -2
  17. package/src/claude/hooks/__tests__/privacy-block.test.js +50 -10
  18. package/src/claude/hooks/__tests__/spec-gate.test.js +75 -1
  19. package/src/claude/hooks/__tests__/state.test.js +65 -0
  20. package/src/claude/hooks/docs-sync.cjs +15 -21
  21. package/src/claude/hooks/inspect-block.cjs +1 -1
  22. package/src/claude/hooks/lib/config.cjs +0 -5
  23. package/src/claude/hooks/privacy-block.cjs +39 -62
  24. package/src/claude/hooks/spec-gate.cjs +18 -7
  25. package/src/claude/hooks/spec-state.cjs +4 -0
  26. package/src/claude/hooks/state.cjs +13 -3
  27. package/src/claude/hooks/usage.cjs +6 -0
  28. package/src/claude/rules/orchestrator.md +2 -2
  29. package/src/claude/rules/skill-domain-routing.md +27 -86
  30. package/src/claude/rules/skill-workflow-routing.md +11 -82
  31. package/src/claude/rules/state-sync.md +1 -1
  32. package/src/claude/runtime.json +7 -7
  33. package/src/claude/scripts/validate-spec-output.cjs +6 -0
  34. package/src/claude/skills/code-review/references/spec-compliance-review.md +1 -1
  35. package/src/claude/skills/develop/SKILL.md +26 -5
  36. package/src/claude/skills/develop/references/parallel-waves.md +112 -0
  37. package/src/claude/skills/develop/references/quality-gate.md +10 -2
  38. package/src/claude/skills/hotfix/references/parallel-patterns.md +1 -1
  39. package/src/claude/skills/inspect/SKILL.md +42 -113
  40. package/src/claude/skills/inspect/references/internal-inspection.md +16 -135
  41. package/src/claude/skills/specs/SKILL.md +134 -386
  42. package/src/claude/skills/specs/rules/tasks-generation.md +1 -1
  43. package/src/claude/skills/specs/templates/task.md +3 -1
  44. package/src/claude/skills/sync/SKILL.md +2 -2
  45. package/src/claude/skills/sync/references/sync-protocols.md +4 -4
  46. package/src/claude/skills/test/SKILL.md +1 -1
  47. package/src/claude/status.cjs +9 -6
  48. package/src/opencode/plugins/docs-sync.ts +10 -16
  49. package/src/claude/archive-command/code/SKILL.md +0 -55
  50. package/src/claude/archive-command/code/references/execution-loop.md +0 -21
  51. package/src/claude/archive-command/code.md +0 -17
  52. package/src/claude/archive-command/docs.md +0 -609
  53. package/src/claude/archive-command/review/codebase/parallel.md +0 -76
  54. package/src/claude/archive-command/spec-design.md +0 -247
  55. package/src/claude/archive-command/spec-init.md +0 -120
  56. package/src/claude/archive-command/spec-requirements.md +0 -138
  57. package/src/claude/archive-command/spec-status.md +0 -98
  58. package/src/claude/archive-command/spec-tasks.md +0 -173
  59. package/src/claude/archive-command/spec-validate.md +0 -118
  60. package/src/claude/archive-command/test.md +0 -8
@@ -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
 
@@ -1,10 +1,6 @@
1
1
  # Internal Discovery with Explore Subagents
2
2
 
3
- Use Explore subagents when SCALE >= 6 or external tools unavailable.
4
-
5
- ## How It Works
6
-
7
- Spawn multiple `Explore` subagents via `Agent` tool to search codebase in parallel.
3
+ Dispatch native Explore agents with breadth medium/very-thorough + the Scope Gate in `SKILL.md`. Use when SCALE ≥ 6 or external tools are unavailable.
8
4
 
9
5
  ## Agent Tool Configuration
10
6
 
@@ -18,156 +14,41 @@ subagent_type: "Explore"
18
14
  Quickly search {DIRECTORY} for files related to: {USER_PROMPT}
19
15
 
20
16
  Instructions:
21
- - Search for relevant files matching the task
22
- - Use Glob/Grep for file discovery
23
- - List files with brief descriptions
24
- - Timeout: 3 minutes max
25
- - Skip if timeout reached
17
+ - Search for relevant files matching the task (Glob/Grep)
18
+ - List files with brief descriptions; timeout 3 minutes; skip if timed out
26
19
 
27
20
  Report format:
28
21
  ## Found Files
29
22
  - `path/file.ext` - description
30
-
31
23
  ## Patterns
32
24
  - Key patterns observed
33
25
  ```
34
26
 
35
27
  ## Spawning Strategy
36
28
 
37
- ### Directory Division
38
- Split codebase logically:
39
- - `src/` - Source code
40
- - `lib/` - Libraries
41
- - `tests/` - Test files
42
- - `config/` - Configuration
43
- - `api/` - API routes
44
- - `types/` - Type definitions
45
-
46
- ### Parallel Execution
47
- - Spawn all agents in single `Agent` tool call
48
- - Each agent gets distinct directory scope
49
- - No overlap between agents
50
-
51
- ## Example
29
+ Split by logical dirs (`src/`, `lib/`, `tests/`, `config/`, `api/`, `types/`). Spawn all in one call; distinct scopes; no overlap.
52
30
 
53
- User prompt: "Find authentication-related files"
54
-
55
- ```
56
- Agent 1: Inspect src/auth/, src/middleware/ for auth files
57
- Agent 2: Inspect src/api/, src/routes/ for auth endpoints
58
- Agent 3: Inspect tests/ for auth tests
59
- Agent 4: Inspect lib/, utils/ for auth utilities
60
- Agent 5: Inspect config/ for auth configuration
61
- Agent 6: Inspect types/, interfaces/ for auth types
62
- ```
31
+ **Example** (auth): A1 `src/auth/, middleware/`; A2 `api/, routes/`; A3 `tests/`; A4 `lib/, utils/`; A5 `config/`; A6 `types/`.
63
32
 
64
33
  ## Task Registration (Optional)
65
34
 
66
- ### When to Register Tasks
67
-
68
- | Agents | Create Tasks? | Rationale |
69
- |--------|--------------|-----------|
70
- | ≤ 2 | No | Overhead exceeds benefit, finishes quickly |
71
- | ≥ 3 | Yes | Meaningful coordination, progress monitoring |
72
-
73
- ### Task Registration Flow
74
-
75
- ```
76
- TaskList() // Check for existing inspect tasks
77
- → Found tasks? → Skip creation, reuse existing
78
- → Empty? → TaskCreate per agent
79
- ```
80
-
81
- ### Task Metadata Pattern
82
-
83
- ```
84
- TaskCreate(
85
- subject: "Inspect {directory} for {target}",
86
- activeForm: "Searching {directory}",
87
- description: "Search {directories} for {patterns}",
88
- metadata: {
89
- agentType: "Explore",
90
- scope: "src/auth/,src/middleware/",
91
- scale: 6,
92
- agentIndex: 1,
93
- totalAgents: 6,
94
- toolMode: "internal",
95
- priority: "P2",
96
- effort: "3m"
97
- }
98
- )
99
- ```
100
-
101
- ### Task Lifecycle
35
+ | Agents | Create Tasks? |
36
+ |--------|--------------|
37
+ | ≤ 2 | No (overhead) |
38
+ | ≥ 3 | Yes |
102
39
 
103
- ```
104
- Step 3: TaskCreate per agent → status: pending
105
- Step 4: Before spawning agent → TaskUpdate → status: in_progress
106
- Step 5: Agent returns report → TaskUpdate → status: completed
107
- Step 5: Agent times out (3m) → Keep in_progress, add error metadata
108
- ```
109
-
110
- ## Timeout Handling
111
-
112
- - Set 3-minute timeout per agent
113
- - Skip non-responding agents
114
- - Don't restart timed-out agents
115
- - Aggregate available results
116
- - Log timeouts in final report's "Unresolved Questions" section
117
-
118
- ## Reading File Content
119
-
120
- When needing to read file content, use chunking to stay within context limits (<150K tokens safe zone).
121
-
122
- ### Step 1: Get Line Counts
123
- Use Read tool with limit/offset or check file size before reading.
124
-
125
- ### Step 2: Calculate Chunks
126
- - **Target:** ~500 lines per chunk (safe for most files)
127
- - **Max files per agent:** 3-5 small files OR 1 large file chunked
128
-
129
- **Chunking formula:**
130
- ```
131
- chunks = ceil(total_lines / 500)
132
- lines_per_chunk = ceil(total_lines / chunks)
133
- ```
134
-
135
- ### Step 3: Read Strategy
40
+ `TaskList` → reuse or `TaskCreate` per agent (`agentType: Explore`, scope, scale, agentIndex, totalAgents, toolMode: internal). Lifecycle: pending → in_progress before spawn → completed on return (timeout: keep in_progress + error metadata).
136
41
 
137
- **Small files (<500 lines each):**
138
- - Read entire file with Read tool
42
+ ## Timeout, Aggregation, Reading
139
43
 
140
- **Large file (>500 lines):**
141
- - Use Read tool with offset/limit parameters
142
- - Read in 500-line chunks
143
-
144
- ### Chunking Decision Tree
145
- ```
146
- File < 500 lines → Read entire file
147
- File 500-1500 lines → Split into 2-3 chunks
148
- File > 1500 lines → Split into ceil(lines/500) chunks
149
- ```
150
-
151
- ## Result Aggregation
152
-
153
- Combine results from all agents:
154
- 1. Deduplicate file paths
155
- 2. Merge descriptions
156
- 3. Note any gaps/timeouts
157
- 4. List unresolved questions
44
+ - 3 min/agent; skip non-responders; do not restart; dedupe paths; note gaps in Unresolved Questions
45
+ - Stay under ~150K tokens; ~500 lines/chunk; max 3–5 small files or 1 large file chunked (`chunks = ceil(total_lines / 500)`); Read with offset/limit
158
46
 
159
47
  ## Scope Discipline
160
48
 
161
- - Start from concrete directories, not repo root
162
- - Prefer scope like `packages/spec/src/claude/skills/**/*.md` over `**/*.md`
163
- - Skip `NO_SCAN_PATHS` from SKILL.md
164
- - Avoid content matching `NO_SCAN_CONTENT_HINTS`
165
- - If request still broad, stop and narrow before continuing
49
+ Start from concrete directories (not repo root); prefer scoped globs; skip `NO_SCAN_PATHS` / `NO_SCAN_CONTENT_HINTS` from SKILL.md; if still broad, narrow first.
166
50
 
167
51
  ## Output Contract
168
52
 
169
- Return:
170
- - file paths
171
- - brief description per file
172
- - notable relationships or repeated patterns
173
- - unresolved questions
53
+ Return: file paths, brief description per file, notable relationships/patterns, unresolved questions.
54
+