@agentshouse/kit 0.2.1-c3fc787e93f0e → 0.2.1-c441d29eb63f4

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 (123) hide show
  1. package/README.md +30 -29
  2. package/dist/acp.js +36 -16
  3. package/dist/agents.js +87 -19
  4. package/dist/api.js +5 -5
  5. package/dist/app-git.js +10 -26
  6. package/dist/bootstrap.json +4 -4
  7. package/dist/bridge.js +3 -6
  8. package/dist/calls.js +63 -0
  9. package/dist/chatgpt.js +7 -1
  10. package/dist/clis.js +17 -4
  11. package/dist/connection.js +126 -0
  12. package/dist/conversations.js +399 -153
  13. package/dist/copies.js +77 -50
  14. package/dist/end.js +9 -4
  15. package/dist/events.js +6 -2
  16. package/dist/files.js +123 -37
  17. package/dist/git.js +3 -4
  18. package/dist/home.js +31 -13
  19. package/dist/house-cli.js +286 -0
  20. package/dist/house-main.js +7 -262
  21. package/dist/instructions.js +6 -10
  22. package/dist/kit-cli.js +68 -0
  23. package/dist/kit-main.js +8 -67
  24. package/dist/login.js +34 -11
  25. package/dist/logout.js +0 -2
  26. package/dist/mcp.js +4 -2
  27. package/dist/placement.js +9 -18
  28. package/dist/resident.js +88 -37
  29. package/dist/scope.js +3 -0
  30. package/dist/service.js +23 -1
  31. package/dist/sign-in.js +19 -37
  32. package/dist/skills.js +12 -34
  33. package/dist/transcription.js +53 -22
  34. package/dist/translate.js +2 -8
  35. package/dist/update.js +42 -45
  36. package/dist/web-wizard.js +100 -0
  37. package/dist/wire.js +19 -3
  38. package/dist/work.js +3 -5
  39. package/package.json +7 -6
  40. package/dist/stream.js +0 -77
  41. package/how-we-work.md +0 -23
  42. package/skills/ask-matt/LICENSE +0 -21
  43. package/skills/ask-matt/PHASE-BOUNDARIES.md +0 -55
  44. package/skills/ask-matt/SKILL.md +0 -91
  45. package/skills/ask-matt/agents/openai.yaml +0 -4
  46. package/skills/code-review/LICENSE +0 -21
  47. package/skills/code-review/SKILL.md +0 -89
  48. package/skills/code-review/agents/openai.yaml +0 -3
  49. package/skills/codebase-design/DEEPENING.md +0 -37
  50. package/skills/codebase-design/DESIGN-IT-TWICE.md +0 -44
  51. package/skills/codebase-design/LICENSE +0 -21
  52. package/skills/codebase-design/SKILL.md +0 -116
  53. package/skills/codebase-design/agents/openai.yaml +0 -3
  54. package/skills/diagnosing-bugs/LICENSE +0 -21
  55. package/skills/diagnosing-bugs/SKILL.md +0 -140
  56. package/skills/diagnosing-bugs/agents/openai.yaml +0 -3
  57. package/skills/diagnosing-bugs/scripts/hitl-loop.template.sh +0 -44
  58. package/skills/domain-modeling/ADR-FORMAT.md +0 -47
  59. package/skills/domain-modeling/CONTEXT-FORMAT.md +0 -60
  60. package/skills/domain-modeling/LICENSE +0 -21
  61. package/skills/domain-modeling/SKILL.md +0 -76
  62. package/skills/domain-modeling/agents/openai.yaml +0 -3
  63. package/skills/grill-me/LICENSE +0 -21
  64. package/skills/grill-me/SKILL.md +0 -8
  65. package/skills/grill-me/agents/openai.yaml +0 -4
  66. package/skills/grill-with-docs/LICENSE +0 -21
  67. package/skills/grill-with-docs/SKILL.md +0 -8
  68. package/skills/grill-with-docs/agents/openai.yaml +0 -4
  69. package/skills/grilling/LICENSE +0 -21
  70. package/skills/grilling/SKILL.md +0 -30
  71. package/skills/grilling/agents/openai.yaml +0 -3
  72. package/skills/handoff/LICENSE +0 -21
  73. package/skills/handoff/SKILL.md +0 -17
  74. package/skills/handoff/agents/openai.yaml +0 -4
  75. package/skills/implement/LICENSE +0 -21
  76. package/skills/implement/SKILL.md +0 -16
  77. package/skills/implement/agents/openai.yaml +0 -4
  78. package/skills/improve-codebase-architecture/HTML-REPORT.md +0 -123
  79. package/skills/improve-codebase-architecture/LICENSE +0 -21
  80. package/skills/improve-codebase-architecture/SKILL.md +0 -72
  81. package/skills/improve-codebase-architecture/agents/openai.yaml +0 -4
  82. package/skills/prototype/LICENSE +0 -21
  83. package/skills/prototype/LOGIC.md +0 -67
  84. package/skills/prototype/SKILL.md +0 -28
  85. package/skills/prototype/UI.md +0 -112
  86. package/skills/prototype/agents/openai.yaml +0 -3
  87. package/skills/research/LICENSE +0 -21
  88. package/skills/research/SKILL.md +0 -14
  89. package/skills/research/agents/openai.yaml +0 -3
  90. package/skills/resolving-merge-conflicts/LICENSE +0 -21
  91. package/skills/resolving-merge-conflicts/SKILL.md +0 -16
  92. package/skills/resolving-merge-conflicts/agents/openai.yaml +0 -3
  93. package/skills/tdd/LICENSE +0 -21
  94. package/skills/tdd/SKILL.md +0 -40
  95. package/skills/tdd/agents/openai.yaml +0 -3
  96. package/skills/tdd/mocking.md +0 -59
  97. package/skills/tdd/tests.md +0 -77
  98. package/skills/teach/GLOSSARY-FORMAT.md +0 -35
  99. package/skills/teach/LEARNING-RECORD-FORMAT.md +0 -46
  100. package/skills/teach/LICENSE +0 -21
  101. package/skills/teach/MISSION-FORMAT.md +0 -31
  102. package/skills/teach/RESOURCES-FORMAT.md +0 -32
  103. package/skills/teach/SKILL.md +0 -141
  104. package/skills/teach/agents/openai.yaml +0 -4
  105. package/skills/to-questionnaire/LICENSE +0 -21
  106. package/skills/to-questionnaire/SKILL.md +0 -55
  107. package/skills/to-questionnaire/agents/openai.yaml +0 -4
  108. package/skills/to-spec/LICENSE +0 -21
  109. package/skills/to-spec/SKILL.md +0 -76
  110. package/skills/to-spec/agents/openai.yaml +0 -4
  111. package/skills/to-tickets/LICENSE +0 -21
  112. package/skills/to-tickets/SKILL.md +0 -106
  113. package/skills/to-tickets/agents/openai.yaml +0 -4
  114. package/skills/wait-what/LICENSE +0 -21
  115. package/skills/wait-what/SKILL.md +0 -8
  116. package/skills/wait-what/agents/openai.yaml +0 -4
  117. package/skills/wayfinder/LICENSE +0 -21
  118. package/skills/wayfinder/SKILL.md +0 -129
  119. package/skills/wayfinder/agents/openai.yaml +0 -4
  120. package/skills/writing-for-agents/LICENSE +0 -21
  121. package/skills/writing-for-agents/SKILL-MECHANICS.md +0 -22
  122. package/skills/writing-for-agents/SKILL.md +0 -83
  123. package/skills/writing-for-agents/agents/openai.yaml +0 -3
