This repository was archived by the owner on May 15, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Expand file tree
/
Copy pathdiagnosticsHandler.ts
More file actions
92 lines (78 loc) · 3.05 KB
/
Copy pathdiagnosticsHandler.ts
File metadata and controls
92 lines (78 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import * as path from "path"
import * as os from "os"
import * as fs from "fs/promises"
import * as vscode from "vscode"
import { getTaskDirectoryPath } from "../../utils/storage"
import { fileExistsAtPath } from "../../utils/fs"
export interface ErrorDiagnosticsValues {
timestamp?: string
version?: string
provider?: string
model?: string
details?: string
}
export interface GenerateDiagnosticsParams {
taskId: string
globalStoragePath: string
values?: ErrorDiagnosticsValues
log: (message: string) => void
}
export interface GenerateDiagnosticsResult {
success: boolean
filePath?: string
error?: string
}
/**
* Generates an error diagnostics file containing error metadata and API conversation history.
* The file is created in the system temp directory and opened in VS Code for the user to review
* before sharing with support.
*/
export async function generateErrorDiagnostics(params: GenerateDiagnosticsParams): Promise<GenerateDiagnosticsResult> {
const { taskId, globalStoragePath, values, log } = params
try {
const taskDirPath = await getTaskDirectoryPath(globalStoragePath, taskId)
// Load API conversation history from the same file used by openDebugApiHistory
const apiHistoryPath = path.join(taskDirPath, "api_conversation_history.json")
let history: unknown = []
if (await fileExistsAtPath(apiHistoryPath)) {
const content = await fs.readFile(apiHistoryPath, "utf8")
try {
history = JSON.parse(content)
} catch {
// If parsing fails, fall back to empty history but still generate diagnostics file
vscode.window.showErrorMessage("Failed to parse api_conversation_history.json")
}
}
const diagnostics = {
error: {
timestamp: values?.timestamp ?? new Date().toISOString(),
version: values?.version ?? "",
provider: values?.provider ?? "",
model: values?.model ?? "",
details: values?.details ?? "",
},
history,
}
// Prepend human-readable guidance comments before the JSON payload
const headerComment =
"// If you open a GitHub issue, you can attach this file to help diagnose the issue faster.\n" +
"// Only share it if you're OK sharing the contents of the conversation below.\n\n"
const jsonContent = JSON.stringify(diagnostics, null, 2)
const fullContent = headerComment + jsonContent
// Create a temporary diagnostics file
const tmpDir = os.tmpdir()
const timestamp = Date.now()
const tempFileName = `roo-diagnostics-${taskId.slice(0, 8)}-${timestamp}.json`
const tempFilePath = path.join(tmpDir, tempFileName)
await fs.writeFile(tempFilePath, fullContent, "utf8")
// Open the diagnostics file in VS Code
const doc = await vscode.workspace.openTextDocument(tempFilePath)
await vscode.window.showTextDocument(doc, { preview: true })
return { success: true, filePath: tempFilePath }
} catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error)
log(`Error generating diagnostics: ${errorMessage}`)
vscode.window.showErrorMessage(`Failed to generate diagnostics: ${errorMessage}`)
return { success: false, error: errorMessage }
}
}