@agentclientprotocol/claude-agent-acp 0.102.1-preview.1 → 0.102.1-preview.3

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 (229) hide show
  1. package/README.md +5 -1
  2. package/dist/acp-agent.d.ts +93 -622
  3. package/dist/acp-agent.d.ts.map +1 -1
  4. package/dist/acp-agent.js +369 -3474
  5. package/dist/acp-client.d.ts +28 -0
  6. package/dist/acp-client.d.ts.map +1 -0
  7. package/dist/acp-client.js +1 -0
  8. package/dist/acp-subagents.d.ts +1 -2
  9. package/dist/acp-subagents.d.ts.map +1 -1
  10. package/dist/auth-methods.d.ts +21 -0
  11. package/dist/auth-methods.d.ts.map +1 -0
  12. package/dist/auth-methods.js +68 -0
  13. package/dist/auth-status-reporter.d.ts +112 -0
  14. package/dist/auth-status-reporter.d.ts.map +1 -0
  15. package/dist/auth-status-reporter.js +253 -0
  16. package/dist/background-work.d.ts +12 -265
  17. package/dist/background-work.d.ts.map +1 -1
  18. package/dist/background-work.js +8 -558
  19. package/dist/client-system-prompt.d.ts +7 -0
  20. package/dist/client-system-prompt.d.ts.map +1 -1
  21. package/dist/client-system-prompt.js +24 -0
  22. package/dist/context-compaction.d.ts +20 -0
  23. package/dist/context-compaction.d.ts.map +1 -1
  24. package/dist/context-compaction.js +26 -0
  25. package/dist/context-window.d.ts +70 -0
  26. package/dist/context-window.d.ts.map +1 -0
  27. package/dist/context-window.js +132 -0
  28. package/dist/diff.d.ts +1 -1
  29. package/dist/diff.js +1 -1
  30. package/dist/elicitation.d.ts +66 -1
  31. package/dist/elicitation.d.ts.map +1 -1
  32. package/dist/elicitation.js +109 -0
  33. package/dist/file-change-audit.d.ts +4 -3
  34. package/dist/file-change-audit.d.ts.map +1 -1
  35. package/dist/file-change-audit.js +3 -2
  36. package/dist/lib.d.ts +5 -1
  37. package/dist/lib.d.ts.map +1 -1
  38. package/dist/lib.js +3 -1
  39. package/dist/logger.d.ts +10 -0
  40. package/dist/logger.d.ts.map +1 -0
  41. package/dist/logger.js +1 -0
  42. package/dist/mcp-oauth.d.ts +44 -0
  43. package/dist/mcp-oauth.d.ts.map +1 -0
  44. package/dist/mcp-oauth.js +142 -0
  45. package/dist/mcp-servers.d.ts +10 -0
  46. package/dist/mcp-servers.d.ts.map +1 -0
  47. package/dist/mcp-servers.js +29 -0
  48. package/dist/message-filters.d.ts +43 -0
  49. package/dist/message-filters.d.ts.map +1 -0
  50. package/dist/message-filters.js +197 -0
  51. package/dist/native-subagents.d.ts +18 -8
  52. package/dist/native-subagents.d.ts.map +1 -1
  53. package/dist/native-subagents.js +7 -35
  54. package/dist/new-session-meta.d.ts +40 -0
  55. package/dist/new-session-meta.d.ts.map +1 -0
  56. package/dist/new-session-meta.js +1 -0
  57. package/dist/permissions/presentation.d.ts +29 -0
  58. package/dist/permissions/presentation.d.ts.map +1 -1
  59. package/dist/permissions/presentation.js +38 -11
  60. package/dist/prompt-suggestions.d.ts +29 -0
  61. package/dist/prompt-suggestions.d.ts.map +1 -1
  62. package/dist/prompt-suggestions.js +45 -0
  63. package/dist/prompt-to-claude.d.ts +10 -0
  64. package/dist/prompt-to-claude.d.ts.map +1 -0
  65. package/dist/prompt-to-claude.js +120 -0
  66. package/dist/providers.d.ts +139 -0
  67. package/dist/providers.d.ts.map +1 -0
  68. package/dist/providers.js +286 -0
  69. package/dist/remote-control.d.ts +62 -0
  70. package/dist/remote-control.d.ts.map +1 -0
  71. package/dist/remote-control.js +78 -0
  72. package/dist/result-end.d.ts +68 -0
  73. package/dist/result-end.d.ts.map +1 -0
  74. package/dist/result-end.js +84 -0
  75. package/dist/sdk-to-acp.d.ts +93 -0
  76. package/dist/sdk-to-acp.d.ts.map +1 -0
  77. package/dist/sdk-to-acp.js +635 -0
  78. package/dist/serve.d.ts +9 -3
  79. package/dist/serve.d.ts.map +1 -1
  80. package/dist/serve.js +10 -5
  81. package/dist/session-config-ids.d.ts +1 -0
  82. package/dist/session-config-ids.d.ts.map +1 -1
  83. package/dist/session-config-ids.js +1 -0
  84. package/dist/session-config-options.d.ts +64 -0
  85. package/dist/session-config-options.d.ts.map +1 -0
  86. package/dist/session-config-options.js +162 -0
  87. package/dist/session-effort.d.ts +67 -0
  88. package/dist/session-effort.d.ts.map +1 -1
  89. package/dist/session-effort.js +98 -0
  90. package/dist/session-env.d.ts +22 -0
  91. package/dist/session-env.d.ts.map +1 -0
  92. package/dist/session-env.js +66 -0
  93. package/dist/session-fast-mode.d.ts +83 -0
  94. package/dist/session-fast-mode.d.ts.map +1 -0
  95. package/dist/session-fast-mode.js +142 -0
  96. package/dist/session-index/connection.d.ts +5 -6
  97. package/dist/session-index/connection.d.ts.map +1 -1
  98. package/dist/session-index/connection.js +3 -5
  99. package/dist/session-mode.d.ts +1 -0
  100. package/dist/session-mode.d.ts.map +1 -1
  101. package/dist/session-mode.js +1 -1
  102. package/dist/session-model.d.ts +41 -0
  103. package/dist/session-model.d.ts.map +1 -1
  104. package/dist/session-model.js +110 -45
  105. package/dist/session-notices.d.ts +44 -0
  106. package/dist/session-notices.d.ts.map +1 -1
  107. package/dist/session-notices.js +68 -0
  108. package/dist/session-titles.d.ts +34 -12
  109. package/dist/session-titles.d.ts.map +1 -1
  110. package/dist/session-titles.js +7 -6
  111. package/dist/session-usage.d.ts +125 -0
  112. package/dist/session-usage.d.ts.map +1 -0
  113. package/dist/session-usage.js +196 -0
  114. package/dist/slash-commands.d.ts +10 -0
  115. package/dist/slash-commands.d.ts.map +1 -0
  116. package/dist/slash-commands.js +99 -0
  117. package/dist/streamed-text.d.ts +33 -0
  118. package/dist/streamed-text.d.ts.map +1 -0
  119. package/dist/streamed-text.js +71 -0
  120. package/dist/subagent-configuration.d.ts +32 -0
  121. package/dist/subagent-configuration.d.ts.map +1 -0
  122. package/dist/subagent-configuration.js +70 -0
  123. package/dist/subagent-replay.d.ts +18 -0
  124. package/dist/subagent-replay.d.ts.map +1 -1
  125. package/dist/subagent-replay.js +25 -15
  126. package/dist/tool-calls/client-capabilities.d.ts +8 -8
  127. package/dist/tool-calls/client-capabilities.js +4 -4
  128. package/dist/tool-calls/renderer.d.ts +4 -5
  129. package/dist/tool-calls/renderer.d.ts.map +1 -1
  130. package/dist/tool-calls/renderer.js +4 -5
  131. package/dist/turn-events.d.ts +6 -46
  132. package/dist/turn-events.d.ts.map +1 -1
  133. package/dist/utils.d.ts +1 -1
  134. package/dist/utils.d.ts.map +1 -1
  135. package/dist/v2/agent.d.ts +7 -11
  136. package/dist/v2/agent.d.ts.map +1 -1
  137. package/dist/v2/agent.js +751 -331
  138. package/dist/v2/air.d.ts +33 -0
  139. package/dist/v2/air.d.ts.map +1 -0
  140. package/dist/v2/air.js +29 -0
  141. package/dist/v2/auth.d.ts +97 -0
  142. package/dist/v2/auth.d.ts.map +1 -0
  143. package/dist/v2/auth.js +216 -0
  144. package/dist/v2/background.d.ts +27 -16
  145. package/dist/v2/background.d.ts.map +1 -1
  146. package/dist/v2/background.js +4 -32
  147. package/dist/v2/child-config.d.ts +55 -0
  148. package/dist/v2/child-config.d.ts.map +1 -0
  149. package/dist/v2/child-config.js +92 -0
  150. package/dist/v2/clear-context.d.ts +94 -0
  151. package/dist/v2/clear-context.d.ts.map +1 -0
  152. package/dist/v2/clear-context.js +176 -0
  153. package/dist/v2/commands.d.ts +46 -0
  154. package/dist/v2/commands.d.ts.map +1 -0
  155. package/dist/v2/commands.js +54 -0
  156. package/dist/v2/config.d.ts +187 -0
  157. package/dist/v2/config.d.ts.map +1 -0
  158. package/dist/v2/config.js +494 -0
  159. package/dist/v2/elicitation.d.ts +93 -0
  160. package/dist/v2/elicitation.d.ts.map +1 -0
  161. package/dist/v2/elicitation.js +160 -0
  162. package/dist/v2/file-changes.d.ts +61 -0
  163. package/dist/v2/file-changes.d.ts.map +1 -0
  164. package/dist/v2/file-changes.js +108 -0
  165. package/dist/v2/file-preview.d.ts +18 -0
  166. package/dist/v2/file-preview.d.ts.map +1 -0
  167. package/dist/v2/file-preview.js +29 -0
  168. package/dist/v2/initialize.d.ts +10 -24
  169. package/dist/v2/initialize.d.ts.map +1 -1
  170. package/dist/v2/initialize.js +4 -111
  171. package/dist/v2/outcome.d.ts +81 -0
  172. package/dist/v2/outcome.d.ts.map +1 -0
  173. package/dist/v2/outcome.js +166 -0
  174. package/dist/v2/permissions.d.ts +92 -0
  175. package/dist/v2/permissions.d.ts.map +1 -0
  176. package/dist/v2/permissions.js +162 -0
  177. package/dist/v2/prompt.d.ts +2 -42
  178. package/dist/v2/prompt.d.ts.map +1 -1
  179. package/dist/v2/prompt.js +2 -119
  180. package/dist/v2/remote-control.d.ts +41 -0
  181. package/dist/v2/remote-control.d.ts.map +1 -0
  182. package/dist/v2/remote-control.js +63 -0
  183. package/dist/v2/reports.d.ts +198 -0
  184. package/dist/v2/reports.d.ts.map +1 -0
  185. package/dist/v2/reports.js +487 -0
  186. package/dist/v2/restarts.d.ts +128 -0
  187. package/dist/v2/restarts.d.ts.map +1 -0
  188. package/dist/v2/restarts.js +348 -0
  189. package/dist/v2/session-requests.d.ts +20 -0
  190. package/dist/v2/session-requests.d.ts.map +1 -0
  191. package/dist/v2/session-requests.js +108 -0
  192. package/dist/v2/session-update.d.ts +2 -13
  193. package/dist/v2/session-update.d.ts.map +1 -1
  194. package/dist/v2/session-update.js +2 -22
  195. package/dist/v2/session.d.ts +340 -41
  196. package/dist/v2/session.d.ts.map +1 -1
  197. package/dist/v2/session.js +1224 -141
  198. package/dist/v2/setup.d.ts +49 -0
  199. package/dist/v2/setup.d.ts.map +1 -0
  200. package/dist/v2/setup.js +62 -0
  201. package/dist/v2/stopped-work.d.ts +123 -0
  202. package/dist/v2/stopped-work.d.ts.map +1 -0
  203. package/dist/v2/stopped-work.js +210 -0
  204. package/dist/v2/stream.d.ts +229 -0
  205. package/dist/v2/stream.d.ts.map +1 -0
  206. package/dist/v2/stream.js +507 -0
  207. package/dist/v2/subagent-replay.d.ts +115 -0
  208. package/dist/v2/subagent-replay.d.ts.map +1 -0
  209. package/dist/v2/subagent-replay.js +479 -0
  210. package/dist/v2/subscription-guard.d.ts +60 -0
  211. package/dist/v2/subscription-guard.d.ts.map +1 -0
  212. package/dist/v2/subscription-guard.js +84 -0
  213. package/dist/v2/tasks.d.ts +492 -0
  214. package/dist/v2/tasks.d.ts.map +1 -0
  215. package/dist/v2/tasks.js +1728 -0
  216. package/dist/v2/terminal.d.ts.map +1 -1
  217. package/dist/v2/terminal.js +6 -1
  218. package/dist/v2/tool-call.d.ts +3 -2
  219. package/dist/v2/tool-call.d.ts.map +1 -1
  220. package/dist/v2/update-translator.d.ts +36 -0
  221. package/dist/v2/update-translator.d.ts.map +1 -0
  222. package/dist/v2/update-translator.js +80 -0
  223. package/dist/workflow-progress.d.ts +23 -0
  224. package/dist/workflow-progress.d.ts.map +1 -1
  225. package/dist/workflow-progress.js +31 -8
  226. package/package.json +1 -1
  227. package/dist/v2/permission.d.ts +0 -28
  228. package/dist/v2/permission.d.ts.map +0 -1
  229. package/dist/v2/permission.js +0 -41
