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