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

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 (57) hide show
  1. package/README.md +49 -24
  2. package/dist/abort.js +9 -0
  3. package/dist/acp.js +102 -88
  4. package/dist/agents.js +356 -52
  5. package/dist/api.js +40 -4
  6. package/dist/app-git.js +48 -0
  7. package/dist/authority-main.js +2 -2
  8. package/dist/bridge.js +93 -78
  9. package/dist/building.js +50 -0
  10. package/dist/calls.js +71 -0
  11. package/dist/chatgpt.js +32 -0
  12. package/dist/chunks.js +49 -0
  13. package/dist/clis.js +224 -88
  14. package/dist/codex-main.js +58 -0
  15. package/dist/configure-main.js +6 -0
  16. package/dist/connection.js +105 -0
  17. package/dist/conversations.js +749 -268
  18. package/dist/copies.js +475 -260
  19. package/dist/end.js +33 -0
  20. package/dist/enrol-main.js +7 -1
  21. package/dist/events.js +546 -0
  22. package/dist/files.js +140 -17
  23. package/dist/git-main.js +2 -2
  24. package/dist/git.js +62 -22
  25. package/dist/home.js +134 -10
  26. package/dist/house-cli.js +299 -0
  27. package/dist/house-main.js +5 -102
  28. package/dist/instructions.js +17 -18
  29. package/dist/kit-cli.js +68 -0
  30. package/dist/kit-main.js +8 -16
  31. package/dist/login.js +130 -95
  32. package/dist/logout.js +19 -0
  33. package/dist/mcp.js +43 -0
  34. package/dist/operation.js +7 -4
  35. package/dist/parts.js +82 -0
  36. package/dist/placement.js +31 -0
  37. package/dist/refusals.js +53 -0
  38. package/dist/relay.js +41 -0
  39. package/dist/resident.js +145 -51
  40. package/dist/scope.js +214 -0
  41. package/dist/scripts.js +255 -0
  42. package/dist/secret-input.js +7 -2
  43. package/dist/service-main.js +9 -0
  44. package/dist/service.js +55 -0
  45. package/dist/shell.js +3 -0
  46. package/dist/sign-in.js +52 -32
  47. package/dist/silence.js +28 -0
  48. package/dist/skills.js +92 -0
  49. package/dist/transcription.js +210 -0
  50. package/dist/translate.js +2 -8
  51. package/dist/update.js +127 -0
  52. package/dist/wire.js +40 -0
  53. package/dist/work.js +346 -0
  54. package/package.json +20 -21
  55. package/dist/blocks.js +0 -51
  56. package/dist/bootstrap.json +0 -28
  57. package/dist/stream.js +0 -47
