@agentshouse/kit 0.2.1-cf110d15f69c8 → 0.2.1-cfb7b543f2af6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/README.md +11 -10
  2. package/dist/agents.js +72 -6
  3. package/dist/api.js +5 -1
  4. package/dist/bootstrap.json +4 -4
  5. package/dist/chatgpt.js +32 -0
  6. package/dist/clis.js +10 -3
  7. package/dist/conversations.js +11 -1
  8. package/dist/copies.js +18 -8
  9. package/dist/end.js +4 -0
  10. package/dist/files.js +7 -1
  11. package/dist/git.js +11 -8
  12. package/dist/home.js +41 -4
  13. package/dist/house-cli.js +291 -0
  14. package/dist/house-main.js +7 -206
  15. package/dist/instructions.js +2 -27
  16. package/dist/kit-cli.js +68 -0
  17. package/dist/kit-main.js +8 -22
  18. package/dist/login.js +36 -27
  19. package/dist/placement.js +48 -0
  20. package/dist/relay.js +1 -1
  21. package/dist/resident.js +8 -4
  22. package/dist/skills.js +81 -12
  23. package/dist/stream.js +62 -13
  24. package/dist/transcription.js +3 -3
  25. package/dist/update.js +28 -6
  26. package/dist/wire.js +6 -0
  27. package/how-we-work.md +13 -3
  28. package/package.json +2 -1
  29. package/skills/ask-matt/SKILL.md +17 -11
  30. package/skills/ask-matt/agents/openai.yaml +1 -0
  31. package/skills/code-review/SKILL.md +5 -5
  32. package/skills/codebase-design/DESIGN-IT-TWICE.md +1 -1
  33. package/skills/codebase-design/SKILL.md +0 -2
  34. package/skills/diagnosing-bugs/SKILL.md +2 -4
  35. package/skills/domain-modeling/{CONTEXT-FORMAT.md → GLOSSARY-FORMAT.md} +10 -10
  36. package/skills/domain-modeling/SKILL.md +12 -14
  37. package/skills/grill-me/SKILL.md +1 -2
  38. package/skills/grill-me/agents/openai.yaml +1 -0
  39. package/skills/grill-with-docs/SKILL.md +1 -2
  40. package/skills/grill-with-docs/agents/openai.yaml +1 -0
  41. package/skills/grilling/SKILL.md +2 -2
  42. package/skills/handoff/SKILL.md +2 -3
  43. package/skills/handoff/agents/openai.yaml +1 -0
  44. package/skills/implement/SKILL.md +5 -4
  45. package/skills/implement/agents/openai.yaml +1 -0
  46. package/skills/implement-spec/SKILL.md +40 -0
  47. package/skills/implement-spec/agents/openai.yaml +5 -0
  48. package/skills/improve-codebase-architecture/SKILL.md +6 -7
  49. package/skills/improve-codebase-architecture/agents/openai.yaml +1 -0
  50. package/skills/pr/CREDITS.md +3 -0
  51. package/skills/pr/LICENSE +21 -0
  52. package/skills/pr/SKILL.md +170 -0
  53. package/skills/pr/agents/openai.yaml +3 -0
  54. package/skills/prototype/SKILL.md +0 -2
  55. package/skills/research/SKILL.md +0 -2
  56. package/skills/retro/LICENSE +21 -0
  57. package/skills/retro/SKILL.md +44 -0
  58. package/skills/retro/agents/openai.yaml +5 -0
  59. package/skills/tdd/SKILL.md +2 -4
  60. package/skills/teach/SKILL.md +3 -4
  61. package/skills/teach/agents/openai.yaml +1 -0
  62. package/skills/to-questionnaire/SKILL.md +1 -2
  63. package/skills/to-questionnaire/agents/openai.yaml +1 -0
  64. package/skills/to-spec/SKILL.md +1 -2
  65. package/skills/to-spec/agents/openai.yaml +1 -0
  66. package/skills/to-tickets/SKILL.md +3 -4
  67. package/skills/to-tickets/agents/openai.yaml +1 -0
  68. package/skills/triage/AGENT-BRIEF.md +207 -0
  69. package/skills/triage/LICENSE +21 -0
  70. package/skills/triage/OUT-OF-SCOPE.md +105 -0
  71. package/skills/triage/SKILL.md +112 -0
  72. package/skills/triage/agents/openai.yaml +5 -0
  73. package/skills/wait-what/SKILL.md +2 -3
  74. package/skills/wait-what/agents/openai.yaml +1 -0
  75. package/skills/wayfinder/SKILL.md +5 -6
  76. package/skills/wayfinder/agents/openai.yaml +1 -0
  77. package/skills/wizard/LICENSE +21 -0
  78. package/skills/wizard/SKILL.md +44 -0
  79. package/skills/wizard/agents/openai.yaml +3 -0
  80. package/skills/wizard/template.sh +223 -0
  81. package/skills/writing-for-agents/SKILL.md +0 -2
  82. package/skills/resolving-merge-conflicts/SKILL.md +0 -16
  83. package/skills/resolving-merge-conflicts/agents/openai.yaml +0 -3
  84. /package/skills/{resolving-merge-conflicts → implement-spec}/LICENSE +0 -0
