@agentshouse/kit 0.2.1-cbabe8ad337ff → 0.2.1-cc6246211e00c

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.
Files changed (130) hide show
  1. package/README.md +42 -41
  2. package/dist/acp.js +38 -17
  3. package/dist/agents.js +111 -24
  4. package/dist/api.js +7 -3
  5. package/dist/app-git.js +10 -26
  6. package/dist/authority-main.js +2 -2
  7. package/dist/bridge.js +11 -25
  8. package/dist/building.js +46 -0
  9. package/dist/calls.js +63 -0
  10. package/dist/chatgpt.js +32 -0
  11. package/dist/clis-main.js +2 -2
  12. package/dist/clis.js +87 -22
  13. package/dist/connection.js +126 -0
  14. package/dist/conversations.js +410 -156
  15. package/dist/copies.js +185 -123
  16. package/dist/end.js +23 -4
  17. package/dist/enrol-main.js +7 -1
  18. package/dist/events.js +6 -2
  19. package/dist/files.js +139 -31
  20. package/dist/git.js +13 -11
  21. package/dist/home.js +96 -7
  22. package/dist/house-cli.js +299 -0
  23. package/dist/house-main.js +7 -177
  24. package/dist/instructions.js +8 -10
  25. package/dist/kit-cli.js +68 -0
  26. package/dist/kit-main.js +8 -22
  27. package/dist/login.js +111 -23
  28. package/dist/logout.js +0 -2
  29. package/dist/mcp.js +4 -2
  30. package/dist/parts.js +34 -16
  31. package/dist/placement.js +39 -0
  32. package/dist/relay.js +33 -2
  33. package/dist/resident.js +106 -44
  34. package/dist/scope.js +3 -0
  35. package/dist/service-main.js +9 -0
  36. package/dist/service.js +55 -0
  37. package/dist/sign-in.js +22 -39
  38. package/dist/skills.js +49 -35
  39. package/dist/transcription.js +85 -45
  40. package/dist/translate.js +2 -8
  41. package/dist/update.js +98 -53
  42. package/dist/web-wizard.js +101 -0
  43. package/dist/wire.js +22 -0
  44. package/dist/work.js +3 -5
  45. package/package.json +20 -20
  46. package/dist/bootstrap.json +0 -24
  47. package/dist/stream.js +0 -72
  48. package/how-we-work.md +0 -23
  49. package/skills/ask-matt/LICENSE +0 -21
  50. package/skills/ask-matt/PHASE-BOUNDARIES.md +0 -55
  51. package/skills/ask-matt/SKILL.md +0 -91
  52. package/skills/ask-matt/agents/openai.yaml +0 -4
  53. package/skills/code-review/LICENSE +0 -21
  54. package/skills/code-review/SKILL.md +0 -89
  55. package/skills/code-review/agents/openai.yaml +0 -3
  56. package/skills/codebase-design/DEEPENING.md +0 -37
  57. package/skills/codebase-design/DESIGN-IT-TWICE.md +0 -44
  58. package/skills/codebase-design/LICENSE +0 -21
  59. package/skills/codebase-design/SKILL.md +0 -116
  60. package/skills/codebase-design/agents/openai.yaml +0 -3
  61. package/skills/diagnosing-bugs/LICENSE +0 -21
  62. package/skills/diagnosing-bugs/SKILL.md +0 -140
  63. package/skills/diagnosing-bugs/agents/openai.yaml +0 -3
  64. package/skills/diagnosing-bugs/scripts/hitl-loop.template.sh +0 -44
  65. package/skills/domain-modeling/ADR-FORMAT.md +0 -47
  66. package/skills/domain-modeling/CONTEXT-FORMAT.md +0 -60
  67. package/skills/domain-modeling/LICENSE +0 -21
  68. package/skills/domain-modeling/SKILL.md +0 -76
  69. package/skills/domain-modeling/agents/openai.yaml +0 -3
  70. package/skills/grill-me/LICENSE +0 -21
  71. package/skills/grill-me/SKILL.md +0 -8
  72. package/skills/grill-me/agents/openai.yaml +0 -4
  73. package/skills/grill-with-docs/LICENSE +0 -21
  74. package/skills/grill-with-docs/SKILL.md +0 -8
  75. package/skills/grill-with-docs/agents/openai.yaml +0 -4
  76. package/skills/grilling/LICENSE +0 -21
  77. package/skills/grilling/SKILL.md +0 -30
  78. package/skills/grilling/agents/openai.yaml +0 -3
  79. package/skills/handoff/LICENSE +0 -21
  80. package/skills/handoff/SKILL.md +0 -17
  81. package/skills/handoff/agents/openai.yaml +0 -4
  82. package/skills/implement/LICENSE +0 -21
  83. package/skills/implement/SKILL.md +0 -16
  84. package/skills/implement/agents/openai.yaml +0 -4
  85. package/skills/improve-codebase-architecture/HTML-REPORT.md +0 -123
  86. package/skills/improve-codebase-architecture/LICENSE +0 -21
  87. package/skills/improve-codebase-architecture/SKILL.md +0 -72
  88. package/skills/improve-codebase-architecture/agents/openai.yaml +0 -4
  89. package/skills/prototype/LICENSE +0 -21
  90. package/skills/prototype/LOGIC.md +0 -67
  91. package/skills/prototype/SKILL.md +0 -28
  92. package/skills/prototype/UI.md +0 -112
  93. package/skills/prototype/agents/openai.yaml +0 -3
  94. package/skills/research/LICENSE +0 -21
  95. package/skills/research/SKILL.md +0 -14
  96. package/skills/research/agents/openai.yaml +0 -3
  97. package/skills/resolving-merge-conflicts/LICENSE +0 -21
  98. package/skills/resolving-merge-conflicts/SKILL.md +0 -16
  99. package/skills/resolving-merge-conflicts/agents/openai.yaml +0 -3
  100. package/skills/tdd/LICENSE +0 -21
  101. package/skills/tdd/SKILL.md +0 -40
  102. package/skills/tdd/agents/openai.yaml +0 -3
  103. package/skills/tdd/mocking.md +0 -59
  104. package/skills/tdd/tests.md +0 -77
  105. package/skills/teach/GLOSSARY-FORMAT.md +0 -35
  106. package/skills/teach/LEARNING-RECORD-FORMAT.md +0 -46
  107. package/skills/teach/LICENSE +0 -21
  108. package/skills/teach/MISSION-FORMAT.md +0 -31
  109. package/skills/teach/RESOURCES-FORMAT.md +0 -32
  110. package/skills/teach/SKILL.md +0 -141
  111. package/skills/teach/agents/openai.yaml +0 -4
  112. package/skills/to-questionnaire/LICENSE +0 -21
  113. package/skills/to-questionnaire/SKILL.md +0 -55
  114. package/skills/to-questionnaire/agents/openai.yaml +0 -4
  115. package/skills/to-spec/LICENSE +0 -21
  116. package/skills/to-spec/SKILL.md +0 -76
  117. package/skills/to-spec/agents/openai.yaml +0 -4
  118. package/skills/to-tickets/LICENSE +0 -21
  119. package/skills/to-tickets/SKILL.md +0 -106
  120. package/skills/to-tickets/agents/openai.yaml +0 -4
  121. package/skills/wait-what/LICENSE +0 -21
  122. package/skills/wait-what/SKILL.md +0 -8
  123. package/skills/wait-what/agents/openai.yaml +0 -4
  124. package/skills/wayfinder/LICENSE +0 -21
  125. package/skills/wayfinder/SKILL.md +0 -129
  126. package/skills/wayfinder/agents/openai.yaml +0 -4
  127. package/skills/writing-for-agents/LICENSE +0 -21
  128. package/skills/writing-for-agents/SKILL-MECHANICS.md +0 -22
  129. package/skills/writing-for-agents/SKILL.md +0 -83
  130. package/skills/writing-for-agents/agents/openai.yaml +0 -3
