@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.
Files changed (66) hide show
  1. package/README.md +27 -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/root-config.js +24 -5
  9. package/bin/phases/select-platform.js +14 -9
  10. package/package.json +1 -1
  11. package/src/claude/CLAUDE.md +1 -1
  12. package/src/claude/agents/code-auditor.md +1 -1
  13. package/src/claude/agents/debugger.md +1 -0
  14. package/src/claude/agents/god-developer.md +10 -1
  15. package/src/claude/agents/inspector.md +1 -0
  16. package/src/claude/agents/spec-maker.md +1 -1
  17. package/src/claude/agents/test-runner.md +2 -2
  18. package/src/claude/gitignore +11 -4
  19. package/src/claude/hooks/__tests__/privacy-block.test.js +50 -10
  20. package/src/claude/hooks/__tests__/spec-gate.test.js +75 -1
  21. package/src/claude/hooks/__tests__/state.test.js +65 -0
  22. package/src/claude/hooks/docs-sync.cjs +15 -21
  23. package/src/claude/hooks/inspect-block.cjs +1 -1
  24. package/src/claude/hooks/lib/config.cjs +0 -5
  25. package/src/claude/hooks/privacy-block.cjs +39 -62
  26. package/src/claude/hooks/spec-gate.cjs +18 -7
  27. package/src/claude/hooks/spec-state.cjs +4 -0
  28. package/src/claude/hooks/state.cjs +13 -3
  29. package/src/claude/hooks/usage.cjs +6 -0
  30. package/src/claude/migration-manifest.json +1 -0
  31. package/src/claude/rules/orchestrator.md +2 -2
  32. package/src/claude/rules/skill-domain-routing.md +27 -86
  33. package/src/claude/rules/skill-workflow-routing.md +11 -74
  34. package/src/claude/rules/state-sync.md +1 -1
  35. package/src/claude/runtime.json +7 -7
  36. package/src/claude/scripts/validate-spec-output.cjs +6 -0
  37. package/src/claude/skills/code-review/references/spec-compliance-review.md +1 -1
  38. package/src/claude/skills/delegate/SKILL.md +124 -0
  39. package/src/claude/skills/delegate/references/codex-delegation.md +71 -0
  40. package/src/claude/skills/delegate/references/grok-delegation.md +84 -0
  41. package/src/claude/skills/develop/SKILL.md +26 -5
  42. package/src/claude/skills/develop/references/parallel-waves.md +112 -0
  43. package/src/claude/skills/develop/references/quality-gate.md +10 -2
  44. package/src/claude/skills/hotfix/references/parallel-patterns.md +1 -1
  45. package/src/claude/skills/inspect/SKILL.md +42 -113
  46. package/src/claude/skills/inspect/references/internal-inspection.md +16 -135
  47. package/src/claude/skills/specs/SKILL.md +134 -386
  48. package/src/claude/skills/specs/rules/tasks-generation.md +1 -1
  49. package/src/claude/skills/specs/templates/task.md +3 -1
  50. package/src/claude/skills/sync/SKILL.md +2 -2
  51. package/src/claude/skills/sync/references/sync-protocols.md +4 -4
  52. package/src/claude/skills/test/SKILL.md +1 -1
  53. package/src/claude/status.cjs +9 -6
  54. package/src/opencode/plugins/docs-sync.ts +10 -16
  55. package/src/claude/archive-command/code/SKILL.md +0 -55
  56. package/src/claude/archive-command/code/references/execution-loop.md +0 -21
  57. package/src/claude/archive-command/code.md +0 -17
  58. package/src/claude/archive-command/docs.md +0 -609
  59. package/src/claude/archive-command/review/codebase/parallel.md +0 -76
  60. package/src/claude/archive-command/spec-design.md +0 -247
  61. package/src/claude/archive-command/spec-init.md +0 -120
  62. package/src/claude/archive-command/spec-requirements.md +0 -138
  63. package/src/claude/archive-command/spec-status.md +0 -98
  64. package/src/claude/archive-command/spec-tasks.md +0 -173
  65. package/src/claude/archive-command/spec-validate.md +0 -118
  66. package/src/claude/archive-command/test.md +0 -8
@@ -157,7 +157,7 @@ Every task file MUST contain the Risk Assessment table, even if no risks are ide
157
157
 
158
158
  ### Mandatory Evidence Section
159
159
 
160
- Every new task file MUST include a `## Evidence` section. Existing specs may still use the v0.8 heading `## Task Test Plan & Verification Evidence` or the legacy `## Verification & Evidence` heading; readers and sync tools must support all three.
160
+ Every new task file MUST include a `## Evidence` section (`## Evidence` (legacy heading aliases still parse)).
161
161
 
