@piagent/platform 1.2.4 → 1.2.6

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 (49) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/README.md +3 -2
  3. package/catalog/capabilities.json +4 -4
  4. package/docs/command-reference-vietnamese.md +9 -8
  5. package/docs/context-engine.md +177 -0
  6. package/docs/context-window-policy.md +13 -8
  7. package/docs/distribution-standard.md +7 -7
  8. package/docs/operator-manual-vietnamese.md +7 -7
  9. package/docs/publishing-for-teams.md +4 -0
  10. package/docs/quality-benchmark.md +14 -1
  11. package/docs/release-install-policy.md +6 -6
  12. package/docs/runtime-harness-standard.md +16 -7
  13. package/docs/security-threat-model.md +1 -1
  14. package/docs/task-lifecycle-vietnamese.md +4 -4
  15. package/docs/team-onboarding.md +2 -2
  16. package/docs/usage-observability.md +6 -0
  17. package/docs-site/architecture.html +4 -3
  18. package/docs-site/commands.html +2 -1
  19. package/docs-site/content/context-engine.html +47 -0
  20. package/docs-site/context-engine.html +171 -0
  21. package/docs-site/index.html +2 -1
  22. package/docs-site/mcp-approval.html +2 -1
  23. package/docs-site/mcp-auth.html +2 -1
  24. package/docs-site/mcp-servers.html +2 -1
  25. package/docs-site/mcp.html +2 -1
  26. package/docs-site/permissions.html +2 -1
  27. package/docs-site/profiles.html +2 -1
  28. package/docs-site/quickstart.html +2 -1
  29. package/docs-site/runtime.html +4 -3
  30. package/docs-site/scope.html +2 -1
  31. package/docs-site/security.html +2 -1
  32. package/docs-site/team.html +2 -1
  33. package/docs-site/workflows.html +2 -1
  34. package/package.json +3 -2
  35. package/packages/piagent-core/README.md +8 -2
  36. package/packages/piagent-core/capabilities/capability-core.js +4 -0
  37. package/packages/piagent-core/extensions/context-engine.js +1175 -0
  38. package/packages/piagent-core/extensions/piagent-guard.ts +785 -17
  39. package/packages/piagent-core/package.json +1 -1
  40. package/packages/piagent-core/policies/base-policy.json +2 -0
  41. package/packages/piagent-core/prompts/scout.md +10 -24
  42. package/packages/piagent-core/prompts/task.md +25 -45
  43. package/scripts/build-docs-site.mjs +6 -0
  44. package/scripts/context-engine.mjs +115 -0
  45. package/scripts/install-global.sh +14 -1
  46. package/scripts/piagent-cli.mjs +2 -1
  47. package/scripts/quality-benchmark.sh +71 -1
  48. package/scripts/update-global.mjs +7 -1
  49. package/scripts/verify-local.sh +8 -0
package/CHANGELOG.md CHANGED
@@ -2,6 +2,32 @@
2
2
 
3
3
  This file records release-facing changes for Pi Agent Platform. Copy the relevant version block into GitHub Releases when publishing a tag.
4
4
 
5
+ ## v1.2.6 - 2026-07-31
6
+
7
+ ### Added
8
+
9
+ - Added Pi Context Engine v2: a local incremental SQLite FTS5 index with symbol and import extraction, hybrid Reciprocal Rank Fusion and personalized PageRank retrieval, hard-budget context packs, reverse-import test impact, and the `piagent-context` terminal command.
10
+
11
+ - Added Agent Watch compatible context telemetry keyed by Pi session ID and session name. It records model/thinking metadata, active tool counts, usage, retrieval confidence, context-pack utilization, duplicate reads/output, and transparent context-waste metrics without duplicating raw prompts or tool output.
12
+
13
+ ### Changed
14
+
15
+ - Piagent now starts with a one-tool loader and activates governance, policy, code retrieval, knowledge, onboarding, and usage groups by task shape. Tiny tasks expose 11 of 30 Piagent tools and ordinary tasks expose 15, while runtime guards remain active regardless of the visible tool schema.
16
+
17
+ - Task and scout workflows are risk-adaptive. Unfamiliar work receives one bounded Context Engine pack, low-confidence retrieval permits at most one read-only finder pass, repeated read/search results collapse to a delta marker, and session compaction preserves task state instead of raw logs.
18
+
19
+ - Quality benchmarks now record fresh input, output and cache-read tokens, first-correct-edit time, rework count, and a context-efficiency snapshot so token savings are compared against acceptance and verification quality.
20
+
21
+ ### Fixed
22
+
23
+ - Release installation now removes an older local `@piagent/platform` registration as well as older Git registrations before installing the pinned release, preventing the local checkout and released package from loading together.
24
+
25
+ ## v1.2.5 - 2026-07-30
26
+
27
+ ### Fixed
28
+
29
+ - `piagent-update` now accepts npm 12's singleton-array `npm view --json` output when resolving the target helper version and its pinned Pi host peer dependency. Empty or multi-entry metadata still fails closed, so the updater never guesses which release or host to install.
30
+
5
31
  ## v1.2.4 - 2026-07-30
