@damphuquy/agent-init 1.4.4 → 2.1.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.
Files changed (31) hide show
  1. package/README.md +10 -4
  2. package/README.vi.md +10 -4
  3. package/package.json +1 -1
  4. package/templates/en/.agents/behavior.md +34 -2
  5. package/templates/en/.agents/guardrails.md +2 -1
  6. package/templates/en/AGENTS.md +15 -8
  7. package/templates/en/process/README.md +14 -10
  8. package/templates/en/process/_seeds/_GUIDE.md +10 -6
  9. package/templates/en/process/_seeds/decision-template.md.seed +7 -6
  10. package/templates/en/process/_seeds/plan-template.md.seed +2 -2
  11. package/templates/en/process/_seeds/review-template.md.seed +1 -1
  12. package/templates/en/process/_seeds/task-template.md.seed +18 -9
  13. package/templates/en/process/context/all-context.md +1 -1
  14. package/templates/en/process/context/planning/all-planning.md +72 -16
  15. package/templates/en/process/context/tests/all-tests.md +87 -30
  16. package/templates/en/process/development-protocols/implementation-standards.md +103 -14
  17. package/templates/en/process/development-protocols/orchestration.md +88 -11
  18. package/templates/vi/.agents/behavior.md +34 -2
  19. package/templates/vi/.agents/guardrails.md +2 -1
  20. package/templates/vi/AGENTS.md +15 -8
  21. package/templates/vi/process/README.md +14 -10
  22. package/templates/vi/process/_seeds/_GUIDE.md +10 -6
  23. package/templates/vi/process/_seeds/decision-template.md.seed +7 -6
  24. package/templates/vi/process/_seeds/plan-template.md.seed +2 -2
  25. package/templates/vi/process/_seeds/review-template.md.seed +1 -1
  26. package/templates/vi/process/_seeds/task-template.md.seed +18 -9
  27. package/templates/vi/process/context/all-context.md +1 -1
  28. package/templates/vi/process/context/planning/all-planning.md +72 -16
  29. package/templates/vi/process/context/tests/all-tests.md +87 -30
  30. package/templates/vi/process/development-protocols/implementation-standards.md +104 -15
  31. package/templates/vi/process/development-protocols/orchestration.md +89 -12
@@ -1,56 +1,113 @@
1
1
  # Testing Standards & Harness Strategy Context
2
2
 
3
- <testing_context version="1.0">
3
+ <testing_context version="2.0">
4
4
 
5
5
  <overview>
6
- Guidelines for test pyramid calibration, isolation policies, mock conventions, and automated verification harness across the system.
6
+ Guidelines for test pyramid calibration, isolation policies, mock conventions, fixture hygiene, and automated verification harness across the system.
7
7
  </overview>
8
8
 
9
- ## 1. Test Pyramid & Classification
9
+ ---
10
+
11
+ ## 1. Test Pyramid & Layer Calibration
12
+
10
13
  <test_pyramid>
11
14
  <layer name="Unit Tests" path="tests/unit/">
12
- - Scope: Pure business logic, domain models, utility functions, edge case branching.
13
- - Execution speed: Fast (< 50ms per test), zero network/disk/external I/O.
14
- - Mock policy: Mock all I/O boundaries, external clients, and port interfaces.
15
+ - **Scope:** Pure domain models, business logic calculations, utility functions, edge-case branching.
16
+ - **Speed & Constraints:** Ultra-fast (< 50ms per test). Zero network calls, zero disk I/O, zero real database connections.
17
+ - **Mocking Policy:** Mock all port interfaces, external clients, and I/O boundaries.
15
18
  </layer>
16
19
 
17
20
  <layer name="Integration Tests" path="tests/integration/">
18
- - Scope: Database persistence, external API client adapters, framework wiring.
19
- - Isolation: Ephemeral test containers (e.g. Testcontainers) or dedicated isolated test database per suite.
20
- - Teardown: Must guarantee zero state leakage across test runs.
21
+ - **Scope:** Repository persistence adapters, database queries, migration scripts, HTTP client wrappers, framework wiring.
22
+ - **Isolation:** Ephemeral test containers (e.g. Testcontainers), in-memory databases, or isolated schema instances per test worker.
23
+ - **Teardown:** Must guarantee 100% state cleanup with zero leakage across test runs.
21
24
  </layer>
