@harness-sdk/harnessd 0.0.0-stage → 0.0.1

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 (53) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +63 -2
  3. package/dist/bin.d.ts +3 -0
  4. package/dist/bin.d.ts.map +1 -0
  5. package/dist/bin.js +15 -0
  6. package/dist/bin.js.map +1 -0
  7. package/dist/channel.d.ts +56 -0
  8. package/dist/channel.d.ts.map +1 -0
  9. package/dist/channel.js +356 -0
  10. package/dist/channel.js.map +1 -0
  11. package/dist/claude.d.ts +42 -0
  12. package/dist/claude.d.ts.map +1 -0
  13. package/dist/claude.js +166 -0
  14. package/dist/claude.js.map +1 -0
  15. package/dist/cli.d.ts +8 -0
  16. package/dist/cli.d.ts.map +1 -0
  17. package/dist/cli.js +258 -0
  18. package/dist/cli.js.map +1 -0
  19. package/dist/config.d.ts +43 -0
  20. package/dist/config.d.ts.map +1 -0
  21. package/dist/config.js +121 -0
  22. package/dist/config.js.map +1 -0
  23. package/dist/daemon.d.ts +24 -0
  24. package/dist/daemon.d.ts.map +1 -0
  25. package/dist/daemon.js +239 -0
  26. package/dist/daemon.js.map +1 -0
  27. package/dist/launchd.d.ts +22 -0
  28. package/dist/launchd.d.ts.map +1 -0
  29. package/dist/launchd.js +88 -0
  30. package/dist/launchd.js.map +1 -0
  31. package/dist/log.d.ts +3 -0
  32. package/dist/log.d.ts.map +1 -0
  33. package/dist/log.js +17 -0
  34. package/dist/log.js.map +1 -0
  35. package/dist/terminal.d.ts +11 -0
  36. package/dist/terminal.d.ts.map +1 -0
  37. package/dist/terminal.js +36 -0
  38. package/dist/terminal.js.map +1 -0
  39. package/dist/watchdog.d.ts +73 -0
  40. package/dist/watchdog.d.ts.map +1 -0
  41. package/dist/watchdog.js +230 -0
  42. package/dist/watchdog.js.map +1 -0
  43. package/package.json +54 -4
  44. package/src/bin.ts +18 -0
  45. package/src/channel.ts +461 -0
  46. package/src/claude.ts +274 -0
  47. package/src/cli.ts +372 -0
  48. package/src/config.ts +203 -0
  49. package/src/daemon.ts +312 -0
  50. package/src/launchd.ts +126 -0
  51. package/src/log.ts +17 -0
  52. package/src/terminal.ts +33 -0
  53. package/src/watchdog.ts +310 -0
