@piagent/platform 1.2.10 → 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.
Files changed (105) hide show
  1. package/CHANGELOG.md +137 -0
  2. package/README.md +27 -4
  3. package/adapters/backend-api/profile.json +1 -1
  4. package/adapters/be-readonly-fe/profile.json +2 -2
  5. package/adapters/data/profile.json +1 -1
  6. package/adapters/devops/profile.json +1 -3
  7. package/adapters/docs/profile.json +1 -1
  8. package/adapters/fullstack/profile.json +2 -4
  9. package/adapters/generic/profile.json +1 -1
  10. package/adapters/mobile/profile.json +1 -2
  11. package/adapters/node-typescript/profile.json +1 -3
  12. package/benchmarks/core-v1/suite.json +51 -0
  13. package/benchmarks/core-v1/tasks/discount-order/grade.mjs +17 -0
  14. package/benchmarks/core-v1/tasks/discount-order/project/package.json +8 -0
  15. package/benchmarks/core-v1/tasks/discount-order/project/src/discount.js +3 -0
  16. package/benchmarks/core-v1/tasks/discount-order/project/src/order.js +6 -0
  17. package/benchmarks/core-v1/tasks/discount-order/project/test/order.test.js +7 -0
  18. package/benchmarks/core-v1/tasks/discount-order/prompt.md +4 -0
  19. package/benchmarks/core-v1/tasks/invoice-quantity/grade.mjs +17 -0
  20. package/benchmarks/core-v1/tasks/invoice-quantity/project/package.json +8 -0
  21. package/benchmarks/core-v1/tasks/invoice-quantity/project/src/invoice.js +3 -0
  22. package/benchmarks/core-v1/tasks/invoice-quantity/project/test/invoice.test.js +7 -0
  23. package/benchmarks/core-v1/tasks/invoice-quantity/prompt.md +3 -0
  24. package/benchmarks/core-v1/tasks/protected-env-refusal/grade.mjs +11 -0
  25. package/benchmarks/core-v1/tasks/protected-env-refusal/project/README.md +4 -0
  26. package/benchmarks/core-v1/tasks/protected-env-refusal/project/package.json +8 -0
  27. package/benchmarks/core-v1/tasks/protected-env-refusal/project/test/smoke.test.js +4 -0
  28. package/benchmarks/core-v1/tasks/protected-env-refusal/prompt.md +4 -0
  29. package/benchmarks/core-v1/tasks/targeted-session/grade.mjs +14 -0
  30. package/benchmarks/core-v1/tasks/targeted-session/project/package.json +8 -0
  31. package/benchmarks/core-v1/tasks/targeted-session/project/src/auth/session.js +3 -0
  32. package/benchmarks/core-v1/tasks/targeted-session/project/src/billing/currency.js +3 -0
  33. package/benchmarks/core-v1/tasks/targeted-session/project/src/catalog/search.js +3 -0
  34. package/benchmarks/core-v1/tasks/targeted-session/project/src/notifications/channel.js +3 -0
  35. package/benchmarks/core-v1/tasks/targeted-session/project/src/search/tokenize.js +3 -0
  36. package/benchmarks/core-v1/tasks/targeted-session/project/test/session.test.js +7 -0
  37. package/benchmarks/core-v1/tasks/targeted-session/prompt.md +4 -0
  38. package/catalog/capabilities.json +10 -10
  39. package/docs/command-reference-vietnamese.md +10 -6
  40. package/docs/context-engine.md +33 -11
  41. package/docs/distribution-standard.md +11 -8
  42. package/docs/mcp-and-tools.md +13 -7
  43. package/docs/model-options.md +7 -10
  44. package/docs/operator-manual-vietnamese.md +82 -33
  45. package/docs/package-architecture-notes.md +3 -1
  46. package/docs/publishing-for-teams.md +4 -0
  47. package/docs/quality-benchmark.md +225 -58
  48. package/docs/quickstart-vietnamese.md +5 -0
  49. package/docs/release-install-policy.md +41 -7
  50. package/docs/runtime-harness-standard.md +47 -29
  51. package/docs/runtime-policy-design.md +23 -12
  52. package/docs/runtime-quality-baseline.md +31 -17
  53. package/docs/security-threat-model.md +1 -1
  54. package/docs/task-implementation-contract.md +113 -177
  55. package/docs/task-lifecycle-vietnamese.md +129 -125
  56. package/docs/team-onboarding.md +12 -4
  57. package/docs/usage-observability.md +15 -8
  58. package/docs-site/architecture.html +1 -1
  59. package/docs-site/commands.html +1 -1
  60. package/docs-site/content/runtime.html +10 -0
  61. package/docs-site/context-engine.html +1 -1
  62. package/docs-site/index.html +1 -1
  63. package/docs-site/mcp-approval.html +1 -1
  64. package/docs-site/mcp-auth.html +1 -1
  65. package/docs-site/mcp-servers.html +1 -1
  66. package/docs-site/mcp.html +1 -1
  67. package/docs-site/permissions.html +1 -1
  68. package/docs-site/profiles.html +1 -1
  69. package/docs-site/quickstart.html +1 -1
  70. package/docs-site/runtime.html +11 -1
  71. package/docs-site/scope.html +1 -1
  72. package/docs-site/security.html +1 -1
  73. package/docs-site/team.html +1 -1
  74. package/docs-site/workflows.html +1 -1
  75. package/evals/fixtures/task-contract.invalid.json +15 -1
  76. package/evals/fixtures/task-contract.valid.json +18 -2
  77. package/package.json +3 -2
  78. package/packages/piagent-core/README.md +37 -3
  79. package/packages/piagent-core/benchmark/benchmark-core.js +691 -0
  80. package/packages/piagent-core/extensions/context-engine.js +81 -57
  81. package/packages/piagent-core/extensions/guard-types.ts +35 -3
  82. package/packages/piagent-core/extensions/local-state-path.js +59 -0
  83. package/packages/piagent-core/extensions/piagent-guard.ts +1865 -171
  84. package/packages/piagent-core/extensions/policy-core.js +11 -1
  85. package/packages/piagent-core/extensions/runtime-evidence.js +39 -19
  86. package/packages/piagent-core/extensions/state-retention.js +218 -0
  87. package/packages/piagent-core/extensions/task-lifecycle.js +138 -0
  88. package/packages/piagent-core/extensions/task-state.js +630 -0
  89. package/packages/piagent-core/package.json +1 -1
  90. package/packages/piagent-core/policies/base-policy.json +1 -0
  91. package/packages/piagent-core/prompts/be-to-fe.md +14 -22
  92. package/packages/piagent-core/prompts/platform-improve.md +12 -17
  93. package/packages/piagent-core/prompts/review.md +7 -11
  94. package/packages/piagent-core/prompts/scout.md +6 -10
  95. package/packages/piagent-core/prompts/task.md +11 -17
  96. package/packages/piagent-core/skills/piagent-ops/SKILL.md +12 -15
  97. package/schemas/task-contract.schema.json +267 -104
  98. package/scripts/benchmark-runner.mjs +1172 -0
  99. package/scripts/install-global.sh +1 -1
  100. package/scripts/migrate-project-state.mjs +94 -3
  101. package/scripts/piagent-cli.mjs +1 -1
  102. package/scripts/update-global.mjs +36 -3
  103. package/scripts/verify-local.sh +15 -0
  104. package/templates/project/.pi/task-contract.template.json +19 -2
  105. package/templates/project/AGENTS.md +10 -20
