@agentshouse/kit 0.2.1-c96543a4c8b15 → 0.2.1-c9c41d009d46a

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