A personal assistant that lives on your desktop, remembers what matters, and can use your Mac for you.
TypeScript
fix(connectors): stop reporting the computer registration as a blocked change
Alan Buscagliad099a891693e
diff --git a/packages/daemon/src/connectors.ts b/packages/daemon/src/connectors.tsindex b37243a..8127a8a 100644--- a/packages/daemon/src/connectors.ts+++ b/packages/daemon/src/connectors.ts@@ -568,14 +568,16 @@ export class ConnectorStore {* `report: false` only writes them (the daemon's start, where the files are what it just read).*/enforce(report = true): boolean {- const untouched = Object.keys(this.saved.connectors).length === 0 && !this.computer;+ // A missing file is untouched while it would hold nothing: the record before any connector is saved,+ // and mcp.json before any connector or the computer helper is in it.+ const noConnectors = Object.keys(this.saved.connectors).length === 0;const changed: string[] = [];- for (const [file, text] of [- [this.file, this.recordText()],- [this.mcpFile, renderMcpJson(this.saved, this.computer)],+ for (const [file, text, empty] of [+ [this.file, this.recordText(), noConnectors],+ [this.mcpFile, renderMcpJson(this.saved, this.computer), noConnectors && !this.computer],] as const) {const current = existsSync(file) ? readFileSync(file, "utf8") : undefined;- if (current === text || (current === undefined && untouched)) continue;+ if (current === text || (current === undefined && empty)) continue;mkdirSync(this.options.agentHome, { recursive: true, mode: 0o700 });writePrivate(file, text);changed.push(file);diff --git a/packages/daemon/test/computer.test.ts b/packages/daemon/test/computer.test.tsindex 554f580..7a0926a 100644--- a/packages/daemon/test/computer.test.ts+++ b/packages/daemon/test/computer.test.ts@@ -121,6 +121,17 @@ async function restarted(d: DotDaemon, pid: number | undefined) {}describe("computer control registration (S24.7)", () => {+ it("registering on an install with no saved connectors is not reported as a blocked change", async () => {+ const { send, logs, messages, servers, dataDir } = await setup();+ send({ type: "computer_register", url: HELPER, token: KEY });+ await waitFor(() => servers().computer);+ // Longer than the one-second backup check, so a late revert would show.+ await new Promise((resolve) => setTimeout(resolve, 1300));+ expect(logs.filter((line) => line.includes("put back"))).toEqual([]);+ expect(messages.filter((m) => m.type === "toast")).toEqual([]);+ expect(existsSync(join(dataDir, "connectors.json"))).toBe(false);+ });+it("renders the helper as a built-in direct server with the key in its header, and the key goes nowhere else", async () => {const {d,@@ -169,13 +180,16 @@ describe("computer control registration (S24.7)", () => {await find("connectors", (m) => computerOf(m.connectors) !== undefined);expect(computerOf(await second.list())).toBeDefined();- expect(readFileSync(join(dataDir, "connectors.json"), "utf8")).not.toContain("computer");+ // With no saved connector the record is never written; when it is, it never holds the helper.+ const recordFile = join(dataDir, "connectors.json");+ const record = existsSync(recordFile) ? readFileSync(recordFile, "utf8") : "";+ expect(record).not.toContain("computer");for (const text of [JSON.stringify(messages),JSON.stringify(second.messages),logs.join("\n"),agentEnv(),- readFileSync(join(dataDir, "connectors.json"), "utf8"),+ record,]) {expect(text).not.toContain(KEY);expect(text).not.toContain("51234");