@agentshouse/kit 0.2.1-c903d1429e34a → 0.2.1-c9a26041e119a

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 (83) hide show
  1. package/README.md +16 -15
  2. package/dist/agents.js +58 -4
  3. package/dist/api.js +5 -1
  4. package/dist/bootstrap.json +4 -4
  5. package/dist/chatgpt.js +26 -0
  6. package/dist/clis.js +42 -9
  7. package/dist/conversations.js +6 -5
  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-main.js +165 -65
  14. package/dist/instructions.js +4 -29
  15. package/dist/kit-main.js +53 -8
  16. package/dist/login.js +39 -13
  17. package/dist/parts.js +34 -16
  18. package/dist/placement.js +48 -0
  19. package/dist/relay.js +1 -1
  20. package/dist/resident.js +8 -4
  21. package/dist/skills.js +81 -12
  22. package/dist/stream.js +62 -13
  23. package/dist/transcription.js +3 -3
  24. package/dist/update.js +28 -6
  25. package/dist/wire.js +6 -0
  26. package/how-we-work.md +13 -3
  27. package/package.json +2 -1
  28. package/skills/ask-matt/SKILL.md +17 -11
  29. package/skills/ask-matt/agents/openai.yaml +1 -0
  30. package/skills/code-review/SKILL.md +5 -5
  31. package/skills/codebase-design/DESIGN-IT-TWICE.md +1 -1
  32. package/skills/codebase-design/SKILL.md +0 -2
  33. package/skills/diagnosing-bugs/SKILL.md +2 -4
  34. package/skills/domain-modeling/{CONTEXT-FORMAT.md → GLOSSARY-FORMAT.md} +10 -10
  35. package/skills/domain-modeling/SKILL.md +12 -14
  36. package/skills/grill-me/SKILL.md +1 -2
  37. package/skills/grill-me/agents/openai.yaml +1 -0
  38. package/skills/grill-with-docs/SKILL.md +1 -2
  39. package/skills/grill-with-docs/agents/openai.yaml +1 -0
  40. package/skills/grilling/SKILL.md +2 -2
  41. package/skills/handoff/SKILL.md +2 -3
  42. package/skills/handoff/agents/openai.yaml +1 -0
  43. package/skills/implement/SKILL.md +5 -4
  44. package/skills/implement/agents/openai.yaml +1 -0
  45. package/skills/implement-spec/SKILL.md +40 -0
  46. package/skills/implement-spec/agents/openai.yaml +5 -0
  47. package/skills/improve-codebase-architecture/SKILL.md +6 -7
  48. package/skills/improve-codebase-architecture/agents/openai.yaml +1 -0
  49. package/skills/pr/CREDITS.md +3 -0
  50. package/skills/pr/LICENSE +21 -0
  51. package/skills/pr/SKILL.md +170 -0
  52. package/skills/pr/agents/openai.yaml +3 -0
  53. package/skills/prototype/SKILL.md +0 -2
  54. package/skills/research/SKILL.md +0 -2
  55. package/skills/retro/LICENSE +21 -0
  56. package/skills/retro/SKILL.md +44 -0
  57. package/skills/retro/agents/openai.yaml +5 -0
  58. package/skills/tdd/SKILL.md +2 -4
  59. package/skills/teach/SKILL.md +3 -4
  60. package/skills/teach/agents/openai.yaml +1 -0
  61. package/skills/to-questionnaire/SKILL.md +1 -2
  62. package/skills/to-questionnaire/agents/openai.yaml +1 -0
  63. package/skills/to-spec/SKILL.md +1 -2
  64. package/skills/to-spec/agents/openai.yaml +1 -0
  65. package/skills/to-tickets/SKILL.md +3 -4
  66. package/skills/to-tickets/agents/openai.yaml +1 -0
  67. package/skills/triage/AGENT-BRIEF.md +207 -0
  68. package/skills/triage/LICENSE +21 -0
  69. package/skills/triage/OUT-OF-SCOPE.md +105 -0
  70. package/skills/triage/SKILL.md +112 -0
  71. package/skills/triage/agents/openai.yaml +5 -0
  72. package/skills/wait-what/SKILL.md +2 -3
  73. package/skills/wait-what/agents/openai.yaml +1 -0
  74. package/skills/wayfinder/SKILL.md +5 -6
  75. package/skills/wayfinder/agents/openai.yaml +1 -0
  76. package/skills/wizard/LICENSE +21 -0
  77. package/skills/wizard/SKILL.md +44 -0
  78. package/skills/wizard/agents/openai.yaml +3 -0
  79. package/skills/wizard/template.sh +223 -0
  80. package/skills/writing-for-agents/SKILL.md +0 -2
  81. package/skills/resolving-merge-conflicts/SKILL.md +0 -16
  82. package/skills/resolving-merge-conflicts/agents/openai.yaml +0 -3
  83. /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
