@piagent/platform 1.2.13 → 1.2.14

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 (66) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/README.md +11 -3
  3. package/README.vi.md +90 -0
  4. package/architecture/layers.json +117 -0
  5. package/docs/README.md +23 -0
  6. package/docs/architecture.md +7 -61
  7. package/docs/command-reference-vietnamese.md +6 -6
  8. package/docs/distribution-standard.md +7 -7
  9. package/docs/en/README.md +13 -0
  10. package/docs/en/architecture.md +81 -0
  11. package/docs/en/maintainer-guide.md +121 -0
  12. package/docs/languages.json +40 -0
  13. package/docs/operator-manual-vietnamese.md +7 -7
  14. package/docs/package-architecture-notes.md +9 -0
  15. package/docs/release-install-policy.md +6 -6
  16. package/docs/security-threat-model.md +1 -1
  17. package/docs/team-onboarding.md +2 -2
  18. package/docs/vi/README.md +13 -0
  19. package/docs/vi/architecture.md +81 -0
  20. package/docs/vi/maintainer-guide.md +121 -0
  21. package/docs-site/architecture.html +38 -14
  22. package/docs-site/benchmark.html +3 -1
  23. package/docs-site/commands.html +3 -1
  24. package/docs-site/content/architecture.html +35 -13
  25. package/docs-site/context-engine.html +3 -1
  26. package/docs-site/index.html +3 -1
  27. package/docs-site/mcp-approval.html +3 -1
  28. package/docs-site/mcp-auth.html +3 -1
  29. package/docs-site/mcp-servers.html +3 -1
  30. package/docs-site/mcp.html +3 -1
  31. package/docs-site/permissions.html +3 -1
  32. package/docs-site/profiles.html +3 -1
  33. package/docs-site/quickstart.html +3 -1
  34. package/docs-site/runtime.html +3 -1
  35. package/docs-site/scope.html +3 -1
  36. package/docs-site/security.html +3 -1
  37. package/docs-site/team.html +3 -1
  38. package/docs-site/workflows.html +3 -1
  39. package/package.json +5 -1
  40. package/packages/piagent-core/README.md +6 -2
  41. package/packages/piagent-core/capabilities/capability-core.js +3 -0
  42. package/packages/piagent-core/capabilities/runtime-integrity.js +18 -0
  43. package/packages/piagent-core/extensions/guard-types.ts +0 -37
  44. package/packages/piagent-core/extensions/piagent-guard.ts +170 -2099
  45. package/packages/piagent-core/extensions/task-state.js +22 -3
  46. package/packages/piagent-core/package.json +1 -1
  47. package/packages/piagent-core/runtime/hooks/agent-start-hook.ts +213 -0
  48. package/packages/piagent-core/runtime/hooks/completion-hook.ts +203 -0
  49. package/packages/piagent-core/runtime/hooks/input-hook.ts +122 -0
  50. package/packages/piagent-core/runtime/hooks/session-hooks.ts +104 -0
  51. package/packages/piagent-core/runtime/hooks/session-start-hook.ts +140 -0
  52. package/packages/piagent-core/runtime/hooks/tool-result-hook.ts +316 -0
  53. package/packages/piagent-core/runtime/input/chat-images.ts +299 -0
  54. package/packages/piagent-core/runtime/runtime-limits.ts +21 -0
  55. package/packages/piagent-core/runtime/session/message-signals.ts +64 -0
  56. package/packages/piagent-core/runtime/session/runtime-state.ts +175 -0
  57. package/packages/piagent-core/runtime/session/system-prompt.ts +52 -0
  58. package/packages/piagent-core/runtime/session/tool-result-compaction.ts +352 -0
  59. package/packages/piagent-core/runtime/session/usage.ts +178 -0
  60. package/packages/piagent-core/runtime/tools/tool-groups.ts +86 -0
  61. package/packages/piagent-core/runtime/workflows/input-routing.ts +113 -0
  62. package/packages/piagent-core/runtime/workflows/task-intake.ts +73 -0
  63. package/scripts/build-docs-site.mjs +4 -1
  64. package/scripts/check-architecture.mjs +132 -0
  65. package/scripts/check-doc-languages.mjs +67 -0
  66. package/scripts/verify-local.sh +31 -0
