@agentshouse/kit 0.2.1-ce3d2bb67177c → 0.2.1-ceeaf32286734
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 +6 -9
- package/dist/authority-main.js +2 -2
- package/dist/bridge.js +1 -1
- package/dist/building.js +46 -0
- package/dist/calls.js +11 -3
- package/dist/clis-main.js +2 -2
- package/dist/clis.js +39 -15
- package/dist/connection.js +20 -29
- package/dist/conversations.js +149 -47
- package/dist/end.js +8 -2
- package/dist/events.js +29 -8
- package/dist/files.js +33 -17
- package/dist/git.js +2 -2
- package/dist/house-cli.js +27 -55
- package/dist/house-main.js +3 -3
- package/dist/instructions.js +29 -9
- package/dist/kit-cli.js +2 -2
- package/dist/kit-main.js +3 -3
- package/dist/login.js +3 -1
- package/dist/mcp.js +2 -0
- package/dist/relay.js +21 -0
- package/dist/resident.js +17 -6
- package/dist/scripts.js +255 -0
- package/dist/sign-in.js +3 -2
- package/dist/silence.js +28 -0
- package/dist/skills.js +41 -96
- package/dist/transcription.js +32 -23
- package/dist/update.js +51 -8
- package/package.json +19 -20
- package/dist/bootstrap.json +0 -24
- package/how-we-work.md +0 -33
- package/skills/ask-matt/LICENSE +0 -21
- package/skills/ask-matt/PHASE-BOUNDARIES.md +0 -55
- package/skills/ask-matt/SKILL.md +0 -97
- package/skills/ask-matt/agents/openai.yaml +0 -5
- package/skills/code-review/LICENSE +0 -21
- package/skills/code-review/SKILL.md +0 -89
- package/skills/code-review/agents/openai.yaml +0 -3
- package/skills/codebase-design/DEEPENING.md +0 -37
- package/skills/codebase-design/DESIGN-IT-TWICE.md +0 -44
- package/skills/codebase-design/LICENSE +0 -21
- package/skills/codebase-design/SKILL.md +0 -114
- package/skills/codebase-design/agents/openai.yaml +0 -3
- package/skills/diagnosing-bugs/LICENSE +0 -21
- package/skills/diagnosing-bugs/SKILL.md +0 -138
- package/skills/diagnosing-bugs/agents/openai.yaml +0 -3
- package/skills/diagnosing-bugs/scripts/hitl-loop.template.sh +0 -44
- package/skills/domain-modeling/ADR-FORMAT.md +0 -47
- package/skills/domain-modeling/GLOSSARY-FORMAT.md +0 -60
- package/skills/domain-modeling/LICENSE +0 -21
- package/skills/domain-modeling/SKILL.md +0 -74
- package/skills/domain-modeling/agents/openai.yaml +0 -3
- package/skills/grill-me/LICENSE +0 -21
- package/skills/grill-me/SKILL.md +0 -7
- package/skills/grill-me/agents/openai.yaml +0 -5
- package/skills/grill-with-docs/LICENSE +0 -21
- package/skills/grill-with-docs/SKILL.md +0 -7
- package/skills/grill-with-docs/agents/openai.yaml +0 -5
- package/skills/grilling/LICENSE +0 -21
- package/skills/grilling/SKILL.md +0 -30
- package/skills/grilling/agents/openai.yaml +0 -3
- package/skills/handoff/LICENSE +0 -21
- package/skills/handoff/SKILL.md +0 -16
- package/skills/handoff/agents/openai.yaml +0 -5
- package/skills/implement/LICENSE +0 -21
- package/skills/implement/SKILL.md +0 -17
- package/skills/implement/agents/openai.yaml +0 -5
- package/skills/implement-spec/LICENSE +0 -21
- package/skills/implement-spec/SKILL.md +0 -40
- package/skills/implement-spec/agents/openai.yaml +0 -5
- package/skills/improve-codebase-architecture/HTML-REPORT.md +0 -123
- package/skills/improve-codebase-architecture/LICENSE +0 -21
- package/skills/improve-codebase-architecture/SKILL.md +0 -71
- package/skills/improve-codebase-architecture/agents/openai.yaml +0 -5
- package/skills/pr/CREDITS.md +0 -3
- package/skills/pr/LICENSE +0 -21
- package/skills/pr/SKILL.md +0 -170
- package/skills/pr/agents/openai.yaml +0 -3
- package/skills/prototype/LICENSE +0 -21
- package/skills/prototype/LOGIC.md +0 -67
- package/skills/prototype/SKILL.md +0 -26
- package/skills/prototype/UI.md +0 -112
- package/skills/prototype/agents/openai.yaml +0 -3
- package/skills/research/LICENSE +0 -21
- package/skills/research/SKILL.md +0 -12
- package/skills/research/agents/openai.yaml +0 -3
- package/skills/retro/LICENSE +0 -21
- package/skills/retro/SKILL.md +0 -44
- package/skills/retro/agents/openai.yaml +0 -5
- package/skills/tdd/LICENSE +0 -21
- package/skills/tdd/SKILL.md +0 -38
- package/skills/tdd/agents/openai.yaml +0 -3
- package/skills/tdd/mocking.md +0 -59
- package/skills/tdd/tests.md +0 -77
- package/skills/teach/GLOSSARY-FORMAT.md +0 -35
- package/skills/teach/LEARNING-RECORD-FORMAT.md +0 -46
- package/skills/teach/LICENSE +0 -21
- package/skills/teach/MISSION-FORMAT.md +0 -31
- package/skills/teach/RESOURCES-FORMAT.md +0 -32
- package/skills/teach/SKILL.md +0 -140
- package/skills/teach/agents/openai.yaml +0 -5
- package/skills/to-questionnaire/LICENSE +0 -21
- package/skills/to-questionnaire/SKILL.md +0 -54
- package/skills/to-questionnaire/agents/openai.yaml +0 -5
- package/skills/to-spec/LICENSE +0 -21
- package/skills/to-spec/SKILL.md +0 -75
- package/skills/to-spec/agents/openai.yaml +0 -5
- package/skills/to-tickets/LICENSE +0 -21
- package/skills/to-tickets/SKILL.md +0 -105
- package/skills/to-tickets/agents/openai.yaml +0 -5
- package/skills/triage/AGENT-BRIEF.md +0 -207
- package/skills/triage/LICENSE +0 -21
- package/skills/triage/OUT-OF-SCOPE.md +0 -105
- package/skills/triage/SKILL.md +0 -112
- package/skills/triage/agents/openai.yaml +0 -5
- package/skills/wait-what/LICENSE +0 -21
- package/skills/wait-what/SKILL.md +0 -7
- package/skills/wait-what/agents/openai.yaml +0 -5
- package/skills/wayfinder/LICENSE +0 -21
- package/skills/wayfinder/SKILL.md +0 -128
- package/skills/wayfinder/agents/openai.yaml +0 -5
- package/skills/wizard/LICENSE +0 -21
- package/skills/wizard/SKILL.md +0 -44
- package/skills/wizard/agents/openai.yaml +0 -3
- package/skills/wizard/template.sh +0 -223
- package/skills/writing-for-agents/LICENSE +0 -21
- package/skills/writing-for-agents/SKILL-MECHANICS.md +0 -22
- package/skills/writing-for-agents/SKILL.md +0 -81
- package/skills/writing-for-agents/agents/openai.yaml +0 -3
package/README.md
CHANGED
|
@@ -26,8 +26,8 @@ Kit runs the agent CLIs your login shell finds and installs a missing one
|
|
|
26
26
|
through that CLI's own installer. 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
|
-
Environment
|
|
30
|
-
them out; running it again without the flag brings them back.
|
|
29
|
+
Environment the agent skills of `@agentshouse/skills`, at the version each Kit
|
|
30
|
+
release installs. Add `--no-skills` to the command to leave them out; running it again without the flag brings them back.
|
|
31
31
|
|
|
32
32
|
## Commands
|
|
33
33
|
|
|
@@ -51,10 +51,10 @@ Room may no longer be copied here. `house fetch` does the same and records House
|
|
|
51
51
|
`refs/house/received`; rebase onto it, commit and run `house push --owner` in the copy, through the install command in
|
|
52
52
|
the container. An Agent runs both, without `--owner`. `house upload` and `house download` move a Room's other files straight between disk and House's store, and a broken upload resumes on its own.
|
|
53
53
|
|
|
54
|
-
Kit turns each audio file your message to an Agent links into text on this
|
|
55
|
-
|
|
56
|
-
|
|
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
|
+
|
|
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
|
|
|
60
|
-
MIT.
|
|
60
|
+
MIT.
|
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,
|
|
@@ -246,7 +243,7 @@ export class Agents {
|
|
|
246
243
|
const known = this.readings.get(kind) ?? SIGNED_OUT;
|
|
247
244
|
const owner = {};
|
|
248
245
|
try {
|
|
249
|
-
await this.examine(kind, known,
|
|
246
|
+
await this.examine(kind, known, (kind, cli) => offer(kind, cli, known, AbortSignal.any([signal, AbortSignal.timeout(SIGNED_IN_READ_MS)])), signal, owner);
|
|
250
247
|
}
|
|
251
248
|
finally {
|
|
252
249
|
this.settle(kind, owner);
|
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/bridge.js
CHANGED
|
@@ -13,7 +13,7 @@ import { callHouse, mcpBody, rpc, UNREACHABLE } from './mcp.js';
|
|
|
13
13
|
import { operationId } from './operation.js';
|
|
14
14
|
import { refusalOf, retryable } from './refusals.js';
|
|
15
15
|
import { relayed } from './relay.js';
|
|
16
|
-
const MCP_REQUEST_BYTES =
|
|
16
|
+
const MCP_REQUEST_BYTES = 4_000_000;
|
|
17
17
|
export async function received(request) {
|
|
18
18
|
let text = '';
|
|
19
19
|
request.setEncoding('utf8');
|
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,7 +72,7 @@ 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',
|
|
74
77
|
adapter: {
|
|
75
78
|
package: '@agentclientprotocol/codex-acp',
|
|
@@ -92,7 +95,7 @@ export const CLIS = {
|
|
|
92
95
|
},
|
|
93
96
|
'claude-agent-acp': {
|
|
94
97
|
bin: 'claude',
|
|
95
|
-
minimum: '2.1.
|
|
98
|
+
minimum: '2.1.303',
|
|
96
99
|
install: 'curl -fsSL https://claude.ai/install.sh | bash',
|
|
97
100
|
adapter: {
|
|
98
101
|
package: '@agentclientprotocol/claude-agent-acp',
|
|
@@ -110,7 +113,7 @@ export const CLIS = {
|
|
|
110
113
|
title,
|
|
111
114
|
settings: { sandbox: { network: bridgeInClaudeSandbox(bridge) } },
|
|
112
115
|
},
|
|
113
|
-
emitRawSDKMessages: RAW_SUBTYPES.map((subtype) => ({ type: 'system', subtype })),
|
|
116
|
+
emitRawSDKMessages: [...RAW_SUBTYPES.map((subtype) => ({ type: 'system', subtype })), { type: 'result' }],
|
|
114
117
|
},
|
|
115
118
|
}),
|
|
116
119
|
unknownSession: (error) => answered(error).code === -32002,
|
|
@@ -138,7 +141,6 @@ export const CLIS = {
|
|
|
138
141
|
};
|
|
139
142
|
const KIT_PACKAGE = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
|
|
140
143
|
export const KIT_RELEASE = KIT_PACKAGE.version;
|
|
141
|
-
const PROXY = /^https?_proxy$/i;
|
|
142
144
|
const VERSION = /\d+\.\d+\.\d+(?:-[0-9A-Za-z.]+)?/;
|
|
143
145
|
// An install still running after fifteen minutes is ended and reported as failed, so a hung download cannot hold its CLI's report.
|
|
144
146
|
const INSTALL_MS = 15 * 60_000;
|
|
@@ -160,15 +162,12 @@ async function installedAdapter(kind) {
|
|
|
160
162
|
return null;
|
|
161
163
|
}
|
|
162
164
|
}
|
|
163
|
-
export function withoutProxy() {
|
|
164
|
-
return Object.fromEntries(Object.entries(process.env).filter(([name]) => !PROXY.test(name)));
|
|
165
|
-
}
|
|
166
165
|
export function run(command, args, timeoutMs, detached = false, signal) {
|
|
167
166
|
return new Promise((resolve) => {
|
|
168
167
|
const child = spawn(command, args, {
|
|
169
168
|
stdio: ['ignore', 'pipe', 'pipe'],
|
|
170
169
|
timeout: timeoutMs,
|
|
171
|
-
env:
|
|
170
|
+
env: childEnvironment(),
|
|
172
171
|
detached,
|
|
173
172
|
signal: detached ? undefined : signal,
|
|
174
173
|
});
|
|
@@ -202,15 +201,37 @@ export function run(command, args, timeoutMs, detached = false, signal) {
|
|
|
202
201
|
export function failureOf(ran, program) {
|
|
203
202
|
return ran.output.trim().slice(-CAUSE_CHARACTERS) || `${program} exited with ${ran.status ?? 'a signal'}`;
|
|
204
203
|
}
|
|
204
|
+
export function adapterArchive(kind) {
|
|
205
|
+
return `${kind}-${KIT_PACKAGE.peerDependencies[CLIS[kind].adapter.package]}.tar.gz`;
|
|
206
|
+
}
|
|
205
207
|
export async function installAdapter(kind, signal) {
|
|
206
208
|
const adapter = CLIS[kind].adapter;
|
|
207
209
|
if (adapter === null)
|
|
208
210
|
return null;
|
|
209
|
-
|
|
210
|
-
if ((await installedAdapter(kind)) === release)
|
|
211
|
+
if ((await installedAdapter(kind)) === KIT_PACKAGE.peerDependencies[adapter.package])
|
|
211
212
|
return null;
|
|
212
|
-
const
|
|
213
|
-
|
|
213
|
+
const name = adapterArchive(kind);
|
|
214
|
+
const archive = `${prefix(kind)}.tar.gz`;
|
|
215
|
+
const deadline = AbortSignal.timeout(INSTALL_MS);
|
|
216
|
+
const bounded = signal === undefined ? deadline : AbortSignal.any([signal, deadline]);
|
|
217
|
+
try {
|
|
218
|
+
const sha256 = await servedDigest(name, bounded);
|
|
219
|
+
if (sha256 === null)
|
|
220
|
+
return `House serves no ${name}`;
|
|
221
|
+
await rm(prefix(kind), { recursive: true, force: true });
|
|
222
|
+
await mkdir(prefix(kind), { recursive: true });
|
|
223
|
+
await downloadServed(name, sha256, archive, bounded);
|
|
224
|
+
const ran = await run('tar', ['-xzf', archive, '-C', prefix(kind)], INSTALL_MS, true, signal);
|
|
225
|
+
return ran.status === 0 ? null : failureOf(ran, 'tar');
|
|
226
|
+
}
|
|
227
|
+
catch (error) {
|
|
228
|
+
if (deadline.aborted && signal?.aborted !== true)
|
|
229
|
+
return `${name} did not arrive within ${INSTALL_MS / 1000} seconds`;
|
|
230
|
+
return error instanceof Error ? error.message : String(error);
|
|
231
|
+
}
|
|
232
|
+
finally {
|
|
233
|
+
await rm(archive, { force: true });
|
|
234
|
+
}
|
|
214
235
|
}
|
|
215
236
|
export async function installCli(kind, signal) {
|
|
216
237
|
const ran = await run('bash', ['-o', 'pipefail', '-c', CLIS[kind].install], INSTALL_MS, true, signal);
|
|
@@ -225,10 +246,13 @@ const USER_BIN = 'case ":$PATH:" in *":$HOME/.local/bin:"*) ;; *) PATH="$PATH:$H
|
|
|
225
246
|
function inLoginShell(script, argument = '', signal) {
|
|
226
247
|
return run(loginShell(), ['-l', '-i', '-c', `exec /bin/sh -c '${USER_BIN}; ${script}' sh ${argument}`], READ_MS, true, signal);
|
|
227
248
|
}
|
|
228
|
-
export async function
|
|
229
|
-
const ran = await inLoginShell(LOOKUP,
|
|
249
|
+
export async function onLoginPath(program, signal) {
|
|
250
|
+
const ran = await inLoginShell(LOOKUP, program, signal);
|
|
230
251
|
return ran.stdout.split('\n').findLast((line) => line.startsWith(FOUND))?.slice(FOUND.length) ?? null;
|
|
231
252
|
}
|
|
253
|
+
export function locate(kind, signal) {
|
|
254
|
+
return onLoginPath(CLIS[kind].bin, signal);
|
|
255
|
+
}
|
|
232
256
|
export async function loginPath() {
|
|
233
257
|
const marker = 'house-kit-path ';
|
|
234
258
|
const ran = await inLoginShell(`printf "${marker}%s\\n" "$PATH"`);
|
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,21 +31,29 @@ 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;
|
|
56
|
+
handlers.closed();
|
|
76
57
|
process.stderr.write(`kit: connection closed ${event.code} ${event.reason}\n`);
|
|
77
58
|
if (event.reason === 'replaced')
|
|
78
59
|
end(REPLACED);
|
|
@@ -84,6 +65,8 @@ export function holdConnection(handlers) {
|
|
|
84
65
|
endUnserved(refused.text);
|
|
85
66
|
if (!opened && refused !== null)
|
|
86
67
|
process.stderr.write(`kit: ${refused.message}\n`);
|
|
68
|
+
if (paused)
|
|
69
|
+
return;
|
|
87
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.
|
|
88
71
|
setTimeout(() => void connect(), opened ? 1000 + Math.random() * 2000 : retryDelay(failures++));
|
|
89
72
|
};
|
|
@@ -91,7 +74,7 @@ export function holdConnection(handlers) {
|
|
|
91
74
|
opened = true;
|
|
92
75
|
failures = 0;
|
|
93
76
|
connection = opening;
|
|
94
|
-
silence = new
|
|
77
|
+
silence = new Silence(CONNECTION_SILENCE_MS, () => {
|
|
95
78
|
if (connection !== opening)
|
|
96
79
|
return;
|
|
97
80
|
connection = null;
|
|
@@ -121,5 +104,13 @@ export function holdConnection(handlers) {
|
|
|
121
104
|
connection.send(JSON.stringify(notification));
|
|
122
105
|
return true;
|
|
123
106
|
},
|
|
107
|
+
pause() {
|
|
108
|
+
paused = true;
|
|
109
|
+
socket?.close();
|
|
110
|
+
return () => {
|
|
111
|
+
paused = false;
|
|
112
|
+
void connect();
|
|
113
|
+
};
|
|
114
|
+
},
|
|
124
115
|
};
|
|
125
116
|
}
|