@agentshouse/kit 0.2.1-c3fc787e93f0e → 0.2.1-c44c14117631a
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 +30 -29
- package/dist/acp.js +38 -17
- package/dist/agents.js +87 -19
- package/dist/api.js +5 -5
- package/dist/app-git.js +10 -26
- package/dist/authority-main.js +2 -2
- package/dist/bridge.js +4 -7
- package/dist/building.js +46 -0
- package/dist/calls.js +63 -0
- package/dist/chatgpt.js +7 -1
- package/dist/clis-main.js +2 -2
- package/dist/clis.js +49 -16
- package/dist/connection.js +126 -0
- package/dist/conversations.js +404 -154
- package/dist/copies.js +77 -50
- package/dist/end.js +9 -4
- package/dist/events.js +6 -2
- package/dist/files.js +139 -37
- package/dist/git.js +5 -6
- package/dist/home.js +31 -13
- package/dist/house-cli.js +299 -0
- package/dist/house-main.js +7 -262
- package/dist/instructions.js +6 -10
- package/dist/kit-cli.js +68 -0
- package/dist/kit-main.js +8 -67
- package/dist/login.js +34 -11
- package/dist/logout.js +0 -2
- package/dist/mcp.js +4 -2
- package/dist/placement.js +9 -18
- package/dist/relay.js +21 -0
- package/dist/resident.js +88 -37
- package/dist/scope.js +3 -0
- package/dist/service.js +23 -1
- package/dist/sign-in.js +22 -39
- package/dist/skills.js +12 -34
- package/dist/transcription.js +85 -45
- package/dist/translate.js +2 -8
- package/dist/update.js +71 -48
- package/dist/web-wizard.js +101 -0
- package/dist/wire.js +19 -3
- package/dist/work.js +3 -5
- package/package.json +20 -20
- package/dist/bootstrap.json +0 -24
- package/dist/stream.js +0 -77
- package/how-we-work.md +0 -23
- package/skills/ask-matt/LICENSE +0 -21
- package/skills/ask-matt/PHASE-BOUNDARIES.md +0 -55
- package/skills/ask-matt/SKILL.md +0 -91
- package/skills/ask-matt/agents/openai.yaml +0 -4
- package/skills/code-review/LICENSE +0 -21
- package/skills/code-review/SKILL.md +0 -89
- package/skills/code-review/agents/openai.yaml +0 -3
- package/skills/codebase-design/DEEPENING.md +0 -37
- package/skills/codebase-design/DESIGN-IT-TWICE.md +0 -44
- package/skills/codebase-design/LICENSE +0 -21
- package/skills/codebase-design/SKILL.md +0 -116
- package/skills/codebase-design/agents/openai.yaml +0 -3
- package/skills/diagnosing-bugs/LICENSE +0 -21
- package/skills/diagnosing-bugs/SKILL.md +0 -140
- package/skills/diagnosing-bugs/agents/openai.yaml +0 -3
- package/skills/diagnosing-bugs/scripts/hitl-loop.template.sh +0 -44
- package/skills/domain-modeling/ADR-FORMAT.md +0 -47
- package/skills/domain-modeling/CONTEXT-FORMAT.md +0 -60
- package/skills/domain-modeling/LICENSE +0 -21
- package/skills/domain-modeling/SKILL.md +0 -76
- package/skills/domain-modeling/agents/openai.yaml +0 -3
- package/skills/grill-me/LICENSE +0 -21
- package/skills/grill-me/SKILL.md +0 -8
- package/skills/grill-me/agents/openai.yaml +0 -4
- package/skills/grill-with-docs/LICENSE +0 -21
- package/skills/grill-with-docs/SKILL.md +0 -8
- package/skills/grill-with-docs/agents/openai.yaml +0 -4
- package/skills/grilling/LICENSE +0 -21
- package/skills/grilling/SKILL.md +0 -30
- package/skills/grilling/agents/openai.yaml +0 -3
- package/skills/handoff/LICENSE +0 -21
- package/skills/handoff/SKILL.md +0 -17
- package/skills/handoff/agents/openai.yaml +0 -4
- package/skills/implement/LICENSE +0 -21
- package/skills/implement/SKILL.md +0 -16
- package/skills/implement/agents/openai.yaml +0 -4
- package/skills/improve-codebase-architecture/HTML-REPORT.md +0 -123
- package/skills/improve-codebase-architecture/LICENSE +0 -21
- package/skills/improve-codebase-architecture/SKILL.md +0 -72
- package/skills/improve-codebase-architecture/agents/openai.yaml +0 -4
- package/skills/prototype/LICENSE +0 -21
- package/skills/prototype/LOGIC.md +0 -67
- package/skills/prototype/SKILL.md +0 -28
- package/skills/prototype/UI.md +0 -112
- package/skills/prototype/agents/openai.yaml +0 -3
- package/skills/research/LICENSE +0 -21
- package/skills/research/SKILL.md +0 -14
- package/skills/research/agents/openai.yaml +0 -3
- package/skills/resolving-merge-conflicts/LICENSE +0 -21
- package/skills/resolving-merge-conflicts/SKILL.md +0 -16
- package/skills/resolving-merge-conflicts/agents/openai.yaml +0 -3
- package/skills/tdd/LICENSE +0 -21
- package/skills/tdd/SKILL.md +0 -40
- package/skills/tdd/agents/openai.yaml +0 -3
- package/skills/tdd/mocking.md +0 -59
- package/skills/tdd/tests.md +0 -77
- package/skills/teach/GLOSSARY-FORMAT.md +0 -35
- package/skills/teach/LEARNING-RECORD-FORMAT.md +0 -46
- package/skills/teach/LICENSE +0 -21
- package/skills/teach/MISSION-FORMAT.md +0 -31
- package/skills/teach/RESOURCES-FORMAT.md +0 -32
- package/skills/teach/SKILL.md +0 -141
- package/skills/teach/agents/openai.yaml +0 -4
- package/skills/to-questionnaire/LICENSE +0 -21
- package/skills/to-questionnaire/SKILL.md +0 -55
- package/skills/to-questionnaire/agents/openai.yaml +0 -4
- package/skills/to-spec/LICENSE +0 -21
- package/skills/to-spec/SKILL.md +0 -76
- package/skills/to-spec/agents/openai.yaml +0 -4
- package/skills/to-tickets/LICENSE +0 -21
- package/skills/to-tickets/SKILL.md +0 -106
- package/skills/to-tickets/agents/openai.yaml +0 -4
- package/skills/wait-what/LICENSE +0 -21
- package/skills/wait-what/SKILL.md +0 -8
- package/skills/wait-what/agents/openai.yaml +0 -4
- package/skills/wayfinder/LICENSE +0 -21
- package/skills/wayfinder/SKILL.md +0 -129
- package/skills/wayfinder/agents/openai.yaml +0 -4
- package/skills/writing-for-agents/LICENSE +0 -21
- package/skills/writing-for-agents/SKILL-MECHANICS.md +0 -22
- package/skills/writing-for-agents/SKILL.md +0 -83
- package/skills/writing-for-agents/agents/openai.yaml +0 -3
package/dist/sign-in.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
2
|
import { createInterface } from 'node:readline';
|
|
3
|
-
import { CLIS
|
|
3
|
+
import { CLIS } from './clis.js';
|
|
4
|
+
import { childEnvironment } from './relay.js';
|
|
4
5
|
import { killTree } from './scope.js';
|
|
5
6
|
import { holdSecretInput } from './secret-input.js';
|
|
6
7
|
const ESCAPE = /\u001b\[[\d;]*m/g;
|
|
@@ -9,72 +10,54 @@ const CODE = /^[A-Z0-9]+-[A-Z0-9]+$/;
|
|
|
9
10
|
function causeOf(error) {
|
|
10
11
|
return error instanceof Error ? error.message : String(error);
|
|
11
12
|
}
|
|
12
|
-
function logged(error) {
|
|
13
|
-
process.stderr.write(`kit: ${causeOf(error)}\n`);
|
|
14
|
-
}
|
|
15
13
|
function endOf(signal) {
|
|
16
14
|
return new Promise((resolve) => signal.addEventListener('abort', () => resolve(true), { once: true }));
|
|
17
15
|
}
|
|
18
16
|
export class SignIns {
|
|
19
17
|
house;
|
|
20
18
|
agents;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
constructor(house, agents, changed) {
|
|
19
|
+
calls;
|
|
20
|
+
constructor(house, agents, calls) {
|
|
24
21
|
this.house = house;
|
|
25
22
|
this.agents = agents;
|
|
26
|
-
this.
|
|
27
|
-
}
|
|
28
|
-
idle() {
|
|
29
|
-
return this.running.size === 0;
|
|
23
|
+
this.calls = calls;
|
|
30
24
|
}
|
|
31
|
-
start(
|
|
32
|
-
|
|
33
|
-
return;
|
|
34
|
-
this.running.add(input.input_id);
|
|
35
|
-
this.changed();
|
|
36
|
-
this.signIn(input)
|
|
37
|
-
.catch(logged)
|
|
38
|
-
.finally(() => {
|
|
39
|
-
this.running.delete(input.input_id);
|
|
40
|
-
this.changed();
|
|
41
|
-
});
|
|
25
|
+
start(call) {
|
|
26
|
+
void this.calls.carry(call.input_id, () => this.signIn(call));
|
|
42
27
|
}
|
|
43
|
-
async signIn(
|
|
28
|
+
async signIn(call) {
|
|
44
29
|
const ending = new AbortController();
|
|
45
30
|
// 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(),
|
|
47
|
-
const ended = await Promise.race([this.signedIn(
|
|
31
|
+
const timer = setTimeout(() => ending.abort(), call.ends_in * 1000);
|
|
32
|
+
const ended = await Promise.race([this.signedIn(call, ending.signal), endOf(ending.signal)]);
|
|
48
33
|
clearTimeout(timer);
|
|
49
34
|
if (ended)
|
|
50
|
-
process.stderr.write(`kit: the ${
|
|
51
|
-
|
|
52
|
-
if (!ended)
|
|
53
|
-
await this.agents.reread(input.cli);
|
|
35
|
+
process.stderr.write(`kit: the ${call.cli} sign-in reached the end House set for it\n`);
|
|
36
|
+
return ended ? { result: {} } : { result: {}, returned: () => this.agents.reread(call.cli) };
|
|
54
37
|
}
|
|
55
|
-
async signedIn(
|
|
56
|
-
await this.login(
|
|
38
|
+
async signedIn(call, signal) {
|
|
39
|
+
await this.login(call, signal);
|
|
57
40
|
if (!signal.aborted)
|
|
58
|
-
await this.agents.recheck(
|
|
41
|
+
await this.agents.recheck(call.cli, signal);
|
|
59
42
|
return false;
|
|
60
43
|
}
|
|
61
|
-
async login(
|
|
44
|
+
async login(call, signal) {
|
|
62
45
|
let cli;
|
|
63
46
|
try {
|
|
64
|
-
cli = await this.agents.located(
|
|
47
|
+
cli = await this.agents.located(call.cli, signal);
|
|
65
48
|
}
|
|
66
49
|
catch (error) {
|
|
67
50
|
if (!signal.aborted)
|
|
68
|
-
process.stderr.write(`kit: the ${
|
|
51
|
+
process.stderr.write(`kit: the ${call.cli} sign-in failed: ${causeOf(error)}\n`);
|
|
69
52
|
return;
|
|
70
53
|
}
|
|
71
54
|
if (signal.aborted)
|
|
72
55
|
return;
|
|
73
|
-
const login = CLIS[
|
|
56
|
+
const login = CLIS[call.cli].login;
|
|
74
57
|
const child = spawn(cli, login.args, {
|
|
75
58
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
76
59
|
detached: true,
|
|
77
|
-
env:
|
|
60
|
+
env: childEnvironment(),
|
|
78
61
|
});
|
|
79
62
|
const running = () => child.exitCode === null && child.signalCode === null;
|
|
80
63
|
const stop = () => killTree(child);
|
|
@@ -102,7 +85,7 @@ export class SignIns {
|
|
|
102
85
|
return;
|
|
103
86
|
held = true;
|
|
104
87
|
const steps = [{ kind: 'visit', label: 'Open this link and sign in', url: link }, step];
|
|
105
|
-
void holdSecretInput(this.house,
|
|
88
|
+
void holdSecretInput(this.house, call.input_id, steps, running).then((content) => {
|
|
106
89
|
if (!running())
|
|
107
90
|
return;
|
|
108
91
|
if (content === null)
|
|
@@ -119,6 +102,6 @@ export class SignIns {
|
|
|
119
102
|
});
|
|
120
103
|
signal.removeEventListener('abort', stop);
|
|
121
104
|
if (failed !== null && !signal.aborted)
|
|
122
|
-
process.stderr.write(`kit: the ${
|
|
105
|
+
process.stderr.write(`kit: the ${call.cli} sign-in failed: ${failed}\n`);
|
|
123
106
|
}
|
|
124
107
|
}
|
package/dist/skills.js
CHANGED
|
@@ -1,17 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { cp, lstat, mkdir, readdir, realpath, rm, symlink, writeFile } from 'node:fs/promises';
|
|
1
|
+
import { cp, lstat, mkdir, realpath, rm, symlink } from 'node:fs/promises';
|
|
3
2
|
import { homedir } from 'node:os';
|
|
4
3
|
import { join, relative } from 'node:path';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
4
|
+
import { listSkills } from '@agentshouse/skills';
|
|
5
|
+
import { KIT_RELEASE } from './clis.js';
|
|
7
6
|
import { kitHome, readConfiguration, readHome, writeHome } from './home.js';
|
|
8
|
-
import { refusalOf } from './refusals.js';
|
|
9
|
-
export const HOW_WE_WORK = '/rooms/private/how-we-work.md';
|
|
10
|
-
const SKILL_SET = fileURLToPath(new URL('../skills/', import.meta.url));
|
|
11
|
-
const HOW_WE_WORK_TEXT = readFileSync(new URL('../how-we-work.md', import.meta.url), 'utf8');
|
|
12
7
|
const RECORD = 'skill-set.json';
|
|
13
|
-
const CREATED = 'how-we-work-created';
|
|
14
|
-
const UNWRITABLE = new Set(['room_not_found', 'operation_denied']);
|
|
15
8
|
function skillsDirectory() {
|
|
16
9
|
return join(homedir(), '.agents', 'skills');
|
|
17
10
|
}
|
|
@@ -30,23 +23,24 @@ async function present(path) {
|
|
|
30
23
|
}
|
|
31
24
|
}
|
|
32
25
|
async function install() {
|
|
33
|
-
const
|
|
34
|
-
for (const
|
|
35
|
-
if (!(await present(join(skillsDirectory(), name))) && !(await present(join(claudeDirectory(), name)))) {
|
|
36
|
-
|
|
26
|
+
const placed = [];
|
|
27
|
+
for (const skill of listSkills()) {
|
|
28
|
+
if (!(await present(join(skillsDirectory(), skill.name))) && !(await present(join(claudeDirectory(), skill.name)))) {
|
|
29
|
+
placed.push(skill);
|
|
37
30
|
}
|
|
38
31
|
}
|
|
32
|
+
const names = placed.map((skill) => skill.name);
|
|
39
33
|
await writeHome(RECORD, { names });
|
|
40
34
|
await mkdir(skillsDirectory(), { recursive: true });
|
|
41
35
|
await mkdir(claudeDirectory(), { recursive: true });
|
|
42
36
|
const skills = await realpath(skillsDirectory());
|
|
43
37
|
const claude = await realpath(claudeDirectory());
|
|
44
|
-
for (const name of
|
|
45
|
-
await cp(
|
|
38
|
+
for (const { name, directory } of placed) {
|
|
39
|
+
await cp(directory, join(skillsDirectory(), name), { recursive: true });
|
|
46
40
|
if (claude !== skills)
|
|
47
41
|
await symlink(relative(claude, join(skills, name)), join(claudeDirectory(), name));
|
|
48
42
|
}
|
|
49
|
-
await writeHome(RECORD, { version:
|
|
43
|
+
await writeHome(RECORD, { version: KIT_RELEASE, names });
|
|
50
44
|
}
|
|
51
45
|
export async function placeSkillSet() {
|
|
52
46
|
try {
|
|
@@ -59,7 +53,7 @@ export async function placeSkillSet() {
|
|
|
59
53
|
async function replaceSkillSet() {
|
|
60
54
|
const accepted = (await readConfiguration()).skills;
|
|
61
55
|
const installed = await readHome(RECORD);
|
|
62
|
-
if (accepted && installed?.version ===
|
|
56
|
+
if (accepted && installed?.version === KIT_RELEASE)
|
|
63
57
|
return;
|
|
64
58
|
for (const name of installed?.names ?? []) {
|
|
65
59
|
await rm(join(claudeDirectory(), name), { recursive: true, force: true });
|
|
@@ -70,19 +64,3 @@ async function replaceSkillSet() {
|
|
|
70
64
|
else
|
|
71
65
|
await rm(join(kitHome(), RECORD), { force: true });
|
|
72
66
|
}
|
|
73
|
-
export async function createHowWeWork(bridge) {
|
|
74
|
-
if (!(await readConfiguration()).skills || (await readHome(RECORD))?.version === undefined)
|
|
75
|
-
return;
|
|
76
|
-
if (await present(join(kitHome(), CREATED)))
|
|
77
|
-
return;
|
|
78
|
-
const created = await bridge.tool('edit', { changes: [{ op: 'create', path: HOW_WE_WORK, content: HOW_WE_WORK_TEXT }] });
|
|
79
|
-
if (created.isError === true) {
|
|
80
|
-
const text = created.content.map((content) => content.text).join('\n');
|
|
81
|
-
const refusal = refusalOf(text);
|
|
82
|
-
if (UNWRITABLE.has(refusal?.code ?? ''))
|
|
83
|
-
return;
|
|
84
|
-
if (refusal?.code !== 'edit_conflict' || !refusal.conflicts.includes('path_exists'))
|
|
85
|
-
throw new Error(text);
|
|
86
|
-
}
|
|
87
|
-
await writeFile(join(kitHome(), CREATED), '');
|
|
88
|
-
}
|
package/dist/transcription.js
CHANGED
|
@@ -1,33 +1,39 @@
|
|
|
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 { pipeline } from 'node:stream/promises';
|
|
7
4
|
import { unlessAborted } from './abort.js';
|
|
5
|
+
import { downloadServed } from './building.js';
|
|
8
6
|
import { failureOf, run } from './clis.js';
|
|
7
|
+
import { downloaded, fetched } from './files.js';
|
|
9
8
|
import { kitHome } from './home.js';
|
|
10
9
|
const RELEASE = 'https://github.com/agentshouse/kit/releases/download/engine-2';
|
|
11
10
|
export const MODEL = {
|
|
12
|
-
|
|
11
|
+
name: 'ggml-parakeet-tdt-0.6b-v3-q4_k.bin',
|
|
12
|
+
from: 'https://huggingface.co/ggml-org/parakeet-GGUF/resolve/35156454d1a39de06863303dd209fd2bed6ee079/ggml-parakeet-tdt-0.6b-v3-q4_k.bin',
|
|
13
13
|
sha256: '8b205b8b39c6535e153de6fb11c51db46125d45c4f16ba496fe41a0fe71b885e',
|
|
14
|
+
bytes: 415_611_879,
|
|
14
15
|
executable: false,
|
|
15
16
|
};
|
|
16
17
|
export const ENGINES = {
|
|
17
18
|
'linux-x64': {
|
|
18
|
-
decoder: {
|
|
19
|
-
engine: {
|
|
19
|
+
decoder: { name: 'ffmpeg-linux-x86_64', from: `${RELEASE}/ffmpeg-linux-x86_64`, sha256: '1f8235d206428305afb89c6e8ab99d100425a0ba61e22bb4c7aff017db8c8de5', bytes: 5_175_832, executable: true },
|
|
20
|
+
engine: { name: 'parakeet-cli-linux-x86_64', from: `${RELEASE}/parakeet-cli-linux-x86_64`, sha256: 'bb2585695992fe1927a33960002cdf51b8a90a96ad65593c3d0a9f1fbc0865c2', bytes: 3_801_616, executable: true },
|
|
20
21
|
},
|
|
21
22
|
'linux-arm64': {
|
|
22
|
-
decoder: {
|
|
23
|
-
engine: {
|
|
23
|
+
decoder: { name: 'ffmpeg-linux-aarch64', from: `${RELEASE}/ffmpeg-linux-aarch64`, sha256: 'a7e08a0fae0179d1078312f6bb13d2a9aa4d4c71a1d82a022953f25dee452f5e', bytes: 4_590_208, executable: true },
|
|
24
|
+
engine: { name: 'parakeet-cli-linux-aarch64', from: `${RELEASE}/parakeet-cli-linux-aarch64`, sha256: 'cbc0bedc8daae97f1ef9dcee4200c06226218e300e0fd62ead1306d22742b7ed', bytes: 3_477_624, executable: true },
|
|
24
25
|
},
|
|
25
26
|
'darwin-arm64': {
|
|
26
|
-
decoder: {
|
|
27
|
-
engine: {
|
|
27
|
+
decoder: { name: 'ffmpeg-darwin-arm64', from: `${RELEASE}/ffmpeg-darwin-arm64`, sha256: '7abe154aaed3d6b49f5167ca7221bb66bed51388925d99a7e4261a41fe52fba6', bytes: 3_696_768, executable: true },
|
|
28
|
+
engine: { name: 'parakeet-cli-darwin-arm64', from: `${RELEASE}/parakeet-cli-darwin-arm64`, sha256: '9a2aafc0922ad7c0b6db6eff1641e96572ba32ac40bf995a1df242ed2febf297', bytes: 1_939_728, executable: true },
|
|
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();
|
|
32
38
|
let holding = Promise.resolve();
|
|
33
39
|
let setting = null;
|
|
@@ -40,7 +46,7 @@ function installed(artifact) {
|
|
|
40
46
|
return join(directory(), artifact.sha256);
|
|
41
47
|
}
|
|
42
48
|
async function executed(command, args, signal) {
|
|
43
|
-
// A
|
|
49
|
+
// 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
50
|
const ran = await run(command, args, 0, false, signal);
|
|
45
51
|
if (ran.status !== 0)
|
|
46
52
|
throw new Error(failureOf(ran, basename(command)));
|
|
@@ -49,22 +55,50 @@ async function executed(command, args, signal) {
|
|
|
49
55
|
function present(path) {
|
|
50
56
|
return stat(path).then(() => true, () => false);
|
|
51
57
|
}
|
|
52
|
-
async function
|
|
58
|
+
async function threads() {
|
|
53
59
|
const [quota, period] = (await readFile('/sys/fs/cgroup/cpu.max', 'utf8').catch(() => 'max')).split(' ');
|
|
54
60
|
const allowed = quota === 'max' ? Infinity : Math.ceil(Number(quota) / Number(period));
|
|
55
|
-
return Math.min(availableParallelism(), allowed);
|
|
56
|
-
}
|
|
57
|
-
async function sha256(path) {
|
|
58
|
-
const hash = createHash('sha256');
|
|
59
|
-
await pipeline(createReadStream(path), hash);
|
|
60
|
-
return hash.digest('hex');
|
|
61
|
+
return Math.max(1, Math.floor(Math.min(availableParallelism(), allowed) / 2));
|
|
61
62
|
}
|
|
62
63
|
function causeOf(error) {
|
|
63
64
|
return error instanceof Error ? error.message : String(error);
|
|
64
65
|
}
|
|
66
|
+
async function failing(reason, work) {
|
|
67
|
+
try {
|
|
68
|
+
return await work;
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
throw new Error(reason, { cause: error });
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function ready() {
|
|
75
|
+
if (setting !== true)
|
|
76
|
+
throw new Error(OFF);
|
|
77
|
+
if (!readiness.installed)
|
|
78
|
+
throw new Error(NOT_INSTALLED);
|
|
79
|
+
}
|
|
65
80
|
function pinnedHere() {
|
|
66
81
|
return ENGINES[`${process.platform}-${process.arch}`];
|
|
67
82
|
}
|
|
83
|
+
const DOWNLOADS = 3;
|
|
84
|
+
async function downloadedAgain(artifact, signal) {
|
|
85
|
+
// An artifact arrives at a hundred kilobytes a second or its download ends, so a stalled Building cannot hold the install open.
|
|
86
|
+
const deadlineMs = Math.ceil(artifact.bytes / 100);
|
|
87
|
+
const deadline = AbortSignal.timeout(deadlineMs);
|
|
88
|
+
for (let attempt = 1;; attempt++) {
|
|
89
|
+
try {
|
|
90
|
+
return await downloadServed(artifact.name, artifact.sha256, `${installed(artifact)}.part`, AbortSignal.any([signal, deadline]), artifact.bytes);
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
if (signal.aborted)
|
|
94
|
+
throw error;
|
|
95
|
+
if (deadline.aborted)
|
|
96
|
+
throw new Error(`${artifact.name} did not arrive within ${Math.ceil(deadlineMs / 1000)} seconds`);
|
|
97
|
+
if (attempt === DOWNLOADS)
|
|
98
|
+
throw error;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
68
102
|
async function install(artifacts, signal) {
|
|
69
103
|
await mkdir(directory(), { recursive: true });
|
|
70
104
|
const pinned = new Set(artifacts.map((artifact) => artifact.sha256));
|
|
@@ -77,13 +111,8 @@ async function install(artifacts, signal) {
|
|
|
77
111
|
if (!(await present(installed(artifact))))
|
|
78
112
|
missing.push(artifact);
|
|
79
113
|
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
|
-
}
|
|
114
|
+
for (const artifact of missing)
|
|
115
|
+
await downloadedAgain(artifact, signal);
|
|
87
116
|
for (const artifact of missing) {
|
|
88
117
|
if (artifact.executable)
|
|
89
118
|
await chmod(`${installed(artifact)}.part`, 0o755);
|
|
@@ -133,27 +162,23 @@ export function holdTranscription(transcribe) {
|
|
|
133
162
|
export function transcriptionReport() {
|
|
134
163
|
return readiness;
|
|
135
164
|
}
|
|
136
|
-
async function transcribed(
|
|
165
|
+
async function transcribed(audio, parts, signal) {
|
|
137
166
|
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
|
-
}
|
|
167
|
+
await mkdir(parts);
|
|
168
|
+
await failing(UNDECODABLE, executed(installed(pinned.decoder), ['-nostdin', '-hide_banner', '-loglevel', 'error', '-i', audio, '-ar', '16000', '-ac', '1', '-c:a', 'pcm_s16le',
|
|
169
|
+
'-f', 'segment', '-segment_time', String(CHUNK_SECONDS), join(parts, '%05d.wav')], signal));
|
|
170
|
+
const segments = (await readdir(parts)).sort().flatMap((part) => ['-f', join(parts, part)]);
|
|
171
|
+
const said = await failing(UNTRANSCRIBED, executed(installed(pinned.engine), ['-t', String(await threads()), '-np', '-m', installed(MODEL), ...segments], signal));
|
|
172
|
+
const text = said
|
|
173
|
+
.split('\n')
|
|
174
|
+
.map((line) => line.trim())
|
|
175
|
+
.filter((line) => line !== '')
|
|
176
|
+
.join(' ');
|
|
177
|
+
if (text === '')
|
|
178
|
+
throw new Error(UNTRANSCRIBED);
|
|
179
|
+
return text;
|
|
153
180
|
}
|
|
154
|
-
|
|
155
|
-
if (!readiness.installed)
|
|
156
|
-
return null;
|
|
181
|
+
async function alone(work, signal) {
|
|
157
182
|
const before = held;
|
|
158
183
|
let release;
|
|
159
184
|
const mine = new Promise((resolve) => {
|
|
@@ -162,9 +187,24 @@ export async function transcribe(path, signal) {
|
|
|
162
187
|
held = Promise.all([before, mine]);
|
|
163
188
|
try {
|
|
164
189
|
await unlessAborted(before, signal);
|
|
165
|
-
return
|
|
190
|
+
return await work();
|
|
166
191
|
}
|
|
167
192
|
finally {
|
|
168
193
|
release();
|
|
169
194
|
}
|
|
170
195
|
}
|
|
196
|
+
export async function transcribe(address, signal) {
|
|
197
|
+
ready();
|
|
198
|
+
const work = await mkdtemp(join(tmpdir(), 'kit-transcription-'));
|
|
199
|
+
try {
|
|
200
|
+
const audio = join(work, 'audio');
|
|
201
|
+
await failing(NOT_DOWNLOADED, downloaded(address, (url) => fetched(url, signal), audio, 'audio'));
|
|
202
|
+
return await alone(() => {
|
|
203
|
+
ready();
|
|
204
|
+
return transcribed(audio, join(work, 'parts'), signal);
|
|
205
|
+
}, signal);
|
|
206
|
+
}
|
|
207
|
+
finally {
|
|
208
|
+
await rm(work, { recursive: true, force: true });
|
|
209
|
+
}
|
|
210
|
+
}
|
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
|
@@ -6,9 +6,10 @@ import { join } from 'node:path';
|
|
|
6
6
|
import { run } from './clis.js';
|
|
7
7
|
import { kitHome, workspaceRoot } from './home.js';
|
|
8
8
|
import { service, throughSudo } from './placement.js';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
import { relayed } from './relay.js';
|
|
10
|
+
const BOOTSTRAP_BYTES = 1_000_000;
|
|
11
|
+
// A bootstrap is at most a million bytes, so two minutes carry it over ten kilobytes a second and no stalled host holds the update queue.
|
|
12
|
+
const BOOTSTRAP_MS = 120_000;
|
|
12
13
|
function directory() {
|
|
13
14
|
return join(kitHome(), 'update');
|
|
14
15
|
}
|
|
@@ -18,8 +19,8 @@ function pending() {
|
|
|
18
19
|
function outcome() {
|
|
19
20
|
return join(directory(), 'outcome');
|
|
20
21
|
}
|
|
21
|
-
function unit(
|
|
22
|
-
return `house-kit-update-${
|
|
22
|
+
function unit(callId) {
|
|
23
|
+
return `house-kit-update-${callId}`;
|
|
23
24
|
}
|
|
24
25
|
function manager() {
|
|
25
26
|
return service() === 'user' ? ['--user'] : [];
|
|
@@ -36,7 +37,7 @@ function placement() {
|
|
|
36
37
|
function record() {
|
|
37
38
|
return `outcome=$1; shift; bash "$0" "$@"; printf %s "$?" > "$outcome"; ${[...elevated(), 'systemctl', ...manager(), 'start', 'house-kit.service'].join(' ')}`;
|
|
38
39
|
}
|
|
39
|
-
async function
|
|
40
|
+
async function pendingCall() {
|
|
40
41
|
try {
|
|
41
42
|
return JSON.parse(await readFile(pending(), 'utf8')).input_id;
|
|
42
43
|
}
|
|
@@ -50,20 +51,37 @@ async function recorded() {
|
|
|
50
51
|
return null;
|
|
51
52
|
return status.trim() === '0' ? {} : { refused: `the Kit bootstrap exited with ${status.trim()}` };
|
|
52
53
|
}
|
|
53
|
-
async function
|
|
54
|
+
async function forget(callId) {
|
|
55
|
+
if ((await pendingCall()) !== callId)
|
|
56
|
+
return;
|
|
57
|
+
await rm(pending(), { force: true });
|
|
58
|
+
await rm(outcome(), { force: true });
|
|
59
|
+
}
|
|
60
|
+
async function finished(callId) {
|
|
54
61
|
for (;;) {
|
|
55
|
-
const
|
|
56
|
-
if (
|
|
57
|
-
return
|
|
62
|
+
const result = await recorded();
|
|
63
|
+
if (result !== null)
|
|
64
|
+
return result;
|
|
58
65
|
// systemctl answers at once, so ten seconds only bounds a stuck service manager.
|
|
59
|
-
if ((await run('systemctl', [...manager(), 'is-active', '--quiet', unit(
|
|
66
|
+
if ((await run('systemctl', [...manager(), 'is-active', '--quiet', unit(callId)], 10_000)).status !== 0) {
|
|
60
67
|
return (await recorded()) ?? { refused: 'the Kit bootstrap did not finish' };
|
|
61
68
|
}
|
|
62
69
|
// The bootstrap runs for minutes, so checking each second sees its outcome within a second at little cost.
|
|
63
70
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
64
71
|
}
|
|
65
72
|
}
|
|
66
|
-
function
|
|
73
|
+
async function bounded(body, most) {
|
|
74
|
+
const chunks = [];
|
|
75
|
+
let bytes = 0;
|
|
76
|
+
for await (const chunk of body ?? []) {
|
|
77
|
+
bytes += chunk.length;
|
|
78
|
+
if (bytes > most)
|
|
79
|
+
return null;
|
|
80
|
+
chunks.push(chunk);
|
|
81
|
+
}
|
|
82
|
+
return Buffer.concat(chunks, bytes);
|
|
83
|
+
}
|
|
84
|
+
function rerun(script, callId, flags) {
|
|
67
85
|
return new Promise((resolve) => {
|
|
68
86
|
const [command, ...args] = [
|
|
69
87
|
...elevated(),
|
|
@@ -73,7 +91,7 @@ function rerun(script, inputId, flags) {
|
|
|
73
91
|
'--wait',
|
|
74
92
|
'--collect',
|
|
75
93
|
'--quiet',
|
|
76
|
-
`--unit=${unit(
|
|
94
|
+
`--unit=${unit(callId)}`,
|
|
77
95
|
`--setenv=HOME=${homedir()}`,
|
|
78
96
|
`--setenv=HOUSE_KIT_HOME=${kitHome()}`,
|
|
79
97
|
'/bin/sh',
|
|
@@ -85,57 +103,62 @@ function rerun(script, inputId, flags) {
|
|
|
85
103
|
...flags,
|
|
86
104
|
];
|
|
87
105
|
const child = spawn(command, args, { stdio: ['ignore', 'ignore', 'inherit'] });
|
|
88
|
-
child.on('error', () => resolve({ refused: 'no service manager runs this Kit' }));
|
|
106
|
+
child.on('error', () => resolve({ refused: 'no service manager runs this Kit process' }));
|
|
89
107
|
child.on('close', () => resolve(null));
|
|
90
108
|
});
|
|
91
109
|
}
|
|
92
|
-
export class
|
|
93
|
-
|
|
94
|
-
held = new Set();
|
|
110
|
+
export class KitUpdate {
|
|
111
|
+
calls;
|
|
95
112
|
queue = Promise.resolve();
|
|
96
|
-
constructor(
|
|
97
|
-
this.
|
|
113
|
+
constructor(calls) {
|
|
114
|
+
this.calls = calls;
|
|
98
115
|
}
|
|
99
116
|
async resumed() {
|
|
100
|
-
const
|
|
101
|
-
if (
|
|
117
|
+
const callId = await pendingCall();
|
|
118
|
+
if (callId === null)
|
|
102
119
|
return;
|
|
103
|
-
await this.
|
|
120
|
+
await this.enqueue(callId, () => finished(callId));
|
|
104
121
|
}
|
|
105
|
-
start(
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
122
|
+
start(call) {
|
|
123
|
+
void this.enqueue(call.input_id, () => this.carry(call));
|
|
124
|
+
}
|
|
125
|
+
enqueue(callId, work) {
|
|
126
|
+
const before = this.queue;
|
|
127
|
+
const carried = this.calls.carry(callId, async () => {
|
|
128
|
+
await before;
|
|
129
|
+
return { result: await work(), returned: () => forget(callId) };
|
|
130
|
+
});
|
|
131
|
+
this.queue = before.then(() => carried);
|
|
132
|
+
return carried;
|
|
114
133
|
}
|
|
115
|
-
async carry(
|
|
116
|
-
if ((await
|
|
117
|
-
return finished(
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
134
|
+
async carry(call) {
|
|
135
|
+
if ((await pendingCall()) === call.input_id)
|
|
136
|
+
return finished(call.input_id);
|
|
137
|
+
const deadline = AbortSignal.timeout(BOOTSTRAP_MS);
|
|
138
|
+
let script;
|
|
139
|
+
try {
|
|
140
|
+
const answer = await fetch(relayed(call.bootstrap), { signal: deadline });
|
|
141
|
+
if (!answer.ok)
|
|
142
|
+
return { refused: `the Kit bootstrap could not be downloaded: ${answer.status}` };
|
|
143
|
+
script = await bounded(answer.body, BOOTSTRAP_BYTES);
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
if (!deadline.aborted)
|
|
147
|
+
throw error;
|
|
148
|
+
return { refused: `the Kit bootstrap did not arrive within ${BOOTSTRAP_MS / 1000} seconds` };
|
|
149
|
+
}
|
|
150
|
+
if (script === null)
|
|
151
|
+
return { refused: `the Kit bootstrap is larger than ${BOOTSTRAP_BYTES} bytes` };
|
|
152
|
+
if (createHash('sha256').update(script).digest('hex') !== call.sha256) {
|
|
123
153
|
return { refused: 'the Kit bootstrap does not match its sha256' };
|
|
124
154
|
}
|
|
125
155
|
await mkdir(directory(), { recursive: true, mode: 0o700 });
|
|
126
156
|
const path = join(directory(), 'connect-linux.sh');
|
|
127
157
|
await writeFile(path, script, { mode: 0o700 });
|
|
128
158
|
await rm(outcome(), { force: true });
|
|
129
|
-
await writeFile(pending(), `${JSON.stringify({ input_id:
|
|
130
|
-
return (await rerun(path,
|
|
159
|
+
await writeFile(pending(), `${JSON.stringify({ input_id: call.input_id })}\n`, { mode: 0o600 });
|
|
160
|
+
return (await rerun(path, call.input_id, call.update_clis ? ['--update-clis'] : [])) ?? (await recorded()) ?? {
|
|
131
161
|
refused: 'the Kit bootstrap did not finish',
|
|
132
162
|
};
|
|
133
163
|
}
|
|
134
|
-
async acknowledge(inputId, ack) {
|
|
135
|
-
await this.house.deliver(`/kit/inputs/${inputId}/ack`, ack);
|
|
136
|
-
if ((await pendingInput()) !== inputId)
|
|
137
|
-
return;
|
|
138
|
-
await rm(pending(), { force: true });
|
|
139
|
-
await rm(outcome(), { force: true });
|
|
140
|
-
}
|
|
141
164
|
}
|