package/dist/skills.js CHANGED
@@ -1,17 +1,10 @@
1
- import { readFileSync } from 'node:fs';
2
- import { cp, lstat, mkdir, readdir, realpath, rm, symlink, writeFile } from 'node:fs/promises';
1
+ import { cp, lstat, mkdir, realpath, rm, symlink } from 'node:fs/promises';
3
2
  import { homedir } from 'node:os';
4
3
  import { join, relative } from 'node:path';
5
- import { fileURLToPath } from 'node:url';
6
- import { KIT_VERSION } from './clis.js';
4
+ import { listSkills } from '@agentshouse/skills';
5
+ import { KIT_RELEASE } from './clis.js';
7
6
  import { kitHome, readConfiguration, readHome, writeHome } from './home.js';
8
- import { refusalOf } from './refusals.js';
9
- export const HOW_WE_WORK = '/rooms/private/how-we-work.md';
10
- const SKILL_SET = fileURLToPath(new URL('../skills/', import.meta.url));
11
- const HOW_WE_WORK_TEXT = readFileSync(new URL('../how-we-work.md', import.meta.url), 'utf8');
12
7
  const RECORD = 'skill-set.json';
13
- const CREATED = 'how-we-work-created';
14
- const UNWRITABLE = new Set(['room_not_found', 'operation_denied']);
15
8
  function skillsDirectory() {
16
9
  return join(homedir(), '.agents', 'skills');
17
10
  }
