@agentshouse/kit 0.2.1-ceeaf32286734 → 0.2.1-ceffdba88db37
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 +14 -15
- package/dist/acp.js +1 -1
- package/dist/afk.js +17 -0
- package/dist/agents.js +54 -25
- package/dist/api.js +11 -6
- package/dist/authority-main.js +2 -2
- package/dist/bridge.js +4 -4
- package/dist/building.js +7 -3
- package/dist/calls.js +1 -1
- package/dist/chunks.js +49 -0
- package/dist/clis.js +35 -57
- package/dist/connection.js +24 -20
- package/dist/content.js +63 -0
- package/dist/conversations.js +236 -115
- package/dist/copies.js +293 -148
- package/dist/end.js +2 -9
- package/dist/events.js +729 -218
- package/dist/files.js +2 -2
- package/dist/git.js +44 -10
- package/dist/grok.js +39 -0
- package/dist/home.js +0 -7
- package/dist/house-cli.js +81 -21
- package/dist/instructions.js +2 -4
- package/dist/kit-cli.js +1 -4
- package/dist/login.js +12 -5
- package/dist/logout.js +2 -2
- package/dist/mcp.js +2 -2
- package/dist/placement.js +9 -23
- package/dist/resident.js +44 -37
- package/dist/scope.js +12 -4
- package/dist/scripts.js +59 -11
- package/dist/secret-input.js +1 -1
- package/dist/transcription.js +5 -2
- package/dist/translate.js +18 -9
- package/dist/update.js +105 -159
- package/dist/wire.js +19 -9
- package/dist/work.js +9 -2
- package/package.json +12 -8
- package/dist/chatgpt.js +0 -32
- package/dist/clis-main.js +0 -23
- package/dist/parts.js +0 -82
package/dist/files.js
CHANGED
|
@@ -27,7 +27,7 @@ export function inspectedFile(answer) {
|
|
|
27
27
|
media_type: typeof inspected.media_type === 'string' ? inspected.media_type : null,
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
|
-
function paused(milliseconds) {
|
|
30
|
+
export function paused(milliseconds) {
|
|
31
31
|
return new Promise((resolve) => setTimeout(resolve, milliseconds));
|
|
32
32
|
}
|
|
33
33
|
export function storeRefusal(act, status) {
|
|
@@ -140,5 +140,5 @@ export async function downloaded(address, fetching, destination, name) {
|
|
|
140
140
|
}
|
|
141
141
|
export async function fetched(url, signal) {
|
|
142
142
|
const answer = await fetch(relayed(url), { signal });
|
|
143
|
-
return { status: answer.status, body: answer.body
|
|
143
|
+
return { status: answer.status, body: answer.body === null ? Readable.from([]) : Readable.fromWeb(answer.body) };
|
|
144
144
|
}
|
package/dist/git.js
CHANGED
|
@@ -70,18 +70,52 @@ function data(text) {
|
|
|
70
70
|
const bytes = Buffer.from(text, 'utf8');
|
|
71
71
|
return [Buffer.from(`data ${bytes.length}\n`), bytes, Buffer.from('\n')];
|
|
72
72
|
}
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
function written(stream, bytes) {
|
|
74
|
+
return new Promise((resolve, reject) => {
|
|
75
|
+
stream.write(bytes, (error) => (error ? reject(error) : resolve()));
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
async function imported(stream, commits) {
|
|
79
|
+
await written(stream, Buffer.from('feature done\n'));
|
|
75
80
|
for (const [index, commit] of commits.entries()) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
81
|
+
await written(stream, Buffer.concat([
|
|
82
|
+
Buffer.from(`commit ${HOUSE_REF}\nmark :${index + 1}\ncommitter ${COMMITTER} ${Math.floor(Date.now() / 1000)} +0000\n`),
|
|
83
|
+
...data(commit.message),
|
|
84
|
+
...(commit.from === null ? [] : [Buffer.from(`from ${commit.from}\n`)]),
|
|
85
|
+
...(commit.merge === undefined ? [] : [Buffer.from(`merge ${commit.merge}\n`)]),
|
|
86
|
+
...(commit.replaces === true ? [Buffer.from('deleteall\n')] : []),
|
|
87
|
+
]));
|
|
88
|
+
for await (const [path, content] of commit.files) {
|
|
89
|
+
await written(stream, content === null
|
|
90
|
+
? Buffer.from(`D ${quoted(path)}\n`)
|
|
91
|
+
: Buffer.concat([Buffer.from(`M 100644 inline ${quoted(path)}\n`), ...data(content)]));
|
|
82
92
|
}
|
|
83
|
-
stream
|
|
93
|
+
await written(stream, Buffer.from('\n'));
|
|
94
|
+
}
|
|
95
|
+
await written(stream, Buffer.from('done\n'));
|
|
96
|
+
}
|
|
97
|
+
export async function importCommits(repository, commits) {
|
|
98
|
+
const child = spawn('git', ['fast-import', '--quiet', '--force'], { cwd: repository, env: childEnvironment() });
|
|
99
|
+
let stderr = '';
|
|
100
|
+
child.stdout.resume();
|
|
101
|
+
child.stderr.on('data', (chunk) => {
|
|
102
|
+
stderr += chunk.toString('utf8');
|
|
103
|
+
});
|
|
104
|
+
child.stdin.on('error', () => undefined);
|
|
105
|
+
const closed = new Promise((resolve, reject) => {
|
|
106
|
+
child.on('error', reject);
|
|
107
|
+
child.on('close', resolve);
|
|
108
|
+
});
|
|
109
|
+
try {
|
|
110
|
+
await imported(child.stdin, commits);
|
|
111
|
+
child.stdin.end();
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
child.stdin.destroy();
|
|
115
|
+
await closed;
|
|
116
|
+
throw error.code === 'EPIPE' ? new Error(`git fast-import failed: ${stderr.trim()}`) : error;
|
|
84
117
|
}
|
|
85
|
-
|
|
118
|
+
if ((await closed) !== 0)
|
|
119
|
+
throw new Error(`git fast-import failed: ${stderr.trim()}`);
|
|
86
120
|
return revision(repository, HOUSE_REF);
|
|
87
121
|
}
|
package/dist/grok.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
const PLAN = 'plan';
|
|
2
|
+
const PLAN_ABANDONED = 'abandoned';
|
|
3
|
+
const PLAN_FIELD = {
|
|
4
|
+
type: 'string',
|
|
5
|
+
title: 'Approve this plan?',
|
|
6
|
+
oneOf: [
|
|
7
|
+
{ const: 'approved', title: 'Approve' },
|
|
8
|
+
{ const: PLAN_ABANDONED, title: 'Abandon' },
|
|
9
|
+
],
|
|
10
|
+
};
|
|
11
|
+
function form(sessionId, message, properties) {
|
|
12
|
+
return { mode: 'form', sessionId, message, requestedSchema: { type: 'object', properties } };
|
|
13
|
+
}
|
|
14
|
+
function questionField({ options, multiSelect }, title) {
|
|
15
|
+
const choices = options.map(({ label, description }) => ({ const: label, title: label, description }));
|
|
16
|
+
return multiSelect === true ? { type: 'array', title, items: { anyOf: choices } } : { type: 'string', title, oneOf: choices };
|
|
17
|
+
}
|
|
18
|
+
export function grokQuestionForm({ sessionId, questions }) {
|
|
19
|
+
const lone = questions.length === 1;
|
|
20
|
+
return form(sessionId, questions.map(({ question }) => question).join('\n\n'), Object.fromEntries(questions.map((one) => [one.question, questionField(one, lone ? 'Answer' : one.question)])));
|
|
21
|
+
}
|
|
22
|
+
function answerText(value) {
|
|
23
|
+
return Array.isArray(value) ? value.join(', ') : String(value);
|
|
24
|
+
}
|
|
25
|
+
function contentOf(response) {
|
|
26
|
+
return response.action === 'accept' ? (response.content ?? {}) : {};
|
|
27
|
+
}
|
|
28
|
+
export function grokQuestionAnswer(response) {
|
|
29
|
+
if (response.action !== 'accept')
|
|
30
|
+
return { outcome: 'cancelled' };
|
|
31
|
+
const answers = Object.entries(contentOf(response)).map(([question, value]) => [question, answerText(value)]);
|
|
32
|
+
return { outcome: 'accepted', answers: Object.fromEntries(answers) };
|
|
33
|
+
}
|
|
34
|
+
export function grokPlanForm({ sessionId, planContent }) {
|
|
35
|
+
return form(sessionId, planContent, { [PLAN]: PLAN_FIELD });
|
|
36
|
+
}
|
|
37
|
+
export function grokPlanAnswer(response) {
|
|
38
|
+
return { outcome: contentOf(response)[PLAN] ?? PLAN_ABANDONED };
|
|
39
|
+
}
|
package/dist/home.js
CHANGED
|
@@ -8,7 +8,6 @@ const ENROLMENT = 'credential.json';
|
|
|
8
8
|
const DISCONNECTED = 'disconnected.json';
|
|
9
9
|
const CONFIGURATION = 'kit.json';
|
|
10
10
|
const OWN_AGENT = 'own-agent.json';
|
|
11
|
-
const RESTART = 'restart';
|
|
12
11
|
let defaulted;
|
|
13
12
|
function writable(directory) {
|
|
14
13
|
try {
|
|
@@ -132,12 +131,6 @@ export async function forgetRejected(rejected) {
|
|
|
132
131
|
export function enrolled() {
|
|
133
132
|
return existsSync(join(kitHome(), ENROLMENT));
|
|
134
133
|
}
|
|
135
|
-
export function restartAsked() {
|
|
136
|
-
return existsSync(join(kitHome(), RESTART));
|
|
137
|
-
}
|
|
138
|
-
export function forgetRestart() {
|
|
139
|
-
return rm(join(kitHome(), RESTART), { force: true });
|
|
140
|
-
}
|
|
141
134
|
export function readOwnAgent() {
|
|
142
135
|
return readHome(OWN_AGENT);
|
|
143
136
|
}
|
package/dist/house-cli.js
CHANGED
|
@@ -12,7 +12,8 @@ import { callHouse, rpc, UNREACHABLE, Unsettled } from './mcp.js';
|
|
|
12
12
|
import { refusalOf, retryable } from './refusals.js';
|
|
13
13
|
import { proxyUnlessRelayed, relayed, selectRelay } from './relay.js';
|
|
14
14
|
import { parse } from 'yaml';
|
|
15
|
-
const USAGE = "usage: house <tool> ['<arguments as JSON>']";
|
|
15
|
+
const USAGE = "usage: house <tool> ['<arguments as JSON>']; house help <tool>: its arguments";
|
|
16
|
+
const HELP = 'help [tool]';
|
|
16
17
|
const PUSH_USAGE = 'usage: house push [commit] [--owner]';
|
|
17
18
|
const PUSH = "push [commit]: sends the Local copy's committed changes to House";
|
|
18
19
|
const FETCH_USAGE = 'usage: house fetch';
|
|
@@ -23,8 +24,8 @@ const ARGUMENTS = `the arguments are one JSON object in single quotes, like hous
|
|
|
23
24
|
const CLOSED = "this conversation's House connection is closed; nothing to do from here";
|
|
24
25
|
const SANDBOXED = "your CLI's sandbox kept house from House; run house directly, not through another program";
|
|
25
26
|
const REVOKED = 'this conversation no longer has House access; nothing to do from here';
|
|
26
|
-
const UNCONNECTED = "this computer's own agent has no House connection; run kit login
|
|
27
|
-
const DISCONNECTED = "House no longer accepts this computer's own agent; run kit login
|
|
27
|
+
const UNCONNECTED = "this computer's own agent has no House connection; run kit login";
|
|
28
|
+
const DISCONNECTED = "House no longer accepts this computer's own agent; run kit login";
|
|
28
29
|
const UNCONFIRMED = 'with no result; a write may or may not have taken effect, so read before you repeat it';
|
|
29
30
|
const socketPath = process.env.HOUSE_BRIDGE;
|
|
30
31
|
const MEDIA_TYPES = new Map([
|
|
@@ -255,21 +256,77 @@ function argumentsOf(argument) {
|
|
|
255
256
|
throw new Error(ARGUMENTS);
|
|
256
257
|
return parsed;
|
|
257
258
|
}
|
|
259
|
+
// The schema a $ref points to inside the Tool's own inputSchema, or an empty one when it points elsewhere.
|
|
260
|
+
function resolved(schema, root) {
|
|
261
|
+
if (schema.$ref === undefined)
|
|
262
|
+
return schema;
|
|
263
|
+
if (!schema.$ref.startsWith('#'))
|
|
264
|
+
return {};
|
|
265
|
+
let found = root;
|
|
266
|
+
for (const key of schema.$ref.split('/').slice(1)) {
|
|
267
|
+
found = typeof found === 'object' && found !== null ? found[key.replaceAll('~1', '/').replaceAll('~0', '~')] : undefined;
|
|
268
|
+
}
|
|
269
|
+
return typeof found === 'object' && found !== null ? found : {};
|
|
270
|
+
}
|
|
271
|
+
// The schema a $ref resolves to, with that $ref added to the open ones, or null when it is open already,
|
|
272
|
+
// so a schema that holds itself is expanded once.
|
|
273
|
+
function expanded(schema, root, refs) {
|
|
274
|
+
if (schema.$ref === undefined)
|
|
275
|
+
return { schema, refs };
|
|
276
|
+
return refs.has(schema.$ref) ? null : { schema: resolved(schema, root), refs: new Set([...refs, schema.$ref]) };
|
|
277
|
+
}
|
|
278
|
+
// One line per argument: its name, its value when it has one or a few, whether it is required, and its
|
|
279
|
+
// description. When deep, the arguments its value holds follow it.
|
|
280
|
+
function argumentLines(schema, root, indent, deep, refs = new Set()) {
|
|
281
|
+
const required = new Set(schema.required ?? []);
|
|
282
|
+
return Object.entries(schema.properties ?? {}).flatMap(([name, property]) => {
|
|
283
|
+
const value = resolved(property, root);
|
|
284
|
+
const values = value.const !== undefined ? [value.const] : (value.enum ?? []);
|
|
285
|
+
const words = [name, ...(values.length === 0 ? [] : [values.map((one) => JSON.stringify(one)).join(' | ')]), ...(required.has(name) ? ['(required)'] : [])];
|
|
286
|
+
const description = property.description ?? value.description;
|
|
287
|
+
const line = `${indent}${words.join(' ')}${description === undefined ? '' : `: ${description}`}`;
|
|
288
|
+
return deep ? [line, ...held(property, root, `${indent} `, refs)] : [line];
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
// The arguments a value holds: its own, its items', and those of each alternative of a oneOf or anyOf,
|
|
292
|
+
// each alternative a "- " entry when more than one has arguments.
|
|
293
|
+
function held(schema, root, indent, refs) {
|
|
294
|
+
const value = expanded(schema, root, refs);
|
|
295
|
+
if (value === null)
|
|
296
|
+
return [];
|
|
297
|
+
const alternatives = (value.schema.oneOf ?? value.schema.anyOf ?? [])
|
|
298
|
+
.map((alternative) => held(alternative, root, indent, value.refs))
|
|
299
|
+
.filter((lines) => lines.length > 0);
|
|
300
|
+
return [
|
|
301
|
+
...argumentLines(value.schema, root, indent, true, value.refs),
|
|
302
|
+
...(value.schema.items === undefined ? [] : held(value.schema.items, root, indent, value.refs)),
|
|
303
|
+
...(alternatives.length === 1
|
|
304
|
+
? alternatives[0]
|
|
305
|
+
: alternatives.flatMap((lines) => lines.map((line, index) => (index === 0 ? `${indent}- ${line.slice(indent.length)}` : ` ${line}`)))),
|
|
306
|
+
];
|
|
307
|
+
}
|
|
308
|
+
function listed(tool) {
|
|
309
|
+
return tool.description === undefined ? tool.name : `${tool.name}: ${tool.description}`;
|
|
310
|
+
}
|
|
311
|
+
async function toolHelp(name) {
|
|
312
|
+
const tool = (await tools()).find((one) => one.name === name);
|
|
313
|
+
if (tool === undefined)
|
|
314
|
+
throw new Error(`${name} is no Tool; house find_command '{"query":"${name}"}' finds Commands`);
|
|
315
|
+
return [listed(tool), ...argumentLines(tool.inputSchema, tool.inputSchema, ' ', true)].join('\n');
|
|
316
|
+
}
|
|
258
317
|
async function house(args) {
|
|
259
318
|
const { flags, positionals: [verb, argument] } = accepted(args, ['--help'], 2, USAGE);
|
|
260
|
-
if (verb === 'help' && argument !== undefined)
|
|
261
|
-
throw unexpected(argument, USAGE);
|
|
262
319
|
if (flags.has('--help') && argument !== undefined)
|
|
263
320
|
throw unexpected('--help', USAGE);
|
|
321
|
+
// house help <name> runs as house <name> --help, so both forms answer alike.
|
|
322
|
+
if (verb === 'help' && argument !== undefined)
|
|
323
|
+
return run([argument, '--help']);
|
|
264
324
|
if (verb === undefined || verb === 'help') {
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
if (flags.has('--help')) {
|
|
268
|
-
const tool = (await tools()).find((listed) => listed.name === verb);
|
|
269
|
-
if (tool === undefined)
|
|
270
|
-
throw new Error(`${verb} is no Tool; house find_command '{"query":"${verb}"}' finds Commands`);
|
|
271
|
-
return [...(tool.description === undefined ? [] : [tool.description]), JSON.stringify(tool.inputSchema)].join('\n');
|
|
325
|
+
const listing = (await tools()).flatMap((tool) => tool.description === undefined ? [tool.name, ...argumentLines(tool.inputSchema, tool.inputSchema, ' ', false)] : [listed(tool)]);
|
|
326
|
+
return [USAGE, HELP, PUSH, FETCH, DOWNLOAD, ...listing].join('\n');
|
|
272
327
|
}
|
|
328
|
+
if (flags.has('--help'))
|
|
329
|
+
return toolHelp(verb);
|
|
273
330
|
const parsed = argumentsOf(argument);
|
|
274
331
|
return verb === 'upload' ? upload(parsed) : called(verb, parsed);
|
|
275
332
|
}
|
|
@@ -280,16 +337,19 @@ async function called(name, args) {
|
|
|
280
337
|
throw new Error(text.replace(/\n+$/, ''));
|
|
281
338
|
return text;
|
|
282
339
|
}
|
|
340
|
+
function run(argv) {
|
|
341
|
+
const named = argv.findIndex((arg) => !arg.startsWith('-'));
|
|
342
|
+
const rest = argv.filter((_arg, index) => index !== named);
|
|
343
|
+
if (argv[named] === 'push')
|
|
344
|
+
return push(rest);
|
|
345
|
+
if (argv[named] === 'fetch')
|
|
346
|
+
return fetched(rest);
|
|
347
|
+
if (argv[named] === 'download')
|
|
348
|
+
return download(rest);
|
|
349
|
+
return house(argv);
|
|
350
|
+
}
|
|
283
351
|
const argv = process.argv.slice(2);
|
|
284
|
-
|
|
285
|
-
const rest = argv.filter((_arg, index) => index !== named);
|
|
286
|
-
(argv[named] === 'push'
|
|
287
|
-
? push(rest)
|
|
288
|
-
: argv[named] === 'fetch'
|
|
289
|
-
? fetched(rest)
|
|
290
|
-
: argv[named] === 'download'
|
|
291
|
-
? download(rest)
|
|
292
|
-
: house(argv)).then((text) => {
|
|
352
|
+
run(argv).then((text) => {
|
|
293
353
|
process.stdout.write(`${text}\n`);
|
|
294
354
|
if (argv[0] === 'shell')
|
|
295
355
|
process.exitCode = Number(/^exit: (\d+)(?:\n|$)/.exec(text)?.[1] ?? 0);
|
package/dist/instructions.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { agentInstructions } from '@agentshouse/skills';
|
|
2
|
-
import { HOUSE_REF } from './git.js';
|
|
3
2
|
const OWNER_RULES = '/rooms/private/owner-rules.md';
|
|
4
3
|
const UNREADABLE = /^(?:\S+: )?(?:path_not_found|room_not_found|operation_denied)\b/;
|
|
5
4
|
const FAILED = /^exit: [1-9]\d*$/;
|
|
@@ -26,7 +25,6 @@ async function readOwnerRules(bridge) {
|
|
|
26
25
|
}
|
|
27
26
|
return document;
|
|
28
27
|
}
|
|
29
|
-
export async function instructions(bridge, base
|
|
30
|
-
|
|
31
|
-
return [lines.join('\n'), base, (await readOwnerRules(bridge)).replace(/\n$/, '')].filter((part) => part !== '').join('\n\n');
|
|
28
|
+
export async function instructions(bridge, base) {
|
|
29
|
+
return [agentInstructions().join('\n'), base, (await readOwnerRules(bridge)).replace(/\n$/, '')].filter((part) => part !== '').join('\n\n');
|
|
32
30
|
}
|
package/dist/kit-cli.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { parseArgs } from 'node:util';
|
|
2
2
|
import { answerGitCredential } from './app-git.js';
|
|
3
|
-
import { chatgpt } from './chatgpt.js';
|
|
4
3
|
import { login } from './login.js';
|
|
5
4
|
import { logout } from './logout.js';
|
|
6
5
|
import { proxyUnlessRelayed } from './relay.js';
|
|
7
6
|
import { resident } from './resident.js';
|
|
8
|
-
const USAGE = 'usage: kit <login|logout|resident
|
|
7
|
+
const USAGE = 'usage: kit <login|logout|resident>\n';
|
|
9
8
|
const COMMANDS = new Map([
|
|
10
9
|
[
|
|
11
10
|
'logout',
|
|
@@ -40,8 +39,6 @@ proxyUnlessRelayed();
|
|
|
40
39
|
async function run() {
|
|
41
40
|
if (command === 'login')
|
|
42
41
|
return login(argv);
|
|
43
|
-
if (command === 'chatgpt')
|
|
44
|
-
return chatgpt(argv);
|
|
45
42
|
if (command === '--help') {
|
|
46
43
|
parseArgs({ args: argv });
|
|
47
44
|
process.stdout.write(USAGE);
|
package/dist/login.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { KIT_LOGIN_PATHS, } from '@agentshouse/kit-wire';
|
|
1
2
|
import { spawn } from 'node:child_process';
|
|
2
3
|
import { createHash, randomBytes } from 'node:crypto';
|
|
3
4
|
import { parseArgs } from 'node:util';
|
|
@@ -11,16 +12,22 @@ import { selectRelay } from './relay.js';
|
|
|
11
12
|
import { startService } from './service.js';
|
|
12
13
|
import { placeSkillSet } from './skills.js';
|
|
13
14
|
import { endUnserved } from './wire.js';
|
|
14
|
-
|
|
15
|
+
const DEFAULT_HOUSE = 'https://agents.house';
|
|
15
16
|
const OPENER = process.platform === 'darwin' ? 'open' : 'xdg-open';
|
|
16
17
|
// Polling every two seconds brings the User's confirmation to the waiting Kit moments after they give it.
|
|
17
18
|
const POLL_INTERVAL_MS = 2000;
|
|
19
|
+
function startLogin(house, request) {
|
|
20
|
+
return post(house, KIT_LOGIN_PATHS.start, request);
|
|
21
|
+
}
|
|
22
|
+
function pollLogin(house, request) {
|
|
23
|
+
return post(house, KIT_LOGIN_PATHS.poll, request);
|
|
24
|
+
}
|
|
18
25
|
function open(link) {
|
|
19
26
|
spawn(OPENER, [link], { detached: true, stdio: 'ignore' })
|
|
20
27
|
.on('error', () => undefined)
|
|
21
28
|
.unref();
|
|
22
29
|
}
|
|
23
|
-
|
|
30
|
+
async function accepted(house, credential) {
|
|
24
31
|
const checked = await callHouse(house, credential, rpc('tools/list', {}));
|
|
25
32
|
if (checked.status === 200)
|
|
26
33
|
return true;
|
|
@@ -92,12 +99,12 @@ export async function login(argv) {
|
|
|
92
99
|
let named = environment;
|
|
93
100
|
let exchanged;
|
|
94
101
|
if (values.code !== undefined) {
|
|
95
|
-
exchanged = await
|
|
102
|
+
exchanged = await pollLogin(house, { code: values.code });
|
|
96
103
|
}
|
|
97
104
|
else {
|
|
98
105
|
held = ownAgent !== null && ownAgent.house === house && (await accepted(house, ownAgent.credential));
|
|
99
106
|
const verifier = randomBytes(32).toString('base64url');
|
|
100
|
-
const start = () => retrying(() =>
|
|
107
|
+
const start = () => retrying(() => startLogin(house, {
|
|
101
108
|
...(named === undefined
|
|
102
109
|
? { act: 'new_environment', ...(replaces === undefined ? {} : { replaces }) }
|
|
103
110
|
: { act: 'existing_environment', environment_id: named }),
|
|
@@ -119,7 +126,7 @@ export async function login(argv) {
|
|
|
119
126
|
}
|
|
120
127
|
process.stdout.write(`Open this link and confirm: ${started.start_url}\n`);
|
|
121
128
|
open(started.start_url);
|
|
122
|
-
exchanged = await retrying(() =>
|
|
129
|
+
exchanged = await retrying(() => pollLogin(house, { login: started.login, code_verifier: verifier }), undefined, () => POLL_INTERVAL_MS);
|
|
123
130
|
}
|
|
124
131
|
await placeSkillSet(house);
|
|
125
132
|
await writeCodexRule().catch((error) => process.stderr.write(`kit: ${error.message}\n`));
|
package/dist/logout.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { HouseRefusal,
|
|
1
|
+
import { HouseRefusal, kitAct } from './api.js';
|
|
2
2
|
import { forgetEnrolment, forgetOwnAgent, readEnrolment } from './home.js';
|
|
3
3
|
export async function logout() {
|
|
4
4
|
const enrolled = await readEnrolment();
|
|
5
5
|
if (enrolled !== null) {
|
|
6
6
|
try {
|
|
7
|
-
await
|
|
7
|
+
await kitAct(enrolled.house, 'kits/log-out', {}, enrolled.credential);
|
|
8
8
|
}
|
|
9
9
|
catch (error) {
|
|
10
10
|
if (!(error instanceof HouseRefusal && error.status === 401))
|
package/dist/mcp.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { KIT_WIRE, KIT_WIRE_HEADER } from '@agentshouse/kit-wire';
|
|
1
2
|
import { randomUUID } from 'node:crypto';
|
|
2
3
|
import { KIT_RELEASE } from './clis.js';
|
|
3
4
|
import { relayed } from './relay.js';
|
|
4
|
-
import { KIT_WIRE, KIT_WIRE_HEADER } from './wire.js';
|
|
5
5
|
const MCP_PROTOCOL_VERSION = '2026-07-28';
|
|
6
6
|
export const UNREACHABLE = 'House is unreachable; call again in a minute';
|
|
7
7
|
export class Unsettled extends Error {
|
|
@@ -34,7 +34,7 @@ export async function callHouse(origin, credential, message, operation = null, s
|
|
|
34
34
|
'mcp-protocol-version': MCP_PROTOCOL_VERSION,
|
|
35
35
|
'mcp-method': message.method,
|
|
36
36
|
...(tool === null ? {} : { 'mcp-name': tool }),
|
|
37
|
-
[KIT_WIRE_HEADER]:
|
|
37
|
+
[KIT_WIRE_HEADER]: KIT_WIRE,
|
|
38
38
|
},
|
|
39
39
|
body: mcpBody(message, operation),
|
|
40
40
|
signal,
|
package/dist/placement.js
CHANGED
|
@@ -1,23 +1,6 @@
|
|
|
1
1
|
import { readFileSync } from 'node:fs';
|
|
2
|
-
import { join } from 'node:path';
|
|
3
|
-
import { run } from './clis.js';
|
|
2
|
+
import { join, resolve } from 'node:path';
|
|
4
3
|
import { kitHome } from './home.js';
|
|
5
|
-
export function service() {
|
|
6
|
-
if (process.platform !== 'linux' || !process.env.INVOCATION_ID)
|
|
7
|
-
return null;
|
|
8
|
-
return process.env.MANAGERPID ? 'user' : 'system';
|
|
9
|
-
}
|
|
10
|
-
export function throughSudo() {
|
|
11
|
-
return service() === 'system' && process.getuid() !== 0;
|
|
12
|
-
}
|
|
13
|
-
export async function updatesItself() {
|
|
14
|
-
if (service() === null)
|
|
15
|
-
return false;
|
|
16
|
-
if (!throughSudo())
|
|
17
|
-
return true;
|
|
18
|
-
// sudo answers at once, so ten seconds only bounds a stuck sudo.
|
|
19
|
-
return (await run('sudo', ['-n', 'true'], 10_000)).status === 0;
|
|
20
|
-
}
|
|
21
4
|
function recorded(name) {
|
|
22
5
|
try {
|
|
23
6
|
return readFileSync(join(kitHome(), name), 'utf8').trim();
|
|
@@ -31,9 +14,12 @@ function recorded(name) {
|
|
|
31
14
|
export function installCommand() {
|
|
32
15
|
return recorded('install-command');
|
|
33
16
|
}
|
|
34
|
-
export function
|
|
35
|
-
const
|
|
36
|
-
if (
|
|
37
|
-
|
|
38
|
-
return
|
|
17
|
+
export function placedPrefix() {
|
|
18
|
+
const prefix = process.env.HOUSE_KIT_PREFIX;
|
|
19
|
+
if (prefix === undefined || prefix === '')
|
|
20
|
+
throw new Error('this Kit process was not started by a launcher its installer placed');
|
|
21
|
+
return resolve(prefix);
|
|
22
|
+
}
|
|
23
|
+
export function releaseDirectory(release) {
|
|
24
|
+
return join(placedPrefix(), 'releases', release);
|
|
39
25
|
}
|
package/dist/resident.js
CHANGED
|
@@ -8,10 +8,10 @@ import { fileURLToPath } from 'node:url';
|
|
|
8
8
|
import { Agents } from './agents.js';
|
|
9
9
|
import { house } from './api.js';
|
|
10
10
|
import { received } from './bridge.js';
|
|
11
|
-
import {
|
|
11
|
+
import { Conversations } from './conversations.js';
|
|
12
12
|
import { LocalCopies } from './copies.js';
|
|
13
|
-
import { restart
|
|
14
|
-
import { agentBase, enrolled,
|
|
13
|
+
import { restart } from './end.js';
|
|
14
|
+
import { agentBase, enrolled, kitHome, ownerLock, ownerSocket, readEnrolment } from './home.js';
|
|
15
15
|
import { Calls } from './calls.js';
|
|
16
16
|
import { killDescendants } from './scope.js';
|
|
17
17
|
import { removeInputs, Scripts } from './scripts.js';
|
|
@@ -20,6 +20,7 @@ import { SignIns } from './sign-in.js';
|
|
|
20
20
|
import { placeSkillSet } from './skills.js';
|
|
21
21
|
import { holdConnection } from './connection.js';
|
|
22
22
|
import { KitUpdate } from './update.js';
|
|
23
|
+
import { takeUnservedRelease } from './wire.js';
|
|
23
24
|
import { codexLauncher } from './work.js';
|
|
24
25
|
function report(error) {
|
|
25
26
|
process.stderr.write(`kit: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
@@ -110,13 +111,6 @@ function connected() {
|
|
|
110
111
|
}
|
|
111
112
|
async function started() {
|
|
112
113
|
await connected();
|
|
113
|
-
await forgetRestart();
|
|
114
|
-
watch(kitHome(), () => {
|
|
115
|
-
if (enrolled())
|
|
116
|
-
return;
|
|
117
|
-
killDescendants();
|
|
118
|
-
process.exit(1);
|
|
119
|
-
});
|
|
120
114
|
await placeSkillSet((await readEnrolment()).house);
|
|
121
115
|
await mkdir(agentBase(), { recursive: true });
|
|
122
116
|
await installShim(join(kitHome(), 'shim', 'git'), 'git-main');
|
|
@@ -127,6 +121,7 @@ export async function resident() {
|
|
|
127
121
|
const copies = new LocalCopies(house);
|
|
128
122
|
await copies.load();
|
|
129
123
|
await serveOwner(copies);
|
|
124
|
+
await copies.swept();
|
|
130
125
|
await started().catch((error) => {
|
|
131
126
|
report(error);
|
|
132
127
|
process.exit(1);
|
|
@@ -135,20 +130,28 @@ export async function resident() {
|
|
|
135
130
|
const agents = new Agents(house, () => changed());
|
|
136
131
|
let connection = null;
|
|
137
132
|
let reported = false;
|
|
133
|
+
let stopping = false;
|
|
134
|
+
const stop = async (then) => {
|
|
135
|
+
if (stopping)
|
|
136
|
+
return;
|
|
137
|
+
stopping = true;
|
|
138
|
+
conversations.stopped();
|
|
139
|
+
killDescendants();
|
|
140
|
+
await connection?.close();
|
|
141
|
+
then();
|
|
142
|
+
};
|
|
138
143
|
const idle = () => calls.idle() && conversations.idle() && agents.idle();
|
|
139
144
|
const changed = () => {
|
|
140
145
|
if (!idle()) {
|
|
141
146
|
reported = false;
|
|
142
147
|
}
|
|
143
|
-
else if (
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
else if (update.held() && conversations.quiet()) {
|
|
147
|
-
update.apply(connection.pause());
|
|
148
|
+
else if (update.placedRelease() !== null && conversations.quiet()) {
|
|
149
|
+
const placed = update.placedRelease();
|
|
150
|
+
void stop(() => restart(`Kit ${placed} is placed; its supervisor starts it`));
|
|
148
151
|
}
|
|
149
152
|
else if (!reported) {
|
|
150
153
|
reported = true;
|
|
151
|
-
logged(house.deliver('/
|
|
154
|
+
logged(house.deliver('kits/report-idle', {}, idle));
|
|
152
155
|
}
|
|
153
156
|
};
|
|
154
157
|
const calls = new Calls(house, changed);
|
|
@@ -157,26 +160,36 @@ export async function resident() {
|
|
|
157
160
|
agents,
|
|
158
161
|
copies,
|
|
159
162
|
calls,
|
|
160
|
-
send: (
|
|
163
|
+
send: (oneWayCall) => connection?.send(oneWayCall) ?? false,
|
|
161
164
|
changed,
|
|
162
165
|
});
|
|
163
166
|
const signIns = new SignIns(house, agents, calls);
|
|
164
|
-
const update = new KitUpdate(calls
|
|
167
|
+
const update = new KitUpdate(calls);
|
|
168
|
+
if (process.env.HOUSE_KIT_SANDBOX !== '1')
|
|
169
|
+
takeUnservedRelease((release) => logged(update.takeRefused(release)));
|
|
165
170
|
removeInputs();
|
|
166
|
-
const scripts = new Scripts(calls, (
|
|
171
|
+
const scripts = new Scripts(calls, (oneWayCall) => connection?.send(oneWayCall) ?? false);
|
|
167
172
|
for (const signal of ['SIGTERM', 'SIGINT']) {
|
|
168
173
|
process.once(signal, () => {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
174
|
+
void stop(() => {
|
|
175
|
+
removeInputs();
|
|
176
|
+
process.kill(process.pid, signal);
|
|
177
|
+
});
|
|
172
178
|
});
|
|
173
179
|
}
|
|
174
|
-
|
|
175
|
-
|
|
180
|
+
const unenrolled = () => {
|
|
181
|
+
if (!enrolled())
|
|
182
|
+
void stop(() => process.exit(1));
|
|
183
|
+
};
|
|
184
|
+
watch(kitHome(), unenrolled);
|
|
185
|
+
unenrolled();
|
|
186
|
+
await house.deliver('kits/report-restart', {}).catch(report);
|
|
176
187
|
logged(agents.refresh());
|
|
188
|
+
agents.keepCurrent(() => process.env.HOUSE_KIT_SANDBOX === '1' && reported);
|
|
177
189
|
connection = holdConnection({
|
|
178
190
|
opened: () => {
|
|
179
191
|
conversations.opened();
|
|
192
|
+
scripts.connected();
|
|
180
193
|
changed();
|
|
181
194
|
logged(copies.connected());
|
|
182
195
|
},
|
|
@@ -185,24 +198,18 @@ export async function resident() {
|
|
|
185
198
|
if (call.kind === 'sign_in')
|
|
186
199
|
signIns.start(call);
|
|
187
200
|
else if (call.kind === 'update')
|
|
188
|
-
update.
|
|
201
|
+
update.take(call);
|
|
189
202
|
else if (call.kind === 'run_wizard' || call.kind === 'run_function')
|
|
190
203
|
scripts.start(call);
|
|
191
|
-
else
|
|
204
|
+
else
|
|
192
205
|
conversations.call(call);
|
|
193
|
-
else {
|
|
194
|
-
const refused = { refused: unknownMethod(call.kind) };
|
|
195
|
-
void calls.carry(call.input_id, async () => ({ result: refused }));
|
|
196
|
-
}
|
|
197
206
|
},
|
|
198
|
-
|
|
199
|
-
if (
|
|
200
|
-
conversations.watching(
|
|
201
|
-
if (
|
|
202
|
-
logged(copies.changed(notification.rooms));
|
|
203
|
-
if (notification.type === 'work_available' && notification.subject === 'agents')
|
|
207
|
+
oneWayCall: (oneWayCall) => {
|
|
208
|
+
if (oneWayCall.type === 'watching')
|
|
209
|
+
conversations.watching(oneWayCall.watching);
|
|
210
|
+
if (oneWayCall.type === 'work_available' && oneWayCall.subject === 'agents')
|
|
204
211
|
logged(agents.refresh());
|
|
205
|
-
scripts.notified(
|
|
212
|
+
scripts.notified(oneWayCall);
|
|
206
213
|
},
|
|
207
214
|
});
|
|
208
215
|
}
|
package/dist/scope.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { execFileSync } from 'node:child_process';
|
|
2
|
-
import { mkdirSync, readdirSync, readFileSync, rmdirSync, statSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { mkdirSync, readdirSync, readFileSync, realpathSync, rmdirSync, statSync, writeFileSync } from 'node:fs';
|
|
3
3
|
import { join } from 'node:path';
|
|
4
4
|
const LISTING_BYTES = 1 << 28;
|
|
5
5
|
const CGROUPS = '/sys/fs/cgroup';
|
|
@@ -122,15 +122,23 @@ function members(group) {
|
|
|
122
122
|
}
|
|
123
123
|
return pids;
|
|
124
124
|
}
|
|
125
|
+
function besideCli(cli) {
|
|
126
|
+
try {
|
|
127
|
+
return `${realpathSync(cli)}-`;
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
125
133
|
export class Scope {
|
|
126
134
|
marker;
|
|
127
|
-
|
|
135
|
+
helpers;
|
|
128
136
|
group;
|
|
129
137
|
session = null;
|
|
130
138
|
recorded = null;
|
|
131
139
|
constructor(marker, name, cli) {
|
|
132
140
|
this.marker = marker;
|
|
133
|
-
this.
|
|
141
|
+
this.helpers = besideCli(cli);
|
|
134
142
|
const own = ownGroup();
|
|
135
143
|
this.group = own === null ? null : join(own, name);
|
|
136
144
|
try {
|
|
@@ -168,7 +176,7 @@ export class Scope {
|
|
|
168
176
|
return true;
|
|
169
177
|
if (this.recorded === null)
|
|
170
178
|
return found.size > 0;
|
|
171
|
-
return [...found].some(([pid, { session, command }]) => session !== this.session || !(this.recorded.has(pid) || command.startsWith(
|
|
179
|
+
return [...found].some(([pid, { session, command }]) => session !== this.session || !(this.recorded.has(pid) || (this.helpers !== null && command.startsWith(this.helpers))));
|
|
172
180
|
}
|
|
173
181
|
empty() {
|
|
174
182
|
return this.found()?.size === 0;
|