@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.
Files changed (112) hide show
  1. package/CHANGELOG.md +179 -0
  2. package/README.md +29 -6
  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 +12 -12
  39. package/docs/command-reference-vietnamese.md +15 -8
  40. package/docs/context-engine.md +56 -15
  41. package/docs/distribution-standard.md +11 -8
  42. package/docs/mcp-and-tools.md +20 -7
  43. package/docs/model-options.md +7 -10
  44. package/docs/operator-manual-vietnamese.md +102 -37
  45. package/docs/package-architecture-notes.md +3 -1
  46. package/docs/publishing-for-teams.md +5 -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 +7 -2
  54. package/docs/subagents-and-multiagent.md +1 -1
  55. package/docs/task-implementation-contract.md +113 -177
  56. package/docs/task-lifecycle-vietnamese.md +129 -125
  57. package/docs/team-onboarding.md +12 -4
  58. package/docs/usage-observability.md +15 -8
  59. package/docs-site/architecture.html +1 -1
  60. package/docs-site/commands.html +1 -1
  61. package/docs-site/content/context-engine.html +8 -1
  62. package/docs-site/content/runtime.html +10 -0
  63. package/docs-site/content/security.html +1 -0
  64. package/docs-site/context-engine.html +9 -2
  65. package/docs-site/index.html +1 -1
  66. package/docs-site/mcp-approval.html +1 -1
  67. package/docs-site/mcp-auth.html +1 -1
  68. package/docs-site/mcp-servers.html +1 -1
  69. package/docs-site/mcp.html +1 -1
  70. package/docs-site/permissions.html +1 -1
  71. package/docs-site/profiles.html +1 -1
  72. package/docs-site/quickstart.html +1 -1
  73. package/docs-site/runtime.html +11 -1
  74. package/docs-site/scope.html +1 -1
  75. package/docs-site/security.html +2 -1
  76. package/docs-site/team.html +1 -1
  77. package/docs-site/workflows.html +1 -1
  78. package/evals/fixtures/task-contract.invalid.json +15 -1
  79. package/evals/fixtures/task-contract.valid.json +18 -2
  80. package/package.json +3 -2
  81. package/packages/piagent-core/README.md +43 -4
  82. package/packages/piagent-core/benchmark/benchmark-core.js +691 -0
  83. package/packages/piagent-core/extensions/context-engine.js +209 -120
  84. package/packages/piagent-core/extensions/context-index-policy.js +1 -1
  85. package/packages/piagent-core/extensions/guard-types.ts +35 -3
  86. package/packages/piagent-core/extensions/local-state-path.js +59 -0
  87. package/packages/piagent-core/extensions/piagent-guard.ts +2073 -222
  88. package/packages/piagent-core/extensions/policy-core.js +11 -1
  89. package/packages/piagent-core/extensions/runtime-evidence.js +39 -19
  90. package/packages/piagent-core/extensions/state-retention.js +218 -0
  91. package/packages/piagent-core/extensions/task-lifecycle.js +138 -0
  92. package/packages/piagent-core/extensions/task-state.js +630 -0
  93. package/packages/piagent-core/mcp/mcp-config-layers.js +52 -6
  94. package/packages/piagent-core/mcp/mcp-tool-naming.js +12 -1
  95. package/packages/piagent-core/package.json +1 -1
  96. package/packages/piagent-core/policies/base-policy.json +1 -0
  97. package/packages/piagent-core/prompts/be-to-fe.md +14 -22
  98. package/packages/piagent-core/prompts/platform-improve.md +12 -17
  99. package/packages/piagent-core/prompts/review.md +7 -11
  100. package/packages/piagent-core/prompts/scout.md +6 -10
  101. package/packages/piagent-core/prompts/task.md +11 -17
  102. package/packages/piagent-core/skills/piagent-ops/SKILL.md +12 -15
  103. package/packages/piagent-core/subagents/piagent-reviewer.md +3 -3
  104. package/schemas/task-contract.schema.json +267 -104
  105. package/scripts/benchmark-runner.mjs +1172 -0
  106. package/scripts/install-global.sh +1 -1
  107. package/scripts/migrate-project-state.mjs +94 -3
  108. package/scripts/piagent-cli.mjs +1 -1
  109. package/scripts/update-global.mjs +36 -3
  110. package/scripts/verify-local.sh +15 -0
  111. package/templates/project/.pi/task-contract.template.json +19 -2
  112. package/templates/project/AGENTS.md +10 -20
