@agentshouse/kit 0.2.1-c3cf4b145dcda → 0.2.1-c3e86aacccc80
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 +21 -20
- package/dist/acp.js +7 -97
- package/dist/agents.js +3 -2
- package/dist/api.js +5 -5
- package/dist/bootstrap.json +4 -4
- package/dist/bridge.js +11 -37
- package/dist/clis.js +52 -13
- package/dist/codex-main.js +58 -0
- package/dist/conversations.js +55 -55
- package/dist/copies.js +127 -102
- package/dist/end.js +14 -4
- package/dist/enrol-main.js +7 -1
- package/dist/events.js +10 -76
- package/dist/home.js +41 -3
- package/dist/house-main.js +76 -32
- package/dist/instructions.js +7 -5
- package/dist/login.js +89 -105
- package/dist/logout.js +14 -14
- package/dist/parts.js +34 -16
- package/dist/relay.js +12 -2
- package/dist/resident.js +27 -20
- package/dist/scope.js +203 -0
- package/dist/service-main.js +9 -0
- package/dist/service.js +33 -0
- package/dist/sign-in.js +1 -1
- package/dist/stream.js +5 -3
- package/dist/work.js +348 -0
- package/package.json +2 -2
package/dist/events.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const COMMAND = { shown: 'command' };
|
|
2
2
|
const HIDDEN = { shown: 'hidden' };
|
|
3
3
|
const FINISHED = new Set(['completed', 'failed']);
|
|
4
|
-
const RUNNING_JOB = new Set(['running', 'paused']);
|
|
4
|
+
export const RUNNING_JOB = new Set(['running', 'paused']);
|
|
5
5
|
const ROUTINE_TARGETS = { send_routine_request: 'access', cancel_routine_request: 'request' };
|
|
6
6
|
function words(line) {
|
|
7
7
|
const found = [];
|
|
@@ -113,9 +113,6 @@ class Reader {
|
|
|
113
113
|
refused(option) {
|
|
114
114
|
this.requestedOptions.delete(option);
|
|
115
115
|
}
|
|
116
|
-
turnStarted() {
|
|
117
|
-
return [];
|
|
118
|
-
}
|
|
119
116
|
closeTurn() {
|
|
120
117
|
const events = [];
|
|
121
118
|
for (const [id, call] of this.calls) {
|
|
@@ -187,10 +184,7 @@ class Reader {
|
|
|
187
184
|
const label = this.jobs.get(id) ?? '';
|
|
188
185
|
if (state !== 'running')
|
|
189
186
|
this.jobs.delete(id);
|
|
190
|
-
return [
|
|
191
|
-
{ kind: 'busy', key: `job:${id}`, running: state === 'running' },
|
|
192
|
-
{ kind: 'marker', marker: 'job', text: `${label}: ${state}` },
|
|
193
|
-
];
|
|
187
|
+
return [{ kind: 'marker', marker: 'job', text: `${label}: ${state}` }];
|
|
194
188
|
}
|
|
195
189
|
optionsChanged(options) {
|
|
196
190
|
const events = [];
|
|
@@ -275,7 +269,6 @@ class Reader {
|
|
|
275
269
|
class ClaudeReader extends Reader {
|
|
276
270
|
watchedOptions = { model: 'model' };
|
|
277
271
|
tasks = new Map();
|
|
278
|
-
scheduled = new Map();
|
|
279
272
|
own(message) {
|
|
280
273
|
if (message.params?.update?._meta?.claudeCode?.parentToolUseId !== undefined)
|
|
281
274
|
return [];
|
|
@@ -295,10 +288,6 @@ class ClaudeReader extends Reader {
|
|
|
295
288
|
return [];
|
|
296
289
|
const sdk = message.params.message;
|
|
297
290
|
switch (sdk.subtype) {
|
|
298
|
-
case 'background_tasks_changed':
|
|
299
|
-
return [{ kind: 'busy', key: 'tasks', running: sdk.tasks.length > 0 }];
|
|
300
|
-
case 'session_state_changed':
|
|
301
|
-
return [{ kind: 'busy', key: 'state', running: sdk.state === 'running' }];
|
|
302
291
|
case 'task_started':
|
|
303
292
|
if (sdk.tool_use_id !== undefined)
|
|
304
293
|
this.tasks.set(sdk.task_id, sdk.tool_use_id);
|
|
@@ -309,16 +298,6 @@ class ClaudeReader extends Reader {
|
|
|
309
298
|
return [];
|
|
310
299
|
}
|
|
311
300
|
}
|
|
312
|
-
turnStarted() {
|
|
313
|
-
const events = [];
|
|
314
|
-
for (const [id, entry] of this.scheduled) {
|
|
315
|
-
if (entry.recurring)
|
|
316
|
-
continue;
|
|
317
|
-
this.scheduled.delete(id);
|
|
318
|
-
events.push({ kind: 'busy', key: `scheduled:${id}`, running: false });
|
|
319
|
-
}
|
|
320
|
-
return events;
|
|
321
|
-
}
|
|
322
301
|
decide(call, final) {
|
|
323
302
|
const tool = call.meta.claudeCode?.toolName;
|
|
324
303
|
if (tool === 'Agent' || tool === 'Task' || call.meta.jetbrains?.air?.subagent === true) {
|
|
@@ -350,22 +329,7 @@ class ClaudeReader extends Reader {
|
|
|
350
329
|
if (call.status !== 'completed')
|
|
351
330
|
return [];
|
|
352
331
|
if (tool === 'CronCreate' || (tool === 'ScheduleWakeup' && call.rawInput?.stop !== true)) {
|
|
353
|
-
|
|
354
|
-
recurring: tool === 'CronCreate' && call.rawInput?.recurring !== false,
|
|
355
|
-
text: contentText(call.content) ?? '',
|
|
356
|
-
});
|
|
357
|
-
return [
|
|
358
|
-
{ kind: 'busy', key: `scheduled:${call.id}`, running: true },
|
|
359
|
-
{ kind: 'marker', marker: 'job', text: `${call.rawInput?.prompt ?? call.title ?? ''}: scheduled` },
|
|
360
|
-
];
|
|
361
|
-
}
|
|
362
|
-
if (tool === 'CronDelete') {
|
|
363
|
-
for (const [id, entry] of this.scheduled) {
|
|
364
|
-
if (!entry.text.includes(String(call.rawInput?.id)))
|
|
365
|
-
continue;
|
|
366
|
-
this.scheduled.delete(id);
|
|
367
|
-
return [{ kind: 'busy', key: `scheduled:${id}`, running: false }];
|
|
368
|
-
}
|
|
332
|
+
return [{ kind: 'marker', marker: 'job', text: `${call.rawInput?.prompt ?? call.title ?? ''}: scheduled` }];
|
|
369
333
|
}
|
|
370
334
|
return [];
|
|
371
335
|
}
|
|
@@ -402,15 +366,9 @@ class CodexReader extends Reader {
|
|
|
402
366
|
case 'subagent_spawned':
|
|
403
367
|
this.children.set(update.subagentSessionId, { id: null, text: '' });
|
|
404
368
|
this.subagents.add(update.subagentSessionId);
|
|
405
|
-
return [
|
|
406
|
-
{ kind: 'busy', key: `subagent:${update.subagentSessionId}`, running: true },
|
|
407
|
-
{ kind: 'subagent', id: update.subagentSessionId, description: update.name },
|
|
408
|
-
];
|
|
369
|
+
return [{ kind: 'subagent', id: update.subagentSessionId, description: update.name }];
|
|
409
370
|
case 'subagent_state_update':
|
|
410
|
-
return
|
|
411
|
-
{ kind: 'busy', key: `subagent:${update.subagentSessionId}`, running: false },
|
|
412
|
-
...this.finish(update.subagentSessionId, this.children.get(update.subagentSessionId)?.text || null),
|
|
413
|
-
];
|
|
371
|
+
return this.finish(update.subagentSessionId, this.children.get(update.subagentSessionId)?.text || null);
|
|
414
372
|
default:
|
|
415
373
|
return super.update(update);
|
|
416
374
|
}
|
|
@@ -427,10 +385,6 @@ class CodexReader extends Reader {
|
|
|
427
385
|
child.id = id;
|
|
428
386
|
child.text += update.content.text;
|
|
429
387
|
}
|
|
430
|
-
const status = update._meta?.codex?.threadStatus?.type;
|
|
431
|
-
if (update.sessionUpdate === 'session_info_update' && status !== undefined) {
|
|
432
|
-
return [{ kind: 'busy', key: `thread:${session}`, running: status === 'active' }];
|
|
433
|
-
}
|
|
434
388
|
return [];
|
|
435
389
|
}
|
|
436
390
|
decide(call) {
|
|
@@ -460,7 +414,6 @@ class CodexReader extends Reader {
|
|
|
460
414
|
class GrokReader extends Reader {
|
|
461
415
|
watchedOptions = {};
|
|
462
416
|
children = new Map();
|
|
463
|
-
queues = new Map();
|
|
464
417
|
models = [];
|
|
465
418
|
model = null;
|
|
466
419
|
answered(result) {
|
|
@@ -473,15 +426,10 @@ class GrokReader extends Reader {
|
|
|
473
426
|
if (this.session !== null && session !== undefined && session !== this.session && !this.children.has(session))
|
|
474
427
|
return [];
|
|
475
428
|
if (message.method === '_x.ai/queue/changed') {
|
|
476
|
-
|
|
477
|
-
this.queues.set(session, { running, entries: message.params.entries.length });
|
|
478
|
-
return [this.queued(session), ...(running !== null && session === this.session ? [{ kind: 'started' }] : [])];
|
|
429
|
+
return (message.params.runningPromptId ?? null) !== null && session === this.session ? [{ kind: 'started' }] : [];
|
|
479
430
|
}
|
|
480
431
|
if (message.params?.update?.sessionUpdate === 'turn_completed') {
|
|
481
|
-
|
|
482
|
-
if (queue !== undefined && queue.running === message.params.update.prompt_id)
|
|
483
|
-
queue.running = null;
|
|
484
|
-
return [this.queued(session), ...(session === this.session ? [{ kind: 'ended' }] : [])];
|
|
432
|
+
return session === this.session ? [{ kind: 'ended' }] : [];
|
|
485
433
|
}
|
|
486
434
|
if (message.method === '_x.ai/models/update') {
|
|
487
435
|
this.offered(message.params);
|
|
@@ -489,10 +437,6 @@ class GrokReader extends Reader {
|
|
|
489
437
|
}
|
|
490
438
|
return super.read(message);
|
|
491
439
|
}
|
|
492
|
-
queued(session) {
|
|
493
|
-
const queue = this.queues.get(session);
|
|
494
|
-
return { kind: 'busy', key: `queue:${session}`, running: queue !== undefined && (queue.running !== null || queue.entries > 0) };
|
|
495
|
-
}
|
|
496
440
|
offered(models) {
|
|
497
441
|
this.models = models.availableModels ?? this.models;
|
|
498
442
|
this.model = models.currentModelId ?? this.model;
|
|
@@ -508,16 +452,9 @@ class GrokReader extends Reader {
|
|
|
508
452
|
case '_x.ai/task_completed':
|
|
509
453
|
return this.job(update.task_snapshot.task_id, null, update.task_snapshot.exit_code === 0 ? 'completed' : 'failed');
|
|
510
454
|
case '_x.ai/scheduled_task_created':
|
|
511
|
-
return [
|
|
512
|
-
{ kind: 'busy', key: `scheduled:${update.task_id}`, running: true },
|
|
513
|
-
{ kind: 'marker', marker: 'job', text: `${update.prompt}: next run ${update.next_fire_at}` },
|
|
514
|
-
];
|
|
515
|
-
case '_x.ai/scheduled_task_deleted':
|
|
516
|
-
return [{ kind: 'busy', key: `scheduled:${update.task_id}`, running: false }];
|
|
455
|
+
return [{ kind: 'marker', marker: 'job', text: `${update.prompt}: next run ${update.next_fire_at}` }];
|
|
517
456
|
case '_x.ai/session_notification':
|
|
518
457
|
return this.notification(update);
|
|
519
|
-
case '_x.ai/mcp_initialized':
|
|
520
|
-
return [{ kind: 'servers' }];
|
|
521
458
|
default:
|
|
522
459
|
return [];
|
|
523
460
|
}
|
|
@@ -538,14 +475,11 @@ class GrokReader extends Reader {
|
|
|
538
475
|
candidate.decided.description === update.description) ??
|
|
539
476
|
[...this.calls.values()].find((candidate) => candidate.decided?.shown === 'subagent' && ![...this.children.values()].includes(candidate.id));
|
|
540
477
|
this.children.set(update.child_session_id, call?.id ?? null);
|
|
541
|
-
return [
|
|
478
|
+
return [];
|
|
542
479
|
}
|
|
543
480
|
case 'subagent_finished': {
|
|
544
481
|
const call = this.children.get(update.child_session_id);
|
|
545
|
-
return [
|
|
546
|
-
{ kind: 'busy', key: `subagent:${update.child_session_id}`, running: false },
|
|
547
|
-
...(typeof call === 'string' ? this.finish(call, update.output ?? null) : []),
|
|
548
|
-
];
|
|
482
|
+
return typeof call === 'string' ? this.finish(call, update.output ?? null) : [];
|
|
549
483
|
}
|
|
550
484
|
case 'auto_compact_completed':
|
|
551
485
|
return [{ kind: 'marker', marker: 'compaction', text: '' }];
|
package/dist/home.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { existsSync } from 'node:fs';
|
|
1
|
+
import { existsSync, linkSync, readFileSync, renameSync, rmSync } from 'node:fs';
|
|
2
2
|
import { mkdir, readFile, rename, rm, writeFile } from 'node:fs/promises';
|
|
3
3
|
import { homedir } from 'node:os';
|
|
4
4
|
import { join } from 'node:path';
|
|
5
|
+
import { selectRelay } from './relay.js';
|
|
5
6
|
const ENROLMENT = 'credential.json';
|
|
6
7
|
const DISCONNECTED = 'disconnected.json';
|
|
7
8
|
const CONFIGURATION = 'kit.json';
|
|
8
9
|
const OWN_AGENT = 'own-agent.json';
|
|
10
|
+
const RESTART = 'restart';
|
|
9
11
|
export function kitHome() {
|
|
10
12
|
return process.env.HOUSE_KIT_HOME ?? join(homedir(), '.house-kit');
|
|
11
13
|
}
|
|
@@ -32,8 +34,11 @@ export async function writeHome(name, value) {
|
|
|
32
34
|
await writeFile(temporary, `${JSON.stringify(value)}\n`, { mode: 0o600 });
|
|
33
35
|
await rename(temporary, join(home, name));
|
|
34
36
|
}
|
|
35
|
-
export function readEnrolment() {
|
|
36
|
-
|
|
37
|
+
export async function readEnrolment() {
|
|
38
|
+
const enrolment = await readHome(ENROLMENT);
|
|
39
|
+
if (enrolment !== null)
|
|
40
|
+
selectRelay(process.env.HOUSE_KIT_RELAY || enrolment.relay);
|
|
41
|
+
return enrolment;
|
|
37
42
|
}
|
|
38
43
|
export async function writeEnrolment(enrolment) {
|
|
39
44
|
await writeHome(ENROLMENT, enrolment);
|
|
@@ -46,9 +51,42 @@ export async function forgetEnrolment({ house, environment }) {
|
|
|
46
51
|
await writeHome(DISCONNECTED, { house, environment });
|
|
47
52
|
await rm(join(kitHome(), ENROLMENT), { force: true });
|
|
48
53
|
}
|
|
54
|
+
export async function forgetRejected(rejected) {
|
|
55
|
+
const held = await readHome(ENROLMENT);
|
|
56
|
+
if (held?.credential !== rejected)
|
|
57
|
+
return;
|
|
58
|
+
await writeHome(DISCONNECTED, { house: held.house, environment: held.environment });
|
|
59
|
+
const enrolment = join(kitHome(), ENROLMENT);
|
|
60
|
+
const taken = `${enrolment}.${process.pid}`;
|
|
61
|
+
try {
|
|
62
|
+
renameSync(enrolment, taken);
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
if (error.code === 'ENOENT')
|
|
66
|
+
return;
|
|
67
|
+
throw error;
|
|
68
|
+
}
|
|
69
|
+
if (JSON.parse(readFileSync(taken, 'utf8')).credential !== rejected) {
|
|
70
|
+
try {
|
|
71
|
+
linkSync(taken, enrolment);
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
if (error.code !== 'EEXIST')
|
|
75
|
+
throw error;
|
|
76
|
+
}
|
|
77
|
+
rmSync(join(kitHome(), DISCONNECTED), { force: true });
|
|
78
|
+
}
|
|
79
|
+
rmSync(taken);
|
|
80
|
+
}
|
|
49
81
|
export function enrolled() {
|
|
50
82
|
return existsSync(join(kitHome(), ENROLMENT));
|
|
51
83
|
}
|
|
84
|
+
export function restartAsked() {
|
|
85
|
+
return existsSync(join(kitHome(), RESTART));
|
|
86
|
+
}
|
|
87
|
+
export function forgetRestart() {
|
|
88
|
+
return rm(join(kitHome(), RESTART), { force: true });
|
|
89
|
+
}
|
|
52
90
|
export function readOwnAgent() {
|
|
53
91
|
return readHome(OWN_AGENT);
|
|
54
92
|
}
|
package/dist/house-main.js
CHANGED
|
@@ -2,20 +2,52 @@
|
|
|
2
2
|
import { createHash } from 'node:crypto';
|
|
3
3
|
import { readFile } from 'node:fs/promises';
|
|
4
4
|
import { request, setGlobalProxyFromEnv } from 'node:http';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { extname, join } from 'node:path';
|
|
6
|
+
import { HOUSE_REF } from './git.js';
|
|
7
|
+
import { kitHome, readEnrolment, readOwnAgent } from './home.js';
|
|
7
8
|
import { callHouse, rpc, UNREACHABLE } from './mcp.js';
|
|
8
9
|
import { refusalOf } from './refusals.js';
|
|
10
|
+
import { relayed } from './relay.js';
|
|
11
|
+
import { parse, stringify } from 'yaml';
|
|
9
12
|
const USAGE = "usage: house <tool> ['<arguments as JSON>']";
|
|
10
13
|
const PUSH_USAGE = 'usage: house push [commit] [--owner]';
|
|
11
14
|
const PUSH = "push [commit]: sends the Local copy's committed changes to House";
|
|
15
|
+
const FETCH_USAGE = 'usage: house fetch';
|
|
16
|
+
const FETCH = `fetch: records House's changes on each Local copy's ${HOUSE_REF}`;
|
|
12
17
|
const ARGUMENTS = `the arguments are one JSON object in single quotes, like house search '{"query":"invoice"}'`;
|
|
13
18
|
const CLOSED = "this conversation's House connection is closed; nothing to do from here";
|
|
14
|
-
const SANDBOXED = "your CLI's sandbox kept house from House; run house
|
|
19
|
+
const SANDBOXED = "your CLI's sandbox kept house from House; run house directly, not through another program";
|
|
15
20
|
const REVOKED = 'this conversation no longer has House access; nothing to do from here';
|
|
16
21
|
const UNCONNECTED = "this computer's own agent has no House connection; run kit login";
|
|
17
22
|
const DISCONNECTED = "House no longer accepts this computer's own agent; run kit login";
|
|
18
23
|
const socketPath = process.env.HOUSE_BRIDGE;
|
|
24
|
+
const MEDIA_TYPES = new Map([
|
|
25
|
+
['avif', 'image/avif'],
|
|
26
|
+
['csv', 'text/csv'],
|
|
27
|
+
['docx', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'],
|
|
28
|
+
['gif', 'image/gif'],
|
|
29
|
+
['heic', 'image/heic'],
|
|
30
|
+
['html', 'text/html'],
|
|
31
|
+
['jpeg', 'image/jpeg'],
|
|
32
|
+
['jpg', 'image/jpeg'],
|
|
33
|
+
['json', 'application/json'],
|
|
34
|
+
['m4a', 'audio/mp4'],
|
|
35
|
+
['md', 'text/markdown'],
|
|
36
|
+
['mov', 'video/quicktime'],
|
|
37
|
+
['mp3', 'audio/mpeg'],
|
|
38
|
+
['mp4', 'video/mp4'],
|
|
39
|
+
['ogg', 'audio/ogg'],
|
|
40
|
+
['pdf', 'application/pdf'],
|
|
41
|
+
['png', 'image/png'],
|
|
42
|
+
['pptx', 'application/vnd.openxmlformats-officedocument.presentationml.presentation'],
|
|
43
|
+
['svg', 'image/svg+xml'],
|
|
44
|
+
['txt', 'text/plain'],
|
|
45
|
+
['wav', 'audio/wav'],
|
|
46
|
+
['webm', 'video/webm'],
|
|
47
|
+
['webp', 'image/webp'],
|
|
48
|
+
['xlsx', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'],
|
|
49
|
+
['zip', 'application/zip'],
|
|
50
|
+
]);
|
|
19
51
|
function refused(path, status, text) {
|
|
20
52
|
const refusal = refusalOf(text);
|
|
21
53
|
if (refusal !== null)
|
|
@@ -51,6 +83,7 @@ async function direct(message) {
|
|
|
51
83
|
const ownAgent = await readOwnAgent();
|
|
52
84
|
if (ownAgent === null)
|
|
53
85
|
throw new Error(UNCONNECTED);
|
|
86
|
+
await readEnrolment();
|
|
54
87
|
setGlobalProxyFromEnv();
|
|
55
88
|
const answer = await callHouse(ownAgent.house, ownAgent.credential, message).catch(() => {
|
|
56
89
|
throw new Error(UNREACHABLE);
|
|
@@ -79,25 +112,35 @@ async function localFile(path) {
|
|
|
79
112
|
: `${path} is not a readable file`);
|
|
80
113
|
}
|
|
81
114
|
}
|
|
82
|
-
async function
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
115
|
+
async function sent(url, bytes, operation) {
|
|
116
|
+
const headers = { 'content-type': 'application/octet-stream', 'x-house-byte-operation': operation };
|
|
117
|
+
if (socketPath !== undefined)
|
|
118
|
+
return bridged(url, bytes, headers);
|
|
119
|
+
setGlobalProxyFromEnv();
|
|
120
|
+
const answer = await fetch(relayed(url), { method: 'POST', headers, body: bytes }).catch(() => {
|
|
121
|
+
throw new Error(UNREACHABLE);
|
|
122
|
+
});
|
|
123
|
+
const text = await answer.text();
|
|
124
|
+
if (answer.status === 200)
|
|
125
|
+
return text;
|
|
126
|
+
throw new Error(refused(url, answer.status, text));
|
|
127
|
+
}
|
|
128
|
+
async function upload({ file, ...destination }) {
|
|
129
|
+
if (typeof file !== 'string' || file === '')
|
|
130
|
+
throw new Error('upload needs "file", a local file');
|
|
131
|
+
const bytes = await localFile(file);
|
|
132
|
+
const mediaType = MEDIA_TYPES.get(extname(file).slice(1).toLowerCase());
|
|
133
|
+
const answer = await called('upload', {
|
|
134
|
+
...destination,
|
|
89
135
|
bytes: bytes.length,
|
|
90
136
|
sha256: createHash('sha256').update(bytes).digest('hex'),
|
|
91
|
-
|
|
137
|
+
...(mediaType === undefined ? {} : { media_type: mediaType }),
|
|
138
|
+
});
|
|
139
|
+
const declared = parse(answer);
|
|
92
140
|
if (declared.upload === undefined)
|
|
93
|
-
return
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
'x-house-byte-operation': declared.upload.operation,
|
|
97
|
-
}));
|
|
98
|
-
if (saved.upload_failure !== undefined)
|
|
99
|
-
throw new Error(`${path} was not saved: ${saved.upload_failure}; call again later`);
|
|
100
|
-
return saved.attachment;
|
|
141
|
+
return answer;
|
|
142
|
+
const written = JSON.parse(await sent(declared.upload.url, bytes, declared.upload.operation));
|
|
143
|
+
return stringify(written, { lineWidth: 0 }).trimEnd();
|
|
101
144
|
}
|
|
102
145
|
async function push(args) {
|
|
103
146
|
if (args.includes('--help'))
|
|
@@ -113,6 +156,14 @@ async function push(args) {
|
|
|
113
156
|
throw new Error(pushed.text);
|
|
114
157
|
return pushed.text;
|
|
115
158
|
}
|
|
159
|
+
async function fetched(args) {
|
|
160
|
+
if (args.includes('--help'))
|
|
161
|
+
return FETCH_USAGE;
|
|
162
|
+
const answer = JSON.parse(await bridged('/git/fetch', {}, undefined, socketPath ?? join(kitHome(), 'owner.sock')));
|
|
163
|
+
if (answer.refused)
|
|
164
|
+
throw new Error(answer.text);
|
|
165
|
+
return answer.text;
|
|
166
|
+
}
|
|
116
167
|
function argumentsOf(argument) {
|
|
117
168
|
if (argument === undefined)
|
|
118
169
|
return {};
|
|
@@ -129,7 +180,7 @@ function argumentsOf(argument) {
|
|
|
129
180
|
}
|
|
130
181
|
async function house([verb, argument]) {
|
|
131
182
|
if (verb === undefined || verb === '--help' || verb === 'help') {
|
|
132
|
-
return [USAGE, 'help', PUSH, ...(await tools()).map((tool) => (tool.description === undefined ? tool.name : `${tool.name}: ${tool.description}`))].join('\n');
|
|
183
|
+
return [USAGE, 'help', PUSH, FETCH, ...(await tools()).map((tool) => (tool.description === undefined ? tool.name : `${tool.name}: ${tool.description}`))].join('\n');
|
|
133
184
|
}
|
|
134
185
|
if (argument === '--help') {
|
|
135
186
|
const tool = (await tools()).find((listed) => listed.name === verb);
|
|
@@ -138,24 +189,17 @@ async function house([verb, argument]) {
|
|
|
138
189
|
return [...(tool.description === undefined ? [] : [tool.description]), JSON.stringify(tool.inputSchema)].join('\n');
|
|
139
190
|
}
|
|
140
191
|
const args = argumentsOf(argument);
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
const attachments = [];
|
|
146
|
-
for (const path of args.attachments) {
|
|
147
|
-
attachments.push(await upload(path, args.room_ref, 'each attachments entry is the path of a local file'));
|
|
148
|
-
}
|
|
149
|
-
args.attachments = attachments;
|
|
150
|
-
}
|
|
151
|
-
const result = await mcp('tools/call', { name: verb, arguments: args });
|
|
192
|
+
return verb === 'upload' ? upload(args) : called(verb, args);
|
|
193
|
+
}
|
|
194
|
+
async function called(name, args) {
|
|
195
|
+
const result = await mcp('tools/call', { name, arguments: args });
|
|
152
196
|
const text = result.content.map((content) => content.text).join('\n');
|
|
153
197
|
if (result.isError === true)
|
|
154
198
|
throw new Error(text.replace(/\n+$/, ''));
|
|
155
199
|
return text;
|
|
156
200
|
}
|
|
157
201
|
const argv = process.argv.slice(2);
|
|
158
|
-
(argv[0] === 'push' ? push(argv.slice(1)) : house(argv)).then((text) => {
|
|
202
|
+
(argv[0] === 'push' ? push(argv.slice(1)) : argv[0] === 'fetch' ? fetched(argv.slice(1)) : house(argv)).then((text) => {
|
|
159
203
|
process.stdout.write(`${text}\n`);
|
|
160
204
|
if (argv[0] === 'shell')
|
|
161
205
|
process.exitCode = Number(/^exit: (\d+)(?:\n|$)/.exec(text)?.[1] ?? 0);
|
package/dist/instructions.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { HOUSE_REF } from './git.js';
|
|
1
2
|
import { HOW_WE_WORK } from './skills.js';
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
3
|
+
const SOURCE_LINE = "From House:";
|
|
4
|
+
const HOUSE_LINE = "Work with House through the `house` CLI: run `house --help`, and `house find_command` for House's guides and formats.";
|
|
5
|
+
const FILE_LINE = 'To give the User a file, upload it with `house upload` and link it; for an App, a Site or a website, follow `house find_command \'{"query":"app"}\'`. Never start a server.';
|
|
6
|
+
const READ_LINE = "Optional per-Room instructions: `/rooms/private/rooms/<handle>/AGENTS.md`.";
|
|
7
|
+
const COPIES_LINE = `House Local copies; before work run \`house fetch\` and rebase onto \`${HOUSE_REF}\`; after it commit, then \`house push\`:`;
|
|
6
8
|
const UNREADABLE = /^(?:\S+: )?(?:path_not_found|room_not_found|operation_denied)\b/;
|
|
7
9
|
const FAILED = /^exit: [1-9]\d*$/;
|
|
8
10
|
const CUT = /^stderr: shell: output_cut (\d+) of \d+ bytes; continue with: (.+)$/;
|
|
@@ -29,6 +31,6 @@ async function howWeWork(bridge) {
|
|
|
29
31
|
return document.replace(/\n$/, '');
|
|
30
32
|
}
|
|
31
33
|
export async function instructions(bridge, base, copies) {
|
|
32
|
-
const lines = [HOUSE_LINE, FILE_LINE, READ_LINE, ...(copies.length === 0 ? [] : [COPIES_LINE, ...copies])];
|
|
34
|
+
const lines = [SOURCE_LINE, HOUSE_LINE, FILE_LINE, READ_LINE, ...(copies.length === 0 ? [] : [COPIES_LINE, ...copies])];
|
|
33
35
|
return [lines.join('\n'), base, await howWeWork(bridge)].filter((part) => part !== '').join('\n\n');
|
|
34
36
|
}
|