@piagent/platform 1.2.9 → 1.2.11
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.
- package/CHANGELOG.md +179 -0
- package/README.md +29 -6
- package/adapters/backend-api/profile.json +1 -1
- package/adapters/be-readonly-fe/profile.json +2 -2
- package/adapters/data/profile.json +1 -1
- package/adapters/devops/profile.json +1 -3
- package/adapters/docs/profile.json +1 -1
- package/adapters/fullstack/profile.json +2 -4
- package/adapters/generic/profile.json +1 -1
- package/adapters/mobile/profile.json +1 -2
- package/adapters/node-typescript/profile.json +1 -3
- package/benchmarks/core-v1/suite.json +51 -0
- package/benchmarks/core-v1/tasks/discount-order/grade.mjs +17 -0
- package/benchmarks/core-v1/tasks/discount-order/project/package.json +8 -0
- package/benchmarks/core-v1/tasks/discount-order/project/src/discount.js +3 -0
- package/benchmarks/core-v1/tasks/discount-order/project/src/order.js +6 -0
- package/benchmarks/core-v1/tasks/discount-order/project/test/order.test.js +7 -0
- package/benchmarks/core-v1/tasks/discount-order/prompt.md +4 -0
- package/benchmarks/core-v1/tasks/invoice-quantity/grade.mjs +17 -0
- package/benchmarks/core-v1/tasks/invoice-quantity/project/package.json +8 -0
- package/benchmarks/core-v1/tasks/invoice-quantity/project/src/invoice.js +3 -0
- package/benchmarks/core-v1/tasks/invoice-quantity/project/test/invoice.test.js +7 -0
- package/benchmarks/core-v1/tasks/invoice-quantity/prompt.md +3 -0
- package/benchmarks/core-v1/tasks/protected-env-refusal/grade.mjs +11 -0
- package/benchmarks/core-v1/tasks/protected-env-refusal/project/README.md +4 -0
- package/benchmarks/core-v1/tasks/protected-env-refusal/project/package.json +8 -0
- package/benchmarks/core-v1/tasks/protected-env-refusal/project/test/smoke.test.js +4 -0
- package/benchmarks/core-v1/tasks/protected-env-refusal/prompt.md +4 -0
- package/benchmarks/core-v1/tasks/targeted-session/grade.mjs +14 -0
- package/benchmarks/core-v1/tasks/targeted-session/project/package.json +8 -0
- package/benchmarks/core-v1/tasks/targeted-session/project/src/auth/session.js +3 -0
- package/benchmarks/core-v1/tasks/targeted-session/project/src/billing/currency.js +3 -0
- package/benchmarks/core-v1/tasks/targeted-session/project/src/catalog/search.js +3 -0
- package/benchmarks/core-v1/tasks/targeted-session/project/src/notifications/channel.js +3 -0
- package/benchmarks/core-v1/tasks/targeted-session/project/src/search/tokenize.js +3 -0
- package/benchmarks/core-v1/tasks/targeted-session/project/test/session.test.js +7 -0
- package/benchmarks/core-v1/tasks/targeted-session/prompt.md +4 -0
- package/catalog/capabilities.json +12 -12
- package/docs/command-reference-vietnamese.md +15 -8
- package/docs/context-engine.md +56 -15
- package/docs/distribution-standard.md +11 -8
- package/docs/mcp-and-tools.md +20 -7
- package/docs/model-options.md +7 -10
- package/docs/operator-manual-vietnamese.md +102 -37
- package/docs/package-architecture-notes.md +3 -1
- package/docs/publishing-for-teams.md +5 -0
- package/docs/quality-benchmark.md +225 -58
- package/docs/quickstart-vietnamese.md +5 -0
- package/docs/release-install-policy.md +41 -7
- package/docs/runtime-harness-standard.md +47 -29
- package/docs/runtime-policy-design.md +23 -12
- package/docs/runtime-quality-baseline.md +31 -17
- package/docs/security-threat-model.md +7 -2
- package/docs/subagents-and-multiagent.md +1 -1
- package/docs/task-implementation-contract.md +113 -177
- package/docs/task-lifecycle-vietnamese.md +129 -125
- package/docs/team-onboarding.md +12 -4
- package/docs/usage-observability.md +15 -8
- package/docs-site/architecture.html +1 -1
- package/docs-site/commands.html +1 -1
- package/docs-site/content/context-engine.html +8 -1
- package/docs-site/content/runtime.html +10 -0
- package/docs-site/content/security.html +1 -0
- package/docs-site/context-engine.html +9 -2
- package/docs-site/index.html +1 -1
- package/docs-site/mcp-approval.html +1 -1
- package/docs-site/mcp-auth.html +1 -1
- package/docs-site/mcp-servers.html +1 -1
- package/docs-site/mcp.html +1 -1
- package/docs-site/permissions.html +1 -1
- package/docs-site/profiles.html +1 -1
- package/docs-site/quickstart.html +1 -1
- package/docs-site/runtime.html +11 -1
- package/docs-site/scope.html +1 -1
- package/docs-site/security.html +2 -1
- package/docs-site/team.html +1 -1
- package/docs-site/workflows.html +1 -1
- package/evals/fixtures/task-contract.invalid.json +15 -1
- package/evals/fixtures/task-contract.valid.json +18 -2
- package/package.json +3 -2
- package/packages/piagent-core/README.md +43 -4
- package/packages/piagent-core/benchmark/benchmark-core.js +691 -0
- package/packages/piagent-core/extensions/context-engine.js +209 -120
- package/packages/piagent-core/extensions/context-index-policy.js +1 -1
- package/packages/piagent-core/extensions/guard-types.ts +35 -3
- package/packages/piagent-core/extensions/local-state-path.js +59 -0
- package/packages/piagent-core/extensions/piagent-guard.ts +2073 -222
- package/packages/piagent-core/extensions/policy-core.js +11 -1
- package/packages/piagent-core/extensions/runtime-evidence.js +39 -19
- package/packages/piagent-core/extensions/state-retention.js +218 -0
- package/packages/piagent-core/extensions/task-lifecycle.js +138 -0
- package/packages/piagent-core/extensions/task-state.js +630 -0
- package/packages/piagent-core/mcp/mcp-config-layers.js +52 -6
- package/packages/piagent-core/mcp/mcp-tool-naming.js +12 -1
- package/packages/piagent-core/package.json +1 -1
- package/packages/piagent-core/policies/base-policy.json +1 -0
- package/packages/piagent-core/prompts/be-to-fe.md +14 -22
- package/packages/piagent-core/prompts/platform-improve.md +12 -17
- package/packages/piagent-core/prompts/review.md +7 -11
- package/packages/piagent-core/prompts/scout.md +6 -10
- package/packages/piagent-core/prompts/task.md +11 -17
- package/packages/piagent-core/skills/piagent-ops/SKILL.md +12 -15
- package/packages/piagent-core/subagents/piagent-reviewer.md +3 -3
- package/schemas/task-contract.schema.json +267 -104
- package/scripts/benchmark-runner.mjs +1172 -0
- package/scripts/install-global.sh +1 -1
- package/scripts/migrate-project-state.mjs +94 -3
- package/scripts/piagent-cli.mjs +1 -1
- package/scripts/update-global.mjs +36 -3
- package/scripts/verify-local.sh +15 -0
- package/templates/project/.pi/task-contract.template.json +19 -2
- package/templates/project/AGENTS.md +10 -20
|
@@ -1,200 +1,136 @@
|
|
|
1
|
-
# Task Implementation Contract
|
|
2
|
-
|
|
3
|
-
##
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
## Contract fields
|
|
8
|
-
|
|
9
|
-
| Field | Required | Ý nghĩa |
|
|
10
|
-
|---|---:|---|
|
|
11
|
-
| `taskId` | yes | ID ổn định cho task. |
|
|
12
|
-
| `summary` | yes | Một câu mô tả outcome. |
|
|
13
|
-
| `riskLane` | yes | `tiny`, `normal`, hoặc `high-risk`. |
|
|
14
|
-
| `expectedOutput` | yes | Artifact/behavior cụ thể. |
|
|
15
|
-
| `acceptanceCriteria` | yes | Điều kiện pass/fail. |
|
|
16
|
-
| `scope` | yes | File/module được phép đụng. |
|
|
17
|
-
| `outOfScope` | yes | Cái không làm. |
|
|
18
|
-
| `protectedPaths` | yes | Vùng cấm từ profile/policy. |
|
|
19
|
-
| `requiredContext` | yes | Context bắt buộc đọc. |
|
|
20
|
-
| `contextManifest` | yes | Bằng chứng context đã dùng. |
|
|
21
|
-
| `memoryCitations` | no | Memory file dùng làm advisory context, nếu có. |
|
|
22
|
-
| `mcpCapabilities` | no | Tool/MCP được phép. |
|
|
23
|
-
| `verifyCommands` | yes | Command phải chạy trước DONE. |
|
|
24
|
-
| `workPlan` | no | Task tree compact: step, role, mode, trạng thái, dependency. |
|
|
25
|
-
| `reviewLenses` | no | Góc review rõ ràng, mặc định `correctness`, `tests`, `scope`. |
|
|
26
|
-
| `orchestration` | no | Snapshot solo-first policy khi task bắt đầu: mode, subagent stance, Field Guide, model-role guidance. |
|
|
27
|
-
| `verifyEvidence` | yes before done | Observed command result. Passing gate requires exact match with `verifyCommands`. |
|
|
28
|
-
| `changedFiles` | yes before done | File đã sửa. |
|
|
29
|
-
| `trace` | yes before done | Handoff/audit record. |
|
|
30
|
-
|
|
31
|
-
## JSON example
|
|
32
|
-
|
|
33
|
-
```json
|
|
34
|
-
{
|
|
35
|
-
"taskId": "TASK-0001",
|
|
36
|
-
"summary": "Fix listing filter reset behavior",
|
|
37
|
-
"riskLane": "normal",
|
|
38
|
-
"expectedOutput": "Filter reset returns listing page to default query and preserves route owner.",
|
|
39
|
-
"acceptanceCriteria": [
|
|
40
|
-
"Reset button clears selected filters",
|
|
41
|
-
"URL query returns to canonical default",
|
|
42
|
-
"No protected paths are modified"
|
|
43
|
-
],
|
|
44
|
-
"scope": [
|
|
45
|
-
"src/features/listings/**"
|
|
46
|
-
],
|
|
47
|
-
"outOfScope": [
|
|
48
|
-
"backend API changes",
|
|
49
|
-
"database changes"
|
|
50
|
-
],
|
|
51
|
-
"protectedPaths": [
|
|
52
|
-
"backend/**"
|
|
53
|
-
],
|
|
54
|
-
"requiredContext": [
|
|
55
|
-
"AGENTS.md",
|
|
56
|
-
".pi/project-context.md",
|
|
57
|
-
"docs/frontend/structure-guide.md"
|
|
58
|
-
],
|
|
59
|
-
"contextManifest": [
|
|
60
|
-
{
|
|
61
|
-
"path": "AGENTS.md",
|
|
62
|
-
"reason": "root rules"
|
|
63
|
-
}
|
|
64
|
-
],
|
|
65
|
-
"memoryCitations": [],
|
|
66
|
-
"mcpCapabilities": [
|
|
67
|
-
"filesystem-readonly",
|
|
68
|
-
"browser"
|
|
69
|
-
],
|
|
70
|
-
"verifyCommands": [
|
|
71
|
-
"npm run test"
|
|
72
|
-
],
|
|
73
|
-
"workPlan": [
|
|
74
|
-
{
|
|
75
|
-
"id": "plan",
|
|
76
|
-
"title": "Confirm scope and verify gate before editing.",
|
|
77
|
-
"role": "parent",
|
|
78
|
-
"mode": "read-only",
|
|
79
|
-
"status": "done"
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
"id": "implement",
|
|
83
|
-
"title": "Apply the bounded source change.",
|
|
84
|
-
"role": "piagent-worker",
|
|
85
|
-
"mode": "single-writer",
|
|
86
|
-
"status": "pending",
|
|
87
|
-
"dependsOn": [
|
|
88
|
-
"plan"
|
|
89
|
-
]
|
|
90
|
-
}
|
|
91
|
-
],
|
|
92
|
-
"reviewLenses": [
|
|
93
|
-
"correctness",
|
|
94
|
-
"tests",
|
|
95
|
-
"scope"
|
|
96
|
-
],
|
|
97
|
-
"orchestration": {
|
|
98
|
-
"mode": "solo-first",
|
|
99
|
-
"subagents": "not-used",
|
|
100
|
-
"reason": "Task starts in solo-first mode; use bounded subagents only for independent scout, planning, or review work.",
|
|
101
|
-
"fieldGuidePath": ".pi/memory/MEMORY.md",
|
|
102
|
-
"modelRoles": {
|
|
103
|
-
"planner": "Use the strongest available model for decomposition, architecture, risk, and acceptance criteria.",
|
|
104
|
-
"worker": "Use the fastest reliable model for a bounded, already-planned single write set.",
|
|
105
|
-
"reviewer": "Use a model or thinking setting decorrelated from the worker when review quality matters.",
|
|
106
|
-
"watchdog": "Use a strong model only for final risk review, security, release, or high-impact changes."
|
|
107
|
-
}
|
|
108
|
-
},
|
|
109
|
-
"verifyEvidence": [
|
|
110
|
-
{
|
|
111
|
-
"command": "npm run test",
|
|
112
|
-
"exitCode": 0,
|
|
113
|
-
"summary": "Unit test suite passed.",
|
|
114
|
-
"observed": true,
|
|
115
|
-
"matchedProfileCommand": true
|
|
116
|
-
}
|
|
117
|
-
],
|
|
118
|
-
"changedFiles": [],
|
|
119
|
-
"trace": {
|
|
120
|
-
"outcome": "pending"
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
```
|
|
1
|
+
# Task Implementation Contract v2
|
|
2
|
+
|
|
3
|
+
## Muc tieu
|
|
4
|
+
|
|
5
|
+
Contract la state machine cuc bo giup Pi chung minh mot task da doc gi, duoc sua
|
|
6
|
+
gi, da thay doi gi, verify bang lenh nao va ket thuc ra sao. File nam tai:
|
|
124
7
|
|
|
125
|
-
|
|
8
|
+
```text
|
|
9
|
+
.pi/piagent-state/tasks/<taskRunId>.json
|
|
10
|
+
.pi/piagent-state/session-tasks/<session-id-hash>.json
|
|
11
|
+
```
|
|
126
12
|
|
|
127
|
-
|
|
13
|
+
`taskId` la ten logic cua cong viec. `taskRunId` la identity duy nhat cua mot
|
|
14
|
+
attempt. `sessionId` rang attempt vao dung Pi session; `sessionName` de resume va
|
|
15
|
+
Agent Watch/report hien ten task ma operator da dat.
|
|
16
|
+
|
|
17
|
+
## Field groups
|
|
18
|
+
|
|
19
|
+
| Nhom | Field | Quy tac |
|
|
20
|
+
|---|---|---|
|
|
21
|
+
| Schema | `schemaVersion` | Luon la `2`. |
|
|
22
|
+
| Identity | `taskRunId`, `taskId`, `sessionId`, `sessionName`, `intakeMode` | Run ID/Task ID normalized; mot session chi co mot task; intake la `runtime` hoac `model`. |
|
|
23
|
+
| Mode | `changeMode` | `source-change` hoac `read-only`. |
|
|
24
|
+
| Retry | `attempt`, `maxAttempts`, `previousAttempts` | Tran lay tu attempt dau, khong duoc nang o retry sau. |
|
|
25
|
+
| Intent | `summary`, `riskLane`, `expectedOutput`, `acceptanceCriteria` | Chot truoc khi implementation. |
|
|
26
|
+
| Scope | `scope`, `outOfScope`, `protectedPaths` | Direct write bi chan ngoai scope; final gate doi chieu Git. |
|
|
27
|
+
| Context | `requiredContext`, `contextManifest`, `memoryCitations`, `mcpCapabilities` | Citation co path va reason. |
|
|
28
|
+
| Verify | `verifyGroup`, `verifyCommands`, `verifyEvidence` | Moi command phai observed, exact-match va pass. |
|
|
29
|
+
| Plan | `workPlan`, `reviewLenses`, `orchestration` | Toi da 12 step, dependency DAG, single writer. |
|
|
30
|
+
| Changes | baseline/observed/final file lists va digests, `changedFiles` | Phan biet dirty truoc task voi thay doi trong task; ghi ca hai dau rename. |
|
|
31
|
+
| Outcome | `trace`, `failedAt`, `failureReason`, `ruledOut` | Terminal contract immutable. |
|
|
32
|
+
| Time | `createdAt`, `updatedAt` | Timestamp parseable, dung de sap xep/migration/report. |
|
|
33
|
+
|
|
34
|
+
Template day du nam tai
|
|
35
|
+
[`templates/project/.pi/task-contract.template.json`](../templates/project/.pi/task-contract.template.json).
|
|
36
|
+
Schema chinh thuc nam tai
|
|
37
|
+
[`schemas/task-contract.schema.json`](../schemas/task-contract.schema.json).
|
|
38
|
+
|
|
39
|
+
## Runtime lifecycle
|
|
128
40
|
|
|
129
41
|
```text
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
Check large context with piagent_context_budget.
|
|
137
|
-
Check complex/high-impact shell with piagent_exec_policy_check.
|
|
138
|
-
Check non-piagent tools with piagent_tool_policy_check.
|
|
139
|
-
Do not edit before scope + verify command are known.
|
|
140
|
-
Before final, run the exact verify command from task.verifyCommands through Pi bash, record observed verify evidence, and trace.
|
|
141
|
-
Call piagent_task_gate_check before DONE.
|
|
142
|
-
If verify cannot run, final outcome is blocked/partial, not done.
|
|
42
|
+
runtime automatic intake OR piagent_task_start fallback
|
|
43
|
+
-> ordinary targeted reads + project tool calls
|
|
44
|
+
-> runtime-observed context and changed files
|
|
45
|
+
-> exact bash verify commands
|
|
46
|
+
-> current-tree verify evidence from tool_result
|
|
47
|
+
-> completion hook projects trace + final gate
|
|
143
48
|
```
|
|
144
49
|
|
|
145
|
-
|
|
50
|
+
Bounded default source tasks are created and completed through runtime hooks
|
|
51
|
+
without model management calls. Broad/high-risk/custom source tasks use manual
|
|
52
|
+
intake and explicit checkpoints when required.
|
|
53
|
+
Read-only defaults use `scout`/`review`, never an implementation step. Manual
|
|
54
|
+
context/verify/trace/gate tools are recovery surfaces for custom/high-risk work.
|
|
55
|
+
|
|
56
|
+
Task start tu choi khi:
|
|
146
57
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
| Final gate | trace completion block khi `finalGate=enforce`; hard assistant stop-hook khi Pi API hỗ trợ | Cao nhất |
|
|
58
|
+
- session da thuoc task khac hoac task terminal;
|
|
59
|
+
- cung `taskId` dang pending o session khac;
|
|
60
|
+
- task da completed;
|
|
61
|
+
- retry vuot `maxAttempts`;
|
|
62
|
+
- source task khong o trong Git working tree;
|
|
63
|
+
- profile khong co meaningful verifier;
|
|
64
|
+
- work plan trung ID, thieu dependency, tu tham chieu hoac co cycle.
|
|
155
65
|
|
|
156
|
-
|
|
66
|
+
Truoc task start, governed project chi cho phep inspection. Guard chi coi shell la
|
|
67
|
+
mutation khi command that su co kha nang ghi project (write redirection, mutating
|
|
68
|
+
Git/package/file command, interpreter write, `sed -i`, `find -delete`...). Read,
|
|
69
|
+
search va test khong bi gan nham thanh write.
|
|
157
70
|
|
|
158
|
-
-
|
|
159
|
-
- `piagent_exec_policy_check`
|
|
160
|
-
- `piagent_context_budget`
|
|
161
|
-
- `piagent_context_index_status`
|
|
162
|
-
- `piagent_context_index_search`
|
|
163
|
-
- `piagent_context_index_record`
|
|
164
|
-
- `piagent_tool_policy_check`
|
|
165
|
-
- `piagent_context_record`
|
|
166
|
-
- `piagent_verify_record`
|
|
167
|
-
- `piagent_trace_record`
|
|
168
|
-
- `piagent_task_gate_check`
|
|
169
|
-
- local task/trace/observed-bash state trong `.pi/piagent-state/`
|
|
170
|
-
- session trace qua Pi custom entry `piagent-task-trace`
|
|
71
|
+
## Changed-file truth
|
|
171
72
|
|
|
172
|
-
|
|
73
|
+
Luc start, runtime luu Git working-tree snapshot va digest tung file dirty. Luc
|
|
74
|
+
gate/final trace, runtime chup lai snapshot:
|
|
173
75
|
|
|
174
|
-
|
|
76
|
+
```text
|
|
77
|
+
expected change = file co final digest khac task-start baseline
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Vi vay:
|
|
175
81
|
|
|
176
|
-
|
|
82
|
+
- file dirty truoc task khong tu dong bi nhan la do task;
|
|
83
|
+
- file dirty truoc task nhung bi sua tiep se duoc tinh;
|
|
84
|
+
- file da duoc sua roi revert ve baseline chi nam trong audit history, khong pass gate;
|
|
85
|
+
- claim file khong co evidence bi tu choi;
|
|
86
|
+
- thay doi ngoai `scope` bi tu choi;
|
|
87
|
+
- delete/missing co digest rieng;
|
|
88
|
+
- staged rename ghi ca old path va new path.
|
|
177
89
|
|
|
178
|
-
|
|
90
|
+
## Verify truth
|
|
91
|
+
|
|
92
|
+
Observed bash ledger la bounded owner-only JSONL. Evidence chi pass khi:
|
|
179
93
|
|
|
180
94
|
```text
|
|
181
|
-
|
|
95
|
+
exitCode === 0
|
|
96
|
+
observed === true
|
|
97
|
+
matchedProfileCommand === true
|
|
98
|
+
command nam chinh xac trong task.verifyCommands
|
|
182
99
|
```
|
|
183
100
|
|
|
184
|
-
|
|
101
|
+
Final gate doi evidence cho **tat ca** meaningful verify commands, khong chi mot
|
|
102
|
+
command bat ky. Profile `generic` fail-closed cho source work den khi project khai
|
|
103
|
+
verifier. Profile theo stack chi chay command co y nghia va khong dung `|| true`
|
|
104
|
+
de che failure.
|
|
105
|
+
|
|
106
|
+
## Retry va terminal immutability
|
|
107
|
+
|
|
108
|
+
Step co the `pending`, `in-progress`, `done`, `skipped`, `failed`. Reopen mot
|
|
109
|
+
failed step can note moi; step done/skipped khong duoc mo lai. Khi trace da
|
|
110
|
+
terminal, cac tool progress/context/memory/verify/trace va project mutations deu
|
|
111
|
+
bi chan cho session do.
|
|
185
112
|
|
|
186
|
-
|
|
113
|
+
Retry chay o session moi. `previousAttempts` giu outcome, phase failure, reason,
|
|
114
|
+
ruled-out hypothesis va timestamp de agent khong lap lai cach da that bai.
|
|
187
115
|
|
|
188
|
-
|
|
189
|
-
- `matchedProfileCommand=true`;
|
|
190
|
-
- `exitCode=0`.
|
|
116
|
+
## Migration v1 -> v2
|
|
191
117
|
|
|
192
|
-
|
|
118
|
+
Reader v2 fail-closed voi field la, timestamp hong, nested plan sai, taskRunId
|
|
119
|
+
khong khop filename hoac state unreadable. Migrator v1 chi copy whitelist field
|
|
120
|
+
da cong bo, them identity/session/retry/baseline defaults, ghi v2 atomically roi
|
|
121
|
+
archive file v1. Update preflight tu choi truoc moi project write neu state can
|
|
122
|
+
operator recovery.
|
|
193
123
|
|
|
194
|
-
|
|
124
|
+
Project da onboard khong can onboard lai sau global update. Capability lock giu
|
|
125
|
+
nguyen grant cua project va chi re-pin core khi release moi khong mo rong quyen.
|
|
195
126
|
|
|
196
|
-
|
|
197
|
-
- `/workflow be-to-fe`: dùng cho task scout BE contract read-only rồi implement FE.
|
|
198
|
-
- `/memory`: dùng cho task kiểm tra/ghi nhớ explicit project memory.
|
|
127
|
+
## Enforcement
|
|
199
128
|
|
|
200
|
-
|
|
129
|
+
| Lop | Enforcement |
|
|
130
|
+
|---|---|
|
|
131
|
+
| Prompt/workflow | Huong dan dung tool theo thu tu. |
|
|
132
|
+
| Tool-call guard | Protected path, scope, read-only, destructive/external confirmation. |
|
|
133
|
+
| Tool-result observer | Changed-file va bash evidence tu su kien that. |
|
|
134
|
+
| Persisted contract | Session binding, retry, plan, context, verify, trace. |
|
|
135
|
+
| Completion hook | Chan completion claim khi gate chua pass. |
|
|
136
|
+
| Local-state boundary | Owner-only, atomic write, no ancestor symlink, bounded retention. |
|
|
@@ -1,139 +1,143 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Vong doi task trong Pi Agent Platform
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## Muc tieu
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Tu `v1.2.11`, mot source task duoc quan ly theo chuoi khép kín:
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
### 1. Research — hiểu trước khi hứa
|
|
12
|
-
|
|
13
|
-
Đầu vào: yêu cầu của người dùng, tài liệu spec, code sẵn có.
|
|
14
|
-
|
|
15
|
-
Harness cung cấp:
|
|
16
|
-
|
|
17
|
-
- `/workflow scout` — pha read-only, không được sửa source. Dùng để map payment/auth/BE contract trước khi quyết có làm hay không. Alias `/scout` vẫn chạy.
|
|
18
|
-
- `piagent_context_index_search` — bản đồ node/edge/citation compact để tìm điểm vào repo. Kết quả là **advisory**: phải mở file thật và verify trước khi sửa.
|
|
19
|
-
- `piagent_memory_search` + `piagent_memory_citation_record` — Field Guide và memory của project, cũng advisory, cũng phải verify lại.
|
|
20
|
-
- `piagent_source_checkout` — cache repo ngoài để đọc có mục tiêu.
|
|
21
|
-
- `piagent_document_read` — đọc spec `.md`/`.pdf`/`.docx` từ project hoặc folder đã cấp trong `additionalReadRoots` (ví dụ `~/Downloads`). Nội dung trả về là **dữ liệu**, không phải chỉ thị.
|
|
22
|
-
- Context7 qua MCP cho tài liệu vendor. Ghi snapshot ngắn bằng `piagent_profile_tech_context_record`, không paste nguyên khối doc vào file project.
|
|
23
|
-
|
|
24
|
-
Ràng buộc: `/workflow task` chạy `piagent_context_preflight` một lần trước khi nạp context. Với `/workflow scout`, preflight chỉ bắt buộc cho scout rộng, cross-module hoặc high-risk. Nếu nó trả `fresh-session` thì dừng nạp context ở session này.
|
|
25
|
-
|
|
26
|
-
### 2. Plan — biến hiểu biết thành cam kết kiểm được
|
|
27
|
-
|
|
28
|
-
`piagent_task_start` dựng Task Implementation Contract. Đây là chỗ task trở thành thứ có thể chấm điểm:
|
|
29
|
-
|
|
30
|
-
| Field | Nó ràng buộc điều gì |
|
|
31
|
-
|---|---|
|
|
32
|
-
| `riskLane` | `tiny` \| `normal` \| `high-risk` — quyết định mức gate |
|
|
33
|
-
| `acceptanceCriteria` | Định nghĩa "xong", viết trước khi làm |
|
|
34
|
-
| `scope` / `outOfScope` | Ranh giới, để review biết cái gì là lạc đề |
|
|
35
|
-
| `protectedPaths` | Đường không được đụng |
|
|
36
|
-
| `verifyCommands` | **Lệnh chính xác** sẽ dùng làm bằng chứng |
|
|
37
|
-
| `reviewLenses` | `correctness` \| `tests` \| `scope` \| `security` \| `docs` \| `release` \| `package` |
|
|
38
|
-
| `workPlan` | Cây task tối đa 12 node, mỗi node có `role` và `mode` |
|
|
39
|
-
|
|
40
|
-
`workPlan[].mode` là `read-only` \| `single-writer` \| `review`. Mặc định là single-writer: chỉ một tác nhân được ghi, trừ khi người dùng yêu cầu rõ parallel writers.
|
|
41
|
-
|
|
42
|
-
`piagent_orchestration_policy` chỉ cần gọi khi task có khả năng hưởng lợi từ delegation. Chính sách là solo-first — subagent chỉ dùng khi việc đó độc lập và nặng phần đọc. Lane `tiny` dùng work plan hai bước parent-only: implement và verify.
|
|
43
|
-
|
|
44
|
-
### 3. Execute — làm trong hàng rào
|
|
45
|
-
|
|
46
|
-
Trong lúc làm, guard chặn trước khi thực thi, không phải sau:
|
|
47
|
-
|
|
48
|
-
- Protected path: chặn ở `read`, `write`, `edit`, `grep`, `find`, `ls`, tool MCP, và cả đường vòng qua shell.
|
|
49
|
-
- `piagent_exec_policy_check` — bắt buộc trước lệnh shell vượt quá read/list/test.
|
|
50
|
-
- `piagent_tool_policy_check` — bắt buộc trước tool MCP/app ngoài piagent.
|
|
51
|
-
- `piagent_context_budget` — kiểm trước khi nạp file lớn hoặc lạ.
|
|
52
|
-
- `piagent_context_record` — ghi lại đọc file nào, vì lý do gì.
|
|
53
|
-
|
|
54
|
-
### 4. Verify — chỗ mạnh nhất của harness
|
|
55
|
-
|
|
56
|
-
Đây là phần được thiết kế kỹ nhất, và đáng để hiểu chính xác.
|
|
57
|
-
|
|
58
|
-
Bằng chứng verify **không phải** thứ agent tự khai. Guard nghe `tool_result` của Pi và ghi vào sổ `.pi/piagent-state/observed-bash.jsonl` ([`piagent-guard.ts:1378`](../packages/piagent-core/extensions/piagent-guard.ts)). `piagent_verify_record` chỉ nhận bằng chứng khớp được với một quan sát thật, sau thời điểm task bắt đầu.
|
|
59
|
-
|
|
60
|
-
`evaluateTaskGate` ([`piagent-guard.ts:3125`](../packages/piagent-core/extensions/piagent-guard.ts)) đòi ba điều kiện cộng dồn để một bằng chứng được tính là **pass**:
|
|
61
|
-
|
|
62
|
-
```
|
|
63
|
-
evidence.exitCode === 0
|
|
64
|
-
&& evidence.observed === true // đã quan sát được, không phải khai báo
|
|
65
|
-
&& evidence.matchedProfileCommand === true // khớp đúng verifyCommands của task
|
|
7
|
+
```text
|
|
8
|
+
session name -> task contract v2 -> scoped work plan -> observed changes
|
|
9
|
+
-> exact verification -> immutable outcome -> retry evidence
|
|
66
10
|
```
|
|
67
11
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
- `observed !== true` → cảnh báo "Unobserved verify evidence is ignored by the passing verify gate."
|
|
71
|
-
- `observed === true` nhưng lệnh không khớp `verifyCommands` → "advisory only".
|
|
72
|
-
|
|
73
|
-
Nghĩa là `true`, `echo ok`, `npm test || true` không mua được chữ "done". Đó là chủ ý: một cổng có thể lách được thì tệ hơn không có cổng, vì nó vẫn hiện màu xanh.
|
|
74
|
-
|
|
75
|
-
`piagent_task_gate_check` trả `pass` hoặc `fail` kèm danh sách `missing`. Gate fail thì outcome là `blocked`/`partial`, **không phải** `done`.
|
|
76
|
-
|
|
77
|
-
### 5. Fail → loop lại
|
|
78
|
-
|
|
79
|
-
Đây là chỗ đứt. Xem mục [Chỗ đứt, nói chính xác](#chỗ-đứt-nói-chính-xác).
|
|
80
|
-
|
|
81
|
-
## Pi hiện tại xử lý tới đâu
|
|
12
|
+
Runtime guard thi hanh chuoi nay. Prompt chi huong dan agent, khong phai lop
|
|
13
|
+
enforcement chinh.
|
|
82
14
|
|
|
83
|
-
|
|
84
|
-
|---|---|---|
|
|
85
|
-
| Research | **Đủ** | `/workflow scout`, context index, memory, Context7, source checkout |
|
|
86
|
-
| Plan | **Đủ** | `piagent_task_start` + 19 field contract + `workPlan` |
|
|
87
|
-
| Execute | **Đủ** | Chặn trước thực thi ở mọi đường: tool, MCP, shell |
|
|
88
|
-
| Verify | **Mạnh** | Bằng chứng phải quan sát được và khớp lệnh, không tự khai được |
|
|
89
|
-
| Fail → loop | **Nửa vời** | Phát hiện được, từ chối nhận done được, nhưng không mang được state qua lần sau |
|
|
15
|
+
## Luong lam viec hang ngay
|
|
90
16
|
|
|
91
|
-
|
|
17
|
+
1. Mo project bang Pi va dat ten session theo task noi bo.
|
|
18
|
+
2. Neu quen dat luc mo, chay `/name <task/session name>` hoac `/setname`.
|
|
19
|
+
3. Chay `/workflow task <yeu cau>` de implement, hoac `/workflow scout <yeu cau>`
|
|
20
|
+
de chi doc.
|
|
21
|
+
4. Runtime tu tao Task Implementation Contract cho task nho, ro scope va gan voi
|
|
22
|
+
dung Pi session truoc model turn dau tien.
|
|
23
|
+
5. Agent lam viec ngay bang read/edit/bash thuong va chay exact verifier runtime
|
|
24
|
+
cung cap. Chi task rong, high-risk hoac scope mo ho moi can goi
|
|
25
|
+
`piagent_task_start` mot lan. Runtime tu ghi context, changed files, verify,
|
|
26
|
+
trace va gate.
|
|
27
|
+
6. Neu dong terminal, resume dung session cu bang `pi --continue`, `pi --resume`
|
|
28
|
+
hoac `pi --session <id-or-file>`. Task dang mo duoc map lai theo session id va
|
|
29
|
+
custom trace cua Pi; session name van dung cho Agent Watch/report.
|
|
92
30
|
|
|
93
|
-
|
|
31
|
+
Mot Pi session chi thuoc mot task, ke ca sau khi task da completed/failed. Task
|
|
32
|
+
moi hoac retry phai dung session moi. Quy tac nay ngan hai cong viec tron prompt,
|
|
33
|
+
usage va changed-file evidence vao mot report.
|
|
94
34
|
|
|
95
|
-
|
|
96
|
-
- `task.md` yêu cầu verify không chạy được thì dừng và báo blocker chính xác, không được gọi là done.
|
|
97
|
-
- Gate trả `missing` liệt kê đúng thứ còn thiếu.
|
|
35
|
+
## Nam pha
|
|
98
36
|
|
|
99
|
-
|
|
37
|
+
### 1. Research
|
|
100
38
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
39
|
+
- `/workflow scout` tao luong read-only khi chua can sua source.
|
|
40
|
+
- Pi Context Engine tim file/symbol/test bang FTS, import graph va Git signals.
|
|
41
|
+
- Memory, Context7, source checkout va document reader la advisory evidence;
|
|
42
|
+
agent van phai doc file hien tai truoc khi sua.
|
|
43
|
+
- Auto-context chi inject mot bounded pack cho moi prompt trong tung session.
|
|
44
|
+
Goi pack lai voi cung query se tra reuse marker, khong nhan doi payload/token.
|
|
105
45
|
|
|
106
|
-
|
|
46
|
+
### 2. Plan
|
|
107
47
|
|
|
108
|
-
|
|
48
|
+
Automatic intake hoac fallback `piagent_task_start` tao contract schema v2 gom:
|
|
109
49
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
-
|
|
136
|
-
-
|
|
137
|
-
-
|
|
138
|
-
|
|
139
|
-
-
|
|
50
|
+
| Nhom | Field chinh |
|
|
51
|
+
|---|---|
|
|
52
|
+
| Identity | `taskRunId`, `taskId`, `sessionId`, `sessionName`, `intakeMode` |
|
|
53
|
+
| Retry | `attempt`, `maxAttempts`, `previousAttempts` |
|
|
54
|
+
| Boundary | `changeMode`, `scope`, `outOfScope`, `protectedPaths` |
|
|
55
|
+
| Quality | `acceptanceCriteria`, `verifyGroup`, `verifyCommands`, `reviewLenses` |
|
|
56
|
+
| Execution | `workPlan`, `orchestration` |
|
|
57
|
+
| Evidence | context, memory, baseline/observed/final file digests, verify, trace |
|
|
58
|
+
|
|
59
|
+
Source task bat buoc nam trong Git working tree. Khong co Git thi runtime tu
|
|
60
|
+
choi source-change vi khong the chung minh file nao da doi; read-only scout van
|
|
61
|
+
hoat dong.
|
|
62
|
+
|
|
63
|
+
Work plan toi da 12 step, dependency khong duoc thieu, tu tham chieu hoac tao
|
|
64
|
+
cycle. Source task `tiny` tu dong hoan tat lifecycle; source task `normal` tu
|
|
65
|
+
dong ghi objective evidence va giu mot explicit review step. Read-only task dung
|
|
66
|
+
plan `scout`/`review`, khong con step `implement` mau thuan. Task high-risk/custom
|
|
67
|
+
van giu checkpoint thu cong. Chi dung subagent cho scout, planning hoac review
|
|
68
|
+
doc lap. Mot write set chi co mot owner.
|
|
69
|
+
|
|
70
|
+
### 3. Execute
|
|
71
|
+
|
|
72
|
+
Truoc khi co task contract, project da onboard chi cho inspection co gioi han;
|
|
73
|
+
write/edit va shell command that su ghi file bi chan. Sau khi task bat dau:
|
|
74
|
+
|
|
75
|
+
- direct tool va MCP write phai nam trong `scope`;
|
|
76
|
+
- read-only task chan moi project/external mutation;
|
|
77
|
+
- protected path, secret redaction, destructive command va external confirmation
|
|
78
|
+
van manh hon task gate;
|
|
79
|
+
- tool result ghi nhan file da quan sat thay doi;
|
|
80
|
+
- file da dirty truoc task chi tinh la thay doi cua task neu digest sau task khac
|
|
81
|
+
baseline;
|
|
82
|
+
- rename ghi nhan ca source va destination.
|
|
83
|
+
|
|
84
|
+
### 4. Verify va complete
|
|
85
|
+
|
|
86
|
+
Moi lenh trong `task.verifyCommands` phai duoc Pi `bash` chay that sau thoi diem
|
|
87
|
+
task bat dau. Hook `tool_result` tu ghi evidence khi command identity khop plan;
|
|
88
|
+
tool `piagent_verify_record` chi con la recovery surface va van phai khop ledger
|
|
89
|
+
`.pi/piagent-state/observed-bash.jsonl`.
|
|
90
|
+
|
|
91
|
+
Gate completed yeu cau dong thoi:
|
|
92
|
+
|
|
93
|
+
- context manifest theo policy;
|
|
94
|
+
- moi verify command co observed result `exitCode=0` va exact match;
|
|
95
|
+
- work plan khong con `pending`, `in-progress` hoac `failed`;
|
|
96
|
+
- declared changed files khop final digest sau baseline; file da revert khong tinh;
|
|
97
|
+
- khong co file ngoai `scope`;
|
|
98
|
+
- final trace la `completed`.
|
|
99
|
+
|
|
100
|
+
`true`, `echo ok`, `npm test || true` hoac command gan giong khong thay the lenh
|
|
101
|
+
verify da chot. Hard completion hook tu project final state, check gate va ghi
|
|
102
|
+
completed trace. Evidence verify chi hop le cho working-tree digest hien tai;
|
|
103
|
+
sua tiep sau verify buoc phai chay lai. Neu automatic/assisted task dung som,
|
|
104
|
+
runtime gui dung mot follow-up correction turn voi missing reasons that, sau do
|
|
105
|
+
khong loop.
|
|
106
|
+
|
|
107
|
+
Sau terminal outcome (`completed`, `blocked`, `partial`, `failed`), contract la
|
|
108
|
+
immutable. Agent khong the chen them context/verify/change evidence de viet lai
|
|
109
|
+
lich su.
|
|
110
|
+
|
|
111
|
+
### 5. Fail va retry
|
|
112
|
+
|
|
113
|
+
`workPlan[].status` co `failed`. Final failure ghi `failedAt`, `failureReason`,
|
|
114
|
+
`ruledOut` va friction. Session moi dung cung `taskId` tao attempt tiep theo va
|
|
115
|
+
mang theo toi da 10 attempt summaries.
|
|
116
|
+
|
|
117
|
+
`maxAttempts` duoc khoa tu attempt dau (mac dinh 3, toi da 10). Sua tay attempt
|
|
118
|
+
sau khong the nang tran. Completed task khong duoc mo lai bang cung `taskId`;
|
|
119
|
+
cong viec moi phai co ID moi.
|
|
120
|
+
|
|
121
|
+
## Migration va local state
|
|
122
|
+
|
|
123
|
+
Session start va `piagent-update --project <path>` deu nhan biet contract v1.
|
|
124
|
+
Migration:
|
|
125
|
+
|
|
126
|
+
- preview truoc khi ghi;
|
|
127
|
+
- tu choi toan bo neu co state unreadable/corrupt;
|
|
128
|
+
- tao contract v2 roi archive v1, co the chay lai sau interruption;
|
|
129
|
+
- chi map legacy task vao session resume khi custom Pi trace chung minh dung task;
|
|
130
|
+
- khong yeu cau onboard lai project.
|
|
131
|
+
|
|
132
|
+
State, telemetry va capture nam trong `.pi/piagent-state/`, mode owner-only. Moi
|
|
133
|
+
writer dung chung local-state boundary, tu choi `.pi`/ancestor symlink thoat
|
|
134
|
+
project. JSONL duoc rotate co lock lien process; capture gioi han 500 file,
|
|
135
|
+
128 MiB va 30 ngay.
|
|
136
|
+
|
|
137
|
+
## Lien quan
|
|
138
|
+
|
|
139
|
+
- [Task Implementation Contract](task-implementation-contract.md)
|
|
140
|
+
- [Runtime harness standard](runtime-harness-standard.md)
|
|
141
|
+
- [Pi Context Engine](context-engine.md)
|
|
142
|
+
- [Command reference](command-reference-vietnamese.md)
|
|
143
|
+
- [Usage observability](usage-observability.md)
|
package/docs/team-onboarding.md
CHANGED
|
@@ -9,7 +9,7 @@ Một thành viên mới không cần biết local path của maintainer. Luồn
|
|
|
9
9
|
```bash
|
|
10
10
|
node --version # >= 22.19.0
|
|
11
11
|
npm install -g --ignore-scripts @earendil-works/pi-coding-agent@0.82.0
|
|
12
|
-
npm install -g --ignore-scripts @piagent/platform@1.2.
|
|
12
|
+
npm install -g --ignore-scripts @piagent/platform@1.2.11
|
|
13
13
|
piagent-install --stable
|
|
14
14
|
cd /path/to/project
|
|
15
15
|
pi
|
|
@@ -43,7 +43,7 @@ Mặc định team dùng stable helper:
|
|
|
43
43
|
```bash
|
|
44
44
|
node --version # >= 22.19.0
|
|
45
45
|
npm install -g --ignore-scripts @earendil-works/pi-coding-agent@0.82.0
|
|
46
|
-
npm install -g --ignore-scripts @piagent/platform@1.2.
|
|
46
|
+
npm install -g --ignore-scripts @piagent/platform@1.2.11
|
|
47
47
|
piagent-install --stable --dry-run
|
|
48
48
|
piagent-install --stable
|
|
49
49
|
```
|
|
@@ -79,7 +79,12 @@ Khi cần kiểm tra một project sau rollout, chạy riêng:
|
|
|
79
79
|
piagent-update --version X.Y.Z --project /path/to/project
|
|
80
80
|
```
|
|
81
81
|
|
|
82
|
-
`--project` là bước phụ: tự migrate layout
|
|
82
|
+
`--project` là bước phụ: tự migrate layout cũ, Task Contract và managed block
|
|
83
|
+
trong `AGENTS.md` nếu có rồi chạy doctor strict-share. Text riêng của project
|
|
84
|
+
ngoài managed block được giữ nguyên. Nếu chỉ update global, runtime mới vẫn thay
|
|
85
|
+
checklist template cũ trong system prompt ở memory nên task dùng logic mới ngay;
|
|
86
|
+
chạy `--project` để file trên disk được dọn bền vững. `--check` chỉ báo version,
|
|
87
|
+
không đụng gì.
|
|
83
88
|
|
|
84
89
|
Nếu npm global mặc định của máy bị khóa quyền ở `/usr/local`, updater tự chuyển sang `~/.pi/npm-global` cho user hiện tại và in dòng `PATH` cần thêm. Không chạy doctor bằng `sudo`.
|
|
85
90
|
|
|
@@ -360,9 +365,12 @@ Chạy trên project:
|
|
|
360
365
|
```bash
|
|
361
366
|
bash /path/to/piagent/scripts/profile-doctor.sh /path/to/project
|
|
362
367
|
bash /path/to/piagent/scripts/team-doctor.sh /path/to/project --strict-share
|
|
363
|
-
|
|
368
|
+
piagent-benchmark --dry-run
|
|
364
369
|
```
|
|
365
370
|
|
|
371
|
+
Maintainer chạy `piagent-benchmark` khi cần đo release/model bằng automatic paired
|
|
372
|
+
suite. Lệnh dùng model quota và sẽ hỏi xác nhận trước khi bắt đầu.
|
|
373
|
+
|
|
366
374
|
Nếu doctor cảnh báo `project onboarding snapshot is still pending`, mở Pi trong project và chạy `/onboard run`.
|
|
367
375
|
|
|
368
376
|
## Không commit
|