@sema-agent/core 7.58.0 → 7.60.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 (519) hide show
  1. package/CHANGELOG.md +1340 -0
  2. package/README.md +6 -4
  3. package/dist/agents/agent-definition.d.ts +7 -0
  4. package/dist/agents/agent-definition.js +12 -0
  5. package/dist/agents/agent-transcript-tool.d.ts +2 -1
  6. package/dist/agents/agent-transcript-tool.js +3 -1
  7. package/dist/agents/cc-peer-directory.js +8 -8
  8. package/dist/agents/child-model-seat.d.ts +4 -2
  9. package/dist/agents/child-model-seat.js +9 -4
  10. package/dist/agents/cumulative-stats.js +0 -1
  11. package/dist/agents/inherited-tool-pool.d.ts +26 -1
  12. package/dist/agents/inherited-tool-pool.js +22 -0
  13. package/dist/agents/peer-directory.d.ts +9 -0
  14. package/dist/agents/peer-directory.js +6 -2
  15. package/dist/agents/retain-ledger.d.ts +11 -1
  16. package/dist/agents/retain-ledger.js +13 -2
  17. package/dist/agents/roster-store.d.ts +1 -1
  18. package/dist/agents/roster-store.js +3 -1
  19. package/dist/agents/send-message-tool.d.ts +8 -19
  20. package/dist/agents/send-message-tool.js +32 -50
  21. package/dist/agents/subagent.d.ts +51 -17
  22. package/dist/agents/subagent.js +150 -112
  23. package/dist/agents/tool-filter.d.ts +1 -3
  24. package/dist/agents/tool-filter.js +4 -12
  25. package/dist/bench/metrics.d.ts +3 -5
  26. package/dist/bench/metrics.js +0 -1
  27. package/dist/brain/anthropic.js +161 -45
  28. package/dist/brain/degrading.js +3 -1
  29. package/dist/brain/errors.d.ts +9 -3
  30. package/dist/brain/errors.js +7 -1
  31. package/dist/brain/failover.js +2 -1
  32. package/dist/brain/open-responses.js +3 -3
  33. package/dist/brain/openai.js +103 -53
  34. package/dist/brain/provider-dialect.d.ts +11 -0
  35. package/dist/brain/provider-dialect.js +5 -2
  36. package/dist/brain/reasoning-request.js +5 -4
  37. package/dist/brain/reasoning.d.ts +19 -0
  38. package/dist/brain/reasoning.js +17 -2
  39. package/dist/brain/request-route.d.ts +4 -1
  40. package/dist/brain/request-route.js +4 -1
  41. package/dist/brain/route-adjudicator.d.ts +84 -18
  42. package/dist/brain/route-adjudicator.js +90 -22
  43. package/dist/brain/route-conformance.js +1 -1
  44. package/dist/brain/status-sink.d.ts +7 -1
  45. package/dist/brain/status-sink.js +6 -0
  46. package/dist/brain/stream-engine.js +84 -49
  47. package/dist/brain/stream-shared.d.ts +30 -0
  48. package/dist/brain/stream-shared.js +34 -1
  49. package/dist/brain/timeout.d.ts +65 -6
  50. package/dist/brain/timeout.js +111 -11
  51. package/dist/core/a2a.d.ts +15 -5
  52. package/dist/core/a2a.js +34 -19
  53. package/dist/core/account-row.d.ts +61 -0
  54. package/dist/core/account-row.js +51 -0
  55. package/dist/core/advisor-verdict.d.ts +2 -1
  56. package/dist/core/advisor-verdict.js +1 -1
  57. package/dist/core/agent-definition.d.ts +20 -0
  58. package/dist/core/allow-entry.d.ts +20 -6
  59. package/dist/core/allow-entry.js +17 -7
  60. package/dist/core/approval-object.d.ts +29 -15
  61. package/dist/core/approval-object.js +47 -19
  62. package/dist/core/artifact-host.d.ts +0 -2
  63. package/dist/core/artifact-host.js +0 -1
  64. package/dist/core/auto-compaction.js +1 -1
  65. package/dist/core/auto-mode-defaults.d.ts +8 -0
  66. package/dist/core/auto-mode-defaults.js +1 -0
  67. package/dist/core/auto-mode-rebuild.d.ts +2 -1
  68. package/dist/core/auto-mode.d.ts +39 -4
  69. package/dist/core/auto-mode.js +63 -12
  70. package/dist/core/background-agent-store.d.ts +26 -4
  71. package/dist/core/background-agent-store.js +3 -2
  72. package/dist/core/background-shell.d.ts +12 -1
  73. package/dist/core/background-shell.js +12 -0
  74. package/dist/core/checkpoint-requirements.d.ts +13 -1
  75. package/dist/core/checkpoint-requirements.js +3 -1
  76. package/dist/core/checkpoint-store.d.ts +66 -25
  77. package/dist/core/checkpoint-store.js +22 -9
  78. package/dist/core/child-clamp-seats.d.ts +29 -0
  79. package/dist/core/child-clamp-seats.js +56 -1
  80. package/dist/core/compliance.d.ts +3 -3
  81. package/dist/core/compliance.js +1 -1
  82. package/dist/core/credential-echo.d.ts +52 -0
  83. package/dist/core/credential-echo.js +65 -0
  84. package/dist/core/credential-vocabulary.d.ts +13 -3
  85. package/dist/core/credential-vocabulary.js +12 -4
  86. package/dist/core/cross-boundary-taint.d.ts +4 -5
  87. package/dist/core/effective-path-target.d.ts +8 -2
  88. package/dist/core/effective-path-target.js +8 -3
  89. package/dist/core/engine-notice.d.ts +156 -23
  90. package/dist/core/engine-notice.js +19 -5
  91. package/dist/core/frame-settlement.d.ts +5 -0
  92. package/dist/core/frame-settlement.js +4 -0
  93. package/dist/core/gate-fold.js +8 -6
  94. package/dist/core/gate-lanes.js +47 -12
  95. package/dist/core/gate-outcome.d.ts +32 -3
  96. package/dist/core/gate-outcome.js +19 -1
  97. package/dist/core/governance-codes.d.ts +17 -1
  98. package/dist/core/governance-codes.js +25 -0
  99. package/dist/core/hands-band-screen.js +0 -1
  100. package/dist/core/hands-band.d.ts +0 -3
  101. package/dist/core/hooks.d.ts +70 -59
  102. package/dist/core/hooks.js +125 -80
  103. package/dist/core/image-admission.d.ts +106 -52
  104. package/dist/core/image-admission.js +184 -56
  105. package/dist/core/image-downsample.d.ts +36 -69
  106. package/dist/core/image-downsample.js +111 -73
  107. package/dist/core/integer-option.d.ts +21 -0
  108. package/dist/core/integer-option.js +13 -0
  109. package/dist/core/locked-config.d.ts +59 -5
  110. package/dist/core/locked-config.js +82 -50
  111. package/dist/core/mailbox-store.d.ts +45 -1
  112. package/dist/core/mailbox-store.js +53 -9
  113. package/dist/core/mcp-call-meta.d.ts +2 -2
  114. package/dist/core/mcp-call-meta.js +9 -10
  115. package/dist/core/mcp-failure.d.ts +122 -20
  116. package/dist/core/mcp-failure.js +73 -5
  117. package/dist/core/mcp-host-seat.d.ts +92 -0
  118. package/dist/core/mcp-host-seat.js +131 -0
  119. package/dist/core/mcp-probe.d.ts +7 -2
  120. package/dist/core/mcp-probe.js +7 -2
  121. package/dist/core/mcp-server-link.d.ts +22 -1
  122. package/dist/core/mcp-server-link.js +25 -1
  123. package/dist/core/mcp-server-spec.d.ts +38 -9
  124. package/dist/core/mcp-server-spec.js +55 -21
  125. package/dist/core/mcp.d.ts +27 -12
  126. package/dist/core/mcp.js +105 -76
  127. package/dist/core/memory-admission.d.ts +23 -6
  128. package/dist/core/memory-admission.js +19 -9
  129. package/dist/core/memory-engine/consolidation-driver.d.ts +2 -4
  130. package/dist/core/memory-engine/consolidation-driver.js +3 -3
  131. package/dist/core/memory-engine/consolidation.d.ts +4 -0
  132. package/dist/core/memory-engine/consolidation.js +1 -0
  133. package/dist/core/memory-engine/content-origin.d.ts +13 -0
  134. package/dist/core/memory-engine/content-origin.js +21 -3
  135. package/dist/core/memory-engine/delegation-settlement.js +5 -12
  136. package/dist/core/memory-engine/distiller.js +2 -2
  137. package/dist/core/memory-engine/dual-root.d.ts +50 -1
  138. package/dist/core/memory-engine/dual-root.js +44 -1
  139. package/dist/core/memory-engine/engine.d.ts +67 -14
  140. package/dist/core/memory-engine/engine.js +384 -212
  141. package/dist/core/memory-engine/export-bundle.d.ts +23 -0
  142. package/dist/core/memory-engine/export-bundle.js +23 -4
  143. package/dist/core/memory-engine/file-backend.d.ts +128 -55
  144. package/dist/core/memory-engine/file-backend.js +290 -117
  145. package/dist/core/memory-engine/index.d.ts +3 -2
  146. package/dist/core/memory-engine/index.js +2 -1
  147. package/dist/core/memory-engine/layout.d.ts +59 -11
  148. package/dist/core/memory-engine/layout.js +190 -40
  149. package/dist/core/memory-engine/memory-backend-contract.d.ts +1 -1
  150. package/dist/core/memory-engine/memory-backend-contract.js +39 -2
  151. package/dist/core/memory-engine/scope-contract.d.ts +13 -3
  152. package/dist/core/memory-engine/scope-contract.js +2 -2
  153. package/dist/core/memory-engine/sync-client.d.ts +51 -9
  154. package/dist/core/memory-engine/sync-client.js +107 -13
  155. package/dist/core/memory-engine/sync-report.d.ts +103 -0
  156. package/dist/core/memory-engine/sync-report.js +119 -0
  157. package/dist/core/memory-engine/sync.d.ts +8 -1
  158. package/dist/core/memory-engine/types.d.ts +6 -0
  159. package/dist/core/mode-policy.d.ts +9 -1
  160. package/dist/core/mode-policy.js +11 -1
  161. package/dist/core/model-receipt.d.ts +39 -0
  162. package/dist/core/model-receipt.js +139 -0
  163. package/dist/core/mods/agent-stations.d.ts +65 -0
  164. package/dist/core/mods/agent-stations.js +105 -0
  165. package/dist/core/mods/classic-events.d.ts +5 -1
  166. package/dist/core/mods/kernel/dispatch.d.ts +5 -1
  167. package/dist/core/mods/kernel/dispatch.js +6 -5
  168. package/dist/core/mods/kernel/events.d.ts +11 -4
  169. package/dist/core/mods/kernel/events.js +11 -7
  170. package/dist/core/mods/kernel/receive.d.ts +5 -0
  171. package/dist/core/mods/kernel/receive.js +10 -0
  172. package/dist/core/mods/kernel/registration.d.ts +4 -0
  173. package/dist/core/mods/kernel/registration.js +3 -0
  174. package/dist/core/mods/lifecycle-stations.d.ts +41 -0
  175. package/dist/core/mods/lifecycle-stations.js +35 -0
  176. package/dist/core/mods/stations.d.ts +73 -60
  177. package/dist/core/mods/stations.js +64 -40
  178. package/dist/core/mods/tool-call.d.ts +10 -4
  179. package/dist/core/mods/tool-call.js +28 -12
  180. package/dist/core/mounted-mcp.d.ts +5 -0
  181. package/dist/core/mounted-mcp.js +2 -2
  182. package/dist/core/namespaced-rule-name.d.ts +7 -1
  183. package/dist/core/namespaced-rule-name.js +13 -2
  184. package/dist/core/oracle-isolation.js +1 -1
  185. package/dist/core/own-property-receipt.d.ts +3 -0
  186. package/dist/core/own-property-receipt.js +3 -0
  187. package/dist/core/parent-spec-seat.d.ts +8 -3
  188. package/dist/core/parent-spec-seat.js +2 -0
  189. package/dist/core/park-selfcheck.js +14 -8
  190. package/dist/core/peer-seat.d.ts +133 -16
  191. package/dist/core/peer-seat.js +319 -42
  192. package/dist/core/permission-rule-consent.d.ts +0 -21
  193. package/dist/core/permission-rule-consent.js +11 -6
  194. package/dist/core/permission-rule-model.d.ts +20 -2
  195. package/dist/core/permission-rule-model.js +8 -7
  196. package/dist/core/present-plan-tool.d.ts +11 -3
  197. package/dist/core/present-plan-tool.js +2 -2
  198. package/dist/core/protocol-http-auth.d.ts +14 -2
  199. package/dist/core/protocol-http-auth.js +16 -7
  200. package/dist/core/read-face-seats.d.ts +7 -5
  201. package/dist/core/read-face-seats.js +4 -1
  202. package/dist/core/redaction-marks.d.ts +4 -3
  203. package/dist/core/redaction-marks.js +2 -2
  204. package/dist/core/remote-env.d.ts +146 -98
  205. package/dist/core/remote-env.js +113 -14
  206. package/dist/core/resume-startup-cause.js +1 -0
  207. package/dist/core/retention.js +37 -12
  208. package/dist/core/retired-keys.d.ts +6 -1
  209. package/dist/core/retired-keys.js +4 -1
  210. package/dist/core/rewrite-rejudge.d.ts +13 -5
  211. package/dist/core/rewrite-rejudge.js +9 -5
  212. package/dist/core/roles.d.ts +69 -3
  213. package/dist/core/roles.js +167 -80
  214. package/dist/core/rule-owner.d.ts +3 -0
  215. package/dist/core/runner/announce-once-ledger.d.ts +5 -4
  216. package/dist/core/runner/announce-once-ledger.js +4 -2
  217. package/dist/core/runner/assemble-result.d.ts +0 -5
  218. package/dist/core/runner/assemble-result.js +0 -1
  219. package/dist/core/runner/call-hook-stations.d.ts +17 -10
  220. package/dist/core/runner/call-hook-stations.js +23 -12
  221. package/dist/core/runner/child-tree.d.ts +7 -8
  222. package/dist/core/runner/child-tree.js +6 -6
  223. package/dist/core/runner/classifier-ladder.d.ts +10 -2
  224. package/dist/core/runner/classifier-ladder.js +39 -8
  225. package/dist/core/runner/construction-doors.js +5 -0
  226. package/dist/core/runner/contracts.d.ts +82 -57
  227. package/dist/core/runner/credential-origin-seat.js +4 -3
  228. package/dist/core/runner/cross-boundary-lane.d.ts +3 -5
  229. package/dist/core/runner/cross-boundary-lane.js +11 -2
  230. package/dist/core/runner/cwd-alignment-probe.d.ts +20 -0
  231. package/dist/core/runner/cwd-alignment-probe.js +21 -0
  232. package/dist/core/runner/decide-continuation.d.ts +2 -2
  233. package/dist/core/runner/env-capability-census.d.ts +15 -20
  234. package/dist/core/runner/env-capability-census.js +25 -34
  235. package/dist/core/runner/file-history-request.d.ts +2 -2
  236. package/dist/core/runner/file-history-request.js +0 -8
  237. package/dist/core/runner/gate-exit.d.ts +87 -11
  238. package/dist/core/runner/gate-exit.js +30 -8
  239. package/dist/core/runner/git-status-frame.d.ts +5 -2
  240. package/dist/core/runner/git-status-frame.js +3 -4
  241. package/dist/core/runner/image-removed-seat.d.ts +12 -0
  242. package/dist/core/runner/image-removed-seat.js +19 -0
  243. package/dist/core/runner/image.d.ts +7 -2
  244. package/dist/core/runner/image.js +14 -8
  245. package/dist/core/runner/inline-image.d.ts +10 -8
  246. package/dist/core/runner/inline-image.js +11 -9
  247. package/dist/core/runner/memory-consolidation-driver.js +5 -5
  248. package/dist/core/runner/park-commit.d.ts +1 -1
  249. package/dist/core/runner/park-commit.js +3 -0
  250. package/dist/core/runner/permission-rule-lanes.js +1 -1
  251. package/dist/core/runner/prepare-ask-lane.d.ts +1 -1
  252. package/dist/core/runner/prepare-ask-lane.js +2 -1
  253. package/dist/core/runner/prepare-boundary-parks.d.ts +2 -2
  254. package/dist/core/runner/prepare-boundary-parks.js +5 -5
  255. package/dist/core/runner/prepare-caps-and-workflow.d.ts +7 -5
  256. package/dist/core/runner/prepare-caps-and-workflow.js +6 -3
  257. package/dist/core/runner/prepare-config-doors.d.ts +6 -1
  258. package/dist/core/runner/prepare-config-doors.js +16 -9
  259. package/dist/core/runner/prepare-context-lane.js +2 -0
  260. package/dist/core/runner/prepare-delegation-surface.d.ts +9 -3
  261. package/dist/core/runner/prepare-delegation-surface.js +5 -4
  262. package/dist/core/runner/prepare-file-history.d.ts +10 -12
  263. package/dist/core/runner/prepare-file-history.js +3 -12
  264. package/dist/core/runner/prepare-gate-stations.d.ts +4 -3
  265. package/dist/core/runner/prepare-gate-stations.js +4 -3
  266. package/dist/core/runner/prepare-hands-readface.d.ts +7 -1
  267. package/dist/core/runner/prepare-hands-readface.js +19 -6
  268. package/dist/core/runner/prepare-inherited-gate.d.ts +6 -7
  269. package/dist/core/runner/prepare-inherited-gate.js +22 -31
  270. package/dist/core/runner/prepare-memory-engine-session.js +1 -1
  271. package/dist/core/runner/prepare-memory.d.ts +2 -2
  272. package/dist/core/runner/prepare-memory.js +12 -19
  273. package/dist/core/runner/prepare-park-ask.d.ts +4 -6
  274. package/dist/core/runner/prepare-park-ask.js +5 -9
  275. package/dist/core/runner/prepare-policy-chain.d.ts +8 -7
  276. package/dist/core/runner/prepare-policy-chain.js +136 -121
  277. package/dist/core/runner/prepare-project-context.d.ts +2 -2
  278. package/dist/core/runner/prepare-project-context.js +10 -7
  279. package/dist/core/runner/prepare-prompt-inputs.d.ts +5 -2
  280. package/dist/core/runner/prepare-prompt-inputs.js +10 -20
  281. package/dist/core/runner/prepare-protocol-tools.d.ts +5 -3
  282. package/dist/core/runner/prepare-protocol-tools.js +17 -2
  283. package/dist/core/runner/prepare-run-refs.d.ts +2 -3
  284. package/dist/core/runner/prepare-run-refs.js +4 -1
  285. package/dist/core/runner/prepare-suspend-saga.d.ts +0 -2
  286. package/dist/core/runner/prepare-suspend-saga.js +5 -7
  287. package/dist/core/runner/prepare-task.js +44 -28
  288. package/dist/core/runner/prepare-turn-wiring.d.ts +2 -0
  289. package/dist/core/runner/prepare-turn-wiring.js +7 -2
  290. package/dist/core/runner/prepare-wiring-manifest.d.ts +5 -4
  291. package/dist/core/runner/prepare-wiring-manifest.js +34 -19
  292. package/dist/core/runner/prepare-workspace-restore.js +3 -3
  293. package/dist/core/runner/reply-pricing.d.ts +30 -0
  294. package/dist/core/runner/reply-pricing.js +19 -0
  295. package/dist/core/runner/resume-admission.js +4 -2
  296. package/dist/core/runner/resume-apply.js +6 -1
  297. package/dist/core/runner/resume-checkpoint-screen.js +4 -4
  298. package/dist/core/runner/resume-policy-outcome.js +5 -5
  299. package/dist/core/runner/retired-runner-deps.js +4 -1
  300. package/dist/core/runner/role-seat-defaulted.d.ts +44 -0
  301. package/dist/core/runner/role-seat-defaulted.js +40 -0
  302. package/dist/core/runner/run-attachment-seats.js +3 -3
  303. package/dist/core/runner/run-brain-sinks.js +3 -0
  304. package/dist/core/runner/run-git-lane.d.ts +3 -1
  305. package/dist/core/runner/run-git-lane.js +1 -1
  306. package/dist/core/runner/run-harness-handlers.d.ts +3 -1
  307. package/dist/core/runner/run-harness-handlers.js +3 -1
  308. package/dist/core/runner/run-identity-wiring.d.ts +2 -5
  309. package/dist/core/runner/run-identity-wiring.js +6 -5
  310. package/dist/core/runner/run-leg.d.ts +2 -0
  311. package/dist/core/runner/run-leg.js +63 -56
  312. package/dist/core/runner/run-notification-lane.d.ts +3 -1
  313. package/dist/core/runner/run-notification-lane.js +16 -10
  314. package/dist/core/runner/run-settle-and-teardown.js +5 -1
  315. package/dist/core/runner/run-stop-and-final-verify.d.ts +4 -0
  316. package/dist/core/runner/run-stop-and-final-verify.js +14 -6
  317. package/dist/core/runner/run-terminal-adoption.d.ts +2 -5
  318. package/dist/core/runner/run-terminal-adoption.js +9 -3
  319. package/dist/core/runner/run-turn-boundary.js +89 -77
  320. package/dist/core/runner/runtask.d.ts +8 -5
  321. package/dist/core/runner/runtask.js +21 -13
  322. package/dist/core/runner/side-call-account.d.ts +1 -1
  323. package/dist/core/runner/side-call-account.js +3 -18
  324. package/dist/core/runner/skills-seat.js +2 -2
  325. package/dist/core/runner/sub-agent-deny-lists.d.ts +24 -0
  326. package/dist/core/runner/sub-agent-deny-lists.js +20 -7
  327. package/dist/core/runner/synthetic-tools.js +2 -2
  328. package/dist/core/runner/tool-disclosure.js +0 -2
  329. package/dist/core/runner/tool-end-body.js +2 -2
  330. package/dist/core/runner/tool-face-overlay.d.ts +1 -1
  331. package/dist/core/runner/tool-face-overlay.js +26 -19
  332. package/dist/core/runner/tool-occurrence.d.ts +1 -1
  333. package/dist/core/runner/tool-occurrence.js +2 -2
  334. package/dist/core/runner/tool-result-media-seat.d.ts +9 -1
  335. package/dist/core/runner/tool-result-media-seat.js +17 -1
  336. package/dist/core/runner/turn-attachments.d.ts +29 -27
  337. package/dist/core/runner/turn-attachments.js +27 -42
  338. package/dist/core/runner-deps.d.ts +32 -19
  339. package/dist/core/secret-env.d.ts +35 -4
  340. package/dist/core/secret-env.js +65 -3
  341. package/dist/core/sensitive-path-policy.js +3 -3
  342. package/dist/core/session-policy-store.d.ts +12 -3
  343. package/dist/core/session-policy-store.js +29 -10
  344. package/dist/core/session-store.d.ts +5 -7
  345. package/dist/core/session-store.js +50 -11
  346. package/dist/core/side-query.d.ts +11 -1
  347. package/dist/core/side-query.js +9 -0
  348. package/dist/core/skill-grant-binding.d.ts +31 -2
  349. package/dist/core/skill-grant-binding.js +31 -1
  350. package/dist/core/skill-grant.d.ts +17 -5
  351. package/dist/core/skill-grant.js +24 -6
  352. package/dist/core/store-contracts/background-agent-store-contract.js +27 -0
  353. package/dist/core/store-contracts/checkpoint-store-contract.js +3 -2
  354. package/dist/core/store-contracts/mailbox-store-contract.js +31 -1
  355. package/dist/core/store-contracts/tool-result-store-contract.d.ts +1 -1
  356. package/dist/core/store-contracts/tool-result-store-contract.js +37 -0
  357. package/dist/core/stub-env.d.ts +5 -5
  358. package/dist/core/stub-env.js +11 -1
  359. package/dist/core/swappable-deps.d.ts +17 -43
  360. package/dist/core/swappable-deps.js +15 -5
  361. package/dist/core/synthetic-read-verdict.d.ts +1 -1
  362. package/dist/core/synthetic-read-verdict.js +2 -1
  363. package/dist/core/task-event.d.ts +50 -10
  364. package/dist/core/task-notification.d.ts +88 -5
  365. package/dist/core/task-notification.js +146 -17
  366. package/dist/core/task-registry-agent.d.ts +18 -12
  367. package/dist/core/task-registry-agent.js +19 -6
  368. package/dist/core/task-registry-monitor.d.ts +7 -0
  369. package/dist/core/task-registry-monitor.js +28 -1
  370. package/dist/core/task-registry-shared.d.ts +43 -3
  371. package/dist/core/task-registry-shared.js +21 -7
  372. package/dist/core/task-registry-workflow.js +1 -1
  373. package/dist/core/task-registry.d.ts +50 -35
  374. package/dist/core/task-registry.js +64 -23
  375. package/dist/core/task-result.d.ts +3 -12
  376. package/dist/core/task-spec.d.ts +15 -7
  377. package/dist/core/task-stream.d.ts +1 -1
  378. package/dist/core/terminal-cause.d.ts +10 -0
  379. package/dist/core/tool-catalog-entries.js +1 -1
  380. package/dist/core/tool-check-reading.d.ts +1 -0
  381. package/dist/core/tool-check-reading.js +3 -3
  382. package/dist/core/tool-face-reader.d.ts +7 -6
  383. package/dist/core/tool-face-reader.js +4 -3
  384. package/dist/core/tool-name-aliases.d.ts +19 -0
  385. package/dist/core/tool-name-aliases.js +54 -2
  386. package/dist/core/tool-policy.d.ts +21 -4
  387. package/dist/core/tool-policy.js +1 -1
  388. package/dist/core/tool-registry.d.ts +5 -5
  389. package/dist/core/tool-registry.js +2 -2
  390. package/dist/core/tool-result-store.d.ts +88 -5
  391. package/dist/core/tool-result-store.js +51 -12
  392. package/dist/core/tool-roster.d.ts +112 -5
  393. package/dist/core/tool-roster.js +42 -1
  394. package/dist/core/tool-spec.d.ts +23 -5
  395. package/dist/core/trace.d.ts +0 -1
  396. package/dist/core/types.d.ts +5 -5
  397. package/dist/core/types.js +2 -2
  398. package/dist/core/untrusted-text.js +1 -1
  399. package/dist/core/user-attachment.d.ts +10 -5
  400. package/dist/core/user-attachment.js +15 -7
  401. package/dist/core/wiring-manifest.d.ts +6 -3
  402. package/dist/engine/compaction/compaction.js +29 -3
  403. package/dist/engine/execution-env/node-execution-env.d.ts +11 -5
  404. package/dist/engine/execution-env/node-execution-env.js +21 -13
  405. package/dist/engine/harness/agent-harness.d.ts +26 -3
  406. package/dist/engine/harness/agent-harness.js +49 -16
  407. package/dist/engine/harness/messages.d.ts +3 -1
  408. package/dist/engine/harness/messages.js +3 -2
  409. package/dist/engine/harness/types.d.ts +119 -28
  410. package/dist/engine/llm/rejected-images.d.ts +46 -0
  411. package/dist/engine/llm/rejected-images.js +54 -0
  412. package/dist/engine/llm/tool-turns.d.ts +2 -1
  413. package/dist/engine/llm/types.d.ts +18 -7
  414. package/dist/engine/loop/agent-loop.d.ts +20 -12
  415. package/dist/engine/loop/agent-loop.js +205 -36
  416. package/dist/engine/loop/types.d.ts +12 -3
  417. package/dist/engine/lsp/node-lsp-manager.d.ts +3 -3
  418. package/dist/engine/lsp/node-lsp-manager.js +32 -13
  419. package/dist/engine/session/path-to-root.d.ts +38 -0
  420. package/dist/engine/session/path-to-root.js +39 -0
  421. package/dist/engine/session/storage-base.js +4 -21
  422. package/dist/index.d.ts +35 -21
  423. package/dist/index.js +26 -17
  424. package/dist/internal/harness-types.d.ts +1 -1
  425. package/dist/internal/harness.d.ts +1 -0
  426. package/dist/internal/llm.d.ts +1 -0
  427. package/dist/orchestration/run-workflow-tool.d.ts +9 -3
  428. package/dist/orchestration/run-workflow-tool.js +59 -29
  429. package/dist/orchestration/workflow-governance.d.ts +1 -1
  430. package/dist/orchestration/workflow-governance.js +2 -1
  431. package/dist/orchestration/workflow-observe.d.ts +17 -1
  432. package/dist/orchestration/workflow-observe.js +20 -0
  433. package/dist/orchestration/workflow-types.d.ts +32 -7
  434. package/dist/orchestration/workflow.d.ts +4 -0
  435. package/dist/orchestration/workflow.js +762 -491
  436. package/dist/prompts/default.d.ts +1 -10
  437. package/dist/prompts/default.js +0 -2
  438. package/dist/shell/counting-pass.d.ts +50 -0
  439. package/dist/shell/counting-pass.js +502 -0
  440. package/dist/shell/lex.d.ts +4 -2
  441. package/dist/shell/lex.js +93 -34
  442. package/dist/shell/shell-words.d.ts +1 -1
  443. package/dist/shell/shell-words.js +7 -6
  444. package/dist/stores/file/background-agent-store.d.ts +1 -1
  445. package/dist/stores/file/background-agent-store.js +3 -1
  446. package/dist/stores/file/checkpoint-store.d.ts +127 -2
  447. package/dist/stores/file/checkpoint-store.js +19 -14
  448. package/dist/stores/file/file-history-store.d.ts +1 -1
  449. package/dist/stores/file/file-history-store.js +3 -1
  450. package/dist/stores/file/index.d.ts +4 -3
  451. package/dist/stores/file/index.js +17 -8
  452. package/dist/stores/file/mailbox-store.d.ts +1 -1
  453. package/dist/stores/file/mailbox-store.js +9 -11
  454. package/dist/stores/file/memory-store.d.ts +1 -1
  455. package/dist/stores/file/memory-store.js +3 -1
  456. package/dist/stores/file/session-policy-store.d.ts +1 -1
  457. package/dist/stores/file/session-policy-store.js +3 -1
  458. package/dist/stores/file/session-store.d.ts +1 -1
  459. package/dist/stores/file/session-store.js +3 -1
  460. package/dist/stores/file/shared-ledger.d.ts +26 -0
  461. package/dist/stores/file/shared-ledger.js +38 -9
  462. package/dist/stores/file/tool-result-store.d.ts +20 -2
  463. package/dist/stores/file/tool-result-store.js +74 -6
  464. package/dist/stores/file/usage-window-store.d.ts +1 -1
  465. package/dist/stores/file/usage-window-store.js +3 -1
  466. package/dist/stores/file/workflow-journal-store.d.ts +1 -11
  467. package/dist/stores/file/workflow-journal-store.js +3 -2
  468. package/dist/tools/fs/containment-face.d.ts +5 -0
  469. package/dist/tools/fs/encoding.d.ts +13 -4
  470. package/dist/tools/fs/encoding.js +17 -2
  471. package/dist/tools/fs/fs-bash-background-text.d.ts +7 -0
  472. package/dist/tools/fs/fs-bash-background-text.js +1 -0
  473. package/dist/tools/fs/fs-bash.d.ts +14 -4
  474. package/dist/tools/fs/fs-bash.js +29 -35
  475. package/dist/tools/fs/fs-pdf.d.ts +2 -2
  476. package/dist/tools/fs/fs-pdf.js +26 -21
  477. package/dist/tools/fs/fs-read.d.ts +5 -4
  478. package/dist/tools/fs/fs-read.js +35 -18
  479. package/dist/tools/fs/fs-search-tools.js +4 -1
  480. package/dist/tools/fs/fs-shared.d.ts +11 -13
  481. package/dist/tools/fs/fs-shared.js +11 -7
  482. package/dist/tools/fs/fs-write.js +5 -5
  483. package/dist/tools/fs/index.d.ts +14 -8
  484. package/dist/tools/fs/index.js +13 -5
  485. package/dist/tools/fs/program-read-model.d.ts +13 -0
  486. package/dist/tools/fs/program-read-model.js +15 -0
  487. package/dist/tools/fs/program-read-model.rows.js +1 -1
  488. package/dist/tools/fs/read-deny.d.ts +13 -10
  489. package/dist/tools/fs/read-deny.js +25 -5
  490. package/dist/tools/fs/read-floor.d.ts +62 -0
  491. package/dist/tools/fs/read-floor.js +58 -0
  492. package/dist/tools/fs/removal-targets.d.ts +9 -4
  493. package/dist/tools/fs/removal-targets.js +17 -9
  494. package/dist/tools/fs/search.d.ts +3 -3
  495. package/dist/tools/fs/search.js +4 -4
  496. package/dist/tools/fs/shell-read-check.d.ts +1 -1
  497. package/dist/tools/fs/shell-read-check.js +2 -1
  498. package/dist/tools/fs/shell-read-judge.d.ts +16 -8
  499. package/dist/tools/fs/shell-read-judge.js +10 -6
  500. package/dist/tools/fs/shell-read-plan.d.ts +6 -1
  501. package/dist/tools/fs/shell-read-plan.js +22 -15
  502. package/dist/tools/fs/shell-read-start.js +1 -0
  503. package/dist/tools/fs/shell-reentry-text.d.ts +15 -1
  504. package/dist/tools/fs/shell-reentry-text.js +25 -3
  505. package/dist/tools/monitor.d.ts +9 -4
  506. package/dist/tools/monitor.js +17 -8
  507. package/dist/tools/scheduler-tools.js +42 -4
  508. package/dist/tools/web.d.ts +0 -10
  509. package/dist/tools/web.js +1 -4
  510. package/package.json +5 -2
  511. package/test/export-surface.snapshot.json +161 -21
  512. package/wire-changes/core-stores-sql@7.59.0.json +29 -0
  513. package/wire-changes/core-stores-sql@7.60.0.json +30 -0
  514. package/wire-changes/core@7.59.0.json +2459 -0
  515. package/wire-changes/core@7.60.0.json +3274 -0
  516. package/wire-changes/mods-kernel@7.59.0.json +29 -0
  517. package/wire-changes/mods-kernel@7.60.0.json +62 -0
  518. package/wire-changes/primitives@7.59.0.json +29 -0
  519. package/wire-changes/primitives@7.60.0.json +30 -0
