@piagent/platform 1.5.5 → 1.6.1

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 (323) hide show
  1. package/CHANGELOG.md +166 -0
  2. package/README.md +25 -21
  3. package/README.vi.md +34 -5
  4. package/adapters/web-frontend/profile.json +2 -4
  5. package/architecture/layers.json +18 -3
  6. package/benchmarks/deep-logic-v1/SPECIALIST_PROTOCOL.vi.md +122 -0
  7. package/benchmarks/deep-logic-v1/grade.mjs +272 -10
  8. package/benchmarks/deep-logic-v1/project/apps/admin/src/billing-summary.js +3 -0
  9. package/benchmarks/deep-logic-v1/project/benchmark-contract/public-smoke.test.js +166 -0
  10. package/benchmarks/deep-logic-v1/project/package.json +1 -1
  11. package/benchmarks/deep-logic-v1/project/packages/billing/src/close-period.js +3 -0
  12. package/benchmarks/deep-logic-v1/project/packages/billing/src/plan-timeline.js +3 -0
  13. package/benchmarks/deep-logic-v1/project/test/smoke.test.js +7 -1
  14. package/benchmarks/deep-logic-v1/prompts/budgeted-context-graph.md +2 -0
  15. package/benchmarks/deep-logic-v1/prompts/fair-dependency-scheduler.md +2 -0
  16. package/benchmarks/deep-logic-v1/prompts/layered-policy-resolution.md +2 -0
  17. package/benchmarks/deep-logic-v1/prompts/resumable-stream-assembly.md +3 -1
  18. package/benchmarks/deep-logic-v1/prompts/revision-event-reconciliation.md +2 -0
  19. package/benchmarks/deep-logic-v1/prompts/temporal-usage-billing-close.md +123 -0
  20. package/benchmarks/deep-logic-v1/prompts/transactional-config-merge.md +2 -0
  21. package/benchmarks/deep-logic-v1/suite.json +51 -3
  22. package/benchmarks/deep-logic-v1/variant.mjs +22 -1
  23. package/benchmarks/production-v1/spend-control.v1.json +92 -0
  24. package/benchmarks/production-v1/suite.json +46 -3
  25. package/catalog/capabilities.json +18 -18
  26. package/docs/authority-manifest.md +1 -1
  27. package/docs/auto-delegation-policy.md +38 -73
  28. package/docs/command-reference-vietnamese.md +27 -35
  29. package/docs/context-engine.md +12 -4
  30. package/docs/context-window-policy.md +37 -1
  31. package/docs/distribution-standard.md +7 -7
  32. package/docs/en/architecture.md +27 -13
  33. package/docs/languages.json +4 -4
  34. package/docs/model-options.md +8 -5
  35. package/docs/operator-manual-vietnamese.md +27 -45
  36. package/docs/project-adapters.md +2 -2
  37. package/docs/publishing-for-teams.md +10 -0
  38. package/docs/quality-benchmark.md +427 -62
  39. package/docs/release-install-policy.md +10 -9
  40. package/docs/runtime-harness-standard.md +3 -3
  41. package/docs/runtime-policy-design.md +4 -4
  42. package/docs/runtime-quality-baseline.md +13 -6
  43. package/docs/security-threat-model.md +2 -2
  44. package/docs/subagent-orchestration-capabilities.md +19 -51
  45. package/docs/subagents-and-multiagent.md +21 -47
  46. package/docs/task-implementation-contract.md +3 -3
  47. package/docs/task-lifecycle-vietnamese.md +3 -3
  48. package/docs/team-onboarding.md +2 -2
  49. package/docs/usage-observability.md +7 -2
  50. package/docs/vi/architecture.md +27 -13
  51. package/docs-site/architecture.html +1 -1
  52. package/docs-site/benchmark.html +89 -95
  53. package/docs-site/commands.html +1 -1
  54. package/docs-site/content/benchmark.html +88 -94
  55. package/docs-site/content/en/benchmark.html +134 -90
  56. package/docs-site/content/en/index.html +19 -19
  57. package/docs-site/content/en/runtime.html +4 -4
  58. package/docs-site/content/en/whats-new.html +12 -1
  59. package/docs-site/content/en/workflows.html +2 -2
  60. package/docs-site/content/index.html +19 -19
  61. package/docs-site/content/runtime.html +4 -4
  62. package/docs-site/content/whats-new.html +12 -1
  63. package/docs-site/content/workflows.html +2 -2
  64. package/docs-site/context-engine.html +1 -1
  65. package/docs-site/en/architecture.html +1 -1
  66. package/docs-site/en/benchmark.html +135 -91
  67. package/docs-site/en/commands.html +1 -1
  68. package/docs-site/en/context-engine.html +1 -1
  69. package/docs-site/en/index.html +20 -20
  70. package/docs-site/en/mcp-approval.html +1 -1
  71. package/docs-site/en/mcp-auth.html +1 -1
  72. package/docs-site/en/mcp-servers.html +1 -1
  73. package/docs-site/en/mcp.html +1 -1
  74. package/docs-site/en/permissions.html +1 -1
  75. package/docs-site/en/profiles.html +1 -1
  76. package/docs-site/en/quickstart.html +1 -1
  77. package/docs-site/en/runtime.html +5 -5
  78. package/docs-site/en/scope.html +1 -1
  79. package/docs-site/en/security.html +1 -1
  80. package/docs-site/en/team.html +1 -1
  81. package/docs-site/en/whats-new.html +13 -2
  82. package/docs-site/en/workflows.html +3 -3
  83. package/docs-site/index.html +20 -20
  84. package/docs-site/mcp-approval.html +1 -1
  85. package/docs-site/mcp-auth.html +1 -1
  86. package/docs-site/mcp-servers.html +1 -1
  87. package/docs-site/mcp.html +1 -1
  88. package/docs-site/permissions.html +1 -1
  89. package/docs-site/profiles.html +1 -1
  90. package/docs-site/quickstart.html +1 -1
  91. package/docs-site/runtime.html +5 -5
  92. package/docs-site/scope.html +1 -1
  93. package/docs-site/security.html +1 -1
  94. package/docs-site/team.html +1 -1
  95. package/docs-site/whats-new.html +13 -2
  96. package/docs-site/workflows.html +3 -3
  97. package/evals/fixtures/benchmark-assurance-evidence.invalid.json +1 -1
  98. package/evals/fixtures/benchmark-assurance-evidence.valid.json +1 -1
  99. package/evals/fixtures/codex-relative-efficiency-v1.invalid.json +4 -0
  100. package/evals/fixtures/codex-relative-efficiency-v1.valid.json +94 -0
  101. package/evals/fixtures/helper-request.invalid.json +1 -1
  102. package/evals/fixtures/helper-request.valid.json +1 -1
  103. package/evals/fixtures/piagent-webui/session-live-state-v1.invalid.json +18 -0
  104. package/evals/fixtures/piagent-webui/session-live-state-v1.valid.json +27 -0
  105. package/evals/fixtures/piagent-webui/subagent-tree-v1.valid.json +7 -0
  106. package/evals/fixtures/task-authority-snapshot.valid.json +4 -4
  107. package/evals/fs4-readiness-matrix.v1.json +2 -2
  108. package/evals/fs5-causal-arm.v1.json +3 -3
  109. package/evals/fs5-pilot-protocol.v1.json +3 -3
  110. package/evals/fs5-pilot-protocol.v2.json +8 -8
  111. package/evals/fs5-pilot-protocol.v3.json +8 -8
  112. package/evals/fs5-pilot-protocol.v4.json +7 -6
  113. package/evals/fs5-pilot-protocol.v5.json +9 -7
  114. package/evals/private-holdout-v1/public-exposure.v1.json +1 -1
  115. package/evals/runtime-conformance-v1/README.md +43 -0
  116. package/evals/runtime-conformance-v1/evaluate-paid-canary.mjs +198 -0
  117. package/evals/runtime-conformance-v1/lane.json +57 -0
  118. package/evals/runtime-conformance-v1/paid-canary.json +31 -0
  119. package/evals/runtime-conformance-v1/runner.mjs +456 -0
  120. package/package.json +3 -1
  121. package/packages/piagent-core/README.md +13 -4
  122. package/packages/piagent-core/benchmark/benchmark-assurance.js +4 -1
  123. package/packages/piagent-core/benchmark/benchmark-bootstrap.js +91 -9
  124. package/packages/piagent-core/benchmark/benchmark-claim-restrictions.js +38 -7
  125. package/packages/piagent-core/benchmark/benchmark-cli.js +7 -7
  126. package/packages/piagent-core/benchmark/benchmark-codex-relative-efficiency.js +698 -0
  127. package/packages/piagent-core/benchmark/benchmark-codex.js +3 -1
  128. package/packages/piagent-core/benchmark/benchmark-comparison.js +271 -2
  129. package/packages/piagent-core/benchmark/benchmark-core.js +736 -664
  130. package/packages/piagent-core/benchmark/benchmark-execution-guard.js +7 -5
  131. package/packages/piagent-core/benchmark/benchmark-forensics.js +441 -4
  132. package/packages/piagent-core/benchmark/benchmark-host-readiness.js +639 -0
  133. package/packages/piagent-core/benchmark/benchmark-matrix.js +22 -4
  134. package/packages/piagent-core/benchmark/benchmark-normalized-cost.js +317 -0
  135. package/packages/piagent-core/benchmark/benchmark-preflight.js +5 -1
  136. package/packages/piagent-core/benchmark/benchmark-process.js +6 -5
  137. package/packages/piagent-core/benchmark/benchmark-provider-free-evidence.js +345 -0
  138. package/packages/piagent-core/benchmark/benchmark-provider-wire.js +126 -0
  139. package/packages/piagent-core/benchmark/benchmark-record-validation.js +252 -0
  140. package/packages/piagent-core/benchmark/benchmark-report.js +130 -12
  141. package/packages/piagent-core/benchmark/benchmark-resume-recovery.js +14 -0
  142. package/packages/piagent-core/benchmark/benchmark-runner-policy.js +26 -0
  143. package/packages/piagent-core/benchmark/benchmark-runtime-causal.js +244 -0
  144. package/packages/piagent-core/benchmark/benchmark-stage-diagnostic.js +979 -0
  145. package/packages/piagent-core/benchmark/benchmark-statistics.js +64 -0
  146. package/packages/piagent-core/benchmark/benchmark-stop-policy.js +8 -5
  147. package/packages/piagent-core/benchmark/benchmark-suite-identity.js +31 -0
  148. package/packages/piagent-core/benchmark/benchmark-suite-runtime.js +13 -9
  149. package/packages/piagent-core/benchmark/benchmark-suite.js +149 -2
  150. package/packages/piagent-core/benchmark/benchmark-summary-support.js +380 -0
  151. package/packages/piagent-core/benchmark/benchmark-timing-diagnostics.js +971 -0
  152. package/packages/piagent-core/benchmark/benchmark-usage.js +322 -0
  153. package/packages/piagent-core/benchmark/benchmark-workflow.js +166 -0
  154. package/packages/piagent-core/capabilities/runtime-integrity.js +3 -0
  155. package/packages/piagent-core/docs/context-efficiency-improvement-plan.md +1080 -0
  156. package/packages/piagent-core/extensions/acceptance-behavior-proof.js +806 -0
  157. package/packages/piagent-core/extensions/acceptance-contract-semantics.js +83 -69
  158. package/packages/piagent-core/extensions/acceptance-error-classes.js +160 -0
  159. package/packages/piagent-core/extensions/acceptance-executable-evidence.js +12 -9
  160. package/packages/piagent-core/extensions/acceptance-receipt.js +123 -59
  161. package/packages/piagent-core/extensions/acceptance-state-machine-evidence.js +518 -0
  162. package/packages/piagent-core/extensions/acceptance-test-binding-evidence.js +60 -0
  163. package/packages/piagent-core/extensions/context-efficiency-metrics.js +302 -0
  164. package/packages/piagent-core/extensions/context-efficiency-report.js +167 -0
  165. package/packages/piagent-core/extensions/context-engine.js +149 -156
  166. package/packages/piagent-core/extensions/context-evidence.js +48 -0
  167. package/packages/piagent-core/extensions/context-import-links.js +296 -0
  168. package/packages/piagent-core/extensions/context-index-policy.js +4 -0
  169. package/packages/piagent-core/extensions/context-query-paths.js +57 -0
  170. package/packages/piagent-core/extensions/context-telemetry-integrity.js +65 -0
  171. package/packages/piagent-core/extensions/criterion-context-pack.js +435 -7
  172. package/packages/piagent-core/extensions/criterion-graph.js +82 -9
  173. package/packages/piagent-core/extensions/fallback-base-policy.ts +101 -0
  174. package/packages/piagent-core/extensions/guard-types.ts +6 -0
  175. package/packages/piagent-core/extensions/javascript-regex-evidence.js +32 -0
  176. package/packages/piagent-core/extensions/piagent-guard.ts +420 -260
  177. package/packages/piagent-core/extensions/task-contract-view.js +17 -3
  178. package/packages/piagent-core/extensions/task-lifecycle.js +39 -2
  179. package/packages/piagent-core/extensions/task-state.js +109 -142
  180. package/packages/piagent-core/extensions/verification-intelligence.js +52 -13
  181. package/packages/piagent-core/extensions/workspace-evidence-roots.js +193 -0
  182. package/packages/piagent-core/package.json +1 -1
  183. package/packages/piagent-core/policies/base-policy.json +44 -2
  184. package/packages/piagent-core/policy/authority-manifest.v1.json +3 -3
  185. package/packages/piagent-core/prompts/be-to-fe.md +2 -8
  186. package/packages/piagent-core/prompts/plan.md +1 -1
  187. package/packages/piagent-core/prompts/platform-improve.md +2 -6
  188. package/packages/piagent-core/prompts/review.md +2 -7
  189. package/packages/piagent-core/prompts/scout.md +1 -1
  190. package/packages/piagent-core/prompts/task.md +4 -3
  191. package/packages/piagent-core/runtime/context/context-delivery.ts +103 -0
  192. package/packages/piagent-core/runtime/context/context-delta-shadow.ts +53 -0
  193. package/packages/piagent-core/runtime/context/context-efficiency-format.ts +47 -0
  194. package/packages/piagent-core/runtime/context/context-evidence-qualification.ts +32 -0
  195. package/packages/piagent-core/runtime/context/prefix-telemetry.ts +47 -0
  196. package/packages/piagent-core/runtime/context/repository-memory-hints.ts +27 -0
  197. package/packages/piagent-core/runtime/hooks/agent-prompt-telemetry.ts +56 -0
  198. package/packages/piagent-core/runtime/hooks/agent-start-hook.ts +162 -102
  199. package/packages/piagent-core/runtime/hooks/completion-hook.ts +12 -12
  200. package/packages/piagent-core/runtime/hooks/input-hook.ts +17 -1
  201. package/packages/piagent-core/runtime/hooks/session-hooks.ts +22 -2
  202. package/packages/piagent-core/runtime/hooks/session-start-hook.ts +107 -3
  203. package/packages/piagent-core/runtime/hooks/tool-result-content-guards.ts +95 -0
  204. package/packages/piagent-core/runtime/hooks/tool-result-hook.ts +134 -166
  205. package/packages/piagent-core/runtime/hooks/tool-result-value-helpers.ts +66 -0
  206. package/packages/piagent-core/runtime/inspection/activity-event-adapter.ts +4 -2
  207. package/packages/piagent-core/runtime/inspection/activity-recovery.ts +104 -0
  208. package/packages/piagent-core/runtime/inspection/bounded-emission-guard.ts +286 -0
  209. package/packages/piagent-core/runtime/inspection/runtime-event-store.ts +37 -7
  210. package/packages/piagent-core/runtime/inspection/task-compaction-history.ts +1 -1
  211. package/packages/piagent-core/runtime/inspection/task-handoff-history.ts +1 -1
  212. package/packages/piagent-core/runtime/inspection/task-subagent-tree.ts +27 -4
  213. package/packages/piagent-core/runtime/inspection/tool-failure-classification.ts +70 -0
  214. package/packages/piagent-core/runtime/inspection/webui-snapshot.ts +73 -9
  215. package/packages/piagent-core/runtime/model/authenticated-catalog.ts +17 -9
  216. package/packages/piagent-core/runtime/model/openai-codex-reasoning.ts +83 -0
  217. package/packages/piagent-core/runtime/model/provider-wire-fingerprint.ts +238 -0
  218. package/packages/piagent-core/runtime/orchestration/helper-lifecycle.ts +16 -12
  219. package/packages/piagent-core/runtime/orchestration/minimal-delegation-policy.ts +71 -0
  220. package/packages/piagent-core/runtime/orchestration/owned-work-budget.ts +28 -20
  221. package/packages/piagent-core/runtime/orchestration/role-policy.ts +27 -9
  222. package/packages/piagent-core/runtime/orchestration/subagent-tool-policy.ts +329 -0
  223. package/packages/piagent-core/runtime/policy/block-remedy.ts +0 -4
  224. package/packages/piagent-core/runtime/product/activity-inspector.ts +7 -2
  225. package/packages/piagent-core/runtime/product/efficiency-metrics.ts +7 -2
  226. package/packages/piagent-core/runtime/quality/edit-freshness-guard.ts +102 -0
  227. package/packages/piagent-core/runtime/quality/exact-output-contract.ts +22 -11
  228. package/packages/piagent-core/runtime/quality/performance-assurance-signals.ts +23 -0
  229. package/packages/piagent-core/runtime/quality/performance-assurance.ts +9 -5
  230. package/packages/piagent-core/runtime/recovery/continuation-budget.ts +1 -1
  231. package/packages/piagent-core/runtime/recovery/edit-recovery-context.ts +113 -0
  232. package/packages/piagent-core/runtime/recovery/edit-recovery-delivery.ts +42 -0
  233. package/packages/piagent-core/runtime/recovery/handoff-projection.ts +4 -1
  234. package/packages/piagent-core/runtime/recovery/pristine-task-policy-refresh.ts +91 -0
  235. package/packages/piagent-core/runtime/recovery/recovery-policy.ts +7 -4
  236. package/packages/piagent-core/runtime/recovery/resume-state.ts +112 -14
  237. package/packages/piagent-core/runtime/recovery/semantic-repair-handshake.ts +60 -13
  238. package/packages/piagent-core/runtime/recovery/semantic-repair-runtime.ts +55 -2
  239. package/packages/piagent-core/runtime/recovery/task-evidence-coverage-refresh.ts +217 -0
  240. package/packages/piagent-core/runtime/registration/context-commands.ts +82 -7
  241. package/packages/piagent-core/runtime/registration/knowledge-tools.ts +9 -5
  242. package/packages/piagent-core/runtime/registration/operator-request-intake.ts +49 -0
  243. package/packages/piagent-core/runtime/registration/policy-tools.ts +50 -15
  244. package/packages/piagent-core/runtime/registration/session-commands.ts +1 -1
  245. package/packages/piagent-core/runtime/registration/task-completion-tools.ts +61 -25
  246. package/packages/piagent-core/runtime/registration/task-evidence-tools.ts +21 -12
  247. package/packages/piagent-core/runtime/registration/task-start-guidance.ts +169 -0
  248. package/packages/piagent-core/runtime/registration/task-start-manifest.ts +54 -0
  249. package/packages/piagent-core/runtime/registration/task-start-retry-helpers.ts +37 -0
  250. package/packages/piagent-core/runtime/registration/task-start-tool.ts +108 -103
  251. package/packages/piagent-core/runtime/runtime-limits.ts +16 -2
  252. package/packages/piagent-core/runtime/session/adaptive-context-analysis.ts +461 -0
  253. package/packages/piagent-core/runtime/session/adaptive-context-governor.ts +464 -0
  254. package/packages/piagent-core/runtime/session/adaptive-context-ledger.ts +265 -0
  255. package/packages/piagent-core/runtime/session/message-signals.ts +7 -3
  256. package/packages/piagent-core/runtime/session/operator-request-carry.ts +44 -0
  257. package/packages/piagent-core/runtime/session/runtime-state.ts +161 -5
  258. package/packages/piagent-core/runtime/session/source-checkout-read-grants.ts +35 -0
  259. package/packages/piagent-core/runtime/session/system-prompt.ts +76 -14
  260. package/packages/piagent-core/runtime/session/task-contract-presentation.ts +39 -0
  261. package/packages/piagent-core/runtime/tools/apply-patch-tool.ts +500 -0
  262. package/packages/piagent-core/runtime/tools/phase-tools.ts +8 -8
  263. package/packages/piagent-core/runtime/tools/tool-groups.ts +12 -2
  264. package/packages/piagent-core/runtime/trajectory/trajectory-runtime.ts +2 -1
  265. package/packages/piagent-core/runtime/verification/exact-verifier-reuse.ts +101 -0
  266. package/packages/piagent-core/runtime/workflows/runtime-intake-compaction.ts +164 -0
  267. package/packages/piagent-core/runtime/workflows/task-intake.ts +207 -38
  268. package/packages/piagent-core/security/sensitive-data.js +13 -218
  269. package/packages/piagent-core/security/sensitive-project-file.js +42 -0
  270. package/packages/piagent-core/security/sensitive-source-expression.js +330 -0
  271. package/packages/piagent-core/security/sensitive-source-formats.js +394 -0
  272. package/packages/piagent-core/security/sensitive-text.js +234 -0
  273. package/packages/piagent-core/subagents/piagent-oracle.md +5 -3
  274. package/packages/piagent-core/subagents/piagent-planner.md +6 -4
  275. package/packages/piagent-core/subagents/piagent-reviewer.md +5 -3
  276. package/packages/piagent-core/subagents/piagent-scout.md +4 -2
  277. package/packages/piagent-core/subagents/piagent-worker.md +7 -5
  278. package/packages/piagent-webui/dist/client/assets/{MarkdownMessage-rD9WJKxs.js → MarkdownMessage-B4XehTCU.js} +1 -1
  279. package/packages/piagent-webui/dist/client/assets/index-CgOEyRPG.js +176 -0
  280. package/packages/piagent-webui/dist/client/index.html +1 -1
  281. package/packages/piagent-webui/extension/piagent-webui.ts +3 -1
  282. package/packages/piagent-webui/extension/same-session-bridge.ts +1 -1
  283. package/packages/piagent-webui/extension/session-stream-adapter.ts +33 -10
  284. package/packages/piagent-webui/gateway/gateway-events.ts +109 -5
  285. package/packages/piagent-webui/gateway/gateway-service.ts +3 -0
  286. package/packages/piagent-webui/gateway/gateway-session-stream.ts +122 -20
  287. package/packages/piagent-webui/gateway/session-command-controller.ts +18 -3
  288. package/packages/piagent-webui/gateway/session-effective-options.ts +47 -0
  289. package/packages/piagent-webui/gateway/session-live-state.ts +21 -0
  290. package/packages/piagent-webui/gateway/session-operation-lifecycle.ts +237 -0
  291. package/packages/piagent-webui/gateway/session-operation-retry-control.ts +38 -0
  292. package/packages/piagent-webui/gateway/session-operation-start.ts +5 -1
  293. package/packages/piagent-webui/gateway/session-operation-watchdog.ts +165 -0
  294. package/packages/piagent-webui/gateway/session-runtime-factory.ts +45 -0
  295. package/packages/piagent-webui/gateway/session-runtime-supervisor.ts +141 -125
  296. package/packages/piagent-webui/ownership/session-lease-store.ts +5 -2
  297. package/packages/piagent-webui/server/core-inspection-provider.ts +2 -1
  298. package/packages/piagent-webui/server/loopback-server.ts +8 -0
  299. package/packages/piagent-webui/server/transcript-projection.ts +113 -9
  300. package/packages/piagent-webui/shared/text-visibility.ts +10 -0
  301. package/schemas/codex-relative-efficiency-v1.schema.json +155 -0
  302. package/schemas/piagent-webui/catalog-v1.json +9 -0
  303. package/schemas/piagent-webui/gateway-protocol-v1.schema.json +53 -3
  304. package/schemas/piagent-webui/runtime-event-v2.schema.json +15 -5
  305. package/schemas/piagent-webui/session-live-state-v1.schema.json +76 -0
  306. package/schemas/piagent-webui/subagent-tree-v1.schema.json +11 -1
  307. package/schemas/project-profile.schema.json +1 -1
  308. package/schemas/task-contract.schema.json +27 -1
  309. package/scripts/benchmark-runner-core.mjs +367 -363
  310. package/scripts/benchmark-runner-finalization.mjs +313 -0
  311. package/scripts/benchmark-runner-host-readiness.mjs +94 -0
  312. package/scripts/benchmark-runner-support.mjs +200 -0
  313. package/scripts/benchmark-session.mjs +95 -41
  314. package/scripts/configure-model-scope.sh +4 -3
  315. package/scripts/configure-subagents.sh +42 -34
  316. package/scripts/helper-evaluation.mjs +2 -2
  317. package/scripts/install-global.sh +2 -2
  318. package/scripts/pi-usage-history.mjs +37 -10
  319. package/scripts/setup.sh +2 -2
  320. package/scripts/team-doctor.sh +1 -1
  321. package/scripts/verify-local.sh +10 -1
  322. package/templates/global/settings.json +2 -1
  323. package/packages/piagent-webui/dist/client/assets/index-BZRFw1u6.js +0 -174
