@ngockhoale/ukit 2.5.1 → 2.6.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 (53) hide show
  1. package/CHANGELOG.md +80 -0
  2. package/manifests/platform.full.yaml +16 -0
  3. package/package.json +1 -1
  4. package/src/cli/commands/install.js +49 -2
  5. package/src/cli/commands/update.js +5 -0
  6. package/src/core/output/index.js +77 -0
  7. package/src/core/update.js +36 -5
  8. package/templates/.claude/agents/code-reviewer.md +12 -1
  9. package/templates/.claude/agents/feature-implementer.md +4 -2
  10. package/templates/.claude/agents/handoff-planner.md +36 -1
  11. package/templates/.claude/commands/ukit/handoff-clear.md +4 -0
  12. package/templates/.claude/commands/ukit/handoff-create.md +23 -7
  13. package/templates/.claude/commands/ukit/handoff-fullstack.md +181 -17
  14. package/templates/.claude/commands/ukit/handoff-implement.md +9 -2
  15. package/templates/.claude/commands/ukit/handoff-review.md +4 -1
  16. package/templates/.claude/commands/ukit/handoff-status.md +6 -2
  17. package/templates/.claude/hooks/auto-allow-bash.sh +17 -5
  18. package/templates/.claude/hooks/block-dangerous.sh +18 -5
  19. package/templates/.claude/hooks/completion-gate.sh +17 -5
  20. package/templates/.claude/hooks/compress-output.sh +15 -6
  21. package/templates/.claude/hooks/context-hardcap-gate.sh +77 -46
  22. package/templates/.claude/hooks/context-window-guard.sh +41 -27
  23. package/templates/.claude/hooks/handoff-model-guard.sh +62 -14
  24. package/templates/.claude/hooks/handoff-resume.sh +20 -7
  25. package/templates/.claude/hooks/post-edit-verify.sh +17 -5
  26. package/templates/.claude/hooks/pre-edit-backup.sh +17 -5
  27. package/templates/.claude/hooks/project-important.sh +18 -1
  28. package/templates/.claude/hooks/protect-files.sh +18 -5
  29. package/templates/.claude/hooks/record-execution.sh +17 -5
  30. package/templates/.claude/hooks/sensitive-data-guard.sh +48 -9
  31. package/templates/.claude/hooks/skill-router.sh +124 -86
  32. package/templates/.claude/hooks/stale-spec-guard.sh +22 -6
  33. package/templates/.claude/hooks/task-watchdog.sh +22 -7
  34. package/templates/.claude/hooks/verification-guard.sh +17 -5
  35. package/templates/.claude/hooks/vision-router.sh +17 -5
  36. package/templates/.claude/settings.json +15 -10
  37. package/templates/.claude/ukit/index/provision-worktree.mjs +30 -2
  38. package/templates/.claude/ukit/runtime/execution-ledger.mjs +99 -1
  39. package/templates/.claude/ukit/runtime/hook-input.sh +25 -0
  40. package/templates/.claude/ukit/runtime/hook-telemetry.mjs +86 -2
  41. package/templates/.claude/ukit/runtime/output-compression.mjs +87 -0
  42. package/templates/.claude/ukit/runtime/stop-coordinator.mjs +201 -11
  43. package/templates/.omp/RULES.md +9 -1
  44. package/templates/.omp/agents/code-reviewer.md +12 -1
  45. package/templates/.omp/agents/feature-implementer.md +4 -2
  46. package/templates/.omp/agents/handoff-planner.md +36 -1
  47. package/templates/.omp/hooks/pre/ukit-bridge.js +110 -3
  48. package/templates/AGENTS.md +14 -0
  49. package/templates/CLAUDE.md +14 -0
  50. package/templates/docs/AI_HANDOFF/RULES.md +37 -4
  51. package/templates/docs/AI_HANDOFF/SPEC.md +98 -0
  52. package/templates/docs/AI_HANDOFF/tasks/_TEMPLATE.md +4 -1
  53. package/templates/ukit/storage/config.json +48 -9
