@sema-agent/core 7.67.2 → 7.68.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 (505) hide show
  1. package/CHANGELOG.md +1533 -0
  2. package/README.md +18 -9
  3. package/README.zh-CN.md +16 -8
  4. package/dist/agents/agent-definition.d.ts +1 -1
  5. package/dist/agents/agent-definition.js +4 -1
  6. package/dist/agents/cascade.d.ts +2 -2
  7. package/dist/agents/cascade.js +3 -1
  8. package/dist/agents/cumulative-stats.d.ts +2 -1
  9. package/dist/agents/cumulative-stats.js +4 -1
  10. package/dist/agents/list-agents-tool.d.ts +30 -0
  11. package/dist/agents/list-agents-tool.js +45 -3
  12. package/dist/agents/peer-admission.d.ts +2 -2
  13. package/dist/agents/peer-session-drain.d.ts +2 -0
  14. package/dist/agents/peer-session-drain.js +1 -0
  15. package/dist/agents/repair-loop.js +3 -1
  16. package/dist/agents/retain-ledger.d.ts +61 -8
  17. package/dist/agents/retain-ledger.js +25 -3
  18. package/dist/agents/roster-store.d.ts +4 -2
  19. package/dist/agents/send-message-tool.d.ts +1 -1
  20. package/dist/agents/send-message-tool.js +20 -15
  21. package/dist/agents/subagent-steps.js +2 -10
  22. package/dist/agents/subagent.d.ts +3 -0
  23. package/dist/agents/subagent.js +106 -76
  24. package/dist/agents/tool-filter.d.ts +20 -11
  25. package/dist/agents/tool-filter.js +8 -4
  26. package/dist/agents/verify.d.ts +3 -1
  27. package/dist/agents/verify.js +2 -0
  28. package/dist/brain/anthropic.js +4 -4
  29. package/dist/brain/errors.d.ts +20 -0
  30. package/dist/brain/errors.js +114 -0
  31. package/dist/brain/open-responses.js +3 -1
  32. package/dist/brain/openai.js +3 -1
  33. package/dist/brain/provider-message.d.ts +5 -3
  34. package/dist/brain/provider-message.js +35 -8
  35. package/dist/brain/reasoning-request.d.ts +73 -19
  36. package/dist/brain/reasoning-request.js +164 -72
  37. package/dist/brain/reasoning-stamp.d.ts +26 -0
  38. package/dist/brain/reasoning-stamp.js +10 -0
  39. package/dist/brain/reasoning.d.ts +95 -162
  40. package/dist/brain/reasoning.js +31 -86
  41. package/dist/brain/route-adjudicator.d.ts +9 -7
  42. package/dist/brain/route-adjudicator.js +12 -10
  43. package/dist/brain/status-sink.d.ts +19 -64
  44. package/dist/brain/status-sink.js +5 -21
  45. package/dist/brain/stream-engine.d.ts +11 -2
  46. package/dist/brain/stream-engine.js +10 -0
  47. package/dist/core/a2a.d.ts +17 -5
  48. package/dist/core/a2a.js +11 -3
  49. package/dist/core/allow-entry.d.ts +35 -15
  50. package/dist/core/allow-entry.js +47 -60
  51. package/dist/core/ask-headline.d.ts +68 -0
  52. package/dist/core/ask-headline.js +23 -0
  53. package/dist/core/ask-origin.d.ts +36 -8
  54. package/dist/core/ask-origin.js +17 -10
  55. package/dist/core/ask-question.d.ts +34 -7
  56. package/dist/core/ask-question.js +10 -1
  57. package/dist/core/ask-unresolvable-notice.d.ts +7 -0
  58. package/dist/core/ask-unresolvable-notice.js +9 -3
  59. package/dist/core/auto-strip.d.ts +53 -0
  60. package/dist/core/auto-strip.js +76 -0
  61. package/dist/core/background-agent-store.d.ts +45 -5
  62. package/dist/core/background-agent-store.js +69 -15
  63. package/dist/core/background-shell.d.ts +2 -2
  64. package/dist/core/caller-text.js +2 -2
  65. package/dist/core/canonical-json.d.ts +13 -0
  66. package/dist/core/canonical-json.js +7 -0
  67. package/dist/core/checkpoint-features.d.ts +66 -20
  68. package/dist/core/checkpoint-features.js +12 -1
  69. package/dist/core/checkpoint-generation.d.ts +1 -1
  70. package/dist/core/checkpoint-queries.d.ts +1 -1
  71. package/dist/core/checkpoint-queries.js +4 -1
  72. package/dist/core/checkpoint-requirements.d.ts +25 -1
  73. package/dist/core/checkpoint-requirements.js +5 -1
  74. package/dist/core/checkpoint-row-verdict.d.ts +1 -0
  75. package/dist/core/checkpoint-row-verdict.js +4 -0
  76. package/dist/core/checkpoint-store.d.ts +66 -38
  77. package/dist/core/checkpoint-store.js +15 -6
  78. package/dist/core/child-clamp-seats.d.ts +6 -0
  79. package/dist/core/child-clamp-seats.js +1 -0
  80. package/dist/core/config-refusal-codes.d.ts +1 -1
  81. package/dist/core/config-refusal-codes.js +1 -0
  82. package/dist/core/delegation-frames.d.ts +9 -12
  83. package/dist/core/delegation-frames.js +9 -8
  84. package/dist/core/engine-capabilities.d.ts +21 -8
  85. package/dist/core/engine-capabilities.js +1 -1
  86. package/dist/core/engine-notice.d.ts +147 -34
  87. package/dist/core/engine-notice.js +27 -16
  88. package/dist/core/engine-storage-backend.d.ts +2 -1
  89. package/dist/core/env-budget.js +3 -3
  90. package/dist/core/env-knob-announce.d.ts +10 -10
  91. package/dist/core/env-knob-announce.js +3 -6
  92. package/dist/core/file-history-store.d.ts +29 -4
  93. package/dist/core/file-history-store.js +13 -0
  94. package/dist/core/frame-settlement.d.ts +2 -1
  95. package/dist/core/gate-fold.js +1 -1
  96. package/dist/core/gate-lanes.js +56 -49
  97. package/dist/core/governance-codes.d.ts +39 -3
  98. package/dist/core/governance-codes.js +61 -3
  99. package/dist/core/hooks.d.ts +29 -11
  100. package/dist/core/hooks.js +5 -2
  101. package/dist/core/human-input-projection.js +3 -3
  102. package/dist/core/input-author.d.ts +17 -3
  103. package/dist/core/input-author.js +15 -3
  104. package/dist/core/leg-identity.d.ts +10 -28
  105. package/dist/core/leg-identity.js +1 -21
  106. package/dist/core/lsp.d.ts +18 -13
  107. package/dist/core/lsp.js +30 -22
  108. package/dist/core/mailbox-store.d.ts +1 -1
  109. package/dist/core/mailbox-store.js +4 -4
  110. package/dist/core/mcp-connection-pool.d.ts +93 -4
  111. package/dist/core/mcp-connection-pool.js +104 -1
  112. package/dist/core/mcp-failure.d.ts +38 -12
  113. package/dist/core/mcp-failure.js +9 -13
  114. package/dist/core/mcp-probe.d.ts +4 -3
  115. package/dist/core/mcp-server-link.d.ts +4 -2
  116. package/dist/core/mcp-server-link.js +4 -5
  117. package/dist/core/mcp-server-spec.d.ts +3 -3
  118. package/dist/core/mcp-server-unavailable-notice.d.ts +22 -8
  119. package/dist/core/mcp-server-unavailable-notice.js +18 -4
  120. package/dist/core/mcp.d.ts +40 -6
  121. package/dist/core/mcp.js +39 -13
  122. package/dist/core/memory-engine/content-origin.js +2 -2
  123. package/dist/core/memory-engine/control-objects.d.ts +2 -4
  124. package/dist/core/memory-engine/control-objects.js +2 -10
  125. package/dist/core/memory-engine/delegation-settlement.js +6 -1
  126. package/dist/core/memory-engine/dual-root.js +3 -0
  127. package/dist/core/memory-engine/engine.d.ts +6 -4
  128. package/dist/core/memory-engine/engine.js +32 -29
  129. package/dist/core/memory-engine/file-backend.d.ts +20 -5
  130. package/dist/core/memory-engine/file-backend.js +21 -31
  131. package/dist/core/memory-engine/frontmatter.d.ts +2 -0
  132. package/dist/core/memory-engine/frontmatter.js +4 -0
  133. package/dist/core/memory-engine/layout.d.ts +114 -20
  134. package/dist/core/memory-engine/layout.js +340 -22
  135. package/dist/core/memory-engine/memory-deployment.d.ts +7 -5
  136. package/dist/core/memory-engine/mount-failed-notice.d.ts +19 -7
  137. package/dist/core/memory-engine/mount-failed-notice.js +43 -10
  138. package/dist/core/memory-engine/sync-client.js +4 -5
  139. package/dist/core/model-fallbacks.d.ts +5 -1
  140. package/dist/core/model-fallbacks.js +3 -3
  141. package/dist/core/model-receipt.d.ts +2 -1
  142. package/dist/core/model-receipt.js +12 -1
  143. package/dist/core/mods/kernel/dispatch.d.ts +2 -2
  144. package/dist/core/mods/kernel/dispatch.js +14 -6
  145. package/dist/core/mods/kernel/events.d.ts +8 -5
  146. package/dist/core/mods/kernel/events.js +2 -2
  147. package/dist/core/mods/kernel/index.d.ts +1 -1
  148. package/dist/core/mods/kernel/registration.d.ts +9 -0
  149. package/dist/core/mods/package.js +1 -1
  150. package/dist/core/mods/session-append.d.ts +4 -2
  151. package/dist/core/mods/session-append.js +3 -0
  152. package/dist/core/mods/stations.d.ts +7 -11
  153. package/dist/core/mods/stations.js +4 -7
  154. package/dist/core/mods/tool-call.d.ts +10 -8
  155. package/dist/core/mods/tool-call.js +15 -18
  156. package/dist/core/mounted-mcp.d.ts +0 -4
  157. package/dist/core/mounted-mcp.js +1 -1
  158. package/dist/core/park-noun.d.ts +24 -0
  159. package/dist/core/park-noun.js +21 -0
  160. package/dist/core/park-resumability.d.ts +60 -0
  161. package/dist/core/park-resumability.js +30 -0
  162. package/dist/core/permission-rule-provider.d.ts +24 -2
  163. package/dist/core/permission-rule-provider.js +11 -8
  164. package/dist/core/permission-rule-store.d.ts +8 -1
  165. package/dist/core/permission-rule-store.js +2 -3
  166. package/dist/core/permission-rules.d.ts +2 -1
  167. package/dist/core/permission-rules.js +8 -4
  168. package/dist/core/persisted-rule-arms.d.ts +3 -0
  169. package/dist/core/persisted-rule-arms.js +2 -1
  170. package/dist/core/present-plan-tool.d.ts +47 -3
  171. package/dist/core/present-plan-tool.js +62 -4
  172. package/dist/core/principal-name.d.ts +1 -1
  173. package/dist/core/principal-name.js +5 -5
  174. package/dist/core/process-identity.js +10 -5
  175. package/dist/core/protocol-http-auth.d.ts +30 -9
  176. package/dist/core/protocol-http-auth.js +113 -59
  177. package/dist/core/read-only-shell.js +9 -5
  178. package/dist/core/redaction-marks.d.ts +4 -26
  179. package/dist/core/redaction-marks.js +9 -21
  180. package/dist/core/remote-env.d.ts +43 -16
  181. package/dist/core/remote-env.js +1 -1
  182. package/dist/core/request-copy-projection.d.ts +1 -1
  183. package/dist/core/request-copy-projection.js +40 -50
  184. package/dist/core/resume-config-judge.js +1 -1
  185. package/dist/core/resume-startup-cause.d.ts +35 -18
  186. package/dist/core/resume-startup-cause.js +13 -10
  187. package/dist/core/retention.d.ts +167 -25
  188. package/dist/core/retention.js +100 -20
  189. package/dist/core/roles.d.ts +6 -0
  190. package/dist/core/roles.js +11 -5
  191. package/dist/core/rule-lane-reads.d.ts +3 -0
  192. package/dist/core/rule-lane-reads.js +5 -1
  193. package/dist/core/rule-store-fault.d.ts +70 -0
  194. package/dist/core/rule-store-fault.js +102 -0
  195. package/dist/core/runner/advertised-writable-dirs.js +16 -31
  196. package/dist/core/runner/announce-once-ledger.d.ts +19 -2
  197. package/dist/core/runner/announce-once-ledger.js +24 -2
  198. package/dist/core/runner/assemble-result.d.ts +6 -0
  199. package/dist/core/runner/assemble-result.js +1 -1
  200. package/dist/core/runner/auto-strip-notice.d.ts +36 -0
  201. package/dist/core/runner/auto-strip-notice.js +59 -0
  202. package/dist/core/runner/branch-window.d.ts +3 -0
  203. package/dist/core/runner/branch-window.js +37 -0
  204. package/dist/core/runner/caller-roster.d.ts +8 -3
  205. package/dist/core/runner/capability-withheld-seat.js +3 -9
  206. package/dist/core/runner/clock-and-limits.d.ts +22 -1
  207. package/dist/core/runner/clock-and-limits.js +30 -0
  208. package/dist/core/runner/contracts.d.ts +58 -35
  209. package/dist/core/runner/credential-refusal-seat.d.ts +2 -0
  210. package/dist/core/runner/credential-refusal-seat.js +47 -0
  211. package/dist/core/runner/cross-boundary-lane.js +6 -4
  212. package/dist/core/runner/decide-continuation.js +1 -1
  213. package/dist/core/runner/file-history-restore.d.ts +53 -2
  214. package/dist/core/runner/file-history-restore.js +29 -10
  215. package/dist/core/runner/forward-sink.d.ts +14 -1
  216. package/dist/core/runner/forward-sink.js +14 -12
  217. package/dist/core/runner/gate-exit.d.ts +8 -7
  218. package/dist/core/runner/gate-exit.js +13 -13
  219. package/dist/core/runner/git-status-frame.js +2 -4
  220. package/dist/core/runner/initial-run-state.js +1 -1
  221. package/dist/core/runner/main-call-account.d.ts +3 -1
  222. package/dist/core/runner/main-call-account.js +5 -3
  223. package/dist/core/runner/mcp-redial.d.ts +2 -5
  224. package/dist/core/runner/mcp-redial.js +2 -2
  225. package/dist/core/runner/nested-memory-content.d.ts +7 -1
  226. package/dist/core/runner/nested-memory-content.js +73 -13
  227. package/dist/core/runner/nested-memory-lane.d.ts +44 -19
  228. package/dist/core/runner/nested-memory-lane.js +152 -76
  229. package/dist/core/runner/park-commit.js +3 -1
  230. package/dist/core/runner/permission-rule-lanes.d.ts +8 -2
  231. package/dist/core/runner/permission-rule-lanes.js +29 -3
  232. package/dist/core/runner/person-path-rows.d.ts +3 -11
  233. package/dist/core/runner/person-path-rows.js +21 -24
  234. package/dist/core/runner/prepare-acquire-reconcile.js +3 -1
  235. package/dist/core/runner/prepare-artifact.d.ts +1 -1
  236. package/dist/core/runner/prepare-artifact.js +20 -14
  237. package/dist/core/runner/prepare-ask-lane.d.ts +9 -6
  238. package/dist/core/runner/prepare-ask-lane.js +6 -5
  239. package/dist/core/runner/prepare-boundary-parks.d.ts +7 -1
  240. package/dist/core/runner/prepare-boundary-parks.js +27 -24
  241. package/dist/core/runner/prepare-caps-and-workflow.d.ts +5 -2
  242. package/dist/core/runner/prepare-caps-and-workflow.js +4 -3
  243. package/dist/core/runner/prepare-config-doors.d.ts +9 -24
  244. package/dist/core/runner/prepare-config-doors.js +58 -41
  245. package/dist/core/runner/prepare-context-lane.d.ts +2 -2
  246. package/dist/core/runner/prepare-context-lane.js +3 -5
  247. package/dist/core/runner/prepare-defer-classify.d.ts +1 -1
  248. package/dist/core/runner/prepare-defer-classify.js +1 -1
  249. package/dist/core/runner/prepare-delegation-surface.d.ts +2 -2
  250. package/dist/core/runner/prepare-delegation-surface.js +3 -2
  251. package/dist/core/runner/prepare-file-history.d.ts +62 -26
  252. package/dist/core/runner/prepare-file-history.js +117 -46
  253. package/dist/core/runner/prepare-gate-stations.d.ts +4 -0
  254. package/dist/core/runner/prepare-gate-stations.js +6 -5
  255. package/dist/core/runner/prepare-hands-readface.d.ts +9 -4
  256. package/dist/core/runner/prepare-hands-readface.js +8 -4
  257. package/dist/core/runner/prepare-inherited-gate.d.ts +11 -4
  258. package/dist/core/runner/prepare-inherited-gate.js +6 -6
  259. package/dist/core/runner/prepare-listings.d.ts +1 -1
  260. package/dist/core/runner/prepare-listings.js +1 -1
  261. package/dist/core/runner/prepare-memory.js +2 -2
  262. package/dist/core/runner/prepare-offload-wrappers.d.ts +1 -1
  263. package/dist/core/runner/prepare-offload-wrappers.js +1 -1
  264. package/dist/core/runner/prepare-park-ask.d.ts +10 -3
  265. package/dist/core/runner/prepare-park-ask.js +7 -9
  266. package/dist/core/runner/prepare-policy-chain.d.ts +18 -9
  267. package/dist/core/runner/prepare-policy-chain.js +18 -13
  268. package/dist/core/runner/prepare-project-context.d.ts +1 -1
  269. package/dist/core/runner/prepare-project-context.js +5 -3
  270. package/dist/core/runner/prepare-prompt-assembly.js +2 -1
  271. package/dist/core/runner/prepare-prompt-inputs.d.ts +2 -2
  272. package/dist/core/runner/prepare-prompt-inputs.js +1 -1
  273. package/dist/core/runner/prepare-protocol-tools.d.ts +4 -5
  274. package/dist/core/runner/prepare-protocol-tools.js +7 -7
  275. package/dist/core/runner/prepare-question-face.d.ts +4 -2
  276. package/dist/core/runner/prepare-run-refs.d.ts +7 -2
  277. package/dist/core/runner/prepare-run-refs.js +8 -7
  278. package/dist/core/runner/prepare-safety-scan.d.ts +4 -3
  279. package/dist/core/runner/prepare-suspend-saga.d.ts +3 -7
  280. package/dist/core/runner/prepare-suspend-saga.js +4 -3
  281. package/dist/core/runner/prepare-task.js +66 -53
  282. package/dist/core/runner/prepare-tool-disclosure-mount.d.ts +3 -2
  283. package/dist/core/runner/prepare-tool-disclosure-mount.js +2 -1
  284. package/dist/core/runner/prepare-turn-wiring.d.ts +3 -1
  285. package/dist/core/runner/prepare-turn-wiring.js +1 -1
  286. package/dist/core/runner/prepare-wiring-manifest.d.ts +9 -4
  287. package/dist/core/runner/prepare-wiring-manifest.js +14 -6
  288. package/dist/core/runner/prepare-workspace-restore.d.ts +4 -4
  289. package/dist/core/runner/prepare-workspace-restore.js +15 -6
  290. package/dist/core/runner/remote-env-retry.d.ts +3 -3
  291. package/dist/core/runner/restore-seat.d.ts +41 -0
  292. package/dist/core/runner/restore-seat.js +38 -0
  293. package/dist/core/runner/resume-admission.js +1 -1
  294. package/dist/core/runner/resume-apply.js +4 -3
  295. package/dist/core/runner/resume-checkpoint-screen.js +2 -1
  296. package/dist/core/runner/resume-internals-and-config.js +2 -1
  297. package/dist/core/runner/resume-preflight.js +2 -1
  298. package/dist/core/runner/rewind-files.js +22 -6
  299. package/dist/core/runner/rule-store-unreadable-notice.d.ts +8 -0
  300. package/dist/core/runner/rule-store-unreadable-notice.js +11 -0
  301. package/dist/core/runner/run-brain-sinks.d.ts +3 -6
  302. package/dist/core/runner/run-brain-sinks.js +6 -6
  303. package/dist/core/runner/run-compaction-machinery.d.ts +2 -2
  304. package/dist/core/runner/run-git-lane.d.ts +2 -0
  305. package/dist/core/runner/run-git-lane.js +2 -1
  306. package/dist/core/runner/run-harness-handlers.js +5 -4
  307. package/dist/core/runner/run-identity-wiring.js +20 -12
  308. package/dist/core/runner/run-leg.js +31 -72
  309. package/dist/core/runner/run-notification-lane.d.ts +3 -0
  310. package/dist/core/runner/run-notification-lane.js +2 -4
  311. package/dist/core/runner/run-reasoning-seat.d.ts +5 -6
  312. package/dist/core/runner/run-reasoning-seat.js +13 -18
  313. package/dist/core/runner/run-settle-and-teardown.js +13 -9
  314. package/dist/core/runner/run-terminal-adoption.js +4 -8
  315. package/dist/core/runner/run-turn-boundary.js +6 -3
  316. package/dist/core/runner/runtask.d.ts +9 -4
  317. package/dist/core/runner/runtask.js +29 -22
  318. package/dist/core/runner/session-rule-policy.d.ts +11 -1
  319. package/dist/core/runner/shell-env-withheld.js +2 -7
  320. package/dist/core/runner/side-call-account.d.ts +5 -6
  321. package/dist/core/runner/side-call-account.js +2 -2
  322. package/dist/core/runner/stream-lifecycle-verbs.d.ts +3 -0
  323. package/dist/core/runner/stream-lifecycle-verbs.js +5 -3
  324. package/dist/core/runner/stream-settle-backstop.js +4 -6
  325. package/dist/core/runner/stream-steer-verb.d.ts +1 -1
  326. package/dist/core/runner/stream-steer-verb.js +4 -4
  327. package/dist/core/runner/sub-agent-deny-lists.d.ts +8 -3
  328. package/dist/core/runner/sub-agent-deny-lists.js +7 -4
  329. package/dist/core/runner/teardown-bounded.d.ts +7 -0
  330. package/dist/core/runner/teardown-bounded.js +7 -0
  331. package/dist/core/runner/terminal-account.js +41 -13
  332. package/dist/core/runner/terminal-projection.d.ts +1 -5
  333. package/dist/core/runner/tool-end-body.d.ts +9 -3
  334. package/dist/core/runner/tool-end-body.js +6 -3
  335. package/dist/core/runner/tool-output-projection.d.ts +13 -4
  336. package/dist/core/runner/tool-output-projection.js +10 -14
  337. package/dist/core/runner/turn-attachments.d.ts +3 -2
  338. package/dist/core/runner/turn-attachments.js +12 -5
  339. package/dist/core/runner-deps.d.ts +6 -6
  340. package/dist/core/runtime-caps.d.ts +2 -1
  341. package/dist/core/secret-env.d.ts +20 -3
  342. package/dist/core/secret-env.js +13 -15
  343. package/dist/core/session-checkout.d.ts +115 -15
  344. package/dist/core/session-checkout.js +435 -136
  345. package/dist/core/session-policy-store.js +21 -3
  346. package/dist/core/session-reconcile.js +1 -0
  347. package/dist/core/session-store.js +2 -0
  348. package/dist/core/session.d.ts +11 -1
  349. package/dist/core/shell-run-candidates.d.ts +1 -0
  350. package/dist/core/shell-run-candidates.js +1 -1
  351. package/dist/core/shutdown-debug.d.ts +6 -5
  352. package/dist/core/shutdown-debug.js +5 -1
  353. package/dist/core/skill-grant.js +4 -1
  354. package/dist/core/skills-directory.js +5 -3
  355. package/dist/core/spec-contract.d.ts +1 -1
  356. package/dist/core/store-contracts/checkpoint-store-contract.js +2 -7
  357. package/dist/core/store-contracts/file-history-store-contract.js +26 -2
  358. package/dist/core/store-contracts/session-deletion-cascade-contract.js +130 -14
  359. package/dist/core/store-contracts/task-list-store-contract.d.ts +2 -1
  360. package/dist/core/store-contracts/task-list-store-contract.js +28 -1
  361. package/dist/core/task-event.d.ts +48 -27
  362. package/dist/core/task-notification.d.ts +15 -9
  363. package/dist/core/task-notification.js +12 -0
  364. package/dist/core/task-registry-agent.d.ts +24 -22
  365. package/dist/core/task-registry-agent.js +65 -46
  366. package/dist/core/task-registry-shared.d.ts +17 -5
  367. package/dist/core/task-registry.d.ts +17 -6
  368. package/dist/core/task-registry.js +6 -1
  369. package/dist/core/task-result.d.ts +71 -25
  370. package/dist/core/task-spec-members.d.ts +0 -1
  371. package/dist/core/task-spec-members.js +1 -1
  372. package/dist/core/task-spec.d.ts +60 -52
  373. package/dist/core/task-stream.d.ts +45 -12
  374. package/dist/core/terminal-cause.d.ts +45 -8
  375. package/dist/core/terminal-cause.js +5 -0
  376. package/dist/core/tool-card-bound.d.ts +32 -0
  377. package/dist/core/tool-card-bound.js +33 -0
  378. package/dist/core/tool-catalog-entries.d.ts +9 -0
  379. package/dist/core/tool-catalog-entries.js +48 -0
  380. package/dist/core/tool-errors.d.ts +4 -3
  381. package/dist/core/tool-face.d.ts +3 -3
  382. package/dist/core/tool-mount-facts.d.ts +3 -2
  383. package/dist/core/tool-mount-facts.js +1 -1
  384. package/dist/core/tool-mount-static.js +7 -5
  385. package/dist/core/tool-policy.d.ts +21 -19
  386. package/dist/core/tool-policy.js +5 -6
  387. package/dist/core/tool-registry.d.ts +3 -1
  388. package/dist/core/tool-registry.js +15 -1
  389. package/dist/core/tool-result-store.d.ts +9 -3
  390. package/dist/core/tool-result-store.js +14 -1
  391. package/dist/core/tool-roster.d.ts +6 -0
  392. package/dist/core/tool-roster.js +18 -0
  393. package/dist/core/tool-spec.d.ts +17 -8
  394. package/dist/core/trace.d.ts +35 -31
  395. package/dist/core/types.d.ts +2 -2
  396. package/dist/core/untrusted-egress.d.ts +19 -7
  397. package/dist/core/untrusted-egress.js +26 -7
  398. package/dist/core/untrusted-text.d.ts +6 -18
  399. package/dist/core/untrusted-text.js +11 -4
  400. package/dist/core/user-attachment.d.ts +9 -6
  401. package/dist/core/user-attachment.js +12 -10
  402. package/dist/core/user-row-origin.d.ts +44 -25
  403. package/dist/core/user-row-origin.js +30 -20
  404. package/dist/core/wiring-manifest.d.ts +26 -7
  405. package/dist/core/wiring-manifest.js +14 -11
  406. package/dist/core/workspace-snapshot.d.ts +3 -1
  407. package/dist/core/workspace-snapshot.js +1 -0
  408. package/dist/engine/execution-env/node-execution-env.d.ts +23 -16
  409. package/dist/engine/execution-env/node-execution-env.js +127 -67
  410. package/dist/engine/harness/agent-harness.d.ts +4 -5
  411. package/dist/engine/harness/agent-harness.js +2 -7
  412. package/dist/engine/harness/types.d.ts +51 -19
  413. package/dist/engine/harness/types.js +28 -1
  414. package/dist/engine/llm/types.d.ts +26 -14
  415. package/dist/engine/llm/types.js +2 -2
  416. package/dist/engine/loop/agent-loop.d.ts +2 -2
  417. package/dist/engine/loop/agent-loop.js +51 -275
  418. package/dist/engine/loop/types.d.ts +0 -18
  419. package/dist/engine/session/import-validate.d.ts +3 -0
  420. package/dist/engine/session/import-validate.js +34 -2
  421. package/dist/engine/session/repo-utils.d.ts +42 -4
  422. package/dist/engine/session/repo-utils.js +33 -5
  423. package/dist/engine/session/session.d.ts +41 -14
  424. package/dist/engine/session/session.js +96 -25
  425. package/dist/index.d.ts +21 -16
  426. package/dist/index.js +16 -10
  427. package/dist/orchestration/run-spec.d.ts +1 -1
  428. package/dist/orchestration/run-workflow-tool.d.ts +12 -9
  429. package/dist/orchestration/run-workflow-tool.js +15 -19
  430. package/dist/orchestration/workflow-governance.js +13 -21
  431. package/dist/orchestration/workflow-observe.d.ts +4 -3
  432. package/dist/orchestration/workflow-primitives.d.ts +1 -1
  433. package/dist/orchestration/workflow-record-artifact.d.ts +14 -0
  434. package/dist/orchestration/workflow-record-artifact.js +32 -0
  435. package/dist/orchestration/workflow-script-store.d.ts +9 -0
  436. package/dist/orchestration/workflow-script-store.js +20 -1
  437. package/dist/orchestration/workflow-types.d.ts +33 -3
  438. package/dist/orchestration/workflow.d.ts +24 -14
  439. package/dist/orchestration/workflow.js +52 -23
  440. package/dist/prompt-assembly/artifact.js +4 -8
  441. package/dist/prompt-assembly/catalog/engine.d.ts +263 -0
  442. package/dist/prompt-assembly/catalog/engine.js +30 -0
  443. package/dist/prompt-assembly/catalog/index.d.ts +1 -1
  444. package/dist/prompt-assembly/catalog/index.js +2 -2
  445. package/dist/prompt-assembly/catalog/locales/zh-Hans/engine.d.ts +1 -1
  446. package/dist/prompt-assembly/catalog/locales/zh-Hans/engine.js +29 -0
  447. package/dist/prompt-assembly/epoch.js +6 -8
  448. package/dist/prompt-assembly/turn-snapshot.js +8 -9
  449. package/dist/stores/file/background-agent-store.js +5 -6
  450. package/dist/stores/file/checkpoint-store.d.ts +0 -4
  451. package/dist/stores/file/checkpoint-store.js +7 -3
  452. package/dist/stores/file/file-history-store.d.ts +8 -0
  453. package/dist/stores/file/file-history-store.js +72 -0
  454. package/dist/stores/file/fs-atomic.js +17 -12
  455. package/dist/stores/file/index.js +11 -5
  456. package/dist/stores/file/mailbox-store.js +13 -4
  457. package/dist/stores/file/permission-rule-store.js +14 -13
  458. package/dist/stores/file/shared-ledger.d.ts +4 -0
  459. package/dist/stores/file/shared-ledger.js +4 -0
  460. package/dist/stores/file/task-list-store.js +12 -3
  461. package/dist/stores/file/workflow-run-store.js +1 -0
  462. package/dist/tools/fs/bash-program-position.d.ts +4 -2
  463. package/dist/tools/fs/bash-program-position.js +1 -1
  464. package/dist/tools/fs/bash-readonly-classifier.js +1 -1
  465. package/dist/tools/fs/bound-open.d.ts +97 -0
  466. package/dist/tools/fs/bound-open.js +103 -0
  467. package/dist/tools/fs/containment-face.d.ts +2 -2
  468. package/dist/tools/fs/fs-pdf.d.ts +7 -1
  469. package/dist/tools/fs/fs-pdf.js +31 -23
  470. package/dist/tools/fs/fs-read.d.ts +24 -17
  471. package/dist/tools/fs/fs-read.js +84 -53
  472. package/dist/tools/fs/fs-shared.d.ts +14 -12
  473. package/dist/tools/fs/fs-shared.js +5 -4
  474. package/dist/tools/fs/fs-write.d.ts +2 -2
  475. package/dist/tools/fs/fs-write.js +20 -12
  476. package/dist/tools/fs/index.d.ts +4 -4
  477. package/dist/tools/fs/index.js +2 -2
  478. package/dist/tools/fs/notebook.d.ts +1 -1
  479. package/dist/tools/fs/pdf.d.ts +12 -3
  480. package/dist/tools/fs/pdf.js +22 -9
  481. package/dist/tools/fs/read-deny-home.d.ts +3 -2
  482. package/dist/tools/fs/read-deny-home.js +8 -11
  483. package/dist/tools/fs/safety.d.ts +3 -2
  484. package/dist/tools/fs/shell-read-check.js +10 -9
  485. package/dist/tools/monitor.d.ts +6 -5
  486. package/dist/tools/task-list.d.ts +16 -6
  487. package/dist/tools/task-list.js +4 -0
  488. package/dist/tools/web.d.ts +9 -1
  489. package/dist/tools/web.js +8 -3
  490. package/dist/tools/worktree.d.ts +7 -5
  491. package/dist/tools/worktree.js +4 -3
  492. package/package.json +4 -3
  493. package/test/export-surface.snapshot.json +93 -7
  494. package/wire-changes/core-stores-sql@7.67.3.json +39 -0
  495. package/wire-changes/core-stores-sql@7.68.0.json +39 -0
  496. package/wire-changes/core@7.67.3.json +65 -0
  497. package/wire-changes/core@7.68.0.json +4257 -0
  498. package/wire-changes/mods-kernel@7.67.3.json +39 -0
  499. package/wire-changes/mods-kernel@7.68.0.json +129 -0
  500. package/wire-changes/primitives@7.67.3.json +39 -0
  501. package/wire-changes/primitives@7.68.0.json +253 -0
  502. package/wire-changes/wiki-gate@7.67.3.json +39 -0
  503. package/wire-changes/wiki-gate@7.68.0.json +39 -0
  504. package/dist/core/runner/credential-origin-seat.d.ts +0 -2
  505. package/dist/core/runner/credential-origin-seat.js +0 -20