22
25
 
23
26
  <layer name="End-to-End Tests" path="tests/e2e/">
24
- - Scope: Critical user journeys, full HTTP/gRPC API lifecycle, regression smoke tests.
25
- - Verification: Validates end-to-end contract integrity across subsystems.
27
+ - **Scope:** Critical user journeys, public API lifecycle, full authentication flows, regression smoke tests.
28
+ - **Verification:** Validates end-to-end contract integrity across the entire system.
26
29
  </layer>
27
30
  </test_pyramid>
28
31
 
29
- ## 2. Test Harness Policies
30
- <test_policies>
31
- <policy name="Determinism">
32
- Zero flaky tests. Tests must not depend on real wall-clock time (use frozen clocks or fake timers) or randomized execution order.
33
- </policy>
32
+ ---
33
+
34
+ ## 2. Mocking Boundaries & Anti-Patterns
35
+
36
+ <mocking_boundaries>
37
+ <rule id="mock_at_architectural_boundary">
38
+ **Mock at the boundaries, never at the core.** Only mock external infrastructure: third-party HTTP APIs, message brokers, email services, or system clock.
39
+ </rule>
40
+
41
+ <rule id="do_not_mock_domain_or_sut">
42
+ Never mock the System Under Test (SUT) or pure domain entities/value objects. If a domain entity is hard to instantiate without mocks, its design is coupled and requires refactoring.
43
+ </rule>
44
+
45
+ <rule id="verify_mock_interactions_sparingly">
46
+ Prefer asserting on return values and observable state changes rather than verifying exact method call counts (`toHaveBeenCalledTimes`), which couples tests to private implementation details.
47
+ </rule>
48
+ </mocking_boundaries>
49
+
50
+ ---
51
+
52
+ ## 3. Test Fixture & Data Factory Hygiene
53
+
54
+ <fixture_hygiene>
55
+ <rule id="data_factories_over_preseeded_db">
56
+ Use explicit test factories (or builder functions) with sensible defaults rather than relying on brittle, shared SQL seed dumps.
57
+ </rule>
58
+
59
+ <rule id="no_shared_mutable_fixtures">
60
+ Every test must instantiate its own data fixtures. Never share mutable state or global test variables between tests.
61
+ </rule>
62
+
63
+ <rule id="deterministic_teardown">
64
+ Always clean up database records, temp files, or mock registries in `afterEach` / `teardown` hooks to prevent cascading cross-test failures.
65
+ </rule>
66
+ </fixture_hygiene>
67
+
68
+ ---
69
+
70
+ ## 4. Determinism & Flaky Test Zero-Tolerance
71
+
72
+ <determinism>
73
+ <rule id="frozen_clock">
74
+ Never use real wall-clock time (`Date.now()`, `datetime.now()`) in time-sensitive assertions. Use frozen clocks or fake timers to ensure absolute reproducibility.
75
+ </rule>
76
+
77
+ <rule id="order_independence">
78
+ Tests must pass when run individually or in random order (`--randomize`). Never rely on one test running before another.
79
+ </rule>
80
+
81
+ <rule id="no_arbitrary_sleeps">
82
+ Never use arbitrary `sleep(1000)` in async tests. Use explicit polling helpers with timeouts (`waitFor`, `eventually`) that resolve as soon as the expected condition is met.
83
+ </rule>
84
+ </determinism>
85
+
86
+ ---
87
+
88
+ ## 5. Assertion Precision & Failure Clarity
89
+
90
+ <assertion_precision>
91
+ <rule id="exact_assertions">
92
+ Avoid vague assertions (e.g. `expect(res).toBeTruthy()`). Always assert exact expected values, HTTP status codes, and error codes.
93
+ </rule>
34
94
 
35
- <policy name="Clean State">
36
- Every test must seed its own data or fixtures. Tests must never assume pre-existing database rows.
37
- </policy>
95
+ <rule id="actionable_failure_messages">
96
+ When custom assertions are used, provide clear error messages indicating what input was given and what specific invariant was violated.
97
+ </rule>
98
+ </assertion_precision>
38
99
 
