@agentshouse/kit 0.2.1-c3e4a20bb3183 → 0.2.1-c3e86aacccc80
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 +82 -40
- package/dist/api.js +32 -3
- package/dist/app-git.js +64 -0
- package/dist/bootstrap.json +10 -17
- package/dist/bridge.js +36 -52
- package/dist/clis.js +95 -65
- package/dist/codex-main.js +58 -0
- package/dist/conversations.js +287 -236
- package/dist/copies.js +154 -136
- package/dist/end.js +18 -0
- package/dist/enrol-main.js +7 -1
- package/dist/events.js +521 -0
- package/dist/files.js +16 -1
- package/dist/home.js +55 -4
- package/dist/house-main.js +88 -42
- package/dist/instructions.js +7 -5
- package/dist/kit-main.js +7 -1
- package/dist/login.js +92 -104
- package/dist/logout.js +21 -0
- package/dist/mcp.js +2 -1
- package/dist/parts.js +82 -0
- package/dist/refusals.js +12 -0
- package/dist/relay.js +20 -0
- package/dist/resident.js +54 -28
- 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 +1 -1
- package/dist/stream.js +33 -5
- package/dist/transcription.js +54 -6
- package/dist/update.js +2 -0
- package/dist/work.js +348 -0
- package/package.json +2 -2
- package/dist/blocks.js +0 -51
package/dist/house-main.js
CHANGED
|
@@ -2,18 +2,52 @@
|
|
|
2
2
|
import { createHash } from 'node:crypto';
|
|
3
3
|
import { readFile } from 'node:fs/promises';
|
|
4
4
|
import { request, setGlobalProxyFromEnv } from 'node:http';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { extname, join } from 'node:path';
|
|
6
|
+
import { HOUSE_REF } from './git.js';
|
|
7
|
+
import { kitHome, readEnrolment, readOwnAgent } from './home.js';
|
|
7
8
|
import { callHouse, rpc, UNREACHABLE } from './mcp.js';
|
|
8
9
|
import { refusalOf } from './refusals.js';
|
|
10
|
+
import { relayed } from './relay.js';
|
|
11
|
+
import { parse, stringify } from 'yaml';
|
|
9
12
|
const USAGE = "usage: house <tool> ['<arguments as JSON>']";
|
|
10
|
-
const
|
|
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}`;
|
|
11
17
|
const ARGUMENTS = `the arguments are one JSON object in single quotes, like house search '{"query":"invoice"}'`;
|
|
12
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";
|
|
13
20
|
const REVOKED = 'this conversation no longer has House access; nothing to do from here';
|
|
14
21
|
const UNCONNECTED = "this computer's own agent has no House connection; run kit login";
|
|
15
22
|
const DISCONNECTED = "House no longer accepts this computer's own agent; run kit login";
|
|
16
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
|
+
]);
|
|
17
51
|
function refused(path, status, text) {
|
|
18
52
|
const refusal = refusalOf(text);
|
|
19
53
|
if (refusal !== null)
|
|
@@ -41,7 +75,7 @@ function bridged(path, body, headers = { 'content-type': 'application/json' }, t
|
|
|
41
75
|
reject(new Error(refused(path, answer.statusCode, text)));
|
|
42
76
|
});
|
|
43
77
|
});
|
|
44
|
-
sent.on('error', () => reject(new Error(CLOSED)));
|
|
78
|
+
sent.on('error', (error) => reject(new Error(error.code === 'EPERM' || error.code === 'EACCES' ? SANDBOXED : CLOSED)));
|
|
45
79
|
sent.end(body instanceof Buffer ? body : JSON.stringify(body));
|
|
46
80
|
});
|
|
47
81
|
}
|
|
@@ -49,6 +83,7 @@ async function direct(message) {
|
|
|
49
83
|
const ownAgent = await readOwnAgent();
|
|
50
84
|
if (ownAgent === null)
|
|
51
85
|
throw new Error(UNCONNECTED);
|
|
86
|
+
await readEnrolment();
|
|
52
87
|
setGlobalProxyFromEnv();
|
|
53
88
|
const answer = await callHouse(ownAgent.house, ownAgent.credential, message).catch(() => {
|
|
54
89
|
throw new Error(UNREACHABLE);
|
|
@@ -77,42 +112,58 @@ async function localFile(path) {
|
|
|
77
112
|
: `${path} is not a readable file`);
|
|
78
113
|
}
|
|
79
114
|
}
|
|
80
|
-
async function
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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,
|
|
87
135
|
bytes: bytes.length,
|
|
88
136
|
sha256: createHash('sha256').update(bytes).digest('hex'),
|
|
89
|
-
|
|
137
|
+
...(mediaType === undefined ? {} : { media_type: mediaType }),
|
|
138
|
+
});
|
|
139
|
+
const declared = parse(answer);
|
|
90
140
|
if (declared.upload === undefined)
|
|
91
|
-
return
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
'x-house-byte-operation': declared.upload.operation,
|
|
95
|
-
}));
|
|
96
|
-
if (saved.upload_failure !== undefined)
|
|
97
|
-
throw new Error(`${path} was not saved: ${saved.upload_failure}; call again later`);
|
|
98
|
-
return saved.attachment;
|
|
141
|
+
return answer;
|
|
142
|
+
const written = JSON.parse(await sent(declared.upload.url, bytes, declared.upload.operation));
|
|
143
|
+
return stringify(written, { lineWidth: 0 }).trimEnd();
|
|
99
144
|
}
|
|
100
|
-
async function
|
|
145
|
+
async function push(args) {
|
|
101
146
|
if (args.includes('--help'))
|
|
102
|
-
return
|
|
103
|
-
if (args[0] !== 'push')
|
|
104
|
-
throw new Error('only house git push [commit] exists; use plain git for the rest');
|
|
147
|
+
return PUSH_USAGE;
|
|
105
148
|
const owner = args.includes('--owner');
|
|
106
|
-
const commit = args.
|
|
149
|
+
const commit = args.find((arg) => arg !== '--owner') ?? 'HEAD';
|
|
107
150
|
if (owner && socketPath !== undefined)
|
|
108
|
-
throw new Error('--owner is not for Agent conversations; run house
|
|
151
|
+
throw new Error('--owner is not for Agent conversations; run house push without it');
|
|
109
152
|
if (!owner && socketPath === undefined)
|
|
110
|
-
throw new Error('outside an Agent conversation, house
|
|
153
|
+
throw new Error('outside an Agent conversation, house push needs --owner');
|
|
111
154
|
const pushed = JSON.parse(await bridged('/git/push', { cwd: process.cwd(), commit }, undefined, owner ? join(kitHome(), 'owner.sock') : socketPath));
|
|
112
155
|
if (pushed.refused)
|
|
113
156
|
throw new Error(pushed.text);
|
|
114
157
|
return pushed.text;
|
|
115
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
|
+
}
|
|
116
167
|
function argumentsOf(argument) {
|
|
117
168
|
if (argument === undefined)
|
|
118
169
|
return {};
|
|
@@ -128,35 +179,30 @@ function argumentsOf(argument) {
|
|
|
128
179
|
return parsed;
|
|
129
180
|
}
|
|
130
181
|
async function house([verb, argument]) {
|
|
131
|
-
if (verb === undefined || verb === '--help') {
|
|
132
|
-
return [USAGE, '
|
|
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');
|
|
133
184
|
}
|
|
134
185
|
if (argument === '--help') {
|
|
135
186
|
const tool = (await tools()).find((listed) => listed.name === verb);
|
|
136
187
|
if (tool === undefined)
|
|
137
188
|
throw new Error(`${verb} is no Tool; house find_command '{"query":"${verb}"}' finds Commands`);
|
|
138
|
-
return
|
|
189
|
+
return [...(tool.description === undefined ? [] : [tool.description]), JSON.stringify(tool.inputSchema)].join('\n');
|
|
139
190
|
}
|
|
140
191
|
const args = argumentsOf(argument);
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
const attachments = [];
|
|
146
|
-
for (const path of args.attachments) {
|
|
147
|
-
attachments.push(await upload(path, args.room_ref, 'each attachments entry is the path of a local file'));
|
|
148
|
-
}
|
|
149
|
-
args.attachments = attachments;
|
|
150
|
-
}
|
|
151
|
-
const result = await mcp('tools/call', { name: verb, arguments: args });
|
|
192
|
+
return verb === 'upload' ? upload(args) : called(verb, args);
|
|
193
|
+
}
|
|
194
|
+
async function called(name, args) {
|
|
195
|
+
const result = await mcp('tools/call', { name, arguments: args });
|
|
152
196
|
const text = result.content.map((content) => content.text).join('\n');
|
|
153
197
|
if (result.isError === true)
|
|
154
198
|
throw new Error(text.replace(/\n+$/, ''));
|
|
155
199
|
return text;
|
|
156
200
|
}
|
|
157
201
|
const argv = process.argv.slice(2);
|
|
158
|
-
(argv[0] === '
|
|
202
|
+
(argv[0] === 'push' ? push(argv.slice(1)) : argv[0] === 'fetch' ? fetched(argv.slice(1)) : house(argv)).then((text) => {
|
|
159
203
|
process.stdout.write(`${text}\n`);
|
|
204
|
+
if (argv[0] === 'shell')
|
|
205
|
+
process.exitCode = Number(/^exit: (\d+)(?:\n|$)/.exec(text)?.[1] ?? 0);
|
|
160
206
|
}, (error) => {
|
|
161
207
|
process.stderr.write(`house: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
162
208
|
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,15 +1,21 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { setGlobalProxyFromEnv } from 'node:http';
|
|
3
|
+
import { answerGitCredential } from './app-git.js';
|
|
3
4
|
import { login } from './login.js';
|
|
5
|
+
import { logout } from './logout.js';
|
|
4
6
|
import { resident } from './resident.js';
|
|
5
7
|
const [command, ...argv] = process.argv.slice(2);
|
|
6
8
|
setGlobalProxyFromEnv();
|
|
7
9
|
async function run() {
|
|
8
10
|
if (command === 'login')
|
|
9
11
|
return login(argv);
|
|
12
|
+
if (command === 'logout')
|
|
13
|
+
return logout();
|
|
10
14
|
if (command === 'resident')
|
|
11
15
|
return resident();
|
|
12
|
-
|
|
16
|
+
if (command === 'git-credential')
|
|
17
|
+
return answerGitCredential(argv[0]);
|
|
18
|
+
process.stderr.write('usage: kit <login|logout|resident>\n');
|
|
13
19
|
process.exitCode = 2;
|
|
14
20
|
}
|
|
15
21
|
run().catch((error) => {
|
package/dist/login.js
CHANGED
|
@@ -1,53 +1,22 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
1
2
|
import { createHash, randomBytes } from 'node:crypto';
|
|
2
|
-
import { createServer } from 'node:http';
|
|
3
3
|
import { hostname } from 'node:os';
|
|
4
|
-
import { createInterface } from 'node:readline/promises';
|
|
5
4
|
import { parseArgs } from 'node:util';
|
|
6
|
-
import { post } from './api.js';
|
|
7
|
-
import {
|
|
5
|
+
import { post, retrying } from './api.js';
|
|
6
|
+
import { placeAppGit } from './app-git.js';
|
|
7
|
+
import { forgetOwnAgent, readDisconnected, readEnrolment, readOwnAgent, writeEnrolment, writeOwnAgent } from './home.js';
|
|
8
8
|
import { callHouse, rpc } from './mcp.js';
|
|
9
|
+
import { selectRelay } from './relay.js';
|
|
10
|
+
import { startService } from './service.js';
|
|
11
|
+
import { placeSkillSet } from './skills.js';
|
|
9
12
|
const DEFAULT_HOUSE = 'https://agents.house';
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const server = createServer((request, response) => {
|
|
18
|
-
const received = new URL(request.url ?? '/', 'http://127.0.0.1').searchParams.get('code');
|
|
19
|
-
if (received === null || held !== null) {
|
|
20
|
-
response.writeHead(404).end();
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
held = response;
|
|
24
|
-
deliver(received);
|
|
25
|
-
});
|
|
26
|
-
const close = () => {
|
|
27
|
-
server.close();
|
|
28
|
-
server.closeAllConnections();
|
|
29
|
-
};
|
|
30
|
-
const port = Number(process.env.HOUSE_KIT_LOGIN_PORT ?? 0);
|
|
31
|
-
server.once('error', reject);
|
|
32
|
-
server.listen(port, port === 0 ? '127.0.0.1' : '0.0.0.0', () => {
|
|
33
|
-
const address = server.address();
|
|
34
|
-
if (address === null || typeof address === 'string') {
|
|
35
|
-
reject(new Error('the login callback has no port'));
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
resolve({
|
|
39
|
-
uri: `http://127.0.0.1:${address.port}/callback`,
|
|
40
|
-
code,
|
|
41
|
-
answer: (text) => new Promise((written) => {
|
|
42
|
-
if (held === null || held.destroyed || !held.socket || held.socket.destroyed)
|
|
43
|
-
return written();
|
|
44
|
-
held.once('close', () => written());
|
|
45
|
-
held.writeHead(200, { 'content-type': 'text/plain; charset=utf-8', connection: 'close' }).end(`${text}\n`);
|
|
46
|
-
}),
|
|
47
|
-
close,
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
});
|
|
13
|
+
const OPENER = process.platform === 'darwin' ? 'open' : 'xdg-open';
|
|
14
|
+
// Polling every two seconds brings the User's confirmation to the waiting Kit moments after they give it.
|
|
15
|
+
const POLL_INTERVAL_MS = 2000;
|
|
16
|
+
function open(link) {
|
|
17
|
+
spawn(OPENER, [link], { detached: true, stdio: 'ignore' })
|
|
18
|
+
.on('error', () => undefined)
|
|
19
|
+
.unref();
|
|
51
20
|
}
|
|
52
21
|
async function accepted(house, credential) {
|
|
53
22
|
const checked = await callHouse(house, credential, rpc('tools/list', {}));
|
|
@@ -57,17 +26,19 @@ async function accepted(house, credential) {
|
|
|
57
26
|
return false;
|
|
58
27
|
throw new Error(`House answered ${checked.status} when Kit checked this computer's own agent's connection: ${checked.text}`);
|
|
59
28
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
29
|
+
const USAGE = `usage: kit login [--house <origin>] [--environment <id>] [--rooms <ref>[,<ref>...] | --no-private] [--code <code>]
|
|
30
|
+
--house <origin> the House to connect to, ${DEFAULT_HOUSE} unless one is stored
|
|
31
|
+
--environment <id> reconnect this Environment
|
|
32
|
+
--rooms <ref>[,<ref>...] give this Environment only these Rooms
|
|
33
|
+
--no-private give this Environment every Room but your Private Room
|
|
34
|
+
--code <code> connect this machine with a login code
|
|
35
|
+
`;
|
|
36
|
+
function chosenRooms(rooms, noPrivate) {
|
|
37
|
+
if (rooms !== undefined && noPrivate)
|
|
38
|
+
throw new Error('--rooms and --no-private are two choices of Rooms; pass one');
|
|
39
|
+
if (rooms !== undefined)
|
|
40
|
+
return { rooms: { reach: 'selected', refs: rooms.split(',') } };
|
|
41
|
+
return noPrivate ? { rooms: { reach: 'all_but_private' } } : {};
|
|
71
42
|
}
|
|
72
43
|
export async function login(argv) {
|
|
73
44
|
const { values } = parseArgs({
|
|
@@ -75,62 +46,79 @@ export async function login(argv) {
|
|
|
75
46
|
options: {
|
|
76
47
|
house: { type: 'string' },
|
|
77
48
|
environment: { type: 'string' },
|
|
78
|
-
|
|
49
|
+
rooms: { type: 'string' },
|
|
50
|
+
'no-private': { type: 'boolean', default: false },
|
|
51
|
+
code: { type: 'string' },
|
|
52
|
+
help: { type: 'boolean', default: false },
|
|
79
53
|
},
|
|
80
54
|
});
|
|
81
|
-
|
|
55
|
+
if (values.help) {
|
|
56
|
+
process.stdout.write(USAGE);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (values.code !== undefined && values.rooms !== undefined)
|
|
60
|
+
throw new Error('--code cannot be used with --rooms');
|
|
61
|
+
if (values.code !== undefined && values['no-private'])
|
|
62
|
+
throw new Error('--code cannot be used with --no-private');
|
|
63
|
+
if (values.code !== undefined && values.environment !== undefined)
|
|
64
|
+
throw new Error('--code cannot be used with --environment');
|
|
65
|
+
const rooms = chosenRooms(values.rooms, values['no-private']);
|
|
66
|
+
const enrolled = (await readEnrolment()) ?? (await readDisconnected());
|
|
67
|
+
if (values.code !== undefined && enrolled !== null) {
|
|
68
|
+
throw new Error(`--code connects a new machine; this Kit home records Environment ${enrolled.environment}, so run kit login to reconnect it`);
|
|
69
|
+
}
|
|
70
|
+
const relay = process.env.HOUSE_KIT_RELAY || undefined;
|
|
71
|
+
selectRelay(relay);
|
|
82
72
|
const house = values.house ?? enrolled?.house ?? DEFAULT_HOUSE;
|
|
83
73
|
const replaces = process.env.HOUSE_KIT_REPLACES;
|
|
84
74
|
const environment = replaces === undefined ? (values.environment ?? (enrolled?.house === house ? enrolled.environment : undefined)) : undefined;
|
|
85
75
|
const ownAgent = await readOwnAgent();
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
76
|
+
let held = false;
|
|
77
|
+
let exchanged;
|
|
78
|
+
if (values.code !== undefined) {
|
|
79
|
+
exchanged = await post(house, '/kit/token', { code: values.code, label: hostname() });
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
held = ownAgent !== null && ownAgent.house === house && (await accepted(house, ownAgent.credential));
|
|
83
|
+
const verifier = randomBytes(32).toString('base64url');
|
|
84
|
+
const started = await retrying(() => post(house, '/kit', {
|
|
85
|
+
label: hostname(),
|
|
86
|
+
...(environment === undefined
|
|
87
|
+
? { act: 'new_environment', ...(replaces === undefined ? {} : { replaces }) }
|
|
88
|
+
: { act: 'existing_environment', environment_id: environment }),
|
|
89
|
+
...rooms,
|
|
90
|
+
code_challenge: createHash('sha256').update(verifier).digest('base64url'),
|
|
91
|
+
...(held ? {} : { headless: true }),
|
|
92
|
+
}));
|
|
93
|
+
process.stdout.write(`Open this link and confirm: ${started.start_url}\n`);
|
|
94
|
+
open(started.start_url);
|
|
95
|
+
exchanged = await retrying(() => post(house, '/kit/token', { login: started.login, code_verifier: verifier }), undefined, () => POLL_INTERVAL_MS);
|
|
96
|
+
}
|
|
97
|
+
try {
|
|
98
|
+
await placeSkillSet();
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
process.stderr.write(`kit: the skills could not be placed: ${error.message}\n`);
|
|
102
|
+
}
|
|
103
|
+
await writeEnrolment({
|
|
104
|
+
house,
|
|
105
|
+
...(relay === undefined ? {} : { relay }),
|
|
106
|
+
environment: exchanged.environment,
|
|
107
|
+
credential: exchanged.credential,
|
|
108
|
+
});
|
|
109
|
+
process.stdout.write(`Environment ${exchanged.environment} is connected to ${house}.\n`);
|
|
110
|
+
if (exchanged.headless_credential !== undefined) {
|
|
111
|
+
await writeOwnAgent({ house, user: exchanged.user, credential: exchanged.headless_credential });
|
|
112
|
+
}
|
|
113
|
+
else if (held && ownAgent !== null && ownAgent.user !== exchanged.user) {
|
|
114
|
+
await forgetOwnAgent();
|
|
115
|
+
process.stdout.write("This computer's own agent was another User's; run kit login again to connect it to you.\n");
|
|
115
116
|
}
|
|
116
|
-
|
|
117
|
+
await placeAppGit(ownAgent, await readOwnAgent());
|
|
117
118
|
try {
|
|
118
|
-
|
|
119
|
-
...started,
|
|
120
|
-
presentation: 'loopback',
|
|
121
|
-
loopback_uri: callback.uri,
|
|
122
|
-
});
|
|
123
|
-
process.stdout.write(`Open this link and confirm: ${start_url}\n`);
|
|
124
|
-
try {
|
|
125
|
-
await exchange(await callback.code);
|
|
126
|
-
}
|
|
127
|
-
catch (error) {
|
|
128
|
-
await callback.answer(`This Environment was not connected: ${error.message}`);
|
|
129
|
-
throw error;
|
|
130
|
-
}
|
|
131
|
-
await callback.answer('This Environment is connected. You can close this tab.');
|
|
119
|
+
startService();
|
|
132
120
|
}
|
|
133
|
-
|
|
134
|
-
|
|
121
|
+
catch (error) {
|
|
122
|
+
process.stderr.write(`kit: ${error.message}\n`);
|
|
135
123
|
}
|
|
136
124
|
}
|
package/dist/logout.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { HouseRefusal, post } from './api.js';
|
|
2
|
+
import { forgetAppGit } from './app-git.js';
|
|
3
|
+
import { forgetEnrolment, forgetOwnAgent, readEnrolment } from './home.js';
|
|
4
|
+
export async function logout() {
|
|
5
|
+
const enrolled = await readEnrolment();
|
|
6
|
+
if (enrolled !== null) {
|
|
7
|
+
try {
|
|
8
|
+
await post(enrolled.house, '/kit/logout', {}, enrolled.credential);
|
|
9
|
+
}
|
|
10
|
+
catch (error) {
|
|
11
|
+
if (!(error instanceof HouseRefusal && error.status === 401))
|
|
12
|
+
throw error;
|
|
13
|
+
}
|
|
14
|
+
await forgetEnrolment(enrolled);
|
|
15
|
+
}
|
|
16
|
+
await forgetAppGit();
|
|
17
|
+
await forgetOwnAgent();
|
|
18
|
+
process.stdout.write(enrolled === null
|
|
19
|
+
? 'This computer is not connected to House.\n'
|
|
20
|
+
: `Environment ${enrolled.environment} is disconnected; kit login reconnects it.\n`);
|
|
21
|
+
}
|
package/dist/mcp.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
2
|
import { KIT_VERSION } from './clis.js';
|
|
3
|
+
import { relayed } from './relay.js';
|
|
3
4
|
const MCP_PROTOCOL_VERSION = '2026-07-28';
|
|
4
5
|
export const UNREACHABLE = 'House is unreachable; call again in a minute';
|
|
5
6
|
export function rpc(method, params) {
|
|
@@ -21,7 +22,7 @@ export function mcpBody(message, operation) {
|
|
|
21
22
|
}
|
|
22
23
|
export async function callHouse(origin, credential, message, operation = null, signal) {
|
|
23
24
|
const tool = message.method === 'tools/call' ? String(message.params.name) : null;
|
|
24
|
-
const answer = await fetch(new URL('/', origin), {
|
|
25
|
+
const answer = await fetch(relayed(new URL('/', origin)), {
|
|
25
26
|
method: 'POST',
|
|
26
27
|
headers: {
|
|
27
28
|
'content-type': 'application/json',
|
package/dist/parts.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
export class Parts {
|
|
2
|
+
parts = [];
|
|
3
|
+
context = null;
|
|
4
|
+
emit;
|
|
5
|
+
made = [];
|
|
6
|
+
events = 0;
|
|
7
|
+
writing = null;
|
|
8
|
+
counting = null;
|
|
9
|
+
planned = null;
|
|
10
|
+
constructor(emit) {
|
|
11
|
+
this.emit = emit;
|
|
12
|
+
}
|
|
13
|
+
write(type, id, text) {
|
|
14
|
+
if (text === '')
|
|
15
|
+
return;
|
|
16
|
+
if (this.writing?.type === type && this.writing.id === id) {
|
|
17
|
+
this.parts[this.writing.index].text += text;
|
|
18
|
+
this.emit({ op: 'append', index: this.writing.index, text });
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
this.writing = { type, id, index: this.start({ type, text }) };
|
|
22
|
+
}
|
|
23
|
+
command() {
|
|
24
|
+
if (this.counting === null) {
|
|
25
|
+
this.counting = this.start({ type: 'commands', count: 1 });
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const part = this.parts[this.counting];
|
|
29
|
+
part.count++;
|
|
30
|
+
this.emit({ op: 'count', index: this.counting, count: part.count });
|
|
31
|
+
}
|
|
32
|
+
start(part) {
|
|
33
|
+
this.writing = null;
|
|
34
|
+
this.counting = null;
|
|
35
|
+
return this.add(part, ++this.events);
|
|
36
|
+
}
|
|
37
|
+
reserve() {
|
|
38
|
+
this.writing = null;
|
|
39
|
+
this.counting = null;
|
|
40
|
+
return ++this.events;
|
|
41
|
+
}
|
|
42
|
+
arrive(part, reserved) {
|
|
43
|
+
this.add(part, reserved);
|
|
44
|
+
}
|
|
45
|
+
done(index, result) {
|
|
46
|
+
const part = this.parts[index];
|
|
47
|
+
part.status = 'done';
|
|
48
|
+
part.result = result;
|
|
49
|
+
this.emit({ op: 'status', index, status: 'done', result });
|
|
50
|
+
}
|
|
51
|
+
plan(entries) {
|
|
52
|
+
if (this.planned === null) {
|
|
53
|
+
this.planned = this.start({ type: 'plan', entries });
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
this.parts[this.planned].entries = entries;
|
|
57
|
+
this.emit({ op: 'plan', index: this.planned, entries });
|
|
58
|
+
}
|
|
59
|
+
measure(context) {
|
|
60
|
+
this.context = context;
|
|
61
|
+
this.emit({ op: 'context', ...context });
|
|
62
|
+
}
|
|
63
|
+
saved() {
|
|
64
|
+
return this.parts
|
|
65
|
+
.map((part, index) => ({ part, made: this.made[index] }))
|
|
66
|
+
.sort((a, b) => a.made - b.made)
|
|
67
|
+
.map(({ part }) => part);
|
|
68
|
+
}
|
|
69
|
+
operations() {
|
|
70
|
+
return [
|
|
71
|
+
...this.parts.map((part, index) => ({ op: 'start', index, part })),
|
|
72
|
+
...(this.context === null ? [] : [{ op: 'context', ...this.context }]),
|
|
73
|
+
];
|
|
74
|
+
}
|
|
75
|
+
add(part, made) {
|
|
76
|
+
this.parts.push(part);
|
|
77
|
+
this.made.push(made);
|
|
78
|
+
const index = this.parts.length - 1;
|
|
79
|
+
this.emit({ op: 'start', index, part });
|
|
80
|
+
return index;
|
|
81
|
+
}
|
|
82
|
+
}
|
package/dist/refusals.js
CHANGED
|
@@ -21,6 +21,18 @@ function spoken(text) {
|
|
|
21
21
|
const detail = said.indexOf('\n');
|
|
22
22
|
return { code: head[1], text: said, conflicts: detail === -1 ? [] : conflictCodes(said.slice(detail + 1)) };
|
|
23
23
|
}
|
|
24
|
+
export function retryable(text) {
|
|
25
|
+
let body;
|
|
26
|
+
try {
|
|
27
|
+
body = JSON.parse(text);
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
const error = body?.error;
|
|
33
|
+
const verdict = error?.retryable ?? error?.data?.retryable;
|
|
34
|
+
return typeof verdict === 'boolean' ? verdict : null;
|
|
35
|
+
}
|
|
24
36
|
export function refusalOf(text) {
|
|
25
37
|
let body;
|
|
26
38
|
try {
|
package/dist/relay.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
let selected;
|
|
2
|
+
export function selectRelay(relay) {
|
|
3
|
+
selected = relay === undefined || relay === '' ? null : relay;
|
|
4
|
+
}
|
|
5
|
+
function relayOrigin() {
|
|
6
|
+
if (selected !== undefined)
|
|
7
|
+
return selected ?? undefined;
|
|
8
|
+
const ambient = process.env.HOUSE_KIT_RELAY;
|
|
9
|
+
return ambient === undefined || ambient === '' ? undefined : ambient;
|
|
10
|
+
}
|
|
11
|
+
export function relayed(target) {
|
|
12
|
+
const url = new URL(target);
|
|
13
|
+
const relay = relayOrigin();
|
|
14
|
+
if (relay === undefined)
|
|
15
|
+
return url;
|
|
16
|
+
const through = new URL(`${url.host}${url.pathname}${url.search}`, `${relay}/`);
|
|
17
|
+
if (url.protocol === 'wss:' || url.protocol === 'ws:')
|
|
18
|
+
through.protocol = 'wss:';
|
|
19
|
+
return through;
|
|
20
|
+
}
|