@agentshouse/kit 0.2.1-cf110d15f69c8 → 0.2.1-cfb7b543f2af6

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 (84) hide show
  1. package/README.md +11 -10
  2. package/dist/agents.js +72 -6
  3. package/dist/api.js +5 -1
  4. package/dist/bootstrap.json +4 -4
  5. package/dist/chatgpt.js +32 -0
  6. package/dist/clis.js +10 -3
  7. package/dist/conversations.js +11 -1
  8. package/dist/copies.js +18 -8
  9. package/dist/end.js +4 -0
  10. package/dist/files.js +7 -1
  11. package/dist/git.js +11 -8
  12. package/dist/home.js +41 -4
  13. package/dist/house-cli.js +291 -0
  14. package/dist/house-main.js +7 -206
  15. package/dist/instructions.js +2 -27
  16. package/dist/kit-cli.js +68 -0
  17. package/dist/kit-main.js +8 -22
  18. package/dist/login.js +36 -27
  19. package/dist/placement.js +48 -0
  20. package/dist/relay.js +1 -1
  21. package/dist/resident.js +8 -4
  22. package/dist/skills.js +81 -12
  23. package/dist/stream.js +62 -13
  24. package/dist/transcription.js +3 -3
  25. package/dist/update.js +28 -6
  26. package/dist/wire.js +6 -0
  27. package/how-we-work.md +13 -3
  28. package/package.json +2 -1
  29. package/skills/ask-matt/SKILL.md +17 -11
  30. package/skills/ask-matt/agents/openai.yaml +1 -0
  31. package/skills/code-review/SKILL.md +5 -5
  32. package/skills/codebase-design/DESIGN-IT-TWICE.md +1 -1
  33. package/skills/codebase-design/SKILL.md +0 -2
  34. package/skills/diagnosing-bugs/SKILL.md +2 -4
  35. package/skills/domain-modeling/{CONTEXT-FORMAT.md → GLOSSARY-FORMAT.md} +10 -10
  36. package/skills/domain-modeling/SKILL.md +12 -14
  37. package/skills/grill-me/SKILL.md +1 -2
  38. package/skills/grill-me/agents/openai.yaml +1 -0
  39. package/skills/grill-with-docs/SKILL.md +1 -2
  40. package/skills/grill-with-docs/agents/openai.yaml +1 -0
  41. package/skills/grilling/SKILL.md +2 -2
  42. package/skills/handoff/SKILL.md +2 -3
  43. package/skills/handoff/agents/openai.yaml +1 -0
  44. package/skills/implement/SKILL.md +5 -4
  45. package/skills/implement/agents/openai.yaml +1 -0
  46. package/skills/implement-spec/SKILL.md +40 -0
  47. package/skills/implement-spec/agents/openai.yaml +5 -0
  48. package/skills/improve-codebase-architecture/SKILL.md +6 -7
  49. package/skills/improve-codebase-architecture/agents/openai.yaml +1 -0
  50. package/skills/pr/CREDITS.md +3 -0
  51. package/skills/pr/LICENSE +21 -0
  52. package/skills/pr/SKILL.md +170 -0
  53. package/skills/pr/agents/openai.yaml +3 -0
  54. package/skills/prototype/SKILL.md +0 -2
  55. package/skills/research/SKILL.md +0 -2
  56. package/skills/retro/LICENSE +21 -0
  57. package/skills/retro/SKILL.md +44 -0
  58. package/skills/retro/agents/openai.yaml +5 -0
  59. package/skills/tdd/SKILL.md +2 -4
  60. package/skills/teach/SKILL.md +3 -4
  61. package/skills/teach/agents/openai.yaml +1 -0
  62. package/skills/to-questionnaire/SKILL.md +1 -2
  63. package/skills/to-questionnaire/agents/openai.yaml +1 -0
  64. package/skills/to-spec/SKILL.md +1 -2
  65. package/skills/to-spec/agents/openai.yaml +1 -0
  66. package/skills/to-tickets/SKILL.md +3 -4
  67. package/skills/to-tickets/agents/openai.yaml +1 -0
  68. package/skills/triage/AGENT-BRIEF.md +207 -0
  69. package/skills/triage/LICENSE +21 -0
  70. package/skills/triage/OUT-OF-SCOPE.md +105 -0
  71. package/skills/triage/SKILL.md +112 -0
  72. package/skills/triage/agents/openai.yaml +5 -0
  73. package/skills/wait-what/SKILL.md +2 -3
  74. package/skills/wait-what/agents/openai.yaml +1 -0
  75. package/skills/wayfinder/SKILL.md +5 -6
  76. package/skills/wayfinder/agents/openai.yaml +1 -0
  77. package/skills/wizard/LICENSE +21 -0
  78. package/skills/wizard/SKILL.md +44 -0
  79. package/skills/wizard/agents/openai.yaml +3 -0
  80. package/skills/wizard/template.sh +223 -0
  81. package/skills/writing-for-agents/SKILL.md +0 -2
  82. package/skills/resolving-merge-conflicts/SKILL.md +0 -16
  83. package/skills/resolving-merge-conflicts/agents/openai.yaml +0 -3
  84. /package/skills/{resolving-merge-conflicts → implement-spec}/LICENSE +0 -0