@@ -1,11 +1,13 @@
1
1
  import { createHash } from "node:crypto";
2
2
 
3
3
  import { redactSensitiveText } from "../../piagent-core/extensions/redaction-core.js";
4
+ import { hasVisibleText } from "../shared/text-visibility.ts";
4
5
 
5
6
  const MAX_ENTRIES = 50_000;
6
7
  const MAX_ITEMS = 200;
7
8
  const MAX_TEXT = 16_384;
8
- const ANSI = /\u001b(?:[@-_]|\[[0-?]*[ -/]*[@-~])/g;
9
+ const ANSI = /\u001b(?:\[[0-?]*[ -/]*[@-~]|[@-_])/g;
10
+ const COMPLETION_GATE = /^\[Piagent completion gate: (CONTINUING|NOT APPROVED)\]/i;
9
11
 
10
12
  type TranscriptIdentity = { projectRef: string; runtimeInstanceId: string; sessionRef: string; taskId: string | null; taskRunId: string | null;
11
13
  agentOperationId: null; toolCallId: null };
@@ -30,6 +32,7 @@ export type TranscriptProjectionInput = {
30
32
  beforeCursor?: string | null;
31
33
  limit?: number;
32
34
  generatedAt?: string;
35
+ taskOutcome?: string | null;
33
36
  };
34
37
 
35
38
  function hash(value: string): string { return createHash("sha256").update(value).digest("hex"); }
@@ -87,6 +90,21 @@ function assistantFailureReason(message: any): string | null {
87
90
  if (/(?:network|fetch failed|econn|timed? ?out|unavailable)/.test(detail)) return "provider-unavailable";
88
91
  return "provider-response-failed";
89
92
  }
93
+ function assistantUnavailableReason(message: any, text: string, projectedToolCalls: TranscriptItem["toolCalls"]): string | null {
94
+ if (message?.role !== "assistant") return null;
95
+ const stopReason = String(message?.stopReason ?? "");
96
+ if (stopReason === "error") return assistantFailureReason(message) ?? "provider-response-failed";
97
+ if (stopReason === "aborted") return "assistant-message-aborted";
98
+ if (stopReason === "length") return "assistant-output-incomplete";
99
+ const gate = COMPLETION_GATE.exec(text.trimStart());
100
+ if (gate) return gate[1]?.toUpperCase() === "CONTINUING"
101
+ ? "assistant-completion-continuing" : "assistant-completion-not-approved";
102
+ if (projectedToolCalls.length > 0 || ["toolUse", "pending", "deferred"].includes(stopReason)) return "assistant-intermediate-output";
103
+ if (!stopReason) return "assistant-settlement-unknown";
104
+ if (stopReason && stopReason !== "stop") return "assistant-settlement-unknown";
105
+ if (!hasVisibleText(text)) return "assistant-message-empty";
106
+ return null;
107
+ }
90
108
  function safeText(value: string): { full: string; preview: string; redacted: boolean; truncated: boolean } {
91
109
  const clean = value.replace(ANSI, "").replace(/[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f]/g, " ");
92
110
  const redaction = redactSensitiveText(clean);
@@ -129,18 +147,102 @@ function item(entry: any, identity: TranscriptIdentity): TranscriptItem | null {
129
147
  const itemRole = role(entry.message), recordedAt = timestamp(entry.timestamp ?? entry.message.timestamp);
130
148
  if (!itemRole || !recordedAt || typeof entry.id !== "string" || entry.id.length === 0) return null;
131
149
  const userProjection = userMessageProjection(entry.message);
150
+ const projectedToolCalls = toolCalls(entry.message, identity.sessionRef, itemRole);
132
151
  const content = itemRole === "tool-result" ? unavailableContent("tool-output-in-activity-preview") : (() => {
133
152
  const projected = safeText(itemRole === "user" ? userProjection.text : messageText(entry.message));
134
- const failureReason = projected.full.length === 0 ? assistantFailureReason(entry.message) : null;
135
- if (failureReason) return unavailableContent(failureReason);
153
+ const unavailableReason = assistantUnavailableReason(entry.message, projected.full, projectedToolCalls);
154
+ if (unavailableReason) return unavailableContent(unavailableReason);
136
155
  return { state: projected.redacted ? "redacted" as const : "available" as const, text: projected.preview,
137
156
  textChars: Math.min(1_000_000_000, projected.full.length), digest: `sha256:${hash(projected.full)}`, truncated: projected.truncated,
138
157
  redacted: projected.redacted, imageCount: imageCount(entry.message), reasonCode: projected.redacted ? "sensitive-values-redacted" as const : null };
139
158
  })();
140
159
  return { messageRef: opaque("message", [identity.sessionRef, entry.id]), parentMessageRef: null, role: itemRole, recordedAt,
141
160
  agentOperationId: null, turnIndex: null, content, ...(userProjection.attachments.length ? { attachments: userProjection.attachments } : {}),
142
- toolCalls: toolCalls(entry.message, identity.sessionRef, itemRole) };
161
+ toolCalls: projectedToolCalls };
162
+ }
163
+
164
+ type ProjectedTranscriptItem = { entry: any; item: TranscriptItem; cursor: string };
165
+
166
+ function linkTranscriptTurns(values: ProjectedTranscriptItem[]): ProjectedTranscriptItem[] {
167
+ let userMessageRef: string | null = null;
168
+ const toolCallOwners = new Map<string, string>();
169
+ return values.map((value) => {
170
+ let parentMessageRef: string | null = null;
171
+ if (value.item.role === "user") userMessageRef = value.item.messageRef;
172
+ else if (value.item.role === "tool-result") {
173
+ parentMessageRef = toolCallOwners.get(value.item.toolCalls[0]?.toolCallRef ?? "") ?? userMessageRef;
174
+ } else parentMessageRef = userMessageRef;
175
+ const linked = { ...value, item: { ...value.item, parentMessageRef } };
176
+ if (linked.item.role === "assistant") {
177
+ for (const toolCall of linked.item.toolCalls) toolCallOwners.set(toolCall.toolCallRef, linked.item.messageRef);
178
+ }
179
+ return linked;
180
+ });
181
+ }
182
+
183
+ function suppressOpenTaskHandoff(values: ProjectedTranscriptItem[], taskOutcome: string | null | undefined): ProjectedTranscriptItem[] {
184
+ if (taskOutcome !== "pending") return values;
185
+ let latestUser = -1;
186
+ for (let index = values.length - 1; index >= 0; index -= 1) {
187
+ if (values[index]?.item.role === "user") { latestUser = index; break; }
188
+ }
189
+ if (latestUser < 0) return values;
190
+ return values.map((value, index) => {
191
+ if (index <= latestUser || value.item.role !== "assistant" || value.item.toolCalls.length > 0
192
+ || !["available", "redacted"].includes(value.item.content.state)) return value;
193
+ return { ...value, item: { ...value.item, content: unavailableContent("assistant-task-pending") } };
194
+ });
195
+ }
196
+
197
+ function durableAssistant(item: TranscriptItem): boolean {
198
+ return item.role === "assistant" && item.toolCalls.length === 0
199
+ && (item.content.state === "available" || item.content.state === "redacted")
200
+ && hasVisibleText(item.content.text ?? "");
201
+ }
202
+
203
+ function compactOversizedTurn(
204
+ values: ProjectedTranscriptItem[], start: number, end: number, limit: number
205
+ ): ProjectedTranscriptItem[] {
206
+ if (limit === 1) return [values[start]!];
207
+ const selected = new Set<number>([start]);
208
+ for (let index = end - 1; index > start; index -= 1) {
209
+ if (durableAssistant(values[index]!.item)) { selected.add(index); break; }
210
+ }
211
+ for (let index = end - 1; index > start && selected.size < limit; index -= 1) selected.add(index);
212
+ return [...selected].sort((left, right) => left - right).map((index) => values[index]!);
213
+ }
214
+
215
+ function boundedTurnPage(
216
+ values: ProjectedTranscriptItem[], end: number, limit: number
217
+ ): { selected: ProjectedTranscriptItem[]; start: number; compacted: boolean } {
218
+ if (end <= 0) return { selected: [], start: 0, compacted: false };
219
+ const users: number[] = [];
220
+ for (let index = 0; index < end; index += 1) if (values[index]?.item.role === "user") users.push(index);
221
+ if (users.length === 0) {
222
+ const start = Math.max(0, end - limit);
223
+ return { selected: values.slice(start, end), start, compacted: false };
224
+ }
225
+
226
+ const selected: ProjectedTranscriptItem[] = [];
227
+ let remaining = limit, turnEnd = end, start = end;
228
+ for (let userIndex = users.length - 1; userIndex >= 0 && remaining > 0; userIndex -= 1) {
229
+ const turnStart = users[userIndex]!;
230
+ const turnSize = turnEnd - turnStart;
231
+ if (turnSize > remaining) {
232
+ if (selected.length === 0) {
233
+ const compacted = compactOversizedTurn(values, turnStart, turnEnd, remaining);
234
+ return { selected: compacted, start: turnStart, compacted: true };
235
+ }
236
+ break;
237
+ }
238
+ selected.unshift(...values.slice(turnStart, turnEnd));
239
+ start = turnStart;
240
+ remaining -= turnSize;
241
+ turnEnd = turnStart;
242
+ }
243
+ return { selected, start, compacted: false };
143
244
  }
245
+
144
246
  function unavailable(input: TranscriptProjectionInput, reasonCode: string, limit: number): TranscriptDocument {
145
247
  return { schemaVersion: 1, version: "piagent-webui-transcript-v1", generatedAt: input.generatedAt ?? new Date().toISOString(),
146
248
  identity: structuredClone(input.identity), revision: structuredClone(input.revision), eventCursor: input.eventCursor,
@@ -150,17 +252,19 @@ function unavailable(input: TranscriptProjectionInput, reasonCode: string, limit
150
252
  export function projectTranscript(input: TranscriptProjectionInput): TranscriptDocument {
151
253
  const limit = Math.max(1, Math.min(MAX_ITEMS, Number.isInteger(input.limit) ? Number(input.limit) : 50));
152
254
  if (!Array.isArray(input.entries) || input.entries.length > MAX_ENTRIES) return unavailable(input, "transcript-history-unavailable", limit);
153
- const projected = input.entries.map((entry) => ({ entry, item: item(entry, input.identity) })).filter((value): value is { entry: any; item: TranscriptItem } => Boolean(value.item));
154
- const cursors = projected.map(({ entry }) => opaque("transcript", [input.identity.sessionRef, entry.id]));
255
+ const projected = suppressOpenTaskHandoff(linkTranscriptTurns(input.entries.map((entry) => ({ entry, item: item(entry, input.identity),
256
+ cursor: opaque("transcript", [input.identity.sessionRef, (entry as any)?.id]) }))
257
+ .filter((value): value is ProjectedTranscriptItem => Boolean(value.item))), input.taskOutcome);
258
+ const cursors = projected.map((value) => value.cursor);
155
259
  let end = projected.length;
156
260
  if (input.beforeCursor) {
157
261
  const cursorIndex = cursors.indexOf(input.beforeCursor);
158
262
  if (cursorIndex < 0) return unavailable(input, "transcript-cursor-gap", limit);
159
263
  end = cursorIndex;
160
264
  }
161
- const start = Math.max(0, end - limit), selected = projected.slice(start, end).map((value) => value.item), hasOlder = start > 0;
265
+ const page = boundedTurnPage(projected, end, limit), selected = page.selected.map((value) => value.item), hasOlder = page.start > 0;
162
266
  return { schemaVersion: 1, version: "piagent-webui-transcript-v1", generatedAt: input.generatedAt ?? new Date().toISOString(),
163
267
  identity: structuredClone(input.identity), revision: structuredClone(input.revision), eventCursor: input.eventCursor,
164
- state: "ready", items: selected, page: { beforeCursor: input.beforeCursor ?? null, nextBeforeCursor: hasOlder ? cursors[start] : null,
165
- hasOlder, limit, truncated: projected.length !== input.entries.filter((entry: any) => entry?.type === "message").length }, reasonCode: null };
268
+ state: "ready", items: selected, page: { beforeCursor: input.beforeCursor ?? null, nextBeforeCursor: hasOlder ? cursors[page.start] : null,
269
+ hasOlder, limit, truncated: page.compacted || projected.length !== input.entries.filter((entry: any) => entry?.type === "message").length }, reasonCode: null };
166
270
  }
@@ -0,0 +1,10 @@
1
+ // Classification only: callers keep the original Unicode text unchanged.
2
+ // A response needs at least one rendering code point; whitespace, controls and
3
+ // Unicode default-ignorables alone cannot form a visible assistant answer.
4
+ const NON_RENDERING_CODE_POINT = /^(?:\p{White_Space}|\p{Cc}|\p{Default_Ignorable_Code_Point})$/u;
5
+ const ANSI_ESCAPE = /\u001b(?:\[[0-?]*[ -/]*[@-~]|[@-_])/g;
6
+
7
+ export function hasVisibleText(value: string): boolean {
8
+ for (const codePoint of value.replace(ANSI_ESCAPE, "")) if (!NON_RENDERING_CODE_POINT.test(codePoint)) return true;
9
+ return false;
10
+ }
@@ -0,0 +1,155 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://github.com/Vt-mmm/piagent/schemas/codex-relative-efficiency-v1.schema.json",
4
+ "title": "Piagent Codex-relative efficiency evidence v1",
5
+ "type": "object",
6
+ "additionalProperties": false,
7
+ "required": ["schemaVersion", "policy", "required", "claim", "billedOrSubscriptionCost", "costBoundary", "checks", "failures", "passed", "families", "totalTokenTraffic", "apiEquivalentCost", "subagents"],
8
+ "properties": {
9
+ "schemaVersion": { "const": 1 },
10
+ "policy": { "$ref": "#/$defs/policy" },
11
+ "required": { "type": "boolean" },
12
+ "claim": { "type": "string", "minLength": 1 },
13
+ "billedOrSubscriptionCost": { "const": false },
14
+ "costBoundary": { "type": "string", "minLength": 1 },
15
+ "checks": {
16
+ "type": "object",
17
+ "minProperties": 1,
18
+ "additionalProperties": { "type": "boolean" }
19
+ },
20
+ "failures": { "type": "array", "items": { "type": "string", "minLength": 1 }, "uniqueItems": true },
21
+ "passed": { "type": "boolean" },
22
+ "families": { "type": "array", "minItems": 1, "items": { "$ref": "#/$defs/family" } },
23
+ "totalTokenTraffic": { "$ref": "#/$defs/aggregateTokens" },
24
+ "apiEquivalentCost": { "$ref": "#/$defs/aggregateCost" },
25
+ "subagents": { "$ref": "#/$defs/subagents" }
26
+ },
27
+ "$defs": {
28
+ "nullableNonNegativeNumber": { "type": ["number", "null"], "minimum": 0 },
29
+ "nullablePositiveNumber": { "type": ["number", "null"], "exclusiveMinimum": 0 },
30
+ "confidence": {
31
+ "type": ["object", "null"],
32
+ "additionalProperties": false,
33
+ "required": ["lower", "upper", "sampleUnit", "scenarioCount"],
34
+ "properties": {
35
+ "lower": { "type": "number", "exclusiveMinimum": 0 },
36
+ "upper": { "type": "number", "exclusiveMinimum": 0 },
37
+ "sampleUnit": { "const": "scenario-family" },
38
+ "scenarioCount": { "type": "integer", "minimum": 2 }
39
+ }
40
+ },
41
+ "policy": {
42
+ "type": "object",
43
+ "additionalProperties": false,
44
+ "required": ["schemaVersion", "id", "baselineSurface", "candidateSurface", "estimand", "outcomeConditioning", "attemptPolicy", "maximumTotalTokenTrafficRatio", "maximumTotalTokenTrafficRatioUpper95", "maximumApiEquivalentCostRatio", "maximumApiEquivalentCostRatioUpper95", "maximumSubagentSessionsPerAttempt", "maximumSubagentTrafficShare"],
45
+ "properties": {
46
+ "schemaVersion": { "const": 1 },
47
+ "id": { "const": "codex-relative-efficiency-v1" },
48
+ "baselineSurface": { "const": "codex-cli" },
49
+ "candidateSurface": { "const": "piagent" },
50
+ "estimand": { "const": "fixed-workload-family-geometric-mean" },
51
+ "outcomeConditioning": { "const": "none" },
52
+ "attemptPolicy": { "const": "accepted-plus-exact-provider-started-failed-attempts" },
53
+ "maximumTotalTokenTrafficRatio": { "type": "number", "exclusiveMinimum": 0, "maximum": 0.7 },
54
+ "maximumTotalTokenTrafficRatioUpper95": { "type": "number", "exclusiveMinimum": 0, "maximum": 0.7 },
55
+ "maximumApiEquivalentCostRatio": { "type": "number", "exclusiveMinimum": 0, "maximum": 0.7 },
56
+ "maximumApiEquivalentCostRatioUpper95": { "type": "number", "exclusiveMinimum": 0, "maximum": 0.7 },
57
+ "maximumSubagentSessionsPerAttempt": { "type": "integer", "minimum": 0, "maximum": 1 },
58
+ "maximumSubagentTrafficShare": { "type": "number", "minimum": 0, "maximum": 0.05 }
59
+ }
60
+ },
61
+ "family": {
62
+ "type": "object",
63
+ "additionalProperties": false,
64
+ "required": ["scenarioId", "expectedAttempts", "pairedAttempts", "exact", "issues", "baselineTokenTraffic", "candidateTokenTraffic", "totalTokenTrafficRatio", "baselineApiEquivalentCostUsd", "candidateApiEquivalentCostUsd", "apiEquivalentCostRatio", "candidateSubagentSessions", "candidateSubagentTraffic", "maximumSubagentSessionsPerAttempt", "candidateAttempts", "subagentEvidenceComplete"],
65
+ "properties": {
66
+ "scenarioId": { "type": "string", "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$" },
67
+ "expectedAttempts": { "type": ["integer", "null"], "minimum": 1 },
68
+ "pairedAttempts": { "type": "integer", "minimum": 0 },
69
+ "exact": { "type": "boolean" },
70
+ "issues": { "type": "array", "items": { "type": "string", "minLength": 1 }, "uniqueItems": true },
71
+ "baselineTokenTraffic": { "type": "number", "minimum": 0 },
72
+ "candidateTokenTraffic": { "type": "number", "minimum": 0 },
73
+ "totalTokenTrafficRatio": { "$ref": "#/$defs/nullablePositiveNumber" },
74
+ "baselineApiEquivalentCostUsd": { "type": "number", "minimum": 0 },
75
+ "candidateApiEquivalentCostUsd": { "type": "number", "minimum": 0 },
76
+ "apiEquivalentCostRatio": { "$ref": "#/$defs/nullablePositiveNumber" },
77
+ "candidateSubagentSessions": { "type": "integer", "minimum": 0 },
78
+ "candidateSubagentTraffic": { "type": "integer", "minimum": 0 },
79
+ "maximumSubagentSessionsPerAttempt": { "type": "integer", "minimum": 0 },
80
+ "candidateAttempts": { "type": "integer", "minimum": 0 },
81
+ "subagentEvidenceComplete": { "type": "boolean" }
82
+ }
83
+ },
84
+ "aggregateBase": {
85
+ "type": "object",
86
+ "required": ["complete", "expectedScenarioFamilies", "completeScenarioFamilies", "ratio", "ratioConfidence95", "ratioConfidence95Raw", "aggregateRatio", "deltaPercent"],
87
+ "properties": {
88
+ "complete": { "type": "boolean" },
89
+ "expectedScenarioFamilies": { "type": "integer", "minimum": 1 },
90
+ "completeScenarioFamilies": { "type": "integer", "minimum": 0 },
91
+ "ratio": { "$ref": "#/$defs/nullablePositiveNumber" },
92
+ "ratioConfidence95": { "$ref": "#/$defs/confidence" },
93
+ "ratioConfidence95Raw": { "$ref": "#/$defs/confidence" },
94
+ "aggregateRatio": { "$ref": "#/$defs/nullableNonNegativeNumber" },
95
+ "deltaPercent": { "type": ["number", "null"] }
96
+ }
97
+ },
98
+ "aggregateTokens": {
99
+ "allOf": [
100
+ { "$ref": "#/$defs/aggregateBase" },
101
+ {
102
+ "type": "object",
103
+ "additionalProperties": false,
104
+ "required": ["complete", "expectedScenarioFamilies", "completeScenarioFamilies", "ratio", "ratioConfidence95", "ratioConfidence95Raw", "aggregateBaselineTokens", "aggregateCandidateTokens", "aggregateRatio", "deltaPercent"],
105
+ "properties": {
106
+ "complete": true,
107
+ "expectedScenarioFamilies": true,
108
+ "completeScenarioFamilies": true,
109
+ "ratio": true,
110
+ "ratioConfidence95": true,
111
+ "ratioConfidence95Raw": true,
112
+ "aggregateRatio": true,
113
+ "deltaPercent": true,
114
+ "aggregateBaselineTokens": { "type": "number", "minimum": 0 },
115
+ "aggregateCandidateTokens": { "type": "number", "minimum": 0 }
116
+ }
117
+ }
118
+ ]
119
+ },
120
+ "aggregateCost": {
121
+ "allOf": [
122
+ { "$ref": "#/$defs/aggregateBase" },
123
+ {
124
+ "type": "object",
125
+ "additionalProperties": false,
126
+ "required": ["complete", "expectedScenarioFamilies", "completeScenarioFamilies", "ratio", "ratioConfidence95", "ratioConfidence95Raw", "aggregateBaselineUsd", "aggregateCandidateUsd", "aggregateRatio", "deltaPercent"],
127
+ "properties": {
128
+ "complete": true,
129
+ "expectedScenarioFamilies": true,
130
+ "completeScenarioFamilies": true,
131
+ "ratio": true,
132
+ "ratioConfidence95": true,
133
+ "ratioConfidence95Raw": true,
134
+ "aggregateRatio": true,
135
+ "deltaPercent": true,
136
+ "aggregateBaselineUsd": { "type": "number", "minimum": 0 },
137
+ "aggregateCandidateUsd": { "type": "number", "minimum": 0 }
138
+ }
139
+ }
140
+ ]
141
+ },
142
+ "subagents": {
143
+ "type": "object",
144
+ "additionalProperties": false,
145
+ "required": ["candidateAttempts", "sessions", "tokenTraffic", "trafficShare", "maximumObservedSessionsPerAttempt"],
146
+ "properties": {
147
+ "candidateAttempts": { "type": "integer", "minimum": 0 },
148
+ "sessions": { "type": "integer", "minimum": 0 },
149
+ "tokenTraffic": { "type": "integer", "minimum": 0 },
150
+ "trafficShare": { "$ref": "#/$defs/nullableNonNegativeNumber" },
151
+ "maximumObservedSessionsPerAttempt": { "type": "integer", "minimum": 0 }
152
+ }
153
+ }
154
+ }
155
+ }
@@ -218,6 +218,15 @@
218
218
  "supported": true,
219
219
  "current": true
220
220
  },
221
+ {
222
+ "name": "session-live-state-v1",
223
+ "file": "session-live-state-v1.schema.json",
224
+ "id": "https://piagent.io.vn/schemas/piagent-webui/session-live-state-v1.schema.json",
225
+ "documentVersion": 1,
226
+ "role": "read-model",
227
+ "supported": true,
228
+ "current": true
229
+ },
221
230
  {
222
231
  "name": "session-command-v1",
223
232
  "file": "session-command-v1.schema.json",
@@ -269,7 +269,7 @@
269
269
  "sequence": { "$ref": "#/$defs/stateVersion" },
270
270
  "stateVersion": { "$ref": "#/$defs/stateVersion" },
271
271
  "generatedAt": { "$ref": "common-v1.schema.json#/$defs/timestamp" },
272
- "kind": { "enum": ["catalog.changed", "session.changed", "runtime.changed", "resync.required", "message.delta", "message.completed", "tool.started", "tool.completed"] },
272
+ "kind": { "enum": ["catalog.changed", "session.changed", "runtime.changed", "resync.required", "message.delta", "message.completed", "operation.settled", "tool.started", "tool.completed"] },
273
273
  "payload": { "type": "object" }
274
274
  }
275
275
  },
@@ -411,6 +411,54 @@
411
411
  }
412
412
  ]
