@abot-ai/runtime 1.5.0 → 1.6.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 (984) hide show
  1. package/dist/src/bridge/start-agent-bridge.js +22 -0
  2. package/dist/src/capabilities/normal-invocation/contracts.d.ts +11 -0
  3. package/dist/src/capabilities/normal-invocation/contracts.js +1 -0
  4. package/dist/src/capabilities/normal-invocation/validator.js +40 -4
  5. package/dist/src/capabilities/result-budget.d.ts +17 -0
  6. package/dist/src/capabilities/result-budget.js +21 -0
  7. package/dist/src/capabilities/tool-context-text.d.ts +16 -0
  8. package/dist/src/capabilities/tool-context-text.js +30 -0
  9. package/dist/src/capabilities/tool-definition-validator/definition-parser.js +6 -0
  10. package/dist/src/capabilities/tool-definition-validator/event-input-text-options.js +3 -2
  11. package/dist/src/capabilities/tool-event-input-text.d.ts +1 -0
  12. package/dist/src/capabilities/tool-event-input-text.js +2 -1
  13. package/dist/src/capabilities/tool-executor.d.ts +3 -1
  14. package/dist/src/capabilities/tool-executor.js +29 -50
  15. package/dist/src/capabilities/tool-interruption.d.ts +3 -0
  16. package/dist/src/capabilities/tool-interruption.js +6 -0
  17. package/dist/src/capabilities/tool-result-normalization.d.ts +18 -0
  18. package/dist/src/capabilities/tool-result-normalization.js +68 -0
  19. package/dist/src/capabilities/tool-types.d.ts +25 -2
  20. package/dist/src/cli/host-companion-bundle.mjs +474 -212
  21. package/dist/src/cli/host-companion.js +6 -0
  22. package/dist/src/cli/host-permissions.d.ts +7 -0
  23. package/dist/src/cli/host-permissions.js +24 -0
  24. package/dist/src/computer-access/companion/native-messages.js +1 -0
  25. package/dist/src/computer-access/companion/native-permissions.d.ts +14 -0
  26. package/dist/src/computer-access/companion/native-permissions.js +49 -0
  27. package/dist/src/computer-access/companion/native-session.js +4 -0
  28. package/dist/src/computer-access/companion/notification-installation.js +2 -15
  29. package/dist/src/computer-access/companion/notification-macos-bundle.d.ts +3 -0
  30. package/dist/src/computer-access/companion/notification-macos-bundle.js +84 -0
  31. package/dist/src/computer-access/companion/notification-macos.js +1 -1
  32. package/dist/src/computer-access/companion/notification-protocol.d.ts +1 -1
  33. package/dist/src/computer-access/companion/notification-protocol.js +20 -1
  34. package/dist/src/computer-access/companion/notification-readiness.js +2 -1
  35. package/dist/src/computer-access/companion/permission-protocol.d.ts +22 -0
  36. package/dist/src/computer-access/companion/permission-protocol.js +45 -0
  37. package/dist/src/computer-access/companion/protocol.d.ts +2 -1
  38. package/dist/src/computer-access/companion/protocol.js +3 -0
  39. package/dist/src/computer-access/companion/release-version.d.ts +1 -1
  40. package/dist/src/computer-access/companion/release-version.js +1 -1
  41. package/dist/src/computer-access/companion/spark-notification-query.d.ts +2 -0
  42. package/dist/src/computer-access/companion/spark-notification-query.js +62 -0
  43. package/dist/src/computer-access/computer/macos-desktop.js +1 -1
  44. package/dist/src/computer-access/computer/macos-input.js +2 -5
  45. package/dist/src/computer-access/computer/macos-permission-helper.d.ts +4 -0
  46. package/dist/src/computer-access/computer/macos-permission-helper.js +38 -0
  47. package/dist/src/computer-access/host-observation.d.ts +3 -3
  48. package/dist/src/computer-access/native-permission-contract.d.ts +23 -0
  49. package/dist/src/computer-access/native-permission-contract.js +38 -0
  50. package/dist/src/model-gateway/policy/invocation-policy.js +10 -1
  51. package/dist/src/model-gateway/providers/openai/payload.js +8 -0
  52. package/dist/src/model-gateway/structured-output/ollama-format.js +5 -0
  53. package/dist/src/model-gateway/structured-output/openai-format.js +5 -0
  54. package/dist/src/model-gateway/types.d.ts +3 -0
  55. package/dist/src/plugin-contract/manifest.d.ts +2 -1
  56. package/dist/src/plugin-sdk/context-text-result.d.ts +10 -0
  57. package/dist/src/plugin-sdk/context-text-result.js +19 -0
  58. package/dist/src/plugin-sdk/index.d.ts +1 -0
  59. package/dist/src/plugin-sdk/index.js +1 -0
  60. package/dist/src/plugin-sdk/results.d.ts +7 -4
  61. package/dist/src/plugin-sdk/results.js +35 -10
  62. package/dist/src/runtime/adapters/co-worker-resources.d.ts +2 -0
  63. package/dist/src/runtime/adapters/co-worker-resources.js +2 -2
  64. package/dist/src/runtime/adapters/file-session-store.js +6 -0
  65. package/dist/src/runtime/adapters/in-memory-session-store.js +14 -1
  66. package/dist/src/runtime/adapters/long-term-memory/onboarding-service.d.ts +2 -1
  67. package/dist/src/runtime/adapters/long-term-memory/onboarding-service.js +5 -4
  68. package/dist/src/runtime/adapters/passive-learning-runtime.d.ts +2 -1
  69. package/dist/src/runtime/adapters/passive-learning-runtime.js +1 -1
  70. package/dist/src/runtime/adapters/registered-tool-normal-invocations/execution/prepared-execution.js +77 -26
  71. package/dist/src/runtime/adapters/registered-tool-normal-invocations/execution/result-budget.d.ts +11 -0
  72. package/dist/src/runtime/adapters/registered-tool-normal-invocations/execution/result-budget.js +30 -0
  73. package/dist/src/runtime/adapters/registered-tool-normal-invocations/shared/contracts.d.ts +28 -1
  74. package/dist/src/runtime/adapters/registered-tool-payload-plan.d.ts +3 -3
  75. package/dist/src/runtime/adapters/registered-tool-payload-plan.js +4 -4
  76. package/dist/src/runtime/adapters/registered-tool-worker-capabilities/contracts.d.ts +2 -0
  77. package/dist/src/runtime/adapters/registered-tool-worker-capabilities/payload-authoring-result.js +4 -18
  78. package/dist/src/runtime/adapters/registered-tool-worker-capabilities/prepared-execution.js +3 -3
  79. package/dist/src/runtime/adapters/registered-tool-worker-capabilities/result-envelope.d.ts +13 -0
  80. package/dist/src/runtime/adapters/registered-tool-worker-capabilities/result-envelope.js +15 -0
  81. package/dist/src/runtime/adapters/registered-tool-worker-capabilities/result-evidence.d.ts +3 -7
  82. package/dist/src/runtime/adapters/registered-tool-worker-capabilities/result-evidence.js +6 -38
  83. package/dist/src/runtime/adapters/registered-tool-worker-capabilities/result-observer.d.ts +2 -1
  84. package/dist/src/runtime/adapters/registered-tool-worker-capabilities/result-observer.js +14 -6
  85. package/dist/src/runtime/adapters/registered-tool-worker-capabilities/result-references.d.ts +9 -0
  86. package/dist/src/runtime/adapters/registered-tool-worker-capabilities/result-references.js +29 -0
  87. package/dist/src/runtime/adapters/registered-tool-worker-capabilities.js +1 -0
  88. package/dist/src/runtime/adapters/scheduler-executor-dispatch.d.ts +11 -0
  89. package/dist/src/runtime/adapters/scheduler-executor-dispatch.js +10 -0
  90. package/dist/src/runtime/adapters/scheduler-runtime.d.ts +3 -1
  91. package/dist/src/runtime/adapters/scheduler-runtime.js +28 -12
  92. package/dist/src/runtime/automations/agent-assignment.d.ts +8 -0
  93. package/dist/src/runtime/automations/agent-assignment.js +29 -0
  94. package/dist/src/runtime/automations/agent-request-failure.d.ts +2 -0
  95. package/dist/src/runtime/automations/agent-request-failure.js +74 -0
  96. package/dist/src/runtime/automations/agent-session-lifetime.d.ts +11 -0
  97. package/dist/src/runtime/automations/agent-session-lifetime.js +46 -0
  98. package/dist/src/runtime/automations/agent-step-executor.d.ts +35 -0
  99. package/dist/src/runtime/automations/agent-step-executor.js +278 -0
  100. package/dist/src/runtime/automations/agent-tool-scope.d.ts +4 -0
  101. package/dist/src/runtime/automations/agent-tool-scope.js +73 -0
  102. package/dist/src/runtime/automations/archive-management.d.ts +26 -0
  103. package/dist/src/runtime/automations/archive-management.js +50 -0
  104. package/dist/src/runtime/automations/binding-resolution.d.ts +28 -0
  105. package/dist/src/runtime/automations/binding-resolution.js +115 -0
  106. package/dist/src/runtime/automations/branch-result-projection.d.ts +4 -0
  107. package/dist/src/runtime/automations/branch-result-projection.js +15 -0
  108. package/dist/src/runtime/automations/catalog.d.ts +76 -0
  109. package/dist/src/runtime/automations/catalog.js +67 -0
  110. package/dist/src/runtime/automations/definition-contracts.d.ts +128 -0
  111. package/dist/src/runtime/automations/definition-contracts.js +1 -0
  112. package/dist/src/runtime/automations/definition-input.d.ts +3 -0
  113. package/dist/src/runtime/automations/definition-input.js +283 -0
  114. package/dist/src/runtime/automations/dependency-fingerprint.d.ts +9 -0
  115. package/dist/src/runtime/automations/dependency-fingerprint.js +55 -0
  116. package/dist/src/runtime/automations/draft-batch-aliases.d.ts +12 -0
  117. package/dist/src/runtime/automations/draft-batch-aliases.js +94 -0
  118. package/dist/src/runtime/automations/draft-batch.d.ts +29 -0
  119. package/dist/src/runtime/automations/draft-batch.js +147 -0
  120. package/dist/src/runtime/automations/draft-management.d.ts +53 -0
  121. package/dist/src/runtime/automations/draft-management.js +164 -0
  122. package/dist/src/runtime/automations/draft-mutations.d.ts +29 -0
  123. package/dist/src/runtime/automations/draft-mutations.js +219 -0
  124. package/dist/src/runtime/automations/draft-restoration.d.ts +11 -0
  125. package/dist/src/runtime/automations/draft-restoration.js +44 -0
  126. package/dist/src/runtime/automations/effect-admission-lifetime.d.ts +9 -0
  127. package/dist/src/runtime/automations/effect-admission-lifetime.js +31 -0
  128. package/dist/src/runtime/automations/failure-policy.d.ts +8 -0
  129. package/dist/src/runtime/automations/failure-policy.js +9 -0
  130. package/dist/src/runtime/automations/graph-executor.d.ts +23 -0
  131. package/dist/src/runtime/automations/graph-executor.js +227 -0
  132. package/dist/src/runtime/automations/graph-validation.d.ts +29 -0
  133. package/dist/src/runtime/automations/graph-validation.js +271 -0
  134. package/dist/src/runtime/automations/input-batch-selection.d.ts +7 -0
  135. package/dist/src/runtime/automations/input-batch-selection.js +42 -0
  136. package/dist/src/runtime/automations/input-capacity.d.ts +9 -0
  137. package/dist/src/runtime/automations/input-capacity.js +38 -0
  138. package/dist/src/runtime/automations/input-ledger.d.ts +45 -0
  139. package/dist/src/runtime/automations/input-ledger.js +147 -0
  140. package/dist/src/runtime/automations/late-settlement.d.ts +9 -0
  141. package/dist/src/runtime/automations/late-settlement.js +42 -0
  142. package/dist/src/runtime/automations/limits.d.ts +25 -0
  143. package/dist/src/runtime/automations/limits.js +41 -0
  144. package/dist/src/runtime/automations/model-capacity.d.ts +9 -0
  145. package/dist/src/runtime/automations/model-capacity.js +67 -0
  146. package/dist/src/runtime/automations/model-dependency-projection.d.ts +56 -0
  147. package/dist/src/runtime/automations/model-dependency-projection.js +88 -0
  148. package/dist/src/runtime/automations/node-transactions.d.ts +57 -0
  149. package/dist/src/runtime/automations/node-transactions.js +223 -0
  150. package/dist/src/runtime/automations/occurrence-preparation.d.ts +12 -0
  151. package/dist/src/runtime/automations/occurrence-preparation.js +257 -0
  152. package/dist/src/runtime/automations/permission-grants.d.ts +27 -0
  153. package/dist/src/runtime/automations/permission-grants.js +72 -0
  154. package/dist/src/runtime/automations/persistence.d.ts +9 -0
  155. package/dist/src/runtime/automations/persistence.js +13 -0
  156. package/dist/src/runtime/automations/publication-validation.d.ts +16 -0
  157. package/dist/src/runtime/automations/publication-validation.js +162 -0
  158. package/dist/src/runtime/automations/publication.d.ts +33 -0
  159. package/dist/src/runtime/automations/publication.js +97 -0
  160. package/dist/src/runtime/automations/replay-preparation.d.ts +7 -0
  161. package/dist/src/runtime/automations/replay-preparation.js +59 -0
  162. package/dist/src/runtime/automations/result-capacity.d.ts +5 -0
  163. package/dist/src/runtime/automations/result-capacity.js +9 -0
  164. package/dist/src/runtime/automations/result-publication.d.ts +10 -0
  165. package/dist/src/runtime/automations/result-publication.js +21 -0
  166. package/dist/src/runtime/automations/result-store.d.ts +17 -0
  167. package/dist/src/runtime/automations/result-store.js +109 -0
  168. package/dist/src/runtime/automations/retention.d.ts +12 -0
  169. package/dist/src/runtime/automations/retention.js +134 -0
  170. package/dist/src/runtime/automations/run-file-binding.d.ts +3 -0
  171. package/dist/src/runtime/automations/run-file-binding.js +19 -0
  172. package/dist/src/runtime/automations/run-output-summary.d.ts +25 -0
  173. package/dist/src/runtime/automations/run-output-summary.js +54 -0
  174. package/dist/src/runtime/automations/run-report.d.ts +83 -0
  175. package/dist/src/runtime/automations/run-report.js +121 -0
  176. package/dist/src/runtime/automations/runtime-executor.d.ts +16 -0
  177. package/dist/src/runtime/automations/runtime-executor.js +260 -0
  178. package/dist/src/runtime/automations/saved-agent-management.d.ts +16 -0
  179. package/dist/src/runtime/automations/saved-agent-management.js +94 -0
  180. package/dist/src/runtime/automations/service.d.ts +286 -0
  181. package/dist/src/runtime/automations/service.js +330 -0
  182. package/dist/src/runtime/automations/snapshot-staging.d.ts +13 -0
  183. package/dist/src/runtime/automations/snapshot-staging.js +126 -0
  184. package/dist/src/runtime/automations/source-attachment-access.d.ts +23 -0
  185. package/dist/src/runtime/automations/source-attachment-access.js +70 -0
  186. package/dist/src/runtime/automations/source-discovery.d.ts +25 -0
  187. package/dist/src/runtime/automations/source-discovery.js +179 -0
  188. package/dist/src/runtime/automations/starter-template-builder.d.ts +5 -0
  189. package/dist/src/runtime/automations/starter-template-builder.js +78 -0
  190. package/dist/src/runtime/automations/starter-template-contracts.d.ts +42 -0
  191. package/dist/src/runtime/automations/starter-template-contracts.js +1 -0
  192. package/dist/src/runtime/automations/starter-template-definitions.d.ts +3 -0
  193. package/dist/src/runtime/automations/starter-template-definitions.js +100 -0
  194. package/dist/src/runtime/automations/starter-template-showcases.d.ts +3 -0
  195. package/dist/src/runtime/automations/starter-template-showcases.js +154 -0
  196. package/dist/src/runtime/automations/starter-template-structure.d.ts +4 -0
  197. package/dist/src/runtime/automations/starter-template-structure.js +11 -0
  198. package/dist/src/runtime/automations/starter-templates.d.ts +20 -0
  199. package/dist/src/runtime/automations/starter-templates.js +75 -0
  200. package/dist/src/runtime/automations/step-evidence-effects.d.ts +46 -0
  201. package/dist/src/runtime/automations/step-evidence-effects.js +173 -0
  202. package/dist/src/runtime/automations/step-evidence-inputs.d.ts +22 -0
  203. package/dist/src/runtime/automations/step-evidence-inputs.js +105 -0
  204. package/dist/src/runtime/automations/step-evidence-output.d.ts +17 -0
  205. package/dist/src/runtime/automations/step-evidence-output.js +43 -0
  206. package/dist/src/runtime/automations/step-evidence.d.ts +24 -0
  207. package/dist/src/runtime/automations/step-evidence.js +53 -0
  208. package/dist/src/runtime/automations/step-interruption.d.ts +3 -0
  209. package/dist/src/runtime/automations/step-interruption.js +26 -0
  210. package/dist/src/runtime/automations/step-runner.d.ts +57 -0
  211. package/dist/src/runtime/automations/step-runner.js +278 -0
  212. package/dist/src/runtime/automations/storage-records.d.ts +133 -0
  213. package/dist/src/runtime/automations/storage-records.js +286 -0
  214. package/dist/src/runtime/automations/terminal-admission-receipt.d.ts +12 -0
  215. package/dist/src/runtime/automations/terminal-admission-receipt.js +39 -0
  216. package/dist/src/runtime/automations/tool-lifetimes.d.ts +13 -0
  217. package/dist/src/runtime/automations/tool-lifetimes.js +56 -0
  218. package/dist/src/runtime/automations/tool-step-executor.d.ts +32 -0
  219. package/dist/src/runtime/automations/tool-step-executor.js +136 -0
  220. package/dist/src/runtime/automations/tool-step-outcome.d.ts +24 -0
  221. package/dist/src/runtime/automations/tool-step-outcome.js +32 -0
  222. package/dist/src/runtime/automations/trigger-schedule.d.ts +7 -0
  223. package/dist/src/runtime/automations/trigger-schedule.js +19 -0
  224. package/dist/src/runtime/automations/working-directory.d.ts +3 -0
  225. package/dist/src/runtime/automations/working-directory.js +13 -0
  226. package/dist/src/runtime/capabilities/automation-builder/authoring-reference.d.ts +422 -0
  227. package/dist/src/runtime/capabilities/automation-builder/authoring-reference.js +130 -0
  228. package/dist/src/runtime/capabilities/automation-builder/creation-recipe.d.ts +9 -0
  229. package/dist/src/runtime/capabilities/automation-builder/creation-recipe.js +155 -0
  230. package/dist/src/runtime/capabilities/automation-builder/payload-instructions.d.ts +6 -0
  231. package/dist/src/runtime/capabilities/automation-builder/payload-instructions.js +6 -0
  232. package/dist/src/runtime/capabilities/automation-builder/payload-schema.d.ts +3 -0
  233. package/dist/src/runtime/capabilities/automation-builder/payload-schema.js +105 -0
  234. package/dist/src/runtime/capabilities/automation-builder/tool-contract.d.ts +65 -0
  235. package/dist/src/runtime/capabilities/automation-builder/tool-contract.js +27 -0
  236. package/dist/src/runtime/capabilities/automation-builder/tool-module.d.ts +4 -0
  237. package/dist/src/runtime/capabilities/automation-builder/tool-module.js +108 -0
  238. package/dist/src/runtime/capabilities/automations/authoring-catalog-contract.d.ts +78 -0
  239. package/dist/src/runtime/capabilities/automations/authoring-catalog-contract.js +28 -0
  240. package/dist/src/runtime/capabilities/automations/authoring-catalog.d.ts +320 -0
  241. package/dist/src/runtime/capabilities/automations/authoring-catalog.js +158 -0
  242. package/dist/src/runtime/capabilities/automations/authoring-input-contracts.d.ts +140 -0
  243. package/dist/src/runtime/capabilities/automations/authoring-input-contracts.js +36 -0
  244. package/dist/src/runtime/capabilities/automations/authoring-inputs.d.ts +9 -0
  245. package/dist/src/runtime/capabilities/automations/authoring-inputs.js +86 -0
  246. package/dist/src/runtime/capabilities/automations/authoring-preparation-limits.d.ts +5 -0
  247. package/dist/src/runtime/capabilities/automations/authoring-preparation-limits.js +5 -0
  248. package/dist/src/runtime/capabilities/automations/authoring-preparation.d.ts +483 -0
  249. package/dist/src/runtime/capabilities/automations/authoring-preparation.js +51 -0
  250. package/dist/src/runtime/capabilities/automations/draft-index.d.ts +14 -0
  251. package/dist/src/runtime/capabilities/automations/draft-index.js +26 -0
  252. package/dist/src/runtime/capabilities/automations/draft-operation-refs.d.ts +11 -0
  253. package/dist/src/runtime/capabilities/automations/draft-operation-refs.js +37 -0
  254. package/dist/src/runtime/capabilities/automations/draft-receipt-admission.d.ts +24 -0
  255. package/dist/src/runtime/capabilities/automations/draft-receipt-admission.js +36 -0
  256. package/dist/src/runtime/capabilities/automations/event-presentation.d.ts +3 -0
  257. package/dist/src/runtime/capabilities/automations/event-presentation.js +18 -0
  258. package/dist/src/runtime/capabilities/automations/model-tool-contract.d.ts +3 -0
  259. package/dist/src/runtime/capabilities/automations/model-tool-contract.js +34 -0
  260. package/dist/src/runtime/capabilities/automations/tool-contract.d.ts +3 -0
  261. package/dist/src/runtime/capabilities/automations/tool-contract.js +65 -0
  262. package/dist/src/runtime/capabilities/automations/tool-module.d.ts +4 -0
  263. package/dist/src/runtime/capabilities/automations/tool-module.js +286 -0
  264. package/dist/src/runtime/capabilities/runtime-path-namespace.d.ts +6 -0
  265. package/dist/src/runtime/capabilities/runtime-path-namespace.js +48 -0
  266. package/dist/src/runtime/capabilities/runtime-target-path.d.ts +1 -0
  267. package/dist/src/runtime/capabilities/runtime-target-path.js +16 -8
  268. package/dist/src/runtime/capabilities/scheduling/create-operations.d.ts +6 -0
  269. package/dist/src/runtime/capabilities/scheduling/job-list-page.d.ts +4 -1
  270. package/dist/src/runtime/composition.d.ts +5 -2
  271. package/dist/src/runtime/context/canonical-capability-result.d.ts +4 -0
  272. package/dist/src/runtime/context/canonical-capability-result.js +80 -0
  273. package/dist/src/runtime/context/capability-brief-readmission.js +2 -5
  274. package/dist/src/runtime/context/capability-result-compaction-source.d.ts +12 -0
  275. package/dist/src/runtime/context/capability-result-compaction-source.js +61 -0
  276. package/dist/src/runtime/context/compacted-capability-result-receipt.d.ts +7 -0
  277. package/dist/src/runtime/context/compacted-capability-result-receipt.js +29 -0
  278. package/dist/src/runtime/context/compaction-source-invariant.d.ts +6 -0
  279. package/dist/src/runtime/context/compaction-source-invariant.js +12 -0
  280. package/dist/src/runtime/context/execution-compacted-evidence.d.ts +29 -0
  281. package/dist/src/runtime/context/execution-compacted-evidence.js +87 -0
  282. package/dist/src/runtime/context/execution-compaction-objective.d.ts +11 -0
  283. package/dist/src/runtime/context/execution-compaction-objective.js +12 -0
  284. package/dist/src/runtime/context/model-step-compaction.d.ts +9 -0
  285. package/dist/src/runtime/context/model-step-compaction.js +115 -128
  286. package/dist/src/runtime/context/operation-supervision-compacted-evidence.d.ts +37 -0
  287. package/dist/src/runtime/context/operation-supervision-compacted-evidence.js +69 -0
  288. package/dist/src/runtime/context/operation-supervision-evidence-binding.d.ts +29 -0
  289. package/dist/src/runtime/context/operation-supervision-evidence-binding.js +66 -0
  290. package/dist/src/runtime/context/operation-supervision-evidence-projection.d.ts +5 -0
  291. package/dist/src/runtime/context/operation-supervision-evidence-projection.js +133 -0
  292. package/dist/src/runtime/context/operation-supervision-evidence.d.ts +2 -1
  293. package/dist/src/runtime/context/operation-supervision-evidence.js +38 -37
  294. package/dist/src/runtime/context/request-tool-results-checkpoint.d.ts +3 -0
  295. package/dist/src/runtime/context/request-tool-results-checkpoint.js +126 -0
  296. package/dist/src/runtime/context/request-tool-results-message-binding.d.ts +1 -0
  297. package/dist/src/runtime/context/request-tool-results-message-binding.js +10 -0
  298. package/dist/src/runtime/context/request-tool-results-supersession.d.ts +9 -0
  299. package/dist/src/runtime/context/request-tool-results-supersession.js +78 -0
  300. package/dist/src/runtime/context/request-tool-results.d.ts +3 -9
  301. package/dist/src/runtime/context/request-tool-results.js +15 -181
  302. package/dist/src/runtime/context/runtime-filesystem-scope.d.ts +21 -0
  303. package/dist/src/runtime/context/runtime-filesystem-scope.js +51 -0
  304. package/dist/src/runtime/context/semantic-compaction/checkpoint-message.d.ts +3 -0
  305. package/dist/src/runtime/context/semantic-compaction/checkpoint-message.js +22 -0
  306. package/dist/src/runtime/context/semantic-compaction/contracts.d.ts +0 -3
  307. package/dist/src/runtime/context/semantic-compaction/contracts.js +9 -20
  308. package/dist/src/runtime/context/semantic-compaction/dependency-results.js +15 -1
  309. package/dist/src/runtime/context/semantic-compaction/evidence-scope.d.ts +7 -0
  310. package/dist/src/runtime/context/semantic-compaction/evidence-scope.js +7 -0
  311. package/dist/src/runtime/context/semantic-compaction/format.d.ts +2 -1
  312. package/dist/src/runtime/context/semantic-compaction/format.js +27 -19
  313. package/dist/src/runtime/context/semantic-compaction/generation-contracts.d.ts +18 -0
  314. package/dist/src/runtime/context/semantic-compaction/generation-contracts.js +1 -0
  315. package/dist/src/runtime/context/semantic-compaction/generation-input.d.ts +11 -0
  316. package/dist/src/runtime/context/semantic-compaction/generation-input.js +74 -0
  317. package/dist/src/runtime/context/semantic-compaction/generation-source-registration.d.ts +3 -0
  318. package/dist/src/runtime/context/semantic-compaction/generation-source-registration.js +12 -0
  319. package/dist/src/runtime/context/semantic-compaction/output-validation.d.ts +10 -0
  320. package/dist/src/runtime/context/semantic-compaction/output-validation.js +75 -0
  321. package/dist/src/runtime/context/semantic-compaction/parser.d.ts +2 -2
  322. package/dist/src/runtime/context/semantic-compaction/parser.js +13 -26
  323. package/dist/src/runtime/context/semantic-compaction/prompt.js +18 -5
  324. package/dist/src/runtime/context/semantic-compaction/repair-headroom.d.ts +4 -3
  325. package/dist/src/runtime/context/semantic-compaction/repair-headroom.js +10 -4
  326. package/dist/src/runtime/context/semantic-compaction/replacement-budget.d.ts +25 -0
  327. package/dist/src/runtime/context/semantic-compaction/replacement-budget.js +55 -0
  328. package/dist/src/runtime/context/semantic-compaction/run.d.ts +3 -14
  329. package/dist/src/runtime/context/semantic-compaction/run.js +27 -186
  330. package/dist/src/runtime/context/semantic-compaction/scope-quarantine.d.ts +17 -0
  331. package/dist/src/runtime/context/semantic-compaction/scope-quarantine.js +37 -0
  332. package/dist/src/runtime/context/semantic-compaction/snapshot.d.ts +5 -1
  333. package/dist/src/runtime/context/semantic-compaction/snapshot.js +10 -2
  334. package/dist/src/runtime/context/semantic-compaction/source-registration.d.ts +3 -0
  335. package/dist/src/runtime/context/semantic-compaction/source-registration.js +34 -0
  336. package/dist/src/runtime/context/semantic-compaction/source-slots.d.ts +5 -0
  337. package/dist/src/runtime/context/semantic-compaction/source-slots.js +4 -0
  338. package/dist/src/runtime/context/semantic-compaction/store.d.ts +6 -1
  339. package/dist/src/runtime/context/semantic-compaction/store.js +54 -9
  340. package/dist/src/runtime/context/semantic-compaction/super-child-result-source.d.ts +8 -0
  341. package/dist/src/runtime/context/semantic-compaction/super-child-result-source.js +50 -0
  342. package/dist/src/runtime/context/semantic-compaction/super-operation-source.d.ts +8 -0
  343. package/dist/src/runtime/context/semantic-compaction/super-operation-source.js +99 -0
  344. package/dist/src/runtime/context/semantic-compaction/super-reviewer-source.d.ts +16 -0
  345. package/dist/src/runtime/context/semantic-compaction/super-reviewer-source.js +37 -0
  346. package/dist/src/runtime/context/semantic-compaction/super-source-integrity.d.ts +21 -0
  347. package/dist/src/runtime/context/semantic-compaction/super-source-integrity.js +169 -0
  348. package/dist/src/runtime/context/semantic-compaction/super-source-message.d.ts +4 -0
  349. package/dist/src/runtime/context/semantic-compaction/super-source-message.js +23 -0
  350. package/dist/src/runtime/context/session-memory/model-step-controller.js +34 -20
  351. package/dist/src/runtime/context/session-memory/selection.js +0 -2
  352. package/dist/src/runtime/context/spark-conversation-policy.d.ts +4 -0
  353. package/dist/src/runtime/context/spark-conversation-policy.js +16 -0
  354. package/dist/src/runtime/context/super-compaction-failure-owner.d.ts +10 -0
  355. package/dist/src/runtime/context/super-compaction-failure-owner.js +64 -0
  356. package/dist/src/runtime/context/super-context-failure.d.ts +28 -0
  357. package/dist/src/runtime/context/super-context-failure.js +37 -0
  358. package/dist/src/runtime/context/super-context-policy.d.ts +3 -0
  359. package/dist/src/runtime/context/super-context-policy.js +35 -0
  360. package/dist/src/runtime/context/super-request-tool-results-checkpoint.d.ts +6 -0
  361. package/dist/src/runtime/context/super-request-tool-results-checkpoint.js +29 -0
  362. package/dist/src/runtime/context/super-worker-compaction-failure.d.ts +5 -0
  363. package/dist/src/runtime/context/super-worker-compaction-failure.js +19 -0
  364. package/dist/src/runtime/context/super-worker-compaction-projection.d.ts +8 -0
  365. package/dist/src/runtime/context/super-worker-compaction-projection.js +41 -0
  366. package/dist/src/runtime/context/super-worker-compaction-sidecar.d.ts +21 -0
  367. package/dist/src/runtime/context/super-worker-compaction-sidecar.js +67 -0
  368. package/dist/src/runtime/context/verified-compaction-projection.d.ts +7 -0
  369. package/dist/src/runtime/context/verified-compaction-projection.js +16 -0
  370. package/dist/src/runtime/default-environment-adapters.d.ts +4 -0
  371. package/dist/src/runtime/default-environment-adapters.js +7 -1
  372. package/dist/src/runtime/local-application.d.ts +277 -0
  373. package/dist/src/runtime/local-application.js +7 -0
  374. package/dist/src/runtime/local-host/app-learning-dispatch.js +0 -8
  375. package/dist/src/runtime/local-host/app-native-permissions.d.ts +20 -0
  376. package/dist/src/runtime/local-host/app-native-permissions.js +76 -0
  377. package/dist/src/runtime/local-host/app-owner.js +12 -1
  378. package/dist/src/runtime/local-host/app-request-control.d.ts +1 -0
  379. package/dist/src/runtime/local-host/app-request-control.js +5 -0
  380. package/dist/src/runtime/local-host/app-service-dispatch.d.ts +2 -1
  381. package/dist/src/runtime/local-host/app-service-dispatch.js +31 -0
  382. package/dist/src/runtime/local-host/client-learning.d.ts +1 -1
  383. package/dist/src/runtime/local-host/client-learning.js +0 -1
  384. package/dist/src/runtime/local-host/client-native-permissions.d.ts +4 -0
  385. package/dist/src/runtime/local-host/client-native-permissions.js +37 -0
  386. package/dist/src/runtime/local-host/client-services.d.ts +273 -0
  387. package/dist/src/runtime/local-host/client-services.js +3 -2
  388. package/dist/src/runtime/local-host/learning-preferences-input.js +1 -0
  389. package/dist/src/runtime/model/context-compaction-admission.d.ts +21 -0
  390. package/dist/src/runtime/model/context-compaction-admission.js +214 -0
  391. package/dist/src/runtime/model/context-compaction-contracts.d.ts +32 -0
  392. package/dist/src/runtime/model/context-compaction-contracts.js +1 -0
  393. package/dist/src/runtime/model/context-compaction-diagnostics.d.ts +33 -0
  394. package/dist/src/runtime/model/context-compaction-diagnostics.js +97 -0
  395. package/dist/src/runtime/model/context-compaction-stage-plan.d.ts +3 -0
  396. package/dist/src/runtime/model/context-compaction-stage-plan.js +28 -0
  397. package/dist/src/runtime/model/input-token-count.d.ts +1 -0
  398. package/dist/src/runtime/model/input-token-count.js +4 -1
  399. package/dist/src/runtime/model/invoke-step.js +80 -126
  400. package/dist/src/runtime/model/invoke-structured-step.d.ts +1 -1
  401. package/dist/src/runtime/model/invoke-structured-step.js +3 -2
  402. package/dist/src/runtime/model/model-context-assessment.d.ts +17 -0
  403. package/dist/src/runtime/model/model-context-assessment.js +51 -0
  404. package/dist/src/runtime/model/model-context-budget.js +1 -0
  405. package/dist/src/runtime/model/model-step-acceptance.d.ts +4 -0
  406. package/dist/src/runtime/model/model-step-acceptance.js +28 -0
  407. package/dist/src/runtime/model/model-step-port.d.ts +4 -15
  408. package/dist/src/runtime/model/model-step-steering.d.ts +14 -1
  409. package/dist/src/runtime/model/model-step-steering.js +23 -0
  410. package/dist/src/runtime/orchestration/capability-adapters/result.d.ts +4 -1
  411. package/dist/src/runtime/orchestration/capability-adapters/result.js +11 -7
  412. package/dist/src/runtime/orchestration/role-calls/child-return.d.ts +5 -1
  413. package/dist/src/runtime/orchestration/role-calls/child-return.js +2 -2
  414. package/dist/src/runtime/orchestration/worker-capabilities/binding/invocation-preparation.js +1 -8
  415. package/dist/src/runtime/orchestration/worker-capabilities/contracts.d.ts +3 -4
  416. package/dist/src/runtime/orchestration/worker-capabilities/contracts.js +1 -1
  417. package/dist/src/runtime/orchestration/worker-capabilities/execution/context-projection.js +2 -1
  418. package/dist/src/runtime/orchestration/worker-capabilities/payload-assignment-validation.js +9 -9
  419. package/dist/src/runtime/orchestration/worker-capabilities/payload-author.js +9 -33
  420. package/dist/src/runtime/orchestration/worker-capabilities/payload-body-normalization.d.ts +12 -0
  421. package/dist/src/runtime/orchestration/worker-capabilities/payload-body-normalization.js +80 -0
  422. package/dist/src/runtime/orchestration/worker-capabilities/payload-compaction-transport.d.ts +3 -0
  423. package/dist/src/runtime/orchestration/worker-capabilities/payload-compaction-transport.js +14 -0
  424. package/dist/src/runtime/orchestration/worker-capabilities/payload-context-snapshot.d.ts +2 -0
  425. package/dist/src/runtime/orchestration/worker-capabilities/payload-context-snapshot.js +12 -0
  426. package/dist/src/runtime/orchestration/worker-capabilities/payload-contracts.d.ts +5 -1
  427. package/dist/src/runtime/orchestration/worker-capabilities/payload-instructions.js +1 -1
  428. package/dist/src/runtime/passive-learning/background-dependencies.d.ts +0 -1
  429. package/dist/src/runtime/passive-learning/contracts.d.ts +2 -3
  430. package/dist/src/runtime/passive-learning/proactive/agent.d.ts +3 -0
  431. package/dist/src/runtime/passive-learning/proactive/agent.js +36 -14
  432. package/dist/src/runtime/passive-learning/proactive/contracts.d.ts +7 -1
  433. package/dist/src/runtime/passive-learning/proactive/contracts.js +8 -1
  434. package/dist/src/runtime/passive-learning/proactive/conversation-style-prompt.d.ts +1 -0
  435. package/dist/src/runtime/passive-learning/proactive/conversation-style-prompt.js +6 -0
  436. package/dist/src/runtime/passive-learning/proactive/conversation-style-reference.d.ts +30 -0
  437. package/dist/src/runtime/passive-learning/proactive/conversation-style-reference.js +61 -0
  438. package/dist/src/runtime/passive-learning/proactive/handoff-brief.d.ts +1 -0
  439. package/dist/src/runtime/passive-learning/proactive/handoff-brief.js +4 -0
  440. package/dist/src/runtime/passive-learning/proactive/model-output.d.ts +1 -1
  441. package/dist/src/runtime/passive-learning/proactive/model-output.js +5 -4
  442. package/dist/src/runtime/passive-learning/proactive/model.d.ts +7 -1
  443. package/dist/src/runtime/passive-learning/proactive/model.js +58 -32
  444. package/dist/src/runtime/passive-learning/proactive/prompt.d.ts +1 -1
  445. package/dist/src/runtime/passive-learning/proactive/prompt.js +4 -2
  446. package/dist/src/runtime/passive-learning/proactive/staged-authoring.d.ts +14 -0
  447. package/dist/src/runtime/passive-learning/proactive/staged-authoring.js +27 -0
  448. package/dist/src/runtime/passive-learning/proactive/staged-context.d.ts +13 -0
  449. package/dist/src/runtime/passive-learning/proactive/staged-context.js +39 -4
  450. package/dist/src/runtime/passive-learning/proactive/staged-contract.d.ts +3 -0
  451. package/dist/src/runtime/passive-learning/proactive/staged-contract.js +4 -0
  452. package/dist/src/runtime/passive-learning/proactive/staged-format.d.ts +5 -1
  453. package/dist/src/runtime/passive-learning/proactive/staged-format.js +2 -4
  454. package/dist/src/runtime/passive-learning/proactive/staged-output.d.ts +3 -4
  455. package/dist/src/runtime/passive-learning/proactive/staged-output.js +13 -5
  456. package/dist/src/runtime/passive-learning/proactive/staged-progress-store.d.ts +0 -1
  457. package/dist/src/runtime/passive-learning/proactive/staged-progress-store.js +2 -18
  458. package/dist/src/runtime/passive-learning/proactive/staged-prompt.d.ts +3 -1
  459. package/dist/src/runtime/passive-learning/proactive/staged-prompt.js +13 -4
  460. package/dist/src/runtime/passive-learning/proactive/staged-review.d.ts +1 -1
  461. package/dist/src/runtime/passive-learning/proactive/staged-review.js +10 -11
  462. package/dist/src/runtime/passive-learning/proactive/store.d.ts +1 -1
  463. package/dist/src/runtime/passive-learning/proactive/store.js +11 -5
  464. package/dist/src/runtime/passive-learning/review-progress.d.ts +1 -1
  465. package/dist/src/runtime/passive-learning/review-progress.js +2 -2
  466. package/dist/src/runtime/passive-learning/service-status.js +2 -2
  467. package/dist/src/runtime/passive-learning/service.js +0 -6
  468. package/dist/src/runtime/passive-learning/spark-chat-preferences.d.ts +3 -0
  469. package/dist/src/runtime/passive-learning/spark-chat-preferences.js +8 -0
  470. package/dist/src/runtime/passive-learning/staged-review-call.d.ts +3 -0
  471. package/dist/src/runtime/passive-learning/staged-review-call.js +19 -13
  472. package/dist/src/runtime/passive-learning/store.js +4 -0
  473. package/dist/src/runtime/plugins/manifest-projection.js +4 -0
  474. package/dist/src/runtime/plugins/manifest-validator.js +7 -0
  475. package/dist/src/runtime/ports.d.ts +14 -1
  476. package/dist/src/runtime/request/approval-wait/activation-events.d.ts +5 -0
  477. package/dist/src/runtime/request/approval-wait/activation-events.js +4 -3
  478. package/dist/src/runtime/request/approval-wait/snapshot.d.ts +1 -1
  479. package/dist/src/runtime/request/approval-wait/snapshot.js +1 -0
  480. package/dist/src/runtime/request/approval-wait/super-compaction-restore.d.ts +20 -0
  481. package/dist/src/runtime/request/approval-wait/super-compaction-restore.js +61 -0
  482. package/dist/src/runtime/request/automation-output-contract.d.ts +6 -0
  483. package/dist/src/runtime/request/automation-output-contract.js +33 -0
  484. package/dist/src/runtime/request/contracts.d.ts +16 -0
  485. package/dist/src/runtime/request/execution-agent-root-execution.js +2 -0
  486. package/dist/src/runtime/request/execution-facets.js +7 -0
  487. package/dist/src/runtime/request/execution-payload-compacted-evidence.d.ts +64 -0
  488. package/dist/src/runtime/request/execution-payload-compacted-evidence.js +46 -0
  489. package/dist/src/runtime/request/execution-scope-surfaces.d.ts +2 -0
  490. package/dist/src/runtime/request/execution-scope-surfaces.js +28 -0
  491. package/dist/src/runtime/request/execution-scope.d.ts +8 -2
  492. package/dist/src/runtime/request/execution-scope.js +14 -2
  493. package/dist/src/runtime/request/handler.d.ts +7 -0
  494. package/dist/src/runtime/request/handler.js +196 -35
  495. package/dist/src/runtime/request/locked-request-steering.d.ts +3 -0
  496. package/dist/src/runtime/request/locked-request-steering.js +12 -0
  497. package/dist/src/runtime/request/policy-degraded-finalization.d.ts +10 -0
  498. package/dist/src/runtime/request/policy-degraded-finalization.js +27 -0
  499. package/dist/src/runtime/request/prepared-execution.d.ts +10 -1
  500. package/dist/src/runtime/request/prepared-execution.js +43 -8
  501. package/dist/src/runtime/request/request-steering.d.ts +1 -1
  502. package/dist/src/runtime/request/result.d.ts +3 -0
  503. package/dist/src/runtime/request/role-executor-composition.js +4 -3
  504. package/dist/src/runtime/request/root-contract.d.ts +2 -0
  505. package/dist/src/runtime/request/root-execution-kernel.js +10 -9
  506. package/dist/src/runtime/request/root-invalid-output.js +16 -1
  507. package/dist/src/runtime/request/session-admission.d.ts +6 -0
  508. package/dist/src/runtime/request/session-admission.js +47 -14
  509. package/dist/src/runtime/request/super-checkpoint-quarantine.d.ts +8 -0
  510. package/dist/src/runtime/request/super-checkpoint-quarantine.js +76 -0
  511. package/dist/src/runtime/request/super-context-failure-executor.d.ts +4 -0
  512. package/dist/src/runtime/request/super-context-failure-executor.js +68 -0
  513. package/dist/src/runtime/request/super-context-failure-integrity.d.ts +16 -0
  514. package/dist/src/runtime/request/super-context-failure-integrity.js +130 -0
  515. package/dist/src/runtime/request/super-context-scope.d.ts +9 -0
  516. package/dist/src/runtime/request/super-context-scope.js +65 -0
  517. package/dist/src/runtime/request/super-failure-explanation.d.ts +22 -0
  518. package/dist/src/runtime/request/super-failure-explanation.js +77 -0
  519. package/dist/src/runtime/request/super-failure-message.d.ts +10 -0
  520. package/dist/src/runtime/request/super-failure-message.js +40 -0
  521. package/dist/src/runtime/request/super-payload-context-failure.d.ts +11 -0
  522. package/dist/src/runtime/request/super-payload-context-failure.js +55 -0
  523. package/dist/src/runtime/request/super-root-failure-finalization.d.ts +23 -0
  524. package/dist/src/runtime/request/super-root-failure-finalization.js +112 -0
  525. package/dist/src/runtime/request/worker-capability-composition.d.ts +2 -0
  526. package/dist/src/runtime/request/worker-capability-composition.js +4 -1
  527. package/dist/src/runtime/request/worker-capability-payload.d.ts +2 -1
  528. package/dist/src/runtime/request/worker-capability-payload.js +74 -48
  529. package/dist/src/runtime/runtime-environment.d.ts +3 -1
  530. package/dist/src/runtime/runtime-environment.js +167 -1
  531. package/dist/src/runtime/scheduler/automation-job-management.d.ts +12 -0
  532. package/dist/src/runtime/scheduler/automation-job-management.js +288 -0
  533. package/dist/src/runtime/scheduler/automation-rerun.d.ts +6 -0
  534. package/dist/src/runtime/scheduler/automation-rerun.js +95 -0
  535. package/dist/src/runtime/scheduler/automation-run-budget.d.ts +4 -0
  536. package/dist/src/runtime/scheduler/automation-run-budget.js +16 -0
  537. package/dist/src/runtime/scheduler/automation-run-change-events.d.ts +11 -0
  538. package/dist/src/runtime/scheduler/automation-run-change-events.js +77 -0
  539. package/dist/src/runtime/scheduler/automation-run-completion.d.ts +11 -0
  540. package/dist/src/runtime/scheduler/automation-run-completion.js +93 -0
  541. package/dist/src/runtime/scheduler/automation-run-control.d.ts +3 -0
  542. package/dist/src/runtime/scheduler/automation-run-control.js +48 -0
  543. package/dist/src/runtime/scheduler/automation-run-records.d.ts +5 -0
  544. package/dist/src/runtime/scheduler/automation-run-records.js +37 -0
  545. package/dist/src/runtime/scheduler/automation-schedule.d.ts +10 -0
  546. package/dist/src/runtime/scheduler/automation-schedule.js +48 -0
  547. package/dist/src/runtime/scheduler/automation-scheduler-engine.d.ts +4 -0
  548. package/dist/src/runtime/scheduler/automation-scheduler-engine.js +188 -0
  549. package/dist/src/runtime/scheduler/automation-snapshot-validation.d.ts +3 -0
  550. package/dist/src/runtime/scheduler/automation-snapshot-validation.js +106 -0
  551. package/dist/src/runtime/scheduler/contracts.d.ts +143 -3
  552. package/dist/src/runtime/scheduler/file-store.js +15 -1
  553. package/dist/src/runtime/scheduler/job-management.js +3 -2
  554. package/dist/src/runtime/scheduler/journal-automation-index.d.ts +23 -0
  555. package/dist/src/runtime/scheduler/journal-automation-index.js +205 -0
  556. package/dist/src/runtime/scheduler/journal-automation-transaction.d.ts +11 -0
  557. package/dist/src/runtime/scheduler/journal-automation-transaction.js +90 -0
  558. package/dist/src/runtime/scheduler/journal-checkpoint.js +5 -2
  559. package/dist/src/runtime/scheduler/journal-head.d.ts +1 -1
  560. package/dist/src/runtime/scheduler/journal-head.js +2 -2
  561. package/dist/src/runtime/scheduler/journal-index-state.d.ts +21 -10
  562. package/dist/src/runtime/scheduler/journal-index-state.js +76 -17
  563. package/dist/src/runtime/scheduler/journal-index.d.ts +9 -3
  564. package/dist/src/runtime/scheduler/journal-index.js +84 -9
  565. package/dist/src/runtime/scheduler/journal-store.d.ts +9 -1
  566. package/dist/src/runtime/scheduler/journal-store.js +110 -7
  567. package/dist/src/runtime/scheduler/journal-transaction.d.ts +7 -4
  568. package/dist/src/runtime/scheduler/journal-transaction.js +13 -2
  569. package/dist/src/runtime/scheduler/next-occurrence.js +2 -0
  570. package/dist/src/runtime/scheduler/run-completion.js +2 -1
  571. package/dist/src/runtime/scheduler/run-records.js +8 -3
  572. package/dist/src/runtime/scheduler/schedule-update.d.ts +2 -2
  573. package/dist/src/runtime/scheduler/schedule-validation.d.ts +2 -2
  574. package/dist/src/runtime/scheduler/schedule-validation.js +2 -0
  575. package/dist/src/runtime/scheduler/scheduler-engine.js +24 -8
  576. package/dist/src/runtime/scheduler/scheduler-service.d.ts +4 -1
  577. package/dist/src/runtime/scheduler/scheduler-service.js +83 -10
  578. package/dist/src/runtime/scheduler/scheduler-target.d.ts +9 -0
  579. package/dist/src/runtime/scheduler/scheduler-target.js +41 -0
  580. package/dist/src/runtime/scheduler/service-context.d.ts +6 -2
  581. package/dist/src/runtime/scheduler/service-context.js +6 -3
  582. package/dist/src/runtime/scheduler/snapshot-validation.d.ts +3 -3
  583. package/dist/src/runtime/scheduler/snapshot-validation.js +21 -1
  584. package/dist/src/runtime/scheduler/startup-recovery.d.ts +1 -1
  585. package/dist/src/runtime/scheduler/startup-recovery.js +15 -2
  586. package/dist/src/runtime/scheduler/working-store.js +8 -0
  587. package/dist/src/runtime/session/request-session.d.ts +1 -0
  588. package/dist/src/runtime/session/request-session.js +1 -0
  589. package/dist/src/runtime/session/session-deletion-boundary.d.ts +1 -1
  590. package/dist/src/runtime/session/session-deletion-boundary.js +6 -2
  591. package/dist/src/runtime/session/session-lifecycle-store.d.ts +4 -1
  592. package/dist/src/runtime/session/session-lifecycle-store.js +32 -4
  593. package/dist/src/runtime/session/spark-session-attachments.d.ts +4 -0
  594. package/dist/src/runtime/session/spark-session-attachments.js +28 -0
  595. package/dist/src/runtime/session/spark-session-cleanup-receipt.d.ts +7 -0
  596. package/dist/src/runtime/session/spark-session-cleanup-receipt.js +61 -0
  597. package/dist/src/runtime/session/spark-session-clear.d.ts +6 -0
  598. package/dist/src/runtime/session/spark-session-clear.js +36 -0
  599. package/dist/src/runtime/session/terminal-response.d.ts +21 -0
  600. package/dist/src/runtime/session/terminal-response.js +38 -0
  601. package/dist/src/runtime/steps/auditor-decision/advisory-receipt.d.ts +1 -0
  602. package/dist/src/runtime/steps/auditor-decision/advisory-receipt.js +12 -0
  603. package/dist/src/runtime/steps/auditor-decision/contracts.d.ts +4 -0
  604. package/dist/src/runtime/steps/auditor-decision/evidence-coverage.js +5 -5
  605. package/dist/src/runtime/steps/auditor-decision/evidence-inventory.d.ts +2 -1
  606. package/dist/src/runtime/steps/auditor-decision/evidence-inventory.js +12 -1
  607. package/dist/src/runtime/steps/auditor-decision/evidence-representation.d.ts +8 -2
  608. package/dist/src/runtime/steps/auditor-decision/evidence-representation.js +14 -1
  609. package/dist/src/runtime/steps/auditor-decision/input.d.ts +2 -0
  610. package/dist/src/runtime/steps/auditor-decision/input.js +12 -3
  611. package/dist/src/runtime/steps/auditor-decision/projection.js +20 -1
  612. package/dist/src/runtime/steps/auditor-decision/prompt.js +6 -6
  613. package/dist/src/runtime/steps/auditor-decision/run.js +2 -3
  614. package/dist/src/runtime/steps/capability-execution-instructions.d.ts +5 -0
  615. package/dist/src/runtime/steps/capability-execution-instructions.js +5 -0
  616. package/dist/src/runtime/steps/degraded-finalization/contract.d.ts +3 -0
  617. package/dist/src/runtime/steps/degraded-finalization/fallback.js +14 -4
  618. package/dist/src/runtime/steps/degraded-finalization/input.js +11 -1
  619. package/dist/src/runtime/steps/degraded-finalization/output-limit-cause.d.ts +4 -0
  620. package/dist/src/runtime/steps/degraded-finalization/output-limit-cause.js +17 -0
  621. package/dist/src/runtime/steps/degraded-finalization/prompt.js +4 -1
  622. package/dist/src/runtime/steps/degraded-finalization/super.d.ts +20 -0
  623. package/dist/src/runtime/steps/degraded-finalization/super.js +128 -0
  624. package/dist/src/runtime/steps/execution-agent/capability-decision-parsing.d.ts +1 -0
  625. package/dist/src/runtime/steps/execution-agent/capability-decision-parsing.js +21 -3
  626. package/dist/src/runtime/steps/execution-agent/capability-invocation-contract.d.ts +1 -1
  627. package/dist/src/runtime/steps/execution-agent/capability-invocation-contract.js +4 -2
  628. package/dist/src/runtime/steps/execution-agent/capability-selection-schema.d.ts +3 -0
  629. package/dist/src/runtime/steps/execution-agent/capability-selection-schema.js +72 -0
  630. package/dist/src/runtime/steps/execution-agent/compaction.d.ts +5 -2
  631. package/dist/src/runtime/steps/execution-agent/compaction.js +10 -4
  632. package/dist/src/runtime/steps/execution-agent/contracts.d.ts +14 -2
  633. package/dist/src/runtime/steps/execution-agent/controls-compacted-evidence.d.ts +16 -0
  634. package/dist/src/runtime/steps/execution-agent/controls-compacted-evidence.js +67 -0
  635. package/dist/src/runtime/steps/execution-agent/controls-evidence-contract.d.ts +21 -0
  636. package/dist/src/runtime/steps/execution-agent/controls-evidence-contract.js +64 -0
  637. package/dist/src/runtime/steps/execution-agent/controls-evidence.d.ts +32 -0
  638. package/dist/src/runtime/steps/execution-agent/controls-evidence.js +119 -0
  639. package/dist/src/runtime/steps/execution-agent/decision-parsing.js +1 -0
  640. package/dist/src/runtime/steps/execution-agent/format.d.ts +2 -0
  641. package/dist/src/runtime/steps/execution-agent/format.js +9 -68
  642. package/dist/src/runtime/steps/execution-agent/input.js +19 -2
  643. package/dist/src/runtime/steps/execution-agent/prompt.d.ts +1 -0
  644. package/dist/src/runtime/steps/execution-agent/prompt.js +15 -2
  645. package/dist/src/runtime/steps/execution-agent/refinement-input.d.ts +32 -0
  646. package/dist/src/runtime/steps/execution-agent/refinement-input.js +146 -0
  647. package/dist/src/runtime/steps/execution-agent/refinement-prompt.d.ts +1 -0
  648. package/dist/src/runtime/steps/execution-agent/refinement-prompt.js +11 -0
  649. package/dist/src/runtime/steps/execution-agent/refinement.d.ts +4 -4
  650. package/dist/src/runtime/steps/execution-agent/refinement.js +18 -108
  651. package/dist/src/runtime/steps/execution-agent/response-input.js +13 -6
  652. package/dist/src/runtime/steps/execution-agent/response-prompt.js +1 -1
  653. package/dist/src/runtime/steps/execution-agent/response-run.js +19 -5
  654. package/dist/src/runtime/steps/execution-agent/run.js +9 -3
  655. package/dist/src/runtime/steps/execution-agent/state-context.d.ts +1 -1
  656. package/dist/src/runtime/steps/execution-agent/state-context.js +20 -5
  657. package/dist/src/runtime/steps/planner-decision/input.js +7 -0
  658. package/dist/src/runtime/steps/planner-decision/resume.d.ts +2 -1
  659. package/dist/src/runtime/steps/planner-decision/resume.js +3 -3
  660. package/dist/src/runtime/steps/planner-decision/run.js +13 -0
  661. package/dist/src/runtime/steps/planner-graph/prompt.js +2 -0
  662. package/dist/src/runtime/steps/planner-graph/run.js +1 -0
  663. package/dist/src/runtime/steps/reviewer-decision/projection.js +5 -0
  664. package/dist/src/runtime/steps/reviewer-decision/run.js +13 -0
  665. package/dist/src/runtime/steps/supervisor-decision/input.d.ts +1 -1
  666. package/dist/src/runtime/steps/supervisor-decision/input.js +2 -0
  667. package/dist/src/runtime/steps/supervisor-decision/run.js +14 -0
  668. package/dist/src/runtime/steps/supervisor-decision/working-directory.d.ts +2 -0
  669. package/dist/src/runtime/steps/supervisor-decision/working-directory.js +6 -0
  670. package/dist/src/runtime/steps/supervisor-response/input.d.ts +1 -1
  671. package/dist/src/runtime/steps/supervisor-response/input.js +14 -7
  672. package/dist/src/runtime/steps/supervisor-response/run.js +39 -9
  673. package/dist/src/runtime/steps/worker-decision/compaction-integrity.d.ts +11 -0
  674. package/dist/src/runtime/steps/worker-decision/compaction-integrity.js +40 -0
  675. package/dist/src/runtime/steps/worker-decision/input/reference-context.js +7 -0
  676. package/dist/src/runtime/steps/worker-decision/input/types.d.ts +4 -1
  677. package/dist/src/runtime/steps/worker-decision/prompt.js +9 -2
  678. package/dist/src/runtime/steps/worker-decision/result-author.js +4 -0
  679. package/dist/src/runtime/steps/worker-decision/run.js +12 -49
  680. package/dist/src/runtime/steps/worker-decision/worker-handoff-compaction.d.ts +4 -0
  681. package/dist/src/runtime/steps/worker-decision/worker-handoff-compaction.js +69 -0
  682. package/dist/src/sessions/assistant-initiative-append.d.ts +14 -0
  683. package/dist/src/sessions/assistant-initiative-append.js +64 -0
  684. package/dist/src/sessions/assistant-initiative.d.ts +4 -0
  685. package/dist/src/sessions/assistant-initiative.js +7 -1
  686. package/dist/src/sessions/automation-session-origin.d.ts +34 -0
  687. package/dist/src/sessions/automation-session-origin.js +78 -0
  688. package/dist/src/sessions/automation-session-store.d.ts +12 -0
  689. package/dist/src/sessions/automation-session-store.js +129 -0
  690. package/dist/src/sessions/index.d.ts +1 -0
  691. package/dist/src/sessions/index.js +3 -0
  692. package/dist/src/sessions/memory/source.d.ts +1 -1
  693. package/dist/src/sessions/memory/source.js +4 -11
  694. package/dist/src/sessions/project-binding.d.ts +1 -0
  695. package/dist/src/sessions/record/projection.d.ts +1 -0
  696. package/dist/src/sessions/record/projection.js +4 -0
  697. package/dist/src/sessions/session-service.d.ts +9 -0
  698. package/dist/src/sessions/session-service.js +53 -4
  699. package/dist/src/sessions/spark-handoff-brief.d.ts +3 -0
  700. package/dist/src/sessions/spark-handoff-brief.js +9 -0
  701. package/dist/src/sessions/spark-session.d.ts +13 -0
  702. package/dist/src/sessions/spark-session.js +25 -0
  703. package/dist/src/sessions/types.d.ts +5 -0
  704. package/dist/src/web-ui/app/ARCHITECTURE.md +89 -0
  705. package/dist/src/web-ui/app/app-bootstrap.js +24 -2
  706. package/dist/src/web-ui/app/app-dom.js +5 -0
  707. package/dist/src/web-ui/app/app-realtime-transport.js +27 -2
  708. package/dist/src/web-ui/app/app.js +5 -10
  709. package/dist/src/web-ui/app/automations-feature.js +103 -0
  710. package/dist/src/web-ui/app/components/automations/archive-actions.js +20 -0
  711. package/dist/src/web-ui/app/components/automations/authoring-entry.js +25 -0
  712. package/dist/src/web-ui/app/components/automations/binding-editor.js +101 -0
  713. package/dist/src/web-ui/app/components/automations/binding-fields.js +166 -0
  714. package/dist/src/web-ui/app/components/automations/chat-run-projection.js +280 -0
  715. package/dist/src/web-ui/app/components/automations/draft-recovery-actions.js +28 -0
  716. package/dist/src/web-ui/app/components/automations/editor-action-icons.js +18 -0
  717. package/dist/src/web-ui/app/components/automations/editor-actions.js +57 -0
  718. package/dist/src/web-ui/app/components/automations/editor.js +218 -0
  719. package/dist/src/web-ui/app/components/automations/failure-presentation.js +299 -0
  720. package/dist/src/web-ui/app/components/automations/library-tabs.js +45 -0
  721. package/dist/src/web-ui/app/components/automations/list.js +58 -0
  722. package/dist/src/web-ui/app/components/automations/live-view.js +39 -0
  723. package/dist/src/web-ui/app/components/automations/node-inspector.js +251 -0
  724. package/dist/src/web-ui/app/components/automations/permission-selection.js +37 -0
  725. package/dist/src/web-ui/app/components/automations/rerun-confirmation.js +16 -0
  726. package/dist/src/web-ui/app/components/automations/run-output-view.js +100 -0
  727. package/dist/src/web-ui/app/components/automations/run-report-view.js +224 -0
  728. package/dist/src/web-ui/app/components/automations/run-step-selection.js +7 -0
  729. package/dist/src/web-ui/app/components/automations/run-steps-view.js +33 -0
  730. package/dist/src/web-ui/app/components/automations/run.js +38 -0
  731. package/dist/src/web-ui/app/components/automations/schema-literal-inputs.js +212 -0
  732. package/dist/src/web-ui/app/components/automations/step-editor-dialog.js +243 -0
  733. package/dist/src/web-ui/app/components/automations/step-preview.js +48 -0
  734. package/dist/src/web-ui/app/components/automations/template-gallery.js +74 -0
  735. package/dist/src/web-ui/app/components/automations/timeline-camera.js +219 -0
  736. package/dist/src/web-ui/app/components/automations/timeline.js +141 -0
  737. package/dist/src/web-ui/app/components/automations/tool-identity.js +25 -0
  738. package/dist/src/web-ui/app/components/automations/workspace.js +462 -0
  739. package/dist/src/web-ui/app/components/composer-context-window.js +24 -13
  740. package/dist/src/web-ui/app/components/config-workspace/model-rendering.js +2 -2
  741. package/dist/src/web-ui/app/components/conversation-activity.d.ts +2 -28
  742. package/dist/src/web-ui/app/components/conversation-activity.js +23 -60
  743. package/dist/src/web-ui/app/components/conversation-status.js +3 -2
  744. package/dist/src/web-ui/app/components/conversation-view.js +36 -14
  745. package/dist/src/web-ui/app/components/dashboard/automations.js +28 -0
  746. package/dist/src/web-ui/app/components/dashboard/workspace.js +9 -0
  747. package/dist/src/web-ui/app/components/notifications/dom.js +1 -1
  748. package/dist/src/web-ui/app/components/notifications/feedback.js +34 -0
  749. package/dist/src/web-ui/app/components/notifications/pagination.js +13 -0
  750. package/dist/src/web-ui/app/components/notifications/presentation.js +25 -4
  751. package/dist/src/web-ui/app/components/notifications/tabs.js +49 -0
  752. package/dist/src/web-ui/app/components/notifications/workspace.js +19 -26
  753. package/dist/src/web-ui/app/components/onboarding-workspace-access.js +1 -1
  754. package/dist/src/web-ui/app/components/passive-learning/agent-state.js +0 -5
  755. package/dist/src/web-ui/app/components/passive-learning/agent-view.js +1 -1
  756. package/dist/src/web-ui/app/components/passive-learning/home.js +0 -4
  757. package/dist/src/web-ui/app/components/passive-learning/memory.js +0 -3
  758. package/dist/src/web-ui/app/components/passive-learning/settings-view.js +2 -2
  759. package/dist/src/web-ui/app/components/passive-learning/workspace-view.js +3 -3
  760. package/dist/src/web-ui/app/components/runtime-setup/optional-steps.js +7 -1
  761. package/dist/src/web-ui/app/components/runtime-setup-guide.d.ts +5 -1
  762. package/dist/src/web-ui/app/components/runtime-setup-guide.js +6 -3
  763. package/dist/src/web-ui/app/components/schedules/details.js +3 -2
  764. package/dist/src/web-ui/app/components/schedules/form.js +4 -4
  765. package/dist/src/web-ui/app/components/spark-chat/empty-state.js +45 -0
  766. package/dist/src/web-ui/app/components/spark-chat/handoff-actions.js +59 -0
  767. package/dist/src/web-ui/app/components/spark-chat/mascot-activity.js +27 -0
  768. package/dist/src/web-ui/app/components/spark-chat/motion.js +52 -0
  769. package/dist/src/web-ui/app/components/spark-chat/panel.js +109 -0
  770. package/dist/src/web-ui/app/components/spark-chat/placement.js +198 -0
  771. package/dist/src/web-ui/app/components/spark-chat/results.js +44 -0
  772. package/dist/src/web-ui/app/components/spark-chat/settings.js +84 -0
  773. package/dist/src/web-ui/app/components/system-host/macos-permission-preparation.js +83 -0
  774. package/dist/src/web-ui/app/components/system-host/macos-permission-rendering.js +85 -0
  775. package/dist/src/web-ui/app/components/system-host/macos-permission-scopes.js +51 -0
  776. package/dist/src/web-ui/app/components/system-host/manager.js +34 -0
  777. package/dist/src/web-ui/app/components/system-host/rendering.js +12 -4
  778. package/dist/src/web-ui/app/components/workspace-shell.js +39 -6
  779. package/dist/src/web-ui/app/computer-access-feature.js +5 -0
  780. package/dist/src/web-ui/app/configuration-feature.js +1 -0
  781. package/dist/src/web-ui/app/controllers/app-event-bindings.js +24 -2
  782. package/dist/src/web-ui/app/controllers/automation-draft-actions.js +153 -0
  783. package/dist/src/web-ui/app/controllers/automation-management-actions.js +75 -0
  784. package/dist/src/web-ui/app/controllers/automation-mutation-lifecycle.js +32 -0
  785. package/dist/src/web-ui/app/controllers/automation-read-projection.js +63 -0
  786. package/dist/src/web-ui/app/controllers/automation-run-actions.js +54 -0
  787. package/dist/src/web-ui/app/controllers/automation-view-scope.js +19 -0
  788. package/dist/src/web-ui/app/controllers/automations-controller.js +395 -0
  789. package/dist/src/web-ui/app/controllers/composer-queue-controller.d.ts +1 -0
  790. package/dist/src/web-ui/app/controllers/composer-queue-controller.js +18 -12
  791. package/dist/src/web-ui/app/controllers/conversation-session-controller.js +38 -15
  792. package/dist/src/web-ui/app/controllers/conversation-view-feature.js +1 -14
  793. package/dist/src/web-ui/app/controllers/dashboard-controller.js +42 -1
  794. package/dist/src/web-ui/app/controllers/notifications-controller.js +1 -1
  795. package/dist/src/web-ui/app/controllers/passive-learning-controller.js +33 -85
  796. package/dist/src/web-ui/app/controllers/projects-controller.d.ts +2 -0
  797. package/dist/src/web-ui/app/controllers/projects-controller.js +53 -18
  798. package/dist/src/web-ui/app/controllers/realtime-event-controller.js +42 -160
  799. package/dist/src/web-ui/app/controllers/request-lifecycle-controller.js +2 -0
  800. package/dist/src/web-ui/app/controllers/runtime-onboarding-controller.d.ts +4 -1
  801. package/dist/src/web-ui/app/controllers/runtime-onboarding-controller.js +14 -3
  802. package/dist/src/web-ui/app/controllers/schedules-controller.js +11 -19
  803. package/dist/src/web-ui/app/controllers/spark-chat-notices.js +34 -0
  804. package/dist/src/web-ui/app/controllers/spark-chat-reading.js +145 -0
  805. package/dist/src/web-ui/app/controllers/spark-chat-sync.js +151 -0
  806. package/dist/src/web-ui/app/controllers/spark-handoff-navigation.js +32 -0
  807. package/dist/src/web-ui/app/controllers/workspace-route-controller.js +21 -1
  808. package/dist/src/web-ui/app/dashboard-feature.js +0 -1
  809. package/dist/src/web-ui/app/index.html +12 -10
  810. package/dist/src/web-ui/app/lib/automation-binding-producers.js +47 -0
  811. package/dist/src/web-ui/app/lib/automation-graph-position.js +19 -0
  812. package/dist/src/web-ui/app/lib/automation-parallel-depth.js +19 -0
  813. package/dist/src/web-ui/app/lib/configuration-pages.js +3 -5
  814. package/dist/src/web-ui/app/lib/context-compaction-state.d.ts +41 -0
  815. package/dist/src/web-ui/app/lib/context-compaction-state.js +172 -0
  816. package/dist/src/web-ui/app/lib/context-window-measurement.d.ts +33 -0
  817. package/dist/src/web-ui/app/lib/context-window-measurement.js +99 -0
  818. package/dist/src/web-ui/app/lib/context-window-replay.d.ts +32 -0
  819. package/dist/src/web-ui/app/lib/context-window-replay.js +38 -0
  820. package/dist/src/web-ui/app/lib/context-window-snapshot-order.d.ts +16 -8
  821. package/dist/src/web-ui/app/lib/context-window-snapshot-order.js +29 -9
  822. package/dist/src/web-ui/app/lib/context-window-state.d.ts +80 -0
  823. package/dist/src/web-ui/app/lib/context-window-state.js +341 -0
  824. package/dist/src/web-ui/app/lib/conversation-status-model.js +15 -3
  825. package/dist/src/web-ui/app/lib/realtime-message.js +9 -0
  826. package/dist/src/web-ui/app/lib/schedule-conversation-presentation.js +19 -0
  827. package/dist/src/web-ui/app/lib/schedule-presentation.js +2 -2
  828. package/dist/src/web-ui/app/lib/spark-chat-address.js +22 -0
  829. package/dist/src/web-ui/app/lib/spark-chat-presentation.js +16 -0
  830. package/dist/src/web-ui/app/lib/spark-chat-read-state.js +13 -0
  831. package/dist/src/web-ui/app/lib/spark-proposal-message.js +7 -0
  832. package/dist/src/web-ui/app/lib/tool-activity-event.d.ts +1 -0
  833. package/dist/src/web-ui/app/lib/tool-activity-event.js +6 -2
  834. package/dist/src/web-ui/app/lib/tool-activity-model.js +1 -0
  835. package/dist/src/web-ui/app/lib/tool-approval-acknowledgement.js +7 -0
  836. package/dist/src/web-ui/app/lib/tool-automation-activity-fields.js +59 -0
  837. package/dist/src/web-ui/app/lib/tool-process-activity-fields.js +1 -1
  838. package/dist/src/web-ui/app/lib/workspace-change.js +2 -2
  839. package/dist/src/web-ui/app/lib/workspace-route.d.ts +3 -0
  840. package/dist/src/web-ui/app/lib/workspace-route.js +13 -2
  841. package/dist/src/web-ui/app/notifications-feature.js +13 -0
  842. package/dist/src/web-ui/app/passive-learning-feature.js +5 -30
  843. package/dist/src/web-ui/app/projects-feature.js +16 -5
  844. package/dist/src/web-ui/app/runtime-onboarding-feature.js +1 -0
  845. package/dist/src/web-ui/app/services/client-preferences.d.ts +0 -2
  846. package/dist/src/web-ui/app/services/client-preferences.js +0 -2
  847. package/dist/src/web-ui/app/services/runtime-web-client/automations.d.ts +36 -0
  848. package/dist/src/web-ui/app/services/runtime-web-client/automations.js +63 -0
  849. package/dist/src/web-ui/app/services/runtime-web-client/learning.js +0 -9
  850. package/dist/src/web-ui/app/services/runtime-web-client/spark-chat.d.ts +22 -0
  851. package/dist/src/web-ui/app/services/runtime-web-client/spark-chat.js +29 -0
  852. package/dist/src/web-ui/app/services/runtime-web-client/system-host.js +4 -2
  853. package/dist/src/web-ui/app/services/runtime-web-client.d.ts +24 -4
  854. package/dist/src/web-ui/app/services/runtime-web-client.js +5 -1
  855. package/dist/src/web-ui/app/spark-chat-conversation.js +217 -0
  856. package/dist/src/web-ui/app/spark-chat-feature.js +187 -0
  857. package/dist/src/web-ui/app/spark-mascot.svg +12 -0
  858. package/dist/src/web-ui/app/styles/11-workspace-header-width.css +48 -14
  859. package/dist/src/web-ui/app/styles/11-workspace-rail.css +6 -0
  860. package/dist/src/web-ui/app/styles/19-dashboard-automations.css +32 -0
  861. package/dist/src/web-ui/app/styles/41-co-worker-agent.css +6 -25
  862. package/dist/src/web-ui/app/styles/46-system-host.css +17 -0
  863. package/dist/src/web-ui/app/styles/48-notifications.css +14 -8
  864. package/dist/src/web-ui/app/styles/50-automations.css +353 -0
  865. package/dist/src/web-ui/app/styles/51-automation-editor-actions.css +35 -0
  866. package/dist/src/web-ui/app/styles/51-automation-templates.css +39 -0
  867. package/dist/src/web-ui/app/styles/52-automation-reports.css +84 -0
  868. package/dist/src/web-ui/app/styles/52-automation-step-editor.css +73 -0
  869. package/dist/src/web-ui/app/styles/53-automation-schema-inputs.css +21 -0
  870. package/dist/src/web-ui/app/styles/54-spark-chat.css +111 -0
  871. package/dist/src/web-ui/app/styles/94-automations-responsive.css +35 -0
  872. package/dist/src/web-ui/app/styles.css +9 -1
  873. package/dist/src/web-ui/app/ui-behavior.js +1 -0
  874. package/dist/src/web-ui/local-runtime/api-router.d.ts +2 -0
  875. package/dist/src/web-ui/local-runtime/api-router.js +18 -0
  876. package/dist/src/web-ui/local-runtime/automation-routes.d.ts +27 -0
  877. package/dist/src/web-ui/local-runtime/automation-routes.js +227 -0
  878. package/dist/src/web-ui/local-runtime/environment-registry.d.ts +4 -0
  879. package/dist/src/web-ui/local-runtime/environment-registry.js +5 -0
  880. package/dist/src/web-ui/local-runtime/learning-notifications.js +1 -1
  881. package/dist/src/web-ui/local-runtime/learning-routes.js +0 -22
  882. package/dist/src/web-ui/local-runtime/request-execution.js +35 -0
  883. package/dist/src/web-ui/local-runtime/session-routes.js +32 -2
  884. package/dist/src/web-ui/local-runtime/setup-embedding-config-repository.d.ts +6 -0
  885. package/dist/src/web-ui/local-runtime/setup-embedding-config-repository.js +25 -0
  886. package/dist/src/web-ui/local-runtime/setup-embedding-service.js +2 -0
  887. package/dist/src/web-ui/local-runtime/spark-chat-admission.d.ts +7 -0
  888. package/dist/src/web-ui/local-runtime/spark-chat-admission.js +37 -0
  889. package/dist/src/web-ui/local-runtime/spark-chat-configuration.d.ts +8 -0
  890. package/dist/src/web-ui/local-runtime/spark-chat-configuration.js +16 -0
  891. package/dist/src/web-ui/local-runtime/spark-chat-handoff.d.ts +4 -0
  892. package/dist/src/web-ui/local-runtime/spark-chat-handoff.js +84 -0
  893. package/dist/src/web-ui/local-runtime/spark-chat-routes.d.ts +19 -0
  894. package/dist/src/web-ui/local-runtime/spark-chat-routes.js +62 -0
  895. package/dist/src/web-ui/local-runtime-backend.d.ts +4 -0
  896. package/dist/src/web-ui/local-runtime-backend.js +3 -0
  897. package/dist/src/web-ui/notifications/automation-event-projection.d.ts +3 -0
  898. package/dist/src/web-ui/notifications/automation-event-projection.js +57 -0
  899. package/dist/src/web-ui/notifications/contracts.d.ts +20 -5
  900. package/dist/src/web-ui/notifications/contracts.js +7 -1
  901. package/dist/src/web-ui/notifications/conversation-source.d.ts +6 -0
  902. package/dist/src/web-ui/notifications/conversation-source.js +26 -0
  903. package/dist/src/web-ui/notifications/event-fields.d.ts +3 -0
  904. package/dist/src/web-ui/notifications/event-fields.js +12 -0
  905. package/dist/src/web-ui/notifications/event-projection.d.ts +2 -1
  906. package/dist/src/web-ui/notifications/event-projection.js +22 -20
  907. package/dist/src/web-ui/notifications/service.js +33 -2
  908. package/dist/src/web-ui/notifications/storage-schema.js +118 -21
  909. package/dist/src/web-ui/server.js +1 -1
  910. package/dist/src/web-ui/session-read-state/service.d.ts +39 -0
  911. package/dist/src/web-ui/session-read-state/service.js +20 -2
  912. package/dist/src/web-ui/session-read-state/store.d.ts +2 -0
  913. package/dist/src/web-ui/session-read-state/store.js +7 -0
  914. package/dist/src/web-ui/session-read-state/visible-messages.d.ts +30 -0
  915. package/dist/src/web-ui/session-read-state/visible-messages.js +119 -0
  916. package/dist/src/web-ui/system-host-service.d.ts +4 -1
  917. package/dist/src/web-ui/system-host-service.js +14 -3
  918. package/dist/src/web-ui/system-host-setup/local-request-authority.d.ts +3 -0
  919. package/dist/src/web-ui/system-host-setup/local-request-authority.js +15 -0
  920. package/dist/src/web-ui/system-host-setup/local-setup-availability.js +2 -12
  921. package/dist/src/web-ui/system-host-setup/native-permission-route.d.ts +26 -0
  922. package/dist/src/web-ui/system-host-setup/native-permission-route.js +96 -0
  923. package/dist/src/web-ui/system-host-setup/permission-route.d.ts +13 -0
  924. package/dist/src/web-ui/system-host-setup/permission-route.js +102 -0
  925. package/docs/installation.md +41 -9
  926. package/docs/plugins.md +53 -11
  927. package/docs/runtime-public-contracts.md +7 -2
  928. package/docs/tool-execution-result-evidence-contract.md +11 -4
  929. package/package.json +1 -1
  930. package/plugins/capability-brief/src/index.cjs +85 -37
  931. package/plugins/code-outline/source/index.ts +7 -2
  932. package/plugins/code-outline/src/index.cjs +91 -39
  933. package/plugins/document-reader/plugin.json +18 -3
  934. package/plugins/document-reader/skills/document_reader_skill/SKILL.md +6 -6
  935. package/plugins/document-reader/source/source-resolution.ts +1 -1
  936. package/plugins/document-reader/src/index.cjs +86 -38
  937. package/plugins/exec/plugin.json +3 -3
  938. package/plugins/exec/source/handlers.ts +78 -20
  939. package/plugins/exec/source/output-contracts.ts +45 -0
  940. package/plugins/exec/source/output-files.ts +161 -0
  941. package/plugins/exec/source/output-maintenance.ts +60 -0
  942. package/plugins/exec/source/output-range-reader.ts +97 -0
  943. package/plugins/exec/source/output-retention.ts +34 -0
  944. package/plugins/exec/source/output-snapshot.ts +54 -0
  945. package/plugins/exec/source/output-store.ts +182 -0
  946. package/plugins/exec/source/output-utf8-boundary.ts +14 -0
  947. package/plugins/exec/source/output-writer.ts +131 -0
  948. package/plugins/exec/source/process-manager.ts +142 -70
  949. package/plugins/exec/source/process-output-buffer.ts +13 -18
  950. package/plugins/exec/source/process-output.ts +158 -0
  951. package/plugins/exec/source/request-resources.ts +28 -12
  952. package/plugins/exec/source/result-presentation.ts +39 -39
  953. package/plugins/exec/source/retained-output-failure.ts +51 -0
  954. package/plugins/exec/source/settings.ts +9 -10
  955. package/plugins/exec/source/terminal-delivery.ts +49 -0
  956. package/plugins/exec/source/types.ts +12 -1
  957. package/plugins/exec/src/index.cjs +1112 -188
  958. package/plugins/filesystem/plugin.json +5 -5
  959. package/plugins/filesystem/skills/read_file_skill/SKILL.md +1 -1
  960. package/plugins/filesystem/src/index.cjs +85 -37
  961. package/plugins/json-inspector/source/index.ts +7 -2
  962. package/plugins/json-inspector/src/index.cjs +91 -39
  963. package/plugins/local-search/source/index.ts +9 -4
  964. package/plugins/local-search/src/index.cjs +93 -41
  965. package/plugins/memory/src/index.cjs +85 -37
  966. package/plugins/project-orientation/source/index.ts +9 -4
  967. package/plugins/project-orientation/src/index.cjs +93 -41
  968. package/plugins/system/plugin.json +2 -2
  969. package/plugins/system/source/computer/observation-output.ts +1 -1
  970. package/plugins/system/src/index.cjs +88 -43
  971. package/plugins/system-probe/source/index.ts +7 -2
  972. package/plugins/system-probe/src/index.cjs +91 -39
  973. package/plugins/web/README.md +9 -0
  974. package/plugins/web/source/plugin.ts +5 -3
  975. package/plugins/web/source/research.ts +7 -7
  976. package/plugins/web/src/index.cjs +96 -43
  977. package/src/runtime/README.md +100 -11
  978. package/src/runtime/scheduler/README.md +63 -0
  979. package/dist/src/web-ui/app/components/passive-learning/proposal-notifications.js +0 -106
  980. package/dist/src/web-ui/app/components/passive-learning/proposal-read-state.js +0 -23
  981. package/dist/src/web-ui/app/components/passive-learning/proposal-view.js +0 -23
  982. package/dist/src/web-ui/app/components/spark-conversation-actions.js +0 -62
  983. package/dist/src/web-ui/app/services/spark-conversation-preferences.js +0 -27
  984. package/dist/src/web-ui/app/styles/29-spark-conversation.css +0 -19
