@agentshouse/kit 0.2.1-ceeaf32286734 → 0.2.1-ceffdba88db37
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 +14 -15
- package/dist/acp.js +1 -1
- package/dist/afk.js +17 -0
- package/dist/agents.js +54 -25
- package/dist/api.js +11 -6
- package/dist/authority-main.js +2 -2
- package/dist/bridge.js +4 -4
- package/dist/building.js +7 -3
- package/dist/calls.js +1 -1
- package/dist/chunks.js +49 -0
- package/dist/clis.js +35 -57
- package/dist/connection.js +24 -20
- package/dist/content.js +63 -0
- package/dist/conversations.js +236 -115
- package/dist/copies.js +293 -148
- package/dist/end.js +2 -9
- package/dist/events.js +729 -218
- package/dist/files.js +2 -2
- package/dist/git.js +44 -10
- package/dist/grok.js +39 -0
- package/dist/home.js +0 -7
- package/dist/house-cli.js +81 -21
- package/dist/instructions.js +2 -4
- package/dist/kit-cli.js +1 -4
- package/dist/login.js +12 -5
- package/dist/logout.js +2 -2
- package/dist/mcp.js +2 -2
- package/dist/placement.js +9 -23
- package/dist/resident.js +44 -37
- package/dist/scope.js +12 -4
- package/dist/scripts.js +59 -11
- package/dist/secret-input.js +1 -1
- package/dist/transcription.js +5 -2
- package/dist/translate.js +18 -9
- package/dist/update.js +105 -159
- package/dist/wire.js +19 -9
- package/dist/work.js +9 -2
- package/package.json +12 -8
- package/dist/chatgpt.js +0 -32
- package/dist/clis-main.js +0 -23
- package/dist/parts.js +0 -82
package/dist/scripts.js
CHANGED
|
@@ -15,6 +15,11 @@ const SIGNALLED = 128;
|
|
|
15
15
|
const NEWLINE = 0x0a;
|
|
16
16
|
const NO_BASH = "bash is not on the login shell's PATH";
|
|
17
17
|
const LOST = { refused: 'the Kit lost its connection to House' };
|
|
18
|
+
const UNSENT_CHARS = 64_000;
|
|
19
|
+
// House holds a Web Wizard's run two minutes for its Kit to connect again, so the script waits as long for a dropped connection to come back.
|
|
20
|
+
const RETURN_MS = 120_000;
|
|
21
|
+
// House takes a run on again with its page's terminal size in the frames right after the Kit connects, so a script it sent nothing for in ten seconds is one House no longer carries.
|
|
22
|
+
const TAKEN_ON_MS = 10_000;
|
|
18
23
|
function causeOf(error) {
|
|
19
24
|
return error instanceof Error ? error.message : String(error);
|
|
20
25
|
}
|
|
@@ -44,6 +49,12 @@ async function inputFile(value) {
|
|
|
44
49
|
export function removeInputs() {
|
|
45
50
|
rmSync(inputs(), { recursive: true, force: true });
|
|
46
51
|
}
|
|
52
|
+
function latest(screen) {
|
|
53
|
+
if (screen.length <= UNSENT_CHARS)
|
|
54
|
+
return screen;
|
|
55
|
+
const line = screen.indexOf('\n', screen.length - UNSENT_CHARS);
|
|
56
|
+
return screen.slice(line < 0 ? screen.length - UNSENT_CHARS : line + 1);
|
|
57
|
+
}
|
|
47
58
|
function struck(line, typed) {
|
|
48
59
|
return typed.some((typedLine) => line.includes(typedLine));
|
|
49
60
|
}
|
|
@@ -130,25 +141,54 @@ export class Scripts {
|
|
|
130
141
|
start(call) {
|
|
131
142
|
void this.calls.carry(call.input_id, () => this.run(call.input_id, planned(call)));
|
|
132
143
|
}
|
|
133
|
-
notified(
|
|
134
|
-
|
|
144
|
+
notified(oneWayCall) {
|
|
145
|
+
if (!('wizard' in oneWayCall))
|
|
146
|
+
return;
|
|
147
|
+
const run = this.runs.get(oneWayCall.wizard);
|
|
135
148
|
if (run === undefined)
|
|
136
149
|
return;
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
150
|
+
this.waited(run, null);
|
|
151
|
+
if (oneWayCall.type === 'wizard_input')
|
|
152
|
+
this.typed(run, oneWayCall.data);
|
|
153
|
+
if (oneWayCall.type === 'wizard_size')
|
|
154
|
+
this.resized(run, { cols: oneWayCall.cols, rows: oneWayCall.rows });
|
|
155
|
+
if (oneWayCall.type === 'wizard_end' && run.plan.terminal === 'page')
|
|
142
156
|
this.end(run, {});
|
|
143
157
|
}
|
|
144
158
|
disconnected() {
|
|
145
|
-
for (const run of this.runs.values())
|
|
146
|
-
|
|
159
|
+
for (const run of this.runs.values()) {
|
|
160
|
+
if (run.plan.terminal === 'page')
|
|
161
|
+
this.waited(run, RETURN_MS);
|
|
162
|
+
else
|
|
163
|
+
this.end(run, LOST);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
connected() {
|
|
167
|
+
for (const [id, run] of this.runs) {
|
|
168
|
+
if (run.waiting === null)
|
|
169
|
+
continue;
|
|
170
|
+
this.waited(run, TAKEN_ON_MS);
|
|
171
|
+
if (run.unsent !== '' && this.send({ type: 'wizard_output', wizard: id, data: run.unsent }))
|
|
172
|
+
run.unsent = '';
|
|
173
|
+
}
|
|
147
174
|
}
|
|
148
175
|
async run(id, plan) {
|
|
149
176
|
const size = plan.terminal === 'page' ? null : FIRST_SIZE;
|
|
150
177
|
const output = plan.function === null ? null : new KeptOutput(plan.function.outputCap);
|
|
151
|
-
const run = {
|
|
178
|
+
const run = {
|
|
179
|
+
plan,
|
|
180
|
+
input: null,
|
|
181
|
+
output,
|
|
182
|
+
process: null,
|
|
183
|
+
pipes: [],
|
|
184
|
+
terminal: null,
|
|
185
|
+
size,
|
|
186
|
+
typed: [],
|
|
187
|
+
unsent: '',
|
|
188
|
+
waiting: null,
|
|
189
|
+
ended: null,
|
|
190
|
+
sized: Promise.withResolvers(),
|
|
191
|
+
};
|
|
152
192
|
if (size !== null)
|
|
153
193
|
run.sized.resolve();
|
|
154
194
|
this.runs.set(id, run);
|
|
@@ -184,7 +224,8 @@ export class Scripts {
|
|
|
184
224
|
run.process = terminal;
|
|
185
225
|
run.terminal = terminal;
|
|
186
226
|
terminal.onData((data) => {
|
|
187
|
-
this.send({ type: 'wizard_output', wizard: id, data })
|
|
227
|
+
if (!this.send({ type: 'wizard_output', wizard: id, data }))
|
|
228
|
+
run.unsent = latest(`${run.unsent}${data}`);
|
|
188
229
|
output?.add(data);
|
|
189
230
|
});
|
|
190
231
|
for (const data of run.typed.splice(0))
|
|
@@ -242,10 +283,17 @@ export class Scripts {
|
|
|
242
283
|
end(run, result) {
|
|
243
284
|
if (run.ended !== null)
|
|
244
285
|
return;
|
|
286
|
+
this.waited(run, null);
|
|
245
287
|
run.ended = result;
|
|
246
288
|
run.sized.resolve();
|
|
247
289
|
this.stop(run);
|
|
248
290
|
}
|
|
291
|
+
waited(run, ms) {
|
|
292
|
+
if (run.waiting !== null)
|
|
293
|
+
clearTimeout(run.waiting);
|
|
294
|
+
run.waiting = ms === null ? null : setTimeout(() => this.end(run, LOST), ms);
|
|
295
|
+
run.waiting?.unref();
|
|
296
|
+
}
|
|
249
297
|
stop(run) {
|
|
250
298
|
if (run.process !== null)
|
|
251
299
|
killTree(run.process);
|
package/dist/secret-input.js
CHANGED
|
@@ -2,7 +2,7 @@ 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 {
|
|
5
|
-
const held = await house.
|
|
5
|
+
const held = await house.act('secret-inputs/await', { subject, steps });
|
|
6
6
|
if (held.outcome === 'collected')
|
|
7
7
|
return held.content;
|
|
8
8
|
if (held.release !== 'held')
|
package/dist/transcription.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { chmod, mkdir, mkdtemp, readdir, readFile, rename, rm, stat } from 'node:fs/promises';
|
|
2
2
|
import { availableParallelism, tmpdir } from 'node:os';
|
|
3
3
|
import { basename, join } from 'node:path';
|
|
4
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
4
5
|
import { unlessAborted } from './abort.js';
|
|
5
6
|
import { downloadServed } from './building.js';
|
|
6
7
|
import { failureOf, run } from './clis.js';
|
|
@@ -125,7 +126,7 @@ async function install(artifacts, signal) {
|
|
|
125
126
|
}
|
|
126
127
|
}
|
|
127
128
|
function reported(next) {
|
|
128
|
-
const changed = next
|
|
129
|
+
const changed = !isDeepStrictEqual(next, readiness);
|
|
129
130
|
readiness = next;
|
|
130
131
|
return changed;
|
|
131
132
|
}
|
|
@@ -137,10 +138,12 @@ async function settle(transcribe) {
|
|
|
137
138
|
await rm(directory(), { recursive: true, force: true });
|
|
138
139
|
return reported({ installed: false, failure: null });
|
|
139
140
|
}
|
|
141
|
+
const pinned = pinnedHere();
|
|
142
|
+
if (pinned === undefined)
|
|
143
|
+
return reported({ installed: false, failure: null, no_engine: true });
|
|
140
144
|
const download = new AbortController();
|
|
141
145
|
downloading = download;
|
|
142
146
|
try {
|
|
143
|
-
const pinned = pinnedHere();
|
|
144
147
|
await install([pinned.decoder, pinned.engine, MODEL], download.signal);
|
|
145
148
|
return reported({ installed: true, failure: null });
|
|
146
149
|
}
|
package/dist/translate.js
CHANGED
|
@@ -1,12 +1,21 @@
|
|
|
1
|
-
import { apply, parse, serialize } from '@agentshouse/mdmodel';
|
|
1
|
+
import { apply, definitionAt, HOUSE_TYPED_PATHS, parse, serialize, } from '@agentshouse/mdmodel';
|
|
2
2
|
function same(left, right) {
|
|
3
3
|
return JSON.stringify(left) === JSON.stringify(right);
|
|
4
4
|
}
|
|
5
|
-
function applied(document, changes) {
|
|
6
|
-
const result = apply(document, changes);
|
|
5
|
+
function applied(document, changes, definition) {
|
|
6
|
+
const result = apply(document, changes, definition);
|
|
7
7
|
return result.outcome === 'applied' ? serialize(result.document) : null;
|
|
8
8
|
}
|
|
9
|
-
function
|
|
9
|
+
export function readDocument(content, file, model) {
|
|
10
|
+
const definitions = definitionAt(model, file, HOUSE_TYPED_PATHS);
|
|
11
|
+
const parsed = parse(content, file, definitions);
|
|
12
|
+
if (!parsed.ok)
|
|
13
|
+
return null;
|
|
14
|
+
const { document } = parsed;
|
|
15
|
+
const definition = definitions(document.type);
|
|
16
|
+
return definition !== undefined || document.type === undefined ? { document, definition } : null;
|
|
17
|
+
}
|
|
18
|
+
function components(path, before, after, text, definition) {
|
|
10
19
|
const edits = [];
|
|
11
20
|
const changes = [];
|
|
12
21
|
if (before.preamble !== after.preamble) {
|
|
@@ -33,13 +42,13 @@ function components(path, before, after, text) {
|
|
|
33
42
|
edits.push({ op: 'replace_section', path, section: name, base: prior, content: value });
|
|
34
43
|
changes.push({ kind: 'section', name, value, prior });
|
|
35
44
|
}
|
|
36
|
-
return edits.length > 0 && applied(before, changes) === text ? edits : null;
|
|
45
|
+
return edits.length > 0 && applied(before, changes, definition) === text ? edits : null;
|
|
37
46
|
}
|
|
38
|
-
export function changed(path, file, base, before, after) {
|
|
47
|
+
export function changed(path, file, base, before, after, model) {
|
|
39
48
|
if (!file.endsWith('.md'))
|
|
40
49
|
return [{ op: 'replace', path, base, content: after }];
|
|
41
|
-
const
|
|
42
|
-
const
|
|
43
|
-
const structured =
|
|
50
|
+
const prior = readDocument(before, file, model);
|
|
51
|
+
const next = readDocument(after, file, model);
|
|
52
|
+
const structured = prior !== null && next !== null ? components(path, prior.document, next.document, after, prior.definition) : null;
|
|
44
53
|
return structured ?? [{ op: 'replace', path, base, content: after }];
|
|
45
54
|
}
|
package/dist/update.js
CHANGED
|
@@ -1,181 +1,127 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
|
-
import {
|
|
3
|
-
import { mkdir, readFile, rm, writeFile } from 'node:fs/promises';
|
|
4
|
-
import { homedir } from 'node:os';
|
|
2
|
+
import { mkdir } from 'node:fs/promises';
|
|
5
3
|
import { join } from 'node:path';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
// A
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
function
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
function unit(callId) {
|
|
26
|
-
return `house-kit-update-${callId}`;
|
|
27
|
-
}
|
|
28
|
-
function manager() {
|
|
29
|
-
return service() === 'user' ? ['--user'] : [];
|
|
30
|
-
}
|
|
31
|
-
function elevated() {
|
|
32
|
-
return throughSudo() ? ['sudo', '-n'] : [];
|
|
33
|
-
}
|
|
34
|
-
function account() {
|
|
35
|
-
return throughSudo() ? [`--uid=${process.getuid()}`, `--gid=${process.getgid()}`] : [];
|
|
36
|
-
}
|
|
37
|
-
function placement() {
|
|
38
|
-
return service() === 'user' ? ['--workspace', workspaceRoot()] : ['--linux'];
|
|
39
|
-
}
|
|
40
|
-
function record() {
|
|
41
|
-
return `outcome=$1; shift; timeout ${RERUN_MS / 1000} bash "$0" "$@"; printf %s "$?" > "$outcome"; ${[...elevated(), 'systemctl', ...manager(), 'start', 'house-kit.service'].join(' ')}`;
|
|
42
|
-
}
|
|
43
|
-
async function pendingCall() {
|
|
44
|
-
try {
|
|
45
|
-
return JSON.parse(await readFile(pending(), 'utf8')).input_id;
|
|
46
|
-
}
|
|
47
|
-
catch {
|
|
48
|
-
return null;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
async function recorded() {
|
|
52
|
-
const status = await readFile(outcome(), 'utf8').catch(() => null);
|
|
53
|
-
if (status === null)
|
|
54
|
-
return null;
|
|
55
|
-
if (status.trim() === TIMED_OUT)
|
|
56
|
-
return { refused: `the Kit bootstrap did not finish within ${RERUN_MS / 1000} seconds` };
|
|
57
|
-
return status.trim() === '0' ? {} : { refused: `the Kit bootstrap exited with ${status.trim()}` };
|
|
58
|
-
}
|
|
59
|
-
async function forget(callId) {
|
|
60
|
-
if ((await pendingCall()) !== callId)
|
|
61
|
-
return;
|
|
62
|
-
await rm(pending(), { force: true });
|
|
63
|
-
await rm(outcome(), { force: true });
|
|
64
|
-
}
|
|
65
|
-
async function finished(callId) {
|
|
66
|
-
for (;;) {
|
|
67
|
-
const result = await recorded();
|
|
68
|
-
if (result !== null)
|
|
69
|
-
return result;
|
|
70
|
-
// systemctl answers at once, so ten seconds only bounds a stuck service manager.
|
|
71
|
-
if ((await run('systemctl', [...manager(), 'is-active', '--quiet', unit(callId)], 10_000)).status !== 0) {
|
|
72
|
-
return (await recorded()) ?? { refused: 'the Kit bootstrap did not finish' };
|
|
73
|
-
}
|
|
74
|
-
// The bootstrap runs for minutes, so checking each second sees its outcome within a second at little cost.
|
|
75
|
-
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
async function bounded(body, most) {
|
|
79
|
-
const chunks = [];
|
|
80
|
-
let bytes = 0;
|
|
81
|
-
for await (const chunk of body ?? []) {
|
|
82
|
-
bytes += chunk.length;
|
|
83
|
-
if (bytes > most)
|
|
84
|
-
return null;
|
|
85
|
-
chunks.push(chunk);
|
|
86
|
-
}
|
|
87
|
-
return Buffer.concat(chunks, bytes);
|
|
88
|
-
}
|
|
89
|
-
function rerun(script, callId, flags) {
|
|
4
|
+
import { downloadServed, servedRelease } from './building.js';
|
|
5
|
+
import { KIT_RELEASE } from './clis.js';
|
|
6
|
+
import { restart, updateLine } from './end.js';
|
|
7
|
+
import { kitHome, readEnrolment } from './home.js';
|
|
8
|
+
import { placedPrefix } from './placement.js';
|
|
9
|
+
import { childEnvironment, relayOrigin } from './relay.js';
|
|
10
|
+
const INSTALLER_BYTES = 1_000_000;
|
|
11
|
+
// A release's Node.js, Kit package and adapters are about a hundred megabytes, so an hour carries them at thirty kilobytes a second, and a placement still running then has hung.
|
|
12
|
+
const PLACEMENT_MS = 60 * 60_000;
|
|
13
|
+
// A refused Kit is offline until its placement succeeds, so it tries again within five minutes of its Building or this computer recovering, while a placement that fails only after its hundred-megabyte download runs at most twelve times an hour.
|
|
14
|
+
export const PLACEMENT_RETRY_MS = 5 * 60_000;
|
|
15
|
+
const REFUSED = 'kit_bootstrap_refused: ';
|
|
16
|
+
const OUTPUT_CHARACTERS = 4000;
|
|
17
|
+
function causeOf(error) {
|
|
18
|
+
if (error instanceof TypeError && error.cause instanceof Error)
|
|
19
|
+
return `the Building did not answer: ${error.cause.message}`;
|
|
20
|
+
return error instanceof Error ? error.message : String(error);
|
|
21
|
+
}
|
|
22
|
+
function placing(installer, house, prefix, signal) {
|
|
90
23
|
return new Promise((resolve) => {
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
'
|
|
94
|
-
...
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
24
|
+
const relay = relayOrigin();
|
|
25
|
+
const child = spawn('bash', [installer, '--house', house, '--place', prefix], {
|
|
26
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
27
|
+
env: { ...childEnvironment(), ...(relay === undefined ? {} : { HOUSE_KIT_RELAY: relay }) },
|
|
28
|
+
detached: true,
|
|
29
|
+
});
|
|
30
|
+
const stop = () => {
|
|
31
|
+
try {
|
|
32
|
+
process.kill(-child.pid, 'SIGKILL');
|
|
33
|
+
}
|
|
34
|
+
catch { }
|
|
35
|
+
};
|
|
36
|
+
signal.addEventListener('abort', stop, { once: true });
|
|
37
|
+
if (signal.aborted)
|
|
38
|
+
stop();
|
|
39
|
+
let output = '';
|
|
40
|
+
for (const stream of [child.stdout, child.stderr]) {
|
|
41
|
+
stream.setEncoding('utf8').on('data', (chunk) => {
|
|
42
|
+
output = (output + chunk).slice(-OUTPUT_CHARACTERS);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
const ended = (failure) => {
|
|
46
|
+
signal.removeEventListener('abort', stop);
|
|
47
|
+
resolve(failure);
|
|
48
|
+
};
|
|
49
|
+
child.on('error', (error) => ended(error.message));
|
|
50
|
+
child.on('close', (status) => {
|
|
51
|
+
if (status === 0)
|
|
52
|
+
return ended(null);
|
|
53
|
+
if (signal.aborted)
|
|
54
|
+
return ended(`the placement did not end within ${PLACEMENT_MS / 1000} seconds`);
|
|
55
|
+
const lines = output.split('\n').filter((line) => line.trim() !== '');
|
|
56
|
+
const refused = lines.findLast((line) => line.startsWith(REFUSED));
|
|
57
|
+
ended(refused?.slice(REFUSED.length) ?? lines.at(-1) ?? `the placement ended with status ${status ?? 'a signal'}`);
|
|
58
|
+
});
|
|
113
59
|
});
|
|
114
60
|
}
|
|
115
61
|
export class KitUpdate {
|
|
116
62
|
calls;
|
|
117
|
-
changed;
|
|
118
|
-
waiting = new Map();
|
|
119
63
|
queue = Promise.resolve();
|
|
120
|
-
|
|
64
|
+
placed = null;
|
|
65
|
+
constructor(calls) {
|
|
121
66
|
this.calls = calls;
|
|
122
|
-
this.changed = changed;
|
|
123
67
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
if (callId === null)
|
|
127
|
-
return;
|
|
128
|
-
await this.enqueue(callId, () => finished(callId));
|
|
68
|
+
take(call) {
|
|
69
|
+
void this.calls.carry(call.input_id, async () => ({ result: await this.queued(() => this.update(call.release)) }));
|
|
129
70
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
71
|
+
async takeRefused(release) {
|
|
72
|
+
for (;;) {
|
|
73
|
+
const failure = await this.queued(async () => (this.placed === null ? this.place(release, 'served') : null));
|
|
74
|
+
if (failure === null)
|
|
75
|
+
restart(`Kit ${this.placed} is placed; its supervisor starts it`);
|
|
76
|
+
process.stderr.write(`kit: ${updateLine(`Kit ${KIT_RELEASE} stays offline and tries again in ${PLACEMENT_RETRY_MS / 60_000} minutes`)}\n`);
|
|
77
|
+
await new Promise((resolve) => setTimeout(resolve, PLACEMENT_RETRY_MS));
|
|
78
|
+
}
|
|
133
79
|
}
|
|
134
|
-
|
|
135
|
-
return this.
|
|
80
|
+
placedRelease() {
|
|
81
|
+
return this.placed;
|
|
136
82
|
}
|
|
137
|
-
|
|
138
|
-
const
|
|
139
|
-
this.
|
|
140
|
-
|
|
83
|
+
queued(work) {
|
|
84
|
+
const taken = this.queue.then(work);
|
|
85
|
+
this.queue = taken.catch(() => undefined);
|
|
86
|
+
return taken;
|
|
141
87
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
return {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
88
|
+
async update(release) {
|
|
89
|
+
if (release === (this.placed ?? KIT_RELEASE))
|
|
90
|
+
return {};
|
|
91
|
+
if (this.placed !== null)
|
|
92
|
+
return { refused: `Kit ${this.placed} is placed and starts first, once no turn is open` };
|
|
93
|
+
const failure = await this.place(release, 'named');
|
|
94
|
+
if (failure !== null)
|
|
95
|
+
return { refused: failure };
|
|
96
|
+
process.stderr.write(`kit: Kit ${release} is placed; it starts once no turn is open\n`);
|
|
97
|
+
return {};
|
|
150
98
|
}
|
|
151
|
-
async
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
let script;
|
|
99
|
+
async place(release, which) {
|
|
100
|
+
const signal = AbortSignal.timeout(PLACEMENT_MS);
|
|
101
|
+
let version = release;
|
|
102
|
+
let failure;
|
|
156
103
|
try {
|
|
157
|
-
const
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
104
|
+
const prefix = placedPrefix();
|
|
105
|
+
const served = await servedRelease(signal);
|
|
106
|
+
if (which === 'named' && served.version !== release)
|
|
107
|
+
throw new Error(`the Building serves Kit ${served.version}, not Kit ${release}`);
|
|
108
|
+
version = served.version;
|
|
109
|
+
if (version === KIT_RELEASE)
|
|
110
|
+
throw new Error(`the Building serves Kit ${KIT_RELEASE}, which this Kit runs`);
|
|
111
|
+
await mkdir(join(kitHome(), 'update'), { recursive: true, mode: 0o700 });
|
|
112
|
+
const installer = join(kitHome(), 'update', served.installer);
|
|
113
|
+
await downloadServed(served.installer, served.sha256, installer, signal, INSTALLER_BYTES);
|
|
114
|
+
failure = await placing(installer, (await readEnrolment()).house, prefix, signal);
|
|
161
115
|
}
|
|
162
116
|
catch (error) {
|
|
163
|
-
|
|
164
|
-
throw error;
|
|
165
|
-
return { refused: `the Kit bootstrap did not arrive within ${BOOTSTRAP_MS / 1000} seconds` };
|
|
117
|
+
failure = signal.aborted ? `the placement did not end within ${PLACEMENT_MS / 1000} seconds` : causeOf(error);
|
|
166
118
|
}
|
|
167
|
-
if (
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
return
|
|
119
|
+
if (failure !== null) {
|
|
120
|
+
const refused = `Kit ${version} could not be placed: ${failure}`;
|
|
121
|
+
process.stderr.write(`kit: ${refused}\n`);
|
|
122
|
+
return refused;
|
|
171
123
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
await writeFile(path, script, { mode: 0o700 });
|
|
175
|
-
await rm(outcome(), { force: true });
|
|
176
|
-
await writeFile(pending(), `${JSON.stringify({ input_id: call.input_id })}\n`, { mode: 0o600 });
|
|
177
|
-
return (await rerun(path, call.input_id, call.update_clis ? ['--update-clis'] : [])) ?? (await recorded()) ?? {
|
|
178
|
-
refused: 'the Kit bootstrap did not finish',
|
|
179
|
-
};
|
|
124
|
+
this.placed = version;
|
|
125
|
+
return null;
|
|
180
126
|
}
|
|
181
127
|
}
|
package/dist/wire.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { machine } from './placement.js';
|
|
1
|
+
import { updateRequired } from './end.js';
|
|
3
2
|
import { refusalOf } from './refusals.js';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
function
|
|
3
|
+
let take = null;
|
|
4
|
+
let taken = false;
|
|
5
|
+
function unservedBy(text) {
|
|
7
6
|
let body;
|
|
8
7
|
try {
|
|
9
8
|
body = JSON.parse(text);
|
|
@@ -11,12 +10,23 @@ function newer(text) {
|
|
|
11
10
|
catch {
|
|
12
11
|
return null;
|
|
13
12
|
}
|
|
14
|
-
return body?.error?.code === '
|
|
13
|
+
return body?.error?.code === 'kit_update_required' ? body.error : null;
|
|
14
|
+
}
|
|
15
|
+
export function takeUnservedRelease(taking) {
|
|
16
|
+
take = taking;
|
|
17
|
+
}
|
|
18
|
+
export function unserved() {
|
|
19
|
+
return taken;
|
|
15
20
|
}
|
|
16
21
|
export function endUnserved(text) {
|
|
22
|
+
const refused = unservedBy(text);
|
|
23
|
+
if (refused !== null && take !== null) {
|
|
24
|
+
if (!taken) {
|
|
25
|
+
taken = true;
|
|
26
|
+
take(refused.release);
|
|
27
|
+
}
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
17
30
|
if (refusalOf(text)?.code === 'kit_update_required')
|
|
18
31
|
updateRequired();
|
|
19
|
-
const refused = newer(text);
|
|
20
|
-
if (refused !== null)
|
|
21
|
-
newerThanHouse(refused.release, refused.commands[machine()]);
|
|
22
32
|
}
|
package/dist/work.js
CHANGED
|
@@ -177,6 +177,7 @@ class ClaudeWork extends Work {
|
|
|
177
177
|
}
|
|
178
178
|
}
|
|
179
179
|
class CodexWork extends Work {
|
|
180
|
+
tapped;
|
|
180
181
|
threads = new Map();
|
|
181
182
|
queues = new Map();
|
|
182
183
|
goals = new Set();
|
|
@@ -193,6 +194,10 @@ class CodexWork extends Work {
|
|
|
193
194
|
heard = 0;
|
|
194
195
|
proving = -1;
|
|
195
196
|
proven = -1;
|
|
197
|
+
constructor(changed, tapped) {
|
|
198
|
+
super(changed);
|
|
199
|
+
this.tapped = tapped;
|
|
200
|
+
}
|
|
196
201
|
async open(cli) {
|
|
197
202
|
this.path = join(socketDirectory(), `${randomUUID()}.sock`);
|
|
198
203
|
this.server = createServer((socket) => this.connected(socket));
|
|
@@ -274,6 +279,8 @@ class CodexWork extends Work {
|
|
|
274
279
|
}
|
|
275
280
|
stream(message, socket) {
|
|
276
281
|
const params = message.params;
|
|
282
|
+
if (message.method !== undefined)
|
|
283
|
+
this.tapped(message);
|
|
277
284
|
switch (message.method) {
|
|
278
285
|
case 'thread/status/changed':
|
|
279
286
|
this.threads.set(params.threadId, params.status.type === 'active' && params.status.activeFlags.length === 0);
|
|
@@ -337,10 +344,10 @@ class GrokWork extends Work {
|
|
|
337
344
|
return true;
|
|
338
345
|
}
|
|
339
346
|
}
|
|
340
|
-
export function workFor(kind, cwd, changed) {
|
|
347
|
+
export function workFor(kind, cwd, changed, tapped) {
|
|
341
348
|
if (kind === 'claude-agent-acp')
|
|
342
349
|
return new ClaudeWork(cwd, changed);
|
|
343
350
|
if (kind === 'codex-acp')
|
|
344
|
-
return new CodexWork(changed);
|
|
351
|
+
return new CodexWork(changed, tapped);
|
|
345
352
|
return new GrokWork(changed);
|
|
346
353
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentshouse/kit",
|
|
3
|
-
"version": "0.2.1-
|
|
3
|
+
"version": "0.2.1-ceffdba88db37",
|
|
4
4
|
"description": "Kit connects an Environment to agents.house.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -19,20 +19,23 @@
|
|
|
19
19
|
"bootstrap-manifest": "node scripts/bootstrap-manifest.mjs",
|
|
20
20
|
"build": "tsc -p tsconfig.build.json",
|
|
21
21
|
"engine": "mkdir -p tmp/engine && docker run --rm -v \"$PWD:/kit\" -w /kit alpine:3.24@sha256:294b683cb724975bec92580e1e685676bd4b50bda910ddb8c51d4cabeaec77e6 sh scripts/engine.sh tmp/engine",
|
|
22
|
-
"follow-skills": "node scripts/follow-skills.mjs",
|
|
22
|
+
"follow-skills-and-kit-wire": "node scripts/follow-skills-and-kit-wire.mjs",
|
|
23
23
|
"release-files": "node scripts/release-files.mjs",
|
|
24
24
|
"test": "tsc -p tsconfig.json && vitest run"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@agentclientprotocol/sdk": "2.0
|
|
28
|
-
"@agentshouse/
|
|
29
|
-
"@agentshouse/
|
|
27
|
+
"@agentclientprotocol/sdk": "2.4.0",
|
|
28
|
+
"@agentshouse/kit-wire": "0.1.0-c2e87e570c808",
|
|
29
|
+
"@agentshouse/mdmodel": "0.1.0-cd6a8e5bc7efc",
|
|
30
|
+
"@agentshouse/session-content": "0.1.0-cad437697294e",
|
|
31
|
+
"@agentshouse/skills": "0.1.0-c6f43632bb24a",
|
|
30
32
|
"@lydell/node-pty": "1.2.0-beta.15",
|
|
33
|
+
"micromark": "4.0.2",
|
|
31
34
|
"yaml": "2.9.1"
|
|
32
35
|
},
|
|
33
36
|
"peerDependencies": {
|
|
34
|
-
"@agentclientprotocol/claude-agent-acp": "0.
|
|
35
|
-
"@agentclientprotocol/codex-acp": "2.
|
|
37
|
+
"@agentclientprotocol/claude-agent-acp": "0.100.0",
|
|
38
|
+
"@agentclientprotocol/codex-acp": "2.5.0"
|
|
36
39
|
},
|
|
37
40
|
"peerDependenciesMeta": {
|
|
38
41
|
"@agentclientprotocol/claude-agent-acp": {
|
|
@@ -47,7 +50,8 @@
|
|
|
47
50
|
"@types/ws": "8.18.2",
|
|
48
51
|
"typescript": "7.0.2",
|
|
49
52
|
"vitest": "5.0.5",
|
|
50
|
-
"ws": "8.22.0"
|
|
53
|
+
"ws": "8.22.0",
|
|
54
|
+
"zod": "4.6.7"
|
|
51
55
|
},
|
|
52
56
|
"packageManager": "npm@11.19.1",
|
|
53
57
|
"engines": {
|
package/dist/chatgpt.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { parseArgs } from 'node:util';
|
|
2
|
-
import { placeAppGit } from './app-git.js';
|
|
3
|
-
import { kitHome, readOwnAgent, writeOwnAgent } from './home.js';
|
|
4
|
-
import { accepted, DEFAULT_HOUSE } from './login.js';
|
|
5
|
-
const KEY_SOURCE = 'New key for a script on Connections';
|
|
6
|
-
const USAGE = `usage: kit chatgpt --key <key> [--house <origin>]
|
|
7
|
-
--key <key> a key from ${KEY_SOURCE}
|
|
8
|
-
--house <origin> the House of the key, ${DEFAULT_HOUSE} unless one is stored
|
|
9
|
-
`;
|
|
10
|
-
export async function chatgpt(argv) {
|
|
11
|
-
const { values } = parseArgs({
|
|
12
|
-
args: argv,
|
|
13
|
-
options: { key: { type: 'string' }, house: { type: 'string' }, help: { type: 'boolean', default: false } },
|
|
14
|
-
});
|
|
15
|
-
if (values.help) {
|
|
16
|
-
process.stdout.write(USAGE);
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
if (values.key === undefined)
|
|
20
|
-
throw new Error(`pass --key with a key from ${KEY_SOURCE}`);
|
|
21
|
-
const before = await readOwnAgent();
|
|
22
|
-
const house = values.house ?? before?.house ?? DEFAULT_HOUSE;
|
|
23
|
-
if (!(await accepted(house, values.key)))
|
|
24
|
-
throw new Error(`${house} does not accept this key; pass one from ${KEY_SOURCE}`);
|
|
25
|
-
const relay = process.env.HOUSE_KIT_RELAY || undefined;
|
|
26
|
-
await writeOwnAgent({ house, ...(relay === undefined ? {} : { relay }), credential: values.key });
|
|
27
|
-
await placeAppGit(await readOwnAgent()).catch((error) => process.stderr.write(`kit: ${error.message}\n`));
|
|
28
|
-
if (before !== null && before.credential !== values.key) {
|
|
29
|
-
process.stdout.write('This replaced the key this Kit home held; give each session its own HOUSE_KIT_HOME to keep its own key.\n');
|
|
30
|
-
}
|
|
31
|
-
process.stdout.write(`house now calls ${house} as you, with the key kept in ${kitHome()}.\n`);
|
|
32
|
-
}
|