@@ -0,0 +1,121 @@
1
+ # Maintainer guide
2
+
3
+ [Tiếng Việt](../vi/maintainer-guide.md)
4
+
5
+ ## Placement rule
6
+
7
+ Before adding code, answer one ownership question:
8
+
9
+ | Question | Destination |
10
+ |---|---|
11
+ | Does it register a Pi hook, command, tool, or session UI? | `packages/piagent-core/runtime/` |
12
+ | Is it a deterministic policy or scoring decision? | A focused core service module; no Pi API or direct UI output |
13
+ | Does it persist local runtime evidence? | State service with owner-only mode and bounded retention |
14
+ | Does it integrate MCP? | `packages/piagent-core/mcp/` |
15
+ | Does it resolve profiles, packs, or locks? | `packages/piagent-core/capabilities/` |
16
+ | Is it a CLI command? | Thin `scripts/` entrypoint calling a package service |
17
+ | Is it project-specific? | Project profile/adapter, never `piagent-core` |
18
+
19
+ Do not create a `utils` dumping ground. Name a module after the capability it owns.
20
+
21
+ ## Current split queue
22
+
23
+ ### P0: composition root
24
+
25
+ `packages/piagent-core/extensions/piagent-guard.ts` remains the main architecture debt. It is 8,290 lines after the lifecycle extraction and may only shrink under the architecture gate.
26
+
27
+ Already extracted:
28
+
29
+ - `runtime/session/message-signals.ts`
30
+ - `runtime/session/runtime-state.ts`
31
+ - `runtime/session/system-prompt.ts`
32
+ - `runtime/session/usage.ts`
33
+ - `runtime/session/tool-result-compaction.ts`
34
+ - `runtime/input/chat-images.ts`
35
+ - `runtime/hooks/session-start-hook.ts`
36
+ - `runtime/hooks/session-hooks.ts`
37
+ - `runtime/hooks/input-hook.ts`
38
+ - `runtime/hooks/agent-start-hook.ts`
39
+ - `runtime/hooks/completion-hook.ts`
40
+ - `runtime/hooks/tool-result-hook.ts`
41
+ - `runtime/tools/tool-groups.ts`
42
+ - `runtime/workflows/input-routing.ts`
43
+ - `runtime/workflows/task-intake.ts`
44
+ - `runtime/runtime-limits.ts`
45
+
46
+ Next cohesive extractions:
47
+
48
+ 1. `runtime/hooks/tool-call-hook.ts`: pre-call capability, path, shell, external-action, task-scope, and confirmation enforcement.
49
+ 2. `runtime/tools/`: policy, task, context, memory, onboarding, profile, document, and source tools.
50
+ 3. `runtime/commands/`: workflow, session, permission, context, MCP, profile, onboarding, and compatibility aliases.
51
+ 4. Focused core services for the remaining profile, memory, onboarding, and source-cache algorithms still embedded in the composition root.
52
+
53
+ Target: the composition root stays below 500 lines and contains registration order plus a small shared runtime state object.
54
+
55
+ ### P1: policy engine
56
+
57
+ Split `extensions/policy-core.js` by decision boundary:
58
+
59
+ - `policy/shell/tokenize.js`
60
+ - `policy/shell/expansion.js`
61
+ - `policy/path/match.js`
62
+ - `policy/path/candidates.js`
63
+ - `policy/exec/evaluate.js`
64
+
65
+ Keep one compatibility barrel until all internal imports move. Differential shell tests remain attached to the parser/matcher boundary.
66
+
67
+ ### P1: Context Engine
68
+
69
+ Split `extensions/context-engine.js` into:
70
+
71
+ - `context/index/store.js`
72
+ - `context/index/policy.js`
73
+ - `context/retrieval/search.js`
74
+ - `context/retrieval/pack.js`
75
+ - `context/telemetry.js`
76
+ - `context/test-impact.js`
77
+
78
+ The index store owns SQLite and secure deletion. Retrieval never opens policy on its own; it receives an explicit resolved exclusion policy.
79
+
80
+ ### P2: capability resolver
81
+
82
+ Split `capabilities/capability-core.js` into manifest validation, dependency resolution, permission projection, and lock integrity. Atomic file writes belong in an infrastructure module rather than the resolver.
83
+
84
+ ### P2: benchmark runner
85
+
86
+ Split `scripts/benchmark-runner.mjs` into a thin CLI plus package modules for suite materialization, surface execution, evidence collection, grading, and report rendering. The CLI must not calculate a second version of a benchmark metric.
87
+
88
+ ### P2: long documentation and tests
89
+
90
+ - Split the operator manual by install, daily workflow, session/usage, MCP, recovery, and reporting; keep an index at its stable path.
91
+ - Split `piagent-guard-integration.test.mjs` by runtime hook family while retaining shared harness helpers.
92
+ - Mirror each extracted source feature with one focused test file.
93
+
94
+ ## Runtime composition rules
95
+
96
+ - Registration functions receive an explicit dependency object. They do not import mutable state from the composition root.
97
+ - Shared session state has one typed owner and is passed to hook/tool/command registrars.
98
+ - Tool and command aliases call the same handler; aliases do not duplicate behavior.
99
+ - UI formatting stays in runtime adapters. Policy services return structured decisions.
100
+ - Every file under `packages/piagent-core/runtime/` is listed in
101
+ `capabilities/runtime-integrity.js`; the capability lock must pin executable
102
+ runtime code before a release can pass.
103
+ - Every filesystem write declares path, mode, retention, and source of truth.
104
+ - Every derived metric names its inputs and has a unit test with a hand-computed example.
105
+
106
+ ## Change checklist
107
+
108
+ 1. Put code in the owning layer.
109
+ 2. Add or update the EN/VI pair for normative behavior.
110
+ 3. Run `npm run architecture:check` before broad tests.
111
+ 4. Run focused tests for the changed feature.
112
+ 5. Run `npm run verify` before release.
113
+ 6. Update both language files in the same commit when semantics change.
114
+
115
+ ## Definition of done for the migration
116
+
117
+ - Composition root is at most 500 lines.
118
+ - No non-growth exception remains in `architecture/layers.json`.
119
+ - Core policy modules do not import runtime or CLI code.
120
+ - Every normative maintainer topic has an EN/VI pair.
121
+ - Full verification, package distribution, benchmark schema, and published docs gates remain green.
@@ -0,0 +1,40 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "defaultLanguage": "en",
4
+ "preservedTechnicalTerms": [
5
+ "agent",
6
+ "terminal",
7
+ "workflow",
8
+ "MCP",
9
+ "tool",
10
+ "runtime",
11
+ "context",
12
+ "session",
13
+ "token",
14
+ "model",
15
+ "thinking",
16
+ "benchmark"
17
+ ],
18
+ "pairs": [
19
+ {
20
+ "topic": "repository-readme",
21
+ "en": "README.md",
22
+ "vi": "README.vi.md"
23
+ },
24
+ {
25
+ "topic": "documentation-index",
26
+ "en": "docs/en/README.md",
27
+ "vi": "docs/vi/README.md"
28
+ },
29
+ {
30
+ "topic": "architecture",
31
+ "en": "docs/en/architecture.md",
32
+ "vi": "docs/vi/architecture.md"
33
+ },
34
+ {
35
+ "topic": "maintainer-guide",
36
+ "en": "docs/en/maintainer-guide.md",
37
+ "vi": "docs/vi/maintainer-guide.md"
38
+ }
39
+ ]
40
+ }
@@ -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.13
21
+ npm install -g --ignore-scripts @piagent/platform@1.2.14
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.13`. 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.14`. 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.13
102
+ npm install -g --ignore-scripts @piagent/platform@1.2.14
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.13 \
285
+ --package-source git:github.com/Vt-mmm/piagent@v1.2.14 \
286
286
  --mcp-preset core \
