fix: add shell:true to spawn calls for cross-platform npx compatibility

This commit is contained in:
2026-06-15 11:42:31 +08:00
parent a34f3cf240
commit 525fa5ef8f

View File

@@ -63,6 +63,7 @@ function apiSavePlugin() {
const child = spawn('npx', args, {
env: { ...process.env, DEEPSEEK_API_KEY: apiKey || process.env.DEEPSEEK_API_KEY || '' },
timeout: 15000,
shell: true,
})
let stdout = ''
@@ -71,11 +72,11 @@ function apiSavePlugin() {
child.stdout.on('data', (d: Buffer) => stdout += d.toString())
child.stderr.on('data', (d: Buffer) => stderr += d.toString())
child.on('error', () => {
child.on('error', (err: any) => {
if (responded) return
responded = true
res.writeHead(503)
res.end(JSON.stringify({ error: 'opencode 未安装,请运行 npm install' }))
res.end(JSON.stringify({ error: err?.message || 'spawn failed' }))
})
child.on('close', async (code) => {
@@ -93,6 +94,7 @@ function apiSavePlugin() {
const listChild = spawn('npx', ['opencode', 'session', 'list', '--format', 'json', '--max-count', '1'], {
timeout: 5000,
env: { ...process.env, DEEPSEEK_API_KEY: apiKey || process.env.DEEPSEEK_API_KEY || '' },
shell: true,
})
let listOut = ''
listChild.stdout.on('data', (d: Buffer) => listOut += d.toString())
@@ -134,7 +136,7 @@ function apiSavePlugin() {
server.middlewares.use('/api/ai/sessions', (req: any, res: any) => {
if (req.method !== 'GET') { res.writeHead(405); res.end(); return }
try {
const child = spawn('npx', ['opencode', 'session', 'list', '--format', 'json'], { timeout: 5000 })
const child = spawn('npx', ['opencode', 'session', 'list', '--format', 'json'], { timeout: 5000, shell: true })
let stdout = ''
let responded = false
child.stdout.on('data', (d: Buffer) => stdout += d.toString())