@qlairoslabs/acp-client 0.13.0-alpha.1 → 0.13.1-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 (263) hide show
  1. package/CONSUMER_GUIDE.md +147 -8
  2. package/MIGRATION-0.12-to-0.13.md +20 -7
  3. package/package.json +9 -2
  4. package/src/agent/conversation-manager.ts +1 -0
  5. package/src/agent/native-operations.ts +39 -0
  6. package/src/agent-session-config.ts +2 -0
  7. package/src/agent-session.ts +1 -0
  8. package/src/agent.ts +97 -2
  9. package/src/client.ts +5 -3
  10. package/src/controller-connection.ts +1 -0
  11. package/src/controller.ts +2 -0
  12. package/src/index.ts +1 -0
  13. package/src/launcher.ts +2 -0
  14. package/src/native/approvals.ts +20 -3
  15. package/src/native/controller.ts +3 -2
  16. package/src/native/host.ts +73 -4
  17. package/src/native-harness/scripts/build-routine-zones.py +47 -0
  18. package/src/native-harness/src/capabilities/context/session.ts +2 -1
  19. package/src/native-harness/src/capabilities/reminders/cron-calendar.ts +50 -0
  20. package/src/native-harness/src/capabilities/reminders/cron-fields.ts +46 -0
  21. package/src/native-harness/src/capabilities/reminders/cron-proof.ts +32 -0
  22. package/src/native-harness/src/capabilities/reminders/cron-zone.ts +53 -0
  23. package/src/native-harness/src/capabilities/reminders/iana-zones.json.gz +0 -0
  24. package/src/native-harness/src/capabilities/reminders/iana-zones.ts +34 -0
  25. package/src/native-harness/src/capabilities/reminders/interval.ts +30 -0
  26. package/src/native-harness/src/capabilities/reminders/routine-advance.ts +47 -0
  27. package/src/native-harness/src/capabilities/reminders/routine-backlog.ts +47 -0
  28. package/src/native-harness/src/capabilities/reminders/routine-expiry.ts +15 -0
  29. package/src/native-harness/src/capabilities/reminders/routine-occurrence.ts +65 -0
  30. package/src/native-harness/src/capabilities/reminders/routine-schedule.ts +70 -0
  31. package/src/native-harness/src/capabilities/reminders/unattended.ts +8 -0
  32. package/src/native-harness/src/capabilities/tools/reminders/index.ts +27 -5
  33. package/src/native-harness/src/contracts/config-permissions.ts +3 -1
  34. package/src/native-harness/src/contracts/protocol.ts +1 -1
  35. package/src/native-harness/src/contracts/reminders.ts +4 -2
  36. package/src/native-harness/src/contracts/routines.ts +20 -0
  37. package/src/native-harness/src/contracts/session-file.ts +1 -0
  38. package/src/native-harness/src/contracts/session.ts +2 -2
  39. package/src/native-harness/src/contracts/storage.ts +11 -10
  40. package/src/native-harness/src/index.ts +6 -2
  41. package/src/native-harness/src/interfaces/protocol/server.ts +11 -9
  42. package/src/native-harness/src/interfaces/protocol/stdio-client.ts +7 -0
  43. package/src/native-harness/src/kernel/channels.ts +8 -4
  44. package/src/native-harness/src/runtime/config/paths.ts +7 -1
  45. package/src/native-harness/src/runtime/reminder-validation.ts +31 -10
  46. package/src/native-harness/src/runtime/reminders.ts +2 -2
  47. package/src/native-harness/src/state/storage/archive.ts +27 -9
  48. package/src/native-harness/src/state/storage/engine.ts +214 -23
  49. package/src/native-harness/src/state/storage/memory-reminders.ts +31 -6
  50. package/src/native-harness/src/state/storage/memory.ts +15 -2
  51. package/src/native-harness/src/state/storage/reminder-archive.ts +53 -12
  52. package/src/native-harness/src/state/storage/reminder-change.ts +60 -14
  53. package/src/native-harness/src/state/storage/reminder-tables.ts +11 -3
  54. package/src/native-harness/src/state/storage/routine-row.ts +25 -0
  55. package/src/native-harness/src/state/storage/sqlite-reminders.ts +48 -8
  56. package/src/native-harness/src/state/storage/sqlite.ts +11 -4
  57. package/src/native-harness/src/testing.ts +1 -1
  58. package/src/native-harness/src/util/config.ts +10 -2
  59. package/src/native-harness/src/util/intake.ts +7 -0
  60. package/src/orchestrator/permissions.ts +6 -3
  61. package/src/permissions/conversation.ts +13 -5
  62. package/src/permissions/matcher.ts +2 -0
  63. package/src/permissions/outcome.ts +12 -1
  64. package/src/permissions/policy.ts +13 -8
  65. package/src/terminals.ts +9 -6
  66. package/src/native/reminders/reminders.test.ts +0 -553
  67. package/src/native/reminders/routine-config.typecheck.ts +0 -13
  68. package/src/native/reminders/wire.typecheck.ts +0 -13
  69. package/src/native-harness/.res/README.md +0 -1
  70. package/src/native-harness/.res/architecture/README.md +0 -21
  71. package/src/native-harness/.res/architecture/context-and-data.md +0 -31
  72. package/src/native-harness/.res/architecture/execution.md +0 -42
  73. package/src/native-harness/.res/architecture/overview.md +0 -44
  74. package/src/native-harness/.res/architecture/persistence.md +0 -56
  75. package/src/native-harness/.res/architecture/suspend-and-resume.md +0 -45
  76. package/src/native-harness/.res/architecture/technical-architecture.md +0 -50
  77. package/src/native-harness/.res/decisions/0001-basic-loop.md +0 -11
  78. package/src/native-harness/.res/decisions/0002-channel-input.md +0 -17
  79. package/src/native-harness/.res/decisions/0003-inference-inspection.md +0 -14
  80. package/src/native-harness/.res/decisions/0004-shared-context.md +0 -21
  81. package/src/native-harness/.res/decisions/0005-notice-inbox.md +0 -20
  82. package/src/native-harness/.res/decisions/0006-explicit-notices.md +0 -12
  83. package/src/native-harness/.res/decisions/0007-channel-output.md +0 -12
  84. package/src/native-harness/.res/decisions/0008-browser-client.md +0 -16
  85. package/src/native-harness/.res/decisions/0009-scripted-model.md +0 -18
  86. package/src/native-harness/.res/decisions/0010-inprocess-protocol.md +0 -19
  87. package/src/native-harness/.res/decisions/0011-stdio-transport.md +0 -21
  88. package/src/native-harness/.res/decisions/0012-session-storage-contract.md +0 -37
  89. package/src/native-harness/.res/decisions/0013-durable-delivery-contract.md +0 -64
  90. package/src/native-harness/.res/decisions/0014-channel-controls-contract.md +0 -73
  91. package/src/native-harness/.res/decisions/0015-session-file-contract.md +0 -72
  92. package/src/native-harness/.res/decisions/0016-configuration-permissions.md +0 -159
  93. package/src/native-harness/.res/decisions/0017-openrouter-managed-config.md +0 -69
  94. package/src/native-harness/.res/decisions/0018-tool-dispatch-evidence.md +0 -78
  95. package/src/native-harness/.res/decisions/0019-model-execution.md +0 -188
  96. package/src/native-harness/.res/decisions/0020-startup-channel-changes.md +0 -71
  97. package/src/native-harness/.res/decisions/0021-tools-and-host-callbacks.md +0 -100
  98. package/src/native-harness/.res/decisions/0022-operator-controls.md +0 -115
  99. package/src/native-harness/.res/decisions/0023-long-running-mock.md +0 -82
  100. package/src/native-harness/.res/decisions/0024-callback-policy-names.md +0 -46
  101. package/src/native-harness/.res/decisions/0025-external-notices.md +0 -364
  102. package/src/native-harness/.res/decisions/0026-bounded-context.md +0 -81
  103. package/src/native-harness/.res/decisions/0027-development-instructions.md +0 -22
  104. package/src/native-harness/.res/decisions/0028-debug-tools.md +0 -16
  105. package/src/native-harness/.res/decisions/0029-bounded-model-call-pages.md +0 -37
  106. package/src/native-harness/.res/decisions/0030-timeline-retrieval.md +0 -145
  107. package/src/native-harness/.res/decisions/0031-one-off-reminders.md +0 -173
  108. package/src/native-harness/.res/docs/11-15.md +0 -148
  109. package/src/native-harness/.res/docs/BUSINESS_RULES.md +0 -111
  110. package/src/native-harness/.res/docs/WORK.md +0 -65
  111. package/src/native-harness/.res/docs/_/11-16-persistence/LOG.md +0 -312
  112. package/src/native-harness/.res/docs/_/11-16-persistence/PLAN.md +0 -77
  113. package/src/native-harness/.res/docs/_/11-16-persistence/SPEC.md +0 -313
  114. package/src/native-harness/.res/docs/_/11-19-channel-controls/LOG.md +0 -160
  115. package/src/native-harness/.res/docs/_/11-19-channel-controls/PLAN.md +0 -89
  116. package/src/native-harness/.res/docs/_/11-19-channel-controls/SPEC.md +0 -135
  117. package/src/native-harness/.res/docs/_/11-19-config-permissions/LOG.md +0 -143
  118. package/src/native-harness/.res/docs/_/11-19-config-permissions/PLAN.md +0 -93
  119. package/src/native-harness/.res/docs/_/11-19-config-permissions/SPEC.md +0 -181
  120. package/src/native-harness/.res/docs/acp-client-integration/0001-DESIGN/11-20-LOG.md +0 -433
  121. package/src/native-harness/.res/docs/acp-client-integration/0001-DESIGN/PLAN.md +0 -60
  122. package/src/native-harness/.res/docs/acp-client-integration/0001-DESIGN/PROTOCOL.md +0 -141
  123. package/src/native-harness/.res/docs/acp-client-integration/0001-DESIGN/SPEC.md +0 -168
  124. package/src/native-harness/.res/docs/attachments/0001-DESIGN/SPEC.md +0 -111
  125. package/src/native-harness/.res/docs/bounded-context/0001-DESIGN/PLAN.md +0 -129
  126. package/src/native-harness/.res/docs/bounded-context/0001-DESIGN/SPEC.md +0 -135
  127. package/src/native-harness/.res/docs/channel-messaging/0001-DESIGN-external-notices/LOG.md +0 -437
  128. package/src/native-harness/.res/docs/channel-messaging/0001-DESIGN-external-notices/PLAN.md +0 -127
  129. package/src/native-harness/.res/docs/channel-messaging/0001-DESIGN-external-notices/SPEC.md +0 -203
  130. package/src/native-harness/.res/docs/long-running-mock/0001-DESIGN/LOG.md +0 -292
  131. package/src/native-harness/.res/docs/long-running-mock/0001-DESIGN/PLAN.md +0 -91
  132. package/src/native-harness/.res/docs/long-running-mock/0001-DESIGN/SPEC.md +0 -187
  133. package/src/native-harness/.res/docs/model-execution/0001-DESIGN/LOG.md +0 -148
  134. package/src/native-harness/.res/docs/model-execution/0001-DESIGN/PLAN.md +0 -95
  135. package/src/native-harness/.res/docs/model-execution/0001-DESIGN/SPEC.md +0 -200
  136. package/src/native-harness/.res/docs/model-execution/0002-AMENDMENT-accounting/SPEC.md +0 -80
  137. package/src/native-harness/.res/docs/operator-controls/0001-DESIGN/LOG.md +0 -206
  138. package/src/native-harness/.res/docs/operator-controls/0001-DESIGN/PLAN.md +0 -106
  139. package/src/native-harness/.res/docs/operator-controls/0001-DESIGN/SPEC.md +0 -297
  140. package/src/native-harness/.res/docs/persistence/0002-AMENDMENT-session-file/LOG.md +0 -41
  141. package/src/native-harness/.res/docs/persistence/0002-AMENDMENT-session-file/PLAN.md +0 -36
  142. package/src/native-harness/.res/docs/persistence/0002-AMENDMENT-session-file/SPEC.md +0 -84
  143. package/src/native-harness/.res/docs/shell-execution/0001-DESIGN/SPEC.md +0 -147
  144. package/src/native-harness/.res/docs/timeline-retrieval/0001-DESIGN/LOG.md +0 -15
  145. package/src/native-harness/.res/docs/timeline-retrieval/0001-DESIGN/PLAN.md +0 -107
  146. package/src/native-harness/.res/docs/timeline-retrieval/0001-DESIGN/SPEC.md +0 -114
  147. package/src/native-harness/.res/docs/todos/11-19-TODO-auto_review-approve.md +0 -24
  148. package/src/native-harness/.res/docs/todos/11-20-TODO-user-entered-tool-code.md +0 -23
  149. package/src/native-harness/.res/docs/todos/11-21-TODO-node-resource-coordination.md +0 -103
  150. package/src/native-harness/.res/docs/todos/11-22-TODO-harness-m1-sequence.md +0 -50
  151. package/src/native-harness/.res/docs/tools-and-callbacks/0001-DESIGN/LOG.md +0 -337
  152. package/src/native-harness/.res/docs/tools-and-callbacks/0001-DESIGN/PLAN.md +0 -76
  153. package/src/native-harness/.res/docs/tools-and-callbacks/0001-DESIGN/SPEC.md +0 -204
  154. package/src/native-harness/.res/docs/tools-and-callbacks/0002-AMENDMENT-callback-policy/LOG.md +0 -73
  155. package/src/native-harness/.res/docs/tools-and-callbacks/0002-AMENDMENT-callback-policy/SPEC.md +0 -64
  156. package/src/native-harness/.res/docs/tools-and-callbacks/0003-DESIGN-attachment-tools/SPEC.md +0 -58
  157. package/src/native-harness/.res/docs/tools-and-callbacks/0004-DESIGN-reminder-tools/LOG.md +0 -45
  158. package/src/native-harness/.res/docs/tools-and-callbacks/0004-DESIGN-reminder-tools/PLAN.md +0 -108
  159. package/src/native-harness/.res/docs/tools-and-callbacks/0004-DESIGN-reminder-tools/SPEC.md +0 -169
  160. package/src/native-harness/.res/docs/web-tools/0001-DESIGN/SPEC.md +0 -128
  161. package/src/native-harness/.res/marketing-draft.md +0 -22
  162. package/src/native-harness/.res/sandbox/1-simple-harness/README.md +0 -285
  163. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-1.md +0 -19
  164. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-10.md +0 -138
  165. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-11.md +0 -148
  166. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-12.md +0 -172
  167. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-13.md +0 -194
  168. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-14.md +0 -233
  169. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-15.md +0 -249
  170. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-16.md +0 -265
  171. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-17.md +0 -279
  172. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-18.md +0 -293
  173. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-19.md +0 -307
  174. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-2.md +0 -29
  175. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-20.md +0 -317
  176. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-21.md +0 -327
  177. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-3.md +0 -40
  178. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-4.md +0 -59
  179. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-5.md +0 -69
  180. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-6.md +0 -79
  181. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-7.md +0 -89
  182. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-8.md +0 -102
  183. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-9.md +0 -116
  184. package/src/native-harness/.res/sandbox/1-simple-harness/conversation.jsonl +0 -49
  185. package/src/native-harness/.res/sandbox/1-simple-harness/doc.md +0 -87
  186. package/src/native-harness/.res/sandbox/1-simple-harness/harness.py +0 -289
  187. package/src/native-harness/.res/sandbox/1-simple-harness/local/harness copy 2.py +0 -221
  188. package/src/native-harness/.res/sandbox/1-simple-harness/local/harness copy 3.py +0 -287
  189. package/src/native-harness/.res/sandbox/1-simple-harness/local/harness copy.py +0 -165
  190. package/src/native-harness/.res/sandbox/1-simple-harness/state.json +0 -22
  191. package/src/native-harness/.res/sandbox/1-simple-harness/system-prompt.md +0 -2
  192. package/src/native-harness/AGENTS.md +0 -70
  193. package/src/native-harness/ARCHITECTURE.md +0 -249
  194. package/src/native-harness/bun.lock +0 -26
  195. package/src/native-harness/test/agent.test.ts +0 -130
  196. package/src/native-harness/test/approval-gate.test.ts +0 -255
  197. package/src/native-harness/test/approval-protocol.test.ts +0 -94
  198. package/src/native-harness/test/boundaries.test.ts +0 -18
  199. package/src/native-harness/test/channel-controls.test.ts +0 -322
  200. package/src/native-harness/test/client-abort.test.ts +0 -136
  201. package/src/native-harness/test/config-policy.test.ts +0 -301
  202. package/src/native-harness/test/conformance/storage.ts +0 -1141
  203. package/src/native-harness/test/context.test.ts +0 -177
  204. package/src/native-harness/test/crash.test.ts +0 -187
  205. package/src/native-harness/test/debug-tools.test.ts +0 -67
  206. package/src/native-harness/test/development-cli.test.ts +0 -67
  207. package/src/native-harness/test/development.test.ts +0 -171
  208. package/src/native-harness/test/dispatch-evidence.test.ts +0 -58
  209. package/src/native-harness/test/e2e.test.ts +0 -186
  210. package/src/native-harness/test/external-notices.test.ts +0 -101
  211. package/src/native-harness/test/fixtures/approval-e2e.jsonl +0 -4
  212. package/src/native-harness/test/fixtures/crash-scenario.jsonl +0 -5
  213. package/src/native-harness/test/fixtures/development-lifecycle.jsonl +0 -10
  214. package/src/native-harness/test/fixtures/echo-scenario.jsonl +0 -3
  215. package/src/native-harness/test/fixtures/format2-schema.ts +0 -27
  216. package/src/native-harness/test/fixtures/format3-schema.ts +0 -16
  217. package/src/native-harness/test/fixtures/hold-scenario.jsonl +0 -4
  218. package/src/native-harness/test/fixtures/model-e2e.jsonl +0 -3
  219. package/src/native-harness/test/fixtures/storage-owner.ts +0 -20
  220. package/src/native-harness/test/format-reply.test.ts +0 -10
  221. package/src/native-harness/test/helpers/operator-view.ts +0 -41
  222. package/src/native-harness/test/helpers/scenario.ts +0 -9
  223. package/src/native-harness/test/helpers/session.ts +0 -38
  224. package/src/native-harness/test/helpers/stdio.ts +0 -46
  225. package/src/native-harness/test/inspector.test.ts +0 -77
  226. package/src/native-harness/test/listeners.test.ts +0 -49
  227. package/src/native-harness/test/loop.test.ts +0 -88
  228. package/src/native-harness/test/model-channel-double.test.ts +0 -87
  229. package/src/native-harness/test/model-crash.test.ts +0 -62
  230. package/src/native-harness/test/model-delivery-regressions.test.ts +0 -55
  231. package/src/native-harness/test/model-e2e.test.ts +0 -71
  232. package/src/native-harness/test/model-final-filter.test.ts +0 -30
  233. package/src/native-harness/test/model-large-reply.test.ts +0 -28
  234. package/src/native-harness/test/model-live-queue.test.ts +0 -33
  235. package/src/native-harness/test/model-runner.test.ts +0 -117
  236. package/src/native-harness/test/model-storage.test.ts +0 -99
  237. package/src/native-harness/test/model-stream-adapter.test.ts +0 -26
  238. package/src/native-harness/test/model-stream-public.test.ts +0 -77
  239. package/src/native-harness/test/notices.test.ts +0 -64
  240. package/src/native-harness/test/openrouter-config.test.ts +0 -218
  241. package/src/native-harness/test/operator-controls.test.ts +0 -132
  242. package/src/native-harness/test/output.test.ts +0 -44
  243. package/src/native-harness/test/owner-config.test.ts +0 -64
  244. package/src/native-harness/test/permissions-e2e.test.ts +0 -68
  245. package/src/native-harness/test/persistence.test.ts +0 -236
  246. package/src/native-harness/test/portability.test.ts +0 -337
  247. package/src/native-harness/test/protocol.test.ts +0 -160
  248. package/src/native-harness/test/reminder-clock.test.ts +0 -61
  249. package/src/native-harness/test/reminder-stdio.test.ts +0 -140
  250. package/src/native-harness/test/reminder-storage.test.ts +0 -124
  251. package/src/native-harness/test/scenario-jsonl.test.ts +0 -112
  252. package/src/native-harness/test/scripted.test.ts +0 -92
  253. package/src/native-harness/test/session-file.test.ts +0 -51
  254. package/src/native-harness/test/startup-channel-changes.test.ts +0 -256
  255. package/src/native-harness/test/stdio.test.ts +0 -132
  256. package/src/native-harness/test/storage-memory.test.ts +0 -4
  257. package/src/native-harness/test/storage-sqlite.test.ts +0 -420
  258. package/src/native-harness/test/suspension.test.ts +0 -430
  259. package/src/native-harness/test/timeline-retrieval.test.ts +0 -211
  260. package/src/native-harness/test/tools-catalog.test.ts +0 -468
  261. package/src/native-harness/test/tools-protocol.test.ts +0 -418
  262. package/src/native-harness/test/transfers.test.ts +0 -94
  263. package/src/native-harness/test/web-chat.test.ts +0 -35
