@agentshouse/kit 0.2.1-ce3d2bb67177c → 0.2.1-ce46b2b55463f
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 +31 -35
- package/dist/acp.js +56 -6
- package/dist/afk.js +17 -0
- package/dist/agents.js +120 -51
- package/dist/api.js +11 -6
- package/dist/binaries.js +79 -0
- package/dist/bridge.js +30 -26
- package/dist/building.js +50 -0
- package/dist/calls.js +29 -4
- package/dist/chunks.js +49 -0
- package/dist/clis.js +61 -49
- package/dist/connect.js +108 -0
- package/dist/connection.js +33 -38
- package/dist/content.js +106 -0
- package/dist/conversations.js +325 -141
- package/dist/copies.js +720 -247
- package/dist/earlier.js +263 -0
- package/dist/end.js +4 -5
- package/dist/events.js +549 -281
- package/dist/files.js +110 -28
- package/dist/git-main.js +24 -29
- package/dist/git.js +89 -14
- package/dist/grok.js +39 -0
- package/dist/home.js +65 -29
- package/dist/house-cli.js +114 -159
- package/dist/house-main.js +3 -3
- package/dist/instructions.js +29 -11
- package/dist/keys.js +238 -0
- package/dist/kit-cli.js +16 -6
- package/dist/kit-main.js +3 -3
- package/dist/login.js +36 -20
- package/dist/logout.js +2 -2
- package/dist/mcp.js +38 -1
- package/dist/owner.js +46 -0
- package/dist/placement.js +9 -23
- package/dist/refusals.js +37 -21
- package/dist/relay.js +21 -0
- package/dist/resident.js +109 -65
- package/dist/scope.js +12 -4
- package/dist/scripts.js +303 -0
- package/dist/secret-input.js +1 -1
- package/dist/settings.js +188 -0
- package/dist/sign-in.js +49 -3
- package/dist/silence.js +28 -0
- package/dist/skills.js +41 -96
- package/dist/supervisor.js +163 -0
- package/dist/transcription.js +37 -25
- package/dist/translate.js +18 -9
- package/dist/update.js +115 -117
- package/dist/wire.js +19 -9
- package/dist/work.js +9 -2
- package/dist/workspace.js +103 -0
- package/package.json +25 -21
- package/dist/authority-main.js +0 -22
- package/dist/bootstrap.json +0 -24
- package/dist/chatgpt.js +0 -32
- package/dist/clis-main.js +0 -23
- package/dist/configure-main.js +0 -6
- package/dist/enrol-main.js +0 -10
- package/dist/parts.js +0 -82
- package/dist/service-main.js +0 -9
- package/dist/service.js +0 -55
- package/how-we-work.md +0 -33
- package/skills/ask-matt/LICENSE +0 -21
- package/skills/ask-matt/PHASE-BOUNDARIES.md +0 -55
- package/skills/ask-matt/SKILL.md +0 -97
- package/skills/ask-matt/agents/openai.yaml +0 -5
- 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 -114
- package/skills/codebase-design/agents/openai.yaml +0 -3
- package/skills/diagnosing-bugs/LICENSE +0 -21
- package/skills/diagnosing-bugs/SKILL.md +0 -138
- 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/GLOSSARY-FORMAT.md +0 -60
- package/skills/domain-modeling/LICENSE +0 -21
- package/skills/domain-modeling/SKILL.md +0 -74
- package/skills/domain-modeling/agents/openai.yaml +0 -3
- package/skills/grill-me/LICENSE +0 -21
- package/skills/grill-me/SKILL.md +0 -7
- package/skills/grill-me/agents/openai.yaml +0 -5
- package/skills/grill-with-docs/LICENSE +0 -21
- package/skills/grill-with-docs/SKILL.md +0 -7
- package/skills/grill-with-docs/agents/openai.yaml +0 -5
- 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 -16
- package/skills/handoff/agents/openai.yaml +0 -5
- package/skills/implement/LICENSE +0 -21
- package/skills/implement/SKILL.md +0 -17
- package/skills/implement/agents/openai.yaml +0 -5
- package/skills/implement-spec/LICENSE +0 -21
- package/skills/implement-spec/SKILL.md +0 -40
- package/skills/implement-spec/agents/openai.yaml +0 -5
- 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 -71
- package/skills/improve-codebase-architecture/agents/openai.yaml +0 -5
- package/skills/pr/CREDITS.md +0 -3
- package/skills/pr/LICENSE +0 -21
- package/skills/pr/SKILL.md +0 -170
- package/skills/pr/agents/openai.yaml +0 -3
- package/skills/prototype/LICENSE +0 -21
- package/skills/prototype/LOGIC.md +0 -67
- package/skills/prototype/SKILL.md +0 -26
- 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 -12
- package/skills/research/agents/openai.yaml +0 -3
- package/skills/retro/LICENSE +0 -21
- package/skills/retro/SKILL.md +0 -44
- package/skills/retro/agents/openai.yaml +0 -5
- package/skills/tdd/LICENSE +0 -21
- package/skills/tdd/SKILL.md +0 -38
- 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 -140
- package/skills/teach/agents/openai.yaml +0 -5
- package/skills/to-questionnaire/LICENSE +0 -21
- package/skills/to-questionnaire/SKILL.md +0 -54
- package/skills/to-questionnaire/agents/openai.yaml +0 -5
- package/skills/to-spec/LICENSE +0 -21
- package/skills/to-spec/SKILL.md +0 -75
- package/skills/to-spec/agents/openai.yaml +0 -5
- package/skills/to-tickets/LICENSE +0 -21
- package/skills/to-tickets/SKILL.md +0 -105
- package/skills/to-tickets/agents/openai.yaml +0 -5
- package/skills/triage/AGENT-BRIEF.md +0 -207
- package/skills/triage/LICENSE +0 -21
- package/skills/triage/OUT-OF-SCOPE.md +0 -105
- package/skills/triage/SKILL.md +0 -112
- package/skills/triage/agents/openai.yaml +0 -5
- package/skills/wait-what/LICENSE +0 -21
- package/skills/wait-what/SKILL.md +0 -7
- package/skills/wait-what/agents/openai.yaml +0 -5
- package/skills/wayfinder/LICENSE +0 -21
- package/skills/wayfinder/SKILL.md +0 -128
- package/skills/wayfinder/agents/openai.yaml +0 -5
- package/skills/wizard/LICENSE +0 -21
- package/skills/wizard/SKILL.md +0 -44
- package/skills/wizard/agents/openai.yaml +0 -3
- package/skills/wizard/template.sh +0 -223
- 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 -81
- package/skills/writing-for-agents/agents/openai.yaml +0 -3
package/dist/binaries.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
+
import { createWriteStream } from 'node:fs';
|
|
3
|
+
import { mkdir, rm } from 'node:fs/promises';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import { Readable } from 'node:stream';
|
|
6
|
+
import { pipeline } from 'node:stream/promises';
|
|
7
|
+
import { downloaded, fetched, fileRange, mediaTypeOf, sentPart, uploaded } from './files.js';
|
|
8
|
+
import { blobBytes, blobSizes, isText, storedFile } from './git.js';
|
|
9
|
+
const SENT_AT_ONCE = 10;
|
|
10
|
+
const UPLOADS = 'house-uploads';
|
|
11
|
+
const DOWNLOADS = 'house-downloads';
|
|
12
|
+
const OCTET_STREAM = 'application/octet-stream';
|
|
13
|
+
const MARKDOWN = /\.md$/i;
|
|
14
|
+
const STORE = {
|
|
15
|
+
unreached: (error) => new Error(`the store did not answer (${error.code ?? error.message})`),
|
|
16
|
+
refused: (status) => new Error(`the store answered ${status}`),
|
|
17
|
+
};
|
|
18
|
+
async function described(repository, object, bytes, path) {
|
|
19
|
+
const digest = createHash('sha256');
|
|
20
|
+
for await (const chunk of blobBytes(repository, object))
|
|
21
|
+
digest.update(chunk);
|
|
22
|
+
return { bytes, sha256: digest.digest('hex'), media_type: mediaTypeOf(path) ?? OCTET_STREAM };
|
|
23
|
+
}
|
|
24
|
+
export async function sorted(repository, arriving, maxBytes) {
|
|
25
|
+
const sizes = await blobSizes(repository, arriving.map(([, object]) => object));
|
|
26
|
+
const binary = new Map();
|
|
27
|
+
const markdown = [];
|
|
28
|
+
for (const [path, object] of arriving) {
|
|
29
|
+
const size = sizes.get(object);
|
|
30
|
+
if (await isText(repository, object, size, maxBytes))
|
|
31
|
+
continue;
|
|
32
|
+
if (MARKDOWN.test(path))
|
|
33
|
+
markdown.push(path);
|
|
34
|
+
else
|
|
35
|
+
binary.set(path, await described(repository, object, size, path));
|
|
36
|
+
}
|
|
37
|
+
return { binary, markdown };
|
|
38
|
+
}
|
|
39
|
+
export async function eachAtOnce(items, work) {
|
|
40
|
+
let next = 0;
|
|
41
|
+
const working = async () => {
|
|
42
|
+
while (next < items.length)
|
|
43
|
+
await work(items[next++]);
|
|
44
|
+
};
|
|
45
|
+
await Promise.all(Array.from({ length: Math.min(SENT_AT_ONCE, items.length) }, working));
|
|
46
|
+
}
|
|
47
|
+
export async function sentBinary(repository, object, name, file, upload, finish) {
|
|
48
|
+
const directory = join(repository, '.git', UPLOADS);
|
|
49
|
+
await mkdir(directory, { recursive: true });
|
|
50
|
+
const copy = join(directory, randomUUID());
|
|
51
|
+
try {
|
|
52
|
+
await pipeline(Readable.from(blobBytes(repository, object)), createWriteStream(copy, { flags: 'wx' }));
|
|
53
|
+
await uploaded({ id: upload.id, part_bytes: upload.part_bytes }, {
|
|
54
|
+
name,
|
|
55
|
+
bytes: file.bytes,
|
|
56
|
+
sha256: file.sha256,
|
|
57
|
+
read: (start, end) => fileRange(copy, start, end, (error) => error),
|
|
58
|
+
send: (url, start, end, headers) => sentPart(url, copy, start, end, headers, STORE),
|
|
59
|
+
finish,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
finally {
|
|
63
|
+
await rm(copy, { force: true });
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
export async function receivedBinary(repository, name, address) {
|
|
67
|
+
const file = join(repository, '.git', DOWNLOADS, randomUUID());
|
|
68
|
+
try {
|
|
69
|
+
await downloaded(address, (url) => fetched(url), file, name);
|
|
70
|
+
return await storedFile(repository, file);
|
|
71
|
+
}
|
|
72
|
+
finally {
|
|
73
|
+
await rm(file, { force: true });
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
export async function sweptTransfers(repository) {
|
|
77
|
+
for (const directory of [UPLOADS, DOWNLOADS])
|
|
78
|
+
await rm(join(repository, '.git', directory), { recursive: true, force: true });
|
|
79
|
+
}
|
package/dist/bridge.js
CHANGED
|
@@ -8,12 +8,13 @@ import { parse } from 'yaml';
|
|
|
8
8
|
import { finalRefusal, HouseRefusal, retryDelay, retrying } from './api.js';
|
|
9
9
|
import { loginPath } from './clis.js';
|
|
10
10
|
import { changedPaths, } from './copies.js';
|
|
11
|
+
import { fileInfo } from './files.js';
|
|
11
12
|
import { kitHome, readEnrolment, socketDirectory } from './home.js';
|
|
12
|
-
import { callHouse, mcpBody, rpc, UNREACHABLE } from './mcp.js';
|
|
13
|
+
import { callHouse, mcpBody, refusalIn, rpc, toolAnswer, UNREACHABLE } from './mcp.js';
|
|
13
14
|
import { operationId } from './operation.js';
|
|
14
|
-
import { refusalOf, retryable } from './refusals.js';
|
|
15
|
+
import { refusalOf, retryable, stopsPush } from './refusals.js';
|
|
15
16
|
import { relayed } from './relay.js';
|
|
16
|
-
const MCP_REQUEST_BYTES =
|
|
17
|
+
const MCP_REQUEST_BYTES = 4_000_000;
|
|
17
18
|
export async function received(request) {
|
|
18
19
|
let text = '';
|
|
19
20
|
request.setEncoding('utf8');
|
|
@@ -34,18 +35,6 @@ function relay(request, response, house, authorization) {
|
|
|
34
35
|
forwarded.on('error', () => response.destroy());
|
|
35
36
|
request.pipe(forwarded);
|
|
36
37
|
}
|
|
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 !== 200)
|
|
42
|
-
return { refused: refusalIn(forwarded.text, forwarded.status) };
|
|
43
|
-
const answer = JSON.parse(forwarded.text);
|
|
44
|
-
if (answer.error !== undefined)
|
|
45
|
-
return { refused: refusalIn(answer.error.message, forwarded.status) };
|
|
46
|
-
const text = answer.result.content.map((content) => content.text).join('\n');
|
|
47
|
-
return answer.result.isError === true ? { refused: refusalIn(text, forwarded.status) } : { text };
|
|
48
|
-
}
|
|
49
38
|
function pendingSeconds(forwarded) {
|
|
50
39
|
if (forwarded.status !== 200)
|
|
51
40
|
return null;
|
|
@@ -58,16 +47,19 @@ function pendingSeconds(forwarded) {
|
|
|
58
47
|
const seconds = JSON.parse(text).pending.retry_after;
|
|
59
48
|
return typeof seconds === 'number' ? seconds : null;
|
|
60
49
|
}
|
|
61
|
-
function resendAfter(forwarded, attempt) {
|
|
50
|
+
function resendAfter(forwarded, attempt, pushing) {
|
|
62
51
|
if (forwarded === null)
|
|
63
52
|
return retryDelay(attempt);
|
|
64
|
-
if (forwarded.status !== 200)
|
|
53
|
+
if (forwarded.status !== 200) {
|
|
54
|
+
if (pushing && stopsPush(refusalOf(forwarded.text)))
|
|
55
|
+
return null;
|
|
65
56
|
return retryable(forwarded.text) === false ? null : retryDelay(attempt);
|
|
57
|
+
}
|
|
66
58
|
const seconds = pendingSeconds(forwarded);
|
|
67
59
|
return seconds === null ? null : seconds * 1000;
|
|
68
60
|
}
|
|
69
61
|
function editAnswer(forwarded) {
|
|
70
|
-
const answer =
|
|
62
|
+
const answer = toolAnswer(forwarded);
|
|
71
63
|
if ('refused' in answer)
|
|
72
64
|
return answer;
|
|
73
65
|
const { results } = parse(answer.text);
|
|
@@ -81,10 +73,10 @@ function editAnswer(forwarded) {
|
|
|
81
73
|
export async function openBridge(house, copies, conversationId, signal) {
|
|
82
74
|
const path = [join(kitHome(), 'shim'), dirname(process.execPath), await loginPath()].join(delimiter);
|
|
83
75
|
const origin = (await readEnrolment()).house;
|
|
84
|
-
const { credential } = await retrying(() => house.
|
|
76
|
+
const { credential } = await retrying(() => house.act('conversations/credentials/issue', { conversation: conversationId }, signal), signal);
|
|
85
77
|
const closed = new AbortController();
|
|
86
78
|
const sent = (message, operation) => callHouse(origin, credential, message, operation, closed.signal);
|
|
87
|
-
const send = async (message, operation) => {
|
|
79
|
+
const send = async (message, operation, pushing = false) => {
|
|
88
80
|
if (operation === null)
|
|
89
81
|
return sent(message, null);
|
|
90
82
|
for (let attempt = 0;; attempt++) {
|
|
@@ -93,7 +85,7 @@ export async function openBridge(house, copies, conversationId, signal) {
|
|
|
93
85
|
throw error;
|
|
94
86
|
return null;
|
|
95
87
|
});
|
|
96
|
-
const after = resendAfter(forwarded, attempt);
|
|
88
|
+
const after = resendAfter(forwarded, attempt, pushing);
|
|
97
89
|
if (after === null)
|
|
98
90
|
return forwarded;
|
|
99
91
|
// A Tool call House did not settle is sent again on the jittered curve, or after the wait House names for a pending one.
|
|
@@ -104,8 +96,8 @@ export async function openBridge(house, copies, conversationId, signal) {
|
|
|
104
96
|
const staged = async (operation, changes) => {
|
|
105
97
|
const bytes = Buffer.from(JSON.stringify({ changes }));
|
|
106
98
|
const sha256 = createHash('sha256').update(bytes).digest('hex');
|
|
107
|
-
const prepared =
|
|
108
|
-
command: '
|
|
99
|
+
const prepared = toolAnswer(await send(call('run_command', {
|
|
100
|
+
command: 'files/batch-upload',
|
|
109
101
|
arguments: { paths: changedPaths(changes), bytes: bytes.length, sha256 },
|
|
110
102
|
}), operation));
|
|
111
103
|
if ('refused' in prepared)
|
|
@@ -141,7 +133,7 @@ export async function openBridge(house, copies, conversationId, signal) {
|
|
|
141
133
|
const caller = {
|
|
142
134
|
key: `conversation:${conversationId}`,
|
|
143
135
|
submit: async (operation, changes, held, retain) => {
|
|
144
|
-
const inline = call('
|
|
136
|
+
const inline = call('files_batch', { changes });
|
|
145
137
|
let upload = held;
|
|
146
138
|
if (upload === undefined && Buffer.byteLength(mcpBody(inline, operation)) > MCP_REQUEST_BYTES) {
|
|
147
139
|
const prepared = await staged(operation, changes);
|
|
@@ -150,7 +142,19 @@ export async function openBridge(house, copies, conversationId, signal) {
|
|
|
150
142
|
upload = prepared;
|
|
151
143
|
await retain(upload);
|
|
152
144
|
}
|
|
153
|
-
return editAnswer(await send(upload === undefined ? inline : call('
|
|
145
|
+
return editAnswer(await send(upload === undefined ? inline : call('files_batch', { paths: changedPaths(changes), upload }), operation, true));
|
|
146
|
+
},
|
|
147
|
+
finish: async (upload, room, partSha256) => {
|
|
148
|
+
const answer = toolAnswer(await send(call('upload', { upload, room_ref: room, part_sha256: partSha256 }), operationId(), true));
|
|
149
|
+
if ('refused' in answer)
|
|
150
|
+
throw new Error(answer.refused.text);
|
|
151
|
+
return parse(answer.text);
|
|
152
|
+
},
|
|
153
|
+
info: async (path, revision) => {
|
|
154
|
+
const answer = toolAnswer(await send(call('info', { path, ...(revision === undefined ? {} : { ref: revision }) }), operationId()));
|
|
155
|
+
if ('refused' in answer)
|
|
156
|
+
throw new Error(answer.refused.text);
|
|
157
|
+
return fileInfo(answer.text);
|
|
154
158
|
},
|
|
155
159
|
};
|
|
156
160
|
const local = async (path, text) => {
|
|
@@ -159,7 +163,7 @@ export async function openBridge(house, copies, conversationId, signal) {
|
|
|
159
163
|
return { status: 200, text: JSON.stringify(await copies.push(cwd, commit, caller)) };
|
|
160
164
|
}
|
|
161
165
|
if (path === '/git/fetch')
|
|
162
|
-
return { status: 200, text: JSON.stringify(await copies.fetch()) };
|
|
166
|
+
return { status: 200, text: JSON.stringify(await copies.fetch(caller)) };
|
|
163
167
|
if (path === '/git/observed') {
|
|
164
168
|
await copies.observed(JSON.parse(text));
|
|
165
169
|
return { status: 200, text: '{}' };
|
package/dist/building.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { createWriteStream } from 'node:fs';
|
|
3
|
+
import { rm } from 'node:fs/promises';
|
|
4
|
+
import { Transform } from 'node:stream';
|
|
5
|
+
import { pipeline } from 'node:stream/promises';
|
|
6
|
+
import { readEnrolment } from './home.js';
|
|
7
|
+
import { relayed } from './relay.js';
|
|
8
|
+
const MANIFEST = 'bootstrap.json';
|
|
9
|
+
async function served(name, signal) {
|
|
10
|
+
const enrolment = await readEnrolment();
|
|
11
|
+
if (enrolment === null)
|
|
12
|
+
throw new Error('this Kit is connected to no House');
|
|
13
|
+
const answer = await fetch(relayed(new URL(`/kit-installer/${encodeURIComponent(name)}`, enrolment.house)), { signal });
|
|
14
|
+
if (answer.status === 200 && answer.body !== null)
|
|
15
|
+
return answer;
|
|
16
|
+
await answer.body?.cancel();
|
|
17
|
+
throw new Error(`House answered ${answer.status} for ${name}`);
|
|
18
|
+
}
|
|
19
|
+
export async function servedRelease(signal) {
|
|
20
|
+
const manifest = (await (await served(MANIFEST, signal)).json());
|
|
21
|
+
const installer = manifest.hosts?.linux;
|
|
22
|
+
const sha256 = typeof installer === 'string' ? manifest.files?.[installer]?.sha256 : undefined;
|
|
23
|
+
if (typeof manifest.version !== 'string' || typeof installer !== 'string' || typeof sha256 !== 'string') {
|
|
24
|
+
throw new Error(`House serves no Kit release in ${MANIFEST}`);
|
|
25
|
+
}
|
|
26
|
+
return { version: manifest.version, installer, sha256 };
|
|
27
|
+
}
|
|
28
|
+
export async function downloadServed(name, sha256, destination, signal, most = Infinity) {
|
|
29
|
+
const answer = await served(name, signal);
|
|
30
|
+
const digest = createHash('sha256');
|
|
31
|
+
let bytes = 0;
|
|
32
|
+
const hashed = new Transform({
|
|
33
|
+
transform(chunk, _encoding, done) {
|
|
34
|
+
bytes += chunk.length;
|
|
35
|
+
if (bytes > most)
|
|
36
|
+
return done(new Error(`${name} is larger than its pinned ${most} bytes`));
|
|
37
|
+
digest.update(chunk);
|
|
38
|
+
done(null, chunk);
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
try {
|
|
42
|
+
await pipeline(answer.body, hashed, createWriteStream(destination), { signal });
|
|
43
|
+
if (digest.digest('hex') !== sha256)
|
|
44
|
+
throw new Error(`${name} does not match its sha256`);
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
await rm(destination, { force: true });
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
50
|
+
}
|
package/dist/calls.js
CHANGED
|
@@ -11,6 +11,9 @@ export class Calls {
|
|
|
11
11
|
path = join(kitHome(), 'call-results.json');
|
|
12
12
|
results;
|
|
13
13
|
returned = new Set();
|
|
14
|
+
released = new Set();
|
|
15
|
+
carrying = new Map();
|
|
16
|
+
settings = new Set();
|
|
14
17
|
open = 0;
|
|
15
18
|
constructor(house, changed) {
|
|
16
19
|
this.house = house;
|
|
@@ -26,7 +29,16 @@ export class Calls {
|
|
|
26
29
|
idle() {
|
|
27
30
|
return this.open === 0;
|
|
28
31
|
}
|
|
32
|
+
busy() {
|
|
33
|
+
return [...this.carrying.keys()].some((callId) => !this.settings.has(callId));
|
|
34
|
+
}
|
|
35
|
+
carrySettings(callId, work) {
|
|
36
|
+
this.settings.add(callId);
|
|
37
|
+
return this.carry(callId, work);
|
|
38
|
+
}
|
|
29
39
|
carry(callId, work) {
|
|
40
|
+
if (this.released.has(callId))
|
|
41
|
+
return Promise.resolve();
|
|
30
42
|
const known = this.carried.get(callId);
|
|
31
43
|
const result = this.results.get(callId);
|
|
32
44
|
const carried = known ?? (result === undefined ? work() : Promise.resolve({ result }));
|
|
@@ -35,23 +47,36 @@ export class Calls {
|
|
|
35
47
|
carried.catch(() => this.carried.delete(callId));
|
|
36
48
|
}
|
|
37
49
|
this.open++;
|
|
50
|
+
this.carrying.set(callId, (this.carrying.get(callId) ?? 0) + 1);
|
|
38
51
|
this.changed();
|
|
39
52
|
return carried
|
|
40
|
-
.then(async ({ result, returned }) => {
|
|
53
|
+
.then(async ({ result, returned, release }) => {
|
|
41
54
|
try {
|
|
42
|
-
await this.house.deliver(
|
|
55
|
+
await this.house.deliver('kit-calls/results/return', { call: callId, ...result });
|
|
43
56
|
}
|
|
44
57
|
finally {
|
|
45
58
|
this.returned.add(callId);
|
|
46
59
|
if (this.results.delete(callId))
|
|
47
60
|
this.save();
|
|
48
61
|
}
|
|
49
|
-
if (known
|
|
50
|
-
|
|
62
|
+
if (known !== undefined)
|
|
63
|
+
return;
|
|
64
|
+
if (release) {
|
|
65
|
+
this.carried.delete(callId);
|
|
66
|
+
this.released.add(callId);
|
|
67
|
+
}
|
|
68
|
+
await returned?.();
|
|
51
69
|
})
|
|
52
70
|
.catch(logged)
|
|
53
71
|
.finally(() => {
|
|
54
72
|
this.open--;
|
|
73
|
+
const left = this.carrying.get(callId) - 1;
|
|
74
|
+
if (left === 0) {
|
|
75
|
+
this.carrying.delete(callId);
|
|
76
|
+
this.settings.delete(callId);
|
|
77
|
+
}
|
|
78
|
+
else
|
|
79
|
+
this.carrying.set(callId, left);
|
|
55
80
|
this.changed();
|
|
56
81
|
});
|
|
57
82
|
}
|
package/dist/chunks.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { readFile, rm } from 'node:fs/promises';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { downloaded, fetched } from './files.js';
|
|
4
|
+
const DOWNLOADS_AT_ONCE = 6;
|
|
5
|
+
// A chunk is about one megabyte, so a download still unfinished after two minutes holds every Room behind it on a dead connection.
|
|
6
|
+
const CHUNK_DOWNLOAD_MS = 120_000;
|
|
7
|
+
class AddressExpired extends Error {
|
|
8
|
+
constructor() {
|
|
9
|
+
super("House's store refused every chunk it asked for");
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function once(chunk) {
|
|
13
|
+
let asked = false;
|
|
14
|
+
return async () => {
|
|
15
|
+
if (asked)
|
|
16
|
+
throw new AddressExpired();
|
|
17
|
+
asked = true;
|
|
18
|
+
return { download: chunk.download, sha256: chunk.hash };
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export async function stagedChunks(directory, chunks) {
|
|
22
|
+
let next = 0;
|
|
23
|
+
let failure;
|
|
24
|
+
const downloading = async () => {
|
|
25
|
+
while (next < chunks.length && failure === undefined) {
|
|
26
|
+
const chunk = chunks[next++];
|
|
27
|
+
const reading = (url) => fetched(url, AbortSignal.timeout(CHUNK_DOWNLOAD_MS));
|
|
28
|
+
await downloaded(once(chunk), reading, join(directory, chunk.hash), 'A Room chunk').catch((error) => {
|
|
29
|
+
failure ??= error;
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
await Promise.all(Array.from({ length: DOWNLOADS_AT_ONCE }, downloading));
|
|
34
|
+
return failure;
|
|
35
|
+
}
|
|
36
|
+
export async function* chunkEntries(directory, chunks, models) {
|
|
37
|
+
yield* models;
|
|
38
|
+
for (const { hash } of chunks) {
|
|
39
|
+
const file = join(directory, hash);
|
|
40
|
+
for (const line of (await readFile(file, 'utf8')).split('\n')) {
|
|
41
|
+
if (line === '')
|
|
42
|
+
continue;
|
|
43
|
+
const entry = JSON.parse(line);
|
|
44
|
+
if (!('folder' in entry))
|
|
45
|
+
yield entry;
|
|
46
|
+
}
|
|
47
|
+
await rm(file);
|
|
48
|
+
}
|
|
49
|
+
}
|
package/dist/clis.js
CHANGED
|
@@ -2,9 +2,11 @@ import { spawn } from 'node:child_process';
|
|
|
2
2
|
import { randomUUID } from 'node:crypto';
|
|
3
3
|
import { constants, readFileSync } from 'node:fs';
|
|
4
4
|
import { access, mkdir, readFile, rename, writeFile } from 'node:fs/promises';
|
|
5
|
-
import {
|
|
5
|
+
import { userInfo } from 'node:os';
|
|
6
6
|
import { delimiter, dirname, isAbsolute, join } from 'node:path';
|
|
7
|
-
import {
|
|
7
|
+
import { CLAUDE_KEY, CODEX_KEY, GROK_KEY, codexHome } from './keys.js';
|
|
8
|
+
import { releaseDirectory } from './placement.js';
|
|
9
|
+
import { childEnvironment } from './relay.js';
|
|
8
10
|
const HOUSE_EXECUTABLES = /^host_executable\(name = "house", paths = (\[.*\])\)$/m;
|
|
9
11
|
function houseRule(houses) {
|
|
10
12
|
return `prefix_rule(pattern = ["house"], decision = "allow")\nhost_executable(name = "house", paths = ${JSON.stringify(houses)})\n`;
|
|
@@ -14,10 +16,12 @@ const RAW_SUBTYPES = [
|
|
|
14
16
|
'task_started',
|
|
15
17
|
'task_updated',
|
|
16
18
|
'task_notification',
|
|
19
|
+
'task_progress',
|
|
17
20
|
'session_state_changed',
|
|
18
21
|
'hook_started',
|
|
19
22
|
'hook_response',
|
|
20
23
|
];
|
|
24
|
+
const RAW_TYPES = ['result', 'user', 'assistant', 'rate_limit_event', 'prompt_suggestion'];
|
|
21
25
|
async function executable(path) {
|
|
22
26
|
try {
|
|
23
27
|
await access(path, constants.X_OK);
|
|
@@ -47,7 +51,7 @@ async function listedHouses(file) {
|
|
|
47
51
|
}
|
|
48
52
|
export async function allowHouseInCodex(path) {
|
|
49
53
|
const candidates = [...new Set(path.split(delimiter).filter((directory) => isAbsolute(directory)))].map((directory) => join(directory, 'house'));
|
|
50
|
-
const rules = join(
|
|
54
|
+
const rules = join(codexHome(), 'rules');
|
|
51
55
|
const file = join(rules, 'house.rules');
|
|
52
56
|
const houses = [];
|
|
53
57
|
for (const house of [...(await listedHouses(file)), ...candidates]) {
|
|
@@ -60,6 +64,14 @@ export async function allowHouseInCodex(path) {
|
|
|
60
64
|
await rename(temporary, file);
|
|
61
65
|
}
|
|
62
66
|
async function nothing() { }
|
|
67
|
+
function claudeQuestionFields(request) {
|
|
68
|
+
const properties = request.requestedSchema?.properties ?? {};
|
|
69
|
+
return Object.keys(properties).filter((name) => properties[name]._meta?.jetbrains?.air?.customAnswer !== undefined);
|
|
70
|
+
}
|
|
71
|
+
function codexQuestionFields(request) {
|
|
72
|
+
const { _meta, requestedSchema } = request;
|
|
73
|
+
return _meta?.codex === undefined ? [] : (requestedSchema?.required ?? []);
|
|
74
|
+
}
|
|
63
75
|
function answered(error) {
|
|
64
76
|
return typeof error === 'object' && error !== null ? error : {};
|
|
65
77
|
}
|
|
@@ -68,9 +80,11 @@ function bridgeInClaudeSandbox(bridge) {
|
|
|
68
80
|
}
|
|
69
81
|
export const CLIS = {
|
|
70
82
|
'codex-acp': {
|
|
83
|
+
name: 'Codex',
|
|
71
84
|
bin: 'codex',
|
|
72
|
-
minimum: '0.
|
|
85
|
+
minimum: '0.165.0',
|
|
73
86
|
install: 'curl -fsSL https://chatgpt.com/codex/install.sh | sh',
|
|
87
|
+
update: 'codex update',
|
|
74
88
|
adapter: {
|
|
75
89
|
package: '@agentclientprotocol/codex-acp',
|
|
76
90
|
bin: 'codex-acp',
|
|
@@ -84,16 +98,19 @@ export const CLIS = {
|
|
|
84
98
|
const { code, data } = answered(error);
|
|
85
99
|
return code === -32603 && typeof data?.details === 'string' && data.details.startsWith('no rollout found');
|
|
86
100
|
},
|
|
87
|
-
renames: true,
|
|
88
101
|
allowHouse: allowHouseInCodex,
|
|
102
|
+
questionFields: codexQuestionFields,
|
|
89
103
|
signedIn: { command: ['login', 'status'] },
|
|
90
104
|
login: { args: ['login', '--device-auth'], code: 'show' },
|
|
105
|
+
key: CODEX_KEY,
|
|
91
106
|
air: ['asyncTasks', 'nativeSubagentSessions'],
|
|
92
107
|
},
|
|
93
108
|
'claude-agent-acp': {
|
|
109
|
+
name: 'Claude Code',
|
|
94
110
|
bin: 'claude',
|
|
95
|
-
minimum: '2.1.
|
|
111
|
+
minimum: '2.1.316',
|
|
96
112
|
install: 'curl -fsSL https://claude.ai/install.sh | bash',
|
|
113
|
+
update: 'claude update',
|
|
97
114
|
adapter: {
|
|
98
115
|
package: '@agentclientprotocol/claude-agent-acp',
|
|
99
116
|
bin: 'claude-agent-acp',
|
|
@@ -102,73 +119,63 @@ export const CLIS = {
|
|
|
102
119
|
},
|
|
103
120
|
args: [],
|
|
104
121
|
fullAccess: 'bypassPermissions',
|
|
105
|
-
sessionMeta: (bridge
|
|
122
|
+
sessionMeta: (bridge) => ({
|
|
106
123
|
claudeCode: {
|
|
107
124
|
options: {
|
|
108
125
|
allowedTools: ['Bash(house:*)'],
|
|
109
126
|
includeHookEvents: true,
|
|
110
|
-
title,
|
|
111
127
|
settings: { sandbox: { network: bridgeInClaudeSandbox(bridge) } },
|
|
112
128
|
},
|
|
113
|
-
emitRawSDKMessages: RAW_SUBTYPES.map((subtype) => ({ type: 'system', subtype })),
|
|
129
|
+
emitRawSDKMessages: [...RAW_SUBTYPES.map((subtype) => ({ type: 'system', subtype })), ...RAW_TYPES.map((type) => ({ type }))],
|
|
114
130
|
},
|
|
115
131
|
}),
|
|
116
132
|
unknownSession: (error) => answered(error).code === -32002,
|
|
117
|
-
renames: false,
|
|
118
133
|
allowHouse: nothing,
|
|
134
|
+
questionFields: claudeQuestionFields,
|
|
119
135
|
signedIn: { command: ['auth', 'status'] },
|
|
120
136
|
login: { args: ['auth', 'login', '--claudeai'], code: 'collect', rejected: 'Invalid code' },
|
|
137
|
+
key: CLAUDE_KEY,
|
|
121
138
|
air: ['asyncTasks', 'sessionFailure'],
|
|
122
139
|
},
|
|
123
140
|
'grok-build': {
|
|
141
|
+
name: 'Grok Build',
|
|
124
142
|
bin: 'grok',
|
|
125
143
|
minimum: '1.0.46',
|
|
126
144
|
install: 'curl -fsSL https://x.ai/cli/install.sh | bash',
|
|
145
|
+
update: 'grok update',
|
|
127
146
|
adapter: null,
|
|
128
147
|
args: ['--sandbox', 'off', 'agent', '--always-approve', '--no-leader', 'stdio'],
|
|
129
148
|
fullAccess: null,
|
|
130
149
|
sessionMeta: () => ({}),
|
|
131
150
|
unknownSession: (error) => answered(error).data?.code === 'FS_NOT_FOUND',
|
|
132
|
-
renames: false,
|
|
133
151
|
allowHouse: nothing,
|
|
134
|
-
|
|
152
|
+
questionFields: () => [],
|
|
153
|
+
signedIn: { initializeMeta: 'defaultAuthMethodId', apiKey: 'xai.api_key' },
|
|
135
154
|
login: { args: ['login', '--device-auth'], code: 'show' },
|
|
155
|
+
key: GROK_KEY,
|
|
136
156
|
air: ['asyncTasks'],
|
|
137
157
|
},
|
|
138
158
|
};
|
|
139
159
|
const KIT_PACKAGE = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
|
|
140
160
|
export const KIT_RELEASE = KIT_PACKAGE.version;
|
|
141
|
-
const PROXY = /^https?_proxy$/i;
|
|
142
161
|
const VERSION = /\d+\.\d+\.\d+(?:-[0-9A-Za-z.]+)?/;
|
|
143
|
-
// An install still running after fifteen minutes is ended
|
|
162
|
+
// An install or update still running after fifteen minutes is ended as failed, so a hung download can neither hold its CLI's report nor keep the Kit busy.
|
|
144
163
|
const INSTALL_MS = 15 * 60_000;
|
|
145
164
|
// A login shell or a version read is ended after half a minute, so a profile that waits for input cannot stall the report.
|
|
146
165
|
const READ_MS = 30_000;
|
|
147
166
|
const CAUSE_CHARACTERS = 4000;
|
|
148
|
-
function prefix(kind) {
|
|
149
|
-
return join(kitHome(), 'agents', kind);
|
|
150
|
-
}
|
|
151
167
|
export function adapterCommand(kind) {
|
|
152
|
-
return join(
|
|
168
|
+
return join(releaseDirectory(KIT_RELEASE), 'adapters', kind, 'node_modules', '.bin', CLIS[kind].adapter.bin);
|
|
153
169
|
}
|
|
154
|
-
async function
|
|
155
|
-
|
|
156
|
-
const manifest = join(prefix(kind), 'node_modules', CLIS[kind].adapter.package, 'package.json');
|
|
157
|
-
return JSON.parse(await readFile(manifest, 'utf8')).version;
|
|
158
|
-
}
|
|
159
|
-
catch {
|
|
160
|
-
return null;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
export function withoutProxy() {
|
|
164
|
-
return Object.fromEntries(Object.entries(process.env).filter(([name]) => !PROXY.test(name)));
|
|
170
|
+
export async function cliEnvironment(kind) {
|
|
171
|
+
return { ...childEnvironment(), ...(await CLIS[kind].key.environment?.()) };
|
|
165
172
|
}
|
|
166
|
-
export function run(command, args, timeoutMs, detached = false, signal) {
|
|
173
|
+
export function run(command, args, timeoutMs, detached = false, signal, env = childEnvironment()) {
|
|
167
174
|
return new Promise((resolve) => {
|
|
168
175
|
const child = spawn(command, args, {
|
|
169
176
|
stdio: ['ignore', 'pipe', 'pipe'],
|
|
170
177
|
timeout: timeoutMs,
|
|
171
|
-
env
|
|
178
|
+
env,
|
|
172
179
|
detached,
|
|
173
180
|
signal: detached ? undefined : signal,
|
|
174
181
|
});
|
|
@@ -202,19 +209,18 @@ export function run(command, args, timeoutMs, detached = false, signal) {
|
|
|
202
209
|
export function failureOf(ran, program) {
|
|
203
210
|
return ran.output.trim().slice(-CAUSE_CHARACTERS) || `${program} exited with ${ran.status ?? 'a signal'}`;
|
|
204
211
|
}
|
|
205
|
-
export
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
const
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
return ran.status === 0 ? null : failureOf(ran,
|
|
212
|
+
export function adapterArchive(kind) {
|
|
213
|
+
return `${kind}-${KIT_PACKAGE.peerDependencies[CLIS[kind].adapter.package]}.tar.gz`;
|
|
214
|
+
}
|
|
215
|
+
async function bounded(program, work, signal) {
|
|
216
|
+
const deadline = AbortSignal.timeout(INSTALL_MS);
|
|
217
|
+
const ran = await work(signal === undefined ? deadline : AbortSignal.any([signal, deadline]));
|
|
218
|
+
if (deadline.aborted && signal?.aborted !== true)
|
|
219
|
+
return `${program} did not end within ${INSTALL_MS / 1000} seconds`;
|
|
220
|
+
return ran.status === 0 ? null : failureOf(ran, program);
|
|
214
221
|
}
|
|
215
|
-
export
|
|
216
|
-
|
|
217
|
-
return ran.status === 0 ? null : failureOf(ran, 'the install');
|
|
222
|
+
export function installCli(kind, signal) {
|
|
223
|
+
return bounded('the install', (within) => run('bash', ['-o', 'pipefail', '-c', CLIS[kind].install], INSTALL_MS, true, within), signal);
|
|
218
224
|
}
|
|
219
225
|
function loginShell() {
|
|
220
226
|
return process.env.SHELL || userInfo().shell;
|
|
@@ -222,13 +228,19 @@ function loginShell() {
|
|
|
222
228
|
const FOUND = 'house-kit-cli ';
|
|
223
229
|
const LOOKUP = `found=$(command -v "$1") || exit 0; case $found in /*) ;; *) found=$(pwd -P)/$found ;; esac; printf "${FOUND}%s\\n" "$found"`;
|
|
224
230
|
const USER_BIN = 'case ":$PATH:" in *":$HOME/.local/bin:"*) ;; *) PATH="$PATH:$HOME/.local/bin" ;; esac; export PATH';
|
|
225
|
-
function inLoginShell(script, argument = '', signal) {
|
|
226
|
-
return run(loginShell(), ['-l', '-i', '-c', `exec /bin/sh -c '${USER_BIN}; ${script}' sh ${argument}`],
|
|
231
|
+
function inLoginShell(script, argument = '', signal, timeoutMs = READ_MS) {
|
|
232
|
+
return run(loginShell(), ['-l', '-i', '-c', `exec /bin/sh -c '${USER_BIN}; ${script}' sh ${argument}`], timeoutMs, true, signal);
|
|
227
233
|
}
|
|
228
|
-
export async function
|
|
229
|
-
const ran = await inLoginShell(LOOKUP,
|
|
234
|
+
export async function onLoginPath(program, signal) {
|
|
235
|
+
const ran = await inLoginShell(LOOKUP, program, signal);
|
|
230
236
|
return ran.stdout.split('\n').findLast((line) => line.startsWith(FOUND))?.slice(FOUND.length) ?? null;
|
|
231
237
|
}
|
|
238
|
+
export function locate(kind, signal) {
|
|
239
|
+
return onLoginPath(CLIS[kind].bin, signal);
|
|
240
|
+
}
|
|
241
|
+
export function updateCli(kind) {
|
|
242
|
+
return bounded('the update', (within) => inLoginShell(CLIS[kind].update, '', within, INSTALL_MS));
|
|
243
|
+
}
|
|
232
244
|
export async function loginPath() {
|
|
233
245
|
const marker = 'house-kit-path ';
|
|
234
246
|
const ran = await inLoginShell(`printf "${marker}%s\\n" "$PATH"`);
|
|
@@ -240,8 +252,8 @@ export async function writeCodexRule() {
|
|
|
240
252
|
throw new Error(`Codex's rule for house could not be written: ${error.message}`);
|
|
241
253
|
});
|
|
242
254
|
}
|
|
243
|
-
export async function versionOf(path, signal) {
|
|
244
|
-
return VERSION.exec((await run(path, ['--version'], READ_MS, false, signal)).stdout)?.[0] ?? null;
|
|
255
|
+
export async function versionOf(kind, path, signal) {
|
|
256
|
+
return VERSION.exec((await run(path, ['--version'], READ_MS, false, signal, await cliEnvironment(kind))).stdout)?.[0] ?? null;
|
|
245
257
|
}
|
|
246
258
|
function numbers(version) {
|
|
247
259
|
return version.split(/[.-]/, 3).map(Number);
|