413
413
  },
414
+ "operationCompletedPayload": {
415
+ "type": "object",
416
+ "additionalProperties": false,
417
+ "required": ["sessionRef", "operationRef", "messageRef", "sessionRevision", "settlement", "reasonCode"],
418
+ "properties": {
419
+ "sessionRef": { "$ref": "common-v1.schema.json#/$defs/opaqueRef" },
420
+ "operationRef": { "$ref": "common-v1.schema.json#/$defs/opaqueRef" },
421
+ "messageRef": { "$ref": "common-v1.schema.json#/$defs/opaqueRef" },
422
+ "sessionRevision": { "$ref": "common-v1.schema.json#/$defs/revisionToken" },
423
+ "settlement": { "const": "completed" },
424
+ "reasonCode": { "type": "null" }
425
+ }
426
+ },
427
+ "operationIncompletePayload": {
428
+ "type": "object",
429
+ "additionalProperties": false,
430
+ "required": ["sessionRef", "operationRef", "messageRef", "sessionRevision", "settlement", "reasonCode"],
431
+ "properties": {
432
+ "sessionRef": { "$ref": "common-v1.schema.json#/$defs/opaqueRef" },
433
+ "operationRef": { "$ref": "common-v1.schema.json#/$defs/opaqueRef" },
434
+ "messageRef": { "$ref": "common-v1.schema.json#/$defs/nullableOpaqueRef" },
435
+ "sessionRevision": {
436
+ "anyOf": [
437
+ { "$ref": "common-v1.schema.json#/$defs/revisionToken" },
438
+ { "type": "null" }
439
+ ]
440
+ },
441
+ "settlement": { "enum": ["blocked", "aborted", "error", "unknown"] },
442
+ "reasonCode": { "$ref": "common-v1.schema.json#/$defs/reasonCode" }
443
+ }
444
+ },
445
+ "operationSettledEvent": {
446
+ "allOf": [
447
+ { "$ref": "#/$defs/eventBase" },
448
+ {
449
+ "type": "object",
450
+ "properties": {
451
+ "kind": { "const": "operation.settled" },
452
+ "payload": {
453
+ "oneOf": [
454
+ { "$ref": "#/$defs/operationCompletedPayload" },
455
+ { "$ref": "#/$defs/operationIncompletePayload" }
456
+ ]
457
+ }
458
+ }
459
+ }
460
+ ]
461
+ },
414
462
  "toolEvent": {
415
463
  "allOf": [
416
464
  { "$ref": "#/$defs/eventBase" },
@@ -421,13 +469,14 @@
421
469
  "payload": {
422
470
  "type": "object",
423
471
  "additionalProperties": false,
424
- "required": ["sessionRef", "operationRef", "toolCallRef", "toolLabel", "isError"],
472
+ "required": ["sessionRef", "operationRef", "toolCallRef", "toolLabel", "isError", "reasonCode"],
425
473
  "properties": {
426
474
  "sessionRef": { "$ref": "common-v1.schema.json#/$defs/opaqueRef" },
427
475
  "operationRef": { "$ref": "common-v1.schema.json#/$defs/opaqueRef" },
428
476
  "toolCallRef": { "$ref": "common-v1.schema.json#/$defs/opaqueRef" },
429
477
  "toolLabel": { "type": "string", "minLength": 1, "maxLength": 160, "pattern": "^[^\\u0000-\\u001F\\u007F]+$" },
430
- "isError": { "type": ["boolean", "null"] }
478
+ "isError": { "type": ["boolean", "null"] },
479
+ "reasonCode": { "$ref": "common-v1.schema.json#/$defs/nullableReasonCode" }
431
480
  }
432
481
  }
433
482
  },
@@ -449,6 +498,7 @@
449
498
  { "$ref": "#/$defs/resyncRequiredEvent" },
450
499
  { "$ref": "#/$defs/messageDeltaEvent" },
451
500
  { "$ref": "#/$defs/messageCompletedEvent" },
501
+ { "$ref": "#/$defs/operationSettledEvent" },
452
502
  { "$ref": "#/$defs/toolEvent" }
453
503
  ]
