fix: add debug logging, fix non-ascii dash in system prompt
This commit is contained in:
+25
-4
@@ -13,6 +13,9 @@ interface CliJsonResult {
|
||||
|
||||
function runClaude(args: string[], cwd: string): Promise<string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
console.log(`[claude] Running: npx claude-code ${args.join(" ")}`);
|
||||
console.log(`[claude] CWD: ${cwd}`);
|
||||
|
||||
const proc = spawn("npx", ["--yes", "@anthropic-ai/claude-code", ...args], {
|
||||
cwd,
|
||||
shell: true,
|
||||
@@ -31,6 +34,10 @@ function runClaude(args: string[], cwd: string): Promise<string> {
|
||||
});
|
||||
|
||||
proc.on("close", (code: number | null) => {
|
||||
console.log(`[claude] Exit code: ${code}`);
|
||||
console.log(`[claude] Stdout length: ${stdout.length}`);
|
||||
if (stderr) console.log(`[claude] Stderr: ${stderr.slice(0, 500)}`);
|
||||
|
||||
if (code !== 0 && !stdout) {
|
||||
reject(new Error(stderr || `claude exited with code ${code}`));
|
||||
} else {
|
||||
@@ -38,11 +45,14 @@ function runClaude(args: string[], cwd: string): Promise<string> {
|
||||
}
|
||||
});
|
||||
|
||||
proc.on("error", reject);
|
||||
proc.on("error", (err) => {
|
||||
console.error(`[claude] Spawn error:`, err);
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
const APPEND_PROMPT = "Always respond in Russian. You are a helpful coding assistant connected via Telegram. Engage fully with user requests — analyze, suggest, implement. Never ask the user to repeat or clarify when the request is clear enough to act on.";
|
||||
const APPEND_PROMPT = "Always respond in Russian. You are a helpful coding assistant connected via Telegram. Engage fully with user requests - analyze, suggest, implement. Never ask the user to repeat or clarify when the request is clear enough to act on.";
|
||||
|
||||
export class ClaudeService {
|
||||
async createSession(prompt: string, cwd: string): Promise<ClaudeResult> {
|
||||
@@ -51,7 +61,11 @@ export class ClaudeService {
|
||||
cwd,
|
||||
);
|
||||
|
||||
const parsed = JSON.parse(raw.trim().split("\n").pop()!) as CliJsonResult;
|
||||
const lastLine = raw.trim().split("\n").pop()!;
|
||||
console.log(`[claude] createSession raw last line (first 300 chars): ${lastLine.slice(0, 300)}`);
|
||||
const parsed = JSON.parse(lastLine) as CliJsonResult;
|
||||
console.log(`[claude] createSession result: "${parsed.result?.slice(0, 200)}"`);
|
||||
console.log(`[claude] createSession session_id: ${parsed.session_id}`);
|
||||
|
||||
return {
|
||||
sessionId: parsed.session_id ?? "",
|
||||
@@ -60,12 +74,19 @@ export class ClaudeService {
|
||||
}
|
||||
|
||||
async sendMessage(prompt: string, sessionId: string, cwd: string): Promise<string> {
|
||||
console.log(`[claude] sendMessage prompt: "${prompt.slice(0, 100)}"`);
|
||||
console.log(`[claude] sendMessage sessionId: ${sessionId}`);
|
||||
|
||||
const raw = await runClaude(
|
||||
["-p", prompt, "--output-format", "json", "--resume", sessionId, "--dangerously-skip-permissions", "--append-system-prompt", APPEND_PROMPT],
|
||||
cwd,
|
||||
);
|
||||
|
||||
const parsed = JSON.parse(raw.trim().split("\n").pop()!) as CliJsonResult;
|
||||
const lastLine = raw.trim().split("\n").pop()!;
|
||||
console.log(`[claude] sendMessage raw last line (first 300 chars): ${lastLine.slice(0, 300)}`);
|
||||
const parsed = JSON.parse(lastLine) as CliJsonResult;
|
||||
console.log(`[claude] sendMessage result: "${parsed.result?.slice(0, 200)}"`);
|
||||
|
||||
return parsed.result ?? "";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user