@agentshouse/kit 0.2.1-cf6326dfa5c3e → 0.2.1-cf6a92e13f031

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 (130) hide show
  1. package/README.md +22 -22
  2. package/dist/acp.js +2 -2
  3. package/dist/agents.js +2 -2
  4. package/dist/api.js +5 -5
  5. package/dist/bootstrap.json +4 -4
  6. package/dist/bridge.js +1 -1
  7. package/dist/{inputs.js → calls.js} +20 -20
  8. package/dist/clis.js +6 -3
  9. package/dist/{stream.js → connection.js} +30 -27
  10. package/dist/conversations.js +220 -105
  11. package/dist/copies.js +15 -29
  12. package/dist/end.js +6 -2
  13. package/dist/events.js +2 -2
  14. package/dist/files.js +123 -37
  15. package/dist/git.js +1 -1
  16. package/dist/house-cli.js +81 -86
  17. package/dist/instructions.js +28 -8
  18. package/dist/kit-cli.js +2 -2
  19. package/dist/login.js +1 -3
  20. package/dist/mcp.js +4 -2
  21. package/dist/placement.js +11 -2
  22. package/dist/resident.js +38 -32
  23. package/dist/scope.js +3 -0
  24. package/dist/service.js +1 -1
  25. package/dist/sign-in.js +19 -19
  26. package/dist/skills.js +12 -93
  27. package/dist/transcription.js +51 -20
  28. package/dist/update.js +32 -32
  29. package/dist/web-wizard.js +100 -0
  30. package/dist/wire.js +19 -3
  31. package/package.json +6 -6
  32. package/how-we-work.md +0 -33
  33. package/skills/ask-matt/LICENSE +0 -21
  34. package/skills/ask-matt/PHASE-BOUNDARIES.md +0 -55
  35. package/skills/ask-matt/SKILL.md +0 -97
  36. package/skills/ask-matt/agents/openai.yaml +0 -5
  37. package/skills/code-review/LICENSE +0 -21
  38. package/skills/code-review/SKILL.md +0 -89
  39. package/skills/code-review/agents/openai.yaml +0 -3
  40. package/skills/codebase-design/DEEPENING.md +0 -37
  41. package/skills/codebase-design/DESIGN-IT-TWICE.md +0 -44
  42. package/skills/codebase-design/LICENSE +0 -21
  43. package/skills/codebase-design/SKILL.md +0 -114
  44. package/skills/codebase-design/agents/openai.yaml +0 -3
  45. package/skills/diagnosing-bugs/LICENSE +0 -21
  46. package/skills/diagnosing-bugs/SKILL.md +0 -138
  47. package/skills/diagnosing-bugs/agents/openai.yaml +0 -3
  48. package/skills/diagnosing-bugs/scripts/hitl-loop.template.sh +0 -44
  49. package/skills/domain-modeling/ADR-FORMAT.md +0 -47
  50. package/skills/domain-modeling/GLOSSARY-FORMAT.md +0 -60
  51. package/skills/domain-modeling/LICENSE +0 -21
  52. package/skills/domain-modeling/SKILL.md +0 -74
  53. package/skills/domain-modeling/agents/openai.yaml +0 -3
  54. package/skills/grill-me/LICENSE +0 -21
  55. package/skills/grill-me/SKILL.md +0 -7
  56. package/skills/grill-me/agents/openai.yaml +0 -5
  57. package/skills/grill-with-docs/LICENSE +0 -21
  58. package/skills/grill-with-docs/SKILL.md +0 -7
  59. package/skills/grill-with-docs/agents/openai.yaml +0 -5
  60. package/skills/grilling/LICENSE +0 -21
  61. package/skills/grilling/SKILL.md +0 -30
  62. package/skills/grilling/agents/openai.yaml +0 -3
  63. package/skills/handoff/LICENSE +0 -21
  64. package/skills/handoff/SKILL.md +0 -16
  65. package/skills/handoff/agents/openai.yaml +0 -5
  66. package/skills/implement/LICENSE +0 -21
  67. package/skills/implement/SKILL.md +0 -17
  68. package/skills/implement/agents/openai.yaml +0 -5
  69. package/skills/implement-spec/LICENSE +0 -21
  70. package/skills/implement-spec/SKILL.md +0 -40
  71. package/skills/implement-spec/agents/openai.yaml +0 -5
  72. package/skills/improve-codebase-architecture/HTML-REPORT.md +0 -123
  73. package/skills/improve-codebase-architecture/LICENSE +0 -21
  74. package/skills/improve-codebase-architecture/SKILL.md +0 -71
  75. package/skills/improve-codebase-architecture/agents/openai.yaml +0 -5
  76. package/skills/pr/CREDITS.md +0 -3
  77. package/skills/pr/LICENSE +0 -21
  78. package/skills/pr/SKILL.md +0 -170
  79. package/skills/pr/agents/openai.yaml +0 -3
  80. package/skills/prototype/LICENSE +0 -21
  81. package/skills/prototype/LOGIC.md +0 -67
  82. package/skills/prototype/SKILL.md +0 -26
  83. package/skills/prototype/UI.md +0 -112
  84. package/skills/prototype/agents/openai.yaml +0 -3
  85. package/skills/research/LICENSE +0 -21
  86. package/skills/research/SKILL.md +0 -12
  87. package/skills/research/agents/openai.yaml +0 -3
  88. package/skills/retro/LICENSE +0 -21
  89. package/skills/retro/SKILL.md +0 -44
  90. package/skills/retro/agents/openai.yaml +0 -5
  91. package/skills/tdd/LICENSE +0 -21
  92. package/skills/tdd/SKILL.md +0 -38
  93. package/skills/tdd/agents/openai.yaml +0 -3
  94. package/skills/tdd/mocking.md +0 -59
  95. package/skills/tdd/tests.md +0 -77
  96. package/skills/teach/GLOSSARY-FORMAT.md +0 -35
  97. package/skills/teach/LEARNING-RECORD-FORMAT.md +0 -46
  98. package/skills/teach/LICENSE +0 -21
  99. package/skills/teach/MISSION-FORMAT.md +0 -31
  100. package/skills/teach/RESOURCES-FORMAT.md +0 -32
  101. package/skills/teach/SKILL.md +0 -140
  102. package/skills/teach/agents/openai.yaml +0 -5
  103. package/skills/to-questionnaire/LICENSE +0 -21
  104. package/skills/to-questionnaire/SKILL.md +0 -54
  105. package/skills/to-questionnaire/agents/openai.yaml +0 -5
  106. package/skills/to-spec/LICENSE +0 -21
  107. package/skills/to-spec/SKILL.md +0 -75
  108. package/skills/to-spec/agents/openai.yaml +0 -5
  109. package/skills/to-tickets/LICENSE +0 -21
  110. package/skills/to-tickets/SKILL.md +0 -105
  111. package/skills/to-tickets/agents/openai.yaml +0 -5
  112. package/skills/triage/AGENT-BRIEF.md +0 -207
  113. package/skills/triage/LICENSE +0 -21
  114. package/skills/triage/OUT-OF-SCOPE.md +0 -105
  115. package/skills/triage/SKILL.md +0 -112
  116. package/skills/triage/agents/openai.yaml +0 -5
  117. package/skills/wait-what/LICENSE +0 -21
  118. package/skills/wait-what/SKILL.md +0 -7
  119. package/skills/wait-what/agents/openai.yaml +0 -5
  120. package/skills/wayfinder/LICENSE +0 -21
  121. package/skills/wayfinder/SKILL.md +0 -128
  122. package/skills/wayfinder/agents/openai.yaml +0 -5
  123. package/skills/wizard/LICENSE +0 -21
  124. package/skills/wizard/SKILL.md +0 -44
  125. package/skills/wizard/agents/openai.yaml +0 -3
  126. package/skills/wizard/template.sh +0 -223
  127. package/skills/writing-for-agents/LICENSE +0 -21
  128. package/skills/writing-for-agents/SKILL-MECHANICS.md +0 -22
  129. package/skills/writing-for-agents/SKILL.md +0 -81
  130. package/skills/writing-for-agents/agents/openai.yaml +0 -3