@@ -1,180 +1,10 @@
1
1
  #!/usr/bin/env node
2
- import { createHash } from 'node:crypto';
3
- import { readFile } from 'node:fs/promises';
4
- import { request, setGlobalProxyFromEnv } from 'node:http';
5
- import { basename, join } from 'node:path';
6
- import { kitHome, readOwnAgent } from './home.js';
7
- import { callHouse, rpc, UNREACHABLE } from './mcp.js';
8
- import { refusalOf } from './refusals.js';
9
- import { relayed } from './relay.js';
10
- import { parse } from 'yaml';
11
- const USAGE = "usage: house <tool> ['<arguments as JSON>']";
12
- const PUSH_USAGE = 'usage: house push [commit] [--owner]';
13
- const PUSH = "push [commit]: sends the Local copy's committed changes to House";
14
- const ARGUMENTS = `the arguments are one JSON object in single quotes, like house search '{"query":"invoice"}'`;
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 directly, not through another program";
17
- const REVOKED = 'this conversation no longer has House access; nothing to do from here';
18
- const UNCONNECTED = "this computer's own agent has no House connection; run kit login";
19
- const DISCONNECTED = "House no longer accepts this computer's own agent; run kit login";
20
- const socketPath = process.env.HOUSE_BRIDGE;
21
- function refused(path, status, text) {
22
- const refusal = refusalOf(text);
23
- if (refusal !== null)
24
- return refusal.text;
25
- if (status === 401)
26
- return REVOKED;
27
- if (URL.canParse(path))
28
- return `the upload answered ${status}; upload the file again`;
29
- if (status === 502 && /^[A-Za-z]/.test(text))
30
- return text;
31
- return `${path} answered ${status}`;
32
- }
33
- function bridged(path, body, headers = { 'content-type': 'application/json' }, to = socketPath) {
34
- return new Promise((resolve, reject) => {
35
- const sent = request({ socketPath: to, path, method: 'POST', headers }, (answer) => {
36
- let text = '';
37
- answer.setEncoding('utf8');
38
- answer.on('data', (chunk) => {
39
- text += chunk;
40
- });
41
- answer.on('end', () => {
42
- if (answer.statusCode === 200)
43
- resolve(text);
44
- else
45
- reject(new Error(refused(path, answer.statusCode, text)));
46
- });
47
- });
48
- sent.on('error', (error) => reject(new Error(error.code === 'EPERM' || error.code === 'EACCES' ? SANDBOXED : CLOSED)));
49
- sent.end(body instanceof Buffer ? body : JSON.stringify(body));
50
- });
51
- }
52
- async function direct(message) {
53
- const ownAgent = await readOwnAgent();
54
- if (ownAgent === null)
55
- throw new Error(UNCONNECTED);
56
- setGlobalProxyFromEnv();
57
- const answer = await callHouse(ownAgent.house, ownAgent.credential, message).catch(() => {
58
- throw new Error(UNREACHABLE);
59
- });
60
- if (answer.status === 200)
61
- return answer.text;
62
- throw new Error(answer.status === 401 ? DISCONNECTED : (refusalOf(answer.text)?.text ?? `House answered ${answer.status}`));
63
- }
64
- async function mcp(method, params) {
65
- const message = rpc(method, params);
66
- const answer = JSON.parse(socketPath === undefined ? await direct(message) : await bridged('/', message));
67
- if (answer.error !== undefined)
68
- throw new Error(answer.error.message);
69
- return answer.result;
70
- }
71
- async function tools() {
72
- return (await mcp('tools/list', {})).tools;
73
- }
74
- async function localFile(path) {
75
- try {
76
- return await readFile(path);
77
- }
78
- catch (error) {
79
- throw new Error(error.code === 'EISDIR'
80
- ? `${path} is a folder; upload one file at a time`
81
- : `${path} is not a readable file`);
82
- }
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
- }
97
- async function upload(path, roomRef, missing) {
98
- if (typeof path !== 'string' || path === '')
99
- throw new Error(missing);
100
- const bytes = await localFile(path);
101
- const declared = parse(await called('upload', {
102
- ...(roomRef === undefined ? {} : { room_ref: roomRef }),
103
- name: basename(path),
104
- bytes: bytes.length,
105
- sha256: createHash('sha256').update(bytes).digest('hex'),
106
- }));
107
- if (declared.upload === undefined)
108
- return declared.attachment;
109
- const saved = JSON.parse(await sent(declared.upload.url, bytes, declared.upload.operation));
110
- if (saved.upload_failure !== undefined)
111
- throw new Error(`${path} was not saved: ${saved.upload_failure}; call again later`);
112
- return saved.attachment;
113
- }
114
- async function push(args) {
115
- if (args.includes('--help'))
116
- return PUSH_USAGE;
117
- const owner = args.includes('--owner');
118
- const commit = args.find((arg) => arg !== '--owner') ?? 'HEAD';
119
- if (owner && socketPath !== undefined)
120
- throw new Error('--owner is not for Agent conversations; run house push without it');
121
- if (!owner && socketPath === undefined)
122
- throw new Error('outside an Agent conversation, house push needs --owner');
123
- const pushed = JSON.parse(await bridged('/git/push', { cwd: process.cwd(), commit }, undefined, owner ? join(kitHome(), 'owner.sock') : socketPath));
124
- if (pushed.refused)
125
- throw new Error(pushed.text);
126
- return pushed.text;
127
- }
128
- function argumentsOf(argument) {
129
- if (argument === undefined)
130
- return {};
131
- let parsed;
132
- try {
133
- parsed = JSON.parse(argument);
134
- }
135
- catch {
136
- throw new Error(ARGUMENTS);
137
- }
138
- if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed))
139
- throw new Error(ARGUMENTS);
140
- return parsed;
141
- }
142
- async function house([verb, argument]) {
143
- if (verb === undefined || verb === '--help' || verb === 'help') {
144
- return [USAGE, 'help', PUSH, ...(await tools()).map((tool) => (tool.description === undefined ? tool.name : `${tool.name}: ${tool.description}`))].join('\n');
145
- }
146
- if (argument === '--help') {
147
- const tool = (await tools()).find((listed) => listed.name === verb);
148
- if (tool === undefined)
149
- throw new Error(`${verb} is no Tool; house find_command '{"query":"${verb}"}' finds Commands`);
150
- return [...(tool.description === undefined ? [] : [tool.description]), JSON.stringify(tool.inputSchema)].join('\n');
151
- }
152
- const args = argumentsOf(argument);
153
- if (verb === 'upload') {
154
- return JSON.stringify({ attachment: await upload(args.path, args.room_ref, 'upload needs "path", a local file') });
155
- }
156
- if (verb === 'append_record' && Array.isArray(args.attachments)) {
157
- const attachments = [];
158
- for (const path of args.attachments) {
159
- attachments.push(await upload(path, args.room_ref, 'each attachments entry is the path of a local file'));
160
- }
161
- args.attachments = attachments;
162
- }
163
- return called(verb, args);
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;
164
6
  }
