@yaks/browse 0.0.0-stage → 0.2.36

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 (271) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +324 -2
  3. package/_dist/app.d.ts +8 -0
  4. package/_dist/app.d.ts.map +1 -0
  5. package/_dist/cli.d.ts +16 -0
  6. package/_dist/cli.d.ts.map +1 -0
  7. package/_dist/hosting.d.ts +24 -0
  8. package/_dist/hosting.d.ts.map +1 -0
  9. package/_dist/mod.d.ts +7 -0
  10. package/_dist/mod.d.ts.map +1 -0
  11. package/_dist/types.d.ts +5 -0
  12. package/_dist/types.d.ts.map +1 -0
  13. package/_dist/url.d.ts +2 -0
  14. package/_dist/url.d.ts.map +1 -0
  15. package/app.js +10 -0
  16. package/app.js.map +1 -0
  17. package/app.ts +10 -0
  18. package/browser-links.js +22 -0
  19. package/browser-links.js.map +1 -0
  20. package/browser-links.ts +28 -0
  21. package/cli.js +172 -0
  22. package/cli.js.map +1 -0
  23. package/cli.ts +168 -0
  24. package/client.js +748 -0
  25. package/client.js.map +1 -0
  26. package/client.ts +734 -0
  27. package/clipboard.js +18 -0
  28. package/clipboard.js.map +1 -0
  29. package/clipboard.ts +17 -0
  30. package/commands.js +1157 -0
  31. package/commands.js.map +1 -0
  32. package/commands.ts +1108 -0
  33. package/components/Ansi.tsx +160 -0
  34. package/components/App.tsx +446 -0
  35. package/components/Canvas.tsx +625 -0
  36. package/components/Card.tsx +276 -0
  37. package/components/Chat.tsx +205 -0
  38. package/components/Configuration.tsx +218 -0
  39. package/components/Decision.tsx +49 -0
  40. package/components/Dot.tsx +52 -0
  41. package/components/Entity.tsx +609 -0
  42. package/components/Fault.tsx +43 -0
  43. package/components/Filter.tsx +103 -0
  44. package/components/Keybindings.tsx +100 -0
  45. package/components/Keys.tsx +67 -0
  46. package/components/Markdown.tsx +90 -0
  47. package/components/Navigation.tsx +161 -0
  48. package/components/New.tsx +490 -0
  49. package/components/Peek.tsx +168 -0
  50. package/components/Prio.tsx +20 -0
  51. package/components/Run.tsx +263 -0
  52. package/components/Search.tsx +280 -0
  53. package/components/Stamp.tsx +44 -0
  54. package/components/Status.tsx +514 -0
  55. package/components/Sync.tsx +173 -0
  56. package/components/Tile.tsx +50 -0
  57. package/components/answered.js +23 -0
  58. package/components/answered.js.map +1 -0
  59. package/components/answered.ts +25 -0
  60. package/components/comp.js +11 -0
  61. package/components/comp.js.map +1 -0
  62. package/components/comp.ts +10 -0
  63. package/components/drag.js +173 -0
  64. package/components/drag.js.map +1 -0
  65. package/components/drag.ts +198 -0
  66. package/components/fields.tsx +90 -0
  67. package/components/fixtures/README.md +10 -0
  68. package/components/fixtures/archetypes.json +3646 -0
  69. package/components/hits.js +63 -0
  70. package/components/hits.js.map +1 -0
  71. package/components/hits.ts +84 -0
  72. package/components/icons.tsx +177 -0
  73. package/components/inspect.tsx +331 -0
  74. package/components/mount.ts +79 -0
  75. package/components/nav.tsx +479 -0
  76. package/components/offers.js +26 -0
  77. package/components/offers.js.map +1 -0
  78. package/components/offers.ts +54 -0
  79. package/components/page.js +21 -0
  80. package/components/page.js.map +1 -0
  81. package/components/page.ts +18 -0
  82. package/components/read.js +5 -0
  83. package/components/read.js.map +1 -0
  84. package/components/read.ts +7 -0
  85. package/components/registry.js +285 -0
  86. package/components/registry.js.map +1 -0
  87. package/components/registry.ts +317 -0
  88. package/components/session_status.tsx +115 -0
  89. package/components/subscriptions.js +149 -0
  90. package/components/subscriptions.js.map +1 -0
  91. package/components/subscriptions.ts +161 -0
  92. package/components/title.tsx +21 -0
  93. package/components/useQuery.js +166 -0
  94. package/components/useQuery.js.map +1 -0
  95. package/components/useQuery.ts +211 -0
  96. package/components/views/Board.tsx +450 -0
  97. package/components/views/BoardTile.tsx +65 -0
  98. package/components/views/Dashboard.tsx +148 -0
  99. package/components/views/Debug.tsx +445 -0
  100. package/components/views/Dependency.tsx +51 -0
  101. package/components/views/Entry.tsx +500 -0
  102. package/components/views/Gist.tsx +28 -0
  103. package/components/views/Inline.tsx +54 -0
  104. package/components/views/Json.tsx +19 -0
  105. package/components/views/Layout.tsx +211 -0
  106. package/components/views/List.tsx +238 -0
  107. package/components/views/Md.tsx +43 -0
  108. package/components/views/Media.tsx +48 -0
  109. package/components/views/Memory.tsx +32 -0
  110. package/components/views/Relate.tsx +205 -0
  111. package/components/views/Search.tsx +42 -0
  112. package/components/views/Session.tsx +850 -0
  113. package/components/views/SessionManage.tsx +127 -0
  114. package/components/views/Show.tsx +758 -0
  115. package/components/views/Shown.tsx +72 -0
  116. package/components/views/Split.tsx +58 -0
  117. package/components/views/TaskTile.tsx +37 -0
  118. package/components/views/Title.tsx +105 -0
  119. package/components/views/Wake.tsx +77 -0
  120. package/components/views/Web.tsx +49 -0
  121. package/components/wells.js +30 -0
  122. package/components/wells.js.map +1 -0
  123. package/components/wells.ts +33 -0
  124. package/configuration.js +38 -0
  125. package/configuration.js.map +1 -0
  126. package/configuration.ts +41 -0
  127. package/decision_sync.js +88 -0
  128. package/decision_sync.js.map +1 -0
  129. package/decision_sync.ts +93 -0
  130. package/deno.json +1 -0
  131. package/domain-host.tsx +108 -0
  132. package/edge.js +193 -0
  133. package/edge.js.map +1 -0
  134. package/edge.ts +196 -0
  135. package/entry_log.js +241 -0
  136. package/entry_log.js.map +1 -0
  137. package/entry_log.ts +214 -0
  138. package/failure.js +22 -0
  139. package/failure.js.map +1 -0
  140. package/failure.ts +34 -0
  141. package/front.json +61 -0
  142. package/highlight.js +143 -0
  143. package/highlight.js.map +1 -0
  144. package/highlight.ts +149 -0
  145. package/history.js +68 -0
  146. package/history.js.map +1 -0
  147. package/history.ts +72 -0
  148. package/host_commands.js +107 -0
  149. package/host_commands.js.map +1 -0
  150. package/host_commands.ts +38 -0
  151. package/hosting.js +53 -0
  152. package/hosting.js.map +1 -0
  153. package/hosting.ts +72 -0
  154. package/idb.js +14 -0
  155. package/idb.js.map +1 -0
  156. package/idb.ts +15 -0
  157. package/index.js +232 -0
  158. package/index.js.map +1 -0
  159. package/index.ts +252 -0
  160. package/keybindings.js +136 -0
  161. package/keybindings.js.map +1 -0
  162. package/keybindings.ts +37 -0
  163. package/kit.js +103 -0
  164. package/kit.js.map +1 -0
  165. package/kit.ts +119 -0
  166. package/layout.js +254 -0
  167. package/layout.js.map +1 -0
  168. package/layout.ts +210 -0
  169. package/legacy_outbox.js +53 -0
  170. package/legacy_outbox.js.map +1 -0
  171. package/legacy_outbox.ts +63 -0
  172. package/live.js +2883 -0
  173. package/live.js.map +1 -0
  174. package/live.ts +3334 -0
  175. package/live_archetypes.js +92 -0
  176. package/live_archetypes.js.map +1 -0
  177. package/live_archetypes.ts +113 -0
  178. package/live_client.js +145 -0
  179. package/live_client.js.map +1 -0
  180. package/live_client.ts +120 -0
  181. package/main.tsx +5 -0
  182. package/mod.js +7 -0
  183. package/mod.js.map +1 -0
  184. package/mod.ts +7 -0
  185. package/mount.tsx +50 -0
  186. package/navigation.js +120 -0
  187. package/navigation.js.map +1 -0
  188. package/navigation.ts +152 -0
  189. package/near.js +83 -0
  190. package/near.js.map +1 -0
  191. package/near.ts +83 -0
  192. package/new.js +295 -0
  193. package/new.js.map +1 -0
  194. package/new.ts +361 -0
  195. package/outbox.js +112 -0
  196. package/outbox.js.map +1 -0
  197. package/outbox.ts +129 -0
  198. package/owner.js +39 -0
  199. package/owner.js.map +1 -0
  200. package/owner.ts +37 -0
  201. package/package.json +81 -4
  202. package/paste.js +157 -0
  203. package/paste.js.map +1 -0
  204. package/paste.ts +122 -0
  205. package/props.js +303 -0
  206. package/props.js.map +1 -0
  207. package/props.ts +358 -0
  208. package/providers.js +136 -0
  209. package/providers.js.map +1 -0
  210. package/providers.ts +194 -0
  211. package/query.js +987 -0
  212. package/query.js.map +1 -0
  213. package/query.ts +1113 -0
  214. package/remote.js +37 -0
  215. package/remote.js.map +1 -0
  216. package/remote.ts +46 -0
  217. package/resolver.js +149 -0
  218. package/resolver.js.map +1 -0
  219. package/resolver.ts +213 -0
  220. package/rfc2047.js +37 -0
  221. package/rfc2047.js.map +1 -0
  222. package/rfc2047.ts +40 -0
  223. package/row_holds.js +107 -0
  224. package/row_holds.js.map +1 -0
  225. package/row_holds.ts +93 -0
  226. package/served.ts +42 -0
  227. package/session_worktree.js +7 -0
  228. package/session_worktree.js.map +1 -0
  229. package/session_worktree.ts +16 -0
  230. package/sessions.js +57 -0
  231. package/sessions.js.map +1 -0
  232. package/sessions.ts +53 -0
  233. package/sha.js +161 -0
  234. package/sha.js.map +1 -0
  235. package/sha.ts +164 -0
  236. package/styles.css +2823 -0
  237. package/subs.js +36 -0
  238. package/subs.js.map +1 -0
  239. package/subs.ts +40 -0
  240. package/terminal-route.js +13 -0
  241. package/terminal-route.js.map +1 -0
  242. package/terminal-route.ts +17 -0
  243. package/terminal.js +251 -0
  244. package/terminal.js.map +1 -0
  245. package/terminal.ts +186 -0
  246. package/time.js +142 -0
  247. package/time.js.map +1 -0
  248. package/time.ts +133 -0
  249. package/title.js +25 -0
  250. package/title.js.map +1 -0
  251. package/title.ts +50 -0
  252. package/tui/doc.ts +6 -0
  253. package/tui/testing.ts +19 -0
  254. package/twin.js +11 -0
  255. package/twin.js.map +1 -0
  256. package/twin.ts +13 -0
  257. package/types.js +456 -0
  258. package/types.js.map +1 -0
  259. package/types.ts +1370 -0
  260. package/url.js +77 -0
  261. package/url.js.map +1 -0
  262. package/url.ts +85 -0
  263. package/verb.js +82 -0
  264. package/verb.js.map +1 -0
  265. package/verb.ts +137 -0
  266. package/warmth.js +41 -0
  267. package/warmth.js.map +1 -0
  268. package/warmth.ts +54 -0
  269. package/wire.js +86 -0
  270. package/wire.js.map +1 -0
  271. package/wire.ts +63 -0
