@agentshouse/kit 0.2.1-ccf188e02985d → 0.2.1-ccffb3f637815
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 +37 -41
- 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 +89 -0
- package/dist/bridge.js +29 -28
- package/dist/building.js +50 -0
- package/dist/calls.js +88 -0
- package/dist/chunks.js +49 -0
- package/dist/clis.js +62 -50
- package/dist/connect.js +108 -0
- package/dist/connection.js +120 -0
- package/dist/content.js +106 -0
- package/dist/conversations.js +594 -219
- package/dist/copies.js +772 -279
- package/dist/earlier.js +263 -0
- package/dist/end.js +12 -5
- package/dist/events.js +549 -281
- package/dist/files.js +206 -38
- package/dist/git-main.js +24 -29
- package/dist/git.js +90 -15
- package/dist/grok.js +39 -0
- package/dist/home.js +80 -29
- package/dist/house-cli.js +155 -164
- 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/mcp.js +42 -3
- package/dist/old-references.js +27 -0
- package/dist/owner.js +46 -0
- package/dist/placement.js +15 -20
- package/dist/refusals.js +37 -21
- package/dist/relay.js +21 -0
- package/dist/resident.js +128 -82
- package/dist/scope.js +15 -4
- package/dist/scripts.js +303 -0
- package/dist/secret-input.js +1 -1
- package/dist/settings.js +188 -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/translate.js +19 -18
- package/dist/update.js +118 -120
- package/dist/wire.js +30 -4
- package/dist/work.js +27 -2
- package/dist/workspace.js +103 -0
- package/package.json +26 -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/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/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,69 @@
|
|
|
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' ? [conflict.code] : []);
|
|
17
|
+
return detail.conflicts.flatMap((conflict) => typeof conflict?.code === 'string' ? [{ code: conflict.code, path: typeof conflict.path === 'string' ? conflict.path : '' }] : []);
|
|
15
18
|
}
|
|
16
19
|
function spoken(text) {
|
|
17
20
|
const head = HEAD.exec(text);
|
|
18
21
|
if (head === null)
|
|
19
22
|
return null;
|
|
20
23
|
const said = text.replace(/\n+$/, '');
|
|
21
|
-
const
|
|
22
|
-
|
|
24
|
+
const line = said.indexOf('\n');
|
|
25
|
+
const detail = line === -1 ? {} : detailOf(said.slice(line + 1));
|
|
26
|
+
return { code: head[1], text: said, conflicts: conflictsOf(detail), detail };
|
|
23
27
|
}
|
|
24
|
-
export function
|
|
25
|
-
|
|
28
|
+
export function stopsPush(refusal) {
|
|
29
|
+
return refusal !== null && PUSH_STOPS.has(refusal.code) && refusal.retryable === true;
|
|
30
|
+
}
|
|
31
|
+
export function firstLine(refusal) {
|
|
32
|
+
return refusal.text.split('\n')[0];
|
|
33
|
+
}
|
|
34
|
+
function parsed(text) {
|
|
26
35
|
try {
|
|
27
|
-
body
|
|
36
|
+
return { body: JSON.parse(text) };
|
|
28
37
|
}
|
|
29
38
|
catch {
|
|
30
39
|
return null;
|
|
31
40
|
}
|
|
41
|
+
}
|
|
42
|
+
function errorIn(body) {
|
|
32
43
|
const error = body?.error;
|
|
44
|
+
return typeof error === 'object' && error !== null ? error : null;
|
|
45
|
+
}
|
|
46
|
+
function verdictOf(error) {
|
|
33
47
|
const verdict = error?.retryable ?? error?.data?.retryable;
|
|
34
48
|
return typeof verdict === 'boolean' ? verdict : null;
|
|
35
49
|
}
|
|
50
|
+
export function retryable(text) {
|
|
51
|
+
const answer = parsed(text);
|
|
52
|
+
return answer === null ? null : verdictOf(errorIn(answer.body));
|
|
53
|
+
}
|
|
36
54
|
export function refusalOf(text) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
body = JSON.parse(text);
|
|
40
|
-
}
|
|
41
|
-
catch {
|
|
55
|
+
const answer = parsed(text);
|
|
56
|
+
if (answer === null)
|
|
42
57
|
return spoken(text);
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (typeof error !== 'object' || error === null)
|
|
58
|
+
const error = errorIn(answer.body);
|
|
59
|
+
if (error === null)
|
|
46
60
|
return null;
|
|
47
61
|
const { code, message, data } = error;
|
|
62
|
+
const verdict = verdictOf(error);
|
|
63
|
+
const judged = verdict === null ? {} : { retryable: verdict };
|
|
48
64
|
const said = typeof message === 'string' ? spoken(message) : null;
|
|
49
65
|
if (said !== null)
|
|
50
|
-
return said;
|
|
66
|
+
return { ...said, ...judged };
|
|
51
67
|
const named = typeof code === 'string' ? code : typeof data?.code === 'string' ? data.code : null;
|
|
52
|
-
return named === null ? null : { code: named, text: named, conflicts: [] };
|
|
68
|
+
return named === null ? null : { code: named, text: named, conflicts: [], detail: {}, ...judged };
|
|
53
69
|
}
|
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 {
|
|
10
|
+
import { Conversations } from './conversations.js';
|
|
12
11
|
import { LocalCopies } from './copies.js';
|
|
13
|
-
import { restart } from './end.js';
|
|
14
|
-
import { agentBase, enrolled,
|
|
15
|
-
import {
|
|
12
|
+
import { restart, restartPlaced } from './end.js';
|
|
13
|
+
import { agentBase, enrolled, kitHome, ownerSocket, readEnrolment, recordPlannedRestart, 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, 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,39 +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
48
|
if (request.url === '/git/fetch') {
|
|
61
|
-
answered = await copies.fetch();
|
|
49
|
+
answered = await copies.fetch(copies.owner);
|
|
62
50
|
}
|
|
63
51
|
else if (request.url === '/git/push') {
|
|
64
52
|
const { cwd, commit } = JSON.parse(text);
|
|
65
53
|
answered = await copies.push(cwd, commit, copies.owner);
|
|
66
54
|
}
|
|
55
|
+
else if (request.url === '/settings') {
|
|
56
|
+
const applied = await settling.settle(JSON.parse(text));
|
|
57
|
+
response.writeHead(200, { 'content-type': 'application/json' }).end(JSON.stringify(applied), () => settling.answered(applied));
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
67
60
|
else {
|
|
68
61
|
response.writeHead(404).end();
|
|
69
62
|
return;
|
|
@@ -79,18 +72,6 @@ async function serveOwner(copies) {
|
|
|
79
72
|
server.listen(ownerSocket());
|
|
80
73
|
await once(server, 'listening');
|
|
81
74
|
}
|
|
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
75
|
function connected() {
|
|
95
76
|
return new Promise((resolve) => {
|
|
96
77
|
const watcher = watch(kitHome(), () => {
|
|
@@ -109,89 +90,154 @@ function connected() {
|
|
|
109
90
|
}
|
|
110
91
|
async function started() {
|
|
111
92
|
await connected();
|
|
112
|
-
await
|
|
113
|
-
watch(kitHome(), () => {
|
|
114
|
-
if (enrolled())
|
|
115
|
-
return;
|
|
116
|
-
killDescendants();
|
|
117
|
-
process.exit(1);
|
|
118
|
-
});
|
|
119
|
-
await placeSkillSet();
|
|
93
|
+
await placeSkillSet((await readEnrolment()).house);
|
|
120
94
|
await mkdir(agentBase(), { recursive: true });
|
|
121
95
|
await installShim(join(kitHome(), 'shim', 'git'), 'git-main');
|
|
122
96
|
await installShim(codexLauncher(), 'codex-main');
|
|
123
97
|
}
|
|
124
98
|
export async function resident() {
|
|
99
|
+
await moveEarlier();
|
|
125
100
|
await mkdir(kitHome(), { recursive: true, mode: 0o700 });
|
|
101
|
+
const lock = await holdOwner();
|
|
102
|
+
const planned = takePlannedRestart();
|
|
103
|
+
await resumeWorkspaceMove();
|
|
126
104
|
const copies = new LocalCopies(house);
|
|
127
105
|
await copies.load();
|
|
128
|
-
|
|
106
|
+
let running = null;
|
|
107
|
+
let settings = Promise.resolve();
|
|
108
|
+
const settle = (change) => {
|
|
109
|
+
const applied = settings.then(() => applySettings(change, {
|
|
110
|
+
working: () => running !== null && (running.conversations.turnOpen() || running.calls.busy()),
|
|
111
|
+
end: () => {
|
|
112
|
+
running?.conversations.stopped();
|
|
113
|
+
killDescendants();
|
|
114
|
+
},
|
|
115
|
+
routes: async () => {
|
|
116
|
+
if (running === null)
|
|
117
|
+
return enrolledRoutes();
|
|
118
|
+
await running.agents.read();
|
|
119
|
+
return running.agents.desired.routes;
|
|
120
|
+
},
|
|
121
|
+
}));
|
|
122
|
+
settings = applied.catch(() => undefined);
|
|
123
|
+
return applied.then((answer) => {
|
|
124
|
+
if ('settings' in answer && !answer.moved)
|
|
125
|
+
running?.agents.report().catch(report);
|
|
126
|
+
return answer;
|
|
127
|
+
});
|
|
128
|
+
};
|
|
129
|
+
const answered = (applied) => {
|
|
130
|
+
if ('settings' in applied ? !applied.moved : !applied.ended)
|
|
131
|
+
return;
|
|
132
|
+
const ended = 'settings' in applied
|
|
133
|
+
? `the workspace moved to ${applied.settings.workspace}; its supervisor starts Kit there`
|
|
134
|
+
: 'the workspace stays where it was; its supervisor starts Kit again';
|
|
135
|
+
if (running === null)
|
|
136
|
+
restart(ended);
|
|
137
|
+
else
|
|
138
|
+
void running.stop(() => restart(ended));
|
|
139
|
+
};
|
|
140
|
+
await copies.swept();
|
|
141
|
+
await serveOwner(lock, copies, { settle, answered });
|
|
129
142
|
await started().catch((error) => {
|
|
130
143
|
report(error);
|
|
131
144
|
process.exit(1);
|
|
132
145
|
});
|
|
133
146
|
process.env.HOUSE_KIT_RESIDENT = String(process.pid);
|
|
134
147
|
const agents = new Agents(house, () => changed());
|
|
135
|
-
let
|
|
148
|
+
let connection = null;
|
|
136
149
|
let reported = false;
|
|
137
|
-
|
|
150
|
+
let stopping = false;
|
|
151
|
+
const stop = async (then) => {
|
|
152
|
+
if (stopping)
|
|
153
|
+
return;
|
|
154
|
+
stopping = true;
|
|
155
|
+
conversations.stopped();
|
|
156
|
+
killDescendants();
|
|
157
|
+
await connection?.close();
|
|
158
|
+
then();
|
|
159
|
+
};
|
|
160
|
+
const idle = () => calls.idle() && conversations.idle() && agents.idle();
|
|
138
161
|
const changed = () => {
|
|
139
162
|
if (!idle()) {
|
|
140
163
|
reported = false;
|
|
141
164
|
}
|
|
142
|
-
else if (
|
|
143
|
-
|
|
165
|
+
else if (update.placedRelease() !== null && conversations.quiet() && process.env.HOUSE_KIT_SANDBOX !== '1') {
|
|
166
|
+
const placed = update.placedRelease();
|
|
167
|
+
void stop(() => restartPlaced(placed));
|
|
144
168
|
}
|
|
145
169
|
else if (!reported) {
|
|
146
170
|
reported = true;
|
|
147
|
-
logged(house.deliver('/
|
|
171
|
+
logged(house.deliver('kits/report-idle', {}, idle));
|
|
148
172
|
}
|
|
149
173
|
};
|
|
150
|
-
const
|
|
174
|
+
const calls = new Calls(house, changed);
|
|
151
175
|
const conversations = new Conversations({
|
|
152
176
|
house,
|
|
153
177
|
agents,
|
|
154
178
|
copies,
|
|
155
|
-
|
|
156
|
-
send: (
|
|
179
|
+
calls,
|
|
180
|
+
send: (oneWayCall) => connection?.send(oneWayCall) ?? false,
|
|
157
181
|
changed,
|
|
158
182
|
});
|
|
159
|
-
const signIns = new SignIns(house, agents,
|
|
160
|
-
const
|
|
183
|
+
const signIns = new SignIns(house, agents, calls);
|
|
184
|
+
const update = new KitUpdate(calls);
|
|
185
|
+
takeUnservedRelease((release) => logged(update.takeRefused(release)));
|
|
186
|
+
removeInputs();
|
|
187
|
+
const scripts = new Scripts(calls, (oneWayCall) => connection?.send(oneWayCall) ?? false);
|
|
188
|
+
running = { conversations, agents, calls, stop };
|
|
161
189
|
for (const signal of ['SIGTERM', 'SIGINT']) {
|
|
162
190
|
process.once(signal, () => {
|
|
163
|
-
|
|
164
|
-
|
|
191
|
+
recordPlannedRestart();
|
|
192
|
+
void stop(() => {
|
|
193
|
+
removeInputs();
|
|
194
|
+
process.kill(process.pid, signal);
|
|
195
|
+
});
|
|
165
196
|
});
|
|
166
197
|
}
|
|
167
|
-
|
|
168
|
-
|
|
198
|
+
const unenrolled = () => {
|
|
199
|
+
if (!enrolled())
|
|
200
|
+
void stop(() => process.exit(1));
|
|
201
|
+
};
|
|
202
|
+
watch(kitHome(), unenrolled);
|
|
203
|
+
unenrolled();
|
|
204
|
+
await house.deliver('kits/report-restart', planned ? { planned } : {}).catch(report);
|
|
169
205
|
logged(agents.refresh());
|
|
170
|
-
|
|
206
|
+
agents.keepCurrent(() => process.env.HOUSE_KIT_SANDBOX === '1' && reported);
|
|
207
|
+
connection = holdConnection({
|
|
171
208
|
opened: () => {
|
|
172
209
|
conversations.opened();
|
|
210
|
+
scripts.connected();
|
|
173
211
|
changed();
|
|
174
212
|
logged(copies.connected());
|
|
175
213
|
},
|
|
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
|
-
}
|
|
214
|
+
closed: () => scripts.disconnected(),
|
|
215
|
+
call: (call) => {
|
|
216
|
+
if (call.kind === 'sign_in')
|
|
217
|
+
signIns.start(call);
|
|
218
|
+
else if (call.kind === 'update')
|
|
219
|
+
update.take(call);
|
|
220
|
+
else if (call.kind === 'settings') {
|
|
221
|
+
void calls.carrySettings(call.input_id, async () => {
|
|
222
|
+
const applied = await settle(call);
|
|
223
|
+
const result = 'refused' in applied ? { refused: applied.refused } : { settings: applied.settings };
|
|
224
|
+
if ('settings' in applied ? !applied.moved : !applied.ended)
|
|
225
|
+
return { result };
|
|
226
|
+
calls.keepResult(call.input_id, result);
|
|
227
|
+
return new Promise(() => answered(applied));
|
|
228
|
+
});
|
|
194
229
|
}
|
|
230
|
+
else if (call.kind === 'run_wizard' || call.kind === 'run_function')
|
|
231
|
+
scripts.start(call);
|
|
232
|
+
else
|
|
233
|
+
conversations.call(call);
|
|
234
|
+
},
|
|
235
|
+
oneWayCall: (oneWayCall) => {
|
|
236
|
+
if (oneWayCall.type === 'watching')
|
|
237
|
+
conversations.watching(oneWayCall.watching);
|
|
238
|
+
if (oneWayCall.type === 'work_available' && oneWayCall.subject === 'agents')
|
|
239
|
+
logged(agents.refresh());
|
|
240
|
+
scripts.notified(oneWayCall);
|
|
195
241
|
},
|
|
196
242
|
});
|
|
197
243
|
}
|
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;
|