@agentshouse/kit 0.2.1-c5d36e97b0fea → 0.2.1-c5d51f1e4ce19

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 (89) hide show
  1. package/README.md +25 -24
  2. package/dist/agents.js +73 -7
  3. package/dist/api.js +6 -2
  4. package/dist/bootstrap.json +4 -4
  5. package/dist/chatgpt.js +32 -0
  6. package/dist/clis.js +42 -9
  7. package/dist/conversations.js +29 -9
  8. package/dist/copies.js +36 -26
  9. package/dist/end.js +17 -3
  10. package/dist/enrol-main.js +7 -1
  11. package/dist/events.js +3 -0
  12. package/dist/files.js +7 -1
  13. package/dist/git.js +11 -8
  14. package/dist/home.js +81 -6
  15. package/dist/house-cli.js +291 -0
  16. package/dist/house-main.js +7 -188
  17. package/dist/instructions.js +7 -31
  18. package/dist/kit-cli.js +68 -0
  19. package/dist/kit-main.js +8 -22
  20. package/dist/login.js +102 -21
  21. package/dist/parts.js +34 -16
  22. package/dist/placement.js +48 -0
  23. package/dist/relay.js +12 -2
  24. package/dist/resident.js +15 -6
  25. package/dist/service-main.js +9 -0
  26. package/dist/service.js +33 -0
  27. package/dist/skills.js +81 -12
  28. package/dist/stream.js +66 -15
  29. package/dist/transcription.js +3 -3
  30. package/dist/update.js +28 -6
  31. package/dist/wire.js +6 -0
  32. package/how-we-work.md +13 -3
  33. package/package.json +3 -2
  34. package/skills/ask-matt/SKILL.md +17 -11
  35. package/skills/ask-matt/agents/openai.yaml +1 -0
  36. package/skills/code-review/SKILL.md +5 -5
  37. package/skills/codebase-design/DESIGN-IT-TWICE.md +1 -1
  38. package/skills/codebase-design/SKILL.md +0 -2
  39. package/skills/diagnosing-bugs/SKILL.md +2 -4
  40. package/skills/domain-modeling/{CONTEXT-FORMAT.md → GLOSSARY-FORMAT.md} +10 -10
  41. package/skills/domain-modeling/SKILL.md +12 -14
  42. package/skills/grill-me/SKILL.md +1 -2
  43. package/skills/grill-me/agents/openai.yaml +1 -0
  44. package/skills/grill-with-docs/SKILL.md +1 -2
  45. package/skills/grill-with-docs/agents/openai.yaml +1 -0
  46. package/skills/grilling/SKILL.md +2 -2
  47. package/skills/handoff/SKILL.md +2 -3
  48. package/skills/handoff/agents/openai.yaml +1 -0
  49. package/skills/implement/SKILL.md +5 -4
  50. package/skills/implement/agents/openai.yaml +1 -0
  51. package/skills/implement-spec/SKILL.md +40 -0
  52. package/skills/implement-spec/agents/openai.yaml +5 -0
  53. package/skills/improve-codebase-architecture/SKILL.md +6 -7
  54. package/skills/improve-codebase-architecture/agents/openai.yaml +1 -0
  55. package/skills/pr/CREDITS.md +3 -0
  56. package/skills/pr/LICENSE +21 -0
  57. package/skills/pr/SKILL.md +170 -0
  58. package/skills/pr/agents/openai.yaml +3 -0
  59. package/skills/prototype/SKILL.md +0 -2
  60. package/skills/research/SKILL.md +0 -2
  61. package/skills/retro/LICENSE +21 -0
  62. package/skills/retro/SKILL.md +44 -0
  63. package/skills/retro/agents/openai.yaml +5 -0
  64. package/skills/tdd/SKILL.md +2 -4
  65. package/skills/teach/SKILL.md +3 -4
  66. package/skills/teach/agents/openai.yaml +1 -0
  67. package/skills/to-questionnaire/SKILL.md +1 -2
  68. package/skills/to-questionnaire/agents/openai.yaml +1 -0
  69. package/skills/to-spec/SKILL.md +1 -2
  70. package/skills/to-spec/agents/openai.yaml +1 -0
  71. package/skills/to-tickets/SKILL.md +3 -4
  72. package/skills/to-tickets/agents/openai.yaml +1 -0
  73. package/skills/triage/AGENT-BRIEF.md +207 -0
  74. package/skills/triage/LICENSE +21 -0
  75. package/skills/triage/OUT-OF-SCOPE.md +105 -0
  76. package/skills/triage/SKILL.md +112 -0
  77. package/skills/triage/agents/openai.yaml +5 -0
  78. package/skills/wait-what/SKILL.md +2 -3
  79. package/skills/wait-what/agents/openai.yaml +1 -0
  80. package/skills/wayfinder/SKILL.md +5 -6
  81. package/skills/wayfinder/agents/openai.yaml +1 -0
  82. package/skills/wizard/LICENSE +21 -0
  83. package/skills/wizard/SKILL.md +44 -0
  84. package/skills/wizard/agents/openai.yaml +3 -0
  85. package/skills/wizard/template.sh +223 -0
  86. package/skills/writing-for-agents/SKILL.md +0 -2
  87. package/skills/resolving-merge-conflicts/SKILL.md +0 -16
  88. package/skills/resolving-merge-conflicts/agents/openai.yaml +0 -3
  89. /package/skills/{resolving-merge-conflicts → implement-spec}/LICENSE +0 -0