162
162
  That section is the task-level test plan and proof checklist. It MUST contain:
163
163
  1. **Automated proof** — exact command(s) for typecheck, tests, build, or explicit `N/A`
@@ -60,6 +60,8 @@
60
60
  This section is both the task-level test plan and the proof checklist. Keep it short, exact, and executable.
61
61
  Select the proof by task risk; do not run every test type for every task.
62
62
 
63
+ Verification: PENDING
64
+
63
65
  - Logic/data/validator task: include unit tests.
64
66
  - Stateful UI/component task: include component or integration tests.
65
67
  - Cross-module/API/state flow task: include integration tests.
@@ -94,4 +96,4 @@ Select the proof by task risk; do not run every test type for every task.
94
96
  > **Parallel marker**: Append `(P)` to the title if this task can run concurrently with another (usually when serving different requirements).
95
97
  > **Test note**: If a test coverage sub-task can be deferred post-MVP, mark it with `- [ ]*`.
96
98
  > **Requirement mapping**: Every sub-task MUST end with `_Requirements: X.X_`. No mapping = invalid task file.
97
- > **Evidence rule**: No `## Evidence` section = invalid task file. Existing specs may use `## Task Test Plan & Verification Evidence` or legacy `## Verification & Evidence`; agents must support all three headings.
99
+ > **Evidence rule**: No `## Evidence` section = invalid task file. Use `## Evidence` (legacy heading aliases still parse).
@@ -39,8 +39,8 @@ Scans the `spec.json` against all physical `task-R*.md` files to detect mismatch
39
39
 
40
40
  1. **Precision Edits:** Never overwrite the entire `spec.json` string blindly. Update only the required keys, while keeping JSON valid.
41
41
  2. **Machine + Human Sync:** Every task status update MUST modify both `spec.json.task_registry[...]` and the matching markdown task file header/status section.
42
- 3. **Markdown Integrity:** When marking a task `done`, only then turn `[ ]` into `[x]` inside `## Steps` / `## Implementation Steps` and relevant `Completion Criteria` / `Evidence` checkboxes that have actual proof. `Task Test Plan & Verification Evidence` and legacy `Verification & Evidence` sections are supported.
43
- 4. **Verification Receipt Rule:** `done` is illegal without a human-readable verification receipt already present in `## Evidence`, `## Task Test Plan & Verification Evidence`, or legacy `## Verification & Evidence` (commands executed, artifact/runtime proof, or equivalent concrete evidence). If proof is missing, keep the task `in_progress` or `blocked`.
42
+ 3. **Markdown Integrity:** When marking a task `done`, only then turn `[ ]` into `[x]` inside `## Steps` / `## Implementation Steps` and relevant `Completion Criteria` / `Evidence` checkboxes that have actual proof. Use `## Evidence` (legacy heading aliases still parse).
43
+ 4. **Verification Receipt Rule:** `done` is illegal without a human-readable verification receipt already present in `## Evidence` (legacy heading aliases still parse) (commands executed, artifact/runtime proof, or equivalent concrete evidence). If proof is missing, keep the task `in_progress` or `blocked`.
44
44
  5. **Task Docs Hook:** Every time `hapo:sync` marks a task as `done`, it must flag that a task-level docs checkpoint is now due for that verified task.
45
45
  6. **Phase Prompt Rule:** When `hapo:sync` marks the final pending task in the whole feature as `done`, it should automatically prompt the user if they'd like to advance the phase, but only after the docs checkpoint for that last completed task has been considered.
46
46
 
@@ -15,7 +15,7 @@ When requested to update a phase or change task configuration, `spec.json` must
15
15
  - full relative path like `tasks/task-R0-02-extension-shell.md`
16
16
  * **Status Update:** If a task changes to `blocked`, the matching `task_registry[path].status` must become `"blocked"`, `task_registry[path].blocker` must record the reason, and `spec.json.status` / `spec.json.blocker` must reflect the top-level block if work is globally blocked.
17
17
  * **Timestamp Rule:** Update `task_registry[path].started_at`, `completed_at`, and `last_updated_at` consistently with the new state. Also refresh `spec.json.updated_at`.
