@agentshouse/kit 0.2.1-ca0e1517cce79 → 0.2.1-ca1f38641026d
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 +6 -6
- package/dist/acp.js +57 -6
- package/dist/agents.js +12 -21
- package/dist/authority-main.js +2 -2
- package/dist/building.js +46 -0
- package/dist/calls.js +11 -3
- package/dist/clis-main.js +2 -2
- package/dist/clis.js +37 -13
- package/dist/connection.js +19 -29
- package/dist/conversations.js +140 -40
- package/dist/end.js +8 -2
- package/dist/events.js +29 -8
- package/dist/git.js +2 -2
- package/dist/house-cli.js +3 -4
- package/dist/instructions.js +4 -4
- package/dist/kit-cli.js +2 -2
- package/dist/login.js +3 -1
- package/dist/mcp.js +2 -0
- package/dist/relay.js +21 -0
- package/dist/resident.js +17 -12
- package/dist/scripts.js +255 -0
- package/dist/sign-in.js +3 -2
- package/dist/silence.js +28 -0
- package/dist/skills.js +38 -12
- package/dist/transcription.js +32 -23
- package/dist/update.js +51 -8
- package/package.json +11 -12
- package/dist/bootstrap.json +0 -24
- package/dist/web-wizard.js +0 -100
package/README.md
CHANGED
|
@@ -13,17 +13,17 @@ pass `--workspace <path>`.
|
|
|
13
13
|
|
|
14
14
|
Add `--container` to run Kit in one Docker container instead, with your
|
|
15
15
|
workspace mounted at `/agents/house`; your Agents then reach only that
|
|
16
|
-
workspace. On Windows
|
|
16
|
+
workspace. On Windows the container is the one choice. Append a `kit` or `house` command to the container's options to run it in that container.
|
|
17
17
|
Running the command for the other choice on a connected computer asks you to
|
|
18
18
|
confirm, then replaces its Environment, whose Agents end, with a new one. Running it with a different `HOUSE_KIT_HOME`
|
|
19
19
|
from the running Kit process asks you to confirm before it replaces that process, and leaves the earlier Kit home as it was.
|
|
20
20
|
|
|
21
|
-
On your own Linux server, run the Linux command with `--linux` to
|
|
22
|
-
|
|
23
|
-
`
|
|
21
|
+
On your own Linux server, run the Linux command with `--linux` to install Kit natively, with its workspace at `/agents/house` and a missing `ca-certificates`, `curl` or `git` installed through apt; `kit` and `house` are then on the server's `PATH`.
|
|
22
|
+
|
|
23
|
+
Kit is built for macOS 27 on Apple silicon, Ubuntu 26.04 LTS on amd64 and Windows 11 on amd64. On another release, distribution or architecture the command prints one warning line, such as `Warning: macOS 26.7.1 is outdated; update to macOS 27.`, and installs anyway. It refuses only an architecture other than amd64 and arm64, and a native install on a Linux without glibc, where `--container` still runs Kit. On a Linux without systemd it installs and connects Kit but starts nothing: run the `kit resident` command it prints under your own service manager, restarting it whenever it ends with a failure. `--container` installs Docker Engine on Ubuntu and Debian; another Linux needs a working Docker Engine first.
|
|
24
24
|
|
|
25
25
|
Kit runs the agent CLIs your login shell finds and installs a missing one
|
|
26
|
-
through that CLI's own installer. Running the command again offers to update
|
|
26
|
+
through that CLI's own installer. A CLI older than the oldest release Kit is built for still runs, though its conversations may fail: Kit tells House its version, that oldest release and the CLI's own update command, such as `claude update`. Running the command again offers to update
|
|
27
27
|
each CLI older than Kit needs; add `--update-clis` to update every one to
|
|
28
28
|
its latest release without asking. Kit also gives every Agent on the
|
|
29
29
|
Environment the agent skills of `@agentshouse/skills`, at the version each Kit
|
|
@@ -53,7 +53,7 @@ the container. An Agent runs both, without `--owner`. `house upload` and `house
|
|
|
53
53
|
|
|
54
54
|
Kit turns each audio file your message to an Agent links into text on this computer before the Agent reads it, and keeps a message whose audio it cannot turn into text from starting. While transcription is on, the speech engine and model use about 425 MB beside the Environment's credential; turning it off deletes them.
|
|
55
55
|
|
|
56
|
-
When you press Run on a Web Wizard's page, Kit runs its script with `bash` in a terminal on this computer, as you, in the home and directory it runs agent CLIs from, with your login shell's `PATH`; the page shows that terminal and takes your typing, and closing the page, or Kit losing its connection to House, ends the script and its child processes. Kit keeps nothing the script prints or you type.
|
|
56
|
+
When you press Run on a Web Wizard's page, Kit runs its script with `bash` in a terminal on this computer, as you, in the home and directory it runs agent CLIs from, with your login shell's `PATH`; the page shows that terminal and takes your typing, and closing the page, or Kit losing its connection to House, ends the script and its child processes. Kit keeps nothing the script prints or you type. A script you keep as a function from a Web Wizard runs as you, from the same home, directory and `PATH`, when a Trigger of your Private Room or your agent runs it, with no terminal and nothing on its standard input, and when you press Run now on its page, in a terminal you can type into. Kit writes the run's input as JSON to a file only you can read, whose path is in `HOUSE_INPUT`, and deletes it when the run ends; it ends the script and its child processes at the run's time limit or when it loses its connection to House, and sends House the end of what the script printed, up to the run's output limit, without any line that holds a line you typed.
|
|
57
57
|
|
|
58
58
|
## License
|
|
59
59
|
|
package/dist/acp.js
CHANGED
|
@@ -1,31 +1,74 @@
|
|
|
1
|
-
import { ndJsonStream, PROTOCOL_VERSION, } from '@agentclientprotocol/sdk';
|
|
1
|
+
import { ndJsonStream, PROTOCOL_VERSION, RequestError, } from '@agentclientprotocol/sdk';
|
|
2
2
|
import { spawn } from 'node:child_process';
|
|
3
3
|
import { Readable, Writable } from 'node:stream';
|
|
4
|
-
import { CLIS, KIT_RELEASE, adapterCommand
|
|
4
|
+
import { CLIS, KIT_RELEASE, adapterCommand } from './clis.js';
|
|
5
|
+
import { childEnvironment } from './relay.js';
|
|
5
6
|
import { killTree } from './scope.js';
|
|
7
|
+
import { Silence } from './silence.js';
|
|
6
8
|
const RETIRED = 'the CLI was retired';
|
|
9
|
+
const SIGNED_OUT = RequestError.authRequired().code;
|
|
10
|
+
export function signedOut(error) {
|
|
11
|
+
return typeof error === 'object' && error !== null && error.code === SIGNED_OUT;
|
|
12
|
+
}
|
|
13
|
+
// Claude Code ends a shell command or a model request after ten minutes, so a CLI that owes the Kit an answer and sends nothing for half an hour has hung.
|
|
14
|
+
export const CLI_SILENCE_MS = 30 * 60_000;
|
|
15
|
+
const SILENT = `the CLI sent nothing for ${CLI_SILENCE_MS / 60_000} minutes`;
|
|
7
16
|
export async function startAdapter(kind, cli, cwd, app, events = () => undefined, added = {}, signal, scope = null) {
|
|
8
17
|
const adapter = CLIS[kind].adapter;
|
|
9
18
|
const started = [adapter === null ? cli : adapterCommand(kind), CLIS[kind].args];
|
|
10
19
|
const [command, args] = scope?.command(...started) ?? started;
|
|
11
20
|
const child = spawn(command, args, {
|
|
12
21
|
cwd,
|
|
13
|
-
env: { ...
|
|
22
|
+
env: { ...childEnvironment(), ...(adapter === null ? {} : { ...adapter.env, [adapter.executable]: cli }), ...added },
|
|
14
23
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
15
24
|
detached: true,
|
|
16
25
|
});
|
|
17
26
|
let owned = true;
|
|
18
27
|
let retired = false;
|
|
28
|
+
let silent = false;
|
|
29
|
+
let over = false;
|
|
30
|
+
let open = false;
|
|
19
31
|
let stderr = '';
|
|
32
|
+
const owed = new Set();
|
|
33
|
+
const asked = new Set();
|
|
34
|
+
const silence = new Silence(CLI_SILENCE_MS, () => {
|
|
35
|
+
silent = true;
|
|
36
|
+
connection.close(new Error(SILENT));
|
|
37
|
+
if (child.pid !== undefined)
|
|
38
|
+
killTree(child);
|
|
39
|
+
});
|
|
40
|
+
const watch = () => (!over && (owed.size > 0 || open) && asked.size === 0 ? silence.heard() : silence.stop());
|
|
20
41
|
child.stderr.on('data', (chunk) => {
|
|
21
42
|
stderr = (stderr + chunk.toString('utf8')).slice(-4000);
|
|
22
43
|
});
|
|
23
44
|
const stream = ndJsonStream(Writable.toWeb(child.stdin), Readable.toWeb(child.stdout));
|
|
45
|
+
const output = stream.writable.getWriter();
|
|
24
46
|
const connection = app.connect({
|
|
25
|
-
writable:
|
|
47
|
+
writable: new WritableStream({
|
|
48
|
+
write(message) {
|
|
49
|
+
const sent = message;
|
|
50
|
+
if (sent.id !== undefined) {
|
|
51
|
+
if (sent.method === undefined)
|
|
52
|
+
asked.delete(sent.id);
|
|
53
|
+
else
|
|
54
|
+
owed.add(sent.id);
|
|
55
|
+
watch();
|
|
56
|
+
}
|
|
57
|
+
return output.write(message);
|
|
58
|
+
},
|
|
59
|
+
close: () => output.close(),
|
|
60
|
+
abort: (reason) => output.abort(reason),
|
|
61
|
+
}),
|
|
26
62
|
readable: stream.readable.pipeThrough(new TransformStream({
|
|
27
63
|
transform(message, controller) {
|
|
28
64
|
const read = message;
|
|
65
|
+
if (read.id !== undefined) {
|
|
66
|
+
if (read.method === undefined)
|
|
67
|
+
owed.delete(read.id);
|
|
68
|
+
else
|
|
69
|
+
asked.add(read.id);
|
|
70
|
+
}
|
|
71
|
+
watch();
|
|
29
72
|
if (owned)
|
|
30
73
|
events(read);
|
|
31
74
|
if (read.id !== undefined || (read.method !== 'session/update' && !read.method.startsWith('_'))) {
|
|
@@ -37,6 +80,8 @@ export async function startAdapter(kind, cli, cwd, app, events = () => undefined
|
|
|
37
80
|
const { promise: lost, resolve: lose } = Promise.withResolvers();
|
|
38
81
|
const exited = new Promise((resolve) => {
|
|
39
82
|
const end = (cause) => {
|
|
83
|
+
over = true;
|
|
84
|
+
silence.stop();
|
|
40
85
|
if (owned)
|
|
41
86
|
lose(cause);
|
|
42
87
|
owned = false;
|
|
@@ -46,11 +91,13 @@ export async function startAdapter(kind, cli, cwd, app, events = () => undefined
|
|
|
46
91
|
child.on('error', (error) => end(`the CLI did not start: ${error.message}`));
|
|
47
92
|
child.on('exit', (code, signal) => {
|
|
48
93
|
const last = stderr.trim().split('\n').at(-1);
|
|
49
|
-
end(`the CLI exited with ${code ?? signal}${last ? `: ${last}` : ''}`);
|
|
94
|
+
end(silent ? SILENT : `the CLI exited with ${code ?? signal}${last ? `: ${last}` : ''}`);
|
|
50
95
|
});
|
|
51
96
|
});
|
|
52
97
|
const retire = () => {
|
|
53
98
|
owned = false;
|
|
99
|
+
over = true;
|
|
100
|
+
silence.stop();
|
|
54
101
|
if (retired)
|
|
55
102
|
return;
|
|
56
103
|
retired = true;
|
|
@@ -74,7 +121,11 @@ export async function startAdapter(kind, cli, cwd, app, events = () => undefined
|
|
|
74
121
|
clientInfo: { name: '@agentshouse/kit', version: KIT_RELEASE },
|
|
75
122
|
});
|
|
76
123
|
scope?.entered(child.pid);
|
|
77
|
-
|
|
124
|
+
const turn = (opened) => {
|
|
125
|
+
open = opened;
|
|
126
|
+
watch();
|
|
127
|
+
};
|
|
128
|
+
return { connection, initialized, exited, lost, silent: () => silent, turn, retire };
|
|
78
129
|
}
|
|
79
130
|
catch (error) {
|
|
80
131
|
retire();
|
package/dist/agents.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { client } from '@agentclientprotocol/sdk';
|
|
2
2
|
import { readFile, realpath } from 'node:fs/promises';
|
|
3
3
|
import { setTimeout as delay } from 'node:timers/promises';
|
|
4
|
-
import { startAdapter } from './acp.js';
|
|
4
|
+
import { signedOut, startAdapter } from './acp.js';
|
|
5
5
|
import { CLIS, KIT_RELEASE, below, installAdapter, installCli, locate, run, versionOf } from './clis.js';
|
|
6
6
|
import { agentBase, kitHome } from './home.js';
|
|
7
7
|
import { updatesItself } from './placement.js';
|
|
@@ -9,6 +9,8 @@ import { holdTranscription, transcriptionReport } from './transcription.js';
|
|
|
9
9
|
import { KIT_WIRE } from './wire.js';
|
|
10
10
|
// Two quiet seconds let a fresh conversation start before background model discovery competes for its CPU.
|
|
11
11
|
const MODEL_PROBE_QUIET_MS = 2_000;
|
|
12
|
+
// A sign-in's model read that has not answered in ten seconds leaves its sign-in to the status check, so a hung CLI never holds the sign-in's result.
|
|
13
|
+
const SIGNED_IN_READ_MS = 10_000;
|
|
12
14
|
const SIGNED_OUT = { signed_in: false, models: [], modes: [] };
|
|
13
15
|
const INSTALLING = { release: null, failure: null, installing: true, ...SIGNED_OUT };
|
|
14
16
|
function select(options, category) {
|
|
@@ -69,13 +71,6 @@ async function models(kind, adapter, known) {
|
|
|
69
71
|
}
|
|
70
72
|
return { models: offered, modes };
|
|
71
73
|
}
|
|
72
|
-
async function signedIn(kind, cli, known, signal) {
|
|
73
|
-
const probe = CLIS[kind].signedIn;
|
|
74
|
-
// A sign-in check that has not answered in half a minute counts as signed out rather than stalling the report.
|
|
75
|
-
if ('command' in probe)
|
|
76
|
-
return (await run(cli, probe.command, 30_000, false, signal)).status === 0;
|
|
77
|
-
return (await offer(kind, cli, known, signal)).signed_in;
|
|
78
|
-
}
|
|
79
74
|
function ended(signal) {
|
|
80
75
|
return new Promise((_, reject) => {
|
|
81
76
|
if (signal.aborted)
|
|
@@ -102,6 +97,8 @@ async function offer(kind, cli, known, signal) {
|
|
|
102
97
|
catch (error) {
|
|
103
98
|
if (!signal?.aborted)
|
|
104
99
|
process.stderr.write(`kit: ${kind} did not offer its models: ${causeOf(error)}\n`);
|
|
100
|
+
if (signedOut(error))
|
|
101
|
+
return SIGNED_OUT;
|
|
105
102
|
return {
|
|
106
103
|
signed_in: adapter === undefined && 'initializeMeta' in probe ? known.signed_in : true,
|
|
107
104
|
models: known.models,
|
|
@@ -113,10 +110,11 @@ async function offer(kind, cli, known, signal) {
|
|
|
113
110
|
}
|
|
114
111
|
}
|
|
115
112
|
function reported(kind, reading) {
|
|
113
|
+
const { minimum, update } = CLIS[kind];
|
|
116
114
|
return {
|
|
117
115
|
kind,
|
|
118
116
|
release: reading.release,
|
|
119
|
-
...(reading.
|
|
117
|
+
...(reading.release !== null && below(reading.release, minimum) ? { minimum, update } : {}),
|
|
120
118
|
failure: reading.failure,
|
|
121
119
|
...(reading.installing === undefined ? {} : { installing: reading.installing }),
|
|
122
120
|
signed_in: reading.signed_in,
|
|
@@ -126,10 +124,6 @@ function reported(kind, reading) {
|
|
|
126
124
|
};
|
|
127
125
|
}
|
|
128
126
|
const NOT_READY = "the Agent's CLI is not ready on this computer";
|
|
129
|
-
function tooOld(kind, release) {
|
|
130
|
-
const cli = CLIS[kind];
|
|
131
|
-
return `${cli.bin} ${release} is older than ${cli.minimum}, the oldest this Kit runs`;
|
|
132
|
-
}
|
|
133
127
|
async function sshHostKey() {
|
|
134
128
|
// Listing a local host key takes a moment, so ten seconds only bounds a stuck ssh-keygen.
|
|
135
129
|
const listed = await run('ssh-keygen', ['-l', '-E', 'sha256', '-f', '/etc/ssh/ssh_host_ed25519_key.pub'], 10_000);
|
|
@@ -215,12 +209,12 @@ export class Agents {
|
|
|
215
209
|
const resolved = await this.resolve(kind);
|
|
216
210
|
if (!('cli' in resolved)) {
|
|
217
211
|
this.update(kind, resolved);
|
|
218
|
-
throw new Error(
|
|
212
|
+
throw new Error(NOT_READY);
|
|
219
213
|
}
|
|
220
214
|
const { cli, release } = resolved;
|
|
221
215
|
const known = this.readings.get(kind);
|
|
222
|
-
const kept = known?.release === null
|
|
223
|
-
if (known?.release !== release ||
|
|
216
|
+
const kept = known?.release === null ? SIGNED_OUT : (known ?? SIGNED_OUT);
|
|
217
|
+
if (known?.release !== release || this.installs.has(kind)) {
|
|
224
218
|
this.update(kind, { release, failure: null, signed_in: kept.signed_in, models: kept.models, modes: kept.modes });
|
|
225
219
|
}
|
|
226
220
|
const read = this.nextRead(kind);
|
|
@@ -246,7 +240,7 @@ export class Agents {
|
|
|
246
240
|
const known = this.readings.get(kind) ?? SIGNED_OUT;
|
|
247
241
|
const owner = {};
|
|
248
242
|
try {
|
|
249
|
-
await this.examine(kind, known,
|
|
243
|
+
await this.examine(kind, known, (kind, cli) => offer(kind, cli, known, AbortSignal.any([signal, AbortSignal.timeout(SIGNED_IN_READ_MS)])), signal, owner);
|
|
250
244
|
}
|
|
251
245
|
finally {
|
|
252
246
|
this.settle(kind, owner);
|
|
@@ -318,9 +312,6 @@ export class Agents {
|
|
|
318
312
|
const release = await versionOf(cli, signal);
|
|
319
313
|
if (release === null)
|
|
320
314
|
return { release: null, failure: `${cli} --version names no version`, ...SIGNED_OUT };
|
|
321
|
-
const minimum = CLIS[kind].minimum;
|
|
322
|
-
if (below(release, minimum))
|
|
323
|
-
return { release, minimum, failure: null, ...SIGNED_OUT };
|
|
324
315
|
return { cli, release };
|
|
325
316
|
}
|
|
326
317
|
async examine(kind, known, read, signal, owner) {
|
|
@@ -339,7 +330,7 @@ export class Agents {
|
|
|
339
330
|
}
|
|
340
331
|
async load(kind) {
|
|
341
332
|
const known = this.readings.get(kind);
|
|
342
|
-
if (known !== undefined && known.failure === null
|
|
333
|
+
if (known !== undefined && known.failure === null)
|
|
343
334
|
return;
|
|
344
335
|
await this.examine(kind, SIGNED_OUT, (kind, cli, known) => this.quietOffer(kind, cli, known));
|
|
345
336
|
await this.report();
|
package/dist/authority-main.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { setGlobalProxyFromEnv } from 'node:http';
|
|
2
1
|
import { HouseRefusal, post } from './api.js';
|
|
3
2
|
import { readEnrolment } from './home.js';
|
|
3
|
+
import { proxyUnlessRelayed } from './relay.js';
|
|
4
4
|
function unanswered(error) {
|
|
5
5
|
return error instanceof HouseRefusal ? error.status >= 500 : error instanceof TypeError && error.message === 'fetch failed';
|
|
6
6
|
}
|
|
7
|
-
|
|
7
|
+
proxyUnlessRelayed();
|
|
8
8
|
try {
|
|
9
9
|
const { house, credential } = (await readEnrolment());
|
|
10
10
|
try {
|
package/dist/building.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { createWriteStream } from 'node:fs';
|
|
3
|
+
import { rm } from 'node:fs/promises';
|
|
4
|
+
import { Transform } from 'node:stream';
|
|
5
|
+
import { pipeline } from 'node:stream/promises';
|
|
6
|
+
import { readEnrolment } from './home.js';
|
|
7
|
+
import { relayed } from './relay.js';
|
|
8
|
+
const MANIFEST = 'bootstrap.json';
|
|
9
|
+
async function served(name, signal) {
|
|
10
|
+
const enrolment = await readEnrolment();
|
|
11
|
+
if (enrolment === null)
|
|
12
|
+
throw new Error('this Kit is connected to no House');
|
|
13
|
+
const answer = await fetch(relayed(new URL(`/kit-installer/${encodeURIComponent(name)}`, enrolment.house)), { signal });
|
|
14
|
+
if (answer.status === 200 && answer.body !== null)
|
|
15
|
+
return answer;
|
|
16
|
+
await answer.body?.cancel();
|
|
17
|
+
throw new Error(`House answered ${answer.status} for ${name}`);
|
|
18
|
+
}
|
|
19
|
+
export async function servedDigest(name, signal) {
|
|
20
|
+
const manifest = (await (await served(MANIFEST, signal)).json());
|
|
21
|
+
const sha256 = manifest.files?.[name]?.sha256;
|
|
22
|
+
return typeof sha256 === 'string' ? sha256 : null;
|
|
23
|
+
}
|
|
24
|
+
export async function downloadServed(name, sha256, destination, signal, most = Infinity) {
|
|
25
|
+
const answer = await served(name, signal);
|
|
26
|
+
const digest = createHash('sha256');
|
|
27
|
+
let bytes = 0;
|
|
28
|
+
const hashed = new Transform({
|
|
29
|
+
transform(chunk, _encoding, done) {
|
|
30
|
+
bytes += chunk.length;
|
|
31
|
+
if (bytes > most)
|
|
32
|
+
return done(new Error(`${name} is larger than its pinned ${most} bytes`));
|
|
33
|
+
digest.update(chunk);
|
|
34
|
+
done(null, chunk);
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
try {
|
|
38
|
+
await pipeline(answer.body, hashed, createWriteStream(destination), { signal });
|
|
39
|
+
if (digest.digest('hex') !== sha256)
|
|
40
|
+
throw new Error(`${name} does not match its sha256`);
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
await rm(destination, { force: true });
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
}
|
package/dist/calls.js
CHANGED
|
@@ -11,6 +11,7 @@ export class Calls {
|
|
|
11
11
|
path = join(kitHome(), 'call-results.json');
|
|
12
12
|
results;
|
|
13
13
|
returned = new Set();
|
|
14
|
+
released = new Set();
|
|
14
15
|
open = 0;
|
|
15
16
|
constructor(house, changed) {
|
|
16
17
|
this.house = house;
|
|
@@ -27,6 +28,8 @@ export class Calls {
|
|
|
27
28
|
return this.open === 0;
|
|
28
29
|
}
|
|
29
30
|
carry(callId, work) {
|
|
31
|
+
if (this.released.has(callId))
|
|
32
|
+
return Promise.resolve();
|
|
30
33
|
const known = this.carried.get(callId);
|
|
31
34
|
const result = this.results.get(callId);
|
|
32
35
|
const carried = known ?? (result === undefined ? work() : Promise.resolve({ result }));
|
|
@@ -37,7 +40,7 @@ export class Calls {
|
|
|
37
40
|
this.open++;
|
|
38
41
|
this.changed();
|
|
39
42
|
return carried
|
|
40
|
-
.then(async ({ result, returned }) => {
|
|
43
|
+
.then(async ({ result, returned, release }) => {
|
|
41
44
|
try {
|
|
42
45
|
await this.house.deliver(`/kit/inputs/${callId}/ack`, result);
|
|
43
46
|
}
|
|
@@ -46,8 +49,13 @@ export class Calls {
|
|
|
46
49
|
if (this.results.delete(callId))
|
|
47
50
|
this.save();
|
|
48
51
|
}
|
|
49
|
-
if (known
|
|
50
|
-
|
|
52
|
+
if (known !== undefined)
|
|
53
|
+
return;
|
|
54
|
+
if (release) {
|
|
55
|
+
this.carried.delete(callId);
|
|
56
|
+
this.released.add(callId);
|
|
57
|
+
}
|
|
58
|
+
await returned?.();
|
|
51
59
|
})
|
|
52
60
|
.catch(logged)
|
|
53
61
|
.finally(() => {
|
package/dist/clis-main.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { setGlobalProxyFromEnv } from 'node:http';
|
|
2
1
|
import { post } from './api.js';
|
|
3
2
|
import { CLIS, below, locate, versionOf } from './clis.js';
|
|
4
3
|
import { readEnrolment } from './home.js';
|
|
5
|
-
|
|
4
|
+
import { proxyUnlessRelayed } from './relay.js';
|
|
5
|
+
proxyUnlessRelayed();
|
|
6
6
|
try {
|
|
7
7
|
const { house, credential } = (await readEnrolment());
|
|
8
8
|
const { agents } = await post(house, '/kit/agents/desired', {}, credential);
|
package/dist/clis.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
2
|
import { randomUUID } from 'node:crypto';
|
|
3
3
|
import { constants, readFileSync } from 'node:fs';
|
|
4
|
-
import { access, mkdir, readFile, rename, writeFile } from 'node:fs/promises';
|
|
4
|
+
import { access, mkdir, readFile, rename, rm, writeFile } from 'node:fs/promises';
|
|
5
5
|
import { homedir, userInfo } from 'node:os';
|
|
6
6
|
import { delimiter, dirname, isAbsolute, join } from 'node:path';
|
|
7
|
+
import { downloadServed, servedDigest } from './building.js';
|
|
7
8
|
import { kitHome } from './home.js';
|
|
9
|
+
import { childEnvironment } from './relay.js';
|
|
8
10
|
const HOUSE_EXECUTABLES = /^host_executable\(name = "house", paths = (\[.*\])\)$/m;
|
|
9
11
|
function houseRule(houses) {
|
|
10
12
|
return `prefix_rule(pattern = ["house"], decision = "allow")\nhost_executable(name = "house", paths = ${JSON.stringify(houses)})\n`;
|
|
@@ -14,6 +16,7 @@ const RAW_SUBTYPES = [
|
|
|
14
16
|
'task_started',
|
|
15
17
|
'task_updated',
|
|
16
18
|
'task_notification',
|
|
19
|
+
'task_progress',
|
|
17
20
|
'session_state_changed',
|
|
18
21
|
'hook_started',
|
|
19
22
|
'hook_response',
|
|
@@ -69,8 +72,9 @@ function bridgeInClaudeSandbox(bridge) {
|
|
|
69
72
|
export const CLIS = {
|
|
70
73
|
'codex-acp': {
|
|
71
74
|
bin: 'codex',
|
|
72
|
-
minimum: '0.
|
|
75
|
+
minimum: '0.160.1',
|
|
73
76
|
install: 'curl -fsSL https://chatgpt.com/codex/install.sh | sh',
|
|
77
|
+
update: 'codex update',
|
|
74
78
|
adapter: {
|
|
75
79
|
package: '@agentclientprotocol/codex-acp',
|
|
76
80
|
bin: 'codex-acp',
|
|
@@ -92,8 +96,9 @@ export const CLIS = {
|
|
|
92
96
|
},
|
|
93
97
|
'claude-agent-acp': {
|
|
94
98
|
bin: 'claude',
|
|
95
|
-
minimum: '2.1.
|
|
99
|
+
minimum: '2.1.303',
|
|
96
100
|
install: 'curl -fsSL https://claude.ai/install.sh | bash',
|
|
101
|
+
update: 'claude update',
|
|
97
102
|
adapter: {
|
|
98
103
|
package: '@agentclientprotocol/claude-agent-acp',
|
|
99
104
|
bin: 'claude-agent-acp',
|
|
@@ -110,7 +115,7 @@ export const CLIS = {
|
|
|
110
115
|
title,
|
|
111
116
|
settings: { sandbox: { network: bridgeInClaudeSandbox(bridge) } },
|
|
112
117
|
},
|
|
113
|
-
emitRawSDKMessages: RAW_SUBTYPES.map((subtype) => ({ type: 'system', subtype })),
|
|
118
|
+
emitRawSDKMessages: [...RAW_SUBTYPES.map((subtype) => ({ type: 'system', subtype })), { type: 'result' }],
|
|
114
119
|
},
|
|
115
120
|
}),
|
|
116
121
|
unknownSession: (error) => answered(error).code === -32002,
|
|
@@ -124,6 +129,7 @@ export const CLIS = {
|
|
|
124
129
|
bin: 'grok',
|
|
125
130
|
minimum: '1.0.46',
|
|
126
131
|
install: 'curl -fsSL https://x.ai/cli/install.sh | bash',
|
|
132
|
+
update: 'grok update',
|
|
127
133
|
adapter: null,
|
|
128
134
|
args: ['--sandbox', 'off', 'agent', '--always-approve', '--no-leader', 'stdio'],
|
|
129
135
|
fullAccess: null,
|
|
@@ -138,7 +144,6 @@ export const CLIS = {
|
|
|
138
144
|
};
|
|
139
145
|
const KIT_PACKAGE = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
|
|
140
146
|
export const KIT_RELEASE = KIT_PACKAGE.version;
|
|
141
|
-
const PROXY = /^https?_proxy$/i;
|
|
142
147
|
const VERSION = /\d+\.\d+\.\d+(?:-[0-9A-Za-z.]+)?/;
|
|
143
148
|
// An install still running after fifteen minutes is ended and reported as failed, so a hung download cannot hold its CLI's report.
|
|
144
149
|
const INSTALL_MS = 15 * 60_000;
|
|
@@ -160,15 +165,12 @@ async function installedAdapter(kind) {
|
|
|
160
165
|
return null;
|
|
161
166
|
}
|
|
162
167
|
}
|
|
163
|
-
export function withoutProxy() {
|
|
164
|
-
return Object.fromEntries(Object.entries(process.env).filter(([name]) => !PROXY.test(name)));
|
|
165
|
-
}
|
|
166
168
|
export function run(command, args, timeoutMs, detached = false, signal) {
|
|
167
169
|
return new Promise((resolve) => {
|
|
168
170
|
const child = spawn(command, args, {
|
|
169
171
|
stdio: ['ignore', 'pipe', 'pipe'],
|
|
170
172
|
timeout: timeoutMs,
|
|
171
|
-
env:
|
|
173
|
+
env: childEnvironment(),
|
|
172
174
|
detached,
|
|
173
175
|
signal: detached ? undefined : signal,
|
|
174
176
|
});
|
|
@@ -202,15 +204,37 @@ export function run(command, args, timeoutMs, detached = false, signal) {
|
|
|
202
204
|
export function failureOf(ran, program) {
|
|
203
205
|
return ran.output.trim().slice(-CAUSE_CHARACTERS) || `${program} exited with ${ran.status ?? 'a signal'}`;
|
|
204
206
|
}
|
|
207
|
+
export function adapterArchive(kind) {
|
|
208
|
+
return `${kind}-${KIT_PACKAGE.peerDependencies[CLIS[kind].adapter.package]}.tar.gz`;
|
|
209
|
+
}
|
|
205
210
|
export async function installAdapter(kind, signal) {
|
|
206
211
|
const adapter = CLIS[kind].adapter;
|
|
207
212
|
if (adapter === null)
|
|
208
213
|
return null;
|
|
209
|
-
|
|
210
|
-
if ((await installedAdapter(kind)) === release)
|
|
214
|
+
if ((await installedAdapter(kind)) === KIT_PACKAGE.peerDependencies[adapter.package])
|
|
211
215
|
return null;
|
|
212
|
-
const
|
|
213
|
-
|
|
216
|
+
const name = adapterArchive(kind);
|
|
217
|
+
const archive = `${prefix(kind)}.tar.gz`;
|
|
218
|
+
const deadline = AbortSignal.timeout(INSTALL_MS);
|
|
219
|
+
const bounded = signal === undefined ? deadline : AbortSignal.any([signal, deadline]);
|
|
220
|
+
try {
|
|
221
|
+
const sha256 = await servedDigest(name, bounded);
|
|
222
|
+
if (sha256 === null)
|
|
223
|
+
return `House serves no ${name}`;
|
|
224
|
+
await rm(prefix(kind), { recursive: true, force: true });
|
|
225
|
+
await mkdir(prefix(kind), { recursive: true });
|
|
226
|
+
await downloadServed(name, sha256, archive, bounded);
|
|
227
|
+
const ran = await run('tar', ['-xzf', archive, '-C', prefix(kind)], INSTALL_MS, true, signal);
|
|
228
|
+
return ran.status === 0 ? null : failureOf(ran, 'tar');
|
|
229
|
+
}
|
|
230
|
+
catch (error) {
|
|
231
|
+
if (deadline.aborted && signal?.aborted !== true)
|
|
232
|
+
return `${name} did not arrive within ${INSTALL_MS / 1000} seconds`;
|
|
233
|
+
return error instanceof Error ? error.message : String(error);
|
|
234
|
+
}
|
|
235
|
+
finally {
|
|
236
|
+
await rm(archive, { force: true });
|
|
237
|
+
}
|
|
214
238
|
}
|
|
215
239
|
export async function installCli(kind, signal) {
|
|
216
240
|
const ran = await run('bash', ['-o', 'pipefail', '-c', CLIS[kind].install], INSTALL_MS, true, signal);
|
package/dist/connection.js
CHANGED
|
@@ -3,40 +3,13 @@ import { HouseRefusal, retryDelay } from './api.js';
|
|
|
3
3
|
import { end, REPLACED, signInAgain } from './end.js';
|
|
4
4
|
import { readEnrolment } from './home.js';
|
|
5
5
|
import { relayed } from './relay.js';
|
|
6
|
+
import { Silence } from './silence.js';
|
|
6
7
|
import { endUnserved, KIT_WIRE } from './wire.js';
|
|
7
8
|
const PATH = '/kit/stream';
|
|
8
9
|
const SUBPROTOCOL = `house.kit.stream.${KIT_WIRE}`;
|
|
9
10
|
const REFUSAL_HEADER = 'x-house-refusal';
|
|
10
11
|
// House beats each Kit connection every thirty seconds, so two silent beats mean this Kit process cannot hear House.
|
|
11
12
|
export const CONNECTION_SILENCE_MS = 60_000;
|
|
12
|
-
const SYSTEM_CONNECTION_CLOCK = {
|
|
13
|
-
later: (delay, callback) => setTimeout(callback, delay),
|
|
14
|
-
clear: (timer) => clearTimeout(timer),
|
|
15
|
-
};
|
|
16
|
-
export class ConnectionSilence {
|
|
17
|
-
timer = null;
|
|
18
|
-
silent;
|
|
19
|
-
clock;
|
|
20
|
-
interval;
|
|
21
|
-
constructor(silent, clock = SYSTEM_CONNECTION_CLOCK, interval = CONNECTION_SILENCE_MS) {
|
|
22
|
-
this.silent = silent;
|
|
23
|
-
this.clock = clock;
|
|
24
|
-
this.interval = interval;
|
|
25
|
-
}
|
|
26
|
-
heard() {
|
|
27
|
-
this.stop();
|
|
28
|
-
this.timer = this.clock.later(this.interval, () => {
|
|
29
|
-
this.timer = null;
|
|
30
|
-
this.silent();
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
stop() {
|
|
34
|
-
if (this.timer === null)
|
|
35
|
-
return;
|
|
36
|
-
this.clock.clear(this.timer);
|
|
37
|
-
this.timer = null;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
13
|
function connectionUrl(house) {
|
|
41
14
|
const url = new URL(PATH, house);
|
|
42
15
|
url.protocol = url.protocol === 'https:' ? 'wss:' : 'ws:';
|
|
@@ -58,19 +31,26 @@ subscribe('undici:request:headers', (message) => {
|
|
|
58
31
|
});
|
|
59
32
|
export function holdConnection(handlers) {
|
|
60
33
|
let connection = null;
|
|
34
|
+
let socket = null;
|
|
35
|
+
let paused = false;
|
|
61
36
|
let failures = 0;
|
|
62
37
|
const connect = async () => {
|
|
63
38
|
const { house, credential } = (await readEnrolment());
|
|
39
|
+
if (paused || socket !== null)
|
|
40
|
+
return;
|
|
64
41
|
refused = null;
|
|
65
42
|
const opening = new WebSocket(relayed(connectionUrl(house)), {
|
|
66
43
|
protocols: [SUBPROTOCOL],
|
|
67
44
|
headers: { authorization: `Bearer ${credential}` },
|
|
68
45
|
});
|
|
46
|
+
socket = opening;
|
|
69
47
|
let opened = false;
|
|
70
48
|
let silence = null;
|
|
71
49
|
const closed = (event) => {
|
|
72
50
|
silence?.stop();
|
|
73
51
|
silence = null;
|
|
52
|
+
if (socket === opening)
|
|
53
|
+
socket = null;
|
|
74
54
|
if (connection === opening)
|
|
75
55
|
connection = null;
|
|
76
56
|
handlers.closed();
|
|
@@ -85,6 +65,8 @@ export function holdConnection(handlers) {
|
|
|
85
65
|
endUnserved(refused.text);
|
|
86
66
|
if (!opened && refused !== null)
|
|
87
67
|
process.stderr.write(`kit: ${refused.message}\n`);
|
|
68
|
+
if (paused)
|
|
69
|
+
return;
|
|
88
70
|
// A closed connection reopens in one to three seconds, spread so Kit processes one restart closed return apart; an opening House refused or left unanswered backs off on the jittered curve, retryable or not, since a resident outlives a House deploy.
|
|
89
71
|
setTimeout(() => void connect(), opened ? 1000 + Math.random() * 2000 : retryDelay(failures++));
|
|
90
72
|
};
|
|
@@ -92,7 +74,7 @@ export function holdConnection(handlers) {
|
|
|
92
74
|
opened = true;
|
|
93
75
|
failures = 0;
|
|
94
76
|
connection = opening;
|
|
95
|
-
silence = new
|
|
77
|
+
silence = new Silence(CONNECTION_SILENCE_MS, () => {
|
|
96
78
|
if (connection !== opening)
|
|
97
79
|
return;
|
|
98
80
|
connection = null;
|
|
@@ -122,5 +104,13 @@ export function holdConnection(handlers) {
|
|
|
122
104
|
connection.send(JSON.stringify(notification));
|
|
123
105
|
return true;
|
|
124
106
|
},
|
|
107
|
+
pause() {
|
|
108
|
+
paused = true;
|
|
109
|
+
socket?.close();
|
|
110
|
+
return () => {
|
|
111
|
+
paused = false;
|
|
112
|
+
void connect();
|
|
113
|
+
};
|
|
114
|
+
},
|
|
125
115
|
};
|
|
126
116
|
}
|