454
504
  }
@@ -2962,11 +2962,21 @@
2962
2962
  },
2963
2963
  "then": {
2964
2964
  "type": "object",
2965
- "properties": {
2966
- "isError": { "const": false },
2967
- "exitCode": { "anyOf": [{ "const": 0 }, { "type": "null" }] },
2968
- "reasonCode": { "type": "null" }
2969
- }
2965
+ "oneOf": [
2966
+ {
2967
+ "properties": {
2968
+ "isError": { "const": false },
2969
+ "exitCode": { "anyOf": [{ "const": 0 }, { "type": "null" }] },
2970
+ "reasonCode": { "type": "null" }
2971
+ }
2972
+ },
2973
+ {
2974
+ "properties": {
2975
+ "isError": { "const": false },
2976
+ "reasonCode": { "const": "search-target-missing" }
2977
+ }
2978
+ }
2979
+ ]
2970
2980
  }
2971
2981
  },
2972
2982
  {
@@ -0,0 +1,76 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://piagent.io.vn/schemas/piagent-webui/session-live-state-v1.schema.json",
4
+ "title": "Piagent WebUI canonical volatile session operation state v1",
5
+ "type": "object",
6
+ "additionalProperties": false,
7
+ "required": ["schemaVersion", "version", "generatedAt", "gatewayInstanceRef", "eventSequence", "state", "operations", "settlements", "reasonCode"],
8
+ "properties": {
9
+ "schemaVersion": { "const": 1 },
10
+ "version": { "const": "piagent-session-live-state-v1" },
11
+ "generatedAt": { "$ref": "common-v1.schema.json#/$defs/timestamp" },
12
+ "gatewayInstanceRef": { "$ref": "common-v1.schema.json#/$defs/opaqueRef" },
13
+ "eventSequence": { "type": "integer", "minimum": 0, "maximum": 9007199254740991 },
14
+ "state": { "enum": ["ready", "unavailable"] },
15
+ "operations": {
16
+ "type": "array",
17
+ "maxItems": 100,
18
+ "uniqueItems": true,
19
+ "items": { "$ref": "#/$defs/currentOperation" }
20
+ },
21
+ "settlements": {
22
+ "description": "Bounded, Gateway-epoch-local non-success terminal operation outcomes retained for Activity reconciliation.",
23
+ "type": "array",
24
+ "maxItems": 100,
25
+ "uniqueItems": true,
26
+ "items": { "$ref": "#/$defs/terminalSettlement" }
27
+ },
28
+ "reasonCode": { "$ref": "common-v1.schema.json#/$defs/nullableReasonCode" }
29
+ },
30
+ "allOf": [
31
+ {
32
+ "if": { "properties": { "state": { "const": "ready" } }, "required": ["state"] },
33
+ "then": { "properties": { "reasonCode": { "type": "null" } } },
34
+ "else": {
35
+ "properties": {
36
+ "operations": { "type": "array", "maxItems": 0 },
37
+ "settlements": { "type": "array", "maxItems": 0 },
38
+ "reasonCode": { "$ref": "common-v1.schema.json#/$defs/reasonCode" }
39
+ }
40
+ }
41
+ }
42
+ ],
43
+ "$defs": {
44
+ "currentOperation": {
45
+ "type": "object",
46
+ "additionalProperties": false,
47
+ "required": ["sessionRef", "operationRef", "state", "abortable"],
48
+ "properties": {
49
+ "sessionRef": { "$ref": "common-v1.schema.json#/$defs/opaqueRef" },
50
+ "operationRef": { "$ref": "common-v1.schema.json#/$defs/opaqueRef" },
51
+ "state": { "enum": ["running", "waiting-approval", "settling"] },
52
+ "abortable": { "type": "boolean" }
53
+ },
54
+ "allOf": [
55
+ {
56
+ "if": { "properties": { "state": { "const": "settling" } }, "required": ["state"] },
57
+ "then": { "properties": { "abortable": { "const": false } } },
58
+ "else": { "properties": { "abortable": { "const": true } } }
59
+ }
60
+ ]
61
+ },
62
+ "terminalSettlement": {
63
+ "type": "object",
64
+ "additionalProperties": false,
65
+ "required": ["sessionRef", "operationRef", "settlement", "reasonCode", "settledAt", "sequence"],
66
+ "properties": {
67
+ "sessionRef": { "$ref": "common-v1.schema.json#/$defs/opaqueRef" },
68
+ "operationRef": { "$ref": "common-v1.schema.json#/$defs/opaqueRef" },
69
+ "settlement": { "enum": ["blocked", "aborted", "error", "unknown"] },
70
+ "reasonCode": { "$ref": "common-v1.schema.json#/$defs/reasonCode" },
71
+ "settledAt": { "$ref": "common-v1.schema.json#/$defs/timestamp" },
72
+ "sequence": { "type": "integer", "minimum": 1, "maximum": 9007199254740991 }
73
+ }
74
+ }
75
+ }
76
+ }
@@ -4,7 +4,7 @@
4
4
  "title": "Piagent WebUI bounded subagent ownership tree v1",
