@sema-agent/server 7.141.0 → 7.143.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 (341) hide show
  1. package/MIGRATION.md +657 -0
  2. package/USAGE.md +102 -30
  3. package/dist/adoption/plan.js +22 -0
  4. package/dist/approval-ask-audit-store.d.ts +61 -43
  5. package/dist/approval-ask-audit-store.js +69 -44
  6. package/dist/approval-ask-machine.d.ts +15 -7
  7. package/dist/approval-ask-machine.js +10 -4
  8. package/dist/approval-card.d.ts +126 -27
  9. package/dist/approval-card.js +103 -23
  10. package/dist/approval-crash-convergence.d.ts +17 -7
  11. package/dist/approval-crash-convergence.js +94 -22
  12. package/dist/approval-deny-reasons.d.ts +34 -30
  13. package/dist/approval-deny-reasons.js +21 -6
  14. package/dist/approval-policy-settlement.d.ts +1 -1
  15. package/dist/approval-queue-kind.d.ts +27 -0
  16. package/dist/approval-queue-kind.js +6 -0
  17. package/dist/approval-reconciler.d.ts +41 -9
  18. package/dist/approval-reconciler.js +45 -42
  19. package/dist/audit.js +4 -2
  20. package/dist/auth-bridge.d.ts +9 -6
  21. package/dist/auth-bridge.js +9 -3
  22. package/dist/boot/adoption.js +2 -1
  23. package/dist/boot/budget-tracing.d.ts +17 -1
  24. package/dist/boot/budget-tracing.js +10 -6
  25. package/dist/boot/device-lane.d.ts +1 -1
  26. package/dist/boot/execution-env.d.ts +24 -4
  27. package/dist/boot/execution-env.js +26 -23
  28. package/dist/boot/execution-lane.js +2 -1
  29. package/dist/boot/exit-boundary.js +5 -4
  30. package/dist/boot/governance-seams.d.ts +26 -41
  31. package/dist/boot/governance-seams.js +61 -28
  32. package/dist/boot/late-binds.d.ts +7 -4
  33. package/dist/boot/late-binds.js +3 -1
  34. package/dist/boot/leader.js +2 -4
  35. package/dist/boot/memory-consolidation.d.ts +0 -8
  36. package/dist/boot/memory-consolidation.js +5 -4
  37. package/dist/boot/parked-revive-gate.js +2 -1
  38. package/dist/boot/permission-rules-audit.d.ts +0 -28
  39. package/dist/boot/permission-rules-audit.js +2 -1
  40. package/dist/boot/read-deny-anchor-audit.js +2 -1
  41. package/dist/boot/reapers.js +9 -7
  42. package/dist/boot/resolve-spec.d.ts +1 -1
  43. package/dist/boot/resolve-spec.js +19 -10
  44. package/dist/boot/retention-lane.js +5 -3
  45. package/dist/boot/runner-deps.d.ts +10 -7
  46. package/dist/boot/runner-deps.js +20 -29
  47. package/dist/boot/runtime-caps.js +3 -2
  48. package/dist/boot/session-faces.js +4 -3
  49. package/dist/boot/shutdown.d.ts +9 -0
  50. package/dist/boot/shutdown.js +19 -4
  51. package/dist/boot/stage-02-web-admin-pull.js +3 -0
  52. package/dist/boot/stage-03-store-backend.d.ts +4 -1
  53. package/dist/boot/stage-03-store-backend.js +1 -2
  54. package/dist/boot/stage-04-stores.d.ts +5 -2
  55. package/dist/boot/stage-04-stores.js +6 -7
  56. package/dist/boot/stage-05-execution-env.d.ts +6 -3
  57. package/dist/boot/stage-05-execution-env.js +8 -6
  58. package/dist/boot/stage-06-runners.d.ts +6 -3
  59. package/dist/boot/stage-06-runners.js +3 -4
  60. package/dist/boot/stage-07-capability-layer.d.ts +6 -3
  61. package/dist/boot/stage-07-capability-layer.js +7 -2
  62. package/dist/boot/stage-08-reapers.d.ts +6 -3
  63. package/dist/boot/stage-08-reapers.js +3 -2
  64. package/dist/boot/stage-09-leader.d.ts +6 -3
  65. package/dist/boot/stage-10-http-server.d.ts +6 -3
  66. package/dist/boot/stage-10-http-server.js +14 -5
  67. package/dist/boot/stores.d.ts +5 -2
  68. package/dist/boot/stores.js +10 -9
  69. package/dist/boot/web-admin.d.ts +5 -1
  70. package/dist/boot/web-admin.js +48 -36
  71. package/dist/boot/webfetch-summarize-lane.js +2 -1
  72. package/dist/boot/workflow-orchestration.js +3 -2
  73. package/dist/capabilities/builtin-tools.d.ts +2 -1
  74. package/dist/capabilities/builtin-tools.js +2 -4
  75. package/dist/capabilities/composite-members.d.ts +2 -1
  76. package/dist/capabilities/composite-members.js +2 -1
  77. package/dist/capabilities/hands-lane.d.ts +9 -39
  78. package/dist/capabilities/hands-lane.js +8 -13
  79. package/dist/capabilities/mcp-probe.d.ts +3 -2
  80. package/dist/capabilities/scenarios.d.ts +11 -1
  81. package/dist/capabilities/scenarios.js +1 -0
  82. package/dist/capabilities/skills.d.ts +1 -17
  83. package/dist/capabilities/skills.js +0 -8
  84. package/dist/capability-facts.d.ts +31 -7
  85. package/dist/capability-facts.js +27 -4
  86. package/dist/card-void.d.ts +6 -9
  87. package/dist/config-catalog.js +2 -1
  88. package/dist/config-dir-trust.js +58 -29
  89. package/dist/config-invariants.d.ts +7 -1
  90. package/dist/config-invariants.js +7 -0
  91. package/dist/config-provider.d.ts +10 -0
  92. package/dist/config-provider.js +15 -4
  93. package/dist/config-root-migration.d.ts +13 -0
  94. package/dist/config-root-migration.js +99 -0
  95. package/dist/config-types.d.ts +19 -8
  96. package/dist/config.d.ts +10 -3
  97. package/dist/config.js +18 -4
  98. package/dist/delegated-session-owner.d.ts +5 -3
  99. package/dist/delegated-session-owner.js +1 -1
  100. package/dist/device-ws-protocol.d.ts +1 -0
  101. package/dist/device-ws-protocol.js +2 -1
  102. package/dist/env-model-table-gate.d.ts +53 -0
  103. package/dist/env-model-table-gate.js +53 -0
  104. package/dist/execution-lane-caps.d.ts +2 -1
  105. package/dist/fleet/fleet-bus.d.ts +34 -55
  106. package/dist/fleet/fleet-bus.js +35 -100
  107. package/dist/fleet/fleet-reconciler.d.ts +4 -4
  108. package/dist/fleet/fleet-reconciler.js +1 -1
  109. package/dist/fleet/subagent-tail-bus.d.ts +14 -11
  110. package/dist/fleet/subagent-tail-bus.js +15 -28
  111. package/dist/hooks/hook-runner.d.ts +6 -0
  112. package/dist/hooks/hook-runner.js +58 -8
  113. package/dist/host-decision.d.ts +54 -20
  114. package/dist/host-decision.js +42 -14
  115. package/dist/http/admission.d.ts +1 -1
  116. package/dist/http/admission.js +7 -3
  117. package/dist/http/approval-sweeps.js +11 -8
  118. package/dist/http/caller-trust.d.ts +1 -1
  119. package/dist/http/dispatch.js +4 -2
  120. package/dist/http/durable-run-leg.js +2 -2
  121. package/dist/http/engine-refusal.d.ts +16 -0
  122. package/dist/http/engine-refusal.js +17 -0
  123. package/dist/http/execution-context.d.ts +2 -2
  124. package/dist/http/idempotency.d.ts +1 -1
  125. package/dist/http/memory-compliance-failure-reply.d.ts +1 -3
  126. package/dist/http/memory-compliance-failure-reply.js +4 -6
  127. package/dist/http/owner-access.d.ts +11 -0
  128. package/dist/http/owner-access.js +13 -0
  129. package/dist/http/principal-gate.d.ts +3 -1
  130. package/dist/http/principal-gate.js +17 -8
  131. package/dist/http/resume-legs.d.ts +21 -7
  132. package/dist/http/resume-legs.js +76 -58
  133. package/dist/http/resume-restatement.d.ts +39 -0
  134. package/dist/http/resume-restatement.js +25 -0
  135. package/dist/http/route-ctx.d.ts +35 -10
  136. package/dist/http/route-ctx.js +1 -1
  137. package/dist/http/route-table.js +2 -0
  138. package/dist/http/routes/approvals-assistant.d.ts +9 -1
  139. package/dist/http/routes/approvals-assistant.js +142 -31
  140. package/dist/http/routes/attachments.js +18 -0
  141. package/dist/http/routes/capabilities.js +16 -4
  142. package/dist/http/routes/memory-policy.d.ts +2 -2
  143. package/dist/http/routes/memory-policy.js +27 -7
  144. package/dist/http/routes/notify-wake.js +23 -25
  145. package/dist/http/routes/rules.js +48 -13
  146. package/dist/http/routes/runs.js +12 -11
  147. package/dist/http/routes/session-memory-sync.d.ts +91 -0
  148. package/dist/http/routes/session-memory-sync.js +174 -0
  149. package/dist/http/routes/session-sync.js +13 -20
  150. package/dist/http/routes/sessions-list.d.ts +2 -1
  151. package/dist/http/routes/sessions.d.ts +2 -2
  152. package/dist/http/routes/sessions.js +22 -23
  153. package/dist/http/routes/tasks.js +34 -54
  154. package/dist/http/run-read-face.d.ts +7 -0
  155. package/dist/http/run-read-face.js +9 -3
  156. package/dist/http/send.d.ts +5 -0
  157. package/dist/http/send.js +9 -2
  158. package/dist/http/server.d.ts +27 -15
  159. package/dist/http/server.js +4 -6
  160. package/dist/http/stored-body-replay.js +15 -4
  161. package/dist/http/submit-replay.d.ts +4 -3
  162. package/dist/http/submit-replay.js +2 -2
  163. package/dist/http/sync-submit-body.d.ts +21 -4
  164. package/dist/http/sync-submit-body.js +13 -0
  165. package/dist/http/wire-types.d.ts +17 -7
  166. package/dist/identity-source.d.ts +21 -2
  167. package/dist/identity-source.js +6 -0
  168. package/dist/leader/leader.js +5 -2
  169. package/dist/leader/wire.d.ts +7 -1
  170. package/dist/leader/wire.js +6 -5
  171. package/dist/leg-facts.d.ts +37 -0
  172. package/dist/leg-facts.js +15 -0
  173. package/dist/memory-bundle-engine.d.ts +1 -4
  174. package/dist/memory-bundle-engine.js +2 -2
  175. package/dist/memory-incident-sink.d.ts +19 -6
  176. package/dist/memory-incident-sink.js +8 -4
  177. package/dist/memory-operator-faces.d.ts +30 -66
  178. package/dist/memory-operator-faces.js +17 -88
  179. package/dist/memory-scope-stores.d.ts +38 -40
  180. package/dist/memory-scope-stores.js +51 -36
  181. package/dist/memory-scope.d.ts +0 -9
  182. package/dist/memory-scope.js +0 -9
  183. package/dist/memory-sync-client.d.ts +21 -21
  184. package/dist/memory-sync-client.js +62 -43
  185. package/dist/memory-sync-identity.d.ts +24 -0
  186. package/dist/memory-sync-identity.js +57 -0
  187. package/dist/memory-sync.d.ts +27 -5
  188. package/dist/memory-sync.js +29 -7
  189. package/dist/model-plane-face.d.ts +13 -7
  190. package/dist/model-plane-face.js +2 -1
  191. package/dist/observability/fail-open.d.ts +47 -14
  192. package/dist/observability/fail-open.js +37 -11
  193. package/dist/observability/run-terminal.d.ts +92 -34
  194. package/dist/observability/run-terminal.js +171 -162
  195. package/dist/orchestration/workflow-completion-inbox.d.ts +5 -19
  196. package/dist/orchestration/workflow-completion-inbox.js +0 -12
  197. package/dist/orchestration/workflow-notify-journal.d.ts +3 -2
  198. package/dist/orchestration/workflow-park-decision.d.ts +8 -3
  199. package/dist/orchestration/workflow-park-decision.js +5 -3
  200. package/dist/org-delivery-gate.d.ts +11 -0
  201. package/dist/org-delivery-gate.js +19 -1
  202. package/dist/parked-decide.d.ts +13 -9
  203. package/dist/parked-decide.js +7 -7
  204. package/dist/parked-revive-surface.js +1 -1
  205. package/dist/peer-inbound-face.d.ts +127 -0
  206. package/dist/peer-inbound-face.js +158 -0
  207. package/dist/permission-rule-list.d.ts +13 -9
  208. package/dist/permission-rule-list.js +7 -3
  209. package/dist/plugins/approval-ask-store-file.d.ts +14 -4
  210. package/dist/plugins/approval-ask-store-file.js +64 -11
  211. package/dist/plugins/approval-ask-store-memory.d.ts +2 -1
  212. package/dist/plugins/approval-ask-store-memory.js +17 -14
  213. package/dist/plugins/approval-ask-store-sql.d.ts +70 -23
  214. package/dist/plugins/approval-ask-store-sql.js +79 -30
  215. package/dist/plugins/checkpoint-store-sql.d.ts +4 -4
  216. package/dist/plugins/checkpoint-store-sql.js +9 -7
  217. package/dist/plugins/file-history-store-sql.d.ts +24 -18
  218. package/dist/plugins/file-history-store-sql.js +24 -19
  219. package/dist/plugins/file-run-store.d.ts +35 -1
  220. package/dist/plugins/file-run-store.js +108 -9
  221. package/dist/plugins/imported-layer-root-retirement.d.ts +82 -0
  222. package/dist/plugins/imported-layer-root-retirement.js +96 -0
  223. package/dist/plugins/local-checkpoint-store.d.ts +1 -1
  224. package/dist/plugins/local-checkpoint-store.js +2 -2
  225. package/dist/plugins/local-session-store.d.ts +42 -9
  226. package/dist/plugins/local-session-store.js +83 -33
  227. package/dist/plugins/local-task-attachment-store.d.ts +12 -2
  228. package/dist/plugins/local-task-attachment-store.js +67 -43
  229. package/dist/plugins/mailbox-recipient-lifecycle.d.ts +9 -31
  230. package/dist/plugins/mailbox-recipient-lifecycle.js +4 -0
  231. package/dist/plugins/mailbox-store-sql.d.ts +12 -8
  232. package/dist/plugins/mailbox-store-sql.js +76 -7
  233. package/dist/plugins/memory-key-guards.d.ts +3 -3
  234. package/dist/plugins/memory-run-store.d.ts +6 -1
  235. package/dist/plugins/memory-run-store.js +11 -1
  236. package/dist/plugins/memory-sync-store-pg.d.ts +15 -0
  237. package/dist/plugins/memory-sync-store-pg.js +21 -0
  238. package/dist/plugins/memory-sync-store-tidb.d.ts +2 -0
  239. package/dist/plugins/memory-sync-store-tidb.js +13 -1
  240. package/dist/plugins/one-time-migrations.d.ts +58 -2
  241. package/dist/plugins/one-time-migrations.js +161 -4
  242. package/dist/plugins/org-delivery-quota-store.d.ts +1 -1
  243. package/dist/plugins/org-delivery-quota-store.js +2 -12
  244. package/dist/plugins/park-commit-watch.d.ts +1 -1
  245. package/dist/plugins/permission-rule-store-file.d.ts +10 -1
  246. package/dist/plugins/permission-rule-store-file.js +15 -2
  247. package/dist/plugins/permission-rule-store-sql.d.ts +31 -1
  248. package/dist/plugins/permission-rule-store-sql.js +35 -2
  249. package/dist/plugins/remote-env-device.d.ts +8 -11
  250. package/dist/plugins/remote-env-device.js +6 -3
  251. package/dist/plugins/remote-env-e2b.d.ts +23 -4
  252. package/dist/plugins/remote-env-e2b.js +111 -28
  253. package/dist/plugins/remote-env-k8s.d.ts +61 -22
  254. package/dist/plugins/remote-env-k8s.js +133 -33
  255. package/dist/plugins/remote-env-local-docker.d.ts +15 -3
  256. package/dist/plugins/remote-env-local-docker.js +40 -12
  257. package/dist/plugins/retention-store-sql.d.ts +2 -2
  258. package/dist/plugins/run-store-sql.d.ts +9 -1
  259. package/dist/plugins/run-store-sql.js +9 -1
  260. package/dist/plugins/sandbox-read-floor.d.ts +5 -7
  261. package/dist/plugins/sandbox-read-floor.js +2 -7
  262. package/dist/plugins/sql-errors.d.ts +10 -1
  263. package/dist/plugins/sql-errors.js +13 -0
  264. package/dist/plugins/store-backend.d.ts +33 -35
  265. package/dist/plugins/store-backend.js +10 -1
  266. package/dist/plugins/store-contracts.d.ts +50 -1
  267. package/dist/plugins/store-contracts.js +6 -0
  268. package/dist/plugins/task-attachment-store.d.ts +112 -14
  269. package/dist/plugins/task-attachment-store.js +207 -29
  270. package/dist/plugins/tool-result-store-sql.d.ts +9 -8
  271. package/dist/plugins/tool-result-store-sql.js +23 -2
  272. package/dist/plugins/wiring-section-codec.d.ts +32 -0
  273. package/dist/plugins/wiring-section-codec.js +55 -0
  274. package/dist/plugins/workspace-fill.d.ts +60 -0
  275. package/dist/plugins/workspace-fill.js +106 -0
  276. package/dist/project-bundle.d.ts +38 -0
  277. package/dist/project-bundle.js +609 -0
  278. package/dist/rule-entry-list.d.ts +3 -2
  279. package/dist/rule-entry-list.js +5 -1
  280. package/dist/rules-consent.d.ts +28 -5
  281. package/dist/rules-consent.js +40 -28
  282. package/dist/run-local.js +11 -13
  283. package/dist/runs.d.ts +12 -8
  284. package/dist/runs.js +6 -8
  285. package/dist/runtime-governance.d.ts +1 -1
  286. package/dist/sandbox-egress-policy.d.ts +4 -1
  287. package/dist/sandbox-egress-policy.js +3 -1
  288. package/dist/sandbox-git-plane.d.ts +31 -12
  289. package/dist/sandbox-git-plane.js +24 -4
  290. package/dist/security.d.ts +9 -0
  291. package/dist/security.js +8 -0
  292. package/dist/server-secret-env.d.ts +4 -0
  293. package/dist/session-error-wire.d.ts +36 -0
  294. package/dist/session-error-wire.js +13 -0
  295. package/dist/session-incarnation.d.ts +1 -1
  296. package/dist/session-notify-door.d.ts +106 -0
  297. package/dist/session-notify-door.js +93 -0
  298. package/dist/session-sync.d.ts +9 -14
  299. package/dist/session-sync.js +5 -5
  300. package/dist/session-workspace.d.ts +3 -13
  301. package/dist/session-workspace.js +0 -9
  302. package/dist/standing-answer-grant.d.ts +5 -0
  303. package/dist/standing-answer-grant.js +10 -0
  304. package/dist/stores-sql/session-policy-store-sql.d.ts +4 -2
  305. package/dist/stores-sql/session-policy-store-sql.js +3 -13
  306. package/dist/task-mcp.d.ts +1 -1
  307. package/dist/task-settings.d.ts +21 -10
  308. package/dist/task-settings.js +46 -13
  309. package/dist/terminal.d.ts +39 -19
  310. package/dist/terminal.js +65 -22
  311. package/dist/tool-approval.d.ts +56 -37
  312. package/dist/tool-approval.js +78 -71
  313. package/dist/trace/core-keyset-guard.d.ts +134 -14
  314. package/dist/trace/engine-notice-wire.d.ts +9 -3
  315. package/dist/trace/engine-notice-wire.js +7 -3
  316. package/dist/trace/exit-seat.d.ts +9 -2
  317. package/dist/trace/exit-seat.js +1 -0
  318. package/dist/trace/ledger-sink.d.ts +10 -6
  319. package/dist/trace/ledger-sink.js +2 -2
  320. package/dist/trace/model-segment.d.ts +55 -25
  321. package/dist/trace/model-segment.js +101 -33
  322. package/dist/trace/project.d.ts +25 -5
  323. package/dist/trace/project.js +22 -0
  324. package/dist/trace/redact.d.ts +61 -9
  325. package/dist/trace/redact.js +1490 -468
  326. package/dist/trace/self-minted-wire.d.ts +745 -24
  327. package/dist/trace/self-minted-wire.js +239 -9
  328. package/dist/trace/wire-projection-faces.d.ts +2 -2
  329. package/dist/trace/wire-projection-faces.js +2 -2
  330. package/dist/verifier-pause-card.d.ts +33 -5
  331. package/dist/verifier-pause-card.js +15 -10
  332. package/dist/web-admin-client/apply-effective.d.ts +12 -16
  333. package/dist/web-admin-client/apply-effective.js +109 -9
  334. package/dist/web-admin-client/effective-keys.js +2 -0
  335. package/dist/web-admin-client/types.d.ts +4 -0
  336. package/dist/workspace-space.d.ts +19 -3
  337. package/dist/workspace-space.js +8 -4
  338. package/docs/DEVICE-EXECUTOR-PROTOCOL.md +3 -1
  339. package/package.json +3 -2
  340. package/wire-changes/server@7.142.0.json +639 -0
  341. package/wire-changes/server@7.143.0.json +1167 -0