@@ -19,10 +19,12 @@
19
19
 
20
20
  Mọi giao tiếp giữa các AI trong handoff CHỈ qua file dưới `docs/AI_HANDOFF/`:
21
21
 
22
+ - `SPEC.md` — spec chi tiết (15 section, viết ở handoff-create trước PLAN tasks). Executor implement theo SPEC + task file, không theo prompt thô.
22
23
  - `PLAN.md` — brainstorm + Test Plan tổng (Phase 1).
23
24
  - `INDEX.md` — bảng task + status (mọi phase đọc/ghi).
24
25
  - `tasks/TASK-xxx.md` — nơi sống của từng task: Goal + Test Cases + Verification + Executor Report + Reviewer Verdict + **Discussion thread**.
25
26
  - `ACTIVE.md` — snapshot cycle hiện tại.
27
+ - `RUN.md` — run cursor của `/ukit:handoff-fullstack`; `Phase:` ≠ `done`/`blocked` khiến Stop gate từ chối stop → run tự chạy tiếp.
26
28
  - `archive/` — cycle cũ.
27
29
 
28
30
  **Cấm**: AI gửi câu hỏi/comment qua chat tool khác, qua commit message, hay qua file ngoài thư mục này. Lý do: cross-tool/cross-subagent chỉ đồng bộ được qua file. AI nào không đọc folder này = không tham gia handoff.
@@ -115,8 +117,38 @@ brainstorm ──[plan approved]──▶ ready ──[executor pick]──▶ i
115
117
  pending_review ──[reviewer]──▶ approved | approved_minor ──▶ done
116
118
  ├▶ changes_requested ──[fix]──▶ in_progress
117
119
  └▶ critical_block ──[fix]──▶ in_progress
120
+ <any stuck state> ──[record không resume được]──▶ cancelled_superseded → TASK-xxx-R<n> mới
118
121
  ```
119
122
 
123
+ ### Recovery — `cancelled_superseded` + `-R<n>`
124
+
125
+ Task ở `pending`, stale `in_progress`, hay `blocked` mà record không resume sạch được
126
+ (worktree mất, report mâu thuẫn, state invalid): **không bỏ lơi**. Đánh
127
+ `cancelled_superseded`, tạo `TASK-xxx-R1` (`-R2`, …) giữ nguyên spec references +
128
+ acceptance + verification, link `## Discussion` hai chiều, chạy task mới ngay trong
129
+ cycle hiện tại.
130
+
131
+ ### Handoff-fullstack loop (autonomous)
132
+
133
+ `/ukit:handoff-fullstack` = create → implement → review → recovery → docs → archive,
134
+ chạy **đến khi không còn gì để làm**:
135
+
136
+ - Chỉ 2 output kết thúc hợp lệ: `HANDOFF FULLSTACK COMPLETE` hoặc
137
+ `HANDOFF FULLSTACK BLOCKED`. Recap/checkpoint không phải điểm dừng — dùng form
138
+ `CHECKPOINT — WORK CONTINUING` rồi làm tiếp ngay.
139
+ - Phase 0 sweep gom mọi unfinished work: INDEX, task files, cycle cũ (HISTORY/archive),
140
+ `docs/TASKS.md` `Ready for AI`, uncommitted WIP.
141
+ - Quiet-period: chỉ đóng run khi backlog rỗng + `handoff.fullstack.quietScansRequired`
142
+ (mặc định 2) scan liên tiếp không thấy việc mới.
143
+ - Stop gate (Claude Code): `RUN.md` `Phase:` ≠ `done`/`blocked` → Stop hook từ chối
144
+ stop kèm `Next:` step. Breaker `stopGateMaxStalledBlocks` (mặc định 12) thả ra nếu
145
+ cursor không nhích — lối thoát, không phải đường thường.
146
+ - `handoff-clear` PHẢI đặt `Phase: done` (hoặc xóa RUN.md) — cursor sống sẽ giữ gate
147
+ chặn stop của session sau.
148
+ - Phase F: docs sync (WORKLOG luôn; PROJECT/CODE_MAP/CHANGELOG khi đổi surface) →
149
+ archive cycle vào `archive/cycle-NN/` (khi `autoArchive=true`) → `Phase: done` →
150
+ Final Report với marker.
151
+
120
152
  ### 4 Phases
