@agentshouse/kit 0.2.1-cbdf76b9a90a3 → 0.2.1-cc6246211e00c

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.
Files changed (134) hide show
  1. package/README.md +22 -22
  2. package/dist/acp.js +4 -3
  3. package/dist/agents.js +2 -2
  4. package/dist/api.js +1 -1
  5. package/dist/authority-main.js +2 -2
  6. package/dist/bridge.js +1 -1
  7. package/dist/building.js +46 -0
  8. package/dist/{inputs.js → calls.js} +20 -20
  9. package/dist/clis-main.js +2 -2
  10. package/dist/clis.js +38 -15
  11. package/dist/{stream.js → connection.js} +26 -23
  12. package/dist/conversations.js +149 -85
  13. package/dist/copies.js +15 -29
  14. package/dist/end.js +3 -3
  15. package/dist/events.js +2 -2
  16. package/dist/files.js +139 -37
  17. package/dist/git.js +3 -3
  18. package/dist/house-cli.js +95 -87
  19. package/dist/house-main.js +3 -3
  20. package/dist/instructions.js +29 -9
  21. package/dist/kit-cli.js +4 -4
  22. package/dist/kit-main.js +3 -3
  23. package/dist/login.js +2 -4
  24. package/dist/mcp.js +4 -2
  25. package/dist/relay.js +21 -0
  26. package/dist/resident.js +40 -34
  27. package/dist/service.js +1 -1
  28. package/dist/sign-in.js +22 -21
  29. package/dist/skills.js +42 -97
  30. package/dist/transcription.js +83 -43
  31. package/dist/update.js +61 -35
  32. package/dist/web-wizard.js +101 -0
  33. package/dist/wire.js +1 -1
  34. package/package.json +20 -21
  35. package/dist/bootstrap.json +0 -24
  36. package/how-we-work.md +0 -33
  37. package/skills/ask-matt/LICENSE +0 -21
  38. package/skills/ask-matt/PHASE-BOUNDARIES.md +0 -55
  39. package/skills/ask-matt/SKILL.md +0 -97
  40. package/skills/ask-matt/agents/openai.yaml +0 -5
  41. package/skills/code-review/LICENSE +0 -21
  42. package/skills/code-review/SKILL.md +0 -89
  43. package/skills/code-review/agents/openai.yaml +0 -3
  44. package/skills/codebase-design/DEEPENING.md +0 -37
  45. package/skills/codebase-design/DESIGN-IT-TWICE.md +0 -44
  46. package/skills/codebase-design/LICENSE +0 -21
  47. package/skills/codebase-design/SKILL.md +0 -114
  48. package/skills/codebase-design/agents/openai.yaml +0 -3
  49. package/skills/diagnosing-bugs/LICENSE +0 -21
  50. package/skills/diagnosing-bugs/SKILL.md +0 -138
  51. package/skills/diagnosing-bugs/agents/openai.yaml +0 -3
  52. package/skills/diagnosing-bugs/scripts/hitl-loop.template.sh +0 -44
  53. package/skills/domain-modeling/ADR-FORMAT.md +0 -47
  54. package/skills/domain-modeling/GLOSSARY-FORMAT.md +0 -60
  55. package/skills/domain-modeling/LICENSE +0 -21
  56. package/skills/domain-modeling/SKILL.md +0 -74
  57. package/skills/domain-modeling/agents/openai.yaml +0 -3
  58. package/skills/grill-me/LICENSE +0 -21
  59. package/skills/grill-me/SKILL.md +0 -7
  60. package/skills/grill-me/agents/openai.yaml +0 -5
  61. package/skills/grill-with-docs/LICENSE +0 -21
  62. package/skills/grill-with-docs/SKILL.md +0 -7
  63. package/skills/grill-with-docs/agents/openai.yaml +0 -5
  64. package/skills/grilling/LICENSE +0 -21
  65. package/skills/grilling/SKILL.md +0 -30
  66. package/skills/grilling/agents/openai.yaml +0 -3
  67. package/skills/handoff/LICENSE +0 -21
  68. package/skills/handoff/SKILL.md +0 -16
  69. package/skills/handoff/agents/openai.yaml +0 -5
  70. package/skills/implement/LICENSE +0 -21
  71. package/skills/implement/SKILL.md +0 -17
  72. package/skills/implement/agents/openai.yaml +0 -5
  73. package/skills/implement-spec/LICENSE +0 -21
  74. package/skills/implement-spec/SKILL.md +0 -40
  75. package/skills/implement-spec/agents/openai.yaml +0 -5
  76. package/skills/improve-codebase-architecture/HTML-REPORT.md +0 -123
  77. package/skills/improve-codebase-architecture/LICENSE +0 -21
  78. package/skills/improve-codebase-architecture/SKILL.md +0 -71
  79. package/skills/improve-codebase-architecture/agents/openai.yaml +0 -5
  80. package/skills/pr/CREDITS.md +0 -3
  81. package/skills/pr/LICENSE +0 -21
  82. package/skills/pr/SKILL.md +0 -170
  83. package/skills/pr/agents/openai.yaml +0 -3
  84. package/skills/prototype/LICENSE +0 -21
  85. package/skills/prototype/LOGIC.md +0 -67
  86. package/skills/prototype/SKILL.md +0 -26
  87. package/skills/prototype/UI.md +0 -112
  88. package/skills/prototype/agents/openai.yaml +0 -3
  89. package/skills/research/LICENSE +0 -21
  90. package/skills/research/SKILL.md +0 -12
  91. package/skills/research/agents/openai.yaml +0 -3
  92. package/skills/retro/LICENSE +0 -21
  93. package/skills/retro/SKILL.md +0 -44
  94. package/skills/retro/agents/openai.yaml +0 -5
  95. package/skills/tdd/LICENSE +0 -21
  96. package/skills/tdd/SKILL.md +0 -38
  97. package/skills/tdd/agents/openai.yaml +0 -3
  98. package/skills/tdd/mocking.md +0 -59
  99. package/skills/tdd/tests.md +0 -77
  100. package/skills/teach/GLOSSARY-FORMAT.md +0 -35
  101. package/skills/teach/LEARNING-RECORD-FORMAT.md +0 -46
  102. package/skills/teach/LICENSE +0 -21
  103. package/skills/teach/MISSION-FORMAT.md +0 -31
  104. package/skills/teach/RESOURCES-FORMAT.md +0 -32
  105. package/skills/teach/SKILL.md +0 -140
  106. package/skills/teach/agents/openai.yaml +0 -5
  107. package/skills/to-questionnaire/LICENSE +0 -21
  108. package/skills/to-questionnaire/SKILL.md +0 -54
  109. package/skills/to-questionnaire/agents/openai.yaml +0 -5
  110. package/skills/to-spec/LICENSE +0 -21
  111. package/skills/to-spec/SKILL.md +0 -75
  112. package/skills/to-spec/agents/openai.yaml +0 -5
  113. package/skills/to-tickets/LICENSE +0 -21
  114. package/skills/to-tickets/SKILL.md +0 -105
  115. package/skills/to-tickets/agents/openai.yaml +0 -5
  116. package/skills/triage/AGENT-BRIEF.md +0 -207
  117. package/skills/triage/LICENSE +0 -21
  118. package/skills/triage/OUT-OF-SCOPE.md +0 -105
  119. package/skills/triage/SKILL.md +0 -112
  120. package/skills/triage/agents/openai.yaml +0 -5
  121. package/skills/wait-what/LICENSE +0 -21
  122. package/skills/wait-what/SKILL.md +0 -7
  123. package/skills/wait-what/agents/openai.yaml +0 -5
  124. package/skills/wayfinder/LICENSE +0 -21
  125. package/skills/wayfinder/SKILL.md +0 -128
  126. package/skills/wayfinder/agents/openai.yaml +0 -5
  127. package/skills/wizard/LICENSE +0 -21
  128. package/skills/wizard/SKILL.md +0 -44
  129. package/skills/wizard/agents/openai.yaml +0 -3
  130. package/skills/wizard/template.sh +0 -223
  131. package/skills/writing-for-agents/LICENSE +0 -21
  132. package/skills/writing-for-agents/SKILL-MECHANICS.md +0 -22
  133. package/skills/writing-for-agents/SKILL.md +0 -81
  134. package/skills/writing-for-agents/agents/openai.yaml +0 -3
