mirror of
https://github.com/wu736139669/hapi.git
synced 2026-08-05 06:24:37 +00:00
@@ -8,6 +8,7 @@ import { systemPrompt } from "./utils/systemPrompt";
|
||||
import { withBunRuntimeEnv } from "@/utils/bunRuntime";
|
||||
import { spawnWithAbort } from "@/utils/spawnWithAbort";
|
||||
import { getHapiBlobsDir } from "@/constants/uploadPaths";
|
||||
import { stripNewlinesForWindowsShellArg } from "@/utils/shellEscape";
|
||||
|
||||
export async function claudeLocal(opts: {
|
||||
abort: AbortSignal,
|
||||
@@ -50,7 +51,7 @@ export async function claudeLocal(opts: {
|
||||
args.push('--resume', startFrom);
|
||||
}
|
||||
|
||||
args.push('--append-system-prompt', systemPrompt);
|
||||
args.push('--append-system-prompt', stripNewlinesForWindowsShellArg(systemPrompt));
|
||||
|
||||
const cleanupMcpConfig = appendMcpConfigArg(args, opts.mcpServers, {
|
||||
baseDir: projectDir
|
||||
|
||||
@@ -25,6 +25,7 @@ import {
|
||||
import { getDefaultClaudeCodePath, logDebug, streamToStdin } from './utils'
|
||||
import { withBunRuntimeEnv } from '@/utils/bunRuntime'
|
||||
import { killProcessByChildProcess } from '@/utils/process'
|
||||
import { stripNewlinesForWindowsShellArg } from '@/utils/shellEscape'
|
||||
import type { Writable } from 'node:stream'
|
||||
import { logger } from '@/ui/logger'
|
||||
import { appendMcpConfigArg } from '../utils/mcpConfig'
|
||||
@@ -289,8 +290,8 @@ export function query(config: {
|
||||
const args = ['--output-format', 'stream-json', '--verbose']
|
||||
let cleanupMcpConfig: (() => void) | null = null
|
||||
|
||||
if (customSystemPrompt) args.push('--system-prompt', customSystemPrompt)
|
||||
if (appendSystemPrompt) args.push('--append-system-prompt', appendSystemPrompt)
|
||||
if (customSystemPrompt) args.push('--system-prompt', stripNewlinesForWindowsShellArg(customSystemPrompt))
|
||||
if (appendSystemPrompt) args.push('--append-system-prompt', stripNewlinesForWindowsShellArg(appendSystemPrompt))
|
||||
if (maxTurns) args.push('--max-turns', maxTurns.toString())
|
||||
if (model) args.push('--model', model)
|
||||
if (canCallTool) {
|
||||
@@ -317,7 +318,7 @@ export function query(config: {
|
||||
|
||||
// Handle prompt input
|
||||
if (typeof prompt === 'string') {
|
||||
args.push('--print', prompt.trim())
|
||||
args.push('--print', stripNewlinesForWindowsShellArg(prompt.trim()))
|
||||
} else {
|
||||
args.push('--input-format', 'stream-json')
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
/**
|
||||
* Strip newlines when passing args through Windows cmd.exe.
|
||||
* cmd.exe treats CR/LF as command separators and truncates multiline args.
|
||||
*/
|
||||
export function stripNewlinesForWindowsShellArg(value: string): string {
|
||||
if (process.platform !== 'win32') {
|
||||
return value;
|
||||
}
|
||||
return value.replace(/\r?\n/g, ' ');
|
||||
}
|
||||
Reference in New Issue
Block a user