@lysyi3m/sidecar 0.0.0-stage → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +285 -2
  3. package/dist/bin/sidecar-dashboard.js +27 -0
  4. package/dist/bin/sidecar-mcp.js +35 -0
  5. package/dist/bin/sidecar.js +70 -0
  6. package/dist/src/adapters/claude-code.js +333 -0
  7. package/dist/src/adapters/claude-desktop.js +184 -0
  8. package/dist/src/adapters/codex.js +383 -0
  9. package/dist/src/adapters/index.js +38 -0
  10. package/dist/src/adapters/installed.js +25 -0
  11. package/dist/src/adapters/outcome.js +30 -0
  12. package/dist/src/adapters/registration.js +69 -0
  13. package/dist/src/adapters/types.js +1 -0
  14. package/dist/src/cases/events.js +9 -0
  15. package/dist/src/cases/items.js +120 -0
  16. package/dist/src/cases/lock.js +80 -0
  17. package/dist/src/cases/opinion.js +58 -0
  18. package/dist/src/cases/state.js +121 -0
  19. package/dist/src/cases/store.js +181 -0
  20. package/dist/src/cases/usage.js +36 -0
  21. package/dist/src/cli/deps.js +18 -0
  22. package/dist/src/cli/lines.js +11 -0
  23. package/dist/src/cli/list.js +44 -0
  24. package/dist/src/cli/setup.js +202 -0
  25. package/dist/src/cli/status.js +111 -0
  26. package/dist/src/cli/style.js +26 -0
  27. package/dist/src/cli/ui.js +170 -0
  28. package/dist/src/cli/uninstall.js +73 -0
  29. package/dist/src/config.js +108 -0
  30. package/dist/src/dashboard/cases.js +109 -0
  31. package/dist/src/dashboard/html.js +31 -0
  32. package/dist/src/dashboard/links.js +35 -0
  33. package/dist/src/dashboard/marks.js +16 -0
  34. package/dist/src/dashboard/pages.js +516 -0
  35. package/dist/src/dashboard/server.js +305 -0
  36. package/dist/src/dashboard/service.js +138 -0
  37. package/dist/src/dashboard/static/agents/NOTICE +32 -0
  38. package/dist/src/dashboard/static/agents/claude-code.svg +1 -0
  39. package/dist/src/dashboard/static/agents/claude-desktop.svg +1 -0
  40. package/dist/src/dashboard/static/agents/codex.svg +1 -0
  41. package/dist/src/dashboard/static/app.css +1121 -0
  42. package/dist/src/dashboard/static/app.js +256 -0
  43. package/dist/src/dashboard/static/times.js +44 -0
  44. package/dist/src/dashboard/view.js +25 -0
  45. package/dist/src/lib/agent-process.js +57 -0
  46. package/dist/src/lib/atomic-write.js +35 -0
  47. package/dist/src/lib/command.js +20 -0
  48. package/dist/src/lib/failpoint.js +14 -0
  49. package/dist/src/lib/git.js +14 -0
  50. package/dist/src/lib/json.js +2 -0
  51. package/dist/src/lib/paths.js +19 -0
  52. package/dist/src/lib/proc.js +80 -0
  53. package/dist/src/lib/version.js +43 -0
  54. package/dist/src/mcp/server.js +800 -0
  55. package/dist/src/mcp/stdio.js +31 -0
  56. package/dist/src/mcp/tools.js +180 -0
  57. package/dist/src/turns/dispatch.js +188 -0
  58. package/dist/src/turns/knobs.js +14 -0
  59. package/dist/src/turns/prompt.js +284 -0
  60. package/dist/src/turns/runner.js +283 -0
  61. package/package.json +44 -4
