MCPcopy Create free account
hub / github.com/codag-megalith/codag-visualizer / analyzeWorkspace

Function analyzeWorkspace

frontend/src/analysis/workspace.ts:61–1065  ·  view source on GitHub ↗
(
    ctx: WorkspaceContext,
    bypassCache: boolean = false
)

Source from the content-addressed store, hash-verified

59 * @param bypassCache - If true, skip cache and force fresh analysis
60 */
61export async function analyzeWorkspace(
62 ctx: WorkspaceContext,
63 bypassCache: boolean = false
64): Promise<void> {
65 const { api, cache, webview, metadataBuilder, extensionContext, log } = ctx;
66
67 // Pre-flight: check backend is reachable and API key is valid
68 const health = await api.checkHealth();
69 if (!health.healthy) {
70 log('Backend not reachable — showing error overlay');
71 webview.showLoading('Connecting to backend...');
72 webview.notifyBackendError();
73 return;
74 }
75 if (health.apiKeyStatus !== 'valid') {
76 log(`API key ${health.apiKeyStatus} — showing error overlay`);
77 webview.notifyApiKeyError(health.apiKeyStatus === 'missing' ? 'missing' : 'invalid');
78 return;
79 }
80
81 // Dismiss any lingering error overlay from a previous failed check
82 webview.dismissErrorOverlays();
83
84 // Track analysis start time
85 const startTime = Date.now();
86 const sessionAtStart = getAnalysisSession(); // Capture session to detect invalidation
87
88 // Pipeline stats tracking - shows what gets filtered at each stage
89 const pipelineStats = {
90 detected: { llmFiles: 0, httpFiles: 0, httpClientFilesAdded: 0 },
91 cached: { filesFromCache: 0, filesNeedAnalysis: 0 },
92 analyzed: { filesSentToLLM: 0, httpConnections: 0 },
93 results: { filesWithNodes: 0, filesWithNoWorkflow: 0, totalNodes: 0 },
94 edges: { llmGenerated: 0, resolved: 0, orphaned: 0 }
95 };
96
97 log('Starting workspace scan...');
98 log(`Workspace root: ${vscode.workspace.workspaceFolders?.[0]?.uri.fsPath}`);
99 if (bypassCache) {
100 log('⚠️ BYPASS MODE: Cache reading/writing disabled for this analysis');
101 }
102
103 // Check if workspace is open
104 const workspaceFolders = vscode.workspace.workspaceFolders;
105 if (!workspaceFolders || workspaceFolders.length === 0) {
106 webview.notifyWarning('No folder open. Use File > Open Folder to open a project.');
107 return;
108 }
109 const workspaceRoot = workspaceFolders[0].uri.fsPath;
110
111 try {
112 // Show panel immediately (don't block on file detection)
113 webview.showLoading('Scanning workspace...');
114
115 // Check if workspace has any source files
116 const sourceFileCount = (await WorkflowDetector.getAllSourceFiles()).length;
117 if (sourceFileCount === 0) {
118 webview.notifyWarning('No source files found (.py, .ts, .js). Open a folder containing code.');

Callers 1

activateFunction · 0.90

Calls 15

startMethod · 0.95
addMethod · 0.95
hasOperationsMethod · 0.95
getReportMethod · 0.95
getAnalysisSessionFunction · 0.90
getSavedSelectedPathsFunction · 0.90
withHttpEdgesFunction · 0.90
estimateAnalysisCostFunction · 0.90
createDependencyBatchesFunction · 0.90
combineFilesXMLFunction · 0.90
estimateTokensFunction · 0.90
displayCostReportFunction · 0.90

Tested by

no test coverage detected