@agentshouse/kit 0.2.1-ce3d2bb67177c → 0.2.1-ce46b2b55463f

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 (161) hide show
  1. package/README.md +31 -35
  2. package/dist/acp.js +56 -6
  3. package/dist/afk.js +17 -0
  4. package/dist/agents.js +120 -51
  5. package/dist/api.js +11 -6
  6. package/dist/binaries.js +79 -0
  7. package/dist/bridge.js +30 -26
  8. package/dist/building.js +50 -0
  9. package/dist/calls.js +29 -4
  10. package/dist/chunks.js +49 -0
  11. package/dist/clis.js +61 -49
  12. package/dist/connect.js +108 -0
  13. package/dist/connection.js +33 -38
  14. package/dist/content.js +106 -0
  15. package/dist/conversations.js +325 -141
  16. package/dist/copies.js +720 -247
  17. package/dist/earlier.js +263 -0
  18. package/dist/end.js +4 -5
  19. package/dist/events.js +549 -281
  20. package/dist/files.js +110 -28
  21. package/dist/git-main.js +24 -29
  22. package/dist/git.js +89 -14
  23. package/dist/grok.js +39 -0
  24. package/dist/home.js +65 -29
  25. package/dist/house-cli.js +114 -159
  26. package/dist/house-main.js +3 -3
  27. package/dist/instructions.js +29 -11
  28. package/dist/keys.js +238 -0
  29. package/dist/kit-cli.js +16 -6
  30. package/dist/kit-main.js +3 -3
  31. package/dist/login.js +36 -20
  32. package/dist/logout.js +2 -2
  33. package/dist/mcp.js +38 -1
  34. package/dist/owner.js +46 -0
  35. package/dist/placement.js +9 -23
  36. package/dist/refusals.js +37 -21
  37. package/dist/relay.js +21 -0
  38. package/dist/resident.js +109 -65
  39. package/dist/scope.js +12 -4
  40. package/dist/scripts.js +303 -0
  41. package/dist/secret-input.js +1 -1
  42. package/dist/settings.js +188 -0
  43. package/dist/sign-in.js +49 -3
  44. package/dist/silence.js +28 -0
  45. package/dist/skills.js +41 -96
  46. package/dist/supervisor.js +163 -0
  47. package/dist/transcription.js +37 -25
  48. package/dist/translate.js +18 -9
  49. package/dist/update.js +115 -117
  50. package/dist/wire.js +19 -9
  51. package/dist/work.js +9 -2
  52. package/dist/workspace.js +103 -0
  53. package/package.json +25 -21
  54. package/dist/authority-main.js +0 -22
  55. package/dist/bootstrap.json +0 -24
  56. package/dist/chatgpt.js +0 -32
  57. package/dist/clis-main.js +0 -23
  58. package/dist/configure-main.js +0 -6
  59. package/dist/enrol-main.js +0 -10
  60. package/dist/parts.js +0 -82
  61. package/dist/service-main.js +0 -9
  62. package/dist/service.js +0 -55
  63. package/how-we-work.md +0 -33
  64. package/skills/ask-matt/LICENSE +0 -21
  65. package/skills/ask-matt/PHASE-BOUNDARIES.md +0 -55
  66. package/skills/ask-matt/SKILL.md +0 -97
  67. package/skills/ask-matt/agents/openai.yaml +0 -5
  68. package/skills/code-review/LICENSE +0 -21
  69. package/skills/code-review/SKILL.md +0 -89
  70. package/skills/code-review/agents/openai.yaml +0 -3
  71. package/skills/codebase-design/DEEPENING.md +0 -37
  72. package/skills/codebase-design/DESIGN-IT-TWICE.md +0 -44
  73. package/skills/codebase-design/LICENSE +0 -21
  74. package/skills/codebase-design/SKILL.md +0 -114
  75. package/skills/codebase-design/agents/openai.yaml +0 -3
  76. package/skills/diagnosing-bugs/LICENSE +0 -21
  77. package/skills/diagnosing-bugs/SKILL.md +0 -138
  78. package/skills/diagnosing-bugs/agents/openai.yaml +0 -3
  79. package/skills/diagnosing-bugs/scripts/hitl-loop.template.sh +0 -44
  80. package/skills/domain-modeling/ADR-FORMAT.md +0 -47
  81. package/skills/domain-modeling/GLOSSARY-FORMAT.md +0 -60
  82. package/skills/domain-modeling/LICENSE +0 -21
  83. package/skills/domain-modeling/SKILL.md +0 -74
  84. package/skills/domain-modeling/agents/openai.yaml +0 -3
  85. package/skills/grill-me/LICENSE +0 -21
  86. package/skills/grill-me/SKILL.md +0 -7
  87. package/skills/grill-me/agents/openai.yaml +0 -5
  88. package/skills/grill-with-docs/LICENSE +0 -21
  89. package/skills/grill-with-docs/SKILL.md +0 -7
  90. package/skills/grill-with-docs/agents/openai.yaml +0 -5
  91. package/skills/grilling/LICENSE +0 -21
  92. package/skills/grilling/SKILL.md +0 -30
  93. package/skills/grilling/agents/openai.yaml +0 -3
  94. package/skills/handoff/LICENSE +0 -21
  95. package/skills/handoff/SKILL.md +0 -16
  96. package/skills/handoff/agents/openai.yaml +0 -5
  97. package/skills/implement/LICENSE +0 -21
  98. package/skills/implement/SKILL.md +0 -17
  99. package/skills/implement/agents/openai.yaml +0 -5
  100. package/skills/implement-spec/LICENSE +0 -21
  101. package/skills/implement-spec/SKILL.md +0 -40
  102. package/skills/implement-spec/agents/openai.yaml +0 -5
  103. package/skills/improve-codebase-architecture/HTML-REPORT.md +0 -123
  104. package/skills/improve-codebase-architecture/LICENSE +0 -21
  105. package/skills/improve-codebase-architecture/SKILL.md +0 -71
  106. package/skills/improve-codebase-architecture/agents/openai.yaml +0 -5
  107. package/skills/pr/CREDITS.md +0 -3
  108. package/skills/pr/LICENSE +0 -21
  109. package/skills/pr/SKILL.md +0 -170
  110. package/skills/pr/agents/openai.yaml +0 -3
  111. package/skills/prototype/LICENSE +0 -21
  112. package/skills/prototype/LOGIC.md +0 -67
  113. package/skills/prototype/SKILL.md +0 -26
  114. package/skills/prototype/UI.md +0 -112
  115. package/skills/prototype/agents/openai.yaml +0 -3
  116. package/skills/research/LICENSE +0 -21
  117. package/skills/research/SKILL.md +0 -12
  118. package/skills/research/agents/openai.yaml +0 -3
  119. package/skills/retro/LICENSE +0 -21
  120. package/skills/retro/SKILL.md +0 -44
  121. package/skills/retro/agents/openai.yaml +0 -5
  122. package/skills/tdd/LICENSE +0 -21
  123. package/skills/tdd/SKILL.md +0 -38
  124. package/skills/tdd/agents/openai.yaml +0 -3
  125. package/skills/tdd/mocking.md +0 -59
  126. package/skills/tdd/tests.md +0 -77
  127. package/skills/teach/GLOSSARY-FORMAT.md +0 -35
  128. package/skills/teach/LEARNING-RECORD-FORMAT.md +0 -46
  129. package/skills/teach/LICENSE +0 -21
  130. package/skills/teach/MISSION-FORMAT.md +0 -31
  131. package/skills/teach/RESOURCES-FORMAT.md +0 -32
  132. package/skills/teach/SKILL.md +0 -140
  133. package/skills/teach/agents/openai.yaml +0 -5
  134. package/skills/to-questionnaire/LICENSE +0 -21
  135. package/skills/to-questionnaire/SKILL.md +0 -54
  136. package/skills/to-questionnaire/agents/openai.yaml +0 -5
  137. package/skills/to-spec/LICENSE +0 -21
  138. package/skills/to-spec/SKILL.md +0 -75
  139. package/skills/to-spec/agents/openai.yaml +0 -5
  140. package/skills/to-tickets/LICENSE +0 -21
  141. package/skills/to-tickets/SKILL.md +0 -105
  142. package/skills/to-tickets/agents/openai.yaml +0 -5
  143. package/skills/triage/AGENT-BRIEF.md +0 -207
  144. package/skills/triage/LICENSE +0 -21
  145. package/skills/triage/OUT-OF-SCOPE.md +0 -105
  146. package/skills/triage/SKILL.md +0 -112
  147. package/skills/triage/agents/openai.yaml +0 -5
  148. package/skills/wait-what/LICENSE +0 -21
  149. package/skills/wait-what/SKILL.md +0 -7
  150. package/skills/wait-what/agents/openai.yaml +0 -5
  151. package/skills/wayfinder/LICENSE +0 -21
  152. package/skills/wayfinder/SKILL.md +0 -128
  153. package/skills/wayfinder/agents/openai.yaml +0 -5
  154. package/skills/wizard/LICENSE +0 -21
  155. package/skills/wizard/SKILL.md +0 -44
  156. package/skills/wizard/agents/openai.yaml +0 -3
  157. package/skills/wizard/template.sh +0 -223
  158. package/skills/writing-for-agents/LICENSE +0 -21
  159. package/skills/writing-for-agents/SKILL-MECHANICS.md +0 -22
  160. package/skills/writing-for-agents/SKILL.md +0 -81
  161. 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,11 +1,12 @@
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',
@@ -25,6 +26,15 @@ const COMMANDS = new Map([
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,3 +1,4 @@
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
4
  import { parseArgs } from 'node:util';
@@ -8,23 +9,31 @@ import { forgetDisconnected, forgetOwnAgent, readDisconnected, readEnrolment, re
8
9
  import { callHouse, rpc } from './mcp.js';
9
10
  import { refusalOf } from './refusals.js';
10
11
  import { selectRelay } from './relay.js';
11
- import { startService } from './service.js';
12
+ import { startService } from './supervisor.js';
12
13
  import { placeSkillSet } from './skills.js';
14
+ import { endUnserved } from './wire.js';
13
15
  export const DEFAULT_HOUSE = 'https://agents.house';
14
16
  const OPENER = process.platform === 'darwin' ? 'open' : 'xdg-open';
15
17
  // Polling every two seconds brings the User's confirmation to the waiting Kit moments after they give it.
16
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
+ }
17
25
  function open(link) {
18
26
  spawn(OPENER, [link], { detached: true, stdio: 'ignore' })
19
27
  .on('error', () => undefined)
20
28
  .unref();
21
29
  }
22
- export async function accepted(house, credential) {
30
+ async function accepted(house, credential) {
23
31
  const checked = await callHouse(house, credential, rpc('tools/list', {}));
24
32
  if (checked.status === 200)
25
33
  return true;
26
34
  if (checked.status === 401)
27
35
  return false;
36
+ endUnserved(checked.text);
28
37
  throw new Error(`House answered ${checked.status} when Kit checked this computer's own agent's connection: ${checked.text}`);
29
38
  }
30
39
  const USAGE = `usage: kit login [--house <origin>] [--environment <id>] [--rooms <ref>[,<ref>...] | --no-private]
@@ -68,6 +77,21 @@ export async function login(argv) {
68
77
  process.stdout.write(USAGE);
69
78
  return;
70
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) {
71
95
  if (values.code !== undefined && values.rooms !== undefined)
72
96
  throw new Error('--code cannot be used with --rooms');
73
97
  if (values.code !== undefined && values['no-private'])
@@ -82,23 +106,23 @@ export async function login(argv) {
82
106
  const relay = process.env.HOUSE_KIT_RELAY || undefined;
83
107
  selectRelay(relay);
84
108
  const house = values.house ?? enrolled?.house ?? DEFAULT_HOUSE;
85
- const replaces = process.env.HOUSE_KIT_REPLACES;
86
- const remembered = replaces === undefined && values.environment === undefined && enrolled?.house === house ? enrolled.environment : undefined;
87
- const environment = replaces === undefined ? (values.environment ?? remembered) : undefined;
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
+ }
88
114
  const ownAgent = await readOwnAgent();
89
115
  let held = false;
90
116
  let named = environment;
91
117
  let exchanged;
92
118
  if (values.code !== undefined) {
93
- exchanged = await post(house, '/kit/token', { code: values.code });
119
+ exchanged = await pollLogin(house, { code: values.code });
94
120
  }
95
121
  else {
96
122
  held = ownAgent !== null && ownAgent.house === house && (await accepted(house, ownAgent.credential));
97
123
  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 }),
124
+ const start = () => retrying(() => startLogin(house, {
125
+ ...(named === undefined ? { act: 'new_environment' } : { act: 'existing_environment', environment_id: named }),
102
126
  ...rooms,
103
127
  code_challenge: createHash('sha256').update(verifier).digest('base64url'),
104
128
  ...(held ? {} : { headless: true }),
@@ -117,10 +141,8 @@ export async function login(argv) {
117
141
  }
118
142
  process.stdout.write(`Open this link and confirm: ${started.start_url}\n`);
119
143
  open(started.start_url);
120
- 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);
121
145
  }
122
- await placeSkillSet();
123
- await writeCodexRule().catch((error) => process.stderr.write(`kit: ${error.message}\n`));
124
146
  const relayRecord = relay === undefined ? {} : { relay };
125
147
  await writeEnrolment({
126
148
  house,
@@ -139,11 +161,5 @@ export async function login(argv) {
139
161
  else if (held && ownAgent !== null) {
140
162
  await writeOwnAgent({ house, ...relayRecord, user: ownAgent.user, credential: ownAgent.credential });
141
163
  }
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
- }
164
+ return house;
149
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))
package/dist/mcp.js CHANGED
@@ -1,8 +1,14 @@
1
+ import { KIT_WIRE, KIT_WIRE_HEADER } from '@agentshouse/kit-wire';
1
2
  import { randomUUID } from 'node:crypto';
2
3
  import { KIT_RELEASE } from './clis.js';
3
- import { relayed } from './relay.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
+ 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';
6
12
  export class Unsettled extends Error {
7
13
  }
8
14
  export function rpc(method, params) {
@@ -33,9 +39,40 @@ export async function callHouse(origin, credential, message, operation = null, s
33
39
  'mcp-protocol-version': MCP_PROTOCOL_VERSION,
34
40
  'mcp-method': message.method,
35
41
  ...(tool === null ? {} : { 'mcp-name': tool }),
42
+ [KIT_WIRE_HEADER]: KIT_WIRE,
36
43
  },
37
44
  body: mcpBody(message, operation),
38
45
  signal,
39
46
  });
40
47
  return { status: answer.status, text: await answer.text() };
41
48
  }
49
+ export function unconfirmed(status) {
50
+ return `House answered ${status} ${UNCONFIRMED}`;
51
+ }
52
+ export async function ownAgentCall(message) {
53
+ const ownAgent = await readOwnAgent();
54
+ if (ownAgent === null)
55
+ throw new Error(UNCONNECTED);
56
+ selectRelay(process.env.HOUSE_KIT_RELAY || ownAgent.relay);
57
+ const answer = await callHouse(ownAgent.house, ownAgent.credential, message).catch(() => {
58
+ throw new Unsettled(UNREACHABLE);
59
+ });
60
+ if (answer.status === 200)
61
+ return answer.text;
62
+ if (answer.status === 401)
63
+ throw new Error(DISCONNECTED);
64
+ const refusal = refusalOf(answer.text)?.text ?? unconfirmed(answer.status);
65
+ throw retryable(answer.text) === false ? new Error(refusal) : new Unsettled(refusal);
66
+ }
67
+ export function refusalIn(text, status) {
68
+ return refusalOf(text) ?? { code: '', text: text === '' ? `House refused it with ${status}` : text, conflicts: [], detail: {} };
69
+ }
70
+ export function toolAnswer(forwarded) {
71
+ if (forwarded.status !== 200)
72
+ return { refused: refusalIn(forwarded.text, forwarded.status) };
73
+ const answer = JSON.parse(forwarded.text);
74
+ if (answer.error !== undefined)
75
+ return { refused: refusalIn(answer.error.message, forwarded.status) };
76
+ const text = answer.result.content.map((content) => content.text).join('\n');
77
+ return answer.result.isError === true ? { refused: refusalIn(text, forwarded.status) } : { text };
78
+ }
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
+ }
package/dist/placement.js CHANGED
@@ -1,23 +1,6 @@
1
1
  import { readFileSync } from 'node:fs';
2
- import { join } from 'node:path';
3
- import { run } from './clis.js';
2
+ import { join, resolve } from 'node:path';
4
3
  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
4
  function recorded(name) {
22
5
  try {
23
6
  return readFileSync(join(kitHome(), name), 'utf8').trim();
@@ -31,9 +14,12 @@ function recorded(name) {
31
14
  export function installCommand() {
32
15
  return recorded('install-command');
33
16
  }
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';
17
+ export function placedPrefix() {
18
+ const prefix = process.env.HOUSE_KIT_PREFIX;
19
+ if (prefix === undefined || prefix === '')
20
+ throw new Error('this Kit process was not started by a launcher its installer placed');
21
+ return resolve(prefix);
22
+ }
23
+ export function releaseDirectory(release) {
24
+ return join(placedPrefix(), 'releases', release);
39
25
  }
package/dist/refusals.js CHANGED
@@ -1,53 +1,69 @@
1
1
  import { parse } from 'yaml';
2
2
  const HEAD = /^([a-z][a-z0-9_]*): \S/;
3
- function conflictCodes(detail) {
3
+ const PUSH_STOPS = new Set(['limit_reached', 'cap_reached']);
4
+ function detailOf(text) {
4
5
  let parsed;
5
6
  try {
6
- parsed = parse(detail);
7
+ parsed = parse(text);
7
8
  }
8
9
  catch {
9
- return [];
10
+ return {};
10
11
  }
11
- const conflicts = parsed?.conflicts;
12
- if (!Array.isArray(conflicts))
12
+ return typeof parsed === 'object' && parsed !== null && !Array.isArray(parsed) ? parsed : {};
13
+ }
14
+ function conflictsOf(detail) {
15
+ if (!Array.isArray(detail.conflicts))
13
16
  return [];
14
- return conflicts.flatMap((conflict) => typeof conflict?.code === 'string' ? [conflict.code] : []);
17
+ return detail.conflicts.flatMap((conflict) => typeof conflict?.code === 'string' ? [{ code: conflict.code, path: typeof conflict.path === 'string' ? conflict.path : '' }] : []);
15
18
  }
16
19
  function spoken(text) {
17
20
  const head = HEAD.exec(text);
18
21
  if (head === null)
19
22
  return null;
20
23
  const said = text.replace(/\n+$/, '');
21
- const detail = said.indexOf('\n');
22
- return { code: head[1], text: said, conflicts: detail === -1 ? [] : conflictCodes(said.slice(detail + 1)) };
24
+ const line = said.indexOf('\n');
25
+ const detail = line === -1 ? {} : detailOf(said.slice(line + 1));
26
+ return { code: head[1], text: said, conflicts: conflictsOf(detail), detail };
23
27
  }
24
- export function retryable(text) {
25
- let body;
28
+ export function stopsPush(refusal) {
29
+ return refusal !== null && PUSH_STOPS.has(refusal.code) && refusal.retryable === true;
30
+ }
31
+ export function firstLine(refusal) {
32
+ return refusal.text.split('\n')[0];
33
+ }
34
+ function parsed(text) {
26
35
  try {
27
- body = JSON.parse(text);
36
+ return { body: JSON.parse(text) };
28
37
  }
29
38
  catch {
30
39
  return null;
31
40
  }
41
+ }
42
+ function errorIn(body) {
32
43
  const error = body?.error;
44
+ return typeof error === 'object' && error !== null ? error : null;
45
+ }
46
+ function verdictOf(error) {
33
47
  const verdict = error?.retryable ?? error?.data?.retryable;
34
48
  return typeof verdict === 'boolean' ? verdict : null;
35
49
  }
50
+ export function retryable(text) {
51
+ const answer = parsed(text);
52
+ return answer === null ? null : verdictOf(errorIn(answer.body));
53
+ }
36
54
  export function refusalOf(text) {
37
- let body;
38
- try {
39
- body = JSON.parse(text);
40
- }
41
- catch {
55
+ const answer = parsed(text);
56
+ if (answer === null)
42
57
  return spoken(text);
43
- }
44
- const error = body?.error;
45
- if (typeof error !== 'object' || error === null)
58
+ const error = errorIn(answer.body);
59
+ if (error === null)
46
60
  return null;
47
61
  const { code, message, data } = error;
62
+ const verdict = verdictOf(error);
63
+ const judged = verdict === null ? {} : { retryable: verdict };
48
64
  const said = typeof message === 'string' ? spoken(message) : null;
49
65
  if (said !== null)
50
- return said;
66
+ return { ...said, ...judged };
51
67
  const named = typeof code === 'string' ? code : typeof data?.code === 'string' ? data.code : null;
52
- return named === null ? null : { code: named, text: named, conflicts: [] };
68
+ return named === null ? null : { code: named, text: named, conflicts: [], detail: {}, ...judged };
53
69
  }