package/dist/work.js ADDED
@@ -0,0 +1,346 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ import { once } from 'node:events';
3
+ import { readFileSync } from 'node:fs';
4
+ import { rm } from 'node:fs/promises';
5
+ import { createServer } from 'node:net';
6
+ import { join } from 'node:path';
7
+ import { RUNNING_JOB } from './events.js';
8
+ import { kitHome, socketDirectory } from './home.js';
9
+ const ENDED_TASK = new Set(['completed', 'failed', 'killed']);
10
+ const SCHEDULING = new Set(['CronCreate', 'CronDelete', 'ScheduleWakeup']);
11
+ const QUEUE_LIST = 'house-kit-queue-';
12
+ const SYNC = 'house-kit-sync-';
13
+ const WAKEUP = /Next wakeup scheduled for (\d\d):(\d\d):(\d\d) \(in (\d+)s\)/;
14
+ const HALF_DAY = 12 * 60 * 60 * 1000;
15
+ export function codexLauncher() {
16
+ return join(kitHome(), 'launchers', 'codex');
17
+ }
18
+ export class Work {
19
+ changed;
20
+ jobs = new Set();
21
+ constructor(changed) {
22
+ this.changed = changed;
23
+ }
24
+ async open(_cli) {
25
+ return {};
26
+ }
27
+ async settled() { }
28
+ read(message) {
29
+ this.take(message);
30
+ this.changed();
31
+ }
32
+ take(message) {
33
+ const update = message.params?.update;
34
+ if (message.method !== 'session/update' || update?.asyncTaskId === undefined)
35
+ return;
36
+ if (update.sessionUpdate === 'async_task_spawned')
37
+ this.jobs.add(update.asyncTaskId);
38
+ if (update.sessionUpdate === 'async_task_state_update' && !RUNNING_JOB.has(update.state))
39
+ this.jobs.delete(update.asyncTaskId);
40
+ }
41
+ busy() {
42
+ return this.jobs.size > 0;
43
+ }
44
+ close() { }
45
+ }
46
+ class ClaudeWork extends Work {
47
+ cwd;
48
+ level = new Set();
49
+ listed = new Set();
50
+ started = new Set();
51
+ running = false;
52
+ hooks = new Set();
53
+ calls = new Map();
54
+ crons = new Map();
55
+ wakeups = [];
56
+ goal = false;
57
+ constructor(cwd, changed) {
58
+ super(changed);
59
+ this.cwd = cwd;
60
+ }
61
+ take(message) {
62
+ super.take(message);
63
+ if (message.method === '_claude/sdkMessage')
64
+ this.sdk(message.params.message);
65
+ if (message.method === 'session/update')
66
+ this.update(message.params.update);
67
+ }
68
+ busy() {
69
+ return (super.busy() ||
70
+ this.level.size > 0 ||
71
+ this.started.size > 0 ||
72
+ this.running ||
73
+ this.hooks.size > 0 ||
74
+ this.crons.size > 0 ||
75
+ this.wakeups.length > 0 ||
76
+ this.goal ||
77
+ this.durable());
78
+ }
79
+ sdk(message) {
80
+ switch (message.subtype) {
81
+ case 'background_tasks_changed':
82
+ this.level = new Set(message.tasks.map((task) => task.task_id));
83
+ for (const id of this.level) {
84
+ this.listed.add(id);
85
+ this.started.delete(id);
86
+ }
87
+ break;
88
+ case 'task_started':
89
+ if (!this.listed.has(message.task_id))
90
+ this.started.add(message.task_id);
91
+ break;
92
+ case 'task_updated':
93
+ if (ENDED_TASK.has(message.patch.status))
94
+ this.started.delete(message.task_id);
95
+ break;
96
+ case 'task_notification':
97
+ this.started.delete(message.task_id);
98
+ break;
99
+ case 'session_state_changed':
100
+ if (message.state === 'running' && !this.running)
101
+ this.wakeups = this.wakeups.filter((due) => due > Date.now());
102
+ this.running = message.state === 'running';
103
+ break;
104
+ case 'hook_started':
105
+ this.hooks.add(message.hook_id);
106
+ break;
107
+ case 'hook_response':
108
+ this.hooks.delete(message.hook_id);
109
+ break;
110
+ }
111
+ }
112
+ update(update) {
113
+ const air = update._meta?.jetbrains?.air;
114
+ if (update.sessionUpdate === 'session_info_update' && air !== undefined && 'goal' in air) {
115
+ this.goal = air.goal?.status === 'active';
116
+ }
117
+ if (update.sessionUpdate !== 'tool_call' && update.sessionUpdate !== 'tool_call_update')
118
+ return;
119
+ const tool = update._meta?.claudeCode?.toolName;
120
+ if (update.sessionUpdate === 'tool_call' && SCHEDULING.has(tool ?? ''))
121
+ this.calls.set(update.toolCallId, { tool });
122
+ const call = this.calls.get(update.toolCallId);
123
+ if (call === undefined)
124
+ return;
125
+ if (update.rawInput !== undefined)
126
+ call.input = update.rawInput;
127
+ if (update.content !== undefined)
128
+ call.content = update.content;
129
+ if (update.status === 'failed')
130
+ this.calls.delete(update.toolCallId);
131
+ if (update.status !== 'completed')
132
+ return;
133
+ this.calls.delete(update.toolCallId);
134
+ if (call.tool === 'CronCreate')
135
+ this.crons.set(update.toolCallId, JSON.stringify(call.content ?? []));
136
+ if (call.tool === 'ScheduleWakeup')
137
+ this.wakeup(call);
138
+ if (call.tool !== 'CronDelete')
139
+ return;
140
+ for (const [id, text] of this.crons)
141
+ if (text.includes(String(call.input?.id)))
142
+ this.crons.delete(id);
143
+ }
144
+ wakeup(call) {
145
+ if (call.input?.stop === true) {
146
+ this.wakeups = [];
147
+ return;
148
+ }
149
+ const time = WAKEUP.exec(JSON.stringify(call.content ?? []));
150
+ if (time === null) {
151
+ this.wakeups.push(Infinity);
152
+ return;
153
+ }
154
+ const fires = Date.now() + Number(time[4]) * 1000;
155
+ const due = new Date(fires);
156
+ due.setHours(Number(time[1]), Number(time[2]), Number(time[3]), 0);
157
+ if (due.getTime() - fires > HALF_DAY)
158
+ due.setDate(due.getDate() - 1);
159
+ if (fires - due.getTime() > HALF_DAY)
160
+ due.setDate(due.getDate() + 1);
161
+ this.wakeups.push(due.getTime());
162
+ }
163
+ durable() {
164
+ let text;
165
+ try {
166
+ text = readFileSync(join(this.cwd, '.claude', 'scheduled_tasks.json'), 'utf8');
167
+ }
168
+ catch (error) {
169
+ return error.code !== 'ENOENT';
170
+ }
171
+ try {
172
+ return JSON.parse(text).tasks?.length !== 0;
173
+ }
174
+ catch {
175
+ return true;
176
+ }
177
+ }
178
+ }
179
+ class CodexWork extends Work {
180
+ threads = new Map();
181
+ queues = new Map();
182
+ goals = new Set();
183
+ items = new Set();
184
+ hooks = new Set();
185
+ starting = new Set();
186
+ settling = [];
187
+ memories = null;
188
+ lost = false;
189
+ server = null;
190
+ path = null;
191
+ socket = null;
192
+ asked = 0;
193
+ heard = 0;
194
+ proving = -1;
195
+ proven = -1;
196
+ async open(cli) {
197
+ this.path = join(socketDirectory(), `${randomUUID()}.sock`);
198
+ this.server = createServer((socket) => this.connected(socket));
199
+ this.server.listen(this.path);
200
+ await once(this.server, 'listening');
201
+ return { CODEX_PATH: codexLauncher(), HOUSE_KIT_CODEX: cli, HOUSE_KIT_CODEX_STREAM: this.path };
202
+ }
203
+ settled() {
204
+ return new Promise((resolve) => {
205
+ this.settling.push(resolve);
206
+ this.settle();
207
+ });
208
+ }
209
+ take(message) {
210
+ super.take(message);
211
+ this.heard++;
212
+ }
213
+ busy() {
214
+ if (super.busy() ||
215
+ this.lost ||
216
+ this.memories !== false ||
217
+ [...this.threads.values()].some(Boolean) ||
218
+ this.queues.size > 0 ||
219
+ this.goals.size > 0 ||
220
+ this.items.size > 0 ||
221
+ this.hooks.size > 0) {
222
+ return true;
223
+ }
224
+ if (this.proven === this.heard)
225
+ return false;
226
+ this.prove();
227
+ return true;
228
+ }
229
+ close() {
230
+ this.server?.close();
231
+ if (this.path !== null)
232
+ void rm(this.path, { force: true });
233
+ }
234
+ connected(socket) {
235
+ this.socket = socket;
236
+ let buffer = '';
237
+ socket.on('error', () => this.lose());
238
+ socket.on('close', () => this.lose());
239
+ socket.setEncoding('utf8').on('data', (chunk) => {
240
+ buffer += chunk;
241
+ for (let index = buffer.indexOf('\n'); index >= 0; index = buffer.indexOf('\n')) {
242
+ const message = this.parsed(buffer.slice(0, index));
243
+ buffer = buffer.slice(index + 1);
244
+ if (message !== null)
245
+ this.stream(message, socket);
246
+ }
247
+ this.settle();
248
+ this.changed();
249
+ });
250
+ }
251
+ parsed(line) {
252
+ try {
253
+ return JSON.parse(line);
254
+ }
255
+ catch {
256
+ this.lost = true;
257
+ return null;
258
+ }
259
+ }
260
+ lose() {
261
+ this.lost = true;
262
+ this.changed();
263
+ }
264
+ prove() {
265
+ if (this.proving === this.heard)
266
+ return;
267
+ this.proving = this.heard;
268
+ this.socket.write(`${JSON.stringify({ jsonrpc: '2.0', id: `${SYNC}${this.heard}`, method: 'house-kit/sync' })}\n`);
269
+ }
270
+ settle() {
271
+ if (this.starting.size === 0)
272
+ for (const resolve of this.settling.splice(0))
273
+ resolve();
274
+ }
275
+ stream(message, socket) {
276
+ const params = message.params;
277
+ switch (message.method) {
278
+ case 'thread/status/changed':
279
+ this.threads.set(params.threadId, params.status.type === 'active' && params.status.activeFlags.length === 0);
280
+ break;
281
+ case 'thread/closed':
282
+ this.threads.delete(params.threadId);
283
+ break;
284
+ case 'thread/queue/changed':
285
+ this.queues.set(params.threadId, ++this.asked);
286
+ socket.write(`${JSON.stringify({ jsonrpc: '2.0', id: `${QUEUE_LIST}${this.asked}`, method: 'thread/queue/list', params: { threadId: params.threadId } })}\n`);
287
+ break;
288
+ case 'thread/goal/updated':
289
+ if (params.goal.status === 'active')
290
+ this.goals.add(params.threadId);
291
+ else
292
+ this.goals.delete(params.threadId);
293
+ break;
294
+ case 'thread/goal/cleared':
295
+ this.goals.delete(params.threadId);
296
+ break;
297
+ case 'item/started':
298
+ this.items.add(`${params.threadId} ${params.item.id}`);
299
+ break;
300
+ case 'item/completed':
301
+ this.items.delete(`${params.threadId} ${params.item.id}`);
302
+ break;
303
+ case 'hook/started':
304
+ this.hooks.add(params.run.id);
305
+ break;
306
+ case 'hook/completed':
307
+ this.hooks.delete(params.run.id);
308
+ break;
309
+ case 'mcpServer/startupStatus/updated':
310
+ if (params.status === 'starting')
311
+ this.starting.add(`${params.threadId} ${params.name}`);
312
+ else
313
+ this.starting.delete(`${params.threadId} ${params.name}`);
314
+ break;
315
+ case undefined:
316
+ this.answered(message);
317
+ }
318
+ }
319
+ answered(message) {
320
+ if (typeof message.id === 'string' && message.id.startsWith(SYNC)) {
321
+ this.proven = Number(message.id.slice(SYNC.length));
322
+ }
323
+ else if (typeof message.id === 'string' && message.id.startsWith(QUEUE_LIST)) {
324
+ const asked = Number(message.id.slice(QUEUE_LIST.length));
325
+ for (const [thread, latest] of this.queues) {
326
+ if (latest === asked && message.result?.data?.length === 0)
327
+ this.queues.delete(thread);
328
+ }
329
+ }
330
+ else if (message.result?.config?.features !== undefined) {
331
+ this.memories = message.result.config.features.memories !== false;
332
+ }
333
+ }
334
+ }
335
+ class GrokWork extends Work {
336
+ busy() {
337
+ return true;
338
+ }
339
+ }
340
+ export function workFor(kind, cwd, changed) {
341
+ if (kind === 'claude-agent-acp')
342
+ return new ClaudeWork(cwd, changed);
343
+ if (kind === 'codex-acp')
344
+ return new CodexWork(changed);
345
+ return new GrokWork(changed);
346
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@agentshouse/kit",
3
- "version": "0.2.1-alpha.8",
4
- "description": "House Kit connects an Environment to agents.house.",
3
+ "version": "0.2.1-c02dacffca87c",
4
+ "description": "Kit connects an Environment to agents.house.",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
@@ -12,25 +12,27 @@
12
12
  "kit": "dist/kit-main.js",
13
13
  "house": "dist/house-main.js"
14
14
  },