package/CONSUMER_GUIDE.md CHANGED
@@ -1064,8 +1064,16 @@ export async function openApprovalDemo(adapter: AgentAdapter, path: string) {
1064
1064
 
1065
1065
  Allow and deny resolve immediately. Ask first uses a per-prompt
1066
1066
  `onPermissionRequest` handler. Without one, it waits for a consumer only if
1067
- `answersPermissions` is true. Otherwise the unattended ask is refused. The
1068
- consumer wait defaults to five minutes, starts at request ingress, and expires
1067
+ `answersPermissions` is true. An ask with neither responder uses `permissions.unanswered`. The default,
1068
+ `"reject"`, refuses the tool and lets the turn continue. ACP selects
1069
+ `reject_once` when offered and sends cancellation otherwise. Native responds
1070
+ with `deny`. Use `permissions: { default: "ask", unanswered: "cancel" }`
1071
+ to send ACP's cancelled permission response or interrupt the requesting
1072
+ native turn. The setting applies only to an unanswered ask. It leaves
1073
+ explicit deny, handler responses and consumer timeout behavior unchanged.
1074
+ A forwarded ask uses the giving conversation's setting when it is
1075
+ available. Without a giving conversation, an applicable worker policy with
1076
+ `unanswered: "cancel"` cancels an otherwise unanswered ask. The consumer wait defaults to five minutes, starts at request ingress, and expires
1069
1077
  to a refusal. Supply a positive integer below 600,000 to override it.
1070
1078
  `expiresAt` is epoch milliseconds and is present only for a consumer wait.
1071
1079
  Check `answerPermission()`'s `{ accepted }` result. Unknown, expired,
@@ -1083,6 +1091,22 @@ and `deny`. The harness also has a ten-minute approval limit. A configured
1083
1091
  including while detached. Await `answer("allow_once")` or `answer("deny")`
1084
1092
  to learn whether the harness accepted the decision.
1085
1093
 
1094
+ ## Built-in ACP terminal environments
1095
+
1096
+ Set `terminalEnv` on the client, controller or conversation runtime, or
1097
+ return it from `launcher.prepare()`. The prepared value takes precedence.
1098
+ For example, `terminalEnv: { PATH: "/usr/bin:/bin", LANG: "C.UTF-8" }`
1099
+ passes exactly those environment variables to built-in terminals. Use an
1100
+ empty object to pass none. In this mode ACP terminal request environment
1101
+ entries cannot add to or override the host's environment.
1102
+
1103
+ When no exact environment is configured, the built-in ACP terminal uses the
1104
+ variables supplied in the terminal request. The hub's process environment,
1105
+ client spawn settings and the launcher's `spawnEnv` are separate.
1106
+ `TerminalRegistry` also accepts `terminalEnv` in its options and in a direct
1107
+ `create()` call. A direct per-terminal setting wins. Custom terminal
1108
+ handlers are responsible for their own environment isolation.
1109
+
1086
1110
  ## Cancellable ACP startup and deferred connections
1087
1111
 
1088
1112
  Agent-owned normal ACP conversations connect on open by default. Use
@@ -1166,7 +1190,14 @@ export async function openNative(
1166
1190
  }
1167
1191
  ```
1168
1192
 
1169
- Use a supported OpenRouter model ID configured for your account. For an offline
1193
+ Use a supported OpenRouter model ID configured for your account. `harness.config.model` is typed from the harness SDK
1194
+ and passed through unchanged on every open. Besides `scripted` and `openrouter`, the SDK defines an inference-source arm,
1195
+ `{ protocol: "openai-compatible", providerId, model, baseUrl, apiKeyEnv? }` (decision 0034): an OpenAI-compatible Chat
1196
+ Completions endpoint chosen by the consumer. `baseUrl` is HTTPS or a literal loopback address over HTTP (`127.x` or `::1`,
1197
+ not `localhost`) with no credentials, query or fragment; the harness appends the Chat Completions path and follows no
1198
+ redirects; `apiKeyEnv` names a variable in the harness's environment, is optional for keyless endpoints and is read only
1199
+ when the session opens. The library accepts and forwards this arm today (compile-time and open-request tests); the harness
1200
+ runtime that executes it is still being implemented, so an open with this arm is not yet usable end to end. For an offline
1170
1201
  equivalent, pass `{ protocol: "scripted", script: "/path/to/scenario.jsonl" }`
1171
1202
  as the second argument. Function parameters are JSON Schema. Functions return
1172
1203
  JSON values and receive a context with invocation identity and an abort signal.
@@ -1543,6 +1574,66 @@ The harness can refuse with `busy` or `next_due_soon`. A refusal leaves
1543
1574
  the session running. Work that arrives after a successful idle stop can
1544
1575
  start it again.
1545
1576
 
1577
+ ### Restart the native agent and apply live settings
1578
+
1579
+ Use `await agent.previewNativeRestart()` to get `conversationCount` and
1580
+ `conversationIds` for a confirmation dialog. The preview includes active
1581
+ native conversation records, including ones whose harness channel is created
1582
+ on first use. ACP conversations are outside its scope.
1583
+
1584
+ ```ts
1585
+ const preview = await agent.previewNativeRestart();
1586
+ const result = await agent.restartNative({ when: "idle", config: nextHarnessConfig });
1587
+ ```
1588
+
1589
+ `when: "idle"` waits for active turns, approvals and queued native input
1590
+ across the agent, then uses the harness's atomic idle stop. Use
1591
+ `waitForNativeIdle({ signal })` to wait without restarting. An idle wait is
1592
+ a snapshot and new input can arrive after it resolves. Suspended work
1593
+ with queued input can keep the wait pending. Supply an abort signal when
1594
+ the user can cancel the wait. `when: "now"` requests interruption of
1595
+ running turns and restarts the shared native process. The harness retains
1596
+ its durable queue and reminder wake. Closing the Agent cancels idle waits.
1597
+
1598
+ The executable open takes the replacement `config` and optional
1599
+ `functions` catalog. Omit either to keep the Agent's current setting.
1600
+ Pass `functions: null` to clear application-supplied functions.
1601
+ The harness applies its normal configuration precedence and compatibility
1602
+ checks, including a managed configuration sidecar when present. The
1603
+ Agent uses the new settings for subsequent opens in the same process.
1604
+ Persist application configuration separately if future Agent instances
1605
+ need to supply it.
1606
+
1607
+ `subscribeNativeRestart(listener)` returns an unsubscribe function.
1608
+ The listener receives the same `restarted` or `restart_failed` result
1609
+ as the caller, with interrupted harness turn IDs and per-conversation
1610
+ outcomes. A `reconnected` channel was reconciled by the replacement
1611
+ open. A `deferred` conversation has no channel in that open and can
1612
+ materialize on use. On failure the result includes the error. Native
1613
+ conversation handles retain their identity and subscriptions.
1614
+
1615
+ Read `agent.channelSettingsLive` for channel-scoped edits, session-wide
1616
+ tool controls and settings to defer to an executable open.
1617
+
1618
+ - `applyNativeChannelSettings(id, { displayName, policy, lifecycle })`
1619
+ uses the ordered channel change path. A running harness applies it
1620
+ live. A stopped harness stores it for its next open. `policy` selects
1621
+ an existing named policy. A policy-only change keeps the channel
1622
+ name. Pass `null` to clear a name or policy. The lifecycle values
1623
+ `"suspended"`, `"open"` and `"retired"` map to suspend, resume and
1624
+ delete. To delete the local conversation and its records as well,
1625
+ use `agent.conversations.delete(id)`.
1626
+ - `applyNativeToolSetting(name, operation)` enables or removes runtime
1627
+ tools, or revokes or restores revocable tools. It requires a running
1628
+ harness. The operations affect the whole session. Per-channel access
1629
+ can be restricted by the channel's named policy.
1630
+ - Named policy definitions, the default policy, model, system prompt and
1631
+ tool catalog take effect on executable open. The native wire has no
1632
+ participant-roster edit for an existing channel. An open alone cannot
1633
+ replace that roster, so hold or refuse that edit. Unsupported
1634
+ channel fields return `channel_settings_not_live` with the field
1635
+ names, without applying any part of the patch.
1636
+
1546
1637
  ### Native turn metering
1547
1638
 
1548
1639
  Agent-owned native conversations meter turns by default (`best_effort`). The
@@ -1613,10 +1704,19 @@ manual barriers and process replacement in code.
1613
1704
 
1614
1705
  ### Functions the model can call
1615
1706
 
1616
- Register functions in `harness.functions`. The harness offers them to the
1617
- model, applies the conversation's policy and asks for approval where the policy
1618
- says `ask`, validates the arguments against `parameters`, and then calls the
1619
- handler in this process.
1707
+ Register functions in `harness.functions.tools` before the Agent starts.
1708
+ The host declares the handler names during initialize and sends the tool
1709
+ catalog on every executable session open or create. Set `defaultPolicy` and
1710
+ `policies` under `harness.config`. The harness uses those policies to decide
1711
+ which tools to offer and whether a call needs approval. It validates the
1712
+ arguments against `parameters` before calling the handler in this process.
1713
+
1714
+ `harness.config.system` supplies the complete consumer system text. At the
1715
+ next executable open, changing it replaces that text for subsequent model
1716
+ requests in the same saved session. The harness still appends its own
1717
+ instructions and retains the conversation history. To apply a different
1718
+ configuration, close the Agent and open it with the new configuration and
1719
+ the same persisted Agent and harness home.
1620
1720
 
1621
1721
  ```ts
1622
1722
  harness: {
@@ -1644,7 +1744,10 @@ harness: {
1644
1744
  - **Why a tool cannot run.** `agent.nativeHarness.tools()` lists each tool
1645
1745
  with `available` and a reason (`revoked`, `not_enabled`, `handler_missing`).
1646
1746
  Policy is separate: a tool the conversation's policy denies is not offered.
1647
- - **Handlers.** Return any JSON value. Throw `FunctionError(code, message)` for
1747
+ - **Handlers.** The second argument contains `invocationId`, `channel`,
1748
+ `turnId`, `tool`, `policyNames` and `signal`. `policyNames` comes from
1749
+ the harness authorization snapshot. The names have no precedence by order.
1750
+ Return a JSON value as the tool result. Throw `FunctionError(code, message)` for
1648
1751
  a failure the model should see. `signal` aborts when the harness stops
1649
1752
  waiting: the tool's deadline passed, the turn was interrupted, or the harness
1650
1753
  stopped. A value returned after that is ignored.
@@ -1666,6 +1769,42 @@ harness: {
1666
1769
  but has no recorded result (crash, lost connection, interrupt) is
1667
1770
  `interrupted` with `effect: "unknown"`. It is never run again automatically.
1668
1771
 
1772
+ Native conversations do not support attaching ACP `mcpServers`. To use an
1773
+ MCP tool, connect the MCP client in your host application and register a
1774
+ native function that calls it. Supply the tool description and input schema
1775
+ and allow the wrapper by its registered name in `harness.config.policies`.
1776
+
1777
+ ```ts
1778
+ import { FunctionError, type NativeFunctionsConfig } from "@qlairoslabs/acp-client";
1779
+
1780
+ export function orderTools(
1781
+ callMcpTool: (name: string, args: Record<string, unknown>, signal: AbortSignal) =>
1782
+ Promise<{ content: unknown[]; isError?: boolean }>,
1783
+ ): NativeFunctionsConfig {
1784
+ return {
1785
+ tools: {
1786
+ lookup: {
1787
+ description: "Look up an order",
1788
+ parameters: {
1789
+ type: "object",
1790
+ properties: { id: { type: "string" } },
1791
+ required: ["id"],
1792
+ additionalProperties: false,
1793
+ },
1794
+ async handler(args, { signal }) {
1795
+ const result = await callMcpTool("lookup_order", args, signal);
1796
+ if (result.isError) throw new FunctionError("mcp_tool_error", "Order lookup failed");
1797
+ return result.content;
1798
+ },
1799
+ },
1800
+ },
1801
+ };
1802
+ }
1803
+ ```
1804
+
1805
+ Pass the returned object as `harness.functions`. The host owns the MCP
1806
+ connection lifecycle and forwards cancellation through its client library.
1807
+
1669
1808
  Tool changes need a running harness: `revokeTool` and the others fail with
1670
1809
  `HarnessUnavailableError` while it is stopped.
1671
1810
 
@@ -4,8 +4,8 @@ For consumers of the published `@qlairoslabs/acp-client` 0.12.1, including
4
4
  `~agents` (`libs/agents/agents-core`). See the [consumer guide](CONSUMER_GUIDE.md)
5
5
  for complete examples.
6
6
 
7
- **Status.** These changes are on `alpha`. The package version remains 0.12.1
8
- and 0.13 is unpublished. For a local trial, point a disposable
7
+ **Status.** Version `0.13.0-alpha.1` is published under the `alpha` tag.
8
+ This note also covers subsequent changes on `alpha`. For a local trial, point a disposable
9
9
  consumer checkout at a local archive of the target code and use a copy of the
10
10
  database. For example, use a `file:/absolute/path/to/acp-client-archive`
11
11
  dependency in the trial checkout or replace its local package link. Make the
@@ -40,10 +40,11 @@ entry has 924 exports, including nine new reminder names.
40
40
 
41
41
  | What changed | What to do |
42
42
  | --- | --- |
43
- | `defaultPermission` was removed. | Replace `"approve"` with `permissions: { default: "allow" }` and `"cancel"` with `permissions: { default: "ask" }`. Omitting the setting means ask. |
43
+ | `defaultPermission` was removed. | Replace `"approve"` with `permissions: { default: "allow" }` and `"cancel"` with `permissions: { default: "ask", unanswered: "cancel" }` to keep cancellation on an unattended ask. Omitting the setting means ask and reject the tool if nobody answers. |
44
44
  | Permission defaults and rules can settle requests before the prompt handler. | Install a handler or declare a consumer for asks. Update ACP refusal handling for `reject_once` where offered and cancellation otherwise. |
45
45
  | `AgentController` and `AgentControllerStartEvent` have new names. | Use `HarnessController` and `ControllerStartEvent`. The deprecated aliases still work. |
46
46
  | `conversation.connection` is a `ConversationController`. | Use the shared interface where possible and use `conversation.harnessConnection()` for ACP-specific members. Handle its null return. |
47
+ | Built-in ACP terminals no longer inherit the hub or spawned process environment. | Supply exact variables via `terminalEnv` in client/runtime config, prepared launch or direct terminal creation. |
47
48
  | Launcher kind includes `"native-harness"`. | Handle the new kind in custom launcher unions and switches. Route it explicitly or reject it if unsupported. |
48
49
  | Custom persistence backends must supply `capabilities.channels: boolean`. | Use `channels: false` without a durable channel repository. The repository itself is optional. |
49
50
  | Adapter registration now accepts `AgentAdapter` (`Adapter \| NativeAdapter`). | Narrow `AgentAdapterRegistration.adapter`, entries in `AgentConfig.adapters`, and arguments to `AgentAdapterRegistry.register` before reading ACP fields such as `command`. `list()` still returns entries with an `Adapter`. |
@@ -143,7 +144,10 @@ Rules use `kind:` and exact `command:` keys. The stricter match wins. Native ask
143
144
  use the callback and default, while the harness itself grants or denies tools
144
145
  by name. Allow and deny are final. In particular, default allow can skip a
145
146
  prompt handler that previously ran. An ask with no handler and no eligible
146
- consumer is refused. Use `answersPermissions`, `permissionTimeoutMs` and
147
+ consumer uses `permissions.unanswered`. The default `"reject"` refuses
148
+ the tool using `reject_once` where ACP offers it or `deny` on native.
149
+ `"cancel"` sends ACP's cancelled response or interrupts the requesting
150
+ native turn. Use `answersPermissions`, `permissionTimeoutMs` and
147
151
  `answerPermission` to implement a conversation approval UI. See
148
152
  [permission configuration and events](CONSUMER_GUIDE.md#permissions-and-approval-ui).
149
153
 
@@ -230,6 +234,15 @@ destination receives an out-of-band message. A native destination receives a
230
234
  durable notice. Eligible notices can be retried without redispatching worker
231
235
  work. See the [orchestrator guide](CONSUMER_GUIDE.md#orchestrator-and-worker-delivery-experimental).
232
236
 
237
+ ## Native tools and system instructions
238
+
239
+ Provide host callbacks in `harness.functions.tools` and tool policies
240
+ in `harness.config`. Native conversations cannot attach ACP MCP servers.
241
+ Wrap an MCP call in a native function if needed. A new executable open uses
242
+ the supplied `harness.config.system` in place of the previous consumer
243
+ system text and keeps the harness's own instructions. See
244
+ [Functions the model can call](CONSUMER_GUIDE.md#functions-the-model-can-call).
245
+
233
246
  ## Other native harness changes
234
247
 
235
248
  The standalone native harness managed session config can opt into `timelineTools: true` to make
@@ -247,9 +260,9 @@ errors. The archive adds 13 diagnostics across the following four groups.
247
260
 
248
261
  | Location under `src/` | Exact edit |
249
262
  | --- | --- |
250
- | `agent/chat/session.ts` | Keep the app's `default_permission` and CLI option names. Import `PermissionSettings` from the package and make it the return type of `libraryPermission`, returning `{ default: policy === "approve" ? "allow" : "ask" }`. Set `permissions: libraryPermission(defaultPermission ?? agentCfg.default_permission)` on the session config. Pass `permissions: config.permissions` to both `loadAgentSession` and `createAgentSession`. |
251
- | `agent/chat/sqlite-session.ts` | In `conversationDefaults` set `permissions: { default: (canonical ? canonical.input.permission.policy : opts.defaultPermission ?? agentCfg!.default_permission) === "approve" ? "allow" : "ask" }`. Update the comment in `hub/index.ts` about the prompt handler. It runs for ask only, and an unattended ask fails closed. |
252
- | `__tests__/integration/docker-image-candidate-acp.test.ts`, `__tests__/integration/opencode-model-catalog.test.ts`, `gateway/docker-delivery.test.ts` | Replace the library-level `defaultPermission: "cancel"` with `permissions: { default: "ask" }`. |
263
+ | `agent/chat/session.ts` | Keep the app's `default_permission` and CLI option names. Import `PermissionSettings` from the package and make it the return type of `libraryPermission`, returning `policy === "approve" ? { default: "allow" } : { default: "ask", unanswered: "cancel" }`. Set `permissions: libraryPermission(defaultPermission ?? agentCfg.default_permission)` on the session config. Pass `permissions: config.permissions` to both `loadAgentSession` and `createAgentSession`. |
264
+ | `agent/chat/sqlite-session.ts` | In `conversationDefaults` apply the same mapping to `canonical ? canonical.input.permission.policy : opts.defaultPermission ?? agentCfg!.default_permission`. Update the comment in `hub/index.ts` about the prompt handler. It runs for ask only, and an unattended ask fails closed. |
265
+ | `__tests__/integration/docker-image-candidate-acp.test.ts`, `__tests__/integration/opencode-model-catalog.test.ts`, `gateway/docker-delivery.test.ts` | Replace the library-level `defaultPermission: "cancel"` with `permissions: { default: "ask", unanswered: "cancel" }`. |
253
266
  | `agent/chat/launcher.ts` | For the current ACP-only launcher add `if (kind === "native-harness") throw new Error("Native harness launch is unsupported by this runtime");` before passing `kind` to `prepareProcessLaunch`. To enable native launches later, extend `RuntimeProcessKind` and its runtime handlers to route the new kind explicitly. |
254
267
  | `hub/index.ts` | Keep the degraded PTY special case. Replace `session.connection.currentClient.isConnected` with `session.harnessConnection()?.currentClient.isConnected ?? false` inside the existing try/catch. Update session test doubles used by that branch to supply `harnessConnection()` with the expected client state. |
255
268
  | `configuration/recording/acp-contract.test.ts` | Remove the public-package import of `ConversationPersistenceContext` from this fixture. Type `context` as `Parameters<ConversationSettingsResolver["settingsFor"]>[0]` using the fixture's existing resolver import. The error in the linked archive is a split branded type identity from mixing relative package internals with a public package type. The resolver contract test can stay on its test-only internal import path. |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qlairoslabs/acp-client",
3
- "version": "0.13.0-alpha.1",
3
+ "version": "0.13.1-alpha.1",
4
4
  "description": "Embeddable Agent Client Protocol (ACP) client library with degraded PTY fallback.",
5
5
  "type": "module",
6
6
  "module": "src/index.ts",
@@ -40,7 +40,14 @@
40
40
  "CHANGELOG-consumer-fixes.md",
41
41
  "CHANGELOG-controller-interface.md",
42
42
  "MIGRATION-0.10-to-0.12.md",
43
- "MIGRATION-0.12-to-0.13.md"
43
+ "MIGRATION-0.12-to-0.13.md",
44
+ "!src/native-harness/test",
45
+ "!src/native-harness/.res",
46
+ "!src/native-harness/AGENTS.md",
47
+ "!src/native-harness/ARCHITECTURE.md",
48
+ "!src/native-harness/bun.lock",
49
+ "!src/**/*.test.ts",
50
+ "!src/**/*.typecheck.ts"
44
51
  ],
45
52
  "exports": {
46
53
  ".": "./src/index.ts",
@@ -577,6 +577,7 @@ export class DefaultAgentConversationManager implements AgentConversationManager
577
577
  ...(defaults.launcher ? { launcher: defaults.launcher } : {}),
578
578
  ...(defaults.execPrefix ? { execPrefix: defaults.execPrefix } : {}),
579
579
  ...(defaults.env ? { env: defaults.env } : {}),
580
+ ...(defaults.terminalEnv ? { terminalEnv: defaults.terminalEnv } : {}),
580
581
  ...(defaults.cwd ? { cwd: defaults.cwd } : {}),
581
582
  ...(defaults.clientInfo ? { clientInfo: defaults.clientInfo } : {}),
582
583
  ...(defaults.logger ? { logger: defaults.logger } : {}),
@@ -0,0 +1,39 @@
1
+ import type { AgentConversationId } from "../agent-ids.ts";
2
+ import type { ChannelChangeOutcome } from "../native/channel-changes.ts";
3
+ import type { AgentHarnessConfig } from "./config.ts";
4
+
5
+ export const channelSettingsLive = {
6
+ channel: ["displayName", "policy", "lifecycle"],
7
+ channelOperations: ["create", "edit", "suspend", "resume", "delete"],
8
+ sessionTools: ["enable", "remove", "revoke", "restore"],
9
+ restartRequired: ["policies", "defaultPolicy", "model", "system", "toolCatalog", "participants"],
10
+ } as const;
11
+ export type NativeToolSetting = typeof channelSettingsLive.sessionTools[number];
12
+ export type NativeChannelSettings = Readonly<Record<string, unknown>> & {
13
+ readonly displayName?: string | null;
14
+ readonly policy?: string | null;
15
+ readonly lifecycle?: "open" | "suspended" | "retired";
16
+ };
17
+
18
+ export type NativeChannelSettingsResult = ChannelChangeOutcome
19
+ | { readonly state: "unsupported"; readonly code: "channel_settings_not_live"; readonly fields: readonly string[] }
20
+ | { readonly state: "unsupported"; readonly code: "invalid_channel_settings" | "not_native_conversation" };
21
+
22
+ export interface NativeRestartOptions {
23
+ readonly when?: "idle" | "now";
24
+ readonly signal?: AbortSignal;
25
+ readonly config?: AgentHarnessConfig["config"];
26
+ readonly functions?: AgentHarnessConfig["functions"] | null;
27
+ }
28
+
29
+ export interface NativeRestartPreview {
30
+ readonly conversationCount: number;
31
+ readonly conversationIds: readonly AgentConversationId[];
32
+ }
33
+
34
+ export type NativeRestartResult = NativeRestartPreview & {
35
+ readonly kind: "restarted" | "restart_failed";
36
+ readonly interruptedTurns: readonly { channel: string; turnId: string }[];
37
+ readonly conversations: readonly { id: AgentConversationId; outcome: "reconnected" | "deferred" | "failed" }[];
38
+ readonly error?: unknown;
39
+ };
@@ -42,6 +42,8 @@ export interface AgentSessionConfig extends ConversationPermissionConfig {
42
42
  execPrefix?: string[];
43
43
  /** @deprecated Use launcher and its exact spawnEnv. */
44
44
  env?: Record<string, string>;
45
+ /** Exact environment for built-in ACP terminals. */
46
+ terminalEnv?: Record<string, string>;
45
47
  cwd?: string;
46
48
  /** Additional absolute directories declared to the provider. */
47
49
  additionalDirectories?: string[];
@@ -588,6 +588,7 @@ export class AgentConversation implements AgentClient, Bridgeable {
588
588
  launcher: config.launcher,
589
589
  execPrefix: config.execPrefix,
590
590
  env: config.env,
591
+ terminalEnv: config.terminalEnv,
591
592
  cwd: config.cwd,
592
593
  additionalDirectories: config.additionalDirectories,
593
594
  mcpServers: config.mcpServers,
package/src/agent.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { channelSettingsLive, type NativeChannelSettings, type NativeChannelSettingsResult, type NativeRestartOptions, type NativeRestartPreview, type NativeRestartResult, type NativeToolSetting } from "./agent/native-operations.ts";
1
2
  import { createAgentReminderService, type ReminderService } from "./native/reminders/service.ts";
2
3
  import { resolveProviderStart } from "./conversation-startup.ts";
3
4
  import { withDelegationTools } from "./orchestrator/native-delegation.ts";
@@ -160,13 +161,15 @@ export class Agent {
160
161
  if (config.orchestrator) validateOrchestrator(config.orchestrator, persistence, resolveConversationRecordCapture(config.capture).message);
161
162
  this.persistence = persistence;
162
163
  this.adapters = adapters;
164
+ const orchestration = config.orchestrator;
165
+ if (orchestration) this.wrapNativeFunctions = functions => withDelegationTools(functions, orchestration,
166
+ () => this.orchestrator!, () => this.conversations);
163
167
  const channels = config.harness ? protectedChannels(persistence) : undefined;
164
168
  this.nativeHarness = config.harness
165
169
  ? new NativeHarnessHost({
166
170
  sessionId: id,
167
171
  ...config.harness,
168
- ...(config.orchestrator ? { functions: withDelegationTools(config.harness.functions, config.orchestrator,
169
- () => this.orchestrator!, () => this.conversations) } : {}),
172
+ ...(this.wrapNativeFunctions ? { functions: this.wrapNativeFunctions(config.harness.functions) } : {}),
170
173
  ...(config.harness.launcher ?? config.conversationDefaults?.launcher
171
174
  ? { launcher: config.harness.launcher ?? config.conversationDefaults!.launcher }
172
175
  : {}),
@@ -470,9 +473,101 @@ export class Agent {
470
473
  this.eventBus.publish(records);
471
474
  }
472
475
 
476
+ private nativeOperationHost(): NativeHarnessHost {
477
+ if (this.closed) throw new Error("Agent is closed");
478
+ if (!this.nativeHarness) throw new Error("Agent has no native harness");
479
+ return this.nativeHarness;
480
+ }
481
+
482
+ async previewNativeRestart(): Promise<NativeRestartPreview> {
483
+ this.nativeOperationHost();
484
+ const conversationIds: AgentConversationId[] = [];
485
+ let cursor: string | undefined;
486
+ do {
487
+ const page = await this.conversations.list({ cursor });
488
+ for (const conversation of page.conversations) {
489
+ if (!conversation.deletedAt && conversation.controllerKind === "native") conversationIds.push(conversation.agentConversationId);
490
+ }
491
+ cursor = page.nextCursor;
492
+ } while (cursor !== undefined);
493
+ return { conversationIds, conversationCount: conversationIds.length };
494
+ }
495
+
496
+ private readonly nativeOperationsLifetime = new AbortController();
497
+
498
+ waitForNativeIdle(options: { signal?: AbortSignal } = {}): Promise<void> {
499
+ return this.nativeOperationHost().waitForIdle(options.signal ? AbortSignal.any([options.signal, this.nativeOperationsLifetime.signal]) : this.nativeOperationsLifetime.signal);
500
+ }
501
+
502
+ private readonly wrapNativeFunctions?: (functions: NonNullable<AgentConfig["harness"]>["functions"]) => NonNullable<AgentConfig["harness"]>["functions"];
503
+ private nativeRestart?: Promise<NativeRestartResult>;
504
+ private readonly nativeRestartListeners = new Set<(result: NativeRestartResult) => void>();
505
+
506
+ subscribeNativeRestart(listener: (result: NativeRestartResult) => void): () => void {
507
+ this.nativeRestartListeners.add(listener);
508
+ return () => { this.nativeRestartListeners.delete(listener); };
509
+ }
510
+
511
+ restartNative(options: NativeRestartOptions = {}): Promise<NativeRestartResult> {
512
+ if (this.nativeRestart) return this.nativeRestart;
513
+ const host = this.nativeOperationHost();
514
+ return this.nativeRestart = (async () => {
515
+ const preview = await this.previewNativeRestart();
516
+ const interruptedTurns: { channel: string; turnId: string }[] = [];
517
+ let result: NativeRestartResult;
518
+ try {
519
+ const signal = options.signal ? AbortSignal.any([options.signal, this.nativeOperationsLifetime.signal]) : this.nativeOperationsLifetime.signal;
520
+ const functions = options.functions !== undefined && this.wrapNativeFunctions
521
+ ? this.wrapNativeFunctions(options.functions ?? undefined) : options.functions;
522
+ await host.restartForAgent({ ...options, signal, functions }, interruptedTurns);
523
+ result = { ...preview, kind: "restarted", interruptedTurns, conversations: preview.conversationIds.map(id =>
524
+ ({ id, outcome: host.channel(id) ? "reconnected" : "deferred" })) };
525
+ } catch (error) {
526
+ result = { ...preview, kind: "restart_failed", interruptedTurns, error,
527
+ conversations: preview.conversationIds.map(id => ({ id, outcome: "failed" })) };
528
+ }
529
+ for (const listener of this.nativeRestartListeners) {
530
+ try { listener(result); } catch { /* Observers cannot change the restart outcome. */ }
531
+ }
532
+ return result;
533
+ })().finally(() => { this.nativeRestart = undefined; });
534
+ }
535
+
536
+ readonly channelSettingsLive = channelSettingsLive;
537
+
538
+ async applyNativeChannelSettings(id: AgentConversationId, settings: NativeChannelSettings): Promise<NativeChannelSettingsResult> {
539
+ const host = this.nativeOperationHost();
540
+ const conversation = await this.conversations.get(id);
541
+ if (!conversation || conversation.deletedAt || conversation.controllerKind !== "native") {
542
+ return { state: "unsupported", code: "not_native_conversation" } as const;
543
+ }
544
+ const unsupported = Object.keys(settings).filter(key => !channelSettingsLive.channel.some(field => field === key));
545
+ if (unsupported.length) return { state: "unsupported", code: "channel_settings_not_live", fields: unsupported } as const;
546
+ const { displayName, policy, lifecycle } = settings;
547
+ if ([displayName, policy].some(value => value !== undefined && value !== null && typeof value !== "string")
548
+ || (lifecycle !== undefined && !["open", "suspended", "retired"].includes(lifecycle))) {
549
+ return { state: "unsupported", code: "invalid_channel_settings" } as const;
550
+ }
551
+ if (displayName === undefined && policy === undefined && lifecycle === undefined) return { state: "applied" } as const;
552
+ return host.changeChannel(id, { ...(displayName === undefined ? {} : { displayName }),
553
+ ...(policy === undefined ? {} : { policy }), ...(lifecycle === undefined ? {} : { lifecycle }) });
554
+ }
555
+
556
+ applyNativeToolSetting(name: string, setting: NativeToolSetting) {
557
+ const host = this.nativeOperationHost();
558
+ switch (setting) {
559
+ case "enable": return host.enableTool(name);
560
+ case "remove": return host.removeTool(name);
561
+ case "revoke": return host.revokeTool(name);
562
+ case "restore": return host.restoreTool(name);
563
+ }
564
+ }
565
+
473
566
  async close(): Promise<void> {
474
567
  if (this.closed) return;
475
568
  this.closed = true;
569
+ this.nativeOperationsLifetime.abort(new Error("Agent is closed"));
570
+ await this.nativeRestart;
476
571
  this.nativeHarness?.closeReminderSupervisors();
477
572
  this.manager.cancelStarts();
478
573
  let shutdownError: unknown;
package/src/client.ts CHANGED
@@ -62,6 +62,8 @@ export interface AcpClientConfig extends PermissionPolicyConfig {
62
62
  execPrefix?: string[];
63
63
  /** @deprecated Use launcher and its exact spawnEnv. */
64
64
  env?: Record<string, string>;
65
+ /** Exact environment for built-in ACP terminals. */
66
+ terminalEnv?: Record<string, string>;
65
67
  /** Workspace visible to the ACP target and sent in session requests. */
66
68
  cwd?: string;
67
69
  /** Additional workspace roots passed to ACP session creation and loading. */
@@ -331,7 +333,7 @@ export class AcpClient implements AgentClient {
331
333
  this.terminals = this.handlers.terminal === "builtin"
332
334
  ? new TerminalRegistry({
333
335
  cwd: this.config.cwd,
334
- env: this.config.env,
336
+ terminalEnv: launch.terminalEnv ?? this.config.terminalEnv,
335
337
  logger: this.config.logger,
336
338
  })
337
339
  : null;
@@ -728,7 +730,7 @@ export class AcpClient implements AgentClient {
728
730
  private terminalHandlers(registry: TerminalRegistry) {
729
731
  return {
730
732
  create: async (p: schema.CreateTerminalRequest) => ({
731
- terminalId: registry.create(p as Parameters<TerminalRegistry["create"]>[0]),
733
+ terminalId: registry.create({ command: p.command, args: p.args, cwd: p.cwd, env: p.env, outputByteLimit: p.outputByteLimit }),
732
734
  }),
733
735
  output: async (p: schema.TerminalOutputRequest) => {
734
736
  const { output, truncated, exitStatus } = registry.output(p.terminalId);
@@ -983,7 +985,7 @@ export class AcpClient implements AgentClient {
983
985
  if (abort.signal.aborted) return { outcome: "cancelled" as const };
984
986
  if (handler && recordingPermissionHandlers.has(handler)) return handler(request, abort.signal);
985
987
  return answerPermissionLevel(permissionLevel(request, this.config), request,
986
- handler && (() => handler(request, abort.signal)));
988
+ handler && (() => handler(request, abort.signal)), this.config.permissions?.unanswered);
987
989
  }),
988
990
  ]);
989
991
  } finally {
@@ -49,6 +49,7 @@ export async function bringUp(
49
49
  launcher: config.launcher,
50
50
  execPrefix: config.execPrefix,
51
51
  env: config.env,
52
+ terminalEnv: config.terminalEnv,
52
53
  cwd: config.cwd,
53
54
  additionalDirectories: config.additionalDirectories,
54
55
  sessionId,
package/src/controller.ts CHANGED
@@ -68,6 +68,8 @@ export interface AgentControllerConfig extends PermissionPolicyConfig {
68
68
  execPrefix?: string[];
69
69
  /** @deprecated Use launcher and its exact spawnEnv. */
70
70
  env?: Record<string, string>;
71
+ /** Exact environment for built-in ACP terminals. */
72
+ terminalEnv?: Record<string, string>;
71
73
  cwd?: string;
72
74
  additionalDirectories?: string[];
73
75
  /** Session id to load on start(). */
package/src/index.ts CHANGED
@@ -41,6 +41,7 @@ export type { ConversationTimelineItem } from "./persistence/timeline-reconcile.
41
41
  export * from "./audit/index.ts";
42
42
 
43
43
  export { Agent } from "./agent.ts";
44
+ export { channelSettingsLive, type NativeChannelSettings, type NativeChannelSettingsResult, type NativeRestartOptions, type NativeRestartPreview, type NativeRestartResult, type NativeToolSetting } from "./agent/native-operations.ts";
44
45
  export type {
45
46
  AgentConfig,
46
47
  AgentConversationManager,
package/src/launcher.ts CHANGED
@@ -13,6 +13,8 @@ export interface PreparedLaunch {
13
13
  spawnCwd?: string;
14
14
  /** Complete environment for the directly spawned process. */
15
15
  spawnEnv: Record<string, string>;
16
+ /** Exact environment for built-in host terminals. Independent of spawnEnv. */
17
+ terminalEnv?: Record<string, string>;
16
18
  /** Release resources created while preparing this launch. Called exactly once. */
17
19
  dispose?: () => void | Promise<void>;
18
20
  }
@@ -2,6 +2,7 @@ import { permissionArrival } from "../permissions/arrival.ts";
2
2
  import type { ChannelEvent } from "../native-harness/src/client.ts";
3
3
  import type { Logger } from "../logger.ts";
4
4
  import { cancelledPermission, nativeConversationStopping, nativePermissionRequests, refuseNativeOnClose, type NativePermission, type PermissionResolution } from "../permissions/conversation.ts";
5
+ import { unansweredCancellation } from "../permissions/outcome.ts";
5
6
  import { recordingPermissionHandlers } from "../permissions/policy.ts";
6
7
  import type { PermissionRequest, PromptHandlers } from "../types.ts";
7
8
  import type { NativeApprovalRequest, NativeApprovalResponder } from "./host.ts";
@@ -20,11 +21,15 @@ class Approval implements NativePermission {
20
21
  private inFlight = false;
21
22
  private observedAnswer?: PermissionResolution;
22
23
  private started = false;
24
+ private cancelTurn?: () => void;
25
+
26
+ onCancelTurn(listener: () => void): void { this.cancelTurn = listener; }
23
27
 
24
28
  constructor(
25
29
  readonly request: NativeApprovalRequest,
26
30
  readonly hostHandled: boolean,
27
31
  private readonly send: SendApproval,
32
+ private readonly interrupt?: () => Promise<boolean>,
28
33
  ) {
29
34
  this.resolution = new Promise(resolve => { this.resolve = resolve; });
30
35
  }
@@ -46,6 +51,17 @@ class Approval implements NativePermission {
46
51
  async answer(resolution: PermissionResolution): Promise<boolean> {
47
52
  if (this.inFlight || this.abort.signal.aborted) return false;
48
53
  this.inFlight = true;
54
+ if (resolution.outcome === unansweredCancellation && this.interrupt) {
55
+ this.observedAnswer = resolution;
56
+ try {
57
+ this.cancelTurn?.();
58
+ const accepted = await this.interrupt();
59
+ this.finish(accepted ? resolution : cancelledPermission);
60
+ return accepted;
61
+ } finally {
62
+ this.finish(cancelledPermission);
63
+ }
64
+ }
49
65
  const decision = resolution.outcome.outcome === "selected" && resolution.outcome.optionId === "allow_once" ? allow : deny;
50
66
  try {
51
67
  const accepted = await this.send(decision.optionId);
@@ -64,7 +80,7 @@ class Approval implements NativePermission {
64
80
  if (!this.inFlight) this.finish(this.observedAnswer);
65
81
  } else if (reason === "approval_timeout") {
66
82
  this.finish({ outcome: deny, by: "timeout" });
67
- } else {
83
+ } else if (this.observedAnswer?.outcome !== unansweredCancellation) {
68
84
  this.finish(cancelledPermission);
69
85
  }
70
86
  }
@@ -76,6 +92,7 @@ class Approval implements NativePermission {
76
92
  finish(result: PermissionResolution): void {
77
93
  if (this.abort.signal.aborted) return;
78
94
  this.abort.abort();
95
+ this.cancelTurn = undefined;
79
96
  this.resolve(result);
80
97
  }
81
98
  }
@@ -88,11 +105,11 @@ export class NativeApprovals {
88
105
 
89
106
  constructor(private readonly responder: NativeApprovalResponder | undefined, private readonly log: Logger) {}
90
107
 
91
- observe(channel: string, event: ApprovalEvent, send: SendApproval): void {
108
+ observe(channel: string, event: ApprovalEvent, send: SendApproval, interrupt?: () => Promise<boolean>): void {
92
109
  let ticket = this.events.get(event) ?? this.active.get(event.requestId);
93
110
  if (!ticket) {
94
111
  const { type: _type, ...request } = event;
95
- ticket = new Approval({ ...request, channel }, this.responder !== undefined, send);
112
+ ticket = new Approval({ ...request, channel }, this.responder !== undefined, send, interrupt);
96
113
  this.active.set(event.requestId, ticket);
97
114
  }
98
115
  this.events.set(event, ticket);