6
32
 
7
33
  ### Changed
package/README.md CHANGED
@@ -74,7 +74,7 @@ Removal targets what is registered in Pi's settings rather than what the current
74
74
  - Runtime profile selection via `/profile`, plus select-style tech stack setup via `/profile setup` and `/profile tech`.
75
75
  - Runtime usage/session controls via `/usage`, `/name`, `/fresh`, plus Pi native `/session`.
76
76
  - Explicit project memory via `/memory` or `/memory-policy` and `piagent_memory_*` tools.
77
- - Compact project context controls via `/context` or `/context index` and `piagent_context_index_*` tools. This is an advisory navigation graph, not a security boundary or source of truth.
77
+ - Local Context Engine controls via `/context`: incremental code index, hybrid search, token-budgeted packs, test impact, efficiency telemetry, and semantic compaction. Results remain advisory, not a security boundary or source of truth.
78
78
  - MCP setup helpers for Context7, Chrome DevTools, GitHub, Playwright, and Figma.
79
79
  - Subagent setup helpers for read-only scouting, planning, implementation, review, and risk challenge.
80
80
  - Chat image-path intake: paste a local screenshot path into the Pi chat box and the guard attaches it as `[image1]` before the model sees the prompt.
@@ -261,6 +261,7 @@ This repository intentionally excludes:
261
261
  - [Operator manual tiếng Việt](docs/operator-manual-vietnamese.md)
262
262
  - [Quickstart tiếng Việt](docs/quickstart-vietnamese.md)
263
263
  - [Command reference tiếng Việt](docs/command-reference-vietnamese.md)
264
+ - [Pi Context Engine](docs/context-engine.md)
264
265
  - [Team onboarding](docs/team-onboarding.md)
265
266
  - [Project onboarding](docs/project-onboarding.md)
266
267
  - [Workflow recipes](docs/workflow-recipes.md)
@@ -290,7 +291,7 @@ This repository intentionally excludes:
290
291
 
291
292
  ## Maturity
292
293
 
293
- The current package version is read from package metadata and release tags. Personal machines may follow the unpinned package source when accepting ongoing updates; production/team quickstarts and committed project settings should pin an explicit tag such as `v1.2.4` or a reviewed commit.
294
+ The current package version is read from package metadata and release tags. Personal machines may follow the unpinned package source when accepting ongoing updates; production/team quickstarts and committed project settings should pin an explicit tag such as `v1.2.6` or a reviewed commit.
294
295
 
295
296
  Ready for:
296
297
 
@@ -26,8 +26,8 @@
26
26
  "path": "evals/scenarios/capability-resolution.json"
27
27
  },
28
28
  {
29
- "byteSize": 6146,
30
- "digest": "sha256:a7a975b99ed2f45881d110582fb6990c500f7e081f865230bf9e4ae242cdd81e",
29
+ "byteSize": 6201,
30
+ "digest": "sha256:35398d414c6fd57f63c81990881410ad4286074c2c63fbf53a808b6cfb27b343",
31
31
  "id": "base-policy",
32
32
  "kind": "policies",
33
33
  "path": "packages/piagent-core/policies/base-policy.json"
@@ -61,8 +61,8 @@
61
61
  "path": "packages/piagent-core/prompts/review.md"
62
62
  },