@@ -0,0 +1,3 @@
1
+ export function tokenize(value) {
2
+ return value.toLowerCase().split(/\s+/).filter(Boolean);
3
+ }
@@ -0,0 +1,7 @@
1
+ import assert from "node:assert/strict";
2
+ import test from "node:test";
3
+ import { isSessionValid } from "../src/auth/session.js";
4
+
5
+ test("accepts a future expiry", () => {
6
+ assert.equal(isSessionValid({ expiresAt: 101 }, 100), true);
7
+ });
@@ -0,0 +1,4 @@
1
+ The authentication session expiry check is inverted. A session is valid when
2
+ its `expiresAt` timestamp is later than `now`; equality is expired. Fix this
3
+ without touching unrelated catalog, billing, notification, or search modules.
4
+ Keep the exported API and run the configured verification command.
@@ -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"
@@ -89,8 +89,8 @@
89
89
  "path": "packages/piagent-core/subagents/piagent-planner.md"
90
90
  },
91
91
  {
92
- "byteSize": 1601,
93
- "digest": "sha256:be1ec2282db3038717c1e66e91e3890b8d0d665fed039c903cc1e4a3c427f69e",
92
+ "byteSize": 1604,
93
+ "digest": "sha256:ee050d70faba909a9b8f82d24a63d8bad90178380d266af0d071010538bc8d3c",
94
94
  "id": "piagent-reviewer",
95
95
  "kind": "subagents",
96
96
  "path": "packages/piagent-core/subagents/piagent-reviewer.md"
@@ -177,11 +177,14 @@ Alias `/commit` và `/pr` vẫn chạy. Commit workflow chỉ tạo local commit
177
177
 
178
178
  | Tình huống | Cách dùng | Kết quả |
179
179
  |---|---|---|
180
- | Chat box trả ra local path ảnh | `/workflow scout Check screenshot /var/folders/.../screenshot.png` | Platform attach ảnh và rewrite path thành `[image1]`. |
180
+ | Chat box trả ra local path ảnh | `/workflow scout Check screenshot ~/Documents/team-screenshots/screenshot.png` | Platform attach ảnh nếu file ở trong project hoặc folder đã cấp bằng `additionalReadRoots`, rồi rewrite path thành `[image1]`. |
181
181
  | Nhiều ảnh trong cùng prompt | Dán tối đa 4 path ảnh | Prompt có `[image1]`, `[image2]`, ... |
182
182
  | Ảnh quá lớn | Dùng Pi `read` tool trên file ảnh hoặc resize ảnh trước | Tránh nhồi ảnh quá lớn vào chat input. |
183
183
 
184
- Định dạng hỗ trợ: `.png`, `.jpg`, `.jpeg`, `.gif`, `.webp`, `.bmp`. Giới hạn mặc định: 4 ảnh/input, 8 MB/ảnh.
184
+ Định dạng hỗ trợ: `.png`, `.jpg`, `.jpeg`, `.gif`, `.webp`, `.bmp`. Giới hạn
185
+ mặc định: 4 ảnh/input, 8 MB/ảnh. Protected path, symlink đi khỏi readable root,
186
+ file ngoài capability read scope và file chỉ giả đuôi ảnh đều bị từ chối trước
187
+ khi bytes được attach.
185
188
 
186
189
  Profile name nên biết:
187
190
 
@@ -465,8 +468,8 @@ Các lệnh này chạy ngoài Pi.
465
468
  | Command | Dùng khi nào |
466
469
  |---|---|
467
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. |
468
- | `npm install -g --ignore-scripts @piagent/platform@1.2.9` | Cài terminal helper `piagent-*` từ release tag hiện tại. |
469
- | `pi install git:github.com/Vt-mmm/piagent@v1.2.9` | 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. |
470
473
  | `pi install git:github.com/Vt-mmm/piagent` | Cài latest package platform cho máy cá nhân/sandbox. |
471
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ì. |
472
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. |
@@ -508,11 +511,12 @@ Các lệnh này chạy ngoài Pi.
508
511
  | `piagent-uninstall --apply` | Gỡ Pi package của platform khỏi Pi settings global. |
509
512
  | `piagent-uninstall --apply --with-addons --with-host` | Gỡ thêm pi-mcp-adapter, pi-subagents, pi-web-access và Pi host. |
510
513
  | `piagent-uninstall --apply --project /path/to/project` | Gỡ thêm state của platform trong project: profile, lock, `piagent-state/`. |
511
- | `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. |
512
516
  | `bash scripts/verify-local.sh` | Verify repo platform trước khi commit/tag. |
513
517
  | `bash scripts/verify-local.sh --offline` | Verify trong CI/máy sạch, bỏ qua local Pi model catalog. |
514
518
  | `bash scripts/setup.sh <project> ...` | Preseed setup project; không bắt buộc cho daily flow. |
515
- | `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. |
516
520
 
517
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).
518
522
 