@@ -0,0 +1,291 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { mkdir, readFile, writeFile } from 'node:fs/promises';
3
+ import { request, setGlobalProxyFromEnv } from 'node:http';
4
+ import { basename, dirname, extname, join, resolve } from 'node:path';
5
+ import { verified } from './files.js';
6
+ import { HOUSE_REF } from './git.js';
7
+ import { kitHome, readOwnAgent } from './home.js';
8
+ import { callHouse, rpc, UNREACHABLE } from './mcp.js';
9
+ import { refusalOf } from './refusals.js';
10
+ import { relayed, selectRelay } 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 DOWNLOAD_USAGE = `usage: house download '{"path":"/rooms/<handle>/<path>","file":"<local file>"}', adding "ref" for a revision`;
18
+ const DOWNLOAD = 'download: writes a binary file of a Room to the local file named by file';
19
+ const ARGUMENTS = `the arguments are one JSON object in single quotes, like house search '{"query":"invoice"}'`;
20
+ const CLOSED = "this conversation's House connection is closed; nothing to do from here";
21
+ const SANDBOXED = "your CLI's sandbox kept house from House; run house directly, not through another program";
22
+ const REVOKED = 'this conversation no longer has House access; nothing to do from here';
23
+ const UNCONNECTED = "this computer's own agent has no House connection; run kit login, or kit chatgpt --key <key> with a script key";
24
+ const DISCONNECTED = "House no longer accepts this computer's own agent; run kit login, or kit chatgpt --key <key> with a script key";
25
+ const UNCONFIRMED = 'with no result; a write may or may not have taken effect, so read before you repeat it';
26
+ const socketPath = process.env.HOUSE_BRIDGE;
27
+ const MEDIA_TYPES = new Map([
28
+ ['avif', 'image/avif'],
29
+ ['csv', 'text/csv'],
30
+ ['docx', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'],
31
+ ['gif', 'image/gif'],
32
+ ['heic', 'image/heic'],
33
+ ['html', 'text/html'],
34
+ ['jpeg', 'image/jpeg'],
35
+ ['jpg', 'image/jpeg'],
36
+ ['json', 'application/json'],
37
+ ['m4a', 'audio/mp4'],
38
+ ['md', 'text/markdown'],
39
+ ['mov', 'video/quicktime'],
40
+ ['mp3', 'audio/mpeg'],
41
+ ['mp4', 'video/mp4'],
42
+ ['ogg', 'audio/ogg'],
43
+ ['pdf', 'application/pdf'],
44
+ ['png', 'image/png'],
45
+ ['pptx', 'application/vnd.openxmlformats-officedocument.presentationml.presentation'],
46
+ ['svg', 'image/svg+xml'],
47
+ ['txt', 'text/plain'],
48
+ ['wav', 'audio/wav'],
49
+ ['webm', 'video/webm'],
50
+ ['webp', 'image/webp'],
51
+ ['xlsx', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'],
52
+ ['zip', 'application/zip'],
53
+ ]);
54
+ function refused(path, method, status, text, local) {
55
+ const refusal = refusalOf(text);
56
+ if (refusal !== null)
57
+ return refusal.text;
58
+ if (status === 401)
59
+ return REVOKED;
60
+ const act = method === 'GET' ? 'download' : 'upload';
61
+ if (URL.canParse(path))
62
+ return `the ${act} answered ${status}; ${act} the file again`;
63
+ if (status === 502 && local)
64
+ return text;
65
+ return path === '/' ? unconfirmed(status) : `${path} answered ${status}`;
66
+ }
67
+ function unconfirmed(status) {
68
+ return `House answered ${status} ${UNCONFIRMED}`;
69
+ }
70
+ function exchanged(path, method, body, headers = { 'content-type': 'application/json' }, to = socketPath) {
71
+ return new Promise((resolve, reject) => {
72
+ const sent = request({ socketPath: to, path, method, headers }, (answer) => {
73
+ const chunks = [];
74
+ answer.on('data', (chunk) => chunks.push(chunk));
75
+ answer.on('end', () => {
76
+ const bytes = Buffer.concat(chunks);
77
+ if (answer.statusCode === 200)
78
+ resolve(bytes);
79
+ else
80
+ reject(new Error(refused(path, method, answer.statusCode, bytes.toString('utf8'), answer.headers['content-type'] === undefined)));
81
+ });
82
+ });
83
+ sent.on('error', (error) => reject(new Error(error.code === 'EPERM' || error.code === 'EACCES' ? SANDBOXED : CLOSED)));
84
+ sent.end(body === undefined ? undefined : body instanceof Buffer ? body : JSON.stringify(body));
85
+ });
86
+ }
87
+ async function bridged(path, body, headers, to = socketPath) {
88
+ return (await exchanged(path, 'POST', body, headers, to)).toString('utf8');
89
+ }
90
+ async function direct(message) {
91
+ const ownAgent = await readOwnAgent();
92
+ if (ownAgent === null)
93
+ throw new Error(UNCONNECTED);
94
+ selectRelay(process.env.HOUSE_KIT_RELAY || ownAgent.relay);
95
+ setGlobalProxyFromEnv();
96
+ const answer = await callHouse(ownAgent.house, ownAgent.credential, message).catch(() => {
97
+ throw new Error(UNREACHABLE);
98
+ });
99
+ if (answer.status === 200)
100
+ return answer.text;
101
+ throw new Error(answer.status === 401 ? DISCONNECTED : (refusalOf(answer.text)?.text ?? unconfirmed(answer.status)));
102
+ }
103
+ async function mcp(method, params) {
104
+ const message = rpc(method, params);
105
+ const answer = JSON.parse(socketPath === undefined ? await direct(message) : await bridged('/', message));
106
+ if (answer.error !== undefined)
107
+ throw new Error(answer.error.message);
108
+ return answer.result;
109
+ }
110
+ async function tools() {
111
+ return (await mcp('tools/list', {})).tools;
112
+ }
113
+ async function localFile(path) {
114
+ try {
115
+ return await readFile(path);
116
+ }
117
+ catch (error) {
118
+ throw new Error(error.code === 'EISDIR'
119
+ ? `${path} is a folder; upload one file at a time`
120
+ : `${path} is not a readable file`);
121
+ }
122
+ }
123
+ async function transferred(url, method, bytes, headers) {
124
+ if (socketPath !== undefined)
125
+ return exchanged(url, method, bytes, headers);
126
+ setGlobalProxyFromEnv();
127
+ const answer = await fetch(relayed(url), { method, ...(headers === undefined ? {} : { headers }), ...(bytes === undefined ? {} : { body: bytes }) }).catch(() => {
128
+ throw new Error(UNREACHABLE);
129
+ });
130
+ const received = Buffer.from(await answer.arrayBuffer());
131
+ if (answer.status === 200)
132
+ return received;
133
+ throw new Error(refused(url, method, answer.status, received.toString('utf8'), false));
134
+ }
135
+ async function sent(url, bytes, operation) {
136
+ const headers = { 'content-type': 'application/octet-stream', 'x-house-byte-operation': operation };
137
+ return (await transferred(url, 'POST', bytes, headers)).toString('utf8');
138
+ }
139
+ async function download(args) {
140
+ const { flags, positionals: [argument] } = accepted(args, ['--help'], 1, DOWNLOAD_USAGE);
141
+ if (flags.has('--help'))
142
+ return DOWNLOAD_USAGE;
143
+ const { file, ...selected } = argumentsOf(argument);
144
+ if (typeof file !== 'string' || file === '')
145
+ throw new Error('download needs "file", the local file to write');
146
+ const inspected = parse(await called('inspect', selected));
147
+ if (typeof inspected?.download !== 'string')
148
+ throw new Error(`${String(selected.path)} holds no binary file; shell reads its text`);
149
+ const bytes = verified(await transferred(inspected.download, 'GET'), String(inspected.sha256), String(selected.path));
150
+ const written = resolve(file);
151
+ await mkdir(dirname(written), { recursive: true });
152
+ await writeFile(written, bytes);
153
+ return written;
154
+ }
155
+ async function described(file) {
156
+ const bytes = await localFile(file);
157
+ const mediaType = MEDIA_TYPES.get(extname(file).slice(1).toLowerCase());
158
+ return {
159
+ bytes,
160
+ description: {
161
+ bytes: bytes.length,
162
+ sha256: createHash('sha256').update(bytes).digest('hex'),
163
+ ...(mediaType === undefined ? {} : { media_type: mediaType }),
164
+ },
165
+ };
166
+ }
167
+ async function upload({ file, ...destination }) {
168
+ if (typeof file !== 'string' || file === '')
169
+ throw new Error('upload needs "file", a local file');
170
+ const { bytes, description } = await described(file);
171
+ const answer = await called('upload', { ...destination, ...description });
172
+ const declared = parse(answer);
173
+ if (declared.upload === undefined)
174
+ return answer;
175
+ const written = JSON.parse(await sent(declared.upload.url, bytes, declared.upload.operation));
176
+ return stringify(written, { lineWidth: 0 }).trimEnd();
177
+ }
178
+ async function appendRecord(args) {
179
+ const held = new Map();
180
+ const attachments = Array.isArray(args.attachments)
181
+ ? await Promise.all(args.attachments.map(async (attachment) => {
182
+ if (typeof attachment !== 'string')
183
+ return attachment;
184
+ const { bytes, description } = await described(attachment);
185
+ held.set(description.sha256, bytes);
186
+ return { name: basename(attachment), ...description };
187
+ }))
188
+ : args.attachments;
189
+ const record = { ...args, attachments };
190
+ for (;;) {
191
+ const answer = await called('append_record', record);
192
+ const { upload } = parse(answer);
193
+ if (upload === undefined)
194
+ return answer;
195
+ for (const grant of upload)
196
+ await sent(grant.url, held.get(grant.sha256), grant.operation);
197
+ }
198
+ }
199
+ function unexpected(argument, usage) {
200
+ return new Error(`unexpected argument ${argument}; ${usage}`);
201
+ }
202
+ function accepted(args, flags, positionals, usage) {
203
+ const given = { flags: new Set(), positionals: [] };
204
+ for (const arg of args) {
205
+ if (flags.includes(arg))
206
+ given.flags.add(arg);
207
+ else if (!arg.startsWith('-') && given.positionals.length < positionals)
208
+ given.positionals.push(arg);
209
+ else
210
+ throw unexpected(arg, usage);
211
+ }
212
+ return given;
213
+ }
214
+ async function push(args) {
215
+ const { flags, positionals: [commit = 'HEAD'] } = accepted(args, ['--help', '--owner'], 1, PUSH_USAGE);
216
+ if (flags.has('--help'))
217
+ return PUSH_USAGE;
218
+ const owner = flags.has('--owner');
219
+ if (owner && socketPath !== undefined)
220
+ throw new Error('--owner is not for Agent conversations; run house push without it');
221
+ if (!owner && socketPath === undefined)
222
+ throw new Error('outside an Agent conversation, house push needs --owner');
223
+ const pushed = JSON.parse(await bridged('/git/push', { cwd: process.cwd(), commit }, undefined, owner ? join(kitHome(), 'owner.sock') : socketPath));
224
+ if (pushed.refused)
225
+ throw new Error(pushed.text);
226
+ return pushed.text;
227
+ }
228
+ async function fetched(args) {
229
+ if (accepted(args, ['--help'], 0, FETCH_USAGE).flags.has('--help'))
230
+ return FETCH_USAGE;
231
+ const answer = JSON.parse(await bridged('/git/fetch', {}, undefined, socketPath ?? join(kitHome(), 'owner.sock')));
232
+ if (answer.refused)
233
+ throw new Error(answer.text);
234
+ return answer.text;
235
+ }
236
+ function argumentsOf(argument) {
237
+ if (argument === undefined)
238
+ return {};
239
+ let parsed;
240
+ try {
241
+ parsed = JSON.parse(argument);
242
+ }
243
+ catch {
244
+ throw new Error(ARGUMENTS);
245
+ }
246
+ if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed))
247
+ throw new Error(ARGUMENTS);
248
+ return parsed;
249
+ }
250
+ async function house(args) {
251
+ const { flags, positionals: [verb, argument] } = accepted(args, ['--help'], 2, USAGE);
252
+ if (verb === 'help' && argument !== undefined)
253
+ throw unexpected(argument, USAGE);
254
+ if (flags.has('--help') && argument !== undefined)
255
+ throw unexpected('--help', USAGE);
256
+ if (verb === undefined || verb === 'help') {
257
+ return [USAGE, 'help', PUSH, FETCH, DOWNLOAD, ...(await tools()).map((tool) => (tool.description === undefined ? tool.name : `${tool.name}: ${tool.description}`))].join('\n');
258
+ }
259
+ if (flags.has('--help')) {
260
+ const tool = (await tools()).find((listed) => listed.name === verb);
261
+ if (tool === undefined)
262
+ throw new Error(`${verb} is no Tool; house find_command '{"query":"${verb}"}' finds Commands`);
263
+ return [...(tool.description === undefined ? [] : [tool.description]), JSON.stringify(tool.inputSchema)].join('\n');
264
+ }
265
+ const parsed = argumentsOf(argument);
266
+ return verb === 'upload' ? upload(parsed) : verb === 'append_record' ? appendRecord(parsed) : called(verb, parsed);
267
+ }
268
+ async function called(name, args) {
269
+ const result = await mcp('tools/call', { name, arguments: args });
270
+ const text = result.content.map((content) => content.text).join('\n');
271
+ if (result.isError === true)
272
+ throw new Error(text.replace(/\n+$/, ''));
273
+ return text;
274
+ }
275
+ const argv = process.argv.slice(2);
276
+ const named = argv.findIndex((arg) => !arg.startsWith('-'));
277
+ const rest = argv.filter((_arg, index) => index !== named);
278
+ (argv[named] === 'push'
279
+ ? push(rest)
280
+ : argv[named] === 'fetch'
281
+ ? fetched(rest)
282
+ : argv[named] === 'download'
283
+ ? download(rest)
284
+ : house(argv)).then((text) => {
285
+ process.stdout.write(`${text}\n`);
286
+ if (argv[0] === 'shell')
287
+ process.exitCode = Number(/^exit: (\d+)(?:\n|$)/.exec(text)?.[1] ?? 0);
288
+ }, (error) => {
289
+ process.stderr.write(`house: ${error instanceof Error ? error.message : String(error)}\n`);
290
+ process.exitCode = 1;
291
+ });
@@ -1,209 +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
- async function push(args) {
146
- if (args.includes('--help'))
147
- return PUSH_USAGE;
148
- const owner = args.includes('--owner');
149
- const commit = args.find((arg) => arg !== '--owner') ?? 'HEAD';
150
- if (owner && socketPath !== undefined)
151
- throw new Error('--owner is not for Agent conversations; run house push without it');
152
- if (!owner && socketPath === undefined)
153
- throw new Error('outside an Agent conversation, house push needs --owner');
154
- const pushed = JSON.parse(await bridged('/git/push', { cwd: process.cwd(), commit }, undefined, owner ? join(kitHome(), 'owner.sock') : socketPath));
155
- if (pushed.refused)
156
- throw new Error(pushed.text);
157
- return pushed.text;
158
- }
159
- async function fetched(args) {
160
- if (args.includes('--help'))
161
- return FETCH_USAGE;
162
- const answer = JSON.parse(await bridged('/git/fetch', {}, undefined, socketPath ?? join(kitHome(), 'owner.sock')));
163
- if (answer.refused)
164
- throw new Error(answer.text);
165
- return answer.text;
166
- }
167
- function argumentsOf(argument) {
168
- if (argument === undefined)
169
- return {};
170
- let parsed;
171
- try {
172
- parsed = JSON.parse(argument);
173
- }
174
- catch {
175
- throw new Error(ARGUMENTS);
176
- }
177
- if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed))
178
- throw new Error(ARGUMENTS);
179
- return parsed;
180
- }
181
- async function house([verb, argument]) {
182
- if (verb === undefined || verb === '--help' || verb === 'help') {
183
- return [USAGE, 'help', PUSH, FETCH, ...(await tools()).map((tool) => (tool.description === undefined ? tool.name : `${tool.name}: ${tool.description}`))].join('\n');
184
- }
185
- if (argument === '--help') {
186
- const tool = (await tools()).find((listed) => listed.name === verb);
187
- if (tool === undefined)
188
- throw new Error(`${verb} is no Tool; house find_command '{"query":"${verb}"}' finds Commands`);
189
- return [...(tool.description === undefined ? [] : [tool.description]), JSON.stringify(tool.inputSchema)].join('\n');
190
- }
191
- const args = argumentsOf(argument);
192
- return verb === 'upload' ? upload(args) : called(verb, args);
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;
193
6
  }
