MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / generateErrorDiagnostics

Function generateErrorDiagnostics

src/core/webview/diagnosticsHandler.ts:35–92  ·  view source on GitHub ↗
(params: GenerateDiagnosticsParams)

Source from the content-addressed store, hash-verified

33 * before sharing with support.
34 */
35export async function generateErrorDiagnostics(params: GenerateDiagnosticsParams): Promise<GenerateDiagnosticsResult> {
36 const { taskId, globalStoragePath, values, log } = params
37
38 try {
39 const taskDirPath = await getTaskDirectoryPath(globalStoragePath, taskId)
40
41 // Load API conversation history from the same file used by openDebugApiHistory
42 const apiHistoryPath = path.join(taskDirPath, "api_conversation_history.json")
43 let history: unknown = []
44
45 if (await fileExistsAtPath(apiHistoryPath)) {
46 const content = await fs.readFile(apiHistoryPath, "utf8")
47 try {
48 history = JSON.parse(content)
49 } catch {
50 // If parsing fails, fall back to empty history but still generate diagnostics file
51 vscode.window.showErrorMessage("Failed to parse api_conversation_history.json")
52 }
53 }
54
55 const diagnostics = {
56 error: {
57 timestamp: values?.timestamp ?? new Date().toISOString(),
58 version: values?.version ?? "",
59 provider: values?.provider ?? "",
60 model: values?.model ?? "",
61 details: values?.details ?? "",
62 },
63 history,
64 }
65
66 // Prepend human-readable guidance comments before the JSON payload
67 const headerComment =
68 "// Please share this file with Zoo Code Support (support@zoocode.dev) to diagnose the issue faster\n" +
69 "// Just make sure you're OK sharing the contents of the conversation below.\n\n"
70 const jsonContent = JSON.stringify(diagnostics, null, 2)
71 const fullContent = headerComment + jsonContent
72
73 // Create a temporary diagnostics file
74 const tmpDir = os.tmpdir()
75 const timestamp = Date.now()
76 const tempFileName = `zoo-diagnostics-${taskId.slice(0, 8)}-${timestamp}.json`
77 const tempFilePath = path.join(tmpDir, tempFileName)
78
79 await fs.writeFile(tempFilePath, fullContent, "utf8")
80
81 // Open the diagnostics file in VS Code
82 const doc = await vscode.workspace.openTextDocument(tempFilePath)
83 await vscode.window.showTextDocument(doc, { preview: true })
84
85 return { success: true, filePath: tempFilePath }
86 } catch (error) {
87 const errorMessage = error instanceof Error ? error.message : String(error)
88 log(`Error generating diagnostics: ${errorMessage}`)
89 vscode.window.showErrorMessage(`Failed to generate diagnostics: ${errorMessage}`)
90 return { success: false, error: errorMessage }
91 }
92}

Callers 2

webviewMessageHandlerFunction · 0.90

Calls 10

getTaskDirectoryPathFunction · 0.90
fileExistsAtPathFunction · 0.90
parseMethod · 0.80
writeFileMethod · 0.80
openTextDocumentMethod · 0.80
showTextDocumentMethod · 0.80
StringInterface · 0.50
logFunction · 0.50
readFileMethod · 0.45
showErrorMessageMethod · 0.45

Tested by

no test coverage detected