@@ -1,12 +1,32 @@
1
+ import { agentInstructions } from '@agentshouse/skills';
1
2
  import { HOUSE_REF } from './git.js';
2
- import { readHowWeWork } from './skills.js';
3
- const SOURCE_LINE = "From House:";
4
- const HOUSE_LINE = "Work with House through the `house` CLI: run `house --help`, and `house find_command` for House's guides and formats.";
5
- const FILE_LINE = 'To give the User a file, upload it with `house upload` and link it; for an App, a Site or a website, follow `house find_command \'{"query":"app"}\'`. Never start a server.';
6
- const READ_LINE = "Optional per-Room instructions: `/rooms/private/rooms/<handle>/AGENTS.md`.";
7
- const WAIT_LINE = 'To get what another Agent will write into a Room, `create_trigger` on where it will land with a `conversation` action, then end your turn: this conversation continues when it lands.';
8
- const COPIES_LINE = `House Local copies; before work run \`house fetch\` and rebase onto \`${HOUSE_REF}\`; after it commit, then \`house push\`:`;
3
+ const HOW_WE_WORK = '/rooms/private/how-we-work.md';
4
+ const UNREADABLE = /^(?:\S+: )?(?:path_not_found|room_not_found|operation_denied)\b/;
5
+ const FAILED = /^exit: [1-9]\d*$/;
6
+ const CUT = /^stderr: shell: output_cut (\d+) of \d+ bytes; continue with: (.+)$/;
7
+ function cutOf(lines) {
8
+ const cut = CUT.exec(lines[0] ?? '');
9
+ return cut !== null && Buffer.byteLength(lines.slice(1).join('\n')) === Number(cut[1]) ? cut : null;
10
+ }
11
+ async function readHowWeWork(bridge) {
12
+ let document = '';
13
+ for (let command = `cat ${HOW_WE_WORK}`; command !== undefined;) {
14
+ const read = await bridge.tool('shell', { command });
15
+ const text = read.content.map((content) => content.text).join('\n');
16
+ const lines = text.split('\n');
17
+ if (read.isError === true || (FAILED.test(lines[0] ?? '') && lines[1]?.startsWith('stderr: '))) {
18
+ const refusal = read.isError === true ? text : lines.slice(1).join('\n').replace(/^stderr: /gm, '');
19
+ if (UNREADABLE.test(refusal))
20
+ return '';
21
+ throw new Error(refusal);
22
+ }
23
+ const cut = cutOf(lines);
24
+ document += lines.slice(cut === null ? 0 : 1).join('\n');
25
+ command = cut?.[2];
26
+ }
27
+ return document;
28
+ }
9
29
  export async function instructions(bridge, base, copies) {
10
- const lines = [SOURCE_LINE, HOUSE_LINE, FILE_LINE, READ_LINE, WAIT_LINE, ...(copies.length === 0 ? [] : [COPIES_LINE, ...copies])];
30
+ const lines = agentInstructions(HOUSE_REF, copies);
11
31
  return [lines.join('\n'), base, (await readHowWeWork(bridge)).replace(/\n$/, '')].filter((part) => part !== '').join('\n\n');
12
32
  }
