@cmodjs/core 8.7.0 → 8.8.0
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/docs/commands.md +1 -1
- package/docs/dependencies.md +1 -1
- package/docs/jobs.md +2 -2
- package/docs/session.md +4 -4
- package/docs/ui.md +2 -2
- package/jobs/prompt.js +14 -18
- package/mod.d.ts +32 -0
- package/mod.d.ts.map +1 -1
- package/package.json +1 -1
- package/records.d.ts +1 -1
- package/records.js +1 -1
- package/runtime/conversations.d.ts.map +1 -1
- package/runtime/conversations.js +27 -13
- package/runtime/interfaces.d.ts +5 -2
- package/runtime/interfaces.d.ts.map +1 -1
- package/runtime/interfaces.js +24 -8
- package/runtime/rpc.d.ts.map +1 -1
- package/runtime/rpc.js +6 -1
- package/session/conversation.d.ts.map +1 -1
- package/session/conversation.js +35 -13
- package/src/jobs/prompt.ts +13 -15
- package/src/mod.ts +1 -0
- package/src/records.ts +1 -1
- package/src/runtime/conversations.ts +26 -11
- package/src/runtime/interfaces.ts +27 -11
- package/src/runtime/rpc.ts +8 -1
- package/src/session/conversation.ts +35 -11
- package/src/testing/fake-serve.ts +6 -0
- package/testing/fake-serve.d.ts.map +1 -1
- package/testing/fake-serve.js +7 -0
package/runtime/interfaces.js
CHANGED
|
@@ -23,6 +23,7 @@ export const sessionActs = {
|
|
|
23
23
|
status: '$/status',
|
|
24
24
|
ui: '$/ui',
|
|
25
25
|
uiEvent: '$/uiEvent',
|
|
26
|
+
tasks: '$/tasks',
|
|
26
27
|
};
|
|
27
28
|
export const terminalInterface = 'cmod/Terminal';
|
|
28
29
|
export const providersInterface = 'cmod/Providers';
|
|
@@ -203,6 +204,7 @@ export const showLeaseMs = 16_000;
|
|
|
203
204
|
export function routeSessions({ computer, device, now, after, report, aliases = [], programs, terminals, }) {
|
|
204
205
|
const holders = new Map();
|
|
205
206
|
const holderOf = (session) => [...holders.values()].find((holder) => holder.session === session);
|
|
207
|
+
const toldAt = () => new Map([...holders.values()].map((holder) => [holder.session, holder.toldAt]));
|
|
206
208
|
const holding = (session) => {
|
|
207
209
|
const holder = holderOf(session);
|
|
208
210
|
return holder === undefined ? undefined : { session: holder.session, project: holder.project, cwd: holder.cwd };
|
|
@@ -216,7 +218,7 @@ export function routeSessions({ computer, device, now, after, report, aliases =
|
|
|
216
218
|
if (!sessionActions.includes(action))
|
|
217
219
|
throw new RpcError(rpcCodes.methodNotFound, `A session takes no ${action}.`);
|
|
218
220
|
if (action === 'visit') {
|
|
219
|
-
await computer.visit(session, typeof input === 'string' ? input : new Date(now()).toISOString());
|
|
221
|
+
await computer.visit(session, typeof input === 'string' ? input : new Date(now()).toISOString(), holding);
|
|
220
222
|
changed({ session, part: 'visit' });
|
|
221
223
|
return null;
|
|
222
224
|
}
|
|
@@ -241,19 +243,32 @@ export function routeSessions({ computer, device, now, after, report, aliases =
|
|
|
241
243
|
return { ...listed, ...(status === undefined ? {} : { status }), ...(waitingFor === undefined ? {} : { waitingFor }), ...(told.contextPercent === undefined ? {} : { contextPercent: told.contextPercent }), ...(told.lastTurn === undefined ? {} : { lastTurn: told.lastTurn }) };
|
|
242
244
|
};
|
|
243
245
|
const implementation = {
|
|
244
|
-
sessions: async (scope = {}) =>
|
|
245
|
-
|
|
246
|
-
|
|
246
|
+
sessions: async (scope = {}) => (await computer.sessions(scope, holding, toldAt())).map((listed) => withStatus(listed, holderOf(listed.id)?.told)),
|
|
247
|
+
session: async (session) => {
|
|
248
|
+
const found = await computer.session(session, holding, toldAt());
|
|
249
|
+
if (found === undefined)
|
|
250
|
+
throw new RpcError(rpcCodes.notHeld, `No session ${session} on this computer.`);
|
|
251
|
+
return withStatus(found, holderOf(session)?.told);
|
|
247
252
|
},
|
|
248
253
|
search: (text, options = {}) => computer.search(text, options),
|
|
249
|
-
read: (session, part, options = {}) =>
|
|
254
|
+
read: async (session, part, options = {}) => {
|
|
255
|
+
const saved = await computer.read(session, part, options, holding);
|
|
256
|
+
const holder = holderOf(session);
|
|
257
|
+
if (part !== 'tasks' || holder === undefined)
|
|
258
|
+
return saved;
|
|
259
|
+
return holder.connection.request(sessionActs.tasks, { saved, options }).catch((error) => {
|
|
260
|
+
if (error instanceof RpcError && error.code === rpcCodes.methodNotFound)
|
|
261
|
+
return saved;
|
|
262
|
+
throw error;
|
|
263
|
+
});
|
|
264
|
+
},
|
|
250
265
|
...Object.fromEntries(sessionActions.map((action) => [action, (session, input, context) => call(session, action, input ?? null, isObject(context) ? context : {})])),
|
|
251
266
|
};
|
|
252
267
|
const showing = async (session) => {
|
|
253
268
|
const holder = holderOf(session);
|
|
254
269
|
if (holder !== undefined)
|
|
255
270
|
return holder.connection;
|
|
256
|
-
const isRunning = (await computer.sessions({ running: true }, holding, new
|
|
271
|
+
const isRunning = (await computer.sessions({ running: true }, holding, new Map())).some((listed) => listed.id === session);
|
|
257
272
|
throw new RpcError(rpcCodes.notHeld, isRunning ? `Session ${session} runs here, but no cmod plugin of 7.0.0 or later in it reaches cmod serve, so its views show only in Claude Code. Run /reload-plugins in it to show them here.` : `No session ${session} runs on this computer, so it shows no UI.`);
|
|
258
273
|
};
|
|
259
274
|
const askedUi = async (session, method, args) => {
|
|
@@ -365,7 +380,7 @@ export function routeSessions({ computer, device, now, after, report, aliases =
|
|
|
365
380
|
for (const [each, holder] of holders)
|
|
366
381
|
if (holder.session === session && each !== connection)
|
|
367
382
|
holders.delete(each);
|
|
368
|
-
holders.set(connection, { session, project, cwd, ...(isObject(herdrTerminal) && typeof herdrTerminal.id === 'string' && typeof herdrTerminal.socket === 'string' ? { herdrTerminal: { id: herdrTerminal.id, socket: herdrTerminal.socket } } : {}), connection,
|
|
383
|
+
holders.set(connection, { session, project, cwd, ...(isObject(herdrTerminal) && typeof herdrTerminal.id === 'string' && typeof herdrTerminal.socket === 'string' ? { herdrTerminal: { id: herdrTerminal.id, socket: herdrTerminal.socket } } : {}), connection, ...(known?.session === session ? { told: known.told, toldAt: known.toldAt } : { told: {}, toldAt: 0 }) });
|
|
369
384
|
changed({ session, part: 'running' });
|
|
370
385
|
relisted(session);
|
|
371
386
|
toldShown.delete(session);
|
|
@@ -381,7 +396,8 @@ export function routeSessions({ computer, device, now, after, report, aliases =
|
|
|
381
396
|
const { session, ...told } = (isObject(params) ? params : {});
|
|
382
397
|
if (holder === undefined || holder.session !== session || JSON.stringify(told) === JSON.stringify(holder.told))
|
|
383
398
|
return { result: null };
|
|
384
|
-
|
|
399
|
+
const isMoved = told.status !== holder.told.status || JSON.stringify(told.waitingFor) !== JSON.stringify(holder.told.waitingFor);
|
|
400
|
+
holders.set(connection, { ...holder, told, toldAt: isMoved ? now() : holder.toldAt });
|
|
385
401
|
changed({ session: holder.session, part: 'status' });
|
|
386
402
|
return { result: null };
|
|
387
403
|
}
|
package/runtime/rpc.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rpc.d.ts","sourceRoot":"","sources":["../src/runtime/rpc.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,KAAK,GAAG,MAAM,GAAG,MAAM,CAAA;AAEnC,MAAM,MAAM,YAAY,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAA;CAAE,CAAA;AAEvG,MAAM,MAAM,UAAU,GAClB;IAAE,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAA;CAAE,GACnG;IAAE,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAA;CAAE,GAC/E;IAAE,QAAQ,CAAC,OAAO,EAA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AAG;IACzD,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAA;IAC7B,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CACvB,CAAA;AAED,wBAAgB,UAAU,CAAC,EACzB,IAAI,EACJ,MAAM,EACN,SAAS,EACT,OAAO,EACP,IAAI,EACJ,OAAc,EACd,eAAuB,GACxB,EAAE;IACD,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAA;IACvB,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAA;IAC3B,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,SAAS,KAAK,OAAO,CAAA;IACnD,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAA;IAC3C,QAAQ,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAC5C,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,eAAe,CAAC,EAAE,OAAO,CAAA;CACnC,GAAG,SAAS,CA2IZ"}
|
package/runtime/rpc.js
CHANGED
|
@@ -169,6 +169,7 @@ export function rpcRoutes({ handle, onClose, now, pollMs = 8000, liveMs = 30_000
|
|
|
169
169
|
if (each === undefined)
|
|
170
170
|
return;
|
|
171
171
|
held.delete(id);
|
|
172
|
+
timers.clearTimeout(each.unpolled);
|
|
172
173
|
each.poll?.([]);
|
|
173
174
|
each.connection.close(new Error(reason));
|
|
174
175
|
onClose?.(each.connection);
|
|
@@ -182,8 +183,10 @@ export function rpcRoutes({ handle, onClose, now, pollMs = 8000, liveMs = 30_000
|
|
|
182
183
|
if (entry === undefined)
|
|
183
184
|
return;
|
|
184
185
|
outbox.push(message);
|
|
185
|
-
if (entry.poll === undefined)
|
|
186
|
+
if (entry.poll === undefined) {
|
|
187
|
+
entry.unpolled ??= timers.setTimeout(() => drop(id, `no poll for ${pollMs / 1000} s while a message waited`), pollMs);
|
|
186
188
|
return;
|
|
189
|
+
}
|
|
187
190
|
const poll = entry.poll;
|
|
188
191
|
entry.poll = undefined;
|
|
189
192
|
poll(takenWithin(outbox, entry.chars));
|
|
@@ -210,6 +213,8 @@ export function rpcRoutes({ handle, onClose, now, pollMs = 8000, liveMs = 30_000
|
|
|
210
213
|
};
|
|
211
214
|
const poll = (each, signal, chars) => new Promise((resolve) => {
|
|
212
215
|
each.poll?.([]);
|
|
216
|
+
timers.clearTimeout(each.unpolled);
|
|
217
|
+
each.unpolled = undefined;
|
|
213
218
|
each.chars = chars;
|
|
214
219
|
if (each.outbox.length > 0)
|
|
215
220
|
return resolve(takenWithin(each.outbox, chars));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conversation.d.ts","sourceRoot":"","sources":["../src/session/conversation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,KAAK,OAAO,EAAE,MAAM,sBAAsB,CAAA;AAC7E,OAAO,EAAY,KAAK,MAAM,EAAE,MAAM,0BAA0B,CAAA;AAChE,OAAO,EAAE,OAAO,EAA6B,KAAK,GAAG,EAAE,KAAK,QAAQ,EAAE,MAAM,mCAAmC,CAAA;AAG/G,OAAO,EAAE,QAAQ,EAAE,MAAM,qCAAqC,CAAA;AAE9D,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,IAAI,EAAE,MAAM,wBAAwB,CAAA;AACtE,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAC1E,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AAE/D,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;I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ation.js
CHANGED
|
@@ -28,6 +28,12 @@ export function placedMessage(where, unplaced, task, isInTurn = true, agentType
|
|
|
28
28
|
export const searchLimit = 50;
|
|
29
29
|
const agentTools = ['Agent', 'Task'];
|
|
30
30
|
const asyncLaunch = 'Async agent launched';
|
|
31
|
+
const stopTool = 'TaskStop';
|
|
32
|
+
function endedStatusOf(told) {
|
|
33
|
+
if (told === 'completed' || told === 'failed' || told === 'killed')
|
|
34
|
+
return told;
|
|
35
|
+
return told === 'stopped' ? 'killed' : undefined;
|
|
36
|
+
}
|
|
31
37
|
export function emptyConversation(session) {
|
|
32
38
|
return { session, context: 0, contextOpenedAt: '', agentCalls: [], endedCalls: {}, tasks: {}, taskTurns: {} };
|
|
33
39
|
}
|
|
@@ -69,7 +75,14 @@ export function createConversation(start) {
|
|
|
69
75
|
turn = undefined;
|
|
70
76
|
return [{ type: TurnEnd, turn: ended }];
|
|
71
77
|
};
|
|
72
|
-
const
|
|
78
|
+
const close = (task, at, status) => {
|
|
79
|
+
if (task.closedAt !== undefined)
|
|
80
|
+
return [];
|
|
81
|
+
const ended = { ...task, closedAt: at, ...(status === undefined ? {} : { status }) };
|
|
82
|
+
tasks.set(task.id, ended);
|
|
83
|
+
return [...endTaskTurn(task.id, at), { type: TaskEnd, task: ended }];
|
|
84
|
+
};
|
|
85
|
+
const endCall = (call, at, only, status) => {
|
|
73
86
|
const opened = [...tasks.values()].filter((each) => each.openedBy === call && (only === undefined || each.id === only));
|
|
74
87
|
if (opened.length === 0) {
|
|
75
88
|
if (agentCalls.has(call))
|
|
@@ -78,13 +91,20 @@ export function createConversation(start) {
|
|
|
78
91
|
}
|
|
79
92
|
if (only === undefined)
|
|
80
93
|
agentCalls.delete(call);
|
|
81
|
-
return opened.flatMap((task) =>
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
94
|
+
return opened.flatMap((task) => close(task, at, status));
|
|
95
|
+
};
|
|
96
|
+
const notified = (text, at) => {
|
|
97
|
+
const call = tagOf(text, 'tool-use-id');
|
|
98
|
+
const id = tagOf(text, 'task-id');
|
|
99
|
+
const told = tagOf(text, 'status');
|
|
100
|
+
const status = told === undefined ? undefined : endedStatusOf(told);
|
|
101
|
+
if (told !== undefined && status === undefined)
|
|
102
|
+
return [];
|
|
103
|
+
const byCall = call !== undefined && agentCalls.has(call) ? endCall(call, at, id, status) : [];
|
|
104
|
+
if (byCall.length > 0 || id === undefined)
|
|
105
|
+
return byCall;
|
|
106
|
+
const task = tasks.get(id);
|
|
107
|
+
return task === undefined ? [] : close(task, at, status);
|
|
88
108
|
};
|
|
89
109
|
const changeGoal = (text) => {
|
|
90
110
|
goal = text;
|
|
@@ -137,12 +157,14 @@ export function createConversation(start) {
|
|
|
137
157
|
if (placed.type === ToolCall && agentTools.includes(placed.name))
|
|
138
158
|
agentCalls.add(placed.callId);
|
|
139
159
|
if (placed.type === ToolResult && agentCalls.has(placed.callId) && !String(placed.output).startsWith(asyncLaunch))
|
|
140
|
-
changes.push(...endCall(placed.callId, row.at));
|
|
141
|
-
if (placed.type ===
|
|
142
|
-
const
|
|
143
|
-
if (
|
|
144
|
-
changes.push(...
|
|
160
|
+
changes.push(...endCall(placed.callId, row.at, undefined, placed.isError ? 'failed' : 'completed'));
|
|
161
|
+
if (placed.type === ToolResult && placed.name === stopTool && !placed.isError && typeof placed.input['task_id'] === 'string') {
|
|
162
|
+
const stopped = tasks.get(placed.input['task_id']);
|
|
163
|
+
if (stopped !== undefined)
|
|
164
|
+
changes.push(...close(stopped, row.at, 'killed'));
|
|
145
165
|
}
|
|
166
|
+
if (placed.type === Note && placed.from.type === Task)
|
|
167
|
+
changes.push(...notified(textOf(row.content), row.at));
|
|
146
168
|
}
|
|
147
169
|
return changes;
|
|
148
170
|
},
|
package/src/jobs/prompt.ts
CHANGED
|
@@ -55,11 +55,10 @@ export function prompt<State extends object = Record<never, never>>({ name, prom
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
function addKeptCurrent<State extends object>(job: JobContext<State>, name: string, textFor: () => Promise<string | undefined>, log: (reason: string) => void): Subscription {
|
|
58
|
-
const {
|
|
58
|
+
const { router } = engineOf(job.mod)
|
|
59
59
|
let given: string | undefined
|
|
60
60
|
let hasStarted = false
|
|
61
|
-
let
|
|
62
|
-
let updates = Promise.resolve()
|
|
61
|
+
let isChanged = false
|
|
63
62
|
|
|
64
63
|
const starting = router.add('classic.SessionStart', (e, next) => {
|
|
65
64
|
hasStarted = e.source === 'resume' || e.source === 'compact'
|
|
@@ -77,25 +76,24 @@ function addKeptCurrent<State extends object>(job: JobContext<State>, name: stri
|
|
|
77
76
|
return given === undefined ? below : { ...below, blocks: [...below.blocks, { name, text: given }] }
|
|
78
77
|
})
|
|
79
78
|
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
79
|
+
const handedOver = async <Below,>(below: Below): Promise<Below> => {
|
|
80
|
+
if (!hasStarted || !isChanged) return below
|
|
81
|
+
isChanged = false
|
|
83
82
|
const value = await textFor()
|
|
84
|
-
if (value === undefined || value === given) return
|
|
83
|
+
if (value === undefined || value === given) return below
|
|
85
84
|
given = value
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
})
|
|
85
|
+
const fields = (below ?? {}) as Readonly<Record<string, unknown>>
|
|
86
|
+
return { ...fields, additionalContext: [...((fields['additionalContext'] as readonly string[] | undefined) ?? []), modNote(job.mod.name, `# ${name}\n${value}`)] } as Below
|
|
89
87
|
}
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
updates = updates.then(update).catch((error: unknown) => log(messageOf(error)))
|
|
94
|
-
})
|
|
88
|
+
const prompted = router.add('classic.UserPromptSubmit', async (e, next) => handedOver(await next(e)))
|
|
89
|
+
const batched = router.add('classic.PostToolBatch', async (e, next) => (e.agent_id === undefined ? handedOver(await next(e)) : next(e)))
|
|
90
|
+
const following = onStateChange(job.mod.state, () => void (isChanged = true))
|
|
95
91
|
return {
|
|
96
92
|
remove() {
|
|
97
93
|
starting.remove()
|
|
98
94
|
adding.remove()
|
|
95
|
+
prompted.remove()
|
|
96
|
+
batched.remove()
|
|
99
97
|
following.remove()
|
|
100
98
|
},
|
|
101
99
|
}
|
package/src/mod.ts
CHANGED
|
@@ -120,6 +120,7 @@ declare module 'claude-code' {
|
|
|
120
120
|
'cmod/Sessions': {
|
|
121
121
|
methods: {
|
|
122
122
|
sessions(scope?: { project?: string; everyProject?: boolean; running?: boolean; since?: string }): { id: string; title: string; color?: string; project: string; cwd: string; model: string; startedAt: string; lastAt: string; forkedFrom?: string; isRunning: boolean; agentType?: string; transcriptPath?: string; visitedAt?: string; device?: { id: string; name: string }; status?: 'busy' | 'shell' | 'idle' | 'waiting'; waitingFor?: { dialog: string; tool?: string; input?: Record<string, unknown>; question?: string }; contextPercent?: number; lastTurn?: { reason: 'answered' | 'stopped' | 'failed'; at: string; failure?: string } }[]
|
|
123
|
+
session(session: string): { id: string; title: string; color?: string; project: string; cwd: string; model: string; startedAt: string; lastAt: string; forkedFrom?: string; isRunning: boolean; agentType?: string; transcriptPath?: string; visitedAt?: string; device?: { id: string; name: string }; status?: 'busy' | 'shell' | 'idle' | 'waiting'; waitingFor?: { dialog: string; tool?: string; input?: Record<string, unknown>; question?: string }; contextPercent?: number; lastTurn?: { reason: 'answered' | 'stopped' | 'failed'; at: string; failure?: string } }
|
|
123
124
|
search(text: string, options?: { project?: string; everyProject?: boolean; running?: boolean; since?: string; limit?: number; before?: { session: string; id: string }; record?: { session?: string; task?: string; turn?: string; context?: number; isAgent?: true } }): unknown[]
|
|
124
125
|
read(session: string, part: 'messages' | 'turns' | 'contexts' | 'tasks' | 'goal' | 'usage' | 'state', options?: { project?: string; task?: string; turn?: string; context?: number; after?: string; last?: number; all?: true }): unknown
|
|
125
126
|
send(session: string, message: { type: 'prompt' | 'note'; text: string; as?: 'person' | 'session' }, context?: { project?: string; caller?: string; task?: string }): void
|
package/src/records.ts
CHANGED
|
@@ -499,7 +499,7 @@ function readHotkeys(hotkeys: unknown): Steps {
|
|
|
499
499
|
return { hotkeys: checkHotkeys('package.json "cmod"', hotkeys as Record<string, HotkeyInit>) }
|
|
500
500
|
}
|
|
501
501
|
|
|
502
|
-
export const coreVersion = '8.
|
|
502
|
+
export const coreVersion = '8.8.0'
|
|
503
503
|
|
|
504
504
|
export const oldestCmodVersion = '8.0.0'
|
|
505
505
|
|
|
@@ -7,7 +7,7 @@ import { createConversation, emptyConversation, ownerOfSpawn, tasksWithAgents, t
|
|
|
7
7
|
import { Session, UsageChange, type BeforeEvent, type Surface, type SessionSend, type TaskStartArgs, type ToolCallArgs } from '../session/session.js'
|
|
8
8
|
import { GoalChange } from '../session/goal/goal.js'
|
|
9
9
|
import { TurnEnd, TurnStart } from '../session/context/turn/turn.js'
|
|
10
|
-
import { TaskStart } from '../session/goal/task.js'
|
|
10
|
+
import { TaskEnd, TaskStart } from '../session/goal/task.js'
|
|
11
11
|
import { receivedMatcher } from '../utils/matcher.js'
|
|
12
12
|
import { resolve } from '../vendor.js'
|
|
13
13
|
import { ifMissing } from '../utils/paths.js'
|
|
@@ -211,9 +211,21 @@ export function serveConversations({
|
|
|
211
211
|
|
|
212
212
|
let ui: Implementation = {}
|
|
213
213
|
|
|
214
|
+
const liveTasksOver = async (saved: readonly TaskData[], request: Readonly<Record<string, unknown>>): Promise<TaskData[]> => {
|
|
215
|
+
await starting
|
|
216
|
+
const kept = liveTasks().filter((task) => request['all'] === true || task.parent === request['task'])
|
|
217
|
+
const running = await claude.agent.list().catch((error: unknown) => (claude.ui.warn('tasks:status', `cmod: the tasks show no status, because Claude Code listed no agents: ${messageOf(error)}`), []))
|
|
218
|
+
const background = saved.flatMap(({ id, status, isBackground }) => (status === undefined || isBackground !== true ? [] : [{ id, status }]))
|
|
219
|
+
return tasksWithAgents(merged(saved, kept, (task) => task.id), [...running, ...background])
|
|
220
|
+
}
|
|
221
|
+
|
|
214
222
|
const handle = async (method: string, params: unknown, signal: AbortSignal): Promise<unknown> => {
|
|
215
223
|
const answered = await held.handler(method, params, signal)
|
|
216
224
|
if (answered !== undefined) return answered.result
|
|
225
|
+
if (method === sessionActs.tasks) {
|
|
226
|
+
const { saved, options } = (isObject(params) ? params : {}) as { readonly saved?: unknown; readonly options?: unknown }
|
|
227
|
+
return liveTasksOver(Array.isArray(saved) ? (saved as TaskData[]) : [], isObject(options) ? options : {})
|
|
228
|
+
}
|
|
217
229
|
if (method === sessionActs.act) {
|
|
218
230
|
const { action, input, caller, task } = params as { readonly action: string; readonly input: unknown; readonly caller?: string; readonly task?: string }
|
|
219
231
|
if (!isAct(action)) throw new RpcError(rpcCodes.methodNotFound, (await unknownTo(`"${action}" action`)).message)
|
|
@@ -360,6 +372,7 @@ export function serveConversations({
|
|
|
360
372
|
const closings = new Map<string, TurnData>()
|
|
361
373
|
let onTurnClosed: (turn: TurnData) => void = () => undefined
|
|
362
374
|
const dispatch = (changes: readonly SessionChange[]) => {
|
|
375
|
+
if (session !== '' && changes.some((change) => change.type === TaskStart || change.type === TaskEnd)) local.client.notify(sessionActs.changed, { session, part: 'tasks' })
|
|
363
376
|
for (const change of changes) {
|
|
364
377
|
if ((change.type === TurnStart || change.type === TurnEnd) && change.turn.prompt.task === undefined) lastTurn = change.turn
|
|
365
378
|
if (change.type === Message && !liveIds.has(change.message.id)) {
|
|
@@ -842,6 +855,7 @@ export function serveConversations({
|
|
|
842
855
|
openedBy: task.openedBy,
|
|
843
856
|
openedAt: task.openedAt,
|
|
844
857
|
...(task.closedAt === undefined ? {} : { closedAt: task.closedAt }),
|
|
858
|
+
...(task.status === undefined ? {} : { status: task.status }),
|
|
845
859
|
...(task.parent === undefined ? {} : { parent: task.parent }),
|
|
846
860
|
...(task.forkedFrom === undefined ? {} : { forkedFrom: task.forkedFrom }),
|
|
847
861
|
...(task.isBackground === true ? { isBackground: true as const } : {}),
|
|
@@ -869,8 +883,16 @@ export function serveConversations({
|
|
|
869
883
|
},
|
|
870
884
|
async [conversationMethods.session](request) {
|
|
871
885
|
const id = String(request['session'])
|
|
872
|
-
const
|
|
873
|
-
|
|
886
|
+
const lookedUp = (client: Pick<RpcClient, 'request'>) =>
|
|
887
|
+
client.request<SessionData>(`${sessionsInterface}.session`, [id]).catch(async (error: unknown) => {
|
|
888
|
+
if (!(error instanceof RpcError && error.code === rpcCodes.methodNotFound)) throw error
|
|
889
|
+
const listed = (await client.request<SessionData[]>(`${sessionsInterface}.sessions`, [{ everyProject: true }])).find((each) => each.id === id)
|
|
890
|
+
if (listed === undefined) throw new RpcError(rpcCodes.notHeld, `No session ${id} on this provider.`)
|
|
891
|
+
return listed
|
|
892
|
+
})
|
|
893
|
+
const found = await firstHolding(lookedUp).catch((error: unknown) => {
|
|
894
|
+
throw isNotHeld(error) ? new Error(`no session ${id} on any of your devices.`) : error
|
|
895
|
+
})
|
|
874
896
|
return found.id === session ? { ...found, isRunning: true } : found
|
|
875
897
|
},
|
|
876
898
|
async [conversationMethods.search](request) {
|
|
@@ -911,14 +933,7 @@ export function serveConversations({
|
|
|
911
933
|
},
|
|
912
934
|
async [conversationMethods.tasks](request) {
|
|
913
935
|
const id = String(request['session'])
|
|
914
|
-
|
|
915
|
-
const saved = await read<TaskData[]>(id, 'tasks', isNested ? { all: true } : fields(request, ['task']))
|
|
916
|
-
if (id !== session) return saved
|
|
917
|
-
await starting
|
|
918
|
-
const kept = liveTasks().filter((task) => isNested || task.parent === request['task'])
|
|
919
|
-
const running = await claude.agent.list().catch((error: unknown) => (claude.ui.warn('tasks:status', `cmod: the tasks show no status, because Claude Code listed no agents: ${messageOf(error)}`), []))
|
|
920
|
-
const background = saved.flatMap(({ id, status }) => (status === undefined ? [] : [{ id, status }]))
|
|
921
|
-
return tasksWithAgents(merged(saved, kept, (task) => task.id), [...running, ...background])
|
|
936
|
+
return read<TaskData[]>(id, 'tasks', request['all'] === true ? { all: true } : fields(request, ['task']))
|
|
922
937
|
},
|
|
923
938
|
async [conversationMethods.goal](request) {
|
|
924
939
|
const id = String(request['session'])
|
|
@@ -41,6 +41,7 @@ export const sessionActs = {
|
|
|
41
41
|
status: '$/status',
|
|
42
42
|
ui: '$/ui',
|
|
43
43
|
uiEvent: '$/uiEvent',
|
|
44
|
+
tasks: '$/tasks',
|
|
44
45
|
} as const
|
|
45
46
|
|
|
46
47
|
export const terminalInterface = 'cmod/Terminal'
|
|
@@ -313,12 +314,15 @@ export type SessionContext = Readonly<Record<string, unknown>>
|
|
|
313
314
|
|
|
314
315
|
export type HoldingOf = (session: string) => HeldSession | undefined
|
|
315
316
|
|
|
317
|
+
export type ToldAt = ReadonlyMap<string, number>
|
|
318
|
+
|
|
316
319
|
export type SessionComputer = {
|
|
317
|
-
sessions(scope: Readonly<Record<string, unknown>>, holding: HoldingOf,
|
|
320
|
+
sessions(scope: Readonly<Record<string, unknown>>, holding: HoldingOf, told: ToldAt): readonly SessionData[] | Promise<readonly SessionData[]>
|
|
321
|
+
session(session: string, holding: HoldingOf, told: ToldAt): SessionData | undefined | Promise<SessionData | undefined>
|
|
318
322
|
search(text: string, options: Readonly<Record<string, unknown>>): unknown
|
|
319
323
|
read(session: string, part: string, options: Readonly<Record<string, unknown>>, holding: HoldingOf): unknown
|
|
320
324
|
unheld(session: string, action: string, input: unknown, context: SessionContext, holding: HoldingOf): Promise<unknown>
|
|
321
|
-
visit(session: string, at: string): Promise<void>
|
|
325
|
+
visit(session: string, at: string, holding: HoldingOf): Promise<void>
|
|
322
326
|
remove(session: string, context: SessionContext, holding: HoldingOf): Promise<void>
|
|
323
327
|
}
|
|
324
328
|
|
|
@@ -356,9 +360,10 @@ export function routeSessions({
|
|
|
356
360
|
readonly programs?: ProgramReach
|
|
357
361
|
readonly terminals?: SessionTerminals
|
|
358
362
|
}): SessionRouting {
|
|
359
|
-
type Holder = HeldSession & { readonly connection: Pick<Peer, 'request' | 'notify'>; readonly told: HeldStatus }
|
|
363
|
+
type Holder = HeldSession & { readonly connection: Pick<Peer, 'request' | 'notify'>; readonly told: HeldStatus; readonly toldAt: number }
|
|
360
364
|
const holders = new Map<Pick<Peer, 'request' | 'notify'>, Holder>()
|
|
361
365
|
const holderOf = (session: string) => [...holders.values()].find((holder) => holder.session === session)
|
|
366
|
+
const toldAt = (): ToldAt => new Map([...holders.values()].map((holder) => [holder.session, holder.toldAt]))
|
|
362
367
|
const holding: HoldingOf = (session) => {
|
|
363
368
|
const holder = holderOf(session)
|
|
364
369
|
return holder === undefined ? undefined : { session: holder.session, project: holder.project, cwd: holder.cwd }
|
|
@@ -372,7 +377,7 @@ export function routeSessions({
|
|
|
372
377
|
const call = async (session: string, action: string, input: unknown, context: SessionContext = {}): Promise<unknown> => {
|
|
373
378
|
if (!(sessionActions as readonly string[]).includes(action)) throw new RpcError(rpcCodes.methodNotFound, `A session takes no ${action}.`)
|
|
374
379
|
if (action === 'visit') {
|
|
375
|
-
await computer.visit(session, typeof input === 'string' ? input : new Date(now()).toISOString())
|
|
380
|
+
await computer.visit(session, typeof input === 'string' ? input : new Date(now()).toISOString(), holding)
|
|
376
381
|
changed({ session, part: 'visit' })
|
|
377
382
|
return null
|
|
378
383
|
}
|
|
@@ -396,19 +401,29 @@ export function routeSessions({
|
|
|
396
401
|
}
|
|
397
402
|
|
|
398
403
|
const implementation: Implementation = {
|
|
399
|
-
sessions: async (scope: Readonly<Record<string, unknown>> = {}) =>
|
|
400
|
-
|
|
401
|
-
|
|
404
|
+
sessions: async (scope: Readonly<Record<string, unknown>> = {}) => (await computer.sessions(scope, holding, toldAt())).map((listed) => withStatus(listed, holderOf(listed.id)?.told)),
|
|
405
|
+
session: async (session: string) => {
|
|
406
|
+
const found = await computer.session(session, holding, toldAt())
|
|
407
|
+
if (found === undefined) throw new RpcError(rpcCodes.notHeld, `No session ${session} on this computer.`)
|
|
408
|
+
return withStatus(found, holderOf(session)?.told)
|
|
402
409
|
},
|
|
403
410
|
search: (text: string, options: Readonly<Record<string, unknown>> = {}) => computer.search(text, options),
|
|
404
|
-
read: (session: string, part: string, options: Readonly<Record<string, unknown>> = {}) =>
|
|
411
|
+
read: async (session: string, part: string, options: Readonly<Record<string, unknown>> = {}) => {
|
|
412
|
+
const saved = await computer.read(session, part, options, holding)
|
|
413
|
+
const holder = holderOf(session)
|
|
414
|
+
if (part !== 'tasks' || holder === undefined) return saved
|
|
415
|
+
return holder.connection.request(sessionActs.tasks, { saved, options }).catch((error: unknown) => {
|
|
416
|
+
if (error instanceof RpcError && error.code === rpcCodes.methodNotFound) return saved
|
|
417
|
+
throw error
|
|
418
|
+
})
|
|
419
|
+
},
|
|
405
420
|
...Object.fromEntries(sessionActions.map((action) => [action, (session: string, input?: unknown, context?: unknown) => call(session, action, input ?? null, isObject(context) ? context : {})])),
|
|
406
421
|
}
|
|
407
422
|
|
|
408
423
|
const showing = async (session: string) => {
|
|
409
424
|
const holder = holderOf(session)
|
|
410
425
|
if (holder !== undefined) return holder.connection
|
|
411
|
-
const isRunning = (await computer.sessions({ running: true }, holding, new
|
|
426
|
+
const isRunning = (await computer.sessions({ running: true }, holding, new Map())).some((listed) => listed.id === session)
|
|
412
427
|
throw new RpcError(rpcCodes.notHeld, isRunning ? `Session ${session} runs here, but no cmod plugin of 7.0.0 or later in it reaches cmod serve, so its views show only in Claude Code. Run /reload-plugins in it to show them here.` : `No session ${session} runs on this computer, so it shows no UI.`)
|
|
413
428
|
}
|
|
414
429
|
|
|
@@ -511,7 +526,7 @@ export function routeSessions({
|
|
|
511
526
|
const { session, project, cwd, herdrTerminal } = params as HeldSession
|
|
512
527
|
const known = holders.get(connection)
|
|
513
528
|
for (const [each, holder] of holders) if (holder.session === session && each !== connection) holders.delete(each)
|
|
514
|
-
holders.set(connection, { session, project, cwd, ...(isObject(herdrTerminal) && typeof herdrTerminal.id === 'string' && typeof herdrTerminal.socket === 'string' ? { herdrTerminal: { id: herdrTerminal.id, socket: herdrTerminal.socket } } : {}), connection,
|
|
529
|
+
holders.set(connection, { session, project, cwd, ...(isObject(herdrTerminal) && typeof herdrTerminal.id === 'string' && typeof herdrTerminal.socket === 'string' ? { herdrTerminal: { id: herdrTerminal.id, socket: herdrTerminal.socket } } : {}), connection, ...(known?.session === session ? { told: known.told, toldAt: known.toldAt } : { told: {}, toldAt: 0 }) })
|
|
515
530
|
changed({ session, part: 'running' })
|
|
516
531
|
relisted(session)
|
|
517
532
|
toldShown.delete(session)
|
|
@@ -526,7 +541,8 @@ export function routeSessions({
|
|
|
526
541
|
const holder = holders.get(connection)
|
|
527
542
|
const { session, ...told } = (isObject(params) ? params : {}) as HeldStatus & { readonly session?: unknown }
|
|
528
543
|
if (holder === undefined || holder.session !== session || JSON.stringify(told) === JSON.stringify(holder.told)) return { result: null }
|
|
529
|
-
|
|
544
|
+
const isMoved = told.status !== holder.told.status || JSON.stringify(told.waitingFor) !== JSON.stringify(holder.told.waitingFor)
|
|
545
|
+
holders.set(connection, { ...holder, told, toldAt: isMoved ? now() : holder.toldAt })
|
|
530
546
|
changed({ session: holder.session, part: 'status' })
|
|
531
547
|
return { result: null }
|
|
532
548
|
}
|
package/src/runtime/rpc.ts
CHANGED
|
@@ -189,6 +189,7 @@ type Held = {
|
|
|
189
189
|
poll: ((messages: RpcMessage[]) => void) | undefined
|
|
190
190
|
chars: number | undefined
|
|
191
191
|
seenAt: number
|
|
192
|
+
unpolled?: unknown
|
|
192
193
|
}
|
|
193
194
|
|
|
194
195
|
export type RpcHttpRequest = { readonly method: string; readonly path: string; readonly signal: AbortSignal; json(): Promise<unknown> }
|
|
@@ -223,6 +224,7 @@ export function rpcRoutes({
|
|
|
223
224
|
const each = held.get(id)
|
|
224
225
|
if (each === undefined) return
|
|
225
226
|
held.delete(id)
|
|
227
|
+
timers.clearTimeout(each.unpolled)
|
|
226
228
|
each.poll?.([])
|
|
227
229
|
each.connection.close(new Error(reason))
|
|
228
230
|
onClose?.(each.connection)
|
|
@@ -236,7 +238,10 @@ export function rpcRoutes({
|
|
|
236
238
|
send: (message) => {
|
|
237
239
|
if (entry === undefined) return
|
|
238
240
|
outbox.push(message)
|
|
239
|
-
if (entry.poll === undefined)
|
|
241
|
+
if (entry.poll === undefined) {
|
|
242
|
+
entry.unpolled ??= timers.setTimeout(() => drop(id, `no poll for ${pollMs / 1000} s while a message waited`), pollMs)
|
|
243
|
+
return
|
|
244
|
+
}
|
|
240
245
|
const poll = entry.poll
|
|
241
246
|
entry.poll = undefined
|
|
242
247
|
poll(takenWithin(outbox, entry.chars))
|
|
@@ -264,6 +269,8 @@ export function rpcRoutes({
|
|
|
264
269
|
const poll = (each: Held, signal: AbortSignal, chars: number | undefined) =>
|
|
265
270
|
new Promise<RpcMessage[]>((resolve) => {
|
|
266
271
|
each.poll?.([])
|
|
272
|
+
timers.clearTimeout(each.unpolled)
|
|
273
|
+
each.unpolled = undefined
|
|
267
274
|
each.chars = chars
|
|
268
275
|
if (each.outbox.length > 0) return resolve(takenWithin(each.outbox, chars))
|
|
269
276
|
const timer = timers.setTimeout(() => answer([]), pollMs)
|
|
@@ -110,6 +110,15 @@ const agentTools: readonly string[] = ['Agent', 'Task']
|
|
|
110
110
|
|
|
111
111
|
const asyncLaunch = 'Async agent launched'
|
|
112
112
|
|
|
113
|
+
const stopTool = 'TaskStop'
|
|
114
|
+
|
|
115
|
+
type EndedStatus = Extract<TaskStatus, 'completed' | 'failed' | 'killed'>
|
|
116
|
+
|
|
117
|
+
function endedStatusOf(told: string): EndedStatus | undefined {
|
|
118
|
+
if (told === 'completed' || told === 'failed' || told === 'killed') return told
|
|
119
|
+
return told === 'stopped' ? 'killed' : undefined
|
|
120
|
+
}
|
|
121
|
+
|
|
113
122
|
export function emptyConversation(session: string): ConversationState {
|
|
114
123
|
return { session, context: 0, contextOpenedAt: '', agentCalls: [], endedCalls: {}, tasks: {}, taskTurns: {} }
|
|
115
124
|
}
|
|
@@ -155,19 +164,33 @@ export function createConversation(start: ConversationState): Conversation {
|
|
|
155
164
|
return [{ type: TurnEnd, turn: ended }]
|
|
156
165
|
}
|
|
157
166
|
|
|
158
|
-
const
|
|
167
|
+
const close = (task: RunningTask, at: string, status: EndedStatus | undefined): SessionChange[] => {
|
|
168
|
+
if (task.closedAt !== undefined) return []
|
|
169
|
+
const ended = { ...task, closedAt: at, ...(status === undefined ? {} : { status }) }
|
|
170
|
+
tasks.set(task.id, ended)
|
|
171
|
+
return [...endTaskTurn(task.id, at), { type: TaskEnd, task: ended }]
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const endCall = (call: string, at: string, only?: string, status?: EndedStatus): SessionChange[] => {
|
|
159
175
|
const opened = [...tasks.values()].filter((each) => each.openedBy === call && (only === undefined || each.id === only))
|
|
160
176
|
if (opened.length === 0) {
|
|
161
177
|
if (agentCalls.has(call)) endedCalls.set(call, at)
|
|
162
178
|
return []
|
|
163
179
|
}
|
|
164
180
|
if (only === undefined) agentCalls.delete(call)
|
|
165
|
-
return opened.flatMap((task) =>
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
181
|
+
return opened.flatMap((task) => close(task, at, status))
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const notified = (text: string, at: string): SessionChange[] => {
|
|
185
|
+
const call = tagOf(text, 'tool-use-id')
|
|
186
|
+
const id = tagOf(text, 'task-id')
|
|
187
|
+
const told = tagOf(text, 'status')
|
|
188
|
+
const status = told === undefined ? undefined : endedStatusOf(told)
|
|
189
|
+
if (told !== undefined && status === undefined) return []
|
|
190
|
+
const byCall = call !== undefined && agentCalls.has(call) ? endCall(call, at, id, status) : []
|
|
191
|
+
if (byCall.length > 0 || id === undefined) return byCall
|
|
192
|
+
const task = tasks.get(id)
|
|
193
|
+
return task === undefined ? [] : close(task, at, status)
|
|
171
194
|
}
|
|
172
195
|
|
|
173
196
|
const changeGoal = (text: string): SessionChange[] => {
|
|
@@ -211,11 +234,12 @@ export function createConversation(start: ConversationState): Conversation {
|
|
|
211
234
|
} as Message
|
|
212
235
|
changes.push({ type: Message, message: placed })
|
|
213
236
|
if (placed.type === ToolCall && agentTools.includes(placed.name)) agentCalls.add(placed.callId)
|
|
214
|
-
if (placed.type === ToolResult && agentCalls.has(placed.callId) && !String(placed.output).startsWith(asyncLaunch)) changes.push(...endCall(placed.callId, row.at))
|
|
215
|
-
if (placed.type ===
|
|
216
|
-
const
|
|
217
|
-
if (
|
|
237
|
+
if (placed.type === ToolResult && agentCalls.has(placed.callId) && !String(placed.output).startsWith(asyncLaunch)) changes.push(...endCall(placed.callId, row.at, undefined, placed.isError ? 'failed' : 'completed'))
|
|
238
|
+
if (placed.type === ToolResult && placed.name === stopTool && !placed.isError && typeof placed.input['task_id'] === 'string') {
|
|
239
|
+
const stopped = tasks.get(placed.input['task_id'])
|
|
240
|
+
if (stopped !== undefined) changes.push(...close(stopped, row.at, 'killed'))
|
|
218
241
|
}
|
|
242
|
+
if (placed.type === Note && placed.from.type === Task) changes.push(...notified(textOf(row.content), row.at))
|
|
219
243
|
}
|
|
220
244
|
return changes
|
|
221
245
|
},
|
|
@@ -38,6 +38,7 @@ const notHere = (session: string) => new RpcError(rpcCodes.notHeld, `No session
|
|
|
38
38
|
|
|
39
39
|
const unfaked: SessionComputer = {
|
|
40
40
|
sessions: () => [],
|
|
41
|
+
session: () => undefined,
|
|
41
42
|
search: () => [],
|
|
42
43
|
read: (_session, part) => (part === 'goal' ? { text: '' } : part === 'state' ? null : []),
|
|
43
44
|
unheld: (session) => Promise.reject(notHere(session)),
|
|
@@ -73,6 +74,11 @@ export function fakeServe(
|
|
|
73
74
|
},
|
|
74
75
|
computer: {
|
|
75
76
|
sessions: (...args) => answer('sessions')(...args),
|
|
77
|
+
session: async (session, holding, told) => {
|
|
78
|
+
const own = fakes().session
|
|
79
|
+
if (own !== undefined) return own(session, holding, told)
|
|
80
|
+
return (await answer('sessions')({ everyProject: true }, holding, told)).find((each) => each.id === session)
|
|
81
|
+
},
|
|
76
82
|
search: (...args) => answer('search')(...args),
|
|
77
83
|
read: (...args) => answer('read')(...args),
|
|
78
84
|
unheld: (...args) => answer('unheld')(...args),
|