@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,65 @@
1
+ /** @jsxRuntime automatic *//** @jsxImportSourceTypes npm:react@19.3.0 *//** @jsxImportSource npm:react@19.3.0 */
2
+ // A board's Tile and Meta faces: one ordinary linked tile whose second row
3
+ // carries the same status counts as the board's columns.
4
+ //
5
+ // The counts come from an AGGREGATE subscription, never the board's members
6
+ // (T-22509): a tile renders four numbers, so it asks the server for four
7
+ // numbers. Streaming membership for them put ~4.4k task rows on the wire for
8
+ // every canvas that showed the Everything tile; only a FULLSCREEN board
9
+ // (Board.tsx, List.tsx) opens the member sub.
10
+ /* @ts-types="npm:@types/react@19.3.0" */ import type { ReactNode } from 'npm:react@19.3.0'
11
+ import { type Ent } from '../../types.ts'
12
+ import { boardTally, statuses } from '../../live.ts'
13
+ import { Entity } from '../Entity.tsx'
14
+ import { menuAt } from '../nav.tsx'
15
+ import { useBoardTally } from '../subscriptions.ts'
16
+ import {
17
+ slot,
18
+ TileFrame,
19
+ tileLink,
20
+ type TileProps,
21
+ tileTitle,
22
+ } from '../Tile.tsx'
23
+ import { el } from 'jsr:@yaks/ui@0.2.36'
24
+ import { Dot } from '../Dot.tsx'
25
+ import { useDerived } from '../read.ts'
26
+ import { Meta } from './Show.tsx'
27
+
28
+ let Stat = el('span', 'BoardStat')
29
+
30
+ export let BoardMeta = (
31
+ { e, id, children }: { e: Ent; id?: boolean; children?: ReactNode },
32
+ ) => {
33
+ useBoardTally(e)
34
+ // No tally yet — the sub hasn't answered, or the query doesn't parse — paints
35
+ // no stats at all. Four zeros would be a claim, and a wrong one.
36
+ let counts = useDerived(() => boardTally(e), [e])
37
+ let stats = counts && (
38
+ <>
39
+ {statuses.map((status) => (
40
+ <Stat key={status}>
41
+ <Dot status={status} />
42
+ {counts[status] ?? 0}
43
+ </Stat>
44
+ ))}
45
+ </>
46
+ )
47
+ return <Meta e={e} id={id} before={stats}>{children}</Meta>
48
+ }
49
+
50
+ export let BoardTile = ({ e, slots, onOpen }: TileProps) => (
51
+ <TileFrame
52
+ mod={['board', 'dense']}
53
+ {...tileLink(e, onOpen)}
54
+ onContextMenu={menuAt(e)}
55
+ >
56
+ <TileFrame.Head>
57
+ {slot(slots, 'before')}
58
+ <TileFrame.Title {...tileTitle(slots, e.doc?.title ?? '')} />
59
+ </TileFrame.Head>
60
+ <Entity eid={e.eid} view='Meta' id>
61
+ {slot(slots, 'after')}
62
+ </Entity>
63
+ {slot(slots, 'body')}
64
+ </TileFrame>
65
+ )
@@ -0,0 +1,148 @@
1
+ /** @jsxRuntime automatic *//** @jsxImportSourceTypes npm:react@19.3.0 *//** @jsxImportSource npm:react@19.3.0 */
2
+ import { awake, type Ent } from '../../types.ts'
3
+ import { ent, sessionDetail } from '../../live.ts'
4
+ import { block } from 'jsr:@yaks/ui@0.2.36'
5
+ import { Entity } from '../Entity.tsx'
6
+ import { useQueryResult } from '../useQuery.ts'
7
+ import { applicable } from '../registry.ts'
8
+ import { tabOffers } from '../offers.ts'
9
+ import { Waiting } from '../inspect.tsx'
10
+ import { Answer } from 'jsr:@yaks/ux@0.2.36'
11
+ import { answeredOf, retryOf } from '../answered.ts'
12
+ import type { QueryResult } from '../useQuery.ts'
13
+
14
+ // The Project Cockpit (D-14587): a project's facets in a fixed grid —
15
+ // Boards, a cell for each tab a package offers on it, then Sessions · Lately —
16
+ // the same vocabulary in the same order on every project, so the eye
17
+ // learns one layout. Every cell is a LIVE QUERY rendered through the shared
18
+ // rows at summary density (--density, styles.css): membership is never
19
+ // stored, exactly as a board's isn't, and each row keeps List.Tile's click
20
+ // and menu contract — the cockpit arranges renderers, it adds none. An
21
+ // offered tab's cell draws the project in that view with `limit` in its
22
+ // context, under the tab's name and what waits there.
23
+
24
+ let Frame = block('div', 'Dash', {
25
+ Cell: 'section',
26
+ Name: 'h2',
27
+ Badge: 'span',
28
+ Rows: 'div',
29
+ More: 'div',
30
+ })
31
+ let { Cell, Name, Badge, Rows, More } = Frame
32
+
33
+ // Enough to glance; the facet's own view holds the rest.
34
+ let CAP = 8
35
+ // The claims whose sessions the sessions facet may draw.
36
+ let CLAIMS = 32
37
+
38
+ // The first of a cell's reads the server refused.
39
+ let refusedRead = (reads: QueryResult[]) =>
40
+ reads.find((r) => r.subscription?.state.status == 'failed')?.subscription
41
+
42
+ let Facet = (
43
+ { name, ids, badge, reads = [] }: {
44
+ name: string
45
+ ids: string[]
46
+ badge?: number
47
+ reads?: QueryResult[]
48
+ },
49
+ ) => (
50
+ <Cell>
51
+ <Name>
52
+ {name}
53
+ {(badge ?? 0) > 0 && <Badge>{badge}</Badge>}
54
+ </Name>
55
+ <Answer
56
+ answered={answeredOf(ids, {
57
+ ready: reads.every((r) => r.ready),
58
+ subscription: refusedRead(reads),
59
+ })}
60
+ empty={`No ${name.toLowerCase()}`}
61
+ failed={`${name} could not load.`}
62
+ retry={retryOf(refusedRead(reads))}
63
+ >
64
+ {(shown) => (
65
+ <Rows>
66
+ {shown.slice(0, CAP).map((id) => (
67
+ <Entity key={id} eid={id} view='List.Tile' />
68
+ ))}
69
+ {shown.length > CAP && <More>+{shown.length - CAP} more</More>}
70
+ </Rows>
71
+ )}
72
+ </Answer>
73
+ </Cell>
74
+ )
75
+
76
+ // The sessions serving this project: each through the task it claimed last,
77
+ // filed here. Awake first.
78
+ export let sessionsOf = (
79
+ e: Ent,
80
+ sessions: Ent[],
81
+ claims: Ent[],
82
+ ) => {
83
+ let jobs = new Map<string, Ent>()
84
+ for (let task of claims) {
85
+ if (!task.task || !task.claim) continue
86
+ let prior = jobs.get(task.claim.session)
87
+ if (
88
+ !prior || String(task.claim.at ?? '') >
89
+ String(prior.claim?.at ?? '')
90
+ ) jobs.set(task.claim.session, task)
91
+ }
92
+ return sessions
93
+ .filter((s) => {
94
+ let job = jobs.get(s.eid)
95
+ return job?.filed?.project == e.eid
96
+ })
97
+ .sort((a, b) => Number(awake(b)) - Number(awake(a)) || b.num - a.num)
98
+ }
99
+
100
+ export let Dashboard = ({ e }: { e: Ent }) => {
101
+ // The sessions facet asks only for what it draws: the newest claims on
102
+ // this project's tasks, then the sessions holding them, projected to the
103
+ // row columns and none of the history behind them (live.ts sessionDetail).
104
+ let boards = useQueryResult(`.board.query~=${e.eid}`)
105
+ let claims = useQueryResult(
106
+ `.claim&.filed.project=${e.eid}&.order=-claim.at&.limit=${CLAIMS}` +
107
+ '&.fields=task.status,claim.session,claim.at,filed.project',
108
+ )
109
+ let holders = [
110
+ ...new Set(claims.eids.map((eid) => ent(eid).claim?.session)),
111
+ ].filter((s): s is string => !!s)
112
+ let sessions = useQueryResult(
113
+ holders.length ? `${sessionDetail}&.entity.eid=${holders.join(',')}` : '',
114
+ holders.length > 0,
115
+ )
116
+ // This facet paints eight rows, so stream only its eight warmest. Fetching
117
+ // every task in every project card made the root canvas discard megabytes.
118
+ // Its sub-projects' tasks are its own.
119
+ let tasks = useQueryResult(
120
+ `.task&.filed.project->${e.eid}&.order=hot&.limit=${CAP}`,
121
+ )
122
+ let views = applicable(e)
123
+ let offered = tabOffers().filter((t) => views.includes(t.view))
124
+ return (
125
+ <Frame>
126
+ <Facet name='boards' ids={boards.eids} reads={[boards]} />
127
+ {offered.map((t) => (
128
+ <Cell key={t.view}>
129
+ <Name>
130
+ {t.view.toLowerCase()}
131
+ <Waiting offer={t} eid={e.eid}>{(n) => <Badge>{n}</Badge>}</Waiting>
132
+ </Name>
133
+ <Entity eid={e.eid} view={t.view} limit={CAP} />
134
+ </Cell>
135
+ ))}
136
+ <Facet
137
+ name='sessions'
138
+ reads={[sessions, claims]}
139
+ ids={sessionsOf(
140
+ e,
141
+ sessions.eids.map(ent),
142
+ claims.eids.map(ent),
143
+ ).map((s) => s.eid)}
144
+ />
145
+ <Facet name='lately' reads={[tasks]} ids={tasks.eids} />
146
+ </Frame>
147
+ )
148
+ }
@@ -0,0 +1,445 @@
1
+ /** @jsxRuntime automatic *//** @jsxImportSourceTypes npm:react@19.3.0 *//** @jsxImportSource npm:react@19.3.0 */
2
+ import { searchPath } from '../../url.ts'
3
+ /* @ts-types="npm:@types/react@19.3.0" */ import { Fragment, type ReactNode, useState } from 'npm:react@19.3.0'
4
+ import { formatProp, isRef, propAt } from '../../props.ts'
5
+ import {
6
+ comps as vocab,
7
+ type Ent,
8
+ idOf,
9
+ plural,
10
+ statusOf,
11
+ } from '../../types.ts'
12
+ import { ent, mutate, parents } from '../../live.ts'
13
+ import { BACKLINKS, useBacklinks } from '../useQuery.ts'
14
+ import { up } from './Dependency.tsx'
15
+ import * as ui from 'jsr:@yaks/ui@0.2.36'
16
+ import { Edit } from 'jsr:@yaks/ux@0.2.36'
17
+ import { bundle, renderView } from '../registry.ts'
18
+ import { Id } from './Inline.tsx'
19
+ import { Entity } from '../Entity.tsx'
20
+ import { viaName } from 'jsr:@yaks/kernel@0.2.36/Comments'
21
+ import { title } from '../title.tsx'
22
+ import { follow } from '../nav.tsx'
23
+ import { compTone } from '../comp.ts'
24
+ import { Icon } from '../icons.tsx'
25
+ import { dragData } from '../drag.ts'
26
+ import { Json } from './Json.tsx'
27
+ import { face, leaves, shape } from 'jsr:@yaks/inspect@0.2.36'
28
+
29
+ // Adding/removing comps is a browser power tool — the TUI paints Debug as
30
+ // static lines with no live events, so the controls stay web-only. typeof
31
+ // Deno is the seam: undefined in the browser bundle, set in the TUI's Deno
32
+ // process.
33
+ let browser = typeof Deno == 'undefined'
34
+
35
+ // The Debug view: one full inspector for the entity itself — EVERY prop,
36
+ // nothing hidden — with contained children as one linked Debug.Tile row
37
+ // each (a board full of tasks stays a list, not an explosion). The per-kind
38
+ // dispatch lives in Debug.Tile: tasks get the status row, everything
39
+ // else the generic one; the inspector's own head is its ListTile too.
40
+
41
+ let Frame = ui.block('div', 'Debug', {
42
+ Lens: 'div',
43
+ Head: 'div',
44
+ Tabs: 'div',
45
+ Key: 'span',
46
+ Comp: 'span',
47
+ Val: 'span',
48
+ Rm: 'button',
49
+ Add: 'div',
50
+ AddBtn: 'button',
51
+ AddList: 'div',
52
+ AddItem: 'button',
53
+ Item: 'div',
54
+ Kind: 'span',
55
+ Title: 'span',
56
+ Status: 'span',
57
+ Claim: 'span',
58
+ Prio: 'span',
59
+ Kids: 'div',
60
+ Linked: 'div',
61
+ Via: 'span',
62
+ })
63
+ let {
64
+ Lens,
65
+ Head,
66
+ Tabs,
67
+ Key,
68
+ Comp,
69
+ Val,
70
+ Rm,
71
+ Add,
72
+ AddBtn,
73
+ AddList,
74
+ AddItem,
75
+ Item,
76
+ Kind,
77
+ Title,
78
+ Status,
79
+ Claim,
80
+ Prio,
81
+ Kids,
82
+ Linked,
83
+ Via,
84
+ } = Frame
85
+ let { Tab } = ui.Tabs
86
+
87
+ // Raw file forms belong to the inspector, not every card's primary tab row.
88
+ // They remain draggable here because the same gesture is how a browser hands
89
+ // the serialized bytes to the desktop. The Markdown form is the registry's, so
90
+ // a kind whose package says it better (a persona as the text an agent is
91
+ // given) says it here.
92
+ export let DebugTabs = (
93
+ { e, head, children }: {
94
+ e: Ent
95
+ head?: ReactNode
96
+ children?: ReactNode
97
+ },
98
+ ) => {
99
+ let [view, setView] = useState('Debug')
100
+ let views = ['Debug', ...(e.doc ? ['Markdown'] : []), 'JSON']
101
+ return (
102
+ <Lens>
103
+ <Head>
104
+ {head}
105
+ <Tabs>
106
+ <ui.Tabs>
107
+ {views.map((v) => (
108
+ <Tab
109
+ key={v}
110
+ type='button'
111
+ mod={v == view && 'on'}
112
+ draggable={v != 'Debug'}
113
+ onDragStart={(ev: DragEvent) => dragData(ev, e.eid, v)}
114
+ onClick={() => setView(v)}
115
+ aria-label={v == 'Debug' ? 'Components' : v}
116
+ data-tip={v == 'Debug' ? 'Components' : v}
117
+ >
118
+ <Icon
119
+ name={v == 'Debug'
120
+ ? 'bug'
121
+ : v == 'Markdown'
122
+ ? 'hash'
123
+ : 'braces'}
124
+ />
125
+ </Tab>
126
+ ))}
127
+ </ui.Tabs>
128
+ </Tabs>
129
+ </Head>
130
+ {view == 'Markdown'
131
+ ? renderView(e, 'Markdown')
132
+ : view == 'JSON'
133
+ ? <Json e={e} />
134
+ : children}
135
+ </Lens>
136
+ )
137
+ }
138
+
139
+ // The comps an entity actually carries, minus the spine — the raw payload.
140
+ // Provenance (created/updated) rides in `rest` now like any component, so
141
+ // Debug renders each as its own key→value row (T-6670).
142
+ let comps = (e: Ent) => {
143
+ let {
144
+ eid: _e,
145
+ entity: _spine,
146
+ num: _n,
147
+ kind: _k,
148
+ refs: _r,
149
+ kids: _kids,
150
+ ...rest
151
+ } = e
152
+ return Object.entries(rest).filter(([, v]) => v) as [
153
+ string,
154
+ Record<string, unknown>,
155
+ ][]
156
+ }
157
+
158
+ // A value colored by its shape (@yaks/inspect). null and '' still show —
159
+ // debug hides nothing, including absence.
160
+ let leaf = (v: unknown) => <Val mod={shape(v)}>{face(v)}</Val>
161
+
162
+ // One key → value row of the kit's Pairs: a browser lines the values up in a
163
+ // column, a terminal writes `key: value` a line each.
164
+ let pair = (key: ReactNode, value: ReactNode) => (
165
+ <>
166
+ <ui.Pairs.Key>
167
+ <Key>{key}</Key>
168
+ </ui.Pairs.Key>
169
+ <ui.Pairs.Value>{value}</ui.Pairs.Value>
170
+ </>
171
+ )
172
+
173
+ // A reference reads as its ASSOCIATION, not its raw column: the entity's
174
+ // chip + title, then the eid it stored. One row, not two — the column
175
+ // (assignee, a uuid) and the association (assignee, the entity) said
176
+ // together. The chip is a link; the rest of the value opens the eid editor
177
+ // where the reference is wire-writable.
178
+ let refFace = (v: unknown) =>
179
+ v == null || v === '' ? null : (
180
+ <>
181
+ <Id e={ent(String(v))} /> {ent(String(v)).doc?.title ?? ''}{' '}
182
+ <Val mod='id'>{String(v)}</Val>
183
+ </>
184
+ )
185
+
186
+ // EVERY prop as a key → value row — the spine (eid, num), then each
187
+ // component whole ('pin.x 664'). kind is NOT here: it's derived, not
188
+ // data, and the summary line above already says it. Wire-writable props
189
+ // render through <Edit editable> — the typed vocabulary picks each one's
190
+ // editor, so the WHOLE entity is editable here with the right control and
191
+ // zero per-kind code; server-owned columns stay the plain read they are.
192
+ //
193
+ // A component's rows are the UNION of its stored columns and its
194
+ // vocabulary columns: a freshly-added comp lands in the cache empty
195
+ // (mutate({name, comp:{}})), so the vocab keys are what surface its
196
+ // editable Prop rows before any value exists — set memory.scope the
197
+ // moment you add memory. For an entity loaded whole (snapshot carries every
198
+ // column) this union is exactly its stored keys.
199
+ let cells = (e: Ent, name: string, comp: Record<string, unknown>) => {
200
+ let keys = [
201
+ ...new Set([...Object.keys(comp), ...Object.keys(vocab[name] ?? {})]),
202
+ ]
203
+ return keys.flatMap((k, i) => {
204
+ let v = comp[k]
205
+ let rm = browser && i == 0 && name in vocab && (
206
+ <Rm
207
+ type='button'
208
+ title={`remove ${name}`}
209
+ onClick={() => mutate({ eid: e.eid, name, comp: null })}
210
+ >
211
+ ×
212
+ </Rm>
213
+ )
214
+ // The reference detector reads the PropType, so `created.by`, `to`, and
215
+ // `project` are associations without a second naming convention.
216
+ let assoc = isRef(name, k)
217
+ let editable = k in (vocab[name] ?? {})
218
+ let key = (path: string[] = []) => (
219
+ <>
220
+ <Comp mod={compTone(name)}>{name}.</Comp>
221
+ {[k, ...path].join('.')}
222
+ {path.length == 0 && rm}
223
+ </>
224
+ )
225
+ // A value the reader can't edit opens into a row per leaf, so a
226
+ // structure reads as keys and values: `spend.parts.input [3,0,0,0,0.01]`.
227
+ if (!assoc && !editable) {
228
+ return leaves(v).map(([path, x]) => (
229
+ <Fragment key={[name, k, ...path].join('.')}>
230
+ {pair(key(path), leaf(x))}
231
+ </Fragment>
232
+ ))
233
+ }
234
+ return (
235
+ <Fragment key={`${name}.${k}`}>
236
+ {pair(
237
+ key(),
238
+ assoc
239
+ ? (
240
+ <Edit
241
+ e={bundle(e)}
242
+ comp={name}
243
+ prop={k}
244
+ editable={editable}
245
+ show={(_, val) => refFace(val)}
246
+ />
247
+ )
248
+ : <Edit e={bundle(e)} comp={name} prop={k} editable />,
249
+ )}
250
+ </Fragment>
251
+ )
252
+ })
253
+ }
254
+
255
+ let AllProps = ({ e }: { e: Ent }) => (
256
+ <ui.Pairs className='Debug_Props'>
257
+ {pair('eid', leaf(e.eid))}
258
+ {pair('num', leaf(e.num))}
259
+ {comps(e).flatMap(([name, comp]) => cells(e, name, comp))}
260
+ </ui.Pairs>
261
+ )
262
+
263
+ // The add-comp picker — a `+ component` toggle listing wire-writable
264
+ // comps this entity lacks (comps keys minus present ones). Selecting one
265
+ // applies an empty patch; the host upserts the row with its column defaults
266
+ // (a doc + empty memory reads as a memory at once, type defaulting to
267
+ // 'project'), and its columns then surface as the editable Prop rows
268
+ // above. The spine and `entity` are never comps here, so they can't be
269
+ // added; deleting the entity stays the verb menu's job.
270
+ export let AddComp = ({ e }: { e: Ent }) => {
271
+ let [open, setOpen] = useState(false)
272
+ let present = new Set(comps(e).map(([n]) => n))
273
+ let addable = Object.keys(vocab).filter((n) => !present.has(n)).sort()
274
+ let add = (name: string) => {
275
+ mutate({ eid: e.eid, name, comp: {} })
276
+ setOpen(false)
277
+ }
278
+ return (
279
+ <Add>
280
+ <AddBtn type='button' onClick={() => setOpen((o) => !o)}>
281
+ + component
282
+ </AddBtn>
283
+ {open && (
284
+ <AddList>
285
+ {addable.map((n) => (
286
+ <AddItem
287
+ key={n}
288
+ type='button'
289
+ onClick={() => add(n)}
290
+ >
291
+ <Comp mod={compTone(n)}>{n}</Comp>
292
+ </AddItem>
293
+ ))}
294
+ </AddList>
295
+ )}
296
+ </Add>
297
+ )
298
+ }
299
+
300
+ export let Debug = (
301
+ { e, project, tabs = true }: { e: Ent; project?: boolean; tabs?: boolean },
302
+ ) => {
303
+ // Incoming references too: whatever points here, said by which prop
304
+ // brought it (useBacklinks — the held eid-keyed reverse sub, derived from
305
+ // the typed vocabulary: sessions on their task, cards on their target, …).
306
+ let incoming = useBacklinks(e.eid)
307
+ let head = <Entity eid={e.eid} view='Debug.Tile' />
308
+ let body = (
309
+ <>
310
+ <AllProps e={e} />
311
+ {browser && <AddComp e={e} />}
312
+ {parents(e.eid).map((d) => (
313
+ <Entity
314
+ key={d.parent + d.type}
315
+ eid={d.parent}
316
+ view='Dependency'
317
+ type={d.type}
318
+ label={up(d.type)}
319
+ />
320
+ ))}
321
+ {e.refs.map((r) => (
322
+ <Entity key={r.child} eid={r.child} view='Dependency' type={r.type} />
323
+ ))}
324
+ {e.kids.length > 0 && (
325
+ <Kids>
326
+ {e.kids.map((k) => (
327
+ <Entity key={k.eid} eid={k.eid} view='Debug.Tile' />
328
+ ))}
329
+ </Kids>
330
+ )}
331
+ {project
332
+ ? <ProjectIncoming e={e} {...incoming} />
333
+ : incoming.links.length > 0 && (
334
+ <Kids>
335
+ {incoming.links.map((b) => (
336
+ <Linked key={b.from + b.via}>
337
+ <Via>← {b.via}</Via>
338
+ <Entity eid={b.from} view='Debug.Tile' />
339
+ </Linked>
340
+ ))}
341
+ {incoming.more && <Census e={e} />}
342
+ </Kids>
343
+ )}
344
+ </>
345
+ )
346
+ return (
347
+ <Frame>
348
+ {browser && tabs
349
+ ? <DebugTabs e={e} head={head}>{body}</DebugTabs>
350
+ : <>{head}{body}</>}
351
+ </Frame>
352
+ )
353
+ }
354
+
355
+ let CAP = 3
356
+ let groups = (links: { from: string; via: string }[]) => {
357
+ let out = new Map<string, { kind: string; via: string; ids: string[] }>()
358
+ for (let link of links) {
359
+ if (link.via.endsWith('.by')) continue
360
+ let kind = ent(link.from).kind
361
+ let key = `${link.via}\0${kind}`
362
+ let group = out.get(key) ?? { kind, via: link.via, ids: [] }
363
+ group.ids.push(link.from)
364
+ out.set(key, group)
365
+ }
366
+ return [...out.values()].map((group) => ({
367
+ ...group,
368
+ ids: group.ids.toSorted((a, b) => ent(b).num - ent(a).num),
369
+ }))
370
+ }
371
+
372
+ // The window holds the newest referrers; the inspector reads every one.
373
+ let Census = ({ e }: { e: Ent }) => {
374
+ let href = searchPath(`.refs=${idOf(e)}`)
375
+ return (
376
+ <Linked href={href} onClick={follow(href)}>
377
+ <Via>← refs</Via>
378
+ the newest {BACKLINKS} are shown; every one
379
+ </Linked>
380
+ )
381
+ }
382
+
383
+ let ProjectIncoming = (
384
+ { e, links, more }: { e: Ent } & ReturnType<typeof useBacklinks>,
385
+ ) => {
386
+ let linked = groups(links)
387
+ if (!linked.length) return null
388
+ return (
389
+ <Kids>
390
+ {linked.flatMap((group) => {
391
+ let shown = group.ids.slice(0, CAP)
392
+ let rest = group.ids.length - shown.length
393
+ let query = `.${group.via}=${idOf(e)}`
394
+ let href = searchPath(query)
395
+ return [
396
+ ...shown.map((eid) => (
397
+ <Linked key={group.via + eid}>
398
+ <Via>← {group.via}</Via>
399
+ <Entity eid={eid} view='Debug.Tile' />
400
+ </Linked>
401
+ )),
402
+ ...(rest
403
+ ? [
404
+ <Linked
405
+ key={group.via + group.kind}
406
+ href={href}
407
+ onClick={follow(href)}
408
+ >
409
+ <Via>← {group.via}</Via>
410
+ +{rest} more {plural(group.kind)}
411
+ </Linked>,
412
+ ]
413
+ : []),
414
+ ]
415
+ })}
416
+ {more && <Census e={e} />}
417
+ </Kids>
418
+ )
419
+ }
420
+
421
+ // A project is an actor and a home, so its complete backlink set is an
422
+ // activity ledger. Attribution belongs in history; associations stay here,
423
+ // capped per relation with a filtered census link for the remainder.
424
+ export let ProjectDebug = ({ e }: { e: Ent }) => <Debug e={e} project />
425
+
426
+ export let DebugTaskItem = ({ e }: { e: Ent }) => (
427
+ <Item>
428
+ <Id e={e} />
429
+ <Kind>{e.kind}</Kind>
430
+ <Title {...title(e.doc?.title ?? '')} />
431
+ {e.claim && <Claim>⚑ {viaName(e.claim.session)}</Claim>}
432
+ <Prio>
433
+ {formatProp(propAt('filed', 'priority')!, e.filed?.priority ?? 0)}
434
+ </Prio>
435
+ <Status mod={statusOf(e)}>{statusOf(e)}</Status>
436
+ </Item>
437
+ )
438
+
439
+ export let DebugAnyItem = ({ e }: { e: Ent }) => (
440
+ <Item>
441
+ <Id e={e} />
442
+ <Kind>{e.kind}</Kind>
443
+ {e.doc?.title && <Title {...title(e.doc.title)} />}
444
+ </Item>
445
+ )