@piagent/platform 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (159) hide show
  1. package/.gitattributes +7 -0
  2. package/AGENTS.md +31 -0
  3. package/CHANGELOG.md +296 -0
  4. package/CODE_OF_CONDUCT.md +36 -0
  5. package/CONTRIBUTING.md +66 -0
  6. package/LICENSE +21 -0
  7. package/README.md +588 -0
  8. package/SECURITY.md +38 -0
  9. package/adapters/backend-api/profile.json +88 -0
  10. package/adapters/be-readonly-fe/profile.json +120 -0
  11. package/adapters/data/profile.json +88 -0
  12. package/adapters/devops/profile.json +92 -0
  13. package/adapters/docs/profile.json +74 -0
  14. package/adapters/fullstack/profile.json +94 -0
  15. package/adapters/generic/profile.json +95 -0
  16. package/adapters/mobile/profile.json +87 -0
  17. package/adapters/node-typescript/profile.json +76 -0
  18. package/adapters/python/profile.json +75 -0
  19. package/adapters/web-frontend/profile.json +101 -0
  20. package/catalog/capabilities.json +206 -0
  21. package/docs/architecture.md +64 -0
  22. package/docs/auto-delegation-policy.md +192 -0
  23. package/docs/capability-packs.md +234 -0
  24. package/docs/command-reference-vietnamese.md +484 -0
  25. package/docs/context-window-policy.md +85 -0
  26. package/docs/distribution-standard.md +229 -0
  27. package/docs/herdr-workflow.md +58 -0
  28. package/docs/mcp-and-tools.md +316 -0
  29. package/docs/memory-policy.md +164 -0
  30. package/docs/model-options.md +165 -0
  31. package/docs/oauth-providers.md +53 -0
  32. package/docs/operator-manual-vietnamese.md +1080 -0
  33. package/docs/package-architecture-notes.md +101 -0
  34. package/docs/project-adapters.md +174 -0
  35. package/docs/project-onboarding.md +135 -0
  36. package/docs/publishing-for-teams.md +64 -0
  37. package/docs/quality-benchmark.md +74 -0
  38. package/docs/quickstart-vietnamese.md +350 -0
  39. package/docs/release-install-policy.md +223 -0
  40. package/docs/runtime-harness-standard.md +118 -0
  41. package/docs/runtime-policy-design.md +132 -0
  42. package/docs/runtime-quality-baseline.md +257 -0
  43. package/docs/security-redaction-benchmark.md +56 -0
  44. package/docs/security-threat-model.md +66 -0
  45. package/docs/subagent-orchestration-capabilities.md +104 -0
  46. package/docs/subagents-and-multiagent.md +346 -0
  47. package/docs/task-implementation-contract.md +200 -0
  48. package/docs/team-onboarding.md +333 -0
  49. package/docs/usage-observability.md +130 -0
  50. package/docs/vercel-docs-site.md +115 -0
  51. package/docs/workflow-recipes.md +125 -0
  52. package/docs-site/assets/piagent-logo.svg +35 -0
  53. package/docs-site/favicon.svg +18 -0
  54. package/docs-site/index.html +1613 -0
  55. package/docs-site/vercel.json +24 -0
  56. package/evals/fixtures/action-proposal.invalid.json +34 -0
  57. package/evals/fixtures/action-proposal.valid.json +34 -0
  58. package/evals/fixtures/capability-pack.invalid.json +123 -0
  59. package/evals/fixtures/capability-pack.valid.json +123 -0
  60. package/evals/fixtures/capability-recipe.invalid.json +81 -0
  61. package/evals/fixtures/capability-recipe.valid.json +82 -0
  62. package/evals/fixtures/context-index.invalid.json +25 -0
  63. package/evals/fixtures/context-index.valid.json +25 -0
  64. package/evals/fixtures/eval-scenario.invalid.json +40 -0
  65. package/evals/fixtures/eval-scenario.valid.json +45 -0
  66. package/evals/fixtures/project-profile.invalid.json +88 -0
  67. package/evals/fixtures/project-profile.valid.json +95 -0
  68. package/evals/fixtures/task-contract.invalid.json +73 -0
  69. package/evals/fixtures/task-contract.valid.json +74 -0
  70. package/evals/golden/enforcement-decisions.json +329 -0
  71. package/evals/scenarios/capability-resolution.json +45 -0
  72. package/package.json +132 -0
  73. package/packages/piagent-core/README.md +147 -0
  74. package/packages/piagent-core/capabilities/capability-core.js +1023 -0
  75. package/packages/piagent-core/capabilities/capability-sources.js +265 -0
  76. package/packages/piagent-core/extensions/guard-io.js +45 -0
  77. package/packages/piagent-core/extensions/guard-shell-analysis.ts +558 -0
  78. package/packages/piagent-core/extensions/guard-types.ts +406 -0
  79. package/packages/piagent-core/extensions/piagent-guard.ts +5760 -0
  80. package/packages/piagent-core/extensions/policy-core.js +1070 -0
  81. package/packages/piagent-core/extensions/redaction-core.js +4 -0
  82. package/packages/piagent-core/extensions/runtime-evidence.js +215 -0
  83. package/packages/piagent-core/package.json +46 -0
  84. package/packages/piagent-core/policies/base-policy.json +249 -0
  85. package/packages/piagent-core/prompts/be-to-fe.md +82 -0
  86. package/packages/piagent-core/prompts/commit.md +27 -0
  87. package/packages/piagent-core/prompts/discuss.md +35 -0
  88. package/packages/piagent-core/prompts/memory-policy.md +52 -0
  89. package/packages/piagent-core/prompts/model-options.md +68 -0
  90. package/packages/piagent-core/prompts/onboard-project.md +147 -0
  91. package/packages/piagent-core/prompts/piagent-commands.md +68 -0
  92. package/packages/piagent-core/prompts/plan.md +35 -0
  93. package/packages/piagent-core/prompts/platform-improve.md +69 -0
  94. package/packages/piagent-core/prompts/pr.md +26 -0
  95. package/packages/piagent-core/prompts/review.md +38 -0
  96. package/packages/piagent-core/prompts/scout.md +50 -0
  97. package/packages/piagent-core/prompts/task.md +69 -0
  98. package/packages/piagent-core/security/sensitive-data.js +187 -0
  99. package/packages/piagent-core/skills/piagent-ops/SKILL.md +44 -0
  100. package/packages/piagent-core/skills/piagent-source-cache/SKILL.md +59 -0
  101. package/packages/piagent-core/skills/piagent-source-cache/checkout-source-repo.sh +144 -0
  102. package/packages/piagent-core/subagents/piagent-oracle.md +29 -0
  103. package/packages/piagent-core/subagents/piagent-planner.md +46 -0
  104. package/packages/piagent-core/subagents/piagent-reviewer.md +48 -0
  105. package/packages/piagent-core/subagents/piagent-scout.md +37 -0
  106. package/packages/piagent-core/subagents/piagent-worker.md +44 -0
  107. package/packs/engineering-base/pack.json +123 -0
  108. package/packs/engineering-base/recipes/bounded-change.json +82 -0
  109. package/packs/web-delivery/pack.json +72 -0
  110. package/packs/web-delivery/recipes/verified-web-change.json +57 -0
  111. package/schemas/action-proposal.schema.json +90 -0
  112. package/schemas/capability-pack.schema.json +190 -0
  113. package/schemas/capability-recipe.schema.json +72 -0
  114. package/schemas/context-index.schema.json +258 -0
  115. package/schemas/eval-scenario.schema.json +67 -0
  116. package/schemas/project-profile.schema.json +555 -0
  117. package/schemas/task-contract.schema.json +314 -0
  118. package/scripts/audit-runtime-host.sh +78 -0
  119. package/scripts/bootstrap-local.sh +25 -0
  120. package/scripts/capability-catalog.mjs +290 -0
  121. package/scripts/check-runtime-advisories.mjs +114 -0
  122. package/scripts/configure-mcp.sh +301 -0
  123. package/scripts/configure-model-scope.sh +143 -0
  124. package/scripts/configure-subagents.sh +241 -0
  125. package/scripts/import-agent-instructions.mjs +199 -0
  126. package/scripts/init-project.sh +369 -0
  127. package/scripts/install-global.sh +532 -0
  128. package/scripts/link-project.sh +25 -0
  129. package/scripts/migrate-project-state.mjs +176 -0
  130. package/scripts/pi-auto.sh +79 -0
  131. package/scripts/pi-model-catalog.sh +154 -0
  132. package/scripts/pi-session-stats.sh +135 -0
  133. package/scripts/piagent-cli.mjs +53 -0
  134. package/scripts/profile-doctor.sh +238 -0
  135. package/scripts/quality-benchmark.sh +185 -0
  136. package/scripts/redaction-benchmark.mjs +227 -0
  137. package/scripts/runtime-policy-smoke.sh +48 -0
  138. package/scripts/setup.sh +425 -0
  139. package/scripts/team-doctor.sh +461 -0
  140. package/scripts/verify-local.sh +540 -0
  141. package/scripts/verify-release-identity.mjs +85 -0
  142. package/scripts/verify-vercel-link.mjs +64 -0
  143. package/templates/global/mcp.json +9 -0
  144. package/templates/global/settings.json +37 -0
  145. package/templates/project/.mcp.json +9 -0
  146. package/templates/project/.pi/context-index.json +25 -0
  147. package/templates/project/.pi/gitignore.template +22 -0
  148. package/templates/project/.pi/mcp.json +9 -0
  149. package/templates/project/.pi/memory/MEMORY.md +11 -0
  150. package/templates/project/.pi/memory/memory_summary.md +9 -0
  151. package/templates/project/.pi/piagent-profile.json +107 -0
  152. package/templates/project/.pi/project-context.md +30 -0
  153. package/templates/project/.pi/settings.json +17 -0
  154. package/templates/project/.pi/task-contract.template.json +74 -0
  155. package/templates/project/.pi/tech-context/README.md +7 -0
  156. package/templates/project/.pi/tech-stack.json +10 -0
  157. package/templates/project/AGENTS.md +34 -0
  158. package/templates/project/REVIEW_GUIDELINES.md +23 -0
  159. package/types/pi-runtime-shims.d.ts +13 -0
