Understand any codebase instantly. System intelligence for codebases, built for humans and AI.
TypeScript aiai-memoryclaude-codeclicode-analysiscode-mappingcode-memorycodebase-understandingcodexdeveloper-toolsllmopenclawpersistent-memoryprogram-analysissoftware-architecturesystem-intelligencesystem-mapping
fix(config): refuse to overwrite a config.yaml that doesn't parse
KageBinary1aa12971c401
diff --git a/ix-cli/src/cli/__tests__/config-file-mode.test.ts b/ix-cli/src/cli/__tests__/config-file-mode.test.tsindex 488d1f85..dafb2a89 100644--- a/ix-cli/src/cli/__tests__/config-file-mode.test.ts+++ b/ix-cli/src/cli/__tests__/config-file-mode.test.ts@@ -116,3 +116,22 @@ describe("saveConfig persistence", () => {});});});++describe("saveConfig with an unparseable config", () => {+ it("refuses to overwrite it, so the workspaces and credentials in it survive", () => {+ fs.mkdirSync(cfgDir(), { recursive: true });+ const broken = [+ "endpoint: http://localhost:9090",+ "workspaces:",+ " - workspace_id: ws-a",+ " root_path: /src/a",+ "instances: { cloud: { token: secret }", // unclosed flow mapping+ "",+ ].join("\n");+ fs.writeFileSync(cfgPath(), broken);++ expect(() => saveConfig({ endpoint: "http://localhost:8090", format: "text" })).toThrow(/not valid YAML/);+ expect(fs.readFileSync(cfgPath(), "utf8")).toBe(broken);+ expect(fs.readdirSync(cfgDir())).toEqual(["config.yaml"]);+ });+});diff --git a/ix-cli/src/cli/config.ts b/ix-cli/src/cli/config.tsindex 88a18862..f0c54aa9 100644--- a/ix-cli/src/cli/config.ts+++ b/ix-cli/src/cli/config.ts@@ -192,8 +192,15 @@ export function saveConfig(config: IxConfig): void {if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {existing = parsed as Record<string, unknown>;}- } catch {- existing = {};+ } catch (err) {+ // Refuse rather than start from `{}`: that rewrote the file with only+ // this call's fields, silently dropping every other workspace, a custom+ // endpoint and extension state such as Pro's credentials -- all over+ // one typo in a hand edit.+ throw new Error(+ `${configPath} is not valid YAML, so Ix will not overwrite it. ` ++ `Fix or remove the file and run the command again. (${err instanceof Error ? err.message.split("\n")[0] : String(err)})`,+ );}}// Drop OSS-owned keys from the disk snapshot — the in-memory `config`