287
287
  --subagents-preset safe
288
288
  ```
@@ -971,8 +971,8 @@ Watchdog là optional adversarial reviewer ở cuối turn, không bật mặc
971
971
 
972
972
  | Command | Dùng để |
973
973
  |---|---|
974
- | `npm install -g --ignore-scripts @piagent/platform@1.2.13` | Cài terminal helper `piagent-*` từ release tag hiện tại. |
975
- | `pi install git:github.com/Vt-mmm/piagent@v1.2.13` | Install pinned release cho reproducible team setup. |
974
+ | `npm install -g --ignore-scripts @piagent/platform@1.2.14` | Cài terminal helper `piagent-*` từ release tag hiện tại. |
975
+ | `pi install git:github.com/Vt-mmm/piagent@v1.2.14` | Install pinned release cho reproducible team setup. |
976
976
  | `pi install git:github.com/Vt-mmm/piagent` | Install latest platform package cho máy cá nhân/sandbox. |
977
977
  | 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). |
978
978
  | 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. |
@@ -1083,7 +1083,7 @@ Mở lại Pi session sau khi install.
1083
1083
  Cài lại terminal helper đúng release rồi kiểm tra `PATH`:
1084
1084
 
1085
1085
  ```bash
1086
- npm install -g --ignore-scripts @piagent/platform@1.2.13
1086
+ npm install -g --ignore-scripts @piagent/platform@1.2.14
1087
1087
  command -v piagent-install
