debug(cli): add verbose event logging for CI debugging with message content and tool details
- logEventVerbose() logs all event types including message content, tool calls, and results - Session tags distinguish main vs child sessions for multi-session tracking - completion.ts error logging instead of silently swallowing API errors - Helps diagnose realtime streaming behavior in CI environments 🤖 Generated with assistance of OhMyOpenCode (https://github.com/code-yeongyu/oh-my-opencode)
This commit is contained in:
@@ -12,8 +12,8 @@ export async function checkCompletionConditions(ctx: RunContext): Promise<boolea
|
|||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
} catch {
|
} catch (err) {
|
||||||
// API errors are transient - silently continue polling
|
console.error(pc.red(`[completion] API error: ${err}`))
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ export async function processEvents(
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
console.error(pc.dim(`[event] ${payload.type}`))
|
logEventVerbose(ctx, payload)
|
||||||
|
|
||||||
handleSessionIdle(ctx, payload, state)
|
handleSessionIdle(ctx, payload, state)
|
||||||
handleSessionStatus(ctx, payload, state)
|
handleSessionStatus(ctx, payload, state)
|
||||||
@@ -55,6 +55,79 @@ export async function processEvents(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function logEventVerbose(ctx: RunContext, payload: EventPayload): void {
|
||||||
|
const props = payload.properties as Record<string, unknown> | undefined
|
||||||
|
const info = props?.info as Record<string, unknown> | undefined
|
||||||
|
const sessionID = props?.sessionID ?? info?.sessionID
|
||||||
|
const isMainSession = sessionID === ctx.sessionID
|
||||||
|
const sessionTag = isMainSession
|
||||||
|
? pc.green("[MAIN]")
|
||||||
|
: pc.yellow(`[${String(sessionID).slice(0, 8)}]`)
|
||||||
|
|
||||||
|
switch (payload.type) {
|
||||||
|
case "session.idle":
|
||||||
|
case "session.status": {
|
||||||
|
const status = (props?.status as { type?: string })?.type ?? "idle"
|
||||||
|
console.error(pc.dim(`${sessionTag} ${payload.type}: ${status}`))
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
case "message.part.updated": {
|
||||||
|
const partProps = props as MessagePartUpdatedProps | undefined
|
||||||
|
const role = partProps?.info?.role ?? "unknown"
|
||||||
|
const part = partProps?.part
|
||||||
|
if (part?.type === "text" && part.text) {
|
||||||
|
const preview = part.text.slice(0, 100).replace(/\n/g, "\\n")
|
||||||
|
console.error(
|
||||||
|
pc.dim(`${sessionTag} message.part (${role}): "${preview}${part.text.length > 100 ? "..." : ""}"`)
|
||||||
|
)
|
||||||
|
} else if (part?.type === "tool-invocation") {
|
||||||
|
const toolPart = part as { toolName?: string; state?: string }
|
||||||
|
console.error(
|
||||||
|
pc.dim(`${sessionTag} message.part (tool): ${toolPart.toolName} [${toolPart.state}]`)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
case "message.updated": {
|
||||||
|
const msgProps = props as MessageUpdatedProps | undefined
|
||||||
|
const role = msgProps?.info?.role ?? "unknown"
|
||||||
|
const content = msgProps?.content ?? ""
|
||||||
|
const preview = content.slice(0, 100).replace(/\n/g, "\\n")
|
||||||
|
console.error(
|
||||||
|
pc.dim(`${sessionTag} message.updated (${role}): "${preview}${content.length > 100 ? "..." : ""}"`)
|
||||||
|
)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
case "tool.execute": {
|
||||||
|
const toolProps = props as ToolExecuteProps | undefined
|
||||||
|
const toolName = toolProps?.name ?? "unknown"
|
||||||
|
const input = toolProps?.input ?? {}
|
||||||
|
const inputStr = JSON.stringify(input).slice(0, 150)
|
||||||
|
console.error(
|
||||||
|
pc.cyan(`${sessionTag} ⚡ TOOL.EXECUTE: ${pc.bold(toolName)}`)
|
||||||
|
)
|
||||||
|
console.error(pc.dim(` input: ${inputStr}${inputStr.length >= 150 ? "..." : ""}`))
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
case "tool.result": {
|
||||||
|
const resultProps = props as ToolResultProps | undefined
|
||||||
|
const output = resultProps?.output ?? ""
|
||||||
|
const preview = output.slice(0, 200).replace(/\n/g, "\\n")
|
||||||
|
console.error(
|
||||||
|
pc.green(`${sessionTag} ✓ TOOL.RESULT: "${preview}${output.length > 200 ? "..." : ""}"`)
|
||||||
|
)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
console.error(pc.dim(`${sessionTag} ${payload.type}`))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function handleSessionIdle(
|
function handleSessionIdle(
|
||||||
ctx: RunContext,
|
ctx: RunContext,
|
||||||
payload: EventPayload,
|
payload: EventPayload,
|
||||||
|
|||||||
Reference in New Issue
Block a user