@qlairoslabs/acp-client 0.12.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 (288) 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 +984 -6
  6. package/MIGRATION-0.10-to-0.12.md +4 -1
  7. package/MIGRATION-0.12-to-0.13.md +288 -0
  8. package/README.md +17 -16
  9. package/package.json +11 -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 +95 -158
  19. package/src/agent/manager-settings.ts +1 -0
  20. package/src/agent/native-channel-lifecycle.ts +111 -0
  21. package/src/agent/native-operations.ts +39 -0
  22. package/src/agent/persisted-lifecycle.ts +44 -4
  23. package/src/agent/persistence-policy/context.ts +13 -0
  24. package/src/agent/persistence-policy/resolver.ts +7 -0
  25. package/src/agent/persistence-policy/types.ts +1 -0
  26. package/src/agent/record-capture.ts +1 -0
  27. package/src/agent-adapter-registry.ts +33 -7
  28. package/src/agent-conversation-contracts.ts +14 -1
  29. package/src/agent-conversation-errors.ts +8 -0
  30. package/src/agent-conversation-owner.ts +9 -4
  31. package/src/agent-session-config.ts +137 -0
  32. package/src/agent-session.ts +440 -934
  33. package/src/agent.ts +168 -0
  34. package/src/capabilities.ts +2 -0
  35. package/src/checkpointing/recovery.ts +3 -0
  36. package/src/cli/index.ts +3 -3
  37. package/src/cli/managed.ts +2 -2
  38. package/src/client.ts +56 -96
  39. package/src/connection-attempt.ts +95 -0
  40. package/src/controller-connection.ts +115 -0
  41. package/src/controller.ts +158 -148
  42. package/src/conversation-controller/capabilities.ts +88 -0
  43. package/src/conversation-controller/contracts.ts +208 -0
  44. package/src/conversation-controller/factory.ts +39 -0
  45. package/src/conversation-controller/guards.ts +98 -0
  46. package/src/conversation-controller/index.ts +20 -0
  47. package/src/conversation-startup.ts +35 -0
  48. package/src/conversation-turns/backend-turns.ts +373 -0
  49. package/src/conversation-turns/clear-operations.ts +37 -0
  50. package/src/conversation-turns/context.ts +135 -0
  51. package/src/conversation-turns/index.ts +4 -0
  52. package/src/conversation-turns/record-helpers.ts +75 -0
  53. package/src/conversation-turns/recording.ts +235 -0
  54. package/src/conversation-turns/run-turn.ts +367 -0
  55. package/src/conversation-turns/turn-run.ts +57 -0
  56. package/src/errors.ts +41 -0
  57. package/src/handoff-options.ts +81 -0
  58. package/src/identity/checkpoint-backed.ts +1 -1
  59. package/src/index.ts +59 -3
  60. package/src/internal-inference/coordination/manager.ts +11 -0
  61. package/src/internal-inference/runtime/harness-runtime.ts +4 -4
  62. package/src/launcher.ts +37 -2
  63. package/src/media/parts.ts +5 -0
  64. package/src/message-status.ts +83 -0
  65. package/src/metering/engine.ts +39 -64
  66. package/src/metering/measurement-provenance.ts +36 -0
  67. package/src/metering/native/durability.ts +115 -0
  68. package/src/metering/native/ledger.ts +104 -0
  69. package/src/metering/native/operation.ts +85 -0
  70. package/src/metering/native/projection.ts +114 -0
  71. package/src/metering/native/proof.ts +51 -0
  72. package/src/metering/native/requirements.ts +10 -0
  73. package/src/metering/native/retirement.ts +92 -0
  74. package/src/metering/native/source.ts +90 -0
  75. package/src/metering/record.ts +38 -1
  76. package/src/metering/state.ts +13 -3
  77. package/src/native/approvals.ts +186 -0
  78. package/src/native/capabilities.ts +17 -0
  79. package/src/native/channel-changes.ts +211 -0
  80. package/src/native/connection.ts +56 -0
  81. package/src/native/controller.ts +592 -0
  82. package/src/native/delegation-sender.ts +26 -0
  83. package/src/native/errors.ts +35 -0
  84. package/src/native/functions.ts +156 -0
  85. package/src/native/host-config.ts +59 -0
  86. package/src/native/host.ts +978 -0
  87. package/src/native/item-receipts.ts +15 -0
  88. package/src/native/metering.ts +12 -0
  89. package/src/native/records.ts +166 -0
  90. package/src/native/recovery.ts +186 -0
  91. package/src/native/reminders/fixtures/schema21.sqlite.gz +0 -0
  92. package/src/native/reminders/idle.ts +70 -0
  93. package/src/native/reminders/limits.ts +19 -0
  94. package/src/native/reminders/notifications.ts +29 -0
  95. package/src/native/reminders/routine-guard.ts +66 -0
  96. package/src/native/reminders/routine-schedule.ts +25 -0
  97. package/src/native/reminders/routine-wire.ts +21 -0
  98. package/src/native/reminders/schedule.ts +97 -0
  99. package/src/native/reminders/service.ts +280 -0
  100. package/src/native/reminders/supervisor.ts +91 -0
  101. package/src/native/reminders/sync.ts +301 -0
  102. package/src/native/reminders/wire.ts +197 -0
  103. package/src/native/submission-withdrawal.ts +65 -0
  104. package/src/native/usage.ts +15 -0
  105. package/src/native/worker-delivery.ts +61 -0
  106. package/src/native-harness/README.md +726 -0
  107. package/src/native-harness/package.json +24 -0
  108. package/src/native-harness/scripts/build-routine-zones.py +47 -0
  109. package/src/native-harness/src/capabilities/context/build.ts +59 -0
  110. package/src/native-harness/src/capabilities/context/instructions/agent-demo.md +11 -0
  111. package/src/native-harness/src/capabilities/context/instructions/agent.md +5 -0
  112. package/src/native-harness/src/capabilities/context/instructions/harness.md +7 -0
  113. package/src/native-harness/src/capabilities/context/load-instructions.ts +22 -0
  114. package/src/native-harness/src/capabilities/context/session.ts +93 -0
  115. package/src/native-harness/src/capabilities/model/attempt.ts +27 -0
  116. package/src/native-harness/src/capabilities/model/openrouter-stream.ts +72 -0
  117. package/src/native-harness/src/capabilities/model/openrouter.ts +62 -0
  118. package/src/native-harness/src/capabilities/model/runner.ts +116 -0
  119. package/src/native-harness/src/capabilities/model/scenario-attempt.ts +50 -0
  120. package/src/native-harness/src/capabilities/model/scenario-file.ts +125 -0
  121. package/src/native-harness/src/capabilities/model/scripted-error.ts +6 -0
  122. package/src/native-harness/src/capabilities/model/scripted.ts +81 -0
  123. package/src/native-harness/src/capabilities/model/usage.ts +15 -0
  124. package/src/native-harness/src/capabilities/reminders/cron-calendar.ts +50 -0
  125. package/src/native-harness/src/capabilities/reminders/cron-fields.ts +46 -0
  126. package/src/native-harness/src/capabilities/reminders/cron-proof.ts +32 -0
  127. package/src/native-harness/src/capabilities/reminders/cron-zone.ts +53 -0
  128. package/src/native-harness/src/capabilities/reminders/iana-zones.json.gz +0 -0
  129. package/src/native-harness/src/capabilities/reminders/iana-zones.ts +34 -0
  130. package/src/native-harness/src/capabilities/reminders/interval.ts +30 -0
  131. package/src/native-harness/src/capabilities/reminders/routine-advance.ts +47 -0
  132. package/src/native-harness/src/capabilities/reminders/routine-backlog.ts +47 -0
  133. package/src/native-harness/src/capabilities/reminders/routine-expiry.ts +15 -0
  134. package/src/native-harness/src/capabilities/reminders/routine-occurrence.ts +65 -0
  135. package/src/native-harness/src/capabilities/reminders/routine-schedule.ts +70 -0
  136. package/src/native-harness/src/capabilities/reminders/unattended.ts +8 -0
  137. package/src/native-harness/src/capabilities/tools/builtin/current-time.ts +28 -0
  138. package/src/native-harness/src/capabilities/tools/builtin/notify-channel.ts +17 -0
  139. package/src/native-harness/src/capabilities/tools/debug/index.ts +13 -0
  140. package/src/native-harness/src/capabilities/tools/debug/result.ts +12 -0
  141. package/src/native-harness/src/capabilities/tools/debug/test-echo.ts +16 -0
  142. package/src/native-harness/src/capabilities/tools/debug/test-fail.ts +14 -0
  143. package/src/native-harness/src/capabilities/tools/debug/test-wait.ts +19 -0
  144. package/src/native-harness/src/capabilities/tools/reminders/index.ts +97 -0
  145. package/src/native-harness/src/capabilities/tools/runtime/catalog.ts +103 -0
  146. package/src/native-harness/src/capabilities/tools/runtime/functions.ts +130 -0
  147. package/src/native-harness/src/capabilities/tools/runtime/invocations.ts +48 -0
  148. package/src/native-harness/src/capabilities/tools/testing/echo.ts +18 -0
  149. package/src/native-harness/src/capabilities/tools/testing/record.ts +47 -0
  150. package/src/native-harness/src/capabilities/tools/timeline/index.ts +41 -0
  151. package/src/native-harness/src/client.ts +18 -0
  152. package/src/native-harness/src/contracts/agent.ts +105 -0
  153. package/src/native-harness/src/contracts/config-permissions.ts +49 -0
  154. package/src/native-harness/src/contracts/context.ts +112 -0
  155. package/src/native-harness/src/contracts/events.ts +47 -0
  156. package/src/native-harness/src/contracts/input-limits.ts +7 -0
  157. package/src/native-harness/src/contracts/inspection.ts +22 -0
  158. package/src/native-harness/src/contracts/loop.ts +31 -0
  159. package/src/native-harness/src/contracts/model-execution.ts +83 -0
  160. package/src/native-harness/src/contracts/operator-controls.ts +106 -0
  161. package/src/native-harness/src/contracts/output.ts +13 -0
  162. package/src/native-harness/src/contracts/protocol.ts +320 -0
  163. package/src/native-harness/src/contracts/reminders.ts +134 -0
  164. package/src/native-harness/src/contracts/routines.ts +20 -0
  165. package/src/native-harness/src/contracts/scenario.ts +42 -0
  166. package/src/native-harness/src/contracts/session-file.ts +20 -0
  167. package/src/native-harness/src/contracts/session.ts +184 -0
  168. package/src/native-harness/src/contracts/storage.ts +597 -0
  169. package/src/native-harness/src/contracts/timeline-retrieval.ts +40 -0
  170. package/src/native-harness/src/contracts/tools.ts +133 -0
  171. package/src/native-harness/src/governance/permissions/gate.ts +129 -0
  172. package/src/native-harness/src/governance/policy/resolve.ts +32 -0
  173. package/src/native-harness/src/index.ts +322 -0
  174. package/src/native-harness/src/interfaces/cli/chat.ts +83 -0
  175. package/src/native-harness/src/interfaces/cli/development.ts +145 -0
  176. package/src/native-harness/src/interfaces/cli/format-reply.ts +27 -0
  177. package/src/native-harness/src/interfaces/cli/listeners.ts +74 -0
  178. package/src/native-harness/src/interfaces/cli/main.ts +47 -0
  179. package/src/native-harness/src/interfaces/cli/scenario.ts +37 -0
  180. package/src/native-harness/src/interfaces/cli/serve.ts +21 -0
  181. package/src/native-harness/src/interfaces/cli/start.ts +106 -0
  182. package/src/native-harness/src/interfaces/client.ts +225 -0
  183. package/src/native-harness/src/interfaces/inspector/index.html +283 -0
  184. package/src/native-harness/src/interfaces/inspector/observe.ts +35 -0
  185. package/src/native-harness/src/interfaces/inspector/server.ts +56 -0
  186. package/src/native-harness/src/interfaces/inspector/state.ts +92 -0
  187. package/src/native-harness/src/interfaces/protocol/channel-changes.ts +153 -0
  188. package/src/native-harness/src/interfaces/protocol/framing.ts +47 -0
  189. package/src/native-harness/src/interfaces/protocol/functions.ts +87 -0
  190. package/src/native-harness/src/interfaces/protocol/in-process.ts +67 -0
  191. package/src/native-harness/src/interfaces/protocol/live-queue.ts +55 -0
  192. package/src/native-harness/src/interfaces/protocol/load.ts +60 -0
  193. package/src/native-harness/src/interfaces/protocol/local.ts +120 -0
  194. package/src/native-harness/src/interfaces/protocol/operator.ts +120 -0
  195. package/src/native-harness/src/interfaces/protocol/output.ts +59 -0
  196. package/src/native-harness/src/interfaces/protocol/server.ts +519 -0
  197. package/src/native-harness/src/interfaces/protocol/stdio-client.ts +126 -0
  198. package/src/native-harness/src/interfaces/protocol/stdio-server.ts +82 -0
  199. package/src/native-harness/src/interfaces/protocol/subscribe.ts +41 -0
  200. package/src/native-harness/src/interfaces/protocol/transfers.ts +146 -0
  201. package/src/native-harness/src/interfaces/web-chat/index.html +94 -0
  202. package/src/native-harness/src/interfaces/web-chat/server.ts +34 -0
  203. package/src/native-harness/src/kernel/channels.ts +409 -0
  204. package/src/native-harness/src/kernel/loop.ts +45 -0
  205. package/src/native-harness/src/runtime/config/development.ts +23 -0
  206. package/src/native-harness/src/runtime/config/managed.ts +2 -0
  207. package/src/native-harness/src/runtime/config/paths.ts +33 -0
  208. package/src/native-harness/src/runtime/reminder-timer.ts +42 -0
  209. package/src/native-harness/src/runtime/reminder-validation.ts +125 -0
  210. package/src/native-harness/src/runtime/reminders.ts +66 -0
  211. package/src/native-harness/src/state/storage/archive.ts +257 -0
  212. package/src/native-harness/src/state/storage/engine.ts +1204 -0
  213. package/src/native-harness/src/state/storage/inference.ts +124 -0
  214. package/src/native-harness/src/state/storage/memory-reminders.ts +103 -0
  215. package/src/native-harness/src/state/storage/memory.ts +354 -0
  216. package/src/native-harness/src/state/storage/policy-metadata.ts +32 -0
  217. package/src/native-harness/src/state/storage/reminder-archive.ts +104 -0
  218. package/src/native-harness/src/state/storage/reminder-change.ts +138 -0
  219. package/src/native-harness/src/state/storage/reminder-tables.ts +35 -0
  220. package/src/native-harness/src/state/storage/retrieval.ts +122 -0
  221. package/src/native-harness/src/state/storage/routine-row.ts +25 -0
  222. package/src/native-harness/src/state/storage/script-identity.ts +7 -0
  223. package/src/native-harness/src/state/storage/session-file.ts +85 -0
  224. package/src/native-harness/src/state/storage/sqlite-reminders.ts +174 -0
  225. package/src/native-harness/src/state/storage/sqlite.ts +632 -0
  226. package/src/native-harness/src/testing.ts +190 -0
  227. package/src/native-harness/src/util/config.ts +66 -0
  228. package/src/native-harness/src/util/intake.ts +7 -0
  229. package/src/native-harness/src/util/json.ts +41 -0
  230. package/src/native-harness/src/util/message-position.ts +3 -0
  231. package/src/native-harness/src/util/reminder-schedule.ts +44 -0
  232. package/src/native-harness/src/util/schema.ts +40 -0
  233. package/src/native-harness/src/util/timeline-text.ts +72 -0
  234. package/src/native-harness/src/util/timeline-tool-names.ts +3 -0
  235. package/src/native-harness/tsconfig.json +20 -0
  236. package/src/observation/agent-event-bus.ts +44 -18
  237. package/src/observation/index.ts +1 -0
  238. package/src/operations/contracts.ts +11 -3
  239. package/src/operations/errors.ts +5 -0
  240. package/src/operations/stale-policy.ts +1 -1
  241. package/src/operations/supervisor.ts +34 -10
  242. package/src/orchestrator/acp-delivery.ts +68 -0
  243. package/src/orchestrator/assignments.ts +27 -0
  244. package/src/orchestrator/busy.ts +15 -0
  245. package/src/orchestrator/config.ts +41 -0
  246. package/src/orchestrator/consumer-api.ts +24 -0
  247. package/src/orchestrator/contracts.ts +71 -0
  248. package/src/orchestrator/durable-assignments.ts +111 -0
  249. package/src/orchestrator/native-delegation.ts +103 -0
  250. package/src/orchestrator/orchestrator.ts +318 -0
  251. package/src/orchestrator/permissions.ts +28 -0
  252. package/src/orchestrator/policy.ts +44 -0
  253. package/src/orchestrator/pool.ts +123 -0
  254. package/src/orchestrator/tool-descriptions.ts +11 -0
  255. package/src/permissions/acp.ts +18 -0
  256. package/src/permissions/arrival.ts +13 -0
  257. package/src/permissions/consumer-config.ts +19 -0
  258. package/src/permissions/conversation.ts +288 -0
  259. package/src/permissions/matcher.ts +87 -0
  260. package/src/permissions/outcome.ts +26 -0
  261. package/src/permissions/policy.ts +86 -0
  262. package/src/permissions/request.ts +26 -0
  263. package/src/persistence/activity-projection.ts +1 -0
  264. package/src/persistence/backend.ts +34 -1
  265. package/src/persistence/channels.ts +23 -0
  266. package/src/persistence/index.ts +4 -0
  267. package/src/persistence/protocol-method.ts +5 -0
  268. package/src/persistence/reminder-wake.ts +49 -0
  269. package/src/persistence/reminders.ts +385 -0
  270. package/src/persistence/sqlite-backend.ts +84 -6
  271. package/src/persistence/sqlite-channels.ts +65 -0
  272. package/src/persistence/sqlite-reminders.ts +85 -0
  273. package/src/persistence/sqlite-schema.ts +108 -3
  274. package/src/persistence/sqlite-worker-delivery.ts +374 -0
  275. package/src/persistence/sqlite-workers.ts +59 -0
  276. package/src/persistence/worker-delivery-contract.ts +104 -0
  277. package/src/persistence/worker-terminal-reason.ts +29 -0
  278. package/src/persistence/workers.ts +19 -0
  279. package/src/provider-notices.ts +137 -0
  280. package/src/repl/commands.ts +2 -2
  281. package/src/steering/combine.ts +3 -1
  282. package/src/steering/contracts.ts +11 -2
  283. package/src/steering/controller.ts +3 -2
  284. package/src/terminals.ts +9 -6
  285. package/src/transport/acp-transport.ts +24 -14
  286. package/src/types.ts +15 -12
  287. package/src/updates.ts +14 -2
  288. package/src/wire-log.ts +1 -1
