@agentshouse/kit 0.2.1-cf669c6d1ecbb → 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 +16 -15
  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 +42 -9
  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 -189
  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 +37 -12
  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/README.md CHANGED
@@ -33,26 +33,27 @@ them out; running it again without the flag brings them back.
33
33
 
34
34
  `kit login` opens or prints a link you confirm in any browser, on this computer
35
35
  or another, continues on its own and keeps the Environment's credential in
36
- `~/.house-kit`, or in `$HOUSE_KIT_HOME` when it is set. `--environment <id>`
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
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;
39
- `--code <code>` connects immediately without a link.
38
+ only those Rooms and `--no-private` every Room but your Private Room; `--code <code>` connects immediately without a link.
40
39
  A login also 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, as it connects, copies each
48
- Room you chose for it as a Git repository in the workspace's `local-copies`.
49
- `house fetch` records House's changes on each copy's `refs/house/received`;
50
- rebase onto it, commit and run `house push --owner` in the copy, through the
51
- install command in the container. An Agent runs both, without `--owner`.
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
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 { signInAgain } 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);
@@ -1,23 +1,23 @@
1
1
  {
2
2
  "schemaVersion": 2,
3
- "version": "0.2.1-cf669c6d1ecbb",
3
+ "version": "0.2.1-cfb7b543f2af6",
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-cf669c6d1ecbb/connect-linux.sh"
8
+ "url": "https://github.com/agentshouse/kit/releases/download/v0.2.1-cfb7b543f2af6/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-cf669c6d1ecbb/connect-linux.sh"
14
+ "url": "https://github.com/agentshouse/kit/releases/download/v0.2.1-cfb7b543f2af6/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-cf669c6d1ecbb/connect-windows.ps1"
20
+ "url": "https://github.com/agentshouse/kit/releases/download/v0.2.1-cfb7b543f2af6/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
  }
@@ -17,6 +17,15 @@ 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 EXIT_PLAN_MODE = {
21
+ parse(value) {
22
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
23
+ throw new Error('_x.ai/exit_plan_mode needs an object');
24
+ }
25
+ return value;
26
+ },
27
+ };
28
+ export const CONVERSATION_INPUTS = new Set(['open', 'message', 'interrupt', 'kill', 'option', 'answer']);
20
29
  function causeOf(error) {
21
30
  return error instanceof Error ? error.message : String(error);
22
31
  }
