@harness-sdk/harnessd 0.0.0 → 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/LICENSE +21 -0
- package/README.md +64 -2
- 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.d.ts +3 -0
- package/dist/bin.d.ts.map +1 -0
- package/dist/bin.js +19 -0
- package/dist/bin.js.map +1 -0
- package/dist/channel.d.ts +56 -0
- package/dist/channel.d.ts.map +1 -0
- package/dist/channel.js +356 -0
- package/dist/channel.js.map +1 -0
- package/dist/claude.d.ts +41 -0
- package/dist/claude.d.ts.map +1 -0
- package/dist/claude.js +152 -0
- package/dist/claude.js.map +1 -0
- package/dist/cli.d.ts +13 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +413 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.d.ts +56 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +161 -0
- package/dist/config.js.map +1 -0
- package/dist/daemon.d.ts +37 -0
- package/dist/daemon.d.ts.map +1 -0
- package/dist/daemon.js +300 -0
- package/dist/daemon.js.map +1 -0
- package/dist/launchd.d.ts +18 -0
- package/dist/launchd.d.ts.map +1 -0
- package/dist/launchd.js +91 -0
- package/dist/launchd.js.map +1 -0
- package/dist/log.d.ts +3 -0
- package/dist/log.d.ts.map +1 -0
- package/dist/log.js +17 -0
- package/dist/log.js.map +1 -0
- 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/terminal.d.ts +11 -0
- package/dist/terminal.d.ts.map +1 -0
- package/dist/terminal.js +36 -0
- package/dist/terminal.js.map +1 -0
- package/dist/watchdog.d.ts +83 -0
- package/dist/watchdog.d.ts.map +1 -0
- package/dist/watchdog.js +236 -0
- package/dist/watchdog.js.map +1 -0
- package/package.json +55 -6
- package/src/accounts.ts +242 -0
- package/src/bin.ts +24 -0
- package/src/channel.ts +461 -0
- package/src/claude.ts +249 -0
- package/src/cli.ts +633 -0
- package/src/config.ts +281 -0
- package/src/daemon.ts +379 -0
- package/src/launchd.ts +131 -0
- package/src/log.ts +17 -0
- 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/terminal.ts +33 -0
- package/src/watchdog.ts +318 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 AgentbaseAI Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,65 @@
|
|
|
1
|
-
#
|
|
1
|
+
# harnessd
|
|
2
2
|
|
|
3
|
-
|
|
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
|
+
|
|
5
|
+
- It starts at login and after any crash, and picks up the same conversation.
|
|
6
|
+
- Each agentic app you connect is a channel. Its events reach the agent as they happen, and its tools let the agent answer.
|
|
7
|
+
- Its terminal is there whenever you want it, on the Mac or over SSH.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm install -g @harness-sdk/harnessd
|
|
13
|
+
harnessd service install
|
|
14
|
+
harnessd attach
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
`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
|
+
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
|
+
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.
|
|
22
|
+
|
|
23
|
+
## Connect a channel
|
|
24
|
+
|
|
25
|
+
A channel is an MCP server that serves events, such as a [Statewire](https://www.npmjs.com/package/statewire) host. Name it in `~/.config/harnessd/config.json`:
|
|
26
|
+
|
|
27
|
+
```json
|
|
28
|
+
{
|
|
29
|
+
"folder": "~/agent",
|
|
30
|
+
"channels": {
|
|
31
|
+
"board": {
|
|
32
|
+
"url": "https://board.example.com/api/board/mcp",
|
|
33
|
+
"headers": { "Authorization": "Bearer ${BOARD_TOKEN}" }
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Each event reaches the conversation as `<channel source="plugin:harnessd:board" event="…">…</channel>`, and the server's tools sit beside it. If the agent restarts, the events it missed come when it's back.
|
|
40
|
+
|
|
41
|
+
harnessd loads its channels with Claude Code's flag for local channels and answers its start-up warning. `harnessd status` shows whether each channel's events arrive, and says so when managed settings turn channels off.
|
|
42
|
+
|
|
43
|
+
## The config file
|
|
44
|
+
|
|
45
|
+
| Key | What it does |
|
|
46
|
+
| --- | --- |
|
|
47
|
+
| `folder` | Where Claude Code runs. |
|
|
48
|
+
| `args` | More arguments for `claude`, such as `["--model", "opus"]` or `["--remote-control"]`. |
|
|
49
|
+
| `env` | More environment for `claude`. |
|
|
50
|
+
| `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
|
+
| `channels` | MCP servers by name: a `url` (https, or http on this Mac), `headers` that read `${VAR}` from the environment, and `arguments` for event types that ask for them. |
|
|
52
|
+
| `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. |
|
|
53
|
+
|
|
54
|
+
A change takes effect at the next start: `harnessd stop`, then `harnessd start`.
|
|
55
|
+
|
|
56
|
+
## Commands
|
|
57
|
+
|
|
58
|
+
| Command | What it does |
|
|
59
|
+
| --- | --- |
|
|
60
|
+
| `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. |
|
|
61
|
+
| `harnessd service uninstall` | Stop harnessd and remove its service (with `sudo` for a boot service). Your settings and conversation stay. |
|
|
62
|
+
| `harnessd status` | What runs, which conversation, whether events arrive, and the log's last lines and path. `--json` for scripts. |
|
|
63
|
+
| `harnessd attach` | Claude Code's terminal. `/clear` there starts a new conversation, and restarts resume that one. |
|
|
64
|
+
| `harnessd stop`, `harnessd start` | Stop Claude Code until you start it again. harnessd itself stays up and answers `status`. |
|
|
65
|
+
| `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,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAA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.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,OAAO,MAAM;CAAW;CAC5D,IACE,EAAE,UAAU,gBACZ,EA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usr/bin/env node
|
|
2
|
+
import { runHarnessd } from "./cli.js";
|
|
3
|
+
import { realpathSync } from "node:fs";
|
|
4
|
+
// src/bin.ts
|
|
5
|
+
console.log = console.error.bind(console);
|
|
6
|
+
console.info = console.error.bind(console);
|
|
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
|
+
});
|
|
12
|
+
try {
|
|
13
|
+
process.exitCode = await runHarnessd(process.argv.slice(2), realpathSync(process.argv[1]));
|
|
14
|
+
} catch (error) {
|
|
15
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
16
|
+
process.exitCode = 1;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=bin.js.map
|
package/dist/bin.js.map
ADDED
|
@@ -0,0 +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\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"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { type Harnessd } from "./config.js";
|
|
2
|
+
export declare namespace Channel {
|
|
3
|
+
/** What a channel keeps in harnessd's home: where its events resume, and whether Claude Code hears them. */
|
|
4
|
+
type Status = {
|
|
5
|
+
readonly cursor?: string;
|
|
6
|
+
/** When this Claude Code process got its first event. */
|
|
7
|
+
readonly pushedAt?: string;
|
|
8
|
+
/** When one of its events first showed up in the conversation's transcript. */
|
|
9
|
+
readonly heardAt?: string;
|
|
10
|
+
};
|
|
11
|
+
type Options = {
|
|
12
|
+
readonly name: string;
|
|
13
|
+
readonly channel: Harnessd.Channel;
|
|
14
|
+
readonly paths: Harnessd.Paths;
|
|
15
|
+
readonly send: (message: Record<string, unknown>) => void;
|
|
16
|
+
readonly log: (line: string) => void;
|
|
17
|
+
readonly env?: NodeJS.ProcessEnv;
|
|
18
|
+
readonly fetch?: typeof fetch;
|
|
19
|
+
readonly startMs?: number;
|
|
20
|
+
readonly checkMs?: number;
|
|
21
|
+
};
|
|
22
|
+
type Server = {
|
|
23
|
+
readonly handle: (request: Request) => Promise<Record<string, unknown> | undefined>;
|
|
24
|
+
readonly stop: () => Promise<void>;
|
|
25
|
+
};
|
|
26
|
+
type Request = {
|
|
27
|
+
jsonrpc: "2.0";
|
|
28
|
+
id?: string | number;
|
|
29
|
+
method: string;
|
|
30
|
+
params?: Record<string, unknown>;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/** Subscription arguments as toolport's `stream` takes them: kebab-case flags, `--x` and `--no-x` for booleans. */
|
|
34
|
+
export declare const streamFlags: (args: Readonly<Record<string, string | number | boolean>>) => string[];
|
|
35
|
+
export declare const statusFile: (paths: Harnessd.Paths, name: string) => string;
|
|
36
|
+
export declare const readStatus: (file: string) => Channel.Status;
|
|
37
|
+
/** 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
|
+
export declare const channelMessage: (line: {
|
|
39
|
+
name: string;
|
|
40
|
+
data: unknown;
|
|
41
|
+
gap?: boolean;
|
|
42
|
+
delivery: string;
|
|
43
|
+
}) => {
|
|
44
|
+
content: string;
|
|
45
|
+
meta: Record<string, string>;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* `harnessd channel <name>`: the stdio MCP server Claude Code runs for one channel. It follows the MCP server's push
|
|
49
|
+
* events (`events/stream`) and hands each to Claude Code as a channel message, and it serves that server's tools, so
|
|
50
|
+
* the agent answers there. Where the events resume is saved only once Claude Code is seen to hear them: an event it
|
|
51
|
+
* dropped (a channel it didn't let in) comes again at the next start.
|
|
52
|
+
*/
|
|
53
|
+
export declare const channelServer: (options: Channel.Options) => Channel.Server;
|
|
54
|
+
/** Serves one channel on stdin and stdout until Claude Code closes stdin. */
|
|
55
|
+
export declare const serveChannel: (options: Omit<Channel.Options, "send">) => Promise<void>;
|
|
56
|
+
//# sourceMappingURL=channel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"channel.d.ts","sourceRoot":"","sources":["../src/channel.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAa,KAAK,QAAQ,EAAE,oBAAiB;AAEpD,yBAAiB,OAAO,CAAC;IACvB,4GAA4G;IAC5G,KAAY,MAAM,GAAG;QACnB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QACzB,yDAAyD;QACzD,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;QAC3B,+EAA+E;QAC/E,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,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