claude-code-rust 0.12.1 → 0.12.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.
@@ -7,10 +7,12 @@ import { getSessionMessages, listSessions, renameSession, } from "@anthropic-ai/
7
7
  import { buildModeState, markModeUnavailableForSession, parseCommandEnvelope, permissionModeFailureLooksUnsupported, refreshSupportedModesForSession, toPermissionMode, } from "./bridge/commands.js";
8
8
  import { writeEvent, failConnection, slashError, emitRuntimeReloadCompleted, emitRuntimeReloadFailed, emitSessionUpdate, emitSessionsList, currentSessionListOptions, setSessionListingDir, } from "./bridge/events.js";
9
9
  import { contentFromPrompt } from "./bridge/message_handlers.js";
10
- import { sessions, sessionById, createSession, closeAllSessions, handleElicitationResponse, handlePermissionResponse, handleQuestionResponse, emitCurrentModelUpdate, refreshCurrentModel, shouldInvalidateResolvedRuntimeModel, } from "./bridge/session_lifecycle.js";
10
+ import { sessions, sessionById, createSession, closeAllSessions, handleElicitationResponse, handlePermissionResponse, handleQuestionResponse, handleUserDialogResponse, emitCurrentModelUpdate, refreshCurrentModel, shouldInvalidateResolvedRuntimeModel, } from "./bridge/session_lifecycle.js";
11
11
  import { mapSessionMessagesToUpdates } from "./bridge/history.js";
12
12
  import { emitAvailableAgentsIfChanged, mapAvailableAgents } from "./bridge/agents.js";
13
- import { MCP_STALE_STATUS_REVALIDATION_COOLDOWN_MS, handleMcpAuthenticateCommand, handleMcpClearAuthCommand, handleMcpOauthCallbackUrlCommand, handleMcpReconnectCommand, handleMcpSetServersCommand, handleMcpStatusCommand, handleMcpToggleCommand, staleMcpAuthCandidates, } from "./bridge/mcp.js";
13
+ import { mapSdkSlashCommands, updateAvailableCommands } from "./bridge/available_commands.js";
14
+ import { mapSdkAccountInfo } from "./bridge/account_metadata.js";
15
+ import { MCP_STALE_STATUS_REVALIDATION_COOLDOWN_MS, emitReconciledMcpSnapshotFromStatuses, handleMcpAuthenticateCommand, handleMcpClearAuthCommand, handleMcpOauthCallbackUrlCommand, handleMcpReconnectCommand, handleMcpSetServersCommand, handleMcpStatusCommand, handleMcpToggleCommand, staleMcpAuthCandidates, } from "./bridge/mcp.js";
14
16
  import { bridgeLogger, LOG_TARGETS, logBridgeCommandReceived } from "./bridge/logger.js";
15
17
  // Re-exports: all symbols that tests and external consumers import from bridge.js.
16
18
  export { AsyncQueue } from "./bridge/shared.js";
