@piagent/platform 1.8.0 → 1.9.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 (216) hide show
  1. package/AGENTS.md +7 -0
  2. package/CHANGELOG.md +97 -1
  3. package/README.md +45 -70
  4. package/README.vi.md +34 -61
  5. package/architecture/layers.json +16 -3
  6. package/catalog/capabilities.json +14 -7
  7. package/catalog/claude-model-additions.json +42 -0
  8. package/docs/auto-delegation-policy.md +2 -0
  9. package/docs/command-reference-vietnamese.md +68 -90
  10. package/docs/context-window-policy.md +5 -5
  11. package/docs/distribution-standard.md +13 -16
  12. package/docs/en/architecture.md +9 -1
  13. package/docs/herdr-workflow.md +2 -3
  14. package/docs/languages.json +4 -4
  15. package/docs/managed-local-acceptance.md +403 -0
  16. package/docs/mcp-and-tools.md +5 -7
  17. package/docs/memory-policy.md +3 -3
  18. package/docs/model-options.md +2 -2
  19. package/docs/oauth-providers.md +1 -1
  20. package/docs/operator-manual-vietnamese.md +82 -127
  21. package/docs/package-architecture-notes.md +4 -4
  22. package/docs/piagent-core-improvement-plan.md +3 -5
  23. package/docs/piagent-core-plan-checkpoint-2026-09-06.json +2 -13
  24. package/docs/piagent-runtime-benchmark-execution-plan.md +10 -8
  25. package/docs/project-adapters.md +3 -3
  26. package/docs/project-onboarding.md +15 -16
  27. package/docs/publishing-for-teams.md +2 -1
  28. package/docs/quality-benchmark.md +2 -0
  29. package/docs/quickstart-vietnamese.md +23 -24
  30. package/docs/release-install-policy.md +3 -2
  31. package/docs/research/harness-next-evidence-review.md +7 -7
  32. package/docs/runtime-harness-standard.md +2 -0
  33. package/docs/runtime-policy-design.md +2 -0
  34. package/docs/runtime-quality-baseline.md +2 -0
  35. package/docs/subagent-orchestration-capabilities.md +1 -1
  36. package/docs/subagents-and-multiagent.md +10 -8
  37. package/docs/task-implementation-contract.md +2 -0
  38. package/docs/task-lifecycle-vietnamese.md +2 -0
  39. package/docs/team-onboarding.md +28 -59
  40. package/docs/usage-observability.md +2 -2
  41. package/docs/vi/architecture.md +9 -1
  42. package/docs/workflow-recipes.md +6 -10
  43. package/docs-site/architecture.html +4 -3
  44. package/docs-site/assets/docs.css +80 -0
  45. package/docs-site/benchmark.html +7 -1
  46. package/docs-site/commands.html +37 -23
  47. package/docs-site/content/architecture.html +2 -2
  48. package/docs-site/content/benchmark.html +5 -0
  49. package/docs-site/content/commands.html +35 -22
  50. package/docs-site/content/ecosystem.html +144 -0
  51. package/docs-site/content/en/architecture.html +1 -1
  52. package/docs-site/content/en/benchmark.html +5 -0
  53. package/docs-site/content/en/commands.html +30 -13
  54. package/docs-site/content/en/ecosystem.html +144 -0
  55. package/docs-site/content/en/index.html +24 -9
  56. package/docs-site/content/en/quickstart.html +10 -12
  57. package/docs-site/content/en/security.html +1 -1
  58. package/docs-site/content/en/team.html +2 -2
  59. package/docs-site/content/en/whats-new.html +77 -1
  60. package/docs-site/content/en/workflows.html +29 -31
  61. package/docs-site/content/index.html +24 -9
  62. package/docs-site/content/quickstart.html +10 -12
  63. package/docs-site/content/security.html +2 -2
  64. package/docs-site/content/team.html +2 -2
  65. package/docs-site/content/whats-new.html +77 -1
  66. package/docs-site/content/workflows.html +36 -38
  67. package/docs-site/context-engine.html +2 -1
  68. package/docs-site/ecosystem.html +283 -0
  69. package/docs-site/en/architecture.html +3 -2
  70. package/docs-site/en/benchmark.html +7 -1
  71. package/docs-site/en/commands.html +32 -14
  72. package/docs-site/en/context-engine.html +2 -1
  73. package/docs-site/en/ecosystem.html +283 -0
  74. package/docs-site/en/index.html +30 -14
  75. package/docs-site/en/mcp-approval.html +2 -1
  76. package/docs-site/en/mcp-auth.html +2 -1
  77. package/docs-site/en/mcp-servers.html +2 -1
  78. package/docs-site/en/mcp.html +2 -1
  79. package/docs-site/en/permissions.html +2 -1
  80. package/docs-site/en/profiles.html +2 -1
  81. package/docs-site/en/quickstart.html +17 -18
  82. package/docs-site/en/runtime.html +2 -1
  83. package/docs-site/en/scope.html +2 -1
  84. package/docs-site/en/security.html +6 -5
  85. package/docs-site/en/team.html +4 -3
  86. package/docs-site/en/whats-new.html +85 -8
  87. package/docs-site/en/workflows.html +34 -35
  88. package/docs-site/index.html +30 -14
  89. package/docs-site/mcp-approval.html +2 -1
  90. package/docs-site/mcp-auth.html +2 -1
  91. package/docs-site/mcp-servers.html +2 -1
  92. package/docs-site/mcp.html +2 -1
  93. package/docs-site/permissions.html +2 -1
  94. package/docs-site/profiles.html +2 -1
  95. package/docs-site/quickstart.html +17 -18
  96. package/docs-site/runtime.html +2 -1
  97. package/docs-site/scope.html +2 -1
  98. package/docs-site/security.html +7 -6
  99. package/docs-site/team.html +4 -3
  100. package/docs-site/whats-new.html +85 -8
  101. package/docs-site/workflows.html +41 -42
  102. package/evals/fs5-causal-arm.v1.json +2 -2
  103. package/evals/private-holdout-v1/CURRENT_BOUNDARY.md +17 -0
  104. package/evals/private-holdout-v1/public-exposure.v2.json +2 -2
  105. package/package.json +8 -7
  106. package/packages/piagent-core/README.md +15 -23
  107. package/packages/piagent-core/docs/context-efficiency-improvement-plan.md +2 -0
  108. package/packages/piagent-core/extensions/experiment-loop-policy.ts +75 -0
  109. package/packages/piagent-core/extensions/local-state-path.js +15 -0
  110. package/packages/piagent-core/extensions/piagent-guard.ts +108 -960
  111. package/packages/piagent-core/extensions/policy-core.js +2 -2
  112. package/packages/piagent-core/extensions/source-checkout-paths.ts +54 -0
  113. package/packages/piagent-core/managed/broker-client.mjs +49 -0
  114. package/packages/piagent-core/managed/capabilities.mjs +28 -0
  115. package/packages/piagent-core/managed/compaction.mjs +63 -0
  116. package/packages/piagent-core/managed/doctor.mjs +107 -0
  117. package/packages/piagent-core/managed/native-catalog.mjs +42 -0
  118. package/packages/piagent-core/managed/patch-snapshot.mjs +48 -0
  119. package/packages/piagent-core/managed/repository-operation.mjs +84 -0
  120. package/packages/piagent-core/managed/request-stream.mjs +129 -0
  121. package/packages/piagent-core/managed/resource-loader.mjs +42 -0
  122. package/packages/piagent-core/managed/review-snapshot-worker.mjs +27 -0
  123. package/packages/piagent-core/managed/sandbox-diagnostic.mjs +12 -0
  124. package/packages/piagent-core/managed/search-fallback.mjs +93 -0
  125. package/packages/piagent-core/managed/session.mjs +472 -0
  126. package/packages/piagent-core/managed/store.d.mts +3 -0
  127. package/packages/piagent-core/managed/store.mjs +64 -0
  128. package/packages/piagent-core/managed/tool-boundary.mjs +243 -0
  129. package/packages/piagent-core/managed/tool-worker.mjs +36 -0
  130. package/packages/piagent-core/managed/toolchain.mjs +120 -0
  131. package/packages/piagent-core/managed/web-fetch.mjs +105 -0
  132. package/packages/piagent-core/managed/web-search.mjs +96 -0
  133. package/packages/piagent-core/managed/workflow.mjs +299 -0
  134. package/packages/piagent-core/package.json +2 -5
  135. package/packages/piagent-core/policies/base-policy.json +80 -26
  136. package/packages/piagent-core/runtime/hooks/agent-start-hook.ts +3 -3
  137. package/packages/piagent-core/runtime/hooks/input-hook.ts +35 -196
  138. package/packages/piagent-core/runtime/hooks/session-start-hook.ts +2 -0
  139. package/packages/piagent-core/runtime/inspection/approval-broker.ts +9 -1
  140. package/packages/piagent-core/runtime/managed-failure.d.mts +10 -0
  141. package/packages/piagent-core/runtime/managed-failure.mjs +164 -0
  142. package/packages/piagent-core/runtime/orchestration/minimal-delegation-policy.ts +8 -29
  143. package/packages/piagent-core/runtime/orchestration/owned-work-budget.ts +1 -1
  144. package/packages/piagent-core/runtime/policy/block-remedy.ts +5 -3
  145. package/packages/piagent-core/runtime/registration/context-commands.ts +1 -1
  146. package/packages/piagent-core/runtime/registration/knowledge-tools.ts +7 -7
  147. package/packages/piagent-core/runtime/registration/policy-tools.ts +2 -2
  148. package/packages/piagent-core/runtime/registration/session-commands.ts +11 -26
  149. package/packages/piagent-core/runtime/registration/task-evidence-tools.ts +1 -1
  150. package/packages/piagent-core/runtime/session/system-prompt.ts +6 -7
  151. package/packages/piagent-core/runtime/workflows/webui-runtime-command.ts +6 -6
  152. package/packages/piagent-core/runtime/workflows/webui-workflow.ts +6 -11
  153. package/packages/piagent-core/security/sensitive-text.js +9 -0
  154. package/packages/piagent-core/skills/piagent-ops/SKILL.md +8 -10
  155. package/packages/piagent-core/skills/test-audit/SKILL.md +101 -0
  156. package/packages/piagent-core/subagents/piagent-planner.md +1 -1
  157. package/packages/piagent-webui/dist/client/assets/{MarkdownMessage-DMU7Xe_O.js → MarkdownMessage-Dd9wPk-v.js} +1 -1
  158. package/packages/piagent-webui/dist/client/assets/index-7I-50Q2U.js +228 -0
  159. package/packages/piagent-webui/dist/client/assets/{index-DVahUVWy.css → index-DgSmcnP8.css} +1 -1
  160. package/packages/piagent-webui/dist/client/index.html +2 -2
  161. package/packages/piagent-webui/extension/piagent-webui.ts +11 -11
  162. package/packages/piagent-webui/extension/session-stream-adapter.ts +3 -1
  163. package/packages/piagent-webui/extension/terminal-session-adapter.ts +6 -1
  164. package/packages/piagent-webui/gateway/company-relay.ts +308 -0
  165. package/packages/piagent-webui/gateway/control-socket.ts +39 -12
  166. package/packages/piagent-webui/gateway/gateway-service.ts +109 -28
  167. package/packages/piagent-webui/gateway/gateway-session-stream.ts +58 -2
  168. package/packages/piagent-webui/gateway/managed-gateway.mjs +41 -0
  169. package/packages/piagent-webui/gateway/managed-launch.ts +145 -0
  170. package/packages/piagent-webui/gateway/managed-projection.ts +20 -0
  171. package/packages/piagent-webui/gateway/pi-host.ts +22 -4
  172. package/packages/piagent-webui/gateway/runtime-session-controls.ts +5 -2
  173. package/packages/piagent-webui/gateway/session-approval-authority.ts +28 -0
  174. package/packages/piagent-webui/gateway/session-catalog.ts +11 -3
  175. package/packages/piagent-webui/gateway/session-command-controller.ts +8 -2
  176. package/packages/piagent-webui/gateway/session-file-facts.ts +25 -0
  177. package/packages/piagent-webui/gateway/session-inspection-registry.ts +40 -9
  178. package/packages/piagent-webui/gateway/session-list-cache.ts +68 -0
  179. package/packages/piagent-webui/gateway/session-runtime-ownership.ts +8 -1
  180. package/packages/piagent-webui/gateway/session-runtime-supervisor.ts +20 -27
  181. package/packages/piagent-webui/ownership/managed-terminal-lease.ts +27 -0
  182. package/packages/piagent-webui/ownership/profile-state.ts +2 -0
  183. package/packages/piagent-webui/ownership/session-lease-store.ts +22 -1
  184. package/packages/piagent-webui/server/approval-projection.ts +9 -0
  185. package/packages/piagent-webui/server/core-inspection-provider.ts +4 -9
  186. package/packages/piagent-webui/server/loopback-server.ts +37 -1
  187. package/packages/piagent-webui/server/message-stop-reason.ts +11 -0
  188. package/packages/piagent-webui/server/tool-call-summary.ts +185 -0
  189. package/packages/piagent-webui/server/transcript-projection.ts +86 -3
  190. package/packs/engineering-base/pack.json +4 -0
  191. package/schemas/piagent-webui/runtime-command-v1.schema.json +1 -2
  192. package/schemas/piagent-webui/session-catalog-v1.schema.json +8 -0
  193. package/schemas/piagent-webui/transcript-v1.schema.json +94 -1
  194. package/scripts/build-docs-site.mjs +23 -12
  195. package/scripts/check-public-wording.mjs +5 -6
  196. package/scripts/check-runtime-advisories.mjs +23 -6
  197. package/scripts/claude-model-additions.mjs +33 -0
  198. package/scripts/configure-model-scope.sh +30 -6
  199. package/scripts/configure-subagents.sh +1 -1
  200. package/scripts/explain-command.mjs +5 -6
  201. package/scripts/model-scope-prune.mjs +75 -0
  202. package/scripts/phase-tools-evaluation.mjs +9 -4
  203. package/scripts/piagent-cli.mjs +51 -2
  204. package/scripts/piagent-dashboard.mjs +27 -4
  205. package/scripts/piagent-installations.mjs +26 -0
  206. package/scripts/piagent-studio.mjs +155 -0
  207. package/scripts/runtime-advisory-exceptions.json +29 -0
  208. package/scripts/team-doctor.sh +20 -1
  209. package/scripts/typescript-loader.mjs +6 -0
  210. package/scripts/verify-local.sh +2 -2
  211. package/templates/global/settings.json +3 -1
  212. package/templates/project/.pi/project-context.md +3 -3
  213. package/templates/project/AGENTS.md +4 -5
  214. package/docs/piagent-core-reasoning-research-2026-09-06.md +0 -225
  215. package/docs/piagent-core-research-sources-2026-09-06.json +0 -416
  216. package/packages/piagent-webui/dist/client/assets/index-Cui9AAV_.js +0 -176
