dw-kit 1.8.0-rc.2 → 1.9.0-rc.1

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 (57) hide show
  1. package/.claude/rules/dw.md +2 -0
  2. package/.claude/skills/dw-goal/SKILL.md +206 -0
  3. package/.claude/skills/dw-goal-sync/SKILL.md +131 -0
  4. package/.claude/templates/agent-report.md +35 -35
  5. package/.dw/config/agents.yml +8 -0
  6. package/.dw/core/AGENTS.md +53 -53
  7. package/.dw/core/schemas/events/created.schema.json +33 -0
  8. package/.dw/core/schemas/events/debate_agent_failed.schema.json +42 -0
  9. package/.dw/core/schemas/events/debate_agent_replied.schema.json +44 -0
  10. package/.dw/core/schemas/events/debate_agent_started.schema.json +37 -0
  11. package/.dw/core/schemas/events/debate_completed.schema.json +36 -0
  12. package/.dw/core/schemas/events/debate_started.schema.json +47 -0
  13. package/.dw/core/schemas/events/goal_archived.schema.json +32 -0
  14. package/.dw/core/schemas/events/goal_created.schema.json +32 -0
  15. package/.dw/core/schemas/events/goal_field_updated.schema.json +35 -0
  16. package/.dw/core/schemas/events/goal_pivoted.schema.json +36 -0
  17. package/.dw/core/schemas/events/goal_status_changed.schema.json +40 -0
  18. package/.dw/core/schemas/events/goal_task_linked.schema.json +33 -0
  19. package/.dw/core/schemas/events/goal_task_unlinked.schema.json +33 -0
  20. package/.dw/core/schemas/events/index.json +185 -0
  21. package/.dw/core/schemas/events/orchestrator_cancelled.schema.json +29 -0
  22. package/.dw/core/schemas/events/orchestrator_completed.schema.json +38 -0
  23. package/.dw/core/schemas/events/orchestrator_confirm.schema.json +33 -0
  24. package/.dw/core/schemas/events/orchestrator_confirmed.schema.json +33 -0
  25. package/.dw/core/schemas/events/orchestrator_error.schema.json +29 -0
  26. package/.dw/core/schemas/events/orchestrator_pending_dropped.schema.json +29 -0
  27. package/.dw/core/schemas/events/orchestrator_pending_expired.schema.json +32 -0
  28. package/.dw/core/schemas/events/orchestrator_recommend_rejected.schema.json +37 -0
  29. package/.dw/core/schemas/events/orchestrator_recommended.schema.json +33 -0
  30. package/.dw/core/schemas/events/orchestrator_spawn_failed.schema.json +29 -0
  31. package/.dw/core/schemas/events/orchestrator_started.schema.json +33 -0
  32. package/.dw/core/schemas/events/orchestrator_timeout.schema.json +29 -0
  33. package/.dw/core/schemas/events/reconciled.schema.json +29 -0
  34. package/.dw/core/schemas/events/reconciled_stale.schema.json +29 -0
  35. package/.dw/core/schemas/events/session.created.schema.json +39 -0
  36. package/.dw/core/schemas/events/session.reconciled.schema.json +33 -0
  37. package/.dw/core/schemas/events/session.status_changed.schema.json +42 -0
  38. package/.dw/core/schemas/events/spawn_failed.schema.json +29 -0
  39. package/.dw/core/schemas/events/started.schema.json +59 -0
  40. package/.dw/core/schemas/events/stopped.schema.json +33 -0
  41. package/.dw/security/advisory-snapshot.json +157 -0
  42. package/CLAUDE.md +1 -1
  43. package/LICENSE +201 -21
  44. package/NOTICE +26 -0
  45. package/SECURITY.md +87 -0
  46. package/TRADEMARK.md +65 -0
  47. package/bin/dw.mjs +1 -1
  48. package/package.json +10 -4
  49. package/src/commands/voice.mjs +590 -4
  50. package/src/lib/board-data.mjs +220 -0
  51. package/src/lib/debate.mjs +325 -0
  52. package/src/lib/event-schema.mjs +342 -0
  53. package/src/lib/orchestrator.mjs +31 -9
  54. package/src/lib/session-store.mjs +36 -4
  55. package/src/lib/voice-action.mjs +165 -0
  56. package/src/lib/voice-parser.mjs +13 -0
  57. package/.dw/config/connectors.local.yml +0 -38
@@ -101,6 +101,8 @@ Core workflow: `/dw:flow` · `/dw:task-init` · `/dw:research` · `/dw:plan` ·
101
101
 
102
102
  `/dw:plan` includes **Quick Debate** (red/blue self-critique): default ON for `thorough`, auto-trigger on high-stakes signals for `standard`, off for `quick`. Override via `--debate` / `--no-debate` / `--debate-deep`.
103
103
 
104
+ Goals (ADR-0010/0016): `/dw:goal` (outcome-driven pursuit loop — drive Goal tới KR, leo thang tư duy khi kẹt; `--auto` long-horizon) · `/dw:goal-sync` (reactive sync khi human pivot)
105
+
104
106
  Decisions: `/dw:decision [title]` — create ADR
105
107
 
106
108
  Dev: `/dw:debug` · `/dw:review` · `/dw:thinking` · `/dw:prompt` · `/dw:docs-update`
