@agentshouse/kit 0.2.1-ccffb3f637815 → 0.2.1-cd423aab3dbcc

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/dist/earlier.js CHANGED
@@ -21,7 +21,7 @@ const WINDOWS_COPY = '.house-kit-home';
21
21
  const WINDOWS_WORKSPACE = 'workspace';
22
22
  const PLACEMENT = 'placement';
23
23
  const RELEASES = 'kit';
24
- const WORKSPACE_FOLDERS = ['agents', 'local-copies'];
24
+ const WORKSPACE_FOLDERS = ['agents', 'local-copies', 'rooms'];
25
25
  const RECORDS = join('local-copies', 'rooms');
26
26
  const COMMANDS = ['kit', 'house'];
27
27
  const DROPPED_FLAGS = / --(?:linux|container)$/u;
@@ -64,10 +64,20 @@ function desktopKit() {
64
64
  const workspace = value('HOUSE_KIT_WORKSPACE') ?? desktopWorkspace();
65
65
  return { kind: 'desktop', home: named ?? join(homedir(), '.house-kit'), workspace, seen: workspace, unit: named !== undefined };
66
66
  }
67
+ function unitAccount(unit) {
68
+ return /^User=(.+)$/mu.exec(unit)?.[1];
69
+ }
70
+ function account() {
71
+ return spawnSync('id', ['-un'], { encoding: 'utf8' }).stdout.trim();
72
+ }
73
+ export function otherAccountKit() {
74
+ const unit = readText(SERVER_UNIT);
75
+ const runs = unit === null ? undefined : unitAccount(unit);
76
+ return runs === undefined || runs === account() ? null : runs;
77
+ }
67
78
  function serverKit() {
68
79
  const unit = readText(SERVER_UNIT);
69
- const account = spawnSync('id', ['-un'], { encoding: 'utf8' }).stdout.trim();
70
- if (unit !== null && !new RegExp(`^User=${account}$`, 'mu').test(unit))
80
+ if (unit !== null && unitAccount(unit) !== account())
71
81
  return null;
72
82
  if (unit === null && !(root() && existsSync(SERVER_PREFIX)))
73
83
  return null;
package/dist/git.js CHANGED
@@ -1,14 +1,5 @@
1
1
  import { spawn } from 'node:child_process';
2
- import { isUtf8 } from 'node:buffer';
3
- import { createHash } from 'node:crypto';
4
- import { join } from 'node:path';
5
- import { workspaceRoot } from './home.js';
6
2
  import { childEnvironment } from './relay.js';
7
- export function localCopies() {
8
- return join(workspaceRoot(), 'local-copies');
9
- }
10
- export const HOUSE_REF = 'refs/house/received';
11
- const COMMITTER = 'Kit <house-kit@localhost>';
12
3
  export function run(cwd, args, input, env = {}) {
13
4
  return new Promise((resolve, reject) => {
14
5
  const child = spawn('git', args, { cwd, env: { ...childEnvironment(), ...env } });
@@ -24,139 +15,3 @@ export function run(cwd, args, input, env = {}) {
24
15
  child.stdin.end(input);
25
16
  });
26
17
  }
27
- export async function git(cwd, args, input, env) {
28
- const ran = await run(cwd, args, input, env);
29
- if (ran.status !== 0)
30
- throw new Error(`git ${args[0]} failed: ${ran.stderr.trim()}`);
31
- return ran.stdout.toString('utf8');
32
- }
33
- export async function succeeded(cwd, args, env) {
34
- return (await run(cwd, args, undefined, env)).status === 0;
35
- }
36
- export async function revision(cwd, name) {
37
- return (await git(cwd, ['rev-parse', '--verify', `${name}^{commit}`])).trim();
38
- }
39
- export async function tree(repository, commit) {
40
- const listed = await git(repository, ['ls-tree', '-r', '-z', commit]);
41
- const entries = new Map();
42
- for (const entry of listed.split('\0')) {
43
- const tab = entry.indexOf('\t');
44
- if (tab < 0)
45
- continue;
46
- const [, type, object] = entry.slice(0, tab).split(' ');
47
- if (type === 'blob')
48
- entries.set(entry.slice(tab + 1), object);
49
- }
50
- return entries;
51
- }
52
- async function blob(repository, object) {
53
- return (await run(repository, ['cat-file', 'blob', object])).stdout;
54
- }
55
- export async function blobText(repository, object) {
56
- return (await blob(repository, object)).toString('utf8');
57
- }
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;
73
- const bytes = await blob(repository, object);
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();
98
- }
99
- export function blobId(content) {
100
- if (typeof content !== 'string')
101
- return content.blob;
102
- const bytes = Buffer.from(content, 'utf8');
103
- return createHash('sha1').update(`blob ${bytes.length}\0`).update(bytes).digest('hex');
104
- }
105
- function quoted(path) {
106
- return `"${path.replace(/[\\"]/g, '\\$&').replace(/\n/g, '\\n')}"`;
107
- }
108
- function data(text) {
109
- const bytes = Buffer.from(text, 'utf8');
110
- return [Buffer.from(`data ${bytes.length}\n`), bytes, Buffer.from('\n')];
111
- }
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'));
119
- for (const [index, commit] of commits.entries()) {
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`));
133
- }
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;
158
- }
159
- if ((await closed) !== 0)
160
- throw new Error(`git fast-import failed: ${stderr.trim()}`);
161
- return revision(repository, HOUSE_REF);
162
- }
package/dist/home.js CHANGED
@@ -31,6 +31,9 @@ function privateDirectory(path) {
31
31
  export function oneFolder(account = homedir()) {
32
32
  return join(account, '.agents', 'house');
33
33
  }
34
+ export function houseFolder(account = homedir()) {
35
+ return join(account, 'house');
36
+ }
34
37
  export function desktopPrefix() {
35
38
  return join(homedir(), '.local', 'share', 'house-kit');
36
39
  }
@@ -77,11 +80,14 @@ export function ownerLock() {
77
80
  export function workspaceRoot() {
78
81
  if (earlierPrefix() !== null)
79
82
  return process.env.HOUSE_KIT_WORKSPACE ?? '/agents/house';
80
- return configuredWorkspace() ?? kitHome();
83
+ return configuredWorkspace() ?? houseFolder();
81
84
  }
82
85
  export function agentBase() {
83
86
  return join(workspaceRoot(), 'agents');
84
87
  }
88
+ export function roomsFolder() {
89
+ return join(workspaceRoot(), 'rooms');
90
+ }
85
91
  function parsed(name, text) {
86
92
  try {
87
93
  return JSON.parse(text);
@@ -196,7 +202,7 @@ function configuredWorkspace() {
196
202
  }
197
203
  export async function readConfiguration() {
198
204
  const stored = await readHome(CONFIGURATION);
199
- return { skills: stored?.skills !== false, workspace: stored?.workspace ?? kitHome() };
205
+ return { skills: stored?.skills !== false, workspace: stored?.workspace ?? houseFolder() };
200
206
  }
201
207
  export async function storedConfiguration() {
202
208
  return (await readHome(CONFIGURATION)) ?? {};
package/dist/house-cli.js CHANGED
@@ -1,25 +1,23 @@
1
- import { createHash } from 'node:crypto';
2
- import { createReadStream } from 'node:fs';
3
1
  import { request } from 'node:http';
4
2
  import { resolve } from 'node:path';
5
3
  import { text as textOf } from 'node:stream/consumers';
6
4
  import { downloaded, fileInfo, fileRange, mediaTypeOf, opened, sentPart, storeRefusal, uploaded, } from './files.js';
7
- import { HOUSE_REF } from './git.js';
5
+ import { DEFAULT_MAX_SIZE, UPLOAD_NEEDS_OWNER } from './copies.js';
8
6
  import { ownerSocket } from './home.js';
7
+ import { fileDigest } from './manifest.js';
9
8
  import { ownAgentCall, rpc, unconfirmed, UNREACHABLE } from './mcp.js';
10
9
  import { refusalOf } from './refusals.js';
11
10
  import { parse } from 'yaml';
12
11
  const USAGE = "usage: house <tool> ['<arguments as JSON>'], or house <tool> - to read them from stdin; house help <tool>: its arguments";
13
12
  const HELP = 'help [tool]';
14
- const PUSH_USAGE = 'usage: house push [commit] [--owner]';
15
- const PUSH = "push [commit]: sends the Local copy's committed changes to House in one push, each .md file as document text and every other file as an attachment";
16
- const FETCH_USAGE = 'usage: house fetch';
17
- const FETCH = `fetch: records House's changes on each Local copy's ${HOUSE_REF}`;
18
- const DOWNLOAD_USAGE = `usage: house download '{"path":"/rooms/<handle>/<path>","file":"<local file>"}', adding "ref" for a revision`;
19
- const DOWNLOAD = 'download: writes a binary file of a Room to the local file named by file';
20
- const UPLOAD_USAGE = `usage: house upload '{"file":"<local file>","room_ref":"r_…","path":"<path in the Room>"}', adding "base", the revision it replaces`;
13
+ const UPLOAD_USAGE = `usage: house upload [--owner], or house upload '{"file":"<local file>","path":"/rooms/<handle>/<path>"}', adding "base", the revision it replaces`;
14
+ const UPLOAD = "upload: in a Room's Local copy, sends every file changed, added or deleted there since it last matched House, each .md file as document text and every other file as an attachment, with --owner outside an Agent conversation; with JSON, sends one local file to the Room path it names";
15
+ const DOWNLOAD_USAGE = `usage: house download [--with-attachments] [--max-size <MB>], or house download '{"path":"/rooms/<handle>/<path>","file":"<local file>"}', adding "ref" for a revision`;
16
+ const DOWNLOAD = `download: brings House's changes into every Local copy, leaving each file changed here for the next house upload, and with --with-attachments each attachment it lacks up to --max-size megabytes, ${DEFAULT_MAX_SIZE} by default; with JSON, writes one attachment of a Room to the local file named by file`;
17
+ const MAX_SIZE = `--max-size takes a number of megabytes; ${DOWNLOAD_USAGE}`;
18
+ const MEGABYTES = /^\d+(?:\.\d+)?$/;
21
19
  const ARGUMENTS = `the arguments are one JSON object, in single quotes or on stdin after -, like house search '{"query":"invoice"}'`;
22
- const CLOSED = "this conversation's House connection is closed; nothing to do from here";
20
+ const CLOSED = 'this House connection is closed; nothing to do from here';
23
21
  const SANDBOXED = "your CLI's sandbox kept house from House; run house directly, not through another program";
24
22
  const REVOKED = 'this conversation no longer has House access; nothing to do from here';
25
23
  const socketPath = process.env.HOUSE_BRIDGE;
@@ -71,9 +69,20 @@ function unreadable(path, error) {
71
69
  : `${path} is not a readable file`);
72
70
  }
73
71
  async function download(args) {
74
- const { flags, positionals: [argument] } = accepted(args, ['--help'], 1, DOWNLOAD_USAGE);
72
+ const valued = args.indexOf('--max-size');
73
+ const size = valued === -1 ? undefined : args[valued + 1];
74
+ const rest = valued === -1 ? args : args.filter((_arg, index) => index !== valued && index !== valued + 1);
75
+ const { flags, positionals: [argument] } = accepted(rest, ['--help', '--with-attachments'], 1, DOWNLOAD_USAGE);
75
76
  if (flags.has('--help'))
76
- return DOWNLOAD_USAGE;
77
+ return `${DOWNLOAD_USAGE}\n${DOWNLOAD}`;
78
+ if (argument === undefined) {
79
+ if (valued !== -1 && !MEGABYTES.test(size ?? ''))
80
+ throw new Error(MAX_SIZE);
81
+ const maxSize = size === undefined ? DEFAULT_MAX_SIZE : Number(size);
82
+ return copyVerb('/copy/download', { attachments: flags.has('--with-attachments'), max_size: maxSize });
83
+ }
84
+ if (valued !== -1 || flags.has('--with-attachments'))
85
+ throw unexpected(valued !== -1 ? '--max-size' : '--with-attachments', DOWNLOAD_USAGE);
77
86
  const { file, ...selected } = await argumentsOf(argument);
78
87
  if (typeof file !== 'string' || file === '')
79
88
  throw new Error('download needs "file", the local file to write');
@@ -90,22 +99,18 @@ async function download(args) {
90
99
  return written;
91
100
  }
92
101
  async function described(file) {
93
- const digest = createHash('sha256');
94
- let bytes = 0;
102
+ let held;
95
103
  try {
96
- for await (const chunk of createReadStream(file)) {
97
- digest.update(chunk);
98
- bytes += chunk.length;
99
- }
104
+ held = await fileDigest(file);
100
105
  }
101
106
  catch (error) {
102
107
  throw unreadable(file, error);
103
108
  }
104
109
  const mediaType = mediaTypeOf(file);
105
- return { bytes, sha256: digest.digest('hex'), ...(mediaType === undefined ? {} : { media_type: mediaType }) };
110
+ return { bytes: held.bytes, sha256: held.sha256, ...(mediaType === undefined ? {} : { media_type: mediaType }) };
106
111
  }
107
- async function finished(upload, room, partSha256) {
108
- const text = await called('upload', { upload, room_ref: room, part_sha256: partSha256 });
112
+ async function finished(upload, path, partSha256) {
113
+ const text = await called('upload', { upload, path, part_sha256: partSha256 });
109
114
  const answer = parse(text);
110
115
  return answer !== null && 'upload' in answer ? answer : { text };
111
116
  }
@@ -123,7 +128,7 @@ async function upload({ file, ...destination }) {
123
128
  sha256: description.sha256,
124
129
  read: (start, end) => fileRange(file, start, end, (error) => unreadable(file, error)),
125
130
  send: (url, start, end, headers) => sentPart(url, file, start, end, headers, WAY),
126
- finish: (id, partSha256) => finished(id, destination.room_ref, partSha256),
131
+ finish: (id, partSha256) => finished(id, destination.path, partSha256),
127
132
  });
128
133
  return accepted.text;
129
134
  }
@@ -142,28 +147,26 @@ function accepted(args, flags, positionals, usage) {
142
147
  }
143
148
  return given;
144
149
  }