63
63
  {
64
- "byteSize": 5073,
65
- "digest": "sha256:1dd1339b1e0d8e5882595a38da1781e5b8f59d96afdf4dcdc45c6a77ad7ccfe5",
64
+ "byteSize": 3452,
65
+ "digest": "sha256:d06f189c7cf6484cc60d79c200e85ff60f543651264b9233cb23686145cc35d8",
66
66
  "id": "task",
67
67
  "kind": "prompts",
68
68
  "path": "packages/piagent-core/prompts/task.md"
@@ -37,8 +37,8 @@ Command ngắn của PiAgent dùng cho workflow và guard local:
37
37
  |---|---|
38
38
  | `/commands` | Menu/help command, không gọi model. |
39
39
  | `/workflow` | Launcher task/scout/plan/review/git/onboard. |
40
- | `/usage` | Usage live/history/preflight/compact/logs. |
41
- | `/context` | Context index/search/preflight/compact. |
40
+ | `/usage` | Usage live/history/preflight/compact/logs/efficiency. |
41
+ | `/context` | Smart index/rebuild/search/pack/impact/efficiency/preflight/compact. |
42
42
  | `/permission` | Permission mode của session. |
43
43
  | `/profile` | Profile và tech stack. |
44
44
  | `/memory` | Project memory policy. |
@@ -65,6 +65,7 @@ Trong Pi:
65
65
  /commands
66
66
  /onboard
67
67
  /context index
68
+ /context rebuild
68
69
  /memory
69
70
  ```
70
71
 
@@ -107,10 +108,10 @@ Nếu task còn mơ hồ:
107
108
  Pi Agent dùng ít namespace nhưng mỗi namespace có subcommand/menu rõ:
108
109
 
109
110
  - `/workflow` là cửa chính cho task/scout/review/git/onboard workflow. Workflow cần agent turn là cố ý và được nói rõ.
110
- - `/usage` gom live usage, history/report hint, preflight, compact, logs.
111
+ - `/usage` gom live usage, history/report hint, preflight, compact, logs, efficiency.
111
112
  - `/name` đặt tên session theo task để Agent Watch/report map đúng việc.
112
113
  - `/fresh` mở session mới cho `task`, `scout`, hoặc `be-to-fe` khi phiên hiện tại đã nặng.
113
- - `/context` gom context index, search, preflight, compact.
114
+ - `/context` gom architecture map, code index, search, context pack, test impact, efficiency, preflight và semantic compact.
114
115
  - `/permission` gom permission status/read-only/workspace-write/full-access.
115
116
  - `/profile` là namespace duy nhất cho profile và tech stack.
116
117
  - `/commands` là runtime help/menu, không còn bắt agent đọc docs để giải thích.
@@ -137,10 +138,10 @@ Các command này đến từ package `piagent-core`.
137
138
  | `/onboard` | First-run setup/status. | Mở menu onboarding: status, run, profile, setup. |
138
139
  | `/profile` | Xem/áp profile và chọn tech. | Chạy ngay, không gọi model. |
139
140
  | `/profile setup` | Chọn profile + tech bằng option. | Ghi profile/lock/tech manifest. |
140
- | `/usage` | Xem live usage hoặc report hint. | Menu live/history/preflight/compact/logs. |
141
+ | `/usage` | Xem live usage hoặc report hint. | Menu live/history/preflight/compact/logs/efficiency. |
141
142
  | `/name <name>` | Đặt tên session theo task. | Agent Watch/report map đúng task. |
142
143
  | `/fresh task|scout|be-to-fe <request>` | Phiên hiện tại đã nặng hoặc muốn tách việc. | Mở session mới có tên và replay workflow prompt gọn. |
143
- | `/context` | Xem context index/search/preflight/compact. | Menu context, không gọi model. |
144
+ | `/context` | Xem index/search/pack/impact/efficiency/preflight/compact. | Menu context, không gọi model. |
144
145
  | `/permission` | Xem/đổi quyền runtime. | Menu status/read-only/workspace-write/full-access. |
145
146
  | `/memory` hoặc `/memory-policy` | Xem memory policy. | Chạy ngay, không gọi model. |
146
147
  | `/model-options` | Xem hướng dẫn model/thinking. | Chạy ngay; chọn model vẫn dùng `/model` hoặc `Ctrl+L`. |
@@ -464,8 +465,8 @@ Các lệnh này chạy ngoài Pi.
464
465
  | Command | Dùng khi nào |
465
466
  |---|---|
466
467
  | `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. |
467
- | `npm install -g --ignore-scripts @piagent/platform@1.2.4` | Cài terminal helper `piagent-*` từ release tag hiện tại. |
468
- | `pi install git:github.com/Vt-mmm/piagent@v1.2.4` | Cài pinned release khi cần reproducible team setup. |
468
+ | `npm install -g --ignore-scripts @piagent/platform@1.2.6` | Cài terminal helper `piagent-*` từ release tag hiện tại. |
469
+ | `pi install git:github.com/Vt-mmm/piagent@v1.2.6` | Cài pinned release khi cần reproducible team setup. |
469
470
  | `pi install git:github.com/Vt-mmm/piagent` | Cài latest package platform cho máy cá nhân/sandbox. |
470
471
  | `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ì. |
471
472
  | `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. |
@@ -0,0 +1,177 @@
1
+ # Pi Context Engine
2
+
3
+ ## Mục tiêu
4
+
5
+ Pi Context Engine giảm token bằng cách giảm context nhiễu, không đổi model chính
6
+ và không hạ thinking level. Runtime chọn đúng tool, file, symbol và test trước khi
7
+ model bắt đầu scout rộng.
8
+
9
+ ```text
10
+ task
11
+ -> deterministic task signals
12
+ -> dynamic tool groups
13
+ -> explicit path + FTS5 + symbol/import graph + git/test signals
14
+ -> Reciprocal Rank Fusion + personalized PageRank
15
+ -> token-budgeted context pack
16
+ -> selected parent model
17
+ -> delta tool results + semantic compaction
18
+ -> local telemetry for Agent Watch
19
+ ```
20
+
21
+ ## P0: runtime context controls
22
+
23
+ - Piagent tools được chia thành `governance`, `policy`, `retrieval`,
24
+ `knowledge`, `onboarding`, và `usage`. Code retrieval không tự kéo theo
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.
30
+ - Tool order cố định để giữ prompt prefix ổn định cho provider có prompt cache.
31
+ - Read/grep/find/ls lặp lại với cùng input và cùng output trả delta marker thay
32
+ vì chèn lại toàn bộ kết quả.
33
+ - Telemetry không lưu prompt hoặc tool output thô. Nó lưu hash, kích thước, tool,
34
+ model, thinking, active-tool count, usage, retrieval confidence và đường dẫn
35
+ tương đối đã được guard redaction.
36
+
37
+ Rollback flags:
38
+
39
+ ```bash
40
+ PIAGENT_DYNAMIC_TOOLS=off pi
41
+ PIAGENT_AUTO_CONTEXT=off pi
42
+ PIAGENT_CONTEXT_TELEMETRY=off pi
43
+ ```
44
+
45
+ ## P1: code index và retrieval
46
+
47
+ Index nằm tại:
48
+
49
+ ```text
50
+ .pi/piagent-state/context-engine/context-v2.sqlite
51
+ ```
52
+
53
+ Nó dùng SQLite FTS5 có sẵn trong Node.js `>=22.19.0`, không cần native package
54
+ hoặc install script. File được nhận diện bằng SHA-256; lần refresh sau tái sử
55
+ dụng record có `mtime` và size không đổi. `.gitignore`, binary, file quá lớn,
56
+ secret file, protected paths, dependency/build output và toàn bộ guard state
57
+ không được index.
58
+
59
+ Symbol layer hiện dùng parser adapter zero-dependency cho TypeScript/JavaScript,
60
+ Python, Go, Rust, Java/Kotlin/C#, C/C++, Swift, Dart, Ruby, PHP, Elixir, Lua,
61
+ SQL và Markdown. Schema parser-neutral để có thể thêm Tree-sitter sau này mà
62
+ không migrate consumer. Tree-sitter không phải dependency mặc định vì native
63
+ grammar size và install reliability phải thắng benchmark trước khi rollout.
64
+
65
+ Candidate ranking gồm:
66
+
67
+ 1. Explicit path/basename.
68
+ 2. FTS5 BM25 lexical match.
69
+ 3. Exact và partial symbol match.
70
+ 4. Current Git changes.
71
+ 5. Test filename/path relation.
72
+ 6. Positive-only session feedback.
73
+ 7. Personalized PageRank trên import graph.
74
+
75
+ Các ranked list được hợp nhất bằng Reciprocal Rank Fusion:
76
+
77
+ ```text
78
+ score(file) = sum(weight(source) / (60 + rank(source, file)))
79
+ ```
80
+
81
+ Context pack tách repo map và source snippets, sau đó dừng cứng tại token
82
+ budget. Index chỉ là navigation evidence; model phải đọc file hiện tại trước
83
+ khi edit.
84
+
85
+ ## P2: compaction, finder và test impact
86
+
87
+ - `/context impact` đi ngược import graph từ file thay đổi và tìm test liên quan.
88
+ - Context pack trả `high`, `medium`, `low`, hoặc `none` confidence.
89
+ - Với `low/none`, runtime đề xuất đúng một bounded read-only finder pass, không
90
+ tự spawn và không tự đổi model.
91
+ - `/context compact` giữ goal, acceptance criteria, quyết định, invariant,
92
+ changed files, verify evidence, blocker và next action. Nó loại log thô,
93
+ repeated reads, kế hoạch đã bị thay thế và source excerpt có thể đọc lại.
94
+
95
+ ## P3: Agent Watch telemetry và feedback
96
+
97
+ Event append-only nằm tại:
98
+
99
+ ```text
100
+ .pi/piagent-state/context-engine/events.jsonl
101
+ .pi/piagent-state/context-engine/efficiency-report.json
102
+ ```
103
+
104
+ Mỗi event có:
105
+
106
+ ```json
107
+ {
108
+ "schemaVersion": 1,
109
+ "source": "piagent",
110
+ "recordedAt": "ISO-8601",
111
+ "event": "agent_prompt | tool_activation | context_pack | tool_call | tool_result | turn_end | session_compact",
112
+ "sessionId": "Pi session id",
113
+ "sessionName": "operator session name",
114
+ "model": "provider/model",
115
+ "thinkingLevel": "off|minimal|low|medium|high|xhigh"
116
+ }
117
+ ```
118
+
119
+ Agent Watch có thể join event với Pi session JSONL bằng `sessionId` và
120
+ `sessionName`. Không cần polling realtime; import lúc mở app hoặc lúc xuất
121
+ report vẫn thấy đủ event đã ghi.
122
+
123
+ Feedback không phải model học ngầm. Khi một context pack chọn file và chính
124
+ session đó sau đó thực sự đọc hoặc sửa file, file nhận một boost nhỏ ở những
125
+ lần retrieval sau. File chưa có lịch sử hoặc từng được chọn nhưng chưa dùng
126
+ không bị trừ điểm. `contextSelections`, `contextSelectionsUsed` và
127
+ `contextUtilizationRate` trong efficiency report cho phép audit hiệu quả của
128
+ ranking. Runtime chỉ đọc phần đuôi telemetry có giới hạn khi tính report hoặc
129
+ feedback, nên lịch sử dài không làm chậm từng prompt theo thời gian.
130
+
131
+ `contextWasteScore` nằm trong khoảng `0..100`, thấp hơn là tốt hơn:
132
+
133
+ ```text
134
+ 30% duplicate read rate
135
+ 25% duplicate output rate
136
+ 20% tool schema share
137
+ 15% low-confidence retrieval rate
138
+ 10% active-tool excess
139
+ ```
140
+
141
+ Đây là operational signal, không phải quality verdict. Report phải đối chiếu
142
+ với task gate, acceptance result, verify evidence, token usage và rework.
143
+
144
+ ## Sử dụng
145
+
146
+ Trong Pi:
147
+
148
+ ```text
149
+ /context index
150
+ /context rebuild
151
+ /context search <symbol or keyword>
152
+ /context pack <task>
153
+ /context impact [changed files]
154
+ /context efficiency
155
+ /usage efficiency
156
+ ```
157
+
158
+ Ngoài terminal, không chạy model:
159
+
160
+ ```bash
161
+ piagent-context status
162
+ piagent-context rebuild
163
+ piagent-context search calculateInvoiceTotal
164
+ piagent-context pack "Fix invoice total calculation" --tokens 4000
165
+ piagent-context impact src/invoice.ts
166
+ piagent-context efficiency
167
+ ```
168
+
169
+ ## Benchmark gate
170
+
171
+ So sánh cùng task, repository commit, model, thinking và verify command. Mỗi
172
+ variant chạy ít nhất ba lần. Chỉ bật mặc định khi:
173
+
174
+ - acceptance/pass rate không giảm;
175
+ - rework và failed verification không tăng;
176
+ - fresh input tokens, duplicate reads và time-to-first-correct-edit giảm;
177
+ - protected-path, secret-redaction và final-gate tests vẫn pass.
@@ -4,19 +4,20 @@
4
4
 
5
5
  Không nhồi toàn bộ repo vào context. Agent phải load đúng lớp context theo task.
6
6
 
7
- Lần đầu gắn project vào platform, chạy `/onboard run` sau login/model selection để tạo `.pi/project-context.md` và `.pi/context-index.json`. Các task sau dùng context index như bản đồ nhỏ để tìm đúng vùng cần đọc, rồi vẫn verify bằng files task-specific hiện tại.
7
+ Lần đầu gắn project vào platform, chạy `/onboard run` sau login/model selection để tạo `.pi/project-context.md`, `.pi/context-index.json` và local Context Engine index. Các task sau dùng index như bản đồ nhỏ để tìm đúng vùng cần đọc, rồi vẫn verify bằng files task-specific hiện tại.
8
8
 
9
9
  ## Context order
10
10
 
11
11
  1. `AGENTS.md` gần project nhất.
12
12
  2. Project profile: `.pi/piagent-profile.json`.
13
- 3. Project context index: `.pi/context-index.json` nếu tồn tại và không stale.
14
- 4. Project context snapshot: `.pi/project-context.md`.
15
- 5. Memory summary nếu profile bật memory và task liên quan: `.pi/memory/memory_summary.md`.
16
- 6. Required context từ profile.
17
- 7. Task-specific files.
18
- 8. Related tests/docs.
19
- 9. External docs only khi cần và ưu tiên official docs.
13
+ 3. Context Engine pack cho task unfamiliar/cross-module nếu index tồn tại và không stale.
14
+ 4. Project context index: `.pi/context-index.json` nếu tồn tại và không stale.
15
+ 5. Project context snapshot: `.pi/project-context.md`.
16
+ 6. Memory summary nếu profile bật memory và task liên quan: `.pi/memory/memory_summary.md`.
17
+ 7. Required context từ profile.
18
+ 8. Task-specific files.
19
+ 9. Related tests/docs.
20
+ 10. External docs only khi cần và ưu tiên official docs.
20
21
 
21
22
  Trước khi ghi context manifest hoặc dự định đưa file lớn vào prompt, dùng:
22
23
 
@@ -30,6 +31,7 @@ Trước task lớn/risk cao trong Pi TUI:
30
31
 
31
32
  ```text
32
33
  /context preflight
34
+ /context pack <task>
33
35
  /context compact
34
36
  ```
35
37
 
@@ -72,6 +74,8 @@ Pi settings template dùng:
72
74
  - Không paste full mandatory-flow boilerplate vào task hằng ngày; platform prompts/tools đã chứa flow đó.
73
75
  - Nếu context vượt budget, tạo summary theo module thay vì nhồi full files.
74
76
  - Dùng `/context search` hoặc `piagent_context_index_search` để tìm điểm vào repo, nhưng không dùng index thay thế việc đọc source thật.
77
+ - Dùng `/context rebuild` sau structural changes; incremental refresh tái sử dụng file không đổi.
78
+ - Context pack low-confidence chỉ được mở rộng bằng một bounded finder pass, không loop scout vô hạn.
75
79
  - Không raw-read hoặc raw-edit `.pi/context-index.json` trong task thường ngày. Runtime coi index là advisory state, sanitize khi đọc qua tool/command, và ghi qua `/onboard run` hoặc `piagent_context_index_record`.
76
80
  - File context vượt hard cap phải được summarize hoặc đọc targeted slices, không inject full.
77
81
  - Nếu input quá dài thật, lưu intake vào file project/local gitignored rồi reference file; không dán toàn bộ spec vào một turn.
@@ -79,6 +83,7 @@ Pi settings template dùng:
79
83
  - Tool output dài chỉ nên hiện preview. Dùng `/logs` hoặc command targeted hơn để debug; không paste full test/build log vào chat/final.
80
84
  - Memory chỉ là hint. Phải verify bằng source hiện tại trước khi sửa code.
81
85
  - Context index cũng chỉ là hint. Nó có node/edge/citation để giảm scout lại, không phải security boundary hoặc source of truth.
86
+ - Context Engine telemetry chỉ lưu operational metadata/hash dưới `.pi/piagent-state/`; prompt và tool output thô vẫn nằm trong Pi session/audit source hiện có.
82
87
 
83
88
  ## Nguồn
84
89
 
@@ -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.4` |
17
+ | Team pinned release | `git:github.com/Vt-mmm/piagent@v1.2.6` |
18
18
  | Personal/sandbox dev | `git:github.com/Vt-mmm/piagent` |
19
- | Registry distribution | `npm:@piagent/platform@1.2.4` |
19
+ | Registry distribution | `npm:@piagent/platform@1.2.6` |
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.4` | 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.6` | 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.4
56
+ pi install git:github.com/Vt-mmm/piagent@v1.2.6
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.4
68
+ npm install -g --ignore-scripts @piagent/platform@1.2.6
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.4` 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.4`.
73
+ `pi install git:github.com/Vt-mmm/piagent@v1.2.6` 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.6`.
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.4 \
123
+ --package-source git:github.com/Vt-mmm/piagent@v1.2.6 \
124
124
  --mcp-preset core \
125
125
  --subagents-preset safe
126
126
  ```
@@ -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.4
21
+ npm install -g --ignore-scripts @piagent/platform@1.2.6
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.4`. 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.6`. 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.4
102
+ npm install -g --ignore-scripts @piagent/platform@1.2.6
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.4 \
285
+ --package-source git:github.com/Vt-mmm/piagent@v1.2.6 \
286
286
  --mcp-preset core \
287
287
  --subagents-preset safe
288
288
  ```
@@ -894,8 +894,8 @@ Watchdog là optional adversarial reviewer ở cuối turn, không bật mặc
894
894
 
895
895
  | Command | Dùng để |
896
896
  |---|---|
897
- | `npm install -g --ignore-scripts @piagent/platform@1.2.4` | Cài terminal helper `piagent-*` từ release tag hiện tại. |
898
- | `pi install git:github.com/Vt-mmm/piagent@v1.2.4` | Install pinned release cho reproducible team setup. |
897
+ | `npm install -g --ignore-scripts @piagent/platform@1.2.6` | Cài terminal helper `piagent-*` từ release tag hiện tại. |
898
+ | `pi install git:github.com/Vt-mmm/piagent@v1.2.6` | Install pinned release cho reproducible team setup. |
899
899
  | `pi install git:github.com/Vt-mmm/piagent` | Install latest platform package cho máy cá nhân/sandbox. |
900
900
  | 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). |
