@agentshouse/kit 0.2.1-cca496635583e → 0.2.1-ccb257fa8a318
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 +85 -18
- package/dist/agents.js +110 -23
- package/dist/api.js +5 -1
- package/dist/app-git.js +10 -26
- package/dist/authority-main.js +2 -2
- package/dist/bridge.js +4 -7
- package/dist/building.js +46 -0
- package/dist/calls.js +71 -0
- package/dist/chatgpt.js +32 -0
- package/dist/clis-main.js +2 -2
- package/dist/clis.js +87 -22
- package/dist/connection.js +116 -0
- package/dist/conversations.js +480 -159
- package/dist/copies.js +89 -52
- package/dist/end.js +11 -2
- package/dist/events.js +6 -2
- package/dist/files.js +139 -31
- package/dist/git.js +13 -11
- package/dist/home.js +56 -5
- package/dist/house-cli.js +299 -0
- package/dist/house-main.js +7 -189
- package/dist/instructions.js +7 -11
- package/dist/kit-cli.js +68 -0
- package/dist/kit-main.js +8 -22
- package/dist/login.js +50 -16
- package/dist/logout.js +0 -2
- package/dist/mcp.js +6 -2
- package/dist/parts.js +34 -16
- package/dist/placement.js +39 -0
- package/dist/relay.js +22 -1
- package/dist/resident.js +94 -34
- package/dist/scope.js +3 -0
- package/dist/scripts.js +255 -0
- package/dist/service.js +23 -1
- package/dist/sign-in.js +22 -39
- package/dist/silence.js +28 -0
- package/dist/skills.js +49 -35
- package/dist/transcription.js +85 -45
- package/dist/translate.js +2 -8
- package/dist/update.js +115 -53
- package/dist/wire.js +22 -0
- package/dist/work.js +3 -5
- package/package.json +20 -20
- package/dist/bootstrap.json +0 -24
- 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-cli.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { parseArgs } from 'node:util';
|
|
2
|
+
import { answerGitCredential } from './app-git.js';
|
|
3
|
+
import { chatgpt } from './chatgpt.js';
|
|
4
|
+
import { login } from './login.js';
|
|
5
|
+
import { logout } from './logout.js';
|
|
6
|
+
import { proxyUnlessRelayed } from './relay.js';
|
|
7
|
+
import { resident } from './resident.js';
|
|
8
|
+
const USAGE = 'usage: kit <login|logout|resident|chatgpt>\n';
|
|
9
|
+
const COMMANDS = new Map([
|
|
10
|
+
[
|
|
11
|
+
'logout',
|
|
12
|
+
{
|
|
13
|
+
usage: 'usage: kit logout',
|
|
14
|
+
about: "disconnects this computer, stops the Kit process and ends your own agent's connection",
|
|
15
|
+
operands: 0,
|
|
16
|
+
run: logout,
|
|
17
|
+
},
|
|
18
|
+
],
|
|
19
|
+
[
|
|
20
|
+
'resident',
|
|
21
|
+
{
|
|
22
|
+
usage: 'usage: kit resident',
|
|
23
|
+
about: "keeps this Environment connected; Kit's service runs it",
|
|
24
|
+
operands: 0,
|
|
25
|
+
run: resident,
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
[
|
|
29
|
+
'git-credential',
|
|
30
|
+
{
|
|
31
|
+
usage: 'usage: kit git-credential <get|store|erase>',
|
|
32
|
+
about: "answers git with your own agent's House credential; git runs it",
|
|
33
|
+
operands: 1,
|
|
34
|
+
run: ([operation]) => answerGitCredential(operation),
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
]);
|
|
38
|
+
const [command, ...argv] = process.argv.slice(2);
|
|
39
|
+
proxyUnlessRelayed();
|
|
40
|
+
async function run() {
|
|
41
|
+
if (command === 'login')
|
|
42
|
+
return login(argv);
|
|
43
|
+
if (command === 'chatgpt')
|
|
44
|
+
return chatgpt(argv);
|
|
45
|
+
if (command === '--help') {
|
|
46
|
+
parseArgs({ args: argv });
|
|
47
|
+
process.stdout.write(USAGE);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const chosen = COMMANDS.get(command ?? '');
|
|
51
|
+
if (chosen === undefined) {
|
|
52
|
+
process.stderr.write(USAGE);
|
|
53
|
+
process.exitCode = 2;
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const { values, positionals } = parseArgs({ args: argv, options: { help: { type: 'boolean', default: false } }, allowPositionals: true });
|
|
57
|
+
if (positionals.length > chosen.operands)
|
|
58
|
+
throw new Error(`unexpected argument ${positionals[chosen.operands]}; ${chosen.usage}`);
|
|
59
|
+
if (values.help) {
|
|
60
|
+
process.stdout.write(`${chosen.usage}\n ${chosen.about}\n`);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
return chosen.run(positionals);
|
|
64
|
+
}
|
|
65
|
+
run().catch((error) => {
|
|
66
|
+
process.stderr.write(`kit: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
67
|
+
process.exitCode = 1;
|
|
68
|
+
});
|
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, patch = 0] = process.versions.node.split('.').map(Number);
|
|
3
|
+
if (major < 24 || (major === 24 && (minor < 22 || (minor === 22 && patch < 1)))) {
|
|
4
|
+
process.stderr.write(`kit: the Kit needs Node 24.22.1 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,17 @@
|
|
|
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
|
+
import { endUnserved } from './wire.js';
|
|
14
|
+
export const DEFAULT_HOUSE = 'https://agents.house';
|
|
12
15
|
const OPENER = process.platform === 'darwin' ? 'open' : 'xdg-open';
|
|
13
16
|
// Polling every two seconds brings the User's confirmation to the waiting Kit moments after they give it.
|
|
14
17
|
const POLL_INTERVAL_MS = 2000;
|
|
@@ -17,21 +20,33 @@ function open(link) {
|
|
|
17
20
|
.on('error', () => undefined)
|
|
18
21
|
.unref();
|
|
19
22
|
}
|
|
20
|
-
async function accepted(house, credential) {
|
|
23
|
+
export async function accepted(house, credential) {
|
|
21
24
|
const checked = await callHouse(house, credential, rpc('tools/list', {}));
|
|
22
25
|
if (checked.status === 200)
|
|
23
26
|
return true;
|
|
24
27
|
if (checked.status === 401)
|
|
25
28
|
return false;
|
|
29
|
+
endUnserved(checked.text);
|
|
26
30
|
throw new Error(`House answered ${checked.status} when Kit checked this computer's own agent's connection: ${checked.text}`);
|
|
27
31
|
}
|
|
28
|
-
const USAGE = `usage: kit login [--house <origin>] [--environment <id>] [--rooms <ref>[,<ref>...] | --no-private]
|
|
32
|
+
const USAGE = `usage: kit login [--house <origin>] [--environment <id>] [--rooms <ref>[,<ref>...] | --no-private]
|
|
33
|
+
kit login [--house <origin>] --code <code>
|
|
29
34
|
--house <origin> the House to connect to, ${DEFAULT_HOUSE} unless one is stored
|
|
30
35
|
--environment <id> reconnect this Environment
|
|
31
36
|
--rooms <ref>[,<ref>...] give this Environment only these Rooms
|
|
32
37
|
--no-private give this Environment every Room but your Private Room
|
|
33
38
|
--code <code> connect this machine with a login code
|
|
34
39
|
`;
|
|
40
|
+
function connected(house, named, environment) {
|
|
41
|
+
if (named === undefined)
|
|
42
|
+
return `Environment ${environment} is connected to ${house}.\n`;
|
|
43
|
+
if (named === environment)
|
|
44
|
+
return `Environment ${environment} is reconnected to ${house}.\n`;
|
|
45
|
+
return `Environment ${named} stays with its account; this computer is connected to ${house} as new Environment ${environment} of the account that confirmed.\n`;
|
|
46
|
+
}
|
|
47
|
+
function gone(error) {
|
|
48
|
+
return error instanceof HouseRefusal && refusalOf(error.text)?.code === 'kit_environment_not_found';
|
|
49
|
+
}
|
|
35
50
|
function chosenRooms(rooms, noPrivate) {
|
|
36
51
|
if (rooms !== undefined && noPrivate)
|
|
37
52
|
throw new Error('--rooms and --no-private are two choices of Rooms; pass one');
|
|
@@ -70,44 +85,63 @@ export async function login(argv) {
|
|
|
70
85
|
selectRelay(relay);
|
|
71
86
|
const house = values.house ?? enrolled?.house ?? DEFAULT_HOUSE;
|
|
72
87
|
const replaces = process.env.HOUSE_KIT_REPLACES;
|
|
73
|
-
const
|
|
88
|
+
const remembered = replaces === undefined && values.environment === undefined && enrolled?.house === house ? enrolled.environment : undefined;
|
|
89
|
+
const environment = replaces === undefined ? (values.environment ?? remembered) : undefined;
|
|
74
90
|
const ownAgent = await readOwnAgent();
|
|
75
91
|
let held = false;
|
|
92
|
+
let named = environment;
|
|
76
93
|
let exchanged;
|
|
77
94
|
if (values.code !== undefined) {
|
|
78
|
-
exchanged = await post(house, '/kit/token', { code: values.code
|
|
95
|
+
exchanged = await post(house, '/kit/token', { code: values.code });
|
|
79
96
|
}
|
|
80
97
|
else {
|
|
81
98
|
held = ownAgent !== null && ownAgent.house === house && (await accepted(house, ownAgent.credential));
|
|
82
99
|
const verifier = randomBytes(32).toString('base64url');
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
...(environment === undefined
|
|
100
|
+
const start = () => retrying(() => post(house, '/kit', {
|
|
101
|
+
...(named === undefined
|
|
86
102
|
? { act: 'new_environment', ...(replaces === undefined ? {} : { replaces }) }
|
|
87
|
-
: { act: 'existing_environment', environment_id:
|
|
103
|
+
: { act: 'existing_environment', environment_id: named }),
|
|
88
104
|
...rooms,
|
|
89
105
|
code_challenge: createHash('sha256').update(verifier).digest('base64url'),
|
|
90
106
|
...(held ? {} : { headless: true }),
|
|
91
107
|
}));
|
|
108
|
+
let started;
|
|
109
|
+
try {
|
|
110
|
+
started = await start();
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
if (remembered === undefined || !gone(error))
|
|
114
|
+
throw error;
|
|
115
|
+
await forgetDisconnected();
|
|
116
|
+
process.stdout.write(`House no longer holds Environment ${remembered}; connecting this computer as a new one.\n`);
|
|
117
|
+
named = undefined;
|
|
118
|
+
started = await start();
|
|
119
|
+
}
|
|
92
120
|
process.stdout.write(`Open this link and confirm: ${started.start_url}\n`);
|
|
93
121
|
open(started.start_url);
|
|
94
122
|
exchanged = await retrying(() => post(house, '/kit/token', { login: started.login, code_verifier: verifier }), undefined, () => POLL_INTERVAL_MS);
|
|
95
123
|
}
|
|
124
|
+
await placeSkillSet(house);
|
|
125
|
+
await writeCodexRule().catch((error) => process.stderr.write(`kit: ${error.message}\n`));
|
|
126
|
+
const relayRecord = relay === undefined ? {} : { relay };
|
|
96
127
|
await writeEnrolment({
|
|
97
128
|
house,
|
|
98
|
-
...
|
|
129
|
+
...relayRecord,
|
|
99
130
|
environment: exchanged.environment,
|
|
100
131
|
credential: exchanged.credential,
|
|
101
132
|
});
|
|
102
|
-
process.stdout.write(
|
|
133
|
+
process.stdout.write(connected(house, named, exchanged.environment));
|
|
103
134
|
if (exchanged.headless_credential !== undefined) {
|
|
104
|
-
await writeOwnAgent({ house, user: exchanged.user, credential: exchanged.headless_credential });
|
|
135
|
+
await writeOwnAgent({ house, ...relayRecord, user: exchanged.user, credential: exchanged.headless_credential });
|
|
105
136
|
}
|
|
106
137
|
else if (held && ownAgent !== null && ownAgent.user !== exchanged.user) {
|
|
107
138
|
await forgetOwnAgent();
|
|
108
139
|
process.stdout.write("This computer's own agent was another User's; run kit login again to connect it to you.\n");
|
|
109
140
|
}
|
|
110
|
-
|
|
141
|
+
else if (held && ownAgent !== null) {
|
|
142
|
+
await writeOwnAgent({ house, ...relayRecord, user: ownAgent.user, credential: ownAgent.credential });
|
|
143
|
+
}
|
|
144
|
+
await placeAppGit(await readOwnAgent()).catch((error) => process.stderr.write(`kit: ${error.message}\n`));
|
|
111
145
|
try {
|
|
112
146
|
startService();
|
|
113
147
|
}
|
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,11 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
|
-
import {
|
|
2
|
+
import { KIT_RELEASE } from './clis.js';
|
|
3
3
|
import { relayed } from './relay.js';
|
|
4
|
+
import { KIT_WIRE, KIT_WIRE_HEADER } from './wire.js';
|
|
4
5
|
const MCP_PROTOCOL_VERSION = '2026-07-28';
|
|
5
6
|
export const UNREACHABLE = 'House is unreachable; call again in a minute';
|
|
7
|
+
export class Unsettled extends Error {
|
|
8
|
+
}
|
|
6
9
|
export function rpc(method, params) {
|
|
7
10
|
return { jsonrpc: '2.0', id: randomUUID(), method, params };
|
|
8
11
|
}
|
|
@@ -13,7 +16,7 @@ export function mcpBody(message, operation) {
|
|
|
13
16
|
...message.params,
|
|
14
17
|
_meta: {
|
|
15
18
|
'io.modelcontextprotocol/protocolVersion': MCP_PROTOCOL_VERSION,
|
|
16
|
-
'io.modelcontextprotocol/clientInfo': { name: '@agentshouse/kit', version:
|
|
19
|
+
'io.modelcontextprotocol/clientInfo': { name: '@agentshouse/kit', version: KIT_RELEASE },
|
|
17
20
|
'io.modelcontextprotocol/clientCapabilities': {},
|
|
18
21
|
...(operation === null ? {} : { 'agents.house/agent-operation': operation }),
|
|
19
22
|
},
|
|
@@ -31,6 +34,7 @@ export async function callHouse(origin, credential, message, operation = null, s
|
|
|
31
34
|
'mcp-protocol-version': MCP_PROTOCOL_VERSION,
|
|
32
35
|
'mcp-method': message.method,
|
|
33
36
|
...(tool === null ? {} : { 'mcp-name': tool }),
|
|
37
|
+
[KIT_WIRE_HEADER]: String(KIT_WIRE),
|
|
34
38
|
},
|
|
35
39
|
body: mcpBody(message, operation),
|
|
36
40
|
signal,
|
package/dist/parts.js
CHANGED
|
@@ -2,7 +2,10 @@ export class Parts {
|
|
|
2
2
|
parts = [];
|
|
3
3
|
context = null;
|
|
4
4
|
emit;
|
|
5
|
+
made = [];
|
|
6
|
+
events = 0;
|
|
5
7
|
writing = null;
|
|
8
|
+
counting = null;
|
|
6
9
|
planned = null;
|
|
7
10
|
constructor(emit) {
|
|
8
11
|
this.emit = emit;
|
|
@@ -10,32 +13,34 @@ export class Parts {
|
|
|
10
13
|
write(type, id, text) {
|
|
11
14
|
if (text === '')
|
|
12
15
|
return;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
part.text += text;
|
|
17
|
-
this.emit({ op: 'append', index: last, text });
|
|
16
|
+
if (this.writing?.type === type && this.writing.id === id) {
|
|
17
|
+
this.parts[this.writing.index].text += text;
|
|
18
|
+
this.emit({ op: 'append', index: this.writing.index, text });
|
|
18
19
|
return;
|
|
19
20
|
}
|
|
20
|
-
this.start({ type, text });
|
|
21
|
-
this.writing = { type, id };
|
|
21
|
+
this.writing = { type, id, index: this.start({ type, text }) };
|
|
22
22
|
}
|
|
23
23
|
command() {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
if (part?.type !== 'commands') {
|
|
27
|
-
this.start({ type: 'commands', count: 1 });
|
|
24
|
+
if (this.counting === null) {
|
|
25
|
+
this.counting = this.start({ type: 'commands', count: 1 });
|
|
28
26
|
return;
|
|
29
27
|
}
|
|
28
|
+
const part = this.parts[this.counting];
|
|
30
29
|
part.count++;
|
|
31
|
-
this.emit({ op: 'count', index:
|
|
30
|
+
this.emit({ op: 'count', index: this.counting, count: part.count });
|
|
32
31
|
}
|
|
33
32
|
start(part) {
|
|
34
33
|
this.writing = null;
|
|
35
|
-
this.
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
this.counting = null;
|
|
35
|
+
return this.add(part, ++this.events);
|
|
36
|
+
}
|
|
37
|
+
reserve() {
|
|
38
|
+
this.writing = null;
|
|
39
|
+
this.counting = null;
|
|
40
|
+
return ++this.events;
|
|
41
|
+
}
|
|
42
|
+
arrive(part, reserved) {
|
|
43
|
+
this.add(part, reserved);
|
|
39
44
|
}
|
|
40
45
|
done(index, result) {
|
|
41
46
|
const part = this.parts[index];
|
|
@@ -55,10 +60,23 @@ export class Parts {
|
|
|
55
60
|
this.context = context;
|
|
56
61
|
this.emit({ op: 'context', ...context });
|
|
57
62
|
}
|
|
63
|
+
saved() {
|
|
64
|
+
return this.parts
|
|
65
|
+
.map((part, index) => ({ part, made: this.made[index] }))
|
|
66
|
+
.sort((a, b) => a.made - b.made)
|
|
67
|
+
.map(({ part }) => part);
|
|
68
|
+
}
|
|
58
69
|
operations() {
|
|
59
70
|
return [
|
|
60
71
|
...this.parts.map((part, index) => ({ op: 'start', index, part })),
|
|
61
72
|
...(this.context === null ? [] : [{ op: 'context', ...this.context }]),
|
|
62
73
|
];
|
|
63
74
|
}
|
|
75
|
+
add(part, made) {
|
|
76
|
+
this.parts.push(part);
|
|
77
|
+
this.made.push(made);
|
|
78
|
+
const index = this.parts.length - 1;
|
|
79
|
+
this.emit({ op: 'start', index, part });
|
|
80
|
+
return index;
|
|
81
|
+
}
|
|
64
82
|
}
|
|
@@ -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
|
@@ -1,13 +1,34 @@
|
|
|
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
|
-
function relayOrigin() {
|
|
10
|
+
export function relayOrigin() {
|
|
6
11
|
if (selected !== undefined)
|
|
7
12
|
return selected ?? undefined;
|
|
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,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, readEnrolment, restartAsked } from './home.js';
|
|
15
|
+
import { Calls } from './calls.js';
|
|
14
16
|
import { killDescendants } from './scope.js';
|
|
17
|
+
import { removeInputs, Scripts } from './scripts.js';
|
|
15
18
|
import { quoted } from './shell.js';
|
|
16
19
|
import { SignIns } from './sign-in.js';
|
|
17
20
|
import { placeSkillSet } from './skills.js';
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
21
|
+
import { holdConnection } from './connection.js';
|
|
22
|
+
import { KitUpdate } from './update.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(), () => {
|
|
@@ -81,18 +117,25 @@ export async function resident() {
|
|
|
81
117
|
killDescendants();
|
|
82
118
|
process.exit(1);
|
|
83
119
|
});
|
|
84
|
-
await placeSkillSet();
|
|
120
|
+
await placeSkillSet((await readEnrolment()).house);
|
|
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;
|
|
@@ -100,49 +143,66 @@ export async function resident() {
|
|
|
100
143
|
else if (restartAsked() && conversations.quiet()) {
|
|
101
144
|
restart('restarting for an updated CLI');
|
|
102
145
|
}
|
|
146
|
+
else if (update.held() && conversations.quiet()) {
|
|
147
|
+
update.apply(connection.pause());
|
|
148
|
+
}
|
|
103
149
|
else if (!reported) {
|
|
104
150
|
reported = true;
|
|
105
151
|
logged(house.deliver('/kit/idle', {}, idle));
|
|
106
152
|
}
|
|
107
153
|
};
|
|
154
|
+
const calls = new Calls(house, changed);
|
|
108
155
|
const conversations = new Conversations({
|
|
109
156
|
house,
|
|
110
157
|
agents,
|
|
111
158
|
copies,
|
|
112
|
-
|
|
159
|
+
calls,
|
|
160
|
+
send: (notification) => connection?.send(notification) ?? false,
|
|
113
161
|
changed,
|
|
114
162
|
});
|
|
115
|
-
const signIns = new SignIns(house, agents,
|
|
116
|
-
const
|
|
163
|
+
const signIns = new SignIns(house, agents, calls);
|
|
164
|
+
const update = new KitUpdate(calls, changed);
|
|
165
|
+
removeInputs();
|
|
166
|
+
const scripts = new Scripts(calls, (notification) => connection?.send(notification) ?? false);
|
|
117
167
|
for (const signal of ['SIGTERM', 'SIGINT']) {
|
|
118
168
|
process.once(signal, () => {
|
|
119
169
|
killDescendants();
|
|
170
|
+
removeInputs();
|
|
120
171
|
process.kill(process.pid, signal);
|
|
121
172
|
});
|
|
122
173
|
}
|
|
123
174
|
await house.deliver('/kit/restarted', {}).catch(report);
|
|
124
|
-
await
|
|
175
|
+
await update.resumed().catch(report);
|
|
125
176
|
logged(agents.refresh());
|
|
126
|
-
|
|
177
|
+
connection = holdConnection({
|
|
127
178
|
opened: () => {
|
|
128
179
|
conversations.opened();
|
|
129
180
|
changed();
|
|
130
181
|
logged(copies.connected());
|
|
131
182
|
},
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
183
|
+
closed: () => scripts.disconnected(),
|
|
184
|
+
call: (call) => {
|
|
185
|
+
if (call.kind === 'sign_in')
|
|
186
|
+
signIns.start(call);
|
|
187
|
+
else if (call.kind === 'update')
|
|
188
|
+
update.hold(call);
|
|
189
|
+
else if (call.kind === 'run_wizard' || call.kind === 'run_function')
|
|
190
|
+
scripts.start(call);
|
|
191
|
+
else if (CONVERSATION_METHODS.has(call.kind))
|
|
192
|
+
conversations.call(call);
|
|
193
|
+
else {
|
|
194
|
+
const refused = { refused: `This Kit does not know ${call.kind}; update the Kit` };
|
|
195
|
+
void calls.carry(call.input_id, async () => ({ result: refused }));
|
|
145
196
|
}
|
|
146
197
|
},
|
|
198
|
+
notification: (notification) => {
|
|
199
|
+
if (notification.type === 'watching')
|
|
200
|
+
conversations.watching(notification.watching === true);
|
|
201
|
+
if (notification.type === 'authority_changed')
|
|
202
|
+
logged(copies.changed(notification.rooms));
|
|
203
|
+
if (notification.type === 'work_available' && notification.subject === 'agents')
|
|
204
|
+
logged(agents.refresh());
|
|
205
|
+
scripts.notified(notification);
|
|
206
|
+
},
|
|
147
207
|
});
|
|
148
208
|
}
|