@agentshouse/kit 0.2.1-alpha.2 → 0.2.1-alpha.20
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 +39 -3
- package/dist/abort.js +9 -0
- package/dist/acp.js +27 -7
- package/dist/agents.js +204 -52
- package/dist/api.js +6 -1
- package/dist/authority-main.js +22 -0
- package/dist/bootstrap.json +31 -0
- package/dist/bridge.js +178 -54
- package/dist/clis-main.js +23 -0
- package/dist/clis.js +106 -32
- package/dist/configure-main.js +6 -0
- package/dist/conversations.js +128 -36
- package/dist/copies.js +809 -0
- package/dist/enrol-main.js +4 -0
- package/dist/git-main.js +153 -0
- package/dist/git.js +85 -0
- package/dist/home.js +36 -7
- package/dist/house-main.js +112 -41
- package/dist/instructions.js +16 -10
- package/dist/kit-main.js +2 -0
- package/dist/login.js +29 -5
- package/dist/mcp.js +38 -0
- package/dist/operation.js +12 -0
- package/dist/refusals.js +41 -0
- package/dist/resident.js +63 -7
- package/dist/sign-in.js +21 -5
- package/dist/skills.js +78 -0
- package/dist/transcription.js +118 -0
- package/dist/translate.js +51 -0
- package/dist/update.js +117 -0
- package/how-we-work.md +23 -0
- package/package.json +13 -9
- package/skills/ask-matt/LICENSE +21 -0
- package/skills/ask-matt/PHASE-BOUNDARIES.md +55 -0
- package/skills/ask-matt/SKILL.md +91 -0
- package/skills/ask-matt/agents/openai.yaml +4 -0
- package/skills/code-review/LICENSE +21 -0
- package/skills/code-review/SKILL.md +89 -0
- package/skills/code-review/agents/openai.yaml +3 -0
- package/skills/codebase-design/DEEPENING.md +37 -0
- package/skills/codebase-design/DESIGN-IT-TWICE.md +44 -0
- package/skills/codebase-design/LICENSE +21 -0
- package/skills/codebase-design/SKILL.md +116 -0
- package/skills/codebase-design/agents/openai.yaml +3 -0
- package/skills/diagnosing-bugs/LICENSE +21 -0
- package/skills/diagnosing-bugs/SKILL.md +140 -0
- package/skills/diagnosing-bugs/agents/openai.yaml +3 -0
- package/skills/diagnosing-bugs/scripts/hitl-loop.template.sh +44 -0
- package/skills/domain-modeling/ADR-FORMAT.md +47 -0
- package/skills/domain-modeling/CONTEXT-FORMAT.md +60 -0
- package/skills/domain-modeling/LICENSE +21 -0
- package/skills/domain-modeling/SKILL.md +76 -0
- package/skills/domain-modeling/agents/openai.yaml +3 -0
- package/skills/grill-me/LICENSE +21 -0
- package/skills/grill-me/SKILL.md +8 -0
- package/skills/grill-me/agents/openai.yaml +4 -0
- package/skills/grill-with-docs/LICENSE +21 -0
- package/skills/grill-with-docs/SKILL.md +8 -0
- package/skills/grill-with-docs/agents/openai.yaml +4 -0
- package/skills/grilling/LICENSE +21 -0
- package/skills/grilling/SKILL.md +30 -0
- package/skills/grilling/agents/openai.yaml +3 -0
- package/skills/handoff/LICENSE +21 -0
- package/skills/handoff/SKILL.md +17 -0
- package/skills/handoff/agents/openai.yaml +4 -0
- package/skills/implement/LICENSE +21 -0
- package/skills/implement/SKILL.md +16 -0
- package/skills/implement/agents/openai.yaml +4 -0
- package/skills/improve-codebase-architecture/HTML-REPORT.md +123 -0
- package/skills/improve-codebase-architecture/LICENSE +21 -0
- package/skills/improve-codebase-architecture/SKILL.md +72 -0
- package/skills/improve-codebase-architecture/agents/openai.yaml +4 -0
- package/skills/prototype/LICENSE +21 -0
- package/skills/prototype/LOGIC.md +67 -0
- package/skills/prototype/SKILL.md +28 -0
- package/skills/prototype/UI.md +112 -0
- package/skills/prototype/agents/openai.yaml +3 -0
- package/skills/research/LICENSE +21 -0
- package/skills/research/SKILL.md +14 -0
- package/skills/research/agents/openai.yaml +3 -0
- package/skills/resolving-merge-conflicts/LICENSE +21 -0
- package/skills/resolving-merge-conflicts/SKILL.md +16 -0
- package/skills/resolving-merge-conflicts/agents/openai.yaml +3 -0
- package/skills/tdd/LICENSE +21 -0
- package/skills/tdd/SKILL.md +40 -0
- package/skills/tdd/agents/openai.yaml +3 -0
- package/skills/tdd/mocking.md +59 -0
- package/skills/tdd/tests.md +77 -0
- package/skills/teach/GLOSSARY-FORMAT.md +35 -0
- package/skills/teach/LEARNING-RECORD-FORMAT.md +46 -0
- package/skills/teach/LICENSE +21 -0
- package/skills/teach/MISSION-FORMAT.md +31 -0
- package/skills/teach/RESOURCES-FORMAT.md +32 -0
- package/skills/teach/SKILL.md +141 -0
- package/skills/teach/agents/openai.yaml +4 -0
- package/skills/to-questionnaire/LICENSE +21 -0
- package/skills/to-questionnaire/SKILL.md +55 -0
- package/skills/to-questionnaire/agents/openai.yaml +4 -0
- package/skills/to-spec/LICENSE +21 -0
- package/skills/to-spec/SKILL.md +76 -0
- package/skills/to-spec/agents/openai.yaml +4 -0
- package/skills/to-tickets/LICENSE +21 -0
- package/skills/to-tickets/SKILL.md +106 -0
- package/skills/to-tickets/agents/openai.yaml +4 -0
- package/skills/wait-what/LICENSE +21 -0
- package/skills/wait-what/SKILL.md +8 -0
- package/skills/wait-what/agents/openai.yaml +4 -0
- package/skills/wayfinder/LICENSE +21 -0
- package/skills/wayfinder/SKILL.md +129 -0
- package/skills/wayfinder/agents/openai.yaml +4 -0
- package/skills/writing-for-agents/LICENSE +21 -0
- package/skills/writing-for-agents/SKILL-MECHANICS.md +22 -0
- package/skills/writing-for-agents/SKILL.md +83 -0
- package/skills/writing-for-agents/agents/openai.yaml +3 -0
package/dist/bridge.js
CHANGED
|
@@ -1,79 +1,208 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
2
2
|
import { once } from 'node:events';
|
|
3
|
+
import { setTimeout as delay } from 'node:timers/promises';
|
|
3
4
|
import { mkdir } from 'node:fs/promises';
|
|
4
5
|
import { createServer, request as httpRequest } from 'node:http';
|
|
5
6
|
import { request as httpsRequest } from 'node:https';
|
|
6
|
-
import { join } from 'node:path';
|
|
7
|
-
import {
|
|
7
|
+
import { delimiter, dirname, join } from 'node:path';
|
|
8
|
+
import { parse } from 'yaml';
|
|
9
|
+
import { HouseRefusal, retryDelay } from './api.js';
|
|
10
|
+
import { loginPath } from './clis.js';
|
|
11
|
+
import { changedPaths, } from './copies.js';
|
|
8
12
|
import { kitHome, readEnrolment } from './home.js';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
bytes[8] = 0x80 | (bytes[8] & 0x3f);
|
|
16
|
-
const hex = bytes.toString('hex');
|
|
17
|
-
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
18
|
-
}
|
|
19
|
-
async function received(request) {
|
|
13
|
+
import { callHouse, mcpBody, rpc, UNREACHABLE } from './mcp.js';
|
|
14
|
+
import { operationId, uuidOf } from './operation.js';
|
|
15
|
+
import { refusalOf } from './refusals.js';
|
|
16
|
+
const MCP_REQUEST_BYTES = 4 * 1024 * 1024;
|
|
17
|
+
const ATTACHMENTS = '/kit/attachments/upload';
|
|
18
|
+
export async function received(request) {
|
|
20
19
|
let text = '';
|
|
21
20
|
request.setEncoding('utf8');
|
|
22
21
|
for await (const chunk of request)
|
|
23
22
|
text += chunk;
|
|
24
23
|
return text;
|
|
25
24
|
}
|
|
26
|
-
|
|
25
|
+
function relay(request, response, target, authorization) {
|
|
26
|
+
const send = target.protocol === 'https:' ? httpsRequest : httpRequest;
|
|
27
|
+
const forwarded = send(target, {
|
|
28
|
+
method: request.method,
|
|
29
|
+
headers: { ...request.headers, host: target.host, ...(authorization === undefined ? {} : { authorization }) },
|
|
30
|
+
}, (answer) => {
|
|
31
|
+
response.writeHead(answer.statusCode, answer.headers);
|
|
32
|
+
answer.pipe(response);
|
|
33
|
+
});
|
|
34
|
+
forwarded.on('error', () => response.destroy());
|
|
35
|
+
request.pipe(forwarded);
|
|
36
|
+
}
|
|
37
|
+
function refusalIn(text, status) {
|
|
38
|
+
return refusalOf(text) ?? { code: '', text: text === '' ? `House refused it with ${status}` : text, conflicts: [] };
|
|
39
|
+
}
|
|
40
|
+
function answered(forwarded) {
|
|
41
|
+
if (forwarded.status >= 500)
|
|
42
|
+
throw new HouseRefusal('/', forwarded.status, forwarded.text);
|
|
43
|
+
if (forwarded.status !== 200)
|
|
44
|
+
return { refused: refusalIn(forwarded.text, forwarded.status) };
|
|
45
|
+
const answer = JSON.parse(forwarded.text);
|
|
46
|
+
if (answer.error !== undefined)
|
|
47
|
+
return { refused: refusalIn(answer.error.message, forwarded.status) };
|
|
48
|
+
const text = answer.result.content.map((content) => content.text).join('\n');
|
|
49
|
+
return answer.result.isError === true ? { refused: refusalIn(text, forwarded.status) } : { text };
|
|
50
|
+
}
|
|
51
|
+
function pendingSeconds(forwarded) {
|
|
52
|
+
if (forwarded.status !== 200)
|
|
53
|
+
return null;
|
|
54
|
+
const { result } = JSON.parse(forwarded.text);
|
|
55
|
+
if (result === undefined || result.isError === true)
|
|
56
|
+
return null;
|
|
57
|
+
const text = result.content.map((content) => content.text).join('\n');
|
|
58
|
+
if (!text.startsWith('{"pending":'))
|
|
59
|
+
return null;
|
|
60
|
+
const seconds = JSON.parse(text).pending.retry_after;
|
|
61
|
+
return typeof seconds === 'number' ? seconds : null;
|
|
62
|
+
}
|
|
63
|
+
function resendAfter(forwarded, attempt) {
|
|
64
|
+
if (forwarded === null)
|
|
65
|
+
return retryDelay(attempt);
|
|
66
|
+
if (forwarded.status >= 500)
|
|
67
|
+
return refusalOf(forwarded.text) === null ? retryDelay(attempt) : null;
|
|
68
|
+
const seconds = pendingSeconds(forwarded);
|
|
69
|
+
return seconds === null ? null : seconds * 1000;
|
|
70
|
+
}
|
|
71
|
+
function versioned(conversationId, text) {
|
|
72
|
+
const file = JSON.parse(text);
|
|
73
|
+
const identity = JSON.stringify([conversationId, file.room_ref ?? null, file.name, file.sha256]);
|
|
74
|
+
return JSON.stringify({ ...file, version: uuidOf(createHash('sha256').update(identity).digest(), 8) });
|
|
75
|
+
}
|
|
76
|
+
function editAnswer(forwarded) {
|
|
77
|
+
const answer = answered(forwarded);
|
|
78
|
+
if ('refused' in answer)
|
|
79
|
+
return answer;
|
|
80
|
+
const { results } = parse(answer.text);
|
|
81
|
+
return {
|
|
82
|
+
accepted: results.flatMap((result) => [
|
|
83
|
+
...(result.from === undefined ? [] : [{ path: result.from, revision: null, content: null }]),
|
|
84
|
+
{ path: result.path, revision: result.revision ?? null },
|
|
85
|
+
]),
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
export async function openBridge(house, copies, conversationId, signal) {
|
|
89
|
+
const path = [join(kitHome(), 'shim'), dirname(process.execPath), await loginPath()].join(delimiter);
|
|
27
90
|
const origin = (await readEnrolment()).house;
|
|
28
91
|
const { credential } = await house.post(`/kit/conversations/${conversationId}/credential`, {}, signal);
|
|
29
92
|
const closed = new AbortController();
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
93
|
+
const sent = (message, operation) => callHouse(origin, credential, message, operation, closed.signal);
|
|
94
|
+
const send = async (message, operation) => {
|
|
95
|
+
if (operation === null)
|
|
96
|
+
return sent(message, null);
|
|
97
|
+
for (let attempt = 0;; attempt++) {
|
|
98
|
+
const forwarded = await sent(message, operation).catch((error) => {
|
|
99
|
+
if (closed.signal.aborted)
|
|
100
|
+
throw error;
|
|
101
|
+
return null;
|
|
102
|
+
});
|
|
103
|
+
const after = resendAfter(forwarded, attempt);
|
|
104
|
+
if (after === null)
|
|
105
|
+
return forwarded;
|
|
106
|
+
await delay(after, undefined, { signal: closed.signal });
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
const call = (name, args) => rpc('tools/call', { name, arguments: args });
|
|
110
|
+
const staged = async (operation, changes) => {
|
|
111
|
+
const bytes = Buffer.from(JSON.stringify({ changes }));
|
|
112
|
+
const sha256 = createHash('sha256').update(bytes).digest('hex');
|
|
113
|
+
const prepared = answered(await send(call('run_command', {
|
|
114
|
+
command: 'prepare_edit_upload',
|
|
115
|
+
arguments: { paths: changedPaths(changes), bytes: bytes.length, sha256 },
|
|
116
|
+
}), operation));
|
|
117
|
+
if ('refused' in prepared)
|
|
118
|
+
return prepared;
|
|
119
|
+
const { transfer } = parse(prepared.text);
|
|
120
|
+
const posted = await fetch(transfer.url, {
|
|
121
|
+
method: 'POST',
|
|
122
|
+
headers: { 'content-type': 'text/plain; charset=utf-8' },
|
|
123
|
+
body: Buffer.concat([Buffer.from(`${transfer.operation}\n`), bytes]),
|
|
124
|
+
signal: closed.signal,
|
|
125
|
+
});
|
|
126
|
+
const text = await posted.text();
|
|
127
|
+
if (posted.status >= 500)
|
|
128
|
+
throw new HouseRefusal('/', posted.status, text);
|
|
129
|
+
if (!posted.ok)
|
|
130
|
+
return { refused: refusalIn(text, posted.status) };
|
|
131
|
+
const held = JSON.parse(text).transfer;
|
|
132
|
+
return { url: held.url, operation: held.operation, bytes: bytes.length, sha256 };
|
|
133
|
+
};
|
|
134
|
+
let mutations = null;
|
|
135
|
+
const writes = async (tool) => {
|
|
136
|
+
mutations ??= house
|
|
137
|
+
.post('/kit/tools/mutations', {}, closed.signal)
|
|
138
|
+
.then(({ tools }) => new Set(tools.filter((listed) => listed.writes).map((listed) => listed.name)));
|
|
139
|
+
try {
|
|
140
|
+
return (await mutations).has(tool);
|
|
141
|
+
}
|
|
142
|
+
catch (error) {
|
|
143
|
+
mutations = null;
|
|
144
|
+
throw error;
|
|
145
|
+
}
|
|
55
146
|
};
|
|
56
147
|
const forward = async (path, text) => {
|
|
57
|
-
|
|
148
|
+
if (path === '/') {
|
|
149
|
+
const message = JSON.parse(text);
|
|
150
|
+
const tool = message.method === 'tools/call' ? String(message.params.name) : null;
|
|
151
|
+
return send(message, tool !== null && (await writes(tool)) ? operationId() : null);
|
|
152
|
+
}
|
|
58
153
|
const answer = await fetch(new URL(path, origin), {
|
|
59
154
|
method: 'POST',
|
|
60
|
-
headers: { 'content-type': 'application/json', authorization: `Bearer ${credential}
|
|
61
|
-
body:
|
|
155
|
+
headers: { 'content-type': 'application/json', authorization: `Bearer ${credential}` },
|
|
156
|
+
body: versioned(conversationId, text),
|
|
62
157
|
signal: closed.signal,
|
|
63
158
|
});
|
|
64
159
|
return { status: answer.status, text: await answer.text() };
|
|
65
160
|
};
|
|
161
|
+
const caller = {
|
|
162
|
+
key: `conversation:${conversationId}`,
|
|
163
|
+
submit: async (operation, changes, held, retain) => {
|
|
164
|
+
const inline = call('edit', { changes });
|
|
165
|
+
let upload = held;
|
|
166
|
+
if (upload === undefined && Buffer.byteLength(mcpBody(inline, operation)) > MCP_REQUEST_BYTES) {
|
|
167
|
+
const prepared = await staged(operation, changes);
|
|
168
|
+
if ('refused' in prepared)
|
|
169
|
+
return prepared;
|
|
170
|
+
upload = prepared;
|
|
171
|
+
await retain(upload);
|
|
172
|
+
}
|
|
173
|
+
return editAnswer(await send(upload === undefined ? inline : call('edit', { paths: changedPaths(changes), upload }), operation));
|
|
174
|
+
},
|
|
175
|
+
};
|
|
176
|
+
const local = async (path, text) => {
|
|
177
|
+
if (path === '/git/push') {
|
|
178
|
+
const { cwd, commit } = JSON.parse(text);
|
|
179
|
+
return { status: 200, text: JSON.stringify(await copies.push(cwd, commit, caller)) };
|
|
180
|
+
}
|
|
181
|
+
if (path === '/git/observed') {
|
|
182
|
+
await copies.observed(JSON.parse(text));
|
|
183
|
+
return { status: 200, text: '{}' };
|
|
184
|
+
}
|
|
185
|
+
return path === '/' || path === ATTACHMENTS ? forward(path, text) : { status: 404, text: '' };
|
|
186
|
+
};
|
|
66
187
|
const sockets = join(kitHome(), 'bridges');
|
|
67
188
|
await mkdir(sockets, { recursive: true, mode: 0o700 });
|
|
68
189
|
const socketPath = join(sockets, `${randomUUID()}.sock`);
|
|
69
190
|
const bridge = createServer(async (request, response) => {
|
|
70
191
|
try {
|
|
71
192
|
const path = request.url ?? '';
|
|
72
|
-
|
|
73
|
-
|
|
193
|
+
if (URL.canParse(path)) {
|
|
194
|
+
relay(request, response, new URL(path));
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
const answered = await local(path, await received(request));
|
|
198
|
+
response.writeHead(answered.status, { 'content-type': 'application/json' }).end(answered.text);
|
|
74
199
|
}
|
|
75
200
|
catch (error) {
|
|
76
|
-
|
|
201
|
+
if (error instanceof HouseRefusal) {
|
|
202
|
+
response.writeHead(error.status, { 'content-type': 'application/json' }).end(error.text);
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
response.writeHead(502).end(request.url === '/git/push' && error instanceof Error ? error.message : UNREACHABLE);
|
|
77
206
|
}
|
|
78
207
|
});
|
|
79
208
|
bridge.listen(socketPath);
|
|
@@ -86,13 +215,7 @@ export async function openBridge(house, conversationId, signal) {
|
|
|
86
215
|
response.writeHead(404).end();
|
|
87
216
|
return;
|
|
88
217
|
}
|
|
89
|
-
|
|
90
|
-
const forwarded = send(target, { method: request.method, headers: { ...request.headers, host: target.host, authorization } }, (answer) => {
|
|
91
|
-
response.writeHead(answer.statusCode, answer.headers);
|
|
92
|
-
answer.pipe(response);
|
|
93
|
-
});
|
|
94
|
-
forwarded.on('error', () => response.destroy());
|
|
95
|
-
request.pipe(forwarded);
|
|
218
|
+
relay(request, response, target, authorization);
|
|
96
219
|
});
|
|
97
220
|
git.listen(0, '127.0.0.1');
|
|
98
221
|
await once(git, 'listening');
|
|
@@ -100,12 +223,13 @@ export async function openBridge(house, conversationId, signal) {
|
|
|
100
223
|
return {
|
|
101
224
|
env: {
|
|
102
225
|
HOUSE_BRIDGE: socketPath,
|
|
226
|
+
PATH: path,
|
|
103
227
|
GIT_CONFIG_COUNT: '1',
|
|
104
228
|
GIT_CONFIG_KEY_0: `url.${proxy}/app/.insteadOf`,
|
|
105
229
|
GIT_CONFIG_VALUE_0: app,
|
|
106
230
|
},
|
|
107
231
|
tool: async (name, args) => {
|
|
108
|
-
const forwarded = await forward('/', JSON.stringify(
|
|
232
|
+
const forwarded = await forward('/', JSON.stringify(call(name, args)));
|
|
109
233
|
if (forwarded.status !== 200)
|
|
110
234
|
throw new Error(`House refused ${name} with ${forwarded.status}: ${forwarded.text}`);
|
|
111
235
|
const answer = JSON.parse(forwarded.text);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { setGlobalProxyFromEnv } from 'node:http';
|
|
2
|
+
import { post } from './api.js';
|
|
3
|
+
import { CLIS, below, locate, versionOf } from './clis.js';
|
|
4
|
+
import { readEnrolment } from './home.js';
|
|
5
|
+
setGlobalProxyFromEnv();
|
|
6
|
+
try {
|
|
7
|
+
const { house, credential } = (await readEnrolment());
|
|
8
|
+
const { agents } = await post(house, '/kit/agents/desired', {}, credential);
|
|
9
|
+
for (const kind of agents) {
|
|
10
|
+
const cli = await locate(kind);
|
|
11
|
+
if (cli === null)
|
|
12
|
+
continue;
|
|
13
|
+
const release = await versionOf(cli);
|
|
14
|
+
if (release === null)
|
|
15
|
+
continue;
|
|
16
|
+
const { bin, minimum } = CLIS[kind];
|
|
17
|
+
process.stdout.write(`${[bin, cli, release, minimum, below(release, minimum) ? 'old' : 'current'].join('\t')}\n`);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
process.stderr.write(`kit: ${error.message}\n`);
|
|
22
|
+
process.exitCode = 1;
|
|
23
|
+
}
|
package/dist/clis.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
2
|
import { readFileSync } from 'node:fs';
|
|
3
3
|
import { readFile } from 'node:fs/promises';
|
|
4
|
+
import { userInfo } from 'node:os';
|
|
4
5
|
import { join } from 'node:path';
|
|
5
6
|
import { kitHome } from './home.js';
|
|
6
7
|
const RUNNING_JOB = new Set(['running', 'paused']);
|
|
@@ -20,34 +21,55 @@ function asyncTask({ method, params }) {
|
|
|
20
21
|
}
|
|
21
22
|
return null;
|
|
22
23
|
}
|
|
24
|
+
function airPhase({ _meta }) {
|
|
25
|
+
const phase = _meta?.jetbrains?.air?.phase;
|
|
26
|
+
if (phase === 'commentary')
|
|
27
|
+
return 'note';
|
|
28
|
+
if (phase === 'final_answer')
|
|
29
|
+
return 'answer';
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
23
32
|
export const CLIS = {
|
|
24
33
|
'codex-acp': {
|
|
25
|
-
|
|
26
|
-
|
|
34
|
+
bin: 'codex',
|
|
35
|
+
minimum: '0.159.1',
|
|
36
|
+
install: 'curl -fsSL https://chatgpt.com/codex/install.sh | sh',
|
|
37
|
+
adapter: { package: '@agentclientprotocol/codex-acp', bin: 'codex-acp', executable: 'CODEX_PATH', env: {} },
|
|
27
38
|
args: [],
|
|
28
|
-
signedIn: { command: ['
|
|
29
|
-
login: { args: ['
|
|
39
|
+
signedIn: { command: ['login', 'status'] },
|
|
40
|
+
login: { args: ['login', '--device-auth'], code: 'show' },
|
|
30
41
|
queues: false,
|
|
31
42
|
turnStarted: (notice) => threadStatus(notice) === 'active',
|
|
32
43
|
turnEnded: (notice) => threadStatus(notice) === 'idle',
|
|
33
44
|
job: asyncTask,
|
|
45
|
+
phase: airPhase,
|
|
34
46
|
},
|
|
35
47
|
'claude-agent-acp': {
|
|
36
|
-
|
|
37
|
-
|
|
48
|
+
bin: 'claude',
|
|
49
|
+
minimum: '2.1.286',
|
|
50
|
+
install: 'curl -fsSL https://claude.ai/install.sh | bash',
|
|
51
|
+
adapter: {
|
|
52
|
+
package: '@agentclientprotocol/claude-agent-acp',
|
|
53
|
+
bin: 'claude-agent-acp',
|
|
54
|
+
executable: 'CLAUDE_CODE_EXECUTABLE',
|
|
55
|
+
env: { CLAUDE_CODE_ENTRYPOINT: 'claude-agent-acp' },
|
|
56
|
+
},
|
|
38
57
|
args: [],
|
|
39
|
-
signedIn: { command: ['
|
|
40
|
-
login: { args: ['
|
|
58
|
+
signedIn: { command: ['auth', 'status'] },
|
|
59
|
+
login: { args: ['auth', 'login', '--claudeai'], code: 'collect', rejected: 'Invalid code' },
|
|
41
60
|
queues: false,
|
|
42
61
|
turnStarted: () => false,
|
|
43
62
|
turnEnded: ({ method, params }) => method === 'session/update' &&
|
|
44
63
|
params?.update?.sessionUpdate === 'usage_update' &&
|
|
45
64
|
params.update._meta?.['_claude/origin'] !== undefined,
|
|
46
65
|
job: asyncTask,
|
|
66
|
+
phase: () => null,
|
|
47
67
|
},
|
|
48
68
|
'grok-build': {
|
|
49
|
-
package: '@xai-official/grok',
|
|
50
69
|
bin: 'grok',
|
|
70
|
+
minimum: '1.0.46',
|
|
71
|
+
install: 'curl -fsSL https://x.ai/cli/install.sh | bash',
|
|
72
|
+
adapter: null,
|
|
51
73
|
args: ['agent', '--no-leader', 'stdio'],
|
|
52
74
|
signedIn: { initializeMeta: 'defaultAuthMethodId' },
|
|
53
75
|
login: { args: ['login', '--device-auth'], code: 'show' },
|
|
@@ -61,50 +83,102 @@ export const CLIS = {
|
|
|
61
83
|
return { id: params.update.task_snapshot.task_id, running: false };
|
|
62
84
|
return null;
|
|
63
85
|
},
|
|
86
|
+
phase: () => null,
|
|
64
87
|
},
|
|
65
88
|
};
|
|
66
89
|
const KIT_PACKAGE = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
|
|
67
90
|
export const KIT_VERSION = KIT_PACKAGE.version;
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
91
|
+
const PROXY = /^https?_proxy$/i;
|
|
92
|
+
const VERSION = /\d+\.\d+\.\d+(?:-[0-9A-Za-z.]+)?/;
|
|
93
|
+
const INSTALL_MS = 15 * 60_000;
|
|
94
|
+
const READ_MS = 30_000;
|
|
95
|
+
const CAUSE_CHARACTERS = 4000;
|
|
71
96
|
function prefix(kind) {
|
|
72
97
|
return join(kitHome(), 'agents', kind);
|
|
73
98
|
}
|
|
74
|
-
export function
|
|
75
|
-
return join(prefix(kind), 'node_modules', '.bin', CLIS[kind].bin);
|
|
99
|
+
export function adapterCommand(kind) {
|
|
100
|
+
return join(prefix(kind), 'node_modules', '.bin', CLIS[kind].adapter.bin);
|
|
76
101
|
}
|
|
77
|
-
|
|
102
|
+
async function installedAdapter(kind) {
|
|
78
103
|
try {
|
|
79
|
-
const manifest = join(prefix(kind), 'node_modules', CLIS[kind].package, 'package.json');
|
|
104
|
+
const manifest = join(prefix(kind), 'node_modules', CLIS[kind].adapter.package, 'package.json');
|
|
80
105
|
return JSON.parse(await readFile(manifest, 'utf8')).version;
|
|
81
106
|
}
|
|
82
107
|
catch {
|
|
83
108
|
return null;
|
|
84
109
|
}
|
|
85
110
|
}
|
|
86
|
-
export function
|
|
111
|
+
export function withoutProxy() {
|
|
112
|
+
return Object.fromEntries(Object.entries(process.env).filter(([name]) => !PROXY.test(name)));
|
|
113
|
+
}
|
|
114
|
+
export function run(command, args, timeoutMs, detached = false, signal) {
|
|
87
115
|
return new Promise((resolve) => {
|
|
88
|
-
const child = spawn(command, args, {
|
|
116
|
+
const child = spawn(command, args, {
|
|
117
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
118
|
+
timeout: timeoutMs,
|
|
119
|
+
env: withoutProxy(),
|
|
120
|
+
detached,
|
|
121
|
+
signal,
|
|
122
|
+
});
|
|
123
|
+
let stdout = '';
|
|
89
124
|
let output = '';
|
|
90
|
-
child.stdout.on('data', (chunk) => {
|
|
91
|
-
|
|
125
|
+
child.stdout.setEncoding('utf8').on('data', (chunk) => {
|
|
126
|
+
stdout += chunk;
|
|
127
|
+
output += chunk;
|
|
92
128
|
});
|
|
93
|
-
child.stderr.on('data', (chunk) => {
|
|
94
|
-
output += chunk
|
|
129
|
+
child.stderr.setEncoding('utf8').on('data', (chunk) => {
|
|
130
|
+
output += chunk;
|
|
95
131
|
});
|
|
96
|
-
child.on('error', (error) => resolve({ status: null, output: error.message }));
|
|
97
|
-
child.on('close', (status) => resolve({ status, output }));
|
|
132
|
+
child.on('error', (error) => resolve({ status: null, stdout, output: error.message }));
|
|
133
|
+
child.on('close', (status) => resolve({ status, stdout, output }));
|
|
98
134
|
});
|
|
99
135
|
}
|
|
100
|
-
export
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
const
|
|
105
|
-
if (
|
|
106
|
-
|
|
136
|
+
export function failureOf(ran, program) {
|
|
137
|
+
return ran.output.trim().slice(-CAUSE_CHARACTERS) || `${program} exited with ${ran.status ?? 'a signal'}`;
|
|
138
|
+
}
|
|
139
|
+
export async function installAdapter(kind) {
|
|
140
|
+
const adapter = CLIS[kind].adapter;
|
|
141
|
+
if (adapter === null)
|
|
142
|
+
return null;
|
|
143
|
+
const release = KIT_PACKAGE.peerDependencies[adapter.package];
|
|
144
|
+
if ((await installedAdapter(kind)) === release)
|
|
107
145
|
return null;
|
|
146
|
+
const ran = await run('npm', ['install', '--prefix', prefix(kind), '--no-save', '--no-audit', '--no-fund', '--omit=optional', `${adapter.package}@${release}`], INSTALL_MS);
|
|
147
|
+
return ran.status === 0 ? null : failureOf(ran, 'npm');
|
|
148
|
+
}
|
|
149
|
+
export async function installCli(kind) {
|
|
150
|
+
const ran = await run('bash', ['-o', 'pipefail', '-c', CLIS[kind].install], INSTALL_MS, true);
|
|
151
|
+
return ran.status === 0 ? null : failureOf(ran, 'the install');
|
|
152
|
+
}
|
|
153
|
+
function loginShell() {
|
|
154
|
+
return process.env.SHELL || userInfo().shell;
|
|
155
|
+
}
|
|
156
|
+
const FOUND = 'house-kit-cli ';
|
|
157
|
+
const LOOKUP = `found=$(command -v "$1") || exit 0; case $found in /*) ;; *) found=$(pwd -P)/$found ;; esac; printf "${FOUND}%s\\n" "$found"`;
|
|
158
|
+
const USER_BIN = 'case ":$PATH:" in *":$HOME/.local/bin:"*) ;; *) PATH="$PATH:$HOME/.local/bin" ;; esac; export PATH';
|
|
159
|
+
function inLoginShell(script, argument = '') {
|
|
160
|
+
return run(loginShell(), ['-l', '-i', '-c', `exec /bin/sh -c '${USER_BIN}; ${script}' sh ${argument}`], READ_MS, true);
|
|
161
|
+
}
|
|
162
|
+
export async function locate(kind) {
|
|
163
|
+
const ran = await inLoginShell(LOOKUP, CLIS[kind].bin);
|
|
164
|
+
return ran.stdout.split('\n').findLast((line) => line.startsWith(FOUND))?.slice(FOUND.length) ?? null;
|
|
165
|
+
}
|
|
166
|
+
export async function loginPath() {
|
|
167
|
+
const marker = 'house-kit-path ';
|
|
168
|
+
const ran = await inLoginShell(`printf "${marker}%s\\n" "$PATH"`);
|
|
169
|
+
return ran.stdout.split('\n').findLast((line) => line.startsWith(marker)).slice(marker.length);
|
|
170
|
+
}
|
|
171
|
+
export async function versionOf(path) {
|
|
172
|
+
return VERSION.exec((await run(path, ['--version'], READ_MS)).stdout)?.[0] ?? null;
|
|
173
|
+
}
|
|
174
|
+
function numbers(version) {
|
|
175
|
+
return version.split(/[.-]/, 3).map(Number);
|
|
176
|
+
}
|
|
177
|
+
export function below(found, minimum) {
|
|
178
|
+
const [have, need] = [numbers(found), numbers(minimum)];
|
|
179
|
+
for (let index = 0; index < 3; index++) {
|
|
180
|
+
if (have[index] !== need[index])
|
|
181
|
+
return have[index] < need[index];
|
|
108
182
|
}
|
|
109
|
-
return
|
|
183
|
+
return found.includes('-') && !minimum.includes('-');
|
|
110
184
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { readConfiguration, writeConfiguration } from './home.js';
|
|
2
|
+
const skills = !process.argv.slice(2).includes('--no-skills');
|
|
3
|
+
const stored = await readConfiguration();
|
|
4
|
+
await writeConfiguration({ skills });
|
|
5
|
+
if (stored.skills !== skills)
|
|
6
|
+
process.stdout.write('changed\n');
|