@agentclientprotocol/claude-agent-acp 0.102.0 → 0.102.1-preview.2

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 (206) hide show
  1. package/README.md +5 -1
  2. package/dist/acp-agent.d.ts +119 -439
  3. package/dist/acp-agent.d.ts.map +1 -1
  4. package/dist/acp-agent.js +380 -2412
  5. package/dist/acp-subagents.d.ts +1 -2
  6. package/dist/acp-subagents.d.ts.map +1 -1
  7. package/dist/auth-methods.d.ts +21 -0
  8. package/dist/auth-methods.d.ts.map +1 -0
  9. package/dist/auth-methods.js +68 -0
  10. package/dist/auth-status-reporter.d.ts +112 -0
  11. package/dist/auth-status-reporter.d.ts.map +1 -0
  12. package/dist/auth-status-reporter.js +253 -0
  13. package/dist/background-work.d.ts +12 -265
  14. package/dist/background-work.d.ts.map +1 -1
  15. package/dist/background-work.js +8 -558
  16. package/dist/client-system-prompt.d.ts +7 -0
  17. package/dist/client-system-prompt.d.ts.map +1 -1
  18. package/dist/client-system-prompt.js +24 -0
  19. package/dist/context-compaction.d.ts +20 -0
  20. package/dist/context-compaction.d.ts.map +1 -1
  21. package/dist/context-compaction.js +26 -0
  22. package/dist/context-window.d.ts +70 -0
  23. package/dist/context-window.d.ts.map +1 -0
  24. package/dist/context-window.js +132 -0
  25. package/dist/diff.d.ts +1 -1
  26. package/dist/diff.js +1 -1
  27. package/dist/elicitation.d.ts +66 -1
  28. package/dist/elicitation.d.ts.map +1 -1
  29. package/dist/elicitation.js +109 -0
  30. package/dist/file-change-audit.d.ts +4 -3
  31. package/dist/file-change-audit.d.ts.map +1 -1
  32. package/dist/file-change-audit.js +3 -2
  33. package/dist/mcp-oauth.d.ts +44 -0
  34. package/dist/mcp-oauth.d.ts.map +1 -0
  35. package/dist/mcp-oauth.js +142 -0
  36. package/dist/mcp-servers.d.ts +10 -0
  37. package/dist/mcp-servers.d.ts.map +1 -0
  38. package/dist/mcp-servers.js +29 -0
  39. package/dist/native-subagents.d.ts +18 -8
  40. package/dist/native-subagents.d.ts.map +1 -1
  41. package/dist/native-subagents.js +7 -35
  42. package/dist/permissions/presentation.d.ts +29 -0
  43. package/dist/permissions/presentation.d.ts.map +1 -1
  44. package/dist/permissions/presentation.js +38 -11
  45. package/dist/plans.d.ts +36 -6
  46. package/dist/plans.d.ts.map +1 -1
  47. package/dist/plans.js +49 -11
  48. package/dist/prompt-suggestions.d.ts +29 -0
  49. package/dist/prompt-suggestions.d.ts.map +1 -1
  50. package/dist/prompt-suggestions.js +45 -0
  51. package/dist/providers.d.ts +139 -0
  52. package/dist/providers.d.ts.map +1 -0
  53. package/dist/providers.js +286 -0
  54. package/dist/remote-control.d.ts +62 -0
  55. package/dist/remote-control.d.ts.map +1 -0
  56. package/dist/remote-control.js +78 -0
  57. package/dist/result-end.d.ts +39 -0
  58. package/dist/result-end.d.ts.map +1 -0
  59. package/dist/result-end.js +50 -0
  60. package/dist/serve.d.ts +7 -2
  61. package/dist/serve.d.ts.map +1 -1
  62. package/dist/serve.js +10 -5
  63. package/dist/session-config-ids.d.ts +1 -0
  64. package/dist/session-config-ids.d.ts.map +1 -1
  65. package/dist/session-config-ids.js +1 -0
  66. package/dist/session-config-options.d.ts +64 -0
  67. package/dist/session-config-options.d.ts.map +1 -0
  68. package/dist/session-config-options.js +162 -0
  69. package/dist/session-effort.d.ts +67 -0
  70. package/dist/session-effort.d.ts.map +1 -1
  71. package/dist/session-effort.js +98 -0
  72. package/dist/session-env.d.ts +22 -0
  73. package/dist/session-env.d.ts.map +1 -0
  74. package/dist/session-env.js +66 -0
  75. package/dist/session-fast-mode.d.ts +83 -0
  76. package/dist/session-fast-mode.d.ts.map +1 -0
  77. package/dist/session-fast-mode.js +142 -0
  78. package/dist/session-index/connection.d.ts +2 -5
  79. package/dist/session-index/connection.d.ts.map +1 -1
  80. package/dist/session-index/connection.js +3 -5
  81. package/dist/session-mode.d.ts +1 -0
  82. package/dist/session-mode.d.ts.map +1 -1
  83. package/dist/session-mode.js +1 -1
  84. package/dist/session-model.d.ts +41 -0
  85. package/dist/session-model.d.ts.map +1 -1
  86. package/dist/session-model.js +110 -45
  87. package/dist/session-notices.d.ts +44 -0
  88. package/dist/session-notices.d.ts.map +1 -1
  89. package/dist/session-notices.js +68 -0
  90. package/dist/session-titles.d.ts +34 -12
  91. package/dist/session-titles.d.ts.map +1 -1
  92. package/dist/session-titles.js +7 -6
  93. package/dist/session-usage.d.ts +125 -0
  94. package/dist/session-usage.d.ts.map +1 -0
  95. package/dist/session-usage.js +196 -0
  96. package/dist/streamed-text.d.ts +33 -0
  97. package/dist/streamed-text.d.ts.map +1 -0
  98. package/dist/streamed-text.js +71 -0
  99. package/dist/subagent-configuration.d.ts +32 -0
  100. package/dist/subagent-configuration.d.ts.map +1 -0
  101. package/dist/subagent-configuration.js +70 -0
  102. package/dist/subagent-replay.d.ts +18 -0
  103. package/dist/subagent-replay.d.ts.map +1 -1
  104. package/dist/subagent-replay.js +25 -15
  105. package/dist/tool-calls/client-capabilities.d.ts +8 -8
  106. package/dist/tool-calls/client-capabilities.js +4 -4
  107. package/dist/tool-calls/renderer.d.ts +4 -5
  108. package/dist/tool-calls/renderer.d.ts.map +1 -1
  109. package/dist/tool-calls/renderer.js +4 -5
  110. package/dist/turn-events.d.ts +6 -46
  111. package/dist/turn-events.d.ts.map +1 -1
  112. package/dist/v2/agent.d.ts +7 -11
  113. package/dist/v2/agent.d.ts.map +1 -1
  114. package/dist/v2/agent.js +751 -331
  115. package/dist/v2/air.d.ts +33 -0
  116. package/dist/v2/air.d.ts.map +1 -0
  117. package/dist/v2/air.js +29 -0
  118. package/dist/v2/auth.d.ts +97 -0
  119. package/dist/v2/auth.d.ts.map +1 -0
  120. package/dist/v2/auth.js +216 -0
  121. package/dist/v2/background.d.ts +27 -16
  122. package/dist/v2/background.d.ts.map +1 -1
  123. package/dist/v2/background.js +4 -32
  124. package/dist/v2/child-config.d.ts +55 -0
  125. package/dist/v2/child-config.d.ts.map +1 -0
  126. package/dist/v2/child-config.js +92 -0
  127. package/dist/v2/clear-context.d.ts +94 -0
  128. package/dist/v2/clear-context.d.ts.map +1 -0
  129. package/dist/v2/clear-context.js +176 -0
  130. package/dist/v2/commands.d.ts +46 -0
  131. package/dist/v2/commands.d.ts.map +1 -0
  132. package/dist/v2/commands.js +54 -0
  133. package/dist/v2/config.d.ts +187 -0
  134. package/dist/v2/config.d.ts.map +1 -0
  135. package/dist/v2/config.js +494 -0
  136. package/dist/v2/elicitation.d.ts +93 -0
  137. package/dist/v2/elicitation.d.ts.map +1 -0
  138. package/dist/v2/elicitation.js +160 -0
  139. package/dist/v2/file-changes.d.ts +61 -0
  140. package/dist/v2/file-changes.d.ts.map +1 -0
  141. package/dist/v2/file-changes.js +108 -0
  142. package/dist/v2/file-preview.d.ts +18 -0
  143. package/dist/v2/file-preview.d.ts.map +1 -0
  144. package/dist/v2/file-preview.js +29 -0
  145. package/dist/v2/initialize.d.ts +10 -24
  146. package/dist/v2/initialize.d.ts.map +1 -1
  147. package/dist/v2/initialize.js +4 -111
  148. package/dist/v2/outcome.d.ts +81 -0
  149. package/dist/v2/outcome.d.ts.map +1 -0
  150. package/dist/v2/outcome.js +165 -0
  151. package/dist/v2/permissions.d.ts +92 -0
  152. package/dist/v2/permissions.d.ts.map +1 -0
  153. package/dist/v2/permissions.js +162 -0
  154. package/dist/v2/prompt.d.ts +2 -42
  155. package/dist/v2/prompt.d.ts.map +1 -1
  156. package/dist/v2/prompt.js +2 -119
  157. package/dist/v2/remote-control.d.ts +41 -0
  158. package/dist/v2/remote-control.d.ts.map +1 -0
  159. package/dist/v2/remote-control.js +63 -0
  160. package/dist/v2/reports.d.ts +198 -0
  161. package/dist/v2/reports.d.ts.map +1 -0
  162. package/dist/v2/reports.js +487 -0
  163. package/dist/v2/restarts.d.ts +128 -0
  164. package/dist/v2/restarts.d.ts.map +1 -0
  165. package/dist/v2/restarts.js +348 -0
  166. package/dist/v2/session-requests.d.ts +20 -0
  167. package/dist/v2/session-requests.d.ts.map +1 -0
  168. package/dist/v2/session-requests.js +108 -0
  169. package/dist/v2/session-update.d.ts +2 -13
  170. package/dist/v2/session-update.d.ts.map +1 -1
  171. package/dist/v2/session-update.js +2 -22
  172. package/dist/v2/session.d.ts +340 -41
  173. package/dist/v2/session.d.ts.map +1 -1
  174. package/dist/v2/session.js +1223 -141
  175. package/dist/v2/setup.d.ts +49 -0
  176. package/dist/v2/setup.d.ts.map +1 -0
  177. package/dist/v2/setup.js +62 -0
  178. package/dist/v2/stopped-work.d.ts +123 -0
  179. package/dist/v2/stopped-work.d.ts.map +1 -0
  180. package/dist/v2/stopped-work.js +210 -0
  181. package/dist/v2/stream.d.ts +228 -0
  182. package/dist/v2/stream.d.ts.map +1 -0
  183. package/dist/v2/stream.js +506 -0
  184. package/dist/v2/subagent-replay.d.ts +115 -0
  185. package/dist/v2/subagent-replay.d.ts.map +1 -0
  186. package/dist/v2/subagent-replay.js +479 -0
  187. package/dist/v2/subscription-guard.d.ts +60 -0
  188. package/dist/v2/subscription-guard.d.ts.map +1 -0
  189. package/dist/v2/subscription-guard.js +84 -0
  190. package/dist/v2/tasks.d.ts +492 -0
  191. package/dist/v2/tasks.d.ts.map +1 -0
  192. package/dist/v2/tasks.js +1728 -0
  193. package/dist/v2/terminal.d.ts.map +1 -1
  194. package/dist/v2/terminal.js +6 -1
  195. package/dist/v2/tool-call.d.ts +3 -2
  196. package/dist/v2/tool-call.d.ts.map +1 -1
  197. package/dist/v2/update-translator.d.ts +36 -0
  198. package/dist/v2/update-translator.d.ts.map +1 -0
  199. package/dist/v2/update-translator.js +80 -0
  200. package/dist/workflow-progress.d.ts +23 -0
  201. package/dist/workflow-progress.d.ts.map +1 -1
  202. package/dist/workflow-progress.js +31 -8
  203. package/package.json +1 -1
  204. package/dist/v2/permission.d.ts +0 -28
  205. package/dist/v2/permission.d.ts.map +0 -1
  206. package/dist/v2/permission.js +0 -41
