@yaks/session 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 (393) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +1392 -2
  3. package/_dist/admission.d.ts +15 -0
  4. package/_dist/admission.d.ts.map +1 -0
  5. package/_dist/announce.d.ts +17 -0
  6. package/_dist/announce.d.ts.map +1 -0
  7. package/_dist/answer.d.ts +200 -0
  8. package/_dist/answer.d.ts.map +1 -0
  9. package/_dist/append.d.ts +10 -0
  10. package/_dist/append.d.ts.map +1 -0
  11. package/_dist/archive.d.ts +6 -0
  12. package/_dist/archive.d.ts.map +1 -0
  13. package/_dist/asks.d.ts +11 -0
  14. package/_dist/asks.d.ts.map +1 -0
  15. package/_dist/audit.d.ts +15 -0
  16. package/_dist/audit.d.ts.map +1 -0
  17. package/_dist/bounce.d.ts +19 -0
  18. package/_dist/bounce.d.ts.map +1 -0
  19. package/_dist/bus.d.ts +8 -0
  20. package/_dist/bus.d.ts.map +1 -0
  21. package/_dist/cache.d.ts +45 -0
  22. package/_dist/cache.d.ts.map +1 -0
  23. package/_dist/child-notice.d.ts +6 -0
  24. package/_dist/child-notice.d.ts.map +1 -0
  25. package/_dist/children.d.ts +59 -0
  26. package/_dist/children.d.ts.map +1 -0
  27. package/_dist/cli.d.ts +8 -0
  28. package/_dist/cli.d.ts.map +1 -0
  29. package/_dist/comp.d.ts +9 -0
  30. package/_dist/comp.d.ts.map +1 -0
  31. package/_dist/compact.d.ts +19 -0
  32. package/_dist/compact.d.ts.map +1 -0
  33. package/_dist/conversation.d.ts +158 -0
  34. package/_dist/conversation.d.ts.map +1 -0
  35. package/_dist/cost.d.ts +13 -0
  36. package/_dist/cost.d.ts.map +1 -0
  37. package/_dist/deferred.d.ts +79 -0
  38. package/_dist/deferred.d.ts.map +1 -0
  39. package/_dist/ended.d.ts +27 -0
  40. package/_dist/ended.d.ts.map +1 -0
  41. package/_dist/files.d.ts +73 -0
  42. package/_dist/files.d.ts.map +1 -0
  43. package/_dist/fork.d.ts +23 -0
  44. package/_dist/fork.d.ts.map +1 -0
  45. package/_dist/graft.d.ts +33 -0
  46. package/_dist/graft.d.ts.map +1 -0
  47. package/_dist/graph.d.ts +14 -0
  48. package/_dist/graph.d.ts.map +1 -0
  49. package/_dist/handoff.d.ts +29 -0
  50. package/_dist/handoff.d.ts.map +1 -0
  51. package/_dist/imported.d.ts +63 -0
  52. package/_dist/imported.d.ts.map +1 -0
  53. package/_dist/intake.d.ts +43 -0
  54. package/_dist/intake.d.ts.map +1 -0
  55. package/_dist/joined.d.ts +35 -0
  56. package/_dist/joined.d.ts.map +1 -0
  57. package/_dist/lease.d.ts +21 -0
  58. package/_dist/lease.d.ts.map +1 -0
  59. package/_dist/lines.d.ts +13 -0
  60. package/_dist/lines.d.ts.map +1 -0
  61. package/_dist/mod.d.ts +107 -0
  62. package/_dist/mod.d.ts.map +1 -0
  63. package/_dist/naming.d.ts +10 -0
  64. package/_dist/naming.d.ts.map +1 -0
  65. package/_dist/native.d.ts +13 -0
  66. package/_dist/native.d.ts.map +1 -0
  67. package/_dist/parts.d.ts +145 -0
  68. package/_dist/parts.d.ts.map +1 -0
  69. package/_dist/plugin.d.ts +33 -0
  70. package/_dist/plugin.d.ts.map +1 -0
  71. package/_dist/project.d.ts +67 -0
  72. package/_dist/project.d.ts.map +1 -0
  73. package/_dist/prose.d.ts +7 -0
  74. package/_dist/prose.d.ts.map +1 -0
  75. package/_dist/providers.d.ts +36 -0
  76. package/_dist/providers.d.ts.map +1 -0
  77. package/_dist/reach.d.ts +39 -0
  78. package/_dist/reach.d.ts.map +1 -0
  79. package/_dist/react.d.ts +236 -0
  80. package/_dist/react.d.ts.map +1 -0
  81. package/_dist/readers.d.ts +221 -0
  82. package/_dist/readers.d.ts.map +1 -0
  83. package/_dist/reap.d.ts +21 -0
  84. package/_dist/reap.d.ts.map +1 -0
  85. package/_dist/recall.d.ts +32 -0
  86. package/_dist/recall.d.ts.map +1 -0
  87. package/_dist/routes.d.ts +15 -0
  88. package/_dist/routes.d.ts.map +1 -0
  89. package/_dist/run.d.ts +81 -0
  90. package/_dist/run.d.ts.map +1 -0
  91. package/_dist/service.d.ts +131 -0
  92. package/_dist/service.d.ts.map +1 -0
  93. package/_dist/source.d.ts +9 -0
  94. package/_dist/source.d.ts.map +1 -0
  95. package/_dist/start.d.ts +29 -0
  96. package/_dist/start.d.ts.map +1 -0
  97. package/_dist/state.d.ts +75 -0
  98. package/_dist/state.d.ts.map +1 -0
  99. package/_dist/status.d.ts +38 -0
  100. package/_dist/status.d.ts.map +1 -0
  101. package/_dist/tail.d.ts +121 -0
  102. package/_dist/tail.d.ts.map +1 -0
  103. package/_dist/timing.d.ts +9 -0
  104. package/_dist/timing.d.ts.map +1 -0
  105. package/_dist/told.d.ts +17 -0
  106. package/_dist/told.d.ts.map +1 -0
  107. package/_dist/tools.d.ts +41 -0
  108. package/_dist/tools.d.ts.map +1 -0
  109. package/_dist/transcript.d.ts +5 -0
  110. package/_dist/transcript.d.ts.map +1 -0
  111. package/_dist/turn.d.ts +49 -0
  112. package/_dist/turn.d.ts.map +1 -0
  113. package/_dist/unknown.d.ts +6 -0
  114. package/_dist/unknown.d.ts.map +1 -0
  115. package/_dist/views.d.ts +9 -0
  116. package/_dist/views.d.ts.map +1 -0
  117. package/_dist/vocab.d.ts +9 -0
  118. package/_dist/vocab.d.ts.map +1 -0
  119. package/_dist/wait.d.ts +15 -0
  120. package/_dist/wait.d.ts.map +1 -0
  121. package/_dist/wake.d.ts +116 -0
  122. package/_dist/wake.d.ts.map +1 -0
  123. package/_dist/watch.d.ts +52 -0
  124. package/_dist/watch.d.ts.map +1 -0
  125. package/_dist/who.d.ts +84 -0
  126. package/_dist/who.d.ts.map +1 -0
  127. package/_dist/window.d.ts +43 -0
  128. package/_dist/window.d.ts.map +1 -0
  129. package/admission.js +137 -0
  130. package/admission.js.map +1 -0
  131. package/admission.ts +164 -0
  132. package/announce.js +123 -0
  133. package/announce.js.map +1 -0
  134. package/announce.ts +126 -0
  135. package/answer.js +372 -0
  136. package/answer.js.map +1 -0
  137. package/answer.ts +426 -0
  138. package/append.js +125 -0
  139. package/append.js.map +1 -0
  140. package/append.ts +205 -0
  141. package/archive.js +62 -0
  142. package/archive.js.map +1 -0
  143. package/archive.ts +62 -0
  144. package/asks.js +80 -0
  145. package/asks.js.map +1 -0
  146. package/asks.ts +106 -0
  147. package/attempt.js +46 -0
  148. package/attempt.js.map +1 -0
  149. package/attempt.ts +60 -0
  150. package/audit.js +57 -0
  151. package/audit.js.map +1 -0
  152. package/audit.ts +65 -0
  153. package/bounce.js +29 -0
  154. package/bounce.js.map +1 -0
  155. package/bounce.ts +34 -0
  156. package/bus.js +568 -0
  157. package/bus.js.map +1 -0
  158. package/bus.ts +683 -0
  159. package/cache.js +169 -0
  160. package/cache.js.map +1 -0
  161. package/cache.ts +230 -0
  162. package/child-notice.js +128 -0
  163. package/child-notice.js.map +1 -0
  164. package/child-notice.ts +136 -0
  165. package/children.js +937 -0
  166. package/children.js.map +1 -0
  167. package/children.ts +925 -0
  168. package/claude-control.js +8 -0
  169. package/claude-control.js.map +1 -0
  170. package/claude-control.ts +12 -0
  171. package/cli.js +23 -0
  172. package/cli.js.map +1 -0
  173. package/cli.ts +28 -0
  174. package/comp.js +76 -0
  175. package/comp.js.map +1 -0
  176. package/comp.ts +78 -0
  177. package/compact.js +157 -0
  178. package/compact.js.map +1 -0
  179. package/compact.ts +209 -0
  180. package/compact_ask.js +280 -0
  181. package/compact_ask.js.map +1 -0
  182. package/compact_ask.ts +199 -0
  183. package/continue.js +131 -0
  184. package/continue.js.map +1 -0
  185. package/continue.ts +143 -0
  186. package/conversation.js +337 -0
  187. package/conversation.js.map +1 -0
  188. package/conversation.ts +593 -0
  189. package/cost.js +111 -0
  190. package/cost.js.map +1 -0
  191. package/cost.ts +93 -0
  192. package/deferred.js +207 -0
  193. package/deferred.js.map +1 -0
  194. package/deferred.ts +219 -0
  195. package/deno.json +1 -0
  196. package/dependencies.js +114 -0
  197. package/dependencies.js.map +1 -0
  198. package/dependencies.ts +110 -0
  199. package/draining.js +20 -0
  200. package/draining.js.map +1 -0
  201. package/draining.ts +26 -0
  202. package/ended.js +210 -0
  203. package/ended.js.map +1 -0
  204. package/ended.ts +225 -0
  205. package/files.js +285 -0
  206. package/files.js.map +1 -0
  207. package/files.ts +318 -0
  208. package/fork.js +96 -0
  209. package/fork.js.map +1 -0
  210. package/fork.ts +124 -0
  211. package/graft.js +97 -0
  212. package/graft.js.map +1 -0
  213. package/graft.ts +88 -0
  214. package/graph.js +49 -0
  215. package/graph.js.map +1 -0
  216. package/graph.ts +61 -0
  217. package/handoff.js +111 -0
  218. package/handoff.js.map +1 -0
  219. package/handoff.ts +147 -0
  220. package/help.js +432 -0
  221. package/help.js.map +1 -0
  222. package/help.ts +431 -0
  223. package/hooks.js +253 -0
  224. package/hooks.js.map +1 -0
  225. package/hooks.ts +333 -0
  226. package/imported.js +259 -0
  227. package/imported.js.map +1 -0
  228. package/imported.ts +201 -0
  229. package/inspect.js +353 -0
  230. package/inspect.js.map +1 -0
  231. package/inspect.ts +378 -0
  232. package/intake.js +115 -0
  233. package/intake.js.map +1 -0
  234. package/intake.ts +124 -0
  235. package/joined.js +67 -0
  236. package/joined.js.map +1 -0
  237. package/joined.ts +69 -0
  238. package/lease.js +146 -0
  239. package/lease.js.map +1 -0
  240. package/lease.ts +151 -0
  241. package/lifecycle.js +49 -0
  242. package/lifecycle.js.map +1 -0
  243. package/lifecycle.ts +46 -0
  244. package/lines.js +171 -0
  245. package/lines.js.map +1 -0
  246. package/lines.ts +177 -0
  247. package/listen.js +604 -0
  248. package/listen.js.map +1 -0
  249. package/listen.ts +976 -0
  250. package/log.js +78 -0
  251. package/log.js.map +1 -0
  252. package/log.ts +88 -0
  253. package/mod.js +107 -0
  254. package/mod.js.map +1 -0
  255. package/mod.ts +113 -0
  256. package/name.js +51 -0
  257. package/name.js.map +1 -0
  258. package/name.ts +84 -0
  259. package/naming.js +96 -0
  260. package/naming.js.map +1 -0
  261. package/naming.ts +102 -0
  262. package/native.js +17 -0
  263. package/native.js.map +1 -0
  264. package/native.ts +17 -0
  265. package/package.json +133 -4
  266. package/parts.js +334 -0
  267. package/parts.js.map +1 -0
  268. package/parts.ts +383 -0
  269. package/plugin.js +77 -0
  270. package/plugin.js.map +1 -0
  271. package/plugin.ts +98 -0
  272. package/project.js +354 -0
  273. package/project.js.map +1 -0
  274. package/project.ts +407 -0
  275. package/prompt.js +57 -0
  276. package/prompt.js.map +1 -0
  277. package/prompt.ts +92 -0
  278. package/prose.js +43 -0
  279. package/prose.js.map +1 -0
  280. package/prose.ts +63 -0
  281. package/providers.js +279 -0
  282. package/providers.js.map +1 -0
  283. package/providers.ts +306 -0
  284. package/pruning.js +80 -0
  285. package/pruning.js.map +1 -0
  286. package/pruning.ts +147 -0
  287. package/reach.js +923 -0
  288. package/reach.js.map +1 -0
  289. package/reach.ts +1107 -0
  290. package/react.js +2259 -0
  291. package/react.js.map +1 -0
  292. package/react.ts +2864 -0
  293. package/readers.js +956 -0
  294. package/readers.js.map +1 -0
  295. package/readers.ts +1017 -0
  296. package/reap.js +60 -0
  297. package/reap.js.map +1 -0
  298. package/reap.ts +65 -0
  299. package/recall.js +67 -0
  300. package/recall.js.map +1 -0
  301. package/recall.ts +114 -0
  302. package/reopen.js +45 -0
  303. package/reopen.js.map +1 -0
  304. package/reopen.ts +44 -0
  305. package/result-entry.js +32 -0
  306. package/result-entry.js.map +1 -0
  307. package/result-entry.ts +34 -0
  308. package/resume.js +266 -0
  309. package/resume.js.map +1 -0
  310. package/resume.ts +283 -0
  311. package/routes.js +129 -0
  312. package/routes.js.map +1 -0
  313. package/routes.ts +147 -0
  314. package/routine.js +179 -0
  315. package/routine.js.map +1 -0
  316. package/routine.ts +191 -0
  317. package/run.js +932 -0
  318. package/run.js.map +1 -0
  319. package/run.ts +999 -0
  320. package/service.js +806 -0
  321. package/service.js.map +1 -0
  322. package/service.ts +911 -0
  323. package/source.js +26 -0
  324. package/source.js.map +1 -0
  325. package/source.ts +40 -0
  326. package/start.js +197 -0
  327. package/start.js.map +1 -0
  328. package/start.ts +214 -0
  329. package/state.js +247 -0
  330. package/state.js.map +1 -0
  331. package/state.ts +404 -0
  332. package/status.js +1222 -0
  333. package/status.js.map +1 -0
  334. package/status.ts +1555 -0
  335. package/status_bench.ts +50 -0
  336. package/statusline.js +187 -0
  337. package/statusline.js.map +1 -0
  338. package/statusline.ts +232 -0
  339. package/tail.js +748 -0
  340. package/tail.js.map +1 -0
  341. package/tail.ts +815 -0
  342. package/talk.js +58 -0
  343. package/talk.js.map +1 -0
  344. package/talk.ts +51 -0
  345. package/task-context.js +41 -0
  346. package/task-context.js.map +1 -0
  347. package/task-context.ts +53 -0
  348. package/texted.js +65 -0
  349. package/texted.js.map +1 -0
  350. package/texted.ts +65 -0
  351. package/timing.js +37 -0
  352. package/timing.js.map +1 -0
  353. package/timing.ts +52 -0
  354. package/told.js +56 -0
  355. package/told.js.map +1 -0
  356. package/told.ts +54 -0
  357. package/tools.js +595 -0
  358. package/tools.js.map +1 -0
  359. package/tools.ts +633 -0
  360. package/transcript.js +34 -0
  361. package/transcript.js.map +1 -0
  362. package/transcript.ts +41 -0
  363. package/turn.js +47 -0
  364. package/turn.js.map +1 -0
  365. package/turn.ts +68 -0
  366. package/unknown.js +8 -0
  367. package/unknown.js.map +1 -0
  368. package/unknown.ts +9 -0
  369. package/views.js +15 -0
  370. package/views.js.map +1 -0
  371. package/views.ts +21 -0
  372. package/vocab.js +24 -0
  373. package/vocab.js.map +1 -0
  374. package/vocab.json +1573 -0
  375. package/vocab.ts +30 -0
  376. package/wait.js +30 -0
  377. package/wait.js.map +1 -0
  378. package/wait.ts +45 -0
  379. package/wake.js +552 -0
  380. package/wake.js.map +1 -0
  381. package/wake.ts +597 -0
  382. package/watch.js +520 -0
  383. package/watch.js.map +1 -0
  384. package/watch.ts +596 -0
  385. package/who.js +309 -0
  386. package/who.js.map +1 -0
  387. package/who.ts +347 -0
  388. package/window.js +179 -0
  389. package/window.js.map +1 -0
  390. package/window.ts +268 -0
  391. package/woken.js +129 -0
  392. package/woken.js.map +1 -0
  393. package/woken.ts +127 -0
