@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,168 @@
1
+ # acp-client integration contract
2
+
3
+ Date: 2026-11-20.
4
+ Status: proposed for review. See [PROTOCOL.md](PROTOCOL.md) for the wire contract
5
+ and [PLAN.md](PLAN.md) for implementation and verification.
6
+
7
+ ## Goal
8
+
9
+ Run two native conversations in acp-client against one real scripted harness
10
+ over stdio. Exercise durable acceptance, steering, tool approval, interruption,
11
+ and recovery without provider credentials. This establishes a boundary both
12
+ projects can build against.
13
+
14
+ Use the reviewed model-execution stack as the reference implementation
15
+ (`02c96de`, closure `49f2974`). Reuse lazy startup, shared process ownership,
16
+ offline channel changes, and turn correlation from the
17
+ [original acp-client integration design](../../../../../../.res/somelogs.md/11-11+/library/11-11-SPEC-native-harness-integration.md).
18
+ The first test covers the behaviors below. Host tool callbacks, broader
19
+ operator controls, and long-running mock scenarios extend it in later slices.
20
+
21
+ ## Ownership
22
+
23
+ | Component | Responsibility |
24
+ | --- | --- |
25
+ | acp-client | Launch and supervise the process, associate conversation IDs with channel IDs, keep prompt handles and application records, and present events to consumers. |
26
+ | Native harness | Own session and channel state, input acceptance and take, execution and permissions, and durable recovery. |
27
+ | Public harness client | Provide typed stdio requests, notifications, and connection failure. acp-client uses the public exports. |
28
+
29
+ The native adapter implements the reviewed `ConversationController` interface.
30
+ Bring that host work and the accepted harness stack onto one integration base
31
+ before implementing the adapter.
32
+
33
+ ### Controller behavior
34
+
35
+ Map `turn_started` and `turn_took` to `subscribeTurns()`. The harness
36
+ can produce output before acp-client attaches its supervisor. Buffer that
37
+ turn's early output and outcome until the supervisor subscribes and calls
38
+ the `prompt()` returned by `prepareTurn()`. Preparing the turn does not
39
+ start another inference. The harness's `turn_ended` settles that prepared
40
+ prompt. acp-client finalizes and publishes the conversation outcome once.
41
+
42
+ For a native conversation, `forceStop()` uses the targeted channel interrupt
43
+ for its active turn and settles that conversation's controller work. The
44
+ shared host owns process shutdown. Other channels retain their execution
45
+ and subscriptions.
46
+
47
+ The native controller reports `startFresh()` as unsupported and exposes
48
+ that limitation through the conversation capability surface. The controller
49
+ contract currently requires the method and has no dedicated reset capability.
50
+ Define the capability and unsupported outcome at the host adapter gate.
51
+ The call leaves the channel, session, and timeline unchanged.
52
+
53
+ One acp-client agent maps to one durable harness session. Each native
54
+ conversation maps to a stable channel ID within it. Creating or showing a
55
+ conversation can happen before launch. First work starts the process. Concurrent
56
+ sends for the same agent share the same startup rather than launching competing
57
+ owners. Use the host launcher with a configured harness home that survives
58
+ process restart.
59
+
60
+ All conversations on that session talk to the same agent. Opening a new
61
+ conversation gives it a new channel and leaves the entity and its shared
62
+ timeline intact. An agent-wide context reset and a channel context reset are
63
+ deferred. Retiring a channel preserves its timeline entries.
64
+
65
+ ## Startup and recovery
66
+
67
+ 1. Attach event handlers and initialize the public client over stdio.
68
+ 2. Load the existing session with the latest pending channel changes. Create it
69
+ on a confirmed missing-session response. Surface configuration,
70
+ compatibility, and ownership errors to the consumer.
71
+ 3. Reconcile the returned snapshot by channel, input, turn, and message IDs.
72
+ Buffer any live events received while applying that snapshot and merge them
73
+ afterward. The harness orders events from recovered work after the load
74
+ response. A revision is a snapshot boundary, and several events can share it.
75
+ 4. Report suspended channels and sessions as suspended. Loading does not itself
76
+ authorize resume.
77
+
78
+ ### Changes made while stopped
79
+
80
+ Keep the original `harness_pending` design. While the harness is down, acp-client
81
+ stores the latest desired channel name, policy, suspension, or deletion.
82
+ It submits the coalesced changes with `session/create` or `session/load`.
83
+ The harness applies them before pending work can run. acp-client clears a
84
+ change only when that exact version is confirmed, so an edit made during
85
+ startup stays pending.
86
+
87
+ The batch sent with open is the startup cutoff. Send edits made after that
88
+ cutoff through the live channel API as soon as open completes. Apply those
89
+ edits before submitting fresh host work to the affected channel. Recovered
90
+ work can start before a later edit reaches the harness. A suspension in the
91
+ open batch prevents that work from starting.
92
+
93
+ A policy change governs new input that inherits the channel policy.
94
+ Previously accepted inputs retain their resolved policies. To prevent
95
+ pending work from running on startup, suspend the channel in the startup
96
+ batch. A delete that finds pending input or a checkpoint leaves that channel
97
+ suspended and reports a conflict. The rest of the session can open. The user
98
+ can withdraw waiting input or resolve the checkpoint before retrying deletion.
99
+
100
+ Session configuration is fixed for an open session. Changes take effect
101
+ on the next open through the existing configuration resolution rules.
102
+
103
+ After a crash or disconnect, the host can reopen through the same flow. Accepted
104
+ but untaken input is still pending. Taken input belongs to its original turn.
105
+ The harness reports interrupted turns and any uncertain tool outcomes. The
106
+ host restores committed replies that it missed and does not automatically
107
+ repeat interrupted work. Live text deltas are provisional. A committed reply
108
+ with the same message ID replaces a local draft on reconnect.
109
+
110
+ ## Sending, approval, and interruption
111
+
112
+ Use the host's prompt record to save the stable input ID and exact payload
113
+ before calling `channel/push`. Distinguish a prompt waiting in the host queue
114
+ from a submission whose outcome is unknown. Only a receipt or reconciled
115
+ harness state confirms durable acceptance. After reopening, retry unresolved
116
+ submissions with the original ID and payload. Leave accepted, untaken inputs
117
+ pending and settle taken inputs from their owning turns.
118
+
119
+ | Harness fact | acp-client behavior |
120
+ | --- | --- |
121
+ | Push accepted | Mark the prompt handle accepted. Keep the ID and payload recorded before submission. |
122
+ | `turn_started` or `turn_took` | Associate all listed input IDs with that turn. Input may steer when taken by an active turn. Preserve the association even if the event arrives before the push response. |
123
+ | `message_completed` | Record the committed reply once by message ID. Fetch referenced text through the public client when it exceeds one frame. |
124
+ | Approval requested | Route the exact pending call to the conversation's approval handler. Respond by request ID with allow once or deny. A stale answer has no effect. |
125
+ | `turn_ended` or withdrawal | Settle the relevant prompt handles from the correlated outcome. A suspended turn remains pending until resumed or ended. |
126
+
127
+ An interrupt targets a specific channel and turn. The affected turn can end
128
+ while other channels continue. Send and turn completion remain separate.
129
+ acp-client can choose to delay submitting a prompt in its own queue. Once
130
+ submitted, the harness delivers it by its existing take rules. The first
131
+ integration uses channel suspension for explicit pauses. An expiring hold
132
+ can be revisited when a consumer operation needs it.
133
+
134
+ ## First end-to-end checkpoint
135
+
136
+ Use acp-client's public conversation interface and a real scripted stdio child:
137
+
138
+ 1. Open two conversations under one agent. Send concurrently and verify a
139
+ single process and durable session are shared.
140
+ 2. Send another input while one channel is working. Verify it is accepted and
141
+ then correlated to the turn that takes it. The other channel can finish
142
+ independently.
143
+ 3. Route an approval for an existing scripted tool through the consumer.
144
+ Verify approval dispatches that call once.
145
+ 4. Interrupt one active turn and verify the other channel keeps working.
146
+ Exercise this through conversation-level `forceStop()`. Send fresh input
147
+ on the interrupted channel.
148
+ 5. Lose the process or connection after a reply commits. Record a suspension
149
+ for one channel while the process is down. Reopen and verify the suspension
150
+ takes effect before that channel can run recovered work. Verify
151
+ the host restores that reply by ID, reconciles pending and interrupted input,
152
+ and continues on the same session without duplicating work or records.
153
+ 6. Lose the push response after the harness commits the input. Reopen from
154
+ the host's saved submission and verify that the same ID is accepted only
155
+ once. Separately lose the open response after channel changes commit and
156
+ verify that retrying open confirms the changes without duplicating work.
157
+
158
+ The broader integration checkpoint adds a consumer-registered callback and a
159
+ long-running mock run after those slices are available.
160
+
161
+ ## Decisions before implementation
162
+
163
+ - Confirm the launcher contract for native harness processes, the startup
164
+ deadline, and when acp-client retries a failed launch.
165
+ - Finalize the pending-change result shape in the protocol contract.
166
+ - Use the existing small-session load view for the first test. Define the
167
+ recovery page cursor and add bounded recovery before relying on
168
+ long-running mock sessions.
@@ -0,0 +1,111 @@
1
+ # Attachments and image input
2
+
3
+ Date: 2026-11-22
4
+
5
+ Status: Proposed for v1. Managed attachments and image input are the first
6
+ increment. The consumer-managed adapter follows on the same contract.
7
+
8
+ ## Ownership and scope
9
+
10
+ Use one attachment model for images and general files. The harness owns the
11
+ attachment identity, channel attribution, and association with a message.
12
+ The configured store owns the bytes. Select the store for the session at
13
+ open and keep the selection across reopen.
14
+
15
+ - By default, the harness keeps files under `media/<attachment-id>` in the
16
+ managed session directory. SQLite stores attachment ID, session and channel
17
+ ownership, original filename, media type, byte length, and SHA-256 digest.
18
+ The filename is display metadata. References identify immutable bytes.
19
+ - A consumer-managed session can use a store supplied by its host. acp-client
20
+ can adapt its existing media store through a public harness contract. The
21
+ host retains and serves the bytes across reconnect and restart. It registers
22
+ an opaque store reference linked to the harness-owned attachment ID. The
23
+ harness continues to work standalone with its default store.
24
+
25
+ Message parts in the inbox and timeline carry attachment IDs and preserve
26
+ their order alongside text. History, live events, and the inspector expose
27
+ references and metadata. Clients retrieve bytes separately when opening a file.
28
+
29
+ ## Prepare and send
30
+
31
+ 1. **Prepare the bytes.** Stage managed uploads in the session directory. Use
32
+ bounded transfers over stdio, borrowing the existing session-file transfer
33
+ mechanics for chunks, offsets, and digests. The standalone web server uses
34
+ the same attachment admission and finalization rules. Apply size and type
35
+ limits before making an attachment available.
36
+ 2. **Finalize.** Verify the declared length and digest and make the managed
37
+ file durable before recording it as ready. In consumer-managed mode the
38
+ host makes the copy durable before registering it. Registration is an
39
+ operation on the trusted host connection. The reference identifies bytes
40
+ the host has already committed and agreed to retain.
41
+ 3. **Send.** `channel/push` can carry ordered text and attachment-reference
42
+ parts, including an attachment-only message. Verify that each attachment
43
+ is ready and may be used by the sending channel. Commit its association
44
+ with the input as part of durable inbox acceptance before acknowledging
45
+ the message. Include the ordered parts in retry identity so the same input
46
+ ID can reuse its attachment IDs and a changed payload reports a conflict.
47
+
48
+ An interrupted upload or unreferenced finalized file can be reclaimed. Cleanup
49
+ must coordinate with message acceptance so it cannot remove a referenced
50
+ attachment. Always retain accepted attachment bytes, including after the turn
51
+ settles. The first version has one retention behavior for accepted attachments.
52
+
53
+ ## Read and present attachments
54
+
55
+ Resolve an attachment by ID through the configured store using the requesting
56
+ channel and the attachment's recorded ownership. Use the same visibility
57
+ boundary planned for [timeline retrieval](../../timeline-retrieval/0001-DESIGN/SPEC.md)
58
+ when applying conversation access policy. An ID identifies an attachment.
59
+ Authorization comes from the request's channel or trusted consumer scope.
60
+
61
+ Download retrieves bounded chunks. A missing file or disconnected consumer
62
+ store yields an explicit unavailable outcome while the message and metadata
63
+ remain readable. Verify size and digest when ingesting and when checking
64
+ integrity for relocation. Ordinary history paging does not load the bytes.
65
+
66
+ Image input is the first model-facing path. The context builder selects which
67
+ image references an inference needs and the provider adapter resolves those
68
+ bytes for an image-capable model. Advertise image input only when the configured
69
+ model path supports it. Give an explicit error for an unsupported image input.
70
+ Keep older images as references in shared history. Selection of older images
71
+ for reinjection belongs to bounded context. Keep image bytes out of persisted
72
+ provider diagnostics and ordinary history reads.
73
+
74
+ General files are first-class attachments. They use the same upload, storage,
75
+ and download path. Making a file available to a shell runner requires an
76
+ authorized handoff, including when it runs on a separate filesystem. The
77
+ [attachment tools](../../tools-and-callbacks/0003-DESIGN-attachment-tools/SPEC.md)
78
+ define that handoff. Document parsing and image generation are separate features.
79
+
80
+ ## Reopen, relocation, and outbound sharing
81
+
82
+ Reopen preserves the attachment IDs and message associations. A
83
+ consumer-managed session supplies the same store on reopen to resolve its
84
+ references. A complete `.harness` export packages retained bytes from either
85
+ store alongside the timeline. Fail explicitly if a retained file is unavailable
86
+ or the export exceeds its configured limit. Import validates and restores the
87
+ files before making the imported session available. A metadata-only export
88
+ would be a separate mode.
89
+
90
+ The outbound increment uses `share_attachment` to publish a runner file or
91
+ an existing attachment through the normal channel event path. The harness owns
92
+ the outgoing message and the selected store owns the bytes.
93
+
94
+ ## Acceptance
95
+
96
+ 1. Upload an image larger than one stdio frame, finalize it, and send it with
97
+ text. Verify ordered parts, stable IDs, idempotent retry, and history reads
98
+ that return metadata without loading bytes.
99
+ 2. Interrupt an upload and a publish attempt between file finalization and
100
+ message commit. Verify orphan cleanup and that reopening preserves the
101
+ bytes for every acknowledged message.
102
+ 3. Exercise image input through the standalone web chat with fake vision
103
+ inference. Verify a text-only model rejects image input explicitly. Upload
104
+ and download a general file through the same attachment contract.
105
+ 4. Export and import a managed session into a fresh home. Verify the metadata
106
+ and bytes, explicit failure for missing bytes or an oversized export, and
107
+ access checks on downloads by ID.
108
+ 5. For the consumer-managed increment, run the attachment contract through
109
+ acp-client's store. Verify reopen and export, the explicit unavailable
110
+ outcome when the host cannot resolve a file, and one harness-owned message
111
+ for each accepted input.
@@ -0,0 +1,129 @@
1
+ # Bounded context implementation plan
2
+
3
+ Date: 2026-11-23
4
+
5
+ Status: Gate 4 implements the inspector and end-to-end checkpoint.
6
+
7
+ ## Scope and base
8
+
9
+ Implement [SPEC.md](SPEC.md) inside the native harness. Record the exact `alpha`
10
+ revision at handoff and verify the code paths below against it. Follow the
11
+ [architecture](../../../../ARCHITECTURE.md) and [contribution rules](../../../../AGENTS.md).
12
+ The first end-to-end checkpoint uses existing text and notice inputs. Timeline
13
+ retrieval and image input extend it through their own specs.
14
+
15
+ ## Modules and ownership
16
+
17
+ Paths in this table are relative to the native harness package.
18
+
19
+ | Area | Existing code | Work |
20
+ | --- | --- | --- |
21
+ | Contracts | `src/contracts/context.ts`, `storage.ts`, `model-execution.ts` | Define the call-scoped context, the revisioned inference read, and the typed context-limit outcome. Reuse neutral messages and tool definitions. Pin the relationship between rendered input and the IDs used by model receipts and scripted playback. |
22
+ | Storage | `src/state/storage/engine.ts`, `sqlite.ts`, `memory.ts` | Implement one bounded inference read. Reuse turn and channel range indexes where they fit. Read active input, turn policy metadata, and local and shared history from one revision. Keep queries and index choices in storage. |
23
+ | Context | `src/capabilities/context/build.ts` | Evolve the current renderer into pure selection and assembly. Keep harness instructions here. Add the small session-scoped builder alongside it, with injected read and tool-selection dependencies. |
24
+ | Session assembly | `src/index.ts`, `src/kernel/loop.ts` | Create the builder at session open. Call it after taking eligible input. Replace the separate full snapshots used for prompt building, tool policy, and input IDs. Keep the kernel concerned with sequencing through contracts. |
25
+ | Model and tools | `src/capabilities/model/runner.ts`, `src/capabilities/tools/`, `src/governance/permissions/` | Pass a single assembled request to the existing runner. Reuse its retry snapshot and the registry's tool ordering. Recheck availability at dispatch through the existing gate. Provider encoding stays with the model adapter. |
26
+ | Input admission | `src/kernel/channels.ts`, `src/interfaces/protocol/`, `src/interfaces/cli/chat.ts`, development web chat | Enforce the text byte limit before durable acceptance. Surface the same limit for client preflight. Route all sends through the authoritative check. |
27
+ | Development observation | `src/interfaces/cli/development.ts`, `src/interfaces/inspector/` | Capture actual inference input in Gate 3. Use focused status, bounded session-wide preview, and paged timeline reads. Remove per-event full snapshots from both preview and status paths. |
28
+
29
+ ## Implementation gates
30
+
31
+ ### 1. Contract and budget rules
32
+
33
+ Review [decision 0026](../../../decisions/0026-bounded-context.md). It defines the
34
+ five logical parts, one-revision storage read, frozen request inputs, and
35
+ context-limit error. Pin what material must fit and where the builder can omit
36
+ an entire completed tool exchange. Capture the tool offer once for the request.
37
+ Keep dispatch authorization tied to all applicable taken input policies, even
38
+ when some material is trimmed from the prompt. Specify how the represented
39
+ input IDs feed delivery and Seen receipts, and preserve the scripted model's
40
+ boundary-scoped input IDs. A build rejected for size starts no model attempt.
41
+ It pins the published byte limit and rejection outcome at admission, how multiple
42
+ eligible inputs fit at a boundary, and how already-taken inputs settle on a
43
+ context-limit failure. Provider output enforcement remains open.
44
+
45
+ Review the initial defaults in [Business rules](../../BUSINESS_RULES.md), including
46
+ the input estimate, output reserve, record and byte read bounds, and allocation
47
+ between local and shared history. Review the decision and typecheck the contracts
48
+ before starting the storage implementation.
49
+
50
+ ### 2. Bounded storage read
51
+
52
+ Implement the inference read on SQLite and memory under shared conformance.
53
+ Read detached data at one committed revision and release the read before
54
+ rendering or provider work. Return enough information to detect when required
55
+ material exceeded its read budget. Inspect payload sizes before loading bodies.
56
+ Check row and byte bounds separately, including unusually large records and a
57
+ recent range dominated by one channel. Use query plans to check index use and
58
+ add indexes where the existing ones leave a gap.
59
+
60
+ Exercise a long timeline with a busy second channel. Verify adapter parity,
61
+ stable ordering, the correct active inputs and policy metadata, and bounded
62
+ results. Instrument the read path to detect calls to full snapshots and verify
63
+ the SQLite path avoids materializing the history to apply its limits.
64
+
65
+ ### 3. Inference integration
66
+
67
+ Create `SessionContext` in session assembly and wire one build into each
68
+ inference boundary. Pass selected inputs and the exact tool offer to the existing
69
+ model runner. Use focused reads for dispatch-time policy when a fresh check is
70
+ needed. Preserve provider reasoning state with the exchanges that require it.
71
+ Wire the input limit through harness admission and client preflight. Add a
72
+ minimal inference capture to the existing Channels tab for the first web-chat
73
+ exercise, with the revision, selected messages, tools, and trims.
74
+
75
+ Extend `test/context.test.ts` and the existing scripted request and model runner
76
+ tests. Check the five parts, provenance, local and shared allocation, trimming,
77
+ and whole call–result pairing. Exercise an over-budget required input, concurrent
78
+ channel notices, and a provider retry that receives the same request after
79
+ another channel commits. Verify newly taken input is represented before it can
80
+ be marked seen and that the captured context excludes later commits.
81
+
82
+ ### 4. Inspector and end-to-end checkpoint
83
+
84
+ Complete the inspector with lightweight pushed status, focused historical call
85
+ reads, and an on-demand paged Timeline. Build the bounded session-wide Live
86
+ Context preview on open or refresh. Coalesce change notifications and only
87
+ refresh while visible. On reconnect, reread status and the visible view. Respect
88
+ diagnostic capture controls and use image metadata in inspection. Instrument
89
+ both observer paths to check that events trigger no full-session snapshots.
90
+
91
+ Run a scripted two-channel scenario through real stdio with a long durable
92
+ timeline. Hold one inference while another channel sends a correction and makes
93
+ progress. Verify bounded assembly reads, the held request's revision, the next
94
+ build's view, explicit notice steering and wake, and continuity after reopen.
95
+ Exercise the same behavior in the development web chat and inspect the captured
96
+ requests. Record the initial allocation and any changes made from that exercise.
97
+ Run package typecheck and the harness suite, plus native integration regression
98
+ checks for the shared entry points. Update the architecture and usage docs with
99
+ the accepted behavior.
100
+
101
+ ## Scale evidence
102
+
103
+ Measure context storage reads, assembly, inspector work, and model-call bookkeeping separately
104
+ from provider wait time. The current model-call store reads and rewrites an
105
+ accumulated model-state record. This plan's scale gate proves bounded context
106
+ assembly. If bookkeeping still grows with session length, record that separately
107
+ with the measurements so it can be addressed in its owning design.
108
+
109
+
110
+ Gate 4 scale evidence uses 10,000 timeline entries over real stdio. A correction
111
+ commits on Bob's channel while Alice's inference is held. Alice's held request
112
+ keeps its older revision and the request after reopen sees the correction.
113
+ That checkpoint makes zero full-session snapshot reads. Paging and invalidation
114
+ are checked separately through the inspector HTTP interface. In Chrome, the
115
+ scripted development chat exercised a notice wake and Bob completing while
116
+ Alice waited for a dashboard tool. Alice's requests at revisions 44 and 60
117
+ showed the later correction entering only the continuation.
118
+
119
+ The reopen test exposed a record-allocation issue under a long local history.
120
+ Storage now reserves up to one third of the remaining record and byte budget
121
+ for recent shared records, with unused space returned to local records. The
122
+ request estimator, token reserves, and input limits kept their starting values.
123
+
124
+ An offline warm SQLite probe with 10,000 timeline entries and 5,000 mock model
125
+ calls measured medians of 1.56 ms for the inference read, 3.77 ms for assembly
126
+ with a preloaded read, and 2.33 ms for inspector status plus Live Context.
127
+ Fetching recent call summaries took 5.26 ms. Starting and closing a model
128
+ call took 65.02 ms together, including durable writes. These are local
129
+ measurements with no model or network wait.
@@ -0,0 +1,135 @@
1
+ # Bounded inference context
2
+
3
+ Date: 2026-11-23
4
+
5
+ Status: Proposed for M2 and the v1 harness. Start with bounded selection and
6
+ refine allocation and rendering through scripted and interactive tests.
7
+ See [PLAN.md](PLAN.md) for module ownership and implementation gates.
8
+
9
+ ## Session ownership and read boundary
10
+
11
+ Create one in-process `SessionContext` when the harness opens a session. It
12
+ uses the existing durable session store, session configuration, and tool
13
+ registry. All native channels use the same builder. The timeline is the
14
+ authoritative history, including after restart.
15
+
16
+ After taking input at an inference boundary, the turn runner calls
17
+ `build({ channelId, turnId })`. The context module reads a bounded view through
18
+ the storage contract at one committed timeline revision. Capture configuration
19
+ and tool definitions for that build as well. Release the storage read before
20
+ rendering, loading image bytes, or calling the model. Selection and rendering
21
+ belong in the context module. Provider encoding belongs in the model adapter.
22
+
23
+ The build returns an immutable inference context with the session, channel,
24
+ turn, and read revision, plus the ordered messages and offered tools. Freeze
25
+ the request inputs for retries of the same inference. Later iterations build
26
+ fresh views. Channels may infer concurrently from different revisions of the
27
+ same session. A committed change is eligible for later reads. An explicit
28
+ channel notice reaches the target through the existing take or wake behavior.
29
+
30
+ Use indexed reads for inference assembly. Bound both record count and bytes
31
+ read, including reads for active input and applicable tool policy. Check payload
32
+ sizes before loading message bodies. Search for shared history within a bounded
33
+ recent range. Return fewer shared entries when that range is dominated by the
34
+ current channel. Opening a
35
+ session recovers its durable state. The builder reads conversation material
36
+ on demand and can reconstruct the next context from the same timeline after
37
+ reopen. Assembled contexts are call-scoped values.
38
+
39
+ ## Request structure
40
+
41
+ | Part | Content |
42
+ | --- | --- |
43
+ | Agent instructions | The consumer's configured system prompt, preserved verbatim. |
44
+ | Harness instructions | A short, stable explanation of how to interpret attributed history and active input. Tool-specific usage guidance lives with the tool definitions. |
45
+ | Current conversation | The current channel and the origin of the turn. Attribute each active input separately so steering from several participants stays clear. |
46
+ | Selected history | Recent messages from the current channel and a smaller window of earlier activity from other channels. Preserve source attribution. Render selected records in timeline order as historical data. |
47
+ | Active turn | The triggering input, taken steering and notices, and the assistant and tool exchanges still needed for inference. Preserve native call and result pairing. |
48
+
49
+ The first two parts form the system prompt. The next three form the
50
+ conversation input. Offered tool definitions travel alongside the messages in
51
+ the provider's tool field and count toward the budget. An entry appears once
52
+ per request. In particular, active-turn entries are excluded from history.
53
+
54
+ With [image input](../../attachments/0001-DESIGN/SPEC.md), include selected
55
+ images as parts of their active messages when the model supports them. Keep
56
+ older attachments and general files as references. Follow the
57
+ [timeline retrieval contract](../../timeline-retrieval/0001-DESIGN/SPEC.md)
58
+ for access to older messages and for keeping saved retrieval exchanges out of
59
+ later shared context.
60
+
61
+ V1 shares native history across the session and offers no cross-channel
62
+ privacy guarantee. Attribution remains available for interpretation, queries,
63
+ and future policy work. Shared identity outside the harness is deferred.
64
+
65
+ ## Budget and selection
66
+
67
+ Enforce a published per-message UTF-8 byte limit before durable input acceptance.
68
+ The harness is authoritative. The development web chat and REPL preflight against
69
+ the same limit. An oversized submission is rejected before any inbox or timeline
70
+ write and receives no `Received` receipt. Take an ordered prefix within the
71
+ intake limits at each inference boundary and leave any suffix pending. If
72
+ already-taken required material cannot fit, fail with `context_limit` before
73
+ inference. Taken items remain linked to the failed turn and keep their existing
74
+ receipt milestones. See [decision 0026](../../../decisions/0026-bounded-context.md)
75
+ for receipt, policy, and compatibility details.
76
+
77
+ 1. Start with the configured model context limit. Reserve space for output
78
+ and estimation error. Estimate the input cost of instructions, tool
79
+ schemas, active messages, and selected images. Provider enforcement of the
80
+ output reserve remains a separate decision.
81
+ 2. Allocate remaining space to history. Give the current channel priority
82
+ for continuity and reserve a smaller share for recent shared activity.
83
+ Allow unused space to be borrowed. Under pressure, remove the oldest
84
+ shared entries first, then the oldest local entries. The original
85
+ timeline remains available to retrieval tools.
86
+ 3. Bound large tool results when presenting them to the model. If a long
87
+ turn needs further trimming, omit older completed exchanges as whole
88
+ units where provider rules permit. Preserve the current input, newly
89
+ taken steering and notices, and exchanges required for continuation.
90
+ Return a typed context-limit error if the required material cannot fit.
91
+
92
+ Use a conservative estimator for v1 and keep storage read limits independent
93
+ of the model budget. Start with the defaults in
94
+ [Business rules](../../BUSINESS_RULES.md) and tune them during testing.
95
+ Automatic summaries and persisted assembled context can be evaluated after
96
+ testing bounded selection.
97
+
98
+ ## Inspection and acceptance
99
+
100
+ Keep the development inspector's existing three tabs:
101
+
102
+ - **Live Context** shows a bounded session-wide preview. Fetch it on opening or
103
+ refreshing the tab. Push a change notification and coalesce refreshes while
104
+ the tab is visible. A hidden tab stays dirty until opened.
105
+ - **Timeline** loads a bounded latest page on demand and pages older records
106
+ separately. Committed entries can update the visible page incrementally.
107
+ - **Channels** updates lightweight working status from events. With capture
108
+ enabled, show the five parts, offered tools, read revision, estimated input
109
+ size, and trimming decisions from the inference itself. Use attachment
110
+ metadata in place of large binary payloads. Follow diagnostic capture controls
111
+ and fetch historical call details on demand.
112
+
113
+ On reconnect, refresh status and the visible view. Events and tab refreshes use
114
+ incremental updates or focused reads. The inspector's status and preview paths
115
+ both need to avoid full-session snapshots on every event.
116
+
117
+ 1. Overlap inference across channels on a long session. Verify that one
118
+ channel's activity leaves room for another channel's recent conversation.
119
+ Assert bounded inference-path reads, including large records, and record
120
+ assembly latency separately from provider latency. Verify a dominant channel
121
+ cannot make the shared history read walk the full timeline.
122
+ 2. Commit a correction while another channel's inference runs. Verify that
123
+ the running request stays fixed and that the later view can see the
124
+ correction. Exercise explicit notice steering and wake through the same
125
+ inference boundaries.
126
+ 3. Verify oversized input is refused before acceptance in the harness and
127
+ preflighted in web chat and REPL. Exercise an oversized active turn and verify
128
+ output reservation, trimming,
129
+ intact tool pairing, and a typed error when required content cannot fit.
130
+ Verify retries use the original request inputs.
131
+ 4. Reopen the session and build from the restored timeline. With timeline
132
+ retrieval available, recover an earlier decision outside the selected
133
+ window. Exercise the scenarios in the web chat and inspect the captured
134
+ requests to refine allocation and rendering. Verify hidden tabs perform no
135
+ event-driven preview reads and reconnect refreshes the visible data.