@@ -1,14 +1,44 @@
1
1
  import { type MemorySyncCursor } from "./sync.js";
2
2
  import { type MemoryBackend, type MemoryEntry, type PatchReport } from "./types.js";
3
- /** The injected HTTP seam — core never bundles a fetch. The deployment maps `path` (e.g.
4
- * `/v1/memory/sync/user%3Aalice`) onto its server base URL, attaches auth, and returns the
5
- * DECODED JSON body of a 2xx response; any non-2xx / network failure should THROW (the round then
6
- * aborts with zero local side effects — the transport runs before any local write). */
7
- export type MemorySyncTransport = (path: string, body: unknown) => Promise<unknown>;
3
+ type CursorAxis = "scope" | "peer" | "store";
4
+ /** The refusal of a sync that cannot be judged, raised before any read or transport call: the cursor is not this
5
+ * sync's (`config.memory_sync_cursor_mismatch`, with `detail` naming the axis and what the cursor carried there), or
6
+ * the local store has nothing to bind a cursor to (`config.memory_sync_store`, no `detail`). `outs` are the two ways
7
+ * out its sentence names. */
8
+ type SyncRefusal = Error & {
9
+ code: "config.memory_sync_cursor_mismatch" | "config.memory_sync_store";
10
+ detail?: {
11
+ readonly axis: CursorAxis;
12
+ readonly found: "absent" | "other";
13
+ };
14
+ outs: readonly [string, string];
15
+ };
16
+ /** A thrown value read as a sync refusal this module minted, or `undefined` — the report's one reader of the refusal. */
17
+ export declare function readSyncRefusal(thrown: unknown): Pick<SyncRefusal, "code" | "detail" | "outs" | "message"> | undefined;
18
+ /**
19
+ * The identity a sync cursor is bound to — the one mint of {@link MemorySyncCursor.store}: the physical root of
20
+ * the local File store (the path its root anchor records). A store without a directory has no root to bind a
21
+ * baseline to and is refused as a sync plane (`config.memory_sync_store`).
22
+ */
23
+ export declare function memorySyncStoreOf(backend: MemoryBackend): string;
24
+ /** The injected seam to ONE peer — core never bundles a fetch. */
25
+ export interface MemorySyncTransport {
26
+ /** The addressing identity of the peer `post` reaches (a central sync API: its normalized base URL) and the
27
+ * round's only source of its peer; another peer carries another identity. Rides the wire and the cursor
28
+ * verbatim — never a credential: an identity that is empty or only whitespace, a URL with userinfo, or one the
29
+ * same-principal egress pass would redact is refused before any read or request. Read once per call, and
30
+ * taken at its word: the engine cannot see where `post` actually sends. */
31
+ readonly peer: string;
32
+ /** Maps `path` (e.g. `/v1/memory/sync/user%3Aalice`) onto the peer, attaches auth, and returns the DECODED
33
+ * JSON body of a 2xx response; any non-2xx / network failure should THROW (the round then aborts with zero
34
+ * local side effects — the transport runs before any local write). */
35
+ post(path: string, body: unknown): Promise<unknown>;
36
+ }
8
37
  /** The wire REQUEST of one round (the server's `parseMemorySyncRequest` twin): the push
9
38
  * half as computed against the client's own cursor. `deletes` ⊆ `Object.keys(baseRevs)` by
10
39
  * construction (a delete is CAS'd on its baseline; an id never synced cannot be delete-propagated). */
