Skip to content
102 linesCodeBlameRaw

Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.

The plan says what g1t is for without measuring it against other products1import assert from "node:assert/strict";
2import { test } from "node:test";
3
4import {
5 AGENTS,
6 AGENT_IDS,
7 AGENT_STORAGE_KEY,
8 DEFAULT_AGENT,
9 MCP_URL,
Merge branch 'worktree-agent-aaf03bdceac799c89'10 agentsFor,
The plan says what g1t is for without measuring it against other products11 cursorInstallLink,
12 getAgentChoice,
13 parseAgent,
14 readAgentChoice,
15 setAgentChoice,
16 subscribeAgentChoice,
17 writeAgentChoice,
18} from "./agent-setup.ts";
19
20function memory() {
21 const map = new Map<string, string>();
22 return {
23 getItem: (key: string) => map.get(key) ?? null,
24 setItem: (key: string, value: string) => void map.set(key, value),
25 map,
26 };
27}
28
29const throwing = {
30 getItem: () => {
31 throw new Error("blocked");
32 },
33 setItem: () => {
34 throw new Error("blocked");
35 },
36};
37
38test("a choice is remembered and read back", () => {
39 const store = memory();
40 assert.equal(writeAgentChoice(() => store, "codex"), true);
41 assert.equal(store.map.get(AGENT_STORAGE_KEY), "codex");
42 assert.equal(readAgentChoice(() => store), "codex");
43});
44
45test("no choice, an unknown one, or storage that throws falls back to the default", () => {
46 assert.equal(readAgentChoice(() => memory()), DEFAULT_AGENT);
47 const store = memory();
48 store.setItem(AGENT_STORAGE_KEY, "notepad");
49 assert.equal(readAgentChoice(() => store), DEFAULT_AGENT);
50 assert.equal(readAgentChoice(() => throwing), DEFAULT_AGENT);
51 assert.equal(readAgentChoice(() => null), DEFAULT_AGENT);
52 assert.equal(
53 readAgentChoice(() => {
54 throw new Error("no localStorage");
55 }),
56 DEFAULT_AGENT,
57 );
58 assert.equal(writeAgentChoice(() => throwing, "cursor"), false);
59 assert.equal(writeAgentChoice(() => null, "cursor"), false);
60});
61
62test("every toggle on the page follows the last choice", () => {
63 const store = memory();
64 let heard = 0;
65 const stop = subscribeAgentChoice(() => heard++);
66 setAgentChoice("opencode", () => store);
67 assert.equal(getAgentChoice(), "opencode");
68 assert.equal(store.map.get(AGENT_STORAGE_KEY), "opencode");
69 assert.equal(heard, 1);
70 // Storage that refuses still changes the page.
71 setAgentChoice("cursor", () => throwing);
72 assert.equal(getAgentChoice(), "cursor");
73 assert.equal(heard, 2);
74 stop();
75 setAgentChoice("codex", () => store);
76 assert.equal(heard, 2);
77});
78
79test("parseAgent accepts only known agents", () => {
80 for (const id of AGENT_IDS) assert.equal(parseAgent(id), id);
81 assert.equal(parseAgent("Claude Code"), null);
82 assert.equal(parseAgent(null), null);
83});
84
85test("every snippet points at the MCP server", () => {
86 for (const id of AGENT_IDS) assert.ok(AGENTS[id].code.includes(MCP_URL), id);
87 assert.deepEqual(JSON.parse(AGENTS.cursor.code), { mcpServers: { g1t: { url: MCP_URL } } });
88 assert.equal(JSON.parse(AGENTS.opencode.code).mcp.g1t.type, "remote");
89 const config = new URL(cursorInstallLink()).searchParams.get("config");
90 assert.deepEqual(JSON.parse(atob(config ?? "")), { url: MCP_URL });
91});
Merge branch 'worktree-agent-aaf03bdceac799c89'92
93test("the snippets can point at another MCP server", () => {
94 const mcp = "http://localhost:8790/mcp";
95 const agents = agentsFor(mcp);
96 for (const id of AGENT_IDS) {
97 assert.ok(agents[id].code.includes(mcp), id);
98 assert.ok(!agents[id].code.includes(MCP_URL), id);
99 }
100 const config = new URL(cursorInstallLink(mcp)).searchParams.get("config");
101 assert.deepEqual(JSON.parse(atob(config ?? "")), { url: mcp });
102});

This file's history is long; its oldest lines are credited to the oldest commit read.