15
- "exports": {
16
- "./bootstrap": "./dist/bootstrap.json"
17
- },
18
15
  "files": [
19
16
  "dist"
20
17
  ],
21
18
  "scripts": {
22
- "build": "tsc -p tsconfig.build.json && node scripts/bootstrap-manifest.mjs",
19
+ "bootstrap-manifest": "node scripts/bootstrap-manifest.mjs",
20
+ "build": "tsc -p tsconfig.build.json",
21
+ "engine": "mkdir -p tmp/engine && docker run --rm -v \"$PWD:/kit\" -w /kit alpine:3.24@sha256:294b683cb724975bec92580e1e685676bd4b50bda910ddb8c51d4cabeaec77e6 sh scripts/engine.sh tmp/engine",
22
+ "follow-skills": "node scripts/follow-skills.mjs",
23
+ "release-files": "node scripts/release-files.mjs",
23
24
  "test": "tsc -p tsconfig.json && vitest run"
24
25
  },
25
26
  "dependencies": {
26
- "@agentclientprotocol/sdk": "1.7.0",
27
- "@agentshouse/mdmodel": "0.1.0-alpha.17",
27
+ "@agentclientprotocol/sdk": "2.0.1",
28
+ "@agentshouse/mdmodel": "0.1.0-c4f4d37bc9d6a",
29
+ "@agentshouse/skills": "0.1.0-ca0e7383018fc",
30
+ "@lydell/node-pty": "1.2.0-beta.15",
28
31
  "yaml": "2.9.1"
29
32
  },
