@harness-sdk/harnessd 0.0.1 → 0.1.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.
- package/README.md +31 -18
- 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.d.ts +15 -10
- package/dist/channel.d.ts.map +1 -1
- package/dist/channel.js +113 -158
- package/dist/channel.js.map +1 -1
- package/dist/claude.d.ts +17 -13
- package/dist/claude.d.ts.map +1 -1
- package/dist/claude.js +69 -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 +317 -131
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +46 -10
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +142 -51
- package/dist/config.js.map +1 -1
- package/dist/daemon.d.ts +29 -4
- package/dist/daemon.d.ts.map +1 -1
- package/dist/daemon.js +174 -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 +8 -12
- package/src/accounts.ts +242 -0
- package/src/bin.ts +6 -0
- package/src/channel.ts +151 -172
- package/src/claude.ts +90 -88
- package/src/cli.ts +494 -183
- package/src/config.ts +239 -63
- package/src/daemon.ts +215 -65
- 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/README.md
CHANGED
|
@@ -1,54 +1,66 @@
|
|
|
1
1
|
# harnessd
|
|
2
2
|
|
|
3
|
-
harnessd keeps Claude Code running on your Mac, day and night, connected to the events of your agentic apps. Put it on a Mac mini and you have an agent that's always on.
|
|
3
|
+
harnessd keeps Claude Code running on your Mac or Linux machine, day and night, connected to the events of your agentic apps. Put it on a Mac mini and you have an agent that's always on.
|
|
4
4
|
|
|
5
5
|
- It starts at login and after any crash, and picks up the same conversation.
|
|
6
|
-
-
|
|
6
|
+
- When Claude Code's own updater installs a new version, it restarts Claude Code into it once the agent is idle.
|
|
7
|
+
- Each agentic app you connect is a server. The events you subscribe to reach the agent as they happen, and its tools are a command the agent runs to answer.
|
|
7
8
|
- Its terminal is there whenever you want it, on the Mac or over SSH.
|
|
8
9
|
|
|
9
10
|
## Install
|
|
10
11
|
|
|
11
12
|
```sh
|
|
12
13
|
npm install -g @harness-sdk/harnessd
|
|
13
|
-
harnessd install
|
|
14
|
+
harnessd service install
|
|
14
15
|
harnessd attach
|
|
15
16
|
```
|
|
16
17
|
|
|
17
|
-
`harnessd
|
|
18
|
+
`harnessd service install` checks that Claude Code is installed and signed in. If it isn't, it asks whether to install it with Anthropic's installer, and whether to sign in now. `harnessd attach` opens Claude Code's terminal; Ctrl-\\ detaches, and Claude Code keeps running.
|
|
18
19
|
|
|
19
|
-
The agent works in `~/agent`, which harnessd marks as trusted in Claude Code. Its standing instructions go in `~/agent/CLAUDE.md`, the file Claude Code already reads.
|
|
20
|
+
The agent works in `~/agent`, which harnessd marks as trusted in Claude Code. Its standing instructions go in `~/agent/CLAUDE.md`, the file Claude Code already reads. Claude Code runs in its auto permission mode, which decides each action itself. To turn permission prompts off instead, add `"args": ["--dangerously-skip-permissions"]` to the config file, and give the agent a machine of its own.
|
|
20
21
|
|
|
21
|
-
|
|
22
|
+
Claude Code updates itself, but a running Claude Code keeps its version until it restarts. harnessd checks for a newer installed version every hour and each time Claude Code says it's idle: no turn, no background agent, nothing on screen to answer. Once the agent is idle, harnessd restarts Claude Code into the new version, in the same conversation, and tells it it was updated. To hold a version, set `DISABLE_AUTOUPDATER=1` in Claude Code's settings and install that version with `claude install <version>`.
|
|
22
23
|
|
|
23
|
-
|
|
24
|
+
harnessd starts when you log in. On a Mac, turn on automatic login (System Settings, Users & Groups), so the agent comes back after a power cut. Or install it with `sudo harnessd service install`: it then starts at boot, with nobody logged in, and still runs as your user. Linux needs systemd, on x64 or arm64.
|
|
24
25
|
|
|
25
|
-
|
|
26
|
+
## Connect a server
|
|
27
|
+
|
|
28
|
+
A server is an MCP server, such as a [Statewire](https://www.npmjs.com/package/statewire) host. List it in `~/.config/harnessd/config.json`, and subscribe the channel to the events the agent should get:
|
|
26
29
|
|
|
27
30
|
```json
|
|
28
31
|
{
|
|
32
|
+
"compatibilityDate": "2026-12-02",
|
|
29
33
|
"folder": "~/agent",
|
|
30
|
-
"
|
|
34
|
+
"servers": {
|
|
31
35
|
"board": {
|
|
32
36
|
"url": "https://board.example.com/api/board/mcp",
|
|
33
37
|
"headers": { "Authorization": "Bearer ${BOARD_TOKEN}" }
|
|
34
38
|
}
|
|
39
|
+
},
|
|
40
|
+
"channel": {
|
|
41
|
+
"subscribe": [
|
|
42
|
+
{ "server": "board", "event": "task.handed", "arguments": { "board": "main" } }
|
|
43
|
+
]
|
|
35
44
|
}
|
|
36
45
|
}
|
|
37
46
|
```
|
|
38
47
|
|
|
39
|
-
Each event reaches the conversation as `<channel source="plugin:harnessd:board" event="
|
|
48
|
+
Each subscribed event reaches the conversation as `<channel source="plugin:harnessd:channel" server="board" event="task.handed">…</channel>`, and no other event does. The server's tools are the `board` command in the agent's shell: `board --help` lists them. If the agent restarts, the events it missed come when it's back.
|
|
40
49
|
|
|
41
|
-
|
|
50
|
+
harnessd loads its channel with Claude Code's flag for local channels and answers its start-up warning. `harnessd status` shows whether the events arrive, and says so when managed settings turn channels off.
|
|
42
51
|
|
|
43
52
|
## The config file
|
|
44
53
|
|
|
45
54
|
| Key | What it does |
|
|
46
55
|
| --- | --- |
|
|
56
|
+
| `compatibilityDate` | The date the file was written. `harnessd service install` writes it, and harnessd behaves as it did on that date. |
|
|
47
57
|
| `folder` | Where Claude Code runs. |
|
|
48
58
|
| `args` | More arguments for `claude`, such as `["--model", "opus"]` or `["--remote-control"]`. |
|
|
49
59
|
| `env` | More environment for `claude`. |
|
|
50
60
|
| `prestart` | A shell command run before each start. It prints `{ "env": {…}, "args": […] }` for that start, so a token is fetched fresh and never kept on disk. |
|
|
51
|
-
| `
|
|
61
|
+
| `servers` | MCP servers by name: a `url` (https, or http on this Mac) and `headers` that read `${VAR}` from the environment. Each one's tools are a command of its name for the agent. |
|
|
62
|
+
| `channel` | `subscribe`: the events that reach the agent, each a `server`, an `event` and its `arguments`. |
|
|
63
|
+
| `accounts` | Claude accounts by name, each with the `env` that signs it in, such as a `claude setup-token` token in `CLAUDE_CODE_OAUTH_TOKEN`. When the one in use hits its usage limit or its sign-in fails, Claude Code goes on with the next, in the same conversation. |
|
|
52
64
|
|
|
53
65
|
A change takes effect at the next start: `harnessd stop`, then `harnessd start`.
|
|
54
66
|
|
|
@@ -56,9 +68,10 @@ A change takes effect at the next start: `harnessd stop`, then `harnessd start`.
|
|
|
56
68
|
|
|
57
69
|
| Command | What it does |
|
|
58
70
|
| --- | --- |
|
|
59
|
-
| `harnessd
|
|
60
|
-
| `harnessd
|
|
61
|
-
| `harnessd
|
|
62
|
-
| `harnessd
|
|
63
|
-
| `harnessd
|
|
64
|
-
| `harnessd
|
|
71
|
+
| `harnessd service install` | Start harnessd now and at every login. With `sudo`: at every boot, as your user (`--user <name>` for another). Run it again after an upgrade. |
|
|
72
|
+
| `harnessd service uninstall` | Stop harnessd and remove its service (with `sudo` for a boot service). Your settings and conversation stay. |
|
|
73
|
+
| `harnessd status` | What runs, which Claude Code version and conversation, an update waiting for the agent to be idle, whether events arrive, and the log's last lines and path. `--json` for scripts. |
|
|
74
|
+
| `harnessd attach` | Claude Code's terminal. `/clear` there starts a new conversation, and restarts resume that one. |
|
|
75
|
+
| `harnessd stop`, `harnessd start` | Stop Claude Code until you start it again. harnessd itself stays up and answers `status`. |
|
|
76
|
+
| `harnessd tools <server>` | A server's tools, the same command the agent runs as `<server>`. `harnessd tools <server> login` signs in to a server that asks for OAuth. |
|
|
77
|
+
| `harnessd --version` | harnessd's version. |
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
export declare namespace Accounts {
|
|
2
|
+
/** Why Claude Code can't go on with the account it runs on. */
|
|
3
|
+
type Stop = {
|
|
4
|
+
readonly why: "its usage limit" | "a failed sign-in";
|
|
5
|
+
/** When the account is worth another try (epoch ms). */
|
|
6
|
+
readonly until: number;
|
|
7
|
+
};
|
|
8
|
+
/** An account harnessd passes over, for now. */
|
|
9
|
+
type Mark = Stop & {
|
|
10
|
+
/** The account's environment when it stopped: a changed one (a new token) is tried again. */
|
|
11
|
+
readonly env: string;
|
|
12
|
+
};
|
|
13
|
+
type Options = {
|
|
14
|
+
/** The config's accounts, in its order. */
|
|
15
|
+
readonly accounts: () => Readonly<Record<string, Readonly<Record<string, string>>>>;
|
|
16
|
+
readonly now?: () => number;
|
|
17
|
+
};
|
|
18
|
+
type Rotation = {
|
|
19
|
+
/** The account the next start runs on: `current` while it can go on, else the first that can. All stopped: `current`. */
|
|
20
|
+
readonly pick: (current: string | undefined) => string | undefined;
|
|
21
|
+
readonly mark: (name: string, stop: Stop) => void;
|
|
22
|
+
/** The accounts passed over now. */
|
|
23
|
+
readonly marks: () => Readonly<Record<string, Stop>>;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/** Whether a line of Claude Code's transcript says the account can't go on: a usage limit, or a sign-in the API refused. */
|
|
27
|
+
export declare const accountStop: (entry: unknown, now?: number) => Accounts.Stop | undefined;
|
|
28
|
+
/** Which of the config's accounts Claude Code runs on, and which it passes over until they can go on again. */
|
|
29
|
+
export declare const rotation: (options: Accounts.Options) => Accounts.Rotation;
|
|
30
|
+
/**
|
|
31
|
+
* Calls `onEntry` with each line the conversation's transcript gains from now on; `file` says where it is once Claude
|
|
32
|
+
* Code has written it. When Claude Code moves to another conversation, its transcript is followed from then on.
|
|
33
|
+
*/
|
|
34
|
+
export declare const followTranscript: (o: {
|
|
35
|
+
sessionId: () => string;
|
|
36
|
+
file: (sessionId: string) => string | undefined;
|
|
37
|
+
onEntry: (entry: unknown) => void;
|
|
38
|
+
/** After each look at the transcript, whether it gained lines or not. */
|
|
39
|
+
onRead?: () => void;
|
|
40
|
+
everyMs?: number;
|
|
41
|
+
}) => {
|
|
42
|
+
/** Reads what the transcript gained since the last look, then stops looking. */
|
|
43
|
+
finish: () => void;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* One start of Claude Code on `account`, watched from before the start to after the exit: when the account stops and
|
|
47
|
+
* another can go on, Claude Code hands over to it in the same conversation.
|
|
48
|
+
*/
|
|
49
|
+
export declare const accountRun: (o: {
|
|
50
|
+
account: string;
|
|
51
|
+
rotation: Accounts.Rotation;
|
|
52
|
+
/** The conversation Claude Code is in. */
|
|
53
|
+
sessionId: () => string;
|
|
54
|
+
/** Where a conversation's transcript is, once Claude Code has written it. */
|
|
55
|
+
file: (sessionId: string) => string | undefined;
|
|
56
|
+
/** Restarts the start with this pid, telling the conversation why. */
|
|
57
|
+
restart: (reason: string, pid: number) => void;
|
|
58
|
+
log: (line: string) => void;
|
|
59
|
+
everyMs?: number;
|
|
60
|
+
}) => {
|
|
61
|
+
/** Claude Code runs. */
|
|
62
|
+
started: (startedPid: number) => undefined;
|
|
63
|
+
/** Claude Code exited, or never started: reads the transcript's last lines. A reason: the next start goes on with another account, and is told this. */
|
|
64
|
+
exited: () => string | undefined;
|
|
65
|
+
};
|
|
66
|
+
//# sourceMappingURL=accounts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accounts.d.ts","sourceRoot":"","sources":["../src/accounts.ts"],"names":[],"mappings":"AAEA,yBAAiB,QAAQ,CAAC;IACxB,+DAA+D;IAC/D,KAAY,IAAI,GAAG;QACjB,QAAQ,CAAC,GAAG,EAAE,iBAAiB,GAAG,kBAAkB,CAAC;QACrD,wDAAwD;QACxD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;KACxB,CAAC;IAEF,gDAAgD;IAChD,KAAY,IAAI,GAAG,IAAI,GAAG;QACxB,6FAA6F;QAC7F,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;KACtB,CAAC;IAEF,KAAY,OAAO,GAAG;QACpB,2CAA2C;QAC3C,QAAQ,CAAC,QAAQ,EAAE,MAAM,QAAQ,CAC/B,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CACjD,CAAC;QACF,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;KAC7B,CAAC;IAEF,KAAY,QAAQ,GAAG;QACrB,yHAAyH;QACzH,QAAQ,CAAC,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,KAAK,MAAM,GAAG,SAAS,CAAC;QACnE,QAAQ,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC;QAClD,oCAAoC;QACpC,QAAQ,CAAC,KAAK,EAAE,MAAM,QAAQ,CA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Sync, fstatSync, openSync, readSync } from "node:fs";
|
|
2
|
+
// src/accounts.ts
|
|
3
|
+
const LIMIT_MS = 18e6;
|
|
4
|
+
const SIGN_IN_MS = 864e5;
|
|
5
|
+
/** Whether a line of Claude Code's transcript says the account can't go on: a usage limit, or a sign-in the API refused. */
|
|
6
|
+
const accountStop = (entry, now = Date.now()) => {
|
|
7
|
+
if (typeof entry !== "object" || entry === null) return void 0;
|
|
8
|
+
const e = entry;
|
|
9
|
+
if (e.type !== "assistant" || e.isApiErrorMessage !== true) return void 0;
|
|
10
|
+
if (e.error === "authentication_failed") return {
|
|
11
|
+
why: "a failed sign-in",
|
|
12
|
+
until: now + SIGN_IN_MS
|
|
13
|
+
};
|
|
14
|
+
if (e.error !== "rate_limit" || e.apiErrorStatus !== 429 || e.apiErrorIsTransient === true) return void 0;
|
|
15
|
+
const resetsAt = e.quotaLimits?.resetsAt;
|
|
16
|
+
return {
|
|
17
|
+
why: "its usage limit",
|
|
18
|
+
until: typeof resetsAt === "number" && resetsAt * 1e3 > now ? resetsAt * 1e3 : now + LIMIT_MS
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
/** Which of the config's accounts Claude Code runs on, and which it passes over until they can go on again. */
|
|
22
|
+
const rotation = (options) => {
|
|
23
|
+
const now = options.now ?? Date.now;
|
|
24
|
+
const marked = /* @__PURE__ */ new Map();
|
|
25
|
+
const stopped = (name, env) => {
|
|
26
|
+
const mark = marked.get(name);
|
|
27
|
+
if (!mark) return false;
|
|
28
|
+
if (mark.until > now() && mark.env === JSON.stringify(env)) return true;
|
|
29
|
+
marked.delete(name);
|
|
30
|
+
return false;
|
|
31
|
+
};
|
|
32
|
+
const open = () => Object.entries(options.accounts()).filter(([name, env]) => !stopped(name, env)).map(([name]) => name);
|
|
33
|
+
return {
|
|
34
|
+
pick: (current) => {
|
|
35
|
+
const accounts = options.accounts();
|
|
36
|
+
const names = Object.keys(accounts);
|
|
37
|
+
const free = open();
|
|
38
|
+
if (current !== void 0 && free.includes(current)) return current;
|
|
39
|
+
return free[0] ?? (current !== void 0 && current in accounts ? current : names[0]);
|
|
40
|
+
},
|
|
41
|
+
mark: (name, stop) => {
|
|
42
|
+
const env = options.accounts()[name];
|
|
43
|
+
if (env) marked.set(name, {
|
|
44
|
+
...stop,
|
|
45
|
+
env: JSON.stringify(env)
|
|
46
|
+
});
|
|
47
|
+
},
|
|
48
|
+
marks: () => {
|
|
49
|
+
const accounts = options.accounts();
|
|
50
|
+
for (const name of marked.keys()) if (!(name in accounts)) marked.delete(name);
|
|
51
|
+
const free = new Set(open());
|
|
52
|
+
return Object.fromEntries([...marked].filter(([name]) => !free.has(name)).map(([name, { why, until }]) => [name, {
|
|
53
|
+
why,
|
|
54
|
+
until
|
|
55
|
+
}]));
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Calls `onEntry` with each line the conversation's transcript gains from now on; `file` says where it is once Claude
|
|
61
|
+
* Code has written it. When Claude Code moves to another conversation, its transcript is followed from then on.
|
|
62
|
+
*/
|
|
63
|
+
const followTranscript = (o) => {
|
|
64
|
+
let sessionId;
|
|
65
|
+
let path;
|
|
66
|
+
let offset;
|
|
67
|
+
let rest = "";
|
|
68
|
+
const read = () => {
|
|
69
|
+
if (o.sessionId() !== sessionId) {
|
|
70
|
+
sessionId = o.sessionId();
|
|
71
|
+
path = void 0;
|
|
72
|
+
offset = void 0;
|
|
73
|
+
rest = "";
|
|
74
|
+
}
|
|
75
|
+
path ??= o.file(sessionId);
|
|
76
|
+
if (path === void 0) {
|
|
77
|
+
offset = 0;
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
let fd;
|
|
81
|
+
try {
|
|
82
|
+
fd = openSync(path, "r");
|
|
83
|
+
} catch {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
try {
|
|
87
|
+
const { size } = fstatSync(fd);
|
|
88
|
+
offset ??= size;
|
|
89
|
+
if (size <= offset) return;
|
|
90
|
+
const chunk = Buffer.alloc(size - offset);
|
|
91
|
+
readSync(fd, chunk, 0, chunk.length, offset);
|
|
92
|
+
offset = size;
|
|
93
|
+
const lines = (rest + chunk.toString("utf8")).split("\n");
|
|
94
|
+
rest = lines.pop() ?? "";
|
|
95
|
+
for (const line of lines) {
|
|
96
|
+
if (!line.trim()) continue;
|
|
97
|
+
let entry;
|
|
98
|
+
try {
|
|
99
|
+
entry = JSON.parse(line);
|
|
100
|
+
} catch {
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
o.onEntry(entry);
|
|
104
|
+
}
|
|
105
|
+
} finally {
|
|
106
|
+
closeSync(fd);
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
const look = () => {
|
|
110
|
+
read();
|
|
111
|
+
o.onRead?.();
|
|
112
|
+
};
|
|
113
|
+
look();
|
|
114
|
+
const timer = setInterval(look, o.everyMs ?? 1e4);
|
|
115
|
+
return {
|
|
116
|
+
/** Reads what the transcript gained since the last look, then stops looking. */
|
|
117
|
+
finish: () => {
|
|
118
|
+
clearInterval(timer);
|
|
119
|
+
read();
|
|
120
|
+
} };
|
|
121
|
+
};
|
|
122
|
+
/**
|
|
123
|
+
* One start of Claude Code on `account`, watched from before the start to after the exit: when the account stops and
|
|
124
|
+
* another can go on, Claude Code hands over to it in the same conversation.
|
|
125
|
+
*/
|
|
126
|
+
const accountRun = (o) => {
|
|
127
|
+
let pid;
|
|
128
|
+
let handed = false;
|
|
129
|
+
const handover = () => {
|
|
130
|
+
const why = o.rotation.marks()[o.account]?.why;
|
|
131
|
+
const next = o.rotation.pick(o.account);
|
|
132
|
+
if (handed || !why || next === void 0 || next === o.account) return void 0;
|
|
133
|
+
handed = true;
|
|
134
|
+
o.log(`switching from account ${o.account} to ${next}`);
|
|
135
|
+
return `account ${o.account} stopped at ${why}, so Claude Code now runs on account ${next}`;
|
|
136
|
+
};
|
|
137
|
+
const follow = followTranscript({
|
|
138
|
+
sessionId: o.sessionId,
|
|
139
|
+
file: o.file,
|
|
140
|
+
onEntry: (entry) => {
|
|
141
|
+
const stop = accountStop(entry);
|
|
142
|
+
if (!stop) return;
|
|
143
|
+
if (!(o.account in o.rotation.marks())) o.log(`account ${o.account} stopped at ${stop.why}`);
|
|
144
|
+
o.rotation.mark(o.account, stop);
|
|
145
|
+
},
|
|
146
|
+
onRead: () => {
|
|
147
|
+
if (pid === void 0) return;
|
|
148
|
+
const reason = handover();
|
|
149
|
+
if (reason !== void 0) o.restart(reason, pid);
|
|
150
|
+
},
|
|
151
|
+
...o.everyMs !== void 0 && { everyMs: o.everyMs }
|
|
152
|
+
});
|
|
153
|
+
return {
|
|
154
|
+
/** Claude Code runs. */
|
|
155
|
+
started: (startedPid) => void (pid = startedPid),
|
|
156
|
+
/** Claude Code exited, or never started: reads the transcript's last lines. A reason: the next start goes on with another account, and is told this. */
|
|
157
|
+
exited: () => {
|
|
158
|
+
pid = void 0;
|
|
159
|
+
follow.finish();
|
|
160
|
+
return handover();
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
};
|
|
164
|
+
export { accountRun, accountStop, followTranscript, rotation };
|
|
165
|
+
|
|
166
|
+
//# sourceMappingURL=accounts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accounts.js","names":[],"sources":["../src/accounts.ts"],"sourcesContent":["import { closeSync, fstatSync, openSync, readSync } from \"node:fs\";\n\nexport namespace Accounts {\n /** Why Claude Code can't go on with the account it runs on. */\n export type Stop = {\n readonly why: \"its usage limit\" | \"a failed sign-in\";\n /** When the account is worth another try (epoch ms). */\n readonly until: number;\n };\n\n /** An account harnessd passes over, for now. */\n export type Mark = Stop & {\n /** The account's environment when it stopped: a changed one (a new token) is tried again. */\n readonly env: string;\n };\n\n export type Options = {\n /** The config's accounts, in its order. */\n readonly accounts: () => Readonly<\n Record<string, Readonly<Record<string, string>>>\n >;\n readonly now?: () => number;\n };\n\n export type Rotation = {\n /** The account the next start runs on: `current` while it can go on, else the first that can. All stopped: `current`. */\n readonly pick: (current: string | undefined) => string | undefined;\n readonly mark: (name: string, stop: Stop) => void;\n /** The accounts passed over now. */\n readonly marks: () => Readonly<Record<string, Stop>>;\n };\n}\n\nconst LIMIT_MS = 5 * 60 * 60_000;\nconst SIGN_IN_MS = 24 * 60 * 60_000;\n\n/** Whether a line of Claude Code's transcript says the account can't go on: a usage limit, or a sign-in the API refused. */\nexport const accountStop = (\n entry: unknown,\n now = Date.now(),\n): Accounts.Stop | undefined => {\n if (typeof entry !== \"object\" || entry === null) return undefined;\n const e = entry as {\n type?: unknown;\n isApiErrorMessage?: unknown;\n error?: unknown;\n apiErrorStatus?: unknown;\n apiErrorIsTransient?: unknown;\n quotaLimits?: { resetsAt?: unknown };\n };\n if (e.type !== \"assistant\" || e.isApiErrorMessage !== true) return undefined;\n if (e.error === \"authentication_failed\")\n return { why: \"a failed sign-in\", until: now + SIGN_IN_MS };\n if (\n e.error !== \"rate_limit\" ||\n e.apiErrorStatus !== 429 ||\n e.apiErrorIsTransient === true\n )\n return undefined;\n const resetsAt = e.quotaLimits?.resetsAt;\n return {\n why: \"its usage limit\",\n until:\n typeof resetsAt === \"number\" && resetsAt * 1000 > now\n ? resetsAt * 1000\n : now + LIMIT_MS,\n };\n};\n\n/** Which of the config's accounts Claude Code runs on, and which it passes over until they can go on again. */\nexport const rotation = (options: Accounts.Options): Accounts.Rotation => {\n const now = options.now ?? Date.now;\n const marked = new Map<string, Accounts.Mark>();\n const stopped = (name: string, env: Readonly<Record<string, string>>) => {\n const mark = marked.get(name);\n if (!mark) return false;\n if (mark.until > now() && mark.env === JSON.stringify(env)) return true;\n marked.delete(name);\n return false;\n };\n const open = () =>\n Object.entries(options.accounts())\n .filter(([name, env]) => !stopped(name, env))\n .map(([name]) => name);\n return {\n pick: (current) => {\n const accounts = options.accounts();\n const names = Object.keys(accounts);\n const free = open();\n if (current !== undefined && free.includes(current)) return current;\n return (\n free[0] ??\n (current !== undefined && current in accounts ? current : names[0])\n );\n },\n mark: (name, stop) => {\n const env = options.accounts()[name];\n if (env) marked.set(name, { ...stop, env: JSON.stringify(env) });\n },\n marks: () => {\n const accounts = options.accounts();\n for (const name of marked.keys())\n if (!(name in accounts)) marked.delete(name);\n const free = new Set(open());\n return Object.fromEntries(\n [...marked]\n .filter(([name]) => !free.has(name))\n .map(([name, { why, until }]) => [name, { why, until }]),\n );\n },\n };\n};\n\n/**\n * Calls `onEntry` with each line the conversation's transcript gains from now on; `file` says where it is once Claude\n * Code has written it. When Claude Code moves to another conversation, its transcript is followed from then on.\n */\nexport const followTranscript = (o: {\n sessionId: () => string;\n file: (sessionId: string) => string | undefined;\n onEntry: (entry: unknown) => void;\n /** After each look at the transcript, whether it gained lines or not. */\n onRead?: () => void;\n everyMs?: number;\n}) => {\n let sessionId: string | undefined;\n let path: string | undefined;\n let offset: number | undefined;\n let rest = \"\";\n const read = () => {\n if (o.sessionId() !== sessionId) {\n sessionId = o.sessionId();\n path = undefined;\n offset = undefined;\n rest = \"\";\n }\n path ??= o.file(sessionId);\n if (path === undefined) {\n // a transcript that appears after the start, or after a move to another conversation, is read from its first line\n offset = 0;\n return;\n }\n let fd: number;\n try {\n fd = openSync(path, \"r\");\n } catch {\n return;\n }\n try {\n const { size } = fstatSync(fd);\n offset ??= size;\n if (size <= offset) return;\n const chunk = Buffer.alloc(size - offset);\n readSync(fd, chunk, 0, chunk.length, offset);\n offset = size;\n const lines = (rest + chunk.toString(\"utf8\")).split(\"\\n\");\n rest = lines.pop() ?? \"\";\n for (const line of lines) {\n if (!line.trim()) continue;\n let entry: unknown;\n try {\n entry = JSON.parse(line);\n } catch {\n continue;\n }\n o.onEntry(entry);\n }\n } finally {\n closeSync(fd);\n }\n };\n const look = () => {\n read();\n o.onRead?.();\n };\n look();\n const timer = setInterval(look, o.everyMs ?? 10_000);\n return {\n /** Reads what the transcript gained since the last look, then stops looking. */\n finish: () => {\n clearInterval(timer);\n read();\n },\n };\n};\n\n/**\n * One start of Claude Code on `account`, watched from before the start to after the exit: when the account stops and\n * another can go on, Claude Code hands over to it in the same conversation.\n */\nexport const accountRun = (o: {\n account: string;\n rotation: Accounts.Rotation;\n /** The conversation Claude Code is in. */\n sessionId: () => string;\n /** Where a conversation's transcript is, once Claude Code has written it. */\n file: (sessionId: string) => string | undefined;\n /** Restarts the start with this pid, telling the conversation why. */\n restart: (reason: string, pid: number) => void;\n log: (line: string) => void;\n everyMs?: number;\n}) => {\n let pid: number | undefined;\n let handed = false;\n const handover = () => {\n const why = o.rotation.marks()[o.account]?.why;\n const next = o.rotation.pick(o.account);\n if (handed || !why || next === undefined || next === o.account)\n return undefined;\n handed = true;\n o.log(`switching from account ${o.account} to ${next}`);\n return `account ${o.account} stopped at ${why}, so Claude Code now runs on account ${next}`;\n };\n const follow = followTranscript({\n sessionId: o.sessionId,\n file: o.file,\n onEntry: (entry) => {\n const stop = accountStop(entry);\n if (!stop) return;\n if (!(o.account in o.rotation.marks()))\n o.log(`account ${o.account} stopped at ${stop.why}`);\n o.rotation.mark(o.account, stop);\n },\n // after each look: a stopped account hands over as soon as another can go on, now or once that one's limit resets\n onRead: () => {\n if (pid === undefined) return;\n const reason = handover();\n if (reason !== undefined) o.restart(reason, pid);\n },\n ...(o.everyMs !== undefined && { everyMs: o.everyMs }),\n });\n return {\n /** Claude Code runs. */\n started: (startedPid: number) => void (pid = startedPid),\n /** Claude Code exited, or never started: reads the transcript's last lines. A reason: the next start goes on with another account, and is told this. */\n exited: () => {\n pid = undefined;\n follow.finish();\n return handover();\n },\n };\n};\n"],"mappings":";;AAiCA,MAAM,WAAW;AACjB,MAAM,aAAa;;AAGnB,MAAa,eACX,OACA,MAAM,KAAK,IAAI,MACe;CAC9B,IAAI,OAAO,UAAU,YAAY,UAAU,MAAM,OAAO,KAAA;CACxD,MAAM,IAAI;CAQV,IAAI,EAAE,SAAS,eAAe,EAAE,sBAAsB,MAAM,OAAO,KAAA;CACnE,IAAI,EAAE,UAAU,yBACd,OAAO;EAAE,KAAK;EAAoB,OA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AM,EAAE,WAAW,GAAM;CACnD,OAAO;;AAEL,cAAc;EACZ,cAAc,KAAK;EACnB,KAAK;CACP,EACF;AACF;;;;;AAMA,MAAa,cAAc,MAWrB;CACJ,IAAI;CACJ,IAAI,SAAS;CACb,MAAM,iBAAiB;EACrB,MAAM,MAAM,EAAE,SAAS,MAAM,CAAC,CAAC,EAAE,QAAQ,EAAE;EAC3C,MAAM,OAAO,EAAE,SAAS,KAAK,EAAE,OAAO;EACtC,IAAI,UAAU,CAAC,OAAO,SAAS,KAAA,KAAa,SAAS,EAAE,SACrD,OAAO,KAAA;EACT,SAAS;EACT,EAAE,IAAI,0BAA0B,EAAE,QAAQ,MAAM,MAAM;EACtD,OAAO,WAAW,EAAE,QAAQ,cAAc,IAAI,uCAAuC;CACvF;CACA,MAAM,SAAS,iBAAiB;EAC9B,WAAW,EAAE;EACb,MAAM,EAAE;EACR,UAAU,UAAU;GAClB,MAAM,OAAO,YAAY,KAAK;GAC9B,IAAI,CAAC,MAAM;GACX,IAAI,EAAE,EAAE,WAAW,EAAE,SAAS,MAAM,IAClC,EAAE,IAAI,WAAW,EAAE,QAAQ,cAAc,KAAK,KAAK;GACrD,EAAE,SAAS,KAAK,EAAE,SAAS,IAAI;EACjC;EAEA,cAAc;GACZ,IAAI,QAAQ,KAAA,GAAW;GACvB,MAAM,SAAS,SAAS;GACxB,IAAI,WAAW,KAAA,GAAW,EAAE,QAAQ,QAAQ,GAAG;EACjD;EACA,GAAI,EAAE,YAAY,KAAA,KAAa,EAAE,SAAS,EAAE,QAAQ;CACtD,CAAC;CACD,OAAO;;EAEL,UAAU,eAAuB,MAAM,MAAM;;EAE7C,cAAc;GACZ,MAAM,KAAA;GACN,OAAO,OAAO;GACd,OAAO,SAAS;EAClB;CACF;AACF"}
|
package/dist/bin.js
CHANGED
|
@@ -5,6 +5,10 @@ import { realpathSync } from "node:fs";
|
|
|
5
5
|
console.log = console.error.bind(console);
|
|
6
6
|
console.info = console.error.bind(console);
|
|
7
7
|
console.debug = console.error.bind(console);
|
|
8
|
+
process.stdout.on("error", (error) => {
|
|
9
|
+
if (error.code !== "EPIPE") throw error;
|
|
10
|
+
process.exit(0);
|
|
11
|
+
});
|
|
8
12
|
try {
|
|
9
13
|
process.exitCode = await runHarnessd(process.argv.slice(2), realpathSync(process.argv[1]));
|
|
10
14
|
} catch (error) {
|
package/dist/bin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bin.js","names":[],"sources":["../src/bin.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { realpathSync } from \"node:fs\";\nimport { runHarnessd } from \"./cli\";\n\n// stdout belongs to the command (for `harnessd channel`, to Claude Code)\nconsole.log = console.error.bind(console);\nconsole.info = console.error.bind(console);\nconsole.debug = console.error.bind(console);\n\ntry {\n process.exitCode = await runHarnessd(\n process.argv.slice(2),\n realpathSync(process.argv[1]!),\n );\n} catch (error) {\n console.error(error instanceof Error ? error.message : String(error));\n process.exitCode = 1;\n}\n"],"mappings":";;;;AAKA,QAAQ,MAAM,QAAQ,MAAM,KAAK,OAAO;AACxC,QAAQ,OAAO,QAAQ,MAAM,KAAK,OAAO;AACzC,QAAQ,QAAQ,QAAQ,MAAM,KAAK,OAAO;
|
|
1
|
+
{"version":3,"file":"bin.js","names":[],"sources":["../src/bin.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { realpathSync } from \"node:fs\";\nimport { runHarnessd } from \"./cli\";\n\n// stdout belongs to the command (for `harnessd channel`, to Claude Code)\nconsole.log = console.error.bind(console);\nconsole.info = console.error.bind(console);\nconsole.debug = console.error.bind(console);\n\n// a reader that closes early (harnessd status | head) ends the command quietly\nprocess.stdout.on(\"error\", (error: NodeJS.ErrnoException) => {\n if (error.code !== \"EPIPE\") throw error;\n process.exit(0);\n});\n\ntry {\n process.exitCode = await runHarnessd(\n process.argv.slice(2),\n realpathSync(process.argv[1]!),\n );\n} catch (error) {\n console.error(error instanceof Error ? error.message : String(error));\n process.exitCode = 1;\n}\n"],"mappings":";;;;AAKA,QAAQ,MAAM,QAAQ,MAAM,KAAK,OAAO;AACxC,QAAQ,OAAO,QAAQ,MAAM,KAAK,OAAO;AACzC,QAAQ,QAAQ,QAAQ,MAAM,KAAK,OAAO;AAG1C,QAAQ,OAAO,GAAG,UAAU,UAAiC;CAC3D,IAAI,MAAM,SAAS,SAAS,MAAM;CAClC,QAAQ,KAAK,CAAC;AAChB,CAAC;AAED,IAAI;CACF,QAAQ,WAAW,MAAM,YACvB,QAAQ,KAAK,MAAM,CAAC,GACpB,aAAa,QAAQ,KAAK,EAAG,CAC/B;AACF,SAAS,OAAO;CACd,QAAQ,MAAM,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC;CACpE,QAAQ,WAAW;AACrB"}
|
package/dist/channel.d.ts
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
+
import { type CliOptions } from "toolport/cli";
|
|
1
2
|
import { type Harnessd } from "./config.js";
|
|
2
3
|
export declare namespace Channel {
|
|
3
|
-
/** What
|
|
4
|
+
/** What the channel keeps in harnessd's home: where each subscription's events resume, and whether Claude Code hears them. */
|
|
4
5
|
type Status = {
|
|
5
|
-
|
|
6
|
+
/** Each subscription's cursor, by its key. */
|
|
7
|
+
readonly cursors?: Readonly<Record<string, string>>;
|
|
6
8
|
/** When this Claude Code process got its first event. */
|
|
7
9
|
readonly pushedAt?: string;
|
|
8
10
|
/** When one of its events first showed up in the conversation's transcript. */
|
|
9
11
|
readonly heardAt?: string;
|
|
10
12
|
};
|
|
11
13
|
type Options = {
|
|
12
|
-
readonly
|
|
13
|
-
readonly channel: Harnessd.Channel;
|
|
14
|
+
readonly config: Harnessd.Config;
|
|
14
15
|
readonly paths: Harnessd.Paths;
|
|
15
16
|
readonly send: (message: Record<string, unknown>) => void;
|
|
16
17
|
readonly log: (line: string) => void;
|
|
@@ -32,10 +33,14 @@ export declare namespace Channel {
|
|
|
32
33
|
}
|
|
33
34
|
/** Subscription arguments as toolport's `stream` takes them: kebab-case flags, `--x` and `--no-x` for booleans. */
|
|
34
35
|
export declare const streamFlags: (args: Readonly<Record<string, string | number | boolean>>) => string[];
|
|
35
|
-
|
|
36
|
+
/** A server's command, `harnessd tools <server>`, which the channel's subscriptions run too: one sign-in serves both. */
|
|
37
|
+
export declare const serverCli: (paths: Harnessd.Paths, name: string, server: Harnessd.Server, env: NodeJS.ProcessEnv, fetch?: typeof globalThis.fetch) => CliOptions;
|
|
38
|
+
/** A subscription as the log and `harnessd status` name it: `board task.handed --board AUI`. */
|
|
39
|
+
export declare const subscriptionLabel: (subscription: Harnessd.Subscription) => string;
|
|
36
40
|
export declare const readStatus: (file: string) => Channel.Status;
|
|
37
41
|
/** One event as Claude Code shows it: its `text`, else its data as JSON, with its scalar fields as tag attributes and its delivery id. */
|
|
38
42
|
export declare const channelMessage: (line: {
|
|
43
|
+
server: string;
|
|
39
44
|
name: string;
|
|
40
45
|
data: unknown;
|
|
41
46
|
gap?: boolean;
|
|
@@ -45,12 +50,12 @@ export declare const channelMessage: (line: {
|
|
|
45
50
|
meta: Record<string, string>;
|
|
46
51
|
};
|
|
47
52
|
/**
|
|
48
|
-
* `harnessd channel
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
53
|
+
* `harnessd channel`: the stdio MCP server Claude Code runs for harnessd's one channel. It follows each subscription
|
|
54
|
+
* of the config (one `events/stream` each) and hands every event to Claude Code as a channel message. Where a
|
|
55
|
+
* subscription's events resume is saved only once Claude Code is seen to hear them: an event it dropped (a channel it
|
|
56
|
+
* didn't let in) comes again at the next start. The agent answers with the servers' commands, not here.
|
|
52
57
|
*/
|
|
53
58
|
export declare const channelServer: (options: Channel.Options) => Channel.Server;
|
|
54
|
-
/** Serves
|
|
59
|
+
/** Serves the channel on stdin and stdout until Claude Code closes stdin. */
|
|
55
60
|
export declare const serveChannel: (options: Omit<Channel.Options, "send">) => Promise<void>;
|
|
56
61
|
//# sourceMappingURL=channel.d.ts.map
|
package/dist/channel.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"channel.d.ts","sourceRoot":"","sources":["../src/channel.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"channel.d.ts","sourceRoot":"","sources":["../src/channel.ts"],"names":[],"mappings":"AAaA,OAAO,EAAU,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AAEvD,OAAO,EAA8B,KAAK,QAAQ,EAAE,oBAAiB;AAErE,yBAAiB,OAAO,CAAC;IACvB,8HAA8H;IAC9H,KAAY,MAAM,GAAG;QACnB,8CAA8C;QAC9C,QAAQ,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;QACpD,yDAAyD;QACzD,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;QAC3B,+EAA+E;QAC/E,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;KAC3B,CAAC;IAEF,KAAY,OAAO,GAAG;QACpB,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC;QACjC,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC;QAC/B,QAAQ,CAAC,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC;QAC1D,QAAQ,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;QACrC,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;QACjC,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;QAC9B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;QAC1B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;KAC3B,CAAC;IAEF,KAAY,MAAM,GAAG;QACnB,QAAQ,CAAC,MAAM,EAAE,CACf,OAAO,EAAE,OAAO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