@@ -138,8 +138,28 @@ function defineRuntimePlugin(definition) {
138
138
  return definition;
139
139
  }
140
140
 
141
+ // src/capabilities/tool-context-text.ts
142
+ function hasValidToolContextText(carrier) {
143
+ const fields = carrier.contextTextFields;
144
+ if (fields === void 0) return true;
145
+ if (!Array.isArray(fields) || fields.length === 0 || fields.length > 3)
146
+ return false;
147
+ if (new Set(fields).size !== fields.length) return false;
148
+ for (const field of fields) {
149
+ if (!isContextTextField(field)) return false;
150
+ if (typeof carrier[field] !== "string") return false;
151
+ }
152
+ return true;
153
+ }
154
+ function isContextTextField(value) {
155
+ return value === "output" || value === "stdout" || value === "stderr";
156
+ }
157
+
158
+ // src/capabilities/result-budget.ts
159
+ var CAPABILITY_RESULT_ENVELOPE_MAX_BYTES = 256 * 1024;
160
+
141
161
  // src/plugin-sdk/results.ts
142
- var PLUGIN_RESULT_SERIALIZED_MAX_BYTES = 128 * 1024;
162
+ var PLUGIN_RESULT_SERIALIZED_MAX_BYTES = CAPABILITY_RESULT_ENVELOPE_MAX_BYTES;
143
163
  function resultBoundsFailure(code, message) {
144
164
  return {
145
165
  ok: false,
@@ -149,9 +169,27 @@ function resultBoundsFailure(code, message) {
149
169
  errorCode: code
150
170
  };
151
171
  }
152
- function enforcePluginResultByteBudget(result) {
153
- let serialized;
172
+ function enforcePluginResultByteBudget(result, resultBudget) {
173
+ let requiresContextTextHost = false;
174
+ let serializedBytes;
175
+ let envelopeBytes;
176
+ let maxBytes = PLUGIN_RESULT_SERIALIZED_MAX_BYTES;
177
+ let fitsDeclaredBudget = true;
154
178
  try {
179
+ if (!hasValidToolContextText(result)) {
180
+ return resultBoundsFailure(
181
+ "plugin_context_text_invalid",
182
+ "The plugin declared invalid context text fields."
183
+ );
184
+ }
185
+ requiresContextTextHost = result.contextTextFields !== void 0;
186
+ const lacksContextTextHost = requiresContextTextHost && resultBudget?.acceptsContextText !== true;
187
+ if (lacksContextTextHost) {
188
+ return resultBoundsFailure(
189
+ "plugin_context_text_unavailable",
190
+ "The host does not support context-managed tool text."
191
+ );
192
+ }
155
193
  const candidate = JSON.stringify(result);
156
194
  if (candidate === void 0) {
157
195
  return resultBoundsFailure(
@@ -159,36 +197,43 @@ function enforcePluginResultByteBudget(result) {
159
197
  "The plugin produced a result that is not JSON-safe."
160
198
  );
161
199
  }
162
- serialized = candidate;
200
+ const assessment = resultBudget?.assess(result);
201
+ serializedBytes = assessment?.serializedBytes ?? Buffer.byteLength(candidate, "utf8");
202
+ envelopeBytes = assessment?.envelopeBytes ?? serializedBytes;
203
+ maxBytes = Math.min(assessment?.maxBytes ?? maxBytes, maxBytes);
204
+ fitsDeclaredBudget = assessment?.fits ?? true;
163
205
  } catch {
164
206
  return resultBoundsFailure(
165
207
  "plugin_result_not_json_safe",
166
208
  "The plugin produced a result that is not JSON-safe."
167
209
  );
168
210
  }
169
- if (Buffer.byteLength(serialized, "utf8") > PLUGIN_RESULT_SERIALIZED_MAX_BYTES) {
170
- return resultBoundsFailure(
171
- "plugin_result_too_large",
172
- `The plugin result exceeds the ${PLUGIN_RESULT_SERIALIZED_MAX_BYTES}-byte safety limit.`
173
- );
211
+ const hasResultDeliveryHeadroom = fitsDeclaredBudget && envelopeBytes <= maxBytes;
212
+ if (!hasResultDeliveryHeadroom) {
213
+ const message = requiresContextTextHost ? `The plugin result envelope is ${envelopeBytes} bytes (${serializedBytes} total bytes) and exceeds the ${maxBytes}-byte delivery limit.` : `The plugin result is ${serializedBytes} bytes and exceeds the ${maxBytes}-byte delivery limit.`;
214
+ return resultBoundsFailure("plugin_result_too_large", message);
174
215
  }
175
216
  return result;
176
217
  }
177
- function failureResult(input) {
178
- return enforcePluginResultByteBudget({
179
- ok: false,
180
- ...input.media !== void 0 ? { media: input.media } : {},
181
- output: input.output ?? input.message,
182
- producedNewInformation: false,
183
- ...input.progress !== void 0 ? { progress: input.progress } : {},
184
- ...input.actions !== void 0 ? { actions: input.actions } : {},
185
- ...input.exitCode !== void 0 ? { exitCode: input.exitCode } : {},
186
- ...input.stdout !== void 0 ? { stdout: input.stdout } : {},
187
- ...input.stderr !== void 0 ? { stderr: input.stderr } : {},
188
- ...input.data !== void 0 ? { data: input.data } : {},
189
- error: input.message,
190
- errorCode: input.errorCode
191
- });
218
+ function failureResult(input, resultBudget) {
219
+ return enforcePluginResultByteBudget(
220
+ {
221
+ ok: false,
222
+ ...input.interruption ? { interruption: input.interruption } : {},
223
+ ...input.media !== void 0 ? { media: input.media } : {},
224
+ output: input.output ?? input.message,
225
+ producedNewInformation: false,
226
+ ...input.progress !== void 0 ? { progress: input.progress } : {},
227
+ ...input.actions !== void 0 ? { actions: input.actions } : {},
228
+ ...input.exitCode !== void 0 ? { exitCode: input.exitCode } : {},
229
+ ...input.stdout !== void 0 ? { stdout: input.stdout } : {},
230
+ ...input.stderr !== void 0 ? { stderr: input.stderr } : {},
231
+ ...input.data !== void 0 ? { data: input.data } : {},
232
+ error: input.message,
233
+ errorCode: input.errorCode
234
+ },
235
+ resultBudget
236
+ );
192
237
  }
193
238
  function failureFromError(error, options) {
194
239
  const pathCode = runtimeToolPathErrorCode(error);
@@ -202,6 +247,21 @@ function failureFromError(error, options) {
202
247
  });
203
248
  }
204
249
 
250
+ // src/plugin-sdk/context-text-result.ts
251
+ function deliverPluginTextResult(result, fields, budget) {
252
+ const assessed = enforcePluginResultByteBudget(result, budget);
253
+ if (!canHandOffContextText(result, assessed, budget)) return assessed;
254
+ return enforcePluginResultByteBudget(
255
+ { ...result, contextTextFields: Object.freeze([...fields]) },
256
+ budget
257
+ );
258
+ }
259
+ function canHandOffContextText(original, assessed, budget) {
260
+ if (budget?.acceptsContextText !== true) return false;
261
+ if (assessed === original) return false;
262
+ return assessed.errorCode === "plugin_result_too_large";
263
+ }
264
+
205
265
  // src/capabilities/tool-media.ts
206
266
  var TOOL_IMAGE_MAX_BYTES = 10 * 1024 * 1024;
207
267
 
@@ -476,26 +536,32 @@ function diffExecFilesystemSnapshots(before, after) {
476
536
  }
477
537
 
478
538
  // plugins/exec/source/result-presentation.ts
479
- function streamDisplay(snapshot) {
480
- if (snapshot.text) return snapshot.text;
539
+ var EXEC_CONTEXT_TEXT_FIELDS = Object.freeze(["stdout", "stderr"]);
540
+ function streamReceipt(snapshot, field) {
541
+ if (snapshot.text) return `See the ${field} field (${snapshot.text.length} characters).`;
481
542
  return snapshot.sawOutput ? "(no new output; earlier output was already returned)" : "(empty)";
482
543
  }
483
- function renderedOutput(lines, outputMaxChars) {
484
- const bounded = boundText(lines.join("\n"), {
485
- maxChars: outputMaxChars,
486
- marker: "\n[exec output truncated]"
544
+ function renderedOutput(lines) {
545
+ const output = lines.join("\n");
546
+ return Object.freeze({
547
+ output,
548
+ metadata: Object.freeze({
549
+ truncated: false,
550
+ originalChars: output.length,
551
+ returnedChars: output.length,
552
+ omittedChars: 0
553
+ })
487
554
  });
488
- return Object.freeze({ output: bounded.text, metadata: bounded.metadata });
489
555
  }
490
- function outputBoundsData(snapshot, rendered, maxChars) {
556
+ function outputBoundsData(snapshot, rendered) {
491
557
  return Object.freeze({
492
- maxChars,
558
+ maxChars: null,
493
559
  stdout: snapshot.stdout.metadata,
494
560
  stderr: snapshot.stderr.metadata,
495
561
  rendered
496
562
  });
497
563
  }
498
- function runningResult(snapshot, execution) {
564
+ function runningResult(snapshot, execution, resultBudget) {
499
565
  const nextCursor = snapshot.nextCursor ?? 1;
500
566
  const rendered = renderedOutput(
501
567
  [
@@ -505,16 +571,17 @@ function runningResult(snapshot, execution) {
505
571
  `Process ID: ${snapshot.processId}`,
506
572
  `Next cursor: ${nextCursor}`,
507
573
  "STDOUT since the previous observation:",
508
- streamDisplay(snapshot.stdout),
574
+ streamReceipt(snapshot.stdout, "stdout"),
509
575
  "STDERR since the previous observation:",
510
- streamDisplay(snapshot.stderr),
576
+ streamReceipt(snapshot.stderr, "stderr"),
511
577
  "Continue this exact process with exec_wait; do not run the command again."
512
- ],
513
- execution.outputMaxChars
578
+ ]
514
579
  );
515
- return failureResult({
580
+ return deliverPluginTextResult({
581
+ ok: false,
582
+ producedNewInformation: false,
516
583
  errorCode: "exec_process_running",
517
- message: "The command is still running. Continue it with exec_wait using the returned process ID and cursor.",
584
+ error: "The command is still running. Continue it with exec_wait using the returned process ID and cursor.",
518
585
  output: rendered.output,
519
586
  stdout: snapshot.stdout.text,
520
587
  stderr: snapshot.stderr.text,
@@ -522,17 +589,13 @@ function runningResult(snapshot, execution) {
522
589
  processId: snapshot.processId,
523
590
  processStatus: "running",
524
591
  nextCursor,
525
- outputBounds: outputBoundsData(
526
- snapshot,
527
- rendered.metadata,
528
- execution.outputMaxChars
529
- ),
592
+ outputBounds: outputBoundsData(snapshot, rendered.metadata),
530
593
  observationMeta: {
531
594
  kind: "volatile_external",
532
595
  carryPolicy: "never"
533
596
  }
534
597
  }
535
- });
598
+ }, EXEC_CONTEXT_TEXT_FIELDS, resultBudget);
536
599
  }
537
600
  async function captureFilesystemDelta(execution) {
538
601
  if (!execution.filesystemStateBefore) return null;
@@ -604,12 +667,11 @@ async function finalizeExecResult(params) {
604
667
  `Exit code: ${exitCode}`,
605
668
  ...filesystemEvidence ? filesystemEvidence.outputLines : [],
606
669
  "STDOUT:",
607
- streamDisplay(snapshot.stdout),
670
+ streamReceipt(snapshot.stdout, "stdout"),
608
671
  "STDERR:",
609
- streamDisplay(snapshot.stderr),
672
+ streamReceipt(snapshot.stderr, "stderr"),
610
673
  ...resultSummary ? [resultSummary] : []
611
- ],
612
- execution.outputMaxChars
674
+ ]
613
675
  );
614
676
  const processStatus = snapshot.terminationReason ?? "completed";
615
677
  const data = {
@@ -618,11 +680,7 @@ async function finalizeExecResult(params) {
618
680
  ...filesystemEvidence ? { mutationGrounding: filesystemEvidence.mutationGrounding } : {},
619
681
  processId: snapshot.processId,
620
682
  processStatus,
621
- outputBounds: outputBoundsData(
622
- snapshot,
623
- rendered.metadata,
624
- execution.outputMaxChars
625
- ),
683
+ outputBounds: outputBoundsData(snapshot, rendered.metadata),
626
684
  ...filesystemDelta ? { filesystemObservation: filesystemDelta.observation } : { filesystemObservation: { available: false } },
627
685
  observationMeta: {
628
686
  kind: "volatile_external",
@@ -640,16 +698,42 @@ async function finalizeExecResult(params) {
640
698
  data
641
699
  };
642
700
  if (ok && (!inconclusiveSuccess || cancellationIsSuccess)) {
643
- return enforcePluginResultByteBudget({ ok: true, ...common });
701
+ return deliverPluginTextResult({ ok: true, ...common }, EXEC_CONTEXT_TEXT_FIELDS, params.resultBudget);
644
702
  }
645
703
  const errorCode = inconclusiveSuccess ? "no_observable_result" : snapshot.terminationReason === "aborted" ? "exec_aborted" : snapshot.terminationReason === "spawn_failed" ? "exec_spawn_failed" : snapshot.terminationReason === "idle_timeout" ? "exec_idle_timeout" : snapshot.terminationReason === "hard_timeout" ? "exec_hard_timeout" : "non_zero_exit";
646
704
  const error = inconclusiveSuccess ? resultSummary : errorCode === "exec_aborted" ? "The exec request was aborted." : errorCode === "exec_spawn_failed" ? "The runtime could not start the configured non-interactive shell." : errorCode === "exec_idle_timeout" ? `The command produced no output for ${execution.idleTimeoutMs}ms.` : errorCode === "exec_hard_timeout" ? `The command exceeded the ${execution.hardTimeoutMs}ms hard timeout.` : `The command exited with code ${exitCode}.`;
647
- return enforcePluginResultByteBudget({
705
+ return deliverPluginTextResult({
648
706
  ok: false,
649
707
  ...common,
650
708
  error,
651
709
  errorCode
652
- });
710
+ }, EXEC_CONTEXT_TEXT_FIELDS, params.resultBudget);
711
+ }
712
+
713
+ // plugins/exec/source/retained-output-failure.ts
714
+ function retainedOutputFailure(snapshot, context) {
715
+ const expired = hasUnavailableOutput(snapshot);
716
+ return failureResult(
717
+ {
718
+ errorCode: expired ? "exec_output_expired" : snapshot.outputFailure ? "exec_output_storage_failed" : "exec_output_delivery_pending",
719
+ message: expired ? "The retained output expired or is no longer available. The command was already started; it has not been run again." : snapshot.outputFailure ? "Output storage or delivery failed. The command was already started; do not run it again. Any committed bytes are retained for the configured retention period; complete output delivery is not confirmed." : "The output exceeds the delivery envelope and remains retained. The command was already executed; do not run it again.",
720
+ data: {
721
+ processId: snapshot.processId,
722
+ processStatus: snapshot.status,
723
+ nextCursor: snapshot.nextCursor,
724
+ ...snapshot.exitCode !== void 0 ? { exitCode: snapshot.exitCode } : {},
725
+ ...snapshot.terminationReason ? { terminationReason: snapshot.terminationReason } : {},
726
+ outputDelivery: expired ? "expired" : "pending",
727
+ ...snapshot.outputFailure ? { outputStorageFailure: snapshot.outputFailure } : {},
728
+ retainedCharacters: snapshot.stdout.text.length + snapshot.stderr.text.length
729
+ }
730
+ },
731
+ context?.resultBudget
732
+ );
733
+ }
734
+ function hasUnavailableOutput(snapshot) {
735
+ if (snapshot.outputFailure?.code === "exec_output_expired") return true;
736
+ return snapshot.outputFailure?.code === "exec_output_expired_or_unavailable";
653
737
  }
654
738
 
655
739
  // plugins/exec/source/errors.ts
@@ -676,6 +760,169 @@ function execFailureFromError(error, operation) {
676
760
  });
677
761
  }
678
762
 
763
+ // plugins/exec/source/terminal-delivery.ts
764
+ var import_node_crypto2 = require("node:crypto");
765
+ var ExecTerminalDelivery = class {
766
+ claim;
767
+ accepted = false;
768
+ get isClaimed() {
769
+ return this.claim !== void 0;
770
+ }
771
+ assertAvailable() {
772
+ if (this.isClaimed) throw this.unavailable();
773
+ }
774
+ reserve(snapshot) {
775
+ if (snapshot.status !== "settled") return snapshot;
776
+ this.assertAvailable();
777
+ this.claim = (0, import_node_crypto2.randomUUID)();
778
+ return Object.freeze({ ...snapshot, deliveryId: this.claim });
779
+ }
780
+ assertOwner(snapshot) {
781
+ if (snapshot.status !== "settled") return;
782
+ if (!this.claim || snapshot.deliveryId !== this.claim || this.accepted)
783
+ throw this.unavailable();
784
+ }
785
+ accept(snapshot) {
786
+ if (snapshot.status !== "settled") return;
787
+ this.assertOwner(snapshot);
788
+ this.accepted = true;
789
+ }
790
+ reject(snapshot) {
791
+ if (this.accepted) return;
792
+ if (snapshot.deliveryId !== this.claim) return;
793
+ this.claim = void 0;
794
+ }
795
+ unavailable() {
796
+ return new ExecPluginError(
797
+ "unknown_exec_process",
798
+ "The terminal exec result is already claimed by another observation."
799
+ );
800
+ }
801
+ };
802
+
803
+ // plugins/exec/source/output-files.ts
804
+ var import_node_crypto3 = require("node:crypto");
805
+ var import_promises2 = require("node:fs/promises");
806
+ var import_node_path2 = require("node:path");
807
+ var ID = /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/;
808
+ function outputStorageRoot(stateDir) {
809
+ if (!stateDir.trim()) throw outputFailure("state_dir_invalid");
810
+ return (0, import_node_path2.resolve)(stateDir, "output");
811
+ }
812
+ function outputOwnerDirectory(root, ownerId) {
813
+ if (!ownerId.trim()) throw outputFailure("owner_invalid");
814
+ return (0, import_node_path2.join)(root, (0, import_node_crypto3.createHash)("sha256").update(ownerId).digest("hex"));
815
+ }
816
+ function outputStreamPath(directory, id) {
817
+ assertOutputId(id);
818
+ return (0, import_node_path2.join)(directory, `${id}.bytes`);
819
+ }
820
+ function outputSnapshotPath(directory, id) {
821
+ assertOutputId(id);
822
+ return (0, import_node_path2.join)(directory, `${id}.snapshot.json`);
823
+ }
824
+ function assertOutputId(id) {
825
+ if (typeof id !== "string" || !ID.test(id)) throw outputFailure("id_invalid");
826
+ }
827
+ function outputFailure(code, cause) {
828
+ const error = new ExecPluginError(
829
+ `exec_output_${code}`,
830
+ `Exec output storage failed: ${code}.`
831
+ );
832
+ if (cause !== void 0)
833
+ Object.defineProperty(error, "cause", { value: cause });
834
+ return error;
835
+ }
836
+ async function writeOutputMetadata(path, value) {
837
+ const temporary = `${path}.${(0, import_node_crypto3.randomUUID)()}.tmp`;
838
+ try {
839
+ const file = await (0, import_promises2.open)(temporary, "wx", 384);
840
+ try {
841
+ await file.writeFile(JSON.stringify(value));
842
+ await file.sync();
843
+ } finally {
844
+ await file.close();
845
+ }
846
+ await (0, import_promises2.rename)(temporary, path);
847
+ const directory = await (0, import_promises2.open)((0, import_node_path2.dirname)(path), "r");
848
+ try {
849
+ await directory.sync();
850
+ } finally {
851
+ await directory.close();
852
+ }
853
+ } catch (error) {
854
+ await (0, import_promises2.rm)(temporary, { force: true }).catch(() => void 0);
855
+ throw outputFailure("metadata_write_failed", error);
856
+ }
857
+ }
858
+ async function prepareOutputOwnerDirectory(directory) {
859
+ try {
860
+ await (0, import_promises2.mkdir)(directory, { recursive: true, mode: 448 });
861
+ } catch (error) {
862
+ throw outputFailure("write_failed", error);
863
+ }
864
+ }
865
+ async function readOutputOwner(directory) {
866
+ let value;
867
+ try {
868
+ value = JSON.parse(await (0, import_promises2.readFile)((0, import_node_path2.join)(directory, "owner.json"), "utf8"));
869
+ } catch (error) {
870
+ if (error.code === "ENOENT") return void 0;
871
+ throw outputFailure("owner_read_failed", error);
872
+ }
873
+ if (!isOutputOwnerRecord(value)) throw outputFailure("owner_invalid");
874
+ return value;
875
+ }
876
+ function isOutputOwnerRecord(value) {
877
+ if (!value || typeof value !== "object") return false;
878
+ const owner = value;
879
+ if (owner.kind !== "exec_output_owner_v1") return false;
880
+ if (typeof owner.ownerId !== "string" || !owner.ownerId.trim()) return false;
881
+ return owner.completedAt === null || Number.isSafeInteger(owner.completedAt) && owner.completedAt >= 0;
882
+ }
883
+ async function lookupOutputSnapshot(directory, ownerId, id) {
884
+ let value;
885
+ try {
886
+ value = JSON.parse(
887
+ await (0, import_promises2.readFile)(outputSnapshotPath(directory, id), "utf8")
888
+ );
889
+ } catch (error) {
890
+ throw outputFailure("snapshot_unavailable", error);
891
+ }
892
+ if (!isStoredOutputSnapshot(value, ownerId, id))
893
+ throw outputFailure("snapshot_binding_invalid");
894
+ return value;
895
+ }
896
+ function isStoredOutputSnapshot(value, ownerId, id) {
897
+ if (!value || typeof value !== "object") return false;
898
+ const snapshot = value;
899
+ if (snapshot.kind !== "exec_output_snapshot_v1" || snapshot.ownerId !== ownerId)
900
+ return false;
901
+ if (typeof snapshot.streamId !== "string" || !ID.test(snapshot.streamId))
902
+ return false;
903
+ const body = snapshot.body;
904
+ if (!body || typeof body !== "object" || body.id !== id) return false;
905
+ return isExecOutputBody(body);
906
+ }
907
+ function isExecOutputBody(value) {
908
+ if (!value || typeof value !== "object") return false;
909
+ const body = value;
910
+ if (typeof body.id !== "string" || !ID.test(body.id)) return false;
911
+ if (body.stream !== "stdout" && body.stream !== "stderr") return false;
912
+ if (!Number.isSafeInteger(body.startByte) || body.startByte < 0) return false;
913
+ if (!Number.isSafeInteger(body.endByte) || body.endByte < body.startByte)
914
+ return false;
915
+ if (body.byteLength !== body.endByte - body.startByte) return false;
916
+ return typeof body.sha256 === "string" && /^sha256:[a-f0-9]{64}$/.test(body.sha256);
917
+ }
918
+ async function readOutputSnapshot(directory, ownerId, body) {
919
+ const snapshot = await lookupOutputSnapshot(directory, ownerId, body.id);
920
+ const stored = snapshot.body;
921
+ if (stored.stream !== body.stream || stored.startByte !== body.startByte || stored.endByte !== body.endByte || stored.byteLength !== body.byteLength || stored.sha256 !== body.sha256)
922
+ throw outputFailure("snapshot_binding_invalid");
923
+ return snapshot;
924
+ }
925
+
679
926
  // plugins/exec/source/request-resources.ts
680
927
  var ExecRequestResources = class {
681
928
  constructor(manager, pending, preparation) {
@@ -694,6 +941,7 @@ var ExecRequestResources = class {
694
941
  pending;
695
942
  owned = /* @__PURE__ */ new Map();
696
943
  restored = /* @__PURE__ */ new Map();
944
+ deliveries = /* @__PURE__ */ new Map();
697
945
  started(processId, scope, settled, context) {
698
946
  this.owned.set(processId, scope);
699
947
  context?.requestWork?.trackUntil(settled);
@@ -701,6 +949,10 @@ var ExecRequestResources = class {
701
949
  forget(processId) {
702
950
  this.owned.delete(processId);
703
951
  this.restored.delete(processId);
952
+ this.deliveries.delete(processId);
953
+ }
954
+ isRestored(processId) {
955
+ return this.restored.has(processId);
704
956
  }
705
957
  terminal(processId, scope, cursor) {
706
958
  const entry = this.restored.get(processId);
@@ -715,10 +967,16 @@ var ExecRequestResources = class {
715
967
  "stale_exec_process_cursor",
716
968
  "The saved exec cursor is stale."
717
969
  );
718
- this.restored.delete(processId);
719
- return structuredClone(entry.snapshot);
970
+ return this.deliveries.get(processId).reserve({
971
+ ...structuredClone(entry.snapshot),
972
+ nextCursor: entry.cursor
973
+ });
974
+ }
975
+ rejectTerminal(snapshot) {
976
+ this.deliveries.get(snapshot.processId)?.reject(snapshot);
720
977
  }
721
978
  snapshot() {
979
+ for (const delivery of this.deliveries.values()) delivery.assertAvailable();
722
980
  const executions = [...this.restored.values()];
723
981
  for (const [processId, scope] of this.owned) {
724
982
  const execution = this.pending.get(processId);
@@ -735,16 +993,17 @@ var ExecRequestResources = class {
735
993
  }
736
994
  });
737
995
  }
738
- return { kind: "exec_terminal_state_v1", executions };
996
+ return { kind: "exec_terminal_state_v2", executions };
739
997
  }
740
998
  restore(value) {
741
- if (!isRecord(value) || value.kind !== "exec_terminal_state_v1" || !Array.isArray(value.executions))
999
+ if (!isRecord(value) || value.kind !== "exec_terminal_state_v1" && value.kind !== "exec_terminal_state_v2" || !Array.isArray(value.executions))
742
1000
  throw invalid();
743
1001
  for (const entry of value.executions) {
744
1002
  if (!isSavedExecution(entry) || this.restored.has(entry.processId))
745
1003
  throw invalid();
746
1004
  const before = entry.execution.filesystemStateBefore;
747
1005
  this.restored.set(entry.processId, structuredClone(entry));
1006
+ this.deliveries.set(entry.processId, new ExecTerminalDelivery());
748
1007
  this.pending.set(entry.processId, {
749
1008
  ...structuredClone(entry.execution),
750
1009
  filesystemStateBefore: before ? { ...before, entries: new Map(before.entries) } : null
@@ -766,16 +1025,15 @@ var ExecRequestResources = class {
766
1025
  for (const id of this.restored.keys()) this.pending.delete(id);
767
1026
  this.owned.clear();
768
1027
  this.restored.clear();
1028
+ this.deliveries.clear();
769
1029
  }
770
1030
  };
771
1031
  function isSavedExecution(value) {
772
- if (!isRecord(value) || typeof value.processId !== "string" || typeof value.scope !== "string" || !Number.isSafeInteger(value.cursor) || value.cursor < 1 || !isRecord(value.snapshot) || value.snapshot.processId !== value.processId || value.snapshot.status !== "settled" || !isStream(value.snapshot.stdout) || !isStream(value.snapshot.stderr) || !Number.isFinite(value.snapshot.elapsedMs) || !isRecord(value.execution) || typeof value.execution.commandPreview !== "string" || !isRecord(value.execution.cwd) || typeof value.execution.cwd.absolutePath !== "string" || typeof value.execution.cwd.logicalPath !== "string")
1032
+ if (!isRecord(value) || typeof value.processId !== "string" || typeof value.scope !== "string" || !Number.isSafeInteger(value.cursor) || value.cursor < 1 || !isRecord(value.snapshot) || value.snapshot.processId !== value.processId || value.snapshot.status !== "settled" || !isStream(value.snapshot.stdout, "stdout") || !isStream(value.snapshot.stderr, "stderr") || !Number.isFinite(value.snapshot.elapsedMs) || !isRecord(value.execution) || typeof value.execution.commandPreview !== "string" || !isRecord(value.execution.cwd) || typeof value.execution.cwd.absolutePath !== "string" || typeof value.execution.cwd.logicalPath !== "string")
773
1033
  return false;
774
- if (![
775
- value.execution.hardTimeoutMs,
776
- value.execution.idleTimeoutMs,
777
- value.execution.outputMaxChars
778
- ].every(Number.isFinite))
1034
+ if (![value.execution.hardTimeoutMs, value.execution.idleTimeoutMs].every(
1035
+ Number.isFinite
1036
+ ))
779
1037
  return false;
780
1038
  const before = value.execution.filesystemStateBefore;
781
1039
  return before === null || isRecord(before) && typeof before.absoluteRoot === "string" && typeof before.logicalRoot === "string" && typeof before.rootExists === "boolean" && typeof before.complete === "boolean" && Array.isArray(before.entries) && before.entries.every(
@@ -784,8 +1042,8 @@ function isSavedExecution(value) {
784
1042
  )
785
1043
  );
786
1044
  }
787
- function isStream(value) {
788
- return isRecord(value) && typeof value.text === "string" && typeof value.sawOutput === "boolean" && isRecord(value.metadata) && typeof value.metadata.truncated === "boolean" && [
1045
+ function isStream(value, stream) {
1046
+ return isRecord(value) && typeof value.text === "string" && typeof value.sawOutput === "boolean" && (value.body === void 0 || isExecOutputBody(value.body) && value.body.stream === stream) && isRecord(value.metadata) && typeof value.metadata.truncated === "boolean" && [
789
1047
  value.metadata.originalChars,
790
1048
  value.metadata.returnedChars,
791
1049
  value.metadata.omittedChars
@@ -799,10 +1057,10 @@ function invalid() {
799
1057
  }
800
1058
 
801
1059
  // plugins/exec/source/paths.ts
802
- var import_promises2 = require("node:fs/promises");
803
- var import_node_path2 = require("node:path");
1060
+ var import_promises3 = require("node:fs/promises");
1061
+ var import_node_path3 = require("node:path");
804
1062
  function resolveContextualDirectory(pluginContext, executionContext, requestedPath) {
805
- if ((0, import_node_path2.isAbsolute)(requestedPath)) return { absolutePath: requestedPath };
1063
+ if ((0, import_node_path3.isAbsolute)(requestedPath)) return { absolutePath: requestedPath };
806
1064
  const isWorkspaceAlias = requestedPath === "workspace" || requestedPath.startsWith("workspace/");
807
1065
  const base = resolvePluginPath(
808
1066
  {
@@ -812,18 +1070,18 @@ function resolveContextualDirectory(pluginContext, executionContext, requestedPa
812
1070
  { allowedLocations: [isWorkspaceAlias ? "workspace" : "agent_work"] }
813
1071
  );
814
1072
  const relativePath = isWorkspaceAlias ? requestedPath.slice("workspace".length + 1) || "." : requestedPath;
815
- return { absolutePath: `${base.absolutePath}${import_node_path2.sep}${relativePath}`, base };
1073
+ return { absolutePath: `${base.absolutePath}${import_node_path3.sep}${relativePath}`, base };
816
1074
  }
817
1075
  function isOutsideExecContextBase(relativePath) {
818
1076
  if (relativePath === "..") return true;
819
- if (relativePath.startsWith(`..${import_node_path2.sep}`)) return true;
820
- return (0, import_node_path2.isAbsolute)(relativePath);
1077
+ if (relativePath.startsWith(`..${import_node_path3.sep}`)) return true;
1078
+ return (0, import_node_path3.isAbsolute)(relativePath);
821
1079
  }
822
1080
  function logicalDirectory(absolutePath, base) {
823
1081
  if (!base) return absolutePath;
824
- const fromBase = (0, import_node_path2.relative)(base.absolutePath, absolutePath);
1082
+ const fromBase = (0, import_node_path3.relative)(base.absolutePath, absolutePath);
825
1083
  if (isOutsideExecContextBase(fromBase)) return absolutePath;
826
- return import_node_path2.posix.join(base.logicalPath, fromBase.split(import_node_path2.sep).join("/") || ".");
1084
+ return import_node_path3.posix.join(base.logicalPath, fromBase.split(import_node_path3.sep).join("/") || ".");
827
1085
  }
828
1086
  async function resolveExecWorkingDirectory(pluginContext, executionContext, rawPath) {
829
1087
  const requestedPath = readRequiredString(rawPath, {
@@ -845,8 +1103,8 @@ async function resolveExecWorkingDirectory(pluginContext, executionContext, rawP
845
1103
  let absolutePath;
846
1104
  let info;
847
1105
  try {
848
- absolutePath = await (0, import_promises2.realpath)(target.absolutePath);
849
- info = await (0, import_promises2.stat)(absolutePath);
1106
+ absolutePath = await (0, import_promises3.realpath)(target.absolutePath);
1107
+ info = await (0, import_promises3.stat)(absolutePath);
850
1108
  } catch (error) {
851
1109
  if (error instanceof Error && "code" in error && error.code === "ENOENT") {
852
1110
  throw new ExecPluginError(
@@ -873,55 +1131,627 @@ async function resolveExecWorkingDirectory(pluginContext, executionContext, rawP
873
1131
 
874
1132
  // plugins/exec/source/process-manager.ts
875
1133
  var import_node_child_process = require("node:child_process");
876
- var import_node_crypto2 = require("node:crypto");
1134
+ var import_node_crypto6 = require("node:crypto");
1135
+ var import_node_os = require("node:os");
1136
+ var import_node_path6 = require("node:path");
1137
+
1138
+ // plugins/exec/source/process-output.ts
1139
+ function streamReceipt2(body) {
1140
+ return {
1141
+ text: "",
1142
+ sawOutput: (body?.endByte ?? 0) > 0,
1143
+ metadata: {
1144
+ truncated: false,
1145
+ originalChars: 0,
1146
+ returnedChars: 0,
1147
+ omittedChars: 0
1148
+ },
1149
+ ...body ? { body } : {}
1150
+ };
1151
+ }
1152
+ async function createExecProcessOutput(store, ownerId) {
1153
+ const stdout = await store.createWriter({ ownerId, stream: "stdout" });
1154
+ let stderr;
1155
+ try {
1156
+ stderr = await store.createWriter({ ownerId, stream: "stderr" });
1157
+ } catch (error) {
1158
+ await stdout.dispose();
1159
+ throw error;
1160
+ }
1161
+ const offsets = { stdout: 0, stderr: 0 };
1162
+ let settled;
1163
+ let failure;
1164
+ let finished2 = false;
1165
+ let tail = Promise.resolve();
1166
+ const serialize = async (operation) => {
1167
+ const previous = tail;
1168
+ let release = () => {
1169
+ };
1170
+ tail = new Promise((resolve2) => {
1171
+ release = resolve2;
1172
+ });
1173
+ await previous;
1174
+ try {
1175
+ return await operation();
1176
+ } finally {
1177
+ release();
1178
+ }
1179
+ };
1180
+ const recordFailure = (error) => {
1181
+ failure ??= error instanceof Error ? error.message : "exec_output_write_failed";
1182
+ };
1183
+ const capture = async () => {
1184
+ try {
1185
+ const out = await stdout.snapshot({
1186
+ startByte: offsets.stdout,
1187
+ endByte: finished2 ? stdout.byteLength : stdout.utf8ByteLength
1188
+ });
1189
+ const err = await stderr.snapshot({
1190
+ startByte: offsets.stderr,
1191
+ endByte: finished2 ? stderr.byteLength : stderr.utf8ByteLength
1192
+ });
1193
+ return {
1194
+ stdout: streamReceipt2(out),
1195
+ stderr: streamReceipt2(err),
1196
+ ...failureReceipt()
1197
+ };
1198
+ } catch (error) {
1199
+ recordFailure(error);
1200
+ return {
1201
+ stdout: streamReceipt2(),
1202
+ stderr: streamReceipt2(),
1203
+ ...failureReceipt()
1204
+ };
1205
+ }
1206
+ };
1207
+ const failureReceipt = () => failure ? {
1208
+ outputFailure: {
1209
+ code: failure,
1210
+ stdoutBytes: stdout.byteLength,
1211
+ stderrBytes: stderr.byteLength
1212
+ }
1213
+ } : {};
1214
+ return Object.freeze({
1215
+ attach(streams, onActivity, onFailure) {
1216
+ for (const name of ["stdout", "stderr"]) {
1217
+ const source = streams[name];
1218
+ const writer = name === "stdout" ? stdout : stderr;
1219
+ source.on("data", onActivity);
1220
+ const failed = (error) => {
1221
+ recordFailure(error);
1222
+ source.pause();
1223
+ onFailure();
1224
+ };
1225
+ writer.sink.on("error", failed);
1226
+ source.on("error", failed);
1227
+ source.pipe(writer.sink);
1228
+ }
1229
+ },
1230
+ async finish() {
1231
+ if (!stdout.sink.writableEnded) stdout.sink.end();
1232
+ if (!stderr.sink.writableEnded) stderr.sink.end();
1233
+ const outcomes = await Promise.allSettled([
1234
+ stdout.completion,
1235
+ stderr.completion
1236
+ ]);
1237
+ for (const outcome of outcomes)
1238
+ if (outcome.status === "rejected") recordFailure(outcome.reason);
1239
+ await serialize(async () => {
1240
+ finished2 = true;
1241
+ settled = await capture();
1242
+ });
1243
+ },
1244
+ peek() {
1245
+ return serialize(async () => settled ?? await capture());
1246
+ },
1247
+ checkpoint() {
1248
+ if (!settled) throw new Error("exec_snapshot_not_quiescent");
1249
+ return settled;
1250
+ },
1251
+ accept(snapshot) {
1252
+ return serialize(async () => {
1253
+ if (snapshot.outputFailure)
1254
+ throw new Error("exec_output_not_delivered");
1255
+ for (const name of ["stdout", "stderr"]) {
1256
+ const body = snapshot[name].body;
1257
+ const writer = name === "stdout" ? stdout : stderr;
1258
+ if (!body || body.startByte !== offsets[name] || body.endByte > writer.byteLength)
1259
+ throw new Error("exec_output_snapshot_mismatch");
1260
+ }
1261
+ offsets.stdout = snapshot.stdout.body.endByte;
1262
+ offsets.stderr = snapshot.stderr.body.endByte;
1263
+ if (finished2) settled = await capture();
1264
+ });
1265
+ },
1266
+ async dispose() {
1267
+ await Promise.all([stdout.dispose(), stderr.dispose()]);
1268
+ }
1269
+ });
1270
+ }
1271
+
1272
+ // plugins/exec/source/output-store.ts
1273
+ var import_promises9 = require("node:fs/promises");
1274
+ var import_node_path5 = require("node:path");
1275
+
1276
+ // plugins/exec/source/output-contracts.ts
1277
+ var DEFAULT_EXEC_OUTPUT_RETENTION_MS = 7 * 24 * 60 * 6e4;
1278
+ var EXEC_OUTPUT_IO_CHUNK_BYTES = 64 * 1024;
1279
+
1280
+ // plugins/exec/source/output-range-reader.ts
1281
+ var import_node_crypto4 = require("node:crypto");
1282
+ var import_promises4 = require("node:fs/promises");
1283
+ function assertOutputRange(startByte, endByte, availableBytes) {
1284
+ if (!Number.isSafeInteger(startByte) || startByte < 0)
1285
+ throw outputFailure("range_invalid");
1286
+ if (!Number.isSafeInteger(endByte) || endByte < startByte)
1287
+ throw outputFailure("range_invalid");
1288
+ if (endByte > availableBytes) throw outputFailure("range_invalid");
1289
+ }
1290
+ async function* readOutputFileRange(path, range) {
1291
+ assertOutputRange(
1292
+ range.offset,
1293
+ range.offset + range.length,
1294
+ Number.MAX_SAFE_INTEGER
1295
+ );
1296
+ if (!Number.isSafeInteger(range.maxChunkBytes) || range.maxChunkBytes < 1 || range.maxChunkBytes > EXEC_OUTPUT_IO_CHUNK_BYTES)
1297
+ throw outputFailure("chunk_size_invalid");
1298
+ range.signal?.throwIfAborted();
1299
+ const handle = await (0, import_promises4.open)(path, "r").catch((error) => {
1300
+ throw outputFailure("read_failed", error);
1301
+ });
1302
+ try {
1303
+ const end = range.offset + range.length;
1304
+ let position = range.offset;
1305
+ while (position < end) {
1306
+ range.signal?.throwIfAborted();
1307
+ const buffer = Buffer.allocUnsafe(
1308
+ Math.min(range.maxChunkBytes, end - position)
1309
+ );
1310
+ const { bytesRead } = await handle.read(
1311
+ buffer,
1312
+ 0,
1313
+ buffer.length,
1314
+ position
1315
+ );
1316
+ if (bytesRead === 0) throw outputFailure("body_incomplete");
1317
+ position += bytesRead;
1318
+ yield buffer.subarray(0, bytesRead);
1319
+ }
1320
+ range.signal?.throwIfAborted();
1321
+ } catch (error) {
1322
+ if (range.signal?.aborted) throw error;
1323
+ if (error instanceof ExecPluginError) throw error;
1324
+ throw outputFailure("read_failed", error);
1325
+ } finally {
1326
+ await handle.close();
1327
+ }
1328
+ }
1329
+ async function hashOutputRange(path, startByte, endByte, signal) {
1330
+ const hash = (0, import_node_crypto4.createHash)("sha256");
1331
+ for await (const chunk of readOutputFileRange(path, {
1332
+ offset: startByte,
1333
+ length: endByte - startByte,
1334
+ maxChunkBytes: EXEC_OUTPUT_IO_CHUNK_BYTES,
1335
+ ...signal ? { signal } : {}
1336
+ }))
1337
+ hash.update(chunk);
1338
+ return `sha256:${hash.digest("hex")}`;
1339
+ }
1340
+ async function assertOutputBodyHash(path, body, signal) {
1341
+ assertOutputRange(body.startByte, body.endByte, Number.MAX_SAFE_INTEGER);
1342
+ if (body.byteLength !== body.endByte - body.startByte)
1343
+ throw outputFailure("snapshot_binding_invalid");
1344
+ if (await hashOutputRange(path, body.startByte, body.endByte, signal) !== body.sha256)
1345
+ throw outputFailure("body_hash_mismatch");
1346
+ }
1347
+
1348
+ // plugins/exec/source/output-maintenance.ts
1349
+ var import_promises5 = require("node:fs/promises");
1350
+ var MAX_CLEANUP_INTERVAL_MS = 60 * 6e4;
1351
+ var jobs = /* @__PURE__ */ new Map();
1352
+ function scheduleExecOutputCleanup(root, retentionMs, cleanup) {
1353
+ const intervalMs = Math.max(
1354
+ 1,
1355
+ Math.min(retentionMs, MAX_CLEANUP_INTERVAL_MS)
1356
+ );
1357
+ const previous = jobs.get(root);
1358
+ if (previous) {
1359
+ previous.cleanup = cleanup;
1360
+ previous.intervalMs = intervalMs;
1361
+ previous.requested = true;
1362
+ return;
1363
+ }
1364
+ const job = { cleanup, intervalMs, requested: false };
1365
+ jobs.set(root, job);
1366
+ const sweep = async () => {
1367
+ job.requested = false;
1368
+ let empty = false;
1369
+ try {
1370
+ await job.cleanup();
1371
+ empty = (await (0, import_promises5.readdir)(root).catch((error) => {
1372
+ if (error.code === "ENOENT") return [];
1373
+ throw error;
1374
+ })).length === 0;
1375
+ } catch {
1376
+ process.emitWarning(
1377
+ "EXEC output cleanup failed; a later sweep will retry.",
1378
+ {
1379
+ code: "EXEC_OUTPUT_CLEANUP_FAILED"
1380
+ }
1381
+ );
1382
+ }
1383
+ if (empty && !job.requested) {
1384
+ jobs.delete(root);
1385
+ return;
1386
+ }
1387
+ const timer = setTimeout(() => {
1388
+ void sweep();
1389
+ }, job.intervalMs);
1390
+ timer.unref();
1391
+ };
1392
+ void sweep();
1393
+ }
1394
+
1395
+ // plugins/exec/source/output-retention.ts
1396
+ var import_promises6 = require("node:fs/promises");
1397
+ var import_node_path4 = require("node:path");
1398
+ async function outputCaptureCompletedAt(directory, owner) {
1399
+ if (owner?.completedAt !== null && owner?.completedAt !== void 0)
1400
+ return owner.completedAt;
1401
+ const entries = await (0, import_promises6.readdir)(directory, { withFileTypes: true });
1402
+ const captures = entries.filter(
1403
+ (entry) => entry.isFile() && entry.name.endsWith(".bytes")
1404
+ );
1405
+ if (!captures.length) return (await (0, import_promises6.stat)(directory)).mtimeMs;
1406
+ const times = await Promise.all(
1407
+ captures.map(
1408
+ async (entry) => (await (0, import_promises6.stat)((0, import_node_path4.join)(directory, entry.name))).mtimeMs
1409
+ )
1410
+ );
1411
+ return Math.max(...times);
1412
+ }
1413
+ async function hasOutputExpired(directory, owner, now, retentionMs) {
1414
+ return now - await outputCaptureCompletedAt(directory, owner) >= retentionMs;
1415
+ }
1416
+
1417
+ // plugins/exec/source/output-utf8-boundary.ts
1418
+ function incompleteUtf8TailBytes(tail) {
1419
+ if (tail.length === 0) return 0;
1420
+ let lead = tail.length - 1;
1421
+ while (lead >= 0 && (tail[lead] & 192) === 128) lead -= 1;
1422
+ if (lead < 0) return 0;
1423
+ const byte = tail[lead];
1424
+ let expected = 1;
1425
+ if (byte >= 194 && byte <= 223) expected = 2;
1426
+ if (byte >= 224 && byte <= 239) expected = 3;
1427
+ if (byte >= 240 && byte <= 244) expected = 4;
1428
+ const available = tail.length - lead;
1429
+ return available < expected ? available : 0;
1430
+ }
1431
+
1432
+ // plugins/exec/source/output-writer.ts
1433
+ var import_node_crypto5 = require("node:crypto");
1434
+ var import_promises7 = require("node:fs/promises");
1435
+ var import_node_stream = require("node:stream");
1436
+ var import_promises8 = require("node:stream/promises");
1437
+ var OutputFileSink = class extends import_node_stream.Writable {
1438
+ constructor(file) {
1439
+ super({ highWaterMark: EXEC_OUTPUT_IO_CHUNK_BYTES });
1440
+ this.file = file;
1441
+ }
1442
+ file;
1443
+ committedBytes = 0;
1444
+ utf8ByteLength = 0;
1445
+ tail = Buffer.alloc(0);
1446
+ _write(chunk, _encoding, callback) {
1447
+ this.writeChunk(chunk).then(
1448
+ () => callback(),
1449
+ (error) => callback(outputFailure("write_failed", error))
1450
+ );
1451
+ }
1452
+ async writeChunk(chunk) {
1453
+ let offset = 0;
1454
+ while (offset < chunk.length) {
1455
+ const length = Math.min(
1456
+ EXEC_OUTPUT_IO_CHUNK_BYTES,
1457
+ chunk.length - offset
1458
+ );
1459
+ const { bytesWritten } = await this.file.write(
1460
+ chunk,
1461
+ offset,
1462
+ length,
1463
+ this.committedBytes
1464
+ );
1465
+ if (bytesWritten === 0) throw outputFailure("write_zero_progress");
1466
+ const written = chunk.subarray(offset, offset + bytesWritten);
1467
+ this.tail = Buffer.concat([this.tail, written.subarray(-4)]).subarray(-4);
1468
+ offset += bytesWritten;
1469
+ this.committedBytes += bytesWritten;
1470
+ this.utf8ByteLength = this.committedBytes - incompleteUtf8TailBytes(this.tail);
1471
+ }
1472
+ }
1473
+ _final(callback) {
1474
+ this.file.datasync().then(
1475
+ () => callback(),
1476
+ (error) => callback(outputFailure("write_failed", error))
1477
+ );
1478
+ }
1479
+ _destroy(error, callback) {
1480
+ this.file.close().then(
1481
+ () => callback(error),
1482
+ (cause) => callback(error ?? outputFailure("close_failed", cause))
1483
+ );
1484
+ }
1485
+ };
1486
+ async function createOutputWriter(params) {
1487
+ const streamId = (0, import_node_crypto5.randomUUID)();
1488
+ const path = outputStreamPath(params.directory, streamId);
1489
+ const file = await (0, import_promises7.open)(path, "wx+", 384).catch((error) => {
1490
+ throw outputFailure("write_failed", error);
1491
+ });
1492
+ const sink = new OutputFileSink(file);
1493
+ const completion = (0, import_promises8.finished)(sink).finally(params.onClosed);
1494
+ void completion.catch(() => void 0);
1495
+ return Object.freeze({
1496
+ sink,
1497
+ get byteLength() {
1498
+ return sink.committedBytes;
1499
+ },
1500
+ get utf8ByteLength() {
1501
+ return sink.utf8ByteLength;
1502
+ },
1503
+ completion,
1504
+ async snapshot(range = {
1505
+ startByte: 0
1506
+ }) {
1507
+ if (sink.errored) throw sink.errored;
1508
+ const startByte = range.startByte;
1509
+ const endByte = range.endByte ?? sink.committedBytes;
1510
+ assertOutputRange(startByte, endByte, sink.committedBytes);
1511
+ const body = Object.freeze({
1512
+ id: (0, import_node_crypto5.randomUUID)(),
1513
+ stream: params.stream,
1514
+ startByte,
1515
+ endByte,
1516
+ byteLength: endByte - startByte,
1517
+ sha256: await hashOutputRange(path, startByte, endByte)
1518
+ });
1519
+ await writeOutputMetadata(outputSnapshotPath(params.directory, body.id), {
1520
+ kind: "exec_output_snapshot_v1",
1521
+ ownerId: params.ownerId,
1522
+ streamId,
1523
+ body
1524
+ });
1525
+ return body;
1526
+ },
1527
+ async dispose() {
1528
+ if (!sink.destroyed) sink.destroy();
1529
+ await completion.catch(() => void 0);
1530
+ }
1531
+ });
1532
+ }
1533
+
1534
+ // plugins/exec/source/output-store.ts
1535
+ var activeWriters = /* @__PURE__ */ new Map();
1536
+ var activeReaders = /* @__PURE__ */ new Map();
1537
+ var ownerOperations = /* @__PURE__ */ new Map();
1538
+ async function withOutputOwnerLock(directory, operation) {
1539
+ const previous = ownerOperations.get(directory) ?? Promise.resolve();
1540
+ let release = () => {
1541
+ };
1542
+ const current = new Promise((resolve2) => {
1543
+ release = resolve2;
1544
+ });
1545
+ ownerOperations.set(directory, current);
1546
+ await previous;
1547
+ try {
1548
+ return await operation();
1549
+ } finally {
1550
+ release();
1551
+ if (ownerOperations.get(directory) === current)
1552
+ ownerOperations.delete(directory);
1553
+ }
1554
+ }
1555
+ function createExecOutputStore(params) {
1556
+ const root = outputStorageRoot(params.stateDir);
1557
+ const retentionMs = params.retentionMs ?? DEFAULT_EXEC_OUTPUT_RETENTION_MS;
1558
+ if (!Number.isSafeInteger(retentionMs) || retentionMs < 0)
1559
+ throw outputFailure("retention_invalid");
1560
+ const now = params.now ?? Date.now;
1561
+ async function retain(directory, ownerId) {
1562
+ await prepareOutputOwnerDirectory(directory);
1563
+ const previous = await readOutputOwner(directory);
1564
+ if (previous && previous.ownerId !== ownerId)
1565
+ throw outputFailure("owner_binding_invalid");
1566
+ if (previous?.completedAt === null) return;
1567
+ await writeOutputMetadata((0, import_node_path5.join)(directory, "owner.json"), {
1568
+ kind: "exec_output_owner_v1",
1569
+ ownerId,
1570
+ completedAt: null
1571
+ });
1572
+ }
1573
+ const store = Object.freeze({
1574
+ async createWriter(input) {
1575
+ if (input.stream !== "stdout" && input.stream !== "stderr")
1576
+ throw outputFailure("stream_invalid");
1577
+ const directory = outputOwnerDirectory(root, input.ownerId);
1578
+ return withOutputOwnerLock(directory, async () => {
1579
+ await retain(directory, input.ownerId);
1580
+ const writer = await createOutputWriter({
1581
+ directory,
1582
+ ownerId: input.ownerId,
1583
+ stream: input.stream,
1584
+ async onClosed() {
1585
+ await withOutputOwnerLock(directory, async () => {
1586
+ const count = (activeWriters.get(directory) ?? 1) - 1;
1587
+ if (count > 0) activeWriters.set(directory, count);
1588
+ if (count > 0) return;
1589
+ activeWriters.delete(directory);
1590
+ await writeOutputMetadata((0, import_node_path5.join)(directory, "owner.json"), {
1591
+ kind: "exec_output_owner_v1",
1592
+ ownerId: input.ownerId,
1593
+ completedAt: now()
1594
+ });
1595
+ });
1596
+ }
1597
+ });
1598
+ activeWriters.set(directory, (activeWriters.get(directory) ?? 0) + 1);
1599
+ store.startMaintenance();
1600
+ return writer;
1601
+ });
1602
+ },
1603
+ async *readRange(input) {
1604
+ const directory = outputOwnerDirectory(root, input.ownerId);
1605
+ assertOutputRange(
1606
+ input.offset,
1607
+ input.offset + input.length,
1608
+ input.body.byteLength
1609
+ );
1610
+ await withOutputOwnerLock(directory, async () => {
1611
+ const owner = await readOutputOwner(directory);
1612
+ if (!owner) throw outputFailure("expired_or_unavailable");
1613
+ if (owner.ownerId !== input.ownerId)
1614
+ throw outputFailure("owner_binding_invalid");
1615
+ if (!activeWriters.has(directory) && await hasOutputExpired(directory, owner, now(), retentionMs))
1616
+ throw outputFailure("expired");
1617
+ activeReaders.set(directory, (activeReaders.get(directory) ?? 0) + 1);
1618
+ });
1619
+ try {
1620
+ const snapshot = await readOutputSnapshot(
1621
+ directory,
1622
+ input.ownerId,
1623
+ input.body
1624
+ );
1625
+ const path = outputStreamPath(directory, snapshot.streamId);
1626
+ await assertOutputBodyHash(path, input.body, input.signal);
1627
+ yield* readOutputFileRange(path, {
1628
+ offset: input.body.startByte + input.offset,
1629
+ length: input.length,
1630
+ maxChunkBytes: input.maxChunkBytes,
1631
+ ...input.signal ? { signal: input.signal } : {}
1632
+ });
1633
+ } finally {
1634
+ const count = (activeReaders.get(directory) ?? 1) - 1;
1635
+ if (count > 0) activeReaders.set(directory, count);
1636
+ if (count === 0) activeReaders.delete(directory);
1637
+ }
1638
+ },
1639
+ startMaintenance() {
1640
+ scheduleExecOutputCleanup(
1641
+ root,
1642
+ retentionMs,
1643
+ () => store.cleanupExpired()
1644
+ );
1645
+ },
1646
+ async cleanupExpired() {
1647
+ const directories = await (0, import_promises9.readdir)(root, { withFileTypes: true }).catch(
1648
+ (error) => {
1649
+ if (error.code === "ENOENT") return [];
1650
+ throw outputFailure("cleanup_failed", error);
1651
+ }
1652
+ );
1653
+ let removed = 0;
1654
+ for (const entry of directories) {
1655
+ if (!entry.isDirectory() || !/^[a-f0-9]{64}$/.test(entry.name))
1656
+ continue;
1657
+ const directory = (0, import_node_path5.join)(root, entry.name);
1658
+ await withOutputOwnerLock(directory, async () => {
1659
+ if (activeWriters.has(directory)) return;
1660
+ if (activeReaders.has(directory)) return;
1661
+ const owner = await readOutputOwner(directory);
1662
+ if (owner && outputOwnerDirectory(root, owner.ownerId) !== directory)
1663
+ throw outputFailure("owner_binding_invalid");
1664
+ if (!await hasOutputExpired(directory, owner, now(), retentionMs))
1665
+ return;
1666
+ await (0, import_promises9.rm)(directory, { recursive: true });
1667
+ removed += 1;
1668
+ });
1669
+ }
1670
+ return removed;
1671
+ }
1672
+ });
1673
+ return store;
1674
+ }
1675
+
1676
+ // plugins/exec/source/output-snapshot.ts
877
1677
  var import_node_string_decoder = require("node:string_decoder");
878
1678
 
879
1679
  // plugins/exec/source/process-output-buffer.ts
880
- var CappedTextBuffer = class {
881
- constructor(maxChars) {
882
- this.maxChars = maxChars;
883
- }
884
- maxChars;
1680
+ var ExecOutputBuffer = class {
885
1681
  text = "";
886
- originalChars = 0;
887
- omittedChars = 0;
888
1682
  sawOutput = false;
889
1683
  append(chunk) {
890
1684
  if (!chunk) return;
891
- const safeChunk = sanitizeJsonText(chunk);
892
1685
  this.sawOutput = true;
893
- this.originalChars += safeChunk.length;
894
- const available = Math.max(this.maxChars - this.text.length, 0);
895
- this.text += safeChunk.slice(0, available);
896
- this.omittedChars += Math.max(safeChunk.length - available, 0);
1686
+ this.text += sanitizeJsonText(chunk);
897
1687
  }
898
1688
  peek() {
899
1689
  const text = this.text;
900
- const originalChars = this.originalChars;
901
- const omittedChars = this.omittedChars;
902
1690
  return Object.freeze({
903
1691
  text,
904
1692
  sawOutput: this.sawOutput,
905
1693
  metadata: Object.freeze({
906
- truncated: omittedChars > 0,
907
- originalChars,
1694
+ truncated: false,
1695
+ originalChars: text.length,
908
1696
  returnedChars: text.length,
909
- omittedChars
1697
+ omittedChars: 0
910
1698
  })
911
1699
  });
912
1700
  }
1701
+ accept(snapshot) {
1702
+ if (!this.text.startsWith(snapshot.text)) {
1703
+ throw new Error("exec_output_snapshot_mismatch");
1704
+ }
1705
+ this.text = this.text.slice(snapshot.text.length);
1706
+ }
913
1707
  consume() {
914
1708
  const result = this.peek();
915
- this.text = "";
916
- this.originalChars = 0;
917
- this.omittedChars = 0;
1709
+ this.accept(result);
918
1710
  return result;
919
1711
  }
920
1712
  };
921
1713
 
1714
+ // plugins/exec/source/output-snapshot.ts
1715
+ function execOutputOwner(scope, processId) {
1716
+ return JSON.stringify([scope, processId]);
1717
+ }
1718
+ async function materializeExecOutput(store, scope, snapshot) {
1719
+ if (snapshot.outputFailure) return snapshot;
1720
+ const ownerId = execOutputOwner(scope, snapshot.processId);
1721
+ async function read(stream) {
1722
+ if (!stream.body) return stream;
1723
+ const decoder = new import_node_string_decoder.StringDecoder("utf8");
1724
+ const buffer = new ExecOutputBuffer();
1725
+ for await (const chunk of store.readRange({
1726
+ ownerId,
1727
+ body: stream.body,
1728
+ offset: 0,
1729
+ length: stream.body.byteLength,
1730
+ maxChunkBytes: EXEC_OUTPUT_IO_CHUNK_BYTES
1731
+ }))
1732
+ buffer.append(decoder.write(Buffer.from(chunk)));
1733
+ buffer.append(decoder.end());
1734
+ return { ...buffer.peek(), sawOutput: stream.sawOutput, body: stream.body };
1735
+ }
1736
+ try {
1737
+ const stdout = await read(snapshot.stdout);
1738
+ const stderr = await read(snapshot.stderr);
1739
+ return { ...snapshot, stdout, stderr };
1740
+ } catch (error) {
1741
+ return {
1742
+ ...snapshot,
1743
+ outputFailure: {
1744
+ code: error instanceof ExecPluginError ? error.code : "exec_output_read_failed",
1745
+ stdoutBytes: snapshot.stdout.body?.byteLength ?? 0,
1746
+ stderrBytes: snapshot.stderr.body?.byteLength ?? 0
1747
+ }
1748
+ };
1749
+ }
1750
+ }
1751
+
922
1752
  // plugins/exec/source/shell-platform.ts
923
1753
  var import_node_fs2 = require("node:fs");
924
- var import_promises3 = require("node:fs/promises");
1754
+ var import_promises10 = require("node:fs/promises");
925
1755
  var EXEC_SHELL = "/bin/bash";
926
1756
  function isSupportedExecPlatform(platform) {
927
1757
  return platform === "linux" || platform === "darwin";
@@ -934,7 +1764,7 @@ async function assertSupportedShell(platform = process.platform) {
934
1764
  );
935
1765
  }
936
1766
  try {
937
- await (0, import_promises3.access)(EXEC_SHELL, import_node_fs2.constants.X_OK);
1767
+ await (0, import_promises10.access)(EXEC_SHELL, import_node_fs2.constants.X_OK);
938
1768
  } catch {
939
1769
  throw new ExecPluginError(
940
1770
  "exec_shell_unavailable",
@@ -944,22 +1774,23 @@ async function assertSupportedShell(platform = process.platform) {
944
1774
  }
945
1775
 
946
1776
  // plugins/exec/source/process-manager.ts
947
- var COMPLETED_PROCESS_RETENTION_MS = 5 * 6e4;
948
1777
  var MAX_ACTIVE_PROCESSES_PER_SCOPE = 4;
949
- function createExecProcessManager() {
1778
+ function createExecProcessManager(store = createExecOutputStore({
1779
+ stateDir: (0, import_node_path6.join)((0, import_node_os.tmpdir)(), "abot-exec")
1780
+ })) {
950
1781
  const processes = /* @__PURE__ */ new Map();
1782
+ const opening = /* @__PURE__ */ new Map();
951
1783
  const unknownProcess = () => new ExecPluginError(
952
1784
  "unknown_exec_process",
953
1785
  "The exec process is unknown to this plugin instance and session."
954
1786
  );
955
1787
  const dispose = (managed) => {
956
- if (managed.retentionTimeout) clearTimeout(managed.retentionTimeout);
957
1788
  processes.delete(managed.processId);
958
1789
  managed.onDisposed?.(managed.processId);
959
1790
  };
960
1791
  const activeProcessCount = (scope) => [...processes.values()].filter(
961
1792
  (managed) => managed.scope === scope && !managed.settled
962
- ).length;
1793
+ ).length + (opening.get(scope) ?? 0);
963
1794
  const killProcessTree = (managed) => {
964
1795
  const pid = managed.child.pid;
965
1796
  if (typeof pid === "number") {
@@ -975,8 +1806,13 @@ function createExecProcessManager() {
975
1806
  if (managed.settled || managed.terminationReason) return;
976
1807
  managed.terminationReason = reason;
977
1808
  killProcessTree(managed);
1809
+ if (reason === "output_storage_failed") {
1810
+ managed.child.stdout.destroy();
1811
+ managed.child.stderr.destroy();
1812
+ }
978
1813
  };
979
1814
  const scheduleIdleTimeout = (managed, idleTimeoutMs) => {
1815
+ if (managed.settling || managed.settled) return;
980
1816
  if (managed.idleTimeout) clearTimeout(managed.idleTimeout);
981
1817
  managed.idleTimeout = setTimeout(
982
1818
  () => requestTermination(managed, "idle_timeout"),
@@ -984,11 +1820,17 @@ function createExecProcessManager() {
984
1820
  );
985
1821
  managed.idleTimeout.unref?.();
986
1822
  };
987
- const settle = (managed, exitCode, fallbackReason) => {
988
- if (managed.settled) return;
1823
+ const settle = async (managed, exitCode, fallbackReason) => {
1824
+ if (managed.settling || managed.settled) return;
1825
+ managed.settling = true;
1826
+ if (managed.hardTimeout) clearTimeout(managed.hardTimeout);
1827
+ if (managed.idleTimeout) clearTimeout(managed.idleTimeout);
1828
+ await managed.output.finish();
989
1829
  managed.settled = true;
1830
+ if (managed.output.checkpoint().outputFailure)
1831
+ managed.terminationReason = "output_storage_failed";
990
1832
  managed.terminationReason ??= fallbackReason;
991
- managed.exitCode = managed.terminationReason === "hard_timeout" || managed.terminationReason === "idle_timeout" ? 124 : managed.terminationReason === "cancelled" || managed.terminationReason === "aborted" ? 130 : exitCode;
1833
+ managed.exitCode = managed.terminationReason === "hard_timeout" || managed.terminationReason === "idle_timeout" ? 124 : managed.terminationReason === "cancelled" || managed.terminationReason === "aborted" ? 130 : managed.terminationReason === "output_storage_failed" ? -1 : exitCode;
992
1834
  if (managed.hardTimeout) clearTimeout(managed.hardTimeout);
993
1835
  if (managed.idleTimeout) clearTimeout(managed.idleTimeout);
994
1836
  if (managed.abortSignal && managed.abortListener) {
@@ -999,35 +1841,43 @@ function createExecProcessManager() {
999
1841
  dispose(managed);
1000
1842
  return;
1001
1843
  }
1002
- managed.retentionTimeout = setTimeout(
1003
- () => dispose(managed),
1004
- COMPLETED_PROCESS_RETENTION_MS
1005
- );
1006
- managed.retentionTimeout.unref?.();
1007
1844
  };
1008
- const consumeSnapshot = (managed) => {
1009
- if (managed.settled) {
1010
- if (managed.terminalSnapshotClaimed) throw unknownProcess();
1011
- managed.terminalSnapshotClaimed = true;
1845
+ const peekSnapshot = async (managed) => {
1846
+ managed.terminalDelivery.assertAvailable();
1847
+ const status = managed.settled ? "settled" : "running";
1848
+ const output = await managed.output.peek();
1849
+ if (output.outputFailure && !managed.settled) {
1850
+ requestTermination(managed, "output_storage_failed");
1851
+ await managed.settlePromise;
1852
+ return peekSnapshot(managed);
1012
1853
  }
1013
- return Object.freeze({
1014
- processId: managed.processId,
1015
- status: managed.settled ? "settled" : "running",
1016
- ...!managed.settled ? { nextCursor: managed.cursor } : {},
1017
- ...managed.exitCode === void 0 ? {} : { exitCode: managed.exitCode },
1018
- stdout: managed.stdout.consume(),
1019
- stderr: managed.stderr.consume(),
1020
- ...managed.terminationReason ? { terminationReason: managed.terminationReason } : {},
1021
- elapsedMs: Date.now() - managed.startedAt
1022
- });
1854
+ const snapshot = await materializeExecOutput(
1855
+ store,
1856
+ managed.scope,
1857
+ Object.freeze({
1858
+ processId: managed.processId,
1859
+ status,
1860
+ nextCursor: managed.cursor,
1861
+ ...managed.exitCode === void 0 ? {} : { exitCode: managed.exitCode },
1862
+ ...output,
1863
+ ...managed.terminationReason ? { terminationReason: managed.terminationReason } : {},
1864
+ elapsedMs: Date.now() - managed.startedAt
1865
+ })
1866
+ );
1867
+ if (snapshot.outputFailure && !managed.settled) {
1868
+ requestTermination(managed, "output_storage_failed");
1869
+ await managed.settlePromise;
1870
+ return peekSnapshot(managed);
1871
+ }
1872
+ return managed.terminalDelivery.reserve(snapshot);
1023
1873
  };
1024
1874
  const waitForSettlement = async (managed, waitMs) => {
1025
1875
  if (managed.settled) return;
1026
1876
  let timeout;
1027
1877
  await Promise.race([
1028
1878
  managed.settlePromise,
1029
- new Promise((resolve) => {
1030
- timeout = setTimeout(resolve, waitMs);
1879
+ new Promise((resolve2) => {
1880
+ timeout = setTimeout(resolve2, waitMs);
1031
1881
  timeout.unref?.();
1032
1882
  })
1033
1883
  ]);
@@ -1043,8 +1893,8 @@ function createExecProcessManager() {
1043
1893
  const withProcessTransition = async (managed, operation) => {
1044
1894
  const previous = managed.transitionTail;
1045
1895
  let releaseTransition = () => void 0;
1046
- managed.transitionTail = new Promise((resolve) => {
1047
- releaseTransition = resolve;
1896
+ managed.transitionTail = new Promise((resolve2) => {
1897
+ releaseTransition = resolve2;
1048
1898
  });
1049
1899
  await previous;
1050
1900
  try {
@@ -1063,9 +1913,27 @@ function createExecProcessManager() {
1063
1913
  `The session already has ${MAX_ACTIVE_PROCESSES_PER_SCOPE} active exec processes.`
1064
1914
  );
1065
1915
  }
1916
+ opening.set(params.scope, (opening.get(params.scope) ?? 0) + 1);
1917
+ const processId = `exec_${(0, import_node_crypto6.randomUUID)()}`;
1918
+ let output;
1919
+ try {
1920
+ await store.cleanupExpired();
1921
+ output = await createExecProcessOutput(
1922
+ store,
1923
+ execOutputOwner(params.scope, processId)
1924
+ );
1925
+ if (params.abortSignal?.aborted) {
1926
+ await output.dispose();
1927
+ params.abortSignal.throwIfAborted();
1928
+ }
1929
+ } finally {
1930
+ const count = opening.get(params.scope) - 1;
1931
+ if (count) opening.set(params.scope, count);
1932
+ else opening.delete(params.scope);
1933
+ }
1066
1934
  let resolveSettled = () => void 0;
1067
- const settlePromise = new Promise((resolve) => {
1068
- resolveSettled = resolve;
1935
+ const settlePromise = new Promise((resolve2) => {
1936
+ resolveSettled = resolve2;
1069
1937
  });
1070
1938
  let child;
1071
1939
  try {
@@ -1075,51 +1943,41 @@ function createExecProcessManager() {
1075
1943
  stdio: ["ignore", "pipe", "pipe"]
1076
1944
  });
1077
1945
  } catch {
1946
+ await output.dispose();
1078
1947
  throw new ExecPluginError(
1079
1948
  "exec_spawn_failed",
1080
1949
  "The runtime could not start the configured non-interactive shell."
1081
1950
  );
1082
1951
  }
1083
1952
  const managed = {
1084
- processId: `exec_${(0, import_node_crypto2.randomUUID)()}`,
1953
+ processId,
1085
1954
  scope: params.scope,
1086
1955
  child,
1087
1956
  startedAt: Date.now(),
1088
1957
  cursor: 1,
1089
- stdout: new CappedTextBuffer(params.outputMaxChars),
1090
- stderr: new CappedTextBuffer(params.outputMaxChars),
1091
- stdoutDecoder: new import_node_string_decoder.StringDecoder("utf8"),
1092
- stderrDecoder: new import_node_string_decoder.StringDecoder("utf8"),
1958
+ output,
1959
+ settling: false,
1093
1960
  settled: false,
1094
1961
  settlePromise,
1095
1962
  resolveSettled,
1096
1963
  transitionTail: Promise.resolve(),
1097
- terminalSnapshotClaimed: false,
1964
+ terminalDelivery: new ExecTerminalDelivery(),
1098
1965
  waitInFlight: false,
1099
1966
  ...params.abortSignal ? { abortSignal: params.abortSignal } : {},
1100
1967
  ...params.onDisposed ? { onDisposed: params.onDisposed } : {}
1101
1968
  };
1102
1969
  processes.set(managed.processId, managed);
1103
1970
  params.onStarted?.(managed.processId, managed.settlePromise);
1104
- const observe = (stream, chunk) => {
1105
- if (managed.settled || !chunk) return;
1106
- if (stream === "stdout") managed.stdout.append(chunk);
1107
- else managed.stderr.append(chunk);
1108
- scheduleIdleTimeout(managed, params.idleTimeoutMs);
1109
- };
1110
- child.stdout.on(
1111
- "data",
1112
- (chunk) => observe("stdout", managed.stdoutDecoder.write(chunk))
1113
- );
1114
- child.stderr.on(
1115
- "data",
1116
- (chunk) => observe("stderr", managed.stderrDecoder.write(chunk))
1971
+ output.attach(
1972
+ child,
1973
+ () => scheduleIdleTimeout(managed, params.idleTimeoutMs),
1974
+ () => requestTermination(managed, "output_storage_failed")
1117
1975
  );
1118
- child.on("error", () => settle(managed, -1, "spawn_failed"));
1976
+ child.on("error", () => {
1977
+ void settle(managed, -1, "spawn_failed");
1978
+ });
1119
1979
  child.on("close", (code) => {
1120
- observe("stdout", managed.stdoutDecoder.end());
1121
- observe("stderr", managed.stderrDecoder.end());
1122
- settle(managed, typeof code === "number" ? code : -1, "completed");
1980
+ void settle(managed, typeof code === "number" ? code : -1, "completed");
1123
1981
  });
1124
1982
  managed.hardTimeout = setTimeout(
1125
1983
  () => requestTermination(managed, "hard_timeout"),
@@ -1141,12 +1999,12 @@ function createExecProcessManager() {
1141
1999
  } else {
1142
2000
  await waitForSettlement(managed, params.yieldAfterMs);
1143
2001
  }
1144
- return consumeSnapshot(managed);
2002
+ return peekSnapshot(managed);
1145
2003
  },
1146
2004
  async wait(params) {
1147
2005
  const managed = getScopedProcess(params.processId, params.scope);
1148
2006
  await withProcessTransition(managed, () => {
1149
- if (managed.terminalSnapshotClaimed) throw unknownProcess();
2007
+ managed.terminalDelivery.assertAvailable();
1150
2008
  if (managed.waitInFlight) {
1151
2009
  throw new ExecPluginError(
1152
2010
  "exec_wait_in_progress",
@@ -1165,24 +2023,24 @@ function createExecProcessManager() {
1165
2023
  await waitForSettlement(managed, params.waitMs);
1166
2024
  return withProcessTransition(managed, () => {
1167
2025
  managed.waitInFlight = false;
1168
- if (managed.terminalSnapshotClaimed) throw unknownProcess();
1169
- return consumeSnapshot(managed);
2026
+ managed.terminalDelivery.assertAvailable();
2027
+ return peekSnapshot(managed);
1170
2028
  });
1171
2029
  },
1172
2030
  async cancel(params) {
1173
2031
  const managed = getScopedProcess(params.processId, params.scope);
1174
2032
  return withProcessTransition(managed, async () => {
1175
- if (managed.terminalSnapshotClaimed) throw unknownProcess();
2033
+ managed.terminalDelivery.assertAvailable();
1176
2034
  if (!managed.settled) {
1177
2035
  requestTermination(managed, "cancelled");
1178
2036
  await managed.settlePromise;
1179
2037
  }
1180
- return consumeSnapshot(managed);
2038
+ return peekSnapshot(managed);
1181
2039
  });
1182
2040
  },
1183
2041
  snapshotSettled(processId, scope) {
1184
2042
  const managed = getScopedProcess(processId, scope);
1185
- if (!managed.settled || managed.waitInFlight || managed.terminalSnapshotClaimed)
2043
+ if (!managed.settled || managed.waitInFlight || managed.terminalDelivery.isClaimed)
1186
2044
  throw new Error("exec_snapshot_not_quiescent");
1187
2045
  return Object.freeze({
1188
2046
  cursor: managed.cursor,
@@ -1190,13 +2048,36 @@ function createExecProcessManager() {
1190
2048
  processId,
1191
2049
  status: "settled",
1192
2050
  ...managed.exitCode === void 0 ? {} : { exitCode: managed.exitCode },
1193
- stdout: managed.stdout.peek(),
1194
- stderr: managed.stderr.peek(),
2051
+ ...managed.output.checkpoint(),
1195
2052
  ...managed.terminationReason ? { terminationReason: managed.terminationReason } : {},
1196
2053
  elapsedMs: Date.now() - managed.startedAt
1197
2054
  })
1198
2055
  });
1199
2056
  },
2057
+ async accept(snapshot, scope) {
2058
+ const wasReleasedAfterAbort = snapshot.terminationReason === "aborted" && !processes.has(snapshot.processId);
2059
+ if (wasReleasedAfterAbort) return;
2060
+ const managed = getScopedProcess(snapshot.processId, scope);
2061
+ await withProcessTransition(managed, async () => {
2062
+ managed.terminalDelivery.assertOwner(snapshot);
2063
+ if (snapshot.nextCursor !== managed.cursor) {
2064
+ throw new ExecPluginError(
2065
+ "stale_exec_process_cursor",
2066
+ "The output receipt no longer matches the current exec cursor."
2067
+ );
2068
+ }
2069
+ await managed.output.accept(snapshot);
2070
+ managed.terminalDelivery.accept(snapshot);
2071
+ });
2072
+ },
2073
+ async reject(snapshot, scope) {
2074
+ const managed = processes.get(snapshot.processId);
2075
+ if (!managed) return;
2076
+ if (managed.scope !== scope) throw unknownProcess();
2077
+ await withProcessTransition(managed, () => {
2078
+ managed.terminalDelivery.reject(snapshot);
2079
+ });
2080
+ },
1200
2081
  async release(processId, scope) {
1201
2082
  const managed = processes.get(processId);
1202
2083
  if (!managed) return;
@@ -1214,11 +2095,15 @@ function createExecProcessManager() {
1214
2095
  var DEFAULT_EXEC_HARD_TIMEOUT_MS = 6e5;
1215
2096
  var DEFAULT_EXEC_YIELD_AFTER_MS = 15e3;
1216
2097
  var DEFAULT_EXEC_IDLE_TIMEOUT_MS = 12e4;
1217
- var DEFAULT_EXEC_OUTPUT_MAX_CHARS = 8e3;
1218
- var EXEC_OUTPUT_MAX_CHARS = 8e3;
1219
- var EXEC_COMMAND_MAX_CHARS = 4096;
2098
+ var EXEC_COMMAND_MAX_CHARS = 8192;
1220
2099
  function readExecSettings(config) {
1221
2100
  return Object.freeze({
2101
+ outputRetentionMs: readBoundedInteger(config?.outputRetentionMs, {
2102
+ defaultValue: DEFAULT_EXEC_OUTPUT_RETENTION_MS,
2103
+ minimum: 1,
2104
+ maximum: Number.MAX_SAFE_INTEGER,
2105
+ name: "outputRetentionMs"
2106
+ }),
1222
2107
  hardTimeoutMs: readBoundedInteger(config?.timeoutMs, {
1223
2108
  defaultValue: DEFAULT_EXEC_HARD_TIMEOUT_MS,
1224
2109
  minimum: 1,
@@ -1236,12 +2121,6 @@ function readExecSettings(config) {
1236
2121
  minimum: 1,
1237
2122
  maximum: 36e5,
1238
2123
  name: "idleTimeoutMs"
1239
- }),
1240
- outputMaxChars: readBoundedInteger(config?.outputMaxChars, {
1241
- defaultValue: DEFAULT_EXEC_OUTPUT_MAX_CHARS,
1242
- minimum: 64,
1243
- maximum: EXEC_OUTPUT_MAX_CHARS,
1244
- name: "outputMaxChars"
1245
2124
  })
1246
2125
  });
1247
2126
  }
@@ -1293,7 +2172,12 @@ function processScope(context) {
1293
2172
  return sessionId || "anonymous";
1294
2173
  }
1295
2174
  function createExecHandlers(pluginContext, settings, preparation) {
1296
- const processManager = createExecProcessManager();
2175
+ const outputStore = createExecOutputStore({
2176
+ stateDir: pluginContext.stateDir,
2177
+ retentionMs: settings.outputRetentionMs
2178
+ });
2179
+ outputStore.startMaintenance();
2180
+ const processManager = createExecProcessManager(outputStore);
1297
2181
  const pendingExecutions = /* @__PURE__ */ new Map();
1298
2182
  const requestResources = new ExecRequestResources(
1299
2183
  processManager,
@@ -1301,13 +2185,52 @@ function createExecHandlers(pluginContext, settings, preparation) {
1301
2185
  preparation
1302
2186
  );
1303
2187
  const finalizeAndRelease = async (params) => {
2188
+ pendingExecutions.set(params.snapshot.processId, params.execution);
1304
2189
  try {
1305
- return await finalizeExecResult(params);
1306
- } finally {
2190
+ if (params.snapshot.outputFailure) {
2191
+ return retainedOutputFailure(params.snapshot, params.context);
2192
+ }
2193
+ const result = await finalizeExecResult({
2194
+ ...params,
2195
+ resultBudget: params.context?.resultBudget
2196
+ });
2197
+ if (result.errorCode === "plugin_result_too_large") {
2198
+ return retainedOutputFailure(params.snapshot, params.context);
2199
+ }
2200
+ try {
2201
+ if (!requestResources.isRestored(params.snapshot.processId)) {
2202
+ await processManager.accept(params.snapshot, params.scope);
2203
+ }
2204
+ } catch (error) {
2205
+ return retainedOutputFailure(
2206
+ {
2207
+ ...params.snapshot,
2208
+ outputFailure: {
2209
+ code: error instanceof Error ? error.message : "exec_output_acknowledgement_failed",
2210
+ stdoutBytes: params.snapshot.stdout.body?.byteLength ?? 0,
2211
+ stderrBytes: params.snapshot.stderr.body?.byteLength ?? 0
2212
+ }
2213
+ },
2214
+ params.context
2215
+ );
2216
+ }
1307
2217
  pendingExecutions.delete(params.snapshot.processId);
1308
2218
  requestResources.forget(params.snapshot.processId);
1309
2219
  await processManager.release(params.snapshot.processId, params.scope);
2220
+ return result;
2221
+ } finally {
2222
+ requestResources.rejectTerminal(params.snapshot);
2223
+ await processManager.reject(params.snapshot, params.scope);
2224
+ }
2225
+ };
2226
+ const deliverRunning = async (snapshot, execution, scope, context) => {
2227
+ if (snapshot.outputFailure) return retainedOutputFailure(snapshot, context);
2228
+ const result = runningResult(snapshot, execution, context?.resultBudget);
2229
+ if (result.errorCode === "plugin_result_too_large") {
2230
+ return retainedOutputFailure(snapshot, context);
1310
2231
  }
2232
+ await processManager.accept(snapshot, scope);
2233
+ return result;
1311
2234
  };
1312
2235
  const exec = async (params, context) => {
1313
2236
  try {
@@ -1330,15 +2253,13 @@ function createExecHandlers(pluginContext, settings, preparation) {
1330
2253
  cwd,
1331
2254
  filesystemStateBefore,
1332
2255
  hardTimeoutMs: settings.hardTimeoutMs,
1333
- idleTimeoutMs: Math.min(settings.idleTimeoutMs, settings.hardTimeoutMs),
1334
- outputMaxChars: settings.outputMaxChars
2256
+ idleTimeoutMs: Math.min(settings.idleTimeoutMs, settings.hardTimeoutMs)
1335
2257
  });
1336
2258
  const scope = processScope(context);
1337
2259
  const snapshot = await processManager.start({
1338
2260
  scope,
1339
2261
  shellCommand: command,
1340
2262
  cwd: cwd.absolutePath,
1341
- outputMaxChars: settings.outputMaxChars,
1342
2263
  yieldAfterMs: Math.min(settings.yieldAfterMs, settings.hardTimeoutMs),
1343
2264
  idleTimeoutMs: execution.idleTimeoutMs,
1344
2265
  hardTimeoutMs: execution.hardTimeoutMs,
@@ -1351,9 +2272,9 @@ function createExecHandlers(pluginContext, settings, preparation) {
1351
2272
  });
1352
2273
  if (snapshot.status === "running") {
1353
2274
  pendingExecutions.set(snapshot.processId, execution);
1354
- return runningResult(snapshot, execution);
2275
+ return deliverRunning(snapshot, execution, scope, context);
1355
2276
  }
1356
- return finalizeAndRelease({ snapshot, execution, scope });
2277
+ return finalizeAndRelease({ snapshot, execution, scope, context });
1357
2278
  } catch (error) {
1358
2279
  return execFailureFromError(error, "exec");
1359
2280
  }
@@ -1377,13 +2298,14 @@ function createExecHandlers(pluginContext, settings, preparation) {
1377
2298
  );
1378
2299
  }
1379
2300
  const scope = processScope(context);
1380
- const snapshot = requestResources.terminal(processId, scope, cursor) ?? await processManager.wait({
2301
+ const restored = requestResources.terminal(processId, scope, cursor);
2302
+ const snapshot = restored ? await materializeExecOutput(outputStore, scope, restored) : await processManager.wait({
1381
2303
  processId,
1382
2304
  scope,
1383
2305
  cursor,
1384
2306
  waitMs: settings.yieldAfterMs
1385
2307
  });
1386
- return snapshot.status === "running" ? runningResult(snapshot, execution) : finalizeAndRelease({ snapshot, execution, scope });
2308
+ return snapshot.status === "running" ? deliverRunning(snapshot, execution, scope, context) : finalizeAndRelease({ snapshot, execution, scope, context });
1387
2309
  } catch (error) {
1388
2310
  return execFailureFromError(error, "exec_wait");
1389
2311
  }
@@ -1402,12 +2324,14 @@ function createExecHandlers(pluginContext, settings, preparation) {
1402
2324
  );
1403
2325
  }
1404
2326
  const scope = processScope(context);
1405
- const snapshot = requestResources.terminal(processId, scope) ?? await processManager.cancel({ processId, scope });
2327
+ const restored = requestResources.terminal(processId, scope);
2328
+ const snapshot = restored ? await materializeExecOutput(outputStore, scope, restored) : await processManager.cancel({ processId, scope });
1406
2329
  return finalizeAndRelease({
1407
2330
  snapshot,
1408
2331
  execution,
1409
2332
  scope,
1410
- cancellationIsSuccess: true
2333
+ cancellationIsSuccess: true,
2334
+ context
1411
2335
  });
1412
2336
  } catch (error) {
1413
2337
  return execFailureFromError(error, "exec_cancel");