@@ -12,8 +12,8 @@
12
12
  },
13
13
  "artifacts": [
14
14
  {
15
- "byteSize": 1901,
16
- "digest": "sha256:4cf593f5ae8d2806d5d1262ea31f7814e087b0d599e66fc064467b8c22a6a075",
15
+ "byteSize": 1913,
16
+ "digest": "sha256:fc10abbe00bb05e64e43662550b9a92e95b7441c3da000a5e2e244c5afb0eccc",
17
17
  "id": "generic",
18
18
  "kind": "adapters",
19
19
  "path": "adapters/generic/profile.json"
@@ -26,8 +26,8 @@
26
26
  "path": "evals/scenarios/capability-resolution.json"
27
27
  },
28
28
  {
29
- "byteSize": 6201,
30
- "digest": "sha256:35398d414c6fd57f63c81990881410ad4286074c2c63fbf53a808b6cfb27b343",
29
+ "byteSize": 6232,
30
+ "digest": "sha256:a2c44a910a440e972579c2a2ec372ee15cfb73b63b27d01c1e3a053c176d11bf",
31
31
  "id": "base-policy",
32
32
  "kind": "policies",
33
33
  "path": "packages/piagent-core/policies/base-policy.json"
@@ -54,15 +54,15 @@
54
54
  "path": "packages/piagent-core/prompts/pr.md"
55
55
  },
56
56
  {
57
- "byteSize": 1749,
58
- "digest": "sha256:160bf204e632293068bba0d457f0abb0c5a76af3ed452b0647746e9e7071d773",
57
+ "byteSize": 1314,
58
+ "digest": "sha256:e1e9caf68957748bebf6ac2d6294905226b298b2734434db8341b35664794388",
59
59
  "id": "review",
60
60
  "kind": "prompts",
61
61
  "path": "packages/piagent-core/prompts/review.md"
62
62
  },
63
63
  {
64
- "byteSize": 3452,
65
- "digest": "sha256:d06f189c7cf6484cc60d79c200e85ff60f543651264b9233cb23686145cc35d8",
64
+ "byteSize": 2371,
65
+ "digest": "sha256:bfe8374f15e06d410eec7ab2c82f85ef011fc7d514a92f23720179b497910a44",
66
66
  "id": "task",
67
67
  "kind": "prompts",
68
68
  "path": "packages/piagent-core/prompts/task.md"
@@ -75,8 +75,8 @@
75
75
  "path": "packs/engineering-base/recipes/bounded-change.json"
76
76
  },
77
77
  {
78
- "byteSize": 1356,
79
- "digest": "sha256:8ee63773b66386fb1e278e178842d4bd2a725b73d60e1114529df4aa3bc628f4",
78
+ "byteSize": 1832,
79
+ "digest": "sha256:a1c21e7d1c3ab12fff8516bbac2922526e35b37a6852eaa9f5a7d98a102b830e",
80
80
  "id": "piagent-ops",
81
81
  "kind": "skills",
82
82
  "path": "packages/piagent-core/skills/piagent-ops/SKILL.md"
@@ -468,8 +468,8 @@ Các lệnh này chạy ngoài Pi.
468
468
  | Command | Dùng khi nào |
469
469
  |---|---|
470
470
  | `npm install -g --ignore-scripts @earendil-works/pi-coding-agent@0.82.0` | Cài Pi CLI tương thích với release hiện tại. |
471
- | `npm install -g --ignore-scripts @piagent/platform@1.2.10` | Cài terminal helper `piagent-*` từ release tag hiện tại. |
472
- | `pi install git:github.com/Vt-mmm/piagent@v1.2.10` | Cài pinned release khi cần reproducible team setup. |
471
+ | `npm install -g --ignore-scripts @piagent/platform@1.2.11` | Cài terminal helper `piagent-*` từ release tag hiện tại. |
472
+ | `pi install git:github.com/Vt-mmm/piagent@v1.2.11` | Cài pinned release khi cần reproducible team setup. |
473
473
  | `pi install git:github.com/Vt-mmm/piagent` | Cài latest package platform cho máy cá nhân/sandbox. |
474
474
  | `piagent-update --check` | Báo version hiện tại vs version sẽ lên cho cả ba thành phần; không cài gì. |
475
475
  | `piagent-update` | Full update global một lệnh cho cả máy: Pi host → npm-global helper → Pi package, đúng thứ tự release yêu cầu. |
@@ -511,11 +511,12 @@ Các lệnh này chạy ngoài Pi.
511
511
  | `piagent-uninstall --apply` | Gỡ Pi package của platform khỏi Pi settings global. |
512
512
  | `piagent-uninstall --apply --with-addons --with-host` | Gỡ thêm pi-mcp-adapter, pi-subagents, pi-web-access và Pi host. |
513
513
  | `piagent-uninstall --apply --project /path/to/project` | Gỡ thêm state của platform trong project: profile, lock, `piagent-state/`. |
514
- | `piagent-benchmark ...` | Ghi quality benchmark bằng package bin. |
514
+ | `piagent-benchmark` | Tự chạy paired Raw Pi/Piagent ở steady-state đã onboard, chấm riêng hidden grader + scope + workflow và đọc exact token/tool histogram từ session. |
515
+ | `piagent-benchmark --dry-run` | Validate suite và xem số model session, không gọi model. |
515
516
  | `bash scripts/verify-local.sh` | Verify repo platform trước khi commit/tag. |
516
517
  | `bash scripts/verify-local.sh --offline` | Verify trong CI/máy sạch, bỏ qua local Pi model catalog. |
517
518
  | `bash scripts/setup.sh <project> ...` | Preseed setup project; không bắt buộc cho daily flow. |
518
- | `bash scripts/quality-benchmark.sh ...` | Ghi quality benchmark theo scenario thật. |
519
+ | `bash scripts/quality-benchmark.sh ...` | Legacy: ghi tay benchmark cho scenario project-specific. |
519
520
 
520
521
  Trong output `piagent-install`, `currentRelease` là version của terminal helper đang chạy, không phải lời xác nhận rằng npm-global helper vừa được update. Checklist đầy đủ nằm tại [release/install policy](release-install-policy.md).
521
522
 
@@ -528,7 +529,7 @@ Khi đang develop chính repo `piagent`, có thể dùng npm scripts tương ứ
528
529
  | `npm run install-global` | `bash scripts/install-global.sh` |
529
530
  | `npm run init-project -- <project>` | `bash scripts/init-project.sh <project>` |
530
531
  | `npm run doctor -- <project> --strict-share` | `bash scripts/team-doctor.sh <project> --strict-share` |
531
- | `npm run benchmark -- ...` | `bash scripts/quality-benchmark.sh ...` |
532
+ | `npm run benchmark -- ...` | `node scripts/benchmark-runner.mjs ...` |
532
533
  | `npm run usage -- <project>` | `bash scripts/pi-session-stats.sh <project>` |
533
534
  | `npm run usage -- --history <project> --days 7` | `bash scripts/pi-session-stats.sh --history <project> --days 7` |
534
535
  | `npm run models` | `bash scripts/pi-model-catalog.sh` |
@@ -570,7 +571,10 @@ export GITHUB_PERSONAL_ACCESS_TOKEN=<github-token>
570
571
  | Subagents tốn bao nhiêu? | `/subagent-cost` |
571
572
  | Có nên compact chưa? | Xem `contextUsage.percent`; trên 75% mới cân nhắc `/compact`. |
572
573
 
573
- Không claim tiết kiệm token/cost nếu chưa có số liệu cùng scenario. Dùng benchmark script để ghi lại.
574
+ Không claim tiết kiệm token/cost nếu chưa có paired evidence cùng scenario. Dùng
575
+ `piagent-benchmark`; runner chỉ cho phép verdict tiết kiệm khi
576
+ quality/reliability đạt ít nhất `9/10`, safety/workflow đạt tuyệt đối, quality
577
+ không giảm và có ít nhất ba cặp cùng model với exact usage.
574
578
 
575
579
  ## Source rule cho subagent/custom agent
576
580
 
@@ -12,7 +12,7 @@ task
12
12
  -> dynamic tool groups
13
13
  -> explicit path + FTS5 + symbol/import graph + git/test signals
14
14
  -> Reciprocal Rank Fusion + personalized PageRank
15
- -> token-budgeted context pack
15
+ -> token-budgeted navigation pack or current-turn source snapshot
16
16
  -> selected parent model
17
17
  -> delta tool results + semantic compaction
18
18
  -> local telemetry for Agent Watch
@@ -23,19 +23,32 @@ task
23
23
  - Piagent tools được chia thành `governance`, `policy`, `retrieval`,
24
24
  `knowledge`, `onboarding`, và `usage`. Code retrieval không tự kéo theo
25
25
  memory, document intake, source checkout hoặc orchestration.
26
- - Session bắt đầu với loader nhỏ. Input hook bật nhóm cần cho task trước khi
27
- system prompt được tạo.
28
- - `piagent_tools` chỉ mở thêm nhóm được yêu cầu; runtime guard vẫn chạy kể cả
29
- khi policy tool không hiện với model.
26
+ - Session bắt đầu không mang schema quản trị Piagent. Input hook bật thẳng nhóm
27
+ tối thiểu cần cho task trước khi system prompt được tạo.
28
+ - `piagent_tools` chỉ xuất hiện khi operator yêu cầu rõ tool loader; runtime
29
+ guard vẫn chạy kể cả khi policy tool không hiện với model.
30
30
  - Tool order cố định để giữ prompt prefix ổn định cho provider có prompt cache.
31
31
  - Read/grep/find/ls lặp lại với cùng input và cùng output trả delta marker thay
32
32
  vì chèn lại toàn bộ kết quả.
33
+ - Auto-context được cache theo `cwd + sessionId + promptHash`. Cùng prompt trong
34
+ cùng session chỉ inject một lần; session khác vẫn có pack riêng. Gọi manual
35
+ pack với cùng query trả reuse marker ngắn trừ khi `refresh=true`.
36
+ - Auto pack dùng 500 token cho `tiny`, 900 cho `normal`, 1.200 cho `high-risk`;
37
+ manual pack mặc định 2.400 token. Model và thinking level không bị hạ.
38
+ - Task source bounded do runtime intake quản lý có thể nhận current-turn snapshot
39
+ tối đa 900 token trước action đầu. Snapshot chỉ lấy file dưới source/test root,
40
+ đọc nội dung hiện tại sau freshness/protected-path/symlink checks và bị bỏ qua
41
+ khi index stale hoặc retrieval confidence thấp. Model dùng snapshot cho edit
42
+ đầu tiên, chỉ re-read khi thiếu region hoặc edit báo mismatch.
43
+ - Token estimator tính ASCII và UTF-8 riêng, bảo thủ hơn cho tiếng Việt/CJK/emoji
44
+ để pack không vượt budget chỉ vì một ký tự dùng nhiều byte.
33
45
  - Telemetry không lưu prompt hoặc tool output thô. Nó lưu hash, kích thước, tool,
34
46
  model, thinking, active-tool count, usage, retrieval confidence và đường dẫn
35
47
  tương đối đã được guard redaction.
36
48
 
37
- Ba cơ chế `PIAGENT_DYNAMIC_TOOLS`, `PIAGENT_AUTO_CONTEXT` và
38
- `PIAGENT_CONTEXT_TELEMETRY` đều **bật mặc định** từ `v1.2.6`. Telemetry chỉ ghi
49
+ Bốn cơ chế `PIAGENT_DYNAMIC_TOOLS`, `PIAGENT_AUTO_CONTEXT`,
50
+ `PIAGENT_CONTEXT_TELEMETRY` và `PIAGENT_AUTO_RECOVERY` đều **bật mặc định**.
51
+ Ba cờ đầu có từ `v1.2.6`; bounded recovery có từ `v1.2.11`. Telemetry chỉ ghi
39
52
  operational metadata/hash như mô tả dưới đây, không ghi prompt hoặc tool output
40
53
  thô. Tắt riêng từng cơ chế cho một lần chạy bằng:
41
54
 
@@ -43,6 +56,7 @@ thô. Tắt riêng từng cơ chế cho một lần chạy bằng:
43
56
  PIAGENT_DYNAMIC_TOOLS=off pi
44
57
  PIAGENT_AUTO_CONTEXT=off pi
45
58
  PIAGENT_CONTEXT_TELEMETRY=off pi
59
+ PIAGENT_AUTO_RECOVERY=off pi
46
60
  ```
47
61
 
48
62
  ## P1: code index và retrieval
@@ -101,8 +115,10 @@ score(file) = sum(weight(source) / (60 + rank(source, file)))
101
115
  ```
102
116
 
103
117
  Context pack tách repo map và source snippets, sau đó dừng cứng tại token
104
- budget. Index chỉ là navigation evidence; model phải đọc file hiện tại trước
105
- khi edit.
118
+ budget. Manual/read-only pack vẫn chỉ là navigation evidence và model phải đọc
119
+ file hiện tại trước khi edit. Riêng current-turn snapshot của automatic bounded
120
+ task đọc lại file hiện tại sau freshness check; edit exact-text sẽ fail nếu file
121
+ đổi sau snapshot, khi đó model phải re-read thay vì đoán.
106
122
 
107
123
  Tất cả API chạm context index (`build`, `status`, `ensure`, `search`, `pack`,
108
124
  `impact`) bắt buộc caller truyền `excludePatterns` tường minh và fail-closed
@@ -146,8 +162,14 @@ Mỗi event có:
146
162
  ```
147
163
 
148
164
  Agent Watch có thể join event với Pi session JSONL bằng `sessionId` và
149
- `sessionName`. Không cần polling realtime; import lúc mở app hoặc lúc xuất
150
- report vẫn thấy đủ event đã ghi.
165
+ `sessionName`, và với task contract bằng `taskId`/`taskRunId`. Không cần polling
166
+ realtime; import lúc mở app hoặc lúc xuất report vẫn thấy event đã ghi.
167
+
168
+ Telemetry, trace, observed-bash và capture dùng bounded JSONL owner-only, có
169
+ cross-process rotation lock. Giới hạn mặc định: context telemetry 32 MiB, task
170
+ trace 8 MiB, capture index 4 MiB; tool-result captures tối đa 500 file, 128 MiB
171
+ và 30 ngày. Record đơn lẻ vượt trần được thay bằng audit marker thay vì làm file
172
+ phình. Mọi writer từ chối `.pi` hoặc ancestor symlink ra ngoài project.
151
173
 
152
174
  Feedback không phải model học ngầm. Khi một context pack chọn file và chính
153
175
  session đó sau đó thực sự đọc hoặc sửa file, file nhận một boost nhỏ ở những
@@ -14,9 +14,9 @@ Repo này phải chạy được cho nhiều project/domain khác nhau. Vì vậ
14
14
 
15
15
  | Use case | Package source |
16
16
  |---|---|
17
- | Team pinned release | `git:github.com/Vt-mmm/piagent@v1.2.10` |
17
+ | Team pinned release | `git:github.com/Vt-mmm/piagent@v1.2.11` |
18
18
  | Personal/sandbox dev | `git:github.com/Vt-mmm/piagent` |
19
- | Registry distribution | `npm:@piagent/platform@1.2.10` |
19
+ | Registry distribution | `npm:@piagent/platform@1.2.11` |
20
20
  | Enterprise npm (fork under another scope) | `npm:@your-scope/platform@x.y.z` |
21
21
  | Local platform dev | `/path/to/piagent` |
22
22
 
@@ -26,7 +26,7 @@ Latest tiện cho máy cá nhân muốn nhận cập nhật nhanh. Pin tag/commi
26
26
 
27
27
  | Channel | Command | Target | Policy |
28
28
  |---|---|---|---|
29
- | `stable` | `bash scripts/install-global.sh --stable` | Helper release tag resolved to commit SHA, currently `v1.2.10` | Install the Pi package matching the helper. |
29
+ | `stable` | `bash scripts/install-global.sh --stable` | Helper release tag resolved to commit SHA, currently `v1.2.11` | Install the Pi package matching the helper. |
30
30
  | `exact` | `bash scripts/install-global.sh --version vX.Y.Z --resolve-tag` | Requested tag resolved to commit SHA | Pi-package-only rollout, rollback, and incident recovery. |
31
31
  | `dev` | `bash scripts/install-global.sh --dev` | Moving Git source | Personal/sandbox only; do not commit into project settings. |
32
32
  | `local` | `bash scripts/install-global.sh --local` | Current checkout path | Platform development only. |
@@ -53,7 +53,7 @@ Root `package.json` có `pi` manifest trỏ tới:
53
53
  Do đó team có thể:
54
54
 
55
55
  ```bash
56
- pi install git:github.com/Vt-mmm/piagent@v1.2.10
56
+ pi install git:github.com/Vt-mmm/piagent@v1.2.11
57
57
  ```
58
58
 
59
59
  Không cần biết internal folder `packages/piagent-core`. Source không pin chỉ dành cho personal/sandbox như bảng channel ở trên.
@@ -65,12 +65,12 @@ Team nên install global package một lần:
65
65
  ```bash
66
66
  node --version # >= 22.19.0
67
67
  npm install -g --ignore-scripts @earendil-works/pi-coding-agent@0.82.0
68
- npm install -g --ignore-scripts @piagent/platform@1.2.10
68
+ npm install -g --ignore-scripts @piagent/platform@1.2.11
69
69
  piagent-install --stable --dry-run
70
70
  piagent-install --stable
71
71
  ```
72
72
 
73
- `pi install git:github.com/Vt-mmm/piagent@v1.2.10` vẫn hợp lệ nếu chỉ cần cài Pi package. Lệnh đó không tự tạo các binary terminal `piagent-*`; muốn có helper global thì dùng `npm install -g --ignore-scripts @piagent/platform@1.2.10`.
73
+ `pi install git:github.com/Vt-mmm/piagent@v1.2.11` vẫn hợp lệ nếu chỉ cần cài Pi package. Lệnh đó không tự tạo các binary terminal `piagent-*`; muốn có helper global thì dùng `npm install -g --ignore-scripts @piagent/platform@1.2.11`.
74
74
 
75
75
  Support matrix hiện tại: macOS Apple Silicon + Bash và Linux x64 + Bash đã được verify; macOS Intel + Bash và Linux ARM64 + Bash là supported target cần chạy smoke trước rollout; native Windows chưa phải target rollout team; WSL2 experimental. Chi tiết và version runtime nằm trong [release/install policy](release-install-policy.md).
76
76
 
@@ -120,7 +120,7 @@ Nếu muốn commit sẵn `.pi/piagent-profile.json` vào repo hoặc bootstrap
120
120
  ```bash
121
121
  bash scripts/setup.sh /path/to/project \
122
122
  --profile be-readonly-fe \
123
- --package-source git:github.com/Vt-mmm/piagent@v1.2.10 \
123
+ --package-source git:github.com/Vt-mmm/piagent@v1.2.11 \
124
124
  --mcp-preset core \
125
125
  --subagents-preset safe
126
126
  ```
@@ -201,7 +201,10 @@ Máy chưa có helper dùng bootstrap all-in-one:
201
201
  npm exec -y --package @piagent/platform@X.Y.Z -- piagent-update --version X.Y.Z --force
202
202
  ```
203
203
 
204
- Máy bị khóa npm global ở `/usr/local` không cần `sudo`: updater sẽ dùng prefix user-local `~/.pi/npm-global` hoặc maintainer có thể truyền `--npm-prefix <path>`.
204
+ Updater ưu tiên prefix đang chứa chính command `piagent-update` nếu prefix đó
205
+ có quyền ghi, kể cả khi `npm config` trỏ sang nơi khác. Nếu cả prefix đang chạy
206
+ và npm global mặc định đều bị khóa, updater mới dùng `~/.pi/npm-global`; không
207
+ cần `sudo`. Maintainer vẫn có thể ép vị trí bằng `--npm-prefix <path>`.
205
208
 
206
209
  Project migration/doctor là bước kiểm tra sau global update, chỉ chạy cho repo cần xác minh:
207
210
 
@@ -453,13 +453,18 @@ Search/list channels cũng được kiểm:
453
453
 
454
454
  ## Built-in platform tools
455
455
 
456
+ The registry below is the full capability surface. Dynamic activation exposes
457
+ only the small subset needed now. Routine tasks use task start/progress while
458
+ lifecycle hooks handle policy and evidence; status/evidence/gate entries are
459
+ operator diagnostics or recovery tools.
460
+
456
461
  | Tool | Intent |
457
462
  |---|---|
458
463
  | `piagent_context` | Active profile/context/verify/MCP/memory overview. |
459
- | `piagent_exec_policy_check` | Evaluate shell command before running. |
460
- | `piagent_context_budget` | Check candidate context files against hard caps. |
461
- | `piagent_tool_policy_check` | Check tool capability registration. |
462
- | `piagent_task_gate_check` | Check task readiness before final DONE. |
464
+ | `piagent_exec_policy_check` | Explain the shell-policy verdict already enforced by the hook. |
465
+ | `piagent_context_budget` | Diagnose candidate context files against hard caps. |
466
+ | `piagent_tool_policy_check` | Diagnose tool capability registration. |
467
+ | `piagent_task_gate_check` | Diagnose missing final proof during recovery. |
463
468
  | `piagent_memory_status` | Project memory policy/files/rules. |
464
469
  | `piagent_memory_search` | Keyword search `.pi/memory` markdown. |
465
470
  | `piagent_memory_note` | Append explicit durable memory note. |
@@ -473,9 +478,10 @@ Search/list channels cũng được kiểm:
473
478
  | `piagent_profile_tech_apply` | Apply profile + selected role tech stack and Context7 placeholders. |
474
479
  | `piagent_profile_tech_context_record` | Record a concise Context7 evidence snapshot for a selected tech. |
475
480
  | `piagent_task_start` | Create Task Implementation Contract. |
476
- | `piagent_context_record` | Record context manifest for task. |
477
- | `piagent_verify_record` | Record verify evidence only when it matches an observed Pi bash result after task start. Passing gate also requires exact match with `task.verifyCommands`. |
478
- | `piagent_trace_record` | Record handoff/final trace. |
481
+ | `piagent_task_progress` | Complete the normal review step or explicit custom/high-risk checkpoints. |
482
+ | `piagent_context_record` | Recovery fallback for context manifest evidence. |
483
+ | `piagent_verify_record` | Recovery fallback for an exact observed Pi bash result bound to the current tree. |
484
+ | `piagent_trace_record` | Recovery/high-risk fallback for handoff or blocker state. |
479
485
 
480
486
  ## Core capabilities
481
487
 
@@ -146,20 +146,17 @@ piagent-model-scope --preset full --default-model anthropic/claude-sonnet-5:xhig
146
146
 
147
147
  ## Benchmark rule
148
148
 
149
- Không claim “Pi + provider X tiết kiệm hơn provider Y” bằng cảm giác. Chạy cùng scenario rồi ghi bằng:
149
+ Không claim “Pi + provider X tiết kiệm hơn provider Y” bằng cảm giác. Pin model
150
+ và thinking rồi chạy automatic paired benchmark:
150
151
 
151
152
  ```bash
152
- piagent-usage /path/to/project
153
- bash scripts/quality-benchmark.sh /path/to/project --record \
154
- --scenario bounded-source-fix \
155
- --surface pi \
156
- --result pass \
157
- --tokens <total> \
158
- --cost <cost> \
159
- --verify "<verify-command>" \
160
- --notes "provider/model/thinking=<provider/model:thinking>"
153
+ piagent-benchmark --dry-run --model <provider/model> --thinking high
154
+ piagent-benchmark --model <provider/model> --thinking high
161
155
  ```
162
156
 
157
+ Runner đọc model/thinking/token/cost từ Pi session và chỉ kết luận efficiency
158
+ khi quality/safety gates vẫn đạt. Dùng một report riêng cho mỗi model preset.
159
+
163
160
  So sánh tối thiểu:
164
161
 
165
162
  - Pi + model Codex ở fast/balanced/deep;
@@ -18,12 +18,12 @@ Support matrix release hiện tại: macOS Apple Silicon + Bash và Linux x64 +
18
18
  ```bash
19
19
  node --version # >= 22.19.0
20
20
  npm install -g --ignore-scripts @earendil-works/pi-coding-agent@0.82.0
21
- npm install -g --ignore-scripts @piagent/platform@1.2.10
21
+ npm install -g --ignore-scripts @piagent/platform@1.2.11
22
22
  piagent-install --stable --dry-run
23
23
  piagent-install --stable
24
24
  ```
25
25
 
26
- Khi seed `.pi/settings.json` cho team/repo cần audit lặp lại, giữ package source dạng pinned tag như `git:github.com/Vt-mmm/piagent@v1.2.10`. Máy cá nhân có thể dùng `git:github.com/Vt-mmm/piagent` để theo latest.
26
+ Khi seed `.pi/settings.json` cho team/repo cần audit lặp lại, giữ package source dạng pinned tag như `git:github.com/Vt-mmm/piagent@v1.2.11`. Máy cá nhân có thể dùng `git:github.com/Vt-mmm/piagent` để theo latest.
27
27
 
28
28
  Nếu đang ở source checkout của platform, dùng helper theo channel để preview trước khi đổi:
29
29
 
@@ -99,7 +99,7 @@ install package once
99
99
 
100
100
  ```bash
101
101
  npm install -g --ignore-scripts @earendil-works/pi-coding-agent@0.82.0
102
- npm install -g --ignore-scripts @piagent/platform@1.2.10
102
+ npm install -g --ignore-scripts @piagent/platform@1.2.11
103
103
  piagent-install --stable --dry-run
104
104
  piagent-install --stable
105
105
  ```
@@ -282,7 +282,7 @@ Không phải daily default. Dùng khi muốn tạo sẵn `.pi` files cho projec
282
282
  bash /path/to/piagent/scripts/setup.sh /path/to/project \
283
283
  --project-only \
284
284
  --profile auto \
285
- --package-source git:github.com/Vt-mmm/piagent@v1.2.10 \
285
+ --package-source git:github.com/Vt-mmm/piagent@v1.2.11 \
286
286
  --mcp-preset core \
287
287
  --subagents-preset safe
288
288
  ```
@@ -416,42 +416,54 @@ Một source-changing task nên đi qua:
416
416
 
417
417
  ```text
418
418
  intake
419
- -> profile/context
420
- -> task contract
421
- -> context manifest
419
+ -> session name + profile/context
420
+ -> session-bound task contract v2
421
+ -> runtime-observed context manifest
422
422
  -> implementation
423
- -> verify command
424
- -> observed verify evidence
425
- -> trace
426
- -> final gate
427
- -> handoff
423
+ -> baseline-aware changed files
424
+ -> every exact verify command
425
+ -> current-tree verify evidence from tool_result
426
+ -> completion hook: trace + final gate
427
+ -> immutable outcome / retry handoff
428
428
  ```
429
429
 
430
- Các piagent tools nền:
430
+ Trong task nhỏ và rõ scope, runtime tạo contract trước model turn đầu tiên nên
431
+ model không gọi management tool nào. Task rộng, high-risk hoặc scope mơ hồ mới
432
+ fallback về một `piagent_task_start`. Các tool còn lại bên dưới là bề mặt
433
+ operator/diagnostics/recovery, không phải checklist phải gọi mỗi task.
434
+
435
+ Các Piagent tools:
431
436
 
432
437
  | Tool | Vai trò |
433
438
  |---|---|
434
439
  | `piagent_context` | Đọc active profile, required context, verify commands, MCP/memory settings. |
435
440
  | `piagent_context_index_status/search/record` | Kiểm tra/tìm/ghi context index advisory có citation. |
436
- | `piagent_task_start` | Tạo task contract: scope, risk, acceptance criteria. |
437
- | `piagent_context_record` | Ghi context manifest: file nào đã đọc và lý do. |
438
- | `piagent_exec_policy_check` | Check shell command trước khi chạy lệnh rủi ro. |
439
- | `piagent_context_budget` | Check file/context size để tránh nhồi context. |
440
- | `piagent_tool_policy_check` | Check capability của tool/MCP. |
441
- | `piagent_verify_record` | Chỉ ghi verify evidence nếu Pi đã quan sát bash result thật sau task start. |
442
- | `piagent_trace_record` | Ghi outcome, changed files, notes. |
443
- | `piagent_task_gate_check` | Check final gate trước khi báo DONE. |
441
+ | `piagent_task_start` | Fallback intake cho task rộng/high-risk/mơ hồ; scope chỉ nhận project-relative path/glob. |
442
+ | `piagent_task_progress` | Chuyển step trong work plan và ghi failure/ruled-out evidence. |
443
+ | `piagent_context_record` | Recovery: bổ sung context manifest khi observer không đủ. |
444
+ | `piagent_exec_policy_check` | Diagnostics: giải thích shell-policy verdict; runtime vẫn check mọi call. |
445
+ | `piagent_context_budget` | Diagnostics: xem budget của file/context lớn. |
446
+ | `piagent_tool_policy_check` | Diagnostics: xem capability verdict của tool/MCP. |
447
+ | `piagent_verify_record` | Recovery: đối chiếu verify với bash result thật sau task start. |
448
+ | `piagent_trace_record` | Recovery/high-risk: ghi outcome hoặc blocker thủ công. |
449
+ | `piagent_task_gate_check` | Diagnostics/recovery: xem missing final proof. |
444
450
  | `piagent_usage_snapshot` | Snapshot session/model/context. |
445
451
 
446
452
  Done đúng nghĩa:
447
453
 
448
- - có task contract;
454
+ - task contract v2 gắn đúng session hiện tại;
449
455
  - có context manifest;
450
- - verify command đã chạy thật;
451
- - verify evidence khớp `task.verifyCommands`;
456
+ - mọi verify command đã chạy thật và khớp `task.verifyCommands`;
457
+ - changed files khác baseline, có evidence và nằm trong scope;
458
+ - work plan không còn step pending/in-progress/failed;
452
459
  - trace outcome rõ;
453
460
  - final gate pass hoặc ghi rõ blocked/partial.
454
461
 
462
+ Source task yêu cầu Git working tree và meaningful verifier ngay từ lúc start.
463
+ Một session chỉ dùng cho một task. Retry mở session mới với cùng `taskId`; runtime
464
+ giữ previous attempt evidence và từ chối vượt `maxAttempts`. Contract đã terminal
465
+ không thể sửa thêm context/verify/trace để viết lại lịch sử.
466
+
455
467
  ## 6. Guardrails cần hiểu
456
468
 
457
469
  Protected path mặc định:
@@ -588,19 +600,48 @@ Sau compact, agent phải đọc lại context quan trọng trước khi sửa t
588
600
  Không claim tiết kiệm token/cost nếu chưa có số liệu cùng scenario.
589
601
 
590
602
  ```bash
591
- bash /path/to/piagent/scripts/quality-benchmark.sh /path/to/project --init
603
+ piagent-benchmark --dry-run
604
+ piagent-benchmark
605
+ ```
592
606
 
593
- bash /path/to/piagent/scripts/quality-benchmark.sh /path/to/project --record \
607
+ Lệnh mặc định tự chạy 4 scenario trên Raw Pi và Piagent, mỗi bên 3 lần; token,
608
+ cost, model và thinking được đọc từ Pi session thay vì nhập tay. Runner chỉ cho
609
+ phép kết luận tiết kiệm token khi quality/reliability đạt ít nhất `9/10`,
610
+ safety/workflow đạt `10/10`, quality không giảm, có ít nhất ba cặp cùng model
611
+ với exact usage và geometric mean của tỷ lệ fresh token `Piagent / Raw Pi`
612
+ theo từng cặp thực sự nhỏ hơn `1`.
613
+
614
+ So sánh trực tiếp với surface `codex-cli` đã đăng nhập:
615
+
616
+ ```bash
617
+ piagent-benchmark \
618
+ --surfaces piagent,codex-cli \
619
+ --model openai-codex/gpt-5.6-sol \
620
+ --thinking xhigh
621
+ ```
622
+
623
+ Chế độ mặc định là `controlled`: Codex chạy ephemeral, chỉ được ghi trong
624
+ workspace benchmark, dùng `CODEX_HOME` tạm để loại global `AGENTS.md`,
625
+ config/rules/hooks/plugins/session cá nhân và tắt capability tùy chọn có thể
626
+ làm lệch task offline. Credential hiện có chỉ được nối bằng symlink `auth.json`,
627
+ không bị runner đọc hay sao chép. `--codex-mode native` đo cấu hình Codex thật
628
+ của operator, gồm global instruction/hooks/MCP/plugins, nên chỉ dùng như report UX bổ sung. Codex OAuth
629
+ không trả currency cost trong JSONL; report để `n/a`, còn fresh token được tính
630
+ bằng `(input_tokens - cached_input_tokens) + output_tokens`.
631
+
632
+ Để ghi thêm scenario thật ngoài automatic suite, dùng chế độ legacy:
633
+
634
+ ```bash
635
+ piagent-benchmark /path/to/project --record \
594
636
  --scenario "ui-fix-with-ci-gate" \
595
637
  --surface pi \
596
638
  --result partial \
597
639
  --tokens 26323474 \
598
640
  --cost 18.33 \
599
- --verify "npm test / E2E / CI gate" \
600
- --notes "Implementation + branch push + main/test merge + CI monitor; deploy gate failed at shard 2."
641
+ --verify "npm test / E2E / CI gate"
601
642
  ```
602
643
 
603
- Benchmark nên đặt theo scenario thật, ví dụ:
644
+ Scenario project-specific nên đặt theo công việc thật, ví dụ:
604
645
 
605
646
  - `bounded-source-fix`;
606
647
  - `be-spec-to-fe`;
@@ -671,6 +712,11 @@ pi --continue
671
712
 
672
713
  Nếu `--continue` không đúng phiên cần làm, mở selector bằng `pi --resume`, chọn theo session name đã đặt. Khi resume đúng session cũ, tên session vẫn là tên đã set; nếu cần chỉnh lại cho khớp task nội bộ thì chạy `/name <new name>` ngay trước khi làm tiếp.
673
714
 
715
+ Task Contract v2 map bằng `sessionId` và Pi custom trace, không dựa riêng vào tên.
716
+ Đổi tên sau khi task bắt đầu sẽ cập nhật contract để Agent Watch/report dùng tên
717
+ mới. Không fork/reuse một session terminal cho task khác; retry hoặc task mới mở
718
+ session mới để usage/prompt/change evidence không bị trộn.
719
+
674
720
  ### Khi nào nên resume, continue, fork
675
721
 
676
722
  | Nhu cầu | Dùng |
@@ -910,8 +956,8 @@ Watchdog là optional adversarial reviewer ở cuối turn, không bật mặc
910
956
 
911
957
  | Command | Dùng để |
912
958
  |---|---|
913
- | `npm install -g --ignore-scripts @piagent/platform@1.2.10` | Cài terminal helper `piagent-*` từ release tag hiện tại. |
914
- | `pi install git:github.com/Vt-mmm/piagent@v1.2.10` | Install pinned release cho reproducible team setup. |
959
+ | `npm install -g --ignore-scripts @piagent/platform@1.2.11` | Cài terminal helper `piagent-*` từ release tag hiện tại. |
960
+ | `pi install git:github.com/Vt-mmm/piagent@v1.2.11` | Install pinned release cho reproducible team setup. |
915
961
  | `pi install git:github.com/Vt-mmm/piagent` | Install latest platform package cho máy cá nhân/sandbox. |
916
962
  | Cài exact Pi host của release, rồi `npm install -g --ignore-scripts @piagent/platform@X.Y.Z` và `piagent-install --stable` | Full update: đồng bộ host, terminal helper và Pi package. Mỗi release pin một Pi host chính xác; lấy đúng version của release đang cài trong [release/install policy](release-install-policy.md). |
917
963
  | Cài exact Pi host ghi trong release cũ, rồi helper `vPREVIOUS` và `piagent-install --stable` | Full rollback; đánh giá lại dependency findings của host cũ trước khi hạ version. |
@@ -944,7 +990,10 @@ Watchdog là optional adversarial reviewer ở cuối turn, không bật mặc
944
990
  | `piagent-subagents --preset safe` | Setup subagents baseline. |
945
991
  | `bash scripts/verify-local.sh` | Verify platform repo. |
946
992
  | `bash scripts/team-doctor.sh /path/to/project --strict-share` | Doctor project/team setup khi chạy từ source checkout. |
947
- | `bash scripts/quality-benchmark.sh /path/to/project --record ...` | Ghi benchmark. |
993
+ | `piagent-benchmark` | Tự chạy, chấm và xuất paired benchmark report. |
994
+ | `piagent-benchmark --dry-run` | Xem execution plan, không dùng model quota. |
995
+ | `piagent-benchmark --surfaces piagent,codex-cli --model <provider/model> --thinking high` | So sánh Piagent với surface `codex-cli` ở controlled mode. |
996
+ | `piagent-benchmark /path/to/project --record ...` | Legacy: ghi tay một scenario project-specific. |
948
997
 
949
998
  ### Trong Pi
950
999
 
@@ -1018,7 +1067,7 @@ Mở lại Pi session sau khi install.
1018
1067
  Cài lại terminal helper đúng release rồi kiểm tra `PATH`:
1019
1068
 
1020
1069
  ```bash
1021
- npm install -g --ignore-scripts @piagent/platform@1.2.10
1070
+ npm install -g --ignore-scripts @piagent/platform@1.2.11
1022
1071
  command -v piagent-install
1023
1072
  ```
1024
1073
 
@@ -8,6 +8,8 @@ Pi Agent Platform được đóng gói như một reusable Pi package để dùn
8
8
 
9
9
  ```text
10
10
  packages/piagent-core/
11
+ ├─ benchmark/
12
+ │ └─ benchmark-core.js ← suite validation, scoring, reports
11
13
  ├─ capabilities/
12
14
  │ └─ capability-core.js
13
15
  ├─ extensions/
@@ -89,7 +91,7 @@ Manifest data never executes code. Invalid paths, symbolic links, dependency cyc
89
91
  | Backend-readonly to frontend | `/workflow be-to-fe` |
90
92
  | Source cache | `piagent-source-cache` + `piagent_source_checkout` |
91
93
  | Subagent roles | `piagent-scout`, `piagent-planner`, `piagent-worker`, `piagent-reviewer`, `piagent-oracle` |
92
- | Quality benchmark | `scripts/quality-benchmark.sh` |
94
+ | Quality benchmark | `scripts/benchmark-runner.mjs` + `benchmark/benchmark-core.js`; legacy recorder: `scripts/quality-benchmark.sh` |
93
95
  | Capability catalog | `packs/*/pack.json` + `catalog/capabilities.json` |
94
96
  | Capability resolver | `capability-core.js` + `piagent-capabilities` |
95
97
 
@@ -63,6 +63,10 @@ pi install /path/to/piagent
63
63
  - `1.2.8`: cài `pi-web-access@0.17.0` mặc định trong setup/update để researcher subagents có web/search/fetch thật; thêm `--no-web-access` cho máy không được phép browse.
64
64
  - `1.2.9`: hợp nhất Context Engine exclusion policy giữa CLI và runtime, resolve profile `extends`, loại `readOnlyPaths`, tự rebuild index khi policy digest đổi, chặn symlink source ra ngoài project, và làm rõ lỗi thiếu migrator trong update dry-run.
65
65
  - `1.2.10`: bắt buộc `contextIndexV2Status` nhận explicit exclusion policy; Context Engine storage chuyển sang owner-only, bật core + FTS5 secure-delete và tự retry FTS rebuild/VACUUM khi policy đổi để purge raw bytes của index cũ.
66
+ - `1.2.11`: Task Contract v2 gắn session/attempt, retry có giới hạn, work-plan
67
+ progress, Git baseline-aware changed files, scope + all-command final gate,
68
+ hard completion hook, context pack dedupe, fail-closed verifier và bounded
69
+ symlink-safe local state dùng được giữa nhiều Pi session/subagent.
66
70
 
67
71
  ## Không publish
68
72