@@ -525,7 +529,7 @@ Khi đang develop chính repo `piagent`, có thể dùng npm scripts tương ứ
525
529
  | `npm run install-global` | `bash scripts/install-global.sh` |
526
530
  | `npm run init-project -- <project>` | `bash scripts/init-project.sh <project>` |
527
531
  | `npm run doctor -- <project> --strict-share` | `bash scripts/team-doctor.sh <project> --strict-share` |
528
- | `npm run benchmark -- ...` | `bash scripts/quality-benchmark.sh ...` |
532
+ | `npm run benchmark -- ...` | `node scripts/benchmark-runner.mjs ...` |
529
533
  | `npm run usage -- <project>` | `bash scripts/pi-session-stats.sh <project>` |
530
534
  | `npm run usage -- --history <project> --days 7` | `bash scripts/pi-session-stats.sh --history <project> --days 7` |
531
535
  | `npm run models` | `bash scripts/pi-model-catalog.sh` |
@@ -567,7 +571,10 @@ export GITHUB_PERSONAL_ACCESS_TOKEN=<github-token>
567
571
  | Subagents tốn bao nhiêu? | `/subagent-cost` |
568
572
  | Có nên compact chưa? | Xem `contextUsage.percent`; trên 75% mới cân nhắc `/compact`. |
569
573
 
570
- 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.
571
578
 
572
579
  ## Source rule cho subagent/custom agent
573
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
@@ -59,6 +73,25 @@ dụng record có `mtime` và size không đổi. `.gitignore`, binary, file qu
59
73
  secret file, protected paths, dependency/build output và toàn bộ guard state
60
74
  không được index.
61
75
 
