@damphuquy/agent-init 1.4.3 → 2.0.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.
@@ -1,28 +1,117 @@
1
1
  # Implementation & Harness Standards
2
2
 
3
- <implementation_standards version="1.0">
3
+ <implementation_standards version="2.0">
4
4
 
5
5
  <description>
6
- Engineering quality, type safety, and testing conventions for this codebase.
6
+ Engineering quality, strict typing, clean architecture, and defensive execution conventions. Project-agnostic.
7
7
  </description>
8
8
 
9
- ## 1. Type Safety & Code Hygiene
10
- <conventions>
9
+ ---
10
+
11
+ ## 1. Type Safety & Static Analysis
12
+
13
+ <type_safety>
11
14
  <rule id="strict_typing">
12
- All functions, methods, and class attributes must have explicit type annotations. Use modern union types (`int | None` or `string | null`) and avoid untyped `Any`/`any` unless interfacing with raw external payloads.
15
+ All functions, methods, and class attributes must have explicit type annotations. Use modern union types (`int | None` or `string | null`). Avoid untyped `Any`/`any` unless deserializing unvalidated external payloads at boundary gateways.
16
+ </rule>
17
+
18
+ <rule id="explicit_return_types">
19
+ Always declare explicit return types on public functions and methods to enforce compile-time contracts and prevent accidental type widening.
20
+ </rule>
21
+
22
+ <rule id="no_suppression">
23
+ Never silence linter, formatter, or type-checker errors with inline suppression directives (`# type: ignore`, `eslint-disable`, `@SuppressWarnings`) to artificially pass a validation gate. Fix the underlying root cause.
13
24
  </rule>
25
+ </type_safety>
26
+
27
+ ---
28
+
29
+ ## 2. Clean Architecture & Layered Domain Purity
30
+
31
+ <clean_architecture>
32
+ <rule id="dependency_rule">
33
+ Dependencies must only point inward toward the core domain. Inner domain layers must never import or depend on outer infrastructure frameworks, databases, or UI modules.
34
+ </rule>
35
+
14
36
  <rule id="domain_purity">
15
- Code in domain layers must remain pure with zero external infrastructure dependencies.
37
+ Core business logic, domain entities, and value objects must remain 100% pure with zero side-effects, zero filesystem I/O, and zero network calls.
16
38
  </rule>
17
- <rule id="immutability">
18
- Prefer immutable models for domain events, value objects, and DTOs.
39
+
40
+ <rule id="ports_and_adapters">
41
+ Define abstract interfaces (ports) in the application/domain layer for persistence, external APIs, and messaging. Implement concrete drivers (adapters) strictly within infrastructure packages.
42
+ </rule>
43
+
44
+ <rule id="no_premature_abstraction">
45
+ Do not introduce speculative abstraction layers, dynamic factories, or unnecessary indirection for simple single-purpose utilities.
46
+ </rule>
47
+ </clean_architecture>
48
+
49
+ ---
50
+
51
+ ## 3. Error Handling & Fail-Fast Principles
52
+
53
+ <error_handling>
54
+ <rule id="fail_fast_at_boundaries">
55
+ Validate all incoming parameters, payloads, and environment variables at system entrypoints. Reject malformed input immediately before invoking business logic.
56
+ </rule>
57
+
58
+ <rule id="no_silent_swallowing">
59
+ Never use empty `catch {}`, `except: pass`, or unlogged exception handlers. Every caught exception must either be handled, transformed into a typed domain error, or cleanly propagated.
60
+ </rule>
61
+
62
+ <rule id="typed_domain_errors">
63
+ Create explicit domain error classes with machine-readable error codes (e.g. `ResourceNotFoundError`, `ValidationError`, `ConcurrencyConflictError`) rather than throwing generic exceptions.
19
64
  </rule>
20
- </conventions>
65
+ </error_handling>
21
66
 