18
- * **Done-State Rule:** Never set `task_registry[path].status = "done"` unless the matching markdown task file already contains a verification receipt in `## Evidence`, `## Task Test Plan & Verification Evidence`, or legacy `## Verification & Evidence`, or the caller explicitly provides proof that can be written there first.
18
+ * **Done-State Rule:** Never set `task_registry[path].status = "done"` unless the matching markdown task file already contains a verification receipt in `## Evidence` (legacy heading aliases still parse), or the caller explicitly provides proof that can be written there first.
19
19
  * **Receipt Integrity Rule:** A valid verification receipt must include the exact commands run, their outcomes, and artifact/runtime proof. Receipts containing `PRECHECK_FAIL`, `FAIL`, `UNVERIFIED`, or explicit "placeholder / simplified for MVP / production later" contract deviations are not eligible for `done`.
20
20
  * **Contract Fidelity Rule:** If the task file notes or evidence show that a named framework/auth/runtime choice from the spec was silently replaced, sync MUST refuse `done` until the spec is amended or the implementation is corrected.
21
21
  * **Task Docs Rule:** After a task is moved to `done`, emit a short alert that a task-level docs checkpoint is due for this verified task.
@@ -27,12 +27,12 @@ The structure of `tasks/task.md` relies heavily on exact keyword markers. Follow
27
27
  ### A. Completing a Task
28
28
  When `/hapo:sync <feature> <task-id> done`:
29
29
  1. Find: `**Status:** pending` (or `in_progress` / `blocked`).
30
- 2. Inspect `## Evidence` first. If the task uses `## Task Test Plan & Verification Evidence` or legacy `## Verification & Evidence`, inspect that section instead. If it has no explicit proof lines (commands run, artifact proof, runtime proof, or blockers cleared), STOP and refuse to mark the task done.
30
+ 2. Inspect `## Evidence` (legacy heading aliases still parse) first. If it has no explicit proof lines (commands run, artifact proof, runtime proof, or blockers cleared), STOP and refuse to mark the task done.
31
31
  3. Refuse completion if the receipt contains any non-passing marker such as `PRECHECK_FAIL`, `FAIL`, `UNVERIFIED`, or an explicit note that the implementation substituted a named contract with a placeholder/custom simplification.
32
32
  4. Replace with: `**Status:** done`.
33
33
  5. Locate block: `## Steps` or `## Implementation Steps`.
34
34
  6. Convert `- [ ]` into `- [x]` strictly within that section.
35
- 7. Update relevant checkboxes in `## Completion Criteria` and `## Evidence` only when the caller provides or the file already contains real proof. For v0.8 or legacy task files, update `## Task Test Plan & Verification Evidence` or `## Verification & Evidence` instead.
35
+ 7. Update relevant checkboxes in `## Completion Criteria` and `## Evidence` (legacy heading aliases still parse) only when the caller provides or the file already contains real proof.
36
36
  8. Surface a note such as: `Docs checkpoint due: task Rn-mm just completed`.
37
37
 
38
38
  ### B. Blocking a Task
@@ -59,7 +59,7 @@ When `/hapo:sync audit <feature>` is activated:
59
59
  - Missing disk file referenced in registry → remove or flag it
60
60
  - Markdown says `done` but registry not done → registry wins only if evidence already exists; otherwise downgrade markdown or flag conflict
61
61
  - Registry says `done` but markdown still pending → update markdown only if evidence exists
62
- - Either side says `done` but `## Evidence` / `## Task Test Plan & Verification Evidence` / legacy `## Verification & Evidence` has no concrete proof → downgrade to `in_progress` or flag conflict instead of preserving fake completion
62
+ - Either side says `done` but `## Evidence` (legacy heading aliases still parse) has no concrete proof → downgrade to `in_progress` or flag conflict instead of preserving fake completion
63
63
  - Either side says `done` but the receipt contains `PRECHECK_FAIL`, `FAIL`, `UNVERIFIED`, or explicit contract-substitution notes → downgrade to `in_progress` or flag conflict
64
64
  5. **Correction Alert:** Output a brief markdown alert detailing mismatches fixed and any unresolved conflicts requiring manual review.
65
65
  6. **Task Docs Alert:** If audit reveals tasks newly marked `done`, include whether task-level docs sync appears still due or already accounted for in the current run summary.
