@agentshouse/kit 0.2.1-c9c41d009d46a → 0.2.1-ca0e1517cce79

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 (133) hide show
  1. package/README.md +24 -24
  2. package/dist/acp.js +36 -16
  3. package/dist/agents.js +36 -16
  4. package/dist/api.js +5 -5
  5. package/dist/bootstrap.json +4 -4
  6. package/dist/bridge.js +2 -2
  7. package/dist/calls.js +63 -0
  8. package/dist/clis.js +15 -3
  9. package/dist/{stream.js → connection.js} +33 -30
  10. package/dist/conversations.js +364 -153
  11. package/dist/copies.js +62 -43
  12. package/dist/end.js +6 -2
  13. package/dist/events.js +4 -3
  14. package/dist/files.js +139 -37
  15. package/dist/git.js +1 -1
  16. package/dist/house-cli.js +93 -84
  17. package/dist/house-main.js +3 -3
  18. package/dist/instructions.js +28 -8
  19. package/dist/kit-cli.js +2 -2
  20. package/dist/kit-main.js +3 -3
  21. package/dist/login.js +1 -3
  22. package/dist/mcp.js +4 -2
  23. package/dist/placement.js +11 -2
  24. package/dist/resident.js +38 -28
  25. package/dist/scope.js +3 -0
  26. package/dist/service.js +23 -1
  27. package/dist/sign-in.js +19 -37
  28. package/dist/skills.js +12 -93
  29. package/dist/transcription.js +51 -20
  30. package/dist/translate.js +2 -8
  31. package/dist/update.js +42 -45
  32. package/dist/web-wizard.js +100 -0
  33. package/dist/wire.js +19 -3
  34. package/package.json +12 -12
  35. package/how-we-work.md +0 -33
  36. package/skills/ask-matt/LICENSE +0 -21
  37. package/skills/ask-matt/PHASE-BOUNDARIES.md +0 -55
  38. package/skills/ask-matt/SKILL.md +0 -97
  39. package/skills/ask-matt/agents/openai.yaml +0 -5
  40. package/skills/code-review/LICENSE +0 -21
  41. package/skills/code-review/SKILL.md +0 -89
  42. package/skills/code-review/agents/openai.yaml +0 -3
  43. package/skills/codebase-design/DEEPENING.md +0 -37
  44. package/skills/codebase-design/DESIGN-IT-TWICE.md +0 -44
  45. package/skills/codebase-design/LICENSE +0 -21
  46. package/skills/codebase-design/SKILL.md +0 -114
  47. package/skills/codebase-design/agents/openai.yaml +0 -3
  48. package/skills/diagnosing-bugs/LICENSE +0 -21
  49. package/skills/diagnosing-bugs/SKILL.md +0 -138
  50. package/skills/diagnosing-bugs/agents/openai.yaml +0 -3
  51. package/skills/diagnosing-bugs/scripts/hitl-loop.template.sh +0 -44
  52. package/skills/domain-modeling/ADR-FORMAT.md +0 -47
  53. package/skills/domain-modeling/GLOSSARY-FORMAT.md +0 -60
  54. package/skills/domain-modeling/LICENSE +0 -21
  55. package/skills/domain-modeling/SKILL.md +0 -74
  56. package/skills/domain-modeling/agents/openai.yaml +0 -3
  57. package/skills/grill-me/LICENSE +0 -21
  58. package/skills/grill-me/SKILL.md +0 -7
  59. package/skills/grill-me/agents/openai.yaml +0 -5
  60. package/skills/grill-with-docs/LICENSE +0 -21
  61. package/skills/grill-with-docs/SKILL.md +0 -7
  62. package/skills/grill-with-docs/agents/openai.yaml +0 -5
  63. package/skills/grilling/LICENSE +0 -21
  64. package/skills/grilling/SKILL.md +0 -30
  65. package/skills/grilling/agents/openai.yaml +0 -3
  66. package/skills/handoff/LICENSE +0 -21
  67. package/skills/handoff/SKILL.md +0 -16
  68. package/skills/handoff/agents/openai.yaml +0 -5
  69. package/skills/implement/LICENSE +0 -21
  70. package/skills/implement/SKILL.md +0 -17
  71. package/skills/implement/agents/openai.yaml +0 -5
  72. package/skills/implement-spec/LICENSE +0 -21
  73. package/skills/implement-spec/SKILL.md +0 -40
  74. package/skills/implement-spec/agents/openai.yaml +0 -5
  75. package/skills/improve-codebase-architecture/HTML-REPORT.md +0 -123
  76. package/skills/improve-codebase-architecture/LICENSE +0 -21
  77. package/skills/improve-codebase-architecture/SKILL.md +0 -71
  78. package/skills/improve-codebase-architecture/agents/openai.yaml +0 -5
  79. package/skills/pr/CREDITS.md +0 -3
  80. package/skills/pr/LICENSE +0 -21
  81. package/skills/pr/SKILL.md +0 -170
  82. package/skills/pr/agents/openai.yaml +0 -3
  83. package/skills/prototype/LICENSE +0 -21
  84. package/skills/prototype/LOGIC.md +0 -67
  85. package/skills/prototype/SKILL.md +0 -26
  86. package/skills/prototype/UI.md +0 -112
  87. package/skills/prototype/agents/openai.yaml +0 -3
  88. package/skills/research/LICENSE +0 -21
  89. package/skills/research/SKILL.md +0 -12
  90. package/skills/research/agents/openai.yaml +0 -3
  91. package/skills/retro/LICENSE +0 -21
  92. package/skills/retro/SKILL.md +0 -44
  93. package/skills/retro/agents/openai.yaml +0 -5
  94. package/skills/tdd/LICENSE +0 -21
  95. package/skills/tdd/SKILL.md +0 -38
  96. package/skills/tdd/agents/openai.yaml +0 -3
  97. package/skills/tdd/mocking.md +0 -59
  98. package/skills/tdd/tests.md +0 -77
  99. package/skills/teach/GLOSSARY-FORMAT.md +0 -35
  100. package/skills/teach/LEARNING-RECORD-FORMAT.md +0 -46
  101. package/skills/teach/LICENSE +0 -21
  102. package/skills/teach/MISSION-FORMAT.md +0 -31
  103. package/skills/teach/RESOURCES-FORMAT.md +0 -32
  104. package/skills/teach/SKILL.md +0 -140
  105. package/skills/teach/agents/openai.yaml +0 -5
  106. package/skills/to-questionnaire/LICENSE +0 -21
  107. package/skills/to-questionnaire/SKILL.md +0 -54
  108. package/skills/to-questionnaire/agents/openai.yaml +0 -5
  109. package/skills/to-spec/LICENSE +0 -21
  110. package/skills/to-spec/SKILL.md +0 -75
  111. package/skills/to-spec/agents/openai.yaml +0 -5
  112. package/skills/to-tickets/LICENSE +0 -21
  113. package/skills/to-tickets/SKILL.md +0 -105
  114. package/skills/to-tickets/agents/openai.yaml +0 -5
  115. package/skills/triage/AGENT-BRIEF.md +0 -207
  116. package/skills/triage/LICENSE +0 -21
  117. package/skills/triage/OUT-OF-SCOPE.md +0 -105
  118. package/skills/triage/SKILL.md +0 -112
  119. package/skills/triage/agents/openai.yaml +0 -5
  120. package/skills/wait-what/LICENSE +0 -21
  121. package/skills/wait-what/SKILL.md +0 -7
  122. package/skills/wait-what/agents/openai.yaml +0 -5
  123. package/skills/wayfinder/LICENSE +0 -21
  124. package/skills/wayfinder/SKILL.md +0 -128
  125. package/skills/wayfinder/agents/openai.yaml +0 -5
  126. package/skills/wizard/LICENSE +0 -21
  127. package/skills/wizard/SKILL.md +0 -44
  128. package/skills/wizard/agents/openai.yaml +0 -3
  129. package/skills/wizard/template.sh +0 -223
  130. package/skills/writing-for-agents/LICENSE +0 -21
  131. package/skills/writing-for-agents/SKILL-MECHANICS.md +0 -22
  132. package/skills/writing-for-agents/SKILL.md +0 -81
  133. package/skills/writing-for-agents/agents/openai.yaml +0 -3