22
- ## 2. Test Architecture
23
- <test_structure>
24
- - `tests/unit/`: Fast, isolated tests for domain models, core logic, and mock adapters.
25
- - `tests/integration/`: End-to-end flow tests with test services or local databases.
26
- </test_structure>
67
+ ---
68
+
69
+ ## 4. Immutability & Concurrency Safety
70
+
71
+ <concurrency_and_immutability>
72
+ <rule id="immutable_data_structures">
73
+ Prefer immutable models (`dataclass(frozen=True)`, `readonly` interfaces, or `Readonly<T>`) for domain events, configuration objects, and Data Transfer Objects (DTOs).
74
+ </rule>
75
+
76
+ <rule id="no_shared_mutable_state">
77
+ Avoid global mutable variables, module-level state caches, or singletons with mutable fields. Pass dependencies explicitly via constructors (Dependency Injection).
78
+ </rule>
79
+
80
+ <rule id="safe_async_lifecycle">
81
+ Always handle asynchronous error rejection and cancellation cleanly. Ensure timeouts are specified for external network calls and database queries.
82
+ </rule>
83
+ </concurrency_and_immutability>
84
+
85
+ ---
86
+
87
+ ## 5. Observability & Logging Hygiene
88
+
89
+ <observability_hygiene>
90
+ <rule id="structured_logging">
91
+ Use structured logging with key-value context (`task_id`, `user_id`, `component`) instead of unstructured string concatenation.
92
+ </rule>
93
+
94
+ <rule id="no_credential_leakage">
95
+ Never log sensitive data: passwords, tokens, API keys, cookies, or personally identifiable information (PII).
96
+ </rule>
97
+
98
+ <rule id="clean_production_diff">
99
+ Remove all temporary debug logs (`console.log`, `print()`, `debugger`, `dump()`) before requesting Gate G3 sign-off.
100
+ </rule>
101
+ </observability_hygiene>
102
+
103
+ ---
104
+
105
+ ## 6. Defensive Resource Management & Teardown
106
+
107
+ <resource_management>
108
+ <rule id="deterministic_teardown">
109
+ Always manage file handles, network sockets, and database transactions using deterministic scoping constructs (`try...finally`, Python `with`, TypeScript `using`, or language-native RAII).
110
+ </rule>
111
+
112
+ <rule id="isolated_test_state">
113
+ Test fixtures must create and destroy their own temporary state. Tests must leave the system in a clean state upon completion.
114
+ </rule>
115
+ </resource_management>
27
116
 
28
117
  </implementation_standards>
@@ -1,24 +1,101 @@
1
1
  # Subagent Delegation & Orchestration Protocol
2
2
 
3
- <orchestration_protocol version="1.0">
3
+ <orchestration_protocol version="2.0">
4
4
 
5
5
  <description>
6
- Guidelines for delegating, isolating, and coordinating subagents during complex tasks.
6
+ Engineering guidelines for delegating, isolating, and coordinating subagents during complex, multi-phase tasks. Project-agnostic.
7
7
  </description>
8
8
 
9
- ## 1. Delegation Principles
10
- <delegation_rules>
11
- <rule id="explicit_scope">
12
- Always specify exact files, function signatures, and expected structured output formats.
9
+ ---
10
+
11
+ ## 1. Delegation Criteria & Workload Triage
12
+
13
+ <delegation_criteria>
14
+ Subagents should be spawned deliberately for bounded, high-leverage subtasks. Do NOT spawn subagents for trivial steps.
15
+
16
+ ### When to Delegate to a Subagent:
17
+ - **Isolated Research Spikes:** Exploring unfamiliar libraries, auditing legacy subsystems, or reading documentation without polluting the parent agent's context window.
18
+ - **Dedicated Quality Audits:** Independent security vulnerability audits, accessibility reviews (a11y), or strict lint/formatting passes.
19
+ - **Orthogonal Test Authoring:** Writing standalone unit test fixtures or integration harnesses for a frozen interface contract.
20
+ - **Parallel Independent Slices:** Implementing non-overlapping, orthogonal components that touch distinct file boundaries.
21
+
22
+ ### When Parent Agent MUST Retain Control (Do NOT Delegate):
23
+ - **Architectural Trade-offs & Decisions:** Authoring `decision.md` options and Gate 1 sign-offs.
24
+ - **Master Task Contract & Planning:** Defining `task.md`, vertical slice contracts in `plan.md`, and Gate 2 sign-offs.
25
+ - **Quality Gates & User Approval:** Conducting Gate G3 review sign-off and final `handoff.md` generation.
26
+ - **Interactive User Clarification:** Any prompt requiring direct user guidance or requirement resolution.
27
+ </delegation_criteria>
28
+
29
+ ---
30
+
31
+ ## 2. Context Containment & Scoping Rules
32
+
33
+ <context_containment>
34
+ <rule id="explicit_file_manifest">
35
+ Always provide the subagent with an explicit list of file paths to inspect or modify. Never prompt a subagent with open-ended instructions like "explore the project" or "look around the codebase".
36
+ </rule>
37
+
38
+ <rule id="port_and_interface_focus">
39
+ Constrain the subagent's inputs to relevant port interfaces, domain entities, and accompanying test suites. Keep infrastructure noise out of the subagent prompt.
40
+ </rule>
41
+
42
+ <rule id="structured_output_contract">
43
+ Always demand a structured output format from the subagent (e.g. unified diff, bulleted findings categorized by Confirmed/Observed/Hypothesized, or JSON/markdown table).
44
+ </rule>
45
+ </context_containment>
46
+
47
+ ---
48
+
49
+ ## 3. Concurrency, Isolation & Write Permissions
50
+
51
+ <concurrency_and_isolation>
52
+ <rule id="zero_write_collision">
53
+ Multiple subagents must NEVER be given write access to the same files or shared mutable database tables concurrently. Overlapping writes cause silent regressions and merge conflicts.
54
+ </rule>
55
+
56
+ <rule id="read_only_by_default">
57
+ Default subagents to read-only mode whenever possible (e.g. research, code exploration, audit). Only grant write permissions when the target files are strictly isolated to that subagent.
58
+ </rule>
59
+
60
+ <rule id="workspace_isolation">
61
+ If subagents support isolated workspaces (e.g. branch or worktree mode), use them for speculative spike experiments to ensure the parent working tree remains clean.
62
+ </rule>
63
+ </concurrency_and_isolation>
64
+
65
+ ---
66
+
67
+ ## 4. State Synchronization & Parent Re-Integration
68
+
69
+ <state_synchronization>
70
+ <rule id="parent_owns_master_state">
71
+ Subagents must NEVER directly edit the parent's master task artifacts (`task.md`, `state.md`, `review.md`). Only the parent agent reconciles subagent outputs into master state files.
72
+ </rule>
73
+
74
+ <rule id="verification_before_acceptance">
75
+ When a subagent returns modified source code or findings, the parent agent must inspect the diff and execute the slice's designated verifier command before accepting the work.
76
+ </rule>
77
+
78
+ <rule id="evidence_crystallization">
79
+ Extract verified facts from subagent reports and append them to `state.md > <verification_evidence>`. Discard transient subagent conversation logs to preserve context hygiene.
80
+ </rule>
81
+ </state_synchronization>
82
+
83
+ ---
84
+
85
+ ## 5. Reactive Coordination, Timeouts & Failure Recovery
86
+
87
+ <coordination_and_recovery>
88
+ <rule id="no_polling_loops">
89
+ Never implement sleep-and-poll loops (`while true; sleep 5; check_status`) to monitor subagents. Rely on the system's reactive message wakeup mechanism to resume execution upon subagent completion.
13
90
  </rule>