package/README.md CHANGED
@@ -1,14 +1,12 @@
1
1
  # House Kit
2
2
 
3
- House Kit connects an Environment, a Linux computer or server, to
4
- [agents.house](https://agents.house). It runs your Agents' conversations
5
- through the agent CLIs you chose and gives each Agent the `house` command.
3
+ House Kit connects an Environment, a Linux computer or server, to [agents.house](https://agents.house). It runs
4
+ your Agents' conversations through the agent CLIs you chose and gives each Agent the `house` command.
6
5
 
7
6
  ## Install
8
7
 
9
- Run `curl -fsSL agents.house/kit | sh`, or `irm agents.house/kit.ps1 | iex` on
10
- Windows, and again to update; options follow `sh -s --`. On macOS and Linux it
11
- installs House Kit natively under your own account, without an admin password,
8
+ Run `curl -fsSL agents.house/kit | sh`, or `irm agents.house/kit.ps1 | iex` on Windows, and again to update;
9
+ options follow `sh -s --`. On macOS and Linux it installs House Kit natively under your own account, without an admin password,
12
10
  as a service that runs while you are logged in. `kit` and `house` are then on
13
11
  your login shell's `PATH`, and your workspace is `~/AgentsHouse` unless you
14
12
  pass `--workspace <path>`.
@@ -20,7 +18,7 @@ workspace. On Windows 11 the container is the one choice. Append a `kit` or
20
18
  Running the command for the other choice on a connected computer asks you to
21
19
  confirm, then replaces its Environment, whose Agents end, with a new one.
22
20
 
23
- On your own Ubuntu 26.04 server, run the Linux command with `--linux` to
21
+ On your own Linux server, run the Linux command with `--linux` to
24
22
  install House Kit natively, with its workspace at `/agents/house`; `kit` and
25
23
  `house` are then on the server's `PATH`.
26
24
 
@@ -33,26 +31,29 @@ them out; running it again without the flag brings them back.
33
31
 
34
32
  ## Commands
35
33
 
36
- `kit login` opens or prints a link you confirm in any browser, on this
37
- computer or another, continues on its own and keeps the Environment's
38
- credential in `~/.house-kit`, or in `$HOUSE_KIT_HOME` when it is set. Pass
39
- `--environment <id>` to reconnect an Environment you already have. It also
40
- connects your own agent: outside an Agent conversation, `house <tool>` calls
41
- House as you and `git` clones and pushes your Apps at `<house>/app/` as you,
42
- until you revoke that connection on Connections. `house help` lists the Tools.
43
- `kit logout` disconnects this computer, stops House Kit and ends your own
44
- agent's connection, so `house` and `git` no longer act as you here; a later
45
- `kit login` reconnects the same Environment.
46
-
47
- `kit resident` keeps the Environment connected and the Rooms you chose for it
48
- as Git repositories under `local-copies` in the workspace. `house fetch`
49
- records House's changes on each copy's `refs/house/received`; rebase onto it,
50
- commit and run `house push --owner` in the copy, through the install command in
51
- the container. An Agent runs both, without `--owner`.
34
+ `kit login` opens or prints a link you confirm in any browser, on this computer
35
+ or another, continues on its own and keeps the Environment's credential in
36
+ `$HOUSE_KIT_HOME` when it is set, else in `~/.house-kit`, or in `house-kit-<uid>` under the temporary directory when your home is read-only. `--environment <id>`
37
+ reconnects an Environment you already have; `--rooms <ref>[,<ref>...]` gives it
38
+ only those Rooms and `--no-private` every Room but your Private Room; `--code <code>` connects immediately without a link.
39
+ A login also connects your own agent: outside an Agent conversation, `house <tool>` calls
40
+ House as you and `git` clones and pushes your Apps at `<house>/app/` as you, until you revoke
41
+ that connection on Connections. `house help` lists the Tools. Codex sessions started after a
42
+ login run a lone `house` command outside their sandbox. `kit logout` disconnects this
43
+ computer, stops House Kit and ends your own agent's connection, so `house` and `git` no
44
+ longer act as you here; a later `kit login` reconnects the same Environment, or connects
45
+ this computer as a new one when House no longer holds it.
46
+ In a container you do not control, such as ChatGPT's, `npm i -g @agentshouse/kit` and `kit chatgpt --key <key>` with a key made on Connections let `house <tool>` act as you, starting and configuring nothing else.
47
+
48
+ `kit resident` keeps the Environment connected and, as it connects, copies the text of each Room
49
+ you chose for it as a Git repository in the workspace's `local-copies`. `house fetch` records
50
+ House's changes on each copy's `refs/house/received`; rebase onto it, commit and run
51
+ `house push --owner` in the copy, through the install command in the container. An Agent runs
52
+ both, without `--owner`. `house upload` and `house download` move a Room's other files.
52
53
 
53
54
  House Kit turns each audio file of your message to an Agent into text on this
54
55
  computer before the Agent reads it. While transcription is on, the speech
55
- engine and model use about 425 MB in `~/.house-kit`; turning it off deletes them.
56
+ engine and model use about 425 MB beside the Environment's credential; turning it off deletes them.
56
57
 
57
58
  ## License
58
59
 
package/dist/agents.js CHANGED
@@ -1,10 +1,15 @@
1
1
  import { client } from '@agentclientprotocol/sdk';
2
2
  import { readFile, realpath } from 'node:fs/promises';
3
+ import { setTimeout as delay } from 'node:timers/promises';
3
4
  import { startAdapter } from './acp.js';
4
5
  import { CLIS, KIT_VERSION, below, installAdapter, installCli, locate, run, versionOf } from './clis.js';
5
6
  import { agentBase, kitHome } from './home.js';
7
+ import { updatesItself } from './placement.js';
6
8
  import { killTree } from './scope.js';
7
9
  import { holdTranscription, transcriptionReport } from './transcription.js';
10
+ import { KIT_WIRE } from './wire.js';
11
+ // Two quiet seconds let a fresh conversation start before background model discovery competes for its CPU.
12
+ const MODEL_PROBE_QUIET_MS = 2_000;
8
13
  const SIGNED_OUT = { signed_in: false, models: [], modes: [] };
9
14
  function select(options, category) {
10
15
  const option = options.find((candidate) => candidate.category === category);
@@ -22,6 +27,22 @@ function causeOf(error) {
22
27
  function logged(error) {
23
28
  process.stderr.write(`kit: ${causeOf(error)}\n`);
24
29
  }
30
+ const LAPTOP_CHASSIS = new Set(['8', '9', '10', '14', '30', '31', '32']);
31
+ const DESKTOP_CHASSIS = new Set(['3', '4', '5', '6', '7', '15', '16']);
32
+ const SERVER_CHASSIS = new Set(['17', '18', '19', '20', '21', '22', '23', '24']);
33
+ export function chassisForm(value) {
34
+ const chassis = value.trim();
35
+ if (LAPTOP_CHASSIS.has(chassis))
36
+ return 'laptop';
37
+ if (DESKTOP_CHASSIS.has(chassis))
38
+ return 'desktop';
39
+ if (SERVER_CHASSIS.has(chassis))
40
+ return 'server';
41
+ return undefined;
42
+ }
43
+ export function hostVm(version) {
44
+ return /docker desktop|microsoft|wsl|linuxkit/i.test(version);
45
+ }
25
46
  async function models(kind, adapter, known) {
26
47
  const agent = adapter.connection.agent;
27
48
  const opened = await agent.request('session/new', { cwd: kitHome(), mcpServers: [] });
@@ -120,6 +141,22 @@ async function operatingSystem() {
120
141
  const release = await readFile('/etc/os-release', 'utf8');
121
142
  return /^PRETTY_NAME="?([^"\n]*)"?$/m.exec(release)?.[1] ?? release;
122
143
  }
144
+ async function hostForm() {
145
+ if (process.platform === 'darwin') {
146
+ const battery = await run('pmset', ['-g', 'batt'], 10_000);
147
+ return battery.status === 0 && battery.output.includes('InternalBattery') ? 'laptop' : 'desktop';
148
+ }
149
+ if (process.platform !== 'linux')
150
+ return undefined;
151
+ const [container, version, chassis] = await Promise.all([
152
+ readFile('/.dockerenv', 'utf8').then(() => true).catch(() => false),
153
+ readFile('/proc/version', 'utf8').catch(() => ''),
154
+ readFile('/sys/class/dmi/id/chassis_type', 'utf8').catch(() => ''),
155
+ ]);
156
+ if (container && hostVm(version))
157
+ return undefined;
158
+ return chassisForm(chassis);
159
+ }
123
160
  export class Agents {
124
161
  desired = { agents: [], routes: [], transcribe: false };
125
162
  house;
@@ -128,10 +165,17 @@ export class Agents {
128
165
  installing = Promise.resolve();
129
166
  readings = new Map();
130
167
  reads = new Map();
168
+ starts = 0;
131
169
  sending = Promise.resolve();
132
170
  sent = null;
133
- constructor(house) {
171
+ refreshing = 0;
172
+ changed;
173
+ constructor(house, changed = () => undefined) {
134
174
  this.house = house;
175
+ this.changed = changed;
176
+ }
177
+ idle() {
178
+ return this.refreshing === 0;
135
179
  }
136
180
  read() {
137
181
  return this.reading.then(() => undefined, () => undefined);
@@ -140,21 +184,31 @@ export class Agents {
140
184
  return this.desired.routes.find((route) => route.agent_id === agentId);
141
185
  }
142
186
  refresh() {
187
+ this.refreshing++;
188
+ this.changed();
143
189
  const reading = this.read().then(async () => {
144
190
  this.desired = await this.house.deliver('/kit/agents/desired', {});
145
191
  return this.desired;
146
192
  });
147
193
  this.reading = reading;
148
- return reading.then(({ agents, transcribe }) => {
194
+ reading
195
+ .then(({ agents, transcribe }) => Promise.all([
149
196
  holdTranscription(transcribe)
150
197
  .then((changed) => (changed ? this.report() : undefined))
151
- .catch(logged);
198
+ .catch(logged),
152
199
  Promise.all(agents.map((kind) => this.load(kind)))
153
200
  .then(() => this.report())
154
- .catch(logged);
201
+ .catch(logged),
202
+ ]))
203
+ .catch(() => undefined)
204
+ .finally(() => {
205
+ this.refreshing--;
206
+ this.changed();
155
207
  });
208
+ return reading.then(() => undefined);
156
209
  }
157
210
  cli(kind) {
211
+ this.starts += 1;
158
212
  return this.queue(kind, async () => {
159
213
  const resolved = await this.resolve(kind);
160
214
  if (!('cli' in resolved)) {
@@ -168,7 +222,7 @@ export class Agents {
168
222
  this.update(kind, { release, failure: null, signed_in: kept.signed_in, models: kept.models, modes: kept.modes });
169
223
  }
170
224
  const read = this.nextRead(kind);
171
- offer(kind, cli, kept)
225
+ this.quietOffer(kind, cli, kept)
172
226
  .then((offered) => {
173
227
  const current = this.readings.get(kind);
174
228
  if (this.reads.get(kind) === read && current?.release === release)
@@ -255,11 +309,19 @@ export class Agents {
255
309
  if (this.reads.get(kind) === current && !signal?.aborted)
256
310
  this.readings.set(kind, reading);
257
311
  }
312
+ async quietOffer(kind, cli, known) {
313
+ for (let seen = -1; seen !== this.starts;) {
314
+ seen = this.starts;
315
+ await delay(MODEL_PROBE_QUIET_MS);
316
+ }
317
+ return offer(kind, cli, known);
318
+ }
258
319
  async load(kind) {
259
320
  const known = this.readings.get(kind);
260
- if (known !== undefined && known.failure === null)
321
+ if (known !== undefined && known.failure === null && known.minimum === undefined)
261
322
  return;
262
- await this.examine(kind, SIGNED_OUT, offer);
323
+ await this.examine(kind, SIGNED_OUT, (kind, cli, known) => this.quietOffer(kind, cli, known));
324
+ await this.report();
263
325
  }
264
326
  async send() {
265
327
  const agents = this.desired.agents.flatMap((kind) => {
@@ -267,9 +329,13 @@ export class Agents {
267
329
  return reading === undefined ? [] : [reported(kind, reading)];
268
330
  });
269
331
  const hostKey = await sshHostKey();
332
+ const form = await hostForm();
270
333
  const body = {
271
334
  os: await operatingSystem(),
335
+ ...(form === undefined ? {} : { form }),
272
336
  kit_version: KIT_VERSION,
337
+ wire: KIT_WIRE,
338
+ updates_itself: await updatesItself(),
273
339
  agent_base: agentBase(),
274
340
  agents,
275
341
  transcription: transcriptionReport(),
package/dist/api.js CHANGED
@@ -1,8 +1,9 @@
1
1
  import { setTimeout as delay } from 'node:timers/promises';
2
- import { end, SIGN_IN_AGAIN } from './end.js';
2
+ import { signInAgain, updateRequired } from './end.js';
3
3
  import { readEnrolment } from './home.js';
4
4
  import { retryable } from './refusals.js';
5
5
  import { relayed } from './relay.js';
6
+ import { KIT_WIRE, KIT_WIRE_HEADER, tooOld } from './wire.js';
6
7
  export class HouseRefusal extends Error {
7
8
  status;
8
9
  text;
@@ -37,12 +38,15 @@ export async function post(house, path, body, credential, signal) {
37
38
  method: 'POST',
38
39
  headers: {
39
40
  'content-type': 'application/json',
41
+ [KIT_WIRE_HEADER]: String(KIT_WIRE),
40
42
  ...(credential === undefined ? {} : { authorization: `Bearer ${credential}` }),
41
43
  },
42
44
  body: JSON.stringify(body),
43
45
  signal,
44
46
  });
45
47
  const text = await answer.text();
48
+ if (!answer.ok && tooOld(text))
49
+ updateRequired(house);
46
50
  if (!answer.ok)
47
51
  throw new HouseRefusal(path, answer.status, text);
48
52
  return JSON.parse(text);
@@ -54,7 +58,7 @@ async function enrolledPost(path, body, signal) {
54
58
  }
55
59
  catch (error) {
56
60
  if (error instanceof HouseRefusal && error.status === 401)
57
- end(SIGN_IN_AGAIN);
61
+ await signInAgain(credential);
58
62
  throw error;
59
63
  }
60
64
  }
@@ -1,23 +1,23 @@
1
1
  {
2
2
  "schemaVersion": 2,
3
- "version": "0.2.1-c5d36e97b0fea",
3
+ "version": "0.2.1-c5d51f1e4ce19",
4
4
  "hosts": {
5
5
  "macos": {
6
6
  "asset": {
7
7
  "name": "connect-linux.sh",
8
- "url": "https://github.com/agentshouse/kit/releases/download/v0.2.1-c5d36e97b0fea/connect-linux.sh"
8
+ "url": "https://github.com/agentshouse/kit/releases/download/v0.2.1-c5d51f1e4ce19/connect-linux.sh"
9
9
  }
10
10
  },
11
11
  "linux": {
12
12
  "asset": {
13
13
  "name": "connect-linux.sh",
14
- "url": "https://github.com/agentshouse/kit/releases/download/v0.2.1-c5d36e97b0fea/connect-linux.sh"
14
+ "url": "https://github.com/agentshouse/kit/releases/download/v0.2.1-c5d51f1e4ce19/connect-linux.sh"
15
15
  }
16
16
  },
17
17
  "windows": {
18
18
  "asset": {
19
19
  "name": "connect-windows.ps1",
20
- "url": "https://github.com/agentshouse/kit/releases/download/v0.2.1-c5d36e97b0fea/connect-windows.ps1"
20
+ "url": "https://github.com/agentshouse/kit/releases/download/v0.2.1-c5d51f1e4ce19/connect-windows.ps1"
21
21
  }
22
22
  }
23
23
  }
@@ -0,0 +1,32 @@
1
+ import { parseArgs } from 'node:util';
2
+ import { placeAppGit } from './app-git.js';
3
+ import { kitHome, readOwnAgent, writeOwnAgent } from './home.js';
4
+ import { accepted, DEFAULT_HOUSE } from './login.js';
5
+ const KEY_SOURCE = 'New key for a script on Connections';
6
+ const USAGE = `usage: kit chatgpt --key <key> [--house <origin>]
7
+ --key <key> a key from ${KEY_SOURCE}
8
+ --house <origin> the House of the key, ${DEFAULT_HOUSE} unless one is stored
9
+ `;
10
+ export async function chatgpt(argv) {
11
+ const { values } = parseArgs({
12
+ args: argv,
13
+ options: { key: { type: 'string' }, house: { type: 'string' }, help: { type: 'boolean', default: false } },
14
+ });
15
+ if (values.help) {
16
+ process.stdout.write(USAGE);
17
+ return;
18
+ }
19
+ if (values.key === undefined)
20
+ throw new Error(`pass --key with a key from ${KEY_SOURCE}`);
21
+ const before = await readOwnAgent();
22
+ const house = values.house ?? before?.house ?? DEFAULT_HOUSE;
23
+ if (!(await accepted(house, values.key)))
24
+ throw new Error(`${house} does not accept this key; pass one from ${KEY_SOURCE}`);
25
+ const relay = process.env.HOUSE_KIT_RELAY || undefined;
26
+ await writeOwnAgent({ house, ...(relay === undefined ? {} : { relay }), credential: values.key });
27
+ await placeAppGit(before, await readOwnAgent()).catch((error) => process.stderr.write(`kit: ${error.message}\n`));
28
+ if (before !== null && before.credential !== values.key) {
29
+ process.stdout.write('This replaced the key this Kit home held; give each session its own HOUSE_KIT_HOME to keep its own key.\n');
30
+ }
31
+ process.stdout.write(`house now calls ${house} as you, with the key kept in ${kitHome()}.\n`);
32
+ }
package/dist/clis.js CHANGED
@@ -1,9 +1,14 @@
1
1
  import { spawn } from 'node:child_process';
2
+ import { randomUUID } from 'node:crypto';
2
3
  import { constants, readFileSync } from 'node:fs';
3
- import { access, mkdir, readFile, writeFile } from 'node:fs/promises';
4
+ import { access, mkdir, readFile, rename, writeFile } from 'node:fs/promises';
4
5
  import { homedir, userInfo } from 'node:os';
5
- import { delimiter, isAbsolute, join } from 'node:path';
6
+ import { delimiter, dirname, isAbsolute, join } from 'node:path';
6
7
  import { kitHome } from './home.js';
8
+ const HOUSE_EXECUTABLES = /^host_executable\(name = "house", paths = (\[.*\])\)$/m;
9
+ function houseRule(houses) {
10
+ return `prefix_rule(pattern = ["house"], decision = "allow")\nhost_executable(name = "house", paths = ${JSON.stringify(houses)})\n`;
11
+ }
7
12
  const RAW_SUBTYPES = [
8
13
  'background_tasks_changed',
9
14
  'task_started',
@@ -22,15 +27,37 @@ async function executable(path) {
22
27
  return false;
23
28
  }
24
29
  }
25
- async function allowHouseInCodex(path) {
30
+ async function listedHouses(file) {
31
+ let text;
32
+ try {
33
+ text = await readFile(file, 'utf8');
34
+ }
35
+ catch (error) {
36
+ if (error.code === 'ENOENT')
37
+ return [];
38
+ throw error;
39
+ }
40
+ try {
41
+ const listed = JSON.parse(HOUSE_EXECUTABLES.exec(text)?.[1] ?? '[]');
42
+ return Array.isArray(listed) ? listed.filter((house) => typeof house === 'string') : [];
43
+ }
44
+ catch {
45
+ return [];
46
+ }
47
+ }
48
+ export async function allowHouseInCodex(path) {
26
49
  const candidates = [...new Set(path.split(delimiter).filter((directory) => isAbsolute(directory)))].map((directory) => join(directory, 'house'));
27
- const houses = [];
28
- for (const candidate of candidates)
29
- if (await executable(candidate))
30
- houses.push(candidate);
31
50
  const rules = join(process.env.CODEX_HOME || join(homedir(), '.codex'), 'rules');
51
+ const file = join(rules, 'house.rules');
52
+ const houses = [];
53
+ for (const house of [...(await listedHouses(file)), ...candidates]) {
54
+ if (!houses.includes(house) && (await executable(house)))
55
+ houses.push(house);
56
+ }
32
57
  await mkdir(rules, { recursive: true });
33
- await writeFile(join(rules, 'house.rules'), `prefix_rule(pattern = ["house"], decision = "allow")\nhost_executable(name = "house", paths = ${JSON.stringify(houses)})\n`);
58
+ const temporary = `${file}.${randomUUID()}`;
59
+ await writeFile(temporary, houseRule(houses));
60
+ await rename(temporary, file);
34
61
  }
35
62
  async function nothing() { }
36
63
  function bridgeInClaudeSandbox(bridge) {
@@ -173,7 +200,7 @@ export async function installAdapter(kind, signal) {
173
200
  const release = KIT_PACKAGE.peerDependencies[adapter.package];
174
201
  if ((await installedAdapter(kind)) === release)
175
202
  return null;
176
- const ran = await run('npm', ['install', '--prefix', prefix(kind), '--no-save', '--no-audit', '--no-fund', '--omit=optional', `${adapter.package}@${release}`], INSTALL_MS, true, signal);
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);
177
204
  return ran.status === 0 ? null : failureOf(ran, 'npm');
178
205
  }
179
206
  export async function installCli(kind, signal) {
@@ -198,6 +225,12 @@ export async function loginPath() {
198
225
  const ran = await inLoginShell(`printf "${marker}%s\\n" "$PATH"`);
199
226
  return ran.stdout.split('\n').findLast((line) => line.startsWith(marker)).slice(marker.length);
200
227
  }
228
+ export async function writeCodexRule() {
229
+ const shell = await loginPath().catch(() => '');
230
+ await allowHouseInCodex([dirname(process.execPath), process.env.PATH ?? '', shell].join(delimiter)).catch((error) => {
231
+ throw new Error(`Codex's rule for house could not be written: ${error.message}`);
232
+ });
233
+ }
201
234
  export async function versionOf(path, signal) {
202
235
  return VERSION.exec((await run(path, ['--version'], READ_MS, false, signal)).stdout)?.[0] ?? null;
203
236
  }
@@ -6,7 +6,7 @@ import { unlessAborted } from './abort.js';
6
6
  import { startAdapter } from './acp.js';
7
7
  import { openBridge } from './bridge.js';
8
8
  import { CLIS } from './clis.js';
9
- import { readerFor } from './events.js';
9
+ import { answeredFailure, readerFor } from './events.js';
10
10
  import { placeFiles, uploadBytes } from './files.js';
11
11
  import { agentBase } from './home.js';
12
12
  import { instructions } from './instructions.js';
@@ -17,6 +17,16 @@ import { createHowWeWork } from './skills.js';
17
17
  import { transcribe } from './transcription.js';
18
18
  import { workFor } from './work.js';
19
19
  const KILLED = 'the conversation was killed';
20
+ const REFUSED = 'the CLI refused the prompt';
21
+ const EXIT_PLAN_MODE = {
22
+ parse(value) {
23
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
24
+ throw new Error('_x.ai/exit_plan_mode needs an object');
25
+ }
26
+ return value;
27
+ },
28
+ };
29
+ export const CONVERSATION_INPUTS = new Set(['open', 'message', 'interrupt', 'kill', 'option', 'answer']);
20
30
  function causeOf(error) {
21
31
  return error instanceof Error ? error.message : String(error);
22
32
  }
@@ -132,6 +142,9 @@ export class Conversations {
132
142
  return false;
133
143
  return !conversations.some((conversation) => conversation.running?.scope.working() || [...conversation.leftovers].some((scope) => scope.working()));
134
144
  }
145
+ quiet() {
146
+ return this.idle() && [...this.conversations.values()].every((conversation) => conversation.open === 0);
147
+ }
135
148
  look() {
136
149
  for (const conversation of this.conversations.values()) {
137
150
  for (const scope of conversation.leftovers) {
@@ -344,7 +357,8 @@ export class Conversations {
344
357
  reader.session = sessionId;
345
358
  const app = client({ name: '@agentshouse/kit' })
346
359
  .onRequest('session/request_permission', ({ params, signal }) => this.ask(conversation, 'session/request_permission', params, false, signal))
347
- .onRequest('elicitation/create', ({ params, signal }) => this.ask(conversation, 'elicitation/create', params, asksSecret(params), signal));
360
+ .onRequest('elicitation/create', ({ params, signal }) => this.ask(conversation, 'elicitation/create', params, asksSecret(params), signal))
361
+ .onRequest('_x.ai/exit_plan_mode', EXIT_PLAN_MODE, ({ params, signal }) => this.ask(conversation, '_x.ai/exit_plan_mode', params, false, signal));
348
362
  const cli = await unlessAborted(this.kit.agents.cli(route.kind), conversation.killed.signal);
349
363
  const bridge = await openBridge(this.kit.house, this.kit.copies, conversation.id, conversation.killed.signal);
350
364
  if (conversation.kills > 0) {
@@ -487,19 +501,21 @@ export class Conversations {
487
501
  this.kit.changed();
488
502
  return turn;
489
503
  }
490
- end(conversation, turn, failed) {
504
+ end(conversation, turn, failed, notice = null) {
491
505
  if (turn.ended)
492
506
  return;
493
507
  if (conversation.turn === turn) {
494
508
  for (const event of conversation.running?.reader.closeTurn() ?? [])
495
509
  this.apply(conversation, turn, event);
496
510
  }
511
+ if (notice !== null)
512
+ turn.parts.start({ type: 'marker', marker: 'retry', text: notice });
497
513
  turn.ended = true;
498
514
  conversation.open--;
499
515
  if (conversation.turn === turn)
500
516
  conversation.turn = null;
501
517
  const body = Promise.allSettled(turn.uploads).then(() => ({
502
- parts: turn.parts.parts,
518
+ parts: turn.parts.saved(),
503
519
  context: turn.parts.context,
504
520
  ...failed,
505
521
  }));
@@ -511,7 +527,11 @@ export class Conversations {
511
527
  const running = conversation.running;
512
528
  const turn = this.begin(conversation);
513
529
  turn.prompted = true;
514
- running.adapter.connection.agent.request('session/prompt', { sessionId: running.sessionId, prompt }).then(() => this.end(conversation, turn, null), async (error) => {
530
+ running.adapter.connection.agent.request('session/prompt', { sessionId: running.sessionId, prompt }).then((answer) => {
531
+ const notice = answeredFailure(answer);
532
+ const failed = notice ?? (answer.stopReason === 'refusal' ? REFUSED : null);
533
+ this.end(conversation, turn, failed === null ? null : { failed }, notice);
534
+ }, async (error) => {
515
535
  if (running.adapter.connection.signal.aborted) {
516
536
  this.end(conversation, turn, { failed: running.killed ? KILLED : await running.adapter.exited });
517
537
  }
@@ -644,7 +664,7 @@ export class Conversations {
644
664
  turn.parts.plan(event.entries);
645
665
  return;
646
666
  case 'image':
647
- turn.uploads.push(this.image(conversation, turn, event.data, event.mediaType));
667
+ turn.uploads.push(this.image(conversation, turn, turn.parts.reserve(), event.data, event.mediaType));
648
668
  this.kit.changed();
649
669
  return;
650
670
  }
@@ -664,7 +684,7 @@ export class Conversations {
664
684
  else
665
685
  conversation.turn.parts.start(part);
666
686
  }
667
- async image(conversation, turn, data, mediaType) {
687
+ async image(conversation, turn, reserved, data, mediaType) {
668
688
  const bytes = Buffer.from(data, 'base64');
669
689
  const name = `image-${++turn.images}.${mediaType.split('/')[1]}`;
670
690
  try {
@@ -677,10 +697,10 @@ export class Conversations {
677
697
  const saved = declared.upload === undefined ? declared : await uploadBytes(declared.upload, bytes);
678
698
  if (saved.save.status !== 'saved')
679
699
  throw new Error(saved.save.failure ?? saved.save.status);
680
- turn.parts.start({ type: 'image', file: saved.version, name, media_type: mediaType });
700
+ turn.parts.arrive({ type: 'image', file: saved.version, name, media_type: mediaType }, reserved);
681
701
  }
682
702
  catch (error) {
683
- turn.parts.start({ type: 'marker', marker: 'retry', text: `${name} was not saved: ${causeOf(error)}` });
703
+ turn.parts.arrive({ type: 'marker', marker: 'retry', text: `${name} was not saved: ${causeOf(error)}` }, reserved);
684
704
  }
685
705
  }
686
706
  }