@agentshouse/kit 0.2.1-ccf188e02985d → 0.2.1-cd423aab3dbcc

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 (164) hide show
  1. package/README.md +35 -42
  2. package/dist/acp.js +66 -12
  3. package/dist/afk.js +17 -0
  4. package/dist/agents.js +122 -53
  5. package/dist/api.js +15 -10
  6. package/dist/binaries.js +60 -0
  7. package/dist/bridge.js +100 -45
  8. package/dist/building.js +50 -0
  9. package/dist/calls.js +88 -0
  10. package/dist/chunks.js +54 -0
  11. package/dist/clis.js +62 -50
  12. package/dist/connect.js +121 -0
  13. package/dist/connection.js +120 -0
  14. package/dist/content.js +106 -0
  15. package/dist/conversations.js +617 -240
  16. package/dist/copies.js +1277 -623
  17. package/dist/earlier.js +273 -0
  18. package/dist/end.js +12 -5
  19. package/dist/events.js +549 -281
  20. package/dist/files.js +206 -38
  21. package/dist/git.js +2 -72
  22. package/dist/grok.js +39 -0
  23. package/dist/home.js +86 -29
  24. package/dist/house-cli.js +180 -189
  25. package/dist/house-main.js +3 -3
  26. package/dist/instructions.js +29 -11
  27. package/dist/keys.js +238 -0
  28. package/dist/kit-cli.js +18 -8
  29. package/dist/kit-main.js +3 -3
  30. package/dist/login.js +36 -22
  31. package/dist/logout.js +2 -2
  32. package/dist/manifest.js +75 -0
  33. package/dist/mcp.js +47 -7
  34. package/dist/owner.js +46 -0
  35. package/dist/placement.js +15 -20
  36. package/dist/refusals.js +50 -23
  37. package/dist/relay.js +21 -0
  38. package/dist/resident.js +141 -90
  39. package/dist/scope.js +15 -4
  40. package/dist/scripts.js +319 -0
  41. package/dist/secret-input.js +1 -1
  42. package/dist/settings.js +247 -0
  43. package/dist/sign-in.js +67 -21
  44. package/dist/silence.js +28 -0
  45. package/dist/skills.js +42 -97
  46. package/dist/supervisor.js +163 -0
  47. package/dist/transcription.js +88 -45
  48. package/dist/update.js +118 -120
  49. package/dist/wire.js +30 -4
  50. package/dist/work.js +27 -2
  51. package/dist/workspace.js +113 -0
  52. package/package.json +25 -22
  53. package/dist/authority-main.js +0 -22
  54. package/dist/bootstrap.json +0 -24
  55. package/dist/chatgpt.js +0 -32
  56. package/dist/clis-main.js +0 -23
  57. package/dist/configure-main.js +0 -6
  58. package/dist/enrol-main.js +0 -10
  59. package/dist/git-main.js +0 -153
  60. package/dist/inputs.js +0 -37
  61. package/dist/parts.js +0 -82
  62. package/dist/service-main.js +0 -9
  63. package/dist/service.js +0 -55
  64. package/dist/stream.js +0 -123
  65. package/dist/translate.js +0 -51
  66. package/how-we-work.md +0 -33
  67. package/skills/ask-matt/LICENSE +0 -21
  68. package/skills/ask-matt/PHASE-BOUNDARIES.md +0 -55
  69. package/skills/ask-matt/SKILL.md +0 -97
  70. package/skills/ask-matt/agents/openai.yaml +0 -5
  71. package/skills/code-review/LICENSE +0 -21
  72. package/skills/code-review/SKILL.md +0 -89
  73. package/skills/code-review/agents/openai.yaml +0 -3
  74. package/skills/codebase-design/DEEPENING.md +0 -37
  75. package/skills/codebase-design/DESIGN-IT-TWICE.md +0 -44
  76. package/skills/codebase-design/LICENSE +0 -21
  77. package/skills/codebase-design/SKILL.md +0 -114
  78. package/skills/codebase-design/agents/openai.yaml +0 -3
  79. package/skills/diagnosing-bugs/LICENSE +0 -21
  80. package/skills/diagnosing-bugs/SKILL.md +0 -138
  81. package/skills/diagnosing-bugs/agents/openai.yaml +0 -3
  82. package/skills/diagnosing-bugs/scripts/hitl-loop.template.sh +0 -44
  83. package/skills/domain-modeling/ADR-FORMAT.md +0 -47
  84. package/skills/domain-modeling/GLOSSARY-FORMAT.md +0 -60
  85. package/skills/domain-modeling/LICENSE +0 -21
  86. package/skills/domain-modeling/SKILL.md +0 -74
  87. package/skills/domain-modeling/agents/openai.yaml +0 -3
  88. package/skills/grill-me/LICENSE +0 -21
  89. package/skills/grill-me/SKILL.md +0 -7
  90. package/skills/grill-me/agents/openai.yaml +0 -5
  91. package/skills/grill-with-docs/LICENSE +0 -21
  92. package/skills/grill-with-docs/SKILL.md +0 -7
  93. package/skills/grill-with-docs/agents/openai.yaml +0 -5
  94. package/skills/grilling/LICENSE +0 -21
  95. package/skills/grilling/SKILL.md +0 -30
  96. package/skills/grilling/agents/openai.yaml +0 -3
  97. package/skills/handoff/LICENSE +0 -21
  98. package/skills/handoff/SKILL.md +0 -16
  99. package/skills/handoff/agents/openai.yaml +0 -5
  100. package/skills/implement/LICENSE +0 -21
  101. package/skills/implement/SKILL.md +0 -17
  102. package/skills/implement/agents/openai.yaml +0 -5
  103. package/skills/implement-spec/LICENSE +0 -21
  104. package/skills/implement-spec/SKILL.md +0 -40
  105. package/skills/implement-spec/agents/openai.yaml +0 -5
  106. package/skills/improve-codebase-architecture/HTML-REPORT.md +0 -123
  107. package/skills/improve-codebase-architecture/LICENSE +0 -21
  108. package/skills/improve-codebase-architecture/SKILL.md +0 -71
  109. package/skills/improve-codebase-architecture/agents/openai.yaml +0 -5
  110. package/skills/pr/CREDITS.md +0 -3
  111. package/skills/pr/LICENSE +0 -21
  112. package/skills/pr/SKILL.md +0 -170
  113. package/skills/pr/agents/openai.yaml +0 -3
  114. package/skills/prototype/LICENSE +0 -21
  115. package/skills/prototype/LOGIC.md +0 -67
  116. package/skills/prototype/SKILL.md +0 -26
  117. package/skills/prototype/UI.md +0 -112
  118. package/skills/prototype/agents/openai.yaml +0 -3
  119. package/skills/research/LICENSE +0 -21
  120. package/skills/research/SKILL.md +0 -12
  121. package/skills/research/agents/openai.yaml +0 -3
  122. package/skills/retro/LICENSE +0 -21
  123. package/skills/retro/SKILL.md +0 -44
  124. package/skills/retro/agents/openai.yaml +0 -5
  125. package/skills/tdd/LICENSE +0 -21
  126. package/skills/tdd/SKILL.md +0 -38
  127. package/skills/tdd/agents/openai.yaml +0 -3
  128. package/skills/tdd/mocking.md +0 -59
  129. package/skills/tdd/tests.md +0 -77
  130. package/skills/teach/GLOSSARY-FORMAT.md +0 -35
  131. package/skills/teach/LEARNING-RECORD-FORMAT.md +0 -46
  132. package/skills/teach/LICENSE +0 -21
  133. package/skills/teach/MISSION-FORMAT.md +0 -31
  134. package/skills/teach/RESOURCES-FORMAT.md +0 -32
  135. package/skills/teach/SKILL.md +0 -140
  136. package/skills/teach/agents/openai.yaml +0 -5
  137. package/skills/to-questionnaire/LICENSE +0 -21
  138. package/skills/to-questionnaire/SKILL.md +0 -54
  139. package/skills/to-questionnaire/agents/openai.yaml +0 -5
  140. package/skills/to-spec/LICENSE +0 -21
  141. package/skills/to-spec/SKILL.md +0 -75
  142. package/skills/to-spec/agents/openai.yaml +0 -5
  143. package/skills/to-tickets/LICENSE +0 -21
  144. package/skills/to-tickets/SKILL.md +0 -105
  145. package/skills/to-tickets/agents/openai.yaml +0 -5
  146. package/skills/triage/AGENT-BRIEF.md +0 -207
  147. package/skills/triage/LICENSE +0 -21
  148. package/skills/triage/OUT-OF-SCOPE.md +0 -105
  149. package/skills/triage/SKILL.md +0 -112
  150. package/skills/triage/agents/openai.yaml +0 -5
  151. package/skills/wait-what/LICENSE +0 -21
  152. package/skills/wait-what/SKILL.md +0 -7
  153. package/skills/wait-what/agents/openai.yaml +0 -5
  154. package/skills/wayfinder/LICENSE +0 -21
  155. package/skills/wayfinder/SKILL.md +0 -128
  156. package/skills/wayfinder/agents/openai.yaml +0 -5
  157. package/skills/wizard/LICENSE +0 -21
  158. package/skills/wizard/SKILL.md +0 -44
  159. package/skills/wizard/agents/openai.yaml +0 -3
  160. package/skills/wizard/template.sh +0 -223
  161. package/skills/writing-for-agents/LICENSE +0 -21
  162. package/skills/writing-for-agents/SKILL-MECHANICS.md +0 -22
  163. package/skills/writing-for-agents/SKILL.md +0 -81
  164. package/skills/writing-for-agents/agents/openai.yaml +0 -3
