@agentshouse/kit 0.2.1-cca9e1f43de44 → 0.2.1-ccf188e02985d
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 +30 -28
- package/dist/acp.js +41 -111
- package/dist/agents.js +110 -22
- package/dist/api.js +9 -5
- package/dist/app-git.js +10 -26
- package/dist/bootstrap.json +4 -4
- package/dist/bridge.js +10 -24
- package/dist/chatgpt.js +32 -0
- package/dist/clis.js +95 -14
- package/dist/codex-main.js +58 -0
- package/dist/conversations.js +181 -114
- package/dist/copies.js +188 -119
- package/dist/end.js +19 -4
- package/dist/enrol-main.js +7 -1
- package/dist/events.js +14 -76
- package/dist/files.js +8 -2
- package/dist/git.js +10 -8
- package/dist/home.js +96 -7
- package/dist/house-cli.js +291 -0
- package/dist/house-main.js +7 -177
- package/dist/inputs.js +37 -0
- package/dist/instructions.js +10 -32
- package/dist/kit-cli.js +68 -0
- package/dist/kit-main.js +8 -22
- package/dist/login.js +117 -106
- package/dist/logout.js +14 -16
- package/dist/parts.js +34 -16
- package/dist/placement.js +30 -0
- package/dist/relay.js +12 -2
- package/dist/resident.js +89 -33
- package/dist/scope.js +203 -0
- package/dist/service-main.js +9 -0
- package/dist/service.js +55 -0
- package/dist/sign-in.js +6 -24
- package/dist/skills.js +81 -12
- package/dist/stream.js +68 -17
- package/dist/transcription.js +3 -3
- package/dist/update.js +48 -29
- package/dist/wire.js +6 -0
- package/dist/work.js +346 -0
- package/how-we-work.md +13 -3
- package/package.json +3 -2
- package/skills/ask-matt/SKILL.md +17 -11
- package/skills/ask-matt/agents/openai.yaml +1 -0
- package/skills/code-review/SKILL.md +5 -5
- package/skills/codebase-design/DESIGN-IT-TWICE.md +1 -1
- package/skills/codebase-design/SKILL.md +0 -2
- package/skills/diagnosing-bugs/SKILL.md +2 -4
- package/skills/domain-modeling/{CONTEXT-FORMAT.md → GLOSSARY-FORMAT.md} +10 -10
- package/skills/domain-modeling/SKILL.md +12 -14
- package/skills/grill-me/SKILL.md +1 -2
- package/skills/grill-me/agents/openai.yaml +1 -0
- package/skills/grill-with-docs/SKILL.md +1 -2
- package/skills/grill-with-docs/agents/openai.yaml +1 -0
- package/skills/grilling/SKILL.md +2 -2
- package/skills/handoff/SKILL.md +2 -3
- package/skills/handoff/agents/openai.yaml +1 -0
- package/skills/implement/SKILL.md +5 -4
- package/skills/implement/agents/openai.yaml +1 -0
- package/skills/implement-spec/SKILL.md +40 -0
- package/skills/implement-spec/agents/openai.yaml +5 -0
- package/skills/improve-codebase-architecture/SKILL.md +6 -7
- package/skills/improve-codebase-architecture/agents/openai.yaml +1 -0
- package/skills/pr/CREDITS.md +3 -0
- package/skills/pr/LICENSE +21 -0
- package/skills/pr/SKILL.md +170 -0
- package/skills/pr/agents/openai.yaml +3 -0
- package/skills/prototype/SKILL.md +0 -2
- package/skills/research/SKILL.md +0 -2
- package/skills/retro/LICENSE +21 -0
- package/skills/retro/SKILL.md +44 -0
- package/skills/retro/agents/openai.yaml +5 -0
- package/skills/tdd/SKILL.md +2 -4
- package/skills/teach/SKILL.md +3 -4
- package/skills/teach/agents/openai.yaml +1 -0
- package/skills/to-questionnaire/SKILL.md +1 -2
- package/skills/to-questionnaire/agents/openai.yaml +1 -0
- package/skills/to-spec/SKILL.md +1 -2
- package/skills/to-spec/agents/openai.yaml +1 -0
- package/skills/to-tickets/SKILL.md +3 -4
- package/skills/to-tickets/agents/openai.yaml +1 -0
- package/skills/triage/AGENT-BRIEF.md +207 -0
- package/skills/triage/LICENSE +21 -0
- package/skills/triage/OUT-OF-SCOPE.md +105 -0
- package/skills/triage/SKILL.md +112 -0
- package/skills/triage/agents/openai.yaml +5 -0
- package/skills/wait-what/SKILL.md +2 -3
- package/skills/wait-what/agents/openai.yaml +1 -0
- package/skills/wayfinder/SKILL.md +5 -6
- package/skills/wayfinder/agents/openai.yaml +1 -0
- package/skills/wizard/LICENSE +21 -0
- package/skills/wizard/SKILL.md +44 -0
- package/skills/wizard/agents/openai.yaml +3 -0
- package/skills/wizard/template.sh +223 -0
- package/skills/writing-for-agents/SKILL.md +0 -2
- package/skills/resolving-merge-conflicts/SKILL.md +0 -16
- package/skills/resolving-merge-conflicts/agents/openai.yaml +0 -3
- /package/skills/{resolving-merge-conflicts → implement-spec}/LICENSE +0 -0
package/dist/login.js
CHANGED
|
@@ -1,56 +1,26 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
1
2
|
import { createHash, randomBytes } from 'node:crypto';
|
|
2
|
-
import { createServer } from 'node:http';
|
|
3
3
|
import { hostname } from 'node:os';
|
|
4
|
-
import { createInterface } from 'node:readline/promises';
|
|
5
4
|
import { parseArgs } from 'node:util';
|
|
6
|
-
import { post } from './api.js';
|
|
5
|
+
import { HouseRefusal, post, retrying } from './api.js';
|
|
7
6
|
import { placeAppGit } from './app-git.js';
|
|
8
|
-
import {
|
|
7
|
+
import { writeCodexRule } from './clis.js';
|
|
8
|
+
import { forgetDisconnected, forgetOwnAgent, readDisconnected, readEnrolment, readOwnAgent, writeEnrolment, writeOwnAgent, } from './home.js';
|
|
9
9
|
import { callHouse, rpc } from './mcp.js';
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
held = response;
|
|
25
|
-
deliver(received);
|
|
26
|
-
});
|
|
27
|
-
const close = () => {
|
|
28
|
-
server.close();
|
|
29
|
-
server.closeAllConnections();
|
|
30
|
-
};
|
|
31
|
-
const port = Number(process.env.HOUSE_KIT_LOGIN_PORT ?? 0);
|
|
32
|
-
server.once('error', reject);
|
|
33
|
-
server.listen(port, port === 0 ? '127.0.0.1' : '0.0.0.0', () => {
|
|
34
|
-
const address = server.address();
|
|
35
|
-
if (address === null || typeof address === 'string') {
|
|
36
|
-
reject(new Error('the login callback has no port'));
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
resolve({
|
|
40
|
-
uri: `http://127.0.0.1:${address.port}/callback`,
|
|
41
|
-
code,
|
|
42
|
-
answer: (text) => new Promise((written) => {
|
|
43
|
-
if (held === null || held.destroyed || !held.socket || held.socket.destroyed)
|
|
44
|
-
return written();
|
|
45
|
-
held.once('close', () => written());
|
|
46
|
-
held.writeHead(200, { 'content-type': 'text/plain; charset=utf-8', connection: 'close' }).end(`${text}\n`);
|
|
47
|
-
}),
|
|
48
|
-
close,
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
});
|
|
10
|
+
import { refusalOf } from './refusals.js';
|
|
11
|
+
import { selectRelay } from './relay.js';
|
|
12
|
+
import { startService } from './service.js';
|
|
13
|
+
import { placeSkillSet } from './skills.js';
|
|
14
|
+
export const DEFAULT_HOUSE = 'https://agents.house';
|
|
15
|
+
const OPENER = process.platform === 'darwin' ? 'open' : 'xdg-open';
|
|
16
|
+
// Polling every two seconds brings the User's confirmation to the waiting Kit moments after they give it.
|
|
17
|
+
const POLL_INTERVAL_MS = 2000;
|
|
18
|
+
function open(link) {
|
|
19
|
+
spawn(OPENER, [link], { detached: true, stdio: 'ignore' })
|
|
20
|
+
.on('error', () => undefined)
|
|
21
|
+
.unref();
|
|
52
22
|
}
|
|
53
|
-
async function accepted(house, credential) {
|
|
23
|
+
export async function accepted(house, credential) {
|
|
54
24
|
const checked = await callHouse(house, credential, rpc('tools/list', {}));
|
|
55
25
|
if (checked.status === 200)
|
|
56
26
|
return true;
|
|
@@ -58,17 +28,30 @@ async function accepted(house, credential) {
|
|
|
58
28
|
return false;
|
|
59
29
|
throw new Error(`House answered ${checked.status} when Kit checked this computer's own agent's connection: ${checked.text}`);
|
|
60
30
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
31
|
+
const USAGE = `usage: kit login [--house <origin>] [--environment <id>] [--rooms <ref>[,<ref>...] | --no-private]
|
|
32
|
+
kit login [--house <origin>] --code <code>
|
|
33
|
+
--house <origin> the House to connect to, ${DEFAULT_HOUSE} unless one is stored
|
|
34
|
+
--environment <id> reconnect this Environment
|
|
35
|
+
--rooms <ref>[,<ref>...] give this Environment only these Rooms
|
|
36
|
+
--no-private give this Environment every Room but your Private Room
|
|
37
|
+
--code <code> connect this machine with a login code
|
|
38
|
+
`;
|
|
39
|
+
function connected(house, named, environment) {
|
|
40
|
+
if (named === undefined)
|
|
41
|
+
return `Environment ${environment} is connected to ${house}.\n`;
|
|
42
|
+
if (named === environment)
|
|
43
|
+
return `Environment ${environment} is reconnected to ${house}.\n`;
|
|
44
|
+
return `Environment ${named} stays with its account; this computer is connected to ${house} as new Environment ${environment} of the account that confirmed.\n`;
|
|
45
|
+
}
|
|
46
|
+
function gone(error) {
|
|
47
|
+
return error instanceof HouseRefusal && refusalOf(error.text)?.code === 'kit_environment_not_found';
|
|
48
|
+
}
|
|
49
|
+
function chosenRooms(rooms, noPrivate) {
|
|
50
|
+
if (rooms !== undefined && noPrivate)
|
|
51
|
+
throw new Error('--rooms and --no-private are two choices of Rooms; pass one');
|
|
52
|
+
if (rooms !== undefined)
|
|
53
|
+
return { rooms: { reach: 'selected', refs: rooms.split(',') } };
|
|
54
|
+
return noPrivate ? { rooms: { reach: 'all_but_private' } } : {};
|
|
72
55
|
}
|
|
73
56
|
export async function login(argv) {
|
|
74
57
|
const { values } = parseArgs({
|
|
@@ -76,65 +59,93 @@ export async function login(argv) {
|
|
|
76
59
|
options: {
|
|
77
60
|
house: { type: 'string' },
|
|
78
61
|
environment: { type: 'string' },
|
|
79
|
-
|
|
62
|
+
rooms: { type: 'string' },
|
|
63
|
+
'no-private': { type: 'boolean', default: false },
|
|
64
|
+
code: { type: 'string' },
|
|
65
|
+
help: { type: 'boolean', default: false },
|
|
80
66
|
},
|
|
81
67
|
});
|
|
68
|
+
if (values.help) {
|
|
69
|
+
process.stdout.write(USAGE);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
if (values.code !== undefined && values.rooms !== undefined)
|
|
73
|
+
throw new Error('--code cannot be used with --rooms');
|
|
74
|
+
if (values.code !== undefined && values['no-private'])
|
|
75
|
+
throw new Error('--code cannot be used with --no-private');
|
|
76
|
+
if (values.code !== undefined && values.environment !== undefined)
|
|
77
|
+
throw new Error('--code cannot be used with --environment');
|
|
78
|
+
const rooms = chosenRooms(values.rooms, values['no-private']);
|
|
82
79
|
const enrolled = (await readEnrolment()) ?? (await readDisconnected());
|
|
80
|
+
if (values.code !== undefined && enrolled !== null) {
|
|
81
|
+
throw new Error(`--code connects a new machine; this Kit home records Environment ${enrolled.environment}, so run kit login to reconnect it`);
|
|
82
|
+
}
|
|
83
|
+
const relay = process.env.HOUSE_KIT_RELAY || undefined;
|
|
84
|
+
selectRelay(relay);
|
|
83
85
|
const house = values.house ?? enrolled?.house ?? DEFAULT_HOUSE;
|
|
84
86
|
const replaces = process.env.HOUSE_KIT_REPLACES;
|
|
85
|
-
const
|
|
87
|
+
const remembered = replaces === undefined && values.environment === undefined && enrolled?.house === house ? enrolled.environment : undefined;
|
|
88
|
+
const environment = replaces === undefined ? (values.environment ?? remembered) : undefined;
|
|
86
89
|
const ownAgent = await readOwnAgent();
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
: { act: 'existing_environment', environment_id: environment }),
|
|
93
|
-
code_challenge: createHash('sha256').update(verifier).digest('base64url'),
|
|
94
|
-
...(held ? {} : { headless: true }),
|
|
95
|
-
};
|
|
96
|
-
const exchange = async (code) => {
|
|
97
|
-
const exchanged = await post(house, '/kit/token', { code, code_verifier: verifier });
|
|
98
|
-
await writeEnrolment({ house, environment: exchanged.environment, credential: exchanged.credential });
|
|
99
|
-
process.stdout.write(`Environment ${exchanged.environment} is connected to ${house}.\n`);
|
|
100
|
-
if (exchanged.headless_credential !== undefined) {
|
|
101
|
-
await writeOwnAgent({ house, user: exchanged.user, credential: exchanged.headless_credential });
|
|
102
|
-
}
|
|
103
|
-
else if (held && ownAgent.user !== exchanged.user) {
|
|
104
|
-
await forgetOwnAgent();
|
|
105
|
-
process.stdout.write("This computer's own agent was another User's; run kit login again to connect it to you.\n");
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
const placeGit = async () => placeAppGit(ownAgent, await readOwnAgent());
|
|
109
|
-
if (values.manual) {
|
|
110
|
-
const { start_url } = await post(house, '/kit', {
|
|
111
|
-
...started,
|
|
112
|
-
presentation: 'manual',
|
|
113
|
-
});
|
|
114
|
-
process.stdout.write(`Open this link and confirm: ${start_url}\n`);
|
|
115
|
-
await exchange(await typed('Code: '));
|
|
116
|
-
await placeGit();
|
|
117
|
-
return;
|
|
90
|
+
let held = false;
|
|
91
|
+
let named = environment;
|
|
92
|
+
let exchanged;
|
|
93
|
+
if (values.code !== undefined) {
|
|
94
|
+
exchanged = await post(house, '/kit/token', { code: values.code, label: hostname() });
|
|
118
95
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
96
|
+
else {
|
|
97
|
+
held = ownAgent !== null && ownAgent.house === house && (await accepted(house, ownAgent.credential));
|
|
98
|
+
const verifier = randomBytes(32).toString('base64url');
|
|
99
|
+
const start = () => retrying(() => post(house, '/kit', {
|
|
100
|
+
label: hostname(),
|
|
101
|
+
...(named === undefined
|
|
102
|
+
? { act: 'new_environment', ...(replaces === undefined ? {} : { replaces }) }
|
|
103
|
+
: { act: 'existing_environment', environment_id: named }),
|
|
104
|
+
...rooms,
|
|
105
|
+
code_challenge: createHash('sha256').update(verifier).digest('base64url'),
|
|
106
|
+
...(held ? {} : { headless: true }),
|
|
107
|
+
}));
|
|
108
|
+
let started;
|
|
127
109
|
try {
|
|
128
|
-
await
|
|
110
|
+
started = await start();
|
|
129
111
|
}
|
|
130
112
|
catch (error) {
|
|
131
|
-
|
|
132
|
-
|
|
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();
|
|
133
119
|
}
|
|
134
|
-
|
|
120
|
+
process.stdout.write(`Open this link and confirm: ${started.start_url}\n`);
|
|
121
|
+
open(started.start_url);
|
|
122
|
+
exchanged = await retrying(() => post(house, '/kit/token', { login: started.login, code_verifier: verifier }), undefined, () => POLL_INTERVAL_MS);
|
|
123
|
+
}
|
|
124
|
+
await placeSkillSet();
|
|
125
|
+
await writeCodexRule().catch((error) => process.stderr.write(`kit: ${error.message}\n`));
|
|
126
|
+
const relayRecord = relay === undefined ? {} : { relay };
|
|
127
|
+
await writeEnrolment({
|
|
128
|
+
house,
|
|
129
|
+
...relayRecord,
|
|
130
|
+
environment: exchanged.environment,
|
|
131
|
+
credential: exchanged.credential,
|
|
132
|
+
});
|
|
133
|
+
process.stdout.write(connected(house, named, exchanged.environment));
|
|
134
|
+
if (exchanged.headless_credential !== undefined) {
|
|
135
|
+
await writeOwnAgent({ house, ...relayRecord, user: exchanged.user, credential: exchanged.headless_credential });
|
|
136
|
+
}
|
|
137
|
+
else if (held && ownAgent !== null && ownAgent.user !== exchanged.user) {
|
|
138
|
+
await forgetOwnAgent();
|
|
139
|
+
process.stdout.write("This computer's own agent was another User's; run kit login again to connect it to you.\n");
|
|
140
|
+
}
|
|
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`));
|
|
145
|
+
try {
|
|
146
|
+
startService();
|
|
135
147
|
}
|
|
136
|
-
|
|
137
|
-
|
|
148
|
+
catch (error) {
|
|
149
|
+
process.stderr.write(`kit: ${error.message}\n`);
|
|
138
150
|
}
|
|
139
|
-
await placeGit();
|
|
140
151
|
}
|
package/dist/logout.js
CHANGED
|
@@ -1,21 +1,19 @@
|
|
|
1
1
|
import { HouseRefusal, post } from './api.js';
|
|
2
|
-
import {
|
|
3
|
-
import { forgetEnrolment, readEnrolment } from './home.js';
|
|
2
|
+
import { forgetEnrolment, forgetOwnAgent, readEnrolment } from './home.js';
|
|
4
3
|
export async function logout() {
|
|
5
4
|
const enrolled = await readEnrolment();
|
|
6
|
-
if (enrolled
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
if (enrolled !== null) {
|
|
6
|
+
try {
|
|
7
|
+
await post(enrolled.house, '/kit/logout', {}, enrolled.credential);
|
|
8
|
+
}
|
|
9
|
+
catch (error) {
|
|
10
|
+
if (!(error instanceof HouseRefusal && error.status === 401))
|
|
11
|
+
throw error;
|
|
12
|
+
}
|
|
13
|
+
await forgetEnrolment(enrolled);
|
|
10
14
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
if (!(error instanceof HouseRefusal && error.status === 401))
|
|
16
|
-
throw error;
|
|
17
|
-
}
|
|
18
|
-
await forgetEnrolment(enrolled);
|
|
19
|
-
await forgetAppGit();
|
|
20
|
-
process.stdout.write(`Environment ${enrolled.environment} is disconnected; kit login reconnects it.\n`);
|
|
15
|
+
await forgetOwnAgent();
|
|
16
|
+
process.stdout.write(enrolled === null
|
|
17
|
+
? 'This computer is not connected to House.\n'
|
|
18
|
+
: `Environment ${enrolled.environment} is disconnected; kit login reconnects it.\n`);
|
|
21
19
|
}
|
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,30 @@
|
|
|
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
|
+
export function installCommand() {
|
|
22
|
+
try {
|
|
23
|
+
return readFileSync(join(kitHome(), 'install-command'), 'utf8').trim();
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
if (error.code === 'ENOENT')
|
|
27
|
+
return null;
|
|
28
|
+
throw error;
|
|
29
|
+
}
|
|
30
|
+
}
|
package/dist/relay.js
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
|
+
let selected;
|
|
2
|
+
export function selectRelay(relay) {
|
|
3
|
+
selected = relay === undefined || relay === '' ? null : relay;
|
|
4
|
+
}
|
|
5
|
+
export function relayOrigin() {
|
|
6
|
+
if (selected !== undefined)
|
|
7
|
+
return selected ?? undefined;
|
|
8
|
+
const ambient = process.env.HOUSE_KIT_RELAY;
|
|
9
|
+
return ambient === undefined || ambient === '' ? undefined : ambient;
|
|
10
|
+
}
|
|
1
11
|
export function relayed(target) {
|
|
2
12
|
const url = new URL(target);
|
|
3
|
-
const relay =
|
|
4
|
-
if (relay === undefined
|
|
13
|
+
const relay = relayOrigin();
|
|
14
|
+
if (relay === undefined)
|
|
5
15
|
return url;
|
|
6
16
|
const through = new URL(`${url.host}${url.pathname}${url.search}`, `${relay}/`);
|
|
7
17
|
if (url.protocol === 'wss:' || url.protocol === 'ws:')
|
package/dist/resident.js
CHANGED
|
@@ -1,54 +1,96 @@
|
|
|
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';
|
|
5
|
-
import { extname, join } from 'node:path';
|
|
4
|
+
import { createServer, get } from 'node:http';
|
|
5
|
+
import { dirname, extname, join } from 'node:path';
|
|
6
|
+
import { DatabaseSync } from 'node:sqlite';
|
|
6
7
|
import { fileURLToPath } from 'node:url';
|
|
7
|
-
import { killDescendants } from './acp.js';
|
|
8
8
|
import { Agents } from './agents.js';
|
|
9
9
|
import { house } from './api.js';
|
|
10
10
|
import { received } from './bridge.js';
|
|
11
|
-
import { Conversations } from './conversations.js';
|
|
11
|
+
import { CONVERSATION_INPUTS, Conversations } from './conversations.js';
|
|
12
12
|
import { LocalCopies } from './copies.js';
|
|
13
|
-
import {
|
|
13
|
+
import { restart } from './end.js';
|
|
14
|
+
import { agentBase, enrolled, forgetRestart, kitHome, ownerLock, ownerSocket, restartAsked } from './home.js';
|
|
15
|
+
import { Inputs } from './inputs.js';
|
|
16
|
+
import { killDescendants } from './scope.js';
|
|
14
17
|
import { quoted } from './shell.js';
|
|
15
18
|
import { SignIns } from './sign-in.js';
|
|
16
19
|
import { placeSkillSet } from './skills.js';
|
|
17
20
|
import { holdStream } from './stream.js';
|
|
18
21
|
import { Updates } from './update.js';
|
|
22
|
+
import { codexLauncher } from './work.js';
|
|
19
23
|
function report(error) {
|
|
20
24
|
process.stderr.write(`kit: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
21
25
|
}
|
|
22
26
|
function logged(work) {
|
|
23
27
|
work.catch(report);
|
|
24
28
|
}
|
|
25
|
-
async function installShim() {
|
|
26
|
-
const main = fileURLToPath(new URL(
|
|
27
|
-
await mkdir(
|
|
28
|
-
await writeFile(
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
async function installShim(path, module) {
|
|
30
|
+
const main = fileURLToPath(new URL(`./${module}${extname(fileURLToPath(import.meta.url))}`, import.meta.url));
|
|
31
|
+
await mkdir(dirname(path), { recursive: true });
|
|
32
|
+
await writeFile(path, `#!/bin/sh\nexec ${quoted(process.execPath)} ${quoted(main)} "$@"\n`, { mode: 0o755 });
|
|
33
|
+
}
|
|
34
|
+
function claimed(lock) {
|
|
35
|
+
try {
|
|
36
|
+
lock.exec('BEGIN EXCLUSIVE');
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
if (error.errcode === 5)
|
|
41
|
+
return false;
|
|
42
|
+
throw error;
|
|
43
|
+
}
|
|
31
44
|
}
|
|
32
45
|
async function serveOwner(copies) {
|
|
33
|
-
const
|
|
34
|
-
|
|
46
|
+
const lock = new DatabaseSync(ownerLock());
|
|
47
|
+
if (!claimed(lock)) {
|
|
48
|
+
lock.close();
|
|
49
|
+
const running = await runningResident();
|
|
50
|
+
throw new Error(`${running === null ? 'another Kit' : `Kit ${running}`} already runs this Environment from Kit home ${kitHome()}; stop it first to run another here`);
|
|
51
|
+
}
|
|
35
52
|
const server = createServer(async (request, response) => {
|
|
36
53
|
try {
|
|
37
|
-
|
|
54
|
+
const text = await received(request);
|
|
55
|
+
let answered;
|
|
56
|
+
if (request.url === '/resident') {
|
|
57
|
+
response.writeHead(200, { 'content-type': 'application/json' }).end(JSON.stringify({ pid: process.pid }));
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if (request.url === '/git/fetch') {
|
|
61
|
+
answered = await copies.fetch();
|
|
62
|
+
}
|
|
63
|
+
else if (request.url === '/git/push') {
|
|
64
|
+
const { cwd, commit } = JSON.parse(text);
|
|
65
|
+
answered = await copies.push(cwd, commit, copies.owner);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
38
68
|
response.writeHead(404).end();
|
|
39
69
|
return;
|
|
40
70
|
}
|
|
41
|
-
|
|
42
|
-
const pushed = await copies.push(cwd, commit, copies.owner);
|
|
43
|
-
response.writeHead(200, { 'content-type': 'application/json' }).end(JSON.stringify(pushed));
|
|
71
|
+
response.writeHead(200, { 'content-type': 'application/json' }).end(JSON.stringify(answered));
|
|
44
72
|
}
|
|
45
73
|
catch (error) {
|
|
46
74
|
response.writeHead(502).end(error instanceof Error ? error.message : String(error));
|
|
47
75
|
}
|
|
48
76
|
});
|
|
49
|
-
server.
|
|
77
|
+
server.on('close', () => lock.close());
|
|
78
|
+
await rm(ownerSocket(), { force: true });
|
|
79
|
+
server.listen(ownerSocket());
|
|
50
80
|
await once(server, 'listening');
|
|
51
81
|
}
|
|
82
|
+
function runningResident() {
|
|
83
|
+
return new Promise((resolve, reject) => {
|
|
84
|
+
get({ socketPath: ownerSocket(), path: '/resident' }, (answer) => {
|
|
85
|
+
received(answer).then((text) => resolve(JSON.parse(text).pid), reject);
|
|
86
|
+
}).on('error', (error) => {
|
|
87
|
+
if (error.code === 'ENOENT' || error.code === 'ECONNREFUSED')
|
|
88
|
+
resolve(null);
|
|
89
|
+
else
|
|
90
|
+
reject(error);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
}
|
|
52
94
|
function connected() {
|
|
53
95
|
return new Promise((resolve) => {
|
|
54
96
|
const watcher = watch(kitHome(), () => {
|
|
@@ -65,8 +107,9 @@ function connected() {
|
|
|
65
107
|
resolve();
|
|
66
108
|
});
|
|
67
109
|
}
|
|
68
|
-
|
|
110
|
+
async function started() {
|
|
69
111
|
await connected();
|
|
112
|
+
await forgetRestart();
|
|
70
113
|
watch(kitHome(), () => {
|
|
71
114
|
if (enrolled())
|
|
72
115
|
return;
|
|
@@ -75,33 +118,46 @@ export async function resident() {
|
|
|
75
118
|
});
|
|
76
119
|
await placeSkillSet();
|
|
77
120
|
await mkdir(agentBase(), { recursive: true });
|
|
78
|
-
|
|
79
|
-
|
|
121
|
+
await installShim(join(kitHome(), 'shim', 'git'), 'git-main');
|
|
122
|
+
await installShim(codexLauncher(), 'codex-main');
|
|
123
|
+
}
|
|
124
|
+
export async function resident() {
|
|
125
|
+
await mkdir(kitHome(), { recursive: true, mode: 0o700 });
|
|
80
126
|
const copies = new LocalCopies(house);
|
|
81
127
|
await copies.load();
|
|
82
|
-
await installShim();
|
|
83
128
|
await serveOwner(copies);
|
|
129
|
+
await started().catch((error) => {
|
|
130
|
+
report(error);
|
|
131
|
+
process.exit(1);
|
|
132
|
+
});
|
|
133
|
+
process.env.HOUSE_KIT_RESIDENT = String(process.pid);
|
|
134
|
+
const agents = new Agents(house, () => changed());
|
|
84
135
|
let stream = null;
|
|
85
136
|
let reported = false;
|
|
86
|
-
const idle = () => conversations.idle() &&
|
|
137
|
+
const idle = () => inputs.idle() && conversations.idle() && agents.idle();
|
|
87
138
|
const changed = () => {
|
|
88
139
|
if (!idle()) {
|
|
89
140
|
reported = false;
|
|
90
141
|
}
|
|
142
|
+
else if (restartAsked() && conversations.quiet()) {
|
|
143
|
+
restart('restarting for an updated CLI');
|
|
144
|
+
}
|
|
91
145
|
else if (!reported) {
|
|
92
146
|
reported = true;
|
|
93
147
|
logged(house.deliver('/kit/idle', {}, idle));
|
|
94
148
|
}
|
|
95
149
|
};
|
|
150
|
+
const inputs = new Inputs(house, changed);
|
|
96
151
|
const conversations = new Conversations({
|
|
97
152
|
house,
|
|
98
153
|
agents,
|
|
99
154
|
copies,
|
|
155
|
+
inputs,
|
|
100
156
|
send: (frame) => stream?.send(frame) ?? false,
|
|
101
157
|
changed,
|
|
102
158
|
});
|
|
103
|
-
const signIns = new SignIns(house, agents,
|
|
104
|
-
const updates = new Updates(
|
|
159
|
+
const signIns = new SignIns(house, agents, inputs);
|
|
160
|
+
const updates = new Updates(inputs);
|
|
105
161
|
for (const signal of ['SIGTERM', 'SIGINT']) {
|
|
106
162
|
process.once(signal, () => {
|
|
107
163
|
killDescendants();
|
|
@@ -115,26 +171,26 @@ export async function resident() {
|
|
|
115
171
|
opened: () => {
|
|
116
172
|
conversations.opened();
|
|
117
173
|
changed();
|
|
118
|
-
logged(copies.
|
|
174
|
+
logged(copies.connected());
|
|
119
175
|
},
|
|
120
176
|
frame: (arrived) => {
|
|
121
177
|
if (arrived.type === 'watching')
|
|
122
178
|
conversations.watching(arrived.watching === true);
|
|
179
|
+
if (arrived.type === 'authority_changed')
|
|
180
|
+
logged(copies.changed(arrived.rooms));
|
|
123
181
|
if (arrived.type === 'work_available' && arrived.subject === 'agents')
|
|
124
182
|
logged(agents.refresh());
|
|
125
|
-
if (arrived.type === 'work_available' && arrived.subject === 'local_copy')
|
|
126
|
-
logged(copies.select());
|
|
127
|
-
if (arrived.type === 'entries') {
|
|
128
|
-
copies.entries(arrived);
|
|
129
|
-
}
|
|
130
183
|
if (arrived.type === 'input') {
|
|
131
|
-
reported = false;
|
|
132
184
|
if (arrived.kind === 'sign_in')
|
|
133
185
|
signIns.start(arrived);
|
|
134
186
|
else if (arrived.kind === 'update')
|
|
135
187
|
updates.start(arrived);
|
|
136
|
-
else
|
|
188
|
+
else if (CONVERSATION_INPUTS.has(arrived.kind))
|
|
137
189
|
conversations.input(arrived);
|
|
190
|
+
else {
|
|
191
|
+
const refused = { refused: `This Kit does not know ${arrived.kind}; update the Kit` };
|
|
192
|
+
void inputs.carry(String(arrived.input_id), async () => ({ ack: refused }));
|
|
193
|
+
}
|
|
138
194
|
}
|
|
139
195
|
},
|
|
140
196
|
});
|