@agentshouse/kit 0.2.1-c5d36e97b0fea → 0.2.1-c62e8a5e845ed
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 +23 -23
- package/dist/agents.js +5 -1
- package/dist/api.js +6 -2
- package/dist/bootstrap.json +4 -4
- package/dist/clis.js +41 -9
- package/dist/codex.js +61 -0
- package/dist/conversations.js +9 -5
- package/dist/copies.js +18 -18
- package/dist/end.js +17 -3
- package/dist/enrol-main.js +7 -1
- package/dist/home.js +41 -3
- package/dist/house-main.js +76 -36
- package/dist/instructions.js +5 -4
- package/dist/kit-main.js +53 -8
- package/dist/login.js +82 -16
- package/dist/parts.js +34 -16
- package/dist/placement.js +48 -0
- package/dist/relay.js +12 -2
- package/dist/resident.js +13 -4
- package/dist/service-main.js +9 -0
- package/dist/service.js +33 -0
- package/dist/stream.js +9 -4
- package/dist/update.js +27 -6
- package/dist/wire.js +6 -0
- package/package.json +2 -2
package/dist/house-main.js
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
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 {
|
|
5
|
+
import { extname, join } from 'node:path';
|
|
6
6
|
import { HOUSE_REF } from './git.js';
|
|
7
|
-
import { kitHome, readOwnAgent } from './home.js';
|
|
7
|
+
import { kitHome, readEnrolment, readOwnAgent } from './home.js';
|
|
8
8
|
import { callHouse, rpc, UNREACHABLE } from './mcp.js';
|
|
9
9
|
import { refusalOf } from './refusals.js';
|
|
10
10
|
import { relayed } from './relay.js';
|
|
11
|
-
import { parse } from 'yaml';
|
|
11
|
+
import { parse, stringify } from 'yaml';
|
|
12
12
|
const USAGE = "usage: house <tool> ['<arguments as JSON>']";
|
|
13
13
|
const PUSH_USAGE = 'usage: house push [commit] [--owner]';
|
|
14
14
|
const PUSH = "push [commit]: sends the Local copy's committed changes to House";
|
|
@@ -21,6 +21,33 @@ const REVOKED = 'this conversation no longer has House access; nothing to do fro
|
|
|
21
21
|
const UNCONNECTED = "this computer's own agent has no House connection; run kit login";
|
|
22
22
|
const DISCONNECTED = "House no longer accepts this computer's own agent; run kit login";
|
|
23
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
|
+
]);
|
|
24
51
|
function refused(path, status, text) {
|
|
25
52
|
const refusal = refusalOf(text);
|
|
26
53
|
if (refusal !== null)
|
|
@@ -56,6 +83,7 @@ async function direct(message) {
|
|
|
56
83
|
const ownAgent = await readOwnAgent();
|
|
57
84
|
if (ownAgent === null)
|
|
58
85
|
throw new Error(UNCONNECTED);
|
|
86
|
+
await readEnrolment();
|
|
59
87
|
setGlobalProxyFromEnv();
|
|
60
88
|
const answer = await callHouse(ownAgent.house, ownAgent.credential, message).catch(() => {
|
|
61
89
|
throw new Error(UNREACHABLE);
|
|
@@ -97,28 +125,43 @@ async function sent(url, bytes, operation) {
|
|
|
97
125
|
return text;
|
|
98
126
|
throw new Error(refused(url, answer.status, text));
|
|
99
127
|
}
|
|
100
|
-
async function upload(
|
|
101
|
-
if (typeof
|
|
102
|
-
throw new Error(
|
|
103
|
-
const bytes = await localFile(
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
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,
|
|
107
135
|
bytes: bytes.length,
|
|
108
136
|
sha256: createHash('sha256').update(bytes).digest('hex'),
|
|
109
|
-
|
|
137
|
+
...(mediaType === undefined ? {} : { media_type: mediaType }),
|
|
138
|
+
});
|
|
139
|
+
const declared = parse(answer);
|
|
110
140
|
if (declared.upload === undefined)
|
|
111
|
-
return
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
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;
|
|
116
159
|
}
|
|
117
160
|
async function push(args) {
|
|
118
|
-
|
|
161
|
+
const { flags, positionals: [commit = 'HEAD'] } = accepted(args, ['--help', '--owner'], 1, PUSH_USAGE);
|
|
162
|
+
if (flags.has('--help'))
|
|
119
163
|
return PUSH_USAGE;
|
|
120
|
-
const owner =
|
|
121
|
-
const commit = args.find((arg) => arg !== '--owner') ?? 'HEAD';
|
|
164
|
+
const owner = flags.has('--owner');
|
|
122
165
|
if (owner && socketPath !== undefined)
|
|
123
166
|
throw new Error('--owner is not for Agent conversations; run house push without it');
|
|
124
167
|
if (!owner && socketPath === undefined)
|
|
@@ -129,7 +172,7 @@ async function push(args) {
|
|
|
129
172
|
return pushed.text;
|
|
130
173
|
}
|
|
131
174
|
async function fetched(args) {
|
|
132
|
-
if (args.
|
|
175
|
+
if (accepted(args, ['--help'], 0, FETCH_USAGE).flags.has('--help'))
|
|
133
176
|
return FETCH_USAGE;
|
|
134
177
|
const answer = JSON.parse(await bridged('/git/fetch', {}, undefined, socketPath ?? join(kitHome(), 'owner.sock')));
|
|
135
178
|
if (answer.refused)
|
|
@@ -150,28 +193,23 @@ function argumentsOf(argument) {
|
|
|
150
193
|
throw new Error(ARGUMENTS);
|
|
151
194
|
return parsed;
|
|
152
195
|
}
|
|
153
|
-
async function house(
|
|
154
|
-
|
|
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') {
|
|
155
203
|
return [USAGE, 'help', PUSH, FETCH, ...(await tools()).map((tool) => (tool.description === undefined ? tool.name : `${tool.name}: ${tool.description}`))].join('\n');
|
|
156
204
|
}
|
|
157
|
-
if (
|
|
205
|
+
if (flags.has('--help')) {
|
|
158
206
|
const tool = (await tools()).find((listed) => listed.name === verb);
|
|
159
207
|
if (tool === undefined)
|
|
160
208
|
throw new Error(`${verb} is no Tool; house find_command '{"query":"${verb}"}' finds Commands`);
|
|
161
209
|
return [...(tool.description === undefined ? [] : [tool.description]), JSON.stringify(tool.inputSchema)].join('\n');
|
|
162
210
|
}
|
|
163
|
-
const
|
|
164
|
-
|
|
165
|
-
return JSON.stringify({ attachment: await upload(args.path, args.room_ref, 'upload needs "path", a local file') });
|
|
166
|
-
}
|
|
167
|
-
if (verb === 'append_record' && Array.isArray(args.attachments)) {
|
|
168
|
-
const attachments = [];
|
|
169
|
-
for (const path of args.attachments) {
|
|
170
|
-
attachments.push(await upload(path, args.room_ref, 'each attachments entry is the path of a local file'));
|
|
171
|
-
}
|
|
172
|
-
args.attachments = attachments;
|
|
173
|
-
}
|
|
174
|
-
return called(verb, args);
|
|
211
|
+
const parsed = argumentsOf(argument);
|
|
212
|
+
return verb === 'upload' ? upload(parsed) : called(verb, parsed);
|
|
175
213
|
}
|
|
176
214
|
async function called(name, args) {
|
|
177
215
|
const result = await mcp('tools/call', { name, arguments: args });
|
|
@@ -181,7 +219,9 @@ async function called(name, args) {
|
|
|
181
219
|
return text;
|
|
182
220
|
}
|
|
183
221
|
const argv = process.argv.slice(2);
|
|
184
|
-
|
|
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) => {
|
|
185
225
|
process.stdout.write(`${text}\n`);
|
|
186
226
|
if (argv[0] === 'shell')
|
|
187
227
|
process.exitCode = Number(/^exit: (\d+)(?:\n|$)/.exec(text)?.[1] ?? 0);
|
package/dist/instructions.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { HOUSE_REF } from './git.js';
|
|
2
2
|
import { HOW_WE_WORK } from './skills.js';
|
|
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`.";
|
|
6
7
|
const COPIES_LINE = `House Local copies; before work run \`house fetch\` and rebase onto \`${HOUSE_REF}\`; after it commit, then \`house push\`:`;
|
|
7
8
|
const UNREADABLE = /^(?:\S+: )?(?:path_not_found|room_not_found|operation_denied)\b/;
|
|
8
9
|
const FAILED = /^exit: [1-9]\d*$/;
|
|
@@ -30,6 +31,6 @@ async function howWeWork(bridge) {
|
|
|
30
31
|
return document.replace(/\n$/, '');
|
|
31
32
|
}
|
|
32
33
|
export async function instructions(bridge, base, copies) {
|
|
33
|
-
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])];
|
|
34
35
|
return [lines.join('\n'), base, await howWeWork(bridge)].filter((part) => part !== '').join('\n\n');
|
|
35
36
|
}
|
package/dist/kit-main.js
CHANGED
|
@@ -1,22 +1,67 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { setGlobalProxyFromEnv } from 'node:http';
|
|
3
|
+
import { parseArgs } from 'node:util';
|
|
3
4
|
import { answerGitCredential } from './app-git.js';
|
|
5
|
+
import { codex } from './codex.js';
|
|
4
6
|
import { login } from './login.js';
|
|
5
7
|
import { logout } from './logout.js';
|
|
6
8
|
import { resident } from './resident.js';
|
|
9
|
+
const USAGE = 'usage: kit <login|logout|resident|codex>\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
|
+
]);
|
|
7
39
|
const [command, ...argv] = process.argv.slice(2);
|
|
8
40
|
setGlobalProxyFromEnv();
|
|
9
41
|
async function run() {
|
|
10
42
|
if (command === 'login')
|
|
11
43
|
return login(argv);
|
|
12
|
-
if (command === '
|
|
13
|
-
return
|
|
14
|
-
if (command === '
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return
|
|
18
|
-
|
|
19
|
-
|
|
44
|
+
if (command === 'codex')
|
|
45
|
+
return codex(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);
|
|
20
65
|
}
|
|
21
66
|
run().catch((error) => {
|
|
22
67
|
process.stderr.write(`kit: ${error instanceof Error ? error.message : String(error)}\n`);
|
package/dist/login.js
CHANGED
|
@@ -4,9 +4,13 @@ import { hostname } from 'node:os';
|
|
|
4
4
|
import { parseArgs } from 'node:util';
|
|
5
5
|
import { post, retrying } from './api.js';
|
|
6
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
|
+
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';
|
|
10
14
|
const OPENER = process.platform === 'darwin' ? 'open' : 'xdg-open';
|
|
11
15
|
// Polling every two seconds brings the User's confirmation to the waiting Kit moments after they give it.
|
|
12
16
|
const POLL_INTERVAL_MS = 2000;
|
|
@@ -15,7 +19,7 @@ function open(link) {
|
|
|
15
19
|
.on('error', () => undefined)
|
|
16
20
|
.unref();
|
|
17
21
|
}
|
|
18
|
-
async function accepted(house, credential) {
|
|
22
|
+
export async function accepted(house, credential) {
|
|
19
23
|
const checked = await callHouse(house, credential, rpc('tools/list', {}));
|
|
20
24
|
if (checked.status === 200)
|
|
21
25
|
return true;
|
|
@@ -23,39 +27,101 @@ async function accepted(house, credential) {
|
|
|
23
27
|
return false;
|
|
24
28
|
throw new Error(`House answered ${checked.status} when Kit checked this computer's own agent's connection: ${checked.text}`);
|
|
25
29
|
}
|
|
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' } } : {};
|
|
44
|
+
}
|
|
26
45
|
export async function login(argv) {
|
|
27
46
|
const { values } = parseArgs({
|
|
28
47
|
args: argv,
|
|
29
48
|
options: {
|
|
30
49
|
house: { type: 'string' },
|
|
31
50
|
environment: { type: 'string' },
|
|
51
|
+
rooms: { type: 'string' },
|
|
52
|
+
'no-private': { type: 'boolean', default: false },
|
|
53
|
+
code: { type: 'string' },
|
|
54
|
+
help: { type: 'boolean', default: false },
|
|
32
55
|
},
|
|
33
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']);
|
|
34
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);
|
|
35
74
|
const house = values.house ?? enrolled?.house ?? DEFAULT_HOUSE;
|
|
36
75
|
const replaces = process.env.HOUSE_KIT_REPLACES;
|
|
37
76
|
const environment = replaces === undefined ? (values.environment ?? (enrolled?.house === house ? enrolled.environment : undefined)) : undefined;
|
|
38
77
|
const ownAgent = await readOwnAgent();
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
+
});
|
|
52
112
|
process.stdout.write(`Environment ${exchanged.environment} is connected to ${house}.\n`);
|
|
53
113
|
if (exchanged.headless_credential !== undefined) {
|
|
54
114
|
await writeOwnAgent({ house, user: exchanged.user, credential: exchanged.headless_credential });
|
|
55
115
|
}
|
|
56
|
-
else if (held && ownAgent.user !== exchanged.user) {
|
|
116
|
+
else if (held && ownAgent !== null && ownAgent.user !== exchanged.user) {
|
|
57
117
|
await forgetOwnAgent();
|
|
58
118
|
process.stdout.write("This computer's own agent was another User's; run kit login again to connect it to you.\n");
|
|
59
119
|
}
|
|
60
120
|
await placeAppGit(ownAgent, await readOwnAgent());
|
|
121
|
+
try {
|
|
122
|
+
startService();
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
process.stderr.write(`kit: ${error.message}\n`);
|
|
126
|
+
}
|
|
61
127
|
}
|
package/dist/parts.js
CHANGED
|
@@ -2,7 +2,10 @@ export class Parts {
|
|
|
2
2
|
parts = [];
|
|
3
3
|
context = null;
|
|
4
4
|
emit;
|
|
5
|
+
made = [];
|
|
6
|
+
events = 0;
|
|
5
7
|
writing = null;
|
|
8
|
+
counting = null;
|
|
6
9
|
planned = null;
|
|
7
10
|
constructor(emit) {
|
|
8
11
|
this.emit = emit;
|
|
@@ -10,32 +13,34 @@ export class Parts {
|
|
|
10
13
|
write(type, id, text) {
|
|
11
14
|
if (text === '')
|
|
12
15
|
return;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
part.text += text;
|
|
17
|
-
this.emit({ op: 'append', index: last, text });
|
|
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 });
|
|
18
19
|
return;
|
|
19
20
|
}
|
|
20
|
-
this.start({ type, text });
|
|
21
|
-
this.writing = { type, id };
|
|
21
|
+
this.writing = { type, id, index: this.start({ type, text }) };
|
|
22
22
|
}
|
|
23
23
|
command() {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
if (part?.type !== 'commands') {
|
|
27
|
-
this.start({ type: 'commands', count: 1 });
|
|
24
|
+
if (this.counting === null) {
|
|
25
|
+
this.counting = this.start({ type: 'commands', count: 1 });
|
|
28
26
|
return;
|
|
29
27
|
}
|
|
28
|
+
const part = this.parts[this.counting];
|
|
30
29
|
part.count++;
|
|
31
|
-
this.emit({ op: 'count', index:
|
|
30
|
+
this.emit({ op: 'count', index: this.counting, count: part.count });
|
|
32
31
|
}
|
|
33
32
|
start(part) {
|
|
34
33
|
this.writing = null;
|
|
35
|
-
this.
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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);
|
|
39
44
|
}
|
|
40
45
|
done(index, result) {
|
|
41
46
|
const part = this.parts[index];
|
|
@@ -55,10 +60,23 @@ export class Parts {
|
|
|
55
60
|
this.context = context;
|
|
56
61
|
this.emit({ op: 'context', ...context });
|
|
57
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
|
+
}
|
|
58
69
|
operations() {
|
|
59
70
|
return [
|
|
60
71
|
...this.parts.map((part, index) => ({ op: 'start', index, part })),
|
|
61
72
|
...(this.context === null ? [] : [{ op: 'context', ...this.context }]),
|
|
62
73
|
];
|
|
63
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
|
+
}
|
|
64
82
|
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { run } from './clis.js';
|
|
4
|
+
import { kitHome } from './home.js';
|
|
5
|
+
import { relayOrigin } from './relay.js';
|
|
6
|
+
export function service() {
|
|
7
|
+
if (process.platform !== 'linux' || !process.env.INVOCATION_ID)
|
|
8
|
+
return null;
|
|
9
|
+
return process.env.MANAGERPID ? 'user' : 'system';
|
|
10
|
+
}
|
|
11
|
+
export function throughSudo() {
|
|
12
|
+
return service() === 'system' && process.getuid() !== 0;
|
|
13
|
+
}
|
|
14
|
+
export async function updatesItself() {
|
|
15
|
+
if (service() === null)
|
|
16
|
+
return false;
|
|
17
|
+
if (!throughSudo())
|
|
18
|
+
return true;
|
|
19
|
+
// sudo answers at once, so ten seconds only bounds a stuck sudo.
|
|
20
|
+
return (await run('sudo', ['-n', 'true'], 10_000)).status === 0;
|
|
21
|
+
}
|
|
22
|
+
function installed() {
|
|
23
|
+
try {
|
|
24
|
+
return readFileSync(join(kitHome(), 'placement'), 'utf8').trim();
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
if (error.code === 'ENOENT')
|
|
28
|
+
return null;
|
|
29
|
+
throw error;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function entries(house) {
|
|
33
|
+
const host = new URL(house).host;
|
|
34
|
+
const relay = relayOrigin();
|
|
35
|
+
if (relay === undefined)
|
|
36
|
+
return [`curl -fsSL ${host}/kit | sh`, `irm ${host}/kit.ps1 | iex`];
|
|
37
|
+
const entry = `${relay}/${host}/kit`;
|
|
38
|
+
return [`curl -fsSL ${entry} | HOUSE_KIT_RELAY=${relay} sh`, `$env:HOUSE_KIT_RELAY='${relay}'; irm ${entry}.ps1 | iex`];
|
|
39
|
+
}
|
|
40
|
+
export function installCommand(house) {
|
|
41
|
+
const [shell, windows] = entries(house);
|
|
42
|
+
const placement = installed();
|
|
43
|
+
if (placement === 'native')
|
|
44
|
+
return shell;
|
|
45
|
+
if (placement === 'server')
|
|
46
|
+
return `${shell} -s -- --linux`;
|
|
47
|
+
return `${shell} -s -- --container, or ${windows} on Windows`;
|
|
48
|
+
}
|
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
|
+
export 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:')
|
package/dist/resident.js
CHANGED
|
@@ -7,9 +7,10 @@ import { fileURLToPath } from 'node:url';
|
|
|
7
7
|
import { Agents } from './agents.js';
|
|
8
8
|
import { house } from './api.js';
|
|
9
9
|
import { received } from './bridge.js';
|
|
10
|
-
import { Conversations } from './conversations.js';
|
|
10
|
+
import { CONVERSATION_INPUTS, Conversations } from './conversations.js';
|
|
11
11
|
import { LocalCopies } from './copies.js';
|
|
12
|
-
import {
|
|
12
|
+
import { restart } from './end.js';
|
|
13
|
+
import { agentBase, enrolled, forgetRestart, kitHome, restartAsked } from './home.js';
|
|
13
14
|
import { killDescendants } from './scope.js';
|
|
14
15
|
import { quoted } from './shell.js';
|
|
15
16
|
import { SignIns } from './sign-in.js';
|
|
@@ -73,6 +74,7 @@ function connected() {
|
|
|
73
74
|
}
|
|
74
75
|
export async function resident() {
|
|
75
76
|
await connected();
|
|
77
|
+
await forgetRestart();
|
|
76
78
|
watch(kitHome(), () => {
|
|
77
79
|
if (enrolled())
|
|
78
80
|
return;
|
|
@@ -95,6 +97,9 @@ export async function resident() {
|
|
|
95
97
|
if (!idle()) {
|
|
96
98
|
reported = false;
|
|
97
99
|
}
|
|
100
|
+
else if (restartAsked() && conversations.quiet()) {
|
|
101
|
+
restart('restarting for an updated CLI');
|
|
102
|
+
}
|
|
98
103
|
else if (!reported) {
|
|
99
104
|
reported = true;
|
|
100
105
|
logged(house.deliver('/kit/idle', {}, idle));
|
|
@@ -122,7 +127,7 @@ export async function resident() {
|
|
|
122
127
|
opened: () => {
|
|
123
128
|
conversations.opened();
|
|
124
129
|
changed();
|
|
125
|
-
logged(copies.
|
|
130
|
+
logged(copies.connected());
|
|
126
131
|
},
|
|
127
132
|
frame: (arrived) => {
|
|
128
133
|
if (arrived.type === 'watching')
|
|
@@ -135,8 +140,12 @@ export async function resident() {
|
|
|
135
140
|
signIns.start(arrived);
|
|
136
141
|
else if (arrived.kind === 'update')
|
|
137
142
|
updates.start(arrived);
|
|
138
|
-
else
|
|
143
|
+
else if (CONVERSATION_INPUTS.has(arrived.kind))
|
|
139
144
|
conversations.input(arrived);
|
|
145
|
+
else {
|
|
146
|
+
const refused = { refused: `This Kit does not know ${arrived.kind}; update the Kit` };
|
|
147
|
+
logged(house.deliver(`/kit/inputs/${arrived.input_id}/ack`, refused).finally(changed));
|
|
148
|
+
}
|
|
140
149
|
}
|
|
141
150
|
},
|
|
142
151
|
});
|