1088
1088
  ```
1089
1089
 
@@ -1,5 +1,14 @@
1
1
  # Package architecture notes
2
2
 
3
+ This path is retained for stable links. The maintained architecture documents are:
4
+
5
+ - [Architecture (English)](en/architecture.md)
6
+ - [Architecture (Tiếng Việt)](vi/architecture.md)
7
+ - [Maintainer guide (English)](en/maintainer-guide.md)
8
+ - [Maintainer guide (Tiếng Việt)](vi/maintainer-guide.md)
9
+
10
+ The remaining notes below describe historical package decisions and should not be used as the current file-placement map.
11
+
3
12
  ## Mục tiêu
4
13
 
5
14
  Pi Agent Platform được đóng gói như một reusable Pi package để dùng cho nhiều project mà không kéo theo rule nghiệp vụ của một repo cụ thể.
@@ -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.13 | Rollout guidance |
13
+ | Surface | Status for v1.2.14 | 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.13` | Fixed after resolution | Default for team rollout. |
36
+ | `stable` | `git:github.com/Vt-mmm/piagent@<resolved-commit-sha>` from `v1.2.14` | 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.13
56
+ npm install -g --ignore-scripts @piagent/platform@1.2.14
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.13 (helper package version)
65
- tag: v1.2.13
64
+ currentRelease: v1.2.14 (helper package version)
65
+ tag: v1.2.14
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.13
82
+ pi install git:github.com/Vt-mmm/piagent@v1.2.14
83
83
  ```
84
84
 
85
85
  Direct `pi install` does not create `piagent-*` commands on `PATH`.
@@ -22,7 +22,7 @@ This document covers the packaged guard, project profiles, capability locks, ins
22
22
  - The operator, operating-system account, Pi host, and explicitly trusted project repository are trusted to execute code.
23
23
  - Project-local Pi resources are loaded only after Pi project trust or an explicit operator override.
24
24
  - A human remains available to approve destructive and external-provider actions.
25
- - 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.13, and WSL2 is experimental/unverified.
25
+ - 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.14, and WSL2 is experimental/unverified.
26
26
  - Registry, GitHub, model-provider, MCP-provider, and Vercel controls are external dependencies. Their account security and platform guarantees are not replaced by this repository.
27
27
 
28
28
  ## Threat actors and failure modes
@@ -9,7 +9,7 @@ Một thành viên mới không cần biết local path của maintainer. Luồn
9
9
  ```bash
10
10
  node --version # >= 22.19.0
11
11
  npm install -g --ignore-scripts @earendil-works/pi-coding-agent@0.82.0
12
- npm install -g --ignore-scripts @piagent/platform@1.2.13
12
+ npm install -g --ignore-scripts @piagent/platform@1.2.14
13
13
  piagent-install --stable
14
14
  cd /path/to/project
15
15
  pi
@@ -43,7 +43,7 @@ Mặc định team dùng stable helper:
43
43
  ```bash
44
44
  node --version # >= 22.19.0
45
45
  npm install -g --ignore-scripts @earendil-works/pi-coding-agent@0.82.0
46
- npm install -g --ignore-scripts @piagent/platform@1.2.13
46
+ npm install -g --ignore-scripts @piagent/platform@1.2.14
47
47
  piagent-install --stable --dry-run
48
48
  piagent-install --stable
49
49
  ```
