@agentshouse/kit 0.2.1-c5d36e97b0fea → 0.2.1-c8179f06883b6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -23
- package/dist/agents.js +5 -1
- package/dist/api.js +6 -2
- package/dist/bootstrap.json +4 -4
- package/dist/clis.js +41 -9
- package/dist/codex.js +61 -0
- package/dist/conversations.js +9 -5
- package/dist/copies.js +18 -18
- package/dist/end.js +17 -3
- package/dist/enrol-main.js +7 -1
- package/dist/home.js +41 -3
- package/dist/house-main.js +76 -36
- package/dist/instructions.js +5 -4
- package/dist/kit-main.js +53 -8
- package/dist/login.js +82 -16
- package/dist/parts.js +34 -16
- package/dist/placement.js +48 -0
- package/dist/relay.js +12 -2
- package/dist/resident.js +13 -4
- package/dist/service-main.js +9 -0
- package/dist/service.js +33 -0
- package/dist/stream.js +9 -4
- package/dist/update.js +27 -6
- package/dist/wire.js +6 -0
- package/package.json +2 -2
package/dist/service.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
const UNIT = 'house-kit.service';
|
|
3
|
+
// launchctl and systemctl answer at once, so ten seconds only bounds a stuck service manager.
|
|
4
|
+
const MANAGER_MS = 10_000;
|
|
5
|
+
function manage(command, args) {
|
|
6
|
+
return spawnSync(command, args, { encoding: 'utf8', timeout: MANAGER_MS });
|
|
7
|
+
}
|
|
8
|
+
function start(command, args) {
|
|
9
|
+
const started = manage(command, args);
|
|
10
|
+
if (started.status === 0)
|
|
11
|
+
return;
|
|
12
|
+
const cause = started.error?.message ?? (started.stderr.trim() || `${command} exited with ${started.status ?? 'a signal'}`);
|
|
13
|
+
throw new Error(`the House Kit service could not be started: ${cause}`);
|
|
14
|
+
}
|
|
15
|
+
export function startService() {
|
|
16
|
+
if (process.platform === 'darwin') {
|
|
17
|
+
const service = `gui/${process.getuid()}/house-kit`;
|
|
18
|
+
const printed = manage('launchctl', ['print', service]);
|
|
19
|
+
if (printed.status !== 0 || /^\tstate = running$/m.test(printed.stdout))
|
|
20
|
+
return false;
|
|
21
|
+
start('launchctl', ['kickstart', service]);
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
for (const scope of [['--user'], []]) {
|
|
25
|
+
if (manage('systemctl', [...scope, 'is-enabled', '--quiet', UNIT]).status !== 0)
|
|
26
|
+
continue;
|
|
27
|
+
if (manage('systemctl', [...scope, 'is-active', '--quiet', UNIT]).status === 0)
|
|
28
|
+
return false;
|
|
29
|
+
start('systemctl', [...scope, 'start', UNIT]);
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
return false;
|
|
33
|
+
}
|
package/dist/stream.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { subscribe } from 'node:diagnostics_channel';
|
|
2
2
|
import { finalRefusal, HouseRefusal, retryDelay } from './api.js';
|
|
3
|
-
import { end, REPLACED,
|
|
3
|
+
import { end, REPLACED, signInAgain, updateRequired } from './end.js';
|
|
4
4
|
import { readEnrolment } from './home.js';
|
|
5
5
|
import { relayed } from './relay.js';
|
|
6
|
+
import { KIT_WIRE, tooOld } from './wire.js';
|
|
6
7
|
const PATH = '/kit/stream';
|
|
7
|
-
const SUBPROTOCOL =
|
|
8
|
+
const SUBPROTOCOL = `house.kit.stream.${KIT_WIRE}`;
|
|
8
9
|
const REFUSAL_HEADER = 'x-house-refusal';
|
|
9
10
|
function streamUrl(house) {
|
|
10
11
|
const url = new URL(PATH, house);
|
|
@@ -52,8 +53,12 @@ export function holdStream(handlers) {
|
|
|
52
53
|
process.stderr.write(`kit: control stream closed ${event.code} ${event.reason}\n`);
|
|
53
54
|
if (event.reason === 'replaced')
|
|
54
55
|
end(REPLACED);
|
|
55
|
-
if (event.reason === 'credential_rejected' || refused?.status === 401)
|
|
56
|
-
|
|
56
|
+
if (event.reason === 'credential_rejected' || refused?.status === 401) {
|
|
57
|
+
void signInAgain(credential);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if (refused !== null && tooOld(refused.text))
|
|
61
|
+
updateRequired(house);
|
|
57
62
|
if (finalRefusal(refused))
|
|
58
63
|
end(refused.message);
|
|
59
64
|
// 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.
|
package/dist/update.js
CHANGED
|
@@ -4,8 +4,8 @@ import { mkdir, readFile, rm, writeFile } from 'node:fs/promises';
|
|
|
4
4
|
import { homedir } from 'node:os';
|
|
5
5
|
import { join } from 'node:path';
|
|
6
6
|
import { run } from './clis.js';
|
|
7
|
-
import { kitHome } from './home.js';
|
|
8
|
-
|
|
7
|
+
import { kitHome, workspaceRoot } from './home.js';
|
|
8
|
+
import { service, throughSudo } from './placement.js';
|
|
9
9
|
function logged(error) {
|
|
10
10
|
process.stderr.write(`kit: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
11
11
|
}
|
|
@@ -21,6 +21,21 @@ function outcome() {
|
|
|
21
21
|
function unit(inputId) {
|
|
22
22
|
return `house-kit-update-${inputId}`;
|
|
23
23
|
}
|
|
24
|
+
function manager() {
|
|
25
|
+
return service() === 'user' ? ['--user'] : [];
|
|
26
|
+
}
|
|
27
|
+
function elevated() {
|
|
28
|
+
return throughSudo() ? ['sudo', '-n'] : [];
|
|
29
|
+
}
|
|
30
|
+
function account() {
|
|
31
|
+
return throughSudo() ? [`--uid=${process.getuid()}`, `--gid=${process.getgid()}`] : [];
|
|
32
|
+
}
|
|
33
|
+
function placement() {
|
|
34
|
+
return service() === 'user' ? ['--workspace', workspaceRoot()] : ['--linux'];
|
|
35
|
+
}
|
|
36
|
+
function record() {
|
|
37
|
+
return `outcome=$1; shift; bash "$0" "$@"; printf %s "$?" > "$outcome"; ${[...elevated(), 'systemctl', ...manager(), 'start', 'house-kit.service'].join(' ')}`;
|
|
38
|
+
}
|
|
24
39
|
async function pendingInput() {
|
|
25
40
|
try {
|
|
26
41
|
return JSON.parse(await readFile(pending(), 'utf8')).input_id;
|
|
@@ -41,7 +56,7 @@ async function finished(inputId) {
|
|
|
41
56
|
if (ack !== null)
|
|
42
57
|
return ack;
|
|
43
58
|
// systemctl answers at once, so ten seconds only bounds a stuck service manager.
|
|
44
|
-
if ((await run('systemctl', ['is-active', '--quiet', unit(inputId)], 10_000)).status !== 0) {
|
|
59
|
+
if ((await run('systemctl', [...manager(), 'is-active', '--quiet', unit(inputId)], 10_000)).status !== 0) {
|
|
45
60
|
return (await recorded()) ?? { refused: 'the Kit bootstrap did not finish' };
|
|
46
61
|
}
|
|
47
62
|
// The bootstrap runs for minutes, so checking each second sees its outcome within a second at little cost.
|
|
@@ -50,7 +65,11 @@ async function finished(inputId) {
|
|
|
50
65
|
}
|
|
51
66
|
function rerun(script, inputId, flags) {
|
|
52
67
|
return new Promise((resolve) => {
|
|
53
|
-
const
|
|
68
|
+
const [command, ...args] = [
|
|
69
|
+
...elevated(),
|
|
70
|
+
'systemd-run',
|
|
71
|
+
...manager(),
|
|
72
|
+
...account(),
|
|
54
73
|
'--wait',
|
|
55
74
|
'--collect',
|
|
56
75
|
'--quiet',
|
|
@@ -58,11 +77,13 @@ function rerun(script, inputId, flags) {
|
|
|
58
77
|
`--setenv=HOME=${homedir()}`,
|
|
59
78
|
'/bin/sh',
|
|
60
79
|
'-c',
|
|
61
|
-
|
|
80
|
+
record(),
|
|
62
81
|
script,
|
|
63
82
|
outcome(),
|
|
83
|
+
...placement(),
|
|
64
84
|
...flags,
|
|
65
|
-
]
|
|
85
|
+
];
|
|
86
|
+
const child = spawn(command, args, { stdio: ['ignore', 'ignore', 'inherit'] });
|
|
66
87
|
child.on('error', () => resolve({ refused: 'no service manager runs this Kit' }));
|
|
67
88
|
child.on('close', () => resolve(null));
|
|
68
89
|
});
|
package/dist/wire.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentshouse/kit",
|
|
3
|
-
"version": "0.2.1-
|
|
3
|
+
"version": "0.2.1-c8179f06883b6",
|
|
4
4
|
"description": "House Kit connects an Environment to agents.house.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@agentclientprotocol/sdk": "1.7.0",
|
|
30
|
-
"@agentshouse/mdmodel": "0.1.0-
|
|
30
|
+
"@agentshouse/mdmodel": "0.1.0-c68e2039f1ca8",
|
|
31
31
|
"yaml": "2.9.1"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|