@agentshouse/kit 0.2.1-cf669c6d1ecbb → 0.2.1-cf6a92e13f031
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 +36 -35
- package/dist/acp.js +36 -16
- package/dist/agents.js +110 -23
- package/dist/api.js +5 -1
- package/dist/app-git.js +10 -26
- package/dist/bootstrap.json +4 -4
- package/dist/bridge.js +4 -7
- package/dist/calls.js +63 -0
- package/dist/chatgpt.js +32 -0
- package/dist/clis.js +57 -12
- package/dist/connection.js +126 -0
- package/dist/conversations.js +399 -152
- package/dist/copies.js +89 -52
- package/dist/end.js +11 -2
- package/dist/events.js +6 -2
- package/dist/files.js +123 -31
- package/dist/git.js +11 -9
- package/dist/home.js +56 -5
- package/dist/house-cli.js +286 -0
- package/dist/house-main.js +7 -189
- package/dist/instructions.js +6 -10
- package/dist/kit-cli.js +68 -0
- package/dist/kit-main.js +8 -22
- package/dist/login.js +48 -16
- package/dist/logout.js +0 -2
- package/dist/mcp.js +4 -2
- package/dist/placement.js +39 -0
- package/dist/relay.js +1 -1
- package/dist/resident.js +88 -33
- package/dist/scope.js +3 -0
- package/dist/service.js +23 -1
- package/dist/sign-in.js +19 -37
- package/dist/skills.js +20 -32
- package/dist/transcription.js +53 -22
- package/dist/translate.js +2 -8
- package/dist/update.js +69 -50
- package/dist/web-wizard.js +100 -0
- package/dist/wire.js +22 -0
- package/dist/work.js +3 -5
- package/package.json +7 -6
- package/dist/stream.js +0 -74
- 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/kit-main.js
CHANGED
|
@@ -1,24 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import { logout } from './logout.js';
|
|
6
|
-
import { resident } from './resident.js';
|
|
7
|
-
const [command, ...argv] = process.argv.slice(2);
|
|
8
|
-
setGlobalProxyFromEnv();
|
|
9
|
-
async function run() {
|
|
10
|
-
if (command === 'login')
|
|
11
|
-
return login(argv);
|
|
12
|
-
if (command === 'logout')
|
|
13
|
-
return logout();
|
|
14
|
-
if (command === 'resident')
|
|
15
|
-
return resident();
|
|
16
|
-
if (command === 'git-credential')
|
|
17
|
-
return answerGitCredential(argv[0]);
|
|
18
|
-
process.stderr.write('usage: kit <login|logout|resident>\n');
|
|
19
|
-
process.exitCode = 2;
|
|
20
|
-
}
|
|
21
|
-
run().catch((error) => {
|
|
22
|
-
process.stderr.write(`kit: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
2
|
+
const [major = 0, minor = 0] = process.versions.node.split('.').map(Number);
|
|
3
|
+
if (major < 24 || (major === 24 && minor < 14)) {
|
|
4
|
+
process.stderr.write(`kit: the Kit needs Node 24.14.0 or newer; this is ${process.versions.node}\n`);
|
|
23
5
|
process.exitCode = 1;
|
|
24
|
-
}
|
|
6
|
+
}
|
|
7
|
+
else {
|
|
8
|
+
await import('./kit-cli.js');
|
|
9
|
+
}
|
|
10
|
+
export {};
|
package/dist/login.js
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
2
|
import { createHash, randomBytes } from 'node:crypto';
|
|
3
|
-
import { hostname } from 'node:os';
|
|
4
3
|
import { parseArgs } from 'node:util';
|
|
5
|
-
import { post, retrying } from './api.js';
|
|
4
|
+
import { HouseRefusal, post, retrying } from './api.js';
|
|
6
5
|
import { placeAppGit } from './app-git.js';
|
|
7
|
-
import {
|
|
6
|
+
import { writeCodexRule } from './clis.js';
|
|
7
|
+
import { forgetDisconnected, forgetOwnAgent, readDisconnected, readEnrolment, readOwnAgent, writeEnrolment, writeOwnAgent, } from './home.js';
|
|
8
8
|
import { callHouse, rpc } from './mcp.js';
|
|
9
|
+
import { refusalOf } from './refusals.js';
|
|
9
10
|
import { selectRelay } from './relay.js';
|
|
10
11
|
import { startService } from './service.js';
|
|
11
|
-
|
|
12
|
+
import { placeSkillSet } from './skills.js';
|
|
13
|
+
export const DEFAULT_HOUSE = 'https://agents.house';
|
|
12
14
|
const OPENER = process.platform === 'darwin' ? 'open' : 'xdg-open';
|
|
13
15
|
// Polling every two seconds brings the User's confirmation to the waiting Kit moments after they give it.
|
|
14
16
|
const POLL_INTERVAL_MS = 2000;
|
|
@@ -17,7 +19,7 @@ function open(link) {
|
|
|
17
19
|
.on('error', () => undefined)
|
|
18
20
|
.unref();
|
|
19
21
|
}
|
|
20
|
-
async function accepted(house, credential) {
|
|
22
|
+
export async function accepted(house, credential) {
|
|
21
23
|
const checked = await callHouse(house, credential, rpc('tools/list', {}));
|
|
22
24
|
if (checked.status === 200)
|
|
23
25
|
return true;
|
|
@@ -25,13 +27,24 @@ async function accepted(house, credential) {
|
|
|
25
27
|
return false;
|
|
26
28
|
throw new Error(`House answered ${checked.status} when Kit checked this computer's own agent's connection: ${checked.text}`);
|
|
27
29
|
}
|
|
28
|
-
const USAGE = `usage: kit login [--house <origin>] [--environment <id>] [--rooms <ref>[,<ref>...] | --no-private]
|
|
30
|
+
const USAGE = `usage: kit login [--house <origin>] [--environment <id>] [--rooms <ref>[,<ref>...] | --no-private]
|
|
31
|
+
kit login [--house <origin>] --code <code>
|
|
29
32
|
--house <origin> the House to connect to, ${DEFAULT_HOUSE} unless one is stored
|
|
30
33
|
--environment <id> reconnect this Environment
|
|
31
34
|
--rooms <ref>[,<ref>...] give this Environment only these Rooms
|
|
32
35
|
--no-private give this Environment every Room but your Private Room
|
|
33
36
|
--code <code> connect this machine with a login code
|
|
34
37
|
`;
|
|
38
|
+
function connected(house, named, environment) {
|
|
39
|
+
if (named === undefined)
|
|
40
|
+
return `Environment ${environment} is connected to ${house}.\n`;
|
|
41
|
+
if (named === environment)
|
|
42
|
+
return `Environment ${environment} is reconnected to ${house}.\n`;
|
|
43
|
+
return `Environment ${named} stays with its account; this computer is connected to ${house} as new Environment ${environment} of the account that confirmed.\n`;
|
|
44
|
+
}
|
|
45
|
+
function gone(error) {
|
|
46
|
+
return error instanceof HouseRefusal && refusalOf(error.text)?.code === 'kit_environment_not_found';
|
|
47
|
+
}
|
|
35
48
|
function chosenRooms(rooms, noPrivate) {
|
|
36
49
|
if (rooms !== undefined && noPrivate)
|
|
37
50
|
throw new Error('--rooms and --no-private are two choices of Rooms; pass one');
|
|
@@ -70,44 +83,63 @@ export async function login(argv) {
|
|
|
70
83
|
selectRelay(relay);
|
|
71
84
|
const house = values.house ?? enrolled?.house ?? DEFAULT_HOUSE;
|
|
72
85
|
const replaces = process.env.HOUSE_KIT_REPLACES;
|
|
73
|
-
const
|
|
86
|
+
const remembered = replaces === undefined && values.environment === undefined && enrolled?.house === house ? enrolled.environment : undefined;
|
|
87
|
+
const environment = replaces === undefined ? (values.environment ?? remembered) : undefined;
|
|
74
88
|
const ownAgent = await readOwnAgent();
|
|
75
89
|
let held = false;
|
|
90
|
+
let named = environment;
|
|
76
91
|
let exchanged;
|
|
77
92
|
if (values.code !== undefined) {
|
|
78
|
-
exchanged = await post(house, '/kit/token', { code: values.code
|
|
93
|
+
exchanged = await post(house, '/kit/token', { code: values.code });
|
|
79
94
|
}
|
|
80
95
|
else {
|
|
81
96
|
held = ownAgent !== null && ownAgent.house === house && (await accepted(house, ownAgent.credential));
|
|
82
97
|
const verifier = randomBytes(32).toString('base64url');
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
...(environment === undefined
|
|
98
|
+
const start = () => retrying(() => post(house, '/kit', {
|
|
99
|
+
...(named === undefined
|
|
86
100
|
? { act: 'new_environment', ...(replaces === undefined ? {} : { replaces }) }
|
|
87
|
-
: { act: 'existing_environment', environment_id:
|
|
101
|
+
: { act: 'existing_environment', environment_id: named }),
|
|
88
102
|
...rooms,
|
|
89
103
|
code_challenge: createHash('sha256').update(verifier).digest('base64url'),
|
|
90
104
|
...(held ? {} : { headless: true }),
|
|
91
105
|
}));
|
|
106
|
+
let started;
|
|
107
|
+
try {
|
|
108
|
+
started = await start();
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
if (remembered === undefined || !gone(error))
|
|
112
|
+
throw error;
|
|
113
|
+
await forgetDisconnected();
|
|
114
|
+
process.stdout.write(`House no longer holds Environment ${remembered}; connecting this computer as a new one.\n`);
|
|
115
|
+
named = undefined;
|
|
116
|
+
started = await start();
|
|
117
|
+
}
|
|
92
118
|
process.stdout.write(`Open this link and confirm: ${started.start_url}\n`);
|
|
93
119
|
open(started.start_url);
|
|
94
120
|
exchanged = await retrying(() => post(house, '/kit/token', { login: started.login, code_verifier: verifier }), undefined, () => POLL_INTERVAL_MS);
|
|
95
121
|
}
|
|
122
|
+
await placeSkillSet();
|
|
123
|
+
await writeCodexRule().catch((error) => process.stderr.write(`kit: ${error.message}\n`));
|
|
124
|
+
const relayRecord = relay === undefined ? {} : { relay };
|
|
96
125
|
await writeEnrolment({
|
|
97
126
|
house,
|
|
98
|
-
...
|
|
127
|
+
...relayRecord,
|
|
99
128
|
environment: exchanged.environment,
|
|
100
129
|
credential: exchanged.credential,
|
|
101
130
|
});
|
|
102
|
-
process.stdout.write(
|
|
131
|
+
process.stdout.write(connected(house, named, exchanged.environment));
|
|
103
132
|
if (exchanged.headless_credential !== undefined) {
|
|
104
|
-
await writeOwnAgent({ house, user: exchanged.user, credential: exchanged.headless_credential });
|
|
133
|
+
await writeOwnAgent({ house, ...relayRecord, user: exchanged.user, credential: exchanged.headless_credential });
|
|
105
134
|
}
|
|
106
135
|
else if (held && ownAgent !== null && ownAgent.user !== exchanged.user) {
|
|
107
136
|
await forgetOwnAgent();
|
|
108
137
|
process.stdout.write("This computer's own agent was another User's; run kit login again to connect it to you.\n");
|
|
109
138
|
}
|
|
110
|
-
|
|
139
|
+
else if (held && ownAgent !== null) {
|
|
140
|
+
await writeOwnAgent({ house, ...relayRecord, user: ownAgent.user, credential: ownAgent.credential });
|
|
141
|
+
}
|
|
142
|
+
await placeAppGit(await readOwnAgent()).catch((error) => process.stderr.write(`kit: ${error.message}\n`));
|
|
111
143
|
try {
|
|
112
144
|
startService();
|
|
113
145
|
}
|
package/dist/logout.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { HouseRefusal, post } from './api.js';
|
|
2
|
-
import { forgetAppGit } from './app-git.js';
|
|
3
2
|
import { forgetEnrolment, forgetOwnAgent, readEnrolment } from './home.js';
|
|
4
3
|
export async function logout() {
|
|
5
4
|
const enrolled = await readEnrolment();
|
|
@@ -13,7 +12,6 @@ export async function logout() {
|
|
|
13
12
|
}
|
|
14
13
|
await forgetEnrolment(enrolled);
|
|
15
14
|
}
|
|
16
|
-
await forgetAppGit();
|
|
17
15
|
await forgetOwnAgent();
|
|
18
16
|
process.stdout.write(enrolled === null
|
|
19
17
|
? 'This computer is not connected to House.\n'
|
package/dist/mcp.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
|
-
import {
|
|
2
|
+
import { KIT_RELEASE } from './clis.js';
|
|
3
3
|
import { relayed } from './relay.js';
|
|
4
4
|
const MCP_PROTOCOL_VERSION = '2026-07-28';
|
|
5
5
|
export const UNREACHABLE = 'House is unreachable; call again in a minute';
|
|
6
|
+
export class Unsettled extends Error {
|
|
7
|
+
}
|
|
6
8
|
export function rpc(method, params) {
|
|
7
9
|
return { jsonrpc: '2.0', id: randomUUID(), method, params };
|
|
8
10
|
}
|
|
@@ -13,7 +15,7 @@ export function mcpBody(message, operation) {
|
|
|
13
15
|
...message.params,
|
|
14
16
|
_meta: {
|
|
15
17
|
'io.modelcontextprotocol/protocolVersion': MCP_PROTOCOL_VERSION,
|
|
16
|
-
'io.modelcontextprotocol/clientInfo': { name: '@agentshouse/kit', version:
|
|
18
|
+
'io.modelcontextprotocol/clientInfo': { name: '@agentshouse/kit', version: KIT_RELEASE },
|
|
17
19
|
'io.modelcontextprotocol/clientCapabilities': {},
|
|
18
20
|
...(operation === null ? {} : { 'agents.house/agent-operation': operation }),
|
|
19
21
|
},
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { run } from './clis.js';
|
|
4
|
+
import { kitHome } from './home.js';
|
|
5
|
+
export function service() {
|
|
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
|
+
function recorded(name) {
|
|
22
|
+
try {
|
|
23
|
+
return readFileSync(join(kitHome(), name), 'utf8').trim();
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
if (error.code === 'ENOENT')
|
|
27
|
+
return null;
|
|
28
|
+
throw error;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export function installCommand() {
|
|
32
|
+
return recorded('install-command');
|
|
33
|
+
}
|
|
34
|
+
export function machine() {
|
|
35
|
+
const placed = recorded('placement');
|
|
36
|
+
if (placed === 'container' || placed === 'server' || placed === 'windows')
|
|
37
|
+
return placed;
|
|
38
|
+
return process.platform === 'darwin' ? 'macos' : 'linux';
|
|
39
|
+
}
|
package/dist/relay.js
CHANGED
|
@@ -2,7 +2,7 @@ let selected;
|
|
|
2
2
|
export function selectRelay(relay) {
|
|
3
3
|
selected = relay === undefined || relay === '' ? null : relay;
|
|
4
4
|
}
|
|
5
|
-
function relayOrigin() {
|
|
5
|
+
export function relayOrigin() {
|
|
6
6
|
if (selected !== undefined)
|
|
7
7
|
return selected ?? undefined;
|
|
8
8
|
const ambient = process.env.HOUSE_KIT_RELAY;
|
package/dist/resident.js
CHANGED
|
@@ -1,22 +1,25 @@
|
|
|
1
1
|
import { once } from 'node:events';
|
|
2
2
|
import { watch } from 'node:fs';
|
|
3
3
|
import { mkdir, rm, writeFile } from 'node:fs/promises';
|
|
4
|
-
import { createServer } from 'node:http';
|
|
4
|
+
import { createServer, get } from 'node:http';
|
|
5
5
|
import { dirname, extname, join } from 'node:path';
|
|
6
|
+
import { DatabaseSync } from 'node:sqlite';
|
|
6
7
|
import { fileURLToPath } from 'node:url';
|
|
7
8
|
import { Agents } from './agents.js';
|
|
8
9
|
import { house } from './api.js';
|
|
9
10
|
import { received } from './bridge.js';
|
|
10
|
-
import { Conversations } from './conversations.js';
|
|
11
|
+
import { CONVERSATION_METHODS, Conversations } from './conversations.js';
|
|
11
12
|
import { LocalCopies } from './copies.js';
|
|
12
13
|
import { restart } from './end.js';
|
|
13
|
-
import { agentBase, enrolled, forgetRestart, kitHome, restartAsked } from './home.js';
|
|
14
|
+
import { agentBase, enrolled, forgetRestart, kitHome, ownerLock, ownerSocket, restartAsked } from './home.js';
|
|
15
|
+
import { Calls } from './calls.js';
|
|
14
16
|
import { killDescendants } from './scope.js';
|
|
15
17
|
import { quoted } from './shell.js';
|
|
16
18
|
import { SignIns } from './sign-in.js';
|
|
17
19
|
import { placeSkillSet } from './skills.js';
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
+
import { holdConnection } from './connection.js';
|
|
21
|
+
import { KitUpdate } from './update.js';
|
|
22
|
+
import { WebWizards } from './web-wizard.js';
|
|
20
23
|
import { codexLauncher } from './work.js';
|
|
21
24
|
function report(error) {
|
|
22
25
|
process.stderr.write(`kit: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
@@ -29,13 +32,32 @@ async function installShim(path, module) {
|
|
|
29
32
|
await mkdir(dirname(path), { recursive: true });
|
|
30
33
|
await writeFile(path, `#!/bin/sh\nexec ${quoted(process.execPath)} ${quoted(main)} "$@"\n`, { mode: 0o755 });
|
|
31
34
|
}
|
|
35
|
+
function claimed(lock) {
|
|
36
|
+
try {
|
|
37
|
+
lock.exec('BEGIN EXCLUSIVE');
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
if (error.errcode === 5)
|
|
42
|
+
return false;
|
|
43
|
+
throw error;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
32
46
|
async function serveOwner(copies) {
|
|
33
|
-
const
|
|
34
|
-
|
|
47
|
+
const lock = new DatabaseSync(ownerLock());
|
|
48
|
+
if (!claimed(lock)) {
|
|
49
|
+
lock.close();
|
|
50
|
+
const running = await runningResident();
|
|
51
|
+
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`);
|
|
52
|
+
}
|
|
35
53
|
const server = createServer(async (request, response) => {
|
|
36
54
|
try {
|
|
37
55
|
const text = await received(request);
|
|
38
56
|
let answered;
|
|
57
|
+
if (request.url === '/resident') {
|
|
58
|
+
response.writeHead(200, { 'content-type': 'application/json' }).end(JSON.stringify({ pid: process.pid }));
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
39
61
|
if (request.url === '/git/fetch') {
|
|
40
62
|
answered = await copies.fetch();
|
|
41
63
|
}
|
|
@@ -53,9 +75,23 @@ async function serveOwner(copies) {
|
|
|
53
75
|
response.writeHead(502).end(error instanceof Error ? error.message : String(error));
|
|
54
76
|
}
|
|
55
77
|
});
|
|
56
|
-
server.
|
|
78
|
+
server.on('close', () => lock.close());
|
|
79
|
+
await rm(ownerSocket(), { force: true });
|
|
80
|
+
server.listen(ownerSocket());
|
|
57
81
|
await once(server, 'listening');
|
|
58
82
|
}
|
|
83
|
+
function runningResident() {
|
|
84
|
+
return new Promise((resolve, reject) => {
|
|
85
|
+
get({ socketPath: ownerSocket(), path: '/resident' }, (answer) => {
|
|
86
|
+
received(answer).then((text) => resolve(JSON.parse(text).pid), reject);
|
|
87
|
+
}).on('error', (error) => {
|
|
88
|
+
if (error.code === 'ENOENT' || error.code === 'ECONNREFUSED')
|
|
89
|
+
resolve(null);
|
|
90
|
+
else
|
|
91
|
+
reject(error);
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
}
|
|
59
95
|
function connected() {
|
|
60
96
|
return new Promise((resolve) => {
|
|
61
97
|
const watcher = watch(kitHome(), () => {
|
|
@@ -72,7 +108,7 @@ function connected() {
|
|
|
72
108
|
resolve();
|
|
73
109
|
});
|
|
74
110
|
}
|
|
75
|
-
|
|
111
|
+
async function started() {
|
|
76
112
|
await connected();
|
|
77
113
|
await forgetRestart();
|
|
78
114
|
watch(kitHome(), () => {
|
|
@@ -83,16 +119,23 @@ export async function resident() {
|
|
|
83
119
|
});
|
|
84
120
|
await placeSkillSet();
|
|
85
121
|
await mkdir(agentBase(), { recursive: true });
|
|
86
|
-
process.env.HOUSE_KIT_RESIDENT = String(process.pid);
|
|
87
|
-
const agents = new Agents(house);
|
|
88
|
-
const copies = new LocalCopies(house);
|
|
89
|
-
await copies.load();
|
|
90
122
|
await installShim(join(kitHome(), 'shim', 'git'), 'git-main');
|
|
91
123
|
await installShim(codexLauncher(), 'codex-main');
|
|
124
|
+
}
|
|
125
|
+
export async function resident() {
|
|
126
|
+
await mkdir(kitHome(), { recursive: true, mode: 0o700 });
|
|
127
|
+
const copies = new LocalCopies(house);
|
|
128
|
+
await copies.load();
|
|
92
129
|
await serveOwner(copies);
|
|
93
|
-
|
|
130
|
+
await started().catch((error) => {
|
|
131
|
+
report(error);
|
|
132
|
+
process.exit(1);
|
|
133
|
+
});
|
|
134
|
+
process.env.HOUSE_KIT_RESIDENT = String(process.pid);
|
|
135
|
+
const agents = new Agents(house, () => changed());
|
|
136
|
+
let connection = null;
|
|
94
137
|
let reported = false;
|
|
95
|
-
const idle = () => conversations.idle() &&
|
|
138
|
+
const idle = () => calls.idle() && conversations.idle() && agents.idle();
|
|
96
139
|
const changed = () => {
|
|
97
140
|
if (!idle()) {
|
|
98
141
|
reported = false;
|
|
@@ -105,15 +148,18 @@ export async function resident() {
|
|
|
105
148
|
logged(house.deliver('/kit/idle', {}, idle));
|
|
106
149
|
}
|
|
107
150
|
};
|
|
151
|
+
const calls = new Calls(house, changed);
|
|
108
152
|
const conversations = new Conversations({
|
|
109
153
|
house,
|
|
110
154
|
agents,
|
|
111
155
|
copies,
|
|
112
|
-
|
|
156
|
+
calls,
|
|
157
|
+
send: (notification) => connection?.send(notification) ?? false,
|
|
113
158
|
changed,
|
|
114
159
|
});
|
|
115
|
-
const signIns = new SignIns(house, agents,
|
|
116
|
-
const
|
|
160
|
+
const signIns = new SignIns(house, agents, calls);
|
|
161
|
+
const update = new KitUpdate(calls);
|
|
162
|
+
const wizards = new WebWizards(calls, (notification) => connection?.send(notification) ?? false);
|
|
117
163
|
for (const signal of ['SIGTERM', 'SIGINT']) {
|
|
118
164
|
process.once(signal, () => {
|
|
119
165
|
killDescendants();
|
|
@@ -121,28 +167,37 @@ export async function resident() {
|
|
|
121
167
|
});
|
|
122
168
|
}
|
|
123
169
|
await house.deliver('/kit/restarted', {}).catch(report);
|
|
124
|
-
await
|
|
170
|
+
await update.resumed().catch(report);
|
|
125
171
|
logged(agents.refresh());
|
|
126
|
-
|
|
172
|
+
connection = holdConnection({
|
|
127
173
|
opened: () => {
|
|
128
174
|
conversations.opened();
|
|
129
175
|
changed();
|
|
130
176
|
logged(copies.connected());
|
|
131
177
|
},
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
178
|
+
closed: () => wizards.disconnected(),
|
|
179
|
+
call: (call) => {
|
|
180
|
+
if (call.kind === 'sign_in')
|
|
181
|
+
signIns.start(call);
|
|
182
|
+
else if (call.kind === 'update')
|
|
183
|
+
update.start(call);
|
|
184
|
+
else if (call.kind === 'run_wizard')
|
|
185
|
+
wizards.start(call);
|
|
186
|
+
else if (CONVERSATION_METHODS.has(call.kind))
|
|
187
|
+
conversations.call(call);
|
|
188
|
+
else {
|
|
189
|
+
const refused = { refused: `This Kit does not know ${call.kind}; update the Kit` };
|
|
190
|
+
void calls.carry(call.input_id, async () => ({ result: refused }));
|
|
145
191
|
}
|
|
146
192
|
},
|
|
193
|
+
notification: (notification) => {
|
|
194
|
+
if (notification.type === 'watching')
|
|
195
|
+
conversations.watching(notification.watching === true);
|
|
196
|
+
if (notification.type === 'authority_changed')
|
|
197
|
+
logged(copies.changed(notification.rooms));
|
|
198
|
+
if (notification.type === 'work_available' && notification.subject === 'agents')
|
|
199
|
+
logged(agents.refresh());
|
|
200
|
+
wizards.notified(notification);
|
|
201
|
+
},
|
|
147
202
|
});
|
|
148
203
|
}
|
package/dist/scope.js
CHANGED
|
@@ -4,6 +4,7 @@ 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
|
}
|
package/dist/service.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { spawnSync } from 'node:child_process';
|
|
2
|
+
import { existsSync, realpathSync } from 'node:fs';
|
|
3
|
+
import { resolve } from 'node:path';
|
|
4
|
+
import { kitHome } from './home.js';
|
|
2
5
|
const UNIT = 'house-kit.service';
|
|
3
6
|
// launchctl and systemctl answer at once, so ten seconds only bounds a stuck service manager.
|
|
4
7
|
const MANAGER_MS = 10_000;
|
|
@@ -10,7 +13,21 @@ function start(command, args) {
|
|
|
10
13
|
if (started.status === 0)
|
|
11
14
|
return;
|
|
12
15
|
const cause = started.error?.message ?? (started.stderr.trim() || `${command} exited with ${started.status ?? 'a signal'}`);
|
|
13
|
-
throw new Error(`the
|
|
16
|
+
throw new Error(`the Kit service could not be started: ${cause}`);
|
|
17
|
+
}
|
|
18
|
+
function physical(path) {
|
|
19
|
+
return existsSync(path) ? realpathSync(path) : resolve(path);
|
|
20
|
+
}
|
|
21
|
+
function systemdHome(environment) {
|
|
22
|
+
for (const [, quoted, bare] of environment.matchAll(/"((?:[^"\\]|\\.)*)"|(\S+)/g)) {
|
|
23
|
+
const assignment = bare ?? quoted.replace(/\\(.)/g, '$1');
|
|
24
|
+
if (assignment.startsWith('HOUSE_KIT_HOME='))
|
|
25
|
+
return assignment.slice('HOUSE_KIT_HOME='.length);
|
|
26
|
+
}
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
function runsThisHome(served) {
|
|
30
|
+
return served !== undefined && physical(served) === physical(kitHome());
|
|
14
31
|
}
|
|
15
32
|
export function startService() {
|
|
16
33
|
if (process.platform === 'darwin') {
|
|
@@ -18,12 +35,17 @@ export function startService() {
|
|
|
18
35
|
const printed = manage('launchctl', ['print', service]);
|
|
19
36
|
if (printed.status !== 0 || /^\tstate = running$/m.test(printed.stdout))
|
|
20
37
|
return false;
|
|
38
|
+
if (!runsThisHome(/^\t+HOUSE_KIT_HOME => (.+)$/m.exec(printed.stdout)?.[1]))
|
|
39
|
+
return false;
|
|
21
40
|
start('launchctl', ['kickstart', service]);
|
|
22
41
|
return true;
|
|
23
42
|
}
|
|
24
43
|
for (const scope of [['--user'], []]) {
|
|
25
44
|
if (manage('systemctl', [...scope, 'is-enabled', '--quiet', UNIT]).status !== 0)
|
|
26
45
|
continue;
|
|
46
|
+
const environment = manage('systemctl', [...scope, 'show', '--property=Environment', '--value', UNIT]).stdout;
|
|
47
|
+
if (!runsThisHome(systemdHome(environment)))
|
|
48
|
+
continue;
|
|
27
49
|
if (manage('systemctl', [...scope, 'is-active', '--quiet', UNIT]).status === 0)
|
|
28
50
|
return false;
|
|
29
51
|
start('systemctl', [...scope, 'start', UNIT]);
|
package/dist/sign-in.js
CHANGED
|
@@ -9,68 +9,50 @@ const CODE = /^[A-Z0-9]+-[A-Z0-9]+$/;
|
|
|
9
9
|
function causeOf(error) {
|
|
10
10
|
return error instanceof Error ? error.message : String(error);
|
|
11
11
|
}
|
|
12
|
-
function logged(error) {
|
|
13
|
-
process.stderr.write(`kit: ${causeOf(error)}\n`);
|
|
14
|
-
}
|
|
15
12
|
function endOf(signal) {
|
|
16
13
|
return new Promise((resolve) => signal.addEventListener('abort', () => resolve(true), { once: true }));
|
|
17
14
|
}
|
|
18
15
|
export class SignIns {
|
|
19
16
|
house;
|
|
20
17
|
agents;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
constructor(house, agents, changed) {
|
|
18
|
+
calls;
|
|
19
|
+
constructor(house, agents, calls) {
|
|
24
20
|
this.house = house;
|
|
25
21
|
this.agents = agents;
|
|
26
|
-
this.
|
|
27
|
-
}
|
|
28
|
-
idle() {
|
|
29
|
-
return this.running.size === 0;
|
|
22
|
+
this.calls = calls;
|
|
30
23
|
}
|
|
31
|
-
start(
|
|
32
|
-
|
|
33
|
-
return;
|
|
34
|
-
this.running.add(input.input_id);
|
|
35
|
-
this.changed();
|
|
36
|
-
this.signIn(input)
|
|
37
|
-
.catch(logged)
|
|
38
|
-
.finally(() => {
|
|
39
|
-
this.running.delete(input.input_id);
|
|
40
|
-
this.changed();
|
|
41
|
-
});
|
|
24
|
+
start(call) {
|
|
25
|
+
void this.calls.carry(call.input_id, () => this.signIn(call));
|
|
42
26
|
}
|
|
43
|
-
async signIn(
|
|
27
|
+
async signIn(call) {
|
|
44
28
|
const ending = new AbortController();
|
|
45
29
|
// House stops waiting for a sign-in ten minutes after it wrote it and sends the seconds left, so its install and login end with the page.
|
|
46
|
-
const timer = setTimeout(() => ending.abort(),
|
|
47
|
-
const ended = await Promise.race([this.signedIn(
|
|
30
|
+
const timer = setTimeout(() => ending.abort(), call.ends_in * 1000);
|
|
31
|
+
const ended = await Promise.race([this.signedIn(call, ending.signal), endOf(ending.signal)]);
|
|
48
32
|
clearTimeout(timer);
|
|
49
33
|
if (ended)
|
|
50
|
-
process.stderr.write(`kit: the ${
|
|
51
|
-
|
|
52
|
-
if (!ended)
|
|
53
|
-
await this.agents.reread(input.cli);
|
|
34
|
+
process.stderr.write(`kit: the ${call.cli} sign-in reached the end House set for it\n`);
|
|
35
|
+
return ended ? { result: {} } : { result: {}, returned: () => this.agents.reread(call.cli) };
|
|
54
36
|
}
|
|
55
|
-
async signedIn(
|
|
56
|
-
await this.login(
|
|
37
|
+
async signedIn(call, signal) {
|
|
38
|
+
await this.login(call, signal);
|
|
57
39
|
if (!signal.aborted)
|
|
58
|
-
await this.agents.recheck(
|
|
40
|
+
await this.agents.recheck(call.cli, signal);
|
|
59
41
|
return false;
|
|
60
42
|
}
|
|
61
|
-
async login(
|
|
43
|
+
async login(call, signal) {
|
|
62
44
|
let cli;
|
|
63
45
|
try {
|
|
64
|
-
cli = await this.agents.located(
|
|
46
|
+
cli = await this.agents.located(call.cli, signal);
|
|
65
47
|
}
|
|
66
48
|
catch (error) {
|
|
67
49
|
if (!signal.aborted)
|
|
68
|
-
process.stderr.write(`kit: the ${
|
|
50
|
+
process.stderr.write(`kit: the ${call.cli} sign-in failed: ${causeOf(error)}\n`);
|
|
69
51
|
return;
|
|
70
52
|
}
|
|
71
53
|
if (signal.aborted)
|
|
72
54
|
return;
|
|
73
|
-
const login = CLIS[
|
|
55
|
+
const login = CLIS[call.cli].login;
|
|
74
56
|
const child = spawn(cli, login.args, {
|
|
75
57
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
76
58
|
detached: true,
|
|
@@ -102,7 +84,7 @@ export class SignIns {
|
|
|
102
84
|
return;
|
|
103
85
|
held = true;
|
|
104
86
|
const steps = [{ kind: 'visit', label: 'Open this link and sign in', url: link }, step];
|
|
105
|
-
void holdSecretInput(this.house,
|
|
87
|
+
void holdSecretInput(this.house, call.input_id, steps, running).then((content) => {
|
|
106
88
|
if (!running())
|
|
107
89
|
return;
|
|
108
90
|
if (content === null)
|
|
@@ -119,6 +101,6 @@ export class SignIns {
|
|
|
119
101
|
});
|
|
120
102
|
signal.removeEventListener('abort', stop);
|
|
121
103
|
if (failed !== null && !signal.aborted)
|
|
122
|
-
process.stderr.write(`kit: the ${
|
|
104
|
+
process.stderr.write(`kit: the ${call.cli} sign-in failed: ${failed}\n`);
|
|
123
105
|
}
|
|
124
106
|
}
|