package/dist/claude.js ADDED
@@ -0,0 +1,166 @@
1
+ import { accessSync, constants, existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
2
+ import { execFile } from "node:child_process";
3
+ import { homedir } from "node:os";
4
+ import { delimiter, join } from "node:path";
5
+ // src/claude.ts
6
+ /** How Claude Code names a `--plugin-dir` plugin, and what `--channels` takes. */
7
+ const PLUGIN = "harnessd@inline";
8
+ const MANAGED_SETTINGS = "/Library/Application Support/ClaudeCode/managed-settings.json";
9
+ const claudeDir = (env) => env.CLAUDE_CONFIG_DIR || join(homedir(), ".claude");
10
+ /**
11
+ * Records the folder as trusted where Claude Code keeps its answer to the trust dialog (its global config's
12
+ * `projects[<folder>].hasTrustDialogAccepted`), so an unattended start doesn't stop at that dialog. Only that field
13
+ * changes; a Mac where Claude Code never ran has no config yet, and the dialog comes with the sign-in.
14
+ */
15
+ const trustFolder = (folder, env = process.env) => {
16
+ const file = env.CLAUDE_CONFIG_DIR ? join(env.CLAUDE_CONFIG_DIR, ".claude.json") : join(homedir(), ".claude.json");
17
+ if (!existsSync(file)) return false;
18
+ const text = readFileSync(file, "utf8");
19
+ const config = JSON.parse(text);
20
+ const key = realpathSync(folder);
21
+ if (config.projects?.[key]?.hasTrustDialogAccepted === true) return true;
22
+ config.projects = {
23
+ ...config.projects,
24
+ [key]: {
25
+ ...config.projects?.[key],
26
+ hasTrustDialogAccepted: true
27
+ }
28
+ };
29
+ const written = `${text.trimEnd() === JSON.stringify(JSON.parse(text), null, 2) ? JSON.stringify(config, null, 2) : JSON.stringify(config)}${text.endsWith("\n") ? "\n" : ""}`;
30
+ const temp = `${file}.harnessd-${process.pid}`;
31
+ writeFileSync(temp, written, { mode: statSync(file).mode & 511 });
32
+ renameSync(temp, file);
33
+ return true;
34
+ };
35
+ /** A conversation's transcript, wherever Claude Code put it. */
36
+ const findTranscript = (sessionId, env = process.env) => {
37
+ const projects = join(claudeDir(env), "projects");
38
+ try {
39
+ for (const dir of readdirSync(projects)) {
40
+ const file = join(projects, dir, `${sessionId}.jsonl`);
41
+ if (existsSync(file)) return file;
42
+ }
43
+ } catch {}
44
+ };
45
+ /** The first `name` on `path` that can run. */
46
+ const which = (name, path = process.env.PATH ?? "") => {
47
+ if (name.includes("/")) return name;
48
+ for (const dir of path.split(delimiter)) {
49
+ if (!dir) continue;
50
+ try {
51
+ accessSync(join(dir, name), constants.X_OK);
52
+ return join(dir, name);
53
+ } catch {}
54
+ }
55
+ throw new Error(`${name} isn't on PATH (${path}); install Claude Code: curl -fsSL https://claude.ai/install.sh | bash`);
56
+ };
57
+ /**
58
+ * harnessd's plugin, written before each start from the config's channels: one MCP server per channel, each
59
+ * `harnessd channel <name>`. None: no plugin.
60
+ */
61
+ const writePlugin = (paths, config, bin) => {
62
+ rmSync(paths.plugin, {
63
+ recursive: true,
64
+ force: true
65
+ });
66
+ const names = Object.keys(config.channels);
67
+ if (names.length === 0) return false;
68
+ mkdirSync(join(paths.plugin, ".claude-plugin"), { recursive: true });
69
+ const manifest = {
70
+ name: "harnessd",
71
+ version: "1.0.0",
72
+ description: "harnessd's channels: each one's events, and its tools",
73
+ mcpServers: Object.fromEntries(names.map((name) => [name, {
74
+ command: process.execPath,
75
+ args: [
76
+ bin,
77
+ "channel",
78
+ name
79
+ ],
80
+ env: { HARNESSD_HOME: paths.home }
81
+ }])),
82
+ channels: names.map((name) => ({
83
+ server: name,
84
+ displayName: name
85
+ }))
86
+ };
87
+ writeFileSync(join(paths.plugin, ".claude-plugin", "plugin.json"), `${JSON.stringify(manifest, null, 2)}\n`);
88
+ return true;
89
+ };
90
+ /**
91
+ * The claude command line for one start (after the binary). `--channels` names the plugin only when the managed
92
+ * settings let it in: a refused entry there also shuts out the same plugin loaded with the development flag.
93
+ */
94
+ const claudeArgs = (o) => [
95
+ "--dangerously-skip-permissions",
96
+ ...o.plugin ? ["--plugin-dir", o.plugin] : [],
97
+ ...o.plugin && o.allowed ? ["--channels", `plugin:${PLUGIN}`] : [],
98
+ ...o.start.resume ? ["--resume", o.start.sessionId] : ["--session-id", o.start.sessionId],
99
+ ...o.start.prompt ? [o.start.prompt] : [],
100
+ ...o.config.args,
101
+ ...o.extra
102
+ ];
103
+ /** Runs the config's prestart command in the agent's folder: its stdout is JSON `{ env?, args? }`, or nothing. */
104
+ const prestart = (command, folder, env, log) => new Promise((resolve, reject) => {
105
+ execFile("/bin/sh", ["-c", command], {
106
+ cwd: folder,
107
+ env,
108
+ timeout: 6e4,
109
+ maxBuffer: 16777216
110
+ }, (error, stdout, stderr) => {
111
+ for (const line of stderr.split("\n")) if (line.trim()) log(`prestart: ${line}`);
112
+ if (error) return reject(/* @__PURE__ */ new Error(`prestart failed: ${error.message.split("\n")[0]}`));
113
+ if (!stdout.trim()) return resolve({
114
+ env: {},
115
+ args: []
116
+ });
117
+ let parsed;
118
+ try {
119
+ parsed = JSON.parse(stdout);
120
+ } catch {
121
+ return reject(/* @__PURE__ */ new Error("prestart printed something other than JSON { env?, args? }"));
122
+ }
123
+ const { env: more = {}, args = [], ...rest } = parsed ?? {};
124
+ if (typeof parsed !== "object" || Object.keys(rest).length > 0 || typeof more !== "object" || more === null || Object.values(more).some((v) => typeof v !== "string") || !Array.isArray(args) || args.some((a) => typeof a !== "string")) return reject(/* @__PURE__ */ new Error("prestart's JSON must be { env?: { NAME: string }, args?: string[] }"));
125
+ if ("CLAUDE_CONFIG_DIR" in more) return reject(/* @__PURE__ */ new Error("prestart can't set CLAUDE_CONFIG_DIR; set it in config.json's env"));
126
+ resolve({
127
+ env: more,
128
+ args
129
+ });
130
+ });
131
+ });
132
+ /** What keeps harnessd's channels out of Claude Code on this Mac: its managed settings must let `harnessd@inline` in. */
133
+ const channelBlockers = (file = MANAGED_SETTINGS) => {
134
+ let settings = {};
135
+ try {
136
+ const parsed = JSON.parse(readFileSync(file, "utf8"));
137
+ if (typeof parsed === "object" && parsed !== null) settings = parsed;
138
+ } catch {}
139
+ const listed = Array.isArray(settings.allowedChannelPlugins) && settings.allowedChannelPlugins.some((entry) => entry === "harnessd@inline" || typeof entry === "object" && entry !== null && entry.plugin === "harnessd" && entry.marketplace === "inline");
140
+ return [...settings.channelsEnabled === true ? [] : [`${file} doesn't set channelsEnabled: true`], ...listed ? [] : [`${file} doesn't list ${PLUGIN} in allowedChannelPlugins`]];
141
+ };
142
+ /** The managed settings with harnessd's channel let in; a list that wasn't there starts with Anthropic's own channels. */
143
+ const allowChannel = (file = MANAGED_SETTINGS) => {
144
+ const settings = existsSync(file) ? JSON.parse(readFileSync(file, "utf8")) : {};
145
+ if (typeof settings !== "object" || settings === null || Array.isArray(settings)) throw new Error(`${file} isn't a JSON object; harnessd won't write over it`);
146
+ const list = Array.isArray(settings.allowedChannelPlugins) ? settings.allowedChannelPlugins : [
147
+ "telegram",
148
+ "discord",
149
+ "imessage",
150
+ "fakechat"
151
+ ].map((plugin) => ({
152
+ marketplace: "claude-plugins-official",
153
+ plugin
154
+ }));
155
+ return {
156
+ ...settings,
157
+ channelsEnabled: true,
158
+ allowedChannelPlugins: [...list.filter((entry) => !(typeof entry === "object" && entry?.plugin === "harnessd")), {
159
+ marketplace: "inline",
160
+ plugin: "harnessd"
161
+ }]
162
+ };
163
+ };
164
+ export { MANAGED_SETTINGS, PLUGIN, allowChannel, channelBlockers, claudeArgs, findTranscript, prestart, trustFolder, which, writePlugin };
165
+
166
+ //# sourceMappingURL=claude.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"claude.js","names":[],"sources":["../src/claude.ts"],"sourcesContent":["import { execFile } from \"node:child_process\";\nimport {\n accessSync,\n constants,\n existsSync,\n mkdirSync,\n readFileSync,\n readdirSync,\n realpathSync,\n renameSync,\n rmSync,\n statSync,\n writeFileSync,\n} from \"node:fs\";\nimport { homedir } from \"node:os\";\nimport { delimiter, join } from \"node:path\";\nimport type { Harnessd } from \"./config\";\nimport type { Watchdog } from \"./watchdog\";\n\n/** How Claude Code names a `--plugin-dir` plugin, and what `--channels` takes. */\nexport const PLUGIN = \"harnessd@inline\";\nexport const MANAGED_SETTINGS =\n \"/Library/Application Support/ClaudeCode/managed-settings.json\";\n\nconst claudeDir = (env: NodeJS.ProcessEnv) =>\n env.CLAUDE_CONFIG_DIR || join(homedir(), \".claude\");\n\n/**\n * Records the folder as trusted where Claude Code keeps its answer to the trust dialog (its global config's\n * `projects[<folder>].hasTrustDialogAccepted`), so an unattended start doesn't stop at that dialog. Only that field\n * changes; a Mac where Claude Code never ran has no config yet, and the dialog comes with the sign-in.\n */\nexport const trustFolder = (\n folder: string,\n env: NodeJS.ProcessEnv = process.env,\n): boolean => {\n const file = env.CLAUDE_CONFIG_DIR\n ? join(env.CLAUDE_CONFIG_DIR, \".claude.json\")\n : join(homedir(), \".claude.json\");\n if (!existsSync(file)) return false;\n const text = readFileSync(file, \"utf8\");\n const config = JSON.parse(text) as {\n projects?: Record<string, { hasTrustDialogAccepted?: boolean }>;\n };\n const key = realpathSync(folder);\n if (config.projects?.[key]?.hasTrustDialogAccepted === true) return true;\n config.projects = {\n ...config.projects,\n [key]: { ...config.projects?.[key], hasTrustDialogAccepted: true },\n };\n const pretty = text.trimEnd() === JSON.stringify(JSON.parse(text), null, 2);\n const written = `${pretty ? JSON.stringify(config, null, 2) : JSON.stringify(config)}${text.endsWith(\"\\n\") ? \"\\n\" : \"\"}`;\n const temp = `${file}.harnessd-${process.pid}`;\n writeFileSync(temp, written, { mode: statSync(file).mode & 0o777 });\n renameSync(temp, file);\n return true;\n};\n\n/** A conversation's transcript, wherever Claude Code put it. */\nexport const findTranscript = (\n sessionId: string,\n env: NodeJS.ProcessEnv = process.env,\n): string | undefined => {\n const projects = join(claudeDir(env), \"projects\");\n try {\n for (const dir of readdirSync(projects)) {\n const file = join(projects, dir, `${sessionId}.jsonl`);\n if (existsSync(file)) return file;\n }\n } catch {}\n return undefined;\n};\n\n/** The first `name` on `path` that can run. */\nexport const which = (name: string, path = process.env.PATH ?? \"\") => {\n if (name.includes(\"/\")) return name;\n for (const dir of path.split(delimiter)) {\n if (!dir) continue;\n try {\n accessSync(join(dir, name), constants.X_OK);\n return join(dir, name);\n } catch {}\n }\n throw new Error(\n `${name} isn't on PATH (${path}); install Claude Code: curl -fsSL https://claude.ai/install.sh | bash`,\n );\n};\n\n/**\n * harnessd's plugin, written before each start from the config's channels: one MCP server per channel, each\n * `harnessd channel <name>`. None: no plugin.\n */\nexport const writePlugin = (\n paths: Harnessd.Paths,\n config: Harnessd.Config,\n bin: string,\n): boolean => {\n rmSync(paths.plugin, { recursive: true, force: true });\n const names = Object.keys(config.channels);\n if (names.length === 0) return false;\n mkdirSync(join(paths.plugin, \".claude-plugin\"), { recursive: true });\n const manifest = {\n name: \"harnessd\",\n version: \"1.0.0\",\n description: \"harnessd's channels: each one's events, and its tools\",\n mcpServers: Object.fromEntries(\n names.map((name) => [\n name,\n {\n command: process.execPath,\n args: [bin, \"channel\", name],\n env: { HARNESSD_HOME: paths.home },\n },\n ]),\n ),\n channels: names.map((name) => ({ server: name, displayName: name })),\n };\n writeFileSync(\n join(paths.plugin, \".claude-plugin\", \"plugin.json\"),\n `${JSON.stringify(manifest, null, 2)}\\n`,\n );\n return true;\n};\n\n/**\n * The claude command line for one start (after the binary). `--channels` names the plugin only when the managed\n * settings let it in: a refused entry there also shuts out the same plugin loaded with the development flag.\n */\nexport const claudeArgs = (o: {\n start: Watchdog.Start;\n plugin: string | undefined;\n allowed: boolean;\n config: Harnessd.Config;\n extra: readonly string[];\n}) => [\n \"--dangerously-skip-permissions\",\n ...(o.plugin ? [\"--plugin-dir\", o.plugin] : []),\n ...(o.plugin && o.allowed ? [\"--channels\", `plugin:${PLUGIN}`] : []),\n ...(o.start.resume\n ? [\"--resume\", o.start.sessionId]\n : [\"--session-id\", o.start.sessionId]),\n // before the config's arguments: after a list flag (--add-dir…) claude would take it as one more value\n ...(o.start.prompt ? [o.start.prompt] : []),\n ...o.config.args,\n ...o.extra,\n];\n\nexport type Prestart = { env: Record<string, string>; args: string[] };\n\n/** Runs the config's prestart command in the agent's folder: its stdout is JSON `{ env?, args? }`, or nothing. */\nexport const prestart = (\n command: string,\n folder: string,\n env: NodeJS.ProcessEnv,\n log: (line: string) => void,\n) =>\n new Promise<Prestart>((resolve, reject) => {\n execFile(\n \"/bin/sh\",\n [\"-c\", command],\n { cwd: folder, env, timeout: 60_000, maxBuffer: 16 * 1024 * 1024 },\n (error, stdout, stderr) => {\n for (const line of stderr.split(\"\\n\"))\n if (line.trim()) log(`prestart: ${line}`);\n if (error)\n return reject(\n new Error(`prestart failed: ${error.message.split(\"\\n\")[0]}`),\n );\n if (!stdout.trim()) return resolve({ env: {}, args: [] });\n let parsed: unknown;\n try {\n parsed = JSON.parse(stdout);\n } catch {\n return reject(\n new Error(\n \"prestart printed something other than JSON { env?, args? }\",\n ),\n );\n }\n const {\n env: more = {},\n args = [],\n ...rest\n } = (parsed ?? {}) as { env?: unknown; args?: unknown };\n if (\n typeof parsed !== \"object\" ||\n Object.keys(rest).length > 0 ||\n typeof more !== \"object\" ||\n more === null ||\n Object.values(more).some((v) => typeof v !== \"string\") ||\n !Array.isArray(args) ||\n args.some((a) => typeof a !== \"string\")\n )\n return reject(\n new Error(\n \"prestart's JSON must be { env?: { NAME: string }, args?: string[] }\",\n ),\n );\n // harnessd finds the conversation before prestart runs, so where Claude Code keeps it comes from config.json\n if (\"CLAUDE_CONFIG_DIR\" in more)\n return reject(\n new Error(\n \"prestart can't set CLAUDE_CONFIG_DIR; set it in config.json's env\",\n ),\n );\n resolve({\n env: more as Record<string, string>,\n args: args as string[],\n });\n },\n );\n });\n\n/** What keeps harnessd's channels out of Claude Code on this Mac: its managed settings must let `harnessd@inline` in. */\nexport const channelBlockers = (file = MANAGED_SETTINGS): string[] => {\n let settings: { channelsEnabled?: unknown; allowedChannelPlugins?: unknown } =\n {};\n try {\n const parsed: unknown = JSON.parse(readFileSync(file, \"utf8\"));\n if (typeof parsed === \"object\" && parsed !== null) settings = parsed;\n } catch {}\n const listed =\n Array.isArray(settings.allowedChannelPlugins) &&\n settings.allowedChannelPlugins.some(\n (entry: unknown) =>\n entry === PLUGIN ||\n (typeof entry === \"object\" &&\n entry !== null &&\n (entry as { plugin?: unknown }).plugin === \"harnessd\" &&\n (entry as { marketplace?: unknown }).marketplace === \"inline\"),\n );\n return [\n ...(settings.channelsEnabled === true\n ? []\n : [`${file} doesn't set channelsEnabled: true`]),\n ...(listed\n ? []\n : [`${file} doesn't list ${PLUGIN} in allowedChannelPlugins`]),\n ];\n};\n\n/** The managed settings with harnessd's channel let in; a list that wasn't there starts with Anthropic's own channels. */\nexport const allowChannel = (\n file = MANAGED_SETTINGS,\n): Record<string, unknown> => {\n // only a missing file starts from nothing: anything else there is policy to keep\n const settings: Record<string, unknown> = existsSync(file)\n ? JSON.parse(readFileSync(file, \"utf8\"))\n : {};\n if (\n typeof settings !== \"object\" ||\n settings === null ||\n Array.isArray(settings)\n )\n throw new Error(\n `${file} isn't a JSON object; harnessd won't write over it`,\n );\n const list = Array.isArray(settings.allowedChannelPlugins)\n ? settings.allowedChannelPlugins\n : [\"telegram\", \"discord\", \"imessage\", \"fakechat\"].map((plugin) => ({\n marketplace: \"claude-plugins-official\",\n plugin,\n }));\n return {\n ...settings,\n channelsEnabled: true,\n allowedChannelPlugins: [\n ...list.filter(\n (entry) => !(typeof entry === \"object\" && entry?.plugin === \"harnessd\"),\n ),\n { marketplace: \"inline\", plugin: \"harnessd\" },\n ],\n };\n};\n"],"mappings":";;;;;;AAoBA,MAAa,SAAS;AACtB,MAAa,mBACX;AAEF,MAAM,aAAa,QACjB,IAAI,qBAAqB,KAAK,QAAQ,GAAG,SAAS;;;;;;AAOpD,MAAa,eACX,QACA,MAAyB,QAAQ,QACrB;CACZ,MAAM,O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B,UACC,UAAA,qBACC,OAAO,UAAU,YAChB,UAAU,QACT,MAA+B,WAAW,cAC1C,MAAoC,gBAAgB,QAC3D;CACF,OAAO,CACL,GAAI,SAAS,oBAAoB,OAC7B,CAAC,IACD,CAAC,GAAG,KAAK,mCAAmC,GAChD,GAAI,SACA,CAAC,IACD,CAAC,GAAG,KAAK,gBAAgB,OAAO,0BAA0B,CAChE;AACF;;AAGA,MAAa,gBACX,OAAO,qBACqB;CAE5B,MAAM,WAAoC,WAAW,IAAI,IACrD,KAAK,MAAM,aAAa,MAAM,MAAM,CAAC,IACrC,CAAC;CACL,IACE,OAAO,aAAa,YACpB,aAAa,QACb,MAAM,QAAQ,QAAQ,GAEtB,MAAM,IAAI,MACR,GAAG,KAAK,mDACV;CACF,MAAM,OAAO,MAAM,QAAQ,SAAS,qBAAqB,IACrD,SAAS,wBACT;EAAC;EAAY;EAAW;EAAY;CAAU,CAAC,CAAC,KAAK,YAAY;EAC/D,aAAa;EACb;CACF,EAAE;CACN,OAAO;EACL,GAAG;EACH,iBAAiB;EACjB,uBAAuB,CACrB,GAAG,KAAK,QACL,UAAU,EAAE,OAAO,UAAU,YAAY,OAAO,WAAW,WAC9D,GACA;GAAE,aAAa;GAAU,QAAQ;EAAW,CAC9C;CACF;AACF"}
package/dist/cli.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ type Io = {
2
+ out: (line: string) => void;
3
+ err: (line: string) => void;
4
+ };
5
+ /** Runs one harnessd command; resolves to the exit code. */
6
+ export declare const runHarnessd: (argv: readonly string[], bin: string, io?: Io) => Promise<number>;
7
+ export {};
8
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAiCA,KAAK,EAAE,GAAG;IAAE,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAAC,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;CAAE,CAAC;AA0QvE,4DAA4D;AAC5D,eAAO,MAAM,WAAW,GACtB,MAAM,SAAS,MAAM,EAAE,EACvB,KAAK,MAAM,EACX,KAAI,EAGH,KACA,OAAO,CAAC,MAAM,CAgEhB,CAAC"}
package/dist/cli.js ADDED
@@ -0,0 +1,258 @@
1
+ import { MANAGED_SETTINGS, allowChannel, channelBlockers, which } from "./claude.js";
2
+ import { DEFAULT_CONFIG, pathsOf, readConfig } from "./config.js";
3
+ import { readStatus, serveChannel, statusFile } from "./channel.js";
4
+ import { logTo } from "./log.js";
5
+ import { ask, runDaemon } from "./daemon.js";
6
+ import { load, plistOf, stableNode, unload } from "./launchd.js";
7
+ import { existsSync, mkdirSync, writeFileSync } from "node:fs";
8
+ import { spawn, spawnSync } from "node:child_process";
9
+ import { createConnection } from "node:net";
10
+ import { createInterface } from "node:readline";
11
+ // src/cli.ts
12
+ const USAGE = `harnessd keeps Claude Code running on this Mac, connected to the events of your agentic apps.
13
+
14
+ usage: harnessd <command>
15
+
16
+ install Start harnessd now and at every login
17
+ uninstall Stop harnessd and remove it from login
18
+ status [--json] What runs, which conversation, and whether each channel's events arrive
19
+ start Start Claude Code after a stop
20
+ stop Stop Claude Code; it stays stopped until start
21
+ new [message] Start a new conversation, with message as its first message
22
+ attach Open Claude Code's terminal; Ctrl-\\ detaches
23
+ logs Follow harnessd's log
24
+
25
+ Settings: ~/.harnessd/config.json (HARNESSD_HOME moves the folder).`;
26
+ const DETACH = "";
27
+ const notRunning = (paths) => `harnessd isn't running in ${paths.home}: harnessd install starts it.`;
28
+ const command = async (paths, request, io) => {
29
+ const answer = await ask(paths.socket, request);
30
+ if (!answer) {
31
+ io.err(notRunning(paths));
32
+ return 1;
33
+ }
34
+ io[answer.ok ? "out" : "err"](String(answer.message));
35
+ return answer.ok ? 0 : 1;
36
+ };
37
+ const confirm = async (question) => {
38
+ const lines = createInterface({
39
+ input: process.stdin,
40
+ output: process.stdout
41
+ });
42
+ const answer = await new Promise((resolve) => lines.question(`${question} [y/N] `, resolve));
43
+ lines.close();
44
+ return /^y(es)?$/i.test(answer.trim());
45
+ };
46
+ const install = async (paths, bin, io) => {
47
+ if (process.platform !== "darwin") throw new Error("harnessd runs on macOS (it starts with launchd).");
48
+ if (bin.includes("/_npx/")) throw new Error("Install harnessd first, so launchd has a lasting copy to start: npm install -g @harness-sdk/harnessd");
49
+ const claude = which("claude");
50
+ const version = spawnSync(claude, ["--version"], {
51
+ encoding: "utf8",
52
+ timeout: 3e4
53
+ });
54
+ if (version.status !== 0) throw new Error(`${claude} --version failed: ${(version.stderr || version.stdout || "").trim()}`);
55
+ mkdirSync(paths.home, { recursive: true });
56
+ if (!existsSync(paths.config)) writeFileSync(paths.config, `${JSON.stringify(DEFAULT_CONFIG, null, 2)}\n`);
57
+ const config = readConfig(paths);
58
+ mkdirSync(config.folder, { recursive: true });
59
+ const blockers = Object.keys(config.channels).length > 0 ? channelBlockers() : [];
60
+ if (blockers.length > 0) {
61
+ io.out(`Claude Code lets a channel in only when this Mac's managed settings list it:\n ${blockers.join("\n ")}`);
62
+ if (process.stdin.isTTY && await confirm(`Let harnessd's channels in? This writes /Library/Application Support/ClaudeCode/managed-settings.json with sudo.`)) {
63
+ if (spawnSync("sudo", [
64
+ "sh",
65
+ "-c",
66
+ `mkdir -p "$(dirname "$1")" && cat > "$1"`,
67
+ "sh",
68
+ "/Library/Application Support/ClaudeCode/managed-settings.json"
69
+ ], {
70
+ input: `${JSON.stringify(allowChannel(), null, 2)}\n`,
71
+ stdio: [
72
+ "pipe",
73
+ "inherit",
74
+ "inherit"
75
+ ]
76
+ }).status !== 0) throw new Error(`Couldn't write ${MANAGED_SETTINGS}.`);
77
+ } else io.out("Until they're let in, Claude Code drops the channels' events; harnessd status says so.");
78
+ }
79
+ const env = { PATH: process.env.PATH ?? "/usr/bin:/bin" };
80
+ if (process.env.HARNESSD_HOME) env.HARNESSD_HOME = paths.home;
81
+ load(paths.label, plistOf({
82
+ label: paths.label,
83
+ node: stableNode(),
84
+ bin,
85
+ env,
86
+ paths
87
+ }));
88
+ io.out([
89
+ `harnessd runs Claude Code in ${config.folder} (${version.stdout.trim()}), now and at every login.`,
90
+ " harnessd attach its terminal: sign in there if Claude Code asks; Ctrl-\\ detaches",
91
+ " harnessd status what runs and whether events arrive",
92
+ "Turn on automatic login (System Settings > Users & Groups), so harnessd comes back after a power cut."
93
+ ].join("\n"));
94
+ return 0;
95
+ };
96
+ const ago = (iso) => {
97
+ const s = Math.max(0, Math.round((Date.now() - Date.parse(iso)) / 1e3));
98
+ return s < 120 ? `${s}s` : s < 7200 ? `${Math.round(s / 60)}m` : s < 172800 ? `${Math.round(s / 3600)}h` : `${Math.round(s / 86400)}d`;
99
+ };
100
+ /** Each channel as of the Claude Code that runs now: what an earlier run heard says nothing about this one. */
101
+ const channelReport = (paths, config, running, blockers) => Object.fromEntries(Object.entries(config?.channels ?? {}).map(([name, channel]) => {
102
+ const status = readStatus(statusFile(paths, name));
103
+ const since = running?.state === "running" || running?.state === "starting" ? running.startedAt : void 0;
104
+ const now = (at) => since !== void 0 && at !== void 0 && at >= since;
105
+ const events = since === void 0 ? "off (Claude Code isn't running)" : now(status.heardAt) ? "arriving" : now(status.pushedAt) ? "sent, not in the conversation yet" : "none yet";
106
+ return [name, {
107
+ url: channel.url,
108
+ events,
109
+ ...status,
110
+ ...blockers.length > 0 && { blockers }
111
+ }];
112
+ }));
113
+ const status = async (paths, json, io) => {
114
+ const answer = await ask(paths.socket, { command: "status" });
115
+ let config;
116
+ let configError;
117
+ try {
118
+ config = readConfig(paths);
119
+ } catch (error) {
120
+ configError = error instanceof Error ? error.message : String(error);
121
+ }
122
+ const blockers = config && Object.keys(config.channels).length > 0 ? channelBlockers() : [];
123
+ const channels = channelReport(paths, config, answer?.status, blockers);
124
+ const s = answer?.status;
125
+ if (json) {
126
+ io.out(JSON.stringify({
127
+ running: !!s,
128
+ home: paths.home,
129
+ ...s && { status: s },
130
+ ...configError && { configError },
131
+ channels
132
+ }));
133
+ return s ? 0 : 1;
134
+ }
135
+ if (!s) io.out(notRunning(paths));
136
+ else {
137
+ const since = s.startedAt ? ` for ${ago(s.startedAt)}` : "";
138
+ const what = s.state === "running" ? `Claude Code running${since} (pid ${s.pid})` : s.state === "waiting" ? `Claude Code starting again${s.nextStartAt ? ` in ${Math.max(0, Math.round((Date.parse(s.nextStartAt) - Date.now()) / 1e3))}s` : ""}` : s.state === "stopped" ? "Claude Code stopped (harnessd start starts it)" : "Claude Code starting";
139
+ io.out(`harnessd ${s.daemonPid}: ${what}`);
140
+ if (s.sessionId) io.out(`conversation ${s.sessionId}${s.folder ? ` in ${s.folder}` : ""}`);
141
+ if (s.restarts > 0 || s.lastExit) io.out(`restarts ${s.restarts}${s.lastExit ? `, last exit code ${s.lastExit.code} ${ago(s.lastExit.at)} ago` : ""}`);
142
+ }
143
+ if (configError) io.out(configError);
144
+ for (const [name, channel] of Object.entries(channels)) io.out(`channel ${name}: events ${channel.events} (${channel.url})`);
145
+ if (blockers.length > 0 && Object.values(channels).some((c) => c.events !== "arriving")) io.out(`channels are blocked: ${blockers.join("; ")} (harnessd install lets them in)`);
146
+ return s ? 0 : 1;
147
+ };
148
+ const attach = (paths, io) => new Promise((resolve) => {
149
+ if (!process.stdin.isTTY || !process.stdout.isTTY) {
150
+ io.err("harnessd attach needs a terminal.");
151
+ return resolve(1);
152
+ }
153
+ const connection = createConnection(paths.socket);
154
+ const send = (value) => connection.write(`${JSON.stringify(value)}\n`);
155
+ const onResize = () => send({ resize: {
156
+ cols: process.stdout.columns,
157
+ rows: process.stdout.rows
158
+ } });
159
+ const onInput = (data) => {
160
+ const text = data.toString("utf8");
161
+ if (text.includes(DETACH)) connection.end();
162
+ else send({ input: text });
163
+ };
164
+ let done = false;
165
+ const finish = (code, line) => {
166
+ if (done) return;
167
+ done = true;
168
+ process.stdin.setRawMode(false);
169
+ process.stdin.off("data", onInput);
170
+ process.stdin.pause();
171
+ process.stdout.off("resize", onResize);
172
+ process.stdout.write("\x1B[0m\r\n");
173
+ if (line) io.err(line);
174
+ resolve(code);
175
+ };
176
+ connection.once("error", () => finish(1, notRunning(paths)));
177
+ connection.once("connect", () => {
178
+ send({
179
+ command: "attach",
180
+ cols: process.stdout.columns,
181
+ rows: process.stdout.rows
182
+ });
183
+ process.stdin.setRawMode(true);
184
+ process.stdin.resume();
185
+ process.stdin.on("data", onInput);
186
+ process.stdout.on("resize", onResize);
187
+ createInterface({ input: connection }).on("line", (line) => {
188
+ try {
189
+ const message = JSON.parse(line);
190
+ if (typeof message.output === "string") process.stdout.write(message.output);
191
+ } catch {}
192
+ });
193
+ });
194
+ connection.once("close", () => finish(0, "Detached; Claude Code keeps running."));
195
+ });
196
+ /** Runs one harnessd command; resolves to the exit code. */
197
+ const runHarnessd = async (argv, bin, io = {
198
+ out: (line) => void process.stdout.write(`${line}\n`),
199
+ err: (line) => void process.stderr.write(`${line}\n`)
200
+ }) => {
201
+ const paths = pathsOf();
202
+ const [first, ...rest] = argv;
203
+ switch (first) {
204
+ case "install": return install(paths, bin, io);
205
+ case "uninstall": {
206
+ const had = unload(paths.label);
207
+ io.out(had ? `Removed harnessd from login. Its settings and conversation stay in ${paths.home}.` : "harnessd wasn't installed.");
208
+ return 0;
209
+ }
210
+ case "status": return status(paths, rest.includes("--json"), io);
211
+ case "start":
212
+ case "stop": return command(paths, { command: first }, io);
213
+ case "new": return command(paths, {
214
+ command: "new",
215
+ ...rest.length > 0 && { message: rest.join(" ") }
216
+ }, io);
217
+ case "attach": return attach(paths, io);
218
+ case "logs": return new Promise((resolve) => {
219
+ if (!existsSync(paths.log)) {
220
+ io.err(`No log yet at ${paths.log}.`);
221
+ return resolve(1);
222
+ }
223
+ spawn("tail", [
224
+ "-n",
225
+ "100",
226
+ "-F",
227
+ paths.log
228
+ ], { stdio: "inherit" }).on("exit", (code) => resolve(code ?? 0));
229
+ });
230
+ case "run":
231
+ await runDaemon(paths, bin);
232
+ return 0;
233
+ case "channel": {
234
+ const name = rest[0] ?? "";
235
+ const channel = readConfig(paths).channels[name];
236
+ if (!channel) throw new Error(`No channel "${name}" in ${paths.config}`);
237
+ await serveChannel({
238
+ name,
239
+ channel,
240
+ paths,
241
+ log: logTo(paths.log, `channel ${name}: `)
242
+ });
243
+ return 0;
244
+ }
245
+ case void 0:
246
+ case "help":
247
+ case "--help":
248
+ case "-h":
249
+ io.out(USAGE);
250
+ return first === void 0 ? 1 : 0;
251
+ default:
252
+ io.err(`Unknown command ${first}.\n\n${USAGE}`);
253
+ return 2;
254
+ }
255
+ };
256
+ export { runHarnessd };
257
+
258
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","names":[],"sources":["../src/cli.ts"],"sourcesContent":["import { spawn, spawnSync } from \"node:child_process\";\nimport { existsSync, mkdirSync, writeFileSync } from \"node:fs\";\nimport { createConnection } from \"node:net\";\nimport { createInterface } from \"node:readline\";\nimport {\n allowChannel,\n channelBlockers,\n MANAGED_SETTINGS,\n which,\n} from \"./claude\";\nimport { readStatus, serveChannel, statusFile } from \"./channel\";\nimport { DEFAULT_CONFIG, pathsOf, readConfig, type Harnessd } from \"./config\";\nimport { ask, runDaemon, type Daemon } from \"./daemon\";\nimport { load, plistOf, stableNode, unload } from \"./launchd\";\nimport { logTo } from \"./log\";\n\nconst USAGE = `harnessd keeps Claude Code running on this Mac, connected to the events of your agentic apps.\n\nusage: harnessd <command>\n\n install Start harnessd now and at every login\n uninstall Stop harnessd and remove it from login\n status [--json] What runs, which conversation, and whether each channel's events arrive\n start Start Claude Code after a stop\n stop Stop Claude Code; it stays stopped until start\n new [message] Start a new conversation, with message as its first message\n attach Open Claude Code's terminal; Ctrl-\\\\ detaches\n logs Follow harnessd's log\n\nSettings: ~/.harnessd/config.json (HARNESSD_HOME moves the folder).`;\n\nconst DETACH = \"\\x1c\";\n\ntype Io = { out: (line: string) => void; err: (line: string) => void };\n\nconst notRunning = (paths: Harnessd.Paths) =>\n `harnessd isn't running in ${paths.home}: harnessd install starts it.`;\n\nconst command = async (\n paths: Harnessd.Paths,\n request: Daemon.Request,\n io: Io,\n) => {\n const answer = await ask(paths.socket, request);\n if (!answer) {\n io.err(notRunning(paths));\n return 1;\n }\n io[answer.ok ? \"out\" : \"err\"](String(answer.message));\n return answer.ok ? 0 : 1;\n};\n\nconst confirm = async (question: string) => {\n const lines = createInterface({\n input: process.stdin,\n output: process.stdout,\n });\n const answer = await new Promise<string>((resolve) =>\n lines.question(`${question} [y/N] `, resolve),\n );\n lines.close();\n return /^y(es)?$/i.test(answer.trim());\n};\n\nconst install = async (paths: Harnessd.Paths, bin: string, io: Io) => {\n if (process.platform !== \"darwin\")\n throw new Error(\"harnessd runs on macOS (it starts with launchd).\");\n if (bin.includes(\"/_npx/\"))\n throw new Error(\n \"Install harnessd first, so launchd has a lasting copy to start: npm install -g @harness-sdk/harnessd\",\n );\n const claude = which(\"claude\");\n const version = spawnSync(claude, [\"--version\"], {\n encoding: \"utf8\",\n timeout: 30_000,\n });\n if (version.status !== 0)\n throw new Error(\n `${claude} --version failed: ${(version.stderr || version.stdout || \"\").trim()}`,\n );\n mkdirSync(paths.home, { recursive: true });\n if (!existsSync(paths.config))\n writeFileSync(paths.config, `${JSON.stringify(DEFAULT_CONFIG, null, 2)}\\n`);\n const config = readConfig(paths);\n mkdirSync(config.folder, { recursive: true });\n\n const blockers =\n Object.keys(config.channels).length > 0 ? channelBlockers() : [];\n if (blockers.length > 0) {\n io.out(\n `Claude Code lets a channel in only when this Mac's managed settings list it:\\n ${blockers.join(\"\\n \")}`,\n );\n if (\n process.stdin.isTTY &&\n (await confirm(\n `Let harnessd's channels in? This writes ${MANAGED_SETTINGS} with sudo.`,\n ))\n ) {\n const written = spawnSync(\n \"sudo\",\n [\n \"sh\",\n \"-c\",\n `mkdir -p \"$(dirname \"$1\")\" && cat > \"$1\"`,\n \"sh\",\n MANAGED_SETTINGS,\n ],\n {\n input: `${JSON.stringify(allowChannel(), null, 2)}\\n`,\n stdio: [\"pipe\", \"inherit\", \"inherit\"],\n },\n );\n if (written.status !== 0)\n throw new Error(`Couldn't write ${MANAGED_SETTINGS}.`);\n } else\n io.out(\n \"Until they're let in, Claude Code drops the channels' events; harnessd status says so.\",\n );\n }\n\n const env: Record<string, string> = {\n PATH: process.env.PATH ?? \"/usr/bin:/bin\",\n };\n if (process.env.HARNESSD_HOME) env.HARNESSD_HOME = paths.home;\n load(\n paths.label,\n plistOf({ label: paths.label, node: stableNode(), bin, env, paths }),\n );\n io.out(\n [\n `harnessd runs Claude Code in ${config.folder} (${version.stdout.trim()}), now and at every login.`,\n \" harnessd attach its terminal: sign in there if Claude Code asks; Ctrl-\\\\ detaches\",\n \" harnessd status what runs and whether events arrive\",\n \"Turn on automatic login (System Settings > Users & Groups), so harnessd comes back after a power cut.\",\n ].join(\"\\n\"),\n );\n return 0;\n};\n\nconst ago = (iso: string) => {\n const s = Math.max(0, Math.round((Date.now() - Date.parse(iso)) / 1000));\n return s < 120\n ? `${s}s`\n : s < 7200\n ? `${Math.round(s / 60)}m`\n : s < 172_800\n ? `${Math.round(s / 3600)}h`\n : `${Math.round(s / 86_400)}d`;\n};\n\n/** Each channel as of the Claude Code that runs now: what an earlier run heard says nothing about this one. */\nconst channelReport = (\n paths: Harnessd.Paths,\n config: Harnessd.Config | undefined,\n running: Daemon.Status | undefined,\n blockers: string[],\n) =>\n Object.fromEntries(\n Object.entries(config?.channels ?? {}).map(([name, channel]) => {\n const status = readStatus(statusFile(paths, name));\n const since =\n running?.state === \"running\" || running?.state === \"starting\"\n ? running.startedAt\n : undefined;\n const now = (at: string | undefined) =>\n since !== undefined && at !== undefined && at >= since;\n const events =\n since === undefined\n ? \"off (Claude Code isn't running)\"\n : now(status.heardAt)\n ? \"arriving\"\n : now(status.pushedAt)\n ? \"sent, not in the conversation yet\"\n : \"none yet\";\n return [\n name,\n {\n url: channel.url,\n events,\n ...status,\n ...(blockers.length > 0 && { blockers }),\n },\n ];\n }),\n );\n\nconst status = async (paths: Harnessd.Paths, json: boolean, io: Io) => {\n const answer = (await ask(paths.socket, { command: \"status\" })) as\n | { status?: Daemon.Status }\n | undefined;\n let config: Harnessd.Config | undefined;\n let configError: string | undefined;\n try {\n config = readConfig(paths);\n } catch (error) {\n configError = error instanceof Error ? error.message : String(error);\n }\n const blockers =\n config && Object.keys(config.channels).length > 0 ? channelBlockers() : [];\n const channels = channelReport(paths, config, answer?.status, blockers);\n const s = answer?.status;\n if (json) {\n io.out(\n JSON.stringify({\n running: !!s,\n home: paths.home,\n ...(s && { status: s }),\n ...(configError && { configError }),\n channels,\n }),\n );\n return s ? 0 : 1;\n }\n if (!s) io.out(notRunning(paths));\n else {\n const since = s.startedAt ? ` for ${ago(s.startedAt)}` : \"\";\n const what =\n s.state === \"running\"\n ? `Claude Code running${since} (pid ${s.pid})`\n : s.state === \"waiting\"\n ? `Claude Code starting again${s.nextStartAt ? ` in ${Math.max(0, Math.round((Date.parse(s.nextStartAt) - Date.now()) / 1000))}s` : \"\"}`\n : s.state === \"stopped\"\n ? \"Claude Code stopped (harnessd start starts it)\"\n : \"Claude Code starting\";\n io.out(`harnessd ${s.daemonPid}: ${what}`);\n if (s.sessionId)\n io.out(`conversation ${s.sessionId}${s.folder ? ` in ${s.folder}` : \"\"}`);\n if (s.restarts > 0 || s.lastExit)\n io.out(\n `restarts ${s.restarts}${s.lastExit ? `, last exit code ${s.lastExit.code} ${ago(s.lastExit.at)} ago` : \"\"}`,\n );\n }\n if (configError) io.out(configError);\n for (const [name, channel] of Object.entries(channels))\n io.out(`channel ${name}: events ${channel.events} (${channel.url})`);\n if (\n blockers.length > 0 &&\n Object.values(channels).some((c) => c.events !== \"arriving\")\n )\n io.out(\n `channels are blocked: ${blockers.join(\"; \")} (harnessd install lets them in)`,\n );\n return s ? 0 : 1;\n};\n\nconst attach = (paths: Harnessd.Paths, io: Io) =>\n new Promise<number>((resolve) => {\n if (!process.stdin.isTTY || !process.stdout.isTTY) {\n io.err(\"harnessd attach needs a terminal.\");\n return resolve(1);\n }\n const connection = createConnection(paths.socket);\n const send = (value: unknown) =>\n connection.write(`${JSON.stringify(value)}\\n`);\n const onResize = () =>\n send({\n resize: { cols: process.stdout.columns, rows: process.stdout.rows },\n });\n const onInput = (data: Buffer) => {\n const text = data.toString(\"utf8\");\n if (text.includes(DETACH)) connection.end();\n else send({ input: text });\n };\n let done = false;\n const finish = (code: number, line?: string) => {\n if (done) return;\n done = true;\n process.stdin.setRawMode(false);\n process.stdin.off(\"data\", onInput);\n process.stdin.pause();\n process.stdout.off(\"resize\", onResize);\n process.stdout.write(\"\\x1b[0m\\r\\n\");\n if (line) io.err(line);\n resolve(code);\n };\n connection.once(\"error\", () => finish(1, notRunning(paths)));\n connection.once(\"connect\", () => {\n send({\n command: \"attach\",\n cols: process.stdout.columns,\n rows: process.stdout.rows,\n });\n process.stdin.setRawMode(true);\n process.stdin.resume();\n process.stdin.on(\"data\", onInput);\n process.stdout.on(\"resize\", onResize);\n createInterface({ input: connection }).on(\"line\", (line) => {\n try {\n const message = JSON.parse(line) as { output?: string };\n if (typeof message.output === \"string\")\n process.stdout.write(message.output);\n } catch {}\n });\n });\n connection.once(\"close\", () =>\n finish(0, \"Detached; Claude Code keeps running.\"),\n );\n });\n\n/** Runs one harnessd command; resolves to the exit code. */\nexport const runHarnessd = async (\n argv: readonly string[],\n bin: string,\n io: Io = {\n out: (line) => void process.stdout.write(`${line}\\n`),\n err: (line) => void process.stderr.write(`${line}\\n`),\n },\n): Promise<number> => {\n const paths = pathsOf();\n const [first, ...rest] = argv;\n switch (first) {\n case \"install\":\n return install(paths, bin, io);\n case \"uninstall\": {\n const had = unload(paths.label);\n io.out(\n had\n ? `Removed harnessd from login. Its settings and conversation stay in ${paths.home}.`\n : \"harnessd wasn't installed.\",\n );\n return 0;\n }\n case \"status\":\n return status(paths, rest.includes(\"--json\"), io);\n case \"start\":\n case \"stop\":\n return command(paths, { command: first }, io);\n case \"new\":\n return command(\n paths,\n { command: \"new\", ...(rest.length > 0 && { message: rest.join(\" \") }) },\n io,\n );\n case \"attach\":\n return attach(paths, io);\n case \"logs\":\n return new Promise((resolve) => {\n if (!existsSync(paths.log)) {\n io.err(`No log yet at ${paths.log}.`);\n return resolve(1);\n }\n spawn(\"tail\", [\"-n\", \"100\", \"-F\", paths.log], { stdio: \"inherit\" }).on(\n \"exit\",\n (code) => resolve(code ?? 0),\n );\n });\n case \"run\":\n await runDaemon(paths, bin);\n return 0;\n case \"channel\": {\n const name = rest[0] ?? \"\";\n const channel = readConfig(paths).channels[name];\n if (!channel) throw new Error(`No channel \"${name}\" in ${paths.config}`);\n await serveChannel({\n name,\n channel,\n paths,\n log: logTo(paths.log, `channel ${name}: `),\n });\n return 0;\n }\n case undefined:\n case \"help\":\n case \"--help\":\n case \"-h\":\n io.out(USAGE);\n return first === undefined ? 1 : 0;\n default:\n io.err(`Unknown command ${first}.\\n\\n${USAGE}`);\n return 2;\n }\n};\n"],"mappings":";;;;;;;;;;;AAgBA,MAAM,QAAQ;;;;;;;;;;;;;;AAed,MAAM,SAAS;AAIf,MAAM,cAAc,UAClB,6BAA6B,MAAM,KAAK;AAE1C,MAAM,UAAU,OACd,OACA,SACA,OACG;CACH,MAAM,SAAS,MAAM,IAAI,MAAM,QAAQ,OAAO;CAC9C,IAAI,CAAC,QAAQ;EACX,GAAG,IAAI,WAAW,KAAK,CAAC;EACxB,OAAO;CACT;CACA,GAAG,OAAO,KAAK,QAAQ,MAAM,CAAC,OAAO,OAAO,OAAO,CAAC;CACpD,OAAO,OAAO,KAAK,IAAI;AACzB;AAEA,MAAM,UAAU,OAAO,aAAqB;CAC1C,MAAM,QAAQ,gBAAgB;EAC5B,OAAO,QAAQ;EACf,QAAQ,QAAQ;CAClB,CAAC;CACD,MAAM,SAAS,MAAM,IAAI,SAAiB,YACxC,MAAM,SAAS,GAAG,SAAS,UAAU,OAAO,CAC9C;CACA,MAAM,MAAM;CACZ,OAAO,YAAY,KAAK,OAAO,KAAK,CAAC;AACvC;AAEA,MAA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IAAI,SAAS,YAAY;GAC9B,IAAI,CAAC,WAAW,MAAM,GAAG,GAAG;IAC1B,GAAG,IAAI,iBAAiB,MAAM,IAAI,EAAE;IACpC,OAAO,QAAQ,CAAC;GAClB;GACA,MAAM,QAAQ;IAAC;IAAM;IAAO;IAAM,MAAM;GAAG,GAAG,EAAE,OAAO,UAAU,CAAC,CAAC,CAAC,GAClE,SACC,SAAS,QAAQ,QAAQ,CAAC,CAC7B;EACF,CAAC;EACH,KAAK;GACH,MAAM,UAAU,OAAO,GAAG;GAC1B,OAAO;EACT,KAAK,WAAW;GACd,MAAM,OAAO,KAAK,MAAM;GACxB,MAAM,UAAU,WAAW,KAAK,CAAC,CAAC,SAAS;GAC3C,IAAI,CAAC,SAAS,MAAM,IAAI,MAAM,eAAe,KAAK,OAAO,MAAM,QAAQ;GACvE,MAAM,aAAa;IACjB;IACA;IACA;IACA,KAAK,MAAM,MAAM,KAAK,WAAW,KAAK,GAAG;GAC3C,CAAC;GACD,OAAO;EACT;EACA,KAAK,KAAA;EACL,KAAK;EACL,KAAK;EACL,KAAK;GACH,GAAG,IAAI,KAAK;GACZ,OAAO,UAAU,KAAA,IAAY,IAAI;EACnC;GACE,GAAG,IAAI,mBAAmB,MAAM,OAAO,OAAO;GAC9C,OAAO;CACX;AACF"}
@@ -0,0 +1,43 @@
1
+ export declare namespace Harnessd {
2
+ /** `config.json` in harnessd's home, read at every start of Claude Code. */
3
+ type Config = {
4
+ /** The agent's folder: Claude Code runs here and reads its CLAUDE.md. */
5
+ readonly folder: string;
6
+ /** More arguments for `claude`. */
7
+ readonly args: readonly string[];
8
+ /** More environment for `claude`. */
9
+ readonly env: Readonly<Record<string, string>>;
10
+ /** A shell command run before each start; its stdout is JSON `{ env?, args? }` for that start. */
11
+ readonly prestart?: string;
12
+ /** MCP servers whose events reach the agent, by name. */
13
+ readonly channels: Readonly<Record<string, Channel>>;
14
+ };
15
+ /** A Streamable HTTP MCP server; `${VAR}` in a header reads the environment. */
16
+ type Channel = {
17
+ readonly url: string;
18
+ readonly headers: Readonly<Record<string, string>>;
19
+ /** Subscription arguments for its events, such as the board to follow; each event type takes the ones it declares. */
20
+ readonly arguments: Readonly<Record<string, string | number | boolean>>;
21
+ };
22
+ /** Where one harnessd keeps its files. */
23
+ type Paths = {
24
+ readonly home: string;
25
+ readonly config: string;
26
+ readonly state: string;
27
+ readonly log: string;
28
+ readonly socket: string;
29
+ readonly plugin: string;
30
+ readonly channels: string;
31
+ readonly label: string;
32
+ };
33
+ }
34
+ export declare const pathsOf: (env?: NodeJS.ProcessEnv) => Harnessd.Paths;
35
+ export declare const DEFAULT_CONFIG: {
36
+ folder: string;
37
+ channels: {};
38
+ };
39
+ export declare const parseConfig: (raw: unknown) => Harnessd.Config;
40
+ export declare const readConfig: (paths: Harnessd.Paths) => Harnessd.Config;
41
+ /** A channel's headers with each `${VAR}` read from `env`; a variable that isn't set throws. */
42
+ export declare const headersOf: (channel: Harnessd.Channel, env: NodeJS.ProcessEnv) => Record<string, string>;
43
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAKA,yBAAiB,QAAQ,CAAC;IACxB,4EAA4E;IAC5E,KAAY,MAAM,GAAG;QACnB,yEAAyE;QACzE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;QACxB,mCAAmC;QACnC,QAAQ,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;QACjC,qCAAqC;QACrC,QAAQ,CAAC,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;QAC/C,kGAAkG;QAClG,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;QAC3B,yDAAyD;QACzD,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;KACtD,CAAC;IAEF,g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