@@ -3,8 +3,10 @@ import { readFile, realpath } from 'node:fs/promises';
3
3
  import { startAdapter } from './acp.js';
4
4
  import { CLIS, KIT_VERSION, below, installAdapter, installCli, locate, run, versionOf } from './clis.js';
5
5
  import { agentBase, kitHome } from './home.js';
6
+ import { updatesItself } from './placement.js';
6
7
  import { killTree } from './scope.js';
7
8
  import { holdTranscription, transcriptionReport } from './transcription.js';
9
+ import { KIT_WIRE } from './wire.js';
8
10
  const SIGNED_OUT = { signed_in: false, models: [], modes: [] };
9
11
  function select(options, category) {
10
12
  const option = options.find((candidate) => candidate.category === category);
@@ -22,6 +24,22 @@ function causeOf(error) {
22
24
  function logged(error) {
23
25
  process.stderr.write(`kit: ${causeOf(error)}\n`);
24
26
  }
27
+ const LAPTOP_CHASSIS = new Set(['8', '9', '10', '14', '30', '31', '32']);
28
+ const DESKTOP_CHASSIS = new Set(['3', '4', '5', '6', '7', '15', '16']);
29
+ const SERVER_CHASSIS = new Set(['17', '18', '19', '20', '21', '22', '23', '24']);
30
+ export function chassisForm(value) {
31
+ const chassis = value.trim();
32
+ if (LAPTOP_CHASSIS.has(chassis))
33
+ return 'laptop';
34
+ if (DESKTOP_CHASSIS.has(chassis))
35
+ return 'desktop';
36
+ if (SERVER_CHASSIS.has(chassis))
37
+ return 'server';
38
+ return undefined;
39
+ }
40
+ export function hostVm(version) {
41
+ return /docker desktop|microsoft|wsl|linuxkit/i.test(version);
42
+ }
25
43
  async function models(kind, adapter, known) {
26
44
  const agent = adapter.connection.agent;
27
45
  const opened = await agent.request('session/new', { cwd: kitHome(), mcpServers: [] });
@@ -120,6 +138,22 @@ async function operatingSystem() {
120
138
  const release = await readFile('/etc/os-release', 'utf8');
121
139
  return /^PRETTY_NAME="?([^"\n]*)"?$/m.exec(release)?.[1] ?? release;
122
140
  }
141
+ async function hostForm() {
142
+ if (process.platform === 'darwin') {
143
+ const battery = await run('pmset', ['-g', 'batt'], 10_000);
144
+ return battery.status === 0 && battery.output.includes('InternalBattery') ? 'laptop' : 'desktop';
145
+ }
146
+ if (process.platform !== 'linux')
147
+ return undefined;
148
+ const [container, version, chassis] = await Promise.all([
149
+ readFile('/.dockerenv', 'utf8').then(() => true).catch(() => false),
150
+ readFile('/proc/version', 'utf8').catch(() => ''),
151
+ readFile('/sys/class/dmi/id/chassis_type', 'utf8').catch(() => ''),
152
+ ]);
153
+ if (container && hostVm(version))
154
+ return undefined;
155
+ return chassisForm(chassis);
156
+ }
123
157
  export class Agents {
124
158
  desired = { agents: [], routes: [], transcribe: false };
125
159
  house;
@@ -130,8 +164,14 @@ export class Agents {
130
164
  reads = new Map();
131
165
  sending = Promise.resolve();
132
166
  sent = null;
133
- constructor(house) {
167
+ refreshing = 0;
168
+ changed;
169
+ constructor(house, changed = () => undefined) {
134
170
  this.house = house;
171
+ this.changed = changed;
172
+ }
173
+ idle() {
174
+ return this.refreshing === 0;
135
175
  }
136
176
  read() {
137
177
  return this.reading.then(() => undefined, () => undefined);
@@ -140,19 +180,28 @@ export class Agents {
140
180
  return this.desired.routes.find((route) => route.agent_id === agentId);
141
181
  }
142
182
  refresh() {
183
+ this.refreshing++;
184
+ this.changed();
143
185
  const reading = this.read().then(async () => {
144
186
  this.desired = await this.house.deliver('/kit/agents/desired', {});
145
187
  return this.desired;
146
188
  });
147
189
  this.reading = reading;
148
- return reading.then(({ agents, transcribe }) => {
190
+ reading
191
+ .then(({ agents, transcribe }) => Promise.all([
149
192
  holdTranscription(transcribe)
150
193
  .then((changed) => (changed ? this.report() : undefined))
151
- .catch(logged);
194
+ .catch(logged),
152
195
  Promise.all(agents.map((kind) => this.load(kind)))
153
196
  .then(() => this.report())
154
- .catch(logged);
197
+ .catch(logged),
198
+ ]))
199
+ .catch(() => undefined)
200
+ .finally(() => {
201
+ this.refreshing--;
202
+ this.changed();
155
203
  });
204
+ return reading.then(() => undefined);
156
205
  }
157
206
  cli(kind) {
158
207
  return this.queue(kind, async () => {
@@ -260,6 +309,7 @@ export class Agents {
260
309
  if (known !== undefined && known.failure === null && known.minimum === undefined)
261
310
  return;
262
311
  await this.examine(kind, SIGNED_OUT, offer);
312
+ await this.report();
263
313
  }
264
314
  async send() {
265
315
  const agents = this.desired.agents.flatMap((kind) => {
@@ -267,9 +317,13 @@ export class Agents {
267
317
  return reading === undefined ? [] : [reported(kind, reading)];
268
318
  });
269
319
  const hostKey = await sshHostKey();
320
+ const form = await hostForm();
270
321
  const body = {
271
322
  os: await operatingSystem(),
323
+ ...(form === undefined ? {} : { form }),
272
324
  kit_version: KIT_VERSION,
325
+ wire: KIT_WIRE,
326
+ updates_itself: await updatesItself(),
273
327
  agent_base: agentBase(),
274
328
  agents,
275
329
  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-c903d1429e34a",
3
+ "version": "0.2.1-c9a26041e119a",
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-c903d1429e34a/connect-linux.sh"
8
+ "url": "https://github.com/agentshouse/kit/releases/download/v0.2.1-c9a26041e119a/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-c903d1429e34a/connect-linux.sh"
14
+ "url": "https://github.com/agentshouse/kit/releases/download/v0.2.1-c9a26041e119a/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-c903d1429e34a/connect-windows.ps1"
20
+ "url": "https://github.com/agentshouse/kit/releases/download/v0.2.1-c9a26041e119a/connect-windows.ps1"
21
21
  }
22
22
  }
23
23
  }
@@ -0,0 +1,26 @@
1
+ import { parseArgs } from 'node:util';
2
+ import { kitHome, readOwnAgent, writeOwnAgent } from './home.js';
3
+ import { accepted, DEFAULT_HOUSE } from './login.js';
4
+ const KEY_SOURCE = 'New key for a script on Connections';
5
+ const USAGE = `usage: kit chatgpt --key <key> [--house <origin>]
6
+ --key <key> a key from ${KEY_SOURCE}
7
+ --house <origin> the House of the key, ${DEFAULT_HOUSE} unless one is stored
8
+ `;
9
+ export async function chatgpt(argv) {
10
+ const { values } = parseArgs({
11
+ args: argv,
12
+ options: { key: { type: 'string' }, house: { type: 'string' }, help: { type: 'boolean', default: false } },
13
+ });
14
+ if (values.help) {
15
+ process.stdout.write(USAGE);
16
+ return;
17
+ }
18
+ if (values.key === undefined)
19
+ throw new Error(`pass --key with a key from ${KEY_SOURCE}`);
20
+ const house = values.house ?? (await readOwnAgent())?.house ?? DEFAULT_HOUSE;
21
+ if (!(await accepted(house, values.key)))
22
+ throw new Error(`${house} does not accept this key; pass one from ${KEY_SOURCE}`);
23
+ const relay = process.env.HOUSE_KIT_RELAY || undefined;
24
+ await writeOwnAgent({ house, ...(relay === undefined ? {} : { relay }), credential: values.key });
25
+ process.stdout.write(`house now calls ${house} as you, with the key kept in ${kitHome()}.\n`);
26
+ }
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,7 @@ 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
+ export const CONVERSATION_INPUTS = new Set(['open', 'message', 'interrupt', 'kill', 'option', 'answer']);
20
21
  function causeOf(error) {
21
22
  return error instanceof Error ? error.message : String(error);
22
23
  }
@@ -502,7 +503,7 @@ export class Conversations {
502
503
  if (conversation.turn === turn)
503
504
  conversation.turn = null;
504
505
  const body = Promise.allSettled(turn.uploads).then(() => ({
505
- parts: turn.parts.parts,
506
+ parts: turn.parts.saved(),
506
507
  context: turn.parts.context,
507
508
  ...failed,
508
509
  }));
@@ -647,7 +648,7 @@ export class Conversations {
647
648
  turn.parts.plan(event.entries);
648
649
  return;
649
650
  case 'image':
650
- turn.uploads.push(this.image(conversation, turn, event.data, event.mediaType));
651
+ turn.uploads.push(this.image(conversation, turn, turn.parts.reserve(), event.data, event.mediaType));
651
652
  this.kit.changed();
652
653
  return;
653
654
  }
@@ -667,7 +668,7 @@ export class Conversations {
667
668
  else
668
669
  conversation.turn.parts.start(part);
669
670
  }
670
- async image(conversation, turn, data, mediaType) {
671
+ async image(conversation, turn, reserved, data, mediaType) {
671
672
  const bytes = Buffer.from(data, 'base64');
672
673
  const name = `image-${++turn.images}.${mediaType.split('/')[1]}`;
673
674
  try {
@@ -680,10 +681,10 @@ export class Conversations {
680
681
  const saved = declared.upload === undefined ? declared : await uploadBytes(declared.upload, bytes);
681
682
  if (saved.save.status !== 'saved')
682
683
  throw new Error(saved.save.failure ?? saved.save.status);
683
- turn.parts.start({ type: 'image', file: saved.version, name, media_type: mediaType });
684
+ turn.parts.arrive({ type: 'image', file: saved.version, name, media_type: mediaType }, reserved);
684
685
  }
685
686
  catch (error) {
686
- turn.parts.start({ type: 'marker', marker: 'retry', text: `${name} was not saved: ${causeOf(error)}` });
687
+ turn.parts.arrive({ type: 'marker', marker: 'retry', text: `${name} was not saved: ${causeOf(error)}` }, reserved);
687
688
  }
688
689
  }
689
690
  }
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 });