@yaks/tracker 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 (198) hide show
  1. package/Histogram.js +71 -0
  2. package/Histogram.js.map +1 -0
  3. package/Histogram.ts +100 -0
  4. package/LICENSE +202 -0
  5. package/README.md +639 -2
  6. package/_dist/brief.d.ts +25 -0
  7. package/_dist/brief.d.ts.map +1 -0
  8. package/_dist/changes.d.ts +9 -0
  9. package/_dist/changes.d.ts.map +1 -0
  10. package/_dist/chart.d.ts +24 -0
  11. package/_dist/chart.d.ts.map +1 -0
  12. package/_dist/digest.d.ts +64 -0
  13. package/_dist/digest.d.ts.map +1 -0
  14. package/_dist/effects.d.ts +73 -0
  15. package/_dist/effects.d.ts.map +1 -0
  16. package/_dist/errors.d.ts +14 -0
  17. package/_dist/errors.d.ts.map +1 -0
  18. package/_dist/everywhere.d.ts +13 -0
  19. package/_dist/everywhere.d.ts.map +1 -0
  20. package/_dist/fault.d.ts +29 -0
  21. package/_dist/fault.d.ts.map +1 -0
  22. package/_dist/file.d.ts +6 -0
  23. package/_dist/file.d.ts.map +1 -0
  24. package/_dist/fixtime.d.ts +20 -0
  25. package/_dist/fixtime.d.ts.map +1 -0
  26. package/_dist/frames.d.ts +6 -0
  27. package/_dist/frames.d.ts.map +1 -0
  28. package/_dist/graph.d.ts +3 -0
  29. package/_dist/graph.d.ts.map +1 -0
  30. package/_dist/group.d.ts +21 -0
  31. package/_dist/group.d.ts.map +1 -0
  32. package/_dist/instrument.d.ts +37 -0
  33. package/_dist/instrument.d.ts.map +1 -0
  34. package/_dist/intake.d.ts +21 -0
  35. package/_dist/intake.d.ts.map +1 -0
  36. package/_dist/merge.d.ts +11 -0
  37. package/_dist/merge.d.ts.map +1 -0
  38. package/_dist/mod.d.ts +7 -0
  39. package/_dist/mod.d.ts.map +1 -0
  40. package/_dist/model.d.ts +20 -0
  41. package/_dist/model.d.ts.map +1 -0
  42. package/_dist/outage.d.ts +7 -0
  43. package/_dist/outage.d.ts.map +1 -0
  44. package/_dist/people.d.ts +3 -0
  45. package/_dist/people.d.ts.map +1 -0
  46. package/_dist/poll.d.ts +101 -0
  47. package/_dist/poll.d.ts.map +1 -0
  48. package/_dist/poll_thread.d.ts +8 -0
  49. package/_dist/poll_thread.d.ts.map +1 -0
  50. package/_dist/reading.d.ts +34 -0
  51. package/_dist/reading.d.ts.map +1 -0
  52. package/_dist/remote.d.ts +61 -0
  53. package/_dist/remote.d.ts.map +1 -0
  54. package/_dist/report.d.ts +324 -0
  55. package/_dist/report.d.ts.map +1 -0
  56. package/_dist/resolution.d.ts +22 -0
  57. package/_dist/resolution.d.ts.map +1 -0
  58. package/_dist/routes.d.ts +33 -0
  59. package/_dist/routes.d.ts.map +1 -0
  60. package/_dist/script.d.ts +8 -0
  61. package/_dist/script.d.ts.map +1 -0
  62. package/_dist/service.d.ts +30 -0
  63. package/_dist/service.d.ts.map +1 -0
  64. package/_dist/sync_health.d.ts +4 -0
  65. package/_dist/sync_health.d.ts.map +1 -0
  66. package/_dist/ticket.d.ts +14 -0
  67. package/_dist/ticket.d.ts.map +1 -0
  68. package/_dist/tools.d.ts +39 -0
  69. package/_dist/tools.d.ts.map +1 -0
  70. package/_dist/trace-intake.d.ts +25 -0
  71. package/_dist/trace-intake.d.ts.map +1 -0
  72. package/_dist/views.d.ts +11 -0
  73. package/_dist/views.d.ts.map +1 -0
  74. package/_dist/vocab.d.ts +9 -0
  75. package/_dist/vocab.d.ts.map +1 -0
  76. package/box.json +51 -0
  77. package/brief.js +86 -0
  78. package/brief.js.map +1 -0
  79. package/brief.ts +120 -0
  80. package/changes.js +57 -0
  81. package/changes.js.map +1 -0
  82. package/changes.ts +70 -0
  83. package/chart.js +186 -0
  84. package/chart.js.map +1 -0
  85. package/chart.ts +193 -0
  86. package/deno.json +1 -0
  87. package/digest.js +329 -0
  88. package/digest.js.map +1 -0
  89. package/digest.ts +406 -0
  90. package/effects.js +136 -0
  91. package/effects.js.map +1 -0
  92. package/effects.ts +178 -0
  93. package/errors.js +130 -0
  94. package/errors.js.map +1 -0
  95. package/errors.ts +185 -0
  96. package/everywhere.js +46 -0
  97. package/everywhere.js.map +1 -0
  98. package/everywhere.ts +66 -0
  99. package/fault.js +65 -0
  100. package/fault.js.map +1 -0
  101. package/fault.ts +107 -0
  102. package/file.js +87 -0
  103. package/file.js.map +1 -0
  104. package/file.ts +93 -0
  105. package/fixtime.js +67 -0
  106. package/fixtime.js.map +1 -0
  107. package/fixtime.ts +86 -0
  108. package/frames.js +77 -0
  109. package/frames.js.map +1 -0
  110. package/frames.ts +69 -0
  111. package/graph.js +7 -0
  112. package/graph.js.map +1 -0
  113. package/graph.ts +8 -0
  114. package/group.js +444 -0
  115. package/group.js.map +1 -0
  116. package/group.ts +533 -0
  117. package/inspect.js +471 -0
  118. package/inspect.js.map +1 -0
  119. package/inspect.ts +693 -0
  120. package/instrument.js +69 -0
  121. package/instrument.js.map +1 -0
  122. package/instrument.ts +93 -0
  123. package/intake.js +43 -0
  124. package/intake.js.map +1 -0
  125. package/intake.ts +84 -0
  126. package/merge.js +126 -0
  127. package/merge.js.map +1 -0
  128. package/merge.ts +115 -0
  129. package/migrate.ts +36 -0
  130. package/mod.js +8 -0
  131. package/mod.js.map +1 -0
  132. package/mod.ts +19 -0
  133. package/model.js +8 -0
  134. package/model.js.map +1 -0
  135. package/model.ts +27 -0
  136. package/outage.js +129 -0
  137. package/outage.js.map +1 -0
  138. package/outage.ts +158 -0
  139. package/package.json +133 -4
  140. package/page.d.ts +2 -0
  141. package/page.js +905 -0
  142. package/people.js +51 -0
  143. package/people.js.map +1 -0
  144. package/people.ts +82 -0
  145. package/poll.js +277 -0
  146. package/poll.js.map +1 -0
  147. package/poll.ts +411 -0
  148. package/poll_thread.js +104 -0
  149. package/poll_thread.js.map +1 -0
  150. package/poll_thread.ts +126 -0
  151. package/poll_worker.ts +45 -0
  152. package/reading.js +122 -0
  153. package/reading.js.map +1 -0
  154. package/reading.ts +162 -0
  155. package/reconcile.js +113 -0
  156. package/reconcile.js.map +1 -0
  157. package/reconcile.ts +130 -0
  158. package/remote.js +312 -0
  159. package/remote.js.map +1 -0
  160. package/remote.ts +397 -0
  161. package/report.js +825 -0
  162. package/report.js.map +1 -0
  163. package/report.ts +944 -0
  164. package/resolution.js +114 -0
  165. package/resolution.js.map +1 -0
  166. package/resolution.ts +123 -0
  167. package/routes.js +130 -0
  168. package/routes.js.map +1 -0
  169. package/routes.ts +163 -0
  170. package/script.js +13 -0
  171. package/script.js.map +1 -0
  172. package/script.ts +16 -0
  173. package/service.js +174 -0
  174. package/service.js.map +1 -0
  175. package/service.ts +215 -0
  176. package/spread.js +94 -0
  177. package/spread.js.map +1 -0
  178. package/spread.ts +101 -0
  179. package/sync_health.js +36 -0
  180. package/sync_health.js.map +1 -0
  181. package/sync_health.ts +65 -0
  182. package/ticket.js +6 -0
  183. package/ticket.js.map +1 -0
  184. package/ticket.ts +24 -0
  185. package/tools.js +305 -0
  186. package/tools.js.map +1 -0
  187. package/tools.ts +411 -0
  188. package/trace-intake.js +164 -0
  189. package/trace-intake.js.map +1 -0
  190. package/trace-intake.ts +148 -0
  191. package/views.js +247 -0
  192. package/views.js.map +1 -0
  193. package/views.ts +254 -0
  194. package/vocab.js +20 -0
  195. package/vocab.js.map +1 -0
  196. package/vocab.json +834 -0
  197. package/vocab.ts +14 -0
  198. package/yak-tracker@.service +22 -0
