@agentshouse/kit 0.2.1-c0b0ffa6c025b → 0.2.1-c0eea939ba749
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 +14 -14
- package/dist/acp.js +34 -14
- package/dist/agents.js +50 -17
- package/dist/api.js +1 -1
- package/dist/app-git.js +10 -26
- package/dist/bootstrap.json +4 -4
- package/dist/bridge.js +3 -6
- package/dist/chatgpt.js +4 -1
- package/dist/clis.js +9 -0
- package/dist/conversations.js +123 -72
- package/dist/copies.js +86 -45
- package/dist/end.js +3 -2
- package/dist/events.js +4 -0
- package/dist/files.js +1 -1
- package/dist/git.js +2 -3
- package/dist/home.js +27 -13
- package/dist/house-cli.js +291 -0
- package/dist/house-main.js +7 -289
- package/dist/inputs.js +37 -0
- package/dist/instructions.js +2 -1
- package/dist/kit-cli.js +68 -0
- package/dist/kit-main.js +8 -67
- package/dist/login.js +14 -5
- package/dist/logout.js +0 -2
- package/dist/placement.js +2 -20
- package/dist/resident.js +60 -15
- package/dist/service.js +22 -0
- package/dist/sign-in.js +5 -23
- package/dist/stream.js +5 -5
- package/dist/update.js +20 -23
- package/dist/wire.js +1 -1
- package/dist/work.js +3 -5
- package/package.json +1 -1
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
|
@@ -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
|
}
|
|
@@ -132,7 +141,7 @@ export async function login(argv) {
|
|
|
132
141
|
else if (held && ownAgent !== null) {
|
|
133
142
|
await writeOwnAgent({ house, ...relayRecord, user: ownAgent.user, credential: ownAgent.credential });
|
|
134
143
|
}
|
|
135
|
-
await placeAppGit(
|
|
144
|
+
await placeAppGit(await readOwnAgent()).catch((error) => process.stderr.write(`kit: ${error.message}\n`));
|
|
136
145
|
try {
|
|
137
146
|
startService();
|
|
138
147
|
}
|
package/dist/logout.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { HouseRefusal, post } from './api.js';
|
|
2
|
-
import { forgetAppGit } from './app-git.js';
|
|
3
2
|
import { forgetEnrolment, forgetOwnAgent, readEnrolment } from './home.js';
|
|
4
3
|
export async function logout() {
|
|
5
4
|
const enrolled = await readEnrolment();
|
|
@@ -13,7 +12,6 @@ export async function logout() {
|
|
|
13
12
|
}
|
|
14
13
|
await forgetEnrolment(enrolled);
|
|
15
14
|
}
|
|
16
|
-
await forgetAppGit();
|
|
17
15
|
await forgetOwnAgent();
|
|
18
16
|
process.stdout.write(enrolled === null
|
|
19
17
|
? 'This computer is not connected to House.\n'
|
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
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { once } from 'node:events';
|
|
2
2
|
import { watch } from 'node:fs';
|
|
3
3
|
import { mkdir, rm, writeFile } from 'node:fs/promises';
|
|
4
|
-
import { createServer } from 'node:http';
|
|
4
|
+
import { createServer, get } from 'node:http';
|
|
5
5
|
import { dirname, extname, join } from 'node:path';
|
|
6
|
+
import { DatabaseSync } from 'node:sqlite';
|
|
6
7
|
import { fileURLToPath } from 'node:url';
|
|
7
8
|
import { Agents } from './agents.js';
|
|
8
9
|
import { house } from './api.js';
|
|
@@ -10,7 +11,8 @@ import { received } from './bridge.js';
|
|
|
10
11
|
import { CONVERSATION_INPUTS, Conversations } from './conversations.js';
|
|
11
12
|
import { LocalCopies } from './copies.js';
|
|
12
13
|
import { restart } from './end.js';
|
|
13
|
-
import { agentBase, enrolled, forgetRestart, kitHome, restartAsked } from './home.js';
|
|
14
|
+
import { agentBase, enrolled, forgetRestart, kitHome, ownerLock, ownerSocket, restartAsked } from './home.js';
|
|
15
|
+
import { Inputs } from './inputs.js';
|
|
14
16
|
import { killDescendants } from './scope.js';
|
|
15
17
|
import { quoted } from './shell.js';
|
|
16
18
|
import { SignIns } from './sign-in.js';
|
|
@@ -29,13 +31,32 @@ async function installShim(path, module) {
|
|
|
29
31
|
await mkdir(dirname(path), { recursive: true });
|
|
30
32
|
await writeFile(path, `#!/bin/sh\nexec ${quoted(process.execPath)} ${quoted(main)} "$@"\n`, { mode: 0o755 });
|
|
31
33
|
}
|
|
34
|
+
function claimed(lock) {
|
|
35
|
+
try {
|
|
36
|
+
lock.exec('BEGIN EXCLUSIVE');
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
if (error.errcode === 5)
|
|
41
|
+
return false;
|
|
42
|
+
throw error;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
32
45
|
async function serveOwner(copies) {
|
|
33
|
-
const
|
|
34
|
-
|
|
46
|
+
const lock = new DatabaseSync(ownerLock());
|
|
47
|
+
if (!claimed(lock)) {
|
|
48
|
+
lock.close();
|
|
49
|
+
const running = await runningResident();
|
|
50
|
+
throw new Error(`${running === null ? 'another Kit' : `Kit ${running}`} already runs this Environment from Kit home ${kitHome()}; stop it first to run another here`);
|
|
51
|
+
}
|
|
35
52
|
const server = createServer(async (request, response) => {
|
|
36
53
|
try {
|
|
37
54
|
const text = await received(request);
|
|
38
55
|
let answered;
|
|
56
|
+
if (request.url === '/resident') {
|
|
57
|
+
response.writeHead(200, { 'content-type': 'application/json' }).end(JSON.stringify({ pid: process.pid }));
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
39
60
|
if (request.url === '/git/fetch') {
|
|
40
61
|
answered = await copies.fetch();
|
|
41
62
|
}
|
|
@@ -53,9 +74,23 @@ async function serveOwner(copies) {
|
|
|
53
74
|
response.writeHead(502).end(error instanceof Error ? error.message : String(error));
|
|
54
75
|
}
|
|
55
76
|
});
|
|
56
|
-
server.
|
|
77
|
+
server.on('close', () => lock.close());
|
|
78
|
+
await rm(ownerSocket(), { force: true });
|
|
79
|
+
server.listen(ownerSocket());
|
|
57
80
|
await once(server, 'listening');
|
|
58
81
|
}
|
|
82
|
+
function runningResident() {
|
|
83
|
+
return new Promise((resolve, reject) => {
|
|
84
|
+
get({ socketPath: ownerSocket(), path: '/resident' }, (answer) => {
|
|
85
|
+
received(answer).then((text) => resolve(JSON.parse(text).pid), reject);
|
|
86
|
+
}).on('error', (error) => {
|
|
87
|
+
if (error.code === 'ENOENT' || error.code === 'ECONNREFUSED')
|
|
88
|
+
resolve(null);
|
|
89
|
+
else
|
|
90
|
+
reject(error);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
}
|
|
59
94
|
function connected() {
|
|
60
95
|
return new Promise((resolve) => {
|
|
61
96
|
const watcher = watch(kitHome(), () => {
|
|
@@ -72,7 +107,7 @@ function connected() {
|
|
|
72
107
|
resolve();
|
|
73
108
|
});
|
|
74
109
|
}
|
|
75
|
-
|
|
110
|
+
async function started() {
|
|
76
111
|
await connected();
|
|
77
112
|
await forgetRestart();
|
|
78
113
|
watch(kitHome(), () => {
|
|
@@ -83,16 +118,23 @@ export async function resident() {
|
|
|
83
118
|
});
|
|
84
119
|
await placeSkillSet();
|
|
85
120
|
await mkdir(agentBase(), { recursive: true });
|
|
86
|
-
process.env.HOUSE_KIT_RESIDENT = String(process.pid);
|
|
87
|
-
const agents = new Agents(house, () => changed());
|
|
88
|
-
const copies = new LocalCopies(house);
|
|
89
|
-
await copies.load();
|
|
90
121
|
await installShim(join(kitHome(), 'shim', 'git'), 'git-main');
|
|
91
122
|
await installShim(codexLauncher(), 'codex-main');
|
|
123
|
+
}
|
|
124
|
+
export async function resident() {
|
|
125
|
+
await mkdir(kitHome(), { recursive: true, mode: 0o700 });
|
|
126
|
+
const copies = new LocalCopies(house);
|
|
127
|
+
await copies.load();
|
|
92
128
|
await serveOwner(copies);
|
|
129
|
+
await started().catch((error) => {
|
|
130
|
+
report(error);
|
|
131
|
+
process.exit(1);
|
|
132
|
+
});
|
|
133
|
+
process.env.HOUSE_KIT_RESIDENT = String(process.pid);
|
|
134
|
+
const agents = new Agents(house, () => changed());
|
|
93
135
|
let stream = null;
|
|
94
136
|
let reported = false;
|
|
95
|
-
const idle = () =>
|
|
137
|
+
const idle = () => inputs.idle() && conversations.idle() && agents.idle();
|
|
96
138
|
const changed = () => {
|
|
97
139
|
if (!idle()) {
|
|
98
140
|
reported = false;
|
|
@@ -105,15 +147,17 @@ export async function resident() {
|
|
|
105
147
|
logged(house.deliver('/kit/idle', {}, idle));
|
|
106
148
|
}
|
|
107
149
|
};
|
|
150
|
+
const inputs = new Inputs(house, changed);
|
|
108
151
|
const conversations = new Conversations({
|
|
109
152
|
house,
|
|
110
153
|
agents,
|
|
111
154
|
copies,
|
|
155
|
+
inputs,
|
|
112
156
|
send: (frame) => stream?.send(frame) ?? false,
|
|
113
157
|
changed,
|
|
114
158
|
});
|
|
115
|
-
const signIns = new SignIns(house, agents,
|
|
116
|
-
const updates = new Updates(
|
|
159
|
+
const signIns = new SignIns(house, agents, inputs);
|
|
160
|
+
const updates = new Updates(inputs);
|
|
117
161
|
for (const signal of ['SIGTERM', 'SIGINT']) {
|
|
118
162
|
process.once(signal, () => {
|
|
119
163
|
killDescendants();
|
|
@@ -132,10 +176,11 @@ export async function resident() {
|
|
|
132
176
|
frame: (arrived) => {
|
|
133
177
|
if (arrived.type === 'watching')
|
|
134
178
|
conversations.watching(arrived.watching === true);
|
|
179
|
+
if (arrived.type === 'authority_changed')
|
|
180
|
+
logged(copies.changed(arrived.rooms));
|
|
135
181
|
if (arrived.type === 'work_available' && arrived.subject === 'agents')
|
|
136
182
|
logged(agents.refresh());
|
|
137
183
|
if (arrived.type === 'input') {
|
|
138
|
-
reported = false;
|
|
139
184
|
if (arrived.kind === 'sign_in')
|
|
140
185
|
signIns.start(arrived);
|
|
141
186
|
else if (arrived.kind === 'update')
|
|
@@ -144,7 +189,7 @@ export async function resident() {
|
|
|
144
189
|
conversations.input(arrived);
|
|
145
190
|
else {
|
|
146
191
|
const refused = { refused: `This Kit does not know ${arrived.kind}; update the Kit` };
|
|
147
|
-
|
|
192
|
+
void inputs.carry(String(arrived.input_id), async () => ({ ack: refused }));
|
|
148
193
|
}
|
|
149
194
|
}
|
|
150
195
|
},
|
package/dist/service.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { spawnSync } from 'node:child_process';
|
|
2
|
+
import { existsSync, realpathSync } from 'node:fs';
|
|
3
|
+
import { resolve } from 'node:path';
|
|
4
|
+
import { kitHome } from './home.js';
|
|
2
5
|
const UNIT = 'house-kit.service';
|
|
3
6
|
// launchctl and systemctl answer at once, so ten seconds only bounds a stuck service manager.
|
|
4
7
|
const MANAGER_MS = 10_000;
|
|
@@ -12,18 +15,37 @@ function start(command, args) {
|
|
|
12
15
|
const cause = started.error?.message ?? (started.stderr.trim() || `${command} exited with ${started.status ?? 'a signal'}`);
|
|
13
16
|
throw new Error(`the House Kit service could not be started: ${cause}`);
|
|
14
17
|
}
|
|
18
|
+
function physical(path) {
|
|
19
|
+
return existsSync(path) ? realpathSync(path) : resolve(path);
|
|
20
|
+
}
|
|
21
|
+
function systemdHome(environment) {
|
|
22
|
+
for (const [, quoted, bare] of environment.matchAll(/"((?:[^"\\]|\\.)*)"|(\S+)/g)) {
|
|
23
|
+
const assignment = bare ?? quoted.replace(/\\(.)/g, '$1');
|
|
24
|
+
if (assignment.startsWith('HOUSE_KIT_HOME='))
|
|
25
|
+
return assignment.slice('HOUSE_KIT_HOME='.length);
|
|
26
|
+
}
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
function runsThisHome(served) {
|
|
30
|
+
return served !== undefined && physical(served) === physical(kitHome());
|
|
31
|
+
}
|
|
15
32
|
export function startService() {
|
|
16
33
|
if (process.platform === 'darwin') {
|
|
17
34
|
const service = `gui/${process.getuid()}/house-kit`;
|
|
18
35
|
const printed = manage('launchctl', ['print', service]);
|
|
19
36
|
if (printed.status !== 0 || /^\tstate = running$/m.test(printed.stdout))
|
|
20
37
|
return false;
|
|
38
|
+
if (!runsThisHome(/^\t+HOUSE_KIT_HOME => (.+)$/m.exec(printed.stdout)?.[1]))
|
|
39
|
+
return false;
|
|
21
40
|
start('launchctl', ['kickstart', service]);
|
|
22
41
|
return true;
|
|
23
42
|
}
|
|
24
43
|
for (const scope of [['--user'], []]) {
|
|
25
44
|
if (manage('systemctl', [...scope, 'is-enabled', '--quiet', UNIT]).status !== 0)
|
|
26
45
|
continue;
|
|
46
|
+
const environment = manage('systemctl', [...scope, 'show', '--property=Environment', '--value', UNIT]).stdout;
|
|
47
|
+
if (!runsThisHome(systemdHome(environment)))
|
|
48
|
+
continue;
|
|
27
49
|
if (manage('systemctl', [...scope, 'is-active', '--quiet', UNIT]).status === 0)
|
|
28
50
|
return false;
|
|
29
51
|
start('systemctl', [...scope, 'start', UNIT]);
|
package/dist/sign-in.js
CHANGED
|
@@ -9,36 +9,20 @@ const CODE = /^[A-Z0-9]+-[A-Z0-9]+$/;
|
|
|
9
9
|
function causeOf(error) {
|
|
10
10
|
return error instanceof Error ? error.message : String(error);
|
|
11
11
|
}
|
|
12
|
-
function logged(error) {
|
|
13
|
-
process.stderr.write(`kit: ${causeOf(error)}\n`);
|
|
14
|
-
}
|
|
15
12
|
function endOf(signal) {
|
|
16
13
|
return new Promise((resolve) => signal.addEventListener('abort', () => resolve(true), { once: true }));
|
|
17
14
|
}
|
|
18
15
|
export class SignIns {
|
|
19
16
|
house;
|
|
20
17
|
agents;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
constructor(house, agents, changed) {
|
|
18
|
+
inputs;
|
|
19
|
+
constructor(house, agents, inputs) {
|
|
24
20
|
this.house = house;
|
|
25
21
|
this.agents = agents;
|
|
26
|
-
this.
|
|
27
|
-
}
|
|
28
|
-
idle() {
|
|
29
|
-
return this.running.size === 0;
|
|
22
|
+
this.inputs = inputs;
|
|
30
23
|
}
|
|
31
24
|
start(input) {
|
|
32
|
-
|
|
33
|
-
return;
|
|
34
|
-
this.running.add(input.input_id);
|
|
35
|
-
this.changed();
|
|
36
|
-
this.signIn(input)
|
|
37
|
-
.catch(logged)
|
|
38
|
-
.finally(() => {
|
|
39
|
-
this.running.delete(input.input_id);
|
|
40
|
-
this.changed();
|
|
41
|
-
});
|
|
25
|
+
void this.inputs.carry(input.input_id, () => this.signIn(input));
|
|
42
26
|
}
|
|
43
27
|
async signIn(input) {
|
|
44
28
|
const ending = new AbortController();
|
|
@@ -48,9 +32,7 @@ export class SignIns {
|
|
|
48
32
|
clearTimeout(timer);
|
|
49
33
|
if (ended)
|
|
50
34
|
process.stderr.write(`kit: the ${input.cli} sign-in reached the end House set for it\n`);
|
|
51
|
-
|
|
52
|
-
if (!ended)
|
|
53
|
-
await this.agents.reread(input.cli);
|
|
35
|
+
return ended ? { ack: {} } : { ack: {}, acknowledged: () => this.agents.reread(input.cli) };
|
|
54
36
|
}
|
|
55
37
|
async signedIn(input, signal) {
|
|
56
38
|
await this.login(input, signal);
|
package/dist/stream.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { subscribe } from 'node:diagnostics_channel';
|
|
2
|
-
import {
|
|
2
|
+
import { HouseRefusal, retryDelay } from './api.js';
|
|
3
3
|
import { end, REPLACED, signInAgain, updateRequired } from './end.js';
|
|
4
4
|
import { readEnrolment } from './home.js';
|
|
5
5
|
import { relayed } from './relay.js';
|
|
@@ -81,10 +81,10 @@ export function holdStream(handlers) {
|
|
|
81
81
|
return;
|
|
82
82
|
}
|
|
83
83
|
if (refused !== null && tooOld(refused.text))
|
|
84
|
-
updateRequired(
|
|
85
|
-
if (
|
|
86
|
-
|
|
87
|
-
// A closed socket reopens in one to three seconds, spread so Kits one restart closed return apart; an opening House refused
|
|
84
|
+
updateRequired();
|
|
85
|
+
if (!opened && refused !== null)
|
|
86
|
+
process.stderr.write(`kit: ${refused.message}\n`);
|
|
87
|
+
// A closed socket reopens in one to three seconds, spread so Kits one restart closed return apart; an opening House refused or left unanswered backs off on the jittered curve, retryable or not, since a resident outlives a House deploy.
|
|
88
88
|
setTimeout(() => void connect(), opened ? 1000 + Math.random() * 2000 : retryDelay(failures++));
|
|
89
89
|
};
|
|
90
90
|
opening.onopen = () => {
|
package/dist/update.js
CHANGED
|
@@ -6,9 +6,6 @@ import { join } from 'node:path';
|
|
|
6
6
|
import { run } from './clis.js';
|
|
7
7
|
import { kitHome, workspaceRoot } from './home.js';
|
|
8
8
|
import { service, throughSudo } from './placement.js';
|
|
9
|
-
function logged(error) {
|
|
10
|
-
process.stderr.write(`kit: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
11
|
-
}
|
|
12
9
|
function directory() {
|
|
13
10
|
return join(kitHome(), 'update');
|
|
14
11
|
}
|
|
@@ -50,6 +47,12 @@ async function recorded() {
|
|
|
50
47
|
return null;
|
|
51
48
|
return status.trim() === '0' ? {} : { refused: `the Kit bootstrap exited with ${status.trim()}` };
|
|
52
49
|
}
|
|
50
|
+
async function forget(inputId) {
|
|
51
|
+
if ((await pendingInput()) !== inputId)
|
|
52
|
+
return;
|
|
53
|
+
await rm(pending(), { force: true });
|
|
54
|
+
await rm(outcome(), { force: true });
|
|
55
|
+
}
|
|
53
56
|
async function finished(inputId) {
|
|
54
57
|
for (;;) {
|
|
55
58
|
const ack = await recorded();
|
|
@@ -90,27 +93,28 @@ function rerun(script, inputId, flags) {
|
|
|
90
93
|
});
|
|
91
94
|
}
|
|
92
95
|
export class Updates {
|
|
93
|
-
|
|
94
|
-
held = new Set();
|
|
96
|
+
inputs;
|
|
95
97
|
queue = Promise.resolve();
|
|
96
|
-
constructor(
|
|
97
|
-
this.
|
|
98
|
+
constructor(inputs) {
|
|
99
|
+
this.inputs = inputs;
|
|
98
100
|
}
|
|
99
101
|
async resumed() {
|
|
100
102
|
const inputId = await pendingInput();
|
|
101
103
|
if (inputId === null)
|
|
102
104
|
return;
|
|
103
|
-
await this.
|
|
105
|
+
await this.enqueue(inputId, () => finished(inputId));
|
|
104
106
|
}
|
|
105
107
|
start(input) {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
108
|
+
void this.enqueue(input.input_id, () => this.carry(input));
|
|
109
|
+
}
|
|
110
|
+
enqueue(inputId, work) {
|
|
111
|
+
const before = this.queue;
|
|
112
|
+
const carried = this.inputs.carry(inputId, async () => {
|
|
113
|
+
await before;
|
|
114
|
+
return { ack: await work(), acknowledged: () => forget(inputId) };
|
|
115
|
+
});
|
|
116
|
+
this.queue = before.then(() => carried);
|
|
117
|
+
return carried;
|
|
114
118
|
}
|
|
115
119
|
async carry(input) {
|
|
116
120
|
if ((await pendingInput()) === input.input_id)
|
|
@@ -131,11 +135,4 @@ export class Updates {
|
|
|
131
135
|
refused: 'the Kit bootstrap did not finish',
|
|
132
136
|
};
|
|
133
137
|
}
|
|
134
|
-
async acknowledge(inputId, ack) {
|
|
135
|
-
await this.house.deliver(`/kit/inputs/${inputId}/ack`, ack);
|
|
136
|
-
if ((await pendingInput()) !== inputId)
|
|
137
|
-
return;
|
|
138
|
-
await rm(pending(), { force: true });
|
|
139
|
-
await rm(outcome(), { force: true });
|
|
140
|
-
}
|
|
141
138
|
}
|
package/dist/wire.js
CHANGED
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');
|