@@ -0,0 +1,13 @@
1
+ # Tài liệu Pi Agent Platform
2
+
3
+ [English](../en/README.md)
4
+
5
+ ## Bắt đầu từ đây
6
+
7
+ - [Architecture](architecture.md): chiều dependency, ownership của code, luồng runtime và ranh giới state.
8
+ - [Maintainer guide](maintainer-guide.md): code mới đặt ở đâu, file budget, thứ tự tách file và checklist review.
9
+ - [Release và install policy](../release-install-policy.md)
10
+ - [Quality benchmark](../quality-benchmark.md)
11
+ - [Security threat model](../security-threat-model.md)
12
+
13
+ Tài liệu tiếng Việt giữ nguyên các keyword kỹ thuật: agent, terminal, workflow, MCP, tool, runtime, context, session, token, model, thinking và benchmark. Code, schema, command name và reusable workflow prompt luôn dùng tiếng Anh.
@@ -0,0 +1,81 @@
1
+ # Architecture của Pi Agent Platform
2
+
3
+ [English](../en/architecture.md)
4
+
5
+ ## Mục tiêu
6
+
7
+ Platform là một Pi harness dùng lại cho nhiều project, không phải application chứa business logic riêng của một project. Architecture phải thể hiện rõ bốn tính chất trong code:
8
+
9
+ 1. Policy decision phải test được mà không cần mở Pi.
10
+ 2. Pi lifecycle hook chỉ compose feature, không ôm toàn bộ implementation của feature.
11
+ 3. Local state, MCP, process và filesystem access nằm sau adapter rõ ràng.
12
+ 4. Business rule riêng của project nằm trong project profile và adapter, không nằm trong core.
13
+
14
+ ## Chiều dependency
15
+
16
+ ```text
17
+ entrypoints/scripts
18
+ |
19
+ v
20
+ composition: extensions/piagent-guard.ts
21
+ |
22
+ +--------------------+
23
+ v v
24
+ runtime adapters integrations
25
+ | MCP / capabilities
26
+ v |
27
+ core services <-------------+
28
+ policy / task / context / security
29
+ ```
30
+
31
+ Dependency chỉ đi xuống. Core service không import Pi composition root hay runtime adapter. Runtime adapter được gọi core service và integration. Chỉ composition root mới register toàn bộ Pi extension.
32
+
33
+ Rule máy đọc nằm tại `architecture/layers.json`; chạy `npm run architecture:check` để enforce.
34
+
35
+ ## Các layer vật lý
36
+
37
+ | Layer | Vị trí hiện tại | Ownership | Không được chứa |
38
+ |---|---|---|---|
39
+ | Composition | `packages/piagent-core/extensions/piagent-guard.ts` | Wiring, dependency construction, thứ tự registration | Feature algorithm, mutable state implementation, formatter lớn |
40
+ | Runtime adapters | `packages/piagent-core/runtime/` | Pi lifecycle hook, shared session state, command/tool registration, input routing | Policy decision dùng lại |
41
+ | Core services | `packages/piagent-core/extensions/` trừ entrypoint | Policy, context, task lifecycle, state service | Pi command menu và UI text |
42
+ | MCP integration | `packages/piagent-core/mcp/` | MCP config layer, readiness, approval, command action | Task và context policy |
43
+ | Capabilities | `packages/piagent-core/capabilities/` | Profile resolution, pack validation, lock, source root | Pi session lifecycle |
44
+ | Security foundation | `packages/piagent-core/security/` | Sensitive-data primitive | Workflow behavior |
45
+ | Benchmark | `packages/piagent-core/benchmark/`, `benchmarks/` | Suite validation, scoring, evidence | Runtime enforcement |
46
+ | Entrypoints | `scripts/` | CLI argument và gọi use case | Domain logic trùng lặp |
47
+ | Product assets | `prompts/`, `skills/`, `subagents/`, `adapters/`, `packs/`, `schemas/` | Declarative behavior và contract | Hidden runtime state |
48
+
49
+ Folder `extensions/` vẫn chứa một số service module do lịch sử. Tên folder này là legacy; chỉ `piagent-guard.ts` được Pi load như extension. Mỗi lần migrate phải tách theo một feature trọn vẹn và giữ compatibility cho đến khi migration hoàn tất.
50
+
51
+ ## Luồng runtime
52
+
53
+ 1. Pi load một extension entrypoint duy nhất.
54
+ 2. Composition resolve base policy, project profile, capability lock và local session state.
55
+ 3. Runtime hook normalize input và thu session evidence qua một session-scoped state owner.
56
+ 4. Core service quyết định path, shell, MCP, task, context và final-gate policy.
57
+ 5. Runtime adapter register tool và slash command ngắn gọn.
58
+ 6. Owner-only local state ghi evidence; prompt chỉ là hướng dẫn, không phải enforcement boundary.
59
+
60
+ ## Ownership của state
61
+
62
+ | State | Owner | Vị trí | Commit |
63
+ |---|---|---|---:|
64
+ | OAuth và provider auth | Pi/provider | user config | Không |
65
+ | Platform install config | Piagent installer | global Pi settings | Không |
66
+ | Project profile và lock | Project | `.pi/piagent-profile*.json` | Có |
67
+ | Task, trace, telemetry, capture | Runtime | `.pi/piagent-state/` | Không |
68
+ | Session history | Pi | Pi session store | Không |
69
+ | Shared project instructions | Project | `AGENTS.md`, project docs | Có |
70
+
71
+ Một feature không được tạo representation authoritative thứ hai cho cùng một state. Derived index phải có policy digest và phải rebuild được từ source of truth.
72
+
73
+ ## Ranh giới file
74
+
75
+ - Runtime module mới: tối đa 500 dòng.
76
+ - Core module mới: tối đa 1.000 dòng.
77
+ - CLI entrypoint: tối đa 800 dòng; use case phải chuyển vào package module.
78
+ - File lớn đang tồn tại có non-growth budget rõ ràng trong `architecture/layers.json`.
79
+ - Test mirror feature path và test public behavior, không phụ thuộc private implementation order.
80
+
81
+ Thứ tự tách file và ownership rule chi tiết nằm trong [maintainer guide](maintainer-guide.md).
@@ -0,0 +1,121 @@
1
+ # Maintainer guide
2
+
3
+ [English](../en/maintainer-guide.md)
4
+
5
+ ## Rule đặt code
6
+
7
+ Trước khi thêm code, cần trả lời một câu hỏi về ownership:
8
+
9
+ | Câu hỏi | Vị trí |
10
+ |---|---|
11
+ | Code register Pi hook, command, tool hay session UI? | `packages/piagent-core/runtime/` |
12
+ | Code là policy decision hoặc scoring decision deterministic? | Core service module nhỏ, không dùng Pi API và không format UI |
13
+ | Code persist local runtime evidence? | State service có owner-only mode và bounded retention |
14
+ | Code integrate MCP? | `packages/piagent-core/mcp/` |
15
+ | Code resolve profile, pack hay lock? | `packages/piagent-core/capabilities/` |
16
+ | Code là CLI command? | `scripts/` chỉ parse argument và gọi package service |
17
+ | Code riêng cho một project? | Project profile/adapter, không đưa vào `piagent-core` |
18
+
19
+ Không tạo folder `utils` để gom code không rõ ownership. Module phải mang tên capability mà nó quản lý.
20
+
21
+ ## Thứ tự tách file hiện tại
22
+
23
+ ### P0: composition root
24
+
25
+ `packages/piagent-core/extensions/piagent-guard.ts` là architecture debt lớn nhất. Sau đợt tách lifecycle file còn 8.290 dòng và architecture gate chỉ cho phép file nhỏ dần.
26
+
27
+ Đã tách:
28
+
29
+ - `runtime/session/message-signals.ts`
30
+ - `runtime/session/runtime-state.ts`
31
+ - `runtime/session/system-prompt.ts`
32
+ - `runtime/session/usage.ts`
33
+ - `runtime/session/tool-result-compaction.ts`
34
+ - `runtime/input/chat-images.ts`
35
+ - `runtime/hooks/session-start-hook.ts`
36
+ - `runtime/hooks/session-hooks.ts`
37
+ - `runtime/hooks/input-hook.ts`
38
+ - `runtime/hooks/agent-start-hook.ts`
39
+ - `runtime/hooks/completion-hook.ts`
40
+ - `runtime/hooks/tool-result-hook.ts`
41
+ - `runtime/tools/tool-groups.ts`
42
+ - `runtime/workflows/input-routing.ts`
43
+ - `runtime/workflows/task-intake.ts`
44
+ - `runtime/runtime-limits.ts`
45
+
46
+ Những feature cần tách tiếp theo một khối trọn vẹn:
47
+
48
+ 1. `runtime/hooks/tool-call-hook.ts`: enforcement trước tool call cho capability, path, shell, external action, task scope và confirmation.
49
+ 2. `runtime/tools/`: policy, task, context, memory, onboarding, profile, document và source tools.
50
+ 3. `runtime/commands/`: workflow, session, permission, context, MCP, profile, onboarding và compatibility alias.
51
+ 4. Tạo core service tập trung cho profile, memory, onboarding và source-cache algorithm vẫn còn nằm trong composition root.
52
+
53
+ Mục tiêu: composition root dưới 500 dòng, chỉ giữ registration order và một shared runtime state object nhỏ.
54
+
55
+ ### P1: policy engine
56
+
57
+ Tách `extensions/policy-core.js` theo decision boundary:
58
+
59
+ - `policy/shell/tokenize.js`
60
+ - `policy/shell/expansion.js`
61
+ - `policy/path/match.js`
62
+ - `policy/path/candidates.js`
63
+ - `policy/exec/evaluate.js`
64
+
65
+ Giữ một compatibility barrel cho đến khi toàn bộ internal import đã migrate. Differential shell test phải nằm sát parser/matcher boundary.
66
+
67
+ ### P1: Context Engine
68
+
69
+ Tách `extensions/context-engine.js` thành:
70
+
71
+ - `context/index/store.js`
72
+ - `context/index/policy.js`
73
+ - `context/retrieval/search.js`
74
+ - `context/retrieval/pack.js`
75
+ - `context/telemetry.js`
76
+ - `context/test-impact.js`
77
+
78
+ Index store owner SQLite và secure deletion. Retrieval không tự load policy; nó nhận resolved exclusion policy bắt buộc từ caller.
79
+
80
+ ### P2: capability resolver
81
+
82
+ Tách `capabilities/capability-core.js` thành manifest validation, dependency resolution, permission projection và lock integrity. Atomic file write thuộc infrastructure module, không thuộc resolver.
83
+
84
+ ### P2: benchmark runner
85
+
86
+ Tách `scripts/benchmark-runner.mjs` thành CLI mỏng và package module cho suite materialization, surface execution, evidence collection, grading và report rendering. CLI không được tự tính một bản benchmark metric thứ hai.
87
+
88
+ ### P2: docs và test dài
89
+
90
+ - Tách operator manual theo install, daily workflow, session/usage, MCP, recovery và reporting; stable path cũ trở thành index.
91
+ - Tách `piagent-guard-integration.test.mjs` theo từng runtime hook family, vẫn dùng chung harness helper.
92
+ - Mỗi source feature được tách phải có một test file tập trung.
93
+
94
+ ## Rule cho runtime composition
95
+
96
+ - Registration function nhận dependency object rõ ràng, không import mutable state từ composition root.
97
+ - Shared session state có một typed owner và được truyền vào hook/tool/command registrar.
98
+ - Tool và command alias gọi cùng handler; alias không duplicate behavior.
99
+ - UI formatting nằm trong runtime adapter. Policy service trả về structured decision.
100
+ - Mọi file trong `packages/piagent-core/runtime/` phải có trong
101
+ `capabilities/runtime-integrity.js`; capability lock phải pin toàn bộ runtime
102
+ code thực thi trước khi release được phép pass.
103
+ - Mỗi filesystem write phải khai báo path, mode, retention và source of truth.
104
+ - Mỗi derived metric phải nêu input và có unit test tính tay một ví dụ.
105
+
106
+ ## Checklist khi thay đổi
107
+
108
+ 1. Đặt code đúng owning layer.
109
+ 2. Thêm hoặc update cặp EN/VI nếu behavior là normative.
110
+ 3. Chạy `npm run architecture:check` trước broad test.
111
+ 4. Chạy focused test của feature vừa sửa.
112
+ 5. Chạy `npm run verify` trước release.
113
+ 6. Khi semantic thay đổi, update hai language file trong cùng commit.
114
+
115
+ ## Definition of done cho architecture migration
116
+
117
+ - Composition root tối đa 500 dòng.
118
+ - `architecture/layers.json` không còn non-growth exception.
119
+ - Core policy module không import runtime hay CLI code.
120
+ - Mọi maintainer topic normative đều có cặp EN/VI.
121
+ - Full verification, package distribution, benchmark schema và published docs gate đều xanh.
@@ -27,7 +27,8 @@
27
27
  <span>Pi Agent Platform</span>
