@agentshouse/kit 0.2.1-ce145e9aadbf6 → 0.2.1-ce3d2bb67177c
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +40 -39
- package/dist/acp.js +48 -105
- package/dist/agents.js +153 -43
- package/dist/api.js +34 -2
- package/dist/app-git.js +48 -0
- package/dist/bootstrap.json +4 -4
- package/dist/bridge.js +36 -57
- package/dist/calls.js +63 -0
- package/dist/chatgpt.js +32 -0
- package/dist/clis.js +127 -70
- package/dist/codex-main.js +58 -0
- package/dist/connection.js +125 -0
- package/dist/conversations.js +620 -323
- package/dist/copies.js +188 -128
- package/dist/end.js +27 -0
- package/dist/enrol-main.js +7 -1
- package/dist/events.js +525 -0
- package/dist/files.js +123 -17
- package/dist/git.js +11 -9
- package/dist/home.js +96 -7
- package/dist/house-cli.js +327 -0
- package/dist/house-main.js +7 -159
- package/dist/instructions.js +10 -32
- package/dist/kit-cli.js +68 -0
- package/dist/kit-main.js +8 -19
- package/dist/login.js +117 -104
- package/dist/logout.js +14 -13
- package/dist/mcp.js +4 -2
- package/dist/parts.js +82 -0
- package/dist/placement.js +39 -0
- package/dist/refusals.js +12 -0
- package/dist/relay.js +12 -2
- package/dist/resident.js +106 -50
- package/dist/scope.js +206 -0
- package/dist/secret-input.js +3 -2
- package/dist/service-main.js +9 -0
- package/dist/service.js +55 -0
- package/dist/shell.js +3 -0
- package/dist/sign-in.js +37 -31
- package/dist/skills.js +84 -15
- package/dist/transcription.js +100 -21
- package/dist/translate.js +2 -8
- package/dist/update.js +71 -50
- package/dist/wire.js +22 -0
- package/dist/work.js +346 -0
- package/how-we-work.md +13 -3
- package/package.json +4 -3
- package/skills/ask-matt/SKILL.md +17 -11
- package/skills/ask-matt/agents/openai.yaml +1 -0
- package/skills/code-review/SKILL.md +5 -5
- package/skills/codebase-design/DESIGN-IT-TWICE.md +1 -1
- package/skills/codebase-design/SKILL.md +0 -2
- package/skills/diagnosing-bugs/SKILL.md +2 -4
- package/skills/domain-modeling/{CONTEXT-FORMAT.md → GLOSSARY-FORMAT.md} +10 -10
- package/skills/domain-modeling/SKILL.md +12 -14
- package/skills/grill-me/SKILL.md +1 -2
- package/skills/grill-me/agents/openai.yaml +1 -0
- package/skills/grill-with-docs/SKILL.md +1 -2
- package/skills/grill-with-docs/agents/openai.yaml +1 -0
- package/skills/grilling/SKILL.md +2 -2
- package/skills/handoff/SKILL.md +2 -3
- package/skills/handoff/agents/openai.yaml +1 -0
- package/skills/implement/SKILL.md +5 -4
- package/skills/implement/agents/openai.yaml +1 -0
- package/skills/implement-spec/SKILL.md +40 -0
- package/skills/implement-spec/agents/openai.yaml +5 -0
- package/skills/improve-codebase-architecture/SKILL.md +6 -7
- package/skills/improve-codebase-architecture/agents/openai.yaml +1 -0
- package/skills/pr/CREDITS.md +3 -0
- package/skills/pr/LICENSE +21 -0
- package/skills/pr/SKILL.md +170 -0
- package/skills/pr/agents/openai.yaml +3 -0
- package/skills/prototype/SKILL.md +0 -2
- package/skills/research/SKILL.md +0 -2
- package/skills/retro/LICENSE +21 -0
- package/skills/retro/SKILL.md +44 -0
- package/skills/retro/agents/openai.yaml +5 -0
- package/skills/tdd/SKILL.md +2 -4
- package/skills/teach/SKILL.md +3 -4
- package/skills/teach/agents/openai.yaml +1 -0
- package/skills/to-questionnaire/SKILL.md +1 -2
- package/skills/to-questionnaire/agents/openai.yaml +1 -0
- package/skills/to-spec/SKILL.md +1 -2
- package/skills/to-spec/agents/openai.yaml +1 -0
- package/skills/to-tickets/SKILL.md +3 -4
- package/skills/to-tickets/agents/openai.yaml +1 -0
- package/skills/triage/AGENT-BRIEF.md +207 -0
- package/skills/triage/LICENSE +21 -0
- package/skills/triage/OUT-OF-SCOPE.md +105 -0
- package/skills/triage/SKILL.md +112 -0
- package/skills/triage/agents/openai.yaml +5 -0
- package/skills/wait-what/SKILL.md +2 -3
- package/skills/wait-what/agents/openai.yaml +1 -0
- package/skills/wayfinder/SKILL.md +5 -6
- package/skills/wayfinder/agents/openai.yaml +1 -0
- package/skills/wizard/LICENSE +21 -0
- package/skills/wizard/SKILL.md +44 -0
- package/skills/wizard/agents/openai.yaml +3 -0
- package/skills/wizard/template.sh +223 -0
- package/skills/writing-for-agents/SKILL.md +0 -2
- package/dist/blocks.js +0 -51
- package/dist/stream.js +0 -47
- package/skills/resolving-merge-conflicts/SKILL.md +0 -16
- package/skills/resolving-merge-conflicts/agents/openai.yaml +0 -3
- /package/skills/{resolving-merge-conflicts → implement-spec}/LICENSE +0 -0
package/dist/skills.js
CHANGED
|
@@ -1,17 +1,31 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
1
2
|
import { readFileSync } from 'node:fs';
|
|
2
|
-
import { cp, lstat, mkdir, readdir, realpath, rm, symlink
|
|
3
|
+
import { cp, lstat, mkdir, readdir, realpath, rm, symlink } from 'node:fs/promises';
|
|
3
4
|
import { homedir } from 'node:os';
|
|
4
5
|
import { join, relative } from 'node:path';
|
|
5
6
|
import { fileURLToPath } from 'node:url';
|
|
6
|
-
import {
|
|
7
|
+
import { parse } from 'yaml';
|
|
8
|
+
import { KIT_RELEASE } from './clis.js';
|
|
7
9
|
import { kitHome, readConfiguration, readHome, writeHome } from './home.js';
|
|
8
10
|
import { refusalOf } from './refusals.js';
|
|
9
|
-
|
|
11
|
+
const HOW_WE_WORK = '/rooms/private/how-we-work.md';
|
|
10
12
|
const SKILL_SET = fileURLToPath(new URL('../skills/', import.meta.url));
|
|
11
13
|
const HOW_WE_WORK_TEXT = readFileSync(new URL('../how-we-work.md', import.meta.url), 'utf8');
|
|
14
|
+
const SHIPPED_HOW_WE_WORK = [
|
|
15
|
+
'ae4dda60da7b174f22dc5fa9bf07fc27c25864932a74230de4f9f509ddd91f41',
|
|
16
|
+
'0bdcd43e1603ba6673a3cae56d70bbf90657cbeefd124e91a47be2ca1cbd6c93',
|
|
17
|
+
'4106a87ec66da6f7b2a10e74d18e6559d68d5f4fe7415dae68f5c7bdb9081968',
|
|
18
|
+
'ac814a2197038f037b657bb719340395f89f319ac9fcdd386629c3fe2cec68f1',
|
|
19
|
+
'29951ee394aad9979eecfed3e5dc32c2c86e2226b6a380db5dbd4f305f4d1156',
|
|
20
|
+
];
|
|
12
21
|
const RECORD = 'skill-set.json';
|
|
13
|
-
const
|
|
22
|
+
const WRITTEN = 'how-we-work.json';
|
|
14
23
|
const UNWRITABLE = new Set(['room_not_found', 'operation_denied']);
|
|
24
|
+
const PRESENT = new Set(['path_exists']);
|
|
25
|
+
const CHANGED = new Set(['base_revision_stale', 'path_absent']);
|
|
26
|
+
const UNREADABLE = /^(?:\S+: )?(?:path_not_found|room_not_found|operation_denied)\b/;
|
|
27
|
+
const FAILED = /^exit: [1-9]\d*$/;
|
|
28
|
+
const CUT = /^stderr: shell: output_cut (\d+) of \d+ bytes; continue with: (.+)$/;
|
|
15
29
|
function skillsDirectory() {
|
|
16
30
|
return join(homedir(), '.agents', 'skills');
|
|
17
31
|
}
|
|
@@ -46,12 +60,20 @@ async function install() {
|
|
|
46
60
|
if (claude !== skills)
|
|
47
61
|
await symlink(relative(claude, join(skills, name)), join(claudeDirectory(), name));
|
|
48
62
|
}
|
|
49
|
-
await writeHome(RECORD, { version:
|
|
63
|
+
await writeHome(RECORD, { version: KIT_RELEASE, names });
|
|
50
64
|
}
|
|
51
65
|
export async function placeSkillSet() {
|
|
66
|
+
try {
|
|
67
|
+
await replaceSkillSet();
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
process.stderr.write(`kit: the skills could not be placed: ${error.message}\n`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
async function replaceSkillSet() {
|
|
52
74
|
const accepted = (await readConfiguration()).skills;
|
|
53
75
|
const installed = await readHome(RECORD);
|
|
54
|
-
if (accepted && installed?.version ===
|
|
76
|
+
if (accepted && installed?.version === KIT_RELEASE)
|
|
55
77
|
return;
|
|
56
78
|
for (const name of installed?.names ?? []) {
|
|
57
79
|
await rm(join(claudeDirectory(), name), { recursive: true, force: true });
|
|
@@ -62,17 +84,64 @@ export async function placeSkillSet() {
|
|
|
62
84
|
else
|
|
63
85
|
await rm(join(kitHome(), RECORD), { force: true });
|
|
64
86
|
}
|
|
87
|
+
function sha256(text) {
|
|
88
|
+
return createHash('sha256').update(text).digest('hex');
|
|
89
|
+
}
|
|
90
|
+
function cutOf(lines) {
|
|
91
|
+
const cut = CUT.exec(lines[0] ?? '');
|
|
92
|
+
return cut !== null && Buffer.byteLength(lines.slice(1).join('\n')) === Number(cut[1]) ? cut : null;
|
|
93
|
+
}
|
|
94
|
+
export async function readHowWeWork(bridge) {
|
|
95
|
+
let document = '';
|
|
96
|
+
for (let command = `cat ${HOW_WE_WORK}`; command !== undefined;) {
|
|
97
|
+
const read = await bridge.tool('shell', { command });
|
|
98
|
+
const text = read.content.map((content) => content.text).join('\n');
|
|
99
|
+
const lines = text.split('\n');
|
|
100
|
+
if (read.isError === true || (FAILED.test(lines[0] ?? '') && lines[1]?.startsWith('stderr: '))) {
|
|
101
|
+
const refusal = read.isError === true ? text : lines.slice(1).join('\n').replace(/^stderr: /gm, '');
|
|
102
|
+
if (UNREADABLE.test(refusal))
|
|
103
|
+
return '';
|
|
104
|
+
throw new Error(refusal);
|
|
105
|
+
}
|
|
106
|
+
const cut = cutOf(lines);
|
|
107
|
+
document += lines.slice(cut === null ? 0 : 1).join('\n');
|
|
108
|
+
command = cut?.[2];
|
|
109
|
+
}
|
|
110
|
+
return document;
|
|
111
|
+
}
|
|
112
|
+
async function currentRevision(bridge) {
|
|
113
|
+
const inspected = await bridge.tool('inspect', { path: HOW_WE_WORK });
|
|
114
|
+
const text = inspected.content.map((content) => content.text).join('\n');
|
|
115
|
+
if (inspected.isError === true)
|
|
116
|
+
throw new Error(text);
|
|
117
|
+
return parse(text).revisions[0].revision;
|
|
118
|
+
}
|
|
119
|
+
async function edit(bridge, change, kept) {
|
|
120
|
+
const edited = await bridge.tool('edit', { changes: [{ ...change, path: HOW_WE_WORK, content: HOW_WE_WORK_TEXT }] });
|
|
121
|
+
if (edited.isError !== true)
|
|
122
|
+
return 'written';
|
|
123
|
+
const text = edited.content.map((content) => content.text).join('\n');
|
|
124
|
+
const refusal = refusalOf(text);
|
|
125
|
+
if (UNWRITABLE.has(refusal?.code ?? ''))
|
|
126
|
+
return 'unwritable';
|
|
127
|
+
if (refusal?.code === 'edit_conflict' && refusal.conflicts.some((conflict) => kept.has(conflict)))
|
|
128
|
+
return 'kept';
|
|
129
|
+
throw new Error(text);
|
|
130
|
+
}
|
|
65
131
|
export async function createHowWeWork(bridge) {
|
|
66
|
-
if ((await
|
|
132
|
+
if (!(await readConfiguration()).skills || (await readHome(RECORD))?.version === undefined)
|
|
133
|
+
return;
|
|
134
|
+
const current = sha256(HOW_WE_WORK_TEXT);
|
|
135
|
+
if ((await readHome(WRITTEN)) === current)
|
|
136
|
+
return;
|
|
137
|
+
const created = await edit(bridge, { op: 'create' }, PRESENT);
|
|
138
|
+
if (created === 'unwritable')
|
|
67
139
|
return;
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
if (UNWRITABLE.has(refusal?.code ?? ''))
|
|
140
|
+
if (created === 'kept') {
|
|
141
|
+
const base = await currentRevision(bridge);
|
|
142
|
+
const held = sha256(await readHowWeWork(bridge));
|
|
143
|
+
if (held !== current && SHIPPED_HOW_WE_WORK.includes(held) && (await edit(bridge, { op: 'replace', base }, CHANGED)) === 'unwritable')
|
|
73
144
|
return;
|
|
74
|
-
if (refusal?.code !== 'edit_conflict' || !refusal.conflicts.includes('path_exists'))
|
|
75
|
-
throw new Error(text);
|
|
76
145
|
}
|
|
77
|
-
await
|
|
146
|
+
await writeHome(WRITTEN, current);
|
|
78
147
|
}
|
package/dist/transcription.js
CHANGED
|
@@ -6,6 +6,7 @@ import { basename, join } from 'node:path';
|
|
|
6
6
|
import { pipeline } from 'node:stream/promises';
|
|
7
7
|
import { unlessAborted } from './abort.js';
|
|
8
8
|
import { failureOf, run } from './clis.js';
|
|
9
|
+
import { downloaded, fetched } from './files.js';
|
|
9
10
|
import { kitHome } from './home.js';
|
|
10
11
|
const RELEASE = 'https://github.com/agentshouse/kit/releases/download/engine-2';
|
|
11
12
|
export const MODEL = {
|
|
@@ -28,7 +29,16 @@ export const ENGINES = {
|
|
|
28
29
|
},
|
|
29
30
|
};
|
|
30
31
|
const CHUNK_SECONDS = 20;
|
|
32
|
+
const OFF = "transcription is off on the Agent's Environment, so this message's audio has no text; turn it on or write instead";
|
|
33
|
+
const NOT_INSTALLED = "the speech engine is not installed on the Agent's Environment, so this message's audio has no text";
|
|
34
|
+
const NOT_DOWNLOADED = 'an audio file this message links could not be downloaded; send the message again';
|
|
35
|
+
const UNDECODABLE = 'an audio file this message links could not be decoded';
|
|
36
|
+
const UNTRANSCRIBED = 'an audio file this message links could not be transcribed';
|
|
31
37
|
let held = Promise.resolve();
|
|
38
|
+
let holding = Promise.resolve();
|
|
39
|
+
let setting = null;
|
|
40
|
+
let downloading = null;
|
|
41
|
+
let readiness = { installed: false, failure: null };
|
|
32
42
|
function directory() {
|
|
33
43
|
return join(kitHome(), 'transcription');
|
|
34
44
|
}
|
|
@@ -36,6 +46,7 @@ function installed(artifact) {
|
|
|
36
46
|
return join(directory(), artifact.sha256);
|
|
37
47
|
}
|
|
38
48
|
async function executed(command, args, signal) {
|
|
49
|
+
// 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
50
|
const ran = await run(command, args, 0, false, signal);
|
|
40
51
|
if (ran.status !== 0)
|
|
41
52
|
throw new Error(failureOf(ran, basename(command)));
|
|
@@ -44,16 +55,36 @@ async function executed(command, args, signal) {
|
|
|
44
55
|
function present(path) {
|
|
45
56
|
return stat(path).then(() => true, () => false);
|
|
46
57
|
}
|
|
47
|
-
async function
|
|
58
|
+
async function threads() {
|
|
48
59
|
const [quota, period] = (await readFile('/sys/fs/cgroup/cpu.max', 'utf8').catch(() => 'max')).split(' ');
|
|
49
60
|
const allowed = quota === 'max' ? Infinity : Math.ceil(Number(quota) / Number(period));
|
|
50
|
-
return Math.min(availableParallelism(), allowed);
|
|
61
|
+
return Math.max(1, Math.floor(Math.min(availableParallelism(), allowed) / 2));
|
|
51
62
|
}
|
|
52
63
|
async function sha256(path) {
|
|
53
64
|
const hash = createHash('sha256');
|
|
54
65
|
await pipeline(createReadStream(path), hash);
|
|
55
66
|
return hash.digest('hex');
|
|
56
67
|
}
|
|
68
|
+
function causeOf(error) {
|
|
69
|
+
return error instanceof Error ? error.message : String(error);
|
|
70
|
+
}
|
|
71
|
+
async function failing(reason, work) {
|
|
72
|
+
try {
|
|
73
|
+
return await work;
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
throw new Error(reason, { cause: error });
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function ready() {
|
|
80
|
+
if (setting !== true)
|
|
81
|
+
throw new Error(OFF);
|
|
82
|
+
if (!readiness.installed)
|
|
83
|
+
throw new Error(NOT_INSTALLED);
|
|
84
|
+
}
|
|
85
|
+
function pinnedHere() {
|
|
86
|
+
return ENGINES[`${process.platform}-${process.arch}`];
|
|
87
|
+
}
|
|
57
88
|
async function install(artifacts, signal) {
|
|
58
89
|
await mkdir(directory(), { recursive: true });
|
|
59
90
|
const pinned = new Set(artifacts.map((artifact) => artifact.sha256));
|
|
@@ -68,6 +99,7 @@ async function install(artifacts, signal) {
|
|
|
68
99
|
try {
|
|
69
100
|
for (const artifact of missing) {
|
|
70
101
|
const part = `${installed(artifact)}.part`;
|
|
102
|
+
// Three retries carry a large download past a dropped connection before the download fails.
|
|
71
103
|
await executed('curl', ['-fsSL', '--retry', '3', '-o', part, artifact.url], signal);
|
|
72
104
|
if ((await sha256(part)) !== artifact.sha256)
|
|
73
105
|
throw new Error(`${artifact.url} does not match its sha256`);
|
|
@@ -83,29 +115,61 @@ async function install(artifacts, signal) {
|
|
|
83
115
|
await rm(`${installed(artifact)}.part`, { force: true });
|
|
84
116
|
}
|
|
85
117
|
}
|
|
86
|
-
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
118
|
+
function reported(next) {
|
|
119
|
+
const changed = next.installed !== readiness.installed || next.failure !== readiness.failure;
|
|
120
|
+
readiness = next;
|
|
121
|
+
return changed;
|
|
122
|
+
}
|
|
123
|
+
async function settle(transcribe) {
|
|
124
|
+
if (transcribe === setting)
|
|
125
|
+
return false;
|
|
126
|
+
setting = transcribe;
|
|
127
|
+
if (!transcribe) {
|
|
128
|
+
await rm(directory(), { recursive: true, force: true });
|
|
129
|
+
return reported({ installed: false, failure: null });
|
|
130
|
+
}
|
|
131
|
+
const download = new AbortController();
|
|
132
|
+
downloading = download;
|
|
93
133
|
try {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
.filter((line) => line !== '')
|
|
102
|
-
.join(' ');
|
|
134
|
+
const pinned = pinnedHere();
|
|
135
|
+
await install([pinned.decoder, pinned.engine, MODEL], download.signal);
|
|
136
|
+
return reported({ installed: true, failure: null });
|
|
137
|
+
}
|
|
138
|
+
catch (error) {
|
|
139
|
+
await rm(directory(), { recursive: true, force: true });
|
|
140
|
+
return reported({ installed: false, failure: download.signal.aborted ? null : causeOf(error) });
|
|
103
141
|
}
|
|
104
142
|
finally {
|
|
105
|
-
|
|
143
|
+
downloading = null;
|
|
106
144
|
}
|
|
107
145
|
}
|
|
108
|
-
export
|
|
146
|
+
export function holdTranscription(transcribe) {
|
|
147
|
+
if (!transcribe)
|
|
148
|
+
downloading?.abort();
|
|
149
|
+
const settled = holding.then(() => settle(transcribe));
|
|
150
|
+
holding = settled.catch(() => undefined);
|
|
151
|
+
return settled;
|
|
152
|
+
}
|
|
153
|
+
export function transcriptionReport() {
|
|
154
|
+
return readiness;
|
|
155
|
+
}
|
|
156
|
+
async function transcribed(audio, parts, signal) {
|
|
157
|
+
const pinned = pinnedHere();
|
|
158
|
+
await mkdir(parts);
|
|
159
|
+
await failing(UNDECODABLE, executed(installed(pinned.decoder), ['-nostdin', '-hide_banner', '-loglevel', 'error', '-i', audio, '-ar', '16000', '-ac', '1', '-c:a', 'pcm_s16le',
|
|
160
|
+
'-f', 'segment', '-segment_time', String(CHUNK_SECONDS), join(parts, '%05d.wav')], signal));
|
|
161
|
+
const segments = (await readdir(parts)).sort().flatMap((part) => ['-f', join(parts, part)]);
|
|
162
|
+
const said = await failing(UNTRANSCRIBED, executed(installed(pinned.engine), ['-t', String(await threads()), '-np', '-m', installed(MODEL), ...segments], signal));
|
|
163
|
+
const text = said
|
|
164
|
+
.split('\n')
|
|
165
|
+
.map((line) => line.trim())
|
|
166
|
+
.filter((line) => line !== '')
|
|
167
|
+
.join(' ');
|
|
168
|
+
if (text === '')
|
|
169
|
+
throw new Error(UNTRANSCRIBED);
|
|
170
|
+
return text;
|
|
171
|
+
}
|
|
172
|
+
async function alone(work, signal) {
|
|
109
173
|
const before = held;
|
|
110
174
|
let release;
|
|
111
175
|
const mine = new Promise((resolve) => {
|
|
@@ -114,9 +178,24 @@ export async function transcribe(path, signal) {
|
|
|
114
178
|
held = Promise.all([before, mine]);
|
|
115
179
|
try {
|
|
116
180
|
await unlessAborted(before, signal);
|
|
117
|
-
return await
|
|
181
|
+
return await work();
|
|
118
182
|
}
|
|
119
183
|
finally {
|
|
120
184
|
release();
|
|
121
185
|
}
|
|
122
186
|
}
|
|
187
|
+
export async function transcribe(address, signal) {
|
|
188
|
+
ready();
|
|
189
|
+
const work = await mkdtemp(join(tmpdir(), 'kit-transcription-'));
|
|
190
|
+
try {
|
|
191
|
+
const audio = join(work, 'audio');
|
|
192
|
+
await failing(NOT_DOWNLOADED, downloaded(address, (url) => fetched(url, signal), audio, 'audio'));
|
|
193
|
+
return await alone(() => {
|
|
194
|
+
ready();
|
|
195
|
+
return transcribed(audio, join(work, 'parts'), signal);
|
|
196
|
+
}, signal);
|
|
197
|
+
}
|
|
198
|
+
finally {
|
|
199
|
+
await rm(work, { recursive: true, force: true });
|
|
200
|
+
}
|
|
201
|
+
}
|
package/dist/translate.js
CHANGED
|
@@ -3,14 +3,8 @@ function same(left, right) {
|
|
|
3
3
|
return JSON.stringify(left) === JSON.stringify(right);
|
|
4
4
|
}
|
|
5
5
|
function applied(document, changes) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const result = apply(current, change);
|
|
9
|
-
if (result.outcome !== 'applied')
|
|
10
|
-
return null;
|
|
11
|
-
current = result.document;
|
|
12
|
-
}
|
|
13
|
-
return serialize(current);
|
|
6
|
+
const result = apply(document, changes);
|
|
7
|
+
return result.outcome === 'applied' ? serialize(result.document) : null;
|
|
14
8
|
}
|
|
15
9
|
function components(path, before, after, text) {
|
|
16
10
|
const edits = [];
|
package/dist/update.js
CHANGED
|
@@ -4,11 +4,8 @@ import { mkdir, readFile, rm, writeFile } from 'node:fs/promises';
|
|
|
4
4
|
import { homedir } from 'node:os';
|
|
5
5
|
import { join } from 'node:path';
|
|
6
6
|
import { run } from './clis.js';
|
|
7
|
-
import { kitHome } from './home.js';
|
|
8
|
-
|
|
9
|
-
function logged(error) {
|
|
10
|
-
process.stderr.write(`kit: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
11
|
-
}
|
|
7
|
+
import { kitHome, workspaceRoot } from './home.js';
|
|
8
|
+
import { service, throughSudo } from './placement.js';
|
|
12
9
|
function directory() {
|
|
13
10
|
return join(kitHome(), 'update');
|
|
14
11
|
}
|
|
@@ -18,10 +15,25 @@ function pending() {
|
|
|
18
15
|
function outcome() {
|
|
19
16
|
return join(directory(), 'outcome');
|
|
20
17
|
}
|
|
21
|
-
function unit(
|
|
22
|
-
return `house-kit-update-${
|
|
18
|
+
function unit(callId) {
|
|
19
|
+
return `house-kit-update-${callId}`;
|
|
20
|
+
}
|
|
21
|
+
function manager() {
|
|
22
|
+
return service() === 'user' ? ['--user'] : [];
|
|
23
|
+
}
|
|
24
|
+
function elevated() {
|
|
25
|
+
return throughSudo() ? ['sudo', '-n'] : [];
|
|
26
|
+
}
|
|
27
|
+
function account() {
|
|
28
|
+
return throughSudo() ? [`--uid=${process.getuid()}`, `--gid=${process.getgid()}`] : [];
|
|
29
|
+
}
|
|
30
|
+
function placement() {
|
|
31
|
+
return service() === 'user' ? ['--workspace', workspaceRoot()] : ['--linux'];
|
|
32
|
+
}
|
|
33
|
+
function record() {
|
|
34
|
+
return `outcome=$1; shift; bash "$0" "$@"; printf %s "$?" > "$outcome"; ${[...elevated(), 'systemctl', ...manager(), 'start', 'house-kit.service'].join(' ')}`;
|
|
23
35
|
}
|
|
24
|
-
async function
|
|
36
|
+
async function pendingCall() {
|
|
25
37
|
try {
|
|
26
38
|
return JSON.parse(await readFile(pending(), 'utf8')).input_id;
|
|
27
39
|
}
|
|
@@ -35,83 +47,92 @@ async function recorded() {
|
|
|
35
47
|
return null;
|
|
36
48
|
return status.trim() === '0' ? {} : { refused: `the Kit bootstrap exited with ${status.trim()}` };
|
|
37
49
|
}
|
|
38
|
-
async function
|
|
50
|
+
async function forget(callId) {
|
|
51
|
+
if ((await pendingCall()) !== callId)
|
|
52
|
+
return;
|
|
53
|
+
await rm(pending(), { force: true });
|
|
54
|
+
await rm(outcome(), { force: true });
|
|
55
|
+
}
|
|
56
|
+
async function finished(callId) {
|
|
39
57
|
for (;;) {
|
|
40
|
-
const
|
|
41
|
-
if (
|
|
42
|
-
return
|
|
43
|
-
|
|
58
|
+
const result = await recorded();
|
|
59
|
+
if (result !== null)
|
|
60
|
+
return result;
|
|
61
|
+
// systemctl answers at once, so ten seconds only bounds a stuck service manager.
|
|
62
|
+
if ((await run('systemctl', [...manager(), 'is-active', '--quiet', unit(callId)], 10_000)).status !== 0) {
|
|
44
63
|
return (await recorded()) ?? { refused: 'the Kit bootstrap did not finish' };
|
|
45
64
|
}
|
|
65
|
+
// The bootstrap runs for minutes, so checking each second sees its outcome within a second at little cost.
|
|
46
66
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
47
67
|
}
|
|
48
68
|
}
|
|
49
|
-
function rerun(script,
|
|
69
|
+
function rerun(script, callId, flags) {
|
|
50
70
|
return new Promise((resolve) => {
|
|
51
|
-
const
|
|
71
|
+
const [command, ...args] = [
|
|
72
|
+
...elevated(),
|
|
73
|
+
'systemd-run',
|
|
74
|
+
...manager(),
|
|
75
|
+
...account(),
|
|
52
76
|
'--wait',
|
|
53
77
|
'--collect',
|
|
54
78
|
'--quiet',
|
|
55
|
-
`--unit=${unit(
|
|
79
|
+
`--unit=${unit(callId)}`,
|
|
56
80
|
`--setenv=HOME=${homedir()}`,
|
|
81
|
+
`--setenv=HOUSE_KIT_HOME=${kitHome()}`,
|
|
57
82
|
'/bin/sh',
|
|
58
83
|
'-c',
|
|
59
|
-
|
|
84
|
+
record(),
|
|
60
85
|
script,
|
|
61
86
|
outcome(),
|
|
87
|
+
...placement(),
|
|
62
88
|
...flags,
|
|
63
|
-
]
|
|
64
|
-
child
|
|
89
|
+
];
|
|
90
|
+
const child = spawn(command, args, { stdio: ['ignore', 'ignore', 'inherit'] });
|
|
91
|
+
child.on('error', () => resolve({ refused: 'no service manager runs this Kit process' }));
|
|
65
92
|
child.on('close', () => resolve(null));
|
|
66
93
|
});
|
|
67
94
|
}
|
|
68
|
-
export class
|
|
69
|
-
|
|
70
|
-
held = new Set();
|
|
95
|
+
export class KitUpdate {
|
|
96
|
+
calls;
|
|
71
97
|
queue = Promise.resolve();
|
|
72
|
-
constructor(
|
|
73
|
-
this.
|
|
98
|
+
constructor(calls) {
|
|
99
|
+
this.calls = calls;
|
|
74
100
|
}
|
|
75
101
|
async resumed() {
|
|
76
|
-
const
|
|
77
|
-
if (
|
|
102
|
+
const callId = await pendingCall();
|
|
103
|
+
if (callId === null)
|
|
78
104
|
return;
|
|
79
|
-
await this.
|
|
105
|
+
await this.enqueue(callId, () => finished(callId));
|
|
80
106
|
}
|
|
81
|
-
start(
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
107
|
+
start(call) {
|
|
108
|
+
void this.enqueue(call.input_id, () => this.carry(call));
|
|
109
|
+
}
|
|
110
|
+
enqueue(callId, work) {
|
|
111
|
+
const before = this.queue;
|
|
112
|
+
const carried = this.calls.carry(callId, async () => {
|
|
113
|
+
await before;
|
|
114
|
+
return { result: await work(), returned: () => forget(callId) };
|
|
115
|
+
});
|
|
116
|
+
this.queue = before.then(() => carried);
|
|
117
|
+
return carried;
|
|
90
118
|
}
|
|
91
|
-
async carry(
|
|
92
|
-
if ((await
|
|
93
|
-
return finished(
|
|
94
|
-
const answer = await fetch(
|
|
119
|
+
async carry(call) {
|
|
120
|
+
if ((await pendingCall()) === call.input_id)
|
|
121
|
+
return finished(call.input_id);
|
|
122
|
+
const answer = await fetch(call.bootstrap);
|
|
95
123
|
if (!answer.ok)
|
|
96
124
|
return { refused: `the Kit bootstrap could not be downloaded: ${answer.status}` };
|
|
97
125
|
const script = Buffer.from(await answer.arrayBuffer());
|
|
98
|
-
if (createHash('sha256').update(script).digest('hex') !==
|
|
126
|
+
if (createHash('sha256').update(script).digest('hex') !== call.sha256) {
|
|
99
127
|
return { refused: 'the Kit bootstrap does not match its sha256' };
|
|
100
128
|
}
|
|
101
129
|
await mkdir(directory(), { recursive: true, mode: 0o700 });
|
|
102
130
|
const path = join(directory(), 'connect-linux.sh');
|
|
103
131
|
await writeFile(path, script, { mode: 0o700 });
|
|
104
132
|
await rm(outcome(), { force: true });
|
|
105
|
-
await writeFile(pending(), `${JSON.stringify({ input_id:
|
|
106
|
-
return (await rerun(path,
|
|
133
|
+
await writeFile(pending(), `${JSON.stringify({ input_id: call.input_id })}\n`, { mode: 0o600 });
|
|
134
|
+
return (await rerun(path, call.input_id, call.update_clis ? ['--update-clis'] : [])) ?? (await recorded()) ?? {
|
|
107
135
|
refused: 'the Kit bootstrap did not finish',
|
|
108
136
|
};
|
|
109
137
|
}
|
|
110
|
-
async acknowledge(inputId, ack) {
|
|
111
|
-
await this.house.deliver(`/kit/inputs/${inputId}/ack`, ack);
|
|
112
|
-
if ((await pendingInput()) !== inputId)
|
|
113
|
-
return;
|
|
114
|
-
await rm(pending(), { force: true });
|
|
115
|
-
await rm(outcome(), { force: true });
|
|
116
|
-
}
|
|
117
138
|
}
|
package/dist/wire.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { newerThanHouse, updateRequired } from './end.js';
|
|
2
|
+
import { machine } from './placement.js';
|
|
3
|
+
import { refusalOf } from './refusals.js';
|
|
4
|
+
export const KIT_WIRE = 3;
|
|
5
|
+
export const KIT_WIRE_HEADER = 'x-house-kit-wire';
|
|
6
|
+
function newer(text) {
|
|
7
|
+
let body;
|
|
8
|
+
try {
|
|
9
|
+
body = JSON.parse(text);
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
return body?.error?.code === 'kit_newer_than_house' ? body.error : null;
|
|
15
|
+
}
|
|
16
|
+
export function endUnserved(text) {
|
|
17
|
+
if (refusalOf(text)?.code === 'kit_update_required')
|
|
18
|
+
updateRequired();
|
|
19
|
+
const refused = newer(text);
|
|
20
|
+
if (refused !== null)
|
|
21
|
+
newerThanHouse(refused.release, refused.commands[machine()]);
|
|
22
|
+
}
|