@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/files.js
CHANGED
|
@@ -1,48 +1,137 @@
|
|
|
1
1
|
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
-
import { createWriteStream } from 'node:fs';
|
|
2
|
+
import { createReadStream, createWriteStream } from 'node:fs';
|
|
3
3
|
import { mkdir, rename, rm } from 'node:fs/promises';
|
|
4
|
-
import {
|
|
4
|
+
import { request } from 'node:http';
|
|
5
|
+
import { request as httpsRequest } from 'node:https';
|
|
6
|
+
import { basename, dirname, extname, join } from 'node:path';
|
|
5
7
|
import { Readable, Transform } from 'node:stream';
|
|
6
8
|
import { pipeline } from 'node:stream/promises';
|
|
7
9
|
import { parseDocument } from 'yaml';
|
|
8
10
|
import { retryDelay } from './api.js';
|
|
9
11
|
import { Unsettled } from './mcp.js';
|
|
10
|
-
import { relayed } from './relay.js';
|
|
12
|
+
import { proxyUnlessRelayed, relayed } from './relay.js';
|
|
11
13
|
const STALLED_ROUNDS = 8;
|
|
14
|
+
const PART_CHECKSUM = 'x-amz-checksum-sha256';
|
|
12
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
|
+
}
|
|
13
46
|
export function linkedPaths(text) {
|
|
14
47
|
return [...new Set(Array.from(text.matchAll(LINK), (link) => link[1]))];
|
|
15
48
|
}
|
|
16
|
-
export function
|
|
49
|
+
export function fileInfo(answer) {
|
|
17
50
|
const document = parseDocument(answer);
|
|
18
51
|
if (document.errors.length > 0)
|
|
19
52
|
return null;
|
|
20
|
-
const
|
|
21
|
-
if (typeof
|
|
53
|
+
const details = document.toJS();
|
|
54
|
+
if (typeof details?.download !== 'string')
|
|
22
55
|
return null;
|
|
23
56
|
return {
|
|
24
|
-
download:
|
|
25
|
-
sha256: String(
|
|
26
|
-
|
|
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,
|
|
27
62
|
};
|
|
28
63
|
}
|
|
29
|
-
function paused(milliseconds) {
|
|
64
|
+
export function paused(milliseconds) {
|
|
30
65
|
return new Promise((resolve) => setTimeout(resolve, milliseconds));
|
|
31
66
|
}
|
|
32
67
|
export function storeRefusal(act, status) {
|
|
33
68
|
return new Error(`the ${act} answered ${status}; ${act} the file again`);
|
|
34
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
|
+
}
|
|
35
118
|
export async function uploaded(declared, uploading) {
|
|
36
|
-
|
|
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);
|
|
37
123
|
let idle = 0;
|
|
38
124
|
let stalled = 0;
|
|
39
|
-
|
|
125
|
+
while ('upload' in answer) {
|
|
126
|
+
const { id, parts } = answer.upload;
|
|
40
127
|
let sent = 0;
|
|
41
128
|
let failure = null;
|
|
42
|
-
for (const { part, url } of
|
|
43
|
-
const start = (part - 1) *
|
|
129
|
+
for (const { part, url } of parts ?? []) {
|
|
130
|
+
const start = (part - 1) * partBytes;
|
|
44
131
|
try {
|
|
45
|
-
await uploading.send(url, start, Math.min(start +
|
|
132
|
+
await uploading.send(url, start, Math.min(start + partBytes, uploading.bytes), {
|
|
133
|
+
[PART_CHECKSUM]: digests[part - 1].toString('base64'),
|
|
134
|
+
});
|
|
46
135
|
sent++;
|
|
47
136
|
}
|
|
48
137
|
catch (error) {
|
|
@@ -57,24 +146,17 @@ export async function uploaded(declared, uploading) {
|
|
|
57
146
|
else {
|
|
58
147
|
if (failure !== null && ++stalled >= STALLED_ROUNDS)
|
|
59
148
|
throw failure;
|
|
60
|
-
// A round that sent no part, its store unreachable
|
|
149
|
+
// A round that sent no part, its store unreachable, is followed by the next finishing call on the jittered curve.
|
|
61
150
|
await paused(retryDelay(idle++));
|
|
62
151
|
}
|
|
63
|
-
|
|
64
|
-
while ('checking' in answer) {
|
|
65
|
-
// A finishing call that finds House still checking the stored bytes is sent again after five seconds, the cadence at which House takes up a check it handed over.
|
|
66
|
-
await paused(5_000);
|
|
67
|
-
answer = await finishing(uploading, upload.id);
|
|
68
|
-
}
|
|
69
|
-
if (!('upload' in answer))
|
|
70
|
-
return answer;
|
|
71
|
-
upload = answer.upload;
|
|
152
|
+
answer = await finishing(uploading, id, partSha256);
|
|
72
153
|
}
|
|
154
|
+
return answer;
|
|
73
155
|
}
|
|
74
|
-
async function finishing(uploading, upload) {
|
|
156
|
+
async function finishing(uploading, upload, partSha256) {
|
|
75
157
|
for (let unsettled = 1;; unsettled++) {
|
|
76
158
|
try {
|
|
77
|
-
return await uploading.finish(upload);
|
|
159
|
+
return await uploading.finish(upload, partSha256);
|
|
78
160
|
}
|
|
79
161
|
catch (error) {
|
|
80
162
|
if (!(error instanceof Unsettled) || unsettled === STALLED_ROUNDS)
|
|
@@ -124,5 +206,5 @@ export async function downloaded(address, fetching, destination, name) {
|
|
|
124
206
|
}
|
|
125
207
|
export async function fetched(url, signal) {
|
|
126
208
|
const answer = await fetch(relayed(url), { signal });
|
|
127
|
-
return { status: answer.status, body: answer.body
|
|
209
|
+
return { status: answer.status, body: answer.body === null ? Readable.from([]) : Readable.fromWeb(answer.body) };
|
|
128
210
|
}
|
package/dist/git-main.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { spawn, spawnSync } from 'node:child_process';
|
|
3
|
-
import { accessSync, constants, realpathSync, statSync } from 'node:fs';
|
|
3
|
+
import { accessSync, constants, mkdtempSync, realpathSync, rmSync, statSync } from 'node:fs';
|
|
4
4
|
import { request } from 'node:http';
|
|
5
5
|
import { constants as system } from 'node:os';
|
|
6
6
|
import { delimiter, dirname, join } from 'node:path';
|
|
@@ -52,11 +52,12 @@ function nativeGit() {
|
|
|
52
52
|
}
|
|
53
53
|
return null;
|
|
54
54
|
}
|
|
55
|
-
function captured(git, args) {
|
|
55
|
+
function captured(git, args, { input, index } = {}) {
|
|
56
56
|
const ran = spawnSync(git, args, {
|
|
57
|
-
|
|
57
|
+
input,
|
|
58
|
+
stdio: [input === undefined ? 'ignore' : 'pipe', 'pipe', 'ignore'],
|
|
58
59
|
maxBuffer: Infinity,
|
|
59
|
-
env: { ...process.env, LC_ALL: 'C' },
|
|
60
|
+
env: { ...process.env, LC_ALL: 'C', ...(index === undefined ? {} : { GIT_INDEX_FILE: index }) },
|
|
60
61
|
});
|
|
61
62
|
return ran.status === 0 ? ran.stdout.toString('utf8') : null;
|
|
62
63
|
}
|
|
@@ -78,30 +79,25 @@ function delegated(git, args) {
|
|
|
78
79
|
child.once('close', (status, signal) => settle({ status, signal }));
|
|
79
80
|
});
|
|
80
81
|
}
|
|
81
|
-
function
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
82
|
+
function merged(git, copy, common) {
|
|
83
|
+
const staged = (captured(git, [...copy, 'ls-files', '--stage', '-z']) ?? '').split('\0');
|
|
84
|
+
const input = staged.filter((entry) => /^\d+ [0-9a-f]+ 0\t/.test(entry)).map((entry) => `${entry}\0`).join('');
|
|
85
|
+
const scratch = mkdtempSync(join(common, 'house-index-'));
|
|
86
|
+
try {
|
|
87
|
+
const index = join(scratch, 'index');
|
|
88
|
+
captured(git, [...copy, 'update-index', '-z', '--index-info'], { input, index });
|
|
89
|
+
return captured(git, [...copy, 'write-tree'], { index })?.trim();
|
|
90
|
+
}
|
|
91
|
+
finally {
|
|
92
|
+
rmSync(scratch, { recursive: true, force: true });
|
|
87
93
|
}
|
|
88
|
-
return entries;
|
|
89
94
|
}
|
|
90
|
-
function moved(
|
|
95
|
+
function moved(git, copy, before) {
|
|
96
|
+
const renames = ['diff-index', '--cached', '-z', '--name-status', '--find-renames=100%', '--diff-filter=R', before];
|
|
97
|
+
const fields = (captured(git, [...copy, ...renames]) ?? '').split('\0');
|
|
91
98
|
const moves = [];
|
|
92
|
-
for (
|
|
93
|
-
|
|
94
|
-
continue;
|
|
95
|
-
const renaming = line.slice('Renaming '.length);
|
|
96
|
-
for (let at = renaming.indexOf(' to '); at >= 0; at = renaming.indexOf(' to ', at + 1)) {
|
|
97
|
-
const from = renaming.slice(0, at);
|
|
98
|
-
const to = renaming.slice(at + 4);
|
|
99
|
-
if (before.has(from) && !after.has(from) && after.get(to) === before.get(from)) {
|
|
100
|
-
moves.push({ from, to });
|
|
101
|
-
break;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
99
|
+
for (let at = 0; at + 2 < fields.length; at += 3)
|
|
100
|
+
moves.push({ from: fields[at + 1], to: fields[at + 2] });
|
|
105
101
|
return moves;
|
|
106
102
|
}
|
|
107
103
|
function reported(socketPath, body) {
|
|
@@ -128,11 +124,10 @@ async function observed(git, args) {
|
|
|
128
124
|
if (common === undefined || worktree === undefined || !dirname(common).startsWith(`${localCopies()}/`)) {
|
|
129
125
|
return delegated(git, args);
|
|
130
126
|
}
|
|
131
|
-
const
|
|
132
|
-
const before = name === 'mv' ?
|
|
133
|
-
const planned = name === 'mv' ? (captured(git, [...globals, 'mv', '--dry-run', ...args.slice(index + 1)]) ?? '') : '';
|
|
127
|
+
const copy = [...globals, '-C', worktree];
|
|
128
|
+
const before = name === 'mv' ? merged(git, copy, common) : undefined;
|
|
134
129
|
const outcome = await delegated(git, args);
|
|
135
|
-
const moves = before !==
|
|
130
|
+
const moves = before !== undefined && outcome.status === 0 ? moved(git, copy, before) : [];
|
|
136
131
|
await reported(bridge, { common, worktree, moves });
|
|
137
132
|
return outcome;
|
|
138
133
|
}
|
package/dist/git.js
CHANGED
|
@@ -2,8 +2,8 @@ import { spawn } from 'node:child_process';
|
|
|
2
2
|
import { isUtf8 } from 'node:buffer';
|
|
3
3
|
import { createHash } from 'node:crypto';
|
|
4
4
|
import { join } from 'node:path';
|
|
5
|
-
import { withoutProxy } from './clis.js';
|
|
6
5
|
import { workspaceRoot } from './home.js';
|
|
6
|
+
import { childEnvironment } from './relay.js';
|
|
7
7
|
export function localCopies() {
|
|
8
8
|
return join(workspaceRoot(), 'local-copies');
|
|
9
9
|
}
|
|
@@ -11,7 +11,7 @@ export const HOUSE_REF = 'refs/house/received';
|
|
|
11
11
|
const COMMITTER = 'Kit <house-kit@localhost>';
|
|
12
12
|
export function run(cwd, args, input, env = {}) {
|
|
13
13
|
return new Promise((resolve, reject) => {
|
|
14
|
-
const child = spawn('git', args, { cwd, env: { ...
|
|
14
|
+
const child = spawn('git', args, { cwd, env: { ...childEnvironment(), ...env } });
|
|
15
15
|
const stdout = [];
|
|
16
16
|
let stderr = '';
|
|
17
17
|
child.stdout.on('data', (chunk) => stdout.push(chunk));
|
|
@@ -55,11 +55,50 @@ async function blob(repository, object) {
|
|
|
55
55
|
export async function blobText(repository, object) {
|
|
56
56
|
return (await blob(repository, object)).toString('utf8');
|
|
57
57
|
}
|
|
58
|
-
export async function
|
|
58
|
+
export async function blobSizes(repository, objects) {
|
|
59
|
+
if (objects.length === 0)
|
|
60
|
+
return new Map();
|
|
61
|
+
const listed = await git(repository, ['cat-file', '--batch-check=%(objectname) %(objectsize)'], `${[...new Set(objects)].join('\n')}\n`);
|
|
62
|
+
return new Map(listed
|
|
63
|
+
.split('\n')
|
|
64
|
+
.filter((line) => line !== '')
|
|
65
|
+
.map((line) => {
|
|
66
|
+
const [object, size] = line.split(' ');
|
|
67
|
+
return [object, Number(size)];
|
|
68
|
+
}));
|
|
69
|
+
}
|
|
70
|
+
export async function isText(repository, object, size, maxBytes) {
|
|
71
|
+
if (size > maxBytes)
|
|
72
|
+
return false;
|
|
59
73
|
const bytes = await blob(repository, object);
|
|
60
|
-
return
|
|
74
|
+
return isUtf8(bytes) && !bytes.includes(0);
|
|
75
|
+
}
|
|
76
|
+
export async function* blobBytes(repository, object) {
|
|
77
|
+
const child = spawn('git', ['cat-file', 'blob', object], { cwd: repository, env: childEnvironment(), stdio: ['ignore', 'pipe', 'pipe'] });
|
|
78
|
+
let stderr = '';
|
|
79
|
+
child.stderr.on('data', (chunk) => {
|
|
80
|
+
stderr += chunk.toString('utf8');
|
|
81
|
+
});
|
|
82
|
+
const closed = new Promise((resolve, reject) => {
|
|
83
|
+
child.on('error', reject);
|
|
84
|
+
child.on('close', resolve);
|
|
85
|
+
});
|
|
86
|
+
try {
|
|
87
|
+
yield* child.stdout;
|
|
88
|
+
}
|
|
89
|
+
finally {
|
|
90
|
+
if (child.exitCode === null)
|
|
91
|
+
child.kill();
|
|
92
|
+
}
|
|
93
|
+
if ((await closed) !== 0)
|
|
94
|
+
throw new Error(`git cat-file failed: ${stderr.trim()}`);
|
|
95
|
+
}
|
|
96
|
+
export async function storedFile(repository, file) {
|
|
97
|
+
return (await git(repository, ['hash-object', '-w', '--no-filters', '--', file])).trim();
|
|
61
98
|
}
|
|
62
99
|
export function blobId(content) {
|
|
100
|
+
if (typeof content !== 'string')
|
|
101
|
+
return content.blob;
|
|
63
102
|
const bytes = Buffer.from(content, 'utf8');
|
|
64
103
|
return createHash('sha1').update(`blob ${bytes.length}\0`).update(bytes).digest('hex');
|
|
65
104
|
}
|
|
@@ -70,18 +109,54 @@ function data(text) {
|
|
|
70
109
|
const bytes = Buffer.from(text, 'utf8');
|
|
71
110
|
return [Buffer.from(`data ${bytes.length}\n`), bytes, Buffer.from('\n')];
|
|
72
111
|
}
|
|
73
|
-
|
|
74
|
-
|
|
112
|
+
function written(stream, bytes) {
|
|
113
|
+
return new Promise((resolve, reject) => {
|
|
114
|
+
stream.write(bytes, (error) => (error ? reject(error) : resolve()));
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
async function imported(stream, commits) {
|
|
118
|
+
await written(stream, Buffer.from('feature done\n'));
|
|
75
119
|
for (const [index, commit] of commits.entries()) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
120
|
+
await written(stream, Buffer.concat([
|
|
121
|
+
Buffer.from(`commit ${HOUSE_REF}\nmark :${index + 1}\ncommitter ${COMMITTER} ${Math.floor(Date.now() / 1000)} +0000\n`),
|
|
122
|
+
...data(commit.message),
|
|
123
|
+
...(commit.from === null ? [] : [Buffer.from(`from ${commit.from}\n`)]),
|
|
124
|
+
...(commit.merge === undefined ? [] : [Buffer.from(`merge ${commit.merge}\n`)]),
|
|
125
|
+
...(commit.replaces === true ? [Buffer.from('deleteall\n')] : []),
|
|
126
|
+
]));
|
|
127
|
+
for await (const [path, content] of commit.files) {
|
|
128
|
+
await written(stream, content === null
|
|
129
|
+
? Buffer.from(`D ${quoted(path)}\n`)
|
|
130
|
+
: typeof content === 'string'
|
|
131
|
+
? Buffer.concat([Buffer.from(`M 100644 inline ${quoted(path)}\n`), ...data(content)])
|
|
132
|
+
: Buffer.from(`M 100644 ${content.blob} ${quoted(path)}\n`));
|
|
82
133
|
}
|
|
83
|
-
stream
|
|
134
|
+
await written(stream, Buffer.from('\n'));
|
|
135
|
+
}
|
|
136
|
+
await written(stream, Buffer.from('done\n'));
|
|
137
|
+
}
|
|
138
|
+
export async function importCommits(repository, commits) {
|
|
139
|
+
const child = spawn('git', ['fast-import', '--quiet', '--force'], { cwd: repository, env: childEnvironment() });
|
|
140
|
+
let stderr = '';
|
|
141
|
+
child.stdout.resume();
|
|
142
|
+
child.stderr.on('data', (chunk) => {
|
|
143
|
+
stderr += chunk.toString('utf8');
|
|
144
|
+
});
|
|
145
|
+
child.stdin.on('error', () => undefined);
|
|
146
|
+
const closed = new Promise((resolve, reject) => {
|
|
147
|
+
child.on('error', reject);
|
|
148
|
+
child.on('close', resolve);
|
|
149
|
+
});
|
|
150
|
+
try {
|
|
151
|
+
await imported(child.stdin, commits);
|
|
152
|
+
child.stdin.end();
|
|
153
|
+
}
|
|
154
|
+
catch (error) {
|
|
155
|
+
child.stdin.destroy();
|
|
156
|
+
await closed;
|
|
157
|
+
throw error.code === 'EPIPE' ? new Error(`git fast-import failed: ${stderr.trim()}`) : error;
|
|
84
158
|
}
|
|
85
|
-
|
|
159
|
+
if ((await closed) !== 0)
|
|
160
|
+
throw new Error(`git fast-import failed: ${stderr.trim()}`);
|
|
86
161
|
return revision(repository, HOUSE_REF);
|
|
87
162
|
}
|
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,24 +1,14 @@
|
|
|
1
1
|
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
-
import {
|
|
2
|
+
import { chmodSync, existsSync, linkSync, lstatSync, mkdirSync, readFileSync, realpathSync, renameSync, rmSync } from 'node:fs';
|
|
3
3
|
import { mkdir, readFile, rename, rm, writeFile } from 'node:fs/promises';
|
|
4
|
-
import { homedir
|
|
4
|
+
import { homedir } from 'node:os';
|
|
5
5
|
import { join, resolve } from 'node:path';
|
|
6
6
|
import { selectRelay } from './relay.js';
|
|
7
7
|
const ENROLMENT = 'credential.json';
|
|
8
8
|
const DISCONNECTED = 'disconnected.json';
|
|
9
9
|
const CONFIGURATION = 'kit.json';
|
|
10
10
|
const OWN_AGENT = 'own-agent.json';
|
|
11
|
-
const
|
|
12
|
-
let defaulted;
|
|
13
|
-
function writable(directory) {
|
|
14
|
-
try {
|
|
15
|
-
accessSync(directory, constants.W_OK | constants.X_OK);
|
|
16
|
-
return true;
|
|
17
|
-
}
|
|
18
|
-
catch {
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
11
|
+
const EARLIER_PREFIXES = ['/kit-home/kit', '/opt/house-kit'];
|
|
22
12
|
function privateDirectory(path) {
|
|
23
13
|
try {
|
|
24
14
|
mkdirSync(path, { mode: 0o700 });
|
|
@@ -37,15 +27,39 @@ function privateDirectory(path) {
|
|
|
37
27
|
chmodSync(path, 0o700);
|
|
38
28
|
return path;
|
|
39
29
|
}
|
|
40
|
-
function
|
|
41
|
-
return
|
|
30
|
+
export function oneFolder(account = homedir()) {
|
|
31
|
+
return join(account, '.agents', 'house');
|
|
32
|
+
}
|
|
33
|
+
export function desktopPrefix() {
|
|
34
|
+
return join(homedir(), '.local', 'share', 'house-kit');
|
|
35
|
+
}
|
|
36
|
+
export function earlierPrefix() {
|
|
37
|
+
const prefix = process.env.HOUSE_KIT_PREFIX;
|
|
38
|
+
if (prefix === undefined || prefix === '')
|
|
39
|
+
return null;
|
|
40
|
+
return [...EARLIER_PREFIXES, desktopPrefix()].includes(resolve(prefix)) ? resolve(prefix) : null;
|
|
41
|
+
}
|
|
42
|
+
export function awaitsTakeover() {
|
|
43
|
+
const prefix = earlierPrefix();
|
|
44
|
+
return prefix === EARLIER_PREFIXES[0] || (prefix === EARLIER_PREFIXES[1] && process.getuid() !== 0);
|
|
42
45
|
}
|
|
43
|
-
function
|
|
44
|
-
|
|
45
|
-
|
|
46
|
+
export function earlierHome() {
|
|
47
|
+
return process.env.HOUSE_KIT_HOME || join(homedir(), '.house-kit');
|
|
48
|
+
}
|
|
49
|
+
export function reinstall() {
|
|
50
|
+
if (!awaitsTakeover())
|
|
51
|
+
return undefined;
|
|
52
|
+
try {
|
|
53
|
+
return readFileSync(join(earlierHome(), 'placement'), 'utf8').trim() === 'windows' ? 'windows' : 'linux';
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
if (error.code === 'ENOENT')
|
|
57
|
+
return 'linux';
|
|
58
|
+
throw error;
|
|
59
|
+
}
|
|
46
60
|
}
|
|
47
61
|
export function kitHome() {
|
|
48
|
-
return
|
|
62
|
+
return earlierPrefix() === null ? oneFolder() : earlierHome();
|
|
49
63
|
}
|
|
50
64
|
export function socketDirectory() {
|
|
51
65
|
const sockets = privateDirectory(join(realpathSync('/tmp'), `hk-${process.geteuid()}`));
|
|
@@ -60,20 +74,32 @@ export function ownerLock() {
|
|
|
60
74
|
return join(socketDirectory(), 'owner.lock');
|
|
61
75
|
}
|
|
62
76
|
export function workspaceRoot() {
|
|
63
|
-
|
|
77
|
+
if (earlierPrefix() !== null)
|
|
78
|
+
return process.env.HOUSE_KIT_WORKSPACE ?? '/agents/house';
|
|
79
|
+
return configuredWorkspace() ?? kitHome();
|
|
64
80
|
}
|
|
65
81
|
export function agentBase() {
|
|
66
82
|
return join(workspaceRoot(), 'agents');
|
|
67
83
|
}
|
|
84
|
+
function parsed(name, text) {
|
|
85
|
+
try {
|
|
86
|
+
return JSON.parse(text);
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
throw new Error(`${name} in Kit home holds no JSON`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
68
92
|
export async function readHome(name) {
|
|
93
|
+
let text;
|
|
69
94
|
try {
|
|
70
|
-
|
|
95
|
+
text = await readFile(join(kitHome(), name), 'utf8');
|
|
71
96
|
}
|
|
72
97
|
catch (error) {
|
|
73
98
|
if (error.code === 'ENOENT')
|
|
74
99
|
return null;
|
|
75
100
|
throw error;
|
|
76
101
|
}
|
|
102
|
+
return parsed(name, text);
|
|
77
103
|
}
|
|
78
104
|
export async function writeHome(name, value) {
|
|
79
105
|
const home = kitHome();
|
|
@@ -117,7 +143,7 @@ export async function forgetRejected(rejected) {
|
|
|
117
143
|
return;
|
|
118
144
|
throw error;
|
|
119
145
|
}
|
|
120
|
-
if (
|
|
146
|
+
if (parsed(ENROLMENT, readFileSync(taken, 'utf8')).credential !== rejected) {
|
|
121
147
|
try {
|
|
122
148
|
linkSync(taken, enrolment);
|
|
123
149
|
}
|
|
@@ -132,12 +158,6 @@ export async function forgetRejected(rejected) {
|
|
|
132
158
|
export function enrolled() {
|
|
133
159
|
return existsSync(join(kitHome(), ENROLMENT));
|
|
134
160
|
}
|
|
135
|
-
export function restartAsked() {
|
|
136
|
-
return existsSync(join(kitHome(), RESTART));
|
|
137
|
-
}
|
|
138
|
-
export function forgetRestart() {
|
|
139
|
-
return rm(join(kitHome(), RESTART), { force: true });
|
|
140
|
-
}
|
|
141
161
|
export function readOwnAgent() {
|
|
142
162
|
return readHome(OWN_AGENT);
|
|
143
163
|
}
|
|
@@ -147,8 +167,24 @@ export function writeOwnAgent(ownAgent) {
|
|
|
147
167
|
export function forgetOwnAgent() {
|
|
148
168
|
return rm(join(kitHome(), OWN_AGENT), { force: true });
|
|
149
169
|
}
|
|
170
|
+
function configuredWorkspace() {
|
|
171
|
+
let text;
|
|
172
|
+
try {
|
|
173
|
+
text = readFileSync(join(kitHome(), CONFIGURATION), 'utf8');
|
|
174
|
+
}
|
|
175
|
+
catch (error) {
|
|
176
|
+
if (error.code === 'ENOENT')
|
|
177
|
+
return undefined;
|
|
178
|
+
throw error;
|
|
179
|
+
}
|
|
180
|
+
return parsed(CONFIGURATION, text).workspace;
|
|
181
|
+
}
|
|
150
182
|
export async function readConfiguration() {
|
|
151
|
-
|
|
183
|
+
const stored = await readHome(CONFIGURATION);
|
|
184
|
+
return { skills: stored?.skills !== false, workspace: stored?.workspace ?? kitHome() };
|
|
185
|
+
}
|
|
186
|
+
export async function storedConfiguration() {
|
|
187
|
+
return (await readHome(CONFIGURATION)) ?? {};
|
|
152
188
|
}
|
|
153
189
|
export function writeConfiguration(configuration) {
|
|
154
190
|
return writeHome(CONFIGURATION, configuration);
|