28
28
  </a>
29
29
  <div class="top-actions">
30
- <span class="pill"><span class="pill-dot"></span>v1.2.13 docs</span>
30
+ <span class="pill"><span class="pill-dot"></span>v1.2.14 docs · VI</span>
31
+ <a class="button" href="https://github.com/Vt-mmm/piagent/blob/main/docs/en/README.md" lang="en" target="_blank" rel="noopener noreferrer">English docs</a>
31
32
  <a class="button social" href="https://github.com/Vt-mmm/piagent" target="_blank" rel="noopener noreferrer" aria-label="Mở GitHub repository">
32
33
  <svg viewBox="0 0 24 24" fill="none" aria-hidden="true">
33
34
  <path d="M7 17 17 7M9 7h8v8" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" />
@@ -95,34 +96,56 @@
95
96
  <p>Repo này không nhét business logic vào core. Core chỉ giữ policy, prompts, guard, skills và scripts dùng lại được.</p>
96
97
  </div>
97
98
  <section class="section">
98
-
99
+ <div class="callout">
100
+ <strong>Chiều dependency được enforce bằng code.</strong>
101
+ <p><span class="inline-code">architecture/layers.json</span> là rule máy đọc; <span class="inline-code">npm run architecture:check</span> chặn dependency ngược và file vượt budget.</p>
102
+ </div>
99
103
  <div class="grid cols-3">
