-
Notifications
You must be signed in to change notification settings - Fork 24
fix: add shell:true for Windows .cmd file spawn #9
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -144,10 +144,9 @@ export class ClaudeCodeLanguageModel implements LanguageModelV2 { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| content: [{ type: "text", text }] as any, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| finishReason: "stop", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| usage: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| inputTokens: 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| outputTokens: 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| totalTokens: 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| inputTokens: { total: 0, noCache: 0, cacheRead: undefined, cacheWrite: undefined }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| outputTokens: { total: 0, text: undefined, reasoning: undefined }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } as unknown as LanguageModelV2Usage, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| request: { body: { text: "" } }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| response: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| id: generateId(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -185,6 +184,7 @@ export class ClaudeCodeLanguageModel implements LanguageModelV2 { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| skipPermissions: this.config.skipPermissions !== false, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| includeSessionId: false, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| model: this.modelId, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mcpConfigPath: this.config.mcpConfigPath, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| log.info("doGenerate starting", { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -200,6 +200,7 @@ export class ClaudeCodeLanguageModel implements LanguageModelV2 { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const proc = spawn(this.config.cliPath, cliArgs, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cwd, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| stdio: ["pipe", "pipe", "pipe"], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| shell: process.platform === "win32", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| env: { ...process.env, TERM: "xterm-256color" }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
200
to
206
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const proc = spawn(this.config.cliPath, cliArgs, { | |
| cwd, | |
| stdio: ["pipe", "pipe", "pipe"], | |
| shell: process.platform === "win32", | |
| env: { ...process.env, TERM: "xterm-256color" }, | |
| }) | |
| const isWindowsCmdShim = | |
| process.platform === "win32" && | |
| /\.(cmd|bat)$/i.test(this.config.cliPath) | |
| const escapeForCmdExe = (value: string): string => { | |
| const escapedForQuotes = value.replace(/"/g, '""') | |
| const escapedMetaChars = escapedForQuotes.replace( | |
| /([()%!^"<>&|])/g, | |
| "^$1", | |
| ) | |
| return `"${escapedMetaChars}"` | |
| } | |
| const proc = isWindowsCmdShim | |
| ? spawn(process.env.ComSpec ?? "cmd.exe", [ | |
| "/d", | |
| "/s", | |
| "/c", | |
| `${escapeForCmdExe(this.config.cliPath)} ${cliArgs | |
| .map((arg) => escapeForCmdExe(arg)) | |
| .join(" ")}`, | |
| ], { | |
| cwd, | |
| stdio: ["pipe", "pipe", "pipe"], | |
| shell: false, | |
| env: { ...process.env, TERM: "xterm-256color" }, | |
| }) | |
| : spawn(this.config.cliPath, cliArgs, { | |
| cwd, | |
| stdio: ["pipe", "pipe", "pipe"], | |
| shell: false, | |
| env: { ...process.env, TERM: "xterm-256color" }, | |
| }) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,6 +53,7 @@ export function spawnClaudeProcess( | |
| const proc = spawn(cliPath, cliArgs, { | ||
| cwd, | ||
| stdio: ["pipe", "pipe", "pipe"], | ||
| shell: process.platform === "win32", | ||
| env: { ...process.env, TERM: "xterm-256color" }, | ||
|
Comment on lines
53
to
57
|
||
| }) | ||
|
|
||
|
|
@@ -107,8 +108,9 @@ export function buildCliArgs(opts: { | |
| skipPermissions: boolean | ||
| includeSessionId?: boolean | ||
| model?: string | ||
| mcpConfigPath?: string | ||
| }): string[] { | ||
| const { sessionKey, skipPermissions, includeSessionId = true, model } = opts | ||
| const { sessionKey, skipPermissions, includeSessionId = true, model, mcpConfigPath } = opts | ||
| const args = [ | ||
| "--output-format", | ||
| "stream-json", | ||
|
|
@@ -132,6 +134,10 @@ export function buildCliArgs(opts: { | |
| args.push("--dangerously-skip-permissions") | ||
| } | ||
|
|
||
| if (mcpConfigPath) { | ||
| args.push("--mcp-config", mcpConfigPath) | ||
| } | ||
|
|
||
| return args | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
usageshape is being changed and then forced through withas unknown as LanguageModelV2Usage, which bypasses type safety and may break downstream consumers expecting the previous runtime shape. Prefer constructing aLanguageModelV2Usagevalue that type-checks without double-casting (or keep the prior shape) and ensure the change is intentional/documented since it’s outside the PR’s stated scope.