901
901
  | 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. |
@@ -1002,7 +1002,7 @@ Mở lại Pi session sau khi install.
1002
1002
  Cài lại terminal helper đúng release rồi kiểm tra `PATH`:
1003
1003
 
1004
1004
  ```bash
1005
- npm install -g --ignore-scripts @piagent/platform@1.2.4
1005
+ npm install -g --ignore-scripts @piagent/platform@1.2.6
1006
1006
  command -v piagent-install
1007
1007
  ```
1008
1008
 
@@ -55,6 +55,10 @@ pi install /path/to/piagent
55
55
  - `1.2.0`: `piagent-mcp` quản lý server đầy đủ, server do repo mang theo phải được duyệt mới dùng được, và `/piagent-mcp` là command trong session chứ không phải nhờ model chạy bash.
56
56
  - `1.2.1`: approval gate thật sự phủ direct tool và server đến qua `imports` — hai đường vòng mà bản `1.2.0` để hở; kèm một loạt fix về containment khi vendor, độ sâu shell guard, và credential trong URL.
57
57
  - `1.2.2`: tool output dài được compact vào preview trong Pi và capture local cho Agent Watch/report; thêm `/setname` và `/logs` cho session naming và log audit gọn.
58
+ - `1.2.3`: gom command hằng ngày về `/workflow`, `/usage`, `/context`, `/permission`, `/onboard`, `/name` và `/fresh`.
59
+ - `1.2.4`: update global có fallback về user-writable npm prefix và project migration/doctor là bước hậu kiểm tùy chọn.
60
+ - `1.2.5`: updater đọc đúng metadata singleton-array của npm 12.
61
+ - `1.2.6`: Context Engine v2, dynamic tool loading, hard-budget retrieval, semantic compaction, Agent Watch telemetry/feedback và quality benchmark theo context efficiency.
58
62
 
