@agentshouse/kit 0.2.1-alpha.9 → 0.2.1-c14f8446ba284

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.
@@ -0,0 +1,170 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { createReadStream } from 'node:fs';
3
+ import { chmod, mkdir, mkdtemp, readdir, readFile, rename, rm, stat } from 'node:fs/promises';
4
+ import { availableParallelism, tmpdir } from 'node:os';
5
+ import { basename, join } from 'node:path';
6
+ import { pipeline } from 'node:stream/promises';
7
+ import { unlessAborted } from './abort.js';
8
+ import { failureOf, run } from './clis.js';
9
+ import { kitHome } from './home.js';
10
+ const RELEASE = 'https://github.com/agentshouse/kit/releases/download/engine-2';
11
+ export const MODEL = {
12
+ url: 'https://huggingface.co/ggml-org/parakeet-GGUF/resolve/35156454d1a39de06863303dd209fd2bed6ee079/ggml-parakeet-tdt-0.6b-v3-q4_k.bin',
13
+ sha256: '8b205b8b39c6535e153de6fb11c51db46125d45c4f16ba496fe41a0fe71b885e',
14
+ executable: false,
15
+ };
16
+ export const ENGINES = {
17
+ 'linux-x64': {
18
+ decoder: { url: `${RELEASE}/ffmpeg-linux-x86_64`, sha256: '1f8235d206428305afb89c6e8ab99d100425a0ba61e22bb4c7aff017db8c8de5', executable: true },
19
+ engine: { url: `${RELEASE}/parakeet-cli-linux-x86_64`, sha256: 'bb2585695992fe1927a33960002cdf51b8a90a96ad65593c3d0a9f1fbc0865c2', executable: true },
20
+ },
21
+ 'linux-arm64': {
22
+ decoder: { url: `${RELEASE}/ffmpeg-linux-aarch64`, sha256: 'a7e08a0fae0179d1078312f6bb13d2a9aa4d4c71a1d82a022953f25dee452f5e', executable: true },
23
+ engine: { url: `${RELEASE}/parakeet-cli-linux-aarch64`, sha256: 'cbc0bedc8daae97f1ef9dcee4200c06226218e300e0fd62ead1306d22742b7ed', executable: true },
24
+ },
25
+ 'darwin-arm64': {
26
+ decoder: { url: `${RELEASE}/ffmpeg-darwin-arm64`, sha256: '7abe154aaed3d6b49f5167ca7221bb66bed51388925d99a7e4261a41fe52fba6', executable: true },
27
+ engine: { url: `${RELEASE}/parakeet-cli-darwin-arm64`, sha256: '9a2aafc0922ad7c0b6db6eff1641e96572ba32ac40bf995a1df242ed2febf297', executable: true },
28
+ },
29
+ };
30
+ const CHUNK_SECONDS = 20;
31
+ let held = Promise.resolve();
32
+ let holding = Promise.resolve();
33
+ let setting = null;
34
+ let downloading = null;
35
+ let readiness = { installed: false, failure: null };
36
+ function directory() {
37
+ return join(kitHome(), 'transcription');
38
+ }
39
+ function installed(artifact) {
40
+ return join(directory(), artifact.sha256);
41
+ }
42
+ async function executed(command, args, signal) {
43
+ // A download or a transcription runs as long as its size needs; the setting turning off or the turn's interrupt or end aborts it instead.
44
+ const ran = await run(command, args, 0, false, signal);
45
+ if (ran.status !== 0)
46
+ throw new Error(failureOf(ran, basename(command)));
47
+ return ran.stdout;
48
+ }
49
+ function present(path) {
50
+ return stat(path).then(() => true, () => false);
51
+ }
52
+ async function cpus() {
53
+ const [quota, period] = (await readFile('/sys/fs/cgroup/cpu.max', 'utf8').catch(() => 'max')).split(' ');
54
+ const allowed = quota === 'max' ? Infinity : Math.ceil(Number(quota) / Number(period));
55
+ return Math.min(availableParallelism(), allowed);
56
+ }
57
+ async function sha256(path) {
58
+ const hash = createHash('sha256');
59
+ await pipeline(createReadStream(path), hash);
60
+ return hash.digest('hex');
61
+ }
62
+ function causeOf(error) {
63
+ return error instanceof Error ? error.message : String(error);
64
+ }
65
+ function pinnedHere() {
66
+ return ENGINES[`${process.platform}-${process.arch}`];
67
+ }
68
+ async function install(artifacts, signal) {
69
+ await mkdir(directory(), { recursive: true });
70
+ const pinned = new Set(artifacts.map((artifact) => artifact.sha256));
71
+ for (const name of await readdir(directory())) {
72
+ if (!pinned.has(name))
73
+ await rm(join(directory(), name), { recursive: true, force: true });
74
+ }
75
+ const missing = [];
76
+ for (const artifact of artifacts)
77
+ if (!(await present(installed(artifact))))
78
+ missing.push(artifact);
79
+ try {
80
+ for (const artifact of missing) {
81
+ const part = `${installed(artifact)}.part`;
82
+ // Three retries carry a large download past a dropped connection before the download fails.
83
+ await executed('curl', ['-fsSL', '--retry', '3', '-o', part, artifact.url], signal);
84
+ if ((await sha256(part)) !== artifact.sha256)
85
+ throw new Error(`${artifact.url} does not match its sha256`);
86
+ }
87
+ for (const artifact of missing) {
88
+ if (artifact.executable)
89
+ await chmod(`${installed(artifact)}.part`, 0o755);
90
+ await rename(`${installed(artifact)}.part`, installed(artifact));
91
+ }
92
+ }
93
+ finally {
94
+ for (const artifact of missing)
95
+ await rm(`${installed(artifact)}.part`, { force: true });
96
+ }
97
+ }
98
+ function reported(next) {
99
+ const changed = next.installed !== readiness.installed || next.failure !== readiness.failure;
100
+ readiness = next;
101
+ return changed;
102
+ }
103
+ async function settle(transcribe) {
104
+ if (transcribe === setting)
105
+ return false;
106
+ setting = transcribe;
107
+ if (!transcribe) {
108
+ await rm(directory(), { recursive: true, force: true });
109
+ return reported({ installed: false, failure: null });
110
+ }
111
+ const download = new AbortController();
112
+ downloading = download;
113
+ try {
114
+ const pinned = pinnedHere();
115
+ await install([pinned.decoder, pinned.engine, MODEL], download.signal);
116
+ return reported({ installed: true, failure: null });
117
+ }
118
+ catch (error) {
119
+ await rm(directory(), { recursive: true, force: true });
120
+ return reported({ installed: false, failure: download.signal.aborted ? null : causeOf(error) });
121
+ }
122
+ finally {
123
+ downloading = null;
124
+ }
125
+ }
126
+ export function holdTranscription(transcribe) {
127
+ if (!transcribe)
128
+ downloading?.abort();
129
+ const settled = holding.then(() => settle(transcribe));
130
+ holding = settled.catch(() => undefined);
131
+ return settled;
132
+ }
133
+ export function transcriptionReport() {
134
+ return readiness;
135
+ }
136
+ async function transcribed(path, signal) {
137
+ const pinned = pinnedHere();
138
+ const work = await mkdtemp(join(tmpdir(), 'kit-transcription-'));
139
+ try {
140
+ await executed(installed(pinned.decoder), ['-nostdin', '-hide_banner', '-loglevel', 'error', '-i', path, '-ar', '16000', '-ac', '1', '-c:a', 'pcm_s16le',
141
+ '-f', 'segment', '-segment_time', String(CHUNK_SECONDS), join(work, '%05d.wav')], signal);
142
+ const parts = (await readdir(work)).sort().flatMap((part) => ['-f', join(work, part)]);
143
+ const text = await executed(installed(pinned.engine), ['-t', String(await cpus()), '-np', '-m', installed(MODEL), ...parts], signal);
144
+ return text
145
+ .split('\n')
146
+ .map((line) => line.trim())
147
+ .filter((line) => line !== '')
148
+ .join(' ');
149
+ }
150
+ finally {
151
+ await rm(work, { recursive: true, force: true });
152
+ }
153
+ }
154
+ export async function transcribe(path, signal) {
155
+ if (!readiness.installed)
156
+ return null;
157
+ const before = held;
158
+ let release;
159
+ const mine = new Promise((resolve) => {
160
+ release = resolve;
161
+ });
162
+ held = Promise.all([before, mine]);
163
+ try {
164
+ await unlessAborted(before, signal);
165
+ return readiness.installed ? await transcribed(path, signal) : null;
166
+ }
167
+ finally {
168
+ release();
169
+ }
170
+ }
package/dist/update.js ADDED
@@ -0,0 +1,119 @@
1
+ import { spawn } from 'node:child_process';
2
+ import { createHash } from 'node:crypto';
3
+ import { mkdir, readFile, rm, writeFile } from 'node:fs/promises';
4
+ import { homedir } from 'node:os';
5
+ import { join } from 'node:path';
6
+ import { run } from './clis.js';
7
+ import { kitHome } from './home.js';
8
+ const RECORD = 'outcome=$1; shift; bash "$0" --linux "$@"; printf %s "$?" > "$outcome"; systemctl start house-kit.service';
9
+ function logged(error) {
10
+ process.stderr.write(`kit: ${error instanceof Error ? error.message : String(error)}\n`);
11
+ }
12
+ function directory() {
13
+ return join(kitHome(), 'update');
14
+ }
15
+ function pending() {
16
+ return join(directory(), 'pending.json');
17
+ }
18
+ function outcome() {
19
+ return join(directory(), 'outcome');
20
+ }
21
+ function unit(inputId) {
22
+ return `house-kit-update-${inputId}`;
23
+ }
24
+ async function pendingInput() {
25
+ try {
26
+ return JSON.parse(await readFile(pending(), 'utf8')).input_id;
27
+ }
28
+ catch {
29
+ return null;
30
+ }
31
+ }
32
+ async function recorded() {
33
+ const status = await readFile(outcome(), 'utf8').catch(() => null);
34
+ if (status === null)
35
+ return null;
36
+ return status.trim() === '0' ? {} : { refused: `the Kit bootstrap exited with ${status.trim()}` };
37
+ }
38
+ async function finished(inputId) {
39
+ for (;;) {
40
+ const ack = await recorded();
41
+ if (ack !== null)
42
+ return ack;
43
+ // systemctl answers at once, so ten seconds only bounds a stuck service manager.
44
+ if ((await run('systemctl', ['is-active', '--quiet', unit(inputId)], 10_000)).status !== 0) {
45
+ return (await recorded()) ?? { refused: 'the Kit bootstrap did not finish' };
46
+ }
47
+ // The bootstrap runs for minutes, so checking each second sees its outcome within a second at little cost.
48
+ await new Promise((resolve) => setTimeout(resolve, 1000));
49
+ }
50
+ }
51
+ function rerun(script, inputId, flags) {
52
+ return new Promise((resolve) => {
53
+ const child = spawn('systemd-run', [
54
+ '--wait',
55
+ '--collect',
56
+ '--quiet',
57
+ `--unit=${unit(inputId)}`,
58
+ `--setenv=HOME=${homedir()}`,
59
+ '/bin/sh',
60
+ '-c',
61
+ RECORD,
62
+ script,
63
+ outcome(),
64
+ ...flags,
65
+ ], { stdio: ['ignore', 'ignore', 'inherit'] });
66
+ child.on('error', () => resolve({ refused: 'no service manager runs this Kit' }));
67
+ child.on('close', () => resolve(null));
68
+ });
69
+ }
70
+ export class Updates {
71
+ house;
72
+ held = new Set();
73
+ queue = Promise.resolve();
74
+ constructor(house) {
75
+ this.house = house;
76
+ }
77
+ async resumed() {
78
+ const inputId = await pendingInput();
79
+ if (inputId === null)
80
+ return;
81
+ await this.acknowledge(inputId, await finished(inputId));
82
+ }
83
+ start(input) {
84
+ if (this.held.has(input.input_id))
85
+ return;
86
+ this.held.add(input.input_id);
87
+ this.queue = this.queue
88
+ .then(() => this.carry(input))
89
+ .then((ack) => this.acknowledge(input.input_id, ack))
90
+ .catch(logged)
91
+ .finally(() => this.held.delete(input.input_id));
92
+ }
93
+ async carry(input) {
94
+ if ((await pendingInput()) === input.input_id)
95
+ return finished(input.input_id);
96
+ const answer = await fetch(input.bootstrap);
97
+ if (!answer.ok)
98
+ return { refused: `the Kit bootstrap could not be downloaded: ${answer.status}` };
99
+ const script = Buffer.from(await answer.arrayBuffer());
100
+ if (createHash('sha256').update(script).digest('hex') !== input.sha256) {
101
+ return { refused: 'the Kit bootstrap does not match its sha256' };
102
+ }
103
+ await mkdir(directory(), { recursive: true, mode: 0o700 });
104
+ const path = join(directory(), 'connect-linux.sh');
105
+ await writeFile(path, script, { mode: 0o700 });
106
+ await rm(outcome(), { force: true });
107
+ await writeFile(pending(), `${JSON.stringify({ input_id: input.input_id })}\n`, { mode: 0o600 });
108
+ return (await rerun(path, input.input_id, input.update_clis ? ['--update-clis'] : [])) ?? (await recorded()) ?? {
109
+ refused: 'the Kit bootstrap did not finish',
110
+ };
111
+ }
112
+ async acknowledge(inputId, ack) {
113
+ await this.house.deliver(`/kit/inputs/${inputId}/ack`, ack);
114
+ if ((await pendingInput()) !== inputId)
115
+ return;
116
+ await rm(pending(), { force: true });
117
+ await rm(outcome(), { force: true });
118
+ }
119
+ }
package/dist/work.js ADDED
@@ -0,0 +1,348 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ import { once } from 'node:events';
3
+ import { readFileSync } from 'node:fs';
4
+ import { mkdir, 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 } 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
+ const sockets = join(kitHome(), 'bridges');
198
+ await mkdir(sockets, { recursive: true, mode: 0o700 });
199
+ this.path = join(sockets, `${randomUUID()}.sock`);
200
+ this.server = createServer((socket) => this.connected(socket));
201
+ this.server.listen(this.path);
202
+ await once(this.server, 'listening');
203
+ return { CODEX_PATH: codexLauncher(), HOUSE_KIT_CODEX: cli, HOUSE_KIT_CODEX_STREAM: this.path };
204
+ }
205
+ settled() {
206
+ return new Promise((resolve) => {
207
+ this.settling.push(resolve);
208
+ this.settle();
209
+ });
210
+ }
211
+ take(message) {
212
+ super.take(message);
213
+ this.heard++;
214
+ }
215
+ busy() {
216
+ if (super.busy() ||
217
+ this.lost ||
218
+ this.memories !== false ||
219
+ [...this.threads.values()].some(Boolean) ||
220
+ this.queues.size > 0 ||
221
+ this.goals.size > 0 ||
222
+ this.items.size > 0 ||
223
+ this.hooks.size > 0) {
224
+ return true;
225
+ }
226
+ if (this.proven === this.heard)
227
+ return false;
228
+ this.prove();
229
+ return true;
230
+ }
231
+ close() {
232
+ this.server?.close();
233
+ if (this.path !== null)
234
+ void rm(this.path, { force: true });
235
+ }
236
+ connected(socket) {
237
+ this.socket = socket;
238
+ let buffer = '';
239
+ socket.on('error', () => this.lose());
240
+ socket.on('close', () => this.lose());
241
+ socket.setEncoding('utf8').on('data', (chunk) => {
242
+ buffer += chunk;
243
+ for (let index = buffer.indexOf('\n'); index >= 0; index = buffer.indexOf('\n')) {
244
+ const message = this.parsed(buffer.slice(0, index));
245
+ buffer = buffer.slice(index + 1);
246
+ if (message !== null)
247
+ this.stream(message, socket);
248
+ }
249
+ this.settle();
250
+ this.changed();
251
+ });
252
+ }
253
+ parsed(line) {
254
+ try {
255
+ return JSON.parse(line);
256
+ }
257
+ catch {
258
+ this.lost = true;
259
+ return null;
260
+ }
261
+ }
262
+ lose() {
263
+ this.lost = true;
264
+ this.changed();
265
+ }
266
+ prove() {
267
+ if (this.proving === this.heard)
268
+ return;
269
+ this.proving = this.heard;
270
+ this.socket.write(`${JSON.stringify({ jsonrpc: '2.0', id: `${SYNC}${this.heard}`, method: 'house-kit/sync' })}\n`);
271
+ }
272
+ settle() {
273
+ if (this.starting.size === 0)
274
+ for (const resolve of this.settling.splice(0))
275
+ resolve();
276
+ }
277
+ stream(message, socket) {
278
+ const params = message.params;
279
+ switch (message.method) {
280
+ case 'thread/status/changed':
281
+ this.threads.set(params.threadId, params.status.type === 'active' && params.status.activeFlags.length === 0);
282
+ break;
283
+ case 'thread/closed':
284
+ this.threads.delete(params.threadId);
285
+ break;
286
+ case 'thread/queue/changed':
287
+ this.queues.set(params.threadId, ++this.asked);
288
+ socket.write(`${JSON.stringify({ jsonrpc: '2.0', id: `${QUEUE_LIST}${this.asked}`, method: 'thread/queue/list', params: { threadId: params.threadId } })}\n`);
289
+ break;
290
+ case 'thread/goal/updated':
291
+ if (params.goal.status === 'active')
292
+ this.goals.add(params.threadId);
293
+ else
294
+ this.goals.delete(params.threadId);
295
+ break;
296
+ case 'thread/goal/cleared':
297
+ this.goals.delete(params.threadId);
298
+ break;
299
+ case 'item/started':
300
+ this.items.add(`${params.threadId} ${params.item.id}`);
301
+ break;
302
+ case 'item/completed':
303
+ this.items.delete(`${params.threadId} ${params.item.id}`);
304
+ break;
305
+ case 'hook/started':
306
+ this.hooks.add(params.run.id);
307
+ break;
308
+ case 'hook/completed':
309
+ this.hooks.delete(params.run.id);
310
+ break;
311
+ case 'mcpServer/startupStatus/updated':
312
+ if (params.status === 'starting')
313
+ this.starting.add(`${params.threadId} ${params.name}`);
314
+ else
315
+ this.starting.delete(`${params.threadId} ${params.name}`);
316
+ break;
317
+ case undefined:
318
+ this.answered(message);
319
+ }
320
+ }
321
+ answered(message) {
322
+ if (typeof message.id === 'string' && message.id.startsWith(SYNC)) {
323
+ this.proven = Number(message.id.slice(SYNC.length));
324
+ }
325
+ else if (typeof message.id === 'string' && message.id.startsWith(QUEUE_LIST)) {
326
+ const asked = Number(message.id.slice(QUEUE_LIST.length));
327
+ for (const [thread, latest] of this.queues) {
328
+ if (latest === asked && message.result?.data?.length === 0)
329
+ this.queues.delete(thread);
330
+ }
331
+ }
332
+ else if (message.result?.config?.features !== undefined) {
333
+ this.memories = message.result.config.features.memories !== false;
334
+ }
335
+ }
336
+ }
337
+ class GrokWork extends Work {
338
+ busy() {
339
+ return true;
340
+ }
341
+ }
342
+ export function workFor(kind, cwd, changed) {
343
+ if (kind === 'claude-agent-acp')
344
+ return new ClaudeWork(cwd, changed);
345
+ if (kind === 'codex-acp')
346
+ return new CodexWork(changed);
347
+ return new GrokWork(changed);
348
+ }
package/how-we-work.md CHANGED
@@ -2,24 +2,22 @@
2
2
 
