@agentshouse/kit 0.2.1-c3e4a20bb3183 → 0.2.1-c4d151f197958

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.
@@ -6,10 +6,14 @@ import { basename, join } from 'node:path';
6
6
  import { kitHome, readOwnAgent } from './home.js';
7
7
  import { callHouse, rpc, UNREACHABLE } from './mcp.js';
8
8
  import { refusalOf } from './refusals.js';
9
+ import { relayed } from './relay.js';
10
+ import { parse } from 'yaml';
9
11
  const USAGE = "usage: house <tool> ['<arguments as JSON>']";
10
- const GIT_USAGE = 'usage: house git push [commit] [--owner]';
12
+ const PUSH_USAGE = 'usage: house push [commit] [--owner]';
13
+ const PUSH = "push [commit]: sends the Local copy's committed changes to House";
11
14
  const ARGUMENTS = `the arguments are one JSON object in single quotes, like house search '{"query":"invoice"}'`;
12
15
  const CLOSED = "this conversation's House connection is closed; nothing to do from here";
16
+ const SANDBOXED = "your CLI's sandbox kept house from House; run house directly, not through another program";
13
17
  const REVOKED = 'this conversation no longer has House access; nothing to do from here';
14
18
  const UNCONNECTED = "this computer's own agent has no House connection; run kit login";
15
19
  const DISCONNECTED = "House no longer accepts this computer's own agent; run kit login";
@@ -41,7 +45,7 @@ function bridged(path, body, headers = { 'content-type': 'application/json' }, t
41
45
  reject(new Error(refused(path, answer.statusCode, text)));
42
46
  });
43
47
  });
44
- sent.on('error', () => reject(new Error(CLOSED)));
48
+ sent.on('error', (error) => reject(new Error(error.code === 'EPERM' || error.code === 'EACCES' ? SANDBOXED : CLOSED)));
45
49
  sent.end(body instanceof Buffer ? body : JSON.stringify(body));
46
50
  });
47
51
  }
@@ -77,11 +81,24 @@ async function localFile(path) {
77
81
  : `${path} is not a readable file`);
78
82
  }
79
83
  }