165
- async function called(name, args) {
166
- const result = await mcp('tools/call', { name, arguments: args });
167
- const text = result.content.map((content) => content.text).join('\n');
168
- if (result.isError === true)
169
- throw new Error(text.replace(/\n+$/, ''));
170
- return text;
7
+ else {
8
+ await import('./house-cli.js');
171
9
  }
172
- const argv = process.argv.slice(2);
173
- (argv[0] === 'push' ? push(argv.slice(1)) : house(argv)).then((text) => {
174
- process.stdout.write(`${text}\n`);
175
- if (argv[0] === 'shell')
176
- process.exitCode = Number(/^exit: (\d+)(?:\n|$)/.exec(text)?.[1] ?? 0);
177
- }, (error) => {
178
- process.stderr.write(`house: ${error instanceof Error ? error.message : String(error)}\n`);
179
- process.exitCode = 1;
180
- });
10
+ export {};
@@ -1,8 +1,6 @@
1
- import { HOW_WE_WORK } from './skills.js';
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 upload` and link it; never start a server.';
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 howWeWork(bridge) {
11
+ async function readOwnerRules(bridge) {
14
12
  let document = '';
15
- for (let command = `cat ${HOW_WE_WORK}`; command !== undefined;) {
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.replace(/\n$/, '');
27
+ return document;
30
28
  }
31
29
  export async function instructions(bridge, base, copies) {
32
- const lines = [HOUSE_LINE, FILE_LINE, READ_LINE, ...(copies.length === 0 ? [] : [COPIES_LINE, ...copies])];
33
- 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 readOwnerRules(bridge)).replace(/\n$/, '')].filter((part) => part !== '').join('\n\n');
34
32
  }
@@ -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,24 +1,10 @@
1
1
  #!/usr/bin/env node
2
- import { setGlobalProxyFromEnv } from 'node:http';
3
- import { answerGitCredential } from './app-git.js';
4
- import { login } from './login.js';
5
- import { logout } from './logout.js';
6
- import { resident } from './resident.js';
7
- const [command, ...argv] = process.argv.slice(2);
8
- setGlobalProxyFromEnv();
9
- async function run() {
10
- if (command === 'login')
11
- return login(argv);
12
- if (command === 'logout')
13
- return logout();
14
- if (command === 'resident')
15
- return resident();
16
- if (command === 'git-credential')
17
- return answerGitCredential(argv[0]);
18
- process.stderr.write('usage: kit <login|logout|resident>\n');
19
- process.exitCode = 2;
20
- }
21
- run().catch((error) => {
22
- 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`);
23
5
  process.exitCode = 1;
