@agentshouse/kit 0.2.1-c5883630417e1 → 0.2.1-c5cb352412cd2
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 +7 -7
- package/dist/agents.js +50 -3
- package/dist/api.js +1 -1
- package/dist/bootstrap.json +4 -4
- package/dist/bridge.js +2 -5
- package/dist/chatgpt.js +7 -1
- package/dist/conversations.js +53 -14
- package/dist/copies.js +16 -8
- package/dist/end.js +3 -2
- package/dist/events.js +3 -0
- package/dist/git.js +2 -3
- package/dist/home.js +22 -13
- 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 +13 -4
- package/dist/placement.js +2 -20
- package/dist/resident.js +2 -2
- package/dist/stream.js +58 -12
- package/dist/work.js +3 -5
- package/package.json +1 -1
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
|
@@ -36,6 +36,13 @@ const USAGE = `usage: kit login [--house <origin>] [--environment <id>] [--rooms
|
|
|
36
36
|
--no-private give this Environment every Room but your Private Room
|
|
37
37
|
--code <code> connect this machine with a login code
|
|
38
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
|
+
}
|
|
39
46
|
function gone(error) {
|
|
40
47
|
return error instanceof HouseRefusal && refusalOf(error.text)?.code === 'kit_environment_not_found';
|
|
41
48
|
}
|
|
@@ -81,6 +88,7 @@ export async function login(argv) {
|
|
|
81
88
|
const environment = replaces === undefined ? (values.environment ?? remembered) : undefined;
|
|
82
89
|
const ownAgent = await readOwnAgent();
|
|
83
90
|
let held = false;
|
|
91
|
+
let named = environment;
|
|
84
92
|
let exchanged;
|
|
85
93
|
if (values.code !== undefined) {
|
|
86
94
|
exchanged = await post(house, '/kit/token', { code: values.code, label: hostname() });
|
|
@@ -88,7 +96,7 @@ export async function login(argv) {
|
|
|
88
96
|
else {
|
|
89
97
|
held = ownAgent !== null && ownAgent.house === house && (await accepted(house, ownAgent.credential));
|
|
90
98
|
const verifier = randomBytes(32).toString('base64url');
|
|
91
|
-
const start = (
|
|
99
|
+
const start = () => retrying(() => post(house, '/kit', {
|
|
92
100
|
label: hostname(),
|
|
93
101
|
...(named === undefined
|
|
94
102
|
? { act: 'new_environment', ...(replaces === undefined ? {} : { replaces }) }
|
|
@@ -99,14 +107,15 @@ export async function login(argv) {
|
|
|
99
107
|
}));
|
|
100
108
|
let started;
|
|
101
109
|
try {
|
|
102
|
-
started = await start(
|
|
110
|
+
started = await start();
|
|
103
111
|
}
|
|
104
112
|
catch (error) {
|
|
105
113
|
if (remembered === undefined || !gone(error))
|
|
106
114
|
throw error;
|
|
107
115
|
await forgetDisconnected();
|
|
108
116
|
process.stdout.write(`House no longer holds Environment ${remembered}; connecting this computer as a new one.\n`);
|
|
109
|
-
|
|
117
|
+
named = undefined;
|
|
118
|
+
started = await start();
|
|
110
119
|
}
|
|
111
120
|
process.stdout.write(`Open this link and confirm: ${started.start_url}\n`);
|
|
112
121
|
open(started.start_url);
|
|
@@ -121,7 +130,7 @@ export async function login(argv) {
|
|
|
121
130
|
environment: exchanged.environment,
|
|
122
131
|
credential: exchanged.credential,
|
|
123
132
|
});
|
|
124
|
-
process.stdout.write(
|
|
133
|
+
process.stdout.write(connected(house, named, exchanged.environment));
|
|
125
134
|
if (exchanged.headless_credential !== undefined) {
|
|
126
135
|
await writeOwnAgent({ house, ...relayRecord, user: exchanged.user, credential: exchanged.headless_credential });
|
|
127
136
|
}
|
package/dist/placement.js
CHANGED
|
@@ -2,7 +2,6 @@ import { readFileSync } from 'node:fs';
|
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
import { run } from './clis.js';
|
|
4
4
|
import { kitHome } from './home.js';
|
|
5
|
-
import { relayOrigin } from './relay.js';
|
|
6
5
|
export function service() {
|
|
7
6
|
if (process.platform !== 'linux' || !process.env.INVOCATION_ID)
|
|
8
7
|
return null;
|
|
@@ -19,9 +18,9 @@ export async function updatesItself() {
|
|
|
19
18
|
// sudo answers at once, so ten seconds only bounds a stuck sudo.
|
|
20
19
|
return (await run('sudo', ['-n', 'true'], 10_000)).status === 0;
|
|
21
20
|
}
|
|
22
|
-
function
|
|
21
|
+
export function installCommand() {
|
|
23
22
|
try {
|
|
24
|
-
return readFileSync(join(kitHome(), '
|
|
23
|
+
return readFileSync(join(kitHome(), 'install-command'), 'utf8').trim();
|
|
25
24
|
}
|
|
26
25
|
catch (error) {
|
|
27
26
|
if (error.code === 'ENOENT')
|
|
@@ -29,20 +28,3 @@ function installed() {
|
|
|
29
28
|
throw error;
|
|
30
29
|
}
|
|
31
30
|
}
|
|
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/resident.js
CHANGED
|
@@ -10,7 +10,7 @@ import { received } from './bridge.js';
|
|
|
10
10
|
import { CONVERSATION_INPUTS, Conversations } from './conversations.js';
|
|
11
11
|
import { LocalCopies } from './copies.js';
|
|
12
12
|
import { restart } from './end.js';
|
|
13
|
-
import { agentBase, enrolled, forgetRestart, kitHome, restartAsked } from './home.js';
|
|
13
|
+
import { agentBase, enrolled, forgetRestart, kitHome, ownerSocket, restartAsked } from './home.js';
|
|
14
14
|
import { killDescendants } from './scope.js';
|
|
15
15
|
import { quoted } from './shell.js';
|
|
16
16
|
import { SignIns } from './sign-in.js';
|
|
@@ -30,7 +30,7 @@ async function installShim(path, module) {
|
|
|
30
30
|
await writeFile(path, `#!/bin/sh\nexec ${quoted(process.execPath)} ${quoted(main)} "$@"\n`, { mode: 0o755 });
|
|
31
31
|
}
|
|
32
32
|
async function serveOwner(copies) {
|
|
33
|
-
const socketPath =
|
|
33
|
+
const socketPath = ownerSocket();
|
|
34
34
|
await rm(socketPath, { force: true });
|
|
35
35
|
const server = createServer(async (request, response) => {
|
|
36
36
|
try {
|
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`);
|
|
@@ -58,12 +81,35 @@ export function holdStream(handlers) {
|
|
|
58
81
|
return;
|
|
59
82
|
}
|
|
60
83
|
if (refused !== null && tooOld(refused.text))
|
|
61
|
-
updateRequired(
|
|
84
|
+
updateRequired();
|
|
62
85
|
if (finalRefusal(refused))
|
|
63
86
|
end(refused.message);
|
|
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/dist/work.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
2
|
import { once } from 'node:events';
|
|
3
3
|
import { readFileSync } from 'node:fs';
|
|
4
|
-
import {
|
|
4
|
+
import { rm } from 'node:fs/promises';
|
|
5
5
|
import { createServer } from 'node:net';
|
|
6
6
|
import { join } from 'node:path';
|
|
7
7
|
import { RUNNING_JOB } from './events.js';
|
|
8
|
-
import { kitHome } from './home.js';
|
|
8
|
+
import { kitHome, socketDirectory } from './home.js';
|
|
9
9
|
const ENDED_TASK = new Set(['completed', 'failed', 'killed']);
|
|
10
10
|
const SCHEDULING = new Set(['CronCreate', 'CronDelete', 'ScheduleWakeup']);
|
|
11
11
|
const QUEUE_LIST = 'house-kit-queue-';
|
|
@@ -194,9 +194,7 @@ class CodexWork extends Work {
|
|
|
194
194
|
proving = -1;
|
|
195
195
|
proven = -1;
|
|
196
196
|
async open(cli) {
|
|
197
|
-
|
|
198
|
-
await mkdir(sockets, { recursive: true, mode: 0o700 });
|
|
199
|
-
this.path = join(sockets, `${randomUUID()}.sock`);
|
|
197
|
+
this.path = join(socketDirectory(), `${randomUUID()}.sock`);
|
|
200
198
|
this.server = createServer((socket) => this.connected(socket));
|
|
201
199
|
this.server.listen(this.path);
|
|
202
200
|
await once(this.server, 'listening');
|