@agentshouse/kit 0.2.1-ccf188e02985d → 0.2.1-cd423aab3dbcc
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 +35 -42
- package/dist/acp.js +66 -12
- package/dist/afk.js +17 -0
- package/dist/agents.js +122 -53
- package/dist/api.js +15 -10
- package/dist/binaries.js +60 -0
- package/dist/bridge.js +100 -45
- package/dist/building.js +50 -0
- package/dist/calls.js +88 -0
- package/dist/chunks.js +54 -0
- package/dist/clis.js +62 -50
- package/dist/connect.js +121 -0
- package/dist/connection.js +120 -0
- package/dist/content.js +106 -0
- package/dist/conversations.js +617 -240
- package/dist/copies.js +1277 -623
- package/dist/earlier.js +273 -0
- package/dist/end.js +12 -5
- package/dist/events.js +549 -281
- package/dist/files.js +206 -38
- package/dist/git.js +2 -72
- package/dist/grok.js +39 -0
- package/dist/home.js +86 -29
- package/dist/house-cli.js +180 -189
- package/dist/house-main.js +3 -3
- package/dist/instructions.js +29 -11
- package/dist/keys.js +238 -0
- package/dist/kit-cli.js +18 -8
- package/dist/kit-main.js +3 -3
- package/dist/login.js +36 -22
- package/dist/logout.js +2 -2
- package/dist/manifest.js +75 -0
- package/dist/mcp.js +47 -7
- package/dist/owner.js +46 -0
- package/dist/placement.js +15 -20
- package/dist/refusals.js +50 -23
- package/dist/relay.js +21 -0
- package/dist/resident.js +141 -90
- package/dist/scope.js +15 -4
- package/dist/scripts.js +319 -0
- package/dist/secret-input.js +1 -1
- package/dist/settings.js +247 -0
- package/dist/sign-in.js +67 -21
- package/dist/silence.js +28 -0
- package/dist/skills.js +42 -97
- package/dist/supervisor.js +163 -0
- package/dist/transcription.js +88 -45
- package/dist/update.js +118 -120
- package/dist/wire.js +30 -4
- package/dist/work.js +27 -2
- package/dist/workspace.js +113 -0
- package/package.json +25 -22
- package/dist/authority-main.js +0 -22
- package/dist/bootstrap.json +0 -24
- package/dist/chatgpt.js +0 -32
- package/dist/clis-main.js +0 -23
- package/dist/configure-main.js +0 -6
- package/dist/enrol-main.js +0 -10
- package/dist/git-main.js +0 -153
- package/dist/inputs.js +0 -37
- package/dist/parts.js +0 -82
- package/dist/service-main.js +0 -9
- package/dist/service.js +0 -55
- package/dist/stream.js +0 -123
- package/dist/translate.js +0 -51
- package/how-we-work.md +0 -33
- package/skills/ask-matt/LICENSE +0 -21
- package/skills/ask-matt/PHASE-BOUNDARIES.md +0 -55
- package/skills/ask-matt/SKILL.md +0 -97
- package/skills/ask-matt/agents/openai.yaml +0 -5
- 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 -114
- package/skills/codebase-design/agents/openai.yaml +0 -3
- package/skills/diagnosing-bugs/LICENSE +0 -21
- package/skills/diagnosing-bugs/SKILL.md +0 -138
- 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/GLOSSARY-FORMAT.md +0 -60
- package/skills/domain-modeling/LICENSE +0 -21
- package/skills/domain-modeling/SKILL.md +0 -74
- package/skills/domain-modeling/agents/openai.yaml +0 -3
- package/skills/grill-me/LICENSE +0 -21
- package/skills/grill-me/SKILL.md +0 -7
- package/skills/grill-me/agents/openai.yaml +0 -5
- package/skills/grill-with-docs/LICENSE +0 -21
- package/skills/grill-with-docs/SKILL.md +0 -7
- package/skills/grill-with-docs/agents/openai.yaml +0 -5
- 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 -16
- package/skills/handoff/agents/openai.yaml +0 -5
- package/skills/implement/LICENSE +0 -21
- package/skills/implement/SKILL.md +0 -17
- package/skills/implement/agents/openai.yaml +0 -5
- package/skills/implement-spec/LICENSE +0 -21
- package/skills/implement-spec/SKILL.md +0 -40
- package/skills/implement-spec/agents/openai.yaml +0 -5
- 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 -71
- package/skills/improve-codebase-architecture/agents/openai.yaml +0 -5
- package/skills/pr/CREDITS.md +0 -3
- package/skills/pr/LICENSE +0 -21
- package/skills/pr/SKILL.md +0 -170
- package/skills/pr/agents/openai.yaml +0 -3
- package/skills/prototype/LICENSE +0 -21
- package/skills/prototype/LOGIC.md +0 -67
- package/skills/prototype/SKILL.md +0 -26
- 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 -12
- package/skills/research/agents/openai.yaml +0 -3
- package/skills/retro/LICENSE +0 -21
- package/skills/retro/SKILL.md +0 -44
- package/skills/retro/agents/openai.yaml +0 -5
- package/skills/tdd/LICENSE +0 -21
- package/skills/tdd/SKILL.md +0 -38
- 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 -140
- package/skills/teach/agents/openai.yaml +0 -5
- package/skills/to-questionnaire/LICENSE +0 -21
- package/skills/to-questionnaire/SKILL.md +0 -54
- package/skills/to-questionnaire/agents/openai.yaml +0 -5
- package/skills/to-spec/LICENSE +0 -21
- package/skills/to-spec/SKILL.md +0 -75
- package/skills/to-spec/agents/openai.yaml +0 -5
- package/skills/to-tickets/LICENSE +0 -21
- package/skills/to-tickets/SKILL.md +0 -105
- package/skills/to-tickets/agents/openai.yaml +0 -5
- package/skills/triage/AGENT-BRIEF.md +0 -207
- package/skills/triage/LICENSE +0 -21
- package/skills/triage/OUT-OF-SCOPE.md +0 -105
- package/skills/triage/SKILL.md +0 -112
- package/skills/triage/agents/openai.yaml +0 -5
- package/skills/wait-what/LICENSE +0 -21
- package/skills/wait-what/SKILL.md +0 -7
- package/skills/wait-what/agents/openai.yaml +0 -5
- package/skills/wayfinder/LICENSE +0 -21
- package/skills/wayfinder/SKILL.md +0 -128
- package/skills/wayfinder/agents/openai.yaml +0 -5
- package/skills/wizard/LICENSE +0 -21
- package/skills/wizard/SKILL.md +0 -44
- package/skills/wizard/agents/openai.yaml +0 -3
- package/skills/wizard/template.sh +0 -223
- 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 -81
- package/skills/writing-for-agents/agents/openai.yaml +0 -3
package/dist/transcription.js
CHANGED
|
@@ -1,33 +1,40 @@
|
|
|
1
|
-
import { createHash } from 'node:crypto';
|
|
2
|
-
import { createReadStream } from 'node:fs';
|
|
3
1
|
import { chmod, mkdir, mkdtemp, readdir, readFile, rename, rm, stat } from 'node:fs/promises';
|
|
4
2
|
import { availableParallelism, tmpdir } from 'node:os';
|
|
5
3
|
import { basename, join } from 'node:path';
|
|
6
|
-
import {
|
|
4
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
7
5
|
import { unlessAborted } from './abort.js';
|
|
6
|
+
import { downloadServed } from './building.js';
|
|
8
7
|
import { failureOf, run } from './clis.js';
|
|
8
|
+
import { downloaded, fetched } from './files.js';
|
|
9
9
|
import { kitHome } from './home.js';
|
|
10
10
|
const RELEASE = 'https://github.com/agentshouse/kit/releases/download/engine-2';
|
|
11
11
|
export const MODEL = {
|
|
12
|
-
|
|
12
|
+
name: 'ggml-parakeet-tdt-0.6b-v3-q4_k.bin',
|
|
13
|
+
from: 'https://huggingface.co/ggml-org/parakeet-GGUF/resolve/35156454d1a39de06863303dd209fd2bed6ee079/ggml-parakeet-tdt-0.6b-v3-q4_k.bin',
|
|
13
14
|
sha256: '8b205b8b39c6535e153de6fb11c51db46125d45c4f16ba496fe41a0fe71b885e',
|
|
15
|
+
bytes: 415_611_879,
|
|
14
16
|
executable: false,
|
|
15
17
|
};
|
|
16
18
|
export const ENGINES = {
|
|
17
19
|
'linux-x64': {
|
|
18
|
-
decoder: {
|
|
19
|
-
engine: {
|
|
20
|
+
decoder: { name: 'ffmpeg-linux-x86_64', from: `${RELEASE}/ffmpeg-linux-x86_64`, sha256: '1f8235d206428305afb89c6e8ab99d100425a0ba61e22bb4c7aff017db8c8de5', bytes: 5_175_832, executable: true },
|
|
21
|
+
engine: { name: 'parakeet-cli-linux-x86_64', from: `${RELEASE}/parakeet-cli-linux-x86_64`, sha256: 'bb2585695992fe1927a33960002cdf51b8a90a96ad65593c3d0a9f1fbc0865c2', bytes: 3_801_616, executable: true },
|
|
20
22
|
},
|
|
21
23
|
'linux-arm64': {
|
|
22
|
-
decoder: {
|
|
23
|
-
engine: {
|
|
24
|
+
decoder: { name: 'ffmpeg-linux-aarch64', from: `${RELEASE}/ffmpeg-linux-aarch64`, sha256: 'a7e08a0fae0179d1078312f6bb13d2a9aa4d4c71a1d82a022953f25dee452f5e', bytes: 4_590_208, executable: true },
|
|
25
|
+
engine: { name: 'parakeet-cli-linux-aarch64', from: `${RELEASE}/parakeet-cli-linux-aarch64`, sha256: 'cbc0bedc8daae97f1ef9dcee4200c06226218e300e0fd62ead1306d22742b7ed', bytes: 3_477_624, executable: true },
|
|
24
26
|
},
|
|
25
27
|
'darwin-arm64': {
|
|
26
|
-
decoder: {
|
|
27
|
-
engine: {
|
|
28
|
+
decoder: { name: 'ffmpeg-darwin-arm64', from: `${RELEASE}/ffmpeg-darwin-arm64`, sha256: '7abe154aaed3d6b49f5167ca7221bb66bed51388925d99a7e4261a41fe52fba6', bytes: 3_696_768, executable: true },
|
|
29
|
+
engine: { name: 'parakeet-cli-darwin-arm64', from: `${RELEASE}/parakeet-cli-darwin-arm64`, sha256: '9a2aafc0922ad7c0b6db6eff1641e96572ba32ac40bf995a1df242ed2febf297', bytes: 1_939_728, executable: true },
|
|
28
30
|
},
|
|
29
31
|
};
|
|
30
32
|
const CHUNK_SECONDS = 20;
|
|
33
|
+
const OFF = "transcription is off on the Agent's Environment, so this message's audio has no text; turn it on or write instead";
|
|
34
|
+
const NOT_INSTALLED = "the speech engine is not installed on the Agent's Environment, so this message's audio has no text";
|
|
35
|
+
const NOT_DOWNLOADED = 'an audio file this message links could not be downloaded; send the message again';
|
|
36
|
+
const UNDECODABLE = 'an audio file this message links could not be decoded';
|
|
37
|
+
const UNTRANSCRIBED = 'an audio file this message links could not be transcribed';
|
|
31
38
|
let held = Promise.resolve();
|
|
32
39
|
let holding = Promise.resolve();
|
|
33
40
|
let setting = null;
|
|
@@ -40,7 +47,7 @@ function installed(artifact) {
|
|
|
40
47
|
return join(directory(), artifact.sha256);
|
|
41
48
|
}
|
|
42
49
|
async function executed(command, args, signal) {
|
|
43
|
-
// A
|
|
50
|
+
// A decode or a transcription runs as long as its audio needs; the setting turning off or the turn's interrupt or end aborts it instead.
|
|
44
51
|
const ran = await run(command, args, 0, false, signal);
|
|
45
52
|
if (ran.status !== 0)
|
|
46
53
|
throw new Error(failureOf(ran, basename(command)));
|
|
@@ -54,17 +61,45 @@ async function threads() {
|
|
|
54
61
|
const allowed = quota === 'max' ? Infinity : Math.ceil(Number(quota) / Number(period));
|
|
55
62
|
return Math.max(1, Math.floor(Math.min(availableParallelism(), allowed) / 2));
|
|
56
63
|
}
|
|
57
|
-
async function sha256(path) {
|
|
58
|
-
const hash = createHash('sha256');
|
|
59
|
-
await pipeline(createReadStream(path), hash);
|
|
60
|
-
return hash.digest('hex');
|
|
61
|
-
}
|
|
62
64
|
function causeOf(error) {
|
|
63
65
|
return error instanceof Error ? error.message : String(error);
|
|
64
66
|
}
|
|
67
|
+
async function failing(reason, work) {
|
|
68
|
+
try {
|
|
69
|
+
return await work;
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
throw new Error(reason, { cause: error });
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function ready() {
|
|
76
|
+
if (setting !== true)
|
|
77
|
+
throw new Error(OFF);
|
|
78
|
+
if (!readiness.installed)
|
|
79
|
+
throw new Error(NOT_INSTALLED);
|
|
80
|
+
}
|
|
65
81
|
function pinnedHere() {
|
|
66
82
|
return ENGINES[`${process.platform}-${process.arch}`];
|
|
67
83
|
}
|
|
84
|
+
const DOWNLOADS = 3;
|
|
85
|
+
async function downloadedAgain(artifact, signal) {
|
|
86
|
+
// An artifact arrives at a hundred kilobytes a second or its download ends, so a stalled Building cannot hold the install open.
|
|
87
|
+
const deadlineMs = Math.ceil(artifact.bytes / 100);
|
|
88
|
+
const deadline = AbortSignal.timeout(deadlineMs);
|
|
89
|
+
for (let attempt = 1;; attempt++) {
|
|
90
|
+
try {
|
|
91
|
+
return await downloadServed(artifact.name, artifact.sha256, `${installed(artifact)}.part`, AbortSignal.any([signal, deadline]), artifact.bytes);
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
if (signal.aborted)
|
|
95
|
+
throw error;
|
|
96
|
+
if (deadline.aborted)
|
|
97
|
+
throw new Error(`${artifact.name} did not arrive within ${Math.ceil(deadlineMs / 1000)} seconds`);
|
|
98
|
+
if (attempt === DOWNLOADS)
|
|
99
|
+
throw error;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
68
103
|
async function install(artifacts, signal) {
|
|
69
104
|
await mkdir(directory(), { recursive: true });
|
|
70
105
|
const pinned = new Set(artifacts.map((artifact) => artifact.sha256));
|
|
@@ -77,13 +112,8 @@ async function install(artifacts, signal) {
|
|
|
77
112
|
if (!(await present(installed(artifact))))
|
|
78
113
|
missing.push(artifact);
|
|
79
114
|
try {
|
|
80
|
-
for (const artifact of missing)
|
|
81
|
-
|
|
82
|
-
// Three retries carry a large download past a dropped connection before the download fails.
|
|
83
|
-
await executed('curl', ['-fsSL', '--retry', '3', '-o', part, artifact.url], signal);
|
|
84
|
-
if ((await sha256(part)) !== artifact.sha256)
|
|
85
|
-
throw new Error(`${artifact.url} does not match its sha256`);
|
|
86
|
-
}
|
|
115
|
+
for (const artifact of missing)
|
|
116
|
+
await downloadedAgain(artifact, signal);
|
|
87
117
|
for (const artifact of missing) {
|
|
88
118
|
if (artifact.executable)
|
|
89
119
|
await chmod(`${installed(artifact)}.part`, 0o755);
|
|
@@ -96,7 +126,7 @@ async function install(artifacts, signal) {
|
|
|
96
126
|
}
|
|
97
127
|
}
|
|
98
128
|
function reported(next) {
|
|
99
|
-
const changed = next
|
|
129
|
+
const changed = !isDeepStrictEqual(next, readiness);
|
|
100
130
|
readiness = next;
|
|
101
131
|
return changed;
|
|
102
132
|
}
|
|
@@ -108,10 +138,12 @@ async function settle(transcribe) {
|
|
|
108
138
|
await rm(directory(), { recursive: true, force: true });
|
|
109
139
|
return reported({ installed: false, failure: null });
|
|
110
140
|
}
|
|
141
|
+
const pinned = pinnedHere();
|
|
142
|
+
if (pinned === undefined)
|
|
143
|
+
return reported({ installed: false, failure: null, no_engine: true });
|
|
111
144
|
const download = new AbortController();
|
|
112
145
|
downloading = download;
|
|
113
146
|
try {
|
|
114
|
-
const pinned = pinnedHere();
|
|
115
147
|
await install([pinned.decoder, pinned.engine, MODEL], download.signal);
|
|
116
148
|
return reported({ installed: true, failure: null });
|
|
117
149
|
}
|
|
@@ -133,27 +165,23 @@ export function holdTranscription(transcribe) {
|
|
|
133
165
|
export function transcriptionReport() {
|
|
134
166
|
return readiness;
|
|
135
167
|
}
|
|
136
|
-
async function transcribed(
|
|
168
|
+
async function transcribed(audio, parts, signal) {
|
|
137
169
|
const pinned = pinnedHere();
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
await rm(work, { recursive: true, force: true });
|
|
152
|
-
}
|
|
170
|
+
await mkdir(parts);
|
|
171
|
+
await failing(UNDECODABLE, executed(installed(pinned.decoder), ['-nostdin', '-hide_banner', '-loglevel', 'error', '-i', audio, '-ar', '16000', '-ac', '1', '-c:a', 'pcm_s16le',
|
|
172
|
+
'-f', 'segment', '-segment_time', String(CHUNK_SECONDS), join(parts, '%05d.wav')], signal));
|
|
173
|
+
const segments = (await readdir(parts)).sort().flatMap((part) => ['-f', join(parts, part)]);
|
|
174
|
+
const said = await failing(UNTRANSCRIBED, executed(installed(pinned.engine), ['-t', String(await threads()), '-np', '-m', installed(MODEL), ...segments], signal));
|
|
175
|
+
const text = said
|
|
176
|
+
.split('\n')
|
|
177
|
+
.map((line) => line.trim())
|
|
178
|
+
.filter((line) => line !== '')
|
|
179
|
+
.join(' ');
|
|
180
|
+
if (text === '')
|
|
181
|
+
throw new Error(UNTRANSCRIBED);
|
|
182
|
+
return text;
|
|
153
183
|
}
|
|
154
|
-
|
|
155
|
-
if (!readiness.installed)
|
|
156
|
-
return null;
|
|
184
|
+
async function alone(work, signal) {
|
|
157
185
|
const before = held;
|
|
158
186
|
let release;
|
|
159
187
|
const mine = new Promise((resolve) => {
|
|
@@ -162,9 +190,24 @@ export async function transcribe(path, signal) {
|
|
|
162
190
|
held = Promise.all([before, mine]);
|
|
163
191
|
try {
|
|
164
192
|
await unlessAborted(before, signal);
|
|
165
|
-
return
|
|
193
|
+
return await work();
|
|
166
194
|
}
|
|
167
195
|
finally {
|
|
168
196
|
release();
|
|
169
197
|
}
|
|
170
198
|
}
|
|
199
|
+
export async function transcribe(address, signal) {
|
|
200
|
+
ready();
|
|
201
|
+
const work = await mkdtemp(join(tmpdir(), 'kit-transcription-'));
|
|
202
|
+
try {
|
|
203
|
+
const audio = join(work, 'audio');
|
|
204
|
+
await failing(NOT_DOWNLOADED, downloaded(address, (url) => fetched(url, signal), audio, 'audio'));
|
|
205
|
+
return await alone(() => {
|
|
206
|
+
ready();
|
|
207
|
+
return transcribed(audio, join(work, 'parts'), signal);
|
|
208
|
+
}, signal);
|
|
209
|
+
}
|
|
210
|
+
finally {
|
|
211
|
+
await rm(work, { recursive: true, force: true });
|
|
212
|
+
}
|
|
213
|
+
}
|
package/dist/update.js
CHANGED
|
@@ -1,138 +1,136 @@
|
|
|
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
|
-
|
|
10
|
-
|
|
4
|
+
import { downloadServed, servedRelease } from './building.js';
|
|
5
|
+
import { KIT_RELEASE } from './clis.js';
|
|
6
|
+
import { restartPlaced, 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);
|
|
11
21
|
}
|
|
12
|
-
function
|
|
13
|
-
return
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
22
|
+
function placing(installer, house, prefix, signal) {
|
|
23
|
+
return new Promise((resolve) => {
|
|
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
|
+
});
|
|
59
|
+
});
|
|
35
60
|
}
|
|
36
|
-
async function
|
|
61
|
+
async function placed(prefix, admit) {
|
|
62
|
+
const signal = AbortSignal.timeout(PLACEMENT_MS);
|
|
63
|
+
let version = '';
|
|
37
64
|
try {
|
|
38
|
-
|
|
65
|
+
const placedIn = prefix();
|
|
66
|
+
const served = await servedRelease(signal);
|
|
67
|
+
admit(served.version);
|
|
68
|
+
version = served.version;
|
|
69
|
+
await mkdir(join(kitHome(), 'update'), { recursive: true, mode: 0o700 });
|
|
70
|
+
const installer = join(kitHome(), 'update', served.installer);
|
|
71
|
+
await downloadServed(served.installer, served.sha256, installer, signal, INSTALLER_BYTES);
|
|
72
|
+
return { version, failure: await placing(installer, (await readEnrolment()).house, placedIn, signal) };
|
|
39
73
|
}
|
|
40
|
-
catch {
|
|
41
|
-
return
|
|
74
|
+
catch (error) {
|
|
75
|
+
return { version, failure: signal.aborted ? `the placement did not end within ${PLACEMENT_MS / 1000} seconds` : causeOf(error) };
|
|
42
76
|
}
|
|
43
77
|
}
|
|
44
|
-
async function
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
return null;
|
|
48
|
-
return status.trim() === '0' ? {} : { refused: `the Kit bootstrap exited with ${status.trim()}` };
|
|
49
|
-
}
|
|
50
|
-
async function forget(inputId) {
|
|
51
|
-
if ((await pendingInput()) !== inputId)
|
|
52
|
-
return;
|
|
53
|
-
await rm(pending(), { force: true });
|
|
54
|
-
await rm(outcome(), { force: true });
|
|
78
|
+
export async function placeServedRelease(prefix) {
|
|
79
|
+
const { version, failure } = await placed(() => prefix, () => undefined);
|
|
80
|
+
return failure === null ? null : `${version === '' ? "The Building's Kit release" : `Kit ${version}`} could not be placed: ${failure}`;
|
|
55
81
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
82
|
+
export class KitUpdate {
|
|
83
|
+
calls;
|
|
84
|
+
queue = Promise.resolve();
|
|
85
|
+
placed = null;
|
|
86
|
+
constructor(calls) {
|
|
87
|
+
this.calls = calls;
|
|
88
|
+
}
|
|
89
|
+
take(call) {
|
|
90
|
+
void this.calls.carry(call.input_id, async () => ({ result: await this.queued(() => this.update(call.release)) }));
|
|
91
|
+
}
|
|
92
|
+
async takeRefused(release) {
|
|
93
|
+
for (;;) {
|
|
94
|
+
const failure = await this.queued(async () => (this.placed === null ? this.place(release, 'served') : null));
|
|
95
|
+
if (failure === null)
|
|
96
|
+
restartPlaced(this.placed);
|
|
97
|
+
process.stderr.write(`kit: ${updateLine(`Kit ${KIT_RELEASE} stays offline and tries again in ${PLACEMENT_RETRY_MS / 60_000} minutes`)}\n`);
|
|
98
|
+
await new Promise((resolve) => setTimeout(resolve, PLACEMENT_RETRY_MS));
|
|
64
99
|
}
|
|
65
|
-
// The bootstrap runs for minutes, so checking each second sees its outcome within a second at little cost.
|
|
66
|
-
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
67
100
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
return new Promise((resolve) => {
|
|
71
|
-
const [command, ...args] = [
|
|
72
|
-
...elevated(),
|
|
73
|
-
'systemd-run',
|
|
74
|
-
...manager(),
|
|
75
|
-
...account(),
|
|
76
|
-
'--wait',
|
|
77
|
-
'--collect',
|
|
78
|
-
'--quiet',
|
|
79
|
-
`--unit=${unit(inputId)}`,
|
|
80
|
-
`--setenv=HOME=${homedir()}`,
|
|
81
|
-
`--setenv=HOUSE_KIT_HOME=${kitHome()}`,
|
|
82
|
-
'/bin/sh',
|
|
83
|
-
'-c',
|
|
84
|
-
record(),
|
|
85
|
-
script,
|
|
86
|
-
outcome(),
|
|
87
|
-
...placement(),
|
|
88
|
-
...flags,
|
|
89
|
-
];
|
|
90
|
-
const child = spawn(command, args, { stdio: ['ignore', 'ignore', 'inherit'] });
|
|
91
|
-
child.on('error', () => resolve({ refused: 'no service manager runs this Kit' }));
|
|
92
|
-
child.on('close', () => resolve(null));
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
export class Updates {
|
|
96
|
-
inputs;
|
|
97
|
-
queue = Promise.resolve();
|
|
98
|
-
constructor(inputs) {
|
|
99
|
-
this.inputs = inputs;
|
|
101
|
+
placedRelease() {
|
|
102
|
+
return this.placed;
|
|
100
103
|
}
|
|
101
|
-
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
await this.enqueue(inputId, () => finished(inputId));
|
|
104
|
+
queued(work) {
|
|
105
|
+
const taken = this.queue.then(work);
|
|
106
|
+
this.queue = taken.catch(() => undefined);
|
|
107
|
+
return taken;
|
|
106
108
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
+
async update(release) {
|
|
110
|
+
if (release === (this.placed ?? KIT_RELEASE))
|
|
111
|
+
return {};
|
|
112
|
+
if (this.placed !== null)
|
|
113
|
+
return { refused: `Kit ${this.placed} is placed and starts first, once no turn is open` };
|
|
114
|
+
const failure = await this.place(release, 'named');
|
|
115
|
+
if (failure !== null)
|
|
116
|
+
return { refused: failure };
|
|
117
|
+
const starts = process.env.HOUSE_KIT_SANDBOX === '1' ? 'when the Sandbox starts again' : 'once no turn is open';
|
|
118
|
+
process.stderr.write(`kit: Kit ${release} is placed; it starts ${starts}\n`);
|
|
119
|
+
return {};
|
|
109
120
|
}
|
|
110
|
-
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
121
|
+
async place(release, which) {
|
|
122
|
+
const { version, failure } = await placed(placedPrefix, (served) => {
|
|
123
|
+
if (which === 'named' && served !== release)
|
|
124
|
+
throw new Error(`the Building serves Kit ${served}, not Kit ${release}`);
|
|
125
|
+
if (served === KIT_RELEASE)
|
|
126
|
+
throw new Error(`the Building serves Kit ${KIT_RELEASE}, which this Kit runs`);
|
|
115
127
|
});
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
if ((await pendingInput()) === input.input_id)
|
|
121
|
-
return finished(input.input_id);
|
|
122
|
-
const answer = await fetch(input.bootstrap);
|
|
123
|
-
if (!answer.ok)
|
|
124
|
-
return { refused: `the Kit bootstrap could not be downloaded: ${answer.status}` };
|
|
125
|
-
const script = Buffer.from(await answer.arrayBuffer());
|
|
126
|
-
if (createHash('sha256').update(script).digest('hex') !== input.sha256) {
|
|
127
|
-
return { refused: 'the Kit bootstrap does not match its sha256' };
|
|
128
|
+
if (failure !== null) {
|
|
129
|
+
const refused = `Kit ${version || release} could not be placed: ${failure}`;
|
|
130
|
+
process.stderr.write(`kit: ${refused}\n`);
|
|
131
|
+
return refused;
|
|
128
132
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
await writeFile(path, script, { mode: 0o700 });
|
|
132
|
-
await rm(outcome(), { force: true });
|
|
133
|
-
await writeFile(pending(), `${JSON.stringify({ input_id: input.input_id })}\n`, { mode: 0o600 });
|
|
134
|
-
return (await rerun(path, input.input_id, input.update_clis ? ['--update-clis'] : [])) ?? (await recorded()) ?? {
|
|
135
|
-
refused: 'the Kit bootstrap did not finish',
|
|
136
|
-
};
|
|
133
|
+
this.placed = version;
|
|
134
|
+
return null;
|
|
137
135
|
}
|
|
138
136
|
}
|
package/dist/wire.js
CHANGED
|
@@ -1,6 +1,32 @@
|
|
|
1
|
+
import { updateRequired } from './end.js';
|
|
1
2
|
import { refusalOf } from './refusals.js';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
let take = null;
|
|
4
|
+
let taken = false;
|
|
5
|
+
function unservedBy(text) {
|
|
6
|
+
let body;
|
|
7
|
+
try {
|
|
8
|
+
body = JSON.parse(text);
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
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;
|
|
20
|
+
}
|
|
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
|
+
}
|
|
30
|
+
if (refusalOf(text)?.code === 'kit_update_required')
|
|
31
|
+
updateRequired();
|
|
6
32
|
}
|
package/dist/work.js
CHANGED
|
@@ -25,6 +25,9 @@ export class Work {
|
|
|
25
25
|
return {};
|
|
26
26
|
}
|
|
27
27
|
async settled() { }
|
|
28
|
+
caughtUp() {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
28
31
|
read(message) {
|
|
29
32
|
this.take(message);
|
|
30
33
|
this.changed();
|
|
@@ -177,6 +180,7 @@ class ClaudeWork extends Work {
|
|
|
177
180
|
}
|
|
178
181
|
}
|
|
179
182
|
class CodexWork extends Work {
|
|
183
|
+
tapped;
|
|
180
184
|
threads = new Map();
|
|
181
185
|
queues = new Map();
|
|
182
186
|
goals = new Set();
|
|
@@ -184,6 +188,7 @@ class CodexWork extends Work {
|
|
|
184
188
|
hooks = new Set();
|
|
185
189
|
starting = new Set();
|
|
186
190
|
settling = [];
|
|
191
|
+
waiting = [];
|
|
187
192
|
memories = null;
|
|
188
193
|
lost = false;
|
|
189
194
|
server = null;
|
|
@@ -193,6 +198,10 @@ class CodexWork extends Work {
|
|
|
193
198
|
heard = 0;
|
|
194
199
|
proving = -1;
|
|
195
200
|
proven = -1;
|
|
201
|
+
constructor(changed, tapped) {
|
|
202
|
+
super(changed);
|
|
203
|
+
this.tapped = tapped;
|
|
204
|
+
}
|
|
196
205
|
async open(cli) {
|
|
197
206
|
this.path = join(socketDirectory(), `${randomUUID()}.sock`);
|
|
198
207
|
this.server = createServer((socket) => this.connected(socket));
|
|
@@ -210,6 +219,14 @@ class CodexWork extends Work {
|
|
|
210
219
|
super.take(message);
|
|
211
220
|
this.heard++;
|
|
212
221
|
}
|
|
222
|
+
caughtUp() {
|
|
223
|
+
if (this.lost || this.socket === null)
|
|
224
|
+
return null;
|
|
225
|
+
const { promise, resolve } = Promise.withResolvers();
|
|
226
|
+
this.waiting.push({ heard: this.heard, resolve });
|
|
227
|
+
this.prove();
|
|
228
|
+
return promise;
|
|
229
|
+
}
|
|
213
230
|
busy() {
|
|
214
231
|
if (super.busy() ||
|
|
215
232
|
this.lost ||
|
|
@@ -259,6 +276,7 @@ class CodexWork extends Work {
|
|
|
259
276
|
}
|
|
260
277
|
lose() {
|
|
261
278
|
this.lost = true;
|
|
279
|
+
this.release();
|
|
262
280
|
this.changed();
|
|
263
281
|
}
|
|
264
282
|
prove() {
|
|
@@ -267,6 +285,10 @@ class CodexWork extends Work {
|
|
|
267
285
|
this.proving = this.heard;
|
|
268
286
|
this.socket.write(`${JSON.stringify({ jsonrpc: '2.0', id: `${SYNC}${this.heard}`, method: 'house-kit/sync' })}\n`);
|
|
269
287
|
}
|
|
288
|
+
release() {
|
|
289
|
+
while (this.waiting[0] !== undefined && (this.lost || this.waiting[0].heard <= this.proven))
|
|
290
|
+
this.waiting.shift().resolve();
|
|
291
|
+
}
|
|
270
292
|
settle() {
|
|
271
293
|
if (this.starting.size === 0)
|
|
272
294
|
for (const resolve of this.settling.splice(0))
|
|
@@ -274,6 +296,8 @@ class CodexWork extends Work {
|
|
|
274
296
|
}
|
|
275
297
|
stream(message, socket) {
|
|
276
298
|
const params = message.params;
|
|
299
|
+
if (message.method !== undefined)
|
|
300
|
+
this.tapped(message);
|
|
277
301
|
switch (message.method) {
|
|
278
302
|
case 'thread/status/changed':
|
|
279
303
|
this.threads.set(params.threadId, params.status.type === 'active' && params.status.activeFlags.length === 0);
|
|
@@ -319,6 +343,7 @@ class CodexWork extends Work {
|
|
|
319
343
|
answered(message) {
|
|
320
344
|
if (typeof message.id === 'string' && message.id.startsWith(SYNC)) {
|
|
321
345
|
this.proven = Number(message.id.slice(SYNC.length));
|
|
346
|
+
this.release();
|
|
322
347
|
}
|
|
323
348
|
else if (typeof message.id === 'string' && message.id.startsWith(QUEUE_LIST)) {
|
|
324
349
|
const asked = Number(message.id.slice(QUEUE_LIST.length));
|
|
@@ -337,10 +362,10 @@ class GrokWork extends Work {
|
|
|
337
362
|
return true;
|
|
338
363
|
}
|
|
339
364
|
}
|
|
340
|
-
export function workFor(kind, cwd, changed) {
|
|
365
|
+
export function workFor(kind, cwd, changed, tapped) {
|
|
341
366
|
if (kind === 'claude-agent-acp')
|
|
342
367
|
return new ClaudeWork(cwd, changed);
|
|
343
368
|
if (kind === 'codex-acp')
|
|
344
|
-
return new CodexWork(changed);
|
|
369
|
+
return new CodexWork(changed, tapped);
|
|
345
370
|
return new GrokWork(changed);
|
|
346
371
|
}
|