@agentshouse/kit 0.2.1-alpha.8 → 0.2.1-c063e835a50ea

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 (116) hide show
  1. package/README.md +35 -11
  2. package/dist/abort.js +9 -0
  3. package/dist/acp.js +27 -7
  4. package/dist/agents.js +204 -52
  5. package/dist/api.js +6 -2
  6. package/dist/bootstrap.json +10 -14
  7. package/dist/bridge.js +90 -54
  8. package/dist/clis-main.js +23 -0
  9. package/dist/clis.js +102 -32
  10. package/dist/configure-main.js +6 -0
  11. package/dist/conversations.js +105 -26
  12. package/dist/copies.js +49 -39
  13. package/dist/files.js +2 -1
  14. package/dist/git-main.js +2 -2
  15. package/dist/git.js +6 -2
  16. package/dist/home.js +49 -7
  17. package/dist/house-main.js +96 -41
  18. package/dist/instructions.js +14 -13
  19. package/dist/kit-main.js +4 -1
  20. package/dist/login.js +24 -4
  21. package/dist/logout.js +18 -0
  22. package/dist/mcp.js +39 -0
  23. package/dist/operation.js +7 -4
  24. package/dist/refusals.js +41 -0
  25. package/dist/relay.js +10 -0
  26. package/dist/resident.js +36 -9
  27. package/dist/secret-input.js +4 -2
  28. package/dist/sign-in.js +17 -5
  29. package/dist/skills.js +78 -0
  30. package/dist/stream.js +4 -4
  31. package/dist/transcription.js +122 -0
  32. package/dist/update.js +117 -0
  33. package/how-we-work.md +23 -0
  34. package/package.json +7 -8
  35. package/skills/ask-matt/LICENSE +21 -0
  36. package/skills/ask-matt/PHASE-BOUNDARIES.md +55 -0
  37. package/skills/ask-matt/SKILL.md +91 -0
  38. package/skills/ask-matt/agents/openai.yaml +4 -0
  39. package/skills/code-review/LICENSE +21 -0
  40. package/skills/code-review/SKILL.md +89 -0
  41. package/skills/code-review/agents/openai.yaml +3 -0
  42. package/skills/codebase-design/DEEPENING.md +37 -0
  43. package/skills/codebase-design/DESIGN-IT-TWICE.md +44 -0
  44. package/skills/codebase-design/LICENSE +21 -0
  45. package/skills/codebase-design/SKILL.md +116 -0
  46. package/skills/codebase-design/agents/openai.yaml +3 -0
  47. package/skills/diagnosing-bugs/LICENSE +21 -0
  48. package/skills/diagnosing-bugs/SKILL.md +140 -0
  49. package/skills/diagnosing-bugs/agents/openai.yaml +3 -0
  50. package/skills/diagnosing-bugs/scripts/hitl-loop.template.sh +44 -0
  51. package/skills/domain-modeling/ADR-FORMAT.md +47 -0
  52. package/skills/domain-modeling/CONTEXT-FORMAT.md +60 -0
  53. package/skills/domain-modeling/LICENSE +21 -0
  54. package/skills/domain-modeling/SKILL.md +76 -0
  55. package/skills/domain-modeling/agents/openai.yaml +3 -0
  56. package/skills/grill-me/LICENSE +21 -0
  57. package/skills/grill-me/SKILL.md +8 -0
  58. package/skills/grill-me/agents/openai.yaml +4 -0
  59. package/skills/grill-with-docs/LICENSE +21 -0
  60. package/skills/grill-with-docs/SKILL.md +8 -0
  61. package/skills/grill-with-docs/agents/openai.yaml +4 -0
  62. package/skills/grilling/LICENSE +21 -0
  63. package/skills/grilling/SKILL.md +30 -0
  64. package/skills/grilling/agents/openai.yaml +3 -0
  65. package/skills/handoff/LICENSE +21 -0
  66. package/skills/handoff/SKILL.md +17 -0
  67. package/skills/handoff/agents/openai.yaml +4 -0
  68. package/skills/implement/LICENSE +21 -0
  69. package/skills/implement/SKILL.md +16 -0
  70. package/skills/implement/agents/openai.yaml +4 -0
  71. package/skills/improve-codebase-architecture/HTML-REPORT.md +123 -0
  72. package/skills/improve-codebase-architecture/LICENSE +21 -0
  73. package/skills/improve-codebase-architecture/SKILL.md +72 -0
  74. package/skills/improve-codebase-architecture/agents/openai.yaml +4 -0
  75. package/skills/prototype/LICENSE +21 -0
  76. package/skills/prototype/LOGIC.md +67 -0
  77. package/skills/prototype/SKILL.md +28 -0
  78. package/skills/prototype/UI.md +112 -0
  79. package/skills/prototype/agents/openai.yaml +3 -0
  80. package/skills/research/LICENSE +21 -0
  81. package/skills/research/SKILL.md +14 -0
  82. package/skills/research/agents/openai.yaml +3 -0
  83. package/skills/resolving-merge-conflicts/LICENSE +21 -0
  84. package/skills/resolving-merge-conflicts/SKILL.md +16 -0
  85. package/skills/resolving-merge-conflicts/agents/openai.yaml +3 -0
  86. package/skills/tdd/LICENSE +21 -0
  87. package/skills/tdd/SKILL.md +40 -0
  88. package/skills/tdd/agents/openai.yaml +3 -0
  89. package/skills/tdd/mocking.md +59 -0
  90. package/skills/tdd/tests.md +77 -0
  91. package/skills/teach/GLOSSARY-FORMAT.md +35 -0
  92. package/skills/teach/LEARNING-RECORD-FORMAT.md +46 -0
  93. package/skills/teach/LICENSE +21 -0
  94. package/skills/teach/MISSION-FORMAT.md +31 -0
  95. package/skills/teach/RESOURCES-FORMAT.md +32 -0
  96. package/skills/teach/SKILL.md +141 -0
  97. package/skills/teach/agents/openai.yaml +4 -0
  98. package/skills/to-questionnaire/LICENSE +21 -0
  99. package/skills/to-questionnaire/SKILL.md +55 -0
  100. package/skills/to-questionnaire/agents/openai.yaml +4 -0
  101. package/skills/to-spec/LICENSE +21 -0
  102. package/skills/to-spec/SKILL.md +76 -0
  103. package/skills/to-spec/agents/openai.yaml +4 -0
  104. package/skills/to-tickets/LICENSE +21 -0
  105. package/skills/to-tickets/SKILL.md +106 -0
  106. package/skills/to-tickets/agents/openai.yaml +4 -0
  107. package/skills/wait-what/LICENSE +21 -0
  108. package/skills/wait-what/SKILL.md +8 -0
  109. package/skills/wait-what/agents/openai.yaml +4 -0
  110. package/skills/wayfinder/LICENSE +21 -0
  111. package/skills/wayfinder/SKILL.md +129 -0
  112. package/skills/wayfinder/agents/openai.yaml +4 -0
  113. package/skills/writing-for-agents/LICENSE +21 -0
  114. package/skills/writing-for-agents/SKILL-MECHANICS.md +22 -0
  115. package/skills/writing-for-agents/SKILL.md +83 -0
  116. package/skills/writing-for-agents/agents/openai.yaml +3 -0