@@ -0,0 +1,166 @@
1
+ /**
2
+ * How a turn of an ACP v2 session ends: the stop reason, usage, error
3
+ * and `_meta.quota` of its `idle`. Whether Claude Code's result failed the
4
+ * turn, and its stop reason or error text, follow the rules that the v1 core
5
+ * reads its results with too (`resultEnd`). The error is the one v1 answers a
6
+ * failed prompt with: an authentication failure is `authRequired`
7
+ * (-32000), and any other carries the assistant message's error kind
8
+ * (`data.errorKind`).
9
+ */
10
+ import { RequestError } from "@agentclientprotocol/sdk/unstable";
11
+ import { AUTONOMOUS_RESULT_ORIGINS } from "../result-end.js";
12
+ import { isSyntheticLoginMessage } from "../message-filters.js";
13
+ import { resultEnd } from "../result-end.js";
14
+ import { providerFailureCategory } from "../session-failure-extension.js";
15
+ import { getMatchingModelUsage, modelUsageIncrement, normalizeModelUsage, quotaMeta, resumedFirstResultModelUsage, tallyTotal, } from "../session-usage.js";
16
+ /** What a prompt's turn that ended without a result spent. */
17
+ const NOTHING_SPENT = {
18
+ inputTokens: 0,
19
+ outputTokens: 0,
20
+ cachedReadTokens: 0,
21
+ cachedWriteTokens: 0,
22
+ };
23
+ /**
24
+ * The stop reason, usage and `_meta.quota` of an idle, from the result that
25
+ * ended the turn, and what its assistant messages reported (`report`).
26
+ * `prompted`: a prompt started the turn. Without a result, such as when an
27
+ * interrupt stopped the work before its result, a prompt's turn reports zero
28
+ * usage and a zero quota, and a cycle that Claude Code started on its own
29
+ * reports neither. A failed turn reports its error instead.
30
+ */
31
+ export function idleOutcome(end, cancelled, report, prompted = false) {
32
+ const spent = end
33
+ ? { usage: end.usage, _meta: end._meta }
34
+ : prompted
35
+ ? { usage: { ...NOTHING_SPENT, totalTokens: 0 }, _meta: quotaMeta(NOTHING_SPENT, {}) }
36
+ : {};
37
+ if (cancelled)
38
+ return { stopReason: "cancelled", ...spent };
39
+ // Claude Code's sign-in message fails the turn.
40
+ if (report?.loginRequired)
41
+ return failed(RequestError.authRequired());
42
+ if (!end)
43
+ return { stopReason: "end_turn", ...spent };
44
+ const { result } = end;
45
+ const ended = resultEnd(result);
46
+ if (!("error" in ended))
47
+ return { stopReason: ended.stopReason, ...spent };
48
+ const kind = report?.errorKind;
49
+ // Only these subtypes read the assistant's error kind for the failure's
50
+ // category.
51
+ const authFailure = ended.loginRequired ||
52
+ ((result.subtype === "success" || result.subtype === "error_during_execution") &&
53
+ providerFailureCategory(kind) === "auth_required");
54
+ return failed(authFailure
55
+ ? RequestError.authRequired()
56
+ : RequestError.internalError(kind ? { errorKind: kind } : undefined, ended.error));
57
+ }
58
+ function failed(error) {
59
+ return {
60
+ stopReason: "error",
61
+ error: {
62
+ code: error.code,
63
+ message: error.message,
64
+ ...(error.data !== undefined ? { data: error.data } : {}),
65
+ },
66
+ };
67
+ }
68
+ /**
69
+ * What the assistant messages of the open turn reported about its end: the
70
+ * error kind of a failed API request, Claude Code's sign-in message, and a
71
+ * refusal's explanation. Read from the main conversation's messages.
72
+ */
73
+ export class TurnReport {
74
+ errorKind;
75
+ /** Claude Code showed its sign-in message ("Not logged in · Please run /login"). */
76
+ loginRequired = false;
77
+ /** The explanation of the turn's refusal. */
78
+ refusalExplanation;
79
+ /**
80
+ * An assistant message of the main conversation. Returns whether it is
81
+ * Claude Code's sign-in message, which the client is not shown: its
82
+ * `/login` instruction is for Claude Code's terminal, and the turn's idle
83
+ * fails with `authRequired` instead.
84
+ */
85
+ assistant(message) {
86
+ if (message.error)
87
+ this.errorKind = message.error;
88
+ if (message.message.stop_reason === "refusal") {
89
+ this.refusalExplanation =
90
+ message.message.stop_details?.explanation ?? this.refusalExplanation;
91
+ }
92
+ if (!isSyntheticLoginMessage(message.message))
93
+ return false;
94
+ this.loginRequired = true;
95
+ return true;
96
+ }
97
+ /**
98
+ * Claude Code's `model_refusal_no_fallback`: the explanation when the
99
+ * refused message carried none (older CLIs, gateways that drop
100
+ * `stop_details`). One for a turn that no user prompt started
101
+ * (`refused_user_message_uuid: null`) is not this turn's.
102
+ */
103
+ refusalWithoutFallback(message) {
104
+ if (this.refusalExplanation || message.refused_user_message_uuid === null)
105
+ return;
106
+ this.refusalExplanation = message.api_refusal_explanation ?? message.content;
107
+ }
108
+ reset() {
109
+ this.errorKind = undefined;
110
+ this.loginRequired = false;
111
+ this.refusalExplanation = undefined;
112
+ }
113
+ }
114
+ /**
115
+ * Whether `result` is a placeholder: Claude Code answers background-task
116
+ * notifications that queued up with one model call, and gives each but the
117
+ * last a result with `num_turns: 0` before that call runs. The cycle goes on
118
+ * to the last one's result.
119
+ */
120
+ export function isPlaceholderResult(result) {
121
+ return (result.origin != null &&
122
+ AUTONOMOUS_RESULT_ORIGINS.has(result.origin.kind) &&
123
+ result.num_turns === 0 &&
124
+ !result.is_error);
125
+ }
126
+ /**
127
+ * What each result spent. `result.modelUsage` is a running total of the
128
+ * query, so a result's rows are its increment over the previous reading. A
129
+ * resumed query's first reading continues the totals of its transcript, so
130
+ * that result's row is its own `usage`, under the model of the last
131
+ * assistant message (see `resumedFirstResultModelUsage`).
132
+ */
133
+ export class ResultUsage {
134
+ reading;
135
+ model = null;
136
+ constructor(resumed) {
137
+ this.reading = resumed ? undefined : {};
138
+ }
139
+ /** An assistant message of the main conversation, by `model`. */
140
+ assistant(model) {
141
+ if (model && model !== "<synthetic>")
142
+ this.model = model;
143
+ }
144
+ /** What `result` spent. Every result moves the reading on, also a placeholder. */
145
+ record(result) {
146
+ const tally = {
147
+ inputTokens: result.usage.input_tokens ?? 0,
148
+ outputTokens: result.usage.output_tokens ?? 0,
149
+ cachedReadTokens: result.usage.cache_read_input_tokens ?? 0,
150
+ cachedWriteTokens: result.usage.cache_creation_input_tokens ?? 0,
151
+ };
152
+ const reading = normalizeModelUsage(result.modelUsage);
153
+ const key = this.model === null
154
+ ? null
155
+ : (getMatchingModelUsage(result.modelUsage ?? {}, this.model)?.key ?? this.model);
156
+ const rows = this.reading === undefined
157
+ ? resumedFirstResultModelUsage(result.usage, key)
158
+ : modelUsageIncrement(reading, this.reading);
159
+ this.reading = reading;
160
+ return {
161
+ result,
162
+ usage: { ...tally, totalTokens: tallyTotal(tally) },
163
+ _meta: quotaMeta(tally, rows),
164
+ };
165
+ }
166
+ }
@@ -0,0 +1,92 @@
1
+ /**
2
+ * Claude Code's permission checks (`canUseTool`), asked as ACP v2 permission
3
+ * requests.
4
+ *
5
+ * The request is built and its answer read by the same helpers as on v1
6
+ * (`permissions/*`), so a v2 client gets the same options and the same
7
+ * effects of each.
8
+ */
9
+ import type { RequestPermissionResponse, ToolCallUpdate } from "@agentclientprotocol/sdk/unstable";
10
+ import type * as v2 from "@agentclientprotocol/sdk/experimental/v2/unstable";
11
+ import type { CanUseTool, PermissionMode, PermissionResult } from "@anthropic-ai/claude-agent-sdk";
12
+ import { type AcpPermissionRequest } from "../permissions/presentation.js";
13
+ import type { ClearContextReset } from "../clear-context-coordinator.js";
14
+ import type { RequestTarget } from "./tasks.js";
15
+ /** What a permission check needs of its root session. */
16
+ export interface PermissionHost {
17
+ /**
18
+ * The client is JetBrains AIR: a request carries the AIR permission
19
+ * presentation, and its tool call the AIR `_meta.claudeCode` (see
20
+ * `permissionToolCallMeta`).
21
+ */
22
+ readonly airClient: boolean;
23
+ /** The ids of the modes that the session offers. */
24
+ availableModes(): string[];
25
+ /**
26
+ * The session that the request goes to: the root, or the child session of
27
+ * the subagent `agentId`. It counts the request as open while it is
28
+ * (`requires_action`).
29
+ */
30
+ target(agentId: string | undefined): Promise<RequestTarget>;
31
+ /** The user picked a mode in the answer, such as ExitPlanMode's "auto-accept edits". */
32
+ modeChanged(mode: PermissionMode): void;
33
+ /** The mode the session left when it entered plan mode, while it is in plan. */
34
+ prePlanMode(): string | undefined;
35
+ /** An allowed answer, with a mode the model cannot serve set as its fallback (see `config.ts`). */
36
+ permissionAllowed(result: PermissionResult): Promise<PermissionResult>;
37
+ /**
38
+ * Whether ExitPlanMode of the agent `agentId` offers to clear the context
39
+ * (see `ClearContext`), and how much of the context is in use.
40
+ */
41
+ contextReset(agentId: string | undefined): {
42
+ offered: boolean;
43
+ usedPercent: number | undefined;
44
+ };
45
+ /**
46
+ * An ExitPlanMode answer that interrupts the cycle: "No, keep planning", or
47
+ * a plan accepted with clearing the context (`reset`).
48
+ */
49
+ exitPlanInterrupting(toolUseId: string, reset: ClearContextReset | undefined): void;
50
+ /**
51
+ * A permission request of `target` is about to show the tool call
52
+ * `toolCallId` of `toolName` (see `SessionTasks.requestShows`).
53
+ */
54
+ requestShows(target: RequestTarget, toolName: string, toolCallId: string): void;
55
+ /** The subject's tool call, with the `_meta` that the client holds of it. */
56
+ toolCallSubject<T extends ToolCallUpdate>(sessionId: string, toolCall: T): T;
57
+ /**
58
+ * Whether the tool use is of work that a cancel stopped before the client
59
+ * saw it (see `StoppedWork`): it is denied without a request (see
60
+ * {@link denyingStoppedWork}).
61
+ */
62
+ dropsToolUse(toolUseId: string, agentId: string | undefined, signal: AbortSignal): Promise<boolean>;
63
+ }
64
+ /**
65
+ * Denies the tool uses of work that a cancel stopped before the client saw it
66
+ * (see `StoppedWork`), without a request, before `inner` asks the client
67
+ * anything: a permission request, or AskUserQuestion's questions. The client
68
+ * was told that this work never ran.
69
+ */
70
+ export declare function denyingStoppedWork(host: Pick<PermissionHost, "dropsToolUse">, inner: CanUseTool): CanUseTool;
71
+ export declare function canUseTool(host: PermissionHost): CanUseTool;
72
+ /**
73
+ * The v2 form of a permission request.
74
+ *
75
+ * v1 asks about a tool call, whose title the prompt shows. v2 gives the prompt
76
+ * its own `title` and `description`, which the presentation sets for a v2
77
+ * client (`AcpPermissionRequest`), and asks about a `subject`: here always the tool
78
+ * call, as the same patch that a `tool_call_update` carries.
79
+ */
80
+ export declare function v2PermissionRequest(request: AcpPermissionRequest): v2.RequestPermissionRequest;
81
+ /**
82
+ * The v1 form of the answer to a permission request.
83
+ *
84
+ * v2 adds outcomes that v1 does not know, which the draft says are no
85
+ * approval. They become `cancelled`. In v2, `cancelled` also means that the
86
+ * user dismissed the prompt or the client declined it by policy. So the v2
87
+ * core reads a `cancelled` outcome as the user refusing the tool, unless a
88
+ * `session/cancel` is stopping the session's work: then the tool use is
89
+ * aborted, as on v1 (`canUseTool`).
90
+ */
91
+ export declare function v1PermissionResponse(response: v2.RequestPermissionResponse): RequestPermissionResponse;
92
+ //# sourceMappingURL=permissions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"permissions.d.ts","sourceRoot":"","sources":["../../src/v2/permissions.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,yBAAyB,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AACnG,OAAO,KAAK,KAAK,EAAE,MAAM,mDAAmD,CAAC;AAC7E,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAInG,OAAO,EAIL,KAAK,oBAAoB,EAC1B,MAAM,gCAAgC,CAAC;AAGxC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACzE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAKhD,yDAAyD;AACzD,MAAM,WAAW,cAAc;IAC7B;;;;OAIG;IACH,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,oDAAoD;IACpD,cAAc,IAAI,MAAM,EAAE,CAAC;IAC3B;;;;OAIG;IACH,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;IAC5D,wFAAwF;IACxF,WAAW,CAAC,IAAI,EAAE,cAAc,GAAG,IAAI,CAAC;IACxC,gFAAgF;IAChF,WAAW,IAAI,MAAM,GAAG,SAAS,CAAC;IAClC,mGAAmG;IACnG,iBAAiB,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;IACvE;;;OAGG;IACH,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,WAAW,EAAE,MAAM,GAAG,SAAS,CAAA;KAAE,CAAC;IACjG;;;OAGG;IACH,oBAAoB,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,iBAAiB,GAAG,SAAS,GAAG,IAAI,CAAC;IACpF;;;OAGG;IACH,YAAY,CAAC,MAAM,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAChF,6EAA6E;IAC7E,eAAe,CAAC,CAAC,SAAS,cAAc,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,GAAG,CAAC,CAAC;IAC7E;;;;OAIG;IACH,YAAY,CACV,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,MAAM,EAAE,WAAW,GAClB,OAAO,CAAC,OAAO,CAAC,CAAC;CACrB;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,IAAI,CAAC,cAAc,EAAE,cAAc,CAAC,EAC1C,KAAK,EAAE,UAAU,GAChB,UAAU,CAOZ;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,cAAc,GAAG,UAAU,CAoI3D;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,oBAAoB,GAAG,EAAE,CAAC,wBAAwB,CAY9F;AAED;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,EAAE,CAAC,yBAAyB,GACrC,yBAAyB,CAS3B"}
@@ -0,0 +1,162 @@
1
+ import { previewPatchContent } from "../diff.js";
2
+ import { normalizeDurablePermissionChangeSet } from "../permissions/normalization.js";
3
+ import { buildClaudePermissionOptions } from "../permissions/options.js";
4
+ import { airPermissionMeta, buildClaudePermissionPresentation, permissionToolCallMeta, } from "../permissions/presentation.js";
5
+ import { decodeClaudePermissionResponse } from "../permissions/response.js";
6
+ import { ClientCapabilities } from "../tool-calls/client-capabilities.js";
7
+ import { v2ToolCallPatch } from "./tool-call.js";
8
+ const V2_CAPABILITIES = ClientCapabilities.from(undefined, { v2: true });
9
+ /**
10
+ * Denies the tool uses of work that a cancel stopped before the client saw it
11
+ * (see `StoppedWork`), without a request, before `inner` asks the client
12
+ * anything: a permission request, or AskUserQuestion's questions. The client
13
+ * was told that this work never ran.
14
+ */
15
+ export function denyingStoppedWork(host, inner) {
16
+ return async (toolName, toolInput, options) => {
17
+ if (await host.dropsToolUse(options.toolUseID, options.agentID, options.signal)) {
18
+ return { behavior: "deny", message: "The user cancelled this prompt." };
19
+ }
20
+ return inner(toolName, toolInput, options);
21
+ };
22
+ }
23
+ export function canUseTool(host) {
24
+ return async (toolName, toolInput, { signal, suggestions, toolUseID, matchedAskRule, blockedPath, decisionReason, title, displayName, description, defaultToNo, suppressAlwaysAllowRule, agentID, mcpServer, }) => {
25
+ // No persistent "always allow" when the user's own ask rule forced the
26
+ // prompt, or when Claude Code says the rule it would write grants more
27
+ // than this ask.
28
+ const noPersistentRule = matchedAskRule !== undefined || suppressAlwaysAllowRule === true;
29
+ const durableChangeSet = normalizeDurablePermissionChangeSet(suggestions, noPersistentRule);
30
+ // A v2 diff cannot hold an Edit's snippet: the request shows the exact patch.
31
+ const previewCwd = (await host.target(agentID)).cwd;
32
+ const previewContent = await previewPatchContent(toolName, toolInput, previewCwd, "v2");
33
+ // After the last await: a subagent announced meanwhile gets the request
34
+ // on its own session.
35
+ const target = await host.target(agentID);
36
+ const presentation = buildClaudePermissionPresentation({
37
+ toolName,
38
+ input: toolInput,
39
+ toolUseID,
40
+ cwd: target.cwd,
41
+ capabilities: V2_CAPABILITIES,
42
+ previewContent,
43
+ blockedPath,
44
+ title,
45
+ displayName,
46
+ description,
47
+ decisionReason,
48
+ defaultToNo,
49
+ });
50
+ // The tool call keeps the v2 rendering that the stream gave it. An AIR
51
+ // client also gets the heading and explanation in AIR's `_meta`.
52
+ if (host.airClient && presentation.title) {
53
+ presentation._meta = airPermissionMeta({
54
+ title: presentation.title,
55
+ description: presentation.description,
56
+ defaultToNo,
57
+ });
58
+ }
59
+ const toolCallMeta = permissionToolCallMeta({
60
+ toolName,
61
+ parentToolUseId: target.parentToolUseId,
62
+ mcpServer,
63
+ airClient: host.airClient,
64
+ });
65
+ if (toolCallMeta)
66
+ presentation.toolCall._meta = toolCallMeta;
67
+ const contextReset = host.contextReset(agentID);
68
+ const options = buildClaudePermissionOptions({
69
+ toolName,
70
+ displayName,
71
+ input: toolInput,
72
+ cwd: target.cwd,
73
+ durableChangeSet,
74
+ allowPersistentOptions: !noPersistentRule,
75
+ defaultToNo,
76
+ availableModes: host.availableModes(),
77
+ prePlanMode: host.prePlanMode(),
78
+ allowContextReset: contextReset.offered,
79
+ contextUsedPercent: contextReset.usedPercent,
80
+ });
81
+ // The stream never shows SandboxNetworkAccess's tool call: the client
82
+ // gets it before the request, and its status after the answer.
83
+ const networkAccess = toolName === "SandboxNetworkAccess";
84
+ if (networkAccess)
85
+ target.output.permissionToolCall(toolName, toolUseID, toolInput);
86
+ host.requestShows(target, toolName, toolUseID);
87
+ const toolCall = host.toolCallSubject(target.sessionId, presentation.toolCall);
88
+ const response = v1PermissionResponse(await target.requestPermission(v2PermissionRequest({ ...presentation, toolCall, options, sessionId: target.sessionId }), signal));
89
+ if (signal.aborted)
90
+ throw new Error("Tool use aborted");
91
+ // In v2, `cancelled` is also the user dismissing the prompt. Without a
92
+ // `session/cancel`, that is a refusal, and the turn goes on.
93
+ if (response.outcome.outcome === "cancelled") {
94
+ if (target.cancelling())
95
+ throw new Error("Tool use aborted");
96
+ return {
97
+ behavior: "deny",
98
+ message: "User refused permission to run tool",
99
+ toolUseID,
100
+ decisionClassification: "user_reject",
101
+ };
102
+ }
103
+ const decision = decodeClaudePermissionResponse(response, toolName, toolInput, toolUseID, options, durableChangeSet);
104
+ const decoded = decision.permissionResult;
105
+ if (toolName === "ExitPlanMode" && decoded.behavior === "deny" && decoded.interrupt === true) {
106
+ const plan = typeof toolInput.plan === "string" ? toolInput.plan.trim() : "";
107
+ host.exitPlanInterrupting(toolUseID, decision.contextResetMode && plan
108
+ ? { toolUseId: toolUseID, plan, mode: decision.contextResetMode }
109
+ : undefined);
110
+ }
111
+ const permissionResult = await host.permissionAllowed(decoded);
112
+ if (networkAccess) {
113
+ target.output.toolCallStatus(toolUseID, permissionResult.behavior === "allow" ? "completed" : "failed");
114
+ }
115
+ if (permissionResult.behavior === "allow") {
116
+ const modeUpdate = permissionResult.updatedPermissions?.find((update) => update.type === "setMode" && update.destination === "session");
117
+ if (modeUpdate?.type === "setMode")
118
+ host.modeChanged(modeUpdate.mode);
119
+ }
120
+ return permissionResult;
121
+ };
122
+ }
123
+ /**
124
+ * The v2 form of a permission request.
125
+ *
126
+ * v1 asks about a tool call, whose title the prompt shows. v2 gives the prompt
127
+ * its own `title` and `description`, which the presentation sets for a v2
128
+ * client (`AcpPermissionRequest`), and asks about a `subject`: here always the tool
129
+ * call, as the same patch that a `tool_call_update` carries.
130
+ */
131
+ export function v2PermissionRequest(request) {
132
+ if (request.title === undefined) {
133
+ throw new Error("An ACP v2 permission request needs a title");
134
+ }
135
+ return {
136
+ sessionId: request.sessionId,
137
+ title: request.title,
138
+ ...(request.description ? { description: request.description } : {}),
139
+ subject: { type: "tool_call", toolCall: v2ToolCallPatch(request.toolCall) },
140
+ options: request.options,
141
+ ...(request._meta != null ? { _meta: request._meta } : {}),
142
+ };
143
+ }
144
+ /**
145
+ * The v1 form of the answer to a permission request.
146
+ *
147
+ * v2 adds outcomes that v1 does not know, which the draft says are no
148
+ * approval. They become `cancelled`. In v2, `cancelled` also means that the
149
+ * user dismissed the prompt or the client declined it by policy. So the v2
150
+ * core reads a `cancelled` outcome as the user refusing the tool, unless a
151
+ * `session/cancel` is stopping the session's work: then the tool use is
152
+ * aborted, as on v1 (`canUseTool`).
153
+ */
154
+ export function v1PermissionResponse(response) {
155
+ const outcome = response.outcome;
156
+ return {
157
+ outcome: outcome.outcome === "selected"
158
+ ? outcome
159
+ : { outcome: "cancelled" },
160
+ ...(response._meta != null ? { _meta: response._meta } : {}),
161
+ };
162
+ }
@@ -1,49 +1,9 @@
1
1
  /**
2
- * ACP v2 `session/prompt`, served through the turn events of `ClaudeAcpAgent`.
3
- *
4
- * v2 answers the prompt once Claude Code takes it in, with the id of the user
5
- * message it became, and reports the rest of the turn as `state_update`s.
2
+ * The v1 form of a v2 `session/prompt` and of its content, which the shared
3
+ * prompt conversion (`promptToClaude`) and the system prompt take.
6
4
  */