package/dist/login.js CHANGED
@@ -1,17 +1,17 @@
1
1
  import { spawn } from 'node:child_process';
2
2
  import { createHash, randomBytes } from 'node:crypto';
3
3
  import { hostname } from 'node:os';
4
- import { delimiter, dirname } from 'node:path';
5
4
  import { parseArgs } from 'node:util';
6
- import { post, retrying } from './api.js';
5
+ import { HouseRefusal, post, retrying } from './api.js';
7
6
  import { placeAppGit } from './app-git.js';
8
- import { allowHouseInCodex, loginPath } from './clis.js';
9
- import { forgetOwnAgent, readDisconnected, readEnrolment, readOwnAgent, writeEnrolment, writeOwnAgent } from './home.js';
7
+ import { writeCodexRule } from './clis.js';
8
+ import { forgetDisconnected, forgetOwnAgent, readDisconnected, readEnrolment, readOwnAgent, writeEnrolment, writeOwnAgent, } from './home.js';
10
9
  import { callHouse, rpc } from './mcp.js';
10
+ import { refusalOf } from './refusals.js';
11
11
  import { selectRelay } from './relay.js';
12
12
  import { startService } from './service.js';
13
13
  import { placeSkillSet } from './skills.js';
14
- const DEFAULT_HOUSE = 'https://agents.house';
14
+ export const DEFAULT_HOUSE = 'https://agents.house';
15
15
  const OPENER = process.platform === 'darwin' ? 'open' : 'xdg-open';
16
16
  // Polling every two seconds brings the User's confirmation to the waiting Kit moments after they give it.
17
17
  const POLL_INTERVAL_MS = 2000;
@@ -20,7 +20,7 @@ function open(link) {
20
20
  .on('error', () => undefined)
21
21
  .unref();
22
22
  }
