@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,135 @@
1
+ # Native harness channel controls
2
+
3
+ Status: proposed behavior for review.
4
+
5
+ ## Scope
6
+
7
+ A session can run several channels concurrently, with one active turn per
8
+ channel. A consumer can manage a single channel and its work while other
9
+ channels continue. This slice builds on the durable inbox, timeline, and
10
+ iteration checkpoints in the [persistence spec](../11-16-persistence/SPEC.md).
11
+ Implementation should start from the accepted persistence branch or a base
12
+ that includes it.
13
+
14
+ Scope covers send, withdraw, and interrupt, plus channel create, suspend,
15
+ resume, edit, and delete. Context reset, a hold that continues accepting
16
+ messages, policy changes, and model settings are separate design work.
17
+
18
+ ## Messages and turns
19
+
20
+ - **Send.** Acknowledge after the harness durably accepts the input. Preserve
21
+ the existing input ID deduplication rules. An active turn takes pending
22
+ input at its next inference boundary. An open channel starts a new turn
23
+ when there is pending work and no turn can take it. Turn outcomes remain
24
+ separate from send acknowledgment. Taken input enters the timeline and
25
+ becomes eligible for inference context.
26
+ - **Withdraw.** Remove an untaken input from pending delivery. Withdrawal
27
+ competes atomically with take. If take won, return the owning turn ID.
28
+ If withdrawal won, report the withdrawn outcome, retain it across restart,
29
+ and keep the input out of the timeline. A retry with the same ID and payload
30
+ cannot make the input pending again.
31
+ - **Interrupt.** Target a specific active turn ID. Request cancellation and
32
+ end that turn without waiting for its inference or tool to finish. A stale
33
+ interrupt cannot affect a newer turn. Keep taken inputs and committed
34
+ timeline entries attached to the interrupted turn. Untaken inputs stay
35
+ pending and are eligible to start another turn if the channel and session
36
+ allow execution. Fence off late results. Any external effect whose outcome
37
+ is unknown remains uncertain and is never replayed automatically.
38
+
39
+ If interrupt wins while a channel is suspending, end the turn and complete
40
+ channel suspension without a checkpoint. Untaken inputs remain pending.
41
+ If the checkpoint commits first, the turn is no longer active and interrupt
42
+ reports that it did not interrupt a turn. The checkpoint stays intact.
43
+
44
+ ## Channel lifecycle
45
+
46
+ The channel's lifecycle is separate from its turn status. An open channel
47
+ can be idle or working. A suspending channel can be finishing an iteration.
48
+ A suspended channel may have a checkpoint and pending input.
49
+
50
+ | Operation | Behavior |
51
+ | --- | --- |
52
+ | **Create** | Open a channel with a stable ID and optional display name. Creation alone starts no turn. The first accepted participant message to an unused ID can also create the channel, as in the persistence baseline. |
53
+ | **Suspend** | Close admission and stop taking pending input or starting new iterations. Finish the active inference and the tools it requested, if any. Complete the turn if it can finish at that boundary. Otherwise, commit a checkpoint and mark the channel suspended. Preserve pending input in either case. |
54
+ | **Resume** | Clear the channel's individual suspension. When the session permits execution, continue the checkpointed turn under its original ID and make pending input eligible for normal delivery. |
55
+ | **Edit** | Update the display name. Keep the channel ID, history, and execution state. |
56
+ | **Delete** | Retire the channel only when it has no active or checkpointed turn and no pending input. Check eligibility and retire the ID atomically with respect to send and scheduling. Preserve the timeline and reserve the retired ID. |
57
+
58
+ Once individual suspension begins, reject new messages and inbound notices
59
+ for that channel with a stable channel-suspended error. A retry of an
60
+ already-accepted input still returns its recorded outcome. The finishing turn
61
+ can send notices to other channels where admission is open. After suspension
62
+ completes, success means the channel and any checkpoint are durable.
63
+
64
+ Keep the session suspension and individual channel suspension independent.
65
+ Session resume starts only channels eligible to run. Individually suspended
66
+ channels remain suspended. Resuming an individual channel while the session
67
+ is suspended clears its individual suspension and preserves any checkpoint
68
+ under the session suspension. Admission and execution wait for session resume.
69
+
70
+ A committed individual suspension survives restart. If the process dies
71
+ before individual suspension commits, apply crash recovery to the unfinished
72
+ turn. Mark it interrupted, report any uncertain tool effects, and preserve
73
+ untaken input. Reopen the channel for work subject to the session lifecycle.
74
+ An interrupted session-wide suspension leaves any independently committed
75
+ channel suspension and its checkpoint intact.
76
+
77
+ Deleting a channel rejects new sends, inbound notices, and explicit create
78
+ requests for the retired ID. Callers can withdraw pending inputs before
79
+ retrying deletion. Historical records still refer to the retired ID. A
80
+ checkpoint with incompatible execution configuration stays intact until a
81
+ compatible resume is possible. Deletion requires the checkpoint to be resolved.
82
+
83
+ ## Persistence compatibility
84
+
85
+ Databases and archives produced by the accepted persistence revision can
86
+ open or import. Existing channels have no individual suspension. A stored
87
+ session-wide suspension and its checkpoints retain their original resume
88
+ behavior. Databases and archives created by this slice preserve individual
89
+ suspensions, withdrawn outcomes, and retired IDs.
90
+
91
+ ## Public behavior and acceptance
92
+
93
+ Expose operations and observable outcomes through the session API and typed
94
+ client. Status exposes channel lifecycle, turn status, and pending input
95
+ independently. Pending work on a suspended channel remains visible as waiting
96
+ for resume. It does not make the session report active execution by itself.
97
+ Document exact wire names, error codes, and compatibility
98
+ choices in the contract decision before changing implementation.
99
+
100
+ Use deterministic barriers with a scripted model and controlled tools:
101
+
102
+ 1. **Independent suspension.** Run two channels. Suspend Alice while her
103
+ tool runs and an accepted message is pending. Reject new input and
104
+ inbound notices for Alice while Bob continues. Reopen the session and
105
+ verify Alice stays suspended. Resume her channel and verify that the
106
+ completed tool does not run again and the pending message is taken once.
107
+ 2. **Session composition.** Suspend and resume the session around an
108
+ individually suspended channel. Verify it stays suspended, and that a
109
+ channel resume during session suspension preserves its checkpoint and
110
+ starts no work. Crash during a session-wide suspension and confirm an
111
+ earlier committed individual checkpoint survives. Verify suspended pending
112
+ input is visible even when no turn is executing.
113
+ 3. **Interrupt and stale requests.** Interrupt a specific turn while a tool
114
+ runs. A late result cannot advance it. Pending input may start a new
115
+ turn, and retrying the old interrupt leaves that new turn alone.
116
+ During channel suspension, test interruption on both sides of checkpoint
117
+ commit. An interrupt before commit leaves the channel suspended without
118
+ a checkpoint. An interrupt after commit preserves the checkpoint.
119
+ 4. **Withdraw versus take.** Exercise each side of the race. A withdrawn
120
+ item remains withdrawn across restart and retry. A taken item reports
121
+ its turn ID and remains on the timeline.
122
+ 5. **Delete versus send.** If acceptance wins, deletion fails while the
123
+ input remains pending or its turn remains unfinished. If deletion wins,
124
+ the send is rejected. Reopening preserves the retired ID and timeline.
125
+ Verify that neither create nor first send can reuse a retired ID. Verify
126
+ first send can still create an unused channel, and that explicit create
127
+ and edit leave an idle channel idle with the same ID.
128
+ 6. **Crash during suspension.** Kill the process before the checkpoint
129
+ commits. Reopen with the taken inputs on an interrupted turn and
130
+ untaken input still recoverable. Verify the channel can accept new work.
131
+ 7. **Compatibility.** Open a database and import an archive produced by
132
+ the accepted persistence revision. Verify ordinary channels still run
133
+ and session-wide checkpoints still resume explicitly. Verify an
134
+ incompatible individual checkpoint remains intact after attempts to
135
+ resume or delete its channel.
@@ -0,0 +1,143 @@
1
+ # Configuration and permissions work log
2
+
3
+ Branch `aiagent/cod1a-config-permissions`, based on session-file closure
4
+ `df43007`. Spec/plan `821f5f6` cherry-picked as `610451d`. Implementer:
5
+ cod1a-m; independent reviewer: gro1a-o; coordinator: haurness-l.
6
+
7
+ ## Stage 1: contract and decision
8
+
9
+ Decision 0016 and the contract types define config provisioning, durable policy
10
+ references, approval wire messages and lifecycle ordering. Contract review is
11
+ required before implementation. Typecheck and the retry, notice/restart and
12
+ suspension/dispatch traces are the gate.
13
+
14
+ Gro reviewed `92605f3` without approval and requested locks for legacy migration
15
+ and signatures, canonical checkpoint fingerprints, initialization and interrupt
16
+ semantics, and incompatible execution and channel policy edits. The follow-up
17
+ records those requirements; Stage 2 remains blocked on independent approval.
18
+
19
+ Gro approved contract revision `d09cb7e`; their independent typecheck passed.
20
+ Stage 2 is in progress. Its first increment provides pure config validation,
21
+ policy precedence, canonical policy fingerprints, signature and inherited
22
+ reference helpers, and `config/validate` over both client transports. These do
23
+ not yet enforce policies at dispatch or provide managed reopen. The focused
24
+ validation and policy tests are separate from the required Stage 2 gate.
25
+
26
+ ### Stage 2: configuration and policy implementation
27
+
28
+ The implementation adds managed per-session paths, active and saved config
29
+ selection, validation, format 4 policy metadata and archive 3 migration,
30
+ policy-aware input signatures and transitive notice references, and canonical
31
+ checkpoint-policy fingerprints. A mismatched policy reference permits
32
+ inspection without executing; legacy incompatible SQLite sessions use an
33
+ isolated inspection view. Fresh-home session-file import reopens using saved
34
+ config. `29b4856` introduced pure validation and policy helpers; `ad71378` and
35
+ `8cb8888` extended the reviewed contracts before their implementation.
36
+
37
+ The scripted-only config raised a scope question because the existing explicit
38
+ `--db` development path also supports OpenRouter. The coordinator confirmed
39
+ that this provider needs managed config as part of the work.
40
+ Tool dispatch enforcement and consumer approvals belong to Stage 3 and are not
41
+ yet implemented; Stage 2 must be reviewed before that work starts.
42
+
43
+ The user approved extending managed config for OpenRouter. Contract amendment
44
+ 0017 and its types are submitted separately before provider implementation.
45
+ It preserves the existing OpenRouter compatibility key, records only the
46
+ environment variable name, and leaves key values in the destination process.
47
+
48
+ Gro approved amendment `6cac6d2`: a custom `apiKeyEnv` is resolved only by
49
+ that name, without falling back to `OPENROUTER_API_KEY`. The key value and
50
+ variable name are deliberately excluded from checkpoint fingerprints; changing
51
+ the referenced credential therefore does not block resume. A legacy direct
52
+ `provider.apiKey` can be used for the current open only when no saved config
53
+ exists, and is never persisted. The destination must supply the saved reference
54
+ on later opens. Provider tests use injected offline models and fake secrets.
55
+
56
+ The Stage 2 implementation supports scripted and OpenRouter managed configs,
57
+ keeps the original provider checkpoint key, resolves the selected environment
58
+ reference on open, and does not persist credential values. Fake-provider tests
59
+ cover fresh-home import/reopen, custom environment selection, missing keys,
60
+ sidecar/model precedence, model and reference checkpoint compatibility, and a
61
+ pre-managed provider checkpoint. Provider error text is redacted if it echoes
62
+ the credential. SQLite statement cleanup was tightened after a migrated-session
63
+ reopen exposed a lock retained by prepared statements. `engine.ts` remains over
64
+ 400 lines because both adapters share its transactional lifecycle and policy
65
+ rules; splitting that engine is deferred to a dedicated change.
66
+
67
+ Stage 2 gate: `bun run typecheck` passed; `bun test ./test` passed 209 tests,
68
+ 0 failures, 2753 assertions across 25 files (52.39s), using local IPC access.
69
+ The gate includes both-adapter migration and inherited-notice tests, managed and
70
+ explicit-db reopen, fresh-home session-file import, and offline fake-provider
71
+ credential and checkpoint tests.
72
+
73
+ Gro approved Stage 2 at `47cd4df`; their independent typecheck passed and the
74
+ full suite passed 209 tests, 0 failures, 2753 assertions (73.23s).
75
+
76
+ ## Stage 3: dispatch and approvals
77
+
78
+ Gro approved dispatch-evidence decision 0018 at `4ef6286`, confirmed distinct
79
+ interrupt/stop close codes in `d67c693`, and approved owner-config binding at
80
+ `00ecb36`. The gate resolves policies from the storage owner's immutable config,
81
+ tracks approval requests and unused grants, and commits dispatch evidence before
82
+ invoking a tool. Pending approval closure writes its paired result before live
83
+ interrupt, stop or checkpoint; crash recovery never replays a request or grant.
84
+ The stdio and in-process paths expose the same approval event and answer request.
85
+
86
+ Gate: `bun run typecheck` passed; `bun test ./test` passed 243 tests, 0 failures,
87
+ 2917 assertions across 29 files (64.41s), with local IPC access. Focused tests
88
+ cover policy precedence at take, inherited notices, deny/unhandled/timeout/
89
+ disconnect, one-time grants, both suspension/dispatch orders, reentrant
90
+ interrupt and stop, a real crash with approval pending, legacy and invalid
91
+ dispatch evidence, and owner-config mismatch/failure/mutation on both adapters.
92
+ Gro approved Stage 3 at `bb171b22fe165eab82837c70432e23a83f0b64e5`; their
93
+ independent typecheck passed and the full suite passed 243 tests, 0 failures,
94
+ 2917 assertions across 29 files (63.15s). The reviewer noted that archive
95
+ import rejects duplicate call IDs across a whole turn while append uniqueness
96
+ is per message; this is an accepted non-blocking boundary.
97
+
98
+ ## Stage 4: public interface and end-to-end
99
+
100
+ The typed client exports the managed configuration and approval types. Usage
101
+ and architecture documentation describe policy selection, approval lifecycle,
102
+ saved-config reopening, and externally supplied OpenRouter credentials. The
103
+ scripted SQLite acceptance scenario runs through both in-process and real stdio
104
+ clients: Bob completes while Alice waits; suspension closes Alice's approval
105
+ without a tool effect; export and fresh-home import reopen the saved config;
106
+ the old answer remains unavailable; the resumed model receives the paired
107
+ cancellation result; and a fresh one-time approval dispatches exactly once.
108
+ A malformed stdio approval event without a turn ID is rejected. Request capture
109
+ is an opt-in scripted-test facility.
110
+
111
+ Stage 4 implementation gate: `bun run typecheck --pretty false` passed;
112
+ `bun test ./test` passed 245 tests, 0 failures, 2953 assertions across 30 files
113
+ (52.17s), with local IPC access. Gro approved the behavior revision
114
+ `626783ef308be1a39e8b276eb10a71e19e8ec288`. Their independent typecheck
115
+ passed and the full suite passed 245 tests, 0 failures, 2953 assertions across
116
+ 30 files (48.10s). This closes the configuration and tool permissions slice.
117
+
118
+ ## Closure and retrospective
119
+
120
+ The accepted contract revisions are 0016 at `d09cb7e`, OpenRouter amendment
121
+ 0017 at `6cac6d2`, dispatch evidence 0018 at `4ef6286`, close-code naming at
122
+ `d67c693`, and owner binding at `00ecb36`. Gro independently approved Stage 2
123
+ at `47cd4df`, Stage 3 at `bb171b2`, and Stage 4 at `626783e`. The earlier
124
+ session-file behavior remains `7e49bd5`; storage format 4, logical archive 3,
125
+ and session-file envelope 1 remain unchanged by Stage 4.
126
+
127
+ The contract-first reviews caught missing migration and race guarantees, and
128
+ required a separate owner-config binding before the dispatch gate could be
129
+ completed. Those decisions and the separate stage gates made the repeated
130
+ review work explicit. The OpenRouter scope amendment preserved the development
131
+ path while testing provider behavior offline without live credentials.
132
+
133
+ Accepted boundaries: automatic approval review, configured tool adapters,
134
+ shared-history access policies and pattern matching remain out of scope. An
135
+ invalid sidecar fails open with a validation error; it neither falls through to
136
+ nor replaces the saved config. Interrupt and stop approval cancellation codes
137
+ apply to undispatched approvals; a dispatched call follows the uncertain-effect
138
+ rules. Custom credential environment references have no fallback, and provider
139
+ secrets are supplied at runtime. The transfer/open announced-size limit still
140
+ applies before body bytes are received. A pre-format-4 session lacking the
141
+ legacy policy opens for inspection without migrating or recovering its owned
142
+ file. Archive import's turn-wide duplicate-call-ID restriction is stricter than
143
+ append's per-message uniqueness. No merge was requested.
@@ -0,0 +1,93 @@
1
+ # Configuration and tool permissions implementation plan
2
+
3
+ Status: proposed for review.
4
+
5
+ ## Scope and module map
6
+
7
+ Implement the session configuration, tool policy, and consumer approval flow in
8
+ [SPEC.md](SPEC.md). Start from session-file closure `df43007`, which includes
9
+ the accepted channel-controls revision and session-file codec. Record the exact
10
+ base in the work log at assignment. Use existing tools to prove the flow through
11
+ the session API and typed client, including export and reopen.
12
+
13
+ Paths below are relative to the native harness package.
14
+
15
+ | Area | Code | Responsibility |
16
+ | --- | --- | --- |
17
+ | Contracts | New config and permission contracts in `src/contracts/`, plus existing agent, session, storage, event, and protocol contracts | Define validated config, policy references, approval requests and answers, and lifecycle outcomes. |
18
+ | Configuration | Existing `src/runtime/config/` | Add pure config validation and managed session path resolution. Load one config at open from the optional sidecar or saved config. Keep credential resolution at runtime and expose validation to the consumer. |
19
+ | Policy | New `src/governance/policy/` | Resolve the named policy for accepted input and calculate the strictest applicable decision for each tool call. Keep the resolver independent of transport, storage and inference. |
20
+ | Permissions | New `src/governance/permissions/` | Gate the executor. Own pending requests, IDs, allow-once decisions, timeouts and cancellation. Tie each decision to the exact tool call. |
21
+ | Storage and recovery | Existing `src/state/storage/` | Persist policy references with channels and items, preserve them across restart and export, and validate checkpoint compatibility. Save and load portable config through the session-file contract. |
22
+ | Scheduler and assembly | Existing `src/kernel/` and `src/index.ts` | Supply the policies of taken inputs and lifecycle signals through contracts. Assembly injects the gate at the existing tool execution boundary. Reuse paired tool results and the current iteration checkpoint. |
23
+ | Public interfaces | Existing `src/client.ts`, `src/interfaces/client.ts`, and protocol adapters | Expose validation and approval operations. Carry request publication, the consumer's answer, and disconnect to the appropriate session services. |
24
+ | Verification | Existing `src/testing.ts` and `test/` | Use scripted inference, controlled lifecycle barriers, and tools with observable effects. Exercise the same gate through in-process and stdio entry points. |
25
+
26
+ Keep policy resolution out of the kernel and approval state out of the transport.
27
+ The policy resolver decides `allow`, `ask`, or `deny`. The permissions gate
28
+ applies that result and controls dispatch. A grant for one call cannot authorize
29
+ another call, including a later call with the same tool name and arguments.
30
+
31
+ ## Implementation stages and acceptance gates
32
+
33
+ | Stage | Work and dependencies | Acceptance gate |
34
+ | --- | --- | --- |
35
+ | **1. Contracts** | Define the config schema and provisioning, input signatures and resolved policy metadata, and inherited policy references on notices. Align the portable config with the session-file contract. Specify approval outcomes, the dispatch boundary, and how skipped calls are reported. | Typecheck and trace retry after a policy edit, notice delivery across restart, and both orders of suspension versus approved dispatch. Identify when the executor may run and which events the caller sees. |
36
+ | **2. Config and policy** | Implement validation, startup lookup, policy resolution, persistence of references, and the session-file integration. Keep the effective config fixed for the open session. | Validate startup and reopen behavior, including import into a fresh home without a sidecar. Verify an identical retry retains its original policy, a changed explicit policy conflicts, and a restored notice carries source restrictions that apply at take. |
37
+ | **3. Execution gate** | Gate every dispatch for the existing executor. Add approvals, one-time consumption, timeouts and lifecycle cancellation. Emit `tool_call: started` at dispatch and record paired results for skipped calls. | Check allow, deny, approval, timeout, missing handler and disconnect with an observable tool. Verify another channel keeps working. Use a barrier to test both orders of suspension versus dispatch after approval, including tool effects and started events. |
38
+ | **4. Client and end-to-end** | Expose the flow through the typed client and both transports. Update the architecture and usage docs. | Run the scripted stdio scenario below, typecheck, and run the full harness suite. Verify equivalent approval behavior in process. Independently review the exact final revision and record the results. |
39
+
40
+ For the wire contract, start by evaluating an approval event plus an answer
41
+ request keyed by request ID. It fits the current event and request paths.
42
+ Gate 1 should compare it with the callback shape in the older protocol spec
43
+ and record the choice, including how requests become unavailable on disconnect.
44
+
45
+ ### End-to-end gate
46
+
47
+ Run a scripted SQLite session through the public client against a real stdio
48
+ child. Alice proposes a tool call that requires approval. While her approval is
49
+ pending, Bob completes a turn. Suspend Alice's channel, verify the tool has
50
+ produced no effect, and send a late answer for the closed request. Resume Alice
51
+ and verify that the next model call receives the recorded
52
+ `approval_cancelled_by_suspension` result. Have the script request the action
53
+ again. Approve the new request and verify that the tool runs once.
54
+
55
+ Use deterministic barriers to check the boundary between approval and dispatch.
56
+ Cover session suspension, interruption, and stop at the focused test level.
57
+
58
+ ## How we work
59
+
60
+ ### Shared rules
61
+
62
+ - Follow [AGENTS.md](../../../AGENTS.md) and [ARCHITECTURE.md](../../../ARCHITECTURE.md).
63
+ Land contract changes with their decision records ahead of dependent changes.
64
+ - Use one implementation branch. Record its base, stage revisions, decisions,
65
+ and verification results in `LOG.md` once work starts.
66
+ - Use scripted models and controlled tools for offline checks. Identify the
67
+ exact revision in each review handoff.
68
+
69
+ ### Coordinator
70
+
71
+ Assign one implementer and one independent reviewer when scope is approved.
72
+ Confirm the channel-controls base, resolve product or contract questions,
73
+ and check the final evidence against the spec.
74
+
75
+ ### Implementer
76
+
77
+ Own the branch edits. Run each stage's gate and send the reviewer the exact
78
+ revision and evidence. Resolve findings directly and send the revised commit
79
+ back for review.
80
+
81
+ ### Reviewer
82
+
83
+ Review each revision independently and send findings directly to the
84
+ implementer. Check that every tool dispatch passes the gate, policy reflects
85
+ the inputs the turn took, and late responses cannot reach the executor.
86
+ Approve each gate explicitly after fixes. Bring scope changes or disputed
87
+ blockers to the coordinator. An approved stage can proceed to the next one.
88
+
89
+ ## Closure
90
+
91
+ Record the accepted revision, review outcome, gate results, and remaining
92
+ limitations in `LOG.md`. Include a short retrospective on coordination,
93
+ review, and any work that had to be repeated.
@@ -0,0 +1,181 @@
1
+ # Native harness configuration and tool permissions
2
+
3
+ Status: proposed for review.
4
+
5
+ ## Scope
6
+
7
+ A consumer can configure a session, assign tool policies to channels and
8
+ individual messages, and answer approval requests for specific tool calls.
9
+ The harness enforces those decisions before executing a tool. Use the
10
+ existing tools and scripted inference to verify the flow.
11
+
12
+ This slice builds on the durable inbox and checkpoints in the
13
+ [persistence spec](../11-16-persistence/SPEC.md) and the channel lifecycle in
14
+ the [channel-controls spec](../11-19-channel-controls/SPEC.md).
15
+ Configured tool adapters, shared-history access policies, and
16
+ [automatic approval review](../todos/11-19-TODO-auto_review-approve.md)
17
+ are separate work.
18
+
19
+ ## Session configuration
20
+
21
+ Each open session uses one validated configuration. The provisional
22
+ default home is `~/.harness`, with `--home` as an override.
23
+
24
+ ```text
25
+ <home>/<session_id>/
26
+ config.json # optional
27
+ session.sqlite
28
+ ```
29
+
30
+ Configuration contains the system prompt, model selection, named tool policies,
31
+ and the default policy. At creation, the consumer can supply it directly or
32
+ provide `config.json`. The server keeps the validated configuration in memory
33
+ while the session is open and saves a portable copy with the session so it
34
+ can reopen without a sidecar.
35
+
36
+ When `config.json` is present at open, it supplies the configuration for that
37
+ open. Otherwise, load the saved copy. File edits take effect on the next open.
38
+ An invalid file produces a validation error without replacing the saved copy.
39
+ Expose validation separately so a consumer can check configuration before
40
+ starting inference. Errors identify the invalid field or policy reference.
41
+ Use environment references for credentials and resolve their values at runtime.
42
+
43
+ On reopen, validate stored policy references before enabling execution. A
44
+ configured policy that still exists can change its rules for future turns
45
+ after reopen. Resuming a checkpoint also requires compatible execution
46
+ configuration, including the policy definitions relevant to that checkpoint.
47
+ If the configuration is incompatible, leave the checkpoint and pending inputs
48
+ intact and allow inspection.
49
+
50
+ ### Export and import integration
51
+
52
+ The [session-file amendment](../persistence/0002-AMENDMENT-session-file/SPEC.md)
53
+ defines the binary file format and saves the active, validated config
54
+ atomically with the imported snapshot. The config loader opens the restored
55
+ session from that saved config without a sidecar or an inline config argument.
56
+
57
+ Use the per-session directory for managed sessions. This slice replaces the
58
+ experimental flat database layout without migration support. Preserve the
59
+ explicit development `--db` path.
60
+
61
+ ## Tool policy
62
+
63
+ Proposed first rule format. Each named policy has an explicit fallback of
64
+ `allow`, `ask`, or `deny`, and may override that fallback by exact tool
65
+ name. Require the session default to name a defined policy. An example
66
+ policy can allow `current_time`, ask for `dashboard_work`, and deny every
67
+ other tool. Pattern matching can be designed when a consumer needs it.
68
+
69
+ Resolve the policy for each input in this order:
70
+
71
+ 1. The policy explicitly supplied by the trusted consumer for that message.
72
+ 2. The channel's configured policy.
73
+ 3. The session's default policy.
74
+
75
+ Reject an unknown explicit policy when accepting input or updating a
76
+ channel. Persist the resolved policy name with the accepted item so a
77
+ channel policy change cannot silently reclassify waiting input. A message
78
+ body cannot set its own policy.
79
+
80
+ Include the submitted explicit policy, or its absence, in the input's
81
+ deduplication identity. An identical retry returns the original receipt
82
+ and preserves the policy resolved at first acceptance, even after a
83
+ channel policy change. Reusing the same message ID with a different
84
+ explicit policy returns `item_conflict`, even if both requests would
85
+ resolve to the same policy.
86
+
87
+ For internal notices, the harness records the source turn's contributing
88
+ policy references at acceptance, including any restrictions inherited from
89
+ earlier notices. The model cannot supply a policy override. When the target
90
+ turn takes the notice, combine the stored source references with the
91
+ target's policy resolved at acceptance and the policies of any other
92
+ inputs the target turn has taken. Preserve those references across restart
93
+ and export/import. A notice cannot grant the target turn tool permissions
94
+ that its source turn lacked under the open configuration.
95
+
96
+ A policy contributes to the active turn when the turn takes the input.
97
+ For each proposed tool call, evaluate the applicable rules across all
98
+ inputs the turn has taken. `deny` wins over `ask`, and `ask` wins over
99
+ `allow`. The decision for one tool need not match the decision for another.
100
+ A later input can tighten tool permissions for the remainder of that turn.
101
+ An input still waiting in the inbox has no effect on the turn. A tool
102
+ already running is unaffected. A fresh turn starts with the policies of
103
+ the inputs it takes.
104
+
105
+ This intentionally makes no distinction between chat text that asks to
106
+ change the work and chat text that only asks for an update. Either can
107
+ tighten an active turn after take. Tool policy governs execution and does
108
+ not define who can read the shared timeline.
109
+
110
+ ## Consumer approval
111
+
112
+ Check policy in code immediately before tool execution. `allow` permits
113
+ the call. `deny` produces a paired tool result without invoking it. `ask`
114
+ opens one approval request for the exact call, with a request ID, channel
115
+ ID, turn ID, tool call ID, tool name, and arguments. The consumer can
116
+ allow once or deny. Approval does not change a policy or authorize
117
+ different arguments, later calls, or another turn.
118
+
119
+ A waiting approval occupies only its own turn. Other channels continue.
120
+ Give each request a bounded timeout. Denial, timeout, a missing approval
121
+ handler, or disconnection of the approval consumer closes the request
122
+ and leaves its tool unexecuted. Record the reason in the paired tool
123
+ result if the turn continues.
124
+
125
+ Publish `tool_call: started` when the tool is dispatched. Waiting for
126
+ approval, granting approval, and recording a result for a skipped call
127
+ do not emit `started`. The execution gate orders dispatch against
128
+ cancellation. If suspension wins before an approval-gated call is
129
+ dispatched, close the request or discard the unused grant, and record
130
+ `approval_cancelled_by_suspension`. If dispatch wins, the running tool
131
+ finishes under the normal suspension rules. An allow-once grant is
132
+ consumed at dispatch and cannot be reused.
133
+
134
+ On channel or session suspension, close outstanding approvals in the
135
+ affected part of the session and record a paired tool result with reason
136
+ `approval_cancelled_by_suspension`. Further requests in the finishing
137
+ iteration that would require approval receive the same result. The
138
+ result explains that the tool did not run and that the resumed turn can
139
+ make a fresh call to request approval if the action is still needed.
140
+ Finish the iteration using the existing checkpoint rules.
141
+
142
+ Interrupt or stop closes requests for interrupted turns and fences off
143
+ tool execution. A late or duplicate response cannot reopen a request.
144
+ An unanswered request never survives as executable approval across
145
+ restart or resume. Serialize decision, cancellation, and tool dispatch so
146
+ a response arriving after cancellation cannot cause the tool to run.
147
+
148
+ ## Acceptance
149
+
150
+ Use a scripted model and observable tool effects to verify the public
151
+ approval flow without provider credentials.
152
+
153
+ 1. Open with valid configuration, reject invalid fields without changing
154
+ saved state, and verify file edits apply on reopen. Remove the sidecar
155
+ after opening, export a binary `.harness` file, then import and reopen in
156
+ a fresh home without a sidecar. Verify the imported config matches the
157
+ version the source server used. Reject invalid or unsupported file formats.
158
+ 2. Resolve message, channel, and default policies. Verify one policy
159
+ combination before and after take, including a tool that remains
160
+ permitted by both policies. Reject an unknown named policy.
161
+ Retry an accepted message after a channel policy change and verify
162
+ its resolved policy stays the same. Reuse its ID with a changed explicit
163
+ policy and verify a conflict. Reopen with a pending notice from a more
164
+ restrictive source and verify that the target turn still enforces that
165
+ restriction when it takes the notice.
166
+ 3. Exercise allow, deny, and ask through the execution gate. An approval
167
+ runs the exact call once. A denied, timed-out, disconnected, or
168
+ unhandled request produces no tool effect. Verify a second channel
169
+ can finish while the first waits.
170
+ 4. Suspend a turn awaiting approval, resume it, and observe the recorded
171
+ suspension reason in its model context. A late response produces no
172
+ tool effect. If the model requests the action again, it receives a
173
+ new approval request. Interrupt and stop likewise fence late approval.
174
+ Exercise both orders of suspension versus dispatch after approval.
175
+ Before dispatch, suspension produces the distinct cancellation result
176
+ with no tool effect or started event. After dispatch, suspension lets
177
+ the running call finish, with exactly one started event.
178
+
179
+ Record the configuration shape, policy metadata, approval wire contract,
180
+ and lifecycle race outcomes in a contract decision before dependent code
181
+ changes.