84
+ async function sent(url, bytes, operation) {
85
+ const headers = { 'content-type': 'application/octet-stream', 'x-house-byte-operation': operation };
86
+ if (socketPath !== undefined)
87
+ return bridged(url, bytes, headers);
88
+ setGlobalProxyFromEnv();
89
+ const answer = await fetch(relayed(url), { method: 'POST', headers, body: bytes }).catch(() => {
90
+ throw new Error(UNREACHABLE);
91
+ });
92
+ const text = await answer.text();
93
+ if (answer.status === 200)
94
+ return text;
95
+ throw new Error(refused(url, answer.status, text));
96
+ }
80
97
  async function upload(path, roomRef, missing) {
81
98
  if (typeof path !== 'string' || path === '')
82
99
  throw new Error(missing);
83
100
  const bytes = await localFile(path);
84
- const declared = JSON.parse(await bridged('/kit/attachments/upload', {
101
+ const declared = parse(await called('upload', {
85
102
  ...(roomRef === undefined ? {} : { room_ref: roomRef }),
86
103
  name: basename(path),
87
104
  bytes: bytes.length,
@@ -89,25 +106,20 @@ async function upload(path, roomRef, missing) {
89
106
  }));
90
107
  if (declared.upload === undefined)
91
108
  return declared.attachment;
92
- const saved = JSON.parse(await bridged(declared.upload.url, bytes, {
93
- 'content-type': 'application/octet-stream',
94
- 'x-house-byte-operation': declared.upload.operation,
95
- }));
109
+ const saved = JSON.parse(await sent(declared.upload.url, bytes, declared.upload.operation));
96
110
  if (saved.upload_failure !== undefined)
97
111
  throw new Error(`${path} was not saved: ${saved.upload_failure}; call again later`);
98
112
  return saved.attachment;
99
113
  }
100
- async function gitPush(args) {
114
+ async function push(args) {
101
115
  if (args.includes('--help'))
102
- return GIT_USAGE;
103
- if (args[0] !== 'push')
104
- throw new Error('only house git push [commit] exists; use plain git for the rest');
116
+ return PUSH_USAGE;
105
117
  const owner = args.includes('--owner');
106
- const commit = args.slice(1).find((arg) => arg !== '--owner') ?? 'HEAD';
118
+ const commit = args.find((arg) => arg !== '--owner') ?? 'HEAD';
107
119
  if (owner && socketPath !== undefined)
108
- throw new Error('--owner is not for Agent conversations; run house git push without it');
120
+ throw new Error('--owner is not for Agent conversations; run house push without it');
109
121
  if (!owner && socketPath === undefined)
110
- throw new Error('outside an Agent conversation, house git push needs --owner');
122
+ throw new Error('outside an Agent conversation, house push needs --owner');
111
123
  const pushed = JSON.parse(await bridged('/git/push', { cwd: process.cwd(), commit }, undefined, owner ? join(kitHome(), 'owner.sock') : socketPath));
112
124
  if (pushed.refused)
113
125
  throw new Error(pushed.text);
@@ -128,35 +140,40 @@ function argumentsOf(argument) {
128
140
  return parsed;
129
141
  }
130
142
  async function house([verb, argument]) {
131
- if (verb === undefined || verb === '--help') {
132
- return [USAGE, 'git push [commit]', ...(await tools()).map((tool) => `${tool.name}: ${tool.description}`)].join('\n');
143
+ if (verb === undefined || verb === '--help' || verb === 'help') {
144
+ return [USAGE, 'help', PUSH, ...(await tools()).map((tool) => (tool.description === undefined ? tool.name : `${tool.name}: ${tool.description}`))].join('\n');
133
145
  }
134
146
  if (argument === '--help') {
135
147
  const tool = (await tools()).find((listed) => listed.name === verb);
136
148
  if (tool === undefined)
137
149
  throw new Error(`${verb} is no Tool; house find_command '{"query":"${verb}"}' finds Commands`);
138
- return `${tool.description}\n${JSON.stringify(tool.inputSchema)}`;
150
+ return [...(tool.description === undefined ? [] : [tool.description]), JSON.stringify(tool.inputSchema)].join('\n');
139
151
  }
140
152
  const args = argumentsOf(argument);
141
- if (socketPath !== undefined && verb === 'upload_attachment') {
142
- return JSON.stringify({ attachment: await upload(args.path, args.room_ref, 'upload_attachment needs "path", a local file') });
153
+ if (verb === 'upload') {
154
+ return JSON.stringify({ attachment: await upload(args.path, args.room_ref, 'upload needs "path", a local file') });
143
155
  }
144
- if (socketPath !== undefined && verb === 'append_record' && Array.isArray(args.attachments)) {
156
+ if (verb === 'append_record' && Array.isArray(args.attachments)) {
145
157
  const attachments = [];
146
158
  for (const path of args.attachments) {
147
159
  attachments.push(await upload(path, args.room_ref, 'each attachments entry is the path of a local file'));
148
160
  }
149
161
  args.attachments = attachments;
150
162
  }
151
- const result = await mcp('tools/call', { name: verb, arguments: args });
163
+ return called(verb, args);
164
+ }
165
+ async function called(name, args) {
166
+ const result = await mcp('tools/call', { name, arguments: args });
152
167
  const text = result.content.map((content) => content.text).join('\n');
153
168
  if (result.isError === true)
154
169
  throw new Error(text.replace(/\n+$/, ''));
155
170
  return text;
156
171
  }
157
172
  const argv = process.argv.slice(2);
158
- (argv[0] === 'git' ? gitPush(argv.slice(1)) : house(argv)).then((text) => {
173
+ (argv[0] === 'push' ? push(argv.slice(1)) : house(argv)).then((text) => {
159
174
  process.stdout.write(`${text}\n`);
175
+ if (argv[0] === 'shell')
176
+ process.exitCode = Number(/^exit: (\d+)(?:\n|$)/.exec(text)?.[1] ?? 0);
160
177
  }, (error) => {
161
178
  process.stderr.write(`house: ${error instanceof Error ? error.message : String(error)}\n`);
162
179
  process.exitCode = 1;
@@ -1,8 +1,8 @@
1
1
  import { HOW_WE_WORK } from './skills.js';
2
2
  const HOUSE_LINE = 'Work with House through the `house` CLI: run `house --help`.';
3
- const FILE_LINE = 'To give the User a file or a page, upload it with `house upload_attachment` and link it; never start a server.';
4
- const READ_LINE = 'Before working in a Room, read `/private/rooms/<handle>/AGENTS.md`.';
5
- const COPIES_LINE = 'House Local copies; commit, then `house git push`:';
3
+ const FILE_LINE = 'To give the User a file or a page, upload it with `house upload` and link it; never start a server.';
4
+ const READ_LINE = 'Before working in a Room, read `/rooms/private/rooms/<handle>/AGENTS.md`.';
5
+ const COPIES_LINE = 'House Local copies; commit, then `house push`:';
6
6
  const UNREADABLE = /^(?:\S+: )?(?:path_not_found|room_not_found|operation_denied)\b/;
7
7
  const FAILED = /^exit: [1-9]\d*$/;
8
8
  const CUT = /^stderr: shell: output_cut (\d+) of \d+ bytes; continue with: (.+)$/;
package/dist/kit-main.js CHANGED
@@ -1,15 +1,21 @@
1
1
  #!/usr/bin/env node
2
2
  import { setGlobalProxyFromEnv } from 'node:http';
3
+ import { answerGitCredential } from './app-git.js';
3
4
  import { login } from './login.js';
5
+ import { logout } from './logout.js';
4
6
  import { resident } from './resident.js';
5
7
  const [command, ...argv] = process.argv.slice(2);
6
8
  setGlobalProxyFromEnv();
7
9
  async function run() {
8
10
  if (command === 'login')
9
11
  return login(argv);
12
+ if (command === 'logout')
13
+ return logout();
10
14
  if (command === 'resident')
11
15
  return resident();
12
- process.stderr.write('usage: kit <login|resident>\n');
16
+ if (command === 'git-credential')
17
+ return answerGitCredential(argv[0]);
18
+ process.stderr.write('usage: kit <login|logout|resident>\n');
13
19
  process.exitCode = 2;
14
20
  }
15
21
  run().catch((error) => {
package/dist/login.js CHANGED
@@ -1,53 +1,19 @@
1
+ import { spawn } from 'node:child_process';
1
2
  import { createHash, randomBytes } from 'node:crypto';
2
- import { createServer } from 'node:http';
3
3
  import { hostname } from 'node:os';
4
- import { createInterface } from 'node:readline/promises';
5
4
  import { parseArgs } from 'node:util';
6
- import { post } from './api.js';
7
- import { forgetOwnAgent, readEnrolment, readOwnAgent, writeEnrolment, writeOwnAgent } from './home.js';
5
+ import { post, retrying } from './api.js';
6
+ import { placeAppGit } from './app-git.js';
7
+ import { forgetOwnAgent, readDisconnected, readEnrolment, readOwnAgent, writeEnrolment, writeOwnAgent } from './home.js';
8
8
  import { callHouse, rpc } from './mcp.js';
9
9
  const DEFAULT_HOUSE = 'https://agents.house';
10
- function listen() {
11
- return new Promise((resolve, reject) => {
12
- let deliver = () => undefined;
13
- let held = null;
14
- const code = new Promise((settle) => {
15
- deliver = settle;
16
- });
17
- const server = createServer((request, response) => {
18
- const received = new URL(request.url ?? '/', 'http://127.0.0.1').searchParams.get('code');
19
- if (received === null || held !== null) {
20
- response.writeHead(404).end();
21
- return;
22
- }
23
- held = response;
24
- deliver(received);
25
- });
26
- const close = () => {
27
- server.close();
28
- server.closeAllConnections();
29
- };
30
- const port = Number(process.env.HOUSE_KIT_LOGIN_PORT ?? 0);
31
- server.once('error', reject);
32
- server.listen(port, port === 0 ? '127.0.0.1' : '0.0.0.0', () => {
33
- const address = server.address();
34
- if (address === null || typeof address === 'string') {
35
- reject(new Error('the login callback has no port'));
36
- return;
37
- }
38
- resolve({
39
- uri: `http://127.0.0.1:${address.port}/callback`,
40
- code,
41
- answer: (text) => new Promise((written) => {
42
- if (held === null || held.destroyed || !held.socket || held.socket.destroyed)
43
- return written();
44
- held.once('close', () => written());
45
- held.writeHead(200, { 'content-type': 'text/plain; charset=utf-8', connection: 'close' }).end(`${text}\n`);
46
- }),
47
- close,
48
- });
49
- });
50
- });
10
+ const OPENER = process.platform === 'darwin' ? 'open' : 'xdg-open';
11
+ // Polling every two seconds brings the User's confirmation to the waiting Kit moments after they give it.
12
+ const POLL_INTERVAL_MS = 2000;
13
+ function open(link) {
14
+ spawn(OPENER, [link], { detached: true, stdio: 'ignore' })
15
+ .on('error', () => undefined)
16
+ .unref();
51
17
  }
52
18
  async function accepted(house, credential) {
53
19
  const checked = await callHouse(house, credential, rpc('tools/list', {}));
@@ -57,80 +23,39 @@ async function accepted(house, credential) {
57
23
  return false;
58
24
  throw new Error(`House answered ${checked.status} when Kit checked this computer's own agent's connection: ${checked.text}`);
59
25
  }
60
- async function typed(question) {
61
- const reader = createInterface({ input: process.stdin, output: process.stdout });
62
- const closed = new Promise((_, reject) => {
63
- reader.once('close', () => reject(new Error('no code was typed')));
64
- });
65
- try {
66
- return (await Promise.race([reader.question(question), closed])).trim();
67
- }
68
- finally {
69
- reader.close();
70
- }
71
- }
72
26
  export async function login(argv) {
73
27
  const { values } = parseArgs({
74
28
  args: argv,
75
29
  options: {
76
30
  house: { type: 'string' },
77
31
  environment: { type: 'string' },
78
- manual: { type: 'boolean', default: false },
79
32
  },
80
33
  });
81
- const enrolled = await readEnrolment();
34
+ const enrolled = (await readEnrolment()) ?? (await readDisconnected());
82
35
  const house = values.house ?? enrolled?.house ?? DEFAULT_HOUSE;
83
36
  const replaces = process.env.HOUSE_KIT_REPLACES;
84
37
  const environment = replaces === undefined ? (values.environment ?? (enrolled?.house === house ? enrolled.environment : undefined)) : undefined;
85
38
  const ownAgent = await readOwnAgent();
86
39
  const held = ownAgent !== null && ownAgent.house === house && (await accepted(house, ownAgent.credential));
87
40
  const verifier = randomBytes(32).toString('base64url');
88
- const started = {
41
+ const started = await retrying(() => post(house, '/kit', {
89
42
  ...(environment === undefined
90
43
  ? { act: 'new_environment', label: hostname(), ...(replaces === undefined ? {} : { replaces }) }
91
44
  : { act: 'existing_environment', environment_id: environment }),
92
45
  code_challenge: createHash('sha256').update(verifier).digest('base64url'),
93
46
  ...(held ? {} : { headless: true }),
94
- };
95
- const exchange = async (code) => {
96
- const exchanged = await post(house, '/kit/token', { code, code_verifier: verifier });
97
- await writeEnrolment({ house, environment: exchanged.environment, credential: exchanged.credential });
98
- process.stdout.write(`Environment ${exchanged.environment} is connected to ${house}.\n`);
99
- if (exchanged.headless_credential !== undefined) {
100
- await writeOwnAgent({ house, user: exchanged.user, credential: exchanged.headless_credential });
101
- }
102
- else if (held && ownAgent.user !== exchanged.user) {
103
- await forgetOwnAgent();
104
- process.stdout.write("This computer's own agent was another User's; run kit login again to connect it to you.\n");
105
- }
106
- };
107
- if (values.manual) {
108
- const { start_url } = await post(house, '/kit', {
109
- ...started,
110
- presentation: 'manual',
111
- });
112
- process.stdout.write(`Open this link and confirm: ${start_url}\n`);
113
- await exchange(await typed('Code: '));
114
- return;
115
- }
116
- const callback = await listen();
117
- try {
118
- const { start_url } = await post(house, '/kit', {
119
- ...started,
120
- presentation: 'loopback',
121
- loopback_uri: callback.uri,
122
- });
123
- process.stdout.write(`Open this link and confirm: ${start_url}\n`);
124
- try {
125
- await exchange(await callback.code);
126
- }
127
- catch (error) {
128
- await callback.answer(`This Environment was not connected: ${error.message}`);
129
- throw error;
130
- }
131
- await callback.answer('This Environment is connected. You can close this tab.');
47
+ }));
48
+ process.stdout.write(`Open this link and confirm: ${started.start_url}\n`);
49
+ open(started.start_url);
50
+ const exchanged = await retrying(() => post(house, '/kit/token', { login: started.login, code_verifier: verifier }), undefined, () => POLL_INTERVAL_MS);
51
+ await writeEnrolment({ house, environment: exchanged.environment, credential: exchanged.credential });
52
+ process.stdout.write(`Environment ${exchanged.environment} is connected to ${house}.\n`);
53
+ if (exchanged.headless_credential !== undefined) {
54
+ await writeOwnAgent({ house, user: exchanged.user, credential: exchanged.headless_credential });
132
55
  }
133
- finally {
134
- callback.close();
56
+ else if (held && ownAgent.user !== exchanged.user) {
57
+ await forgetOwnAgent();
58
+ process.stdout.write("This computer's own agent was another User's; run kit login again to connect it to you.\n");
135
59
  }
60
+ await placeAppGit(ownAgent, await readOwnAgent());
136
61
  }
package/dist/logout.js ADDED
@@ -0,0 +1,27 @@
1
+ import { HouseRefusal, post } from './api.js';
2
+ import { forgetAppGit } from './app-git.js';
3
+ import { forgetEnrolment, forgetOwnAgent, readEnrolment, readOwnAgent } from './home.js';
4
+ const KEPT_CONNECTION = "House had already disconnected this computer, so its own agent's connection stays until you revoke it on Connections.\n";
5
+ export async function logout() {
6
+ const enrolled = await readEnrolment();
7
+ const ownAgent = await readOwnAgent();
8
+ let refused = false;
9
+ if (enrolled !== null) {
10
+ try {
11
+ await post(enrolled.house, '/kit/logout', {}, enrolled.credential);
12
+ }
13
+ catch (error) {
14
+ if (!(error instanceof HouseRefusal && error.status === 401))
15
+ throw error;
16
+ refused = true;
17
+ }
18
+ await forgetEnrolment(enrolled);
19
+ }
20
+ await forgetAppGit();
21
+ await forgetOwnAgent();
22
+ process.stdout.write(enrolled === null
23
+ ? 'This computer is not connected to House.\n'
24
+ : `Environment ${enrolled.environment} is disconnected; kit login reconnects it.\n`);
25
+ if (ownAgent !== null && (enrolled === null || refused))
26
+ process.stdout.write(KEPT_CONNECTION);
27
+ }
package/dist/mcp.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { randomUUID } from 'node:crypto';
2
2
  import { KIT_VERSION } from './clis.js';
3
+ import { relayed } from './relay.js';
3
4
  const MCP_PROTOCOL_VERSION = '2026-07-28';
4
5
  export const UNREACHABLE = 'House is unreachable; call again in a minute';
5
6
  export function rpc(method, params) {
@@ -21,7 +22,7 @@ export function mcpBody(message, operation) {
21
22
  }
22
23
  export async function callHouse(origin, credential, message, operation = null, signal) {
23
24
  const tool = message.method === 'tools/call' ? String(message.params.name) : null;
24
- const answer = await fetch(new URL('/', origin), {
25
+ const answer = await fetch(relayed(new URL('/', origin)), {
25
26
  method: 'POST',
26
27
  headers: {
27
28
  'content-type': 'application/json',
package/dist/parts.js ADDED
@@ -0,0 +1,64 @@
1
+ export class Parts {
2
+ parts = [];
3
+ context = null;
4
+ emit;
5
+ writing = null;
6
+ planned = null;
7
+ constructor(emit) {
8
+ this.emit = emit;
9
+ }
10
+ write(type, id, text) {
11
+ if (text === '')
12
+ return;
13
+ const last = this.parts.length - 1;
14
+ const part = this.parts[last];
15
+ if (this.writing?.type === type && this.writing.id === id && part?.type === type) {
16
+ part.text += text;
17
+ this.emit({ op: 'append', index: last, text });
18
+ return;
19
+ }
20
+ this.start({ type, text });
21
+ this.writing = { type, id };
22
+ }
23
+ command() {
24
+ const last = this.parts.length - 1;
25
+ const part = this.parts[last];
26
+ if (part?.type !== 'commands') {
27
+ this.start({ type: 'commands', count: 1 });
28
+ return;
29
+ }
30
+ part.count++;
31
+ this.emit({ op: 'count', index: last, count: part.count });
32
+ }
33
+ start(part) {
34
+ this.writing = null;
35
+ this.parts.push(part);
36
+ const index = this.parts.length - 1;
37
+ this.emit({ op: 'start', index, part });
38
+ return index;
39
+ }
40
+ done(index, result) {
41
+ const part = this.parts[index];
42
+ part.status = 'done';
43
+ part.result = result;
44
+ this.emit({ op: 'status', index, status: 'done', result });
45
+ }
46
+ plan(entries) {
47
+ if (this.planned === null) {
48
+ this.planned = this.start({ type: 'plan', entries });
49
+ return;
50
+ }
51
+ this.parts[this.planned].entries = entries;
52
+ this.emit({ op: 'plan', index: this.planned, entries });
53
+ }
54
+ measure(context) {
55
+ this.context = context;
56
+ this.emit({ op: 'context', ...context });
57
+ }
58
+ operations() {
59
+ return [
60
+ ...this.parts.map((part, index) => ({ op: 'start', index, part })),
61
+ ...(this.context === null ? [] : [{ op: 'context', ...this.context }]),
62
+ ];
63
+ }
64
+ }
package/dist/refusals.js CHANGED
@@ -21,6 +21,18 @@ function spoken(text) {
21
21
  const detail = said.indexOf('\n');
22
22
  return { code: head[1], text: said, conflicts: detail === -1 ? [] : conflictCodes(said.slice(detail + 1)) };
23
23
  }
24
+ export function retryable(text) {
25
+ let body;
26
+ try {
27
+ body = JSON.parse(text);
28
+ }
29
+ catch {
30
+ return null;
31
+ }
32
+ const error = body?.error;
33
+ const verdict = error?.retryable ?? error?.data?.retryable;
34
+ return typeof verdict === 'boolean' ? verdict : null;
35
+ }
24
36
  export function refusalOf(text) {
25
37
  let body;
26
38
  try {
package/dist/relay.js ADDED
@@ -0,0 +1,10 @@
1
+ export function relayed(target) {
2
+ const url = new URL(target);
3
+ const relay = process.env.HOUSE_KIT_RELAY;
4
+ if (relay === undefined || relay === '')
5
+ return url;
6
+ const through = new URL(`${url.host}${url.pathname}${url.search}`, `${relay}/`);
7
+ if (url.protocol === 'wss:' || url.protocol === 'ws:')
8
+ through.protocol = 'wss:';
9
+ return through;
10
+ }
package/dist/resident.js CHANGED
@@ -1,34 +1,32 @@
1
1
  import { once } from 'node:events';
2
+ import { watch } from 'node:fs';
2
3
  import { mkdir, rm, writeFile } from 'node:fs/promises';
3
4
  import { createServer } from 'node:http';
4
- import { extname, join } from 'node:path';
5
+ import { dirname, extname, join } from 'node:path';
5
6
  import { fileURLToPath } from 'node:url';
6
- import { killDescendants } from './acp.js';
7
7
  import { Agents } from './agents.js';
8
8
  import { house } from './api.js';
9
9
  import { received } from './bridge.js';
10
10
  import { Conversations } from './conversations.js';
11
11
  import { LocalCopies } from './copies.js';
12
- import { agentBase, kitHome, readEnrolment } from './home.js';
12
+ import { agentBase, enrolled, kitHome } from './home.js';
13
+ import { killDescendants } from './scope.js';
14
+ import { quoted } from './shell.js';
13
15
  import { SignIns } from './sign-in.js';
14
16
  import { placeSkillSet } from './skills.js';
15
17
  import { holdStream } from './stream.js';
16
18
  import { Updates } from './update.js';
19
+ import { codexLauncher } from './work.js';
17
20
  function report(error) {
18
21
  process.stderr.write(`kit: ${error instanceof Error ? error.message : String(error)}\n`);
19
22
  }
20
23
  function logged(work) {
21
24
  work.catch(report);
22
25
  }
23
- function quoted(value) {
24
- return `'${value.replaceAll("'", `'\\''`)}'`;
25
- }
26
- async function installShim() {
27
- const main = fileURLToPath(new URL(`./git-main${extname(fileURLToPath(import.meta.url))}`, import.meta.url));
28
- await mkdir(join(kitHome(), 'shim'), { recursive: true });
29
- await writeFile(join(kitHome(), 'shim', 'git'), `#!/bin/sh\nexec ${quoted(process.execPath)} ${quoted(main)} "$@"\n`, {
30
- mode: 0o755,
31
- });
26
+ async function installShim(path, module) {
27
+ const main = fileURLToPath(new URL(`./${module}${extname(fileURLToPath(import.meta.url))}`, import.meta.url));
28
+ await mkdir(dirname(path), { recursive: true });
29
+ await writeFile(path, `#!/bin/sh\nexec ${quoted(process.execPath)} ${quoted(main)} "$@"\n`, { mode: 0o755 });
32
30
  }
33
31
  async function serveOwner(copies) {
34
32
  const socketPath = join(kitHome(), 'owner.sock');
@@ -50,19 +48,38 @@ async function serveOwner(copies) {
50
48
  server.listen(socketPath);
51
49
  await once(server, 'listening');
52
50
  }
51
+ function connected() {
52
+ return new Promise((resolve) => {
53
+ const watcher = watch(kitHome(), () => {
54
+ if (!enrolled())
55
+ return;
56
+ watcher.close();
57
+ resolve();
58
+ });
59
+ if (!enrolled()) {
60
+ process.stderr.write('kit: this Environment is not connected; run kit login\n');
61
+ return;
62
+ }
63
+ watcher.close();
64
+ resolve();
65
+ });
66
+ }
53
67
  export async function resident() {
54
- if ((await readEnrolment()) === null) {
55
- process.stderr.write('kit: this Environment is not enrolled; run kit login\n');
56
- process.exitCode = 1;
57
- return;
58
- }
68
+ await connected();
69
+ watch(kitHome(), () => {
70
+ if (enrolled())
71
+ return;
72
+ killDescendants();
73
+ process.exit(1);
74
+ });
59
75
  await placeSkillSet();
60
76
  await mkdir(agentBase(), { recursive: true });
61
77
  process.env.HOUSE_KIT_RESIDENT = String(process.pid);
62
78
  const agents = new Agents(house);
63
79
  const copies = new LocalCopies(house);
64
80
  await copies.load();
65
- await installShim();
81
+ await installShim(join(kitHome(), 'shim', 'git'), 'git-main');
82
+ await installShim(codexLauncher(), 'codex-main');
66
83
  await serveOwner(copies);
67
84
  let stream = null;
68
85
  let reported = false;
@@ -101,6 +118,8 @@ export async function resident() {
101
118
  logged(copies.select());
102
119
  },
103
120
  frame: (arrived) => {
121
+ if (arrived.type === 'watching')
122
+ conversations.watching(arrived.watching === true);
104
123
  if (arrived.type === 'work_available' && arrived.subject === 'agents')
105
124
  logged(agents.refresh());
106
125
  if (arrived.type === 'work_available' && arrived.subject === 'local_copy')