(params: GenerateDiagnosticsParams)
| 33 | * before sharing with support. |
| 34 | */ |
| 35 | export 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 | } |
no test coverage detected