24
- });
6
+ }
7
+ else {
8
+ await import('./kit-cli.js');
9
+ }
10
+ export {};
package/dist/login.js CHANGED
@@ -1,12 +1,16 @@
1
1
  import { spawn } from 'node:child_process';
2
2
  import { createHash, randomBytes } from 'node:crypto';
3
- import { hostname } from 'node:os';
4
3
  import { parseArgs } from 'node:util';
5
- import { post, retrying } from './api.js';
4
+ import { HouseRefusal, post, retrying } from './api.js';
6
5
  import { placeAppGit } from './app-git.js';
7
- import { forgetOwnAgent, readDisconnected, readEnrolment, readOwnAgent, writeEnrolment, writeOwnAgent } from './home.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
- const DEFAULT_HOUSE = 'https://agents.house';
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';
10
14
  const OPENER = process.platform === 'darwin' ? 'open' : 'xdg-open';
11
15
  // Polling every two seconds brings the User's confirmation to the waiting Kit moments after they give it.
12
16
  const POLL_INTERVAL_MS = 2000;
@@ -15,7 +19,7 @@ function open(link) {
15
19
  .on('error', () => undefined)
16
20
  .unref();
17
21
  }
18
- async function accepted(house, credential) {
22
+ export async function accepted(house, credential) {
19
23
  const checked = await callHouse(house, credential, rpc('tools/list', {}));
20
24
  if (checked.status === 200)
21
25
  return true;
@@ -23,39 +27,123 @@ async function accepted(house, credential) {
23
27
  return false;
24
28
  throw new Error(`House answered ${checked.status} when Kit checked this computer's own agent's connection: ${checked.text}`);
25
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' } } : {};
54
+ }
26
55
  export async function login(argv) {
27
56
  const { values } = parseArgs({
28
57
  args: argv,
29
58
  options: {
30
59
  house: { type: 'string' },
31
60
  environment: { type: 'string' },
61
+ rooms: { type: 'string' },
62
+ 'no-private': { type: 'boolean', default: false },
63
+ code: { type: 'string' },
64
+ help: { type: 'boolean', default: false },
32
65
  },
33
66
  });
67
+ if (values.help) {
68
+ process.stdout.write(USAGE);
69
+ return;
70
+ }
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']);
34
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);
35
84
  const house = values.house ?? enrolled?.house ?? DEFAULT_HOUSE;
36
85
  const replaces = process.env.HOUSE_KIT_REPLACES;
37
- const environment = replaces === undefined ? (values.environment ?? (enrolled?.house === house ? enrolled.environment : undefined)) : undefined;
86
+ const remembered = replaces === undefined && values.environment === undefined && enrolled?.house === house ? enrolled.environment : undefined;
87
+ const environment = replaces === undefined ? (values.environment ?? remembered) : undefined;
38
88
  const ownAgent = await readOwnAgent();
39
- const held = ownAgent !== null && ownAgent.house === house && (await accepted(house, ownAgent.credential));
40
- const verifier = randomBytes(32).toString('base64url');
41
- const started = await retrying(() => post(house, '/kit', {
42
- ...(environment === undefined
43
- ? { act: 'new_environment', label: hostname(), ...(replaces === undefined ? {} : { replaces }) }
44
- : { act: 'existing_environment', environment_id: environment }),
45
- code_challenge: createHash('sha256').update(verifier).digest('base64url'),
46
- ...(held ? {} : { headless: true }),
47
- }));
48
- process.stdout.write(`Open this link and confirm: ${started.start_url}\n`);
49
- open(started.start_url);
50
- const exchanged = await retrying(() => post(house, '/kit/token', { login: started.login, code_verifier: verifier }), undefined, () => POLL_INTERVAL_MS);
51
- await writeEnrolment({ house, environment: exchanged.environment, credential: exchanged.credential });
52
- process.stdout.write(`Environment ${exchanged.environment} is connected to ${house}.\n`);
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;
107
+ try {
108
+ started = await start();
109
+ }
110
+ catch (error) {
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();
117
+ }
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(house);
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));
53
132
  if (exchanged.headless_credential !== undefined) {
54
- await writeOwnAgent({ house, user: exchanged.user, credential: exchanged.headless_credential });
133
+ await writeOwnAgent({ house, ...relayRecord, user: exchanged.user, credential: exchanged.headless_credential });
55
134
  }
