@agentshouse/kit 0.2.1-cd9cbd8b6428c → 0.2.1-cf110d15f69c8
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 +26 -26
- package/dist/acp.js +16 -93
- package/dist/agents.js +82 -40
- package/dist/api.js +30 -2
- package/dist/app-git.js +64 -0
- package/dist/bootstrap.json +4 -4
- package/dist/bridge.js +35 -52
- package/dist/clis.js +121 -65
- package/dist/codex-main.js +58 -0
- package/dist/conversations.js +287 -236
- package/dist/copies.js +147 -130
- package/dist/end.js +18 -0
- package/dist/enrol-main.js +7 -1
- package/dist/events.js +521 -0
- package/dist/files.js +14 -0
- package/dist/home.js +41 -3
- package/dist/house-main.js +79 -32
- package/dist/instructions.js +7 -5
- package/dist/kit-main.js +3 -0
- package/dist/login.js +99 -102
- package/dist/logout.js +16 -13
- package/dist/parts.js +82 -0
- package/dist/refusals.js +12 -0
- package/dist/relay.js +12 -2
- package/dist/resident.js +30 -23
- 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 +31 -4
- 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,19 +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
13
|
const PUSH_USAGE = 'usage: house push [commit] [--owner]';
|
|
11
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}`;
|
|
12
17
|
const ARGUMENTS = `the arguments are one JSON object in single quotes, like house search '{"query":"invoice"}'`;
|
|
13
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";
|
|
14
20
|
const REVOKED = 'this conversation no longer has House access; nothing to do from here';
|
|
15
21
|
const UNCONNECTED = "this computer's own agent has no House connection; run kit login";
|
|
16
22
|
const DISCONNECTED = "House no longer accepts this computer's own agent; run kit login";
|
|
17
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
|
+
]);
|
|
18
51
|
function refused(path, status, text) {
|
|
19
52
|
const refusal = refusalOf(text);
|
|
20
53
|
if (refusal !== null)
|
|
@@ -42,7 +75,7 @@ function bridged(path, body, headers = { 'content-type': 'application/json' }, t
|
|
|
42
75
|
reject(new Error(refused(path, answer.statusCode, text)));
|
|
43
76
|
});
|
|
44
77
|
});
|
|
45
|
-
sent.on('error', () => reject(new Error(CLOSED)));
|
|
78
|
+
sent.on('error', (error) => reject(new Error(error.code === 'EPERM' || error.code === 'EACCES' ? SANDBOXED : CLOSED)));
|
|
46
79
|
sent.end(body instanceof Buffer ? body : JSON.stringify(body));
|
|
47
80
|
});
|
|
48
81
|
}
|
|
@@ -50,6 +83,7 @@ async function direct(message) {
|
|
|
50
83
|
const ownAgent = await readOwnAgent();
|
|
51
84
|
if (ownAgent === null)
|
|
52
85
|
throw new Error(UNCONNECTED);
|
|
86
|
+
await readEnrolment();
|
|
53
87
|
setGlobalProxyFromEnv();
|
|
54
88
|
const answer = await callHouse(ownAgent.house, ownAgent.credential, message).catch(() => {
|
|
55
89
|
throw new Error(UNREACHABLE);
|
|
@@ -78,25 +112,35 @@ async function localFile(path) {
|
|
|
78
112
|
: `${path} is not a readable file`);
|
|
79
113
|
}
|
|
80
114
|
}
|
|
81
|
-
async function
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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,
|
|
88
135
|
bytes: bytes.length,
|
|
89
136
|
sha256: createHash('sha256').update(bytes).digest('hex'),
|
|
90
|
-
|
|
137
|
+
...(mediaType === undefined ? {} : { media_type: mediaType }),
|
|
138
|
+
});
|
|
139
|
+
const declared = parse(answer);
|
|
91
140
|
if (declared.upload === undefined)
|
|
92
|
-
return
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
'x-house-byte-operation': declared.upload.operation,
|
|
96
|
-
}));
|
|
97
|
-
if (saved.upload_failure !== undefined)
|
|
98
|
-
throw new Error(`${path} was not saved: ${saved.upload_failure}; call again later`);
|
|
99
|
-
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();
|
|
100
144
|
}
|
|
101
145
|
async function push(args) {
|
|
102
146
|
if (args.includes('--help'))
|
|
@@ -112,6 +156,14 @@ async function push(args) {
|
|
|
112
156
|
throw new Error(pushed.text);
|
|
113
157
|
return pushed.text;
|
|
114
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
|
+
}
|
|
115
167
|
function argumentsOf(argument) {
|
|
116
168
|
if (argument === undefined)
|
|
117
169
|
return {};
|
|
@@ -128,7 +180,7 @@ function argumentsOf(argument) {
|
|
|
128
180
|
}
|
|
129
181
|
async function house([verb, argument]) {
|
|
130
182
|
if (verb === undefined || verb === '--help' || verb === 'help') {
|
|
131
|
-
return [USAGE, 'help', PUSH, ...(await tools()).map((tool) => (tool.description === undefined ? tool.name : `${tool.name}: ${tool.description}`))].join('\n');
|
|
183
|
+
return [USAGE, 'help', PUSH, FETCH, ...(await tools()).map((tool) => (tool.description === undefined ? tool.name : `${tool.name}: ${tool.description}`))].join('\n');
|
|
132
184
|
}
|
|
133
185
|
if (argument === '--help') {
|
|
134
186
|
const tool = (await tools()).find((listed) => listed.name === verb);
|
|
@@ -137,25 +189,20 @@ async function house([verb, argument]) {
|
|
|
137
189
|
return [...(tool.description === undefined ? [] : [tool.description]), JSON.stringify(tool.inputSchema)].join('\n');
|
|
138
190
|
}
|
|
139
191
|
const args = argumentsOf(argument);
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
const attachments = [];
|
|
145
|
-
for (const path of args.attachments) {
|
|
146
|
-
attachments.push(await upload(path, args.room_ref, 'each attachments entry is the path of a local file'));
|
|
147
|
-
}
|
|
148
|
-
args.attachments = attachments;
|
|
149
|
-
}
|
|
150
|
-
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 });
|
|
151
196
|
const text = result.content.map((content) => content.text).join('\n');
|
|
152
197
|
if (result.isError === true)
|
|
153
198
|
throw new Error(text.replace(/\n+$/, ''));
|
|
154
199
|
return text;
|
|
155
200
|
}
|
|
156
201
|
const argv = process.argv.slice(2);
|
|
157
|
-
(argv[0] === 'push' ? push(argv.slice(1)) : house(argv)).then((text) => {
|
|
202
|
+
(argv[0] === 'push' ? push(argv.slice(1)) : argv[0] === 'fetch' ? fetched(argv.slice(1)) : house(argv)).then((text) => {
|
|
158
203
|
process.stdout.write(`${text}\n`);
|
|
204
|
+
if (argv[0] === 'shell')
|
|
205
|
+
process.exitCode = Number(/^exit: (\d+)(?:\n|$)/.exec(text)?.[1] ?? 0);
|
|
159
206
|
}, (error) => {
|
|
160
207
|
process.stderr.write(`house: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
161
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,5 +1,6 @@
|
|
|
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';
|
|
4
5
|
import { logout } from './logout.js';
|
|
5
6
|
import { resident } from './resident.js';
|
|
@@ -12,6 +13,8 @@ async function run() {
|
|
|
12
13
|
return logout();
|
|
13
14
|
if (command === 'resident')
|
|
14
15
|
return resident();
|
|
16
|
+
if (command === 'git-credential')
|
|
17
|
+
return answerGitCredential(argv[0]);
|
|
15
18
|
process.stderr.write('usage: kit <login|logout|resident>\n');
|
|
16
19
|
process.exitCode = 2;
|
|
17
20
|
}
|
package/dist/login.js
CHANGED
|
@@ -1,53 +1,24 @@
|
|
|
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 {
|
|
4
|
+
import { delimiter, dirname } from 'node:path';
|
|
5
5
|
import { parseArgs } from 'node:util';
|
|
6
|
-
import { post } from './api.js';
|
|
6
|
+
import { post, retrying } from './api.js';
|
|
7
|
+
import { placeAppGit } from './app-git.js';
|
|
8
|
+
import { allowHouseInCodex, loginPath } from './clis.js';
|
|
7
9
|
import { forgetOwnAgent, readDisconnected, readEnrolment, readOwnAgent, writeEnrolment, writeOwnAgent } from './home.js';
|
|
8
10
|
import { callHouse, rpc } from './mcp.js';
|
|
11
|
+
import { selectRelay } from './relay.js';
|
|
12
|
+
import { startService } from './service.js';
|
|
13
|
+
import { placeSkillSet } from './skills.js';
|
|
9
14
|
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
|
-
});
|
|
15
|
+
const OPENER = process.platform === 'darwin' ? 'open' : 'xdg-open';
|
|
16
|
+
// Polling every two seconds brings the User's confirmation to the waiting Kit moments after they give it.
|
|
17
|
+
const POLL_INTERVAL_MS = 2000;
|
|
18
|
+
function open(link) {
|
|
19
|
+
spawn(OPENER, [link], { detached: true, stdio: 'ignore' })
|
|
20
|
+
.on('error', () => undefined)
|
|
21
|
+
.unref();
|
|
51
22
|
}
|
|
52
23
|
async function accepted(house, credential) {
|
|
53
24
|
const checked = await callHouse(house, credential, rpc('tools/list', {}));
|
|
@@ -57,17 +28,19 @@ async function accepted(house, credential) {
|
|
|
57
28
|
return false;
|
|
58
29
|
throw new Error(`House answered ${checked.status} when Kit checked this computer's own agent's connection: ${checked.text}`);
|
|
59
30
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
31
|
+
const USAGE = `usage: kit login [--house <origin>] [--environment <id>] [--rooms <ref>[,<ref>...] | --no-private] [--code <code>]
|
|
32
|
+
--house <origin> the House to connect to, ${DEFAULT_HOUSE} unless one is stored
|
|
33
|
+
--environment <id> reconnect this Environment
|
|
34
|
+
--rooms <ref>[,<ref>...] give this Environment only these Rooms
|
|
35
|
+
--no-private give this Environment every Room but your Private Room
|
|
36
|
+
--code <code> connect this machine with a login code
|
|
37
|
+
`;
|
|
38
|
+
function chosenRooms(rooms, noPrivate) {
|
|
39
|
+
if (rooms !== undefined && noPrivate)
|
|
40
|
+
throw new Error('--rooms and --no-private are two choices of Rooms; pass one');
|
|
41
|
+
if (rooms !== undefined)
|
|
42
|
+
return { rooms: { reach: 'selected', refs: rooms.split(',') } };
|
|
43
|
+
return noPrivate ? { rooms: { reach: 'all_but_private' } } : {};
|
|
71
44
|
}
|
|
72
45
|
export async function login(argv) {
|
|
73
46
|
const { values } = parseArgs({
|
|
@@ -75,62 +48,86 @@ export async function login(argv) {
|
|
|
75
48
|
options: {
|
|
76
49
|
house: { type: 'string' },
|
|
77
50
|
environment: { type: 'string' },
|
|
78
|
-
|
|
51
|
+
rooms: { type: 'string' },
|
|
52
|
+
'no-private': { type: 'boolean', default: false },
|
|
53
|
+
code: { type: 'string' },
|
|
54
|
+
help: { type: 'boolean', default: false },
|
|
79
55
|
},
|
|
80
56
|
});
|
|
57
|
+
if (values.help) {
|
|
58
|
+
process.stdout.write(USAGE);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
if (values.code !== undefined && values.rooms !== undefined)
|
|
62
|
+
throw new Error('--code cannot be used with --rooms');
|
|
63
|
+
if (values.code !== undefined && values['no-private'])
|
|
64
|
+
throw new Error('--code cannot be used with --no-private');
|
|
65
|
+
if (values.code !== undefined && values.environment !== undefined)
|
|
66
|
+
throw new Error('--code cannot be used with --environment');
|
|
67
|
+
const rooms = chosenRooms(values.rooms, values['no-private']);
|
|
81
68
|
const enrolled = (await readEnrolment()) ?? (await readDisconnected());
|
|
69
|
+
if (values.code !== undefined && enrolled !== null) {
|
|
70
|
+
throw new Error(`--code connects a new machine; this Kit home records Environment ${enrolled.environment}, so run kit login to reconnect it`);
|
|
71
|
+
}
|
|
72
|
+
const relay = process.env.HOUSE_KIT_RELAY || undefined;
|
|
73
|
+
selectRelay(relay);
|
|
82
74
|
const house = values.house ?? enrolled?.house ?? DEFAULT_HOUSE;
|
|
83
75
|
const replaces = process.env.HOUSE_KIT_REPLACES;
|
|
84
76
|
const environment = replaces === undefined ? (values.environment ?? (enrolled?.house === house ? enrolled.environment : undefined)) : undefined;
|
|
85
77
|
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
|
-
|
|
78
|
+
let held = false;
|
|
79
|
+
let exchanged;
|
|
80
|
+
if (values.code !== undefined) {
|
|
81
|
+
exchanged = await post(house, '/kit/token', { code: values.code, label: hostname() });
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
held = ownAgent !== null && ownAgent.house === house && (await accepted(house, ownAgent.credential));
|
|
85
|
+
const verifier = randomBytes(32).toString('base64url');
|
|
86
|
+
const started = await retrying(() => post(house, '/kit', {
|
|
87
|
+
label: hostname(),
|
|
88
|
+
...(environment === undefined
|
|
89
|
+
? { act: 'new_environment', ...(replaces === undefined ? {} : { replaces }) }
|
|
90
|
+
: { act: 'existing_environment', environment_id: environment }),
|
|
91
|
+
...rooms,
|
|
92
|
+
code_challenge: createHash('sha256').update(verifier).digest('base64url'),
|
|
93
|
+
...(held ? {} : { headless: true }),
|
|
94
|
+
}));
|
|
95
|
+
process.stdout.write(`Open this link and confirm: ${started.start_url}\n`);
|
|
96
|
+
open(started.start_url);
|
|
97
|
+
exchanged = await retrying(() => post(house, '/kit/token', { login: started.login, code_verifier: verifier }), undefined, () => POLL_INTERVAL_MS);
|
|
98
|
+
}
|
|
99
|
+
try {
|
|
100
|
+
await placeSkillSet();
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
process.stderr.write(`kit: the skills could not be placed: ${error.message}\n`);
|
|
104
|
+
}
|
|
105
|
+
try {
|
|
106
|
+
const shell = await loginPath().catch(() => '');
|
|
107
|
+
await allowHouseInCodex([dirname(process.execPath), process.env.PATH ?? '', shell].join(delimiter));
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
process.stderr.write(`kit: Codex's rule for house could not be written: ${error.message}\n`);
|
|
111
|
+
}
|
|
112
|
+
await writeEnrolment({
|
|
113
|
+
house,
|
|
114
|
+
...(relay === undefined ? {} : { relay }),
|
|
115
|
+
environment: exchanged.environment,
|
|
116
|
+
credential: exchanged.credential,
|
|
117
|
+
});
|
|
118
|
+
process.stdout.write(`Environment ${exchanged.environment} is connected to ${house}.\n`);
|
|
119
|
+
if (exchanged.headless_credential !== undefined) {
|
|
120
|
+
await writeOwnAgent({ house, user: exchanged.user, credential: exchanged.headless_credential });
|
|
121
|
+
}
|
|
122
|
+
else if (held && ownAgent !== null && ownAgent.user !== exchanged.user) {
|
|
123
|
+
await forgetOwnAgent();
|
|
124
|
+
process.stdout.write("This computer's own agent was another User's; run kit login again to connect it to you.\n");
|
|
115
125
|
}
|
|
116
|
-
|
|
126
|
+
await placeAppGit(ownAgent, await readOwnAgent());
|
|
117
127
|
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.');
|
|
128
|
+
startService();
|
|
132
129
|
}
|
|
133
|
-
|
|
134
|
-
|
|
130
|
+
catch (error) {
|
|
131
|
+
process.stderr.write(`kit: ${error.message}\n`);
|
|
135
132
|
}
|
|
136
133
|
}
|
package/dist/logout.js
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
import { HouseRefusal, post } from './api.js';
|
|
2
|
-
import {
|
|
2
|
+
import { forgetAppGit } from './app-git.js';
|
|
3
|
+
import { forgetEnrolment, forgetOwnAgent, readEnrolment } from './home.js';
|
|
3
4
|
export async function logout() {
|
|
4
5
|
const enrolled = await readEnrolment();
|
|
5
|
-
if (enrolled
|
|
6
|
-
|
|
7
|
-
|
|
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);
|
|
8
15
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
throw error;
|
|
15
|
-
}
|
|
16
|
-
await forgetEnrolment(enrolled);
|
|
17
|
-
process.stdout.write(`Environment ${enrolled.environment} is disconnected; kit login reconnects it.\n`);
|
|
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`);
|
|
18
21
|
}
|
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
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
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
|
+
}
|
|
1
11
|
export function relayed(target) {
|
|
2
12
|
const url = new URL(target);
|
|
3
|
-
const relay =
|
|
4
|
-
if (relay === undefined
|
|
13
|
+
const relay = relayOrigin();
|
|
14
|
+
if (relay === undefined)
|
|
5
15
|
return url;
|
|
6
16
|
const through = new URL(`${url.host}${url.pathname}${url.search}`, `${relay}/`);
|
|
7
17
|
if (url.protocol === 'wss:' || url.protocol === 'ws:')
|