@@ -0,0 +1,206 @@
1
+ ---
2
+ name: dw:goal
3
+ description: "Drive một Goal tới các Key Results bằng vòng lặp pursuit hướng kết quả. Đo gap → hành động → đo lại; khi một cách thất bại thì NÂNG CẤP tư duy (leo bậc) thay vì lặp lại. Dừng theo termination contract. Khác dw:goal-sync (chỉ đồng bộ) và dw:flow (drive 1 task)."
4
+ argument-hint: "[goal-id] [--auto] [--max-iter N]"
5
+ ---
6
+
7
+ # dw:goal — Vòng Lặp Đeo Bám Mục Tiêu (Outcome-Driven Pursuit)
8
+
9
+ Goal: **$ARGUMENTS** (để trống = goal liên quan task đang làm via `parent_goal_id`)
10
+
11
+ > Triết lý (ADR-0016): **quan tâm tới KẾT QUẢ, không phải effort.** Plan là thứ vứt đi
12
+ > được — nếu plan fail thì Goal vẫn sống, ta nghĩ plan mới. Cần thì **xoáy nhiều vòng**,
13
+ > và mỗi lần fail phải **nâng cấp tư duy** (leo bậc thang) chứ không lặp lại cách cũ.
14
+ > Success = KR đo được chạm target, KHÔNG phải "đã làm xong task".
15
+
16
+ ## Vị trí trong hệ skill (không trùng lặp)
17
+
18
+ ```
19
+ dw:goal → drive 1 GOAL tới các KR, qua NHIỀU task & NHIỀU lần thử ← skill này
20
+ ├─ dw:goal-sync → primitive cho pha OBSERVE (đọc goal + tail events)
21
+ ├─ dw:flow → drive 1 TASK end-to-end tới Done (giữ human gate riêng)
22
+ ├─ dw:plan / dw:thinking → công cụ cho pha ORIENT + ladder L1/L2
23
+ └─ dw goal * CLI → tầng dữ liệu (đọc KR, update progress, link task, events)
24
+ ```
25
+
26
+ `dw:goal` **điều phối** các mảnh trên thành một loop hướng kết quả. Nó KHÔNG tự
27
+ implement task (giao cho `dw:flow`), KHÔNG tự plan từ đầu (gọi `dw:plan`).
28
+
29
+ ## Khi nào dùng
30
+
31
+ - Có một Goal (`G-{slug}`) với Key Results đã định nghĩa, muốn AI **chủ động đẩy** tới đích.
32
+ - Goal cần nhiều task / nhiều lần thử mới đạt — không phải 1 task đơn lẻ (dùng `dw:flow`).
33
+ - Bị kẹt ở một KR và muốn AI **thử cách tiếp cận khác** một cách có hệ thống.
34
+
35
+ ## Bước 0 — Khởi động & parse args
36
+
37
+ Parse `$ARGUMENTS`:
38
+ - `goal-id` (`G-{slug}`) — validate regex. Nếu trống → derive từ task đang làm
39
+ (`parent_goal_id` trong `.dw/tasks/{task}/task.md`, giống `dw:goal-sync` Bước 1).
40
+ Không có → dừng, gợi ý `dw goal portfolio` để chọn.
41
+ - Tự chủ (xem "Thang tự chủ"): _(không cờ)_ = **A0 supervised** (mặc định, dừng cuối mỗi vòng);
42
+ `--auto` = **A1 checkpoint** (dừng ở ranh giới mỗi KR đạt); `--auto=full` = **A2 full** (chỉ hard-stop).
43
+ - `--max-iter N` — trần số vòng cho A1/A2 (mặc định **5**). A0 không cần.
44
+
45
+ Đọc config `.dw/config/dw.config.yml` (nếu cần): `quality.test_command` để đo KR
46
+ auto-measurable; `team.roles` (có `techlead` → strategic pivot cần TL).
47
+
48
+ Đọc journal nếu có: `.dw/goals/{goal-id}/goal-loop.md` — phục hồi state vòng trước
49
+ (iteration #, ladder rung mỗi KR, bài học Reflexion). Không có = bắt đầu từ iteration 1, L0.
50
+
51
+ ## Vòng lặp Pursuit (mỗi vòng = một "vòng xoáy")
52
+
53
+ Lặp các pha **OBSERVE → ORIENT → DECIDE → ACT → VERIFY → REFLECT**, rồi xét EXIT.
54
+
55
+ ### 1. OBSERVE — đo trạng thái thật
56
+
57
+ Tái dùng logic `dw:goal-sync`:
58
+
59
+ ```bash
60
+ dw goal show $GOAL # ANSI snapshot: status, version, KR table
61
+ dw goal summary $GOAL # strategic context ngắn
62
+ grep "\"goal_id\":\"$GOAL\"" .dw/events-global.jsonl | tail -30 # drift gần đây
63
+ ```
64
+
65
+ Đọc Section 3 (KR table) → với mỗi KR lấy `current` vs `target`. Tính **gap** = target − current.
66
+ Đọc Section 3 (Linked Tasks) → trạng thái các task đang góp cho goal.
67
+
68
+ Phân loại mỗi KR (3 loại — quyết định nước đi đúng):
69
+ - **Auto-measurable** (đo được bằng lệnh): test count, coverage %, smoke pass/fail, file tồn tại, tag git… → đo trực tiếp.
70
+ - **Human-attested** (định tính: "adoption ≥5 teams", "UX mượt"…) → KHÔNG bịa số. Khi cần cập nhật loại này → **STOP hỏi human attest**.
71
+ - **Wait-gated** (chặn bởi *thời gian*, không bởi tư duy: "≥30 ngày telemetry baseline", "chờ CI/cron chạy", "chờ deadline"…) → KR chỉ tiến khi thời gian trôi. **TUYỆT ĐỐI không leo ladder** (leo bậc = thrash, không cách nghĩ nào làm thời gian trôi nhanh hơn). Nước đi đúng: refresh `current` theo lượng đã trôi nếu cần, rồi **⏳ pause với ETA resume**.
72
+
73
+ ### 2. ORIENT — phân tích gap (nạp THINKING.md)
74
+
75
+ - KR nào gap lớn nhất / đang block các KR khác? → chọn **KR mục tiêu** cho vòng này.
76
+ - **Hỏi trước khi leo ladder: KR này chặn bởi *tư duy* hay bởi *thời gian*?** Nếu là wait-gated → KHÔNG leo, chuyển sang ⏳ pause. Chỉ leo ladder khi cái chặn là approach/tư duy.
77
+ - Áp dụng `.claude/skills/dw-thinking/THINKING.md`: giả định nào đang chặn? dependency? failure mode? `current` có bị **stale** (set lâu rồi, chưa refresh) không?
78
+ - Đọc bài học Reflexion từ journal: cách nào đã thử & thất bại cho KR này?
79
+ - Kết luận trạng thái goal: `on-track | stuck | infeasible | achieved`. (wait-gated mà đúng ETA = **on-track**, KHÔNG phải stuck.)
80
+
81
+ ### 3. DECIDE — chọn nước đi ở ĐÚNG bậc thang tư duy
82
+
83
+ Nước đi điển hình: spawn/resume một task nhắm thẳng KR mục tiêu, hoặc một hành động nhỏ trực tiếp, hoặc reframe. **Chọn strategy theo bậc ladder hiện tại của KR đó** (xem Thang Nâng Cấp Tư Duy bên dưới).
84
+
85
+ ### 4. ACT — thực thi
86
+
87
+ - **Task-level work** → giao cho `/dw:flow <task>` (flow giữ human gate của nó: GATE C plan, GATE D changes). Tạo task mới bằng `dw task new` + `dw goal link $GOAL <task>` nếu chưa có.
88
+ - **Cập nhật KR**: sau khi có kết quả đo được, cập nhật `current` trong Section 3 (qua edit goal.md hoặc lệnh `dw goal` tương ứng). Emit event tiến độ.
89
+ - **Agent OS**: nếu môi trường multi-agent, claim trước khi ghi (`dw agent claim`).
90
+
91
+ ### 5. VERIFY — ĐO LẠI KR mục tiêu (bắt buộc)
92
+
93
+ Chạy lại phép đo của KR (test command, đếm, kiểm tra artifact…). Ghi **delta** vào journal + Section 4 timeline.
94
+
95
+ > Đây là điểm cốt lõi: **thành công tính bằng delta đo được, không phải bằng việc đã làm.**
96
+ > Nếu KR human-attested → hỏi human, không tự đánh ✅.
97
+
98
+ ### 6. REFLECT — học & quyết định bậc kế (Reflexion)
99
+
100
+ - KR **tiến về target** → chốt; chuyển KR kế; có thể **hạ về L0** cho KR mới.
101
+ - KR **không nhúc nhích / đi sai** → ghi *vì sao* thành một dòng bài học trong journal, rồi **leo 1 bậc ladder** cho vòng sau.
102
+
103
+ ### 7. EXIT — xét termination contract (xem dưới). Nếu chưa exit → vòng kế.
104
+
105
+ ---
106
+
107
+ ## Thang Nâng Cấp Tư Duy ("nâng cấp tư duy") — cơ chế lõi
108
+
109
+ Vòng fail thì **PHẢI leo bậc**; **KHÔNG** chạy lại cùng một bậc. Vòng thành công có thể hạ về L0 cho KR kế.
110
+
111
+ | Bậc | Chiến lược | Tái dùng |
112
+ |-----|-----------|----------|
113
+ | **L0** | Thực thi trực tiếp — làm việc task hiển nhiên | `dw:execute` / inline |
114
+ | **L1** | Plan có cấu trúc — áp THINKING.md, tạo plan thật | `dw:plan`, `dw:thinking` |
115
+ | **L2** | Debate đối kháng — red/blue mổ approach, tìm giả định ẩn đang chặn | `dw:plan` Quick Debate (Mode A 2-pass mặc định; Mode B subagents song song nếu có) |
116
+ | **L3** | Reframe — nghi ngờ *cách tiếp cận*: có đường orthogonal? chia nhỏ khác? chạy spike/experiment de-risk? | annex `experiment-{id}.md` |
117
+ | **L4** | Nghi ngờ *chính Goal* — KR có đo đúng thứ cần? target khả thi? → đề xuất `Pivoted` / sửa KR | `dw goal bump --reason` |
118
+ | **L5** | Escalate human — DỪNG, trình diagnosis + options, trả quyền | AskUser / GATE |
119
+
120
+ Thang này biến "nâng cấp tư duy" mơ hồ thành cơ chế cụ thể, kiểm toán được — chống thrash (lặp cách hỏng) và chống spin vô tiến triển.
121
+
122
+ ---
123
+
124
+ ## Termination Contract (điều kiện dừng tường minh)
125
+
126
+ - ✅ **Achieved** — mọi KR in-scope chạm target → `dw goal` status → `Achieved`, viết summary, DỪNG.
127
+ - 🔴 **Infeasible** — đã tới L4 mà không còn đường → đề xuất `Abandoned`/`Pivoted`, DỪNG chờ human.
128
+ - ⏸ **Budget-exhausted** — chạm `--max-iter` HOẶC hết ngân sách time/turn → **wrap-up nhẹ nhàng** (kiểu Codex): ghi tiến độ + việc còn lại vào Section 5 / journal, lưu state, DỪNG. **Resumable** session sau.
129
+ - ⏳ **Wait-gated pause** — KR mục tiêu là wait-gated (chặn bởi thời gian), không còn KR actionable nào khác → DỪNG với **ETA resume cụ thể**. KHÔNG leo ladder, KHÔNG tạo task lấp chỗ.
130
+ - 🚧 **No-progress guard** — N vòng liên tiếp (mặc định **2**) KR-delta = 0 *và* không có diagnosis mới → ép leo bậc ngay; nếu đã ở L5 → DỪNG + escalate. (Chống loop vô hạn, mượn từ Codex loop-suppression.)
131
+ - 🛑 **Irreversible-action boundary** — trước MỌI hành động khó đảo (push / release / merge / gửi ra ngoài) → **LUÔN DỪNG chờ human** (ADR-0009). KHÔNG bao giờ tự push.
132
+ - 👤 **Human interrupt** — pause goal, lưu state.
133
+
134
+ ## Thang tự chủ (autonomy tăng dần — "tự động hoá dần dần")
135
+
136
+ Tự chủ là một **núm xoay 3 nấc**, không phải bật/tắt. Bắt đầu thấp, **nâng dần khi đã tin** loop chạy đúng trên goal/loại KR cụ thể. Mỗi nấc chỉ NỚI điểm dừng định kỳ — **các hard-stop của Termination Contract luôn áp dụng ở mọi nấc**.
137
+
138
+ | Nấc | Cờ | Dừng định kỳ ở đâu | Khi nào dùng |
139
+ |-----|----|--------------------|--------------|
140
+ | **A0 · supervised** (MẶC ĐỊNH) | _(không cờ)_ | Cuối **mỗi vòng** | Goal mới / KR rủi ro / chưa tin loop |
141
+ | **A1 · checkpoint** | `--auto` | Cuối mỗi **KR đạt target** (ranh giới KR), không dừng giữa các vòng cùng một KR | Đã tin loop với KR auto-measurable; muốn nó tự xoáy 1 KR tới đích rồi báo |
142
+ | **A2 · full** | `--auto=full` | Không dừng định kỳ — chỉ hard-stop | Goal rõ ràng, KR auto-measurable, đã chạy A1 trơn tru ít nhất 1 lần |
143
+
144
+ `--max-iter N` (mặc định 5) áp cho A1/A2. **`--auto` mặc định = A1 (checkpoint)** — nấc giữa an toàn; phải gõ rõ `--auto=full` mới lên A2. Đây chính là "tự động hoá dần dần": default-auto là nấc thận trọng, không nhảy thẳng full.
145
+
146
+ **Bất biến ở mọi nấc:**
147
+ - Hard-stop của Termination Contract (irreversible boundary, no-progress guard, ladder L5, wait-gated) **không bao giờ bị nới**.
148
+ - Việc task vẫn đi qua human gate của `dw:flow` (GATE C/D). Loop chỉ tự chủ ở tầng *chọn KR / leo bậc / đo đạc*.
149
+ - Càng lên nấc cao, journal `goal-loop.md` càng phải ghi đầy đủ (để human audit lại chuỗi quyết định đã tự chạy).
150
+
151
+ **Lộ trình tự động hoá sâu hơn (P2/P3, telemetry-gated):** đo KR auto-measurable tự động qua CLI helper (`dw goal gap`), rồi tới adapter chạy `test_command`/đếm artifact và tự ghi `current` — giảm dần phần human phải đo tay. Xem ADR-0016 Phasing.
152
+
153
+ ## State bền vững giữa các session — `goal-loop.md`
154
+
155
+ Khi loop kéo dài nhiều session HOẶC chạy `--auto`, ghi annex `.dw/goals/{goal-id}/goal-loop.md`
156
+ (appendage hợp lệ theo goal.md Section 6). Cấu trúc gợi ý:
157
+
158
+ ```markdown
159
+ # Goal Loop Journal — {goal-id}
160
+
161
+ ## Iteration {N} — {YYYY-MM-DD HH:MM} — mode: {supervised|auto}
162
+ - Target KR: KR-00X (gap: {target} − {current})
163
+ - Ladder rung: L{n}
164
+ - Move: {nước đi đã làm}
165
+ - Verify delta: {KR-00X: {old} → {new}} | hoặc: no change
166
+ - Lesson (nếu fail): {vì sao không tiến + sẽ thử gì khác}
167
+
168
+ ## Reflexion memory (per-KR — tránh lặp cách hỏng)
169
+ - KR-001: [L0 fail: lý do] → [L1 fail: lý do] → [đang ở L2]
170
+ - KR-002: ✅ đạt ở L0
171
+
172
+ ## Budget
173
+ - Iterations: {used}/{max} | Stopped-by: {achieved|budget|no-progress|...}
174
+ ```
175
+
176
+ Session mới đọc journal này để **resume** đúng bậc + nhớ bài học. Đây là bản file-based, vendor-neutral của "thread-level goal persistence" mà Codex `/goal` làm.
177
+
178
+ ## Vendor neutrality (W-6 — ADR-0010)
179
+
180
+ Skill là quy trình markdown bất kỳ agent (Claude/Codex/Gemini/CI) đọc được; mọi state nằm trong file (`goal.md`, `events-global.jsonl`, `goal-loop.md`). Bậc cần subagent (L2 Mode B, exploration song song) **degrade nhẹ nhàng** về single-agent 2-pass cho agent không có subagent. Loop chỉ dùng Tier-1 file-watch — KHÔNG phụ thuộc SSE/HTTP.
181
+
182
+ ## Output (mỗi vòng — supervised; hoặc cuối run — auto)
183
+
184
+ ```
185
+ 🎯 Goal $GOAL — $TITLE (iteration N, mode: supervised|auto)
186
+ Target KR vòng này : KR-00X (gap: target − current)
187
+ Ladder rung : L{n} ({tên strategy})
188
+ Move : {tóm tắt nước đi}
189
+ Verify : KR-00X {old} → {new} [✅ moved | ⚠ no change]
190
+ Reflexion : {bài học nếu fail}
191
+ ──
192
+ Trạng thái goal : on-track | stuck | infeasible | achieved
193
+ Next : {KR/nước đi vòng sau} hoặc {lý do DỪNG + options}
194
+ ```
195
+
196
+ Supervised → kết bằng: "Vòng N xong. `continue` / `redirect: …` / `stop`?"
197
+
198
+ ## Liên quan
199
+
200
+ - `dw:goal-sync` — primitive pha OBSERVE (đồng bộ phản ứng khi human pivot)
201
+ - `dw:flow` — orchestrator 1 task (pha ACT giao cho nó)
202
+ - `dw:plan` · `dw:thinking` — công cụ pha ORIENT + ladder L1/L2
203
+ - `dw goal show|summary|portfolio|link|bump` — tầng dữ liệu/state
204
+ - ADR-0016 (`.dw/decisions/0016-goal-pursuit-loop-skill.md`) — full thiết kế loop + ladder + contract
205
+ - ADR-0010 — Goals Layer (KR schema, events, vendor neutrality W-6)
206
+ - ADR-0009 — Agent OS (human gate + cooperative claim)
@@ -0,0 +1,131 @@
1
+ ---
2
+ name: dw:goal-sync
3
+ description: "Đồng bộ trạng thái Goal hiện tại từ .dw/events-global.jsonl. Đọc summary + linked tasks + recent events để re-plan khi human pivot mục tiêu giữa session."
4
+ argument-hint: "[goal-id]"
5
+ ---
6
+
7
+ # Đồng Bộ Trạng Thái Goal
8
+
9
+ Goal: **$ARGUMENTS** (để trống = goal liên quan task đang làm via `parent_goal_id`)
10
+
11
+ ## Khi nào dùng
12
+
13
+ - Khi human report là goal vừa pivot (status change, summary edit, KR added)
14
+ - Khi bắt đầu session mới và task đang làm có `parent_goal_id` set
15
+ - Khi `dw goal portfolio` cho thấy goal liên quan có `goal_version` cao hơn version đã đọc trước
16
+ - Trong dài session, định kỳ resync để bắt event human chỉnh trên browser editor
17
+
18
+ ## Bước 1 — Resolve goal_id
19
+
20
+ Nếu user truyền `$ARGUMENTS`:
21
+ - Validate ID format `G-{slug}` qua regex
22
+ - Dùng trực tiếp
23
+
24
+ Nếu không, derive từ task đang làm:
25
+ ```bash
26
+ # Get current task (most recent v3 task in .dw/tasks/)
27
+ TASK=$(ls -t .dw/tasks/*/task.md 2>/dev/null | head -1 | awk -F/ '{print $(NF-1)}')
28
+ # Extract parent_goal_id from frontmatter
29
+ GOAL=$(grep -E '^parent_goal_id:' ".dw/tasks/$TASK/task.md" | sed 's/parent_goal_id:\s*//;s/["'"'"']//g')
30
+ ```
31
+
32
+ Nếu `parent_goal_id` = `none` hoặc empty → không có goal để sync, dừng.
33
+
34
+ ## Bước 2 — Snapshot hiện tại
35
+
36
+ ```bash
37
+ dw goal show $GOAL # ANSI snapshot
38
+ dw goal summary $GOAL # 1000-char summary
39
+ ```
40
+
41
+ Đọc cấu trúc:
42
+ - `status` (Draft / Active / Achieved / Abandoned / Pivoted) — nếu Pivoted hoặc Abandoned, cần re-plan
43
+ - `goal_version` — track để detect changes future
44
+ - `summary` — strategic context
45
+ - `cycle` — temporal grouping (Q2 2026, etc.)
46
+ - `target_date` — deadline
47
+ - Linked tasks — cross-task picture
48
+
49
+ ## Bước 3 — Tail events log (Tier 1)
50
+
51
+ Đọc events gần đây cho goal này từ `.dw/events-global.jsonl`:
52
+
53
+ ```bash
54
+ # Filter events for this goal (last 50 lines)
55
+ grep "\"goal_id\":\"$GOAL\"" .dw/events-global.jsonl | tail -50
56
+ ```
57
+
58
+ Hoặc programmatic via `src/lib/goal-watch.mjs`:
59
+
60
+ ```javascript
61
+ import { iterateGoalEvents } from 'dw-kit/lib/goal-watch.mjs';
62
+
63
+ const recentEvents = [];
64
+ for await (const ev of iterateGoalEvents({ goalId: $GOAL, backfill: 50 })) {
65
+ recentEvents.push(ev);
66
+ if (recentEvents.length >= 50) break;
67
+ }
68
+ ```
69
+
70
+ Event types để chú ý:
71
+ - `goal_status_changed` — human pivoted; re-read goal.md immediately
72
+ - `goal_pivoted` — version bump with reason; check `summary` field for why
73
+ - `goal_field_updated` (field: `summary` | `icon` | `cycle`) — context drift
74
+ - `goal_kr_progress` — KR moved
75
+ - `goal_task_linked` / `goal_task_unlinked` — scope changed
76
+
77
+ ## Bước 4 — Detect drift vs last-known version
78
+
79
+ So sánh `goal_version` từ Bước 2 với version agent ghi nhớ trước đó (nếu có).
80
+
81
+ Nếu version tăng:
82
+ 1. **Re-read** `.dw/goals/$GOAL/goal.md` đầy đủ Section 1-5
83
+ 2. **Re-check** task.md đang làm — `parent_goal_id` còn match không?
84
+ 3. **Re-plan** subtasks nếu strategic intent thay đổi
85
+ 4. Nếu Pivoted/Abandoned status — STOP execution, ask human
86
+
87
+ Nếu version không đổi nhưng có `goal_field_updated` events:
88
+ - Summary changed → soft refresh strategic context only
89
+ - Cycle/icon changed → cosmetic, không re-plan
90
+
91
+ ## Bước 5 — Subscribe (long-running session)
92
+
93
+ Đối với session dài, set up watcher để auto-detect future changes:
94
+
95
+ ```javascript
96
+ import { watchGoal } from 'dw-kit/lib/goal-watch.mjs';
97
+
98
+ const unsubscribe = watchGoal('$GOAL', (event) => {
99
+ if (event.event === 'goal_status_changed' || event.event === 'goal_pivoted') {
100
+ // Stop current work, re-read goal, notify human
101
+ }
102
+ });
103
+ ```
104
+
105
+ **Vendor neutrality (W-6):** Tier 1 fs.watch trên `events-global.jsonl` là cách DUY NHẤT để non-Claude agents (Codex, Gemini, CI) react. Đừng dùng SSE `/events.sse` cho agents — chỉ browser UI dùng SSE.
106
+
107
+ **Rotation:** `.dw/events-global.jsonl` rotate sang `.dw/events-global-YYYYMM.jsonl` khi đạt 500KB/5000 lines (C-4). Historical events trong archive files; watcher auto-detect new lines trong current file.
108
+
109
+ ## Output
110
+
111
+ Brief summary cho human:
112
+
113
+ ```
114
+ 🎯 Goal $GOAL — $TITLE
115
+ Status: $STATUS (v$VERSION, last_updated $DATE)
116
+ Recent activity: N events trong last 50 lines
117
+ - YYYY-MM-DDTHH:MM:SSZ goal_status_changed: $FROM → $TO
118
+ - YYYY-MM-DDTHH:MM:SSZ goal_field_updated summary
119
+ ...
120
+
121
+ [Drift analysis if version bumped vs last-known]
122
+ [Suggested next action if Pivoted/Abandoned]
123
+ ```
124
+
125
+ ## Liên quan
126
+
127
+ - `dw goal show $GOAL` — full ANSI snapshot
128
+ - `dw goal portfolio` — all goals overview
129
+ - `dw goal lint $GOAL` — drift detection vs goals-index.json
130
+ - `.dw/research/agentchattr-fit-analysis.md` — summary primitive borrow context
131
+ - ADR-0010 § Round 2 — full Goals Layer architecture
@@ -1,35 +1,35 @@
1
- ---
2
- date: [ISO timestamp — e.g. 2026-04-02T14:30:00]
3
- from: [agent-role — researcher | planner | developer | reviewer | debugger]
4
- to: [agent-role — planner | developer | user]
5
- task: [task-name]
6
- status: DONE | DONE_WITH_CONCERNS | BLOCKED | NEEDS_CONTEXT
7
- ---
8
-
9
- ## Summary
10
-
11
- [1-3 câu tóm tắt kết quả / findings]
12
-
13
- ## Details
14
-
15
- [Chi tiết findings, decisions, hoặc implementation notes]
16
-
17
- ## Concerns (nếu DONE_WITH_CONCERNS)
18
-
19
- - [Concern 1]
20
- - [Concern 2]
21
-
22
- ## Blockers (nếu BLOCKED)
23
-
24
- - **Blocker**: [Mô tả vấn đề]
25
- - **Owner**: [Ai cần resolve]
26
- - **Unblock by**: [Action cần làm]
27
-
28
- ## Needs (nếu NEEDS_CONTEXT)
29
-
30
- - [ ] [Thông tin cần thêm]
31
- - [ ] [Quyết định cần từ user/TL]
32
-
33
- ## Next Steps
34
-
35
- - [Bước tiếp theo đề xuất]
1
+ ---
2
+ date: [ISO timestamp — e.g. 2026-04-02T14:30:00]
3
+ from: [agent-role — researcher | planner | developer | reviewer | debugger]
4
+ to: [agent-role — planner | developer | user]
5
+ task: [task-name]
6
+ status: DONE | DONE_WITH_CONCERNS | BLOCKED | NEEDS_CONTEXT
7
+ ---
8
+
9
+ ## Summary
10
+
11
+ [1-3 câu tóm tắt kết quả / findings]
12
+
13
+ ## Details
14
+
15
+ [Chi tiết findings, decisions, hoặc implementation notes]
16
+
17
+ ## Concerns (nếu DONE_WITH_CONCERNS)
18
+
19
+ - [Concern 1]
20
+ - [Concern 2]
21
+
22
+ ## Blockers (nếu BLOCKED)
23
+
24
+ - **Blocker**: [Mô tả vấn đề]
25
+ - **Owner**: [Ai cần resolve]
26
+ - **Unblock by**: [Action cần làm]
27
+
28
+ ## Needs (nếu NEEDS_CONTEXT)
29
+
30
+ - [ ] [Thông tin cần thêm]
31
+ - [ ] [Quyết định cần từ user/TL]
32
+
33
+ ## Next Steps
34
+
35
+ - [Bước tiếp theo đề xuất]
@@ -10,6 +10,14 @@
10
10
 
11
11
  schema_version: agents@v1
12
12
 
13
+ # ADR-0015 KR-D: multi-agent live debate roster. Trigger via voice
14
+ # "debate <topic>" / "tranh luận <topic>". Server spawns these agents
15
+ # in parallel; replies stream to browser via SSE. Each entry MUST also
16
+ # exist under `agents:` below.
17
+ voice_debate:
18
+ roster: [claude, codex]
19
+ timeout_ms: 30000
20
+
13
21
  agents:
14
22
  # Anthropic Claude Code — non-interactive print mode.
15
23
  # Install: https://docs.claude.com/en/docs/claude-code
@@ -1,53 +1,53 @@
1
- # Agent Communication Protocol — dw-kit v1.2
2
-
3
- ## Mục Đích
4
-
5
- Khi một task lớn cần nhiều "vai" khác nhau (researcher → planner → developer), việc ghi lại kết quả từng bước giúp:
6
- - Team members (người hoặc agent) biết chính xác task đang ở đâu
7
- - Audit trail rõ ràng: ai quyết định gì, lúc nào
8
- - Session tiếp theo có thể tiếp tục mà không cần hỏi lại
9
-
10
- ## Convention: Reports Directory
11
-
12
- ```
13
- .dw/tasks/[task-name]/
14
- ├── [name]-context.md # Research findings
15
- ├── [name]-plan.md # Implementation plan
16
- ├── [name]-progress.md # Progress tracking
17
- └── reports/ # Agent communication (v1.2+)
18
- ├── 260402-1430-from-researcher-to-planner-analysis.md
19
- ├── 260402-1500-from-planner-to-developer-subtask-1.md
20
- └── 260402-1600-from-developer-to-reviewer-pr-ready.md
21
- ```
22
-
23
- **Filename format**: `[YYMMDD-HHMM]-from-[role]-to-[role]-[description].md`
24
-
25
- ## Status Codes
26
-
27
- | Status | Nghĩa |
28
- |--------|-------|
29
- | `DONE` | Hoàn thành, output sẵn sàng để dùng |
30
- | `DONE_WITH_CONCERNS` | Xong nhưng có điểm đáng chú ý / cần review |
31
- | `BLOCKED` | Bị chặn, cần action từ bên ngoài để tiếp tục |
32
- | `NEEDS_CONTEXT` | Thiếu thông tin, cần human confirm |
33
-
34
- ## Khi Nào Tạo Report
35
-
36
- - Sau khi `dw-research` hoàn thành → report `from-researcher-to-planner`
37
- - Sau khi `dw-plan` approved → report `from-planner-to-developer`
38
- - Khi phát hiện blocker trong execute → report `from-developer-to-user` với `BLOCKED`
39
- - Sau khi review xong → report `from-reviewer-to-developer`
40
-
41
- ## Khi Nào KHÔNG Cần Report
42
-
43
- - Tasks `quick` depth (≤2 files, hotfix) → không cần overhead này
44
- - Solo dev, single session → progress.md đã đủ
45
- - Thông tin đã có trong context.md / plan.md → không duplicate
46
-
47
- ## Template
48
-
49
- Dùng `.claude/templates/agent-report.md`
50
-
51
- ## Lưu Ý Quan Trọng
52
-
53
- Reports là **cho con người đọc**, không phải protocol cho AI. Claude Code đã communicate qua conversation context. Reports giúp team members theo dõi task cross-session, không phải AI-to-AI messaging.
1
+ # Agent Communication Protocol — dw-kit v1.2
2
+
3
+ ## Mục Đích
4
+
5
+ Khi một task lớn cần nhiều "vai" khác nhau (researcher → planner → developer), việc ghi lại kết quả từng bước giúp:
6
+ - Team members (người hoặc agent) biết chính xác task đang ở đâu
7
+ - Audit trail rõ ràng: ai quyết định gì, lúc nào
8
+ - Session tiếp theo có thể tiếp tục mà không cần hỏi lại
9
+
10
+ ## Convention: Reports Directory
11
+
12
+ ```
13
+ .dw/tasks/[task-name]/
14
+ ├── [name]-context.md # Research findings
15
+ ├── [name]-plan.md # Implementation plan
16
+ ├── [name]-progress.md # Progress tracking
17
+ └── reports/ # Agent communication (v1.2+)
18
+ ├── 260402-1430-from-researcher-to-planner-analysis.md
19
+ ├── 260402-1500-from-planner-to-developer-subtask-1.md
20
+ └── 260402-1600-from-developer-to-reviewer-pr-ready.md
21
+ ```
22
+
23
+ **Filename format**: `[YYMMDD-HHMM]-from-[role]-to-[role]-[description].md`
24
+
25
+ ## Status Codes
26
+
27
+ | Status | Nghĩa |
28
+ |--------|-------|
29
+ | `DONE` | Hoàn thành, output sẵn sàng để dùng |
30
+ | `DONE_WITH_CONCERNS` | Xong nhưng có điểm đáng chú ý / cần review |
31
+ | `BLOCKED` | Bị chặn, cần action từ bên ngoài để tiếp tục |
32
+ | `NEEDS_CONTEXT` | Thiếu thông tin, cần human confirm |
33
+
34
+ ## Khi Nào Tạo Report
35
+
36
+ - Sau khi `dw-research` hoàn thành → report `from-researcher-to-planner`
37
+ - Sau khi `dw-plan` approved → report `from-planner-to-developer`
38
+ - Khi phát hiện blocker trong execute → report `from-developer-to-user` với `BLOCKED`
39
+ - Sau khi review xong → report `from-reviewer-to-developer`
40
+
41
+ ## Khi Nào KHÔNG Cần Report
42
+
43
+ - Tasks `quick` depth (≤2 files, hotfix) → không cần overhead này
44
+ - Solo dev, single session → progress.md đã đủ
45
+ - Thông tin đã có trong context.md / plan.md → không duplicate
46
+
47
+ ## Template
48
+
49
+ Dùng `.claude/templates/agent-report.md`
50
+
51
+ ## Lưu Ý Quan Trọng
52
+
53
+ Reports là **cho con người đọc**, không phải protocol cho AI. Claude Code đã communicate qua conversation context. Reports giúp team members theo dõi task cross-session, không phải AI-to-AI messaging.
@@ -0,0 +1,33 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "$id": "https://github.com/dv-workflow/dv-workflow/schemas/events/created.schema.json",
4
+ "title": "DW Event: created",
5
+ "description": "Category: session-lifecycle. See docs/specs/dw-event-schema-v1.0.md §5 for narrative.",
6
+ "type": "object",
7
+ "properties": {
8
+ "ts": {
9
+ "type": "string",
10
+ "format": "date-time",
11
+ "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:\\.\\d+)?Z$",
12
+ "description": "ISO 8601 UTC timestamp (envelope, set by writer)"
13
+ },
14
+ "event": {
15
+ "type": "string",
16
+ "const": "created",
17
+ "description": "Event name (envelope)"
18
+ },
19
+ "agent": {
20
+ "type": "string"
21
+ },
22
+ "goal": {
23
+ "type": "string"
24
+ }
25
+ },
26
+ "required": [
27
+ "ts",
28
+ "event",
29
+ "agent",
30
+ "goal"
31
+ ],
32
+ "additionalProperties": true
33
+ }
@@ -0,0 +1,42 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "$id": "https://github.com/dv-workflow/dv-workflow/schemas/events/debate_agent_failed.schema.json",
4
+ "title": "DW Event: debate_agent_failed",
5
+ "description": "Category: debate. See docs/specs/dw-event-schema-v1.0.md §5 for narrative.",
6
+ "type": "object",
7
+ "properties": {
8
+ "ts": {
9
+ "type": "string",
10
+ "format": "date-time",
11
+ "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:\\.\\d+)?Z$",
12
+ "description": "ISO 8601 UTC timestamp (envelope, set by writer)"
13
+ },
14
+ "event": {
15
+ "type": "string",
16
+ "const": "debate_agent_failed",
17
+ "description": "Event name (envelope)"
18
+ },
19
+ "debate_id": {
20
+ "type": "string"
21
+ },
22
+ "agent": {
23
+ "type": "string"
24
+ },
25
+ "error": {
26
+ "type": "string"
27
+ },
28
+ "exit_code": {
29
+ "type": "integer"
30
+ },
31
+ "ms": {
32
+ "type": "integer"
33
+ }
34
+ },
35
+ "required": [
36
+ "ts",
37
+ "event",
38
+ "debate_id",
39
+ "agent"
40
+ ],
41
+ "additionalProperties": true
42
+ }
@@ -0,0 +1,44 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "$id": "https://github.com/dv-workflow/dv-workflow/schemas/events/debate_agent_replied.schema.json",
4
+ "title": "DW Event: debate_agent_replied",
5
+ "description": "Category: debate. See docs/specs/dw-event-schema-v1.0.md §5 for narrative.",
6
+ "type": "object",
7
+ "properties": {
8
+ "ts": {
9
+ "type": "string",
10
+ "format": "date-time",
11
+ "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:\\.\\d+)?Z$",
12
+ "description": "ISO 8601 UTC timestamp (envelope, set by writer)"
13
+ },
14
+ "event": {
15
+ "type": "string",
16
+ "const": "debate_agent_replied",
17
+ "description": "Event name (envelope)"
18
+ },
19
+ "debate_id": {
20
+ "type": "string"
21
+ },
22
+ "agent": {
23
+ "type": "string"
24
+ },
25
+ "ms": {
26
+ "type": "integer"
27
+ },
28
+ "reply": {
29
+ "type": "string"
30
+ },
31
+ "reply_chars": {
32
+ "type": "integer"
33
+ }
34
+ },
35
+ "required": [
36
+ "ts",
37
+ "event",
38
+ "debate_id",
39
+ "agent",
40
+ "ms",
41
+ "reply"
42
+ ],
43
+ "additionalProperties": true
44
+ }