@@ -0,0 +1,137 @@
1
+ // Provider notices: warnings, retries and failures a harness reports in an update's `_meta`.
2
+ //
3
+ // ACP has no standard "warning" or "retrying" update, so adapters put them in `_meta` of a
4
+ // `session_info_update`. Two shapes are read here:
5
+ //
6
+ // - The JetBrains AIR session-failure extension (`_meta.jetbrains.air.sessionFailure`), sent by
7
+ // codex-acp and claude-agent-acp once the client advertises the `sessionFailure` capability
8
+ // (`AIR_CLIENT_CAPABILITY_META`). One typed object: id, revision, category, severity, title,
9
+ // actions.
10
+ // - codex-acp's own fallback (`_meta.codex.error`), sent to clients that don't advertise AIR:
11
+ // the error message, Codex's error info (an HTTP status inside) and `willRetry`.
12
+ //
13
+ // A notice with severity "error" (or `willRetry: false`) is a failure the provider reports; any
14
+ // other severity is a notice that ends nothing (a retry in progress, a reconnect, an advisory).
15
+
16
+ /** What acp-client advertises in `clientCapabilities._meta`: AIR extension version 1, session failures. */
17
+ export const AIR_CLIENT_CAPABILITY_META = Object.freeze({
18
+ jetbrains: Object.freeze({ air: Object.freeze({ version: 1, capabilities: Object.freeze(["sessionFailure"]) }) }),
19
+ });
20
+
21
+ export type ProviderNoticeSeverity = "info" | "warning" | "error";
22
+ export type ProviderNoticeAction = "retry" | "login" | "new_session";
23
+
24
+ /** A notice or failure the provider reported, normalized from either shape. */
25
+ export interface ProviderNoticeActivity {
26
+ kind: "provider_notice";
27
+ /** Stable per notice: later revisions of the same notice share it. */
28
+ noticeId: string;
29
+ revision: number;
30
+ severity: ProviderNoticeSeverity;
31
+ /** Coarse class, as the adapter sends it: "limit", "service", "connection", "access", "request", … */
32
+ category: string;
33
+ /** A finer code when the shape allows one (from Codex's error info: "rate_limited", …). */
34
+ code?: string;
35
+ title: string;
36
+ details?: string;
37
+ actions: readonly ProviderNoticeAction[];
38
+ httpStatus?: number;
39
+ willRetry?: boolean;
40
+ /** Which shape it came from. */
41
+ source: "air" | "codex";
42
+ }
43
+
44
+ const MAX_TEXT = 512;
45
+ const ACTIONS = new Set<ProviderNoticeAction>(["retry", "login", "new_session"]);
46
+
47
+ function record(value: unknown): Record<string, unknown> | undefined {
48
+ return value && typeof value === "object" && !Array.isArray(value) ? value as Record<string, unknown> : undefined;
49
+ }
50
+
51
+ function text(value: unknown): string | undefined {
52
+ if (typeof value !== "string") return undefined;
53
+ const line = value.split(/\r?\n/, 1)[0]?.replace(/\s+/g, " ").trim() ?? "";
54
+ return line ? line.slice(0, MAX_TEXT) : undefined;
55
+ }
56
+
57
+ function actions(value: unknown): ProviderNoticeAction[] {
58
+ if (!Array.isArray(value)) return [];
59
+ return value.filter((a): a is ProviderNoticeAction => typeof a === "string" && ACTIONS.has(a as ProviderNoticeAction));
60
+ }
61
+
62
+ /** The HTTP status inside Codex's error info (`{ <variant>: { httpStatusCode } }`), if any. */
63
+ function codexHttpStatus(info: unknown): number | undefined {
64
+ const variants = record(info);
65
+ if (!variants) return undefined;
66
+ for (const detail of Object.values(variants)) {
67
+ const status = record(detail)?.httpStatusCode;
68
+ if (typeof status === "number" && Number.isSafeInteger(status)) return status;
69
+ }
70
+ return undefined;
71
+ }
72
+
73
+ /** Codex's own categories, from its error info: a 429 is a rate limit, a 401 sign-in. */
74
+ function codexCode(info: unknown, status: number | undefined): { code: string; category: string } {
75
+ if (status === 429) return { code: "rate_limited", category: "limit" };
76
+ if (status === 401 || info === "unauthorized") return { code: "auth_required", category: "access" };
77
+ if (info === "usageLimitExceeded") return { code: "quota_exhausted", category: "limit" };
78
+ if (info === "contextWindowExceeded") return { code: "context_exhausted", category: "limit" };
79
+ return { code: "provider_error", category: "service" };
80
+ }
81
+
82
+ function fromAir(failure: Record<string, unknown>): ProviderNoticeActivity | null {
83
+ const noticeId = typeof failure.id === "string" && failure.id ? failure.id : undefined;
84
+ const title = text(failure.title);
85
+ if (!noticeId || !title) return null;
86
+ const severity = failure.severity === "error" ? "error" : failure.severity === "info" ? "info" : "warning";
87
+ const revision = typeof failure.revision === "number" && Number.isSafeInteger(failure.revision) ? failure.revision : 1;
88
+ const details = text(failure.details);
89
+ return {
90
+ kind: "provider_notice",
91
+ noticeId,
92
+ revision,
93
+ severity,
94
+ category: text(failure.category) ?? "unknown",
95
+ title,
96
+ ...(details ? { details } : {}),
97
+ actions: actions(failure.actions),
98
+ source: "air",
99
+ };
100
+ }
101
+
102
+ function fromCodex(error: Record<string, unknown>, fallbackId: string): ProviderNoticeActivity | null {
103
+ const title = text(error.message);
104
+ if (!title) return null;
105
+ const status = codexHttpStatus(error.codexErrorInfo);
106
+ const { code, category } = codexCode(error.codexErrorInfo, status);
107
+ const willRetry = error.willRetry === true;
108
+ const turn = typeof error.turnId === "string" && error.turnId ? error.turnId : fallbackId;
109
+ return {
110
+ kind: "provider_notice",
111
+ // One notice per turn: a later retry warning for the same turn is a new revision of it.
112
+ noticeId: `codex:${turn}`,
113
+ revision: 1,
114
+ severity: willRetry ? "warning" : "error",
115
+ category,
116
+ code,
117
+ title,
118
+ actions: willRetry ? [] : code === "auth_required" ? ["login"] : code === "rate_limited" ? ["retry"] : [],
119
+ ...(status === undefined ? {} : { httpStatus: status }),
120
+ willRetry,
121
+ source: "codex",
122
+ };
123
+ }
124
+
125
+ /**
126
+ * A provider notice in a `session_info_update`'s `_meta`, if it carries one. AIR wins when both are
127
+ * present. `fallbackId` names the notice when Codex sends no turn id.
128
+ */
129
+ export function providerNoticeFromMeta(meta: unknown, fallbackId = "session"): ProviderNoticeActivity | null {
130
+ const root = record(meta);
131
+ if (!root) return null;
132
+ const air = record(record(record(root.jetbrains)?.air)?.sessionFailure);
133
+ if (air) return fromAir(air);
134
+ const codexError = record(record(root.codex)?.error);
135
+ if (codexError) return fromCodex(codexError, fallbackId);
136
+ return null;
137
+ }
@@ -84,13 +84,13 @@ export interface ControllerCommandHandlerDeps {
84
84
  adapterId?: string;
85
85
  }