@@ -0,0 +1,305 @@
1
+ import { createHash, timingSafeEqual } from "node:crypto";
2
+ import { existsSync, readdirSync, readFileSync } from "node:fs";
3
+ import { join } from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+ import { createAdaptorServer } from "@hono/node-server";
6
+ import { getConnInfo } from "@hono/node-server/conninfo";
7
+ import { Hono } from "hono";
8
+ import { streamSSE } from "hono/streaming";
9
+ import { isCaseId } from "../cases/store.js";
10
+ import { loadConfig } from "../config.js";
11
+ import { CaseIndex, stampOf, unchanged } from "./cases.js";
12
+ import { dashboardBase, isLoopbackHost } from "./links.js";
13
+ import { MARKS } from "./marks.js";
14
+ import { caseRows, casePage, caseUnits, indexPage, sideList } from "./pages.js";
15
+ import { caseModel } from "./view.js";
16
+ // The dashboard: a read-only web UI over the case store. Two pages — the case index at / and one
17
+ // case at /cases/<id> — rendered on the server (pages.ts) from the view model (view.ts), styled by
18
+ // ./static/app.css, and kept live by ./static/app.js: the case page through server-sent patches,
19
+ // the case lists by refetching their fragments. It runs as its own process — a per-user service
20
+ // installed by `sidecar setup` (see service.ts) — and knows nothing about MCP or agents.
21
+ //
22
+ // Access: a loopback client needs no token, but its Host must be a loopback name, which blocks
23
+ // DNS-rebinding pages. Any other client must present the access token; without one the dashboard
24
+ // refuses to listen beyond loopback. See docs/design.md → Dashboard.
25
+ const POLL_MS = 1_000;
26
+ /** How long one write to a case stream may wait for a reader that stopped reading. */
27
+ const STREAM_WRITE_MS = 30_000;
28
+ /**
29
+ * A stream that has written nothing for this long sends a comment. Without traffic, a peer that
30
+ * vanished without closing, e.g. a laptop that went to sleep, would hold its stream for good; with
31
+ * it, the kernel gives up retransmitting, the connection closes, and the stream ends.
32
+ */
33
+ const HEARTBEAT_MS = 30_000;
34
+ const STATIC = fileURLToPath(new URL("./static/", import.meta.url));
35
+ /** A strong validator for a response body: a browser sends it back to learn the body is unchanged. */
36
+ const etagOf = (body) => `"${createHash("sha256").update(body).digest("base64url").slice(0, 27)}"`;
37
+ /**
38
+ * Static files, read once at start and served by name from that allowlist: no request path ever
39
+ * reaches the disk. A code change needs a service restart anyway.
40
+ */
41
+ const ASSETS = new Map(readdirSync(STATIC)
42
+ .filter((name) => /^[\w-]+\.(css|js)$/.test(name))
43
+ .map((name) => {
44
+ const body = readFileSync(join(STATIC, name), "utf8");
45
+ const type = name.endsWith(".css")
46
+ ? "text/css; charset=utf-8"
47
+ : "text/javascript; charset=utf-8";
48
+ return [name, { body, type, etag: etagOf(body) }];
49
+ }));
50
+ const COOKIE = "sidecar_token";
51
+ const SIDEBAR_COOKIE = "sidecar_sidebar";
52
+ /** A client's address; a dual-stack listener reports an IPv4 client in its IPv4-mapped form. */
53
+ const isLoopbackAddress = (address) => isLoopbackHost(address.replace(/^::ffff:(?=[\d.]+$)/i, ""));
54
+ export async function startDashboard(store, opts = {}) {
55
+ const host = opts.host ?? "127.0.0.1";
56
+ if (!isLoopbackHost(host) && !opts.token) {
57
+ throw new Error(`refusing to serve the dashboard on ${host} without an access token; run \`sidecar setup\``);
58
+ }
59
+ const server = createAdaptorServer({
60
+ fetch: app(store, () => server.address().port, opts.token, {
61
+ streamWriteMs: opts.streamWriteMs ?? STREAM_WRITE_MS,
62
+ }).fetch,
63
+ });
64
+ await new Promise((resolve, reject) => {
65
+ server.once("error", reject);
66
+ server.listen({ host, port: opts.port ?? 0 }, () => resolve());
67
+ });
68
+ const { port: bound } = server.address();
69
+ return {
70
+ url: dashboardBase(bound, host),
71
+ close: () => new Promise((resolve) => {
72
+ server.closeAllConnections();
73
+ server.close(() => resolve());
74
+ }),
75
+ };
76
+ }
77
+ /**
78
+ * A Host header names this dashboard on loopback: a loopback name and the port it listens on. A
79
+ * browser leaves out port 80. A DNS-rebinding page sends its own domain name, never one of these.
80
+ */
81
+ function loopbackHostHeader(header, port) {
82
+ const m = /^(?:\[([^\]]+)\]|([^:[\]]+))(?::(\d+))?$/.exec(header);
83
+ if (!m)
84
+ return false;
85
+ const name = (m[1] ?? m[2]).toLowerCase();
86
+ return ((m[1] !== undefined ? name === "::1" : isLoopbackHost(name)) && Number(m[3] ?? 80) === port);
87
+ }
88
+ export function authorize(req, port, token) {
89
+ if (isLoopbackAddress(req.remoteAddress ?? "")) {
90
+ if (!loopbackHostHeader(req.host ?? "", port))
91
+ return { kind: "deny", status: 403, reason: "forbidden host" };
92
+ // Loopback needs no token, but one pasted into the URL still leaves the address bar.
93
+ const url = new URL(req.url, "http://x");
94
+ if (!url.searchParams.has("token"))
95
+ return { kind: "allow" };
96
+ url.searchParams.delete("token");
97
+ return { kind: "redirect", location: url.pathname + url.search };
98
+ }
99
+ // A remote client. The token also defeats DNS rebinding: a rebinding page runs under a foreign
100
+ // origin, and the browser never sends it this host's cookie.
101
+ if (!token)
102
+ return { kind: "deny", status: 403, reason: "network access is not enabled" };
103
+ const url = new URL(req.url, "http://x");
104
+ const offered = url.searchParams.get("token");
105
+ if (offered !== null) {
106
+ if (!same(offered, token))
107
+ return { kind: "deny", status: 401, reason: "wrong access token" };
108
+ url.searchParams.delete("token");
109
+ return {
110
+ kind: "redirect",
111
+ location: url.pathname + url.search,
112
+ setCookie: `${COOKIE}=${token}; HttpOnly; SameSite=Strict; Path=/; Max-Age=31536000`,
113
+ };
114
+ }
115
+ const fromCookie = cookieValue(req.cookie, COOKIE);
116
+ return fromCookie !== undefined && same(fromCookie, token)
117
+ ? { kind: "allow" }
118
+ : {
119
+ kind: "deny",
120
+ status: 401,
121
+ reason: "access token required: open the dashboard link `sidecar status` prints",
122
+ };
123
+ }
124
+ const cookieValue = (header, name) => (header ?? "")
125
+ .split(";")
126
+ .map((c) => c.trim().split("="))
127
+ .find(([key]) => key === name)?.[1];
128
+ /**
129
+ * The sidebar's state, which the browser keeps in a cookie (static/app.js) rather than in storage
130
+ * only a script can read: the server renders it, so a page never paints the sidebar open first.
131
+ */
132
+ const sidebarCollapsed = (header) => cookieValue(header, SIDEBAR_COOKIE) === "collapsed";
133
+ /** Constant-time comparison, so response timing does not leak the token. */
134
+ function same(a, b) {
135
+ const x = Buffer.from(a);
136
+ const y = Buffer.from(b);
137
+ return x.length === y.length && timingSafeEqual(x, y);
138
+ }
139
+ function app(store, port, token, limits) {
140
+ const web = new Hono();
141
+ const cases = new CaseIndex(store);
142
+ const htmlResponse = (body) => new Response(body.value, {
143
+ headers: { "content-type": "text/html; charset=utf-8", "cache-control": "no-store" },
144
+ });
145
+ /**
146
+ * A list fragment with its validator: the list's version for this URL, so an unchanged list is
147
+ * answered before anything is rendered. The page sends it back and keeps its markup on a 304:
148
+ * case lists change far less often than the pages poll them.
149
+ */
150
+ const fragmentResponse = async (c, render) => {
151
+ const list = await cases.list();
152
+ const etag = etagOf(`${list.version} ${c.req.url}`);
153
+ if (c.req.header("if-none-match") === etag)
154
+ return new Response(null, { status: 304, headers: { etag, "cache-control": "no-store" } });
155
+ return new Response(render(list).value, {
156
+ headers: { "content-type": "text/html; charset=utf-8", "cache-control": "no-store", etag },
157
+ });
158
+ };
159
+ web.use(async (c, next) => {
160
+ // Set first, so refusals and errors are never cached either.
161
+ c.header("cache-control", "no-store");
162
+ const url = new URL(c.req.url);
163
+ const access = authorize({
164
+ remoteAddress: getConnInfo(c).remote.address,
165
+ host: c.req.header("host"),
166
+ url: url.pathname + url.search,
167
+ cookie: c.req.header("cookie"),
168
+ }, port(), token);
169
+ if (access.kind === "deny")
170
+ return c.text(access.reason, access.status);
171
+ if (access.kind === "redirect") {
172
+ return new Response(null, {
173
+ status: 303,
174
+ headers: {
175
+ location: access.location,
176
+ "cache-control": "no-store",
177
+ ...(access.setCookie ? { "set-cookie": access.setCookie } : {}),
178
+ },
179
+ });
180
+ }
181
+ if (c.req.method !== "GET")
182
+ return c.text("read-only", 405);
183
+ await next();
184
+ });
185
+ // A missing case is a 404. A page of a case that cannot be read reaches onError, with its reason;
186
+ // the stream reports that reason as a `problem` event.
187
+ const exists = (caseId) => isCaseId(caseId) && existsSync(store.logPath(caseId));
188
+ const NO_CASE = "no such case";
189
+ web.get("/", async (c) => htmlResponse(indexPage((await cases.list()).cases, { state: c.req.query("state"), search: c.req.query("search") }, { collapsed: sidebarCollapsed(c.req.header("cookie")) })));
190
+ web.get("/cases/:id", async (c) => {
191
+ const caseId = c.req.param("id");
192
+ if (!exists(caseId))
193
+ return c.text(NO_CASE, 404);
194
+ return htmlResponse(casePage(caseModel(caseId, await store.read(caseId), reviewBudget(store)), (await cases.list()).cases, { collapsed: sidebarCollapsed(c.req.header("cookie")) }));
195
+ });
196
+ web.get("/fragments/sidebar", (c) => {
197
+ const active = c.req.query("active");
198
+ return fragmentResponse(c, (list) => sideList(list.cases, active && isCaseId(active) ? active : null));
199
+ });
200
+ web.get("/fragments/cases", (c) => fragmentResponse(c, (list) => caseRows(list.cases)));
201
+ web.get("/assets/agents/:name{[a-z0-9-]+\\.svg}", (c) => {
202
+ const mark = MARKS.get(c.req.param("name").slice(0, -".svg".length));
203
+ // A mark changes only with a release; private, since access may need the token.
204
+ return mark
205
+ ? c.body(mark.svg, 200, {
206
+ "content-type": "image/svg+xml",
207
+ "cache-control": "private, max-age=86400",
208
+ })
209
+ : c.text("not found", 404);
210
+ });
211
+ web.get("/assets/:name", (c) => {
212
+ const asset = ASSETS.get(c.req.param("name"));
213
+ if (!asset)
214
+ return c.text("not found", 404);
215
+ // Revalidated on each use rather than cached for a time, so a restart with new code shows at once.
216
+ const headers = { etag: asset.etag, "cache-control": "private, no-cache" };
217
+ return c.req.header("if-none-match") === asset.etag
218
+ ? c.body(null, 304, headers)
219
+ : c.body(asset.body, 200, { ...headers, "content-type": asset.type });
220
+ });
221
+ web.get("/api/cases/:id{[0-9a-f]{8}}/stream", (c) => {
222
+ const caseId = c.req.param("id");
223
+ return exists(caseId)
224
+ ? patches(c, store, caseId, Number(c.req.query("after") ?? -1), limits.streamWriteMs)
225
+ : c.text(NO_CASE, 404);
226
+ });
227
+ web.notFound((c) => c.text("not found", 404));
228
+ // An unreadable case, for one: the reason, not a generic page.
229
+ web.onError((err, c) => c.text(err.message, 500));
230
+ return web;
231
+ }
232
+ /** Read when a page or patch renders, so an edit applies to the next render without a restart. */
233
+ const reviewBudget = (store) => loadConfig(store.options.home).reviewBudget;
234
+ /**
235
+ * Server-sent patches for one case page. The page names the last event it rendered (`after`); the
236
+ * stream renders the page's parts as of that event, then on each poll that finds new events renders
237
+ * them again and sends only the parts whose markup changed, in page order. A reconnect sends the
238
+ * same `after`, so it gets every change since the page loaded; replacing a part twice is harmless.
239
+ * A poll that fails sends its reason as a `problem` event, once per reason; the next poll that
240
+ * succeeds sends an empty `problem`, which clears it.
241
+ *
242
+ * A poll reads the log only when its stamp changed since this stream's last read: an idle case
243
+ * costs one stat a second. Each stream keeps its own stamp, so no other reader's refresh can make
244
+ * it skip a change.
245
+ */
246
+ function patches(c, store, caseId, after, writeMs) {
247
+ return streamSSE(c, async (stream) => {
248
+ // Awaited, so a slow reader holds the loop instead of growing a buffer. A reader that stops
249
+ // reading for writeMs loses its connection; its page reconnects with the event it last applied.
250
+ let wrote = Date.now();
251
+ const bounded = async (write) => {
252
+ const timer = setTimeout(() => c.env.outgoing.destroy(), writeMs);
253
+ try {
254
+ await write;
255
+ }
256
+ finally {
257
+ clearTimeout(timer);
258
+ wrote = Date.now();
259
+ }
260
+ };
261
+ const send = (event, data) => bounded(stream.writeSSE({ event, data }));
262
+ const file = store.logPath(caseId);
263
+ let seen;
264
+ let sent;
265
+ let last = Number.isInteger(after) ? after : -1;
266
+ let problem = "";
267
+ while (!stream.aborted) {
268
+ try {
269
+ const stamp = stampOf(file);
270
+ // A missing log is read too, so its absence is reported like any other failure.
271
+ if (!stamp || !unchanged(seen, stamp)) {
272
+ const events = await store.read(caseId);
273
+ seen = stamp;
274
+ const budget = reviewBudget(store);
275
+ sent ??= new Map(last >= 0
276
+ ? caseUnits(caseModel(caseId, events.filter((e) => e.n <= last), budget)).map((u) => [u.id, u.html])
277
+ : []);
278
+ if (events.length > 0 && events.at(-1).n > last) {
279
+ const units = caseUnits(caseModel(caseId, events, budget));
280
+ const changed = units.filter((u) => sent.get(u.id) !== u.html);
281
+ sent = new Map(units.map((u) => [u.id, u.html]));
282
+ last = events.at(-1).n;
283
+ if (changed.length)
284
+ await send("patch", changed.map((u) => u.html).join("\n"));
285
+ }
286
+ }
287
+ if (problem) {
288
+ problem = "";
289
+ await send("problem", "");
290
+ }
291
+ }
292
+ catch (err) {
293
+ seen = undefined;
294
+ const reason = err.message || "the case could not be read";
295
+ if (reason !== problem) {
296
+ problem = reason;
297
+ await send("problem", reason);
298
+ }
299
+ }
300
+ if (Date.now() - wrote >= HEARTBEAT_MS)
301
+ await bounded(stream.write(": heartbeat\n\n"));
302
+ await stream.sleep(POLL_MS);
303
+ }
304
+ });
305
+ }
@@ -0,0 +1,138 @@
1
+ import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
2
+ import { homedir, userInfo } from "node:os";
3
+ import { join } from "node:path";
4
+ import { DEFAULT_HOME } from "../config.js";
5
+ import { exec } from "../lib/command.js";
6
+ import { modulePath } from "../lib/paths.js";
7
+ // Runs the dashboard as a per-user service, so it is up whenever the user is logged in: a systemd
8
+ // user unit on Linux, a launchd agent on macOS. The service runs bin/sidecar-dashboard.ts in the
9
+ // foreground; it has nothing to do with MCP or agent sessions.
10
+ export const UNIT = "sidecar-dashboard.service";
11
+ const LABEL = "dev.lysyi3m.sidecar.dashboard";
12
+ const ENTRY = modulePath("../../bin/sidecar-dashboard", import.meta.url);
13
+ export function defaultSpec(home) {
14
+ return {
15
+ node: process.execPath,
16
+ entry: ENTRY,
17
+ ...(home !== DEFAULT_HOME ? { home } : {}),
18
+ logFile: join(home, "dashboard.log"),
19
+ };
20
+ }
21
+ /**
22
+ * systemd quotes arguments with double quotes; backslashes and quotes inside are escaped, and `%`
23
+ * doubled, since it starts a specifier.
24
+ */
25
+ const sdQuote = (arg) => `"${arg.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/%/g, "%%")}"`;
26
+ /** ExecStart also expands `$NAME` and `${NAME}`; Environment= does not. */
27
+ const sdExecArg = (arg) => sdQuote(arg).replace(/\$/g, "$$$$");
28
+ export function systemdUnit(spec) {
29
+ return [
30
+ "[Unit]",
31
+ "Description=sidecar case dashboard",
32
+ "",
33
+ "[Service]",
34
+ `ExecStart=${[spec.node, spec.entry].map(sdExecArg).join(" ")}`,
35
+ ...(spec.home ? [`Environment=${sdQuote(`SIDECAR_HOME=${spec.home}`)}`] : []),
36
+ "Restart=on-failure",
37
+ "RestartSec=5",
38
+ "",
39
+ "[Install]",
40
+ "WantedBy=default.target",
41
+ "",
42
+ ].join("\n");
43
+ }
44
+ const xml = (text) => text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
45
+ export function launchdPlist(spec) {
46
+ const env = spec.home
47
+ ? ` <key>EnvironmentVariables</key>\n <dict><key>SIDECAR_HOME</key><string>${xml(spec.home)}</string></dict>\n`
48
+ : "";
49
+ return `<?xml version="1.0" encoding="UTF-8"?>
50
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
51
+ <plist version="1.0">
52
+ <dict>
53
+ <key>Label</key><string>${LABEL}</string>
54
+ <key>ProgramArguments</key>
55
+ <array>
56
+ <string>${xml(spec.node)}</string>
57
+ <string>${xml(spec.entry)}</string>
58
+ </array>
59
+ ${env} <key>RunAtLoad</key><true/>
60
+ <key>KeepAlive</key><dict><key>SuccessfulExit</key><false/></dict>
61
+ <key>StandardOutPath</key><string>${xml(spec.logFile)}</string>
62
+ <key>StandardErrorPath</key><string>${xml(spec.logFile)}</string>
63
+ </dict>
64
+ </plist>
65
+ `;
66
+ }
67
+ function servicePaths(platform = process.platform) {
68
+ const file = platform === "darwin"
69
+ ? join(homedir(), "Library", "LaunchAgents", `${LABEL}.plist`)
70
+ : join(process.env.XDG_CONFIG_HOME ?? join(homedir(), ".config"), "systemd", "user", UNIT);
71
+ return { platform, file };
72
+ }
73
+ function check(result, what) {
74
+ if (!result.ok)
75
+ throw new Error(`${what} failed: ${result.output}`);
76
+ }
77
+ const UNLOAD_DEADLINE_MS = 10_000;
78
+ const pause = (ms) => {
79
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
80
+ };
81
+ /**
82
+ * `bootout` can return while launchd still holds the job, and a `bootstrap` issued then fails with
83
+ * "5: Input/output error". So wait until `print` no longer finds it.
84
+ */
85
+ function bootout(target, run, wait) {
86
+ run({ command: "launchctl", args: ["bootout", target] }); // absent on a first install
87
+ const deadline = Date.now() + UNLOAD_DEADLINE_MS;
88
+ while (run({ command: "launchctl", args: ["print", target] }).ok) {
89
+ if (Date.now() >= deadline)
90
+ throw new Error(`launchctl bootout: ${target} is still loaded after ${UNLOAD_DEADLINE_MS / 1000} s`);
91
+ wait(100);
92
+ }
93
+ }
94
+ /** Installs (or replaces) the service and starts it now and at every login. */
95
+ export function installService(spec, paths = servicePaths(), run = exec, wait = pause) {
96
+ mkdirSync(join(paths.file, ".."), { recursive: true });
97
+ if (paths.platform === "darwin") {
98
+ const domain = `gui/${userInfo().uid}`;
99
+ bootout(`${domain}/${LABEL}`, run, wait);
100
+ writeFileSync(paths.file, launchdPlist(spec));
101
+ check(run({ command: "launchctl", args: ["bootstrap", domain, paths.file] }), "launchctl bootstrap");
102
+ return;
103
+ }
104
+ writeFileSync(paths.file, systemdUnit(spec));
105
+ check(run({ command: "systemctl", args: ["--user", "daemon-reload"] }), "systemctl --user daemon-reload");
106
+ // A unit that hit its start limit refuses every start until its failed state is reset. Unchecked: a
107
+ // unit that has not failed has nothing to reset.
108
+ run({ command: "systemctl", args: ["--user", "reset-failed", UNIT] });
109
+ check(run({ command: "systemctl", args: ["--user", "enable", "--now", UNIT] }), `systemctl --user enable --now ${UNIT}`);
110
+ // enable --now does not restart a unit that was already running an older ExecStart.
111
+ check(run({ command: "systemctl", args: ["--user", "restart", UNIT] }), `systemctl --user restart ${UNIT}`);
112
+ }
113
+ /** Stops the service and removes it. Throws, leaving the file, when the service cannot be stopped. */
114
+ export function uninstallService(paths = servicePaths(), run = exec, wait = pause) {
115
+ if (paths.platform === "darwin") {
116
+ bootout(`gui/${userInfo().uid}/${LABEL}`, run, wait);
117
+ }
118
+ else {
119
+ check(run({ command: "systemctl", args: ["--user", "disable", "--now", UNIT] }), `systemctl --user disable --now ${UNIT}`);
120
+ }
121
+ if (existsSync(paths.file))
122
+ rmSync(paths.file);
123
+ if (paths.platform !== "darwin")
124
+ run({ command: "systemctl", args: ["--user", "daemon-reload"] });
125
+ }
126
+ export function serviceStatus(spec, paths = servicePaths(), run = exec) {
127
+ if (!existsSync(paths.file))
128
+ return { installed: false, current: false, running: false };
129
+ const expected = paths.platform === "darwin" ? launchdPlist(spec) : systemdUnit(spec);
130
+ const running = paths.platform === "darwin"
131
+ ? run({
132
+ command: "launchctl",
133
+ args: ["print", `gui/${userInfo().uid}/${LABEL}`],
134
+ }).output.includes("state = running")
135
+ : run({ command: "systemctl", args: ["--user", "is-active", UNIT] }).output.trim() ===
136
+ "active";
137
+ return { installed: true, current: readFileSync(paths.file, "utf8") === expected, running };
138
+ }
@@ -0,0 +1,32 @@
1
+ The marks in this directory are copied unchanged from @lobehub/icons-static-svg 1.95.1:
2
+
3
+ claude-code.svg icons/claudecode.svg
4
+ codex.svg icons/codex.svg
5
+ claude-desktop.svg icons/claude.svg
6
+
7
+ Each mark is a trademark of its owner and identifies the agent only. A file is named by the
8
+ adapter id whose app it shows.
9
+
10
+ The icon set is distributed under this license:
11
+
12
+ MIT License
13
+
14
+ Copyright (c) 2023 LobeHub
15
+
16
+ Permission is hereby granted, free of charge, to any person obtaining a copy
17
+ of this software and associated documentation files (the "Software"), to deal
18
+ in the Software without restriction, including without limitation the rights
19
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
20
+ copies of the Software, and to permit persons to whom the Software is
21
+ furnished to do so, subject to the following conditions:
22
+
23
+ The above copyright notice and this permission notice shall be included in all
24
+ copies or substantial portions of the Software.
25
+
26
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
29
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
31
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ <svg fill="currentColor" fill-rule="evenodd" height="1em" style="flex:none;line-height:1" viewBox="0 0 24 24" width="1em" xmlns="http://www.w3.org/2000/svg"><title>Claude Code</title><path clip-rule="evenodd" d="M20.998 10.949H24v3.102h-3v3.028h-1.487V20H18v-2.921h-1.487V20H15v-2.921H9V20H7.488v-2.921H6V20H4.487v-2.921H3V14.05H0V10.95h3V5h17.998v5.949zM6 10.949h1.488V8.102H6v2.847zm10.51 0H18V8.102h-1.49v2.847z"></path></svg>
@@ -0,0 +1 @@
1
+ <svg fill="currentColor" fill-rule="evenodd" height="1em" style="flex:none;line-height:1" viewBox="0 0 24 24" width="1em" xmlns="http://www.w3.org/2000/svg"><title>Claude</title><path d="M4.709 15.955l4.72-2.647.08-.23-.08-.128H9.2l-.79-.048-2.698-.073-2.339-.097-2.266-.122-.571-.121L0 11.784l.055-.352.48-.321.686.06 1.52.103 2.278.158 1.652.097 2.449.255h.389l.055-.157-.134-.098-.103-.097-2.358-1.596-2.552-1.688-1.336-.972-.724-.491-.364-.462-.158-1.008.656-.722.881.06.225.061.893.686 1.908 1.476 2.491 1.833.365.304.145-.103.019-.073-.164-.274-1.355-2.446-1.446-2.49-.644-1.032-.17-.619a2.97 2.97 0 01-.104-.729L6.283.134 6.696 0l.996.134.42.364.62 1.414 1.002 2.229 1.555 3.03.456.898.243.832.091.255h.158V9.01l.128-1.706.237-2.095.23-2.695.08-.76.376-.91.747-.492.584.28.48.685-.067.444-.286 1.851-.559 2.903-.364 1.942h.212l.243-.242.985-1.306 1.652-2.064.73-.82.85-.904.547-.431h1.033l.76 1.129-.34 1.166-1.064 1.347-.881 1.142-1.264 1.7-.79 1.36.073.11.188-.02 2.856-.606 1.543-.28 1.841-.315.833.388.091.395-.328.807-1.969.486-2.309.462-3.439.813-.042.03.049.061 1.549.146.662.036h1.622l3.02.225.79.522.474.638-.079.485-1.215.62-1.64-.389-3.829-.91-1.312-.329h-.182v.11l1.093 1.068 2.006 1.81 2.509 2.33.127.578-.322.455-.34-.049-2.205-1.657-.851-.747-1.926-1.62h-.128v.17l.444.649 2.345 3.521.122 1.08-.17.353-.608.213-.668-.122-1.374-1.925-1.415-2.167-1.143-1.943-.14.08-.674 7.254-.316.37-.729.28-.607-.461-.322-.747.322-1.476.389-1.924.315-1.53.286-1.9.17-.632-.012-.042-.14.018-1.434 1.967-2.18 2.945-1.726 1.845-.414.164-.717-.37.067-.662.401-.589 2.388-3.036 1.44-1.882.93-1.086-.006-.158h-.055L4.132 18.56l-1.13.146-.487-.456.061-.746.231-.243 1.908-1.312-.006.006z"></path></svg>
@@ -0,0 +1 @@
1
+ <svg fill="currentColor" fill-rule="evenodd" height="1em" style="flex:none;line-height:1" viewBox="0 0 24 24" width="1em" xmlns="http://www.w3.org/2000/svg"><title>Codex</title><path clip-rule="evenodd" d="M8.086.457a6.105 6.105 0 013.046-.415c1.333.153 2.521.72 3.564 1.7a.117.117 0 00.107.029c1.408-.346 2.762-.224 4.061.366l.063.03.154.076c1.357.703 2.33 1.77 2.918 3.198.278.679.418 1.388.421 2.126a5.655 5.655 0 01-.18 1.631.167.167 0 00.04.155 5.982 5.982 0 011.578 2.891c.385 1.901-.01 3.615-1.183 5.14l-.182.22a6.063 6.063 0 01-2.934 1.851.162.162 0 00-.108.102c-.255.736-.511 1.364-.987 1.992-1.199 1.582-2.962 2.462-4.948 2.451-1.583-.008-2.986-.587-4.21-1.736a.145.145 0 00-.14-.032c-.518.167-1.04.191-1.604.185a5.924 5.924 0 01-2.595-.622 6.058 6.058 0 01-2.146-1.781c-.203-.269-.404-.522-.551-.821a7.74 7.74 0 01-.495-1.283 6.11 6.11 0 01-.017-3.064.166.166 0 00.008-.074.115.115 0 00-.037-.064 5.958 5.958 0 01-1.38-2.202 5.196 5.196 0 01-.333-1.589 6.915 6.915 0 01.188-2.132c.45-1.484 1.309-2.648 2.577-3.493.282-.188.55-.334.802-.438.286-.12.573-.22.861-.304a.129.129 0 00.087-.087A6.016 6.016 0 015.635 2.31C6.315 1.464 7.132.846 8.086.457zm-.804 7.85a.848.848 0 00-1.473.842l1.694 2.965-1.688 2.848a.849.849 0 001.46.864l1.94-3.272a.849.849 0 00.007-.854l-1.94-3.393zm5.446 6.24a.849.849 0 000 1.695h4.848a.849.849 0 000-1.696h-4.848z"></path></svg>