@@ -0,0 +1,39 @@
1
+ /**
2
+ * How Claude Code's `result` ends the work that it reports: the rules that
3
+ * both cores read a turn's result with (the v1 prompt loop in `acp-agent.ts`
4
+ * and `v2/outcome.ts`). Each core adds its own side effects, such as v1's
5
+ * session failure category.
6
+ */
7
+ import type { SDKResultMessage } from "@anthropic-ai/claude-agent-sdk";
8
+ export type ResultEnd = {
9
+ stopReason: "refusal" | "max_tokens" | "end_turn" | "max_turn_requests";
10
+ }
11
+ /**
12
+ * The result failed the work, with Claude Code's error text. `loginRequired`:
13
+ * the text of a `success` result tells the user to run `/login`.
14
+ */
15
+ | {
16
+ error: string;
17
+ loginRequired: boolean;
18
+ };
19
+ /**
20
+ * True when CLI error text tells the user to sign in with `/login`. The CLI
21
+ * words this several ways — "Not logged in · Please run /login", "Not logged
22
+ * in · Run /login", "Login expired · Run /login to sign in again, or
23
+ * re-authenticate your Anthropic profile" — so match the "run /login"
24
+ * instruction rather than one sentence.
25
+ */
26
+ export declare function isLoginRequiredText(text: string): boolean;
27
+ /**
28
+ * - Any subtype with `stop_reason: "refusal"`: `refusal`, also on an error.
29
+ * - `success`: an error with the `/login` text fails the work, then
30
+ * `stop_reason: "max_tokens"` is `max_tokens`, then any other error fails
31
+ * the work. Otherwise `end_turn`.
32
+ * - `error_during_execution`: `max_tokens` as for `success`, then an error
33
+ * fails the work. Otherwise `end_turn`.
34
+ * - `error_max_turns`, `error_max_budget_usd` and
35
+ * `error_max_structured_output_retries`: an error fails the work, whatever
36
+ * the stop reason. Otherwise `max_turn_requests`.
37
+ */
38
+ export declare function resultEnd(result: SDKResultMessage): ResultEnd;
39
+ //# sourceMappingURL=result-end.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"result-end.d.ts","sourceRoot":"","sources":["../src/result-end.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAEvE,MAAM,MAAM,SAAS,GACjB;IAAE,UAAU,EAAE,SAAS,GAAG,YAAY,GAAG,UAAU,GAAG,mBAAmB,CAAA;CAAE;AAC7E;;;GAGG;GACD;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,OAAO,CAAA;CAAE,CAAC;AAE9C;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEzD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,gBAAgB,GAAG,SAAS,CAmB7D"}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * True when CLI error text tells the user to sign in with `/login`. The CLI
3
+ * words this several ways — "Not logged in · Please run /login", "Not logged
4
+ * in · Run /login", "Login expired · Run /login to sign in again, or
5
+ * re-authenticate your Anthropic profile" — so match the "run /login"
6
+ * instruction rather than one sentence.
7
+ */
8
+ export function isLoginRequiredText(text) {
9
+ return /\brun \/login\b/i.test(text);
10
+ }
11
+ /**
12
+ * - Any subtype with `stop_reason: "refusal"`: `refusal`, also on an error.
13
+ * - `success`: an error with the `/login` text fails the work, then
14
+ * `stop_reason: "max_tokens"` is `max_tokens`, then any other error fails
15
+ * the work. Otherwise `end_turn`.
16
+ * - `error_during_execution`: `max_tokens` as for `success`, then an error
17
+ * fails the work. Otherwise `end_turn`.
18
+ * - `error_max_turns`, `error_max_budget_usd` and
19
+ * `error_max_structured_output_retries`: an error fails the work, whatever
20
+ * the stop reason. Otherwise `max_turn_requests`.
21
+ */
22
+ export function resultEnd(result) {
23
+ if (result.stop_reason === "refusal")
24
+ return { stopReason: "refusal" };
25
+ switch (result.subtype) {
26
+ case "success":
27
+ if (result.is_error && isLoginRequiredText(result.result)) {
28
+ return { error: result.result, loginRequired: true };
29
+ }
30
+ if (result.stop_reason === "max_tokens")
31
+ return { stopReason: "max_tokens" };
32
+ if (result.is_error)
33
+ return { error: result.result, loginRequired: false };
34
+ return { stopReason: "end_turn" };
35
+ case "error_during_execution":
36
+ if (result.stop_reason === "max_tokens")
37
+ return { stopReason: "max_tokens" };
38
+ if (result.is_error)
39
+ return failed(result);
40
+ return { stopReason: "end_turn" };
41
+ default:
42
+ // `error_max_turns`, `error_max_budget_usd`, `error_max_structured_output_retries`.
43
+ if (result.is_error)
44
+ return failed(result);
45
+ return { stopReason: "max_turn_requests" };
46
+ }
47
+ }
48
+ function failed(result) {
49
+ return { error: result.errors.join(", ") || result.subtype, loginRequired: false };
50
+ }
package/dist/serve.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import * as v2 from "@agentclientprotocol/sdk/experimental/v2";
2
2
  import { type ClaudeAcpAgent, type Logger } from "./acp-agent.js";