11
40
  export interface MemorySyncRequestBody {
41
+ /** The transport's {@link MemorySyncTransport.peer}. */
12
42
  peer: string;
13
43
  /** id → rev at the last completed round (the cursor's baseRevs; empty = first round). */
14
44
  baseRevs: Record<string, string>;
@@ -79,12 +109,18 @@ export interface SyncMemoryScopeOptions {
79
109
  backend: MemoryBackend;
80
110
  /** The scope this round syncs (one round = one scope, mirroring the server route). */
81
111
  scope: string;
82
- /** The injected HTTP seam. */
112
+ /** The injected seam to the peer; its `peer` is the round's peer. */
83
113
  transport: MemorySyncTransport;
84
- /** The persisted cursor from the last completed round with this peer; absent = first round. */
114
+ /** The persisted cursor from the last completed sync with this transport's peer; absent = the first sync. A
115
+ * cursor for another scope, peer or local store — or one with no peer or store binding — is refused
116
+ * (`config.memory_sync_cursor_mismatch`) before any I/O; the refusal carries `detail: { axis, found }` and the two
117
+ * ways out its sentence names (`outs`): for a scope, that partition's own cursor or none before its first completed
118
+ * sync; for a peer, re-bind over a transport that reaches the cursor's peer, or drop the cursor; for a store, rebind
119
+ * the cursor to this store (its `store` set to `memorySyncStoreOf(backend)`) when this store holds the entries its
120
+ * baseline was taken over, or delete it and sync from none, which brings back an entry deleted on either side since
121
+ * the last completed sync. The engine takes none of them on the host's behalf; `memorySyncReportOf` reads the
122
+ * refusal for a host. */
85
123
  cursor?: MemorySyncCursor;
86
- /** Peer name for the cursor partition (defaults to the cursor's peer, else "central"). */
87
- peer?: string;
88
124
  /** Caller-injected clock (engine precedent) — stamps the returned cursor's updatedAtMs. */
89
125
  now?: () => number;
90
126
  /** push-half batching: cap the number of push-half ENTRIES sent this round. The full
@@ -145,9 +181,15 @@ export interface MemorySyncClientResult {
145
181
  * pulled) or, for an unknown id, a spurious push-half DELETE of an entry never seen here. */
146
182
  warnings?: string[];
147
183
  }
184
+ /** Does a name a sync carries verbatim (a peer identity, a target, a scope key) hold a credential — a URL with userinfo
185
+ * (any, a bare user name included: the slot is the credential's), or anything the same-principal egress pass would
186
+ * redact? Such a name is refused, never cleaned: a cleaned identity is another identity, and the cursor taken under it
187
+ * would not be this peer's. The one test for the sync client and its report. */
188
+ export declare function carriesCredential(peer: string): boolean;
148
189
  /**
149
190
  * One full CLIENT sync round for one (scope, peer) against the central sync API — see the
150
191
  * module header for the ①-⑤ flow and the cursor retention discipline. Pure orchestration: all I/O
151
192
  * rides the injected backend/transport; the caller persists the returned cursor.
152
193
  */
153
194
  export declare function syncMemoryScope(opts: SyncMemoryScopeOptions): Promise<MemorySyncClientResult>;
195
+ export {};
@@ -4,6 +4,81 @@ import { scanMemoryFileName, scanMemoryWrite } from "./scan.js";
4
4
  import { MAX_MEMORY_BYTES } from "../memory.js";
5
5
  import { reconcileMemoryEntries } from "./sync.js";
6
6
  import { MEMORY_ORIGIN_CAUSES } from "./types.js";
7
+ import { directoryPinOf } from "./dual-root.js";
8
+ import { landingPathOf } from "./layout.js";
9
+ import { egressText } from "../untrusted-egress.js";
10
+ import { REDACTION_MARKS } from "../redaction-marks.js";
11
+ const REFUSAL_ROWS = {
12
+ scope: {
13
+ why: "a cursor is the baseline of one (scope, peer) partition",
14
+ outs: () => ["pass this partition's own cursor", "pass none before the partition's first completed round"],
15
+ },
16
+ peer: {
17
+ why: "a baseline taken elsewhere would misjudge every entry",
18
+ outs: (want) => [
19
+ "re-bind — run this layer over a transport that reaches the peer the cursor was taken against, or, " +
20
+ `only when this transport reaches that same peer under a new identity, set the cursor's peer to ${quoted(want)}`,
21
+ "drop the cursor to accept re-convergence from an empty baseline — entries changed on both sides are reported as conflicts, " +
22
+ "and entries deleted on one side since the last round come back from the other side",
23
+ ],
24
+ },
25
+ store: {
26
+ why: "its baseline describes another store's entries, so this round is refused, not run on that baseline or without one",
27
+ outs: () => [
28
+ "rebind — when this store holds the entries the baseline was taken over (the same store, moved to this root or bound before " +
29
+ "cursors carried a store), persist the cursor with its store set to this store's identity (memorySyncStoreOf) and sync again",
30
+ "clear — delete the cursor and sync from none, accepting that an entry deleted on either side since the last completed round " +
31
+ "comes back from the other side",
32
+ ],
33
+ },
34
+ "store-plane": {
35
+ why: "a sync baseline is bound to a File store's root, and this store has none",
36
+ outs: () => [
37
+ "sync the File store that holds this scope",
38
+ "leave this store out of the sync — a store with no directory is not a sync plane",
39
+ ],
40
+ },
41
+ };
42
+ const MINTED_REFUSALS = new WeakSet();
43
+ function syncRefusal(on, head, want) {
44
+ const row = REFUSAL_ROWS[on === "store-plane" ? on : on.axis];
45
+ const [first, second] = row.outs(want);
46
+ const outs = Object.freeze([egressText("same-principal", first), egressText("same-principal", second)]);
47
+ const e = new Error(egressText("same-principal", `memory sync: ${head} — ${row.why}; two ways out: (1) ${outs[0]}; (2) ${outs[1]}`));
48
+ if (on === "store-plane") {
49
+ e.code = "config.memory_sync_store";
50
+ }
51
+ else {
52
+ e.code = "config.memory_sync_cursor_mismatch";
53
+ e.detail = Object.freeze({ axis: on.axis, found: on.found });
54
+ }
55
+ e.outs = outs;
56
+ MINTED_REFUSALS.add(e);
57
+ return e;
58
+ }
59
+ export function readSyncRefusal(thrown) {
60
+ return typeof thrown === "object" && thrown !== null && MINTED_REFUSALS.has(thrown) ? thrown : undefined;
61
+ }
62
+ export function memorySyncStoreOf(backend) {
63
+ return syncStoreOf(backend).identity;
64
+ }
65
+ function syncStoreOf(backend) {
66
+ const pin = directoryPinOf(backend);
67
+ if (pin === undefined)
68
+ throw syncRefusal("store-plane", "the local store has no directory", "");
69
+ const root = landingPathOf(pin);
70
+ return { root, identity: `file:${root}` };
71
+ }
72
+ function refuseForeignCursor(cursor, scope, peer, store) {
73
+ const axis = [["scope", cursor.scope, scope], ["peer", cursor.peer, peer], ["store", cursor.store, store]];
74
+ for (const [name, got, want] of axis) {
75
+ if (got === want)
76
+ continue;
77
+ const found = got === undefined ? "absent" : "other";
78
+ const head = found === "absent" ? `cursor has no ${name} binding` : `cursor is for ${name} ${quoted(got)}`;
79
+ throw syncRefusal({ axis: name, found }, `${head}; this round's ${name} is ${quoted(want)}`, want);
80
+ }
81
+ }
7
82
  function memorySyncPath(scope) {
8
83
  return `/v1/memory/sync/${encodeURIComponent(scope)}`;
9
84
  }
@@ -12,9 +87,26 @@ function baselineStub(id, rev, scope) {
12
87
  }
13
88
  const isRecord = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
14
89
  const isNonEmptyString = (v) => typeof v === "string" && v.length > 0;
90
+ const namesSomething = (v) => typeof v === "string" && v.trim().length > 0;
91
+ function quoted(v) {
92
+ if (typeof v !== "string")
93
+ return JSON.stringify(typeof v);
94
+ return carriesCredential(v) ? REDACTION_MARKS.credentials : JSON.stringify(v);
95
+ }
96
+ export function carriesCredential(peer) {
97
+ if (egressText("same-principal", peer) !== peer)
98
+ return true;
99
+ try {
100
+ const url = new URL(peer);
101
+ return url.username !== "" || url.password !== "";
102
+ }
103
+ catch {
104
+ return false;
105
+ }
106
+ }
15
107
  function parseMemorySyncResponse(raw, scope, peer) {
16
108
  const fail = (why) => {
17
- throw new Error(`memory sync: transport response is not a valid sync response (${why})`);
109
+ throw new Error(egressText("same-principal", `memory sync: transport response is not a valid sync response (${why})`));
18
110
  };
19
111
  if (!isRecord(raw))
20
112
  fail("body must be a JSON object { applied, conflicts, serverEntries, serverDeletes, cursor }");
@@ -177,7 +269,7 @@ function parseMemorySyncResponse(raw, scope, peer) {
177
269
  fail("cursor must be an object { peer, baseRevs, updatedAtMs }");
178
270
  const curRec = cur;
179
271
  if (curRec["peer"] !== peer)
180
- fail(`cursor.peer ${JSON.stringify(curRec["peer"])} does not match the requested peer ${JSON.stringify(peer)}`);
272
+ fail(`cursor.peer ${quoted(curRec["peer"])} does not match the requested peer ${quoted(peer)}`);
181
273
  if (!isRecord(curRec["baseRevs"]))
182
274
  fail("cursor.baseRevs must be an object mapping id → rev");
183
275
  const baseRevs = {};
@@ -203,16 +295,18 @@ function parseMemorySyncResponse(raw, scope, peer) {
203
295
  }
204
296
  export async function syncMemoryScope(opts) {
205
297
  const { backend, scope, transport, cursor } = opts;
206
- if (!isNonEmptyString(scope))
298
+ if (!namesSomething(scope))
207
299
  throw new Error("memory sync: scope must be a non-empty string");
208
- const peer = opts.peer ?? cursor?.peer ?? "central";
209
- const now = opts.now ?? Date.now;
210
- if (cursor !== undefined && cursor.scope !== scope) {
211
- throw new Error(`memory sync: cursor is for scope ${JSON.stringify(cursor.scope)}, not ${JSON.stringify(scope)}`);
212
- }
213
- if (cursor !== undefined && cursor.peer !== peer) {
214
- throw new Error(`memory sync: cursor is for peer ${JSON.stringify(cursor.peer)}, not ${JSON.stringify(peer)}`);
300
+ const peer = transport?.peer;
301
+ if (!namesSomething(peer))
302
+ throw new Error("memory sync: transport.peer must be a non-empty string — a transport is { peer, post }, peer = the identity of the peer it reaches");
303
+ if (carriesCredential(peer)) {
304
+ throw new Error(`memory sync: transport.peer ${quoted(peer)} carries a credential — the identity rides the wire, the cursor and refusal sentences verbatim, so it is never a credential: name the peer without userinfo or secret`);
215
305
  }
306
+ const now = opts.now ?? Date.now;
307
+ const { root: storeRoot, identity: store } = syncStoreOf(backend);
308
+ if (cursor !== undefined)
309
+ refuseForeignCursor(cursor, scope, peer, store);
216
310
  for (const [name, v] of [["maxPushEntries", opts.maxPushEntries], ["maxPullEntries", opts.maxPullEntries], ["maxEntryBytes", opts.maxEntryBytes]]) {
217
311
  if (v !== undefined && (!Number.isSafeInteger(v) || v < 1)) {
218
312
  throw new Error(`memory sync: ${name} must be a positive integer (>= 1) when set, got ${String(v)}`);
@@ -259,7 +353,7 @@ export async function syncMemoryScope(opts) {
259
353
  deletes: plan.deleteRemote.map((d) => d.id),
260
354
  ...(opts.maxPullEntries !== undefined ? { pull: { limit: opts.maxPullEntries } } : {}),
261
355
  };
262
- const resp = parseMemorySyncResponse(await transport(memorySyncPath(scope), request), scope, peer);
356
+ const resp = parseMemorySyncResponse(await transport.post(memorySyncPath(scope), request), scope, peer);
263
357
  const conflicts = [...pushGateConflicts, ...resp.conflicts.map((c) => ({ side: "server", ...c }))];
264
358
  const rejected = new Set();
265
359
  const localIds = new Set(local.map((e) => e.id));
@@ -341,7 +435,7 @@ export async function syncMemoryScope(opts) {
341
435
  }),
342
436
  ...deletePatches,
343
437
  ];
344
- const report = patches.length > 0 ? await backend.applyPatches(patches) : { applied: [], conflicts: [] };
438
+ const report = patches.length > 0 ? await backend.applyPatches(patches, { anchoredRoot: storeRoot }) : { applied: [], conflicts: [] };
345
439
  for (const c of report.conflicts) {
346
440
  conflicts.push({
347
441
  side: "local",
@@ -388,7 +482,7 @@ export async function syncMemoryScope(opts) {
388
482
  nextBaseRevs[op.id] = landedRev;
389
483
  }
390
484
  }
391
- nextCursor = { scope, peer, baseRevs: nextBaseRevs, updatedAtMs: now() };
485
+ nextCursor = { scope, peer, store, baseRevs: nextBaseRevs, updatedAtMs: now() };
392
486
  }
393
487
  return {
394
488
  ok: cursorAdvanced && conflicts.length === 0,
@@ -0,0 +1,103 @@
1
+ import { type MemorySyncClientConflict, type MemorySyncClientResult } from "./sync-client.js";
2
+ import type { PatchReport } from "./types.js";
3
+ /** What a layer's calls landed, both halves, in call order (`serverApplied` / `localApplied` verbatim). A replayed
4
+ * call lands nothing and is still synced: whether a layer arrived is its `outcome`, never these counts. */
5
+ type LayerApplied = {
6
+ readonly server: PatchReport["applied"];
7
+ readonly local: PatchReport["applied"];
8
+ };
9
+ /** One layer of a memory sync — one scope, one outcome, and what all its calls landed. */
10
+ export type MemorySyncLayerReport = {
11
+ readonly scope: string;
12
+ readonly applied: LayerApplied;
13
+ } & ({
14
+ readonly outcome: "synced";
15
+ } | {
16
+ readonly outcome: "incomplete";
17
+ readonly why: "conflicts" | "truncated";
18
+ /** The last call's conflicts (server-reported and local), never hidden. */
19
+ readonly conflicts: readonly MemorySyncClientConflict[];
20
+ /** The answers the client refused to take from the server, as the call disclosed them. */
21
+ readonly warnings?: readonly string[];
22
+ } | {
23
+ readonly outcome: "refused";
24
+ readonly code: "config.memory_sync_cursor_mismatch" | "config.memory_sync_store";
25
+ /** Present on a cursor refusal: the axis it was refused on and whether the cursor carried no binding there
26
+ * (`absent`) or another one (`other`). */
27
+ readonly detail?: {
28
+ readonly axis: "scope" | "peer" | "store";
29
+ readonly found: "absent" | "other";
30
+ };
31
+ /** The two ways out the sentence names — both the host's to take, the engine takes neither. */
32
+ readonly outs: readonly [string, string];
33
+ readonly message: string;
34
+ } | {
35
+ readonly outcome: "failed";
36
+ readonly error: string;
37
+ });
38
+ /** A memory sync as a host reports it: the destination it was run for, the source revision it was run against, the
39
+ * source session's read set, and either its layers or its own refusal (no layer run, no request sent). */
40
+ export type MemorySyncRoundReport = {
41
+ /** The engine declaration the session goes to, as the host named it. */
42
+ readonly target: string;
43
+ /** The source session's revision the sync was run against, as the host named it. */
44
+ readonly sourceRevision: string;
45
+ /** The source session's read set — every scope key it reads, in its order. A scope with no layer was not synced. */
46
+ readonly scopes: readonly string[];
47
+ } & ({
48
+ readonly layers: readonly MemorySyncLayerReport[];
49
+ } | {
50
+ readonly refused: {
51
+ /** `config.memory_sync_target_mismatch`: the machine's sync reaches another peer than the engine the session
52
+ * goes to. `session_active`: the source session has a run in flight. */
53
+ readonly code: "config.memory_sync_target_mismatch" | "session_active";
54
+ readonly message: string;
55
+ };
56
+ });
57
+ /** One call of a layer as the host ran it: the scope, and how `syncMemoryScope` settled — its result or what it threw. */
58
+ type LayerCall = {
59
+ readonly scope: string;
60
+ } & ({
61
+ readonly result: MemorySyncClientResult;
62
+ } | {
63
+ readonly thrown: unknown;
64
+ });
65
+ /** A sync refused before any layer ran: the target mismatch carries the peer the machine's sync reaches (the sentence is
66
+ * minted here); a session in flight carries the host's own sentence for its code. */
67
+ type RoundRefusal = {
68
+ readonly code: "config.memory_sync_target_mismatch";
69
+ readonly reaches: string;
70
+ } | {
71
+ readonly code: "session_active";
72
+ readonly message: string;
73
+ };
74
+ type GapWhy = "refused" | "failed" | "incomplete" | "not_replicated" | "not_read_at_destination";
75
+ /**
76
+ * THE report of a memory sync — the one reading of how its `syncMemoryScope` calls settled, for every host that runs or
77
+ * relays one. Give it the destination (`target`), the source revision, the source session's read set (`scopes`), and
78
+ * either each call of each layer in the order they ran (`layers`; a layer continued after a cut appears once per call)
79
+ * or the sync's own refusal (`refused`; no layer ran). A layer outside the read set, a call carrying both or neither of
80
+ * `result` / `thrown`, or a name that is not a non-empty string is refused with a `TypeError`.
81
+ */
82
+ export declare function memorySyncReportOf(round: {
83
+ readonly target: string;
84
+ readonly sourceRevision: string;
85
+ readonly scopes: readonly string[];
86
+ } & ({
87
+ readonly layers: readonly LayerCall[];
88
+ } | {
89
+ readonly refused: RoundRefusal;
90
+ })): MemorySyncRoundReport;
91
+ /**
92
+ * What of a session's memory does not travel with it: every scope of the report's read set that did not arrive whole,
93
+ * once, with why — `refused` (the sync, or its layer, was refused before any request), `failed`, `incomplete`,
94
+ * `not_replicated` (no layer was run for it), or `not_read_at_destination` (its layer synced, and the destination's
95
+ * read set, when given, does not hold it). A scope absent from the result travelled. Keys are compared as written. A
96
+ * report that is not one this engine's `memorySyncReportOf` could have minted (a layer with no scope, outside the read
97
+ * set, listed twice, or with an outcome this engine does not read) is refused with a `TypeError`.
98
+ */
99
+ export declare function memoryTravelGapOf(report: MemorySyncRoundReport, readAtDestination?: readonly string[]): Array<{
100
+ readonly scope: string;
101
+ readonly why: GapWhy;
102
+ }>;
103
+ export {};
@@ -0,0 +1,119 @@
1
+ import { carriesCredential, readSyncRefusal } from "./sync-client.js";
2
+ import { egressText, egressThrownText } from "../untrusted-egress.js";
3
+ const OUTCOMES = new Set(["synced", "incomplete", "refused", "failed"]);
4
+ const text = (s) => egressText("same-principal", s);
5
+ function requireNamed(what, v) {
6
+ if (typeof v !== "string" || v.trim().length === 0)
7
+ throw new TypeError(`memory sync report: ${what} must be a non-empty string`);
8
+ if (carriesCredential(v))
9
+ throw new TypeError(`memory sync report: ${what} carries a credential — a name the report carries verbatim never does`);
10
+ return v;
11
+ }
12
+ const appliedOf = (ops) => ops.map((op) => (op.slug !== undefined ? { ...op, slug: text(op.slug) } : { ...op }));
13
+ function requireNames(what, v) {
14
+ if (!Array.isArray(v))
15
+ throw new TypeError(`memory sync report: ${what} must be an array of scope keys`);
16
+ const out = [];
17
+ for (const s of v) {
18
+ const key = requireNamed(`each of ${what}`, s);
19
+ if (!out.includes(key))
20
+ out.push(key);
21
+ }
22
+ return out;
23
+ }
24
+ function hasExactlyOne(v, a, b, what) {
25
+ const hasA = Object.prototype.hasOwnProperty.call(v, a);
26
+ if (hasA === Object.prototype.hasOwnProperty.call(v, b))
27
+ throw new TypeError(`memory sync report: ${what} carries exactly one of { ${a} } and { ${b} }`);
28
+ return hasA;
29
+ }
30
+ function callReport(call) {
31
+ const scope = call.scope;
32
+ if (!hasExactlyOne(call, "result", "thrown", `layer ${JSON.stringify(scope)}`)) {
33
+ const thrown = call.thrown;
34
+ const refusal = readSyncRefusal(thrown);
35
+ const applied = { server: [], local: [] };
36
+ if (refusal !== undefined) {
37
+ return { scope, outcome: "refused", applied, code: refusal.code, ...(refusal.detail !== undefined ? { detail: refusal.detail } : {}), outs: refusal.outs, message: refusal.message };
38
+ }
39
+ return { scope, outcome: "failed", applied, error: egressThrownText("same-principal", thrown) };
40
+ }
41
+ const r = call.result;
42
+ const applied = { server: appliedOf(r.serverApplied), local: appliedOf(r.localApplied) };
43
+ const warnings = (r.warnings ?? []).map(text);
44
+ if (r.ok && r.pushTruncated !== true && r.pullTruncated !== true && warnings.length === 0)
45
+ return { scope, outcome: "synced", applied };
46
+ return {
47
+ scope,
48
+ outcome: "incomplete",
49
+ why: r.ok ? "truncated" : "conflicts",
50
+ applied,
51
+ conflicts: r.conflicts.map((c) => ({ ...c, reason: text(c.reason) })),
52
+ ...(warnings.length > 0 ? { warnings } : {}),
53
+ };
54
+ }
55
+ function foldCall(before, next) {
56
+ return { ...next, applied: { server: [...before.applied.server, ...next.applied.server], local: [...before.applied.local, ...next.applied.local] } };
57
+ }
58
+ export function memorySyncReportOf(round) {
59
+ const target = requireNamed("target", round.target);
60
+ const sourceRevision = requireNamed("sourceRevision", round.sourceRevision);
61
+ const scopes = requireNames("scopes", round.scopes);
62
+ if (!hasExactlyOne(round, "layers", "refused", "a sync")) {
63
+ const refused = round.refused;
64
+ if (refused?.code === "config.memory_sync_target_mismatch") {
65
+ const reaches = requireNamed("refused.reaches", refused.reaches);
66
+ const message = text(`memory sync: the session goes to ${JSON.stringify(target)}, and this machine's memory sync reaches ${JSON.stringify(reaches)} — ` +
67
+ "no layer was synced: memory sent there would not be where the session reads it");
68
+ return { target, sourceRevision, scopes, refused: { code: refused.code, message } };
69
+ }
70
+ if (refused?.code === "session_active") {
71
+ return { target, sourceRevision, scopes, refused: { code: refused.code, message: text(requireNamed("refused.message", refused.message)) } };
72
+ }
73
+ throw new TypeError(`memory sync report: refused.code must be "config.memory_sync_target_mismatch" or "session_active"`);
74
+ }
75
+ const calls = round.layers;
76
+ if (!Array.isArray(calls))
77
+ throw new TypeError("memory sync report: layers must be an array");
78
+ const byScope = new Map();
79
+ for (const call of calls) {
80
+ const scope = requireNamed("each layer's scope", call?.scope);
81
+ if (!scopes.includes(scope))
82
+ throw new TypeError(`memory sync report: layer ${JSON.stringify(scope)} is not in the session's read set`);
83
+ const report = callReport(call);
84
+ const before = byScope.get(scope);
85
+ byScope.set(scope, before === undefined ? report : foldCall(before, report));
86
+ }
87
+ return { target, sourceRevision, scopes, layers: [...byScope.values()] };
88
+ }
89
+ export function memoryTravelGapOf(report, readAtDestination) {
90
+ if (typeof report !== "object" || report === null)
91
+ throw new TypeError("memory travel gap: report must be a memory sync report");
92
+ const scopes = requireNames("report.scopes", report.scopes);
93
+ const destination = readAtDestination === undefined ? undefined : new Set(requireNames("readAtDestination", readAtDestination));
94
+ if (!hasExactlyOne(report, "layers", "refused", "a sync report"))
95
+ return scopes.map((scope) => ({ scope, why: "refused" }));
96
+ const layers = report.layers;
97
+ if (!Array.isArray(layers))
98
+ throw new TypeError("memory travel gap: report.layers must be an array");
99
+ const byScope = new Map();
100
+ for (const layer of layers) {
101
+ const scope = requireNamed("each layer's scope", layer?.scope);
102
+ const outcome = layer.outcome;
103
+ if (!scopes.includes(scope) || byScope.has(scope) || typeof outcome !== "string" || !OUTCOMES.has(outcome)) {
104
+ throw new TypeError(`memory travel gap: layer ${JSON.stringify(scope)} is not one this engine reports (outside the read set, listed twice, or outcome ${JSON.stringify(outcome)})`);
105
+ }
106
+ byScope.set(scope, layer);
107
+ }
108
+ const gap = [];
109
+ for (const scope of scopes) {
110
+ const layer = byScope.get(scope);
111
+ if (layer === undefined)
112
+ gap.push({ scope, why: "not_replicated" });
113
+ else if (layer.outcome !== "synced")
114
+ gap.push({ scope, why: layer.outcome });
115
+ else if (destination !== undefined && !destination.has(scope))
116
+ gap.push({ scope, why: "not_read_at_destination" });
117
+ }
118
+ return gap;
119
+ }
@@ -8,8 +8,15 @@ import type { MemoryEntry, ScoredMemoryEntry } from "./types.js";
8
8
  */
9
9
  export interface MemorySyncCursor {
10
10
  scope: string;
11
- /** The PEER this cursor tracks (e.g. "central", a repo remote name) — one cursor per peer. */
11
+ /** The identity of the PEER the baseline was taken against (`MemorySyncTransport.peer`); a round over
12
+ * another peer refuses the cursor. One cursor per peer. */
12
13
  peer: string;
14
+ /** The LOCAL store the baseline was taken against (minted by `memorySyncStoreOf`, sync-client.ts).
15
+ * A sync over any other store refuses the cursor: the baseline describes another store's
16
+ * entries, and an id it holds that this store lacks would be pushed as a delete. Persist it
17
+ * verbatim with the rest of the cursor; the host rebinds it (this member set to the new store's
18
+ * identity) only when the new store holds the entries the baseline was taken over. */
19
+ store: string;
13
20
  /** id → rev at the last completed sync round with this peer. */
14
21
  baseRevs: Record<string, string>;
15
22
  /** Caller-injected clock (never Date.now inside the engine — clock-injection precedent). */
@@ -586,6 +586,12 @@ export interface MemoryAnnouncement {
586
586
  * degradation, applied-patch summary); `external` = out-of-session changes the backend's read-side
587
587
  * detected (disk rev ≠ ledger: adopted external edits + inbound-gate rejects). */
588
588
  kind: "gate" | "external";
589
+ /** The one scope this notice reports on — the queue it is filed under, and therefore who reads it:
590
+ * only a session that mounts this scope drains it. Required: a notice that cannot name one scope
591
+ * (a count over several scopes, a fact of the whole control plane, a session-level event with no
592
+ * scope in hand) is not a model-face notice at all — the engine sends it to the host's incident
593
+ * sink instead, so no session reads a name or a count of a scope it does not mount. */
594
+ scope: string;
589
595
  /** ms epoch at enqueue. */
590
596
  at: number;
591
597
  /** Optional producing-session id (repo-level event stream — Q-G: no worktree attribution in S2). */
@@ -134,6 +134,13 @@ export declare function mountedToolRequiresUserInteraction(tools: readonly Agent
134
134
  * A name the roster does not carry dispatches nowhere and is not judged here.
135
135
  */
136
136
  export declare function planRefusesWrite(req: ToolCallRequest, roster: ToolRoster | undefined, readOnlyDeclared?: (toolName: string) => boolean): boolean;
137
+ /**
138
+ * Does a question of the MODE reach a call of this tool — its unstated question (the tool declares the `passthrough` seat
139
+ * and the mode asks one, {@link asksUnstated}) or its write gate (a covered path write; under `plan`, every write
140
+ * {@link planRefusesWrite} names)? Read on the tool's face as the roster mints it — its declarations, never a call's
141
+ * arguments — by the load-time ungated-write warning, which names a caller's write-capable tool no question of the mode reaches.
142
+ */
143
+ export declare function modeQuestionReaches(mode: PermissionMode, roster: ToolRoster, toolName: string, seat: "passthrough" | undefined): boolean;
137
144
  /**
138
145
  * The mode's WRITE GATE as one live policy layer: every call reads the mode ref and dispatches to the gate the
139
146
  * table names for it, so a steer changes the next call's gate without re-composing the chain. The three gates are
@@ -165,7 +172,8 @@ export declare function modeRequestAfterResume(seat: PermissionMode | undefined,
165
172
  * the closed set (`config.permission_mode_invalid`); a `shellGate` value other than the floor word `"always"`
166
173
  * (`config.shell_gate_value_retired` — `"off"` / `"classify"` were a doctrine the mode arbitration replaced). The
167
174
  * value it screened is the value it RETURNS — the mode seat reads this snapshot, never the caller's spec again. The ONE
168
- * function both entrances call: prepare (a run's spec, in its pre-first-await stretch) and the resume ladder's admission rung
175
+ * function both entrances call: prepare (a run's spec as the caller handed it, before the config doors rebind it, in its
176
+ * pre-first-await stretch) and the resume ladder's admission rung
169
177
  * (the re-supplied config, before the claim) — a resume prepare would refuse is refused before it consumes the row.
170
178
  */
171
179
  export declare function refusePermissionModeDoors(spec: Pick<TaskSpec, "permissionMode" | "shellGate">): PermissionMode | undefined;
@@ -1,7 +1,7 @@
1
1
  import { createFsWriteGatePolicy } from "./fs-write-gate-policy.js";
2
2
  import { isProtectedWrite } from "./tool-registry.js";
3
3
  import { answeredFor } from "./tool-policy.js";
4
- import { rosterEntryNamed } from "./tool-roster.js";
4
+ import { rosterEntryNamed, toolCallFaceOf } from "./tool-roster.js";
5
5
  import { wireOf } from "./tool-name-readings.js";
6
6
  import { clampPermissionMode, isPermissionMode, PERMISSION_MODES } from "./ask-origin.js";
7
7
  import { argvOf, lexShellText } from "../shell/lex.js";
@@ -64,6 +64,16 @@ export function planRefusesWrite(req, roster, readOnlyDeclared) {
64
64
  const row = roster === undefined ? undefined : rosterEntryNamed(roster, wireOf("mode.planRosterRow", req));
65
65
  return row !== undefined && !ENGINE_ROSTER_SOURCES.has(row.source) && row.effect !== "read" && !(row.effectProvenance === "default" && readOnlyDeclared?.(row.name) === true);
66
66
  }
67
+ export function modeQuestionReaches(mode, roster, toolName, seat) {
68
+ const policy = modePolicyOf(mode);
69
+ if (policy.unstated === "ask" && seat === "passthrough")
70
+ return true;
71
+ if (policy.writeGate === "none")
72
+ return false;
73
+ const face = toolCallFaceOf(roster, toolName);
74
+ const call = { toolName, args: {}, toolCallId: "", ...(face !== undefined ? { face } : {}) };
75
+ return policy.writeGate === "plan" ? planRefusesWrite(call, roster) : isProtectedWrite(call);
76
+ }
67
77
  const planAsk = (message) => ({ action: "ask", message, decisionReason: "mode" });
68
78
  export function createModeGatePolicy(modeRef, seats) {
69
79
  const askGate = createFsWriteGatePolicy({ env: seats.env, rootPath: seats.rootPath, defaultWrite: "ask" });
@@ -0,0 +1,39 @@
1
+ import type { Model } from "../internal/llm.js";
2
+ import type { CheckpointErrorReason } from "./checkpoint-store.js";
3
+ import { type ReceiptMode } from "./mods/kernel/receive.js";
4
+ /** The arms of the roles family's refusal (`detail.reason` of `config.unknown_role`): a word the catalog does not hold, a value that is no model
5
+ * reference at all, a role word outside the vocabulary, a role whose whole fallback chain supplies no model. Each is a member of the checkpoint
6
+ * refusal reasons (the resume screen carries it on). */
7
+ export type ModelBindingReason = Extract<CheckpointErrorReason, "unknown_model_ref" | "not_a_model_ref" | "unknown_role_word" | "no_model_for_role">;
8
+ /**
9
+ * The coded refusal of a model binding the engine cannot read — a role's seat, a tier's binding, the model a task names, a catalog entry, a
10
+ * role word outside the vocabulary (`field` names the seat as the sentence does, `reason` the arm). The ONE place the code and its `detail`
11
+ * are built: a value that is no model reference at all, a word the catalog does not hold and a role word nothing holds are the caller's own
12
+ * configuration faults, refused by the roles family's code with the seat and the arm beside it — never as the raw read the lookup would have
13
+ * been (a `TypeError` from a value that is not an object, an uncoded lookup error). The terminal states the same `{ field, reason }`.
14
+ */
15
+ export declare function modelBindingRefusal(field: string, reason: ModelBindingReason, message: string): Error;
16
+ /** Whether a value is a list — total: a revoked Proxy traps even `Array.isArray`, and a refusal's own reading must not throw in its place. */
17
+ export declare function isList(value: unknown): boolean;
18
+ /** A word in a refusal sentence, bounded and quoted; any other kind of value by its kind (rendering it could itself throw). */
19
+ export declare function bindingShown(value: unknown): string;
20
+ /** The model door's mode of the one receipt: the declaration mode, with `headers` read per use. */
21
+ export declare const MODEL_RECEIPT_MODE: ReceiptMode;
22
+ /** Whether `value` is a Model the door minted. */
23
+ export declare function isModelSnapshot(value: unknown): value is Model;
24
+ /**
25
+ * The object a Model snapshot was received from — the read a host keys its own tables by when it compares an engine answer with
26
+ * the Model objects it built (the engine hands back its snapshots, never the caller's objects). A value the door did not mint is
27
+ * its own origin.
28
+ */
29
+ export declare function modelOriginOf(model: Model): Model;
30
+ /**
31
+ * Receive a Model at `seat` (the place the caller wrote it, as every refusal names it; `what` is how the sentence names the value — a
32
+ * Model object written there, or the catalog entry a word resolved to): its frozen snapshot, or the coded refusal. A snapshot comes
33
+ * back as itself. The refusals: a value that is not a plain record (a Proxy, a class instance, `Object.create(x)`, a list, a primitive) or
34
+ * holds a member the receipt cannot copy (a getter that threw, a function, another prototype) — `config.unknown_role` /
35
+ * `not_a_model_ref`; a retired member — `config.deps_retired_key` (its own sentence); a member outside the contract — `not_a_model_ref`
36
+ * (a provider's own parameters belong in `Model.params`); an `id` that is not a non-empty string or an `api` that is not a string —
37
+ * `not_a_model_ref`, naming the member.
38
+ */
39
+ export declare function receiveModel(value: unknown, seat: string, what?: string, note?: string): Model;