package/dist/keys.js ADDED
@@ -0,0 +1,238 @@
1
+ import { spawn } from 'node:child_process';
2
+ import { randomUUID } from 'node:crypto';
3
+ import { mkdir, readFile, realpath, rename, writeFile } from 'node:fs/promises';
4
+ import { homedir } from 'node:os';
5
+ import { dirname, join } from 'node:path';
6
+ import { isDeepStrictEqual } from 'node:util';
7
+ import { parse } from 'smol-toml';
8
+ import { readHome, writeHome } from './home.js';
9
+ import { childEnvironment } from './relay.js';
10
+ function table(value) {
11
+ return typeof value === 'object' && value !== null && !Array.isArray(value) ? value : {};
12
+ }
13
+ function filled(value) {
14
+ return typeof value === 'string' && value !== '';
15
+ }
16
+ function hostOf(endpoint) {
17
+ if (typeof endpoint !== 'string')
18
+ return undefined;
19
+ try {
20
+ return new URL(endpoint).host || undefined;
21
+ }
22
+ catch {
23
+ return undefined;
24
+ }
25
+ }
26
+ function keyed(apiKey, endpoint, maker) {
27
+ const host = hostOf(endpoint);
28
+ return { ...(apiKey ? { api_key: true } : {}), ...(host === undefined || host === maker ? {} : { provider: host }) };
29
+ }
30
+ function quietly(read) {
31
+ return () => read().catch(() => ({}));
32
+ }
33
+ async function readText(file) {
34
+ try {
35
+ return await readFile(file, 'utf8');
36
+ }
37
+ catch (error) {
38
+ if (error.code === 'ENOENT')
39
+ return null;
40
+ throw error;
41
+ }
42
+ }
43
+ async function replaceFile(file, text) {
44
+ const target = await realpath(file).catch(() => file);
45
+ await mkdir(dirname(target), { recursive: true });
46
+ const temporary = `${target}.${randomUUID()}`;
47
+ await writeFile(temporary, text, { mode: 0o600 });
48
+ await rename(temporary, target);
49
+ }
50
+ async function jsonSettings(file) {
51
+ const text = await readText(file);
52
+ if (text === null)
53
+ return {};
54
+ let settings;
55
+ try {
56
+ settings = JSON.parse(text);
57
+ }
58
+ catch {
59
+ settings = null;
60
+ }
61
+ if (typeof settings !== 'object' || settings === null || Array.isArray(settings))
62
+ throw new Error(`${file} holds no JSON object`);
63
+ return settings;
64
+ }
65
+ async function tomlSettings(file) {
66
+ return parse((await readText(file)) ?? '');
67
+ }
68
+ const BARE_KEY = /^[A-Za-z0-9_-]+$/;
69
+ function header(line, at) {
70
+ const trimmed = line.trim();
71
+ if (!trimmed.startsWith('['))
72
+ return null;
73
+ let value;
74
+ try {
75
+ value = parse(trimmed);
76
+ }
77
+ catch {
78
+ return null;
79
+ }
80
+ const path = [];
81
+ while (!Array.isArray(value)) {
82
+ const [name, ...more] = Object.keys(table(value));
83
+ if (name === undefined || more.length > 0)
84
+ return { at, path };
85
+ path.push(name);
86
+ value = table(value)[name];
87
+ }
88
+ return { at, path: [...path, '[]'] };
89
+ }
90
+ function editLines(lines, { table: path, key, value, kept }) {
91
+ const headers = lines.flatMap((line, at) => header(line, at) ?? []);
92
+ const found = path.length === 0 ? { at: -1, path } : headers.find((one) => isDeepStrictEqual(one.path, path));
93
+ const assignment = `${key} = ${JSON.stringify(value)}`;
94
+ if (found === undefined) {
95
+ if (value === null)
96
+ return lines;
97
+ const kept = lines.at(-1) === '' ? lines.slice(0, -1) : lines;
98
+ return [...kept, ...(kept.length === 0 ? [] : ['']), `[${path.map((name) => (BARE_KEY.test(name) ? name : JSON.stringify(name))).join('.')}]`, assignment, ''];
99
+ }
100
+ const end = headers.find((one) => one.at > found.at)?.at ?? lines.length;
101
+ const assigned = new RegExp(`^\\s*${key}\\s*=`);
102
+ const current = lines.findIndex((line, at) => at > found.at && at < end && assigned.test(line));
103
+ if (current !== -1 && kept)
104
+ return lines;
105
+ if (current !== -1)
106
+ return value === null ? lines.toSpliced(current, 1) : lines.toSpliced(current, 1, assignment);
107
+ if (value === null)
108
+ return lines;
109
+ const last = lines.findLastIndex((line, at) => at > found.at && at < end && line.trim() !== '');
110
+ return lines.toSpliced(Math.max(last, found.at) + 1, 0, assignment);
111
+ }
112
+ function editSettings(settings, { table: path, key, value, kept }) {
113
+ let at = settings;
114
+ for (const name of path) {
115
+ if (typeof at[name] !== 'object' || at[name] === null)
116
+ at[name] = Object.create(null);
117
+ at = at[name];
118
+ }
119
+ if (kept && key in at)
120
+ return;
121
+ if (value === null)
122
+ delete at[key];
123
+ else
124
+ at[key] = value;
125
+ }
126
+ async function editToml(file, edits) {
127
+ const text = (await readText(file)) ?? '';
128
+ let expected;
129
+ try {
130
+ expected = parse(text);
131
+ }
132
+ catch {
133
+ throw new Error(`${file} is not TOML`);
134
+ }
135
+ for (const edit of edits)
136
+ editSettings(expected, edit);
137
+ const edited = edits.reduce(editLines, text === '' ? [] : text.split('\n')).join('\n');
138
+ let written;
139
+ try {
140
+ written = parse(edited);
141
+ }
142
+ catch {
143
+ written = null;
144
+ }
145
+ if (!isDeepStrictEqual(written, expected))
146
+ throw new Error(`${file} could not take the key without changing its other settings`);
147
+ if (edited === text)
148
+ return async () => undefined;
149
+ return () => replaceFile(file, edited.endsWith('\n') ? edited : `${edited}\n`);
150
+ }
151
+ function claudeSettings() {
152
+ return join(process.env.CLAUDE_CONFIG_DIR || join(homedir(), '.claude'), 'settings.json');
153
+ }
154
+ export const CLAUDE_KEY = {
155
+ read: quietly(async () => {
156
+ const env = table((await jsonSettings(claudeSettings())).env);
157
+ return keyed(filled(env.ANTHROPIC_API_KEY) || filled(env.ANTHROPIC_AUTH_TOKEN), env.ANTHROPIC_BASE_URL, 'api.anthropic.com');
158
+ }),
159
+ write: async (key, endpoint) => {
160
+ const file = claudeSettings();
161
+ const settings = await jsonSettings(file);
162
+ const { ANTHROPIC_API_KEY: _key, ANTHROPIC_AUTH_TOKEN: _token, ANTHROPIC_BASE_URL: _endpoint, ...env } = table(settings.env);
163
+ const written = endpoint === null
164
+ ? { ...env, ANTHROPIC_API_KEY: key }
165
+ : { ...env, ANTHROPIC_AUTH_TOKEN: key, ANTHROPIC_API_KEY: '', ANTHROPIC_BASE_URL: endpoint };
166
+ await replaceFile(file, `${JSON.stringify({ ...settings, env: written }, undefined, 2)}\n`);
167
+ },
168
+ };
169
+ const CODEX_PROVIDER = 'model_provider';
170
+ export function codexHome() {
171
+ return process.env.CODEX_HOME || join(homedir(), '.codex');
172
+ }
173
+ function codexLogin(cli, key, signal) {
174
+ return new Promise((resolve, reject) => {
175
+ const child = spawn(cli, ['login', '--with-api-key'], { stdio: ['pipe', 'ignore', 'pipe'], env: childEnvironment(), signal });
176
+ let output = '';
177
+ child.stderr.setEncoding('utf8').on('data', (chunk) => {
178
+ output = (output + chunk).slice(-4000);
179
+ });
180
+ child.on('error', reject);
181
+ child.on('close', (status) => {
182
+ const last = output.trim().split('\n').at(-1) ?? '';
183
+ if (status === 0)
184
+ resolve();
185
+ else
186
+ reject(new Error(`codex login --with-api-key exited with ${status ?? 'a signal'}${last === '' ? '' : `: ${last}`}`));
187
+ });
188
+ child.stdin.end(key);
189
+ });
190
+ }
191
+ export const CODEX_KEY = {
192
+ read: quietly(async () => {
193
+ const config = await tomlSettings(join(codexHome(), 'config.toml'));
194
+ const id = config[CODEX_PROVIDER];
195
+ if (typeof id === 'string' && id !== 'openai') {
196
+ const provider = table(table(config.model_providers)[id]);
197
+ const fromEnvironment = typeof provider.env_key === 'string' && filled(process.env[provider.env_key]);
198
+ return keyed(filled(provider.experimental_bearer_token) || fromEnvironment, provider.base_url, 'api.openai.com');
199
+ }
200
+ const auth = table(JSON.parse((await readText(join(codexHome(), 'auth.json'))) ?? '{}'));
201
+ return keyed(filled(auth.OPENAI_API_KEY) && (auth.tokens === undefined || auth.tokens === null), undefined, 'api.openai.com');
202
+ }),
203
+ write: async (key, endpoint, cli, signal) => {
204
+ const file = join(codexHome(), 'config.toml');
205
+ if (endpoint === null) {
206
+ const write = await editToml(file, [{ table: [], key: CODEX_PROVIDER, value: null }]);
207
+ await codexLogin(cli, key, signal);
208
+ await write();
209
+ return;
210
+ }
211
+ const host = new URL(endpoint).host;
212
+ const provider = ['model_providers', host];
213
+ const write = await editToml(file, [
214
+ { table: [], key: CODEX_PROVIDER, value: host },
215
+ { table: provider, key: 'name', value: host, kept: true },
216
+ { table: provider, key: 'base_url', value: endpoint },
217
+ { table: provider, key: 'experimental_bearer_token', value: key },
218
+ ]);
219
+ await write();
220
+ },
221
+ };
222
+ const GROK_HELD_KEY = 'grok-key.json';
223
+ export const GROK_KEY = {
224
+ read: quietly(async () => {
225
+ const held = await readHome(GROK_HELD_KEY);
226
+ if (held?.endpoint !== undefined)
227
+ return keyed(true, held.endpoint, 'api.x.ai');
228
+ const config = await tomlSettings(join(process.env.GROK_HOME || join(homedir(), '.grok'), 'config.toml'));
229
+ return keyed(held !== null, table(config.endpoints).models_base_url, 'api.x.ai');
230
+ }),
231
+ write: (key, endpoint) => writeHome(GROK_HELD_KEY, { key, ...(endpoint === null ? {} : { endpoint }) }),
232
+ environment: async () => {
233
+ const held = await readHome(GROK_HELD_KEY);
234
+ if (held === null)
235
+ return {};
236
+ return { XAI_API_KEY: held.key, ...(held.endpoint === undefined ? {} : { GROK_MODELS_BASE_URL: held.endpoint }) };
237
+ },
238
+ };
package/dist/kit-cli.js CHANGED
@@ -1,17 +1,18 @@
1
- import { setGlobalProxyFromEnv } from 'node:http';
2
1
  import { parseArgs } from 'node:util';
