@cmodjs/core 6.3.0 → 8.0.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 +123 -65
- package/docs/dependencies.md +189 -4
- package/docs/index.md +56 -12
- package/docs/install-steps.md +20 -17
- package/docs/jobs.md +43 -16
- package/docs/mod.md +43 -27
- package/docs/options.md +2 -2
- package/docs/session.md +58 -32
- package/docs/testing.md +88 -24
- package/docs/ui.md +128 -58
- package/installer.d.ts +2 -2
- package/jobs/context.js +1 -1
- package/jobs/program.d.ts +4 -1
- package/jobs/program.d.ts.map +1 -1
- package/jobs/program.js +79 -20
- package/mod.d.ts +59 -9
- package/mod.d.ts.map +1 -1
- package/mod.js +5 -3
- package/package.json +1 -1
- package/records.d.ts +15 -2
- package/records.d.ts.map +1 -1
- package/records.js +24 -10
- package/register.d.ts.map +1 -1
- package/register.js +7 -4
- package/rpc.d.ts +7 -0
- package/rpc.d.ts.map +1 -0
- package/rpc.js +59 -0
- package/runtime/bound.d.ts +1 -0
- package/runtime/bound.d.ts.map +1 -1
- package/runtime/bound.js +10 -0
- package/runtime/bun.d.ts +20 -0
- package/runtime/bun.d.ts.map +1 -0
- package/runtime/bun.js +20 -0
- package/runtime/claude.d.ts +1 -0
- package/runtime/claude.d.ts.map +1 -1
- package/runtime/conversations.d.ts +12 -1
- package/runtime/conversations.d.ts.map +1 -1
- package/runtime/conversations.js +472 -362
- package/runtime/deadline.d.ts +4 -3
- package/runtime/deadline.d.ts.map +1 -1
- package/runtime/deadline.js +10 -4
- package/runtime/engine.d.ts +5 -4
- package/runtime/engine.d.ts.map +1 -1
- package/runtime/installer.d.ts +3 -3
- package/runtime/installer.d.ts.map +1 -1
- package/runtime/installer.js +10 -9
- package/runtime/interfaces.d.ts +262 -0
- package/runtime/interfaces.d.ts.map +1 -0
- package/runtime/interfaces.js +935 -0
- package/runtime/lifecycle.d.ts +3 -3
- package/runtime/lifecycle.d.ts.map +1 -1
- package/runtime/lifecycle.js +83 -52
- package/runtime/options.d.ts.map +1 -1
- package/runtime/options.js +2 -6
- package/runtime/parts.d.ts +64 -1
- package/runtime/parts.d.ts.map +1 -1
- package/runtime/parts.js +311 -4
- package/runtime/programs.d.ts +1 -0
- package/runtime/programs.d.ts.map +1 -1
- package/runtime/programs.js +5 -3
- package/runtime/rpc.d.ts +111 -0
- package/runtime/rpc.d.ts.map +1 -0
- package/runtime/rpc.js +387 -0
- package/runtime/sessions.d.ts +6 -4
- package/runtime/sessions.d.ts.map +1 -1
- package/runtime/sessions.js +59 -80
- package/runtime/toaster.js +1 -1
- package/runtime/ui.d.ts +23 -10
- package/runtime/ui.d.ts.map +1 -1
- package/runtime/ui.js +63 -52
- package/runtime/web.d.ts +0 -73
- package/runtime/web.d.ts.map +1 -1
- package/runtime/web.js +9 -5
- package/runtime/widgets.d.ts +4 -2
- package/runtime/widgets.d.ts.map +1 -1
- package/runtime/widgets.js +17 -16
- package/session/conversation.d.ts +7 -1
- package/session/conversation.d.ts.map +1 -1
- package/session/session.d.ts +31 -7
- package/session/session.d.ts.map +1 -1
- package/session/session.js +1 -0
- package/src/installer.ts +2 -2
- package/src/jobs/context.ts +1 -1
- package/src/jobs/program.ts +76 -21
- package/src/mod.ts +51 -10
- package/src/records.ts +33 -9
- package/src/register.ts +7 -4
- package/src/rpc.ts +67 -0
- package/src/runtime/bound.ts +10 -0
- package/src/runtime/bun.ts +40 -0
- package/src/runtime/claude.ts +1 -0
- package/src/runtime/conversations.ts +470 -352
- package/src/runtime/deadline.ts +13 -6
- package/src/runtime/engine.ts +5 -4
- package/src/runtime/installer.ts +13 -12
- package/src/runtime/interfaces.ts +1161 -0
- package/src/runtime/lifecycle.ts +102 -59
- package/src/runtime/options.ts +2 -5
- package/src/runtime/parts.ts +364 -5
- package/src/runtime/programs.ts +6 -3
- package/src/runtime/rpc.ts +457 -0
- package/src/runtime/sessions.ts +63 -83
- package/src/runtime/toaster.ts +1 -1
- package/src/runtime/ui.ts +82 -61
- package/src/runtime/web.ts +10 -39
- package/src/runtime/widgets.ts +20 -18
- package/src/session/conversation.ts +7 -1
- package/src/session/session.ts +22 -7
- package/src/testing/fake-claude.ts +38 -7
- package/src/testing/fake-serve.ts +144 -0
- package/src/testing/fake-sessions.ts +21 -6
- package/src/testing.ts +156 -68
- package/src/ui/areas.ts +2 -2
- package/src/ui/elements.ts +21 -16
- package/src/ui/panes.ts +14 -7
- package/testing/fake-claude.d.ts +6 -0
- package/testing/fake-claude.d.ts.map +1 -1
- package/testing/fake-claude.js +34 -7
- package/testing/fake-serve.d.ts +39 -0
- package/testing/fake-serve.d.ts.map +1 -0
- package/testing/fake-serve.js +110 -0
- package/testing/fake-sessions.d.ts.map +1 -1
- package/testing/fake-sessions.js +22 -6
- package/testing.d.ts +21 -4
- package/testing.d.ts.map +1 -1
- package/testing.js +138 -56
- package/ui/areas.d.ts +3 -1
- package/ui/areas.d.ts.map +1 -1
- package/ui/elements.d.ts +18 -9
- package/ui/elements.d.ts.map +1 -1
- package/ui/elements.js +9 -8
- package/ui/panes.d.ts +10 -6
- package/ui/panes.d.ts.map +1 -1
- package/ui/panes.js +5 -3
- package/runtime/pages.d.ts +0 -32
- package/runtime/pages.d.ts.map +0 -1
- package/runtime/pages.js +0 -142
- package/src/runtime/pages.ts +0 -183
package/runtime/sessions.js
CHANGED
|
@@ -18,6 +18,7 @@ import { callFiles } from './hooks.js';
|
|
|
18
18
|
export const everySession = '*';
|
|
19
19
|
export const conversationMethods = {
|
|
20
20
|
sessions: 'cmod:sessions',
|
|
21
|
+
session: 'cmod:session',
|
|
21
22
|
search: 'cmod:search',
|
|
22
23
|
messages: 'cmod:messages',
|
|
23
24
|
turns: 'cmod:turns',
|
|
@@ -33,11 +34,12 @@ export const conversationMethods = {
|
|
|
33
34
|
sessionColor: 'cmod:sessionColor',
|
|
34
35
|
};
|
|
35
36
|
const resetColors = ['default', 'reset', 'none', 'gray', 'grey'];
|
|
37
|
+
const sessionFields = { id: true, title: true, color: true, project: true, cwd: true, model: true, startedAt: true, lastAt: true, forkedFrom: true, isRunning: true, agentType: true, visitedAt: true, device: true, status: true, waitingFor: true, contextPercent: true, lastTurn: true };
|
|
36
38
|
export function pickedColor(args) {
|
|
37
39
|
const picked = args.trim().toLowerCase();
|
|
38
40
|
return resetColors.includes(picked) ? undefined : picked;
|
|
39
41
|
}
|
|
40
|
-
const acts = ['send', 'startTask', 'fork', 'clone', 'startBackgroundTask', 'callTool', 'usage', 'surfaces', 'abort'];
|
|
42
|
+
const acts = ['send', 'startTask', 'fork', 'clone', 'startBackgroundTask', 'callTool', 'usage', 'surfaces', 'abort', 'end', 'visit', 'delete'];
|
|
41
43
|
export const isAct = (action) => acts.includes(action);
|
|
42
44
|
export async function usageOf(claude) {
|
|
43
45
|
const [model, usage] = await Promise.all([claude.session.model(), claude.session.usage()]);
|
|
@@ -123,19 +125,20 @@ export function createSessionsClient({ name, claude, report, hookOn, routeOn, pe
|
|
|
123
125
|
const known = new Map();
|
|
124
126
|
let current = { id: '', title: '', project: '', cwd: '', model: '', startedAt: '', lastAt: '', isRunning: true };
|
|
125
127
|
let told = { session: '' };
|
|
128
|
+
const ownOnly = (method) => new Error(`${name}: ${method} works only in a mod's own session.`);
|
|
126
129
|
const colored = ({ color: _color, ...data }) => (told.session === data.id && told.color !== undefined ? { ...data, color: told.color } : data);
|
|
127
|
-
const keyOf = (scope) => scope.session ??
|
|
130
|
+
const keyOf = (scope) => scope.session ?? current.id;
|
|
128
131
|
const subscribe = (key) => {
|
|
129
132
|
if (queued.has(key))
|
|
130
133
|
return;
|
|
131
134
|
queued.add(key);
|
|
132
135
|
void Promise.resolve().then(async () => {
|
|
133
136
|
queued.delete(key);
|
|
134
|
-
const heard = (from) => [...(from.get(key) ?? [])].map(({ event, matcher, options, scope }) => ({ event, matcher: matcher === undefined ? undefined : sentMatcher(matcher), ...(options.onFailure === 'refuse' ? { onFailure: 'refuse',
|
|
137
|
+
const heard = (from) => [...(from.get(key) ?? [])].map(({ event, matcher, options, scope }) => ({ event, matcher: matcher === undefined ? undefined : sentMatcher(matcher), scope, ...(options.onFailure === 'refuse' ? { onFailure: 'refuse' } : {}), ...(options.timeoutMs === undefined ? {} : { timeoutMs: options.timeoutMs }) }));
|
|
135
138
|
const tracksTasks = [...(listening.get(key) ?? []), ...(deciding.get(key) ?? [])].some(({ scope }) => scope.task !== undefined || scope.isGoal === true);
|
|
136
139
|
const subscriptions = [...heard(listening), ...(tracksTasks ? [{ event: TaskStart }] : [])];
|
|
137
|
-
await call(conversationMethods.subscribe, { session: key, subscriptions }).catch((error) => report(`sessions:${key}`, `Hears nothing from
|
|
138
|
-
await call(conversationMethods.watchBefore, { session: key, subscriptions: heard(deciding) }).catch((error) => report(`before:${key}`, `Changes nothing in
|
|
140
|
+
await call(conversationMethods.subscribe, { session: key, subscriptions }).catch((error) => report(`sessions:${key}`, `Hears nothing from session ${key}`, error));
|
|
141
|
+
await call(conversationMethods.watchBefore, { session: key, subscriptions: heard(deciding) }).catch((error) => report(`before:${key}`, `Changes nothing in session ${key}`, error));
|
|
139
142
|
});
|
|
140
143
|
};
|
|
141
144
|
const parentsOf = (session) => {
|
|
@@ -205,10 +208,10 @@ export function createSessionsClient({ name, claude, report, hookOn, routeOn, pe
|
|
|
205
208
|
report(`session:${method}`, `The ${method} listener failed`, error);
|
|
206
209
|
return refusalOf(options, takes, error);
|
|
207
210
|
});
|
|
208
|
-
const decidersOf = (session, event
|
|
211
|
+
const decidersOf = (session, event) => [...(deciding.get(session) ?? [])].filter((entry) => entry.event === event);
|
|
209
212
|
const decides = async (entry, session, change) => (entry.matcher === undefined || matches(payloadOf(change), entry.matcher)) && (await inScope(entry, session, change));
|
|
210
|
-
const combined = async (session, event, change,
|
|
211
|
-
const askers = decidersOf(session, event
|
|
213
|
+
const combined = async (session, event, change, cancel) => {
|
|
214
|
+
const askers = decidersOf(session, event)
|
|
212
215
|
.map((entry) => async (latest) => {
|
|
213
216
|
if (!(await decides(entry, session, latest)))
|
|
214
217
|
return undefined;
|
|
@@ -222,7 +225,10 @@ export function createSessionsClient({ name, claude, report, hookOn, routeOn, pe
|
|
|
222
225
|
const method = (into, named, event) => (...args) => {
|
|
223
226
|
if (ended !== undefined)
|
|
224
227
|
throw new Error(`${name}: ${ended} has ended, so its ${named} never fires. Listen on its Session.`);
|
|
225
|
-
|
|
228
|
+
const scope = scopeOf();
|
|
229
|
+
if (routeOn === undefined || keyOf(scope) !== current.id)
|
|
230
|
+
throw ownOnly(named);
|
|
231
|
+
return add(into, scope, event, named, args, subscribe);
|
|
226
232
|
};
|
|
227
233
|
return Object.fromEntries([
|
|
228
234
|
...Object.entries(sessionEvents).map(([named, event]) => [`on${named}`, method(listening, `on${named}`, event)]),
|
|
@@ -342,49 +348,17 @@ export function createSessionsClient({ name, claude, report, hookOn, routeOn, pe
|
|
|
342
348
|
throw new Error(`${name}: Claude Code dropped the prompt: ${submitted.drop}`);
|
|
343
349
|
};
|
|
344
350
|
const surfacesHere = async () => [...(await claude.session.surfaces())];
|
|
345
|
-
const sessionOf = (read, owned, isOwner = owned !== undefined) => {
|
|
351
|
+
const sessionOf = (read, owned, isOwner = owned !== undefined, hears = true) => {
|
|
346
352
|
const id = () => read().id;
|
|
347
353
|
const isHere = () => owned === undefined && id() === current.id;
|
|
348
354
|
const scope = () => (owned === undefined ? { session: id(), isAgent: true } : { session: owned.session, task: owned.task, isAgent: true });
|
|
349
355
|
const where = () => (owned === undefined ? { session: id() } : { session: owned.session, task: owned.task });
|
|
350
356
|
const turnsOf = async (options = {}) => (await call(conversationMethods.turns, { ...where(), ...options })).map((turn) => turnOf(where(), turn));
|
|
351
357
|
const contextsOf = async () => (await call(conversationMethods.contexts, where())).map((context) => contextOf(where(), context));
|
|
352
|
-
const
|
|
353
|
-
|
|
354
|
-
return read().id;
|
|
355
|
-
},
|
|
356
|
-
get title() {
|
|
357
|
-
return read().title;
|
|
358
|
-
},
|
|
359
|
-
get color() {
|
|
360
|
-
return read().color;
|
|
361
|
-
},
|
|
362
|
-
get project() {
|
|
363
|
-
return read().project;
|
|
364
|
-
},
|
|
365
|
-
get agentType() {
|
|
366
|
-
return read().agentType;
|
|
367
|
-
},
|
|
368
|
-
get model() {
|
|
369
|
-
return read().model;
|
|
370
|
-
},
|
|
371
|
-
get cwd() {
|
|
372
|
-
return read().cwd;
|
|
373
|
-
},
|
|
374
|
-
get isRunning() {
|
|
375
|
-
return read().isRunning;
|
|
376
|
-
},
|
|
377
|
-
get startedAt() {
|
|
378
|
-
return read().startedAt;
|
|
379
|
-
},
|
|
380
|
-
get lastAt() {
|
|
381
|
-
return read().lastAt;
|
|
382
|
-
},
|
|
383
|
-
get forkedFrom() {
|
|
384
|
-
return read().forkedFrom;
|
|
385
|
-
},
|
|
358
|
+
const data = Object.defineProperties({}, Object.fromEntries(Object.keys(sessionFields).map((key) => [key, { get: () => read()[key], enumerable: true, configurable: true }])));
|
|
359
|
+
const session = Object.assign(data, {
|
|
386
360
|
search: (text, matcher) => recordPart(scope()).search(text, matcher),
|
|
387
|
-
...eventMethods(scope, true),
|
|
361
|
+
...(hears ? eventMethods(scope, true) : {}),
|
|
388
362
|
goal: goalOf(where),
|
|
389
363
|
context: async () => {
|
|
390
364
|
const all = await contextsOf();
|
|
@@ -409,14 +383,22 @@ export function createSessionsClient({ name, claude, report, hookOn, routeOn, pe
|
|
|
409
383
|
return sendHere(message);
|
|
410
384
|
await act(id(), 'send', message, owned);
|
|
411
385
|
},
|
|
412
|
-
|
|
386
|
+
async end() {
|
|
387
|
+
await act(id(), 'end', null, owned);
|
|
388
|
+
},
|
|
389
|
+
async visit(at) {
|
|
390
|
+
await act(id(), 'visit', at ?? new Date().toISOString(), owned);
|
|
391
|
+
},
|
|
392
|
+
});
|
|
413
393
|
if (isOwner)
|
|
414
394
|
return session;
|
|
415
395
|
const started = async (starting) => taskOf(id(), await starting.catch((error) => Promise.reject(new Error(`${name}: ${messageOf(error)}`))));
|
|
416
396
|
return Object.assign(session, {
|
|
417
|
-
startTask: (task) => started(task.isBackground === true ? act(id(), 'startBackgroundTask', task) : isHere() ? spawnTask(claude, task) : act(id(), 'startTask', task)),
|
|
418
|
-
fork: (task) => started(isHere() ? spawnTask(claude, task, current.id) : act(id(), 'fork', task)),
|
|
419
|
-
|
|
397
|
+
startTask: (task) => started(task.isBackground === true || task.device !== undefined ? act(id(), 'startBackgroundTask', task) : isHere() ? spawnTask(claude, task) : act(id(), 'startTask', task)),
|
|
398
|
+
fork: (task) => started(isHere() && task.isBackground !== true && task.at === undefined ? spawnTask(claude, task, current.id) : act(id(), 'fork', task)),
|
|
399
|
+
delete: async () => {
|
|
400
|
+
await act(id(), 'delete', null);
|
|
401
|
+
},
|
|
420
402
|
callTool: async (toolCall) => (await withFiles(await act(id(), 'callTool', toolCall))),
|
|
421
403
|
});
|
|
422
404
|
};
|
|
@@ -476,7 +458,7 @@ export function createSessionsClient({ name, claude, report, hookOn, routeOn, pe
|
|
|
476
458
|
});
|
|
477
459
|
const listenTo = (method, named) => {
|
|
478
460
|
if (hookOn === undefined || routeOn === undefined)
|
|
479
|
-
throw
|
|
461
|
+
throw ownOnly(method);
|
|
480
462
|
const isBefore = method.startsWith('before');
|
|
481
463
|
if (named === 'PermissionCheck' || named === 'PermissionRequest') {
|
|
482
464
|
const routes = permissionRoutes?.();
|
|
@@ -557,46 +539,43 @@ export function createSessionsClient({ name, claude, report, hookOn, routeOn, pe
|
|
|
557
539
|
},
|
|
558
540
|
caption: (toolCall, text) => claude.ui.notice(toolCall.callId, text),
|
|
559
541
|
});
|
|
560
|
-
const
|
|
561
|
-
|
|
562
|
-
const asked = decidersOf(session, event, isInProject).filter((entry) => isInScope(entry.scope, session, change, isUnderIn(parents.get(session))) && (entry.matcher === undefined || matches(payloadOf(change), entry.matcher)));
|
|
542
|
+
const failedBefore = (session, event, change, error) => {
|
|
543
|
+
const asked = decidersOf(session, event).filter((entry) => isInScope(entry.scope, session, change, isUnderIn(parents.get(session))) && (entry.matcher === undefined || matches(payloadOf(change), entry.matcher)));
|
|
563
544
|
return asked.map((entry) => refusalOf(entry.options, beforeAnswerKeys[event], error)).find((answer) => answer !== undefined);
|
|
564
545
|
};
|
|
546
|
+
const listed = (data) => {
|
|
547
|
+
if (data.id !== current.id) {
|
|
548
|
+
known.set(data.id, data);
|
|
549
|
+
return sessionOf(() => known.get(data.id) ?? data, undefined, false, false);
|
|
550
|
+
}
|
|
551
|
+
current = { ...current, title: current.title || data.title, device: data.device };
|
|
552
|
+
return currentSession;
|
|
553
|
+
};
|
|
565
554
|
return {
|
|
566
555
|
sessions: {
|
|
567
556
|
get current() {
|
|
568
557
|
return currentSession;
|
|
569
558
|
},
|
|
570
|
-
list: async (scope = {}) => (await call(conversationMethods.sessions, scope)).map(
|
|
571
|
-
|
|
572
|
-
known.set(data.id, data);
|
|
573
|
-
return sessionOf(() => known.get(data.id) ?? data);
|
|
574
|
-
}
|
|
575
|
-
if (current.title === '')
|
|
576
|
-
current = { ...current, title: data.title };
|
|
577
|
-
return currentSession;
|
|
578
|
-
}),
|
|
559
|
+
list: async (scope = {}) => (await call(conversationMethods.sessions, scope)).map(listed),
|
|
560
|
+
get: async (id) => (id === current.id ? currentSession : listed(await call(conversationMethods.session, { session: id }))),
|
|
579
561
|
search: (text, matcher, options = {}) => searched({ text, ...searchOptionsOf(options) }, matcher),
|
|
580
|
-
...every,
|
|
581
562
|
},
|
|
582
|
-
changed(session, change,
|
|
563
|
+
changed(session, change, cancel) {
|
|
583
564
|
remember(session, change);
|
|
584
565
|
let payload;
|
|
585
|
-
for (const
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
void isHeard.then((isIn) => isIn && deliver());
|
|
599
|
-
}
|
|
566
|
+
for (const entry of listening.get(session) ?? []) {
|
|
567
|
+
const { event, method, matcher, listener, options } = entry;
|
|
568
|
+
const deliver = () => {
|
|
569
|
+
payload ??= payloadFor(session, change);
|
|
570
|
+
void payload
|
|
571
|
+
.then((heard) => invoke(method, options, cancel, (time) => listener(heard, time)))
|
|
572
|
+
.catch((error) => report(`session:${method}`, `The ${method} listener failed`, error));
|
|
573
|
+
};
|
|
574
|
+
const isHeard = isHeardBy(event, matcher, change) && inScope(entry, session, change);
|
|
575
|
+
if (isHeard === true)
|
|
576
|
+
deliver();
|
|
577
|
+
else if (isHeard !== false)
|
|
578
|
+
void isHeard.then((isIn) => isIn && deliver());
|
|
600
579
|
}
|
|
601
580
|
},
|
|
602
581
|
answerBefore: combined,
|
|
@@ -607,7 +586,7 @@ export function createSessionsClient({ name, claude, report, hookOn, routeOn, pe
|
|
|
607
586
|
follow(next) {
|
|
608
587
|
const moved = next.id !== current.id && current.id !== '';
|
|
609
588
|
const previous = current.id;
|
|
610
|
-
current = colored({ ...next, title: next.title || (next.id === current.id ? current.title : ''), isRunning: true, lastAt: new Date().toISOString() });
|
|
589
|
+
current = colored({ device: current.device, ...next, title: next.title || (next.id === current.id ? current.title : ''), isRunning: true, lastAt: new Date().toISOString() });
|
|
611
590
|
if (!moved)
|
|
612
591
|
return;
|
|
613
592
|
for (const into of [listening, deciding]) {
|
package/runtime/toaster.js
CHANGED
|
@@ -174,7 +174,7 @@ export function createToaster(claude, name, version) {
|
|
|
174
174
|
const call = { isSettled: false };
|
|
175
175
|
try {
|
|
176
176
|
const logged = logFailure(failure).finally(() => void (call.isSettled = true));
|
|
177
|
-
const answer = await (isShown ? logged : beforeDeadline(claude, { ms: failedCallMs }, failedMethod, logged));
|
|
177
|
+
const answer = await (isShown ? logged : beforeDeadline(claude.clock, { ms: failedCallMs }, failedMethod, () => logged));
|
|
178
178
|
if (isObject(answer) && typeof answer['showsToast'] === 'boolean')
|
|
179
179
|
return answer['showsToast'];
|
|
180
180
|
throw new Error(`cmod answered ${answer === undefined ? 'nothing' : JSON.stringify(answer)}, not { showsToast: true or false }`);
|
package/runtime/ui.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Args, ElementTable, Frozen, MarkdownProps, RenderElement, RenderSurface } from 'claude-code';
|
|
2
|
-
import type { Mod, Turn } from '../mod.js';
|
|
2
|
+
import type { Mod, Surface, Turn } from '../mod.js';
|
|
3
3
|
import { type Area, type WidgetInit } from '../ui/areas.js';
|
|
4
4
|
import { type ScrollOptions, type ScrollTarget } from '../ui/panes.js';
|
|
5
5
|
import { type StyledAt } from '../ui/styles.js';
|
|
@@ -15,33 +15,42 @@ export declare const partMethods: {
|
|
|
15
15
|
readonly stylers: 'cmod:markdownStylers';
|
|
16
16
|
};
|
|
17
17
|
export declare const stalePress = "that button drew before the last redraw. Press the one it shows now.";
|
|
18
|
-
export type
|
|
18
|
+
export type ViewPlace = 'sidebar' | 'settings';
|
|
19
19
|
export type WidgetDeclaration = {
|
|
20
20
|
readonly id: string;
|
|
21
21
|
readonly title: string;
|
|
22
22
|
readonly areas: readonly Area[];
|
|
23
23
|
readonly place?: NonNullable<WidgetInit['place']>;
|
|
24
24
|
};
|
|
25
|
+
export type ViewDeclaration = {
|
|
26
|
+
readonly id: string;
|
|
27
|
+
readonly title: string;
|
|
28
|
+
readonly place: ViewPlace;
|
|
29
|
+
};
|
|
25
30
|
export type PageDeclaration = {
|
|
26
31
|
readonly id: string;
|
|
27
32
|
readonly title: string;
|
|
28
|
-
|
|
33
|
+
};
|
|
34
|
+
export type PartDeclaration = PageDeclaration & {
|
|
35
|
+
readonly place?: ViewPlace;
|
|
29
36
|
};
|
|
30
37
|
export type PartList = {
|
|
31
38
|
readonly widgets: readonly WidgetDeclaration[];
|
|
32
|
-
readonly pages: readonly
|
|
33
|
-
readonly
|
|
39
|
+
readonly pages: readonly PartDeclaration[];
|
|
40
|
+
readonly provides?: readonly string[];
|
|
34
41
|
};
|
|
35
42
|
export type PartDraw = {
|
|
36
43
|
readonly widget: string;
|
|
37
44
|
readonly area: Area;
|
|
38
45
|
readonly columns: number;
|
|
46
|
+
readonly surface: Surface;
|
|
39
47
|
readonly turn?: Turn;
|
|
40
48
|
} | {
|
|
41
49
|
readonly page: string;
|
|
42
50
|
readonly params: unknown;
|
|
43
51
|
readonly columns: number;
|
|
44
52
|
readonly isFocused: boolean;
|
|
53
|
+
readonly surface: Surface;
|
|
45
54
|
} | ({
|
|
46
55
|
readonly markdown: string;
|
|
47
56
|
} & StyledAt);
|
|
@@ -60,7 +69,7 @@ export type DrawnPart = {
|
|
|
60
69
|
readonly draw: number;
|
|
61
70
|
readonly tree: unknown;
|
|
62
71
|
};
|
|
63
|
-
export type
|
|
72
|
+
export type PartRequest = {
|
|
64
73
|
readonly open: string;
|
|
65
74
|
readonly params?: unknown;
|
|
66
75
|
readonly focus?: true;
|
|
@@ -81,17 +90,18 @@ export type SettingsTab = 'changelog' | 'permissions';
|
|
|
81
90
|
export type PartsUpdate = {
|
|
82
91
|
readonly parts?: PartList;
|
|
83
92
|
readonly redraw?: true;
|
|
84
|
-
readonly requests?: readonly
|
|
93
|
+
readonly requests?: readonly PartRequest[];
|
|
85
94
|
readonly isAsked?: true;
|
|
86
95
|
readonly isStart?: true;
|
|
87
96
|
};
|
|
88
|
-
export type
|
|
97
|
+
export type ShownParts = {
|
|
89
98
|
readonly open: readonly {
|
|
90
99
|
readonly id: string;
|
|
91
100
|
readonly params: unknown;
|
|
92
101
|
}[];
|
|
93
102
|
readonly shown: string | null;
|
|
94
103
|
readonly isFocused: boolean;
|
|
104
|
+
readonly inApps?: readonly string[];
|
|
95
105
|
};
|
|
96
106
|
export declare function inheriting(props: MarkdownProps, draw: (drawn: MarkdownProps) => RenderElement, laterKey?: () => string | undefined): (left: MarkdownProps) => RenderElement;
|
|
97
107
|
export declare function merged(updates: readonly PartsUpdate[]): PartsUpdate;
|
|
@@ -104,10 +114,12 @@ export type UiOptions<State extends object> = {
|
|
|
104
114
|
readonly mod: () => Mod<State>;
|
|
105
115
|
readonly borrowed: BorrowedMarkdown;
|
|
106
116
|
readonly nextDraw: () => number;
|
|
117
|
+
readonly provided: () => readonly string[];
|
|
107
118
|
};
|
|
108
119
|
export type UiArea<State extends object> = {
|
|
109
120
|
readonly panes: Mod<State>['panes'];
|
|
110
|
-
readonly
|
|
121
|
+
readonly views: Mod<State>['views'];
|
|
122
|
+
readonly pages: Mod<State>['pages'];
|
|
111
123
|
readonly settings: Mod<State>['settings'];
|
|
112
124
|
readonly widgets: Mod<State>['widgets'];
|
|
113
125
|
readonly styles: Mod<State>['styles'];
|
|
@@ -118,10 +130,11 @@ export type UiArea<State extends object> = {
|
|
|
118
130
|
}> | undefined;
|
|
119
131
|
markdownIn(table: ElementTable, at: StyledAt): ((props: MarkdownProps) => RenderElement) | undefined;
|
|
120
132
|
restyled(stylers: readonly string[]): void;
|
|
133
|
+
relisted(): void;
|
|
121
134
|
started(): void;
|
|
122
135
|
changed(): void;
|
|
123
136
|
restorePanes(): Promise<void>;
|
|
124
137
|
};
|
|
125
138
|
export declare const keptDrawInputs = 200;
|
|
126
|
-
export declare function createUi<State extends object>({ name, claude, router, report, announce, mod, borrowed, nextDraw }: UiOptions<State>): UiArea<State>;
|
|
139
|
+
export declare function createUi<State extends object>({ name, claude, router, report, announce, mod, borrowed, nextDraw, provided }: UiOptions<State>): UiArea<State>;
|
|
127
140
|
//# sourceMappingURL=ui.d.ts.map
|
package/runtime/ui.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ui.d.ts","sourceRoot":"","sources":["../src/runtime/ui.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,EAAE,aAAa,EAAgB,aAAa,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AACxH,OAAO,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"ui.d.ts","sourceRoot":"","sources":["../src/runtime/ui.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAA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MAAM,CAAC,CAAA;IAChG,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAA;KAAE,CAAC,GAAG,SAAS,CAAA;IACxG,UAAU,CAAC,KAAK,EAAE,YAAY,EAAE,EAAE,EAAE,QAAQ,GAAG,CAAC,CAAC,KAAK,EAAE,aAAa,KAAK,aAAa,CAAC,GAAG,SAAS,CAAA;IACpG,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,CAAA;IAC1C,QAAQ,IAAI,IAAI,CAAA;IAChB,OAAO,IAAI,IAAI,CAAA;IACf,OAAO,IAAI,IAAI,CAAA;IACf,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CAC9B,CAAA;AAED,eAAO,MAAM,cAAc,MAAM,CAAA;AAEjC,wBAAgB,QAAQ,CAAC,KAAK,SAAS,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAAE,SAAS,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CA2kB7J"}
|
package/runtime/ui.js
CHANGED
|
@@ -4,6 +4,7 @@ import { Box, drawKeyed, drawsFocusable, drawWith, elementData, Markdown, Text }
|
|
|
4
4
|
import { checkPane, checkPart, sizeKeys } from '../ui/panes.js';
|
|
5
5
|
import { componentOf, nameOf } from '../ui/styles.js';
|
|
6
6
|
import { messageOf } from '../utils/text.js';
|
|
7
|
+
import { styleInterface } from './interfaces.js';
|
|
7
8
|
import { cmodPluginName } from './dependencies.js';
|
|
8
9
|
export const partMethods = {
|
|
9
10
|
list: 'cmod:parts',
|
|
@@ -126,7 +127,7 @@ export function merged(updates) {
|
|
|
126
127
|
return { ...(parts === undefined ? {} : { parts }), ...(isRedrawn ? { redraw: true } : {}), ...(requests.length === 0 ? {} : { requests }), ...(isStart ? { isStart } : {}) };
|
|
127
128
|
}
|
|
128
129
|
export const keptDrawInputs = 200;
|
|
129
|
-
export function createUi({ name, claude, router, report, announce, mod, borrowed, nextDraw }) {
|
|
130
|
+
export function createUi({ name, claude, router, report, announce, mod, borrowed, nextDraw, provided }) {
|
|
130
131
|
const panes = new Map();
|
|
131
132
|
const paneLogs = new Map();
|
|
132
133
|
const openPanes = new Set();
|
|
@@ -156,8 +157,8 @@ export function createUi({ name, claude, router, report, announce, mod, borrowed
|
|
|
156
157
|
let isResizeQueued = false;
|
|
157
158
|
const widgets = new Map();
|
|
158
159
|
const widgetAreas = new Map();
|
|
159
|
-
const
|
|
160
|
-
let
|
|
160
|
+
const parts = new Map();
|
|
161
|
+
let shownParts = { open: [], shown: null, isFocused: false };
|
|
161
162
|
const draws = new Map();
|
|
162
163
|
const latestDraws = new Map();
|
|
163
164
|
const failedDraws = new Set();
|
|
@@ -168,11 +169,14 @@ export function createUi({ name, claude, router, report, announce, mod, borrowed
|
|
|
168
169
|
let collected;
|
|
169
170
|
let collecting = 0;
|
|
170
171
|
let queued;
|
|
171
|
-
const partList = () =>
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
172
|
+
const partList = () => {
|
|
173
|
+
const provides = [...provided(), ...(markdownRenders.size > 0 ? [styleInterface] : [])];
|
|
174
|
+
return {
|
|
175
|
+
widgets: [...widgets.values()].map(({ id, title, areas: listed, place }) => ({ id, title, areas: listed, ...(place === undefined ? {} : { place }) })),
|
|
176
|
+
pages: [...parts.values()].map(({ init: { id, title }, place }) => ({ id, title, ...(place === undefined ? {} : { place }) })),
|
|
177
|
+
...(provides.length === 0 ? {} : { provides }),
|
|
178
|
+
};
|
|
179
|
+
};
|
|
176
180
|
const hear = (listed, isRestyled) => {
|
|
177
181
|
if (!Array.isArray(listed))
|
|
178
182
|
return;
|
|
@@ -186,7 +190,7 @@ export function createUi({ name, claude, router, report, announce, mod, borrowed
|
|
|
186
190
|
};
|
|
187
191
|
const treeOf = (render, handlers) => {
|
|
188
192
|
const drawn = render();
|
|
189
|
-
return drawn === undefined ? null : elementData(drawn, handlers);
|
|
193
|
+
return drawn === undefined ? null : elementData(drawn, (run) => handlers.push(run) - 1);
|
|
190
194
|
};
|
|
191
195
|
const isAnyDrawingChanged = () => {
|
|
192
196
|
for (const [key, inputs] of latestDraws) {
|
|
@@ -234,7 +238,7 @@ export function createUi({ name, claude, router, report, announce, mod, borrowed
|
|
|
234
238
|
if (isObject(answer) && name !== cmodPluginName)
|
|
235
239
|
hear(answer['stylers'], false);
|
|
236
240
|
}, (error) => {
|
|
237
|
-
claude.ui.warn('parts:tell', `${name}: the cmod plugin did not hear about its
|
|
241
|
+
claude.ui.warn('parts:tell', `${name}: the cmod plugin did not hear about its widgets, views, and pages: ${messageOf(error)}`);
|
|
238
242
|
});
|
|
239
243
|
};
|
|
240
244
|
if (!isAsked)
|
|
@@ -425,9 +429,7 @@ export function createUi({ name, claude, router, report, announce, mod, borrowed
|
|
|
425
429
|
throw new Error(`${name}: Claude Code did not scroll ${id}: ${deny}`);
|
|
426
430
|
});
|
|
427
431
|
const addPane = (init) => {
|
|
428
|
-
checkPane(name, init);
|
|
429
|
-
if (panes.has(init.id))
|
|
430
|
-
throw new Error(`${name}: the pane "${init.id}" is already added. Give each pane its own id.`);
|
|
432
|
+
checkPane(name, init, panes.has(init.id) ? 'pane' : undefined);
|
|
431
433
|
const added = { init, params: undefined };
|
|
432
434
|
panes.set(init.id, added);
|
|
433
435
|
paneLogs.set(init.id, logOnce(`${init.title} pane`));
|
|
@@ -483,61 +485,64 @@ export function createUi({ name, claude, router, report, announce, mod, borrowed
|
|
|
483
485
|
};
|
|
484
486
|
return pane;
|
|
485
487
|
};
|
|
486
|
-
const
|
|
487
|
-
const
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
const
|
|
492
|
-
|
|
493
|
-
|
|
488
|
+
const openEntry = (id) => shownParts.open.find((each) => each.id === id);
|
|
489
|
+
const takenBy = (id) => (widgets.has(id) ? 'widget' : parts.get(id)?.kind);
|
|
490
|
+
const addPart = (kind, init, place) => {
|
|
491
|
+
checkPart(name, kind, init.id, init.title, takenBy(init.id));
|
|
492
|
+
const added = { init, kind, place, params: undefined };
|
|
493
|
+
const key = `${kind}:${init.id}`;
|
|
494
|
+
let requested;
|
|
495
|
+
parts.set(init.id, added);
|
|
496
|
+
announce(place === 'settings' ? `the ${init.title} view in Settings` : `the ${init.title} ${kind}`);
|
|
494
497
|
void send({ parts: partList() });
|
|
495
|
-
const
|
|
498
|
+
const part = {
|
|
496
499
|
id: init.id,
|
|
497
500
|
get isOpen() {
|
|
498
|
-
|
|
501
|
+
if (requested?.[0] === shownParts)
|
|
502
|
+
return requested[1];
|
|
503
|
+
return place === 'settings' ? shownParts.shown === init.id : openEntry(init.id) !== undefined;
|
|
499
504
|
},
|
|
500
505
|
get isShown() {
|
|
501
|
-
return
|
|
506
|
+
return [shownParts.shown, ...(shownParts.inApps ?? [])].includes(init.id);
|
|
502
507
|
},
|
|
503
508
|
get isFocused() {
|
|
504
|
-
return
|
|
509
|
+
return shownParts.shown === init.id && shownParts.isFocused;
|
|
505
510
|
},
|
|
506
511
|
get params() {
|
|
507
|
-
return (
|
|
512
|
+
return (openEntry(init.id)?.params ?? added.params);
|
|
508
513
|
},
|
|
509
514
|
async open(...[options]) {
|
|
510
515
|
if (options !== undefined && 'params' in options)
|
|
511
516
|
added.params = options.params;
|
|
517
|
+
requested = [shownParts, true];
|
|
512
518
|
await send({ requests: [{ open: init.id, ...(added.params === undefined ? {} : { params: added.params }), ...(options?.focus === true ? { focus: true } : {}) }] });
|
|
513
519
|
},
|
|
514
|
-
toggle: (options) => (
|
|
520
|
+
toggle: (options) => (part.isOpen ? part.close() : part.open(options)),
|
|
515
521
|
close: async () => {
|
|
522
|
+
requested = [shownParts, false];
|
|
516
523
|
await send({ requests: [{ close: init.id }] });
|
|
517
524
|
},
|
|
518
525
|
scrollTo: async (target, options) => {
|
|
519
526
|
await send({ requests: [{ scroll: init.id, to: target, ...(options?.block === undefined ? {} : { block: options.block }) }] });
|
|
520
527
|
},
|
|
521
|
-
focus: async (
|
|
522
|
-
const latest = [...(latestDraws.get(
|
|
523
|
-
if (latest === undefined || !drawsFocusable(treeOf(latest.render, []),
|
|
524
|
-
throw new Error(`${name}: the ${init.title}
|
|
525
|
-
await send({ requests: [{ focus: init.id, key }] });
|
|
528
|
+
focus: async (focused) => {
|
|
529
|
+
const latest = [...(latestDraws.get(key)?.values() ?? [])].at(-1);
|
|
530
|
+
if (latest === undefined || !drawsFocusable(treeOf(latest.render, []), focused))
|
|
531
|
+
throw new Error(`${name}: the ${init.title} ${kind} draws no Button, Input, or Select with the key "${focused}".`);
|
|
532
|
+
await send({ requests: [{ focus: init.id, key: focused }] });
|
|
526
533
|
},
|
|
527
534
|
remove() {
|
|
528
|
-
if (
|
|
535
|
+
if (parts.get(init.id) !== added)
|
|
529
536
|
return;
|
|
530
|
-
|
|
531
|
-
forgetDraws(
|
|
537
|
+
parts.delete(init.id);
|
|
538
|
+
forgetDraws(key);
|
|
532
539
|
void send({ parts: partList(), requests: [{ close: init.id }] });
|
|
533
540
|
},
|
|
534
541
|
};
|
|
535
|
-
return
|
|
542
|
+
return part;
|
|
536
543
|
};
|
|
537
544
|
const addWidget = (init) => {
|
|
538
|
-
checkPart(name, 'widget', init.id, init.title);
|
|
539
|
-
if (widgets.has(init.id))
|
|
540
|
-
throw new Error(`${name}: the widget "${init.id}" is already added. Give each widget its own id.`);
|
|
545
|
+
checkPart(name, 'widget', init.id, init.title, takenBy(init.id));
|
|
541
546
|
widgets.set(init.id, init);
|
|
542
547
|
announce(`the ${init.title} widget`);
|
|
543
548
|
void send({ parts: partList() });
|
|
@@ -640,18 +645,20 @@ export function createUi({ name, claude, router, report, announce, mod, borrowed
|
|
|
640
645
|
if ('markdown' in input)
|
|
641
646
|
return drawPart('markdown', 'markdown style', input, () => markdownDrawing(input.markdown, { surface: input.surface, columns: input.columns }));
|
|
642
647
|
if ('page' in input) {
|
|
643
|
-
const
|
|
648
|
+
const { page, ...props } = input;
|
|
649
|
+
const added = parts.get(page);
|
|
644
650
|
if (added === undefined)
|
|
645
|
-
throw new Error(`${name} has no ${
|
|
646
|
-
const title = `${added.init.title}
|
|
647
|
-
return drawPart(
|
|
651
|
+
throw new Error(`${name} has no view or page ${page}.`);
|
|
652
|
+
const title = `${added.init.title} ${added.kind}`;
|
|
653
|
+
return drawPart(`${added.kind}:${page}`, title, input, () => added.init.render(mod(), props), (error) => Text({ color: 'error', children: `The ${title} could not draw: ${messageOf(error)}` }));
|
|
648
654
|
}
|
|
649
|
-
const widget =
|
|
650
|
-
|
|
655
|
+
const { widget: id, turn, ...given } = input;
|
|
656
|
+
const widget = widgets.get(id);
|
|
657
|
+
if (widget === undefined || !widget.areas.includes(given.area))
|
|
651
658
|
return null;
|
|
652
|
-
widgetAreas.set(
|
|
653
|
-
const context = (
|
|
654
|
-
return drawPart(`widget:${
|
|
659
|
+
widgetAreas.set(id, given.area);
|
|
660
|
+
const context = (given.area === TurnEnd && turn !== undefined ? { ...given, turn } : given);
|
|
661
|
+
return drawPart(`widget:${id}`, `${widget.title} widget`, input, () => widget.render(mod(), context));
|
|
655
662
|
};
|
|
656
663
|
const press = async ({ draw: drawn, handler, args }, caller) => {
|
|
657
664
|
const known = draws.get(drawn);
|
|
@@ -675,9 +682,10 @@ export function createUi({ name, claude, router, report, announce, mod, borrowed
|
|
|
675
682
|
};
|
|
676
683
|
return {
|
|
677
684
|
panes: { add: addPane },
|
|
678
|
-
|
|
685
|
+
views: { add: (init) => addPart('view', init, 'sidebar') },
|
|
686
|
+
pages: { add: (init) => addPart('page', init) },
|
|
679
687
|
settings: {
|
|
680
|
-
add: (init) =>
|
|
688
|
+
add: (init) => addPart('view', init, 'settings'),
|
|
681
689
|
open: async () => {
|
|
682
690
|
await send({ requests: [{ settings: true }] });
|
|
683
691
|
},
|
|
@@ -703,7 +711,7 @@ export function createUi({ name, claude, router, report, announce, mod, borrowed
|
|
|
703
711
|
if (method === partMethods.press)
|
|
704
712
|
return press(input, caller).then((value) => ({ value }));
|
|
705
713
|
if (method === partMethods.shown) {
|
|
706
|
-
|
|
714
|
+
shownParts = input;
|
|
707
715
|
return Promise.resolve({ value: null });
|
|
708
716
|
}
|
|
709
717
|
if (method === partMethods.stylers) {
|
|
@@ -714,13 +722,16 @@ export function createUi({ name, claude, router, report, announce, mod, borrowed
|
|
|
714
722
|
},
|
|
715
723
|
markdownIn,
|
|
716
724
|
restyled: (stylers) => hear(stylers, true),
|
|
725
|
+
relisted() {
|
|
726
|
+
void send({ parts: partList() });
|
|
727
|
+
},
|
|
717
728
|
started() {
|
|
718
729
|
const held = merged(beforeStart ?? []);
|
|
719
730
|
beforeStart = undefined;
|
|
720
731
|
void send({ ...held, parts: partList(), isStart: true });
|
|
721
732
|
},
|
|
722
733
|
changed() {
|
|
723
|
-
if (widgets.size > 0 ||
|
|
734
|
+
if (widgets.size > 0 || parts.size > 0)
|
|
724
735
|
void send({ redraw: true });
|
|
725
736
|
if (panes.size === 0 && styles.size === 0)
|
|
726
737
|
return;
|