3
+ import { type AgentHandle } from "./v2/agent.js";
3
4
  /**
4
5
  * The ACP versions that the adapter serves: `v1` or `v2` alone, or both with
5
6
  * `auto`, where the client's `initialize` picks the version.
@@ -25,7 +26,11 @@ export declare function serveAcp(logger: Logger | undefined, options: {
25
26
  * the draft ACP v2, and every other client gets ACP v1. With `v1`, a v2
26
27
  * client is negotiated down to v1. With `v2`, the router rejects the
27
28
  * `initialize` of a v1 client as an unsupported protocol version. `onAgent`
28
- * receives the agent of the connection once the router has opened it.
29
+ * receives the agent of a v1 connection (`ClaudeAcpAgent`) once the router
30
+ * has opened it, and `onV2Agent` the agent of a v2 connection, which the
31
+ * v2 core (`src/v2/`) serves.
29
32
  */
30
- export declare function acpProtocolRouter(logger: Logger | undefined, onAgent: (agent: ClaudeAcpAgent) => void, protocols?: AcpProtocols): v2.AgentProtocolRouter;
33
+ export declare function acpProtocolRouter(logger: Logger | undefined, onAgent: (agent: ClaudeAcpAgent) => void, protocols?: AcpProtocols, { onV2Agent }?: {
34
+ onV2Agent?: (agent: AgentHandle) => void;
35
+ }): v2.AgentProtocolRouter;
31
36
  //# sourceMappingURL=serve.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"serve.d.ts","sourceRoot":"","sources":["../src/serve.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,0CAA0C,CAAC;AAC/D,OAAO,EAAc,KAAK,cAAc,EAAE,KAA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IAAI,CAAC,CAAC;IAAC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CAAE,CAkBrD;AAED;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,OAAO,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,IAAI,EACxC,SAAS,GAAE,YAAqB,EAChC,EAAE,SAAoB,EAAE,GAAE;IAAE,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,CAAA;CAAO,GAC1E,EAAE,CAAC,mBAAmB,CAOxB"}
