@agentshouse/kit 0.2.1-ce145e9aadbf6 → 0.2.1-ce46b2b55463f
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 +46 -49
- package/dist/acp.js +101 -108
- package/dist/afk.js +17 -0
- package/dist/agents.js +252 -73
- package/dist/api.js +43 -6
- package/dist/app-git.js +48 -0
- package/dist/binaries.js +79 -0
- package/dist/bridge.js +62 -79
- package/dist/building.js +50 -0
- package/dist/calls.js +88 -0
- package/dist/chunks.js +49 -0
- package/dist/clis.js +171 -102
- package/dist/codex-main.js +58 -0
- package/dist/connect.js +108 -0
- package/dist/connection.js +120 -0
- package/dist/content.js +106 -0
- package/dist/conversations.js +816 -335
- package/dist/copies.js +842 -309
- package/dist/earlier.js +263 -0
- package/dist/end.js +26 -0
- package/dist/events.js +793 -0
- package/dist/files.js +206 -18
- package/dist/git-main.js +24 -29
- package/dist/git.js +95 -18
- package/dist/grok.js +39 -0
- package/dist/home.js +134 -9
- package/dist/house-cli.js +282 -0
- package/dist/house-main.js +7 -159
- package/dist/instructions.js +7 -11
- package/dist/keys.js +238 -0
- package/dist/kit-cli.js +78 -0
- package/dist/kit-main.js +8 -19
- package/dist/login.js +133 -104
- package/dist/logout.js +15 -14
- package/dist/mcp.js +42 -3
- package/dist/owner.js +46 -0
- package/dist/placement.js +25 -0
- package/dist/refusals.js +43 -15
- package/dist/relay.js +33 -2
- package/dist/resident.js +161 -61
- package/dist/scope.js +214 -0
- package/dist/scripts.js +303 -0
- package/dist/secret-input.js +4 -3
- package/dist/settings.js +188 -0
- package/dist/shell.js +3 -0
- package/dist/sign-in.js +85 -33
- package/dist/silence.js +28 -0
- package/dist/skills.js +49 -35
- package/dist/supervisor.js +163 -0
- package/dist/transcription.js +131 -40
- package/dist/translate.js +19 -16
- package/dist/update.js +119 -100
- package/dist/wire.js +32 -0
- package/dist/work.js +353 -0
- package/dist/workspace.js +103 -0
- package/package.json +26 -21
- package/dist/authority-main.js +0 -22
- package/dist/blocks.js +0 -51
- package/dist/bootstrap.json +0 -24
- package/dist/clis-main.js +0 -23
- package/dist/configure-main.js +0 -6
- package/dist/enrol-main.js +0 -4
- package/dist/stream.js +0 -47
- package/how-we-work.md +0 -23
- package/skills/ask-matt/LICENSE +0 -21
- package/skills/ask-matt/PHASE-BOUNDARIES.md +0 -55
- package/skills/ask-matt/SKILL.md +0 -91
- package/skills/ask-matt/agents/openai.yaml +0 -4
- 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 -116
- package/skills/codebase-design/agents/openai.yaml +0 -3
- package/skills/diagnosing-bugs/LICENSE +0 -21
- package/skills/diagnosing-bugs/SKILL.md +0 -140
- 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/CONTEXT-FORMAT.md +0 -60
- package/skills/domain-modeling/LICENSE +0 -21
- package/skills/domain-modeling/SKILL.md +0 -76
- package/skills/domain-modeling/agents/openai.yaml +0 -3
- package/skills/grill-me/LICENSE +0 -21
- package/skills/grill-me/SKILL.md +0 -8
- package/skills/grill-me/agents/openai.yaml +0 -4
- package/skills/grill-with-docs/LICENSE +0 -21
- package/skills/grill-with-docs/SKILL.md +0 -8
- package/skills/grill-with-docs/agents/openai.yaml +0 -4
- 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 -17
- package/skills/handoff/agents/openai.yaml +0 -4
- package/skills/implement/LICENSE +0 -21
- package/skills/implement/SKILL.md +0 -16
- package/skills/implement/agents/openai.yaml +0 -4
- 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 -72
- package/skills/improve-codebase-architecture/agents/openai.yaml +0 -4
- package/skills/prototype/LICENSE +0 -21
- package/skills/prototype/LOGIC.md +0 -67
- package/skills/prototype/SKILL.md +0 -28
- 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 -14
- package/skills/research/agents/openai.yaml +0 -3
- package/skills/resolving-merge-conflicts/LICENSE +0 -21
- package/skills/resolving-merge-conflicts/SKILL.md +0 -16
- package/skills/resolving-merge-conflicts/agents/openai.yaml +0 -3
- package/skills/tdd/LICENSE +0 -21
- package/skills/tdd/SKILL.md +0 -40
- 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 -141
- package/skills/teach/agents/openai.yaml +0 -4
- package/skills/to-questionnaire/LICENSE +0 -21
- package/skills/to-questionnaire/SKILL.md +0 -55
- package/skills/to-questionnaire/agents/openai.yaml +0 -4
- package/skills/to-spec/LICENSE +0 -21
- package/skills/to-spec/SKILL.md +0 -76
- package/skills/to-spec/agents/openai.yaml +0 -4
- package/skills/to-tickets/LICENSE +0 -21
- package/skills/to-tickets/SKILL.md +0 -106
- package/skills/to-tickets/agents/openai.yaml +0 -4
- package/skills/wait-what/LICENSE +0 -21
- package/skills/wait-what/SKILL.md +0 -8
- package/skills/wait-what/agents/openai.yaml +0 -4
- package/skills/wayfinder/LICENSE +0 -21
- package/skills/wayfinder/SKILL.md +0 -129
- package/skills/wayfinder/agents/openai.yaml +0 -4
- 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 -83
- package/skills/writing-for-agents/agents/openai.yaml +0 -3
package/dist/mcp.js
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
|
+
import { KIT_WIRE, KIT_WIRE_HEADER } from '@agentshouse/kit-wire';
|
|
1
2
|
import { randomUUID } from 'node:crypto';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
3
|
+
import { KIT_RELEASE } from './clis.js';
|
|
4
|
+
import { readOwnAgent } from './home.js';
|
|
5
|
+
import { refusalOf, retryable } from './refusals.js';
|
|
6
|
+
import { relayed, selectRelay } from './relay.js';
|
|
4
7
|
const MCP_PROTOCOL_VERSION = '2026-07-28';
|
|
5
8
|
export const UNREACHABLE = 'House is unreachable; call again in a minute';
|
|
9
|
+
const UNCONNECTED = "this computer's own agent has no House connection; run kit login";
|
|
10
|
+
const DISCONNECTED = "House no longer accepts this computer's own agent; run kit login";
|
|
11
|
+
const UNCONFIRMED = 'with no result; a write may or may not have taken effect, so read before you repeat it';
|
|
12
|
+
export class Unsettled extends Error {
|
|
13
|
+
}
|
|
6
14
|
export function rpc(method, params) {
|
|
7
15
|
return { jsonrpc: '2.0', id: randomUUID(), method, params };
|
|
8
16
|
}
|
|
@@ -13,7 +21,7 @@ export function mcpBody(message, operation) {
|
|
|
13
21
|
...message.params,
|
|
14
22
|
_meta: {
|
|
15
23
|
'io.modelcontextprotocol/protocolVersion': MCP_PROTOCOL_VERSION,
|
|
16
|
-
'io.modelcontextprotocol/clientInfo': { name: '@agentshouse/kit', version:
|
|
24
|
+
'io.modelcontextprotocol/clientInfo': { name: '@agentshouse/kit', version: KIT_RELEASE },
|
|
17
25
|
'io.modelcontextprotocol/clientCapabilities': {},
|
|
18
26
|
...(operation === null ? {} : { 'agents.house/agent-operation': operation }),
|
|
19
27
|
},
|
|
@@ -31,9 +39,40 @@ export async function callHouse(origin, credential, message, operation = null, s
|
|
|
31
39
|
'mcp-protocol-version': MCP_PROTOCOL_VERSION,
|
|
32
40
|
'mcp-method': message.method,
|
|
33
41
|
...(tool === null ? {} : { 'mcp-name': tool }),
|
|
42
|
+
[KIT_WIRE_HEADER]: KIT_WIRE,
|
|
34
43
|
},
|
|
35
44
|
body: mcpBody(message, operation),
|
|
36
45
|
signal,
|
|
37
46
|
});
|
|
38
47
|
return { status: answer.status, text: await answer.text() };
|
|
39
48
|
}
|
|
49
|
+
export function unconfirmed(status) {
|
|
50
|
+
return `House answered ${status} ${UNCONFIRMED}`;
|
|
51
|
+
}
|
|
52
|
+
export async function ownAgentCall(message) {
|
|
53
|
+
const ownAgent = await readOwnAgent();
|
|
54
|
+
if (ownAgent === null)
|
|
55
|
+
throw new Error(UNCONNECTED);
|
|
56
|
+
selectRelay(process.env.HOUSE_KIT_RELAY || ownAgent.relay);
|
|
57
|
+
const answer = await callHouse(ownAgent.house, ownAgent.credential, message).catch(() => {
|
|
58
|
+
throw new Unsettled(UNREACHABLE);
|
|
59
|
+
});
|
|
60
|
+
if (answer.status === 200)
|
|
61
|
+
return answer.text;
|
|
62
|
+
if (answer.status === 401)
|
|
63
|
+
throw new Error(DISCONNECTED);
|
|
64
|
+
const refusal = refusalOf(answer.text)?.text ?? unconfirmed(answer.status);
|
|
65
|
+
throw retryable(answer.text) === false ? new Error(refusal) : new Unsettled(refusal);
|
|
66
|
+
}
|
|
67
|
+
export function refusalIn(text, status) {
|
|
68
|
+
return refusalOf(text) ?? { code: '', text: text === '' ? `House refused it with ${status}` : text, conflicts: [], detail: {} };
|
|
69
|
+
}
|
|
70
|
+
export function toolAnswer(forwarded) {
|
|
71
|
+
if (forwarded.status !== 200)
|
|
72
|
+
return { refused: refusalIn(forwarded.text, forwarded.status) };
|
|
73
|
+
const answer = JSON.parse(forwarded.text);
|
|
74
|
+
if (answer.error !== undefined)
|
|
75
|
+
return { refused: refusalIn(answer.error.message, forwarded.status) };
|
|
76
|
+
const text = answer.result.content.map((content) => content.text).join('\n');
|
|
77
|
+
return answer.result.isError === true ? { refused: refusalIn(text, forwarded.status) } : { text };
|
|
78
|
+
}
|
package/dist/owner.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { request } from 'node:http';
|
|
2
|
+
import { DatabaseSync } from 'node:sqlite';
|
|
3
|
+
import { received } from './bridge.js';
|
|
4
|
+
import { kitHome, ownerLock, ownerSocket } from './home.js';
|
|
5
|
+
function claimed(lock) {
|
|
6
|
+
try {
|
|
7
|
+
lock.exec('BEGIN EXCLUSIVE');
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
catch (error) {
|
|
11
|
+
if (error.errcode === 5)
|
|
12
|
+
return false;
|
|
13
|
+
throw error;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export function askOwner(path, body) {
|
|
17
|
+
return new Promise((resolve, reject) => {
|
|
18
|
+
const sent = request({ socketPath: ownerSocket(), path, method: body === undefined ? 'GET' : 'POST', headers: { 'content-type': 'application/json' } }, (answer) => {
|
|
19
|
+
received(answer).then((text) => {
|
|
20
|
+
if (answer.statusCode === 200)
|
|
21
|
+
resolve(JSON.parse(text));
|
|
22
|
+
else
|
|
23
|
+
reject(new Error(text));
|
|
24
|
+
}, reject);
|
|
25
|
+
});
|
|
26
|
+
sent.on('error', (error) => {
|
|
27
|
+
if (error.code === 'ENOENT' || error.code === 'ECONNREFUSED')
|
|
28
|
+
resolve(null);
|
|
29
|
+
else
|
|
30
|
+
reject(error);
|
|
31
|
+
});
|
|
32
|
+
sent.end(body === undefined ? undefined : JSON.stringify(body));
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
export async function holdOwner() {
|
|
36
|
+
const lock = new DatabaseSync(ownerLock());
|
|
37
|
+
if (claimed(lock))
|
|
38
|
+
return lock;
|
|
39
|
+
lock.close();
|
|
40
|
+
const running = (await askOwner('/resident'))?.pid ?? null;
|
|
41
|
+
throw new Error(`${running === null ? 'another Kit process' : `Kit process ${running}`} already runs this Environment from Kit home ${kitHome()}; stop it first to run another Kit process here`);
|
|
42
|
+
}
|
|
43
|
+
export async function runningRelease() {
|
|
44
|
+
const running = await askOwner('/resident');
|
|
45
|
+
return running === null ? null : (running.release ?? '');
|
|
46
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { join, resolve } from 'node:path';
|
|
3
|
+
import { kitHome } from './home.js';
|
|
4
|
+
function recorded(name) {
|
|
5
|
+
try {
|
|
6
|
+
return readFileSync(join(kitHome(), name), 'utf8').trim();
|
|
7
|
+
}
|
|
8
|
+
catch (error) {
|
|
9
|
+
if (error.code === 'ENOENT')
|
|
10
|
+
return null;
|
|
11
|
+
throw error;
|
|
12
|
+
}
|
|
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,41 +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
|
-
return
|
|
39
|
+
return null;
|
|
31
40
|
}
|
|
41
|
+
}
|
|
42
|
+
function errorIn(body) {
|
|
32
43
|
const error = body?.error;
|
|
33
|
-
|
|
44
|
+
return typeof error === 'object' && error !== null ? error : null;
|
|
45
|
+
}
|
|
46
|
+
function verdictOf(error) {
|
|
47
|
+
const verdict = error?.retryable ?? error?.data?.retryable;
|
|
48
|
+
return typeof verdict === 'boolean' ? verdict : null;
|
|
49
|
+
}
|
|
50
|
+
export function retryable(text) {
|
|
51
|
+
const answer = parsed(text);
|
|
52
|
+
return answer === null ? null : verdictOf(errorIn(answer.body));
|
|
53
|
+
}
|
|
54
|
+
export function refusalOf(text) {
|
|
55
|
+
const answer = parsed(text);
|
|
56
|
+
if (answer === null)
|
|
57
|
+
return spoken(text);
|
|
58
|
+
const error = errorIn(answer.body);
|
|
59
|
+
if (error === null)
|
|
34
60
|
return null;
|
|
35
61
|
const { code, message, data } = error;
|
|
62
|
+
const verdict = verdictOf(error);
|
|
63
|
+
const judged = verdict === null ? {} : { retryable: verdict };
|
|
36
64
|
const said = typeof message === 'string' ? spoken(message) : null;
|
|
37
65
|
if (said !== null)
|
|
38
|
-
return said;
|
|
66
|
+
return { ...said, ...judged };
|
|
39
67
|
const named = typeof code === 'string' ? code : typeof data?.code === 'string' ? data.code : null;
|
|
40
|
-
return named === null ? null : { code: named, text: named, conflicts: [] };
|
|
68
|
+
return named === null ? null : { code: named, text: named, conflicts: [], detail: {}, ...judged };
|
|
41
69
|
}
|
package/dist/relay.js
CHANGED
|
@@ -1,7 +1,38 @@
|
|
|
1
|
+
import { setGlobalProxyFromEnv } from 'node:http';
|
|
2
|
+
const PROXY = /^https?_proxy$/i;
|
|
3
|
+
const LOOPBACK = ['127.0.0.1', 'localhost', '::1'];
|
|
4
|
+
let selected;
|
|
5
|
+
let restoreProxy;
|
|
6
|
+
export function selectRelay(relay) {
|
|
7
|
+
selected = relay === undefined || relay === '' ? null : relay;
|
|
8
|
+
proxyUnlessRelayed();
|
|
9
|
+
}
|
|
10
|
+
export function relayOrigin() {
|
|
11
|
+
if (selected !== undefined)
|
|
12
|
+
return selected ?? undefined;
|
|
13
|
+
const ambient = process.env.HOUSE_KIT_RELAY;
|
|
14
|
+
return ambient === undefined || ambient === '' ? undefined : ambient;
|
|
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
|
+
}
|
|
1
32
|
export function relayed(target) {
|
|
2
33
|
const url = new URL(target);
|
|
3
|
-
const relay =
|
|
4
|
-
if (relay === undefined
|
|
34
|
+
const relay = relayOrigin();
|
|
35
|
+
if (relay === undefined)
|
|
5
36
|
return url;
|
|
6
37
|
const through = new URL(`${url.host}${url.pathname}${url.search}`, `${relay}/`);
|
|
7
38
|
if (url.protocol === 'wss:' || url.protocol === 'ws:')
|
package/dist/resident.js
CHANGED
|
@@ -2,53 +2,74 @@ import { once } from 'node:events';
|
|
|
2
2
|
import { watch } from 'node:fs';
|
|
3
3
|
import { mkdir, rm, writeFile } from 'node:fs/promises';
|
|
4
4
|
import { createServer } from 'node:http';
|
|
5
|
-
import { extname, join } from 'node:path';
|
|
5
|
+
import { dirname, extname, join } from 'node:path';
|
|
6
6
|
import { fileURLToPath } from 'node:url';
|
|
7
|
-
import { killDescendants } from './acp.js';
|
|
8
7
|
import { Agents } from './agents.js';
|
|
9
8
|
import { house } from './api.js';
|
|
10
9
|
import { received } from './bridge.js';
|
|
11
10
|
import { Conversations } from './conversations.js';
|
|
12
11
|
import { LocalCopies } from './copies.js';
|
|
13
|
-
import {
|
|
12
|
+
import { restart } from './end.js';
|
|
13
|
+
import { agentBase, enrolled, kitHome, ownerSocket, readEnrolment } 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';
|
|
18
|
+
import { killDescendants } from './scope.js';
|
|
19
|
+
import { removeInputs, Scripts } from './scripts.js';
|
|
20
|
+
import { applySettings, enrolledRoutes, resumeWorkspaceMove } from './settings.js';
|
|
21
|
+
import { quoted } from './shell.js';
|
|
14
22
|
import { SignIns } from './sign-in.js';
|
|
15
23
|
import { placeSkillSet } from './skills.js';
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
24
|
+
import { holdConnection } from './connection.js';
|
|
25
|
+
import { KitUpdate } from './update.js';
|
|
26
|
+
import { takeUnservedRelease } from './wire.js';
|
|
27
|
+
import { codexLauncher } from './work.js';
|
|
18
28
|
function report(error) {
|
|
19
29
|
process.stderr.write(`kit: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
20
30
|
}
|
|
21
31
|
function logged(work) {
|
|
22
32
|
work.catch(report);
|
|
23
33
|
}
|
|
24
|
-
function
|
|
25
|
-
|
|
34
|
+
async function installShim(path, module) {
|
|
35
|
+
const main = fileURLToPath(new URL(`./${module}${extname(fileURLToPath(import.meta.url))}`, import.meta.url));
|
|
36
|
+
await mkdir(dirname(path), { recursive: true });
|
|
37
|
+
await writeFile(path, `#!/bin/sh\nexec ${quoted(process.execPath)} ${quoted(main)} "$@"\n`, { mode: 0o755 });
|
|
26
38
|
}
|
|
27
|
-
async function
|
|
28
|
-
const main = fileURLToPath(new URL(`./git-main${extname(fileURLToPath(import.meta.url))}`, import.meta.url));
|
|
29
|
-
await mkdir(join(kitHome(), 'shim'), { recursive: true });
|
|
30
|
-
await writeFile(join(kitHome(), 'shim', 'git'), `#!/bin/sh\nexec ${quoted(process.execPath)} ${quoted(main)} "$@"\n`, {
|
|
31
|
-
mode: 0o755,
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
async function serveOwner(copies) {
|
|
35
|
-
const socketPath = join(kitHome(), 'owner.sock');
|
|
36
|
-
await rm(socketPath, { force: true });
|
|
39
|
+
async function serveOwner(lock, copies, settling) {
|
|
37
40
|
const server = createServer(async (request, response) => {
|
|
38
41
|
try {
|
|
39
|
-
|
|
42
|
+
const text = await received(request);
|
|
43
|
+
let answered;
|
|
44
|
+
if (request.url === '/resident') {
|
|
45
|
+
response.writeHead(200, { 'content-type': 'application/json' }).end(JSON.stringify({ pid: process.pid, release: KIT_RELEASE }));
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (request.url === '/git/fetch') {
|
|
49
|
+
answered = await copies.fetch(copies.owner);
|
|
50
|
+
}
|
|
51
|
+
else if (request.url === '/git/push') {
|
|
52
|
+
const { cwd, commit } = JSON.parse(text);
|
|
53
|
+
answered = await copies.push(cwd, commit, copies.owner);
|
|
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
|
+
}
|
|
60
|
+
else {
|
|
40
61
|
response.writeHead(404).end();
|
|
41
62
|
return;
|
|
42
63
|
}
|
|
43
|
-
|
|
44
|
-
const pushed = await copies.push(cwd, commit, copies.owner);
|
|
45
|
-
response.writeHead(200, { 'content-type': 'application/json' }).end(JSON.stringify(pushed));
|
|
64
|
+
response.writeHead(200, { 'content-type': 'application/json' }).end(JSON.stringify(answered));
|
|
46
65
|
}
|
|
47
66
|
catch (error) {
|
|
48
67
|
response.writeHead(502).end(error instanceof Error ? error.message : String(error));
|
|
49
68
|
}
|
|
50
69
|
});
|
|
51
|
-
server.
|
|
70
|
+
server.on('close', () => lock.close());
|
|
71
|
+
await rm(ownerSocket(), { force: true });
|
|
72
|
+
server.listen(ownerSocket());
|
|
52
73
|
await once(server, 'listening');
|
|
53
74
|
}
|
|
54
75
|
function connected() {
|
|
@@ -67,75 +88,154 @@ function connected() {
|
|
|
67
88
|
resolve();
|
|
68
89
|
});
|
|
69
90
|
}
|
|
70
|
-
|
|
91
|
+
async function started() {
|
|
71
92
|
await connected();
|
|
72
|
-
|
|
73
|
-
|
|
93
|
+
await placeSkillSet((await readEnrolment()).house);
|
|
94
|
+
await mkdir(agentBase(), { recursive: true });
|
|
95
|
+
await installShim(join(kitHome(), 'shim', 'git'), 'git-main');
|
|
96
|
+
await installShim(codexLauncher(), 'codex-main');
|
|
97
|
+
}
|
|
98
|
+
export async function resident() {
|
|
99
|
+
await moveEarlier();
|
|
100
|
+
await mkdir(kitHome(), { recursive: true, mode: 0o700 });
|
|
101
|
+
const lock = await holdOwner();
|
|
102
|
+
await resumeWorkspaceMove();
|
|
103
|
+
const copies = new LocalCopies(house);
|
|
104
|
+
await copies.load();
|
|
105
|
+
let running = null;
|
|
106
|
+
let settings = Promise.resolve();
|
|
107
|
+
const settle = (change) => {
|
|
108
|
+
const applied = settings.then(() => applySettings(change, {
|
|
109
|
+
working: () => running !== null && (running.conversations.turnOpen() || running.calls.busy()),
|
|
110
|
+
end: () => {
|
|
111
|
+
running?.conversations.stopped();
|
|
112
|
+
killDescendants();
|
|
113
|
+
},
|
|
114
|
+
routes: async () => {
|
|
115
|
+
if (running === null)
|
|
116
|
+
return enrolledRoutes();
|
|
117
|
+
await running.agents.read();
|
|
118
|
+
return running.agents.desired.routes;
|
|
119
|
+
},
|
|
120
|
+
}));
|
|
121
|
+
settings = applied.catch(() => undefined);
|
|
122
|
+
return applied.then((answer) => {
|
|
123
|
+
if ('settings' in answer && !answer.moved)
|
|
124
|
+
running?.agents.report().catch(report);
|
|
125
|
+
return answer;
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
const answered = (applied) => {
|
|
129
|
+
if ('settings' in applied ? !applied.moved : !applied.ended)
|
|
74
130
|
return;
|
|
75
|
-
|
|
131
|
+
const ended = 'settings' in applied
|
|
132
|
+
? `the workspace moved to ${applied.settings.workspace}; its supervisor starts Kit there`
|
|
133
|
+
: 'the workspace stays where it was; its supervisor starts Kit again';
|
|
134
|
+
if (running === null)
|
|
135
|
+
restart(ended);
|
|
136
|
+
else
|
|
137
|
+
void running.stop(() => restart(ended));
|
|
138
|
+
};
|
|
139
|
+
await copies.swept();
|
|
140
|
+
await serveOwner(lock, copies, { settle, answered });
|
|
141
|
+
await started().catch((error) => {
|
|
142
|
+
report(error);
|
|
76
143
|
process.exit(1);
|
|
77
144
|
});
|
|
78
|
-
await placeSkillSet();
|
|
79
|
-
await mkdir(agentBase(), { recursive: true });
|
|
80
145
|
process.env.HOUSE_KIT_RESIDENT = String(process.pid);
|
|
81
|
-
const agents = new Agents(house);
|
|
82
|
-
|
|
83
|
-
await copies.load();
|
|
84
|
-
await installShim();
|
|
85
|
-
await serveOwner(copies);
|
|
86
|
-
let stream = null;
|
|
146
|
+
const agents = new Agents(house, () => changed());
|
|
147
|
+
let connection = null;
|
|
87
148
|
let reported = false;
|
|
88
|
-
|
|
149
|
+
let stopping = false;
|
|
150
|
+
const stop = async (then) => {
|
|
151
|
+
if (stopping)
|
|
152
|
+
return;
|
|
153
|
+
stopping = true;
|
|
154
|
+
conversations.stopped();
|
|
155
|
+
killDescendants();
|
|
156
|
+
await connection?.close();
|
|
157
|
+
then();
|
|
158
|
+
};
|
|
159
|
+
const idle = () => calls.idle() && conversations.idle() && agents.idle();
|
|
89
160
|
const changed = () => {
|
|
90
161
|
if (!idle()) {
|
|
91
162
|
reported = false;
|
|
92
163
|
}
|
|
164
|
+
else if (update.placedRelease() !== null && conversations.quiet() && process.env.HOUSE_KIT_SANDBOX !== '1') {
|
|
165
|
+
const placed = update.placedRelease();
|
|
166
|
+
void stop(() => restart(`Kit ${placed} is placed; its supervisor starts it`));
|
|
167
|
+
}
|
|
93
168
|
else if (!reported) {
|
|
94
169
|
reported = true;
|
|
95
|
-
logged(house.deliver('/
|
|
170
|
+
logged(house.deliver('kits/report-idle', {}, idle));
|
|
96
171
|
}
|
|
97
172
|
};
|
|
173
|
+
const calls = new Calls(house, changed);
|
|
98
174
|
const conversations = new Conversations({
|
|
99
175
|
house,
|
|
100
176
|
agents,
|
|
101
177
|
copies,
|
|
102
|
-
|
|
178
|
+
calls,
|
|
179
|
+
send: (oneWayCall) => connection?.send(oneWayCall) ?? false,
|
|
103
180
|
changed,
|
|
104
181
|
});
|
|
105
|
-
const signIns = new SignIns(house, agents,
|
|
106
|
-
const
|
|
182
|
+
const signIns = new SignIns(house, agents, calls);
|
|
183
|
+
const update = new KitUpdate(calls);
|
|
184
|
+
takeUnservedRelease((release) => logged(update.takeRefused(release)));
|
|
185
|
+
removeInputs();
|
|
186
|
+
const scripts = new Scripts(calls, (oneWayCall) => connection?.send(oneWayCall) ?? false);
|
|
187
|
+
running = { conversations, agents, calls, stop };
|
|
107
188
|
for (const signal of ['SIGTERM', 'SIGINT']) {
|
|
108
189
|
process.once(signal, () => {
|
|
109
|
-
|
|
110
|
-
|
|
190
|
+
void stop(() => {
|
|
191
|
+
removeInputs();
|
|
192
|
+
process.kill(process.pid, signal);
|
|
193
|
+
});
|
|
111
194
|
});
|
|
112
195
|
}
|
|
113
|
-
|
|
114
|
-
|
|
196
|
+
const unenrolled = () => {
|
|
197
|
+
if (!enrolled())
|
|
198
|
+
void stop(() => process.exit(1));
|
|
199
|
+
};
|
|
200
|
+
watch(kitHome(), unenrolled);
|
|
201
|
+
unenrolled();
|
|
202
|
+
await house.deliver('kits/report-restart', {}).catch(report);
|
|
115
203
|
logged(agents.refresh());
|
|
116
|
-
|
|
204
|
+
agents.keepCurrent(() => process.env.HOUSE_KIT_SANDBOX === '1' && reported);
|
|
205
|
+
connection = holdConnection({
|
|
117
206
|
opened: () => {
|
|
118
207
|
conversations.opened();
|
|
208
|
+
scripts.connected();
|
|
119
209
|
changed();
|
|
120
|
-
logged(copies.
|
|
210
|
+
logged(copies.connected());
|
|
121
211
|
},
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
conversations.input(arrived);
|
|
212
|
+
closed: () => scripts.disconnected(),
|
|
213
|
+
call: (call) => {
|
|
214
|
+
if (call.kind === 'sign_in')
|
|
215
|
+
signIns.start(call);
|
|
216
|
+
else if (call.kind === 'update')
|
|
217
|
+
update.take(call);
|
|
218
|
+
else if (call.kind === 'settings') {
|
|
219
|
+
void calls.carrySettings(call.input_id, async () => {
|
|
220
|
+
const applied = await settle(call);
|
|
221
|
+
const result = 'refused' in applied ? { refused: applied.refused } : { settings: applied.settings };
|
|
222
|
+
if ('settings' in applied ? !applied.moved : !applied.ended)
|
|
223
|
+
return { result };
|
|
224
|
+
calls.keepResult(call.input_id, result);
|
|
225
|
+
return new Promise(() => answered(applied));
|
|
226
|
+
});
|
|
138
227
|
}
|
|
228
|
+
else if (call.kind === 'run_wizard' || call.kind === 'run_function')
|
|
229
|
+
scripts.start(call);
|
|
230
|
+
else
|
|
231
|
+
conversations.call(call);
|
|
232
|
+
},
|
|
233
|
+
oneWayCall: (oneWayCall) => {
|
|
234
|
+
if (oneWayCall.type === 'watching')
|
|
235
|
+
conversations.watching(oneWayCall.watching);
|
|
236
|
+
if (oneWayCall.type === 'work_available' && oneWayCall.subject === 'agents')
|
|
237
|
+
logged(agents.refresh());
|
|
238
|
+
scripts.notified(oneWayCall);
|
|
139
239
|
},
|
|
140
240
|
});
|
|
141
241
|
}
|