package/dist/kit-cli.js CHANGED
@@ -11,7 +11,7 @@ const COMMANDS = new Map([
11
11
  'logout',
12
12
  {
13
13
  usage: 'usage: kit logout',
14
- about: "disconnects this computer, stops House Kit and ends your own agent's connection",
14
+ about: "disconnects this computer, stops the Kit process and ends your own agent's connection",
15
15
  operands: 0,
16
16
  run: logout,
17
17
  },
@@ -20,7 +20,7 @@ const COMMANDS = new Map([
20
20
  'resident',
21
21
  {
22
22
  usage: 'usage: kit resident',
23
- about: "keeps this Environment connected; House Kit's service runs it",
23
+ about: "keeps this Environment connected; Kit's service runs it",
24
24
  operands: 0,
25
25
  run: resident,
26
26
  },
package/dist/login.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import { spawn } from 'node:child_process';
2
2
  import { createHash, randomBytes } from 'node:crypto';
3
- import { hostname } from 'node:os';
4
3
  import { parseArgs } from 'node:util';
5
4
  import { HouseRefusal, post, retrying } from './api.js';
6
5
  import { placeAppGit } from './app-git.js';
@@ -91,13 +90,12 @@ export async function login(argv) {
91
90
  let named = environment;
92
91
  let exchanged;
93
92
  if (values.code !== undefined) {
94
- exchanged = await post(house, '/kit/token', { code: values.code, label: hostname() });
93
+ exchanged = await post(house, '/kit/token', { code: values.code });
95
94
  }
96
95
  else {
97
96
  held = ownAgent !== null && ownAgent.house === house && (await accepted(house, ownAgent.credential));
98
97
  const verifier = randomBytes(32).toString('base64url');
99
98
  const start = () => retrying(() => post(house, '/kit', {
100
- label: hostname(),
101
99
  ...(named === undefined
102
100
  ? { act: 'new_environment', ...(replaces === undefined ? {} : { replaces }) }
103
101
  : { act: 'existing_environment', environment_id: named }),
package/dist/mcp.js CHANGED
@@ -1,8 +1,10 @@
1
1
  import { randomUUID } from 'node:crypto';
2
- import { KIT_VERSION } from './clis.js';
2
+ import { KIT_RELEASE } from './clis.js';
3
3
  import { relayed } from './relay.js';
4
4
  const MCP_PROTOCOL_VERSION = '2026-07-28';
5
5
  export const UNREACHABLE = 'House is unreachable; call again in a minute';
6
+ export class Unsettled extends Error {
7
+ }
6
8
  export function rpc(method, params) {
7
9
  return { jsonrpc: '2.0', id: randomUUID(), method, params };
8
10
  }
@@ -13,7 +15,7 @@ export function mcpBody(message, operation) {
13
15
  ...message.params,
14
16
  _meta: {
15
17
  'io.modelcontextprotocol/protocolVersion': MCP_PROTOCOL_VERSION,
16
- 'io.modelcontextprotocol/clientInfo': { name: '@agentshouse/kit', version: KIT_VERSION },
18
+ 'io.modelcontextprotocol/clientInfo': { name: '@agentshouse/kit', version: KIT_RELEASE },
17
19
  'io.modelcontextprotocol/clientCapabilities': {},
18
20
  ...(operation === null ? {} : { 'agents.house/agent-operation': operation }),
19
21
  },
package/dist/placement.js CHANGED
@@ -18,9 +18,9 @@ export async function updatesItself() {
18
18
  // sudo answers at once, so ten seconds only bounds a stuck sudo.
19
19
  return (await run('sudo', ['-n', 'true'], 10_000)).status === 0;
20
20
  }
21
- export function installCommand() {
21
+ function recorded(name) {
22
22
  try {
23
- return readFileSync(join(kitHome(), 'install-command'), 'utf8').trim();
23
+ return readFileSync(join(kitHome(), name), 'utf8').trim();
24
24
  }
25
25
  catch (error) {
26
26
  if (error.code === 'ENOENT')
@@ -28,3 +28,12 @@ export function installCommand() {
28
28
  throw error;
29
29
  }
30
30
  }
31
+ export function installCommand() {
32
+ return recorded('install-command');
33
+ }
34
+ export function machine() {
35
+ const placed = recorded('placement');
36
+ if (placed === 'container' || placed === 'server' || placed === 'windows')
37
+ return placed;
38
+ return process.platform === 'darwin' ? 'macos' : 'linux';
39
+ }
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
14
  import { agentBase, enrolled, forgetRestart, kitHome, ownerLock, ownerSocket, restartAsked } from './home.js';
15
- import { Inputs } from './inputs.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 {
@@ -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/scope.js CHANGED
@@ -4,6 +4,7 @@ import { join } from 'node:path';
4
4
  const LISTING_BYTES = 1 << 28;
5
5
  const CGROUPS = '/sys/fs/cgroup';
6
6
  const GONE = new Set(['ENOENT', 'ESRCH']);
7
+ const EXITED = new Set(['Z', 'X']);
7
8
  function failure(error) {
8
9
  return error.code ?? '';
9
10
  }
@@ -24,6 +25,8 @@ function read(pid) {
24
25
  try {
25
26
  const stat = readFileSync(`/proc/${pid}/stat`, 'utf8');
26
27
  const fields = stat.slice(stat.lastIndexOf(')') + 2).split(' ');
28
+ if (EXITED.has(fields[0]))
29
+ return null;
27
30
  const command = readFileSync(`/proc/${pid}/cmdline`, 'utf8').replaceAll('\0', ' ');
28
31
  return { parent: Number(fields[1]), session: fields[3], command };
29
32
  }
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
@@ -15,44 +15,44 @@ function endOf(signal) {
15
15
  export class SignIns {
16
16
  house;
17
17
  agents;
18
- inputs;
19
- constructor(house, agents, inputs) {
18
+ calls;
19
+ constructor(house, agents, calls) {
20
20
  this.house = house;
21
21
  this.agents = agents;
22
- this.inputs = inputs;
22
+ this.calls = calls;
23
23
  }
24
- start(input) {
25
- void this.inputs.carry(input.input_id, () => this.signIn(input));
24
+ start(call) {
25
+ void this.calls.carry(call.input_id, () => this.signIn(call));
26
26
  }
27
- async signIn(input) {
27
+ async signIn(call) {
28
28
  const ending = new AbortController();
29
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.
30
- const timer = setTimeout(() => ending.abort(), input.ends_in * 1000);
31
- 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)]);
32
32
  clearTimeout(timer);
33
33
  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) };
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) };
36
36
  }
37
- async signedIn(input, signal) {
38
- await this.login(input, signal);
37
+ async signedIn(call, signal) {
38
+ await this.login(call, signal);
39
39
  if (!signal.aborted)
40
- await this.agents.recheck(input.cli, signal);
40
+ await this.agents.recheck(call.cli, signal);
41
41
  return false;
42
42
  }
43
- async login(input, signal) {
43
+ async login(call, signal) {
44
44
  let cli;
45
45
  try {
46
- cli = await this.agents.located(input.cli, signal);
46
+ cli = await this.agents.located(call.cli, signal);
47
47
  }
48
48
  catch (error) {
49
49
  if (!signal.aborted)
50
- 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`);
51
51
  return;
52
52
  }
53
53
  if (signal.aborted)
54
54
  return;
55
- const login = CLIS[input.cli].login;
55
+ const login = CLIS[call.cli].login;
56
56
  const child = spawn(cli, login.args, {
57
57
  stdio: ['pipe', 'pipe', 'pipe'],
58
58
  detached: true,
@@ -84,7 +84,7 @@ export class SignIns {
84
84
  return;
85
85
  held = true;
86
86
  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) => {
87
+ void holdSecretInput(this.house, call.input_id, steps, running).then((content) => {
88
88
  if (!running())
89
89
  return;
90
90
  if (content === null)
@@ -101,6 +101,6 @@ export class SignIns {
101
101
  });
102
102
  signal.removeEventListener('abort', stop);
103
103
  if (failed !== null && !signal.aborted)
104
- 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`);
105
105
  }
106
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
+ }