@@ -1,5 +1,6 @@
1
- import { type PersistedTaskResult, type RunRecord } from "../plugins/store-contracts.js";
2
- import { type StoredResultReadSeat } from "../terminal.js";
1
+ import type { CollapseUnder, ExitResult, SeatKeyPaths, TextLeafPaths } from "../trace/core-keyset-guard.js";
2
+ import { type PersistedResultSideKeys, type PersistedTaskResult, type RunRecord } from "../plugins/store-contracts.js";
3
+ import { type PauseSeat, type StoredResultReadSeat } from "../terminal.js";
3
4
  /** 一次终局写口交给观测面的原料(store 侧装配,**未脱敏** —— 脱敏在本模块内做,见 {@link notifyRunTerminal})。 */
4
5
  export interface RunTerminalRecord {
5
6
  /** 这条 run 的账本 id = `GET /v1/runs/:id` 的 id(本仓 run 行主键名为 taskId,同一个值)。 */
@@ -165,35 +166,87 @@ export declare function redactModelText(raw: string): string;
165
166
  /** 回声座上的值留不留:形内 ⇒ `true`(原样留);`undefined` / 空串 ⇒ `false`(缺席本身,不计数);其余越界 ⇒ `false` + 计数。
166
167
  * 调用方按 `false` 删键 / 不铸键 —— 本函数是全部回声座(结果面 / 账本孪生 / 子代通告 / side-query 200 体)的**唯一**判决口。 */
167
168
  export declare function admitProviderEcho(value: unknown, seat: string): value is string;
168
- /** {@link redactTerminalResult} 会碰的全部顶层键 = 现行形里**不是** `"verbatim"` 的行(`"redacted"` ∪ [ref] 的
169
- * `"provider-echo"`)∪ 旧形平面键;`memoRedactTerminalResult` 的记忆键由它派生(两处同源,见 `RESULT_KEY_TREATMENT` 顶注)。
170
- * 🔴 [ref] 起改名(原 `REDACTABLE_RESULT_LEAVES`):回声键不脱敏但**会被改**(越界 ⇒ 删键),漏进记忆键集 = 读面记忆腿对存量行
171
- * O(1) 原样直返,读面纵深对那几片恒不生效([ref] 立案时 `editedFiles` 那一格的同一个病)。 */
169
+ /**
170
+ * 🔴 **[ref]:一条结果上的文本叶一张座表** —— 结果汇点({@link redactTerminalResult})判「哪片叶要脱、怎么脱」的**唯一**一处。
171
+ *
172
+ * 键 = 一条结果上**每一片自由文本叶**的路径(装得下任意文字的串 / 模板串 / 品牌串 / `unknown`;点分;数组元素记 `[]`;索引签名记 `*`),值 = 闭集处置词。结果形 = 本仓结算点交给封口的三种出口结果
173
+ * (普通腿 `TaskResult` / verify 腿 `VerificationResult` / cascade 腿 `CascadeRunResult`,与停驻座门 ⑩f 同一组)∪ server 侧记键(`PersistedResultSideKeys`)。
174
+ * 键集**由类型派生**(`trace/core-keyset-guard.ts` ⑩g 的 `TextLeafPaths`),表的型就是派生键集上的映射 ⇒ core 在任何一种出口结果的任何一层加一片
175
+ * 自由文本叶(或把数字座 / 闭集词座放宽成串、加一个 `unknown` 座)⇒ 少一行 **TS2741**;表里留了 core 没有的残条目 ⇒ **TS2353**。数字 / 布尔 /
176
+ * 闭集字面量联合装不下文字,不进表(闭集词逐字过境是它的型担保的,不是一行表上的判断)。
177
+ *
178
+ * 存在理由(两次「按层记键」的病,第二次是本表的来历):
179
+ * · [ref] U2:读面记忆手抄过自己的叶集 ⇒ 收成「`TaskResult` 顶层键 × 处置」一张表(`RESULT_KEY_TREATMENT`,本表取代,零别名);
180
+ * · [ref]:那张表按 `keyof TaskResult` 记,组合腿结果的**超形**(verify 的 `verification`、cascade 的五键)不在键集里 ⇒
181
+ * `verification.findings[]` / `evidence`(验证器模型写的自由文本)、`attempts[].gateError` / `diagnostics`(门的异常文案 / 门附的理由)原样落 run 行 /
182
+ * 账本 done 行 / 同步 200 体,读面整只回放;而且表只到顶层,叶在哪一层由六只手写臂各自去够(`terminal.message` / `reason`、`remoteEnvFailures[]`、
183
+ * `editedFiles[].path`、`result` / `salvagedOutput`、`rewindNotes[]`),回声键另有一张实现表外加一段加载期对账。
184
+ * 现在:一张表 + 一只走表函数({@link applyResultTextLeaves}),写入口(店 / 账本)与读出口(同步体 / 读面)同调。
185
+ *
186
+ * **处置词(闭集,穷尽 `switch` 消费 —— 加词不加臂 = 编译红)**:
187
+ * · `"model-text"` —— 模型自由文本 / 模型可控字节 ⇒ {@link redactModelText}([ref]:与 CoT 同一只 `redactSecrets`、同一张替换串表;不设体量上限,抛则占位);
188
+ * · `"error-text"` —— 有界的披露散文(异常文案 / 引擎披露行)⇒ {@link redactErrorMessage};
189
+ * · `"provider-echo"` —— 服务商回声、引擎逐字转交的不透明 id ⇒ 只做形状校验({@link admitProviderEcho}:形内原样、越界删键 + 计数),不过脱敏器;
190
+ * · `"provider-join-key"` —— 出身 provider 的跨面 join 键(工具调用 id)⇒ 本面逐字(形状在 core brain 入口一次施加,见 {@link admitProviderEcho} 顶注);
191
+ * · `"verbatim"` —— 本栈内部铸造的 id / 部署配置 / 引擎观测面 ⇒ 不碰。**唯一的模型可控逐字座**是 `structuredOutput`(见该行注)。
192
+ * · `"outward-code"` —— 机器码座(因由的 `terminal.code`、cascade 每一级的 `attempts[].errorCode`:同一类码)⇒ 本汇点不碰 —— 折码的属主是出口封口
193
+ * (`terminal.ts` 的写封 / 读封,{@link sealResultForExit}):出了本服务码形的码在汇点之前已折成 `internal.store_error` 并留运维线索,汇点再折一次就是第二个属主。
194
+ * · 归属词 —— 该路径下是一棵**另有派生表**的子树,本表只登记属主,不在两张表里各判一次:`"stats-tree"`(stats 五表)/ `"terminal-detail"`(detail 三臂表)/
195
+ * `"api-failure"`({@link API_FAILURE_TREATMENT};结果面与账本子代通告面两张脸共用)/ `"stranded-answer"`({@link STRANDED_ANSWER_TREATMENT},逐行)。
196
+ * 属主表的型是 ⑩g 的 `OwnerTable`:每个成员只许盖得住它之下全部自由文本叶的词 ⇒ 子树里多一片叶而属主那一行盖不住(数字袋 `stats.nested` 里加一个串)
197
+ * 同样 tsc 红 —— 折叠只换了「在哪张表上红」,不留盲区。
198
+ * 停驻座的凭据与门(`PAUSE_SEATS` 的六条路径)**不在本表**:凭据归出口封口摘、门归 {@link redactCheckpointGate};键集从座表派生后减掉,不手抄。
199
+ *
200
+ * [ref] / [ref](7.75.1)那条规则在这里成文:**结果上的模型自由文本一律过脱敏器**,没有「别的 sink 自判」这条退路;留 `"verbatim"` 的是本栈铸的
201
+ * id / 目录 id / 部署配置(`structuredOutput` 一座除外,见行内注),逐叶理由见行内注。
202
+ */
203
+ export type TextLeafTreatment = "model-text" | "error-text" | "provider-echo" | "provider-join-key" | "verbatim" | "outward-code" | "stats-tree" | "terminal-detail" | "api-failure" | "stranded-answer";
204
+ /**
205
+ * 子树另有属主的路径前缀 —— 派生出的叶路径落在它之下就折成它本身(⑩g 的 `CollapseUnder`:按**路径**折,不按类型停 —— 结构类型的「停在某型」
206
+ * 会把恰好同形的别处子树一起吞掉)。前四只各对应一只归属词;`attempts.[].model` 是 core 的 `ModelRef`(`string | Model`):本服务的梯子只给目录 id 串
207
+ * (`http/run-meta.ts` 的 `cascadeConfig`,后台腿与同步腿同一只),对象臂不可达 ⇒ 整座按串处置,不展开 `Model` 的二十余格(对象臂真到达那天,它的凭据座
208
+ * —— `headers` —— 是出口封口的事,与 `PAUSE_SEATS` 同类,不是文本表的事)。
209
+ * ⚠️ 五只前缀里**只有这一只没有属主表接着判**(前四只的属主表是 `OwnerTable`,子树里多一片叶盖不住即红):`Model` 加一个串成员不会红 ——
210
+ * 它与「对象臂不可达」是同一个前提,前提翻了(梯子交对象)就得给它一张属主表或展开成行。
211
+ */
212
+ type TextLeafOwnedPrefix = "stats" | "terminal.detail" | "apiFailure" | "strandedHumanAnswers.[]" | "attempts.[].model";
213
+ /** 停驻座的凭据 / 门路径(从 `PAUSE_SEATS` 派生):先折叠(门是一棵子树),再从键集里减掉。 */
214
+ type PauseSeatPath = SeatKeyPaths<PauseSeat, "token" | "gate">;
215
+ /** 本表的键集(派生)。 */
216
+ export type ResultTextLeafPath = Exclude<CollapseUnder<TextLeafPaths<ExitResult | PersistedResultSideKeys>, TextLeafOwnedPrefix | PauseSeatPath>, PauseSeatPath>;
217
+ export declare const RESULT_TEXT_LEAVES: {
218
+ readonly [P in ResultTextLeafPath]: TextLeafTreatment;
219
+ };
220
+ /** {@link redactTerminalResult} 会碰的全部顶层键 = 文本叶表上**会动字节**的行的根键 ∪ 旧形平面键 ∪ 停驻座的根键 ∪ `editedFiles`(条目上界);
221
+ * `memoRedactTerminalResult` 的记忆键由它派生(两处同源,不手抄)。漏进记忆键集 = 读面记忆腿对存量行那几片 O(1) 原样直返,读面纵深恒不生效
222
+ * ([ref] 立案时 `editedFiles` 那一格、[ref] 立案时 `attempts` 那一格的同一个病 —— 后者修前不在任何键表里)。
223
+ * 回声行不脱敏但**会被改**(越界 ⇒ 删键),所以同样进集([ref] 起名 `TREATED_…`,原 `REDACTABLE_…`)。 */
172
224
  export declare const TREATED_RESULT_LEAVES: readonly string[];
173
- export declare function redactTerminalResult<T extends {
174
- terminal?: unknown;
175
- /** 旧形(≤7.63.0)的三个顶层座;形上取 `unknown` —— 读盘面对盘上字节不作假设。 */
176
- errorMessage?: unknown;
177
- blockedReason?: unknown;
178
- checkpointGate?: unknown;
179
- remoteEnvFailures?: readonly {
180
- message?: string | undefined;
181
- }[] | undefined;
182
- /** [ref]:模型自由文本两叶 + 引擎披露散文一族。形上同样取 `unknown`(读面纪律,见下)。 */
183
- result?: unknown;
184
- salvagedOutput?: unknown;
185
- rewindNotes?: unknown;
186
- /** 🔴 形上**故意**是 `unknown`:本函数也是**读面**(旧持久 blob / 非 core Runner 的形不可信),
187
- * 声明成 `{path,edits}[]` 会逼每一个喂坏形的调用点铸一次宽松断言 —— 而「坏形从哪来」正是本座要
188
- * 处理的事(同一份不信任在 `remoteEnvFailures` 的实现里也已成文)。运行期逐项判形,不抛。 */
189
- editedFiles?: unknown;
190
- /** [ref]:形上同样 `unknown` —— 本函数是读盘面,`stats` 的树形逐层现判(见 {@link redactStats})。 */
191
- stats?: unknown;
192
- /** [ref]:provider 回声三键(形上 `unknown`,读盘面纪律同上;处置见 {@link PROVIDER_ECHO_SHAPERS})。 */
193
- apiFailure?: unknown;
194
- strandedHumanAnswers?: unknown;
195
- responseModel?: unknown;
196
- } | null | undefined>(result: T): T;
225
+ /**
226
+ * 同口:终态 `result` 整块也持久化(`GET /v1/runs/:id` 直出),写入前把里面的**自由文本座**脱敏,其余键
227
+ * 逐字不动;`undefined`/`null` 透传。
228
+ *
229
+ * 🔴 [ref](core 7.6.0 [ref] D-8):自由文本座**搬家了** —— 失败文案与阻塞理由从顶层平面键
230
+ * (`errorMessage` / `blockedReason`)搬进因由 `terminal` 的两条臂(`failed.message` / `blocked.reason`)。
231
+ * 本函数**两种形都认**,而这不是「兼容读臂」(codex 对抗复审 r1 [high],亲读验真后**改判**;首版删掉了旧键
232
+ * 臂,那是错的):本函数是**读盘面**,而 `task_run.result` / `task_event(done).result` 里躺着 7.63.0 及以前
233
+ * 写下的**真字节**,它们本来就是平面形。写口只剩因由一条(没有任何东西会再写出旧形),所以这里不存在
234
+ * 「两个写者」;而不认旧形的代价是**可复现的凭据回放**:上线前落盘的原文经 `GET /v1/runs/:id/events` 重新
235
+ * 明文外发(读面这一层纵深正是为那批行存在的)。⇒ 规则仍只有一条:**读盘认盘上真有的形,写盘只写一种形**。
236
+ *
237
+ * 读面也走本函数,所以形上一律取宽:旧持久 blob 与非 core 的 Runner 实现给的形不可信,运行期逐层判形、不抛(走表函数与各属主同款不信任)。
238
+ */
239
+ /**
240
+ * **结果整块的唯一汇点** —— 三孪生 store 的 `setTerminal` / park 两口(经 {@link sealRunRowResult})、`redactLedgerEventData` 的 `done.result`、
241
+ * `POST /v1/tasks` 200 体(`http/routes/tasks.ts` 的 `mintSubmitExitResult`)、读面(`GET /v1/runs/:id` / `/events`,经 {@link memoRedactTerminalResult})
242
+ * 全调它,于是新铸与**存量回放**同时被覆盖(core 铸点修不回溯已写行)。四段,各有一个属主:
243
+ * ① `editedFiles` 条目上界(容器界,不是文本处置;先截后走表,不为越界条目付扫描);
244
+ * ② **文本叶表** {@link RESULT_TEXT_LEAVES} 一张走完({@link applyResultTextLeaves})—— 自由文本 / 回声 / 两棵另有属主的子树都在这一步;
245
+ * ③ 停驻座的门({@link PAUSE_SEATS} × {@link redactCheckpointGate});
246
+ * ④ 旧形(≤7.63.0)的三个顶层平面键 —— 盘上冻结形,不在任何活类型上(见 {@link LEGACY_RESULT_LEAVES})。
247
+ * 形上取宽:本函数也是**读盘面**(旧持久 blob / 非 core Runner 的形不可信),每一段逐层判形、不抛;字节没变 ⇒ **同一引用**。
248
+ */
249
+ export declare function redactTerminalResult<T extends object | null | undefined>(result: T): T;
197
250
  /**
198
251
  * 🔴 **[ref] —— run 行 `result` 列的唯一入口**:先过出口封口({@link sealResultForExit}:摘恢复凭据 + 折域外码),
199
252
  * 再过 {@link redactTerminalResult}。三家 run 店(SQL 两方言 / file / memory)的**三个**写口 —— `setTerminal` 与
@@ -207,10 +260,14 @@ export declare function redactTerminalResult<T extends {
207
260
  *
208
261
  * `null` 原样(= 这条腿没有结果可落:引擎没给终局就收流 / 断连竞态 park / 重开 re-park)。
209
262
  *
210
- * `readSeat`:读面借这同一只组合读存量行时(`GET /v1/runs/:id` 的非终态臂)给出读座 —— 只决定折码运维行是「一件新的失败」还是「同一行的再观看」
211
- * (见 `sealResultForExit`);店的写口不给。
263
+ * 本函数是**写入口**(结果第一次落盘 ⇒ 折码运维线索 `at=exit`);读面读存量行用 {@link sealStoredRunRowResult}(读座必填)。
264
+ */
265
+ export declare function sealRunRowResult(result: PersistedTaskResult | null): PersistedTaskResult | null;
266
+ /**
267
+ * {@link sealRunRowResult} 的**读入口**(`GET /v1/runs/:id` 的非终态臂读停驻行):同一套封口 + 同一只汇点,只差折码运维线索的观看点 ——
268
+ * 读座必填({@link StoredResultReadSeat}),再观看走 fail-open 纪律(见 `terminal.ts` 的 `sealStoredResult`)。
212
269
  */
213
- export declare function sealRunRowResult(result: PersistedTaskResult | null, readSeat?: StoredResultReadSeat): PersistedTaskResult | null;
270
+ export declare function sealStoredRunRowResult(result: PersistedTaskResult | null, seat: StoredResultReadSeat): PersistedTaskResult | null;
214
271
  /** [ref](第五轮合并重扫 wf_f00c00bc 两根 [high]):同一个 `TaskResult` 除 run 行外还被逐字追加进 run_events 的 `done` 行
215
272
  * (bg/verify/cascade/stream/resume 五腿),`failed` 行带原文 `errorMessage`,`GET /v1/runs/:id/events` 原样回放。
216
273
  * 三孪生 `appendEvent` 入口 + 事件读面(旧行纵深)同调本函数:只认 `done.result`(整块走 `redactTerminalResult`)与
@@ -255,7 +312,7 @@ export declare function redactLeaderResultWithFlag(result: unknown): {
255
312
  };
256
313
  export declare function memoRedactedRead<T>(seat: string, raw: T, redact: (v: T) => T): T;
257
314
  /** run 终态 result 的读面记忆只按**本函数会改字节的那几叶**({@link TREATED_RESULT_LEAVES}:脱敏叶 ∪ [ref] 回声叶 ∪ 旧形平面键,属主是
258
- * `RESULT_KEY_TREATMENT`)做键与留体——
315
+ * 文本叶表 {@link RESULT_TEXT_LEAVES})做键与留体——
259
316
  * 第十六轮重扫:按整块 result 摘要每次轮询要 stringify 一份可能数 MB 的 result,且大 result 的脏行永远存不进去。叶全缺席
260
317
  * ⇒ O(1) 直返(`redactTerminalResult` 本就同引用)。
261
318
  * 🔴 [ref](core 7.6.0 D-8):新形把前两片搬进了 `terminal`(同属一个键,按它整只做叶更省);旧形的两片
@@ -294,4 +351,5 @@ export declare function redactLedgerEventForRead(type: string, data: unknown): u
294
351
  export declare function diffScanShadowCountForTest(): number;
295
352
  export declare function resetDiffScanShadowCountForTest(): void;
296
353
  export declare function resetReadRedactionMemoForTest(): void;
354
+ export {};
297
355
  //# sourceMappingURL=run-terminal.d.ts.map
@@ -3,7 +3,7 @@ import { redactSecrets } from "../trace/redact.js";
3
3
  import { isProviderEchoShape } from "@sema-agent/core";
4
4
  import { isModelTextLedgerEventType, isParkLedgerEventType } from "../trace/ledger-events.js";
5
5
  import { isUnsuccessfulRunStatus } from "../plugins/store-contracts.js";
6
- import { mapPauseSeats, PAUSE_SEATS, sealResultForExit } from "../terminal.js";
6
+ import { mapPauseSeats, PAUSE_SEATS, sealResultForExit, sealStoredResult } from "../terminal.js";
7
7
  import { errorText } from "./err-text.js";
8
8
  import { recordFailOpen } from "./fail-open.js";
9
9
  import { toolEndMediaAsDescriptors } from "../trace/tool-output-media.js";
@@ -128,43 +128,140 @@ function shapeEchoMembers(node, table, seat) {
128
128
  }
129
129
  return out ?? node;
130
130
  }
131
- function shapeEchoRows(rows, table, seat) {
132
- if (!Array.isArray(rows))
133
- return rows;
134
- const next = rows.map((row) => shapeEchoMembers(row, table, seat));
135
- return next.every((x, i) => x === rows[i]) ? rows : next;
136
- }
137
131
  const MAX_EDITED_FILES = 1000;
138
- const RESULT_KEY_TREATMENT = {
139
- terminal: "redacted",
140
- remoteEnvFailures: "redacted",
141
- editedFiles: "redacted",
142
- responseModel: "provider-echo",
143
- apiFailure: "provider-echo",
144
- strandedHumanAnswers: "provider-echo",
132
+ export const RESULT_TEXT_LEAVES = {
145
133
  taskId: "verbatim",
146
134
  runId: "verbatim",
147
135
  sessionId: "verbatim",
136
+ placementRoot: "verbatim",
148
137
  model: "verbatim",
149
- compaction: "verbatim",
150
- effectiveReasoning: "verbatim",
151
- result: "redacted",
152
- salvagedOutput: "redacted",
153
- retryAfterMs: "verbatim",
154
- degraded: "verbatim",
138
+ "terminal.code": "outward-code",
139
+ "terminal.message": "error-text",
140
+ "terminal.reason": "error-text",
141
+ "terminal.detail": "terminal-detail",
142
+ "terminal.checkpointId": "verbatim",
143
+ "terminal.requestedByCallId": "provider-join-key",
144
+ "terminal.nestedPause.checkpointId": "verbatim",
145
+ "terminal.nestedPause.requestedByCallId": "provider-join-key",
146
+ result: "model-text",
147
+ salvagedOutput: "model-text",
148
+ "remoteEnvFailures.[].message": "error-text",
149
+ "rewindNotes.[].message": "error-text",
150
+ "editedFiles.[].path": "model-text",
151
+ responseModel: "provider-echo",
152
+ apiFailure: "api-failure",
153
+ "strandedHumanAnswers.[]": "stranded-answer",
154
+ "degraded.from": "verbatim",
155
+ "degraded.to": "verbatim",
156
+ "degraded.chain.[]": "verbatim",
157
+ "effectiveReasoning.endpoint": "verbatim",
158
+ "resultEntryIds.[]": "verbatim",
159
+ "pendingApproval.askIds.[]": "verbatim",
160
+ "effectiveReadDenyPatterns.[].pattern": "verbatim",
161
+ "effectiveMemoryScopes.writeScope": "verbatim",
162
+ "effectiveMemoryScopes.scopes.[].scope": "verbatim",
163
+ "effectiveMemoryScopes.projectKey.scope": "verbatim",
164
+ "effectiveMemoryScopes.materializedResidue.[]": "verbatim",
155
165
  structuredOutput: "verbatim",
156
- resultEntryIds: "verbatim",
157
- rewindNotes: "redacted",
158
- haltedOnUserRejection: "verbatim",
159
- haltedByUser: "verbatim",
160
- pendingApproval: "verbatim",
161
- approvalWaitedMs: "verbatim",
162
- effectiveReadFace: "verbatim",
163
- effectiveWriteFace: "verbatim",
164
- effectiveReadDenyPatterns: "verbatim",
165
- effectiveMemoryScopes: "verbatim",
166
- stats: "redacted",
166
+ stats: "stats-tree",
167
+ "verification.findings.[]": "model-text",
168
+ "verification.evidence": "model-text",
169
+ "verification.verifierPause.sessionId": "verbatim",
170
+ "verification.verifierPause.checkpointId": "verbatim",
171
+ "attempts.[].model": "verbatim",
172
+ "attempts.[].errorCode": "outward-code",
173
+ "attempts.[].gateError": "error-text",
174
+ "attempts.[].diagnostics": "model-text",
175
+ "cancelContext.lastEventKind": "verbatim",
176
+ "cancelContext.lastBrainStatus.phase": "verbatim",
177
+ "cancelContext.lastBrainStatus.errClass": "verbatim",
167
178
  };
179
+ const DROP_LEAF = Symbol("drop-leaf");
180
+ function textLeafAct(treatment) {
181
+ switch (treatment) {
182
+ case "verbatim":
183
+ case "provider-join-key":
184
+ case "outward-code":
185
+ return undefined;
186
+ case "model-text":
187
+ return (v) => (typeof v === "string" ? redactModelText(v) : v);
188
+ case "error-text":
189
+ return (v) => (typeof v === "string" ? redactErrorMessage(v) : v);
190
+ case "provider-echo":
191
+ return (v, _holder, seat) => (admitProviderEcho(v, seat) ? v : DROP_LEAF);
192
+ case "stats-tree":
193
+ return (v) => redactStats(v);
194
+ case "terminal-detail":
195
+ return (v, holder) => shapeTerminalDetail(v, holder);
196
+ case "api-failure":
197
+ return (v) => shapeEchoMembers(v, API_FAILURE_TREATMENT, "apiFailure");
198
+ case "stranded-answer":
199
+ return (v) => shapeEchoMembers(v, STRANDED_ANSWER_TREATMENT, "strandedHumanAnswers[]");
200
+ default: {
201
+ const unhandled = treatment;
202
+ throw new Error(`unhandled text-leaf treatment: ${String(unhandled)}`);
203
+ }
204
+ }
205
+ }
206
+ const ACTIVE_TEXT_LEAVES = Object.entries(RESULT_TEXT_LEAVES).flatMap(([seat, treatment]) => {
207
+ const act = textLeafAct(treatment);
208
+ return act === undefined ? [] : [{ seat, segments: seat.split("."), act }];
209
+ });
210
+ function mapTextLeaf(node, segments, depth, holder, act, seat) {
211
+ if (depth === segments.length)
212
+ return act(node, holder, seat);
213
+ if (node === null || typeof node !== "object")
214
+ return node;
215
+ const segment = segments[depth];
216
+ if (segment === "[]") {
217
+ if (!Array.isArray(node))
218
+ return node;
219
+ let changed = false;
220
+ const next = [];
221
+ for (const el of node) {
222
+ const n = el === undefined ? el : mapTextLeaf(el, segments, depth + 1, node, act, seat);
223
+ if (n === DROP_LEAF) {
224
+ changed = true;
225
+ continue;
226
+ }
227
+ if (!Object.is(n, el))
228
+ changed = true;
229
+ next.push(n);
230
+ }
231
+ return changed ? next : node;
232
+ }
233
+ if (Array.isArray(node))
234
+ return node;
235
+ const obj = node;
236
+ let out;
237
+ for (const key of segment === "*" ? Object.keys(obj) : Object.hasOwn(obj, segment) ? [segment] : []) {
238
+ const child = obj[key];
239
+ if (child === undefined)
240
+ continue;
241
+ const n = mapTextLeaf(child, segments, depth + 1, obj, act, seat);
242
+ if (n === DROP_LEAF)
243
+ delete (out ??= { ...obj })[key];
244
+ else if (!Object.is(n, child))
245
+ (out ??= { ...obj })[key] = n;
246
+ }
247
+ return out ?? node;
248
+ }
249
+ function applyResultTextLeaves(result) {
250
+ let out = result;
251
+ for (const row of ACTIVE_TEXT_LEAVES)
252
+ out = mapTextLeaf(out, row.segments, 0, undefined, row.act, row.seat);
253
+ return out;
254
+ }
255
+ function shapeTerminalDetail(detail, terminal) {
256
+ const kind = terminal !== null && typeof terminal === "object" ? terminal.kind : undefined;
257
+ if (kind === "failed")
258
+ return shapeArmedDetail(detail, TERMINAL_FAILURE_DETAIL_TREATMENT);
259
+ if (kind === "completed")
260
+ return shapeArmedDetail(detail, TERMINAL_COMPLETED_DETAIL_TREATMENT);
261
+ if (kind === "blocked")
262
+ return shapeTerminalBlockedDetail(detail);
263
+ return shapeArmedDetail(detail, {});
264
+ }
168
265
  const API_FAILURE_TREATMENT = {
169
266
  status: "verbatim",
170
267
  requestId: "provider-echo",
@@ -182,6 +279,8 @@ const TERMINAL_FAILURE_DETAIL_TREATMENT = {
182
279
  providerConditionSource: "verbatim",
183
280
  providerResetAtMs: "verbatim",
184
281
  route: "verbatim",
282
+ errorKind: "verbatim",
283
+ tool: "verbatim",
185
284
  },
186
285
  coded: { kind: "verbatim", detail: "free-text-tree" },
187
286
  model_output_invalid: { kind: "verbatim", cause: "verbatim", outputLimit: "verbatim" },
@@ -209,12 +308,15 @@ function redactStringLeaves(node, depth = 0) {
209
308
  }
210
309
  const OFF_ARM_MEMBER_TREATMENT = "free-text-tree";
211
310
  const redactDetailMember = (v) => redactStringLeaves(v, 1);
212
- function shapeTerminalFailureDetail(detail) {
311
+ const TERMINAL_COMPLETED_DETAIL_TREATMENT = {
312
+ finish_reason_unknown: { kind: "verbatim", finishReasonUnknown: "provider-echo" },
313
+ };
314
+ function shapeArmedDetail(detail, arms) {
213
315
  if (detail === null || typeof detail !== "object" || Array.isArray(detail))
214
316
  return detail;
215
317
  const d = detail;
216
318
  const kind = d.kind;
217
- const arm = typeof kind === "string" && Object.hasOwn(TERMINAL_FAILURE_DETAIL_TREATMENT, kind) ? TERMINAL_FAILURE_DETAIL_TREATMENT[kind] : {};
319
+ const arm = typeof kind === "string" && Object.hasOwn(arms, kind) ? arms[kind] : {};
218
320
  let out;
219
321
  for (const key of Object.keys(d)) {
220
322
  const v = d[key];
@@ -237,7 +339,7 @@ function shapeTerminalFailureDetail(detail) {
237
339
  }
238
340
  default: {
239
341
  const unhandled = treatment;
240
- throw new Error(`unhandled failure-detail treatment: ${String(unhandled)}`);
342
+ throw new Error(`unhandled detail-member treatment: ${String(unhandled)}`);
241
343
  }
242
344
  }
243
345
  }
@@ -282,153 +384,60 @@ function shapeTerminalBlockedDetail(detail) {
282
384
  }
283
385
  return out ?? detail;
284
386
  }
285
- const PROVIDER_ECHO_SHAPERS = {
286
- responseModel: (v) => (admitProviderEcho(v, "responseModel") ? v : undefined),
287
- apiFailure: (v) => shapeEchoMembers(v, API_FAILURE_TREATMENT, "apiFailure"),
288
- strandedHumanAnswers: (v) => shapeEchoRows(v, STRANDED_ANSWER_TREATMENT, "strandedHumanAnswers[]"),
289
- };
290
- {
291
- const judged = Object.entries(RESULT_KEY_TREATMENT).filter(([, t]) => t === "provider-echo").map(([k]) => k).sort();
292
- const wired = Object.keys(PROVIDER_ECHO_SHAPERS).sort();
293
- if (judged.join(",") !== wired.join(","))
294
- throw new Error(`run-terminal: provider-echo classification [${judged.join(",")}] ≠ shaper table [${wired.join(",")}]`);
295
- }
296
387
  const LEGACY_RESULT_LEAVES = ["errorMessage", "blockedReason", "checkpointGate"];
297
388
  export const TREATED_RESULT_LEAVES = [
298
389
  ...new Set([
299
- ...Object.entries(RESULT_KEY_TREATMENT).filter(([, t]) => t !== "verbatim").map(([k]) => k),
390
+ ...ACTIVE_TEXT_LEAVES.map((row) => row.segments[0]),
300
391
  ...LEGACY_RESULT_LEAVES,
301
392
  ...PAUSE_SEATS.map((seat) => seat.path[0]),
393
+ "editedFiles",
302
394
  ]),
303
395
  ];
304
396
  export function redactTerminalResult(result) {
305
397
  if (result === undefined || result === null)
306
398
  return result;
307
- const r = result;
308
- let changed = false;
309
- const out = { ...r };
310
- if (typeof r.errorMessage === "string") {
311
- out.errorMessage = redactErrorMessage(r.errorMessage);
312
- changed = true;
313
- }
314
- if (typeof r.blockedReason === "string") {
315
- out.blockedReason = redactErrorMessage(r.blockedReason);
316
- changed = true;
317
- }
318
- if (r.checkpointGate !== undefined) {
319
- const legacyGate = redactCheckpointGate(r.checkpointGate);
320
- if (legacyGate !== r.checkpointGate) {
321
- out.checkpointGate = legacyGate;
322
- changed = true;
323
- }
324
- }
325
- if (r.terminal !== null && typeof r.terminal === "object") {
326
- const t = r.terminal;
327
- let nt;
328
- if (t.kind === "failed" && typeof t.message === "string")
329
- nt = { ...t, message: redactErrorMessage(t.message) };
330
- else if (t.kind === "blocked" && typeof t.reason === "string")
331
- nt = { ...t, reason: redactErrorMessage(t.reason) };
332
- if (t.kind === "blocked") {
333
- const cur = nt ?? t;
334
- const detail = cur.detail;
335
- const shaped = shapeTerminalBlockedDetail(detail);
336
- if (shaped !== detail)
337
- nt = { ...cur, detail: shaped };
338
- }
339
- const base = nt ?? t;
340
- if (t.kind === "failed") {
341
- const cur = nt ?? base;
342
- const detail = cur.detail;
343
- const shaped = shapeTerminalFailureDetail(detail);
344
- if (shaped !== detail)
345
- nt = { ...cur, detail: shaped };
346
- }
347
- if (nt !== undefined) {
348
- out.terminal = nt;
349
- changed = true;
350
- }
351
- }
352
- const gated = mapPauseSeats(out, (seat, keys) => {
399
+ return redactLegacyPlaneLeaves(redactPauseSeatGates(applyResultTextLeaves(capEditedFiles(result))));
400
+ }
401
+ function capEditedFiles(result) {
402
+ const files = result.editedFiles;
403
+ if (!Array.isArray(files) || files.length <= MAX_EDITED_FILES)
404
+ return result;
405
+ return { ...result, editedFiles: files.slice(0, MAX_EDITED_FILES) };
406
+ }
407
+ function redactPauseSeatGates(result) {
408
+ return mapPauseSeats(result, (seat, keys) => {
353
409
  if (!Object.hasOwn(seat, keys.gate))
354
410
  return seat;
355
411
  const g = seat[keys.gate];
356
412
  const ng = redactCheckpointGate(g);
357
413
  return ng === g ? seat : { ...seat, [keys.gate]: ng };
358
414
  });
359
- if (gated !== out) {
360
- Object.assign(out, gated);
361
- changed = true;
362
- }
363
- if (r.remoteEnvFailures !== undefined) {
364
- out.remoteEnvFailures = Array.isArray(r.remoteEnvFailures)
365
- ? r.remoteEnvFailures.map((f) => (f && typeof f === "object" && typeof f.message === "string" ? { ...f, message: redactErrorMessage(f.message) } : f))
366
- : r.remoteEnvFailures;
367
- changed = true;
368
- }
369
- if (r.editedFiles !== undefined) {
370
- out.editedFiles = Array.isArray(r.editedFiles)
371
- ? r.editedFiles
372
- .slice(0, MAX_EDITED_FILES)
373
- .map((f) => {
374
- if (f === null || typeof f !== "object")
375
- return f;
376
- const path = f.path;
377
- return typeof path === "string" ? { ...f, path: redactSecrets(path) } : f;
378
- })
379
- : r.editedFiles;
380
- changed = true;
381
- }
382
- if (typeof r.result === "string") {
383
- const next = redactModelText(r.result);
384
- if (next !== r.result) {
385
- out.result = next;
386
- changed = true;
387
- }
388
- }
389
- if (typeof r.salvagedOutput === "string") {
390
- const next = redactModelText(r.salvagedOutput);
391
- if (next !== r.salvagedOutput) {
392
- out.salvagedOutput = next;
393
- changed = true;
394
- }
415
+ }
416
+ function redactLegacyPlaneLeaves(result) {
417
+ const r = result;
418
+ let out;
419
+ if (typeof r.errorMessage === "string") {
420
+ const next = redactErrorMessage(r.errorMessage);
421
+ if (next !== r.errorMessage)
422
+ (out ??= { ...result }).errorMessage = next;
395
423
  }
396
- if (r.rewindNotes !== undefined) {
397
- out.rewindNotes = Array.isArray(r.rewindNotes)
398
- ? r.rewindNotes.map((n) => {
399
- if (n === null || typeof n !== "object")
400
- return n;
401
- const message = n.message;
402
- return typeof message === "string" ? { ...n, message: redactErrorMessage(message) } : n;
403
- })
404
- : r.rewindNotes;
405
- changed = true;
406
- }
407
- if (r.stats !== undefined) {
408
- const next = redactStats(r.stats);
409
- if (next !== r.stats) {
410
- out.stats = next;
411
- changed = true;
412
- }
424
+ if (typeof r.blockedReason === "string") {
425
+ const next = redactErrorMessage(r.blockedReason);
426
+ if (next !== r.blockedReason)
427
+ (out ??= { ...result }).blockedReason = next;
413
428
  }
414
- const rr = result;
415
- for (const [key, shape] of Object.entries(PROVIDER_ECHO_SHAPERS)) {
416
- const v = rr[key];
417
- if (v === undefined || shape === undefined)
418
- continue;
419
- const next = shape(v);
420
- if (next === v)
421
- continue;
422
- if (next === undefined)
423
- delete out[key];
424
- else
425
- out[key] = next;
426
- changed = true;
429
+ if (r.checkpointGate !== undefined) {
430
+ const next = redactCheckpointGate(r.checkpointGate);
431
+ if (next !== r.checkpointGate)
432
+ (out ??= { ...result }).checkpointGate = next;
427
433
  }
428
- return changed ? out : result;
434
+ return out === undefined ? result : out;
435
+ }
436
+ export function sealRunRowResult(result) {
437
+ return result === null ? null : redactTerminalResult(sealResultForExit(result));
429
438
  }
430
- export function sealRunRowResult(result, readSeat) {
431
- return result === null ? null : redactTerminalResult(sealResultForExit(result, readSeat));
439
+ export function sealStoredRunRowResult(result, seat) {
440
+ return result === null ? null : redactTerminalResult(sealStoredResult(result, seat));
432
441
  }
433
442
  export function redactLedgerEventData(type, data) {
434
443
  if (data === null || typeof data !== "object" || Array.isArray(data))
@@ -897,7 +906,7 @@ export function memoRedactedRead(seat, raw, redact) {
897
906
  export function memoRedactTerminalResult(seat, raw) {
898
907
  if (raw === undefined || raw === null)
899
908
  return raw;
900
- const result = sealResultForExit(raw, seat);
909
+ const result = sealStoredResult(raw, seat);
901
910
  const r = result;
902
911
  if (TREATED_RESULT_LEAVES.every((k) => r[k] === undefined))
903
912
  return result;
@@ -46,10 +46,9 @@ export interface WorkflowCompletionInbox {
46
46
  * the ownerless fence silently starved the new claimant's push). Omitted `purgedOwner` = conservative
47
47
  * fence-all (an ownerless caller can't distinguish). */
48
48
  purge(sessionId: string, purgedOwner?: string | null): Promise<void>;
49
- /** The originating session OBSERVED this run's terminal state through a model-facing poll
50
- * (core 1.232 `WorkflowCompletionNotifier.ackServed` fires this), so the push would be
51
- * a pure duplicate ("poll-then-also-notify" double delivery: the model burns turns dismissing a completion
52
- * it already summarized). Drops the pending entry (a deliberate ack) AND arms a {@link SERVED_FENCE_MS}
49
+ /** The originating session already OBSERVED this run's terminal state on another delivery (the fleet bus's
50
+ * task-notification fold acks the family it delivered), so the push would be a pure duplicate (double
51
+ * delivery: the model burns turns dismissing a completion it already summarized). Drops the pending entry (a deliberate ack) AND arms a {@link SERVED_FENCE_MS}
53
52
  * enqueue fence for this (session, runId) so a LATE-arriving notify (the notifier races the poll) is
54
53
  * dropped too. Fence is in-memory only — a crash between poll and notify re-delivers (at-least-once; the
55
54
  * shell's own runId dedup + the model tolerate it), mirroring the purge fence's restart posture. */
@@ -147,7 +146,7 @@ export declare class InMemoryWorkflowCompletionInbox implements WorkflowCompleti
147
146
  * refused. Swept on BOTH enqueue and purge (a purge-heavy, enqueue-quiet process must not accumulate
148
147
  * stamps unboundedly — review). */
149
148
  private readonly purgedAt;
150
- /** servedKey(sessionId, runId) → stamp: terminal-poll-served fences; an enqueue for the pair within
149
+ /** servedKey(sessionId, runId) → stamp: served fences; an enqueue for the pair within
151
150
  * {@link SERVED_FENCE_MS} is refused (the poll already told the model). Swept alongside the purge fence. */
152
151
  private readonly servedAt;
153
152
  constructor(onWarn?: ((msg: string, meta: Record<string, unknown>) => void) | undefined);
@@ -323,7 +322,7 @@ export declare function externalNotificationInboxEntry(sessionId: string, owner:
323
322
  * UNTRUSTED free text). `status` collapses onto the inbox's completed|failed column; the ORIGINAL status rides
324
323
  * the payload extras and overrides on drain (killed/cancelled reach the shell verbatim). Workflow-type
325
324
  * notifications are the CALLER's job to filter (they have their own durable chain — double-enqueueing here would
326
- * re-open the poll-served double-push). External notifications enter through {@link externalNotificationInboxEntry}.
325
+ * deliver the same completion twice). External notifications enter through {@link externalNotificationInboxEntry}.
327
326
  */