@@ -30,23 +23,24 @@ async function present(path) {
30
23
  }
31
24
  }
32
25
  async function install() {
33
- const names = [];
34
- for (const name of (await readdir(SKILL_SET)).sort()) {
35
- if (!(await present(join(skillsDirectory(), name))) && !(await present(join(claudeDirectory(), name)))) {
36
- 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);
37
30
  }
38
31
  }
32
+ const names = placed.map((skill) => skill.name);
39
33
  await writeHome(RECORD, { names });
40
34
  await mkdir(skillsDirectory(), { recursive: true });
41
35
  await mkdir(claudeDirectory(), { recursive: true });
42
36
  const skills = await realpath(skillsDirectory());
43
37
  const claude = await realpath(claudeDirectory());
44
- for (const name of names) {
45
- 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 });
46
40
  if (claude !== skills)
47
41
  await symlink(relative(claude, join(skills, name)), join(claudeDirectory(), name));
48
42
  }
49
- await writeHome(RECORD, { version: KIT_VERSION, names });
43
+ await writeHome(RECORD, { version: KIT_RELEASE, names });
50
44
  }
51
45
  export async function placeSkillSet() {
52
46
  try {
@@ -59,7 +53,7 @@ export async function placeSkillSet() {
59
53
  async function replaceSkillSet() {
60
54
  const accepted = (await readConfiguration()).skills;
61
55
  const installed = await readHome(RECORD);
62
- if (accepted && installed?.version === KIT_VERSION)
56
+ if (accepted && installed?.version === KIT_RELEASE)
63
57
  return;
64
58
  for (const name of installed?.names ?? []) {
65
59
  await rm(join(claudeDirectory(), name), { recursive: true, force: true });
@@ -70,19 +64,3 @@ async function replaceSkillSet() {
70
64
  else
71
65
  await rm(join(kitHome(), RECORD), { force: true });
72
66
  }
73
- export async function createHowWeWork(bridge) {
74
- if (!(await readConfiguration()).skills || (await readHome(RECORD))?.version === undefined)
75
- return;
76
- if (await present(join(kitHome(), CREATED)))
77
- return;
78
- const created = await bridge.tool('edit', { changes: [{ op: 'create', path: HOW_WE_WORK, content: HOW_WE_WORK_TEXT }] });
79
- if (created.isError === true) {
80
- const text = created.content.map((content) => content.text).join('\n');
81
- const refusal = refusalOf(text);
82
- if (UNWRITABLE.has(refusal?.code ?? ''))
83
- return;
84
- if (refusal?.code !== 'edit_conflict' || !refusal.conflicts.includes('path_exists'))
85
- throw new Error(text);
86
- }
87
- await writeFile(join(kitHome(), CREATED), '');
88
- }
@@ -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;
@@ -49,10 +55,10 @@ async function executed(command, args, signal) {
49
55
  function present(path) {
50
56
  return stat(path).then(() => true, () => false);
51
57
  }
52
- async function cpus() {
58
+ async function threads() {
53
59
  const [quota, period] = (await readFile('/sys/fs/cgroup/cpu.max', 'utf8').catch(() => 'max')).split(' ');
54
60
  const allowed = quota === 'max' ? Infinity : Math.ceil(Number(quota) / Number(period));
55
- return Math.min(availableParallelism(), allowed);
61
+ return Math.max(1, Math.floor(Math.min(availableParallelism(), allowed) / 2));
56
62
  }
57
63
  async function sha256(path) {
58
64
  const hash = createHash('sha256');
@@ -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 cpus()), '-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
  }
package/dist/work.js CHANGED
@@ -1,11 +1,11 @@
1
1
  import { randomUUID } from 'node:crypto';
2
2
  import { once } from 'node:events';
3
3
  import { readFileSync } from 'node:fs';
4
- import { mkdir, rm } from 'node:fs/promises';
4
+ import { rm } from 'node:fs/promises';
5
5
  import { createServer } from 'node:net';
6
6
  import { join } from 'node:path';
7
7
  import { RUNNING_JOB } from './events.js';
8
- import { kitHome } from './home.js';
8
+ import { kitHome, socketDirectory } from './home.js';
9
9
  const ENDED_TASK = new Set(['completed', 'failed', 'killed']);
10
10
  const SCHEDULING = new Set(['CronCreate', 'CronDelete', 'ScheduleWakeup']);
11
11
  const QUEUE_LIST = 'house-kit-queue-';
@@ -194,9 +194,7 @@ class CodexWork extends Work {
194
194
  proving = -1;
195
195
  proven = -1;
196
196
  async open(cli) {
197
- const sockets = join(kitHome(), 'bridges');
198
- await mkdir(sockets, { recursive: true, mode: 0o700 });
199
- this.path = join(sockets, `${randomUUID()}.sock`);
197
+ this.path = join(socketDirectory(), `${randomUUID()}.sock`);
200
198
  this.server = createServer((socket) => this.connected(socket));
201
199
  this.server.listen(this.path);
202
200
  await once(this.server, 'listening');
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@agentshouse/kit",
3
- "version": "0.2.1-c3fc787e93f0e",
4
- "description": "House Kit connects an Environment to agents.house.",
3
+ "version": "0.2.1-c441d29eb63f4",
4
+ "description": "Kit connects an Environment to agents.house.",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
@@ -16,18 +16,19 @@
16
16
  "./bootstrap": "./dist/bootstrap.json"
17
17
  },
18
18
  "files": [
19
- "dist",
20
- "how-we-work.md",
21
- "skills"
19
+ "dist"
22
20
  ],
23
21
  "scripts": {
24
22
  "build": "tsc -p tsconfig.build.json && node scripts/bootstrap-manifest.mjs",
25
23
  "engine": "mkdir -p tmp/engine && docker run --rm -v \"$PWD:/kit\" -w /kit alpine:3.24@sha256:294b683cb724975bec92580e1e685676bd4b50bda910ddb8c51d4cabeaec77e6 sh scripts/engine.sh tmp/engine",
24
+ "follow-skills": "node scripts/follow-skills.mjs",
26
25
  "test": "tsc -p tsconfig.json && vitest run"
27
26
  },
28
27
  "dependencies": {
29
28
  "@agentclientprotocol/sdk": "1.7.0",
30
- "@agentshouse/mdmodel": "0.1.0-c68e2039f1ca8",
29
+ "@agentshouse/mdmodel": "0.1.0-cabd61587647f",
30
+ "@agentshouse/skills": "0.1.0-c6411c39c6d0f",
31
+ "@lydell/node-pty": "1.2.0-beta.15",
31
32
  "yaml": "2.9.1"
32
33
  },
33
34
  "peerDependencies": {
package/dist/stream.js DELETED
@@ -1,77 +0,0 @@
1
- import { subscribe } from 'node:diagnostics_channel';
2
- import { finalRefusal, HouseRefusal, retryDelay } from './api.js';
3
- import { end, REPLACED, signInAgain, updateRequired } from './end.js';
4
- import { readEnrolment } from './home.js';
5
- import { relayed } from './relay.js';
6
- import { KIT_WIRE, tooOld } from './wire.js';
7
- const PATH = '/kit/stream';
8
- const SUBPROTOCOL = `house.kit.stream.${KIT_WIRE}`;
9
- const REFUSAL_HEADER = 'x-house-refusal';
10
- function streamUrl(house) {
11
- const url = new URL(PATH, house);
12
- url.protocol = url.protocol === 'https:' ? 'wss:' : 'ws:';
13
- return url;
14
- }
15
- function header(headers, name) {
16
- for (let index = 0; index < headers.length; index += 2) {
17
- if (headers[index].toString('latin1').toLowerCase() === name)
18
- return headers[index + 1].toString('latin1');
19
- }
20
- return '';
21
- }
22
- let refused = null;
23
- subscribe('undici:request:headers', (message) => {
24
- const { request, response } = message;
25
- if (!request.path.endsWith(PATH))
26
- return;
27
- refused = new HouseRefusal(PATH, response.statusCode, header(response.headers, REFUSAL_HEADER) || response.statusText);
28
- });
29
- export function holdStream(handlers) {
30
- let socket = null;
31
- let failures = 0;
32
- const connect = async () => {
33
- const { house, credential } = (await readEnrolment());
34
- refused = null;
35
- const opening = new WebSocket(relayed(streamUrl(house)), {
36
- protocols: [SUBPROTOCOL],
37
- headers: { authorization: `Bearer ${credential}` },
38
- });
39
- let opened = false;
40
- opening.onopen = () => {
41
- opened = true;
42
- failures = 0;
43
- socket = opening;
44
- handlers.opened();
45
- };
46
- opening.onmessage = (event) => {
47
- handlers.frame(JSON.parse(String(event.data)));
48
- };
49
- opening.onerror = () => undefined;
50
- opening.onclose = (event) => {
51
- if (socket === opening)
52
- socket = null;
53
- process.stderr.write(`kit: control stream closed ${event.code} ${event.reason}\n`);
54
- if (event.reason === 'replaced')
55
- end(REPLACED);
56
- if (event.reason === 'credential_rejected' || refused?.status === 401) {
57
- void signInAgain(credential);
58
- return;
59
- }
60
- if (refused !== null && tooOld(refused.text))
61
- updateRequired(house);
62
- if (finalRefusal(refused))
63
- end(refused.message);
64
- // A closed socket reopens in one to three seconds, spread so Kits one restart closed return apart; an opening House refused as retryable or left unanswered backs off on the jittered curve.
65
- setTimeout(() => void connect(), opened ? 1000 + Math.random() * 2000 : retryDelay(failures++));
66
- };
67
- };
68
- void connect();
69
- return {
70
- send(frame) {
71
- if (socket === null || socket.readyState !== WebSocket.OPEN)
72
- return false;
73
- socket.send(JSON.stringify(frame));
74
- return true;
75
- },
76
- };
77
- }
package/how-we-work.md DELETED
@@ -1,23 +0,0 @@
1
- # How we work
2
-
3
- A Room is where information people share is kept; it is not the place for
4
- private information. Work goes into the Room it belongs to, or the First Room
5
- when none is named.
6
-
7
- The skills are already set up; never run `setup-matt-pocock-skills`.
8
-
9
- ## Where skill output goes
10
-
11
- - Glossary (`CONTEXT.md`): `glossary.md`
12
- - Decisions (ADRs): `decisions/NNNN-<slug>.md`
13
- - Plan (spec): `projects/<name>/plan.md`
14
- - Tasks (tickets): `projects/<name>/tasks/NN-<slug>.md`, with a
15
- `Status:` line (`needs-triage`, `needs-info`, `ready-for-agent`,
16
- `ready-for-human`, `wontfix`), a `Blocked by:` line and comments under
17
- `## Comments`
18
- - Map (Wayfinding): `projects/<name>/map.md`, its tasks under
19
- `tasks/` with `Type:`, `Status: claimed|resolved` and `Blocked by:` lines
20
- - Research: `research/<slug>.md`
21
- - Questionnaires: `questionnaires/<slug>.md`
22
- - Learning: `learning/<topic>/`
23
- - Prototype: one HTML file with every variant on one page.