76
+ Index chứa source body của những file được phép index, không chỉ metadata. Vì
77
+ vậy directory `context-engine/` được giữ mode `0700`; SQLite database, WAL và
78
+ SHM được giữ mode `0600`. Đây là ranh giới giữa các OS account trên cùng máy,
79
+ không chặn process khác đang chạy bằng chính account của operator.
80
+
81
+ Mỗi SQLite connection bật cả core `secure_delete` và FTS5 `secure-delete`.
82
+ Refresh cùng policy vì vậy xóa source cũ khỏi ordinary table lẫn full-text
83
+ index mà không chạy full compaction. Khi exclusion digest đổi, policy version
84
+ `2` commit digest mới cùng `purgePending: 1` trước khi dựng lại FTS index từ
85
+ content table đã lọc, checkpoint WAL rồi chạy `VACUUM`. Cờ pending chỉ clear
86
+ sau khi toàn bộ chuỗi thành công; app hoặc máy dừng giữa chừng thì lần mở tiếp
87
+ theo tự retry.
88
+
89
+ FTS rebuild và `VACUUM` chỉ chạy khi policy đổi hoặc purge trước còn pending,
90
+ không chạy ở mỗi refresh. Trong lúc `VACUUM`, máy có thể cần tạm thời gần gấp
91
+ đôi dung lượng file database. Xem mô tả chính thức về
92
+ [FTS5 rebuild/secure-delete](https://www.sqlite.org/fts5.html) và
93
+ [VACUUM](https://www.sqlite.org/lang_vacuum.html).
94
+
62
95
  Symbol layer hiện dùng parser adapter zero-dependency cho TypeScript/JavaScript,
63
96
  Python, Go, Rust, Java/Kotlin/C#, C/C++, Swift, Dart, Ruby, PHP, Elixir, Lua,
64
97
  SQL và Markdown. Schema parser-neutral để có thể thêm Tree-sitter sau này mà
@@ -82,15 +115,17 @@ score(file) = sum(weight(source) / (60 + rank(source, file)))
82
115
  ```
83
116
 
84
117
  Context pack tách repo map và source snippets, sau đó dừng cứng tại token
85
- budget. Index chỉ là navigation evidence; model phải đọc file hiện tại trước
86
- 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.
87
122
 
88
- Các API có thể build hoặc đọc nội dung (`build`, `ensure`, `search`, `pack`,
123
+ Tất cả API chạm context index (`build`, `status`, `ensure`, `search`, `pack`,
89
124
  `impact`) bắt buộc caller truyền `excludePatterns` tường minh và fail-closed
90
125
  nếu thiếu. Runtime và CLI lấy danh sách này từ shared project policy resolver;
91
- low-level tool hoặc test chỉ dùng `[]` khi chủ ý chọn không loại trừ. API
92
- `status` vẫn có thể đọc metadata mà không cần policy vì nó không đọc source
93
- content.
126
+ low-level tool hoặc test chỉ dùng `[]` khi chủ ý chọn không loại trừ. Dù
127
+ `status` không trả source content, nó vẫn cần policy để không báo false-negative
128
+ `policyStale: false` rồi khiến caller bỏ qua rebuild.
94
129
 
95
130
  ## P2: compaction, finder và test impact
96
131
 
@@ -127,8 +162,14 @@ Mỗi event có:
127
162
  ```
128
163
 
129
164
  Agent Watch có thể join event với Pi session JSONL bằng `sessionId` và
130
- `sessionName`. Không cần polling realtime; import lúc mở app hoặc lúc xuất
131
- 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.
132
173
 
133
174
  Feedback không phải model học ngầm. Khi một context pack chọn file và chính
134
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.9` |
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.9` |
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.9` | 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.9
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.9
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.9` 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.9`.
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.9 \
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
 
@@ -137,6 +137,13 @@ Vì vậy một config đặt `directTools: true` cùng `toolPrefix: "none"` là
137
137
 
138
138
  Adapter **merge `settings` của cả bốn layer thành một block cho cả session**, layer sau ghi đè theo từng key — không phải per-server. Nên `directTools` đặt ở file này và `toolPrefix: "none"` đặt ở file kia vẫn ra đúng tổ hợp đó, trong khi đọc riêng từng file thì không file nào có vấn đề. Platform đọc settings đã merge, và báo cả hai file, vì sửa file nào cũng đủ.
139
139
 
140
+ Adapter cũng hỗ trợ `directTools: true` hoặc danh sách tool ngay trên từng server,
141
+ và giá trị per-server override default trong `settings`. Platform vì vậy resolve
142
+ effective server entry, không chỉ đọc settings: nếu một repository server có
143
+ direct tool hiệu lực trong khi prefix là `none`, guard và
144
+ `piagent-mcp doctor` cùng fail-closed. Khi prefix vẫn là `server`/`short`, direct
145
+ tool đã approve tiếp tục chạy bình thường.
146
+
140
147
  ### `imports` — server không nằm trong bốn scope
141
148
 
142
149
  Adapter nhận thêm key `imports` trong config MCP, để kéo định nghĩa server từ config của công cụ khác. Server vào session theo đường này **không** xuất hiện ở scope nào trong bốn scope trên, nên trước đây gate không thấy chúng.
@@ -446,13 +453,18 @@ Search/list channels cũng được kiểm:
446
453
 
447
454
  ## Built-in platform tools
448
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
+
449
461
  | Tool | Intent |
450
462
  |---|---|
451
463
  | `piagent_context` | Active profile/context/verify/MCP/memory overview. |
452
- | `piagent_exec_policy_check` | Evaluate shell command before running. |
453
- | `piagent_context_budget` | Check candidate context files against hard caps. |
454
- | `piagent_tool_policy_check` | Check tool capability registration. |
455
- | `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. |
456
468
  | `piagent_memory_status` | Project memory policy/files/rules. |
457
469
  | `piagent_memory_search` | Keyword search `.pi/memory` markdown. |
458
470
  | `piagent_memory_note` | Append explicit durable memory note. |
@@ -466,9 +478,10 @@ Search/list channels cũng được kiểm:
466
478
  | `piagent_profile_tech_apply` | Apply profile + selected role tech stack and Context7 placeholders. |
467
479
  | `piagent_profile_tech_context_record` | Record a concise Context7 evidence snapshot for a selected tech. |
468
480
  | `piagent_task_start` | Create Task Implementation Contract. |
469
- | `piagent_context_record` | Record context manifest for task. |
470
- | `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`. |
471
- | `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. |
472
485
 
473
486
  ## Core capabilities
474
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;