@@ -0,0 +1,75 @@
1
+ import { execFileSync } from "node:child_process";
2
+ import fs from "node:fs";
3
+ import path from "node:path";
4
+
5
+ // Experiment-loop tools (an optional Pi package may add them): run_experiment
6
+ // runs `bash -c <command>` itself, so the guard checks that command like any
7
+ // shell command (see SHELL_TOOL_NAMES). log_experiment then commits every
8
+ // change when an idea is kept (`git add -A`, `git commit`) and erases every
9
+ // uncommitted change when it is dropped (`git checkout -- .`, `git clean -fd`),
10
+ // outside the guard. The loop is therefore allowed only where those commands
11
+ // cannot destroy the member's work: in the session folder itself, on an
12
+ // `experiment/` branch or in a linked worktree, starting from a tree with
13
+ // nothing uncommitted.
14
+ export const EXPERIMENT_LOOP_TOOLS = new Set(["init_experiment", "run_experiment", "log_experiment"]);
15
+
16
+ // The loop's own files live in `.auto/` and survive a discard, so they may be
17
+ // uncommitted. Files of any other layout count as project files: the safe side.
18
+ const EXPERIMENT_FILES = /^\.auto\//;
19
+ const EXPERIMENT_BRANCH = "experiment/";
20
+ const DEDICATED_TREE = "Run the loop on a branch or worktree of its own, with nothing uncommitted: `git switch -c experiment/<goal>`, "
21
+ + "or `git worktree add ../<repo>-experiment -b experiment/<goal>` and start Pi in that folder. Your other changes stay untouched.";
22
+
23
+ type Decision = { block: true; reason: string } | undefined;
24
+
25
+ // Trimmed at the end only: `git status --porcelain` lines start with a space.
26
+ function git(cwd: string, args: string[]): string | null {
27
+ try {
28
+ return execFileSync("git", ["-C", cwd, ...args], { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], timeout: 5_000 }).trimEnd();
29
+ } catch { return null; }
30
+ }
31
+
32
+ // `workingDir` from the loop's config (`.auto/config.json`), resolved the way
33
+ // the loop resolves it.
34
+ function configuredWorkingDir(cwd: string): string | null {
35
+ const file = path.join(cwd, ".auto", "config.json");
36
+ if (!fs.existsSync(file)) return null;
37
+ try {
38
+ const value = JSON.parse(fs.readFileSync(file, "utf8"))?.workingDir;
39
+ return typeof value === "string" && value.trim() ? path.resolve(cwd, value) : null;
40
+ } catch { return null; }
41
+ }
42
+
43
+ // Files with uncommitted changes, other than the loop's own.
44
+ export function uncommittedProjectFiles(cwd: string): string[] {
45
+ return (git(cwd, ["status", "--porcelain", "--untracked-files=all"]) ?? "").split("\n").filter(Boolean)
46
+ .map((line) => line.slice(3)).filter((file) => !EXPERIMENT_FILES.test(file));
47
+ }
48
+
49
+ export function experimentLoopDecision(cwd: string, toolName: string): Decision {
50
+ if (!EXPERIMENT_LOOP_TOOLS.has(toolName)) return undefined;
51
+ const workingDir = configuredWorkingDir(cwd);
52
+ if (workingDir && path.resolve(workingDir) !== path.resolve(cwd)) {
53
+ return { block: true, reason: `Blocked ${toolName}: the experiment config moves its commands to ${workingDir}. `
54
+ + "Start Pi in that folder instead, so the guard checks each command where it runs." };
55
+ }
56
+ if (toolName === "run_experiment") return undefined;
57
+ const gitDir = git(cwd, ["rev-parse", "--absolute-git-dir"]);
58
+ if (gitDir === null) {
59
+ return { block: true, reason: `Blocked ${toolName}: the experiment loop commits and reverts with git, and this folder is not a git repository.` };
60
+ }
61
+ const commonDir = git(cwd, ["rev-parse", "--path-format=absolute", "--git-common-dir"]);
62
+ const branch = git(cwd, ["symbolic-ref", "--quiet", "--short", "HEAD"]);
63
+ const linkedWorktree = commonDir !== null && path.resolve(commonDir) !== path.resolve(gitDir);
64
+ if (!linkedWorktree && !branch?.startsWith(EXPERIMENT_BRANCH)) {
65
+ return { block: true, reason: `Blocked ${toolName}: log_experiment commits every change when an idea is kept and erases every uncommitted change when it is discarded, and this is ${branch ? `branch ${branch}` : "a detached checkout"}. ${DEDICATED_TREE}` };
66
+ }
67
+ if (toolName === "init_experiment") {
68
+ const dirty = uncommittedProjectFiles(cwd);
69
+ if (dirty.length > 0) {
70
+ return { block: true, reason: `Blocked init_experiment: ${dirty.length} uncommitted change(s) (${dirty.slice(0, 3).join(", ")}${dirty.length > 3 ? ", …" : ""}) `
71
+ + "would be erased by the first discarded experiment. Commit or stash them first, then start the loop." };
72
+ }
73
+ }
74
+ return undefined;
75
+ }
@@ -46,9 +46,24 @@ export function resolveLocalStatePath(projectRoot, target, options = {}) {
46
46
  return path.join(canonicalRoot, ...segments);
47
47
  }
