@cmodjs/core 8.9.0 → 8.10.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.
Files changed (111) hide show
  1. package/docs/commands.md +13 -11
  2. package/docs/dependencies.md +6 -3
  3. package/docs/index.md +1 -1
  4. package/docs/jobs.md +1 -1
  5. package/docs/mod.md +1 -1
  6. package/docs/session.md +8 -7
  7. package/docs/testing.md +2 -2
  8. package/docs/ui.md +6 -5
  9. package/jobs/program.d.ts.map +1 -1
  10. package/jobs/program.js +5 -4
  11. package/mod.d.ts +34 -5
  12. package/mod.d.ts.map +1 -1
  13. package/package.json +1 -1
  14. package/records.d.ts +4 -2
  15. package/records.d.ts.map +1 -1
  16. package/records.js +6 -3
  17. package/register.d.ts.map +1 -1
  18. package/register.js +14 -5
  19. package/rpc.d.ts.map +1 -1
  20. package/rpc.js +1 -0
  21. package/runtime/bun.d.ts +7 -2
  22. package/runtime/bun.d.ts.map +1 -1
  23. package/runtime/bun.js +61 -7
  24. package/runtime/conversations.d.ts +3 -1
  25. package/runtime/conversations.d.ts.map +1 -1
  26. package/runtime/conversations.js +43 -36
  27. package/runtime/device.d.ts +2 -1
  28. package/runtime/device.d.ts.map +1 -1
  29. package/runtime/device.js +22 -1
  30. package/runtime/drawing-rules.d.ts +9 -0
  31. package/runtime/drawing-rules.d.ts.map +1 -0
  32. package/runtime/drawing-rules.js +46 -0
  33. package/runtime/engine.d.ts +3 -1
  34. package/runtime/engine.d.ts.map +1 -1
  35. package/runtime/hooks.d.ts +1 -1
  36. package/runtime/hooks.d.ts.map +1 -1
  37. package/runtime/hotkeys.d.ts.map +1 -1
  38. package/runtime/hotkeys.js +0 -7
  39. package/runtime/installer.js +3 -3
  40. package/runtime/interfaces.d.ts +47 -8
  41. package/runtime/interfaces.d.ts.map +1 -1
  42. package/runtime/interfaces.js +151 -15
  43. package/runtime/lifecycle.d.ts.map +1 -1
  44. package/runtime/lifecycle.js +61 -29
  45. package/runtime/parts.d.ts +2 -2
  46. package/runtime/parts.d.ts.map +1 -1
  47. package/runtime/parts.js +61 -35
  48. package/runtime/rpc.d.ts +11 -3
  49. package/runtime/rpc.d.ts.map +1 -1
  50. package/runtime/rpc.js +56 -19
  51. package/runtime/sessions.d.ts +2 -1
  52. package/runtime/sessions.d.ts.map +1 -1
  53. package/runtime/sessions.js +11 -4
  54. package/runtime/ui.d.ts +1 -0
  55. package/runtime/ui.d.ts.map +1 -1
  56. package/runtime/ui.js +62 -45
  57. package/runtime/widgets.d.ts +4 -2
  58. package/runtime/widgets.d.ts.map +1 -1
  59. package/runtime/widgets.js +6 -5
  60. package/session/session.d.ts +5 -1
  61. package/session/session.d.ts.map +1 -1
  62. package/src/jobs/program.ts +5 -4
  63. package/src/mod.ts +12 -4
  64. package/src/records.ts +8 -4
  65. package/src/register.ts +15 -5
  66. package/src/rpc.ts +2 -1
  67. package/src/runtime/bun.ts +58 -6
  68. package/src/runtime/conversations.ts +45 -36
  69. package/src/runtime/device.ts +21 -1
  70. package/src/runtime/drawing-rules.ts +42 -0
  71. package/src/runtime/engine.ts +3 -1
  72. package/src/runtime/hooks.ts +0 -1
  73. package/src/runtime/hotkeys.ts +0 -7
  74. package/src/runtime/installer.ts +3 -3
  75. package/src/runtime/interfaces.ts +187 -22
  76. package/src/runtime/lifecycle.ts +63 -29
  77. package/src/runtime/parts.ts +61 -33
  78. package/src/runtime/rpc.ts +65 -20
  79. package/src/runtime/sessions.ts +11 -5
  80. package/src/runtime/ui.ts +61 -38
  81. package/src/runtime/widgets.ts +9 -5
  82. package/src/session/session.ts +3 -1
  83. package/src/testing/fake-elements.ts +7 -23
  84. package/src/testing/fake-serve.ts +51 -9
  85. package/src/testing/fake-sessions.ts +5 -3
  86. package/src/testing.ts +9 -3
  87. package/src/ui/components.ts +13 -14
  88. package/src/ui/elements.ts +4 -4
  89. package/src/ui/palette.ts +38 -0
  90. package/src/ui/styles.ts +2 -0
  91. package/testing/fake-elements.d.ts.map +1 -1
  92. package/testing/fake-elements.js +9 -26
  93. package/testing/fake-serve.d.ts +6 -1
  94. package/testing/fake-serve.d.ts.map +1 -1
  95. package/testing/fake-serve.js +42 -5
  96. package/testing/fake-sessions.d.ts +1 -0
  97. package/testing/fake-sessions.d.ts.map +1 -1
  98. package/testing/fake-sessions.js +4 -2
  99. package/testing.d.ts.map +1 -1
  100. package/testing.js +12 -4
  101. package/ui/components.d.ts.map +1 -1
  102. package/ui/components.js +12 -13
  103. package/ui/elements.d.ts +2 -1
  104. package/ui/elements.d.ts.map +1 -1
  105. package/ui/elements.js +3 -3
  106. package/ui/palette.d.ts +17 -0
  107. package/ui/palette.d.ts.map +1 -0
  108. package/ui/palette.js +20 -0
  109. package/ui/styles.d.ts +1 -0
  110. package/ui/styles.d.ts.map +1 -1
  111. package/ui/styles.js +1 -0
