@anthropic-ai/claude-code 1.0.43 → 1.0.45
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.
- package/cli.js +907 -854
- package/package.json +1 -1
- package/sdk.mjs +192 -30
- package/vendor/claude-code.vsix +0 -0
package/package.json
CHANGED
package/sdk.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// (c) Anthropic PBC. All rights reserved. Use is subject to Anthropic's Commercial Terms of Service (https://www.anthropic.com/legal/commercial-terms).
|
|
2
2
|
|
|
3
|
-
// Version: 1.0.
|
|
3
|
+
// Version: 1.0.45
|
|
4
4
|
|
|
5
5
|
// src/entrypoints/sdk.ts
|
|
6
6
|
import { spawn } from "child_process";
|
|
@@ -8,9 +8,85 @@ import { join } from "path";
|
|
|
8
8
|
import { fileURLToPath } from "url";
|
|
9
9
|
import { createInterface } from "readline";
|
|
10
10
|
import { existsSync } from "fs";
|
|
11
|
+
|
|
12
|
+
// src/utils/stream.ts
|
|
13
|
+
class Stream {
|
|
14
|
+
returned;
|
|
15
|
+
queue = [];
|
|
16
|
+
readResolve;
|
|
17
|
+
readReject;
|
|
18
|
+
isDone = false;
|
|
19
|
+
hasError;
|
|
20
|
+
started = false;
|
|
21
|
+
constructor(returned) {
|
|
22
|
+
this.returned = returned;
|
|
23
|
+
}
|
|
24
|
+
[Symbol.asyncIterator]() {
|
|
25
|
+
if (this.started) {
|
|
26
|
+
throw new Error("Stream can only be iterated once");
|
|
27
|
+
}
|
|
28
|
+
this.started = true;
|
|
29
|
+
return this;
|
|
30
|
+
}
|
|
31
|
+
next() {
|
|
32
|
+
if (this.queue.length > 0) {
|
|
33
|
+
return Promise.resolve({
|
|
34
|
+
done: false,
|
|
35
|
+
value: this.queue.shift()
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
if (this.isDone) {
|
|
39
|
+
return Promise.resolve({ done: true, value: undefined });
|
|
40
|
+
}
|
|
41
|
+
if (this.hasError) {
|
|
42
|
+
return Promise.reject(this.hasError);
|
|
43
|
+
}
|
|
44
|
+
return new Promise((resolve, reject) => {
|
|
45
|
+
this.readResolve = resolve;
|
|
46
|
+
this.readReject = reject;
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
enqueue(value) {
|
|
50
|
+
if (this.readResolve) {
|
|
51
|
+
const resolve = this.readResolve;
|
|
52
|
+
this.readResolve = undefined;
|
|
53
|
+
this.readReject = undefined;
|
|
54
|
+
resolve({ done: false, value });
|
|
55
|
+
} else {
|
|
56
|
+
this.queue.push(value);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
done() {
|
|
60
|
+
this.isDone = true;
|
|
61
|
+
if (this.readResolve) {
|
|
62
|
+
const resolve = this.readResolve;
|
|
63
|
+
this.readResolve = undefined;
|
|
64
|
+
this.readReject = undefined;
|
|
65
|
+
resolve({ done: true, value: undefined });
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
error(error) {
|
|
69
|
+
this.hasError = error;
|
|
70
|
+
if (this.readReject) {
|
|
71
|
+
const reject = this.readReject;
|
|
72
|
+
this.readResolve = undefined;
|
|
73
|
+
this.readReject = undefined;
|
|
74
|
+
reject(error);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return() {
|
|
78
|
+
this.isDone = true;
|
|
79
|
+
if (this.returned) {
|
|
80
|
+
this.returned();
|
|
81
|
+
}
|
|
82
|
+
return Promise.resolve({ done: true, value: undefined });
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// src/entrypoints/sdk.ts
|
|
11
87
|
var __filename2 = fileURLToPath(import.meta.url);
|
|
12
88
|
var __dirname2 = join(__filename2, "..");
|
|
13
|
-
|
|
89
|
+
function query({
|
|
14
90
|
prompt,
|
|
15
91
|
options: {
|
|
16
92
|
abortController = new AbortController,
|
|
@@ -29,7 +105,8 @@ async function* query({
|
|
|
29
105
|
continue: continueConversation,
|
|
30
106
|
resume,
|
|
31
107
|
model,
|
|
32
|
-
fallbackModel
|
|
108
|
+
fallbackModel,
|
|
109
|
+
strictMcpConfig
|
|
33
110
|
} = {}
|
|
34
111
|
}) {
|
|
35
112
|
if (!process.env.CLAUDE_CODE_ENTRYPOINT) {
|
|
@@ -59,6 +136,9 @@ async function* query({
|
|
|
59
136
|
if (mcpServers && Object.keys(mcpServers).length > 0) {
|
|
60
137
|
args.push("--mcp-config", JSON.stringify({ mcpServers }));
|
|
61
138
|
}
|
|
139
|
+
if (strictMcpConfig) {
|
|
140
|
+
args.push("--strict-mcp-config");
|
|
141
|
+
}
|
|
62
142
|
if (permissionMode !== "default") {
|
|
63
143
|
args.push("--permission-mode", permissionMode);
|
|
64
144
|
}
|
|
@@ -85,10 +165,12 @@ async function* query({
|
|
|
85
165
|
...process.env
|
|
86
166
|
}
|
|
87
167
|
});
|
|
168
|
+
let childStdin;
|
|
88
169
|
if (typeof prompt === "string") {
|
|
89
170
|
child.stdin.end();
|
|
90
171
|
} else {
|
|
91
172
|
streamToStdin(prompt, child.stdin, abortController);
|
|
173
|
+
childStdin = child.stdin;
|
|
92
174
|
}
|
|
93
175
|
if (process.env.DEBUG) {
|
|
94
176
|
child.stderr.on("data", (data) => {
|
|
@@ -102,44 +184,124 @@ async function* query({
|
|
|
102
184
|
};
|
|
103
185
|
abortController.signal.addEventListener("abort", cleanup);
|
|
104
186
|
process.on("exit", cleanup);
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
if (code !== 0) {
|
|
116
|
-
reject(new Error(`Claude Code process exited with code ${code}`));
|
|
117
|
-
} else {
|
|
118
|
-
resolve();
|
|
119
|
-
}
|
|
120
|
-
});
|
|
187
|
+
const processExitPromise = new Promise((resolve) => {
|
|
188
|
+
child.on("close", (code) => {
|
|
189
|
+
if (abortController.signal.aborted) {
|
|
190
|
+
query2.setError(new AbortError("Claude Code process aborted by user"));
|
|
191
|
+
}
|
|
192
|
+
if (code !== 0) {
|
|
193
|
+
query2.setError(new Error(`Claude Code process exited with code ${code}`));
|
|
194
|
+
} else {
|
|
195
|
+
resolve();
|
|
196
|
+
}
|
|
121
197
|
});
|
|
122
|
-
|
|
198
|
+
});
|
|
199
|
+
const query2 = new Query(childStdin, child.stdout, processExitPromise);
|
|
200
|
+
child.on("error", (error) => {
|
|
201
|
+
if (abortController.signal.aborted) {
|
|
202
|
+
query2.setError(new AbortError("Claude Code process aborted by user"));
|
|
203
|
+
} else {
|
|
204
|
+
query2.setError(new Error(`Failed to spawn Claude Code process: ${error.message}`));
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
processExitPromise.finally(() => {
|
|
208
|
+
cleanup();
|
|
209
|
+
abortController.signal.removeEventListener("abort", cleanup);
|
|
210
|
+
if (process.env.CLAUDE_SDK_MCP_SERVERS) {
|
|
211
|
+
delete process.env.CLAUDE_SDK_MCP_SERVERS;
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
return query2;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
class Query {
|
|
218
|
+
childStdin;
|
|
219
|
+
childStdout;
|
|
220
|
+
processExitPromise;
|
|
221
|
+
pendingControlResponses = new Map;
|
|
222
|
+
sdkMessages;
|
|
223
|
+
inputStream = new Stream;
|
|
224
|
+
constructor(childStdin, childStdout, processExitPromise) {
|
|
225
|
+
this.childStdin = childStdin;
|
|
226
|
+
this.childStdout = childStdout;
|
|
227
|
+
this.processExitPromise = processExitPromise;
|
|
228
|
+
this.readMessages();
|
|
229
|
+
this.sdkMessages = this.readSdkMessages();
|
|
230
|
+
}
|
|
231
|
+
setError(error) {
|
|
232
|
+
this.inputStream.error(error);
|
|
233
|
+
}
|
|
234
|
+
next(...[value]) {
|
|
235
|
+
return this.sdkMessages.next(...[value]);
|
|
236
|
+
}
|
|
237
|
+
return(value) {
|
|
238
|
+
return this.sdkMessages.return(value);
|
|
239
|
+
}
|
|
240
|
+
throw(e) {
|
|
241
|
+
return this.sdkMessages.throw(e);
|
|
242
|
+
}
|
|
243
|
+
[Symbol.asyncIterator]() {
|
|
244
|
+
return this.sdkMessages;
|
|
245
|
+
}
|
|
246
|
+
[Symbol.asyncDispose]() {
|
|
247
|
+
return this.sdkMessages[Symbol.asyncDispose]();
|
|
248
|
+
}
|
|
249
|
+
async readMessages() {
|
|
250
|
+
const rl = createInterface({ input: this.childStdout });
|
|
123
251
|
try {
|
|
124
252
|
for await (const line of rl) {
|
|
125
|
-
if (processError) {
|
|
126
|
-
throw processError;
|
|
127
|
-
}
|
|
128
253
|
if (line.trim()) {
|
|
129
|
-
|
|
254
|
+
const message = JSON.parse(line);
|
|
255
|
+
if (message.type === "control_response") {
|
|
256
|
+
const handler = this.pendingControlResponses.get(message.response.request_id);
|
|
257
|
+
if (handler) {
|
|
258
|
+
handler(message.response);
|
|
259
|
+
}
|
|
260
|
+
continue;
|
|
261
|
+
}
|
|
262
|
+
this.inputStream.enqueue(message);
|
|
130
263
|
}
|
|
131
264
|
}
|
|
265
|
+
await this.processExitPromise;
|
|
266
|
+
} catch (error) {
|
|
267
|
+
this.inputStream.error(error);
|
|
132
268
|
} finally {
|
|
269
|
+
this.inputStream.done();
|
|
133
270
|
rl.close();
|
|
134
271
|
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
if (process.env.CLAUDE_SDK_MCP_SERVERS) {
|
|
140
|
-
delete process.env.CLAUDE_SDK_MCP_SERVERS;
|
|
272
|
+
}
|
|
273
|
+
async* readSdkMessages() {
|
|
274
|
+
for await (const message of this.inputStream) {
|
|
275
|
+
yield message;
|
|
141
276
|
}
|
|
142
277
|
}
|
|
278
|
+
async interrupt() {
|
|
279
|
+
if (!this.childStdin) {
|
|
280
|
+
throw new Error("Interrupt requires --input-format stream-json");
|
|
281
|
+
}
|
|
282
|
+
await this.request({
|
|
283
|
+
subtype: "interrupt"
|
|
284
|
+
}, this.childStdin);
|
|
285
|
+
}
|
|
286
|
+
request(request, childStdin) {
|
|
287
|
+
const requestId = Math.random().toString(36).substring(2, 15);
|
|
288
|
+
const sdkRequest = {
|
|
289
|
+
request_id: requestId,
|
|
290
|
+
type: "control_request",
|
|
291
|
+
request
|
|
292
|
+
};
|
|
293
|
+
return new Promise((resolve, reject) => {
|
|
294
|
+
this.pendingControlResponses.set(requestId, (response) => {
|
|
295
|
+
if (response.subtype === "success") {
|
|
296
|
+
resolve(response);
|
|
297
|
+
} else {
|
|
298
|
+
reject(new Error(response.error));
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
childStdin.write(JSON.stringify(sdkRequest) + `
|
|
302
|
+
`);
|
|
303
|
+
});
|
|
304
|
+
}
|
|
143
305
|
}
|
|
144
306
|
async function streamToStdin(stream, stdin, abortController) {
|
|
145
307
|
for await (const message of stream) {
|
package/vendor/claude-code.vsix
CHANGED
|
Binary file
|