@agentshouse/kit 0.2.1-cfb7b543f2af6 → 0.2.1-cfbadfb5b5e28

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 (150) hide show
  1. package/README.md +33 -34
  2. package/dist/acp.js +91 -20
  3. package/dist/afk.js +17 -0
  4. package/dist/agents.js +91 -44
  5. package/dist/api.js +5 -5
  6. package/dist/app-git.js +10 -26
  7. package/dist/authority-main.js +3 -3
  8. package/dist/bridge.js +7 -10
  9. package/dist/building.js +50 -0
  10. package/dist/calls.js +71 -0
  11. package/dist/chunks.js +49 -0
  12. package/dist/clis.js +56 -45
  13. package/dist/connection.js +120 -0
  14. package/dist/content.js +63 -0
  15. package/dist/conversations.js +703 -244
  16. package/dist/copies.js +344 -171
  17. package/dist/end.js +15 -4
  18. package/dist/events.js +746 -210
  19. package/dist/files.js +139 -37
  20. package/dist/git.js +49 -16
  21. package/dist/grok.js +39 -0
  22. package/dist/home.js +27 -20
  23. package/dist/house-cli.js +98 -90
  24. package/dist/house-main.js +3 -3
  25. package/dist/instructions.js +29 -10
  26. package/dist/kit-cli.js +5 -8
  27. package/dist/kit-main.js +3 -3
  28. package/dist/login.js +20 -11
  29. package/dist/logout.js +1 -3
  30. package/dist/mcp.js +6 -2
  31. package/dist/placement.js +19 -36
  32. package/dist/relay.js +21 -0
  33. package/dist/resident.js +118 -52
  34. package/dist/scope.js +15 -4
  35. package/dist/scripts.js +255 -0
  36. package/dist/secret-input.js +1 -1
  37. package/dist/service.js +23 -1
  38. package/dist/sign-in.js +22 -39
  39. package/dist/silence.js +28 -0
  40. package/dist/skills.js +42 -97
  41. package/dist/transcription.js +88 -45
  42. package/dist/translate.js +19 -16
  43. package/dist/update.js +113 -127
  44. package/dist/wire.js +37 -3
  45. package/dist/work.js +12 -7
  46. package/package.json +22 -21
  47. package/dist/bootstrap.json +0 -24
  48. package/dist/chatgpt.js +0 -32
  49. package/dist/clis-main.js +0 -23
  50. package/dist/parts.js +0 -82
  51. package/dist/stream.js +0 -123
  52. package/how-we-work.md +0 -33
  53. package/skills/ask-matt/LICENSE +0 -21
  54. package/skills/ask-matt/PHASE-BOUNDARIES.md +0 -55
  55. package/skills/ask-matt/SKILL.md +0 -97
  56. package/skills/ask-matt/agents/openai.yaml +0 -5
  57. package/skills/code-review/LICENSE +0 -21
  58. package/skills/code-review/SKILL.md +0 -89
  59. package/skills/code-review/agents/openai.yaml +0 -3
  60. package/skills/codebase-design/DEEPENING.md +0 -37
  61. package/skills/codebase-design/DESIGN-IT-TWICE.md +0 -44
  62. package/skills/codebase-design/LICENSE +0 -21
  63. package/skills/codebase-design/SKILL.md +0 -114
  64. package/skills/codebase-design/agents/openai.yaml +0 -3
  65. package/skills/diagnosing-bugs/LICENSE +0 -21
  66. package/skills/diagnosing-bugs/SKILL.md +0 -138
  67. package/skills/diagnosing-bugs/agents/openai.yaml +0 -3
  68. package/skills/diagnosing-bugs/scripts/hitl-loop.template.sh +0 -44
  69. package/skills/domain-modeling/ADR-FORMAT.md +0 -47
  70. package/skills/domain-modeling/GLOSSARY-FORMAT.md +0 -60
  71. package/skills/domain-modeling/LICENSE +0 -21
  72. package/skills/domain-modeling/SKILL.md +0 -74
  73. package/skills/domain-modeling/agents/openai.yaml +0 -3
  74. package/skills/grill-me/LICENSE +0 -21
  75. package/skills/grill-me/SKILL.md +0 -7
  76. package/skills/grill-me/agents/openai.yaml +0 -5
  77. package/skills/grill-with-docs/LICENSE +0 -21
  78. package/skills/grill-with-docs/SKILL.md +0 -7
  79. package/skills/grill-with-docs/agents/openai.yaml +0 -5
  80. package/skills/grilling/LICENSE +0 -21
  81. package/skills/grilling/SKILL.md +0 -30
  82. package/skills/grilling/agents/openai.yaml +0 -3
  83. package/skills/handoff/LICENSE +0 -21
  84. package/skills/handoff/SKILL.md +0 -16
  85. package/skills/handoff/agents/openai.yaml +0 -5
  86. package/skills/implement/LICENSE +0 -21
  87. package/skills/implement/SKILL.md +0 -17
  88. package/skills/implement/agents/openai.yaml +0 -5
  89. package/skills/implement-spec/LICENSE +0 -21
  90. package/skills/implement-spec/SKILL.md +0 -40
  91. package/skills/implement-spec/agents/openai.yaml +0 -5
  92. package/skills/improve-codebase-architecture/HTML-REPORT.md +0 -123
  93. package/skills/improve-codebase-architecture/LICENSE +0 -21
  94. package/skills/improve-codebase-architecture/SKILL.md +0 -71
  95. package/skills/improve-codebase-architecture/agents/openai.yaml +0 -5
  96. package/skills/pr/CREDITS.md +0 -3
  97. package/skills/pr/LICENSE +0 -21
  98. package/skills/pr/SKILL.md +0 -170
  99. package/skills/pr/agents/openai.yaml +0 -3
  100. package/skills/prototype/LICENSE +0 -21
  101. package/skills/prototype/LOGIC.md +0 -67
  102. package/skills/prototype/SKILL.md +0 -26
  103. package/skills/prototype/UI.md +0 -112
  104. package/skills/prototype/agents/openai.yaml +0 -3
  105. package/skills/research/LICENSE +0 -21
  106. package/skills/research/SKILL.md +0 -12
  107. package/skills/research/agents/openai.yaml +0 -3
  108. package/skills/retro/LICENSE +0 -21
  109. package/skills/retro/SKILL.md +0 -44
  110. package/skills/retro/agents/openai.yaml +0 -5
  111. package/skills/tdd/LICENSE +0 -21
  112. package/skills/tdd/SKILL.md +0 -38
  113. package/skills/tdd/agents/openai.yaml +0 -3
  114. package/skills/tdd/mocking.md +0 -59
  115. package/skills/tdd/tests.md +0 -77
  116. package/skills/teach/GLOSSARY-FORMAT.md +0 -35
  117. package/skills/teach/LEARNING-RECORD-FORMAT.md +0 -46
  118. package/skills/teach/LICENSE +0 -21
  119. package/skills/teach/MISSION-FORMAT.md +0 -31
  120. package/skills/teach/RESOURCES-FORMAT.md +0 -32
  121. package/skills/teach/SKILL.md +0 -140
  122. package/skills/teach/agents/openai.yaml +0 -5
  123. package/skills/to-questionnaire/LICENSE +0 -21
  124. package/skills/to-questionnaire/SKILL.md +0 -54
  125. package/skills/to-questionnaire/agents/openai.yaml +0 -5
  126. package/skills/to-spec/LICENSE +0 -21
  127. package/skills/to-spec/SKILL.md +0 -75
  128. package/skills/to-spec/agents/openai.yaml +0 -5
  129. package/skills/to-tickets/LICENSE +0 -21
  130. package/skills/to-tickets/SKILL.md +0 -105
  131. package/skills/to-tickets/agents/openai.yaml +0 -5
  132. package/skills/triage/AGENT-BRIEF.md +0 -207
  133. package/skills/triage/LICENSE +0 -21
  134. package/skills/triage/OUT-OF-SCOPE.md +0 -105
  135. package/skills/triage/SKILL.md +0 -112
  136. package/skills/triage/agents/openai.yaml +0 -5
  137. package/skills/wait-what/LICENSE +0 -21
  138. package/skills/wait-what/SKILL.md +0 -7
  139. package/skills/wait-what/agents/openai.yaml +0 -5
  140. package/skills/wayfinder/LICENSE +0 -21
  141. package/skills/wayfinder/SKILL.md +0 -128
  142. package/skills/wayfinder/agents/openai.yaml +0 -5
  143. package/skills/wizard/LICENSE +0 -21
  144. package/skills/wizard/SKILL.md +0 -44
  145. package/skills/wizard/agents/openai.yaml +0 -3
  146. package/skills/wizard/template.sh +0 -223
  147. package/skills/writing-for-agents/LICENSE +0 -21
  148. package/skills/writing-for-agents/SKILL-MECHANICS.md +0 -22
  149. package/skills/writing-for-agents/SKILL.md +0 -81
  150. package/skills/writing-for-agents/agents/openai.yaml +0 -3
