Skip to content

Stop paying the multimodal tax. Your AI agent keeps every image it has seen but only sends the ones it needs: lighter chats, no endless reconnecting, no starting over. Works with Codex, Claude Code, Cline, Gemini CLI, OpenCode, WorkBuddy and more. Install once, forget it.

fix(install): never copy a platform's settings file, it may hold API keys

chipfighter4d680a1ec8d9
diff --git a/plugin/src/core/config-edit.ts b/plugin/src/core/config-edit.ts
index 06cfac4..b11510d 100644
--- a/plugin/src/core/config-edit.ts
+++ b/plugin/src/core/config-edit.ts
@@ -1,13 +1,14 @@
// Purpose: v0.11 — `cam connect --apply` writes a platform's own settings (docs/v0.11/plan.md 3.8): a value at a path
// in a JSON file, an item in a JSON list, or a NAME=value line in an env file. A file that does not parse as plain JSON
-// (comments, say) is left alone and the command says so. Each file is backed up before the first change; what was
-// written, and what was there before, is recorded, and `cam disconnect` puts back only what still holds the value
-// written, so changes the user made since stay.
-// Input: the edits a platform's entry asks for (core/platform.ts). Output: the files, backups under
-// <data dir>/config-backup/<platform>/, and <data dir>/platforms/<platform>/connected.json.
+// (comments, say) is left alone and the command says so. What was written, and what each setting held before, is
+// recorded, and `cam disconnect` puts back only what still holds the value written, so changes the user made since
+// stay. The files themselves are never copied: settings files and .env files often hold API keys, and a key does not
+// leave its file (as with Codex's .env). Only the settings changed are recorded.
+// Input: the edits a platform's entry asks for (core/platform.ts). Output: the files, and
+// <data dir>/platforms/<platform>/connected.json.
-import { copyFileSync, existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
-import { basename, dirname, join } from "node:path";
+import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
+import { dirname, join } from "node:path";
import { platformDirOf } from "./request-index.ts";
type Json = Record<string, any>;
@@ -60,7 +61,8 @@ const parentOf = (root: Json, path: string[], create: boolean): Json | null => {
let node = root;
for (const key of path.slice(0, -1)) {
if (node[key] === undefined && create) node[key] = {};
- if (!node[key] || typeof node[key] !== "object" || Array.isArray(node[key])) return null;
+ // A list is walked by index (Qwen Code keeps its models in lists); one is never made here.
+ if (!node[key] || typeof node[key] !== "object") return null;
node = node[key];
}
return node;
@@ -113,16 +115,8 @@ export function applyEdits(platform: string, edits: ConfigEdit[], root: string,
const files = [...new Set(edits.map((edit) => edit.file))];
// Everything is read and checked before the first file is written.
for (const file of files) if (!edits.some((edit) => edit.file === file && "env" in edit)) readJson(file);
- const backups = join(root, "config-backup", platform);
- const stamp = now.toISOString().replaceAll(":", "-");
const recorded: Recorded[] = [];
- for (const file of files) {
- if (existsSync(file)) {
- mkdirSync(backups, { recursive: true });
- copyFileSync(file, join(backups, `${basename(file)}.${stamp}`));
- }
- recorded.push(...applyTo(file, edits.filter((edit) => edit.file === file)));
- }
+ for (const file of files) recorded.push(...applyTo(file, edits.filter((edit) => edit.file === file)));
// A second connect keeps what was there before the first one.
const earlier = readRecord(platform, root);
const kept = recorded.map((entry) => {
diff --git a/spike/src/connect.test.ts b/spike/src/connect.test.ts
index 613bc4e..60ec3ea 100644
--- a/spike/src/connect.test.ts
+++ b/spike/src/connect.test.ts
@@ -11,6 +11,10 @@ import { geminiCli } from "../../plugin/src/adapters/gemini-cli/platform.ts";
import { opencode } from "../../plugin/src/adapters/opencode/platform.ts";
import { pi } from "../../plugin/src/adapters/pi/platform.ts";
import { workbuddy } from "../../plugin/src/adapters/workbuddy/platform.ts";
+import { cline } from "../../plugin/src/adapters/cline/platform.ts";
+import { goose } from "../../plugin/src/adapters/goose/platform.ts";
+import { kiloCode } from "../../plugin/src/adapters/kilo-code/platform.ts";
+import { qwenCode } from "../../plugin/src/adapters/qwen-code/platform.ts";
import { applyEdits, undoEdits } from "../../plugin/src/core/config-edit.ts";
import { detectPlatform } from "../../plugin/src/platforms.ts";
@@ -32,7 +36,7 @@ test("which platform a shell command runs in, from the variables each one sets",
assert.deepEqual(detectPlatform({ CLAUDECODE: "1", CODEX_THREAD_ID: "t" }).platform, null, "one agent started from another's shell: ask");
});
-test("connect writes JSON values, list items and env lines with a backup; disconnect puts back what was there", () => {
+test("connect writes JSON values, list items and env lines and records what was there; disconnect puts it back", () => {
const dir = temp();
const data = temp();
const settings = join(dir, "settings.json");
@@ -49,7 +53,7 @@ test("connect writes JSON values, list items and env lines with a backup; discon
applyEdits("workbuddy", edits, data);
assert.deepEqual(json(settings), { keep: true, env: { BASE: info.url }, extensions: ["mine.ts", "/x/extension.ts"], mcpServers: { cam: { command: "node" } } });
assert.equal(readFileSync(env, "utf8"), `KEY=secret\r\nBASE=${info.url}\r\nNEW=1\r\n`, "line endings kept, the key untouched");
- assert.equal(readdirSync(join(data, "config-backup", "workbuddy")).length, 2);
+ assert.equal(existsSync(join(data, "config-backup")), false, "no file is copied: settings and .env files may hold API keys");
applyEdits("workbuddy", edits, data); // a second connect remembers what was there before the first
undoEdits("workbuddy", data);
assert.deepEqual(json(settings), { keep: true, env: { BASE: "https://relay.example" }, extensions: ["mine.ts"], mcpServers: {} });
@@ -98,3 +102,48 @@ test("each platform reads where its requests go now and what to write", () => {
const p = pi.setup!({ home, env: { PI_PROVIDER: "anthropic" }, provider: null });
assert.equal(p.fallback, "https://api.anthropic.com", "the provider pi uses now, from its shell");
});
+
+test("v0.11, more platforms: Qwen Code, Cline, Kilo Code and goose are told apart by their own variables", () => {
+ assert.equal(detectPlatform({ QWEN_CODE: "1" }).platform, "qwen-code");
+ assert.equal(detectPlatform({ CLINE_ACTIVE: "true" }).platform, "cline");
+ assert.equal(detectPlatform({ KILO: "1" }).platform, "kilo-code");
+ assert.equal(detectPlatform({ GOOSE_TERMINAL: "1" }).platform, "goose");
+ assert.equal(detectPlatform({ OPENCODE: "1", KILO: "1" }).platform, null, "both: ask");
+});
+
+test("v0.11, more platforms: what Qwen Code, Cline, Kilo Code and goose read and write", () => {
+ const home = temp();
+ mkdirSync(join(home, ".qwen"));
+ writeFileSync(join(home, ".qwen", "settings.json"), JSON.stringify({ security: { auth: { selectedType: "openai" } }, model: { name: "b" }, modelProviders: { openai: [{ id: "a", baseUrl: "https://a.example/v1" }, { id: "b", baseUrl: "https://b.example/v1", envKey: "KEY" }] }, env: { KEY: "sk-secret" } }));
+ const qwen = qwenCode.setup!({ home, env: {}, provider: null });
+ assert.equal(qwen.current, "https://b.example/v1", "the model in use");
+ const data = temp();
+ applyEdits("qwen-code", qwen.edits(info), data);
+ const written = json(join(home, ".qwen", "settings.json"));
+ assert.equal(written.modelProviders.openai[1].baseUrl, info.url);
+ assert.equal(written.modelProviders.openai[0].baseUrl, "https://a.example/v1", "the other model stays");
+ assert.equal(written.env.KEY, "sk-secret", "the key stays where it was");
+ undoEdits("qwen-code", data);
+ assert.equal(json(join(home, ".qwen", "settings.json")).modelProviders.openai[1].baseUrl, "https://b.example/v1");
+ writeFileSync(join(home, ".qwen", "settings.json"), JSON.stringify({ security: { auth: { selectedType: "qwen-oauth" } } }));
+ assert.throws(() => qwenCode.setup!({ home, env: {}, provider: null }), /qwen-oauth/);
+
+ mkdirSync(join(home, ".cline", "data", "settings"), { recursive: true });
+ writeFileSync(join(home, ".cline", "data", "settings", "providers.json"), JSON.stringify({ version: 1, lastUsedProvider: "anthropic", providers: { anthropic: { settings: { provider: "anthropic", apiKey: "sk-ant" } } } }));
+ const c = cline.setup!({ home, env: {}, provider: null });
+ assert.equal(c.fallback, "https://api.anthropic.com/v1");
+ assert.deepEqual((c.edits(info)[0] as { json: string[] }).json, ["providers", "anthropic", "settings", "baseUrl"]);
+ assert.throws(() => cline.setup!({ home, env: {}, provider: "cline" }), /own account/);
+
+ mkdirSync(join(home, ".config", "kilo"), { recursive: true });
+ writeFileSync(join(home, ".config", "kilo", "kilo.json"), JSON.stringify({ model: "google/gemini-x" }));
+ assert.equal(kiloCode.setup!({ home, env: {}, provider: null }).fallback, "https://generativelanguage.googleapis.com/v1beta");
+
+ const appdata = temp();
+ const yaml = process.platform === "win32" ? join(appdata, "Block", "goose", "config") : join(home, ".config", "goose");
+ mkdirSync(yaml, { recursive: true });
+ writeFileSync(join(yaml, "config.yaml"), "GOOSE_PROVIDER: openai\nOPENAI_HOST: \"https://relay.example\"\n");
+ const g = goose.setup!({ home, env: { APPDATA: appdata }, provider: null });
+ assert.equal(g.current, "https://relay.example", "the address set in config.yaml");
+ assert.ok(g.manual, "YAML is not written: the steps are printed");
+});