Skip to content

Commit 5b8a7a4

Browse files
committed
fix: address PR #14 review — guard missing context in /model-groups, fix deleteGroup error-after-commit
- model-groups/command.ts: add guard for missing ctx.cwd or ctx.modelRegistry before calling createModelGroupsComponent; surface friendly notification instead of crashing. Matches refreshModelGroupsState pattern in index.ts. - model-groups/store.ts deleteGroup(): load opposite-scope config before saving the delete so a load failure doesn't throw after the delete is already persisted on disk. Follows moveGroup's pre-validation pattern.
1 parent 6733bfd commit 5b8a7a4

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

model-groups/command.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ export function registerModelGroupsCommand(pi: ExtensionAPI, state: Agenticoding
77
description: "Manage Model Groups",
88
handler: async (_args, ctx) => {
99
if (!ctx.hasUI) return;
10+
if (!ctx.cwd || !ctx.modelRegistry) {
11+
ctx.ui.notify("Cannot manage model groups: missing working directory or model registry", "error");
12+
return;
13+
}
1014
await ctx.ui.custom<void>((tui, theme, _keybindings, done) =>
1115
createModelGroupsComponent(tui, theme, ctx.modelRegistry, ctx.cwd, done, {
1216
initialValidation: state.modelGroups.validation,

model-groups/store.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,10 @@ export function deleteGroup(scope: ModelGroupScope, cwd: string, name: string):
214214
const config = loadScopeConfig(scope, cwd);
215215
if (!config.groups[name]) throw new Error(`Model group '${name}' does not exist in ${scope} scope`);
216216
delete config.groups[name];
217+
218+
// Load the opposite scope before saving — if this throws, nothing was persisted yet.
219+
const other = loadScopeConfig(scope === "global" ? "project" : "global", cwd);
220+
217221
try {
218222
saveModelGroups(scope, cwd, config);
219223
} catch (cause) {
@@ -230,7 +234,6 @@ export function deleteGroup(scope: ModelGroupScope, cwd: string, name: string):
230234
}
231235
throw cause;
232236
}
233-
const other = loadScopeConfig(scope === "global" ? "project" : "global", cwd);
234237
return { otherScopeHasOverride: Boolean(other.groups[name]) };
235238
}
236239

0 commit comments

Comments
 (0)