|
1 | 1 | import * as path from "path"; |
2 | | -import type { RuntimeConfig } from "cmux/types/runtime"; |
| 2 | +import { Config } from "cmux/config"; |
3 | 3 | import type { WorkspaceMetadata } from "cmux/types/workspace"; |
4 | 4 | import { |
5 | 5 | type ExtensionMetadata, |
6 | 6 | readExtensionMetadata, |
7 | 7 | } from "cmux/utils/extensionMetadata"; |
8 | 8 |
|
9 | 9 | /** |
10 | | - * Project configuration from cmux |
11 | | - */ |
12 | | -export interface ProjectConfig { |
13 | | - path: string; |
14 | | - workspaces: WorkspaceMetadata[]; |
15 | | -} |
16 | | - |
17 | | -/** |
18 | | - * Full cmux configuration structure |
19 | | - */ |
20 | | -export interface CmuxConfig { |
21 | | - projects: Array<[string, ProjectConfig]>; |
22 | | -} |
23 | | - |
24 | | -/** |
25 | | - * Workspace with additional context for display |
| 10 | + * Workspace with extension metadata for display in VS Code extension. |
| 11 | + * Combines workspace metadata from main app with extension-specific data. |
26 | 12 | */ |
27 | 13 | export interface WorkspaceWithContext extends WorkspaceMetadata { |
28 | 14 | projectPath: string; |
29 | 15 | extensionMetadata?: ExtensionMetadata; |
30 | 16 | } |
31 | 17 |
|
32 | 18 | /** |
33 | | - * Read and parse the cmux configuration file |
34 | | - */ |
35 | | -export function readCmuxConfig(): CmuxConfig | null { |
36 | | - const os = require("os"); |
37 | | - const fs = require("fs"); |
38 | | - const configPath = path.join(os.homedir(), ".cmux", "config.json"); |
39 | | - |
40 | | - if (!fs.existsSync(configPath)) { |
41 | | - return null; |
42 | | - } |
43 | | - |
44 | | - try { |
45 | | - const configData = fs.readFileSync(configPath, "utf-8"); |
46 | | - return JSON.parse(configData) as CmuxConfig; |
47 | | - } catch (error) { |
48 | | - console.error("Failed to read cmux config:", error); |
49 | | - return null; |
50 | | - } |
51 | | -} |
52 | | - |
53 | | -/** |
54 | | - * Get all workspaces from the cmux configuration |
| 19 | + * Get all workspaces from cmux config, enriched with extension metadata. |
| 20 | + * Uses main app's Config class to read workspace metadata, then enriches |
| 21 | + * with extension-specific data (recency, streaming status). |
55 | 22 | */ |
56 | 23 | export function getAllWorkspaces(): WorkspaceWithContext[] { |
57 | | - const config = readCmuxConfig(); |
58 | | - if (!config) { |
59 | | - return []; |
60 | | - } |
61 | | - |
62 | | - const metadata = readExtensionMetadata(); |
63 | | - console.log(`[cmux] Read ${metadata.size} entries from extension metadata`); |
64 | | - |
65 | | - const workspaces: WorkspaceWithContext[] = []; |
66 | | - |
67 | | - for (const [projectPath, projectConfig] of config.projects) { |
68 | | - const projectName = path.basename(projectPath); |
69 | | - |
70 | | - for (const workspace of projectConfig.workspaces) { |
71 | | - const meta = metadata.get(workspace.id); |
72 | | - |
73 | | - if (meta) { |
74 | | - console.log(`[cmux] ${workspace.id}: recency=${meta.recency}, streaming=${meta.streaming}`); |
75 | | - } |
76 | | - |
77 | | - workspaces.push({ |
78 | | - ...workspace, |
79 | | - // Ensure projectName is set (use from workspace or derive from path) |
80 | | - projectName: workspace.projectName || projectName, |
81 | | - projectPath, |
82 | | - extensionMetadata: meta, |
83 | | - }); |
| 24 | + const config = new Config(); |
| 25 | + const workspaces = config.getAllWorkspaceMetadata(); |
| 26 | + const extensionMeta = readExtensionMetadata(); |
| 27 | + |
| 28 | + console.log(`[cmux] Read ${extensionMeta.size} entries from extension metadata`); |
| 29 | + |
| 30 | + // Enrich with extension metadata |
| 31 | + const enriched: WorkspaceWithContext[] = workspaces.map((ws) => { |
| 32 | + const meta = extensionMeta.get(ws.id); |
| 33 | + if (meta) { |
| 34 | + console.log( |
| 35 | + `[cmux] ${ws.id}: recency=${meta.recency}, streaming=${meta.streaming}` |
| 36 | + ); |
84 | 37 | } |
85 | | - } |
86 | | - |
87 | | - // Sort by recency (metadata recency > createdAt > name) |
| 38 | + return { |
| 39 | + ...ws, |
| 40 | + extensionMetadata: meta, |
| 41 | + }; |
| 42 | + }); |
88 | 43 |
|
| 44 | + // Sort by recency (extension metadata > createdAt > name) |
89 | 45 | const recencyOf = (w: WorkspaceWithContext): number => |
90 | 46 | w.extensionMetadata?.recency ?? (w.createdAt ? Date.parse(w.createdAt) : 0); |
91 | | - workspaces.sort((a, b) => { |
| 47 | + |
| 48 | + enriched.sort((a, b) => { |
92 | 49 | const aRecency = recencyOf(a); |
93 | 50 | const bRecency = recencyOf(b); |
94 | 51 | if (aRecency !== bRecency) return bRecency - aRecency; |
95 | 52 | return a.name.localeCompare(b.name); |
96 | 53 | }); |
97 | 54 |
|
98 | | - return workspaces; |
| 55 | + return enriched; |
99 | 56 | } |
100 | 57 |
|
101 | 58 | /** |
|
0 commit comments