100
104
  <article class="card">
101
- <h3 id="core-package">Core package</h3>
102
- <p><span class="inline-code">packages/piagent-core</span> chứa extension guard, prompts, skills và subagent roles.</p>
105
+ <h3 id="composition">Composition</h3>
106
+ <p><span class="inline-code">piagent-guard.ts</span> chỉ giữ wiring, registration order và shared runtime state. File này không được tiếp tục chứa feature algorithm.</p>
103
107
  </article>
104
108
  <article class="card">
105
- <h3 id="adapters">Adapters</h3>
106
- <p><span class="inline-code">adapters/</span> chứa profile dùng lại: frontend, backend, fullstack, data, devops, docs.</p>
109
+ <h3 id="runtime-adapters">Runtime adapters</h3>
110
+ <p><span class="inline-code">packages/piagent-core/runtime</span> quản lý Pi hook, command, tool, session UI, usage, log compaction và workflow input routing.</p>
107
111
  </article>
108
112
  <article class="card">
109
- <h3 id="capability-packs">Capability packs</h3>
110
- <p><span class="inline-code">packs/</span> gom policy, lifecycle, recipes và eval scenarios theo manifest có lock.</p>
113
+ <h3 id="core-services">Core services</h3>
114
+ <p>Policy, task, context và state trả về structured decision. Core service không import runtime adapter hay Pi composition root.</p>
111
115
  </article>
112
116
  <article class="card">
113
- <h3 id="policies">Policies</h3>
114
- <p>Base policy định nghĩa protected paths, command rules, permission modes và human-action gates.</p>
117
+ <h3 id="integrations">Integrations</h3>
118
+ <p><span class="inline-code">mcp/</span>, <span class="inline-code">capabilities/</span> và <span class="inline-code">security/</span> có ownership riêng; không nhúng task workflow vào integration.</p>
115
119
  </article>
116
120
  <article class="card">