@@ -347,7 +356,8 @@ export class Conversations {
347
356
  reader.session = sessionId;
348
357
  const app = client({ name: '@agentshouse/kit' })
349
358
  .onRequest('session/request_permission', ({ params, signal }) => this.ask(conversation, 'session/request_permission', params, false, signal))
350
- .onRequest('elicitation/create', ({ params, signal }) => this.ask(conversation, 'elicitation/create', params, asksSecret(params), signal));
359
+ .onRequest('elicitation/create', ({ params, signal }) => this.ask(conversation, 'elicitation/create', params, asksSecret(params), signal))
360
+ .onRequest('_x.ai/exit_plan_mode', EXIT_PLAN_MODE, ({ params, signal }) => this.ask(conversation, '_x.ai/exit_plan_mode', params, false, signal));
351
361
  const cli = await unlessAborted(this.kit.agents.cli(route.kind), conversation.killed.signal);
352
362
  const bridge = await openBridge(this.kit.house, this.kit.copies, conversation.id, conversation.killed.signal);
353
363
  if (conversation.kills > 0) {
package/dist/copies.js CHANGED
@@ -3,7 +3,7 @@ import { randomUUID } from 'node:crypto';
3
3
  import { mkdir, readFile, readdir, realpath, rename, rm, rmdir, stat, writeFile } from 'node:fs/promises';
4
4
  import { dirname, join } from 'node:path';
5
5
  import { finalRefusal, HouseRefusal, retrying } from './api.js';
6
- import { blobId, blobText, git, HOUSE_REF, importCommits, localCopies, revision, run, succeeded, tree, } from './git.js';
6
+ import { blobId, blobText, git, isText, HOUSE_REF, importCommits, localCopies, revision, run, succeeded, tree, } from './git.js';
7
7
  import { kitHome } from './home.js';
8
8
  import { operationId } from './operation.js';
9
9
  import { refusalOf } from './refusals.js';
@@ -29,6 +29,10 @@ const REBASED = new Set([
29
29
  function rebaseFixes(refusal) {
30
30
  return refusal.code === 'edit_conflict' && refusal.conflicts.some((code) => REBASED.has(code));
31
31
  }
32
+ function textOnly(paths) {
33
+ const [named, them] = paths.length === 1 ? [`${paths[0]} is`, 'it'] : [`${paths.join(', ')} are`, 'them'];
34
+ return `${named} not text, and house push sends text only; remove ${them} from the commit and place ${them} with house upload`;
35
+ }
32
36
  function short(commit) {
33
37
  return commit.slice(0, 12);
34
38
  }
@@ -572,7 +576,13 @@ export class LocalCopies {
572
576
  const after = await tree(copy.repository, commit);
573
577
  const moved = movedPaths(copy.moves, before, after);
574
578
  const arrived = new Set(moved.values());
575
- const text = (entry, path) => blobText(copy.repository, entry, path);
579
+ const binary = [];
580
+ for (const [path, entry] of after)
581
+ if (before.get(path) !== entry && !(await isText(copy.repository, entry)))
582
+ binary.push(path);
583
+ if (binary.length > 0)
584
+ throw new Error(textOnly(binary));
585
+ const text = (entry) => blobText(copy.repository, entry);
576
586
  const changes = [];
577
587
  for (const path of [...new Set([...before.keys(), ...after.keys()])].sort()) {
578
588
  if (arrived.has(path))
@@ -585,7 +595,7 @@ export class LocalCopies {
585
595
  changes.push({ op: 'rename', path: `${root}/${path}`, to: `${root}/${to}`, base: known });
586
596
  const moving = after.get(to);
587
597
  if (moving !== prior) {
588
- changes.push({ op: 'replace', path: `${root}/${to}`, base: known, content: await text(moving, to) });
598
+ changes.push({ op: 'replace', path: `${root}/${to}`, base: known, content: await text(moving) });
589
599
  }
590
600
  continue;
591
601
  }
@@ -594,9 +604,9 @@ export class LocalCopies {
594
604
  if (next === undefined)
595
605
  changes.push({ op: 'remove', path: `${root}/${path}`, base: known });
596
606
  else if (prior === undefined)
597
- changes.push({ op: 'create', path: `${root}/${path}`, content: await text(next, path) });
607
+ changes.push({ op: 'create', path: `${root}/${path}`, content: await text(next) });
598
608
  else
599
- changes.push(...changed(`${root}/${path}`, path, known, await text(prior, path), await text(next, path)));
609
+ changes.push(...changed(`${root}/${path}`, path, known, await text(prior), await text(next)));
600
610
  }
601
611
  return changes;
602
612
  }
@@ -663,7 +673,7 @@ export class LocalCopies {
663
673
  written.push({
664
674
  path: `${root}/${path}`,
665
675
  revision: entry === undefined ? null : (revisionAt(current, current.house, path) ?? null),
666
- content: entry === undefined ? null : await blobText(copy.repository, entry, path),
676
+ content: entry === undefined ? null : await blobText(copy.repository, entry),
667
677
  });
668
678
  }
669
679
  return this.finished(await this.save({ ...current, push: { ...push, state: 'accepted', written } }));
@@ -707,7 +717,7 @@ export class LocalCopies {
707
717
  {
708
718
  path: `${rootOf(copy.room_handle)}/${path}`,
709
719
  revision: entry === undefined ? null : (revisionAt(copy, copy.house, path) ?? null),
710
- content: entry === undefined ? null : await blobText(copy.repository, entry, path),
720
+ content: entry === undefined ? null : await blobText(copy.repository, entry),
711
721
  },
712
722
  ];
713
723
  }
@@ -752,7 +762,7 @@ export class LocalCopies {
752
762
  async landed(repository, changes, house, selected) {
753
763
  const text = async (path) => {
754
764
  const entry = house.get(relative(path));
755
- return entry === undefined ? undefined : blobText(repository, entry, path);
765
+ return entry === undefined ? undefined : blobText(repository, entry);
756
766
  };
757
767
  for (const change of changes) {
758
768
  const current = await text(change.path);
package/dist/end.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { forgetRejected } from './home.js';
2
+ import { installCommand } from './placement.js';
2
3
  import { killDescendants } from './scope.js';
3
4
  export const REPLACED = 'another Kit started for this Environment';
4
5
  function exit(reason, status) {
@@ -12,6 +13,9 @@ export function end(reason) {
12
13
  export function restart(reason) {
13
14
  exit(reason, 1);
14
15
  }
16
+ export function updateRequired(house) {
17
+ end(`This Kit is too old for House. Update it: ${installCommand(house)}`);
18
+ }
15
19
  export async function signInAgain(rejected) {
16
20
  await forgetRejected(rejected);
17
21
  restart('sign in again');
package/dist/files.js CHANGED
@@ -1,7 +1,13 @@
1
+ import { createHash } from 'node:crypto';
1
2
  import { mkdir, writeFile } from 'node:fs/promises';
2
3
  import { join } from 'node:path';
3
4
  import { HouseRefusal, retrying } from './api.js';
4
5
  import { relayed } from './relay.js';
6
+ export function verified(bytes, sha256, name) {
7
+ if (createHash('sha256').update(bytes).digest('hex') !== sha256)
8
+ throw new Error(`${name} did not arrive whole; download it again`);
9
+ return bytes;
10
+ }
5
11
  export async function placeFiles(house, directory, files, signal) {
6
12
  const paths = [];
7
13
  for (const file of files) {
@@ -16,7 +22,7 @@ export async function placeFiles(house, directory, files, signal) {
16
22
  });
17
23
  await mkdir(folder, { recursive: true });
18
24
  const path = join(folder, file.name);
19
- await writeFile(path, Buffer.from(await answer.arrayBuffer()));
25
+ await writeFile(path, verified(Buffer.from(await answer.arrayBuffer()), file.sha256, file.name));
20
26
  paths.push(path);
21
27
  }
22
28
  return paths;
package/dist/git.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { spawn } from 'node:child_process';
2
+ import { isUtf8 } from 'node:buffer';
2
3
  import { createHash } from 'node:crypto';
3
4
  import { join } from 'node:path';
4
5
  import { withoutProxy } from './clis.js';
@@ -48,14 +49,16 @@ export async function tree(repository, commit) {
48
49
  }
49
50
  return entries;
50
51
  }
51
- export async function blobText(repository, object, path) {
52
- const bytes = (await run(repository, ['cat-file', 'blob', object])).stdout;
53
- try {
54
- return new TextDecoder('utf-8', { fatal: true, ignoreBOM: true }).decode(bytes);
55
- }
56
- catch {
57
- throw new Error(`${path} is binary and House stores only text; remove it from the commit`);
58
- }
52
+ const TEXT_MAX_BYTES = 16 * 1024 * 1024;
53
+ async function blob(repository, object) {
54
+ return (await run(repository, ['cat-file', 'blob', object])).stdout;
55
+ }
56
+ export async function blobText(repository, object) {
57
+ return (await blob(repository, object)).toString('utf8');
58
+ }
59
+ export async function isText(repository, object) {
60
+ const bytes = await blob(repository, object);
61
+ return bytes.length <= TEXT_MAX_BYTES && isUtf8(bytes) && !bytes.includes(0);
59
62
  }
60
63
  export function blobId(content) {
61
64
  const bytes = Buffer.from(content, 'utf8');
package/dist/home.js CHANGED
@@ -1,6 +1,7 @@
1
- import { existsSync, linkSync, readFileSync, renameSync, rmSync } from 'node:fs';
1
+ import { randomUUID } from 'node:crypto';
2
+ import { accessSync, chmodSync, constants, existsSync, linkSync, lstatSync, mkdirSync, readFileSync, renameSync, rmSync } from 'node:fs';
2
3
  import { mkdir, readFile, rename, rm, writeFile } from 'node:fs/promises';
3
- import { homedir } from 'node:os';
4
+ import { homedir, tmpdir } from 'node:os';
4
5
  import { join } from 'node:path';
5
6
  import { selectRelay } from './relay.js';
6
7
  const ENROLMENT = 'credential.json';
@@ -8,8 +9,41 @@ const DISCONNECTED = 'disconnected.json';
8
9
  const CONFIGURATION = 'kit.json';
9
10
  const OWN_AGENT = 'own-agent.json';
10
11
  const RESTART = 'restart';
12
+ let defaulted;
13
+ function writable(directory) {
14
+ try {
15
+ accessSync(directory, constants.W_OK | constants.X_OK);
16
+ return true;
17
+ }
18
+ catch {
19
+ return false;
20
+ }
21
+ }
22
+ function ownTemporaryHome() {
23
+ const home = join(tmpdir(), `house-kit-${process.getuid()}`);
24
+ try {
25
+ mkdirSync(home, { mode: 0o700 });
26
+ }
27
+ catch (error) {
28
+ if (error.code !== 'EEXIST')
29
+ throw error;
30
+ }
31
+ const found = lstatSync(home);
32
+ if (found.isSymbolicLink())
33
+ throw new Error(`${home} is a symbolic link`);
34
+ if (!found.isDirectory())
35
+ throw new Error(`${home} is not a directory`);
36
+ if (found.uid !== process.getuid())
37
+ throw new Error(`${home} is not owned by this User`);
38
+ chmodSync(home, 0o700);
39
+ return home;
40
+ }
41
+ function defaultHome() {
42
+ const home = join(homedir(), '.house-kit');
43
+ return existsSync(home) || writable(homedir()) ? home : ownTemporaryHome();
44
+ }
11
45
  export function kitHome() {
12
- return process.env.HOUSE_KIT_HOME ?? join(homedir(), '.house-kit');
46
+ return process.env.HOUSE_KIT_HOME || (defaulted ??= defaultHome());
13
47
  }
14
48
  export function workspaceRoot() {
15
49
  return process.env.HOUSE_KIT_WORKSPACE ?? '/agents/house';
@@ -30,7 +64,7 @@ export async function readHome(name) {
30
64
  export async function writeHome(name, value) {
31
65
  const home = kitHome();
32
66
  await mkdir(home, { recursive: true, mode: 0o700 });
33
- const temporary = join(home, `${name}.${process.pid}`);
67
+ const temporary = join(home, `${name}.${randomUUID()}`);
34
68
  await writeFile(temporary, `${JSON.stringify(value)}\n`, { mode: 0o600 });
35
69
  await rename(temporary, join(home, name));
36
70
  }
@@ -47,6 +81,9 @@ export async function writeEnrolment(enrolment) {
47
81
  export function readDisconnected() {
48
82
  return readHome(DISCONNECTED);
49
83
  }
84
+ export function forgetDisconnected() {
85
+ return rm(join(kitHome(), DISCONNECTED), { force: true });
86
+ }
50
87
  export async function forgetEnrolment({ house, environment }) {
51
88
  await writeHome(DISCONNECTED, { house, environment });
52
89
  await rm(join(kitHome(), ENROLMENT), { force: true });