39
- <policy name="Assertion Precision">
40
- Avoid vague assertions (e.g. `expect(res).toBeTruthy()`). Always assert exact expected structures, status codes, and error types.
41
- </policy>
100
+ ---
42
101
 
43
- <policy name="Fast Feedback">
44
- Unit tests must execute in under 30 seconds for the entire suite. Slow integration suites must be cleanly partitioned.
45
- </policy>
46
- </test_policies>
102
+ ## 6. Verification Commands Mapping
47
103
 
48
- ## 3. Verification Commands Mapping
49
104
  <verification_commands>
50
105
  <!-- Keep aligned with AGENTS.md <validation_commands> -->
51
- <command type="unit">Run fast unit test suite</command>
52
- <command type="integration">Run integration/e2e tests</command>
53
- <command type="coverage">Run test coverage check</command>
106
+ <command type="unit">Run fast unit test suite (< 30 seconds total)</command>
107
+ <command type="integration">Run isolated integration/e2e tests</command>
108
+ <command type="typecheck">Run static type checker (zero errors, strict mode)</command>
109
+ <command type="lint">Run linter and format checker (zero warnings)</command>
110
+ <command type="coverage">Run test coverage report and threshold check</command>
54
111
  </verification_commands>
55
112
 
56
113
  </testing_context>
@@ -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>
@@ -25,9 +25,41 @@ Mọi phản hồi thúc đẩy tiến độ task BẮT BUỘC phải mở đầ
25
25
  Chỉ lược bỏ khai báo mode đối với các trao đổi mang tính đàm thoại thuần túy không
26
26
  làm thay đổi tiến độ task (ví dụ: giải đáp câu hỏi kỹ thuật, làm rõ phạm vi yêu cầu).
27
27
 
28
+ Trong chế độ chạy liên tục (DELEGATED / Fast-Track), Agent mở đầu bằng mode của phase khởi động. Khi hoàn tất một phase và tự động chuyển sang phase tiếp theo trong cùng lượt phản hồi, Agent chèn phân cách chuyển mode rõ ràng:
29
+ `>>> [PHASE TRANSITION: <PHASE_CŨ> -> <PHASE_MỚI>]` và tiếp tục thực thi dưới mode mới ngay lập tức mà không dừng lại.
30
+
31
+ ---
32
+
33
+ ## 2. Chế Độ Làm Việc & Giao Thức Chuyển Giai Đoạn (Working Modes & Transitions)
34
+
35
+ <working_modes_protocol>
36
+ Phương thức làm việc được quy định tại thẻ `<working_mode>` trong `task.md` hoặc qua chỉ thị của người dùng trong prompt:
37
+
38
+ ### Chế độ PAIR (Mặc định — Hợp tác từng bước):
39
+ - Agent thực hiện từng phase một.
40
+ - Khi hoàn thành phase, cập nhật artifact tương ứng và **DỪNG LẠI** để kỹ sư con người kiểm tra, thảo luận và ký duyệt Gate (G1, G2, G3).
41
+ - Chờ người dùng ra lệnh "Bắt đầu phase tiếp theo" mới chuyển `<current_phase>` trong `task.md` và tiếp tục.
42
+
43
+ ### Chế độ DELEGATED (Tự trị / Fast-Track / Skip Permissions):
44
+ - **Điều kiện kích hoạt:** `<working_mode>DELEGATED</working_mode>` trong `task.md` HOẶC người dùng chỉ thị rõ: "fast-track", "skip permissions", "tự động chạy", "chạy hết các phase", "autonomous".
45
+ - **Quy tắc vàng:** **TUYỆT ĐỐI KHÔNG DỪNG LẠI GIỮA CÁC PHASE ĐỂ ĐỢI PROMPT "TIẾP THEO".**
46
+ - **Quy trình tự động chuyển tiếp liên tục:**
47
+ 1. Khi phase hiện tại hoàn thành đủ tiêu chuẩn thoát (exit criteria/checklist), Agent tự động tích chọn `- [x]`.
48
+ 2. Điền thông tin tự động phê duyệt vào artifact: `approved_by: [AUTO: DELEGATED]` kèm ngày giờ và căn cứ kỹ thuật (ở INNOVATE: tự chọn phương án Recommendation tối ưu; ở PLAN: tự khóa hợp đồng phạm vi file).
49
+ 3. Cập nhật ngay `<current_phase>` trong `task.md` sang phase kế tiếp (`RESEARCH` → `INNOVATE` → `PLAN` → `EXECUTE` → `REVIEW`).
50
+ 4. Khởi tạo artifact seed của phase kế tiếp (Copy-On-Demand) và **TIẾP TỤC THỰC THI NGAY LẬP TỨC** trong cùng phiên làm việc.
51
+ - **Điều kiện dừng duy nhất trong DELEGATED:**
52
+ - Task đã hoàn thành 100% (Gate 3 PASS, dọn dẹp housekeeping sạch sẽ, tạo `handoff.md`, chuyển sang `completed/`).
53
+ - HOẶC chạm một trong các Điều Kiện Dừng Khẩn Cấp thực sự (Escalation Triggers trong `guardrails.md`: hết retry budget 3 lần cho cùng 1 lỗi, lệnh phá hủy nguy hiểm, hoặc mâu thuẫn trực tiếp ngoài phạm vi task).
54
+
55
+ ### Chế độ MANUAL & DIAGNOSE-ONLY:
56
+ - `MANUAL`: Người dùng trực tiếp dẫn dắt từng lệnh, Agent chỉ đóng vai trò hỗ trợ cục bộ.
57
+ - `DIAGNOSE-ONLY`: Chỉ chạy Research & Review để chẩn đoán/kiểm toán lỗi mà không chỉnh sửa mã nguồn.
58
+ </working_modes_protocol>
59
+
28
60
  ---