59
63
  ## Không publish
60
64
 
@@ -41,7 +41,12 @@ bash scripts/quality-benchmark.sh /path/to/project --record \
41
41
  --surface pi \
42
42
  --result pass \
43
43
  --tokens 8200 \
44
+ --input-tokens 6900 \
45
+ --output-tokens 1300 \
46
+ --cache-read-tokens 2400 \
44
47
  --duration 540 \
48
+ --first-correct-edit 210 \
49
+ --rework 0 \
45
50
  --notes "good plan, no edits"
46
51
  ```
47
52
 
@@ -58,8 +63,14 @@ Output:
58
63
  | `result` | `pass`, `fail`, hoặc `partial` theo verify và acceptance criteria. |
59
64
  | `surface` | Agent surface/workflow/model preset được dùng cho run. |
60
65
  | `tokens` | Tổng token do runtime/provider báo. |
66
+ | `inputTokens` | Fresh input token, tách khỏi cache read để so context thực. |
67
+ | `outputTokens` | Token model sinh ra. |
68
+ | `cacheReadTokens` | Input được provider phục vụ từ prompt cache. |
61
69
  | `cost` | Cost nếu provider báo được. |
62
70
  | `durationSeconds` | Thời gian wall-clock. |
71
+ | `firstCorrectEditSeconds` | Thời gian tới edit đầu tiên còn tồn tại trong nghiệm cuối. |
72
+ | `reworkCount` | Số lượt edit bị bỏ hoặc phải làm lại. |
73
+ | `contextEfficiency` | Snapshot tool surface, duplicate read/output, retrieval utilization và context waste từ Pi Context Engine. |
63
74
  | `notes` | Số lần sửa lại, missing context, wrong file, verify failure, hoặc quality observation. |
64
75
 
65
76
  ## Quy tắc claim
@@ -71,4 +82,6 @@ Chỉ claim một setup tốt hơn khi:
71
82
  - cùng verify command;
72
83
  - ít nhất 3 lần chạy hoặc 3 scenario khác nhau;
73
84
  - pass rate không thấp hơn setup hiện tại;
74
- - token/cost giảm mà không tăng manual rework.
85
+ - fresh input token/cost giảm mà không tăng manual rework;
86
+ - time-to-first-correct-edit giảm hoặc không xấu đi;
87
+ - context waste giảm nhưng acceptance và verify vẫn giữ nguyên.
@@ -10,7 +10,7 @@ This file is the canonical install, update, rollback, and release checklist. Oth
10
10
 
11
11
  All supported environments require Node.js `>=22.19.0` and Pi Coding Agent `0.82.0`. The Pi host is installed as a Node CLI; Pi Agent Platform still defines its own release matrix because the terminal helpers and shell policy rely on Bash/POSIX behavior.
12
12
 
13
- | Surface | Status for v1.2.4 | Rollout guidance |
13
+ | Surface | Status for v1.2.6 | Rollout guidance |
14
14
  |---|---|---|
15
15
  | macOS Apple Silicon (`darwin/arm64`) + Bash | Verified for this release. | Safe default for team rollout after normal project smoke tests. |
16
16
  | Linux x64 + Bash | Verified in GitHub Actions. | Safe default for CI/server usage after normal project smoke tests. |
@@ -33,7 +33,7 @@ These three components are versioned independently. A full install, update, or r
33
33
 
34
34
  | Channel | Source shape | Mutability | Use when |
35
35
  |---|---|---:|---|
36
- | `stable` | `git:github.com/Vt-mmm/piagent@<resolved-commit-sha>` from `v1.2.4` | Fixed after resolution | Default for team rollout. |
36
+ | `stable` | `git:github.com/Vt-mmm/piagent@<resolved-commit-sha>` from `v1.2.6` | Fixed after resolution | Default for team rollout. |
37
37
  | `exact` | Tag, reviewed commit, or a tag resolved with `--resolve-tag` | Fixed when using a commit SHA | Pi-package-only roll forward, rollback, or reproduction. |
38
38
  | `dev` | `git:github.com/Vt-mmm/piagent` | Moving | Personal machine or sandbox only. |
39
39
  | `local` | `/path/to/piagent` | Local workspace | Platform development and dry-run validation. |
@@ -53,7 +53,7 @@ Use this flow when the team needs both terminal commands and the Pi package:
53
53
  ```bash
