@agentshouse/kit 0.2.1-cca9e1f43de44 → 0.2.1-ccb257fa8a318

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 (132) hide show
  1. package/README.md +42 -40
  2. package/dist/acp.js +92 -115
  3. package/dist/agents.js +112 -24
  4. package/dist/api.js +10 -6
  5. package/dist/app-git.js +10 -26
  6. package/dist/authority-main.js +2 -2
  7. package/dist/bridge.js +11 -25
  8. package/dist/building.js +46 -0
  9. package/dist/calls.js +71 -0
  10. package/dist/chatgpt.js +32 -0
  11. package/dist/clis-main.js +2 -2
  12. package/dist/clis.js +131 -27
  13. package/dist/codex-main.js +58 -0
  14. package/dist/connection.js +116 -0
  15. package/dist/conversations.js +523 -202
  16. package/dist/copies.js +185 -123
  17. package/dist/end.js +24 -5
  18. package/dist/enrol-main.js +7 -1
  19. package/dist/events.js +16 -78
  20. package/dist/files.js +139 -31
  21. package/dist/git.js +13 -11
  22. package/dist/home.js +96 -7
  23. package/dist/house-cli.js +299 -0
  24. package/dist/house-main.js +7 -177
  25. package/dist/instructions.js +8 -10
  26. package/dist/kit-cli.js +68 -0
  27. package/dist/kit-main.js +8 -22
  28. package/dist/login.js +118 -107
  29. package/dist/logout.js +14 -16
  30. package/dist/mcp.js +6 -2
  31. package/dist/parts.js +34 -16
  32. package/dist/placement.js +39 -0
  33. package/dist/relay.js +33 -2
  34. package/dist/resident.js +118 -51
  35. package/dist/scope.js +206 -0
  36. package/dist/scripts.js +255 -0
  37. package/dist/service-main.js +9 -0
  38. package/dist/service.js +55 -0
  39. package/dist/sign-in.js +23 -40
  40. package/dist/silence.js +28 -0
  41. package/dist/skills.js +49 -35
  42. package/dist/transcription.js +85 -45
  43. package/dist/translate.js +2 -8
  44. package/dist/update.js +115 -53
  45. package/dist/wire.js +22 -0
  46. package/dist/work.js +346 -0
  47. package/package.json +20 -20
  48. package/dist/bootstrap.json +0 -24
  49. package/dist/stream.js +0 -72
  50. package/how-we-work.md +0 -23
  51. package/skills/ask-matt/LICENSE +0 -21
  52. package/skills/ask-matt/PHASE-BOUNDARIES.md +0 -55
  53. package/skills/ask-matt/SKILL.md +0 -91
  54. package/skills/ask-matt/agents/openai.yaml +0 -4
  55. package/skills/code-review/LICENSE +0 -21
  56. package/skills/code-review/SKILL.md +0 -89
  57. package/skills/code-review/agents/openai.yaml +0 -3
  58. package/skills/codebase-design/DEEPENING.md +0 -37
  59. package/skills/codebase-design/DESIGN-IT-TWICE.md +0 -44
  60. package/skills/codebase-design/LICENSE +0 -21
  61. package/skills/codebase-design/SKILL.md +0 -116
  62. package/skills/codebase-design/agents/openai.yaml +0 -3
  63. package/skills/diagnosing-bugs/LICENSE +0 -21
  64. package/skills/diagnosing-bugs/SKILL.md +0 -140
  65. package/skills/diagnosing-bugs/agents/openai.yaml +0 -3
  66. package/skills/diagnosing-bugs/scripts/hitl-loop.template.sh +0 -44
  67. package/skills/domain-modeling/ADR-FORMAT.md +0 -47
  68. package/skills/domain-modeling/CONTEXT-FORMAT.md +0 -60
  69. package/skills/domain-modeling/LICENSE +0 -21
  70. package/skills/domain-modeling/SKILL.md +0 -76
  71. package/skills/domain-modeling/agents/openai.yaml +0 -3
  72. package/skills/grill-me/LICENSE +0 -21
  73. package/skills/grill-me/SKILL.md +0 -8
  74. package/skills/grill-me/agents/openai.yaml +0 -4
  75. package/skills/grill-with-docs/LICENSE +0 -21
  76. package/skills/grill-with-docs/SKILL.md +0 -8
  77. package/skills/grill-with-docs/agents/openai.yaml +0 -4
  78. package/skills/grilling/LICENSE +0 -21
  79. package/skills/grilling/SKILL.md +0 -30
  80. package/skills/grilling/agents/openai.yaml +0 -3
  81. package/skills/handoff/LICENSE +0 -21
  82. package/skills/handoff/SKILL.md +0 -17
  83. package/skills/handoff/agents/openai.yaml +0 -4
  84. package/skills/implement/LICENSE +0 -21
  85. package/skills/implement/SKILL.md +0 -16
  86. package/skills/implement/agents/openai.yaml +0 -4
  87. package/skills/improve-codebase-architecture/HTML-REPORT.md +0 -123
  88. package/skills/improve-codebase-architecture/LICENSE +0 -21
  89. package/skills/improve-codebase-architecture/SKILL.md +0 -72
  90. package/skills/improve-codebase-architecture/agents/openai.yaml +0 -4
  91. package/skills/prototype/LICENSE +0 -21
  92. package/skills/prototype/LOGIC.md +0 -67
  93. package/skills/prototype/SKILL.md +0 -28
  94. package/skills/prototype/UI.md +0 -112
  95. package/skills/prototype/agents/openai.yaml +0 -3
  96. package/skills/research/LICENSE +0 -21
  97. package/skills/research/SKILL.md +0 -14
  98. package/skills/research/agents/openai.yaml +0 -3
  99. package/skills/resolving-merge-conflicts/LICENSE +0 -21
  100. package/skills/resolving-merge-conflicts/SKILL.md +0 -16
  101. package/skills/resolving-merge-conflicts/agents/openai.yaml +0 -3
  102. package/skills/tdd/LICENSE +0 -21
  103. package/skills/tdd/SKILL.md +0 -40
  104. package/skills/tdd/agents/openai.yaml +0 -3
  105. package/skills/tdd/mocking.md +0 -59
  106. package/skills/tdd/tests.md +0 -77
  107. package/skills/teach/GLOSSARY-FORMAT.md +0 -35
  108. package/skills/teach/LEARNING-RECORD-FORMAT.md +0 -46
  109. package/skills/teach/LICENSE +0 -21
  110. package/skills/teach/MISSION-FORMAT.md +0 -31
  111. package/skills/teach/RESOURCES-FORMAT.md +0 -32
  112. package/skills/teach/SKILL.md +0 -141
  113. package/skills/teach/agents/openai.yaml +0 -4
  114. package/skills/to-questionnaire/LICENSE +0 -21
  115. package/skills/to-questionnaire/SKILL.md +0 -55
  116. package/skills/to-questionnaire/agents/openai.yaml +0 -4
  117. package/skills/to-spec/LICENSE +0 -21
  118. package/skills/to-spec/SKILL.md +0 -76
  119. package/skills/to-spec/agents/openai.yaml +0 -4
  120. package/skills/to-tickets/LICENSE +0 -21
  121. package/skills/to-tickets/SKILL.md +0 -106
  122. package/skills/to-tickets/agents/openai.yaml +0 -4
  123. package/skills/wait-what/LICENSE +0 -21
  124. package/skills/wait-what/SKILL.md +0 -8
  125. package/skills/wait-what/agents/openai.yaml +0 -4
  126. package/skills/wayfinder/LICENSE +0 -21
  127. package/skills/wayfinder/SKILL.md +0 -129
  128. package/skills/wayfinder/agents/openai.yaml +0 -4
  129. package/skills/writing-for-agents/LICENSE +0 -21
  130. package/skills/writing-for-agents/SKILL-MECHANICS.md +0 -22
  131. package/skills/writing-for-agents/SKILL.md +0 -83
  132. package/skills/writing-for-agents/agents/openai.yaml +0 -3