5
5
  "type": "object",
6
6
  "additionalProperties": false,
7
- "required": ["schemaVersion", "version", "generatedAt", "identity", "runRef", "state", "treeRevision", "evidenceState", "orchestration", "parent", "children", "writer", "nestedLineage", "summary", "warnings", "health"],
7
+ "required": ["schemaVersion", "version", "generatedAt", "identity", "runRef", "state", "treeRevision", "evidenceState", "orchestration", "delegation", "parent", "children", "writer", "nestedLineage", "summary", "warnings", "health"],
8
8
  "properties": {
9
9
  "schemaVersion": { "const": 1 },
10
10
  "version": { "const": "piagent-webui-subagent-tree-v1" },
@@ -15,6 +15,7 @@
15
15
  "treeRevision": { "$ref": "common-v1.schema.json#/$defs/nullableRevisionToken" },
16
16
  "evidenceState": { "enum": ["complete", "partial", "aggregate-only", "missing", "unknown"] },
17
17
  "orchestration": { "$ref": "#/$defs/orchestration" },
18
+ "delegation": { "$ref": "#/$defs/delegation" },
18
19
  "parent": { "anyOf": [{ "$ref": "#/$defs/parent" }, { "type": "null" }] },
19
20
  "children": { "type": "array", "maxItems": 64, "items": { "$ref": "#/$defs/child" } },
20
21
  "writer": { "$ref": "#/$defs/writer" },
@@ -51,6 +52,15 @@
51
52
  "mode": { "enum": ["solo-first", "bounded-subagents", "parallel-readonly", "unknown"] },
52
53
  "subagents": { "enum": ["not-used", "optional", "used", "unknown"] }
53
54
  } },
