@agentshouse/kit 0.2.1-c3895fcff473b → 0.2.1-c4ea88ba9424e
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 +8 -9
- package/dist/acp.js +4 -1
- package/dist/agents.js +61 -31
- package/dist/api.js +30 -2
- package/dist/app-git.js +64 -0
- package/dist/bootstrap.json +4 -4
- package/dist/bridge.js +25 -17
- package/dist/clis.js +29 -13
- package/dist/conversations.js +7 -6
- package/dist/copies.js +3 -5
- package/dist/end.js +8 -0
- package/dist/kit-main.js +3 -0
- package/dist/login.js +4 -0
- package/dist/logout.js +3 -0
- package/dist/refusals.js +12 -0
- package/dist/resident.js +1 -3
- package/dist/secret-input.js +4 -1
- package/dist/shell.js +3 -0
- package/dist/sign-in.js +33 -8
- package/dist/stream.js +29 -4
- package/dist/transcription.js +54 -6
- package/dist/update.js +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -37,10 +37,11 @@ them out; running it again without the flag brings them back.
|
|
|
37
37
|
Environment's credential in `~/.house-kit`, or in `$HOUSE_KIT_HOME` when it is
|
|
38
38
|
set. Pass `--manual` to paste the code by hand on a machine without a browser,
|
|
39
39
|
and `--environment <id>` to reconnect an Environment you already have. It also
|
|
40
|
-
connects your own agent:
|
|
41
|
-
House as you
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
connects your own agent: outside an Agent conversation, `house <tool>` calls
|
|
41
|
+
House as you and `git` clones and pushes your Apps at `<house>/app/` as you,
|
|
42
|
+
until you revoke that connection on Connections. `house help` lists the Tools.
|
|
43
|
+
`kit logout` disconnects this computer, stops House Kit and ends that Git
|
|
44
|
+
access; a later `kit login` reconnects the same Environment.
|
|
44
45
|
|
|
45
46
|
`kit resident` keeps the Environment connected, and keeps the Rooms you chose
|
|
46
47
|
for this Environment as Git repositories under `local-copies` in the
|
|
@@ -49,11 +50,9 @@ commit to House; in the container, run it through the install command from the
|
|
|
49
50
|
copy's directory. Inside an Agent conversation the Agent runs `house push`.
|
|
50
51
|
|
|
51
52
|
House Kit turns each audio file of your message to an Agent into text on this
|
|
52
|
-
computer before the Agent reads
|
|
53
|
-
|
|
53
|
+
computer before the Agent reads it. While transcription is on, the speech
|
|
54
|
+
engine and model use about 425 MB in `~/.house-kit`; turning it off deletes them.
|
|
54
55
|
|
|
55
56
|
## License
|
|
56
57
|
|
|
57
|
-
MIT
|
|
58
|
-
|
|
59
|
-
The skills come from [mattpocock/skills](https://github.com/mattpocock/skills); thank you, Matt Pocock.
|
|
58
|
+
MIT. The skills come from [mattpocock/skills](https://github.com/mattpocock/skills); thank you, Matt Pocock.
|
package/dist/acp.js
CHANGED
|
@@ -5,7 +5,7 @@ import { Readable, Writable } from 'node:stream';
|
|
|
5
5
|
import { CLIS, KIT_VERSION, adapterCommand, withoutProxy } from './clis.js';
|
|
6
6
|
export const TURN_STARTED = 'kit/turn_started';
|
|
7
7
|
export const TURN_ENDED = 'kit/turn_ended';
|
|
8
|
-
export async function startAdapter(kind, cli, cwd, app, jobs = () => undefined, added = {}) {
|
|
8
|
+
export async function startAdapter(kind, cli, cwd, app, jobs = () => undefined, added = {}, signal) {
|
|
9
9
|
const adapter = CLIS[kind].adapter;
|
|
10
10
|
const child = spawn(adapter === null ? cli : adapterCommand(kind), CLIS[kind].args, {
|
|
11
11
|
cwd,
|
|
@@ -13,6 +13,9 @@ export async function startAdapter(kind, cli, cwd, app, jobs = () => undefined,
|
|
|
13
13
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
14
14
|
detached: true,
|
|
15
15
|
});
|
|
16
|
+
const stop = () => killTree(child);
|
|
17
|
+
signal?.addEventListener('abort', stop, { once: true });
|
|
18
|
+
child.on('exit', () => signal?.removeEventListener('abort', stop));
|
|
16
19
|
let stderr = '';
|
|
17
20
|
child.stderr.on('data', (chunk) => {
|
|
18
21
|
stderr = (stderr + chunk.toString('utf8')).slice(-4000);
|
package/dist/agents.js
CHANGED
|
@@ -3,6 +3,7 @@ import { readFile, realpath } from 'node:fs/promises';
|
|
|
3
3
|
import { killTree, startAdapter } from './acp.js';
|
|
4
4
|
import { CLIS, KIT_VERSION, below, installAdapter, installCli, locate, run, versionOf } from './clis.js';
|
|
5
5
|
import { agentBase, kitHome } from './home.js';
|
|
6
|
+
import { holdTranscription, transcriptionReport } from './transcription.js';
|
|
6
7
|
const SIGNED_OUT = { signed_in: false, models: [], modes: [] };
|
|
7
8
|
function select(options, category) {
|
|
8
9
|
const option = options.find((candidate) => candidate.category === category);
|
|
@@ -46,13 +47,29 @@ async function models(kind, adapter, known) {
|
|
|
46
47
|
}
|
|
47
48
|
return { models: offered, modes };
|
|
48
49
|
}
|
|
49
|
-
async function
|
|
50
|
+
async function signedIn(kind, cli, known, signal) {
|
|
50
51
|
const probe = CLIS[kind].signedIn;
|
|
51
|
-
|
|
52
|
+
// A sign-in check that has not answered in half a minute counts as signed out rather than stalling the report.
|
|
53
|
+
if ('command' in probe)
|
|
54
|
+
return (await run(cli, probe.command, 30_000, false, signal)).status === 0;
|
|
55
|
+
return (await offer(kind, cli, known, signal)).signed_in;
|
|
56
|
+
}
|
|
57
|
+
function ended(signal) {
|
|
58
|
+
return new Promise((_, reject) => {
|
|
59
|
+
if (signal.aborted)
|
|
60
|
+
reject(signal.reason);
|
|
61
|
+
signal.addEventListener('abort', () => reject(signal.reason), { once: true });
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
async function offer(kind, cli, known, signal) {
|
|
65
|
+
const probe = CLIS[kind].signedIn;
|
|
66
|
+
// A sign-in check that has not answered in half a minute counts as signed out rather than stalling the report.
|
|
67
|
+
if ('command' in probe && (await run(cli, probe.command, 30_000, false, signal)).status !== 0)
|
|
52
68
|
return SIGNED_OUT;
|
|
53
69
|
let adapter;
|
|
54
70
|
try {
|
|
55
|
-
adapter = await startAdapter(kind, cli, kitHome(), client({ name: '@agentshouse/kit' }));
|
|
71
|
+
adapter = await startAdapter(kind, cli, kitHome(), client({ name: '@agentshouse/kit' }), () => undefined, {}, signal);
|
|
72
|
+
signal?.throwIfAborted();
|
|
56
73
|
if ('initializeMeta' in probe) {
|
|
57
74
|
const method = adapter.initialized._meta?.[probe.initializeMeta];
|
|
58
75
|
if (typeof method !== 'string' || method.length === 0)
|
|
@@ -61,7 +78,8 @@ async function offer(kind, cli, known) {
|
|
|
61
78
|
return { signed_in: true, ...(await models(kind, adapter, known.models)) };
|
|
62
79
|
}
|
|
63
80
|
catch (error) {
|
|
64
|
-
|
|
81
|
+
if (!signal?.aborted)
|
|
82
|
+
process.stderr.write(`kit: ${kind} did not offer its models: ${causeOf(error)}\n`);
|
|
65
83
|
return {
|
|
66
84
|
signed_in: adapter === undefined && 'initializeMeta' in probe ? known.signed_in : true,
|
|
67
85
|
models: known.models,
|
|
@@ -90,17 +108,19 @@ function tooOld(kind, release) {
|
|
|
90
108
|
return `${cli.bin} ${release} is older than ${cli.minimum}, the oldest this Kit runs`;
|
|
91
109
|
}
|
|
92
110
|
async function sshHostKey() {
|
|
111
|
+
// Listing a local host key takes a moment, so ten seconds only bounds a stuck ssh-keygen.
|
|
93
112
|
const listed = await run('ssh-keygen', ['-l', '-E', 'sha256', '-f', '/etc/ssh/ssh_host_ed25519_key.pub'], 10_000);
|
|
94
113
|
return listed.status === 0 ? (/^\d+ (SHA256:\S+)/.exec(listed.output)?.[1] ?? null) : null;
|
|
95
114
|
}
|
|
96
115
|
async function operatingSystem() {
|
|
116
|
+
// sw_vers answers at once, so ten seconds only bounds a stuck call.
|
|
97
117
|
if (process.platform === 'darwin')
|
|
98
118
|
return `macOS ${(await run('sw_vers', ['-productVersion'], 10_000)).output.trim()}`;
|
|
99
119
|
const release = await readFile('/etc/os-release', 'utf8');
|
|
100
120
|
return /^PRETTY_NAME="?([^"\n]*)"?$/m.exec(release)?.[1] ?? release;
|
|
101
121
|
}
|
|
102
122
|
export class Agents {
|
|
103
|
-
desired = { agents: [], routes: [] };
|
|
123
|
+
desired = { agents: [], routes: [], transcribe: false };
|
|
104
124
|
house;
|
|
105
125
|
reading = Promise.resolve();
|
|
106
126
|
queues = new Map();
|
|
@@ -124,8 +144,11 @@ export class Agents {
|
|
|
124
144
|
return this.desired;
|
|
125
145
|
});
|
|
126
146
|
this.reading = reading;
|
|
127
|
-
return reading.then(({ agents }) => {
|
|
128
|
-
|
|
147
|
+
return reading.then(({ agents, transcribe }) => {
|
|
148
|
+
holdTranscription(transcribe)
|
|
149
|
+
.then((changed) => (changed ? this.report() : undefined))
|
|
150
|
+
.catch(logged);
|
|
151
|
+
Promise.all(agents.map((kind) => this.load(kind)))
|
|
129
152
|
.then(() => this.report())
|
|
130
153
|
.catch(logged);
|
|
131
154
|
});
|
|
@@ -154,16 +177,19 @@ export class Agents {
|
|
|
154
177
|
return cli;
|
|
155
178
|
});
|
|
156
179
|
}
|
|
157
|
-
located(kind) {
|
|
158
|
-
return this.queue(kind, () => this.ensure(kind));
|
|
180
|
+
located(kind, signal) {
|
|
181
|
+
return this.queue(kind, () => this.ensure(kind, signal), signal);
|
|
159
182
|
}
|
|
160
183
|
async reread(kind) {
|
|
161
|
-
await this.
|
|
162
|
-
this.nextRead(kind);
|
|
163
|
-
this.readings.set(kind, await this.examine(kind, this.readings.get(kind) ?? SIGNED_OUT));
|
|
164
|
-
});
|
|
184
|
+
await this.examine(kind, this.readings.get(kind) ?? SIGNED_OUT, offer);
|
|
165
185
|
await this.report();
|
|
166
186
|
}
|
|
187
|
+
async recheck(kind, signal) {
|
|
188
|
+
const known = this.readings.get(kind) ?? SIGNED_OUT;
|
|
189
|
+
await this.examine(kind, known, async (kind, cli) => ((await signedIn(kind, cli, known, signal)) ? { ...known, signed_in: true } : SIGNED_OUT), signal);
|
|
190
|
+
if (!signal.aborted)
|
|
191
|
+
await this.report();
|
|
192
|
+
}
|
|
167
193
|
report() {
|
|
168
194
|
const sending = this.sending.catch(() => undefined).then(() => this.send());
|
|
169
195
|
this.sending = sending;
|
|
@@ -178,39 +204,42 @@ export class Agents {
|
|
|
178
204
|
this.readings.set(kind, reading);
|
|
179
205
|
this.report().catch(logged);
|
|
180
206
|
}
|
|
181
|
-
queue(kind, work) {
|
|
182
|
-
const queued = (this.queues.get(kind) ?? Promise.resolve()).then(
|
|
207
|
+
queue(kind, work, signal) {
|
|
208
|
+
const queued = (this.queues.get(kind) ?? Promise.resolve()).then(() => {
|
|
209
|
+
signal?.throwIfAborted();
|
|
210
|
+
return work();
|
|
211
|
+
});
|
|
183
212
|
this.queues.set(kind, queued.catch(() => undefined));
|
|
184
|
-
return queued;
|
|
213
|
+
return signal === undefined ? queued : Promise.race([queued, ended(signal)]);
|
|
185
214
|
}
|
|
186
|
-
async ensure(kind) {
|
|
187
|
-
const failed = await installAdapter(kind);
|
|
215
|
+
async ensure(kind, signal) {
|
|
216
|
+
const failed = await installAdapter(kind, signal);
|
|
188
217
|
if (failed !== null)
|
|
189
218
|
throw new Error(failed);
|
|
190
|
-
const found = await locate(kind);
|
|
219
|
+
const found = await locate(kind, signal);
|
|
191
220
|
if (found !== null)
|
|
192
221
|
return found;
|
|
193
|
-
const installing = this.installing.catch(() => undefined).then(() => installCli(kind));
|
|
222
|
+
const installing = this.installing.catch(() => undefined).then(() => installCli(kind, signal));
|
|
194
223
|
this.installing = installing;
|
|
195
224
|
const failure = await installing;
|
|
196
225
|
if (failure !== null)
|
|
197
226
|
throw new Error(failure);
|
|
198
|
-
const installed = await locate(kind);
|
|
227
|
+
const installed = await locate(kind, signal);
|
|
199
228
|
if (installed === null)
|
|
200
229
|
throw new Error(`the login shell does not find ${CLIS[kind].bin} after its install`);
|
|
201
230
|
return installed;
|
|
202
231
|
}
|
|
203
|
-
async resolve(kind) {
|
|
232
|
+
async resolve(kind, signal) {
|
|
204
233
|
let cli;
|
|
205
234
|
try {
|
|
206
|
-
cli = await realpath(await this.ensure(kind));
|
|
235
|
+
cli = await realpath(await this.ensure(kind, signal));
|
|
207
236
|
}
|
|
208
237
|
catch (error) {
|
|
209
238
|
const failure = causeOf(error);
|
|
210
239
|
process.stderr.write(`kit: ${kind} did not install: ${failure}\n`);
|
|
211
240
|
return { release: null, failure, ...SIGNED_OUT };
|
|
212
241
|
}
|
|
213
|
-
const release = await versionOf(cli);
|
|
242
|
+
const release = await versionOf(cli, signal);
|
|
214
243
|
if (release === null)
|
|
215
244
|
return { release: null, failure: `${cli} --version names no version`, ...SIGNED_OUT };
|
|
216
245
|
const minimum = CLIS[kind].minimum;
|
|
@@ -218,18 +247,18 @@ export class Agents {
|
|
|
218
247
|
return { release, minimum, failure: null, ...SIGNED_OUT };
|
|
219
248
|
return { cli, release };
|
|
220
249
|
}
|
|
221
|
-
async examine(kind, known) {
|
|
222
|
-
const
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
250
|
+
async examine(kind, known, read, signal) {
|
|
251
|
+
const current = this.nextRead(kind);
|
|
252
|
+
const resolved = await this.queue(kind, () => this.resolve(kind, signal), signal);
|
|
253
|
+
const reading = 'cli' in resolved ? { release: resolved.release, failure: null, ...(await read(kind, resolved.cli, known)) } : resolved;
|
|
254
|
+
if (this.reads.get(kind) === current && !signal?.aborted)
|
|
255
|
+
this.readings.set(kind, reading);
|
|
226
256
|
}
|
|
227
257
|
async load(kind) {
|
|
228
258
|
const known = this.readings.get(kind);
|
|
229
259
|
if (known !== undefined && known.failure === null)
|
|
230
260
|
return;
|
|
231
|
-
this.
|
|
232
|
-
this.readings.set(kind, await this.examine(kind, SIGNED_OUT));
|
|
261
|
+
await this.examine(kind, SIGNED_OUT, offer);
|
|
233
262
|
}
|
|
234
263
|
async send() {
|
|
235
264
|
const agents = this.desired.agents.flatMap((kind) => {
|
|
@@ -242,6 +271,7 @@ export class Agents {
|
|
|
242
271
|
kit_version: KIT_VERSION,
|
|
243
272
|
agent_base: agentBase(),
|
|
244
273
|
agents,
|
|
274
|
+
transcription: transcriptionReport(),
|
|
245
275
|
...(hostKey === null ? {} : { ssh_host_key: hostKey }),
|
|
246
276
|
};
|
|
247
277
|
const state = JSON.stringify(body);
|
package/dist/api.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import { setTimeout as delay } from 'node:timers/promises';
|
|
2
|
+
import { end, SIGN_IN_AGAIN } from './end.js';
|
|
1
3
|
import { readEnrolment } from './home.js';
|
|
4
|
+
import { retryable } from './refusals.js';
|
|
2
5
|
import { relayed } from './relay.js';
|
|
3
6
|
export class HouseRefusal extends Error {
|
|
4
7
|
status;
|
|
@@ -9,9 +12,26 @@ export class HouseRefusal extends Error {
|
|
|
9
12
|
this.text = text;
|
|
10
13
|
}
|
|
11
14
|
}
|
|
15
|
+
export function finalRefusal(error) {
|
|
16
|
+
return error instanceof HouseRefusal && retryable(error.text) === false;
|
|
17
|
+
}
|
|
12
18
|
export function retryDelay(attempt) {
|
|
19
|
+
// Full jitter, doubling from one second to a 30-second cap, spreads the Kits one outage dropped and retries within half a minute of House's return.
|
|
13
20
|
return Math.random() * Math.min(30_000, 1000 * 2 ** attempt);
|
|
14
21
|
}
|
|
22
|
+
export async function retrying(sent, signal) {
|
|
23
|
+
for (let attempt = 0;; attempt++) {
|
|
24
|
+
try {
|
|
25
|
+
return await sent();
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
if (!(error instanceof HouseRefusal) || retryable(error.text) !== true)
|
|
29
|
+
throw error;
|
|
30
|
+
}
|
|
31
|
+
// A request House refused as retryable is sent again on the jittered curve.
|
|
32
|
+
await delay(retryDelay(attempt), undefined, { signal });
|
|
33
|
+
}
|
|
34
|
+
}
|
|
15
35
|
export async function post(house, path, body, credential, signal) {
|
|
16
36
|
const answer = await fetch(relayed(new URL(path, house)), {
|
|
17
37
|
method: 'POST',
|
|
@@ -29,7 +49,14 @@ export async function post(house, path, body, credential, signal) {
|
|
|
29
49
|
}
|
|
30
50
|
async function enrolledPost(path, body, signal) {
|
|
31
51
|
const { house, credential } = (await readEnrolment());
|
|
32
|
-
|
|
52
|
+
try {
|
|
53
|
+
return await post(house, path, body, credential, signal);
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
if (error instanceof HouseRefusal && error.status === 401)
|
|
57
|
+
end(SIGN_IN_AGAIN);
|
|
58
|
+
throw error;
|
|
59
|
+
}
|
|
33
60
|
}
|
|
34
61
|
export const house = {
|
|
35
62
|
post: enrolledPost,
|
|
@@ -39,9 +66,10 @@ export const house = {
|
|
|
39
66
|
return await enrolledPost(path, body);
|
|
40
67
|
}
|
|
41
68
|
catch (error) {
|
|
42
|
-
if (error
|
|
69
|
+
if (finalRefusal(error))
|
|
43
70
|
throw error;
|
|
44
71
|
process.stderr.write(`kit: ${path} did not reach House: ${error.message}\n`);
|
|
72
|
+
// A delivery House did not take is sent again on the jittered curve for as long as it is still current.
|
|
45
73
|
await new Promise((resolve) => setTimeout(resolve, retryDelay(attempt)));
|
|
46
74
|
if (!current())
|
|
47
75
|
throw error;
|
package/dist/app-git.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { extname, resolve } from 'node:path';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
import { run } from './git.js';
|
|
4
|
+
import { kitHome, readOwnAgent } from './home.js';
|
|
5
|
+
import { quoted } from './shell.js';
|
|
6
|
+
function section(house) {
|
|
7
|
+
return `credential.${new URL('/app/', house).href}`;
|
|
8
|
+
}
|
|
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
|
+
async function configured(args) {
|
|
14
|
+
try {
|
|
15
|
+
return await run(kitHome(), ['config', '--global', ...args]);
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
if (error.code === 'ENOENT')
|
|
19
|
+
return null;
|
|
20
|
+
throw error;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
async function forget(house) {
|
|
24
|
+
await configured(['--remove-section', section(house)]);
|
|
25
|
+
}
|
|
26
|
+
async function register(house) {
|
|
27
|
+
await forget(house);
|
|
28
|
+
for (const value of ['', helper()]) {
|
|
29
|
+
const ran = await configured(['--add', `${section(house)}.helper`, value]);
|
|
30
|
+
if (ran === null)
|
|
31
|
+
return;
|
|
32
|
+
if (ran.status !== 0)
|
|
33
|
+
throw new Error(`git config failed: ${ran.stderr.trim()}`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
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
|
+
export async function answerGitCredential(operation) {
|
|
48
|
+
let asked = '';
|
|
49
|
+
for await (const chunk of process.stdin)
|
|
50
|
+
asked += String(chunk);
|
|
51
|
+
if (operation !== 'get')
|
|
52
|
+
return;
|
|
53
|
+
const attributes = new Map(asked
|
|
54
|
+
.split('\n')
|
|
55
|
+
.filter((line) => line.includes('='))
|
|
56
|
+
.map((line) => [line.slice(0, line.indexOf('=')), line.slice(line.indexOf('=') + 1)]));
|
|
57
|
+
const ownAgent = await readOwnAgent();
|
|
58
|
+
if (ownAgent === null)
|
|
59
|
+
return;
|
|
60
|
+
const house = new URL(ownAgent.house);
|
|
61
|
+
if (attributes.get('protocol') !== house.protocol.slice(0, -1) || attributes.get('host') !== house.host)
|
|
62
|
+
return;
|
|
63
|
+
process.stdout.write(`username=house\npassword=${ownAgent.credential}\n`);
|
|
64
|
+
}
|
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-c4ea88ba9424e",
|
|
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-c4ea88ba9424e/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-c4ea88ba9424e/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-c4ea88ba9424e/connect-windows.ps1"
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
}
|
package/dist/bridge.js
CHANGED
|
@@ -6,13 +6,13 @@ import { createServer, request as httpRequest } from 'node:http';
|
|
|
6
6
|
import { request as httpsRequest } from 'node:https';
|
|
7
7
|
import { delimiter, dirname, join } from 'node:path';
|
|
8
8
|
import { parse } from 'yaml';
|
|
9
|
-
import { HouseRefusal, retryDelay } from './api.js';
|
|
9
|
+
import { finalRefusal, HouseRefusal, retryDelay, retrying } from './api.js';
|
|
10
10
|
import { loginPath } from './clis.js';
|
|
11
11
|
import { changedPaths, } from './copies.js';
|
|
12
12
|
import { kitHome, readEnrolment } from './home.js';
|
|
13
13
|
import { callHouse, mcpBody, rpc, UNREACHABLE } from './mcp.js';
|
|
14
14
|
import { operationId, uuidOf } from './operation.js';
|
|
15
|
-
import { refusalOf } from './refusals.js';
|
|
15
|
+
import { refusalOf, retryable } from './refusals.js';
|
|
16
16
|
import { relayed } from './relay.js';
|
|
17
17
|
const MCP_REQUEST_BYTES = 4 * 1024 * 1024;
|
|
18
18
|
const ATTACHMENTS = '/kit/attachments/upload';
|
|
@@ -40,8 +40,6 @@ function refusalIn(text, status) {
|
|
|
40
40
|
return refusalOf(text) ?? { code: '', text: text === '' ? `House refused it with ${status}` : text, conflicts: [] };
|
|
41
41
|
}
|
|
42
42
|
function answered(forwarded) {
|
|
43
|
-
if (forwarded.status >= 500)
|
|
44
|
-
throw new HouseRefusal('/', forwarded.status, forwarded.text);
|
|
45
43
|
if (forwarded.status !== 200)
|
|
46
44
|
return { refused: refusalIn(forwarded.text, forwarded.status) };
|
|
47
45
|
const answer = JSON.parse(forwarded.text);
|
|
@@ -65,8 +63,8 @@ function pendingSeconds(forwarded) {
|
|
|
65
63
|
function resendAfter(forwarded, attempt) {
|
|
66
64
|
if (forwarded === null)
|
|
67
65
|
return retryDelay(attempt);
|
|
68
|
-
if (forwarded.status
|
|
69
|
-
return
|
|
66
|
+
if (forwarded.status !== 200)
|
|
67
|
+
return retryable(forwarded.text) === false ? null : retryDelay(attempt);
|
|
70
68
|
const seconds = pendingSeconds(forwarded);
|
|
71
69
|
return seconds === null ? null : seconds * 1000;
|
|
72
70
|
}
|
|
@@ -105,6 +103,7 @@ export async function openBridge(house, copies, conversationId, signal) {
|
|
|
105
103
|
const after = resendAfter(forwarded, attempt);
|
|
106
104
|
if (after === null)
|
|
107
105
|
return forwarded;
|
|
106
|
+
// A write House did not settle is sent again on the jittered curve, or after the wait House names for a pending one.
|
|
108
107
|
await delay(after, undefined, { signal: closed.signal });
|
|
109
108
|
}
|
|
110
109
|
};
|
|
@@ -119,17 +118,26 @@ export async function openBridge(house, copies, conversationId, signal) {
|
|
|
119
118
|
if ('refused' in prepared)
|
|
120
119
|
return prepared;
|
|
121
120
|
const { transfer } = parse(prepared.text);
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
121
|
+
let text;
|
|
122
|
+
try {
|
|
123
|
+
text = await retrying(async () => {
|
|
124
|
+
const posted = await fetch(relayed(transfer.url), {
|
|
125
|
+
method: 'POST',
|
|
126
|
+
headers: { 'content-type': 'text/plain; charset=utf-8' },
|
|
127
|
+
body: Buffer.concat([Buffer.from(`${transfer.operation}\n`), bytes]),
|
|
128
|
+
signal: closed.signal,
|
|
129
|
+
});
|
|
130
|
+
const answer = await posted.text();
|
|
131
|
+
if (!posted.ok)
|
|
132
|
+
throw new HouseRefusal('/', posted.status, answer);
|
|
133
|
+
return answer;
|
|
134
|
+
}, closed.signal);
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
if (!finalRefusal(error))
|
|
138
|
+
throw error;
|
|
139
|
+
return { refused: refusalIn(error.text, error.status) };
|
|
140
|
+
}
|
|
133
141
|
const held = JSON.parse(text).transfer;
|
|
134
142
|
return { url: held.url, operation: held.operation, bytes: bytes.length, sha256 };
|
|
135
143
|
};
|
package/dist/clis.js
CHANGED
|
@@ -105,7 +105,9 @@ const KIT_PACKAGE = JSON.parse(readFileSync(new URL('../package.json', import.me
|
|
|
105
105
|
export const KIT_VERSION = KIT_PACKAGE.version;
|
|
106
106
|
const PROXY = /^https?_proxy$/i;
|
|
107
107
|
const VERSION = /\d+\.\d+\.\d+(?:-[0-9A-Za-z.]+)?/;
|
|
108
|
+
// An install still running after fifteen minutes is ended and reported as failed, so a hung download cannot hold its CLI's report.
|
|
108
109
|
const INSTALL_MS = 15 * 60_000;
|
|
110
|
+
// A login shell or a version read is ended after half a minute, so a profile that waits for input cannot stall the report.
|
|
109
111
|
const READ_MS = 30_000;
|
|
110
112
|
const CAUSE_CHARACTERS = 4000;
|
|
111
113
|
function prefix(kind) {
|
|
@@ -133,8 +135,22 @@ export function run(command, args, timeoutMs, detached = false, signal) {
|
|
|
133
135
|
timeout: timeoutMs,
|
|
134
136
|
env: withoutProxy(),
|
|
135
137
|
detached,
|
|
136
|
-
signal,
|
|
138
|
+
signal: detached ? undefined : signal,
|
|
137
139
|
});
|
|
140
|
+
const stop = () => {
|
|
141
|
+
try {
|
|
142
|
+
process.kill(-child.pid, 'SIGKILL');
|
|
143
|
+
}
|
|
144
|
+
catch { }
|
|
145
|
+
};
|
|
146
|
+
if (detached && signal?.aborted)
|
|
147
|
+
stop();
|
|
148
|
+
if (detached)
|
|
149
|
+
signal?.addEventListener('abort', stop, { once: true });
|
|
150
|
+
const ended = (ran) => {
|
|
151
|
+
signal?.removeEventListener('abort', stop);
|
|
152
|
+
resolve(ran);
|
|
153
|
+
};
|
|
138
154
|
let stdout = '';
|
|
139
155
|
let output = '';
|
|
140
156
|
child.stdout.setEncoding('utf8').on('data', (chunk) => {
|
|
@@ -144,25 +160,25 @@ export function run(command, args, timeoutMs, detached = false, signal) {
|
|
|
144
160
|
child.stderr.setEncoding('utf8').on('data', (chunk) => {
|
|
145
161
|
output += chunk;
|
|
146
162
|
});
|
|
147
|
-
child.on('error', (error) =>
|
|
148
|
-
child.on('close', (status) =>
|
|
163
|
+
child.on('error', (error) => ended({ status: null, stdout, output: error.message }));
|
|
164
|
+
child.on('close', (status) => ended({ status, stdout, output }));
|
|
149
165
|
});
|
|
150
166
|
}
|
|
151
167
|
export function failureOf(ran, program) {
|
|
152
168
|
return ran.output.trim().slice(-CAUSE_CHARACTERS) || `${program} exited with ${ran.status ?? 'a signal'}`;
|
|
153
169
|
}
|
|
154
|
-
export async function installAdapter(kind) {
|
|
170
|
+
export async function installAdapter(kind, signal) {
|
|
155
171
|
const adapter = CLIS[kind].adapter;
|
|
156
172
|
if (adapter === null)
|
|
157
173
|
return null;
|
|
158
174
|
const release = KIT_PACKAGE.peerDependencies[adapter.package];
|
|
159
175
|
if ((await installedAdapter(kind)) === release)
|
|
160
176
|
return null;
|
|
161
|
-
const ran = await run('npm', ['install', '--prefix', prefix(kind), '--no-save', '--no-audit', '--no-fund', '--omit=optional', `${adapter.package}@${release}`], INSTALL_MS);
|
|
177
|
+
const ran = await run('npm', ['install', '--prefix', prefix(kind), '--no-save', '--no-audit', '--no-fund', '--omit=optional', `${adapter.package}@${release}`], INSTALL_MS, true, signal);
|
|
162
178
|
return ran.status === 0 ? null : failureOf(ran, 'npm');
|
|
163
179
|
}
|
|
164
|
-
export async function installCli(kind) {
|
|
165
|
-
const ran = await run('bash', ['-o', 'pipefail', '-c', CLIS[kind].install], INSTALL_MS, true);
|
|
180
|
+
export async function installCli(kind, signal) {
|
|
181
|
+
const ran = await run('bash', ['-o', 'pipefail', '-c', CLIS[kind].install], INSTALL_MS, true, signal);
|
|
166
182
|
return ran.status === 0 ? null : failureOf(ran, 'the install');
|
|
167
183
|
}
|
|
168
184
|
function loginShell() {
|
|
@@ -171,11 +187,11 @@ function loginShell() {
|
|
|
171
187
|
const FOUND = 'house-kit-cli ';
|
|
172
188
|
const LOOKUP = `found=$(command -v "$1") || exit 0; case $found in /*) ;; *) found=$(pwd -P)/$found ;; esac; printf "${FOUND}%s\\n" "$found"`;
|
|
173
189
|
const USER_BIN = 'case ":$PATH:" in *":$HOME/.local/bin:"*) ;; *) PATH="$PATH:$HOME/.local/bin" ;; esac; export PATH';
|
|
174
|
-
function inLoginShell(script, argument = '') {
|
|
175
|
-
return run(loginShell(), ['-l', '-i', '-c', `exec /bin/sh -c '${USER_BIN}; ${script}' sh ${argument}`], READ_MS, true);
|
|
190
|
+
function inLoginShell(script, argument = '', signal) {
|
|
191
|
+
return run(loginShell(), ['-l', '-i', '-c', `exec /bin/sh -c '${USER_BIN}; ${script}' sh ${argument}`], READ_MS, true, signal);
|
|
176
192
|
}
|
|
177
|
-
export async function locate(kind) {
|
|
178
|
-
const ran = await inLoginShell(LOOKUP, CLIS[kind].bin);
|
|
193
|
+
export async function locate(kind, signal) {
|
|
194
|
+
const ran = await inLoginShell(LOOKUP, CLIS[kind].bin, signal);
|
|
179
195
|
return ran.stdout.split('\n').findLast((line) => line.startsWith(FOUND))?.slice(FOUND.length) ?? null;
|
|
180
196
|
}
|
|
181
197
|
export async function loginPath() {
|
|
@@ -183,8 +199,8 @@ export async function loginPath() {
|
|
|
183
199
|
const ran = await inLoginShell(`printf "${marker}%s\\n" "$PATH"`);
|
|
184
200
|
return ran.stdout.split('\n').findLast((line) => line.startsWith(marker)).slice(marker.length);
|
|
185
201
|
}
|
|
186
|
-
export async function versionOf(path) {
|
|
187
|
-
return VERSION.exec((await run(path, ['--version'], READ_MS)).stdout)?.[0] ?? null;
|
|
202
|
+
export async function versionOf(path, signal) {
|
|
203
|
+
return VERSION.exec((await run(path, ['--version'], READ_MS, false, signal)).stdout)?.[0] ?? null;
|
|
188
204
|
}
|
|
189
205
|
function numbers(version) {
|
|
190
206
|
return version.split(/[.-]/, 3).map(Number);
|
package/dist/conversations.js
CHANGED
|
@@ -209,7 +209,7 @@ export class Conversations {
|
|
|
209
209
|
continue;
|
|
210
210
|
try {
|
|
211
211
|
const text = await transcribe(path, AbortSignal.any([conversation.killed.signal, conversation.interrupted.signal]));
|
|
212
|
-
if (text !== '')
|
|
212
|
+
if (text !== null && text !== '')
|
|
213
213
|
lines.push(`Transcript: ${text}`);
|
|
214
214
|
}
|
|
215
215
|
catch (error) {
|
|
@@ -392,10 +392,8 @@ export class Conversations {
|
|
|
392
392
|
turn.admitted = true;
|
|
393
393
|
for (const note of turn.notes.splice(0))
|
|
394
394
|
this.kit.send(note);
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
this.draft(conversation, turn);
|
|
398
|
-
}
|
|
395
|
+
turn.unsentFrom = 0;
|
|
396
|
+
this.draft(conversation, turn);
|
|
399
397
|
if (turn.entries !== null)
|
|
400
398
|
this.plan(conversation, turn);
|
|
401
399
|
}
|
|
@@ -445,8 +443,11 @@ export class Conversations {
|
|
|
445
443
|
this.attach(conversation.turn ?? this.begin(conversation), sent);
|
|
446
444
|
}
|
|
447
445
|
running.adapter.connection.agent.request('session/prompt', { sessionId: running.sessionId, prompt }).then(() => this.answered(conversation, sent, null), async (error) => {
|
|
448
|
-
if (!running.adapter.connection.signal.aborted)
|
|
446
|
+
if (!running.adapter.connection.signal.aborted) {
|
|
449
447
|
this.answered(conversation, sent, causeOf(error));
|
|
448
|
+
if (conversation.open === 0 && conversation.running === running)
|
|
449
|
+
stop(running.bridge);
|
|
450
|
+
}
|
|
450
451
|
else if (sent.turn !== null) {
|
|
451
452
|
this.end(conversation, sent.turn, { failed: running.killed ? KILLED : await running.adapter.exited });
|
|
452
453
|
}
|
package/dist/copies.js
CHANGED
|
@@ -2,7 +2,7 @@ import { parse } from '@agentshouse/mdmodel';
|
|
|
2
2
|
import { randomUUID } from 'node:crypto';
|
|
3
3
|
import { mkdir, readFile, readdir, realpath, rename, rm, rmdir, stat, writeFile } from 'node:fs/promises';
|
|
4
4
|
import { dirname, join } from 'node:path';
|
|
5
|
-
import { HouseRefusal } from './api.js';
|
|
5
|
+
import { finalRefusal, HouseRefusal, retrying } from './api.js';
|
|
6
6
|
import { blobId, blobText, git, HOUSE_REF, importCommits, localCopies, revision, run, succeeded, tree, } from './git.js';
|
|
7
7
|
import { kitHome } from './home.js';
|
|
8
8
|
import { operationId } from './operation.js';
|
|
@@ -11,7 +11,6 @@ import { changed } from './translate.js';
|
|
|
11
11
|
import { relayed } from './relay.js';
|
|
12
12
|
const BRANCH = 'main';
|
|
13
13
|
const PROVENANCE = '_provenance';
|
|
14
|
-
const REPLICA_RETRY_MS = 30_000;
|
|
15
14
|
const IDENTITY = { GIT_COMMITTER_NAME: 'House Kit', GIT_COMMITTER_EMAIL: 'house-kit@localhost' };
|
|
16
15
|
function causeOf(error) {
|
|
17
16
|
return error instanceof Error ? error.message : String(error);
|
|
@@ -161,11 +160,11 @@ export class LocalCopies {
|
|
|
161
160
|
key: 'owner',
|
|
162
161
|
submit: async (operation, changes) => {
|
|
163
162
|
try {
|
|
164
|
-
const outcome = await house.post('/kit/door/batch', { operation_id: operation, changes });
|
|
163
|
+
const outcome = await retrying(() => house.post('/kit/door/batch', { operation_id: operation, changes }));
|
|
165
164
|
return { accepted: outcome.contents };
|
|
166
165
|
}
|
|
167
166
|
catch (error) {
|
|
168
|
-
if (!(error
|
|
167
|
+
if (!finalRefusal(error))
|
|
169
168
|
throw error;
|
|
170
169
|
return {
|
|
171
170
|
refused: refusalOf(error.text) ?? { code: '', text: `House refused it with ${error.status}`, conflicts: [] },
|
|
@@ -439,7 +438,6 @@ export class LocalCopies {
|
|
|
439
438
|
return this.received(copy);
|
|
440
439
|
if (code !== 'replica_behind')
|
|
441
440
|
throw error;
|
|
442
|
-
setTimeout(() => this.deliver(copy.key), REPLICA_RETRY_MS).unref();
|
|
443
441
|
return copy;
|
|
444
442
|
}
|
|
445
443
|
const view = answer.authorities.find((entry) => entry.authority === copy.room_ref);
|
package/dist/end.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { killDescendants } from './acp.js';
|
|
2
|
+
export const REPLACED = 'another Kit started for this Environment';
|
|
3
|
+
export const SIGN_IN_AGAIN = 'sign in again';
|
|
4
|
+
export function end(reason) {
|
|
5
|
+
process.stderr.write(`kit: ${reason}\n`);
|
|
6
|
+
killDescendants();
|
|
7
|
+
process.exit(0);
|
|
8
|
+
}
|
package/dist/kit-main.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { setGlobalProxyFromEnv } from 'node:http';
|
|
3
|
+
import { answerGitCredential } from './app-git.js';
|
|
3
4
|
import { login } from './login.js';
|
|
4
5
|
import { logout } from './logout.js';
|
|
5
6
|
import { resident } from './resident.js';
|
|
@@ -12,6 +13,8 @@ async function run() {
|
|
|
12
13
|
return logout();
|
|
13
14
|
if (command === 'resident')
|
|
14
15
|
return resident();
|
|
16
|
+
if (command === 'git-credential')
|
|
17
|
+
return answerGitCredential(argv[0]);
|
|
15
18
|
process.stderr.write('usage: kit <login|logout|resident>\n');
|
|
16
19
|
process.exitCode = 2;
|
|
17
20
|
}
|
package/dist/login.js
CHANGED
|
@@ -4,6 +4,7 @@ import { hostname } from 'node:os';
|
|
|
4
4
|
import { createInterface } from 'node:readline/promises';
|
|
5
5
|
import { parseArgs } from 'node:util';
|
|
6
6
|
import { post } from './api.js';
|
|
7
|
+
import { placeAppGit } from './app-git.js';
|
|
7
8
|
import { forgetOwnAgent, readDisconnected, readEnrolment, readOwnAgent, writeEnrolment, writeOwnAgent } from './home.js';
|
|
8
9
|
import { callHouse, rpc } from './mcp.js';
|
|
9
10
|
const DEFAULT_HOUSE = 'https://agents.house';
|
|
@@ -104,6 +105,7 @@ export async function login(argv) {
|
|
|
104
105
|
process.stdout.write("This computer's own agent was another User's; run kit login again to connect it to you.\n");
|
|
105
106
|
}
|
|
106
107
|
};
|
|
108
|
+
const placeGit = async () => placeAppGit(ownAgent, await readOwnAgent());
|
|
107
109
|
if (values.manual) {
|
|
108
110
|
const { start_url } = await post(house, '/kit', {
|
|
109
111
|
...started,
|
|
@@ -111,6 +113,7 @@ export async function login(argv) {
|
|
|
111
113
|
});
|
|
112
114
|
process.stdout.write(`Open this link and confirm: ${start_url}\n`);
|
|
113
115
|
await exchange(await typed('Code: '));
|
|
116
|
+
await placeGit();
|
|
114
117
|
return;
|
|
115
118
|
}
|
|
116
119
|
const callback = await listen();
|
|
@@ -133,4 +136,5 @@ export async function login(argv) {
|
|
|
133
136
|
finally {
|
|
134
137
|
callback.close();
|
|
135
138
|
}
|
|
139
|
+
await placeGit();
|
|
136
140
|
}
|
package/dist/logout.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { HouseRefusal, post } from './api.js';
|
|
2
|
+
import { forgetAppGit } from './app-git.js';
|
|
2
3
|
import { forgetEnrolment, readEnrolment } from './home.js';
|
|
3
4
|
export async function logout() {
|
|
4
5
|
const enrolled = await readEnrolment();
|
|
5
6
|
if (enrolled === null) {
|
|
7
|
+
await forgetAppGit();
|
|
6
8
|
process.stdout.write('This computer is not connected to House.\n');
|
|
7
9
|
return;
|
|
8
10
|
}
|
|
@@ -14,5 +16,6 @@ export async function logout() {
|
|
|
14
16
|
throw error;
|
|
15
17
|
}
|
|
16
18
|
await forgetEnrolment(enrolled);
|
|
19
|
+
await forgetAppGit();
|
|
17
20
|
process.stdout.write(`Environment ${enrolled.environment} is disconnected; kit login reconnects it.\n`);
|
|
18
21
|
}
|
package/dist/refusals.js
CHANGED
|
@@ -21,6 +21,18 @@ function spoken(text) {
|
|
|
21
21
|
const detail = said.indexOf('\n');
|
|
22
22
|
return { code: head[1], text: said, conflicts: detail === -1 ? [] : conflictCodes(said.slice(detail + 1)) };
|
|
23
23
|
}
|
|
24
|
+
export function retryable(text) {
|
|
25
|
+
let body;
|
|
26
|
+
try {
|
|
27
|
+
body = JSON.parse(text);
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
const error = body?.error;
|
|
33
|
+
const verdict = error?.retryable ?? error?.data?.retryable;
|
|
34
|
+
return typeof verdict === 'boolean' ? verdict : null;
|
|
35
|
+
}
|
|
24
36
|
export function refusalOf(text) {
|
|
25
37
|
let body;
|
|
26
38
|
try {
|
package/dist/resident.js
CHANGED
|
@@ -11,6 +11,7 @@ import { received } from './bridge.js';
|
|
|
11
11
|
import { Conversations } from './conversations.js';
|
|
12
12
|
import { LocalCopies } from './copies.js';
|
|
13
13
|
import { agentBase, enrolled, kitHome } from './home.js';
|
|
14
|
+
import { quoted } from './shell.js';
|
|
14
15
|
import { SignIns } from './sign-in.js';
|
|
15
16
|
import { placeSkillSet } from './skills.js';
|
|
16
17
|
import { holdStream } from './stream.js';
|
|
@@ -21,9 +22,6 @@ function report(error) {
|
|
|
21
22
|
function logged(work) {
|
|
22
23
|
work.catch(report);
|
|
23
24
|
}
|
|
24
|
-
function quoted(value) {
|
|
25
|
-
return `'${value.replaceAll("'", `'\\''`)}'`;
|
|
26
|
-
}
|
|
27
25
|
async function installShim() {
|
|
28
26
|
const main = fileURLToPath(new URL(`./git-main${extname(fileURLToPath(import.meta.url))}`, import.meta.url));
|
|
29
27
|
await mkdir(join(kitHome(), 'shim'), { recursive: true });
|
package/dist/secret-input.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { retryDelay } from './api.js';
|
|
1
|
+
import { finalRefusal, retryDelay } from './api.js';
|
|
2
2
|
export async function holdSecretInput(house, subject, steps, waiting) {
|
|
3
3
|
for (let failures = 0; waiting();) {
|
|
4
4
|
try {
|
|
@@ -10,7 +10,10 @@ export async function holdSecretInput(house, subject, steps, waiting) {
|
|
|
10
10
|
failures = 0;
|
|
11
11
|
}
|
|
12
12
|
catch (error) {
|
|
13
|
+
if (finalRefusal(error))
|
|
14
|
+
return null;
|
|
13
15
|
process.stderr.write(`kit: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
16
|
+
// A wait that did not reach House is held again on the jittered curve for as long as its asker still waits.
|
|
14
17
|
await new Promise((resolve) => setTimeout(resolve, retryDelay(failures++)));
|
|
15
18
|
}
|
|
16
19
|
}
|
package/dist/shell.js
ADDED
package/dist/sign-in.js
CHANGED
|
@@ -12,6 +12,9 @@ function causeOf(error) {
|
|
|
12
12
|
function logged(error) {
|
|
13
13
|
process.stderr.write(`kit: ${causeOf(error)}\n`);
|
|
14
14
|
}
|
|
15
|
+
function endOf(signal) {
|
|
16
|
+
return new Promise((resolve) => signal.addEventListener('abort', () => resolve(true), { once: true }));
|
|
17
|
+
}
|
|
15
18
|
export class SignIns {
|
|
16
19
|
house;
|
|
17
20
|
agents;
|
|
@@ -30,24 +33,43 @@ export class SignIns {
|
|
|
30
33
|
return;
|
|
31
34
|
this.running.add(input.input_id);
|
|
32
35
|
this.changed();
|
|
33
|
-
this.
|
|
34
|
-
.then(() => this.agents.reread(input.cli))
|
|
35
|
-
.then(() => this.house.deliver(`/kit/inputs/${input.input_id}/ack`, {}))
|
|
36
|
+
this.signIn(input)
|
|
36
37
|
.catch(logged)
|
|
37
38
|
.finally(() => {
|
|
38
39
|
this.running.delete(input.input_id);
|
|
39
40
|
this.changed();
|
|
40
41
|
});
|
|
41
42
|
}
|
|
42
|
-
async
|
|
43
|
+
async signIn(input) {
|
|
44
|
+
const ending = new AbortController();
|
|
45
|
+
// House stops waiting for a sign-in ten minutes after it wrote it and sends the seconds left, so its install and login end with the page.
|
|
46
|
+
const timer = setTimeout(() => ending.abort(), input.ends_in * 1000);
|
|
47
|
+
const ended = await Promise.race([this.signedIn(input, ending.signal), endOf(ending.signal)]);
|
|
48
|
+
clearTimeout(timer);
|
|
49
|
+
if (ended)
|
|
50
|
+
process.stderr.write(`kit: the ${input.cli} sign-in reached the end House set for it\n`);
|
|
51
|
+
await this.house.deliver(`/kit/inputs/${input.input_id}/ack`, {});
|
|
52
|
+
if (!ended)
|
|
53
|
+
await this.agents.reread(input.cli);
|
|
54
|
+
}
|
|
55
|
+
async signedIn(input, signal) {
|
|
56
|
+
await this.login(input, signal);
|
|
57
|
+
if (!signal.aborted)
|
|
58
|
+
await this.agents.recheck(input.cli, signal);
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
async login(input, signal) {
|
|
43
62
|
let cli;
|
|
44
63
|
try {
|
|
45
|
-
cli = await this.agents.located(input.cli);
|
|
64
|
+
cli = await this.agents.located(input.cli, signal);
|
|
46
65
|
}
|
|
47
66
|
catch (error) {
|
|
48
|
-
|
|
67
|
+
if (!signal.aborted)
|
|
68
|
+
process.stderr.write(`kit: the ${input.cli} sign-in failed: ${causeOf(error)}\n`);
|
|
49
69
|
return;
|
|
50
70
|
}
|
|
71
|
+
if (signal.aborted)
|
|
72
|
+
return;
|
|
51
73
|
const login = CLIS[input.cli].login;
|
|
52
74
|
const child = spawn(cli, login.args, {
|
|
53
75
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
@@ -55,6 +77,8 @@ export class SignIns {
|
|
|
55
77
|
env: withoutProxy(),
|
|
56
78
|
});
|
|
57
79
|
const running = () => child.exitCode === null && child.signalCode === null;
|
|
80
|
+
const stop = () => killTree(child);
|
|
81
|
+
signal.addEventListener('abort', stop, { once: true });
|
|
58
82
|
let link;
|
|
59
83
|
let code;
|
|
60
84
|
let last = '';
|
|
@@ -91,9 +115,10 @@ export class SignIns {
|
|
|
91
115
|
createInterface({ input: output }).on('line', read);
|
|
92
116
|
const failed = await new Promise((resolve) => {
|
|
93
117
|
child.on('error', (error) => resolve(error.message));
|
|
94
|
-
child.on('close', (status,
|
|
118
|
+
child.on('close', (status, killed) => resolve(status === 0 ? null : `exited with ${status ?? killed}${last ? `: ${last}` : ''}`));
|
|
95
119
|
});
|
|
96
|
-
|
|
120
|
+
signal.removeEventListener('abort', stop);
|
|
121
|
+
if (failed !== null && !signal.aborted)
|
|
97
122
|
process.stderr.write(`kit: the ${input.cli} sign-in failed: ${failed}\n`);
|
|
98
123
|
}
|
|
99
124
|
}
|
package/dist/stream.js
CHANGED
|
@@ -1,17 +1,36 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { subscribe } from 'node:diagnostics_channel';
|
|
2
|
+
import { finalRefusal, HouseRefusal, retryDelay } from './api.js';
|
|
3
|
+
import { end, REPLACED, SIGN_IN_AGAIN } from './end.js';
|
|
2
4
|
import { readEnrolment } from './home.js';
|
|
3
5
|
import { relayed } from './relay.js';
|
|
6
|
+
const PATH = '/kit/stream';
|
|
4
7
|
const SUBPROTOCOL = 'house.kit.stream.1';
|
|
8
|
+
const REFUSAL_HEADER = 'x-house-refusal';
|
|
5
9
|
function streamUrl(house) {
|
|
6
|
-
const url = new URL(
|
|
10
|
+
const url = new URL(PATH, house);
|
|
7
11
|
url.protocol = url.protocol === 'https:' ? 'wss:' : 'ws:';
|
|
8
12
|
return url;
|
|
9
13
|
}
|
|
14
|
+
function header(headers, name) {
|
|
15
|
+
for (let index = 0; index < headers.length; index += 2) {
|
|
16
|
+
if (headers[index].toString('latin1').toLowerCase() === name)
|
|
17
|
+
return headers[index + 1].toString('latin1');
|
|
18
|
+
}
|
|
19
|
+
return '';
|
|
20
|
+
}
|
|
21
|
+
let refused = null;
|
|
22
|
+
subscribe('undici:request:headers', (message) => {
|
|
23
|
+
const { request, response } = message;
|
|
24
|
+
if (!request.path.endsWith(PATH))
|
|
25
|
+
return;
|
|
26
|
+
refused = new HouseRefusal(PATH, response.statusCode, header(response.headers, REFUSAL_HEADER) || response.statusText);
|
|
27
|
+
});
|
|
10
28
|
export function holdStream(handlers) {
|
|
11
29
|
let socket = null;
|
|
12
30
|
let failures = 0;
|
|
13
31
|
const connect = async () => {
|
|
14
32
|
const { house, credential } = (await readEnrolment());
|
|
33
|
+
refused = null;
|
|
15
34
|
const opening = new WebSocket(relayed(streamUrl(house)), {
|
|
16
35
|
protocols: [SUBPROTOCOL],
|
|
17
36
|
headers: { authorization: `Bearer ${credential}` },
|
|
@@ -31,8 +50,14 @@ export function holdStream(handlers) {
|
|
|
31
50
|
if (socket === opening)
|
|
32
51
|
socket = null;
|
|
33
52
|
process.stderr.write(`kit: control stream closed ${event.code} ${event.reason}\n`);
|
|
34
|
-
|
|
35
|
-
|
|
53
|
+
if (event.reason === 'replaced')
|
|
54
|
+
end(REPLACED);
|
|
55
|
+
if (event.reason === 'credential_rejected' || refused?.status === 401)
|
|
56
|
+
end(SIGN_IN_AGAIN);
|
|
57
|
+
if (finalRefusal(refused))
|
|
58
|
+
end(refused.message);
|
|
59
|
+
// A closed socket reopens in one to three seconds, spread so Kits one restart closed return apart; an opening House refused as retryable or left unanswered backs off on the jittered curve.
|
|
60
|
+
setTimeout(() => void connect(), opened ? 1000 + Math.random() * 2000 : retryDelay(failures++));
|
|
36
61
|
};
|
|
37
62
|
};
|
|
38
63
|
void connect();
|
package/dist/transcription.js
CHANGED
|
@@ -29,6 +29,10 @@ export const ENGINES = {
|
|
|
29
29
|
};
|
|
30
30
|
const CHUNK_SECONDS = 20;
|
|
31
31
|
let held = Promise.resolve();
|
|
32
|
+
let holding = Promise.resolve();
|
|
33
|
+
let setting = null;
|
|
34
|
+
let downloading = null;
|
|
35
|
+
let readiness = { installed: false, failure: null };
|
|
32
36
|
function directory() {
|
|
33
37
|
return join(kitHome(), 'transcription');
|
|
34
38
|
}
|
|
@@ -36,6 +40,7 @@ function installed(artifact) {
|
|
|
36
40
|
return join(directory(), artifact.sha256);
|
|
37
41
|
}
|
|
38
42
|
async function executed(command, args, signal) {
|
|
43
|
+
// A download or a transcription runs as long as its size needs; the setting turning off or the turn's interrupt or end aborts it instead.
|
|
39
44
|
const ran = await run(command, args, 0, false, signal);
|
|
40
45
|
if (ran.status !== 0)
|
|
41
46
|
throw new Error(failureOf(ran, basename(command)));
|
|
@@ -54,6 +59,12 @@ async function sha256(path) {
|
|
|
54
59
|
await pipeline(createReadStream(path), hash);
|
|
55
60
|
return hash.digest('hex');
|
|
56
61
|
}
|
|
62
|
+
function causeOf(error) {
|
|
63
|
+
return error instanceof Error ? error.message : String(error);
|
|
64
|
+
}
|
|
65
|
+
function pinnedHere() {
|
|
66
|
+
return ENGINES[`${process.platform}-${process.arch}`];
|
|
67
|
+
}
|
|
57
68
|
async function install(artifacts, signal) {
|
|
58
69
|
await mkdir(directory(), { recursive: true });
|
|
59
70
|
const pinned = new Set(artifacts.map((artifact) => artifact.sha256));
|
|
@@ -68,6 +79,7 @@ async function install(artifacts, signal) {
|
|
|
68
79
|
try {
|
|
69
80
|
for (const artifact of missing) {
|
|
70
81
|
const part = `${installed(artifact)}.part`;
|
|
82
|
+
// Three retries carry a large download past a dropped connection before the download fails.
|
|
71
83
|
await executed('curl', ['-fsSL', '--retry', '3', '-o', part, artifact.url], signal);
|
|
72
84
|
if ((await sha256(part)) !== artifact.sha256)
|
|
73
85
|
throw new Error(`${artifact.url} does not match its sha256`);
|
|
@@ -83,12 +95,46 @@ async function install(artifacts, signal) {
|
|
|
83
95
|
await rm(`${installed(artifact)}.part`, { force: true });
|
|
84
96
|
}
|
|
85
97
|
}
|
|
98
|
+
function reported(next) {
|
|
99
|
+
const changed = next.installed !== readiness.installed || next.failure !== readiness.failure;
|
|
100
|
+
readiness = next;
|
|
101
|
+
return changed;
|
|
102
|
+
}
|
|
103
|
+
async function settle(transcribe) {
|
|
104
|
+
if (transcribe === setting)
|
|
105
|
+
return false;
|
|
106
|
+
setting = transcribe;
|
|
107
|
+
if (!transcribe) {
|
|
108
|
+
await rm(directory(), { recursive: true, force: true });
|
|
109
|
+
return reported({ installed: false, failure: null });
|
|
110
|
+
}
|
|
111
|
+
const download = new AbortController();
|
|
112
|
+
downloading = download;
|
|
113
|
+
try {
|
|
114
|
+
const pinned = pinnedHere();
|
|
115
|
+
await install([pinned.decoder, pinned.engine, MODEL], download.signal);
|
|
116
|
+
return reported({ installed: true, failure: null });
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
await rm(directory(), { recursive: true, force: true });
|
|
120
|
+
return reported({ installed: false, failure: download.signal.aborted ? null : causeOf(error) });
|
|
121
|
+
}
|
|
122
|
+
finally {
|
|
123
|
+
downloading = null;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
export function holdTranscription(transcribe) {
|
|
127
|
+
if (!transcribe)
|
|
128
|
+
downloading?.abort();
|
|
129
|
+
const settled = holding.then(() => settle(transcribe));
|
|
130
|
+
holding = settled.catch(() => undefined);
|
|
131
|
+
return settled;
|
|
132
|
+
}
|
|
133
|
+
export function transcriptionReport() {
|
|
134
|
+
return readiness;
|
|
135
|
+
}
|
|
86
136
|
async function transcribed(path, signal) {
|
|
87
|
-
const
|
|
88
|
-
const pinned = ENGINES[platform];
|
|
89
|
-
if (pinned === undefined)
|
|
90
|
-
throw new Error(`no transcription engine is pinned for ${platform}`);
|
|
91
|
-
await install([pinned.decoder, pinned.engine, MODEL], signal);
|
|
137
|
+
const pinned = pinnedHere();
|
|
92
138
|
const work = await mkdtemp(join(tmpdir(), 'kit-transcription-'));
|
|
93
139
|
try {
|
|
94
140
|
await executed(installed(pinned.decoder), ['-nostdin', '-hide_banner', '-loglevel', 'error', '-i', path, '-ar', '16000', '-ac', '1', '-c:a', 'pcm_s16le',
|
|
@@ -106,6 +152,8 @@ async function transcribed(path, signal) {
|
|
|
106
152
|
}
|
|
107
153
|
}
|
|
108
154
|
export async function transcribe(path, signal) {
|
|
155
|
+
if (!readiness.installed)
|
|
156
|
+
return null;
|
|
109
157
|
const before = held;
|
|
110
158
|
let release;
|
|
111
159
|
const mine = new Promise((resolve) => {
|
|
@@ -114,7 +162,7 @@ export async function transcribe(path, signal) {
|
|
|
114
162
|
held = Promise.all([before, mine]);
|
|
115
163
|
try {
|
|
116
164
|
await unlessAborted(before, signal);
|
|
117
|
-
return await transcribed(path, signal);
|
|
165
|
+
return readiness.installed ? await transcribed(path, signal) : null;
|
|
118
166
|
}
|
|
119
167
|
finally {
|
|
120
168
|
release();
|
package/dist/update.js
CHANGED
|
@@ -40,9 +40,11 @@ async function finished(inputId) {
|
|
|
40
40
|
const ack = await recorded();
|
|
41
41
|
if (ack !== null)
|
|
42
42
|
return ack;
|
|
43
|
+
// systemctl answers at once, so ten seconds only bounds a stuck service manager.
|
|
43
44
|
if ((await run('systemctl', ['is-active', '--quiet', unit(inputId)], 10_000)).status !== 0) {
|
|
44
45
|
return (await recorded()) ?? { refused: 'the Kit bootstrap did not finish' };
|
|
45
46
|
}
|
|
47
|
+
// The bootstrap runs for minutes, so checking each second sees its outcome within a second at little cost.
|
|
46
48
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
47
49
|
}
|
|
48
50
|
}
|