29
61
 
30
- ## 2. Giao Thức Khởi Động Session (Session Startup Protocol)
62
+ ## 3. Giao Thức Khởi Động Session (Session Startup Protocol)
31
63
 
32
64
  Trước khi tiếp tục bất kỳ task đang dang dở nào, nạp lại trạng thái bền vững theo đúng thứ tự sau:
33
65
 
@@ -45,7 +77,7 @@ dựa trên các tệp artifact được liệt kê ở trên.
45
77
 
46
78
  ---
47
79
 
48
- ## 3. Quy Tắc Điều Hướng Ngữ Cảnh (Context Navigation Rules)
80
+ ## 4. Quy Tắc Điều Hướng Ngữ Cảnh (Context Navigation Rules)
49
81
 
50
82
  <context_rules>
51
83
  <rule id="minimum_context">
@@ -39,10 +39,11 @@
39
39
  chưa được khai báo trong kế hoạch đã duyệt.
40
40
  3. Thay đổi cần thiết chạm vào tệp nằm ngoài phạm vi được định nghĩa trong `plan.md`.
41
41
  4. Cần một quyết định nghiệp vụ hoặc chính sách chưa có trong `<approved_decisions>`.
42
+ (Ngoại lệ: Trong chế độ DELEGATED / Fast-Track, Agent được phép tự chọn phương án kỹ thuật được khuyến nghị trong `decision.md` miễn là không vi phạm `<invariants>` hay `<out_of_scope>`).
42
43
  5. Cần mở rộng phạm vi ra ngoài mục `<out_of_scope>` trong `task.md`.
43
44
 
44
45
  Ngoại lệ: KHÔNG dừng nếu thay đổi đã được người dùng ủy quyền rõ ràng
45
- trong prompt/spec, hoặc nếu đó là tệp test đi kèm bắt buộc hay cập nhật import.
46
+ trong prompt/spec (chế độ DELEGATED, fast-track, skip permissions), hoặc nếu đó là tệp test đi kèm bắt buộc hay cập nhật import.
46
47
  </escalation_triggers>
47
48
 
48
49
  ---
@@ -69,6 +69,12 @@
69
69
 
70
70
  <riper5_protocol>
71
71
 