56
- else if (held && ownAgent.user !== exchanged.user) {
135
+ else if (held && ownAgent !== null && ownAgent.user !== exchanged.user) {
57
136
  await forgetOwnAgent();
58
137
  process.stdout.write("This computer's own agent was another User's; run kit login again to connect it to you.\n");
59
138
  }
60
- await placeAppGit(ownAgent, await readOwnAgent());
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();
145
+ }
146
+ catch (error) {
147
+ process.stderr.write(`kit: ${error.message}\n`);
148
+ }
61
149
  }
package/dist/logout.js CHANGED
@@ -1,5 +1,4 @@
1
1
  import { HouseRefusal, post } from './api.js';
2
- import { forgetAppGit } from './app-git.js';
3
2
  import { forgetEnrolment, forgetOwnAgent, readEnrolment } from './home.js';
4
3
  export async function logout() {
5
4
  const enrolled = await readEnrolment();
@@ -13,7 +12,6 @@ export async function logout() {
13
12
  }
14
13
  await forgetEnrolment(enrolled);
15
14
  }
16
- await forgetAppGit();
17
15
  await forgetOwnAgent();
18
16
  process.stdout.write(enrolled === null
19
17
  ? 'This computer is not connected to House.\n'
package/dist/mcp.js CHANGED
@@ -1,8 +1,10 @@
1
1
  import { randomUUID } from 'node:crypto';
2
- import { KIT_VERSION } from './clis.js';
2
+ import { KIT_RELEASE } from './clis.js';
3
3
  import { relayed } from './relay.js';
4
4
  const MCP_PROTOCOL_VERSION = '2026-07-28';
5
5
  export const UNREACHABLE = 'House is unreachable; call again in a minute';
6
+ export class Unsettled extends Error {
7
+ }
6
8
  export function rpc(method, params) {
7
9
  return { jsonrpc: '2.0', id: randomUUID(), method, params };
8
10
  }
@@ -13,7 +15,7 @@ export function mcpBody(message, operation) {
13
15
  ...message.params,
14
16
  _meta: {
15
17
  'io.modelcontextprotocol/protocolVersion': MCP_PROTOCOL_VERSION,
16
- 'io.modelcontextprotocol/clientInfo': { name: '@agentshouse/kit', version: KIT_VERSION },
18
+ 'io.modelcontextprotocol/clientInfo': { name: '@agentshouse/kit', version: KIT_RELEASE },
17
19
  'io.modelcontextprotocol/clientCapabilities': {},
18
20
  ...(operation === null ? {} : { 'agents.house/agent-operation': operation }),
19
21
  },
package/dist/parts.js CHANGED
@@ -2,7 +2,10 @@ export class Parts {
2
2
  parts = [];
3
3
  context = null;
4
4
  emit;
5
+ made = [];
6
+ events = 0;
5
7
  writing = null;
8
+ counting = null;
6
9
  planned = null;
7
10
  constructor(emit) {
8
11
  this.emit = emit;
@@ -10,32 +13,34 @@ export class Parts {
10
13
  write(type, id, text) {
11
14
  if (text === '')
12
15
  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 });
16
+ if (this.writing?.type === type && this.writing.id === id) {
17
+ this.parts[this.writing.index].text += text;
18
+ this.emit({ op: 'append', index: this.writing.index, text });
18
19
  return;
19
20
  }
20
- this.start({ type, text });
21
- this.writing = { type, id };
21
+ this.writing = { type, id, index: this.start({ type, text }) };
22
22
  }
23
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 });
24
+ if (this.counting === null) {
25
+ this.counting = this.start({ type: 'commands', count: 1 });
28
26
  return;
29
27
  }
28
+ const part = this.parts[this.counting];
30
29
  part.count++;
31
- this.emit({ op: 'count', index: last, count: part.count });
30
+ this.emit({ op: 'count', index: this.counting, count: part.count });
32
31
  }