328
327
  export declare function taskNotificationInboxEntry(sessionId: string, owner: string | null, n: EngineNotificationParkInput, enqueuedAt: number,
329
328
  /** lead-b (dual-ID audit): the PARENT run's durable taskId (the uuid the shell's footer rows
@@ -372,18 +371,5 @@ export declare function resolveCompletionRoute(p: {
372
371
  sessionId: string;
373
372
  owner: string | null;
374
373
  } | undefined>;
375
- /**
376
- * core 1.232 — resolve WHICH session's inbox entry a poll-served ack targets: the payload's
377
- * `originatingSessionId` directly (core threads it on `ackServed`), else the originating run row via
378
- * `sourceTaskId` (mirrors {@link resolveCompletionRoute}'s session half — same fallback, same reason:
379
- * older runs may predate the lookup-free field). Returns undefined when there is no attribution — the
380
- * entry stays pending (at-least-once; the shell's own dedup covers a rare duplicate).
381
- */
382
- export declare function resolveServedSession(p: {
383
- originatingSessionId?: string;
384
- sourceTaskId?: string;
385
- }, getRun?: (taskId: string) => Promise<{
386
- sessionId?: string | null;
387
- } | undefined | null>): Promise<string | undefined>;
388
374
  export {};
389
375
  //# sourceMappingURL=workflow-completion-inbox.d.ts.map
@@ -429,16 +429,4 @@ export async function resolveCompletionRoute(p, getRun, requirePrincipal) {
429
429
  }
430
430
  return { sessionId, owner };
431
431
  }
432
- export async function resolveServedSession(p, getRun) {
433
- if (p.originatingSessionId)
434
- return p.originatingSessionId;
435
- if (p.sourceTaskId && getRun) {
436
- try {
437
- return (await getRun(p.sourceTaskId))?.sessionId ?? undefined;
438
- }
439
- catch {
440
- }
441
- }
442
- return undefined;
443
- }
444
432
  //# sourceMappingURL=workflow-completion-inbox.js.map