@cmodjs/core 7.0.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 +104 -70
- package/docs/dependencies.md +153 -23
- package/docs/index.md +54 -10
- package/docs/install-steps.md +20 -17
- package/docs/jobs.md +42 -17
- package/docs/mod.md +37 -30
- package/docs/options.md +2 -2
- package/docs/session.md +39 -29
- package/docs/testing.md +84 -23
- package/docs/ui.md +128 -58
- package/installer.d.ts +2 -2
- package/jobs/context.js +1 -1
- package/jobs/program.d.ts +2 -3
- package/jobs/program.d.ts.map +1 -1
- package/jobs/program.js +72 -23
- package/mod.d.ts +23 -8
- package/mod.d.ts.map +1 -1
- package/mod.js +3 -3
- package/package.json +1 -1
- package/records.d.ts +5 -3
- package/records.d.ts.map +1 -1
- package/records.js +18 -9
- package/register.d.ts.map +1 -1
- package/register.js +7 -15
- 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 +9 -2
- package/runtime/conversations.d.ts.map +1 -1
- package/runtime/conversations.js +244 -185
- 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 +4 -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 +108 -42
- package/runtime/interfaces.d.ts.map +1 -1
- package/runtime/interfaces.js +639 -143
- package/runtime/lifecycle.d.ts +3 -5
- package/runtime/lifecycle.d.ts.map +1 -1
- package/runtime/lifecycle.js +74 -63
- 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 +2 -0
- package/runtime/rpc.d.ts.map +1 -1
- package/runtime/rpc.js +30 -5
- package/runtime/sessions.d.ts +3 -3
- package/runtime/sessions.d.ts.map +1 -1
- package/runtime/sessions.js +38 -73
- package/runtime/toaster.js +1 -1
- package/runtime/ui.d.ts +19 -8
- package/runtime/ui.d.ts.map +1 -1
- package/runtime/ui.js +51 -47
- 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 +6 -2
- package/session/conversation.d.ts.map +1 -1
- package/session/session.d.ts +22 -6
- 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 +63 -23
- package/src/mod.ts +22 -11
- package/src/records.ts +21 -9
- package/src/register.ts +7 -15
- 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 +247 -182
- package/src/runtime/deadline.ts +13 -6
- package/src/runtime/engine.ts +4 -4
- package/src/runtime/installer.ts +13 -12
- package/src/runtime/interfaces.ts +753 -172
- package/src/runtime/lifecycle.ts +93 -67
- 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 +32 -5
- package/src/runtime/sessions.ts +39 -73
- package/src/runtime/toaster.ts +1 -1
- package/src/runtime/ui.ts +67 -55
- package/src/runtime/web.ts +10 -39
- package/src/runtime/widgets.ts +20 -18
- package/src/session/conversation.ts +7 -2
- package/src/session/session.ts +14 -6
- package/src/testing/fake-claude.ts +10 -4
- package/src/testing/fake-serve.ts +106 -6
- package/src/testing/fake-sessions.ts +6 -5
- package/src/testing.ts +149 -67
- 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 +2 -0
- package/testing/fake-claude.d.ts.map +1 -1
- package/testing/fake-claude.js +10 -4
- package/testing/fake-serve.d.ts +32 -2
- package/testing/fake-serve.d.ts.map +1 -1
- package/testing/fake-serve.js +81 -6
- package/testing/fake-sessions.d.ts.map +1 -1
- package/testing/fake-sessions.js +6 -5
- package/testing.d.ts +21 -4
- package/testing.d.ts.map +1 -1
- package/testing.js +131 -55
- 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 -34
- package/runtime/pages.d.ts.map +0 -1
- package/runtime/pages.js +0 -157
- package/src/runtime/pages.ts +0 -198
package/runtime/sessions.js
CHANGED
|
@@ -34,6 +34,7 @@ export const conversationMethods = {
|
|
|
34
34
|
sessionColor: 'cmod:sessionColor',
|
|
35
35
|
};
|
|
36
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 };
|
|
37
38
|
export function pickedColor(args) {
|
|
38
39
|
const picked = args.trim().toLowerCase();
|
|
39
40
|
return resetColors.includes(picked) ? undefined : picked;
|
|
@@ -124,8 +125,9 @@ export function createSessionsClient({ name, claude, report, hookOn, routeOn, pe
|
|
|
124
125
|
const known = new Map();
|
|
125
126
|
let current = { id: '', title: '', project: '', cwd: '', model: '', startedAt: '', lastAt: '', isRunning: true };
|
|
126
127
|
let told = { session: '' };
|
|
128
|
+
const ownOnly = (method) => new Error(`${name}: ${method} works only in a mod's own session.`);
|
|
127
129
|
const colored = ({ color: _color, ...data }) => (told.session === data.id && told.color !== undefined ? { ...data, color: told.color } : data);
|
|
128
|
-
const keyOf = (scope) => scope.session ??
|
|
130
|
+
const keyOf = (scope) => scope.session ?? current.id;
|
|
129
131
|
const subscribe = (key) => {
|
|
130
132
|
if (queued.has(key))
|
|
131
133
|
return;
|
|
@@ -135,8 +137,8 @@ export function createSessionsClient({ name, claude, report, hookOn, routeOn, pe
|
|
|
135
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 }) }));
|
|
136
138
|
const tracksTasks = [...(listening.get(key) ?? []), ...(deciding.get(key) ?? [])].some(({ scope }) => scope.task !== undefined || scope.isGoal === true);
|
|
137
139
|
const subscriptions = [...heard(listening), ...(tracksTasks ? [{ event: TaskStart }] : [])];
|
|
138
|
-
await call(conversationMethods.subscribe, { session: key, subscriptions }).catch((error) => report(`sessions:${key}`, `Hears nothing from
|
|
139
|
-
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));
|
|
140
142
|
});
|
|
141
143
|
};
|
|
142
144
|
const parentsOf = (session) => {
|
|
@@ -206,10 +208,10 @@ export function createSessionsClient({ name, claude, report, hookOn, routeOn, pe
|
|
|
206
208
|
report(`session:${method}`, `The ${method} listener failed`, error);
|
|
207
209
|
return refusalOf(options, takes, error);
|
|
208
210
|
});
|
|
209
|
-
const decidersOf = (session, event
|
|
211
|
+
const decidersOf = (session, event) => [...(deciding.get(session) ?? [])].filter((entry) => entry.event === event);
|
|
210
212
|
const decides = async (entry, session, change) => (entry.matcher === undefined || matches(payloadOf(change), entry.matcher)) && (await inScope(entry, session, change));
|
|
211
|
-
const combined = async (session, event, change,
|
|
212
|
-
const askers = decidersOf(session, event
|
|
213
|
+
const combined = async (session, event, change, cancel) => {
|
|
214
|
+
const askers = decidersOf(session, event)
|
|
213
215
|
.map((entry) => async (latest) => {
|
|
214
216
|
if (!(await decides(entry, session, latest)))
|
|
215
217
|
return undefined;
|
|
@@ -223,7 +225,10 @@ export function createSessionsClient({ name, claude, report, hookOn, routeOn, pe
|
|
|
223
225
|
const method = (into, named, event) => (...args) => {
|
|
224
226
|
if (ended !== undefined)
|
|
225
227
|
throw new Error(`${name}: ${ended} has ended, so its ${named} never fires. Listen on its Session.`);
|
|
226
|
-
|
|
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);
|
|
227
232
|
};
|
|
228
233
|
return Object.fromEntries([
|
|
229
234
|
...Object.entries(sessionEvents).map(([named, event]) => [`on${named}`, method(listening, `on${named}`, event)]),
|
|
@@ -343,52 +348,17 @@ export function createSessionsClient({ name, claude, report, hookOn, routeOn, pe
|
|
|
343
348
|
throw new Error(`${name}: Claude Code dropped the prompt: ${submitted.drop}`);
|
|
344
349
|
};
|
|
345
350
|
const surfacesHere = async () => [...(await claude.session.surfaces())];
|
|
346
|
-
const sessionOf = (read, owned, isOwner = owned !== undefined) => {
|
|
351
|
+
const sessionOf = (read, owned, isOwner = owned !== undefined, hears = true) => {
|
|
347
352
|
const id = () => read().id;
|
|
348
353
|
const isHere = () => owned === undefined && id() === current.id;
|
|
349
354
|
const scope = () => (owned === undefined ? { session: id(), isAgent: true } : { session: owned.session, task: owned.task, isAgent: true });
|
|
350
355
|
const where = () => (owned === undefined ? { session: id() } : { session: owned.session, task: owned.task });
|
|
351
356
|
const turnsOf = async (options = {}) => (await call(conversationMethods.turns, { ...where(), ...options })).map((turn) => turnOf(where(), turn));
|
|
352
357
|
const contextsOf = async () => (await call(conversationMethods.contexts, where())).map((context) => contextOf(where(), context));
|
|
353
|
-
const
|
|
354
|
-
|
|
355
|
-
return read().id;
|
|
356
|
-
},
|
|
357
|
-
get title() {
|
|
358
|
-
return read().title;
|
|
359
|
-
},
|
|
360
|
-
get color() {
|
|
361
|
-
return read().color;
|
|
362
|
-
},
|
|
363
|
-
get project() {
|
|
364
|
-
return read().project;
|
|
365
|
-
},
|
|
366
|
-
get agentType() {
|
|
367
|
-
return read().agentType;
|
|
368
|
-
},
|
|
369
|
-
get model() {
|
|
370
|
-
return read().model;
|
|
371
|
-
},
|
|
372
|
-
get cwd() {
|
|
373
|
-
return read().cwd;
|
|
374
|
-
},
|
|
375
|
-
get isRunning() {
|
|
376
|
-
return read().isRunning;
|
|
377
|
-
},
|
|
378
|
-
get startedAt() {
|
|
379
|
-
return read().startedAt;
|
|
380
|
-
},
|
|
381
|
-
get lastAt() {
|
|
382
|
-
return read().lastAt;
|
|
383
|
-
},
|
|
384
|
-
get forkedFrom() {
|
|
385
|
-
return read().forkedFrom;
|
|
386
|
-
},
|
|
387
|
-
get visitedAt() {
|
|
388
|
-
return read().visitedAt;
|
|
389
|
-
},
|
|
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, {
|
|
390
360
|
search: (text, matcher) => recordPart(scope()).search(text, matcher),
|
|
391
|
-
...eventMethods(scope, true),
|
|
361
|
+
...(hears ? eventMethods(scope, true) : {}),
|
|
392
362
|
goal: goalOf(where),
|
|
393
363
|
context: async () => {
|
|
394
364
|
const all = await contextsOf();
|
|
@@ -419,12 +389,12 @@ export function createSessionsClient({ name, claude, report, hookOn, routeOn, pe
|
|
|
419
389
|
async visit(at) {
|
|
420
390
|
await act(id(), 'visit', at ?? new Date().toISOString(), owned);
|
|
421
391
|
},
|
|
422
|
-
};
|
|
392
|
+
});
|
|
423
393
|
if (isOwner)
|
|
424
394
|
return session;
|
|
425
395
|
const started = async (starting) => taskOf(id(), await starting.catch((error) => Promise.reject(new Error(`${name}: ${messageOf(error)}`))));
|
|
426
396
|
return Object.assign(session, {
|
|
427
|
-
startTask: (task) => started(task.isBackground === true || task.
|
|
397
|
+
startTask: (task) => started(task.isBackground === true || task.device !== undefined ? act(id(), 'startBackgroundTask', task) : isHere() ? spawnTask(claude, task) : act(id(), 'startTask', task)),
|
|
428
398
|
fork: (task) => started(isHere() && task.isBackground !== true && task.at === undefined ? spawnTask(claude, task, current.id) : act(id(), 'fork', task)),
|
|
429
399
|
delete: async () => {
|
|
430
400
|
await act(id(), 'delete', null);
|
|
@@ -488,7 +458,7 @@ export function createSessionsClient({ name, claude, report, hookOn, routeOn, pe
|
|
|
488
458
|
});
|
|
489
459
|
const listenTo = (method, named) => {
|
|
490
460
|
if (hookOn === undefined || routeOn === undefined)
|
|
491
|
-
throw
|
|
461
|
+
throw ownOnly(method);
|
|
492
462
|
const isBefore = method.startsWith('before');
|
|
493
463
|
if (named === 'PermissionCheck' || named === 'PermissionRequest') {
|
|
494
464
|
const routes = permissionRoutes?.();
|
|
@@ -569,18 +539,16 @@ export function createSessionsClient({ name, claude, report, hookOn, routeOn, pe
|
|
|
569
539
|
},
|
|
570
540
|
caption: (toolCall, text) => claude.ui.notice(toolCall.callId, text),
|
|
571
541
|
});
|
|
572
|
-
const
|
|
573
|
-
|
|
574
|
-
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)));
|
|
575
544
|
return asked.map((entry) => refusalOf(entry.options, beforeAnswerKeys[event], error)).find((answer) => answer !== undefined);
|
|
576
545
|
};
|
|
577
546
|
const listed = (data) => {
|
|
578
547
|
if (data.id !== current.id) {
|
|
579
548
|
known.set(data.id, data);
|
|
580
|
-
return sessionOf(() => known.get(data.id) ?? data);
|
|
549
|
+
return sessionOf(() => known.get(data.id) ?? data, undefined, false, false);
|
|
581
550
|
}
|
|
582
|
-
|
|
583
|
-
current = { ...current, title: data.title };
|
|
551
|
+
current = { ...current, title: current.title || data.title, device: data.device };
|
|
584
552
|
return currentSession;
|
|
585
553
|
};
|
|
586
554
|
return {
|
|
@@ -591,26 +559,23 @@ export function createSessionsClient({ name, claude, report, hookOn, routeOn, pe
|
|
|
591
559
|
list: async (scope = {}) => (await call(conversationMethods.sessions, scope)).map(listed),
|
|
592
560
|
get: async (id) => (id === current.id ? currentSession : listed(await call(conversationMethods.session, { session: id }))),
|
|
593
561
|
search: (text, matcher, options = {}) => searched({ text, ...searchOptionsOf(options) }, matcher),
|
|
594
|
-
...every,
|
|
595
562
|
},
|
|
596
|
-
changed(session, change,
|
|
563
|
+
changed(session, change, cancel) {
|
|
597
564
|
remember(session, change);
|
|
598
565
|
let payload;
|
|
599
|
-
for (const
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
void isHeard.then((isIn) => isIn && deliver());
|
|
613
|
-
}
|
|
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());
|
|
614
579
|
}
|
|
615
580
|
},
|
|
616
581
|
answerBefore: combined,
|
|
@@ -621,7 +586,7 @@ export function createSessionsClient({ name, claude, report, hookOn, routeOn, pe
|
|
|
621
586
|
follow(next) {
|
|
622
587
|
const moved = next.id !== current.id && current.id !== '';
|
|
623
588
|
const previous = current.id;
|
|
624
|
-
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() });
|
|
625
590
|
if (!moved)
|
|
626
591
|
return;
|
|
627
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
|
|
39
|
+
readonly pages: readonly PartDeclaration[];
|
|
33
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;
|
|
@@ -108,7 +118,8 @@ export type UiOptions<State extends object> = {
|
|
|
108
118
|
};
|
|
109
119
|
export type UiArea<State extends object> = {
|
|
110
120
|
readonly panes: Mod<State>['panes'];
|
|
111
|
-
readonly
|
|
121
|
+
readonly views: Mod<State>['views'];
|
|
122
|
+
readonly pages: Mod<State>['pages'];
|
|
112
123
|
readonly settings: Mod<State>['settings'];
|
|
113
124
|
readonly widgets: Mod<State>['widgets'];
|
|
114
125
|
readonly styles: Mod<State>['styles'];
|
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,IAAI,EAAE,YAAY,EAAE,MAAM,EAAE,aAAa,EAAgB,aAAa,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AACxH,OAAO,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEnD,OAAO,EAAW,KAAK,IAAI,EAAmC,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAGrG,OAAO,EAA8E,KAAK,aAAa,EAAE,KAAK,YAAY,EAA4B,MAAM,gBAAgB,CAAA;AAC5K,OAAO,EAA8C,KAAK,QAAQ,EAAkB,MAAM,iBAAiB,CAAA;AAG3G,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAGzC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAE3C,eAAO,MAAM,WAAW;aACtB,IAAI,EAAE,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AAgB,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
|
@@ -157,8 +157,8 @@ export function createUi({ name, claude, router, report, announce, mod, borrowed
|
|
|
157
157
|
let isResizeQueued = false;
|
|
158
158
|
const widgets = new Map();
|
|
159
159
|
const widgetAreas = new Map();
|
|
160
|
-
const
|
|
161
|
-
let
|
|
160
|
+
const parts = new Map();
|
|
161
|
+
let shownParts = { open: [], shown: null, isFocused: false };
|
|
162
162
|
const draws = new Map();
|
|
163
163
|
const latestDraws = new Map();
|
|
164
164
|
const failedDraws = new Set();
|
|
@@ -173,7 +173,7 @@ export function createUi({ name, claude, router, report, announce, mod, borrowed
|
|
|
173
173
|
const provides = [...provided(), ...(markdownRenders.size > 0 ? [styleInterface] : [])];
|
|
174
174
|
return {
|
|
175
175
|
widgets: [...widgets.values()].map(({ id, title, areas: listed, place }) => ({ id, title, areas: listed, ...(place === undefined ? {} : { place }) })),
|
|
176
|
-
pages: [...
|
|
176
|
+
pages: [...parts.values()].map(({ init: { id, title }, place }) => ({ id, title, ...(place === undefined ? {} : { place }) })),
|
|
177
177
|
...(provides.length === 0 ? {} : { provides }),
|
|
178
178
|
};
|
|
179
179
|
};
|
|
@@ -190,7 +190,7 @@ export function createUi({ name, claude, router, report, announce, mod, borrowed
|
|
|
190
190
|
};
|
|
191
191
|
const treeOf = (render, handlers) => {
|
|
192
192
|
const drawn = render();
|
|
193
|
-
return drawn === undefined ? null : elementData(drawn, handlers);
|
|
193
|
+
return drawn === undefined ? null : elementData(drawn, (run) => handlers.push(run) - 1);
|
|
194
194
|
};
|
|
195
195
|
const isAnyDrawingChanged = () => {
|
|
196
196
|
for (const [key, inputs] of latestDraws) {
|
|
@@ -238,7 +238,7 @@ export function createUi({ name, claude, router, report, announce, mod, borrowed
|
|
|
238
238
|
if (isObject(answer) && name !== cmodPluginName)
|
|
239
239
|
hear(answer['stylers'], false);
|
|
240
240
|
}, (error) => {
|
|
241
|
-
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)}`);
|
|
242
242
|
});
|
|
243
243
|
};
|
|
244
244
|
if (!isAsked)
|
|
@@ -429,9 +429,7 @@ export function createUi({ name, claude, router, report, announce, mod, borrowed
|
|
|
429
429
|
throw new Error(`${name}: Claude Code did not scroll ${id}: ${deny}`);
|
|
430
430
|
});
|
|
431
431
|
const addPane = (init) => {
|
|
432
|
-
checkPane(name, init);
|
|
433
|
-
if (panes.has(init.id))
|
|
434
|
-
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);
|
|
435
433
|
const added = { init, params: undefined };
|
|
436
434
|
panes.set(init.id, added);
|
|
437
435
|
paneLogs.set(init.id, logOnce(`${init.title} pane`));
|
|
@@ -487,61 +485,64 @@ export function createUi({ name, claude, router, report, announce, mod, borrowed
|
|
|
487
485
|
};
|
|
488
486
|
return pane;
|
|
489
487
|
};
|
|
490
|
-
const
|
|
491
|
-
const
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
const
|
|
496
|
-
|
|
497
|
-
|
|
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}`);
|
|
498
497
|
void send({ parts: partList() });
|
|
499
|
-
const
|
|
498
|
+
const part = {
|
|
500
499
|
id: init.id,
|
|
501
500
|
get isOpen() {
|
|
502
|
-
|
|
501
|
+
if (requested?.[0] === shownParts)
|
|
502
|
+
return requested[1];
|
|
503
|
+
return place === 'settings' ? shownParts.shown === init.id : openEntry(init.id) !== undefined;
|
|
503
504
|
},
|
|
504
505
|
get isShown() {
|
|
505
|
-
return
|
|
506
|
+
return [shownParts.shown, ...(shownParts.inApps ?? [])].includes(init.id);
|
|
506
507
|
},
|
|
507
508
|
get isFocused() {
|
|
508
|
-
return
|
|
509
|
+
return shownParts.shown === init.id && shownParts.isFocused;
|
|
509
510
|
},
|
|
510
511
|
get params() {
|
|
511
|
-
return (
|
|
512
|
+
return (openEntry(init.id)?.params ?? added.params);
|
|
512
513
|
},
|
|
513
514
|
async open(...[options]) {
|
|
514
515
|
if (options !== undefined && 'params' in options)
|
|
515
516
|
added.params = options.params;
|
|
517
|
+
requested = [shownParts, true];
|
|
516
518
|
await send({ requests: [{ open: init.id, ...(added.params === undefined ? {} : { params: added.params }), ...(options?.focus === true ? { focus: true } : {}) }] });
|
|
517
519
|
},
|
|
518
|
-
toggle: (options) => (
|
|
520
|
+
toggle: (options) => (part.isOpen ? part.close() : part.open(options)),
|
|
519
521
|
close: async () => {
|
|
522
|
+
requested = [shownParts, false];
|
|
520
523
|
await send({ requests: [{ close: init.id }] });
|
|
521
524
|
},
|
|
522
525
|
scrollTo: async (target, options) => {
|
|
523
526
|
await send({ requests: [{ scroll: init.id, to: target, ...(options?.block === undefined ? {} : { block: options.block }) }] });
|
|
524
527
|
},
|
|
525
|
-
focus: async (
|
|
526
|
-
const latest = [...(latestDraws.get(
|
|
527
|
-
if (latest === undefined || !drawsFocusable(treeOf(latest.render, []),
|
|
528
|
-
throw new Error(`${name}: the ${init.title}
|
|
529
|
-
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 }] });
|
|
530
533
|
},
|
|
531
534
|
remove() {
|
|
532
|
-
if (
|
|
535
|
+
if (parts.get(init.id) !== added)
|
|
533
536
|
return;
|
|
534
|
-
|
|
535
|
-
forgetDraws(
|
|
537
|
+
parts.delete(init.id);
|
|
538
|
+
forgetDraws(key);
|
|
536
539
|
void send({ parts: partList(), requests: [{ close: init.id }] });
|
|
537
540
|
},
|
|
538
541
|
};
|
|
539
|
-
return
|
|
542
|
+
return part;
|
|
540
543
|
};
|
|
541
544
|
const addWidget = (init) => {
|
|
542
|
-
checkPart(name, 'widget', init.id, init.title);
|
|
543
|
-
if (widgets.has(init.id))
|
|
544
|
-
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));
|
|
545
546
|
widgets.set(init.id, init);
|
|
546
547
|
announce(`the ${init.title} widget`);
|
|
547
548
|
void send({ parts: partList() });
|
|
@@ -644,18 +645,20 @@ export function createUi({ name, claude, router, report, announce, mod, borrowed
|
|
|
644
645
|
if ('markdown' in input)
|
|
645
646
|
return drawPart('markdown', 'markdown style', input, () => markdownDrawing(input.markdown, { surface: input.surface, columns: input.columns }));
|
|
646
647
|
if ('page' in input) {
|
|
647
|
-
const
|
|
648
|
+
const { page, ...props } = input;
|
|
649
|
+
const added = parts.get(page);
|
|
648
650
|
if (added === undefined)
|
|
649
|
-
throw new Error(`${name} has no ${
|
|
650
|
-
const title = `${added.init.title}
|
|
651
|
-
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)}` }));
|
|
652
654
|
}
|
|
653
|
-
const widget =
|
|
654
|
-
|
|
655
|
+
const { widget: id, turn, ...given } = input;
|
|
656
|
+
const widget = widgets.get(id);
|
|
657
|
+
if (widget === undefined || !widget.areas.includes(given.area))
|
|
655
658
|
return null;
|
|
656
|
-
widgetAreas.set(
|
|
657
|
-
const context = (
|
|
658
|
-
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));
|
|
659
662
|
};
|
|
660
663
|
const press = async ({ draw: drawn, handler, args }, caller) => {
|
|
661
664
|
const known = draws.get(drawn);
|
|
@@ -679,9 +682,10 @@ export function createUi({ name, claude, router, report, announce, mod, borrowed
|
|
|
679
682
|
};
|
|
680
683
|
return {
|
|
681
684
|
panes: { add: addPane },
|
|
682
|
-
|
|
685
|
+
views: { add: (init) => addPart('view', init, 'sidebar') },
|
|
686
|
+
pages: { add: (init) => addPart('page', init) },
|
|
683
687
|
settings: {
|
|
684
|
-
add: (init) =>
|
|
688
|
+
add: (init) => addPart('view', init, 'settings'),
|
|
685
689
|
open: async () => {
|
|
686
690
|
await send({ requests: [{ settings: true }] });
|
|
687
691
|
},
|
|
@@ -707,7 +711,7 @@ export function createUi({ name, claude, router, report, announce, mod, borrowed
|
|
|
707
711
|
if (method === partMethods.press)
|
|
708
712
|
return press(input, caller).then((value) => ({ value }));
|
|
709
713
|
if (method === partMethods.shown) {
|
|
710
|
-
|
|
714
|
+
shownParts = input;
|
|
711
715
|
return Promise.resolve({ value: null });
|
|
712
716
|
}
|
|
713
717
|
if (method === partMethods.stylers) {
|
|
@@ -727,7 +731,7 @@ export function createUi({ name, claude, router, report, announce, mod, borrowed
|
|
|
727
731
|
void send({ ...held, parts: partList(), isStart: true });
|
|
728
732
|
},
|
|
729
733
|
changed() {
|
|
730
|
-
if (widgets.size > 0 ||
|
|
734
|
+
if (widgets.size > 0 || parts.size > 0)
|
|
731
735
|
void send({ redraw: true });
|
|
732
736
|
if (panes.size === 0 && styles.size === 0)
|
|
733
737
|
return;
|
package/runtime/web.d.ts
CHANGED
|
@@ -1,63 +1,3 @@
|
|
|
1
|
-
export type SidebarTab = {
|
|
2
|
-
readonly key: string;
|
|
3
|
-
readonly label: string;
|
|
4
|
-
readonly isClosable: boolean;
|
|
5
|
-
};
|
|
6
|
-
export type ClosedPage = {
|
|
7
|
-
readonly mod: string;
|
|
8
|
-
readonly page: string;
|
|
9
|
-
readonly title: string;
|
|
10
|
-
};
|
|
11
|
-
export type SessionWait = {
|
|
12
|
-
readonly kind: 'permission';
|
|
13
|
-
readonly tool: string;
|
|
14
|
-
readonly input: Readonly<Record<string, unknown>>;
|
|
15
|
-
} | {
|
|
16
|
-
readonly kind: 'question';
|
|
17
|
-
readonly question: string;
|
|
18
|
-
};
|
|
19
|
-
export type TurnOutcome = {
|
|
20
|
-
readonly reason: 'answered' | 'stopped' | 'failed';
|
|
21
|
-
readonly at: string;
|
|
22
|
-
readonly failure?: string;
|
|
23
|
-
};
|
|
24
|
-
export type SessionAbout = {
|
|
25
|
-
readonly tabs: readonly SidebarTab[];
|
|
26
|
-
readonly pages: readonly ClosedPage[];
|
|
27
|
-
readonly isWorking?: boolean;
|
|
28
|
-
readonly waiting?: SessionWait;
|
|
29
|
-
readonly lastTurn?: TurnOutcome;
|
|
30
|
-
readonly contextPercent?: number;
|
|
31
|
-
};
|
|
32
|
-
export type WebView = {
|
|
33
|
-
readonly id: string;
|
|
34
|
-
readonly tab: string;
|
|
35
|
-
readonly columns: number;
|
|
36
|
-
};
|
|
37
|
-
export type WebInput = {
|
|
38
|
-
readonly draw: number;
|
|
39
|
-
readonly handler: number;
|
|
40
|
-
readonly key: string;
|
|
41
|
-
readonly kind: 'press' | 'change' | 'submit' | 'select' | 'link';
|
|
42
|
-
readonly value?: string;
|
|
43
|
-
readonly href?: string;
|
|
44
|
-
};
|
|
45
|
-
export type WebAction = ({
|
|
46
|
-
readonly type: 'press';
|
|
47
|
-
readonly view: string;
|
|
48
|
-
} & WebInput) | {
|
|
49
|
-
readonly type: 'open';
|
|
50
|
-
readonly mod: string;
|
|
51
|
-
readonly page: string;
|
|
52
|
-
} | {
|
|
53
|
-
readonly type: 'close';
|
|
54
|
-
readonly tab: string;
|
|
55
|
-
} | {
|
|
56
|
-
readonly type: 'prompt';
|
|
57
|
-
readonly text: string;
|
|
58
|
-
} | {
|
|
59
|
-
readonly type: 'stop';
|
|
60
|
-
};
|
|
61
1
|
export type ElementData = {
|
|
62
2
|
readonly $cmodElement: string;
|
|
63
3
|
readonly props: Readonly<Record<string, unknown>>;
|
|
@@ -65,18 +5,5 @@ export type ElementData = {
|
|
|
65
5
|
export type HandlerData = {
|
|
66
6
|
readonly $cmodHandler: number;
|
|
67
7
|
};
|
|
68
|
-
export type SessionEvents = {
|
|
69
|
-
readonly views: readonly WebView[];
|
|
70
|
-
readonly actions: readonly WebAction[];
|
|
71
|
-
};
|
|
72
|
-
export type WebDrawing = {
|
|
73
|
-
readonly view: string;
|
|
74
|
-
readonly draw: number;
|
|
75
|
-
readonly tree: unknown;
|
|
76
|
-
};
|
|
77
|
-
export type SessionPost = {
|
|
78
|
-
readonly about?: SessionAbout;
|
|
79
|
-
readonly drawings?: readonly WebDrawing[];
|
|
80
|
-
};
|
|
81
8
|
export declare function htmlOf(tree: unknown): string;
|
|
82
9
|
//# sourceMappingURL=web.d.ts.map
|
package/runtime/web.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web.d.ts","sourceRoot":"","sources":["../src/runtime/web.ts"],"names":[],"mappings":"AA4CA,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"web.d.ts","sourceRoot":"","sources":["../src/runtime/web.ts"],"names":[],"mappings":"AA4CA,MAAM,MAAM,WAAW,GAAG;IAAE,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAA;CAAE,CAAA;AAE9G,MAAM,MAAM,WAAW,GAAG;IAAE,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;CAAE,CAAA;AAE3D,wBAAgB,MAAM,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAI5C"}
|