72
+ <!-- ─────────────────── CHẾ ĐỘ VẬN HÀNH (WORKING MODES) ─────────────────── -->
73
+ <working_modes>
74
+ <mode id="PAIR" default="true">Hợp tác từng bước. Dừng lại sau mỗi phase để kỹ sư kiểm tra và ký duyệt Gate tương ứng.</mode>
75
+ <mode id="DELEGATED" alias="fast-track,autonomous,skip-permissions">Ủy quyền tự trị. Khi task.md có working_mode=DELEGATED hoặc người dùng chỉ thị fast-track / skip permissions, Agent tự động nghiệm thu các Gate đạt chuẩn ([AUTO: DELEGATED]), tự động chuyển phase trong task.md và thực thi liên tục qua toàn bộ chu trình RIPER-5 mà KHÔNG dừng lại chờ lệnh "tiếp theo".</mode>
76
+ </working_modes>
77
+
72
78
  <!-- ─────────────────── RÀNG BUỘC TỪNG GIAI ĐOẠN ─────────────────── -->
73
79
 
74
80
  <phase name="RESEARCH" order="1">
@@ -76,15 +82,16 @@
76
82
  <constraint>Không tự ý ra quyết định triển khai.</constraint>
77
83
  <constraint>Không tự ý chọn lựa kiến trúc.</constraint>
78
84
  <output>Tạo/cập nhật `research.md`. Phân loại bằng chứng thành Đã xác nhận (Confirmed) / Quan sát thấy (Observed) / Giả thuyết (Hypothesized).</output>
79
- <gate id="G0">Đánh dấu đạt tất cả Tiêu chí rời khỏi Khảo sát (Research Exit Criteria) trong `research.md` trước khi chuyển tiếp.</gate>
85
+ <gate id="G0">Đánh dấu đạt tất cả Tiêu chí rời khỏi Khảo sát (Research Exit Criteria) trong `research.md` trước khi chuyển tiếp. Ở chế độ DELEGATED / Fast-Track, Agent tự động đánh giá và chuyển sang INNOVATE ngay lập tức.</gate>
80
86
  </phase>
81
87
 
82
88
  <phase name="INNOVATE" order="2">
83
89
  <constraint>CHỈ ĐỌC (READ-ONLY). Không chỉnh sửa mã nguồn.</constraint>
84
- <constraint>Đề xuất 2–3 phương án khả thi kèm ma trận đánh đổi (Trade-off). KHÔNG tự ý đơn phương quyết định.</constraint>
85
- <constraint>Tuyệt đối không tự ý quyết định Public API / DB schema / chính sách bảo mật / quy tắc nghiệp vụ khi chưa có sự phê duyệt của con người.</constraint>
86
- <output>Tạo `decision.md`. Để trống phần `<engineer_decision>` kỹ sẽ điền phần này.</output>
87
- <gate id="G1">Gate 1 trong `decision.md` phải được kỹ sư kiểm tra và ký duyệt trước khi chuyển sang Plan.</gate>
90
+ <constraint>Đề xuất 2–3 phương án khả thi kèm ma trận đánh đổi (Trade-off).</constraint>
91
+ <constraint>Chế độ PAIR: Để trống phần `<engineer_decision>` kỹ sẽ kiểm tra điền phần này.</constraint>
92
+ <constraint>Chế độ DELEGATED / Fast-Track: Tự động chọn phương án khuyến nghị (Recommendation), ghi rõ rationale với `[AUTO: DELEGATED]`, tự duyệt Gate 1 chuyển tiếp ngay sang PLAN.</constraint>
93
+ <output>Tạo `decision.md`.</output>
94
+ <gate id="G1">Gate 1 trong `decision.md` được kỹ sư ký duyệt (chế độ PAIR) hoặc tự động ký duyệt bởi Agent với `[AUTO: DELEGATED]` (chế độ DELEGATED / Fast-Track) trước khi chuyển sang Plan.</gate>
88
95
  </phase>
89
96
 
90
97
  <phase name="PLAN" order="3">
@@ -92,7 +99,7 @@
92
99
  <constraint>Mỗi lát cắt (slice) phải có công cụ kiểm chứng (verifier), bằng chứng kỳ vọng và điểm hoàn nguyên (rollback point).</constraint>
93
100
  <constraint>Hợp đồng phạm vi (danh sách file được phép / cấm sửa) phải tường minh.</constraint>