54
54
  node --version # >= 22.19.0
55
55
  npm install -g --ignore-scripts @earendil-works/pi-coding-agent@0.82.0
56
- npm install -g --ignore-scripts @piagent/platform@1.2.4
56
+ npm install -g --ignore-scripts @piagent/platform@1.2.6
57
57
  piagent-install --stable --dry-run
58
58
  piagent-install --stable
59
59
  ```
@@ -61,8 +61,8 @@ piagent-install --stable
61
61
  The stable preview and apply output includes:
62
62
 
63
63
  ```text
64
- currentRelease: v1.2.4 (helper package version)
65
- tag: v1.2.4
64
+ currentRelease: v1.2.6 (helper package version)
65
+ tag: v1.2.6
66
66
  resolvedCommit: <40-char-sha>
67
67
  source: git:github.com/Vt-mmm/piagent@<40-char-sha>
68
68
  ```
@@ -79,7 +79,7 @@ bash scripts/install-global.sh --stable
79
79
  Use this only when terminal commands are not needed:
80
80
 
81
81
  ```bash
82
- pi install git:github.com/Vt-mmm/piagent@v1.2.4
82
+ pi install git:github.com/Vt-mmm/piagent@v1.2.6
83
83
  ```
84
84
 
85
85
  Direct `pi install` does not create `piagent-*` commands on `PATH`.
@@ -24,7 +24,7 @@ Project cụ thể chỉ cần adapter/profile riêng. Core package giữ lifecy
24
24
  |---|---|---|
25
25
  | Risk lane | `riskLane` + profile `hardGates` | Chặn auth, release, provider config, destructive action, database migration. |
26
26
  | Intake | `piagent_task_start` | Mỗi task có scope, output, acceptance criteria trước khi edit. |
27
- | Context rules | `/onboard run`, `.pi/project-context.md`, `requiredContext`, context manifest | Giảm token và tránh đọc toàn repo. |
27
+ | Context rules | `/onboard run`, Pi Context Engine, `.pi/project-context.md`, `requiredContext`, context manifest | Giảm token và tránh đọc toàn repo. |
28
28
  | Test matrix | `verifyCommands` + observed verify evidence | DONE phải có exact verify command thực chạy qua Pi bash hoặc `N/A` rõ lý do. |
29
29
  | Trace | `piagent_trace_record`, `.pi/piagent-state/traces.jsonl`, session entry | Có audit trail cho task. |
30
30
  | Protected paths | `protectedPaths` trong profile + extension guard | Mỗi project có vùng cấm riêng. |
@@ -52,6 +52,9 @@ Project cụ thể chỉ cần adapter/profile riêng. Core package giữ lifecy
52
52
 
53
53
  ## Task lifecycle chuẩn
54
54
 
55
+ Vòng đời thích nghi theo mức rủi ro. Runtime guard luôn hoạt động, nhưng các
56
+ tool context mang tính advisory chỉ được nạp khi task thực sự cần.
57
+
55
58
  ```text
