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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (467) hide show
  1. package/CHANGELOG-consumer-fixes.md +17 -10
  2. package/CHANGELOG-controller-interface.md +258 -0
  3. package/CHANGELOG-metering.md +29 -0
  4. package/CHANGELOG-operation-lifecycle.md +15 -1
  5. package/CONSUMER_GUIDE.md +845 -6
  6. package/MIGRATION-0.10-to-0.12.md +4 -1
  7. package/MIGRATION-0.12-to-0.13.md +275 -0
  8. package/README.md +17 -16
  9. package/package.json +4 -2
  10. package/src/acp-client-handlers.ts +48 -0
  11. package/src/activity.ts +3 -0
  12. package/src/adapters.ts +25 -0
  13. package/src/agent/adoption/provider-attachment.ts +33 -0
  14. package/src/agent/adoption/provider-session-delete.ts +1 -1
  15. package/src/agent/adoption/provider-sessions.ts +3 -2
  16. package/src/agent/append-assistant-message.ts +91 -0
  17. package/src/agent/config.ts +54 -6
  18. package/src/agent/conversation-manager.ts +94 -158
  19. package/src/agent/manager-settings.ts +1 -0
  20. package/src/agent/native-channel-lifecycle.ts +111 -0
  21. package/src/agent/persisted-lifecycle.ts +44 -4
  22. package/src/agent/persistence-policy/context.ts +13 -0
  23. package/src/agent/persistence-policy/resolver.ts +7 -0
  24. package/src/agent/persistence-policy/types.ts +1 -0
  25. package/src/agent/record-capture.ts +1 -0
  26. package/src/agent-adapter-registry.ts +33 -7
  27. package/src/agent-conversation-contracts.ts +14 -1
  28. package/src/agent-conversation-errors.ts +8 -0
  29. package/src/agent-conversation-owner.ts +9 -4
  30. package/src/agent-session-config.ts +135 -0
  31. package/src/agent-session.ts +439 -934
  32. package/src/agent.ts +73 -0
  33. package/src/capabilities.ts +2 -0
  34. package/src/checkpointing/recovery.ts +3 -0
  35. package/src/cli/index.ts +3 -3
  36. package/src/cli/managed.ts +2 -2
  37. package/src/client.ts +52 -94
  38. package/src/connection-attempt.ts +95 -0
  39. package/src/controller-connection.ts +114 -0
  40. package/src/controller.ts +156 -148
  41. package/src/conversation-controller/capabilities.ts +88 -0
  42. package/src/conversation-controller/contracts.ts +208 -0
  43. package/src/conversation-controller/factory.ts +39 -0
  44. package/src/conversation-controller/guards.ts +98 -0
  45. package/src/conversation-controller/index.ts +20 -0
  46. package/src/conversation-startup.ts +35 -0
  47. package/src/conversation-turns/backend-turns.ts +373 -0
  48. package/src/conversation-turns/clear-operations.ts +37 -0
  49. package/src/conversation-turns/context.ts +135 -0
  50. package/src/conversation-turns/index.ts +4 -0
  51. package/src/conversation-turns/record-helpers.ts +75 -0
  52. package/src/conversation-turns/recording.ts +235 -0
  53. package/src/conversation-turns/run-turn.ts +367 -0
  54. package/src/conversation-turns/turn-run.ts +57 -0
  55. package/src/errors.ts +41 -0
  56. package/src/handoff-options.ts +81 -0
  57. package/src/identity/checkpoint-backed.ts +1 -1
  58. package/src/index.ts +58 -3
  59. package/src/internal-inference/coordination/manager.ts +11 -0
  60. package/src/internal-inference/runtime/harness-runtime.ts +4 -4
  61. package/src/launcher.ts +35 -2
  62. package/src/media/parts.ts +5 -0
  63. package/src/message-status.ts +83 -0
  64. package/src/metering/engine.ts +39 -64
  65. package/src/metering/measurement-provenance.ts +36 -0
  66. package/src/metering/native/durability.ts +115 -0
  67. package/src/metering/native/ledger.ts +104 -0
  68. package/src/metering/native/operation.ts +85 -0
  69. package/src/metering/native/projection.ts +114 -0
  70. package/src/metering/native/proof.ts +51 -0
  71. package/src/metering/native/requirements.ts +10 -0
  72. package/src/metering/native/retirement.ts +92 -0
  73. package/src/metering/native/source.ts +90 -0
  74. package/src/metering/record.ts +38 -1
  75. package/src/metering/state.ts +13 -3
  76. package/src/native/approvals.ts +169 -0
  77. package/src/native/capabilities.ts +17 -0
  78. package/src/native/channel-changes.ts +211 -0
  79. package/src/native/connection.ts +56 -0
  80. package/src/native/controller.ts +591 -0
  81. package/src/native/delegation-sender.ts +26 -0
  82. package/src/native/errors.ts +35 -0
  83. package/src/native/functions.ts +156 -0
  84. package/src/native/host-config.ts +59 -0
  85. package/src/native/host.ts +909 -0
  86. package/src/native/item-receipts.ts +15 -0
  87. package/src/native/metering.ts +12 -0
  88. package/src/native/records.ts +166 -0
  89. package/src/native/recovery.ts +186 -0
  90. package/src/native/reminders/fixtures/schema21.sqlite.gz +0 -0
  91. package/src/native/reminders/idle.ts +70 -0
  92. package/src/native/reminders/limits.ts +19 -0
  93. package/src/native/reminders/notifications.ts +29 -0
  94. package/src/native/reminders/reminders.test.ts +553 -0
  95. package/src/native/reminders/routine-config.typecheck.ts +13 -0
  96. package/src/native/reminders/routine-guard.ts +66 -0
  97. package/src/native/reminders/routine-schedule.ts +25 -0
  98. package/src/native/reminders/routine-wire.ts +21 -0
  99. package/src/native/reminders/schedule.ts +97 -0
  100. package/src/native/reminders/service.ts +280 -0
  101. package/src/native/reminders/supervisor.ts +91 -0
  102. package/src/native/reminders/sync.ts +301 -0
  103. package/src/native/reminders/wire.ts +197 -0
  104. package/src/native/reminders/wire.typecheck.ts +13 -0
  105. package/src/native/submission-withdrawal.ts +65 -0
  106. package/src/native/usage.ts +15 -0
  107. package/src/native/worker-delivery.ts +61 -0
  108. package/src/native-harness/.res/README.md +1 -0
  109. package/src/native-harness/.res/architecture/README.md +21 -0
  110. package/src/native-harness/.res/architecture/context-and-data.md +31 -0
  111. package/src/native-harness/.res/architecture/execution.md +42 -0
  112. package/src/native-harness/.res/architecture/overview.md +44 -0
  113. package/src/native-harness/.res/architecture/persistence.md +56 -0
  114. package/src/native-harness/.res/architecture/suspend-and-resume.md +45 -0
  115. package/src/native-harness/.res/architecture/technical-architecture.md +50 -0
  116. package/src/native-harness/.res/decisions/0001-basic-loop.md +11 -0
  117. package/src/native-harness/.res/decisions/0002-channel-input.md +17 -0
  118. package/src/native-harness/.res/decisions/0003-inference-inspection.md +14 -0
  119. package/src/native-harness/.res/decisions/0004-shared-context.md +21 -0
  120. package/src/native-harness/.res/decisions/0005-notice-inbox.md +20 -0
  121. package/src/native-harness/.res/decisions/0006-explicit-notices.md +12 -0
  122. package/src/native-harness/.res/decisions/0007-channel-output.md +12 -0
  123. package/src/native-harness/.res/decisions/0008-browser-client.md +16 -0
  124. package/src/native-harness/.res/decisions/0009-scripted-model.md +18 -0
  125. package/src/native-harness/.res/decisions/0010-inprocess-protocol.md +19 -0
  126. package/src/native-harness/.res/decisions/0011-stdio-transport.md +21 -0
  127. package/src/native-harness/.res/decisions/0012-session-storage-contract.md +37 -0
  128. package/src/native-harness/.res/decisions/0013-durable-delivery-contract.md +64 -0
  129. package/src/native-harness/.res/decisions/0014-channel-controls-contract.md +73 -0
  130. package/src/native-harness/.res/decisions/0015-session-file-contract.md +72 -0
  131. package/src/native-harness/.res/decisions/0016-configuration-permissions.md +159 -0
  132. package/src/native-harness/.res/decisions/0017-openrouter-managed-config.md +69 -0
  133. package/src/native-harness/.res/decisions/0018-tool-dispatch-evidence.md +78 -0
  134. package/src/native-harness/.res/decisions/0019-model-execution.md +188 -0
  135. package/src/native-harness/.res/decisions/0020-startup-channel-changes.md +71 -0
  136. package/src/native-harness/.res/decisions/0021-tools-and-host-callbacks.md +100 -0
  137. package/src/native-harness/.res/decisions/0022-operator-controls.md +115 -0
  138. package/src/native-harness/.res/decisions/0023-long-running-mock.md +82 -0
  139. package/src/native-harness/.res/decisions/0024-callback-policy-names.md +46 -0
  140. package/src/native-harness/.res/decisions/0025-external-notices.md +364 -0
  141. package/src/native-harness/.res/decisions/0026-bounded-context.md +81 -0
  142. package/src/native-harness/.res/decisions/0027-development-instructions.md +22 -0
  143. package/src/native-harness/.res/decisions/0028-debug-tools.md +16 -0
  144. package/src/native-harness/.res/decisions/0029-bounded-model-call-pages.md +37 -0
  145. package/src/native-harness/.res/decisions/0030-timeline-retrieval.md +145 -0
  146. package/src/native-harness/.res/decisions/0031-one-off-reminders.md +173 -0
  147. package/src/native-harness/.res/docs/11-15.md +148 -0
  148. package/src/native-harness/.res/docs/BUSINESS_RULES.md +111 -0
  149. package/src/native-harness/.res/docs/WORK.md +65 -0
  150. package/src/native-harness/.res/docs/_/11-16-persistence/LOG.md +312 -0
  151. package/src/native-harness/.res/docs/_/11-16-persistence/PLAN.md +77 -0
  152. package/src/native-harness/.res/docs/_/11-16-persistence/SPEC.md +313 -0
  153. package/src/native-harness/.res/docs/_/11-19-channel-controls/LOG.md +160 -0
  154. package/src/native-harness/.res/docs/_/11-19-channel-controls/PLAN.md +89 -0
  155. package/src/native-harness/.res/docs/_/11-19-channel-controls/SPEC.md +135 -0
  156. package/src/native-harness/.res/docs/_/11-19-config-permissions/LOG.md +143 -0
  157. package/src/native-harness/.res/docs/_/11-19-config-permissions/PLAN.md +93 -0
  158. package/src/native-harness/.res/docs/_/11-19-config-permissions/SPEC.md +181 -0
  159. package/src/native-harness/.res/docs/acp-client-integration/0001-DESIGN/11-20-LOG.md +433 -0
  160. package/src/native-harness/.res/docs/acp-client-integration/0001-DESIGN/PLAN.md +60 -0
  161. package/src/native-harness/.res/docs/acp-client-integration/0001-DESIGN/PROTOCOL.md +141 -0
  162. package/src/native-harness/.res/docs/acp-client-integration/0001-DESIGN/SPEC.md +168 -0
  163. package/src/native-harness/.res/docs/attachments/0001-DESIGN/SPEC.md +111 -0
  164. package/src/native-harness/.res/docs/bounded-context/0001-DESIGN/PLAN.md +129 -0
  165. package/src/native-harness/.res/docs/bounded-context/0001-DESIGN/SPEC.md +135 -0
  166. package/src/native-harness/.res/docs/channel-messaging/0001-DESIGN-external-notices/LOG.md +437 -0
  167. package/src/native-harness/.res/docs/channel-messaging/0001-DESIGN-external-notices/PLAN.md +127 -0
  168. package/src/native-harness/.res/docs/channel-messaging/0001-DESIGN-external-notices/SPEC.md +203 -0
  169. package/src/native-harness/.res/docs/long-running-mock/0001-DESIGN/LOG.md +292 -0
  170. package/src/native-harness/.res/docs/long-running-mock/0001-DESIGN/PLAN.md +91 -0
  171. package/src/native-harness/.res/docs/long-running-mock/0001-DESIGN/SPEC.md +187 -0
  172. package/src/native-harness/.res/docs/model-execution/0001-DESIGN/LOG.md +148 -0
  173. package/src/native-harness/.res/docs/model-execution/0001-DESIGN/PLAN.md +95 -0
  174. package/src/native-harness/.res/docs/model-execution/0001-DESIGN/SPEC.md +200 -0
  175. package/src/native-harness/.res/docs/model-execution/0002-AMENDMENT-accounting/SPEC.md +80 -0
  176. package/src/native-harness/.res/docs/operator-controls/0001-DESIGN/LOG.md +206 -0
  177. package/src/native-harness/.res/docs/operator-controls/0001-DESIGN/PLAN.md +106 -0
  178. package/src/native-harness/.res/docs/operator-controls/0001-DESIGN/SPEC.md +297 -0
  179. package/src/native-harness/.res/docs/persistence/0002-AMENDMENT-session-file/LOG.md +41 -0
  180. package/src/native-harness/.res/docs/persistence/0002-AMENDMENT-session-file/PLAN.md +36 -0
  181. package/src/native-harness/.res/docs/persistence/0002-AMENDMENT-session-file/SPEC.md +84 -0
  182. package/src/native-harness/.res/docs/shell-execution/0001-DESIGN/SPEC.md +147 -0
  183. package/src/native-harness/.res/docs/timeline-retrieval/0001-DESIGN/LOG.md +15 -0
  184. package/src/native-harness/.res/docs/timeline-retrieval/0001-DESIGN/PLAN.md +107 -0
  185. package/src/native-harness/.res/docs/timeline-retrieval/0001-DESIGN/SPEC.md +114 -0
  186. package/src/native-harness/.res/docs/todos/11-19-TODO-auto_review-approve.md +24 -0
  187. package/src/native-harness/.res/docs/todos/11-20-TODO-user-entered-tool-code.md +23 -0
  188. package/src/native-harness/.res/docs/todos/11-21-TODO-node-resource-coordination.md +103 -0
  189. package/src/native-harness/.res/docs/todos/11-22-TODO-harness-m1-sequence.md +50 -0
  190. package/src/native-harness/.res/docs/tools-and-callbacks/0001-DESIGN/LOG.md +337 -0
  191. package/src/native-harness/.res/docs/tools-and-callbacks/0001-DESIGN/PLAN.md +76 -0
  192. package/src/native-harness/.res/docs/tools-and-callbacks/0001-DESIGN/SPEC.md +204 -0
  193. package/src/native-harness/.res/docs/tools-and-callbacks/0002-AMENDMENT-callback-policy/LOG.md +73 -0
  194. package/src/native-harness/.res/docs/tools-and-callbacks/0002-AMENDMENT-callback-policy/SPEC.md +64 -0
  195. package/src/native-harness/.res/docs/tools-and-callbacks/0003-DESIGN-attachment-tools/SPEC.md +58 -0
  196. package/src/native-harness/.res/docs/tools-and-callbacks/0004-DESIGN-reminder-tools/LOG.md +45 -0
  197. package/src/native-harness/.res/docs/tools-and-callbacks/0004-DESIGN-reminder-tools/PLAN.md +108 -0
  198. package/src/native-harness/.res/docs/tools-and-callbacks/0004-DESIGN-reminder-tools/SPEC.md +169 -0
  199. package/src/native-harness/.res/docs/web-tools/0001-DESIGN/SPEC.md +128 -0
  200. package/src/native-harness/.res/marketing-draft.md +22 -0
  201. package/src/native-harness/.res/sandbox/1-simple-harness/README.md +285 -0
  202. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-1.md +19 -0
  203. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-10.md +138 -0
  204. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-11.md +148 -0
  205. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-12.md +172 -0
  206. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-13.md +194 -0
  207. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-14.md +233 -0
  208. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-15.md +249 -0
  209. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-16.md +265 -0
  210. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-17.md +279 -0
  211. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-18.md +293 -0
  212. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-19.md +307 -0
  213. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-2.md +29 -0
  214. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-20.md +317 -0
  215. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-21.md +327 -0
  216. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-3.md +40 -0
  217. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-4.md +59 -0
  218. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-5.md +69 -0
  219. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-6.md +79 -0
  220. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-7.md +89 -0
  221. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-8.md +102 -0
  222. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-9.md +116 -0
  223. package/src/native-harness/.res/sandbox/1-simple-harness/conversation.jsonl +49 -0
  224. package/src/native-harness/.res/sandbox/1-simple-harness/doc.md +87 -0
  225. package/src/native-harness/.res/sandbox/1-simple-harness/harness.py +289 -0
  226. package/src/native-harness/.res/sandbox/1-simple-harness/local/harness copy 2.py +221 -0
  227. package/src/native-harness/.res/sandbox/1-simple-harness/local/harness copy 3.py +287 -0
  228. package/src/native-harness/.res/sandbox/1-simple-harness/local/harness copy.py +165 -0
  229. package/src/native-harness/.res/sandbox/1-simple-harness/state.json +22 -0
  230. package/src/native-harness/.res/sandbox/1-simple-harness/system-prompt.md +2 -0
  231. package/src/native-harness/AGENTS.md +70 -0
  232. package/src/native-harness/ARCHITECTURE.md +249 -0
  233. package/src/native-harness/README.md +726 -0
  234. package/src/native-harness/bun.lock +26 -0
  235. package/src/native-harness/package.json +24 -0
  236. package/src/native-harness/src/capabilities/context/build.ts +59 -0
  237. package/src/native-harness/src/capabilities/context/instructions/agent-demo.md +11 -0
  238. package/src/native-harness/src/capabilities/context/instructions/agent.md +5 -0
  239. package/src/native-harness/src/capabilities/context/instructions/harness.md +7 -0
  240. package/src/native-harness/src/capabilities/context/load-instructions.ts +22 -0
  241. package/src/native-harness/src/capabilities/context/session.ts +92 -0
  242. package/src/native-harness/src/capabilities/model/attempt.ts +27 -0
  243. package/src/native-harness/src/capabilities/model/openrouter-stream.ts +72 -0
  244. package/src/native-harness/src/capabilities/model/openrouter.ts +62 -0
  245. package/src/native-harness/src/capabilities/model/runner.ts +116 -0
  246. package/src/native-harness/src/capabilities/model/scenario-attempt.ts +50 -0
  247. package/src/native-harness/src/capabilities/model/scenario-file.ts +125 -0
  248. package/src/native-harness/src/capabilities/model/scripted-error.ts +6 -0
  249. package/src/native-harness/src/capabilities/model/scripted.ts +81 -0
  250. package/src/native-harness/src/capabilities/model/usage.ts +15 -0
  251. package/src/native-harness/src/capabilities/tools/builtin/current-time.ts +28 -0
  252. package/src/native-harness/src/capabilities/tools/builtin/notify-channel.ts +17 -0
  253. package/src/native-harness/src/capabilities/tools/debug/index.ts +13 -0
  254. package/src/native-harness/src/capabilities/tools/debug/result.ts +12 -0
  255. package/src/native-harness/src/capabilities/tools/debug/test-echo.ts +16 -0
  256. package/src/native-harness/src/capabilities/tools/debug/test-fail.ts +14 -0
  257. package/src/native-harness/src/capabilities/tools/debug/test-wait.ts +19 -0
  258. package/src/native-harness/src/capabilities/tools/reminders/index.ts +75 -0
  259. package/src/native-harness/src/capabilities/tools/runtime/catalog.ts +103 -0
  260. package/src/native-harness/src/capabilities/tools/runtime/functions.ts +130 -0
  261. package/src/native-harness/src/capabilities/tools/runtime/invocations.ts +48 -0
  262. package/src/native-harness/src/capabilities/tools/testing/echo.ts +18 -0
  263. package/src/native-harness/src/capabilities/tools/testing/record.ts +47 -0
  264. package/src/native-harness/src/capabilities/tools/timeline/index.ts +41 -0
  265. package/src/native-harness/src/client.ts +18 -0
  266. package/src/native-harness/src/contracts/agent.ts +105 -0
  267. package/src/native-harness/src/contracts/config-permissions.ts +47 -0
  268. package/src/native-harness/src/contracts/context.ts +112 -0
  269. package/src/native-harness/src/contracts/events.ts +47 -0
  270. package/src/native-harness/src/contracts/input-limits.ts +7 -0
  271. package/src/native-harness/src/contracts/inspection.ts +22 -0
  272. package/src/native-harness/src/contracts/loop.ts +31 -0
  273. package/src/native-harness/src/contracts/model-execution.ts +83 -0
  274. package/src/native-harness/src/contracts/operator-controls.ts +106 -0
  275. package/src/native-harness/src/contracts/output.ts +13 -0
  276. package/src/native-harness/src/contracts/protocol.ts +320 -0
  277. package/src/native-harness/src/contracts/reminders.ts +132 -0
  278. package/src/native-harness/src/contracts/scenario.ts +42 -0
  279. package/src/native-harness/src/contracts/session-file.ts +19 -0
  280. package/src/native-harness/src/contracts/session.ts +184 -0
  281. package/src/native-harness/src/contracts/storage.ts +596 -0
  282. package/src/native-harness/src/contracts/timeline-retrieval.ts +40 -0
  283. package/src/native-harness/src/contracts/tools.ts +133 -0
  284. package/src/native-harness/src/governance/permissions/gate.ts +129 -0
  285. package/src/native-harness/src/governance/policy/resolve.ts +32 -0
  286. package/src/native-harness/src/index.ts +318 -0
  287. package/src/native-harness/src/interfaces/cli/chat.ts +83 -0
  288. package/src/native-harness/src/interfaces/cli/development.ts +145 -0
  289. package/src/native-harness/src/interfaces/cli/format-reply.ts +27 -0
  290. package/src/native-harness/src/interfaces/cli/listeners.ts +74 -0
  291. package/src/native-harness/src/interfaces/cli/main.ts +47 -0
  292. package/src/native-harness/src/interfaces/cli/scenario.ts +37 -0
  293. package/src/native-harness/src/interfaces/cli/serve.ts +21 -0
  294. package/src/native-harness/src/interfaces/cli/start.ts +106 -0
  295. package/src/native-harness/src/interfaces/client.ts +225 -0
  296. package/src/native-harness/src/interfaces/inspector/index.html +283 -0
  297. package/src/native-harness/src/interfaces/inspector/observe.ts +35 -0
  298. package/src/native-harness/src/interfaces/inspector/server.ts +56 -0
  299. package/src/native-harness/src/interfaces/inspector/state.ts +92 -0
  300. package/src/native-harness/src/interfaces/protocol/channel-changes.ts +153 -0
  301. package/src/native-harness/src/interfaces/protocol/framing.ts +47 -0
  302. package/src/native-harness/src/interfaces/protocol/functions.ts +87 -0
  303. package/src/native-harness/src/interfaces/protocol/in-process.ts +67 -0
  304. package/src/native-harness/src/interfaces/protocol/live-queue.ts +55 -0
  305. package/src/native-harness/src/interfaces/protocol/load.ts +60 -0
  306. package/src/native-harness/src/interfaces/protocol/local.ts +120 -0
  307. package/src/native-harness/src/interfaces/protocol/operator.ts +120 -0
  308. package/src/native-harness/src/interfaces/protocol/output.ts +59 -0
  309. package/src/native-harness/src/interfaces/protocol/server.ts +517 -0
  310. package/src/native-harness/src/interfaces/protocol/stdio-client.ts +119 -0
  311. package/src/native-harness/src/interfaces/protocol/stdio-server.ts +82 -0
  312. package/src/native-harness/src/interfaces/protocol/subscribe.ts +41 -0
  313. package/src/native-harness/src/interfaces/protocol/transfers.ts +146 -0
  314. package/src/native-harness/src/interfaces/web-chat/index.html +94 -0
  315. package/src/native-harness/src/interfaces/web-chat/server.ts +34 -0
  316. package/src/native-harness/src/kernel/channels.ts +405 -0
  317. package/src/native-harness/src/kernel/loop.ts +45 -0
  318. package/src/native-harness/src/runtime/config/development.ts +23 -0
  319. package/src/native-harness/src/runtime/config/managed.ts +2 -0
  320. package/src/native-harness/src/runtime/config/paths.ts +27 -0
  321. package/src/native-harness/src/runtime/reminder-timer.ts +42 -0
  322. package/src/native-harness/src/runtime/reminder-validation.ts +104 -0
  323. package/src/native-harness/src/runtime/reminders.ts +66 -0
  324. package/src/native-harness/src/state/storage/archive.ts +239 -0
  325. package/src/native-harness/src/state/storage/engine.ts +1013 -0
  326. package/src/native-harness/src/state/storage/inference.ts +124 -0
  327. package/src/native-harness/src/state/storage/memory-reminders.ts +78 -0
  328. package/src/native-harness/src/state/storage/memory.ts +341 -0
  329. package/src/native-harness/src/state/storage/policy-metadata.ts +32 -0
  330. package/src/native-harness/src/state/storage/reminder-archive.ts +63 -0
  331. package/src/native-harness/src/state/storage/reminder-change.ts +92 -0
  332. package/src/native-harness/src/state/storage/reminder-tables.ts +27 -0
  333. package/src/native-harness/src/state/storage/retrieval.ts +122 -0
  334. package/src/native-harness/src/state/storage/script-identity.ts +7 -0
  335. package/src/native-harness/src/state/storage/session-file.ts +85 -0
  336. package/src/native-harness/src/state/storage/sqlite-reminders.ts +134 -0
  337. package/src/native-harness/src/state/storage/sqlite.ts +625 -0
  338. package/src/native-harness/src/testing.ts +190 -0
  339. package/src/native-harness/src/util/config.ts +58 -0
  340. package/src/native-harness/src/util/json.ts +41 -0
  341. package/src/native-harness/src/util/message-position.ts +3 -0
  342. package/src/native-harness/src/util/reminder-schedule.ts +44 -0
  343. package/src/native-harness/src/util/schema.ts +40 -0
  344. package/src/native-harness/src/util/timeline-text.ts +72 -0
  345. package/src/native-harness/src/util/timeline-tool-names.ts +3 -0
  346. package/src/native-harness/test/agent.test.ts +130 -0
  347. package/src/native-harness/test/approval-gate.test.ts +255 -0
  348. package/src/native-harness/test/approval-protocol.test.ts +94 -0
  349. package/src/native-harness/test/boundaries.test.ts +18 -0
  350. package/src/native-harness/test/channel-controls.test.ts +322 -0
  351. package/src/native-harness/test/client-abort.test.ts +136 -0
  352. package/src/native-harness/test/config-policy.test.ts +301 -0
  353. package/src/native-harness/test/conformance/storage.ts +1141 -0
  354. package/src/native-harness/test/context.test.ts +177 -0
  355. package/src/native-harness/test/crash.test.ts +187 -0
  356. package/src/native-harness/test/debug-tools.test.ts +67 -0
  357. package/src/native-harness/test/development-cli.test.ts +67 -0
  358. package/src/native-harness/test/development.test.ts +171 -0
  359. package/src/native-harness/test/dispatch-evidence.test.ts +58 -0
  360. package/src/native-harness/test/e2e.test.ts +186 -0
  361. package/src/native-harness/test/external-notices.test.ts +101 -0
  362. package/src/native-harness/test/fixtures/approval-e2e.jsonl +4 -0
  363. package/src/native-harness/test/fixtures/crash-scenario.jsonl +5 -0
  364. package/src/native-harness/test/fixtures/development-lifecycle.jsonl +10 -0
  365. package/src/native-harness/test/fixtures/echo-scenario.jsonl +3 -0
  366. package/src/native-harness/test/fixtures/format2-schema.ts +27 -0
  367. package/src/native-harness/test/fixtures/format3-schema.ts +16 -0
  368. package/src/native-harness/test/fixtures/hold-scenario.jsonl +4 -0
  369. package/src/native-harness/test/fixtures/model-e2e.jsonl +3 -0
  370. package/src/native-harness/test/fixtures/storage-owner.ts +20 -0
  371. package/src/native-harness/test/format-reply.test.ts +10 -0
  372. package/src/native-harness/test/helpers/operator-view.ts +41 -0
  373. package/src/native-harness/test/helpers/scenario.ts +9 -0
  374. package/src/native-harness/test/helpers/session.ts +38 -0
  375. package/src/native-harness/test/helpers/stdio.ts +46 -0
  376. package/src/native-harness/test/inspector.test.ts +77 -0
  377. package/src/native-harness/test/listeners.test.ts +49 -0
  378. package/src/native-harness/test/loop.test.ts +88 -0
  379. package/src/native-harness/test/model-channel-double.test.ts +87 -0
  380. package/src/native-harness/test/model-crash.test.ts +62 -0
  381. package/src/native-harness/test/model-delivery-regressions.test.ts +55 -0
  382. package/src/native-harness/test/model-e2e.test.ts +71 -0
  383. package/src/native-harness/test/model-final-filter.test.ts +30 -0
  384. package/src/native-harness/test/model-large-reply.test.ts +28 -0
  385. package/src/native-harness/test/model-live-queue.test.ts +33 -0
  386. package/src/native-harness/test/model-runner.test.ts +117 -0
  387. package/src/native-harness/test/model-storage.test.ts +99 -0
  388. package/src/native-harness/test/model-stream-adapter.test.ts +26 -0
  389. package/src/native-harness/test/model-stream-public.test.ts +77 -0
  390. package/src/native-harness/test/notices.test.ts +64 -0
  391. package/src/native-harness/test/openrouter-config.test.ts +218 -0
  392. package/src/native-harness/test/operator-controls.test.ts +132 -0
  393. package/src/native-harness/test/output.test.ts +44 -0
  394. package/src/native-harness/test/owner-config.test.ts +64 -0
  395. package/src/native-harness/test/permissions-e2e.test.ts +68 -0
  396. package/src/native-harness/test/persistence.test.ts +236 -0
  397. package/src/native-harness/test/portability.test.ts +337 -0
  398. package/src/native-harness/test/protocol.test.ts +160 -0
  399. package/src/native-harness/test/reminder-clock.test.ts +61 -0
  400. package/src/native-harness/test/reminder-stdio.test.ts +140 -0
  401. package/src/native-harness/test/reminder-storage.test.ts +124 -0
  402. package/src/native-harness/test/scenario-jsonl.test.ts +112 -0
  403. package/src/native-harness/test/scripted.test.ts +92 -0
  404. package/src/native-harness/test/session-file.test.ts +51 -0
  405. package/src/native-harness/test/startup-channel-changes.test.ts +256 -0
  406. package/src/native-harness/test/stdio.test.ts +132 -0
  407. package/src/native-harness/test/storage-memory.test.ts +4 -0
  408. package/src/native-harness/test/storage-sqlite.test.ts +420 -0
  409. package/src/native-harness/test/suspension.test.ts +430 -0
  410. package/src/native-harness/test/timeline-retrieval.test.ts +211 -0
  411. package/src/native-harness/test/tools-catalog.test.ts +468 -0
  412. package/src/native-harness/test/tools-protocol.test.ts +418 -0
  413. package/src/native-harness/test/transfers.test.ts +94 -0
  414. package/src/native-harness/test/web-chat.test.ts +35 -0
  415. package/src/native-harness/tsconfig.json +20 -0
  416. package/src/observation/agent-event-bus.ts +44 -18
  417. package/src/observation/index.ts +1 -0
  418. package/src/operations/contracts.ts +11 -3
  419. package/src/operations/errors.ts +5 -0
  420. package/src/operations/stale-policy.ts +1 -1
  421. package/src/operations/supervisor.ts +34 -10
  422. package/src/orchestrator/acp-delivery.ts +68 -0
  423. package/src/orchestrator/assignments.ts +27 -0
  424. package/src/orchestrator/busy.ts +15 -0
  425. package/src/orchestrator/config.ts +41 -0
  426. package/src/orchestrator/consumer-api.ts +24 -0
  427. package/src/orchestrator/contracts.ts +71 -0
  428. package/src/orchestrator/durable-assignments.ts +111 -0
  429. package/src/orchestrator/native-delegation.ts +103 -0
  430. package/src/orchestrator/orchestrator.ts +318 -0
  431. package/src/orchestrator/permissions.ts +25 -0
  432. package/src/orchestrator/policy.ts +44 -0
  433. package/src/orchestrator/pool.ts +123 -0
  434. package/src/orchestrator/tool-descriptions.ts +11 -0
  435. package/src/permissions/acp.ts +18 -0
  436. package/src/permissions/arrival.ts +13 -0
  437. package/src/permissions/consumer-config.ts +19 -0
  438. package/src/permissions/conversation.ts +280 -0
  439. package/src/permissions/matcher.ts +85 -0
  440. package/src/permissions/outcome.ts +15 -0
  441. package/src/permissions/policy.ts +81 -0
  442. package/src/permissions/request.ts +26 -0
  443. package/src/persistence/activity-projection.ts +1 -0
  444. package/src/persistence/backend.ts +34 -1
  445. package/src/persistence/channels.ts +23 -0
  446. package/src/persistence/index.ts +4 -0
  447. package/src/persistence/protocol-method.ts +5 -0
  448. package/src/persistence/reminder-wake.ts +49 -0
  449. package/src/persistence/reminders.ts +385 -0
  450. package/src/persistence/sqlite-backend.ts +84 -6
  451. package/src/persistence/sqlite-channels.ts +65 -0
  452. package/src/persistence/sqlite-reminders.ts +85 -0
  453. package/src/persistence/sqlite-schema.ts +108 -3
  454. package/src/persistence/sqlite-worker-delivery.ts +374 -0
  455. package/src/persistence/sqlite-workers.ts +59 -0
  456. package/src/persistence/worker-delivery-contract.ts +104 -0
  457. package/src/persistence/worker-terminal-reason.ts +29 -0
  458. package/src/persistence/workers.ts +19 -0
  459. package/src/provider-notices.ts +137 -0
  460. package/src/repl/commands.ts +2 -2
  461. package/src/steering/combine.ts +3 -1
  462. package/src/steering/contracts.ts +11 -2
  463. package/src/steering/controller.ts +3 -2
  464. package/src/transport/acp-transport.ts +24 -14
  465. package/src/types.ts +15 -12
  466. package/src/updates.ts +14 -2
  467. package/src/wire-log.ts +1 -1