package/inspect.ts ADDED
@@ -0,0 +1,378 @@
1
+ /**
2
+ * How a transcript reads in the inspector (@yaks/inspect), registered in this
3
+ * package's `/views` facet ahead of the page any entity has.
4
+ *
5
+ * - `Inspect.Turn`, for an entry: one turn of the conversation, said by who
6
+ * said it: a person's words by the person, a model's by `agent`, a tool
7
+ * called or its answer quiet, by what was called.
8
+ * - `Inspect.Conversation`, for an entry: the turns either side of it in its
9
+ * transcript, it lit among them, each a link to its own page. What any page
10
+ * showing words said in a conversation asks for (a belief citing them).
11
+ * - `Inspect.Page`, for an entry: the entry inside its conversation.
12
+ * - `Inspect.Page`, for a session: what it is running (its status, model and
13
+ * worktree), its brief, and its latest turns.
14
+ *
15
+ * Every part it has no better way to say is the inspector's (`io.show`).
16
+ *
17
+ * @module
18
+ */
19
+
20
+ /* @ts-types="npm:@types/react@19.3.0" */ import { createElement as h, type JSX, type ReactNode } from 'react'
21
+ import { parse } from '@yaks/query'
22
+ import * as ui from '@yaks/ui'
23
+ import { Markdown } from '@yaks/markdown'
24
+ import {
25
+ type Answer,
26
+ type Bundle,
27
+ type Io,
28
+ mention,
29
+ Part,
30
+ type Props,
31
+ useNamed,
32
+ usePageNotes,
33
+ type View,
34
+ } from '@yaks/inspect'
35
+ import { SESSION } from './comp.js'
36
+ import { CALL, ENTRY, OUTPUT, RESULT } from './native.js'
37
+ import { kindOf, textOf } from './state.js'
38
+ import { asks, type Read, sessionName } from './name.js'
39
+
40
+ /** Where an entry sits: its transcript, and its place in it. */
41
+ export type At = { session: string; seq: number }
42
+
43
+ /**
44
+ * The query that reads the entries beside one in its transcript, the way
45
+ * `grep -C` reads around a line: `n` of them ahead of it (`before`, nearest
46
+ * first) or behind it (`after`, in order), every component of each. A
47
+ * transcript is ordered by `entry.seq`, which may skip numbers, so entries are
48
+ * asked for by position, never by a range of numbers.
49
+ *
50
+ * ```ts
51
+ * import { beside } from './inspect.ts'
52
+ * beside({ session: 's1', seq: 12 }, 'before', 3)
53
+ * // '.entry.session=s1&.entry.seq<12&*&.order=-entry.seq&.limit=3'
54
+ * ```
55
+ */
56
+ export let beside = (at: At, way: 'before' | 'after', n: number): string =>
57
+ `.${ENTRY}.session=${at.session}&.${ENTRY}.seq${
58
+ way == 'before' ? '<' : '>'
59
+ }` +
60
+ `${at.seq}&*&.order=${way == 'before' ? '-' : ''}${ENTRY}.seq&.limit=${n}`
61
+
62
+ /** How much of a turn that is not lit reads before it is cut. */
63
+ export let TURN = 320
64
+
65
+ /** How many turns either side of an entry its page shows. */
66
+ export let AROUND = 8
67
+
68
+ /** How many of a session's latest turns its page shows. */
69
+ export let LATEST = 12
70
+
71
+ type Comp = Record<string, unknown>
72
+ let comp = (b: Bundle | undefined, name: string): Comp =>
73
+ (b?.[name] ?? {}) as Comp
74
+ let str = (b: Bundle | undefined, name: string, prop: string): string => {
75
+ let v = comp(b, name)[prop]
76
+ return typeof v == 'string' ? v : ''
77
+ }
78
+ let rows = (a?: Answer): Bundle[] => a?.rows ?? []
79
+ let cut = (text: string, n: number) =>
80
+ text.length > n ? text.slice(0, n - 1).trimEnd() + '…' : text
81
+
82
+ // Where an entry sits, if it is one.
83
+ let placed = (b: Bundle): At | undefined => {
84
+ let session = str(b, ENTRY, 'session')
85
+ let seq = comp(b, ENTRY).seq
86
+ return session && typeof seq == 'number' ? { session, seq } : undefined
87
+ }
88
+
89
+ // What a tool was called with, in a line: what the caller said it was for,
90
+ // else its arguments.
91
+ let called = (b: Bundle): string => {
92
+ let args = comp(b, CALL).args as Comp | undefined
93
+ let why = typeof args?.description == 'string' ? args.description : ''
94
+ return cut(why || JSON.stringify(args ?? {}), 160)
95
+ }
96
+
97
+ /** What a turn is drawn with: whether it is the one the page is about, and
98
+ * whether it is said whole (by default, the one it is about). */
99
+ export type TurnCtx = { on?: boolean; whole?: boolean }
100
+
101
+ /** An entry as one turn of its conversation: who said it, linked to the
102
+ * turn's own page, and what. */
103
+ export let EntryTurn = ({ e, io, ctx }: Props): JSX.Element => {
104
+ let { on, whole = on } = ctx as TurnCtx
105
+ let kind = kindOf(e)
106
+ let said = textOf(e)
107
+ let by = str(e, 'created', 'by')
108
+ let to = str(e, CALL, 'to')
109
+ useNamed(io, [kind == 'input' ? by : '', to])
110
+ let who = kind == 'input' && by
111
+ ? mention(io, by)
112
+ : OUTPUT in e || CALL in e || RESULT in e
113
+ ? 'agent'
114
+ : kind ?? io.kind(e)
115
+ let text: ReactNode = CALL in e
116
+ ? ['called ', to ? mention(io, to) : 'a tool', ': ', called(e)]
117
+ : RESULT in e
118
+ ? ['answered: ', cut(said.trim() || '…', 160)]
119
+ : said
120
+ ? h(Markdown, { source: whole ? said : cut(said, TURN) })
121
+ : kind ?? io.kind(e)
122
+ return h(
123
+ ui.Turns.Turn,
124
+ {
125
+ mod: on ? 'on' : (!said || CALL in e || RESULT in e) && 'quiet',
126
+ 'data-turn': e.entity.eid,
127
+ },
128
+ h(ui.Turns.Who, { href: on ? undefined : io.link(e.entity.eid) }, who),
129
+ h(ui.Turns.Text, {}, text),
130
+ )
131
+ }
132
+
133
+ /** What a conversation around an entry is drawn with: how many turns either
134
+ * side, and whether the entry is said whole. */
135
+ export type ConversationCtx = {
136
+ before?: number
137
+ after?: number
138
+ whole?: boolean
139
+ }
140
+
141
+ /** The turns either side of an entry in its transcript, it lit among them. */
142
+ export let Conversation = ({ e, io, ctx }: Props): JSX.Element | null => {
143
+ let { before = AROUND, after = AROUND, whole = true } = ctx as ConversationCtx
144
+ let at = placed(e)
145
+ let got = io.ask(
146
+ at
147
+ ? {
148
+ before: beside(at, 'before', before),
149
+ after: beside(at, 'after', after),
150
+ }
151
+ : {},
152
+ )
153
+ let ahead = rows(got.before).toReversed()
154
+ let behind = rows(got.after)
155
+ if (!at) return null
156
+ return h(
157
+ ui.Turns,
158
+ { 'data-conversation': e.entity.eid },
159
+ ahead.length == before
160
+ ? h(ui.Turns.More, {}, 'earlier turns are in ', mention(io, at.session))
161
+ : null,
162
+ got.before?.error
163
+ ? h(ui.Rows.More, {}, got.before.error)
164
+ : !got.before?.ready && !ahead.length
165
+ ? h(ui.Loading, {})
166
+ : null,
167
+ [...ahead, e, ...behind].map((b) =>
168
+ io.show(b, 'Inspect.Turn', { on: b == e, whole: b == e && whole })
169
+ ),
170
+ got.after?.error
171
+ ? h(ui.Rows.More, {}, got.after.error)
172
+ : !got.after?.ready && !behind.length
173
+ ? h(ui.Loading, {})
174
+ : null,
175
+ )
176
+ }
177
+
178
+ /** An entry's page: the entry inside its conversation. */
179
+ export let EntryPage = ({ e, io }: Props): JSX.Element => {
180
+ let notes = usePageNotes(io, e, ['Conversation'])
181
+ let at = placed(e)
182
+ let by = str(e, 'created', 'by')
183
+ useNamed(io, [at?.session, by])
184
+ let sub = [
185
+ kindOf(e) == 'input' && by
186
+ ? ['said by ', mention(io, by)]
187
+ : kindOf(e) ?? 'an entry',
188
+ at ? [' in ', mention(io, at.session), ` · turn ${at.seq}`] : null,
189
+ ]
190
+ return h(
191
+ 'div',
192
+ { 'data-inspect': e.entity.eid },
193
+ io.show(e, 'Inspect.Head', { sub, notes: notes.get('') }),
194
+ h(
195
+ Part,
196
+ {
197
+ io,
198
+ eid: e.entity.eid,
199
+ subject: io.id(e),
200
+ heading: 'Conversation',
201
+ notes,
202
+ },
203
+ io.show(e, 'Inspect.Conversation', {}),
204
+ ),
205
+ io.show(e, 'Inspect.Facts', { notes, skip: [ENTRY] }),
206
+ io.show(e, 'Inspect.Links', { notes }),
207
+ io.show(e, 'Inspect.History', { notes }),
208
+ )
209
+ }
210
+
211
+ // The session lifecycle wears the same pip in every shared renderer.
212
+ let SessionDot = ({ e }: { e: Bundle }): JSX.Element => {
213
+ let status = str(e, SESSION, 'status')
214
+ let looks: Record<string, string[]> = {
215
+ idle: ['half', 'active'],
216
+ settled: ['half', 'active'],
217
+ pending: ['half', 'active'],
218
+ running: ['pulse', 'active'],
219
+ completed: ['check', 'positive'],
220
+ failed: ['cross', 'negative'],
221
+ interrupted: ['cross', 'caution'],
222
+ stopped: ['cross', 'caution'],
223
+ lost: ['dashed', 'special'],
224
+ }
225
+ return h(ui.Dot, { mod: looks[status], title: status || 'no status' })
226
+ }
227
+
228
+ // What a session is running, in a line: its status, the model it asks, and
229
+ // the worktree it works in.
230
+ let running = (io: Io, e: Bundle): ReactNode[] => {
231
+ let model = str(e, 'using', 'model')
232
+ let branch = str(e, 'worktree', 'branch')
233
+ let path = str(e, 'workspace', 'root')
234
+ return [
235
+ h(SessionDot, { e }),
236
+ model ? [' · asks ', mention(io, model)] : null,
237
+ branch || path ? [' · in ', branch || path] : null,
238
+ ]
239
+ }
240
+
241
+ /** A session's latest turns, oldest first. */
242
+ let Latest = (
243
+ { e, io, notes }: { e: Bundle; io: Io; notes: Map<string, Bundle[]> },
244
+ ): JSX.Element => {
245
+ let eid = e.entity.eid
246
+ let line = `.${ENTRY}.session=${eid}`
247
+ let got = io.ask({
248
+ turns: `${line}&*&.order=-${ENTRY}.seq&.limit=${LATEST}`,
249
+ total: { query: `${line}&.count`, once: true },
250
+ })
251
+ let turns = rows(got.turns).toReversed()
252
+ return h(
253
+ Part,
254
+ {
255
+ io,
256
+ eid,
257
+ subject: io.id(e),
258
+ heading: 'Latest turns',
259
+ count: got.total?.count,
260
+ note: h(
261
+ 'a',
262
+ { href: io.find(`${line}&.order=${ENTRY}.seq`) },
263
+ 'every turn',
264
+ ),
265
+ notes,
266
+ },
267
+ got.turns?.error
268
+ ? h(ui.Rows.More, {}, got.turns.error)
269
+ : !turns.length && !got.turns?.ready
270
+ ? h(ui.Loading, {})
271
+ : !turns.length
272
+ ? h(ui.Rows.More, {}, 'nothing said yet')
273
+ : h(ui.Turns, {}, turns.map((b) => io.show(b, 'Inspect.Turn', {}))),
274
+ )
275
+ }
276
+
277
+ /** A session's page. */
278
+ export let SessionPage = ({ e, io }: Props): JSX.Element => {
279
+ let notes = usePageNotes(io, e, ['Latest turns'])
280
+ useNamed(io, [str(e, 'using', 'model')])
281
+ let brief = str(e, 'brief', 'text')
282
+ return h(
283
+ 'div',
284
+ { 'data-inspect': e.entity.eid },
285
+ io.show(e, 'Inspect.Head', { sub: running(io, e), notes: notes.get('') }),
286
+ brief
287
+ ? h(
288
+ ui.Section,
289
+ { 'data-brief': '' },
290
+ h(ui.Body, {}, h(Markdown, { source: brief })),
291
+ )
292
+ : null,
293
+ h(Latest, { e, io, notes }),
294
+ io.show(e, 'Inspect.Facts', { notes, skip: ['brief'] }),
295
+ io.show(e, 'Inspect.Links', { notes, skip: [`${ENTRY}.session`] }),
296
+ io.show(e, 'Inspect.History', { notes }),
297
+ )
298
+ }
299
+
300
+ /** A session in any list: its work first, then state and latest turn.
301
+ * Reads are bounded and projected; naming a row never loads a transcript. */
302
+ export let SessionTile = ({ e, io, got = {} }: Props): JSX.Element => {
303
+ let eid = e.entity.eid
304
+ let using = rows(got.first).find((b) => b.using)
305
+ let provider = str(using, 'using', 'provider')
306
+ useNamed(io, [provider])
307
+ let origin = e.native
308
+ ? 'native'
309
+ : e.process
310
+ ? 'managed'
311
+ : comp(e, SESSION).transcript
312
+ ? 'imported'
313
+ : 'unknown harness'
314
+ let read: Read = {
315
+ claim: rows(got.claim),
316
+ work: rows(got.work),
317
+ first: rows(got.first),
318
+ }
319
+ let title = sessionName(e, read) || io.id(e)
320
+ let at = str(rows(got.last)[0], 'created', 'at')
321
+ let ready = Object.values(got).every((a) => a.ready)
322
+ return h(
323
+ ui.Tile,
324
+ { href: io.link(eid) },
325
+ h(
326
+ ui.Tile.Kind,
327
+ {},
328
+ h(SessionDot, { e }),
329
+ ' ',
330
+ origin,
331
+ provider ? ` · ${io.name(provider)}` : '',
332
+ ),
333
+ h(ui.Tile.Title, {}, title),
334
+ h(
335
+ ui.Tile.Sub,
336
+ {},
337
+ [
338
+ str(e, SESSION, 'status'),
339
+ at
340
+ ? `active ${io.when(at)}`
341
+ : ready
342
+ ? 'no transcript recorded'
343
+ : 'loading activity…',
344
+ ]
345
+ .filter(Boolean).join(' · '),
346
+ ),
347
+ )
348
+ }
349
+
350
+ /** The shared list summary. A bounded opening preview keeps old transcripts cheap. */
351
+ let sessionTile: View = {
352
+ view: 'List.Tile',
353
+ match: parse(`.${SESSION}`),
354
+ Render: SessionTile,
355
+ asks: (e) => {
356
+ let eid = e.entity.eid
357
+ return {
358
+ ...asks(eid),
359
+ last:
360
+ `.entry.session=${eid}&.order=-entry.seq&.limit=1&.fields=entry.session,entry.seq,created.at`,
361
+ }
362
+ },
363
+ }
364
+
365
+ /** The pages and parts this package draws in the inspector. */
366
+ export let inspectViews: View[] = [
367
+ sessionTile,
368
+ { ...sessionTile, view: 'Feed.Tile' },
369
+ { ...sessionTile, view: 'Search.Tile' },
370
+ { view: 'Inspect.Turn', match: parse(`.${ENTRY}`), Render: EntryTurn },
371
+ {
372
+ view: 'Inspect.Conversation',
373
+ match: parse(`.${ENTRY}`),
374
+ Render: Conversation,
375
+ },
376
+ { view: 'Inspect.Page', match: parse(`.${ENTRY}`), Render: EntryPage },
377
+ { view: 'Inspect.Page', match: parse(`.${SESSION}`), Render: SessionPage },
378
+ ]
package/intake.js ADDED
@@ -0,0 +1,115 @@
1
+ // The session bus's intake: words given a session from outside it, a
2
+ // person's by a page, a channel or a conversation tool, taken in as its next
3
+ // input once each, with how they came and what came with them. What is
4
+ // addressed to a session in the graph is delivered by ./bus.ts.
5
+ import { derivedEid } from "@yaks/graph/identity";
6
+ import { Stale } from "@yaks/graph/errors";
7
+ import { token } from "@yaks/graph/sha256";
8
+ import { attachmentRows } from "@yaks/blob/attachment";
9
+ import { and, eq, fields, present } from "@yaks/query";
10
+ let comp = (b, name)=>b[name] ?? {};
11
+ /** The input the words named `id` become in the session that takes them
12
+ * in: one id, so a request and its line are one, and giving them again
13
+ * writes nothing. The words it is derived from are the ones its first rows
14
+ * were named by. */ export let inputOf = (id)=>derivedEid('operator-input|' + id);
15
+ /** The rows that give a session these words: its input, linked back to the
16
+ * item it came in (`intake{item}`), and each file's attachment to that item, or
17
+ * to the input where no item names them (@yaks/blob/attachment). */ export let intake = (words)=>{
18
+ let { session, item, from, channel, using, source } = words;
19
+ let named = words.id ?? item;
20
+ let eid = named ? inputOf(named) : crypto.randomUUID();
21
+ return [
22
+ {
23
+ entity: {
24
+ eid
25
+ },
26
+ entry: {
27
+ session,
28
+ ...from ? {
29
+ from
30
+ } : {}
31
+ },
32
+ ...item || source != null ? {
33
+ intake: {
34
+ ...item ? {
35
+ item
36
+ } : {},
37
+ ...source != null ? {
38
+ source
39
+ } : {}
40
+ }
41
+ } : {},
42
+ content: {
43
+ body: words.body
44
+ },
45
+ ...channel ? {
46
+ channel
47
+ } : {},
48
+ ...using ? {
49
+ using
50
+ } : {},
51
+ ...words.system ? {
52
+ system: {}
53
+ } : {},
54
+ ...words.with,
55
+ $actor: {
56
+ by: words.by,
57
+ via: session
58
+ }
59
+ },
60
+ ...attachmentRows(item ?? eid, words.files ?? [])
61
+ ];
62
+ };
63
+ /** Give a session words ({@link intake}), with what the host writes `beside`
64
+ * them in the same batch: the input's id, and whether this wrote it. Named
65
+ * words already taken in write nothing, `beside` included, however many
66
+ * times or at once they are given again. */ export let take = async (g, words, beside = [], options = {})=>{
67
+ let [line, ...files] = intake(words);
68
+ let input = line.entity.eid;
69
+ if ((words.id ?? words.item) && (await g.get([
70
+ input
71
+ ], [
72
+ 'entry'
73
+ ]))[0]?.entry) {
74
+ return {
75
+ input,
76
+ fresh: false
77
+ };
78
+ }
79
+ try {
80
+ await g.apply([
81
+ ...beside,
82
+ {
83
+ ...line,
84
+ $was: {
85
+ entry: {
86
+ session: token(null)
87
+ }
88
+ }
89
+ },
90
+ ...files
91
+ ], options);
92
+ } catch (error) {
93
+ if (error instanceof Stale && error.eid == input) {
94
+ return {
95
+ input,
96
+ fresh: false
97
+ };
98
+ }
99
+ throw error;
100
+ }
101
+ return {
102
+ input,
103
+ fresh: true
104
+ };
105
+ };
106
+ /** The session a task's next words go to: the newest it holds
107
+ * (`contains`), if any. */ export let taskSession = async (g, task)=>{
108
+ let links = await g.read(and(present('contains'), eq('edge.from', task), fields('edge.to')));
109
+ let held = await g.get(links.map((b)=>String(comp(b, 'edge').to)), [
110
+ 'session',
111
+ 'created'
112
+ ]);
113
+ return held.filter((b)=>b?.session).sort((a, b)=>String(comp(a, 'created').at).localeCompare(String(comp(b, 'created').at))).at(-1)?.entity.eid;
114
+ };
115
+ //# sourceMappingURL=intake.js.map
package/intake.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"intake.js","sources":["./intake.ts"],"names":[],"mappings":"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"}
package/intake.ts ADDED
@@ -0,0 +1,124 @@
1
+ // The session bus's intake: words given a session from outside it, a
2
+ // person's by a page, a channel or a conversation tool, taken in as its next
3
+ // input once each, with how they came and what came with them. What is
4
+ // addressed to a session in the graph is delivered by ./bus.ts.
5
+ import type { ApplyOpts, Bundle, Comp, Eid, Graph } from 'jsr:@yaks/graph@0.2.36'
6
+ import { derivedEid } from '@yaks/graph/identity'
7
+ import { Stale } from '@yaks/graph/errors'
8
+ import { token } from '@yaks/graph/sha256'
9
+ import { type Attached, attachmentRows } from '@yaks/blob/attachment'
10
+ import { and, eq, fields, present } from '@yaks/query'
11
+
12
+ let comp = (b: Bundle, name: string): Comp => (b[name] ?? {}) as Comp
13
+
14
+ /** Words given a session from outside it, as its next input ({@link take}):
15
+ * whose they are (`by`) and, when someone else wrote them for that person,
16
+ * who did (`from`); what names them wherever they are given again (`id`),
17
+ * which is the item they came in (`item`, such as a request) unless the
18
+ * caller names them itself; the channel they came by and the framing said
19
+ * before them; the files that came with them and the address of the original
20
+ * text among those files (`source`); the model chosen to answer them (`using`); and what
21
+ * the host keeps beside them (`with`). Words the platform wrote, never a person's, are `system`. */
22
+ export type Intake = {
23
+ session: Eid
24
+ body: string
25
+ by: Eid
26
+ id?: string
27
+ item?: Eid
28
+ from?: string
29
+ channel?: { name: string; framing?: string }
30
+ files?: Attached[]
31
+ source?: string
32
+ using?: Comp
33
+ system?: boolean
34
+ with?: Record<string, Comp>
35
+ }
36
+
37
+ /** The input the words named `id` become in the session that takes them
38
+ * in: one id, so a request and its line are one, and giving them again
39
+ * writes nothing. The words it is derived from are the ones its first rows
40
+ * were named by. */
41
+ export let inputOf = (id: string): Eid => derivedEid('operator-input|' + id)
42
+
43
+ /** The rows that give a session these words: its input, linked back to the
44
+ * item it came in (`intake{item}`), and each file's attachment to that item, or
45
+ * to the input where no item names them (@yaks/blob/attachment). */
46
+ export let intake = (words: Intake): Bundle[] => {
47
+ let { session, item, from, channel, using, source } = words
48
+ let named = words.id ?? item
49
+ let eid = named ? inputOf(named) : crypto.randomUUID()
50
+ return [
51
+ {
52
+ entity: { eid },
53
+ entry: { session, ...from ? { from } : {} },
54
+ ...item || source != null
55
+ ? {
56
+ intake: {
57
+ ...item ? { item } : {},
58
+ ...source != null ? { source } : {},
59
+ },
60
+ }
61
+ : {},
62
+ content: { body: words.body },
63
+ ...channel ? { channel } : {},
64
+ ...using ? { using } : {},
65
+ ...words.system ? { system: {} } : {},
66
+ ...words.with,
67
+ $actor: { by: words.by, via: session },
68
+ },
69
+ ...attachmentRows(item ?? eid, words.files ?? []),
70
+ ]
71
+ }
72
+
73
+ /** Give a session words ({@link intake}), with what the host writes `beside`
74
+ * them in the same batch: the input's id, and whether this wrote it. Named
75
+ * words already taken in write nothing, `beside` included, however many
76
+ * times or at once they are given again. */
77
+ export let take = async (
78
+ g: Pick<Graph, 'get' | 'apply'>,
79
+ words: Intake,
80
+ beside: Bundle[] = [],
81
+ options: ApplyOpts = {},
82
+ ): Promise<{ input: Eid; fresh: boolean }> => {
83
+ let [line, ...files] = intake(words)
84
+ let input = line.entity.eid
85
+ if (
86
+ (words.id ?? words.item) && (await g.get([input], ['entry']))[0]?.entry
87
+ ) {
88
+ return { input, fresh: false }
89
+ }
90
+ try {
91
+ await g.apply([
92
+ ...beside,
93
+ { ...line, $was: { entry: { session: token(null) } } },
94
+ ...files,
95
+ ], options)
96
+ } catch (error) {
97
+ if (error instanceof Stale && error.eid == input) {
98
+ return { input, fresh: false }
99
+ }
100
+ throw error
101
+ }
102
+ return { input, fresh: true }
103
+ }
104
+
105
+ /** The session a task's next words go to: the newest it holds
106
+ * (`contains`), if any. */
107
+ export let taskSession = async (
108
+ g: Pick<Graph, 'read' | 'get'>,
109
+ task: Eid,
110
+ ): Promise<Eid | undefined> => {
111
+ let links = await g.read(and(
112
+ present('contains'),
113
+ eq('edge.from', task),
114
+ fields('edge.to'),
115
+ ))
116
+ let held = await g.get(
117
+ links.map((b) => String(comp(b, 'edge').to)),
118
+ ['session', 'created'],
119
+ )
120
+ return held.filter((b) => b?.session)
121
+ .sort((a, b) =>
122
+ String(comp(a, 'created').at).localeCompare(String(comp(b, 'created').at))
123
+ ).at(-1)?.entity.eid
124
+ }
package/joined.js ADDED
@@ -0,0 +1,67 @@
1
+ // Which entries make the lines of a conversation: one pure function every
2
+ // drawing of a transcript shares, whatever draws its lines (./conversation.ts,
3
+ // browse's session page). It reads nothing but the entries.
4
+ import { CALL } from "./native.js";
5
+ let comp = (b, name)=>b[name];
6
+ /**
7
+ * Which entries make the lines of a conversation, in its order: each entry is
8
+ * a line, except a result whose call is among them, which joins that call's
9
+ * line, so an answer settles in its call's place however many calls ran
10
+ * beside it. A result whose call is not among them is a line of its own.
11
+ * Where `same` says an entry repeats the one before it (a stream telling one
12
+ * fact frame by frame), the run is one line: its last entry, counting the
13
+ * run.
14
+ *
15
+ * ```ts
16
+ * import { joined } from './joined.ts'
17
+ * import { equal } from '@yaks/testing'
18
+ * let e = (eid: string, comps = {}) => ({ entity: { eid }, entry: {}, ...comps })
19
+ * let lines = joined([
20
+ * e('c', { call: { to: 't' } }),
21
+ * e('w', { content: { body: 'Hi' } }),
22
+ * e('r', { result: { call: 'c' } }),
23
+ * e('lone', { result: { call: 'gone' } }),
24
+ * ])
25
+ * equal(lines.map((l) => [l.entry.entity.eid, l.result?.entity.eid]), [
26
+ * ['c', 'r'],
27
+ * ['w', undefined],
28
+ * ['lone', undefined],
29
+ * ])
30
+ * ```
31
+ */ export let joined = (entries, same)=>{
32
+ let calls = new Set(entries.filter((b)=>b[CALL]).map((b)=>b.entity.eid));
33
+ let answer = (b)=>{
34
+ let call = comp(b, 'result')?.call;
35
+ return call != null && calls.has(String(call)) ? String(call) : undefined;
36
+ };
37
+ let results = new Map(entries.flatMap((b)=>{
38
+ let call = answer(b);
39
+ return call ? [
40
+ [
41
+ call,
42
+ b
43
+ ]
44
+ ] : [];
45
+ }));
46
+ let out = [];
47
+ for (let b of entries){
48
+ if (answer(b)) continue;
49
+ let last = out.at(-1);
50
+ if (last && same?.(last.entry, b)) {
51
+ out[out.length - 1] = {
52
+ entry: b,
53
+ n: (last.n ?? 1) + 1
54
+ };
55
+ continue;
56
+ }
57
+ let result = results.get(b.entity.eid);
58
+ out.push(result ? {
59
+ entry: b,
60
+ result
61
+ } : {
62
+ entry: b
63
+ });
64
+ }
65
+ return out;
66
+ };
67
+ //# sourceMappingURL=joined.js.map
package/joined.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"joined.js","sources":["./joined.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,+EAA+E;AAC/E,4DAA4D;AAG5D,SAAS,IAAI,sBAAqB;AAElC,IAAI,OAAO,CAAC,GAAW,OACrB,CAAC,CAAC,KAAK;AAOT;;;;;;;;;;;;;;;;;;;;;;;;;CAyBC,GACD,OAAO,IAAI,SAAS,CAClB,SACA;EAEA,IAAI,QAAQ,IAAI,IAAI,QAAQ,MAAM,CAAC,CAAC,IAAM,CAAC,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,IAAM,EAAE,MAAM,CAAC,GAAG;EAC1E,IAAI,SAAS,CAAC;IACZ,IAAI,OAAO,KAAK,GAAG,WAAW;IAC9B,OAAO,QAAQ,QAAQ,MAAM,GAAG,CAAC,OAAO,SAAS,OAAO,QAAQ;EAClE;EACA,IAAI,UAAU,IAAI,IAChB,QAAQ,OAAO,CAAC,CAAC;IACf,IAAI,OAAO,OAAO;IAClB,OAAO,OAAO;MAAC;QAAC;QAAM;OAAE;KAAU,GAAG,EAAE;EACzC;EAEF,IAAI,MAAgB,EAAE;EACtB,KAAK,IAAI,KAAK,QAAS;IACrB,IAAI,OAAO,IAAI;IACf,IAAI,OAAO,IAAI,EAAE,CAAC,CAAC;IACnB,IAAI,QAAQ,OAAO,KAAK,KAAK,EAAE,IAAI;MACjC,GAAG,CAAC,IAAI,MAAM,GAAG,EAAE,GAAG;QAAE,OAAO;QAAG,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI;MAAE;MACvD;IACF;IACA,IAAI,SAAS,QAAQ,GAAG,CAAC,EAAE,MAAM,CAAC,GAAG;IACrC,IAAI,IAAI,CAAC,SAAS;MAAE,OAAO;MAAG;IAAO,IAAI;MAAE,OAAO;IAAE;EACtD;EACA,OAAO;AACT,EAAC"}