56
59
  1. Intake
57
60
  - risk lane
@@ -61,10 +64,10 @@ Project cụ thể chỉ cần adapter/profile riêng. Core package giữ lifecy
61
64
  - protected paths
62
65
 
63
66
  2. Context
64
- - load piagent_context
65
- - read `.pi/project-context.md`
66
- - read requiredContext
67
- - check large files with piagent_context_budget
67
+ - load concise piagent_context once
68
+ - use one token-budgeted Context Engine pack for unfamiliar/cross-module work
69
+ - read only targeted requiredContext
70
+ - check only large/unfamiliar files with piagent_context_budget
68
71
  - record context manifest
69
72
 
70
73
  3. Plan
@@ -73,8 +76,8 @@ Project cụ thể chỉ cần adapter/profile riêng. Core package giữ lifecy
73
76
  - rollback/handoff if high-risk
74
77
 
75
78
  4. Implement
76
- - check risky shell with piagent_exec_policy_check
77
- - check non-piagent tools with piagent_tool_policy_check
79
+ - check complex/risky shell with piagent_exec_policy_check
80
+ - check non-piagent tools only when capability is unclear
78
81
  - edit only in scope
79
82
  - avoid protected paths
80
83
 
@@ -92,6 +95,12 @@ Project cụ thể chỉ cần adapter/profile riêng. Core package giữ lifecy
92
95
  - piagent_task_gate_check before DONE