33
32
  start(part) {
34
33
  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;
34
+ this.counting = null;
35
+ return this.add(part, ++this.events);
36
+ }
37
+ reserve() {
38
+ this.writing = null;
39
+ this.counting = null;
40
+ return ++this.events;
41
+ }
42
+ arrive(part, reserved) {
43
+ this.add(part, reserved);
39
44
  }
40
45
  done(index, result) {
41
46
  const part = this.parts[index];
@@ -55,10 +60,23 @@ export class Parts {
55
60
  this.context = context;
56
61
  this.emit({ op: 'context', ...context });
57
62
  }
63
+ saved() {
64
+ return this.parts
65
+ .map((part, index) => ({ part, made: this.made[index] }))
66
+ .sort((a, b) => a.made - b.made)
67
+ .map(({ part }) => part);
68
+ }
58
69
  operations() {
59
70
  return [
60
71
  ...this.parts.map((part, index) => ({ op: 'start', index, part })),
61
72
  ...(this.context === null ? [] : [{ op: 'context', ...this.context }]),
62
73
  ];
63
74
  }
75
+ add(part, made) {
76
+ this.parts.push(part);
77
+ this.made.push(made);
78
+ const index = this.parts.length - 1;
79
+ this.emit({ op: 'start', index, part });
80
+ return index;
81
+ }
64
82
  }
@@ -0,0 +1,39 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { run } from './clis.js';
4
+ 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
+ function recorded(name) {
22
+ try {
23
+ return readFileSync(join(kitHome(), name), 'utf8').trim();
24
+ }
25
+ catch (error) {
26
+ if (error.code === 'ENOENT')
27
+ return null;
28
+ throw error;
29
+ }
30
+ }
31
+ export function installCommand() {
32
+ return recorded('install-command');
33
+ }
34
+ export function machine() {
35
+ const placed = recorded('placement');
36
+ if (placed === 'container' || placed === 'server' || placed === 'windows')
37
+ return placed;
38
+ return process.platform === 'darwin' ? 'macos' : 'linux';
39
+ }