7
5
  import { type ContentBlock, type PromptRequest } from "@agentclientprotocol/sdk/unstable";
8
6
  import * as v2 from "@agentclientprotocol/sdk/experimental/v2/unstable";
9
- import type { ClaudeAcpAgent } from "../acp-agent.js";
10
- import type { ForegroundEvents } from "../turn-events.js";
11
- /**
12
- * Starts a turn for `params`, and answers when Claude Code takes the prompt
13
- * in, with the id of the user message it became. `send` delivers a session
14
- * update of the prompt's session; it must not throw, and must deliver updates
15
- * in the order it is called, also relative to the agent's own updates.
16
- *
17
- * - Taken in: the prompt's `user_message`, then the answer. From then on, the
18
- * turn is the session's foreground work, which reports its states (see
19
- * {@link v2Foreground}).
20
- * - Ended or failed before it was taken in: the answer is a JSON-RPC error,
21
- * `-32800` for a prompt that a cancel ended in the queue.
22
- */
23
- export declare function v2Prompt(agent: ClaudeAcpAgent, params: v2.PromptRequest, send: (update: v2.SessionUpdate) => void): Promise<v2.PromptResponse>;
24
- /**
25
- * Reports the foreground work of a session (see {@link ForegroundEvents}) as
26
- * its `state_update`s. `send` delivers a session update of that session, as
27
- * for {@link v2Prompt}.
28
- *
29
- * - Started: `running`. For a prompt's turn, right after its `user_message`.
30
- * - Waiting on a permission request or a question: `requires_action`, and
31
- * `running` once none is open, unless a cancel withdrew the last one: the
32
- * work is being stopped then, and its `idle` follows.
33
- * - Ended: `idle` with the stop reason, usage, and `_meta` of the work.
34
- * - Failed: `idle` with the `error` stop reason and the JSON-RPC error that v1
35
- * answers the prompt with, so a client can show its message and handle its
36
- * code as for an error response (for example, `-32000` starts the client's
37
- * sign-in).
38
- *
39
- * The work is a prompt's turn or a model cycle that Claude Code started on its
40
- * own, such as its follow-up after a background subagent finished. A turn's
41
- * work ends at its result, also when v1 holds the turn's answer for the
42
- * background subagents it spawned (`Turn.deferredSettle`): v2 allows
43
- * background updates while idle, so the subagents' output and requests arrive
44
- * after `idle`, and their follow-up is a cycle of its own.
45
- */
46
- export declare function v2Foreground(send: (update: v2.SessionUpdate) => void): ForegroundEvents;
47
7
  /**
48
8
  * A v2 prompt may hold content blocks that the agent does not take: audio,
49
9
  * which it does not advertise and Claude cannot read, a custom one, or one
@@ -1 +1 @@
1
- {"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../../src/v2/prompt.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAGL,KAAK,YAAY,EACjB,KAAK,aAAa,EAEnB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,KAAK,EAAE,MAAM,mDAAmD,CAAC;AACxE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEtD,OAAO,KAAK,EAAE,gBAAgB,EAAuC,MAAM,mBAAmB,CAAC;AAE/F;;;;;;;;;;;GAWG;AACH,wBAAgB,QAAQ,CACtB,KAAK,EAAE,cAAc,EACrB,MAAM,EAAE,EAAE,CAAC,aAAa,EACxB,IAAI,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,aAAa,KAAK,IAAI,GACvC,OAAO,CAAC,EAAE,CAAC,cAAc,CAAC,CAiC5B;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,aAAa,KAAK,IAAI,GAAG,gBAAgB,CAoBvF;AAgCD;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,EAAE,MAAM,EAAE,GAAG,OAAO,EAAE,EAAE,EAAE,CAAC,aAAa,GAAG,aAAa,CAqBvF;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,EAAE,CAAC,YAAY,GAAG,YAAY,CAcnE"}
1
+ {"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../../src/v2/prompt.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAGL,KAAK,YAAY,EACjB,KAAK,aAAa,EAEnB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,KAAK,EAAE,MAAM,mDAAmD,CAAC;AAGxE;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,EAAE,MAAM,EAAE,GAAG,OAAO,EAAE,EAAE,EAAE,CAAC,aAAa,GAAG,aAAa,CAqBvF;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,EAAE,CAAC,YAAY,GAAG,YAAY,CAcnE"}
package/dist/v2/prompt.js CHANGED
@@ -1,127 +1,10 @@
1
1
  /**
2
- * ACP v2 `session/prompt`, served through the turn events of `ClaudeAcpAgent`.
3
- *
4
- * v2 answers the prompt once Claude Code takes it in, with the id of the user
5
- * message it became, and reports the rest of the turn as `state_update`s.
2
+ * The v1 form of a v2 `session/prompt` and of its content, which the shared
3
+ * prompt conversion (`promptToClaude`) and the system prompt take.
6
4
  */
