mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-09-06 08:18:39 +00:00
Logging tweaks
This commit is contained in:
parent
5e4349a36c
commit
3d804b0ee3
4 changed files with 47 additions and 75 deletions
|
|
@ -222,30 +222,23 @@ const runExercise = async ({ run, task, server }: { run: Run; task: Task; server
|
|||
})
|
||||
|
||||
client.sendMessage({
|
||||
type: IpcMessageType.VSCodeCommand,
|
||||
type: IpcMessageType.TaskCommand,
|
||||
origin: IpcOrigin.Client,
|
||||
clientId: client.clientId!,
|
||||
data: "workbench.action.closeWindow",
|
||||
data: {
|
||||
commandName: TaskCommandName.StartNewTask,
|
||||
data: {
|
||||
configuration: {
|
||||
...rooCodeDefaults,
|
||||
openRouterApiKey: process.env.OPENROUTER_API_KEY!,
|
||||
...run.settings,
|
||||
},
|
||||
text: prompt,
|
||||
newTab: true,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
// client.sendMessage({
|
||||
// type: IpcMessageType.TaskCommand,
|
||||
// origin: IpcOrigin.Client,
|
||||
// clientId: client.clientId!,
|
||||
// data: {
|
||||
// commandName: TaskCommandName.StartNewTask,
|
||||
// data: {
|
||||
// configuration: {
|
||||
// ...rooCodeDefaults,
|
||||
// openRouterApiKey: process.env.OPENROUTER_API_KEY!,
|
||||
// ...run.settings,
|
||||
// },
|
||||
// text: prompt,
|
||||
// newTab: true,
|
||||
// },
|
||||
// },
|
||||
// })
|
||||
|
||||
console.log(`[cli#runExercise | ${language} / ${exercise}] StartNewTask`)
|
||||
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -6,9 +6,9 @@ import { openClineInNewTab } from "../activate/registerCommands"
|
|||
|
||||
import { RooCodeSettings, RooCodeEvents, RooCodeEventName } from "../schemas"
|
||||
import { IpcOrigin, IpcMessageType, TaskCommandName, TaskEvent } from "../schemas/ipc"
|
||||
import { formatLog } from "./formatLog"
|
||||
import { RooCodeAPI } from "./interface"
|
||||
import { IpcServer } from "./ipc"
|
||||
import { outputChannelLog } from "./log"
|
||||
|
||||
export class API extends EventEmitter<RooCodeEvents> implements RooCodeAPI {
|
||||
private readonly outputChannel: vscode.OutputChannel
|
||||
|
|
@ -27,8 +27,7 @@ export class API extends EventEmitter<RooCodeEvents> implements RooCodeAPI {
|
|||
this.registerListeners(this.sidebarProvider)
|
||||
|
||||
if (socketPath) {
|
||||
this.ipc = new IpcServer(socketPath, (...args: unknown[]) => formatLog(this.outputChannel, ...args))
|
||||
|
||||
this.ipc = new IpcServer(socketPath, (...args: unknown[]) => outputChannelLog(this.outputChannel, ...args))
|
||||
this.ipc.listen()
|
||||
|
||||
this.outputChannel.appendLine(
|
||||
|
|
|
|||
|
|
@ -1,52 +0,0 @@
|
|||
/**
|
||||
* @fileoverview Utility for robust object logging with special handling for various data types
|
||||
*/
|
||||
|
||||
import * as vscode from "vscode"
|
||||
|
||||
/**
|
||||
* Formats and logs values to a VSCode output channel with special handling for various data types
|
||||
*
|
||||
* Features:
|
||||
* - Explicit handling for null and undefined values
|
||||
* - Special handling for Error objects to preserve stack traces
|
||||
* - Handles circular references in objects
|
||||
* - Properly formats special types like BigInt, functions, and symbols
|
||||
* - Pretty prints objects with indentation for better readability
|
||||
*
|
||||
* @param outputChannel - The VSCode output channel to log to
|
||||
* @param args - The values to log
|
||||
*/
|
||||
export function formatLog(outputChannel: vscode.OutputChannel, ...args: unknown[]): void {
|
||||
for (const arg of args) {
|
||||
if (arg === null) {
|
||||
outputChannel.appendLine("null")
|
||||
} else if (arg === undefined) {
|
||||
outputChannel.appendLine("undefined")
|
||||
} else if (typeof arg === "string") {
|
||||
outputChannel.appendLine(arg)
|
||||
} else if (arg instanceof Error) {
|
||||
// Special handling for Error objects to preserve stack traces
|
||||
outputChannel.appendLine(`Error: ${arg.message}\n${arg.stack || ""}`)
|
||||
} else {
|
||||
try {
|
||||
outputChannel.appendLine(
|
||||
JSON.stringify(
|
||||
arg,
|
||||
(key, value) => {
|
||||
// Handle special types that JSON.stringify doesn't handle well
|
||||
if (typeof value === "bigint") return `BigInt(${value})`
|
||||
if (typeof value === "function") return `Function: ${value.name || "anonymous"}`
|
||||
if (typeof value === "symbol") return value.toString()
|
||||
return value
|
||||
},
|
||||
2,
|
||||
),
|
||||
) // Pretty print with 2 spaces
|
||||
} catch (error) {
|
||||
// Handle circular references or other JSON.stringify errors
|
||||
outputChannel.appendLine(`[Non-serializable object: ${Object.prototype.toString.call(arg)}]`)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
32
src/exports/log.ts
Normal file
32
src/exports/log.ts
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
import * as vscode from "vscode"
|
||||
|
||||
export function outputChannelLog(outputChannel: vscode.OutputChannel, ...args: unknown[]) {
|
||||
for (const arg of args) {
|
||||
if (arg === null) {
|
||||
outputChannel.appendLine("null")
|
||||
} else if (arg === undefined) {
|
||||
outputChannel.appendLine("undefined")
|
||||
} else if (typeof arg === "string") {
|
||||
outputChannel.appendLine(arg)
|
||||
} else if (arg instanceof Error) {
|
||||
outputChannel.appendLine(`Error: ${arg.message}\n${arg.stack || ""}`)
|
||||
} else {
|
||||
try {
|
||||
outputChannel.appendLine(
|
||||
JSON.stringify(
|
||||
arg,
|
||||
(key, value) => {
|
||||
if (typeof value === "bigint") return `BigInt(${value})`
|
||||
if (typeof value === "function") return `Function: ${value.name || "anonymous"}`
|
||||
if (typeof value === "symbol") return value.toString()
|
||||
return value
|
||||
},
|
||||
2,
|
||||
),
|
||||
)
|
||||
} catch (error) {
|
||||
outputChannel.appendLine(`[Non-serializable object: ${Object.prototype.toString.call(arg)}]`)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue