@harness-sdk/harnessd 0.0.1 → 0.0.2
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.
- package/README.md +14 -13
- package/dist/accounts.d.ts +66 -0
- package/dist/accounts.d.ts.map +1 -0
- package/dist/accounts.js +166 -0
- package/dist/accounts.js.map +1 -0
- package/dist/bin.js +4 -0
- package/dist/bin.js.map +1 -1
- package/dist/channel.js +1 -1
- package/dist/claude.d.ts +12 -13
- package/dist/claude.d.ts.map +1 -1
- package/dist/claude.js +45 -59
- package/dist/claude.js.map +1 -1
- package/dist/cli.d.ts +5 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +269 -114
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +14 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +53 -13
- package/dist/config.js.map +1 -1
- package/dist/daemon.d.ts +17 -4
- package/dist/daemon.d.ts.map +1 -1
- package/dist/daemon.js +112 -51
- package/dist/daemon.js.map +1 -1
- package/dist/launchd.d.ts +12 -16
- package/dist/launchd.d.ts.map +1 -1
- package/dist/launchd.js +28 -25
- package/dist/launchd.js.map +1 -1
- package/dist/prompts.d.ts +53 -0
- package/dist/prompts.d.ts.map +1 -0
- package/dist/prompts.js +171 -0
- package/dist/prompts.js.map +1 -0
- package/dist/service.d.ts +37 -0
- package/dist/service.d.ts.map +1 -0
- package/dist/service.js +71 -0
- package/dist/service.js.map +1 -0
- package/dist/setup.d.ts +37 -0
- package/dist/setup.d.ts.map +1 -0
- package/dist/setup.js +121 -0
- package/dist/setup.js.map +1 -0
- package/dist/system.d.ts +6 -0
- package/dist/system.d.ts.map +1 -0
- package/dist/system.js +16 -0
- package/dist/system.js.map +1 -0
- package/dist/systemd.d.ts +14 -0
- package/dist/systemd.d.ts.map +1 -0
- package/dist/systemd.js +62 -0
- package/dist/systemd.js.map +1 -0
- package/dist/watchdog.d.ts +14 -4
- package/dist/watchdog.d.ts.map +1 -1
- package/dist/watchdog.js +30 -24
- package/dist/watchdog.js.map +1 -1
- package/package.json +5 -3
- package/src/accounts.ts +242 -0
- package/src/bin.ts +6 -0
- package/src/claude.ts +65 -90
- package/src/cli.ts +413 -152
- package/src/config.ts +92 -14
- package/src/daemon.ts +131 -64
- package/src/launchd.ts +40 -35
- package/src/prompts.ts +255 -0
- package/src/service.ts +145 -0
- package/src/setup.ts +188 -0
- package/src/system.ts +11 -0
- package/src/systemd.ts +78 -0
- package/src/watchdog.ts +41 -33
package/src/claude.ts
CHANGED
|
@@ -17,10 +17,8 @@ import { delimiter, join } from "node:path";
|
|
|
17
17
|
import type { Harnessd } from "./config";
|
|
18
18
|
import type { Watchdog } from "./watchdog";
|
|
19
19
|
|
|
20
|
-
/** How Claude Code names a `--plugin-dir` plugin
|
|
20
|
+
/** How Claude Code names a `--plugin-dir` plugin. */
|
|
21
21
|
export const PLUGIN = "harnessd@inline";
|
|
22
|
-
export const MANAGED_SETTINGS =
|
|
23
|
-
"/Library/Application Support/ClaudeCode/managed-settings.json";
|
|
24
22
|
|
|
25
23
|
const claudeDir = (env: NodeJS.ProcessEnv) =>
|
|
26
24
|
env.CLAUDE_CONFIG_DIR || join(homedir(), ".claude");
|
|
@@ -86,56 +84,95 @@ export const which = (name: string, path = process.env.PATH ?? "") => {
|
|
|
86
84
|
);
|
|
87
85
|
};
|
|
88
86
|
|
|
87
|
+
const shellQuote = (text: string) => `'${text.replaceAll("'", "'\\''")}'`;
|
|
88
|
+
|
|
89
89
|
/**
|
|
90
|
-
* harnessd's plugin, written before each start
|
|
91
|
-
* `harnessd channel <name
|
|
90
|
+
* harnessd's plugin, written before each start: one MCP server per channel of the config, each
|
|
91
|
+
* `harnessd channel <name>`, and a SessionStart hook that tells harnessd which conversation Claude Code is in, so a
|
|
92
|
+
* /clear or a /resume is the conversation the next start resumes.
|
|
92
93
|
*/
|
|
93
94
|
export const writePlugin = (
|
|
94
95
|
paths: Harnessd.Paths,
|
|
95
96
|
config: Harnessd.Config,
|
|
96
97
|
bin: string,
|
|
97
|
-
)
|
|
98
|
+
) => {
|
|
98
99
|
rmSync(paths.plugin, { recursive: true, force: true });
|
|
99
|
-
const names = Object.keys(config.channels);
|
|
100
|
-
if (names.length === 0) return false;
|
|
101
100
|
mkdirSync(join(paths.plugin, ".claude-plugin"), { recursive: true });
|
|
101
|
+
const names = Object.keys(config.channels);
|
|
102
|
+
const sessionStart = [
|
|
103
|
+
...Object.entries(paths.env).map(
|
|
104
|
+
([name, value]) => `${name}=${shellQuote(value)}`,
|
|
105
|
+
),
|
|
106
|
+
shellQuote(process.execPath),
|
|
107
|
+
shellQuote(bin),
|
|
108
|
+
"session-start",
|
|
109
|
+
].join(" ");
|
|
102
110
|
const manifest = {
|
|
103
111
|
name: "harnessd",
|
|
104
112
|
version: "1.0.0",
|
|
105
|
-
description:
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
113
|
+
description:
|
|
114
|
+
"harnessd's channels, each one's events and tools, and its SessionStart hook",
|
|
115
|
+
...(names.length > 0 && {
|
|
116
|
+
mcpServers: Object.fromEntries(
|
|
117
|
+
names.map((name) => [
|
|
118
|
+
name,
|
|
119
|
+
{
|
|
120
|
+
command: process.execPath,
|
|
121
|
+
args: [bin, "channel", name],
|
|
122
|
+
env: paths.env,
|
|
123
|
+
},
|
|
124
|
+
]),
|
|
125
|
+
),
|
|
126
|
+
channels: names.map((name) => ({ server: name, displayName: name })),
|
|
127
|
+
}),
|
|
128
|
+
hooks: {
|
|
129
|
+
SessionStart: [{ hooks: [{ type: "command", command: sessionStart }] }],
|
|
130
|
+
},
|
|
117
131
|
};
|
|
118
132
|
writeFileSync(
|
|
119
133
|
join(paths.plugin, ".claude-plugin", "plugin.json"),
|
|
120
134
|
`${JSON.stringify(manifest, null, 2)}\n`,
|
|
121
135
|
);
|
|
122
|
-
return true;
|
|
123
136
|
};
|
|
124
137
|
|
|
138
|
+
/** Whether these claude arguments pick a permission mode themselves. */
|
|
139
|
+
const picksPermissionMode = (args: readonly string[]) =>
|
|
140
|
+
args.some(
|
|
141
|
+
(arg) =>
|
|
142
|
+
arg === "--dangerously-skip-permissions" ||
|
|
143
|
+
arg === "--permission-mode" ||
|
|
144
|
+
arg.startsWith("--permission-mode="),
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
/** Whether these claude arguments turn permission prompts off: the config's `args` (or prestart's) ask for it, harnessd never does. */
|
|
148
|
+
export const skipsPermissions = (args: readonly string[]) =>
|
|
149
|
+
args.some(
|
|
150
|
+
(arg, i) =>
|
|
151
|
+
arg === "--dangerously-skip-permissions" ||
|
|
152
|
+
arg === "--permission-mode=bypassPermissions" ||
|
|
153
|
+
(arg === "bypassPermissions" && args[i - 1] === "--permission-mode"),
|
|
154
|
+
);
|
|
155
|
+
|
|
125
156
|
/**
|
|
126
|
-
* The claude command line for one start (after the binary).
|
|
127
|
-
*
|
|
157
|
+
* The claude command line for one start (after the binary). Claude Code runs in its auto permission mode, which
|
|
158
|
+
* decides each action itself, unless the config's arguments pick another mode. harnessd's plugin is written on this Mac at each start, so
|
|
159
|
+
* its channels load with Claude Code's flag for local channels, which asks for no entry in an approved list. Claude
|
|
160
|
+
* Code then asks once per start whether this is local development; harnessd answers that (see prompts.ts).
|
|
128
161
|
*/
|
|
129
162
|
export const claudeArgs = (o: {
|
|
130
163
|
start: Watchdog.Start;
|
|
131
|
-
plugin: string
|
|
132
|
-
allowed: boolean;
|
|
164
|
+
plugin: string;
|
|
133
165
|
config: Harnessd.Config;
|
|
134
166
|
extra: readonly string[];
|
|
135
167
|
}) => [
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
168
|
+
...(picksPermissionMode([...o.config.args, ...o.extra])
|
|
169
|
+
? []
|
|
170
|
+
: ["--permission-mode", "auto"]),
|
|
171
|
+
"--plugin-dir",
|
|
172
|
+
o.plugin,
|
|
173
|
+
...(Object.keys(o.config.channels).length > 0
|
|
174
|
+
? ["--dangerously-load-development-channels", `plugin:${PLUGIN}`]
|
|
175
|
+
: []),
|
|
139
176
|
...(o.start.resume
|
|
140
177
|
? ["--resume", o.start.sessionId]
|
|
141
178
|
: ["--session-id", o.start.sessionId]),
|
|
@@ -210,65 +247,3 @@ export const prestart = (
|
|
|
210
247
|
},
|
|
211
248
|
);
|
|
212
249
|
});
|
|
213
|
-
|
|
214
|
-
/** What keeps harnessd's channels out of Claude Code on this Mac: its managed settings must let `harnessd@inline` in. */
|
|
215
|
-
export const channelBlockers = (file = MANAGED_SETTINGS): string[] => {
|
|
216
|
-
let settings: { channelsEnabled?: unknown; allowedChannelPlugins?: unknown } =
|
|
217
|
-
{};
|
|
218
|
-
try {
|
|
219
|
-
const parsed: unknown = JSON.parse(readFileSync(file, "utf8"));
|
|
220
|
-
if (typeof parsed === "object" && parsed !== null) settings = parsed;
|
|
221
|
-
} catch {}
|
|
222
|
-
const listed =
|
|
223
|
-
Array.isArray(settings.allowedChannelPlugins) &&
|
|
224
|
-
settings.allowedChannelPlugins.some(
|
|
225
|
-
(entry: unknown) =>
|
|
226
|
-
entry === PLUGIN ||
|
|
227
|
-
(typeof entry === "object" &&
|
|
228
|
-
entry !== null &&
|
|
229
|
-
(entry as { plugin?: unknown }).plugin === "harnessd" &&
|
|
230
|
-
(entry as { marketplace?: unknown }).marketplace === "inline"),
|
|
231
|
-
);
|
|
232
|
-
return [
|
|
233
|
-
...(settings.channelsEnabled === true
|
|
234
|
-
? []
|
|
235
|
-
: [`${file} doesn't set channelsEnabled: true`]),
|
|
236
|
-
...(listed
|
|
237
|
-
? []
|
|
238
|
-
: [`${file} doesn't list ${PLUGIN} in allowedChannelPlugins`]),
|
|
239
|
-
];
|
|
240
|
-
};
|
|
241
|
-
|
|
242
|
-
/** The managed settings with harnessd's channel let in; a list that wasn't there starts with Anthropic's own channels. */
|
|
243
|
-
export const allowChannel = (
|
|
244
|
-
file = MANAGED_SETTINGS,
|
|
245
|
-
): Record<string, unknown> => {
|
|
246
|
-
// only a missing file starts from nothing: anything else there is policy to keep
|
|
247
|
-
const settings: Record<string, unknown> = existsSync(file)
|
|
248
|
-
? JSON.parse(readFileSync(file, "utf8"))
|
|
249
|
-
: {};
|
|
250
|
-
if (
|
|
251
|
-
typeof settings !== "object" ||
|
|
252
|
-
settings === null ||
|
|
253
|
-
Array.isArray(settings)
|
|
254
|
-
)
|
|
255
|
-
throw new Error(
|
|
256
|
-
`${file} isn't a JSON object; harnessd won't write over it`,
|
|
257
|
-
);
|
|
258
|
-
const list = Array.isArray(settings.allowedChannelPlugins)
|
|
259
|
-
? settings.allowedChannelPlugins
|
|
260
|
-
: ["telegram", "discord", "imessage", "fakechat"].map((plugin) => ({
|
|
261
|
-
marketplace: "claude-plugins-official",
|
|
262
|
-
plugin,
|
|
263
|
-
}));
|
|
264
|
-
return {
|
|
265
|
-
...settings,
|
|
266
|
-
channelsEnabled: true,
|
|
267
|
-
allowedChannelPlugins: [
|
|
268
|
-
...list.filter(
|
|
269
|
-
(entry) => !(typeof entry === "object" && entry?.plugin === "harnessd"),
|
|
270
|
-
),
|
|
271
|
-
{ marketplace: "inline", plugin: "harnessd" },
|
|
272
|
-
],
|
|
273
|
-
};
|
|
274
|
-
};
|