@@ -0,0 +1,263 @@
1
+ /** @jsxRuntime automatic *//** @jsxImportSourceTypes npm:react@19.3.0 *//** @jsxImportSource npm:react@19.3.0 */
2
+ import { useObserved } from 'jsr:@yaks/ux@0.2.36'
3
+ import { entityPath } from '../url.ts'
4
+ /* @ts-types="npm:@types/react@19.3.0" */ import { useEffect, useRef, useState } from 'npm:react@19.3.0'
5
+ import { signal } from 'npm:@preact/signals-core@1.14.5'
6
+ import { base, capable, ent, mutate, toPlane, topZ, uuid } from '../live.ts'
7
+ import {
8
+ catalog,
9
+ type Pick,
10
+ type Provider,
11
+ tableOf,
12
+ transport,
13
+ usingOf,
14
+ } from '../providers.ts'
15
+ import { sessionFrames, type SpawnAsk, spawnPlan } from '../client.ts'
16
+ import { type Change, idOf, vocab } from '../types.ts'
17
+ import {
18
+ block,
19
+ Button,
20
+ Card,
21
+ Modal,
22
+ Overlay,
23
+ Select,
24
+ usePlaceAt,
25
+ } from 'jsr:@yaks/ui@0.2.36'
26
+ import { HARNESS } from 'jsr:@yaks/harness@0.2.36/default'
27
+ import { menu, navigate, screenTarget } from './nav.tsx'
28
+
29
+ // The Run door: a task's "run session…" verb opens this over the point
30
+ // the menu stood on — model, effort; the provider is never asked, it is
31
+ // chosen for the pick by readiness — and writes ONE batch: the spawn
32
+ // (spawnOf), plus its card and pin when we're over a canvas, minted here
33
+ // like any other card the browser spawns. The choices are the graph's own
34
+ // provider and model entities, so the form offers only what the host can
35
+ // run, and anything it still can't honor shows on the session itself.
36
+ //
37
+ // Off a canvas (or on the List door, which has no plane) there's nothing
38
+ // to pin, so we navigate to the session instead.
39
+
40
+ type Ask = { eid: string; x: number; y: number }
41
+
42
+ // The live readiness predicate every spawn door judges transports by. No
43
+ // transport is blocked: a provider that cannot start says so on its session.
44
+ export let liveBlocked = (): Promise<(name: string) => boolean> =>
45
+ Promise.resolve(() => false)
46
+
47
+ // The live transport for a picked model: graph-native Codex only when its
48
+ // account is signed in, else the permanent CLI fallback.
49
+ export let choose = async (pick: Pick): Promise<string> =>
50
+ transport(pick, await liveBlocked())
51
+
52
+ let Frame = block('div', 'Run', {
53
+ Row: 'label',
54
+ Name: 'span',
55
+ })
56
+ let { Row, Name } = Frame
57
+ let close = () => run.value = null
58
+
59
+ // The table, read once per page from the graph: the providers, their
60
+ // models, and the `serves` edges between them (providers.ts tableOf).
61
+ export let providers = signal<Provider[]>([])
62
+ let read = async (q: string) =>
63
+ await (await fetch(`${base()}/query?q=${encodeURIComponent(q)}`)).json()
64
+ export let load = async () => {
65
+ if (!['provider', 'model', 'serves'].every((name) => vocab.comp(name))) {
66
+ return
67
+ }
68
+ try {
69
+ let found = await Promise.all(
70
+ ['.provider', '.model', '.serves&?edge'].map(read),
71
+ )
72
+ providers.value = tableOf(found.flat())
73
+ } catch { /* no table, no form — the verb simply does nothing yet */ }
74
+ }
75
+
76
+ // The model a native session asks when no one chose one: the using{provider,
77
+ // model} on the harness's own row (@yaks/harness/default), which
78
+ // `yak session new` asks too. Refused where the host names none.
79
+ export let nativeUsing = async (): Promise<
80
+ { provider: string; model?: string }
81
+ > => {
82
+ let [row] = vocab.comp('using')
83
+ ? await read(`.entity.eid=${HARNESS} ?using`)
84
+ : []
85
+ let using = row?.using as { provider?: string; model?: string } | undefined
86
+ if (!using?.provider) {
87
+ throw new Error('Choose a model: this host names no default for sessions')
88
+ }
89
+ return {
90
+ provider: using.provider,
91
+ ...(using.model ? { model: using.model } : {}),
92
+ }
93
+ }
94
+
95
+ // Every door's spawn (the Run form, :fix, :chat, the TUI): the plan
96
+ // (spawnPlan), its names resolved to the entities the table holds, and the
97
+ // write @yaks/spawn makes. The instruction is the prompt, else the task's id
98
+ // and title, the way session_spawn words it.
99
+ export let spawnOf = async (
100
+ ask: SpawnAsk & { task?: string; prompt?: string },
101
+ ): Promise<{ session: string; changes: Change[] }> => {
102
+ if (
103
+ !['session', 'entry', 'content', 'using'].every((name) => vocab.comp(name))
104
+ ) {
105
+ throw new Error('this host does not run sessions')
106
+ }
107
+ if (!providers.value.length) await load()
108
+ let plan = spawnPlan(providers.value, ask, await liveBlocked())
109
+ if (!plan.provider) throw new Error('no matching provider/model')
110
+ let task = ask.task ? ent(ask.task) : undefined
111
+ let body = ask.prompt ||
112
+ [task && idOf(task), task?.doc?.title].filter(Boolean).join(' — ')
113
+ let session = uuid()
114
+ let using = usingOf(providers.value, { ...plan, provider: plan.provider })
115
+ return {
116
+ session,
117
+ changes: sessionFrames(session, body, using, {
118
+ task: ask.task,
119
+ operator: false,
120
+ }),
121
+ }
122
+ }
123
+
124
+ export let run = signal<Ask | null>(null)
125
+
126
+ // The verb opens the form where the menu is: the click that runs it also
127
+ // closes the menu, so its point is taken NOW, not read back later.
128
+ export let openRun = (eid: string) => {
129
+ run.value = { eid, x: menu.value?.x ?? 0, y: menu.value?.y ?? 0 }
130
+ }
131
+
132
+ // Where the card should land: the root card is the canvas we're looking
133
+ // at, and the ask's point is where the session was asked for. Off a canvas
134
+ // (or on the List door, which has no plane) there's nowhere to pin.
135
+ let spot = (a: Ask) => {
136
+ if (!capable('canvas')) return null
137
+ let t = screenTarget()
138
+ let box = document.querySelector('.Canvas')?.getBoundingClientRect()
139
+ if (!t || !box || !ent(t.eid).canvas) return null
140
+ let at = toPlane(a.x, a.y, box)
141
+ return { canvas: t.eid, x: Math.round(at.x), y: Math.round(at.y) }
142
+ }
143
+
144
+ let Form = ({ a }: { a: Ask }) => {
145
+ let [choice, setChoice] = useState('')
146
+ let [effort, setEffort] = useState('')
147
+ let root = useRef<HTMLElement>(null)
148
+ usePlaceAt(root, a)
149
+ useEffect(() => {
150
+ let node = root.current
151
+ let opener = node?.ownerDocument.activeElement as HTMLElement | null
152
+ node?.querySelector<HTMLElement>('select')?.focus()
153
+ return () => {
154
+ if (
155
+ opener?.isConnected &&
156
+ node?.contains(opener.ownerDocument.activeElement)
157
+ ) {
158
+ opener.focus()
159
+ }
160
+ }
161
+ }, [])
162
+ useEffect(() => {
163
+ if (!providers.value.length) load()
164
+ }, [])
165
+
166
+ // Every choice is DERIVED, never stored beside the menu: a pick the
167
+ // menu no longer offers falls back to its first entry, and effort to
168
+ // the picked model's first, with nothing to keep in sync. Each model is
169
+ // offered ONCE — the transport is chosen at start by readiness.
170
+ let ms = catalog(useObserved(providers))
171
+ let m = ms.find((x) => x.model == choice) ?? ms[0]
172
+ let ef = m?.efforts.includes(effort) ? effort : m?.efforts[0]
173
+
174
+ let go = async () => {
175
+ if (!m) return
176
+ let at = spot(a)
177
+ let { session: eid, changes } = await spawnOf({
178
+ task: a.eid,
179
+ provider: await choose(m),
180
+ model: m.model,
181
+ ...(ef ? { effort: ef } : {}),
182
+ })
183
+ let card = uuid()
184
+ mutate(
185
+ ...changes,
186
+ ...(at
187
+ ? [
188
+ {
189
+ eid: card,
190
+ name: 'card',
191
+ comp: { target: eid, view: 'Session' },
192
+ },
193
+ {
194
+ eid: card,
195
+ name: 'pin',
196
+ comp: {
197
+ canvas: at.canvas,
198
+ x: at.x,
199
+ y: at.y,
200
+ w: 420,
201
+ h: 0,
202
+ z: topZ(at.canvas) + 1,
203
+ },
204
+ },
205
+ ]
206
+ : []),
207
+ )
208
+ run.value = null
209
+ if (!at) navigate(entityPath(eid))
210
+ }
211
+
212
+ return (
213
+ <Overlay
214
+ as={Card}
215
+ className='Run'
216
+ elRef={root}
217
+ role='dialog'
218
+ aria-labelledby='run-title'
219
+ onCancel={close}
220
+ overlay={{ blur: false }}
221
+ onPointerDown={(e: Event) => e.stopPropagation()}
222
+ >
223
+ <Modal.Head
224
+ title='Run session'
225
+ titleId='run-title'
226
+ close={{ onClick: close }}
227
+ />
228
+ <Row>
229
+ <Name>Model</Name>
230
+ <Select
231
+ value={m?.model}
232
+ onChange={(e: Event) =>
233
+ setChoice((e.target as HTMLSelectElement).value)}
234
+ >
235
+ {ms.map((x) => (
236
+ <option key={x.model} value={x.model}>{x.label}</option>
237
+ ))}
238
+ </Select>
239
+ </Row>
240
+ {/* effort is a provider's own axis — claude has none, so no row */}
241
+ {!!m?.efforts.length && (
242
+ <Row>
243
+ <Name>Effort</Name>
244
+ <Select
245
+ value={ef}
246
+ onChange={(e: Event) =>
247
+ setEffort((e.target as HTMLSelectElement).value)}
248
+ >
249
+ {m.efforts.map((x) => <option key={x} value={x}>{x}</option>)}
250
+ </Select>
251
+ </Row>
252
+ )}
253
+ <Button type='button' mod='go' disabled={!m} onClick={go}>Start</Button>
254
+ </Overlay>
255
+ )
256
+ }
257
+
258
+ // Keyed by the task: a second ask is a fresh form, not the last one's
259
+ // leftovers.
260
+ export let Run = () => {
261
+ let a = useObserved(run)
262
+ return a ? <Form key={a.eid} a={a} /> : null
263
+ }
@@ -0,0 +1,280 @@
1
+ /** @jsxRuntime automatic *//** @jsxImportSourceTypes npm:react@19.3.0 *//** @jsxImportSource npm:react@19.3.0 */
2
+ import { useDraft, useObserved } from 'jsr:@yaks/ux@0.2.36'
3
+ import { drafts } from 'jsr:@yaks/draft@0.2.36/input'
4
+ import { pagePath } from '../hosting.ts'
5
+ import { entityPath, searchPath } from '../url.ts'
6
+ /* @ts-types="npm:@types/react@19.3.0" */ import { useEffect, useLayoutEffect, useMemo, useRef, useState } from 'npm:react@19.3.0'
7
+ import { type Hit, idOf, kindOrder, plural } from '../types.ts'
8
+ import { searchOpen } from '../live.ts'
9
+ import { follow, navigate } from './nav.tsx'
10
+ import { Loading, Palette as Frame } from 'jsr:@yaks/ui@0.2.36'
11
+ import { Icon } from './icons.tsx'
12
+ import { fields } from './fields.tsx'
13
+ import { Entity } from './Entity.tsx'
14
+ import { InspectPage } from './inspect.tsx'
15
+ import { aggregate, hits as queryHits } from './hits.ts'
16
+ import { parse, words } from 'jsr:@yaks/query@0.2.36'
17
+ import { type Clock, system } from 'jsr:@yaks/fp@0.2.36'
18
+
19
+ // `/` in normal mode opens the palette (the App shell owns the hotkey
20
+ // and the mount, so any root can search; the `open` callback decides
21
+ // what a pick does); Escape closes it. Search runs server-side (FTS5
22
+ // over every doc) — the palette is just an input, a ranked list, and
23
+ // j/k-ish keys. searchOpen lives in the shell (live.ts) so a hot swap
24
+ // can't shut the palette; the query itself is the `search` field
25
+ // (fields.tsx), whose text is the person's draft until the palette closes.
26
+ export { searchOpen }
27
+
28
+ let { Box, Line, Page, Head, Hit: Row, Message: Snip } = Frame
29
+
30
+ // The palette is a NAVIGATOR — you open a board or project, not read mail —
31
+ // so hits group by kind: navigational kinds lead, bulky content kinds
32
+ // (mail, comment) sink to the tail under their own headers. A kind named in
33
+ // neither list falls between, ordered by kindOrder so grouping is stable.
34
+ let lead = ['project', 'board', 'task', 'design', 'memory', 'canvas']
35
+ let tail = ['mail', 'comment']
36
+ let rank = (kind: string) => {
37
+ let i = lead.indexOf(kind)
38
+ if (i >= 0) return i
39
+ let j = tail.indexOf(kind)
40
+ return j >= 0 ? 900 + j : 100 + kindOrder.indexOf(kind)
41
+ }
42
+ let exact = (h: Hit, q: string) => {
43
+ let sought = q.trim().replace(/^"(.*)"$/s, '$1').toLowerCase()
44
+ return idOf(h).toLowerCase() == sought ||
45
+ h.title.trim().toLowerCase() == sought
46
+ }
47
+
48
+ // An exact address or title stays first; section grouping must not bury the
49
+ // thing the operator named. Every other hit keeps the db's rank within its
50
+ // kind, and the flattened result is what the selection walks.
51
+ export let group = (hits: Hit[], q: string) =>
52
+ [...hits].sort((a, b) =>
53
+ Number(exact(b, q)) - Number(exact(a, q)) || rank(a.kind) - rank(b.kind)
54
+ )
55
+
56
+ // The palette's query is the person's draft.
57
+ let FIELD = 'search'
58
+
59
+ // The words a line searches for, which each result marks where they match;
60
+ // none while the line does not parse.
61
+ let sought = (q: string): string[] => {
62
+ try {
63
+ return words(parse(q))
64
+ } catch {
65
+ return []
66
+ }
67
+ }
68
+
69
+ export let Search = ({ open, clock = system }: {
70
+ open: (eid: string) => void
71
+ clock?: Clock
72
+ }) => {
73
+ let [hits, setHits] = useState<Hit[]>([])
74
+ let [err, setErr] = useState('')
75
+ let [answered, setAnswered] = useState<string | undefined>()
76
+ let [sel, setSel] = useState(0)
77
+ let q = useDraft(FIELD, drafts)
78
+ let searching = useObserved(searchOpen)
79
+ // One array a line, so a row redraws when the words change, not each time
80
+ // the selection moves.
81
+ let marks = useMemo(() => sought(q), [q])
82
+ let [drag, setDrag] = useState(false)
83
+ let box = useRef<HTMLInputElement>(null)
84
+ let seq = useRef(0)
85
+
86
+ useLayoutEffect(() => {
87
+ if (searching) box.current?.focus()
88
+ }, [searching])
89
+
90
+ // FTS shares the server's one event loop with keypress delivery. Search
91
+ // only after the line settles: a request per letter queues stale work ahead
92
+ // of the word the typist is still entering. Cleanup also keeps a late answer
93
+ // from repainting a closed or newer palette.
94
+ useEffect(() => {
95
+ if (!searching) return
96
+ if (!q.trim()) {
97
+ setHits([])
98
+ setErr('')
99
+ return
100
+ }
101
+ setHits([])
102
+ setErr('')
103
+ let abort = new AbortController()
104
+ let cancel = clock.after(150, () => {
105
+ void seek(q, abort.signal)
106
+ })
107
+ return () => {
108
+ cancel()
109
+ abort.abort()
110
+ }
111
+ }, [q, searching, clock])
112
+ if (!searching) return null
113
+
114
+ // The kind-grouped list, flattened: the selection index and every key
115
+ // walk THIS order, so arrowing crosses sections in the order they paint.
116
+ let waiting = !!q.trim() && answered != q
117
+ let ordered = group(waiting ? [] : hits, q)
118
+
119
+ let close = () => {
120
+ seq.current++
121
+ searchOpen.value = false
122
+ setHits([])
123
+ setAnswered(undefined)
124
+ setSel(0)
125
+ fields.set(FIELD, '')
126
+ setDrag(false)
127
+ }
128
+ let seek = async (q: string, signal: AbortSignal) => {
129
+ let mine = ++seq.current
130
+ let found: Hit[] = []
131
+ let bad = ''
132
+ try {
133
+ found = await queryHits(q, 20, signal)
134
+ } catch (e) {
135
+ if (signal.aborted) return
136
+ bad = e instanceof Error ? e.message : String(e)
137
+ }
138
+ if (signal.aborted || mine != seq.current) return // a newer keystroke owns the list
139
+ setHits(found)
140
+ setAnswered(q)
141
+ setErr(bad)
142
+ setSel(0)
143
+ }
144
+ let pick = (h: Hit) => {
145
+ open(h.eid)
146
+ close()
147
+ }
148
+ let href = (h: Hit) => entityPath(idOf(h))
149
+ // The field's list took its keys (Escape included) before these.
150
+ let key = (e: KeyboardEvent) => {
151
+ if (e.key == 'Enter') {
152
+ // ⌘/Ctrl+Enter is cmd-click on the selected hit: a new tab, the
153
+ // palette left standing — same as cmd-clicking the row anchor.
154
+ if (e.metaKey || e.ctrlKey) {
155
+ if (ordered[sel]) globalThis.open?.(href(ordered[sel]))
156
+ return
157
+ }
158
+ if (ordered[sel]) pick(ordered[sel])
159
+ else if (q.trim() && !waiting && !err) {
160
+ navigate(searchPath(q))
161
+ close()
162
+ }
163
+ return
164
+ }
165
+ let down = e.key == 'ArrowDown' || (e.ctrlKey && e.key == 'n') ||
166
+ (e.ctrlKey && e.key == 'j')
167
+ let up = e.key == 'ArrowUp' || (e.ctrlKey && e.key == 'p') ||
168
+ (e.ctrlKey && e.key == 'k')
169
+ if (!down && !up) return
170
+ e.preventDefault()
171
+ setSel((s) =>
172
+ Math.min(Math.max(s + (down ? 1 : -1), 0), ordered.length - 1)
173
+ )
174
+ }
175
+
176
+ return (
177
+ <Frame
178
+ mod={drag && 'drag'}
179
+ onMouseDown={(e: MouseEvent) => e.target == e.currentTarget && close()}
180
+ // The veil owns its pointers — a press here must not fall through
181
+ // to the shell beneath (Menu does the same).
182
+ onPointerDown={(e: PointerEvent) => e.stopPropagation()}
183
+ >
184
+ <Box
185
+ role='dialog'
186
+ aria-label='Search'
187
+ aria-modal='true'
188
+ onCancel={close}
189
+ overlay={{ blur: false }}
190
+ >
191
+ <Line>
192
+ <Icon name='search' />
193
+ <fields.Filter
194
+ id={FIELD}
195
+ mod='bare'
196
+ elRef={box}
197
+ placeholder='Search the graph…'
198
+ aria-label='Search the graph'
199
+ onKey={key}
200
+ />
201
+ {!!q.trim() && (
202
+ <Page
203
+ href={searchPath(q)}
204
+ draggable
205
+ aria-label='Open query as table'
206
+ data-tip='open query as table — or drag its link'
207
+ onClick={(ev: MouseEvent) => {
208
+ follow(searchPath(q))(ev)
209
+ if (ev.defaultPrevented) close()
210
+ }}
211
+ onDragStart={(ev: DragEvent) => {
212
+ let url = location.origin + pagePath(searchPath(q))
213
+ ev.dataTransfer?.setData('text/uri-list', url)
214
+ ev.dataTransfer?.setData('text/plain', url)
215
+ setDrag(true)
216
+ }}
217
+ onDragEnd={() => setDrag(false)}
218
+ >
219
+ <Icon name='arrow-up-right' />
220
+ </Page>
221
+ )}
222
+ </Line>
223
+ {waiting
224
+ ? <Loading>Searching…</Loading>
225
+ : err
226
+ ? <Snip>{err}</Snip>
227
+ : !q.trim()
228
+ ? (
229
+ <Snip>
230
+ Type words or a query · Escape closes · ⌘/Ctrl+Enter opens a new
231
+ tab
232
+ </Snip>
233
+ )
234
+ : answered == q && aggregate(q)
235
+ ? <InspectPage query={q} />
236
+ : answered == q && !ordered.length && <Snip>No results.</Snip>}
237
+ {
238
+ /* Each registry tile is its own real entity anchor. The result shell
239
+ intercepts only a plain click, whose search contract is to replace
240
+ the root; modifier clicks and the tile's entity menu stay native. */
241
+ }
242
+ {ordered.flatMap((h, i) => {
243
+ // A header opens each kind's run; the tail kinds (mail, comment)
244
+ // wear a divider so the navigational targets read as the top.
245
+ let head = !i || ordered[i - 1].kind != h.kind
246
+ let row = (
247
+ <Row
248
+ key={h.eid}
249
+ mod={i == sel ? 'sel' : undefined}
250
+ onMouseEnter={() => setSel(i)}
251
+ onClickCapture={(e: MouseEvent) => {
252
+ if (e.metaKey || e.ctrlKey || e.shiftKey || e.button != 0) {
253
+ return
254
+ }
255
+ e.preventDefault()
256
+ e.stopPropagation()
257
+ pick(h)
258
+ }}
259
+ >
260
+ <Entity eid={h.eid} view='Search.Tile' words={marks} />
261
+ </Row>
262
+ )
263
+ if (!head) return [row]
264
+ return [
265
+ <Head
266
+ key={`head-${h.kind}`}
267
+ mod={tail.includes(h.kind) && 'demoted'}
268
+ >
269
+ {plural(h.kind)}
270
+ </Head>,
271
+ row,
272
+ ]
273
+ })}
274
+ </Box>
275
+ </Frame>
276
+ )
277
+ }
278
+
279
+ // Addressed query results are the inspector's table/aggregate view.
280
+ export { InspectPage as SearchPage } from './inspect.tsx'
@@ -0,0 +1,44 @@
1
+ /** @jsxRuntime automatic *//** @jsxImportSourceTypes npm:react@19.3.0 *//** @jsxImportSource npm:react@19.3.0 */
2
+ // An age, said the human way. An entity says when it was created and, when
3
+ // present, edited; `at` names any other graph moment. The ages come off a
4
+ // minute tick, so an open card never fossilizes at the age it rendered, and
5
+ // the full stamps ride the tooltips.
6
+ /* @ts-types="npm:@types/react@19.3.0" */ import type { ReactNode } from 'npm:react@19.3.0'
7
+ import * as ui from 'jsr:@yaks/ui@0.2.36'
8
+ import { relative } from 'jsr:@yaks/ui@0.2.36'
9
+
10
+ /** How long ago a timestamp is, for plain text descriptions. */
11
+ export let ago = (iso?: string | null, now = Date.now()) => relative(iso, now)
12
+
13
+ export let Stamp = (
14
+ { e, at, label, by }: {
15
+ e?: {
16
+ created?: { at?: string; by?: string | null }
17
+ updated?: { at?: string; by?: string | null }
18
+ }
19
+ at?: string | null
20
+ label?: string
21
+ by?: (comp: 'created' | 'updated') => ReactNode
22
+ },
23
+ ) => {
24
+ let born = at ?? e?.created?.at
25
+ if (!born) return null
26
+ // `updated` presence is the edited signal (T-6670), but belongs only to the
27
+ // entity-age form.
28
+ let edited = at == null ? e?.updated?.at : undefined
29
+ return (
30
+ <ui.Stamp>
31
+ <span>
32
+ {label && `${label} `}
33
+ <ui.Time at={born} />
34
+ {by && e?.created?.by && <>{' by '}{by('created')}</>}
35
+ </span>
36
+ {edited && (
37
+ <span>
38
+ · edited <ui.Time at={edited} />
39
+ {by && e?.updated?.by && <>{' by '}{by('updated')}</>}
40
+ </span>
41
+ )}
42
+ </ui.Stamp>
43
+ )
44
+ }