@agentshouse/kit 0.2.1-c5987c9cb6553 → 0.2.1-c5d51f1e4ce19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/README.md +4 -3
  2. package/dist/agents.js +49 -2
  3. package/dist/bootstrap.json +4 -4
  4. package/dist/chatgpt.js +9 -2
  5. package/dist/clis.js +3 -2
  6. package/dist/conversations.js +20 -4
  7. package/dist/events.js +3 -0
  8. package/dist/home.js +41 -4
  9. package/dist/house-cli.js +291 -0
  10. package/dist/house-main.js +7 -262
  11. package/dist/instructions.js +2 -27
  12. package/dist/kit-cli.js +68 -0
  13. package/dist/kit-main.js +8 -67
  14. package/dist/login.js +30 -15
  15. package/dist/skills.js +81 -12
  16. package/dist/stream.js +57 -11
  17. package/dist/transcription.js +3 -3
  18. package/dist/update.js +1 -0
  19. package/how-we-work.md +13 -3
  20. package/package.json +2 -1
  21. package/skills/ask-matt/SKILL.md +17 -11
  22. package/skills/ask-matt/agents/openai.yaml +1 -0
  23. package/skills/code-review/SKILL.md +5 -5
  24. package/skills/codebase-design/DESIGN-IT-TWICE.md +1 -1
  25. package/skills/codebase-design/SKILL.md +0 -2
  26. package/skills/diagnosing-bugs/SKILL.md +2 -4
  27. package/skills/domain-modeling/{CONTEXT-FORMAT.md → GLOSSARY-FORMAT.md} +10 -10
  28. package/skills/domain-modeling/SKILL.md +12 -14
  29. package/skills/grill-me/SKILL.md +1 -2
  30. package/skills/grill-me/agents/openai.yaml +1 -0
  31. package/skills/grill-with-docs/SKILL.md +1 -2
  32. package/skills/grill-with-docs/agents/openai.yaml +1 -0
  33. package/skills/grilling/SKILL.md +2 -2
  34. package/skills/handoff/SKILL.md +2 -3
  35. package/skills/handoff/agents/openai.yaml +1 -0
  36. package/skills/implement/SKILL.md +5 -4
  37. package/skills/implement/agents/openai.yaml +1 -0
  38. package/skills/implement-spec/SKILL.md +40 -0
  39. package/skills/implement-spec/agents/openai.yaml +5 -0
  40. package/skills/improve-codebase-architecture/SKILL.md +6 -7
  41. package/skills/improve-codebase-architecture/agents/openai.yaml +1 -0
  42. package/skills/pr/CREDITS.md +3 -0
  43. package/skills/pr/LICENSE +21 -0
  44. package/skills/pr/SKILL.md +170 -0
  45. package/skills/pr/agents/openai.yaml +3 -0
  46. package/skills/prototype/SKILL.md +0 -2
  47. package/skills/research/SKILL.md +0 -2
  48. package/skills/retro/LICENSE +21 -0
  49. package/skills/retro/SKILL.md +44 -0
  50. package/skills/retro/agents/openai.yaml +5 -0
  51. package/skills/tdd/SKILL.md +2 -4
  52. package/skills/teach/SKILL.md +3 -4
  53. package/skills/teach/agents/openai.yaml +1 -0
  54. package/skills/to-questionnaire/SKILL.md +1 -2
  55. package/skills/to-questionnaire/agents/openai.yaml +1 -0
  56. package/skills/to-spec/SKILL.md +1 -2
  57. package/skills/to-spec/agents/openai.yaml +1 -0
  58. package/skills/to-tickets/SKILL.md +3 -4
  59. package/skills/to-tickets/agents/openai.yaml +1 -0
  60. package/skills/triage/AGENT-BRIEF.md +207 -0
  61. package/skills/triage/LICENSE +21 -0
  62. package/skills/triage/OUT-OF-SCOPE.md +105 -0
  63. package/skills/triage/SKILL.md +112 -0
  64. package/skills/triage/agents/openai.yaml +5 -0
  65. package/skills/wait-what/SKILL.md +2 -3
  66. package/skills/wait-what/agents/openai.yaml +1 -0
  67. package/skills/wayfinder/SKILL.md +5 -6
  68. package/skills/wayfinder/agents/openai.yaml +1 -0
  69. package/skills/wizard/LICENSE +21 -0
  70. package/skills/wizard/SKILL.md +44 -0
  71. package/skills/wizard/agents/openai.yaml +3 -0
  72. package/skills/wizard/template.sh +223 -0
  73. package/skills/writing-for-agents/SKILL.md +0 -2
  74. package/skills/resolving-merge-conflicts/SKILL.md +0 -16
  75. package/skills/resolving-merge-conflicts/agents/openai.yaml +0 -3
  76. /package/skills/{resolving-merge-conflicts → implement-spec}/LICENSE +0 -0