93
96
  ```
94
97
 
98
+ | Lane | Extra context/orchestration |
99
+ |---|---|
100
+ | `tiny` | Core lifecycle only; parent agent, targeted reads, exact verify. |
101
+ | `normal` | Index/memory only for unfamiliar areas; bounded read-only delegation when it saves context. |
102
+ | `high-risk` | Relevant index/memory/vendor evidence plus explicit security/data/release review. |
103
+
95
104
  ## Maturity phases
96
105
 
97
106
  | Phase | Output | Đủ để implement task? |
@@ -21,7 +21,7 @@ This document covers the packaged guard, project profiles, capability locks, ins
21
21
  - The operator, operating-system account, Pi host, and explicitly trusted project repository are trusted to execute code.
22
22
  - Project-local Pi resources are loaded only after Pi project trust or an explicit operator override.
23
23
  - A human remains available to approve destructive and external-provider actions.
24
- - Supported release verification covers macOS Apple Silicon + Bash, Linux x64 + Bash, Node.js `>=22.19.0`, and the exact Pi host version declared by the release. macOS Intel + Bash and Linux ARM64 + Bash are supported targets that need local smoke verification before broad rollout. Native Windows is not a team-rollout target for v1.2.4, and WSL2 is experimental/unverified.
24
+ - Supported release verification covers macOS Apple Silicon + Bash, Linux x64 + Bash, Node.js `>=22.19.0`, and the exact Pi host version declared by the release. macOS Intel + Bash and Linux ARM64 + Bash are supported targets that need local smoke verification before broad rollout. Native Windows is not a team-rollout target for v1.2.6, and WSL2 is experimental/unverified.
25
25
  - Registry, GitHub, model-provider, MCP-provider, and Vercel controls are external dependencies. Their account security and platform guarantees are not replaced by this repository.
26
26
 
27
27
  ## Threat actors and failure modes