7
5
  import { RequestError, } from "@agentclientprotocol/sdk/unstable";
8
6
  import * as v2 from "@agentclientprotocol/sdk/experimental/v2/unstable";
9
7
  import { isSupportedBlobMimeType } from "../blob-resources.js";
10
- /**
11
- * Starts a turn for `params`, and answers when Claude Code takes the prompt
12
- * in, with the id of the user message it became. `send` delivers a session
13
- * update of the prompt's session; it must not throw, and must deliver updates
14
- * in the order it is called, also relative to the agent's own updates.
15
- *
16
- * - Taken in: the prompt's `user_message`, then the answer. From then on, the
17
- * turn is the session's foreground work, which reports its states (see
18
- * {@link v2Foreground}).
19
- * - Ended or failed before it was taken in: the answer is a JSON-RPC error,
20
- * `-32800` for a prompt that a cancel ended in the queue.
21
- */
22
- export function v2Prompt(agent, params, send) {
23
- return new Promise((resolve, reject) => {
24
- let inserted = false;
25
- const events = {
26
- inserted(messageId) {
27
- inserted = true;
28
- send({ sessionUpdate: "user_message", messageId, content: params.prompt });
29
- resolve({ messageId });
30
- },
31
- ended(outcome) {
32
- if (inserted)
33
- return;
34
- reject(outcome.stopReason === "cancelled"
35
- ? RequestError.requestCancelled()
36
- : RequestError.internalError({ stopReason: outcome.stopReason }, "The turn ended before Claude Code took the prompt in"));
37
- },
38
- failed(error) {
39
- if (!inserted)
40
- reject(error);
41
- },
42
- };
43
- let request;
44
- try {
45
- request = v1PromptRequest(params);
46
- }
47
- catch (error) {
48
- reject(error);
49
- return;
50
- }
51
- agent.startTurn(request, events).catch(reject);
52
- });
53
- }
54
- /**
55
- * Reports the foreground work of a session (see {@link ForegroundEvents}) as
56
- * its `state_update`s. `send` delivers a session update of that session, as
57
- * for {@link v2Prompt}.
58
- *
59
- * - Started: `running`. For a prompt's turn, right after its `user_message`.
60
- * - Waiting on a permission request or a question: `requires_action`, and
61
- * `running` once none is open, unless a cancel withdrew the last one: the
62
- * work is being stopped then, and its `idle` follows.
63
- * - Ended: `idle` with the stop reason, usage, and `_meta` of the work.
64
- * - Failed: `idle` with the `error` stop reason and the JSON-RPC error that v1
65
- * answers the prompt with, so a client can show its message and handle its
66
- * code as for an error response (for example, `-32000` starts the client's
67
- * sign-in).
68
- *
69
- * The work is a prompt's turn or a model cycle that Claude Code started on its
70
- * own, such as its follow-up after a background subagent finished. A turn's
71
- * work ends at its result, also when v1 holds the turn's answer for the
72
- * background subagents it spawned (`Turn.deferredSettle`): v2 allows
73
- * background updates while idle, so the subagents' output and requests arrive
74
- * after `idle`, and their follow-up is a cycle of its own.
75
- */
76
- export function v2Foreground(send) {
77
- return {
78
- running() {
79
- send({ sessionUpdate: "state_update", state: "running" });
80
- },
81
- awaitingUser() {
82
- send({ sessionUpdate: "state_update", state: "requires_action" });
83
- },
84
- ended(outcome) {
85
- send(idle(outcome));
86
- },
87
- failed(error) {
88
- send({
89
- sessionUpdate: "state_update",
90
- state: "idle",
91
- stopReason: "error",
92
- error: jsonRpcError(error),
93
- });
94
- },
95
- };
96
- }
97
- /** The JSON-RPC error that v1 answers a failed prompt with. */
98
- function jsonRpcError(error) {
99
- if (error instanceof RequestError) {
100
- return {
101
- code: error.code,
102
- message: error.message,
103
- ...(error.data !== undefined ? { data: error.data } : {}),
104
- };
105
- }
106
- return {
107
- code: RequestError.internalError().code,
108
- message: error instanceof Error ? error.message : String(error),
109
- };
110
- }
111
- /**
112
- * The `idle` of a turn that ended. Every stop reason the agent reports is one
113
- * of v2's own, so the state is typed as those members of `IdleStateUpdate`:
114
- * the type checker matches each stop reason to its member, which it cannot do
115
- * against the whole union with its custom and unknown members.
116
- */
117
- function idle({ stopReason, usage, _meta }) {
118
- const state = {
119
- stopReason,
120
- ...(usage ? { usage } : {}),
121
- ...(_meta ? { _meta } : {}),
122
- };
123
- return { sessionUpdate: "state_update", state: "idle", ...state };
124
- }
125
8
  /**
126
9
  * A v2 prompt may hold content blocks that the agent does not take: audio,
127
10
  * which it does not advertise and Claude cannot read, a custom one, or one
@@ -0,0 +1,41 @@
1
+ import type { Query, SDKUserMessage } from "@anthropic-ai/claude-agent-sdk";
2
+ import type { Logger } from "../logger.js";
3
+ import { parseRemoteControlCommand } from "../remote-control.js";
4
+ /** What the command needs of its session. */
5
+ export interface RemoteControlHost {
6
+ readonly logger: Logger;
7
+ query(): Query | undefined;
8
+ /** Claude Code's terminal-bound commands, which it does not offer. */
9
+ terminalCommands(): readonly string[] | undefined;
10
+ /** Resolves `true` once no turn is open and no prompt waits in Claude Code, `false` once the session closed. */
11
+ idle(): Promise<boolean>;
12
+ /** Inserts the prompt `uuid` and opens its turn. */
13
+ begin(uuid: string): void;
14
+ /** Sends the reply `text`, as agent text of the message `messageId`, and ends the turn. */
15
+ end(text: string, messageId: string): void;
16
+ }
17
+ export declare class SessionRemoteControl {
18
+ private readonly host;
19
+ /** The uuids of the prompts that this session sent, until Claude Code echoes them. */
20
+ private readonly sent;
21
+ constructor(host: RemoteControlHost);
22
+ /** Whether `prompt` may be the adapter's command, which {@link run} then decides. */
23
+ mayRun(prompt: Parameters<typeof parseRemoteControlCommand>[0]): boolean;
24
+ /**
25
+ * Runs `prompt` as the adapter's command, as its turn, once the session is
26
+ * idle. Resolves `false` without running it when Claude Code serves the
27
+ * command itself or the query has no Remote Control: the prompt then goes
28
+ * to Claude Code. `stillPending` tells whether a cancel or close answered
29
+ * the prompt meanwhile.
30
+ */
31
+ run(prompt: Parameters<typeof parseRemoteControlCommand>[0], uuid: string, stillPending: () => boolean): Promise<boolean>;
32
+ /** The session sent the prompt `uuid` to Claude Code. */
33
+ pushed(uuid: string): void;
34
+ /**
35
+ * The content of a prompt echo to show as a user message: one that a
36
+ * person typed in another client of the session. `undefined` for the
37
+ * echo of a prompt that this session sent, and for any other echo.
38
+ */
39
+ remoteMessage(message: SDKUserMessage): SDKUserMessage["message"]["content"] | undefined;
40
+ }
41
+ //# sourceMappingURL=remote-control.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remote-control.d.ts","sourceRoot":"","sources":["../../src/v2/remote-control.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAC5E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAGL,yBAAyB,EAE1B,MAAM,sBAAsB,CAAC;AAE9B,6CAA6C;AAC7C,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,KAAK,IAAI,KAAK,GAAG,SAAS,CAAC;IAC3B,sEAAsE;IACtE,gBAAgB,IAAI,SAAS,MAAM,EAAE,GAAG,SAAS,CAAC;IAClD,gHAAgH;IAChH,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IACzB,oDAAoD;IACpD,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,2FAA2F;IAC3F,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5C;AAED,qBAAa,oBAAoB;IAInB,OAAO,CAAC,QAAQ,CAAC,IAAI;IAHjC,sFAAsF;IACtF,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAqB;gBAEb,IAAI,EAAE,iBAAiB;IAEpD,qFAAqF;IACrF,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,yBAAyB,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO;IAIxE;;;;;;OAMG;IACG,GAAG,CACP,MAAM,EAAE,UAAU,CAAC,OAAO,yBAAyB,CAAC,CAAC,CAAC,CAAC,EACvD,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,MAAM,OAAO,GAC1B,OAAO,CAAC,OAAO,CAAC;IAenB,yDAAyD;IACzD,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAI1B;;;;OAIG;IACH,aAAa,CAAC,OAAO,EAAE,cAAc,GAAG,cAAc,CAAC,SAAS,CAAC,CAAC,SAAS,CAAC,GAAG,SAAS;CAIzF"}