package/dist/sign-in.js CHANGED
@@ -9,68 +9,50 @@ const CODE = /^[A-Z0-9]+-[A-Z0-9]+$/;
9
9
  function causeOf(error) {
10
10
  return error instanceof Error ? error.message : String(error);
11
11
  }
12
- function logged(error) {
13
- process.stderr.write(`kit: ${causeOf(error)}\n`);
14
- }
15
12
  function endOf(signal) {
16
13
  return new Promise((resolve) => signal.addEventListener('abort', () => resolve(true), { once: true }));
17
14
  }
18
15
  export class SignIns {
19
16
  house;
20
17
  agents;
21
- changed;
22
- running = new Set();
23
- constructor(house, agents, changed) {
18
+ calls;
19
+ constructor(house, agents, calls) {
24
20
  this.house = house;
25
21
  this.agents = agents;
26
- this.changed = changed;
27
- }
28
- idle() {
29
- return this.running.size === 0;
22
+ this.calls = calls;
30
23
  }
31
- start(input) {
32
- if (this.running.has(input.input_id))
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
- });
24
+ start(call) {
25
+ void this.calls.carry(call.input_id, () => this.signIn(call));
42
26
  }
43
- async signIn(input) {
27
+ async signIn(call) {
44
28
  const ending = new AbortController();
45
29
  // 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(), input.ends_in * 1000);
47
- const ended = await Promise.race([this.signedIn(input, ending.signal), endOf(ending.signal)]);
30
+ const timer = setTimeout(() => ending.abort(), call.ends_in * 1000);
31
+ const ended = await Promise.race([this.signedIn(call, ending.signal), endOf(ending.signal)]);
48
32
  clearTimeout(timer);
49
33
  if (ended)
50
- process.stderr.write(`kit: the ${input.cli} sign-in reached the end House set for it\n`);
51
- await this.house.deliver(`/kit/inputs/${input.input_id}/ack`, {});
52
- if (!ended)
53
- await this.agents.reread(input.cli);
34
+ process.stderr.write(`kit: the ${call.cli} sign-in reached the end House set for it\n`);
35
+ return ended ? { result: {} } : { result: {}, returned: () => this.agents.reread(call.cli) };
54
36
  }
55
- async signedIn(input, signal) {
56
- await this.login(input, signal);
37
+ async signedIn(call, signal) {
38
+ await this.login(call, signal);
57
39
  if (!signal.aborted)
58
- await this.agents.recheck(input.cli, signal);
40
+ await this.agents.recheck(call.cli, signal);
59
41
  return false;
60
42
  }
61
- async login(input, signal) {
43
+ async login(call, signal) {
62
44
  let cli;
63
45
  try {
64
- cli = await this.agents.located(input.cli, signal);
46
+ cli = await this.agents.located(call.cli, signal);
65
47
  }
66
48
  catch (error) {
67
49
  if (!signal.aborted)
68
- process.stderr.write(`kit: the ${input.cli} sign-in failed: ${causeOf(error)}\n`);
50
+ process.stderr.write(`kit: the ${call.cli} sign-in failed: ${causeOf(error)}\n`);
69
51
  return;
70
52
  }
71
53
  if (signal.aborted)
72
54
  return;
73
- const login = CLIS[input.cli].login;
55
+ const login = CLIS[call.cli].login;
74
56
  const child = spawn(cli, login.args, {
75
57
  stdio: ['pipe', 'pipe', 'pipe'],
76
58
  detached: true,
@@ -102,7 +84,7 @@ export class SignIns {
102
84
  return;
103
85
  held = true;
104
86
  const steps = [{ kind: 'visit', label: 'Open this link and sign in', url: link }, step];
105
- void holdSecretInput(this.house, input.input_id, steps, running).then((content) => {
87
+ void holdSecretInput(this.house, call.input_id, steps, running).then((content) => {
106
88
  if (!running())
107
89
  return;
108
90
  if (content === null)
@@ -119,6 +101,6 @@ export class SignIns {
119
101
  });
120
102
  signal.removeEventListener('abort', stop);
121
103
  if (failed !== null && !signal.aborted)
122
- process.stderr.write(`kit: the ${input.cli} sign-in failed: ${failed}\n`);
104
+ process.stderr.write(`kit: the ${call.cli} sign-in failed: ${failed}\n`);
123
105
  }
124
106
  }
package/dist/skills.js CHANGED
@@ -1,31 +1,10 @@
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 } 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';
7
- import { parse } from 'yaml';
8
- import { KIT_VERSION } from './clis.js';
4
+ import { listSkills } from '@agentshouse/skills';
5
+ import { KIT_RELEASE } from './clis.js';
9
6
  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
7
  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: (.+)$/;
29
8
  function skillsDirectory() {
30
9
  return join(homedir(), '.agents', 'skills');
31
10
  }
@@ -44,23 +23,24 @@ async function present(path) {
44
23
  }
45
24
  }
46
25
  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);
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);
51
30
  }
52
31
  }
32
+ const names = placed.map((skill) => skill.name);
53
33
  await writeHome(RECORD, { names });
54
34
  await mkdir(skillsDirectory(), { recursive: true });
55
35
  await mkdir(claudeDirectory(), { recursive: true });
56
36
  const skills = await realpath(skillsDirectory());
57
37
  const claude = await realpath(claudeDirectory());
58
- for (const name of names) {
59
- await cp(join(SKILL_SET, name), join(skillsDirectory(), name), { recursive: true });
38
+ for (const { name, directory } of placed) {
39
+ await cp(directory, join(skillsDirectory(), name), { recursive: true });
60
40
  if (claude !== skills)
61
41
  await symlink(relative(claude, join(skills, name)), join(claudeDirectory(), name));
62
42
  }
63
- await writeHome(RECORD, { version: KIT_VERSION, names });
43
+ await writeHome(RECORD, { version: KIT_RELEASE, names });
64
44
  }
65
45
  export async function placeSkillSet() {
66
46
  try {
@@ -73,7 +53,7 @@ export async function placeSkillSet() {
73
53
  async function replaceSkillSet() {
74
54
  const accepted = (await readConfiguration()).skills;
75
55
  const installed = await readHome(RECORD);
76
- if (accepted && installed?.version === KIT_VERSION)
56
+ if (accepted && installed?.version === KIT_RELEASE)
77
57
  return;
78
58
  for (const name of installed?.names ?? []) {
79
59
  await rm(join(claudeDirectory(), name), { recursive: true, force: true });
@@ -84,64 +64,3 @@ async function replaceSkillSet() {
84
64
  else
85
65
  await rm(join(kitHome(), RECORD), { force: true });
86
66
  }
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
- }
@@ -6,6 +6,7 @@ import { basename, join } from 'node:path';
6
6
  import { pipeline } from 'node:stream/promises';
7
7
  import { unlessAborted } from './abort.js';
8
8
  import { failureOf, run } from './clis.js';
9
+ import { downloaded, fetched } from './files.js';
9
10
  import { kitHome } from './home.js';
10
11
  const RELEASE = 'https://github.com/agentshouse/kit/releases/download/engine-2';
11
12
  export const MODEL = {
@@ -28,6 +29,11 @@ export const ENGINES = {
28
29
  },
29
30
  };
30
31
  const CHUNK_SECONDS = 20;
32
+ const OFF = "transcription is off on the Agent's Environment, so this message's audio has no text; turn it on or write instead";
33
+ const NOT_INSTALLED = "the speech engine is not installed on the Agent's Environment, so this message's audio has no text";
34
+ const NOT_DOWNLOADED = 'an audio file this message links could not be downloaded; send the message again';
35
+ const UNDECODABLE = 'an audio file this message links could not be decoded';
36
+ const UNTRANSCRIBED = 'an audio file this message links could not be transcribed';
31
37
  let held = Promise.resolve();
32
38
  let holding = Promise.resolve();
33
39
  let setting = null;
@@ -62,6 +68,20 @@ async function sha256(path) {
62
68
  function causeOf(error) {
63
69
  return error instanceof Error ? error.message : String(error);
64
70
  }
71
+ async function failing(reason, work) {
72
+ try {
73
+ return await work;
74
+ }
75
+ catch (error) {
76
+ throw new Error(reason, { cause: error });
77
+ }
78
+ }
79
+ function ready() {
80
+ if (setting !== true)
81
+ throw new Error(OFF);
82
+ if (!readiness.installed)
83
+ throw new Error(NOT_INSTALLED);
84
+ }
65
85
  function pinnedHere() {
66
86
  return ENGINES[`${process.platform}-${process.arch}`];
67
87
  }
@@ -133,27 +153,23 @@ export function holdTranscription(transcribe) {
133
153
  export function transcriptionReport() {
134
154
  return readiness;
135
155
  }
136
- async function transcribed(path, signal) {
156
+ async function transcribed(audio, parts, signal) {
137
157
  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
- }
158
+ await mkdir(parts);
159
+ await failing(UNDECODABLE, executed(installed(pinned.decoder), ['-nostdin', '-hide_banner', '-loglevel', 'error', '-i', audio, '-ar', '16000', '-ac', '1', '-c:a', 'pcm_s16le',
160
+ '-f', 'segment', '-segment_time', String(CHUNK_SECONDS), join(parts, '%05d.wav')], signal));
161
+ const segments = (await readdir(parts)).sort().flatMap((part) => ['-f', join(parts, part)]);
162
+ const said = await failing(UNTRANSCRIBED, executed(installed(pinned.engine), ['-t', String(await threads()), '-np', '-m', installed(MODEL), ...segments], signal));
163
+ const text = said
164
+ .split('\n')
165
+ .map((line) => line.trim())
166
+ .filter((line) => line !== '')
167
+ .join(' ');
168
+ if (text === '')
169
+ throw new Error(UNTRANSCRIBED);
170
+ return text;
153
171
  }
154
- export async function transcribe(path, signal) {
155
- if (!readiness.installed)
156
- return null;
172
+ async function alone(work, signal) {
157
173
  const before = held;
158
174
  let release;
159
175
  const mine = new Promise((resolve) => {
@@ -162,9 +178,24 @@ export async function transcribe(path, signal) {
162
178
  held = Promise.all([before, mine]);
163
179
  try {
164
180
  await unlessAborted(before, signal);
165
- return readiness.installed ? await transcribed(path, signal) : null;
181
+ return await work();
166
182
  }
167
183
  finally {
168
184
  release();
169
185
  }
170
186
  }
187
+ export async function transcribe(address, signal) {
188
+ ready();
189
+ const work = await mkdtemp(join(tmpdir(), 'kit-transcription-'));
190
+ try {
191
+ const audio = join(work, 'audio');
192
+ await failing(NOT_DOWNLOADED, downloaded(address, (url) => fetched(url, signal), audio, 'audio'));
193
+ return await alone(() => {
194
+ ready();
195
+ return transcribed(audio, join(work, 'parts'), signal);
196
+ }, signal);
197
+ }
198
+ finally {
199
+ await rm(work, { recursive: true, force: true });
200
+ }
201
+ }
package/dist/translate.js CHANGED
@@ -3,14 +3,8 @@ function same(left, right) {
3
3
  return JSON.stringify(left) === JSON.stringify(right);
4
4
  }
5
5
  function applied(document, changes) {
6
- let current = document;
7
- for (const change of changes) {
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,6 @@ 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
- function logged(error) {
10
- process.stderr.write(`kit: ${error instanceof Error ? error.message : String(error)}\n`);
11
- }
12
9
  function directory() {
13
10
  return join(kitHome(), 'update');
14
11
  }
@@ -18,8 +15,8 @@ function pending() {
18
15
  function outcome() {
19
16
  return join(directory(), 'outcome');
20
17
  }
21
- function unit(inputId) {
22
- return `house-kit-update-${inputId}`;
18
+ function unit(callId) {
19
+ return `house-kit-update-${callId}`;
23
20
  }
24
21
  function manager() {
25
22
  return service() === 'user' ? ['--user'] : [];
@@ -36,7 +33,7 @@ function placement() {
36
33
  function record() {
37
34
  return `outcome=$1; shift; bash "$0" "$@"; printf %s "$?" > "$outcome"; ${[...elevated(), 'systemctl', ...manager(), 'start', 'house-kit.service'].join(' ')}`;
38
35
  }
39
- async function pendingInput() {
36
+ async function pendingCall() {
40
37
  try {
41
38
  return JSON.parse(await readFile(pending(), 'utf8')).input_id;
42
39
  }
@@ -50,20 +47,26 @@ async function recorded() {
50
47
  return null;
51
48
  return status.trim() === '0' ? {} : { refused: `the Kit bootstrap exited with ${status.trim()}` };
52
49
  }
53
- async function finished(inputId) {
50
+ async function forget(callId) {
51
+ if ((await pendingCall()) !== callId)
52
+ return;
53
+ await rm(pending(), { force: true });
54
+ await rm(outcome(), { force: true });
55
+ }
56
+ async function finished(callId) {
54
57
  for (;;) {
55
- const ack = await recorded();
56
- if (ack !== null)
57
- return ack;
58
+ const result = await recorded();
59
+ if (result !== null)
60
+ return result;
58
61
  // systemctl answers at once, so ten seconds only bounds a stuck service manager.
59
- if ((await run('systemctl', [...manager(), 'is-active', '--quiet', unit(inputId)], 10_000)).status !== 0) {
62
+ if ((await run('systemctl', [...manager(), 'is-active', '--quiet', unit(callId)], 10_000)).status !== 0) {
60
63
  return (await recorded()) ?? { refused: 'the Kit bootstrap did not finish' };
61
64
  }
62
65
  // The bootstrap runs for minutes, so checking each second sees its outcome within a second at little cost.
63
66
  await new Promise((resolve) => setTimeout(resolve, 1000));
64
67
  }
65
68
  }
66
- function rerun(script, inputId, flags) {
69
+ function rerun(script, callId, flags) {
67
70
  return new Promise((resolve) => {
68
71
  const [command, ...args] = [
69
72
  ...elevated(),
@@ -73,7 +76,7 @@ function rerun(script, inputId, flags) {
73
76
  '--wait',
74
77
  '--collect',
75
78
  '--quiet',
76
- `--unit=${unit(inputId)}`,
79
+ `--unit=${unit(callId)}`,
77
80
  `--setenv=HOME=${homedir()}`,
78
81
  `--setenv=HOUSE_KIT_HOME=${kitHome()}`,
79
82
  '/bin/sh',
@@ -85,57 +88,51 @@ function rerun(script, inputId, flags) {
85
88
  ...flags,
86
89
  ];
87
90
  const child = spawn(command, args, { stdio: ['ignore', 'ignore', 'inherit'] });
88
- child.on('error', () => resolve({ refused: 'no service manager runs this Kit' }));
91
+ child.on('error', () => resolve({ refused: 'no service manager runs this Kit process' }));
89
92
  child.on('close', () => resolve(null));
90
93
  });
91
94
  }
92
- export class Updates {
93
- house;
94
- held = new Set();
95
+ export class KitUpdate {
96
+ calls;
95
97
  queue = Promise.resolve();
96
- constructor(house) {
97
- this.house = house;
98
+ constructor(calls) {
99
+ this.calls = calls;
98
100
  }
99
101
  async resumed() {
100
- const inputId = await pendingInput();
101
- if (inputId === null)
102
+ const callId = await pendingCall();
103
+ if (callId === null)
102
104
  return;
103
- await this.acknowledge(inputId, await finished(inputId));
105
+ await this.enqueue(callId, () => finished(callId));
104
106
  }
105
- start(input) {
106
- if (this.held.has(input.input_id))
107
- return;
108
- this.held.add(input.input_id);
109
- this.queue = this.queue
110
- .then(() => this.carry(input))
111
- .then((ack) => this.acknowledge(input.input_id, ack))
112
- .catch(logged)
113
- .finally(() => this.held.delete(input.input_id));
107
+ start(call) {
108
+ void this.enqueue(call.input_id, () => this.carry(call));
109
+ }
110
+ enqueue(callId, work) {
111
+ const before = this.queue;
112
+ const carried = this.calls.carry(callId, async () => {
113
+ await before;
114
+ return { result: await work(), returned: () => forget(callId) };
115
+ });
116
+ this.queue = before.then(() => carried);
117
+ return carried;
114
118
  }
115
- async carry(input) {
116
- if ((await pendingInput()) === input.input_id)
117
- return finished(input.input_id);
118
- const answer = await fetch(input.bootstrap);
119
+ async carry(call) {
120
+ if ((await pendingCall()) === call.input_id)
121
+ return finished(call.input_id);
122
+ const answer = await fetch(call.bootstrap);
119
123
  if (!answer.ok)
120
124
  return { refused: `the Kit bootstrap could not be downloaded: ${answer.status}` };
121
125
  const script = Buffer.from(await answer.arrayBuffer());
122
- if (createHash('sha256').update(script).digest('hex') !== input.sha256) {
126
+ if (createHash('sha256').update(script).digest('hex') !== call.sha256) {
123
127
  return { refused: 'the Kit bootstrap does not match its sha256' };
124
128
  }
125
129
  await mkdir(directory(), { recursive: true, mode: 0o700 });
126
130
  const path = join(directory(), 'connect-linux.sh');
127
131
  await writeFile(path, script, { mode: 0o700 });
128
132
  await rm(outcome(), { force: true });
129
- await writeFile(pending(), `${JSON.stringify({ input_id: input.input_id })}\n`, { mode: 0o600 });
130
- return (await rerun(path, input.input_id, input.update_clis ? ['--update-clis'] : [])) ?? (await recorded()) ?? {
133
+ await writeFile(pending(), `${JSON.stringify({ input_id: call.input_id })}\n`, { mode: 0o600 });
134
+ return (await rerun(path, call.input_id, call.update_clis ? ['--update-clis'] : [])) ?? (await recorded()) ?? {
131
135
  refused: 'the Kit bootstrap did not finish',
132
136
  };
133
137
  }
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
138
  }
@@ -0,0 +1,100 @@
1
+ import { loginPath, onLoginPath, withoutProxy } from './clis.js';
2
+ import { killTree } from './scope.js';
3
+ const TERMINAL = 'xterm-256color';
4
+ const SIGNALLED = 128;
5
+ const NO_BASH = "bash is not on the login shell's PATH";
6
+ const LOST = { refused: 'the Kit lost its connection to House' };
7
+ function causeOf(error) {
8
+ return error instanceof Error ? error.message : String(error);
9
+ }
10
+ function failed(cause) {
11
+ process.stderr.write(`kit: a Web Wizard could not start: ${cause}\n`);
12
+ return { refused: `the script could not start: ${cause}` };
13
+ }
14
+ export class WebWizards {
15
+ calls;
16
+ send;
17
+ runs = new Map();
18
+ constructor(calls, send) {
19
+ this.calls = calls;
20
+ this.send = send;
21
+ }
22
+ start(call) {
23
+ void this.calls.carry(call.input_id, () => this.run(call));
24
+ }
25
+ notified(notification) {
26
+ const run = this.runs.get(String(notification.wizard));
27
+ if (run === undefined)
28
+ return;
29
+ if (notification.type === 'wizard_input')
30
+ this.typed(run, String(notification.data));
31
+ if (notification.type === 'wizard_size')
32
+ this.resized(run, { cols: Number(notification.cols), rows: Number(notification.rows) });
33
+ if (notification.type === 'wizard_end')
34
+ this.end(run, {});
35
+ }
36
+ disconnected() {
37
+ for (const run of this.runs.values())
38
+ this.end(run, LOST);
39
+ }
40
+ async run(call) {
41
+ const run = { terminal: null, size: null, typed: [], ended: null, sized: Promise.withResolvers() };
42
+ this.runs.set(call.input_id, run);
43
+ try {
44
+ return { result: await this.ran(call.input_id, call.script, run) };
45
+ }
46
+ finally {
47
+ this.runs.delete(call.input_id);
48
+ }
49
+ }
50
+ async ran(wizard, script, run) {
51
+ let terminal;
52
+ try {
53
+ const { spawn } = await import('@lydell/node-pty');
54
+ const shell = await onLoginPath('bash');
55
+ if (shell === null)
56
+ return failed(NO_BASH);
57
+ const path = await loginPath();
58
+ await run.sized.promise;
59
+ if (run.ended !== null)
60
+ return run.ended;
61
+ terminal = spawn(shell, ['-c', script], {
62
+ name: TERMINAL,
63
+ ...run.size,
64
+ cwd: process.cwd(),
65
+ env: { ...withoutProxy(), PATH: path },
66
+ });
67
+ }
68
+ catch (error) {
69
+ return failed(causeOf(error));
70
+ }
71
+ run.terminal = terminal;
72
+ terminal.onData((data) => this.send({ type: 'wizard_output', wizard, data }));
73
+ for (const data of run.typed.splice(0))
74
+ terminal.write(data);
75
+ const exited = await new Promise((resolve) => terminal.onExit(resolve));
76
+ return run.ended ?? { exit_code: exited.signal ? SIGNALLED + exited.signal : exited.exitCode };
77
+ }
78
+ typed(run, data) {
79
+ if (run.terminal === null)
80
+ run.typed.push(data);
81
+ else
82
+ run.terminal.write(data);
83
+ }
84
+ resized(run, size) {
85
+ run.size = size;
86
+ run.sized.resolve();
87
+ try {
88
+ run.terminal?.resize(size.cols, size.rows);
89
+ }
90
+ catch { }
91
+ }
92
+ end(run, result) {
93
+ if (run.ended !== null)
94
+ return;
95
+ run.ended = result;
96
+ run.sized.resolve();
97
+ if (run.terminal !== null)
98
+ killTree(run.terminal);
99
+ }
100
+ }
package/dist/wire.js CHANGED
@@ -1,6 +1,22 @@
1
+ import { newerThanHouse, updateRequired } from './end.js';
2
+ import { machine } from './placement.js';
1
3
  import { refusalOf } from './refusals.js';
2
- export const KIT_WIRE = 1;
4
+ export const KIT_WIRE = 3;
3
5
  export const KIT_WIRE_HEADER = 'x-house-kit-wire';
4
- export function tooOld(text) {
5
- return refusalOf(text)?.code === 'kit_update_required';
6
+ function newer(text) {
7
+ let body;
8
+ try {
9
+ body = JSON.parse(text);
10
+ }
11
+ catch {
12
+ return null;
13
+ }
14
+ return body?.error?.code === 'kit_newer_than_house' ? body.error : null;
15
+ }
16
+ export function endUnserved(text) {
17
+ if (refusalOf(text)?.code === 'kit_update_required')
18
+ updateRequired();
19
+ const refused = newer(text);
20
+ if (refused !== null)
21
+ newerThanHouse(refused.release, refused.commands[machine()]);
6
22
  }