@moxxy/plugin-provider-claude-code 0.44.0 → 0.45.0

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 (117) hide show
  1. package/dist/account-limit.d.ts +8 -0
  2. package/dist/account-limit.d.ts.map +1 -0
  3. package/dist/account-limit.js +23 -0
  4. package/dist/account-limit.js.map +1 -0
  5. package/dist/agent-provider.d.ts +61 -0
  6. package/dist/agent-provider.d.ts.map +1 -0
  7. package/dist/agent-provider.js +195 -0
  8. package/dist/agent-provider.js.map +1 -0
  9. package/dist/agent-session.d.ts +145 -0
  10. package/dist/agent-session.d.ts.map +1 -0
  11. package/dist/agent-session.js +700 -0
  12. package/dist/agent-session.js.map +1 -0
  13. package/dist/background-work.d.ts +42 -0
  14. package/dist/background-work.d.ts.map +1 -0
  15. package/dist/background-work.js +140 -0
  16. package/dist/background-work.js.map +1 -0
  17. package/dist/constants.d.ts +2 -2
  18. package/dist/constants.d.ts.map +1 -1
  19. package/dist/constants.js +2 -2
  20. package/dist/constants.js.map +1 -1
  21. package/dist/executable.d.ts +15 -0
  22. package/dist/executable.d.ts.map +1 -0
  23. package/dist/executable.js +30 -0
  24. package/dist/executable.js.map +1 -0
  25. package/dist/index.d.ts +4 -3
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js +55 -16
  28. package/dist/index.js.map +1 -1
  29. package/dist/login.d.ts +3 -0
  30. package/dist/login.d.ts.map +1 -1
  31. package/dist/login.js +8 -1
  32. package/dist/login.js.map +1 -1
  33. package/dist/offered-models.d.ts +13 -0
  34. package/dist/offered-models.d.ts.map +1 -0
  35. package/dist/offered-models.js +45 -0
  36. package/dist/offered-models.js.map +1 -0
  37. package/dist/own-settings.d.ts +12 -0
  38. package/dist/own-settings.d.ts.map +1 -0
  39. package/dist/own-settings.js +31 -0
  40. package/dist/own-settings.js.map +1 -0
  41. package/dist/questions.d.ts +6 -0
  42. package/dist/questions.d.ts.map +1 -0
  43. package/dist/questions.js +38 -0
  44. package/dist/questions.js.map +1 -0
  45. package/dist/scheduled-wakeups.d.ts +10 -0
  46. package/dist/scheduled-wakeups.d.ts.map +1 -0
  47. package/dist/scheduled-wakeups.js +30 -0
  48. package/dist/scheduled-wakeups.js.map +1 -0
  49. package/dist/sdk-install.d.ts +25 -0
  50. package/dist/sdk-install.d.ts.map +1 -0
  51. package/dist/sdk-install.js +94 -0
  52. package/dist/sdk-install.js.map +1 -0
  53. package/dist/sdk-types.d.ts +310 -0
  54. package/dist/sdk-types.d.ts.map +1 -0
  55. package/dist/sdk-types.js +8 -0
  56. package/dist/sdk-types.js.map +1 -0
  57. package/dist/subagents.d.ts +39 -0
  58. package/dist/subagents.d.ts.map +1 -0
  59. package/dist/subagents.js +114 -0
  60. package/dist/subagents.js.map +1 -0
  61. package/dist/task-list.d.ts +21 -0
  62. package/dist/task-list.d.ts.map +1 -0
  63. package/dist/task-list.js +68 -0
  64. package/dist/task-list.js.map +1 -0
  65. package/dist/translate.d.ts +57 -0
  66. package/dist/translate.d.ts.map +1 -0
  67. package/dist/translate.js +276 -0
  68. package/dist/translate.js.map +1 -0
  69. package/package.json +14 -9
  70. package/src/account-limit.ts +26 -0
  71. package/src/agent-cli.test.ts +83 -0
  72. package/src/agent-provider.test.ts +1156 -0
  73. package/src/agent-provider.ts +223 -0
  74. package/src/agent-session.ts +790 -0
  75. package/src/background-work.ts +163 -0
  76. package/src/constants.ts +2 -3
  77. package/src/event-coverage.test.ts +105 -0
  78. package/src/executable.test.ts +60 -0
  79. package/src/executable.ts +34 -0
  80. package/src/fake-claude.testkit.ts +376 -0
  81. package/src/fixtures/claude-agent-sdk-0.3.296.json +43 -0
  82. package/src/fixtures/claude-supported-models-0.3.296.json +218 -0
  83. package/src/index.test.ts +49 -0
  84. package/src/index.ts +61 -18
  85. package/src/login.ts +10 -1
  86. package/src/offered-models.test.ts +73 -0
  87. package/src/offered-models.ts +57 -0
  88. package/src/own-settings.test.ts +68 -0
  89. package/src/own-settings.ts +33 -0
  90. package/src/questions.test.ts +68 -0
  91. package/src/questions.ts +45 -0
  92. package/src/scheduled-wakeups.test.ts +41 -0
  93. package/src/scheduled-wakeups.ts +34 -0
  94. package/src/sdk-install.test.ts +124 -0
  95. package/src/sdk-install.ts +107 -0
  96. package/src/sdk-types.ts +277 -0
  97. package/src/subagents.ts +123 -0
  98. package/src/task-list.ts +65 -0
  99. package/src/translate.test.ts +439 -0
  100. package/src/translate.ts +280 -0
  101. package/dist/process.d.ts +0 -34
  102. package/dist/process.d.ts.map +0 -1
  103. package/dist/process.js +0 -197
  104. package/dist/process.js.map +0 -1
  105. package/dist/protocol.d.ts +0 -30
  106. package/dist/protocol.d.ts.map +0 -1
  107. package/dist/protocol.js +0 -368
  108. package/dist/protocol.js.map +0 -1
  109. package/dist/provider.d.ts +0 -53
  110. package/dist/provider.d.ts.map +0 -1
  111. package/dist/provider.js +0 -229
  112. package/dist/provider.js.map +0 -1
  113. package/src/process.test.ts +0 -208
  114. package/src/process.ts +0 -224
  115. package/src/protocol.ts +0 -390
  116. package/src/provider.test.ts +0 -671
  117. package/src/provider.ts +0 -267