121
153
 
122
154
  **Phase 1 — Idea + Plan** (smart/reasoning model)
@@ -179,12 +211,13 @@ Missing any → `needs_breakdown`, `blocked`, or `needs_human`.
179
211
 
180
212
  ## Clear Handoff
181
213
 
182
- 1. Archive current cycle → `archive/cycle-NNN.md`.
183
- 2. If archive > 3 files → delete oldest, append 1-line summary to `HISTORY.md`.
214
+ 1. Archive current cycle → `archive/cycle-NNN.md` hoặc `archive/cycle-NN/` (gồm PLAN + SPEC + task files).
215
+ 2. If archive > 3 entries → delete oldest, append 1-line summary to `HISTORY.md`.
184
216
  3. Reset `ACTIVE.md` to empty template.
185
217
  4. Clear `INDEX.md`.
186
- 5. Delete all files in `tasks/`.
187
- 6. Clear `PLAN.md`.
218
+ 5. Delete all files in `tasks/` (keep `_TEMPLATE.md`).
219
+ 6. Clear `PLAN.md`; restore `SPEC.md` về template.
220
+ 7. **`RUN.md` → `Phase: done` hoặc xóa** — bắt buộc, không thì Stop gate chặn session sau.
188
221
 
189
222
  ## Docs Sync
190
223
 
@@ -0,0 +1,98 @@
1
+ # SPEC — <feature / cycle goal>
2
+
3
+ <!--
4
+ Written by the planner at handoff-create (Step 2, before PLAN.md tasks).
5
+ Rule: cụ thể đến mức executor implement KHÔNG cần đoán — exact paths, module names,
6
+ API methods, statuses, schemas, validation rules, permissions, empty/error states,
7
+ migration behavior, test expectations. Section nào không áp dụng thì ghi "N/A — <lý do>",
8
+ không xóa heading. Open question nào cũng phải chốt 1 default và ghi vào §14.
9
+ -->
10
+
11
+ ## 1. Problem and context
12
+
13
+ <Vấn đề, hiện trạng code/docs liên quan, tại sao cần làm ngay.>
14
+
15
+ ## 2. Goals
16
+
17
+ - <Kết quả đo được — thành công trông như thế nào.>
18
+
19
+ ## 3. Non-goals
20
+
21
+ - <Cái CỤ THỂ không làm trong cycle này — chặn scope creep.>
22
+
23
+ ## 4. User journeys
24
+
25
+ - <Ai dùng, flow từng bước, kể cả unhappy path.>
26
+
27
+ ## 5. Functional requirements
28
+
29
+ - FR-001: <requirement>
30
+ - Given: <pre-state>
31
+ - When: <action>
32
+ - Then: <observable result>
33
+ - Error cases: <invalid input → exact behavior/message>
34
+
35
+ ## 6. Fullstack scope
36
+
37
+ ### Backend
38
+ <modules, functions, services — exact paths>
39
+ ### Database / schema / migrations
40
+ <schema changes, migration file names, backfill behavior>
41
+ ### API contract
42
+ <methods, routes, request/response shapes, status codes>
43
+ ### Frontend UI and state
44
+ <components, states, empty/error/loading>
45
+ ### Integration
46
+ <điểm nối giữa các layer>
47
+ ### Security and permissions
48
+ <ai được làm gì, validation/authz checks>
49
+ ### Performance
50
+ <budgets, query concerns, payload sizes>
51
+ ### Observability / logging
52
+ <log points, metrics, error surfacing>
53
+ ### Deployment and rollback
54
+ <feature flags, rollback path, ordering>
55
+
56
+ ## 7. Data model
57
+
58
+ <entities, fields, types, invariants, indexes>
59
+
60
+ ## 8. API contract
61
+
62
+ <endpoint table: method, path, request schema, response schema, error codes>
63
+
64
+ ## 9. UI behavior
65
+
66
+ <state machine per screen: loading / empty / error / success; copy nếu user-facing>
67
+
68
+ ## 10. Edge cases
69
+
70
+ - <concurrency, retries, offline, partial failure, large input, unicode, etc.>
71
+
72
+ ## 11. Test matrix
73
+
74
+ | Area | Cases | Test file |
75
+ |------|-------|-----------|
76
+ | <unit> | <happy + edge list> | <tests/...> |
77
+
78
+ ## 12. Acceptance criteria
79
+
80
+ - [ ] <verifiable criterion — ideally a command or observable state>
81
+
82
+ ## 13. Migration / upgrade steps
83
+
84
+ <ordered steps for existing installs; nếu không có ghi N/A>
85
+
86
+ ## 14. Open questions and chosen defaults
87
+
88
+ | Question | Chosen default | Rationale |
89
+ |----------|----------------|-----------|
90
+ | <q> | <default đã chọn> | <why> |
91
+
92
+ ## 15. Review checklist
93
+
94
+ - [ ] Mọi FR testable (có Given/When/Then hoặc command).
95
+ - [ ] Mọi layer fullstack được cover hoặc ghi N/A có lý do.
96
+ - [ ] Không còn instruction mơ hồ ("improve", "better UX" không định nghĩa).
97
+ - [ ] Dependencies giữa các phần đã ghi rõ.
98
+ - [ ] Legacy/unfinished work từ Phase 0 sweep đã được tính vào.
@@ -6,11 +6,14 @@ File này BẮT BUỘC giữ structure: Goal + Test Cases + Test Files + Verific
6
6
  Mọi AI (planner / executor / reviewer) đọc và ghi vào file NÀY. Không trao đổi ngoài file.