package/dist/serve.js CHANGED
@@ -25,7 +25,9 @@ export function serveAcp(logger, options) {
25
25
  const onAgent = (created) => {
26
26
  agent = created;
27
27
  };
28
- const { closed } = acpProtocolRouter(logger, onAgent, options.protocols).connect(v2.ndJsonStream(output, input));
28
+ const { closed } = acpProtocolRouter(logger, onAgent, options.protocols, {
29
+ onV2Agent: onAgent,
30
+ }).connect(v2.ndJsonStream(output, input));
29
31
  return {
30
32
  closed,
31
33
  dispose: async () => {
@@ -39,13 +41,16 @@ export function serveAcp(logger, options) {
39
41
  * the draft ACP v2, and every other client gets ACP v1. With `v1`, a v2
40
42
  * client is negotiated down to v1. With `v2`, the router rejects the
41
43
  * `initialize` of a v1 client as an unsupported protocol version. `onAgent`
42
- * receives the agent of the connection once the router has opened it.
44
+ * receives the agent of a v1 connection (`ClaudeAcpAgent`) once the router
45
+ * has opened it, and `onV2Agent` the agent of a v2 connection, which the
46
+ * v2 core (`src/v2/`) serves.
43
47
  */
44
- export function acpProtocolRouter(logger, onAgent, protocols = "auto") {
48
+ export function acpProtocolRouter(logger, onAgent, protocols = "auto", { onV2Agent = () => { } } = {}) {
45
49
  const router = v2.agentProtocolRouter();
46
50
  if (protocols !== "v2")
47
51
  router.withV1(v1AgentApp(logger, onAgent));
48
- if (protocols !== "v1")
49
- router.withV2(v2AgentApp(logger, onAgent));
52
+ if (protocols !== "v1") {
53
+ router.withV2(v2AgentApp(logger, onV2Agent));
54
+ }
50
55
  return router;
51
56
  }
@@ -1,6 +1,7 @@
1
1
  /** Shared sentinels and ids for session preferences managed by the adapter. */
2
2
  export declare const DEFAULT_MODEL_ID = "default";
3
3
  export declare const DEFAULT_AGENT_ID = "default";
4
+ export declare const AGENT_CONFIG_ID = "agent";
4
5
  export declare const EFFORT_CONFIG_ID = "effort";
5
6
  export declare const ULTRACODE_CONFIG_ID = "ultracode";
6
7
  //# sourceMappingURL=session-config-ids.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"session-config-ids.d.ts","sourceRoot":"","sources":["../src/session-config-ids.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,eAAO,MAAM,gBAAgB,YAAY,CAAC;AAC1C,eAAO,MAAM,gBAAgB,YAAY,CAAC;AAC1C,eAAO,MAAM,gBAAgB,WAAW,CAAC;AACzC,eAAO,MAAM,mBAAmB,cAAc,CAAC"}
1
+ {"version":3,"file":"session-config-ids.d.ts","sourceRoot":"","sources":["../src/session-config-ids.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,eAAO,MAAM,gBAAgB,YAAY,CAAC;AAC1C,eAAO,MAAM,gBAAgB,YAAY,CAAC;AAC1C,eAAO,MAAM,eAAe,UAAU,CAAC;AACvC,eAAO,MAAM,gBAAgB,WAAW,CAAC;AACzC,eAAO,MAAM,mBAAmB,cAAc,CAAC"}
@@ -1,5 +1,6 @@
1
1
  /** Shared sentinels and ids for session preferences managed by the adapter. */
2
2
  export const DEFAULT_MODEL_ID = "default";
3
3
  export const DEFAULT_AGENT_ID = "default";
4
+ export const AGENT_CONFIG_ID = "agent";
4
5
  export const EFFORT_CONFIG_ID = "effort";
5
6
  export const ULTRACODE_CONFIG_ID = "ultracode";
@@ -0,0 +1,64 @@
1
+ /**
2
+ * The config options of a session, as both the v1 core and the v2 core
3
+ * build them: mode, model, effort, Fast mode, ultracode and the main-thread
4
+ * agent.
5
+ */
6
+ import { type ClientCapabilities, type SessionConfigOption, type SessionModeState, type SetSessionConfigOptionRequest } from "@agentclientprotocol/sdk/unstable";
7
+ import type { AgentInfo, ModelInfo, Query } from "@anthropic-ai/claude-agent-sdk";
8
+ import { AGENT_CONFIG_ID } from "./session-config-ids.js";
9
+ import { type FastModeOptionState } from "./session-fast-mode.js";
10
+ import { MODE_CONFIG_ID } from "./session-mode.js";
11
+ import { type SessionModelState } from "./session-model.js";
12
+ import { type UltracodeOptionState } from "./session-ultracode.js";
13
+ export declare const BUILTIN_AGENT_NAMES: Set<string>;
14
+ /** Discover user/plugin/project-configured main-thread agents, excluding the
15
+ * built-in subagents and the reserved "default" sentinel. Returns an empty
16
+ * list if discovery fails so a flaky control request never blocks session
17
+ * creation. */
18
+ export declare function discoverCustomAgents(q: Query): Promise<AgentInfo[]>;
19
+ /** The configured agents of `agents`: neither a built-in subagent nor the "default" sentinel. */
20
+ export declare function customAgents(agents: readonly AgentInfo[]): AgentInfo[];
21
+ /** Stable ids for the session config options surfaced via `configOptions`.
22
+ * Centralized so the option declarations in `buildConfigOptions` and the
23
+ * handlers in `setSessionConfigOption`/`applyConfigOptionValue` reference the
24
+ * same identifiers and can't drift apart. */
25
+ export { MODE_CONFIG_ID };
26
+ export { AGENT_CONFIG_ID };
27
+ /** Whether the Client advertised support for boolean session config options
28
+ * (`session.configOptions.boolean`). Agents MUST only send `type: "boolean"`
29
+ * config options to Clients that opt in; otherwise we fall back to a `select`.
30
+ * See https://agentclientprotocol.com/rfds/boolean-config-option. */
31
+ export declare function clientSupportsBooleanConfigOptions(clientCapabilities?: ClientCapabilities | null): boolean;
32
+ /** Whether the Client advertised the AIR `recommendedValue` capability for
33
+ * select-style model and effort options. Missing or malformed AIR metadata
34
+ * retains the legacy `default` entries. */
35
+ export declare function clientSupportsRecommendedConfigValue(clientCapabilities?: ClientCapabilities | null): boolean;
36
+ export type ConfigOptionPresentation = {
37
+ /** Replace ambiguous `default` rows with concrete values and advertise the
38
+ * SDK/adapter recommendation as `_meta.jetbrains.air.recommendedValue`. */
39
+ useRecommendedValue: boolean;
40
+ };
41
+ export declare function buildConfigOptions(modes: SessionModeState, models: SessionModelState, modelInfos: ModelInfo[], currentEffortLevel?: string, agents?: AgentInfo[], currentAgent?: string, fastMode?: FastModeOptionState, presentation?: ConfigOptionPresentation, ultracode?: UltracodeOptionState): SessionConfigOption[];
42
+ /**
43
+ * The value that a `session/set_config_option` request sets on `option`, the
44
+ * option as the session advertised it. The value must match the option's
45
+ * type: a `type: "boolean"` option takes `true`/`false`, not "on"/"off", and a
46
+ * `type: "select"` option takes one of its values.
47
+ *
48
+ * Fast mode and ultracode give `enabled`: a boolean, or the "on"/"off" select
49
+ * fallback for clients without boolean config options. A model takes an alias
50
+ * too, such as "opus" or "sonnet" for a full model id. It is resolved against
51
+ * `modelInfos` first: those entries carry `resolvedModel`, so a full model id
52
+ * (in either hint spelling) lands on the right row via the exact tier instead
53
+ * of a fuzzier one picking a same-family sibling from a different context
54
+ * lane. The option's own entries (which never carry `resolvedModel`) remain as
55
+ * a fallback for resolutions that don't map back onto a selectable option
56
+ * (e.g. a fuzzy hit on an out-of-picker verbatim entry). `value` is then the
57
+ * canonical option value, the model id rather than the alias.
58
+ */
59
+ export declare function configOptionValue(option: SessionConfigOption, params: SetSessionConfigOptionRequest, modelInfos: ModelInfo[]): {
60
+ enabled: boolean;
61
+ } | {
62
+ value: string;
63
+ };
64
+ //# sourceMappingURL=session-config-options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-config-options.d.ts","sourceRoot":"","sources":["../src/session-config-options.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAEL,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EACrB,KAAK,6BAA6B,EACnC,MAAM,mCAAmC,CAAC;AAC3C,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,gCAAgC,CAAC;AAKlF,OAAO,EAAE,eAAe,EAA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;;;;;;GAgBG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,mBAAmB,EAC3B,MAAM,EAAE,6BAA6B,EACrC,UAAU,EAAE,SAAS,EAAE,GACtB;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,GAAG;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CA4C1C"}
@@ -0,0 +1,162 @@
1
+ /**
2
+ * The config options of a session, as both the v1 core and the v2 core
3
+ * build them: mode, model, effort, Fast mode, ultracode and the main-thread
4
+ * agent.
5
+ */
6
+ import { RequestError, } from "@agentclientprotocol/sdk/unstable";
7
+ import { AIR_RECOMMENDED_CONFIG_VALUE_CAPABILITY, clientSupportsAirCapability, } from "./air-extension.js";
8
+ import { AGENT_CONFIG_ID, DEFAULT_AGENT_ID } from "./session-config-ids.js";
9
+ import { buildEffortConfigOption } from "./session-effort.js";
10
+ import { createFastModeConfigOption, FAST_MODE_CONFIG_ID, resolveFastModeEnabled, } from "./session-fast-mode.js";
11
+ import { MODE_CONFIG_ID, SessionModeManager } from "./session-mode.js";
12
+ import { buildModelConfigOption, MODEL_CONFIG_ID, resolveModelPreference, } from "./session-model.js";
13
+ import { createUltracodeConfigOption, resolveUltracodeEnabled, ULTRACODE_CONFIG_ID, } from "./session-ultracode.js";
14
+ // `supportedAgents()` always returns Claude Code's built-in subagents — the
15
+ // ones used for Task-tool delegation (Explore, Plan, etc.) — even when the user
16
+ // has configured none of their own. Those aren't meaningful *main-thread*
17
+ // personas, so we filter them out and only surface the Agent picker when the
18
+ // user (or a plugin/project) has configured custom agents. Update this set if
19
+ // the SDK's built-in roster changes.
20
+ export const BUILTIN_AGENT_NAMES = new Set([
21
+ "claude",
22
+ "general-purpose",
23
+ "Explore",
24
+ "Plan",
25
+ "statusline-setup",
26
+ ]);
27
+ // Value of the synthetic "Default" entry in the agent picker, which maps to the
28
+ // standard Claude Code agent (`applyFlagSettings({ agent: null })`). It is a
29
+ // reserved sentinel: a custom agent named exactly this would collide with it
30
+ // (two options sharing the value, selection silently routing to `null`), so we
31
+ // exclude that name from discovery.
32
+ /** Discover user/plugin/project-configured main-thread agents, excluding the
33
+ * built-in subagents and the reserved "default" sentinel. Returns an empty
34
+ * list if discovery fails so a flaky control request never blocks session
35
+ * creation. */
36
+ export async function discoverCustomAgents(q) {
37
+ try {
38
+ return customAgents(await q.supportedAgents());
39
+ }
40
+ catch {
41
+ return [];
42
+ }
43
+ }
44
+ /** The configured agents of `agents`: neither a built-in subagent nor the "default" sentinel. */
45
+ export function customAgents(agents) {
46
+ return agents.filter((a) => !BUILTIN_AGENT_NAMES.has(a.name) && a.name !== DEFAULT_AGENT_ID);
47
+ }
48
+ /** Stable ids for the session config options surfaced via `configOptions`.
49
+ * Centralized so the option declarations in `buildConfigOptions` and the
50
+ * handlers in `setSessionConfigOption`/`applyConfigOptionValue` reference the
51
+ * same identifiers and can't drift apart. */
52
+ export { MODE_CONFIG_ID };
53
+ export { AGENT_CONFIG_ID };
54
+ /** Whether the Client advertised support for boolean session config options
55
+ * (`session.configOptions.boolean`). Agents MUST only send `type: "boolean"`
56
+ * config options to Clients that opt in; otherwise we fall back to a `select`.
57
+ * See https://agentclientprotocol.com/rfds/boolean-config-option. */
58
+ export function clientSupportsBooleanConfigOptions(clientCapabilities) {
59
+ return clientCapabilities?.session?.configOptions?.boolean != null;
60
+ }
61
+ /** Whether the Client advertised the AIR `recommendedValue` capability for
62
+ * select-style model and effort options. Missing or malformed AIR metadata
63
+ * retains the legacy `default` entries. */
64
+ export function clientSupportsRecommendedConfigValue(clientCapabilities) {
65
+ return clientSupportsAirCapability(clientCapabilities, AIR_RECOMMENDED_CONFIG_VALUE_CAPABILITY);
66
+ }
67
+ export function buildConfigOptions(modes, models, modelInfos, currentEffortLevel, agents = [], currentAgent = DEFAULT_AGENT_ID, fastMode, presentation, ultracode) {
68
+ const options = [SessionModeManager.configOption(modes)];
69
+ // A gateway that lists none of the SDK's models leaves no model to offer, so
70
+ // there is no model option at all.
71
+ if (models.availableModels.length > 0) {
72
+ options.push(buildModelConfigOption(models, modelInfos, presentation?.useRecommendedValue === true));
73
+ }
74
+ const effort = buildEffortConfigOption(modelInfos, models.currentModelId, currentEffortLevel, presentation?.useRecommendedValue === true);
75
+ if (effort)
76
+ options.push(effort);
77
+ // Surface the Fast mode toggle only when the current model supports it. The
78
+ // option renders as a native boolean toggle for Clients that opted in, and a
79
+ // two-value select otherwise.
80
+ if (fastMode?.supported) {
81
+ options.push(createFastModeConfigOption(fastMode.enabled, fastMode.useBooleanOption, fastMode.disabledReason));
82
+ }
83
+ // Surface the ultracode toggle only while the CLI can run it: dynamic
84
+ // workflows are enabled and the current model supports it.
85
+ if (ultracode?.supported) {
86
+ options.push(createUltracodeConfigOption(ultracode.enabled, ultracode.useBooleanOption));
87
+ }
88
+ // Only surface the Agent picker when there's a real choice — i.e. the user
89
+ // has configured at least one custom agent (built-ins are filtered out in
90
+ // discoverCustomAgents). With none configured, "Default" would be the only
91
+ // entry, so we omit the option entirely.
92
+ if (agents.length > 0) {
93
+ options.push({
94
+ id: AGENT_CONFIG_ID,
95
+ name: "Agent",
96
+ description: "Main-thread agent persona",
97
+ type: "select",
98
+ currentValue: currentAgent,
99
+ options: [
100
+ { value: DEFAULT_AGENT_ID, name: "Default", description: "Standard Claude Code agent" },
101
+ ...agents.map((a) => ({
102
+ value: a.name,
103
+ name: a.name,
104
+ description: a.description || undefined,
105
+ })),
106
+ ],
107
+ });
108
+ }
109
+ return options;
110
+ }
111
+ /**
112
+ * The value that a `session/set_config_option` request sets on `option`, the
113
+ * option as the session advertised it. The value must match the option's
114
+ * type: a `type: "boolean"` option takes `true`/`false`, not "on"/"off", and a
115
+ * `type: "select"` option takes one of its values.
116
+ *
117
+ * Fast mode and ultracode give `enabled`: a boolean, or the "on"/"off" select
118
+ * fallback for clients without boolean config options. A model takes an alias
119
+ * too, such as "opus" or "sonnet" for a full model id. It is resolved against
120
+ * `modelInfos` first: those entries carry `resolvedModel`, so a full model id
121
+ * (in either hint spelling) lands on the right row via the exact tier instead
122
+ * of a fuzzier one picking a same-family sibling from a different context
123
+ * lane. The option's own entries (which never carry `resolvedModel`) remain as
124
+ * a fallback for resolutions that don't map back onto a selectable option
125
+ * (e.g. a fuzzy hit on an out-of-picker verbatim entry). `value` is then the
126
+ * canonical option value, the model id rather than the alias.
127
+ */
128
+ export function configOptionValue(option, params, modelInfos) {
129
+ const expectedType = option.type === "boolean" ? "boolean" : "string";
130
+ if (typeof params.value !== expectedType) {
131
+ throw RequestError.invalidParams({ configId: params.configId, value: params.value }, `Config option ${params.configId} takes a ${expectedType} value, but received: ${JSON.stringify(params.value)}`);
132
+ }
133
+ if (params.configId === FAST_MODE_CONFIG_ID)
134
+ return { enabled: resolveFastModeEnabled(params) };
135
+ if (params.configId === ULTRACODE_CONFIG_ID) {
136
+ return { enabled: resolveUltracodeEnabled(params) };
137
+ }
138
+ if (typeof params.value !== "string") {
139
+ throw RequestError.invalidParams(undefined, `Invalid value for config option ${params.configId}: ${params.value}`);
140
+ }
141
+ const requested = params.value;
142
+ const allValues = "options" in option && Array.isArray(option.options)
143
+ ? option.options.flatMap((o) => ("options" in o ? o.options : [o]))
144
+ : [];
145
+ let validValue = allValues.find((o) => o.value === requested);
146
+ if (!validValue && params.configId === MODEL_CONFIG_ID) {
147
+ const toOptionValue = (resolved) => resolved ? allValues.find((o) => o.value === resolved.value) : undefined;
148
+ validValue = toOptionValue(resolveModelPreference(modelInfos, requested));
149
+ if (!validValue) {
150
+ const optionInfos = allValues.map((o) => ({
151
+ value: o.value,
152
+ displayName: o.name,
153
+ description: o.description ?? "",
154
+ }));
155
+ validValue = toOptionValue(resolveModelPreference(optionInfos, requested));
156
+ }
157
+ }
158
+ if (!validValue) {
159
+ throw RequestError.invalidParams(undefined, `Invalid value for config option ${params.configId}: ${requested}`);
160
+ }
161
+ return { value: validValue.value };
162
+ }
@@ -6,6 +6,14 @@ export declare function effortFlagSettings(value: string | undefined, ultracode:
6
6
  effortLevel: EffortLevel | null;
7
7
  ultracode?: true;
8
8
  };
9
+ /**
10
+ * `params` without `_meta.claudeCode.options.effort`, for a restart of the
11
+ * session's query: the restart restores the current effort pin instead of
12
+ * the one the session was created with.
13
+ */
14
+ export declare function withoutEffort<T extends {
15
+ _meta?: unknown;
16
+ }>(params: T): T;
9
17
  /** Resolve the effort the CLI will use: per-model settings first, then the
10
18
  * legacy top-level effort setting. Model settings are keyed by canonical
11
19
  * model name, so try the resolved SDK model before picker and raw IDs. */
@@ -16,4 +24,63 @@ export declare function settingsEffortForModel(settings: Settings, modelInfo: Mo
16
24
  export declare function mergeEffortSettings(base: Settings, override: Settings | undefined): Settings;
17
25
  export declare function effortLevelName(level: string): string;
18
26
  export declare function buildEffortConfigOption(modelInfos: ModelInfo[], currentModelId: string, currentEffortLevel: string | undefined, useRecommendedValue: boolean): SessionConfigOption | undefined;
27
+ /** A session's effort bookkeeping: the level the user pinned through the
28
+ * picker, and the level last applied to the SDK's flag layer. */
29
+ export type EffortState = {
30
+ pinned: string | undefined;
31
+ applied: string | undefined;
32
+ };
33
+ /** The effort after a switch to `newModelInfo`, before the option is rebuilt
34
+ * (see {@link settleEffortAfterModelSwitch}). */
35
+ export type EffortSwitch = {
36
+ /** The effort to build the new model's option with. */
37
+ seed: string | undefined;
38
+ /** Whether the user's pin is one of the new model's levels. */
39
+ pinnedForNewModel: boolean;
40
+ before: EffortState;
41
+ /** The level applied before the switch, restored if the sync fails. */
42
+ appliedBeforeSwitch: string | undefined;
43
+ };
44
+ /** The effort seed of a model switch. It depends on who owns the choice: a
45
+ * user pin made through the ACP picker this session lives at the SDK's flag
46
+ * layer and follows the session across switches, so it carries forward.
47
+ * Otherwise the CLI resolves effort itself from the persisted settings — the
48
+ * NEW model's `modelSettings` entry first (the CLI persists /effort per
49
+ * model), then the legacy top-level value — so the option shows what it
50
+ * will actually run instead of dragging the old model's value along. */
51
+ export declare function effortForModelSwitch(input: {
52
+ state: EffortState;
53
+ /** The current value of the effort option, if it is shown. */
54
+ displayed: string | undefined;
55
+ newModelInfo: ModelInfo | undefined;
56
+ modelId: string;
57
+ /** The merged effort settings (see {@link mergeEffortSettings}). */
58
+ settings: Settings;
59
+ useRecommendedValue: boolean;
60
+ }): EffortSwitch;
61
+ /**
62
+ * Applies the effort of a model switch to the SDK's flag layer, once the new
63
+ * model's effort `option` is built from `change.seed`. Returns the new state
64
+ * and the option to show (undefined to hide it).
65
+ *
66
+ * Opted-in clients (`useRecommendedValue`) apply the concrete displayed effort
67
+ * on every switch, including settings-derived values, so a previous automatic
68
+ * flag cannot shadow the new model's settings. This does not create a user
69
+ * pin. For other clients, the flag is synced only when a user pin is lost
70
+ * across the switch — the new model clamped it away, where the flag must be
71
+ * cleared too or the SDK would keep running the old pin invisibly.
72
+ * Settings-derived seeds are display-only: the CLI resolves persisted effort
73
+ * itself, and pinning it at the flag layer would shadow the per-model values
74
+ * on every later switch.
75
+ *
76
+ * The model switch already succeeded, so a failed sync is returned as
77
+ * `error`, not thrown. The old bookkeeping stays, and the unapplied value is
78
+ * never shown: the option shows the last applied value when the new model can
79
+ * select it, else it is hidden until a later switch rebuilds it.
80
+ */
81
+ export declare function settleEffortAfterModelSwitch(change: EffortSwitch, option: SessionConfigOption | undefined, ultracode: boolean, useRecommendedValue: boolean, applyFlagSettings: (settings: ReturnType<typeof effortFlagSettings>) => Promise<void>): Promise<{
82
+ state: EffortState;
83
+ option: SessionConfigOption | undefined;
84
+ error?: unknown;
85
+ }>;
19
86
  //# sourceMappingURL=session-effort.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"session-effort.d.ts","sourceRoot":"","sources":["../src/session-effort.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AAC7E,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,gCAAgC,CAAC;AAIvF,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAK3D,wBAAgB,gBAAg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IACnB,8DAA8D;IAC9D,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,YAAY,EAAE,SAAS,GAAG,SAAS,CAAC;IACpC,OAAO,EAAE,MAAM,CAAC;IAChB,oEAAoE;IACpE,QAAQ,EAAE,QAAQ,CAAC;IACnB,mBAAmB,EAAE,OAAO,CAAC;CAC9B,GAAG,YAAY,CAmBf;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,4BAA4B,CAChD,MAAM,EAAE,YAAY,EACpB,MAAM,EAAE,mBAAmB,GAAG,SAAS,EACvC,SAAS,EAAE,OAAO,EAClB,mBAAmB,EAAE,OAAO,EAC5B,iBAAiB,EAAE,CAAC,QAAQ,EAAE,UAAU,CAAC,OAAO,kBAAkB,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,GACpF,OAAO,CAAC;IAAE,KAAK,EAAE,WAAW,CAAC;IAAC,MAAM,EAAE,mBAAmB,GAAG,SAAS,CAAC;IAAC,KAAK,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC,CA2C3F"}
@@ -16,6 +16,20 @@ export function effortFlagSettings(value, ultracode) {
16
16
  const effortLevel = toSdkEffortLevel(value);
17
17
  return ultracode ? { effortLevel, ultracode: true } : { effortLevel };
18
18
  }
19
+ /**
20
+ * `params` without `_meta.claudeCode.options.effort`, for a restart of the
21
+ * session's query: the restart restores the current effort pin instead of
22
+ * the one the session was created with.
23
+ */
24
+ export function withoutEffort(params) {
25
+ const meta = params._meta;
26
+ if (meta?.claudeCode?.options?.effort === undefined) {
27
+ return params;
28
+ }
29
+ const options = { ...meta.claudeCode.options };
30
+ delete options.effort;
31
+ return { ...params, _meta: { ...meta, claudeCode: { ...meta.claudeCode, options } } };
32
+ }
19
33
  function canonicalizeModelSettingsKey(value) {
20
34
  return value
21
35
  .trim()
@@ -103,3 +117,87 @@ export function buildEffortConfigOption(modelInfos, currentModelId, currentEffor
103
117
  : {}),
104
118
  };
105
119
  }
120
+ /** The effort seed of a model switch. It depends on who owns the choice: a
121
+ * user pin made through the ACP picker this session lives at the SDK's flag
122
+ * layer and follows the session across switches, so it carries forward.
123
+ * Otherwise the CLI resolves effort itself from the persisted settings — the
124
+ * NEW model's `modelSettings` entry first (the CLI persists /effort per
125
+ * model), then the legacy top-level value — so the option shows what it
126
+ * will actually run instead of dragging the old model's value along. */
127
+ export function effortForModelSwitch(input) {
128
+ const { state, displayed, newModelInfo, useRecommendedValue } = input;
129
+ const pinned = state.pinned;
130
+ const pinnedForNewModel = pinned !== undefined &&
131
+ newModelInfo?.supportsEffort === true &&
132
+ newModelInfo.supportedEffortLevels?.some((level) => level === pinned) === true;
133
+ return {
134
+ seed: pinnedForNewModel
135
+ ? pinned
136
+ : settingsEffortForModel(input.settings, newModelInfo, input.modelId),
137
+ pinnedForNewModel,
138
+ before: state,
139
+ appliedBeforeSwitch: state.applied ??
140
+ (useRecommendedValue && typeof displayed === "string" && displayed !== "default"
141
+ ? displayed
142
+ : pinned),
143
+ };
144
+ }
145
+ /**
146
+ * Applies the effort of a model switch to the SDK's flag layer, once the new
147
+ * model's effort `option` is built from `change.seed`. Returns the new state
148
+ * and the option to show (undefined to hide it).
149
+ *
150
+ * Opted-in clients (`useRecommendedValue`) apply the concrete displayed effort
151
+ * on every switch, including settings-derived values, so a previous automatic
152
+ * flag cannot shadow the new model's settings. This does not create a user
153
+ * pin. For other clients, the flag is synced only when a user pin is lost
154
+ * across the switch — the new model clamped it away, where the flag must be
155
+ * cleared too or the SDK would keep running the old pin invisibly.
156
+ * Settings-derived seeds are display-only: the CLI resolves persisted effort
157
+ * itself, and pinning it at the flag layer would shadow the per-model values
158
+ * on every later switch.
159
+ *
160
+ * The model switch already succeeded, so a failed sync is returned as
161
+ * `error`, not thrown. The old bookkeeping stays, and the unapplied value is
162
+ * never shown: the option shows the last applied value when the new model can
163
+ * select it, else it is hidden until a later switch rebuilds it.
164
+ */
165
+ export async function settleEffortAfterModelSwitch(change, option, ultracode, useRecommendedValue, applyFlagSettings) {
166
+ const { pinnedForNewModel, before } = change;
167
+ const sync = useRecommendedValue || (before.pinned !== undefined && !pinnedForNewModel);
168
+ if (!sync) {
169
+ return {
170
+ state: pinnedForNewModel ? { pinned: before.pinned, applied: before.pinned } : before,
171
+ option,
172
+ };
173
+ }
174
+ const newEffort = typeof option?.currentValue === "string" ? option.currentValue : undefined;
175
+ try {
176
+ // A legacy client's unpinned effort is display-only: the CLI resolves the
177
+ // persisted value for the new model. When an old user pin is no longer
178
+ // supported, clear the flag layer instead of replacing it with that
179
+ // displayed value. Opted-in clients deliberately apply their concrete
180
+ // displayed effort.
181
+ await applyFlagSettings(effortFlagSettings(useRecommendedValue ? newEffort : undefined, ultracode));
182
+ return {
183
+ state: {
184
+ pinned: pinnedForNewModel ? before.pinned : undefined,
185
+ applied: useRecommendedValue && newEffort !== "default" ? newEffort : undefined,
186
+ },
187
+ option,
188
+ };
189
+ }
190
+ catch (error) {
191
+ const applied = change.appliedBeforeSwitch;
192
+ const selectable = applied !== undefined &&
193
+ option?.type === "select" &&
194
+ option.options.some((entry) => "value" in entry
195
+ ? entry.value === applied
196
+ : entry.options.some((nested) => nested.value === applied));
197
+ return {
198
+ state: { pinned: before.pinned, applied },
199
+ option: selectable && option?.type === "select" ? { ...option, currentValue: applied } : undefined,
200
+ error,
201
+ };
202
+ }
203
+ }
@@ -0,0 +1,22 @@
1
+ import type { Options, Settings, ThinkingConfig } from "@anthropic-ai/claude-agent-sdk";
2
+ /** Translate the legacy `MAX_THINKING_TOKENS` env var, plus the optional
3
+ * `CLAUDE_CODE_THINKING_DISPLAY` env var, into the SDK's `thinking` option.
4
+ * The `maxThinkingTokens` option it used to feed is deprecated and reduced
5
+ * to on/off on current models, so map the value to explicit thinking config
6
+ * instead: unset → `undefined` (SDK default, adaptive on models that support
7
+ * it) unless a display mode is requested, in which case it becomes explicit
8
+ * `adaptive`; `0` → disabled; a positive integer → a fixed token budget.
9
+ * Anything else is ignored with a warning. `CLAUDE_CODE_THINKING_DISPLAY`
10
+ * must be `summarized` or `omitted`; it has no effect when thinking is
11
+ * disabled. */
12
+ export declare function resolveThinkingConfig(rawTokens: string | undefined, rawDisplay: string | undefined, logger: {
13
+ error: (...args: unknown[]) => void;
14
+ }): ThinkingConfig | undefined;
15
+ /**
16
+ * The programmatic settings of a session, before the provider routing: the
17
+ * models of `CLAUDE_MODEL_CONFIG`, then the client's `settings` option, an
18
+ * object or a file path relative to `cwd`. Throws for a `CLAUDE_MODEL_CONFIG`
19
+ * that is no JSON object, before it reads the file.
20
+ */
21
+ export declare function configuredSettings(provided: Options["settings"], cwd: string): Promise<Settings | undefined>;
22
+ //# sourceMappingURL=session-env.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-env.d.ts","sourceRoot":"","sources":["../src/session-env.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAExF;;;;;;;;;gBASgB;AAChB,wBAAgB,qBAAqB,CACnC,SAAS,EAAE,MAAM,GAAG,SAAS,EAC7B,UAAU,EAAE,MAAM,GAAG,SAAS,EAC9B,MAAM,EAAE;IAAE,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAA;CAAE,GAC9C,cAAc,GAAG,SAAS,CAyB5B;AAiBD;;;;;GAKG;AACH,wBAAsB,kBAAkB,CACtC,QAAQ,EAAE,OAAO,CAAC,UAAU,CAAC,EAC7B,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC,CAO/B"}