@agentshouse/kit 0.2.1-c681dfca497a8 → 0.2.1-c70284f7a7466
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 +16 -15
- package/dist/agents.js +51 -3
- package/dist/api.js +1 -1
- package/dist/app-git.js +10 -26
- package/dist/bootstrap.json +4 -4
- package/dist/bridge.js +2 -5
- package/dist/chatgpt.js +7 -1
- package/dist/clis.js +11 -1
- package/dist/conversations.js +98 -28
- package/dist/copies.js +50 -25
- package/dist/end.js +3 -2
- package/dist/events.js +4 -0
- package/dist/git.js +2 -3
- package/dist/home.js +31 -13
- package/dist/house-cli.js +291 -0
- package/dist/house-main.js +7 -289
- package/dist/instructions.js +4 -28
- package/dist/kit-cli.js +68 -0
- package/dist/kit-main.js +8 -67
- package/dist/login.js +33 -8
- package/dist/logout.js +0 -2
- package/dist/placement.js +2 -20
- package/dist/resident.js +51 -10
- package/dist/skills.js +71 -12
- package/dist/stream.js +58 -12
- package/dist/transcription.js +3 -3
- package/dist/work.js +3 -5
- package/how-we-work.md +2 -0
- package/package.json +1 -1
package/dist/conversations.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { client, } from '@agentclientprotocol/sdk';
|
|
1
|
+
import { client, RequestError, } from '@agentclientprotocol/sdk';
|
|
2
2
|
import { createHash, randomUUID } from 'node:crypto';
|
|
3
3
|
import { mkdir } from 'node:fs/promises';
|
|
4
4
|
import { join } from 'node:path';
|
|
@@ -6,7 +6,7 @@ import { unlessAborted } from './abort.js';
|
|
|
6
6
|
import { startAdapter } from './acp.js';
|
|
7
7
|
import { openBridge } from './bridge.js';
|
|
8
8
|
import { CLIS } from './clis.js';
|
|
9
|
-
import { readerFor } from './events.js';
|
|
9
|
+
import { answeredFailure, readerFor } from './events.js';
|
|
10
10
|
import { placeFiles, uploadBytes } from './files.js';
|
|
11
11
|
import { agentBase } from './home.js';
|
|
12
12
|
import { instructions } from './instructions.js';
|
|
@@ -16,17 +16,56 @@ import { holdSecretInput } from './secret-input.js';
|
|
|
16
16
|
import { createHowWeWork } from './skills.js';
|
|
17
17
|
import { transcribe } from './transcription.js';
|
|
18
18
|
import { workFor } from './work.js';
|
|
19
|
+
const SIGNED_OUT = RequestError.authRequired().code;
|
|
19
20
|
const KILLED = 'the conversation was killed';
|
|
21
|
+
const REFUSED = 'the CLI refused the prompt';
|
|
22
|
+
const NO_CONNECTION = "the Kit could not open this conversation's connection";
|
|
23
|
+
const NO_START = "the Agent's CLI did not start";
|
|
24
|
+
const NO_SESSION = "the Agent's CLI did not open a session";
|
|
25
|
+
const NO_RESUME = "the Agent's CLI could not resume this conversation";
|
|
26
|
+
const NO_SETTINGS = "the Agent's CLI refused the Agent's model, mode or effort";
|
|
27
|
+
class NotStarted extends Error {
|
|
28
|
+
}
|
|
29
|
+
async function step(reason, work) {
|
|
30
|
+
try {
|
|
31
|
+
return await work;
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
throw new NotStarted(reason, { cause: error });
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const EXIT_PLAN_MODE = {
|
|
38
|
+
parse(value) {
|
|
39
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
40
|
+
throw new Error('_x.ai/exit_plan_mode needs an object');
|
|
41
|
+
}
|
|
42
|
+
return value;
|
|
43
|
+
},
|
|
44
|
+
};
|
|
20
45
|
export const CONVERSATION_INPUTS = new Set(['open', 'message', 'interrupt', 'kill', 'option', 'answer']);
|
|
21
46
|
function causeOf(error) {
|
|
22
47
|
return error instanceof Error ? error.message : String(error);
|
|
23
48
|
}
|
|
49
|
+
function answeredWith(error) {
|
|
50
|
+
const signedOut = typeof error === 'object' && error !== null && error.code === SIGNED_OUT;
|
|
51
|
+
return { failure: signedOut ? 'signed_out' : 'error', cause: causeOf(error) };
|
|
52
|
+
}
|
|
53
|
+
function exitedWith(running, cause) {
|
|
54
|
+
return running.killed ? { failure: 'killed', cause: KILLED } : { failure: 'exited', cause };
|
|
55
|
+
}
|
|
24
56
|
function answerMessage(request, response) {
|
|
25
57
|
return `The User answered a question you asked earlier.\nQuestion: ${JSON.stringify(request)}\nAnswer: ${JSON.stringify(response)}`;
|
|
26
58
|
}
|
|
27
59
|
function logged(error) {
|
|
28
60
|
process.stderr.write(`kit: ${causeOf(error)}\n`);
|
|
29
61
|
}
|
|
62
|
+
function refusal(conversation, error) {
|
|
63
|
+
if (conversation.kills > 0)
|
|
64
|
+
return KILLED;
|
|
65
|
+
const cause = error instanceof NotStarted ? `${error.message}: ${causeOf(error.cause)}` : causeOf(error);
|
|
66
|
+
logged(new Error(`conversation ${conversation.id} did not start: ${cause}`));
|
|
67
|
+
return causeOf(error);
|
|
68
|
+
}
|
|
30
69
|
function marker(bridge) {
|
|
31
70
|
return `HOUSE_BRIDGE=${bridge.env.HOUSE_BRIDGE}`;
|
|
32
71
|
}
|
|
@@ -57,6 +96,7 @@ class Conversation {
|
|
|
57
96
|
subagents = new Map();
|
|
58
97
|
held = [];
|
|
59
98
|
opening = null;
|
|
99
|
+
prompted = null;
|
|
60
100
|
kills = 0;
|
|
61
101
|
killed = new AbortController();
|
|
62
102
|
interrupts = 0;
|
|
@@ -200,10 +240,10 @@ export class Conversations {
|
|
|
200
240
|
if (conversation.running !== null)
|
|
201
241
|
return {};
|
|
202
242
|
try {
|
|
203
|
-
return { provider_session_id: await this.start(conversation, await this.route(conversation, input.agent_id), null) };
|
|
243
|
+
return { provider_session_id: await this.start(conversation, await this.route(conversation, input.agent_id), null, true) };
|
|
204
244
|
}
|
|
205
245
|
catch (error) {
|
|
206
|
-
return { refused:
|
|
246
|
+
return { refused: refusal(conversation, error) };
|
|
207
247
|
}
|
|
208
248
|
}
|
|
209
249
|
async message(conversation, input) {
|
|
@@ -220,7 +260,7 @@ export class Conversations {
|
|
|
220
260
|
throw new Error(KILLED);
|
|
221
261
|
}
|
|
222
262
|
catch (error) {
|
|
223
|
-
return { ack: Promise.resolve({ refused: conversation
|
|
263
|
+
return { ack: Promise.resolve({ refused: refusal(conversation, error) }) };
|
|
224
264
|
}
|
|
225
265
|
return {
|
|
226
266
|
ack: new Promise((settle) => {
|
|
@@ -243,13 +283,17 @@ export class Conversations {
|
|
|
243
283
|
async send(conversation, waiting) {
|
|
244
284
|
const { input } = waiting;
|
|
245
285
|
let ack = {};
|
|
286
|
+
let started = false;
|
|
246
287
|
const prompt = [];
|
|
247
288
|
try {
|
|
248
289
|
if (conversation.running === null) {
|
|
249
|
-
const
|
|
250
|
-
const
|
|
251
|
-
|
|
252
|
-
|
|
290
|
+
const stored = conversation.session ?? input.provider_session_id;
|
|
291
|
+
const empty = input.first === true && conversation.prompted !== stored;
|
|
292
|
+
started = (await this.start(conversation, waiting.route, stored, empty)) !== stored;
|
|
293
|
+
}
|
|
294
|
+
const session = conversation.running.sessionId;
|
|
295
|
+
if (started || (input.first === true && session !== input.provider_session_id)) {
|
|
296
|
+
ack = { provider_session_id: session };
|
|
253
297
|
}
|
|
254
298
|
if (input.first === true) {
|
|
255
299
|
prompt.push({
|
|
@@ -261,11 +305,11 @@ export class Conversations {
|
|
|
261
305
|
throw new Error(KILLED);
|
|
262
306
|
}
|
|
263
307
|
catch (error) {
|
|
264
|
-
if (
|
|
308
|
+
if (started) {
|
|
265
309
|
conversation.session = null;
|
|
266
310
|
await this.kill(conversation);
|
|
267
311
|
}
|
|
268
|
-
waiting.settle({ refused: conversation
|
|
312
|
+
waiting.settle({ refused: refusal(conversation, error) });
|
|
269
313
|
return;
|
|
270
314
|
}
|
|
271
315
|
this.prompt(conversation, [...prompt, ...waiting.content]);
|
|
@@ -343,14 +387,15 @@ export class Conversations {
|
|
|
343
387
|
}
|
|
344
388
|
return route;
|
|
345
389
|
}
|
|
346
|
-
async start(conversation, route, sessionId) {
|
|
390
|
+
async start(conversation, route, sessionId, empty) {
|
|
347
391
|
const reader = readerFor(route.kind);
|
|
348
392
|
reader.session = sessionId;
|
|
349
393
|
const app = client({ name: '@agentshouse/kit' })
|
|
350
394
|
.onRequest('session/request_permission', ({ params, signal }) => this.ask(conversation, 'session/request_permission', params, false, signal))
|
|
351
|
-
.onRequest('elicitation/create', ({ params, signal }) => this.ask(conversation, 'elicitation/create', params, asksSecret(params), signal))
|
|
395
|
+
.onRequest('elicitation/create', ({ params, signal }) => this.ask(conversation, 'elicitation/create', params, asksSecret(params), signal))
|
|
396
|
+
.onRequest('_x.ai/exit_plan_mode', EXIT_PLAN_MODE, ({ params, signal }) => this.ask(conversation, '_x.ai/exit_plan_mode', params, false, signal));
|
|
352
397
|
const cli = await unlessAborted(this.kit.agents.cli(route.kind), conversation.killed.signal);
|
|
353
|
-
const bridge = await openBridge(this.kit.house, this.kit.copies, conversation.id, conversation.killed.signal);
|
|
398
|
+
const bridge = await step(NO_CONNECTION, openBridge(this.kit.house, this.kit.copies, conversation.id, conversation.killed.signal));
|
|
354
399
|
if (conversation.kills > 0) {
|
|
355
400
|
bridge.close();
|
|
356
401
|
throw new Error(KILLED);
|
|
@@ -361,24 +406,24 @@ export class Conversations {
|
|
|
361
406
|
try {
|
|
362
407
|
await unlessAborted(createHowWeWork(bridge), conversation.killed.signal);
|
|
363
408
|
await CLIS[route.kind].allowHouse(bridge.env.PATH);
|
|
364
|
-
const
|
|
409
|
+
const streamed = await step(NO_CONNECTION, work.open(cli));
|
|
410
|
+
const adapter = await step(NO_START, startAdapter(route.kind, cli, route.working_directory, app, (message) => {
|
|
365
411
|
work.read(message);
|
|
366
412
|
this.read(conversation, reader, message);
|
|
367
|
-
}, { ...bridge.env, ...
|
|
413
|
+
}, { ...bridge.env, ...streamed }, undefined, scope));
|
|
368
414
|
void adapter.exited.then(() => bridge.close());
|
|
369
415
|
const agent = adapter.connection.agent;
|
|
370
416
|
const cwd = route.working_directory;
|
|
371
417
|
const _meta = CLIS[route.kind].sessionMeta(bridge.env.HOUSE_BRIDGE, conversation.id);
|
|
372
|
-
const
|
|
373
|
-
|
|
374
|
-
: { ...(await agent.request('session/resume', { sessionId, cwd, mcpServers: [], _meta })), sessionId };
|
|
418
|
+
const resumed = sessionId === null ? null : await this.resume(conversation, route.kind, adapter, { sessionId, cwd, mcpServers: [], _meta }, empty);
|
|
419
|
+
const opened = resumed ?? (await step(NO_SESSION, agent.request('session/new', { cwd, mcpServers: [], _meta })));
|
|
375
420
|
reader.session = opened.sessionId;
|
|
376
|
-
if (sessionId
|
|
421
|
+
if (opened.sessionId !== sessionId && CLIS[route.kind].renames) {
|
|
377
422
|
const prompt = [{ type: 'text', text: `/rename ${conversation.id}` }];
|
|
378
|
-
await agent.request('session/prompt', { sessionId: opened.sessionId, prompt });
|
|
423
|
+
await step(NO_SESSION, agent.request('session/prompt', { sessionId: opened.sessionId, prompt }));
|
|
379
424
|
}
|
|
380
425
|
const running = { adapter, bridge, sessionId: opened.sessionId, killed: false, reader, work, scope };
|
|
381
|
-
const options = await this.launchSettings(running, route, opened.configOptions ?? []);
|
|
426
|
+
const options = await step(NO_SETTINGS, this.launchSettings(running, route, opened.configOptions ?? []));
|
|
382
427
|
void work.settled().then(() => scope.record());
|
|
383
428
|
conversation.running = running;
|
|
384
429
|
conversation.session = running.sessionId;
|
|
@@ -400,6 +445,18 @@ export class Conversations {
|
|
|
400
445
|
conversation.opening = null;
|
|
401
446
|
}
|
|
402
447
|
}
|
|
448
|
+
async resume(conversation, kind, adapter, request, empty) {
|
|
449
|
+
try {
|
|
450
|
+
return { ...(await adapter.connection.agent.request('session/resume', request)), sessionId: request.sessionId };
|
|
451
|
+
}
|
|
452
|
+
catch (error) {
|
|
453
|
+
if (!empty || conversation.kills > 0 || !CLIS[kind].unknownSession(error)) {
|
|
454
|
+
throw new NotStarted(NO_RESUME, { cause: error });
|
|
455
|
+
}
|
|
456
|
+
logged(new Error(`conversation ${conversation.id} opens a new session: ${NO_RESUME}: ${causeOf(error)}`));
|
|
457
|
+
return null;
|
|
458
|
+
}
|
|
459
|
+
}
|
|
403
460
|
async launchSettings(running, route, offered) {
|
|
404
461
|
let options = offered;
|
|
405
462
|
const settings = [
|
|
@@ -427,7 +484,7 @@ export class Conversations {
|
|
|
427
484
|
return;
|
|
428
485
|
this.detach(conversation, running);
|
|
429
486
|
if (conversation.turn !== null) {
|
|
430
|
-
this.end(conversation, conversation.turn,
|
|
487
|
+
this.end(conversation, conversation.turn, exitedWith(running, cause));
|
|
431
488
|
}
|
|
432
489
|
this.next(conversation);
|
|
433
490
|
this.kit.changed();
|
|
@@ -491,13 +548,17 @@ export class Conversations {
|
|
|
491
548
|
this.kit.changed();
|
|
492
549
|
return turn;
|
|
493
550
|
}
|
|
494
|
-
end(conversation, turn, failed) {
|
|
551
|
+
end(conversation, turn, failed, notice = null) {
|
|
495
552
|
if (turn.ended)
|
|
496
553
|
return;
|
|
554
|
+
if (failed !== null)
|
|
555
|
+
logged(new Error(`conversation ${conversation.id} turn ${turn.id} failed: ${failed.cause}`));
|
|
497
556
|
if (conversation.turn === turn) {
|
|
498
557
|
for (const event of conversation.running?.reader.closeTurn() ?? [])
|
|
499
558
|
this.apply(conversation, turn, event);
|
|
500
559
|
}
|
|
560
|
+
if (notice !== null)
|
|
561
|
+
turn.parts.start({ type: 'marker', marker: 'retry', text: notice });
|
|
501
562
|
turn.ended = true;
|
|
502
563
|
conversation.open--;
|
|
503
564
|
if (conversation.turn === turn)
|
|
@@ -505,7 +566,7 @@ export class Conversations {
|
|
|
505
566
|
const body = Promise.allSettled(turn.uploads).then(() => ({
|
|
506
567
|
parts: turn.parts.saved(),
|
|
507
568
|
context: turn.parts.context,
|
|
508
|
-
...failed,
|
|
569
|
+
...(failed === null ? {} : { failed: failed.failure }),
|
|
509
570
|
}));
|
|
510
571
|
void this.deliver(conversation, turn, 'ended', body).catch(logged);
|
|
511
572
|
this.next(conversation);
|
|
@@ -515,16 +576,25 @@ export class Conversations {
|
|
|
515
576
|
const running = conversation.running;
|
|
516
577
|
const turn = this.begin(conversation);
|
|
517
578
|
turn.prompted = true;
|
|
518
|
-
|
|
579
|
+
conversation.prompted = running.sessionId;
|
|
580
|
+
running.adapter.connection.agent.request('session/prompt', { sessionId: running.sessionId, prompt }).then((answer) => {
|
|
581
|
+
const notice = answeredFailure(answer);
|
|
582
|
+
if (notice !== null) {
|
|
583
|
+
this.end(conversation, turn, { failure: notice.limit ? 'limit' : 'error', cause: notice.title }, notice.title);
|
|
584
|
+
}
|
|
585
|
+
else {
|
|
586
|
+
this.end(conversation, turn, answer.stopReason === 'refusal' ? { failure: 'refused', cause: REFUSED } : null);
|
|
587
|
+
}
|
|
588
|
+
}, async (error) => {
|
|
519
589
|
if (running.adapter.connection.signal.aborted) {
|
|
520
|
-
this.end(conversation, turn,
|
|
590
|
+
this.end(conversation, turn, exitedWith(running, await running.adapter.exited));
|
|
521
591
|
}
|
|
522
592
|
else {
|
|
523
593
|
if (conversation.open === 1 && conversation.running === running) {
|
|
524
594
|
running.scope.kill();
|
|
525
595
|
this.detach(conversation, running);
|
|
526
596
|
}
|
|
527
|
-
this.end(conversation, turn,
|
|
597
|
+
this.end(conversation, turn, answeredWith(error));
|
|
528
598
|
}
|
|
529
599
|
});
|
|
530
600
|
}
|
package/dist/copies.js
CHANGED
|
@@ -15,6 +15,9 @@ const IDENTITY = { GIT_COMMITTER_NAME: 'House Kit', GIT_COMMITTER_EMAIL: 'house-
|
|
|
15
15
|
function causeOf(error) {
|
|
16
16
|
return error instanceof Error ? error.message : String(error);
|
|
17
17
|
}
|
|
18
|
+
function houseCause(error) {
|
|
19
|
+
return error instanceof HouseRefusal ? (refusalOf(error.text)?.text ?? causeOf(error)) : causeOf(error);
|
|
20
|
+
}
|
|
18
21
|
function logged(error) {
|
|
19
22
|
process.stderr.write(`kit: ${causeOf(error)}\n`);
|
|
20
23
|
}
|
|
@@ -33,6 +36,9 @@ function textOnly(paths) {
|
|
|
33
36
|
const [named, them] = paths.length === 1 ? [`${paths[0]} is`, 'it'] : [`${paths.join(', ')} are`, 'them'];
|
|
34
37
|
return `${named} not text, and house push sends text only; remove ${them} from the commit and place ${them} with house upload`;
|
|
35
38
|
}
|
|
39
|
+
function outside(path) {
|
|
40
|
+
return { refused: true, text: `${path} is not a House Local copy; run house push inside one` };
|
|
41
|
+
}
|
|
36
42
|
function short(commit) {
|
|
37
43
|
return commit.slice(0, 12);
|
|
38
44
|
}
|
|
@@ -60,6 +66,9 @@ function sidecar(path) {
|
|
|
60
66
|
segments.splice(-1, 0, PROVENANCE);
|
|
61
67
|
return segments.join('/');
|
|
62
68
|
}
|
|
69
|
+
function recordOf(key) {
|
|
70
|
+
return join(kitHome(), 'local-copies', `${key}.json`);
|
|
71
|
+
}
|
|
63
72
|
function rootOf(handle) {
|
|
64
73
|
return `/rooms/${handle}`;
|
|
65
74
|
}
|
|
@@ -206,7 +215,7 @@ export class LocalCopies {
|
|
|
206
215
|
async mapping() {
|
|
207
216
|
await this.answering;
|
|
208
217
|
return [...this.copies.values()]
|
|
209
|
-
.filter((copy) => copy.
|
|
218
|
+
.filter((copy) => copy.erasing === undefined)
|
|
210
219
|
.map((copy) => `${rootOf(copy.room_handle)}: ${copy.repository}`)
|
|
211
220
|
.sort();
|
|
212
221
|
}
|
|
@@ -229,25 +238,30 @@ export class LocalCopies {
|
|
|
229
238
|
return this.holding([...new Set([...this.copies.keys(), ...synced.keys()])].sort(), async () => {
|
|
230
239
|
const said = [];
|
|
231
240
|
let refused = false;
|
|
232
|
-
for (const copy of this.copies.values()) {
|
|
233
|
-
|
|
241
|
+
for (const copy of [...this.copies.values()]) {
|
|
242
|
+
const returned = synced.has(copy.key);
|
|
243
|
+
if (returned && copy.erasing === undefined)
|
|
234
244
|
continue;
|
|
235
|
-
|
|
236
|
-
|
|
245
|
+
try {
|
|
246
|
+
await this.erase(copy);
|
|
247
|
+
said.push(`${rootOf(copy.room_handle)}: ${returned ? '' : 'no longer synced to this Environment; '}erased from the Local copy`);
|
|
248
|
+
}
|
|
249
|
+
catch (error) {
|
|
250
|
+
refused = true;
|
|
251
|
+
said.push(`${rootOf(copy.room_handle)}: ${causeOf(error)}`);
|
|
252
|
+
}
|
|
237
253
|
}
|
|
238
254
|
const current = [];
|
|
239
255
|
for (const [key, handle] of synced) {
|
|
240
256
|
try {
|
|
241
257
|
const held = this.copies.get(key);
|
|
258
|
+
if (held?.erasing)
|
|
259
|
+
continue;
|
|
242
260
|
if (held === undefined || !(await exists(held.repository))) {
|
|
243
261
|
said.push(await this.materialize(key, handle));
|
|
244
262
|
continue;
|
|
245
263
|
}
|
|
246
|
-
|
|
247
|
-
if (copy.active)
|
|
248
|
-
current.push(copy);
|
|
249
|
-
else
|
|
250
|
-
said.push(...moved(copy, await this.save(await this.received({ ...copy, active: true }))));
|
|
264
|
+
current.push(held.room_handle === handle ? held : await this.save({ ...held, room_handle: handle }));
|
|
251
265
|
}
|
|
252
266
|
catch (error) {
|
|
253
267
|
refused = true;
|
|
@@ -261,7 +275,7 @@ export class LocalCopies {
|
|
|
261
275
|
}
|
|
262
276
|
catch (error) {
|
|
263
277
|
refused = true;
|
|
264
|
-
said.push(
|
|
278
|
+
said.push(houseCause(error));
|
|
265
279
|
}
|
|
266
280
|
}
|
|
267
281
|
return { refused, text: said.length === 0 ? 'Nothing new from House.' : said.join('\n') };
|
|
@@ -273,6 +287,8 @@ export class LocalCopies {
|
|
|
273
287
|
return;
|
|
274
288
|
await this.exclusive(key, async () => {
|
|
275
289
|
const copy = this.copies.get(key);
|
|
290
|
+
if (copy === undefined || copy.erasing)
|
|
291
|
+
return;
|
|
276
292
|
let moves = copy.moves;
|
|
277
293
|
for (const { from, to } of report.moves) {
|
|
278
294
|
const held = moves.find((move) => move.worktree === report.worktree && move.to === from);
|
|
@@ -295,11 +311,11 @@ export class LocalCopies {
|
|
|
295
311
|
async push(cwd, selector, caller) {
|
|
296
312
|
const located = await run(cwd, ['rev-parse', '--path-format=absolute', '--git-common-dir', '--show-toplevel']);
|
|
297
313
|
if (located.status !== 0)
|
|
298
|
-
return
|
|
314
|
+
return outside(cwd);
|
|
299
315
|
const [common, worktree] = located.stdout.toString('utf8').split('\n');
|
|
300
316
|
const key = await this.keyAt(dirname(common));
|
|
301
317
|
if (key === undefined)
|
|
302
|
-
return
|
|
318
|
+
return outside(worktree);
|
|
303
319
|
return this.exclusive(key, () => this.pushed(key, worktree, selector, caller));
|
|
304
320
|
}
|
|
305
321
|
async keyAt(repository) {
|
|
@@ -320,7 +336,7 @@ export class LocalCopies {
|
|
|
320
336
|
return key === undefined ? work() : this.exclusive(key, () => this.holding(rest, work));
|
|
321
337
|
}
|
|
322
338
|
async save(copy) {
|
|
323
|
-
const path =
|
|
339
|
+
const path = recordOf(copy.key);
|
|
324
340
|
await mkdir(dirname(path), { recursive: true, mode: 0o700 });
|
|
325
341
|
const temporary = `${path}.${process.pid}`;
|
|
326
342
|
await writeFile(temporary, JSON.stringify(copy), { mode: 0o600 });
|
|
@@ -328,6 +344,12 @@ export class LocalCopies {
|
|
|
328
344
|
this.copies.set(copy.key, copy);
|
|
329
345
|
return copy;
|
|
330
346
|
}
|
|
347
|
+
async erase(copy) {
|
|
348
|
+
await this.save({ ...copy, erasing: true });
|
|
349
|
+
await rm(copy.repository, { recursive: true, force: true });
|
|
350
|
+
await rm(recordOf(copy.key), { force: true });
|
|
351
|
+
this.copies.delete(copy.key);
|
|
352
|
+
}
|
|
331
353
|
async read(handle) {
|
|
332
354
|
const prefixes = [rootOf(handle)];
|
|
333
355
|
const discovery = await this.house.post('/kit/door/discover', { prefixes });
|
|
@@ -394,7 +416,6 @@ export class LocalCopies {
|
|
|
394
416
|
room_ref: read.anchor,
|
|
395
417
|
room_handle: handle,
|
|
396
418
|
repository,
|
|
397
|
-
active: true,
|
|
398
419
|
house,
|
|
399
420
|
position: read.position,
|
|
400
421
|
log_epoch: read.log_epoch,
|
|
@@ -523,6 +544,8 @@ export class LocalCopies {
|
|
|
523
544
|
}
|
|
524
545
|
async pushed(key, worktree, selector, caller) {
|
|
525
546
|
let copy = this.copies.get(key);
|
|
547
|
+
if (copy === undefined || copy.erasing)
|
|
548
|
+
return outside(worktree);
|
|
526
549
|
if (copy.push?.state === 'submitted')
|
|
527
550
|
return this.settle(copy, caller);
|
|
528
551
|
const selected = await run(worktree, ['rev-parse', '--verify', '--quiet', '--end-of-options', `${selector}^{commit}`]);
|
|
@@ -536,9 +559,6 @@ export class LocalCopies {
|
|
|
536
559
|
}
|
|
537
560
|
copy = await this.save(without(copy));
|
|
538
561
|
}
|
|
539
|
-
if (!copy.active) {
|
|
540
|
-
return { refused: true, text: `${rootOf(copy.room_handle)} is no longer synced to this Environment, so House takes no push from it` };
|
|
541
|
-
}
|
|
542
562
|
const listed = (await git(copy.repository, ['rev-list', '--topo-order', commit])).split('\n');
|
|
543
563
|
const base = listed.find((ancestor) => ancestor in copy.manifests);
|
|
544
564
|
if (base === undefined) {
|
|
@@ -549,7 +569,7 @@ export class LocalCopies {
|
|
|
549
569
|
changes = await this.derived(copy, base, commit);
|
|
550
570
|
}
|
|
551
571
|
catch (error) {
|
|
552
|
-
return { refused: true, text:
|
|
572
|
+
return { refused: true, text: houseCause(error) };
|
|
553
573
|
}
|
|
554
574
|
if (changes.length === 0)
|
|
555
575
|
return { refused: false, text: `Nothing to submit: ${short(commit)} matches House.` };
|
|
@@ -576,12 +596,17 @@ export class LocalCopies {
|
|
|
576
596
|
const after = await tree(copy.repository, commit);
|
|
577
597
|
const moved = movedPaths(copy.moves, before, after);
|
|
578
598
|
const arrived = new Set(moved.values());
|
|
579
|
-
const
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
599
|
+
const arriving = [...after].filter(([path, entry]) => before.get(path) !== entry);
|
|
600
|
+
if (arriving.length > 0) {
|
|
601
|
+
const { bounds } = await this.house.post('/kit/door/discover', { prefixes: [root] });
|
|
602
|
+
const binary = [];
|
|
603
|
+
for (const [path, entry] of arriving) {
|
|
604
|
+
if (!(await isText(copy.repository, entry, bounds.max_authored_file_bytes)))
|
|
605
|
+
binary.push(path);
|
|
606
|
+
}
|
|
607
|
+
if (binary.length > 0)
|
|
608
|
+
throw new Error(textOnly(binary));
|
|
609
|
+
}
|
|
585
610
|
const text = (entry) => blobText(copy.repository, entry);
|
|
586
611
|
const changes = [];
|
|
587
612
|
for (const path of [...new Set([...before.keys(), ...after.keys()])].sort()) {
|
package/dist/end.js
CHANGED
|
@@ -13,8 +13,9 @@ export function end(reason) {
|
|
|
13
13
|
export function restart(reason) {
|
|
14
14
|
exit(reason, 1);
|
|
15
15
|
}
|
|
16
|
-
export function updateRequired(
|
|
17
|
-
|
|
16
|
+
export function updateRequired() {
|
|
17
|
+
const command = installCommand();
|
|
18
|
+
end(command === null ? 'This Kit is too old for House; install it again.' : `This Kit is too old for House. Update it: ${command}`);
|
|
18
19
|
}
|
|
19
20
|
export async function signInAgain(rejected) {
|
|
20
21
|
await forgetRejected(rejected);
|
package/dist/events.js
CHANGED
|
@@ -512,6 +512,10 @@ class GrokReader extends Reader {
|
|
|
512
512
|
return [];
|
|
513
513
|
}
|
|
514
514
|
}
|
|
515
|
+
export function answeredFailure(answer) {
|
|
516
|
+
const failure = answer._meta?.jetbrains?.air?.sessionFailure;
|
|
517
|
+
return typeof failure?.title === 'string' ? { title: failure.title, limit: failure.category === 'limit' } : null;
|
|
518
|
+
}
|
|
515
519
|
export function readerFor(kind) {
|
|
516
520
|
if (kind === 'claude-agent-acp')
|
|
517
521
|
return new ClaudeReader();
|
package/dist/git.js
CHANGED
|
@@ -49,16 +49,15 @@ export async function tree(repository, commit) {
|
|
|
49
49
|
}
|
|
50
50
|
return entries;
|
|
51
51
|
}
|
|
52
|
-
const TEXT_MAX_BYTES = 16 * 1024 * 1024;
|
|
53
52
|
async function blob(repository, object) {
|
|
54
53
|
return (await run(repository, ['cat-file', 'blob', object])).stdout;
|
|
55
54
|
}
|
|
56
55
|
export async function blobText(repository, object) {
|
|
57
56
|
return (await blob(repository, object)).toString('utf8');
|
|
58
57
|
}
|
|
59
|
-
export async function isText(repository, object) {
|
|
58
|
+
export async function isText(repository, object, maxBytes) {
|
|
60
59
|
const bytes = await blob(repository, object);
|
|
61
|
-
return bytes.length <=
|
|
60
|
+
return bytes.length <= maxBytes && isUtf8(bytes) && !bytes.includes(0);
|
|
62
61
|
}
|
|
63
62
|
export function blobId(content) {
|
|
64
63
|
const bytes = Buffer.from(content, 'utf8');
|
package/dist/home.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
+
import { accessSync, chmodSync, constants, existsSync, linkSync, lstatSync, mkdirSync, readFileSync, realpathSync, renameSync, rmSync } from 'node:fs';
|
|
2
3
|
import { mkdir, readFile, rename, rm, writeFile } from 'node:fs/promises';
|
|
3
4
|
import { homedir, tmpdir } 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';
|
|
@@ -18,24 +19,26 @@ function writable(directory) {
|
|
|
18
19
|
return false;
|
|
19
20
|
}
|
|
20
21
|
}
|
|
21
|
-
function
|
|
22
|
-
const home = join(tmpdir(), `house-kit-${process.getuid()}`);
|
|
22
|
+
function privateDirectory(path) {
|
|
23
23
|
try {
|
|
24
|
-
mkdirSync(
|
|
24
|
+
mkdirSync(path, { mode: 0o700 });
|
|
25
25
|
}
|
|
26
26
|
catch (error) {
|
|
27
27
|
if (error.code !== 'EEXIST')
|
|
28
28
|
throw error;
|
|
29
29
|
}
|
|
30
|
-
const found = lstatSync(
|
|
30
|
+
const found = lstatSync(path);
|
|
31
31
|
if (found.isSymbolicLink())
|
|
32
|
-
throw new Error(`${
|
|
32
|
+
throw new Error(`${path} is a symbolic link`);
|
|
33
33
|
if (!found.isDirectory())
|
|
34
|
-
throw new Error(`${
|
|
35
|
-
if (found.uid !== process.
|
|
36
|
-
throw new Error(`${
|
|
37
|
-
chmodSync(
|
|
38
|
-
return
|
|
34
|
+
throw new Error(`${path} is not a directory`);
|
|
35
|
+
if (found.uid !== process.geteuid())
|
|
36
|
+
throw new Error(`${path} is not owned by this User`);
|
|
37
|
+
chmodSync(path, 0o700);
|
|
38
|
+
return path;
|
|
39
|
+
}
|
|
40
|
+
function ownTemporaryHome() {
|
|
41
|
+
return privateDirectory(join(tmpdir(), `house-kit-${process.getuid()}`));
|
|
39
42
|
}
|
|
40
43
|
function defaultHome() {
|
|
41
44
|
const home = join(homedir(), '.house-kit');
|
|
@@ -44,6 +47,18 @@ function defaultHome() {
|
|
|
44
47
|
export function kitHome() {
|
|
45
48
|
return process.env.HOUSE_KIT_HOME || (defaulted ??= defaultHome());
|
|
46
49
|
}
|
|
50
|
+
export function socketDirectory() {
|
|
51
|
+
const sockets = privateDirectory(join(realpathSync('/tmp'), `hk-${process.geteuid()}`));
|
|
52
|
+
const home = kitHome();
|
|
53
|
+
const physical = existsSync(home) ? realpathSync(home) : resolve(home);
|
|
54
|
+
return privateDirectory(join(sockets, createHash('sha256').update(physical).digest('hex').slice(0, 12)));
|
|
55
|
+
}
|
|
56
|
+
export function ownerSocket() {
|
|
57
|
+
return join(socketDirectory(), 'owner.sock');
|
|
58
|
+
}
|
|
59
|
+
export function ownerLock() {
|
|
60
|
+
return join(socketDirectory(), 'owner.lock');
|
|
61
|
+
}
|
|
47
62
|
export function workspaceRoot() {
|
|
48
63
|
return process.env.HOUSE_KIT_WORKSPACE ?? '/agents/house';
|
|
49
64
|
}
|
|
@@ -63,7 +78,7 @@ export async function readHome(name) {
|
|
|
63
78
|
export async function writeHome(name, value) {
|
|
64
79
|
const home = kitHome();
|
|
65
80
|
await mkdir(home, { recursive: true, mode: 0o700 });
|
|
66
|
-
const temporary = join(home, `${name}.${
|
|
81
|
+
const temporary = join(home, `${name}.${randomUUID()}`);
|
|
67
82
|
await writeFile(temporary, `${JSON.stringify(value)}\n`, { mode: 0o600 });
|
|
68
83
|
await rename(temporary, join(home, name));
|
|
69
84
|
}
|
|
@@ -80,6 +95,9 @@ export async function writeEnrolment(enrolment) {
|
|
|
80
95
|
export function readDisconnected() {
|
|
81
96
|
return readHome(DISCONNECTED);
|
|
82
97
|
}
|
|
98
|
+
export function forgetDisconnected() {
|
|
99
|
+
return rm(join(kitHome(), DISCONNECTED), { force: true });
|
|
100
|
+
}
|
|
83
101
|
export async function forgetEnrolment({ house, environment }) {
|
|
84
102
|
await writeHome(DISCONNECTED, { house, environment });
|
|
85
103
|
await rm(join(kitHome(), ENROLMENT), { force: true });
|