package/inspect.ts ADDED
@@ -0,0 +1,693 @@
1
+ /** A bug's page and an error's, as the inspector draws them: what broke, how
2
+ * often and since when, where it ran, and the newest occurrence to read next.
3
+ * Long things are summed up (counts with the few most shared, short commits,
4
+ * a message's headline) and open whole on a press, in the page's graph.
5
+ * Queries belong here; traces are drawn through the registry, never through
6
+ * a timing import.
7
+ * @module
8
+ */
9
+ /* @ts-types="npm:@types/react@19.3.0" */ import {
10
+ createElement as h,
11
+ type JSX,
12
+ type ReactNode,
13
+ useEffect,
14
+ useState,
15
+ } from 'react'
16
+ import { parse, queryAt } from '@yaks/query'
17
+ import {
18
+ all as baseViews,
19
+ type Bundle,
20
+ type Io,
21
+ mention,
22
+ type Props,
23
+ useNamed,
24
+ type View,
25
+ } from '@yaks/inspect'
26
+ import {
27
+ Dot,
28
+ Head,
29
+ Loading,
30
+ Pairs,
31
+ Rows,
32
+ Section,
33
+ Table,
34
+ Timeline,
35
+ Value,
36
+ } from '@yaks/ui'
37
+ import { Disclosure, disclosureAt } from '@yaks/ux'
38
+ import { comp, type Crumb, type Frame, str } from './model.js'
39
+ import { count, figure, headline, place, sha, thrown, whom } from './brief.js'
40
+ import { spread, tags, type Tally } from './spread.js'
41
+ import { Histogram } from './Histogram.js'
42
+ import { fixtime, span } from './fixtime.js'
43
+ import {
44
+ frameAt,
45
+ occurrences,
46
+ pip,
47
+ relatedTraces,
48
+ remoteBug,
49
+ said,
50
+ standing,
51
+ where,
52
+ } from './reading.js'
53
+ import { explained } from './resolution.js'
54
+
55
+ /** How many of a list show before the rest is asked for. */
56
+ let FEW = 3
57
+ /** How many occurrences a bug's page lists before the rest. */
58
+ let ROWS = 8
59
+
60
+ let REFS = ['process', 'entity', 'app', 'space', 'request']
61
+
62
+ /** Content a press opens, its state kept in the page's graph under `at`. */
63
+ let More = (
64
+ { io, at, summary, children }: {
65
+ io: Io
66
+ at: string
67
+ summary: ReactNode
68
+ children?: ReactNode
69
+ },
70
+ ): JSX.Element => {
71
+ let eid = disclosureAt(at)
72
+ return h(Disclosure, {
73
+ e: io.state(eid) ?? { entity: { eid } },
74
+ onChange: (b: Bundle) => io.set([b]),
75
+ summary,
76
+ lazy: true,
77
+ }, children)
78
+ }
79
+
80
+ let at = (io: Io, moment: string) =>
81
+ h('time', { datetime: moment, title: moment }, io.when(moment))
82
+
83
+ // One shared value: a reference named, a commit short, a tag as written.
84
+ let value = (io: Io, name: string, v: string): ReactNode =>
85
+ REFS.includes(name)
86
+ ? mention(io, v)
87
+ : name == 'commit'
88
+ ? h(Value, { mod: 'id', title: v }, sha(v))
89
+ : v
90
+
91
+ let times = (n: number) => h(Value, { mod: 'id' }, ` ×${n}`)
92
+
93
+ /** The few values most occurrences share, and the rest on a press. */
94
+ let Shared = (
95
+ { io, name, tallies, owner }: {
96
+ io: Io
97
+ name: string
98
+ tallies: Tally[]
99
+ owner: string
100
+ },
101
+ ): JSX.Element => {
102
+ let each = (t: Tally, i: number) => [
103
+ i ? ' · ' : '',
104
+ value(io, name, t.value),
105
+ tallies.length > 1 || t.n > 1 ? times(t.n) : null,
106
+ ]
107
+ // Values each seen once say only how many there were; they list on a press.
108
+ let scattered = tallies.length > FEW && tallies.every((t) => t.n == 1)
109
+ let few = scattered ? [] : tallies.slice(0, FEW)
110
+ let rest = tallies.slice(few.length)
111
+ useNamed(io, REFS.includes(name) ? few.map((t) => t.value) : [])
112
+ return h(
113
+ 'span',
114
+ {},
115
+ scattered ? `${tallies.length} different` : few.map(each),
116
+ rest.length
117
+ ? h(
118
+ More,
119
+ {
120
+ io,
121
+ at: `${owner}|${name}`,
122
+ summary: scattered ? 'list them' : `${rest.length} more`,
123
+ },
124
+ h(Named, {
125
+ io,
126
+ eids: REFS.includes(name) ? rest.map((t) => t.value) : [],
127
+ }),
128
+ rest.map(each),
129
+ )
130
+ : null,
131
+ )
132
+ }
133
+
134
+ /** Names the entities a press opened, while they show. */
135
+ let Named = ({ io, eids }: { io: Io; eids: string[] }) => {
136
+ useNamed(io, eids)
137
+ return null
138
+ }
139
+
140
+ /** What a bug's occurrences ran in, a row for each thing they recorded. */
141
+ let Ran = (
142
+ { io, errors, owner }: { io: Io; errors: Bundle[]; owner: string },
143
+ ): JSX.Element =>
144
+ h(
145
+ Pairs,
146
+ {},
147
+ spread(errors).map(({ name, tallies }) => [
148
+ h(Pairs.Key, { key: `${name}-key` }, name),
149
+ h(
150
+ Pairs.Value,
151
+ { key: name },
152
+ h(Shared, { io, name, tallies, owner }),
153
+ ),
154
+ ]),
155
+ first(errors)
156
+ ? [
157
+ h(Pairs.Key, {}, 'first seen in'),
158
+ h(Pairs.Value, {}, value(io, 'commit', first(errors)!)),
159
+ ]
160
+ : null,
161
+ )
162
+
163
+ // The commit the earliest kept occurrence ran: retention keeps the first of
164
+ // each commit, so this is the first commit the bug was seen in.
165
+ let first = (errors: Bundle[]): string | undefined =>
166
+ str(comp(errors.at(-1), 'error').commit) || undefined
167
+
168
+ /** A stack, top first: what ran and where, the project's own frames marked. */
169
+ let Stack = (
170
+ { io, frames, owner }: { io: Io; frames: Frame[]; owner: string },
171
+ ): JSX.Element => {
172
+ let row = (f: Frame, i: number) =>
173
+ h(
174
+ Table.Row,
175
+ { key: i },
176
+ h(
177
+ Table.Cell,
178
+ {},
179
+ f.app ? h(Dot, { mod: 'accent', title: 'in the project' }) : null,
180
+ ),
181
+ h(
182
+ Table.Cell,
183
+ {},
184
+ f.app
185
+ ? f.function || 'anonymous'
186
+ : h(Value, { mod: 'id' }, f.function || 'anonymous'),
187
+ ),
188
+ h(
189
+ Table.Cell,
190
+ { title: f.file },
191
+ h(
192
+ Value,
193
+ { mod: f.app ? undefined : 'id' },
194
+ place(f.file) + [f.line, f.column].filter((n) => n != null)
195
+ .map((n) => `:${n}`).join(''),
196
+ ),
197
+ ),
198
+ )
199
+ let shown = frames.length > 14 ? frames.slice(0, 10) : frames
200
+ let rest = frames.slice(shown.length)
201
+ return h(
202
+ 'div',
203
+ {},
204
+ h(
205
+ Table,
206
+ { cols: ['num', null, null] },
207
+ h(Table.Body, {}, shown.map(row)),
208
+ ),
209
+ rest.length
210
+ ? h(
211
+ More,
212
+ {
213
+ io,
214
+ at: `${owner}|frames`,
215
+ summary: `${rest.length} more frames`,
216
+ },
217
+ h(
218
+ Table,
219
+ { cols: ['num', null, null] },
220
+ h(Table.Body, {}, rest.map((f, i) => row(f, i + shown.length))),
221
+ ),
222
+ )
223
+ : null,
224
+ )
225
+ }
226
+
227
+ let framesOf = (e: Bundle) => (comp(e, 'exception').frames ?? []) as Frame[]
228
+
229
+ /** A message's headline as the title, its thrown type beside it, and the
230
+ * whole message on a press when the headline left some out. */
231
+ let Message = (
232
+ { io, e, sub, facts }: {
233
+ io: Io
234
+ e: Bundle
235
+ sub: ReactNode
236
+ facts: ReactNode[]
237
+ },
238
+ ): JSX.Element => {
239
+ let whole = said(e), { type, message } = thrown(headline(whole))
240
+ return h(
241
+ Head,
242
+ {},
243
+ h(
244
+ Head.Title,
245
+ {},
246
+ message,
247
+ h(Head.Id, {}, io.id(e)),
248
+ type ? h(Head.Kind, {}, type) : null,
249
+ ),
250
+ sub ? h(Head.Sub, {}, sub) : null,
251
+ h(
252
+ Head.Facts,
253
+ {},
254
+ facts.filter(Boolean).map((f, i) => h('span', { key: i }, f)),
255
+ ),
256
+ whole != headline(whole)
257
+ ? h(
258
+ More,
259
+ { io, at: `${e.entity.eid}|message`, summary: 'whole message' },
260
+ h(Value, { mod: 'text' }, whole),
261
+ )
262
+ : null,
263
+ )
264
+ }
265
+
266
+ /** Occurrences as rows, their references named while they show. */
267
+ let Listed = ({ io, rows }: { io: Io; rows: Bundle[] }): JSX.Element => {
268
+ useNamed(
269
+ io,
270
+ rows.flatMap((b) => REFS.map((k) => str(comp(b, 'during')[k]))),
271
+ )
272
+ return h(
273
+ Rows,
274
+ {},
275
+ rows.map((b) =>
276
+ h(Rows.Item, { key: b.entity.eid }, io.show(b, 'Bug.List.Tile'))
277
+ ),
278
+ )
279
+ }
280
+
281
+ /** The occurrences a bug kept, newest first, the rest on a press. */
282
+ let Occurrences = (
283
+ { io, errors, owner }: { io: Io; errors: Bundle[]; owner: string },
284
+ ): JSX.Element => {
285
+ let rest = errors.slice(ROWS)
286
+ return h(
287
+ 'div',
288
+ {},
289
+ h(Listed, { io, rows: errors.slice(0, ROWS) }),
290
+ rest.length
291
+ ? h(
292
+ More,
293
+ { io, at: `${owner}|occurrences`, summary: `${rest.length} more` },
294
+ h(Listed, { io, rows: rest }),
295
+ )
296
+ : null,
297
+ )
298
+ }
299
+
300
+ // A resolution beside the bug it closed: when, how long the bug was open, and
301
+ // how it was fixed, as its resolver explained it.
302
+ let Resolved = ({ io, e }: { io: Io; e: Bundle }): JSX.Element => {
303
+ let lines = explained(e), open = fixtime(e)
304
+ return h(
305
+ Section,
306
+ {},
307
+ h(
308
+ Section.Title,
309
+ {},
310
+ 'Resolved',
311
+ h(Section.Note, {}, at(io, str(comp(e, 'resolved').at))),
312
+ open == undefined ? null : h(Section.Note, {}, `${span(open)} to fix`),
313
+ ),
314
+ lines.length
315
+ ? h(
316
+ Pairs,
317
+ {},
318
+ lines.map(([k, v]) => [
319
+ h(Pairs.Key, { key: `${k}-key` }, k),
320
+ h(Pairs.Value, { key: k }, v),
321
+ ]),
322
+ )
323
+ : h(
324
+ Section.Sub,
325
+ {},
326
+ 'No explanation was recorded: it was resolved before resolutions were explained.',
327
+ ),
328
+ )
329
+ }
330
+
331
+ let BugPage = ({ e, io, got }: Props): JSX.Element => {
332
+ let bug = comp(e, 'bug'), owner = e.entity.eid
333
+ let errors = [...got.errors?.rows ?? []].sort((a, b) =>
334
+ str(comp(b, 'error').at).localeCompare(str(comp(a, 'error').at))
335
+ )
336
+ let newest = errors[0]
337
+ let hits = Number(bug.hits ?? 0)
338
+ let first = Date.parse(
339
+ str(bug.first) || str(comp(errors.at(-1), 'error').at),
340
+ )
341
+ let ats = errors.map((b) => str(comp(b, 'error').at))
342
+ return h(
343
+ 'article',
344
+ { 'data-bug': owner },
345
+ h(Message, {
346
+ io,
347
+ e,
348
+ sub: where(e, newest),
349
+ facts: [
350
+ [h(Dot, { mod: pip(e) }), ' ', standing(e)],
351
+ count(hits, 'hit'),
352
+ bug.people != null || bug.account != null
353
+ ? whom(Number(bug.people ?? 0), str(bug.account))
354
+ : null,
355
+ bug.last ? ['last ', at(io, str(bug.last))] : null,
356
+ bug.first ? ['since ', at(io, str(bug.first))] : null,
357
+ ],
358
+ }),
359
+ e.resolved ? h(Resolved, { io, e }) : null,
360
+ h(
361
+ Section,
362
+ {},
363
+ h(
364
+ Section.Title,
365
+ {},
366
+ 'When',
367
+ h(
368
+ Section.Count,
369
+ {},
370
+ errors.length < hits
371
+ ? `${errors.length} kept of ${figure(hits)}`
372
+ : count(errors.length, 'occurrence'),
373
+ ),
374
+ ),
375
+ errors.length && Number.isFinite(first)
376
+ ? h(Histogram, { ats, from: first, to: Date.now() })
377
+ : null,
378
+ errors.length < hits
379
+ ? h(
380
+ Section.Sub,
381
+ {},
382
+ 'The tracker keeps the newest hundred occurrences and the first of each commit; the hits count all of them.',
383
+ )
384
+ : null,
385
+ ),
386
+ errors.length
387
+ ? h(
388
+ Section,
389
+ {},
390
+ h(Section.Title, {}, 'Where it ran'),
391
+ h(Ran, { io, errors, owner }),
392
+ )
393
+ : null,
394
+ newest
395
+ ? h(
396
+ Section,
397
+ {},
398
+ h(
399
+ Section.Title,
400
+ {},
401
+ 'Newest occurrence',
402
+ h(Section.Note, {}, at(io, str(comp(newest, 'error').at))),
403
+ h(
404
+ Section.Note,
405
+ {},
406
+ h('a', { href: io.link(newest.entity.eid) }, io.id(newest)),
407
+ ),
408
+ ),
409
+ headline(said(newest)) != headline(said(e))
410
+ ? h(Section.Sub, {}, headline(said(newest)))
411
+ : null,
412
+ framesOf(newest).length
413
+ ? h(Stack, { io, frames: framesOf(newest), owner: newest.entity.eid })
414
+ : h(Section.Sub, {}, 'No stack was recorded.'),
415
+ )
416
+ : null,
417
+ h(
418
+ Section,
419
+ {},
420
+ h(
421
+ Section.Title,
422
+ {},
423
+ 'Occurrences',
424
+ h(Section.Count, {}, errors.length),
425
+ ),
426
+ !got.errors?.ready && !errors.length
427
+ ? h(Loading, {})
428
+ : errors.length
429
+ ? h(Occurrences, { io, errors, owner })
430
+ : h(Section.Sub, {}, 'No occurrence is kept.'),
431
+ ),
432
+ bug.fault
433
+ ? h(
434
+ More,
435
+ { io, at: `${owner}|fault`, summary: 'Grouping key' },
436
+ h(Value, { mod: 'id' }, str(bug.fault)),
437
+ )
438
+ : null,
439
+ )
440
+ }
441
+
442
+ let Traces = (
443
+ { io, related, got }: {
444
+ io: Io
445
+ related: { label: string }
446
+ got: Props['got']
447
+ },
448
+ ): JSX.Element =>
449
+ h(
450
+ Section,
451
+ {},
452
+ h(Section.Title, {}, 'Traces', h(Section.Note, {}, related.label)),
453
+ got.traces?.error
454
+ ? h(
455
+ Section.Sub,
456
+ { role: 'alert' },
457
+ `Traces unavailable: ${got.traces.error}`,
458
+ )
459
+ : !got.traces?.ready && !got.traces?.rows.length
460
+ ? h(Loading, {})
461
+ : got.traces.rows.length
462
+ ? h('div', {}, got.traces.rows.map((b) => io.show(b, 'List.Tile')))
463
+ : h(Section.Sub, {}, 'No recorded trace matches this occurrence.'),
464
+ )
465
+
466
+ // The bug an occurrence belongs to, by its id: its message is already the
467
+ // page's title.
468
+ let bugOf = (io: Io, eid: string): ReactNode => {
469
+ let b = io.get(eid)
470
+ return b
471
+ ? h('a', { href: io.link(eid), title: said(b) }, io.id(b))
472
+ : mention(io, eid)
473
+ }
474
+
475
+ let ErrorPage = ({ e, io, got }: Props): JSX.Element => {
476
+ let error = comp(e, 'error'), d = comp(e, 'during'), owner = e.entity.eid
477
+ let related = io.vocab.all.includes('trace') ? relatedTraces(e) : undefined
478
+ let frames = framesOf(e)
479
+ let crumbs = (comp(e, 'breadcrumbs').items ?? []) as Crumb[]
480
+ let top = frames.find((f) => f.app) ?? frames[0]
481
+ useNamed(io, [...REFS.map((k) => str(d[k])), str(error.bug)])
482
+ let context = [
483
+ ...tags(e).map(([k, v]) => [k, v] as [string, ReactNode]),
484
+ ...REFS.filter((k) => d[k]).map((k) =>
485
+ [k, mention(io, str(d[k]))] as [string, ReactNode]
486
+ ),
487
+ ...d.kind ? [['kind', str(d.kind)] as [string, ReactNode]] : [],
488
+ ...comp(e, 'exception').mechanism
489
+ ? [
490
+ ['caught by', str(comp(e, 'exception').mechanism)] as [
491
+ string,
492
+ ReactNode,
493
+ ],
494
+ ]
495
+ : [],
496
+ ]
497
+ return h(
498
+ 'article',
499
+ { 'data-error': owner },
500
+ h(Message, {
501
+ io,
502
+ e,
503
+ sub: error.bug ? ['one occurrence of ', bugOf(io, str(error.bug))] : null,
504
+ facts: [
505
+ error.at ? at(io, str(error.at)) : null,
506
+ str(error.level),
507
+ str(error.environment),
508
+ error.commit
509
+ ? h(
510
+ Value,
511
+ { mod: 'id', title: str(error.commit) },
512
+ sha(str(error.commit)),
513
+ )
514
+ : null,
515
+ error.version != null ? `version ${error.version}` : null,
516
+ ],
517
+ }),
518
+ h(
519
+ Section,
520
+ {},
521
+ h(Section.Title, {}, 'Where'),
522
+ h(
523
+ Pairs,
524
+ {},
525
+ top ? [h(Pairs.Key, {}, 'at'), h(Pairs.Value, {}, frameAt(top))] : null,
526
+ context.map(([k, v]) => [
527
+ h(Pairs.Key, { key: `${k}-key` }, k),
528
+ h(Pairs.Value, { key: k }, v),
529
+ ]),
530
+ ),
531
+ ),
532
+ h(
533
+ Section,
534
+ {},
535
+ h(Section.Title, {}, 'Stack', h(Section.Count, {}, frames.length)),
536
+ frames.length
537
+ ? h(Stack, { io, frames, owner })
538
+ : h(Section.Sub, {}, 'No stack was recorded.'),
539
+ comp(e, 'exception').stack
540
+ ? h(
541
+ More,
542
+ { io, at: `${owner}|stack`, summary: 'Stack as thrown' },
543
+ h('pre', {}, h('code', {}, str(comp(e, 'exception').stack))),
544
+ )
545
+ : null,
546
+ ),
547
+ crumbs.length
548
+ ? h(
549
+ Section,
550
+ {},
551
+ h(Section.Title, {}, 'Before it', h(Section.Count, {}, crumbs.length)),
552
+ h(
553
+ Timeline,
554
+ {},
555
+ crumbs.map((c, i) =>
556
+ h(
557
+ Timeline.Item,
558
+ { key: i },
559
+ h(Timeline.When, {}, at(io, c.at)),
560
+ h(Timeline.Who, {}, c.category),
561
+ h(Timeline.What, {}, headline(c.message)),
562
+ )
563
+ ),
564
+ ),
565
+ )
566
+ : null,
567
+ related ? h(Traces, { io, related, got }) : null,
568
+ )
569
+ }
570
+
571
+ /** What the box's tracker doors (./routes.ts) answered for one bug: the bug,
572
+ * its newest kept occurrences and their requests. */
573
+ type Read = { bug: string; rows?: Bundle[]; error?: string }
574
+
575
+ /** A bug on another side (the platform tracker), read through the box's
576
+ * tracker doors and drawn with these same pages. Only its read and link doors
577
+ * change; nothing is admitted to the box's or the page's graph. Its numbers
578
+ * belong to the other store, so its rows read by eid. */
579
+ let RemoteBug = (
580
+ { io, side, scope, bug, error }: {
581
+ io: Io
582
+ side: string
583
+ scope?: string
584
+ bug: string
585
+ error?: string
586
+ },
587
+ ): JSX.Element => {
588
+ let [read, set] = useState<Read>()
589
+ useEffect(() => {
590
+ let abort = new AbortController()
591
+ let ask = new URLSearchParams({ bug, ...scope ? { scope } : {} })
592
+ void fetch(`/tracker/bugs?${ask}`, {
593
+ signal: abort.signal,
594
+ }).then(async (r) => {
595
+ let body = await r.json()
596
+ if (!r.ok) throw Error(body.error ?? `the tracker answered ${r.status}`)
597
+ if (!abort.signal.aborted) set({ bug, rows: body.rows })
598
+ }).catch((e) => {
599
+ if (!abort.signal.aborted) set({ bug, error: String(e?.message ?? e) })
600
+ })
601
+ return () => abort.abort()
602
+ }, [bug, scope])
603
+ let held = read?.bug == bug ? read : undefined
604
+ if (held?.error) {
605
+ return h(Section.Sub, { role: 'alert' }, `Bug unavailable: ${held.error}`)
606
+ }
607
+ let rows = held?.rows ?? [], [e] = rows
608
+ if (!e) {
609
+ return h(Loading, {}, `Loading the bug from ${side}…`)
610
+ }
611
+ let errors = rows.filter((b) => b.error)
612
+ // An occurrence opens on this page; the bug and the requests read with it
613
+ // are on it already.
614
+ let link = (eid: string) =>
615
+ errors.some((b) => b.entity.eid == eid)
616
+ ? remoteBug(side, bug, { scope, error: eid })
617
+ : rows.some((b) => b.entity.eid == eid)
618
+ ? remoteBug(side, bug, { scope })
619
+ : io.link(eid)
620
+ let id = (b: Bundle) => io.id({ ...b, entity: { eid: b.entity.eid } })
621
+ let there: Io = {
622
+ ...io,
623
+ get: (eid) => rows.find((b) => b.entity.eid == eid) ?? io.get(eid),
624
+ link,
625
+ id,
626
+ show: (b, view, ctx) =>
627
+ io.show({ ...b, entity: { eid: b.entity.eid } }, view, {
628
+ ...ctx,
629
+ link,
630
+ id,
631
+ }),
632
+ }
633
+ let picked = error ? errors.find((b) => b.entity.eid == error) : undefined
634
+ return picked
635
+ ? h(ErrorPage, {
636
+ e: picked,
637
+ io: there,
638
+ ctx: {},
639
+ got: {
640
+ traces: {
641
+ rows: [],
642
+ ready: false,
643
+ error: `not read across from ${side}`,
644
+ },
645
+ },
646
+ })
647
+ : h(BugPage, {
648
+ e,
649
+ io: there,
650
+ ctx: {},
651
+ got: { errors: { rows: errors, ready: true } },
652
+ })
653
+ }
654
+
655
+ /** The pages this package draws in the inspector. */
656
+ export let inspectViews: View[] = [
657
+ {
658
+ view: 'Full',
659
+ match: parse('.bug'),
660
+ asks: (e) => ({ errors: occurrences(e.entity.eid) }),
661
+ Render: BugPage,
662
+ },
663
+ {
664
+ view: 'Full',
665
+ match: parse('.error'),
666
+ asks: (e, io): Record<string, string> => {
667
+ let related = io.vocab.all.includes('trace') && relatedTraces(e)
668
+ return related ? { traces: related.query } : {}
669
+ },
670
+ Render: ErrorPage,
671
+ },
672
+ {
673
+ // A bug query's page, where a letter about a bug on another side opens it
674
+ // (`?.bug&side=yaks.app&bug=…`, with `&scope=…` for a space's tracker). Its second clause outranks timing's
675
+ // query page, which draws no bug query differently.
676
+ view: 'Inspect.Query',
677
+ match: parse(".entity.eid~='browse-query:' .entity.eid~='.bug'"),
678
+ Render: (props) => {
679
+ let params =
680
+ queryAt(typeof location == 'undefined' ? '' : location.search).state
681
+ let side = params.get('side') ?? 'box', bug = params.get('bug')
682
+ return side != 'box' && bug
683
+ ? h(RemoteBug, {
684
+ io: props.io,
685
+ side,
686
+ scope: params.get('scope') ?? undefined,
687
+ bug,
688
+ error: params.get('error') ?? undefined,
689
+ })
690
+ : h(baseViews.find((v) => v.view == 'Inspect.Query')!.Render, props)
691
+ },
692
+ },
693
+ ]