package/dist/app-git.js CHANGED
@@ -1,15 +1,9 @@
1
- import { extname, resolve } from 'node:path';
2
- import { fileURLToPath } from 'node:url';
3
1
  import { run } from './git.js';
4
2
  import { kitHome, readOwnAgent } from './home.js';
5
- import { quoted } from './shell.js';
3
+ const HELPER = '!kit git-credential';
6
4
  function section(house) {
7
5
  return `credential.${new URL('/app/', house).href}`;
8
6
  }
9
- function helper() {
10
- const main = fileURLToPath(new URL(`./kit-main${extname(fileURLToPath(import.meta.url))}`, import.meta.url));
11
- return `!HOUSE_KIT_HOME=${quoted(resolve(kitHome()))} ${quoted(process.execPath)} ${quoted(main)} git-credential`;
12
- }
13
7
  async function configured(args) {
14
8
  try {
15
9
  return await run(kitHome(), ['config', '--global', ...args]);
@@ -20,30 +14,18 @@ async function configured(args) {
20
14
  throw error;
21
15
  }
22
16
  }
23
- async function forget(house) {
24
- await configured(['--remove-section', section(house)]);
25
- }
26
- async function register(house) {
27
- await forget(house);
28
- for (const value of ['', helper()]) {
29
- const ran = await configured(['--add', `${section(house)}.helper`, value]);
17
+ export async function placeAppGit(ownAgent) {
18
+ if (ownAgent === null)
19
+ return;
20
+ await configured(['--remove-section', section(ownAgent.house)]);
21
+ for (const value of ['', HELPER]) {
22
+ const ran = await configured(['--add', `${section(ownAgent.house)}.helper`, value]);
30
23
  if (ran === null)
31
24
  return;
32
25
  if (ran.status !== 0)
33
26
  throw new Error(`git config failed: ${ran.stderr.trim()}`);
34
27
  }
35
28
  }
36
- export async function placeAppGit(before, after) {
37
- if (before !== null && before.house !== after?.house)
38
- await forget(before.house);
39
- if (after !== null)
40
- await register(after.house);
41
- }
42
- export async function forgetAppGit() {
43
- const ownAgent = await readOwnAgent();
44
- if (ownAgent !== null)
45
- await forget(ownAgent.house);
46
- }
47
29
  export async function answerGitCredential(operation) {
48
30
  let asked = '';
49
31
  for await (const chunk of process.stdin)
@@ -55,8 +37,10 @@ export async function answerGitCredential(operation) {
55
37
  .filter((line) => line.includes('='))
56
38
  .map((line) => [line.slice(0, line.indexOf('=')), line.slice(line.indexOf('=') + 1)]));
57
39
  const ownAgent = await readOwnAgent();
58
- if (ownAgent === null)
40
+ if (ownAgent === null) {
41
+ process.stderr.write(`kit: Kit home ${kitHome()} is not signed in; run kit login\n`);
59
42
  return;
43
+ }
60
44
  const house = new URL(ownAgent.house);
61
45
  if (attributes.get('protocol') !== house.protocol.slice(0, -1) || attributes.get('host') !== house.host)
62
46
  return;
@@ -1,14 +1,14 @@
1
- import { setGlobalProxyFromEnv } from 'node:http';
2
1
  import { HouseRefusal, post } from './api.js';
3
2
  import { readEnrolment } from './home.js';
3
+ import { proxyUnlessRelayed } from './relay.js';
4
4
  function unanswered(error) {
5
5
  return error instanceof HouseRefusal ? error.status >= 500 : error instanceof TypeError && error.message === 'fetch failed';
6
6
  }
7
- setGlobalProxyFromEnv();
7
+ proxyUnlessRelayed();
8
8
  try {
9
9
  const { house, credential } = (await readEnrolment());
10
10
  try {
11
- await post(house, '/kit/agents/desired', {}, credential);
11
+ await post(house, '/kit/agents/desired/list', {}, credential);
12
12
  }
13
13
  catch (error) {
14
14
  if (!unanswered(error))
package/dist/bridge.js CHANGED
@@ -1,7 +1,6 @@
1
1
  import { createHash, randomUUID } from 'node:crypto';
2
2
  import { once } from 'node:events';
3
3
  import { setTimeout as delay } from 'node:timers/promises';
4
- import { mkdir } from 'node:fs/promises';
5
4
  import { createServer, request as httpRequest } from 'node:http';
6
5
  import { request as httpsRequest } from 'node:https';
7
6
  import { delimiter, dirname, join } from 'node:path';
@@ -9,12 +8,12 @@ import { parse } from 'yaml';
9
8
  import { finalRefusal, HouseRefusal, retryDelay, retrying } from './api.js';
10
9
  import { loginPath } from './clis.js';
11
10
  import { changedPaths, } from './copies.js';
12
- import { kitHome, readEnrolment } from './home.js';
11
+ import { kitHome, readEnrolment, socketDirectory } from './home.js';
13
12
  import { callHouse, mcpBody, rpc, UNREACHABLE } from './mcp.js';
14
13
  import { operationId } from './operation.js';
15
14
  import { refusalOf, retryable } from './refusals.js';
16
15
  import { relayed } from './relay.js';
17
- const MCP_REQUEST_BYTES = 4 * 1024 * 1024;
16
+ const MCP_REQUEST_BYTES = 4_000_000;
18
17
  export async function received(request) {
19
18
  let text = '';
20
19
  request.setEncoding('utf8');
@@ -82,7 +81,7 @@ function editAnswer(forwarded) {
82
81
  export async function openBridge(house, copies, conversationId, signal) {
83
82
  const path = [join(kitHome(), 'shim'), dirname(process.execPath), await loginPath()].join(delimiter);
84
83
  const origin = (await readEnrolment()).house;
85
- const { credential } = await house.post(`/kit/conversations/${conversationId}/credential`, {}, signal);
84
+ const { credential } = await retrying(() => house.post('/kit/conversations/credentials/issue', { conversation: conversationId }, signal), signal);
86
85
  const closed = new AbortController();
87
86
  const sent = (message, operation) => callHouse(origin, credential, message, operation, closed.signal);
88
87
  const send = async (message, operation) => {
@@ -106,7 +105,7 @@ export async function openBridge(house, copies, conversationId, signal) {
106
105
  const bytes = Buffer.from(JSON.stringify({ changes }));
107
106
  const sha256 = createHash('sha256').update(bytes).digest('hex');
108
107
  const prepared = answered(await send(call('run_command', {
109
- command: 'prepare_edit_upload',
108
+ command: 'files/batch-upload',
110
109
  arguments: { paths: changedPaths(changes), bytes: bytes.length, sha256 },
111
110
  }), operation));
112
111
  if ('refused' in prepared)
@@ -142,7 +141,7 @@ export async function openBridge(house, copies, conversationId, signal) {
142
141
  const caller = {
143
142
  key: `conversation:${conversationId}`,
144
143
  submit: async (operation, changes, held, retain) => {
145
- const inline = call('edit', { changes });
144
+ const inline = call('files_batch', { changes });
146
145
  let upload = held;
147
146
  if (upload === undefined && Buffer.byteLength(mcpBody(inline, operation)) > MCP_REQUEST_BYTES) {
148
147
  const prepared = await staged(operation, changes);
@@ -151,7 +150,7 @@ export async function openBridge(house, copies, conversationId, signal) {
151
150
  upload = prepared;
152
151
  await retain(upload);
153
152
  }
154
- return editAnswer(await send(upload === undefined ? inline : call('edit', { paths: changedPaths(changes), upload }), operation));
153
+ return editAnswer(await send(upload === undefined ? inline : call('files_batch', { paths: changedPaths(changes), upload }), operation));
155
154
  },
156
155
  };
157
156
  const local = async (path, text) => {
@@ -167,9 +166,7 @@ export async function openBridge(house, copies, conversationId, signal) {
167
166
  }
168
167
  return path === '/' ? forward(text) : { status: 404, text: '' };
169
168
  };
170
- const sockets = join(kitHome(), 'bridges');
171
- await mkdir(sockets, { recursive: true, mode: 0o700 });
172
- const socketPath = join(sockets, `${randomUUID()}.sock`);
169
+ const socketPath = join(socketDirectory(), `${randomUUID()}.sock`);
173
170
  const bridge = createServer(async (request, response) => {
174
171
  try {
175
172
  const path = request.url ?? '';
@@ -0,0 +1,50 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { createWriteStream } from 'node:fs';
3
+ import { rm } from 'node:fs/promises';
4
+ import { Transform } from 'node:stream';
5
+ import { pipeline } from 'node:stream/promises';
6
+ import { readEnrolment } from './home.js';
7
+ import { relayed } from './relay.js';
8
+ const MANIFEST = 'bootstrap.json';
9
+ async function served(name, signal) {
10
+ const enrolment = await readEnrolment();
11
+ if (enrolment === null)
12
+ throw new Error('this Kit is connected to no House');
13
+ const answer = await fetch(relayed(new URL(`/kit-installer/${encodeURIComponent(name)}`, enrolment.house)), { signal });
14
+ if (answer.status === 200 && answer.body !== null)
15
+ return answer;
16
+ await answer.body?.cancel();
17
+ throw new Error(`House answered ${answer.status} for ${name}`);
18
+ }
19
+ export async function servedRelease(signal) {
20
+ const manifest = (await (await served(MANIFEST, signal)).json());
21
+ const installer = manifest.hosts?.linux;
22
+ const sha256 = typeof installer === 'string' ? manifest.files?.[installer]?.sha256 : undefined;
23
+ if (typeof manifest.version !== 'string' || typeof installer !== 'string' || typeof sha256 !== 'string') {
24
+ throw new Error(`House serves no Kit release in ${MANIFEST}`);
25
+ }
26
+ return { version: manifest.version, installer, sha256 };
27
+ }
28
+ export async function downloadServed(name, sha256, destination, signal, most = Infinity) {
29
+ const answer = await served(name, signal);
30
+ const digest = createHash('sha256');
31
+ let bytes = 0;
32
+ const hashed = new Transform({
33
+ transform(chunk, _encoding, done) {
34
+ bytes += chunk.length;
35
+ if (bytes > most)
36
+ return done(new Error(`${name} is larger than its pinned ${most} bytes`));
37
+ digest.update(chunk);
38
+ done(null, chunk);
39
+ },
40
+ });
41
+ try {
42
+ await pipeline(answer.body, hashed, createWriteStream(destination), { signal });
43
+ if (digest.digest('hex') !== sha256)
44
+ throw new Error(`${name} does not match its sha256`);
45
+ }
46
+ catch (error) {
47
+ await rm(destination, { force: true });
48
+ throw error;
49
+ }
50
+ }
package/dist/calls.js ADDED
@@ -0,0 +1,71 @@
1
+ import { existsSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { kitHome } from './home.js';
4
+ function logged(error) {
5
+ process.stderr.write(`kit: ${error instanceof Error ? error.message : String(error)}\n`);
6
+ }
7
+ export class Calls {
8
+ house;
9
+ changed;
10
+ carried = new Map();
11
+ path = join(kitHome(), 'call-results.json');
12
+ results;
13
+ returned = new Set();
14
+ released = new Set();
15
+ open = 0;
16
+ constructor(house, changed) {
17
+ this.house = house;
18
+ this.changed = changed;
19
+ this.results = new Map(existsSync(this.path) ? Object.entries(JSON.parse(readFileSync(this.path, 'utf8'))) : []);
20
+ }
21
+ keepResult(callId, result) {
22
+ if (this.returned.has(callId))
23
+ return;
24
+ this.results.set(callId, result);
25
+ this.save();
26
+ }
27
+ idle() {
28
+ return this.open === 0;
29
+ }
30
+ carry(callId, work) {
31
+ if (this.released.has(callId))
32
+ return Promise.resolve();
33
+ const known = this.carried.get(callId);
34
+ const result = this.results.get(callId);
35
+ const carried = known ?? (result === undefined ? work() : Promise.resolve({ result }));
36
+ if (known === undefined) {
37
+ this.carried.set(callId, carried);
38
+ carried.catch(() => this.carried.delete(callId));
39
+ }
40
+ this.open++;
41
+ this.changed();
42
+ return carried
43
+ .then(async ({ result, returned, release }) => {
44
+ try {
45
+ await this.house.deliver('/kit/kit-calls/results/return', { call: callId, ...result });
46
+ }
47
+ finally {
48
+ this.returned.add(callId);
49
+ if (this.results.delete(callId))
50
+ this.save();
51
+ }
52
+ if (known !== undefined)
53
+ return;
54
+ if (release) {
55
+ this.carried.delete(callId);
56
+ this.released.add(callId);
57
+ }
58
+ await returned?.();
59
+ })
60
+ .catch(logged)
61
+ .finally(() => {
62
+ this.open--;
63
+ this.changed();
64
+ });
65
+ }
66
+ save() {
67
+ const temporary = `${this.path}.${process.pid}`;
68
+ writeFileSync(temporary, JSON.stringify(Object.fromEntries(this.results)), { mode: 0o600 });
69
+ renameSync(temporary, this.path);
70
+ }
71
+ }
package/dist/chunks.js ADDED
@@ -0,0 +1,49 @@
1
+ import { readFile, rm } from 'node:fs/promises';
2
+ import { join } from 'node:path';
3
+ import { downloaded, fetched } from './files.js';
4
+ const DOWNLOADS_AT_ONCE = 6;
5
+ // A chunk is about one megabyte, so a download still unfinished after two minutes holds every Room behind it on a dead connection.
6
+ const CHUNK_DOWNLOAD_MS = 120_000;
7
+ class AddressExpired extends Error {
8
+ constructor() {
9
+ super("House's store refused every chunk it asked for");
10
+ }
11
+ }
12
+ function once(chunk) {
13
+ let asked = false;
14
+ return async () => {
15
+ if (asked)
16
+ throw new AddressExpired();
17
+ asked = true;
18
+ return { download: chunk.download, sha256: chunk.hash };
19
+ };
20
+ }
21
+ export async function stagedChunks(directory, chunks) {
22
+ let next = 0;
23
+ let failure;
24
+ const downloading = async () => {
25
+ while (next < chunks.length && failure === undefined) {
26
+ const chunk = chunks[next++];
27
+ const reading = (url) => fetched(url, AbortSignal.timeout(CHUNK_DOWNLOAD_MS));
28
+ await downloaded(once(chunk), reading, join(directory, chunk.hash), 'A Room chunk').catch((error) => {
29
+ failure ??= error;
30
+ });
31
+ }
32
+ };
33
+ await Promise.all(Array.from({ length: DOWNLOADS_AT_ONCE }, downloading));
34
+ return failure;
35
+ }
36
+ export async function* chunkTexts(directory, chunks, models) {
37
+ yield* models;
38
+ for (const { hash } of chunks) {
39
+ const file = join(directory, hash);
40
+ for (const line of (await readFile(file, 'utf8')).split('\n')) {
41
+ if (line === '')
42
+ continue;
43
+ const entry = JSON.parse(line);
44
+ if (entry.content !== undefined)
45
+ yield entry;
46
+ }
47
+ await rm(file);
48
+ }
49
+ }
package/dist/clis.js CHANGED
@@ -4,7 +4,8 @@ import { constants, readFileSync } from 'node:fs';
4
4
  import { access, mkdir, readFile, rename, writeFile } from 'node:fs/promises';
5
5
  import { homedir, userInfo } from 'node:os';
6
6
  import { delimiter, dirname, isAbsolute, join } from 'node:path';
7
- import { kitHome } from './home.js';
7
+ import { releaseDirectory } from './placement.js';
8
+ import { childEnvironment } from './relay.js';
8
9
  const HOUSE_EXECUTABLES = /^host_executable\(name = "house", paths = (\[.*\])\)$/m;
9
10
  function houseRule(houses) {
10
11
  return `prefix_rule(pattern = ["house"], decision = "allow")\nhost_executable(name = "house", paths = ${JSON.stringify(houses)})\n`;
@@ -14,10 +15,12 @@ const RAW_SUBTYPES = [
14
15
  'task_started',
15
16
  'task_updated',
16
17
  'task_notification',
18
+ 'task_progress',
17
19
  'session_state_changed',
18
20
  'hook_started',
19
21
  'hook_response',
20
22
  ];
23
+ const RAW_TYPES = ['result', 'user', 'assistant', 'rate_limit_event', 'prompt_suggestion'];
21
24
  async function executable(path) {
22
25
  try {
23
26
  await access(path, constants.X_OK);
@@ -60,14 +63,26 @@ export async function allowHouseInCodex(path) {
60
63
  await rename(temporary, file);
61
64
  }
62
65
  async function nothing() { }
66
+ function claudeQuestionFields(request) {
67
+ const properties = request.requestedSchema?.properties ?? {};
68
+ return Object.keys(properties).filter((name) => properties[name]._meta?.jetbrains?.air?.customAnswer !== undefined);
69
+ }
70
+ function codexQuestionFields(request) {
71
+ const { _meta, requestedSchema } = request;
72
+ return _meta?.codex === undefined ? [] : (requestedSchema?.required ?? []);
73
+ }
74
+ function answered(error) {
75
+ return typeof error === 'object' && error !== null ? error : {};
76
+ }
63
77
  function bridgeInClaudeSandbox(bridge) {
64
78
  return process.platform === 'darwin' ? { allowUnixSockets: [bridge] } : { allowAllUnixSockets: true };
65
79
  }
66
80
  export const CLIS = {
67
81
  'codex-acp': {
68
82
  bin: 'codex',
69
- minimum: '0.159.1',
83
+ minimum: '0.165.0',
70
84
  install: 'curl -fsSL https://chatgpt.com/codex/install.sh | sh',
85
+ update: 'codex update',
71
86
  adapter: {
72
87
  package: '@agentclientprotocol/codex-acp',
73
88
  bin: 'codex-acp',
@@ -77,16 +92,21 @@ export const CLIS = {
77
92
  args: [],
78
93
  fullAccess: 'agent-full-access',
79
94
  sessionMeta: () => ({}),
80
- renames: true,
95
+ unknownSession: (error) => {
96
+ const { code, data } = answered(error);
97
+ return code === -32603 && typeof data?.details === 'string' && data.details.startsWith('no rollout found');
98
+ },
81
99
  allowHouse: allowHouseInCodex,
100
+ questionFields: codexQuestionFields,
82
101
  signedIn: { command: ['login', 'status'] },
83
102
  login: { args: ['login', '--device-auth'], code: 'show' },
84
103
  air: ['asyncTasks', 'nativeSubagentSessions'],
85
104
  },
86
105
  'claude-agent-acp': {
87
106
  bin: 'claude',
88
- minimum: '2.1.286',
107
+ minimum: '2.1.316',
89
108
  install: 'curl -fsSL https://claude.ai/install.sh | bash',
109
+ update: 'claude update',
90
110
  adapter: {
91
111
  package: '@agentclientprotocol/claude-agent-acp',
92
112
  bin: 'claude-agent-acp',
@@ -95,19 +115,19 @@ export const CLIS = {
95
115
  },
96
116
  args: [],
97
117
  fullAccess: 'bypassPermissions',
98
- sessionMeta: (bridge, title) => ({
118
+ sessionMeta: (bridge) => ({
99
119
  claudeCode: {
100
120
  options: {
101
121
  allowedTools: ['Bash(house:*)'],
102
122
  includeHookEvents: true,
103
- title,
104
123
  settings: { sandbox: { network: bridgeInClaudeSandbox(bridge) } },
105
124
  },
106
- emitRawSDKMessages: RAW_SUBTYPES.map((subtype) => ({ type: 'system', subtype })),
125
+ emitRawSDKMessages: [...RAW_SUBTYPES.map((subtype) => ({ type: 'system', subtype })), ...RAW_TYPES.map((type) => ({ type }))],
107
126
  },
108
127
  }),
109
- renames: false,
128
+ unknownSession: (error) => answered(error).code === -32002,
110
129
  allowHouse: nothing,
130
+ questionFields: claudeQuestionFields,
111
131
  signedIn: { command: ['auth', 'status'] },
112
132
  login: { args: ['auth', 'login', '--claudeai'], code: 'collect', rejected: 'Invalid code' },
113
133
  air: ['asyncTasks', 'sessionFailure'],
@@ -116,50 +136,36 @@ export const CLIS = {
116
136
  bin: 'grok',
117
137
  minimum: '1.0.46',
118
138
  install: 'curl -fsSL https://x.ai/cli/install.sh | bash',
139
+ update: 'grok update',
119
140
  adapter: null,
120
141
  args: ['--sandbox', 'off', 'agent', '--always-approve', '--no-leader', 'stdio'],
121
142
  fullAccess: null,
122
143
  sessionMeta: () => ({}),
123
- renames: false,
144
+ unknownSession: (error) => answered(error).data?.code === 'FS_NOT_FOUND',
124
145
  allowHouse: nothing,
146
+ questionFields: () => [],
125
147
  signedIn: { initializeMeta: 'defaultAuthMethodId' },
126
148
  login: { args: ['login', '--device-auth'], code: 'show' },
127
149
  air: ['asyncTasks'],
128
150
  },
129
151
  };
130
152
  const KIT_PACKAGE = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
131
- export const KIT_VERSION = KIT_PACKAGE.version;
132
- const PROXY = /^https?_proxy$/i;
153
+ export const KIT_RELEASE = KIT_PACKAGE.version;
133
154
  const VERSION = /\d+\.\d+\.\d+(?:-[0-9A-Za-z.]+)?/;
134
- // An install still running after fifteen minutes is ended and reported as failed, so a hung download cannot hold its CLI's report.
155
+ // An install or update still running after fifteen minutes is ended as failed, so a hung download can neither hold its CLI's report nor keep the Kit busy.
135
156
  const INSTALL_MS = 15 * 60_000;
136
157
  // A login shell or a version read is ended after half a minute, so a profile that waits for input cannot stall the report.
137
158
  const READ_MS = 30_000;
138
159
  const CAUSE_CHARACTERS = 4000;
139
- function prefix(kind) {
140
- return join(kitHome(), 'agents', kind);
141
- }
142
160
  export function adapterCommand(kind) {
143
- return join(prefix(kind), 'node_modules', '.bin', CLIS[kind].adapter.bin);
144
- }
145
- async function installedAdapter(kind) {
146
- try {
147
- const manifest = join(prefix(kind), 'node_modules', CLIS[kind].adapter.package, 'package.json');
148
- return JSON.parse(await readFile(manifest, 'utf8')).version;
149
- }
150
- catch {
151
- return null;
152
- }
153
- }
154
- export function withoutProxy() {
155
- return Object.fromEntries(Object.entries(process.env).filter(([name]) => !PROXY.test(name)));
161
+ return join(releaseDirectory(KIT_RELEASE), 'adapters', kind, 'node_modules', '.bin', CLIS[kind].adapter.bin);
156
162
  }
157
163
  export function run(command, args, timeoutMs, detached = false, signal) {
158
164
  return new Promise((resolve) => {
159
165
  const child = spawn(command, args, {
160
166
  stdio: ['ignore', 'pipe', 'pipe'],
161
167
  timeout: timeoutMs,
162
- env: withoutProxy(),
168
+ env: childEnvironment(),
163
169
  detached,
164
170
  signal: detached ? undefined : signal,
165
171
  });
@@ -193,19 +199,18 @@ export function run(command, args, timeoutMs, detached = false, signal) {
193
199
  export function failureOf(ran, program) {
194
200
  return ran.output.trim().slice(-CAUSE_CHARACTERS) || `${program} exited with ${ran.status ?? 'a signal'}`;
195
201
  }
196
- export async function installAdapter(kind, signal) {
197
- const adapter = CLIS[kind].adapter;
198
- if (adapter === null)
199
- return null;
200
- const release = KIT_PACKAGE.peerDependencies[adapter.package];
201
- if ((await installedAdapter(kind)) === release)
202
- return null;
203
- const ran = await run('npm', ['install', '--prefix', prefix(kind), '--cache', join(kitHome(), 'npm-cache'), '--no-save', '--no-audit', '--no-fund', '--omit=optional', `${adapter.package}@${release}`], INSTALL_MS, true, signal);
204
- return ran.status === 0 ? null : failureOf(ran, 'npm');
202
+ export function adapterArchive(kind) {
203
+ return `${kind}-${KIT_PACKAGE.peerDependencies[CLIS[kind].adapter.package]}.tar.gz`;
205
204
  }
206
- export async function installCli(kind, signal) {
207
- const ran = await run('bash', ['-o', 'pipefail', '-c', CLIS[kind].install], INSTALL_MS, true, signal);
208
- return ran.status === 0 ? null : failureOf(ran, 'the install');
205
+ async function bounded(program, work, signal) {
206
+ const deadline = AbortSignal.timeout(INSTALL_MS);
207
+ const ran = await work(signal === undefined ? deadline : AbortSignal.any([signal, deadline]));
208
+ if (deadline.aborted && signal?.aborted !== true)
209
+ return `${program} did not end within ${INSTALL_MS / 1000} seconds`;
210
+ return ran.status === 0 ? null : failureOf(ran, program);
211
+ }
212
+ export function installCli(kind, signal) {
213
+ return bounded('the install', (within) => run('bash', ['-o', 'pipefail', '-c', CLIS[kind].install], INSTALL_MS, true, within), signal);
209
214
  }
210
215
  function loginShell() {
211
216
  return process.env.SHELL || userInfo().shell;
@@ -213,13 +218,19 @@ function loginShell() {
213
218
  const FOUND = 'house-kit-cli ';
214
219
  const LOOKUP = `found=$(command -v "$1") || exit 0; case $found in /*) ;; *) found=$(pwd -P)/$found ;; esac; printf "${FOUND}%s\\n" "$found"`;
215
220
  const USER_BIN = 'case ":$PATH:" in *":$HOME/.local/bin:"*) ;; *) PATH="$PATH:$HOME/.local/bin" ;; esac; export PATH';
216
- function inLoginShell(script, argument = '', signal) {
217
- return run(loginShell(), ['-l', '-i', '-c', `exec /bin/sh -c '${USER_BIN}; ${script}' sh ${argument}`], READ_MS, true, signal);
221
+ function inLoginShell(script, argument = '', signal, timeoutMs = READ_MS) {
222
+ return run(loginShell(), ['-l', '-i', '-c', `exec /bin/sh -c '${USER_BIN}; ${script}' sh ${argument}`], timeoutMs, true, signal);
218
223
  }
219
- export async function locate(kind, signal) {
220
- const ran = await inLoginShell(LOOKUP, CLIS[kind].bin, signal);
224
+ export async function onLoginPath(program, signal) {
225
+ const ran = await inLoginShell(LOOKUP, program, signal);
221
226
  return ran.stdout.split('\n').findLast((line) => line.startsWith(FOUND))?.slice(FOUND.length) ?? null;
222
227
  }
228
+ export function locate(kind, signal) {
229
+ return onLoginPath(CLIS[kind].bin, signal);
230
+ }
231
+ export function updateCli(kind) {
232
+ return bounded('the update', (within) => inLoginShell(CLIS[kind].update, '', within, INSTALL_MS));
233
+ }
223
234
  export async function loginPath() {
224
235
  const marker = 'house-kit-path ';
225
236
  const ran = await inLoginShell(`printf "${marker}%s\\n" "$PATH"`);
@@ -0,0 +1,120 @@
1
+ import { subscribe } from 'node:diagnostics_channel';
2
+ import { setTimeout as delay } from 'node:timers/promises';
3
+ import { HouseRefusal, retryDelay } from './api.js';
4
+ import { end, REPLACED, signInAgain } from './end.js';
5
+ import { readEnrolment } from './home.js';
6
+ import { relayed } from './relay.js';
7
+ import { Silence } from './silence.js';
8
+ import { endUnserved, KIT_WIRE, unserved } from './wire.js';
9
+ const PATH = '/kit/stream';
10
+ const SUBPROTOCOL = `house.kit.stream.${KIT_WIRE}`;
11
+ const REFUSAL_HEADER = 'x-house-refusal';
12
+ // House beats each Kit connection every thirty seconds, so two silent beats mean this Kit process cannot hear House.
13
+ export const CONNECTION_SILENCE_MS = 60_000;
14
+ // A stopping Kit waits up to two seconds for House to answer its close, so what it sent last reaches House and a House that does not answer holds no stop.
15
+ const CLOSE_ANSWER_MS = 2_000;
16
+ function connectionUrl(house) {
17
+ const url = new URL(PATH, house);
18
+ url.protocol = url.protocol === 'https:' ? 'wss:' : 'ws:';
19
+ return url;
20
+ }
21
+ function header(headers, name) {
22
+ for (let index = 0; index < headers.length; index += 2) {
23
+ if (headers[index].toString('latin1').toLowerCase() === name)
24
+ return headers[index + 1].toString('latin1');
25
+ }
26
+ return '';
27
+ }
28
+ let refused = null;
29
+ subscribe('undici:request:headers', (message) => {
30
+ const { request, response } = message;
31
+ if (!request.path.endsWith(PATH))
32
+ return;
33
+ refused = new HouseRefusal(PATH, response.statusCode, header(response.headers, REFUSAL_HEADER) || response.statusText);
34
+ });
35
+ export function holdConnection(handlers) {
36
+ let connection = null;
37
+ let socket = null;
38
+ let failures = 0;
39
+ let stopping = false;
40
+ const connect = async () => {
41
+ const { house, credential } = (await readEnrolment());
42
+ if (socket !== null || unserved() || stopping)
43
+ return;
44
+ refused = null;
45
+ const opening = new WebSocket(relayed(connectionUrl(house)), {
46
+ protocols: [SUBPROTOCOL],
47
+ headers: { authorization: `Bearer ${credential}` },
48
+ });
49
+ socket = opening;
50
+ let opened = false;
51
+ let silence = null;
52
+ const closed = (event) => {
53
+ silence?.stop();
54
+ silence = null;
55
+ if (socket === opening)
56
+ socket = null;
57
+ if (connection === opening)
58
+ connection = null;
59
+ handlers.closed();
60
+ process.stderr.write(`kit: connection closed ${event.code} ${event.reason}\n`);
61
+ if (stopping)
62
+ return;
63
+ if (event.reason === 'replaced')
64
+ end(REPLACED);
65
+ if (event.reason === 'credential_rejected' || refused?.status === 401) {
66
+ void signInAgain(credential);
67
+ return;
68
+ }
69
+ if (refused !== null)
70
+ endUnserved(refused.text);
71
+ if (!opened && refused !== null)
72
+ process.stderr.write(`kit: ${refused.message}\n`);
73
+ // A closed connection reopens in one to three seconds, spread so Kit processes one restart closed return apart; an opening House refused or left unanswered backs off on the jittered curve, retryable or not, since a resident outlives a House deploy.
74
+ setTimeout(() => void connect(), opened ? 1000 + Math.random() * 2000 : retryDelay(failures++));
75
+ };
76
+ opening.onopen = () => {
77
+ opened = true;
78
+ failures = 0;
79
+ connection = opening;
80
+ silence = new Silence(CONNECTION_SILENCE_MS, () => {
81
+ if (connection !== opening)
82
+ return;
83
+ connection = null;
84
+ opening.onclose = null;
85
+ opening.close();
86
+ closed(new CloseEvent('close', { code: 1006, reason: 'heartbeat_missed' }));
87
+ });
88
+ silence.heard();
89
+ handlers.opened();
90
+ };
91
+ opening.onmessage = (event) => {
92
+ silence?.heard();
93
+ const arrived = JSON.parse(String(event.data));
94
+ if (arrived.type === 'input')
95
+ handlers.call(arrived);
96
+ else if (arrived.type !== 'beat')
97
+ handlers.oneWayCall(arrived);
98
+ };
99
+ opening.onerror = () => undefined;
100
+ opening.onclose = closed;
101
+ };
102
+ void connect();
103
+ return {
104
+ send(oneWayCall) {
105
+ if (connection === null || connection.readyState !== WebSocket.OPEN)
106
+ return false;
107
+ connection.send(JSON.stringify(oneWayCall));
108
+ return true;
109
+ },
110
+ close() {
111
+ stopping = true;
112
+ const open = socket;
113
+ if (open === null)
114
+ return Promise.resolve();
115
+ const answered = new Promise((resolve) => open.addEventListener('close', () => resolve(), { once: true }));
116
+ open.close();
117
+ return Promise.race([answered, delay(CLOSE_ANSWER_MS)]);
118
+ },
119
+ };
120
+ }