@agentshouse/kit 0.2.1-c3e4a20bb3183 → 0.2.1-c3fc787e93f0e
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 +36 -36
- package/dist/acp.js +16 -93
- package/dist/agents.js +103 -42
- package/dist/api.js +36 -3
- package/dist/app-git.js +64 -0
- package/dist/bootstrap.json +10 -17
- package/dist/bridge.js +36 -52
- package/dist/chatgpt.js +26 -0
- package/dist/clis.js +127 -65
- package/dist/codex-main.js +58 -0
- package/dist/conversations.js +288 -236
- package/dist/copies.js +172 -144
- package/dist/end.js +22 -0
- package/dist/enrol-main.js +7 -1
- package/dist/events.js +521 -0
- package/dist/files.js +23 -2
- package/dist/git.js +11 -8
- package/dist/home.js +90 -6
- package/dist/house-main.js +165 -63
- package/dist/instructions.js +7 -5
- package/dist/kit-main.js +55 -4
- package/dist/login.js +96 -106
- package/dist/logout.js +21 -0
- package/dist/mcp.js +2 -1
- package/dist/parts.js +82 -0
- package/dist/placement.js +48 -0
- package/dist/refusals.js +12 -0
- package/dist/relay.js +20 -0
- package/dist/resident.js +62 -32
- package/dist/scope.js +203 -0
- package/dist/secret-input.js +4 -1
- package/dist/service-main.js +9 -0
- package/dist/service.js +33 -0
- package/dist/shell.js +3 -0
- package/dist/sign-in.js +34 -9
- package/dist/skills.js +12 -2
- package/dist/stream.js +37 -6
- package/dist/transcription.js +54 -6
- package/dist/update.js +30 -6
- package/dist/wire.js +6 -0
- package/dist/work.js +348 -0
- package/package.json +2 -2
- package/dist/blocks.js +0 -51
package/dist/home.js
CHANGED
|
@@ -1,11 +1,48 @@
|
|
|
1
|
+
import { accessSync, chmodSync, constants, existsSync, linkSync, lstatSync, mkdirSync, readFileSync, renameSync, rmSync } from 'node:fs';
|
|
1
2
|
import { mkdir, readFile, rename, rm, writeFile } from 'node:fs/promises';
|
|
2
|
-
import { homedir } from 'node:os';
|
|
3
|
+
import { homedir, tmpdir } from 'node:os';
|
|
3
4
|
import { join } from 'node:path';
|
|
5
|
+
import { selectRelay } from './relay.js';
|
|
4
6
|
const ENROLMENT = 'credential.json';
|
|
7
|
+
const DISCONNECTED = 'disconnected.json';
|
|
5
8
|
const CONFIGURATION = 'kit.json';
|
|
6
9
|
const OWN_AGENT = 'own-agent.json';
|
|
10
|
+
const RESTART = 'restart';
|
|
11
|
+
let defaulted;
|
|
12
|
+
function writable(directory) {
|
|
13
|
+
try {
|
|
14
|
+
accessSync(directory, constants.W_OK | constants.X_OK);
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function ownTemporaryHome() {
|
|
22
|
+
const home = join(tmpdir(), `house-kit-${process.getuid()}`);
|
|
23
|
+
try {
|
|
24
|
+
mkdirSync(home, { mode: 0o700 });
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
if (error.code !== 'EEXIST')
|
|
28
|
+
throw error;
|
|
29
|
+
}
|
|
30
|
+
const found = lstatSync(home);
|
|
31
|
+
if (found.isSymbolicLink())
|
|
32
|
+
throw new Error(`${home} is a symbolic link`);
|
|
33
|
+
if (!found.isDirectory())
|
|
34
|
+
throw new Error(`${home} is not a directory`);
|
|
35
|
+
if (found.uid !== process.getuid())
|
|
36
|
+
throw new Error(`${home} is not owned by this User`);
|
|
37
|
+
chmodSync(home, 0o700);
|
|
38
|
+
return home;
|
|
39
|
+
}
|
|
40
|
+
function defaultHome() {
|
|
41
|
+
const home = join(homedir(), '.house-kit');
|
|
42
|
+
return existsSync(home) || writable(homedir()) ? home : ownTemporaryHome();
|
|
43
|
+
}
|
|
7
44
|
export function kitHome() {
|
|
8
|
-
return process.env.HOUSE_KIT_HOME
|
|
45
|
+
return process.env.HOUSE_KIT_HOME || (defaulted ??= defaultHome());
|
|
9
46
|
}
|
|
10
47
|
export function workspaceRoot() {
|
|
11
48
|
return process.env.HOUSE_KIT_WORKSPACE ?? '/agents/house';
|
|
@@ -30,11 +67,58 @@ export async function writeHome(name, value) {
|
|
|
30
67
|
await writeFile(temporary, `${JSON.stringify(value)}\n`, { mode: 0o600 });
|
|
31
68
|
await rename(temporary, join(home, name));
|
|
32
69
|
}
|
|
33
|
-
export function readEnrolment() {
|
|
34
|
-
|
|
70
|
+
export async function readEnrolment() {
|
|
71
|
+
const enrolment = await readHome(ENROLMENT);
|
|
72
|
+
if (enrolment !== null)
|
|
73
|
+
selectRelay(process.env.HOUSE_KIT_RELAY || enrolment.relay);
|
|
74
|
+
return enrolment;
|
|
75
|
+
}
|
|
76
|
+
export async function writeEnrolment(enrolment) {
|
|
77
|
+
await writeHome(ENROLMENT, enrolment);
|
|
78
|
+
await rm(join(kitHome(), DISCONNECTED), { force: true });
|
|
79
|
+
}
|
|
80
|
+
export function readDisconnected() {
|
|
81
|
+
return readHome(DISCONNECTED);
|
|
82
|
+
}
|
|
83
|
+
export async function forgetEnrolment({ house, environment }) {
|
|
84
|
+
await writeHome(DISCONNECTED, { house, environment });
|
|
85
|
+
await rm(join(kitHome(), ENROLMENT), { force: true });
|
|
86
|
+
}
|
|
87
|
+
export async function forgetRejected(rejected) {
|
|
88
|
+
const held = await readHome(ENROLMENT);
|
|
89
|
+
if (held?.credential !== rejected)
|
|
90
|
+
return;
|
|
91
|
+
await writeHome(DISCONNECTED, { house: held.house, environment: held.environment });
|
|
92
|
+
const enrolment = join(kitHome(), ENROLMENT);
|
|
93
|
+
const taken = `${enrolment}.${process.pid}`;
|
|
94
|
+
try {
|
|
95
|
+
renameSync(enrolment, taken);
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
if (error.code === 'ENOENT')
|
|
99
|
+
return;
|
|
100
|
+
throw error;
|
|
101
|
+
}
|
|
102
|
+
if (JSON.parse(readFileSync(taken, 'utf8')).credential !== rejected) {
|
|
103
|
+
try {
|
|
104
|
+
linkSync(taken, enrolment);
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
if (error.code !== 'EEXIST')
|
|
108
|
+
throw error;
|
|
109
|
+
}
|
|
110
|
+
rmSync(join(kitHome(), DISCONNECTED), { force: true });
|
|
111
|
+
}
|
|
112
|
+
rmSync(taken);
|
|
113
|
+
}
|
|
114
|
+
export function enrolled() {
|
|
115
|
+
return existsSync(join(kitHome(), ENROLMENT));
|
|
116
|
+
}
|
|
117
|
+
export function restartAsked() {
|
|
118
|
+
return existsSync(join(kitHome(), RESTART));
|
|
35
119
|
}
|
|
36
|
-
export function
|
|
37
|
-
return
|
|
120
|
+
export function forgetRestart() {
|
|
121
|
+
return rm(join(kitHome(), RESTART), { force: true });
|
|
38
122
|
}
|
|
39
123
|
export function readOwnAgent() {
|
|
40
124
|
return readHome(OWN_AGENT);
|
package/dist/house-main.js
CHANGED
|
@@ -1,61 +1,105 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { createHash } from 'node:crypto';
|
|
3
|
-
import { readFile } from 'node:fs/promises';
|
|
3
|
+
import { mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
4
4
|
import { request, setGlobalProxyFromEnv } from 'node:http';
|
|
5
|
-
import {
|
|
5
|
+
import { dirname, extname, join, resolve } from 'node:path';
|
|
6
|
+
import { verified } from './files.js';
|
|
7
|
+
import { HOUSE_REF } from './git.js';
|
|
6
8
|
import { kitHome, readOwnAgent } from './home.js';
|
|
7
9
|
import { callHouse, rpc, UNREACHABLE } from './mcp.js';
|
|
8
10
|
import { refusalOf } from './refusals.js';
|
|
11
|
+
import { relayed, selectRelay } from './relay.js';
|
|
12
|
+
import { parse, stringify } from 'yaml';
|
|
9
13
|
const USAGE = "usage: house <tool> ['<arguments as JSON>']";
|
|
10
|
-
const
|
|
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';
|
|
11
20
|
const ARGUMENTS = `the arguments are one JSON object in single quotes, like house search '{"query":"invoice"}'`;
|
|
12
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";
|
|
13
23
|
const REVOKED = 'this conversation no longer has House access; nothing to do from here';
|
|
14
24
|
const UNCONNECTED = "this computer's own agent has no House connection; run kit login";
|
|
15
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';
|
|
16
27
|
const socketPath = process.env.HOUSE_BRIDGE;
|
|
17
|
-
|
|
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) {
|
|
18
56
|
const refusal = refusalOf(text);
|
|
19
57
|
if (refusal !== null)
|
|
20
58
|
return refusal.text;
|
|
21
59
|
if (status === 401)
|
|
22
60
|
return REVOKED;
|
|
61
|
+
const act = method === 'GET' ? 'download' : 'upload';
|
|
23
62
|
if (URL.canParse(path))
|
|
24
|
-
return `the
|
|
25
|
-
if (status === 502 &&
|
|
63
|
+
return `the ${act} answered ${status}; ${act} the file again`;
|
|
64
|
+
if (status === 502 && local)
|
|
26
65
|
return text;
|
|
27
|
-
return `${path} answered ${status}`;
|
|
66
|
+
return path === '/' ? unconfirmed(status) : `${path} answered ${status}`;
|
|
28
67
|
}
|
|
29
|
-
function
|
|
68
|
+
function unconfirmed(status) {
|
|
69
|
+
return `House answered ${status} ${UNCONFIRMED}`;
|
|
70
|
+
}
|
|
71
|
+
function exchanged(path, method, body, headers = { 'content-type': 'application/json' }, to = socketPath) {
|
|
30
72
|
return new Promise((resolve, reject) => {
|
|
31
|
-
const sent = request({ socketPath: to, path, method
|
|
32
|
-
|
|
33
|
-
answer.
|
|
34
|
-
answer.on('data', (chunk) => {
|
|
35
|
-
text += chunk;
|
|
36
|
-
});
|
|
73
|
+
const sent = request({ socketPath: to, path, method, headers }, (answer) => {
|
|
74
|
+
const chunks = [];
|
|
75
|
+
answer.on('data', (chunk) => chunks.push(chunk));
|
|
37
76
|
answer.on('end', () => {
|
|
77
|
+
const bytes = Buffer.concat(chunks);
|
|
38
78
|
if (answer.statusCode === 200)
|
|
39
|
-
resolve(
|
|
79
|
+
resolve(bytes);
|
|
40
80
|
else
|
|
41
|
-
reject(new Error(refused(path, answer.statusCode,
|
|
81
|
+
reject(new Error(refused(path, method, answer.statusCode, bytes.toString('utf8'), answer.headers['content-type'] === undefined)));
|
|
42
82
|
});
|
|
43
83
|
});
|
|
44
|
-
sent.on('error', () => reject(new Error(CLOSED)));
|
|
45
|
-
sent.end(body instanceof Buffer ? body : JSON.stringify(body));
|
|
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));
|
|
46
86
|
});
|
|
47
87
|
}
|
|
88
|
+
async function bridged(path, body, headers, to = socketPath) {
|
|
89
|
+
return (await exchanged(path, 'POST', body, headers, to)).toString('utf8');
|
|
90
|
+
}
|
|
48
91
|
async function direct(message) {
|
|
49
92
|
const ownAgent = await readOwnAgent();
|
|
50
93
|
if (ownAgent === null)
|
|
51
94
|
throw new Error(UNCONNECTED);
|
|
95
|
+
selectRelay(process.env.HOUSE_KIT_RELAY || ownAgent.relay);
|
|
52
96
|
setGlobalProxyFromEnv();
|
|
53
97
|
const answer = await callHouse(ownAgent.house, ownAgent.credential, message).catch(() => {
|
|
54
98
|
throw new Error(UNREACHABLE);
|
|
55
99
|
});
|
|
56
100
|
if (answer.status === 200)
|
|
57
101
|
return answer.text;
|
|
58
|
-
throw new Error(answer.status === 401 ? DISCONNECTED : (refusalOf(answer.text)?.text ??
|
|
102
|
+
throw new Error(answer.status === 401 ? DISCONNECTED : (refusalOf(answer.text)?.text ?? unconfirmed(answer.status)));
|
|
59
103
|
}
|
|
60
104
|
async function mcp(method, params) {
|
|
61
105
|
const message = rpc(method, params);
|
|
@@ -77,42 +121,92 @@ async function localFile(path) {
|
|
|
77
121
|
: `${path} is not a readable file`);
|
|
78
122
|
}
|
|
79
123
|
}
|
|
80
|
-
async function
|
|
81
|
-
if (
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
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,
|
|
87
163
|
bytes: bytes.length,
|
|
88
164
|
sha256: createHash('sha256').update(bytes).digest('hex'),
|
|
89
|
-
|
|
165
|
+
...(mediaType === undefined ? {} : { media_type: mediaType }),
|
|
166
|
+
});
|
|
167
|
+
const declared = parse(answer);
|
|
90
168
|
if (declared.upload === undefined)
|
|
91
|
-
return
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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');
|
|
107
193
|
if (owner && socketPath !== undefined)
|
|
108
|
-
throw new Error('--owner is not for Agent conversations; run house
|
|
194
|
+
throw new Error('--owner is not for Agent conversations; run house push without it');
|
|
109
195
|
if (!owner && socketPath === undefined)
|
|
110
|
-
throw new Error('outside an Agent conversation, house
|
|
196
|
+
throw new Error('outside an Agent conversation, house push needs --owner');
|
|
111
197
|
const pushed = JSON.parse(await bridged('/git/push', { cwd: process.cwd(), commit }, undefined, owner ? join(kitHome(), 'owner.sock') : socketPath));
|
|
112
198
|
if (pushed.refused)
|
|
113
199
|
throw new Error(pushed.text);
|
|
114
200
|
return pushed.text;
|
|
115
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
|
+
}
|
|
116
210
|
function argumentsOf(argument) {
|
|
117
211
|
if (argument === undefined)
|
|
118
212
|
return {};
|
|
@@ -127,36 +221,44 @@ function argumentsOf(argument) {
|
|
|
127
221
|
throw new Error(ARGUMENTS);
|
|
128
222
|
return parsed;
|
|
129
223
|
}
|
|
130
|
-
async function house(
|
|
131
|
-
|
|
132
|
-
|
|
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');
|
|
133
232
|
}
|
|
134
|
-
if (
|
|
233
|
+
if (flags.has('--help')) {
|
|
135
234
|
const tool = (await tools()).find((listed) => listed.name === verb);
|
|
136
235
|
if (tool === undefined)
|
|
137
236
|
throw new Error(`${verb} is no Tool; house find_command '{"query":"${verb}"}' finds Commands`);
|
|
138
|
-
return
|
|
139
|
-
}
|
|
140
|
-
const args = argumentsOf(argument);
|
|
141
|
-
if (socketPath !== undefined && verb === 'upload_attachment') {
|
|
142
|
-
return JSON.stringify({ attachment: await upload(args.path, args.room_ref, 'upload_attachment needs "path", a local file') });
|
|
237
|
+
return [...(tool.description === undefined ? [] : [tool.description]), JSON.stringify(tool.inputSchema)].join('\n');
|
|
143
238
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
args.attachments = attachments;
|
|
150
|
-
}
|
|
151
|
-
const result = await mcp('tools/call', { name: verb, arguments: args });
|
|
239
|
+
const parsed = argumentsOf(argument);
|
|
240
|
+
return verb === 'upload' ? upload(parsed) : called(verb, parsed);
|
|
241
|
+
}
|
|
242
|
+
async function called(name, args) {
|
|
243
|
+
const result = await mcp('tools/call', { name, arguments: args });
|
|
152
244
|
const text = result.content.map((content) => content.text).join('\n');
|
|
153
245
|
if (result.isError === true)
|
|
154
246
|
throw new Error(text.replace(/\n+$/, ''));
|
|
155
247
|
return text;
|
|
156
248
|
}
|
|
157
249
|
const argv = process.argv.slice(2);
|
|
158
|
-
|
|
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) => {
|
|
159
259
|
process.stdout.write(`${text}\n`);
|
|
260
|
+
if (argv[0] === 'shell')
|
|
261
|
+
process.exitCode = Number(/^exit: (\d+)(?:\n|$)/.exec(text)?.[1] ?? 0);
|
|
160
262
|
}, (error) => {
|
|
161
263
|
process.stderr.write(`house: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
162
264
|
process.exitCode = 1;
|
package/dist/instructions.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { HOUSE_REF } from './git.js';
|
|
1
2
|
import { HOW_WE_WORK } from './skills.js';
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
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\`:`;
|
|
6
8
|
const UNREADABLE = /^(?:\S+: )?(?:path_not_found|room_not_found|operation_denied)\b/;
|
|
7
9
|
const FAILED = /^exit: [1-9]\d*$/;
|
|
8
10
|
const CUT = /^stderr: shell: output_cut (\d+) of \d+ bytes; continue with: (.+)$/;
|
|
@@ -29,6 +31,6 @@ async function howWeWork(bridge) {
|
|
|
29
31
|
return document.replace(/\n$/, '');
|
|
30
32
|
}
|
|
31
33
|
export async function instructions(bridge, base, copies) {
|
|
32
|
-
const lines = [HOUSE_LINE, FILE_LINE, READ_LINE, ...(copies.length === 0 ? [] : [COPIES_LINE, ...copies])];
|
|
34
|
+
const lines = [SOURCE_LINE, HOUSE_LINE, FILE_LINE, READ_LINE, ...(copies.length === 0 ? [] : [COPIES_LINE, ...copies])];
|
|
33
35
|
return [lines.join('\n'), base, await howWeWork(bridge)].filter((part) => part !== '').join('\n\n');
|
|
34
36
|
}
|
package/dist/kit-main.js
CHANGED
|
@@ -1,16 +1,67 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { setGlobalProxyFromEnv } from 'node:http';
|
|
3
|
+
import { parseArgs } from 'node:util';
|
|
4
|
+
import { answerGitCredential } from './app-git.js';
|
|
5
|
+
import { chatgpt } from './chatgpt.js';
|
|
3
6
|
import { login } from './login.js';
|
|
7
|
+
import { logout } from './logout.js';
|
|
4
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
|
+
]);
|
|
5
39
|
const [command, ...argv] = process.argv.slice(2);
|
|
6
40
|
setGlobalProxyFromEnv();
|
|
7
41
|
async function run() {
|
|
8
42
|
if (command === 'login')
|
|
9
43
|
return login(argv);
|
|
10
|
-
if (command === '
|
|
11
|
-
return
|
|
12
|
-
|
|
13
|
-
|
|
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);
|
|
14
65
|
}
|
|
15
66
|
run().catch((error) => {
|
|
16
67
|
process.stderr.write(`kit: ${error instanceof Error ? error.message : String(error)}\n`);
|