@qlairoslabs/acp-client 0.12.1 → 0.13.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (467) hide show
  1. package/CHANGELOG-consumer-fixes.md +17 -10
  2. package/CHANGELOG-controller-interface.md +258 -0
  3. package/CHANGELOG-metering.md +29 -0
  4. package/CHANGELOG-operation-lifecycle.md +15 -1
  5. package/CONSUMER_GUIDE.md +845 -6
  6. package/MIGRATION-0.10-to-0.12.md +4 -1
  7. package/MIGRATION-0.12-to-0.13.md +275 -0
  8. package/README.md +17 -16
  9. package/package.json +4 -2
  10. package/src/acp-client-handlers.ts +48 -0
  11. package/src/activity.ts +3 -0
  12. package/src/adapters.ts +25 -0
  13. package/src/agent/adoption/provider-attachment.ts +33 -0
  14. package/src/agent/adoption/provider-session-delete.ts +1 -1
  15. package/src/agent/adoption/provider-sessions.ts +3 -2
  16. package/src/agent/append-assistant-message.ts +91 -0
  17. package/src/agent/config.ts +54 -6
  18. package/src/agent/conversation-manager.ts +94 -158
  19. package/src/agent/manager-settings.ts +1 -0
  20. package/src/agent/native-channel-lifecycle.ts +111 -0
  21. package/src/agent/persisted-lifecycle.ts +44 -4
  22. package/src/agent/persistence-policy/context.ts +13 -0
  23. package/src/agent/persistence-policy/resolver.ts +7 -0
  24. package/src/agent/persistence-policy/types.ts +1 -0
  25. package/src/agent/record-capture.ts +1 -0
  26. package/src/agent-adapter-registry.ts +33 -7
  27. package/src/agent-conversation-contracts.ts +14 -1
  28. package/src/agent-conversation-errors.ts +8 -0
  29. package/src/agent-conversation-owner.ts +9 -4
  30. package/src/agent-session-config.ts +135 -0
  31. package/src/agent-session.ts +439 -934
  32. package/src/agent.ts +73 -0
  33. package/src/capabilities.ts +2 -0
  34. package/src/checkpointing/recovery.ts +3 -0
  35. package/src/cli/index.ts +3 -3
  36. package/src/cli/managed.ts +2 -2
  37. package/src/client.ts +52 -94
  38. package/src/connection-attempt.ts +95 -0
  39. package/src/controller-connection.ts +114 -0
  40. package/src/controller.ts +156 -148
  41. package/src/conversation-controller/capabilities.ts +88 -0
  42. package/src/conversation-controller/contracts.ts +208 -0
  43. package/src/conversation-controller/factory.ts +39 -0
  44. package/src/conversation-controller/guards.ts +98 -0
  45. package/src/conversation-controller/index.ts +20 -0
  46. package/src/conversation-startup.ts +35 -0
  47. package/src/conversation-turns/backend-turns.ts +373 -0
  48. package/src/conversation-turns/clear-operations.ts +37 -0
  49. package/src/conversation-turns/context.ts +135 -0
  50. package/src/conversation-turns/index.ts +4 -0
  51. package/src/conversation-turns/record-helpers.ts +75 -0
  52. package/src/conversation-turns/recording.ts +235 -0
  53. package/src/conversation-turns/run-turn.ts +367 -0
  54. package/src/conversation-turns/turn-run.ts +57 -0
  55. package/src/errors.ts +41 -0
  56. package/src/handoff-options.ts +81 -0
  57. package/src/identity/checkpoint-backed.ts +1 -1
  58. package/src/index.ts +58 -3
  59. package/src/internal-inference/coordination/manager.ts +11 -0
  60. package/src/internal-inference/runtime/harness-runtime.ts +4 -4
  61. package/src/launcher.ts +35 -2
  62. package/src/media/parts.ts +5 -0
  63. package/src/message-status.ts +83 -0
  64. package/src/metering/engine.ts +39 -64
  65. package/src/metering/measurement-provenance.ts +36 -0
  66. package/src/metering/native/durability.ts +115 -0
  67. package/src/metering/native/ledger.ts +104 -0
  68. package/src/metering/native/operation.ts +85 -0
  69. package/src/metering/native/projection.ts +114 -0
  70. package/src/metering/native/proof.ts +51 -0
  71. package/src/metering/native/requirements.ts +10 -0
  72. package/src/metering/native/retirement.ts +92 -0
  73. package/src/metering/native/source.ts +90 -0
  74. package/src/metering/record.ts +38 -1
  75. package/src/metering/state.ts +13 -3
  76. package/src/native/approvals.ts +169 -0
  77. package/src/native/capabilities.ts +17 -0
  78. package/src/native/channel-changes.ts +211 -0
  79. package/src/native/connection.ts +56 -0
  80. package/src/native/controller.ts +591 -0
  81. package/src/native/delegation-sender.ts +26 -0
  82. package/src/native/errors.ts +35 -0
  83. package/src/native/functions.ts +156 -0
  84. package/src/native/host-config.ts +59 -0
  85. package/src/native/host.ts +909 -0
  86. package/src/native/item-receipts.ts +15 -0
  87. package/src/native/metering.ts +12 -0
  88. package/src/native/records.ts +166 -0
  89. package/src/native/recovery.ts +186 -0
  90. package/src/native/reminders/fixtures/schema21.sqlite.gz +0 -0
  91. package/src/native/reminders/idle.ts +70 -0
  92. package/src/native/reminders/limits.ts +19 -0
  93. package/src/native/reminders/notifications.ts +29 -0
  94. package/src/native/reminders/reminders.test.ts +553 -0
  95. package/src/native/reminders/routine-config.typecheck.ts +13 -0
  96. package/src/native/reminders/routine-guard.ts +66 -0
  97. package/src/native/reminders/routine-schedule.ts +25 -0
  98. package/src/native/reminders/routine-wire.ts +21 -0
  99. package/src/native/reminders/schedule.ts +97 -0
  100. package/src/native/reminders/service.ts +280 -0
  101. package/src/native/reminders/supervisor.ts +91 -0
  102. package/src/native/reminders/sync.ts +301 -0
  103. package/src/native/reminders/wire.ts +197 -0
  104. package/src/native/reminders/wire.typecheck.ts +13 -0
  105. package/src/native/submission-withdrawal.ts +65 -0
  106. package/src/native/usage.ts +15 -0
  107. package/src/native/worker-delivery.ts +61 -0
  108. package/src/native-harness/.res/README.md +1 -0
  109. package/src/native-harness/.res/architecture/README.md +21 -0
  110. package/src/native-harness/.res/architecture/context-and-data.md +31 -0
  111. package/src/native-harness/.res/architecture/execution.md +42 -0
  112. package/src/native-harness/.res/architecture/overview.md +44 -0
  113. package/src/native-harness/.res/architecture/persistence.md +56 -0
  114. package/src/native-harness/.res/architecture/suspend-and-resume.md +45 -0
  115. package/src/native-harness/.res/architecture/technical-architecture.md +50 -0
  116. package/src/native-harness/.res/decisions/0001-basic-loop.md +11 -0
  117. package/src/native-harness/.res/decisions/0002-channel-input.md +17 -0
  118. package/src/native-harness/.res/decisions/0003-inference-inspection.md +14 -0
  119. package/src/native-harness/.res/decisions/0004-shared-context.md +21 -0
  120. package/src/native-harness/.res/decisions/0005-notice-inbox.md +20 -0
  121. package/src/native-harness/.res/decisions/0006-explicit-notices.md +12 -0
  122. package/src/native-harness/.res/decisions/0007-channel-output.md +12 -0
  123. package/src/native-harness/.res/decisions/0008-browser-client.md +16 -0
  124. package/src/native-harness/.res/decisions/0009-scripted-model.md +18 -0
  125. package/src/native-harness/.res/decisions/0010-inprocess-protocol.md +19 -0
  126. package/src/native-harness/.res/decisions/0011-stdio-transport.md +21 -0
  127. package/src/native-harness/.res/decisions/0012-session-storage-contract.md +37 -0
  128. package/src/native-harness/.res/decisions/0013-durable-delivery-contract.md +64 -0
  129. package/src/native-harness/.res/decisions/0014-channel-controls-contract.md +73 -0
  130. package/src/native-harness/.res/decisions/0015-session-file-contract.md +72 -0
  131. package/src/native-harness/.res/decisions/0016-configuration-permissions.md +159 -0
  132. package/src/native-harness/.res/decisions/0017-openrouter-managed-config.md +69 -0
  133. package/src/native-harness/.res/decisions/0018-tool-dispatch-evidence.md +78 -0
  134. package/src/native-harness/.res/decisions/0019-model-execution.md +188 -0
  135. package/src/native-harness/.res/decisions/0020-startup-channel-changes.md +71 -0
  136. package/src/native-harness/.res/decisions/0021-tools-and-host-callbacks.md +100 -0
  137. package/src/native-harness/.res/decisions/0022-operator-controls.md +115 -0
  138. package/src/native-harness/.res/decisions/0023-long-running-mock.md +82 -0
  139. package/src/native-harness/.res/decisions/0024-callback-policy-names.md +46 -0
  140. package/src/native-harness/.res/decisions/0025-external-notices.md +364 -0
  141. package/src/native-harness/.res/decisions/0026-bounded-context.md +81 -0
  142. package/src/native-harness/.res/decisions/0027-development-instructions.md +22 -0
  143. package/src/native-harness/.res/decisions/0028-debug-tools.md +16 -0
  144. package/src/native-harness/.res/decisions/0029-bounded-model-call-pages.md +37 -0
  145. package/src/native-harness/.res/decisions/0030-timeline-retrieval.md +145 -0
  146. package/src/native-harness/.res/decisions/0031-one-off-reminders.md +173 -0
  147. package/src/native-harness/.res/docs/11-15.md +148 -0
  148. package/src/native-harness/.res/docs/BUSINESS_RULES.md +111 -0
  149. package/src/native-harness/.res/docs/WORK.md +65 -0
  150. package/src/native-harness/.res/docs/_/11-16-persistence/LOG.md +312 -0
  151. package/src/native-harness/.res/docs/_/11-16-persistence/PLAN.md +77 -0
  152. package/src/native-harness/.res/docs/_/11-16-persistence/SPEC.md +313 -0
  153. package/src/native-harness/.res/docs/_/11-19-channel-controls/LOG.md +160 -0
  154. package/src/native-harness/.res/docs/_/11-19-channel-controls/PLAN.md +89 -0
  155. package/src/native-harness/.res/docs/_/11-19-channel-controls/SPEC.md +135 -0
  156. package/src/native-harness/.res/docs/_/11-19-config-permissions/LOG.md +143 -0
  157. package/src/native-harness/.res/docs/_/11-19-config-permissions/PLAN.md +93 -0
  158. package/src/native-harness/.res/docs/_/11-19-config-permissions/SPEC.md +181 -0
  159. package/src/native-harness/.res/docs/acp-client-integration/0001-DESIGN/11-20-LOG.md +433 -0
  160. package/src/native-harness/.res/docs/acp-client-integration/0001-DESIGN/PLAN.md +60 -0
  161. package/src/native-harness/.res/docs/acp-client-integration/0001-DESIGN/PROTOCOL.md +141 -0
  162. package/src/native-harness/.res/docs/acp-client-integration/0001-DESIGN/SPEC.md +168 -0
  163. package/src/native-harness/.res/docs/attachments/0001-DESIGN/SPEC.md +111 -0
  164. package/src/native-harness/.res/docs/bounded-context/0001-DESIGN/PLAN.md +129 -0
  165. package/src/native-harness/.res/docs/bounded-context/0001-DESIGN/SPEC.md +135 -0
  166. package/src/native-harness/.res/docs/channel-messaging/0001-DESIGN-external-notices/LOG.md +437 -0
  167. package/src/native-harness/.res/docs/channel-messaging/0001-DESIGN-external-notices/PLAN.md +127 -0
  168. package/src/native-harness/.res/docs/channel-messaging/0001-DESIGN-external-notices/SPEC.md +203 -0
  169. package/src/native-harness/.res/docs/long-running-mock/0001-DESIGN/LOG.md +292 -0
  170. package/src/native-harness/.res/docs/long-running-mock/0001-DESIGN/PLAN.md +91 -0
  171. package/src/native-harness/.res/docs/long-running-mock/0001-DESIGN/SPEC.md +187 -0
  172. package/src/native-harness/.res/docs/model-execution/0001-DESIGN/LOG.md +148 -0
  173. package/src/native-harness/.res/docs/model-execution/0001-DESIGN/PLAN.md +95 -0
  174. package/src/native-harness/.res/docs/model-execution/0001-DESIGN/SPEC.md +200 -0
  175. package/src/native-harness/.res/docs/model-execution/0002-AMENDMENT-accounting/SPEC.md +80 -0
  176. package/src/native-harness/.res/docs/operator-controls/0001-DESIGN/LOG.md +206 -0
  177. package/src/native-harness/.res/docs/operator-controls/0001-DESIGN/PLAN.md +106 -0
  178. package/src/native-harness/.res/docs/operator-controls/0001-DESIGN/SPEC.md +297 -0
  179. package/src/native-harness/.res/docs/persistence/0002-AMENDMENT-session-file/LOG.md +41 -0
  180. package/src/native-harness/.res/docs/persistence/0002-AMENDMENT-session-file/PLAN.md +36 -0
  181. package/src/native-harness/.res/docs/persistence/0002-AMENDMENT-session-file/SPEC.md +84 -0
  182. package/src/native-harness/.res/docs/shell-execution/0001-DESIGN/SPEC.md +147 -0
  183. package/src/native-harness/.res/docs/timeline-retrieval/0001-DESIGN/LOG.md +15 -0
  184. package/src/native-harness/.res/docs/timeline-retrieval/0001-DESIGN/PLAN.md +107 -0
  185. package/src/native-harness/.res/docs/timeline-retrieval/0001-DESIGN/SPEC.md +114 -0
  186. package/src/native-harness/.res/docs/todos/11-19-TODO-auto_review-approve.md +24 -0
  187. package/src/native-harness/.res/docs/todos/11-20-TODO-user-entered-tool-code.md +23 -0
  188. package/src/native-harness/.res/docs/todos/11-21-TODO-node-resource-coordination.md +103 -0
  189. package/src/native-harness/.res/docs/todos/11-22-TODO-harness-m1-sequence.md +50 -0
  190. package/src/native-harness/.res/docs/tools-and-callbacks/0001-DESIGN/LOG.md +337 -0
  191. package/src/native-harness/.res/docs/tools-and-callbacks/0001-DESIGN/PLAN.md +76 -0
  192. package/src/native-harness/.res/docs/tools-and-callbacks/0001-DESIGN/SPEC.md +204 -0
  193. package/src/native-harness/.res/docs/tools-and-callbacks/0002-AMENDMENT-callback-policy/LOG.md +73 -0
  194. package/src/native-harness/.res/docs/tools-and-callbacks/0002-AMENDMENT-callback-policy/SPEC.md +64 -0
  195. package/src/native-harness/.res/docs/tools-and-callbacks/0003-DESIGN-attachment-tools/SPEC.md +58 -0
  196. package/src/native-harness/.res/docs/tools-and-callbacks/0004-DESIGN-reminder-tools/LOG.md +45 -0
  197. package/src/native-harness/.res/docs/tools-and-callbacks/0004-DESIGN-reminder-tools/PLAN.md +108 -0
  198. package/src/native-harness/.res/docs/tools-and-callbacks/0004-DESIGN-reminder-tools/SPEC.md +169 -0
  199. package/src/native-harness/.res/docs/web-tools/0001-DESIGN/SPEC.md +128 -0
  200. package/src/native-harness/.res/marketing-draft.md +22 -0
  201. package/src/native-harness/.res/sandbox/1-simple-harness/README.md +285 -0
  202. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-1.md +19 -0
  203. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-10.md +138 -0
  204. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-11.md +148 -0
  205. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-12.md +172 -0
  206. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-13.md +194 -0
  207. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-14.md +233 -0
  208. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-15.md +249 -0
  209. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-16.md +265 -0
  210. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-17.md +279 -0
  211. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-18.md +293 -0
  212. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-19.md +307 -0
  213. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-2.md +29 -0
  214. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-20.md +317 -0
  215. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-21.md +327 -0
  216. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-3.md +40 -0
  217. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-4.md +59 -0
  218. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-5.md +69 -0
  219. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-6.md +79 -0
  220. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-7.md +89 -0
  221. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-8.md +102 -0
  222. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-9.md +116 -0
  223. package/src/native-harness/.res/sandbox/1-simple-harness/conversation.jsonl +49 -0
  224. package/src/native-harness/.res/sandbox/1-simple-harness/doc.md +87 -0
  225. package/src/native-harness/.res/sandbox/1-simple-harness/harness.py +289 -0
  226. package/src/native-harness/.res/sandbox/1-simple-harness/local/harness copy 2.py +221 -0
  227. package/src/native-harness/.res/sandbox/1-simple-harness/local/harness copy 3.py +287 -0
  228. package/src/native-harness/.res/sandbox/1-simple-harness/local/harness copy.py +165 -0
  229. package/src/native-harness/.res/sandbox/1-simple-harness/state.json +22 -0
  230. package/src/native-harness/.res/sandbox/1-simple-harness/system-prompt.md +2 -0
  231. package/src/native-harness/AGENTS.md +70 -0
  232. package/src/native-harness/ARCHITECTURE.md +249 -0
  233. package/src/native-harness/README.md +726 -0
  234. package/src/native-harness/bun.lock +26 -0
  235. package/src/native-harness/package.json +24 -0
  236. package/src/native-harness/src/capabilities/context/build.ts +59 -0
  237. package/src/native-harness/src/capabilities/context/instructions/agent-demo.md +11 -0
  238. package/src/native-harness/src/capabilities/context/instructions/agent.md +5 -0
  239. package/src/native-harness/src/capabilities/context/instructions/harness.md +7 -0
  240. package/src/native-harness/src/capabilities/context/load-instructions.ts +22 -0
  241. package/src/native-harness/src/capabilities/context/session.ts +92 -0
  242. package/src/native-harness/src/capabilities/model/attempt.ts +27 -0
  243. package/src/native-harness/src/capabilities/model/openrouter-stream.ts +72 -0
  244. package/src/native-harness/src/capabilities/model/openrouter.ts +62 -0
  245. package/src/native-harness/src/capabilities/model/runner.ts +116 -0
  246. package/src/native-harness/src/capabilities/model/scenario-attempt.ts +50 -0
  247. package/src/native-harness/src/capabilities/model/scenario-file.ts +125 -0
  248. package/src/native-harness/src/capabilities/model/scripted-error.ts +6 -0
  249. package/src/native-harness/src/capabilities/model/scripted.ts +81 -0
  250. package/src/native-harness/src/capabilities/model/usage.ts +15 -0
  251. package/src/native-harness/src/capabilities/tools/builtin/current-time.ts +28 -0
  252. package/src/native-harness/src/capabilities/tools/builtin/notify-channel.ts +17 -0
  253. package/src/native-harness/src/capabilities/tools/debug/index.ts +13 -0
  254. package/src/native-harness/src/capabilities/tools/debug/result.ts +12 -0
  255. package/src/native-harness/src/capabilities/tools/debug/test-echo.ts +16 -0
  256. package/src/native-harness/src/capabilities/tools/debug/test-fail.ts +14 -0
  257. package/src/native-harness/src/capabilities/tools/debug/test-wait.ts +19 -0
  258. package/src/native-harness/src/capabilities/tools/reminders/index.ts +75 -0
  259. package/src/native-harness/src/capabilities/tools/runtime/catalog.ts +103 -0
  260. package/src/native-harness/src/capabilities/tools/runtime/functions.ts +130 -0
  261. package/src/native-harness/src/capabilities/tools/runtime/invocations.ts +48 -0
  262. package/src/native-harness/src/capabilities/tools/testing/echo.ts +18 -0
  263. package/src/native-harness/src/capabilities/tools/testing/record.ts +47 -0
  264. package/src/native-harness/src/capabilities/tools/timeline/index.ts +41 -0
  265. package/src/native-harness/src/client.ts +18 -0
  266. package/src/native-harness/src/contracts/agent.ts +105 -0
  267. package/src/native-harness/src/contracts/config-permissions.ts +47 -0
  268. package/src/native-harness/src/contracts/context.ts +112 -0
  269. package/src/native-harness/src/contracts/events.ts +47 -0
  270. package/src/native-harness/src/contracts/input-limits.ts +7 -0
  271. package/src/native-harness/src/contracts/inspection.ts +22 -0
  272. package/src/native-harness/src/contracts/loop.ts +31 -0
  273. package/src/native-harness/src/contracts/model-execution.ts +83 -0
  274. package/src/native-harness/src/contracts/operator-controls.ts +106 -0
  275. package/src/native-harness/src/contracts/output.ts +13 -0
  276. package/src/native-harness/src/contracts/protocol.ts +320 -0
  277. package/src/native-harness/src/contracts/reminders.ts +132 -0
  278. package/src/native-harness/src/contracts/scenario.ts +42 -0
  279. package/src/native-harness/src/contracts/session-file.ts +19 -0
  280. package/src/native-harness/src/contracts/session.ts +184 -0
  281. package/src/native-harness/src/contracts/storage.ts +596 -0
  282. package/src/native-harness/src/contracts/timeline-retrieval.ts +40 -0
  283. package/src/native-harness/src/contracts/tools.ts +133 -0
  284. package/src/native-harness/src/governance/permissions/gate.ts +129 -0
  285. package/src/native-harness/src/governance/policy/resolve.ts +32 -0
  286. package/src/native-harness/src/index.ts +318 -0
  287. package/src/native-harness/src/interfaces/cli/chat.ts +83 -0
  288. package/src/native-harness/src/interfaces/cli/development.ts +145 -0
  289. package/src/native-harness/src/interfaces/cli/format-reply.ts +27 -0
  290. package/src/native-harness/src/interfaces/cli/listeners.ts +74 -0
  291. package/src/native-harness/src/interfaces/cli/main.ts +47 -0
  292. package/src/native-harness/src/interfaces/cli/scenario.ts +37 -0
  293. package/src/native-harness/src/interfaces/cli/serve.ts +21 -0
  294. package/src/native-harness/src/interfaces/cli/start.ts +106 -0
  295. package/src/native-harness/src/interfaces/client.ts +225 -0
  296. package/src/native-harness/src/interfaces/inspector/index.html +283 -0
  297. package/src/native-harness/src/interfaces/inspector/observe.ts +35 -0
  298. package/src/native-harness/src/interfaces/inspector/server.ts +56 -0
  299. package/src/native-harness/src/interfaces/inspector/state.ts +92 -0
  300. package/src/native-harness/src/interfaces/protocol/channel-changes.ts +153 -0
  301. package/src/native-harness/src/interfaces/protocol/framing.ts +47 -0
  302. package/src/native-harness/src/interfaces/protocol/functions.ts +87 -0
  303. package/src/native-harness/src/interfaces/protocol/in-process.ts +67 -0
  304. package/src/native-harness/src/interfaces/protocol/live-queue.ts +55 -0
  305. package/src/native-harness/src/interfaces/protocol/load.ts +60 -0
  306. package/src/native-harness/src/interfaces/protocol/local.ts +120 -0
  307. package/src/native-harness/src/interfaces/protocol/operator.ts +120 -0
  308. package/src/native-harness/src/interfaces/protocol/output.ts +59 -0
  309. package/src/native-harness/src/interfaces/protocol/server.ts +517 -0
  310. package/src/native-harness/src/interfaces/protocol/stdio-client.ts +119 -0
  311. package/src/native-harness/src/interfaces/protocol/stdio-server.ts +82 -0
  312. package/src/native-harness/src/interfaces/protocol/subscribe.ts +41 -0
  313. package/src/native-harness/src/interfaces/protocol/transfers.ts +146 -0
  314. package/src/native-harness/src/interfaces/web-chat/index.html +94 -0
  315. package/src/native-harness/src/interfaces/web-chat/server.ts +34 -0
  316. package/src/native-harness/src/kernel/channels.ts +405 -0
  317. package/src/native-harness/src/kernel/loop.ts +45 -0
  318. package/src/native-harness/src/runtime/config/development.ts +23 -0
  319. package/src/native-harness/src/runtime/config/managed.ts +2 -0
  320. package/src/native-harness/src/runtime/config/paths.ts +27 -0
  321. package/src/native-harness/src/runtime/reminder-timer.ts +42 -0
  322. package/src/native-harness/src/runtime/reminder-validation.ts +104 -0
  323. package/src/native-harness/src/runtime/reminders.ts +66 -0
  324. package/src/native-harness/src/state/storage/archive.ts +239 -0
  325. package/src/native-harness/src/state/storage/engine.ts +1013 -0
  326. package/src/native-harness/src/state/storage/inference.ts +124 -0
  327. package/src/native-harness/src/state/storage/memory-reminders.ts +78 -0
  328. package/src/native-harness/src/state/storage/memory.ts +341 -0
  329. package/src/native-harness/src/state/storage/policy-metadata.ts +32 -0
  330. package/src/native-harness/src/state/storage/reminder-archive.ts +63 -0
  331. package/src/native-harness/src/state/storage/reminder-change.ts +92 -0
  332. package/src/native-harness/src/state/storage/reminder-tables.ts +27 -0
  333. package/src/native-harness/src/state/storage/retrieval.ts +122 -0
  334. package/src/native-harness/src/state/storage/script-identity.ts +7 -0
  335. package/src/native-harness/src/state/storage/session-file.ts +85 -0
  336. package/src/native-harness/src/state/storage/sqlite-reminders.ts +134 -0
  337. package/src/native-harness/src/state/storage/sqlite.ts +625 -0
  338. package/src/native-harness/src/testing.ts +190 -0
  339. package/src/native-harness/src/util/config.ts +58 -0
  340. package/src/native-harness/src/util/json.ts +41 -0
  341. package/src/native-harness/src/util/message-position.ts +3 -0
  342. package/src/native-harness/src/util/reminder-schedule.ts +44 -0
  343. package/src/native-harness/src/util/schema.ts +40 -0
  344. package/src/native-harness/src/util/timeline-text.ts +72 -0
  345. package/src/native-harness/src/util/timeline-tool-names.ts +3 -0
  346. package/src/native-harness/test/agent.test.ts +130 -0
  347. package/src/native-harness/test/approval-gate.test.ts +255 -0
  348. package/src/native-harness/test/approval-protocol.test.ts +94 -0
  349. package/src/native-harness/test/boundaries.test.ts +18 -0
  350. package/src/native-harness/test/channel-controls.test.ts +322 -0
  351. package/src/native-harness/test/client-abort.test.ts +136 -0
  352. package/src/native-harness/test/config-policy.test.ts +301 -0
  353. package/src/native-harness/test/conformance/storage.ts +1141 -0
  354. package/src/native-harness/test/context.test.ts +177 -0
  355. package/src/native-harness/test/crash.test.ts +187 -0
  356. package/src/native-harness/test/debug-tools.test.ts +67 -0
  357. package/src/native-harness/test/development-cli.test.ts +67 -0
  358. package/src/native-harness/test/development.test.ts +171 -0
  359. package/src/native-harness/test/dispatch-evidence.test.ts +58 -0
  360. package/src/native-harness/test/e2e.test.ts +186 -0
  361. package/src/native-harness/test/external-notices.test.ts +101 -0
  362. package/src/native-harness/test/fixtures/approval-e2e.jsonl +4 -0
  363. package/src/native-harness/test/fixtures/crash-scenario.jsonl +5 -0
  364. package/src/native-harness/test/fixtures/development-lifecycle.jsonl +10 -0
  365. package/src/native-harness/test/fixtures/echo-scenario.jsonl +3 -0
  366. package/src/native-harness/test/fixtures/format2-schema.ts +27 -0
  367. package/src/native-harness/test/fixtures/format3-schema.ts +16 -0
  368. package/src/native-harness/test/fixtures/hold-scenario.jsonl +4 -0
  369. package/src/native-harness/test/fixtures/model-e2e.jsonl +3 -0
  370. package/src/native-harness/test/fixtures/storage-owner.ts +20 -0
  371. package/src/native-harness/test/format-reply.test.ts +10 -0
  372. package/src/native-harness/test/helpers/operator-view.ts +41 -0
  373. package/src/native-harness/test/helpers/scenario.ts +9 -0
  374. package/src/native-harness/test/helpers/session.ts +38 -0
  375. package/src/native-harness/test/helpers/stdio.ts +46 -0
  376. package/src/native-harness/test/inspector.test.ts +77 -0
  377. package/src/native-harness/test/listeners.test.ts +49 -0
  378. package/src/native-harness/test/loop.test.ts +88 -0
  379. package/src/native-harness/test/model-channel-double.test.ts +87 -0
  380. package/src/native-harness/test/model-crash.test.ts +62 -0
  381. package/src/native-harness/test/model-delivery-regressions.test.ts +55 -0
  382. package/src/native-harness/test/model-e2e.test.ts +71 -0
  383. package/src/native-harness/test/model-final-filter.test.ts +30 -0
  384. package/src/native-harness/test/model-large-reply.test.ts +28 -0
  385. package/src/native-harness/test/model-live-queue.test.ts +33 -0
  386. package/src/native-harness/test/model-runner.test.ts +117 -0
  387. package/src/native-harness/test/model-storage.test.ts +99 -0
  388. package/src/native-harness/test/model-stream-adapter.test.ts +26 -0
  389. package/src/native-harness/test/model-stream-public.test.ts +77 -0
  390. package/src/native-harness/test/notices.test.ts +64 -0
  391. package/src/native-harness/test/openrouter-config.test.ts +218 -0
  392. package/src/native-harness/test/operator-controls.test.ts +132 -0
  393. package/src/native-harness/test/output.test.ts +44 -0
  394. package/src/native-harness/test/owner-config.test.ts +64 -0
  395. package/src/native-harness/test/permissions-e2e.test.ts +68 -0
  396. package/src/native-harness/test/persistence.test.ts +236 -0
  397. package/src/native-harness/test/portability.test.ts +337 -0
  398. package/src/native-harness/test/protocol.test.ts +160 -0
  399. package/src/native-harness/test/reminder-clock.test.ts +61 -0
  400. package/src/native-harness/test/reminder-stdio.test.ts +140 -0
  401. package/src/native-harness/test/reminder-storage.test.ts +124 -0
  402. package/src/native-harness/test/scenario-jsonl.test.ts +112 -0
  403. package/src/native-harness/test/scripted.test.ts +92 -0
  404. package/src/native-harness/test/session-file.test.ts +51 -0
  405. package/src/native-harness/test/startup-channel-changes.test.ts +256 -0
  406. package/src/native-harness/test/stdio.test.ts +132 -0
  407. package/src/native-harness/test/storage-memory.test.ts +4 -0
  408. package/src/native-harness/test/storage-sqlite.test.ts +420 -0
  409. package/src/native-harness/test/suspension.test.ts +430 -0
  410. package/src/native-harness/test/timeline-retrieval.test.ts +211 -0
  411. package/src/native-harness/test/tools-catalog.test.ts +468 -0
  412. package/src/native-harness/test/tools-protocol.test.ts +418 -0
  413. package/src/native-harness/test/transfers.test.ts +94 -0
  414. package/src/native-harness/test/web-chat.test.ts +35 -0
  415. package/src/native-harness/tsconfig.json +20 -0
  416. package/src/observation/agent-event-bus.ts +44 -18
  417. package/src/observation/index.ts +1 -0
  418. package/src/operations/contracts.ts +11 -3
  419. package/src/operations/errors.ts +5 -0
  420. package/src/operations/stale-policy.ts +1 -1
  421. package/src/operations/supervisor.ts +34 -10
  422. package/src/orchestrator/acp-delivery.ts +68 -0
  423. package/src/orchestrator/assignments.ts +27 -0
  424. package/src/orchestrator/busy.ts +15 -0
  425. package/src/orchestrator/config.ts +41 -0
  426. package/src/orchestrator/consumer-api.ts +24 -0
  427. package/src/orchestrator/contracts.ts +71 -0
  428. package/src/orchestrator/durable-assignments.ts +111 -0
  429. package/src/orchestrator/native-delegation.ts +103 -0
  430. package/src/orchestrator/orchestrator.ts +318 -0
  431. package/src/orchestrator/permissions.ts +25 -0
  432. package/src/orchestrator/policy.ts +44 -0
  433. package/src/orchestrator/pool.ts +123 -0
  434. package/src/orchestrator/tool-descriptions.ts +11 -0
  435. package/src/permissions/acp.ts +18 -0
  436. package/src/permissions/arrival.ts +13 -0
  437. package/src/permissions/consumer-config.ts +19 -0
  438. package/src/permissions/conversation.ts +280 -0
  439. package/src/permissions/matcher.ts +85 -0
  440. package/src/permissions/outcome.ts +15 -0
  441. package/src/permissions/policy.ts +81 -0
  442. package/src/permissions/request.ts +26 -0
  443. package/src/persistence/activity-projection.ts +1 -0
  444. package/src/persistence/backend.ts +34 -1
  445. package/src/persistence/channels.ts +23 -0
  446. package/src/persistence/index.ts +4 -0
  447. package/src/persistence/protocol-method.ts +5 -0
  448. package/src/persistence/reminder-wake.ts +49 -0
  449. package/src/persistence/reminders.ts +385 -0
  450. package/src/persistence/sqlite-backend.ts +84 -6
  451. package/src/persistence/sqlite-channels.ts +65 -0
  452. package/src/persistence/sqlite-reminders.ts +85 -0
  453. package/src/persistence/sqlite-schema.ts +108 -3
  454. package/src/persistence/sqlite-worker-delivery.ts +374 -0
  455. package/src/persistence/sqlite-workers.ts +59 -0
  456. package/src/persistence/worker-delivery-contract.ts +104 -0
  457. package/src/persistence/worker-terminal-reason.ts +29 -0
  458. package/src/persistence/workers.ts +19 -0
  459. package/src/provider-notices.ts +137 -0
  460. package/src/repl/commands.ts +2 -2
  461. package/src/steering/combine.ts +3 -1
  462. package/src/steering/contracts.ts +11 -2
  463. package/src/steering/controller.ts +3 -2
  464. package/src/transport/acp-transport.ts +24 -14
  465. package/src/types.ts +15 -12
  466. package/src/updates.ts +14 -2
  467. package/src/wire-log.ts +1 -1
