Skip to content

Commit 28ed10a

Browse files
committed
🤖 refactor: normalize runtimeConfig in config file on load
Instead of applying DEFAULT_RUNTIME_CONFIG on-the-fly, we now migrate missing runtimeConfig to the config file during load. This makes the config file the single source of truth and eliminates runtime conversion. Changes: - Removed ensureRuntimeConfig() and getDefaultRuntimeConfig() methods - Apply DEFAULT_RUNTIME_CONFIG directly when loading workspaces - Save normalized config back to disk (configModified = true) - All 4 workspace loading paths now write runtimeConfig to config Benefits: - Config file is normalized once, not on every read - Simpler code - no runtime conversions needed - Easier to remove this migration code in the future
1 parent b2af101 commit 28ed10a

File tree

2 files changed

+19
-38
lines changed

2 files changed

+19
-38
lines changed

docs/vscode-extension.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# VS Code Extension
22

3-
The cmux VS Code extension allows you to quickly jump into your cmux workspaces directly from Visual Studio Code or Cursor.
3+
The cmux VS Code extension allows you to quickly jump into your cmux workspaces directly from Visual Studio Code or Cursor. This enables a more seamless back and forth between a purely agentic workflow and traditional editing. It's
4+
especially useful for completing the "last mile" of a task or establishing the initial architecture.
45

56
## Overview
67

src/config.ts

Lines changed: 17 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -101,27 +101,7 @@ export class Config {
101101
return projectPath.split("/").pop() ?? projectPath.split("\\").pop() ?? "unknown";
102102
}
103103

104-
/**
105-
* Get default runtime config for local workspaces
106-
* This ensures all workspaces have a runtime config set
107-
*/
108-
private getDefaultRuntimeConfig(): RuntimeConfig {
109-
return DEFAULT_RUNTIME_CONFIG;
110-
}
111104

112-
/**
113-
* Ensure workspace metadata has a runtime config
114-
* If missing, applies the default local runtime config
115-
*/
116-
private ensureRuntimeConfig(metadata: WorkspaceMetadata): WorkspaceMetadata {
117-
if (!metadata.runtimeConfig) {
118-
return {
119-
...metadata,
120-
runtimeConfig: this.getDefaultRuntimeConfig(),
121-
};
122-
}
123-
return metadata;
124-
}
125105

126106
/**
127107
* Generate a stable unique workspace ID.
@@ -273,15 +253,15 @@ export class Config {
273253
try {
274254
// NEW FORMAT: If workspace has metadata in config, use it directly
275255
if (workspace.id && workspace.name) {
276-
let metadata: WorkspaceMetadata = {
256+
const metadata: WorkspaceMetadata = {
277257
id: workspace.id,
278258
name: workspace.name,
279259
projectName,
280260
projectPath,
281261
// GUARANTEE: All workspaces must have createdAt (assign now if missing)
282262
createdAt: workspace.createdAt ?? new Date().toISOString(),
283-
// Include runtime config if present, otherwise default will be applied below
284-
runtimeConfig: workspace.runtimeConfig ?? this.getDefaultRuntimeConfig(),
263+
// GUARANTEE: All workspaces must have runtimeConfig (apply default if missing)
264+
runtimeConfig: workspace.runtimeConfig ?? DEFAULT_RUNTIME_CONFIG,
285265
};
286266

287267
// Migrate missing createdAt to config for next load
@@ -290,8 +270,11 @@ export class Config {
290270
configModified = true;
291271
}
292272

293-
// GUARANTEE: All workspaces must have runtimeConfig (apply default if missing)
294-
metadata = this.ensureRuntimeConfig(metadata);
273+
// Migrate missing runtimeConfig to config for next load
274+
if (!workspace.runtimeConfig) {
275+
workspace.runtimeConfig = metadata.runtimeConfig;
276+
configModified = true;
277+
}
295278

296279
workspaceMetadata.push(this.addPathsToMetadata(metadata, workspace.path, projectPath));
297280
continue; // Skip metadata file lookup
@@ -305,28 +288,24 @@ export class Config {
305288

306289
if (fs.existsSync(metadataPath)) {
307290
const data = fs.readFileSync(metadataPath, "utf-8");
308-
let metadata = JSON.parse(data) as WorkspaceMetadata;
291+
const metadata = JSON.parse(data) as WorkspaceMetadata;
309292

310293
// Ensure required fields are present
311-
if (!metadata.name || !metadata.projectPath) {
312-
metadata = {
313-
...metadata,
314-
name: metadata.name ?? workspaceBasename,
315-
projectPath: metadata.projectPath ?? projectPath,
316-
projectName: metadata.projectName ?? projectName,
317-
};
318-
}
294+
if (!metadata.name) metadata.name = workspaceBasename;
295+
if (!metadata.projectPath) metadata.projectPath = projectPath;
296+
if (!metadata.projectName) metadata.projectName = projectName;
319297

320298
// GUARANTEE: All workspaces must have createdAt
321299
metadata.createdAt ??= new Date().toISOString();
322300

323301
// GUARANTEE: All workspaces must have runtimeConfig
324-
metadata = this.ensureRuntimeConfig(metadata);
302+
metadata.runtimeConfig ??= DEFAULT_RUNTIME_CONFIG;
325303

326304
// Migrate to config for next load
327305
workspace.id = metadata.id;
328306
workspace.name = metadata.name;
329307
workspace.createdAt = metadata.createdAt;
308+
workspace.runtimeConfig = metadata.runtimeConfig;
330309
configModified = true;
331310

332311
workspaceMetadata.push(this.addPathsToMetadata(metadata, workspace.path, projectPath));
@@ -344,13 +323,14 @@ export class Config {
344323
// GUARANTEE: All workspaces must have createdAt
345324
createdAt: new Date().toISOString(),
346325
// GUARANTEE: All workspaces must have runtimeConfig
347-
runtimeConfig: this.getDefaultRuntimeConfig(),
326+
runtimeConfig: DEFAULT_RUNTIME_CONFIG,
348327
};
349328

350329
// Save to config for next load
351330
workspace.id = metadata.id;
352331
workspace.name = metadata.name;
353332
workspace.createdAt = metadata.createdAt;
333+
workspace.runtimeConfig = metadata.runtimeConfig;
354334
configModified = true;
355335

356336
workspaceMetadata.push(this.addPathsToMetadata(metadata, workspace.path, projectPath));
@@ -367,7 +347,7 @@ export class Config {
367347
// GUARANTEE: All workspaces must have createdAt (even in error cases)
368348
createdAt: new Date().toISOString(),
369349
// GUARANTEE: All workspaces must have runtimeConfig (even in error cases)
370-
runtimeConfig: this.getDefaultRuntimeConfig(),
350+
runtimeConfig: DEFAULT_RUNTIME_CONFIG,
371351
};
372352
workspaceMetadata.push(this.addPathsToMetadata(metadata, workspace.path, projectPath));
373353
}

0 commit comments

Comments
 (0)