14
91
 
15
- <rule id="context_containment">
16
- Do not grant unbounded repo access; constrain subagent context to relevant test suites and port contracts.
92
+ <rule id="retry_budget_enforcement">
93
+ If a subagent encounters a tool error or recurring failure, enforce the 3-attempt retry budget. If exhausted, record the failure signature in `state.md > <failure_memory>` and escalate to human guidance.
17
94
  </rule>
18
95
 
19
- <rule id="no_polling">
20
- Rely on the system's reactive message wakeup mechanism when subagents complete their execution.
96
+ <rule id="teardown_and_cleanup">
97
+ Terminate idle or failed subagents cleanly. Ensure any temporary scratch files or experiment branches created by the subagent are deleted before completing the slice.
21
98
  </rule>
22
- </delegation_rules>
99
+ </coordination_and_recovery>
23
100
 
24
101
  </orchestration_protocol>
@@ -24,6 +24,7 @@ process/
24
24
  │ ├── review-template.md.seed # Artifact giai đoạn Review (Gate 3)
25
25
  │ ├── handoff-template.md.seed # Tóm tắt bàn giao cuối cùng (ngắn gọn)
26
26
  │ ├── cancellation-template.md.seed # Biên bản hủy task lưu giữ tri thức
27
+ │ ├── pause-template.md.seed # Biên bản tạm dừng task & đóng băng an toàn
27
28
  │ ├── results-template.tsv.seed # Bảng theo dõi số liệu benchmark & định lượng
28
29
  │ └── program-template.md.seed # Bản thiết kế chương trình lớn nhiều giai đoạn
29
30
  ├── context/ # Cơ sở tri thức bền vững & router định tuyến
@@ -45,6 +46,7 @@ process/
45
46
  │ │ ├── review.md # Biên bản nghiệm thu kiểm thử
46
47
  │ │ ├── handoff.md # Tóm tắt bàn giao
47
48
  │ │ ├── results.tsv # (Tùy chọn) Theo dõi benchmark & metric
49
+ │ │ ├── paused.md # (Nếu tạm dừng) Biên bản đóng băng & điều kiện mở lại
48
50
  │ │ └── cancelled.md # (Nếu hủy) Lưu vết nguyên nhân & hoàn nguyên
49
51
  │ ├── completed/ # Lưu trữ các task đã hoàn thành
50
52
  │ └── backlog/ # Ghi chú task tồn đọng: {note_slug}_NOTE_{dd-mm-yy}.md
@@ -107,8 +109,10 @@ handoff.md ← (Complete) Tóm tắt bàn giao ngắn gọn
107
109
  | Thực thi | mã nguồn + kiểm thử + `state.md` |