@@ -20,11 +22,15 @@ export { buildToolResultFields, createToolCall, normalizeToolKind, normalizeTool
20
22
  export { looksLikeAuthRequired } from "./bridge/auth.js";
21
23
  export { parseCommandEnvelope } from "./bridge/commands.js";
22
24
  export { buildSessionListOptions } from "./bridge/events.js";
25
+ export { mapInitSlashCommands, mapSdkSlashCommands, updateAvailableCommands, } from "./bridge/available_commands.js";
23
26
  export { permissionOptionsFromSuggestions, permissionResultFromOutcome, } from "./bridge/permissions.js";
24
27
  export { mapSessionMessagesToUpdates, mapSdkSessions, } from "./bridge/history.js";
25
28
  export { handleSdkMessage, handleTaskSystemMessage } from "./bridge/message_handlers.js";
26
29
  export { mapAvailableAgents } from "./bridge/agents.js";
27
- export { attachRequestUserDialogInterceptor, buildQueryOptions, mapAvailableModels, } from "./bridge/session_lifecycle.js";
30
+ export { buildQueryOptions } from "./bridge/session_lifecycle.js";
31
+ export { mapAvailableModels } from "./bridge/model_metadata.js";
32
+ export { bridgeMcpConfigToSdk, mapMcpServerStatus, mapMcpServerStatusConfig, } from "./bridge/mcp_metadata.js";
33
+ export { apiProviderIsExternal, isKnownApiProvider, mapSdkAccountInfo, shouldEmitStartupAuthRequiredForAccount, } from "./bridge/account_metadata.js";
28
34
  export { parseFastModeState, parseRateLimitStatus, parseRuntimeSessionState, parseApiRetryError, buildRateLimitUpdate, buildApiRetryUpdate, normalizeSettingsParseError, normalizeSettingsParseErrors, } from "./bridge/state_parsing.js";
29
35
  export { MCP_STALE_STATUS_REVALIDATION_COOLDOWN_MS, staleMcpAuthCandidates };
30
36
  export function buildSessionMutationOptions(cwd) {
@@ -43,7 +49,30 @@ export async function generatePersistedSessionTitle(query, description) {
43
49
  }
44
50
  return title;
45
51
  }
46
- const EXPECTED_AGENT_SDK_VERSION = "0.3.146";
52
+ export async function applySessionEffort(query, effort) {
53
+ const settings = { effortLevel: effort };
54
+ // applyFlagSettings controls live session settings; SDK Settings typings model persisted effort levels.
55
+ await query.applyFlagSettings(settings);
56
+ }
57
+ export async function applySessionAgent(query, agent) {
58
+ const settings = { agent };
59
+ await query.applyFlagSettings(settings);
60
+ }
61
+ export function emitEffortConfigOptionUpdate(sessionId, effort) {
62
+ emitSessionUpdate(sessionId, {
63
+ type: "config_option_update",
64
+ option_id: "effortLevel",
65
+ value: effort,
66
+ });
67
+ }
68
+ export function emitAgentConfigOptionUpdate(sessionId, agent) {
69
+ emitSessionUpdate(sessionId, {
70
+ type: "config_option_update",
71
+ option_id: "agent",
72
+ value: agent,
73
+ });
74
+ }
75
+ const EXPECTED_AGENT_SDK_VERSION = "0.3.177";
47
76
  const require = createRequire(import.meta.url);
48
77
  export function resolveInstalledAgentSdkVersion() {
49
78
  try {
@@ -68,6 +97,28 @@ export function agentSdkVersionCompatibilityError() {
68
97
  return (`Unsupported @anthropic-ai/claude-agent-sdk version: expected ${EXPECTED_AGENT_SDK_VERSION}, ` +
69
98
  `found ${installed}.`);
70
99
  }
100
+ export async function handleReloadPluginsCommand(session, requestId) {
101
+ try {
102
+ const result = await session.query.reloadPlugins();
103
+ updateAvailableCommands(session, "reload_plugins", mapSdkSlashCommands(result.commands));
104
+ emitAvailableAgentsIfChanged(session, mapAvailableAgents(result.agents));
105
+ await emitReconciledMcpSnapshotFromStatuses(session, result.mcpServers, "reload_plugins", requestId);
106
+ emitRuntimeReloadCompleted(session.sessionId, requestId);
107
+ }
108
+ catch (error) {
109
+ const message = error instanceof Error ? error.message : String(error);
110
+ bridgeLogger.warn({
111
+ target: LOG_TARGETS.APP_SESSION,
112
+ eventName: "reload_plugins_failed",
113
+ message: "failed to reload session plugins",
114
+ outcome: "failure",
115
+ ...(requestId ? { requestId } : {}),
116
+ sessionId: session.sessionId,
117
+ fields: { error_message: message },
118
+ });
119
+ emitRuntimeReloadFailed(session.sessionId, message, requestId);
120
+ }
121
+ }
71
122
  async function handleCommand(command, requestId) {
72
123
  logBridgeCommandReceived(command, requestId);
73
124
  const sdkVersionError = agentSdkVersionCompatibilityError();
@@ -170,7 +221,9 @@ async function handleCommand(command, requestId) {
170
221
  return;
171
222
  }
172
223
  setSessionListingDir(matched.cwd ?? process.cwd());
173
- const historyMessages = await getSessionMessages(command.session_id, matched.cwd ? { dir: matched.cwd } : undefined);
224
+ const historyMessages = await getSessionMessages(command.session_id, matched.cwd
225
+ ? { dir: matched.cwd, includeSystemMessages: true }
226
+ : { includeSystemMessages: true });
174
227
  const resumeUpdates = mapSessionMessagesToUpdates(historyMessages);
175
228
  const staleSessions = Array.from(sessions.values());
176
229
  const hadActiveSession = staleSessions.length > 0;
@@ -377,6 +430,38 @@ async function handleCommand(command, requestId) {
377
430
  }
378
431
  return;
379
432
  }
433
+ case "set_effort": {
434
+ const session = sessionById(command.session_id);
435
+ if (!session) {
436
+ slashError(command.session_id, `unknown session: ${command.session_id}`, requestId);
437
+ return;
438
+ }
439
+ try {
440
+ await applySessionEffort(session.query, command.effort);
441
+ emitEffortConfigOptionUpdate(session.sessionId, command.effort);
442
+ }
443
+ catch (error) {
444
+ const message = error instanceof Error ? error.message : String(error);
445
+ slashError(command.session_id, `failed to set effort: ${message}`, requestId);
446
+ }
447
+ return;
448
+ }
449
+ case "set_agent": {
450
+ const session = sessionById(command.session_id);
451
+ if (!session) {
452
+ slashError(command.session_id, `unknown session: ${command.session_id}`, requestId);
453
+ return;
454
+ }
455
+ try {
456
+ await applySessionAgent(session.query, command.agent);
457
+ emitAgentConfigOptionUpdate(session.sessionId, command.agent);
458
+ }
459
+ catch (error) {
460
+ const message = error instanceof Error ? error.message : String(error);
461
+ slashError(command.session_id, `failed to set agent: ${message}`, requestId);
462
+ }
463
+ return;
464
+ }
380
465
  case "generate_session_title": {
381
466
  const session = sessionById(command.session_id);
382
467
  if (!session) {
@@ -438,14 +523,7 @@ async function handleCommand(command, requestId) {
438
523
  writeEvent({
439
524
  event: "status_snapshot",
440
525
  session_id: session.sessionId,
441
- account: {
442
- email: account.email,
443
- organization: account.organization,
444
- subscription_type: account.subscriptionType,
445
- token_source: account.tokenSource,
446
- api_key_source: account.apiKeySource,
447
- api_provider: account.apiProvider,
448
- },
526
+ account: mapSdkAccountInfo(account),
449
527
  }, requestId);
450
528
  }
451
529
  catch (error) {
@@ -525,36 +603,7 @@ async function handleCommand(command, requestId) {
525
603
  slashError(command.session_id, `unknown session: ${command.session_id}`, requestId);
526
604
  return;
527
605
  }
528
- try {
529
- const result = await session.query.reloadPlugins();
530
- const commands = Array.isArray(result.commands)
531
- ? result.commands.map((entry) => ({
532
- name: entry.name,
533
- description: entry.description ?? "",
534
- input_hint: entry.argumentHint ?? undefined,
535
- }))
536
- : [];
537
- emitSessionUpdate(session.sessionId, {
538
- type: "available_commands_update",
539
- commands,
540
- });
541
- emitAvailableAgentsIfChanged(session, mapAvailableAgents(result.agents));
542
- await handleMcpStatusCommand(session, requestId);
543
- emitRuntimeReloadCompleted(session.sessionId, requestId);
544
- }
545
- catch (error) {
546
- const message = error instanceof Error ? error.message : String(error);
547
- bridgeLogger.warn({
548
- target: LOG_TARGETS.APP_SESSION,
549
- eventName: "reload_plugins_failed",
550
- message: "failed to reload session plugins",
551
- outcome: "failure",
552
- ...(requestId ? { requestId } : {}),
553
- sessionId: session.sessionId,
554
- fields: { error_message: message },
555
- });
556
- emitRuntimeReloadFailed(session.sessionId, message, requestId);
557
- }
606
+ await handleReloadPluginsCommand(session, requestId);
558
607
  return;
559
608
  }
560
609
  case "mcp_status": {
@@ -626,6 +675,9 @@ async function handleCommand(command, requestId) {
626
675
  case "question_response":
627
676
  handleQuestionResponse(command);
628
677
  return;
678
+ case "user_dialog_response":
679
+ handleUserDialogResponse(command);
680
+ return;
629
681
  case "elicitation_response":
630
682
  handleElicitationResponse(command);
631
683
  return;