@agentshouse/kit 0.2.1-cf110d15f69c8 → 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 +38 -44
- package/dist/acp.js +96 -22
- package/dist/afk.js +17 -0
- package/dist/agents.js +221 -65
- package/dist/api.js +21 -3
- package/dist/app-git.js +10 -26
- package/dist/binaries.js +60 -0
- package/dist/bridge.js +101 -49
- package/dist/building.js +50 -0
- package/dist/calls.js +88 -0
- package/dist/chunks.js +54 -0
- package/dist/clis.js +80 -52
- package/dist/connect.js +121 -0
- package/dist/connection.js +120 -0
- package/dist/content.js +106 -0
- package/dist/conversations.js +711 -267
- package/dist/copies.js +1293 -595
- package/dist/earlier.js +273 -0
- package/dist/end.js +15 -3
- package/dist/events.js +553 -281
- package/dist/files.js +206 -32
- package/dist/git.js +2 -70
- package/dist/grok.js +39 -0
- package/dist/home.js +123 -15
- package/dist/house-cli.js +282 -0
- package/dist/house-main.js +7 -206
- package/dist/instructions.js +7 -13
- package/dist/keys.js +238 -0
- package/dist/kit-cli.js +78 -0
- package/dist/kit-main.js +8 -22
- package/dist/login.js +71 -39
- package/dist/logout.js +2 -4
- package/dist/manifest.js +75 -0
- package/dist/mcp.js +47 -7
- package/dist/owner.js +46 -0
- package/dist/placement.js +25 -0
- package/dist/refusals.js +50 -23
- package/dist/relay.js +22 -1
- package/dist/resident.js +153 -53
- package/dist/scope.js +15 -4
- package/dist/scripts.js +319 -0
- package/dist/secret-input.js +1 -1
- package/dist/settings.js +247 -0
- package/dist/sign-in.js +66 -38
- package/dist/silence.js +28 -0
- package/dist/skills.js +49 -35
- package/dist/supervisor.js +163 -0
- package/dist/transcription.js +90 -47
- package/dist/update.js +119 -102
- package/dist/wire.js +32 -0
- package/dist/work.js +30 -7
- package/dist/workspace.js +113 -0
- package/package.json +25 -21
- package/dist/authority-main.js +0 -22
- package/dist/bootstrap.json +0 -24
- package/dist/clis-main.js +0 -23
- 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 -33
- package/dist/stream.js +0 -74
- package/dist/translate.js +0 -51
- package/how-we-work.md +0 -23
- package/skills/ask-matt/LICENSE +0 -21
- package/skills/ask-matt/PHASE-BOUNDARIES.md +0 -55
- package/skills/ask-matt/SKILL.md +0 -91
- package/skills/ask-matt/agents/openai.yaml +0 -4
- 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 -116
- package/skills/codebase-design/agents/openai.yaml +0 -3
- package/skills/diagnosing-bugs/LICENSE +0 -21
- package/skills/diagnosing-bugs/SKILL.md +0 -140
- 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/CONTEXT-FORMAT.md +0 -60
- package/skills/domain-modeling/LICENSE +0 -21
- package/skills/domain-modeling/SKILL.md +0 -76
- package/skills/domain-modeling/agents/openai.yaml +0 -3
- package/skills/grill-me/LICENSE +0 -21
- package/skills/grill-me/SKILL.md +0 -8
- package/skills/grill-me/agents/openai.yaml +0 -4
- package/skills/grill-with-docs/LICENSE +0 -21
- package/skills/grill-with-docs/SKILL.md +0 -8
- package/skills/grill-with-docs/agents/openai.yaml +0 -4
- 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 -17
- package/skills/handoff/agents/openai.yaml +0 -4
- package/skills/implement/LICENSE +0 -21
- package/skills/implement/SKILL.md +0 -16
- package/skills/implement/agents/openai.yaml +0 -4
- 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 -72
- package/skills/improve-codebase-architecture/agents/openai.yaml +0 -4
- package/skills/prototype/LICENSE +0 -21
- package/skills/prototype/LOGIC.md +0 -67
- package/skills/prototype/SKILL.md +0 -28
- 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 -14
- package/skills/research/agents/openai.yaml +0 -3
- package/skills/resolving-merge-conflicts/LICENSE +0 -21
- package/skills/resolving-merge-conflicts/SKILL.md +0 -16
- package/skills/resolving-merge-conflicts/agents/openai.yaml +0 -3
- package/skills/tdd/LICENSE +0 -21
- package/skills/tdd/SKILL.md +0 -40
- 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 -141
- package/skills/teach/agents/openai.yaml +0 -4
- package/skills/to-questionnaire/LICENSE +0 -21
- package/skills/to-questionnaire/SKILL.md +0 -55
- package/skills/to-questionnaire/agents/openai.yaml +0 -4
- package/skills/to-spec/LICENSE +0 -21
- package/skills/to-spec/SKILL.md +0 -76
- package/skills/to-spec/agents/openai.yaml +0 -4
- package/skills/to-tickets/LICENSE +0 -21
- package/skills/to-tickets/SKILL.md +0 -106
- package/skills/to-tickets/agents/openai.yaml +0 -4
- package/skills/wait-what/LICENSE +0 -21
- package/skills/wait-what/SKILL.md +0 -8
- package/skills/wait-what/agents/openai.yaml +0 -4
- package/skills/wayfinder/LICENSE +0 -21
- package/skills/wayfinder/SKILL.md +0 -129
- package/skills/wayfinder/agents/openai.yaml +0 -4
- 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 -83
- package/skills/writing-for-agents/agents/openai.yaml +0 -3
package/dist/agents.js
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
import { client } from '@agentclientprotocol/sdk';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
2
|
+
import { KIT_WIRE } from '@agentshouse/kit-wire';
|
|
3
|
+
import { readFile } from 'node:fs/promises';
|
|
4
|
+
import { setTimeout as delay } from 'node:timers/promises';
|
|
5
|
+
import { signedOut, startAdapter } from './acp.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
|
-
|
|
10
|
+
// Two quiet seconds let a fresh conversation start before background model discovery competes for its CPU.
|
|
11
|
+
const MODEL_PROBE_QUIET_MS = 2_000;
|
|
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.
|
|
13
|
+
export const CLI_UPDATE_MS = 60 * 60_000;
|
|
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.
|
|
15
|
+
const SIGNED_IN_READ_MS = 10_000;
|
|
16
|
+
const UNNAMED = { default_model: null, default_effort: null };
|
|
17
|
+
const SIGNED_OUT = { signed_in: false, models: [], ...UNNAMED, modes: [] };
|
|
18
|
+
const INSTALLING = { release: null, failure: null, installing: true, ...SIGNED_OUT };
|
|
9
19
|
function select(options, category) {
|
|
10
20
|
const option = options.find((candidate) => candidate.category === category);
|
|
11
21
|
return option?.type === 'select' ? option : undefined;
|
|
@@ -16,12 +26,44 @@ function choices(options) {
|
|
|
16
26
|
function values(options) {
|
|
17
27
|
return choices(options).map((entry) => entry.value);
|
|
18
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
|
+
}
|
|
19
45
|
function causeOf(error) {
|
|
20
46
|
return error instanceof Error ? error.message : String(error);
|
|
21
47
|
}
|
|
22
48
|
function logged(error) {
|
|
23
49
|
process.stderr.write(`kit: ${causeOf(error)}\n`);
|
|
24
50
|
}
|
|
51
|
+
const LAPTOP_CHASSIS = new Set(['8', '9', '10', '14', '30', '31', '32']);
|
|
52
|
+
const DESKTOP_CHASSIS = new Set(['3', '4', '5', '6', '7', '15', '16']);
|
|
53
|
+
const SERVER_CHASSIS = new Set(['17', '18', '19', '20', '21', '22', '23', '24']);
|
|
54
|
+
export function chassisForm(value) {
|
|
55
|
+
const chassis = value.trim();
|
|
56
|
+
if (LAPTOP_CHASSIS.has(chassis))
|
|
57
|
+
return 'laptop';
|
|
58
|
+
if (DESKTOP_CHASSIS.has(chassis))
|
|
59
|
+
return 'desktop';
|
|
60
|
+
if (SERVER_CHASSIS.has(chassis))
|
|
61
|
+
return 'server';
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
export function hostVm(version) {
|
|
65
|
+
return /docker desktop|microsoft|wsl|linuxkit/i.test(version);
|
|
66
|
+
}
|
|
25
67
|
async function models(kind, adapter, known) {
|
|
26
68
|
const agent = adapter.connection.agent;
|
|
27
69
|
const opened = await agent.request('session/new', { cwd: kitHome(), mcpServers: [] });
|
|
@@ -30,30 +72,23 @@ async function models(kind, adapter, known) {
|
|
|
30
72
|
const modes = mode === undefined ? [] : choices(mode.options).map(({ value, name }) => ({ mode: value, name }));
|
|
31
73
|
const model = select(options, 'model');
|
|
32
74
|
if (model === undefined)
|
|
33
|
-
return { models: [], modes };
|
|
75
|
+
return { models: [], ...UNNAMED, modes };
|
|
76
|
+
const started = starting(model, select(options, 'thought_level'));
|
|
34
77
|
const offered = [];
|
|
35
|
-
for (const value of
|
|
78
|
+
for (const { value, name } of named(model.options)) {
|
|
36
79
|
if (select(options, 'model')?.currentValue !== value) {
|
|
37
80
|
try {
|
|
38
81
|
options = (await agent.request('session/set_config_option', { sessionId: opened.sessionId, configId: model.id, value })).configOptions;
|
|
39
82
|
}
|
|
40
83
|
catch (error) {
|
|
41
84
|
process.stderr.write(`kit: ${kind} refused its model ${value}: ${causeOf(error)}\n`);
|
|
42
|
-
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 ?? [] });
|
|
43
86
|
continue;
|
|
44
87
|
}
|
|
45
88
|
}
|
|
46
|
-
|
|
47
|
-
offered.push({ model: value, efforts: effort === undefined ? [] : values(effort.options) });
|
|
89
|
+
offered.push({ model: value, name, efforts: effortsOf(select(options, 'thought_level')) });
|
|
48
90
|
}
|
|
49
|
-
return { models: offered, modes };
|
|
50
|
-
}
|
|
51
|
-
async function signedIn(kind, cli, known, signal) {
|
|
52
|
-
const probe = CLIS[kind].signedIn;
|
|
53
|
-
// A sign-in check that has not answered in half a minute counts as signed out rather than stalling the report.
|
|
54
|
-
if ('command' in probe)
|
|
55
|
-
return (await run(cli, probe.command, 30_000, false, signal)).status === 0;
|
|
56
|
-
return (await offer(kind, cli, known, signal)).signed_in;
|
|
91
|
+
return { models: offered, ...started, modes };
|
|
57
92
|
}
|
|
58
93
|
function ended(signal) {
|
|
59
94
|
return new Promise((_, reject) => {
|
|
@@ -62,52 +97,66 @@ function ended(signal) {
|
|
|
62
97
|
signal.addEventListener('abort', () => reject(signal.reason), { once: true });
|
|
63
98
|
});
|
|
64
99
|
}
|
|
100
|
+
function keyedOf({ api_key, provider }) {
|
|
101
|
+
return { ...(api_key === undefined ? {} : { api_key }), ...(provider === undefined ? {} : { provider }) };
|
|
102
|
+
}
|
|
65
103
|
async function offer(kind, cli, known, signal) {
|
|
66
|
-
const probe = CLIS[kind]
|
|
104
|
+
const { signedIn: probe, key } = CLIS[kind];
|
|
105
|
+
const keyed = await key.read();
|
|
67
106
|
// A sign-in check that has not answered in half a minute counts as signed out rather than stalling the report.
|
|
68
|
-
if ('command' in probe && (await run(cli, probe.command, 30_000, false, signal)).status !== 0)
|
|
69
|
-
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
|
+
}
|
|
70
110
|
let adapter;
|
|
71
111
|
try {
|
|
72
|
-
adapter = await startAdapter(kind, cli, kitHome(), client({ name: '@agentshouse/kit' }), () =>
|
|
112
|
+
adapter = await startAdapter(kind, cli, kitHome(), client({ name: '@agentshouse/kit' }), () => null, {}, signal);
|
|
73
113
|
signal?.throwIfAborted();
|
|
74
114
|
if ('initializeMeta' in probe) {
|
|
75
115
|
const method = adapter.initialized._meta?.[probe.initializeMeta];
|
|
76
116
|
if (typeof method !== 'string' || method.length === 0)
|
|
77
|
-
return SIGNED_OUT;
|
|
117
|
+
return { ...SIGNED_OUT, ...keyed };
|
|
118
|
+
if (method === probe.apiKey)
|
|
119
|
+
keyed.api_key = true;
|
|
78
120
|
}
|
|
79
|
-
return { signed_in: true, ...(await models(kind, adapter, known.models)) };
|
|
121
|
+
return { signed_in: true, ...keyed, ...(await models(kind, adapter, known.models)) };
|
|
80
122
|
}
|
|
81
123
|
catch (error) {
|
|
82
124
|
if (!signal?.aborted)
|
|
83
125
|
process.stderr.write(`kit: ${kind} did not offer its models: ${causeOf(error)}\n`);
|
|
126
|
+
if (signedOut(error))
|
|
127
|
+
return { ...SIGNED_OUT, ...keyed };
|
|
128
|
+
const unread = adapter === undefined && 'initializeMeta' in probe;
|
|
84
129
|
return {
|
|
85
|
-
signed_in:
|
|
130
|
+
signed_in: unread ? known.signed_in : true,
|
|
131
|
+
...keyedOf({ api_key: unread ? known.api_key : keyed.api_key, provider: keyed.provider }),
|
|
86
132
|
models: known.models,
|
|
133
|
+
default_model: known.default_model,
|
|
134
|
+
default_effort: known.default_effort,
|
|
87
135
|
modes: known.modes,
|
|
88
136
|
};
|
|
89
137
|
}
|
|
90
138
|
finally {
|
|
91
|
-
|
|
92
|
-
killTree(adapter.child);
|
|
139
|
+
adapter?.retire();
|
|
93
140
|
}
|
|
94
141
|
}
|
|
95
142
|
function reported(kind, reading) {
|
|
143
|
+
const { minimum, update } = CLIS[kind];
|
|
96
144
|
return {
|
|
97
145
|
kind,
|
|
98
146
|
release: reading.release,
|
|
99
|
-
...(reading.
|
|
147
|
+
...(reading.release !== null && below(reading.release, minimum) ? { minimum, update } : {}),
|
|
100
148
|
failure: reading.failure,
|
|
149
|
+
...(reading.installing === undefined ? {} : { installing: reading.installing }),
|
|
101
150
|
signed_in: reading.signed_in,
|
|
151
|
+
...keyedOf(reading),
|
|
102
152
|
models: reading.models,
|
|
103
153
|
modes: reading.modes,
|
|
104
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 }),
|
|
105
157
|
};
|
|
106
158
|
}
|
|
107
|
-
|
|
108
|
-
const cli = CLIS[kind];
|
|
109
|
-
return `${cli.bin} ${release} is older than ${cli.minimum}, the oldest this Kit runs`;
|
|
110
|
-
}
|
|
159
|
+
const NOT_READY = "the Agent's CLI is not ready on this computer";
|
|
111
160
|
async function sshHostKey() {
|
|
112
161
|
// Listing a local host key takes a moment, so ten seconds only bounds a stuck ssh-keygen.
|
|
113
162
|
const listed = await run('ssh-keygen', ['-l', '-E', 'sha256', '-f', '/etc/ssh/ssh_host_ed25519_key.pub'], 10_000);
|
|
@@ -120,18 +169,44 @@ async function operatingSystem() {
|
|
|
120
169
|
const release = await readFile('/etc/os-release', 'utf8');
|
|
121
170
|
return /^PRETTY_NAME="?([^"\n]*)"?$/m.exec(release)?.[1] ?? release;
|
|
122
171
|
}
|
|
172
|
+
async function hostForm() {
|
|
173
|
+
if (process.platform === 'darwin') {
|
|
174
|
+
const battery = await run('pmset', ['-g', 'batt'], 10_000);
|
|
175
|
+
return battery.status === 0 && battery.output.includes('InternalBattery') ? 'laptop' : 'desktop';
|
|
176
|
+
}
|
|
177
|
+
if (process.platform !== 'linux')
|
|
178
|
+
return undefined;
|
|
179
|
+
const [container, version, chassis] = await Promise.all([
|
|
180
|
+
readFile('/.dockerenv', 'utf8').then(() => true).catch(() => false),
|
|
181
|
+
readFile('/proc/version', 'utf8').catch(() => ''),
|
|
182
|
+
readFile('/sys/class/dmi/id/chassis_type', 'utf8').catch(() => ''),
|
|
183
|
+
]);
|
|
184
|
+
if (container && hostVm(version))
|
|
185
|
+
return undefined;
|
|
186
|
+
return chassisForm(chassis);
|
|
187
|
+
}
|
|
123
188
|
export class Agents {
|
|
124
189
|
desired = { agents: [], routes: [], transcribe: false };
|
|
125
190
|
house;
|
|
126
191
|
reading = Promise.resolve();
|
|
127
192
|
queues = new Map();
|
|
128
193
|
installing = Promise.resolve();
|
|
194
|
+
installs = new Map();
|
|
129
195
|
readings = new Map();
|
|
130
196
|
reads = new Map();
|
|
197
|
+
starts = 0;
|
|
131
198
|
sending = Promise.resolve();
|
|
132
199
|
sent = null;
|
|
133
|
-
|
|
200
|
+
refreshing = 0;
|
|
201
|
+
loaded = Promise.resolve();
|
|
202
|
+
updating = null;
|
|
203
|
+
changed;
|
|
204
|
+
constructor(house, changed = () => undefined) {
|
|
134
205
|
this.house = house;
|
|
206
|
+
this.changed = changed;
|
|
207
|
+
}
|
|
208
|
+
idle() {
|
|
209
|
+
return this.refreshing === 0 && this.updating === null;
|
|
135
210
|
}
|
|
136
211
|
read() {
|
|
137
212
|
return this.reading.then(() => undefined, () => undefined);
|
|
@@ -140,46 +215,73 @@ export class Agents {
|
|
|
140
215
|
return this.desired.routes.find((route) => route.agent_id === agentId);
|
|
141
216
|
}
|
|
142
217
|
refresh() {
|
|
218
|
+
this.refreshing++;
|
|
219
|
+
this.changed();
|
|
143
220
|
const reading = this.read().then(async () => {
|
|
144
|
-
this.desired = await this.house.deliver('
|
|
221
|
+
this.desired = await this.house.deliver('agents/desired/list', {});
|
|
145
222
|
return this.desired;
|
|
146
223
|
});
|
|
147
224
|
this.reading = reading;
|
|
148
|
-
|
|
225
|
+
this.loaded = reading
|
|
226
|
+
.then(({ agents, transcribe }) => Promise.all([
|
|
149
227
|
holdTranscription(transcribe)
|
|
150
228
|
.then((changed) => (changed ? this.report() : undefined))
|
|
151
|
-
.catch(logged)
|
|
229
|
+
.catch(logged),
|
|
152
230
|
Promise.all(agents.map((kind) => this.load(kind)))
|
|
153
231
|
.then(() => this.report())
|
|
154
|
-
.catch(logged)
|
|
232
|
+
.catch(logged),
|
|
233
|
+
]))
|
|
234
|
+
.catch(() => undefined)
|
|
235
|
+
.finally(() => {
|
|
236
|
+
this.refreshing--;
|
|
237
|
+
this.changed();
|
|
155
238
|
});
|
|
239
|
+
return reading.then(() => undefined);
|
|
240
|
+
}
|
|
241
|
+
keepCurrent(stopping) {
|
|
242
|
+
this.updateAll(this.loaded);
|
|
243
|
+
setInterval(() => {
|
|
244
|
+
if (!stopping())
|
|
245
|
+
this.updateAll(Promise.resolve());
|
|
246
|
+
}, CLI_UPDATE_MS);
|
|
156
247
|
}
|
|
157
248
|
cli(kind) {
|
|
249
|
+
this.starts += 1;
|
|
158
250
|
return this.queue(kind, async () => {
|
|
159
251
|
const resolved = await this.resolve(kind);
|
|
160
252
|
if (!('cli' in resolved)) {
|
|
161
253
|
this.update(kind, resolved);
|
|
162
|
-
throw new Error(
|
|
254
|
+
throw new Error(NOT_READY);
|
|
163
255
|
}
|
|
164
256
|
const { cli, release } = resolved;
|
|
165
257
|
const known = this.readings.get(kind);
|
|
166
|
-
const kept = known?.release === null
|
|
167
|
-
if (known?.release !== release ||
|
|
168
|
-
this.update(kind, {
|
|
258
|
+
const kept = known?.release === null ? SIGNED_OUT : (known ?? SIGNED_OUT);
|
|
259
|
+
if (known?.release !== release || this.installs.has(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
|
+
});
|
|
169
270
|
}
|
|
170
271
|
const read = this.nextRead(kind);
|
|
171
|
-
|
|
272
|
+
this.quietOffer(kind, cli, kept)
|
|
172
273
|
.then((offered) => {
|
|
173
274
|
const current = this.readings.get(kind);
|
|
174
275
|
if (this.reads.get(kind) === read && current?.release === release)
|
|
175
|
-
this.update(kind, {
|
|
276
|
+
this.update(kind, { release, failure: current.failure, ...offered });
|
|
176
277
|
})
|
|
177
278
|
.catch(logged);
|
|
178
279
|
return cli;
|
|
179
280
|
});
|
|
180
281
|
}
|
|
181
282
|
located(kind, signal) {
|
|
182
|
-
|
|
283
|
+
const owner = {};
|
|
284
|
+
return this.queue(kind, () => this.ensure(kind, signal, owner).finally(() => this.settle(kind, owner)), signal);
|
|
183
285
|
}
|
|
184
286
|
async reread(kind) {
|
|
185
287
|
await this.examine(kind, this.readings.get(kind) ?? SIGNED_OUT, offer);
|
|
@@ -187,7 +289,13 @@ export class Agents {
|
|
|
187
289
|
}
|
|
188
290
|
async recheck(kind, signal) {
|
|
189
291
|
const known = this.readings.get(kind) ?? SIGNED_OUT;
|
|
190
|
-
|
|
292
|
+
const owner = {};
|
|
293
|
+
try {
|
|
294
|
+
await this.examine(kind, known, (kind, cli) => offer(kind, cli, known, AbortSignal.any([signal, AbortSignal.timeout(SIGNED_IN_READ_MS)])), signal, owner);
|
|
295
|
+
}
|
|
296
|
+
finally {
|
|
297
|
+
this.settle(kind, owner);
|
|
298
|
+
}
|
|
191
299
|
if (!signal.aborted)
|
|
192
300
|
await this.report();
|
|
193
301
|
}
|
|
@@ -201,8 +309,18 @@ export class Agents {
|
|
|
201
309
|
this.reads.set(kind, read);
|
|
202
310
|
return read;
|
|
203
311
|
}
|
|
204
|
-
|
|
312
|
+
hold(kind, reading) {
|
|
205
313
|
this.readings.set(kind, reading);
|
|
314
|
+
this.installs.delete(kind);
|
|
315
|
+
}
|
|
316
|
+
update(kind, reading) {
|
|
317
|
+
this.hold(kind, reading);
|
|
318
|
+
this.report().catch(logged);
|
|
319
|
+
}
|
|
320
|
+
settle(kind, owner) {
|
|
321
|
+
if (this.installs.get(kind) !== owner)
|
|
322
|
+
return;
|
|
323
|
+
this.installs.delete(kind);
|
|
206
324
|
this.report().catch(logged);
|
|
207
325
|
}
|
|
208
326
|
queue(kind, work, signal) {
|
|
@@ -213,13 +331,12 @@ export class Agents {
|
|
|
213
331
|
this.queues.set(kind, queued.catch(() => undefined));
|
|
214
332
|
return signal === undefined ? queued : Promise.race([queued, ended(signal)]);
|
|
215
333
|
}
|
|
216
|
-
async ensure(kind, signal) {
|
|
217
|
-
const failed = await installAdapter(kind, signal);
|
|
218
|
-
if (failed !== null)
|
|
219
|
-
throw new Error(failed);
|
|
334
|
+
async ensure(kind, signal, owner = {}) {
|
|
220
335
|
const found = await locate(kind, signal);
|
|
221
336
|
if (found !== null)
|
|
222
337
|
return found;
|
|
338
|
+
this.installs.set(kind, owner);
|
|
339
|
+
this.report().catch(logged);
|
|
223
340
|
const installing = this.installing.catch(() => undefined).then(() => installCli(kind, signal));
|
|
224
341
|
this.installing = installing;
|
|
225
342
|
const failure = await installing;
|
|
@@ -230,47 +347,86 @@ export class Agents {
|
|
|
230
347
|
throw new Error(`the login shell does not find ${CLIS[kind].bin} after its install`);
|
|
231
348
|
return installed;
|
|
232
349
|
}
|
|
233
|
-
async resolve(kind, signal) {
|
|
350
|
+
async resolve(kind, signal, owner) {
|
|
234
351
|
let cli;
|
|
235
352
|
try {
|
|
236
|
-
cli = await
|
|
353
|
+
cli = await this.ensure(kind, signal, owner);
|
|
237
354
|
}
|
|
238
355
|
catch (error) {
|
|
239
356
|
const failure = causeOf(error);
|
|
240
357
|
process.stderr.write(`kit: ${kind} did not install: ${failure}\n`);
|
|
241
358
|
return { release: null, failure, ...SIGNED_OUT };
|
|
242
359
|
}
|
|
243
|
-
const release = await versionOf(cli, signal);
|
|
360
|
+
const release = await versionOf(kind, cli, signal);
|
|
244
361
|
if (release === null)
|
|
245
362
|
return { release: null, failure: `${cli} --version names no version`, ...SIGNED_OUT };
|
|
246
|
-
const minimum = CLIS[kind].minimum;
|
|
247
|
-
if (below(release, minimum))
|
|
248
|
-
return { release, minimum, failure: null, ...SIGNED_OUT };
|
|
249
363
|
return { cli, release };
|
|
250
364
|
}
|
|
251
|
-
async examine(kind, known, read, signal) {
|
|
365
|
+
async examine(kind, known, read, signal, owner) {
|
|
252
366
|
const current = this.nextRead(kind);
|
|
253
|
-
const resolved = await this.queue(kind, () => this.resolve(kind, signal), signal);
|
|
367
|
+
const resolved = await this.queue(kind, () => this.resolve(kind, signal, owner), signal);
|
|
254
368
|
const reading = 'cli' in resolved ? { release: resolved.release, failure: null, ...(await read(kind, resolved.cli, known)) } : resolved;
|
|
255
369
|
if (this.reads.get(kind) === current && !signal?.aborted)
|
|
256
|
-
this.
|
|
370
|
+
this.hold(kind, reading);
|
|
371
|
+
}
|
|
372
|
+
updateAll(after) {
|
|
373
|
+
if (this.updating !== null)
|
|
374
|
+
return;
|
|
375
|
+
this.updating = after
|
|
376
|
+
.then(async () => {
|
|
377
|
+
for (const kind of this.desired.agents) {
|
|
378
|
+
if (this.installs.has(kind) || !this.readings.get(kind)?.release)
|
|
379
|
+
continue;
|
|
380
|
+
const failure = await updateCli(kind);
|
|
381
|
+
if (failure !== null)
|
|
382
|
+
process.stderr.write(`kit: ${kind} did not update: ${failure}\n`);
|
|
383
|
+
await this.readVersion(kind);
|
|
384
|
+
}
|
|
385
|
+
})
|
|
386
|
+
.catch(logged)
|
|
387
|
+
.finally(() => {
|
|
388
|
+
this.updating = null;
|
|
389
|
+
this.changed();
|
|
390
|
+
});
|
|
391
|
+
this.changed();
|
|
392
|
+
}
|
|
393
|
+
async readVersion(kind) {
|
|
394
|
+
const cli = await locate(kind);
|
|
395
|
+
const release = cli === null ? null : await versionOf(kind, cli);
|
|
396
|
+
const current = this.readings.get(kind);
|
|
397
|
+
if (release === null || !current?.release || current.release === release)
|
|
398
|
+
return;
|
|
399
|
+
this.update(kind, { ...current, release });
|
|
400
|
+
}
|
|
401
|
+
async quietOffer(kind, cli, known) {
|
|
402
|
+
for (let seen = -1; seen !== this.starts;) {
|
|
403
|
+
seen = this.starts;
|
|
404
|
+
await delay(MODEL_PROBE_QUIET_MS);
|
|
405
|
+
}
|
|
406
|
+
return offer(kind, cli, known);
|
|
257
407
|
}
|
|
258
408
|
async load(kind) {
|
|
259
409
|
const known = this.readings.get(kind);
|
|
260
|
-
if (known !== undefined && known.failure === null
|
|
410
|
+
if (known !== undefined && known.failure === null)
|
|
261
411
|
return;
|
|
262
|
-
await this.examine(kind, SIGNED_OUT,
|
|
412
|
+
await this.examine(kind, SIGNED_OUT, (kind, cli, known) => this.quietOffer(kind, cli, known));
|
|
413
|
+
await this.report();
|
|
263
414
|
}
|
|
264
415
|
async send() {
|
|
265
416
|
const agents = this.desired.agents.flatMap((kind) => {
|
|
266
|
-
const reading = this.readings.get(kind);
|
|
417
|
+
const reading = this.installs.has(kind) ? INSTALLING : this.readings.get(kind);
|
|
267
418
|
return reading === undefined ? [] : [reported(kind, reading)];
|
|
268
419
|
});
|
|
269
420
|
const hostKey = await sshHostKey();
|
|
421
|
+
const form = await hostForm();
|
|
270
422
|
const body = {
|
|
271
423
|
os: await operatingSystem(),
|
|
272
|
-
|
|
424
|
+
...(form === undefined ? {} : { form }),
|
|
425
|
+
kit_release: KIT_RELEASE,
|
|
426
|
+
wire: KIT_WIRE,
|
|
273
427
|
agent_base: agentBase(),
|
|
428
|
+
...(reinstall() === undefined ? {} : { reinstall: reinstall() }),
|
|
429
|
+
settings: await heldSettings(),
|
|
274
430
|
agents,
|
|
275
431
|
transcription: transcriptionReport(),
|
|
276
432
|
...(hostKey === null ? {} : { ssh_host_key: hostKey }),
|
|
@@ -278,7 +434,7 @@ export class Agents {
|
|
|
278
434
|
const state = JSON.stringify(body);
|
|
279
435
|
if (state === this.sent)
|
|
280
436
|
return;
|
|
281
|
-
await this.house.deliver('
|
|
437
|
+
await this.house.deliver('agents/report', body);
|
|
282
438
|
this.sent = state;
|
|
283
439
|
}
|
|
284
440
|
}
|
package/dist/api.js
CHANGED
|
@@ -1,8 +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';
|
|
7
|
+
import { endUnserved } from './wire.js';
|
|
6
8
|
export class HouseRefusal extends Error {
|
|
7
9
|
status;
|
|
8
10
|
text;
|
|
@@ -16,7 +18,7 @@ export function finalRefusal(error) {
|
|
|
16
18
|
return error instanceof HouseRefusal && retryable(error.text) === false;
|
|
17
19
|
}
|
|
18
20
|
export function retryDelay(attempt) {
|
|
19
|
-
// Full jitter, doubling from one second to a 30-second cap, spreads the
|
|
21
|
+
// Full jitter, doubling from one second to a 30-second cap, spreads the Kit processes one outage dropped and retries within half a minute of House's return.
|
|
20
22
|
return Math.random() * Math.min(30_000, 1000 * 2 ** attempt);
|
|
21
23
|
}
|
|
22
24
|
export async function retrying(sent, signal, pause = retryDelay) {
|
|
@@ -37,16 +39,27 @@ export async function post(house, path, body, credential, signal) {
|
|
|
37
39
|
method: 'POST',
|
|
38
40
|
headers: {
|
|
39
41
|
'content-type': 'application/json',
|
|
42
|
+
[KIT_WIRE_HEADER]: KIT_WIRE,
|
|
40
43
|
...(credential === undefined ? {} : { authorization: `Bearer ${credential}` }),
|
|
41
44
|
},
|
|
42
45
|
body: JSON.stringify(body),
|
|
43
46
|
signal,
|
|
44
47
|
});
|
|
45
48
|
const text = await answer.text();
|
|
49
|
+
if (!answer.ok)
|
|
50
|
+
endUnserved(text);
|
|
46
51
|
if (!answer.ok)
|
|
47
52
|
throw new HouseRefusal(path, answer.status, text);
|
|
48
53
|
return JSON.parse(text);
|
|
49
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
|
+
}
|
|
50
63
|
async function enrolledPost(path, body, signal) {
|
|
51
64
|
const { house, credential } = (await readEnrolment());
|
|
52
65
|
try {
|
|
@@ -59,8 +72,13 @@ async function enrolledPost(path, body, signal) {
|
|
|
59
72
|
}
|
|
60
73
|
}
|
|
61
74
|
export const house = {
|
|
62
|
-
|
|
63
|
-
|
|
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);
|
|
64
82
|
for (let attempt = 0;; attempt++) {
|
|
65
83
|
try {
|
|
66
84
|
return await enrolledPost(path, body);
|
package/dist/app-git.js
CHANGED
|
@@ -1,15 +1,9 @@
|
|
|
1
|
-
import { extname, resolve } from 'node:path';
|
|
2
|
-
import { fileURLToPath } from 'node:url';
|
|
3
1
|
import { run } from './git.js';
|
|
4
2
|
import { kitHome, readOwnAgent } from './home.js';
|
|
5
|
-
|
|
3
|
+
const HELPER = '!kit git-credential';
|
|
6
4
|
function section(house) {
|
|
7
5
|
return `credential.${new URL('/app/', house).href}`;
|
|
8
6
|
}
|
|
9
|
-
function helper() {
|
|
10
|
-
const main = fileURLToPath(new URL(`./kit-main${extname(fileURLToPath(import.meta.url))}`, import.meta.url));
|
|
11
|
-
return `!HOUSE_KIT_HOME=${quoted(resolve(kitHome()))} ${quoted(process.execPath)} ${quoted(main)} git-credential`;
|
|
12
|
-
}
|
|
13
7
|
async function configured(args) {
|
|
14
8
|
try {
|
|
15
9
|
return await run(kitHome(), ['config', '--global', ...args]);
|
|
@@ -20,30 +14,18 @@ async function configured(args) {
|
|
|
20
14
|
throw error;
|
|
21
15
|
}
|
|
22
16
|
}
|
|
23
|
-
async function
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const ran = await configured(['--add', `${section(house)}.helper`, value]);
|
|
17
|
+
export async function placeAppGit(ownAgent) {
|
|
18
|
+
if (ownAgent === null)
|
|
19
|
+
return;
|
|
20
|
+
await configured(['--remove-section', section(ownAgent.house)]);
|
|
21
|
+
for (const value of ['', HELPER]) {
|
|
22
|
+
const ran = await configured(['--add', `${section(ownAgent.house)}.helper`, value]);
|
|
30
23
|
if (ran === null)
|
|
31
24
|
return;
|
|
32
25
|
if (ran.status !== 0)
|
|
33
26
|
throw new Error(`git config failed: ${ran.stderr.trim()}`);
|
|
34
27
|
}
|
|
35
28
|
}
|
|
36
|
-
export async function placeAppGit(before, after) {
|
|
37
|
-
if (before !== null && before.house !== after?.house)
|
|
38
|
-
await forget(before.house);
|
|
39
|
-
if (after !== null)
|
|
40
|
-
await register(after.house);
|
|
41
|
-
}
|
|
42
|
-
export async function forgetAppGit() {
|
|
43
|
-
const ownAgent = await readOwnAgent();
|
|
44
|
-
if (ownAgent !== null)
|
|
45
|
-
await forget(ownAgent.house);
|
|
46
|
-
}
|
|
47
29
|
export async function answerGitCredential(operation) {
|
|
48
30
|
let asked = '';
|
|
49
31
|
for await (const chunk of process.stdin)
|
|
@@ -55,8 +37,10 @@ export async function answerGitCredential(operation) {
|
|
|
55
37
|
.filter((line) => line.includes('='))
|
|
56
38
|
.map((line) => [line.slice(0, line.indexOf('=')), line.slice(line.indexOf('=') + 1)]));
|
|
57
39
|
const ownAgent = await readOwnAgent();
|
|
58
|
-
if (ownAgent === null)
|
|
40
|
+
if (ownAgent === null) {
|
|
41
|
+
process.stderr.write(`kit: Kit home ${kitHome()} is not signed in; run kit login\n`);
|
|
59
42
|
return;
|
|
43
|
+
}
|
|
60
44
|
const house = new URL(ownAgent.house);
|
|
61
45
|
if (attributes.get('protocol') !== house.protocol.slice(0, -1) || attributes.get('host') !== house.host)
|
|
62
46
|
return;
|
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
|
+
}
|