@agentshouse/kit 0.2.1-ce145e9aadbf6 → 0.2.1-ce3d2bb67177c
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 +40 -39
- package/dist/acp.js +48 -105
- package/dist/agents.js +153 -43
- package/dist/api.js +34 -2
- package/dist/app-git.js +48 -0
- package/dist/bootstrap.json +4 -4
- package/dist/bridge.js +36 -57
- package/dist/calls.js +63 -0
- package/dist/chatgpt.js +32 -0
- package/dist/clis.js +127 -70
- package/dist/codex-main.js +58 -0
- package/dist/connection.js +125 -0
- package/dist/conversations.js +620 -323
- package/dist/copies.js +188 -128
- package/dist/end.js +27 -0
- package/dist/enrol-main.js +7 -1
- package/dist/events.js +525 -0
- package/dist/files.js +123 -17
- package/dist/git.js +11 -9
- package/dist/home.js +96 -7
- package/dist/house-cli.js +327 -0
- package/dist/house-main.js +7 -159
- package/dist/instructions.js +10 -32
- package/dist/kit-cli.js +68 -0
- package/dist/kit-main.js +8 -19
- package/dist/login.js +117 -104
- package/dist/logout.js +14 -13
- package/dist/mcp.js +4 -2
- package/dist/parts.js +82 -0
- package/dist/placement.js +39 -0
- package/dist/refusals.js +12 -0
- package/dist/relay.js +12 -2
- package/dist/resident.js +106 -50
- package/dist/scope.js +206 -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 +37 -31
- package/dist/skills.js +84 -15
- package/dist/transcription.js +100 -21
- package/dist/translate.js +2 -8
- package/dist/update.js +71 -50
- package/dist/wire.js +22 -0
- package/dist/work.js +346 -0
- package/how-we-work.md +13 -3
- package/package.json +4 -3
- package/skills/ask-matt/SKILL.md +17 -11
- package/skills/ask-matt/agents/openai.yaml +1 -0
- package/skills/code-review/SKILL.md +5 -5
- package/skills/codebase-design/DESIGN-IT-TWICE.md +1 -1
- package/skills/codebase-design/SKILL.md +0 -2
- package/skills/diagnosing-bugs/SKILL.md +2 -4
- package/skills/domain-modeling/{CONTEXT-FORMAT.md → GLOSSARY-FORMAT.md} +10 -10
- package/skills/domain-modeling/SKILL.md +12 -14
- package/skills/grill-me/SKILL.md +1 -2
- package/skills/grill-me/agents/openai.yaml +1 -0
- package/skills/grill-with-docs/SKILL.md +1 -2
- package/skills/grill-with-docs/agents/openai.yaml +1 -0
- package/skills/grilling/SKILL.md +2 -2
- package/skills/handoff/SKILL.md +2 -3
- package/skills/handoff/agents/openai.yaml +1 -0
- package/skills/implement/SKILL.md +5 -4
- package/skills/implement/agents/openai.yaml +1 -0
- package/skills/implement-spec/SKILL.md +40 -0
- package/skills/implement-spec/agents/openai.yaml +5 -0
- package/skills/improve-codebase-architecture/SKILL.md +6 -7
- package/skills/improve-codebase-architecture/agents/openai.yaml +1 -0
- package/skills/pr/CREDITS.md +3 -0
- package/skills/pr/LICENSE +21 -0
- package/skills/pr/SKILL.md +170 -0
- package/skills/pr/agents/openai.yaml +3 -0
- package/skills/prototype/SKILL.md +0 -2
- package/skills/research/SKILL.md +0 -2
- package/skills/retro/LICENSE +21 -0
- package/skills/retro/SKILL.md +44 -0
- package/skills/retro/agents/openai.yaml +5 -0
- package/skills/tdd/SKILL.md +2 -4
- package/skills/teach/SKILL.md +3 -4
- package/skills/teach/agents/openai.yaml +1 -0
- package/skills/to-questionnaire/SKILL.md +1 -2
- package/skills/to-questionnaire/agents/openai.yaml +1 -0
- package/skills/to-spec/SKILL.md +1 -2
- package/skills/to-spec/agents/openai.yaml +1 -0
- package/skills/to-tickets/SKILL.md +3 -4
- package/skills/to-tickets/agents/openai.yaml +1 -0
- package/skills/triage/AGENT-BRIEF.md +207 -0
- package/skills/triage/LICENSE +21 -0
- package/skills/triage/OUT-OF-SCOPE.md +105 -0
- package/skills/triage/SKILL.md +112 -0
- package/skills/triage/agents/openai.yaml +5 -0
- package/skills/wait-what/SKILL.md +2 -3
- package/skills/wait-what/agents/openai.yaml +1 -0
- package/skills/wayfinder/SKILL.md +5 -6
- package/skills/wayfinder/agents/openai.yaml +1 -0
- package/skills/wizard/LICENSE +21 -0
- package/skills/wizard/SKILL.md +44 -0
- package/skills/wizard/agents/openai.yaml +3 -0
- package/skills/wizard/template.sh +223 -0
- package/skills/writing-for-agents/SKILL.md +0 -2
- package/dist/blocks.js +0 -51
- package/dist/stream.js +0 -47
- package/skills/resolving-merge-conflicts/SKILL.md +0 -16
- package/skills/resolving-merge-conflicts/agents/openai.yaml +0 -3
- /package/skills/{resolving-merge-conflicts → implement-spec}/LICENSE +0 -0
package/dist/agents.js
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
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 { 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;
|
|
6
12
|
const SIGNED_OUT = { signed_in: false, models: [], modes: [] };
|
|
13
|
+
const INSTALLING = { release: null, failure: null, installing: true, ...SIGNED_OUT };
|
|
7
14
|
function select(options, category) {
|
|
8
15
|
const option = options.find((candidate) => candidate.category === category);
|
|
9
16
|
return option?.type === 'select' ? option : undefined;
|
|
@@ -20,6 +27,22 @@ function causeOf(error) {
|
|
|
20
27
|
function logged(error) {
|
|
21
28
|
process.stderr.write(`kit: ${causeOf(error)}\n`);
|
|
22
29
|
}
|
|
30
|
+
const LAPTOP_CHASSIS = new Set(['8', '9', '10', '14', '30', '31', '32']);
|
|
31
|
+
const DESKTOP_CHASSIS = new Set(['3', '4', '5', '6', '7', '15', '16']);
|
|
32
|
+
const SERVER_CHASSIS = new Set(['17', '18', '19', '20', '21', '22', '23', '24']);
|
|
33
|
+
export function chassisForm(value) {
|
|
34
|
+
const chassis = value.trim();
|
|
35
|
+
if (LAPTOP_CHASSIS.has(chassis))
|
|
36
|
+
return 'laptop';
|
|
37
|
+
if (DESKTOP_CHASSIS.has(chassis))
|
|
38
|
+
return 'desktop';
|
|
39
|
+
if (SERVER_CHASSIS.has(chassis))
|
|
40
|
+
return 'server';
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
export function hostVm(version) {
|
|
44
|
+
return /docker desktop|microsoft|wsl|linuxkit/i.test(version);
|
|
45
|
+
}
|
|
23
46
|
async function models(kind, adapter, known) {
|
|
24
47
|
const agent = adapter.connection.agent;
|
|
25
48
|
const opened = await agent.request('session/new', { cwd: kitHome(), mcpServers: [] });
|
|
@@ -46,19 +69,29 @@ async function models(kind, adapter, known) {
|
|
|
46
69
|
}
|
|
47
70
|
return { models: offered, modes };
|
|
48
71
|
}
|
|
49
|
-
async function signedIn(kind, cli, known) {
|
|
72
|
+
async function signedIn(kind, cli, known, signal) {
|
|
50
73
|
const probe = CLIS[kind].signedIn;
|
|
74
|
+
// A sign-in check that has not answered in half a minute counts as signed out rather than stalling the report.
|
|
51
75
|
if ('command' in probe)
|
|
52
|
-
return (await run(cli, probe.command, 30_000)).status === 0;
|
|
53
|
-
return (await offer(kind, cli, known)).signed_in;
|
|
76
|
+
return (await run(cli, probe.command, 30_000, false, signal)).status === 0;
|
|
77
|
+
return (await offer(kind, cli, known, signal)).signed_in;
|
|
78
|
+
}
|
|
79
|
+
function ended(signal) {
|
|
80
|
+
return new Promise((_, reject) => {
|
|
81
|
+
if (signal.aborted)
|
|
82
|
+
reject(signal.reason);
|
|
83
|
+
signal.addEventListener('abort', () => reject(signal.reason), { once: true });
|
|
84
|
+
});
|
|
54
85
|
}
|
|
55
|
-
async function offer(kind, cli, known) {
|
|
86
|
+
async function offer(kind, cli, known, signal) {
|
|
56
87
|
const probe = CLIS[kind].signedIn;
|
|
57
|
-
|
|
88
|
+
// A sign-in check that has not answered in half a minute counts as signed out rather than stalling the report.
|
|
89
|
+
if ('command' in probe && (await run(cli, probe.command, 30_000, false, signal)).status !== 0)
|
|
58
90
|
return SIGNED_OUT;
|
|
59
91
|
let adapter;
|
|
60
92
|
try {
|
|
61
|
-
adapter = await startAdapter(kind, cli, kitHome(), client({ name: '@agentshouse/kit' }));
|
|
93
|
+
adapter = await startAdapter(kind, cli, kitHome(), client({ name: '@agentshouse/kit' }), () => undefined, {}, signal);
|
|
94
|
+
signal?.throwIfAborted();
|
|
62
95
|
if ('initializeMeta' in probe) {
|
|
63
96
|
const method = adapter.initialized._meta?.[probe.initializeMeta];
|
|
64
97
|
if (typeof method !== 'string' || method.length === 0)
|
|
@@ -67,7 +100,8 @@ async function offer(kind, cli, known) {
|
|
|
67
100
|
return { signed_in: true, ...(await models(kind, adapter, known.models)) };
|
|
68
101
|
}
|
|
69
102
|
catch (error) {
|
|
70
|
-
|
|
103
|
+
if (!signal?.aborted)
|
|
104
|
+
process.stderr.write(`kit: ${kind} did not offer its models: ${causeOf(error)}\n`);
|
|
71
105
|
return {
|
|
72
106
|
signed_in: adapter === undefined && 'initializeMeta' in probe ? known.signed_in : true,
|
|
73
107
|
models: known.models,
|
|
@@ -75,8 +109,7 @@ async function offer(kind, cli, known) {
|
|
|
75
109
|
};
|
|
76
110
|
}
|
|
77
111
|
finally {
|
|
78
|
-
|
|
79
|
-
killTree(adapter.child);
|
|
112
|
+
adapter?.retire();
|
|
80
113
|
}
|
|
81
114
|
}
|
|
82
115
|
function reported(kind, reading) {
|
|
@@ -85,38 +118,66 @@ function reported(kind, reading) {
|
|
|
85
118
|
release: reading.release,
|
|
86
119
|
...(reading.minimum === undefined ? {} : { minimum: reading.minimum }),
|
|
87
120
|
failure: reading.failure,
|
|
121
|
+
...(reading.installing === undefined ? {} : { installing: reading.installing }),
|
|
88
122
|
signed_in: reading.signed_in,
|
|
89
123
|
models: reading.models,
|
|
90
124
|
modes: reading.modes,
|
|
91
125
|
full_access: CLIS[kind].fullAccess,
|
|
92
126
|
};
|
|
93
127
|
}
|
|
128
|
+
const NOT_READY = "the Agent's CLI is not ready on this computer";
|
|
94
129
|
function tooOld(kind, release) {
|
|
95
130
|
const cli = CLIS[kind];
|
|
96
131
|
return `${cli.bin} ${release} is older than ${cli.minimum}, the oldest this Kit runs`;
|
|
97
132
|
}
|
|
98
133
|
async function sshHostKey() {
|
|
134
|
+
// Listing a local host key takes a moment, so ten seconds only bounds a stuck ssh-keygen.
|
|
99
135
|
const listed = await run('ssh-keygen', ['-l', '-E', 'sha256', '-f', '/etc/ssh/ssh_host_ed25519_key.pub'], 10_000);
|
|
100
136
|
return listed.status === 0 ? (/^\d+ (SHA256:\S+)/.exec(listed.output)?.[1] ?? null) : null;
|
|
101
137
|
}
|
|
102
138
|
async function operatingSystem() {
|
|
139
|
+
// sw_vers answers at once, so ten seconds only bounds a stuck call.
|
|
103
140
|
if (process.platform === 'darwin')
|
|
104
141
|
return `macOS ${(await run('sw_vers', ['-productVersion'], 10_000)).output.trim()}`;
|
|
105
142
|
const release = await readFile('/etc/os-release', 'utf8');
|
|
106
143
|
return /^PRETTY_NAME="?([^"\n]*)"?$/m.exec(release)?.[1] ?? release;
|
|
107
144
|
}
|
|
145
|
+
async function hostForm() {
|
|
146
|
+
if (process.platform === 'darwin') {
|
|
147
|
+
const battery = await run('pmset', ['-g', 'batt'], 10_000);
|
|
148
|
+
return battery.status === 0 && battery.output.includes('InternalBattery') ? 'laptop' : 'desktop';
|
|
149
|
+
}
|
|
150
|
+
if (process.platform !== 'linux')
|
|
151
|
+
return undefined;
|
|
152
|
+
const [container, version, chassis] = await Promise.all([
|
|
153
|
+
readFile('/.dockerenv', 'utf8').then(() => true).catch(() => false),
|
|
154
|
+
readFile('/proc/version', 'utf8').catch(() => ''),
|
|
155
|
+
readFile('/sys/class/dmi/id/chassis_type', 'utf8').catch(() => ''),
|
|
156
|
+
]);
|
|
157
|
+
if (container && hostVm(version))
|
|
158
|
+
return undefined;
|
|
159
|
+
return chassisForm(chassis);
|
|
160
|
+
}
|
|
108
161
|
export class Agents {
|
|
109
|
-
desired = { agents: [], routes: [] };
|
|
162
|
+
desired = { agents: [], routes: [], transcribe: false };
|
|
110
163
|
house;
|
|
111
164
|
reading = Promise.resolve();
|
|
112
165
|
queues = new Map();
|
|
113
166
|
installing = Promise.resolve();
|
|
167
|
+
installs = new Map();
|
|
114
168
|
readings = new Map();
|
|
115
169
|
reads = new Map();
|
|
170
|
+
starts = 0;
|
|
116
171
|
sending = Promise.resolve();
|
|
117
172
|
sent = null;
|
|
118
|
-
|
|
173
|
+
refreshing = 0;
|
|
174
|
+
changed;
|
|
175
|
+
constructor(house, changed = () => undefined) {
|
|
119
176
|
this.house = house;
|
|
177
|
+
this.changed = changed;
|
|
178
|
+
}
|
|
179
|
+
idle() {
|
|
180
|
+
return this.refreshing === 0;
|
|
120
181
|
}
|
|
121
182
|
read() {
|
|
122
183
|
return this.reading.then(() => undefined, () => undefined);
|
|
@@ -125,32 +186,45 @@ export class Agents {
|
|
|
125
186
|
return this.desired.routes.find((route) => route.agent_id === agentId);
|
|
126
187
|
}
|
|
127
188
|
refresh() {
|
|
189
|
+
this.refreshing++;
|
|
190
|
+
this.changed();
|
|
128
191
|
const reading = this.read().then(async () => {
|
|
129
192
|
this.desired = await this.house.deliver('/kit/agents/desired', {});
|
|
130
193
|
return this.desired;
|
|
131
194
|
});
|
|
132
195
|
this.reading = reading;
|
|
133
|
-
|
|
196
|
+
reading
|
|
197
|
+
.then(({ agents, transcribe }) => Promise.all([
|
|
198
|
+
holdTranscription(transcribe)
|
|
199
|
+
.then((changed) => (changed ? this.report() : undefined))
|
|
200
|
+
.catch(logged),
|
|
134
201
|
Promise.all(agents.map((kind) => this.load(kind)))
|
|
135
202
|
.then(() => this.report())
|
|
136
|
-
.catch(logged)
|
|
203
|
+
.catch(logged),
|
|
204
|
+
]))
|
|
205
|
+
.catch(() => undefined)
|
|
206
|
+
.finally(() => {
|
|
207
|
+
this.refreshing--;
|
|
208
|
+
this.changed();
|
|
137
209
|
});
|
|
210
|
+
return reading.then(() => undefined);
|
|
138
211
|
}
|
|
139
212
|
cli(kind) {
|
|
213
|
+
this.starts += 1;
|
|
140
214
|
return this.queue(kind, async () => {
|
|
141
215
|
const resolved = await this.resolve(kind);
|
|
142
216
|
if (!('cli' in resolved)) {
|
|
143
217
|
this.update(kind, resolved);
|
|
144
|
-
throw new Error(resolved.failure
|
|
218
|
+
throw new Error(resolved.failure === null ? tooOld(kind, resolved.release) : NOT_READY);
|
|
145
219
|
}
|
|
146
220
|
const { cli, release } = resolved;
|
|
147
221
|
const known = this.readings.get(kind);
|
|
148
222
|
const kept = known?.release === null || known?.minimum !== undefined ? SIGNED_OUT : (known ?? SIGNED_OUT);
|
|
149
|
-
if (known?.release !== release || known.minimum !== undefined) {
|
|
223
|
+
if (known?.release !== release || known.minimum !== undefined || this.installs.has(kind)) {
|
|
150
224
|
this.update(kind, { release, failure: null, signed_in: kept.signed_in, models: kept.models, modes: kept.modes });
|
|
151
225
|
}
|
|
152
226
|
const read = this.nextRead(kind);
|
|
153
|
-
|
|
227
|
+
this.quietOffer(kind, cli, kept)
|
|
154
228
|
.then((offered) => {
|
|
155
229
|
const current = this.readings.get(kind);
|
|
156
230
|
if (this.reads.get(kind) === read && current?.release === release)
|
|
@@ -160,17 +234,25 @@ export class Agents {
|
|
|
160
234
|
return cli;
|
|
161
235
|
});
|
|
162
236
|
}
|
|
163
|
-
located(kind) {
|
|
164
|
-
|
|
237
|
+
located(kind, signal) {
|
|
238
|
+
const owner = {};
|
|
239
|
+
return this.queue(kind, () => this.ensure(kind, signal, owner).finally(() => this.settle(kind, owner)), signal);
|
|
165
240
|
}
|
|
166
241
|
async reread(kind) {
|
|
167
242
|
await this.examine(kind, this.readings.get(kind) ?? SIGNED_OUT, offer);
|
|
168
243
|
await this.report();
|
|
169
244
|
}
|
|
170
|
-
async recheck(kind) {
|
|
245
|
+
async recheck(kind, signal) {
|
|
171
246
|
const known = this.readings.get(kind) ?? SIGNED_OUT;
|
|
172
|
-
|
|
173
|
-
|
|
247
|
+
const owner = {};
|
|
248
|
+
try {
|
|
249
|
+
await this.examine(kind, known, async (kind, cli) => ((await signedIn(kind, cli, known, signal)) ? { ...known, signed_in: true } : SIGNED_OUT), signal, owner);
|
|
250
|
+
}
|
|
251
|
+
finally {
|
|
252
|
+
this.settle(kind, owner);
|
|
253
|
+
}
|
|
254
|
+
if (!signal.aborted)
|
|
255
|
+
await this.report();
|
|
174
256
|
}
|
|
175
257
|
report() {
|
|
176
258
|
const sending = this.sending.catch(() => undefined).then(() => this.send());
|
|
@@ -182,43 +264,58 @@ export class Agents {
|
|
|
182
264
|
this.reads.set(kind, read);
|
|
183
265
|
return read;
|
|
184
266
|
}
|
|
185
|
-
|
|
267
|
+
hold(kind, reading) {
|
|
186
268
|
this.readings.set(kind, reading);
|
|
269
|
+
this.installs.delete(kind);
|
|
270
|
+
}
|
|
271
|
+
update(kind, reading) {
|
|
272
|
+
this.hold(kind, reading);
|
|
273
|
+
this.report().catch(logged);
|
|
274
|
+
}
|
|
275
|
+
settle(kind, owner) {
|
|
276
|
+
if (this.installs.get(kind) !== owner)
|
|
277
|
+
return;
|
|
278
|
+
this.installs.delete(kind);
|
|
187
279
|
this.report().catch(logged);
|
|
188
280
|
}
|
|
189
|
-
queue(kind, work) {
|
|
190
|
-
const queued = (this.queues.get(kind) ?? Promise.resolve()).then(
|
|
281
|
+
queue(kind, work, signal) {
|
|
282
|
+
const queued = (this.queues.get(kind) ?? Promise.resolve()).then(() => {
|
|
283
|
+
signal?.throwIfAborted();
|
|
284
|
+
return work();
|
|
285
|
+
});
|
|
191
286
|
this.queues.set(kind, queued.catch(() => undefined));
|
|
192
|
-
return queued;
|
|
287
|
+
return signal === undefined ? queued : Promise.race([queued, ended(signal)]);
|
|
193
288
|
}
|
|
194
|
-
async ensure(kind) {
|
|
195
|
-
const failed = await installAdapter(kind);
|
|
289
|
+
async ensure(kind, signal, owner = {}) {
|
|
290
|
+
const failed = await installAdapter(kind, signal);
|
|
196
291
|
if (failed !== null)
|
|
197
292
|
throw new Error(failed);
|
|
198
|
-
const found = await locate(kind);
|
|
293
|
+
const found = await locate(kind, signal);
|
|
199
294
|
if (found !== null)
|
|
200
295
|
return found;
|
|
201
|
-
|
|
296
|
+
this.installs.set(kind, owner);
|
|
297
|
+
this.report().catch(logged);
|
|
298
|
+
const installing = this.installing.catch(() => undefined).then(() => installCli(kind, signal));
|
|
202
299
|
this.installing = installing;
|
|
203
300
|
const failure = await installing;
|
|
204
301
|
if (failure !== null)
|
|
205
302
|
throw new Error(failure);
|
|
206
|
-
const installed = await locate(kind);
|
|
303
|
+
const installed = await locate(kind, signal);
|
|
207
304
|
if (installed === null)
|
|
208
305
|
throw new Error(`the login shell does not find ${CLIS[kind].bin} after its install`);
|
|
209
306
|
return installed;
|
|
210
307
|
}
|
|
211
|
-
async resolve(kind) {
|
|
308
|
+
async resolve(kind, signal, owner) {
|
|
212
309
|
let cli;
|
|
213
310
|
try {
|
|
214
|
-
cli = await realpath(await this.ensure(kind));
|
|
311
|
+
cli = await realpath(await this.ensure(kind, signal, owner));
|
|
215
312
|
}
|
|
216
313
|
catch (error) {
|
|
217
314
|
const failure = causeOf(error);
|
|
218
315
|
process.stderr.write(`kit: ${kind} did not install: ${failure}\n`);
|
|
219
316
|
return { release: null, failure, ...SIGNED_OUT };
|
|
220
317
|
}
|
|
221
|
-
const release = await versionOf(cli);
|
|
318
|
+
const release = await versionOf(cli, signal);
|
|
222
319
|
if (release === null)
|
|
223
320
|
return { release: null, failure: `${cli} --version names no version`, ...SIGNED_OUT };
|
|
224
321
|
const minimum = CLIS[kind].minimum;
|
|
@@ -226,30 +323,43 @@ export class Agents {
|
|
|
226
323
|
return { release, minimum, failure: null, ...SIGNED_OUT };
|
|
227
324
|
return { cli, release };
|
|
228
325
|
}
|
|
229
|
-
async examine(kind, known, read) {
|
|
326
|
+
async examine(kind, known, read, signal, owner) {
|
|
230
327
|
const current = this.nextRead(kind);
|
|
231
|
-
const resolved = await this.queue(kind, () => this.resolve(kind));
|
|
328
|
+
const resolved = await this.queue(kind, () => this.resolve(kind, signal, owner), signal);
|
|
232
329
|
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.
|
|
330
|
+
if (this.reads.get(kind) === current && !signal?.aborted)
|
|
331
|
+
this.hold(kind, reading);
|
|
332
|
+
}
|
|
333
|
+
async quietOffer(kind, cli, known) {
|
|
334
|
+
for (let seen = -1; seen !== this.starts;) {
|
|
335
|
+
seen = this.starts;
|
|
336
|
+
await delay(MODEL_PROBE_QUIET_MS);
|
|
337
|
+
}
|
|
338
|
+
return offer(kind, cli, known);
|
|
235
339
|
}
|
|
236
340
|
async load(kind) {
|
|
237
341
|
const known = this.readings.get(kind);
|
|
238
|
-
if (known !== undefined && known.failure === null)
|
|
342
|
+
if (known !== undefined && known.failure === null && known.minimum === undefined)
|
|
239
343
|
return;
|
|
240
|
-
await this.examine(kind, SIGNED_OUT,
|
|
344
|
+
await this.examine(kind, SIGNED_OUT, (kind, cli, known) => this.quietOffer(kind, cli, known));
|
|
345
|
+
await this.report();
|
|
241
346
|
}
|
|
242
347
|
async send() {
|
|
243
348
|
const agents = this.desired.agents.flatMap((kind) => {
|
|
244
|
-
const reading = this.readings.get(kind);
|
|
349
|
+
const reading = this.installs.has(kind) ? INSTALLING : this.readings.get(kind);
|
|
245
350
|
return reading === undefined ? [] : [reported(kind, reading)];
|
|
246
351
|
});
|
|
247
352
|
const hostKey = await sshHostKey();
|
|
353
|
+
const form = await hostForm();
|
|
248
354
|
const body = {
|
|
249
355
|
os: await operatingSystem(),
|
|
250
|
-
|
|
356
|
+
...(form === undefined ? {} : { form }),
|
|
357
|
+
kit_release: KIT_RELEASE,
|
|
358
|
+
wire: KIT_WIRE,
|
|
359
|
+
updates_itself: await updatesItself(),
|
|
251
360
|
agent_base: agentBase(),
|
|
252
361
|
agents,
|
|
362
|
+
transcription: transcriptionReport(),
|
|
253
363
|
...(hostKey === null ? {} : { ssh_host_key: hostKey }),
|
|
254
364
|
};
|
|
255
365
|
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/bootstrap.json
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 2,
|
|
3
|
-
"version": "0.2.1-
|
|
3
|
+
"version": "0.2.1-ce3d2bb67177c",
|
|
4
4
|
"hosts": {
|
|
5
5
|
"macos": {
|
|
6
6
|
"asset": {
|
|
7
7
|
"name": "connect-linux.sh",
|
|
8
|
-
"url": "https://github.com/agentshouse/kit/releases/download/v0.2.1-
|
|
8
|
+
"url": "https://github.com/agentshouse/kit/releases/download/v0.2.1-ce3d2bb67177c/connect-linux.sh"
|
|
9
9
|
}
|
|
10
10
|
},
|
|
11
11
|
"linux": {
|
|
12
12
|
"asset": {
|
|
13
13
|
"name": "connect-linux.sh",
|
|
14
|
-
"url": "https://github.com/agentshouse/kit/releases/download/v0.2.1-
|
|
14
|
+
"url": "https://github.com/agentshouse/kit/releases/download/v0.2.1-ce3d2bb67177c/connect-linux.sh"
|
|
15
15
|
}
|
|
16
16
|
},
|
|
17
17
|
"windows": {
|
|
18
18
|
"asset": {
|
|
19
19
|
"name": "connect-windows.ps1",
|
|
20
|
-
"url": "https://github.com/agentshouse/kit/releases/download/v0.2.1-
|
|
20
|
+
"url": "https://github.com/agentshouse/kit/releases/download/v0.2.1-ce3d2bb67177c/connect-windows.ps1"
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
}
|