108
110
  | Nghiệm thu | `review.md` |
109
111
  | Bàn giao | `handoff.md` |
112
+ | Tạm dừng / Đóng băng | `paused.md` (đóng băng sạch sẽ & checklist mở lại khi bị chặn) |
110
113
  | Hủy task | `cancelled.md` (lưu giữ tri thức khi hủy bỏ) |
111
114
  | Benchmark / Định lượng | `results.tsv` (theo dõi hiệu năng và số liệu đánh giá) |
115
+ | Chương trình lớn | `program.md` (bản thiết kế chương trình lớn nhiều giai đoạn) |
112
116
  | Gate 1 | Phê duyệt trong `decision.md` |
113
117
  | Gate 2 | Phê duyệt trong `plan.md` |
114
118
  | Gate 3 | Phê duyệt trong `review.md` |
@@ -81,6 +81,11 @@
81
81
  các prototype/test có thể tái sử dụng, và kiểm tra hoàn nguyên khi một task đang làm bị dừng giữa chừng.
82
82
  </seed>
83
83
 
84
+ <seed type="pause" path="pause-template.md.seed">
85
+ Biên bản tạm dừng task. Bảo toàn trạng thái cây làm việc git, ảnh chụp các slice đã xong,
86
+ điều kiện kích hoạt lại và đánh giá nguy cơ lỗi thời khi task bị đóng băng tạm thời.
87
+ </seed>
88
+
84
89
  <seed type="results" path="results-template.tsv.seed">
85
90
  Bảng đăng ký đánh giá số liệu benchmark và định lượng.
86
91
  Dùng để theo dõi latency, throughput, bộ nhớ hoặc điểm đánh giá qua các vòng lặp và lát cắt dọc.
@@ -116,6 +121,10 @@ handoff.md ← Tóm tắt bàn giao cuối cùng (ngắn gọn)
116
121
  | Thực thi | mã nguồn + kiểm thử + `state.md` |
117
122
  | Nghiệm thu | `review.md` |
118
123
  | Bàn giao | `handoff.md` |
124
+ | Tạm dừng / Đóng băng | `paused.md` (đóng băng sạch sẽ & checklist mở lại) |
125
+ | Hủy task | `cancelled.md` (lưu giữ tri thức khi hủy bỏ) |
126
+ | Benchmark / Định lượng | `results.tsv` (theo dõi hiệu năng và số liệu đánh giá) |
127
+ | Chương trình lớn | `program.md` (bản thiết kế chương trình lớn nhiều giai đoạn) |
119
128
  | Gate 1 | Phê duyệt trong `decision.md` |
120
129
  | Gate 2 | Phê duyệt trong `plan.md` |
121
130
  | Gate 3 | Phê duyệt trong `review.md` |
@@ -135,6 +144,7 @@ process/features/active/CHG-017-your-feature/
135
144
  ├── review.md ← khởi tạo từ review-template.md.seed (Biên bản kiểm toán Gate 3)
136
145
  ├── handoff.md ← khởi tạo từ handoff-template.md.seed (Tóm tắt bàn giao)
137
146
  ├── results.tsv ← (Tùy chọn) khởi tạo từ results-template.tsv.seed (Metrics/Benchmarks)
147
+ ├── paused.md ← (Nếu tạm dừng) khởi tạo từ pause-template.md.seed
138
148
  └── cancelled.md ← (Nếu hủy task) khởi tạo từ cancellation-template.md.seed
139
149
  ```
140
150
 
@@ -170,6 +180,9 @@ cp process/_seeds/handoff-template.md.seed process/features/active/CHG-XXX-your-
170
180
  # (Tùy chọn) Khi cần theo dõi hiệu năng hoặc số liệu benchmark:
171
181
  cp process/_seeds/results-template.tsv.seed process/features/active/CHG-XXX-your-feature/results.tsv
172
182
 
183
+ # (Khi cần tạm dừng hoặc đóng băng task đang làm):
184
+ cp process/_seeds/pause-template.md.seed process/features/active/CHG-XXX-your-feature/paused.md
185
+
173
186
  # (Khi cần hủy bỏ một task đang dang dở):
174
187
  cp process/_seeds/cancellation-template.md.seed process/features/active/CHG-XXX-your-feature/cancelled.md
175
188
  ```