@@ -1,5 +1,6 @@
1
1
  import { serveSocketPath, storeFolder } from '../records.js'
2
- import { addressCall, connectRpc, type RpcClient, type RpcHandler } from './rpc.js'
2
+ import { interfaceListeners, onMethod, type Listening } from './interfaces.js'
3
+ import { addressCall, connectRpc, isConnectionGone, RpcError, rpcCodes, type RpcClient, type RpcClock, type RpcHandler } from './rpc.js'
3
4
 
4
5
  declare const process: { readonly env: Readonly<Record<string, string | undefined>> }
5
6
 
@@ -7,6 +8,18 @@ declare function fetch(url: string, init: { readonly method?: string; readonly b
7
8
 
8
9
  declare function setTimeout(run: () => void, ms: number): { unref(): unknown }
9
10
 
11
+ declare function clearTimeout(timer: unknown): void
12
+
13
+ export function bunClock(keepsAlive: boolean): RpcClock {
14
+ return {
15
+ after: (ms, run) => {
16
+ const timer = setTimeout(run, ms)
17
+ if (!keepsAlive) timer.unref()
18
+ return { cancel: () => clearTimeout(timer) }
19
+ },
20
+ }
21
+ }
22
+
10
23
  export type BunInit = { readonly method?: string; readonly body?: string; readonly headers?: Readonly<Record<string, string>>; readonly socketPath?: string }
11
24
 
12
25
  export async function bunFetch(url: string, init: BunInit = {}): Promise<{ readonly status: number; readonly ok: boolean; readonly headers: Readonly<Record<string, string>>; readonly text: string }> {
@@ -18,11 +31,13 @@ export function connectServe({
18
31
  handle,
19
32
  onConnect,
20
33
  onError,
34
+ onLost,
21
35
  keepsConnecting = false,
22
36
  }: {
23
37
  readonly handle: RpcHandler
24
38
  readonly onConnect?: (client: RpcClient) => unknown
25
39
  readonly onError?: (error: unknown) => void
40
+ readonly onLost?: () => void
26
41
  readonly keepsConnecting?: boolean
27
42
  }): RpcClient {
28
43
  return connectRpc({
@@ -30,11 +45,48 @@ export function connectServe({
30
45
  handle,
31
46
  ...(onConnect === undefined ? {} : { onConnect }),
32
47
  ...(onError === undefined ? {} : { onError }),
33
- wait: (ms) =>
34
- new Promise<void>((resolve) => {
35
- const timer = setTimeout(resolve, ms)
36
- if (!keepsConnecting) timer.unref()
37
- }),
48
+ ...(onLost === undefined ? {} : { onLost }),
49
+ clock: bunClock(keepsConnecting),
38
50
  keepsConnecting,
39
51
  })
40
52
  }
53
+
54
+ export async function tellServe(method: string, args: readonly unknown[]): Promise<void> {
55
+ const serve = connectServe({ handle: (asked) => Promise.reject(new RpcError(rpcCodes.methodNotFound, `This connection only tells cmod serve, so it answers no ${asked}.`)) })
56
+ try {
57
+ await serve.request(method, args)
58
+ } catch (error) {
59
+ if (!isConnectionGone(error) && !(error instanceof RpcError && error.code === rpcCodes.methodNotFound)) throw error
60
+ } finally {
61
+ await serve.close()
62
+ }
63
+ }
64
+
65
+ export function hearServe<Payload>(listened: readonly Omit<Listening, 'id'>[], heard: (payload: Payload | undefined) => void, report: (error: unknown) => void): RpcClient {
66
+ const listeners = interfaceListeners({ report })
67
+ let isListening = false
68
+ let hasRead = false
69
+ const read = () => {
70
+ hasRead = true
71
+ heard(undefined)
72
+ }
73
+ return connectServe({
74
+ handle: async (method, params, signal) => {
75
+ const answered = await listeners.handler(method, params, signal)
76
+ if (answered !== undefined) return answered.result
77
+ if (method === onMethod) return null
78
+ throw new RpcError(rpcCodes.methodNotFound, `This connection only hears cmod serve, so it answers no ${method}.`)
79
+ },
80
+ onConnect: async (client) => {
81
+ if (!isListening) for (const listening of listened) listeners.listen(client, listening, (payload: Payload) => heard(payload))
82
+ isListening = true
83
+ await listeners.replay(client)
84
+ read()
85
+ },
86
+ onError: () => {
87
+ if (!hasRead) read()
88
+ },
89
+ onLost: read,
90
+ keepsConnecting: true,
91
+ })
92
+ }
@@ -16,9 +16,9 @@ import { beforeAnswerKeys, foldBefore, installBefore, relayOf, type Decide, type
16
16
  import type { Claude } from './claude.js'
17
17
  import { cmodPluginName, isNotInstalled } from './dependencies.js'
18
18
  import { MissingMachineId } from './device.js'
19
- import { interfaceListeners, interfaceMethods, providerActs, providerPeer, serveProviders, sessionActs, sessionsInterface, uiInterface, type HeldStatus, type Implementation, type Provided, type KeptListen, type ProvidedHeard, type ProviderIdentity, type StoreChange, type HeldSession } from './interfaces.js'
19
+ import { interfaceListeners, interfaceMethods, providerActs, providerPeer, serveProviders, sessionActs, sessionsInterface, uiInterface, type HeldStatus, type Implementation, type Provided, type KeptListen, type ProvidedHeard, type ProviderIdentity, type SessionsChange, type HeldSession, storeInterface, methodName, listeningOf, type StoreChange, type StorePart } from './interfaces.js'
20
20
  import { runCmod } from './programs.js'
21
- import { addressCall, connectRpc, RpcError, rpcCodes, type RpcClient } from './rpc.js'
21
+ import { addressCall, connectRpc, isConnectionGone, RpcError, rpcCodes, type RpcClient } from './rpc.js'
22
22
  import type { RoutedHook, Router } from './router.js'
23
23
  import { toolInputOf } from './tool-calls.js'
24
24
  import { conversationMethods, everySession, isAct, isHeardBy, isInScope, pickedColor, resultOf, spawnTask, usageOf, type Act, type Listened, type SessionColor } from './sessions.js'
@@ -56,6 +56,8 @@ export type Conversations = {
56
56
  color(): SessionColor
57
57
  onColor(listener: (told: SessionColor) => void): void
58
58
  onUnreached(listener: () => void): void
59
+ onStoreChange(listener: (part: StorePart | undefined) => void): void
60
+ tellStore(part: StorePart): void
59
61
  serveUi(methods: Implementation): void
60
62
  tellUi(event: string, payload: object): void
61
63
  tellProviders(names: readonly string[]): void
@@ -269,6 +271,7 @@ export function serveConversations({
269
271
  let serveChanges: Registered | undefined
270
272
  let isUnreached = false
271
273
  let unreached: () => void = () => undefined
274
+ let storeChanged: (part: StorePart | undefined) => void = () => undefined
272
275
  const local: { readonly client: RpcClient } = {
273
276
  client: connectRpc({
274
277
  call: call(`unix:${serveSocketPath(store)}`),
@@ -279,17 +282,20 @@ export function serveConversations({
279
282
  tellStatus()
280
283
  await served.replay()
281
284
  await held.replay(client)
285
+ storeChanged(undefined)
282
286
  await reconcileTasks()
283
287
  },
284
288
  onError: (error) => {
285
- claude.ui.warn('serve:connect', `cmod: this session waits for cmod serve: ${messageOf(error)}`)
289
+ if (!isUnreached) claude.ui.warn('serve:connect', `cmod: this session waits for cmod serve: ${messageOf(error)}`)
286
290
  isUnreached = true
287
291
  unreached()
288
292
  },
289
- wait: (ms) => new Promise<void>((resolve) => void claude.clock.after(ms, resolve)),
293
+ clock: claude.clock,
290
294
  keepsConnecting,
291
295
  }),
292
296
  }
297
+ held.followProviders(local.client)
298
+ held.listen(local.client, listeningOf(storeInterface, 'on', 'Change', [], undefined), (told: StoreChange) => storeChanged(told.part))
293
299
 
294
300
  const served = serveProviders({
295
301
  serve: local.client,
@@ -325,7 +331,7 @@ export function serveConversations({
325
331
 
326
332
  const followProvider = (identity: ProviderIdentity): OtherProvider => {
327
333
  const peer = providerPeer(local.client, identity)
328
- const change = held.listen(local.client, { interface: sessionsInterface, event: 'Change', kind: 'on', provider: identity }, (told: StoreChange) => {
334
+ const change = held.listen(local.client, { interface: sessionsInterface, event: 'Change', kind: 'on', provider: identity }, (told: SessionsChange) => {
329
335
  if (told.part === 'running') void closeEndedOn(peer, [told.session]).catch((error: unknown) => report('tasks', `Could not read whether a task ${identity.mod} runs ended`, error))
330
336
  })
331
337
  return { identity, peer, change }
@@ -547,7 +553,7 @@ export function serveConversations({
547
553
 
548
554
  const listenToServe = () => {
549
555
  serveChanges?.remove()
550
- serveChanges = held.listen(local.client, { interface: sessionsInterface, event: 'Change', kind: 'on', args: [session] }, (change: StoreChange) => {
556
+ serveChanges = held.listen(local.client, { interface: sessionsInterface, event: 'Change', kind: 'on', args: [session] }, (change: SessionsChange) => {
551
557
  if (change.part === 'tasks') void reconcileTasks()
552
558
  if (change.part === 'goal') void rereadGoal()
553
559
  })
@@ -757,11 +763,6 @@ export function serveConversations({
757
763
  if (!engineTurns.has('')) claude.clock.after(0, () => void compactNow())
758
764
  return null
759
765
  }
760
- if (action === 'sendTo') {
761
- const { to, type, text } = input as Pick<SessionSend, 'type' | 'text'> & { readonly to: string }
762
- if (to === session) throw new Error(`session ${session} cannot send as itself to itself.`)
763
- return actElsewhere(caller, to, 'send', { type, text, as: Session } satisfies SessionSend, undefined)
764
- }
765
766
  if (action === 'send') {
766
767
  const { type, text, as } = input as SessionSend
767
768
  if (as === Session) throw new Error(`session ${session} cannot send as itself to itself.`)
@@ -863,16 +864,6 @@ export function serveConversations({
863
864
  local.client.notify(sessionActs.changed, { session: from, part: 'tasks' })
864
865
  }
865
866
 
866
- const actElsewhere = async (caller: string, target: string, action: Act, input: unknown, task: string | undefined): Promise<unknown> => {
867
- if (action === 'send' && task === undefined && (input as SessionSend).as === Session) {
868
- const { type, text } = input as SessionSend
869
- const sent = await claude.session.send({ to: { sessionId: target }, text })
870
- if (sent.isDelivered === true) return null
871
- return actOn(target, action, { type, text }, { caller })
872
- }
873
- return actOn(target, action, input, { caller, ...(task === undefined ? {} : { task }) })
874
- }
875
-
876
867
  const merged = <Item>(saved: readonly Item[], kept: readonly Item[], key: (item: Item) => string): Item[] => {
877
868
  const keptKeys = new Set(kept.map(key))
878
869
  return [...saved.filter((item) => !keptKeys.has(key(item))), ...kept]
@@ -913,25 +904,26 @@ export function serveConversations({
913
904
 
914
905
  const fields = (request: Request, keys: readonly string[]) => Object.fromEntries(keys.flatMap((key) => (request[key] === undefined ? [] : [[key, request[key]]])))
915
906
 
907
+ const sessionNamed = async (id: string): Promise<SessionData> => {
908
+ const lookedUp = (client: Pick<RpcClient, 'request'>) =>
909
+ client.request<SessionData>(`${sessionsInterface}.session`, [id]).catch(async (error: unknown) => {
910
+ if (!(error instanceof RpcError && error.code === rpcCodes.methodNotFound)) throw error
911
+ const listed = (await client.request<SessionData[]>(`${sessionsInterface}.sessions`, [{ everyProject: true }])).find((each) => each.id === id)
912
+ if (listed === undefined) throw new RpcError(rpcCodes.notHeld, `No session ${id} on this provider.`)
913
+ return listed
914
+ })
915
+ const found = await firstHolding(lookedUp).catch((error: unknown) => {
916
+ throw isNotHeld(error) ? new Error(`no session ${id} on any of your devices.`) : error
917
+ })
918
+ return found.id === session ? { ...found, isRunning: true } : found
919
+ }
920
+
916
921
  const methods: Readonly<Record<string, (request: Request, caller: string | undefined) => Promise<unknown>>> = {
917
922
  async [conversationMethods.sessions](request) {
918
923
  const found = await listAll({ project: project(), ...fields(request, ['since', 'everyProject', 'running']) })
919
924
  return found.map((each) => (each.id === session ? { ...each, isRunning: true } : each))
920
925
  },
921
- async [conversationMethods.session](request) {
922
- const id = String(request['session'])
923
- const lookedUp = (client: Pick<RpcClient, 'request'>) =>
924
- client.request<SessionData>(`${sessionsInterface}.session`, [id]).catch(async (error: unknown) => {
925
- if (!(error instanceof RpcError && error.code === rpcCodes.methodNotFound)) throw error
926
- const listed = (await client.request<SessionData[]>(`${sessionsInterface}.sessions`, [{ everyProject: true }])).find((each) => each.id === id)
927
- if (listed === undefined) throw new RpcError(rpcCodes.notHeld, `No session ${id} on this provider.`)
928
- return listed
929
- })
930
- const found = await firstHolding(lookedUp).catch((error: unknown) => {
931
- throw isNotHeld(error) ? new Error(`no session ${id} on any of your devices.`) : error
932
- })
933
- return found.id === session ? { ...found, isRunning: true } : found
934
- },
926
+ [conversationMethods.session]: (request) => sessionNamed(String(request['session'])),
935
927
  async [conversationMethods.search](request) {
936
928
  const record = fields(request, ['session', 'task', 'turn', 'context', 'isAgent'])
937
929
  const options = { project: project(), ...fields(request, ['since', 'everyProject', 'running', 'before', 'limit']), record }
@@ -983,6 +975,9 @@ export function serveConversations({
983
975
  }
984
976
  return read(id, 'goal', task === undefined ? {} : { task })
985
977
  },
978
+ async [conversationMethods.mail](request) {
979
+ return read(String(request['session']), 'mail', fields(request, ['last']))
980
+ },
986
981
  async [conversationMethods.updateGoal](request) {
987
982
  const id = String(request['session'])
988
983
  const task = typeof request['task'] === 'string' ? request['task'] : undefined
@@ -1016,15 +1011,29 @@ export function serveConversations({
1016
1011
  const task = typeof request['task'] === 'string' ? request['task'] : undefined
1017
1012
  if (!isAct(action)) throw new Error(`cmod takes no action named ${action}.`)
1018
1013
  if (target === (await claude.session.id())) return perform(caller, action, request['input'], task)
1019
- return actElsewhere(caller, target, action, request['input'], task)
1014
+ const input = action === 'send' && task === undefined ? await fromHere(request['input']) : request['input']
1015
+ return actOn(target, action, input, { caller, ...(task === undefined ? {} : { task }) })
1020
1016
  },
1021
1017
  }
1022
1018
 
1019
+ const fromHere = async (input: unknown): Promise<unknown> => {
1020
+ if (!isObject(input) || input['as'] !== Session || input['from'] !== undefined) return input
1021
+ return { ...input, from: { session, title: (await sessionNamed(session)).title } }
1022
+ }
1023
+
1023
1024
  return {
1024
1025
  onUnreached(listener) {
1025
1026
  unreached = listener
1026
1027
  if (isUnreached) listener()
1027
1028
  },
1029
+ onStoreChange(listener) {
1030
+ storeChanged = listener
1031
+ },
1032
+ tellStore(part) {
1033
+ void local.client.request(methodName(storeInterface, 'changed'), [part]).catch((error: unknown) => {
1034
+ if (!isConnectionGone(error) && !(error instanceof RpcError && error.code === rpcCodes.methodNotFound)) report('store', `Could not tell the other sessions that ${part} changed`, error)
1035
+ })
1036
+ },
1028
1037
  async close() {
1029
1038
  serveChanges?.remove()
1030
1039
  await local.client.close()
@@ -1,3 +1,4 @@
1
+ import { devicePath, isObject } from '../records.js'
1
2
  import type { Device } from '../session/context/turn/device.js'
2
3
  import { ifMissing } from '../utils/paths.js'
3
4
  import { formatExit } from '../utils/text.js'
@@ -23,7 +24,26 @@ export type DeviceSources = {
23
24
  readonly fs: { read(path: string): Promise<string> }
24
25
  }
25
26
 
26
- export async function readDevice(claude: DeviceSources): Promise<Device> {
27
+ export async function readDevice(claude: DeviceSources, store: string): Promise<Device> {
28
+ const text = await claude.fs.read(devicePath(store)).catch(ifMissing(undefined))
29
+ return (text === undefined ? undefined : storedDevice(text)) ?? measureDevice(claude)
30
+ }
31
+
32
+ function storedDevice(text: string): Device | undefined {
33
+ let value: unknown
34
+ try {
35
+ value = JSON.parse(text)
36
+ } catch (error) {
37
+ if (error instanceof SyntaxError) return undefined
38
+ throw error
39
+ }
40
+ if (!isObject(value)) return undefined
41
+ const { id, name, os, arch } = value
42
+ const isDevice = typeof id === 'string' && machineId.test(id) && typeof name === 'string' && Object.values(systems).includes(os as Device['os']) && Object.values(machines).includes(arch as Device['arch'])
43
+ return isDevice ? { id, name, os: os as Device['os'], arch: arch as Device['arch'] } : undefined
44
+ }
45
+
46
+ export async function measureDevice(claude: DeviceSources): Promise<Device> {
27
47
  const output = async (argv: readonly string[]) => {
28
48
  const { exitCode, stdout, stderr } = await claude.process.run(argv)
29
49
  if (exitCode !== 0) throw new Error(`cmod could not read this computer: ${argv.join(' ')} ${formatExit(exitCode, stderr)}`)
@@ -0,0 +1,42 @@
1
+ export type DrawnNode = { readonly type: string; readonly key: unknown; readonly hover: unknown; readonly children: readonly unknown[] }
2
+
3
+ const oncePerKey: ReadonlySet<string> = new Set(['Input', 'Select', 'Markdown', 'Client', 'Raster', 'Image'])
4
+
5
+ export function refusal(tree: unknown, inside: (node: unknown) => DrawnNode | undefined): string | undefined {
6
+ const seen = new Set<string>()
7
+ for (const { type, key } of nodesIn(tree, inside)) {
8
+ if (!oncePerKey.has(type) || typeof key !== 'string') continue
9
+ if (seen.has(`${type}\u0000${key}`)) return `${type} "${key}" is drawn twice; each takes its own key`
10
+ seen.add(`${type}\u0000${key}`)
11
+ }
12
+ const [hovering] = hoversOutsideKeys(tree, inside, false)
13
+ if (hovering === undefined) return undefined
14
+ return `${hovering.type}${typeof hovering.key === 'string' ? ` "${hovering.key}"` : ''} hover has no Box with a key around it; the nearest keyed Box is what the pointer hovers, or a scope names its group`
15
+ }
16
+
17
+ export function insideData(node: unknown): DrawnNode | undefined {
18
+ if (typeof node !== 'object' || node === null || Array.isArray(node)) return undefined
19
+ const { $cmodElement: type, props } = node as Readonly<Record<string, unknown>>
20
+ if (typeof type !== 'string') return undefined
21
+ const fields = typeof props === 'object' && props !== null ? (props as Readonly<Record<string, unknown>>) : {}
22
+ return { type, key: fields['key'], hover: fields['hover'], children: [fields['children']].flat(Number.POSITIVE_INFINITY) }
23
+ }
24
+
25
+ function* nodesIn(node: unknown, inside: (node: unknown) => DrawnNode | undefined): Generator<DrawnNode> {
26
+ for (const each of [node].flat(Number.POSITIVE_INFINITY)) {
27
+ const drawn = inside(each)
28
+ if (drawn === undefined) continue
29
+ yield drawn
30
+ for (const child of drawn.children) yield* nodesIn(child, inside)
31
+ }
32
+ }
33
+
34
+ function* hoversOutsideKeys(node: unknown, inside: (node: unknown) => DrawnNode | undefined, isInKeyedBox: boolean): Generator<DrawnNode> {
35
+ for (const each of [node].flat(Number.POSITIVE_INFINITY)) {
36
+ const drawn = inside(each)
37
+ if (drawn === undefined) continue
38
+ const isKeyed = isInKeyedBox || (drawn.type === 'Box' && typeof drawn.key === 'string')
39
+ if (typeof drawn.hover === 'object' && drawn.hover !== null && !('scope' in drawn.hover) && !isKeyed) yield drawn
40
+ for (const child of drawn.children) yield* hoversOutsideKeys(child, inside, isKeyed)
41
+ }
42
+ }
@@ -1,6 +1,6 @@
1
1
  import type { HookStream, ProcessSpawnChunk, ProcessSpawnResult } from 'claude-code'
2
2
  import type { Claude } from './claude.js'
3
- import type { Providers } from './interfaces.js'
3
+ import type { Providers, StorePart } from './interfaces.js'
4
4
  import type { Parts } from './parts.js'
5
5
  import type { Router } from './router.js'
6
6
  import type { Failure } from './toaster.js'
@@ -22,6 +22,8 @@ export type Engine = {
22
22
  readonly widgets?: Widgets
23
23
  readonly parts?: Parts
24
24
  readonly onServeUnreached: (listener: () => void) => void
25
+ readonly onStoreChange: (listener: (part: StorePart | undefined) => void) => void
26
+ readonly storeChanged: (part: StorePart) => void
25
27
  }
26
28
 
27
29
  const engines = new WeakMap<object, Engine>()
@@ -22,7 +22,6 @@ export type RoutedEvent =
22
22
  | 'prompt.context'
23
23
  | 'prompt.attachment'
24
24
  | 'command.run'
25
- | 'command.describe'
26
25
  | 'session.measure'
27
26
  | 'skill.prompt'
28
27
  | 'ui.render'
@@ -3,7 +3,6 @@ import { boundCombos, hotkeyCommand } from '../records.js'
3
3
  import { ifMissing } from '../utils/paths.js'
4
4
  import { messageOf } from '../utils/text.js'
5
5
  import type { Claude } from './claude.js'
6
- import { cmodPluginName } from './dependencies.js'
7
6
  import type { Router } from './router.js'
8
7
  import type { Failure } from './toaster.js'
9
8
 
@@ -35,12 +34,6 @@ export async function createHotkeys({
35
34
  readonly answerInput: <Answer>(run: () => Promise<Answer>, passOn: () => Promise<unknown>) => Promise<Answer>
36
35
  readonly report: (failure: Failure) => void
37
36
  }): Promise<Readonly<Record<string, Hotkey>>> {
38
- if (name === cmodPluginName) {
39
- router.add('command.describe', async (e, next) => {
40
- const described = await next(e)
41
- return e.command.startsWith(hotkeyCommand(e.provider.plugin.replace(/@[^@]*$/, ''), '')) ? { ...described, isHidden: true } : described
42
- })
43
- }
44
37
  const entries = Object.entries(declared)
45
38
  if (entries.length === 0) return {}
46
39
  const combos = await readCombos(claude, configRoot)
@@ -62,7 +62,7 @@ export function createInstaller(name: string, claude: () => Claude, waiting: { s
62
62
  })
63
63
  waiting.show(() => open(true), next)
64
64
  if (isOpen) {
65
- await send({ redraw: true }).catch(log('the installer did not redraw'))
65
+ await send({ redraw: true, changed: [installView] }).catch(log('the installer did not redraw'))
66
66
  } else {
67
67
  isOpen = true
68
68
  await open(false).catch((error: unknown) => {
@@ -76,7 +76,7 @@ export function createInstaller(name: string, claude: () => Claude, waiting: { s
76
76
  return answer
77
77
  }
78
78
 
79
- const redraw = () => void send({ redraw: true }).catch(log('the installer did not redraw'))
79
+ const redraw = () => void send({ redraw: true, changed: [installView] }).catch(log('the installer did not redraw'))
80
80
 
81
81
  const actions = (...buttons: readonly RenderElement[]) => Box({ gap: 2, flexShrink: 0, children: buttons })
82
82
 
@@ -188,7 +188,7 @@ export function createInstaller(name: string, claude: () => Claude, waiting: { s
188
188
  } catch (error) {
189
189
  notice = { color: 'error', text: `The ${step.title} step's isDone failed: ${messageOf(error)}` }
190
190
  }
191
- await send({ redraw: true })
191
+ await send({ redraw: true, changed: [installView] })
192
192
  }
193
193
  return dialog(
194
194
  Text({ children: [Text({ bold: true, children: step.title }), Text({ dimColor: true, children: ` (${index} of ${total})` })] }),