@agentshouse/kit 0.2.1-cf110d15f69c8 → 0.2.1-cf2c570b41f24
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 +38 -44
- package/dist/acp.js +96 -22
- package/dist/afk.js +17 -0
- package/dist/agents.js +221 -65
- package/dist/api.js +21 -3
- package/dist/app-git.js +10 -26
- package/dist/binaries.js +60 -0
- package/dist/bridge.js +101 -49
- package/dist/building.js +50 -0
- package/dist/calls.js +88 -0
- package/dist/chunks.js +54 -0
- package/dist/clis.js +80 -52
- package/dist/connect.js +121 -0
- package/dist/connection.js +120 -0
- package/dist/content.js +106 -0
- package/dist/conversations.js +711 -267
- package/dist/copies.js +1293 -595
- package/dist/earlier.js +273 -0
- package/dist/end.js +15 -3
- package/dist/events.js +553 -281
- package/dist/files.js +206 -32
- package/dist/git.js +2 -70
- package/dist/grok.js +39 -0
- package/dist/home.js +123 -15
- package/dist/house-cli.js +282 -0
- package/dist/house-main.js +7 -206
- package/dist/instructions.js +7 -13
- package/dist/keys.js +238 -0
- package/dist/kit-cli.js +78 -0
- package/dist/kit-main.js +8 -22
- package/dist/login.js +71 -39
- package/dist/logout.js +2 -4
- package/dist/manifest.js +75 -0
- package/dist/mcp.js +47 -7
- package/dist/owner.js +46 -0
- package/dist/placement.js +25 -0
- package/dist/refusals.js +50 -23
- package/dist/relay.js +22 -1
- package/dist/resident.js +153 -53
- package/dist/scope.js +15 -4
- package/dist/scripts.js +319 -0
- package/dist/secret-input.js +1 -1
- package/dist/settings.js +247 -0
- package/dist/sign-in.js +66 -38
- package/dist/silence.js +28 -0
- package/dist/skills.js +49 -35
- package/dist/supervisor.js +163 -0
- package/dist/transcription.js +90 -47
- package/dist/update.js +119 -102
- package/dist/wire.js +32 -0
- package/dist/work.js +30 -7
- package/dist/workspace.js +113 -0
- package/package.json +25 -21
- package/dist/authority-main.js +0 -22
- 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 -10
- package/dist/git-main.js +0 -153
- package/dist/parts.js +0 -82
- package/dist/service-main.js +0 -9
- package/dist/service.js +0 -33
- package/dist/stream.js +0 -74
- package/dist/translate.js +0 -51
- 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/files.js
CHANGED
|
@@ -1,36 +1,210 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
+
import { createReadStream, createWriteStream } from 'node:fs';
|
|
3
|
+
import { mkdir, rename, rm } from 'node:fs/promises';
|
|
4
|
+
import { request } from 'node:http';
|
|
5
|
+
import { request as httpsRequest } from 'node:https';
|
|
6
|
+
import { basename, dirname, extname, join } from 'node:path';
|
|
7
|
+
import { Readable, Transform } from 'node:stream';
|
|
8
|
+
import { pipeline } from 'node:stream/promises';
|
|
9
|
+
import { parseDocument } from 'yaml';
|
|
10
|
+
import { retryDelay } from './api.js';
|
|
11
|
+
import { Unsettled } from './mcp.js';
|
|
12
|
+
import { proxyUnlessRelayed, relayed } from './relay.js';
|
|
13
|
+
const STALLED_ROUNDS = 8;
|
|
14
|
+
const PART_CHECKSUM = 'x-amz-checksum-sha256';
|
|
15
|
+
const LINK = /\]\((\/rooms\/[^/)\s]+\/[^)\s]+)\)/gu;
|
|
16
|
+
const MEDIA_TYPES = new Map([
|
|
17
|
+
['avif', 'image/avif'],
|
|
18
|
+
['csv', 'text/csv'],
|
|
19
|
+
['docx', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'],
|
|
20
|
+
['gif', 'image/gif'],
|
|
21
|
+
['heic', 'image/heic'],
|
|
22
|
+
['html', 'text/html'],
|
|
23
|
+
['jpeg', 'image/jpeg'],
|
|
24
|
+
['jpg', 'image/jpeg'],
|
|
25
|
+
['json', 'application/json'],
|
|
26
|
+
['m4a', 'audio/mp4'],
|
|
27
|
+
['md', 'text/markdown'],
|
|
28
|
+
['mov', 'video/quicktime'],
|
|
29
|
+
['mp3', 'audio/mpeg'],
|
|
30
|
+
['mp4', 'video/mp4'],
|
|
31
|
+
['ogg', 'audio/ogg'],
|
|
32
|
+
['pdf', 'application/pdf'],
|
|
33
|
+
['png', 'image/png'],
|
|
34
|
+
['pptx', 'application/vnd.openxmlformats-officedocument.presentationml.presentation'],
|
|
35
|
+
['svg', 'image/svg+xml'],
|
|
36
|
+
['txt', 'text/plain'],
|
|
37
|
+
['wav', 'audio/wav'],
|
|
38
|
+
['webm', 'video/webm'],
|
|
39
|
+
['webp', 'image/webp'],
|
|
40
|
+
['xlsx', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'],
|
|
41
|
+
['zip', 'application/zip'],
|
|
42
|
+
]);
|
|
43
|
+
export function mediaTypeOf(path) {
|
|
44
|
+
return MEDIA_TYPES.get(extname(path).slice(1).toLowerCase());
|
|
45
|
+
}
|
|
46
|
+
export function linkedPaths(text) {
|
|
47
|
+
return [...new Set(Array.from(text.matchAll(LINK), (link) => link[1]))];
|
|
48
|
+
}
|
|
49
|
+
export function fileInfo(answer) {
|
|
50
|
+
const document = parseDocument(answer);
|
|
51
|
+
if (document.errors.length > 0)
|
|
52
|
+
return null;
|
|
53
|
+
const details = document.toJS();
|
|
54
|
+
if (typeof details?.download !== 'string')
|
|
55
|
+
return null;
|
|
56
|
+
return {
|
|
57
|
+
download: details.download,
|
|
58
|
+
sha256: String(details.sha256),
|
|
59
|
+
revision: String(details.revision),
|
|
60
|
+
bytes: Number(details.bytes),
|
|
61
|
+
media_type: typeof details.media_type === 'string' ? details.media_type : null,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
export function paused(milliseconds) {
|
|
65
|
+
return new Promise((resolve) => setTimeout(resolve, milliseconds));
|
|
66
|
+
}
|
|
67
|
+
export function storeRefusal(act, status) {
|
|
68
|
+
return new Error(`the ${act} answered ${status}; ${act} the file again`);
|
|
69
|
+
}
|
|
70
|
+
export function opened(url, method, headers, way, body) {
|
|
71
|
+
return new Promise((answered, failed) => {
|
|
72
|
+
const target = way.socketPath === undefined ? relayed(url) : null;
|
|
73
|
+
if (target !== null)
|
|
74
|
+
proxyUnlessRelayed();
|
|
75
|
+
const sent = target === null
|
|
76
|
+
? request({ socketPath: way.socketPath, path: url, method, headers }, answered)
|
|
77
|
+
: (target.protocol === 'https:' ? httpsRequest : request)(target, { method, headers }, answered);
|
|
78
|
+
sent.on('error', (error) => failed(way.unreached(error)));
|
|
79
|
+
if (body === undefined)
|
|
80
|
+
sent.end();
|
|
81
|
+
else
|
|
82
|
+
pipeline(body, sent).catch(() => undefined);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
function ranged(file, start, end) {
|
|
86
|
+
return end === start ? undefined : createReadStream(file, { start, end: end - 1 });
|
|
87
|
+
}
|
|
88
|
+
export async function* fileRange(file, start, end, unreadable) {
|
|
89
|
+
try {
|
|
90
|
+
yield* ranged(file, start, end) ?? [];
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
throw unreadable(error);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
export async function sentPart(url, file, start, end, headers, way) {
|
|
97
|
+
const answer = await opened(url, 'PUT', { ...headers, 'content-length': String(end - start) }, way, ranged(file, start, end));
|
|
98
|
+
await answer.toArray();
|
|
99
|
+
if (answer.statusCode !== 200)
|
|
100
|
+
throw way.refused(answer.statusCode);
|
|
101
|
+
}
|
|
102
|
+
async function partDigests(uploading, partBytes) {
|
|
103
|
+
const whole = createHash('sha256');
|
|
104
|
+
const digests = [];
|
|
105
|
+
for (let start = 0; digests.length === 0 || start < uploading.bytes; start += partBytes) {
|
|
106
|
+
const end = Math.min(start + partBytes, uploading.bytes);
|
|
107
|
+
const digest = createHash('sha256');
|
|
108
|
+
for await (const chunk of uploading.read(start, end)) {
|
|
109
|
+
digest.update(chunk);
|
|
110
|
+
whole.update(chunk);
|
|
111
|
+
}
|
|
112
|
+
digests.push(digest.digest());
|
|
113
|
+
}
|
|
114
|
+
if (whole.digest('hex') !== uploading.sha256)
|
|
115
|
+
throw new Error(`${uploading.name} changed while it was uploaded; upload it again`);
|
|
116
|
+
return digests;
|
|
117
|
+
}
|
|
118
|
+
export async function uploaded(declared, uploading) {
|
|
119
|
+
const partBytes = declared.part_bytes;
|
|
120
|
+
const digests = await partDigests(uploading, partBytes);
|
|
121
|
+
const partSha256 = digests.map((digest) => digest.toString('hex'));
|
|
122
|
+
let answer = await finishing(uploading, declared.id, partSha256);
|
|
123
|
+
let idle = 0;
|
|
124
|
+
let stalled = 0;
|
|
125
|
+
while ('upload' in answer) {
|
|
126
|
+
const { id, parts } = answer.upload;
|
|
127
|
+
let sent = 0;
|
|
128
|
+
let failure = null;
|
|
129
|
+
for (const { part, url } of parts ?? []) {
|
|
130
|
+
const start = (part - 1) * partBytes;
|
|
131
|
+
try {
|
|
132
|
+
await uploading.send(url, start, Math.min(start + partBytes, uploading.bytes), {
|
|
133
|
+
[PART_CHECKSUM]: digests[part - 1].toString('base64'),
|
|
134
|
+
});
|
|
135
|
+
sent++;
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
failure = error;
|
|
139
|
+
break;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
if (sent > 0) {
|
|
143
|
+
idle = 0;
|
|
144
|
+
stalled = 0;
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
if (failure !== null && ++stalled >= STALLED_ROUNDS)
|
|
148
|
+
throw failure;
|
|
149
|
+
// A round that sent no part, its store unreachable, is followed by the next finishing call on the jittered curve.
|
|
150
|
+
await paused(retryDelay(idle++));
|
|
151
|
+
}
|
|
152
|
+
answer = await finishing(uploading, id, partSha256);
|
|
153
|
+
}
|
|
154
|
+
return answer;
|
|
155
|
+
}
|
|
156
|
+
async function finishing(uploading, upload, partSha256) {
|
|
157
|
+
for (let unsettled = 1;; unsettled++) {
|
|
158
|
+
try {
|
|
159
|
+
return await uploading.finish(upload, partSha256);
|
|
160
|
+
}
|
|
161
|
+
catch (error) {
|
|
162
|
+
if (!(error instanceof Unsettled) || unsettled === STALLED_ROUNDS)
|
|
15
163
|
throw error;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
await writeFile(path, Buffer.from(await answer.arrayBuffer()));
|
|
20
|
-
paths.push(path);
|
|
164
|
+
}
|
|
165
|
+
// A finishing call House did not settle, unreached or refused short of final, is sent again on the jittered curve as a conversation resends it, so a dropped connection or a House restart resumes the upload instead of ending it.
|
|
166
|
+
await paused(retryDelay(unsettled - 1));
|
|
21
167
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
168
|
+
}
|
|
169
|
+
async function drained(body) {
|
|
170
|
+
for await (const _chunk of body)
|
|
171
|
+
;
|
|
172
|
+
}
|
|
173
|
+
export async function downloaded(address, fetching, destination, name) {
|
|
174
|
+
for (let asked = 1;; asked++) {
|
|
175
|
+
const { download, sha256 } = await address();
|
|
176
|
+
const answer = await fetching(download);
|
|
177
|
+
if (answer.status === 403 && asked === 1) {
|
|
178
|
+
await drained(answer.body);
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
if (answer.status !== 200) {
|
|
182
|
+
await drained(answer.body);
|
|
183
|
+
throw storeRefusal('download', answer.status);
|
|
184
|
+
}
|
|
185
|
+
await mkdir(dirname(destination), { recursive: true });
|
|
186
|
+
const partial = join(dirname(destination), `.${basename(destination)}.${randomUUID()}`);
|
|
187
|
+
const digest = createHash('sha256');
|
|
188
|
+
const hashed = new Transform({
|
|
189
|
+
transform(chunk, _encoding, done) {
|
|
190
|
+
digest.update(chunk);
|
|
191
|
+
done(null, chunk);
|
|
192
|
+
},
|
|
30
193
|
});
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
194
|
+
try {
|
|
195
|
+
await pipeline(answer.body, hashed, createWriteStream(partial, { flags: 'wx' }));
|
|
196
|
+
if (digest.digest('hex') !== sha256)
|
|
197
|
+
throw new Error(`${name} did not arrive whole; download it again`);
|
|
198
|
+
await rename(partial, destination);
|
|
199
|
+
}
|
|
200
|
+
catch (error) {
|
|
201
|
+
await rm(partial, { force: true });
|
|
202
|
+
throw error;
|
|
203
|
+
}
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
export async function fetched(url, signal) {
|
|
208
|
+
const answer = await fetch(relayed(url), { signal });
|
|
209
|
+
return { status: answer.status, body: answer.body === null ? Readable.from([]) : Readable.fromWeb(answer.body) };
|
|
36
210
|
}
|
package/dist/git.js
CHANGED
|
@@ -1,16 +1,8 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
|
-
import {
|
|
3
|
-
import { join } from 'node:path';
|
|
4
|
-
import { withoutProxy } from './clis.js';
|
|
5
|
-
import { workspaceRoot } from './home.js';
|
|
6
|
-
export function localCopies() {
|
|
7
|
-
return join(workspaceRoot(), 'local-copies');
|
|
8
|
-
}
|
|
9
|
-
export const HOUSE_REF = 'refs/house/received';
|
|
10
|
-
const COMMITTER = 'House Kit <house-kit@localhost>';
|
|
2
|
+
import { childEnvironment } from './relay.js';
|
|
11
3
|
export function run(cwd, args, input, env = {}) {
|
|
12
4
|
return new Promise((resolve, reject) => {
|
|
13
|
-
const child = spawn('git', args, { cwd, env: { ...
|
|
5
|
+
const child = spawn('git', args, { cwd, env: { ...childEnvironment(), ...env } });
|
|
14
6
|
const stdout = [];
|
|
15
7
|
let stderr = '';
|
|
16
8
|
child.stdout.on('data', (chunk) => stdout.push(chunk));
|
|
@@ -23,63 +15,3 @@ export function run(cwd, args, input, env = {}) {
|
|
|
23
15
|
child.stdin.end(input);
|
|
24
16
|
});
|
|
25
17
|
}
|
|
26
|
-
export async function git(cwd, args, input, env) {
|
|
27
|
-
const ran = await run(cwd, args, input, env);
|
|
28
|
-
if (ran.status !== 0)
|
|
29
|
-
throw new Error(`git ${args[0]} failed: ${ran.stderr.trim()}`);
|
|
30
|
-
return ran.stdout.toString('utf8');
|
|
31
|
-
}
|
|
32
|
-
export async function succeeded(cwd, args, env) {
|
|
33
|
-
return (await run(cwd, args, undefined, env)).status === 0;
|
|
34
|
-
}
|
|
35
|
-
export async function revision(cwd, name) {
|
|
36
|
-
return (await git(cwd, ['rev-parse', '--verify', `${name}^{commit}`])).trim();
|
|
37
|
-
}
|
|
38
|
-
export async function tree(repository, commit) {
|
|
39
|
-
const listed = await git(repository, ['ls-tree', '-r', '-z', commit]);
|
|
40
|
-
const entries = new Map();
|
|
41
|
-
for (const entry of listed.split('\0')) {
|
|
42
|
-
const tab = entry.indexOf('\t');
|
|
43
|
-
if (tab < 0)
|
|
44
|
-
continue;
|
|
45
|
-
const [, type, object] = entry.slice(0, tab).split(' ');
|
|
46
|
-
if (type === 'blob')
|
|
47
|
-
entries.set(entry.slice(tab + 1), object);
|
|
48
|
-
}
|
|
49
|
-
return entries;
|
|
50
|
-
}
|
|
51
|
-
export async function blobText(repository, object, path) {
|
|
52
|
-
const bytes = (await run(repository, ['cat-file', 'blob', object])).stdout;
|
|
53
|
-
try {
|
|
54
|
-
return new TextDecoder('utf-8', { fatal: true, ignoreBOM: true }).decode(bytes);
|
|
55
|
-
}
|
|
56
|
-
catch {
|
|
57
|
-
throw new Error(`${path} is binary and House stores only text; remove it from the commit`);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
export function blobId(content) {
|
|
61
|
-
const bytes = Buffer.from(content, 'utf8');
|
|
62
|
-
return createHash('sha1').update(`blob ${bytes.length}\0`).update(bytes).digest('hex');
|
|
63
|
-
}
|
|
64
|
-
function quoted(path) {
|
|
65
|
-
return `"${path.replace(/[\\"]/g, '\\$&').replace(/\n/g, '\\n')}"`;
|
|
66
|
-
}
|
|
67
|
-
function data(text) {
|
|
68
|
-
const bytes = Buffer.from(text, 'utf8');
|
|
69
|
-
return [Buffer.from(`data ${bytes.length}\n`), bytes, Buffer.from('\n')];
|
|
70
|
-
}
|
|
71
|
-
export async function importCommits(repository, commits) {
|
|
72
|
-
const stream = [];
|
|
73
|
-
for (const [index, commit] of commits.entries()) {
|
|
74
|
-
stream.push(Buffer.from(`commit ${HOUSE_REF}\nmark :${index + 1}\ncommitter ${COMMITTER} ${Math.floor(Date.now() / 1000)} +0000\n`), ...data(commit.message), ...(commit.from === null ? [] : [Buffer.from(`from ${commit.from}\n`)]), ...(commit.merge === undefined ? [] : [Buffer.from(`merge ${commit.merge}\n`)]), ...(commit.replaces === true ? [Buffer.from('deleteall\n')] : []));
|
|
75
|
-
for (const [path, content] of commit.files) {
|
|
76
|
-
if (content === null)
|
|
77
|
-
stream.push(Buffer.from(`D ${quoted(path)}\n`));
|
|
78
|
-
else
|
|
79
|
-
stream.push(Buffer.from(`M 100644 inline ${quoted(path)}\n`), ...data(content));
|
|
80
|
-
}
|
|
81
|
-
stream.push(Buffer.from('\n'));
|
|
82
|
-
}
|
|
83
|
-
await git(repository, ['fast-import', '--quiet', '--force'], Buffer.concat(stream));
|
|
84
|
-
return revision(repository, HOUSE_REF);
|
|
85
|
-
}
|
package/dist/grok.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
const PLAN = 'plan';
|
|
2
|
+
const PLAN_ABANDONED = 'abandoned';
|
|
3
|
+
const PLAN_FIELD = {
|
|
4
|
+
type: 'string',
|
|
5
|
+
title: 'Approve this plan?',
|
|
6
|
+
oneOf: [
|
|
7
|
+
{ const: 'approved', title: 'Approve' },
|
|
8
|
+
{ const: PLAN_ABANDONED, title: 'Abandon' },
|
|
9
|
+
],
|
|
10
|
+
};
|
|
11
|
+
function form(sessionId, message, properties) {
|
|
12
|
+
return { mode: 'form', sessionId, message, requestedSchema: { type: 'object', properties } };
|
|
13
|
+
}
|
|
14
|
+
function questionField({ options, multiSelect }, title) {
|
|
15
|
+
const choices = options.map(({ label, description }) => ({ const: label, title: label, description }));
|
|
16
|
+
return multiSelect === true ? { type: 'array', title, items: { anyOf: choices } } : { type: 'string', title, oneOf: choices };
|
|
17
|
+
}
|
|
18
|
+
export function grokQuestionForm({ sessionId, questions }) {
|
|
19
|
+
const lone = questions.length === 1;
|
|
20
|
+
return form(sessionId, questions.map(({ question }) => question).join('\n\n'), Object.fromEntries(questions.map((one) => [one.question, questionField(one, lone ? 'Answer' : one.question)])));
|
|
21
|
+
}
|
|
22
|
+
function answerText(value) {
|
|
23
|
+
return Array.isArray(value) ? value.join(', ') : String(value);
|
|
24
|
+
}
|
|
25
|
+
function contentOf(response) {
|
|
26
|
+
return response.action === 'accept' ? (response.content ?? {}) : {};
|
|
27
|
+
}
|
|
28
|
+
export function grokQuestionAnswer(response) {
|
|
29
|
+
if (response.action !== 'accept')
|
|
30
|
+
return { outcome: 'cancelled' };
|
|
31
|
+
const answers = Object.entries(contentOf(response)).map(([question, value]) => [question, answerText(value)]);
|
|
32
|
+
return { outcome: 'accepted', answers: Object.fromEntries(answers) };
|
|
33
|
+
}
|
|
34
|
+
export function grokPlanForm({ sessionId, planContent }) {
|
|
35
|
+
return form(sessionId, planContent, { [PLAN]: PLAN_FIELD });
|
|
36
|
+
}
|
|
37
|
+
export function grokPlanAnswer(response) {
|
|
38
|
+
return { outcome: contentOf(response)[PLAN] ?? PLAN_ABANDONED };
|
|
39
|
+
}
|
package/dist/home.js
CHANGED
|
@@ -1,36 +1,117 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
+
import { chmodSync, existsSync, linkSync, lstatSync, mkdirSync, readFileSync, realpathSync, renameSync, rmSync, unlinkSync, writeFileSync } from 'node:fs';
|
|
2
3
|
import { mkdir, readFile, rename, rm, writeFile } from 'node:fs/promises';
|
|
3
4
|
import { homedir } from 'node:os';
|
|
4
|
-
import { join } from 'node:path';
|
|
5
|
+
import { join, resolve } from 'node:path';
|
|
5
6
|
import { selectRelay } from './relay.js';
|
|
6
7
|
const ENROLMENT = 'credential.json';
|
|
7
8
|
const DISCONNECTED = 'disconnected.json';
|
|
8
9
|
const CONFIGURATION = 'kit.json';
|
|
9
10
|
const OWN_AGENT = 'own-agent.json';
|
|
10
|
-
const
|
|
11
|
+
const PLANNED_RESTART = 'planned-restart';
|
|
12
|
+
const EARLIER_PREFIXES = ['/kit-home/kit', '/opt/house-kit'];
|
|
13
|
+
function privateDirectory(path) {
|
|
14
|
+
try {
|
|
15
|
+
mkdirSync(path, { mode: 0o700 });
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
if (error.code !== 'EEXIST')
|
|
19
|
+
throw error;
|
|
20
|
+
}
|
|
21
|
+
const found = lstatSync(path);
|
|
22
|
+
if (found.isSymbolicLink())
|
|
23
|
+
throw new Error(`${path} is a symbolic link`);
|
|
24
|
+
if (!found.isDirectory())
|
|
25
|
+
throw new Error(`${path} is not a directory`);
|
|
26
|
+
if (found.uid !== process.geteuid())
|
|
27
|
+
throw new Error(`${path} is not owned by this User`);
|
|
28
|
+
chmodSync(path, 0o700);
|
|
29
|
+
return path;
|
|
30
|
+
}
|
|
31
|
+
export function oneFolder(account = homedir()) {
|
|
32
|
+
return join(account, '.agents', 'house');
|
|
33
|
+
}
|
|
34
|
+
export function houseFolder(account = homedir()) {
|
|
35
|
+
return join(account, 'house');
|
|
36
|
+
}
|
|
37
|
+
export function desktopPrefix() {
|
|
38
|
+
return join(homedir(), '.local', 'share', 'house-kit');
|
|
39
|
+
}
|
|
40
|
+
export function earlierPrefix() {
|
|
41
|
+
const prefix = process.env.HOUSE_KIT_PREFIX;
|
|
42
|
+
if (prefix === undefined || prefix === '')
|
|
43
|
+
return null;
|
|
44
|
+
return [...EARLIER_PREFIXES, desktopPrefix()].includes(resolve(prefix)) ? resolve(prefix) : null;
|
|
45
|
+
}
|
|
46
|
+
export function awaitsTakeover() {
|
|
47
|
+
const prefix = earlierPrefix();
|
|
48
|
+
return prefix === EARLIER_PREFIXES[0] || (prefix === EARLIER_PREFIXES[1] && process.getuid() !== 0);
|
|
49
|
+
}
|
|
50
|
+
export function earlierHome() {
|
|
51
|
+
return process.env.HOUSE_KIT_HOME || join(homedir(), '.house-kit');
|
|
52
|
+
}
|
|
53
|
+
export function reinstall() {
|
|
54
|
+
if (!awaitsTakeover())
|
|
55
|
+
return undefined;
|
|
56
|
+
try {
|
|
57
|
+
return readFileSync(join(earlierHome(), 'placement'), 'utf8').trim() === 'windows' ? 'windows' : 'linux';
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
if (error.code === 'ENOENT')
|
|
61
|
+
return 'linux';
|
|
62
|
+
throw error;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
11
65
|
export function kitHome() {
|
|
12
|
-
return
|
|
66
|
+
return earlierPrefix() === null ? oneFolder() : earlierHome();
|
|
67
|
+
}
|
|
68
|
+
export function socketDirectory() {
|
|
69
|
+
const sockets = privateDirectory(join(realpathSync('/tmp'), `hk-${process.geteuid()}`));
|
|
70
|
+
const home = kitHome();
|
|
71
|
+
const physical = existsSync(home) ? realpathSync(home) : resolve(home);
|
|
72
|
+
return privateDirectory(join(sockets, createHash('sha256').update(physical).digest('hex').slice(0, 12)));
|
|
73
|
+
}
|
|
74
|
+
export function ownerSocket() {
|
|
75
|
+
return join(socketDirectory(), 'owner.sock');
|
|
76
|
+
}
|
|
77
|
+
export function ownerLock() {
|
|
78
|
+
return join(socketDirectory(), 'owner.lock');
|
|
13
79
|
}
|
|
14
80
|
export function workspaceRoot() {
|
|
15
|
-
|
|
81
|
+
if (earlierPrefix() !== null)
|
|
82
|
+
return process.env.HOUSE_KIT_WORKSPACE ?? '/agents/house';
|
|
83
|
+
return configuredWorkspace() ?? houseFolder();
|
|
16
84
|
}
|
|
17
85
|
export function agentBase() {
|
|
18
86
|
return join(workspaceRoot(), 'agents');
|
|
19
87
|
}
|
|
88
|
+
export function roomsFolder() {
|
|
89
|
+
return join(workspaceRoot(), 'rooms');
|
|
90
|
+
}
|
|
91
|
+
function parsed(name, text) {
|
|
92
|
+
try {
|
|
93
|
+
return JSON.parse(text);
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
throw new Error(`${name} in Kit home holds no JSON`);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
20
99
|
export async function readHome(name) {
|
|
100
|
+
let text;
|
|
21
101
|
try {
|
|
22
|
-
|
|
102
|
+
text = await readFile(join(kitHome(), name), 'utf8');
|
|
23
103
|
}
|
|
24
104
|
catch (error) {
|
|
25
105
|
if (error.code === 'ENOENT')
|
|
26
106
|
return null;
|
|
27
107
|
throw error;
|
|
28
108
|
}
|
|
109
|
+
return parsed(name, text);
|
|
29
110
|
}
|
|
30
111
|
export async function writeHome(name, value) {
|
|
31
112
|
const home = kitHome();
|
|
32
113
|
await mkdir(home, { recursive: true, mode: 0o700 });
|
|
33
|
-
const temporary = join(home, `${name}.${
|
|
114
|
+
const temporary = join(home, `${name}.${randomUUID()}`);
|
|
34
115
|
await writeFile(temporary, `${JSON.stringify(value)}\n`, { mode: 0o600 });
|
|
35
116
|
await rename(temporary, join(home, name));
|
|
36
117
|
}
|
|
@@ -47,6 +128,9 @@ export async function writeEnrolment(enrolment) {
|
|
|
47
128
|
export function readDisconnected() {
|
|
48
129
|
return readHome(DISCONNECTED);
|
|
49
130
|
}
|
|
131
|
+
export function forgetDisconnected() {
|
|
132
|
+
return rm(join(kitHome(), DISCONNECTED), { force: true });
|
|
133
|
+
}
|
|
50
134
|
export async function forgetEnrolment({ house, environment }) {
|
|
51
135
|
await writeHome(DISCONNECTED, { house, environment });
|
|
52
136
|
await rm(join(kitHome(), ENROLMENT), { force: true });
|
|
@@ -66,7 +150,7 @@ export async function forgetRejected(rejected) {
|
|
|
66
150
|
return;
|
|
67
151
|
throw error;
|
|
68
152
|
}
|
|
69
|
-
if (
|
|
153
|
+
if (parsed(ENROLMENT, readFileSync(taken, 'utf8')).credential !== rejected) {
|
|
70
154
|
try {
|
|
71
155
|
linkSync(taken, enrolment);
|
|
72
156
|
}
|
|
@@ -78,14 +162,22 @@ export async function forgetRejected(rejected) {
|
|
|
78
162
|
}
|
|
79
163
|
rmSync(taken);
|
|
80
164
|
}
|
|
81
|
-
export function
|
|
82
|
-
|
|
165
|
+
export function recordPlannedRestart() {
|
|
166
|
+
writeFileSync(join(kitHome(), PLANNED_RESTART), '', { mode: 0o600 });
|
|
83
167
|
}
|
|
84
|
-
export function
|
|
85
|
-
|
|
168
|
+
export function takePlannedRestart() {
|
|
169
|
+
try {
|
|
170
|
+
unlinkSync(join(kitHome(), PLANNED_RESTART));
|
|
171
|
+
return true;
|
|
172
|
+
}
|
|
173
|
+
catch (error) {
|
|
174
|
+
if (error.code === 'ENOENT')
|
|
175
|
+
return false;
|
|
176
|
+
throw error;
|
|
177
|
+
}
|
|
86
178
|
}
|
|
87
|
-
export function
|
|
88
|
-
return
|
|
179
|
+
export function enrolled() {
|
|
180
|
+
return existsSync(join(kitHome(), ENROLMENT));
|
|
89
181
|
}
|
|
90
182
|
export function readOwnAgent() {
|
|
91
183
|
return readHome(OWN_AGENT);
|
|
@@ -96,8 +188,24 @@ export function writeOwnAgent(ownAgent) {
|
|
|
96
188
|
export function forgetOwnAgent() {
|
|
97
189
|
return rm(join(kitHome(), OWN_AGENT), { force: true });
|
|
98
190
|
}
|
|
191
|
+
function configuredWorkspace() {
|
|
192
|
+
let text;
|
|
193
|
+
try {
|
|
194
|
+
text = readFileSync(join(kitHome(), CONFIGURATION), 'utf8');
|
|
195
|
+
}
|
|
196
|
+
catch (error) {
|
|
197
|
+
if (error.code === 'ENOENT')
|
|
198
|
+
return undefined;
|
|
199
|
+
throw error;
|
|
200
|
+
}
|
|
201
|
+
return parsed(CONFIGURATION, text).workspace;
|
|
202
|
+
}
|
|
99
203
|
export async function readConfiguration() {
|
|
100
|
-
|
|
204
|
+
const stored = await readHome(CONFIGURATION);
|
|
205
|
+
return { skills: stored?.skills !== false, workspace: stored?.workspace ?? houseFolder() };
|
|
206
|
+
}
|
|
207
|
+
export async function storedConfiguration() {
|
|
208
|
+
return (await readHome(CONFIGURATION)) ?? {};
|
|
101
209
|
}
|
|
102
210
|
export function writeConfiguration(configuration) {
|
|
103
211
|
return writeHome(CONFIGURATION, configuration);
|