@@ -0,0 +1,106 @@
1
+ # Biên Bản Tạm Dừng Task: [TASK-ID] [Tiêu Đề Task]
2
+
3
+ <pause_record task_id="[TASK-ID]" version="1.0" framework="RIPER-5">
4
+
5
+ <!--
6
+ HƯỚNG DẪN TẠM DỪNG & ĐÓNG BĂNG TASK (TASK PAUSE):
7
+ - Mục đích: Đóng băng sạch sẽ task đang thực thi khi gặp blocker bên ngoài, thay đổi độ ưu tiên, hoặc chờ phản hồi từ con người.
8
+ - Tuyệt đối không bỏ dở task mà không lưu vết chính xác trạng thái git và điều kiện kích hoạt lại.
9
+ - Khởi tạo file này thành `paused.md` bên trong thư mục task đang làm.
10
+ - Nếu tạm dừng dài hạn (> 2 tuần), chuyển thư mục task từ `active/` sang `backlog/` (hoặc `paused/`) để giữ `active/` luôn sạch.
11
+ -->
12
+
13
+ <status>
14
+ <phase_at_pause>[RESEARCH | INNOVATE | PLAN | EXECUTE | REVIEW]</phase_at_pause>
15
+ <paused_date>[YYYY-MM-DD hoặc DD-MM-YY]</paused_date>
16
+ <paused_by>[@engineer_hoac_tech_lead]</paused_by>
17
+ <git_branch>[feature/CHG-XXX-mo-ta]</git_branch>
18
+ <git_state>[COMMITTED_WIP | STASHED | CLEAN]</git_state>
19
+ <git_commit_or_stash_ref>[ví dụ: commit hash a1b2c3d hoặc stash@{0}]</git_commit_or_stash_ref>
20
+ </status>
21
+
22
+ ---
23
+
24
+ ## 1. Lý Do Tạm Dừng & Yếu Tố Chặn (Blockers)
25
+
26
+ <pause_context>
27
+ <primary_reason>
28
+ <!-- [ví dụ: Bị chặn bởi API Task CHG-042 / Chờ review bảo mật / Ưu tiên khẩn cấp cho hotfix P0 / Chờ feedback sản phẩm] -->
29
+ [Tóm tắt ngắn gọn lý do tại sao task này phải tạm dừng.]
30
+ </primary_reason>
31
+
32
+ <blocker_details>
33
+ [Ngữ cảnh chi tiết về điều kiện chặn, ticket bên ngoài hoặc sự phụ thuộc kiến trúc.]
34
+ </blocker_details>
35
+ </pause_context>
36
+
37
+ ---
38
+
39
+ ## 2. Tiến Độ Đang Làm & Snapshot Lát Cắt (Slice)
40
+
41
+ <progress_snapshot>
42
+ <completed_slices>
43
+ <!-- Những slice nào trong plan.md đã vượt qua verifier thành công? -->
44
+ - [Slice 1: Mục tiêu — ĐÃ KIỂM THỬ XANH & COMMIT]
45
+ </completed_slices>
46
+
47
+ <active_slice_at_pause>
48
+ <!-- Slice nào đang dang dở khi dừng? -->
49
+ <slice_id>[ví dụ: Slice 2]</slice_id>
50
+ <state_summary>[ví dụ: Đã viết xong logic service, đang viết 2 unit test nhưng còn lỗi mock]</state_summary>
51
+ </active_slice_at_pause>
52
+
53
+ <touched_files>
54
+ <!-- Danh sách file đã sửa hoặc tạo mới trong quá trình thực thi -->
55
+ - `src/...`
56
+ - `tests/...`
57
+ </touched_files>
58
+ </progress_snapshot>
59
+
60
+ ---
61
+
62
+ ## 3. Điều Kiện Kích Hoạt Lại (Resumption Criteria)
63
+
64
+ <resumption_criteria>
65
+ <!-- Sự kiện, ticket hay điều kiện cụ thể nào sẽ mở khóa để tiếp tục task này? -->
66
+ <trigger_condition>
67
+ [ví dụ: CHG-042 được merge vào main và deploy lên môi trường staging]
68
+ </trigger_condition>
69
+
70
+ <responsible_owner>[@ky_su_phu_trach]</responsible_owner>
71
+ </resumption_criteria>
72
+
73
+ ---
74
+
75
+ ## 4. Đánh Giá Nguy Cơ Lỗi Thời (Stale-Risk & Bit-Rot)
76
+
77
+ <stale_risk_assessment>
78
+ <!-- Những gì có nguy cơ biến đổi hoặc xung đột nếu task bị đóng băng nhiều tuần/tháng? -->
79
+ <schema_drift_risk level="[LOW|MEDIUM|HIGH]">
80
+ [Nguy cơ database migration hoặc schema API thay đổi song song trên main.]
81
+ </schema_drift_risk>
82
+
83
+ <dependency_drift_risk level="[LOW|MEDIUM|HIGH]">
84
+ [Nguy cơ thư viện phụ thuộc hoặc module dùng chung được nâng cấp phiên bản.]
85
+ </dependency_drift_risk>
86
+
87
+ <architecture_drift_risk level="[LOW|MEDIUM|HIGH]">
88
+ [Nguy cơ quy chuẩn hoặc tái cấu trúc làm vô hiệu các giả thuyết trong research.md.]
89
+ </architecture_drift_risk>
90
+ </stale_risk_assessment>
91
+
92
+ ---
93
+
94
+ ## 5. Checklist Kiểm Tra Trước Khi Khởi Động Lại (Pre-Flight Resumption)
95
+
96
+ <resumption_checklist>
97
+ <!-- BẮT BUỘC thực hiện tuần tự trước khi mở lại vòng lặp EXECUTE -->
98
+ - [ ] 1. Chuyển thư mục task trở lại `active/` (nếu trước đó đã cất vào `backlog/`).
99
+ - [ ] 2. Checkout đúng branch và rebase/merge code mới nhất từ `main` (`git checkout <branch> && git pull --rebase origin main`).
100
+ - [ ] 3. Chạy lệnh kiểm thử gốc (`npm run test && npm run lint`) để đảm bảo codebase đang hoàn toàn xanh.
101
+ - [ ] 4. Kiểm tra độ tươi ngữ cảnh (Context Freshness): Đọc lại `task.md`, `state.md`, và xác nhận các giả thuyết trong `research.md` còn đúng không.
102
+ - [ ] 5. Nếu `<allowed_files>` bị thay đổi trên `main`, cập nhật lại phạm vi trong `plan.md`.
103
+ - [ ] 6. Xóa hoặc lưu trữ `paused.md`, cập nhật lại `state.md` và tiếp tục thực hiện slice đang dở.
104
+ </resumption_checklist>
105
+
106
+ </pause_record>
@@ -6,9 +6,11 @@
6
6
  PHẦN 0 — KIỂM SOÁT TASK (bản lưu vết trạng thái master)
