@agentshouse/kit 0.2.1-ce145e9aadbf6 → 0.2.1-ceeaf32286734
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +42 -41
- package/dist/acp.js +102 -108
- package/dist/agents.js +152 -45
- package/dist/api.js +34 -2
- package/dist/app-git.js +48 -0
- package/dist/authority-main.js +2 -2
- package/dist/bridge.js +37 -58
- package/dist/building.js +46 -0
- package/dist/calls.js +71 -0
- package/dist/chatgpt.js +32 -0
- package/dist/clis-main.js +2 -2
- package/dist/clis.js +161 -80
- package/dist/codex-main.js +58 -0
- package/dist/connection.js +116 -0
- package/dist/conversations.js +731 -332
- package/dist/copies.js +188 -128
- package/dist/end.js +33 -0
- package/dist/enrol-main.js +7 -1
- package/dist/events.js +546 -0
- package/dist/files.js +139 -17
- package/dist/git.js +13 -11
- package/dist/home.js +96 -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 +39 -0
- package/dist/refusals.js +12 -0
- package/dist/relay.js +33 -2
- package/dist/resident.js +118 -51
- package/dist/scope.js +206 -0
- package/dist/scripts.js +255 -0
- package/dist/secret-input.js +3 -2
- 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 -41
- package/dist/translate.js +2 -8
- package/dist/update.js +117 -53
- package/dist/wire.js +22 -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/stream.js +0 -47
- 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,18 @@
|
|
|
1
1
|
import { client } from '@agentclientprotocol/sdk';
|
|
2
2
|
import { readFile, realpath } from 'node:fs/promises';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { setTimeout as delay } from 'node:timers/promises';
|
|
4
|
+
import { signedOut, startAdapter } from './acp.js';
|
|
5
|
+
import { CLIS, KIT_RELEASE, below, installAdapter, installCli, locate, run, versionOf } from './clis.js';
|
|
5
6
|
import { agentBase, kitHome } from './home.js';
|
|
7
|
+
import { updatesItself } from './placement.js';
|
|
8
|
+
import { holdTranscription, transcriptionReport } from './transcription.js';
|
|
9
|
+
import { KIT_WIRE } from './wire.js';
|
|
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 sign-in's model read that has not answered in ten seconds leaves its sign-in to the status check, so a hung CLI never holds the sign-in's result.
|
|
13
|
+
const SIGNED_IN_READ_MS = 10_000;
|
|
6
14
|
const SIGNED_OUT = { signed_in: false, models: [], modes: [] };
|
|
15
|
+
const INSTALLING = { release: null, failure: null, installing: true, ...SIGNED_OUT };
|
|
7
16
|
function select(options, category) {
|
|
8
17
|
const option = options.find((candidate) => candidate.category === category);
|
|
9
18
|
return option?.type === 'select' ? option : undefined;
|
|
@@ -20,6 +29,22 @@ function causeOf(error) {
|
|
|
20
29
|
function logged(error) {
|
|
21
30
|
process.stderr.write(`kit: ${causeOf(error)}\n`);
|
|
22
31
|
}
|
|
32
|
+
const LAPTOP_CHASSIS = new Set(['8', '9', '10', '14', '30', '31', '32']);
|
|
33
|
+
const DESKTOP_CHASSIS = new Set(['3', '4', '5', '6', '7', '15', '16']);
|
|
34
|
+
const SERVER_CHASSIS = new Set(['17', '18', '19', '20', '21', '22', '23', '24']);
|
|
35
|
+
export function chassisForm(value) {
|
|
36
|
+
const chassis = value.trim();
|
|
37
|
+
if (LAPTOP_CHASSIS.has(chassis))
|
|
38
|
+
return 'laptop';
|
|
39
|
+
if (DESKTOP_CHASSIS.has(chassis))
|
|
40
|
+
return 'desktop';
|
|
41
|
+
if (SERVER_CHASSIS.has(chassis))
|
|
42
|
+
return 'server';
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
export function hostVm(version) {
|
|
46
|
+
return /docker desktop|microsoft|wsl|linuxkit/i.test(version);
|
|
47
|
+
}
|
|
23
48
|
async function models(kind, adapter, known) {
|
|
24
49
|
const agent = adapter.connection.agent;
|
|
25
50
|
const opened = await agent.request('session/new', { cwd: kitHome(), mcpServers: [] });
|
|
@@ -46,19 +71,22 @@ async function models(kind, adapter, known) {
|
|
|
46
71
|
}
|
|
47
72
|
return { models: offered, modes };
|
|
48
73
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
74
|
+
function ended(signal) {
|
|
75
|
+
return new Promise((_, reject) => {
|
|
76
|
+
if (signal.aborted)
|
|
77
|
+
reject(signal.reason);
|
|
78
|
+
signal.addEventListener('abort', () => reject(signal.reason), { once: true });
|
|
79
|
+
});
|
|
54
80
|
}
|
|
55
|
-
async function offer(kind, cli, known) {
|
|
81
|
+
async function offer(kind, cli, known, signal) {
|
|
56
82
|
const probe = CLIS[kind].signedIn;
|
|
57
|
-
|
|
83
|
+
// A sign-in check that has not answered in half a minute counts as signed out rather than stalling the report.
|
|
84
|
+
if ('command' in probe && (await run(cli, probe.command, 30_000, false, signal)).status !== 0)
|
|
58
85
|
return SIGNED_OUT;
|
|
59
86
|
let adapter;
|
|
60
87
|
try {
|
|
61
|
-
adapter = await startAdapter(kind, cli, kitHome(), client({ name: '@agentshouse/kit' }));
|
|
88
|
+
adapter = await startAdapter(kind, cli, kitHome(), client({ name: '@agentshouse/kit' }), () => undefined, {}, signal);
|
|
89
|
+
signal?.throwIfAborted();
|
|
62
90
|
if ('initializeMeta' in probe) {
|
|
63
91
|
const method = adapter.initialized._meta?.[probe.initializeMeta];
|
|
64
92
|
if (typeof method !== 'string' || method.length === 0)
|
|
@@ -67,7 +95,10 @@ async function offer(kind, cli, known) {
|
|
|
67
95
|
return { signed_in: true, ...(await models(kind, adapter, known.models)) };
|
|
68
96
|
}
|
|
69
97
|
catch (error) {
|
|
70
|
-
|
|
98
|
+
if (!signal?.aborted)
|
|
99
|
+
process.stderr.write(`kit: ${kind} did not offer its models: ${causeOf(error)}\n`);
|
|
100
|
+
if (signedOut(error))
|
|
101
|
+
return SIGNED_OUT;
|
|
71
102
|
return {
|
|
72
103
|
signed_in: adapter === undefined && 'initializeMeta' in probe ? known.signed_in : true,
|
|
73
104
|
models: known.models,
|
|
@@ -75,8 +106,7 @@ async function offer(kind, cli, known) {
|
|
|
75
106
|
};
|
|
76
107
|
}
|
|
77
108
|
finally {
|
|
78
|
-
|
|
79
|
-
killTree(adapter.child);
|
|
109
|
+
adapter?.retire();
|
|
80
110
|
}
|
|
81
111
|
}
|
|
82
112
|
function reported(kind, reading) {
|
|
@@ -85,38 +115,66 @@ function reported(kind, reading) {
|
|
|
85
115
|
release: reading.release,
|
|
86
116
|
...(reading.minimum === undefined ? {} : { minimum: reading.minimum }),
|
|
87
117
|
failure: reading.failure,
|
|
118
|
+
...(reading.installing === undefined ? {} : { installing: reading.installing }),
|
|
88
119
|
signed_in: reading.signed_in,
|
|
89
120
|
models: reading.models,
|
|
90
121
|
modes: reading.modes,
|
|
91
122
|
full_access: CLIS[kind].fullAccess,
|
|
92
123
|
};
|
|
93
124
|
}
|
|
125
|
+
const NOT_READY = "the Agent's CLI is not ready on this computer";
|
|
94
126
|
function tooOld(kind, release) {
|
|
95
127
|
const cli = CLIS[kind];
|
|
96
128
|
return `${cli.bin} ${release} is older than ${cli.minimum}, the oldest this Kit runs`;
|
|
97
129
|
}
|
|
98
130
|
async function sshHostKey() {
|
|
131
|
+
// Listing a local host key takes a moment, so ten seconds only bounds a stuck ssh-keygen.
|
|
99
132
|
const listed = await run('ssh-keygen', ['-l', '-E', 'sha256', '-f', '/etc/ssh/ssh_host_ed25519_key.pub'], 10_000);
|
|
100
133
|
return listed.status === 0 ? (/^\d+ (SHA256:\S+)/.exec(listed.output)?.[1] ?? null) : null;
|
|
101
134
|
}
|
|
102
135
|
async function operatingSystem() {
|
|
136
|
+
// sw_vers answers at once, so ten seconds only bounds a stuck call.
|
|
103
137
|
if (process.platform === 'darwin')
|
|
104
138
|
return `macOS ${(await run('sw_vers', ['-productVersion'], 10_000)).output.trim()}`;
|
|
105
139
|
const release = await readFile('/etc/os-release', 'utf8');
|
|
106
140
|
return /^PRETTY_NAME="?([^"\n]*)"?$/m.exec(release)?.[1] ?? release;
|
|
107
141
|
}
|
|
142
|
+
async function hostForm() {
|
|
143
|
+
if (process.platform === 'darwin') {
|
|
144
|
+
const battery = await run('pmset', ['-g', 'batt'], 10_000);
|
|
145
|
+
return battery.status === 0 && battery.output.includes('InternalBattery') ? 'laptop' : 'desktop';
|
|
146
|
+
}
|
|
147
|
+
if (process.platform !== 'linux')
|
|
148
|
+
return undefined;
|
|
149
|
+
const [container, version, chassis] = await Promise.all([
|
|
150
|
+
readFile('/.dockerenv', 'utf8').then(() => true).catch(() => false),
|
|
151
|
+
readFile('/proc/version', 'utf8').catch(() => ''),
|
|
152
|
+
readFile('/sys/class/dmi/id/chassis_type', 'utf8').catch(() => ''),
|
|
153
|
+
]);
|
|
154
|
+
if (container && hostVm(version))
|
|
155
|
+
return undefined;
|
|
156
|
+
return chassisForm(chassis);
|
|
157
|
+
}
|
|
108
158
|
export class Agents {
|
|
109
|
-
desired = { agents: [], routes: [] };
|
|
159
|
+
desired = { agents: [], routes: [], transcribe: false };
|
|
110
160
|
house;
|
|
111
161
|
reading = Promise.resolve();
|
|
112
162
|
queues = new Map();
|
|
113
163
|
installing = Promise.resolve();
|
|
164
|
+
installs = new Map();
|
|
114
165
|
readings = new Map();
|
|
115
166
|
reads = new Map();
|
|
167
|
+
starts = 0;
|
|
116
168
|
sending = Promise.resolve();
|
|
117
169
|
sent = null;
|
|
118
|
-
|
|
170
|
+
refreshing = 0;
|
|
171
|
+
changed;
|
|
172
|
+
constructor(house, changed = () => undefined) {
|
|
119
173
|
this.house = house;
|
|
174
|
+
this.changed = changed;
|
|
175
|
+
}
|
|
176
|
+
idle() {
|
|
177
|
+
return this.refreshing === 0;
|
|
120
178
|
}
|
|
121
179
|
read() {
|
|
122
180
|
return this.reading.then(() => undefined, () => undefined);
|
|
@@ -125,32 +183,45 @@ export class Agents {
|
|
|
125
183
|
return this.desired.routes.find((route) => route.agent_id === agentId);
|
|
126
184
|
}
|
|
127
185
|
refresh() {
|
|
186
|
+
this.refreshing++;
|
|
187
|
+
this.changed();
|
|
128
188
|
const reading = this.read().then(async () => {
|
|
129
189
|
this.desired = await this.house.deliver('/kit/agents/desired', {});
|
|
130
190
|
return this.desired;
|
|
131
191
|
});
|
|
132
192
|
this.reading = reading;
|
|
133
|
-
|
|
193
|
+
reading
|
|
194
|
+
.then(({ agents, transcribe }) => Promise.all([
|
|
195
|
+
holdTranscription(transcribe)
|
|
196
|
+
.then((changed) => (changed ? this.report() : undefined))
|
|
197
|
+
.catch(logged),
|
|
134
198
|
Promise.all(agents.map((kind) => this.load(kind)))
|
|
135
199
|
.then(() => this.report())
|
|
136
|
-
.catch(logged)
|
|
200
|
+
.catch(logged),
|
|
201
|
+
]))
|
|
202
|
+
.catch(() => undefined)
|
|
203
|
+
.finally(() => {
|
|
204
|
+
this.refreshing--;
|
|
205
|
+
this.changed();
|
|
137
206
|
});
|
|
207
|
+
return reading.then(() => undefined);
|
|
138
208
|
}
|
|
139
209
|
cli(kind) {
|
|
210
|
+
this.starts += 1;
|
|
140
211
|
return this.queue(kind, async () => {
|
|
141
212
|
const resolved = await this.resolve(kind);
|
|
142
213
|
if (!('cli' in resolved)) {
|
|
143
214
|
this.update(kind, resolved);
|
|
144
|
-
throw new Error(resolved.failure
|
|
215
|
+
throw new Error(resolved.failure === null ? tooOld(kind, resolved.release) : NOT_READY);
|
|
145
216
|
}
|
|
146
217
|
const { cli, release } = resolved;
|
|
147
218
|
const known = this.readings.get(kind);
|
|
148
219
|
const kept = known?.release === null || known?.minimum !== undefined ? SIGNED_OUT : (known ?? SIGNED_OUT);
|
|
149
|
-
if (known?.release !== release || known.minimum !== undefined) {
|
|
220
|
+
if (known?.release !== release || known.minimum !== undefined || this.installs.has(kind)) {
|
|
150
221
|
this.update(kind, { release, failure: null, signed_in: kept.signed_in, models: kept.models, modes: kept.modes });
|
|
151
222
|
}
|
|
152
223
|
const read = this.nextRead(kind);
|
|
153
|
-
|
|
224
|
+
this.quietOffer(kind, cli, kept)
|
|
154
225
|
.then((offered) => {
|
|
155
226
|
const current = this.readings.get(kind);
|
|
156
227
|
if (this.reads.get(kind) === read && current?.release === release)
|
|
@@ -160,17 +231,25 @@ export class Agents {
|
|
|
160
231
|
return cli;
|
|
161
232
|
});
|
|
162
233
|
}
|
|
163
|
-
located(kind) {
|
|
164
|
-
|
|
234
|
+
located(kind, signal) {
|
|
235
|
+
const owner = {};
|
|
236
|
+
return this.queue(kind, () => this.ensure(kind, signal, owner).finally(() => this.settle(kind, owner)), signal);
|
|
165
237
|
}
|
|
166
238
|
async reread(kind) {
|
|
167
239
|
await this.examine(kind, this.readings.get(kind) ?? SIGNED_OUT, offer);
|
|
168
240
|
await this.report();
|
|
169
241
|
}
|
|
170
|
-
async recheck(kind) {
|
|
242
|
+
async recheck(kind, signal) {
|
|
171
243
|
const known = this.readings.get(kind) ?? SIGNED_OUT;
|
|
172
|
-
|
|
173
|
-
|
|
244
|
+
const owner = {};
|
|
245
|
+
try {
|
|
246
|
+
await this.examine(kind, known, (kind, cli) => offer(kind, cli, known, AbortSignal.any([signal, AbortSignal.timeout(SIGNED_IN_READ_MS)])), signal, owner);
|
|
247
|
+
}
|
|
248
|
+
finally {
|
|
249
|
+
this.settle(kind, owner);
|
|
250
|
+
}
|
|
251
|
+
if (!signal.aborted)
|
|
252
|
+
await this.report();
|
|
174
253
|
}
|
|
175
254
|
report() {
|
|
176
255
|
const sending = this.sending.catch(() => undefined).then(() => this.send());
|
|
@@ -182,43 +261,58 @@ export class Agents {
|
|
|
182
261
|
this.reads.set(kind, read);
|
|
183
262
|
return read;
|
|
184
263
|
}
|
|
185
|
-
|
|
264
|
+
hold(kind, reading) {
|
|
186
265
|
this.readings.set(kind, reading);
|
|
266
|
+
this.installs.delete(kind);
|
|
267
|
+
}
|
|
268
|
+
update(kind, reading) {
|
|
269
|
+
this.hold(kind, reading);
|
|
270
|
+
this.report().catch(logged);
|
|
271
|
+
}
|
|
272
|
+
settle(kind, owner) {
|
|
273
|
+
if (this.installs.get(kind) !== owner)
|
|
274
|
+
return;
|
|
275
|
+
this.installs.delete(kind);
|
|
187
276
|
this.report().catch(logged);
|
|
188
277
|
}
|
|
189
|
-
queue(kind, work) {
|
|
190
|
-
const queued = (this.queues.get(kind) ?? Promise.resolve()).then(
|
|
278
|
+
queue(kind, work, signal) {
|
|
279
|
+
const queued = (this.queues.get(kind) ?? Promise.resolve()).then(() => {
|
|
280
|
+
signal?.throwIfAborted();
|
|
281
|
+
return work();
|
|
282
|
+
});
|
|
191
283
|
this.queues.set(kind, queued.catch(() => undefined));
|
|
192
|
-
return queued;
|
|
284
|
+
return signal === undefined ? queued : Promise.race([queued, ended(signal)]);
|
|
193
285
|
}
|
|
194
|
-
async ensure(kind) {
|
|
195
|
-
const failed = await installAdapter(kind);
|
|
286
|
+
async ensure(kind, signal, owner = {}) {
|
|
287
|
+
const failed = await installAdapter(kind, signal);
|
|
196
288
|
if (failed !== null)
|
|
197
289
|
throw new Error(failed);
|
|
198
|
-
const found = await locate(kind);
|
|
290
|
+
const found = await locate(kind, signal);
|
|
199
291
|
if (found !== null)
|
|
200
292
|
return found;
|
|
201
|
-
|
|
293
|
+
this.installs.set(kind, owner);
|
|
294
|
+
this.report().catch(logged);
|
|
295
|
+
const installing = this.installing.catch(() => undefined).then(() => installCli(kind, signal));
|
|
202
296
|
this.installing = installing;
|
|
203
297
|
const failure = await installing;
|
|
204
298
|
if (failure !== null)
|
|
205
299
|
throw new Error(failure);
|
|
206
|
-
const installed = await locate(kind);
|
|
300
|
+
const installed = await locate(kind, signal);
|
|
207
301
|
if (installed === null)
|
|
208
302
|
throw new Error(`the login shell does not find ${CLIS[kind].bin} after its install`);
|
|
209
303
|
return installed;
|
|
210
304
|
}
|
|
211
|
-
async resolve(kind) {
|
|
305
|
+
async resolve(kind, signal, owner) {
|
|
212
306
|
let cli;
|
|
213
307
|
try {
|
|
214
|
-
cli = await realpath(await this.ensure(kind));
|
|
308
|
+
cli = await realpath(await this.ensure(kind, signal, owner));
|
|
215
309
|
}
|
|
216
310
|
catch (error) {
|
|
217
311
|
const failure = causeOf(error);
|
|
218
312
|
process.stderr.write(`kit: ${kind} did not install: ${failure}\n`);
|
|
219
313
|
return { release: null, failure, ...SIGNED_OUT };
|
|
220
314
|
}
|
|
221
|
-
const release = await versionOf(cli);
|
|
315
|
+
const release = await versionOf(cli, signal);
|
|
222
316
|
if (release === null)
|
|
223
317
|
return { release: null, failure: `${cli} --version names no version`, ...SIGNED_OUT };
|
|
224
318
|
const minimum = CLIS[kind].minimum;
|
|
@@ -226,30 +320,43 @@ export class Agents {
|
|
|
226
320
|
return { release, minimum, failure: null, ...SIGNED_OUT };
|
|
227
321
|
return { cli, release };
|
|
228
322
|
}
|
|
229
|
-
async examine(kind, known, read) {
|
|
323
|
+
async examine(kind, known, read, signal, owner) {
|
|
230
324
|
const current = this.nextRead(kind);
|
|
231
|
-
const resolved = await this.queue(kind, () => this.resolve(kind));
|
|
325
|
+
const resolved = await this.queue(kind, () => this.resolve(kind, signal, owner), signal);
|
|
232
326
|
const reading = 'cli' in resolved ? { release: resolved.release, failure: null, ...(await read(kind, resolved.cli, known)) } : resolved;
|
|
233
|
-
if (this.reads.get(kind) === current)
|
|
234
|
-
this.
|
|
327
|
+
if (this.reads.get(kind) === current && !signal?.aborted)
|
|
328
|
+
this.hold(kind, reading);
|
|
329
|
+
}
|
|
330
|
+
async quietOffer(kind, cli, known) {
|
|
331
|
+
for (let seen = -1; seen !== this.starts;) {
|
|
332
|
+
seen = this.starts;
|
|
333
|
+
await delay(MODEL_PROBE_QUIET_MS);
|
|
334
|
+
}
|
|
335
|
+
return offer(kind, cli, known);
|
|
235
336
|
}
|
|
236
337
|
async load(kind) {
|
|
237
338
|
const known = this.readings.get(kind);
|
|
238
|
-
if (known !== undefined && known.failure === null)
|
|
339
|
+
if (known !== undefined && known.failure === null && known.minimum === undefined)
|
|
239
340
|
return;
|
|
240
|
-
await this.examine(kind, SIGNED_OUT,
|
|
341
|
+
await this.examine(kind, SIGNED_OUT, (kind, cli, known) => this.quietOffer(kind, cli, known));
|
|
342
|
+
await this.report();
|
|
241
343
|
}
|
|
242
344
|
async send() {
|
|
243
345
|
const agents = this.desired.agents.flatMap((kind) => {
|
|
244
|
-
const reading = this.readings.get(kind);
|
|
346
|
+
const reading = this.installs.has(kind) ? INSTALLING : this.readings.get(kind);
|
|
245
347
|
return reading === undefined ? [] : [reported(kind, reading)];
|
|
246
348
|
});
|
|
247
349
|
const hostKey = await sshHostKey();
|
|
350
|
+
const form = await hostForm();
|
|
248
351
|
const body = {
|
|
249
352
|
os: await operatingSystem(),
|
|
250
|
-
|
|
353
|
+
...(form === undefined ? {} : { form }),
|
|
354
|
+
kit_release: KIT_RELEASE,
|
|
355
|
+
wire: KIT_WIRE,
|
|
356
|
+
updates_itself: await updatesItself(),
|
|
251
357
|
agent_base: agentBase(),
|
|
252
358
|
agents,
|
|
359
|
+
transcription: transcriptionReport(),
|
|
253
360
|
...(hostKey === null ? {} : { ssh_host_key: hostKey }),
|
|
254
361
|
};
|
|
255
362
|
const state = JSON.stringify(body);
|
package/dist/api.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
import { setTimeout as delay } from 'node:timers/promises';
|
|
2
|
+
import { signInAgain } from './end.js';
|
|
1
3
|
import { readEnrolment } from './home.js';
|
|
4
|
+
import { retryable } from './refusals.js';
|
|
2
5
|
import { relayed } from './relay.js';
|
|
6
|
+
import { endUnserved, KIT_WIRE, KIT_WIRE_HEADER } from './wire.js';
|
|
3
7
|
export class HouseRefusal extends Error {
|
|
4
8
|
status;
|
|
5
9
|
text;
|
|
@@ -9,27 +13,54 @@ export class HouseRefusal extends Error {
|
|
|
9
13
|
this.text = text;
|
|
10
14
|
}
|
|
11
15
|
}
|
|
16
|
+
export function finalRefusal(error) {
|
|
17
|
+
return error instanceof HouseRefusal && retryable(error.text) === false;
|
|
18
|
+
}
|
|
12
19
|
export function retryDelay(attempt) {
|
|
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.
|
|
13
21
|
return Math.random() * Math.min(30_000, 1000 * 2 ** attempt);
|
|
14
22
|
}
|
|
23
|
+
export async function retrying(sent, signal, pause = retryDelay) {
|
|
24
|
+
for (let attempt = 0;; attempt++) {
|
|
25
|
+
try {
|
|
26
|
+
return await sent();
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
if (!(error instanceof HouseRefusal) || retryable(error.text) !== true)
|
|
30
|
+
throw error;
|
|
31
|
+
}
|
|
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 });
|
|
34
|
+
}
|
|
35
|
+
}
|
|
15
36
|
export async function post(house, path, body, credential, signal) {
|
|
16
37
|
const answer = await fetch(relayed(new URL(path, house)), {
|
|
17
38
|
method: 'POST',
|
|
18
39
|
headers: {
|
|
19
40
|
'content-type': 'application/json',
|
|
41
|
+
[KIT_WIRE_HEADER]: String(KIT_WIRE),
|
|
20
42
|
...(credential === undefined ? {} : { authorization: `Bearer ${credential}` }),
|
|
21
43
|
},
|
|
22
44
|
body: JSON.stringify(body),
|
|
23
45
|
signal,
|
|
24
46
|
});
|
|
25
47
|
const text = await answer.text();
|
|
48
|
+
if (!answer.ok)
|
|
49
|
+
endUnserved(text);
|
|
26
50
|
if (!answer.ok)
|
|
27
51
|
throw new HouseRefusal(path, answer.status, text);
|
|
28
52
|
return JSON.parse(text);
|
|
29
53
|
}
|
|
30
54
|
async function enrolledPost(path, body, signal) {
|
|
31
55
|
const { house, credential } = (await readEnrolment());
|
|
32
|
-
|
|
56
|
+
try {
|
|
57
|
+
return await post(house, path, body, credential, signal);
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
if (error instanceof HouseRefusal && error.status === 401)
|
|
61
|
+
await signInAgain(credential);
|
|
62
|
+
throw error;
|
|
63
|
+
}
|
|
33
64
|
}
|
|
34
65
|
export const house = {
|
|
35
66
|
post: enrolledPost,
|
|
@@ -39,9 +70,10 @@ export const house = {
|
|
|
39
70
|
return await enrolledPost(path, body);
|
|
40
71
|
}
|
|
41
72
|
catch (error) {
|
|
42
|
-
if (error
|
|
73
|
+
if (finalRefusal(error))
|
|
43
74
|
throw error;
|
|
44
75
|
process.stderr.write(`kit: ${path} did not reach House: ${error.message}\n`);
|
|
76
|
+
// A delivery House did not take is sent again on the jittered curve for as long as it is still current.
|
|
45
77
|
await new Promise((resolve) => setTimeout(resolve, retryDelay(attempt)));
|
|
46
78
|
if (!current())
|
|
47
79
|
throw error;
|
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 {
|