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