7
7
  ════════════════════════════════════════════ -->
8
8
  <task_control>
9
- <status>BACKLOG</status> <!-- BACKLOG | ACTIVE | BLOCKED | REVIEW | COMPLETED -->
9
+ <status>BACKLOG</status> <!-- BACKLOG | ACTIVE | BLOCKED | PAUSED | REVIEW | COMPLETED | CANCELLED -->
10
10
  <spec_level>S1</spec_level> <!-- S0=phác thảo | S1=đã định nghĩa | S2=đã kiểm chứng | S3=đã khóa -->
11
+ <priority>P2</priority> <!-- P0=khẩn cấp | P1=cao | P2=bình thường | P3=thấp -->
11
12
  <risk>MEDIUM</risk> <!-- LOW | MEDIUM | HIGH -->
13
+ <estimated_story_points>2</estimated_story_points> <!-- 1 SP ≈ 2-4 giờ làm việc kỹ thuật tập trung -->
12
14
  <working_mode>PAIR</working_mode> <!-- MANUAL | PAIR | DELEGATED | DIAGNOSE-ONLY -->
13
15
  <current_phase>RESEARCH</current_phase> <!-- RESEARCH | INNOVATE | PLAN | EXECUTE | REVIEW -->
14
16
  <owner>@engineer</owner>
@@ -63,6 +65,11 @@
63
65
  - `tests/[duong/dan/toi/test]` — [Khẳng định mục tiêu và test fixtures]
64
66
  </target_files>
65
67
 
68
+ <context_groups>
69
+ <!-- Tham chiếu tới các nhóm ngữ cảnh đã đăng ký trong process/context/all-context.md -->
70
+ - [planning | tests | protocols | domain-specific-group]
71
+ </context_groups>
72
+
66
73
  <source_of_truth>
67
74
  <requirement>[Liên kết tới tài liệu yêu cầu hoặc đặc tả]</requirement>
68
75
  <architecture>[Liên kết tới tài liệu kiến trúc hoặc ADR]</architecture>
@@ -154,6 +161,7 @@
154
161
  - [ ] Chạy verifier ngay sau mỗi slice.
155
162
  - [ ] Kiểm tra git diff sau mỗi slice.
156
163
  - [ ] Cập nhật `state.md` sau mỗi slice.
164
+ - [ ] (Tùy chọn) Ghi nhận số liệu định lượng vào `results.tsv` nếu task có đo lường benchmark/hiệu năng.
157
165
  </phase>
158
166
 
159
167
  <phase name="Review" order="5">
@@ -26,7 +26,7 @@
26
26
  <group id="seeds">
27
27
  <title>Cẩm Nang Mẫu Chuẩn & Seeds</title>
28
28
  <path>[`../_seeds/_GUIDE.md`](../_seeds/_GUIDE.md)</path>
