@agentshouse/kit 0.2.1-cfb7b543f2af6 → 0.2.1-cfbadfb5b5e28
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 +33 -34
- package/dist/acp.js +91 -20
- package/dist/afk.js +17 -0
- package/dist/agents.js +91 -44
- package/dist/api.js +5 -5
- package/dist/app-git.js +10 -26
- package/dist/authority-main.js +3 -3
- package/dist/bridge.js +7 -10
- package/dist/building.js +50 -0
- package/dist/calls.js +71 -0
- package/dist/chunks.js +49 -0
- package/dist/clis.js +56 -45
- package/dist/connection.js +120 -0
- package/dist/content.js +63 -0
- package/dist/conversations.js +703 -244
- package/dist/copies.js +344 -171
- package/dist/end.js +15 -4
- package/dist/events.js +746 -210
- package/dist/files.js +139 -37
- package/dist/git.js +49 -16
- package/dist/grok.js +39 -0
- package/dist/home.js +27 -20
- package/dist/house-cli.js +98 -90
- package/dist/house-main.js +3 -3
- package/dist/instructions.js +29 -10
- package/dist/kit-cli.js +5 -8
- package/dist/kit-main.js +3 -3
- package/dist/login.js +20 -11
- package/dist/logout.js +1 -3
- package/dist/mcp.js +6 -2
- package/dist/placement.js +19 -36
- package/dist/relay.js +21 -0
- package/dist/resident.js +118 -52
- package/dist/scope.js +15 -4
- package/dist/scripts.js +255 -0
- package/dist/secret-input.js +1 -1
- package/dist/service.js +23 -1
- package/dist/sign-in.js +22 -39
- package/dist/silence.js +28 -0
- package/dist/skills.js +42 -97
- package/dist/transcription.js +88 -45
- package/dist/translate.js +19 -16
- package/dist/update.js +113 -127
- package/dist/wire.js +37 -3
- package/dist/work.js +12 -7
- package/package.json +22 -21
- package/dist/bootstrap.json +0 -24
- package/dist/chatgpt.js +0 -32
- package/dist/clis-main.js +0 -23
- package/dist/parts.js +0 -82
- package/dist/stream.js +0 -123
- 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/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/silence.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const SYSTEM_CLOCK = {
|
|
2
|
+
later: (delay, callback) => setTimeout(callback, delay),
|
|
3
|
+
clear: (timer) => clearTimeout(timer),
|
|
4
|
+
};
|
|
5
|
+
export class Silence {
|
|
6
|
+
timer = null;
|
|
7
|
+
interval;
|
|
8
|
+
silent;
|
|
9
|
+
clock;
|
|
10
|
+
constructor(interval, silent, clock = SYSTEM_CLOCK) {
|
|
11
|
+
this.interval = interval;
|
|
12
|
+
this.silent = silent;
|
|
13
|
+
this.clock = clock;
|
|
14
|
+
}
|
|
15
|
+
heard() {
|
|
16
|
+
this.stop();
|
|
17
|
+
this.timer = this.clock.later(this.interval, () => {
|
|
18
|
+
this.timer = null;
|
|
19
|
+
this.silent();
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
stop() {
|
|
23
|
+
if (this.timer === null)
|
|
24
|
+
return;
|
|
25
|
+
this.clock.clear(this.timer);
|
|
26
|
+
this.timer = null;
|
|
27
|
+
}
|
|
28
|
+
}
|
package/dist/skills.js
CHANGED
|
@@ -1,31 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { readFileSync } from 'node:fs';
|
|
3
|
-
import { cp, lstat, mkdir, readdir, realpath, rm, symlink } from 'node:fs/promises';
|
|
1
|
+
import { cp, lstat, mkdir, realpath, rm, symlink, writeFile } from 'node:fs/promises';
|
|
4
2
|
import { homedir } from 'node:os';
|
|
5
3
|
import { join, relative } from 'node:path';
|
|
6
|
-
import {
|
|
4
|
+
import { GUIDE, listSkills } from '@agentshouse/skills';
|
|
7
5
|
import { parse } from 'yaml';
|
|
8
|
-
import {
|
|
6
|
+
import { KIT_RELEASE } from './clis.js';
|
|
9
7
|
import { kitHome, readConfiguration, readHome, writeHome } from './home.js';
|
|
10
|
-
import { refusalOf } from './refusals.js';
|
|
11
|
-
const HOW_WE_WORK = '/rooms/private/how-we-work.md';
|
|
12
|
-
const SKILL_SET = fileURLToPath(new URL('../skills/', import.meta.url));
|
|
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
|
-
];
|
|
21
8
|
const RECORD = 'skill-set.json';
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
const
|
|
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: (.+)$/;
|
|
9
|
+
const ENTRY = 'SKILL.md';
|
|
10
|
+
const FRONTMATTER = /^---\n([\s\S]*?)\n---\n/u;
|
|
11
|
+
const ORIGIN = '<origin>';
|
|
29
12
|
function skillsDirectory() {
|
|
30
13
|
return join(homedir(), '.agents', 'skills');
|
|
31
14
|
}
|
|
@@ -43,105 +26,67 @@ async function present(path) {
|
|
|
43
26
|
throw error;
|
|
44
27
|
}
|
|
45
28
|
}
|
|
46
|
-
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
29
|
+
function skillName(text) {
|
|
30
|
+
const front = FRONTMATTER.exec(text);
|
|
31
|
+
const fields = (front === null ? null : parse(front[1]));
|
|
32
|
+
return typeof fields?.name === 'string' && typeof fields.description === 'string' ? fields.name : undefined;
|
|
33
|
+
}
|
|
34
|
+
function skillSet(origin) {
|
|
35
|
+
const upstream = listSkills().map(({ name, directory }) => ({
|
|
36
|
+
name,
|
|
37
|
+
place: (destination) => cp(directory, destination, { recursive: true }),
|
|
38
|
+
}));
|
|
39
|
+
const pages = GUIDE.flatMap(({ text }) => {
|
|
40
|
+
const name = skillName(text);
|
|
41
|
+
if (name === undefined)
|
|
42
|
+
return [];
|
|
43
|
+
const place = async (destination) => {
|
|
44
|
+
await mkdir(destination);
|
|
45
|
+
await writeFile(join(destination, ENTRY), text.replaceAll(ORIGIN, origin));
|
|
46
|
+
};
|
|
47
|
+
return [{ name, place }];
|
|
48
|
+
});
|
|
49
|
+
return [...upstream, ...pages].sort((left, right) => (left.name < right.name ? -1 : 1));
|
|
50
|
+
}
|
|
51
|
+
async function install(origin) {
|
|
52
|
+
const placed = [];
|
|
53
|
+
for (const skill of skillSet(origin)) {
|
|
54
|
+
if (!(await present(join(skillsDirectory(), skill.name))) && !(await present(join(claudeDirectory(), skill.name)))) {
|
|
55
|
+
placed.push(skill);
|
|
51
56
|
}
|
|
52
57
|
}
|
|
58
|
+
const names = placed.map((skill) => skill.name);
|
|
53
59
|
await writeHome(RECORD, { names });
|
|
54
60
|
await mkdir(skillsDirectory(), { recursive: true });
|
|
55
61
|
await mkdir(claudeDirectory(), { recursive: true });
|
|
56
62
|
const skills = await realpath(skillsDirectory());
|
|
57
63
|
const claude = await realpath(claudeDirectory());
|
|
58
|
-
for (const name of
|
|
59
|
-
await
|
|
64
|
+
for (const { name, place } of placed) {
|
|
65
|
+
await place(join(skillsDirectory(), name));
|
|
60
66
|
if (claude !== skills)
|
|
61
67
|
await symlink(relative(claude, join(skills, name)), join(claudeDirectory(), name));
|
|
62
68
|
}
|
|
63
|
-
await writeHome(RECORD, { version:
|
|
69
|
+
await writeHome(RECORD, { version: KIT_RELEASE, origin, names });
|
|
64
70
|
}
|
|
65
|
-
export async function placeSkillSet() {
|
|
71
|
+
export async function placeSkillSet(origin) {
|
|
66
72
|
try {
|
|
67
|
-
await replaceSkillSet();
|
|
73
|
+
await replaceSkillSet(origin);
|
|
68
74
|
}
|
|
69
75
|
catch (error) {
|
|
70
76
|
process.stderr.write(`kit: the skills could not be placed: ${error.message}\n`);
|
|
71
77
|
}
|
|
72
78
|
}
|
|
73
|
-
async function replaceSkillSet() {
|
|
79
|
+
async function replaceSkillSet(origin) {
|
|
74
80
|
const accepted = (await readConfiguration()).skills;
|
|
75
81
|
const installed = await readHome(RECORD);
|
|
76
|
-
if (accepted && installed?.version ===
|
|
82
|
+
if (accepted && installed?.version === KIT_RELEASE && installed.origin === origin)
|
|
77
83
|
return;
|
|
78
84
|
for (const name of installed?.names ?? []) {
|
|
79
85
|
await rm(join(claudeDirectory(), name), { recursive: true, force: true });
|
|
80
86
|
await rm(join(skillsDirectory(), name), { recursive: true, force: true });
|
|
81
87
|
}
|
|
82
88
|
if (accepted)
|
|
83
|
-
await install();
|
|
89
|
+
await install(origin);
|
|
84
90
|
else
|
|
85
91
|
await rm(join(kitHome(), RECORD), { force: true });
|
|
86
92
|
}
|
|
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
|
-
}
|
|
131
|
-
export async function createHowWeWork(bridge) {
|
|
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')
|
|
139
|
-
return;
|
|
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')
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
146
|
-
await writeHome(WRITTEN, current);
|
|
147
|
-
}
|
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/translate.js
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
|
-
import { apply, parse, serialize } from '@agentshouse/mdmodel';
|
|
1
|
+
import { apply, definitionAt, HOUSE_TYPED_PATHS, parse, serialize, } from '@agentshouse/mdmodel';
|
|
2
2
|
function same(left, right) {
|
|
3
3
|
return JSON.stringify(left) === JSON.stringify(right);
|
|
4
4
|
}
|
|
5
|
-
function applied(document, changes) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
5
|
+
function applied(document, changes, definition) {
|
|
6
|
+
const result = apply(document, changes, definition);
|
|
7
|
+
return result.outcome === 'applied' ? serialize(result.document) : null;
|
|
8
|
+
}
|
|
9
|
+
export function readDocument(content, file, model) {
|
|
10
|
+
const definitions = definitionAt(model, file, HOUSE_TYPED_PATHS);
|
|
11
|
+
const parsed = parse(content, file, definitions);
|
|
12
|
+
if (!parsed.ok)
|
|
13
|
+
return null;
|
|
14
|
+
const { document } = parsed;
|
|
15
|
+
const definition = definitions(document.type);
|
|
16
|
+
return definition !== undefined || document.type === undefined ? { document, definition } : null;
|
|
14
17
|
}
|
|
15
|
-
function components(path, before, after, text) {
|
|
18
|
+
function components(path, before, after, text, definition) {
|
|
16
19
|
const edits = [];
|
|
17
20
|
const changes = [];
|
|
18
21
|
if (before.preamble !== after.preamble) {
|
|
@@ -39,13 +42,13 @@ function components(path, before, after, text) {
|
|
|
39
42
|
edits.push({ op: 'replace_section', path, section: name, base: prior, content: value });
|
|
40
43
|
changes.push({ kind: 'section', name, value, prior });
|
|
41
44
|
}
|
|
42
|
-
return edits.length > 0 && applied(before, changes) === text ? edits : null;
|
|
45
|
+
return edits.length > 0 && applied(before, changes, definition) === text ? edits : null;
|
|
43
46
|
}
|
|
44
|
-
export function changed(path, file, base, before, after) {
|
|
47
|
+
export function changed(path, file, base, before, after, model) {
|
|
45
48
|
if (!file.endsWith('.md'))
|
|
46
49
|
return [{ op: 'replace', path, base, content: after }];
|
|
47
|
-
const
|
|
48
|
-
const
|
|
49
|
-
const structured =
|
|
50
|
+
const prior = readDocument(before, file, model);
|
|
51
|
+
const next = readDocument(after, file, model);
|
|
52
|
+
const structured = prior !== null && next !== null ? components(path, prior.document, next.document, after, prior.definition) : null;
|
|
50
53
|
return structured ?? [{ op: 'replace', path, base, content: after }];
|
|
51
54
|
}
|