94
101
  <output>Tạo `plan.md`. Điền sẵn các tiêu đề của Ma trận Kiểm chứng (Verification Matrix).</output>
95
- <gate id="G2">Gate 2 trong `plan.md` phải được kỹ sư kiểm tra ký duyệt trước khi chuyển sang Execute.</gate>
102
+ <gate id="G2">Gate 2 trong `plan.md` được kỹ sư duyệt (chế độ PAIR) hoặc tự động ký duyệt bởi Agent với `[AUTO: DELEGATED]` (chế độ DELEGATED / Fast-Track) trước khi chuyển sang Execute.</gate>
96
103
  </phase>
97
104
 
98
105
  <phase name="EXECUTE" order="4">
@@ -100,7 +107,7 @@
100
107
  <constraint>Thực hiện từng lát cắt một. Chạy verifier sau mỗi slice. Kiểm tra diff sau mỗi slice.</constraint>
101
108
  <constraint>Không refactor lan man. Không sửa các file bị cấm.</constraint>
102
109
  <constraint>Cập nhật `state.md` ngay sau mỗi slice hoàn thành.</constraint>
103
- <output>Mã nguồn + kiểm thử + cập nhật `state.md` kèm bằng chứng kiểm chứng.</output>
110
+ <output>Mã nguồn + kiểm thử + cập nhật `state.md` kèm bằng chứng kiểm chứng. Khi hoàn tất toàn bộ lát cắt, tự động chuyển ngay sang REVIEW.</output>
104
111
  </phase>
105
112
 
106
113
  <phase name="REVIEW" order="5">
@@ -108,7 +115,7 @@
108
115
  <constraint>Không sửa mã nguồn trong lúc review. Ghi nhận các phát hiện vào `review.md`.</constraint>
109
116
  <constraint>Bao quát: hành vi (behavior), kiến trúc (architecture), dữ liệu (data), bảo mật (security), hồi quy (regression).</constraint>
110
117
  <output>Tạo `review.md` với các phát hiện được phân loại theo danh mục/mức độ/loại và checklist Gate 3.</output>
111
- <gate id="G3">Gate 3 trong `review.md` phải được ký duyệt trước khi bàn giao. Quyết định review phải là PASS.</gate>
118
+ <gate id="G3">Gate 3 trong `review.md` phải được ký duyệt trước khi bàn giao. Quyết định review phải là PASS. Ở chế độ DELEGATED, Agent tự động kiểm toán toàn diện, tạo `handoff.md`, chuyển task sang `completed/` và báo cáo hoàn thành.</gate>
112
119
  </phase>
113
120
 
114
121
  <!-- Quy tắc hành vi (khai báo mode, retry, escalation, cổng hoàn thành) →
@@ -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
@@ -69,16 +71,16 @@ flowchart TD
69
71
  Task --> Res["research.md"] --> G0{"Gate G0 (Tự động)"}
70
72
  end
71
73
  subgraph I2["2. INNOVATE (Chỉ đọc)"]
72
- G0 --> Dec["decision.md (2-3 Phương án)"] --> G1{"Gate G1 (Kỹ sư duyệt)"}
74
+ G0 --> Dec["decision.md (2-3 Phương án)"] --> G1{"Gate G1 (Kỹ sư hoặc Auto-DELEGATED)"}
73
75
  end
74
76
  subgraph P3["3. PLAN (Chỉ lập kế hoạch)"]
75
- G1 --> Plan["plan.md (Lát cắt dọc)"] --> G2{"Gate G2 (Kỹ sư duyệt)"}
77
+ G1 --> Plan["plan.md (Lát cắt dọc)"] --> G2{"Gate G2 (Kỹ sư hoặc Auto-DELEGATED)"}
76
78
  end
77
79
  subgraph E4["4. EXECUTE (Đọc/Ghi theo phạm vi)"]
78
80
  G2 --> Code["Thực thi từng Slice"] --> Test["Chạy Verifiers"] --> State["state.md (Bộ nhớ)"]
79
81
  end
80
82
  subgraph R5["5. REVIEW (Chỉ đọc)"]