23
- async function accepted(house, credential) {
23
+ export async function accepted(house, credential) {
24
24
  const checked = await callHouse(house, credential, rpc('tools/list', {}));
25
25
  if (checked.status === 200)
26
26
  return true;
@@ -28,13 +28,17 @@ async function accepted(house, credential) {
28
28
  return false;
29
29
  throw new Error(`House answered ${checked.status} when Kit checked this computer's own agent's connection: ${checked.text}`);
30
30
  }
31
- const USAGE = `usage: kit login [--house <origin>] [--environment <id>] [--rooms <ref>[,<ref>...] | --no-private] [--code <code>]
31
+ const USAGE = `usage: kit login [--house <origin>] [--environment <id>] [--rooms <ref>[,<ref>...] | --no-private]
32
+ kit login [--house <origin>] --code <code>
32
33
  --house <origin> the House to connect to, ${DEFAULT_HOUSE} unless one is stored
33
34
  --environment <id> reconnect this Environment
34
35
  --rooms <ref>[,<ref>...] give this Environment only these Rooms
35
36
  --no-private give this Environment every Room but your Private Room
36
37
  --code <code> connect this machine with a login code
37
38
  `;
39
+ function gone(error) {
40
+ return error instanceof HouseRefusal && refusalOf(error.text)?.code === 'kit_environment_not_found';
41
+ }
38
42
  function chosenRooms(rooms, noPrivate) {
39
43
  if (rooms !== undefined && noPrivate)
40
44
  throw new Error('--rooms and --no-private are two choices of Rooms; pass one');
@@ -73,7 +77,8 @@ export async function login(argv) {
73
77
  selectRelay(relay);
74
78
  const house = values.house ?? enrolled?.house ?? DEFAULT_HOUSE;
75
79
  const replaces = process.env.HOUSE_KIT_REPLACES;
76
- const environment = replaces === undefined ? (values.environment ?? (enrolled?.house === house ? enrolled.environment : undefined)) : undefined;
80
+ const remembered = replaces === undefined && values.environment === undefined && enrolled?.house === house ? enrolled.environment : undefined;
81
+ const environment = replaces === undefined ? (values.environment ?? remembered) : undefined;
77
82
  const ownAgent = await readOwnAgent();
78
83
  let held = false;
79
84
  let exchanged;
@@ -83,47 +88,51 @@ export async function login(argv) {
83
88
  else {
84
89
  held = ownAgent !== null && ownAgent.house === house && (await accepted(house, ownAgent.credential));
85
90
  const verifier = randomBytes(32).toString('base64url');
86
- const started = await retrying(() => post(house, '/kit', {
91
+ const start = (named) => retrying(() => post(house, '/kit', {
87
92
  label: hostname(),
88
- ...(environment === undefined
93
+ ...(named === undefined
89
94
  ? { act: 'new_environment', ...(replaces === undefined ? {} : { replaces }) }
90
- : { act: 'existing_environment', environment_id: environment }),
95
+ : { act: 'existing_environment', environment_id: named }),
91
96
  ...rooms,
92
97
  code_challenge: createHash('sha256').update(verifier).digest('base64url'),
93
98
  ...(held ? {} : { headless: true }),
94
99
  }));
100
+ let started;
101
+ try {
102
+ started = await start(environment);
103
+ }
104
+ catch (error) {
105
+ if (remembered === undefined || !gone(error))
106
+ throw error;
107
+ await forgetDisconnected();
108
+ process.stdout.write(`House no longer holds Environment ${remembered}; connecting this computer as a new one.\n`);
109
+ started = await start(undefined);
110
+ }
95
111
  process.stdout.write(`Open this link and confirm: ${started.start_url}\n`);
96
112
  open(started.start_url);
97
113
  exchanged = await retrying(() => post(house, '/kit/token', { login: started.login, code_verifier: verifier }), undefined, () => POLL_INTERVAL_MS);
98
114
  }
99
- try {
100
- await placeSkillSet();
101
- }
102
- catch (error) {
103
- process.stderr.write(`kit: the skills could not be placed: ${error.message}\n`);
104
- }
105
- try {
106
- const shell = await loginPath().catch(() => '');
107
- await allowHouseInCodex([dirname(process.execPath), process.env.PATH ?? '', shell].join(delimiter));
108
- }
109
- catch (error) {
110
- process.stderr.write(`kit: Codex's rule for house could not be written: ${error.message}\n`);
111
- }
115
+ await placeSkillSet();
116
+ await writeCodexRule().catch((error) => process.stderr.write(`kit: ${error.message}\n`));
117
+ const relayRecord = relay === undefined ? {} : { relay };
112
118
  await writeEnrolment({
113
119
  house,
114
- ...(relay === undefined ? {} : { relay }),
120
+ ...relayRecord,
115
121
  environment: exchanged.environment,
116
122
  credential: exchanged.credential,
117
123
  });
118
124
  process.stdout.write(`Environment ${exchanged.environment} is connected to ${house}.\n`);
119
125
  if (exchanged.headless_credential !== undefined) {
120
- await writeOwnAgent({ house, user: exchanged.user, credential: exchanged.headless_credential });
126
+ await writeOwnAgent({ house, ...relayRecord, user: exchanged.user, credential: exchanged.headless_credential });
121
127
  }
122
128
  else if (held && ownAgent !== null && ownAgent.user !== exchanged.user) {
123
129
  await forgetOwnAgent();
124
130
  process.stdout.write("This computer's own agent was another User's; run kit login again to connect it to you.\n");
125
131
  }
126
- await placeAppGit(ownAgent, await readOwnAgent());
132
+ else if (held && ownAgent !== null) {
133
+ await writeOwnAgent({ house, ...relayRecord, user: ownAgent.user, credential: ownAgent.credential });
134
+ }
135
+ await placeAppGit(ownAgent, await readOwnAgent()).catch((error) => process.stderr.write(`kit: ${error.message}\n`));
127
136
  try {
128
137
  startService();
129
138
  }
@@ -0,0 +1,48 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { run } from './clis.js';
4
+ import { kitHome } from './home.js';
5
+ import { relayOrigin } from './relay.js';
6
+ export function service() {
7
+ if (process.platform !== 'linux' || !process.env.INVOCATION_ID)
8
+ return null;
9
+ return process.env.MANAGERPID ? 'user' : 'system';
10
+ }
11
+ export function throughSudo() {
12
+ return service() === 'system' && process.getuid() !== 0;
13
+ }
14
+ export async function updatesItself() {
15
+ if (service() === null)
16
+ return false;
17
+ if (!throughSudo())
18
+ return true;
19
+ // sudo answers at once, so ten seconds only bounds a stuck sudo.
20
+ return (await run('sudo', ['-n', 'true'], 10_000)).status === 0;
21
+ }
22
+ function installed() {
23
+ try {
24
+ return readFileSync(join(kitHome(), 'placement'), 'utf8').trim();
25
+ }
26
+ catch (error) {
27
+ if (error.code === 'ENOENT')
28
+ return null;
29
+ throw error;
30
+ }
31
+ }
32
+ function entries(house) {
33
+ const host = new URL(house).host;
34
+ const relay = relayOrigin();
35
+ if (relay === undefined)
36
+ return [`curl -fsSL ${host}/kit | sh`, `irm ${host}/kit.ps1 | iex`];
37
+ const entry = `${relay}/${host}/kit`;
38
+ return [`curl -fsSL ${entry} | HOUSE_KIT_RELAY=${relay} sh`, `$env:HOUSE_KIT_RELAY='${relay}'; irm ${entry}.ps1 | iex`];
39
+ }
40
+ export function installCommand(house) {
41
+ const [shell, windows] = entries(house);
42
+ const placement = installed();
43
+ if (placement === 'native')
44
+ return shell;
45
+ if (placement === 'server')
46
+ return `${shell} -s -- --linux`;
47
+ return `${shell} -s -- --container, or ${windows} on Windows`;
48
+ }
package/dist/relay.js CHANGED
@@ -2,7 +2,7 @@ let selected;
2
2
  export function selectRelay(relay) {
3
3
  selected = relay === undefined || relay === '' ? null : relay;
4
4
  }
5
- function relayOrigin() {
5
+ export function relayOrigin() {
6
6
  if (selected !== undefined)
7
7
  return selected ?? undefined;
8
8
  const ambient = process.env.HOUSE_KIT_RELAY;
package/dist/resident.js CHANGED
@@ -7,7 +7,7 @@ import { fileURLToPath } from 'node:url';
7
7
  import { Agents } from './agents.js';
8
8
  import { house } from './api.js';
9
9
  import { received } from './bridge.js';
10
- import { Conversations } from './conversations.js';
10
+ import { CONVERSATION_INPUTS, Conversations } from './conversations.js';
11
11
  import { LocalCopies } from './copies.js';
12
12
  import { restart } from './end.js';
13
13
  import { agentBase, enrolled, forgetRestart, kitHome, restartAsked } from './home.js';
@@ -84,7 +84,7 @@ export async function resident() {
84
84
  await placeSkillSet();
85
85
  await mkdir(agentBase(), { recursive: true });
86
86
  process.env.HOUSE_KIT_RESIDENT = String(process.pid);
87
- const agents = new Agents(house);
87
+ const agents = new Agents(house, () => changed());
88
88
  const copies = new LocalCopies(house);
89
89
  await copies.load();
90
90
  await installShim(join(kitHome(), 'shim', 'git'), 'git-main');
@@ -92,7 +92,7 @@ export async function resident() {
92
92
  await serveOwner(copies);
93
93
  let stream = null;
94
94
  let reported = false;
95
- const idle = () => conversations.idle() && signIns.idle();
95
+ const idle = () => conversations.idle() && signIns.idle() && agents.idle();
96
96
  const changed = () => {
97
97
  if (!idle()) {
98
98
  reported = false;
@@ -140,8 +140,12 @@ export async function resident() {
140
140
  signIns.start(arrived);
141
141
  else if (arrived.kind === 'update')
142
142
  updates.start(arrived);
143
- else
143
+ else if (CONVERSATION_INPUTS.has(arrived.kind))
144
144
  conversations.input(arrived);
145
+ else {
146
+ const refused = { refused: `This Kit does not know ${arrived.kind}; update the Kit` };
147
+ logged(house.deliver(`/kit/inputs/${arrived.input_id}/ack`, refused).finally(changed));
148
+ }
145
149
  }
146
150
  },
147
151
  });
package/dist/skills.js CHANGED
@@ -1,17 +1,31 @@
1
+ import { createHash } from 'node:crypto';
1
2
  import { readFileSync } from 'node:fs';
2
- import { cp, lstat, mkdir, readdir, realpath, rm, symlink, writeFile } from 'node:fs/promises';
3
+ import { cp, lstat, mkdir, readdir, realpath, rm, symlink } from 'node:fs/promises';
3
4
  import { homedir } from 'node:os';
4
5
  import { join, relative } from 'node:path';
5
6
  import { fileURLToPath } from 'node:url';
7
+ import { parse } from 'yaml';
6
8
  import { KIT_VERSION } from './clis.js';
7
9
  import { kitHome, readConfiguration, readHome, writeHome } from './home.js';
8
10
  import { refusalOf } from './refusals.js';
9
- export const HOW_WE_WORK = '/rooms/private/how-we-work.md';
11
+ const HOW_WE_WORK = '/rooms/private/how-we-work.md';
10
12
  const SKILL_SET = fileURLToPath(new URL('../skills/', import.meta.url));
11
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
+ ];
12
21
  const RECORD = 'skill-set.json';
13
- const CREATED = 'how-we-work-created';
22
+ const WRITTEN = 'how-we-work.json';
14
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: (.+)$/;
15
29
  function skillsDirectory() {
16
30
  return join(homedir(), '.agents', 'skills');
17
31
  }
@@ -49,6 +63,14 @@ async function install() {
49
63
  await writeHome(RECORD, { version: KIT_VERSION, names });
50
64
  }
51
65
  export async function placeSkillSet() {
66
+ try {
67
+ await replaceSkillSet();
68
+ }
69
+ catch (error) {
70
+ process.stderr.write(`kit: the skills could not be placed: ${error.message}\n`);
71
+ }
72
+ }
73
+ async function replaceSkillSet() {
52
74
  const accepted = (await readConfiguration()).skills;
53
75
  const installed = await readHome(RECORD);
54
76
  if (accepted && installed?.version === KIT_VERSION)
@@ -62,17 +84,64 @@ export async function placeSkillSet() {
62
84
  else
63
85
  await rm(join(kitHome(), RECORD), { force: true });
64
86
  }
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
+ }
65
131
  export async function createHowWeWork(bridge) {
66
- if ((await readHome(RECORD)) === null || (await present(join(kitHome(), CREATED))))
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')
67
139
  return;
68
- const created = await bridge.tool('edit', { changes: [{ op: 'create', path: HOW_WE_WORK, content: HOW_WE_WORK_TEXT }] });
69
- if (created.isError === true) {
70
- const text = created.content.map((content) => content.text).join('\n');
71
- const refusal = refusalOf(text);
72
- if (UNWRITABLE.has(refusal?.code ?? ''))
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')
73
144
  return;
74
- if (refusal?.code !== 'edit_conflict' || !refusal.conflicts.includes('path_exists'))
75
- throw new Error(text);
76
145
  }
77
- await writeFile(join(kitHome(), CREATED), '');
146
+ await writeHome(WRITTEN, current);
78
147
  }
package/dist/stream.js CHANGED
@@ -1,11 +1,42 @@
1
1
  import { subscribe } from 'node:diagnostics_channel';
2
2
  import { finalRefusal, HouseRefusal, retryDelay } from './api.js';
3
- import { end, REPLACED, signInAgain } from './end.js';
3
+ import { end, REPLACED, signInAgain, updateRequired } from './end.js';
4
4
  import { readEnrolment } from './home.js';
5
5
  import { relayed } from './relay.js';
6
+ import { KIT_WIRE, tooOld } from './wire.js';
6
7
  const PATH = '/kit/stream';
7
- const SUBPROTOCOL = 'house.kit.stream.1';
8
+ const SUBPROTOCOL = `house.kit.stream.${KIT_WIRE}`;
8
9
  const REFUSAL_HEADER = 'x-house-refusal';
10
+ // House beats each stream every thirty seconds, so two silent beats mean this Kit cannot hear House.
11
+ export const STREAM_SILENCE_MS = 60_000;
12
+ const SYSTEM_STREAM_CLOCK = {
13
+ later: (delay, callback) => setTimeout(callback, delay),
14
+ clear: (timer) => clearTimeout(timer),
15
+ };
16
+ export class StreamSilence {
17
+ timer = null;
18
+ silent;
19
+ clock;
20
+ interval;
21
+ constructor(silent, clock = SYSTEM_STREAM_CLOCK, interval = STREAM_SILENCE_MS) {
22
+ this.silent = silent;
23
+ this.clock = clock;
24
+ this.interval = interval;
25
+ }
26
+ heard() {
27
+ this.stop();
28
+ this.timer = this.clock.later(this.interval, () => {
29
+ this.timer = null;
30
+ this.silent();
31
+ });
32
+ }
33
+ stop() {
34
+ if (this.timer === null)
35
+ return;
36
+ this.clock.clear(this.timer);
37
+ this.timer = null;
38
+ }
39
+ }
9
40
  function streamUrl(house) {
10
41
  const url = new URL(PATH, house);
11
42
  url.protocol = url.protocol === 'https:' ? 'wss:' : 'ws:';
@@ -36,17 +67,10 @@ export function holdStream(handlers) {
36
67
  headers: { authorization: `Bearer ${credential}` },
37
68
  });
38
69
  let opened = false;
39
- opening.onopen = () => {
40
- opened = true;
41
- failures = 0;
42
- socket = opening;
43
- handlers.opened();
44
- };
45
- opening.onmessage = (event) => {
46
- handlers.frame(JSON.parse(String(event.data)));
47
- };
48
- opening.onerror = () => undefined;
49
- opening.onclose = (event) => {
70
+ let silence = null;
71
+ const closed = (event) => {
72
+ silence?.stop();
73
+ silence = null;
50
74
  if (socket === opening)
51
75
  socket = null;
52
76
  process.stderr.write(`kit: control stream closed ${event.code} ${event.reason}\n`);
@@ -56,11 +80,36 @@ export function holdStream(handlers) {
56
80
  void signInAgain(credential);
57
81
  return;
58
82
  }
83
+ if (refused !== null && tooOld(refused.text))
84
+ updateRequired(house);
59
85
  if (finalRefusal(refused))
60
86
  end(refused.message);
61
87
  // 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.
62
88
  setTimeout(() => void connect(), opened ? 1000 + Math.random() * 2000 : retryDelay(failures++));
63
89
  };
90
+ opening.onopen = () => {
91
+ opened = true;
92
+ failures = 0;
93
+ socket = opening;
94
+ silence = new StreamSilence(() => {
95
+ if (socket !== opening)
96
+ return;
97
+ socket = null;
98
+ opening.onclose = null;
99
+ opening.close();
100
+ closed(new CloseEvent('close', { code: 1006, reason: 'heartbeat_missed' }));
101
+ });
102
+ silence.heard();
103
+ handlers.opened();
104
+ };
105
+ opening.onmessage = (event) => {
106
+ silence?.heard();
107
+ const frame = JSON.parse(String(event.data));
108
+ if (frame.type !== 'beat')
109
+ handlers.frame(frame);
110
+ };
111
+ opening.onerror = () => undefined;
112
+ opening.onclose = closed;
64
113
  };
65
114
  void connect();
66
115
  return {
@@ -49,10 +49,10 @@ async function executed(command, args, signal) {
49
49
  function present(path) {
50
50
  return stat(path).then(() => true, () => false);
51
51
  }
52
- async function cpus() {
52
+ async function threads() {
53
53
  const [quota, period] = (await readFile('/sys/fs/cgroup/cpu.max', 'utf8').catch(() => 'max')).split(' ');
54
54
  const allowed = quota === 'max' ? Infinity : Math.ceil(Number(quota) / Number(period));
55
- return Math.min(availableParallelism(), allowed);
55
+ return Math.max(1, Math.floor(Math.min(availableParallelism(), allowed) / 2));
56
56
  }
57
57
  async function sha256(path) {
58
58
  const hash = createHash('sha256');
@@ -140,7 +140,7 @@ async function transcribed(path, signal) {
140
140
  await executed(installed(pinned.decoder), ['-nostdin', '-hide_banner', '-loglevel', 'error', '-i', path, '-ar', '16000', '-ac', '1', '-c:a', 'pcm_s16le',
141
141
  '-f', 'segment', '-segment_time', String(CHUNK_SECONDS), join(work, '%05d.wav')], signal);
142
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);
143
+ const text = await executed(installed(pinned.engine), ['-t', String(await threads()), '-np', '-m', installed(MODEL), ...parts], signal);
144
144
  return text
145
145
  .split('\n')
146
146
  .map((line) => line.trim())
package/dist/update.js CHANGED
@@ -4,8 +4,8 @@ import { mkdir, readFile, rm, writeFile } from 'node:fs/promises';
4
4
  import { homedir } from 'node:os';
5
5
  import { join } from 'node:path';
6
6
  import { run } from './clis.js';
7
- import { kitHome } from './home.js';
8
- const RECORD = 'outcome=$1; shift; bash "$0" --linux "$@"; printf %s "$?" > "$outcome"; systemctl start house-kit.service';
7
+ import { kitHome, workspaceRoot } from './home.js';
8
+ import { service, throughSudo } from './placement.js';
9
9
  function logged(error) {
10
10
  process.stderr.write(`kit: ${error instanceof Error ? error.message : String(error)}\n`);
11
11
  }
@@ -21,6 +21,21 @@ function outcome() {
21
21
  function unit(inputId) {
22
22
  return `house-kit-update-${inputId}`;
23
23
  }
24
+ function manager() {
25
+ return service() === 'user' ? ['--user'] : [];
26
+ }
27
+ function elevated() {
28
+ return throughSudo() ? ['sudo', '-n'] : [];
29
+ }
30
+ function account() {
31
+ return throughSudo() ? [`--uid=${process.getuid()}`, `--gid=${process.getgid()}`] : [];
32
+ }
33
+ function placement() {
34
+ return service() === 'user' ? ['--workspace', workspaceRoot()] : ['--linux'];
35
+ }
36
+ function record() {
37
+ return `outcome=$1; shift; bash "$0" "$@"; printf %s "$?" > "$outcome"; ${[...elevated(), 'systemctl', ...manager(), 'start', 'house-kit.service'].join(' ')}`;
38
+ }
24
39
  async function pendingInput() {
25
40
  try {
26
41
  return JSON.parse(await readFile(pending(), 'utf8')).input_id;
@@ -41,7 +56,7 @@ async function finished(inputId) {
41
56
  if (ack !== null)
42
57
  return ack;
43
58
  // systemctl answers at once, so ten seconds only bounds a stuck service manager.
44
- if ((await run('systemctl', ['is-active', '--quiet', unit(inputId)], 10_000)).status !== 0) {
59
+ if ((await run('systemctl', [...manager(), 'is-active', '--quiet', unit(inputId)], 10_000)).status !== 0) {
45
60
  return (await recorded()) ?? { refused: 'the Kit bootstrap did not finish' };
46
61
  }
47
62
  // The bootstrap runs for minutes, so checking each second sees its outcome within a second at little cost.
@@ -50,19 +65,26 @@ async function finished(inputId) {
50
65
  }
51
66
  function rerun(script, inputId, flags) {
52
67
  return new Promise((resolve) => {
53
- const child = spawn('systemd-run', [
68
+ const [command, ...args] = [
69
+ ...elevated(),
70
+ 'systemd-run',
71
+ ...manager(),
72
+ ...account(),
54
73
  '--wait',
55
74
  '--collect',
56
75
  '--quiet',
57
76
  `--unit=${unit(inputId)}`,
58
77
  `--setenv=HOME=${homedir()}`,
78
+ `--setenv=HOUSE_KIT_HOME=${kitHome()}`,
59
79
  '/bin/sh',
60
80
  '-c',
61
- RECORD,
81
+ record(),
62
82
  script,
63
83
  outcome(),
84
+ ...placement(),
64
85
  ...flags,
65
- ], { stdio: ['ignore', 'ignore', 'inherit'] });
86
+ ];
87
+ const child = spawn(command, args, { stdio: ['ignore', 'ignore', 'inherit'] });
66
88
  child.on('error', () => resolve({ refused: 'no service manager runs this Kit' }));
67
89
  child.on('close', () => resolve(null));
68
90
  });
package/dist/wire.js ADDED
@@ -0,0 +1,6 @@
1
+ import { refusalOf } from './refusals.js';
2
+ export const KIT_WIRE = 1;
3
+ export const KIT_WIRE_HEADER = 'x-house-kit-wire';
4
+ export function tooOld(text) {
5
+ return refusalOf(text)?.code === 'kit_update_required';
6
+ }
package/how-we-work.md CHANGED
@@ -4,20 +4,30 @@ A Room is where information people share is kept; it is not the place for
4
4
  private information. Work goes into the Room it belongs to, or the First Room
5
5
  when none is named.
6
6
 
7
+ Every House answer carries the `url` of what it names; send the User that link.
8
+
7
9
  The skills are already set up; never run `setup-matt-pocock-skills`.
8
10
 
9
11
  ## Where skill output goes
10
12
 
11
- - Glossary (`CONTEXT.md`): `glossary.md`
13
+ - Glossary (`GLOSSARY.md`): `glossary.md`
12
14
  - Decisions (ADRs): `decisions/NNNN-<slug>.md`
13
15
  - Plan (spec): `projects/<name>/plan.md`
14
16
  - Tasks (tickets): `projects/<name>/tasks/NN-<slug>.md`, with a
15
17
  `Status:` line (`needs-triage`, `needs-info`, `ready-for-agent`,
16
- `ready-for-human`, `wontfix`), a `Blocked by:` line and comments under
17
- `## Comments`
18
+ `ready-for-human`, `wontfix`, or `done` once implemented), a
19
+ `Category:` line (`bug`, `enhancement`), a `Blocked by:` line and comments
20
+ under `## Comments`; triage takes no pull requests
21
+ - Rejected requests (triage): `out-of-scope/<concept>.md`
22
+ - Implementation notes (implement-spec): `projects/<name>/notes/`
23
+ - PR bodies (pr): `projects/<name>/prs/<branch>.md`
18
24
  - Map (Wayfinding): `projects/<name>/map.md`, its tasks under
19
25
  `tasks/` with `Type:`, `Status: claimed|resolved` and `Blocked by:` lines
20
26
  - Research: `research/<slug>.md`
27
+ - Architecture reports (improve-codebase-architecture): `architecture/<slug>.html`
28
+ - Handoffs: `handoffs/<slug>.md`
21
29
  - Questionnaires: `questionnaires/<slug>.md`
30
+ - Retrospectives (retro): `retros/<date>-<slug>.md`
31
+ - Wizards: `wizards/<slug>.sh`; the values they capture stay out of the Room
22
32
  - Learning: `learning/<topic>/`
23
33
  - Prototype: one HTML file with every variant on one page.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentshouse/kit",
3
- "version": "0.2.1-cf110d15f69c8",
3
+ "version": "0.2.1-cfb7b543f2af6",
4
4
  "description": "House Kit connects an Environment to agents.house.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -23,6 +23,7 @@
23
23
  "scripts": {
24
24
  "build": "tsc -p tsconfig.build.json && node scripts/bootstrap-manifest.mjs",
25
25
  "engine": "mkdir -p tmp/engine && docker run --rm -v \"$PWD:/kit\" -w /kit alpine:3.24@sha256:294b683cb724975bec92580e1e685676bd4b50bda910ddb8c51d4cabeaec77e6 sh scripts/engine.sh tmp/engine",
26
+ "sync-skills": "node scripts/sync-skills.mjs",
26
27
  "test": "tsc -p tsconfig.json && vitest run"
27
28
  },
28
29
  "dependencies": {