3
2
  import { answerGitCredential } from './app-git.js';
4
- import { chatgpt } from './chatgpt.js';
3
+ import { connect } from './connect.js';
5
4
  import { login } from './login.js';
6
5
  import { logout } from './logout.js';
6
+ import { proxyUnlessRelayed } from './relay.js';
7
7
  import { resident } from './resident.js';
8
- const USAGE = 'usage: kit <login|logout|resident|chatgpt>\n';
8
+ import { kitSettings, SETTINGS_USAGE } from './settings.js';
9
+ const USAGE = 'usage: kit <connect|login|logout|resident|settings>\n';
9
10
  const COMMANDS = new Map([
10
11
  [
11
12
  'logout',
12
13
  {
13
14
  usage: 'usage: kit logout',
14
- about: "disconnects this computer, stops House Kit and ends your own agent's connection",
15
+ about: "disconnects this computer, stops the Kit process and ends your own agent's connection",
15
16
  operands: 0,
16
17
  run: logout,
17
18
  },
@@ -20,11 +21,20 @@ const COMMANDS = new Map([
20
21
  'resident',
21
22
  {
22
23
  usage: 'usage: kit resident',
23
- about: "keeps this Environment connected; House Kit's service runs it",
24
+ about: "keeps this Environment connected; Kit's service runs it",
24
25
  operands: 0,
25
26
  run: resident,
26
27
  },
27
28
  ],
29
+ [
30
+ 'settings',
31
+ {
32
+ usage: SETTINGS_USAGE,
33
+ about: "prints Kit's settings, or changes whether Kit places House's Skills or where its workspace is",
34
+ operands: 2,
35
+ run: kitSettings,
36
+ },
37
+ ],
28
38
  [
29
39
  'git-credential',
30
40
  {
@@ -36,12 +46,12 @@ const COMMANDS = new Map([
36
46
  ],
37
47
  ]);
38
48
  const [command, ...argv] = process.argv.slice(2);
39
- setGlobalProxyFromEnv();
49
+ proxyUnlessRelayed();
40
50
  async function run() {
51
+ if (command === 'connect')
52
+ return connect(argv);
41
53
  if (command === 'login')
42
54
  return login(argv);
43
- if (command === 'chatgpt')
44
- return chatgpt(argv);
45
55
  if (command === '--help') {
46
56
  parseArgs({ args: argv });
47
57
  process.stdout.write(USAGE);
package/dist/kit-main.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
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`);
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`);
5
5
  process.exitCode = 1;
6
6
  }
7
7
  else {
package/dist/login.js CHANGED
@@ -1,6 +1,6 @@
1
+ import { KIT_LOGIN_PATHS, } from '@agentshouse/kit-wire';
1
2
  import { spawn } from 'node:child_process';
2
3
  import { createHash, randomBytes } from 'node:crypto';
3
- import { hostname } from 'node:os';
4
4
  import { parseArgs } from 'node:util';
5
5
  import { HouseRefusal, post, retrying } from './api.js';
6
6
  import { placeAppGit } from './app-git.js';
@@ -9,23 +9,31 @@ import { forgetDisconnected, forgetOwnAgent, readDisconnected, readEnrolment, re
9
9
  import { callHouse, rpc } from './mcp.js';
10
10
  import { refusalOf } from './refusals.js';
11
11
  import { selectRelay } from './relay.js';
12
- import { startService } from './service.js';
12
+ import { startService } from './supervisor.js';
13
13
  import { placeSkillSet } from './skills.js';
14
+ import { endUnserved } from './wire.js';
14
15
  export const DEFAULT_HOUSE = 'https://agents.house';
15
16
  const OPENER = process.platform === 'darwin' ? 'open' : 'xdg-open';
16
17
  // Polling every two seconds brings the User's confirmation to the waiting Kit moments after they give it.
17
18
  const POLL_INTERVAL_MS = 2000;
19
+ function startLogin(house, request) {
20
+ return post(house, KIT_LOGIN_PATHS.start, request);
21
+ }
22
+ function pollLogin(house, request) {
23
+ return post(house, KIT_LOGIN_PATHS.poll, request);
24
+ }
18
25
  function open(link) {
19
26
  spawn(OPENER, [link], { detached: true, stdio: 'ignore' })
20
27
  .on('error', () => undefined)
21
28
  .unref();
22
29
  }
23
- export async function accepted(house, credential) {
30
+ async function accepted(house, credential) {
24
31
  const checked = await callHouse(house, credential, rpc('tools/list', {}));
25
32
  if (checked.status === 200)
26
33
  return true;
27
34
  if (checked.status === 401)
28
35
  return false;
36
+ endUnserved(checked.text);
29
37
  throw new Error(`House answered ${checked.status} when Kit checked this computer's own agent's connection: ${checked.text}`);
30
38
  }
31
39
  const USAGE = `usage: kit login [--house <origin>] [--environment <id>] [--rooms <ref>[,<ref>...] | --no-private]
@@ -69,6 +77,21 @@ export async function login(argv) {
69
77
  process.stdout.write(USAGE);
70
78
  return;
71
79
  }
80
+ const house = await enrol(values);
81
+ await placeConnection(house);
82
+ try {
83
+ startService();
84
+ }
85
+ catch (error) {
86
+ process.stderr.write(`kit: ${error.message}\n`);
87
+ }
88
+ }
89
+ export async function placeConnection(house) {
90
+ await placeSkillSet(house);
91
+ await writeCodexRule().catch((error) => process.stderr.write(`kit: ${error.message}\n`));
92
+ await placeAppGit(await readOwnAgent()).catch((error) => process.stderr.write(`kit: ${error.message}\n`));
93
+ }
94
+ export async function enrol(values) {
72
95
  if (values.code !== undefined && values.rooms !== undefined)
73
96
  throw new Error('--code cannot be used with --rooms');
74
97
  if (values.code !== undefined && values['no-private'])
@@ -83,24 +106,23 @@ export async function login(argv) {
83
106
  const relay = process.env.HOUSE_KIT_RELAY || undefined;
84
107
  selectRelay(relay);
85
108
  const house = values.house ?? enrolled?.house ?? DEFAULT_HOUSE;
86
- const replaces = process.env.HOUSE_KIT_REPLACES;
87
- const remembered = replaces === undefined && values.environment === undefined && enrolled?.house === house ? enrolled.environment : undefined;
88
- const environment = replaces === undefined ? (values.environment ?? remembered) : undefined;
109
+ const remembered = values.environment === undefined && enrolled?.house === house ? enrolled.environment : undefined;
110
+ const environment = values.environment ?? remembered;
111
+ if (environment !== undefined && rooms.rooms !== undefined) {
112
+ throw new Error(`Environment ${environment} keeps its Rooms; change them on its page in House`);
113
+ }
89
114
  const ownAgent = await readOwnAgent();
90
115
  let held = false;
91
116
  let named = environment;
92
117
  let exchanged;
93
118
  if (values.code !== undefined) {
94
- exchanged = await post(house, '/kit/token', { code: values.code, label: hostname() });
119
+ exchanged = await pollLogin(house, { code: values.code });
95
120
  }
96
121
  else {
97
122
  held = ownAgent !== null && ownAgent.house === house && (await accepted(house, ownAgent.credential));
98
123
  const verifier = randomBytes(32).toString('base64url');
99
- const start = () => retrying(() => post(house, '/kit', {
100
- label: hostname(),
101
- ...(named === undefined
102
- ? { act: 'new_environment', ...(replaces === undefined ? {} : { replaces }) }
103
- : { act: 'existing_environment', environment_id: named }),
124
+ const start = () => retrying(() => startLogin(house, {
125
+ ...(named === undefined ? { act: 'new_environment' } : { act: 'existing_environment', environment_id: named }),
104
126
  ...rooms,
105
127
  code_challenge: createHash('sha256').update(verifier).digest('base64url'),
106
128
  ...(held ? {} : { headless: true }),
@@ -119,10 +141,8 @@ export async function login(argv) {
119
141
  }
120
142
  process.stdout.write(`Open this link and confirm: ${started.start_url}\n`);
121
143
  open(started.start_url);
122
- exchanged = await retrying(() => post(house, '/kit/token', { login: started.login, code_verifier: verifier }), undefined, () => POLL_INTERVAL_MS);
144
+ exchanged = await retrying(() => pollLogin(house, { login: started.login, code_verifier: verifier }), undefined, () => POLL_INTERVAL_MS);
123
145
  }
124
- await placeSkillSet();
125
- await writeCodexRule().catch((error) => process.stderr.write(`kit: ${error.message}\n`));
126
146
  const relayRecord = relay === undefined ? {} : { relay };
127
147
  await writeEnrolment({
128
148
  house,
@@ -141,11 +161,5 @@ export async function login(argv) {
141
161
  else if (held && ownAgent !== null) {
142
162
  await writeOwnAgent({ house, ...relayRecord, user: ownAgent.user, credential: ownAgent.credential });
143
163
  }
144
- await placeAppGit(await readOwnAgent()).catch((error) => process.stderr.write(`kit: ${error.message}\n`));
145
- try {
146
- startService();
147
- }
148
- catch (error) {
149
- process.stderr.write(`kit: ${error.message}\n`);
150
- }
164
+ return house;
151
165
  }
package/dist/logout.js CHANGED
@@ -1,10 +1,10 @@
1
- import { HouseRefusal, post } from './api.js';
1
+ import { HouseRefusal, kitAct } from './api.js';
2
2
  import { forgetEnrolment, forgetOwnAgent, readEnrolment } from './home.js';
3
3
  export async function logout() {
4
4
  const enrolled = await readEnrolment();
5
5
  if (enrolled !== null) {
6
6
  try {
7
- await post(enrolled.house, '/kit/logout', {}, enrolled.credential);
7
+ await kitAct(enrolled.house, 'kits/log-out', {}, enrolled.credential);
8
8
  }
9
9
  catch (error) {
10
10
  if (!(error instanceof HouseRefusal && error.status === 401))
@@ -0,0 +1,75 @@
1
+ import { createHash, randomUUID } from 'node:crypto';
2
+ import { createReadStream } from 'node:fs';
3
+ import { mkdir, readFile, readdir, rename, rm, rmdir, writeFile } from 'node:fs/promises';
4
+ import { dirname, join } from 'node:path';
5
+ export const MANIFEST = '.house';
6
+ const UNREAD = '.git';
7
+ const MARKER = /^(?:<{7}|={7}|>{7})(?: .*)?$/m;
8
+ export function digest(bytes) {
9
+ return createHash('sha256').update(bytes).digest('hex');
10
+ }
11
+ export async function fileDigest(file) {
12
+ const hash = createHash('sha256');
13
+ let bytes = 0;
14
+ for await (const chunk of createReadStream(file)) {
15
+ hash.update(chunk);
16
+ bytes += chunk.length;
17
+ }
18
+ return { sha256: hash.digest('hex'), bytes };
19
+ }
20
+ export async function hashed(file) {
21
+ try {
22
+ return await fileDigest(file);
23
+ }
24
+ catch (error) {
25
+ if (error.code === 'ENOENT' || error.code === 'EISDIR')
26
+ return null;
27
+ throw error;
28
+ }
29
+ }
30
+ export async function holding(repository, name, sha256) {
31
+ return (await hashed(join(repository, name)))?.sha256 === sha256;
32
+ }
33
+ export async function readManifest(repository) {
34
+ return JSON.parse(await readFile(join(repository, MANIFEST), 'utf8'));
35
+ }
36
+ export async function placed(staging, target, content) {
37
+ const temporary = `${staging}${randomUUID()}`;
38
+ await writeFile(temporary, content);
39
+ await mkdir(dirname(target), { recursive: true });
40
+ await rename(temporary, target);
41
+ }
42
+ export async function writeManifest(repository, staging, manifest) {
43
+ const files = Object.fromEntries(Object.entries(manifest.files).sort(([left], [right]) => (left < right ? -1 : 1)));
44
+ await placed(staging, join(repository, MANIFEST), `${JSON.stringify({ room_ref: manifest.room_ref, files })}\n`);
45
+ }
46
+ export async function removed(repository, name) {
47
+ await rm(join(repository, name), { force: true });
48
+ for (let folder = dirname(name); folder !== '.'; folder = dirname(folder)) {
49
+ if (!(await rmdir(join(repository, folder)).then(() => true, () => false)))
50
+ return;
51
+ }
52
+ }
53
+ export async function scanned(repository) {
54
+ const present = new Map();
55
+ const walk = async (folder) => {
56
+ for (const entry of await readdir(join(repository, folder), { withFileTypes: true })) {
57
+ const name = folder === '' ? entry.name : `${folder}/${entry.name}`;
58
+ if (folder === '' && (entry.name === MANIFEST || entry.name === UNREAD))
59
+ continue;
60
+ if (entry.isDirectory())
61
+ await walk(name);
62
+ else if (entry.isFile()) {
63
+ const file = await hashed(join(repository, name));
64
+ if (file !== null)
65
+ present.set(name.normalize('NFC'), { name, ...file });
66
+ }
67
+ }
68
+ };
69
+ await walk('');
70
+ return present;
71
+ }
72
+ export async function marked(repository, name) {
73
+ const text = await readFile(join(repository, name), 'utf8').catch(() => null);
74
+ return text !== null && MARKER.test(text);
75
+ }
package/dist/mcp.js CHANGED
@@ -1,26 +1,35 @@
1
+ import { KIT_WIRE, KIT_WIRE_HEADER } from '@agentshouse/kit-wire';
1
2
  import { randomUUID } from 'node:crypto';
2
- import { KIT_VERSION } from './clis.js';
3
- import { relayed } from './relay.js';
3
+ import { KIT_RELEASE } from './clis.js';
4
+ import { readOwnAgent } from './home.js';
5
+ import { refusalOf, retryable } from './refusals.js';
6
+ import { relayed, selectRelay } from './relay.js';
4
7
  const MCP_PROTOCOL_VERSION = '2026-07-28';
5
8
  export const UNREACHABLE = 'House is unreachable; call again in a minute';
9
+ const UNCONNECTED = "this computer's own agent has no House connection; run kit login";
10
+ export const DISCONNECTED = "House no longer accepts this computer's own agent; run kit login";
11
+ const UNCONFIRMED = 'with no result; a write may or may not have taken effect, so read before you repeat it';
12
+ export class Unsettled extends Error {
13
+ }
6
14
  export function rpc(method, params) {
7
15
  return { jsonrpc: '2.0', id: randomUUID(), method, params };
8
16
  }
9
- export function mcpBody(message, operation) {
17
+ export function mcpBody(message, { operation = null, named = {} } = {}) {
10
18
  return JSON.stringify({
11
19
  ...message,
12
20
  params: {
13
21
  ...message.params,
14
22
  _meta: {
15
23
  'io.modelcontextprotocol/protocolVersion': MCP_PROTOCOL_VERSION,
16
- 'io.modelcontextprotocol/clientInfo': { name: '@agentshouse/kit', version: KIT_VERSION },
24
+ 'io.modelcontextprotocol/clientInfo': { name: '@agentshouse/kit', version: KIT_RELEASE },
17
25
  'io.modelcontextprotocol/clientCapabilities': {},
26
+ ...named,
18
27
  ...(operation === null ? {} : { 'agents.house/agent-operation': operation }),
19
28
  },
20
29
  },
21
30
  });
22
31
  }
23
- export async function callHouse(origin, credential, message, operation = null, signal) {
32
+ export async function callHouse(origin, credential, message, sending = {}) {
24
33
  const tool = message.method === 'tools/call' ? String(message.params.name) : null;
25
34
  const answer = await fetch(relayed(new URL('/', origin)), {
26
35
  method: 'POST',
@@ -31,9 +40,40 @@ export async function callHouse(origin, credential, message, operation = null, s
31
40
  'mcp-protocol-version': MCP_PROTOCOL_VERSION,
32
41
  'mcp-method': message.method,
33
42
  ...(tool === null ? {} : { 'mcp-name': tool }),
43
+ [KIT_WIRE_HEADER]: KIT_WIRE,
34
44
  },
35
- body: mcpBody(message, operation),
36
- signal,
45
+ body: mcpBody(message, sending),
46
+ signal: sending.signal,
37
47
  });
38
48
  return { status: answer.status, text: await answer.text() };
39
49
  }
50
+ export function unconfirmed(status) {
51
+ return `House answered ${status} ${UNCONFIRMED}`;
52
+ }
53
+ export async function ownAgentCall(message) {
54
+ const ownAgent = await readOwnAgent();
55
+ if (ownAgent === null)
56
+ throw new Error(UNCONNECTED);
57
+ selectRelay(process.env.HOUSE_KIT_RELAY || ownAgent.relay);
58
+ const answer = await callHouse(ownAgent.house, ownAgent.credential, message).catch(() => {
59
+ throw new Unsettled(UNREACHABLE);
60
+ });
61
+ if (answer.status === 200)
62
+ return answer.text;
63
+ if (answer.status === 401)
64
+ throw new Error(DISCONNECTED);
65
+ const refusal = refusalOf(answer.text)?.text ?? unconfirmed(answer.status);
66
+ throw retryable(answer.text) === false ? new Error(refusal) : new Unsettled(refusal);
67
+ }
68
+ export function refusalIn(text, status) {
69
+ return refusalOf(text) ?? { code: '', text: text === '' ? `House refused it with ${status}` : text, conflicts: [], detail: {} };
70
+ }
71
+ export function toolAnswer(forwarded) {
72
+ if (forwarded.status !== 200)
73
+ return { refused: refusalIn(forwarded.text, forwarded.status) };
74
+ const answer = JSON.parse(forwarded.text);
75
+ if (answer.error !== undefined)
76
+ return { refused: refusalIn(answer.error.message, forwarded.status) };
77
+ const text = answer.result.content.map((content) => content.text).join('\n');
78
+ return answer.result.isError === true ? { refused: refusalIn(text, forwarded.status) } : { text };
79
+ }
package/dist/owner.js ADDED
@@ -0,0 +1,46 @@
1
+ import { request } from 'node:http';
2
+ import { DatabaseSync } from 'node:sqlite';
3
+ import { received } from './bridge.js';
4
+ import { kitHome, ownerLock, ownerSocket } from './home.js';
5
+ function claimed(lock) {
6
+ try {
7
+ lock.exec('BEGIN EXCLUSIVE');
8
+ return true;
9
+ }
10
+ catch (error) {
11
+ if (error.errcode === 5)
12
+ return false;
13
+ throw error;
14
+ }
15
+ }
16
+ export function askOwner(path, body) {
17
+ return new Promise((resolve, reject) => {
18
+ const sent = request({ socketPath: ownerSocket(), path, method: body === undefined ? 'GET' : 'POST', headers: { 'content-type': 'application/json' } }, (answer) => {
19
+ received(answer).then((text) => {
20
+ if (answer.statusCode === 200)
21
+ resolve(JSON.parse(text));
22
+ else
23
+ reject(new Error(text));
24
+ }, reject);
25
+ });
26
+ sent.on('error', (error) => {
27
+ if (error.code === 'ENOENT' || error.code === 'ECONNREFUSED')
28
+ resolve(null);
29
+ else
30
+ reject(error);
31
+ });
32
+ sent.end(body === undefined ? undefined : JSON.stringify(body));
33
+ });
34
+ }
35
+ export async function holdOwner() {
36
+ const lock = new DatabaseSync(ownerLock());
37
+ if (claimed(lock))
38
+ return lock;
39
+ lock.close();
40
+ const running = (await askOwner('/resident'))?.pid ?? null;
41
+ throw new Error(`${running === null ? 'another Kit process' : `Kit process ${running}`} already runs this Environment from Kit home ${kitHome()}; stop it first to run another Kit process here`);
42
+ }
43
+ export async function runningRelease() {
44
+ const running = await askOwner('/resident');
45
+ return running === null ? null : (running.release ?? '');
46
+ }