TwinMind Debug Bundle
Current State
!node --version 2>/dev/null || echo 'N/A'
!python3 --version 2>/dev/null || echo 'N/A'
!uname -a
Overview
Collect comprehensive diagnostic data to troubleshoot TwinMind issues.
Prerequisites
- TwinMind extension or API configured
- Access to browser developer tools
- Command-line access (for API debugging)
Instructions
Step 1: Create Debug Bundle Script
// scripts/twinmind-debug-bundle.ts
import * as fs from 'fs';
import * as os from 'os';
import * as path from 'path';
interface DebugBundle {
timestamp: string;
environment: EnvironmentInfo;
apiStatus: ApiStatus;
recentErrors: ErrorEntry[];
configuration: ConfigSnapshot;
networkTests: NetworkTest[];
}
interface EnvironmentInfo {
nodeVersion: string;
platform: string;
arch: string;
osRelease: string;
timezone: string;
memory: {
total: number;
free: number;
used: number;
};
}
interface ApiStatus {
healthy: boolean;
latencyMs: number;
endpoint: string;
responseHeaders?: Record<string, string>;
}
interface ErrorEntry {
timestamp: string;
type: string;
message: string;
stack?: string;
context?: Record<string, any>;
}
interface ConfigSnapshot {
apiKeyPresent: boolean;
apiKeyPrefix: string;
baseUrl: string;
timeout: number;
environment: string;
}
interface NetworkTest {
endpoint: string;
reachable: boolean;
latencyMs?: number;
error?: string;
}
export async function generateDebugBundle(): Promise<DebugBundle> {
const bundle: DebugBundle = {
timestamp: new Date().toISOString(),
environment: getEnvironmentInfo(),
apiStatus: await checkApiStatus(),
recentErrors: collectRecentErrors(),
configuration: getConfigSnapshot(),
networkTests: await runNetworkTests(),
};
return bundle;
}
function getEnvironmentInfo(): EnvironmentInfo {
return {
nodeVersion: process.version,
platform: os.platform(),
arch: os.arch(),
osRelease: os.release(),
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
memory: {
total: os.totalmem(),
free: os.freemem(),
used: os.totalmem() - os.freemem(),
},
};
}
async function checkApiStatus(): Promise<ApiStatus> {
const endpoint = process.env.TWINMIND_API_URL || 'https://api.twinmind.com/v1';
const start = Date.now();
try {
const response = await fetch(`${endpoint}/health`, {
headers: {
'Authorization': `Bearer ${process.env.TWINMIND_API_KEY}`,
},
});
return {
healthy: response.ok,
latencyMs: Date.now() - start,
endpoint,
responseHeaders: Object.fromEntries(response.headers.entries()),
};
} catch (error: any) {
return {
healthy: false,
latencyMs: Date.now() - start,
endpoint,
};
}
}
function collectRecentErrors(): ErrorEntry[] {
// In a real implementation, this would read from error logs
// For now, return empty array
return [];
}
function getConfigSnapshot(): ConfigSnapshot {
const apiKey = process.env.TWINMIND_API_KEY || '';
return {
apiKeyPresent: apiKey.length > 0,
apiKeyPrefix: apiKey.substring(0, 8) + '...',
baseUrl: process.env.TWINMIND_API_URL || 'https://api.twinmind.com/v1',
timeout: parseInt(process.env.TWINMIND_TIMEOUT || '30000'), # 30000: 30 seconds in ms
environment: process.env.NODE_ENV || 'development',
};
}
async function runNetworkTests(): Promise<NetworkTest[]> {
const endpoints = [
'https://api.twinmind.com',
'',
'https://twinmind.com',
];
const tests: NetworkTest[] = [];
for (const endpoint of endpoints) {
const start = Date.now();
try {
const response = await fetch(endpoint, { method: 'HEAD' });
tests.push({
endpoint,
reachable: response.ok,
latencyMs: Date.now() - start,
});
} catch (error: any) {
tests.push({
endpoint,
reachable: false,
error: error.message,
});
}
}
return tests;
}
// Save bundle to file
export async function saveDebugBundle(outputPath?: string): Promise<string> {
const bundle = await generateDebugBundle();
const filename = outputPath || path.join(
os.tmpdir(),
`twinmind-debug-${Date.now()}.json`
);
fs.writeFileSync(filename, JSON.stringify(bundle, null, 2));
console.log(`Debug bundle saved to: ${filename}`);
return filename;
}