@@ -0,0 +1,299 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { createReadStream } from 'node:fs';
3
+ import { request } from 'node:http';
4
+ import { request as httpsRequest } from 'node:https';
5
+ import { extname, join, resolve } from 'node:path';
6
+ import { Readable } from 'node:stream';
7
+ import { pipeline } from 'node:stream/promises';
8
+ import { downloaded, inspectedFile, storeRefusal, uploaded } from './files.js';
9
+ import { HOUSE_REF } from './git.js';
10
+ import { ownerSocket, readOwnAgent } from './home.js';
11
+ import { callHouse, rpc, UNREACHABLE, Unsettled } from './mcp.js';
12
+ import { refusalOf, retryable } from './refusals.js';
13
+ import { proxyUnlessRelayed, relayed, selectRelay } from './relay.js';
14
+ import { parse } from 'yaml';
15
+ const USAGE = "usage: house <tool> ['<arguments as JSON>']";
16
+ const PUSH_USAGE = 'usage: house push [commit] [--owner]';
17
+ const PUSH = "push [commit]: sends the Local copy's committed changes to House";
18
+ const FETCH_USAGE = 'usage: house fetch';
19
+ const FETCH = `fetch: records House's changes on each Local copy's ${HOUSE_REF}`;
20
+ const DOWNLOAD_USAGE = `usage: house download '{"path":"/rooms/<handle>/<path>","file":"<local file>"}', adding "ref" for a revision`;
21
+ const DOWNLOAD = 'download: writes a binary file of a Room to the local file named by file';
22
+ const ARGUMENTS = `the arguments are one JSON object in single quotes, like house search '{"query":"invoice"}'`;
23
+ const CLOSED = "this conversation's House connection is closed; nothing to do from here";
24
+ const SANDBOXED = "your CLI's sandbox kept house from House; run house directly, not through another program";
25
+ const REVOKED = 'this conversation no longer has House access; nothing to do from here';
26
+ const UNCONNECTED = "this computer's own agent has no House connection; run kit login, or kit chatgpt --key <key> with a script key";
27
+ const DISCONNECTED = "House no longer accepts this computer's own agent; run kit login, or kit chatgpt --key <key> with a script key";
28
+ const UNCONFIRMED = 'with no result; a write may or may not have taken effect, so read before you repeat it';
29
+ const socketPath = process.env.HOUSE_BRIDGE;
30
+ const MEDIA_TYPES = new Map([
31
+ ['avif', 'image/avif'],
32
+ ['csv', 'text/csv'],
33
+ ['docx', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'],
34
+ ['gif', 'image/gif'],
35
+ ['heic', 'image/heic'],
36
+ ['html', 'text/html'],
37
+ ['jpeg', 'image/jpeg'],
38
+ ['jpg', 'image/jpeg'],
39
+ ['json', 'application/json'],
40
+ ['m4a', 'audio/mp4'],
41
+ ['md', 'text/markdown'],
42
+ ['mov', 'video/quicktime'],
43
+ ['mp3', 'audio/mpeg'],
44
+ ['mp4', 'video/mp4'],
45
+ ['ogg', 'audio/ogg'],
46
+ ['pdf', 'application/pdf'],
47
+ ['png', 'image/png'],
48
+ ['pptx', 'application/vnd.openxmlformats-officedocument.presentationml.presentation'],
49
+ ['svg', 'image/svg+xml'],
50
+ ['txt', 'text/plain'],
51
+ ['wav', 'audio/wav'],
52
+ ['webm', 'video/webm'],
53
+ ['webp', 'image/webp'],
54
+ ['xlsx', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'],
55
+ ['zip', 'application/zip'],
56
+ ]);
57
+ function refused(path, status, text, local) {
58
+ const refusal = refusalOf(text);
59
+ if (refusal !== null)
60
+ return refusal.text;
61
+ if (status === 401)
62
+ return REVOKED;
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 bridged(path, body, to = socketPath) {
71
+ return new Promise((resolve, reject) => {
72
+ const sent = request({ socketPath: to, path, method: 'POST', headers: { 'content-type': 'application/json' } }, (answer) => {
73
+ const chunks = [];
74
+ answer.on('data', (chunk) => chunks.push(chunk));
75
+ answer.on('end', () => {
76
+ const text = Buffer.concat(chunks).toString('utf8');
77
+ if (answer.statusCode === 200)
78
+ resolve(text);
79
+ else
80
+ reject(new Error(refused(path, answer.statusCode, text, 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(JSON.stringify(body));
85
+ });
86
+ }
87
+ async function direct(message) {
88
+ const ownAgent = await readOwnAgent();
89
+ if (ownAgent === null)
90
+ throw new Error(UNCONNECTED);
91
+ selectRelay(process.env.HOUSE_KIT_RELAY || ownAgent.relay);
92
+ const answer = await callHouse(ownAgent.house, ownAgent.credential, message).catch(() => {
93
+ throw new Unsettled(UNREACHABLE);
94
+ });
95
+ if (answer.status === 200)
96
+ return answer.text;
97
+ if (answer.status === 401)
98
+ throw new Error(DISCONNECTED);
99
+ const refusal = refusalOf(answer.text)?.text ?? unconfirmed(answer.status);
100
+ throw retryable(answer.text) === false ? new Error(refusal) : new Unsettled(refusal);
101
+ }
102
+ async function mcp(method, params) {
103
+ const message = rpc(method, params);
104
+ const answer = JSON.parse(socketPath === undefined ? await direct(message) : await bridged('/', message));
105
+ if (answer.error !== undefined)
106
+ throw new Error(answer.error.message);
107
+ return answer.result;
108
+ }
109
+ async function tools() {
110
+ return (await mcp('tools/list', {})).tools;
111
+ }
112
+ function unreadable(path, error) {
113
+ return new Error(error.code === 'EISDIR'
114
+ ? `${path} is a folder; upload one file at a time`
115
+ : `${path} is not a readable file`);
116
+ }
117
+ function opened(url, method, headers, body) {
118
+ return new Promise((answered, failed) => {
119
+ const local = socketPath !== undefined;
120
+ const target = local ? null : relayed(url);
121
+ if (!local)
122
+ proxyUnlessRelayed();
123
+ const sent = target === null
124
+ ? request({ socketPath, path: url, method, headers }, answered)
125
+ : (target.protocol === 'https:' ? httpsRequest : request)(target, { method, headers }, answered);
126
+ sent.on('error', (error) => failed(new Error(!local ? UNREACHABLE : error.code === 'EPERM' || error.code === 'EACCES' ? SANDBOXED : CLOSED)));
127
+ if (body === undefined)
128
+ sent.end();
129
+ else
130
+ pipeline(body, sent).catch(() => undefined);
131
+ });
132
+ }
133
+ function ranged(file, start, end) {
134
+ return end === start ? undefined : createReadStream(file, { start, end: end - 1 });
135
+ }
136
+ async function* read(file, start, end) {
137
+ try {
138
+ yield* ranged(file, start, end) ?? [];
139
+ }
140
+ catch (error) {
141
+ throw unreadable(file, error);
142
+ }
143
+ }
144
+ async function sentPart(url, file, start, end, headers) {
145
+ const answer = await opened(url, 'PUT', { ...headers, 'content-length': String(end - start) }, ranged(file, start, end));
146
+ await answer.toArray();
147
+ if (answer.statusCode !== 200)
148
+ throw storeRefusal('upload', answer.statusCode);
149
+ }
150
+ async function download(args) {
151
+ const { flags, positionals: [argument] } = accepted(args, ['--help'], 1, DOWNLOAD_USAGE);
152
+ if (flags.has('--help'))
153
+ return DOWNLOAD_USAGE;
154
+ const { file, ...selected } = argumentsOf(argument);
155
+ if (typeof file !== 'string' || file === '')
156
+ throw new Error('download needs "file", the local file to write');
157
+ const written = resolve(file);
158
+ await downloaded(async () => {
159
+ const file = inspectedFile(await called('inspect', selected));
160
+ if (file === null)
161
+ throw new Error(`${String(selected.path)} holds no binary file; shell reads its text`);
162
+ return file;
163
+ }, async (url) => {
164
+ const answer = await opened(url, 'GET', {});
165
+ return { status: answer.statusCode, body: answer };
166
+ }, written, String(selected.path));
167
+ return written;
168
+ }
169
+ async function described(file) {
170
+ const digest = createHash('sha256');
171
+ let bytes = 0;
172
+ try {
173
+ for await (const chunk of createReadStream(file)) {
174
+ digest.update(chunk);
175
+ bytes += chunk.length;
176
+ }
177
+ }
178
+ catch (error) {
179
+ throw unreadable(file, error);
180
+ }
181
+ const mediaType = MEDIA_TYPES.get(extname(file).slice(1).toLowerCase());
182
+ return { bytes, sha256: digest.digest('hex'), ...(mediaType === undefined ? {} : { media_type: mediaType }) };
183
+ }
184
+ async function finished(upload, room, partSha256) {
185
+ const text = await called('upload', { upload, room_ref: room, part_sha256: partSha256 });
186
+ const answer = parse(text);
187
+ return answer !== null && 'upload' in answer ? answer : { text };
188
+ }
189
+ async function upload({ file, ...destination }) {
190
+ if (typeof file !== 'string' || file === '')
191
+ throw new Error('upload needs "file", a local file');
192
+ const description = await described(file);
193
+ const answer = await called('upload', { ...destination, ...description });
194
+ const declared = parse(answer);
195
+ if (declared?.upload === undefined)
196
+ return answer;
197
+ const accepted = await uploaded(declared.upload, {
198
+ name: file,
199
+ bytes: description.bytes,
200
+ sha256: description.sha256,
201
+ read: (start, end) => read(file, start, end),
202
+ send: (url, start, end, headers) => sentPart(url, file, start, end, headers),
203
+ finish: (id, partSha256) => finished(id, destination.room_ref, partSha256),
204
+ });
205
+ return accepted.text;
206
+ }
207
+ function unexpected(argument, usage) {
208
+ return new Error(`unexpected argument ${argument}; ${usage}`);
209
+ }
210
+ function accepted(args, flags, positionals, usage) {
211
+ const given = { flags: new Set(), positionals: [] };
212
+ for (const arg of args) {
213
+ if (flags.includes(arg))
214
+ given.flags.add(arg);
215
+ else if (!arg.startsWith('-') && given.positionals.length < positionals)
216
+ given.positionals.push(arg);
217
+ else
218
+ throw unexpected(arg, usage);
219
+ }
220
+ return given;
221
+ }
222
+ async function push(args) {
223
+ const { flags, positionals: [commit = 'HEAD'] } = accepted(args, ['--help', '--owner'], 1, PUSH_USAGE);
224
+ if (flags.has('--help'))
225
+ return PUSH_USAGE;
226
+ const owner = flags.has('--owner');
227
+ if (owner && socketPath !== undefined)
228
+ throw new Error('--owner is not for Agent conversations; run house push without it');
229
+ if (!owner && socketPath === undefined)
230
+ throw new Error('outside an Agent conversation, house push needs --owner');
231
+ const pushed = JSON.parse(await bridged('/git/push', { cwd: process.cwd(), commit }, owner ? ownerSocket() : socketPath));
232
+ if (pushed.refused)
233
+ throw new Error(pushed.text);
234
+ return pushed.text;
235
+ }
236
+ async function fetched(args) {
237
+ if (accepted(args, ['--help'], 0, FETCH_USAGE).flags.has('--help'))
238
+ return FETCH_USAGE;
239
+ const answer = JSON.parse(await bridged('/git/fetch', {}, socketPath ?? ownerSocket()));
240
+ if (answer.refused)
241
+ throw new Error(answer.text);
242
+ return answer.text;
243
+ }
244
+ function argumentsOf(argument) {
245
+ if (argument === undefined)
246
+ return {};
247
+ let parsed;
248
+ try {
249
+ parsed = JSON.parse(argument);
250
+ }
251
+ catch {
252
+ throw new Error(ARGUMENTS);
253
+ }
254
+ if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed))
255
+ throw new Error(ARGUMENTS);
256
+ return parsed;
257
+ }
258
+ async function house(args) {
259
+ const { flags, positionals: [verb, argument] } = accepted(args, ['--help'], 2, USAGE);
260
+ if (verb === 'help' && argument !== undefined)
261
+ throw unexpected(argument, USAGE);
262
+ if (flags.has('--help') && argument !== undefined)
263
+ throw unexpected('--help', USAGE);
264
+ if (verb === undefined || verb === 'help') {
265
+ return [USAGE, 'help', PUSH, FETCH, DOWNLOAD, ...(await tools()).map((tool) => (tool.description === undefined ? tool.name : `${tool.name}: ${tool.description}`))].join('\n');
266
+ }
267
+ if (flags.has('--help')) {
268
+ const tool = (await tools()).find((listed) => listed.name === verb);
269
+ if (tool === undefined)
270
+ throw new Error(`${verb} is no Tool; house find_command '{"query":"${verb}"}' finds Commands`);
271
+ return [...(tool.description === undefined ? [] : [tool.description]), JSON.stringify(tool.inputSchema)].join('\n');
272
+ }
273
+ const parsed = argumentsOf(argument);
274
+ return verb === 'upload' ? upload(parsed) : called(verb, parsed);
275
+ }
276
+ async function called(name, args) {
277
+ const result = await mcp('tools/call', { name, arguments: args });
278
+ const text = result.content.map((content) => content.text).join('\n');
279
+ if (result.isError === true)
280
+ throw new Error(text.replace(/\n+$/, ''));
281
+ return text;
282
+ }
283
+ const argv = process.argv.slice(2);
284
+ const named = argv.findIndex((arg) => !arg.startsWith('-'));
285
+ const rest = argv.filter((_arg, index) => index !== named);
286
+ (argv[named] === 'push'
287
+ ? push(rest)
288
+ : argv[named] === 'fetch'
289
+ ? fetched(rest)
290
+ : argv[named] === 'download'
291
+ ? download(rest)
292
+ : house(argv)).then((text) => {
293
+ process.stdout.write(`${text}\n`);
294
+ if (argv[0] === 'shell')
295
+ process.exitCode = Number(/^exit: (\d+)(?:\n|$)/.exec(text)?.[1] ?? 0);
296
+ }, (error) => {
297
+ process.stderr.write(`house: ${error instanceof Error ? error.message : String(error)}\n`);
298
+ process.exitCode = 1;
299
+ });
@@ -1,180 +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 { basename, join } from 'node:path';
6
- import { kitHome, readOwnAgent } from './home.js';
7
- import { callHouse, rpc, UNREACHABLE } from './mcp.js';
8
- import { refusalOf } from './refusals.js';
9
- import { relayed } from './relay.js';
10
- import { parse } from 'yaml';
11
- const USAGE = "usage: house <tool> ['<arguments as JSON>']";
12
- const PUSH_USAGE = 'usage: house push [commit] [--owner]';
13
- const PUSH = "push [commit]: sends the Local copy's committed changes to House";
14
- const ARGUMENTS = `the arguments are one JSON object in single quotes, like house search '{"query":"invoice"}'`;
15
- const CLOSED = "this conversation's House connection is closed; nothing to do from here";
16
- const SANDBOXED = "your CLI's sandbox kept house from House; run house as a command of its own, with no pipe, chain or redirect";
17
- const REVOKED = 'this conversation no longer has House access; nothing to do from here';
18
- const UNCONNECTED = "this computer's own agent has no House connection; run kit login";
19
- const DISCONNECTED = "House no longer accepts this computer's own agent; run kit login";
20
- const socketPath = process.env.HOUSE_BRIDGE;
21
- function refused(path, status, text) {
22
- const refusal = refusalOf(text);
23
- if (refusal !== null)
24
- return refusal.text;
25
- if (status === 401)
26
- return REVOKED;
27
- if (URL.canParse(path))
28
- return `the upload answered ${status}; upload the file again`;
29
- if (status === 502 && /^[A-Za-z]/.test(text))
30
- return text;
31
- return `${path} answered ${status}`;
32
- }
33
- function bridged(path, body, headers = { 'content-type': 'application/json' }, to = socketPath) {
34
- return new Promise((resolve, reject) => {
35
- const sent = request({ socketPath: to, path, method: 'POST', headers }, (answer) => {
36
- let text = '';
37
- answer.setEncoding('utf8');
38
- answer.on('data', (chunk) => {
39
- text += chunk;
40
- });
41
- answer.on('end', () => {
42
- if (answer.statusCode === 200)
43
- resolve(text);
44
- else
45
- reject(new Error(refused(path, answer.statusCode, text)));
46
- });
47
- });
48
- sent.on('error', (error) => reject(new Error(error.code === 'EPERM' || error.code === 'EACCES' ? SANDBOXED : CLOSED)));
49
- sent.end(body instanceof Buffer ? body : JSON.stringify(body));
50
- });
51
- }
52
- async function direct(message) {
53
- const ownAgent = await readOwnAgent();
54
- if (ownAgent === null)
55
- throw new Error(UNCONNECTED);
56
- setGlobalProxyFromEnv();
57
- const answer = await callHouse(ownAgent.house, ownAgent.credential, message).catch(() => {
58
- throw new Error(UNREACHABLE);
59
- });
60
- if (answer.status === 200)
61
- return answer.text;
62
- throw new Error(answer.status === 401 ? DISCONNECTED : (refusalOf(answer.text)?.text ?? `House answered ${answer.status}`));
63
- }
64
- async function mcp(method, params) {
65
- const message = rpc(method, params);
66
- const answer = JSON.parse(socketPath === undefined ? await direct(message) : await bridged('/', message));
67
- if (answer.error !== undefined)
68
- throw new Error(answer.error.message);
69
- return answer.result;
70
- }
71
- async function tools() {
72
- return (await mcp('tools/list', {})).tools;
73
- }
74
- async function localFile(path) {
75
- try {
76
- return await readFile(path);
77
- }
78
- catch (error) {
79
- throw new Error(error.code === 'EISDIR'
80
- ? `${path} is a folder; upload one file at a time`
81
- : `${path} is not a readable file`);
82
- }
83
- }
84
- async function sent(url, bytes, operation) {
85
- const headers = { 'content-type': 'application/octet-stream', 'x-house-byte-operation': operation };
86
- if (socketPath !== undefined)
87
- return bridged(url, bytes, headers);
88
- setGlobalProxyFromEnv();
89
- const answer = await fetch(relayed(url), { method: 'POST', headers, body: bytes }).catch(() => {
90
- throw new Error(UNREACHABLE);
91
- });
92
- const text = await answer.text();
93
- if (answer.status === 200)
94
- return text;
95
- throw new Error(refused(url, answer.status, text));
96
- }
97
- async function upload(path, roomRef, missing) {
98
- if (typeof path !== 'string' || path === '')
99
- throw new Error(missing);
100
- const bytes = await localFile(path);
101
- const declared = parse(await called('upload', {
102
- ...(roomRef === undefined ? {} : { room_ref: roomRef }),
103
- name: basename(path),
104
- bytes: bytes.length,
105
- sha256: createHash('sha256').update(bytes).digest('hex'),
106
- }));
107
- if (declared.upload === undefined)
108
- return declared.attachment;
109
- const saved = JSON.parse(await sent(declared.upload.url, bytes, declared.upload.operation));
110
- if (saved.upload_failure !== undefined)
111
- throw new Error(`${path} was not saved: ${saved.upload_failure}; call again later`);
112
- return saved.attachment;
113
- }
114
- async function push(args) {
115
- if (args.includes('--help'))
116
- return PUSH_USAGE;
117
- const owner = args.includes('--owner');
118
- const commit = args.find((arg) => arg !== '--owner') ?? 'HEAD';
119
- if (owner && socketPath !== undefined)
120
- throw new Error('--owner is not for Agent conversations; run house push without it');
121
- if (!owner && socketPath === undefined)
122
- throw new Error('outside an Agent conversation, house push needs --owner');
123
- const pushed = JSON.parse(await bridged('/git/push', { cwd: process.cwd(), commit }, undefined, owner ? join(kitHome(), 'owner.sock') : socketPath));
124
- if (pushed.refused)
125
- throw new Error(pushed.text);
126
- return pushed.text;
127
- }
128
- function argumentsOf(argument) {
129
- if (argument === undefined)
130
- return {};
131
- let parsed;
132
- try {
133
- parsed = JSON.parse(argument);
134
- }
135
- catch {
136
- throw new Error(ARGUMENTS);
137
- }
138
- if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed))
139
- throw new Error(ARGUMENTS);
140
- return parsed;
141
- }
142
- async function house([verb, argument]) {
143
- if (verb === undefined || verb === '--help' || verb === 'help') {
144
- return [USAGE, 'help', PUSH, ...(await tools()).map((tool) => (tool.description === undefined ? tool.name : `${tool.name}: ${tool.description}`))].join('\n');
145
- }
146
- if (argument === '--help') {
147
- const tool = (await tools()).find((listed) => listed.name === verb);
148
- if (tool === undefined)
149
- throw new Error(`${verb} is no Tool; house find_command '{"query":"${verb}"}' finds Commands`);
150
- return [...(tool.description === undefined ? [] : [tool.description]), JSON.stringify(tool.inputSchema)].join('\n');
151
- }
152
- const args = argumentsOf(argument);
153
- if (verb === 'upload') {
154
- return JSON.stringify({ attachment: await upload(args.path, args.room_ref, 'upload needs "path", a local file') });
155
- }
156
- if (verb === 'append_record' && Array.isArray(args.attachments)) {
157
- const attachments = [];
158
- for (const path of args.attachments) {
159
- attachments.push(await upload(path, args.room_ref, 'each attachments entry is the path of a local file'));
160
- }
161
- args.attachments = attachments;
162
- }
163
- return called(verb, args);
2
+ const [major = 0, minor = 0, patch = 0] = process.versions.node.split('.').map(Number);
3
+ if (major < 24 || (major === 24 && (minor < 22 || (minor === 22 && patch < 1)))) {
4
+ process.stderr.write(`house: the Kit needs Node 24.22.1 or newer; this is ${process.versions.node}\n`);
5
+ process.exitCode = 1;
164
6
  }
165
- async function called(name, args) {
166
- const result = await mcp('tools/call', { name, arguments: args });
167
- const text = result.content.map((content) => content.text).join('\n');
168
- if (result.isError === true)
169
- throw new Error(text.replace(/\n+$/, ''));
170
- return text;
7
+ else {
8
+ await import('./house-cli.js');
171
9
  }
172
- const argv = process.argv.slice(2);
173
- (argv[0] === 'push' ? push(argv.slice(1)) : house(argv)).then((text) => {
174
- process.stdout.write(`${text}\n`);
175
- if (argv[0] === 'shell')
176
- process.exitCode = Number(/^exit: (\d+)(?:\n|$)/.exec(text)?.[1] ?? 0);
177
- }, (error) => {
178
- process.stderr.write(`house: ${error instanceof Error ? error.message : String(error)}\n`);
179
- process.exitCode = 1;
180
- });
10
+ export {};
@@ -1,8 +1,6 @@
1
- import { HOW_WE_WORK } from './skills.js';
2
- const HOUSE_LINE = 'Work with House through the `house` CLI: run `house --help`.';
3
- const FILE_LINE = 'To give the User a file or a page, upload it with `house upload` and link it; never start a server.';
4
- const READ_LINE = 'Before working in a Room, read `/rooms/private/rooms/<handle>/AGENTS.md`.';
5
- const COPIES_LINE = 'House Local copies; commit, then `house push`:';
1
+ import { agentInstructions } from '@agentshouse/skills';
2
+ import { HOUSE_REF } from './git.js';
3
+ const OWNER_RULES = '/rooms/private/owner-rules.md';
6
4
  const UNREADABLE = /^(?:\S+: )?(?:path_not_found|room_not_found|operation_denied)\b/;
7
5
  const FAILED = /^exit: [1-9]\d*$/;
8
6
  const CUT = /^stderr: shell: output_cut (\d+) of \d+ bytes; continue with: (.+)$/;
@@ -10,9 +8,9 @@ function cutOf(lines) {
10
8
  const cut = CUT.exec(lines[0] ?? '');
11
9
  return cut !== null && Buffer.byteLength(lines.slice(1).join('\n')) === Number(cut[1]) ? cut : null;
12
10
  }
13
- async function howWeWork(bridge) {
11
+ async function readOwnerRules(bridge) {
14
12
  let document = '';
15
- for (let command = `cat ${HOW_WE_WORK}`; command !== undefined;) {
13
+ for (let command = `cat ${OWNER_RULES}`; command !== undefined;) {
16
14
  const read = await bridge.tool('shell', { command });
17
15
  const text = read.content.map((content) => content.text).join('\n');
18
16
  const lines = text.split('\n');
@@ -26,9 +24,9 @@ async function howWeWork(bridge) {
26
24
  document += lines.slice(cut === null ? 0 : 1).join('\n');
27
25
  command = cut?.[2];
28
26
  }
29
- return document.replace(/\n$/, '');
27
+ return document;
30
28
  }
31
29
  export async function instructions(bridge, base, copies) {
32
- const lines = [HOUSE_LINE, FILE_LINE, READ_LINE, ...(copies.length === 0 ? [] : [COPIES_LINE, ...copies])];
33
- return [lines.join('\n'), base, await howWeWork(bridge)].filter((part) => part !== '').join('\n\n');
30
+ const lines = agentInstructions(HOUSE_REF, copies);
31
+ return [lines.join('\n'), base, (await readOwnerRules(bridge)).replace(/\n$/, '')].filter((part) => part !== '').join('\n\n');
34
32
  }
@@ -0,0 +1,68 @@
1
+ import { parseArgs } from 'node:util';
2
+ import { answerGitCredential } from './app-git.js';
3
+ import { chatgpt } from './chatgpt.js';
4
+ import { login } from './login.js';
5
+ import { logout } from './logout.js';
6
+ import { proxyUnlessRelayed } from './relay.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 the Kit process 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; 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
+ proxyUnlessRelayed();
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, patch = 0] = process.versions.node.split('.').map(Number);
3
+ if (major < 24 || (major === 24 && (minor < 22 || (minor === 22 && patch < 1)))) {
4
+ process.stderr.write(`kit: the Kit needs Node 24.22.1 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 {};