30
33
  "peerDependencies": {
31
- "@agentclientprotocol/claude-agent-acp": "0.85.1",
32
- "@agentclientprotocol/codex-acp": "2.1.1",
33
- "@xai-official/grok": "1.0.46"
34
+ "@agentclientprotocol/claude-agent-acp": "0.94.0",
35
+ "@agentclientprotocol/codex-acp": "2.2.2"
34
36
  },
35
37
  "peerDependenciesMeta": {
36
38
  "@agentclientprotocol/claude-agent-acp": {
@@ -38,32 +40,29 @@
38
40
  },
39
41
  "@agentclientprotocol/codex-acp": {
40
42
  "optional": true
41
- },
42
- "@xai-official/grok": {
43
- "optional": true
44
43
  }
45
44
  },
46
45
  "devDependencies": {
47
- "@types/node": "24.13.6",
46
+ "@types/node": "24.19.2",
48
47
  "@types/ws": "8.18.2",
49
48
  "typescript": "7.0.2",
50
- "vitest": "5.0.1",
49
+ "vitest": "5.0.5",
51
50
  "ws": "8.22.0"
52
51
  },
53
- "packageManager": "npm@11.19.0",
52
+ "packageManager": "npm@11.19.1",
54
53
  "engines": {
55
- "node": "24.21.0",
56
- "npm": "11.19.0"
54
+ "node": "24.22.1",
55
+ "npm": "11.19.1"
57
56
  },
