@agentshouse/kit 0.2.1-alpha.9 → 0.2.1-c031c7457a661
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 +48 -29
- package/dist/abort.js +9 -0
- package/dist/acp.js +49 -86
- package/dist/agents.js +333 -52
- package/dist/api.js +40 -4
- package/dist/app-git.js +48 -0
- package/dist/bootstrap.json +10 -14
- package/dist/bridge.js +93 -78
- package/dist/calls.js +63 -0
- package/dist/chatgpt.js +32 -0
- package/dist/clis-main.js +23 -0
- package/dist/clis.js +217 -72
- package/dist/codex-main.js +58 -0
- package/dist/connection.js +126 -0
- package/dist/conversations.js +642 -263
- package/dist/copies.js +237 -173
- package/dist/end.js +27 -0
- package/dist/enrol-main.js +7 -1
- package/dist/events.js +525 -0
- package/dist/files.js +140 -17
- package/dist/git-main.js +2 -2
- package/dist/git.js +16 -10
- package/dist/home.js +127 -9
- package/dist/house-cli.js +300 -0
- package/dist/house-main.js +5 -102
- package/dist/instructions.js +16 -17
- package/dist/kit-cli.js +68 -0
- package/dist/kit-main.js +8 -16
- package/dist/login.js +128 -95
- package/dist/logout.js +19 -0
- package/dist/mcp.js +41 -0
- package/dist/operation.js +7 -4
- package/dist/parts.js +82 -0
- package/dist/placement.js +39 -0
- package/dist/refusals.js +53 -0
- package/dist/relay.js +20 -0
- package/dist/resident.js +139 -52
- package/dist/scope.js +206 -0
- package/dist/secret-input.js +7 -2
- package/dist/service-main.js +9 -0
- package/dist/service.js +55 -0
- package/dist/shell.js +3 -0
- package/dist/sign-in.js +50 -31
- package/dist/skills.js +20 -37
- package/dist/transcription.js +201 -0
- package/dist/translate.js +2 -8
- package/dist/update.js +138 -0
- package/dist/web-wizard.js +100 -0
- package/dist/wire.js +22 -0
- package/dist/work.js +346 -0
- package/package.json +9 -11
- package/dist/blocks.js +0 -51
- package/dist/stream.js +0 -47
- package/how-we-work.md +0 -25
- package/skills/ask-matt/LICENSE +0 -21
- package/skills/ask-matt/PHASE-BOUNDARIES.md +0 -55
- package/skills/ask-matt/SKILL.md +0 -91
- package/skills/ask-matt/agents/openai.yaml +0 -4
- package/skills/code-review/LICENSE +0 -21
- package/skills/code-review/SKILL.md +0 -89
- package/skills/code-review/agents/openai.yaml +0 -3
- package/skills/codebase-design/DEEPENING.md +0 -37
- package/skills/codebase-design/DESIGN-IT-TWICE.md +0 -44
- package/skills/codebase-design/LICENSE +0 -21
- package/skills/codebase-design/SKILL.md +0 -116
- package/skills/codebase-design/agents/openai.yaml +0 -3
- package/skills/diagnosing-bugs/LICENSE +0 -21
- package/skills/diagnosing-bugs/SKILL.md +0 -140
- package/skills/diagnosing-bugs/agents/openai.yaml +0 -3
- package/skills/diagnosing-bugs/scripts/hitl-loop.template.sh +0 -44
- package/skills/domain-modeling/ADR-FORMAT.md +0 -47
- package/skills/domain-modeling/CONTEXT-FORMAT.md +0 -60
- package/skills/domain-modeling/LICENSE +0 -21
- package/skills/domain-modeling/SKILL.md +0 -76
- package/skills/domain-modeling/agents/openai.yaml +0 -3
- package/skills/grill-me/LICENSE +0 -21
- package/skills/grill-me/SKILL.md +0 -8
- package/skills/grill-me/agents/openai.yaml +0 -4
- package/skills/grill-with-docs/LICENSE +0 -21
- package/skills/grill-with-docs/SKILL.md +0 -8
- package/skills/grill-with-docs/agents/openai.yaml +0 -4
- package/skills/grilling/LICENSE +0 -21
- package/skills/grilling/SKILL.md +0 -30
- package/skills/grilling/agents/openai.yaml +0 -3
- package/skills/handoff/LICENSE +0 -21
- package/skills/handoff/SKILL.md +0 -17
- package/skills/handoff/agents/openai.yaml +0 -4
- package/skills/implement/LICENSE +0 -21
- package/skills/implement/SKILL.md +0 -16
- package/skills/implement/agents/openai.yaml +0 -4
- package/skills/improve-codebase-architecture/HTML-REPORT.md +0 -123
- package/skills/improve-codebase-architecture/LICENSE +0 -21
- package/skills/improve-codebase-architecture/SKILL.md +0 -72
- package/skills/improve-codebase-architecture/agents/openai.yaml +0 -4
- package/skills/prototype/LICENSE +0 -21
- package/skills/prototype/LOGIC.md +0 -67
- package/skills/prototype/SKILL.md +0 -28
- package/skills/prototype/UI.md +0 -112
- package/skills/prototype/agents/openai.yaml +0 -3
- package/skills/research/LICENSE +0 -21
- package/skills/research/SKILL.md +0 -14
- package/skills/research/agents/openai.yaml +0 -3
- package/skills/resolving-merge-conflicts/LICENSE +0 -21
- package/skills/resolving-merge-conflicts/SKILL.md +0 -16
- package/skills/resolving-merge-conflicts/agents/openai.yaml +0 -3
- package/skills/tdd/LICENSE +0 -21
- package/skills/tdd/SKILL.md +0 -40
- package/skills/tdd/agents/openai.yaml +0 -3
- package/skills/tdd/mocking.md +0 -59
- package/skills/tdd/tests.md +0 -77
- package/skills/teach/GLOSSARY-FORMAT.md +0 -35
- package/skills/teach/LEARNING-RECORD-FORMAT.md +0 -46
- package/skills/teach/LICENSE +0 -21
- package/skills/teach/MISSION-FORMAT.md +0 -31
- package/skills/teach/RESOURCES-FORMAT.md +0 -32
- package/skills/teach/SKILL.md +0 -141
- package/skills/teach/agents/openai.yaml +0 -4
- package/skills/to-questionnaire/LICENSE +0 -21
- package/skills/to-questionnaire/SKILL.md +0 -55
- package/skills/to-questionnaire/agents/openai.yaml +0 -4
- package/skills/to-spec/LICENSE +0 -21
- package/skills/to-spec/SKILL.md +0 -76
- package/skills/to-spec/agents/openai.yaml +0 -4
- package/skills/to-tickets/LICENSE +0 -21
- package/skills/to-tickets/SKILL.md +0 -106
- package/skills/to-tickets/agents/openai.yaml +0 -4
- package/skills/wait-what/LICENSE +0 -21
- package/skills/wait-what/SKILL.md +0 -8
- package/skills/wait-what/agents/openai.yaml +0 -4
- package/skills/wayfinder/LICENSE +0 -21
- package/skills/wayfinder/SKILL.md +0 -129
- package/skills/wayfinder/agents/openai.yaml +0 -4
- package/skills/writing-for-agents/LICENSE +0 -21
- package/skills/writing-for-agents/SKILL-MECHANICS.md +0 -22
- package/skills/writing-for-agents/SKILL.md +0 -83
- package/skills/writing-for-agents/agents/openai.yaml +0 -3
package/dist/house-main.js
CHANGED
|
@@ -1,107 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import { basename, join } from 'node:path';
|
|
6
|
-
import { kitHome } from './home.js';
|
|
7
|
-
const USAGE = "usage: house <tool> ['<arguments as JSON>']";
|
|
8
|
-
const GIT_HELP = 'Submit a Room commit to House; default HEAD. Use --owner only outside an Agent conversation. Native git push is not a House remote.';
|
|
9
|
-
const GIT_USAGE = `usage: house git push [commit] [--owner]\n${GIT_HELP}`;
|
|
10
|
-
const socketPath = process.env.HOUSE_BRIDGE;
|
|
11
|
-
function bridged(path, body, headers = { 'content-type': 'application/json' }, to = socketPath) {
|
|
12
|
-
return new Promise((resolve, reject) => {
|
|
13
|
-
const sent = request({ socketPath: to, path, method: 'POST', headers }, (answer) => {
|
|
14
|
-
let text = '';
|
|
15
|
-
answer.setEncoding('utf8');
|
|
16
|
-
answer.on('data', (chunk) => {
|
|
17
|
-
text += chunk;
|
|
18
|
-
});
|
|
19
|
-
answer.on('end', () => {
|
|
20
|
-
if (answer.statusCode === 200)
|
|
21
|
-
resolve(text);
|
|
22
|
-
else
|
|
23
|
-
reject(new Error(`${path} answered ${answer.statusCode}: ${text}`));
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
sent.on('error', reject);
|
|
27
|
-
sent.end(body instanceof Buffer ? body : JSON.stringify(body));
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
async function mcp(method, params) {
|
|
31
|
-
const answer = JSON.parse(await bridged('/', { jsonrpc: '2.0', id: 1, method, params }));
|
|
32
|
-
if (answer.error !== undefined)
|
|
33
|
-
throw new Error(answer.error.message);
|
|
34
|
-
return answer.result;
|
|
35
|
-
}
|
|
36
|
-
async function tools() {
|
|
37
|
-
return (await mcp('tools/list', {})).tools;
|
|
38
|
-
}
|
|
39
|
-
async function upload(path, roomRef) {
|
|
40
|
-
const bytes = await readFile(path);
|
|
41
|
-
const declared = JSON.parse(await bridged('/kit/attachments/upload', {
|
|
42
|
-
...(roomRef === undefined ? {} : { room_ref: roomRef }),
|
|
43
|
-
version: randomUUID(),
|
|
44
|
-
name: basename(path),
|
|
45
|
-
bytes: bytes.length,
|
|
46
|
-
sha256: createHash('sha256').update(bytes).digest('hex'),
|
|
47
|
-
}));
|
|
48
|
-
return bridged(declared.upload.url, bytes, {
|
|
49
|
-
'content-type': 'application/octet-stream',
|
|
50
|
-
'x-house-byte-operation': declared.upload.operation,
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
async function gitPush(args) {
|
|
54
|
-
if (args.includes('--help'))
|
|
55
|
-
return GIT_USAGE;
|
|
56
|
-
if (args[0] !== 'push')
|
|
57
|
-
throw new Error(GIT_USAGE);
|
|
58
|
-
const owner = args.includes('--owner');
|
|
59
|
-
const commit = args.slice(1).find((arg) => arg !== '--owner') ?? 'HEAD';
|
|
60
|
-
if (owner && socketPath !== undefined)
|
|
61
|
-
throw new Error('house git push --owner runs outside an Agent conversation');
|
|
62
|
-
if (!owner && socketPath === undefined)
|
|
63
|
-
throw new Error('outside an Agent conversation, house git push needs --owner');
|
|
64
|
-
const pushed = JSON.parse(await bridged('/git/push', { cwd: process.cwd(), commit }, undefined, owner ? join(kitHome(), 'owner.sock') : socketPath));
|
|
65
|
-
if (pushed.refused)
|
|
66
|
-
throw new Error(pushed.text);
|
|
67
|
-
return pushed.text;
|
|
68
|
-
}
|
|
69
|
-
async function house([verb, argument]) {
|
|
70
|
-
if (verb === undefined || verb === '--help') {
|
|
71
|
-
return [USAGE, `git push [commit]: ${GIT_HELP}`, ...(await tools()).map((tool) => `${tool.name}: ${tool.description}`)].join('\n');
|
|
72
|
-
}
|
|
73
|
-
if (argument === '--help') {
|
|
74
|
-
const tool = (await tools()).find((listed) => listed.name === verb);
|
|
75
|
-
if (tool === undefined)
|
|
76
|
-
throw new Error(`House has no tool ${verb}`);
|
|
77
|
-
return `${tool.description}\n${JSON.stringify(tool.inputSchema, null, 2)}`;
|
|
78
|
-
}
|
|
79
|
-
const args = (argument === undefined ? {} : JSON.parse(argument));
|
|
80
|
-
if (verb === 'upload_attachment')
|
|
81
|
-
return upload(String(args.path), args.room_ref);
|
|
82
|
-
if (verb === 'append_record' && Array.isArray(args.attachments)) {
|
|
83
|
-
const attachments = [];
|
|
84
|
-
for (const path of args.attachments) {
|
|
85
|
-
attachments.push(JSON.parse(await upload(String(path), args.room_ref)).attachment);
|
|
86
|
-
}
|
|
87
|
-
args.attachments = attachments;
|
|
88
|
-
}
|
|
89
|
-
const result = await mcp('tools/call', { name: verb, arguments: args });
|
|
90
|
-
const text = result.content.map((content) => content.text).join('\n');
|
|
91
|
-
if (result.isError === true)
|
|
92
|
-
throw new Error(text);
|
|
93
|
-
return text;
|
|
94
|
-
}
|
|
95
|
-
const argv = process.argv.slice(2);
|
|
96
|
-
if (argv[0] !== 'git' && socketPath === undefined) {
|
|
97
|
-
process.stderr.write('house: house runs inside an Agent conversation\n');
|
|
2
|
+
const [major = 0, minor = 0] = process.versions.node.split('.').map(Number);
|
|
3
|
+
if (major < 24 || (major === 24 && minor < 14)) {
|
|
4
|
+
process.stderr.write(`house: the Kit needs Node 24.14.0 or newer; this is ${process.versions.node}\n`);
|
|
98
5
|
process.exitCode = 1;
|
|
99
6
|
}
|
|
100
7
|
else {
|
|
101
|
-
(
|
|
102
|
-
process.stdout.write(`${text}\n`);
|
|
103
|
-
}, (error) => {
|
|
104
|
-
process.stderr.write(`house: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
105
|
-
process.exitCode = 1;
|
|
106
|
-
});
|
|
8
|
+
await import('./house-cli.js');
|
|
107
9
|
}
|
|
10
|
+
export {};
|
package/dist/instructions.js
CHANGED
|
@@ -1,33 +1,32 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
const
|
|
4
|
-
const FILE_LINE = 'To give the User a file, upload it with `house upload_attachment` and link it in your answer.';
|
|
5
|
-
const COPIES_LINE = 'These House paths are Git working copies here; commit in one and run `house git push` to send the commit to House:';
|
|
1
|
+
import { agentInstructions } from '@agentshouse/skills';
|
|
2
|
+
import { HOUSE_REF } from './git.js';
|
|
3
|
+
const HOW_WE_WORK = '/rooms/private/how-we-work.md';
|
|
6
4
|
const UNREADABLE = /^(?:\S+: )?(?:path_not_found|room_not_found|operation_denied)\b/;
|
|
5
|
+
const FAILED = /^exit: [1-9]\d*$/;
|
|
7
6
|
const CUT = /^stderr: shell: output_cut (\d+) of \d+ bytes; continue with: (.+)$/;
|
|
8
|
-
|
|
7
|
+
function cutOf(lines) {
|
|
8
|
+
const cut = CUT.exec(lines[0] ?? '');
|
|
9
|
+
return cut !== null && Buffer.byteLength(lines.slice(1).join('\n')) === Number(cut[1]) ? cut : null;
|
|
10
|
+
}
|
|
11
|
+
async function readHowWeWork(bridge) {
|
|
9
12
|
let document = '';
|
|
10
13
|
for (let command = `cat ${HOW_WE_WORK}`; command !== undefined;) {
|
|
11
14
|
const read = await bridge.tool('shell', { command });
|
|
12
15
|
const text = read.content.map((content) => content.text).join('\n');
|
|
13
16
|
const lines = text.split('\n');
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const refusal = read.isError === true ? text : lines.slice(at).join('\n').replace(/^stderr: /gm, '');
|
|
17
|
+
if (read.isError === true || (FAILED.test(lines[0] ?? '') && lines[1]?.startsWith('stderr: '))) {
|
|
18
|
+
const refusal = read.isError === true ? text : lines.slice(1).join('\n').replace(/^stderr: /gm, '');
|
|
17
19
|
if (UNREADABLE.test(refusal))
|
|
18
20
|
return '';
|
|
19
21
|
throw new Error(refusal);
|
|
20
22
|
}
|
|
21
|
-
const cut =
|
|
22
|
-
|
|
23
|
-
document += (cut === null ? shown : shown.subarray(0, Number(cut[1]))).toString();
|
|
23
|
+
const cut = cutOf(lines);
|
|
24
|
+
document += lines.slice(cut === null ? 0 : 1).join('\n');
|
|
24
25
|
command = cut?.[2];
|
|
25
26
|
}
|
|
26
|
-
return document
|
|
27
|
+
return document;
|
|
27
28
|
}
|
|
28
29
|
export async function instructions(bridge, base, copies) {
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
const lines = [HOUSE_LINE, FILE_LINE, appLine, ...(copies.length === 0 ? [] : [COPIES_LINE, ...copies])];
|
|
32
|
-
return [lines.join('\n'), base, await howWeWork(bridge)].filter((part) => part !== '').join('\n\n');
|
|
30
|
+
const lines = agentInstructions(HOUSE_REF, copies);
|
|
31
|
+
return [lines.join('\n'), base, (await readHowWeWork(bridge)).replace(/\n$/, '')].filter((part) => part !== '').join('\n\n');
|
|
33
32
|
}
|
package/dist/kit-cli.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { setGlobalProxyFromEnv } from 'node:http';
|
|
2
|
+
import { parseArgs } from 'node:util';
|
|
3
|
+
import { answerGitCredential } from './app-git.js';
|
|
4
|
+
import { chatgpt } from './chatgpt.js';
|
|
5
|
+
import { login } from './login.js';
|
|
6
|
+
import { logout } from './logout.js';
|
|
7
|
+
import { resident } from './resident.js';
|
|
8
|
+
const USAGE = 'usage: kit <login|logout|resident|chatgpt>\n';
|
|
9
|
+
const COMMANDS = new Map([
|
|
10
|
+
[
|
|
11
|
+
'logout',
|
|
12
|
+
{
|
|
13
|
+
usage: 'usage: kit logout',
|
|
14
|
+
about: "disconnects this computer, stops the Kit process and ends your own agent's connection",
|
|
15
|
+
operands: 0,
|
|
16
|
+
run: logout,
|
|
17
|
+
},
|
|
18
|
+
],
|
|
19
|
+
[
|
|
20
|
+
'resident',
|
|
21
|
+
{
|
|
22
|
+
usage: 'usage: kit resident',
|
|
23
|
+
about: "keeps this Environment connected; Kit's service runs it",
|
|
24
|
+
operands: 0,
|
|
25
|
+
run: resident,
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
[
|
|
29
|
+
'git-credential',
|
|
30
|
+
{
|
|
31
|
+
usage: 'usage: kit git-credential <get|store|erase>',
|
|
32
|
+
about: "answers git with your own agent's House credential; git runs it",
|
|
33
|
+
operands: 1,
|
|
34
|
+
run: ([operation]) => answerGitCredential(operation),
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
]);
|
|
38
|
+
const [command, ...argv] = process.argv.slice(2);
|
|
39
|
+
setGlobalProxyFromEnv();
|
|
40
|
+
async function run() {
|
|
41
|
+
if (command === 'login')
|
|
42
|
+
return login(argv);
|
|
43
|
+
if (command === 'chatgpt')
|
|
44
|
+
return chatgpt(argv);
|
|
45
|
+
if (command === '--help') {
|
|
46
|
+
parseArgs({ args: argv });
|
|
47
|
+
process.stdout.write(USAGE);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const chosen = COMMANDS.get(command ?? '');
|
|
51
|
+
if (chosen === undefined) {
|
|
52
|
+
process.stderr.write(USAGE);
|
|
53
|
+
process.exitCode = 2;
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const { values, positionals } = parseArgs({ args: argv, options: { help: { type: 'boolean', default: false } }, allowPositionals: true });
|
|
57
|
+
if (positionals.length > chosen.operands)
|
|
58
|
+
throw new Error(`unexpected argument ${positionals[chosen.operands]}; ${chosen.usage}`);
|
|
59
|
+
if (values.help) {
|
|
60
|
+
process.stdout.write(`${chosen.usage}\n ${chosen.about}\n`);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
return chosen.run(positionals);
|
|
64
|
+
}
|
|
65
|
+
run().catch((error) => {
|
|
66
|
+
process.stderr.write(`kit: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
67
|
+
process.exitCode = 1;
|
|
68
|
+
});
|
package/dist/kit-main.js
CHANGED
|
@@ -1,18 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const [command, ...argv] = process.argv.slice(2);
|
|
6
|
-
setGlobalProxyFromEnv();
|
|
7
|
-
async function run() {
|
|
8
|
-
if (command === 'login')
|
|
9
|
-
return login(argv);
|
|
10
|
-
if (command === 'resident')
|
|
11
|
-
return resident();
|
|
12
|
-
process.stderr.write('usage: kit <login|resident>\n');
|
|
13
|
-
process.exitCode = 2;
|
|
14
|
-
}
|
|
15
|
-
run().catch((error) => {
|
|
16
|
-
process.stderr.write(`kit: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
2
|
+
const [major = 0, minor = 0] = process.versions.node.split('.').map(Number);
|
|
3
|
+
if (major < 24 || (major === 24 && minor < 14)) {
|
|
4
|
+
process.stderr.write(`kit: the Kit needs Node 24.14.0 or newer; this is ${process.versions.node}\n`);
|
|
17
5
|
process.exitCode = 1;
|
|
18
|
-
}
|
|
6
|
+
}
|
|
7
|
+
else {
|
|
8
|
+
await import('./kit-cli.js');
|
|
9
|
+
}
|
|
10
|
+
export {};
|
package/dist/login.js
CHANGED
|
@@ -1,64 +1,56 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
1
2
|
import { createHash, randomBytes } from 'node:crypto';
|
|
2
|
-
import { createServer } from 'node:http';
|
|
3
|
-
import { hostname } from 'node:os';
|
|
4
|
-
import { createInterface } from 'node:readline/promises';
|
|
5
3
|
import { parseArgs } from 'node:util';
|
|
6
|
-
import { post } from './api.js';
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
deliver(received);
|
|
24
|
-
});
|
|
25
|
-
const close = () => {
|
|
26
|
-
server.close();
|
|
27
|
-
server.closeAllConnections();
|
|
28
|
-
};
|
|
29
|
-
const port = Number(process.env.HOUSE_KIT_LOGIN_PORT ?? 0);
|
|
30
|
-
server.once('error', reject);
|
|
31
|
-
server.listen(port, port === 0 ? '127.0.0.1' : '0.0.0.0', () => {
|
|
32
|
-
const address = server.address();
|
|
33
|
-
if (address === null || typeof address === 'string') {
|
|
34
|
-
reject(new Error('the login callback has no port'));
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
resolve({
|
|
38
|
-
uri: `http://127.0.0.1:${address.port}/callback`,
|
|
39
|
-
code,
|
|
40
|
-
answer: (text) => new Promise((written) => {
|
|
41
|
-
if (held === null || held.destroyed || !held.socket || held.socket.destroyed)
|
|
42
|
-
return written();
|
|
43
|
-
held.once('close', () => written());
|
|
44
|
-
held.writeHead(200, { 'content-type': 'text/plain; charset=utf-8', connection: 'close' }).end(`${text}\n`);
|
|
45
|
-
}),
|
|
46
|
-
close,
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
});
|
|
4
|
+
import { HouseRefusal, post, retrying } from './api.js';
|
|
5
|
+
import { placeAppGit } from './app-git.js';
|
|
6
|
+
import { writeCodexRule } from './clis.js';
|
|
7
|
+
import { forgetDisconnected, forgetOwnAgent, readDisconnected, readEnrolment, readOwnAgent, writeEnrolment, writeOwnAgent, } from './home.js';
|
|
8
|
+
import { callHouse, rpc } from './mcp.js';
|
|
9
|
+
import { refusalOf } from './refusals.js';
|
|
10
|
+
import { selectRelay } from './relay.js';
|
|
11
|
+
import { startService } from './service.js';
|
|
12
|
+
import { placeSkillSet } from './skills.js';
|
|
13
|
+
export const DEFAULT_HOUSE = 'https://agents.house';
|
|
14
|
+
const OPENER = process.platform === 'darwin' ? 'open' : 'xdg-open';
|
|
15
|
+
// Polling every two seconds brings the User's confirmation to the waiting Kit moments after they give it.
|
|
16
|
+
const POLL_INTERVAL_MS = 2000;
|
|
17
|
+
function open(link) {
|
|
18
|
+
spawn(OPENER, [link], { detached: true, stdio: 'ignore' })
|
|
19
|
+
.on('error', () => undefined)
|
|
20
|
+
.unref();
|
|
50
21
|
}
|
|
51
|
-
async function
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
22
|
+
export async function accepted(house, credential) {
|
|
23
|
+
const checked = await callHouse(house, credential, rpc('tools/list', {}));
|
|
24
|
+
if (checked.status === 200)
|
|
25
|
+
return true;
|
|
26
|
+
if (checked.status === 401)
|
|
27
|
+
return false;
|
|
28
|
+
throw new Error(`House answered ${checked.status} when Kit checked this computer's own agent's connection: ${checked.text}`);
|
|
29
|
+
}
|
|
30
|
+
const USAGE = `usage: kit login [--house <origin>] [--environment <id>] [--rooms <ref>[,<ref>...] | --no-private]
|
|
31
|
+
kit login [--house <origin>] --code <code>
|
|
32
|
+
--house <origin> the House to connect to, ${DEFAULT_HOUSE} unless one is stored
|
|
33
|
+
--environment <id> reconnect this Environment
|
|
34
|
+
--rooms <ref>[,<ref>...] give this Environment only these Rooms
|
|
35
|
+
--no-private give this Environment every Room but your Private Room
|
|
36
|
+
--code <code> connect this machine with a login code
|
|
37
|
+
`;
|
|
38
|
+
function connected(house, named, environment) {
|
|
39
|
+
if (named === undefined)
|
|
40
|
+
return `Environment ${environment} is connected to ${house}.\n`;
|
|
41
|
+
if (named === environment)
|
|
42
|
+
return `Environment ${environment} is reconnected to ${house}.\n`;
|
|
43
|
+
return `Environment ${named} stays with its account; this computer is connected to ${house} as new Environment ${environment} of the account that confirmed.\n`;
|
|
44
|
+
}
|
|
45
|
+
function gone(error) {
|
|
46
|
+
return error instanceof HouseRefusal && refusalOf(error.text)?.code === 'kit_environment_not_found';
|
|
47
|
+
}
|
|
48
|
+
function chosenRooms(rooms, noPrivate) {
|
|
49
|
+
if (rooms !== undefined && noPrivate)
|
|
50
|
+
throw new Error('--rooms and --no-private are two choices of Rooms; pass one');
|
|
51
|
+
if (rooms !== undefined)
|
|
52
|
+
return { rooms: { reach: 'selected', refs: rooms.split(',') } };
|
|
53
|
+
return noPrivate ? { rooms: { reach: 'all_but_private' } } : {};
|
|
62
54
|
}
|
|
63
55
|
export async function login(argv) {
|
|
64
56
|
const { values } = parseArgs({
|
|
@@ -66,51 +58,92 @@ export async function login(argv) {
|
|
|
66
58
|
options: {
|
|
67
59
|
house: { type: 'string' },
|
|
68
60
|
environment: { type: 'string' },
|
|
69
|
-
|
|
61
|
+
rooms: { type: 'string' },
|
|
62
|
+
'no-private': { type: 'boolean', default: false },
|
|
63
|
+
code: { type: 'string' },
|
|
64
|
+
help: { type: 'boolean', default: false },
|
|
70
65
|
},
|
|
71
66
|
});
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
const environment = values.environment ?? (enrolled?.house === house ? enrolled.environment : undefined);
|
|
75
|
-
const verifier = randomBytes(32).toString('base64url');
|
|
76
|
-
const started = {
|
|
77
|
-
...(environment === undefined
|
|
78
|
-
? { act: 'new_environment', label: hostname() }
|
|
79
|
-
: { act: 'existing_environment', environment_id: environment }),
|
|
80
|
-
code_challenge: createHash('sha256').update(verifier).digest('base64url'),
|
|
81
|
-
};
|
|
82
|
-
const exchange = async (code) => {
|
|
83
|
-
const exchanged = await post(house, '/kit/token', { code, code_verifier: verifier });
|
|
84
|
-
await writeEnrolment({ house, environment: exchanged.environment, credential: exchanged.credential });
|
|
85
|
-
process.stdout.write(`Environment ${exchanged.environment} is connected to ${house}.\n`);
|
|
86
|
-
};
|
|
87
|
-
if (values.manual) {
|
|
88
|
-
const { start_url } = await post(house, '/kit', {
|
|
89
|
-
...started,
|
|
90
|
-
presentation: 'manual',
|
|
91
|
-
});
|
|
92
|
-
process.stdout.write(`Open this link and confirm: ${start_url}\n`);
|
|
93
|
-
await exchange(await typed('Code: '));
|
|
67
|
+
if (values.help) {
|
|
68
|
+
process.stdout.write(USAGE);
|
|
94
69
|
return;
|
|
95
70
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
71
|
+
if (values.code !== undefined && values.rooms !== undefined)
|
|
72
|
+
throw new Error('--code cannot be used with --rooms');
|
|
73
|
+
if (values.code !== undefined && values['no-private'])
|
|
74
|
+
throw new Error('--code cannot be used with --no-private');
|
|
75
|
+
if (values.code !== undefined && values.environment !== undefined)
|
|
76
|
+
throw new Error('--code cannot be used with --environment');
|
|
77
|
+
const rooms = chosenRooms(values.rooms, values['no-private']);
|
|
78
|
+
const enrolled = (await readEnrolment()) ?? (await readDisconnected());
|
|
79
|
+
if (values.code !== undefined && enrolled !== null) {
|
|
80
|
+
throw new Error(`--code connects a new machine; this Kit home records Environment ${enrolled.environment}, so run kit login to reconnect it`);
|
|
81
|
+
}
|
|
82
|
+
const relay = process.env.HOUSE_KIT_RELAY || undefined;
|
|
83
|
+
selectRelay(relay);
|
|
84
|
+
const house = values.house ?? enrolled?.house ?? DEFAULT_HOUSE;
|
|
85
|
+
const replaces = process.env.HOUSE_KIT_REPLACES;
|
|
86
|
+
const remembered = replaces === undefined && values.environment === undefined && enrolled?.house === house ? enrolled.environment : undefined;
|
|
87
|
+
const environment = replaces === undefined ? (values.environment ?? remembered) : undefined;
|
|
88
|
+
const ownAgent = await readOwnAgent();
|
|
89
|
+
let held = false;
|
|
90
|
+
let named = environment;
|
|
91
|
+
let exchanged;
|
|
92
|
+
if (values.code !== undefined) {
|
|
93
|
+
exchanged = await post(house, '/kit/token', { code: values.code });
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
held = ownAgent !== null && ownAgent.house === house && (await accepted(house, ownAgent.credential));
|
|
97
|
+
const verifier = randomBytes(32).toString('base64url');
|
|
98
|
+
const start = () => retrying(() => post(house, '/kit', {
|
|
99
|
+
...(named === undefined
|
|
100
|
+
? { act: 'new_environment', ...(replaces === undefined ? {} : { replaces }) }
|
|
101
|
+
: { act: 'existing_environment', environment_id: named }),
|
|
102
|
+
...rooms,
|
|
103
|
+
code_challenge: createHash('sha256').update(verifier).digest('base64url'),
|
|
104
|
+
...(held ? {} : { headless: true }),
|
|
105
|
+
}));
|
|
106
|
+
let started;
|
|
104
107
|
try {
|
|
105
|
-
await
|
|
108
|
+
started = await start();
|
|
106
109
|
}
|
|
107
110
|
catch (error) {
|
|
108
|
-
|
|
109
|
-
|
|
111
|
+
if (remembered === undefined || !gone(error))
|
|
112
|
+
throw error;
|
|
113
|
+
await forgetDisconnected();
|
|
114
|
+
process.stdout.write(`House no longer holds Environment ${remembered}; connecting this computer as a new one.\n`);
|
|
115
|
+
named = undefined;
|
|
116
|
+
started = await start();
|
|
110
117
|
}
|
|
111
|
-
|
|
118
|
+
process.stdout.write(`Open this link and confirm: ${started.start_url}\n`);
|
|
119
|
+
open(started.start_url);
|
|
120
|
+
exchanged = await retrying(() => post(house, '/kit/token', { login: started.login, code_verifier: verifier }), undefined, () => POLL_INTERVAL_MS);
|
|
121
|
+
}
|
|
122
|
+
await placeSkillSet();
|
|
123
|
+
await writeCodexRule().catch((error) => process.stderr.write(`kit: ${error.message}\n`));
|
|
124
|
+
const relayRecord = relay === undefined ? {} : { relay };
|
|
125
|
+
await writeEnrolment({
|
|
126
|
+
house,
|
|
127
|
+
...relayRecord,
|
|
128
|
+
environment: exchanged.environment,
|
|
129
|
+
credential: exchanged.credential,
|
|
130
|
+
});
|
|
131
|
+
process.stdout.write(connected(house, named, exchanged.environment));
|
|
132
|
+
if (exchanged.headless_credential !== undefined) {
|
|
133
|
+
await writeOwnAgent({ house, ...relayRecord, user: exchanged.user, credential: exchanged.headless_credential });
|
|
134
|
+
}
|
|
135
|
+
else if (held && ownAgent !== null && ownAgent.user !== exchanged.user) {
|
|
136
|
+
await forgetOwnAgent();
|
|
137
|
+
process.stdout.write("This computer's own agent was another User's; run kit login again to connect it to you.\n");
|
|
138
|
+
}
|
|
139
|
+
else if (held && ownAgent !== null) {
|
|
140
|
+
await writeOwnAgent({ house, ...relayRecord, user: ownAgent.user, credential: ownAgent.credential });
|
|
141
|
+
}
|
|
142
|
+
await placeAppGit(await readOwnAgent()).catch((error) => process.stderr.write(`kit: ${error.message}\n`));
|
|
143
|
+
try {
|
|
144
|
+
startService();
|
|
112
145
|
}
|
|
113
|
-
|
|
114
|
-
|
|
146
|
+
catch (error) {
|
|
147
|
+
process.stderr.write(`kit: ${error.message}\n`);
|
|
115
148
|
}
|
|
116
149
|
}
|
package/dist/logout.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { HouseRefusal, post } from './api.js';
|
|
2
|
+
import { forgetEnrolment, forgetOwnAgent, readEnrolment } from './home.js';
|
|
3
|
+
export async function logout() {
|
|
4
|
+
const enrolled = await readEnrolment();
|
|
5
|
+
if (enrolled !== null) {
|
|
6
|
+
try {
|
|
7
|
+
await post(enrolled.house, '/kit/logout', {}, enrolled.credential);
|
|
8
|
+
}
|
|
9
|
+
catch (error) {
|
|
10
|
+
if (!(error instanceof HouseRefusal && error.status === 401))
|
|
11
|
+
throw error;
|
|
12
|
+
}
|
|
13
|
+
await forgetEnrolment(enrolled);
|
|
14
|
+
}
|
|
15
|
+
await forgetOwnAgent();
|
|
16
|
+
process.stdout.write(enrolled === null
|
|
17
|
+
? 'This computer is not connected to House.\n'
|
|
18
|
+
: `Environment ${enrolled.environment} is disconnected; kit login reconnects it.\n`);
|
|
19
|
+
}
|
package/dist/mcp.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { KIT_RELEASE } from './clis.js';
|
|
3
|
+
import { relayed } from './relay.js';
|
|
4
|
+
const MCP_PROTOCOL_VERSION = '2026-07-28';
|
|
5
|
+
export const UNREACHABLE = 'House is unreachable; call again in a minute';
|
|
6
|
+
export class Unsettled extends Error {
|
|
7
|
+
}
|
|
8
|
+
export function rpc(method, params) {
|
|
9
|
+
return { jsonrpc: '2.0', id: randomUUID(), method, params };
|
|
10
|
+
}
|
|
11
|
+
export function mcpBody(message, operation) {
|
|
12
|
+
return JSON.stringify({
|
|
13
|
+
...message,
|
|
14
|
+
params: {
|
|
15
|
+
...message.params,
|
|
16
|
+
_meta: {
|
|
17
|
+
'io.modelcontextprotocol/protocolVersion': MCP_PROTOCOL_VERSION,
|
|
18
|
+
'io.modelcontextprotocol/clientInfo': { name: '@agentshouse/kit', version: KIT_RELEASE },
|
|
19
|
+
'io.modelcontextprotocol/clientCapabilities': {},
|
|
20
|
+
...(operation === null ? {} : { 'agents.house/agent-operation': operation }),
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
export async function callHouse(origin, credential, message, operation = null, signal) {
|
|
26
|
+
const tool = message.method === 'tools/call' ? String(message.params.name) : null;
|
|
27
|
+
const answer = await fetch(relayed(new URL('/', origin)), {
|
|
28
|
+
method: 'POST',
|
|
29
|
+
headers: {
|
|
30
|
+
'content-type': 'application/json',
|
|
31
|
+
authorization: `Bearer ${credential}`,
|
|
32
|
+
accept: 'application/json, text/event-stream',
|
|
33
|
+
'mcp-protocol-version': MCP_PROTOCOL_VERSION,
|
|
34
|
+
'mcp-method': message.method,
|
|
35
|
+
...(tool === null ? {} : { 'mcp-name': tool }),
|
|
36
|
+
},
|
|
37
|
+
body: mcpBody(message, operation),
|
|
38
|
+
signal,
|
|
39
|
+
});
|
|
40
|
+
return { status: answer.status, text: await answer.text() };
|
|
41
|
+
}
|
package/dist/operation.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { randomBytes } from 'node:crypto';
|
|
2
|
+
export function uuidOf(bytes, version) {
|
|
3
|
+
bytes[6] = (version << 4) | (bytes[6] & 0x0f);
|
|
4
|
+
bytes[8] = 0x80 | (bytes[8] & 0x3f);
|
|
5
|
+
const hex = bytes.toString('hex', 0, 16);
|
|
6
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
7
|
+
}
|
|
2
8
|
export function operationId() {
|
|
3
9
|
const bytes = randomBytes(16);
|
|
4
10
|
bytes.writeUIntBE(Date.now(), 0, 6);
|
|
5
|
-
|
|
6
|
-
bytes[8] = 0x80 | (bytes[8] & 0x3f);
|
|
7
|
-
const hex = bytes.toString('hex');
|
|
8
|
-
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
11
|
+
return uuidOf(bytes, 7);
|
|
9
12
|
}
|