@@ -3,6 +3,7 @@ import { hostname, uptime } from "node:os";
3
3
  import { hrtime } from "node:process";
4
4
  import { execFileSync } from "node:child_process";
5
5
  import { inheritedHostEnv } from "./secret-env.js";
6
+ import { deliverEngineNotice } from "./engine-notice.js";
6
7
  const UNCHECKABLE_TEXT = Object.freeze({
7
8
  another_host: "it was written on another host",
8
9
  another_pid_namespace: "it was written in another pid namespace (another container, or one this process cannot name)",
@@ -49,11 +50,15 @@ function announceStartTimeDegrade(reason) {
49
50
  if (startTimeProbeUnavailable)
50
51
  return;
51
52
  startTimeProbeUnavailable = true;
52
- console.warn(`[sema] this host cannot report process start times (${reason}), so a record naming a process — a file store's ` +
53
- `directory lock, a run claim, a memory writer's session account — is judged by PID ALONE. A record left behind ` +
54
- `by a crashed process whose pid the OS has since handed to an unrelated process then reads as a LIVE owner: a ` +
55
- `lock or claim stays refused until it is removed by hand, and a writer's account stays open until its session ` +
56
- `resumes or the host closes it.`);
53
+ deliverEngineNotice(undefined, {
54
+ code: "config.process_start_time_unavailable",
55
+ message: `[sema] this host cannot report process start times (${reason}), so a record naming a process — a file store's ` +
56
+ `directory lock, a run claim, a memory writer's session account — is judged by PID ALONE. A record left behind ` +
57
+ `by a crashed process whose pid the OS has since handed to an unrelated process then reads as a LIVE owner: a ` +
58
+ `lock or claim stays refused until it is removed by hand, and a writer's account stays open until its session ` +
59
+ `resumes or the host closes it.`,
60
+ detail: { reason },
61
+ });
57
62
  }
58
63
  const START_TIME_PROBE_ATTEMPTS = 3;
59
64
  function probeStartTimes(pid) {
@@ -59,7 +59,8 @@ export declare function underDeclaredHeaders(defaults: Readonly<Record<string, s
59
59
  export declare const httpTrimmed: (value: string) => string;
60
60
  /**
61
61
  * A peer's error text with what the peer was SENT taken out of it. Both kinds of removal are found on the ORIGINAL text (so no marker is
62
- * rescanned and no replacement can disturb what another one reads) and the ranges they take are merged, one marker per merged range: every
62
+ * rescanned and no replacement can disturb what another one reads) and the ranges they take are merged, one marker per merged range (the
63
+ * bare mark: the place says what was there — a value the request carried, a cookie's value): every
63
64
  * occurrence of a declared value in any spelling {@link requestEchoSpellings} derives from it (as declared and as sent, its credentials
64
65
  * part, JSON-escaped with or without `\/`, percent-encoded, form-urlencoded, `+` for a space), in any letter case, longest first, and every `Cookie` / `Set-Cookie` member
65
66
  * whole — a header line to its end, a record member's string, array or object to its close. The two never disarm each other: a declared
@@ -67,9 +68,10 @@ export declare const httpTrimmed: (value: string) => string;
67
68
  * from outside takes its own range and the member's value goes with it. A declared value that is also an ordinary word or number (`en`, `1`,
68
69
  * `application/json`) goes wherever it occurs in the remote's words, in any case — a legibility cost, never a leak; the failure's closed
69
70
  * fields (code, status, delivery) are not text. A declaration too large for one matcher (tens of thousands of characters, which no header
70
- * carries) makes the whole text the marker: the pass never throws and never shows what it could not match. A hit that lies wholly inside
71
- * a marker a pass already wrote (the exact literals, `redactionMarkerSpans`) is no hit, and one that reaches into a marker takes the
72
- * whole marker with it, so the pass over its own output answers the same text.
71
+ * carries) makes the whole text the marker: the pass never throws and never shows what it could not match. A mark the text already holds
72
+ * (a member of the marks table) is atomic, by the renderer's one law (`renderWithheld`): a hit that is exactly a mark is no hit, and one
73
+ * that reaches into a mark — or lies inside one: a declared value can be a piece of a mark's words — takes the whole mark with it, so the
74
+ * pass over its own output answers the same text.
73
75
  */
74
76
  export declare function scrubRequestEcho(text: string, declared: readonly string[]): string;
75
77
  /**
@@ -88,12 +90,31 @@ export declare function eraseSentCredentials(text: string, credentials: readonly
88
90
  * ({@link scrubRequestEcho}: `declared` is required, so no mint reads a remote's words without naming its request), then the credential
89
91
  * vocabulary. Words with no declared value in them read exactly as the vocabulary renders them. Where a declared value is there, the
90
92
  * values the vocabulary finds in the ORIGINAL words are taken out with it, so neither disarms the other: removing a declared `Bearer`
91
- * cannot hide the token after it from the vocabulary, and the vocabulary rewriting part of a declared value cannot leave the rest. A
92
- * caller that bounds the text for display cuts what this returns, never the remote's raw words, so a cut can leave no part of a value.
93
- * The function is a fixed point (its own output answers the same text). A store, a log or an event lane that receives the result does
94
- * not redact again: persistence is not an exit, the mint is.
93
+ * cannot hide the token after it from the vocabulary, and the vocabulary rewriting part of a declared value cannot leave the rest. Each
94
+ * is written as its own member — a declared value the bare mark, a value the vocabulary found its row's — and a region they share as
95
+ * one, its widest span's (the renderer's one law; of a declared value and a vocabulary find over the same region, the find's: the member
96
+ * the words' other faces write there). `found` are values the vocabulary found in another spelling of the same words (a reader that
97
+ * carries the words in one spelling and read them in another), written as the bare mark; they and the values found here are taken out
98
+ * wherever they stand, a Cookie member's name included (only a declared value spares it). A caller that bounds the text for display cuts
99
+ * what this returns, never the remote's raw words, so a cut can leave no part of a value. The function is a fixed point (its own output
100
+ * answers the same text). A store, a log or an event lane that receives the result does not redact again: persistence is not an exit,
101
+ * the mint is.
95
102
  */
96
- export declare function remoteWords(text: string, declared: readonly string[]): Egress<"same-principal">;
103
+ export declare function remoteWords(text: string, declared: readonly string[], found?: readonly string[]): Egress<"same-principal">;
104
+ /**
105
+ * What {@link remoteWords} withholds of `text`, as [start, end) spans in the text's coordinates — THE answer to "which characters of
106
+ * these words does their remote-words reading not carry", for a reader that carries the same words in another spelling and must carry
107
+ * no less: the regions its echo pass withholds and the spans its vocabulary pass then withholds in those marked words
108
+ * ({@link egressCredentialReading}: the label a rendering keeps is not in the span), read back through the marks (a span that touches a
109
+ * mark reaches the whole region the mark stands for). Where the marked words cannot be read back (see {@link writtenRegions}), the whole
110
+ * text; and checked against the reading's own output: where the text outside the spans does not stand in it as written
111
+ * ({@link carriesTheRest}), the spans missed a removal, and the answer is the whole text.
112
+ */
113
+ export declare function remoteWordsSpans(text: string, declared: readonly string[], found?: readonly string[]): Array<readonly [number, number]>;
114
+ /** Whether `rendered` carries, as written and in order, every character of `text` outside `spans`: the text between the spans (merged)
115
+ * stands in `rendered` piece by piece — the first at its start, the last at its end, each other one after the one before. Exported for
116
+ * its pins; not on the package barrel. */
117
+ export declare function carriesTheRest(text: string, spans: ReadonlyArray<readonly [number, number]>, rendered: string): boolean;
97
118
  /** Whether a resolved header set carries anything the declaration bound to its endpoints — a request that does follows no redirect (the
98
119
  * next hop is not a declared endpoint; A2A's follow law reads this). */
99
120
  export declare function carriesDeclaredHeaders(headers: Record<string, string> | undefined): boolean;
@@ -1,7 +1,7 @@
1
1
  import { isLoopbackHost } from "./host-floor.js";
2
2
  import { authSchemeCredentials } from "./secret-env.js";
3
- import { egressText } from "./untrusted-egress.js";
4
- import { REDACTION_MARK, redactionMarkerSpans } from "./redaction-marks.js";
3
+ import { egressCredentialReading, egressText } from "./untrusted-egress.js";
4
+ import { REDACTION_MARKS, renderWithheld } from "@sema-agent/primitives";
5
5
  import { inlineUntrusted } from "./untrusted-text.js";
6
6
  import { callerText } from "./caller-text.js";
7
7
  export const MCP_ASSERTION_HEADER = "connector-assertion";
@@ -106,73 +106,127 @@ function structuredEnd(text, at) {
106
106
  return text.length;
107
107
  }
108
108
  export function scrubRequestEcho(text, declared) {
109
- return markedOver(text, requestEchoRanges(text, declared));
109
+ return renderWithheld(text, requestEchoSpans(text, sentValues(declared)));
110
110
  }
111
111
  export function eraseSentCredentials(text, credentials) {
112
112
  if (credentials.length === 0 || text === "")
113
113
  return text;
114
- return markedOver(text, needleRanges(text, credentials, []));
114
+ return renderWithheld(text, needleSpans(text, sentValues(credentials), []));
115
115
  }
116
- function markedOver(text, removed) {
117
- if (removed.length === 0)
118
- return text;
119
- removed.sort((a, b) => a[0] - b[0] || b[1] - a[1]);
120
- let out = "";
121
- let kept = 0;
122
- let wrote = false;
123
- for (const [start, end] of removed) {
124
- if (wrote && start <= kept) {
125
- kept = Math.max(kept, end);
126
- continue;
127
- }
128
- out += text.slice(kept, start) + REDACTION_MARK;
129
- kept = end;
130
- wrote = true;
131
- }
132
- return out + text.slice(kept);
116
+ function sentValues(values) {
117
+ return values.map((value) => ({ value, mark: REDACTION_MARKS.bare }));
133
118
  }
134
- function requestEchoRanges(text, declared) {
119
+ function requestEchoSpans(text, needles, found = []) {
135
120
  const members = cookieMembers(text);
136
- return [...members.map(([, from, end]) => [from, end]), ...needleRanges(text, declared, members)];
121
+ return [...members.map(([, start, end]) => ({ start, end, mark: REDACTION_MARKS.bare })), ...needleSpans(text, needles, members), ...needleSpans(text, found, [])];
137
122
  }
138
- function needleRanges(text, values, members) {
139
- const forms = new Set();
140
- for (const value of values)
123
+ function needleSpans(text, needles, members) {
124
+ const byMark = new Map();
125
+ for (const { value, mark } of needles) {
126
+ const forms = byMark.get(mark) ?? new Set();
141
127
  for (const spelling of requestEchoSpellings(value))
142
- forms.add(spelling);
143
- forms.delete("");
144
- const removed = [];
145
- const markers = redactionMarkerSpans(text);
146
- for (const hit of valueHits(text, [...forms])) {
147
- if (members.some(([name, from]) => hit[0] >= name && hit[1] <= from))
148
- continue;
149
- if (markers.some(([from, end]) => hit[0] >= from && hit[1] <= end))
150
- continue;
151
- const reach = markers.filter(([from, end]) => hit[0] < end && hit[1] > from);
152
- removed.push([Math.min(hit[0], ...reach.map(([from]) => from)), Math.max(hit[1], ...reach.map(([, end]) => end))]);
153
- }
154
- return removed;
128
+ if (spelling !== "")
129
+ forms.add(spelling);
130
+ byMark.set(mark, forms);
131
+ }
132
+ const spans = [];
133
+ for (const [mark, forms] of byMark) {
134
+ const hits = valueHits(text, [...forms]);
135
+ if (hits === undefined)
136
+ return [{ start: 0, end: text.length, mark: REDACTION_MARKS.oversized }];
137
+ for (const [start, end] of hits)
138
+ if (!members.some(([name, from]) => start >= name && end <= from))
139
+ spans.push({ start, end, mark });
140
+ }
141
+ return spans;
155
142
  }
156
143
  function vocabularyValues(text) {
157
- const report = { findings: [] };
158
- egressText("same-principal", text, report);
159
- return report.findings.map(({ span: [from, end] }) => {
160
- const found = text.slice(from, end);
161
- const rendered = egressText("same-principal", found);
162
- let head = 0;
163
- while (head < found.length && head < rendered.length && found[head] === rendered[head])
164
- head++;
165
- let tail = 0;
166
- while (tail < found.length - head && tail < rendered.length - head && found[found.length - 1 - tail] === rendered[rendered.length - 1 - tail])
167
- tail++;
168
- const value = found.slice(head, found.length - tail);
169
- return value === "" ? found : value;
170
- });
171
- }
172
- export function remoteWords(text, declared) {
173
- if (requestEchoRanges(text, declared).length === 0)
174
- return egressText("same-principal", text);
175
- return egressText("same-principal", scrubRequestEcho(text, [...declared, ...vocabularyValues(text)]));
144
+ return egressCredentialReading(text).spans.map(([from, end, mark]) => ({ value: text.slice(from, end), mark }));
145
+ }
146
+ export function remoteWords(text, declared, found = []) {
147
+ return egressText("same-principal", renderWithheld(text, echoTaken(text, declared, found)));
148
+ }
149
+ function echoTaken(text, declared, found) {
150
+ const sent = sentValues(declared);
151
+ const foundElsewhere = sentValues(found);
152
+ if (requestEchoSpans(text, sent, foundElsewhere).length === 0)
153
+ return [];
154
+ return requestEchoSpans(text, sent, [...foundElsewhere, ...vocabularyValues(text)]);
155
+ }
156
+ export function remoteWordsSpans(text, declared, found = []) {
157
+ const taken = echoTaken(text, declared, found);
158
+ const marked = renderWithheld(text, taken);
159
+ const regions = writtenRegions(text, taken, marked);
160
+ if (regions === undefined)
161
+ return [[0, text.length]];
162
+ const reading = egressCredentialReading(marked);
163
+ const lo = new Int32Array(marked.length);
164
+ const hi = new Int32Array(marked.length);
165
+ let at = 0;
166
+ let kept = 0;
167
+ const keep = (until) => {
168
+ for (; kept < until; kept++, at++)
169
+ [lo[at], hi[at]] = [kept, kept + 1];
170
+ };
171
+ for (const { start, end, length } of regions) {
172
+ keep(start);
173
+ for (let k = 0; k < length; k++, at++)
174
+ [lo[at], hi[at]] = [start, end];
175
+ kept = end;
176
+ }
177
+ keep(text.length);
178
+ const spans = [...regions.map(({ start, end }) => [start, end]), ...reading.spans.filter(([start, end]) => end > start).map(([start, end]) => [lo[start], hi[end - 1]])];
179
+ return carriesTheRest(text, spans, reading.rendered) ? spans : [[0, text.length]];
180
+ }
181
+ export function carriesTheRest(text, spans, rendered) {
182
+ const pieces = [];
183
+ let kept = 0;
184
+ for (const [start, end] of mergedRanges(spans)) {
185
+ pieces.push(text.slice(kept, start));
186
+ kept = end;
187
+ }
188
+ const last = text.slice(kept);
189
+ if (pieces.length === 0)
190
+ return rendered === last;
191
+ if (!rendered.startsWith(pieces[0]))
192
+ return false;
193
+ let at = pieces[0].length;
194
+ for (const piece of pieces.slice(1)) {
195
+ const found = rendered.indexOf(piece, at);
196
+ if (found < 0)
197
+ return false;
198
+ at = found + piece.length;
199
+ }
200
+ return rendered.length - last.length >= at && rendered.endsWith(last);
201
+ }
202
+ const MARK_MEMBERS = Object.values(REDACTION_MARKS);
203
+ function mergedRanges(ranges) {
204
+ const merged = [];
205
+ for (const [start, end] of [...ranges].sort((a, b) => a[0] - b[0] || b[1] - a[1])) {
206
+ const last = merged[merged.length - 1];
207
+ if (last !== undefined && start <= last[1])
208
+ last[1] = Math.max(last[1], end);
209
+ else
210
+ merged.push([start, end]);
211
+ }
212
+ return merged;
213
+ }
214
+ function writtenRegions(text, spans, marked) {
215
+ const regions = [];
216
+ let kept = 0;
217
+ let at = 0;
218
+ for (const [start, end] of mergedRanges(spans.map(({ start, end }) => [start, end]))) {
219
+ if (!marked.startsWith(text.slice(kept, start), at))
220
+ return undefined;
221
+ at += start - kept;
222
+ const member = MARK_MEMBERS.find((m) => marked.startsWith(m, at));
223
+ if (member === undefined)
224
+ return undefined;
225
+ regions.push({ start, end, length: member.length });
226
+ at += member.length;
227
+ kept = end;
228
+ }
229
+ return marked.length - at === text.length - kept && marked.endsWith(text.slice(kept)) ? regions : undefined;
176
230
  }
177
231
  function cookieMembers(text) {
178
232
  const members = [];
@@ -206,7 +260,7 @@ function valueHits(text, forms) {
206
260
  }
207
261
  }
208
262
  catch {
209
- return [[0, text.length]];
263
+ return undefined;
210
264
  }
211
265
  return hits;
212
266
  }
@@ -1,5 +1,5 @@
1
1
  import { posix } from "node:path";
2
- import { lexedWordOf, readShellCommand } from "./shell-run-candidates.js";
2
+ import { DURATION_RE, lexedWordOf, readShellCommand } from "./shell-run-candidates.js";
3
3
  import { readOnlyRefusalSentence, unlistedReaderSentence } from "../tools/fs/bash-readonly-classifier.js";
4
4
  import { descriptorsOfPlan, newLineDescriptors, standardDeviceUnrebound } from "../tools/fs/shell-read-device.js";
5
5
  import { planShellReads } from "../tools/fs/shell-read-plan.js";
@@ -10,7 +10,7 @@ const NOT = (reason) => ({ readOnly: false, reason });
10
10
  const READ_ONLY = { readOnly: true };
11
11
  export const CD_GIT_COMPOUND_SENTENCE = "This command changes directory before running a version-control command, which can pick up untrusted hooks or repository configuration from the target directory. Approve only if you trust it.";
12
12
  export function changesDirectoryBeforeGit(shape, cwd) {
13
- const programs = shape.segments.map((s) => peelBuiltinPrefix(s.argv.slice(leadingAssignmentCount(s.argv)).map((w) => w.text))[0] ?? "");
13
+ const programs = shape.segments.map((s) => peelWrapperPrefix(s.argv.slice(leadingAssignmentCount(s.argv)).map((w) => w.text))[0] ?? "");
14
14
  if (shape.segments.length < 2 || !programs.includes("cd") || !programs.includes("git"))
15
15
  return false;
16
16
  const cds = shape.segments.filter((_, i) => programs[i] === "cd");
@@ -149,7 +149,8 @@ function literalAssignmentValue(a) {
149
149
  return oneRegion;
150
150
  return only.quotedBy === '"' && oneRegion && !/[$`\\]/.test(only.literal);
151
151
  }
152
- function peelBuiltinPrefix(words) {
152
+ const BUILTINS_TIMEOUT_CANNOT_RUN = new Set(["[[", "alias", "cd", "help", "history", "type"]);
153
+ function peelWrapperPrefix(words) {
153
154
  let t = words;
154
155
  for (;;) {
155
156
  if (t[0] === "command") {
@@ -169,8 +170,11 @@ function peelBuiltinPrefix(words) {
169
170
  t = t.slice(r);
170
171
  }
171
172
  else
172
- return t;
173
+ break;
173
174
  }
175
+ while (t[0] === "timeout" && DURATION_RE.test(t[1] ?? "") && t.length > 2 && !BUILTINS_TIMEOUT_CANNOT_RUN.has(t[2]))
176
+ t = t.slice(2);
177
+ return t;
174
178
  }
175
179
  function segmentVerdict(seg, line, bindings, readers, refused) {
176
180
  for (const r of seg.redirections) {
@@ -191,7 +195,7 @@ function segmentVerdict(seg, line, bindings, readers, refused) {
191
195
  const run = seg.argv.slice(k);
192
196
  if (run.length === 0)
193
197
  return NOT("a bare assignment runs no program");
194
- const words = peelBuiltinPrefix(run.map((w) => w.text));
198
+ const words = peelWrapperPrefix(run.map((w) => w.text));
195
199
  const program = words[0];
196
200
  const unlisted = unlistedObjection(program, readers);
197
201
  if (unlisted !== undefined)
@@ -1,29 +1,7 @@
1
- import type { SecretNotation } from "@sema-agent/primitives";
2
- /** The marks, by what they stand for. `whole` is the bare mark (a span removed whole — a credential value, a floor); the
3
- * others name the shape that was withheld: `credentials` a URL's userinfo, `url` a whole URL, `path` an
4
- * absolute filesystem path. A mark the engine writes is exactly one of these four. Frozen: the table is exported to hosts, and every
5
- * pass reads it at call time, so a write by a reader would change what the engine writes. */
6
- export declare const REDACTION_MARKS: Readonly<{
7
- readonly whole: "[redacted]";
8
- readonly credentials: "[redacted-credentials]";
9
- readonly url: "[redacted-url]";
10
- readonly path: "[redacted-path]";
11
- }>;
12
- /** The bare mark — what a host compares against to tell that the engine withheld a value. */
13
- export declare const REDACTION_MARK: "[redacted]";
14
- /** The engine's notation for the credential renderer (`renderSecrets`): a credential value is the bare mark, a URL userinfo
15
- * the credentials mark, and a text no reading can afford is the bare mark whole. Built from the table, so it follows it. */
16
- export declare const REDACTION_NOTATION: SecretNotation;
17
- /** The spelling a request-route rendering writes for a withheld query value or URL user (`«redacted»`) — shown to a person
18
- * in a refusal or a route display, never written by a redaction pass. It is not a member of {@link REDACTION_MARKS}: the
19
- * marks the readers below recognize are that table's four, and this spelling is not one of them. */
20
- export declare const WITHHELD_VALUE_MARK = "\u00ABredacted\u00BB";
21
1
  /** What stands where a reader of a value did not read it — a member past a bound, a value nested past a depth, a value whose
22
2
  * members could not be listed, a gate record's member that is not data: `[not recorded: <why>]`, `why` in the engine's own
23
- * words. Not a redaction mark: nothing here was withheld for what it said (the readers below do not count it), it was not read. */
3
+ * words. Not a redaction mark: nothing here was withheld for what it said (the marks' readers do not count it), it was not read. */
24
4
  export declare function notRecordedMark(why: string): string;
25
- /** Where the marks sit in `s`, one [start, end) span at a time, leftmost first. Lazy: a reader that stops early (a display cut stops
26
- * at its bound) pays for the marks it looked at, not for every mark an input of a million of them holds. */
27
- export declare function eachRedactionMarkerSpan(s: string): Generator<[number, number], void, undefined>;
28
- /** Where the marks sit in `s`, all of them, as [start, end) spans, leftmost first. */
29
- export declare function redactionMarkerSpans(s: string): Array<[number, number]>;
5
+ /** Where a cut of `s` at `at` lands so that no mark is split (half a mark is no mark): `at` itself, or the start of the mark it
6
+ * would land inside. Reads the marks lazily, only up to the cut. */
7
+ export declare function markSafeCut(s: string, at: number): number;
@@ -1,25 +1,13 @@
1
- export const REDACTION_MARKS = Object.freeze({
2
- whole: "[redacted]",
3
- credentials: "[redacted-credentials]",
4
- url: "[redacted-url]",
5
- path: "[redacted-path]",
6
- });
7
- export const REDACTION_MARK = REDACTION_MARKS.whole;
8
- export const REDACTION_NOTATION = Object.freeze({
9
- value: REDACTION_MARKS.whole,
10
- byKind: Object.freeze({ "url-credentials": REDACTION_MARKS.credentials }),
11
- overStrip: REDACTION_MARKS.whole,
12
- });
13
- export const WITHHELD_VALUE_MARK = "«redacted»";
1
+ import { eachRedactionMarkerSpan } from "@sema-agent/primitives";
14
2
  export function notRecordedMark(why) {
15
3
  return `[not recorded: ${why}]`;
16
4
  }
17
- const escapeLiteral = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
18
- const REDACTION_MARKER_RE = new RegExp(Object.values(REDACTION_MARKS).map(escapeLiteral).join("|"), "g");
19
- export function* eachRedactionMarkerSpan(s) {
20
- for (const m of s.matchAll(REDACTION_MARKER_RE))
21
- yield [m.index, m.index + m[0].length];
22
- }
23
- export function redactionMarkerSpans(s) {
24
- return [...eachRedactionMarkerSpan(s)];
5
+ export function markSafeCut(s, at) {
6
+ for (const [start, end] of eachRedactionMarkerSpan(s)) {
7
+ if (start >= at)
8
+ break;
9
+ if (at < end)
10
+ return start;
11
+ }
12
+ return at;
25
13
  }
@@ -94,8 +94,9 @@ export declare function placementTargetOf(handle: WorkspaceHandle): PlacementTar
94
94
  /**
95
95
  * The target an environment reports for itself, read ONCE per leg — at the point the leg's workspace settles: its
96
96
  * `workspaceHandle()`'s {@link placementTargetOf}. `undefined` when there is nothing to read: the environment is not a
97
- * remote one, or its handle cannot answer yet (a lazy-connect adapter before its first connection throws). That leg has
98
- * no target of its own, so what it spawns carries no fence.
97
+ * remote one, or its handle cannot answer yet (a lazy-connect adapter that is still unconnected — its establishment at
98
+ * the leg's restore seat failed in a way the run starts past — throws). That leg has no target of its own, so what it
99
+ * spawns carries no fence.
99
100
  */
100
101
  export declare function reportedPlacementTarget(env: ExecutionEnv | undefined): PlacementTarget | undefined;
101
102
  /**
@@ -290,15 +291,20 @@ export type RemoteExecutionErrorCode =
290
291
  * re-drives committed side effects) — retrying them burns budget or, worse, re-drives a rejected
291
292
  * credential or a committed op.
292
293
  *
293
- * ONE list, two consumers, so a caller's retry decision and its DISCLOSURE can never disagree: the engine
294
- * retries only IDEMPOTENT ops on these codes (see {@link withRetry}'s red line — a snapshot-taking
295
- * `suspendVM` is never retried), and it stamps `retryable` on the failure it reports to the caller for the
296
- * ops it does NOT retry, so a deployment can decide (refresh the credential and re-resume vs give up)
297
- * without parsing prose.
294
+ * ONE list, three consumers, so a caller's retry decision, its DISCLOSURE and whether the run starts at all can
295
+ * never disagree: the engine retries only IDEMPOTENT ops on these codes (see {@link withRetry}'s red line — a
296
+ * snapshot-taking `suspendVM` is never retried); it stamps `retryable` on the failure it reports to the caller for
297
+ * the ops it does NOT retry, so a deployment can decide (refresh the credential and re-resume vs give up) without
298
+ * parsing prose; and the leg's restore seat reads it when the environment answers its establishment call
299
+ * ({@link RemoteExecutionEnv.connect}, or `resumeVM` on a leg that restores a snapshot). Starting the run past a
300
+ * failed establishment IS a retry — the first operation establishes again — so the seat starts it only on a code
301
+ * this list holds, on `unknown` (it says nothing about the environment) and on `aborted` the run's own cancel did
302
+ * not cause; any other code is this environment's standing refusal and fails the run before it starts, with that code.
303
+ * An `env.`-namespaced code ({@link RemoteExecutionError.code}) is never in this list.
298
304
  */
299
305
  export declare const RETRYABLE_REMOTE_ERROR_CODES: readonly RemoteExecutionErrorCode[];
300
- /** Is `code` in the {@link RETRYABLE_REMOTE_ERROR_CODES} family? */
301
- export declare function isRetryableRemoteErrorCode(code: RemoteExecutionErrorCode): boolean;
306
+ /** Is `code` in the {@link RETRYABLE_REMOTE_ERROR_CODES} family? A deployment's `env.` code never is. */
307
+ export declare function isRetryableRemoteErrorCode(code: RemoteExecutionError["code"]): boolean;
302
308
  /**
303
309
  * Error surfaced by {@link RemoteExecutionEnv} lifecycle ops and by {@link RemoteExecutionEnv.execStream}'s
304
310
  * iterator. Mirrors the vendored `ExecutionError` shape but carries the remote-specific code set; it is kept
@@ -306,8 +312,14 @@ export declare function isRetryableRemoteErrorCode(code: RemoteExecutionErrorCod
306
312
  * design/45 suspend/resume *runtime* lands and the Runner/orchestrator layer must thread `"suspended"`.
307
313
  */
308
314
  export declare class RemoteExecutionError extends Error {
309
- readonly code: RemoteExecutionErrorCode;
310
- constructor(code: RemoteExecutionErrorCode, message: string, cause?: Error);
315
+ /**
316
+ * A {@link RemoteExecutionErrorCode}, or a deployment's own `env.`-namespaced code for a refusal of this environment
317
+ * that the closed set has no word for (the namespace the terminal code table reads as the execution environment's,
318
+ * `env.` ⇒ `config`). Either is read through {@link RETRYABLE_REMOTE_ERROR_CODES}: an `env.` code is never in it, so
319
+ * answered at the restore seat it fails the run before it starts, carried to the terminal verbatim.
320
+ */
321
+ readonly code: RemoteExecutionErrorCode | `env.${string}`;
322
+ constructor(code: RemoteExecutionError["code"], message: string, cause?: Error);
311
323
  }
312
324
  /**
313
325
  * A remote, stateful, suspendable {@link ExecutionEnv} (design/48 §5). Extends the base with workspace identity,
@@ -341,13 +353,28 @@ export interface RemoteExecutionEnv extends ExecutionEnv {
341
353
  /**
342
354
  * Identity of the connected workspace (design/48 §5 gap 1). Synchronous: it is data the env already holds.
343
355
  *
344
- * The engine reads it once per leg, when the leg's workspace settles, to learn which target the leg is on
345
- * ({@link reportedPlacementTarget}) — the fence every agent the leg spawns or wakes is minted under. A target-bound
346
- * adapter (one whose handle states `deviceId`) answers it from construction on, before any connection; an adapter
347
- * that cannot answer yet (it throws) gives its leg no target, and that leg's agents carry no fence.
356
+ * The engine reads it once per leg, when the leg's workspace settles — after the leg's restore seat established the
357
+ * environment ({@link connect} / {@link resumeVM}) — to learn which target the leg is on ({@link reportedPlacementTarget}):
358
+ * the fence every agent the leg spawns or wakes is minted under. A target-bound adapter (one whose handle states
359
+ * `deviceId`) answers it from construction on; an adapter that cannot answer even after the establishment call (it
360
+ * throws) gives its leg no target, and that leg's agents carry no fence.
348
361
  */
349
362
  workspaceHandle(): WorkspaceHandle;
350
- /** Provision/attach the remote workspace and inject secrets. Returns the resulting {@link WorkspaceHandle}. */
363
+ /**
364
+ * Provision/attach the remote workspace and inject secrets. Returns the resulting {@link WorkspaceHandle}.
365
+ *
366
+ * The engine calls this once per leg, at the leg's restore seat, on an environment its factory minted for that leg —
367
+ * every leg that does not restore a snapshot (a leg that restores one calls {@link resumeVM} there instead) — with the
368
+ * run's cancel signal as `abortSignal`. It MUST be idempotent: on an environment that is already connected it answers
369
+ * the current handle and provisions nothing (the seat is commonly NOT the first connection: a delegated child, a
370
+ * factory that writes into the environment before handing it over, a parked leg's reconnected environment). A connect
371
+ * that answers a failure has either provisioned nothing, or left what it provisioned where the next connect finds and
372
+ * reuses it — never a second workspace beside the first. How the engine reads a failure is
373
+ * {@link RETRYABLE_REMOTE_ERROR_CODES}: a code in it, `unknown` or `aborted` lets the run start, and its first
374
+ * operation meets the environment as it would have; any other code is this environment's standing refusal and fails
375
+ * the run before it starts, with that code. A connect that throws, or answers anything but this method's result shape
376
+ * (an `error` with a string `code`), is read as `unknown`.
377
+ */
351
378
  connect(config?: RemoteConnectConfig): Promise<{
352
379
  ok: true;
353
380
  value: WorkspaceHandle;
@@ -46,7 +46,7 @@ export const RETRYABLE_REMOTE_ERROR_CODES = [
46
46
  "transport_lost",
47
47
  ];
48
48
  export function isRetryableRemoteErrorCode(code) {
49
- return RETRYABLE_REMOTE_ERROR_CODES.includes(code);
49
+ return RETRYABLE_REMOTE_ERROR_CODES.some((retryable) => retryable === code);
50
50
  }
51
51
  export class RemoteExecutionError extends Error {
52
52
  code;
@@ -8,7 +8,7 @@ export interface CopyProjectionInput {
8
8
  readonly degraded?: ReadonlySet<string>;
9
9
  /** This leg's startup seed: canonical key → the whole-file content hash its system prompt holds. */
10
10
  readonly seeded?: ReadonlyMap<string, string>;
11
- /** The session's reminder mark, for the marked sentences a frame and the seeded Read sentence carry. */
11
+ /** The session's reminder mark, for the marked sentences a frame carries. */
12
12
  readonly mark?: string;
13
13
  /** The results the tool-turn law folded, and the recorded results each folds, in order. */
14
14
  readonly folds?: ReadonlyMap<object, readonly object[]>;