@@ -0,0 +1,333 @@
1
+ # Team onboarding
2
+
3
+ > Team mới nên đọc `docs/operator-manual-vietnamese.md` trước, rồi dùng file này như checklist onboarding.
4
+
5
+ ## Mục tiêu
6
+
7
+ Một thành viên mới không cần biết local path của maintainer. Luồng chuẩn rút gọn:
8
+
9
+ ```bash
10
+ node --version # >= 22.19.0
11
+ npm install -g --ignore-scripts @earendil-works/pi-coding-agent@0.81.1
12
+ npm install -g --ignore-scripts github:Vt-mmm/piagent#v1.0.0
13
+ piagent-install --stable
14
+ cd /path/to/project
15
+ pi
16
+ /login
17
+ <select provider/model>
18
+ /mcp
19
+ /subagents-doctor
20
+ /onboard-project
21
+ /memory-policy
22
+ ```
23
+
24
+ ## Prerequisites
25
+
26
+ - Node.js >=22.19.0.
27
+ - Pi Coding Agent `0.81.1`.
28
+ - Runtime rollout:
29
+ - verified: macOS Apple Silicon + Bash, Linux x64 + Bash;
30
+ - supported target cần smoke trước khi rollout rộng: macOS Intel + Bash, Linux ARM64 + Bash;
31
+ - chưa dùng làm target rollout team: native Windows; WSL2 chỉ experimental.
32
+ - `pi` có trên `PATH`.
33
+ - `herdr` optional nhưng nên có nếu team chạy nhiều agent pane.
34
+ - Git access tới repo platform nếu dùng `git:` package source.
35
+ - OAuth/API access riêng của từng người. Không share token.
36
+
37
+ ## Bước 1 — install global package một lần
38
+
39
+ Mặc định team dùng stable helper:
40
+
41
+ ```bash
42
+ node --version # >= 22.19.0
43
+ npm install -g --ignore-scripts @earendil-works/pi-coding-agent@0.81.1
44
+ npm install -g --ignore-scripts github:Vt-mmm/piagent#v1.0.0
45
+ piagent-install --stable --dry-run
46
+ piagent-install --stable
47
+ ```
48
+
49
+ `currentRelease` trong output là version của npm-global helper đang chạy. Stable resolve tag cùng version đó thành commit SHA trước khi cài Pi package.
50
+
51
+ Khi seed `.pi/settings.json` cho team/repo cần audit lặp lại, dùng tag cố định:
52
+
53
+ ```bash
54
+ pi install git:github.com/Vt-mmm/piagent@vX.Y.Z
55
+ ```
56
+
57
+ Máy cá nhân/sandbox có thể theo moving source nếu chấp nhận cập nhật nhanh:
58
+
59
+ ```bash
60
+ pi install git:github.com/Vt-mmm/piagent
61
+ ```
62
+
63
+ ## Update và rollback cho team
64
+
65
+ Full update phải đồng bộ exact Pi host trước, sau đó terminal helper và Pi package matching:
66
+
67
+ ```bash
68
+ npm install -g --ignore-scripts @earendil-works/pi-coding-agent@0.81.1
69
+ npm install -g --ignore-scripts github:Vt-mmm/piagent#vX.Y.Z
70
+ piagent-install --stable --dry-run
71
+ piagent-install --stable
72
+ piagent-doctor /path/to/project --strict-share
73
+ ```
74
+
75
+ Full rollback dùng cùng sequence với `vPREVIOUS`, nhưng exact Pi host phải lấy từ release policy của target và dependency risk phải được đánh giá lại trước khi hạ host. `piagent-install --version vX.Y.Z --resolve-tag` chỉ đổi Pi package, không đổi Pi host hay npm-global helper. Checklist chi tiết nằm tại [release/install policy](release-install-policy.md).
76
+
77
+ Nếu team publish npm private:
78
+
79
+ ```bash
80
+ npm install -g --ignore-scripts @earendil-works/pi-coding-agent@0.81.1
81
+ pi install npm:@your-scope/platform@x.y.z
82
+ ```
83
+
84
+ Không cần chạy bash để set profile cho từng project.
85
+
86
+ ## Bước 2 — mở project và login OAuth
87
+
88
+ ```bash
89
+ cd /path/to/project
90
+ pi
91
+ /login
92
+ ```
93
+
94
+ Credential nằm trong user Pi dir, không commit.
95
+
96
+ ## Bước 3 — chọn model và onboard project
97
+
98
+ Sau login, chọn provider/model intended cho project understanding bằng native Pi selector. OpenAI Codex và Claude/Anthropic đều là supported option.
99
+
100
+ ```text
101
+ /model # hoặc Ctrl+L
102
+ /scoped-models # optional
103
+ ```
104
+
105
+ Global setup seed sẵn `enabledModels`; đổi nhanh bằng:
106
+
107
+ ```text
108
+ Ctrl+P # cycle scoped models
109
+ Shift+Tab # cycle thinking level
110
+ ```
111
+
112
+ Rồi chạy:
113
+
114
+ ```text
115
+ /mcp
116
+ /subagents-doctor
117
+ /onboard-project
118
+ ```
119
+
120
+ Output chính:
121
+
122
+ - `.pi/project-context.md`
123
+ - `.pi/context-index.json`
124
+ - `.pi/piagent-profile.json`
125
+ - `.pi/piagent-profile.lock.json`
126
+ - `.pi/tech-stack.json`
127
+ - `.pi/tech-context/*.json`
128
+ - `.pi/piagent-state/project-onboarding.json`
129
+
130
+ Memory files are created locally but ignored by default:
131
+
132
+ - `.pi/memory/memory_summary.md`
133
+ - `.pi/memory/MEMORY.md`
134
+
135
+ Đây là bước model đọc qua project lần đầu theo cách bounded: đọc profile, AGENTS, README, docs/config/source map/test command; không load toàn bộ source.
136
+
137
+ Nếu project chưa có profile/tech stack, dùng select-style flow để tránh agent trả lời dài:
138
+
139
+ ```text
140
+ /profile setup
141
+ /profile tech setup fullstack
142
+ ```
143
+
144
+ `fullstack` bắt chọn frontend, backend và database. Nếu native select chưa có trong Pi host, command trả card compact kèm lệnh deterministic `/profile tech apply ...`.
145
+
146
+ Nếu `.pi/project-context.md` còn `Generated: not yet`, không nên chạy `/task` implementation.
147
+
148
+ Memory mặc định là project-scoped và explicit-only. Chạy `/memory-policy` để xem files/rules. Agent chỉ ghi durable memory khi user yêu cầu rõ ràng.
149
+
150
+ Đổi profile sau này:
151
+
152
+ ```text
153
+ /profile list
154
+ /profile setup
155
+ /profile tech setup
156
+ /profile fullstack
157
+ /profile be-readonly-fe
158
+ ```
159
+
160
+ ## Setup nâng cao — tách global và project
161
+
162
+ Các script setup/init vẫn tồn tại cho case preseed config vào repo hoặc CI bootstrap, nhưng không phải default UX:
163
+
164
+ ```bash
165
+ bash /path/to/piagent/scripts/setup.sh /path/to/project \
166
+ --profile be-readonly-fe \
167
+ --package-source git:github.com/Vt-mmm/piagent@vX.Y.Z \
168
+ --mcp-preset core \
169
+ --subagents-preset safe
170
+ ```
171
+
172
+ Nếu cần override profile:
173
+
174
+ ```bash
175
+ bash /path/to/piagent/scripts/setup.sh /path/to/project --project-only --profile backend-api --package-source git:github.com/Vt-mmm/piagent@vX.Y.Z --mcp-preset core --subagents-preset safe
176
+ ```
177
+
178
+ Profile built-in trong Pi:
179
+
180
+ - `auto`: tự detect.
181
+ - `generic`: repo chưa chuẩn.
182
+ - `web-frontend`: Next/React/Vite frontend.
183
+ - `backend-api`: Node/Java/Python API.
184
+ - `be-readonly-fe`: scout BE read-only, implement FE only.
185
+ - `fullstack`: repo có cả frontend và backend.
186
+ - `node-typescript`: Node/TS library/tooling.
187
+ - `python`: Python app/library.
188
+ - `data`: ETL/dbt/DVC/notebook/data pipeline.
189
+ - `devops`: Docker/Terraform/K8s/GitHub Actions.
190
+ - `mobile`: React Native/Flutter.
191
+ - `docs`: docs portal/manual.
192
+
193
+ Project init tạo:
194
+
195
+ - `.pi/settings.json`
196
+ - `.pi/piagent-profile.json`
197
+ - `.pi/context-index.json`
198
+ - `.mcp.json`
199
+ - `.pi/mcp.json`
200
+ - `.pi/memory/memory_summary.md`
201
+ - `.pi/memory/MEMORY.md`
202
+ - `.pi/.gitignore`
203
+ - `AGENTS.md` nếu chưa có
204
+ - `REVIEW_GUIDELINES.md` nếu chưa có
205
+
206
+ Hai file memory ở trên là local/private mặc định theo `.pi/.gitignore`; chỉ commit nếu team opt-in sau review.
207
+
208
+ ## Bước 4 — run trong Herdr
209
+
210
+ ```bash
211
+ herdr
212
+ cd /path/to/project
213
+ pi
214
+ ```
215
+
216
+ Trong Pi, nếu project trust prompt hiện ra, chỉ approve khi đúng repo. Project trust cho phép Pi load `.pi/settings.json`, `.pi` resources và project extensions.
217
+
218
+ Sau khi team đã hiểu repo và muốn giảm prompt trust cho từng lần chạy, dùng:
219
+
220
+ ```bash
221
+ piagent-auto
222
+ ```
223
+
224
+ Read-only auto-run cho scout/audit:
225
+
226
+ ```bash
227
+ piagent-auto --read-only -p "Scout module mapping. Do not edit source."
228
+ ```
229
+
230
+ Lệnh này wrap `pi --approve`; nó không bypass piagent guard.
231
+
232
+ ## Bước 5 — task workflow
233
+
234
+ Requirement chưa rõ:
235
+
236
+ ```text
237
+ /discuss Tạo plan cho feature X. Chưa implement.
238
+ ```
239
+
240
+ Task rõ:
241
+
242
+ ```text
243
+ /task Implement feature X. Follow project profile, protected paths, required context, exec policy, context budget, tool policy, verify, trace, and task gate.
244
+ ```
245
+
246
+ Scout/audit read-only:
247
+
248
+ ```text
249
+ /scout Scout payment FE mapping vs BE contract. Backend read-only. Do not edit source.
250
+ ```
251
+
252
+ Session nặng hoặc context overflow:
253
+
254
+ ```text
255
+ /fresh-scout <read-only scout>
256
+ /fresh-task <bounded task>
257
+ /fresh-be-to-fe <BE-readonly/FE request>
258
+ ```
259
+
260
+ Không paste full mandatory flow hằng ngày. Platform prompts/tools đã chứa checklist; input guard sẽ tự collapse boilerplate nếu paste nhầm.
261
+
262
+ Runtime gate tools:
263
+
264
+ ```text
265
+ piagent_exec_policy_check
266
+ piagent_context_budget
267
+ piagent_tool_policy_check
268
+ piagent_task_gate_check
269
+ ```
270
+
271
+ Task cải tiến platform:
272
+
273
+ ```text
274
+ /platform-improve Improve onboarding, model scope, MCP setup, and verification docs for team usage.
275
+ ```
276
+
277
+ Task BE spec lên FE:
278
+
279
+ ```text
280
+ /be-to-fe Implement FE from BE contract <endpoint/spec>. Backend is read-only.
281
+ ```
282
+
283
+ Project memory:
284
+
285
+ ```text
286
+ /memory-policy
287
+ Remember: this repo uses pnpm, never npm.
288
+ ```
289
+
290
+ External source repo:
291
+
292
+ ```text
293
+ Use piagent_source_checkout for github.com/org/repo, inspect only relevant files, then summarize applicable patterns.
294
+ ```
295
+
296
+ ## Doctor
297
+
298
+ Chạy trên platform:
299
+
300
+ ```bash
301
+ bash scripts/verify-local.sh
302
+ ```
303
+
304
+ Chạy trên project:
305
+
306
+ ```bash
307
+ bash /path/to/piagent/scripts/profile-doctor.sh /path/to/project
308
+ bash /path/to/piagent/scripts/team-doctor.sh /path/to/project --strict-share
309
+ bash /path/to/piagent/scripts/quality-benchmark.sh /path/to/project --init
310
+ ```
311
+
312
+ Nếu doctor cảnh báo `project onboarding snapshot is still pending`, mở Pi trong project và chạy `/onboard-project`.
313
+
314
+ ## Không commit
315
+
316
+ - `.pi/piagent-state/`
317
+ - `.pi/benchmarks/`
318
+ - `.pi/memory/local/`
319
+ - `.pi/memory/state.sqlite`
320
+ - `.pi/memory/rollout_summaries/`
321
+ - `.pi/todos/`
322
+ - `.pi/sessions/`
323
+ - `.pi/auth.json`
324
+ - `.env`
325
+ - token/API key
326
+
327
+ ## Official docs
328
+
329
+ - Pi packages: https://pi.dev/docs/latest/packages
330
+ - Pi project trust/settings: https://pi.dev/docs/latest/settings
331
+ - Pi prompt templates: https://pi.dev/docs/latest/prompt-templates
332
+ - Pi MCP adapter: https://pi.dev/packages/pi-mcp-adapter
333
+ - Herdr integrations: https://herdr.dev/docs/integrations/
@@ -0,0 +1,130 @@
1
+ # Usage observability
2
+
3
+ Mục tiêu: biết Pi session đang tiêu hao token/context/cost như nào mà không phải hỏi model bằng ngôn ngữ tự nhiên.
4
+
5
+ ## Trong Pi TUI
6
+
7
+ Pi có sẵn footer hiển thị token/cache usage, cost, context usage, model hiện tại. Khi cần chi tiết hơn, chạy:
8
+
9
+ ```text
10
+ /session
11
+ ```
12
+
13
+ Piagent package thêm command:
14
+
15
+ ```text
16
+ /piagent-usage
17
+ /task-preflight
18
+ /task-preflight compact
19
+ ```
20
+
21
+ Agent cũng có thể gọi tool:
22
+
23
+ ```text
24
+ piagent_usage_snapshot
25
+ piagent_context_preflight
26
+ ```
27
+
28
+ `/piagent-usage` hiển thị:
29
+
30
+ - session file;
31
+ - session id/name;
32
+ - cwd;
33
+ - model;
34
+ - live context usage hiện tại;
35
+ - active branch entries / total entries;
36
+ - lệnh để lấy exact token/cost totals từ terminal khác.
37
+
38
+ `/task-preflight` hiển thị:
39
+
40
+ - workflow đang định chạy;
41
+ - live context;
42
+ - estimated input tokens;
43
+ - projected context;
44
+ - recommendation: `ok`, `watch`, `compact`, hoặc `fresh-session`;
45
+ - fresh workflow commands nếu session hiện tại quá nặng.
46
+
47
+ `/task-preflight compact` gọi Pi compaction với hướng dẫn giữ lại decisions, blockers, changed files, verify command, và next action.
48
+
49
+ Giới hạn kỹ thuật: extension command context expose `ctx.getContextUsage()`, phù hợp để biết context window đang dùng bao nhiêu. Exact billed totals như `input`, `output`, `cacheRead`, `cacheWrite`, `cost` là API của Pi `/session` và RPC `get_session_stats`.
50
+
51
+ ## Từ terminal khác
52
+
53
+ Nếu đang có một Pi session chạy ở project khác, mở terminal mới:
54
+
55
+ ```bash
56
+ piagent-usage /path/to/project
57
+ ```
58
+
59
+ Hoặc dùng script trực tiếp:
60
+
61
+ ```bash
62
+ bash scripts/pi-session-stats.sh /path/to/project
63
+ ```
64
+
65
+ Script sẽ:
66
+
67
+ 1. tìm session `.jsonl` mới nhất có header `cwd` khớp project path;
68
+ 2. gọi Pi RPC `get_session_stats`;
69
+ 3. in JSON gồm messages, token totals, cost và context usage.
70
+
71
+ Ví dụ output:
72
+
73
+ ```json
74
+ {
75
+ "tokens": {
76
+ "input": 121095,
77
+ "output": 8088,
78
+ "cacheRead": 2023936,
79
+ "cacheWrite": 0,
80
+ "total": 2153119
81
+ },
82
+ "cost": 1.860083,
83
+ "contextUsage": {
84
+ "tokens": 102996,
85
+ "contextWindow": 272000,
86
+ "percent": 37.866176470588236
87
+ }
88
+ }
89
+ ```
90
+
91
+ ## Cách đọc số
92
+
93
+ | Field | Ý nghĩa |
94
+ |---|---|
95
+ | `input` | Token input thật gửi vào model. |
96
+ | `output` | Token model sinh ra. |
97
+ | `cacheRead` | Token đọc từ provider prompt cache. Số này có thể rất lớn nhưng không tương đương fresh input cost. |
98
+ | `cacheWrite` | Token ghi vào cache. |
99
+ | `total` | Tổng theo Pi stats. |
100
+ | `cost` | Cost Pi tính theo pricing metadata của model/provider. |
101
+ | `contextUsage.tokens` | Context window hiện đang bị chiếm bao nhiêu token. |
102
+ | `contextUsage.percent` | Phần trăm context window hiện tại. |
103
+
104
+ ## Khi nào cần compact
105
+
106
+ Xem `contextUsage.percent`:
107
+
108
+ - `< 50%`: bình thường.
109
+ - `50–70%`: bắt đầu tránh đọc file lớn không cần thiết.
110
+ - `70–82%`: chạy `/task-preflight compact` trước task dài tiếp theo.
111
+ - `> 82%`: dùng `/fresh-task`, `/fresh-scout`, hoặc `/fresh-be-to-fe` cho work mới.
112
+ - Sau compaction, `contextUsage.tokens` có thể là `null` cho đến khi có assistant response mới.
113
+
114
+ Nếu user paste full mandatory-flow boilerplate, platform input guard sẽ collapse về workflow command ngắn. Nếu prompt quá dài thật, platform có thể lưu intake vào `.pi/task-inbox/` local gitignored rồi replay bằng fresh workflow command.
115
+
116
+ ## Khi nào ghi benchmark
117
+
118
+ Sau một task cần so sánh workflow/model bằng số liệu:
119
+
120
+ ```bash
121
+ bash scripts/quality-benchmark.sh /path/to/project --record \
122
+ --scenario bounded-source-fix \
123
+ --surface pi \
124
+ --result pass \
125
+ --tokens <total-from-piagent-usage> \
126
+ --cost <cost-from-piagent-usage> \
127
+ --verify "<verify-command>"
128
+ ```
129
+
130
+ Không dùng ước lượng ký tự để claim tiết kiệm token. Dùng `/session`, RPC `get_session_stats`, hoặc `piagent-usage`.
@@ -0,0 +1,115 @@
1
+ # Vercel docs site
2
+
3
+ ## Khuyến nghị
4
+
5
+ Giữ tài liệu HTML trong cùng repository, dưới `docs-site/`.
6
+
7
+ Production URL: https://piagent.io.vn
8
+
9
+ Vercel project: `pi-agent`
10
+
11
+ Root Directory: `docs-site`
12
+
13
+ Lý do:
14
+
15
+ - docs đi cùng source và version của package;
16
+ - source và docs được review trong cùng release candidate;
17
+ - Vercel trỏ Root Directory thẳng vào `docs-site/`;
18
+ - site static không cần build step hoặc environment secret.
19
+
20
+ Tách repository chỉ nên dùng khi docs cần domain, quyền truy cập, hoặc lịch phát hành riêng.
21
+
22
+ ## Production promotion policy
23
+
24
+ Production docs không được advertise một release tag chưa tồn tại.
25
+
26
+ Luồng canonical:
27
+
28
+ 1. Sửa source và versioned docs trên release-candidate branch.
29
+ 2. Chạy verification và chờ CI pass.
30
+ 3. Tạo/push tag trên đúng verified commit và chờ tag-triggered CI trên Ubuntu/macOS pass.
31
+ 4. Chạy stable dry-run và xác nhận resolved commit SHA khớp tag.
32
+ 5. Sau đó release maintainer mới dùng bypass actor đã giới hạn trong ruleset để non-force fast-forward đúng tagged commit vào `main` (Vercel production branch), hoặc checkout đúng commit đó rồi chạy Vercel link preflight trước khi deploy `docs-site/`; không merge/squash/rebase, force-push hay chèn docs-only commit khác trong lúc promote.
33
+ 6. Kiểm tra live version, canonical URL, link và install command.
34
+
35
+ Nếu Vercel đang auto-deploy production branch, giữ vNext docs ngoài branch đó cho tới khi tag CI + SHA verification hoàn tất. Checklist duy nhất nằm tại [release/install policy](release-install-policy.md).
36
+
37
+ ## Deploy bằng Dashboard
38
+
39
+ 1. Vào Vercel project `pi-agent`.
40
+ 2. Set Root Directory: `docs-site`.
41
+ 3. Set Framework Preset: `Other`.
42
+ 4. Build Command: để trống.
43
+ 5. Output Directory: `.` hoặc default.
44
+ 6. Chỉ promote production sau release gate ở trên.
45
+
46
+ ## Deploy bằng CLI
47
+
48
+ Sau khi tag CI và stable SHA verification pass, từ checkout đúng tagged commit:
49
+
50
+ ```bash
51
+ vercel link --cwd docs-site --project pi-agent
52
+ npm run vercel:preflight
53
+ vercel --cwd docs-site --prod
54
+ ```
55
+
56
+ `npm run vercel:preflight` fail-closed nếu `.vercel/project.json` đang trỏ tới project cũ hoặc sai team. Không chạy production deploy bằng CLI trước khi preflight pass.
57
+
58
+ Nếu CLI chưa đăng nhập:
59
+
60
+ ```bash
61
+ vercel login
62
+ ```
63
+
64
+ ## Custom domain
65
+
66
+ Canonical domain: `piagent.io.vn`
67
+
68
+ Trong Vercel project `pi-agent` → Settings → Domains:
69
+
70
+ - add `piagent.io.vn` và đặt làm **Primary**;
71
+ - add `www.piagent.io.vn` và redirect về `piagent.io.vn`.
72
+
73
+ Trong iNET DNS, dùng đúng record Vercel Domains panel đang hiển thị; không hardcode một IP cũ trong runbook:
74
+
75
+ | Type | Name/Host | Value |
76
+ |---|---|---|
77
+ | `A` hoặc `ALIAS` theo Vercel | `@` | Exact apex target do Vercel hiển thị. |
78
+ | `CNAME` | `www` | Exact CNAME target do Vercel hiển thị. |
79
+
80
+ Không xoá `MX`, `TXT`, `NS`, hoặc email records nếu domain đang dùng mail. Sau khi DNS valid, Vercel sẽ cấp SSL tự động.
81
+
82
+ Expected URL behavior:
83
+
84
+ ```text
85
+ https://piagent.io.vn/ -> 200, không redirect
86
+ https://www.piagent.io.vn/ -> redirect về https://piagent.io.vn/
87
+ ```
88
+
89
+ Repo giữ canonical và Open Graph URL ở apex. Không đổi source sang `www` nếu hạ tầng vẫn được định hướng apex-primary.
90
+
91
+ ## Post-deploy verification
92
+
93
+ ```bash
94
+ curl -I https://piagent.io.vn/
95
+ curl -I https://www.piagent.io.vn/
96
+ curl -sSL https://piagent.io.vn/ | grep 'vX.Y.Z docs'
97
+ ```
98
+
99
+ Xác nhận thêm favicon/logo, GitHub/Facebook links, install commands, sidebar anchors và mobile layout.
100
+
101
+ ## Local preview
102
+
103
+ ```bash
104
+ cd docs-site
105
+ python3 -m http.server 4173
106
+ ```
107
+
108
+ Mở `http://localhost:4173`.
109
+
110
+ ## Security notes
111
+
112
+ - Không đặt secret, token, auth file hoặc session cache trong `docs-site/`.
113
+ - `docs-site/vercel.json` chỉ chứa static headers và URL behavior.
114
+ - Không cần environment variable cho site tĩnh.
115
+ - `.vercel/project.json` là metadata local bị ignore; luôn relink và chạy preflight trên checkout/máy deploy thay vì tin state còn sót lại.
@@ -0,0 +1,125 @@
1
+ # Workflow recipes
2
+
3
+ ## Mục tiêu
4
+
5
+ Các recipe này biến những bài toán lặp lại thành workflow có tên rõ, dùng được cho project khác mà không phụ thuộc một project nội bộ cụ thể.
6
+
7
+ ## Recipe 1 — Platform improvement
8
+
9
+ Dùng khi muốn cải tiến setup, prompt, MCP, model scope, memory, runtime policy, hoặc subagent workflow của Pi Agent Platform.
10
+
11
+ Lệnh trong Pi:
12
+
13
+ ```text
14
+ /onboard-project
15
+ /platform-improve Improve <target behavior> in <platform area>.
16
+ ```
17
+
18
+ Input tối thiểu:
19
+
20
+ - source docs URL hoặc repo URL nếu task cần external context;
21
+ - version/date/commit nếu có external context;
22
+ - target behavior cần áp dụng;
23
+ - non-goals: phần không làm trong scope này.
24
+
25
+ Output mong đợi:
26
+
27
+ - implementation matrix;
28
+ - code/docs/config thay đổi;
29
+ - verify evidence;
30
+ - phần không làm và lý do.
31
+
32
+ Verify chuẩn:
33
+
34
+ ```bash
35
+ bash scripts/verify-local.sh
36
+ bash scripts/team-doctor.sh /path/to/piagent --strict-share
37
+ pi list --approve
38
+ ```
39
+
40
+ Memory note:
41
+
42
+ - Nếu task tạo decision/lesson bền vững, user có thể yêu cầu `Remember: ...`.
43
+ - Agent dùng `piagent_memory_note` để ghi note explicit.
44
+ - Không tự ghi toàn bộ transcript vào memory.
45
+ - Nếu task tạo context điều hướng bền vững cho repo, dùng `piagent_context_index_record` để ghi node/edge/citation ngắn sau khi đã verify.
46
+
47
+ ## Recipe 2 — Backend spec to frontend
48
+
49
+ Dùng khi backend là source of truth nhưng frontend là nơi implement. Backend chỉ được scout/read-only.
50
+
51
+ Setup project generic:
52
+
53
+ ```text
54
+ /profile list
55
+ /profile be-readonly-fe
56
+ ```
57
+
58
+ Lệnh trong Pi:
59
+
60
+ ```text
61
+ /onboard-project
62
+ /be-to-fe Implement FE from BE spec: <endpoint/spec/change>
63
+ ```
64
+
65
+ Input tối thiểu:
66
+
67
+ - BE endpoint/spec/diff/ticket;
68
+ - expected FE behavior;
69
+ - target route/page/component nếu biết;
70
+ - verify expectation.
71
+
72
+ Agent phải làm:
73
+
74
+ 1. Scout BE read-only.
75
+ 2. Ghi contract snapshot.
76
+ 3. Map FE touchpoints.
77
+ 4. Implement FE only.
78
+ 5. Verify FE.
79
+ 6. Report BE gaps thay vì sửa BE.
80
+
81
+ ## Khi dùng profile nào
82
+
83
+ | Bài toán | Profile khuyến nghị |
84
+ |---|---|
85
+ | Platform/package/runtime improvement | `platform-development` hoặc profile platform riêng |
86
+ | Fullstack bình thường, FE/BE đều có thể sửa | `fullstack` |
87
+ | BE source of truth nhưng BE không được sửa | `be-readonly-fe` |
88
+ | Backend-only task | `backend-api` |
89
+ | Frontend-only task | `web-frontend` |
90
+ | Project đặc thù/private | profile explicit trong chính repo project |
91
+
92
+ Không dùng `auto` để suy ra `be-readonly-fe`, vì BE read-only là policy decision chứ không phải marker kỹ thuật.
93
+
94
+ ## Recipe 3 — Project memory
95
+
96
+ Dùng khi muốn Pi nhớ durable facts/decisions/preferences giữa các session mà không phải scout lại từ đầu.
97
+
98
+ ```text
99
+ /memory-policy
100
+ Remember: this repo uses pnpm, never npm.
101
+ ```
102
+
103
+ Rule:
104
+
105
+ 1. Memory là hint, không phải authority.
106
+ 2. Chỉ ghi explicit note khi user yêu cầu rõ.
107
+ 3. Không lưu secret/raw private data/source excerpt dài.
108
+ 4. Trước source edit, search memory nếu task liên quan rồi verify bằng repo file hiện tại.
109
+
110
+ ## Recipe 4 — Context index
111
+
112
+ Dùng khi muốn giảm scout lại giữa các session mà không bật auto memory.
113
+
114
+ ```text
115
+ /onboard-project
116
+ /context-index
117
+ /context-index search auth
118
+ ```
119
+
120
+ Rule:
121
+
122
+ 1. Context index là advisory map, không phải source of truth.
123
+ 2. Node/edge phải ngắn và có citation tới file/doc/task đã verify.
124
+ 3. Không lưu raw transcript, secret, token, session, hoặc source excerpt dài.
125
+ 4. Nếu index stale so với profile/tech/onboarding snapshot, chạy lại `/onboard-project` hoặc record lại bằng `piagent_context_index_record`.