86
86
 
87
- /** Local command handlers for the low-level AgentController REPL. */
87
+ /** Local command handlers for the low-level HarnessController REPL. */
88
88
  export interface ControllerCommandHandlers {
89
89
  onSlashCommand: (command: string, args: string[]) => Promise<boolean>;
90
90
  }
91
91
 
92
92
  /**
93
- * Create the legacy low-level AgentController command set. It changes ACP provider
93
+ * Create the legacy low-level HarnessController command set. It changes ACP provider
94
94
  * sessions directly (/new, /load, /resume, /fork); it does not manage AgentSessions.
95
95
  */
96
96
  export function createControllerCommands(
@@ -25,12 +25,14 @@ export function mergeHandlers(list: readonly (PromptHandlers | undefined)[]): Pr
25
25
  return merged;
26
26
  }
27
27
 
28
- function partOf(prompt: SteeringPrompt): CombinedMessage {
28
+ /** The message a queued prompt is, as a run hands it to a backend (also one original message of a combined prompt). */
29
+ export function partOf(prompt: SteeringPrompt): CombinedMessage {
29
30
  return {
30
31
  id: prompt.turnId,
31
32
  text: prompt.text,
32
33
  messageParts: prompt.messageParts,
33
34
  attachments: prompt.attachments,
35
+ ...(prompt.beforeDispatch ? { beforeDispatch: prompt.beforeDispatch } : {}),
34
36
  ...(prompt.participantId ? { participantId: prompt.participantId } : {}),
35
37
  ...(prompt.consumerMetadata !== undefined ? { consumerMetadata: prompt.consumerMetadata } : {}),
36
38
  };
@@ -2,6 +2,7 @@ import type { AgentSessionPromptResult } from "../agent-conversation-contracts.t
2
2
  import type { PersistenceJsonValue } from "../persistence/backend.ts";
3
3
  import type { Attachment, PromptHandlers } from "../types.ts";
4
4
  import type { MessagePart } from "../media/parts.ts";
5
+ import type { MessageStatus, MessageStatusEvent } from "../message-status.ts";
5
6
 
6
7
  /**
7
8
  * How a prompt sent while a turn is running waits.
@@ -12,7 +13,7 @@ import type { MessagePart } from "../media/parts.ts";
12
13
  */
13
14
  export type PromptDelivery = "steer" | "queue";
14
15
 
15
- /** Identifies one prompt while it waits. It is the prompt's operation id. */
16
+ /** Identifies one prompt. A turn can take several messages with distinct ids. */
16
17
  export type PendingMessageId = string;
17
18
 
18
19
  /** Why a pending message was delivered when it was. */
@@ -36,8 +37,12 @@ export interface PendingMessage {
36
37
  */
37
38
  export interface PromptHandle extends Promise<AgentSessionPromptResult> {
38
39
  readonly id: PendingMessageId;
40
+ /** How far the message has got: queued, received, taken, delivered, seen, or withdrawn/failed (`message-status.ts`). */
41
+ readonly status: MessageStatus;
39
42
  /** Remove the message if it has not been delivered yet. Returns whether it was still pending. */
40
43
  withdraw(): boolean;
44
+ /** Also requests confirmed withdrawal of a native input already submitted. */
45
+ withdrawAsync(): Promise<boolean>;
41
46
  }
42
47
 
43
48
  /** Events about messages that wait. They go on the conversation event stream. */
@@ -58,10 +63,13 @@ export type MessageEvent =
58
63
  /** The operation id of the prompt (equals the first id). */
59
64
  readonly turnId: string;
60
65
  }
61
- | { readonly kind: "message_withdrawn"; readonly id: PendingMessageId };
66
+ | { readonly kind: "message_withdrawn"; readonly id: PendingMessageId }
67
+ /** The message's status changed; see `PromptHandle.status`. */
68
+ | MessageStatusEvent;
62
69
 
63
70
  /** One original message of a combined prompt. */
64
71
  export interface CombinedMessage {
72
+ readonly beforeDispatch?: (messageId: string) => Promise<void>;
65
73
  readonly messageParts?: readonly MessagePart[];
66
74
  readonly attachments?: readonly Attachment[];
67
75
  readonly id: PendingMessageId;
@@ -85,6 +93,7 @@ export interface SteeringPrompt {
85
93
  participantId?: string;
86
94
  consumerMetadata?: PersistenceJsonValue;
87
95
  handlers?: PromptHandlers;
96
+ readonly beforeDispatch?: CombinedMessage["beforeDispatch"];
88
97
  attachments?: Attachment[];
89
98
  messageParts?: readonly MessagePart[];
90
99
  /** Present only on a combined prompt: the original messages, in order. */
@@ -258,9 +258,10 @@ export class SteeringController<T extends { readonly kind: string }> {
258
258
  }
259
259
 
260
260
  /** Settle prompts that left the queue without running (withdrawn, or dropped by `interrupt`). */
261
- dropped(items: readonly SteeringPrompt[]): void {
261
+ dropped(items: readonly SteeringPrompt[], error?: Error): void {
262
262
  for (const item of items) {
263
- item.resolve(cancelledPromptResult(item));
263
+ if (error) item.reject(error);
264
+ else item.resolve(cancelledPromptResult(item));
264
265
  if (item.waited) this.host.emit({ kind: "message_withdrawn", id: item.turnId });
265
266
  }
266
267
  }
package/src/terminals.ts CHANGED
@@ -15,6 +15,8 @@ export interface CreateTerminalParams {
15
15
  args?: string[];
16
16
  cwd?: string | null;
17
17
  env?: Array<{ name: string; value: string }>;
18
+ /** Exact environment for this terminal, supplied by the host. */
19
+ terminalEnv?: Record<string, string>;
18
20
  /** Bytes of output to retain; older output is dropped from the FRONT. */
19
21
  outputByteLimit?: number | null;
20
22
  }
@@ -28,8 +30,10 @@ export interface TerminalOutput {
28
30
  export interface TerminalRegistryOptions {
29
31
  /** Fallback cwd when the agent doesn't specify one. */
30
32
  cwd?: string;
31
- /** Extra env for every terminal, merged over process.env. */
33
+ /** Base environment when no exact terminalEnv is supplied. Defaults to empty. */
32
34
  env?: Record<string, string>;
35
+ /** Exact environment for every terminal unless overridden at creation. */
36
+ terminalEnv?: Record<string, string>;
33
37
  logger?: Logger;
34
38
  }
35
39
 
@@ -113,11 +117,10 @@ export class TerminalRegistry {
113
117
  /** Spawn a command and return its terminal id. Output accumulates until released. */
114
118
  create(params: CreateTerminalParams): string {
115
119
  const id = `term-${++this.seq}`;
116
- const env: Record<string, string> = {
117
- ...(process.env as Record<string, string>),
118
- ...(this.options.env ?? {}),
119
- };
120
- for (const v of params.env ?? []) env[v.name] = v.value;
120
+ const exact = params.terminalEnv ?? this.options.terminalEnv;
121
+ const env = exact === undefined
122
+ ? { ...this.options.env, ...Object.fromEntries((params.env ?? []).map(({ name, value }) => [name, value])) }
123
+ : { ...exact };
121
124
 
122
125
  const proc = Bun.spawn(toArgv(params), {
123
126
  cwd: params.cwd ?? this.options.cwd,
@@ -5,7 +5,8 @@
5
5
 
6
6
  import * as acp from "@agentclientprotocol/sdk";
7
7
  import type * as schema from "@agentclientprotocol/sdk";
8
- import { ProcessCrashError } from "../errors.ts";
8
+ import { ConnectionCancelledError, ProcessCrashError } from "../errors.ts";
9
+ import { untilAborted } from "../connection-attempt.ts";
9
10
  import { onceDispose, type PreparedLaunch } from "../launcher.ts";
10
11
  import type { WireEntry } from "../types.ts";
11
12
 
@@ -67,6 +68,7 @@ export class AcpTransport {
67
68
  private proc: ReturnType<typeof Bun.spawn> | null = null;
68
69
  private connection: acp.ClientSideConnection | null = null;
69
70
  private stopping = false;
71
+ private readonly closed = new AbortController();
70
72
  private tap?: (dir: WireEntry["dir"], line: string) => void;
71
73
  private readonly disposeLaunch: () => Promise<void>;
72
74
 
@@ -114,13 +116,19 @@ export class AcpTransport {
114
116
  this.tap = tap;
115
117
  const handler = new ClientHandler(this.opts);
116
118
  this.connection = new acp.ClientSideConnection(() => handler, stream);
117
- this.connection.signal.addEventListener("abort", () => this.opts.onDisconnect?.(), { once: true });
119
+ const disconnected = () => {
120
+ this.closeUnexpectedly(proc.exitCode);
121
+ this.opts.onDisconnect?.();
122
+ };
123
+ if (this.connection.signal.aborted) disconnected();
124
+ else this.connection.signal.addEventListener("abort", disconnected, { once: true });
118
125
 
119
126
  if (proc.stderr) this.pumpStderr(proc.stderr as ReadableStream<Uint8Array>);
120
127
 
121
128
  proc.exited
122
129
  .then(async (code) => {
123
130
  if (this.proc === proc && !this.stopping) {
131
+ this.closeUnexpectedly(code);
124
132
  this.proc = null;
125
133
  this.connection = null;
126
134
  await this.disposeLaunch().catch(() => {});
@@ -128,6 +136,7 @@ export class AcpTransport {
128
136
  }
129
137
  }, async () => {
130
138
  if (this.proc === proc && !this.stopping) {
139
+ this.closeUnexpectedly(null);
131
140
  this.proc = null;
132
141
  this.connection = null;
133
142
  await this.disposeLaunch().catch(() => {});
@@ -143,6 +152,7 @@ export class AcpTransport {
143
152
 
144
153
  async stop(): Promise<void> {
145
154
  this.stopping = true;
155
+ this.closed.abort(new ConnectionCancelledError());
146
156
  const proc = this.proc;
147
157
  this.proc = null;
148
158
  this.connection = null;
@@ -181,10 +191,10 @@ export class AcpTransport {
181
191
  return this.conn().initialize(params);
182
192
  }
183
193
  newSession(params: schema.NewSessionRequest): Promise<schema.NewSessionResponse> {
184
- return this.conn().newSession(params);
194
+ return this.raceExit(this.conn().newSession(params));
185
195
  }
186
196
  loadSession(params: schema.LoadSessionRequest): Promise<schema.LoadSessionResponse> {
187
- return this.conn().loadSession(params);
197
+ return this.raceExit(this.conn().loadSession(params));
188
198
  }
189
199
  forkSession(params: schema.ForkSessionRequest): Promise<schema.ForkSessionResponse> {
190
200
  return this.conn().unstable_forkSession(params);
@@ -213,17 +223,17 @@ export class AcpTransport {
213
223
  return this.conn().setSessionConfigOption(params);
214
224
  }
215
225
 
216
- /** Race a promise against process exit — catches dead/unauthenticated binaries early. */
226
+ /** Observe transport close even if the SDK leaves a request pending. */
217
227
  raceExit<T>(p: Promise<T>): Promise<T> {
218
- if (!this.proc) return p;
219
- const exit = this.proc.exited.then((code) => {
220
- throw new ProcessCrashError(
221
- code ?? null,
222
- `ACP server exited (code ${code ?? "?"}) before the operation completed — ` +
223
- `verify the provider binary is installed and authenticated`,
224
- );
225
- });
226
- return Promise.race([p, exit as Promise<never>]);
228
+ return untilAborted(p, this.closed.signal);
229
+ }
230
+
231
+ throwIfClosed(): void { this.closed.signal.throwIfAborted(); }
232
+
233
+ private closeUnexpectedly(code: number | null): void {
234
+ this.closed.abort(new ProcessCrashError(code,
235
+ `ACP server exited (code ${code ?? "?"}) or closed the connection before the operation completed — ` +
236
+ "verify the provider binary is installed and authenticated"));
227
237
  }
228
238
 
229
239
  private async pumpStderr(stream: ReadableStream<Uint8Array>): Promise<void> {
package/src/types.ts CHANGED
@@ -1,9 +1,11 @@
1
+ import type { ProviderNoticeActivity } from "./provider-notices.ts";
1
2
  import type { ResolvedPart } from "./media/parts.ts";
2
3
  // Core shared types — the OUTPUT contract.
3
4
  // These are what every client (AcpClient, and later PtyClient) produces, so callers
4
5
  // render against these regardless of which mode is active. See SPEC.md.
5
6
 
6
7
  import type { ApplyResult } from "./activity.ts";
8
+ import type { PermissionOption, PermissionTool } from "./permissions/request.ts";
7
9
 
8
10
  /**
9
11
  * A slash command exposed by the replaceable ACP-backed internal session (e.g. codex
@@ -206,9 +208,14 @@ export type ActivityEvent =
206
208
  /** The agent switched session mode. */
207
209
  | { kind: "mode"; modeId: string }
208
210
  /** Context-window accounting. `used`/`size` are tokens. */
209
- | { kind: "usage"; used: number; size: number; cost?: unknown }
210
- /** The agent retitled the session or bumped its activity timestamp. */
211
- | { kind: "session_info"; title?: string | null; updatedAt?: string | null }
211
+ | { kind: "usage"; used: number; size: number; cost?: unknown; meta?: unknown }
212
+ /**
213
+ * The agent retitled the session or bumped its activity timestamp. `meta` keeps the update's
214
+ * `_meta` when it carried one this library doesn't model, so adapter-specific signals aren't lost.
215
+ */
216
+ | { kind: "session_info"; title?: string | null; updatedAt?: string | null; meta?: unknown }
217
+ /** A warning, retry or failure the provider reported in an update's `_meta` (`provider-notices.ts`). */
218
+ | ProviderNoticeActivity
212
219
  /** Config options changed; also reflected in `client.configOptions`. */
213
220
  | { kind: "config"; configOptions: unknown }
214
221
  /** A session update we don't model. The raw notification payload is attached. */
@@ -234,18 +241,15 @@ export type PermissionOutcome =
234
241
  * The open arm keeps a kind we don't know yet from failing to typecheck; branch with a
235
242
  * fallback rather than assuming the four.
236
243
  */
237
- export type PermissionOptionKind =
238
- | "allow_once"
239
- | "allow_always"
240
- | "reject_once"
241
- | "reject_always"
242
- | (string & {});
244
+ export type { PermissionOptionKind } from "./permissions/request.ts";
243
245
 
244
246
  /** A permission request surfaced to the caller. The agent BLOCKS until this resolves. */
245
247
  export interface PermissionRequest {
246
248
  toolCallId: string;
247
249
  title?: string;
248
- options: Array<{ optionId: string; name: string; kind: PermissionOptionKind }>;
250
+ options: PermissionOption[];
251
+ /** Neutral tool data when the producer supplies it. */
252
+ tool?: PermissionTool;
249
253
  /** The raw SDK request, for callers that need fields we haven't surfaced. */
250
254
  raw: unknown;
251
255
  }
@@ -274,8 +278,7 @@ export interface PromptHandlers {
274
278
  */
275
279
  onUpdate?: (notification: unknown) => void;
276
280
  /**
277
- * Blocking permission request. Must return an outcome. If omitted, the client
278
- * falls back to its configured `defaultPermission`.
281
+ * Blocking callback for a request whose configured permission level is ask.
279
282
  */
280
283
  onPermissionRequest?: (
281
284
  request: PermissionRequest,
package/src/updates.ts CHANGED
@@ -21,6 +21,7 @@ import type {
21
21
  ResponseChunk,
22
22
  } from "./types.ts";
23
23
  import { acpToPart } from "./media/acp.ts";
24
+ import { providerNoticeFromMeta } from "./provider-notices.ts";
24
25
 
25
26
  /** A response delta preserving its ACP message id, or null for any other update. */
26
27
  export function extractResponseChunk(
@@ -118,10 +119,21 @@ export function toActivityEvent(update: schema.SessionUpdate): ActivityEvent | n
118
119
  used: Number(u.used ?? 0),
119
120
  size: Number(u.size ?? 0),
120
121
  ...(u.cost != null ? { cost: u.cost } : {}),
122
+ // Kept raw: adapters attach details here (claude-agent-acp: `_claude/rateLimit`).
123
+ ...(u._meta != null ? { meta: u._meta } : {}),
121
124
  };
122
125
 
123
- case "session_info_update":
124
- return { kind: "session_info", title: u.title ?? null, updatedAt: u.updatedAt ?? null };
126
+ case "session_info_update": {
127
+ // Adapters report warnings, retries and failures in this update's `_meta` (provider-notices.ts).
128
+ const notice = providerNoticeFromMeta(u._meta);
129
+ if (notice) return notice;
130
+ return {
131
+ kind: "session_info",
132
+ title: u.title ?? null,
133
+ updatedAt: u.updatedAt ?? null,
134
+ ...(u._meta != null ? { meta: u._meta } : {}),
135
+ };
136
+ }
125
137
 
126
138
  default:
127
139
  return {
package/src/wire-log.ts CHANGED
@@ -35,7 +35,7 @@ const encoder = new TextEncoder();
35
35
  const decoder = new TextDecoder();
36
36
 
37
37
  /**
38
- * Build a `WireEntry` sink for `wire` on `AgentSession`/`AgentController`/`AcpClient`.
38
+ * Build a `WireEntry` sink for `wire` on `AgentSession`/`HarnessController`/`AcpClient`.
39
39
  *
40
40
  * Writes are chained rather than awaited by the caller: the tap sits in the middle of the
41
41
  * protocol stream, so blocking it on disk would stall the conversation. Ordering is