Fix log crash

This commit is contained in:
Colin McDonnell
2025-12-17 12:49:29 -08:00
parent 4826e9acb1
commit 2c92e27b4d
3 changed files with 46 additions and 13 deletions
+16 -5
View File
@@ -91167,6 +91167,7 @@ var gemini = agent({
log.info("\u{1F512} sandbox mode enabled: restricting to read-only operations");
}
let finalOutput2 = "";
let stdoutBuffer = "";
try {
const result = await spawn4({
cmd: "node",
@@ -91177,7 +91178,9 @@ var gemini = agent({
onStdout: async (chunk) => {
const text = chunk.toString();
finalOutput2 += text;
const lines = text.split("\n");
stdoutBuffer += text;
const lines = stdoutBuffer.split("\n");
stdoutBuffer = lines.pop() || "";
for (const line of lines) {
const trimmed = line.trim();
if (!trimmed) continue;
@@ -91189,7 +91192,7 @@ var gemini = agent({
await handler2(event);
}
} catch {
console.log("parse error", trimmed);
log.debug(`[gemini] non-JSON stdout line: ${trimmed.substring(0, 200)}`);
}
}
},
@@ -91300,6 +91303,7 @@ var opencode = agent({
let lastActivityTime = startTime;
let eventCount = 0;
let output = "";
let stdoutBuffer = "";
const result = await spawn4({
cmd: cliPath,
args: args3,
@@ -91309,11 +91313,11 @@ var opencode = agent({
// 10 minutes timeout to prevent infinite hangs
stdio: ["ignore", "pipe", "pipe"],
onStdout: async (chunk) => {
const parsed2 = JSON.parse(chunk);
log.debug(JSON.stringify(parsed2, null, 2));
const text = chunk.toString();
output += text;
const lines = text.split("\n");
stdoutBuffer += text;
const lines = stdoutBuffer.split("\n");
stdoutBuffer = lines.pop() || "";
for (const line of lines) {
const trimmed = line.trim();
if (!trimmed) {
@@ -91322,6 +91326,9 @@ var opencode = agent({
try {
const event = JSON.parse(trimmed);
eventCount++;
log.debug(
`\xBB event: type=${event.type} data=${JSON.stringify(event).substring(0, 300)}`
);
const timeSinceLastActivity = Date.now() - lastActivityTime;
if (timeSinceLastActivity > 1e4) {
const activeToolCalls = toolCallTimings.size;
@@ -91340,6 +91347,7 @@ var opencode = agent({
);
}
} catch {
log.debug(`\xBB non-JSON stdout line: ${trimmed.substring(0, 200)}`);
}
}
},
@@ -91507,6 +91515,9 @@ var messageHandlers4 = {
const parameters = event.part?.state?.input;
const status = event.part?.state?.status;
const output = event.part?.state?.output;
if (!toolName || !toolId) {
log.debug(`\xBB tool_use event missing toolName or toolId: ${JSON.stringify(event)}`);
}
if (toolName && toolId) {
if (stepHistory.length > 0) {
stepHistory[stepHistory.length - 1].toolCalls.push(toolName);