@agentshouse/kit 0.2.1-ccf188e02985d → 0.2.1-cd423aab3dbcc
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 +35 -42
- package/dist/acp.js +66 -12
- package/dist/afk.js +17 -0
- package/dist/agents.js +122 -53
- package/dist/api.js +15 -10
- package/dist/binaries.js +60 -0
- package/dist/bridge.js +100 -45
- package/dist/building.js +50 -0
- package/dist/calls.js +88 -0
- package/dist/chunks.js +54 -0
- package/dist/clis.js +62 -50
- package/dist/connect.js +121 -0
- package/dist/connection.js +120 -0
- package/dist/content.js +106 -0
- package/dist/conversations.js +617 -240
- package/dist/copies.js +1277 -623
- package/dist/earlier.js +273 -0
- package/dist/end.js +12 -5
- package/dist/events.js +549 -281
- package/dist/files.js +206 -38
- package/dist/git.js +2 -72
- package/dist/grok.js +39 -0
- package/dist/home.js +86 -29
- package/dist/house-cli.js +180 -189
- package/dist/house-main.js +3 -3
- package/dist/instructions.js +29 -11
- package/dist/keys.js +238 -0
- package/dist/kit-cli.js +18 -8
- package/dist/kit-main.js +3 -3
- package/dist/login.js +36 -22
- package/dist/logout.js +2 -2
- package/dist/manifest.js +75 -0
- package/dist/mcp.js +47 -7
- package/dist/owner.js +46 -0
- package/dist/placement.js +15 -20
- package/dist/refusals.js +50 -23
- package/dist/relay.js +21 -0
- package/dist/resident.js +141 -90
- package/dist/scope.js +15 -4
- package/dist/scripts.js +319 -0
- package/dist/secret-input.js +1 -1
- package/dist/settings.js +247 -0
- package/dist/sign-in.js +67 -21
- package/dist/silence.js +28 -0
- package/dist/skills.js +42 -97
- package/dist/supervisor.js +163 -0
- package/dist/transcription.js +88 -45
- package/dist/update.js +118 -120
- package/dist/wire.js +30 -4
- package/dist/work.js +27 -2
- package/dist/workspace.js +113 -0
- package/package.json +25 -22
- package/dist/authority-main.js +0 -22
- package/dist/bootstrap.json +0 -24
- package/dist/chatgpt.js +0 -32
- package/dist/clis-main.js +0 -23
- package/dist/configure-main.js +0 -6
- package/dist/enrol-main.js +0 -10
- package/dist/git-main.js +0 -153
- package/dist/inputs.js +0 -37
- package/dist/parts.js +0 -82
- package/dist/service-main.js +0 -9
- package/dist/service.js +0 -55
- package/dist/stream.js +0 -123
- package/dist/translate.js +0 -51
- package/how-we-work.md +0 -33
- package/skills/ask-matt/LICENSE +0 -21
- package/skills/ask-matt/PHASE-BOUNDARIES.md +0 -55
- package/skills/ask-matt/SKILL.md +0 -97
- package/skills/ask-matt/agents/openai.yaml +0 -5
- package/skills/code-review/LICENSE +0 -21
- package/skills/code-review/SKILL.md +0 -89
- package/skills/code-review/agents/openai.yaml +0 -3
- package/skills/codebase-design/DEEPENING.md +0 -37
- package/skills/codebase-design/DESIGN-IT-TWICE.md +0 -44
- package/skills/codebase-design/LICENSE +0 -21
- package/skills/codebase-design/SKILL.md +0 -114
- package/skills/codebase-design/agents/openai.yaml +0 -3
- package/skills/diagnosing-bugs/LICENSE +0 -21
- package/skills/diagnosing-bugs/SKILL.md +0 -138
- package/skills/diagnosing-bugs/agents/openai.yaml +0 -3
- package/skills/diagnosing-bugs/scripts/hitl-loop.template.sh +0 -44
- package/skills/domain-modeling/ADR-FORMAT.md +0 -47
- package/skills/domain-modeling/GLOSSARY-FORMAT.md +0 -60
- package/skills/domain-modeling/LICENSE +0 -21
- package/skills/domain-modeling/SKILL.md +0 -74
- package/skills/domain-modeling/agents/openai.yaml +0 -3
- package/skills/grill-me/LICENSE +0 -21
- package/skills/grill-me/SKILL.md +0 -7
- package/skills/grill-me/agents/openai.yaml +0 -5
- package/skills/grill-with-docs/LICENSE +0 -21
- package/skills/grill-with-docs/SKILL.md +0 -7
- package/skills/grill-with-docs/agents/openai.yaml +0 -5
- package/skills/grilling/LICENSE +0 -21
- package/skills/grilling/SKILL.md +0 -30
- package/skills/grilling/agents/openai.yaml +0 -3
- package/skills/handoff/LICENSE +0 -21
- package/skills/handoff/SKILL.md +0 -16
- package/skills/handoff/agents/openai.yaml +0 -5
- package/skills/implement/LICENSE +0 -21
- package/skills/implement/SKILL.md +0 -17
- package/skills/implement/agents/openai.yaml +0 -5
- package/skills/implement-spec/LICENSE +0 -21
- package/skills/implement-spec/SKILL.md +0 -40
- package/skills/implement-spec/agents/openai.yaml +0 -5
- package/skills/improve-codebase-architecture/HTML-REPORT.md +0 -123
- package/skills/improve-codebase-architecture/LICENSE +0 -21
- package/skills/improve-codebase-architecture/SKILL.md +0 -71
- package/skills/improve-codebase-architecture/agents/openai.yaml +0 -5
- package/skills/pr/CREDITS.md +0 -3
- package/skills/pr/LICENSE +0 -21
- package/skills/pr/SKILL.md +0 -170
- package/skills/pr/agents/openai.yaml +0 -3
- package/skills/prototype/LICENSE +0 -21
- package/skills/prototype/LOGIC.md +0 -67
- package/skills/prototype/SKILL.md +0 -26
- package/skills/prototype/UI.md +0 -112
- package/skills/prototype/agents/openai.yaml +0 -3
- package/skills/research/LICENSE +0 -21
- package/skills/research/SKILL.md +0 -12
- package/skills/research/agents/openai.yaml +0 -3
- package/skills/retro/LICENSE +0 -21
- package/skills/retro/SKILL.md +0 -44
- package/skills/retro/agents/openai.yaml +0 -5
- package/skills/tdd/LICENSE +0 -21
- package/skills/tdd/SKILL.md +0 -38
- package/skills/tdd/agents/openai.yaml +0 -3
- package/skills/tdd/mocking.md +0 -59
- package/skills/tdd/tests.md +0 -77
- package/skills/teach/GLOSSARY-FORMAT.md +0 -35
- package/skills/teach/LEARNING-RECORD-FORMAT.md +0 -46
- package/skills/teach/LICENSE +0 -21
- package/skills/teach/MISSION-FORMAT.md +0 -31
- package/skills/teach/RESOURCES-FORMAT.md +0 -32
- package/skills/teach/SKILL.md +0 -140
- package/skills/teach/agents/openai.yaml +0 -5
- package/skills/to-questionnaire/LICENSE +0 -21
- package/skills/to-questionnaire/SKILL.md +0 -54
- package/skills/to-questionnaire/agents/openai.yaml +0 -5
- package/skills/to-spec/LICENSE +0 -21
- package/skills/to-spec/SKILL.md +0 -75
- package/skills/to-spec/agents/openai.yaml +0 -5
- package/skills/to-tickets/LICENSE +0 -21
- package/skills/to-tickets/SKILL.md +0 -105
- package/skills/to-tickets/agents/openai.yaml +0 -5
- package/skills/triage/AGENT-BRIEF.md +0 -207
- package/skills/triage/LICENSE +0 -21
- package/skills/triage/OUT-OF-SCOPE.md +0 -105
- package/skills/triage/SKILL.md +0 -112
- package/skills/triage/agents/openai.yaml +0 -5
- package/skills/wait-what/LICENSE +0 -21
- package/skills/wait-what/SKILL.md +0 -7
- package/skills/wait-what/agents/openai.yaml +0 -5
- package/skills/wayfinder/LICENSE +0 -21
- package/skills/wayfinder/SKILL.md +0 -128
- package/skills/wayfinder/agents/openai.yaml +0 -5
- package/skills/wizard/LICENSE +0 -21
- package/skills/wizard/SKILL.md +0 -44
- package/skills/wizard/agents/openai.yaml +0 -3
- package/skills/wizard/template.sh +0 -223
- package/skills/writing-for-agents/LICENSE +0 -21
- package/skills/writing-for-agents/SKILL-MECHANICS.md +0 -22
- package/skills/writing-for-agents/SKILL.md +0 -81
- package/skills/writing-for-agents/agents/openai.yaml +0 -3
package/dist/placement.js
CHANGED
|
@@ -1,26 +1,9 @@
|
|
|
1
1
|
import { readFileSync } from 'node:fs';
|
|
2
|
-
import { join } from 'node:path';
|
|
3
|
-
import { run } from './clis.js';
|
|
2
|
+
import { join, resolve } from 'node:path';
|
|
4
3
|
import { kitHome } from './home.js';
|
|
5
|
-
|
|
6
|
-
if (process.platform !== 'linux' || !process.env.INVOCATION_ID)
|
|
7
|
-
return null;
|
|
8
|
-
return process.env.MANAGERPID ? 'user' : 'system';
|
|
9
|
-
}
|
|
10
|
-
export function throughSudo() {
|
|
11
|
-
return service() === 'system' && process.getuid() !== 0;
|
|
12
|
-
}
|
|
13
|
-
export async function updatesItself() {
|
|
14
|
-
if (service() === null)
|
|
15
|
-
return false;
|
|
16
|
-
if (!throughSudo())
|
|
17
|
-
return true;
|
|
18
|
-
// sudo answers at once, so ten seconds only bounds a stuck sudo.
|
|
19
|
-
return (await run('sudo', ['-n', 'true'], 10_000)).status === 0;
|
|
20
|
-
}
|
|
21
|
-
export function installCommand() {
|
|
4
|
+
function recorded(name) {
|
|
22
5
|
try {
|
|
23
|
-
return readFileSync(join(kitHome(),
|
|
6
|
+
return readFileSync(join(kitHome(), name), 'utf8').trim();
|
|
24
7
|
}
|
|
25
8
|
catch (error) {
|
|
26
9
|
if (error.code === 'ENOENT')
|
|
@@ -28,3 +11,15 @@ export function installCommand() {
|
|
|
28
11
|
throw error;
|
|
29
12
|
}
|
|
30
13
|
}
|
|
14
|
+
export function installCommand() {
|
|
15
|
+
return recorded('install-command');
|
|
16
|
+
}
|
|
17
|
+
export function placedPrefix() {
|
|
18
|
+
const prefix = process.env.HOUSE_KIT_PREFIX;
|
|
19
|
+
if (prefix === undefined || prefix === '')
|
|
20
|
+
throw new Error('this Kit process was not started by a launcher its installer placed');
|
|
21
|
+
return resolve(prefix);
|
|
22
|
+
}
|
|
23
|
+
export function releaseDirectory(release) {
|
|
24
|
+
return join(placedPrefix(), 'releases', release);
|
|
25
|
+
}
|
package/dist/refusals.js
CHANGED
|
@@ -1,53 +1,80 @@
|
|
|
1
1
|
import { parse } from 'yaml';
|
|
2
2
|
const HEAD = /^([a-z][a-z0-9_]*): \S/;
|
|
3
|
-
|
|
3
|
+
const PUSH_STOPS = new Set(['limit_reached', 'cap_reached']);
|
|
4
|
+
function detailOf(text) {
|
|
4
5
|
let parsed;
|
|
5
6
|
try {
|
|
6
|
-
parsed = parse(
|
|
7
|
+
parsed = parse(text);
|
|
7
8
|
}
|
|
8
9
|
catch {
|
|
9
|
-
return
|
|
10
|
+
return {};
|
|
10
11
|
}
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
return typeof parsed === 'object' && parsed !== null && !Array.isArray(parsed) ? parsed : {};
|
|
13
|
+
}
|
|
14
|
+
function conflictsOf(detail) {
|
|
15
|
+
if (!Array.isArray(detail.conflicts))
|
|
13
16
|
return [];
|
|
14
|
-
return conflicts.flatMap((conflict) => typeof conflict?.code === 'string'
|
|
17
|
+
return detail.conflicts.flatMap((conflict) => typeof conflict?.code === 'string'
|
|
18
|
+
? [
|
|
19
|
+
{
|
|
20
|
+
code: conflict.code,
|
|
21
|
+
path: typeof conflict.path === 'string' ? conflict.path : '',
|
|
22
|
+
...(typeof conflict.revision === 'string' ? { revision: conflict.revision } : {}),
|
|
23
|
+
...(typeof conflict.content === 'string' ? { content: conflict.content } : {}),
|
|
24
|
+
},
|
|
25
|
+
]
|
|
26
|
+
: []);
|
|
15
27
|
}
|
|
16
28
|
function spoken(text) {
|
|
17
29
|
const head = HEAD.exec(text);
|
|
18
30
|
if (head === null)
|
|
19
31
|
return null;
|
|
20
32
|
const said = text.replace(/\n+$/, '');
|
|
21
|
-
const
|
|
22
|
-
|
|
33
|
+
const line = said.indexOf('\n');
|
|
34
|
+
const detail = line === -1 ? {} : detailOf(said.slice(line + 1));
|
|
35
|
+
return { code: head[1], text: said, conflicts: conflictsOf(detail), detail };
|
|
23
36
|
}
|
|
24
|
-
export function
|
|
25
|
-
|
|
37
|
+
export function stopsPush(refusal) {
|
|
38
|
+
return refusal !== null && PUSH_STOPS.has(refusal.code) && refusal.retryable === true;
|
|
39
|
+
}
|
|
40
|
+
export function firstLine(refusal) {
|
|
41
|
+
return refusal.text.split('\n')[0];
|
|
42
|
+
}
|
|
43
|
+
function parsed(text) {
|
|
26
44
|
try {
|
|
27
|
-
body
|
|
45
|
+
return { body: JSON.parse(text) };
|
|
28
46
|
}
|
|
29
47
|
catch {
|
|
30
48
|
return null;
|
|
31
49
|
}
|
|
50
|
+
}
|
|
51
|
+
function errorIn(body) {
|
|
32
52
|
const error = body?.error;
|
|
53
|
+
return typeof error === 'object' && error !== null ? error : null;
|
|
54
|
+
}
|
|
55
|
+
function verdictOf(error) {
|
|
33
56
|
const verdict = error?.retryable ?? error?.data?.retryable;
|
|
34
57
|
return typeof verdict === 'boolean' ? verdict : null;
|
|
35
58
|
}
|
|
59
|
+
export function retryable(text) {
|
|
60
|
+
const answer = parsed(text);
|
|
61
|
+
return answer === null ? null : verdictOf(errorIn(answer.body));
|
|
62
|
+
}
|
|
36
63
|
export function refusalOf(text) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
body = JSON.parse(text);
|
|
40
|
-
}
|
|
41
|
-
catch {
|
|
64
|
+
const answer = parsed(text);
|
|
65
|
+
if (answer === null)
|
|
42
66
|
return spoken(text);
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (typeof error !== 'object' || error === null)
|
|
67
|
+
const error = errorIn(answer.body);
|
|
68
|
+
if (error === null)
|
|
46
69
|
return null;
|
|
47
|
-
const { code, message, data } = error;
|
|
70
|
+
const { code, message, data, retryable: _retryable, ...fields } = error;
|
|
71
|
+
const verdict = verdictOf(error);
|
|
72
|
+
const judged = verdict === null ? {} : { retryable: verdict };
|
|
48
73
|
const said = typeof message === 'string' ? spoken(message) : null;
|
|
49
|
-
if (said !== null)
|
|
50
|
-
|
|
74
|
+
if (said !== null) {
|
|
75
|
+
const detail = { ...said.detail, ...fields };
|
|
76
|
+
return { ...said, detail, conflicts: conflictsOf(detail), ...judged };
|
|
77
|
+
}
|
|
51
78
|
const named = typeof code === 'string' ? code : typeof data?.code === 'string' ? data.code : null;
|
|
52
|
-
return named === null ? null : { code: named, text: named, conflicts: [] };
|
|
79
|
+
return named === null ? null : { code: named, text: named, conflicts: [], detail: {}, ...judged };
|
|
53
80
|
}
|
package/dist/relay.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
|
+
import { setGlobalProxyFromEnv } from 'node:http';
|
|
2
|
+
const PROXY = /^https?_proxy$/i;
|
|
3
|
+
const LOOPBACK = ['127.0.0.1', 'localhost', '::1'];
|
|
1
4
|
let selected;
|
|
5
|
+
let restoreProxy;
|
|
2
6
|
export function selectRelay(relay) {
|
|
3
7
|
selected = relay === undefined || relay === '' ? null : relay;
|
|
8
|
+
proxyUnlessRelayed();
|
|
4
9
|
}
|
|
5
10
|
export function relayOrigin() {
|
|
6
11
|
if (selected !== undefined)
|
|
@@ -8,6 +13,22 @@ export function relayOrigin() {
|
|
|
8
13
|
const ambient = process.env.HOUSE_KIT_RELAY;
|
|
9
14
|
return ambient === undefined || ambient === '' ? undefined : ambient;
|
|
10
15
|
}
|
|
16
|
+
function unlessRelayed() {
|
|
17
|
+
if (relayOrigin() === undefined)
|
|
18
|
+
return { ...process.env };
|
|
19
|
+
return Object.fromEntries(Object.entries(process.env).filter(([name]) => !PROXY.test(name)));
|
|
20
|
+
}
|
|
21
|
+
export function proxyUnlessRelayed() {
|
|
22
|
+
restoreProxy?.();
|
|
23
|
+
restoreProxy = setGlobalProxyFromEnv(unlessRelayed());
|
|
24
|
+
}
|
|
25
|
+
export function childEnvironment() {
|
|
26
|
+
const environment = unlessRelayed();
|
|
27
|
+
if (!Object.keys(environment).some((name) => PROXY.test(name)))
|
|
28
|
+
return environment;
|
|
29
|
+
const bypassed = [environment.NO_PROXY ?? environment.no_proxy, ...LOOPBACK].filter((entry) => entry !== undefined && entry !== '').join(',');
|
|
30
|
+
return { ...environment, NO_PROXY: bypassed, no_proxy: bypassed };
|
|
31
|
+
}
|
|
11
32
|
export function relayed(target) {
|
|
12
33
|
const url = new URL(target);
|
|
13
34
|
const relay = relayOrigin();
|
package/dist/resident.js
CHANGED
|
@@ -1,24 +1,29 @@
|
|
|
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
|
|
4
|
+
import { createServer } from 'node:http';
|
|
5
5
|
import { dirname, extname, join } from 'node:path';
|
|
6
|
-
import { DatabaseSync } from 'node:sqlite';
|
|
7
6
|
import { fileURLToPath } from 'node:url';
|
|
8
7
|
import { Agents } from './agents.js';
|
|
9
8
|
import { house } from './api.js';
|
|
10
9
|
import { received } from './bridge.js';
|
|
11
|
-
import {
|
|
12
|
-
import { LocalCopies } from './copies.js';
|
|
13
|
-
import { restart } from './end.js';
|
|
14
|
-
import { agentBase, enrolled,
|
|
15
|
-
import {
|
|
10
|
+
import { Conversations } from './conversations.js';
|
|
11
|
+
import { DEFAULT_MAX_SIZE, LocalCopies } from './copies.js';
|
|
12
|
+
import { restart, restartPlaced } from './end.js';
|
|
13
|
+
import { agentBase, enrolled, kitHome, ownerSocket, readEnrolment, recordPlannedRestart, roomsFolder, takePlannedRestart } from './home.js';
|
|
14
|
+
import { Calls } from './calls.js';
|
|
15
|
+
import { KIT_RELEASE } from './clis.js';
|
|
16
|
+
import { moveEarlier } from './earlier.js';
|
|
17
|
+
import { holdOwner } from './owner.js';
|
|
16
18
|
import { killDescendants } from './scope.js';
|
|
19
|
+
import { removeInputs, Scripts } from './scripts.js';
|
|
20
|
+
import { applySettings, enrolledRoutes, launchDirectories, moveIntoHouse, resumeWorkspaceMove } from './settings.js';
|
|
17
21
|
import { quoted } from './shell.js';
|
|
18
22
|
import { SignIns } from './sign-in.js';
|
|
19
23
|
import { placeSkillSet } from './skills.js';
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
24
|
+
import { holdConnection } from './connection.js';
|
|
25
|
+
import { KitUpdate } from './update.js';
|
|
26
|
+
import { takeUnservedRelease } from './wire.js';
|
|
22
27
|
import { codexLauncher } from './work.js';
|
|
23
28
|
function report(error) {
|
|
24
29
|
process.stderr.write(`kit: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
@@ -31,38 +36,27 @@ async function installShim(path, module) {
|
|
|
31
36
|
await mkdir(dirname(path), { recursive: true });
|
|
32
37
|
await writeFile(path, `#!/bin/sh\nexec ${quoted(process.execPath)} ${quoted(main)} "$@"\n`, { mode: 0o755 });
|
|
33
38
|
}
|
|
34
|
-
function
|
|
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
|
-
}
|
|
45
|
-
async function serveOwner(copies) {
|
|
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
|
-
}
|
|
39
|
+
async function serveOwner(lock, copies, settling) {
|
|
52
40
|
const server = createServer(async (request, response) => {
|
|
53
41
|
try {
|
|
54
42
|
const text = await received(request);
|
|
55
43
|
let answered;
|
|
56
44
|
if (request.url === '/resident') {
|
|
57
|
-
response.writeHead(200, { 'content-type': 'application/json' }).end(JSON.stringify({ pid: process.pid }));
|
|
45
|
+
response.writeHead(200, { 'content-type': 'application/json' }).end(JSON.stringify({ pid: process.pid, release: KIT_RELEASE }));
|
|
58
46
|
return;
|
|
59
47
|
}
|
|
60
|
-
if (request.url === '/
|
|
61
|
-
|
|
48
|
+
if (request.url === '/copy/download') {
|
|
49
|
+
const { attachments = false, max_size: maxSize = DEFAULT_MAX_SIZE } = JSON.parse(text);
|
|
50
|
+
answered = await copies.download(copies.owner, { attachments, maxSize });
|
|
62
51
|
}
|
|
63
|
-
else if (request.url === '/
|
|
64
|
-
const { cwd
|
|
65
|
-
answered = await copies.
|
|
52
|
+
else if (request.url === '/copy/upload') {
|
|
53
|
+
const { cwd } = JSON.parse(text);
|
|
54
|
+
answered = await copies.upload(cwd, copies.owner);
|
|
55
|
+
}
|
|
56
|
+
else if (request.url === '/settings') {
|
|
57
|
+
const applied = await settling.settle(JSON.parse(text));
|
|
58
|
+
response.writeHead(200, { 'content-type': 'application/json' }).end(JSON.stringify(applied), () => settling.answered(applied));
|
|
59
|
+
return;
|
|
66
60
|
}
|
|
67
61
|
else {
|
|
68
62
|
response.writeHead(404).end();
|
|
@@ -79,18 +73,6 @@ async function serveOwner(copies) {
|
|
|
79
73
|
server.listen(ownerSocket());
|
|
80
74
|
await once(server, 'listening');
|
|
81
75
|
}
|
|
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
|
-
}
|
|
94
76
|
function connected() {
|
|
95
77
|
return new Promise((resolve) => {
|
|
96
78
|
const watcher = watch(kitHome(), () => {
|
|
@@ -109,89 +91,158 @@ function connected() {
|
|
|
109
91
|
}
|
|
110
92
|
async function started() {
|
|
111
93
|
await connected();
|
|
112
|
-
await
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
killDescendants();
|
|
117
|
-
process.exit(1);
|
|
118
|
-
});
|
|
119
|
-
await placeSkillSet();
|
|
120
|
-
await mkdir(agentBase(), { recursive: true });
|
|
121
|
-
await installShim(join(kitHome(), 'shim', 'git'), 'git-main');
|
|
94
|
+
await placeSkillSet((await readEnrolment()).house);
|
|
95
|
+
await mkdir(agentBase(), { recursive: true, mode: 0o700 });
|
|
96
|
+
await mkdir(roomsFolder(), { recursive: true, mode: 0o700 });
|
|
97
|
+
await rm(join(kitHome(), 'shim'), { recursive: true, force: true });
|
|
122
98
|
await installShim(codexLauncher(), 'codex-main');
|
|
123
99
|
}
|
|
124
100
|
export async function resident() {
|
|
101
|
+
await moveEarlier();
|
|
125
102
|
await mkdir(kitHome(), { recursive: true, mode: 0o700 });
|
|
126
|
-
const
|
|
103
|
+
const lock = await holdOwner();
|
|
104
|
+
await resumeWorkspaceMove();
|
|
105
|
+
const copies = new LocalCopies(house, launchDirectories);
|
|
127
106
|
await copies.load();
|
|
128
|
-
await
|
|
107
|
+
const moved = await moveIntoHouse(copies);
|
|
108
|
+
if (moved !== null)
|
|
109
|
+
restart(moved);
|
|
110
|
+
const planned = takePlannedRestart();
|
|
111
|
+
let running = null;
|
|
112
|
+
let settings = Promise.resolve();
|
|
113
|
+
const settle = (change) => {
|
|
114
|
+
const applied = settings.then(() => applySettings(change, {
|
|
115
|
+
working: () => running !== null && (running.conversations.turnOpen() || running.calls.busy()),
|
|
116
|
+
end: () => {
|
|
117
|
+
running?.conversations.stopped();
|
|
118
|
+
killDescendants();
|
|
119
|
+
},
|
|
120
|
+
routes: async () => {
|
|
121
|
+
if (running === null)
|
|
122
|
+
return enrolledRoutes();
|
|
123
|
+
await running.agents.read();
|
|
124
|
+
return running.agents.desired.routes;
|
|
125
|
+
},
|
|
126
|
+
}));
|
|
127
|
+
settings = applied.catch(() => undefined);
|
|
128
|
+
return applied.then((answer) => {
|
|
129
|
+
if ('settings' in answer && !answer.moved)
|
|
130
|
+
running?.agents.report().catch(report);
|
|
131
|
+
return answer;
|
|
132
|
+
});
|
|
133
|
+
};
|
|
134
|
+
const answered = (applied) => {
|
|
135
|
+
if ('settings' in applied ? !applied.moved : !applied.ended)
|
|
136
|
+
return;
|
|
137
|
+
const ended = 'settings' in applied
|
|
138
|
+
? `the workspace moved to ${applied.settings.workspace}; its supervisor starts Kit there`
|
|
139
|
+
: 'the workspace stays where it was; its supervisor starts Kit again';
|
|
140
|
+
if (running === null)
|
|
141
|
+
restart(ended);
|
|
142
|
+
else
|
|
143
|
+
void running.stop(() => restart(ended));
|
|
144
|
+
};
|
|
145
|
+
await copies.swept();
|
|
146
|
+
await serveOwner(lock, copies, { settle, answered });
|
|
129
147
|
await started().catch((error) => {
|
|
130
148
|
report(error);
|
|
131
149
|
process.exit(1);
|
|
132
150
|
});
|
|
133
151
|
process.env.HOUSE_KIT_RESIDENT = String(process.pid);
|
|
134
152
|
const agents = new Agents(house, () => changed());
|
|
135
|
-
let
|
|
153
|
+
let connection = null;
|
|
136
154
|
let reported = false;
|
|
137
|
-
|
|
155
|
+
let stopping = false;
|
|
156
|
+
const stop = async (then) => {
|
|
157
|
+
if (stopping)
|
|
158
|
+
return;
|
|
159
|
+
stopping = true;
|
|
160
|
+
conversations.stopped();
|
|
161
|
+
killDescendants();
|
|
162
|
+
await connection?.close();
|
|
163
|
+
then();
|
|
164
|
+
};
|
|
165
|
+
const idle = () => calls.idle() && conversations.idle() && agents.idle();
|
|
138
166
|
const changed = () => {
|
|
139
167
|
if (!idle()) {
|
|
140
168
|
reported = false;
|
|
141
169
|
}
|
|
142
|
-
else if (
|
|
143
|
-
|
|
170
|
+
else if (update.placedRelease() !== null && conversations.quiet() && process.env.HOUSE_KIT_SANDBOX !== '1') {
|
|
171
|
+
const placed = update.placedRelease();
|
|
172
|
+
void stop(() => restartPlaced(placed));
|
|
144
173
|
}
|
|
145
174
|
else if (!reported) {
|
|
146
175
|
reported = true;
|
|
147
|
-
logged(house.deliver('/
|
|
176
|
+
logged(house.deliver('kits/report-idle', {}, idle));
|
|
148
177
|
}
|
|
149
178
|
};
|
|
150
|
-
const
|
|
179
|
+
const calls = new Calls(house, changed);
|
|
151
180
|
const conversations = new Conversations({
|
|
152
181
|
house,
|
|
153
182
|
agents,
|
|
154
183
|
copies,
|
|
155
|
-
|
|
156
|
-
send: (
|
|
184
|
+
calls,
|
|
185
|
+
send: (oneWayCall) => connection?.send(oneWayCall) ?? false,
|
|
157
186
|
changed,
|
|
158
187
|
});
|
|
159
|
-
const signIns = new SignIns(house, agents,
|
|
160
|
-
const
|
|
188
|
+
const signIns = new SignIns(house, agents, calls);
|
|
189
|
+
const update = new KitUpdate(calls);
|
|
190
|
+
takeUnservedRelease((release) => logged(update.takeRefused(release)));
|
|
191
|
+
removeInputs();
|
|
192
|
+
const scripts = new Scripts(calls, (oneWayCall) => connection?.send(oneWayCall) ?? false, house, copies);
|
|
193
|
+
running = { conversations, agents, calls, stop };
|
|
161
194
|
for (const signal of ['SIGTERM', 'SIGINT']) {
|
|
162
195
|
process.once(signal, () => {
|
|
163
|
-
|
|
164
|
-
|
|
196
|
+
recordPlannedRestart();
|
|
197
|
+
void stop(() => {
|
|
198
|
+
removeInputs();
|
|
199
|
+
process.kill(process.pid, signal);
|
|
200
|
+
});
|
|
165
201
|
});
|
|
166
202
|
}
|
|
167
|
-
|
|
168
|
-
|
|
203
|
+
const unenrolled = () => {
|
|
204
|
+
if (!enrolled())
|
|
205
|
+
void stop(() => process.exit(1));
|
|
206
|
+
};
|
|
207
|
+
watch(kitHome(), unenrolled);
|
|
208
|
+
unenrolled();
|
|
209
|
+
await house.deliver('kits/report-restart', planned ? { planned } : {}).catch(report);
|
|
169
210
|
logged(agents.refresh());
|
|
170
|
-
|
|
211
|
+
agents.keepCurrent(() => process.env.HOUSE_KIT_SANDBOX === '1' && reported);
|
|
212
|
+
connection = holdConnection({
|
|
171
213
|
opened: () => {
|
|
172
214
|
conversations.opened();
|
|
215
|
+
scripts.connected();
|
|
173
216
|
changed();
|
|
174
217
|
logged(copies.connected());
|
|
175
218
|
},
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
const refused = { refused: `This Kit does not know ${arrived.kind}; update the Kit` };
|
|
192
|
-
void inputs.carry(String(arrived.input_id), async () => ({ ack: refused }));
|
|
193
|
-
}
|
|
219
|
+
closed: () => scripts.disconnected(),
|
|
220
|
+
call: (call) => {
|
|
221
|
+
if (call.kind === 'sign_in')
|
|
222
|
+
signIns.start(call);
|
|
223
|
+
else if (call.kind === 'update')
|
|
224
|
+
update.take(call);
|
|
225
|
+
else if (call.kind === 'settings') {
|
|
226
|
+
void calls.carrySettings(call.input_id, async () => {
|
|
227
|
+
const applied = await settle(call);
|
|
228
|
+
const result = 'refused' in applied ? { refused: applied.refused } : { settings: applied.settings };
|
|
229
|
+
if ('settings' in applied ? !applied.moved : !applied.ended)
|
|
230
|
+
return { result };
|
|
231
|
+
calls.keepResult(call.input_id, result);
|
|
232
|
+
return new Promise(() => answered(applied));
|
|
233
|
+
});
|
|
194
234
|
}
|
|
235
|
+
else if (call.kind === 'run_wizard' || call.kind === 'run_function')
|
|
236
|
+
scripts.start(call);
|
|
237
|
+
else
|
|
238
|
+
conversations.call(call);
|
|
239
|
+
},
|
|
240
|
+
oneWayCall: (oneWayCall) => {
|
|
241
|
+
if (oneWayCall.type === 'watching')
|
|
242
|
+
conversations.watching(oneWayCall.watching);
|
|
243
|
+
if (oneWayCall.type === 'work_available' && oneWayCall.subject === 'agents')
|
|
244
|
+
logged(agents.refresh());
|
|
245
|
+
scripts.notified(oneWayCall);
|
|
195
246
|
},
|
|
196
247
|
});
|
|
197
248
|
}
|
package/dist/scope.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { execFileSync } from 'node:child_process';
|
|
2
|
-
import { mkdirSync, readdirSync, readFileSync, rmdirSync, statSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { mkdirSync, readdirSync, readFileSync, realpathSync, rmdirSync, statSync, writeFileSync } from 'node:fs';
|
|
3
3
|
import { join } from 'node:path';
|
|
4
4
|
const LISTING_BYTES = 1 << 28;
|
|
5
5
|
const CGROUPS = '/sys/fs/cgroup';
|
|
6
6
|
const GONE = new Set(['ENOENT', 'ESRCH']);
|
|
7
|
+
const EXITED = new Set(['Z', 'X']);
|
|
7
8
|
function failure(error) {
|
|
8
9
|
return error.code ?? '';
|
|
9
10
|
}
|
|
@@ -24,6 +25,8 @@ function read(pid) {
|
|
|
24
25
|
try {
|
|
25
26
|
const stat = readFileSync(`/proc/${pid}/stat`, 'utf8');
|
|
26
27
|
const fields = stat.slice(stat.lastIndexOf(')') + 2).split(' ');
|
|
28
|
+
if (EXITED.has(fields[0]))
|
|
29
|
+
return null;
|
|
27
30
|
const command = readFileSync(`/proc/${pid}/cmdline`, 'utf8').replaceAll('\0', ' ');
|
|
28
31
|
return { parent: Number(fields[1]), session: fields[3], command };
|
|
29
32
|
}
|
|
@@ -119,15 +122,23 @@ function members(group) {
|
|
|
119
122
|
}
|
|
120
123
|
return pids;
|
|
121
124
|
}
|
|
125
|
+
function besideCli(cli) {
|
|
126
|
+
try {
|
|
127
|
+
return `${realpathSync(cli)}-`;
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
122
133
|
export class Scope {
|
|
123
134
|
marker;
|
|
124
|
-
|
|
135
|
+
helpers;
|
|
125
136
|
group;
|
|
126
137
|
session = null;
|
|
127
138
|
recorded = null;
|
|
128
139
|
constructor(marker, name, cli) {
|
|
129
140
|
this.marker = marker;
|
|
130
|
-
this.
|
|
141
|
+
this.helpers = besideCli(cli);
|
|
131
142
|
const own = ownGroup();
|
|
132
143
|
this.group = own === null ? null : join(own, name);
|
|
133
144
|
try {
|
|
@@ -165,7 +176,7 @@ export class Scope {
|
|
|
165
176
|
return true;
|
|
166
177
|
if (this.recorded === null)
|
|
167
178
|
return found.size > 0;
|
|
168
|
-
return [...found].some(([pid, { session, command }]) => session !== this.session || !(this.recorded.has(pid) || command.startsWith(
|
|
179
|
+
return [...found].some(([pid, { session, command }]) => session !== this.session || !(this.recorded.has(pid) || (this.helpers !== null && command.startsWith(this.helpers))));
|
|
169
180
|
}
|
|
170
181
|
empty() {
|
|
171
182
|
return this.found()?.size === 0;
|