@@ -0,0 +1,337 @@
1
+ # Tools and host callbacks: work log
2
+
3
+ Branch: `tools-and-callbacks`.
4
+ Base: the work started on `c17d525` of `acp-client-integration`, before its
5
+ review finished. The reviewed and approved revision `b9a96b8` was merged in
6
+ afterwards at `c4f11be`; see the last entry.
7
+
8
+ Baseline at the base: harness typecheck clean and 298 tests passing; acp-client
9
+ typecheck clean and 1390 tests passing.
10
+
11
+ A note that applies to every entry: the machine ran other work during these
12
+ sessions (load average about 5). Under that load one or two harness tests that
13
+ spawn a child process or use SQLite time out per full run, a different one each
14
+ time. Each passed when rerun alone. Full runs below use `--timeout 30000`.
15
+
16
+ ## Step 1: contracts (Gate 1)
17
+
18
+ Commits `610b8fe`, `f95b299`.
19
+
20
+ Done:
21
+
22
+ - Decision record `0021-tools-and-host-callbacks.md`.
23
+ - Contract types in `src/contracts/tools.ts` and additions to `loop.ts`,
24
+ `model-execution.ts`, `events.ts`, `storage.ts`, `protocol.ts`, `session.ts`
25
+ and `context.ts`.
26
+ - The storage side of the contract, because the contract type would not
27
+ compile without it: `setToolRevoked`, `revokedTools` in the snapshot and
28
+ archive, and an optional typed `outcome` on tool results.
29
+ - The kernel loop passes a dispatched call's outcome to its paired result.
30
+
31
+ Tested: typecheck; two new storage conformance cases that run on memory and
32
+ SQLite (revoked set through reopen, export and import; outcome validation).
33
+
34
+ Walkthroughs the plan asks for. Each names the owner and what a consumer sees.
35
+
36
+ | Case | Owner | Observable outcome |
37
+ | --- | --- | --- |
38
+ | Reconnect with a missing handler | The session's catalog. The connection supplies handler names at `initialize`; the catalog is bound on load before `start`. | `session/tools` shows the tool with `available: false, reason: "handler_missing"`. It is not offered. A call to it is skipped with `tool_unavailable`. |
39
+ | Revocation while waiting for approval | The permission gate. `tool/revoke` commits the revocation, then closes the tool's open requests. | One paired result `tool_unavailable`, a `skipped` event, no `started` event. A later `approval/respond` for that request is refused. |
40
+ | Callback with no deadline | `runFunction`. | The call stays `started`. `session/status` shows phase `tool` with the invocation ID. Suspension waits. Interrupt ends it as `interrupted`, effect unknown. |
41
+ | Large result on a separate filesystem | The producer stores the bytes. The harness stores only the reference in the result's `outcome`. | The model sees a preview and `result_id`. `read_tool_result` is checked against recorded references for the requesting channel, then sent to the host as `results/read`. |
42
+
43
+ Drift from the design:
44
+
45
+ - The plan says to validate configured registrations in managed config. The
46
+ catalog is supplied on `session/create` and `session/load` instead, and not
47
+ stored. The spec says definitions are data the consumer declares at open and
48
+ that only revocations are saved, and a stored catalog would make reconnect
49
+ with a changed handler set ambiguous.
50
+ - No new storage table for invocations. Records are derived from the committed
51
+ call, the dispatch evidence of decision 0018, the paired result and the
52
+ turn's end. Storage and archive format numbers do not change.
53
+ - `waiting_for_approval` and the turn phase are process state. After a reopen
54
+ an approval is gone (existing behavior), so nothing is lost.
55
+
56
+ Gaps: the walkthroughs were on paper at this step. Steps 2 and 3 test them.
57
+
58
+ ## Step 2: catalog and lifecycle (Gate 2)
59
+
60
+ Commit `7fdd963`.
61
+
62
+ Done:
63
+
64
+ - `src/util/schema.ts`: a small JSON Schema check for arguments.
65
+ - `src/capabilities/tools/catalog.ts`: catalog validation and state.
66
+ - `src/capabilities/tools/invocations.ts`: derived invocation records.
67
+ - `src/capabilities/tools/functions.ts`: callback execution with deadlines,
68
+ result shaping, and the scoped reader.
69
+ - `src/governance/permissions/gate.ts`: a `refuse` check after policy and
70
+ again at the dispatch boundary, outcomes on results, `closeTool`.
71
+ - `src/index.ts`: offered list per inference, dispatch wiring, phases,
72
+ `session.tools` controls.
73
+ - `BUSINESS_RULES.md`: adjustable defaults.
74
+
75
+ Tested: `test/tools-catalog.test.ts`, 13 tests at the session level with a
76
+ test executor. They cover each Gate 2 evidence item: fixed entries refuse
77
+ removal; revocations survive reopen; runtime selection is supplied at open;
78
+ denied and unavailable tools are omitted; a retry sees the frozen list;
79
+ invalid, unoffered and revoked calls skip without a callback (before approval,
80
+ during it, and after it was granted); recovery before and after dispatch
81
+ evidence reports `skipped`/`none` and `interrupted`/`unknown`; deadline
82
+ precedence; a late reply changes nothing; suspension waits and reports the
83
+ call; large results and reader scope. Full harness suite: 315 tests, all pass
84
+ apart from the load timeouts described above.
85
+
86
+ Regressions:
87
+
88
+ - `test/channel-controls.test.ts`: two assertions compared `activeTurn` with
89
+ exact equality and now see the new `phase` field. Changed to `toMatchObject`.
90
+ A consumer doing exact comparison on `activeTurn` would see the same.
91
+ - Skipped results of built-in tools now carry `outcome: { status: "skipped" }`
92
+ in storage. Their content and events are unchanged.
93
+ - Tools the turn's policy denies are no longer offered to the model, built-ins
94
+ included. The spec asks for this. Before, a denied built-in was offered and
95
+ the call was skipped with `policy_denied`. Existing tests still pass.
96
+
97
+ Gaps and limits:
98
+
99
+ - The schema check covers common keywords only and ignores the rest (`$ref`,
100
+ `oneOf`, `pattern`, `format`). A schema using those is checked loosely.
101
+ - A call made by the model for a tool that was offered in an earlier inference
102
+ of the same turn but not the latest one is refused. Only the latest offered
103
+ set is kept.
104
+ - Expiry of a reference is checked against the harness clock.
105
+ - `read_tool_result` is offered whenever a catalog exists, even with no stored
106
+ result yet.
107
+ - Not yet tested here: real transports, concurrent callbacks, cancel on the
108
+ wire. That is step 3.
109
+
110
+ ## Step 3: callback and result transport (Gate 3)
111
+
112
+ Commits `0bbf257` (harness) and `ea5da58` (acp-client, with step 4).
113
+
114
+ Done, harness:
115
+
116
+ - `src/interfaces/protocol/functions.ts`: the callback bridge (a
117
+ `FunctionExecutor` that sends `functions/call` and `results/read`, matches
118
+ answers by request ID, sends `functions/cancel` when a wait is aborted, and
119
+ fails open waits when the connection goes) and the tool methods.
120
+ - `server.ts`: `initialize` accepts `callbacks: ["functions/call"]` and
121
+ `functions`; `tools` on create and load; handlers bound before `start`;
122
+ capability `functions`. The file is now 433 lines. The reason is that the
123
+ open paths live there; everything separable went to `functions.ts`.
124
+ - Both transports carry callbacks and answers. The stdio server treats a line
125
+ with an ID and a result or error, and no method, as an answer.
126
+ - `HarnessClient.serveFunctions(handler, reader)` runs each handler in its own
127
+ task, plus typed methods for the tool requests. Types exported from
128
+ `src/client.ts`.
129
+ - The scripted server passes the catalog to the session, and its request log
130
+ now lists the tools offered.
131
+ - Fix found by the transport tests: when the executor rejects its wait on
132
+ abort, a deadline was treated as a failure of the call and failed the turn.
133
+ `runFunction` now tells the two apart.
134
+
135
+ Done, acp-client:
136
+
137
+ - `src/native/functions.ts`: `NativeFunctionsConfig`, routing to handlers, the
138
+ private result store and bounded reads by ID.
139
+ - `NativeHarnessHost`: `functions` config, catalog and runtime selection sent
140
+ on every open, `tools()`, `revokeTool`, `restoreTool`, `enableTool`,
141
+ `removeTool`, `toolInvocation`, `toolInvocations`.
142
+ - `conversationCapabilities.supervision: "backend"` on native controllers.
143
+ `stallLimitsFor` returns no limits for it.
144
+ - `tool_call` events with status `skipped` or `interrupted` map to a failed
145
+ tool update for the consumer.
146
+
147
+ Tested:
148
+
149
+ - `test/tools-protocol.test.ts` (harness, 8 tests). In process and over real
150
+ stdio children: concurrent callbacks answered in reverse order land in their
151
+ own channels; status answers while handlers are quiet; interrupt cancels
152
+ only its own call; deadline cancel reaches the handler; late answers change
153
+ nothing; typed errors. Over stdio only: a 3 MB result by reference with
154
+ reader scope; revoke during approval and persistence across processes;
155
+ SIGKILL with a call outstanding. Plus negotiation and catalog validation.
156
+ - `test/native/function-host.test.ts` (acp-client, 4 tests): catalog shape,
157
+ routing, the result store (multi-byte text reassembled from 7-byte parts,
158
+ paths refused, expiry), and the supervision guard.
159
+
160
+ Regressions and behavior changes:
161
+
162
+ - **Native turns are no longer cancelled by `operationLifecycle` silence
163
+ limits**, including configured ones and including a silent model. The spec
164
+ asks for this. The shared conformance case "stale detection" expected a
165
+ stall and failed for the native subject. It now has a `backendSupervised`
166
+ branch that asserts the turn is still running past the limits and ends only
167
+ on an explicit stop. This touches the reviewed controller conformance suite.
168
+ - **Host reopen rule changed.** After a lost connection the host reopened only
169
+ if a push was waiting or a known turn was running. A crash right after an
170
+ input was accepted, before `turn_started` reached the host, left the prompt
171
+ waiting forever. This is a bug in the acp-client integration base, found by
172
+ checkpoint case 4b. The host now also reopens when any accepted input is
173
+ unsettled. Side effect: with file-backed records, a stale unsettled input
174
+ from an earlier acp-client run makes the host reopen after a loss.
175
+ - The scripted server's request log lines gained a `tools` field.
176
+
177
+ Gaps and limits:
178
+
179
+ - Tool changes need a running harness. A revocation made while it is stopped
180
+ is not queued the way channel changes are.
181
+ - The runtime selection is kept in the host's memory. A new acp-client process
182
+ starts from each function's `enabled` flag.
183
+ - Result expiry at the host uses the file's modification time. Stored results
184
+ are plain files with mode 0600 in a 0700 directory, not encrypted.
185
+ - A handler's return value that cannot be serialized to JSON fails the call
186
+ as `handler_failed`.
187
+ - Reads are in bytes of the serialized JSON text, not of the original value.
188
+ - No test sends a `functions/call` whose arguments exceed a frame; that path
189
+ returns `request_too_large` by inspection only.
190
+ - No test covers two connections; the server has one connection per process.
191
+
192
+ ## Step 4: public checkpoint (Gate 4)
193
+
194
+ Commit `ea5da58`.
195
+
196
+ `test/native/functions.test.ts` runs acp-client's public conversation
197
+ interface against a real `serve --stdio` child with a SQLite session. Plan
198
+ scenarios:
199
+
200
+ | Scenario | Test | Result |
201
+ | --- | --- | --- |
202
+ | 1. Approved call held at a barrier; Bob finishes; status shows Alice's tool and elapsed phase; silence does not cancel; result commits once and reaches the next inference | `1:` | Pass. Silence limits of 150 ms, handler held over 600 ms. |
203
+ | 2. Revoke while approval pending; old request authorizes nothing; skipped; next inference omits the tool; persists across reopen | `2:` | Pass. Reopen is a new acp-client and a new harness process. |
204
+ | 3. Result larger than a frame, stored on the host, read through the producing channel; other channel, path and expired ID refused | `3:` | Pass. 3 MB result, host directory outside the harness home. |
205
+ | 4. Lost outcome stays uncertain and the handler is not rerun; timeout gives one paired result and a late reply changes nothing; interrupt, then a late reply starts nothing | `4a`–`4d` | Pass. 4b is the crash between dispatch evidence and the send. |
206
+
207
+ Docs updated: harness `README.md` and `ARCHITECTURE.md`, `BUSINESS_RULES.md`,
208
+ `WORK.md`, and `CONSUMER_GUIDE.md` at the repository root.
209
+
210
+ Final verification at `ea5da58`: see the closing entry.
211
+
212
+ Gaps:
213
+
214
+ - Spec acceptance 1 asks for schema validation through real stdio. The
215
+ invalid-argument cases run at the session level and in process, not in the
216
+ acp-client checkpoint.
217
+ - Scenario 4a stops the harness cleanly through the host. The SIGKILL variant
218
+ is in the harness stdio test.
219
+ - Scenario 3 waits about 4 seconds of wall clock for expiry.
220
+ - The model is scripted throughout. No test uses a provider, so how a real
221
+ model reacts to the skip and timeout messages is untested.
222
+ - No independent review has happened. The plan requires one per gate.
223
+
224
+ ## Closing entry
225
+
226
+ Implementation revision: `ea5da58` on `tools-and-callbacks`. Nothing is pushed.
227
+
228
+ Verification at that revision:
229
+
230
+ - acp-client: typecheck clean; `bun test ./test` 1401 pass, 0 fail (131
231
+ files). Baseline was 1390. An earlier run at the same code had one failure
232
+ in `test/conversation-turns/characterization.test.ts` (PTY bridge) that
233
+ passed when rerun alone.
234
+ - Harness: typecheck clean; `bun test ./test --timeout 30000` 324 tests in 44
235
+ files. One run passed 324 of 324. The final run had two timeouts under
236
+ machine load, in `permissions-e2e.test.ts` and `portability.test.ts`, which
237
+ passed when rerun alone (11 of 11). Baseline was 298.
238
+
239
+ For the reviewer, in order of weight:
240
+
241
+ 1. The base (`acp-client-integration`) is itself unreviewed.
242
+ 2. Native turns ignore host silence limits, and the shared conformance suite
243
+ was changed to say so (step 3).
244
+ 3. The host reopen rule changed to fix a hang in the base (step 3).
245
+ 4. The catalog is supplied at open and not stored in managed config (step 1).
246
+ 5. Invocation records are derived, with no new table and no format bump
247
+ (step 1). A file whose tool results carry `outcome` does not open on the
248
+ previous revision.
249
+ 6. Policy-denied built-in tools are no longer offered to the model (step 2).
250
+ 7. `server.ts` and `host.ts` are over the 400-line guideline.
251
+
252
+ Not done: independent review of each gate, which the plan requires before
253
+ closure, and the retrospective that follows it.
254
+
255
+ ## Merge of the accepted base
256
+
257
+ Commit `c4f11be` merges `acp-client-integration` at `b9a96b8`. That brings the
258
+ startup-deadline fix `7133c5c` and the recorded approval of Gates 1–3 of the
259
+ integration (behavior revision `7133c5c`). Item 1 of the reviewer list above
260
+ no longer applies: the base is accepted.
261
+
262
+ One conflict, in `src/native/host.ts` (`#loadOrCreate`). Both sides were kept:
263
+ the deadline checks from the fix and the tool catalog sent on open.
264
+
265
+ Verification at `c4f11be`:
266
+
267
+ - acp-client: typecheck clean; `bun test ./test` 1402 tests in 131 files,
268
+ 1401 pass. The one failure, a 5 s timeout in
269
+ `test/persistence-file-registry-store.test.ts`, passed when rerun alone
270
+ (7 of 7). `bun test ./test/native` alone: 67 of 67, including the
271
+ late-connection regression from the fix and the tools checkpoint.
272
+ - Harness: typecheck clean; 324 of 324.
273
+
274
+ Gap: the startup deadline is not tested together with host functions. The
275
+ function handlers are registered before `initialize`, so a connection that is
276
+ killed for arriving late has served nothing.
277
+
278
+ Still not done: independent review of the tools and callbacks gates.
279
+
280
+ ## Independent review follow-up
281
+
282
+ Fix branch `aiagent/cod1a-tools-and-callbacks` starts from `fcc1807`, with
283
+ the approved ACP integration closure `b9a96b8` in its ancestry. At the baseline
284
+ both typechecks passed, the native suite passed 67 tests, and the focused
285
+ harness catalog and protocol suites passed 22 tests.
286
+
287
+ Added real stdio coverage for the documented schema-validation gap. Invalid
288
+ callback arguments produce a paired result for the next inference without
289
+ opening approval or invoking the handler. The new isolated test passed.
290
+ Independent review is pending.
291
+
292
+ ## Independent approval and retrospective
293
+
294
+ Gro approved Gates 1–4 at `f4eff944b648ece634891e3dcdb5ae71f6059eed`
295
+ on a clean tree. The accepted chain is contract `610b8fe` and `f95b299`
296
+ (decision 0021), catalog and lifecycle `7fdd963`, callback transport
297
+ `0bbf257`, host and public checkpoint `ea5da58`, integration base merge
298
+ `c4f11be` (including `b9a96b8` and its startup fence `7133c5c`), baseline
299
+ `fcc1807`, and stdio validation coverage `f4eff94`.
300
+
301
+ Both independent typechecks passed. The root suite passed 1402 tests across
302
+ 131 files (11960 assertions, 192.94s). The full harness suite passed 320 of
303
+ 325 tests across 44 files (3413 assertions, 156.95s). Gro attributed the five
304
+ failures to load: three session/create client timeouts, one stdio child killed
305
+ after its shutdown grace period, and one SQLite owner-config test timeout.
306
+ Isolated reruns of portability, protocol, permissions end-to-end and
307
+ owner-config passed all 24 tests (371 assertions, 18.89s). Gro accepted this
308
+ evidence with the existing timeout and shutdown settings.
309
+
310
+ The real SQLite stdio checkpoint passed approved callback dispatch while Bob
311
+ completed independently, pending-approval revocation across reopen, scoped
312
+ retrieval of a 3 MB producer-owned result, and lost, timed-out and interrupted
313
+ callback outcomes with late replies fenced. Review closed the schema coverage
314
+ gap with a real child: invalid arguments skipped before approval or dispatch
315
+ and the next inference received the paired result. The existing implementation
316
+ needed no behavior fix.
317
+
318
+ Native turns use backend supervision, including for silent models. Harness
319
+ model, approval and configured tool deadlines still apply. A lost connection
320
+ can reopen while unsettled submission records remain, including records restored
321
+ by an optional file store. The default store is memory. The host supplies the
322
+ catalog and runtime selection on open. Revocations persist, while revocation
323
+ requests made with the harness stopped are not queued.
324
+
325
+ SQLite format 5 and archive 4 retain their version numbers. Tool outcomes are
326
+ optional and older results without them are treated as successes. Files with
327
+ new tool outcomes cannot open on the previous revision. Policy-denied tools,
328
+ including built-ins, are omitted from inference and still denied at dispatch.
329
+ The schema checker ignores unsupported keywords, and dispatch checks the latest
330
+ inference's offered set.
331
+
332
+ The producer stores result bytes in mode-0600 files. Reads address serialized
333
+ JSON bytes, and expiry is checked against the reference timestamp in the
334
+ harness and against modification time plus TTL in the host. A lost approval
335
+ answer returns false without retry. The combined startup-deadline and callback
336
+ case has no dedicated test. Each process serves one connection. The shared
337
+ protocol server and native host exceed the 400-line guideline.
@@ -0,0 +1,76 @@
1
+ # Tools and host callbacks implementation plan
2
+
3
+ Date: 2026-11-20.
4
+ Status: proposed for review.
5
+
6
+ ## Scope and base
7
+
8
+ Implement [SPEC.md](SPEC.md) on the accepted acp-client integration revision.
9
+ Record that revision at assignment. Deliver one consumer-registered function
10
+ over the public stdio connection, with equivalent behavior in process.
11
+ Keep the same permission gate and tool-result pairing for built-in and
12
+ consumer tools. Other executor types and user-entered code stay separate.
13
+
14
+ ## Code ownership
15
+
16
+ Paths are relative to the native harness package unless identified as acp-client
17
+ paths.
18
+
19
+ | Area | Code seam | Work |
20
+ | --- | --- | --- |
21
+ | Contracts and config | Existing tool, session, permission, storage, and protocol contracts in `src/contracts/` and managed config in `src/runtime/config/` | Define catalog entries, binding and availability, invocation identity, lifecycle, callback envelopes, and result references. Validate configured registrations when opening the session. |
22
+ | Tool catalog and execution | Existing `src/capabilities/tools/`, `src/governance/permissions/gate.ts`, and session assembly in `src/index.ts` | Add the shared catalog, request tool snapshots, argument validation, and callback executor binding. Extend the existing dispatch path for availability and deadlines. Core and runtime tools use the same path. |
23
+ | Kernel and model adapter | Existing `src/kernel/` and `src/capabilities/model/` | Feed the tool snapshot into inference. Preserve it across model retries. The provider adapter renders the fixed and changeable groups. The kernel coordinates the existing iteration and lifecycle without knowing callback or filesystem details. |
24
+ | Durable state | Existing `src/state/storage/` and archive contracts | Reuse the committed assistant request, dispatch evidence, and paired result. Extend those records for invocation lookup, terminal outcomes, and configured revocations. Persist references as metadata. The process serving the result owns its bytes and retention. |
25
+ | Bidirectional protocol | Existing `src/interfaces/protocol/`, live queue, framing, and public client | Add reverse requests, response correlation, cancellation, and connection cleanup within the existing frame limits. Keep callback handler execution independent from reading requests and events. |
26
+ | acp-client | Existing host and controller under acp-client's `src/native/` | Bind the consumer's functions, supply runtime selections on open, route callbacks by invocation, and store and read host-owned results. Use harness phase and outcome for native turn supervision. |
27
+
28
+ Keep the dependency direction in [ARCHITECTURE.md](../../../../ARCHITECTURE.md)
29
+ and [AGENTS.md](../../../../AGENTS.md). acp-client uses public harness
30
+ exports. The kernel depends on contracts. The callback transport delivers
31
+ calls authorized by the existing gate. Tool results use a scoped reader
32
+ through that same tool path. Reuse `session/status` for connection probes and
33
+ phase reporting.
34
+
35
+ ## Implementation stages and acceptance gates
36
+
37
+ | Gate | Work | Evidence required |
38
+ | --- | --- | --- |
39
+ | **1. Contracts** | Record catalog and reconnect semantics, invocation IDs versus wire request IDs, result and event shapes, and scope and retention for result references. Define optional deadline precedence and the order of revocation, approval, and dispatch. Record contract decisions before dependent code changes. | Typecheck. Walk through reconnect with a missing handler, revocation while waiting for approval, a callback with no deadline, and a large result whose producer is on a separate filesystem. Verify each case has one owner and an observable outcome. |
40
+ | **2. Catalog and lifecycle** | Compose the catalog and a test executor behind the existing dispatch gate. Add invocation records and status phases. Preserve configured revocations in storage and archives. | Fixed registrations survive runtime removal attempts. Revocations survive reopen. Runtime tools are supplied at open. Denied tools are omitted and retries retain the same offered list. Invalid or revoked calls skip without dispatch. Recovery before dispatch evidence and recovery between that evidence and transport send report distinct outcomes. Existing built-in tool tests still pass. |
41
+ | **3. Callback and result transport** | Implement reverse requests and cancellation in both transports. Add producer-owned result storage and the scoped reader. Wire the native host and controller to callback and phase events. | Concurrent callbacks correlate to the correct requests. A quiet callback does not trigger native turn cancellation under the host's ordinary ACP silence timer. Optional deadlines and explicit cancellation close the correct call. A large result crosses the wire by reference, with no shared filesystem. Reject cross-channel reads, arbitrary paths, and expired references. |
42
+ | **4. Public checkpoint and review** | Run acp-client with a real scripted stdio child. Update architecture, usage, and published business rule locations. Run harness and host verification. | Run the scenarios below, typecheck and run the full harness suite, and run the relevant acp-client and controller conformance tests. Record the independently reviewed revision and evidence. |
43
+
44
+ ## End-to-end acceptance
45
+
46
+ 1. Start Alice and Bob in one session. Alice requests a host function and
47
+ receives approval for the exact call. Hold its handler at a deterministic
48
+ barrier. Verify Bob finishes, status reports Alice's tool and elapsed phase,
49
+ and ordinary silence does not cancel the call. Release it and verify the
50
+ result commits once and reaches Alice's next inference.
51
+ 2. Revoke a tool while its approval is pending. Verify the old request cannot
52
+ authorize dispatch, the call is recorded as skipped, and the next inference
53
+ omits the tool. Reopen and verify the revocation persists.
54
+ 3. Return a result larger than one stdio frame. Save it on the host, verify the
55
+ callback succeeds with a preview and ID, and retrieve it through the
56
+ producing channel. Test with no shared result directory. Verify the scoped
57
+ reader rejects access from another channel, arbitrary paths, and expired IDs.
58
+ 4. Lose the callback outcome after dispatch. Reopen and verify the record
59
+ reports uncertainty and the handler does not run again. Separately time out
60
+ a stalled callback while its turn is live and verify the next inference
61
+ receives exactly one paired timeout result. Deliver a late reply and verify
62
+ it cannot replace that result or start another inference. Interrupt a whole
63
+ turn and verify a late reply starts no further work for it.
64
+
65
+ Use controlled handlers, scripted inference, and timing barriers so automated
66
+ tests need no provider key or long wall-clock waits. Cover timeout precedence,
67
+ interrupt, and suspend against the same lifecycle used by the public test.
68
+
69
+ ## Handoff and closure
70
+
71
+ Use one implementer and one independent reviewer. Record the base, exact
72
+ stage revisions, evidence, and review outcomes in `LOG.md` once work starts.
73
+ Review each gate before building on it. Check that the existing gate remains
74
+ the only path to dispatch, readers cannot expand their result access, and
75
+ an unresponsive callback does not block connection handling. Record the
76
+ accepted revision, limitations, and a short retrospective at closure.
@@ -0,0 +1,204 @@
1
+ # Native harness tools and host callbacks
2
+
3
+ Date: 2026-11-20.
4
+ Status: proposed for review.
5
+ See [PLAN.md](PLAN.md) for implementation and acceptance gates.
6
+
7
+ ## Scope
8
+
9
+ Let a consumer register functions that the harness can offer to the model and
10
+ execute through the existing permission gate. Define a common tool-call
11
+ lifecycle and prove it with a consumer-registered function over real stdio.
12
+ Support the same behavior in process.
13
+
14
+ Build on [configuration and permissions](../../11-19-config-permissions/SPEC.md)
15
+ and the [acp-client integration](../../acp-client-integration/0001-DESIGN/SPEC.md).
16
+ Reuse the original
17
+ [`functions/call` proposal](../../../../../../.res/somelogs.md/11-11+/11-12-SPEC-harness-protocol.md).
18
+ HTTP, command, and MCP executors, per-channel tool selection, and
19
+ [user-entered code](../../todos/11-20-TODO-user-entered-tool-code.md) remain
20
+ separate work. Existing built-in tools keep working through the same gate.
21
+
22
+ The [attachment-tools design](../0003-DESIGN-attachment-tools/SPEC.md) builds
23
+ on this lifecycle for file transfers and channel publication.
24
+
25
+ ## Tool catalog and availability
26
+
27
+ The session owns tool definitions. A definition has a unique name, description,
28
+ input schema, and a binding to a handler supplied by the consumer. The handler
29
+ name is the binding for this slice. Tool names also identify policy rules.
30
+ Reject duplicate names across the session, including conflicts with built-ins.
31
+
32
+ | Group | Behavior |
33
+ | --- | --- |
34
+ | **Configured, fixed** | The consumer declares these at session open. Runtime operations cannot remove their registrations. |
35
+ | **Configured, revocable** | The consumer declares these at session open and can revoke or restore their grants. Save those decisions with the session so reconnect and export/import preserve them. |
36
+ | **Runtime** | The consumer can enable or remove tools by name from its registered catalog. Keep the enabled set in memory for this slice. The consumer supplies it again when it reconnects. |
37
+
38
+ The consumer provides definitions for runtime tools and binds their handlers
39
+ before enabling them. Changes by name reuse that definition and binding.
40
+ Changing schemas or replacing handlers live is deferred. Tool definitions and
41
+ grants are data. The consumer supplies handler implementations at runtime.
42
+
43
+ The host advertises its available handler names during connection setup.
44
+ Provision bindings and any initial runtime selection before recovered work
45
+ can start. A missing handler makes a tool unavailable. A fixed registration
46
+ remains subject to handler availability and policy. Expose availability
47
+ separately from policy so a consumer can tell why a tool cannot run.
48
+
49
+ ## What the model sees
50
+
51
+ For each inference, take a snapshot of the available tool definitions and the
52
+ turn's effective policy. Show tools the turn may call or ask to use. Omit
53
+ unavailable tools and tools the policy denies. Keep the snapshot fixed across
54
+ retries of that request. Changes to definitions offered to the model take
55
+ effect on the next inference.
56
+
57
+ Preserve a stable group of available fixed definitions and a changeable group
58
+ for model adapters. For OpenRouter, combine them into one native tools array
59
+ with fixed tools first and deterministic order within each group. Other
60
+ adapters can use the groups for provider-specific placement. Both groups use
61
+ the same execution gate.
62
+
63
+ Before dispatch, require a call to match a definition offered in its request.
64
+ Validate the arguments against that definition and check current availability
65
+ and applicable policy. Revocation or removal before dispatch prevents execution,
66
+ including after an approval has been given. Close a pending approval for a tool
67
+ that becomes unavailable. A tool already dispatched follows the normal
68
+ completion and cancellation rules.
69
+
70
+ ## Invocation and lifecycle
71
+
72
+ Each invocation belongs to the channel and turn that requested it. Give it a
73
+ stable harness invocation ID for client and callback correlation. Keep the
74
+ provider's tool-call ID for pairing its result with the model response. The
75
+ record includes the channel, turn, tool name, arguments, disposition, and
76
+ outcome. Channels execute independently. Within one iteration, continue
77
+ processing tool calls in order.
78
+
79
+ | State | Meaning |
80
+ | --- | --- |
81
+ | **Requested** | A complete tool request was committed with the assistant response. |
82
+ | **Waiting for approval** | Policy requires an approval for this particular call. Dispatch has yet to occur. |
83
+ | **Started** | The harness dispatched the authorized call after recording dispatch evidence. For a remote callback, this does not confirm the host handler began. |
84
+ | **Succeeded** | The executor returned a result and the harness committed it. |
85
+ | **Failed** | The executor returned a known error. Record the error without inferring that the handler had no effect. |
86
+ | **Skipped** | The harness did not dispatch the call. Reasons include invalid arguments, an unavailable tool, policy denial, or approval cancelled by suspension. |
87
+ | **Interrupted** | Interruption, timeout, or disconnect ended the harness's wait after dispatch. Without an authoritative outcome, report the effect as unknown. |
88
+
89
+ Publish live state changes with the invocation ID. Expose stored calls and
90
+ outcomes by ID after reconnect. Keep dispatch evidence before a possible
91
+ external effect, and persist the result before publishing a terminal result
92
+ event. On recovery, dispatch evidence without a committed outcome means the
93
+ effect is uncertain, including a crash between recording dispatch and sending
94
+ the callback.
95
+ The harness never automatically repeats an uncertain callback.
96
+
97
+ For a turn that continues, give the model a paired result with inline output,
98
+ a preview and a result reference, or a typed error. Include a reason it can
99
+ act on, such as correcting arguments or requesting a new approval after
100
+ resume. An interrupted turn retains its records and starts no further work.
101
+
102
+ ## Host callback
103
+
104
+ The proposed [callback policy amendment](../0002-AMENDMENT-callback-policy/SPEC.md)
105
+ adds contributing policy names for downstream authorization.
106
+
107
+ After authorizing and recording dispatch, send `functions/call` to the host
108
+ over the same connection. Include the invocation ID, session, channel, turn,
109
+ tool name, and validated arguments. The handler returns inline structured
110
+ output, a preview with a result reference, or a typed error. The harness
111
+ owns the callback wait and keeps other channels running. Match responses to
112
+ the exact outstanding request even when several callbacks are in flight. The
113
+ in-process client follows the same lifecycle.
114
+
115
+ The consumer can set an execution deadline per tool, with an optional session
116
+ default. If neither is set, the harness applies no wall-clock execution deadline.
117
+ Any configured deadline starts at dispatch. Approval has a separate deadline,
118
+ and the model deadline is already finished.
119
+
120
+ Interrupt and stop request cancellation of an active callback. Suspension
121
+ closes undispatched approvals and waits for dispatched tools to settle.
122
+ Report the call suspension is waiting on. A tool without a deadline can keep
123
+ suspension waiting until it settles or an operator interrupts it. Timeout or
124
+ disconnect closes the wait and requests cancellation where possible. Ignore
125
+ late responses for closed invocations. Cancellation cannot undo an external effect.
126
+ If a deadline expires while the turn is still live, commit a paired timeout
127
+ result with an unknown effect and let the turn continue. Interrupting the
128
+ whole turn ends execution for that turn.
129
+
130
+ ### Status and connection health
131
+
132
+ Use the existing `session/status` operation for an on-demand connection probe.
133
+ A response confirms the control connection is responsive. Turn status shows
134
+ the current phase, when it began, and the relevant model call, approval, or
135
+ tool invocation ID. A tool can be active while producing no text or progress.
136
+
137
+ Keep timeout enforcement at the model, approval, and tool boundaries. This
138
+ slice adds no periodic ping or iteration-wide stall deadline. In acp-client,
139
+ native turn supervision uses the harness phase and outcome. A quiet callback
140
+ does not trigger the host's ACP output-silence timer. Connection failure
141
+ continues through the existing stop and recovery rules.
142
+
143
+ ## Large results
144
+
145
+ When a successful result exceeds the inline limit, the producing process
146
+ saves the full result in its private result directory and returns a short
147
+ preview and an opaque result ID. This keeps the callback response within its
148
+ frame limit. An oversized inline result uses the reference path and remains
149
+ a success if the producer stored it successfully.
150
+
151
+ Offer a narrow `read_tool_result` tool that accepts the result ID and reads a
152
+ bounded portion of its contents. Route the read to the process holding the
153
+ bytes. For a consumer callback this can be another callback to the host.
154
+ The harness and host can have separate filesystems. Each uses storage it is
155
+ permitted to access, with no dependency on a shared `/tmp` path.
156
+
157
+ Bind the reference to the producing session, channel, and invocation.
158
+ Authorize the read using the requesting channel supplied by the harness,
159
+ alongside the normal tool policy. The producing channel can retrieve the
160
+ result when policy allows it. An unrelated channel cannot use the reference,
161
+ including when it encounters the ID in shared history. The reader accepts
162
+ result IDs rather than filesystem paths. The producer owns retention and
163
+ declares the lifetime and availability of the bytes across restart or
164
+ relocation. Preserve that information with the result reference. If a
165
+ temporary result expires, report that explicitly. The original call retains
166
+ its recorded outcome.
167
+
168
+ The contract gate defines callback negotiation, request and response envelopes,
169
+ cancel signaling, inline limits, result reference and read shapes, result
170
+ retention, and client event and recovery shapes. Record adjustable defaults in
171
+ [BUSINESS_RULES.md](../../BUSINESS_RULES.md).
172
+
173
+ ## Acceptance
174
+
175
+ Use scripted inference, controlled handlers, and observable effects:
176
+
177
+ 1. Register one consumer function and call it through a real stdio session.
178
+ Verify schema validation, approval for the exact call, one invocation, and
179
+ a committed result that reaches the next inference. Verify Bob's channel
180
+ completes while Alice is waiting for her callback.
181
+ 2. Verify fixed registration cannot be removed, revoked grants survive reopen,
182
+ and runtime tools can be enabled and removed from the registered catalog.
183
+ Check that denied tools stay out of the offered list and that retry uses
184
+ the same list as the initial attempt.
185
+ 3. Revoke a tool after inference offered it but before dispatch, including
186
+ while approval is pending. Verify a skipped outcome and no callback effect.
187
+ 4. Time out a dispatched callback while the turn stays live. Verify one
188
+ paired timeout result reaches the next inference and a late reply cannot
189
+ change it or trigger another inference. Separately interrupt a turn and
190
+ verify a late reply starts no further work. Simulate a lost response, then
191
+ reopen and verify the effect remains uncertain and the callback is never
192
+ repeated automatically. Verify other channels continue while the connection
193
+ is available.
194
+ 5. Verify a callback can outlast a short test deadline on a different tool.
195
+ Check that tool-specific deadlines override the session default, and that
196
+ an unset deadline does not end a running call. While suspension is waiting
197
+ on the untimed call, show its identity and verify interruption resolves
198
+ the wait without replaying it. Verify acp-client supervision leaves a
199
+ quiet callback active beyond the host's ordinary output-silence interval.
200
+ 6. Return a result larger than a stdio frame from a producer that the harness
201
+ cannot reach by a shared filesystem path. Verify the callback succeeds,
202
+ the model sees a preview and result ID, and the producing channel can
203
+ read the result through the scoped reader. Verify another channel, an
204
+ arbitrary path, and an expired reference produce the appropriate errors.