117
- <h3 id="scripts">Scripts</h3>
118
- <p>Setup, doctor, model scope, MCP, subagents, benchmark và trusted-run wrapper đều có CLI riêng.</p>
121
+ <h3 id="entrypoints">Entrypoints</h3>
122
+ <p><span class="inline-code">scripts/</span> parse CLI argument rồi gọi use case. Metric, policy và state transition không được duplicate trong CLI.</p>
119
123
  </article>
120
124
  <article class="card">
121
- <h3 id="docs">Docs</h3>
122
- <p><span class="inline-code">docs/</span> giữ manual dài. <span class="inline-code">docs-site/</span> là trang HTML gọn cho team.</p>
125
+ <h3 id="product-assets">Product assets</h3>
126
+ <p><span class="inline-code">prompts/</span>, <span class="inline-code">skills/</span>, <span class="inline-code">subagents/</span>, <span class="inline-code">adapters/</span>, <span class="inline-code">packs/</span> và <span class="inline-code">schemas/</span> là declarative assets.</p>
123
127
  </article>
124
128
  </div>
125
129
  </section>
130
+
131
+ <section class="section">
132
+ <div class="section-head">
133
+ <p class="eyebrow">Ownership</p>
134
+ <h2 id="state-ownership">Một state chỉ có một source of truth</h2>
135
+ <p>Project profile và lock có thể commit. Task evidence, telemetry, trace, capture và session history là local state. Derived index phải có policy digest và rebuild được.</p>
136
+ </div>
137
+ <div class="table-wrap">
138
+ <table>
139
+ <thead><tr><th>State</th><th>Owner</th><th>Vị trí</th><th>Commit</th></tr></thead>
140
+ <tbody>
141
+ <tr><td>Project profile + lock</td><td>Project</td><td><span class="inline-code">.pi/piagent-profile*.json</span></td><td>Có</td></tr>
142
+ <tr><td>Task, trace, telemetry, capture</td><td>Runtime</td><td><span class="inline-code">.pi/piagent-state/</span></td><td>Không</td></tr>
143
+ <tr><td>Session history</td><td>Pi</td><td>Pi session store</td><td>Không</td></tr>
144
+ <tr><td>Shared instructions</td><td>Project</td><td><span class="inline-code">AGENTS.md</span>, project docs</td><td>Có</td></tr>
145
+ </tbody>
146
+ </table>
147
+ </div>
148
+ </section>
126
149
  <nav class="pager" aria-label="Trang kế tiếp">
127
150
  <a class="pager-prev" href="/security">
128
151
  <span class="pager-label">Trước</span>
@@ -139,6 +162,7 @@
139
162
  <div class="footer-links" aria-label="External links">
140
163
  <a href="https://piagent.io.vn" target="_blank" rel="noopener noreferrer">piagent.io.vn</a>
141
164
  <a href="https://github.com/Vt-mmm/piagent" target="_blank" rel="noopener noreferrer">GitHub repository</a>
165
+ <a href="https://github.com/Vt-mmm/piagent/blob/main/docs/en/README.md" lang="en" target="_blank" rel="noopener noreferrer">English docs</a>
142
166
  <a href="https://www.facebook.com/vinhtam0544/" target="_blank" rel="noopener noreferrer">Facebook profile</a>
143
167
  </div>
144
168
  </footer>
@@ -27,7 +27,8 @@
27
27
  <span>Pi Agent Platform</span>
28
28
  </a>
29
29
  <div class="top-actions">
30
- <span class="pill"><span class="pill-dot"></span>v1.2.13 docs</span>
30
+ <span class="pill"><span class="pill-dot"></span>v1.2.14 docs · VI</span>
31
+ <a class="button" href="https://github.com/Vt-mmm/piagent/blob/main/docs/en/README.md" lang="en" target="_blank" rel="noopener noreferrer">English docs</a>
31
32
  <a class="button social" href="https://github.com/Vt-mmm/piagent" target="_blank" rel="noopener noreferrer" aria-label="Mở GitHub repository">
32
33
  <svg viewBox="0 0 24 24" fill="none" aria-hidden="true">
33
34
  <path d="M7 17 17 7M9 7h8v8" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" />
@@ -324,6 +325,7 @@
324
325
  <div class="footer-links" aria-label="External links">
325
326
  <a href="https://piagent.io.vn" target="_blank" rel="noopener noreferrer">piagent.io.vn</a>
326
327
  <a href="https://github.com/Vt-mmm/piagent" target="_blank" rel="noopener noreferrer">GitHub repository</a>
328
+ <a href="https://github.com/Vt-mmm/piagent/blob/main/docs/en/README.md" lang="en" target="_blank" rel="noopener noreferrer">English docs</a>
327
329
  <a href="https://www.facebook.com/vinhtam0544/" target="_blank" rel="noopener noreferrer">Facebook profile</a>
328
330
  </div>
329
331
  </footer>