29
- <scope>Blueprints mẫu cho task, research, decision, plan, state, review, handoff và program. Đầy đủ chuỗi artifact và lệnh khởi tạo.</scope>
29
+ <scope>Blueprints mẫu cho task, research, decision, plan, state, review, handoff, tạm dừng task, hủy task, benchmark định lượng và program. Đầy đủ chuỗi artifact và lệnh khởi tạo.</scope>
30
30
  </group>
31
31
 
32
32
  <group id="tests">
@@ -1,31 +1,87 @@
1
1
  # Quy Chuẩn Lập Kế Hoạch & Hiệu Chỉnh Năng Lực (Planning Context)
2
2
 
3
- <planning_context version="1.0">
3
+ <planning_context version="2.0">
4
4
 
5
5
  <overview>
6
- Hướng dẫn ước lượng Story Point, phân rã lát cắt dọc và hiệu chỉnh năng lực thực thi.
6
+ Hướng dẫn kỹ thuật về ước lượng Story Point, phân rã lát cắt dọc (Vertical Slicing), điểm hoàn nguyên rollback và hiệu chỉnh năng lực thực thi.
7
7
  </overview>
8
8
 
9
- ## 1. Tiêu Chuẩn Chất Lượng (Quality Standards)
9
+ ---
10
+
11
+ ## 1. Tiêu Chuẩn Chất Lượng (Tiêu Chuẩn INVEST)
12
+
10
13
  <quality_standards>
11
14
  <standard name="INVEST">
12
- - **Độc lập (Independent):** Có thể bàn giao mà không bị chặn bởi các story khác.
13
- - **Thương lượng được (Negotiable):** Chi tiết triển khai có thể tinh chỉnh linh hoạt.
14
- - **Có giá trị (Valuable):** Mang lại giá trị đo lường được cho người dùng hoặc doanh nghiệp.
15
- - **Ước lượng được (Estimable):** Phạm vi đủ rõ để ước lượng khối lượng công việc.
16
- - **Nhỏ gọn (Small):** Hoàn thành vừa vặn trong 1-3 ngày làm việc của kỹ sư.
17
- - **Kiểm chứng được (Testable):** Tiêu chí nghiệm thu (AC) cụ thể, đo lường được.
18
- </standard>
19
-
20
- <standard name="Vertical Slicing (Cắt Lát Dọc)">
21
- Tránh chia việc theo các tầng ngang độc lập (horizontal silos). Bàn giao từng lát cắt dọc hoàn chỉnh xuyên suốt qua API, logic nghiệp vụ và lưu trữ dữ liệu.
15
+ - **Độc lập (Independent):** Có thể bàn giao và kiểm chứng độc lập mà không bị phụ thuộc vòng vo vào story khác.
16
+ - **Thương lượng được (Negotiable):** Chi tiết kỹ thuật và phương án tiếp cận có thể linh hoạt đánh giá trong giai đoạn Innovate.
17
+ - **Có giá trị (Valuable):** Mang lại năng lực hệ thống ràng hoặc tiến bộ kỹ thuật đo lường được.
18
+ - **Ước lượng được (Estimable):** Phạm vi đủ rõ và danh sách file cần sửa đủ hẹp để tính toán khối lượng công việc.
19
+ - **Nhỏ gọn (Small):** Hoàn thành vừa vặn trong 13 ngày làm việc của kỹ sư (hoặc 1–3 Story Points).
20
+ - **Kiểm chứng được (Testable):** Kèm theo các Tiêu chí nghiệm thu (AC) ràng, kiểm chứng được (`- [ ]`).
22
21
  </standard>
23
22
  </quality_standards>
24
23
 