package/dist/relay.js CHANGED
@@ -1,6 +1,11 @@
1
+ import { setGlobalProxyFromEnv } from 'node:http';
2
+ const PROXY = /^https?_proxy$/i;
3
+ const LOOPBACK = ['127.0.0.1', 'localhost', '::1'];
1
4
  let selected;
5
+ let restoreProxy;
2
6
  export function selectRelay(relay) {
3
7
  selected = relay === undefined || relay === '' ? null : relay;
8
+ proxyUnlessRelayed();
4
9
  }
5
10
  export function relayOrigin() {
6
11
  if (selected !== undefined)
@@ -8,6 +13,22 @@ export function relayOrigin() {
8
13
  const ambient = process.env.HOUSE_KIT_RELAY;
9
14
  return ambient === undefined || ambient === '' ? undefined : ambient;
10
15
  }
16
+ function unlessRelayed() {
17
+ if (relayOrigin() === undefined)
18
+ return { ...process.env };
19
+ return Object.fromEntries(Object.entries(process.env).filter(([name]) => !PROXY.test(name)));
20
+ }
21
+ export function proxyUnlessRelayed() {
22
+ restoreProxy?.();
23
+ restoreProxy = setGlobalProxyFromEnv(unlessRelayed());
24
+ }
25
+ export function childEnvironment() {
26
+ const environment = unlessRelayed();
27
+ if (!Object.keys(environment).some((name) => PROXY.test(name)))
28
+ return environment;
29
+ const bypassed = [environment.NO_PROXY ?? environment.no_proxy, ...LOOPBACK].filter((entry) => entry !== undefined && entry !== '').join(',');
30
+ return { ...environment, NO_PROXY: bypassed, no_proxy: bypassed };
31
+ }
11
32
  export function relayed(target) {
12
33
  const url = new URL(target);
13
34
  const relay = relayOrigin();
package/dist/resident.js CHANGED
@@ -8,17 +8,18 @@ import { fileURLToPath } from 'node:url';
8
8
  import { Agents } from './agents.js';
9
9
  import { house } from './api.js';
10
10
  import { received } from './bridge.js';
11
- import { CONVERSATION_INPUTS, Conversations } from './conversations.js';
11
+ import { CONVERSATION_METHODS, Conversations } from './conversations.js';
12
12
  import { LocalCopies } from './copies.js';
13
13
  import { restart } from './end.js';
14
- import { agentBase, enrolled, forgetRestart, kitHome, ownerLock, ownerSocket, restartAsked } from './home.js';
15
- import { Inputs } from './inputs.js';
14
+ import { agentBase, enrolled, forgetRestart, kitHome, ownerLock, ownerSocket, readEnrolment, restartAsked } from './home.js';
15
+ import { Calls } from './calls.js';
16
16
  import { killDescendants } from './scope.js';
17
17
  import { quoted } from './shell.js';
18
18
  import { SignIns } from './sign-in.js';
19
19
  import { placeSkillSet } from './skills.js';
20
- import { holdStream } from './stream.js';
21
- import { Updates } from './update.js';
20
+ import { holdConnection } from './connection.js';
21
+ import { KitUpdate } from './update.js';
22
+ import { WebWizards } from './web-wizard.js';
22
23
  import { codexLauncher } from './work.js';
23
24
  function report(error) {
24
25
  process.stderr.write(`kit: ${error instanceof Error ? error.message : String(error)}\n`);
@@ -47,7 +48,7 @@ async function serveOwner(copies) {
47
48
  if (!claimed(lock)) {
48
49
  lock.close();
49
50
  const running = await runningResident();
50
- throw new Error(`${running === null ? 'another Kit' : `Kit ${running}`} already runs this Environment from Kit home ${kitHome()}; stop it first to run another here`);
51
+ throw new Error(`${running === null ? 'another Kit process' : `Kit process ${running}`} already runs this Environment from Kit home ${kitHome()}; stop it first to run another Kit process here`);
51
52
  }
52
53
  const server = createServer(async (request, response) => {
53
54
  try {
@@ -116,7 +117,7 @@ async function started() {
116
117
  killDescendants();
117
118
  process.exit(1);
118
119
  });
119
- await placeSkillSet();
120
+ await placeSkillSet((await readEnrolment()).house);
120
121
  await mkdir(agentBase(), { recursive: true });
121
122
  await installShim(join(kitHome(), 'shim', 'git'), 'git-main');
122
123
  await installShim(codexLauncher(), 'codex-main');
@@ -132,9 +133,9 @@ export async function resident() {
132
133
  });
133
134
  process.env.HOUSE_KIT_RESIDENT = String(process.pid);
134
135
  const agents = new Agents(house, () => changed());
135
- let stream = null;
136
+ let connection = null;
136
137
  let reported = false;
137
- const idle = () => inputs.idle() && conversations.idle() && agents.idle();
138
+ const idle = () => calls.idle() && conversations.idle() && agents.idle();
138
139
  const changed = () => {
139
140
  if (!idle()) {
140
141
  reported = false;
@@ -147,17 +148,18 @@ export async function resident() {
147
148
  logged(house.deliver('/kit/idle', {}, idle));
148
149
  }
149
150
  };
150
- const inputs = new Inputs(house, changed);
151
+ const calls = new Calls(house, changed);
151
152
  const conversations = new Conversations({
152
153
  house,
153
154
  agents,
154
155
  copies,
155
- inputs,
156
- send: (frame) => stream?.send(frame) ?? false,
156
+ calls,
157
+ send: (notification) => connection?.send(notification) ?? false,
157
158
  changed,
158
159
  });
159
- const signIns = new SignIns(house, agents, inputs);
160
- const updates = new Updates(inputs);
160
+ const signIns = new SignIns(house, agents, calls);
161
+ const update = new KitUpdate(calls);
162
+ const wizards = new WebWizards(calls, (notification) => connection?.send(notification) ?? false);
161
163
  for (const signal of ['SIGTERM', 'SIGINT']) {
162
164
  process.once(signal, () => {
163
165
  killDescendants();
@@ -165,33 +167,37 @@ export async function resident() {
165
167
  });
166
168
  }
167
169
  await house.deliver('/kit/restarted', {}).catch(report);
168
- await updates.resumed().catch(report);
170
+ await update.resumed().catch(report);
169
171
  logged(agents.refresh());
170
- stream = holdStream({
172
+ connection = holdConnection({
171
173
  opened: () => {
172
174
  conversations.opened();
173
175
  changed();
174
176
  logged(copies.connected());
175
177
  },
176
- frame: (arrived) => {
177
- if (arrived.type === 'watching')
178
- conversations.watching(arrived.watching === true);
179
- if (arrived.type === 'authority_changed')
180
- logged(copies.changed(arrived.rooms));
181
- if (arrived.type === 'work_available' && arrived.subject === 'agents')
182
- logged(agents.refresh());
183
- if (arrived.type === 'input') {
184
- if (arrived.kind === 'sign_in')
185
- signIns.start(arrived);
186
- else if (arrived.kind === 'update')
187
- updates.start(arrived);
188
- else if (CONVERSATION_INPUTS.has(arrived.kind))
189
- conversations.input(arrived);
190
- else {
191
- const refused = { refused: `This Kit does not know ${arrived.kind}; update the Kit` };
192
- void inputs.carry(String(arrived.input_id), async () => ({ ack: refused }));
193
- }
178
+ closed: () => wizards.disconnected(),
179
+ call: (call) => {
180
+ if (call.kind === 'sign_in')
181
+ signIns.start(call);
182
+ else if (call.kind === 'update')
183
+ update.start(call);
184
+ else if (call.kind === 'run_wizard')
185
+ wizards.start(call);
186
+ else if (CONVERSATION_METHODS.has(call.kind))
187
+ conversations.call(call);
188
+ else {
189
+ const refused = { refused: `This Kit does not know ${call.kind}; update the Kit` };
190
+ void calls.carry(call.input_id, async () => ({ result: refused }));
194
191
  }
195
192
  },
193
+ notification: (notification) => {
194
+ if (notification.type === 'watching')
195
+ conversations.watching(notification.watching === true);
196
+ if (notification.type === 'authority_changed')
197
+ logged(copies.changed(notification.rooms));
198
+ if (notification.type === 'work_available' && notification.subject === 'agents')
199
+ logged(agents.refresh());
200
+ wizards.notified(notification);
201
+ },
196
202
  });
197
203
  }
package/dist/service.js CHANGED
@@ -13,7 +13,7 @@ function start(command, args) {
13
13
  if (started.status === 0)
14
14
  return;
15
15
  const cause = started.error?.message ?? (started.stderr.trim() || `${command} exited with ${started.status ?? 'a signal'}`);
16
- throw new Error(`the House Kit service could not be started: ${cause}`);
16
+ throw new Error(`the Kit service could not be started: ${cause}`);
17
17
  }
18
18
  function physical(path) {
19
19
  return existsSync(path) ? realpathSync(path) : resolve(path);
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, withoutProxy } from './clis.js';
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;
@@ -15,48 +16,48 @@ function endOf(signal) {
15
16
  export class SignIns {
16
17
  house;
17
18
  agents;
18
- inputs;
19
- constructor(house, agents, inputs) {
19
+ calls;
20
+ constructor(house, agents, calls) {
20
21
  this.house = house;
21
22
  this.agents = agents;
22
- this.inputs = inputs;
23
+ this.calls = calls;
23
24
  }
24
- start(input) {
25
- void this.inputs.carry(input.input_id, () => this.signIn(input));
25
+ start(call) {
26
+ void this.calls.carry(call.input_id, () => this.signIn(call));
26
27
  }
27
- async signIn(input) {
28
+ async signIn(call) {
28
29
  const ending = new AbortController();
29
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.
30
- const timer = setTimeout(() => ending.abort(), input.ends_in * 1000);
31
- const ended = await Promise.race([this.signedIn(input, ending.signal), endOf(ending.signal)]);
31
+ const timer = setTimeout(() => ending.abort(), call.ends_in * 1000);
32
+ const ended = await Promise.race([this.signedIn(call, ending.signal), endOf(ending.signal)]);
32
33
  clearTimeout(timer);
33
34
  if (ended)
34
- process.stderr.write(`kit: the ${input.cli} sign-in reached the end House set for it\n`);
35
- return ended ? { ack: {} } : { ack: {}, acknowledged: () => 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) };
36
37
  }
37
- async signedIn(input, signal) {
38
- await this.login(input, signal);
38
+ async signedIn(call, signal) {
39
+ await this.login(call, signal);
39
40
  if (!signal.aborted)
40
- await this.agents.recheck(input.cli, signal);
41
+ await this.agents.recheck(call.cli, signal);
41
42
  return false;
42
43
  }
43
- async login(input, signal) {
44
+ async login(call, signal) {
44
45
  let cli;
45
46
  try {
46
- cli = await this.agents.located(input.cli, signal);
47
+ cli = await this.agents.located(call.cli, signal);
47
48
  }
48
49
  catch (error) {
49
50
  if (!signal.aborted)
50
- process.stderr.write(`kit: the ${input.cli} sign-in failed: ${causeOf(error)}\n`);
51
+ process.stderr.write(`kit: the ${call.cli} sign-in failed: ${causeOf(error)}\n`);
51
52
  return;
52
53
  }
53
54
  if (signal.aborted)
54
55
  return;
55
- const login = CLIS[input.cli].login;
56
+ const login = CLIS[call.cli].login;
56
57
  const child = spawn(cli, login.args, {
57
58
  stdio: ['pipe', 'pipe', 'pipe'],
58
59
  detached: true,
59
- env: withoutProxy(),
60
+ env: childEnvironment(),
60
61
  });
61
62
  const running = () => child.exitCode === null && child.signalCode === null;
62
63
  const stop = () => killTree(child);
@@ -84,7 +85,7 @@ export class SignIns {
84
85
  return;
85
86
  held = true;
86
87
  const steps = [{ kind: 'visit', label: 'Open this link and sign in', url: link }, step];
87
- void holdSecretInput(this.house, input.input_id, steps, running).then((content) => {
88
+ void holdSecretInput(this.house, call.input_id, steps, running).then((content) => {
88
89
  if (!running())
89
90
  return;
90
91
  if (content === null)
@@ -101,6 +102,6 @@ export class SignIns {
101
102
  });
102
103
  signal.removeEventListener('abort', stop);
103
104
  if (failed !== null && !signal.aborted)
104
- process.stderr.write(`kit: the ${input.cli} sign-in failed: ${failed}\n`);
105
+ process.stderr.write(`kit: the ${call.cli} sign-in failed: ${failed}\n`);
105
106
  }
106
107
  }
package/dist/skills.js CHANGED
@@ -1,31 +1,14 @@
1
- import { createHash } from 'node:crypto';
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 { fileURLToPath } from 'node:url';
4
+ import { GUIDE, listSkills } from '@agentshouse/skills';
7
5
  import { parse } from 'yaml';
8
- import { KIT_VERSION } from './clis.js';
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 WRITTEN = 'how-we-work.json';
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: (.+)$/;
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
- async function install() {
47
- const names = [];
48
- for (const name of (await readdir(SKILL_SET)).sort()) {
49
- if (!(await present(join(skillsDirectory(), name))) && !(await present(join(claudeDirectory(), name)))) {
50
- names.push(name);
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 names) {
59
- await cp(join(SKILL_SET, name), join(skillsDirectory(), name), { recursive: true });
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: KIT_VERSION, names });
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 === KIT_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
- }
@@ -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
- url: 'https://huggingface.co/ggml-org/parakeet-GGUF/resolve/35156454d1a39de06863303dd209fd2bed6ee079/ggml-parakeet-tdt-0.6b-v3-q4_k.bin',
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: { url: `${RELEASE}/ffmpeg-linux-x86_64`, sha256: '1f8235d206428305afb89c6e8ab99d100425a0ba61e22bb4c7aff017db8c8de5', executable: true },
19
- engine: { url: `${RELEASE}/parakeet-cli-linux-x86_64`, sha256: 'bb2585695992fe1927a33960002cdf51b8a90a96ad65593c3d0a9f1fbc0865c2', executable: true },
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: { url: `${RELEASE}/ffmpeg-linux-aarch64`, sha256: 'a7e08a0fae0179d1078312f6bb13d2a9aa4d4c71a1d82a022953f25dee452f5e', executable: true },
23
- engine: { url: `${RELEASE}/parakeet-cli-linux-aarch64`, sha256: 'cbc0bedc8daae97f1ef9dcee4200c06226218e300e0fd62ead1306d22742b7ed', executable: true },
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: { url: `${RELEASE}/ffmpeg-darwin-arm64`, sha256: '7abe154aaed3d6b49f5167ca7221bb66bed51388925d99a7e4261a41fe52fba6', executable: true },
27
- engine: { url: `${RELEASE}/parakeet-cli-darwin-arm64`, sha256: '9a2aafc0922ad7c0b6db6eff1641e96572ba32ac40bf995a1df242ed2febf297', executable: true },
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 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.
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)));
@@ -54,17 +60,45 @@ async function threads() {
54
60
  const allowed = quota === 'max' ? Infinity : Math.ceil(Number(quota) / Number(period));
55
61
  return Math.max(1, Math.floor(Math.min(availableParallelism(), allowed) / 2));
56
62
  }
57
- async function sha256(path) {
58
- const hash = createHash('sha256');
59
- await pipeline(createReadStream(path), hash);
60
- return hash.digest('hex');
61
- }
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
- const part = `${installed(artifact)}.part`;
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(path, signal) {
165
+ async function transcribed(audio, parts, signal) {
137
166
  const pinned = pinnedHere();
138
- const work = await mkdtemp(join(tmpdir(), 'kit-transcription-'));
139
- try {
140
- await executed(installed(pinned.decoder), ['-nostdin', '-hide_banner', '-loglevel', 'error', '-i', path, '-ar', '16000', '-ac', '1', '-c:a', 'pcm_s16le',
141
- '-f', 'segment', '-segment_time', String(CHUNK_SECONDS), join(work, '%05d.wav')], signal);
142
- const parts = (await readdir(work)).sort().flatMap((part) => ['-f', join(work, part)]);
143
- const text = await executed(installed(pinned.engine), ['-t', String(await threads()), '-np', '-m', installed(MODEL), ...parts], signal);
144
- return text
145
- .split('\n')
146
- .map((line) => line.trim())
147
- .filter((line) => line !== '')
148
- .join(' ');
149
- }
150
- finally {
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
- export async function transcribe(path, signal) {
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 readiness.installed ? await transcribed(path, signal) : null;
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
+ }