81
- State --> Rev["review.md (Kiểm toán diff)"] --> G3{"Gate G3 (Kỹ sư duyệt)"}
83
+ State --> Rev["review.md (Kiểm toán diff)"] --> G3{"Gate G3 (Kỹ sư hoặc Auto-DELEGATED)"}
82
84
  end
83
85
  subgraph Done["6. HOÀN THÀNH"]
84
86
  G3 --> Arch["Chuyển sang completed/"] --> Handoff["handoff.md"]
@@ -88,10 +90,10 @@ flowchart TD
88
90
  ```text
89
91
  task.md ← (luôn có) Hợp đồng master, trạng thái RIPER phase/gate, AC, decisions
90
92
  research.md ← (Research) Luồng thực thi, bằng chứng, ranh giới hệ thống
91
- decision.md ← (Innovate) Các phương án, bảng đánh đổi, Gate 1 kỹ bắt buộc duyệt
92
- plan.md ← (Plan) Các lát cắt, verifiers, hợp đồng phạm vi, Gate 2 kỹ sư duyệt
93
+ decision.md ← (Innovate) Các phương án, bảng đánh đổi, Gate 1 (Kỹduyệt hoặc Auto-DELEGATED)
94
+ plan.md ← (Plan) Các lát cắt, verifiers, hợp đồng phạm vi, Gate 2 (Kỹ sư duyệt hoặc Auto-DELEGATED)
93
95
  state.md ← (Execute) Tiến độ từng slice, bộ nhớ lỗi, ngân sách thử lại
94
- review.md ← (Review) Phát hiện kiểm toán, ma trận kiểm chứng, Gate 3
96
+ review.md ← (Review) Phát hiện kiểm toán, ma trận kiểm chứng, Gate 3 (PASS)
95
97
  handoff.md ← (Complete) Tóm tắt bàn giao ngắn gọn
96
98
  ```
97
99
 
@@ -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` |
@@ -126,14 +130,14 @@ handoff.md ← (Complete) Tóm tắt bàn giao ngắn gọn
126
130
  </phase>
127
131
 
128
132
  <phase order="2" name="Innovate">
129
- CHỈ ĐỌC. Đề xuất 2–3 phương án kèm ma trận đánh đổi. Không tự ý đơn phương quyết định.
130
- Tạo `decision.md`. Kỹ sư phê duyệt Gate 1.
133
+ CHỈ ĐỌC. Đề xuất 2–3 phương án kèm ma trận đánh đổi.
134
+ Tạo `decision.md`. Gate 1: Kỹ sư phê duyệt (chế độ PAIR) hoặc Agent tự chọn phương án tối ưu [AUTO: DELEGATED] (chế độ DELEGATED/Fast-Track).
131
135
  </phase>
132
136
 
133
137
  <phase order="3" name="Plan">
134
138
  Chỉ tạo/sửa artifact kế hoạch — không sửa mã nguồn.
135
139
  Phân rã thành các lát cắt dọc (vertical slices) kèm verifiers, điểm hoàn nguyên và hợp đồng phạm vi.
136
- Tạo `plan.md`. Kỹ sư phê duyệt Gate 2.
140
+ Tạo `plan.md`. Gate 2: Kỹ sư phê duyệt (chế độ PAIR) hoặc Agent tự động khóa hợp đồng lát cắt [AUTO: DELEGATED] (chế độ DELEGATED/Fast-Track).
137
141
  </phase>
138
142
 
139
143
  <phase order="4" name="Execute">
@@ -143,7 +147,7 @@ handoff.md ← (Complete) Tóm tắt bàn giao ngắn gọn
143
147
 
144
148
  <phase order="5" name="Review">
145
149
  CHỈ ĐỌC. Có thể chạy các lệnh kiểm thử xác minh. Không sửa mã nguồn.
146
- Tạo `review.md` kèm các phát hiện. Gate 3 phải PASS trước khi bàn giao.
150
+ Tạo `review.md` kèm các phát hiện. Gate 3: Phải PASS trước khi bàn giao. Ở chế độ DELEGATED, Agent tự động hoàn tất dọn dẹp housekeeping và tạo `handoff.md`.
147
151
  </phase>
148
152
  </operational_phases>
149
153