@agentshouse/kit 0.2.1-cb0bd1cadcfed → 0.2.1-cca9e1f43de44
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 +6 -7
- package/dist/acp.js +26 -13
- package/dist/agents.js +39 -26
- package/dist/app-git.js +64 -0
- package/dist/bootstrap.json +4 -4
- package/dist/bridge.js +7 -22
- package/dist/clis.js +36 -62
- package/dist/conversations.js +275 -228
- package/dist/events.js +587 -0
- package/dist/files.js +14 -0
- package/dist/house-main.js +28 -10
- package/dist/instructions.js +1 -1
- package/dist/kit-main.js +3 -0
- package/dist/login.js +4 -0
- package/dist/logout.js +3 -0
- package/dist/parts.js +64 -0
- package/dist/resident.js +3 -3
- package/dist/shell.js +3 -0
- package/dist/sign-in.js +33 -9
- package/package.json +1 -1
- package/dist/blocks.js +0 -51
package/dist/house-main.js
CHANGED
|
@@ -6,11 +6,14 @@ import { basename, join } from 'node:path';
|
|
|
6
6
|
import { kitHome, readOwnAgent } from './home.js';
|
|
7
7
|
import { callHouse, rpc, UNREACHABLE } from './mcp.js';
|
|
8
8
|
import { refusalOf } from './refusals.js';
|
|
9
|
+
import { relayed } from './relay.js';
|
|
10
|
+
import { parse } from 'yaml';
|
|
9
11
|
const USAGE = "usage: house <tool> ['<arguments as JSON>']";
|
|
10
12
|
const PUSH_USAGE = 'usage: house push [commit] [--owner]';
|
|
11
13
|
const PUSH = "push [commit]: sends the Local copy's committed changes to House";
|
|
12
14
|
const ARGUMENTS = `the arguments are one JSON object in single quotes, like house search '{"query":"invoice"}'`;
|
|
13
15
|
const CLOSED = "this conversation's House connection is closed; nothing to do from here";
|
|
16
|
+
const SANDBOXED = "your CLI's sandbox kept house from House; run house as a command of its own, with no pipe, chain or redirect";
|
|
14
17
|
const REVOKED = 'this conversation no longer has House access; nothing to do from here';
|
|
15
18
|
const UNCONNECTED = "this computer's own agent has no House connection; run kit login";
|
|
16
19
|
const DISCONNECTED = "House no longer accepts this computer's own agent; run kit login";
|
|
@@ -42,7 +45,7 @@ function bridged(path, body, headers = { 'content-type': 'application/json' }, t
|
|
|
42
45
|
reject(new Error(refused(path, answer.statusCode, text)));
|
|
43
46
|
});
|
|
44
47
|
});
|
|
45
|
-
sent.on('error', () => reject(new Error(CLOSED)));
|
|
48
|
+
sent.on('error', (error) => reject(new Error(error.code === 'EPERM' || error.code === 'EACCES' ? SANDBOXED : CLOSED)));
|
|
46
49
|
sent.end(body instanceof Buffer ? body : JSON.stringify(body));
|
|
47
50
|
});
|
|
48
51
|
}
|
|
@@ -78,11 +81,24 @@ async function localFile(path) {
|
|
|
78
81
|
: `${path} is not a readable file`);
|
|
79
82
|
}
|
|
80
83
|
}
|
|
84
|
+
async function sent(url, bytes, operation) {
|
|
85
|
+
const headers = { 'content-type': 'application/octet-stream', 'x-house-byte-operation': operation };
|
|
86
|
+
if (socketPath !== undefined)
|
|
87
|
+
return bridged(url, bytes, headers);
|
|
88
|
+
setGlobalProxyFromEnv();
|
|
89
|
+
const answer = await fetch(relayed(url), { method: 'POST', headers, body: bytes }).catch(() => {
|
|
90
|
+
throw new Error(UNREACHABLE);
|
|
91
|
+
});
|
|
92
|
+
const text = await answer.text();
|
|
93
|
+
if (answer.status === 200)
|
|
94
|
+
return text;
|
|
95
|
+
throw new Error(refused(url, answer.status, text));
|
|
96
|
+
}
|
|
81
97
|
async function upload(path, roomRef, missing) {
|
|
82
98
|
if (typeof path !== 'string' || path === '')
|
|
83
99
|
throw new Error(missing);
|
|
84
100
|
const bytes = await localFile(path);
|
|
85
|
-
const declared =
|
|
101
|
+
const declared = parse(await called('upload', {
|
|
86
102
|
...(roomRef === undefined ? {} : { room_ref: roomRef }),
|
|
87
103
|
name: basename(path),
|
|
88
104
|
bytes: bytes.length,
|
|
@@ -90,10 +106,7 @@ async function upload(path, roomRef, missing) {
|
|
|
90
106
|
}));
|
|
91
107
|
if (declared.upload === undefined)
|
|
92
108
|
return declared.attachment;
|
|
93
|
-
const saved = JSON.parse(await
|
|
94
|
-
'content-type': 'application/octet-stream',
|
|
95
|
-
'x-house-byte-operation': declared.upload.operation,
|
|
96
|
-
}));
|
|
109
|
+
const saved = JSON.parse(await sent(declared.upload.url, bytes, declared.upload.operation));
|
|
97
110
|
if (saved.upload_failure !== undefined)
|
|
98
111
|
throw new Error(`${path} was not saved: ${saved.upload_failure}; call again later`);
|
|
99
112
|
return saved.attachment;
|
|
@@ -137,17 +150,20 @@ async function house([verb, argument]) {
|
|
|
137
150
|
return [...(tool.description === undefined ? [] : [tool.description]), JSON.stringify(tool.inputSchema)].join('\n');
|
|
138
151
|
}
|
|
139
152
|
const args = argumentsOf(argument);
|
|
140
|
-
if (
|
|
141
|
-
return JSON.stringify({ attachment: await upload(args.path, args.room_ref, '
|
|
153
|
+
if (verb === 'upload') {
|
|
154
|
+
return JSON.stringify({ attachment: await upload(args.path, args.room_ref, 'upload needs "path", a local file') });
|
|
142
155
|
}
|
|
143
|
-
if (
|
|
156
|
+
if (verb === 'append_record' && Array.isArray(args.attachments)) {
|
|
144
157
|
const attachments = [];
|
|
145
158
|
for (const path of args.attachments) {
|
|
146
159
|
attachments.push(await upload(path, args.room_ref, 'each attachments entry is the path of a local file'));
|
|
147
160
|
}
|
|
148
161
|
args.attachments = attachments;
|
|
149
162
|
}
|
|
150
|
-
|
|
163
|
+
return called(verb, args);
|
|
164
|
+
}
|
|
165
|
+
async function called(name, args) {
|
|
166
|
+
const result = await mcp('tools/call', { name, arguments: args });
|
|
151
167
|
const text = result.content.map((content) => content.text).join('\n');
|
|
152
168
|
if (result.isError === true)
|
|
153
169
|
throw new Error(text.replace(/\n+$/, ''));
|
|
@@ -156,6 +172,8 @@ async function house([verb, argument]) {
|
|
|
156
172
|
const argv = process.argv.slice(2);
|
|
157
173
|
(argv[0] === 'push' ? push(argv.slice(1)) : house(argv)).then((text) => {
|
|
158
174
|
process.stdout.write(`${text}\n`);
|
|
175
|
+
if (argv[0] === 'shell')
|
|
176
|
+
process.exitCode = Number(/^exit: (\d+)(?:\n|$)/.exec(text)?.[1] ?? 0);
|
|
159
177
|
}, (error) => {
|
|
160
178
|
process.stderr.write(`house: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
161
179
|
process.exitCode = 1;
|
package/dist/instructions.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { HOW_WE_WORK } from './skills.js';
|
|
2
2
|
const HOUSE_LINE = 'Work with House through the `house` CLI: run `house --help`.';
|
|
3
|
-
const FILE_LINE = 'To give the User a file or a page, upload it with `house
|
|
3
|
+
const FILE_LINE = 'To give the User a file or a page, upload it with `house upload` and link it; never start a server.';
|
|
4
4
|
const READ_LINE = 'Before working in a Room, read `/rooms/private/rooms/<handle>/AGENTS.md`.';
|
|
5
5
|
const COPIES_LINE = 'House Local copies; commit, then `house push`:';
|
|
6
6
|
const UNREADABLE = /^(?:\S+: )?(?:path_not_found|room_not_found|operation_denied)\b/;
|
package/dist/kit-main.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { setGlobalProxyFromEnv } from 'node:http';
|
|
3
|
+
import { answerGitCredential } from './app-git.js';
|
|
3
4
|
import { login } from './login.js';
|
|
4
5
|
import { logout } from './logout.js';
|
|
5
6
|
import { resident } from './resident.js';
|
|
@@ -12,6 +13,8 @@ async function run() {
|
|
|
12
13
|
return logout();
|
|
13
14
|
if (command === 'resident')
|
|
14
15
|
return resident();
|
|
16
|
+
if (command === 'git-credential')
|
|
17
|
+
return answerGitCredential(argv[0]);
|
|
15
18
|
process.stderr.write('usage: kit <login|logout|resident>\n');
|
|
16
19
|
process.exitCode = 2;
|
|
17
20
|
}
|
package/dist/login.js
CHANGED
|
@@ -4,6 +4,7 @@ import { hostname } from 'node:os';
|
|
|
4
4
|
import { createInterface } from 'node:readline/promises';
|
|
5
5
|
import { parseArgs } from 'node:util';
|
|
6
6
|
import { post } from './api.js';
|
|
7
|
+
import { placeAppGit } from './app-git.js';
|
|
7
8
|
import { forgetOwnAgent, readDisconnected, readEnrolment, readOwnAgent, writeEnrolment, writeOwnAgent } from './home.js';
|
|
8
9
|
import { callHouse, rpc } from './mcp.js';
|
|
9
10
|
const DEFAULT_HOUSE = 'https://agents.house';
|
|
@@ -104,6 +105,7 @@ export async function login(argv) {
|
|
|
104
105
|
process.stdout.write("This computer's own agent was another User's; run kit login again to connect it to you.\n");
|
|
105
106
|
}
|
|
106
107
|
};
|
|
108
|
+
const placeGit = async () => placeAppGit(ownAgent, await readOwnAgent());
|
|
107
109
|
if (values.manual) {
|
|
108
110
|
const { start_url } = await post(house, '/kit', {
|
|
109
111
|
...started,
|
|
@@ -111,6 +113,7 @@ export async function login(argv) {
|
|
|
111
113
|
});
|
|
112
114
|
process.stdout.write(`Open this link and confirm: ${start_url}\n`);
|
|
113
115
|
await exchange(await typed('Code: '));
|
|
116
|
+
await placeGit();
|
|
114
117
|
return;
|
|
115
118
|
}
|
|
116
119
|
const callback = await listen();
|
|
@@ -133,4 +136,5 @@ export async function login(argv) {
|
|
|
133
136
|
finally {
|
|
134
137
|
callback.close();
|
|
135
138
|
}
|
|
139
|
+
await placeGit();
|
|
136
140
|
}
|
package/dist/logout.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { HouseRefusal, post } from './api.js';
|
|
2
|
+
import { forgetAppGit } from './app-git.js';
|
|
2
3
|
import { forgetEnrolment, readEnrolment } from './home.js';
|
|
3
4
|
export async function logout() {
|
|
4
5
|
const enrolled = await readEnrolment();
|
|
5
6
|
if (enrolled === null) {
|
|
7
|
+
await forgetAppGit();
|
|
6
8
|
process.stdout.write('This computer is not connected to House.\n');
|
|
7
9
|
return;
|
|
8
10
|
}
|
|
@@ -14,5 +16,6 @@ export async function logout() {
|
|
|
14
16
|
throw error;
|
|
15
17
|
}
|
|
16
18
|
await forgetEnrolment(enrolled);
|
|
19
|
+
await forgetAppGit();
|
|
17
20
|
process.stdout.write(`Environment ${enrolled.environment} is disconnected; kit login reconnects it.\n`);
|
|
18
21
|
}
|
package/dist/parts.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
export class Parts {
|
|
2
|
+
parts = [];
|
|
3
|
+
context = null;
|
|
4
|
+
emit;
|
|
5
|
+
writing = null;
|
|
6
|
+
planned = null;
|
|
7
|
+
constructor(emit) {
|
|
8
|
+
this.emit = emit;
|
|
9
|
+
}
|
|
10
|
+
write(type, id, text) {
|
|
11
|
+
if (text === '')
|
|
12
|
+
return;
|
|
13
|
+
const last = this.parts.length - 1;
|
|
14
|
+
const part = this.parts[last];
|
|
15
|
+
if (this.writing?.type === type && this.writing.id === id && part?.type === type) {
|
|
16
|
+
part.text += text;
|
|
17
|
+
this.emit({ op: 'append', index: last, text });
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
this.start({ type, text });
|
|
21
|
+
this.writing = { type, id };
|
|
22
|
+
}
|
|
23
|
+
command() {
|
|
24
|
+
const last = this.parts.length - 1;
|
|
25
|
+
const part = this.parts[last];
|
|
26
|
+
if (part?.type !== 'commands') {
|
|
27
|
+
this.start({ type: 'commands', count: 1 });
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
part.count++;
|
|
31
|
+
this.emit({ op: 'count', index: last, count: part.count });
|
|
32
|
+
}
|
|
33
|
+
start(part) {
|
|
34
|
+
this.writing = null;
|
|
35
|
+
this.parts.push(part);
|
|
36
|
+
const index = this.parts.length - 1;
|
|
37
|
+
this.emit({ op: 'start', index, part });
|
|
38
|
+
return index;
|
|
39
|
+
}
|
|
40
|
+
done(index, result) {
|
|
41
|
+
const part = this.parts[index];
|
|
42
|
+
part.status = 'done';
|
|
43
|
+
part.result = result;
|
|
44
|
+
this.emit({ op: 'status', index, status: 'done', result });
|
|
45
|
+
}
|
|
46
|
+
plan(entries) {
|
|
47
|
+
if (this.planned === null) {
|
|
48
|
+
this.planned = this.start({ type: 'plan', entries });
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
this.parts[this.planned].entries = entries;
|
|
52
|
+
this.emit({ op: 'plan', index: this.planned, entries });
|
|
53
|
+
}
|
|
54
|
+
measure(context) {
|
|
55
|
+
this.context = context;
|
|
56
|
+
this.emit({ op: 'context', ...context });
|
|
57
|
+
}
|
|
58
|
+
operations() {
|
|
59
|
+
return [
|
|
60
|
+
...this.parts.map((part, index) => ({ op: 'start', index, part })),
|
|
61
|
+
...(this.context === null ? [] : [{ op: 'context', ...this.context }]),
|
|
62
|
+
];
|
|
63
|
+
}
|
|
64
|
+
}
|
package/dist/resident.js
CHANGED
|
@@ -11,6 +11,7 @@ import { received } from './bridge.js';
|
|
|
11
11
|
import { Conversations } from './conversations.js';
|
|
12
12
|
import { LocalCopies } from './copies.js';
|
|
13
13
|
import { agentBase, enrolled, kitHome } from './home.js';
|
|
14
|
+
import { quoted } from './shell.js';
|
|
14
15
|
import { SignIns } from './sign-in.js';
|
|
15
16
|
import { placeSkillSet } from './skills.js';
|
|
16
17
|
import { holdStream } from './stream.js';
|
|
@@ -21,9 +22,6 @@ function report(error) {
|
|
|
21
22
|
function logged(work) {
|
|
22
23
|
work.catch(report);
|
|
23
24
|
}
|
|
24
|
-
function quoted(value) {
|
|
25
|
-
return `'${value.replaceAll("'", `'\\''`)}'`;
|
|
26
|
-
}
|
|
27
25
|
async function installShim() {
|
|
28
26
|
const main = fileURLToPath(new URL(`./git-main${extname(fileURLToPath(import.meta.url))}`, import.meta.url));
|
|
29
27
|
await mkdir(join(kitHome(), 'shim'), { recursive: true });
|
|
@@ -120,6 +118,8 @@ export async function resident() {
|
|
|
120
118
|
logged(copies.select());
|
|
121
119
|
},
|
|
122
120
|
frame: (arrived) => {
|
|
121
|
+
if (arrived.type === 'watching')
|
|
122
|
+
conversations.watching(arrived.watching === true);
|
|
123
123
|
if (arrived.type === 'work_available' && arrived.subject === 'agents')
|
|
124
124
|
logged(agents.refresh());
|
|
125
125
|
if (arrived.type === 'work_available' && arrived.subject === 'local_copy')
|
package/dist/shell.js
ADDED
package/dist/sign-in.js
CHANGED
|
@@ -12,6 +12,9 @@ function causeOf(error) {
|
|
|
12
12
|
function logged(error) {
|
|
13
13
|
process.stderr.write(`kit: ${causeOf(error)}\n`);
|
|
14
14
|
}
|
|
15
|
+
function endOf(signal) {
|
|
16
|
+
return new Promise((resolve) => signal.addEventListener('abort', () => resolve(true), { once: true }));
|
|
17
|
+
}
|
|
15
18
|
export class SignIns {
|
|
16
19
|
house;
|
|
17
20
|
agents;
|
|
@@ -30,25 +33,43 @@ export class SignIns {
|
|
|
30
33
|
return;
|
|
31
34
|
this.running.add(input.input_id);
|
|
32
35
|
this.changed();
|
|
33
|
-
this.
|
|
34
|
-
.then(() => this.agents.recheck(input.cli))
|
|
35
|
-
.then(() => this.house.deliver(`/kit/inputs/${input.input_id}/ack`, {}))
|
|
36
|
-
.then(() => this.agents.reread(input.cli))
|
|
36
|
+
this.signIn(input)
|
|
37
37
|
.catch(logged)
|
|
38
38
|
.finally(() => {
|
|
39
39
|
this.running.delete(input.input_id);
|
|
40
40
|
this.changed();
|
|
41
41
|
});
|
|
42
42
|
}
|
|
43
|
-
async
|
|
43
|
+
async signIn(input) {
|
|
44
|
+
const ending = new AbortController();
|
|
45
|
+
// House stops waiting for a sign-in ten minutes after it wrote it and sends the seconds left, so its install and login end with the page.
|
|
46
|
+
const timer = setTimeout(() => ending.abort(), input.ends_in * 1000);
|
|
47
|
+
const ended = await Promise.race([this.signedIn(input, ending.signal), endOf(ending.signal)]);
|
|
48
|
+
clearTimeout(timer);
|
|
49
|
+
if (ended)
|
|
50
|
+
process.stderr.write(`kit: the ${input.cli} sign-in reached the end House set for it\n`);
|
|
51
|
+
await this.house.deliver(`/kit/inputs/${input.input_id}/ack`, {});
|
|
52
|
+
if (!ended)
|
|
53
|
+
await this.agents.reread(input.cli);
|
|
54
|
+
}
|
|
55
|
+
async signedIn(input, signal) {
|
|
56
|
+
await this.login(input, signal);
|
|
57
|
+
if (!signal.aborted)
|
|
58
|
+
await this.agents.recheck(input.cli, signal);
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
async login(input, signal) {
|
|
44
62
|
let cli;
|
|
45
63
|
try {
|
|
46
|
-
cli = await this.agents.located(input.cli);
|
|
64
|
+
cli = await this.agents.located(input.cli, signal);
|
|
47
65
|
}
|
|
48
66
|
catch (error) {
|
|
49
|
-
|
|
67
|
+
if (!signal.aborted)
|
|
68
|
+
process.stderr.write(`kit: the ${input.cli} sign-in failed: ${causeOf(error)}\n`);
|
|
50
69
|
return;
|
|
51
70
|
}
|
|
71
|
+
if (signal.aborted)
|
|
72
|
+
return;
|
|
52
73
|
const login = CLIS[input.cli].login;
|
|
53
74
|
const child = spawn(cli, login.args, {
|
|
54
75
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
@@ -56,6 +77,8 @@ export class SignIns {
|
|
|
56
77
|
env: withoutProxy(),
|
|
57
78
|
});
|
|
58
79
|
const running = () => child.exitCode === null && child.signalCode === null;
|
|
80
|
+
const stop = () => killTree(child);
|
|
81
|
+
signal.addEventListener('abort', stop, { once: true });
|
|
59
82
|
let link;
|
|
60
83
|
let code;
|
|
61
84
|
let last = '';
|
|
@@ -92,9 +115,10 @@ export class SignIns {
|
|
|
92
115
|
createInterface({ input: output }).on('line', read);
|
|
93
116
|
const failed = await new Promise((resolve) => {
|
|
94
117
|
child.on('error', (error) => resolve(error.message));
|
|
95
|
-
child.on('close', (status,
|
|
118
|
+
child.on('close', (status, killed) => resolve(status === 0 ? null : `exited with ${status ?? killed}${last ? `: ${last}` : ''}`));
|
|
96
119
|
});
|
|
97
|
-
|
|
120
|
+
signal.removeEventListener('abort', stop);
|
|
121
|
+
if (failed !== null && !signal.aborted)
|
|
98
122
|
process.stderr.write(`kit: the ${input.cli} sign-in failed: ${failed}\n`);
|
|
99
123
|
}
|
|
100
124
|
}
|
package/package.json
CHANGED
package/dist/blocks.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
const FENCE = /^\s*(`{3,}|~{3,})\s*(\S*)/;
|
|
2
|
-
export function blocksOf(text) {
|
|
3
|
-
const blocks = [];
|
|
4
|
-
let paragraph = [];
|
|
5
|
-
let fence = null;
|
|
6
|
-
const closeParagraph = () => {
|
|
7
|
-
const joined = paragraph.join('\n').trim();
|
|
8
|
-
if (joined.length > 0)
|
|
9
|
-
blocks.push({ type: 'paragraph', text: joined });
|
|
10
|
-
paragraph = [];
|
|
11
|
-
};
|
|
12
|
-
const closeFence = () => {
|
|
13
|
-
const joined = fence.lines.join('\n');
|
|
14
|
-
if (joined.length > 0)
|
|
15
|
-
blocks.push({ type: 'code', language: fence.language, text: joined });
|
|
16
|
-
fence = null;
|
|
17
|
-
};
|
|
18
|
-
for (const line of text.split('\n')) {
|
|
19
|
-
if (fence !== null) {
|
|
20
|
-
if (line.trim().startsWith(fence.marker))
|
|
21
|
-
closeFence();
|
|
22
|
-
else
|
|
23
|
-
fence.lines.push(line);
|
|
24
|
-
continue;
|
|
25
|
-
}
|
|
26
|
-
const opening = FENCE.exec(line);
|
|
27
|
-
if (opening !== null) {
|
|
28
|
-
closeParagraph();
|
|
29
|
-
fence = { marker: opening[1], language: opening[2] || null, lines: [] };
|
|
30
|
-
}
|
|
31
|
-
else if (line.trim().length === 0) {
|
|
32
|
-
closeParagraph();
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
paragraph.push(line);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
if (fence !== null)
|
|
39
|
-
closeFence();
|
|
40
|
-
closeParagraph();
|
|
41
|
-
return blocks;
|
|
42
|
-
}
|
|
43
|
-
export function firstChange(before, after) {
|
|
44
|
-
let index = 0;
|
|
45
|
-
while (index < before.length &&
|
|
46
|
-
index < after.length &&
|
|
47
|
-
JSON.stringify(before[index]) === JSON.stringify(after[index])) {
|
|
48
|
-
index++;
|
|
49
|
-
}
|
|
50
|
-
return index;
|
|
51
|
-
}
|