@@ -177,7 +177,7 @@ It merges the JSON data into `.hapo/test-memory.json` per `references/test-memor
177
177
  | `hapo:develop` | orchestrates | Spawns hapo:test at Step 4 |
178
178
  | `inspector` agent | hapo:test → | Scout test file locations when structure is unfamiliar |
179
179
  | `god-developer` agent | hapo:test → | FAIL verdicts route back here for fixing |
180
- | `test-runner` agent | hapo:test → | Primary executor, spawned via Task tool |
180
+ | `test-runner` agent | hapo:test → | Primary executor, spawned via the `Agent` tool |
181
181
  | chrome-devtools scripts | test-runner → | UI verification (navigate, screenshot, console, network, performance, aria-snapshot, inject-auth) |
182
182
 
183
183
  ## References
@@ -21,8 +21,10 @@ const { countConfigs } = require('./hooks/lib/counter.cjs');
21
21
  const { loadConfig } = require('./hooks/lib/config.cjs');
22
22
  const { getGitInfo } = require('./hooks/lib/git.cjs');
23
23
 
24
- // Buffer constant matching /context output (22.5% of 200k)
25
- const AUTOCOMPACT_BUFFER = 45000;
24
+ // Autocompact reserve as a fraction of the ACTUAL window size from the payload.
25
+ // Derived from /context on a 200k window (45000/200000 = 22.5%); expressed as a
26
+ // ratio so 1M-context models are not treated as if they were 200k.
27
+ const AUTOCOMPACT_BUFFER_RATIO = 0.225;
26
28
 
27
29
  /**
28
30
  * Expand home directory to ~
@@ -411,19 +413,20 @@ async function main() {
411
413
  }
412
414
  } catch {}
413
415
 
414
- // Context window - use current_usage fields with AUTOCOMPACT_BUFFER
416
+ // Context window - use current_usage fields with a proportional reserve
415
417
  const usage = data.context_window?.current_usage || {};
416
418
  const contextSize = data.context_window?.context_window_size || 0;
417
419
  let contextPercent = 0;
418
420
  let totalTokens = 0;
419
421
 
420
- if (contextSize > 0 && contextSize > AUTOCOMPACT_BUFFER) {
422
+ if (contextSize > 0) {
421
423
  totalTokens = (usage.input_tokens ?? 0) +
422
424
  (usage.cache_creation_input_tokens ?? 0) +
423
425
  (usage.cache_read_input_tokens ?? 0);
424
426
 
425
- // Add buffer to match /context calculation
426
- contextPercent = Math.min(100, Math.round(((totalTokens + AUTOCOMPACT_BUFFER) / contextSize) * 100));
427
+ // Add the reserve to match /context calculation on any window size
428
+ const buffer = Math.round(contextSize * AUTOCOMPACT_BUFFER_RATIO);
429
+ contextPercent = Math.min(100, Math.round(((totalTokens + buffer) / contextSize) * 100));
427
430
  }
428
431
 
429
432
  // Write context data to temp file for hooks to read
@@ -71,27 +71,21 @@ function currentSourceHash(cwd: string): string {
71
71
 
72
72
  function buildMissingDocsBanner(): string {
73
73
  return [
74
- "### 🔴 URGENT SYSTEM ACTION: MISSING DOCUMENTATION 🔴",
75
- "> BẮT BUỘC (MANDATORY): Hệ thống phát hiện dự án đã có Source Code nhưng thư mục `docs/` chưa tồn tại.",
76
- "> Nhiệm vụ ĐẦU TIÊN của bạn trong session này là đọc hiểu mã nguồn hiện tại và tạo ra các tài liệu tiêu chuẩn:",
77
- "> 1. `docs/system-architecture.md` (Kiến trúc hệ thống, phân tích flow)",
78
- "> 2. `docs/project-overview-pdr.md` (Tổng quan, mục tiêu, tính năng)",
79
- "> 3. Khởi tạo file hidden `docs/.sync_hash` để theo dõi cập nhật.",
80
- "> ",
81
- '> LƯU Ý BẮT BUỘC: Bạn phải chạy lệnh Git này trong Terminal để lấy Hash Code mới nhất: `git log -1 --format="%H" -- . ":(exclude)docs"`',
82
- "> Sau đó ghi chuẩn giá trị Hash đó vào file `docs/.sync_hash`.",
74
+ "### Missing docs/",
75
+ "> Source exists but `docs/` does not. Create baseline docs first:",
76
+ "> 1. `docs/system-architecture.md` — system architecture and flows",
77
+ "> 2. `docs/project-overview-pdr.md` — overview, goals, features",
78
+ '> 3. Write current hash to `docs/.sync_hash` via `git log -1 --format="%H" -- . ":(exclude)docs"`',
83
79
  ].join("\n");
84
80
  }
85
81
 
86
82
  function buildStaleDocsBanner(currentHash: string, lastSyncHash: string): string {
87
83
  return [
88
- "### 🔄 CONTINUOUS DOCS SYNC REQUIRED 🔄",
89
- `> Source Code vừa có sự thay đổi mới (Git Hash: \`${currentHash}\`) kể từ lần đồng bộ Docs cuối cùng (\`${lastSyncHash || "Chưa gán"}\`).`,
90
- "> YÊU CẦU TRƯỚC KHI LÀM THÊM TÍNH NĂNG:",
91
- `> 1. Rà soát file bị thay đổi gần đây (dùng \`git diff ${lastSyncHash} ${currentHash}\` hoặc \`git log\`).`,
92
- "> 2. Cập nhật lại `docs/system-architecture.md` hoặc các chuẩn code nếu cần thiết.",
93
- "> 3. Cập nhật Changelog (nhật ký thay đổi).",
94
- `> 4. KHI HOÀN TẤT, BẠN PHẢI GHI ĐÈ GIÁ TRỊ SAU: \`${currentHash}\` VÀO FILE \`docs/.sync_hash\` ĐỂ CHỐT TRẠNG THÁI HIỆN TẠI.`,
84
+ "### Docs sync needed",
85
+ `> Source changed (\`${currentHash}\`) since last docs sync (\`${lastSyncHash || "none"}\`).`,
86
+ `> 1. Review recent changes (\`git diff ${lastSyncHash} ${currentHash}\` or \`git log\`).`,
87
+ "> 2. Update architecture/code-standards docs and changelog as needed.",
88
+ `> 3. Write \`${currentHash}\` to \`docs/.sync_hash\` when done.`,
95
89
  ].join("\n");