package/dist/bridge.js CHANGED
@@ -1,17 +1,21 @@
1
1
  import { createHash, randomUUID } from 'node:crypto';
2
2
  import { once } from 'node:events';
3
+ import { setTimeout as delay } from 'node:timers/promises';
3
4
  import { mkdir } from 'node:fs/promises';
4
5
  import { createServer, request as httpRequest } from 'node:http';
5
6
  import { request as httpsRequest } from 'node:https';
6
- import { delimiter, join } from 'node:path';
7
+ import { delimiter, dirname, join } from 'node:path';
7
8
  import { parse } from 'yaml';
8
- import { KIT_VERSION } from './clis.js';
9
- import { changedPaths, refusalCode, } from './copies.js';
9
+ import { HouseRefusal, retryDelay } from './api.js';
10
+ import { loginPath } from './clis.js';
11
+ import { changedPaths, } from './copies.js';
10
12
  import { kitHome, readEnrolment } from './home.js';
11
- import { operationId } from './operation.js';
12
- const MCP_PROTOCOL_VERSION = '2026-07-28';
13
+ import { callHouse, mcpBody, rpc, UNREACHABLE } from './mcp.js';
14
+ import { operationId, uuidOf } from './operation.js';
15
+ import { refusalOf } from './refusals.js';
16
+ import { relayed } from './relay.js';
13
17
  const MCP_REQUEST_BYTES = 4 * 1024 * 1024;
