@agentshouse/kit 0.2.1-ccf188e02985d → 0.2.1-ccffb3f637815

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 +37 -41
  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 +89 -0
  7. package/dist/bridge.js +29 -28
  8. package/dist/building.js +50 -0
  9. package/dist/calls.js +88 -0
  10. package/dist/chunks.js +49 -0
  11. package/dist/clis.js +62 -50
  12. package/dist/connect.js +108 -0
  13. package/dist/connection.js +120 -0
  14. package/dist/content.js +106 -0
  15. package/dist/conversations.js +594 -219
  16. package/dist/copies.js +772 -279
  17. package/dist/earlier.js +263 -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-main.js +24 -29
  22. package/dist/git.js +90 -15
  23. package/dist/grok.js +39 -0
  24. package/dist/home.js +80 -29
  25. package/dist/house-cli.js +155 -164
  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 +18 -8
  30. package/dist/kit-main.js +3 -3
  31. package/dist/login.js +36 -22
  32. package/dist/logout.js +2 -2
  33. package/dist/mcp.js +42 -3
  34. package/dist/old-references.js +27 -0
  35. package/dist/owner.js +46 -0
  36. package/dist/placement.js +15 -20
  37. package/dist/refusals.js +37 -21
  38. package/dist/relay.js +21 -0
  39. package/dist/resident.js +128 -82
  40. package/dist/scope.js +15 -4
  41. package/dist/scripts.js +303 -0
  42. package/dist/secret-input.js +1 -1
  43. package/dist/settings.js +188 -0
  44. package/dist/sign-in.js +67 -21
  45. package/dist/silence.js +28 -0
  46. package/dist/skills.js +42 -97
  47. package/dist/supervisor.js +163 -0
  48. package/dist/transcription.js +88 -45
  49. package/dist/translate.js +19 -18
  50. package/dist/update.js +118 -120
  51. package/dist/wire.js +30 -4
  52. package/dist/work.js +27 -2
  53. package/dist/workspace.js +103 -0
  54. package/package.json +26 -22
  55. package/dist/authority-main.js +0 -22
  56. package/dist/bootstrap.json +0 -24
  57. package/dist/chatgpt.js +0 -32
  58. package/dist/clis-main.js +0 -23
  59. package/dist/configure-main.js +0 -6
  60. package/dist/enrol-main.js +0 -10
  61. package/dist/inputs.js +0 -37
  62. package/dist/parts.js +0 -82
  63. package/dist/service-main.js +0 -9
  64. package/dist/service.js +0 -55
  65. package/dist/stream.js +0 -123
  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
