@agentshouse/kit 0.2.1-cf268dff1869b → 0.2.1-cf2c570b41f24
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 +18 -25
- package/dist/acp.js +12 -9
- package/dist/afk.js +17 -0
- package/dist/agents.js +72 -26
- package/dist/api.js +18 -4
- package/dist/binaries.js +60 -0
- package/dist/bridge.js +99 -44
- package/dist/calls.js +18 -1
- package/dist/chunks.js +54 -0
- package/dist/clis.js +33 -15
- package/dist/connect.js +121 -0
- package/dist/connection.js +25 -10
- package/dist/content.js +106 -0
- package/dist/conversations.js +251 -158
- package/dist/copies.js +1260 -599
- package/dist/earlier.js +273 -0
- package/dist/end.js +6 -9
- package/dist/events.js +544 -297
- package/dist/files.js +77 -11
- package/dist/git.js +0 -70
- package/dist/grok.js +39 -0
- package/dist/home.js +86 -22
- package/dist/house-cli.js +145 -162
- package/dist/instructions.js +2 -4
- package/dist/keys.js +238 -0
- package/dist/kit-cli.js +14 -4
- package/dist/login.js +34 -20
- package/dist/logout.js +2 -2
- package/dist/manifest.js +75 -0
- package/dist/mcp.js +43 -7
- package/dist/owner.js +46 -0
- package/dist/placement.js +0 -6
- package/dist/refusals.js +50 -23
- package/dist/resident.js +117 -76
- package/dist/scripts.js +79 -15
- package/dist/secret-input.js +1 -1
- package/dist/settings.js +247 -0
- package/dist/sign-in.js +49 -4
- package/dist/supervisor.js +163 -0
- package/dist/transcription.js +5 -2
- package/dist/update.js +31 -22
- package/dist/wire.js +2 -10
- package/dist/work.js +27 -2
- package/dist/workspace.js +113 -0
- package/package.json +12 -8
- package/dist/authority-main.js +0 -22
- package/dist/chatgpt.js +0 -32
- package/dist/configure-main.js +0 -6
- package/dist/enrol-main.js +0 -10
- package/dist/git-main.js +0 -153
- package/dist/parts.js +0 -82
- package/dist/service-main.js +0 -9
- package/dist/service.js +0 -55
- package/dist/translate.js +0 -45
package/README.md
CHANGED
|
@@ -6,50 +6,43 @@ your Agents' conversations through the agent CLIs you chose and gives each Agent
|
|
|
6
6
|
## Install
|
|
7
7
|
|
|
8
8
|
Run `sh -c 'kit=$(curl -fsSL "$0") || { echo "Kit could not be downloaded; run this command again." >&2; exit 1; }; eval "$kit"' agents.house/kit`,
|
|
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;
|
|
10
|
-
On macOS and Linux it installs Kit natively under your own account, without an admin password, as a
|
|
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 refuses the Kit that runs as too old or too new, 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.
|
|
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; `--code <code>` follows `agents.house/kit` to connect with a login code.
|
|
10
|
+
On macOS and Linux, a server included, it installs Kit natively under your own account, without an admin password, in one folder, `~/.agents/house`: Kit's own files at its top, its releases and their Node.js in `kit`, `kit` and `house` in `bin`, which it adds to your login shell's `PATH`, and its records of the Rooms' copies. Your workspace is `~/house`: each Room's copy in `rooms/<handle>`, so `cd ~/house/rooms/<handle>` and starting your agent CLI there starts it in that Room, and the Agents' folders in `agents`. It stops, changing nothing, where `~/.agents/house` holds something that is not Kit's. On Linux it adds a missing `ca-certificates`, `curl` or `git` through apt. Then `kit connect`, which stops in one line before it connects anything where `~/house` holds something and is not Kit's workspace, writing nothing there, keeps the Environment you connected, redeems the login code or prints a link you confirm, writes Kit's settings where `kit.json` has none, places House's Skills and starts Kit: as a systemd user unit that starts at boot through lingering on Linux, and as a LaunchAgent on macOS. On a Linux without systemd it starts nothing: run the `kit resident` command it prints under your own service manager, restarting it whenever it ends with a failure. One account runs one Kit for one Building; to move it to another, run `kit logout` and then the other Building's command.
|
|
13
11
|
|
|
14
|
-
|
|
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,
|
|
16
|
-
Kit home is the Docker volume `house-kit-home` and the container is the one choice. Append a `kit` or `house` command to the container's options to run it in that container.
|
|
17
|
-
Running the command for the other choice on a connected computer asks you to
|
|
18
|
-
confirm, then replaces its Environment, whose Agents end, with a new one. Running it with a different `HOUSE_KIT_HOME`
|
|
19
|
-
from the running Kit process asks you to confirm before it replaces that process, and leaves the earlier Kit home as it was.
|
|
12
|
+
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 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.
|
|
20
13
|
|
|
21
|
-
|
|
14
|
+
A Kit installed before moves itself into `~/.agents/house` on its next update, a Mac's or a Linux desktop's and one running as root; one in a container or under a system unit of another account asks you, on its Environment's page, to run the install command again on that computer, which moves it and removes the container or the unit, keeping its Environment.
|
|
22
15
|
|
|
23
|
-
|
|
16
|
+
On Windows the command, run in PowerShell, installs WSL where it is absent, asking you to restart only where Windows needs that and to run the command again after, and Ubuntu where WSL has none, with a default user named after yours; it turns on WSL's Keep WSL running, starts Ubuntu, with no window, when you sign in, and installs Kit inside Ubuntu as on Linux. The Linux command run in a WSL terminal recommends the Windows command instead and installs and starts Kit there only once you agree that it then runs only while a WSL terminal is open, and not after a restart; with no terminal to ask in, it installs nothing and names the Windows command. A Kit that ran in Docker Desktop's `house-kit` container moves into Ubuntu as the same Environment, its workspace kept where it was, and the command removes the container, keeping its volume.
|
|
17
|
+
|
|
18
|
+
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 macOS older than 13.5 and a Linux without glibc 2.28 or newer.
|
|
24
19
|
|
|
25
20
|
Kit runs each agent CLI through the link your login shell finds and installs a missing one through that CLI's own
|
|
26
21
|
installer. When it starts and regularly after, Kit runs each CLI's own update command, such as `claude update`, beside
|
|
27
22
|
your conversations: a running conversation keeps its version and the next one runs the new release. A CLI older than
|
|
28
23
|
the oldest release Kit is built for still runs, though its conversations may fail: Kit tells House its version, that
|
|
29
24
|
oldest release and its update command. Kit also gives every Agent on the Environment the agent skills of
|
|
30
|
-
`@agentshouse/skills`, at the version each Kit release installs
|
|
25
|
+
`@agentshouse/skills`, at the version each Kit release installs, unless its `skills` setting is off.
|
|
26
|
+
An API key you give a CLI on House's page, with an endpoint for another provider, goes into that CLI's own settings on
|
|
27
|
+
this computer, where you use the CLI too: Claude Code's `settings.json`, or Codex's login and `config.toml`. Grok Build
|
|
28
|
+
has no setting for a key that serves all its models, so Kit keeps its key in `~/.agents/house/grok-key.json` and sets
|
|
29
|
+
it, with the endpoint, as `XAI_API_KEY` and `GROK_MODELS_BASE_URL` on the Grok Build it runs, never on yours.
|
|
31
30
|
|
|
32
31
|
## Commands
|
|
33
32
|
|
|
34
|
-
`kit login` opens or prints a link you confirm in any browser, on this computer
|
|
35
|
-
or another, continues on its own and keeps the Environment's credential in
|
|
36
|
-
`$HOUSE_KIT_HOME` when it is set, else in `~/.house-kit`, or in `house-kit-<uid>` under the temporary directory when your home is read-only. `--environment <id>`
|
|
37
|
-
reconnects an Environment you already have; `--rooms <ref>[,<ref>...]` gives it
|
|
38
|
-
only those Rooms and `--no-private` every Room but your Private Room; `--code <code>` connects immediately without a link.
|
|
33
|
+
`kit login` opens or prints a link you confirm in any browser, on this computer or another, continues on its own and keeps the Environment's credential in `~/.agents/house`. `--environment <id>` reconnects an Environment you already have, which keeps its Rooms: its page in House changes them. A new Environment takes `--rooms <ref>[,<ref>...]` for only those Rooms and `--no-private` for every Room but your Private Room; `--code <code>` connects immediately without a link.
|
|
39
34
|
A login also connects your own agent: outside an Agent conversation, `house <tool>` calls
|
|
40
35
|
House as you and `git` clones and pushes your Apps at `<house>/app/` as you, each through the Kit
|
|
41
|
-
home
|
|
36
|
+
home of the account it runs as, 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
37
|
login run a lone `house` command outside their sandbox. `kit logout` disconnects this
|
|
43
38
|
computer, stops the Kit process and ends your own agent's connection, so `house` and `git` no
|
|
44
39
|
longer act as you here; a later `kit login` reconnects the same Environment, or connects
|
|
45
40
|
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
41
|
|
|
48
|
-
`kit
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
`
|
|
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.
|
|
42
|
+
`kit settings` prints Kit's two settings, which every update and every rerun of the install keep: `skills`, whether Kit places House's Skills, and `workspace`, the folder that holds `rooms` and `agents`, `~/house` unless you set another. `kit settings skills on|off` and `kit settings workspace <absolute path>` change one, as the Environment's page in House does.
|
|
43
|
+
A new workspace must hold no `rooms` or `agents` folder, and none is taken while an Agent works; Kit then ends its conversations' processes, moves both folders there, across filesystems copying and checking them before it deletes the old ones, and ends so its service starts it there.
|
|
44
|
+
|
|
45
|
+
`kit resident` keeps the Environment connected and, as it connects, copies the text of each Room you chose for it into a plain folder named by its handle in the workspace's `rooms`, beside a hidden `.house` file recording each file's revision and SHA-256, renames the folder with everything in it when the Room's handle changes, and keeps a Room's copy as it is, no longer refreshing it, once the Room may no longer be copied here; where another Room's folder is to take its name, it first renames that copy's folder to the name with ` (kept)`, adding ` 2` and on where that is taken. `house download` brings House's changes into each copy, overwriting only files unchanged here, and with `--with-attachments` the attachments it lacks up to `--max-size` megabytes, 10 by default. `house upload --owner`, run in a copy, sends every file changed, added or deleted there; House merges a change made on an older revision, and a clash leaves conflict markers in the file to resolve before the next upload; an `AGENTS.md` or `CLAUDE.md` at a copy's top, whatever its case, is Kit's and never sent. An Agent runs both, without `--owner`. With a JSON argument, `house upload` and `house download` move one file between disk and a Room, and a broken upload resumes on its own. A copy made by an earlier Kit keeps its files and its `.git`, which Kit no longer reads. A Kit that kept its workspace in `~/.agents/house` moves it to `~/house` at its first start on this release, each copy with every file to `rooms/<handle>`, a copy it no longer follows to `rooms/<reference> (kept)`, and ends so its service starts it there; a workspace you set elsewhere, or one whose `~/house` holds something else, stays where it is and takes the same layout.
|
|
53
46
|
|
|
54
47
|
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
48
|
|
package/dist/acp.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
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 } from './clis.js';
|
|
5
|
-
import { childEnvironment } from './relay.js';
|
|
4
|
+
import { CLIS, KIT_RELEASE, adapterCommand, cliEnvironment } from './clis.js';
|
|
6
5
|
import { killTree } from './scope.js';
|
|
7
6
|
import { Silence } from './silence.js';
|
|
8
7
|
const RETIRED = 'the CLI was retired';
|
|
@@ -13,13 +12,13 @@ export function signedOut(error) {
|
|
|
13
12
|
// 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
13
|
export const CLI_SILENCE_MS = 30 * 60_000;
|
|
15
14
|
const SILENT = `the CLI sent nothing for ${CLI_SILENCE_MS / 60_000} minutes`;
|
|
16
|
-
export async function startAdapter(kind, cli, cwd, app, events = () =>
|
|
15
|
+
export async function startAdapter(kind, cli, cwd, app, events = () => null, added = {}, signal, scope = null) {
|
|
17
16
|
const adapter = CLIS[kind].adapter;
|
|
18
17
|
const started = [adapter === null ? cli : adapterCommand(kind), CLIS[kind].args];
|
|
19
18
|
const [command, args] = scope?.command(...started) ?? started;
|
|
20
19
|
const child = spawn(command, args, {
|
|
21
20
|
cwd,
|
|
22
|
-
env: { ...
|
|
21
|
+
env: { ...(await cliEnvironment(kind)), ...(adapter === null ? {} : { ...adapter.env, [adapter.executable]: cli }), ...added },
|
|
23
22
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
24
23
|
detached: true,
|
|
25
24
|
});
|
|
@@ -69,11 +68,15 @@ export async function startAdapter(kind, cli, cwd, app, events = () => undefined
|
|
|
69
68
|
asked.add(read.id);
|
|
70
69
|
}
|
|
71
70
|
watch();
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
71
|
+
const held = owned ? events(read) : null;
|
|
72
|
+
const pass = () => {
|
|
73
|
+
if (read.id !== undefined || (read.method !== 'session/update' && !read.method.startsWith('_'))) {
|
|
74
|
+
controller.enqueue(message);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
if (held === null)
|
|
78
|
+
return pass();
|
|
79
|
+
return held.then(pass);
|
|
77
80
|
},
|
|
78
81
|
})),
|
|
79
82
|
});
|
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,20 @@
|
|
|
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
|
-
import { CLIS, KIT_RELEASE, below, installCli, locate, run, updateCli, versionOf } from './clis.js';
|
|
6
|
-
import { agentBase, kitHome } from './home.js';
|
|
6
|
+
import { CLIS, KIT_RELEASE, below, cliEnvironment, installCli, locate, run, updateCli, versionOf } from './clis.js';
|
|
7
|
+
import { agentBase, kitHome, reinstall } from './home.js';
|
|
8
|
+
import { heldSettings } from './settings.js';
|
|
7
9
|
import { holdTranscription, transcriptionReport } from './transcription.js';
|
|
8
|
-
import { KIT_WIRE } from './wire.js';
|
|
9
10
|
// Two quiet seconds let a fresh conversation start before background model discovery competes for its CPU.
|
|
10
11
|
const MODEL_PROBE_QUIET_MS = 2_000;
|
|
11
12
|
// 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
13
|
export const CLI_UPDATE_MS = 60 * 60_000;
|
|
13
14
|
// 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
15
|
const SIGNED_IN_READ_MS = 10_000;
|
|
15
|
-
const
|
|
16
|
+
const UNNAMED = { default_model: null, default_effort: null };
|
|
17
|
+
const SIGNED_OUT = { signed_in: false, models: [], ...UNNAMED, modes: [] };
|
|
16
18
|
const INSTALLING = { release: null, failure: null, installing: true, ...SIGNED_OUT };
|
|
17
19
|
function select(options, category) {
|
|
18
20
|
const option = options.find((candidate) => candidate.category === category);
|
|
@@ -24,6 +26,22 @@ function choices(options) {
|
|
|
24
26
|
function values(options) {
|
|
25
27
|
return choices(options).map((entry) => entry.value);
|
|
26
28
|
}
|
|
29
|
+
const CLI_DEFAULT = 'default';
|
|
30
|
+
function effortsOf(option) {
|
|
31
|
+
return option === undefined ? [] : values(option.options).filter((value) => value !== CLI_DEFAULT);
|
|
32
|
+
}
|
|
33
|
+
function named(options) {
|
|
34
|
+
const listed = choices(options).filter((entry) => entry.value !== CLI_DEFAULT);
|
|
35
|
+
return listed.filter((entry, at) => listed.findIndex((first) => first.name === entry.name) === at);
|
|
36
|
+
}
|
|
37
|
+
function starting(model, effort) {
|
|
38
|
+
const current = choices(model.options).find((entry) => entry.value === model.currentValue);
|
|
39
|
+
const name = current?.value === CLI_DEFAULT ? current.description : current?.name;
|
|
40
|
+
return {
|
|
41
|
+
default_model: named(model.options).find((entry) => entry.name === name)?.value ?? null,
|
|
42
|
+
default_effort: effort === undefined || effort.currentValue === CLI_DEFAULT ? null : effort.currentValue,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
27
45
|
function causeOf(error) {
|
|
28
46
|
return error instanceof Error ? error.message : String(error);
|
|
29
47
|
}
|
|
@@ -54,23 +72,23 @@ async function models(kind, adapter, known) {
|
|
|
54
72
|
const modes = mode === undefined ? [] : choices(mode.options).map(({ value, name }) => ({ mode: value, name }));
|
|
55
73
|
const model = select(options, 'model');
|
|
56
74
|
if (model === undefined)
|
|
57
|
-
return { models: [], modes };
|
|
75
|
+
return { models: [], ...UNNAMED, modes };
|
|
76
|
+
const started = starting(model, select(options, 'thought_level'));
|
|
58
77
|
const offered = [];
|
|
59
|
-
for (const value of
|
|
78
|
+
for (const { value, name } of named(model.options)) {
|
|
60
79
|
if (select(options, 'model')?.currentValue !== value) {
|
|
61
80
|
try {
|
|
62
81
|
options = (await agent.request('session/set_config_option', { sessionId: opened.sessionId, configId: model.id, value })).configOptions;
|
|
63
82
|
}
|
|
64
83
|
catch (error) {
|
|
65
84
|
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 ?? [] });
|
|
85
|
+
offered.push({ model: value, name, efforts: known.find((entry) => entry.model === value)?.efforts ?? [] });
|
|
67
86
|
continue;
|
|
68
87
|
}
|
|
69
88
|
}
|
|
70
|
-
|
|
71
|
-
offered.push({ model: value, efforts: effort === undefined ? [] : values(effort.options) });
|
|
89
|
+
offered.push({ model: value, name, efforts: effortsOf(select(options, 'thought_level')) });
|
|
72
90
|
}
|
|
73
|
-
return { models: offered, modes };
|
|
91
|
+
return { models: offered, ...started, modes };
|
|
74
92
|
}
|
|
75
93
|
function ended(signal) {
|
|
76
94
|
return new Promise((_, reject) => {
|
|
@@ -79,30 +97,41 @@ function ended(signal) {
|
|
|
79
97
|
signal.addEventListener('abort', () => reject(signal.reason), { once: true });
|
|
80
98
|
});
|
|
81
99
|
}
|
|
100
|
+
function keyedOf({ api_key, provider }) {
|
|
101
|
+
return { ...(api_key === undefined ? {} : { api_key }), ...(provider === undefined ? {} : { provider }) };
|
|
102
|
+
}
|
|
82
103
|
async function offer(kind, cli, known, signal) {
|
|
83
|
-
const probe = CLIS[kind]
|
|
104
|
+
const { signedIn: probe, key } = CLIS[kind];
|
|
105
|
+
const keyed = await key.read();
|
|
84
106
|
// A sign-in check that has not answered in half a minute counts as signed out rather than stalling the report.
|
|
85
|
-
if ('command' in probe && (await run(cli, probe.command, 30_000, false, signal)).status !== 0)
|
|
86
|
-
return SIGNED_OUT;
|
|
107
|
+
if ('command' in probe && !keyed.api_key && (await run(cli, probe.command, 30_000, false, signal, await cliEnvironment(kind))).status !== 0) {
|
|
108
|
+
return { ...SIGNED_OUT, ...keyed };
|
|
109
|
+
}
|
|
87
110
|
let adapter;
|
|
88
111
|
try {
|
|
89
|
-
adapter = await startAdapter(kind, cli, kitHome(), client({ name: '@agentshouse/kit' }), () =>
|
|
112
|
+
adapter = await startAdapter(kind, cli, kitHome(), client({ name: '@agentshouse/kit' }), () => null, {}, signal);
|
|
90
113
|
signal?.throwIfAborted();
|
|
91
114
|
if ('initializeMeta' in probe) {
|
|
92
115
|
const method = adapter.initialized._meta?.[probe.initializeMeta];
|
|
93
116
|
if (typeof method !== 'string' || method.length === 0)
|
|
94
|
-
return SIGNED_OUT;
|
|
117
|
+
return { ...SIGNED_OUT, ...keyed };
|
|
118
|
+
if (method === probe.apiKey)
|
|
119
|
+
keyed.api_key = true;
|
|
95
120
|
}
|
|
96
|
-
return { signed_in: true, ...(await models(kind, adapter, known.models)) };
|
|
121
|
+
return { signed_in: true, ...keyed, ...(await models(kind, adapter, known.models)) };
|
|
97
122
|
}
|
|
98
123
|
catch (error) {
|
|
99
124
|
if (!signal?.aborted)
|
|
100
125
|
process.stderr.write(`kit: ${kind} did not offer its models: ${causeOf(error)}\n`);
|
|
101
126
|
if (signedOut(error))
|
|
102
|
-
return SIGNED_OUT;
|
|
127
|
+
return { ...SIGNED_OUT, ...keyed };
|
|
128
|
+
const unread = adapter === undefined && 'initializeMeta' in probe;
|
|
103
129
|
return {
|
|
104
|
-
signed_in:
|
|
130
|
+
signed_in: unread ? known.signed_in : true,
|
|
131
|
+
...keyedOf({ api_key: unread ? known.api_key : keyed.api_key, provider: keyed.provider }),
|
|
105
132
|
models: known.models,
|
|
133
|
+
default_model: known.default_model,
|
|
134
|
+
default_effort: known.default_effort,
|
|
106
135
|
modes: known.modes,
|
|
107
136
|
};
|
|
108
137
|
}
|
|
@@ -119,9 +148,12 @@ function reported(kind, reading) {
|
|
|
119
148
|
failure: reading.failure,
|
|
120
149
|
...(reading.installing === undefined ? {} : { installing: reading.installing }),
|
|
121
150
|
signed_in: reading.signed_in,
|
|
151
|
+
...keyedOf(reading),
|
|
122
152
|
models: reading.models,
|
|
123
153
|
modes: reading.modes,
|
|
124
154
|
full_access: CLIS[kind].fullAccess,
|
|
155
|
+
...(reading.default_model === null ? {} : { default_model: reading.default_model }),
|
|
156
|
+
...(reading.default_effort === null ? {} : { default_effort: reading.default_effort }),
|
|
125
157
|
};
|
|
126
158
|
}
|
|
127
159
|
const NOT_READY = "the Agent's CLI is not ready on this computer";
|
|
@@ -186,7 +218,7 @@ export class Agents {
|
|
|
186
218
|
this.refreshing++;
|
|
187
219
|
this.changed();
|
|
188
220
|
const reading = this.read().then(async () => {
|
|
189
|
-
this.desired = await this.house.deliver('
|
|
221
|
+
this.desired = await this.house.deliver('agents/desired/list', {});
|
|
190
222
|
return this.desired;
|
|
191
223
|
});
|
|
192
224
|
this.reading = reading;
|
|
@@ -206,9 +238,12 @@ export class Agents {
|
|
|
206
238
|
});
|
|
207
239
|
return reading.then(() => undefined);
|
|
208
240
|
}
|
|
209
|
-
keepCurrent() {
|
|
241
|
+
keepCurrent(stopping) {
|
|
210
242
|
this.updateAll(this.loaded);
|
|
211
|
-
setInterval(() =>
|
|
243
|
+
setInterval(() => {
|
|
244
|
+
if (!stopping())
|
|
245
|
+
this.updateAll(Promise.resolve());
|
|
246
|
+
}, CLI_UPDATE_MS);
|
|
212
247
|
}
|
|
213
248
|
cli(kind) {
|
|
214
249
|
this.starts += 1;
|
|
@@ -222,14 +257,23 @@ export class Agents {
|
|
|
222
257
|
const known = this.readings.get(kind);
|
|
223
258
|
const kept = known?.release === null ? SIGNED_OUT : (known ?? SIGNED_OUT);
|
|
224
259
|
if (known?.release !== release || this.installs.has(kind)) {
|
|
225
|
-
this.update(kind, {
|
|
260
|
+
this.update(kind, {
|
|
261
|
+
release,
|
|
262
|
+
failure: null,
|
|
263
|
+
signed_in: kept.signed_in,
|
|
264
|
+
...keyedOf(kept),
|
|
265
|
+
models: kept.models,
|
|
266
|
+
default_model: kept.default_model,
|
|
267
|
+
default_effort: kept.default_effort,
|
|
268
|
+
modes: kept.modes,
|
|
269
|
+
});
|
|
226
270
|
}
|
|
227
271
|
const read = this.nextRead(kind);
|
|
228
272
|
this.quietOffer(kind, cli, kept)
|
|
229
273
|
.then((offered) => {
|
|
230
274
|
const current = this.readings.get(kind);
|
|
231
275
|
if (this.reads.get(kind) === read && current?.release === release)
|
|
232
|
-
this.update(kind, {
|
|
276
|
+
this.update(kind, { release, failure: current.failure, ...offered });
|
|
233
277
|
})
|
|
234
278
|
.catch(logged);
|
|
235
279
|
return cli;
|
|
@@ -313,7 +357,7 @@ export class Agents {
|
|
|
313
357
|
process.stderr.write(`kit: ${kind} did not install: ${failure}\n`);
|
|
314
358
|
return { release: null, failure, ...SIGNED_OUT };
|
|
315
359
|
}
|
|
316
|
-
const release = await versionOf(cli, signal);
|
|
360
|
+
const release = await versionOf(kind, cli, signal);
|
|
317
361
|
if (release === null)
|
|
318
362
|
return { release: null, failure: `${cli} --version names no version`, ...SIGNED_OUT };
|
|
319
363
|
return { cli, release };
|
|
@@ -348,7 +392,7 @@ export class Agents {
|
|
|
348
392
|
}
|
|
349
393
|
async readVersion(kind) {
|
|
350
394
|
const cli = await locate(kind);
|
|
351
|
-
const release = cli === null ? null : await versionOf(cli);
|
|
395
|
+
const release = cli === null ? null : await versionOf(kind, cli);
|
|
352
396
|
const current = this.readings.get(kind);
|
|
353
397
|
if (release === null || !current?.release || current.release === release)
|
|
354
398
|
return;
|
|
@@ -381,6 +425,8 @@ export class Agents {
|
|
|
381
425
|
kit_release: KIT_RELEASE,
|
|
382
426
|
wire: KIT_WIRE,
|
|
383
427
|
agent_base: agentBase(),
|
|
428
|
+
...(reinstall() === undefined ? {} : { reinstall: reinstall() }),
|
|
429
|
+
settings: await heldSettings(),
|
|
384
430
|
agents,
|
|
385
431
|
transcription: transcriptionReport(),
|
|
386
432
|
...(hostKey === null ? {} : { ssh_host_key: hostKey }),
|
|
@@ -388,7 +434,7 @@ export class Agents {
|
|
|
388
434
|
const state = JSON.stringify(body);
|
|
389
435
|
if (state === this.sent)
|
|
390
436
|
return;
|
|
391
|
-
await this.house.deliver('
|
|
437
|
+
await this.house.deliver('agents/report', body);
|
|
392
438
|
this.sent = state;
|
|
393
439
|
}
|
|
394
440
|
}
|
package/dist/api.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { KIT_WIRE, KIT_WIRE_HEADER, kitActRoute, } 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,14 @@ 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
|
+
const { path, body } = routed(act, request);
|
|
57
|
+
return post(house, path, body, credential, signal);
|
|
58
|
+
}
|
|
59
|
+
function routed(act, request) {
|
|
60
|
+
const { path, op } = kitActRoute(act);
|
|
61
|
+
return { path, body: op === null ? request : { op, ...request } };
|
|
62
|
+
}
|
|
54
63
|
async function enrolledPost(path, body, signal) {
|
|
55
64
|
const { house, credential } = (await readEnrolment());
|
|
56
65
|
try {
|
|
@@ -63,8 +72,13 @@ async function enrolledPost(path, body, signal) {
|
|
|
63
72
|
}
|
|
64
73
|
}
|
|
65
74
|
export const house = {
|
|
66
|
-
|
|
67
|
-
|
|
75
|
+
act: (act, request, signal) => {
|
|
76
|
+
const { path, body } = routed(act, request);
|
|
77
|
+
return enrolledPost(path, body, signal);
|
|
78
|
+
},
|
|
79
|
+
door: (act, body, signal) => enrolledPost(`/kit/door/${act}`, body, signal),
|
|
80
|
+
deliver: async (act, request, current = () => true) => {
|
|
81
|
+
const { path, body } = routed(act, request);
|
|
68
82
|
for (let attempt = 0;; attempt++) {
|
|
69
83
|
try {
|
|
70
84
|
return await enrolledPost(path, body);
|
package/dist/binaries.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { copyFile, rm } from 'node:fs/promises';
|
|
3
|
+
import { downloaded, fetched, fileRange, mediaTypeOf, sentPart, uploaded } from './files.js';
|
|
4
|
+
import { hashed } from './manifest.js';
|
|
5
|
+
export class Changed extends Error {
|
|
6
|
+
}
|
|
7
|
+
const SENT_AT_ONCE = 10;
|
|
8
|
+
const OCTET_STREAM = 'application/octet-stream';
|
|
9
|
+
const MARKDOWN = /\.md$/i;
|
|
10
|
+
const STORE = {
|
|
11
|
+
unreached: (error) => new Error(`the store did not answer (${error.code ?? error.message})`),
|
|
12
|
+
refused: (status) => new Error(`the store answered ${status}`),
|
|
13
|
+
};
|
|
14
|
+
export function isDocument(path) {
|
|
15
|
+
return MARKDOWN.test(path);
|
|
16
|
+
}
|
|
17
|
+
export function mediaType(path) {
|
|
18
|
+
return mediaTypeOf(path) ?? OCTET_STREAM;
|
|
19
|
+
}
|
|
20
|
+
export async function eachAtOnce(items, work) {
|
|
21
|
+
let next = 0;
|
|
22
|
+
const working = async () => {
|
|
23
|
+
while (next < items.length)
|
|
24
|
+
await work(items[next++]);
|
|
25
|
+
};
|
|
26
|
+
await Promise.all(Array.from({ length: Math.min(SENT_AT_ONCE, items.length) }, working));
|
|
27
|
+
}
|
|
28
|
+
export async function sentBinary(staging, file, name, part, upload, finish) {
|
|
29
|
+
const copy = `${staging}${randomUUID()}`;
|
|
30
|
+
try {
|
|
31
|
+
await copyFile(file, copy).catch(() => {
|
|
32
|
+
throw new Changed(`${name} is gone since house upload read it`);
|
|
33
|
+
});
|
|
34
|
+
const held = await hashed(copy);
|
|
35
|
+
if (held?.sha256 !== part.sha256 || held.bytes !== part.bytes)
|
|
36
|
+
throw new Changed(`${name} changed since house upload read it`);
|
|
37
|
+
await uploaded({ id: upload.id, part_bytes: upload.part_bytes }, {
|
|
38
|
+
name,
|
|
39
|
+
bytes: part.bytes,
|
|
40
|
+
sha256: part.sha256,
|
|
41
|
+
read: (start, end) => fileRange(copy, start, end, (error) => error),
|
|
42
|
+
send: (url, start, end, headers) => sentPart(url, copy, start, end, headers, STORE),
|
|
43
|
+
finish,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
finally {
|
|
47
|
+
await rm(copy, { force: true });
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
export async function receivedBinary(staging, name, address) {
|
|
51
|
+
const file = `${staging}${randomUUID()}`;
|
|
52
|
+
try {
|
|
53
|
+
await downloaded(address, (url) => fetched(url), file, name);
|
|
54
|
+
return file;
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
await rm(file, { force: true });
|
|
58
|
+
throw error;
|
|
59
|
+
}
|
|
60
|
+
}
|