@@ -1,265 +1,10 @@
1
1
  #!/usr/bin/env node
2
- import { createHash } from 'node:crypto';
3
- import { mkdir, readFile, writeFile } from 'node:fs/promises';
4
- import { request, setGlobalProxyFromEnv } from 'node:http';
5
- import { dirname, extname, join, resolve } from 'node:path';
6
- import { verified } from './files.js';
7
- import { HOUSE_REF } from './git.js';
8
- import { kitHome, readEnrolment, readOwnAgent } from './home.js';
9
- import { callHouse, rpc, UNREACHABLE } from './mcp.js';
10
- import { refusalOf } from './refusals.js';
11
- import { relayed } from './relay.js';
12
- import { parse, stringify } from 'yaml';
13
- const USAGE = "usage: house <tool> ['<arguments as JSON>']";
14
- const PUSH_USAGE = 'usage: house push [commit] [--owner]';
15
- const PUSH = "push [commit]: sends the Local copy's committed changes to House";
16
- const FETCH_USAGE = 'usage: house fetch';
17
- const FETCH = `fetch: records House's changes on each Local copy's ${HOUSE_REF}`;
18
- const DOWNLOAD_USAGE = `usage: house download '{"path":"/rooms/<handle>/<path>","file":"<local file>"}', adding "ref" for a revision`;
19
- const DOWNLOAD = 'download: writes a binary file of a Room to the local file named by file';
20
- const ARGUMENTS = `the arguments are one JSON object in single quotes, like house search '{"query":"invoice"}'`;
21
- const CLOSED = "this conversation's House connection is closed; nothing to do from here";
22
- const SANDBOXED = "your CLI's sandbox kept house from House; run house directly, not through another program";
23
- const REVOKED = 'this conversation no longer has House access; nothing to do from here';
24
- const UNCONNECTED = "this computer's own agent has no House connection; run kit login";
25
- const DISCONNECTED = "House no longer accepts this computer's own agent; run kit login";
26
- const UNCONFIRMED = 'with no result; a write may or may not have taken effect, so read before you repeat it';
27
- const socketPath = process.env.HOUSE_BRIDGE;
28
- const MEDIA_TYPES = new Map([
29
- ['avif', 'image/avif'],
30
- ['csv', 'text/csv'],
31
- ['docx', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'],
32
- ['gif', 'image/gif'],
33
- ['heic', 'image/heic'],
34
- ['html', 'text/html'],
35
- ['jpeg', 'image/jpeg'],
36
- ['jpg', 'image/jpeg'],
37
- ['json', 'application/json'],
38
- ['m4a', 'audio/mp4'],
39
- ['md', 'text/markdown'],
40
- ['mov', 'video/quicktime'],
41
- ['mp3', 'audio/mpeg'],
42
- ['mp4', 'video/mp4'],
43
- ['ogg', 'audio/ogg'],
44
- ['pdf', 'application/pdf'],
45
- ['png', 'image/png'],
46
- ['pptx', 'application/vnd.openxmlformats-officedocument.presentationml.presentation'],
47
- ['svg', 'image/svg+xml'],
48
- ['txt', 'text/plain'],
49
- ['wav', 'audio/wav'],
50
- ['webm', 'video/webm'],
51
- ['webp', 'image/webp'],
52
- ['xlsx', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'],
53
- ['zip', 'application/zip'],
54
- ]);
55
- function refused(path, method, status, text, local) {
56
- const refusal = refusalOf(text);
57
- if (refusal !== null)
58
- return refusal.text;
59
- if (status === 401)
60
- return REVOKED;
61
- const act = method === 'GET' ? 'download' : 'upload';
62
- if (URL.canParse(path))
63
- return `the ${act} answered ${status}; ${act} the file again`;
64
- if (status === 502 && local)
65
- return text;
66
- return path === '/' ? unconfirmed(status) : `${path} answered ${status}`;
67
- }
68
- function unconfirmed(status) {
69
- return `House answered ${status} ${UNCONFIRMED}`;
70
- }
71
- function exchanged(path, method, body, headers = { 'content-type': 'application/json' }, to = socketPath) {
72
- return new Promise((resolve, reject) => {
73
- const sent = request({ socketPath: to, path, method, headers }, (answer) => {
74
- const chunks = [];
75
- answer.on('data', (chunk) => chunks.push(chunk));
76
- answer.on('end', () => {
77
- const bytes = Buffer.concat(chunks);
78
- if (answer.statusCode === 200)
79
- resolve(bytes);
80
- else
81
- reject(new Error(refused(path, method, answer.statusCode, bytes.toString('utf8'), answer.headers['content-type'] === undefined)));
82
- });
83
- });
84
- sent.on('error', (error) => reject(new Error(error.code === 'EPERM' || error.code === 'EACCES' ? SANDBOXED : CLOSED)));
85
- sent.end(body === undefined ? undefined : body instanceof Buffer ? body : JSON.stringify(body));
86
- });
87
- }
88
- async function bridged(path, body, headers, to = socketPath) {
89
- return (await exchanged(path, 'POST', body, headers, to)).toString('utf8');
90
- }
91
- async function direct(message) {
92
- const ownAgent = await readOwnAgent();
93
- if (ownAgent === null)
94
- throw new Error(UNCONNECTED);
95
- await readEnrolment();
96
- setGlobalProxyFromEnv();
97
- const answer = await callHouse(ownAgent.house, ownAgent.credential, message).catch(() => {
98
- throw new Error(UNREACHABLE);
99
- });
100
- if (answer.status === 200)
101
- return answer.text;
102
- throw new Error(answer.status === 401 ? DISCONNECTED : (refusalOf(answer.text)?.text ?? unconfirmed(answer.status)));
103
- }
104
- async function mcp(method, params) {
105
- const message = rpc(method, params);
106
- const answer = JSON.parse(socketPath === undefined ? await direct(message) : await bridged('/', message));
107
- if (answer.error !== undefined)
108
- throw new Error(answer.error.message);
109
- return answer.result;
110
- }
111
- async function tools() {
112
- return (await mcp('tools/list', {})).tools;
113
- }
114
- async function localFile(path) {
115
- try {
116
- return await readFile(path);
117
- }
118
- catch (error) {
119
- throw new Error(error.code === 'EISDIR'
120
- ? `${path} is a folder; upload one file at a time`
121
- : `${path} is not a readable file`);
122
- }
123
- }
124
- async function transferred(url, method, bytes, headers) {
125
- if (socketPath !== undefined)
126
- return exchanged(url, method, bytes, headers);
127
- setGlobalProxyFromEnv();
128
- const answer = await fetch(relayed(url), { method, ...(headers === undefined ? {} : { headers }), ...(bytes === undefined ? {} : { body: bytes }) }).catch(() => {
129
- throw new Error(UNREACHABLE);
130
- });
131
- const received = Buffer.from(await answer.arrayBuffer());
132
- if (answer.status === 200)
133
- return received;
134
- throw new Error(refused(url, method, answer.status, received.toString('utf8'), false));
135
- }
136
- async function sent(url, bytes, operation) {
137
- const headers = { 'content-type': 'application/octet-stream', 'x-house-byte-operation': operation };
138
- return (await transferred(url, 'POST', bytes, headers)).toString('utf8');
139
- }
140
- async function download(args) {
141
- const { flags, positionals: [argument] } = accepted(args, ['--help'], 1, DOWNLOAD_USAGE);
142
- if (flags.has('--help'))
143
- return DOWNLOAD_USAGE;
144
- const { file, ...selected } = argumentsOf(argument);
145
- if (typeof file !== 'string' || file === '')
146
- throw new Error('download needs "file", the local file to write');
147
- const inspected = parse(await called('inspect', selected));
148
- if (typeof inspected?.download !== 'string')
149
- throw new Error(`${String(selected.path)} holds no binary file; shell reads its text`);
150
- const bytes = verified(await transferred(inspected.download, 'GET'), String(inspected.sha256), String(selected.path));
151
- const written = resolve(file);
152
- await mkdir(dirname(written), { recursive: true });
153
- await writeFile(written, bytes);
154
- return written;
155
- }
156
- async function upload({ file, ...destination }) {
157
- if (typeof file !== 'string' || file === '')
158
- throw new Error('upload needs "file", a local file');
159
- const bytes = await localFile(file);
160
- const mediaType = MEDIA_TYPES.get(extname(file).slice(1).toLowerCase());
161
- const answer = await called('upload', {
162
- ...destination,
163
- bytes: bytes.length,
164
- sha256: createHash('sha256').update(bytes).digest('hex'),
165
- ...(mediaType === undefined ? {} : { media_type: mediaType }),
166
- });
167
- const declared = parse(answer);
168
- if (declared.upload === undefined)
169
- return answer;
170
- const written = JSON.parse(await sent(declared.upload.url, bytes, declared.upload.operation));
171
- return stringify(written, { lineWidth: 0 }).trimEnd();
172
- }
173
- function unexpected(argument, usage) {
174
- return new Error(`unexpected argument ${argument}; ${usage}`);
175
- }
176
- function accepted(args, flags, positionals, usage) {
177
- const given = { flags: new Set(), positionals: [] };
178
- for (const arg of args) {
179
- if (flags.includes(arg))
180
- given.flags.add(arg);
181
- else if (!arg.startsWith('-') && given.positionals.length < positionals)
182
- given.positionals.push(arg);
183
- else
184
- throw unexpected(arg, usage);
185
- }
186
- return given;
187
- }
188
- async function push(args) {
189
- const { flags, positionals: [commit = 'HEAD'] } = accepted(args, ['--help', '--owner'], 1, PUSH_USAGE);
190
- if (flags.has('--help'))
191
- return PUSH_USAGE;
192
- const owner = flags.has('--owner');
193
- if (owner && socketPath !== undefined)
194
- throw new Error('--owner is not for Agent conversations; run house push without it');
195
- if (!owner && socketPath === undefined)
196
- throw new Error('outside an Agent conversation, house push needs --owner');
197
- const pushed = JSON.parse(await bridged('/git/push', { cwd: process.cwd(), commit }, undefined, owner ? join(kitHome(), 'owner.sock') : socketPath));
198
- if (pushed.refused)
199
- throw new Error(pushed.text);
200
- return pushed.text;
201
- }
202
- async function fetched(args) {
203
- if (accepted(args, ['--help'], 0, FETCH_USAGE).flags.has('--help'))
204
- return FETCH_USAGE;
205
- const answer = JSON.parse(await bridged('/git/fetch', {}, undefined, socketPath ?? join(kitHome(), 'owner.sock')));
206
- if (answer.refused)
207
- throw new Error(answer.text);
208
- return answer.text;
209
- }
210
- function argumentsOf(argument) {
211
- if (argument === undefined)
212
- return {};
213
- let parsed;
214
- try {
215
- parsed = JSON.parse(argument);
216
- }
217
- catch {
218
- throw new Error(ARGUMENTS);
219
- }
220
- if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed))
221
- throw new Error(ARGUMENTS);
222
- return parsed;
223
- }
224
- async function house(args) {
225
- const { flags, positionals: [verb, argument] } = accepted(args, ['--help'], 2, USAGE);
226
- if (verb === 'help' && argument !== undefined)
227
- throw unexpected(argument, USAGE);
228
- if (flags.has('--help') && argument !== undefined)
229
- throw unexpected('--help', USAGE);
230
- if (verb === undefined || verb === 'help') {
231
- return [USAGE, 'help', PUSH, FETCH, DOWNLOAD, ...(await tools()).map((tool) => (tool.description === undefined ? tool.name : `${tool.name}: ${tool.description}`))].join('\n');
232
- }
233
- if (flags.has('--help')) {
234
- const tool = (await tools()).find((listed) => listed.name === verb);
235
- if (tool === undefined)
236
- throw new Error(`${verb} is no Tool; house find_command '{"query":"${verb}"}' finds Commands`);
237
- return [...(tool.description === undefined ? [] : [tool.description]), JSON.stringify(tool.inputSchema)].join('\n');
238
- }
239
- const parsed = argumentsOf(argument);
240
- return verb === 'upload' ? upload(parsed) : called(verb, parsed);
2
+ const [major = 0, minor = 0] = process.versions.node.split('.').map(Number);
3
+ if (major < 24 || (major === 24 && minor < 14)) {
4
+ process.stderr.write(`house: the Kit needs Node 24.14.0 or newer; this is ${process.versions.node}\n`);
5
+ process.exitCode = 1;
241
6
  }
242
- async function called(name, args) {
243
- const result = await mcp('tools/call', { name, arguments: args });
244
- const text = result.content.map((content) => content.text).join('\n');
245
- if (result.isError === true)
246
- throw new Error(text.replace(/\n+$/, ''));
247
- return text;
7
+ else {
8
+ await import('./house-cli.js');
248
9
  }
249
- const argv = process.argv.slice(2);
250
- const named = argv.findIndex((arg) => !arg.startsWith('-'));
251
- const rest = argv.filter((_arg, index) => index !== named);
252
- (argv[named] === 'push'
253
- ? push(rest)
254
- : argv[named] === 'fetch'
255
- ? fetched(rest)
256
- : argv[named] === 'download'
257
- ? download(rest)
258
- : house(argv)).then((text) => {
259
- process.stdout.write(`${text}\n`);
260
- if (argv[0] === 'shell')
261
- process.exitCode = Number(/^exit: (\d+)(?:\n|$)/.exec(text)?.[1] ?? 0);
262
- }, (error) => {
263
- process.stderr.write(`house: ${error instanceof Error ? error.message : String(error)}\n`);
264
- process.exitCode = 1;
265
- });
10
+ export {};
@@ -1,36 +1,11 @@
1
1
  import { HOUSE_REF } from './git.js';
2
- import { HOW_WE_WORK } from './skills.js';
2
+ import { readHowWeWork } from './skills.js';
3
3
  const SOURCE_LINE = "From House:";
4
4
  const HOUSE_LINE = "Work with House through the `house` CLI: run `house --help`, and `house find_command` for House's guides and formats.";
5
5
  const FILE_LINE = 'To give the User a file, upload it with `house upload` and link it; for an App, a Site or a website, follow `house find_command \'{"query":"app"}\'`. Never start a server.';
6
6
  const READ_LINE = "Optional per-Room instructions: `/rooms/private/rooms/<handle>/AGENTS.md`.";
7
7
  const COPIES_LINE = `House Local copies; before work run \`house fetch\` and rebase onto \`${HOUSE_REF}\`; after it commit, then \`house push\`:`;
8
- const UNREADABLE = /^(?:\S+: )?(?:path_not_found|room_not_found|operation_denied)\b/;
9
- const FAILED = /^exit: [1-9]\d*$/;
10
- const CUT = /^stderr: shell: output_cut (\d+) of \d+ bytes; continue with: (.+)$/;
11
- function cutOf(lines) {
12
- const cut = CUT.exec(lines[0] ?? '');
13
- return cut !== null && Buffer.byteLength(lines.slice(1).join('\n')) === Number(cut[1]) ? cut : null;
14
- }
15
- async function howWeWork(bridge) {
16
- let document = '';
17
- for (let command = `cat ${HOW_WE_WORK}`; command !== undefined;) {
18
- const read = await bridge.tool('shell', { command });
19
- const text = read.content.map((content) => content.text).join('\n');
20
- const lines = text.split('\n');
21
- if (read.isError === true || (FAILED.test(lines[0] ?? '') && lines[1]?.startsWith('stderr: '))) {
22
- const refusal = read.isError === true ? text : lines.slice(1).join('\n').replace(/^stderr: /gm, '');
23
- if (UNREADABLE.test(refusal))
24
- return '';
25
- throw new Error(refusal);
26
- }
27
- const cut = cutOf(lines);
28
- document += lines.slice(cut === null ? 0 : 1).join('\n');
29
- command = cut?.[2];
30
- }
31
- return document.replace(/\n$/, '');
32
- }
33
8
  export async function instructions(bridge, base, copies) {
34
9
  const lines = [SOURCE_LINE, HOUSE_LINE, FILE_LINE, READ_LINE, ...(copies.length === 0 ? [] : [COPIES_LINE, ...copies])];
35
- return [lines.join('\n'), base, await howWeWork(bridge)].filter((part) => part !== '').join('\n\n');
10
+ return [lines.join('\n'), base, (await readHowWeWork(bridge)).replace(/\n$/, '')].filter((part) => part !== '').join('\n\n');
36
11
  }
@@ -0,0 +1,68 @@
1
+ import { setGlobalProxyFromEnv } from 'node:http';
2
+ import { parseArgs } from 'node:util';
3
+ import { answerGitCredential } from './app-git.js';
4
+ import { chatgpt } from './chatgpt.js';
5
+ import { login } from './login.js';
6
+ import { logout } from './logout.js';
7
+ import { resident } from './resident.js';
8
+ const USAGE = 'usage: kit <login|logout|resident|chatgpt>\n';
9
+ const COMMANDS = new Map([
10
+ [
11
+ 'logout',
12
+ {
13
+ usage: 'usage: kit logout',
14
+ about: "disconnects this computer, stops House Kit and ends your own agent's connection",
15
+ operands: 0,
16
+ run: logout,
17
+ },
18
+ ],
19
+ [
20
+ 'resident',
21
+ {
22
+ usage: 'usage: kit resident',
23
+ about: "keeps this Environment connected; House Kit's service runs it",
24
+ operands: 0,
25
+ run: resident,
26
+ },
27
+ ],
28
+ [
29
+ 'git-credential',
30
+ {
31
+ usage: 'usage: kit git-credential <get|store|erase>',
32
+ about: "answers git with your own agent's House credential; git runs it",
33
+ operands: 1,
34
+ run: ([operation]) => answerGitCredential(operation),
35
+ },
36
+ ],
37
+ ]);
38
+ const [command, ...argv] = process.argv.slice(2);
39
+ setGlobalProxyFromEnv();
40
+ async function run() {
41
+ if (command === 'login')
42
+ return login(argv);
43
+ if (command === 'chatgpt')
44
+ return chatgpt(argv);
45
+ if (command === '--help') {
46
+ parseArgs({ args: argv });
47
+ process.stdout.write(USAGE);
48
+ return;
49
+ }
50
+ const chosen = COMMANDS.get(command ?? '');
51
+ if (chosen === undefined) {
52
+ process.stderr.write(USAGE);
53
+ process.exitCode = 2;
54
+ return;
55
+ }
56
+ const { values, positionals } = parseArgs({ args: argv, options: { help: { type: 'boolean', default: false } }, allowPositionals: true });
57
+ if (positionals.length > chosen.operands)
58
+ throw new Error(`unexpected argument ${positionals[chosen.operands]}; ${chosen.usage}`);
59
+ if (values.help) {
60
+ process.stdout.write(`${chosen.usage}\n ${chosen.about}\n`);
61
+ return;
62
+ }
63
+ return chosen.run(positionals);
64
+ }
65
+ run().catch((error) => {
66
+ process.stderr.write(`kit: ${error instanceof Error ? error.message : String(error)}\n`);
67
+ process.exitCode = 1;
68
+ });
package/dist/kit-main.js CHANGED
@@ -1,69 +1,10 @@
1
1
  #!/usr/bin/env node
2
- import { setGlobalProxyFromEnv } from 'node:http';
3
- import { parseArgs } from 'node:util';
4
- import { answerGitCredential } from './app-git.js';
5
- import { chatgpt } from './chatgpt.js';
6
- import { login } from './login.js';
7
- import { logout } from './logout.js';
8
- import { resident } from './resident.js';
9
- const USAGE = 'usage: kit <login|logout|resident|chatgpt>\n';
10
- const COMMANDS = new Map([
11
- [
12
- 'logout',
13
- {
14
- usage: 'usage: kit logout',
15
- about: "disconnects this computer, stops House Kit and ends your own agent's connection",
16
- operands: 0,
17
- run: logout,
18
- },
19
- ],
20
- [
21
- 'resident',
22
- {
23
- usage: 'usage: kit resident',
24
- about: "keeps this Environment connected; House Kit's service runs it",
25
- operands: 0,
26
- run: resident,
27
- },
28
- ],
29
- [
30
- 'git-credential',
31
- {
32
- usage: 'usage: kit git-credential <get|store|erase>',
33
- about: "answers git with your own agent's House credential; git runs it",
34
- operands: 1,
35
- run: ([operation]) => answerGitCredential(operation),
36
- },
37
- ],
38
- ]);
39
- const [command, ...argv] = process.argv.slice(2);
40
- setGlobalProxyFromEnv();
41
- async function run() {
42
- if (command === 'login')
43
- return login(argv);
44
- if (command === 'chatgpt')
45
- return chatgpt(argv);
46
- if (command === '--help') {
47
- parseArgs({ args: argv });
48
- process.stdout.write(USAGE);
49
- return;
50
- }
51
- const chosen = COMMANDS.get(command ?? '');
52
- if (chosen === undefined) {
53
- process.stderr.write(USAGE);
54
- process.exitCode = 2;
55
- return;
56
- }
57
- const { values, positionals } = parseArgs({ args: argv, options: { help: { type: 'boolean', default: false } }, allowPositionals: true });
58
- if (positionals.length > chosen.operands)
59
- throw new Error(`unexpected argument ${positionals[chosen.operands]}; ${chosen.usage}`);
60
- if (values.help) {
61
- process.stdout.write(`${chosen.usage}\n ${chosen.about}\n`);
62
- return;
63
- }
64
- return chosen.run(positionals);
65
- }
66
- run().catch((error) => {
67
- process.stderr.write(`kit: ${error instanceof Error ? error.message : String(error)}\n`);
2
+ const [major = 0, minor = 0] = process.versions.node.split('.').map(Number);
3
+ if (major < 24 || (major === 24 && minor < 14)) {
4
+ process.stderr.write(`kit: the Kit needs Node 24.14.0 or newer; this is ${process.versions.node}\n`);
68
5
  process.exitCode = 1;
69
- });
6
+ }
7
+ else {
8
+ await import('./kit-cli.js');
9
+ }
10
+ export {};
package/dist/login.js CHANGED
@@ -2,11 +2,12 @@ import { spawn } from 'node:child_process';
2
2
  import { createHash, randomBytes } from 'node:crypto';
3
3
  import { hostname } from 'node:os';
4
4
  import { parseArgs } from 'node:util';
5
- import { post, retrying } from './api.js';
5
+ import { HouseRefusal, post, retrying } from './api.js';
6
6
  import { placeAppGit } from './app-git.js';
7
7
  import { writeCodexRule } from './clis.js';
8
- import { forgetOwnAgent, readDisconnected, readEnrolment, readOwnAgent, writeEnrolment, writeOwnAgent } from './home.js';
8
+ import { forgetDisconnected, forgetOwnAgent, readDisconnected, readEnrolment, readOwnAgent, writeEnrolment, writeOwnAgent, } from './home.js';
9
9
  import { callHouse, rpc } from './mcp.js';
10
+ import { refusalOf } from './refusals.js';
10
11
  import { selectRelay } from './relay.js';
11
12
  import { startService } from './service.js';
12
13
  import { placeSkillSet } from './skills.js';
@@ -35,6 +36,9 @@ const USAGE = `usage: kit login [--house <origin>] [--environment <id>] [--rooms
35
36
  --no-private give this Environment every Room but your Private Room
36
37
  --code <code> connect this machine with a login code
37
38
  `;
39
+ function gone(error) {
40
+ return error instanceof HouseRefusal && refusalOf(error.text)?.code === 'kit_environment_not_found';
41
+ }
38
42
  function chosenRooms(rooms, noPrivate) {
39
43
  if (rooms !== undefined && noPrivate)
40
44
  throw new Error('--rooms and --no-private are two choices of Rooms; pass one');
@@ -73,7 +77,8 @@ export async function login(argv) {
73
77
  selectRelay(relay);
74
78
  const house = values.house ?? enrolled?.house ?? DEFAULT_HOUSE;
75
79
  const replaces = process.env.HOUSE_KIT_REPLACES;
76
- const environment = replaces === undefined ? (values.environment ?? (enrolled?.house === house ? enrolled.environment : undefined)) : undefined;
80
+ const remembered = replaces === undefined && values.environment === undefined && enrolled?.house === house ? enrolled.environment : undefined;
81
+ const environment = replaces === undefined ? (values.environment ?? remembered) : undefined;
77
82
  const ownAgent = await readOwnAgent();
78
83
  let held = false;
79
84
  let exchanged;
@@ -83,41 +88,51 @@ export async function login(argv) {
83
88
  else {
84
89
  held = ownAgent !== null && ownAgent.house === house && (await accepted(house, ownAgent.credential));
85
90
  const verifier = randomBytes(32).toString('base64url');
86
- const started = await retrying(() => post(house, '/kit', {
91
+ const start = (named) => retrying(() => post(house, '/kit', {
87
92
  label: hostname(),
88
- ...(environment === undefined
93
+ ...(named === undefined
89
94
  ? { act: 'new_environment', ...(replaces === undefined ? {} : { replaces }) }
90
- : { act: 'existing_environment', environment_id: environment }),
95
+ : { act: 'existing_environment', environment_id: named }),
91
96
  ...rooms,
92
97
  code_challenge: createHash('sha256').update(verifier).digest('base64url'),
93
98
  ...(held ? {} : { headless: true }),
94
99
  }));
100
+ let started;
101
+ try {
102
+ started = await start(environment);
103
+ }
104
+ catch (error) {
105
+ if (remembered === undefined || !gone(error))
106
+ throw error;
107
+ await forgetDisconnected();
108
+ process.stdout.write(`House no longer holds Environment ${remembered}; connecting this computer as a new one.\n`);
109
+ started = await start(undefined);
110
+ }
95
111
  process.stdout.write(`Open this link and confirm: ${started.start_url}\n`);
96
112
  open(started.start_url);
97
113
  exchanged = await retrying(() => post(house, '/kit/token', { login: started.login, code_verifier: verifier }), undefined, () => POLL_INTERVAL_MS);
98
114
  }
99
- try {
100
- await placeSkillSet();
101
- }
102
- catch (error) {
103
- process.stderr.write(`kit: the skills could not be placed: ${error.message}\n`);
104
- }
115
+ await placeSkillSet();
105
116
  await writeCodexRule().catch((error) => process.stderr.write(`kit: ${error.message}\n`));
117
+ const relayRecord = relay === undefined ? {} : { relay };
106
118
  await writeEnrolment({
107
119
  house,
108
- ...(relay === undefined ? {} : { relay }),
120
+ ...relayRecord,
109
121
  environment: exchanged.environment,
110
122
  credential: exchanged.credential,
111
123
  });
112
124
  process.stdout.write(`Environment ${exchanged.environment} is connected to ${house}.\n`);
113
125
  if (exchanged.headless_credential !== undefined) {
114
- await writeOwnAgent({ house, user: exchanged.user, credential: exchanged.headless_credential });
126
+ await writeOwnAgent({ house, ...relayRecord, user: exchanged.user, credential: exchanged.headless_credential });
115
127
  }
116
128
  else if (held && ownAgent !== null && ownAgent.user !== exchanged.user) {
117
129
  await forgetOwnAgent();
118
130
  process.stdout.write("This computer's own agent was another User's; run kit login again to connect it to you.\n");
119
131
  }
120
- await placeAppGit(ownAgent, await readOwnAgent());
132
+ else if (held && ownAgent !== null) {
133
+ await writeOwnAgent({ house, ...relayRecord, user: ownAgent.user, credential: ownAgent.credential });
134
+ }
135
+ await placeAppGit(ownAgent, await readOwnAgent()).catch((error) => process.stderr.write(`kit: ${error.message}\n`));
121
136
  try {
122
137
  startService();
123
138
  }