25
- ## 2. Hiệu Chỉnh Năng Lực (Capacity Calibration)
24
+ ---
25
+
26
+ ## 2. Kỷ Luật Cắt Lát Dọc (Vertical Slicing Discipline)
27
+
28
+ <vertical_slicing>
29
+ ### Lát Cắt Dọc (Vertical Slice) vs Tầng Ngang (Horizontal Silo)
30
+ - **Quy tắc Lát Cắt Dọc:** Mỗi lát cắt bắt buộc phải đi xuyên suốt toàn bộ các tầng kỹ thuật cần thiết (ví dụ: Thực thể Domain $\rightarrow$ Service/Logic $\rightarrow$ Port Adapter/API $\rightarrow$ Bài kiểm thử tự động) để mang lại một gia số hành vi hoàn chỉnh, kiểm chứng được.
31
+ - **Phản mẫu Tầng Ngang (Anti-Pattern):** Tuyệt đối không chia việc theo tầng ngang (ví dụ: Slice 1: tạo toàn bộ bảng DB, Slice 2: viết toàn bộ logic service, Slice 3: tạo toàn bộ API endpoint). Các tầng ngang không thể kiểm chứng độc lập, khiến toàn hệ thống ở trạng thái dở dang hoặc không thể chạy test cho đến tận slice cuối cùng.
32
+
33
+ ### Luồng Triển Khai Lát Cắt Dọc Mẫu
34
+ ```text
35
+ [Slice 1: Lõi tối thiểu xuyên suốt] ──► Domain Entity + Repo giả lập bộ nhớ + Endpoint tối thiểu + Test pass
36
+ [Slice 2: Lưu trữ & Ranh giới] ──► Adapter Database thật + File Migration + Kiểm thử tích hợp
37
+ [Slice 3: Trường hợp biên & Xử lý] ──► Chuẩn hóa đầu vào nghiêm ngặt + Bắt lỗi + Test trường hợp biên
38
+ ```
39
+ </vertical_slicing>
40
+
41
+ ---
42
+
43
+ ## 3. Quy Mô Lát Cắt, Khả Năng Kiểm Chứng & Checkpoint
44
+
45
+ <slice_sizing>
46
+ <rule id="slice_cardinality">
47
+ Một task tiêu chuẩn chỉ nên chứa từ **2 đến 5 lát cắt dọc**. Nếu một task đòi hỏi hơn 5 slice, bán kính ảnh hưởng của nó quá lớn và bắt buộc phải phân rã thành Chương trình nhiều giai đoạn (`program-template.md.seed`).
48
+ </rule>
49
+
50
+ <rule id="autonomous_verifier">
51
+ Mỗi slice trong `plan.md` bắt buộc phải có lệnh kiểm chứng `<verifier>` tường minh, tự động chạy được (ví dụ: `npm run test -- test/duong/dan/test.js` hoặc `pytest tests/unit/test_slice.py`). Một slice CHƯA ĐƯỢC COI LÀ XONG nếu lệnh verifier chưa exit với mã 0.
52
+ </rule>
53
+
54
+ <rule id="atomic_checkpoint">
55
+ Commit hoặc đánh dấu checkpoint git sau khi mỗi slice vượt qua verifier. Điều này đảm bảo lịch sử git tinh gọn và cho phép hoàn nguyên ngay lập tức nếu các slice sau gặp lỗi không thể cứu vãn.
56
+ </rule>
57
+ </slice_sizing>
58
+
59
+ ---
60
+
61
+ ## 4. Chiến Lược Hoàn Nguyên (Rollback Strategy) Cho Từng Slice
62
+
63
+ <rollback_strategy>
64
+ Mỗi slice trong `plan.md` BẮT BUỘC phải chỉ định một điểm hoàn nguyên cụ thể `<rollback_point>`:
65
+ - **Checkpoint Git:** `git checkout -- <allowed_files>` hoặc commit hash đảo ngược.
66
+ - **Checkpoint Stash:** `git stash pop` hoặc branch WIP riêng biệt.
67
+ - **Rollback Dữ liệu / Schema:** Script down-migration hoặc xóa container test tạm thời.
68
+
69
+ Nếu Agent cạn kiệt ngân sách thử lại 3 lần cho một slice, Agent phải thực thi rollback point trước khi dừng lại và xin chỉ thị từ con người.
70
+ </rollback_strategy>
71
+
72
+ ---
73
+
74
+ ## 5. Hiệu Chỉnh Năng Lực & Story Point (Capacity Calibration)
75
+
26
76
  <capacity_calibration>
27
- <unit>1 Story Point ≈ 2-4 giờ làm việc kỹ thuật tập trung</unit>
28
- <max_task_size>3-5 Story Points (các task lớn hơn bắt buộc phải phân rã nhỏ hơn)</max_task_size>
77
+ <unit>1 Story Point (SP) ≈ 24 giờ làm việc kỹ thuật tập trung</unit>
78
+ <scale>
79
+ - **1 SP:** Thay đổi thẳng thắn, phạm vi hẹp và rõ ràng (sửa 1-3 files, 1-2 slices).
80
+ - **2 SP:** Tính năng tiêu chuẩn hoặc refactor có phạm vi (sửa 3-5 files, 2-3 slices).
81
+ - **3 SP:** Tác vụ phức tạp vừa phải tác động đến hợp đồng domain và lưu trữ (sửa 4-7 files, 3-4 slices).
82
+ - **5 SP:** Quy mô tối đa cho một task active đơn lẻ trong `process/features/active/`.
83
+ - **> 5 SP:** Quá lớn. Bắt buộc phải tách thành nhiều task độc lập hoặc tổ chức dưới `program-template.md.seed`.
84
+ </scale>
29
85
  </capacity_calibration>
30
86
 
31
87
  </planning_context>