@agentshouse/kit 0.2.1-cf268dff1869b → 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 +18 -25
- package/dist/acp.js +12 -9
- package/dist/afk.js +17 -0
- package/dist/agents.js +72 -26
- package/dist/api.js +18 -4
- package/dist/binaries.js +60 -0
- package/dist/bridge.js +99 -44
- package/dist/calls.js +18 -1
- package/dist/chunks.js +54 -0
- package/dist/clis.js +33 -15
- package/dist/connect.js +121 -0
- package/dist/connection.js +25 -10
- package/dist/content.js +106 -0
- package/dist/conversations.js +251 -158
- package/dist/copies.js +1260 -599
- package/dist/earlier.js +273 -0
- package/dist/end.js +6 -9
- package/dist/events.js +544 -297
- package/dist/files.js +77 -11
- package/dist/git.js +0 -70
- package/dist/grok.js +39 -0
- package/dist/home.js +86 -22
- package/dist/house-cli.js +145 -162
- package/dist/instructions.js +2 -4
- package/dist/keys.js +238 -0
- package/dist/kit-cli.js +14 -4
- package/dist/login.js +34 -20
- package/dist/logout.js +2 -2
- package/dist/manifest.js +75 -0
- package/dist/mcp.js +43 -7
- package/dist/owner.js +46 -0
- package/dist/placement.js +0 -6
- package/dist/refusals.js +50 -23
- package/dist/resident.js +117 -76
- package/dist/scripts.js +79 -15
- package/dist/secret-input.js +1 -1
- package/dist/settings.js +247 -0
- package/dist/sign-in.js +49 -4
- package/dist/supervisor.js +163 -0
- package/dist/transcription.js +5 -2
- package/dist/update.js +31 -22
- package/dist/wire.js +2 -10
- package/dist/work.js +27 -2
- package/dist/workspace.js +113 -0
- package/package.json +12 -8
- package/dist/authority-main.js +0 -22
- package/dist/chatgpt.js +0 -32
- 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 -55
- package/dist/translate.js +0 -45
package/dist/work.js
CHANGED
|
@@ -25,6 +25,9 @@ export class Work {
|
|
|
25
25
|
return {};
|
|
26
26
|
}
|
|
27
27
|
async settled() { }
|
|
28
|
+
caughtUp() {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
28
31
|
read(message) {
|
|
29
32
|
this.take(message);
|
|
30
33
|
this.changed();
|
|
@@ -177,6 +180,7 @@ class ClaudeWork extends Work {
|
|
|
177
180
|
}
|
|
178
181
|
}
|
|
179
182
|
class CodexWork extends Work {
|
|
183
|
+
tapped;
|
|
180
184
|
threads = new Map();
|
|
181
185
|
queues = new Map();
|
|
182
186
|
goals = new Set();
|
|
@@ -184,6 +188,7 @@ class CodexWork extends Work {
|
|
|
184
188
|
hooks = new Set();
|
|
185
189
|
starting = new Set();
|
|
186
190
|
settling = [];
|
|
191
|
+
waiting = [];
|
|
187
192
|
memories = null;
|
|
188
193
|
lost = false;
|
|
189
194
|
server = null;
|
|
@@ -193,6 +198,10 @@ class CodexWork extends Work {
|
|
|
193
198
|
heard = 0;
|
|
194
199
|
proving = -1;
|
|
195
200
|
proven = -1;
|
|
201
|
+
constructor(changed, tapped) {
|
|
202
|
+
super(changed);
|
|
203
|
+
this.tapped = tapped;
|
|
204
|
+
}
|
|
196
205
|
async open(cli) {
|
|
197
206
|
this.path = join(socketDirectory(), `${randomUUID()}.sock`);
|
|
198
207
|
this.server = createServer((socket) => this.connected(socket));
|
|
@@ -210,6 +219,14 @@ class CodexWork extends Work {
|
|
|
210
219
|
super.take(message);
|
|
211
220
|
this.heard++;
|
|
212
221
|
}
|
|
222
|
+
caughtUp() {
|
|
223
|
+
if (this.lost || this.socket === null)
|
|
224
|
+
return null;
|
|
225
|
+
const { promise, resolve } = Promise.withResolvers();
|
|
226
|
+
this.waiting.push({ heard: this.heard, resolve });
|
|
227
|
+
this.prove();
|
|
228
|
+
return promise;
|
|
229
|
+
}
|
|
213
230
|
busy() {
|
|
214
231
|
if (super.busy() ||
|
|
215
232
|
this.lost ||
|
|
@@ -259,6 +276,7 @@ class CodexWork extends Work {
|
|
|
259
276
|
}
|
|
260
277
|
lose() {
|
|
261
278
|
this.lost = true;
|
|
279
|
+
this.release();
|
|
262
280
|
this.changed();
|
|
263
281
|
}
|
|
264
282
|
prove() {
|
|
@@ -267,6 +285,10 @@ class CodexWork extends Work {
|
|
|
267
285
|
this.proving = this.heard;
|
|
268
286
|
this.socket.write(`${JSON.stringify({ jsonrpc: '2.0', id: `${SYNC}${this.heard}`, method: 'house-kit/sync' })}\n`);
|
|
269
287
|
}
|
|
288
|
+
release() {
|
|
289
|
+
while (this.waiting[0] !== undefined && (this.lost || this.waiting[0].heard <= this.proven))
|
|
290
|
+
this.waiting.shift().resolve();
|
|
291
|
+
}
|
|
270
292
|
settle() {
|
|
271
293
|
if (this.starting.size === 0)
|
|
272
294
|
for (const resolve of this.settling.splice(0))
|
|
@@ -274,6 +296,8 @@ class CodexWork extends Work {
|
|
|
274
296
|
}
|
|
275
297
|
stream(message, socket) {
|
|
276
298
|
const params = message.params;
|
|
299
|
+
if (message.method !== undefined)
|
|
300
|
+
this.tapped(message);
|
|
277
301
|
switch (message.method) {
|
|
278
302
|
case 'thread/status/changed':
|
|
279
303
|
this.threads.set(params.threadId, params.status.type === 'active' && params.status.activeFlags.length === 0);
|
|
@@ -319,6 +343,7 @@ class CodexWork extends Work {
|
|
|
319
343
|
answered(message) {
|
|
320
344
|
if (typeof message.id === 'string' && message.id.startsWith(SYNC)) {
|
|
321
345
|
this.proven = Number(message.id.slice(SYNC.length));
|
|
346
|
+
this.release();
|
|
322
347
|
}
|
|
323
348
|
else if (typeof message.id === 'string' && message.id.startsWith(QUEUE_LIST)) {
|
|
324
349
|
const asked = Number(message.id.slice(QUEUE_LIST.length));
|
|
@@ -337,10 +362,10 @@ class GrokWork extends Work {
|
|
|
337
362
|
return true;
|
|
338
363
|
}
|
|
339
364
|
}
|
|
340
|
-
export function workFor(kind, cwd, changed) {
|
|
365
|
+
export function workFor(kind, cwd, changed, tapped) {
|
|
341
366
|
if (kind === 'claude-agent-acp')
|
|
342
367
|
return new ClaudeWork(cwd, changed);
|
|
343
368
|
if (kind === 'codex-acp')
|
|
344
|
-
return new CodexWork(changed);
|
|
369
|
+
return new CodexWork(changed, tapped);
|
|
345
370
|
return new GrokWork(changed);
|
|
346
371
|
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { cp, lstat, mkdir, readdir, readFile, rename, rm, rmdir, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
export async function present(path) {
|
|
4
|
+
try {
|
|
5
|
+
return await lstat(path);
|
|
6
|
+
}
|
|
7
|
+
catch (error) {
|
|
8
|
+
if (error.code === 'ENOENT')
|
|
9
|
+
return null;
|
|
10
|
+
throw error;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
async function listed(path) {
|
|
14
|
+
const entries = await readdir(path, { recursive: true, withFileTypes: true });
|
|
15
|
+
const shown = await Promise.all(entries.map(async (entry) => {
|
|
16
|
+
const at = join(entry.parentPath, entry.name);
|
|
17
|
+
return `${at.slice(path.length)} ${entry.isFile() ? (await lstat(at)).size : entry.isDirectory() ? 'folder' : 'link'}`;
|
|
18
|
+
}));
|
|
19
|
+
return shown.sort();
|
|
20
|
+
}
|
|
21
|
+
export async function moved(source, target) {
|
|
22
|
+
try {
|
|
23
|
+
await rename(source, target);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
if (error.code !== 'EXDEV')
|
|
28
|
+
throw error;
|
|
29
|
+
}
|
|
30
|
+
const copy = `${target}.moving`;
|
|
31
|
+
await rm(copy, { recursive: true, force: true });
|
|
32
|
+
try {
|
|
33
|
+
await cp(source, copy, { recursive: true, preserveTimestamps: true, verbatimSymlinks: true });
|
|
34
|
+
const folder = (await lstat(source)).isDirectory();
|
|
35
|
+
if (folder && JSON.stringify(await listed(source)) !== JSON.stringify(await listed(copy))) {
|
|
36
|
+
throw new Error(`${source} could not be copied to ${target} whole`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
await rm(copy, { recursive: true, force: true });
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
await rename(copy, target);
|
|
44
|
+
await rm(source, { recursive: true, force: true });
|
|
45
|
+
}
|
|
46
|
+
export async function keptName(path) {
|
|
47
|
+
for (let count = 1;; count++) {
|
|
48
|
+
const name = `${path} (kept)${count === 1 ? '' : ` ${count}`}`;
|
|
49
|
+
if ((await present(name)) === null)
|
|
50
|
+
return name;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
export async function merged(from, to, placed = () => 'moves') {
|
|
54
|
+
const found = await present(from);
|
|
55
|
+
if (found === null || !found.isDirectory())
|
|
56
|
+
return;
|
|
57
|
+
await mkdir(to, { recursive: true, mode: 0o700 });
|
|
58
|
+
for (const entry of await readdir(from, { withFileTypes: true })) {
|
|
59
|
+
const source = join(from, entry.name);
|
|
60
|
+
const placement = placed(source, entry);
|
|
61
|
+
if (placement === 'stays')
|
|
62
|
+
continue;
|
|
63
|
+
const target = join(to, entry.name);
|
|
64
|
+
const held = await present(target);
|
|
65
|
+
if (held === null && placement === 'moves')
|
|
66
|
+
await moved(source, target);
|
|
67
|
+
else if (entry.isDirectory() && (held === null || held.isDirectory()))
|
|
68
|
+
await merged(source, target, placed);
|
|
69
|
+
else
|
|
70
|
+
await rm(source, { recursive: true, force: true });
|
|
71
|
+
}
|
|
72
|
+
await removeFolder(from);
|
|
73
|
+
}
|
|
74
|
+
export async function removeFolder(path) {
|
|
75
|
+
await rmdir(path).catch((error) => {
|
|
76
|
+
if (error.code !== 'ENOTEMPTY' && error.code !== 'ENOENT')
|
|
77
|
+
throw error;
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
export function within(path, folder) {
|
|
81
|
+
return path === folder || path.startsWith(`${folder}/`);
|
|
82
|
+
}
|
|
83
|
+
function rewritten(value, from, to, kept) {
|
|
84
|
+
if (typeof value === 'string') {
|
|
85
|
+
if (kept.some((folder) => within(value, folder)) || (within(to, from) && within(value, to)) || !within(value, from))
|
|
86
|
+
return value;
|
|
87
|
+
return `${to}${value.slice(from.length)}`;
|
|
88
|
+
}
|
|
89
|
+
if (Array.isArray(value))
|
|
90
|
+
return value.map((item) => rewritten(item, from, to, kept));
|
|
91
|
+
if (typeof value === 'object' && value !== null) {
|
|
92
|
+
return Object.fromEntries(Object.entries(value).map(([name, held]) => [name, rewritten(held, from, to, kept)]));
|
|
93
|
+
}
|
|
94
|
+
return value;
|
|
95
|
+
}
|
|
96
|
+
export function rerooted(value, from, to) {
|
|
97
|
+
return rewritten(value, from, to, []);
|
|
98
|
+
}
|
|
99
|
+
export async function followRoot(records, from, to, kept = []) {
|
|
100
|
+
if (from === to)
|
|
101
|
+
return;
|
|
102
|
+
for (const name of await readdir(records).catch(() => [])) {
|
|
103
|
+
if (!name.endsWith('.json'))
|
|
104
|
+
continue;
|
|
105
|
+
const path = join(records, name);
|
|
106
|
+
const text = await readFile(path, 'utf8');
|
|
107
|
+
const next = `${JSON.stringify(rewritten(JSON.parse(text), from, to, kept))}\n`;
|
|
108
|
+
if (next.trim() === text.trim())
|
|
109
|
+
continue;
|
|
110
|
+
await writeFile(`${path}.new`, next, { mode: 0o600 });
|
|
111
|
+
await rename(`${path}.new`, path);
|
|
112
|
+
}
|
|
113
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentshouse/kit",
|
|
3
|
-
"version": "0.2.1-
|
|
3
|
+
"version": "0.2.1-cf2c570b41f24",
|
|
4
4
|
"description": "Kit connects an Environment to agents.house.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -19,20 +19,23 @@
|
|
|
19
19
|
"bootstrap-manifest": "node scripts/bootstrap-manifest.mjs",
|
|
20
20
|
"build": "tsc -p tsconfig.build.json",
|
|
21
21
|
"engine": "mkdir -p tmp/engine && docker run --rm -v \"$PWD:/kit\" -w /kit alpine:3.24@sha256:294b683cb724975bec92580e1e685676bd4b50bda910ddb8c51d4cabeaec77e6 sh scripts/engine.sh tmp/engine",
|
|
22
|
-
"follow-skills": "node scripts/follow-skills.mjs",
|
|
22
|
+
"follow-skills-and-kit-wire": "node scripts/follow-skills-and-kit-wire.mjs",
|
|
23
23
|
"release-files": "node scripts/release-files.mjs",
|
|
24
24
|
"test": "tsc -p tsconfig.json && vitest run"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@agentclientprotocol/sdk": "2.0
|
|
28
|
-
"@agentshouse/
|
|
29
|
-
"@agentshouse/
|
|
27
|
+
"@agentclientprotocol/sdk": "2.4.0",
|
|
28
|
+
"@agentshouse/kit-wire": "0.1.0-ce269f317b0cb",
|
|
29
|
+
"@agentshouse/session-content": "0.1.0-c560e48c9bea3",
|
|
30
|
+
"@agentshouse/skills": "0.1.0-cc915e7509460",
|
|
30
31
|
"@lydell/node-pty": "1.2.0-beta.15",
|
|
32
|
+
"micromark": "4.0.2",
|
|
33
|
+
"smol-toml": "1.9.1",
|
|
31
34
|
"yaml": "2.9.1"
|
|
32
35
|
},
|
|
33
36
|
"peerDependencies": {
|
|
34
|
-
"@agentclientprotocol/claude-agent-acp": "0.
|
|
35
|
-
"@agentclientprotocol/codex-acp": "2.
|
|
37
|
+
"@agentclientprotocol/claude-agent-acp": "0.100.0",
|
|
38
|
+
"@agentclientprotocol/codex-acp": "2.5.0"
|
|
36
39
|
},
|
|
37
40
|
"peerDependenciesMeta": {
|
|
38
41
|
"@agentclientprotocol/claude-agent-acp": {
|
|
@@ -47,7 +50,8 @@
|
|
|
47
50
|
"@types/ws": "8.18.2",
|
|
48
51
|
"typescript": "7.0.2",
|
|
49
52
|
"vitest": "5.0.5",
|
|
50
|
-
"ws": "8.22.0"
|
|
53
|
+
"ws": "8.22.0",
|
|
54
|
+
"zod": "4.6.7"
|
|
51
55
|
},
|
|
52
56
|
"packageManager": "npm@11.19.1",
|
|
53
57
|
"engines": {
|
package/dist/authority-main.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { HouseRefusal, post } from './api.js';
|
|
2
|
-
import { readEnrolment } from './home.js';
|
|
3
|
-
import { proxyUnlessRelayed } from './relay.js';
|
|
4
|
-
function unanswered(error) {
|
|
5
|
-
return error instanceof HouseRefusal ? error.status >= 500 : error instanceof TypeError && error.message === 'fetch failed';
|
|
6
|
-
}
|
|
7
|
-
proxyUnlessRelayed();
|
|
8
|
-
try {
|
|
9
|
-
const { house, credential } = (await readEnrolment());
|
|
10
|
-
try {
|
|
11
|
-
await post(house, '/kit/agents/desired', {}, credential);
|
|
12
|
-
}
|
|
13
|
-
catch (error) {
|
|
14
|
-
if (!unanswered(error))
|
|
15
|
-
throw error;
|
|
16
|
-
process.stderr.write(`kit: House did not answer, so the stored credential stands: ${error.message}\n`);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
catch (error) {
|
|
20
|
-
process.stderr.write(`kit: ${error.message}\n`);
|
|
21
|
-
process.exitCode = 1;
|
|
22
|
-
}
|
package/dist/chatgpt.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { parseArgs } from 'node:util';
|
|
2
|
-
import { placeAppGit } from './app-git.js';
|
|
3
|
-
import { kitHome, readOwnAgent, writeOwnAgent } from './home.js';
|
|
4
|
-
import { accepted, DEFAULT_HOUSE } from './login.js';
|
|
5
|
-
const KEY_SOURCE = 'New key for a script on Connections';
|
|
6
|
-
const USAGE = `usage: kit chatgpt --key <key> [--house <origin>]
|
|
7
|
-
--key <key> a key from ${KEY_SOURCE}
|
|
8
|
-
--house <origin> the House of the key, ${DEFAULT_HOUSE} unless one is stored
|
|
9
|
-
`;
|
|
10
|
-
export async function chatgpt(argv) {
|
|
11
|
-
const { values } = parseArgs({
|
|
12
|
-
args: argv,
|
|
13
|
-
options: { key: { type: 'string' }, house: { type: 'string' }, help: { type: 'boolean', default: false } },
|
|
14
|
-
});
|
|
15
|
-
if (values.help) {
|
|
16
|
-
process.stdout.write(USAGE);
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
if (values.key === undefined)
|
|
20
|
-
throw new Error(`pass --key with a key from ${KEY_SOURCE}`);
|
|
21
|
-
const before = await readOwnAgent();
|
|
22
|
-
const house = values.house ?? before?.house ?? DEFAULT_HOUSE;
|
|
23
|
-
if (!(await accepted(house, values.key)))
|
|
24
|
-
throw new Error(`${house} does not accept this key; pass one from ${KEY_SOURCE}`);
|
|
25
|
-
const relay = process.env.HOUSE_KIT_RELAY || undefined;
|
|
26
|
-
await writeOwnAgent({ house, ...(relay === undefined ? {} : { relay }), credential: values.key });
|
|
27
|
-
await placeAppGit(await readOwnAgent()).catch((error) => process.stderr.write(`kit: ${error.message}\n`));
|
|
28
|
-
if (before !== null && before.credential !== values.key) {
|
|
29
|
-
process.stdout.write('This replaced the key this Kit home held; give each session its own HOUSE_KIT_HOME to keep its own key.\n');
|
|
30
|
-
}
|
|
31
|
-
process.stdout.write(`house now calls ${house} as you, with the key kept in ${kitHome()}.\n`);
|
|
32
|
-
}
|
package/dist/configure-main.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { readConfiguration, writeConfiguration } from './home.js';
|
|
2
|
-
const skills = !process.argv.slice(2).includes('--no-skills');
|
|
3
|
-
const stored = await readConfiguration();
|
|
4
|
-
await writeConfiguration({ skills });
|
|
5
|
-
if (stored.skills !== skills)
|
|
6
|
-
process.stdout.write('changed\n');
|
package/dist/enrol-main.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { readFileSync } from 'node:fs';
|
|
2
|
-
import { writeEnrolment } from './home.js';
|
|
3
|
-
const [house, environment] = process.argv.slice(2);
|
|
4
|
-
const relay = process.env.HOUSE_KIT_RELAY || undefined;
|
|
5
|
-
await writeEnrolment({
|
|
6
|
-
house: house,
|
|
7
|
-
...(relay === undefined ? {} : { relay }),
|
|
8
|
-
environment: environment,
|
|
9
|
-
credential: readFileSync(0, 'utf8').trim(),
|
|
10
|
-
});
|
package/dist/git-main.js
DELETED
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { spawn, spawnSync } from 'node:child_process';
|
|
3
|
-
import { accessSync, constants, realpathSync, statSync } from 'node:fs';
|
|
4
|
-
import { request } from 'node:http';
|
|
5
|
-
import { constants as system } from 'node:os';
|
|
6
|
-
import { delimiter, dirname, join } from 'node:path';
|
|
7
|
-
import { localCopies } from './git.js';
|
|
8
|
-
import { kitHome } from './home.js';
|
|
9
|
-
const VALUED = new Set(['-C', '-c', '--git-dir', '--work-tree', '--namespace', '--config-env', '--attr-source', '--super-prefix']);
|
|
10
|
-
const READS = new Set([
|
|
11
|
-
'blame',
|
|
12
|
-
'branch',
|
|
13
|
-
'cat-file',
|
|
14
|
-
'check-ignore',
|
|
15
|
-
'config',
|
|
16
|
-
'describe',
|
|
17
|
-
'diff',
|
|
18
|
-
'fetch',
|
|
19
|
-
'for-each-ref',
|
|
20
|
-
'grep',
|
|
21
|
-
'help',
|
|
22
|
-
'log',
|
|
23
|
-
'ls-files',
|
|
24
|
-
'ls-tree',
|
|
25
|
-
'reflog',
|
|
26
|
-
'remote',
|
|
27
|
-
'rev-list',
|
|
28
|
-
'rev-parse',
|
|
29
|
-
'shortlog',
|
|
30
|
-
'show',
|
|
31
|
-
'show-ref',
|
|
32
|
-
'status',
|
|
33
|
-
'tag',
|
|
34
|
-
'version',
|
|
35
|
-
]);
|
|
36
|
-
const RELAYED = ['SIGINT', 'SIGTERM', 'SIGHUP', 'SIGQUIT'];
|
|
37
|
-
function nativeGit() {
|
|
38
|
-
const shim = join(kitHome(), 'shim');
|
|
39
|
-
for (const directory of (process.env.PATH ?? '').split(delimiter)) {
|
|
40
|
-
if (directory === '')
|
|
41
|
-
continue;
|
|
42
|
-
try {
|
|
43
|
-
if (realpathSync(directory) === realpathSync(shim))
|
|
44
|
-
continue;
|
|
45
|
-
const candidate = join(directory, 'git');
|
|
46
|
-
if (!statSync(candidate).isFile())
|
|
47
|
-
continue;
|
|
48
|
-
accessSync(candidate, constants.X_OK);
|
|
49
|
-
return candidate;
|
|
50
|
-
}
|
|
51
|
-
catch { }
|
|
52
|
-
}
|
|
53
|
-
return null;
|
|
54
|
-
}
|
|
55
|
-
function captured(git, args) {
|
|
56
|
-
const ran = spawnSync(git, args, {
|
|
57
|
-
stdio: ['ignore', 'pipe', 'ignore'],
|
|
58
|
-
maxBuffer: Infinity,
|
|
59
|
-
env: { ...process.env, LC_ALL: 'C' },
|
|
60
|
-
});
|
|
61
|
-
return ran.status === 0 ? ran.stdout.toString('utf8') : null;
|
|
62
|
-
}
|
|
63
|
-
function delegated(git, args) {
|
|
64
|
-
return new Promise((resolve) => {
|
|
65
|
-
const child = spawn(git, args, { stdio: 'inherit' });
|
|
66
|
-
const relay = (signal) => child.kill(signal);
|
|
67
|
-
for (const signal of RELAYED)
|
|
68
|
-
process.on(signal, relay);
|
|
69
|
-
const settle = (outcome) => {
|
|
70
|
-
for (const signal of RELAYED)
|
|
71
|
-
process.off(signal, relay);
|
|
72
|
-
resolve(outcome);
|
|
73
|
-
};
|
|
74
|
-
child.once('error', (error) => {
|
|
75
|
-
process.stderr.write(`git: ${error.message}\n`);
|
|
76
|
-
settle({ status: 127, signal: null });
|
|
77
|
-
});
|
|
78
|
-
child.once('close', (status, signal) => settle({ status, signal }));
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
function staged(listing) {
|
|
82
|
-
const entries = new Map();
|
|
83
|
-
for (const record of (listing ?? '').split('\0')) {
|
|
84
|
-
const tab = record.indexOf('\t');
|
|
85
|
-
if (tab >= 0)
|
|
86
|
-
entries.set(record.slice(tab + 1), record.slice(0, tab).split(' ')[1]);
|
|
87
|
-
}
|
|
88
|
-
return entries;
|
|
89
|
-
}
|
|
90
|
-
function moved(planned, before, after) {
|
|
91
|
-
const moves = [];
|
|
92
|
-
for (const line of planned.split('\n')) {
|
|
93
|
-
if (!line.startsWith('Renaming '))
|
|
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
|
-
}
|
|
105
|
-
return moves;
|
|
106
|
-
}
|
|
107
|
-
function reported(socketPath, body) {
|
|
108
|
-
return new Promise((resolve) => {
|
|
109
|
-
const sent = request({ socketPath, path: '/git/observed', method: 'POST' }, (answer) => {
|
|
110
|
-
answer.resume();
|
|
111
|
-
answer.on('end', resolve);
|
|
112
|
-
});
|
|
113
|
-
sent.on('error', () => resolve());
|
|
114
|
-
sent.end(JSON.stringify(body));
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
async function observed(git, args) {
|
|
118
|
-
let index = 0;
|
|
119
|
-
while (index < args.length && args[index].startsWith('-'))
|
|
120
|
-
index += VALUED.has(args[index]) ? 2 : 1;
|
|
121
|
-
const globals = args.slice(0, index);
|
|
122
|
-
const name = args[index];
|
|
123
|
-
const bridge = process.env.HOUSE_BRIDGE;
|
|
124
|
-
if (bridge === undefined || name === undefined || READS.has(name))
|
|
125
|
-
return delegated(git, args);
|
|
126
|
-
const located = captured(git, [...globals, 'rev-parse', '--path-format=absolute', '--git-common-dir', '--show-toplevel']);
|
|
127
|
-
const [common, worktree] = located?.split('\n') ?? [];
|
|
128
|
-
if (common === undefined || worktree === undefined || !dirname(common).startsWith(`${localCopies()}/`)) {
|
|
129
|
-
return delegated(git, args);
|
|
130
|
-
}
|
|
131
|
-
const listing = [...globals, '-C', worktree, 'ls-files', '--stage', '-z'];
|
|
132
|
-
const before = name === 'mv' ? staged(captured(git, listing)) : null;
|
|
133
|
-
const planned = name === 'mv' ? (captured(git, [...globals, 'mv', '--dry-run', ...args.slice(index + 1)]) ?? '') : '';
|
|
134
|
-
const outcome = await delegated(git, args);
|
|
135
|
-
const moves = before !== null && outcome.status === 0 ? moved(planned, before, staged(captured(git, listing))) : [];
|
|
136
|
-
await reported(bridge, { common, worktree, moves });
|
|
137
|
-
return outcome;
|
|
138
|
-
}
|
|
139
|
-
const git = nativeGit();
|
|
140
|
-
if (git === null) {
|
|
141
|
-
process.stderr.write('git: no installed Git found on PATH\n');
|
|
142
|
-
process.exitCode = 127;
|
|
143
|
-
}
|
|
144
|
-
else {
|
|
145
|
-
observed(git, process.argv.slice(2)).then(({ status, signal }) => {
|
|
146
|
-
if (signal === null) {
|
|
147
|
-
process.exitCode = status ?? 1;
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
process.exitCode = 128 + system.signals[signal];
|
|
151
|
-
process.kill(process.pid, signal);
|
|
152
|
-
});
|
|
153
|
-
}
|
package/dist/parts.js
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
export class Parts {
|
|
2
|
-
parts = [];
|
|
3
|
-
context = null;
|
|
4
|
-
emit;
|
|
5
|
-
made = [];
|
|
6
|
-
events = 0;
|
|
7
|
-
writing = null;
|
|
8
|
-
counting = null;
|
|
9
|
-
planned = null;
|
|
10
|
-
constructor(emit) {
|
|
11
|
-
this.emit = emit;
|
|
12
|
-
}
|
|
13
|
-
write(type, id, text) {
|
|
14
|
-
if (text === '')
|
|
15
|
-
return;
|
|
16
|
-
if (this.writing?.type === type && this.writing.id === id) {
|
|
17
|
-
this.parts[this.writing.index].text += text;
|
|
18
|
-
this.emit({ op: 'append', index: this.writing.index, text });
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
this.writing = { type, id, index: this.start({ type, text }) };
|
|
22
|
-
}
|
|
23
|
-
command() {
|
|
24
|
-
if (this.counting === null) {
|
|
25
|
-
this.counting = this.start({ type: 'commands', count: 1 });
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
const part = this.parts[this.counting];
|
|
29
|
-
part.count++;
|
|
30
|
-
this.emit({ op: 'count', index: this.counting, count: part.count });
|
|
31
|
-
}
|
|
32
|
-
start(part) {
|
|
33
|
-
this.writing = null;
|
|
34
|
-
this.counting = null;
|
|
35
|
-
return this.add(part, ++this.events);
|
|
36
|
-
}
|
|
37
|
-
reserve() {
|
|
38
|
-
this.writing = null;
|
|
39
|
-
this.counting = null;
|
|
40
|
-
return ++this.events;
|
|
41
|
-
}
|
|
42
|
-
arrive(part, reserved) {
|
|
43
|
-
this.add(part, reserved);
|
|
44
|
-
}
|
|
45
|
-
done(index, result) {
|
|
46
|
-
const part = this.parts[index];
|
|
47
|
-
part.status = 'done';
|
|
48
|
-
part.result = result;
|
|
49
|
-
this.emit({ op: 'status', index, status: 'done', result });
|
|
50
|
-
}
|
|
51
|
-
plan(entries) {
|
|
52
|
-
if (this.planned === null) {
|
|
53
|
-
this.planned = this.start({ type: 'plan', entries });
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
this.parts[this.planned].entries = entries;
|
|
57
|
-
this.emit({ op: 'plan', index: this.planned, entries });
|
|
58
|
-
}
|
|
59
|
-
measure(context) {
|
|
60
|
-
this.context = context;
|
|
61
|
-
this.emit({ op: 'context', ...context });
|
|
62
|
-
}
|
|
63
|
-
saved() {
|
|
64
|
-
return this.parts
|
|
65
|
-
.map((part, index) => ({ part, made: this.made[index] }))
|
|
66
|
-
.sort((a, b) => a.made - b.made)
|
|
67
|
-
.map(({ part }) => part);
|
|
68
|
-
}
|
|
69
|
-
operations() {
|
|
70
|
-
return [
|
|
71
|
-
...this.parts.map((part, index) => ({ op: 'start', index, part })),
|
|
72
|
-
...(this.context === null ? [] : [{ op: 'context', ...this.context }]),
|
|
73
|
-
];
|
|
74
|
-
}
|
|
75
|
-
add(part, made) {
|
|
76
|
-
this.parts.push(part);
|
|
77
|
-
this.made.push(made);
|
|
78
|
-
const index = this.parts.length - 1;
|
|
79
|
-
this.emit({ op: 'start', index, part });
|
|
80
|
-
return index;
|
|
81
|
-
}
|
|
82
|
-
}
|
package/dist/service-main.js
DELETED
package/dist/service.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { spawnSync } from 'node:child_process';
|
|
2
|
-
import { existsSync, realpathSync } from 'node:fs';
|
|
3
|
-
import { resolve } from 'node:path';
|
|
4
|
-
import { kitHome } from './home.js';
|
|
5
|
-
const UNIT = 'house-kit.service';
|
|
6
|
-
// launchctl and systemctl answer at once, so ten seconds only bounds a stuck service manager.
|
|
7
|
-
const MANAGER_MS = 10_000;
|
|
8
|
-
function manage(command, args) {
|
|
9
|
-
return spawnSync(command, args, { encoding: 'utf8', timeout: MANAGER_MS });
|
|
10
|
-
}
|
|
11
|
-
function start(command, args) {
|
|
12
|
-
const started = manage(command, args);
|
|
13
|
-
if (started.status === 0)
|
|
14
|
-
return;
|
|
15
|
-
const cause = started.error?.message ?? (started.stderr.trim() || `${command} exited with ${started.status ?? 'a signal'}`);
|
|
16
|
-
throw new Error(`the Kit service could not be started: ${cause}`);
|
|
17
|
-
}
|
|
18
|
-
function physical(path) {
|
|
19
|
-
return existsSync(path) ? realpathSync(path) : resolve(path);
|
|
20
|
-
}
|
|
21
|
-
function systemdHome(environment) {
|
|
22
|
-
for (const [, quoted, bare] of environment.matchAll(/"((?:[^"\\]|\\.)*)"|(\S+)/g)) {
|
|
23
|
-
const assignment = bare ?? quoted.replace(/\\(.)/g, '$1');
|
|
24
|
-
if (assignment.startsWith('HOUSE_KIT_HOME='))
|
|
25
|
-
return assignment.slice('HOUSE_KIT_HOME='.length);
|
|
26
|
-
}
|
|
27
|
-
return undefined;
|
|
28
|
-
}
|
|
29
|
-
function runsThisHome(served) {
|
|
30
|
-
return served !== undefined && physical(served) === physical(kitHome());
|
|
31
|
-
}
|
|
32
|
-
export function startService() {
|
|
33
|
-
if (process.platform === 'darwin') {
|
|
34
|
-
const service = `gui/${process.getuid()}/house-kit`;
|
|
35
|
-
const printed = manage('launchctl', ['print', service]);
|
|
36
|
-
if (printed.status !== 0 || /^\tstate = running$/m.test(printed.stdout))
|
|
37
|
-
return false;
|
|
38
|
-
if (!runsThisHome(/^\t+HOUSE_KIT_HOME => (.+)$/m.exec(printed.stdout)?.[1]))
|
|
39
|
-
return false;
|
|
40
|
-
start('launchctl', ['kickstart', service]);
|
|
41
|
-
return true;
|
|
42
|
-
}
|
|
43
|
-
for (const scope of [['--user'], []]) {
|
|
44
|
-
if (manage('systemctl', [...scope, 'is-enabled', '--quiet', UNIT]).status !== 0)
|
|
45
|
-
continue;
|
|
46
|
-
const environment = manage('systemctl', [...scope, 'show', '--property=Environment', '--value', UNIT]).stdout;
|
|
47
|
-
if (!runsThisHome(systemdHome(environment)))
|
|
48
|
-
continue;
|
|
49
|
-
if (manage('systemctl', [...scope, 'is-active', '--quiet', UNIT]).status === 0)
|
|
50
|
-
return false;
|
|
51
|
-
start('systemctl', [...scope, 'start', UNIT]);
|
|
52
|
-
return true;
|
|
53
|
-
}
|
|
54
|
-
return false;
|
|
55
|
-
}
|
package/dist/translate.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { apply, parse, serialize } from '@agentshouse/mdmodel';
|
|
2
|
-
function same(left, right) {
|
|
3
|
-
return JSON.stringify(left) === JSON.stringify(right);
|
|
4
|
-
}
|
|
5
|
-
function applied(document, changes) {
|
|
6
|
-
const result = apply(document, changes);
|
|
7
|
-
return result.outcome === 'applied' ? serialize(result.document) : null;
|
|
8
|
-
}
|
|
9
|
-
function components(path, before, after, text) {
|
|
10
|
-
const edits = [];
|
|
11
|
-
const changes = [];
|
|
12
|
-
if (before.preamble !== after.preamble) {
|
|
13
|
-
edits.push({ op: 'replace_preamble', path, base: before.preamble, content: after.preamble });
|
|
14
|
-
changes.push({ kind: 'preamble', value: after.preamble, prior: before.preamble });
|
|
15
|
-
}
|
|
16
|
-
for (const name of new Set([...Object.keys(before.fields), ...Object.keys(after.fields)])) {
|
|
17
|
-
const prior = before.fields[name];
|
|
18
|
-
const value = after.fields[name];
|
|
19
|
-
if (same(prior, value))
|
|
20
|
-
continue;
|
|
21
|
-
if (value === undefined)
|
|
22
|
-
return null;
|
|
23
|
-
edits.push({ op: 'set_field', path, field: name, ...(prior === undefined ? {} : { base: prior }), value });
|
|
24
|
-
changes.push({ kind: 'field', name, value, prior });
|
|
25
|
-
}
|
|
26
|
-
for (const name of new Set([...Object.keys(before.sections), ...Object.keys(after.sections)])) {
|
|
27
|
-
const prior = before.sections[name];
|
|
28
|
-
const value = after.sections[name];
|
|
29
|
-
if (prior === value)
|
|
30
|
-
continue;
|
|
31
|
-
if (prior === undefined || value === undefined)
|
|
32
|
-
return null;
|
|
33
|
-
edits.push({ op: 'replace_section', path, section: name, base: prior, content: value });
|
|
34
|
-
changes.push({ kind: 'section', name, value, prior });
|
|
35
|
-
}
|
|
36
|
-
return edits.length > 0 && applied(before, changes) === text ? edits : null;
|
|
37
|
-
}
|
|
38
|
-
export function changed(path, file, base, before, after) {
|
|
39
|
-
if (!file.endsWith('.md'))
|
|
40
|
-
return [{ op: 'replace', path, base, content: after }];
|
|
41
|
-
const parsedBefore = parse(before, file);
|
|
42
|
-
const parsedAfter = parse(after, file);
|
|
43
|
-
const structured = parsedBefore.ok && parsedAfter.ok ? components(path, parsedBefore.document, parsedAfter.document, after) : null;
|
|
44
|
-
return structured ?? [{ op: 'replace', path, base, content: after }];
|
|
45
|
-
}
|