@agentshouse/kit 0.2.1-ce47f621f90e1 → 0.2.1-ce9401bb7d372
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 +3 -4
- package/dist/acp.js +1 -1
- package/dist/afk.js +17 -0
- package/dist/agents.js +45 -13
- package/dist/api.js +11 -6
- package/dist/authority-main.js +2 -2
- package/dist/bridge.js +4 -4
- package/dist/calls.js +1 -1
- package/dist/chunks.js +49 -0
- package/dist/clis.js +16 -8
- package/dist/connection.js +25 -10
- package/dist/content.js +63 -0
- package/dist/conversations.js +236 -115
- package/dist/copies.js +293 -148
- package/dist/end.js +1 -8
- package/dist/events.js +729 -218
- package/dist/files.js +2 -2
- package/dist/git.js +44 -10
- package/dist/grok.js +39 -0
- package/dist/house-cli.js +81 -21
- package/dist/instructions.js +2 -4
- package/dist/kit-cli.js +1 -4
- package/dist/login.js +12 -5
- package/dist/logout.js +2 -2
- package/dist/mcp.js +2 -2
- package/dist/placement.js +0 -6
- package/dist/resident.js +39 -32
- package/dist/scripts.js +59 -11
- package/dist/secret-input.js +1 -1
- package/dist/transcription.js +5 -2
- package/dist/translate.js +18 -9
- package/dist/update.js +2 -1
- package/dist/wire.js +2 -10
- package/dist/work.js +9 -2
- package/package.json +12 -8
- package/dist/chatgpt.js +0 -32
- package/dist/enrol-main.js +0 -10
- package/dist/parts.js +0 -82
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@ Run `sh -c 'kit=$(curl -fsSL "$0") || { echo "Kit could not be downloaded; run t
|
|
|
9
9
|
or `& { try { $kit = irm agents.house/kit.ps1 } catch { throw 'Kit could not be downloaded; run this command again.' }; & ([scriptblock]::Create($kit)) @args }` on Windows, which run nothing of a failed download, and again to update; options follow `agents.house/kit`.
|
|
10
10
|
On macOS and Linux it installs Kit natively under your own account, without an admin password, as a service that runs
|
|
11
11
|
while you are logged in. `kit` and `house` are then on your login shell's `PATH`, and your workspace is `~/AgentsHouse` unless you
|
|
12
|
-
pass `--workspace <path>`. Every run places the Kit release your Building serves, with the Node.js and agent adapters it runs on, in a directory of its own beside the one that runs, then starts it; the earlier one stays until the next release. Kit also updates itself: when your Building takes another release, Kit places it the same way and, once no turn is open, ends so its service, or the container's restart policy, starts it. When House
|
|
12
|
+
pass `--workspace <path>`. Every run places the Kit release your Building serves, with the Node.js and agent adapters it runs on, in a directory of its own beside the one that runs, then starts it; the earlier one stays until the next release. Kit also updates itself: when your Building takes another release, Kit places it the same way and, once no turn is open, ends so its service, or the container's restart policy, starts it. When House no longer serves the wire of the Kit that runs, Kit places your Building's release at once, ending any running turn, and ends the same way; while it cannot, it stays offline, prints why with the command that installs it again, and tries again regularly.
|
|
13
13
|
|
|
14
14
|
Add `--container` to run Kit in one Docker container instead, with your workspace mounted at `/agents/house`; your Agents then reach only that
|
|
15
15
|
workspace. The container's image holds no Kit release and no Node.js: every run places them in Kit home's `kit` folder, which a container created again keeps. On Windows,
|
|
@@ -20,7 +20,7 @@ from the running Kit process asks you to confirm before it replaces that process
|
|
|
20
20
|
|
|
21
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
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,
|
|
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, a native install on a macOS older than 13.5, and one on a Linux without glibc 2.28 or newer, 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 each agent CLI through the link your login shell finds and installs a missing one through that CLI's own
|
|
26
26
|
installer. When it starts and regularly after, Kit runs each CLI's own update command, such as `claude update`, beside
|
|
@@ -38,12 +38,11 @@ reconnects an Environment you already have; `--rooms <ref>[,<ref>...]` gives it
|
|
|
38
38
|
only those Rooms and `--no-private` every Room but your Private Room; `--code <code>` connects immediately without a link.
|
|
39
39
|
A login also connects your own agent: outside an Agent conversation, `house <tool>` calls
|
|
40
40
|
House as you and `git` clones and pushes your Apps at `<house>/app/` as you, each through the Kit
|
|
41
|
-
home `$HOUSE_KIT_HOME` names where it runs, until you revoke that connection on Connections. `house help` lists the Tools. Codex sessions started after a
|
|
41
|
+
home `$HOUSE_KIT_HOME` names where it runs, until you revoke that connection on Connections. `house help` lists the Tools and `house help <tool>` one Tool's arguments. Codex sessions started after a
|
|
42
42
|
login run a lone `house` command outside their sandbox. `kit logout` disconnects this
|
|
43
43
|
computer, stops the Kit process and ends your own agent's connection, so `house` and `git` no
|
|
44
44
|
longer act as you here; a later `kit login` reconnects the same Environment, or connects
|
|
45
45
|
this computer as a new one when House no longer holds it.
|
|
46
|
-
In a container you do not control, such as ChatGPT's, `npm i -g @agentshouse/kit` and `kit chatgpt --key <key>` with a key made on Connections let `house <tool>` act as you, starting and configuring nothing else.
|
|
47
46
|
|
|
48
47
|
`kit resident` keeps the Environment connected and, as it connects, copies the text of each Room you chose for it as a
|
|
49
48
|
Git repository in the workspace's `local-copies`, and keeps a Room's copy as it is, no longer refreshing it, once the
|
package/dist/acp.js
CHANGED
|
@@ -116,7 +116,7 @@ export async function startAdapter(kind, cli, cwd, app, events = () => undefined
|
|
|
116
116
|
terminal: false,
|
|
117
117
|
elicitation: { form: {} },
|
|
118
118
|
session: { compaction: {}, notices: {} },
|
|
119
|
-
_meta: { jetbrains: { air: { version: 1, capabilities: CLIS[kind].air } } },
|
|
119
|
+
_meta: { terminal_output: true, jetbrains: { air: { version: 1, capabilities: CLIS[kind].air } } },
|
|
120
120
|
},
|
|
121
121
|
clientInfo: { name: '@agentshouse/kit', version: KIT_RELEASE },
|
|
122
122
|
});
|
package/dist/afk.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { CLIS } from './clis.js';
|
|
2
|
+
const NOBODY_THERE = 'Nobody is there to answer. Decide for yourself and go on.';
|
|
3
|
+
export const PLAN_APPROVED = { outcome: 'approved' };
|
|
4
|
+
function told(fields) {
|
|
5
|
+
return Object.fromEntries(fields.map((field) => [field, NOBODY_THERE]));
|
|
6
|
+
}
|
|
7
|
+
export function permissionAllowed({ options }) {
|
|
8
|
+
const option = options.find(({ kind }) => kind === 'allow_once') ?? options.find(({ kind }) => kind === 'allow_always');
|
|
9
|
+
return { outcome: { outcome: 'selected', optionId: option.optionId } };
|
|
10
|
+
}
|
|
11
|
+
export function formAnswered(kind, request) {
|
|
12
|
+
const fields = CLIS[kind].questionFields(request);
|
|
13
|
+
return fields.length === 0 ? { action: 'decline' } : { action: 'accept', content: told(fields) };
|
|
14
|
+
}
|
|
15
|
+
export function grokQuestionAnswered({ questions }) {
|
|
16
|
+
return { outcome: 'accepted', answers: told(questions.map(({ question }) => question)) };
|
|
17
|
+
}
|
package/dist/agents.js
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import { client } from '@agentclientprotocol/sdk';
|
|
2
|
+
import { KIT_WIRE } from '@agentshouse/kit-wire';
|
|
2
3
|
import { readFile } from 'node:fs/promises';
|
|
3
4
|
import { setTimeout as delay } from 'node:timers/promises';
|
|
4
5
|
import { signedOut, startAdapter } from './acp.js';
|
|
5
6
|
import { CLIS, KIT_RELEASE, below, installCli, locate, run, updateCli, versionOf } from './clis.js';
|
|
6
7
|
import { agentBase, kitHome } from './home.js';
|
|
7
8
|
import { holdTranscription, transcriptionReport } from './transcription.js';
|
|
8
|
-
import { KIT_WIRE } from './wire.js';
|
|
9
9
|
// Two quiet seconds let a fresh conversation start before background model discovery competes for its CPU.
|
|
10
10
|
const MODEL_PROBE_QUIET_MS = 2_000;
|
|
11
11
|
// A CLI's maker can publish several releases a day, so running each chosen CLI's update command hourly brings a new one to the next conversation within the hour for one small check.
|
|
12
12
|
export const CLI_UPDATE_MS = 60 * 60_000;
|
|
13
13
|
// 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.
|
|
14
14
|
const SIGNED_IN_READ_MS = 10_000;
|
|
15
|
-
const
|
|
15
|
+
const UNNAMED = { default_model: null, default_effort: null };
|
|
16
|
+
const SIGNED_OUT = { signed_in: false, models: [], ...UNNAMED, modes: [] };
|
|
16
17
|
const INSTALLING = { release: null, failure: null, installing: true, ...SIGNED_OUT };
|
|
17
18
|
function select(options, category) {
|
|
18
19
|
const option = options.find((candidate) => candidate.category === category);
|
|
@@ -24,6 +25,22 @@ function choices(options) {
|
|
|
24
25
|
function values(options) {
|
|
25
26
|
return choices(options).map((entry) => entry.value);
|
|
26
27
|
}
|
|
28
|
+
const CLI_DEFAULT = 'default';
|
|
29
|
+
function effortsOf(option) {
|
|
30
|
+
return option === undefined ? [] : values(option.options).filter((value) => value !== CLI_DEFAULT);
|
|
31
|
+
}
|
|
32
|
+
function named(options) {
|
|
33
|
+
const listed = choices(options).filter((entry) => entry.value !== CLI_DEFAULT);
|
|
34
|
+
return listed.filter((entry, at) => listed.findIndex((first) => first.name === entry.name) === at);
|
|
35
|
+
}
|
|
36
|
+
function starting(model, effort) {
|
|
37
|
+
const current = choices(model.options).find((entry) => entry.value === model.currentValue);
|
|
38
|
+
const name = current?.value === CLI_DEFAULT ? current.description : current?.name;
|
|
39
|
+
return {
|
|
40
|
+
default_model: named(model.options).find((entry) => entry.name === name)?.value ?? null,
|
|
41
|
+
default_effort: effort === undefined || effort.currentValue === CLI_DEFAULT ? null : effort.currentValue,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
27
44
|
function causeOf(error) {
|
|
28
45
|
return error instanceof Error ? error.message : String(error);
|
|
29
46
|
}
|
|
@@ -54,23 +71,23 @@ async function models(kind, adapter, known) {
|
|
|
54
71
|
const modes = mode === undefined ? [] : choices(mode.options).map(({ value, name }) => ({ mode: value, name }));
|
|
55
72
|
const model = select(options, 'model');
|
|
56
73
|
if (model === undefined)
|
|
57
|
-
return { models: [], modes };
|
|
74
|
+
return { models: [], ...UNNAMED, modes };
|
|
75
|
+
const started = starting(model, select(options, 'thought_level'));
|
|
58
76
|
const offered = [];
|
|
59
|
-
for (const value of
|
|
77
|
+
for (const { value, name } of named(model.options)) {
|
|
60
78
|
if (select(options, 'model')?.currentValue !== value) {
|
|
61
79
|
try {
|
|
62
80
|
options = (await agent.request('session/set_config_option', { sessionId: opened.sessionId, configId: model.id, value })).configOptions;
|
|
63
81
|
}
|
|
64
82
|
catch (error) {
|
|
65
83
|
process.stderr.write(`kit: ${kind} refused its model ${value}: ${causeOf(error)}\n`);
|
|
66
|
-
offered.push({ model: value, efforts: known.find((entry) => entry.model === value)?.efforts ?? [] });
|
|
84
|
+
offered.push({ model: value, name, efforts: known.find((entry) => entry.model === value)?.efforts ?? [] });
|
|
67
85
|
continue;
|
|
68
86
|
}
|
|
69
87
|
}
|
|
70
|
-
|
|
71
|
-
offered.push({ model: value, efforts: effort === undefined ? [] : values(effort.options) });
|
|
88
|
+
offered.push({ model: value, name, efforts: effortsOf(select(options, 'thought_level')) });
|
|
72
89
|
}
|
|
73
|
-
return { models: offered, modes };
|
|
90
|
+
return { models: offered, ...started, modes };
|
|
74
91
|
}
|
|
75
92
|
function ended(signal) {
|
|
76
93
|
return new Promise((_, reject) => {
|
|
@@ -103,6 +120,8 @@ async function offer(kind, cli, known, signal) {
|
|
|
103
120
|
return {
|
|
104
121
|
signed_in: adapter === undefined && 'initializeMeta' in probe ? known.signed_in : true,
|
|
105
122
|
models: known.models,
|
|
123
|
+
default_model: known.default_model,
|
|
124
|
+
default_effort: known.default_effort,
|
|
106
125
|
modes: known.modes,
|
|
107
126
|
};
|
|
108
127
|
}
|
|
@@ -122,6 +141,8 @@ function reported(kind, reading) {
|
|
|
122
141
|
models: reading.models,
|
|
123
142
|
modes: reading.modes,
|
|
124
143
|
full_access: CLIS[kind].fullAccess,
|
|
144
|
+
...(reading.default_model === null ? {} : { default_model: reading.default_model }),
|
|
145
|
+
...(reading.default_effort === null ? {} : { default_effort: reading.default_effort }),
|
|
125
146
|
};
|
|
126
147
|
}
|
|
127
148
|
const NOT_READY = "the Agent's CLI is not ready on this computer";
|
|
@@ -186,7 +207,7 @@ export class Agents {
|
|
|
186
207
|
this.refreshing++;
|
|
187
208
|
this.changed();
|
|
188
209
|
const reading = this.read().then(async () => {
|
|
189
|
-
this.desired = await this.house.deliver('
|
|
210
|
+
this.desired = await this.house.deliver('agents/desired/list', {});
|
|
190
211
|
return this.desired;
|
|
191
212
|
});
|
|
192
213
|
this.reading = reading;
|
|
@@ -206,9 +227,12 @@ export class Agents {
|
|
|
206
227
|
});
|
|
207
228
|
return reading.then(() => undefined);
|
|
208
229
|
}
|
|
209
|
-
keepCurrent() {
|
|
230
|
+
keepCurrent(stopping) {
|
|
210
231
|
this.updateAll(this.loaded);
|
|
211
|
-
setInterval(() =>
|
|
232
|
+
setInterval(() => {
|
|
233
|
+
if (!stopping())
|
|
234
|
+
this.updateAll(Promise.resolve());
|
|
235
|
+
}, CLI_UPDATE_MS);
|
|
212
236
|
}
|
|
213
237
|
cli(kind) {
|
|
214
238
|
this.starts += 1;
|
|
@@ -222,7 +246,15 @@ export class Agents {
|
|
|
222
246
|
const known = this.readings.get(kind);
|
|
223
247
|
const kept = known?.release === null ? SIGNED_OUT : (known ?? SIGNED_OUT);
|
|
224
248
|
if (known?.release !== release || this.installs.has(kind)) {
|
|
225
|
-
this.update(kind, {
|
|
249
|
+
this.update(kind, {
|
|
250
|
+
release,
|
|
251
|
+
failure: null,
|
|
252
|
+
signed_in: kept.signed_in,
|
|
253
|
+
models: kept.models,
|
|
254
|
+
default_model: kept.default_model,
|
|
255
|
+
default_effort: kept.default_effort,
|
|
256
|
+
modes: kept.modes,
|
|
257
|
+
});
|
|
226
258
|
}
|
|
227
259
|
const read = this.nextRead(kind);
|
|
228
260
|
this.quietOffer(kind, cli, kept)
|
|
@@ -388,7 +420,7 @@ export class Agents {
|
|
|
388
420
|
const state = JSON.stringify(body);
|
|
389
421
|
if (state === this.sent)
|
|
390
422
|
return;
|
|
391
|
-
await this.house.deliver('
|
|
423
|
+
await this.house.deliver('agents/report', body);
|
|
392
424
|
this.sent = state;
|
|
393
425
|
}
|
|
394
426
|
}
|
package/dist/api.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { KIT_WIRE, KIT_WIRE_HEADER, } from '@agentshouse/kit-wire';
|
|
1
2
|
import { setTimeout as delay } from 'node:timers/promises';
|
|
2
3
|
import { signInAgain } from './end.js';
|
|
3
4
|
import { readEnrolment } from './home.js';
|
|
4
5
|
import { retryable } from './refusals.js';
|
|
5
6
|
import { relayed } from './relay.js';
|
|
6
|
-
import { endUnserved
|
|
7
|
+
import { endUnserved } from './wire.js';
|
|
7
8
|
export class HouseRefusal extends Error {
|
|
8
9
|
status;
|
|
9
10
|
text;
|
|
@@ -38,7 +39,7 @@ export async function post(house, path, body, credential, signal) {
|
|
|
38
39
|
method: 'POST',
|
|
39
40
|
headers: {
|
|
40
41
|
'content-type': 'application/json',
|
|
41
|
-
[KIT_WIRE_HEADER]:
|
|
42
|
+
[KIT_WIRE_HEADER]: KIT_WIRE,
|
|
42
43
|
...(credential === undefined ? {} : { authorization: `Bearer ${credential}` }),
|
|
43
44
|
},
|
|
44
45
|
body: JSON.stringify(body),
|
|
@@ -51,6 +52,9 @@ export async function post(house, path, body, credential, signal) {
|
|
|
51
52
|
throw new HouseRefusal(path, answer.status, text);
|
|
52
53
|
return JSON.parse(text);
|
|
53
54
|
}
|
|
55
|
+
export function kitAct(house, act, request, credential, signal) {
|
|
56
|
+
return post(house, `/kit/${act}`, request, credential, signal);
|
|
57
|
+
}
|
|
54
58
|
async function enrolledPost(path, body, signal) {
|
|
55
59
|
const { house, credential } = (await readEnrolment());
|
|
56
60
|
try {
|
|
@@ -63,16 +67,17 @@ async function enrolledPost(path, body, signal) {
|
|
|
63
67
|
}
|
|
64
68
|
}
|
|
65
69
|
export const house = {
|
|
66
|
-
|
|
67
|
-
|
|
70
|
+
act: (act, request, signal) => enrolledPost(`/kit/${act}`, request, signal),
|
|
71
|
+
door: (act, body, signal) => enrolledPost(`/kit/door/${act}`, body, signal),
|
|
72
|
+
deliver: async (act, request, current = () => true) => {
|
|
68
73
|
for (let attempt = 0;; attempt++) {
|
|
69
74
|
try {
|
|
70
|
-
return await enrolledPost(
|
|
75
|
+
return await enrolledPost(`/kit/${act}`, request);
|
|
71
76
|
}
|
|
72
77
|
catch (error) {
|
|
73
78
|
if (finalRefusal(error))
|
|
74
79
|
throw error;
|
|
75
|
-
process.stderr.write(`kit:
|
|
80
|
+
process.stderr.write(`kit: /kit/${act} did not reach House: ${error.message}\n`);
|
|
76
81
|
// A delivery House did not take is sent again on the jittered curve for as long as it is still current.
|
|
77
82
|
await new Promise((resolve) => setTimeout(resolve, retryDelay(attempt)));
|
|
78
83
|
if (!current())
|
package/dist/authority-main.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { HouseRefusal,
|
|
1
|
+
import { HouseRefusal, kitAct } from './api.js';
|
|
2
2
|
import { readEnrolment } from './home.js';
|
|
3
3
|
import { proxyUnlessRelayed } from './relay.js';
|
|
4
4
|
function unanswered(error) {
|
|
@@ -8,7 +8,7 @@ proxyUnlessRelayed();
|
|
|
8
8
|
try {
|
|
9
9
|
const { house, credential } = (await readEnrolment());
|
|
10
10
|
try {
|
|
11
|
-
await
|
|
11
|
+
await kitAct(house, 'agents/desired/list', {}, credential);
|
|
12
12
|
}
|
|
13
13
|
catch (error) {
|
|
14
14
|
if (!unanswered(error))
|
package/dist/bridge.js
CHANGED
|
@@ -81,7 +81,7 @@ function editAnswer(forwarded) {
|
|
|
81
81
|
export async function openBridge(house, copies, conversationId, signal) {
|
|
82
82
|
const path = [join(kitHome(), 'shim'), dirname(process.execPath), await loginPath()].join(delimiter);
|
|
83
83
|
const origin = (await readEnrolment()).house;
|
|
84
|
-
const { credential } = await retrying(() => house.
|
|
84
|
+
const { credential } = await retrying(() => house.act('conversations/credentials/issue', { conversation: conversationId }, signal), signal);
|
|
85
85
|
const closed = new AbortController();
|
|
86
86
|
const sent = (message, operation) => callHouse(origin, credential, message, operation, closed.signal);
|
|
87
87
|
const send = async (message, operation) => {
|
|
@@ -105,7 +105,7 @@ export async function openBridge(house, copies, conversationId, signal) {
|
|
|
105
105
|
const bytes = Buffer.from(JSON.stringify({ changes }));
|
|
106
106
|
const sha256 = createHash('sha256').update(bytes).digest('hex');
|
|
107
107
|
const prepared = answered(await send(call('run_command', {
|
|
108
|
-
command: '
|
|
108
|
+
command: 'files/batch-upload',
|
|
109
109
|
arguments: { paths: changedPaths(changes), bytes: bytes.length, sha256 },
|
|
110
110
|
}), operation));
|
|
111
111
|
if ('refused' in prepared)
|
|
@@ -141,7 +141,7 @@ export async function openBridge(house, copies, conversationId, signal) {
|
|
|
141
141
|
const caller = {
|
|
142
142
|
key: `conversation:${conversationId}`,
|
|
143
143
|
submit: async (operation, changes, held, retain) => {
|
|
144
|
-
const inline = call('
|
|
144
|
+
const inline = call('files_batch', { changes });
|
|
145
145
|
let upload = held;
|
|
146
146
|
if (upload === undefined && Buffer.byteLength(mcpBody(inline, operation)) > MCP_REQUEST_BYTES) {
|
|
147
147
|
const prepared = await staged(operation, changes);
|
|
@@ -150,7 +150,7 @@ export async function openBridge(house, copies, conversationId, signal) {
|
|
|
150
150
|
upload = prepared;
|
|
151
151
|
await retain(upload);
|
|
152
152
|
}
|
|
153
|
-
return editAnswer(await send(upload === undefined ? inline : call('
|
|
153
|
+
return editAnswer(await send(upload === undefined ? inline : call('files_batch', { paths: changedPaths(changes), upload }), operation));
|
|
154
154
|
},
|
|
155
155
|
};
|
|
156
156
|
const local = async (path, text) => {
|
package/dist/calls.js
CHANGED
|
@@ -42,7 +42,7 @@ export class Calls {
|
|
|
42
42
|
return carried
|
|
43
43
|
.then(async ({ result, returned, release }) => {
|
|
44
44
|
try {
|
|
45
|
-
await this.house.deliver(
|
|
45
|
+
await this.house.deliver('kit-calls/results/return', { call: callId, ...result });
|
|
46
46
|
}
|
|
47
47
|
finally {
|
|
48
48
|
this.returned.add(callId);
|
package/dist/chunks.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { readFile, rm } from 'node:fs/promises';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { downloaded, fetched } from './files.js';
|
|
4
|
+
const DOWNLOADS_AT_ONCE = 6;
|
|
5
|
+
// A chunk is about one megabyte, so a download still unfinished after two minutes holds every Room behind it on a dead connection.
|
|
6
|
+
const CHUNK_DOWNLOAD_MS = 120_000;
|
|
7
|
+
class AddressExpired extends Error {
|
|
8
|
+
constructor() {
|
|
9
|
+
super("House's store refused every chunk it asked for");
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function once(chunk) {
|
|
13
|
+
let asked = false;
|
|
14
|
+
return async () => {
|
|
15
|
+
if (asked)
|
|
16
|
+
throw new AddressExpired();
|
|
17
|
+
asked = true;
|
|
18
|
+
return { download: chunk.download, sha256: chunk.hash };
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export async function stagedChunks(directory, chunks) {
|
|
22
|
+
let next = 0;
|
|
23
|
+
let failure;
|
|
24
|
+
const downloading = async () => {
|
|
25
|
+
while (next < chunks.length && failure === undefined) {
|
|
26
|
+
const chunk = chunks[next++];
|
|
27
|
+
const reading = (url) => fetched(url, AbortSignal.timeout(CHUNK_DOWNLOAD_MS));
|
|
28
|
+
await downloaded(once(chunk), reading, join(directory, chunk.hash), 'A Room chunk').catch((error) => {
|
|
29
|
+
failure ??= error;
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
await Promise.all(Array.from({ length: DOWNLOADS_AT_ONCE }, downloading));
|
|
34
|
+
return failure;
|
|
35
|
+
}
|
|
36
|
+
export async function* chunkTexts(directory, chunks, models) {
|
|
37
|
+
yield* models;
|
|
38
|
+
for (const { hash } of chunks) {
|
|
39
|
+
const file = join(directory, hash);
|
|
40
|
+
for (const line of (await readFile(file, 'utf8')).split('\n')) {
|
|
41
|
+
if (line === '')
|
|
42
|
+
continue;
|
|
43
|
+
const entry = JSON.parse(line);
|
|
44
|
+
if (entry.content !== undefined)
|
|
45
|
+
yield entry;
|
|
46
|
+
}
|
|
47
|
+
await rm(file);
|
|
48
|
+
}
|
|
49
|
+
}
|
package/dist/clis.js
CHANGED
|
@@ -20,6 +20,7 @@ const RAW_SUBTYPES = [
|
|
|
20
20
|
'hook_started',
|
|
21
21
|
'hook_response',
|
|
22
22
|
];
|
|
23
|
+
const RAW_TYPES = ['result', 'user', 'assistant', 'rate_limit_event', 'prompt_suggestion'];
|
|
23
24
|
async function executable(path) {
|
|
24
25
|
try {
|
|
25
26
|
await access(path, constants.X_OK);
|
|
@@ -62,6 +63,14 @@ export async function allowHouseInCodex(path) {
|
|
|
62
63
|
await rename(temporary, file);
|
|
63
64
|
}
|
|
64
65
|
async function nothing() { }
|
|
66
|
+
function claudeQuestionFields(request) {
|
|
67
|
+
const properties = request.requestedSchema?.properties ?? {};
|
|
68
|
+
return Object.keys(properties).filter((name) => properties[name]._meta?.jetbrains?.air?.customAnswer !== undefined);
|
|
69
|
+
}
|
|
70
|
+
function codexQuestionFields(request) {
|
|
71
|
+
const { _meta, requestedSchema } = request;
|
|
72
|
+
return _meta?.codex === undefined ? [] : (requestedSchema?.required ?? []);
|
|
73
|
+
}
|
|
65
74
|
function answered(error) {
|
|
66
75
|
return typeof error === 'object' && error !== null ? error : {};
|
|
67
76
|
}
|
|
@@ -71,7 +80,7 @@ function bridgeInClaudeSandbox(bridge) {
|
|
|
71
80
|
export const CLIS = {
|
|
72
81
|
'codex-acp': {
|
|
73
82
|
bin: 'codex',
|
|
74
|
-
minimum: '0.
|
|
83
|
+
minimum: '0.165.0',
|
|
75
84
|
install: 'curl -fsSL https://chatgpt.com/codex/install.sh | sh',
|
|
76
85
|
update: 'codex update',
|
|
77
86
|
adapter: {
|
|
@@ -87,15 +96,15 @@ export const CLIS = {
|
|
|
87
96
|
const { code, data } = answered(error);
|
|
88
97
|
return code === -32603 && typeof data?.details === 'string' && data.details.startsWith('no rollout found');
|
|
89
98
|
},
|
|
90
|
-
renames: true,
|
|
91
99
|
allowHouse: allowHouseInCodex,
|
|
100
|
+
questionFields: codexQuestionFields,
|
|
92
101
|
signedIn: { command: ['login', 'status'] },
|
|
93
102
|
login: { args: ['login', '--device-auth'], code: 'show' },
|
|
94
103
|
air: ['asyncTasks', 'nativeSubagentSessions'],
|
|
95
104
|
},
|
|
96
105
|
'claude-agent-acp': {
|
|
97
106
|
bin: 'claude',
|
|
98
|
-
minimum: '2.1.
|
|
107
|
+
minimum: '2.1.316',
|
|
99
108
|
install: 'curl -fsSL https://claude.ai/install.sh | bash',
|
|
100
109
|
update: 'claude update',
|
|
101
110
|
adapter: {
|
|
@@ -106,20 +115,19 @@ export const CLIS = {
|
|
|
106
115
|
},
|
|
107
116
|
args: [],
|
|
108
117
|
fullAccess: 'bypassPermissions',
|
|
109
|
-
sessionMeta: (bridge
|
|
118
|
+
sessionMeta: (bridge) => ({
|
|
110
119
|
claudeCode: {
|
|
111
120
|
options: {
|
|
112
121
|
allowedTools: ['Bash(house:*)'],
|
|
113
122
|
includeHookEvents: true,
|
|
114
|
-
title,
|
|
115
123
|
settings: { sandbox: { network: bridgeInClaudeSandbox(bridge) } },
|
|
116
124
|
},
|
|
117
|
-
emitRawSDKMessages: [...RAW_SUBTYPES.map((subtype) => ({ type: 'system', subtype })), { type
|
|
125
|
+
emitRawSDKMessages: [...RAW_SUBTYPES.map((subtype) => ({ type: 'system', subtype })), ...RAW_TYPES.map((type) => ({ type }))],
|
|
118
126
|
},
|
|
119
127
|
}),
|
|
120
128
|
unknownSession: (error) => answered(error).code === -32002,
|
|
121
|
-
renames: false,
|
|
122
129
|
allowHouse: nothing,
|
|
130
|
+
questionFields: claudeQuestionFields,
|
|
123
131
|
signedIn: { command: ['auth', 'status'] },
|
|
124
132
|
login: { args: ['auth', 'login', '--claudeai'], code: 'collect', rejected: 'Invalid code' },
|
|
125
133
|
air: ['asyncTasks', 'sessionFailure'],
|
|
@@ -134,8 +142,8 @@ export const CLIS = {
|
|
|
134
142
|
fullAccess: null,
|
|
135
143
|
sessionMeta: () => ({}),
|
|
136
144
|
unknownSession: (error) => answered(error).data?.code === 'FS_NOT_FOUND',
|
|
137
|
-
renames: false,
|
|
138
145
|
allowHouse: nothing,
|
|
146
|
+
questionFields: () => [],
|
|
139
147
|
signedIn: { initializeMeta: 'defaultAuthMethodId' },
|
|
140
148
|
login: { args: ['login', '--device-auth'], code: 'show' },
|
|
141
149
|
air: ['asyncTasks'],
|
package/dist/connection.js
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
|
+
import { KIT_CONNECTION_PATH, KIT_CONNECTION_PROTOCOL_PREFIX, KIT_WIRE, } from '@agentshouse/kit-wire';
|
|
1
2
|
import { subscribe } from 'node:diagnostics_channel';
|
|
3
|
+
import { setTimeout as delay } from 'node:timers/promises';
|
|
2
4
|
import { HouseRefusal, retryDelay } from './api.js';
|
|
3
5
|
import { end, REPLACED, signInAgain } from './end.js';
|
|
4
6
|
import { readEnrolment } from './home.js';
|
|
5
7
|
import { relayed } from './relay.js';
|
|
6
8
|
import { Silence } from './silence.js';
|
|
7
|
-
import { endUnserved,
|
|
8
|
-
const
|
|
9
|
-
const SUBPROTOCOL = `house.kit.stream.${KIT_WIRE}`;
|
|
9
|
+
import { endUnserved, unserved } from './wire.js';
|
|
10
|
+
const SUBPROTOCOL = `${KIT_CONNECTION_PROTOCOL_PREFIX}${KIT_WIRE}`;
|
|
10
11
|
const REFUSAL_HEADER = 'x-house-refusal';
|
|
11
12
|
// House beats each Kit connection every thirty seconds, so two silent beats mean this Kit process cannot hear House.
|
|
12
13
|
export const CONNECTION_SILENCE_MS = 60_000;
|
|
14
|
+
// A stopping Kit waits up to two seconds for House to answer its close, so what it sent last reaches House and a House that does not answer holds no stop.
|
|
15
|
+
const CLOSE_ANSWER_MS = 2_000;
|
|
13
16
|
function connectionUrl(house) {
|
|
14
|
-
const url = new URL(
|
|
17
|
+
const url = new URL(KIT_CONNECTION_PATH, house);
|
|
15
18
|
url.protocol = url.protocol === 'https:' ? 'wss:' : 'ws:';
|
|
16
19
|
return url;
|
|
17
20
|
}
|
|
@@ -25,17 +28,18 @@ function header(headers, name) {
|
|
|
25
28
|
let refused = null;
|
|
26
29
|
subscribe('undici:request:headers', (message) => {
|
|
27
30
|
const { request, response } = message;
|
|
28
|
-
if (!request.path.endsWith(
|
|
31
|
+
if (!request.path.endsWith(KIT_CONNECTION_PATH))
|
|
29
32
|
return;
|
|
30
|
-
refused = new HouseRefusal(
|
|
33
|
+
refused = new HouseRefusal(KIT_CONNECTION_PATH, response.statusCode, header(response.headers, REFUSAL_HEADER) || response.statusText);
|
|
31
34
|
});
|
|
32
35
|
export function holdConnection(handlers) {
|
|
33
36
|
let connection = null;
|
|
34
37
|
let socket = null;
|
|
35
38
|
let failures = 0;
|
|
39
|
+
let stopping = false;
|
|
36
40
|
const connect = async () => {
|
|
37
41
|
const { house, credential } = (await readEnrolment());
|
|
38
|
-
if (socket !== null || unserved())
|
|
42
|
+
if (socket !== null || unserved() || stopping)
|
|
39
43
|
return;
|
|
40
44
|
refused = null;
|
|
41
45
|
const opening = new WebSocket(relayed(connectionUrl(house)), {
|
|
@@ -54,6 +58,8 @@ export function holdConnection(handlers) {
|
|
|
54
58
|
connection = null;
|
|
55
59
|
handlers.closed();
|
|
56
60
|
process.stderr.write(`kit: connection closed ${event.code} ${event.reason}\n`);
|
|
61
|
+
if (stopping)
|
|
62
|
+
return;
|
|
57
63
|
if (event.reason === 'replaced')
|
|
58
64
|
end(REPLACED);
|
|
59
65
|
if (event.reason === 'credential_rejected' || refused?.status === 401) {
|
|
@@ -88,18 +94,27 @@ export function holdConnection(handlers) {
|
|
|
88
94
|
if (arrived.type === 'input')
|
|
89
95
|
handlers.call(arrived);
|
|
90
96
|
else if (arrived.type !== 'beat')
|
|
91
|
-
handlers.
|
|
97
|
+
handlers.oneWayCall(arrived);
|
|
92
98
|
};
|
|
93
99
|
opening.onerror = () => undefined;
|
|
94
100
|
opening.onclose = closed;
|
|
95
101
|
};
|
|
96
102
|
void connect();
|
|
97
103
|
return {
|
|
98
|
-
send(
|
|
104
|
+
send(oneWayCall) {
|
|
99
105
|
if (connection === null || connection.readyState !== WebSocket.OPEN)
|
|
100
106
|
return false;
|
|
101
|
-
connection.send(JSON.stringify(
|
|
107
|
+
connection.send(JSON.stringify(oneWayCall));
|
|
102
108
|
return true;
|
|
103
109
|
},
|
|
110
|
+
close() {
|
|
111
|
+
stopping = true;
|
|
112
|
+
const open = socket;
|
|
113
|
+
if (open === null)
|
|
114
|
+
return Promise.resolve();
|
|
115
|
+
const answered = new Promise((resolve) => open.addEventListener('close', () => resolve(), { once: true }));
|
|
116
|
+
open.close();
|
|
117
|
+
return Promise.race([answered, delay(CLOSE_ANSWER_MS)]);
|
|
118
|
+
},
|
|
104
119
|
};
|
|
105
120
|
}
|
package/dist/content.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { applied } from '@agentshouse/session-content';
|
|
2
|
+
function whole(part, parent) {
|
|
3
|
+
return { ...part, parent };
|
|
4
|
+
}
|
|
5
|
+
export class Content {
|
|
6
|
+
parts = [];
|
|
7
|
+
emit;
|
|
8
|
+
keys = new Map();
|
|
9
|
+
writing = new Map();
|
|
10
|
+
planned = null;
|
|
11
|
+
constructor(emit) {
|
|
12
|
+
this.emit = emit;
|
|
13
|
+
}
|
|
14
|
+
index(key) {
|
|
15
|
+
return this.keys.get(key);
|
|
16
|
+
}
|
|
17
|
+
write(type, id, parent, text) {
|
|
18
|
+
if (text === '')
|
|
19
|
+
return;
|
|
20
|
+
const writing = this.writing.get(parent);
|
|
21
|
+
if (writing?.type === type && writing.id === id) {
|
|
22
|
+
this.apply({ op: 'append', index: writing.index, text });
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const index = this.add(parent, { type, text });
|
|
26
|
+
this.writing.set(parent, { type, id, index });
|
|
27
|
+
}
|
|
28
|
+
put(key, parent, part) {
|
|
29
|
+
const index = this.keys.get(key);
|
|
30
|
+
if (index === undefined) {
|
|
31
|
+
const added = this.add(parent, part);
|
|
32
|
+
this.keys.set(key, added);
|
|
33
|
+
return added;
|
|
34
|
+
}
|
|
35
|
+
const changed = whole(part, this.parts[index].parent);
|
|
36
|
+
if (JSON.stringify(changed) !== JSON.stringify(this.parts[index]))
|
|
37
|
+
this.apply({ op: 'set', index, part: changed });
|
|
38
|
+
return index;
|
|
39
|
+
}
|
|
40
|
+
plan(entries) {
|
|
41
|
+
if (this.planned === null) {
|
|
42
|
+
this.planned = this.add(null, { type: 'plan', entries });
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
this.apply({ op: 'set', index: this.planned, part: { type: 'plan', parent: null, entries } });
|
|
46
|
+
}
|
|
47
|
+
add(parent, part) {
|
|
48
|
+
this.writing.delete(parent);
|
|
49
|
+
return this.arrived(parent, part);
|
|
50
|
+
}
|
|
51
|
+
arrived(parent, part) {
|
|
52
|
+
const index = this.parts.length;
|
|
53
|
+
this.apply({ op: 'start', index, part: whole(part, parent) });
|
|
54
|
+
return index;
|
|
55
|
+
}
|
|
56
|
+
operations() {
|
|
57
|
+
return this.parts.map((part, index) => ({ op: 'start', index, part }));
|
|
58
|
+
}
|
|
59
|
+
apply(operation) {
|
|
60
|
+
this.parts = applied(this.parts, operation);
|
|
61
|
+
this.emit(operation);
|
|
62
|
+
}
|
|
63
|
+
}
|