Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/subprocess/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ import type {
import { isAssistantMessage, isResultMessage, isContentDelta } from "../types/claude-cli.js";
import type { ClaudeModel } from "../adapter/openai-to-cli.js";

const logger = {
info: (msg: string, ...args: any[]) => console.error(`[Subprocess] INFO: ${msg}`, ...args),
error: (msg: string, ...args: any[]) => console.error(`[Subprocess] ERROR: ${msg}`, ...args),
debug: (msg: string, ...args: any[]) => {
if (process.env.DEBUG) console.error(`[Subprocess] DEBUG: ${msg}`, ...args);
}
};

export interface SubprocessOptions {
model: ClaudeModel;
sessionId?: string;
Expand Down Expand Up @@ -86,12 +94,12 @@ export class ClaudeSubprocess extends EventEmitter {
this.process.stdin?.write(prompt);
this.process.stdin?.end();

console.error(`[Subprocess] Process spawned with PID: ${this.process.pid}`);
logger.info(`Process spawned with PID: ${this.process.pid}`);

// Parse JSON stream from stdout
this.process.stdout?.on("data", (chunk: Buffer) => {
const data = chunk.toString();
console.error(`[Subprocess] Received ${data.length} bytes of stdout`);
logger.debug(`Received ${data.length} bytes of stdout`);
this.buffer += data;
this.processBuffer();
});
Expand All @@ -102,13 +110,13 @@ export class ClaudeSubprocess extends EventEmitter {
if (errorText) {
// Don't emit as error unless it's actually an error
// Claude CLI may write debug info to stderr
console.error("[Subprocess stderr]:", errorText.slice(0, 200));
logger.error("stderr output:", errorText.slice(0, 200));
}
});

// Handle process close
this.process.on("close", (code) => {
console.error(`[Subprocess] Process closed with code: ${code}`);
logger.info(`Process closed with code: ${code}`);
this.clearTimeout();
// Process any remaining buffer
if (this.buffer.trim()) {
Expand Down