48
48
 
49
+ // Runtime state is local evidence, never source. A project that never ran
50
+ // setup has no `.pi/.gitignore`, so `git status` listed the state and
51
+ // `git add -A` swept it into commits. The state root ignores itself instead.
52
+ const STATE_ROOT_IGNORE = "# Piagent runtime state: local only, never committed.\n*\n";
53
+ export function ensureStateRootIgnored(projectRoot) {
54
+ try {
55
+ const root = resolveLocalStatePath(projectRoot, path.join(projectRoot, ".pi", "piagent-state"), { label: "Piagent state root" });
56
+ fs.mkdirSync(root, { recursive: true, mode: 0o700 });
57
+ fs.writeFileSync(path.join(root, ".gitignore"), STATE_ROOT_IGNORE, { flag: "wx", mode: 0o600 });
58
+ } catch {
59
+ // Already present, or the project refuses state (symlinked or read-only); either way nothing to add.
60
+ }
61
+ }
62
+
49
63
  export function ensurePrivateStateDirectory(projectRoot, directory, label = "Local state directory") {
50
64
  const target = resolveLocalStatePath(projectRoot, directory, { label });
51
65
  fs.mkdirSync(target, { recursive: true, mode: 0o700 });
66
+ if (path.relative(path.join(fs.realpathSync.native(path.resolve(projectRoot)), ".pi", "piagent-state"), target).split(path.sep)[0] !== "..") ensureStateRootIgnored(projectRoot);
52
67
  const verified = resolveLocalStatePath(projectRoot, directory, { label, kind: "directory" });
53
68
  try {
54
69
  fs.chmodSync(verified, 0o700);