145
- async function push(args) {
146
- const { flags, positionals: [commit = 'HEAD'] } = accepted(args, ['--help', '--owner'], 1, PUSH_USAGE);
147
- if (flags.has('--help'))
148
- return `${PUSH_USAGE}\n${PUSH}`;
149
- const owner = flags.has('--owner');
150
- if (owner && socketPath !== undefined)
151
- throw new Error('--owner is not for Agent conversations; run house push without it');
152
- if (!owner && socketPath === undefined)
153
- throw new Error('outside an Agent conversation, house push needs --owner');
154
- const pushed = JSON.parse(await bridged('/git/push', { cwd: process.cwd(), commit }, owner ? ownerSocket() : socketPath));
155
- if (pushed.refused)
156
- throw new Error(pushed.text);
157
- return pushed.text;
158
- }
159
- async function fetched(args) {
160
- if (accepted(args, ['--help'], 0, FETCH_USAGE).flags.has('--help'))
161
- return FETCH_USAGE;
162
- const answer = JSON.parse(await bridged('/git/fetch', {}, socketPath ?? ownerSocket()));
150
+ async function copyVerb(path, body) {
151
+ const answer = JSON.parse(await bridged(path, body, socketPath ?? ownerSocket()));
163
152
  if (answer.refused)
164
153
  throw new Error(answer.text);
165
154
  return answer.text;
166
155
  }
156
+ async function uploadVerb(args) {
157
+ const { flags, positionals: [argument] } = accepted(args, ['--help', '--owner'], 1, UPLOAD_USAGE);
158
+ if (flags.has('--help'))
159
+ return `${UPLOAD_USAGE}\n${UPLOAD}`;
160
+ if (argument !== undefined) {
161
+ if (flags.has('--owner'))
162
+ throw unexpected('--owner', UPLOAD_USAGE);
163
+ return upload(await argumentsOf(argument));
164
+ }
165
+ const owner = flags.has('--owner');
166
+ if (!owner && socketPath === undefined)
167
+ throw new Error(UPLOAD_NEEDS_OWNER);
168
+ return copyVerb('/copy/upload', { cwd: process.cwd(), owner });
169
+ }
167
170
  async function argumentsOf(argument) {
168
171
  if (argument === undefined)
169
172
  return {};
@@ -246,12 +249,11 @@ async function house(args) {
246
249
  return run([argument, '--help']);
247
250
  if (verb === undefined || verb === 'help') {
248
251
  const listing = (await tools()).flatMap((tool) => tool.description === undefined ? [tool.name, ...argumentLines(tool.inputSchema, tool.inputSchema, ' ', false)] : [listed(tool)]);
249
- return [USAGE, HELP, PUSH, FETCH, DOWNLOAD, ...listing].join('\n');
252
+ return [USAGE, HELP, UPLOAD, DOWNLOAD, ...listing].join('\n');
250
253
  }
251
254
  if (flags.has('--help'))
252
- return verb === 'upload' ? UPLOAD_USAGE : toolHelp(verb);
253
- const parsed = await argumentsOf(argument);
254
- return verb === 'upload' ? upload(parsed) : called(verb, parsed);
255
+ return toolHelp(verb);
256
+ return called(verb, await argumentsOf(argument));
255
257
  }
256
258
  async function called(name, args) {
257
259
  const result = await mcp('tools/call', { name, arguments: args });
@@ -263,10 +265,8 @@ async function called(name, args) {
263
265
  function run(argv) {
264
266
  const named = argv.findIndex((arg) => !arg.startsWith('-'));
265
267
  const rest = argv.filter((_arg, index) => index !== named);
266
- if (argv[named] === 'push')
267
- return push(rest);
268
- if (argv[named] === 'fetch')
269
- return fetched(rest);
268
+ if (argv[named] === 'upload')
269
+ return uploadVerb(rest);
270
270
  if (argv[named] === 'download')
271
271
  return download(rest);
272
272
  return house(argv);
@@ -0,0 +1,75 @@
1
+ import { createHash, randomUUID } from 'node:crypto';
2
+ import { createReadStream } from 'node:fs';
3
+ import { mkdir, readFile, readdir, rename, rm, rmdir, writeFile } from 'node:fs/promises';
4
+ import { dirname, join } from 'node:path';
5
+ export const MANIFEST = '.house';
6
+ const UNREAD = '.git';
7
+ const MARKER = /^(?:<{7}|={7}|>{7})(?: .*)?$/m;
8
+ export function digest(bytes) {
9
+ return createHash('sha256').update(bytes).digest('hex');
10
+ }
11
+ export async function fileDigest(file) {
12
+ const hash = createHash('sha256');
13
+ let bytes = 0;
14
+ for await (const chunk of createReadStream(file)) {
15
+ hash.update(chunk);
16
+ bytes += chunk.length;
17
+ }
18
+ return { sha256: hash.digest('hex'), bytes };
19
+ }
20
+ export async function hashed(file) {
21
+ try {
22
+ return await fileDigest(file);
23
+ }
24
+ catch (error) {
25
+ if (error.code === 'ENOENT' || error.code === 'EISDIR')
26
+ return null;
27
+ throw error;
28
+ }
29
+ }
30
+ export async function holding(repository, name, sha256) {
31
+ return (await hashed(join(repository, name)))?.sha256 === sha256;
32
+ }
33
+ export async function readManifest(repository) {
34
+ return JSON.parse(await readFile(join(repository, MANIFEST), 'utf8'));
35
+ }
36
+ export async function placed(staging, target, content) {
37
+ const temporary = `${staging}${randomUUID()}`;
38
+ await writeFile(temporary, content);
39
+ await mkdir(dirname(target), { recursive: true });
40
+ await rename(temporary, target);
41
+ }
42
+ export async function writeManifest(repository, staging, manifest) {
43
+ const files = Object.fromEntries(Object.entries(manifest.files).sort(([left], [right]) => (left < right ? -1 : 1)));
44
+ await placed(staging, join(repository, MANIFEST), `${JSON.stringify({ room_ref: manifest.room_ref, files })}\n`);
45
+ }
46
+ export async function removed(repository, name) {
47
+ await rm(join(repository, name), { force: true });
48
+ for (let folder = dirname(name); folder !== '.'; folder = dirname(folder)) {
49
+ if (!(await rmdir(join(repository, folder)).then(() => true, () => false)))
50
+ return;
51
+ }
52
+ }
53
+ export async function scanned(repository) {
54
+ const present = new Map();
55
+ const walk = async (folder) => {
56
+ for (const entry of await readdir(join(repository, folder), { withFileTypes: true })) {
57
+ const name = folder === '' ? entry.name : `${folder}/${entry.name}`;
58
+ if (folder === '' && (entry.name === MANIFEST || entry.name === UNREAD))
59
+ continue;
60
+ if (entry.isDirectory())
61
+ await walk(name);
62
+ else if (entry.isFile()) {
63
+ const file = await hashed(join(repository, name));
64
+ if (file !== null)
65
+ present.set(name.normalize('NFC'), { name, ...file });
66
+ }
67
+ }
68
+ };
69
+ await walk('');
70
+ return present;
71
+ }
72
+ export async function marked(repository, name) {
73
+ const text = await readFile(join(repository, name), 'utf8').catch(() => null);
74
+ return text !== null && MARKER.test(text);
75
+ }
package/dist/mcp.js CHANGED
@@ -7,14 +7,14 @@ import { relayed, selectRelay } from './relay.js';
7
7
  const MCP_PROTOCOL_VERSION = '2026-07-28';
8
8
  export const UNREACHABLE = 'House is unreachable; call again in a minute';
9
9
  const UNCONNECTED = "this computer's own agent has no House connection; run kit login";
10
- const DISCONNECTED = "House no longer accepts this computer's own agent; run kit login";
10
+ export const DISCONNECTED = "House no longer accepts this computer's own agent; run kit login";
11
11
  const UNCONFIRMED = 'with no result; a write may or may not have taken effect, so read before you repeat it';
12
12
  export class Unsettled extends Error {
13
13
  }
14
14
  export function rpc(method, params) {
15
15
  return { jsonrpc: '2.0', id: randomUUID(), method, params };
16
16
  }
17
- export function mcpBody(message, operation) {
17
+ export function mcpBody(message, { operation = null, named = {} } = {}) {
18
18
  return JSON.stringify({
19
19
  ...message,
20
20
  params: {
@@ -23,12 +23,13 @@ export function mcpBody(message, operation) {
23
23
  'io.modelcontextprotocol/protocolVersion': MCP_PROTOCOL_VERSION,
24
24
  'io.modelcontextprotocol/clientInfo': { name: '@agentshouse/kit', version: KIT_RELEASE },
25
25
  'io.modelcontextprotocol/clientCapabilities': {},
26
+ ...named,
26
27
  ...(operation === null ? {} : { 'agents.house/agent-operation': operation }),
27
28
  },
28
29
  },
29
30
  });
30
31
  }
31
- export async function callHouse(origin, credential, message, operation = null, signal) {
32
+ export async function callHouse(origin, credential, message, sending = {}) {
32
33
  const tool = message.method === 'tools/call' ? String(message.params.name) : null;
33
34
  const answer = await fetch(relayed(new URL('/', origin)), {
34
35
  method: 'POST',
@@ -41,8 +42,8 @@ export async function callHouse(origin, credential, message, operation = null, s
41
42
  ...(tool === null ? {} : { 'mcp-name': tool }),
42
43
  [KIT_WIRE_HEADER]: KIT_WIRE,
43
44
  },
44
- body: mcpBody(message, operation),
45
- signal,
45
+ body: mcpBody(message, sending),
46
+ signal: sending.signal,
46
47
  });
47
48
  return { status: answer.status, text: await answer.text() };
48
49
  }
package/dist/refusals.js CHANGED
@@ -14,7 +14,16 @@ function detailOf(text) {
14
14
  function conflictsOf(detail) {
15
15
  if (!Array.isArray(detail.conflicts))
16
16
  return [];
17
- return detail.conflicts.flatMap((conflict) => typeof conflict?.code === 'string' ? [{ code: conflict.code, path: typeof conflict.path === 'string' ? conflict.path : '' }] : []);
17
+ return detail.conflicts.flatMap((conflict) => typeof conflict?.code === 'string'
18
+ ? [
19
+ {
20
+ code: conflict.code,
21
+ path: typeof conflict.path === 'string' ? conflict.path : '',
22
+ ...(typeof conflict.revision === 'string' ? { revision: conflict.revision } : {}),
23
+ ...(typeof conflict.content === 'string' ? { content: conflict.content } : {}),
24
+ },
25
+ ]
26
+ : []);
18
27
  }
19
28
  function spoken(text) {
20
29
  const head = HEAD.exec(text);
@@ -58,12 +67,14 @@ export function refusalOf(text) {
58
67
  const error = errorIn(answer.body);
59
68
  if (error === null)
60
69
  return null;
61
- const { code, message, data } = error;
70
+ const { code, message, data, retryable: _retryable, ...fields } = error;
62
71
  const verdict = verdictOf(error);
63
72
  const judged = verdict === null ? {} : { retryable: verdict };
64
73
  const said = typeof message === 'string' ? spoken(message) : null;
65
- if (said !== null)
66
- return { ...said, ...judged };
74
+ if (said !== null) {
75
+ const detail = { ...said.detail, ...fields };
76
+ return { ...said, detail, conflicts: conflictsOf(detail), ...judged };
77
+ }
67
78
  const named = typeof code === 'string' ? code : typeof data?.code === 'string' ? data.code : null;
68
79
  return named === null ? null : { code: named, text: named, conflicts: [], detail: {}, ...judged };
69
80
  }
package/dist/resident.js CHANGED
@@ -8,16 +8,16 @@ import { Agents } from './agents.js';
8
8
  import { house } from './api.js';
9
9
  import { received } from './bridge.js';
10
10
  import { Conversations } from './conversations.js';
11
- import { LocalCopies } from './copies.js';
11
+ import { DEFAULT_MAX_SIZE, LocalCopies } from './copies.js';
12
12
  import { restart, restartPlaced } from './end.js';
13
- import { agentBase, enrolled, kitHome, ownerSocket, readEnrolment, recordPlannedRestart, takePlannedRestart } from './home.js';
13
+ import { agentBase, enrolled, kitHome, ownerSocket, readEnrolment, recordPlannedRestart, roomsFolder, takePlannedRestart } from './home.js';
14
14
  import { Calls } from './calls.js';
15
15
  import { KIT_RELEASE } from './clis.js';
16
16
  import { moveEarlier } from './earlier.js';
17
17
  import { holdOwner } from './owner.js';
18
18
  import { killDescendants } from './scope.js';
19
19
  import { removeInputs, Scripts } from './scripts.js';
20
- import { applySettings, enrolledRoutes, resumeWorkspaceMove } from './settings.js';
20
+ import { applySettings, enrolledRoutes, launchDirectories, moveIntoHouse, resumeWorkspaceMove } from './settings.js';
21
21
  import { quoted } from './shell.js';
22
22
  import { SignIns } from './sign-in.js';
23
23
  import { placeSkillSet } from './skills.js';
@@ -45,12 +45,13 @@ async function serveOwner(lock, copies, settling) {
45
45
  response.writeHead(200, { 'content-type': 'application/json' }).end(JSON.stringify({ pid: process.pid, release: KIT_RELEASE }));
46
46
  return;
47
47
  }
48
- if (request.url === '/git/fetch') {
49
- answered = await copies.fetch(copies.owner);
48
+ if (request.url === '/copy/download') {
49
+ const { attachments = false, max_size: maxSize = DEFAULT_MAX_SIZE } = JSON.parse(text);
50
+ answered = await copies.download(copies.owner, { attachments, maxSize });
50
51
  }
51
- else if (request.url === '/git/push') {
52
- const { cwd, commit } = JSON.parse(text);
53
- answered = await copies.push(cwd, commit, copies.owner);
52
+ else if (request.url === '/copy/upload') {
53
+ const { cwd } = JSON.parse(text);
54
+ answered = await copies.upload(cwd, copies.owner);
54
55
  }
55
56
  else if (request.url === '/settings') {
56
57
  const applied = await settling.settle(JSON.parse(text));
@@ -91,18 +92,22 @@ function connected() {
91
92
  async function started() {
92
93
  await connected();
93
94
  await placeSkillSet((await readEnrolment()).house);
94
- await mkdir(agentBase(), { recursive: true });
95
- await installShim(join(kitHome(), 'shim', 'git'), 'git-main');
95
+ await mkdir(agentBase(), { recursive: true, mode: 0o700 });
96
+ await mkdir(roomsFolder(), { recursive: true, mode: 0o700 });
97
+ await rm(join(kitHome(), 'shim'), { recursive: true, force: true });
96
98
  await installShim(codexLauncher(), 'codex-main');
97
99
  }
98
100
  export async function resident() {
99
101
  await moveEarlier();
100
102
  await mkdir(kitHome(), { recursive: true, mode: 0o700 });
101
103
  const lock = await holdOwner();
102
- const planned = takePlannedRestart();
103
104
  await resumeWorkspaceMove();
104
- const copies = new LocalCopies(house);
105
+ const copies = new LocalCopies(house, launchDirectories);
105
106
  await copies.load();
107
+ const moved = await moveIntoHouse(copies);
108
+ if (moved !== null)
109
+ restart(moved);
110
+ const planned = takePlannedRestart();
106
111
  let running = null;
107
112
  let settings = Promise.resolve();
108
113
  const settle = (change) => {
@@ -184,7 +189,7 @@ export async function resident() {
184
189
  const update = new KitUpdate(calls);
185
190
  takeUnservedRelease((release) => logged(update.takeRefused(release)));
186
191
  removeInputs();
187
- const scripts = new Scripts(calls, (oneWayCall) => connection?.send(oneWayCall) ?? false);
192
+ const scripts = new Scripts(calls, (oneWayCall) => connection?.send(oneWayCall) ?? false, house, copies);
188
193
  running = { conversations, agents, calls, stop };
189
194
  for (const signal of ['SIGTERM', 'SIGINT']) {
190
195
  process.once(signal, () => {