7
7
  -->
8
8
 
9
- - Status: `ready` <!-- ready | in_progress | pending_review | changes_requested | critical_block | approved | approved_minor | blocked | done -->
9
+ - Status: `ready` <!-- ready | in_progress | pending_review | changes_requested | critical_block | approved | approved_minor | blocked | done | cancelled_superseded -->
10
10
  - Size: `M` <!-- S | M | L — runtime budgets key off this field; defaults to M when missing -->
11
11
  - Owner: `-` <!-- tool đang giữ task -->
12
12
  - Reviewer: `-` <!-- model name reviewer dùng, set ở Phase 4 -->
13
13
  - Parent plan: `docs/AI_HANDOFF/PLAN.md` §<section>
14
+ - Spec references: `docs/AI_HANDOFF/SPEC.md` §<n>, §<n> <!-- FR/section IDs this task implements -->
15
+ - Supersedes: `(none)` <!-- hoặc TASK-xxx — recovery task (-R<n>) thay thế một record kẹt -->
16
+ - Superseded by: `(none)` <!-- set khi status = cancelled_superseded -->
14
17
 
15
18
  ## Goal
16
19
 
@@ -144,9 +144,18 @@
144
144
  }
145
145
  },
146
146
  "modelTiers": {
147
- "lite": { "claudeModel": "claude-haiku-4-5", "genericModel": "unic-lite" },
148
- "code": { "claudeModel": "claude-sonnet-5", "genericModel": "unic-code" },
149
- "smart": { "claudeModel": "claude-opus-5", "genericModel": "unic-smart" },
147
+ "lite": {
148
+ "claudeModel": "claude-haiku-4-5",
149
+ "genericModel": "unic-lite"
150
+ },
151
+ "code": {
152
+ "claudeModel": "claude-sonnet-5",
153
+ "genericModel": "unic-code"
154
+ },
155
+ "smart": {
156
+ "claudeModel": "claude-opus-5",
157
+ "genericModel": "unic-smart"
158
+ },
150
159
  "vision": {
151
160
  "claudeModel": "unic-vision",
152
161
  "genericModel": "unic-vision",
@@ -158,7 +167,11 @@
158
167
  "escalation": {
159
168
  "enabled": true,
160
169
  "debugLoopThreshold": 2,
161
- "tierOrder": ["lite", "code", "smart"],
170
+ "tierOrder": [
171
+ "lite",
172
+ "code",
173
+ "smart"
174
+ ],
162
175
  "cap": "smart"
163
176
  }
164
177
  },
@@ -242,12 +255,29 @@
242
255
  "done"
243
256
  ],