14
- const FORWARDED = new Set(['/', '/kit/attachments/upload']);
18
+ const ATTACHMENTS = '/kit/attachments/upload';
15
19
  export async function received(request) {
16
20
  let text = '';
17
21
  request.setEncoding('utf8');
@@ -19,7 +23,8 @@ export async function received(request) {
19
23
  text += chunk;
20
24
  return text;
21
25
  }
22
- function relay(request, response, target, authorization) {
26
+ function relay(request, response, house, authorization) {
27
+ const target = relayed(house);
23
28
  const send = target.protocol === 'https:' ? httpsRequest : httpRequest;
24
29
  const forwarded = send(target, {
25
30
  method: request.method,
@@ -31,16 +36,44 @@ function relay(request, response, target, authorization) {
31
36
  forwarded.on('error', () => response.destroy());
32
37
  request.pipe(forwarded);
33
38
  }
39
+ function refusalIn(text, status) {
40
+ return refusalOf(text) ?? { code: '', text: text === '' ? `House refused it with ${status}` : text, conflicts: [] };
41
+ }
34
42
  function answered(forwarded) {
35
43
  if (forwarded.status >= 500)
36
- throw new Error(`House answered ${forwarded.status}`);
44
+ throw new HouseRefusal('/', forwarded.status, forwarded.text);
37
45
  if (forwarded.status !== 200)
38
- return { refused: { code: refusalCode(forwarded.text), text: forwarded.text } };
46
+ return { refused: refusalIn(forwarded.text, forwarded.status) };
39
47
  const answer = JSON.parse(forwarded.text);
40
48
  if (answer.error !== undefined)
41
- return { refused: { code: refusalCode(answer.error.message), text: answer.error.message } };
49
+ return { refused: refusalIn(answer.error.message, forwarded.status) };
42
50
  const text = answer.result.content.map((content) => content.text).join('\n');
43
- return answer.result.isError === true ? { refused: { code: refusalCode(text), text } } : { text };
51
+ return answer.result.isError === true ? { refused: refusalIn(text, forwarded.status) } : { text };
52
+ }
53
+ function pendingSeconds(forwarded) {
54
+ if (forwarded.status !== 200)
55
+ return null;
56
+ const { result } = JSON.parse(forwarded.text);
57
+ if (result === undefined || result.isError === true)
58
+ return null;
59
+ const text = result.content.map((content) => content.text).join('\n');
60
+ if (!text.startsWith('{"pending":'))
61
+ return null;
62
+ const seconds = JSON.parse(text).pending.retry_after;
63
+ return typeof seconds === 'number' ? seconds : null;
64
+ }
65
+ function resendAfter(forwarded, attempt) {
66
+ if (forwarded === null)
67
+ return retryDelay(attempt);
68
+ if (forwarded.status >= 500)
69
+ return refusalOf(forwarded.text) === null ? retryDelay(attempt) : null;
70
+ const seconds = pendingSeconds(forwarded);
71
+ return seconds === null ? null : seconds * 1000;
72
+ }
73
+ function versioned(conversationId, text) {
74
+ const file = JSON.parse(text);
75
+ const identity = JSON.stringify([conversationId, file.room_ref ?? null, file.name, file.sha256]);
76
+ return JSON.stringify({ ...file, version: uuidOf(createHash('sha256').update(identity).digest(), 8) });
44
77
  }
45
78
  function editAnswer(forwarded) {
46
79
  const answer = answered(forwarded);
@@ -50,44 +83,32 @@ function editAnswer(forwarded) {
50
83
  return {
51
84
  accepted: results.flatMap((result) => [
52
85
  ...(result.from === undefined ? [] : [{ path: result.from, revision: null, content: null }]),
53
- { path: result.path, revision: result.op === 'remove' ? null : result.revision },
86
+ { path: result.path, revision: result.revision ?? null },
54
87
  ]),
55
88
  };
56
89
  }
57
90
  export async function openBridge(house, copies, conversationId, signal) {
91
+ const path = [join(kitHome(), 'shim'), dirname(process.execPath), await loginPath()].join(delimiter);
58
92
  const origin = (await readEnrolment()).house;
59
93
  const { credential } = await house.post(`/kit/conversations/${conversationId}/credential`, {}, signal);
60
94
  const closed = new AbortController();
61
- const body = (message, operation) => JSON.stringify({
62
- ...message,
63
- params: {
64
- ...message.params,
65
- _meta: {
66
- 'io.modelcontextprotocol/protocolVersion': MCP_PROTOCOL_VERSION,
67
- 'io.modelcontextprotocol/clientInfo': { name: '@agentshouse/kit', version: KIT_VERSION },
68
- 'io.modelcontextprotocol/clientCapabilities': {},
69
- ...(operation === null ? {} : { 'agents.house/agent-operation': operation }),
70
- },
71
- },
72
- });
95
+ const sent = (message, operation) => callHouse(origin, credential, message, operation, closed.signal);
73
96
  const send = async (message, operation) => {
74
- const tool = message.method === 'tools/call' ? String(message.params?.name) : null;
75
- const answer = await fetch(new URL('/', origin), {
76
- method: 'POST',
77
- headers: {
78
- 'content-type': 'application/json',
79
- authorization: `Bearer ${credential}`,
80
- accept: 'application/json, text/event-stream',
81
- 'mcp-protocol-version': MCP_PROTOCOL_VERSION,
82
- 'mcp-method': message.method,
83
- ...(tool === null ? {} : { 'mcp-name': tool }),
84
- },
85
- body: body(message, operation),
86
- signal: closed.signal,
87
- });
88
- return { status: answer.status, text: await answer.text() };
97
+ if (operation === null)
98
+ return sent(message, null);
99
+ for (let attempt = 0;; attempt++) {
100
+ const forwarded = await sent(message, operation).catch((error) => {
101
+ if (closed.signal.aborted)
102
+ throw error;
103
+ return null;
104
+ });
105
+ const after = resendAfter(forwarded, attempt);
106
+ if (after === null)
107
+ return forwarded;
108
+ await delay(after, undefined, { signal: closed.signal });
109
+ }
89
110
  };
90
- const call = (name, args) => ({ jsonrpc: '2.0', id: 1, method: 'tools/call', params: { name, arguments: args } });
111
+ const call = (name, args) => rpc('tools/call', { name, arguments: args });
91
112
  const staged = async (operation, changes) => {
92
113
  const bytes = Buffer.from(JSON.stringify({ changes }));
93
114
  const sha256 = createHash('sha256').update(bytes).digest('hex');
@@ -98,7 +119,7 @@ export async function openBridge(house, copies, conversationId, signal) {
98
119
  if ('refused' in prepared)
99
120
  return prepared;
100
121
  const { transfer } = parse(prepared.text);
101
- const posted = await fetch(transfer.url, {
122
+ const posted = await fetch(relayed(transfer.url), {
102
123
  method: 'POST',
103
124
  headers: { 'content-type': 'text/plain; charset=utf-8' },
104
125
  body: Buffer.concat([Buffer.from(`${transfer.operation}\n`), bytes]),
@@ -106,24 +127,35 @@ export async function openBridge(house, copies, conversationId, signal) {
106
127
  });
107
128
  const text = await posted.text();
108
129
  if (posted.status >= 500)
109
- throw new Error(`House answered ${posted.status}`);
130
+ throw new HouseRefusal('/', posted.status, text);
110
131
  if (!posted.ok)
111
- return { refused: { code: refusalCode(text), text } };
132
+ return { refused: refusalIn(text, posted.status) };
112
133
  const held = JSON.parse(text).transfer;
113
134
  return { url: held.url, operation: held.operation, bytes: bytes.length, sha256 };
114
135
  };
136
+ let mutations = null;
137
+ const writes = async (tool) => {
138
+ mutations ??= house
139
+ .post('/kit/tools/mutations', {}, closed.signal)
140
+ .then(({ tools }) => new Set(tools.filter((listed) => listed.writes).map((listed) => listed.name)));
141
+ try {
142
+ return (await mutations).has(tool);
143
+ }
144
+ catch (error) {
145
+ mutations = null;
146
+ throw error;
147
+ }
148
+ };
115
149
  const forward = async (path, text) => {
116
150
  if (path === '/') {
117
151
  const message = JSON.parse(text);
118
- const tool = message.method === 'tools/call' ? String(message.params?.name) : null;
119
- const writes = tool !== null &&
120
- (await house.post('/kit/tools/mutations', {}, closed.signal)).tools.some((listed) => listed.name === tool && listed.writes);
121
- return send(message, writes ? operationId() : null);
152
+ const tool = message.method === 'tools/call' ? String(message.params.name) : null;
153
+ return send(message, tool !== null && (await writes(tool)) ? operationId() : null);
122
154
  }
123
- const answer = await fetch(new URL(path, origin), {
155
+ const answer = await fetch(relayed(new URL(path, origin)), {
124
156
  method: 'POST',
125
157
  headers: { 'content-type': 'application/json', authorization: `Bearer ${credential}` },
126
- body: text,
158
+ body: versioned(conversationId, text),
127
159
  signal: closed.signal,
128
160
  });
129
161
  return { status: answer.status, text: await answer.text() };
@@ -133,7 +165,7 @@ export async function openBridge(house, copies, conversationId, signal) {
133
165
  submit: async (operation, changes, held, retain) => {
134
166
  const inline = call('edit', { changes });
135
167
  let upload = held;
136
- if (upload === undefined && Buffer.byteLength(body(inline, operation)) > MCP_REQUEST_BYTES) {
168
+ if (upload === undefined && Buffer.byteLength(mcpBody(inline, operation)) > MCP_REQUEST_BYTES) {
137
169
  const prepared = await staged(operation, changes);
138
170
  if ('refused' in prepared)
139
171
  return prepared;
@@ -152,7 +184,7 @@ export async function openBridge(house, copies, conversationId, signal) {
152
184
  await copies.observed(JSON.parse(text));
153
185
  return { status: 200, text: '{}' };
154
186
  }
155
- return FORWARDED.has(path) ? forward(path, text) : { status: 404, text: '' };
187
+ return path === '/' || path === ATTACHMENTS ? forward(path, text) : { status: 404, text: '' };
156
188
  };
157
189
  const sockets = join(kitHome(), 'bridges');
158
190
  await mkdir(sockets, { recursive: true, mode: 0o700 });
@@ -168,7 +200,11 @@ export async function openBridge(house, copies, conversationId, signal) {
168
200
  response.writeHead(answered.status, { 'content-type': 'application/json' }).end(answered.text);
169
201
  }
170
202
  catch (error) {
171
- response.writeHead(502).end(error instanceof Error ? error.message : String(error));
203
+ if (error instanceof HouseRefusal) {
204
+ response.writeHead(error.status, { 'content-type': 'application/json' }).end(error.text);
205
+ return;
206
+ }
207
+ response.writeHead(502).end(request.url === '/git/push' && error instanceof Error ? error.message : UNREACHABLE);
172
208
  }
173
209
  });
174
210
  bridge.listen(socketPath);
@@ -189,13 +225,13 @@ export async function openBridge(house, copies, conversationId, signal) {
189
225
  return {
190
226
  env: {
191
227
  HOUSE_BRIDGE: socketPath,
192
- PATH: `${join(kitHome(), 'shim')}${delimiter}${process.env.PATH ?? ''}`,
228
+ PATH: path,
193
229
  GIT_CONFIG_COUNT: '1',
194
230
  GIT_CONFIG_KEY_0: `url.${proxy}/app/.insteadOf`,
195
231
  GIT_CONFIG_VALUE_0: app,
196
232
  },
197
233
  tool: async (name, args) => {
198
- const forwarded = await forward('/', JSON.stringify({ jsonrpc: '2.0', id: 1, method: 'tools/call', params: { name, arguments: args } }));
234
+ const forwarded = await forward('/', JSON.stringify(call(name, args)));
199
235
  if (forwarded.status !== 200)
200
236
  throw new Error(`House refused ${name} with ${forwarded.status}: ${forwarded.text}`);
201
237
  const answer = JSON.parse(forwarded.text);
@@ -0,0 +1,23 @@
1
+ import { setGlobalProxyFromEnv } from 'node:http';
2
+ import { post } from './api.js';
3
+ import { CLIS, below, locate, versionOf } from './clis.js';
4
+ import { readEnrolment } from './home.js';
5
+ setGlobalProxyFromEnv();
6
+ try {
7
+ const { house, credential } = (await readEnrolment());
8
+ const { agents } = await post(house, '/kit/agents/desired', {}, credential);
9
+ for (const kind of agents) {
10
+ const cli = await locate(kind);
11
+ if (cli === null)
12
+ continue;
13
+ const release = await versionOf(cli);
14
+ if (release === null)
15
+ continue;
16
+ const { bin, minimum } = CLIS[kind];
17
+ process.stdout.write(`${[bin, cli, release, minimum, below(release, minimum) ? 'old' : 'current'].join('\t')}\n`);
18
+ }
19
+ }
20
+ catch (error) {
21
+ process.stderr.write(`kit: ${error.message}\n`);
22
+ process.exitCode = 1;
23
+ }
package/dist/clis.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { spawn } from 'node:child_process';
2
2
  import { readFileSync } from 'node:fs';
3
3
  import { readFile } from 'node:fs/promises';
4
+ import { userInfo } from 'node:os';
4
5
  import { join } from 'node:path';
5
6
  import { kitHome } from './home.js';
6
7
  const RUNNING_JOB = new Set(['running', 'paused']);
@@ -20,34 +21,55 @@ function asyncTask({ method, params }) {
20
21
  }
21
22
  return null;
22
23
  }
24
+ function airPhase({ _meta }) {
25
+ const phase = _meta?.jetbrains?.air?.phase;
26
+ if (phase === 'commentary')
27
+ return 'note';
28
+ if (phase === 'final_answer')
29
+ return 'answer';
30
+ return null;
31
+ }
23
32
  export const CLIS = {
24
33
  'codex-acp': {
25
- package: '@agentclientprotocol/codex-acp',
26
- bin: 'codex-acp',
34
+ bin: 'codex',
35
+ minimum: '0.159.1',
36
+ install: 'curl -fsSL https://chatgpt.com/codex/install.sh | sh',
37
+ adapter: { package: '@agentclientprotocol/codex-acp', bin: 'codex-acp', executable: 'CODEX_PATH', env: {} },
27
38
  args: [],
28
- signedIn: { command: ['cli', 'login', 'status'] },
29
- login: { args: ['cli', 'login', '--device-auth'], code: 'show' },
39
+ signedIn: { command: ['login', 'status'] },
40
+ login: { args: ['login', '--device-auth'], code: 'show' },
30
41
  queues: false,
31
42
  turnStarted: (notice) => threadStatus(notice) === 'active',
32
43
  turnEnded: (notice) => threadStatus(notice) === 'idle',
33
44
  job: asyncTask,
45
+ phase: airPhase,
34
46
  },
35
47
  'claude-agent-acp': {
36
- package: '@agentclientprotocol/claude-agent-acp',
37
- bin: 'claude-agent-acp',
48
+ bin: 'claude',
49
+ minimum: '2.1.286',
50
+ install: 'curl -fsSL https://claude.ai/install.sh | bash',
51
+ adapter: {
52
+ package: '@agentclientprotocol/claude-agent-acp',
53
+ bin: 'claude-agent-acp',
54
+ executable: 'CLAUDE_CODE_EXECUTABLE',
55
+ env: { CLAUDE_CODE_ENTRYPOINT: 'claude-agent-acp' },
56
+ },
38
57
  args: [],
39
- signedIn: { command: ['--cli', 'auth', 'status'] },
40
- login: { args: ['--cli', 'auth', 'login', '--claudeai'], code: 'collect' },
58
+ signedIn: { command: ['auth', 'status'] },
59
+ login: { args: ['auth', 'login', '--claudeai'], code: 'collect', rejected: 'Invalid code' },
41
60
  queues: false,
42
61
  turnStarted: () => false,
43
62
  turnEnded: ({ method, params }) => method === 'session/update' &&
44
63
  params?.update?.sessionUpdate === 'usage_update' &&
45
64
  params.update._meta?.['_claude/origin'] !== undefined,
46
65
  job: asyncTask,
66
+ phase: () => null,
47
67
  },
48
68
  'grok-build': {
49
- package: '@xai-official/grok',
50
69
  bin: 'grok',
70
+ minimum: '1.0.46',
71
+ install: 'curl -fsSL https://x.ai/cli/install.sh | bash',
72
+ adapter: null,
51
73
  args: ['agent', '--no-leader', 'stdio'],
52
74
  signedIn: { initializeMeta: 'defaultAuthMethodId' },
53
75
  login: { args: ['login', '--device-auth'], code: 'show' },
@@ -61,23 +83,25 @@ export const CLIS = {
61
83
  return { id: params.update.task_snapshot.task_id, running: false };
62
84
  return null;
63
85
  },
86
+ phase: () => null,
64
87
  },
65
88
  };
66
89
  const KIT_PACKAGE = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
67
90
  export const KIT_VERSION = KIT_PACKAGE.version;
68
91
  const PROXY = /^https?_proxy$/i;
69
- export function pinned(kind) {
70
- return KIT_PACKAGE.peerDependencies[CLIS[kind].package];
71
- }
92
+ const VERSION = /\d+\.\d+\.\d+(?:-[0-9A-Za-z.]+)?/;
93
+ const INSTALL_MS = 15 * 60_000;
94
+ const READ_MS = 30_000;
95
+ const CAUSE_CHARACTERS = 4000;
72
96
  function prefix(kind) {
73
97
  return join(kitHome(), 'agents', kind);
74
98
  }
75
- export function cliCommand(kind) {
76
- return join(prefix(kind), 'node_modules', '.bin', CLIS[kind].bin);
99
+ export function adapterCommand(kind) {
100
+ return join(prefix(kind), 'node_modules', '.bin', CLIS[kind].adapter.bin);
77
101
  }
78
- export async function installedRelease(kind) {
102
+ async function installedAdapter(kind) {
79
103
  try {
80
- const manifest = join(prefix(kind), 'node_modules', CLIS[kind].package, 'package.json');
104
+ const manifest = join(prefix(kind), 'node_modules', CLIS[kind].adapter.package, 'package.json');
81
105
  return JSON.parse(await readFile(manifest, 'utf8')).version;
82
106
  }
83
107
  catch {
@@ -87,28 +111,74 @@ export async function installedRelease(kind) {
87
111
  export function withoutProxy() {
88
112
  return Object.fromEntries(Object.entries(process.env).filter(([name]) => !PROXY.test(name)));
89
113
  }
90
- export function run(command, args, timeoutMs) {
114
+ export function run(command, args, timeoutMs, detached = false, signal) {
91
115
  return new Promise((resolve) => {
92
- const child = spawn(command, args, { stdio: ['ignore', 'pipe', 'pipe'], timeout: timeoutMs, env: withoutProxy() });
116
+ const child = spawn(command, args, {
117
+ stdio: ['ignore', 'pipe', 'pipe'],
118
+ timeout: timeoutMs,
119
+ env: withoutProxy(),
120
+ detached,
121
+ signal,
122
+ });
123
+ let stdout = '';
93
124
  let output = '';
94
- child.stdout.on('data', (chunk) => {
95
- output += chunk.toString('utf8');
125
+ child.stdout.setEncoding('utf8').on('data', (chunk) => {
126
+ stdout += chunk;
127
+ output += chunk;
96
128
  });
97
- child.stderr.on('data', (chunk) => {
98
- output += chunk.toString('utf8');
129
+ child.stderr.setEncoding('utf8').on('data', (chunk) => {
130
+ output += chunk;
99
131
  });
100
- child.on('error', (error) => resolve({ status: null, output: error.message }));
101
- child.on('close', (status) => resolve({ status, output }));
132
+ child.on('error', (error) => resolve({ status: null, stdout, output: error.message }));
133
+ child.on('close', (status) => resolve({ status, stdout, output }));
102
134
  });
103
135
  }
104
- export async function install(kind) {
105
- const release = pinned(kind);
106
- if ((await installedRelease(kind)) === release)
107
- return release;
108
- const ran = await run('npm', ['install', '--prefix', prefix(kind), '--no-save', '--no-audit', '--no-fund', `${CLIS[kind].package}@${release}`], 15 * 60_000);
109
- if (ran.status !== 0) {
110
- process.stderr.write(`kit: ${kind} did not install: ${ran.output.trim()}\n`);
136
+ export function failureOf(ran, program) {
137
+ return ran.output.trim().slice(-CAUSE_CHARACTERS) || `${program} exited with ${ran.status ?? 'a signal'}`;
138
+ }
139
+ export async function installAdapter(kind) {
140
+ const adapter = CLIS[kind].adapter;
141
+ if (adapter === null)
142
+ return null;
143
+ const release = KIT_PACKAGE.peerDependencies[adapter.package];
144
+ if ((await installedAdapter(kind)) === release)
111
145
  return null;
146
+ const ran = await run('npm', ['install', '--prefix', prefix(kind), '--no-save', '--no-audit', '--no-fund', '--omit=optional', `${adapter.package}@${release}`], INSTALL_MS);
147
+ return ran.status === 0 ? null : failureOf(ran, 'npm');
148
+ }
149
+ export async function installCli(kind) {
150
+ const ran = await run('bash', ['-o', 'pipefail', '-c', CLIS[kind].install], INSTALL_MS, true);
151
+ return ran.status === 0 ? null : failureOf(ran, 'the install');
152
+ }
153
+ function loginShell() {
154
+ return process.env.SHELL || userInfo().shell;
155
+ }
156
+ const FOUND = 'house-kit-cli ';
157
+ const LOOKUP = `found=$(command -v "$1") || exit 0; case $found in /*) ;; *) found=$(pwd -P)/$found ;; esac; printf "${FOUND}%s\\n" "$found"`;
158
+ const USER_BIN = 'case ":$PATH:" in *":$HOME/.local/bin:"*) ;; *) PATH="$PATH:$HOME/.local/bin" ;; esac; export PATH';
159
+ function inLoginShell(script, argument = '') {
160
+ return run(loginShell(), ['-l', '-i', '-c', `exec /bin/sh -c '${USER_BIN}; ${script}' sh ${argument}`], READ_MS, true);
161
+ }
162
+ export async function locate(kind) {
163
+ const ran = await inLoginShell(LOOKUP, CLIS[kind].bin);
164
+ return ran.stdout.split('\n').findLast((line) => line.startsWith(FOUND))?.slice(FOUND.length) ?? null;
165
+ }
166
+ export async function loginPath() {
167
+ const marker = 'house-kit-path ';
168
+ const ran = await inLoginShell(`printf "${marker}%s\\n" "$PATH"`);
169
+ return ran.stdout.split('\n').findLast((line) => line.startsWith(marker)).slice(marker.length);
170
+ }
171
+ export async function versionOf(path) {
172
+ return VERSION.exec((await run(path, ['--version'], READ_MS)).stdout)?.[0] ?? null;
173
+ }
174
+ function numbers(version) {
175
+ return version.split(/[.-]/, 3).map(Number);
176
+ }
177
+ export function below(found, minimum) {
178
+ const [have, need] = [numbers(found), numbers(minimum)];
179
+ for (let index = 0; index < 3; index++) {
180
+ if (have[index] !== need[index])
181
+ return have[index] < need[index];
112
182
  }
113
- return installedRelease(kind);
183
+ return found.includes('-') && !minimum.includes('-');
114
184
  }
@@ -0,0 +1,6 @@
1
+ import { readConfiguration, writeConfiguration } from './home.js';
2
+ const skills = !process.argv.slice(2).includes('--no-skills');
3
+ const stored = await readConfiguration();
4
+ await writeConfiguration({ skills });
5
+ if (stored.skills !== skills)
6
+ process.stdout.write('changed\n');