96
90
  }
97
91
 
@@ -1,55 +0,0 @@
1
- ---
2
- name: hapo:code
3
- description: Implement the next approved spec task and then hand off to hapo:test and hapo:review.
4
- version: 1.0.0
5
- argument-hint: <feature-name>
6
- ---
7
-
8
- # Code
9
-
10
- Implement the next pending task from an approved spec instead of coding from memory.
11
-
12
- ## Usage
13
-
14
- ```bash
15
- /hapo:code <feature-name>
16
- ```
17
-
18
- ## Load First
19
-
20
- - `references/execution-loop.md`
21
- - `.specs/$ARGUMENTS/tasks.md`
22
- - `.specs/$ARGUMENTS/design.md`
23
- - `.specs/$ARGUMENTS/requirements.md`
24
-
25
- ## Execute
26
-
27
- 1. Read `.specs/$ARGUMENTS/tasks.md` and identify the next pending task.
28
- 2. Read the related context from `design.md` and `requirements.md`.
29
- 3. Implement only that task. Keep scope tight.
30
- 4. Follow the project standards already present in the repo.
31
- 5. Update task status in the spec artifact if the workflow supports it.
32
- 6. Hand off immediately to:
33
- - `/hapo:test`
34
- - `/hapo:review`
35
-
36
- ## Output
37
-
38
- Return:
39
- - implemented task name
40
- - touched files
41
- - blockers or follow-up items
42
- - explicit handoff to `/hapo:test` and `/hapo:review`
43
-
44
- ## Rules
45
-
46
- - Do not implement multiple major tasks in one pass.
47
- - Stop if `tasks.md` is missing.
48
- - Prefer existing patterns over new abstractions.
49
- - Keep the work aligned to the spec.
50
-
51
- ## Related
52
-
53
- - Command: `/code`
54
- - Previous skill: `/hapo:spec-tasks`
55
- - Next skills: `/hapo:test`, `/hapo:review`
@@ -1,21 +0,0 @@
1
- # Execution Loop
2
-
3
- ## Goal
4
-
5
- Implement one approved task at a time and immediately validate it.
6
-
7
- ## Loop
8
-
9
- 1. Read the next pending task in `tasks.md`.
10
- 2. Read the matching context in `design.md` and `requirements.md`.
11
- 3. Implement only that task.
12
- 4. Run `/hapo:test`.
13
- 5. Run `/hapo:review`.
14
- 6. Move to the next task only after the current pass is clear.
15
-
16
- ## Guardrails
17
-
18
- - Keep scope tight.
19
- - Prefer existing project patterns.
20
- - Do not batch multiple major tasks into one pass.
21
- - Stop and report blockers instead of guessing.
@@ -1,17 +0,0 @@
1
- ---
2
- name: code
3
- description: Implement approved work from specification tasks and then hand off to test and review.
4
- allowed-tools: Read, Glob, Grep, Edit, Write, Bash
5
- argument-hint: <feature-name>
6
- ---
7
-
8
- # /code - Implement from spec tasks
9
-
10
- Use this command after /spec-tasks.
11
-
12
- 1. Read `.specs/$ARGUMENTS/tasks.md` and identify the next pending task.
13
- 2. Implement only that task following project standards.
14
- 3. Run `/test`.
15
- 4. Run `/review`.
16
-
17
- Preferred flow: /spec-init -> /spec-requirements -> /spec-design -> /spec-tasks -> /code -> /test -> /review