194
- async function called(name, args) {
195
- const result = await mcp('tools/call', { name, arguments: args });
196
- const text = result.content.map((content) => content.text).join('\n');
197
- if (result.isError === true)
198
- throw new Error(text.replace(/\n+$/, ''));
199
- return text;
7
+ else {
8
+ await import('./house-cli.js');
200
9
  }
201
- const argv = process.argv.slice(2);
202
- (argv[0] === 'push' ? push(argv.slice(1)) : argv[0] === 'fetch' ? fetched(argv.slice(1)) : house(argv)).then((text) => {
203
- process.stdout.write(`${text}\n`);
204
- if (argv[0] === 'shell')
205
- process.exitCode = Number(/^exit: (\d+)(?:\n|$)/.exec(text)?.[1] ?? 0);
206
- }, (error) => {
207
- process.stderr.write(`house: ${error instanceof Error ? error.message : String(error)}\n`);
208
- process.exitCode = 1;
209
- });
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,24 +1,10 @@
1
1
  #!/usr/bin/env node
2
- import { setGlobalProxyFromEnv } from 'node:http';
3
- import { answerGitCredential } from './app-git.js';
4
- import { login } from './login.js';
5
- import { logout } from './logout.js';
6
- import { resident } from './resident.js';
7
- const [command, ...argv] = process.argv.slice(2);
8
- setGlobalProxyFromEnv();
9
- async function run() {
10
- if (command === 'login')
11
- return login(argv);
12
- if (command === 'logout')
13
- return logout();
14
- if (command === 'resident')
15
- return resident();
16
- if (command === 'git-credential')
17
- return answerGitCredential(argv[0]);
18
- process.stderr.write('usage: kit <login|logout|resident>\n');
19
- process.exitCode = 2;
20
- }
21
- run().catch((error) => {
22
- 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`);
23
5
  process.exitCode = 1;
24
- });
6
+ }
7
+ else {
8
+ await import('./kit-cli.js');
9
+ }
10
+ export {};