@agentshouse/kit 0.2.1-c30728be20485 → 0.2.1-c33a81a492b90
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 +47 -46
- package/dist/acp.js +102 -108
- package/dist/afk.js +17 -0
- package/dist/agents.js +186 -57
- package/dist/api.js +10 -6
- package/dist/app-git.js +48 -0
- package/dist/authority-main.js +2 -2
- package/dist/bridge.js +15 -44
- package/dist/building.js +50 -0
- package/dist/calls.js +71 -0
- package/dist/chatgpt.js +32 -0
- package/dist/chunks.js +49 -0
- package/dist/clis.js +160 -100
- package/dist/codex-main.js +58 -0
- package/dist/connection.js +105 -0
- package/dist/conversations.js +746 -334
- package/dist/copies.js +431 -218
- package/dist/end.js +30 -5
- package/dist/enrol-main.js +7 -1
- package/dist/events.js +546 -0
- package/dist/files.js +139 -17
- package/dist/git.js +57 -21
- package/dist/home.js +89 -7
- package/dist/house-cli.js +299 -0
- package/dist/house-main.js +7 -159
- package/dist/instructions.js +8 -10
- package/dist/kit-cli.js +68 -0
- package/dist/kit-main.js +8 -19
- package/dist/login.js +119 -104
- package/dist/logout.js +14 -13
- package/dist/mcp.js +6 -2
- package/dist/parts.js +82 -0
- package/dist/placement.js +31 -0
- package/dist/relay.js +33 -2
- package/dist/resident.js +118 -51
- package/dist/scope.js +214 -0
- package/dist/scripts.js +255 -0
- package/dist/service-main.js +9 -0
- package/dist/service.js +55 -0
- package/dist/shell.js +3 -0
- package/dist/sign-in.js +40 -33
- package/dist/silence.js +28 -0
- package/dist/skills.js +49 -35
- package/dist/transcription.js +129 -43
- package/dist/translate.js +2 -8
- package/dist/update.js +113 -105
- package/dist/wire.js +40 -0
- package/dist/work.js +346 -0
- package/package.json +20 -20
- package/dist/blocks.js +0 -51
- package/dist/bootstrap.json +0 -24
- package/dist/clis-main.js +0 -23
- package/dist/stream.js +0 -72
- 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,9 +1,19 @@
|
|
|
1
1
|
import { client } from '@agentclientprotocol/sdk';
|
|
2
|
-
import { readFile
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { readFile } from 'node:fs/promises';
|
|
3
|
+
import { setTimeout as delay } from 'node:timers/promises';
|
|
4
|
+
import { signedOut, startAdapter } from './acp.js';
|
|
5
|
+
import { CLIS, KIT_RELEASE, below, installCli, locate, run, updateCli, versionOf } from './clis.js';
|
|
5
6
|
import { agentBase, kitHome } from './home.js';
|
|
7
|
+
import { holdTranscription, transcriptionReport } from './transcription.js';
|
|
8
|
+
import { KIT_WIRE } from './wire.js';
|
|
9
|
+
// Two quiet seconds let a fresh conversation start before background model discovery competes for its CPU.
|
|
10
|
+
const MODEL_PROBE_QUIET_MS = 2_000;
|
|
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
|
+
export const CLI_UPDATE_MS = 60 * 60_000;
|
|
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
|
+
const SIGNED_IN_READ_MS = 10_000;
|
|
6
15
|
const SIGNED_OUT = { signed_in: false, models: [], modes: [] };
|
|
16
|
+
const INSTALLING = { release: null, failure: null, installing: true, ...SIGNED_OUT };
|
|
7
17
|
function select(options, category) {
|
|
8
18
|
const option = options.find((candidate) => candidate.category === category);
|
|
9
19
|
return option?.type === 'select' ? option : undefined;
|
|
@@ -20,6 +30,22 @@ function causeOf(error) {
|
|
|
20
30
|
function logged(error) {
|
|
21
31
|
process.stderr.write(`kit: ${causeOf(error)}\n`);
|
|
22
32
|
}
|
|
33
|
+
const LAPTOP_CHASSIS = new Set(['8', '9', '10', '14', '30', '31', '32']);
|
|
34
|
+
const DESKTOP_CHASSIS = new Set(['3', '4', '5', '6', '7', '15', '16']);
|
|
35
|
+
const SERVER_CHASSIS = new Set(['17', '18', '19', '20', '21', '22', '23', '24']);
|
|
36
|
+
export function chassisForm(value) {
|
|
37
|
+
const chassis = value.trim();
|
|
38
|
+
if (LAPTOP_CHASSIS.has(chassis))
|
|
39
|
+
return 'laptop';
|
|
40
|
+
if (DESKTOP_CHASSIS.has(chassis))
|
|
41
|
+
return 'desktop';
|
|
42
|
+
if (SERVER_CHASSIS.has(chassis))
|
|
43
|
+
return 'server';
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
export function hostVm(version) {
|
|
47
|
+
return /docker desktop|microsoft|wsl|linuxkit/i.test(version);
|
|
48
|
+
}
|
|
23
49
|
async function models(kind, adapter, known) {
|
|
24
50
|
const agent = adapter.connection.agent;
|
|
25
51
|
const opened = await agent.request('session/new', { cwd: kitHome(), mcpServers: [] });
|
|
@@ -46,21 +72,22 @@ async function models(kind, adapter, known) {
|
|
|
46
72
|
}
|
|
47
73
|
return { models: offered, modes };
|
|
48
74
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
75
|
+
function ended(signal) {
|
|
76
|
+
return new Promise((_, reject) => {
|
|
77
|
+
if (signal.aborted)
|
|
78
|
+
reject(signal.reason);
|
|
79
|
+
signal.addEventListener('abort', () => reject(signal.reason), { once: true });
|
|
80
|
+
});
|
|
55
81
|
}
|
|
56
|
-
async function offer(kind, cli, known) {
|
|
82
|
+
async function offer(kind, cli, known, signal) {
|
|
57
83
|
const probe = CLIS[kind].signedIn;
|
|
58
84
|
// A sign-in check that has not answered in half a minute counts as signed out rather than stalling the report.
|
|
59
|
-
if ('command' in probe && (await run(cli, probe.command, 30_000)).status !== 0)
|
|
85
|
+
if ('command' in probe && (await run(cli, probe.command, 30_000, false, signal)).status !== 0)
|
|
60
86
|
return SIGNED_OUT;
|
|
61
87
|
let adapter;
|
|
62
88
|
try {
|
|
63
|
-
adapter = await startAdapter(kind, cli, kitHome(), client({ name: '@agentshouse/kit' }));
|
|
89
|
+
adapter = await startAdapter(kind, cli, kitHome(), client({ name: '@agentshouse/kit' }), () => undefined, {}, signal);
|
|
90
|
+
signal?.throwIfAborted();
|
|
64
91
|
if ('initializeMeta' in probe) {
|
|
65
92
|
const method = adapter.initialized._meta?.[probe.initializeMeta];
|
|
66
93
|
if (typeof method !== 'string' || method.length === 0)
|
|
@@ -69,7 +96,10 @@ async function offer(kind, cli, known) {
|
|
|
69
96
|
return { signed_in: true, ...(await models(kind, adapter, known.models)) };
|
|
70
97
|
}
|
|
71
98
|
catch (error) {
|
|
72
|
-
|
|
99
|
+
if (!signal?.aborted)
|
|
100
|
+
process.stderr.write(`kit: ${kind} did not offer its models: ${causeOf(error)}\n`);
|
|
101
|
+
if (signedOut(error))
|
|
102
|
+
return SIGNED_OUT;
|
|
73
103
|
return {
|
|
74
104
|
signed_in: adapter === undefined && 'initializeMeta' in probe ? known.signed_in : true,
|
|
75
105
|
models: known.models,
|
|
@@ -77,26 +107,24 @@ async function offer(kind, cli, known) {
|
|
|
77
107
|
};
|
|
78
108
|
}
|
|
79
109
|
finally {
|
|
80
|
-
|
|
81
|
-
killTree(adapter.child);
|
|
110
|
+
adapter?.retire();
|
|
82
111
|
}
|
|
83
112
|
}
|
|
84
113
|
function reported(kind, reading) {
|
|
114
|
+
const { minimum, update } = CLIS[kind];
|
|
85
115
|
return {
|
|
86
116
|
kind,
|
|
87
117
|
release: reading.release,
|
|
88
|
-
...(reading.
|
|
118
|
+
...(reading.release !== null && below(reading.release, minimum) ? { minimum, update } : {}),
|
|
89
119
|
failure: reading.failure,
|
|
120
|
+
...(reading.installing === undefined ? {} : { installing: reading.installing }),
|
|
90
121
|
signed_in: reading.signed_in,
|
|
91
122
|
models: reading.models,
|
|
92
123
|
modes: reading.modes,
|
|
93
124
|
full_access: CLIS[kind].fullAccess,
|
|
94
125
|
};
|
|
95
126
|
}
|
|
96
|
-
|
|
97
|
-
const cli = CLIS[kind];
|
|
98
|
-
return `${cli.bin} ${release} is older than ${cli.minimum}, the oldest this Kit runs`;
|
|
99
|
-
}
|
|
127
|
+
const NOT_READY = "the Agent's CLI is not ready on this computer";
|
|
100
128
|
async function sshHostKey() {
|
|
101
129
|
// Listing a local host key takes a moment, so ten seconds only bounds a stuck ssh-keygen.
|
|
102
130
|
const listed = await run('ssh-keygen', ['-l', '-E', 'sha256', '-f', '/etc/ssh/ssh_host_ed25519_key.pub'], 10_000);
|
|
@@ -109,18 +137,44 @@ async function operatingSystem() {
|
|
|
109
137
|
const release = await readFile('/etc/os-release', 'utf8');
|
|
110
138
|
return /^PRETTY_NAME="?([^"\n]*)"?$/m.exec(release)?.[1] ?? release;
|
|
111
139
|
}
|
|
140
|
+
async function hostForm() {
|
|
141
|
+
if (process.platform === 'darwin') {
|
|
142
|
+
const battery = await run('pmset', ['-g', 'batt'], 10_000);
|
|
143
|
+
return battery.status === 0 && battery.output.includes('InternalBattery') ? 'laptop' : 'desktop';
|
|
144
|
+
}
|
|
145
|
+
if (process.platform !== 'linux')
|
|
146
|
+
return undefined;
|
|
147
|
+
const [container, version, chassis] = await Promise.all([
|
|
148
|
+
readFile('/.dockerenv', 'utf8').then(() => true).catch(() => false),
|
|
149
|
+
readFile('/proc/version', 'utf8').catch(() => ''),
|
|
150
|
+
readFile('/sys/class/dmi/id/chassis_type', 'utf8').catch(() => ''),
|
|
151
|
+
]);
|
|
152
|
+
if (container && hostVm(version))
|
|
153
|
+
return undefined;
|
|
154
|
+
return chassisForm(chassis);
|
|
155
|
+
}
|
|
112
156
|
export class Agents {
|
|
113
|
-
desired = { agents: [], routes: [] };
|
|
157
|
+
desired = { agents: [], routes: [], transcribe: false };
|
|
114
158
|
house;
|
|
115
159
|
reading = Promise.resolve();
|
|
116
160
|
queues = new Map();
|
|
117
161
|
installing = Promise.resolve();
|
|
162
|
+
installs = new Map();
|
|
118
163
|
readings = new Map();
|
|
119
164
|
reads = new Map();
|
|
165
|
+
starts = 0;
|
|
120
166
|
sending = Promise.resolve();
|
|
121
167
|
sent = null;
|
|
122
|
-
|
|
168
|
+
refreshing = 0;
|
|
169
|
+
loaded = Promise.resolve();
|
|
170
|
+
updating = null;
|
|
171
|
+
changed;
|
|
172
|
+
constructor(house, changed = () => undefined) {
|
|
123
173
|
this.house = house;
|
|
174
|
+
this.changed = changed;
|
|
175
|
+
}
|
|
176
|
+
idle() {
|
|
177
|
+
return this.refreshing === 0 && this.updating === null;
|
|
124
178
|
}
|
|
125
179
|
read() {
|
|
126
180
|
return this.reading.then(() => undefined, () => undefined);
|
|
@@ -129,32 +183,49 @@ export class Agents {
|
|
|
129
183
|
return this.desired.routes.find((route) => route.agent_id === agentId);
|
|
130
184
|
}
|
|
131
185
|
refresh() {
|
|
186
|
+
this.refreshing++;
|
|
187
|
+
this.changed();
|
|
132
188
|
const reading = this.read().then(async () => {
|
|
133
189
|
this.desired = await this.house.deliver('/kit/agents/desired', {});
|
|
134
190
|
return this.desired;
|
|
135
191
|
});
|
|
136
192
|
this.reading = reading;
|
|
137
|
-
|
|
193
|
+
this.loaded = reading
|
|
194
|
+
.then(({ agents, transcribe }) => Promise.all([
|
|
195
|
+
holdTranscription(transcribe)
|
|
196
|
+
.then((changed) => (changed ? this.report() : undefined))
|
|
197
|
+
.catch(logged),
|
|
138
198
|
Promise.all(agents.map((kind) => this.load(kind)))
|
|
139
199
|
.then(() => this.report())
|
|
140
|
-
.catch(logged)
|
|
200
|
+
.catch(logged),
|
|
201
|
+
]))
|
|
202
|
+
.catch(() => undefined)
|
|
203
|
+
.finally(() => {
|
|
204
|
+
this.refreshing--;
|
|
205
|
+
this.changed();
|
|
141
206
|
});
|
|
207
|
+
return reading.then(() => undefined);
|
|
208
|
+
}
|
|
209
|
+
keepCurrent() {
|
|
210
|
+
this.updateAll(this.loaded);
|
|
211
|
+
setInterval(() => this.updateAll(Promise.resolve()), CLI_UPDATE_MS);
|
|
142
212
|
}
|
|
143
213
|
cli(kind) {
|
|
214
|
+
this.starts += 1;
|
|
144
215
|
return this.queue(kind, async () => {
|
|
145
216
|
const resolved = await this.resolve(kind);
|
|
146
217
|
if (!('cli' in resolved)) {
|
|
147
218
|
this.update(kind, resolved);
|
|
148
|
-
throw new Error(
|
|
219
|
+
throw new Error(NOT_READY);
|
|
149
220
|
}
|
|
150
221
|
const { cli, release } = resolved;
|
|
151
222
|
const known = this.readings.get(kind);
|
|
152
|
-
const kept = known?.release === null
|
|
153
|
-
if (known?.release !== release ||
|
|
223
|
+
const kept = known?.release === null ? SIGNED_OUT : (known ?? SIGNED_OUT);
|
|
224
|
+
if (known?.release !== release || this.installs.has(kind)) {
|
|
154
225
|
this.update(kind, { release, failure: null, signed_in: kept.signed_in, models: kept.models, modes: kept.modes });
|
|
155
226
|
}
|
|
156
227
|
const read = this.nextRead(kind);
|
|
157
|
-
|
|
228
|
+
this.quietOffer(kind, cli, kept)
|
|
158
229
|
.then((offered) => {
|
|
159
230
|
const current = this.readings.get(kind);
|
|
160
231
|
if (this.reads.get(kind) === read && current?.release === release)
|
|
@@ -164,17 +235,25 @@ export class Agents {
|
|
|
164
235
|
return cli;
|
|
165
236
|
});
|
|
166
237
|
}
|
|
167
|
-
located(kind) {
|
|
168
|
-
|
|
238
|
+
located(kind, signal) {
|
|
239
|
+
const owner = {};
|
|
240
|
+
return this.queue(kind, () => this.ensure(kind, signal, owner).finally(() => this.settle(kind, owner)), signal);
|
|
169
241
|
}
|
|
170
242
|
async reread(kind) {
|
|
171
243
|
await this.examine(kind, this.readings.get(kind) ?? SIGNED_OUT, offer);
|
|
172
244
|
await this.report();
|
|
173
245
|
}
|
|
174
|
-
async recheck(kind) {
|
|
246
|
+
async recheck(kind, signal) {
|
|
175
247
|
const known = this.readings.get(kind) ?? SIGNED_OUT;
|
|
176
|
-
|
|
177
|
-
|
|
248
|
+
const owner = {};
|
|
249
|
+
try {
|
|
250
|
+
await this.examine(kind, known, (kind, cli) => offer(kind, cli, known, AbortSignal.any([signal, AbortSignal.timeout(SIGNED_IN_READ_MS)])), signal, owner);
|
|
251
|
+
}
|
|
252
|
+
finally {
|
|
253
|
+
this.settle(kind, owner);
|
|
254
|
+
}
|
|
255
|
+
if (!signal.aborted)
|
|
256
|
+
await this.report();
|
|
178
257
|
}
|
|
179
258
|
report() {
|
|
180
259
|
const sending = this.sending.catch(() => undefined).then(() => this.send());
|
|
@@ -186,74 +265,124 @@ export class Agents {
|
|
|
186
265
|
this.reads.set(kind, read);
|
|
187
266
|
return read;
|
|
188
267
|
}
|
|
189
|
-
|
|
268
|
+
hold(kind, reading) {
|
|
190
269
|
this.readings.set(kind, reading);
|
|
270
|
+
this.installs.delete(kind);
|
|
271
|
+
}
|
|
272
|
+
update(kind, reading) {
|
|
273
|
+
this.hold(kind, reading);
|
|
274
|
+
this.report().catch(logged);
|
|
275
|
+
}
|
|
276
|
+
settle(kind, owner) {
|
|
277
|
+
if (this.installs.get(kind) !== owner)
|
|
278
|
+
return;
|
|
279
|
+
this.installs.delete(kind);
|
|
191
280
|
this.report().catch(logged);
|
|
192
281
|
}
|
|
193
|
-
queue(kind, work) {
|
|
194
|
-
const queued = (this.queues.get(kind) ?? Promise.resolve()).then(
|
|
282
|
+
queue(kind, work, signal) {
|
|
283
|
+
const queued = (this.queues.get(kind) ?? Promise.resolve()).then(() => {
|
|
284
|
+
signal?.throwIfAborted();
|
|
285
|
+
return work();
|
|
286
|
+
});
|
|
195
287
|
this.queues.set(kind, queued.catch(() => undefined));
|
|
196
|
-
return queued;
|
|
288
|
+
return signal === undefined ? queued : Promise.race([queued, ended(signal)]);
|
|
197
289
|
}
|
|
198
|
-
async ensure(kind) {
|
|
199
|
-
const
|
|
200
|
-
if (failed !== null)
|
|
201
|
-
throw new Error(failed);
|
|
202
|
-
const found = await locate(kind);
|
|
290
|
+
async ensure(kind, signal, owner = {}) {
|
|
291
|
+
const found = await locate(kind, signal);
|
|
203
292
|
if (found !== null)
|
|
204
293
|
return found;
|
|
205
|
-
|
|
294
|
+
this.installs.set(kind, owner);
|
|
295
|
+
this.report().catch(logged);
|
|
296
|
+
const installing = this.installing.catch(() => undefined).then(() => installCli(kind, signal));
|
|
206
297
|
this.installing = installing;
|
|
207
298
|
const failure = await installing;
|
|
208
299
|
if (failure !== null)
|
|
209
300
|
throw new Error(failure);
|
|
210
|
-
const installed = await locate(kind);
|
|
301
|
+
const installed = await locate(kind, signal);
|
|
211
302
|
if (installed === null)
|
|
212
303
|
throw new Error(`the login shell does not find ${CLIS[kind].bin} after its install`);
|
|
213
304
|
return installed;
|
|
214
305
|
}
|
|
215
|
-
async resolve(kind) {
|
|
306
|
+
async resolve(kind, signal, owner) {
|
|
216
307
|
let cli;
|
|
217
308
|
try {
|
|
218
|
-
cli = await
|
|
309
|
+
cli = await this.ensure(kind, signal, owner);
|
|
219
310
|
}
|
|
220
311
|
catch (error) {
|
|
221
312
|
const failure = causeOf(error);
|
|
222
313
|
process.stderr.write(`kit: ${kind} did not install: ${failure}\n`);
|
|
223
314
|
return { release: null, failure, ...SIGNED_OUT };
|
|
224
315
|
}
|
|
225
|
-
const release = await versionOf(cli);
|
|
316
|
+
const release = await versionOf(cli, signal);
|
|
226
317
|
if (release === null)
|
|
227
318
|
return { release: null, failure: `${cli} --version names no version`, ...SIGNED_OUT };
|
|
228
|
-
const minimum = CLIS[kind].minimum;
|
|
229
|
-
if (below(release, minimum))
|
|
230
|
-
return { release, minimum, failure: null, ...SIGNED_OUT };
|
|
231
319
|
return { cli, release };
|
|
232
320
|
}
|
|
233
|
-
async examine(kind, known, read) {
|
|
321
|
+
async examine(kind, known, read, signal, owner) {
|
|
234
322
|
const current = this.nextRead(kind);
|
|
235
|
-
const resolved = await this.queue(kind, () => this.resolve(kind));
|
|
323
|
+
const resolved = await this.queue(kind, () => this.resolve(kind, signal, owner), signal);
|
|
236
324
|
const reading = 'cli' in resolved ? { release: resolved.release, failure: null, ...(await read(kind, resolved.cli, known)) } : resolved;
|
|
237
|
-
if (this.reads.get(kind) === current)
|
|
238
|
-
this.
|
|
325
|
+
if (this.reads.get(kind) === current && !signal?.aborted)
|
|
326
|
+
this.hold(kind, reading);
|
|
327
|
+
}
|
|
328
|
+
updateAll(after) {
|
|
329
|
+
if (this.updating !== null)
|
|
330
|
+
return;
|
|
331
|
+
this.updating = after
|
|
332
|
+
.then(async () => {
|
|
333
|
+
for (const kind of this.desired.agents) {
|
|
334
|
+
if (this.installs.has(kind) || !this.readings.get(kind)?.release)
|
|
335
|
+
continue;
|
|
336
|
+
const failure = await updateCli(kind);
|
|
337
|
+
if (failure !== null)
|
|
338
|
+
process.stderr.write(`kit: ${kind} did not update: ${failure}\n`);
|
|
339
|
+
await this.readVersion(kind);
|
|
340
|
+
}
|
|
341
|
+
})
|
|
342
|
+
.catch(logged)
|
|
343
|
+
.finally(() => {
|
|
344
|
+
this.updating = null;
|
|
345
|
+
this.changed();
|
|
346
|
+
});
|
|
347
|
+
this.changed();
|
|
348
|
+
}
|
|
349
|
+
async readVersion(kind) {
|
|
350
|
+
const cli = await locate(kind);
|
|
351
|
+
const release = cli === null ? null : await versionOf(cli);
|
|
352
|
+
const current = this.readings.get(kind);
|
|
353
|
+
if (release === null || !current?.release || current.release === release)
|
|
354
|
+
return;
|
|
355
|
+
this.update(kind, { ...current, release });
|
|
356
|
+
}
|
|
357
|
+
async quietOffer(kind, cli, known) {
|
|
358
|
+
for (let seen = -1; seen !== this.starts;) {
|
|
359
|
+
seen = this.starts;
|
|
360
|
+
await delay(MODEL_PROBE_QUIET_MS);
|
|
361
|
+
}
|
|
362
|
+
return offer(kind, cli, known);
|
|
239
363
|
}
|
|
240
364
|
async load(kind) {
|
|
241
365
|
const known = this.readings.get(kind);
|
|
242
366
|
if (known !== undefined && known.failure === null)
|
|
243
367
|
return;
|
|
244
|
-
await this.examine(kind, SIGNED_OUT,
|
|
368
|
+
await this.examine(kind, SIGNED_OUT, (kind, cli, known) => this.quietOffer(kind, cli, known));
|
|
369
|
+
await this.report();
|
|
245
370
|
}
|
|
246
371
|
async send() {
|
|
247
372
|
const agents = this.desired.agents.flatMap((kind) => {
|
|
248
|
-
const reading = this.readings.get(kind);
|
|
373
|
+
const reading = this.installs.has(kind) ? INSTALLING : this.readings.get(kind);
|
|
249
374
|
return reading === undefined ? [] : [reported(kind, reading)];
|
|
250
375
|
});
|
|
251
376
|
const hostKey = await sshHostKey();
|
|
377
|
+
const form = await hostForm();
|
|
252
378
|
const body = {
|
|
253
379
|
os: await operatingSystem(),
|
|
254
|
-
|
|
380
|
+
...(form === undefined ? {} : { form }),
|
|
381
|
+
kit_release: KIT_RELEASE,
|
|
382
|
+
wire: KIT_WIRE,
|
|
255
383
|
agent_base: agentBase(),
|
|
256
384
|
agents,
|
|
385
|
+
transcription: transcriptionReport(),
|
|
257
386
|
...(hostKey === null ? {} : { ssh_host_key: hostKey }),
|
|
258
387
|
};
|
|
259
388
|
const state = JSON.stringify(body);
|
package/dist/api.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { setTimeout as delay } from 'node:timers/promises';
|
|
2
|
-
import {
|
|
2
|
+
import { signInAgain } from './end.js';
|
|
3
3
|
import { readEnrolment } from './home.js';
|
|
4
4
|
import { retryable } from './refusals.js';
|
|
5
5
|
import { relayed } from './relay.js';
|
|
6
|
+
import { endUnserved, KIT_WIRE, KIT_WIRE_HEADER } from './wire.js';
|
|
6
7
|
export class HouseRefusal extends Error {
|
|
7
8
|
status;
|
|
8
9
|
text;
|
|
@@ -16,10 +17,10 @@ export function finalRefusal(error) {
|
|
|
16
17
|
return error instanceof HouseRefusal && retryable(error.text) === false;
|
|
17
18
|
}
|
|
18
19
|
export function retryDelay(attempt) {
|
|
19
|
-
// Full jitter, doubling from one second to a 30-second cap, spreads the
|
|
20
|
+
// 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
21
|
return Math.random() * Math.min(30_000, 1000 * 2 ** attempt);
|
|
21
22
|
}
|
|
22
|
-
export async function retrying(sent, signal) {
|
|
23
|
+
export async function retrying(sent, signal, pause = retryDelay) {
|
|
23
24
|
for (let attempt = 0;; attempt++) {
|
|
24
25
|
try {
|
|
25
26
|
return await sent();
|
|
@@ -28,8 +29,8 @@ export async function retrying(sent, signal) {
|
|
|
28
29
|
if (!(error instanceof HouseRefusal) || retryable(error.text) !== true)
|
|
29
30
|
throw error;
|
|
30
31
|
}
|
|
31
|
-
// A request House refused as retryable is sent again
|
|
32
|
-
await delay(
|
|
32
|
+
// A request House refused as retryable is sent again after the caller's pause, the jittered curve unless it names its own.
|
|
33
|
+
await delay(pause(attempt), undefined, { signal });
|
|
33
34
|
}
|
|
34
35
|
}
|
|
35
36
|
export async function post(house, path, body, credential, signal) {
|
|
@@ -37,12 +38,15 @@ export async function post(house, path, body, credential, signal) {
|
|
|
37
38
|
method: 'POST',
|
|
38
39
|
headers: {
|
|
39
40
|
'content-type': 'application/json',
|
|
41
|
+
[KIT_WIRE_HEADER]: String(KIT_WIRE),
|
|
40
42
|
...(credential === undefined ? {} : { authorization: `Bearer ${credential}` }),
|
|
41
43
|
},
|
|
42
44
|
body: JSON.stringify(body),
|
|
43
45
|
signal,
|
|
44
46
|
});
|
|
45
47
|
const text = await answer.text();
|
|
48
|
+
if (!answer.ok)
|
|
49
|
+
endUnserved(text);
|
|
46
50
|
if (!answer.ok)
|
|
47
51
|
throw new HouseRefusal(path, answer.status, text);
|
|
48
52
|
return JSON.parse(text);
|
|
@@ -54,7 +58,7 @@ async function enrolledPost(path, body, signal) {
|
|
|
54
58
|
}
|
|
55
59
|
catch (error) {
|
|
56
60
|
if (error instanceof HouseRefusal && error.status === 401)
|
|
57
|
-
|
|
61
|
+
await signInAgain(credential);
|
|
58
62
|
throw error;
|
|
59
63
|
}
|
|
60
64
|
}
|
package/dist/app-git.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { run } from './git.js';
|
|
2
|
+
import { kitHome, readOwnAgent } from './home.js';
|
|
3
|
+
const HELPER = '!kit git-credential';
|
|
4
|
+
function section(house) {
|
|
5
|
+
return `credential.${new URL('/app/', house).href}`;
|
|
6
|
+
}
|
|
7
|
+
async function configured(args) {
|
|
8
|
+
try {
|
|
9
|
+
return await run(kitHome(), ['config', '--global', ...args]);
|
|
10
|
+
}
|
|
11
|
+
catch (error) {
|
|
12
|
+
if (error.code === 'ENOENT')
|
|
13
|
+
return null;
|
|
14
|
+
throw error;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
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]);
|
|
23
|
+
if (ran === null)
|
|
24
|
+
return;
|
|
25
|
+
if (ran.status !== 0)
|
|
26
|
+
throw new Error(`git config failed: ${ran.stderr.trim()}`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export async function answerGitCredential(operation) {
|
|
30
|
+
let asked = '';
|
|
31
|
+
for await (const chunk of process.stdin)
|
|
32
|
+
asked += String(chunk);
|
|
33
|
+
if (operation !== 'get')
|
|
34
|
+
return;
|
|
35
|
+
const attributes = new Map(asked
|
|
36
|
+
.split('\n')
|
|
37
|
+
.filter((line) => line.includes('='))
|
|
38
|
+
.map((line) => [line.slice(0, line.indexOf('=')), line.slice(line.indexOf('=') + 1)]));
|
|
39
|
+
const ownAgent = await readOwnAgent();
|
|
40
|
+
if (ownAgent === null) {
|
|
41
|
+
process.stderr.write(`kit: Kit home ${kitHome()} is not signed in; run kit login\n`);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const house = new URL(ownAgent.house);
|
|
45
|
+
if (attributes.get('protocol') !== house.protocol.slice(0, -1) || attributes.get('host') !== house.host)
|
|
46
|
+
return;
|
|
47
|
+
process.stdout.write(`username=house\npassword=${ownAgent.credential}\n`);
|
|
48
|
+
}
|
package/dist/authority-main.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { setGlobalProxyFromEnv } from 'node:http';
|
|
2
1
|
import { HouseRefusal, post } from './api.js';
|
|
3
2
|
import { readEnrolment } from './home.js';
|
|
3
|
+
import { proxyUnlessRelayed } from './relay.js';
|
|
4
4
|
function unanswered(error) {
|
|
5
5
|
return error instanceof HouseRefusal ? error.status >= 500 : error instanceof TypeError && error.message === 'fetch failed';
|
|
6
6
|
}
|
|
7
|
-
|
|
7
|
+
proxyUnlessRelayed();
|
|
8
8
|
try {
|
|
9
9
|
const { house, credential } = (await readEnrolment());
|
|
10
10
|
try {
|
package/dist/bridge.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { createHash, randomUUID } from 'node:crypto';
|
|
2
2
|
import { once } from 'node:events';
|
|
3
3
|
import { setTimeout as delay } from 'node:timers/promises';
|
|
4
|
-
import { mkdir } from 'node:fs/promises';
|
|
5
4
|
import { createServer, request as httpRequest } from 'node:http';
|
|
6
5
|
import { request as httpsRequest } from 'node:https';
|
|
7
6
|
import { delimiter, dirname, join } from 'node:path';
|
|
@@ -9,13 +8,12 @@ import { parse } from 'yaml';
|
|
|
9
8
|
import { finalRefusal, HouseRefusal, retryDelay, retrying } from './api.js';
|
|
10
9
|
import { loginPath } from './clis.js';
|
|
11
10
|
import { changedPaths, } from './copies.js';
|
|
12
|
-
import { kitHome, readEnrolment } from './home.js';
|
|
11
|
+
import { kitHome, readEnrolment, socketDirectory } from './home.js';
|
|
13
12
|
import { callHouse, mcpBody, rpc, UNREACHABLE } from './mcp.js';
|
|
14
|
-
import { operationId
|
|
13
|
+
import { operationId } from './operation.js';
|
|
15
14
|
import { refusalOf, retryable } from './refusals.js';
|
|
16
15
|
import { relayed } from './relay.js';
|
|
17
|
-
const MCP_REQUEST_BYTES =
|
|
18
|
-
const ATTACHMENTS = '/kit/attachments/upload';
|
|
16
|
+
const MCP_REQUEST_BYTES = 4_000_000;
|
|
19
17
|
export async function received(request) {
|
|
20
18
|
let text = '';
|
|
21
19
|
request.setEncoding('utf8');
|
|
@@ -68,11 +66,6 @@ function resendAfter(forwarded, attempt) {
|
|
|
68
66
|
const seconds = pendingSeconds(forwarded);
|
|
69
67
|
return seconds === null ? null : seconds * 1000;
|
|
70
68
|
}
|
|
71
|
-
function versioned(conversationId, text) {
|
|
72
|
-
const file = JSON.parse(text);
|
|
73
|
-
const identity = JSON.stringify([conversationId, file.room_ref ?? null, file.name, file.sha256]);
|
|
74
|
-
return JSON.stringify({ ...file, version: uuidOf(createHash('sha256').update(identity).digest(), 8) });
|
|
75
|
-
}
|
|
76
69
|
function editAnswer(forwarded) {
|
|
77
70
|
const answer = answered(forwarded);
|
|
78
71
|
if ('refused' in answer)
|
|
@@ -88,7 +81,7 @@ function editAnswer(forwarded) {
|
|
|
88
81
|
export async function openBridge(house, copies, conversationId, signal) {
|
|
89
82
|
const path = [join(kitHome(), 'shim'), dirname(process.execPath), await loginPath()].join(delimiter);
|
|
90
83
|
const origin = (await readEnrolment()).house;
|
|
91
|
-
const { credential } = await house.post(`/kit/conversations/${conversationId}/credential`, {}, signal);
|
|
84
|
+
const { credential } = await retrying(() => house.post(`/kit/conversations/${conversationId}/credential`, {}, signal), signal);
|
|
92
85
|
const closed = new AbortController();
|
|
93
86
|
const sent = (message, operation) => callHouse(origin, credential, message, operation, closed.signal);
|
|
94
87
|
const send = async (message, operation) => {
|
|
@@ -103,7 +96,7 @@ export async function openBridge(house, copies, conversationId, signal) {
|
|
|
103
96
|
const after = resendAfter(forwarded, attempt);
|
|
104
97
|
if (after === null)
|
|
105
98
|
return forwarded;
|
|
106
|
-
// A
|
|
99
|
+
// A Tool call House did not settle is sent again on the jittered curve, or after the wait House names for a pending one.
|
|
107
100
|
await delay(after, undefined, { signal: closed.signal });
|
|
108
101
|
}
|
|
109
102
|
};
|
|
@@ -141,32 +134,9 @@ export async function openBridge(house, copies, conversationId, signal) {
|
|
|
141
134
|
const held = JSON.parse(text).transfer;
|
|
142
135
|
return { url: held.url, operation: held.operation, bytes: bytes.length, sha256 };
|
|
143
136
|
};
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
.post('/kit/tools/mutations', {}, closed.signal)
|
|
148
|
-
.then(({ tools }) => new Set(tools.filter((listed) => listed.writes).map((listed) => listed.name)));
|
|
149
|
-
try {
|
|
150
|
-
return (await mutations).has(tool);
|
|
151
|
-
}
|
|
152
|
-
catch (error) {
|
|
153
|
-
mutations = null;
|
|
154
|
-
throw error;
|
|
155
|
-
}
|
|
156
|
-
};
|
|
157
|
-
const forward = async (path, text) => {
|
|
158
|
-
if (path === '/') {
|
|
159
|
-
const message = JSON.parse(text);
|
|
160
|
-
const tool = message.method === 'tools/call' ? String(message.params.name) : null;
|
|
161
|
-
return send(message, tool !== null && (await writes(tool)) ? operationId() : null);
|
|
162
|
-
}
|
|
163
|
-
const answer = await fetch(relayed(new URL(path, origin)), {
|
|
164
|
-
method: 'POST',
|
|
165
|
-
headers: { 'content-type': 'application/json', authorization: `Bearer ${credential}` },
|
|
166
|
-
body: versioned(conversationId, text),
|
|
167
|
-
signal: closed.signal,
|
|
168
|
-
});
|
|
169
|
-
return { status: answer.status, text: await answer.text() };
|
|
137
|
+
const forward = (text) => {
|
|
138
|
+
const message = JSON.parse(text);
|
|
139
|
+
return send(message, message.method === 'tools/call' ? operationId() : null);
|
|
170
140
|
};
|
|
171
141
|
const caller = {
|
|
172
142
|
key: `conversation:${conversationId}`,
|
|
@@ -188,15 +158,15 @@ export async function openBridge(house, copies, conversationId, signal) {
|
|
|
188
158
|
const { cwd, commit } = JSON.parse(text);
|
|
189
159
|
return { status: 200, text: JSON.stringify(await copies.push(cwd, commit, caller)) };
|
|
190
160
|
}
|
|
161
|
+
if (path === '/git/fetch')
|
|
162
|
+
return { status: 200, text: JSON.stringify(await copies.fetch()) };
|
|
191
163
|
if (path === '/git/observed') {
|
|
192
164
|
await copies.observed(JSON.parse(text));
|
|
193
165
|
return { status: 200, text: '{}' };
|
|
194
166
|
}
|
|
195
|
-
return path === '/'
|
|
167
|
+
return path === '/' ? forward(text) : { status: 404, text: '' };
|
|
196
168
|
};
|
|
197
|
-
const
|
|
198
|
-
await mkdir(sockets, { recursive: true, mode: 0o700 });
|
|
199
|
-
const socketPath = join(sockets, `${randomUUID()}.sock`);
|
|
169
|
+
const socketPath = join(socketDirectory(), `${randomUUID()}.sock`);
|
|
200
170
|
const bridge = createServer(async (request, response) => {
|
|
201
171
|
try {
|
|
202
172
|
const path = request.url ?? '';
|
|
@@ -212,7 +182,8 @@ export async function openBridge(house, copies, conversationId, signal) {
|
|
|
212
182
|
response.writeHead(error.status, { 'content-type': 'application/json' }).end(error.text);
|
|
213
183
|
return;
|
|
214
184
|
}
|
|
215
|
-
|
|
185
|
+
const verb = request.url === '/git/push' || request.url === '/git/fetch';
|
|
186
|
+
response.writeHead(502).end(verb && error instanceof Error ? error.message : UNREACHABLE);
|
|
216
187
|
}
|
|
217
188
|
});
|
|
218
189
|
bridge.listen(socketPath);
|
|
@@ -239,7 +210,7 @@ export async function openBridge(house, copies, conversationId, signal) {
|
|
|
239
210
|
GIT_CONFIG_VALUE_0: app,
|
|
240
211
|
},
|
|
241
212
|
tool: async (name, args) => {
|
|
242
|
-
const forwarded = await forward(
|
|
213
|
+
const forwarded = await forward(JSON.stringify(call(name, args)));
|
|
243
214
|
if (forwarded.status !== 200)
|
|
244
215
|
throw new Error(`House refused ${name} with ${forwarded.status}: ${forwarded.text}`);
|
|
245
216
|
const answer = JSON.parse(forwarded.text);
|