@agentshouse/kit 0.2.1-cd9cbd8b6428c → 0.2.1-cdc381ebf021f
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 +42 -49
- package/dist/acp.js +102 -108
- package/dist/afk.js +17 -0
- package/dist/agents.js +256 -69
- package/dist/api.js +43 -6
- package/dist/app-git.js +48 -0
- package/dist/bridge.js +42 -62
- package/dist/building.js +50 -0
- package/dist/calls.js +88 -0
- package/dist/chunks.js +49 -0
- package/dist/clis.js +169 -95
- package/dist/codex-main.js +58 -0
- package/dist/connect.js +108 -0
- package/dist/connection.js +120 -0
- package/dist/content.js +106 -0
- package/dist/conversations.js +817 -333
- package/dist/copies.js +450 -251
- package/dist/earlier.js +263 -0
- package/dist/end.js +26 -0
- package/dist/events.js +793 -0
- package/dist/files.js +139 -17
- package/dist/git.js +57 -21
- package/dist/grok.js +39 -0
- package/dist/home.js +122 -8
- package/dist/house-cli.js +359 -0
- package/dist/house-main.js +7 -159
- package/dist/instructions.js +7 -11
- package/dist/kit-cli.js +78 -0
- package/dist/kit-main.js +8 -19
- package/dist/login.js +133 -104
- package/dist/logout.js +15 -14
- package/dist/mcp.js +6 -2
- package/dist/owner.js +46 -0
- package/dist/placement.js +25 -0
- package/dist/refusals.js +12 -0
- package/dist/relay.js +33 -2
- package/dist/resident.js +161 -61
- package/dist/scope.js +214 -0
- package/dist/scripts.js +303 -0
- package/dist/secret-input.js +5 -2
- package/dist/settings.js +188 -0
- package/dist/shell.js +3 -0
- package/dist/sign-in.js +40 -32
- package/dist/silence.js +28 -0
- package/dist/skills.js +49 -35
- package/dist/supervisor.js +163 -0
- package/dist/transcription.js +131 -40
- package/dist/translate.js +19 -16
- package/dist/update.js +119 -100
- package/dist/wire.js +32 -0
- package/dist/work.js +353 -0
- package/dist/workspace.js +103 -0
- package/package.json +25 -21
- package/dist/authority-main.js +0 -22
- package/dist/blocks.js +0 -51
- package/dist/bootstrap.json +0 -24
- package/dist/clis-main.js +0 -23
- package/dist/configure-main.js +0 -6
- package/dist/enrol-main.js +0 -4
- package/dist/stream.js +0 -47
- package/how-we-work.md +0 -23
- package/skills/ask-matt/LICENSE +0 -21
- package/skills/ask-matt/PHASE-BOUNDARIES.md +0 -55
- package/skills/ask-matt/SKILL.md +0 -91
- package/skills/ask-matt/agents/openai.yaml +0 -4
- package/skills/code-review/LICENSE +0 -21
- package/skills/code-review/SKILL.md +0 -89
- package/skills/code-review/agents/openai.yaml +0 -3
- package/skills/codebase-design/DEEPENING.md +0 -37
- package/skills/codebase-design/DESIGN-IT-TWICE.md +0 -44
- package/skills/codebase-design/LICENSE +0 -21
- package/skills/codebase-design/SKILL.md +0 -116
- package/skills/codebase-design/agents/openai.yaml +0 -3
- package/skills/diagnosing-bugs/LICENSE +0 -21
- package/skills/diagnosing-bugs/SKILL.md +0 -140
- package/skills/diagnosing-bugs/agents/openai.yaml +0 -3
- package/skills/diagnosing-bugs/scripts/hitl-loop.template.sh +0 -44
- package/skills/domain-modeling/ADR-FORMAT.md +0 -47
- package/skills/domain-modeling/CONTEXT-FORMAT.md +0 -60
- package/skills/domain-modeling/LICENSE +0 -21
- package/skills/domain-modeling/SKILL.md +0 -76
- package/skills/domain-modeling/agents/openai.yaml +0 -3
- package/skills/grill-me/LICENSE +0 -21
- package/skills/grill-me/SKILL.md +0 -8
- package/skills/grill-me/agents/openai.yaml +0 -4
- package/skills/grill-with-docs/LICENSE +0 -21
- package/skills/grill-with-docs/SKILL.md +0 -8
- package/skills/grill-with-docs/agents/openai.yaml +0 -4
- package/skills/grilling/LICENSE +0 -21
- package/skills/grilling/SKILL.md +0 -30
- package/skills/grilling/agents/openai.yaml +0 -3
- package/skills/handoff/LICENSE +0 -21
- package/skills/handoff/SKILL.md +0 -17
- package/skills/handoff/agents/openai.yaml +0 -4
- package/skills/implement/LICENSE +0 -21
- package/skills/implement/SKILL.md +0 -16
- package/skills/implement/agents/openai.yaml +0 -4
- package/skills/improve-codebase-architecture/HTML-REPORT.md +0 -123
- package/skills/improve-codebase-architecture/LICENSE +0 -21
- package/skills/improve-codebase-architecture/SKILL.md +0 -72
- package/skills/improve-codebase-architecture/agents/openai.yaml +0 -4
- package/skills/prototype/LICENSE +0 -21
- package/skills/prototype/LOGIC.md +0 -67
- package/skills/prototype/SKILL.md +0 -28
- package/skills/prototype/UI.md +0 -112
- package/skills/prototype/agents/openai.yaml +0 -3
- package/skills/research/LICENSE +0 -21
- package/skills/research/SKILL.md +0 -14
- package/skills/research/agents/openai.yaml +0 -3
- package/skills/resolving-merge-conflicts/LICENSE +0 -21
- package/skills/resolving-merge-conflicts/SKILL.md +0 -16
- package/skills/resolving-merge-conflicts/agents/openai.yaml +0 -3
- package/skills/tdd/LICENSE +0 -21
- package/skills/tdd/SKILL.md +0 -40
- package/skills/tdd/agents/openai.yaml +0 -3
- package/skills/tdd/mocking.md +0 -59
- package/skills/tdd/tests.md +0 -77
- package/skills/teach/GLOSSARY-FORMAT.md +0 -35
- package/skills/teach/LEARNING-RECORD-FORMAT.md +0 -46
- package/skills/teach/LICENSE +0 -21
- package/skills/teach/MISSION-FORMAT.md +0 -31
- package/skills/teach/RESOURCES-FORMAT.md +0 -32
- package/skills/teach/SKILL.md +0 -141
- package/skills/teach/agents/openai.yaml +0 -4
- package/skills/to-questionnaire/LICENSE +0 -21
- package/skills/to-questionnaire/SKILL.md +0 -55
- package/skills/to-questionnaire/agents/openai.yaml +0 -4
- package/skills/to-spec/LICENSE +0 -21
- package/skills/to-spec/SKILL.md +0 -76
- package/skills/to-spec/agents/openai.yaml +0 -4
- package/skills/to-tickets/LICENSE +0 -21
- package/skills/to-tickets/SKILL.md +0 -106
- package/skills/to-tickets/agents/openai.yaml +0 -4
- package/skills/wait-what/LICENSE +0 -21
- package/skills/wait-what/SKILL.md +0 -8
- package/skills/wait-what/agents/openai.yaml +0 -4
- package/skills/wayfinder/LICENSE +0 -21
- package/skills/wayfinder/SKILL.md +0 -129
- package/skills/wayfinder/agents/openai.yaml +0 -4
- package/skills/writing-for-agents/LICENSE +0 -21
- package/skills/writing-for-agents/SKILL-MECHANICS.md +0 -22
- package/skills/writing-for-agents/SKILL.md +0 -83
- package/skills/writing-for-agents/agents/openai.yaml +0 -3
package/dist/login.js
CHANGED
|
@@ -1,53 +1,31 @@
|
|
|
1
|
+
import { KIT_LOGIN_PATHS, } from '@agentshouse/kit-wire';
|
|
2
|
+
import { spawn } from 'node:child_process';
|
|
1
3
|
import { createHash, randomBytes } from 'node:crypto';
|
|
2
|
-
import { createServer } from 'node:http';
|
|
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';
|
|
7
|
-
import {
|
|
5
|
+
import { HouseRefusal, post, retrying } from './api.js';
|
|
6
|
+
import { placeAppGit } from './app-git.js';
|
|
7
|
+
import { writeCodexRule } from './clis.js';
|
|
8
|
+
import { forgetDisconnected, forgetOwnAgent, readDisconnected, readEnrolment, readOwnAgent, writeEnrolment, writeOwnAgent, } from './home.js';
|
|
8
9
|
import { callHouse, rpc } from './mcp.js';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
server.closeAllConnections();
|
|
29
|
-
};
|
|
30
|
-
const port = Number(process.env.HOUSE_KIT_LOGIN_PORT ?? 0);
|
|
31
|
-
server.once('error', reject);
|
|
32
|
-
server.listen(port, port === 0 ? '127.0.0.1' : '0.0.0.0', () => {
|
|
33
|
-
const address = server.address();
|
|
34
|
-
if (address === null || typeof address === 'string') {
|
|
35
|
-
reject(new Error('the login callback has no port'));
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
resolve({
|
|
39
|
-
uri: `http://127.0.0.1:${address.port}/callback`,
|
|
40
|
-
code,
|
|
41
|
-
answer: (text) => new Promise((written) => {
|
|
42
|
-
if (held === null || held.destroyed || !held.socket || held.socket.destroyed)
|
|
43
|
-
return written();
|
|
44
|
-
held.once('close', () => written());
|
|
45
|
-
held.writeHead(200, { 'content-type': 'text/plain; charset=utf-8', connection: 'close' }).end(`${text}\n`);
|
|
46
|
-
}),
|
|
47
|
-
close,
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
});
|
|
10
|
+
import { refusalOf } from './refusals.js';
|
|
11
|
+
import { selectRelay } from './relay.js';
|
|
12
|
+
import { startService } from './supervisor.js';
|
|
13
|
+
import { placeSkillSet } from './skills.js';
|
|
14
|
+
import { endUnserved } from './wire.js';
|
|
15
|
+
export const DEFAULT_HOUSE = 'https://agents.house';
|
|
16
|
+
const OPENER = process.platform === 'darwin' ? 'open' : 'xdg-open';
|
|
17
|
+
// Polling every two seconds brings the User's confirmation to the waiting Kit moments after they give it.
|
|
18
|
+
const POLL_INTERVAL_MS = 2000;
|
|
19
|
+
function startLogin(house, request) {
|
|
20
|
+
return post(house, KIT_LOGIN_PATHS.start, request);
|
|
21
|
+
}
|
|
22
|
+
function pollLogin(house, request) {
|
|
23
|
+
return post(house, KIT_LOGIN_PATHS.poll, request);
|
|
24
|
+
}
|
|
25
|
+
function open(link) {
|
|
26
|
+
spawn(OPENER, [link], { detached: true, stdio: 'ignore' })
|
|
27
|
+
.on('error', () => undefined)
|
|
28
|
+
.unref();
|
|
51
29
|
}
|
|
52
30
|
async function accepted(house, credential) {
|
|
53
31
|
const checked = await callHouse(house, credential, rpc('tools/list', {}));
|
|
@@ -55,19 +33,33 @@ async function accepted(house, credential) {
|
|
|
55
33
|
return true;
|
|
56
34
|
if (checked.status === 401)
|
|
57
35
|
return false;
|
|
36
|
+
endUnserved(checked.text);
|
|
58
37
|
throw new Error(`House answered ${checked.status} when Kit checked this computer's own agent's connection: ${checked.text}`);
|
|
59
38
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
39
|
+
const USAGE = `usage: kit login [--house <origin>] [--environment <id>] [--rooms <ref>[,<ref>...] | --no-private]
|
|
40
|
+
kit login [--house <origin>] --code <code>
|
|
41
|
+
--house <origin> the House to connect to, ${DEFAULT_HOUSE} unless one is stored
|
|
42
|
+
--environment <id> reconnect this Environment
|
|
43
|
+
--rooms <ref>[,<ref>...] give this Environment only these Rooms
|
|
44
|
+
--no-private give this Environment every Room but your Private Room
|
|
45
|
+
--code <code> connect this machine with a login code
|
|
46
|
+
`;
|
|
47
|
+
function connected(house, named, environment) {
|
|
48
|
+
if (named === undefined)
|
|
49
|
+
return `Environment ${environment} is connected to ${house}.\n`;
|
|
50
|
+
if (named === environment)
|
|
51
|
+
return `Environment ${environment} is reconnected to ${house}.\n`;
|
|
52
|
+
return `Environment ${named} stays with its account; this computer is connected to ${house} as new Environment ${environment} of the account that confirmed.\n`;
|
|
53
|
+
}
|
|
54
|
+
function gone(error) {
|
|
55
|
+
return error instanceof HouseRefusal && refusalOf(error.text)?.code === 'kit_environment_not_found';
|
|
56
|
+
}
|
|
57
|
+
function chosenRooms(rooms, noPrivate) {
|
|
58
|
+
if (rooms !== undefined && noPrivate)
|
|
59
|
+
throw new Error('--rooms and --no-private are two choices of Rooms; pass one');
|
|
60
|
+
if (rooms !== undefined)
|
|
61
|
+
return { rooms: { reach: 'selected', refs: rooms.split(',') } };
|
|
62
|
+
return noPrivate ? { rooms: { reach: 'all_but_private' } } : {};
|
|
71
63
|
}
|
|
72
64
|
export async function login(argv) {
|
|
73
65
|
const { values } = parseArgs({
|
|
@@ -75,62 +67,99 @@ export async function login(argv) {
|
|
|
75
67
|
options: {
|
|
76
68
|
house: { type: 'string' },
|
|
77
69
|
environment: { type: 'string' },
|
|
78
|
-
|
|
70
|
+
rooms: { type: 'string' },
|
|
71
|
+
'no-private': { type: 'boolean', default: false },
|
|
72
|
+
code: { type: 'string' },
|
|
73
|
+
help: { type: 'boolean', default: false },
|
|
79
74
|
},
|
|
80
75
|
});
|
|
76
|
+
if (values.help) {
|
|
77
|
+
process.stdout.write(USAGE);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const house = await enrol(values);
|
|
81
|
+
await placeConnection(house);
|
|
82
|
+
try {
|
|
83
|
+
startService();
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
process.stderr.write(`kit: ${error.message}\n`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
export async function placeConnection(house) {
|
|
90
|
+
await placeSkillSet(house);
|
|
91
|
+
await writeCodexRule().catch((error) => process.stderr.write(`kit: ${error.message}\n`));
|
|
92
|
+
await placeAppGit(await readOwnAgent()).catch((error) => process.stderr.write(`kit: ${error.message}\n`));
|
|
93
|
+
}
|
|
94
|
+
export async function enrol(values) {
|
|
95
|
+
if (values.code !== undefined && values.rooms !== undefined)
|
|
96
|
+
throw new Error('--code cannot be used with --rooms');
|
|
97
|
+
if (values.code !== undefined && values['no-private'])
|
|
98
|
+
throw new Error('--code cannot be used with --no-private');
|
|
99
|
+
if (values.code !== undefined && values.environment !== undefined)
|
|
100
|
+
throw new Error('--code cannot be used with --environment');
|
|
101
|
+
const rooms = chosenRooms(values.rooms, values['no-private']);
|
|
81
102
|
const enrolled = (await readEnrolment()) ?? (await readDisconnected());
|
|
103
|
+
if (values.code !== undefined && enrolled !== null) {
|
|
104
|
+
throw new Error(`--code connects a new machine; this Kit home records Environment ${enrolled.environment}, so run kit login to reconnect it`);
|
|
105
|
+
}
|
|
106
|
+
const relay = process.env.HOUSE_KIT_RELAY || undefined;
|
|
107
|
+
selectRelay(relay);
|
|
82
108
|
const house = values.house ?? enrolled?.house ?? DEFAULT_HOUSE;
|
|
83
|
-
const
|
|
84
|
-
const environment =
|
|
109
|
+
const remembered = values.environment === undefined && enrolled?.house === house ? enrolled.environment : undefined;
|
|
110
|
+
const environment = values.environment ?? remembered;
|
|
111
|
+
if (environment !== undefined && rooms.rooms !== undefined) {
|
|
112
|
+
throw new Error(`Environment ${environment} keeps its Rooms; change them on its page in House`);
|
|
113
|
+
}
|
|
85
114
|
const ownAgent = await readOwnAgent();
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
: { act: 'existing_environment', environment_id: environment }),
|
|
92
|
-
code_challenge: createHash('sha256').update(verifier).digest('base64url'),
|
|
93
|
-
...(held ? {} : { headless: true }),
|
|
94
|
-
};
|
|
95
|
-
const exchange = async (code) => {
|
|
96
|
-
const exchanged = await post(house, '/kit/token', { code, code_verifier: verifier });
|
|
97
|
-
await writeEnrolment({ house, environment: exchanged.environment, credential: exchanged.credential });
|
|
98
|
-
process.stdout.write(`Environment ${exchanged.environment} is connected to ${house}.\n`);
|
|
99
|
-
if (exchanged.headless_credential !== undefined) {
|
|
100
|
-
await writeOwnAgent({ house, user: exchanged.user, credential: exchanged.headless_credential });
|
|
101
|
-
}
|
|
102
|
-
else if (held && ownAgent.user !== exchanged.user) {
|
|
103
|
-
await forgetOwnAgent();
|
|
104
|
-
process.stdout.write("This computer's own agent was another User's; run kit login again to connect it to you.\n");
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
if (values.manual) {
|
|
108
|
-
const { start_url } = await post(house, '/kit', {
|
|
109
|
-
...started,
|
|
110
|
-
presentation: 'manual',
|
|
111
|
-
});
|
|
112
|
-
process.stdout.write(`Open this link and confirm: ${start_url}\n`);
|
|
113
|
-
await exchange(await typed('Code: '));
|
|
114
|
-
return;
|
|
115
|
+
let held = false;
|
|
116
|
+
let named = environment;
|
|
117
|
+
let exchanged;
|
|
118
|
+
if (values.code !== undefined) {
|
|
119
|
+
exchanged = await pollLogin(house, { code: values.code });
|
|
115
120
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
121
|
+
else {
|
|
122
|
+
held = ownAgent !== null && ownAgent.house === house && (await accepted(house, ownAgent.credential));
|
|
123
|
+
const verifier = randomBytes(32).toString('base64url');
|
|
124
|
+
const start = () => retrying(() => startLogin(house, {
|
|
125
|
+
...(named === undefined ? { act: 'new_environment' } : { act: 'existing_environment', environment_id: named }),
|
|
126
|
+
...rooms,
|
|
127
|
+
code_challenge: createHash('sha256').update(verifier).digest('base64url'),
|
|
128
|
+
...(held ? {} : { headless: true }),
|
|
129
|
+
}));
|
|
130
|
+
let started;
|
|
124
131
|
try {
|
|
125
|
-
await
|
|
132
|
+
started = await start();
|
|
126
133
|
}
|
|
127
134
|
catch (error) {
|
|
128
|
-
|
|
129
|
-
|
|
135
|
+
if (remembered === undefined || !gone(error))
|
|
136
|
+
throw error;
|
|
137
|
+
await forgetDisconnected();
|
|
138
|
+
process.stdout.write(`House no longer holds Environment ${remembered}; connecting this computer as a new one.\n`);
|
|
139
|
+
named = undefined;
|
|
140
|
+
started = await start();
|
|
130
141
|
}
|
|
131
|
-
|
|
142
|
+
process.stdout.write(`Open this link and confirm: ${started.start_url}\n`);
|
|
143
|
+
open(started.start_url);
|
|
144
|
+
exchanged = await retrying(() => pollLogin(house, { login: started.login, code_verifier: verifier }), undefined, () => POLL_INTERVAL_MS);
|
|
145
|
+
}
|
|
146
|
+
const relayRecord = relay === undefined ? {} : { relay };
|
|
147
|
+
await writeEnrolment({
|
|
148
|
+
house,
|
|
149
|
+
...relayRecord,
|
|
150
|
+
environment: exchanged.environment,
|
|
151
|
+
credential: exchanged.credential,
|
|
152
|
+
});
|
|
153
|
+
process.stdout.write(connected(house, named, exchanged.environment));
|
|
154
|
+
if (exchanged.headless_credential !== undefined) {
|
|
155
|
+
await writeOwnAgent({ house, ...relayRecord, user: exchanged.user, credential: exchanged.headless_credential });
|
|
156
|
+
}
|
|
157
|
+
else if (held && ownAgent !== null && ownAgent.user !== exchanged.user) {
|
|
158
|
+
await forgetOwnAgent();
|
|
159
|
+
process.stdout.write("This computer's own agent was another User's; run kit login again to connect it to you.\n");
|
|
132
160
|
}
|
|
133
|
-
|
|
134
|
-
|
|
161
|
+
else if (held && ownAgent !== null) {
|
|
162
|
+
await writeOwnAgent({ house, ...relayRecord, user: ownAgent.user, credential: ownAgent.credential });
|
|
135
163
|
}
|
|
164
|
+
return house;
|
|
136
165
|
}
|
package/dist/logout.js
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
import { HouseRefusal,
|
|
2
|
-
import { forgetEnrolment, readEnrolment } from './home.js';
|
|
1
|
+
import { HouseRefusal, kitAct } from './api.js';
|
|
2
|
+
import { forgetEnrolment, forgetOwnAgent, readEnrolment } from './home.js';
|
|
3
3
|
export async function logout() {
|
|
4
4
|
const enrolled = await readEnrolment();
|
|
5
|
-
if (enrolled
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
if (enrolled !== null) {
|
|
6
|
+
try {
|
|
7
|
+
await kitAct(enrolled.house, 'kits/log-out', {}, enrolled.credential);
|
|
8
|
+
}
|
|
9
|
+
catch (error) {
|
|
10
|
+
if (!(error instanceof HouseRefusal && error.status === 401))
|
|
11
|
+
throw error;
|
|
12
|
+
}
|
|
13
|
+
await forgetEnrolment(enrolled);
|
|
8
14
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
if (!(error instanceof HouseRefusal && error.status === 401))
|
|
14
|
-
throw error;
|
|
15
|
-
}
|
|
16
|
-
await forgetEnrolment(enrolled);
|
|
17
|
-
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`);
|
|
18
19
|
}
|
package/dist/mcp.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
import { KIT_WIRE, KIT_WIRE_HEADER } from '@agentshouse/kit-wire';
|
|
1
2
|
import { randomUUID } from 'node:crypto';
|
|
2
|
-
import {
|
|
3
|
+
import { KIT_RELEASE } from './clis.js';
|
|
3
4
|
import { relayed } from './relay.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]: KIT_WIRE,
|
|
34
38
|
},
|
|
35
39
|
body: mcpBody(message, operation),
|
|
36
40
|
signal,
|
package/dist/owner.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { request } from 'node:http';
|
|
2
|
+
import { DatabaseSync } from 'node:sqlite';
|
|
3
|
+
import { received } from './bridge.js';
|
|
4
|
+
import { kitHome, ownerLock, ownerSocket } from './home.js';
|
|
5
|
+
function claimed(lock) {
|
|
6
|
+
try {
|
|
7
|
+
lock.exec('BEGIN EXCLUSIVE');
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
catch (error) {
|
|
11
|
+
if (error.errcode === 5)
|
|
12
|
+
return false;
|
|
13
|
+
throw error;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export function askOwner(path, body) {
|
|
17
|
+
return new Promise((resolve, reject) => {
|
|
18
|
+
const sent = request({ socketPath: ownerSocket(), path, method: body === undefined ? 'GET' : 'POST', headers: { 'content-type': 'application/json' } }, (answer) => {
|
|
19
|
+
received(answer).then((text) => {
|
|
20
|
+
if (answer.statusCode === 200)
|
|
21
|
+
resolve(JSON.parse(text));
|
|
22
|
+
else
|
|
23
|
+
reject(new Error(text));
|
|
24
|
+
}, reject);
|
|
25
|
+
});
|
|
26
|
+
sent.on('error', (error) => {
|
|
27
|
+
if (error.code === 'ENOENT' || error.code === 'ECONNREFUSED')
|
|
28
|
+
resolve(null);
|
|
29
|
+
else
|
|
30
|
+
reject(error);
|
|
31
|
+
});
|
|
32
|
+
sent.end(body === undefined ? undefined : JSON.stringify(body));
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
export async function holdOwner() {
|
|
36
|
+
const lock = new DatabaseSync(ownerLock());
|
|
37
|
+
if (claimed(lock))
|
|
38
|
+
return lock;
|
|
39
|
+
lock.close();
|
|
40
|
+
const running = (await askOwner('/resident'))?.pid ?? null;
|
|
41
|
+
throw new Error(`${running === null ? 'another Kit process' : `Kit process ${running}`} already runs this Environment from Kit home ${kitHome()}; stop it first to run another Kit process here`);
|
|
42
|
+
}
|
|
43
|
+
export async function runningRelease() {
|
|
44
|
+
const running = await askOwner('/resident');
|
|
45
|
+
return running === null ? null : (running.release ?? '');
|
|
46
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { join, resolve } from 'node:path';
|
|
3
|
+
import { kitHome } from './home.js';
|
|
4
|
+
function recorded(name) {
|
|
5
|
+
try {
|
|
6
|
+
return readFileSync(join(kitHome(), name), 'utf8').trim();
|
|
7
|
+
}
|
|
8
|
+
catch (error) {
|
|
9
|
+
if (error.code === 'ENOENT')
|
|
10
|
+
return null;
|
|
11
|
+
throw error;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export function installCommand() {
|
|
15
|
+
return recorded('install-command');
|
|
16
|
+
}
|
|
17
|
+
export function placedPrefix() {
|
|
18
|
+
const prefix = process.env.HOUSE_KIT_PREFIX;
|
|
19
|
+
if (prefix === undefined || prefix === '')
|
|
20
|
+
throw new Error('this Kit process was not started by a launcher its installer placed');
|
|
21
|
+
return resolve(prefix);
|
|
22
|
+
}
|
|
23
|
+
export function releaseDirectory(release) {
|
|
24
|
+
return join(placedPrefix(), 'releases', release);
|
|
25
|
+
}
|
package/dist/refusals.js
CHANGED
|
@@ -21,6 +21,18 @@ function spoken(text) {
|
|
|
21
21
|
const detail = said.indexOf('\n');
|
|
22
22
|
return { code: head[1], text: said, conflicts: detail === -1 ? [] : conflictCodes(said.slice(detail + 1)) };
|
|
23
23
|
}
|
|
24
|
+
export function retryable(text) {
|
|
25
|
+
let body;
|
|
26
|
+
try {
|
|
27
|
+
body = JSON.parse(text);
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
const error = body?.error;
|
|
33
|
+
const verdict = error?.retryable ?? error?.data?.retryable;
|
|
34
|
+
return typeof verdict === 'boolean' ? verdict : null;
|
|
35
|
+
}
|
|
24
36
|
export function refusalOf(text) {
|
|
25
37
|
let body;
|
|
26
38
|
try {
|
package/dist/relay.js
CHANGED
|
@@ -1,7 +1,38 @@
|
|
|
1
|
+
import { setGlobalProxyFromEnv } from 'node:http';
|
|
2
|
+
const PROXY = /^https?_proxy$/i;
|
|
3
|
+
const LOOPBACK = ['127.0.0.1', 'localhost', '::1'];
|
|
4
|
+
let selected;
|
|
5
|
+
let restoreProxy;
|
|
6
|
+
export function selectRelay(relay) {
|
|
7
|
+
selected = relay === undefined || relay === '' ? null : relay;
|
|
8
|
+
proxyUnlessRelayed();
|
|
9
|
+
}
|
|
10
|
+
export function relayOrigin() {
|
|
11
|
+
if (selected !== undefined)
|
|
12
|
+
return selected ?? undefined;
|
|
13
|
+
const ambient = process.env.HOUSE_KIT_RELAY;
|
|
14
|
+
return ambient === undefined || ambient === '' ? undefined : ambient;
|
|
15
|
+
}
|
|
16
|
+
function unlessRelayed() {
|
|
17
|
+
if (relayOrigin() === undefined)
|
|
18
|
+
return { ...process.env };
|
|
19
|
+
return Object.fromEntries(Object.entries(process.env).filter(([name]) => !PROXY.test(name)));
|
|
20
|
+
}
|
|
21
|
+
export function proxyUnlessRelayed() {
|
|
22
|
+
restoreProxy?.();
|
|
23
|
+
restoreProxy = setGlobalProxyFromEnv(unlessRelayed());
|
|
24
|
+
}
|
|
25
|
+
export function childEnvironment() {
|
|
26
|
+
const environment = unlessRelayed();
|
|
27
|
+
if (!Object.keys(environment).some((name) => PROXY.test(name)))
|
|
28
|
+
return environment;
|
|
29
|
+
const bypassed = [environment.NO_PROXY ?? environment.no_proxy, ...LOOPBACK].filter((entry) => entry !== undefined && entry !== '').join(',');
|
|
30
|
+
return { ...environment, NO_PROXY: bypassed, no_proxy: bypassed };
|
|
31
|
+
}
|
|
1
32
|
export function relayed(target) {
|
|
2
33
|
const url = new URL(target);
|
|
3
|
-
const relay =
|
|
4
|
-
if (relay === undefined
|
|
34
|
+
const relay = relayOrigin();
|
|
35
|
+
if (relay === undefined)
|
|
5
36
|
return url;
|
|
6
37
|
const through = new URL(`${url.host}${url.pathname}${url.search}`, `${relay}/`);
|
|
7
38
|
if (url.protocol === 'wss:' || url.protocol === 'ws:')
|