@agentshouse/kit 0.2.1-c063e835a50ea → 0.2.1-c073f4e9391b2
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 +103 -42
- package/dist/api.js +34 -2
- package/dist/app-git.js +64 -0
- package/dist/bootstrap.json +4 -4
- package/dist/bridge.js +33 -51
- package/dist/chatgpt.js +25 -0
- package/dist/clis.js +127 -65
- package/dist/codex-main.js +58 -0
- package/dist/conversations.js +288 -236
- package/dist/copies.js +147 -130
- package/dist/end.js +22 -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 +108 -39
- package/dist/instructions.js +7 -5
- package/dist/kit-main.js +54 -6
- package/dist/login.js +95 -104
- package/dist/logout.js +16 -13
- package/dist/parts.js +82 -0
- package/dist/placement.js +48 -0
- package/dist/refusals.js +12 -0
- package/dist/relay.js +12 -2
- package/dist/resident.js +38 -27
- 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 +35 -5
- package/dist/transcription.js +54 -6
- package/dist/update.js +29 -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/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,31 +112,56 @@ 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
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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
|
+
function unexpected(argument, usage) {
|
|
146
|
+
return new Error(`unexpected argument ${argument}; ${usage}`);
|
|
147
|
+
}
|
|
148
|
+
function accepted(args, flags, positionals, usage) {
|
|
149
|
+
const given = { flags: new Set(), positionals: [] };
|
|
150
|
+
for (const arg of args) {
|
|
151
|
+
if (flags.includes(arg))
|
|
152
|
+
given.flags.add(arg);
|
|
153
|
+
else if (!arg.startsWith('-') && given.positionals.length < positionals)
|
|
154
|
+
given.positionals.push(arg);
|
|
155
|
+
else
|
|
156
|
+
throw unexpected(arg, usage);
|
|
157
|
+
}
|
|
158
|
+
return given;
|
|
100
159
|
}
|
|
101
160
|
async function push(args) {
|
|
102
|
-
|
|
161
|
+
const { flags, positionals: [commit = 'HEAD'] } = accepted(args, ['--help', '--owner'], 1, PUSH_USAGE);
|
|
162
|
+
if (flags.has('--help'))
|
|
103
163
|
return PUSH_USAGE;
|
|
104
|
-
const owner =
|
|
105
|
-
const commit = args.find((arg) => arg !== '--owner') ?? 'HEAD';
|
|
164
|
+
const owner = flags.has('--owner');
|
|
106
165
|
if (owner && socketPath !== undefined)
|
|
107
166
|
throw new Error('--owner is not for Agent conversations; run house push without it');
|
|
108
167
|
if (!owner && socketPath === undefined)
|
|
@@ -112,6 +171,14 @@ async function push(args) {
|
|
|
112
171
|
throw new Error(pushed.text);
|
|
113
172
|
return pushed.text;
|
|
114
173
|
}
|
|
174
|
+
async function fetched(args) {
|
|
175
|
+
if (accepted(args, ['--help'], 0, FETCH_USAGE).flags.has('--help'))
|
|
176
|
+
return FETCH_USAGE;
|
|
177
|
+
const answer = JSON.parse(await bridged('/git/fetch', {}, undefined, socketPath ?? join(kitHome(), 'owner.sock')));
|
|
178
|
+
if (answer.refused)
|
|
179
|
+
throw new Error(answer.text);
|
|
180
|
+
return answer.text;
|
|
181
|
+
}
|
|
115
182
|
function argumentsOf(argument) {
|
|
116
183
|
if (argument === undefined)
|
|
117
184
|
return {};
|
|
@@ -126,36 +193,38 @@ function argumentsOf(argument) {
|
|
|
126
193
|
throw new Error(ARGUMENTS);
|
|
127
194
|
return parsed;
|
|
128
195
|
}
|
|
129
|
-
async function house(
|
|
130
|
-
|
|
131
|
-
|
|
196
|
+
async function house(args) {
|
|
197
|
+
const { flags, positionals: [verb, argument] } = accepted(args, ['--help'], 2, USAGE);
|
|
198
|
+
if (verb === 'help' && argument !== undefined)
|
|
199
|
+
throw unexpected(argument, USAGE);
|
|
200
|
+
if (flags.has('--help') && argument !== undefined)
|
|
201
|
+
throw unexpected('--help', USAGE);
|
|
202
|
+
if (verb === undefined || verb === 'help') {
|
|
203
|
+
return [USAGE, 'help', PUSH, FETCH, ...(await tools()).map((tool) => (tool.description === undefined ? tool.name : `${tool.name}: ${tool.description}`))].join('\n');
|
|
132
204
|
}
|
|
133
|
-
if (
|
|
205
|
+
if (flags.has('--help')) {
|
|
134
206
|
const tool = (await tools()).find((listed) => listed.name === verb);
|
|
135
207
|
if (tool === undefined)
|
|
136
208
|
throw new Error(`${verb} is no Tool; house find_command '{"query":"${verb}"}' finds Commands`);
|
|
137
209
|
return [...(tool.description === undefined ? [] : [tool.description]), JSON.stringify(tool.inputSchema)].join('\n');
|
|
138
210
|
}
|
|
139
|
-
const
|
|
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 });
|
|
211
|
+
const parsed = argumentsOf(argument);
|
|
212
|
+
return verb === 'upload' ? upload(parsed) : called(verb, parsed);
|
|
213
|
+
}
|
|
214
|
+
async function called(name, args) {
|
|
215
|
+
const result = await mcp('tools/call', { name, arguments: args });
|
|
151
216
|
const text = result.content.map((content) => content.text).join('\n');
|
|
152
217
|
if (result.isError === true)
|
|
153
218
|
throw new Error(text.replace(/\n+$/, ''));
|
|
154
219
|
return text;
|
|
155
220
|
}
|
|
156
221
|
const argv = process.argv.slice(2);
|
|
157
|
-
|
|
222
|
+
const named = argv.findIndex((arg) => !arg.startsWith('-'));
|
|
223
|
+
const rest = argv.filter((_arg, index) => index !== named);
|
|
224
|
+
(argv[named] === 'push' ? push(rest) : argv[named] === 'fetch' ? fetched(rest) : house(argv)).then((text) => {
|
|
158
225
|
process.stdout.write(`${text}\n`);
|
|
226
|
+
if (argv[0] === 'shell')
|
|
227
|
+
process.exitCode = Number(/^exit: (\d+)(?:\n|$)/.exec(text)?.[1] ?? 0);
|
|
159
228
|
}, (error) => {
|
|
160
229
|
process.stderr.write(`house: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
161
230
|
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,19 +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';
|
|
4
7
|
import { logout } from './logout.js';
|
|
5
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
|
+
]);
|
|
6
39
|
const [command, ...argv] = process.argv.slice(2);
|
|
7
40
|
setGlobalProxyFromEnv();
|
|
8
41
|
async function run() {
|
|
9
42
|
if (command === 'login')
|
|
10
43
|
return login(argv);
|
|
11
|
-
if (command === '
|
|
12
|
-
return
|
|
13
|
-
if (command === '
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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);
|
|
17
65
|
}
|
|
18
66
|
run().catch((error) => {
|
|
19
67
|
process.stderr.write(`kit: ${error instanceof Error ? error.message : String(error)}\n`);
|
package/dist/login.js
CHANGED
|
@@ -1,55 +1,25 @@
|
|
|
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';
|
|
5
|
+
import { post, retrying } from './api.js';
|
|
6
|
+
import { placeAppGit } from './app-git.js';
|
|
7
|
+
import { writeCodexRule } from './clis.js';
|
|
7
8
|
import { forgetOwnAgent, readDisconnected, readEnrolment, readOwnAgent, writeEnrolment, writeOwnAgent } from './home.js';
|
|
8
9
|
import { callHouse, rpc } from './mcp.js';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
});
|
|
10
|
+
import { selectRelay } from './relay.js';
|
|
11
|
+
import { startService } from './service.js';
|
|
12
|
+
import { placeSkillSet } from './skills.js';
|
|
13
|
+
export const DEFAULT_HOUSE = 'https://agents.house';
|
|
14
|
+
const OPENER = process.platform === 'darwin' ? 'open' : 'xdg-open';
|
|
15
|
+
// Polling every two seconds brings the User's confirmation to the waiting Kit moments after they give it.
|
|
16
|
+
const POLL_INTERVAL_MS = 2000;
|
|
17
|
+
function open(link) {
|
|
18
|
+
spawn(OPENER, [link], { detached: true, stdio: 'ignore' })
|
|
19
|
+
.on('error', () => undefined)
|
|
20
|
+
.unref();
|
|
51
21
|
}
|
|
52
|
-
async function accepted(house, credential) {
|
|
22
|
+
export async function accepted(house, credential) {
|
|
53
23
|
const checked = await callHouse(house, credential, rpc('tools/list', {}));
|
|
54
24
|
if (checked.status === 200)
|
|
55
25
|
return true;
|
|
@@ -57,17 +27,20 @@ async function accepted(house, credential) {
|
|
|
57
27
|
return false;
|
|
58
28
|
throw new Error(`House answered ${checked.status} when Kit checked this computer's own agent's connection: ${checked.text}`);
|
|
59
29
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
30
|
+
const USAGE = `usage: kit login [--house <origin>] [--environment <id>] [--rooms <ref>[,<ref>...] | --no-private]
|
|
31
|
+
kit login [--house <origin>] --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,80 @@ 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
|
+
await writeCodexRule().catch((error) => process.stderr.write(`kit: ${error.message}\n`));
|
|
106
|
+
await writeEnrolment({
|
|
107
|
+
house,
|
|
108
|
+
...(relay === undefined ? {} : { relay }),
|
|
109
|
+
environment: exchanged.environment,
|
|
110
|
+
credential: exchanged.credential,
|
|
111
|
+
});
|
|
112
|
+
process.stdout.write(`Environment ${exchanged.environment} is connected to ${house}.\n`);
|
|
113
|
+
if (exchanged.headless_credential !== undefined) {
|
|
114
|
+
await writeOwnAgent({ house, user: exchanged.user, credential: exchanged.headless_credential });
|
|
115
|
+
}
|
|
116
|
+
else if (held && ownAgent !== null && ownAgent.user !== exchanged.user) {
|
|
117
|
+
await forgetOwnAgent();
|
|
118
|
+
process.stdout.write("This computer's own agent was another User's; run kit login again to connect it to you.\n");
|
|
115
119
|
}
|
|
116
|
-
|
|
120
|
+
await placeAppGit(ownAgent, await readOwnAgent());
|
|
117
121
|
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.');
|
|
122
|
+
startService();
|
|
132
123
|
}
|
|
133
|
-
|
|
134
|
-
|
|
124
|
+
catch (error) {
|
|
125
|
+
process.stderr.write(`kit: ${error.message}\n`);
|
|
135
126
|
}
|
|
136
127
|
}
|
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
|
}
|