@@ -0,0 +1,376 @@
1
+ /**
2
+ * A stand-in for the Claude Agent SDK, the external boundary of the Claude
3
+ * agent connection. It behaves like `query()`: it reads the person's messages
4
+ * from the input stream, starts each turn with `system/init`, ends it with
5
+ * `result`, asks `canUseTool` and the `PreToolUse` hook, and calls Moxxy's
6
+ * tools over Moxxy's MCP server with the real MCP client. What Claude does in
7
+ * a turn is a scene the test writes.
8
+ */
9
+ import { Client } from '@modelcontextprotocol/sdk/client/index.js';
10
+ import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
11
+ import { ToolListChangedNotificationSchema } from '@modelcontextprotocol/sdk/types.js';
12
+ import type {
13
+ ClaudeAgentSdk,
14
+ ClaudeMessage,
15
+ ClaudePermissionMode,
16
+ ClaudePermissionResult,
17
+ ClaudePreToolUseOutput,
18
+ ClaudeSessionCron,
19
+ ClaudeQuery,
20
+ ClaudeQueryOptions,
21
+ ClaudeResolvedSettings,
22
+ ClaudeSettings,
23
+ ClaudeMcpServerStatus,
24
+ ClaudeModelInfo,
25
+ ClaudeSlashCommand,
26
+ ClaudeUserContent,
27
+ ClaudeUserMessage,
28
+ } from './sdk-types.js';
29
+
30
+ export interface FakeTurn {
31
+ readonly text: string;
32
+ readonly content: ClaudeUserContent;
33
+ readonly query: FakeQuery;
34
+ canUseTool(
35
+ name: string,
36
+ input: Record<string, unknown>,
37
+ toolUseID: string,
38
+ extra?: { mcpServer?: { name: string; source: string }; agentID?: string },
39
+ ): Promise<ClaudePermissionResult>;
40
+ /** `agentId` makes the call one from inside a subagent. */
41
+ preToolUse(name: string, input: unknown, toolUseID: string, agentId?: string): Promise<ClaudePreToolUseOutput>;
42
+ callMoxxyTool(name: string, args: Record<string, unknown>): Promise<{ content: unknown; isError?: boolean }>;
43
+ }
44
+
45
+ export type ClaudeScene = (turn: FakeTurn) => AsyncIterable<ClaudeMessage>;
46
+
47
+ /** A turn Claude takes up by itself: what its background work sent first, then what it says. */
48
+ export interface OwnTurn {
49
+ readonly background?: ReadonlyArray<ClaudeMessage>;
50
+ readonly messages: ReadonlyArray<ClaudeMessage>;
51
+ /** Only the background work's messages: Claude takes up no turn after them. */
52
+ readonly noTurn?: true;
53
+ /** A turn Claude woke itself up for (ScheduleWakeup, /loop): its result carries no origin at all. */
54
+ readonly scheduled?: true;
55
+ }
56
+
57
+ export const assistantText = (text: string, model = 'claude-opus-5-5'): ClaudeMessage =>
58
+ ({ type: 'assistant', message: { model, content: [{ type: 'text', text }] }, parent_tool_use_id: null }) as ClaudeMessage;
59
+ export const assistantToolUse = (id: string, name: string, input: unknown): ClaudeMessage =>
60
+ ({ type: 'assistant', message: { content: [{ type: 'tool_use', id, name, input }] }, parent_tool_use_id: null }) as ClaudeMessage;
61
+ export const toolResult = (id: string, content: string, isError = false): ClaudeMessage =>
62
+ ({ type: 'user', message: { content: [{ type: 'tool_result', tool_use_id: id, content, is_error: isError }] }, parent_tool_use_id: null }) as ClaudeMessage;
63
+
64
+ export class FakeClaude implements ClaudeAgentSdk {
65
+ readonly queries: FakeQuery[] = [];
66
+ /** The sessions Claude keeps on disk, as `getSessionInfo` finds them. */
67
+ readonly saved = new Set<string>();
68
+ private sessions = 0;
69
+ /** The person's own Claude skills and commands, as `supportedCommands` reports them next to Claude's built-in ones. */
70
+ ownSkills: ReadonlyArray<string> = [];
71
+ /** The person's own MCP servers, as `mcpServerStatus` reports them next to Moxxy's. */
72
+ ownMcpServers: ReadonlyArray<string> = [];
73
+ /** What `supportedModels` answers, as the Claude the person signed in to lists them; an error is thrown instead. */
74
+ models: ReadonlyArray<ClaudeModelInfo> | Error = [];
75
+ /** The folders `resolveSettings` was asked about. */
76
+ readonly settingsRead: string[] = [];
77
+ /** The own mode comes from the repository's settings, which the trust filter drops. */
78
+ fromRepository = false;
79
+ settingsError: Error | undefined;
80
+ /** `ownMode`: the mode the person's own Claude settings start in when Moxxy names none. */
81
+ constructor(
82
+ private readonly scene: ClaudeScene,
83
+ private readonly ownMode: ClaudePermissionMode = 'default',
84
+ ) {}
85
+
86
+ async resolveSettings(opts?: { readonly cwd?: string }): Promise<ClaudeResolvedSettings> {
87
+ this.settingsRead.push(opts?.cwd ?? '');
88
+ if (this.settingsError) throw this.settingsError;
89
+ return {
90
+ effective: { permissions: { defaultMode: this.ownMode } },
91
+ sources: [{ source: this.fromRepository ? 'project' : 'user', settings: { permissions: { defaultMode: this.ownMode } } }],
92
+ };
93
+ }
94
+
95
+ filterEscalatingDefaultMode(resolved: ClaudeResolvedSettings): ClaudeSettings {
96
+ return this.fromRepository ? { ...resolved.effective, permissions: {} } : resolved.effective;
97
+ }
98
+
99
+ async getSessionInfo(sessionId: string): Promise<{ sessionId: string } | undefined> {
100
+ return this.saved.has(sessionId) ? { sessionId } : undefined;
101
+ }
102
+
103
+ query(params: { prompt: string | AsyncIterable<ClaudeUserMessage>; options: ClaudeQueryOptions }): ClaudeQuery {
104
+ this.sessions += 1;
105
+ const sessionId = params.options.resume ?? `claude-session-${this.sessions}`;
106
+ this.saved.add(sessionId);
107
+ const query = new FakeQuery(params.prompt, params.options, sessionId, this.scene, this.ownMode, () => this.ownSkills, () => this.ownMcpServers, () => this.models);
108
+ this.queries.push(query);
109
+ return query;
110
+ }
111
+
112
+ get last(): FakeQuery {
113
+ const query = this.queries.at(-1);
114
+ if (!query) throw new Error('Claude was never started');
115
+ return query;
116
+ }
117
+ }
118
+
119
+ export class FakeQuery implements ClaudeQuery {
120
+ readonly received: ClaudeUserMessage[] = [];
121
+ readonly modeChanges: ClaudePermissionMode[] = [];
122
+ readonly modelChanges: string[] = [];
123
+ interrupts = 0;
124
+ closed = false;
125
+ /** The tasks `stopTask` was asked to stop, in order. */
126
+ readonly stoppedTasks: string[] = [];
127
+ permissionMode: ClaudePermissionMode;
128
+ /** Moxxy's tools as Claude read them: once as it starts, and again on a list-changed notice. */
129
+ moxxyTools: ReadonlyArray<string> = [];
130
+ private reading: Promise<void> | undefined;
131
+ private stop = new AbortController();
132
+ private mcp: Client | undefined;
133
+ /** Status messages waiting to be read, as Claude sends them whether or not a turn runs. */
134
+ private readonly statuses: ClaudeMessage[] = [];
135
+ /** Turns Claude takes up by itself between the person's messages. */
136
+ private readonly ownTurns: OwnTurn[] = [];
137
+ private wakeOwnTurn: (() => void) | undefined;
138
+
139
+ constructor(
140
+ private readonly prompt: string | AsyncIterable<ClaudeUserMessage>,
141
+ readonly options: ClaudeQueryOptions,
142
+ readonly sessionId: string,
143
+ private readonly scene: ClaudeScene,
144
+ ownMode: ClaudePermissionMode = 'default',
145
+ private readonly ownSkills: () => ReadonlyArray<string> = () => [],
146
+ private readonly ownMcpServers: () => ReadonlyArray<string> = () => [],
147
+ private readonly models: () => ReadonlyArray<ClaudeModelInfo> | Error = () => [],
148
+ ) {
149
+ this.permissionMode = options.permissionMode ?? ownMode;
150
+ }
151
+
152
+ async *[Symbol.asyncIterator](): AsyncIterator<ClaudeMessage> {
153
+ try {
154
+ if (this.options.mcpServers?.moxxy) await this.readMoxxyTools();
155
+ const first = typeof this.prompt === 'string' ? this.userMessage(this.prompt) : undefined;
156
+ const source: AsyncIterable<ClaudeUserMessage> =
157
+ first !== undefined
158
+ ? (async function* () {
159
+ yield first;
160
+ })()
161
+ : (this.prompt as AsyncIterable<ClaudeUserMessage>);
162
+ const messages = source[Symbol.asyncIterator]();
163
+ let nextMessage = messages.next();
164
+ for (;;) {
165
+ const arrived = await Promise.race([nextMessage, this.ownTurnArrived()]);
166
+ if (arrived === 'own') {
167
+ yield* this.ownTurn();
168
+ continue;
169
+ }
170
+ if (arrived.done) return;
171
+ nextMessage = messages.next();
172
+ const message = arrived.value;
173
+ if (this.closed) return;
174
+ this.received.push(message);
175
+ this.stop = new AbortController();
176
+ yield* this.statuses.splice(0);
177
+ yield { type: 'system', subtype: 'init', session_id: this.sessionId, permissionMode: this.permissionMode, model: this.options.model } as ClaudeMessage;
178
+ let ended = false;
179
+ const stop = this.stop.signal;
180
+ const stopped = new Promise<'stopped'>((resolve) => stop.addEventListener('abort', () => resolve('stopped'), { once: true }));
181
+ const scene = this.scene(this.turn(message))[Symbol.asyncIterator]();
182
+ for (;;) {
183
+ const next = await Promise.race([scene.next(), stopped]);
184
+ if (next === 'stopped') {
185
+ void scene.return?.();
186
+ break;
187
+ }
188
+ yield* this.statuses.splice(0);
189
+ if (next.done) break;
190
+ if (next.value.type === 'result') {
191
+ ended = true;
192
+ await this.stopHooks();
193
+ }
194
+ yield next.value;
195
+ }
196
+ if (this.stop.signal.aborted) {
197
+ yield this.result('error_during_execution', true);
198
+ } else if (!ended) {
199
+ await this.stopHooks();
200
+ yield this.result('success', false);
201
+ }
202
+ }
203
+ } finally {
204
+ await this.mcp?.close();
205
+ }
206
+ }
207
+
208
+ /**
209
+ * Claude takes up a turn by itself, as Claude Code 2.1 does once a task it ran
210
+ * in the background finished: first what the background work sent, then a
211
+ * turn of its own (`init`, its messages, a `result` marked as its own).
212
+ */
213
+ startOwnTurn(turn: OwnTurn): void {
214
+ this.ownTurns.push(turn);
215
+ const wake = this.wakeOwnTurn;
216
+ this.wakeOwnTurn = undefined;
217
+ wake?.();
218
+ }
219
+
220
+ private ownTurnArrived(): Promise<'own'> {
221
+ if (this.ownTurns.length > 0) return Promise.resolve('own');
222
+ return new Promise((resolve) => (this.wakeOwnTurn = () => resolve('own')));
223
+ }
224
+
225
+ /** Claude's background work sends messages while no turn runs, and Claude takes up no turn after them. */
226
+ sendBetweenTurns(messages: ReadonlyArray<ClaudeMessage>): void {
227
+ this.startOwnTurn({ background: messages, messages: [], noTurn: true });
228
+ }
229
+
230
+ /** What Claude has set itself to come back for, as its `Stop` hook reports at the end of every turn. */
231
+ crons: ReadonlyArray<ClaudeSessionCron> | undefined = [];
232
+
233
+ private async stopHooks(): Promise<void> {
234
+ for (const matcher of this.options.hooks?.Stop ?? []) {
235
+ for (const hook of matcher.hooks) {
236
+ await hook({ hook_event_name: 'Stop', ...(this.crons ? { session_crons: this.crons } : {}) }, undefined, { signal: this.stop.signal });
237
+ }
238
+ }
239
+ }
240
+
241
+ private async *ownTurn(): AsyncGenerator<ClaudeMessage> {
242
+ const turn = this.ownTurns.shift();
243
+ if (!turn) return;
244
+ yield* turn.background ?? [];
245
+ if (turn.noTurn) return;
246
+ yield { type: 'system', subtype: 'init', session_id: this.sessionId, permissionMode: this.permissionMode, model: this.options.model } as ClaudeMessage;
247
+ yield* turn.messages;
248
+ await this.stopHooks();
249
+ yield this.result('success', false, turn.scheduled ? { origin: undefined } : { origin: { kind: 'task-notification', producer: 'session-task' } });
250
+ }
251
+
252
+ async interrupt(): Promise<unknown> {
253
+ this.interrupts += 1;
254
+ this.stop.abort();
255
+ return undefined;
256
+ }
257
+
258
+ async stopTask(taskId: string): Promise<void> {
259
+ this.stoppedTasks.push(taskId);
260
+ }
261
+
262
+ async setPermissionMode(mode: ClaudePermissionMode): Promise<void> {
263
+ this.modeChanges.push(mode);
264
+ this.toMode(mode);
265
+ }
266
+
267
+ /** The mode changes without Moxxy asking (another client, Claude itself); Claude reports it as it does any change. */
268
+ changeModeElsewhere(mode: ClaudePermissionMode): void {
269
+ this.toMode(mode);
270
+ }
271
+
272
+ private toMode(mode: ClaudePermissionMode): void {
273
+ this.permissionMode = mode;
274
+ // Claude Code 2.1 reports every change of mode with a status message, also one Moxxy asked for.
275
+ this.statuses.push({ type: 'system', subtype: 'status', status: null, permissionMode: mode, session_id: this.sessionId } as ClaudeMessage);
276
+ }
277
+
278
+ async supportedCommands(): Promise<ClaudeSlashCommand[]> {
279
+ return [
280
+ { name: 'compact', description: 'Clear the conversation history but keep a summary', argumentHint: '', builtin: true },
281
+ ...this.ownSkills().map((name) => ({ name, description: `The person's ${name}`, argumentHint: '' })),
282
+ ];
283
+ }
284
+
285
+ async supportedModels(): Promise<ClaudeModelInfo[]> {
286
+ const models = this.models();
287
+ if (models instanceof Error) throw models;
288
+ return [...models];
289
+ }
290
+
291
+ async mcpServerStatus(): Promise<ClaudeMcpServerStatus[]> {
292
+ return [...Object.keys(this.options.mcpServers ?? {}), ...this.ownMcpServers()].map((name) => ({ name, status: 'connected' }));
293
+ }
294
+
295
+ async setModel(model?: string): Promise<void> {
296
+ if (model) this.modelChanges.push(model);
297
+ }
298
+
299
+ close(): void {
300
+ this.closed = true;
301
+ this.stop.abort();
302
+ }
303
+
304
+ result(subtype: string, isError: boolean, extra: Record<string, unknown> = {}): ClaudeMessage {
305
+ return {
306
+ type: 'result',
307
+ subtype,
308
+ is_error: isError,
309
+ session_id: this.sessionId,
310
+ usage: { input_tokens: 3, output_tokens: 7, cache_read_input_tokens: 100 },
311
+ origin: { kind: 'human' },
312
+ ...extra,
313
+ } as ClaudeMessage;
314
+ }
315
+
316
+ private turn(message: ClaudeUserMessage): FakeTurn {
317
+ const content = message.message.content;
318
+ const text = typeof content === 'string' ? content : content.flatMap((b) => (b.type === 'text' ? [b.text] : [])).join('\n');
319
+ return {
320
+ text,
321
+ content,
322
+ query: this,
323
+ canUseTool: (name, input, toolUseID, extra) => {
324
+ const ask = this.options.canUseTool;
325
+ if (!ask) throw new Error('Claude was started without canUseTool');
326
+ return ask(name, input, { signal: this.stop.signal, toolUseID, ...(extra ?? {}) });
327
+ },
328
+ preToolUse: async (name, input, toolUseID, agentId) => {
329
+ let out: ClaudePreToolUseOutput = {};
330
+ for (const matcher of this.options.hooks?.PreToolUse ?? []) {
331
+ for (const hook of matcher.hooks) {
332
+ const verdict = await hook({ hook_event_name: 'PreToolUse', tool_name: name, tool_input: input, tool_use_id: toolUseID, ...(agentId ? { agent_id: agentId } : {}) }, toolUseID, {
333
+ signal: this.stop.signal,
334
+ });
335
+ if (verdict.hookSpecificOutput) out = verdict;
336
+ }
337
+ }
338
+ return out;
339
+ },
340
+ callMoxxyTool: async (name, args) => {
341
+ await this.reading;
342
+ // A tool Moxxy lends behind its catalog is run the way the model runs it: through call_tool.
343
+ const direct = this.moxxyTools.includes(name);
344
+ if (!direct && !this.moxxyTools.includes('call_tool')) throw new Error(`Claude has no tool mcp__moxxy__${name}; it read ${JSON.stringify(this.moxxyTools)}`);
345
+ const client = await this.moxxyClient();
346
+ const result = await client.callTool(direct ? { name, arguments: args } : { name: 'call_tool', arguments: { name, arguments: args } });
347
+ return { content: result.content, ...(result.isError ? { isError: true } : {}) };
348
+ },
349
+ };
350
+ }
351
+
352
+ private async readMoxxyTools(): Promise<void> {
353
+ const client = await this.moxxyClient();
354
+ const read = () =>
355
+ (this.reading = client.listTools().then(({ tools }) => {
356
+ this.moxxyTools = tools.map((tool) => tool.name);
357
+ }));
358
+ client.setNotificationHandler(ToolListChangedNotificationSchema, read);
359
+ await read();
360
+ }
361
+
362
+ /** Connect to Moxxy's MCP server the way Claude does, from the options Moxxy passed. */
363
+ async moxxyClient(): Promise<Client> {
364
+ if (this.mcp) return this.mcp;
365
+ const server = this.options.mcpServers?.moxxy;
366
+ if (!server) throw new Error('Moxxy passed no MCP server');
367
+ const client = new Client({ name: 'claude-code', version: '2.1.296' });
368
+ await client.connect(new StreamableHTTPClientTransport(new URL(server.url), { requestInit: { headers: server.headers } }));
369
+ this.mcp = client;
370
+ return client;
371
+ }
372
+
373
+ private userMessage(text: string): ClaudeUserMessage {
374
+ return { type: 'user', message: { role: 'user', content: text }, parent_tool_use_id: null, origin: { kind: 'human' } };
375
+ }
376
+ }
@@ -0,0 +1,43 @@
1
+ {
2
+ "source": "@anthropic-ai/claude-agent-sdk 0.3.296, SDKMessage (type, and subtype for system messages)",
3
+ "messages": [
4
+ "assistant",
5
+ "auth_status",
6
+ "conversation_reset",
7
+ "prompt_suggestion",
8
+ "rate_limit_event",
9
+ "result",
10
+ "stream_event",
11
+ "system/api_retry",
12
+ "system/background_tasks_changed",
13
+ "system/commands_changed",
14
+ "system/compact_boundary",
15
+ "system/control_request_progress",
16
+ "system/elicitation_complete",
17
+ "system/files_persisted",
18
+ "system/hook_progress",
19
+ "system/hook_response",
20
+ "system/hook_started",
21
+ "system/informational",
22
+ "system/init",
23
+ "system/local_command_output",
24
+ "system/memory_recall",
25
+ "system/mirror_error",
26
+ "system/model_refusal_fallback",
27
+ "system/model_refusal_no_fallback",
28
+ "system/notification",
29
+ "system/permission_denied",
30
+ "system/plugin_install",
31
+ "system/session_state_changed",
32
+ "system/status",
33
+ "system/task_notification",
34
+ "system/task_progress",
35
+ "system/task_started",
36
+ "system/task_updated",
37
+ "system/thinking_tokens",
38
+ "system/worker_shutting_down",
39
+ "tool_progress",
40
+ "tool_use_summary",
41
+ "user"
42
+ ]
43
+ }
@@ -0,0 +1,218 @@
1
+ {
2
+ "recordedFrom": "Claude Agent SDK 0.3.296 supportedModels(), claude.ai sign-in, 2026-10-16",
3
+ "models": [
4
+ {
5
+ "value": "default",
6
+ "resolvedModel": "claude-opus-5-5",
7
+ "displayName": "Default (recommended)",
8
+ "description": "Opus 5.5 \u00b7 Best for everyday, complex tasks",
9
+ "supportsEffort": true,
10
+ "supportedEffortLevels": [
11
+ "low",
12
+ "medium",
13
+ "high",
14
+ "xhigh",
15
+ "max"
16
+ ],
17
+ "supportsAdaptiveThinking": true,
18
+ "supportsFastMode": true,
19
+ "supportsAutoMode": true,
20
+ "supportsThinkingOff": false
21
+ },
22
+ {
23
+ "value": "opus",
24
+ "resolvedModel": "claude-opus-5-5",
25
+ "displayName": "Opus 5.5",
26
+ "description": "For complex work and everyday tasks",
27
+ "supportsEffort": true,
28
+ "supportedEffortLevels": [
29
+ "low",
30
+ "medium",
31
+ "high",
32
+ "xhigh",
33
+ "max"
34
+ ],
35
+ "supportsAdaptiveThinking": true,
36
+ "supportsFastMode": true,
37
+ "supportsAutoMode": true,
38
+ "supportsThinkingOff": false
39
+ },
40
+ {
41
+ "value": "sonnet",
42
+ "resolvedModel": "claude-sonnet-5-5",
43
+ "displayName": "Sonnet 5.5",
44
+ "description": "Most efficient for simpler tasks",
45
+ "supportsEffort": true,
46
+ "supportedEffortLevels": [
47
+ "low",
48
+ "medium",
49
+ "high",
50
+ "xhigh",
51
+ "max"
52
+ ],
53
+ "supportsAdaptiveThinking": true,
54
+ "supportsAutoMode": true,
55
+ "supportsThinkingOff": false
56
+ },
57
+ {
58
+ "value": "fable",
59
+ "resolvedModel": "claude-fable-5-1",
60
+ "displayName": "Fable 5.1",
61
+ "description": "For your toughest challenges",
62
+ "supportsEffort": true,
63
+ "supportedEffortLevels": [
64
+ "low",
65
+ "medium",
66
+ "high",
67
+ "xhigh",
68
+ "max"
69
+ ],
70
+ "supportsAdaptiveThinking": true,
71
+ "supportsAutoMode": true,
72
+ "supportsThinkingOff": false
73
+ },
74
+ {
75
+ "value": "haiku",
76
+ "resolvedModel": "claude-haiku-5-5",
77
+ "displayName": "Haiku 5.5",
78
+ "description": "Fastest for quick answers",
79
+ "supportsEffort": true,
80
+ "supportedEffortLevels": [
81
+ "low",
82
+ "medium",
83
+ "high",
84
+ "xhigh",
85
+ "max"
86
+ ],
87
+ "supportsAdaptiveThinking": true,
88
+ "supportsAutoMode": true,
89
+ "supportsThinkingOff": false
90
+ },
91
+ {
92
+ "value": "claude-haiku-4-5-20251001",
93
+ "resolvedModel": "claude-haiku-4-5-20251001",
94
+ "displayName": "Haiku 4.5",
95
+ "description": "Fastest for quick answers",
96
+ "supportsThinkingOff": true
97
+ },
98
+ {
99
+ "value": "claude-sonnet-5",
100
+ "resolvedModel": "claude-sonnet-5",
101
+ "displayName": "Sonnet 5",
102
+ "description": "Efficient for routine tasks",
103
+ "supportsEffort": true,
104
+ "supportedEffortLevels": [
105
+ "low",
106
+ "medium",
107
+ "high",
108
+ "xhigh",
109
+ "max"
110
+ ],
111
+ "supportsAdaptiveThinking": true,
112
+ "supportsAutoMode": true,
113
+ "supportsThinkingOff": true
114
+ },
115
+ {
116
+ "value": "claude-opus-5",
117
+ "resolvedModel": "claude-opus-5",
118
+ "displayName": "Opus 5",
119
+ "description": "Best for everyday, complex tasks",
120
+ "supportsEffort": true,
121
+ "supportedEffortLevels": [
122
+ "low",
123
+ "medium",
124
+ "high",
125
+ "xhigh",
126
+ "max"
127
+ ],
128
+ "supportsAdaptiveThinking": true,
129
+ "supportsFastMode": true,
130
+ "supportsAutoMode": true,
131
+ "supportsThinkingOff": true
132
+ },
133
+ {
134
+ "value": "claude-fable-5",
135
+ "resolvedModel": "claude-fable-5",
136
+ "displayName": "Fable 5",
137
+ "description": "Most capable for your hardest and longest-running tasks",
138
+ "supportsEffort": true,
139
+ "supportedEffortLevels": [
140
+ "low",
141
+ "medium",
142
+ "high",
143
+ "xhigh",
144
+ "max"
145
+ ],
146
+ "supportsAdaptiveThinking": true,
147
+ "supportsAutoMode": true,
148
+ "supportsThinkingOff": false
149
+ },
150
+ {
151
+ "value": "claude-opus-4-8",
152
+ "resolvedModel": "claude-opus-4-8",
153
+ "displayName": "Opus 4.8",
154
+ "description": "Best for everyday, complex tasks",
155
+ "supportsEffort": true,
156
+ "supportedEffortLevels": [
157
+ "low",
158
+ "medium",
159
+ "high",
160
+ "xhigh",
161
+ "max"
162
+ ],
163
+ "supportsAdaptiveThinking": true,
164
+ "supportsFastMode": true,
165
+ "supportsAutoMode": true,
166
+ "supportsThinkingOff": true
167
+ },
168
+ {
169
+ "value": "claude-opus-4-7",
170
+ "resolvedModel": "claude-opus-4-7",
171
+ "displayName": "Opus 4.7",
172
+ "description": "Best for everyday, complex tasks",
173
+ "supportsEffort": true,
174
+ "supportedEffortLevels": [
175
+ "low",
176
+ "medium",
177
+ "high",
178
+ "xhigh",
179
+ "max"
180
+ ],
181
+ "supportsAdaptiveThinking": true,
182
+ "supportsAutoMode": true,
183
+ "supportsThinkingOff": true
184
+ },
185
+ {
186
+ "value": "claude-opus-4-6",
187
+ "resolvedModel": "claude-opus-4-6",
188
+ "displayName": "Opus 4.6",
189
+ "description": "Best for everyday, complex tasks",
190
+ "supportsEffort": true,
191
+ "supportedEffortLevels": [
192
+ "low",
193
+ "medium",
194
+ "high",
195
+ "max"
196
+ ],
197
+ "supportsAdaptiveThinking": true,
198
+ "supportsAutoMode": true,
199
+ "supportsThinkingOff": true
200
+ },
201
+ {
202
+ "value": "claude-sonnet-4-6",
203
+ "resolvedModel": "claude-sonnet-4-6",
204
+ "displayName": "Sonnet 4.6",
205
+ "description": "Efficient for routine tasks",
206
+ "supportsEffort": true,
207
+ "supportedEffortLevels": [
208
+ "low",
209
+ "medium",
210
+ "high",
211
+ "max"
212
+ ],
213
+ "supportsAdaptiveThinking": true,
214
+ "supportsAutoMode": true,
215
+ "supportsThinkingOff": true
216
+ }
217
+ ]
218
+ }
@@ -0,0 +1,49 @@
1
+ /** The plugin entry: the conversation's live Claude ends when the conversation does. */
2
+ import { describe, expect, it } from 'vitest';
3
+ import { collectTurn } from '@moxxy/core';
4
+ import { assertDefined } from '@moxxy/sdk';
5
+ import { createFakeSession } from '@moxxy/testing';
6
+ import { defaultModePlugin } from '@moxxy/mode-default';
7
+ import { ClaudeAgentProvider, claudeSessions, claudeCodePlugin } from './index.js';
8
+ import { FakeClaude, assistantText } from './fake-claude.testkit.js';
9
+
10
+ describe('the Claude plugin', () => {
11
+ it('closes the conversation running Claude when the conversation shuts down', async () => {
12
+ const claude = new FakeClaude(async function* () {
13
+ yield assistantText('hi');
14
+ });
15
+ const provider = new ClaudeAgentProvider({ executable: '/usr/local/bin/claude', loadSdk: async () => claude });
16
+ const session = createFakeSession({ provider, plugins: [defaultModePlugin] });
17
+ await collectTurn(session, 'hello');
18
+ expect(claudeSessions().size).toBe(1);
19
+
20
+ const onShutdown = claudeCodePlugin.hooks?.onShutdown;
21
+ assertDefined(onShutdown, 'the plugin onShutdown hook');
22
+ await onShutdown(session.appContext());
23
+
24
+ expect(claude.last.closed).toBe(true);
25
+ expect(claudeSessions().size).toBe(0);
26
+ await session.close();
27
+ });
28
+
29
+ it('starts a new conversation on Haiku 5.5 while the person chose no default model', async () => {
30
+ const { claudeCodeProviderDef } = await import('./index.js');
31
+ const provider = new ClaudeAgentProvider({
32
+ executable: '/usr/local/bin/claude',
33
+ loadSdk: async () => new FakeClaude(async function* () {}),
34
+ });
35
+ const session = createFakeSession({ provider, plugins: [defaultModePlugin] });
36
+
37
+ expect(session.getInfo().defaultModel).toBe('claude-haiku-5-5');
38
+ expect(claudeCodeProviderDef.starterModel).toBe('claude-haiku-5-5');
39
+ await session.close();
40
+ });
41
+
42
+ it("lists the models the person's Claude offers, and still knows Haiku 5.5 when Claude is not asked", async () => {
43
+ const { claudeCodeProviderDef, claudeCodeModels } = await import('./index.js');
44
+
45
+ expect(typeof claudeCodeProviderDef.agentCli?.models).toBe('function');
46
+ expect(claudeCodeModels.map((m) => m.id)).toContain('claude-haiku-5-5');
47
+ expect(claudeCodeModels.map((m) => m.id)).not.toContain('claude-haiku-4-5');
48
+ });
49
+ });