55
+ "delegation": { "type": "object", "additionalProperties": false, "required": ["action", "reasonCodes", "projectedNetSavingsRatio", "minimumRequiredNetSavingsRatio", "budget"], "properties": {
56
+ "action": { "enum": ["dispatch", "skip", "unknown"] },
57
+ "reasonCodes": { "type": "array", "maxItems": 16, "uniqueItems": true, "items": { "type": "string", "pattern": "^[a-z0-9_.:-]+$" } },
58
+ "projectedNetSavingsRatio": { "type": ["number", "null"], "minimum": -10, "maximum": 1 },
59
+ "minimumRequiredNetSavingsRatio": { "const": 0.3 },
60
+ "budget": { "type": "object", "additionalProperties": false, "required": ["maxConcurrent", "maxTotal", "maxRetries", "maxWriters"], "properties": {
61
+ "maxConcurrent": { "const": 1 }, "maxTotal": { "const": 1 }, "maxRetries": { "const": 0 }, "maxWriters": { "const": 0 }
62
+ } }
63
+ } },
54
64
  "parent": { "type": "object", "additionalProperties": false, "required": ["nodeRef", "lifecycleState", "budgetTerminal", "mergeOwner"], "properties": {
55
65
  "nodeRef": { "$ref": "common-v1.schema.json#/$defs/opaqueRef" }, "lifecycleState": { "enum": ["active", "terminal", "unknown"] },
56
66
  "budgetTerminal": { "type": ["boolean", "null"] }, "mergeOwner": { "const": "parent" }
@@ -382,7 +382,7 @@
382
382
  "maxConcurrentSubagents": {
383
383
  "type": "integer",
384
384
  "minimum": 0,
385
- "maximum": 6
385
+ "maximum": 1
386
386
  },
387
387
  "defaultReviewLenses": {
388
388
  "type": "array",