@agentshouse/kit 0.2.1-ce145e9aadbf6 → 0.2.1-ce47f621f90e1
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 +47 -46
- package/dist/acp.js +102 -108
- package/dist/agents.js +189 -56
- package/dist/api.js +34 -2
- package/dist/app-git.js +48 -0
- package/dist/authority-main.js +2 -2
- package/dist/bridge.js +37 -58
- package/dist/building.js +50 -0
- package/dist/calls.js +71 -0
- package/dist/chatgpt.js +32 -0
- package/dist/clis.js +150 -99
- package/dist/codex-main.js +58 -0
- package/dist/connection.js +105 -0
- package/dist/conversations.js +731 -332
- package/dist/copies.js +188 -128
- package/dist/end.js +33 -0
- package/dist/enrol-main.js +7 -1
- package/dist/events.js +546 -0
- package/dist/files.js +139 -17
- package/dist/git.js +13 -11
- package/dist/home.js +89 -7
- package/dist/house-cli.js +299 -0
- package/dist/house-main.js +7 -159
- package/dist/instructions.js +8 -10
- package/dist/kit-cli.js +68 -0
- package/dist/kit-main.js +8 -19
- package/dist/login.js +119 -104
- package/dist/logout.js +14 -13
- package/dist/mcp.js +6 -2
- package/dist/parts.js +82 -0
- package/dist/placement.js +31 -0
- package/dist/refusals.js +12 -0
- package/dist/relay.js +33 -2
- package/dist/resident.js +117 -51
- package/dist/scope.js +214 -0
- package/dist/scripts.js +255 -0
- package/dist/secret-input.js +3 -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 +40 -33
- package/dist/silence.js +28 -0
- package/dist/skills.js +49 -35
- package/dist/transcription.js +129 -41
- package/dist/translate.js +2 -8
- package/dist/update.js +113 -103
- package/dist/wire.js +40 -0
- package/dist/work.js +346 -0
- package/package.json +20 -20
- package/dist/blocks.js +0 -51
- package/dist/bootstrap.json +0 -24
- package/dist/clis-main.js +0 -23
- package/dist/stream.js +0 -47
- package/how-we-work.md +0 -23
- 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,162 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import { kitHome, readOwnAgent } from './home.js';
|
|
7
|
-
import { callHouse, rpc, UNREACHABLE } from './mcp.js';
|
|
8
|
-
import { refusalOf } from './refusals.js';
|
|
9
|
-
const USAGE = "usage: house <tool> ['<arguments as JSON>']";
|
|
10
|
-
const PUSH_USAGE = 'usage: house push [commit] [--owner]';
|
|
11
|
-
const PUSH = "push [commit]: sends the Local copy's committed changes to House";
|
|
12
|
-
const ARGUMENTS = `the arguments are one JSON object in single quotes, like house search '{"query":"invoice"}'`;
|
|
13
|
-
const CLOSED = "this conversation's House connection is closed; nothing to do from here";
|
|
14
|
-
const REVOKED = 'this conversation no longer has House access; nothing to do from here';
|
|
15
|
-
const UNCONNECTED = "this computer's own agent has no House connection; run kit login";
|
|
16
|
-
const DISCONNECTED = "House no longer accepts this computer's own agent; run kit login";
|
|
17
|
-
const socketPath = process.env.HOUSE_BRIDGE;
|
|
18
|
-
function refused(path, status, text) {
|
|
19
|
-
const refusal = refusalOf(text);
|
|
20
|
-
if (refusal !== null)
|
|
21
|
-
return refusal.text;
|
|
22
|
-
if (status === 401)
|
|
23
|
-
return REVOKED;
|
|
24
|
-
if (URL.canParse(path))
|
|
25
|
-
return `the upload answered ${status}; upload the file again`;
|
|
26
|
-
if (status === 502 && /^[A-Za-z]/.test(text))
|
|
27
|
-
return text;
|
|
28
|
-
return `${path} answered ${status}`;
|
|
29
|
-
}
|
|
30
|
-
function bridged(path, body, headers = { 'content-type': 'application/json' }, to = socketPath) {
|
|
31
|
-
return new Promise((resolve, reject) => {
|
|
32
|
-
const sent = request({ socketPath: to, path, method: 'POST', headers }, (answer) => {
|
|
33
|
-
let text = '';
|
|
34
|
-
answer.setEncoding('utf8');
|
|
35
|
-
answer.on('data', (chunk) => {
|
|
36
|
-
text += chunk;
|
|
37
|
-
});
|
|
38
|
-
answer.on('end', () => {
|
|
39
|
-
if (answer.statusCode === 200)
|
|
40
|
-
resolve(text);
|
|
41
|
-
else
|
|
42
|
-
reject(new Error(refused(path, answer.statusCode, text)));
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
sent.on('error', () => reject(new Error(CLOSED)));
|
|
46
|
-
sent.end(body instanceof Buffer ? body : JSON.stringify(body));
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
async function direct(message) {
|
|
50
|
-
const ownAgent = await readOwnAgent();
|
|
51
|
-
if (ownAgent === null)
|
|
52
|
-
throw new Error(UNCONNECTED);
|
|
53
|
-
setGlobalProxyFromEnv();
|
|
54
|
-
const answer = await callHouse(ownAgent.house, ownAgent.credential, message).catch(() => {
|
|
55
|
-
throw new Error(UNREACHABLE);
|
|
56
|
-
});
|
|
57
|
-
if (answer.status === 200)
|
|
58
|
-
return answer.text;
|
|
59
|
-
throw new Error(answer.status === 401 ? DISCONNECTED : (refusalOf(answer.text)?.text ?? `House answered ${answer.status}`));
|
|
60
|
-
}
|
|
61
|
-
async function mcp(method, params) {
|
|
62
|
-
const message = rpc(method, params);
|
|
63
|
-
const answer = JSON.parse(socketPath === undefined ? await direct(message) : await bridged('/', message));
|
|
64
|
-
if (answer.error !== undefined)
|
|
65
|
-
throw new Error(answer.error.message);
|
|
66
|
-
return answer.result;
|
|
67
|
-
}
|
|
68
|
-
async function tools() {
|
|
69
|
-
return (await mcp('tools/list', {})).tools;
|
|
70
|
-
}
|
|
71
|
-
async function localFile(path) {
|
|
72
|
-
try {
|
|
73
|
-
return await readFile(path);
|
|
74
|
-
}
|
|
75
|
-
catch (error) {
|
|
76
|
-
throw new Error(error.code === 'EISDIR'
|
|
77
|
-
? `${path} is a folder; upload one file at a time`
|
|
78
|
-
: `${path} is not a readable file`);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
async function upload(path, roomRef, missing) {
|
|
82
|
-
if (typeof path !== 'string' || path === '')
|
|
83
|
-
throw new Error(missing);
|
|
84
|
-
const bytes = await localFile(path);
|
|
85
|
-
const declared = JSON.parse(await bridged('/kit/attachments/upload', {
|
|
86
|
-
...(roomRef === undefined ? {} : { room_ref: roomRef }),
|
|
87
|
-
name: basename(path),
|
|
88
|
-
bytes: bytes.length,
|
|
89
|
-
sha256: createHash('sha256').update(bytes).digest('hex'),
|
|
90
|
-
}));
|
|
91
|
-
if (declared.upload === undefined)
|
|
92
|
-
return declared.attachment;
|
|
93
|
-
const saved = JSON.parse(await bridged(declared.upload.url, bytes, {
|
|
94
|
-
'content-type': 'application/octet-stream',
|
|
95
|
-
'x-house-byte-operation': declared.upload.operation,
|
|
96
|
-
}));
|
|
97
|
-
if (saved.upload_failure !== undefined)
|
|
98
|
-
throw new Error(`${path} was not saved: ${saved.upload_failure}; call again later`);
|
|
99
|
-
return saved.attachment;
|
|
100
|
-
}
|
|
101
|
-
async function push(args) {
|
|
102
|
-
if (args.includes('--help'))
|
|
103
|
-
return PUSH_USAGE;
|
|
104
|
-
const owner = args.includes('--owner');
|
|
105
|
-
const commit = args.find((arg) => arg !== '--owner') ?? 'HEAD';
|
|
106
|
-
if (owner && socketPath !== undefined)
|
|
107
|
-
throw new Error('--owner is not for Agent conversations; run house push without it');
|
|
108
|
-
if (!owner && socketPath === undefined)
|
|
109
|
-
throw new Error('outside an Agent conversation, house push needs --owner');
|
|
110
|
-
const pushed = JSON.parse(await bridged('/git/push', { cwd: process.cwd(), commit }, undefined, owner ? join(kitHome(), 'owner.sock') : socketPath));
|
|
111
|
-
if (pushed.refused)
|
|
112
|
-
throw new Error(pushed.text);
|
|
113
|
-
return pushed.text;
|
|
114
|
-
}
|
|
115
|
-
function argumentsOf(argument) {
|
|
116
|
-
if (argument === undefined)
|
|
117
|
-
return {};
|
|
118
|
-
let parsed;
|
|
119
|
-
try {
|
|
120
|
-
parsed = JSON.parse(argument);
|
|
121
|
-
}
|
|
122
|
-
catch {
|
|
123
|
-
throw new Error(ARGUMENTS);
|
|
124
|
-
}
|
|
125
|
-
if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed))
|
|
126
|
-
throw new Error(ARGUMENTS);
|
|
127
|
-
return parsed;
|
|
2
|
+
const [major = 0, minor = 0, patch = 0] = process.versions.node.split('.').map(Number);
|
|
3
|
+
if (major < 24 || (major === 24 && (minor < 22 || (minor === 22 && patch < 1)))) {
|
|
4
|
+
process.stderr.write(`house: the Kit needs Node 24.22.1 or newer; this is ${process.versions.node}\n`);
|
|
5
|
+
process.exitCode = 1;
|
|
128
6
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
return [USAGE, 'help', PUSH, ...(await tools()).map((tool) => (tool.description === undefined ? tool.name : `${tool.name}: ${tool.description}`))].join('\n');
|
|
132
|
-
}
|
|
133
|
-
if (argument === '--help') {
|
|
134
|
-
const tool = (await tools()).find((listed) => listed.name === verb);
|
|
135
|
-
if (tool === undefined)
|
|
136
|
-
throw new Error(`${verb} is no Tool; house find_command '{"query":"${verb}"}' finds Commands`);
|
|
137
|
-
return [...(tool.description === undefined ? [] : [tool.description]), JSON.stringify(tool.inputSchema)].join('\n');
|
|
138
|
-
}
|
|
139
|
-
const args = argumentsOf(argument);
|
|
140
|
-
if (socketPath !== undefined && verb === 'upload_attachment') {
|
|
141
|
-
return JSON.stringify({ attachment: await upload(args.path, args.room_ref, 'upload_attachment needs "path", a local file') });
|
|
142
|
-
}
|
|
143
|
-
if (socketPath !== undefined && verb === 'append_record' && Array.isArray(args.attachments)) {
|
|
144
|
-
const attachments = [];
|
|
145
|
-
for (const path of args.attachments) {
|
|
146
|
-
attachments.push(await upload(path, args.room_ref, 'each attachments entry is the path of a local file'));
|
|
147
|
-
}
|
|
148
|
-
args.attachments = attachments;
|
|
149
|
-
}
|
|
150
|
-
const result = await mcp('tools/call', { name: verb, arguments: args });
|
|
151
|
-
const text = result.content.map((content) => content.text).join('\n');
|
|
152
|
-
if (result.isError === true)
|
|
153
|
-
throw new Error(text.replace(/\n+$/, ''));
|
|
154
|
-
return text;
|
|
7
|
+
else {
|
|
8
|
+
await import('./house-cli.js');
|
|
155
9
|
}
|
|
156
|
-
|
|
157
|
-
(argv[0] === 'push' ? push(argv.slice(1)) : house(argv)).then((text) => {
|
|
158
|
-
process.stdout.write(`${text}\n`);
|
|
159
|
-
}, (error) => {
|
|
160
|
-
process.stderr.write(`house: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
161
|
-
process.exitCode = 1;
|
|
162
|
-
});
|
|
10
|
+
export {};
|
package/dist/instructions.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
const READ_LINE = 'Before working in a Room, read `/rooms/private/rooms/<handle>/AGENTS.md`.';
|
|
5
|
-
const COPIES_LINE = 'House Local copies; commit, then `house push`:';
|
|
1
|
+
import { agentInstructions } from '@agentshouse/skills';
|
|
2
|
+
import { HOUSE_REF } from './git.js';
|
|
3
|
+
const OWNER_RULES = '/rooms/private/owner-rules.md';
|
|
6
4
|
const UNREADABLE = /^(?:\S+: )?(?:path_not_found|room_not_found|operation_denied)\b/;
|
|
7
5
|
const FAILED = /^exit: [1-9]\d*$/;
|
|
8
6
|
const CUT = /^stderr: shell: output_cut (\d+) of \d+ bytes; continue with: (.+)$/;
|
|
@@ -10,9 +8,9 @@ function cutOf(lines) {
|
|
|
10
8
|
const cut = CUT.exec(lines[0] ?? '');
|
|
11
9
|
return cut !== null && Buffer.byteLength(lines.slice(1).join('\n')) === Number(cut[1]) ? cut : null;
|
|
12
10
|
}
|
|
13
|
-
async function
|
|
11
|
+
async function readOwnerRules(bridge) {
|
|
14
12
|
let document = '';
|
|
15
|
-
for (let command = `cat ${
|
|
13
|
+
for (let command = `cat ${OWNER_RULES}`; command !== undefined;) {
|
|
16
14
|
const read = await bridge.tool('shell', { command });
|
|
17
15
|
const text = read.content.map((content) => content.text).join('\n');
|
|
18
16
|
const lines = text.split('\n');
|
|
@@ -26,9 +24,9 @@ async function howWeWork(bridge) {
|
|
|
26
24
|
document += lines.slice(cut === null ? 0 : 1).join('\n');
|
|
27
25
|
command = cut?.[2];
|
|
28
26
|
}
|
|
29
|
-
return document
|
|
27
|
+
return document;
|
|
30
28
|
}
|
|
31
29
|
export async function instructions(bridge, base, copies) {
|
|
32
|
-
const lines =
|
|
33
|
-
return [lines.join('\n'), base, await
|
|
30
|
+
const lines = agentInstructions(HOUSE_REF, copies);
|
|
31
|
+
return [lines.join('\n'), base, (await readOwnerRules(bridge)).replace(/\n$/, '')].filter((part) => part !== '').join('\n\n');
|
|
34
32
|
}
|
package/dist/kit-cli.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { parseArgs } from 'node:util';
|
|
2
|
+
import { answerGitCredential } from './app-git.js';
|
|
3
|
+
import { chatgpt } from './chatgpt.js';
|
|
4
|
+
import { login } from './login.js';
|
|
5
|
+
import { logout } from './logout.js';
|
|
6
|
+
import { proxyUnlessRelayed } from './relay.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
|
+
proxyUnlessRelayed();
|
|
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,21 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import { resident } from './resident.js';
|
|
6
|
-
const [command, ...argv] = process.argv.slice(2);
|
|
7
|
-
setGlobalProxyFromEnv();
|
|
8
|
-
async function run() {
|
|
9
|
-
if (command === 'login')
|
|
10
|
-
return login(argv);
|
|
11
|
-
if (command === 'logout')
|
|
12
|
-
return logout();
|
|
13
|
-
if (command === 'resident')
|
|
14
|
-
return resident();
|
|
15
|
-
process.stderr.write('usage: kit <login|logout|resident>\n');
|
|
16
|
-
process.exitCode = 2;
|
|
17
|
-
}
|
|
18
|
-
run().catch((error) => {
|
|
19
|
-
process.stderr.write(`kit: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
2
|
+
const [major = 0, minor = 0, patch = 0] = process.versions.node.split('.').map(Number);
|
|
3
|
+
if (major < 24 || (major === 24 && (minor < 22 || (minor === 22 && patch < 1)))) {
|
|
4
|
+
process.stderr.write(`kit: the Kit needs Node 24.22.1 or newer; this is ${process.versions.node}\n`);
|
|
20
5
|
process.exitCode = 1;
|
|
21
|
-
}
|
|
6
|
+
}
|
|
7
|
+
else {
|
|
8
|
+
await import('./kit-cli.js');
|
|
9
|
+
}
|
|
10
|
+
export {};
|
package/dist/login.js
CHANGED
|
@@ -1,73 +1,58 @@
|
|
|
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 {
|
|
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
8
|
import { callHouse, rpc } from './mcp.js';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
held = response;
|
|
24
|
-
deliver(received);
|
|
25
|
-
});
|
|
26
|
-
const close = () => {
|
|
27
|
-
server.close();
|
|
28
|
-
server.closeAllConnections();
|
|
29
|
-
};
|
|
30
|
-
const port = Number(process.env.HOUSE_KIT_LOGIN_PORT ?? 0);
|
|
31
|
-
server.once('error', reject);
|
|
32
|
-
server.listen(port, port === 0 ? '127.0.0.1' : '0.0.0.0', () => {
|
|
33
|
-
const address = server.address();
|
|
34
|
-
if (address === null || typeof address === 'string') {
|
|
35
|
-
reject(new Error('the login callback has no port'));
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
resolve({
|
|
39
|
-
uri: `http://127.0.0.1:${address.port}/callback`,
|
|
40
|
-
code,
|
|
41
|
-
answer: (text) => new Promise((written) => {
|
|
42
|
-
if (held === null || held.destroyed || !held.socket || held.socket.destroyed)
|
|
43
|
-
return written();
|
|
44
|
-
held.once('close', () => written());
|
|
45
|
-
held.writeHead(200, { 'content-type': 'text/plain; charset=utf-8', connection: 'close' }).end(`${text}\n`);
|
|
46
|
-
}),
|
|
47
|
-
close,
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
});
|
|
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
|
+
import { endUnserved } from './wire.js';
|
|
14
|
+
export const DEFAULT_HOUSE = 'https://agents.house';
|
|
15
|
+
const OPENER = process.platform === 'darwin' ? 'open' : 'xdg-open';
|
|
16
|
+
// Polling every two seconds brings the User's confirmation to the waiting Kit moments after they give it.
|
|
17
|
+
const POLL_INTERVAL_MS = 2000;
|
|
18
|
+
function open(link) {
|
|
19
|
+
spawn(OPENER, [link], { detached: true, stdio: 'ignore' })
|
|
20
|
+
.on('error', () => undefined)
|
|
21
|
+
.unref();
|
|
51
22
|
}
|
|
52
|
-
async function accepted(house, credential) {
|
|
23
|
+
export async function accepted(house, credential) {
|
|
53
24
|
const checked = await callHouse(house, credential, rpc('tools/list', {}));
|
|
54
25
|
if (checked.status === 200)
|
|
55
26
|
return true;
|
|
56
27
|
if (checked.status === 401)
|
|
57
28
|
return false;
|
|
29
|
+
endUnserved(checked.text);
|
|
58
30
|
throw new Error(`House answered ${checked.status} when Kit checked this computer's own agent's connection: ${checked.text}`);
|
|
59
31
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
32
|
+
const USAGE = `usage: kit login [--house <origin>] [--environment <id>] [--rooms <ref>[,<ref>...] | --no-private]
|
|
33
|
+
kit login [--house <origin>] --code <code>
|
|
34
|
+
--house <origin> the House to connect to, ${DEFAULT_HOUSE} unless one is stored
|
|
35
|
+
--environment <id> reconnect this Environment
|
|
36
|
+
--rooms <ref>[,<ref>...] give this Environment only these Rooms
|
|
37
|
+
--no-private give this Environment every Room but your Private Room
|
|
38
|
+
--code <code> connect this machine with a login code
|
|
39
|
+
`;
|
|
40
|
+
function connected(house, named, environment) {
|
|
41
|
+
if (named === undefined)
|
|
42
|
+
return `Environment ${environment} is connected to ${house}.\n`;
|
|
43
|
+
if (named === environment)
|
|
44
|
+
return `Environment ${environment} is reconnected to ${house}.\n`;
|
|
45
|
+
return `Environment ${named} stays with its account; this computer is connected to ${house} as new Environment ${environment} of the account that confirmed.\n`;
|
|
46
|
+
}
|
|
47
|
+
function gone(error) {
|
|
48
|
+
return error instanceof HouseRefusal && refusalOf(error.text)?.code === 'kit_environment_not_found';
|
|
49
|
+
}
|
|
50
|
+
function chosenRooms(rooms, noPrivate) {
|
|
51
|
+
if (rooms !== undefined && noPrivate)
|
|
52
|
+
throw new Error('--rooms and --no-private are two choices of Rooms; pass one');
|
|
53
|
+
if (rooms !== undefined)
|
|
54
|
+
return { rooms: { reach: 'selected', refs: rooms.split(',') } };
|
|
55
|
+
return noPrivate ? { rooms: { reach: 'all_but_private' } } : {};
|
|
71
56
|
}
|
|
72
57
|
export async function login(argv) {
|
|
73
58
|
const { values } = parseArgs({
|
|
@@ -75,62 +60,92 @@ export async function login(argv) {
|
|
|
75
60
|
options: {
|
|
76
61
|
house: { type: 'string' },
|
|
77
62
|
environment: { type: 'string' },
|
|
78
|
-
|
|
63
|
+
rooms: { type: 'string' },
|
|
64
|
+
'no-private': { type: 'boolean', default: false },
|
|
65
|
+
code: { type: 'string' },
|
|
66
|
+
help: { type: 'boolean', default: false },
|
|
79
67
|
},
|
|
80
68
|
});
|
|
69
|
+
if (values.help) {
|
|
70
|
+
process.stdout.write(USAGE);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (values.code !== undefined && values.rooms !== undefined)
|
|
74
|
+
throw new Error('--code cannot be used with --rooms');
|
|
75
|
+
if (values.code !== undefined && values['no-private'])
|
|
76
|
+
throw new Error('--code cannot be used with --no-private');
|
|
77
|
+
if (values.code !== undefined && values.environment !== undefined)
|
|
78
|
+
throw new Error('--code cannot be used with --environment');
|
|
79
|
+
const rooms = chosenRooms(values.rooms, values['no-private']);
|
|
81
80
|
const enrolled = (await readEnrolment()) ?? (await readDisconnected());
|
|
81
|
+
if (values.code !== undefined && enrolled !== null) {
|
|
82
|
+
throw new Error(`--code connects a new machine; this Kit home records Environment ${enrolled.environment}, so run kit login to reconnect it`);
|
|
83
|
+
}
|
|
84
|
+
const relay = process.env.HOUSE_KIT_RELAY || undefined;
|
|
85
|
+
selectRelay(relay);
|
|
82
86
|
const house = values.house ?? enrolled?.house ?? DEFAULT_HOUSE;
|
|
83
87
|
const replaces = process.env.HOUSE_KIT_REPLACES;
|
|
84
|
-
const
|
|
88
|
+
const remembered = replaces === undefined && values.environment === undefined && enrolled?.house === house ? enrolled.environment : undefined;
|
|
89
|
+
const environment = replaces === undefined ? (values.environment ?? remembered) : undefined;
|
|
85
90
|
const ownAgent = await readOwnAgent();
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
: { act: 'existing_environment', environment_id: environment }),
|
|
92
|
-
code_challenge: createHash('sha256').update(verifier).digest('base64url'),
|
|
93
|
-
...(held ? {} : { headless: true }),
|
|
94
|
-
};
|
|
95
|
-
const exchange = async (code) => {
|
|
96
|
-
const exchanged = await post(house, '/kit/token', { code, code_verifier: verifier });
|
|
97
|
-
await writeEnrolment({ house, environment: exchanged.environment, credential: exchanged.credential });
|
|
98
|
-
process.stdout.write(`Environment ${exchanged.environment} is connected to ${house}.\n`);
|
|
99
|
-
if (exchanged.headless_credential !== undefined) {
|
|
100
|
-
await writeOwnAgent({ house, user: exchanged.user, credential: exchanged.headless_credential });
|
|
101
|
-
}
|
|
102
|
-
else if (held && ownAgent.user !== exchanged.user) {
|
|
103
|
-
await forgetOwnAgent();
|
|
104
|
-
process.stdout.write("This computer's own agent was another User's; run kit login again to connect it to you.\n");
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
if (values.manual) {
|
|
108
|
-
const { start_url } = await post(house, '/kit', {
|
|
109
|
-
...started,
|
|
110
|
-
presentation: 'manual',
|
|
111
|
-
});
|
|
112
|
-
process.stdout.write(`Open this link and confirm: ${start_url}\n`);
|
|
113
|
-
await exchange(await typed('Code: '));
|
|
114
|
-
return;
|
|
91
|
+
let held = false;
|
|
92
|
+
let named = environment;
|
|
93
|
+
let exchanged;
|
|
94
|
+
if (values.code !== undefined) {
|
|
95
|
+
exchanged = await post(house, '/kit/token', { code: values.code });
|
|
115
96
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
97
|
+
else {
|
|
98
|
+
held = ownAgent !== null && ownAgent.house === house && (await accepted(house, ownAgent.credential));
|
|
99
|
+
const verifier = randomBytes(32).toString('base64url');
|
|
100
|
+
const start = () => retrying(() => post(house, '/kit', {
|
|
101
|
+
...(named === undefined
|
|
102
|
+
? { act: 'new_environment', ...(replaces === undefined ? {} : { replaces }) }
|
|
103
|
+
: { act: 'existing_environment', environment_id: named }),
|
|
104
|
+
...rooms,
|
|
105
|
+
code_challenge: createHash('sha256').update(verifier).digest('base64url'),
|
|
106
|
+
...(held ? {} : { headless: true }),
|
|
107
|
+
}));
|
|
108
|
+
let started;
|
|
124
109
|
try {
|
|
125
|
-
await
|
|
110
|
+
started = await start();
|
|
126
111
|
}
|
|
127
112
|
catch (error) {
|
|
128
|
-
|
|
129
|
-
|
|
113
|
+
if (remembered === undefined || !gone(error))
|
|
114
|
+
throw error;
|
|
115
|
+
await forgetDisconnected();
|
|
116
|
+
process.stdout.write(`House no longer holds Environment ${remembered}; connecting this computer as a new one.\n`);
|
|
117
|
+
named = undefined;
|
|
118
|
+
started = await start();
|
|
130
119
|
}
|
|
131
|
-
|
|
120
|
+
process.stdout.write(`Open this link and confirm: ${started.start_url}\n`);
|
|
121
|
+
open(started.start_url);
|
|
122
|
+
exchanged = await retrying(() => post(house, '/kit/token', { login: started.login, code_verifier: verifier }), undefined, () => POLL_INTERVAL_MS);
|
|
123
|
+
}
|
|
124
|
+
await placeSkillSet(house);
|
|
125
|
+
await writeCodexRule().catch((error) => process.stderr.write(`kit: ${error.message}\n`));
|
|
126
|
+
const relayRecord = relay === undefined ? {} : { relay };
|
|
127
|
+
await writeEnrolment({
|
|
128
|
+
house,
|
|
129
|
+
...relayRecord,
|
|
130
|
+
environment: exchanged.environment,
|
|
131
|
+
credential: exchanged.credential,
|
|
132
|
+
});
|
|
133
|
+
process.stdout.write(connected(house, named, exchanged.environment));
|
|
134
|
+
if (exchanged.headless_credential !== undefined) {
|
|
135
|
+
await writeOwnAgent({ house, ...relayRecord, user: exchanged.user, credential: exchanged.headless_credential });
|
|
136
|
+
}
|
|
137
|
+
else if (held && ownAgent !== null && ownAgent.user !== exchanged.user) {
|
|
138
|
+
await forgetOwnAgent();
|
|
139
|
+
process.stdout.write("This computer's own agent was another User's; run kit login again to connect it to you.\n");
|
|
140
|
+
}
|
|
141
|
+
else if (held && ownAgent !== null) {
|
|
142
|
+
await writeOwnAgent({ house, ...relayRecord, user: ownAgent.user, credential: ownAgent.credential });
|
|
143
|
+
}
|
|
144
|
+
await placeAppGit(await readOwnAgent()).catch((error) => process.stderr.write(`kit: ${error.message}\n`));
|
|
145
|
+
try {
|
|
146
|
+
startService();
|
|
132
147
|
}
|
|
133
|
-
|
|
134
|
-
|
|
148
|
+
catch (error) {
|
|
149
|
+
process.stderr.write(`kit: ${error.message}\n`);
|
|
135
150
|
}
|
|
136
151
|
}
|
package/dist/logout.js
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import { HouseRefusal, post } from './api.js';
|
|
2
|
-
import { forgetEnrolment, readEnrolment } from './home.js';
|
|
2
|
+
import { forgetEnrolment, forgetOwnAgent, readEnrolment } from './home.js';
|
|
3
3
|
export async function logout() {
|
|
4
4
|
const enrolled = await readEnrolment();
|
|
5
|
-
if (enrolled
|
|
6
|
-
|
|
7
|
-
|
|
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);
|
|
8
14
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
if (!(error instanceof HouseRefusal && error.status === 401))
|
|
14
|
-
throw error;
|
|
15
|
-
}
|
|
16
|
-
await forgetEnrolment(enrolled);
|
|
17
|
-
process.stdout.write(`Environment ${enrolled.environment} is disconnected; kit login reconnects it.\n`);
|
|
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`);
|
|
18
19
|
}
|
package/dist/mcp.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
|
-
import {
|
|
2
|
+
import { KIT_RELEASE } from './clis.js';
|
|
3
3
|
import { relayed } from './relay.js';
|
|
4
|
+
import { KIT_WIRE, KIT_WIRE_HEADER } from './wire.js';
|
|
4
5
|
const MCP_PROTOCOL_VERSION = '2026-07-28';
|
|
5
6
|
export const UNREACHABLE = 'House is unreachable; call again in a minute';
|
|
7
|
+
export class Unsettled extends Error {
|
|
8
|
+
}
|
|
6
9
|
export function rpc(method, params) {
|
|
7
10
|
return { jsonrpc: '2.0', id: randomUUID(), method, params };
|
|
8
11
|
}
|
|
@@ -13,7 +16,7 @@ export function mcpBody(message, operation) {
|
|
|
13
16
|
...message.params,
|
|
14
17
|
_meta: {
|
|
15
18
|
'io.modelcontextprotocol/protocolVersion': MCP_PROTOCOL_VERSION,
|
|
16
|
-
'io.modelcontextprotocol/clientInfo': { name: '@agentshouse/kit', version:
|
|
19
|
+
'io.modelcontextprotocol/clientInfo': { name: '@agentshouse/kit', version: KIT_RELEASE },
|
|
17
20
|
'io.modelcontextprotocol/clientCapabilities': {},
|
|
18
21
|
...(operation === null ? {} : { 'agents.house/agent-operation': operation }),
|
|
19
22
|
},
|
|
@@ -31,6 +34,7 @@ export async function callHouse(origin, credential, message, operation = null, s
|
|
|
31
34
|
'mcp-protocol-version': MCP_PROTOCOL_VERSION,
|
|
32
35
|
'mcp-method': message.method,
|
|
33
36
|
...(tool === null ? {} : { 'mcp-name': tool }),
|
|
37
|
+
[KIT_WIRE_HEADER]: String(KIT_WIRE),
|
|
34
38
|
},
|
|
35
39
|
body: mcpBody(message, operation),
|
|
36
40
|
signal,
|