58
57
  "devEngines": {
59
58
  "runtime": {
60
59
  "name": "node",
61
- "version": "24.21.0",
60
+ "version": "24.22.1",
62
61
  "onFail": "error"
63
62
  },
64
63
  "packageManager": {
65
64
  "name": "npm",
66
- "version": "11.19.0",
65
+ "version": "11.19.1",
67
66
  "onFail": "error"
68
67
  }
69
68
  }
package/dist/blocks.js DELETED
@@ -1,51 +0,0 @@
1
- const FENCE = /^\s*(`{3,}|~{3,})\s*(\S*)/;
2
- export function blocksOf(text) {
3
- const blocks = [];
4
- let paragraph = [];
5
- let fence = null;
6
- const closeParagraph = () => {
7
- const joined = paragraph.join('\n').trim();
8
- if (joined.length > 0)
9
- blocks.push({ type: 'paragraph', text: joined });
10
- paragraph = [];
11
- };
12
- const closeFence = () => {
13
- const joined = fence.lines.join('\n');
14
- if (joined.length > 0)
15
- blocks.push({ type: 'code', language: fence.language, text: joined });
16
- fence = null;
17
- };
18
- for (const line of text.split('\n')) {
19
- if (fence !== null) {
20
- if (line.trim().startsWith(fence.marker))
21
- closeFence();
22
- else
23
- fence.lines.push(line);
24
- continue;
25
- }
26
- const opening = FENCE.exec(line);
27
- if (opening !== null) {
28
- closeParagraph();
29
- fence = { marker: opening[1], language: opening[2] || null, lines: [] };
30
- }
31
- else if (line.trim().length === 0) {
32
- closeParagraph();
33
- }
34
- else {
35
- paragraph.push(line);
36
- }
37
- }
38
- if (fence !== null)
39
- closeFence();
40
- closeParagraph();
41
- return blocks;
42
- }
43
- export function firstChange(before, after) {
44
- let index = 0;
45
- while (index < before.length &&
46
- index < after.length &&
47
- JSON.stringify(before[index]) === JSON.stringify(after[index])) {
48
- index++;
49
- }
50
- return index;
51
- }
@@ -1,28 +0,0 @@
1
- {
2
- "schemaVersion": 1,
3
- "version": "0.2.1-alpha.8",
4
- "hosts": {
5
- "linux": {
6
- "command": "bash <(curl -fsSL https://github.com/agentshouse/kit/releases/download/v0.2.1-alpha.8/connect-linux.sh)",
7
- "asset": {
8
- "name": "connect-linux.sh",
9
- "url": "https://github.com/agentshouse/kit/releases/download/v0.2.1-alpha.8/connect-linux.sh"
10
- },
11
- "workspace": {
12
- "argument": "--workspace",
13
- "quoting": "posix"
14
- }
15
- },
16
- "windows": {
17
- "command": "& ([scriptblock]::Create((irm https://github.com/agentshouse/kit/releases/download/v0.2.1-alpha.8/connect-windows.ps1)))",
18
- "asset": {
19
- "name": "connect-windows.ps1",
20
- "url": "https://github.com/agentshouse/kit/releases/download/v0.2.1-alpha.8/connect-windows.ps1"
21
- },
22
- "workspace": {
23
- "argument": "--workspace",
24
- "quoting": "powershell"
25
- }
26
- }
27
- }
28
- }
package/dist/stream.js DELETED
@@ -1,47 +0,0 @@
1
- import { readEnrolment } from './home.js';
2
- const SUBPROTOCOL = 'house.kit.stream.1';
3
- function streamUrl(house) {
4
- const url = new URL('/kit/stream', house);
5
- url.protocol = url.protocol === 'https:' ? 'wss:' : 'ws:';
6
- return url;
7
- }
8
- export function holdStream(handlers) {
9
- let socket = null;
10
- let failures = 0;
11
- const connect = async () => {
12
- const { house, credential } = (await readEnrolment());
13
- const opening = new WebSocket(streamUrl(house), {
14
- protocols: [SUBPROTOCOL],
15
- headers: { authorization: `Bearer ${credential}` },
16
- });
17
- let opened = false;
18
- opening.onopen = () => {
19
- opened = true;
20
- failures = 0;
21
- socket = opening;
22
- handlers.opened();
23
- };
24
- opening.onmessage = (event) => {
25
- handlers.frame(JSON.parse(String(event.data)));
26
- };
27
- opening.onerror = () => undefined;
28
- opening.onclose = (event) => {
29
- if (socket === opening)
30
- socket = null;
31
- process.stderr.write(`kit: control stream closed ${event.code} ${event.reason}\n`);
32
- const delay = opened
33
- ? 1000 + Math.random() * 2000
34
- : Math.min(30_000, 1000 * 2 ** failures++);
35
- setTimeout(() => void connect(), delay);
36
- };
37
- };
38
- void connect();
39
- return {
40
- send(frame) {
41
- if (socket === null || socket.readyState !== WebSocket.OPEN)
42
- return false;
43
- socket.send(JSON.stringify(frame));
44
- return true;
45
- },
46
- };
47
- }