@agentshouse/kit 0.2.1-c2f0855c31ca3 → 0.2.1-c35516351ef49
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 +2 -1
- package/dist/agents.js +49 -2
- package/dist/bootstrap.json +4 -4
- package/dist/chatgpt.js +7 -1
- package/dist/conversations.js +20 -4
- package/dist/events.js +3 -0
- package/dist/home.js +3 -0
- package/dist/house-cli.js +291 -0
- package/dist/house-main.js +7 -289
- package/dist/kit-cli.js +68 -0
- package/dist/kit-main.js +8 -67
- package/dist/login.js +32 -7
- package/dist/skills.js +1 -0
- package/dist/stream.js +57 -11
- package/how-we-work.md +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -41,7 +41,8 @@ House as you and `git` clones and pushes your Apps at `<house>/app/` as you, unt
|
|
|
41
41
|
that connection on Connections. `house help` lists the Tools. Codex sessions started after a
|
|
42
42
|
login run a lone `house` command outside their sandbox. `kit logout` disconnects this
|
|
43
43
|
computer, stops House Kit and ends your own agent's connection, so `house` and `git` no
|
|
44
|
-
longer act as you here; a later `kit login` reconnects the same Environment
|
|
44
|
+
longer act as you here; a later `kit login` reconnects the same Environment, or connects
|
|
45
|
+
this computer as a new one when House no longer holds it.
|
|
45
46
|
In a container you do not control, such as ChatGPT's, `npm i -g @agentshouse/kit` and `kit chatgpt --key <key>` with a key made on Connections let `house <tool>` act as you, starting and configuring nothing else.
|
|
46
47
|
|
|
47
48
|
`kit resident` keeps the Environment connected and, as it connects, copies the text of each Room
|
package/dist/agents.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { client } from '@agentclientprotocol/sdk';
|
|
2
2
|
import { readFile, realpath } from 'node:fs/promises';
|
|
3
|
+
import { setTimeout as delay } from 'node:timers/promises';
|
|
3
4
|
import { startAdapter } from './acp.js';
|
|
4
5
|
import { CLIS, KIT_VERSION, below, installAdapter, installCli, locate, run, versionOf } from './clis.js';
|
|
5
6
|
import { agentBase, kitHome } from './home.js';
|
|
@@ -7,6 +8,8 @@ import { updatesItself } from './placement.js';
|
|
|
7
8
|
import { killTree } from './scope.js';
|
|
8
9
|
import { holdTranscription, transcriptionReport } from './transcription.js';
|
|
9
10
|
import { KIT_WIRE } from './wire.js';
|
|
11
|
+
// Two quiet seconds let a fresh conversation start before background model discovery competes for its CPU.
|
|
12
|
+
const MODEL_PROBE_QUIET_MS = 2_000;
|
|
10
13
|
const SIGNED_OUT = { signed_in: false, models: [], modes: [] };
|
|
11
14
|
function select(options, category) {
|
|
12
15
|
const option = options.find((candidate) => candidate.category === category);
|
|
@@ -24,6 +27,22 @@ function causeOf(error) {
|
|
|
24
27
|
function logged(error) {
|
|
25
28
|
process.stderr.write(`kit: ${causeOf(error)}\n`);
|
|
26
29
|
}
|
|
30
|
+
const LAPTOP_CHASSIS = new Set(['8', '9', '10', '14', '30', '31', '32']);
|
|
31
|
+
const DESKTOP_CHASSIS = new Set(['3', '4', '5', '6', '7', '15', '16']);
|
|
32
|
+
const SERVER_CHASSIS = new Set(['17', '18', '19', '20', '21', '22', '23', '24']);
|
|
33
|
+
export function chassisForm(value) {
|
|
34
|
+
const chassis = value.trim();
|
|
35
|
+
if (LAPTOP_CHASSIS.has(chassis))
|
|
36
|
+
return 'laptop';
|
|
37
|
+
if (DESKTOP_CHASSIS.has(chassis))
|
|
38
|
+
return 'desktop';
|
|
39
|
+
if (SERVER_CHASSIS.has(chassis))
|
|
40
|
+
return 'server';
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
export function hostVm(version) {
|
|
44
|
+
return /docker desktop|microsoft|wsl|linuxkit/i.test(version);
|
|
45
|
+
}
|
|
27
46
|
async function models(kind, adapter, known) {
|
|
28
47
|
const agent = adapter.connection.agent;
|
|
29
48
|
const opened = await agent.request('session/new', { cwd: kitHome(), mcpServers: [] });
|
|
@@ -122,6 +141,22 @@ async function operatingSystem() {
|
|
|
122
141
|
const release = await readFile('/etc/os-release', 'utf8');
|
|
123
142
|
return /^PRETTY_NAME="?([^"\n]*)"?$/m.exec(release)?.[1] ?? release;
|
|
124
143
|
}
|
|
144
|
+
async function hostForm() {
|
|
145
|
+
if (process.platform === 'darwin') {
|
|
146
|
+
const battery = await run('pmset', ['-g', 'batt'], 10_000);
|
|
147
|
+
return battery.status === 0 && battery.output.includes('InternalBattery') ? 'laptop' : 'desktop';
|
|
148
|
+
}
|
|
149
|
+
if (process.platform !== 'linux')
|
|
150
|
+
return undefined;
|
|
151
|
+
const [container, version, chassis] = await Promise.all([
|
|
152
|
+
readFile('/.dockerenv', 'utf8').then(() => true).catch(() => false),
|
|
153
|
+
readFile('/proc/version', 'utf8').catch(() => ''),
|
|
154
|
+
readFile('/sys/class/dmi/id/chassis_type', 'utf8').catch(() => ''),
|
|
155
|
+
]);
|
|
156
|
+
if (container && hostVm(version))
|
|
157
|
+
return undefined;
|
|
158
|
+
return chassisForm(chassis);
|
|
159
|
+
}
|
|
125
160
|
export class Agents {
|
|
126
161
|
desired = { agents: [], routes: [], transcribe: false };
|
|
127
162
|
house;
|
|
@@ -130,6 +165,7 @@ export class Agents {
|
|
|
130
165
|
installing = Promise.resolve();
|
|
131
166
|
readings = new Map();
|
|
132
167
|
reads = new Map();
|
|
168
|
+
starts = 0;
|
|
133
169
|
sending = Promise.resolve();
|
|
134
170
|
sent = null;
|
|
135
171
|
refreshing = 0;
|
|
@@ -172,6 +208,7 @@ export class Agents {
|
|
|
172
208
|
return reading.then(() => undefined);
|
|
173
209
|
}
|
|
174
210
|
cli(kind) {
|
|
211
|
+
this.starts += 1;
|
|
175
212
|
return this.queue(kind, async () => {
|
|
176
213
|
const resolved = await this.resolve(kind);
|
|
177
214
|
if (!('cli' in resolved)) {
|
|
@@ -185,7 +222,7 @@ export class Agents {
|
|
|
185
222
|
this.update(kind, { release, failure: null, signed_in: kept.signed_in, models: kept.models, modes: kept.modes });
|
|
186
223
|
}
|
|
187
224
|
const read = this.nextRead(kind);
|
|
188
|
-
|
|
225
|
+
this.quietOffer(kind, cli, kept)
|
|
189
226
|
.then((offered) => {
|
|
190
227
|
const current = this.readings.get(kind);
|
|
191
228
|
if (this.reads.get(kind) === read && current?.release === release)
|
|
@@ -272,11 +309,19 @@ export class Agents {
|
|
|
272
309
|
if (this.reads.get(kind) === current && !signal?.aborted)
|
|
273
310
|
this.readings.set(kind, reading);
|
|
274
311
|
}
|
|
312
|
+
async quietOffer(kind, cli, known) {
|
|
313
|
+
for (let seen = -1; seen !== this.starts;) {
|
|
314
|
+
seen = this.starts;
|
|
315
|
+
await delay(MODEL_PROBE_QUIET_MS);
|
|
316
|
+
}
|
|
317
|
+
return offer(kind, cli, known);
|
|
318
|
+
}
|
|
275
319
|
async load(kind) {
|
|
276
320
|
const known = this.readings.get(kind);
|
|
277
321
|
if (known !== undefined && known.failure === null && known.minimum === undefined)
|
|
278
322
|
return;
|
|
279
|
-
await this.examine(kind, SIGNED_OUT,
|
|
323
|
+
await this.examine(kind, SIGNED_OUT, (kind, cli, known) => this.quietOffer(kind, cli, known));
|
|
324
|
+
await this.report();
|
|
280
325
|
}
|
|
281
326
|
async send() {
|
|
282
327
|
const agents = this.desired.agents.flatMap((kind) => {
|
|
@@ -284,8 +329,10 @@ export class Agents {
|
|
|
284
329
|
return reading === undefined ? [] : [reported(kind, reading)];
|
|
285
330
|
});
|
|
286
331
|
const hostKey = await sshHostKey();
|
|
332
|
+
const form = await hostForm();
|
|
287
333
|
const body = {
|
|
288
334
|
os: await operatingSystem(),
|
|
335
|
+
...(form === undefined ? {} : { form }),
|
|
289
336
|
kit_version: KIT_VERSION,
|
|
290
337
|
wire: KIT_WIRE,
|
|
291
338
|
updates_itself: await updatesItself(),
|
package/dist/bootstrap.json
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 2,
|
|
3
|
-
"version": "0.2.1-
|
|
3
|
+
"version": "0.2.1-c35516351ef49",
|
|
4
4
|
"hosts": {
|
|
5
5
|
"macos": {
|
|
6
6
|
"asset": {
|
|
7
7
|
"name": "connect-linux.sh",
|
|
8
|
-
"url": "https://github.com/agentshouse/kit/releases/download/v0.2.1-
|
|
8
|
+
"url": "https://github.com/agentshouse/kit/releases/download/v0.2.1-c35516351ef49/connect-linux.sh"
|
|
9
9
|
}
|
|
10
10
|
},
|
|
11
11
|
"linux": {
|
|
12
12
|
"asset": {
|
|
13
13
|
"name": "connect-linux.sh",
|
|
14
|
-
"url": "https://github.com/agentshouse/kit/releases/download/v0.2.1-
|
|
14
|
+
"url": "https://github.com/agentshouse/kit/releases/download/v0.2.1-c35516351ef49/connect-linux.sh"
|
|
15
15
|
}
|
|
16
16
|
},
|
|
17
17
|
"windows": {
|
|
18
18
|
"asset": {
|
|
19
19
|
"name": "connect-windows.ps1",
|
|
20
|
-
"url": "https://github.com/agentshouse/kit/releases/download/v0.2.1-
|
|
20
|
+
"url": "https://github.com/agentshouse/kit/releases/download/v0.2.1-c35516351ef49/connect-windows.ps1"
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
}
|
package/dist/chatgpt.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { parseArgs } from 'node:util';
|
|
2
|
+
import { placeAppGit } from './app-git.js';
|
|
2
3
|
import { kitHome, readOwnAgent, writeOwnAgent } from './home.js';
|
|
3
4
|
import { accepted, DEFAULT_HOUSE } from './login.js';
|
|
4
5
|
const KEY_SOURCE = 'New key for a script on Connections';
|
|
@@ -17,10 +18,15 @@ export async function chatgpt(argv) {
|
|
|
17
18
|
}
|
|
18
19
|
if (values.key === undefined)
|
|
19
20
|
throw new Error(`pass --key with a key from ${KEY_SOURCE}`);
|
|
20
|
-
const
|
|
21
|
+
const before = await readOwnAgent();
|
|
22
|
+
const house = values.house ?? before?.house ?? DEFAULT_HOUSE;
|
|
21
23
|
if (!(await accepted(house, values.key)))
|
|
22
24
|
throw new Error(`${house} does not accept this key; pass one from ${KEY_SOURCE}`);
|
|
23
25
|
const relay = process.env.HOUSE_KIT_RELAY || undefined;
|
|
24
26
|
await writeOwnAgent({ house, ...(relay === undefined ? {} : { relay }), credential: values.key });
|
|
27
|
+
await placeAppGit(before, await readOwnAgent()).catch((error) => process.stderr.write(`kit: ${error.message}\n`));
|
|
28
|
+
if (before !== null && before.credential !== values.key) {
|
|
29
|
+
process.stdout.write('This replaced the key this Kit home held; give each session its own HOUSE_KIT_HOME to keep its own key.\n');
|
|
30
|
+
}
|
|
25
31
|
process.stdout.write(`house now calls ${house} as you, with the key kept in ${kitHome()}.\n`);
|
|
26
32
|
}
|
package/dist/conversations.js
CHANGED
|
@@ -6,7 +6,7 @@ import { unlessAborted } from './abort.js';
|
|
|
6
6
|
import { startAdapter } from './acp.js';
|
|
7
7
|
import { openBridge } from './bridge.js';
|
|
8
8
|
import { CLIS } from './clis.js';
|
|
9
|
-
import { readerFor } from './events.js';
|
|
9
|
+
import { answeredFailure, readerFor } from './events.js';
|
|
10
10
|
import { placeFiles, uploadBytes } from './files.js';
|
|
11
11
|
import { agentBase } from './home.js';
|
|
12
12
|
import { instructions } from './instructions.js';
|
|
@@ -17,6 +17,15 @@ import { createHowWeWork } from './skills.js';
|
|
|
17
17
|
import { transcribe } from './transcription.js';
|
|
18
18
|
import { workFor } from './work.js';
|
|
19
19
|
const KILLED = 'the conversation was killed';
|
|
20
|
+
const REFUSED = 'the CLI refused the prompt';
|
|
21
|
+
const EXIT_PLAN_MODE = {
|
|
22
|
+
parse(value) {
|
|
23
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
24
|
+
throw new Error('_x.ai/exit_plan_mode needs an object');
|
|
25
|
+
}
|
|
26
|
+
return value;
|
|
27
|
+
},
|
|
28
|
+
};
|
|
20
29
|
export const CONVERSATION_INPUTS = new Set(['open', 'message', 'interrupt', 'kill', 'option', 'answer']);
|
|
21
30
|
function causeOf(error) {
|
|
22
31
|
return error instanceof Error ? error.message : String(error);
|
|
@@ -348,7 +357,8 @@ export class Conversations {
|
|
|
348
357
|
reader.session = sessionId;
|
|
349
358
|
const app = client({ name: '@agentshouse/kit' })
|
|
350
359
|
.onRequest('session/request_permission', ({ params, signal }) => this.ask(conversation, 'session/request_permission', params, false, signal))
|
|
351
|
-
.onRequest('elicitation/create', ({ params, signal }) => this.ask(conversation, 'elicitation/create', params, asksSecret(params), signal))
|
|
360
|
+
.onRequest('elicitation/create', ({ params, signal }) => this.ask(conversation, 'elicitation/create', params, asksSecret(params), signal))
|
|
361
|
+
.onRequest('_x.ai/exit_plan_mode', EXIT_PLAN_MODE, ({ params, signal }) => this.ask(conversation, '_x.ai/exit_plan_mode', params, false, signal));
|
|
352
362
|
const cli = await unlessAborted(this.kit.agents.cli(route.kind), conversation.killed.signal);
|
|
353
363
|
const bridge = await openBridge(this.kit.house, this.kit.copies, conversation.id, conversation.killed.signal);
|
|
354
364
|
if (conversation.kills > 0) {
|
|
@@ -491,13 +501,15 @@ export class Conversations {
|
|
|
491
501
|
this.kit.changed();
|
|
492
502
|
return turn;
|
|
493
503
|
}
|
|
494
|
-
end(conversation, turn, failed) {
|
|
504
|
+
end(conversation, turn, failed, notice = null) {
|
|
495
505
|
if (turn.ended)
|
|
496
506
|
return;
|
|
497
507
|
if (conversation.turn === turn) {
|
|
498
508
|
for (const event of conversation.running?.reader.closeTurn() ?? [])
|
|
499
509
|
this.apply(conversation, turn, event);
|
|
500
510
|
}
|
|
511
|
+
if (notice !== null)
|
|
512
|
+
turn.parts.start({ type: 'marker', marker: 'retry', text: notice });
|
|
501
513
|
turn.ended = true;
|
|
502
514
|
conversation.open--;
|
|
503
515
|
if (conversation.turn === turn)
|
|
@@ -515,7 +527,11 @@ export class Conversations {
|
|
|
515
527
|
const running = conversation.running;
|
|
516
528
|
const turn = this.begin(conversation);
|
|
517
529
|
turn.prompted = true;
|
|
518
|
-
running.adapter.connection.agent.request('session/prompt', { sessionId: running.sessionId, prompt }).then(() =>
|
|
530
|
+
running.adapter.connection.agent.request('session/prompt', { sessionId: running.sessionId, prompt }).then((answer) => {
|
|
531
|
+
const notice = answeredFailure(answer);
|
|
532
|
+
const failed = notice ?? (answer.stopReason === 'refusal' ? REFUSED : null);
|
|
533
|
+
this.end(conversation, turn, failed === null ? null : { failed }, notice);
|
|
534
|
+
}, async (error) => {
|
|
519
535
|
if (running.adapter.connection.signal.aborted) {
|
|
520
536
|
this.end(conversation, turn, { failed: running.killed ? KILLED : await running.adapter.exited });
|
|
521
537
|
}
|
package/dist/events.js
CHANGED
|
@@ -512,6 +512,9 @@ class GrokReader extends Reader {
|
|
|
512
512
|
return [];
|
|
513
513
|
}
|
|
514
514
|
}
|
|
515
|
+
export function answeredFailure(answer) {
|
|
516
|
+
return answer._meta?.jetbrains?.air?.sessionFailure?.title ?? null;
|
|
517
|
+
}
|
|
515
518
|
export function readerFor(kind) {
|
|
516
519
|
if (kind === 'claude-agent-acp')
|
|
517
520
|
return new ClaudeReader();
|
package/dist/home.js
CHANGED
|
@@ -81,6 +81,9 @@ export async function writeEnrolment(enrolment) {
|
|
|
81
81
|
export function readDisconnected() {
|
|
82
82
|
return readHome(DISCONNECTED);
|
|
83
83
|
}
|
|
84
|
+
export function forgetDisconnected() {
|
|
85
|
+
return rm(join(kitHome(), DISCONNECTED), { force: true });
|
|
86
|
+
}
|
|
84
87
|
export async function forgetEnrolment({ house, environment }) {
|
|
85
88
|
await writeHome(DISCONNECTED, { house, environment });
|
|
86
89
|
await rm(join(kitHome(), ENROLMENT), { force: true });
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { request, setGlobalProxyFromEnv } from 'node:http';
|
|
4
|
+
import { basename, dirname, extname, join, resolve } from 'node:path';
|
|
5
|
+
import { verified } from './files.js';
|
|
6
|
+
import { HOUSE_REF } from './git.js';
|
|
7
|
+
import { kitHome, readOwnAgent } from './home.js';
|
|
8
|
+
import { callHouse, rpc, UNREACHABLE } from './mcp.js';
|
|
9
|
+
import { refusalOf } from './refusals.js';
|
|
10
|
+
import { relayed, selectRelay } from './relay.js';
|
|
11
|
+
import { parse, stringify } from 'yaml';
|
|
12
|
+
const USAGE = "usage: house <tool> ['<arguments as JSON>']";
|
|
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}`;
|
|
17
|
+
const DOWNLOAD_USAGE = `usage: house download '{"path":"/rooms/<handle>/<path>","file":"<local file>"}', adding "ref" for a revision`;
|
|
18
|
+
const DOWNLOAD = 'download: writes a binary file of a Room to the local file named by file';
|
|
19
|
+
const ARGUMENTS = `the arguments are one JSON object in single quotes, like house search '{"query":"invoice"}'`;
|
|
20
|
+
const CLOSED = "this conversation's House connection is closed; nothing to do from here";
|
|
21
|
+
const SANDBOXED = "your CLI's sandbox kept house from House; run house directly, not through another program";
|
|
22
|
+
const REVOKED = 'this conversation no longer has House access; nothing to do from here';
|
|
23
|
+
const UNCONNECTED = "this computer's own agent has no House connection; run kit login, or kit chatgpt --key <key> with a script key";
|
|
24
|
+
const DISCONNECTED = "House no longer accepts this computer's own agent; run kit login, or kit chatgpt --key <key> with a script key";
|
|
25
|
+
const UNCONFIRMED = 'with no result; a write may or may not have taken effect, so read before you repeat it';
|
|
26
|
+
const socketPath = process.env.HOUSE_BRIDGE;
|
|
27
|
+
const MEDIA_TYPES = new Map([
|
|
28
|
+
['avif', 'image/avif'],
|
|
29
|
+
['csv', 'text/csv'],
|
|
30
|
+
['docx', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'],
|
|
31
|
+
['gif', 'image/gif'],
|
|
32
|
+
['heic', 'image/heic'],
|
|
33
|
+
['html', 'text/html'],
|
|
34
|
+
['jpeg', 'image/jpeg'],
|
|
35
|
+
['jpg', 'image/jpeg'],
|
|
36
|
+
['json', 'application/json'],
|
|
37
|
+
['m4a', 'audio/mp4'],
|
|
38
|
+
['md', 'text/markdown'],
|
|
39
|
+
['mov', 'video/quicktime'],
|
|
40
|
+
['mp3', 'audio/mpeg'],
|
|
41
|
+
['mp4', 'video/mp4'],
|
|
42
|
+
['ogg', 'audio/ogg'],
|
|
43
|
+
['pdf', 'application/pdf'],
|
|
44
|
+
['png', 'image/png'],
|
|
45
|
+
['pptx', 'application/vnd.openxmlformats-officedocument.presentationml.presentation'],
|
|
46
|
+
['svg', 'image/svg+xml'],
|
|
47
|
+
['txt', 'text/plain'],
|
|
48
|
+
['wav', 'audio/wav'],
|
|
49
|
+
['webm', 'video/webm'],
|
|
50
|
+
['webp', 'image/webp'],
|
|
51
|
+
['xlsx', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'],
|
|
52
|
+
['zip', 'application/zip'],
|
|
53
|
+
]);
|
|
54
|
+
function refused(path, method, status, text, local) {
|
|
55
|
+
const refusal = refusalOf(text);
|
|
56
|
+
if (refusal !== null)
|
|
57
|
+
return refusal.text;
|
|
58
|
+
if (status === 401)
|
|
59
|
+
return REVOKED;
|
|
60
|
+
const act = method === 'GET' ? 'download' : 'upload';
|
|
61
|
+
if (URL.canParse(path))
|
|
62
|
+
return `the ${act} answered ${status}; ${act} the file again`;
|
|
63
|
+
if (status === 502 && local)
|
|
64
|
+
return text;
|
|
65
|
+
return path === '/' ? unconfirmed(status) : `${path} answered ${status}`;
|
|
66
|
+
}
|
|
67
|
+
function unconfirmed(status) {
|
|
68
|
+
return `House answered ${status} ${UNCONFIRMED}`;
|
|
69
|
+
}
|
|
70
|
+
function exchanged(path, method, body, headers = { 'content-type': 'application/json' }, to = socketPath) {
|
|
71
|
+
return new Promise((resolve, reject) => {
|
|
72
|
+
const sent = request({ socketPath: to, path, method, headers }, (answer) => {
|
|
73
|
+
const chunks = [];
|
|
74
|
+
answer.on('data', (chunk) => chunks.push(chunk));
|
|
75
|
+
answer.on('end', () => {
|
|
76
|
+
const bytes = Buffer.concat(chunks);
|
|
77
|
+
if (answer.statusCode === 200)
|
|
78
|
+
resolve(bytes);
|
|
79
|
+
else
|
|
80
|
+
reject(new Error(refused(path, method, answer.statusCode, bytes.toString('utf8'), answer.headers['content-type'] === undefined)));
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
sent.on('error', (error) => reject(new Error(error.code === 'EPERM' || error.code === 'EACCES' ? SANDBOXED : CLOSED)));
|
|
84
|
+
sent.end(body === undefined ? undefined : body instanceof Buffer ? body : JSON.stringify(body));
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
async function bridged(path, body, headers, to = socketPath) {
|
|
88
|
+
return (await exchanged(path, 'POST', body, headers, to)).toString('utf8');
|
|
89
|
+
}
|
|
90
|
+
async function direct(message) {
|
|
91
|
+
const ownAgent = await readOwnAgent();
|
|
92
|
+
if (ownAgent === null)
|
|
93
|
+
throw new Error(UNCONNECTED);
|
|
94
|
+
selectRelay(process.env.HOUSE_KIT_RELAY || ownAgent.relay);
|
|
95
|
+
setGlobalProxyFromEnv();
|
|
96
|
+
const answer = await callHouse(ownAgent.house, ownAgent.credential, message).catch(() => {
|
|
97
|
+
throw new Error(UNREACHABLE);
|
|
98
|
+
});
|
|
99
|
+
if (answer.status === 200)
|
|
100
|
+
return answer.text;
|
|
101
|
+
throw new Error(answer.status === 401 ? DISCONNECTED : (refusalOf(answer.text)?.text ?? unconfirmed(answer.status)));
|
|
102
|
+
}
|
|
103
|
+
async function mcp(method, params) {
|
|
104
|
+
const message = rpc(method, params);
|
|
105
|
+
const answer = JSON.parse(socketPath === undefined ? await direct(message) : await bridged('/', message));
|
|
106
|
+
if (answer.error !== undefined)
|
|
107
|
+
throw new Error(answer.error.message);
|
|
108
|
+
return answer.result;
|
|
109
|
+
}
|
|
110
|
+
async function tools() {
|
|
111
|
+
return (await mcp('tools/list', {})).tools;
|
|
112
|
+
}
|
|
113
|
+
async function localFile(path) {
|
|
114
|
+
try {
|
|
115
|
+
return await readFile(path);
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
throw new Error(error.code === 'EISDIR'
|
|
119
|
+
? `${path} is a folder; upload one file at a time`
|
|
120
|
+
: `${path} is not a readable file`);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
async function transferred(url, method, bytes, headers) {
|
|
124
|
+
if (socketPath !== undefined)
|
|
125
|
+
return exchanged(url, method, bytes, headers);
|
|
126
|
+
setGlobalProxyFromEnv();
|
|
127
|
+
const answer = await fetch(relayed(url), { method, ...(headers === undefined ? {} : { headers }), ...(bytes === undefined ? {} : { body: bytes }) }).catch(() => {
|
|
128
|
+
throw new Error(UNREACHABLE);
|
|
129
|
+
});
|
|
130
|
+
const received = Buffer.from(await answer.arrayBuffer());
|
|
131
|
+
if (answer.status === 200)
|
|
132
|
+
return received;
|
|
133
|
+
throw new Error(refused(url, method, answer.status, received.toString('utf8'), false));
|
|
134
|
+
}
|
|
135
|
+
async function sent(url, bytes, operation) {
|
|
136
|
+
const headers = { 'content-type': 'application/octet-stream', 'x-house-byte-operation': operation };
|
|
137
|
+
return (await transferred(url, 'POST', bytes, headers)).toString('utf8');
|
|
138
|
+
}
|
|
139
|
+
async function download(args) {
|
|
140
|
+
const { flags, positionals: [argument] } = accepted(args, ['--help'], 1, DOWNLOAD_USAGE);
|
|
141
|
+
if (flags.has('--help'))
|
|
142
|
+
return DOWNLOAD_USAGE;
|
|
143
|
+
const { file, ...selected } = argumentsOf(argument);
|
|
144
|
+
if (typeof file !== 'string' || file === '')
|
|
145
|
+
throw new Error('download needs "file", the local file to write');
|
|
146
|
+
const inspected = parse(await called('inspect', selected));
|
|
147
|
+
if (typeof inspected?.download !== 'string')
|
|
148
|
+
throw new Error(`${String(selected.path)} holds no binary file; shell reads its text`);
|
|
149
|
+
const bytes = verified(await transferred(inspected.download, 'GET'), String(inspected.sha256), String(selected.path));
|
|
150
|
+
const written = resolve(file);
|
|
151
|
+
await mkdir(dirname(written), { recursive: true });
|
|
152
|
+
await writeFile(written, bytes);
|
|
153
|
+
return written;
|
|
154
|
+
}
|
|
155
|
+
async function described(file) {
|
|
156
|
+
const bytes = await localFile(file);
|
|
157
|
+
const mediaType = MEDIA_TYPES.get(extname(file).slice(1).toLowerCase());
|
|
158
|
+
return {
|
|
159
|
+
bytes,
|
|
160
|
+
description: {
|
|
161
|
+
bytes: bytes.length,
|
|
162
|
+
sha256: createHash('sha256').update(bytes).digest('hex'),
|
|
163
|
+
...(mediaType === undefined ? {} : { media_type: mediaType }),
|
|
164
|
+
},
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
async function upload({ file, ...destination }) {
|
|
168
|
+
if (typeof file !== 'string' || file === '')
|
|
169
|
+
throw new Error('upload needs "file", a local file');
|
|
170
|
+
const { bytes, description } = await described(file);
|
|
171
|
+
const answer = await called('upload', { ...destination, ...description });
|
|
172
|
+
const declared = parse(answer);
|
|
173
|
+
if (declared.upload === undefined)
|
|
174
|
+
return answer;
|
|
175
|
+
const written = JSON.parse(await sent(declared.upload.url, bytes, declared.upload.operation));
|
|
176
|
+
return stringify(written, { lineWidth: 0 }).trimEnd();
|
|
177
|
+
}
|
|
178
|
+
async function appendRecord(args) {
|
|
179
|
+
const held = new Map();
|
|
180
|
+
const attachments = Array.isArray(args.attachments)
|
|
181
|
+
? await Promise.all(args.attachments.map(async (attachment) => {
|
|
182
|
+
if (typeof attachment !== 'string')
|
|
183
|
+
return attachment;
|
|
184
|
+
const { bytes, description } = await described(attachment);
|
|
185
|
+
held.set(description.sha256, bytes);
|
|
186
|
+
return { name: basename(attachment), ...description };
|
|
187
|
+
}))
|
|
188
|
+
: args.attachments;
|
|
189
|
+
const record = { ...args, attachments };
|
|
190
|
+
for (;;) {
|
|
191
|
+
const answer = await called('append_record', record);
|
|
192
|
+
const { upload } = parse(answer);
|
|
193
|
+
if (upload === undefined)
|
|
194
|
+
return answer;
|
|
195
|
+
for (const grant of upload)
|
|
196
|
+
await sent(grant.url, held.get(grant.sha256), grant.operation);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
function unexpected(argument, usage) {
|
|
200
|
+
return new Error(`unexpected argument ${argument}; ${usage}`);
|
|
201
|
+
}
|
|
202
|
+
function accepted(args, flags, positionals, usage) {
|
|
203
|
+
const given = { flags: new Set(), positionals: [] };
|
|
204
|
+
for (const arg of args) {
|
|
205
|
+
if (flags.includes(arg))
|
|
206
|
+
given.flags.add(arg);
|
|
207
|
+
else if (!arg.startsWith('-') && given.positionals.length < positionals)
|
|
208
|
+
given.positionals.push(arg);
|
|
209
|
+
else
|
|
210
|
+
throw unexpected(arg, usage);
|
|
211
|
+
}
|
|
212
|
+
return given;
|
|
213
|
+
}
|
|
214
|
+
async function push(args) {
|
|
215
|
+
const { flags, positionals: [commit = 'HEAD'] } = accepted(args, ['--help', '--owner'], 1, PUSH_USAGE);
|
|
216
|
+
if (flags.has('--help'))
|
|
217
|
+
return PUSH_USAGE;
|
|
218
|
+
const owner = flags.has('--owner');
|
|
219
|
+
if (owner && socketPath !== undefined)
|
|
220
|
+
throw new Error('--owner is not for Agent conversations; run house push without it');
|
|
221
|
+
if (!owner && socketPath === undefined)
|
|
222
|
+
throw new Error('outside an Agent conversation, house push needs --owner');
|
|
223
|
+
const pushed = JSON.parse(await bridged('/git/push', { cwd: process.cwd(), commit }, undefined, owner ? join(kitHome(), 'owner.sock') : socketPath));
|
|
224
|
+
if (pushed.refused)
|
|
225
|
+
throw new Error(pushed.text);
|
|
226
|
+
return pushed.text;
|
|
227
|
+
}
|
|
228
|
+
async function fetched(args) {
|
|
229
|
+
if (accepted(args, ['--help'], 0, FETCH_USAGE).flags.has('--help'))
|
|
230
|
+
return FETCH_USAGE;
|
|
231
|
+
const answer = JSON.parse(await bridged('/git/fetch', {}, undefined, socketPath ?? join(kitHome(), 'owner.sock')));
|
|
232
|
+
if (answer.refused)
|
|
233
|
+
throw new Error(answer.text);
|
|
234
|
+
return answer.text;
|
|
235
|
+
}
|
|
236
|
+
function argumentsOf(argument) {
|
|
237
|
+
if (argument === undefined)
|
|
238
|
+
return {};
|
|
239
|
+
let parsed;
|
|
240
|
+
try {
|
|
241
|
+
parsed = JSON.parse(argument);
|
|
242
|
+
}
|
|
243
|
+
catch {
|
|
244
|
+
throw new Error(ARGUMENTS);
|
|
245
|
+
}
|
|
246
|
+
if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed))
|
|
247
|
+
throw new Error(ARGUMENTS);
|
|
248
|
+
return parsed;
|
|
249
|
+
}
|
|
250
|
+
async function house(args) {
|
|
251
|
+
const { flags, positionals: [verb, argument] } = accepted(args, ['--help'], 2, USAGE);
|
|
252
|
+
if (verb === 'help' && argument !== undefined)
|
|
253
|
+
throw unexpected(argument, USAGE);
|
|
254
|
+
if (flags.has('--help') && argument !== undefined)
|
|
255
|
+
throw unexpected('--help', USAGE);
|
|
256
|
+
if (verb === undefined || verb === 'help') {
|
|
257
|
+
return [USAGE, 'help', PUSH, FETCH, DOWNLOAD, ...(await tools()).map((tool) => (tool.description === undefined ? tool.name : `${tool.name}: ${tool.description}`))].join('\n');
|
|
258
|
+
}
|
|
259
|
+
if (flags.has('--help')) {
|
|
260
|
+
const tool = (await tools()).find((listed) => listed.name === verb);
|
|
261
|
+
if (tool === undefined)
|
|
262
|
+
throw new Error(`${verb} is no Tool; house find_command '{"query":"${verb}"}' finds Commands`);
|
|
263
|
+
return [...(tool.description === undefined ? [] : [tool.description]), JSON.stringify(tool.inputSchema)].join('\n');
|
|
264
|
+
}
|
|
265
|
+
const parsed = argumentsOf(argument);
|
|
266
|
+
return verb === 'upload' ? upload(parsed) : verb === 'append_record' ? appendRecord(parsed) : called(verb, parsed);
|
|
267
|
+
}
|
|
268
|
+
async function called(name, args) {
|
|
269
|
+
const result = await mcp('tools/call', { name, arguments: args });
|
|
270
|
+
const text = result.content.map((content) => content.text).join('\n');
|
|
271
|
+
if (result.isError === true)
|
|
272
|
+
throw new Error(text.replace(/\n+$/, ''));
|
|
273
|
+
return text;
|
|
274
|
+
}
|
|
275
|
+
const argv = process.argv.slice(2);
|
|
276
|
+
const named = argv.findIndex((arg) => !arg.startsWith('-'));
|
|
277
|
+
const rest = argv.filter((_arg, index) => index !== named);
|
|
278
|
+
(argv[named] === 'push'
|
|
279
|
+
? push(rest)
|
|
280
|
+
: argv[named] === 'fetch'
|
|
281
|
+
? fetched(rest)
|
|
282
|
+
: argv[named] === 'download'
|
|
283
|
+
? download(rest)
|
|
284
|
+
: house(argv)).then((text) => {
|
|
285
|
+
process.stdout.write(`${text}\n`);
|
|
286
|
+
if (argv[0] === 'shell')
|
|
287
|
+
process.exitCode = Number(/^exit: (\d+)(?:\n|$)/.exec(text)?.[1] ?? 0);
|
|
288
|
+
}, (error) => {
|
|
289
|
+
process.stderr.write(`house: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
290
|
+
process.exitCode = 1;
|
|
291
|
+
});
|
package/dist/house-main.js
CHANGED
|
@@ -1,292 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import { verified } from './files.js';
|
|
7
|
-
import { HOUSE_REF } from './git.js';
|
|
8
|
-
import { kitHome, readOwnAgent } from './home.js';
|
|
9
|
-
import { callHouse, rpc, UNREACHABLE } from './mcp.js';
|
|
10
|
-
import { refusalOf } from './refusals.js';
|
|
11
|
-
import { relayed, selectRelay } from './relay.js';
|
|
12
|
-
import { parse, stringify } from 'yaml';
|
|
13
|
-
const USAGE = "usage: house <tool> ['<arguments as JSON>']";
|
|
14
|
-
const PUSH_USAGE = 'usage: house push [commit] [--owner]';
|
|
15
|
-
const PUSH = "push [commit]: sends the Local copy's committed changes to House";
|
|
16
|
-
const FETCH_USAGE = 'usage: house fetch';
|
|
17
|
-
const FETCH = `fetch: records House's changes on each Local copy's ${HOUSE_REF}`;
|
|
18
|
-
const DOWNLOAD_USAGE = `usage: house download '{"path":"/rooms/<handle>/<path>","file":"<local file>"}', adding "ref" for a revision`;
|
|
19
|
-
const DOWNLOAD = 'download: writes a binary file of a Room to the local file named by file';
|
|
20
|
-
const ARGUMENTS = `the arguments are one JSON object in single quotes, like house search '{"query":"invoice"}'`;
|
|
21
|
-
const CLOSED = "this conversation's House connection is closed; nothing to do from here";
|
|
22
|
-
const SANDBOXED = "your CLI's sandbox kept house from House; run house directly, not through another program";
|
|
23
|
-
const REVOKED = 'this conversation no longer has House access; nothing to do from here';
|
|
24
|
-
const UNCONNECTED = "this computer's own agent has no House connection; run kit login";
|
|
25
|
-
const DISCONNECTED = "House no longer accepts this computer's own agent; run kit login";
|
|
26
|
-
const UNCONFIRMED = 'with no result; a write may or may not have taken effect, so read before you repeat it';
|
|
27
|
-
const socketPath = process.env.HOUSE_BRIDGE;
|
|
28
|
-
const MEDIA_TYPES = new Map([
|
|
29
|
-
['avif', 'image/avif'],
|
|
30
|
-
['csv', 'text/csv'],
|
|
31
|
-
['docx', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'],
|
|
32
|
-
['gif', 'image/gif'],
|
|
33
|
-
['heic', 'image/heic'],
|
|
34
|
-
['html', 'text/html'],
|
|
35
|
-
['jpeg', 'image/jpeg'],
|
|
36
|
-
['jpg', 'image/jpeg'],
|
|
37
|
-
['json', 'application/json'],
|
|
38
|
-
['m4a', 'audio/mp4'],
|
|
39
|
-
['md', 'text/markdown'],
|
|
40
|
-
['mov', 'video/quicktime'],
|
|
41
|
-
['mp3', 'audio/mpeg'],
|
|
42
|
-
['mp4', 'video/mp4'],
|
|
43
|
-
['ogg', 'audio/ogg'],
|
|
44
|
-
['pdf', 'application/pdf'],
|
|
45
|
-
['png', 'image/png'],
|
|
46
|
-
['pptx', 'application/vnd.openxmlformats-officedocument.presentationml.presentation'],
|
|
47
|
-
['svg', 'image/svg+xml'],
|
|
48
|
-
['txt', 'text/plain'],
|
|
49
|
-
['wav', 'audio/wav'],
|
|
50
|
-
['webm', 'video/webm'],
|
|
51
|
-
['webp', 'image/webp'],
|
|
52
|
-
['xlsx', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'],
|
|
53
|
-
['zip', 'application/zip'],
|
|
54
|
-
]);
|
|
55
|
-
function refused(path, method, status, text, local) {
|
|
56
|
-
const refusal = refusalOf(text);
|
|
57
|
-
if (refusal !== null)
|
|
58
|
-
return refusal.text;
|
|
59
|
-
if (status === 401)
|
|
60
|
-
return REVOKED;
|
|
61
|
-
const act = method === 'GET' ? 'download' : 'upload';
|
|
62
|
-
if (URL.canParse(path))
|
|
63
|
-
return `the ${act} answered ${status}; ${act} the file again`;
|
|
64
|
-
if (status === 502 && local)
|
|
65
|
-
return text;
|
|
66
|
-
return path === '/' ? unconfirmed(status) : `${path} answered ${status}`;
|
|
67
|
-
}
|
|
68
|
-
function unconfirmed(status) {
|
|
69
|
-
return `House answered ${status} ${UNCONFIRMED}`;
|
|
70
|
-
}
|
|
71
|
-
function exchanged(path, method, body, headers = { 'content-type': 'application/json' }, to = socketPath) {
|
|
72
|
-
return new Promise((resolve, reject) => {
|
|
73
|
-
const sent = request({ socketPath: to, path, method, headers }, (answer) => {
|
|
74
|
-
const chunks = [];
|
|
75
|
-
answer.on('data', (chunk) => chunks.push(chunk));
|
|
76
|
-
answer.on('end', () => {
|
|
77
|
-
const bytes = Buffer.concat(chunks);
|
|
78
|
-
if (answer.statusCode === 200)
|
|
79
|
-
resolve(bytes);
|
|
80
|
-
else
|
|
81
|
-
reject(new Error(refused(path, method, answer.statusCode, bytes.toString('utf8'), answer.headers['content-type'] === undefined)));
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
sent.on('error', (error) => reject(new Error(error.code === 'EPERM' || error.code === 'EACCES' ? SANDBOXED : CLOSED)));
|
|
85
|
-
sent.end(body === undefined ? undefined : body instanceof Buffer ? body : JSON.stringify(body));
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
async function bridged(path, body, headers, to = socketPath) {
|
|
89
|
-
return (await exchanged(path, 'POST', body, headers, to)).toString('utf8');
|
|
90
|
-
}
|
|
91
|
-
async function direct(message) {
|
|
92
|
-
const ownAgent = await readOwnAgent();
|
|
93
|
-
if (ownAgent === null)
|
|
94
|
-
throw new Error(UNCONNECTED);
|
|
95
|
-
selectRelay(process.env.HOUSE_KIT_RELAY || ownAgent.relay);
|
|
96
|
-
setGlobalProxyFromEnv();
|
|
97
|
-
const answer = await callHouse(ownAgent.house, ownAgent.credential, message).catch(() => {
|
|
98
|
-
throw new Error(UNREACHABLE);
|
|
99
|
-
});
|
|
100
|
-
if (answer.status === 200)
|
|
101
|
-
return answer.text;
|
|
102
|
-
throw new Error(answer.status === 401 ? DISCONNECTED : (refusalOf(answer.text)?.text ?? unconfirmed(answer.status)));
|
|
103
|
-
}
|
|
104
|
-
async function mcp(method, params) {
|
|
105
|
-
const message = rpc(method, params);
|
|
106
|
-
const answer = JSON.parse(socketPath === undefined ? await direct(message) : await bridged('/', message));
|
|
107
|
-
if (answer.error !== undefined)
|
|
108
|
-
throw new Error(answer.error.message);
|
|
109
|
-
return answer.result;
|
|
110
|
-
}
|
|
111
|
-
async function tools() {
|
|
112
|
-
return (await mcp('tools/list', {})).tools;
|
|
113
|
-
}
|
|
114
|
-
async function localFile(path) {
|
|
115
|
-
try {
|
|
116
|
-
return await readFile(path);
|
|
117
|
-
}
|
|
118
|
-
catch (error) {
|
|
119
|
-
throw new Error(error.code === 'EISDIR'
|
|
120
|
-
? `${path} is a folder; upload one file at a time`
|
|
121
|
-
: `${path} is not a readable file`);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
async function transferred(url, method, bytes, headers) {
|
|
125
|
-
if (socketPath !== undefined)
|
|
126
|
-
return exchanged(url, method, bytes, headers);
|
|
127
|
-
setGlobalProxyFromEnv();
|
|
128
|
-
const answer = await fetch(relayed(url), { method, ...(headers === undefined ? {} : { headers }), ...(bytes === undefined ? {} : { body: bytes }) }).catch(() => {
|
|
129
|
-
throw new Error(UNREACHABLE);
|
|
130
|
-
});
|
|
131
|
-
const received = Buffer.from(await answer.arrayBuffer());
|
|
132
|
-
if (answer.status === 200)
|
|
133
|
-
return received;
|
|
134
|
-
throw new Error(refused(url, method, answer.status, received.toString('utf8'), false));
|
|
135
|
-
}
|
|
136
|
-
async function sent(url, bytes, operation) {
|
|
137
|
-
const headers = { 'content-type': 'application/octet-stream', 'x-house-byte-operation': operation };
|
|
138
|
-
return (await transferred(url, 'POST', bytes, headers)).toString('utf8');
|
|
139
|
-
}
|
|
140
|
-
async function download(args) {
|
|
141
|
-
const { flags, positionals: [argument] } = accepted(args, ['--help'], 1, DOWNLOAD_USAGE);
|
|
142
|
-
if (flags.has('--help'))
|
|
143
|
-
return DOWNLOAD_USAGE;
|
|
144
|
-
const { file, ...selected } = argumentsOf(argument);
|
|
145
|
-
if (typeof file !== 'string' || file === '')
|
|
146
|
-
throw new Error('download needs "file", the local file to write');
|
|
147
|
-
const inspected = parse(await called('inspect', selected));
|
|
148
|
-
if (typeof inspected?.download !== 'string')
|
|
149
|
-
throw new Error(`${String(selected.path)} holds no binary file; shell reads its text`);
|
|
150
|
-
const bytes = verified(await transferred(inspected.download, 'GET'), String(inspected.sha256), String(selected.path));
|
|
151
|
-
const written = resolve(file);
|
|
152
|
-
await mkdir(dirname(written), { recursive: true });
|
|
153
|
-
await writeFile(written, bytes);
|
|
154
|
-
return written;
|
|
155
|
-
}
|
|
156
|
-
async function described(file) {
|
|
157
|
-
const bytes = await localFile(file);
|
|
158
|
-
const mediaType = MEDIA_TYPES.get(extname(file).slice(1).toLowerCase());
|
|
159
|
-
return {
|
|
160
|
-
bytes,
|
|
161
|
-
description: {
|
|
162
|
-
bytes: bytes.length,
|
|
163
|
-
sha256: createHash('sha256').update(bytes).digest('hex'),
|
|
164
|
-
...(mediaType === undefined ? {} : { media_type: mediaType }),
|
|
165
|
-
},
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
async function upload({ file, ...destination }) {
|
|
169
|
-
if (typeof file !== 'string' || file === '')
|
|
170
|
-
throw new Error('upload needs "file", a local file');
|
|
171
|
-
const { bytes, description } = await described(file);
|
|
172
|
-
const answer = await called('upload', { ...destination, ...description });
|
|
173
|
-
const declared = parse(answer);
|
|
174
|
-
if (declared.upload === undefined)
|
|
175
|
-
return answer;
|
|
176
|
-
const written = JSON.parse(await sent(declared.upload.url, bytes, declared.upload.operation));
|
|
177
|
-
return stringify(written, { lineWidth: 0 }).trimEnd();
|
|
178
|
-
}
|
|
179
|
-
async function appendRecord(args) {
|
|
180
|
-
const held = new Map();
|
|
181
|
-
const attachments = Array.isArray(args.attachments)
|
|
182
|
-
? await Promise.all(args.attachments.map(async (attachment) => {
|
|
183
|
-
if (typeof attachment !== 'string')
|
|
184
|
-
return attachment;
|
|
185
|
-
const { bytes, description } = await described(attachment);
|
|
186
|
-
held.set(description.sha256, bytes);
|
|
187
|
-
return { name: basename(attachment), ...description };
|
|
188
|
-
}))
|
|
189
|
-
: args.attachments;
|
|
190
|
-
const record = { ...args, attachments };
|
|
191
|
-
for (;;) {
|
|
192
|
-
const answer = await called('append_record', record);
|
|
193
|
-
const { upload } = parse(answer);
|
|
194
|
-
if (upload === undefined)
|
|
195
|
-
return answer;
|
|
196
|
-
for (const grant of upload)
|
|
197
|
-
await sent(grant.url, held.get(grant.sha256), grant.operation);
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
function unexpected(argument, usage) {
|
|
201
|
-
return new Error(`unexpected argument ${argument}; ${usage}`);
|
|
202
|
-
}
|
|
203
|
-
function accepted(args, flags, positionals, usage) {
|
|
204
|
-
const given = { flags: new Set(), positionals: [] };
|
|
205
|
-
for (const arg of args) {
|
|
206
|
-
if (flags.includes(arg))
|
|
207
|
-
given.flags.add(arg);
|
|
208
|
-
else if (!arg.startsWith('-') && given.positionals.length < positionals)
|
|
209
|
-
given.positionals.push(arg);
|
|
210
|
-
else
|
|
211
|
-
throw unexpected(arg, usage);
|
|
212
|
-
}
|
|
213
|
-
return given;
|
|
214
|
-
}
|
|
215
|
-
async function push(args) {
|
|
216
|
-
const { flags, positionals: [commit = 'HEAD'] } = accepted(args, ['--help', '--owner'], 1, PUSH_USAGE);
|
|
217
|
-
if (flags.has('--help'))
|
|
218
|
-
return PUSH_USAGE;
|
|
219
|
-
const owner = flags.has('--owner');
|
|
220
|
-
if (owner && socketPath !== undefined)
|
|
221
|
-
throw new Error('--owner is not for Agent conversations; run house push without it');
|
|
222
|
-
if (!owner && socketPath === undefined)
|
|
223
|
-
throw new Error('outside an Agent conversation, house push needs --owner');
|
|
224
|
-
const pushed = JSON.parse(await bridged('/git/push', { cwd: process.cwd(), commit }, undefined, owner ? join(kitHome(), 'owner.sock') : socketPath));
|
|
225
|
-
if (pushed.refused)
|
|
226
|
-
throw new Error(pushed.text);
|
|
227
|
-
return pushed.text;
|
|
228
|
-
}
|
|
229
|
-
async function fetched(args) {
|
|
230
|
-
if (accepted(args, ['--help'], 0, FETCH_USAGE).flags.has('--help'))
|
|
231
|
-
return FETCH_USAGE;
|
|
232
|
-
const answer = JSON.parse(await bridged('/git/fetch', {}, undefined, socketPath ?? join(kitHome(), 'owner.sock')));
|
|
233
|
-
if (answer.refused)
|
|
234
|
-
throw new Error(answer.text);
|
|
235
|
-
return answer.text;
|
|
236
|
-
}
|
|
237
|
-
function argumentsOf(argument) {
|
|
238
|
-
if (argument === undefined)
|
|
239
|
-
return {};
|
|
240
|
-
let parsed;
|
|
241
|
-
try {
|
|
242
|
-
parsed = JSON.parse(argument);
|
|
243
|
-
}
|
|
244
|
-
catch {
|
|
245
|
-
throw new Error(ARGUMENTS);
|
|
246
|
-
}
|
|
247
|
-
if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed))
|
|
248
|
-
throw new Error(ARGUMENTS);
|
|
249
|
-
return parsed;
|
|
250
|
-
}
|
|
251
|
-
async function house(args) {
|
|
252
|
-
const { flags, positionals: [verb, argument] } = accepted(args, ['--help'], 2, USAGE);
|
|
253
|
-
if (verb === 'help' && argument !== undefined)
|
|
254
|
-
throw unexpected(argument, USAGE);
|
|
255
|
-
if (flags.has('--help') && argument !== undefined)
|
|
256
|
-
throw unexpected('--help', USAGE);
|
|
257
|
-
if (verb === undefined || verb === 'help') {
|
|
258
|
-
return [USAGE, 'help', PUSH, FETCH, DOWNLOAD, ...(await tools()).map((tool) => (tool.description === undefined ? tool.name : `${tool.name}: ${tool.description}`))].join('\n');
|
|
259
|
-
}
|
|
260
|
-
if (flags.has('--help')) {
|
|
261
|
-
const tool = (await tools()).find((listed) => listed.name === verb);
|
|
262
|
-
if (tool === undefined)
|
|
263
|
-
throw new Error(`${verb} is no Tool; house find_command '{"query":"${verb}"}' finds Commands`);
|
|
264
|
-
return [...(tool.description === undefined ? [] : [tool.description]), JSON.stringify(tool.inputSchema)].join('\n');
|
|
265
|
-
}
|
|
266
|
-
const parsed = argumentsOf(argument);
|
|
267
|
-
return verb === 'upload' ? upload(parsed) : verb === 'append_record' ? appendRecord(parsed) : called(verb, parsed);
|
|
2
|
+
const [major = 0, minor = 0] = process.versions.node.split('.').map(Number);
|
|
3
|
+
if (major < 24 || (major === 24 && minor < 14)) {
|
|
4
|
+
process.stderr.write(`house: the Kit needs Node 24.14.0 or newer; this is ${process.versions.node}\n`);
|
|
5
|
+
process.exitCode = 1;
|
|
268
6
|
}
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
const text = result.content.map((content) => content.text).join('\n');
|
|
272
|
-
if (result.isError === true)
|
|
273
|
-
throw new Error(text.replace(/\n+$/, ''));
|
|
274
|
-
return text;
|
|
7
|
+
else {
|
|
8
|
+
await import('./house-cli.js');
|
|
275
9
|
}
|
|
276
|
-
|
|
277
|
-
const named = argv.findIndex((arg) => !arg.startsWith('-'));
|
|
278
|
-
const rest = argv.filter((_arg, index) => index !== named);
|
|
279
|
-
(argv[named] === 'push'
|
|
280
|
-
? push(rest)
|
|
281
|
-
: argv[named] === 'fetch'
|
|
282
|
-
? fetched(rest)
|
|
283
|
-
: argv[named] === 'download'
|
|
284
|
-
? download(rest)
|
|
285
|
-
: house(argv)).then((text) => {
|
|
286
|
-
process.stdout.write(`${text}\n`);
|
|
287
|
-
if (argv[0] === 'shell')
|
|
288
|
-
process.exitCode = Number(/^exit: (\d+)(?:\n|$)/.exec(text)?.[1] ?? 0);
|
|
289
|
-
}, (error) => {
|
|
290
|
-
process.stderr.write(`house: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
291
|
-
process.exitCode = 1;
|
|
292
|
-
});
|
|
10
|
+
export {};
|
package/dist/kit-cli.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { setGlobalProxyFromEnv } from 'node:http';
|
|
2
|
+
import { parseArgs } from 'node:util';
|
|
3
|
+
import { answerGitCredential } from './app-git.js';
|
|
4
|
+
import { chatgpt } from './chatgpt.js';
|
|
5
|
+
import { login } from './login.js';
|
|
6
|
+
import { logout } from './logout.js';
|
|
7
|
+
import { resident } from './resident.js';
|
|
8
|
+
const USAGE = 'usage: kit <login|logout|resident|chatgpt>\n';
|
|
9
|
+
const COMMANDS = new Map([
|
|
10
|
+
[
|
|
11
|
+
'logout',
|
|
12
|
+
{
|
|
13
|
+
usage: 'usage: kit logout',
|
|
14
|
+
about: "disconnects this computer, stops House Kit and ends your own agent's connection",
|
|
15
|
+
operands: 0,
|
|
16
|
+
run: logout,
|
|
17
|
+
},
|
|
18
|
+
],
|
|
19
|
+
[
|
|
20
|
+
'resident',
|
|
21
|
+
{
|
|
22
|
+
usage: 'usage: kit resident',
|
|
23
|
+
about: "keeps this Environment connected; House Kit's service runs it",
|
|
24
|
+
operands: 0,
|
|
25
|
+
run: resident,
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
[
|
|
29
|
+
'git-credential',
|
|
30
|
+
{
|
|
31
|
+
usage: 'usage: kit git-credential <get|store|erase>',
|
|
32
|
+
about: "answers git with your own agent's House credential; git runs it",
|
|
33
|
+
operands: 1,
|
|
34
|
+
run: ([operation]) => answerGitCredential(operation),
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
]);
|
|
38
|
+
const [command, ...argv] = process.argv.slice(2);
|
|
39
|
+
setGlobalProxyFromEnv();
|
|
40
|
+
async function run() {
|
|
41
|
+
if (command === 'login')
|
|
42
|
+
return login(argv);
|
|
43
|
+
if (command === 'chatgpt')
|
|
44
|
+
return chatgpt(argv);
|
|
45
|
+
if (command === '--help') {
|
|
46
|
+
parseArgs({ args: argv });
|
|
47
|
+
process.stdout.write(USAGE);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const chosen = COMMANDS.get(command ?? '');
|
|
51
|
+
if (chosen === undefined) {
|
|
52
|
+
process.stderr.write(USAGE);
|
|
53
|
+
process.exitCode = 2;
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const { values, positionals } = parseArgs({ args: argv, options: { help: { type: 'boolean', default: false } }, allowPositionals: true });
|
|
57
|
+
if (positionals.length > chosen.operands)
|
|
58
|
+
throw new Error(`unexpected argument ${positionals[chosen.operands]}; ${chosen.usage}`);
|
|
59
|
+
if (values.help) {
|
|
60
|
+
process.stdout.write(`${chosen.usage}\n ${chosen.about}\n`);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
return chosen.run(positionals);
|
|
64
|
+
}
|
|
65
|
+
run().catch((error) => {
|
|
66
|
+
process.stderr.write(`kit: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
67
|
+
process.exitCode = 1;
|
|
68
|
+
});
|
package/dist/kit-main.js
CHANGED
|
@@ -1,69 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import { chatgpt } from './chatgpt.js';
|
|
6
|
-
import { login } from './login.js';
|
|
7
|
-
import { logout } from './logout.js';
|
|
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
|
-
]);
|
|
39
|
-
const [command, ...argv] = process.argv.slice(2);
|
|
40
|
-
setGlobalProxyFromEnv();
|
|
41
|
-
async function run() {
|
|
42
|
-
if (command === 'login')
|
|
43
|
-
return login(argv);
|
|
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);
|
|
65
|
-
}
|
|
66
|
-
run().catch((error) => {
|
|
67
|
-
process.stderr.write(`kit: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
2
|
+
const [major = 0, minor = 0] = process.versions.node.split('.').map(Number);
|
|
3
|
+
if (major < 24 || (major === 24 && minor < 14)) {
|
|
4
|
+
process.stderr.write(`kit: the Kit needs Node 24.14.0 or newer; this is ${process.versions.node}\n`);
|
|
68
5
|
process.exitCode = 1;
|
|
69
|
-
}
|
|
6
|
+
}
|
|
7
|
+
else {
|
|
8
|
+
await import('./kit-cli.js');
|
|
9
|
+
}
|
|
10
|
+
export {};
|
package/dist/login.js
CHANGED
|
@@ -2,11 +2,12 @@ import { spawn } from 'node:child_process';
|
|
|
2
2
|
import { createHash, randomBytes } from 'node:crypto';
|
|
3
3
|
import { hostname } from 'node:os';
|
|
4
4
|
import { parseArgs } from 'node:util';
|
|
5
|
-
import { post, retrying } from './api.js';
|
|
5
|
+
import { HouseRefusal, post, retrying } from './api.js';
|
|
6
6
|
import { placeAppGit } from './app-git.js';
|
|
7
7
|
import { writeCodexRule } from './clis.js';
|
|
8
|
-
import { forgetOwnAgent, readDisconnected, readEnrolment, readOwnAgent, writeEnrolment, writeOwnAgent } from './home.js';
|
|
8
|
+
import { forgetDisconnected, forgetOwnAgent, readDisconnected, readEnrolment, readOwnAgent, writeEnrolment, writeOwnAgent, } from './home.js';
|
|
9
9
|
import { callHouse, rpc } from './mcp.js';
|
|
10
|
+
import { refusalOf } from './refusals.js';
|
|
10
11
|
import { selectRelay } from './relay.js';
|
|
11
12
|
import { startService } from './service.js';
|
|
12
13
|
import { placeSkillSet } from './skills.js';
|
|
@@ -35,6 +36,16 @@ const USAGE = `usage: kit login [--house <origin>] [--environment <id>] [--rooms
|
|
|
35
36
|
--no-private give this Environment every Room but your Private Room
|
|
36
37
|
--code <code> connect this machine with a login code
|
|
37
38
|
`;
|
|
39
|
+
function connected(house, named, environment) {
|
|
40
|
+
if (named === undefined)
|
|
41
|
+
return `Environment ${environment} is connected to ${house}.\n`;
|
|
42
|
+
if (named === environment)
|
|
43
|
+
return `Environment ${environment} is reconnected to ${house}.\n`;
|
|
44
|
+
return `Environment ${named} stays with its account; this computer is connected to ${house} as new Environment ${environment} of the account that confirmed.\n`;
|
|
45
|
+
}
|
|
46
|
+
function gone(error) {
|
|
47
|
+
return error instanceof HouseRefusal && refusalOf(error.text)?.code === 'kit_environment_not_found';
|
|
48
|
+
}
|
|
38
49
|
function chosenRooms(rooms, noPrivate) {
|
|
39
50
|
if (rooms !== undefined && noPrivate)
|
|
40
51
|
throw new Error('--rooms and --no-private are two choices of Rooms; pass one');
|
|
@@ -73,9 +84,11 @@ export async function login(argv) {
|
|
|
73
84
|
selectRelay(relay);
|
|
74
85
|
const house = values.house ?? enrolled?.house ?? DEFAULT_HOUSE;
|
|
75
86
|
const replaces = process.env.HOUSE_KIT_REPLACES;
|
|
76
|
-
const
|
|
87
|
+
const remembered = replaces === undefined && values.environment === undefined && enrolled?.house === house ? enrolled.environment : undefined;
|
|
88
|
+
const environment = replaces === undefined ? (values.environment ?? remembered) : undefined;
|
|
77
89
|
const ownAgent = await readOwnAgent();
|
|
78
90
|
let held = false;
|
|
91
|
+
let named = environment;
|
|
79
92
|
let exchanged;
|
|
80
93
|
if (values.code !== undefined) {
|
|
81
94
|
exchanged = await post(house, '/kit/token', { code: values.code, label: hostname() });
|
|
@@ -83,15 +96,27 @@ export async function login(argv) {
|
|
|
83
96
|
else {
|
|
84
97
|
held = ownAgent !== null && ownAgent.house === house && (await accepted(house, ownAgent.credential));
|
|
85
98
|
const verifier = randomBytes(32).toString('base64url');
|
|
86
|
-
const
|
|
99
|
+
const start = () => retrying(() => post(house, '/kit', {
|
|
87
100
|
label: hostname(),
|
|
88
|
-
...(
|
|
101
|
+
...(named === undefined
|
|
89
102
|
? { act: 'new_environment', ...(replaces === undefined ? {} : { replaces }) }
|
|
90
|
-
: { act: 'existing_environment', environment_id:
|
|
103
|
+
: { act: 'existing_environment', environment_id: named }),
|
|
91
104
|
...rooms,
|
|
92
105
|
code_challenge: createHash('sha256').update(verifier).digest('base64url'),
|
|
93
106
|
...(held ? {} : { headless: true }),
|
|
94
107
|
}));
|
|
108
|
+
let started;
|
|
109
|
+
try {
|
|
110
|
+
started = await start();
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
if (remembered === undefined || !gone(error))
|
|
114
|
+
throw error;
|
|
115
|
+
await forgetDisconnected();
|
|
116
|
+
process.stdout.write(`House no longer holds Environment ${remembered}; connecting this computer as a new one.\n`);
|
|
117
|
+
named = undefined;
|
|
118
|
+
started = await start();
|
|
119
|
+
}
|
|
95
120
|
process.stdout.write(`Open this link and confirm: ${started.start_url}\n`);
|
|
96
121
|
open(started.start_url);
|
|
97
122
|
exchanged = await retrying(() => post(house, '/kit/token', { login: started.login, code_verifier: verifier }), undefined, () => POLL_INTERVAL_MS);
|
|
@@ -105,7 +130,7 @@ export async function login(argv) {
|
|
|
105
130
|
environment: exchanged.environment,
|
|
106
131
|
credential: exchanged.credential,
|
|
107
132
|
});
|
|
108
|
-
process.stdout.write(
|
|
133
|
+
process.stdout.write(connected(house, named, exchanged.environment));
|
|
109
134
|
if (exchanged.headless_credential !== undefined) {
|
|
110
135
|
await writeOwnAgent({ house, ...relayRecord, user: exchanged.user, credential: exchanged.headless_credential });
|
|
111
136
|
}
|
package/dist/skills.js
CHANGED
|
@@ -16,6 +16,7 @@ const SHIPPED_HOW_WE_WORK = [
|
|
|
16
16
|
'0bdcd43e1603ba6673a3cae56d70bbf90657cbeefd124e91a47be2ca1cbd6c93',
|
|
17
17
|
'4106a87ec66da6f7b2a10e74d18e6559d68d5f4fe7415dae68f5c7bdb9081968',
|
|
18
18
|
'ac814a2197038f037b657bb719340395f89f319ac9fcdd386629c3fe2cec68f1',
|
|
19
|
+
'29951ee394aad9979eecfed3e5dc32c2c86e2226b6a380db5dbd4f305f4d1156',
|
|
19
20
|
];
|
|
20
21
|
const RECORD = 'skill-set.json';
|
|
21
22
|
const WRITTEN = 'how-we-work.json';
|
package/dist/stream.js
CHANGED
|
@@ -7,6 +7,36 @@ import { KIT_WIRE, tooOld } from './wire.js';
|
|
|
7
7
|
const PATH = '/kit/stream';
|
|
8
8
|
const SUBPROTOCOL = `house.kit.stream.${KIT_WIRE}`;
|
|
9
9
|
const REFUSAL_HEADER = 'x-house-refusal';
|
|
10
|
+
// House beats each stream every thirty seconds, so two silent beats mean this Kit cannot hear House.
|
|
11
|
+
export const STREAM_SILENCE_MS = 60_000;
|
|
12
|
+
const SYSTEM_STREAM_CLOCK = {
|
|
13
|
+
later: (delay, callback) => setTimeout(callback, delay),
|
|
14
|
+
clear: (timer) => clearTimeout(timer),
|
|
15
|
+
};
|
|
16
|
+
export class StreamSilence {
|
|
17
|
+
timer = null;
|
|
18
|
+
silent;
|
|
19
|
+
clock;
|
|
20
|
+
interval;
|
|
21
|
+
constructor(silent, clock = SYSTEM_STREAM_CLOCK, interval = STREAM_SILENCE_MS) {
|
|
22
|
+
this.silent = silent;
|
|
23
|
+
this.clock = clock;
|
|
24
|
+
this.interval = interval;
|
|
25
|
+
}
|
|
26
|
+
heard() {
|
|
27
|
+
this.stop();
|
|
28
|
+
this.timer = this.clock.later(this.interval, () => {
|
|
29
|
+
this.timer = null;
|
|
30
|
+
this.silent();
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
stop() {
|
|
34
|
+
if (this.timer === null)
|
|
35
|
+
return;
|
|
36
|
+
this.clock.clear(this.timer);
|
|
37
|
+
this.timer = null;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
10
40
|
function streamUrl(house) {
|
|
11
41
|
const url = new URL(PATH, house);
|
|
12
42
|
url.protocol = url.protocol === 'https:' ? 'wss:' : 'ws:';
|
|
@@ -37,17 +67,10 @@ export function holdStream(handlers) {
|
|
|
37
67
|
headers: { authorization: `Bearer ${credential}` },
|
|
38
68
|
});
|
|
39
69
|
let opened = false;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
handlers.opened();
|
|
45
|
-
};
|
|
46
|
-
opening.onmessage = (event) => {
|
|
47
|
-
handlers.frame(JSON.parse(String(event.data)));
|
|
48
|
-
};
|
|
49
|
-
opening.onerror = () => undefined;
|
|
50
|
-
opening.onclose = (event) => {
|
|
70
|
+
let silence = null;
|
|
71
|
+
const closed = (event) => {
|
|
72
|
+
silence?.stop();
|
|
73
|
+
silence = null;
|
|
51
74
|
if (socket === opening)
|
|
52
75
|
socket = null;
|
|
53
76
|
process.stderr.write(`kit: control stream closed ${event.code} ${event.reason}\n`);
|
|
@@ -64,6 +87,29 @@ export function holdStream(handlers) {
|
|
|
64
87
|
// A closed socket reopens in one to three seconds, spread so Kits one restart closed return apart; an opening House refused as retryable or left unanswered backs off on the jittered curve.
|
|
65
88
|
setTimeout(() => void connect(), opened ? 1000 + Math.random() * 2000 : retryDelay(failures++));
|
|
66
89
|
};
|
|
90
|
+
opening.onopen = () => {
|
|
91
|
+
opened = true;
|
|
92
|
+
failures = 0;
|
|
93
|
+
socket = opening;
|
|
94
|
+
silence = new StreamSilence(() => {
|
|
95
|
+
if (socket !== opening)
|
|
96
|
+
return;
|
|
97
|
+
socket = null;
|
|
98
|
+
opening.onclose = null;
|
|
99
|
+
opening.close();
|
|
100
|
+
closed(new CloseEvent('close', { code: 1006, reason: 'heartbeat_missed' }));
|
|
101
|
+
});
|
|
102
|
+
silence.heard();
|
|
103
|
+
handlers.opened();
|
|
104
|
+
};
|
|
105
|
+
opening.onmessage = (event) => {
|
|
106
|
+
silence?.heard();
|
|
107
|
+
const frame = JSON.parse(String(event.data));
|
|
108
|
+
if (frame.type !== 'beat')
|
|
109
|
+
handlers.frame(frame);
|
|
110
|
+
};
|
|
111
|
+
opening.onerror = () => undefined;
|
|
112
|
+
opening.onclose = closed;
|
|
67
113
|
};
|
|
68
114
|
void connect();
|
|
69
115
|
return {
|
package/how-we-work.md
CHANGED
|
@@ -4,6 +4,8 @@ A Room is where information people share is kept; it is not the place for
|
|
|
4
4
|
private information. Work goes into the Room it belongs to, or the First Room
|
|
5
5
|
when none is named.
|
|
6
6
|
|
|
7
|
+
Every House answer carries the `url` of what it names; send the User that link.
|
|
8
|
+
|
|
7
9
|
The skills are already set up; never run `setup-matt-pocock-skills`.
|
|
8
10
|
|
|
9
11
|
## Where skill output goes
|