@agentshouse/kit 0.2.1-ce145e9aadbf6 → 0.2.1-cf669c6d1ecbb
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.
- package/README.md +26 -26
- package/dist/acp.js +16 -93
- package/dist/agents.js +53 -30
- package/dist/api.js +30 -2
- package/dist/app-git.js +64 -0
- package/dist/bootstrap.json +4 -4
- package/dist/bridge.js +33 -51
- package/dist/clis.js +85 -70
- package/dist/codex-main.js +58 -0
- package/dist/conversations.js +284 -236
- package/dist/copies.js +130 -107
- package/dist/end.js +18 -0
- package/dist/enrol-main.js +7 -1
- package/dist/events.js +521 -0
- package/dist/files.js +14 -0
- package/dist/home.js +41 -3
- package/dist/house-main.js +43 -13
- package/dist/instructions.js +7 -5
- package/dist/kit-main.js +3 -0
- package/dist/login.js +83 -102
- package/dist/logout.js +16 -13
- package/dist/parts.js +82 -0
- package/dist/refusals.js +12 -0
- package/dist/relay.js +12 -2
- package/dist/resident.js +30 -23
- package/dist/scope.js +203 -0
- package/dist/secret-input.js +3 -2
- package/dist/service-main.js +9 -0
- package/dist/service.js +33 -0
- package/dist/shell.js +3 -0
- package/dist/sign-in.js +34 -10
- package/dist/stream.js +31 -4
- package/dist/transcription.js +54 -6
- package/dist/update.js +2 -0
- package/dist/work.js +348 -0
- package/package.json +2 -2
- package/dist/blocks.js +0 -51
package/dist/events.js
ADDED
|
@@ -0,0 +1,521 @@
|
|
|
1
|
+
const COMMAND = { shown: 'command' };
|
|
2
|
+
const HIDDEN = { shown: 'hidden' };
|
|
3
|
+
const FINISHED = new Set(['completed', 'failed']);
|
|
4
|
+
export const RUNNING_JOB = new Set(['running', 'paused']);
|
|
5
|
+
const ROUTINE_TARGETS = { send_routine_request: 'access', cancel_routine_request: 'request' };
|
|
6
|
+
function words(line) {
|
|
7
|
+
const found = [];
|
|
8
|
+
let word = null;
|
|
9
|
+
let quote = null;
|
|
10
|
+
for (let index = 0; index < line.length; index++) {
|
|
11
|
+
const character = line[index];
|
|
12
|
+
if (quote !== null) {
|
|
13
|
+
if (character === quote)
|
|
14
|
+
quote = null;
|
|
15
|
+
else if (character === '\\' && quote === '"')
|
|
16
|
+
word += line[++index] ?? '';
|
|
17
|
+
else
|
|
18
|
+
word += character;
|
|
19
|
+
}
|
|
20
|
+
else if (character === "'" || character === '"') {
|
|
21
|
+
quote = character;
|
|
22
|
+
word ??= '';
|
|
23
|
+
}
|
|
24
|
+
else if (character === '\\') {
|
|
25
|
+
word = (word ?? '') + (line[++index] ?? '');
|
|
26
|
+
}
|
|
27
|
+
else if (/\s/.test(character)) {
|
|
28
|
+
if (word !== null)
|
|
29
|
+
found.push(word);
|
|
30
|
+
word = null;
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
word = (word ?? '') + character;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (word !== null)
|
|
37
|
+
found.push(word);
|
|
38
|
+
return found;
|
|
39
|
+
}
|
|
40
|
+
export function houseMessage(line) {
|
|
41
|
+
const [program, verb, json] = words(line.trim());
|
|
42
|
+
if (program !== 'house' || verb !== 'run_command' || json === undefined)
|
|
43
|
+
return null;
|
|
44
|
+
let call;
|
|
45
|
+
try {
|
|
46
|
+
call = JSON.parse(json);
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
const argument = ROUTINE_TARGETS[call.command];
|
|
52
|
+
if (argument === undefined)
|
|
53
|
+
return null;
|
|
54
|
+
const target = call.arguments?.[argument];
|
|
55
|
+
return { shown: 'message', command: call.command, target: typeof target === 'string' ? target : null };
|
|
56
|
+
}
|
|
57
|
+
function decidedByLine(command, final) {
|
|
58
|
+
const line = typeof command === 'string' ? command : Array.isArray(command) ? command.at(-1) : undefined;
|
|
59
|
+
if (typeof line !== 'string')
|
|
60
|
+
return final ? COMMAND : null;
|
|
61
|
+
return houseMessage(line) ?? COMMAND;
|
|
62
|
+
}
|
|
63
|
+
function contentText(content) {
|
|
64
|
+
const text = (content ?? [])
|
|
65
|
+
.map((entry) => (entry.type === 'content' && entry.content?.type === 'text' ? entry.content.text : ''))
|
|
66
|
+
.filter((part) => part !== '')
|
|
67
|
+
.join('\n');
|
|
68
|
+
return text === '' ? null : text;
|
|
69
|
+
}
|
|
70
|
+
function plan(entries) {
|
|
71
|
+
return entries.map((entry) => ({ content: entry.content, status: entry.status }));
|
|
72
|
+
}
|
|
73
|
+
function merged(into, from) {
|
|
74
|
+
if (from === null || from === undefined)
|
|
75
|
+
return into;
|
|
76
|
+
const result = { ...into };
|
|
77
|
+
for (const [key, value] of Object.entries(from)) {
|
|
78
|
+
result[key] =
|
|
79
|
+
typeof value === 'object' && value !== null && !Array.isArray(value) && typeof into[key] === 'object'
|
|
80
|
+
? merged(into[key], value)
|
|
81
|
+
: value;
|
|
82
|
+
}
|
|
83
|
+
return result;
|
|
84
|
+
}
|
|
85
|
+
function names(input, ids) {
|
|
86
|
+
const values = JSON.stringify(input ?? {});
|
|
87
|
+
for (const id of ids)
|
|
88
|
+
if (values.includes(id))
|
|
89
|
+
return true;
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
class Reader {
|
|
93
|
+
session = null;
|
|
94
|
+
calls = new Map();
|
|
95
|
+
subagents = new Set();
|
|
96
|
+
done = new Set();
|
|
97
|
+
seenOptions = new Map();
|
|
98
|
+
requestedOptions = new Map();
|
|
99
|
+
compactions = new Set();
|
|
100
|
+
jobs = new Map();
|
|
101
|
+
read(message) {
|
|
102
|
+
if (message.method === undefined)
|
|
103
|
+
return this.answered(message.result);
|
|
104
|
+
const session = message.params?.sessionId;
|
|
105
|
+
if (session !== undefined && this.session !== null && session !== this.session) {
|
|
106
|
+
return this.elsewhere(session, message);
|
|
107
|
+
}
|
|
108
|
+
return this.own(message);
|
|
109
|
+
}
|
|
110
|
+
requested(option, value) {
|
|
111
|
+
this.requestedOptions.set(option, value);
|
|
112
|
+
}
|
|
113
|
+
refused(option) {
|
|
114
|
+
this.requestedOptions.delete(option);
|
|
115
|
+
}
|
|
116
|
+
closeTurn() {
|
|
117
|
+
const events = [];
|
|
118
|
+
for (const [id, call] of this.calls) {
|
|
119
|
+
if (call.decided?.shown === 'subagent')
|
|
120
|
+
continue;
|
|
121
|
+
if (call.decided === null)
|
|
122
|
+
events.push(...this.shown(call, this.decide(call, true)));
|
|
123
|
+
this.calls.delete(id);
|
|
124
|
+
}
|
|
125
|
+
return events;
|
|
126
|
+
}
|
|
127
|
+
answered(result) {
|
|
128
|
+
if (typeof result?.sessionId === 'string' && this.session === null)
|
|
129
|
+
this.session = result.sessionId;
|
|
130
|
+
for (const option of (result?.configOptions ?? [])) {
|
|
131
|
+
this.seenOptions.set(option.id, option.currentValue);
|
|
132
|
+
this.requestedOptions.delete(option.id);
|
|
133
|
+
}
|
|
134
|
+
return [];
|
|
135
|
+
}
|
|
136
|
+
elsewhere(_session, _message) {
|
|
137
|
+
return [];
|
|
138
|
+
}
|
|
139
|
+
own(message) {
|
|
140
|
+
if (message.method !== 'session/update')
|
|
141
|
+
return this.extension(message);
|
|
142
|
+
return this.update(message.params.update);
|
|
143
|
+
}
|
|
144
|
+
extension(_message) {
|
|
145
|
+
return [];
|
|
146
|
+
}
|
|
147
|
+
update(update) {
|
|
148
|
+
switch (update.sessionUpdate) {
|
|
149
|
+
case 'agent_message_chunk':
|
|
150
|
+
if (update.content.type === 'image')
|
|
151
|
+
return [{ kind: 'image', data: update.content.data, mediaType: update.content.mimeType }];
|
|
152
|
+
return update.content.type === 'text' ? [{ kind: 'text', id: update.messageId ?? null, text: update.content.text }] : [];
|
|
153
|
+
case 'agent_thought_chunk':
|
|
154
|
+
return update.content.type === 'text' ? [{ kind: 'reasoning', id: update.messageId ?? null, text: update.content.text }] : [];
|
|
155
|
+
case 'tool_call':
|
|
156
|
+
case 'tool_call_update':
|
|
157
|
+
return this.tool(update);
|
|
158
|
+
case 'plan':
|
|
159
|
+
return [{ kind: 'plan', entries: plan(update.entries) }];
|
|
160
|
+
case 'usage_update':
|
|
161
|
+
return [{ kind: 'context', used: update.used, window: update.size }];
|
|
162
|
+
case 'current_mode_update':
|
|
163
|
+
return [{ kind: 'marker', marker: 'mode', text: update.currentModeId }];
|
|
164
|
+
case 'available_commands_update':
|
|
165
|
+
return [{ kind: 'commands', commands: update.availableCommands }];
|
|
166
|
+
case 'config_option_update':
|
|
167
|
+
return [{ kind: 'options', options: update.configOptions }, ...this.optionsChanged(update.configOptions)];
|
|
168
|
+
case 'compaction_update':
|
|
169
|
+
if (update.status !== 'completed' || this.compactions.has(update.compactionId))
|
|
170
|
+
return [];
|
|
171
|
+
this.compactions.add(update.compactionId);
|
|
172
|
+
return [{ kind: 'marker', marker: 'compaction', text: '' }];
|
|
173
|
+
case 'async_task_spawned':
|
|
174
|
+
return this.job(update.asyncTaskId, update.name ?? update.description ?? '', 'running');
|
|
175
|
+
case 'async_task_state_update':
|
|
176
|
+
return RUNNING_JOB.has(update.state) ? [] : this.job(update.asyncTaskId, null, update.state);
|
|
177
|
+
default:
|
|
178
|
+
return [];
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
job(id, name, state) {
|
|
182
|
+
if (name !== null)
|
|
183
|
+
this.jobs.set(id, name);
|
|
184
|
+
const label = this.jobs.get(id) ?? '';
|
|
185
|
+
if (state !== 'running')
|
|
186
|
+
this.jobs.delete(id);
|
|
187
|
+
return [{ kind: 'marker', marker: 'job', text: `${label}: ${state}` }];
|
|
188
|
+
}
|
|
189
|
+
optionsChanged(options) {
|
|
190
|
+
const events = [];
|
|
191
|
+
for (const option of options) {
|
|
192
|
+
const marker = this.watchedOptions[option.id];
|
|
193
|
+
const before = this.seenOptions.get(option.id);
|
|
194
|
+
this.seenOptions.set(option.id, option.currentValue);
|
|
195
|
+
if (marker === undefined || before === undefined || before === option.currentValue)
|
|
196
|
+
continue;
|
|
197
|
+
if (this.requestedOptions.get(option.id) === option.currentValue) {
|
|
198
|
+
this.requestedOptions.delete(option.id);
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
events.push({ kind: 'marker', marker, text: String(option.currentValue) });
|
|
202
|
+
}
|
|
203
|
+
return events;
|
|
204
|
+
}
|
|
205
|
+
tool(update) {
|
|
206
|
+
let call = this.calls.get(update.toolCallId);
|
|
207
|
+
if (call === undefined) {
|
|
208
|
+
if (update.sessionUpdate !== 'tool_call')
|
|
209
|
+
return [];
|
|
210
|
+
call = { id: update.toolCallId, decided: null, meta: {}, imaged: false, status: 'in_progress' };
|
|
211
|
+
this.calls.set(call.id, call);
|
|
212
|
+
}
|
|
213
|
+
if (update.kind !== undefined)
|
|
214
|
+
call.kind = update.kind;
|
|
215
|
+
if (update.title !== undefined)
|
|
216
|
+
call.title = update.title;
|
|
217
|
+
if (update.status !== undefined)
|
|
218
|
+
call.status = update.status;
|
|
219
|
+
if (update.rawInput !== undefined)
|
|
220
|
+
call.rawInput = merged(call.rawInput ?? {}, update.rawInput);
|
|
221
|
+
if (update.content !== undefined)
|
|
222
|
+
call.content = update.content;
|
|
223
|
+
call.meta = merged(call.meta, update._meta);
|
|
224
|
+
const events = [];
|
|
225
|
+
const finished = FINISHED.has(call.status);
|
|
226
|
+
if (call.decided === null) {
|
|
227
|
+
const decided = this.decide(call, finished);
|
|
228
|
+
if (decided !== null)
|
|
229
|
+
events.push(...this.shown(call, decided));
|
|
230
|
+
}
|
|
231
|
+
events.push(...this.produced(call));
|
|
232
|
+
if (call.decided?.shown === 'subagent' && finished)
|
|
233
|
+
events.push(...this.subagentFinished(call));
|
|
234
|
+
else if (finished)
|
|
235
|
+
this.calls.delete(call.id);
|
|
236
|
+
return events;
|
|
237
|
+
}
|
|
238
|
+
shown(call, decided) {
|
|
239
|
+
call.decided = decided;
|
|
240
|
+
switch (decided.shown) {
|
|
241
|
+
case 'command':
|
|
242
|
+
return [{ kind: 'command' }];
|
|
243
|
+
case 'hidden':
|
|
244
|
+
return [];
|
|
245
|
+
case 'message':
|
|
246
|
+
return [{ kind: 'message', command: decided.command, target: decided.target }];
|
|
247
|
+
case 'marker':
|
|
248
|
+
return [{ kind: 'marker', marker: decided.marker, text: decided.text }];
|
|
249
|
+
case 'subagent':
|
|
250
|
+
this.subagents.add(call.id);
|
|
251
|
+
return [{ kind: 'subagent', id: call.id, description: decided.description }];
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
produced(_call) {
|
|
255
|
+
return [];
|
|
256
|
+
}
|
|
257
|
+
subagentFinished(call) {
|
|
258
|
+
this.calls.delete(call.id);
|
|
259
|
+
return this.finish(call.id, contentText(call.content));
|
|
260
|
+
}
|
|
261
|
+
finish(id, result) {
|
|
262
|
+
if (!this.subagents.has(id) || this.done.has(id))
|
|
263
|
+
return [];
|
|
264
|
+
this.done.add(id);
|
|
265
|
+
this.calls.delete(id);
|
|
266
|
+
return [{ kind: 'subagent-done', id, result }];
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
class ClaudeReader extends Reader {
|
|
270
|
+
watchedOptions = { model: 'model' };
|
|
271
|
+
tasks = new Map();
|
|
272
|
+
own(message) {
|
|
273
|
+
if (message.params?.update?._meta?.claudeCode?.parentToolUseId !== undefined)
|
|
274
|
+
return [];
|
|
275
|
+
return super.own(message);
|
|
276
|
+
}
|
|
277
|
+
update(update) {
|
|
278
|
+
if (update.sessionUpdate === 'usage_update' && update._meta?.['_claude/origin'] !== undefined) {
|
|
279
|
+
return [...super.update(update), { kind: 'ended' }];
|
|
280
|
+
}
|
|
281
|
+
if (update.sessionUpdate === 'session_info_update' && update._meta?.jetbrains?.air?.sessionFailure !== undefined) {
|
|
282
|
+
return [{ kind: 'marker', marker: 'retry', text: update._meta.jetbrains.air.sessionFailure.title }];
|
|
283
|
+
}
|
|
284
|
+
return super.update(update);
|
|
285
|
+
}
|
|
286
|
+
extension(message) {
|
|
287
|
+
if (message.method !== '_claude/sdkMessage')
|
|
288
|
+
return [];
|
|
289
|
+
const sdk = message.params.message;
|
|
290
|
+
switch (sdk.subtype) {
|
|
291
|
+
case 'task_started':
|
|
292
|
+
if (sdk.tool_use_id !== undefined)
|
|
293
|
+
this.tasks.set(sdk.task_id, sdk.tool_use_id);
|
|
294
|
+
return [];
|
|
295
|
+
case 'task_notification':
|
|
296
|
+
return sdk.tool_use_id === undefined ? [] : this.finish(sdk.tool_use_id, sdk.summary ?? null);
|
|
297
|
+
default:
|
|
298
|
+
return [];
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
decide(call, final) {
|
|
302
|
+
const tool = call.meta.claudeCode?.toolName;
|
|
303
|
+
if (tool === 'Agent' || tool === 'Task' || call.meta.jetbrains?.air?.subagent === true) {
|
|
304
|
+
const description = call.rawInput?.description;
|
|
305
|
+
if (description === undefined && !final)
|
|
306
|
+
return null;
|
|
307
|
+
return { shown: 'subagent', description: description ?? call.title ?? '' };
|
|
308
|
+
}
|
|
309
|
+
if (tool === 'TodoWrite' || tool === 'CronCreate')
|
|
310
|
+
return HIDDEN;
|
|
311
|
+
if (tool === 'ScheduleWakeup') {
|
|
312
|
+
if (call.rawInput === undefined)
|
|
313
|
+
return final ? COMMAND : null;
|
|
314
|
+
return call.rawInput.stop === true ? COMMAND : HIDDEN;
|
|
315
|
+
}
|
|
316
|
+
if (call.kind === 'switch_mode')
|
|
317
|
+
return { shown: 'marker', marker: 'mode', text: call.title ?? '' };
|
|
318
|
+
if (tool === 'Bash')
|
|
319
|
+
return decidedByLine(call.rawInput?.command, final);
|
|
320
|
+
if (tool === 'SendMessage' || tool === 'TaskStop') {
|
|
321
|
+
if (call.rawInput === undefined)
|
|
322
|
+
return final ? COMMAND : null;
|
|
323
|
+
return names(call.rawInput, this.tasks.keys()) ? HIDDEN : COMMAND;
|
|
324
|
+
}
|
|
325
|
+
return COMMAND;
|
|
326
|
+
}
|
|
327
|
+
produced(call) {
|
|
328
|
+
const tool = call.meta.claudeCode?.toolName;
|
|
329
|
+
if (call.status !== 'completed')
|
|
330
|
+
return [];
|
|
331
|
+
if (tool === 'CronCreate' || (tool === 'ScheduleWakeup' && call.rawInput?.stop !== true)) {
|
|
332
|
+
return [{ kind: 'marker', marker: 'job', text: `${call.rawInput?.prompt ?? call.title ?? ''}: scheduled` }];
|
|
333
|
+
}
|
|
334
|
+
return [];
|
|
335
|
+
}
|
|
336
|
+
subagentFinished(call) {
|
|
337
|
+
if (call.meta.claudeCode?.toolResponse?.isAsync === true)
|
|
338
|
+
return [];
|
|
339
|
+
return super.subagentFinished(call);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
const COLLABORATION = new Set(['spawnAgent', 'sendInput', 'resumeAgent', 'wait', 'closeAgent', 'followupTask']);
|
|
343
|
+
class CodexReader extends Reader {
|
|
344
|
+
watchedOptions = { mode: 'mode', collaboration_mode: 'mode' };
|
|
345
|
+
children = new Map();
|
|
346
|
+
own(message) {
|
|
347
|
+
if (message.method === 'session/request_permission' && message.params.toolCall?.kind === 'switch_mode') {
|
|
348
|
+
return [{ kind: 'started' }, { kind: 'marker', marker: 'mode', text: message.params.toolCall.title ?? '' }];
|
|
349
|
+
}
|
|
350
|
+
return super.own(message);
|
|
351
|
+
}
|
|
352
|
+
update(update) {
|
|
353
|
+
switch (update.sessionUpdate) {
|
|
354
|
+
case 'session_info_update': {
|
|
355
|
+
const codex = update._meta?.codex;
|
|
356
|
+
if (codex?.threadStatus?.type === 'active')
|
|
357
|
+
return [{ kind: 'started' }];
|
|
358
|
+
if (codex?.threadStatus?.type === 'idle')
|
|
359
|
+
return [{ kind: 'ended' }];
|
|
360
|
+
if (codex?.error !== undefined)
|
|
361
|
+
return [{ kind: 'marker', marker: 'retry', text: codex.error.message ?? '' }];
|
|
362
|
+
return [];
|
|
363
|
+
}
|
|
364
|
+
case 'notice':
|
|
365
|
+
return update.severity === 'info' ? [{ kind: 'marker', marker: 'model', text: update.description ?? update.title }] : [];
|
|
366
|
+
case 'subagent_spawned':
|
|
367
|
+
this.children.set(update.subagentSessionId, { id: null, text: '' });
|
|
368
|
+
this.subagents.add(update.subagentSessionId);
|
|
369
|
+
return [{ kind: 'subagent', id: update.subagentSessionId, description: update.name }];
|
|
370
|
+
case 'subagent_state_update':
|
|
371
|
+
return this.finish(update.subagentSessionId, this.children.get(update.subagentSessionId)?.text || null);
|
|
372
|
+
default:
|
|
373
|
+
return super.update(update);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
elsewhere(session, message) {
|
|
377
|
+
const child = this.children.get(session);
|
|
378
|
+
const update = message.params?.update;
|
|
379
|
+
if (child === undefined || update === undefined)
|
|
380
|
+
return [];
|
|
381
|
+
if (update.sessionUpdate === 'agent_message_chunk' && update.content.type === 'text') {
|
|
382
|
+
const id = update.messageId ?? null;
|
|
383
|
+
if (child.id !== id)
|
|
384
|
+
child.text = '';
|
|
385
|
+
child.id = id;
|
|
386
|
+
child.text += update.content.text;
|
|
387
|
+
}
|
|
388
|
+
return [];
|
|
389
|
+
}
|
|
390
|
+
decide(call) {
|
|
391
|
+
const air = call.meta.jetbrains?.air;
|
|
392
|
+
if (COLLABORATION.has(call.title ?? ''))
|
|
393
|
+
return HIDDEN;
|
|
394
|
+
if (air?.subagent !== undefined)
|
|
395
|
+
return { shown: 'subagent', description: call.title ?? '' };
|
|
396
|
+
if (call.kind === 'switch_mode')
|
|
397
|
+
return { shown: 'marker', marker: 'mode', text: call.title ?? '' };
|
|
398
|
+
if (call.kind === 'execute')
|
|
399
|
+
return decidedByLine(call.rawInput?.command, true);
|
|
400
|
+
if (call.title === 'Image generation')
|
|
401
|
+
return HIDDEN;
|
|
402
|
+
return COMMAND;
|
|
403
|
+
}
|
|
404
|
+
produced(call) {
|
|
405
|
+
if (call.imaged || call.kind === 'read')
|
|
406
|
+
return [];
|
|
407
|
+
const image = (call.content ?? []).find((entry) => entry.type === 'content' && entry.content?.type === 'image');
|
|
408
|
+
if (image === undefined)
|
|
409
|
+
return [];
|
|
410
|
+
call.imaged = true;
|
|
411
|
+
return [{ kind: 'image', data: image.content.data, mediaType: image.content.mimeType }];
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
class GrokReader extends Reader {
|
|
415
|
+
watchedOptions = {};
|
|
416
|
+
children = new Map();
|
|
417
|
+
models = [];
|
|
418
|
+
model = null;
|
|
419
|
+
answered(result) {
|
|
420
|
+
if (result?.models !== undefined)
|
|
421
|
+
this.offered(result.models);
|
|
422
|
+
return super.answered(result);
|
|
423
|
+
}
|
|
424
|
+
read(message) {
|
|
425
|
+
const session = message.params?.sessionId;
|
|
426
|
+
if (this.session !== null && session !== undefined && session !== this.session && !this.children.has(session))
|
|
427
|
+
return [];
|
|
428
|
+
if (message.method === '_x.ai/queue/changed') {
|
|
429
|
+
return (message.params.runningPromptId ?? null) !== null && session === this.session ? [{ kind: 'started' }] : [];
|
|
430
|
+
}
|
|
431
|
+
if (message.params?.update?.sessionUpdate === 'turn_completed') {
|
|
432
|
+
return session === this.session ? [{ kind: 'ended' }] : [];
|
|
433
|
+
}
|
|
434
|
+
if (message.method === '_x.ai/models/update') {
|
|
435
|
+
this.offered(message.params);
|
|
436
|
+
return [];
|
|
437
|
+
}
|
|
438
|
+
return super.read(message);
|
|
439
|
+
}
|
|
440
|
+
offered(models) {
|
|
441
|
+
this.models = models.availableModels ?? this.models;
|
|
442
|
+
this.model = models.currentModelId ?? this.model;
|
|
443
|
+
}
|
|
444
|
+
window() {
|
|
445
|
+
return this.models.find((model) => model.modelId === this.model)?._meta?.totalContextTokens ?? null;
|
|
446
|
+
}
|
|
447
|
+
extension(message) {
|
|
448
|
+
const update = message.params?.update;
|
|
449
|
+
switch (message.method) {
|
|
450
|
+
case '_x.ai/task_backgrounded':
|
|
451
|
+
return this.job(update.task_id, update.description ?? update.command ?? '', 'running');
|
|
452
|
+
case '_x.ai/task_completed':
|
|
453
|
+
return this.job(update.task_snapshot.task_id, null, update.task_snapshot.exit_code === 0 ? 'completed' : 'failed');
|
|
454
|
+
case '_x.ai/scheduled_task_created':
|
|
455
|
+
return [{ kind: 'marker', marker: 'job', text: `${update.prompt}: next run ${update.next_fire_at}` }];
|
|
456
|
+
case '_x.ai/session_notification':
|
|
457
|
+
return this.notification(update);
|
|
458
|
+
default:
|
|
459
|
+
return [];
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
notification(update) {
|
|
463
|
+
switch (update.sessionUpdate) {
|
|
464
|
+
case 'response_completed': {
|
|
465
|
+
const usage = update.usage;
|
|
466
|
+
const window = this.window();
|
|
467
|
+
if (window === null)
|
|
468
|
+
return [];
|
|
469
|
+
const used = usage.input_tokens + (usage.cache_read_input_tokens ?? 0) + (usage.cache_creation_input_tokens ?? 0) + usage.output_tokens;
|
|
470
|
+
return [{ kind: 'context', used, window }];
|
|
471
|
+
}
|
|
472
|
+
case 'subagent_spawned': {
|
|
473
|
+
const call = [...this.calls.values()].find((candidate) => candidate.decided?.shown === 'subagent' &&
|
|
474
|
+
![...this.children.values()].includes(candidate.id) &&
|
|
475
|
+
candidate.decided.description === update.description) ??
|
|
476
|
+
[...this.calls.values()].find((candidate) => candidate.decided?.shown === 'subagent' && ![...this.children.values()].includes(candidate.id));
|
|
477
|
+
this.children.set(update.child_session_id, call?.id ?? null);
|
|
478
|
+
return [];
|
|
479
|
+
}
|
|
480
|
+
case 'subagent_finished': {
|
|
481
|
+
const call = this.children.get(update.child_session_id);
|
|
482
|
+
return typeof call === 'string' ? this.finish(call, update.output ?? null) : [];
|
|
483
|
+
}
|
|
484
|
+
case 'auto_compact_completed':
|
|
485
|
+
return [{ kind: 'marker', marker: 'compaction', text: '' }];
|
|
486
|
+
case 'model_auto_switched':
|
|
487
|
+
this.model = update.new_model_id;
|
|
488
|
+
return [{ kind: 'marker', marker: 'model', text: update.new_model_id }];
|
|
489
|
+
case 'retry_state':
|
|
490
|
+
return [{ kind: 'marker', marker: 'retry', text: update.message ?? update.reason ?? update.error_type ?? '' }];
|
|
491
|
+
default:
|
|
492
|
+
return [];
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
decide(call) {
|
|
496
|
+
const tool = (call.meta['x.ai/tool'] ?? {});
|
|
497
|
+
if (tool.name === 'spawn_subagent' || tool.kind === 'task') {
|
|
498
|
+
return { shown: 'subagent', description: call.rawInput?.description ?? call.title ?? '' };
|
|
499
|
+
}
|
|
500
|
+
if (tool.name === 'todo_write' || tool.name === 'scheduler_create')
|
|
501
|
+
return HIDDEN;
|
|
502
|
+
if (tool.name === 'enter_plan_mode' || tool.name === 'exit_plan_mode') {
|
|
503
|
+
return { shown: 'marker', marker: 'mode', text: tool.name };
|
|
504
|
+
}
|
|
505
|
+
if (tool.name === 'kill_command_or_subagent')
|
|
506
|
+
return names(call.rawInput, this.children.keys()) ? HIDDEN : COMMAND;
|
|
507
|
+
if (tool.name === 'run_terminal_command')
|
|
508
|
+
return decidedByLine(call.rawInput?.command, true);
|
|
509
|
+
return COMMAND;
|
|
510
|
+
}
|
|
511
|
+
subagentFinished(_call) {
|
|
512
|
+
return [];
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
export function readerFor(kind) {
|
|
516
|
+
if (kind === 'claude-agent-acp')
|
|
517
|
+
return new ClaudeReader();
|
|
518
|
+
if (kind === 'grok-build')
|
|
519
|
+
return new GrokReader();
|
|
520
|
+
return new CodexReader();
|
|
521
|
+
}
|
package/dist/files.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { mkdir, writeFile } from 'node:fs/promises';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
|
+
import { HouseRefusal, retrying } from './api.js';
|
|
3
4
|
import { relayed } from './relay.js';
|
|
4
5
|
export async function placeFiles(house, directory, files, signal) {
|
|
5
6
|
const paths = [];
|
|
@@ -20,3 +21,16 @@ export async function placeFiles(house, directory, files, signal) {
|
|
|
20
21
|
}
|
|
21
22
|
return paths;
|
|
22
23
|
}
|
|
24
|
+
export function uploadBytes(upload, bytes) {
|
|
25
|
+
return retrying(async () => {
|
|
26
|
+
const answer = await fetch(relayed(upload.url), {
|
|
27
|
+
method: 'POST',
|
|
28
|
+
headers: { 'content-type': 'application/octet-stream', 'x-house-byte-operation': upload.operation },
|
|
29
|
+
body: bytes,
|
|
30
|
+
});
|
|
31
|
+
const text = await answer.text();
|
|
32
|
+
if (!answer.ok)
|
|
33
|
+
throw new HouseRefusal(upload.url, answer.status, text);
|
|
34
|
+
return JSON.parse(text);
|
|
35
|
+
});
|
|
36
|
+
}
|
package/dist/home.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { existsSync } from 'node:fs';
|
|
1
|
+
import { existsSync, linkSync, readFileSync, renameSync, rmSync } from 'node:fs';
|
|
2
2
|
import { mkdir, readFile, rename, rm, writeFile } from 'node:fs/promises';
|
|
3
3
|
import { homedir } from 'node:os';
|
|
4
4
|
import { join } from 'node:path';
|
|
5
|
+
import { selectRelay } from './relay.js';
|
|
5
6
|
const ENROLMENT = 'credential.json';
|
|
6
7
|
const DISCONNECTED = 'disconnected.json';
|
|
7
8
|
const CONFIGURATION = 'kit.json';
|
|
8
9
|
const OWN_AGENT = 'own-agent.json';
|
|
10
|
+
const RESTART = 'restart';
|
|
9
11
|
export function kitHome() {
|
|
10
12
|
return process.env.HOUSE_KIT_HOME ?? join(homedir(), '.house-kit');
|
|
11
13
|
}
|
|
@@ -32,8 +34,11 @@ export async function writeHome(name, value) {
|
|
|
32
34
|
await writeFile(temporary, `${JSON.stringify(value)}\n`, { mode: 0o600 });
|
|
33
35
|
await rename(temporary, join(home, name));
|
|
34
36
|
}
|
|
35
|
-
export function readEnrolment() {
|
|
36
|
-
|
|
37
|
+
export async function readEnrolment() {
|
|
38
|
+
const enrolment = await readHome(ENROLMENT);
|
|
39
|
+
if (enrolment !== null)
|
|
40
|
+
selectRelay(process.env.HOUSE_KIT_RELAY || enrolment.relay);
|
|
41
|
+
return enrolment;
|
|
37
42
|
}
|
|
38
43
|
export async function writeEnrolment(enrolment) {
|
|
39
44
|
await writeHome(ENROLMENT, enrolment);
|
|
@@ -46,9 +51,42 @@ export async function forgetEnrolment({ house, environment }) {
|
|
|
46
51
|
await writeHome(DISCONNECTED, { house, environment });
|
|
47
52
|
await rm(join(kitHome(), ENROLMENT), { force: true });
|
|
48
53
|
}
|
|
54
|
+
export async function forgetRejected(rejected) {
|
|
55
|
+
const held = await readHome(ENROLMENT);
|
|
56
|
+
if (held?.credential !== rejected)
|
|
57
|
+
return;
|
|
58
|
+
await writeHome(DISCONNECTED, { house: held.house, environment: held.environment });
|
|
59
|
+
const enrolment = join(kitHome(), ENROLMENT);
|
|
60
|
+
const taken = `${enrolment}.${process.pid}`;
|
|
61
|
+
try {
|
|
62
|
+
renameSync(enrolment, taken);
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
if (error.code === 'ENOENT')
|
|
66
|
+
return;
|
|
67
|
+
throw error;
|
|
68
|
+
}
|
|
69
|
+
if (JSON.parse(readFileSync(taken, 'utf8')).credential !== rejected) {
|
|
70
|
+
try {
|
|
71
|
+
linkSync(taken, enrolment);
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
if (error.code !== 'EEXIST')
|
|
75
|
+
throw error;
|
|
76
|
+
}
|
|
77
|
+
rmSync(join(kitHome(), DISCONNECTED), { force: true });
|
|
78
|
+
}
|
|
79
|
+
rmSync(taken);
|
|
80
|
+
}
|
|
49
81
|
export function enrolled() {
|
|
50
82
|
return existsSync(join(kitHome(), ENROLMENT));
|
|
51
83
|
}
|
|
84
|
+
export function restartAsked() {
|
|
85
|
+
return existsSync(join(kitHome(), RESTART));
|
|
86
|
+
}
|
|
87
|
+
export function forgetRestart() {
|
|
88
|
+
return rm(join(kitHome(), RESTART), { force: true });
|
|
89
|
+
}
|
|
52
90
|
export function readOwnAgent() {
|
|
53
91
|
return readHome(OWN_AGENT);
|
|
54
92
|
}
|