@@ -0,0 +1,364 @@
1
+ # 0025 External notices and delivery handoff
2
+
3
+ ## Problem and options
4
+
5
+ External producers need attributed inbox delivery and durable retries. Using
6
+ participant input would blur attribution and policy provenance. Reuse the inbox
7
+ with a distinct kind and a host-only method.
8
+
9
+ ## Harness contract
10
+
11
+ The initialized endpoint that successfully created or opened the session owns
12
+ it. Only that endpoint admits channel/notify, including on an inspection open.
13
+ Approval and callback capabilities and the supplied source label grant no
14
+ authority. An endpoint without an open session returns invalid_state.
15
+
16
+ The envelope has exactly channel and notice. The notice has required id, text
17
+ and policyNames, plus optional source. Reject unknown fields and missing or
18
+ wrong types as invalid_params. Strings are nonblank and retain exact spelling.
19
+ Normalize the names to a sorted unique set (duplicates and reordering are
20
+ equivalent). An omitted source means host attribution and is distinct from
21
+ an explicit label. External notices have no source channel or turn.
22
+
23
+ The external signature is lowercase SHA-256 of the UTF-8 JSON serialization
24
+ of ["external_notice", channel, source-or-null, text, sortedDistinctPolicyNames].
25
+ Existing signature formulas remain unchanged. After shape and owner checks,
26
+ read the existing inbox ID before any admission or active policy check.
27
+ An identical external notice returns its recorded receipt and causes no write,
28
+ take, or wake. A different payload or kind returns item_conflict. Inspection
29
+ and suspended sessions support the same lookup. Keep check and commit fenced
30
+ by the inbox transaction so competing accepts cannot create duplicates.
31
+
32
+ Apply checks in this order: request shape, owning endpoint, read-only
33
+ duplicate or conflict lookup, session admission, channel admission,
34
+ policy validation, then commit. Duplicate lookup precedes the inspection
35
+ write fence. Identical accepted notices return their receipt in every
36
+ lifecycle that still permits inspection. A new ID in an incompatible
37
+ inspection open returns incompatible. A new external notice while the
38
+ session is suspending or suspended returns not_running. Internal notices
39
+ retain their existing exception during session suspension drain.
40
+ An absent channel returns not_found, a retired channel channel_retired,
41
+ and a suspended or suspending channel channel_suspended.
42
+
43
+ For an eligible destination, unknown or reserved internal inherited names,
44
+ including __legacy_allow, return invalid_policy. Resolve the channel or
45
+ default policy and store it with the inherited names. The scheduler takes
46
+ the notice in ordinary inbox order. Expose the external kind and accepted
47
+ ID in the timeline and render host attribution in context. Conversation
48
+ pages exclude external notices.
49
+
50
+ ## Compatibility
51
+
52
+ Write SQLite format 6 and archive 5, with envelope 1 unchanged. Older readers
53
+ must refuse new versions since they cannot safely take this kind. Add
54
+ nullable external_source columns to items and timeline entries. Persist
55
+ the normalized submitted policy set using the item's existing inherited
56
+ policy metadata. Both tables' kind domain includes external_notice.
57
+ Upgrade formats 2–5 in the existing migration and recovery transaction.
58
+ Add the columns and update kind constraints where present, preserving
59
+ format 5 signatures byte for byte. Older formats retain their existing
60
+ migration rules. Adapter import accepts archives 1–5 and session files
61
+ accept archives 2–5. Legacy archives cannot contain external notices.
62
+ New archives validate attribution, sorted inherited metadata and signature
63
+ before publication, and preserve pending and taken notices with their IDs.
64
+
65
+ ## Durable ACP worker handoff
66
+
67
+ The orchestrator owns assignment identity, destination and worker rules.
68
+ Use the Agent database for the assignment binding and delivery records.
69
+ Keep a unique indexed binding from assignment ID to the worker conversation
70
+ and submitted message ID. The submitted message ID is stable before ACP
71
+ dispatch. The worker operation ID is attached at finalization and may be
72
+ shared by several messages folded into one turn. Store the destination and originating policy-name set
73
+ with it. Commit the binding before sending the ACP prompt. An identical
74
+ reservation can recover that binding. A conflicting reservation writes
75
+ nothing. Redispatch is never a recovery action for an existing binding.
76
+
77
+ Recover by assignment ID through the production index and read the
78
+ authoritative final worker conversation record by worker and operation.
79
+ In the same transaction that commits completed worker records, match
80
+ bindings by worker conversation and every message ID in the turn causes,
81
+ then attach the final operation and record pointers to each matching binding.
82
+ Message IDs are unique within a worker conversation. A second assignment
83
+ claiming the same worker/message pair conflicts. Operation IDs may be
84
+ shared. At terminal commit, compute the union of the originating and
85
+ contributing policy names of all bindings named by the causal message
86
+ IDs. Store the union as contributing policy on every affected binding,
87
+ preserving its original provenance. Each assignment gets its own outcome
88
+ and notice. A successful folded turn supplies the full shared result to
89
+ each binding, with its own destination and the shared policy restrictions.
90
+
91
+ A terminal failure or interruption observed by the current owner stages a
92
+ `failed` or `interrupted` outcome, respectively, with the terminal reason
93
+ and one stable notice per affected assignment. Explicit cancellation is
94
+ interrupted. The notice identifies the assignment and worker, reports the
95
+ known kind and reason, and warns that partial external effects may have
96
+ occurred. The outcome keeps the evidence flag for whether tools were
97
+ dispatched or dispatch history cannot rule them out.
98
+
99
+ Persist only bounded, non-secret reasons. Map typed terminal signals to
100
+ fixed public reason strings of at most 128 UTF-8 bytes. Use a generic
101
+ reason when no safe detail is available. Never copy arbitrary provider
102
+ error or stop text into the stored reason or notice. For example, a
103
+ recognized stall can report "worker stalled", while an unclassified
104
+ failure reports "worker failed". A cancellation without a recognized
105
+ reason reports "worker interrupted", including on native. A successful
106
+ completion is represented by the existing `result` kind. This outcome
107
+ and notice commit in the transaction that persists terminal lifecycle
108
+ records. Reserve uncertainty for abandoned work without reliable
109
+ terminal evidence. Use causal message
110
+ IDs to find the bindings and compute the same shared policy union. Failure
111
+ attaches no final record pointer. If that transaction never commits, the
112
+ replacement owner resolves each abandoned binding independently.
113
+ A streamed chunk or draft cannot serve as a result. A backend may expose
114
+ a recovery hook for an operation without a reliable final record. The
115
+ first ACP implementation has no such hook and uses the uncertainty path.
116
+
117
+ Use the exclusive Agent SQLite owner lock for the lifetime of the writer.
118
+ A second writer fails to open while that lock is held and cannot recover
119
+ or stage delivery. After acquiring ownership on open, classify unfinished
120
+ bindings read from the prior owner as abandoned before accepting new
121
+ dispatches. Only those bindings are eligible for uncertainty resolution.
122
+ There is no lease timeout, and current-owner operations are ineligible.
123
+
124
+ Final-record commits and uncertainty staging must serialize through the
125
+ same Agent database. The uncertainty transaction rechecks for a reliable
126
+ final record under its write transaction, through the binding’s causal
127
+ worker/message ID even when no operation ID is attached yet. An earlier final record selects
128
+ the exact result. If uncertainty commits first, a later final record may
129
+ remain inspectable in the worker transcript but cannot change the staged
130
+ outcome or notice. Enforce uniqueness of the terminal outcome by assignment
131
+ ID and verify both transaction orders.
132
+
133
+ In one Agent database transaction record the resolved result or uncertainty
134
+ and the exact pending notice. Enforce at most one terminal outcome and notice
135
+ intent per assignment. Repeated resolution returns the committed outcome.
136
+ Rollback leaves neither record. Allocate one stable delivery ID at staging
137
+ and retain it with the payload across reconnect and explicit retry.
138
+ A redirect committed before staging supplies the destination. A redirect
139
+ committed afterward leaves the staged payload intact. Keep the original
140
+ policy names in the binding. As work is taken across a redirect, update the
141
+ binding with the union of the policy names contributing on both sides.
142
+ A redirect alone adds no contributor. Staging freezes the union, including
143
+ the original names, and identifies the worker as source. The durable result remains
144
+ inspectable after any delivery outcome.
145
+
146
+ Result, failure, interruption and uncertainty notices start in `pending`. Flush them through
147
+ the owning host after earlier channel changes. Suspension, an unresolved
148
+ change, or a lost acknowledgement leaves the notice pending. Open, resume
149
+ and change confirmation schedule eligible pending retries with the original
150
+ ID and exact payload. A receipt or duplicate receipt moves pending to
151
+ `delivered`. Invalid policy moves it to `blocked_policy`, which returns to
152
+ pending only on explicit retry. A missing or retired destination moves it
153
+ to `failed_destination`. Delivered and failed_destination are terminal.
154
+ A connection loss cannot reopen either terminal state.
155
+
156
+ The fixture-local transcript scan from the feasibility proof is unsuitable
157
+ for production lookup. A second option, provider replay, depends on
158
+ provider-specific guarantees and is not required when the final Agent record
159
+ is available. The harness wire and archive formats are unchanged. Agent
160
+ schema numbering and implementation ownership are coordinated with the
161
+ R1–R3 and orchestrator workstreams before runtime changes.
162
+
163
+ Repository conformance verifies unique assignment and worker/message
164
+ keys. The process-death tests observe the exact beforeDispatch message
165
+ binding on disk at ACP prompt receipt. Verify that folded messages with
166
+ different assignment IDs each resolve to the shared completed operation
167
+ through their own binding, with separate results and provenance. Verify
168
+ that both assignments receive separate uncertainty notices if the final
169
+ record never commits.
170
+
171
+ Exercise both sides of final-record commit in real SIGKILL/replacement tests
172
+ using the production index. Observe the binding on disk at ACP prompt
173
+ receipt, prove that the post-final crash left no staged result or notice,
174
+ and recover the exact result and original provenance twice. For the
175
+ pre-final crash, confirm one uncertainty notice, stable retry ID, and no
176
+ redispatch. Exercise rollback, both redirect commit orders, a crash after
177
+ redirect, recovery after staging, and acknowledgement loss. Deterministic
178
+ ACP peers cover the saved-record boundary offline. Live-provider
179
+ finalization and recovery semantics remain unverified.
180
+
181
+ Before runtime implementation, add typed Agent persistence records and
182
+ repository operations for reservation, indexed lookup, outcome and delivery.
183
+ Pin the transaction and ownership semantics in shared repository conformance,
184
+ including idempotence, conflicts, rollback, finalization order, immutable
185
+ notice payload and retry transitions. Run the ownership and process-death
186
+ cases on SQLite. Coordinate the type placement and schema with Core.
187
+
188
+ Conformance covers folded success and failure, including guest and owner
189
+ assignments with both policies on the owner notice, separate immutable
190
+ notice IDs, and exclusion of bindings outside the operation's causes.
191
+
192
+ Conformance verifies a live provider failure with its reason, a targeted
193
+ interruption with its reason, and pre-finalization crash uncertainty. Each
194
+ produces exactly one immutable outcome and notice on repeated staging.
195
+
196
+ Conformance verifies recognized safe reasons, fallback for absent or
197
+ untrusted details, and absence of provider-supplied secrets and oversized
198
+ reason text in both the outcome and notice. A known interrupted outcome
199
+ keeps the same delivery ID and reason on repeated staging.
200
+
201
+ ## Gate 3 amendment
202
+
203
+ An assignment may span a steer chain. The lifecycle records an observed
204
+ steered cancellation as awaiting continuation, without staging a notice.
205
+ This is distinct from explicit interruption. Under the writer lock,
206
+ `continueAssignment` checks the current predecessor, claims the successor
207
+ worker/message key, and durably moves the active binding before successor
208
+ dispatch. The same committed triple is idempotent. A different successor,
209
+ an already claimed message, or a terminal predecessor is a conflict.
210
+ Keep predecessor keys as superseded for uniqueness and retries. Late
211
+ terminal records for superseded messages remain inspectable and cannot
212
+ settle the assignment. Linkage is an authorization fence, not evidence
213
+ that the successor actually ran.
214
+
215
+ If the successor will not run, the current owner explicitly closes the
216
+ awaiting continuation with a known failure or interruption and stages its
217
+ notice atomically. If the owner dies before an authoritative terminal
218
+ record, the next owner can settle the abandoned assignment as uncertain.
219
+ Neither recovery nor an idempotent continuation sends the prompt again.
220
+ Test both commit orders against predecessor finalization, a crash after
221
+ steer cancellation and before linkage, and a crash after linkage before
222
+ the successor's terminal commit. An assignment emits one terminal notice.
223
+ Original provenance survives a move. Policies attributed to taken work
224
+ survive the chain; terminal folded work unions the active causal policies
225
+ and staging freezes the applicable union.
226
+
227
+ Use typed native and ACP destinations. Native flush reads only native
228
+ destinations and respects earlier unresolved channel changes. ACP
229
+ delivery shares staging and compare-and-set transitions. It marks
230
+ delivered only on durable acceptance at the destination keyed by the
231
+ stable delivery ID, with idempotent retries; an unconfirmed append leaves
232
+ the notice pending. Until that receipt and deduplication path exists,
233
+ ACP delivery remains pending. Persist the worker handle before dispatch
234
+ as immutable attribution; staging and every retry use the same source,
235
+ ID, destination, text and policy set.
236
+
237
+ Discovery is read-only and indexed. Pages are oldest first using an
238
+ exclusive cursor over immutable increasing reservation sequence, scoped to
239
+ the destination kind and discovery state. Default 50, maximum 100. The
240
+ unstaged filter includes finalized but unstaged work and abandoned
241
+ bindings that the current owner may settle. It excludes unfinished work
242
+ owned by the current process, including awaiting continuation. Pending
243
+ means pending only; blocked_policy requires explicit retry. Concurrent
244
+ changes can make earlier rows eligible after a cursor has passed them,
245
+ so each new drain starts at the beginning. Latest outcome per worker is
246
+ the last staged outcome by greatest reservation sequence, with assignment
247
+ ID retained in the result. This supports restoring the worker view and
248
+ does not replace exact lookup by assignment ID.
249
+
250
+ Project only the last completed assistant message in the final operation,
251
+ by committed timeline sequence. Preserve its text exactly. A missing
252
+ message or an empty/whitespace-only text projection is a known failure
253
+ with the public reason "worker produced no saved result". Do not fall
254
+ back to intermediate output. A crash without reliable terminal evidence
255
+ remains uncertain.
256
+
257
+ Keep the existing harness wire contract. Prefer a typed, indexed additive
258
+ Agent migration for continuations, eligibility and provenance over
259
+ encoding searchable fields inside unrelated text columns. Core owns
260
+ schema 19. Allocate any new migration with Core, after the orchestrator
261
+ schema, before implementation. Legacy rows default to native destinations.
262
+ Legacy source falls back to the persisted worker conversation ID where
263
+ no handle was recorded. Existing staged results and notices retain their
264
+ original bytes and IDs, including their original text projection.
265
+
266
+ Gate 3 native delivery applies the existing delivery state transitions.
267
+ Schedule pending scans on open after channel changes, on eligible resume,
268
+ and after confirmation of an earlier change. Lost acknowledgement keeps
269
+ the same notice pending with the same ID and bytes. An invalid policy
270
+ moves it to blocked_policy until explicit retry. A missing or retired
271
+ destination moves it to failed_destination. Match confirmation to the
272
+ attempted delivery ID so a stale response cannot settle unrelated work.
273
+
274
+ If an Agent schema migration is needed, use version 20 after O1's version
275
+ 19 lands. Exercise it on an actual alpha `3fd2db2` database through
276
+ schema 19, retaining legacy rows and pending payloads. Reopen a second
277
+ time to verify idempotence.
278
+
279
+ Combined successor prompts call continueAssignment in beforeDispatch
280
+ message order. The orchestrator reads the active predecessor from
281
+ readBinding. After m0→m1→m2, m1 is superseded even if both m1 and m2
282
+ appear in the final causes. Only m2 settles the assignment and one notice
283
+ results. The orchestrator calls closeContinuation if it knows an awaiting
284
+ successor will never dispatch and no terminal lifecycle callback will
285
+ settle it. Examples include a refused send before beforeDispatch or a
286
+ worker stopped while awaiting continuation. Once linked, promptFailed
287
+ for the active successor settles it; closing the stale predecessor
288
+ cannot overwrite it. Owner death leaves unfinished work for the
289
+ replacement to settle as uncertain.
290
+
291
+ The stable ID remains worker-result:<assignmentId> and can be derived
292
+ before staging. Delivery requires the committed staged payload. The
293
+ orchestrator owns the ACP idempotent append keyed by that ID. Its
294
+ worker_reply is the projected final text; missing or blank projection
295
+ maps to worker_failed with "worker produced no saved result".
296
+
297
+ Core allocated schema 20 after O1's schema 19. Implementation waits for
298
+ the reviewed O1 base before changing SQLite schema.
299
+
300
+ ### Explicit new assignment
301
+
302
+ A normal steer continues the active assignment. Redirect alone changes
303
+ where its eventual notice goes, subject to the existing staging fence.
304
+ An explicit new-assignment send on an idle worker only reserves the new
305
+ assignment.
306
+
307
+ On a busy worker, before dispatching an explicit new assignment, close
308
+ the old assignment against its expected active message ID and reserve
309
+ the new assignment. The explicit replacement may close an unfinished
310
+ active binding or an awaiting continuation. Ordinary continuation
311
+ cleanup may only close an awaiting continuation. Use interrupted with
312
+ the public reason "worker interrupted by steering" and
313
+ possiblePartialEffects true. The new assignment has its own ID,
314
+ provenance and delivery ID. Redirect combined with new sets only the
315
+ new assignment's destination. The old notice retains its destination.
316
+
317
+ If the old final record or staged outcome commits first, it wins and
318
+ the old outcome stays unchanged. If explicit replacement closes first,
319
+ a later old terminal record stays inspectable but cannot settle it
320
+ again or mark it awaiting continuation. Test each order, including old
321
+ steered cancellation before and after the replacement transaction.
322
+ Commit the close and new reservation together before dispatch. A crash
323
+ after that commit leaves the old outcome staged and an unfinished new
324
+ binding recoverable as uncertain, without redispatch.
325
+
326
+ Use the same new assignment and message IDs on retry. Repeating the
327
+ transaction returns the existing matching reservation and leaves the old
328
+ notice unchanged. A reservation conflict rolls back the close. A crash
329
+ between the close and reservation rolls back both. The new assignment
330
+ captures the requesting callback's originating policies; it does not
331
+ inherit the old assignment merely because the worker is the same.
332
+ Where terminal output actually reflects taken inputs subject to earlier
333
+ restrictions, keep the applicable contributing policy union.
334
+
335
+ The orchestrator calls replaceAssignment before dispatch. The repository
336
+ owns the atomic transaction for the old settlement and new reservation.
337
+ Ordinary closeContinuation still only closes awaiting continuation.
338
+ A stale predecessor or conflicting reservation returns conflict without
339
+ writes. If the expected predecessor already finalized or settled, reserve
340
+ the new assignment and return old_settled without changing or staging the
341
+ old result. Otherwise stage its interruption and return replaced. The old
342
+ notice uses "worker interrupted by steering" as its public reason.
343
+
344
+ Persist the replacement relation with the new reservation in that
345
+ transaction, including the predecessor IDs and disposition. An identical
346
+ retry reports existing and the original replaced or old_settled disposition.
347
+ A different predecessor or payload conflicts. The new reservation result
348
+ reports whether the binding was newly reserved or existing; an existing
349
+ reservation cannot authorize redispatch. Test rollback on a conflicting
350
+ reservation and a crash between settlement and reservation.
351
+
352
+ From beforeDispatch, proceed only when replaceAssignment reports a fresh
353
+ reserved binding. Both replaced and old_settled reserve the binding
354
+ directly; neither requires a separate reserve call. An existing binding
355
+ reports the same original disposition without sending again. Conflict
356
+ refuses the send before dispatch.
357
+
358
+ An unfinished predecessor inherited from a dead owner is settled as
359
+ uncertain within replaceAssignment, together with the new reservation.
360
+ Return old_settled. Preserve the predecessor destination and provenance
361
+ and persist the same disposition for retries. This applies to native and
362
+ ACP destinations independently of any host scan. A successor cannot
363
+ continue an abandoned binding. Orchestration must reserve fresh work
364
+ instead, settling the abandoned predecessor through replacement or recovery.
@@ -0,0 +1,81 @@
1
+ # Decision 0026 · Bounded inference context
2
+
3
+ Date: 2026-11-23
4
+
5
+ Status: Gate 1 draft. Grounded on `alpha` at `510e2a7406b4dc2b6d3aafedb61529bff423990b`.
6
+
7
+ Full snapshots currently supply context, policy, and delivery evidence before
8
+ inference. Use one detached, indexed read at a committed revision and freeze
9
+ the assembled input and tool offer for retries. Whole snapshots remain useful
10
+ for export. A persisted rendered context would add rebuild and invalidation
11
+ rules. Start with on-demand selection and shared native visibility.
12
+
13
+ **Admission.** Measure UTF-8 bytes of the normalized text stored for a new
14
+ input, including separators between text parts. Apply the per-message limit to
15
+ participant input and notices. Reuse `invalid_input` in process and
16
+ `invalid_params` on the wire, with a message naming the limit. Rejection writes
17
+ nothing and emits no receipt. An identical retry of an accepted stable ID
18
+ still returns its existing receipt. Expose the effective limit in session open
19
+ metadata and development client configuration. The web chat and REPL preflight
20
+ against the advertised value.
21
+
22
+ **Taking input.** Both start and steering atomically take a FIFO prefix under
23
+ the batch byte and item-count bounds. The next input that would exceed a bound
24
+ and all later inputs remain `received`, in order, for the next boundary. A
25
+ pending suffix keeps normal wake and finish behavior. The batch limit budgets
26
+ raw text. Assembly can still fail when required instructions, tools, attributed
27
+ input, and other required material together exceed the actual request budget.
28
+ An oversized head item accepted by an older version is taken alone and ends
29
+ its turn with `context_limit` if it cannot fit, so it cannot block later work.
30
+
31
+ **Build and receipts.** Preserve the turn's triggering input and inputs newly
32
+ taken since the preceding committed assistant response, including on resume.
33
+ Any additional active exchanges are optional and may be omitted only as whole
34
+ assistant call groups with every corresponding result and provider state. The
35
+ receipt set contains only original input items represented in the frozen
36
+ request. The scripted boundary set contains just newly taken IDs in take
37
+ order. The policy set covers the whole taken turn, including inputs whose text
38
+ was trimmed. If required data or complete policy evidence cannot fit the read
39
+ or input bounds, fail the turn with reason `context_limit` before reserving a
40
+ model call. Taken items stay linked to that failed turn, existing milestones
41
+ stand, and remaining pending items stay eligible. Fresh work can start.
42
+
43
+ **Read and budget.** Both storage adapters implement `InferenceStorageReads`.
44
+ Bound candidate rows and serialized record bytes before materializing message
45
+ bodies. Omit oversized optional history. A required overflow is explicit.
46
+ Measure candidate sizes as serialized message bytes plus UTF-8 attribution and a
47
+ fixed record allowance. The record cap applies to message bodies and also
48
+ limits the distinct policy-name projection independently. Both spend the same
49
+ byte budget. SQLite uses the turn, conversation, and row sequence indexes, with
50
+ partial indexes for taken inputs and assistant responses. A per-turn policy
51
+ projection is backfilled transactionally on first open and updated when items
52
+ are linked, including writes by format-6 owners that predate this read. It
53
+ changes neither the session format nor the archive format. Memory maintains
54
+ the same projection with transaction rollback.
55
+
56
+ Select shared material within a bounded recent candidate range, which may yield
57
+ fewer items under a busy local channel. Use a text estimate with an output and
58
+ error reserve. Provider-side enforcement of the output reserve stays open.
59
+ See [Business rules](../docs/BUSINESS_RULES.md) for starting values.
60
+
61
+ The contracts are additive at Gate 1. Gate 2 wires the storage extension into
62
+ both adapters and proves its bounds. Gate 3 wires admission, receipts, and
63
+ assembly through normal entry points. Existing text inputs and tool policies
64
+ retain their representation.
65
+
66
+ Gate 3 uses the published UTF-8 cap for new session input. A retry of an
67
+ existing item resolves by its original identity. An oversized item already in
68
+ a legacy inbox advances alone and fails with `context_limit`, allowing later
69
+ pending work to proceed. Tool results retained in a request are shortened to
70
+ 2 KiB of source text plus an explicit marker. Historical failure evidence uses
71
+ the same bounded read and is eligible for turns represented in the selected
72
+ history candidates. Diagnostics count candidates trimmed during assembly.
73
+
74
+ Gate 4 uses a loopback inspection read port. Status reads use channel counts
75
+ and latest turn state. Events invalidate views without reading storage.
76
+ Timeline and Live Context page recent headers and load bodies within a byte
77
+ budget. Oversized rows retain their position and advance the cursor. Channels
78
+ requests recent accounting summaries on demand from the existing model-state
79
+ record, whose storage cost remains separate. Captured requests are process
80
+ local and limited per channel. The development HTTP endpoints change, with
81
+ the inspector page updated in the same change.
@@ -0,0 +1,22 @@
1
+ # 0027. Editable development instructions
2
+
3
+ The development startup prompt and tool list assumed the original scripted demo. This
4
+ made live sessions harder to use for arbitrary work or tune between launches.
5
+
6
+ Editing a TypeScript literal required working in the runtime configuration code.
7
+ A shared prompt registry would give the harness ownership of consumer text.
8
+ The development CLI instead loads bundled Markdown or an explicit
9
+ `--instructions <path>` override. It reads the file once, preserving its text,
10
+ and passes the resolved string through the existing system field. The explicit
11
+ override wins for that open, including when a sidecar supplies the other
12
+ configuration fields. SQLite and archives retain only the resolved text.
13
+ Bundled instruction text lives in the context capability's instructions
14
+ directory, with a Markdown file for each of the agent, the harness, and the
15
+ agent demo.
16
+
17
+ The live development tool list contains the clock and channel notices.
18
+ Scripted development uses the generic test-agent prompt when selected with
19
+ `--script`. Individual test fixtures can supply their own tools. Existing saved configuration remains eligible
20
+ for new turns. A suspended turn still has to pass the existing compatibility
21
+ check, so a changed prompt or the removed live demo tool can prevent resume.
22
+ The session config and wire shapes stay the same.
@@ -0,0 +1,16 @@
1
+ # 0028. Opt-in development debug tools
2
+
3
+ Free-form testing needs small, predictable tool calls and a way to compare the
4
+ agent's account against the actual request. A fixed scenario couples these
5
+ checks to a specific prompt. Development startup instead accepts
6
+ `--debug-tools` to offer echo, bounded wait, and intentional failure through the
7
+ ordinary policy gate. `--debug` offers those tools and uses the bundled
8
+ test-agent prompt for the active process, preserving saved agent text. Wait honors the turn's abort signal. Failures use the
9
+ existing paired result and outcome format, with string-only executors still
10
+ supported. The flag applies to one process and is not persisted.
11
+
12
+ The existing development inspector identifies included and trimmed candidates
13
+ by timeline sequence, lists offered tools, and links captured requests to
14
+ durable model-call summaries. Candidate diagnostics describe the bounded read
15
+ and assembly. They do not enumerate older history outside the read window.
16
+ Existing capture controls apply.
@@ -0,0 +1,37 @@
1
+ # 0029 — Bounded model-call pages
2
+
3
+ ## Problem
4
+
5
+ The model-call RPC snapshots the session. The existing storage page operation
6
+ also decodes all of the model history. R5 uses the RPC on turn close, so these
7
+ reads put history-sized work on the ordinary execution path.
8
+
9
+ ## Options
10
+
11
+ Using the existing page operation alone removes the snapshot but still reads
12
+ the history blob. Moving canonical writes to a new model-store schema would
13
+ expand scope and affect recovery and older writers.
14
+
15
+ ## Choice
16
+
17
+ Expose the existing model-call page seam on the assembled session and use it
18
+ for the RPC. Keep the wire contract and frame handling. Read a bounded page
19
+ of complete summaries, fetching at most limit plus one rows in oldest-first
20
+ order. Resolve the exclusive cursor through a unique call-ID index. An
21
+ unknown cursor remains not_found. If the first summary cannot fit the frame,
22
+ return transfer_limit. Otherwise return the complete summaries already packed
23
+ and a continuation when the next summary cannot fit.
24
+
25
+ SQLite stores an indexed side projection of summary JSON by call order.
26
+ Backfill under the owner transaction and update it atomically with canonical
27
+ modelState writes. An older writer marks the projection dirty for the next
28
+ open, following the reply-ID projection precedent. Steady-state reads query
29
+ only the indexed projection. Memory pages the existing array and uses the
30
+ monotonic call ID ordering for cursor lookup.
31
+
32
+ ## Compatibility
33
+
34
+ SQLite format 6 and archive semantics stay unchanged. The canonical blob
35
+ remains authoritative for recovery, archive and writes; the side table
36
+ adds write maintenance and storage. Legacy files open without a format
37
+ migration and older writers keep their existing table layouts.