@@ -1,12 +1,30 @@
1
- import { HOUSE_REF } from './git.js';
2
- import { readHowWeWork } from './skills.js';
3
- const SOURCE_LINE = "From House:";
4
- const HOUSE_LINE = "Work with House through the `house` CLI: run `house --help`, and `house find_command` for House's guides and formats.";
5
- const FILE_LINE = 'To give the User a file, upload it with `house upload` and link it; for an App, a Site or a website, follow `house find_command \'{"query":"app"}\'`. Never start a server.';
6
- const READ_LINE = "Optional per-Room instructions: `/rooms/private/rooms/<handle>/AGENTS.md`.";
7
- const WAIT_LINE = 'To get what another Agent will write into a Room, `create_trigger` on where it will land with a `conversation` action, then end your turn: this conversation continues when it lands.';
8
- const COPIES_LINE = `House Local copies; before work run \`house fetch\` and rebase onto \`${HOUSE_REF}\`; after it commit, then \`house push\`:`;
9
- export async function instructions(bridge, base, copies) {
10
- const lines = [SOURCE_LINE, HOUSE_LINE, FILE_LINE, READ_LINE, WAIT_LINE, ...(copies.length === 0 ? [] : [COPIES_LINE, ...copies])];
11
- return [lines.join('\n'), base, (await readHowWeWork(bridge)).replace(/\n$/, '')].filter((part) => part !== '').join('\n\n');
1
+ import { agentInstructions } from '@agentshouse/skills';
2
+ const OWNER_RULES = '/rooms/private/owner-rules.md';
3
+ const UNREADABLE = /^(?:\S+: )?(?:path_not_found|room_not_found|operation_denied)\b/;
4
+ const FAILED = /^exit: [1-9]\d*$/;
5
+ const CUT = /^stderr: shell: output_cut (\d+) of \d+ bytes; continue with: (.+)$/;
6
+ function cutOf(lines) {
7
+ const cut = CUT.exec(lines[0] ?? '');
8
+ return cut !== null && Buffer.byteLength(lines.slice(1).join('\n')) === Number(cut[1]) ? cut : null;
9
+ }
10
+ async function readOwnerRules(bridge) {
11
+ let document = '';
12
+ for (let command = `cat ${OWNER_RULES}`; command !== undefined;) {
13
+ const read = await bridge.tool('shell', { command });
14
+ const text = read.content.map((content) => content.text).join('\n');
15
+ const lines = text.split('\n');
16
+ if (read.isError === true || (FAILED.test(lines[0] ?? '') && lines[1]?.startsWith('stderr: '))) {
17
+ const refusal = read.isError === true ? text : lines.slice(1).join('\n').replace(/^stderr: /gm, '');
18
+ if (UNREADABLE.test(refusal))
19
+ return '';
20
+ throw new Error(refusal);
21
+ }
22
+ const cut = cutOf(lines);
23
+ document += lines.slice(cut === null ? 0 : 1).join('\n');
24
+ command = cut?.[2];
25
+ }
26
+ return document;
27
+ }
28
+ export async function instructions(bridge, base) {
29
+ return [agentInstructions().join('\n'), base, (await readOwnerRules(bridge)).replace(/\n$/, '')].filter((part) => part !== '').join('\n\n');
12
30
  }
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))
package/dist/mcp.js CHANGED
@@ -1,8 +1,16 @@
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
+ 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
  }
@@ -13,7 +21,7 @@ export function mcpBody(message, operation) {
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': {},
18
26
  ...(operation === null ? {} : { 'agents.house/agent-operation': operation }),
19
27
  },
@@ -31,9 +39,40 @@ export async function callHouse(origin, credential, message, operation = null, s
31
39
  'mcp-protocol-version': MCP_PROTOCOL_VERSION,
32
40
  'mcp-method': message.method,
33
41
  ...(tool === null ? {} : { 'mcp-name': tool }),
42
+ [KIT_WIRE_HEADER]: KIT_WIRE,
34
43
  },
35
44
  body: mcpBody(message, operation),
36
45
  signal,
37
46
  });
38
47
  return { status: answer.status, text: await answer.text() };
39
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
+ }
@@ -0,0 +1,27 @@
1
+ import { ATTACHMENT_REFERENCE_PREFIX, DOCUMENT_REFERENCE_PREFIX, REVISION_REFERENCE_PREFIX } from '@agentshouse/mdmodel';
2
+ import { isDocument } from './binaries.js';
3
+ const OLD_REVISION = 'fr_';
4
+ const OLD_ENTRY = 'af_';
5
+ const REVISION_BASES = new Set(['replace', 'remove', 'rename', 'upload']);
6
+ function renamed(value, path) {
7
+ if (value?.startsWith(OLD_REVISION))
8
+ return `${REVISION_REFERENCE_PREFIX}${value.slice(OLD_REVISION.length)}`;
9
+ if (value?.startsWith(OLD_ENTRY)) {
10
+ return `${isDocument(path) ? DOCUMENT_REFERENCE_PREFIX : ATTACHMENT_REFERENCE_PREFIX}${value.slice(OLD_ENTRY.length)}`;
11
+ }
12
+ return value;
13
+ }
14
+ export function renameOldReferences(record) {
15
+ const held = JSON.stringify(record);
16
+ for (const manifest of Object.values(record.manifests ?? {})) {
17
+ for (const [path, revision] of Object.entries(manifest.files))
18
+ manifest.files[path] = renamed(revision, path);
19
+ }
20
+ for (const change of record.push?.changes ?? []) {
21
+ if (REVISION_BASES.has(change.op) && typeof change.base === 'string')
22
+ change.base = renamed(change.base, change.path);
23
+ }
24
+ for (const written of record.push?.written ?? [])
25
+ written.revision = renamed(written.revision, written.path);
26
+ return JSON.stringify(record) !== held;
27
+ }
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
+ }