244
257
  "taskBudgets": {
245
- "S": { "softMin": 8, "hardMin": 15 },
246
- "M": { "softMin": 15, "hardMin": 30 },
247
- "L": { "softMin": 25, "hardMin": 45 },
258
+ "S": {
259
+ "softMin": 8,
260
+ "hardMin": 15
261
+ },
262
+ "M": {
263
+ "softMin": 15,
264
+ "hardMin": 30
265
+ },
266
+ "L": {
267
+ "softMin": 25,
268
+ "hardMin": 45
269
+ },
248
270
  "hardPolicy": "split"
249
271
  },
250
- "milestoneIntervalMin": 5
272
+ "milestoneIntervalMin": 5,
273
+ "fullstack": {
274
+ "stopGateEnabled": true,
275
+ "stopGateMaxStalledBlocks": 12,
276
+ "quietScansRequired": 2,
277
+ "idleWatchdogMin": 5,
278
+ "autoArchive": true,
279
+ "specRequired": true
280
+ }
251
281
  },
252
282
  "subagents": {
253
283
  "enabled": true,
@@ -299,6 +329,7 @@
299
329
  "skill-routing-needed",
300
330
  "step-budget-enough",
301
331
  "compact-now-or-later",
332
+ "codex-context-budget",
302
333
  "summarize-docs-or-keep-detail"
303
334
  ],
304
335
  "stepBudgets": {
@@ -545,7 +576,15 @@
545
576
  "rerunVerificationCommands": "Reviewer phải tự chạy lại Verification Commands, không tin output executor.",
546
577
  "appendVerdictToTaskFile": "Reviewer append `## Reviewer Verdict` vào task file để khép vòng handoff."
547
578
  },
548
- "statusFlow": "Danh sách status hợp lệ trong INDEX.md. Đổi tên trong này = đổi state machine handoff."
579
+ "statusFlow": "Danh sách status hợp lệ trong INDEX.md. Đổi tên trong này = đổi state machine handoff.",
580
+ "fullstack": {
581
+ "stopGateEnabled": "Bật Stop gate handoff: RUN.md Phase != done/blocked → Stop hook từ chối stop kèm Next step, giữ handoff-fullstack chạy tiếp thay vì đứng sau recap. Tắt chỉ khi debug.",
582
+ "stopGateMaxStalledBlocks": "Liveness breaker: cursor không nhích qua N lần block liên tiếp thì gate thả stop (tránh vòng lặp vô tận). Mặc định 12.",
583
+ "quietScansRequired": "Số scan liên tiếp không thấy việc mới trước khi handoff-fullstack được phép đóng run. Mặc định 2.",
584
+ "idleWatchdogMin": "Khoảng phút cho scheduled wakeup nếu harness hỗ trợ (cron/loop). Mặc định 5.",
585
+ "autoArchive": "true = Phase F tự archive cycle vào docs/AI_HANDOFF/archive/cycle-NN/ khi hoàn tất.",
586
+ "specRequired": "true = handoff-create bắt buộc viết docs/AI_HANDOFF/SPEC.md chi tiết trước khi tạo task."
587
+ }
549
588
  }
550
589
  }
551
590
  }