@agentshouse/kit 0.2.1-cf110d15f69c8 → 0.2.1-cf2c570b41f24
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 +38 -44
- package/dist/acp.js +96 -22
- package/dist/afk.js +17 -0
- package/dist/agents.js +221 -65
- package/dist/api.js +21 -3
- package/dist/app-git.js +10 -26
- package/dist/binaries.js +60 -0
- package/dist/bridge.js +101 -49
- package/dist/building.js +50 -0
- package/dist/calls.js +88 -0
- package/dist/chunks.js +54 -0
- package/dist/clis.js +80 -52
- package/dist/connect.js +121 -0
- package/dist/connection.js +120 -0
- package/dist/content.js +106 -0
- package/dist/conversations.js +711 -267
- package/dist/copies.js +1293 -595
- package/dist/earlier.js +273 -0
- package/dist/end.js +15 -3
- package/dist/events.js +553 -281
- package/dist/files.js +206 -32
- package/dist/git.js +2 -70
- package/dist/grok.js +39 -0
- package/dist/home.js +123 -15
- package/dist/house-cli.js +282 -0
- package/dist/house-main.js +7 -206
- package/dist/instructions.js +7 -13
- package/dist/keys.js +238 -0
- package/dist/kit-cli.js +78 -0
- package/dist/kit-main.js +8 -22
- package/dist/login.js +71 -39
- package/dist/logout.js +2 -4
- package/dist/manifest.js +75 -0
- package/dist/mcp.js +47 -7
- package/dist/owner.js +46 -0
- package/dist/placement.js +25 -0
- package/dist/refusals.js +50 -23
- package/dist/relay.js +22 -1
- package/dist/resident.js +153 -53
- package/dist/scope.js +15 -4
- package/dist/scripts.js +319 -0
- package/dist/secret-input.js +1 -1
- package/dist/settings.js +247 -0
- package/dist/sign-in.js +66 -38
- package/dist/silence.js +28 -0
- package/dist/skills.js +49 -35
- package/dist/supervisor.js +163 -0
- package/dist/transcription.js +90 -47
- package/dist/update.js +119 -102
- package/dist/wire.js +32 -0
- package/dist/work.js +30 -7
- package/dist/workspace.js +113 -0
- package/package.json +25 -21
- package/dist/authority-main.js +0 -22
- package/dist/bootstrap.json +0 -24
- package/dist/clis-main.js +0 -23
- package/dist/configure-main.js +0 -6
- package/dist/enrol-main.js +0 -10
- package/dist/git-main.js +0 -153
- package/dist/parts.js +0 -82
- package/dist/service-main.js +0 -9
- package/dist/service.js +0 -33
- package/dist/stream.js +0 -74
- package/dist/translate.js +0 -51
- package/how-we-work.md +0 -23
- package/skills/ask-matt/LICENSE +0 -21
- package/skills/ask-matt/PHASE-BOUNDARIES.md +0 -55
- package/skills/ask-matt/SKILL.md +0 -91
- package/skills/ask-matt/agents/openai.yaml +0 -4
- package/skills/code-review/LICENSE +0 -21
- package/skills/code-review/SKILL.md +0 -89
- package/skills/code-review/agents/openai.yaml +0 -3
- package/skills/codebase-design/DEEPENING.md +0 -37
- package/skills/codebase-design/DESIGN-IT-TWICE.md +0 -44
- package/skills/codebase-design/LICENSE +0 -21
- package/skills/codebase-design/SKILL.md +0 -116
- package/skills/codebase-design/agents/openai.yaml +0 -3
- package/skills/diagnosing-bugs/LICENSE +0 -21
- package/skills/diagnosing-bugs/SKILL.md +0 -140
- package/skills/diagnosing-bugs/agents/openai.yaml +0 -3
- package/skills/diagnosing-bugs/scripts/hitl-loop.template.sh +0 -44
- package/skills/domain-modeling/ADR-FORMAT.md +0 -47
- package/skills/domain-modeling/CONTEXT-FORMAT.md +0 -60
- package/skills/domain-modeling/LICENSE +0 -21
- package/skills/domain-modeling/SKILL.md +0 -76
- package/skills/domain-modeling/agents/openai.yaml +0 -3
- package/skills/grill-me/LICENSE +0 -21
- package/skills/grill-me/SKILL.md +0 -8
- package/skills/grill-me/agents/openai.yaml +0 -4
- package/skills/grill-with-docs/LICENSE +0 -21
- package/skills/grill-with-docs/SKILL.md +0 -8
- package/skills/grill-with-docs/agents/openai.yaml +0 -4
- package/skills/grilling/LICENSE +0 -21
- package/skills/grilling/SKILL.md +0 -30
- package/skills/grilling/agents/openai.yaml +0 -3
- package/skills/handoff/LICENSE +0 -21
- package/skills/handoff/SKILL.md +0 -17
- package/skills/handoff/agents/openai.yaml +0 -4
- package/skills/implement/LICENSE +0 -21
- package/skills/implement/SKILL.md +0 -16
- package/skills/implement/agents/openai.yaml +0 -4
- package/skills/improve-codebase-architecture/HTML-REPORT.md +0 -123
- package/skills/improve-codebase-architecture/LICENSE +0 -21
- package/skills/improve-codebase-architecture/SKILL.md +0 -72
- package/skills/improve-codebase-architecture/agents/openai.yaml +0 -4
- package/skills/prototype/LICENSE +0 -21
- package/skills/prototype/LOGIC.md +0 -67
- package/skills/prototype/SKILL.md +0 -28
- package/skills/prototype/UI.md +0 -112
- package/skills/prototype/agents/openai.yaml +0 -3
- package/skills/research/LICENSE +0 -21
- package/skills/research/SKILL.md +0 -14
- package/skills/research/agents/openai.yaml +0 -3
- package/skills/resolving-merge-conflicts/LICENSE +0 -21
- package/skills/resolving-merge-conflicts/SKILL.md +0 -16
- package/skills/resolving-merge-conflicts/agents/openai.yaml +0 -3
- package/skills/tdd/LICENSE +0 -21
- package/skills/tdd/SKILL.md +0 -40
- package/skills/tdd/agents/openai.yaml +0 -3
- package/skills/tdd/mocking.md +0 -59
- package/skills/tdd/tests.md +0 -77
- package/skills/teach/GLOSSARY-FORMAT.md +0 -35
- package/skills/teach/LEARNING-RECORD-FORMAT.md +0 -46
- package/skills/teach/LICENSE +0 -21
- package/skills/teach/MISSION-FORMAT.md +0 -31
- package/skills/teach/RESOURCES-FORMAT.md +0 -32
- package/skills/teach/SKILL.md +0 -141
- package/skills/teach/agents/openai.yaml +0 -4
- package/skills/to-questionnaire/LICENSE +0 -21
- package/skills/to-questionnaire/SKILL.md +0 -55
- package/skills/to-questionnaire/agents/openai.yaml +0 -4
- package/skills/to-spec/LICENSE +0 -21
- package/skills/to-spec/SKILL.md +0 -76
- package/skills/to-spec/agents/openai.yaml +0 -4
- package/skills/to-tickets/LICENSE +0 -21
- package/skills/to-tickets/SKILL.md +0 -106
- package/skills/to-tickets/agents/openai.yaml +0 -4
- package/skills/wait-what/LICENSE +0 -21
- package/skills/wait-what/SKILL.md +0 -8
- package/skills/wait-what/agents/openai.yaml +0 -4
- package/skills/wayfinder/LICENSE +0 -21
- package/skills/wayfinder/SKILL.md +0 -129
- package/skills/wayfinder/agents/openai.yaml +0 -4
- package/skills/writing-for-agents/LICENSE +0 -21
- package/skills/writing-for-agents/SKILL-MECHANICS.md +0 -22
- package/skills/writing-for-agents/SKILL.md +0 -83
- package/skills/writing-for-agents/agents/openai.yaml +0 -3
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import { request } from 'node:http';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
import { text as textOf } from 'node:stream/consumers';
|
|
4
|
+
import { downloaded, fileInfo, fileRange, mediaTypeOf, opened, sentPart, storeRefusal, uploaded, } from './files.js';
|
|
5
|
+
import { DEFAULT_MAX_SIZE, UPLOAD_NEEDS_OWNER } from './copies.js';
|
|
6
|
+
import { ownerSocket } from './home.js';
|
|
7
|
+
import { fileDigest } from './manifest.js';
|
|
8
|
+
import { ownAgentCall, rpc, unconfirmed, UNREACHABLE } from './mcp.js';
|
|
9
|
+
import { refusalOf } from './refusals.js';
|
|
10
|
+
import { parse } from 'yaml';
|
|
11
|
+
const USAGE = "usage: house <tool> ['<arguments as JSON>'], or house <tool> - to read them from stdin; house help <tool>: its arguments";
|
|
12
|
+
const HELP = 'help [tool]';
|
|
13
|
+
const UPLOAD_USAGE = `usage: house upload [--owner], or house upload '{"file":"<local file>","path":"/rooms/<handle>/<path>"}', adding "base", the revision it replaces`;
|
|
14
|
+
const UPLOAD = "upload: in a Room's Local copy, sends every file changed, added or deleted there since it last matched House, each .md file as document text and every other file as an attachment, with --owner outside an Agent conversation; with JSON, sends one local file to the Room path it names";
|
|
15
|
+
const DOWNLOAD_USAGE = `usage: house download [--with-attachments] [--max-size <MB>], or house download '{"path":"/rooms/<handle>/<path>","file":"<local file>"}', adding "ref" for a revision`;
|
|
16
|
+
const DOWNLOAD = `download: brings House's changes into every Local copy, leaving each file changed here for the next house upload, and with --with-attachments each attachment it lacks up to --max-size megabytes, ${DEFAULT_MAX_SIZE} by default; with JSON, writes one attachment of a Room to the local file named by file`;
|
|
17
|
+
const MAX_SIZE = `--max-size takes a number of megabytes; ${DOWNLOAD_USAGE}`;
|
|
18
|
+
const MEGABYTES = /^\d+(?:\.\d+)?$/;
|
|
19
|
+
const ARGUMENTS = `the arguments are one JSON object, in single quotes or on stdin after -, like house search '{"query":"invoice"}'`;
|
|
20
|
+
const CLOSED = 'this 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 socketPath = process.env.HOUSE_BRIDGE;
|
|
24
|
+
const WAY = {
|
|
25
|
+
...(socketPath === undefined ? {} : { socketPath }),
|
|
26
|
+
unreached: (error) => new Error(socketPath === undefined ? UNREACHABLE : error.code === 'EPERM' || error.code === 'EACCES' ? SANDBOXED : CLOSED),
|
|
27
|
+
refused: (status) => storeRefusal('upload', status),
|
|
28
|
+
};
|
|
29
|
+
function refused(path, status, text, local) {
|
|
30
|
+
const refusal = refusalOf(text);
|
|
31
|
+
if (refusal !== null)
|
|
32
|
+
return refusal.text;
|
|
33
|
+
if (status === 401)
|
|
34
|
+
return REVOKED;
|
|
35
|
+
if (status === 502 && local)
|
|
36
|
+
return text;
|
|
37
|
+
return path === '/' ? unconfirmed(status) : `${path} answered ${status}`;
|
|
38
|
+
}
|
|
39
|
+
function bridged(path, body, to = socketPath) {
|
|
40
|
+
return new Promise((resolve, reject) => {
|
|
41
|
+
const sent = request({ socketPath: to, path, method: 'POST', headers: { 'content-type': 'application/json' } }, (answer) => {
|
|
42
|
+
const chunks = [];
|
|
43
|
+
answer.on('data', (chunk) => chunks.push(chunk));
|
|
44
|
+
answer.on('end', () => {
|
|
45
|
+
const text = Buffer.concat(chunks).toString('utf8');
|
|
46
|
+
if (answer.statusCode === 200)
|
|
47
|
+
resolve(text);
|
|
48
|
+
else
|
|
49
|
+
reject(new Error(refused(path, answer.statusCode, text, answer.headers['content-type'] === undefined)));
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
sent.on('error', (error) => reject(new Error(error.code === 'EPERM' || error.code === 'EACCES' ? SANDBOXED : CLOSED)));
|
|
53
|
+
sent.end(JSON.stringify(body));
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
async function mcp(method, params) {
|
|
57
|
+
const message = rpc(method, params);
|
|
58
|
+
const answer = JSON.parse(socketPath === undefined ? await ownAgentCall(message) : await bridged('/', message));
|
|
59
|
+
if (answer.error !== undefined)
|
|
60
|
+
throw new Error(answer.error.message);
|
|
61
|
+
return answer.result;
|
|
62
|
+
}
|
|
63
|
+
async function tools() {
|
|
64
|
+
return (await mcp('tools/list', {})).tools;
|
|
65
|
+
}
|
|
66
|
+
function unreadable(path, error) {
|
|
67
|
+
return new Error(error.code === 'EISDIR'
|
|
68
|
+
? `${path} is a folder; upload one file at a time`
|
|
69
|
+
: `${path} is not a readable file`);
|
|
70
|
+
}
|
|
71
|
+
async function download(args) {
|
|
72
|
+
const valued = args.indexOf('--max-size');
|
|
73
|
+
const size = valued === -1 ? undefined : args[valued + 1];
|
|
74
|
+
const rest = valued === -1 ? args : args.filter((_arg, index) => index !== valued && index !== valued + 1);
|
|
75
|
+
const { flags, positionals: [argument] } = accepted(rest, ['--help', '--with-attachments'], 1, DOWNLOAD_USAGE);
|
|
76
|
+
if (flags.has('--help'))
|
|
77
|
+
return `${DOWNLOAD_USAGE}\n${DOWNLOAD}`;
|
|
78
|
+
if (argument === undefined) {
|
|
79
|
+
if (valued !== -1 && !MEGABYTES.test(size ?? ''))
|
|
80
|
+
throw new Error(MAX_SIZE);
|
|
81
|
+
const maxSize = size === undefined ? DEFAULT_MAX_SIZE : Number(size);
|
|
82
|
+
return copyVerb('/copy/download', { attachments: flags.has('--with-attachments'), max_size: maxSize });
|
|
83
|
+
}
|
|
84
|
+
if (valued !== -1 || flags.has('--with-attachments'))
|
|
85
|
+
throw unexpected(valued !== -1 ? '--max-size' : '--with-attachments', DOWNLOAD_USAGE);
|
|
86
|
+
const { file, ...selected } = await argumentsOf(argument);
|
|
87
|
+
if (typeof file !== 'string' || file === '')
|
|
88
|
+
throw new Error('download needs "file", the local file to write');
|
|
89
|
+
const written = resolve(file);
|
|
90
|
+
await downloaded(async () => {
|
|
91
|
+
const file = fileInfo(await called('info', selected));
|
|
92
|
+
if (file === null)
|
|
93
|
+
throw new Error(`${String(selected.path)} holds no binary file; shell reads its text`);
|
|
94
|
+
return file;
|
|
95
|
+
}, async (url) => {
|
|
96
|
+
const answer = await opened(url, 'GET', {}, WAY);
|
|
97
|
+
return { status: answer.statusCode, body: answer };
|
|
98
|
+
}, written, String(selected.path));
|
|
99
|
+
return written;
|
|
100
|
+
}
|
|
101
|
+
async function described(file) {
|
|
102
|
+
let held;
|
|
103
|
+
try {
|
|
104
|
+
held = await fileDigest(file);
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
throw unreadable(file, error);
|
|
108
|
+
}
|
|
109
|
+
const mediaType = mediaTypeOf(file);
|
|
110
|
+
return { bytes: held.bytes, sha256: held.sha256, ...(mediaType === undefined ? {} : { media_type: mediaType }) };
|
|
111
|
+
}
|
|
112
|
+
async function finished(upload, path, partSha256) {
|
|
113
|
+
const text = await called('upload', { upload, path, part_sha256: partSha256 });
|
|
114
|
+
const answer = parse(text);
|
|
115
|
+
return answer !== null && 'upload' in answer ? answer : { text };
|
|
116
|
+
}
|
|
117
|
+
async function upload({ file, ...destination }) {
|
|
118
|
+
if (typeof file !== 'string' || file === '')
|
|
119
|
+
throw new Error('upload needs "file", a local file');
|
|
120
|
+
const description = await described(file);
|
|
121
|
+
const answer = await called('upload', { ...destination, ...description });
|
|
122
|
+
const declared = parse(answer);
|
|
123
|
+
if (declared?.upload === undefined)
|
|
124
|
+
return answer;
|
|
125
|
+
const accepted = await uploaded(declared.upload, {
|
|
126
|
+
name: file,
|
|
127
|
+
bytes: description.bytes,
|
|
128
|
+
sha256: description.sha256,
|
|
129
|
+
read: (start, end) => fileRange(file, start, end, (error) => unreadable(file, error)),
|
|
130
|
+
send: (url, start, end, headers) => sentPart(url, file, start, end, headers, WAY),
|
|
131
|
+
finish: (id, partSha256) => finished(id, destination.path, partSha256),
|
|
132
|
+
});
|
|
133
|
+
return accepted.text;
|
|
134
|
+
}
|
|
135
|
+
function unexpected(argument, usage) {
|
|
136
|
+
return new Error(`unexpected argument ${argument}; ${usage}`);
|
|
137
|
+
}
|
|
138
|
+
function accepted(args, flags, positionals, usage) {
|
|
139
|
+
const given = { flags: new Set(), positionals: [] };
|
|
140
|
+
for (const arg of args) {
|
|
141
|
+
if (flags.includes(arg))
|
|
142
|
+
given.flags.add(arg);
|
|
143
|
+
else if ((arg === '-' || !arg.startsWith('-')) && given.positionals.length < positionals)
|
|
144
|
+
given.positionals.push(arg);
|
|
145
|
+
else
|
|
146
|
+
throw unexpected(arg, usage);
|
|
147
|
+
}
|
|
148
|
+
return given;
|
|
149
|
+
}
|
|
150
|
+
async function copyVerb(path, body) {
|
|
151
|
+
const answer = JSON.parse(await bridged(path, body, socketPath ?? ownerSocket()));
|
|
152
|
+
if (answer.refused)
|
|
153
|
+
throw new Error(answer.text);
|
|
154
|
+
return answer.text;
|
|
155
|
+
}
|
|
156
|
+
async function uploadVerb(args) {
|
|
157
|
+
const { flags, positionals: [argument] } = accepted(args, ['--help', '--owner'], 1, UPLOAD_USAGE);
|
|
158
|
+
if (flags.has('--help'))
|
|
159
|
+
return `${UPLOAD_USAGE}\n${UPLOAD}`;
|
|
160
|
+
if (argument !== undefined) {
|
|
161
|
+
if (flags.has('--owner'))
|
|
162
|
+
throw unexpected('--owner', UPLOAD_USAGE);
|
|
163
|
+
return upload(await argumentsOf(argument));
|
|
164
|
+
}
|
|
165
|
+
const owner = flags.has('--owner');
|
|
166
|
+
if (!owner && socketPath === undefined)
|
|
167
|
+
throw new Error(UPLOAD_NEEDS_OWNER);
|
|
168
|
+
return copyVerb('/copy/upload', { cwd: process.cwd(), owner });
|
|
169
|
+
}
|
|
170
|
+
async function argumentsOf(argument) {
|
|
171
|
+
if (argument === undefined)
|
|
172
|
+
return {};
|
|
173
|
+
const given = argument === '-' ? await textOf(process.stdin) : argument;
|
|
174
|
+
let parsed;
|
|
175
|
+
try {
|
|
176
|
+
parsed = JSON.parse(given);
|
|
177
|
+
}
|
|
178
|
+
catch {
|
|
179
|
+
throw new Error(ARGUMENTS);
|
|
180
|
+
}
|
|
181
|
+
if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed))
|
|
182
|
+
throw new Error(ARGUMENTS);
|
|
183
|
+
return parsed;
|
|
184
|
+
}
|
|
185
|
+
// The schema a $ref points to inside the Tool's own inputSchema, or an empty one when it points elsewhere.
|
|
186
|
+
function resolved(schema, root) {
|
|
187
|
+
if (schema.$ref === undefined)
|
|
188
|
+
return schema;
|
|
189
|
+
if (!schema.$ref.startsWith('#'))
|
|
190
|
+
return {};
|
|
191
|
+
let found = root;
|
|
192
|
+
for (const key of schema.$ref.split('/').slice(1)) {
|
|
193
|
+
found = typeof found === 'object' && found !== null ? found[key.replaceAll('~1', '/').replaceAll('~0', '~')] : undefined;
|
|
194
|
+
}
|
|
195
|
+
return typeof found === 'object' && found !== null ? found : {};
|
|
196
|
+
}
|
|
197
|
+
// The schema a $ref resolves to, with that $ref added to the open ones, or null when it is open already,
|
|
198
|
+
// so a schema that holds itself is expanded once.
|
|
199
|
+
function expanded(schema, root, refs) {
|
|
200
|
+
if (schema.$ref === undefined)
|
|
201
|
+
return { schema, refs };
|
|
202
|
+
return refs.has(schema.$ref) ? null : { schema: resolved(schema, root), refs: new Set([...refs, schema.$ref]) };
|
|
203
|
+
}
|
|
204
|
+
// One line per argument: its name, its value when it has one or a few, whether it is required, and its
|
|
205
|
+
// description. When deep, the arguments its value holds follow it.
|
|
206
|
+
function argumentLines(schema, root, indent, deep, refs = new Set()) {
|
|
207
|
+
const required = new Set(schema.required ?? []);
|
|
208
|
+
return Object.entries(schema.properties ?? {}).flatMap(([name, property]) => {
|
|
209
|
+
const value = resolved(property, root);
|
|
210
|
+
const values = value.const !== undefined ? [value.const] : (value.enum ?? []);
|
|
211
|
+
const words = [name, ...(values.length === 0 ? [] : [values.map((one) => JSON.stringify(one)).join(' | ')]), ...(required.has(name) ? ['(required)'] : [])];
|
|
212
|
+
const description = property.description ?? value.description;
|
|
213
|
+
const line = `${indent}${words.join(' ')}${description === undefined ? '' : `: ${description}`}`;
|
|
214
|
+
return deep ? [line, ...held(property, root, `${indent} `, refs)] : [line];
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
// The arguments a value holds: its own, its items', and those of each alternative of a oneOf or anyOf,
|
|
218
|
+
// each alternative a "- " entry when more than one has arguments.
|
|
219
|
+
function held(schema, root, indent, refs) {
|
|
220
|
+
const value = expanded(schema, root, refs);
|
|
221
|
+
if (value === null)
|
|
222
|
+
return [];
|
|
223
|
+
const alternatives = (value.schema.oneOf ?? value.schema.anyOf ?? [])
|
|
224
|
+
.map((alternative) => held(alternative, root, indent, value.refs))
|
|
225
|
+
.filter((lines) => lines.length > 0);
|
|
226
|
+
return [
|
|
227
|
+
...argumentLines(value.schema, root, indent, true, value.refs),
|
|
228
|
+
...(value.schema.items === undefined ? [] : held(value.schema.items, root, indent, value.refs)),
|
|
229
|
+
...(alternatives.length === 1
|
|
230
|
+
? alternatives[0]
|
|
231
|
+
: alternatives.flatMap((lines) => lines.map((line, index) => (index === 0 ? `${indent}- ${line.slice(indent.length)}` : ` ${line}`)))),
|
|
232
|
+
];
|
|
233
|
+
}
|
|
234
|
+
function listed(tool) {
|
|
235
|
+
return tool.description === undefined ? tool.name : `${tool.name}: ${tool.description}`;
|
|
236
|
+
}
|
|
237
|
+
async function toolHelp(name) {
|
|
238
|
+
const tool = (await tools()).find((one) => one.name === name);
|
|
239
|
+
if (tool === undefined)
|
|
240
|
+
throw new Error(`${name} is no Tool; house find_command '{"query":"${name}"}' finds Commands`);
|
|
241
|
+
return [listed(tool), ...argumentLines(tool.inputSchema, tool.inputSchema, ' ', true)].join('\n');
|
|
242
|
+
}
|
|
243
|
+
async function house(args) {
|
|
244
|
+
const { flags, positionals: [verb, argument] } = accepted(args, ['--help'], 2, USAGE);
|
|
245
|
+
if (flags.has('--help') && argument !== undefined)
|
|
246
|
+
throw unexpected('--help', USAGE);
|
|
247
|
+
// house help <name> runs as house <name> --help, so both forms answer alike.
|
|
248
|
+
if (verb === 'help' && argument !== undefined)
|
|
249
|
+
return run([argument, '--help']);
|
|
250
|
+
if (verb === undefined || verb === 'help') {
|
|
251
|
+
const listing = (await tools()).flatMap((tool) => tool.description === undefined ? [tool.name, ...argumentLines(tool.inputSchema, tool.inputSchema, ' ', false)] : [listed(tool)]);
|
|
252
|
+
return [USAGE, HELP, UPLOAD, DOWNLOAD, ...listing].join('\n');
|
|
253
|
+
}
|
|
254
|
+
if (flags.has('--help'))
|
|
255
|
+
return toolHelp(verb);
|
|
256
|
+
return called(verb, await argumentsOf(argument));
|
|
257
|
+
}
|
|
258
|
+
async function called(name, args) {
|
|
259
|
+
const result = await mcp('tools/call', { name, arguments: args });
|
|
260
|
+
const text = result.content.map((content) => content.text).join('\n');
|
|
261
|
+
if (result.isError === true)
|
|
262
|
+
throw new Error(text.replace(/\n+$/, ''));
|
|
263
|
+
return text;
|
|
264
|
+
}
|
|
265
|
+
function run(argv) {
|
|
266
|
+
const named = argv.findIndex((arg) => !arg.startsWith('-'));
|
|
267
|
+
const rest = argv.filter((_arg, index) => index !== named);
|
|
268
|
+
if (argv[named] === 'upload')
|
|
269
|
+
return uploadVerb(rest);
|
|
270
|
+
if (argv[named] === 'download')
|
|
271
|
+
return download(rest);
|
|
272
|
+
return house(argv);
|
|
273
|
+
}
|
|
274
|
+
const argv = process.argv.slice(2);
|
|
275
|
+
run(argv).then((text) => {
|
|
276
|
+
process.stdout.write(`${text}\n`);
|
|
277
|
+
if (argv[0] === 'shell')
|
|
278
|
+
process.exitCode = Number(/^exit: (\d+)(?:\n|$)/.exec(text)?.[1] ?? 0);
|
|
279
|
+
}, (error) => {
|
|
280
|
+
process.stderr.write(`house: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
281
|
+
process.exitCode = 1;
|
|
282
|
+
});
|
package/dist/house-main.js
CHANGED
|
@@ -1,209 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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, 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;
|
|
193
6
|
}
|
|
194
|
-
|
|
195
|
-
|
|
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
|
-
|
|
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 {};
|
package/dist/instructions.js
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
const SOURCE_LINE = "From House:";
|
|
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
|
-
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
|
-
const READ_LINE = "Optional per-Room instructions: `/rooms/private/rooms/<handle>/AGENTS.md`.";
|
|
7
|
-
const COPIES_LINE = `House Local copies; before work run \`house fetch\` and rebase onto \`${HOUSE_REF}\`; after it commit, then \`house push\`:`;
|
|
1
|
+
import { agentInstructions } from '@agentshouse/skills';
|
|
2
|
+
const OWNER_RULES = '/rooms/private/owner-rules.md';
|
|
8
3
|
const UNREADABLE = /^(?:\S+: )?(?:path_not_found|room_not_found|operation_denied)\b/;
|
|
9
4
|
const FAILED = /^exit: [1-9]\d*$/;
|
|
10
5
|
const CUT = /^stderr: shell: output_cut (\d+) of \d+ bytes; continue with: (.+)$/;
|
|
@@ -12,9 +7,9 @@ function cutOf(lines) {
|
|
|
12
7
|
const cut = CUT.exec(lines[0] ?? '');
|
|
13
8
|
return cut !== null && Buffer.byteLength(lines.slice(1).join('\n')) === Number(cut[1]) ? cut : null;
|
|
14
9
|
}
|
|
15
|
-
async function
|
|
10
|
+
async function readOwnerRules(bridge) {
|
|
16
11
|
let document = '';
|
|
17
|
-
for (let command = `cat ${
|
|
12
|
+
for (let command = `cat ${OWNER_RULES}`; command !== undefined;) {
|
|
18
13
|
const read = await bridge.tool('shell', { command });
|
|
19
14
|
const text = read.content.map((content) => content.text).join('\n');
|
|
20
15
|
const lines = text.split('\n');
|
|
@@ -28,9 +23,8 @@ async function howWeWork(bridge) {
|
|
|
28
23
|
document += lines.slice(cut === null ? 0 : 1).join('\n');
|
|
29
24
|
command = cut?.[2];
|
|
30
25
|
}
|
|
31
|
-
return document
|
|
26
|
+
return document;
|
|
32
27
|
}
|
|
33
|
-
export async function instructions(bridge, base
|
|
34
|
-
|
|
35
|
-
return [lines.join('\n'), base, await howWeWork(bridge)].filter((part) => part !== '').join('\n\n');
|
|
28
|
+
export async function instructions(bridge, base) {
|
|
29
|
+
return [agentInstructions().join('\n'), base, (await readOwnerRules(bridge)).replace(/\n$/, '')].filter((part) => part !== '').join('\n\n');
|
|
36
30
|
}
|