@qlairoslabs/acp-client 0.12.0 → 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 -3
  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 +847 -7
  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 +30 -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 +10 -0
  35. package/src/cli/index.ts +3 -3
  36. package/src/cli/managed.ts +2 -2
  37. package/src/client.ts +68 -98
  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,187 @@
1
+ # Long-running mock mode
2
+
3
+ Date: 2026-11-21.
4
+ Status: proposed for review. See [PLAN.md](PLAN.md) for module ownership,
5
+ implementation gates, and the final driven rehearsal.
6
+
7
+ ## Goal
8
+
9
+ Run repeatable offline rehearsals with the real native harness and acp-client.
10
+ Use the same scenario file format for short deterministic tests and workloads
11
+ lasting minutes or hours. The rehearsal can simulate model output and tool
12
+ effects while exercising real channel scheduling, inference boundaries,
13
+ permissions, callbacks, persistence, and control operations.
14
+
15
+ Build on the [acp-client integration](../../acp-client-integration/0001-DESIGN/SPEC.md),
16
+ [host callbacks](../../tools-and-callbacks/0001-DESIGN/SPEC.md), and
17
+ [operator controls](../../operator-controls/0001-DESIGN/SPEC.md). Use the
18
+ existing scripted model, model-attempt reservation, and public stdio client.
19
+
20
+ ## Ownership
21
+
22
+ | Component | Responsibility |
23
+ | --- | --- |
24
+ | Scenario file | Describe simulated model attempts and scheduled participant messages. |
25
+ | Harness scripted model | Emit the prescribed provider-neutral events in response to a real inference request. |
26
+ | Harness session | Own admission, context, model execution, permission checks, tool dispatch, notices, and durable records. |
27
+ | Rehearsal driver | Run scheduled inputs through acp-client, observe outcomes, and control the child process when tests require it. |
28
+ | Test tool handlers | Simulate controlled delays, holds, failures, and observable effects through the normal tool paths. |
29
+
30
+ The driver lives outside the harness child and can replace it while the same
31
+ run continues. It sends inputs and controls through the consumer APIs. Short
32
+ tests can provide their own input and controls in code while using the same
33
+ model file format.
34
+
35
+ ## JSONL file
36
+
37
+ A local UTF-8 JSONL file contains one JSON object per record. The first record
38
+ declares the format version. Model and send records can be interleaved. The
39
+ loader validates the file before execution and reports malformed or unsupported
40
+ records with their line numbers. Convert the existing short JSON fixtures so
41
+ there is one supported on-disk script format.
42
+
43
+ Parse and validate the scenario once per open and reuse the validated sequences
44
+ across channels and attempts. Each channel has its own attempt position.
45
+
46
+ | Record | Fields and behavior |
47
+ | --- | --- |
48
+ | `scenario` | `version` and a scenario name. Required first record. |
49
+ | `model` | Optional channel ID, optional initial delay, and the simulated attempt behavior. Supports text, timed text chunks, tool requests, synthetic usage, a typed provider failure, or a wait that ends on cancellation. A tool request contains the existing call ID, name, and arguments. |
50
+ | `send` | Elapsed time from the start in milliseconds, channel ID, participant ID, stable input ID, and text. |
51
+
52
+ Example of a model-only script for a test that provides its own prompt:
53
+
54
+ ```jsonl
55
+ {"type":"scenario","version":1,"name":"clock"}
56
+ {"type":"model","channelId":"alice","content":"I’ll check the time.","calls":[{"id":"time-1","name":"current_time","arguments":{}}]}
57
+ {"type":"model","channelId":"alice","content":"I checked the time."}
58
+ ```
59
+
60
+ One model record describes one attempt. Requesting tools leaves execution to
61
+ the harness. Its next attempt consumes another record and receives the real
62
+ tool results in context. A prewritten follow-up alone cannot establish that
63
+ the tool ran or its result reached the model. Tests use recorded effects and,
64
+ when needed, captured requests to verify those boundaries.
65
+
66
+ ## Selection, timing, and recovery
67
+
68
+ Model records for a channel are consumed in file order for that channel.
69
+ Channel-specific sequences take precedence. Model records with no channel ID
70
+ form a reusable default sequence for channels that lack a specific sequence.
71
+ Each such channel has its own position, preserving the existing short-fixture
72
+ behavior. Exhausting the selected sequence reports `script_exhausted`.
73
+
74
+ In a durable session, reuse the existing per-channel model-attempt reservation.
75
+ A retry consumes another record. A crash after reservation leaves that record
76
+ consumed. Persist a digest of the validated model sequences when the scripted
77
+ session is created. Check it on every reopen before enabling execution or
78
+ reserving another attempt, including after a crash with no checkpoint. Return
79
+ `incompatible` if the sequences changed. Formatting and scheduled sends are
80
+ outside the model digest. An older scripted store without a digest requires a
81
+ fresh test session. The driver records the whole-file digest for reproducibility
82
+ and retains its scheduled-action position across a child restart. Persisting
83
+ and restarting the driver itself is outside this slice.
84
+
85
+ Scheduled sends use elapsed time from a monotonic run clock. Sends with the
86
+ same timestamp are issued in file order. Independent channels can overlap, so
87
+ issuing a send does not wait for that turn to complete. Record actual execution
88
+ order and input grouping for diagnosis. Deterministic tests can assert which
89
+ input IDs were included at a particular inference boundary. Use existing
90
+ attempt and turn evidence where it identifies that boundary precisely. Add a
91
+ focused test observation if needed. These assertions do not select responses.
92
+ Timed runs enforce input grouping only when the test declares an expectation.
93
+ Model delays and fixture waits honor cancellation and exercise the configured
94
+ model, approval, and tool deadlines.
95
+
96
+ CI uses barriers in test code. For example, a hold handler signals entry and
97
+ waits for release. The test sends Bob's input after that signal, waits for Bob's
98
+ turn to finish, then releases Alice's handler. Detach, approval, interruption,
99
+ suspension, and restart can also be scripted in test code through the existing
100
+ APIs. The file format in this slice schedules sends. General event triggers and
101
+ file-driven control commands can follow later.
102
+
103
+ ## Tools and notices
104
+
105
+ Reuse the default `notify_channel` built-in from
106
+ [operator controls](../../operator-controls/0001-DESIGN/SPEC.md).
107
+ The harness provides its definition and handler through normal session
108
+ composition and reserves the name against consumer registration. It derives
109
+ the source channel and turn from the invocation and uses the existing
110
+ permission and channel admission paths. A model record can request it and the
111
+ target consumes its next model response if the notice wakes a turn. A driver
112
+ notification command is outside this slice. The mock exercises channel
113
+ notices. Topic notices can follow when the built-in capability is available.
114
+
115
+ Reuse controlled test tools and add a small set of fixture handlers for quiet
116
+ callbacks, delayed results, failures, and observable effects. The fixture owns
117
+ its effects. The harness owns approval, cancellation, pairing results with
118
+ calls, and crash recovery. Uncertain effects follow the existing no-replay rule.
119
+
120
+ The timed rehearsal command supplies a documented set of test handlers and a
121
+ dedicated tool policy. The checked-in timed fixture uses bounded handlers and
122
+ explicitly allows any built-in notices it requests. It runs unattended. Keep
123
+ approval waits, manual holds, and deliberate stalls in deterministic tests,
124
+ where test code controls the responder and release. Both modes use the same
125
+ permission gate and report unexpected tool failures in the run results.
126
+
127
+ ## Run results
128
+
129
+ Run against a fresh test session by default. A restart case deliberately reopens
130
+ that same session. After all scheduled sends are issued, allow expected work to
131
+ settle within a configured run deadline. Track each scheduled send by input ID
132
+ and resolve each accepted input to an outcome. Several accepted inputs can
133
+ share one turn. Completion also checks the session for work started by notices,
134
+ including on channels with no scheduled sends. Running turns, pending inputs,
135
+ and checkpoints count as unfinished unless the test explicitly expects that
136
+ state. An idle indication alone does not establish completion. Once work
137
+ settles, capture a consistent final revision for delivery verification. If
138
+ the run reaches its deadline, record the blocking work available through
139
+ status, then stop and reap the child within the cleanup budget.
140
+
141
+ Fail on unexpected rejection or turn failure, unfinished work at the deadline,
142
+ or missing or duplicate committed replies where delivery was expected. A test
143
+ can explicitly expect interruption, failure, or timeout. Report unused model
144
+ records separately. Unused records fail a test only when it requires exact
145
+ consumption.
146
+
147
+ Record a compact event log and summary with run duration, sent inputs, turn
148
+ outcomes, and observable callback effects. Compare replies recorded by the
149
+ consumer with bounded harness history reads by committed message ID through the
150
+ final revision. Scope the comparison to the tested channels and expected
151
+ delivery windows. For detached channels, check expected replies after explicit
152
+ recovery. Full inference-request capture is opt-in at the scripted adapter.
153
+ With capture disabled, skip diagnostic cloning, retention, and file writes of
154
+ full requests. Lightweight attempt observations can still report channel,
155
+ ordinal, and input IDs. Generate synthetic fixtures before running them.
156
+ Fixture authors can use real timing and event patterns as a guide.
157
+
158
+ ## Acceptance
159
+
160
+ 1. Convert existing fixture coverage to JSONL and verify a model-only script
161
+ works through the scripted harness. Reject malformed records, report a
162
+ missing response explicitly, and verify independent channel positions.
163
+ After a crash with pending input and no checkpoint, reject a changed model
164
+ sequence before any new attempt is reserved. Verify capture-off skips full
165
+ request copying and several attempts reuse one validated scenario.
166
+ 2. Run a deterministic acp-client test with a real stdio child. Alice streams
167
+ text and waits on a controlled callback while Bob completes. Exercise
168
+ approval through the normal gate, then verify targeted interruption leaves
169
+ Bob unaffected. Assert the callback and committed results from observed
170
+ evidence. Exercise steering and verify the expected input IDs at the next
171
+ inference boundary.
172
+ 3. Detach a conversation, let a built-in channel notice start work there, and
173
+ recover the committed reply exactly once after reattachment. Suspend with
174
+ work in progress, replace the child, and resume from the checkpoint without
175
+ repeating a committed effect. Exercise abrupt interruption separately and
176
+ verify a reserved attempt and an uncertain effect are not replayed.
177
+ 4. Run a multi-minute timed fixture with bursts, idle gaps, concurrent
178
+ channels, and short and tool-heavy turns. Verify the driver finishes within
179
+ the configured run deadline, accounts for accepted inputs and expected
180
+ committed replies by ID through the final revision, and leaves no child
181
+ process running. Verify the driver waits for a notice-driven turn after the
182
+ last scheduled input settles. Exercise deadline diagnostics and cleanup
183
+ separately. The same driver accepts hour-scale fixtures. All runs work
184
+ without contacting a model provider.
185
+ 5. In an ordinary session, verify `notify_channel` is offered once when
186
+ policy allows it and runs without consumer registration. Verify policy
187
+ denial prevents dispatch and consumer registration cannot shadow it.
@@ -0,0 +1,148 @@
1
+ # Model execution work log
2
+
3
+ Implementation branch `aiagent/cod1a-model-execution` starts from accepted
4
+ configuration/permissions closure `28c6faf7faf3d4d48333498a61ea74f92273cc25`.
5
+ Scope commit `0590af9` was cherry-picked as `aeac966`. Stage 1 defines the
6
+ contract and decision before runner, adapter, storage, or protocol behavior.
7
+ Each stage requires its own gate and Gro's review of the named revision before
8
+ continuing. The final gate includes scripted SQLite over real stdio, in-process
9
+ parity, full typecheck and the complete offline harness suite.
10
+
11
+ Stage 1 contract gate: `bun run typecheck --pretty false` passed. Decision
12
+ 0019 traces retry in both subscriptions, interruption, slow delivery, and the
13
+ crash boundaries, including durable receipts, usage and script reservation.
14
+ Independent contract review is pending; no dependent implementation is included.
15
+
16
+ Gro did not approve `741cdff`; the requested contract locks include the existing
17
+ wire event, turn outcomes, deadline start, scripted counter, dispatch fence,
18
+ receipt/usage validation, transactional migration and bounded delivery. The
19
+ revised contract includes those locks and wires the new types into the actual
20
+ protocol, events and storage contracts. Standalone contract `tsc` passes. Full
21
+ `bun run typecheck --pretty false` is expected to fail until implementations
22
+ handle reference messages, storage format 5/archive 4 and model-call methods;
23
+ no implementation changes are included in this revision. Gro's re-review is
24
+ required before Stage 2.
25
+
26
+ Gro approved Stage 1 at `a9b5f84f4d165409bc7d9e81ecf15009b484714c`.
27
+ Standalone contract typecheck passed independently; the full typecheck's 27
28
+ errors were accepted as pending storage and reference-consumer implementation.
29
+
30
+ ## Stage 2: call execution
31
+
32
+ The logical-call runner, scripted reservation adapter, OpenRouter streaming
33
+ translation and turn's commit-before-dispatch path are implemented. The gate
34
+ uses a call-store double: `bun test test/model-channel-double.test.ts
35
+ test/model-runner.test.ts test/model-stream-adapter.test.ts test/loop.test.ts`
36
+ passed 21 tests, 0 failures and 66 assertions. It covers the same-channel
37
+ scheduler after interruption, stop and late response, the permission gate after
38
+ commit, retry and deadline, both text-delivery cutoff paths, malformed calls,
39
+ and both adapters through the runner.
40
+
41
+ Full `bun run typecheck --pretty false` remains red on the 27 already identified
42
+ storage format and reference-consumer errors. The real `test/scripted.test.ts`
43
+ scheduler case fails at missing `startCall` because the memory and SQLite
44
+ call-store implementations belong to Stage 3; the other four cases pass. Stage 3
45
+ must repeat channel usability and the scripted test on both real adapters, along
46
+ with persistence and crash gates. No Stage 3 storage work is included here.
47
+ Independent Stage 2 review is pending.
48
+
49
+ Gro did not approve `c02868b`: final subscriptions received ephemeral text
50
+ notifications that the current stdio parser rejects. The protocol publication
51
+ filter now drops text_delta, text_gap and text_incomplete for final mode, after
52
+ the runner's independent retry cutoff. A protocol regression test verifies
53
+ receipts, message_completed, tool and turn events still pass. The expanded gate
54
+ (`bun test test/model-final-filter.test.ts test/model-channel-double.test.ts
55
+ test/model-runner.test.ts test/model-stream-adapter.test.ts test/loop.test.ts`)
56
+ passed 22 tests, 0 failures, 68 assertions. Full typecheck remains at the same
57
+ 27 deferred storage/reference errors; the real scripted scheduler remains
58
+ blocked on Stage 3's call store. Independent re-review is pending.
59
+
60
+ Gro approved Stage 2 at `aeb81af68d9dcdbd3619fdeb71608e2165bc5e08`;
61
+ their independent focused gate passed 22 tests, 0 failures, 68 assertions.
62
+
63
+ ## Stage 3: storage and streaming
64
+
65
+ Memory and SQLite use the shared call-store transactions; format 2/3/4 recovery
66
+ and migration publish format 5, and logical archive 4 retains call summaries,
67
+ script positions and message identity. The stdio parser accepts stream events
68
+ and reference completions. A bounded live queue drops deltas with a gap or fails
69
+ a blocked connection; oversized committed text is available in bounded byte
70
+ pages. The public client exposes message and model-call reads and usage summing.
71
+
72
+ Both real adapters pass interruption followed by new work, receipt and usage
73
+ reopen, script reservation and archive identity tests. SQLite SIGKILL tests on
74
+ both sides of response commit check call outcome, timeline identity and the next
75
+ reserved script step. Other checks cover final/stream message IDs and ordering,
76
+ a slow reader while another channel commits, blocked-queue shutdown, large
77
+ UTF-8 reads on both transports, and a storage failure after a streamed draft.
78
+ The test using usage reports across reopen uses a clean handle close to simulate
79
+ recovery; the SIGKILL fixtures do not themselves report provider usage.
80
+
81
+ Gate: `bun run typecheck --pretty false` passed; `bun test ./test` passed 282
82
+ tests, 0 failures, 3103 assertions across 39 files (57.84s), with local IPC
83
+ access. The shared storage engine remains over 400 lines because it owns the
84
+ transactional lifecycle and model-call rules for both adapters. Model metadata is
85
+ currently serialized as one state record, so updates copy and rewrite that record
86
+ as call history grows; performance at large call counts has not been benchmarked.
87
+ Independent Stage 3 review is pending. Stage 4 still requires the real scripted
88
+ stdio stall/deadline scenario, documentation and final independent review.
89
+
90
+ Gro did not approve Stage 3 at `2ed06ec`: summary pagination discarded earlier
91
+ records when a later summary exceeded a frame, and in-process delivery lacked
92
+ the bounded live queue. The fix returns a continuation after earlier whole
93
+ summaries and fails only when an oversized summary is first on its page. The
94
+ in-process transport now uses the same bounded queue as stdio; nondroppable
95
+ overflow closes the connection and stops the session. Regression tests cover
96
+ both paging orders, delta drop and gap, and connection failure. No Stage 4 work
97
+ is included. Re-review gate: `bun run typecheck --pretty false` passed;
98
+ `bun test ./test` passed 285 tests, 0 failures, 3113 assertions across 40 files
99
+ (51.79s), with local IPC access. Independent re-review is pending.
100
+
101
+ Gro approved Stage 3 at `19c189e22ff8ccab2fb5a11d5becf00731482a31`;
102
+ their independent typecheck passed and the full suite passed 285 tests, 0
103
+ failures, 3113 assertions across 40 files (58.46s). The accepted limitations
104
+ remain: usage recovery was checked across clean reopen, not SIGKILL; the crash
105
+ fixtures do not report usage; and model metadata is one rewritten state record.
106
+
107
+ ## Stage 4: public flow and final gate
108
+
109
+ A real scripted SQLite stdio child uses opt-in test hooks for a partial reply,
110
+ stall, reported usage and a 1.5-second model deadline. Alice times out with an
111
+ incomplete draft and one attempt after Bob finishes; no response or tool effect
112
+ is committed for her timed-out call. Alice completes fresh work, then reopen
113
+ retains the timeout, usage and Seen receipt. Separate public cases exercise a
114
+ text-and-tool response followed by a later reply in final and stream modes over
115
+ both in-process and stdio, checking message IDs and completion-before-dispatch.
116
+ The development inspector displays durable call summaries and attempts after
117
+ reopen. README, architecture and business rules document the implementation.
118
+
119
+ Final implementation gate: `bun run typecheck --pretty false` passed;
120
+ `bun test ./test` passed 290 tests, 0 failures, 3149 assertions across 41 files
121
+ (69.67s), with local IPC access. Gro approved the behavior revision
122
+ `02c96de2ee9b70cad2081e744b67737dc1b58844`; their independent typecheck
123
+ passed and the full suite passed 290 tests, 0 failures, 3149 assertions across
124
+ 41 files (68.33s). The test stall and stream behavior is supplied by opt-in
125
+ `HARNESS_TEST_*` hooks around the scripted adapter; ordinary scripted files
126
+ remain complete-response scripts.
127
+
128
+ ## Closure and retrospective
129
+
130
+ The accepted chain is configuration/permissions closure `28c6faf`, model scope
131
+ `aeac966`, Stage 1 contract `a9b5f84`, Stage 2 `aeb81af`, Stage 3 `19c189e`,
132
+ and Stage 4 behavior `02c96de`. The envelope remains version 1; the durable
133
+ storage format is 5 and logical archive is 4. The default model deadline remains
134
+ 120 seconds, while the final stdio test used 1.5 seconds.
135
+
136
+ Contract review clarified the existing wire completion, recovery ordering and
137
+ attempt reservation before implementation. Independent stage reviews caught a
138
+ final-mode publication error, then a pagination and in-process buffering gap;
139
+ each was fixed and re-reviewed before the next stage. The public gate verified
140
+ timeout and fresh work with a real SQLite stdio child, plus both text modes and
141
+ transports; the inspector was checked across reopen.
142
+
143
+ Accepted limits: usage recovery was tested across a clean close, not SIGKILL;
144
+ the SIGKILL fixtures do not emit usage. Model metadata is stored as one rewritten
145
+ record and its performance at large call counts has not been benchmarked. The
146
+ shared storage engine exceeds 400 lines because it owns both adapters' common
147
+ transactions. The test-only stall and delta hooks do not extend the ordinary
148
+ script-file format. No merge was requested.
@@ -0,0 +1,95 @@
1
+ # Model execution implementation plan
2
+
3
+ Date: 2026-11-19.
4
+ Status: ready for implementation. Start with the contract gate after the base is accepted.
5
+
6
+ ## Scope and module map
7
+
8
+ Implement [SPEC.md](SPEC.md) on a base containing the accepted configuration
9
+ and permissions slice. Record the actual base at assignment. Preserve the
10
+ permission gate and dispatch events. Add a model call runner, streaming
11
+ adapters, and durable call summaries. Topic notices and image input have
12
+ their own work items.
13
+
14
+ Paths below are relative to the native harness package.
15
+
16
+ | Area | Existing or proposed code | Ownership |
17
+ | --- | --- | --- |
18
+ | Contracts | `src/contracts/{loop,events,session,storage,protocol}.ts` and a model contract file if needed | Define adapter attempt events, call and attempt outcomes, receipt evidence, reply IDs, and summary retrieval. |
19
+ | Model execution | New call runner and retry policy in `src/capabilities/model/` | Run one logical call, classify retries, apply a shared deadline, and fence late output. Keep the 120-second deadline, one-second delay, and single retry budget in named defaults. |
20
+ | Model adapters | Existing `src/capabilities/model/{openrouter,scripted}.ts` | Report one attempt using neutral events. Assemble provider tool-call fragments and handle terminal response and usage translation at the edge. Preserve complete-response support. |
21
+ | Kernel and assembly | `src/kernel/{loop,channels}.ts` and `src/index.ts` | Connect the call runner and lifecycle signals through contracts. Commit responses before tool dispatch. Finish iterations and take input at existing boundaries. |
22
+ | State | `src/state/storage/{engine,memory,sqlite,archive}.ts` as needed | Persist summaries, receipts, and scripted attempt position. Commit successful calls and their responses atomically. Recover unfinished calls as interrupted. Settle export/import treatment in the storage contract. |
23
+ | Consumer interfaces | `src/contracts/protocol.ts`, the typed client, and `src/interfaces/{protocol,inspector}/` | Expose both subscription modes, bounded live delivery, completion by ID, reconnect reconciliation, and summary reads. |
24
+ | Verification | `src/testing.ts` and `test/` | Use scripted streams, controlled timing, and local provider fixtures. Verify the same contract through in-process and real stdio clients. |
25
+
26
+ Keep retry and provider details out of the kernel. Permission and tool timeouts
27
+ remain at their own boundaries. Update
28
+ [BUSINESS_RULES.md](../../BUSINESS_RULES.md) with the implementation locations
29
+ for the defaults and behavioral choices once they ship.
30
+
31
+ ## Implementation stages and acceptance gates
32
+
33
+ | Stage | Work and dependencies | Acceptance gate |
34
+ | --- | --- | --- |
35
+ | **1. Contracts** | Define adapter outcomes, receipt evidence, stable reply IDs, atomic success commit, and durable script reservation. Settle usage ordering, storage and archive compatibility, bounded buffering, and reads of large replies. Record decisions before dependent changes. | Typecheck. Trace retry in both subscription modes, interruption, slow delivery, and crashes before and after response commit. Each trace identifies which records commit and what the consumer can recover. |
36
+ | **2. Call execution** | Implement the model call runner and named defaults. Adapt OpenRouter and scripted inference. Apply the retry cutoff before subscription filtering. Wire cancellation and the permission gate. | A transient failure can retry the identical request once within its deadline. Partial text closes retry in both modes. Interrupt cancels an attempt or retry wait, fences late output, and leaves the channel usable. Invalid tool fragments never dispatch. |
37
+ | **3. Streaming and storage** | Correlate drafts, terminal outcomes and committed replies. Implement the atomic success commit, scripted attempt position, durable receipt and usage retrieval, and bounded live delivery. | Verify both sides of the crash boundary and reconnect by message ID. Slow delta readers cannot stall another channel's execution. Oversized replies remain retrievable by ID. Known usage survives reopen without duplicate counts. |
38
+ | **4. End to end and review** | Connect the public API and inspector. Run the scripted process checks, update usage and architecture docs, and run the full harness suite. | Typecheck and the full offline suite pass. Run the public flow below. Independently review the exact revision and record the evidence. |
39
+
40
+ ### End-to-end gate
41
+
42
+ Run a SQLite session through the public client against a real scripted stdio
43
+ child. Alice streams part of a reply, then the script stalls. Bob completes a
44
+ turn on another channel. Trigger Alice's model deadline with a short test
45
+ setting. Verify Alice's live reply ends as incomplete, the call does not
46
+ retry, no tool runs from that stream, and the timeline has no completed reply
47
+ for it. Verify Alice accepts fresh work. Reopen and confirm the recorded call
48
+ outcome and any confirmed receipts remain available.
49
+
50
+ Use focused tests with controlled timing for retry before output, expiry
51
+ during retry wait, and interruption versus a late terminal response. Exercise
52
+ suspension at the iteration boundary with a completed response and tool
53
+ result. The runtime deadline stays at its documented default for ordinary use.
54
+
55
+ Verify both subscription modes with a text-and-tool response followed by a
56
+ later assistant reply. Messages mode delivers complete messages and tool
57
+ events. Streaming uses the same message IDs for deltas and completion.
58
+ Exercise a slow reader and verify that Bob's work commits and is recoverable
59
+ even if his events are delayed. Test dropping deltas separately from failing
60
+ a fully blocked connection, which follows the existing stop rules.
61
+
62
+ ## How we work
63
+
64
+ ### Shared rules
65
+
66
+ - Follow [AGENTS.md](../../../../AGENTS.md) and [ARCHITECTURE.md](../../../../ARCHITECTURE.md).
67
+ Land contract changes and their decision record ahead of dependent changes.
68
+ - Use one implementation branch and record its base, decisions, and gate
69
+ results in `LOG.md` when work starts.
70
+ - Use offline checks with scripted models and local fixtures. Identify the
71
+ exact revision in each review handoff.
72
+
73
+ ### Coordinator
74
+
75
+ Assign one implementer and one independent reviewer once the scope is approved.
76
+ Confirm the accepted base, settle changes to scope or contracts, and check final
77
+ evidence against the spec.
78
+
79
+ ### Implementer
80
+
81
+ Own branch edits. Run each gate and send the reviewer the exact revision and
82
+ evidence. Address findings directly and send the revised revision back.
83
+
84
+ ### Reviewer
85
+
86
+ Review each revision independently and send findings directly to the implementer.
87
+ Check that retries cannot duplicate visible output or tool effects, late
88
+ results cannot advance a stopped turn, and usage remains attributable to the
89
+ right attempt. Approve each gate explicitly. Bring disputed blockers or changes
90
+ to the spec back to the coordinator.
91
+
92
+ ## Closure
93
+
94
+ Record the accepted revision, review outcome, gate results, remaining
95
+ limitations, and a short retrospective in `LOG.md`.
@@ -0,0 +1,200 @@
1
+ # Native harness model execution
2
+
3
+ Date: 2026-11-19.
4
+ Status: ready for implementation on the accepted configuration and permissions base.
5
+
6
+ ## Scope
7
+
8
+ Support streaming model responses, bounded retries and timeouts, and durable
9
+ call summaries. Use the existing OpenRouter and scripted model paths. Build on
10
+ the session lifecycle and the tool dispatch gate defined in the
11
+ [configuration and permissions spec](../../11-19-config-permissions/SPEC.md).
12
+ The [business rules](../../BUSINESS_RULES.md) list choices whose values or
13
+ behavior can be revisited independently.
14
+
15
+ Topic subscriptions and media input have separate designs. The execution loop
16
+ continues to take input through the inbox. A future topic notice can wake a
17
+ subscribed channel and use that same path.
18
+
19
+ ## Execution units
20
+
21
+ - A **turn** runs on one channel and can span any number of iterations.
22
+ Different channels run in parallel.
23
+ - An **iteration** takes pending input, builds a model request, runs one logical
24
+ model call, then handles the tools returned by that call through the
25
+ permission gate. The end of the iteration is a suspension boundary.
26
+ - A **model call** uses one fixed request and one deadline. An **attempt** is
27
+ one execution of that request by the adapter. A call can retry with a new
28
+ attempt while keeping its ID, original request, and deadline.
29
+
30
+ Input accepted while a call is in flight can steer the turn at the next
31
+ inference boundary. It does not change that call or a retry of it. After
32
+ handling a response, continue if tool results require another inference or
33
+ pending input is eligible for take. Otherwise, close the turn through the
34
+ existing atomic inbox check. Input accepted after the turn closes can wake a
35
+ new one.
36
+
37
+ ## Model adapter and stream
38
+
39
+ The adapter runs one attempt and honors cancellation. It reports ordered text
40
+ deltas, provider usage when available, and an explicit terminal outcome.
41
+ When the provider confirms a request reached inference before generating
42
+ output, the adapter may report that evidence separately.
43
+
44
+ A successful terminal response contains the complete assistant message, any
45
+ complete tool requests, and a stop reason. The adapter assembles tool-call
46
+ fragments internally. A non-streaming or scripted adapter may return a complete
47
+ response without deltas. A stream that ends without a valid terminal response
48
+ is incomplete. An explicit provider output limit ends the turn with the
49
+ `output_limit` reason. Keep any streamed text visible as incomplete and
50
+ skip tool dispatch for that response. Define the normalized response shapes
51
+ and stop reasons in the contract decision.
52
+
53
+ Publish text deltas under a stable assistant message ID so the client can
54
+ assemble one live reply. A committed completion uses the same ID. Commit the
55
+ successful model-call outcome and complete assistant response, including its
56
+ tool requests, in one transaction. Publish completion and dispatch tools only
57
+ after that transaction commits.
58
+ Only complete tool requests from a validated response reach the permission
59
+ gate. Keep the existing tool result pairing and dispatch event rules.
60
+
61
+ Every published draft has a terminal outcome. On failure, timeout, interrupt,
62
+ or stop before commit, mark the live reply incomplete with a reason if the
63
+ connection can still deliver the event. The turn separately reports its failed
64
+ or interrupted outcome. Clients can keep partial text visible locally.
65
+
66
+ If the connection dies before a terminal event, the client stops presenting
67
+ the draft as live and reconciles by message ID on reconnect. A committed reply
68
+ replaces the draft if found. Otherwise the draft stays incomplete. Timeline
69
+ reads return committed responses. Live deltas and incomplete text have no
70
+ durable replay guarantee and stay out of inference history.
71
+
72
+ ### Consumer delivery modes
73
+
74
+ Consumers choose a text delivery mode on their event subscription. Both
75
+ modes use the same inference, tool execution, and committed history.
76
+
77
+ | Mode | Consumer receives |
78
+ | --- | --- |
79
+ | Messages (default) | One completed assistant message per model response that contains text, along with tool and turn events. |
80
+ | Streaming | Text deltas followed by completion for the same message ID, along with tool and turn events. |
81
+
82
+ The completed model response defines the message boundary. Paragraphs within
83
+ that response stay together. A response containing text and tool requests
84
+ publishes its completed text before dispatching the tools. A tool-only
85
+ response emits no empty text message. A later inference can emit another
86
+ assistant message in the same turn.
87
+
88
+ Streaming is opt-in for consumers such as the interactive terminal and web
89
+ chat. Messages mode filters out text deltas and incomplete reply events.
90
+ Consumers in that mode still receive the turn outcome. Subscription mode
91
+ does not change the retry policy or what commits to history.
92
+
93
+ Both modes respect bounded transport frames. Coalesce deltas within a bounded
94
+ buffer per connection without waiting for the reader in the execution loop.
95
+ If a reader falls behind, stop live delta delivery for that message. The
96
+ completion gives the consumer the authoritative reply. Deliver ordinary
97
+ completions inline. For a reply too large for one frame, send a completion
98
+ reference with the same message ID and allow bounded reads of its committed
99
+ text by ID. Enqueue completion before tool events for that response.
100
+
101
+ A blocked shared stdio connection can delay events from every channel. If
102
+ terminal events cannot be delivered within the connection bounds, fail the
103
+ connection explicitly and apply existing stop and recovery rules. Results
104
+ already committed remain recoverable. Define the buffer limits, fallback
105
+ signal, and bounded read format in the contract decision.
106
+
107
+ ## Receipts
108
+
109
+ Update receipts only for messages already taken into the target turn and
110
+ actually included in that inference request. Evidence from another channel's
111
+ shared history does not advance them.
112
+
113
+ Provider confirmation that inference accepted the request can establish
114
+ Delivered. Meaningful model output, such as generated text or a tool-call
115
+ delta, can establish Seen before completion. If the adapter only has evidence
116
+ from output, it can confirm both together. A valid non-streaming response can
117
+ also confirm both. Commit confirmed receipts before publishing them. An attempt
118
+ can establish Seen and later fail. Its failure leaves the confirmed receipt
119
+ intact.
120
+
121
+ ## Retry, timeout, and lifecycle
122
+
123
+ Allow at most one automatic retry for a transient provider failure while
124
+ the deadline still permits it. Close the retry window when the runner first
125
+ accepts a nonempty text delta for publication, before filtering by subscription
126
+ or handling transport backpressure. Committing a response also closes that
127
+ window. Privately buffered tool fragments can establish Seen without closing
128
+ it. Retry classification distinguishes transient provider errors from
129
+ cancellation, invalid configuration, and invalid requests. No model retry
130
+ replays a tool.
131
+
132
+ The default model call deadline is 120 seconds from the start of the first
133
+ attempt. It includes waiting for the provider, receiving the full stream, and
134
+ the one-second delay and attempt for any retry. The retry uses only the time
135
+ remaining on that deadline. Tool execution, approval waits, and inbox time
136
+ are outside this deadline. Timing out cancels the active attempt and fences
137
+ late output. End an exhausted or expired call with an explicit outcome and
138
+ leave the channel usable. A turn has no overall iteration limit in this slice.
139
+
140
+ Interrupt and stop cancel the current attempt or retry wait immediately and
141
+ fence late output. Preserve already committed responses and receipts. Suspend
142
+ lets the current logical call settle within its existing deadline, including an
143
+ eligible retry. Finish handling the complete response and its tools under the
144
+ existing suspension and approval rules. Checkpoint before the next model call
145
+ when the turn still needs one.
146
+
147
+ ## Call records and usage
148
+
149
+ The [accounting amendment](../0002-AMENDMENT-accounting/SPEC.md) proposes the
150
+ additional evidence required for native billing-grade accounting.
151
+
152
+ Persist one summary per model call, linked to its turn, with one attempt
153
+ summary per provider attempt. Include stable IDs, timing, outcomes, retry
154
+ reason, provider request ID when available, and provider-reported usage.
155
+ Attribute reported usage to the attempt that incurred it, including failed or
156
+ cancelled attempts. Missing usage remains unknown. Aggregate reported usage
157
+ without counting an attempt twice.
158
+
159
+ Keep summaries available through the harness after restart, separate from the
160
+ conversation timeline. Reopening after a process crash reports unfinished
161
+ calls as interrupted and retains the summaries and usage already recorded.
162
+ If the successful model call committed before the crash, its outcome and
163
+ response remain successful even if its enclosing turn is interrupted.
164
+
165
+ The scripted adapter reserves its next step as part of the durable attempt
166
+ start for that channel. Every attempt advances the script once. A crash after
167
+ reservation consumes the step even if the adapter did not run it. Reopening
168
+ does not derive the script position from completed assistant replies.
169
+ Exact wire events, stored fields, and retrieval are part of the contract gate.
170
+
171
+ ## Acceptance
172
+
173
+ Use scripted attempts and deterministic barriers to verify the following:
174
+
175
+ 1. Streaming emits deltas under one ID and commits one completed reply with
176
+ that ID. Fragmented tool arguments reach the executor only as a complete,
177
+ permission-checked call. Scripted and non-streaming responses still work.
178
+ Messages mode emits no deltas and publishes completed text before any
179
+ tool dispatch from the same response.
180
+ 2. A transient failure before output can retry once using the same request.
181
+ Both attempts appear under one call. The shared deadline bounds the retry.
182
+ 3. A late failure after streamed text marks the reply incomplete, leaves no
183
+ completed timeline message for it, and does not retry or execute partial
184
+ tool calls. Both subscription modes make the same retry decision. An
185
+ explicit output limit has its own recorded reason.
186
+ 4. Interrupt cancels a stalled attempt or retry wait and fences late output.
187
+ Suspend lets the current iteration settle and resumes from its checkpoint.
188
+ A second channel can finish a turn while the first is waiting.
189
+ 5. Confirmed receipts and call summaries survive restart. Usage reported by a
190
+ failed attempt is counted once. Missing usage remains unknown.
191
+ 6. Crash on either side of the atomic success commit. Verify the call outcome
192
+ and timeline agree, the streaming client reconciles using the message ID,
193
+ and the scripted adapter continues from its reserved attempt position.
194
+ 7. With a slow reader, verify deltas are coalesced or dropped within bounds
195
+ while another channel can complete and commit. Recover dropped text from
196
+ completion. Fetch an oversized reply by ID in bounded reads in both modes.
197
+ Verify a fully blocked connection follows stop and recovery behavior.
198
+
199
+ Record the adapter and client event contracts, call summaries, and operational
200
+ defaults in a decision record before dependent code changes.