3
3
  A Room is where information people share is kept; it is not the place for
4
4
  private information. Work goes into the Room it belongs to, or the First Room
5
- when none is named. Read and write Rooms with the `house` CLI.
5
+ when none is named.
6
6
 
7
7
  The skills are already set up; never run `setup-matt-pocock-skills`.
8
8
 
9
9
  ## Where skill output goes
10
10
 
11
- - Glossary (`CONTEXT.md`): `library/glossary.md`
12
- - Decisions (ADRs): `library/decisions/NNNN-<slug>.md`
13
- - Plan (spec): `library/projects/<name>/plan.md`
14
- - Tasks (tickets): `library/projects/<name>/tasks/NN-<slug>.md`, with a
11
+ - Glossary (`CONTEXT.md`): `glossary.md`
12
+ - Decisions (ADRs): `decisions/NNNN-<slug>.md`
13
+ - Plan (spec): `projects/<name>/plan.md`
14
+ - Tasks (tickets): `projects/<name>/tasks/NN-<slug>.md`, with a
15
15
  `Status:` line (`needs-triage`, `needs-info`, `ready-for-agent`,
16
16
  `ready-for-human`, `wontfix`), a `Blocked by:` line and comments under
17
17
  `## Comments`
18
- - Map (Wayfinding): `library/projects/<name>/map.md`, its tasks under
18
+ - Map (Wayfinding): `projects/<name>/map.md`, its tasks under
19
19
  `tasks/` with `Type:`, `Status: claimed|resolved` and `Blocked by:` lines
20
- - Research: `library/research/<slug>.md`
21
- - Questionnaires: `library/questionnaires/<slug>.md`
22
- - Learning: `library/learning/<topic>/`
23
- - Files a person should open, such as HTML pages, are uploaded to the Room and
24
- linked from the document they belong to; a prototype is one HTML file with
25
- every variant on one page.
20
+ - Research: `research/<slug>.md`
21
+ - Questionnaires: `questionnaires/<slug>.md`
22
+ - Learning: `learning/<topic>/`
23
+ - Prototype: one HTML file with every variant on one page.