@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
package/entry_log.js ADDED
@@ -0,0 +1,241 @@
1
+ // A session's transcript as the page draws it. Each entry is one yak entry
2
+ // (packages/session/README.md#the-transcript): what kind it is, and whether the
3
+ // transcript is still working, are @yaks/session's own reads (`kindOf`,
4
+ // `statusOf`, `openCalls`), so the page and the host never disagree about them.
5
+ // A model or a tool is a referenced entity; `name` turns its eid into words.
6
+ import { kindOf, openCalls, statusOf, textOf } from "@yaks/session/status";
7
+ import { doing } from "@yaks/tools/title";
8
+ import { refusalText } from "@yaks/tools/errors";
9
+ let text = (value)=>String(value ?? '');
10
+ let clip = (value, limit = 240)=>{
11
+ let out = text(value).replace(/\s+/g, ' ').trim();
12
+ return out.length > limit ? `${out.slice(0, limit - 1)}…` : out;
13
+ };
14
+ let bundle = (row)=>({
15
+ entity: {
16
+ eid: row.eid
17
+ },
18
+ ...row.comps
19
+ });
20
+ // Token counts as the turn row serializes them, by @yaks/model `usage`'s own
21
+ // names.
22
+ let usage = (u)=>{
23
+ if (!u) return undefined;
24
+ let n = (k)=>Number(u[k] ?? 0);
25
+ return {
26
+ input: n('input_tokens'),
27
+ json: JSON.stringify({
28
+ input_tokens: n('input_tokens'),
29
+ cached_tokens: n('cached_tokens'),
30
+ output_tokens: n('output_tokens'),
31
+ reasoning_tokens: n('reasoning_tokens')
32
+ })
33
+ };
34
+ };
35
+ let toolOf = (c, name)=>name(text(c.call?.to)) || 'tool';
36
+ let failure = (c)=>{
37
+ let refusal = c.refusal;
38
+ return c.exception ? text(c.exception.value) || text(c.content?.body) || 'exception' : refusal ? refusalText(text(refusal.code), text(c.content?.body)) : undefined;
39
+ };
40
+ let shown = (row, byEid, name)=>{
41
+ let c = row.comps;
42
+ let b = bundle(row);
43
+ let kind = kindOf(b);
44
+ // A result carrying its call's refusal is shown as the refusal it is.
45
+ if (kind == 'exception' || kind == 'refusal' || c.refusal) {
46
+ return {
47
+ kind: 'error',
48
+ text: failure(c)
49
+ };
50
+ }
51
+ if (kind == 'stop') return {
52
+ kind: 'sys',
53
+ tag: 'stop'
54
+ };
55
+ if (kind == 'ask') {
56
+ let model = name(text(c.ask?.to)) ?? name(text(c.using?.model));
57
+ let u = usage(c.usage);
58
+ return u ? {
59
+ kind: 'turn',
60
+ model,
61
+ usage: u.json,
62
+ ...u.input ? {
63
+ context: u.input
64
+ } : {}
65
+ } : {
66
+ kind: 'sys',
67
+ tag: 'ask',
68
+ ...model ? {
69
+ text: model
70
+ } : {}
71
+ };
72
+ }
73
+ if (kind == 'call') {
74
+ let args = c.call?.args ?? {};
75
+ let tool = toolOf(c, name);
76
+ return typeof args.command == 'string' ? {
77
+ kind: 'exec',
78
+ command: args.command,
79
+ desc: tool
80
+ } : {
81
+ kind: 'tool',
82
+ name: tool,
83
+ detail: clip(JSON.stringify(args))
84
+ };
85
+ }
86
+ if (c.tool_progress) {
87
+ return {
88
+ kind: 'sys',
89
+ tag: 'pending',
90
+ text: textOf(b)
91
+ };
92
+ }
93
+ if (kind == 'result') {
94
+ let call = byEid.get(text(c.result?.call));
95
+ let body = clip(textOf(b));
96
+ let code = c.exit?.code == null ? undefined : Number(c.exit.code);
97
+ return {
98
+ kind: 'tool',
99
+ name: `↳ ${call ? toolOf(call.comps, name) : 'tool'}`,
100
+ ...body ? {
101
+ detail: body
102
+ } : {},
103
+ ...code == null ? {} : {
104
+ ok: code == 0
105
+ }
106
+ };
107
+ }
108
+ if (c.cancel) {
109
+ return {
110
+ kind: 'sys',
111
+ tag: 'cancel',
112
+ text: text(c.cancel.target)
113
+ };
114
+ }
115
+ if (c.checkpoint) return {
116
+ kind: 'sys',
117
+ tag: 'checkpoint'
118
+ };
119
+ if (c.attention) return {
120
+ kind: 'sys',
121
+ tag: 'attention'
122
+ };
123
+ let body = textOf(b);
124
+ if (kind == 'reasoning') {
125
+ return body ? {
126
+ kind: 'reason',
127
+ text: body
128
+ } : undefined;
129
+ }
130
+ if (kind == 'output') {
131
+ return {
132
+ kind: 'say',
133
+ role: 'agent',
134
+ text: body
135
+ };
136
+ }
137
+ if (kind == 'input') {
138
+ // Instructions admitted into the transcript (@yaks/context `prompt`),
139
+ // passive context (`notice`) and words the platform wrote (`system`) are
140
+ // the harness's, not something said.
141
+ if (c.prompt) return {
142
+ kind: 'sys',
143
+ tag: 'instructions',
144
+ text: clip(body)
145
+ };
146
+ if (c.notice) return {
147
+ kind: 'sys',
148
+ tag: 'notice',
149
+ text: clip(body)
150
+ };
151
+ if (c.system) return {
152
+ kind: 'sys',
153
+ tag: 'system',
154
+ text: clip(body)
155
+ };
156
+ return {
157
+ kind: 'say',
158
+ role: 'user',
159
+ text: body
160
+ };
161
+ }
162
+ return undefined;
163
+ };
164
+ // What the transcript is waiting on, when it's working: a call no result has
165
+ // answered yet, the model, or the daemon that has an input to ask about.
166
+ let activityOf = (bundles, name)=>{
167
+ let status = statusOf(bundles);
168
+ if (status != 'running' && status != 'pending') return undefined;
169
+ let call = openCalls(bundles).at(-1);
170
+ if (call) {
171
+ let tool = toolOf(call, name);
172
+ return {
173
+ kind: 'tool',
174
+ label: doing(tool)
175
+ };
176
+ }
177
+ return status == 'running' ? {
178
+ kind: 'model',
179
+ label: 'waiting for model…'
180
+ } : {
181
+ kind: 'runner',
182
+ label: 'waiting for runner…'
183
+ };
184
+ };
185
+ export let graphLog = (source, name = ()=>undefined)=>{
186
+ let rows = source.toSorted((a, b)=>a.seq - b.seq);
187
+ let byEid = new Map(rows.map((row)=>[
188
+ row.eid,
189
+ row
190
+ ]));
191
+ let bundles = rows.map(bundle);
192
+ let entries = rows.map((source)=>{
193
+ let row = shown(source, byEid, name);
194
+ let at = text(source.comps.created?.at);
195
+ if (row && at && !row.at) row = {
196
+ ...row,
197
+ at
198
+ };
199
+ return {
200
+ eid: source.eid,
201
+ ...source.comps.result?.call ? {
202
+ call: text(source.comps.result.call)
203
+ } : {},
204
+ seq: source.seq,
205
+ // Raw source is only read on disclosure (eid-backed rows use EntryLens).
206
+ // Keep it exact without serializing every transcript payload on paint.
207
+ get line () {
208
+ return JSON.stringify({
209
+ eid: source.eid,
210
+ seq: source.seq,
211
+ ...source.comps
212
+ });
213
+ },
214
+ ...row ? {
215
+ row
216
+ } : {}
217
+ };
218
+ });
219
+ let context = entries.findLast((entry)=>entry.row?.context)?.row?.context;
220
+ let activity = activityOf(bundles, name);
221
+ return {
222
+ entries,
223
+ ...activity ? {
224
+ activity
225
+ } : {},
226
+ ...context ? {
227
+ context
228
+ } : {}
229
+ };
230
+ };
231
+ // Bound rendered entries for callers that already hold a log. A paged reader
232
+ // may pass graphLog one page; a result whose call is on an older page then
233
+ // keeps the generic tool label until that page is loaded.
234
+ export let pageEntries = (entries, p)=>{
235
+ let tail = Math.max(0, p.tail ?? 0);
236
+ let after = Math.max(0, p.after ?? 0);
237
+ let limit = Math.max(0, p.limit ?? 0);
238
+ let picked = tail > 0 ? entries.slice(-tail) : entries.filter((entry)=>entry.seq > after);
239
+ return limit > 0 ? picked.slice(0, limit) : picked;
240
+ };
241
+ //# sourceMappingURL=entry_log.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entry_log.js","sources":["./entry_log.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,gFAAgF;AAChF,wEAAwE;AACxE,gFAAgF;AAChF,6EAA6E;AAC7E,SAAS,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,oCAAyC;AAGrF,SAAS,KAAK,iCAAsC;AACpD,SAAS,WAAW,kCAAuC;AAyB3D,IAAI,OAAO,CAAC,QAAmB,OAAO,SAAS;AAC/C,IAAI,OAAO,CAAC,OAAgB,QAAQ,GAAG;EACrC,IAAI,MAAM,KAAK,OAAO,OAAO,CAAC,QAAQ,KAAK,IAAI;EAC/C,OAAO,IAAI,MAAM,GAAG,QAAQ,GAAG,IAAI,KAAK,CAAC,GAAG,QAAQ,GAAG,CAAC,CAAC,GAAG;AAC9D;AAEA,IAAI,SAAS,CAAC,MAA0B,CAAC;IACvC,QAAQ;MAAE,KAAK,IAAI,GAAG;IAAC;IACvB,GAAG,IAAI,KAAK;EACd,CAAC;AAED,6EAA6E;AAC7E,SAAS;AACT,IAAI,QAAQ,CAAC;EACX,IAAI,CAAC,GAAG,OAAO;EACf,IAAI,IAAI,CAAC,IAAc,OAAO,CAAC,CAAC,EAAE,IAAI;EACtC,OAAO;IACL,OAAO,EAAE;I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AE,OACrB;QAAE,MAAM,KAAK,OAAO,KAAK,CAAC,MAAM,CAAC,IAAI;MAAE,IACvC,CAAC,CAAC;MACN,KAAK,OAAO,GAAG;MACf,yEAAyE;MACzE,uEAAuE;MACvE,IAAI,QAAO;QACT,OAAO,KAAK,SAAS,CAAC;UACpB,KAAK,OAAO,GAAG;UACf,KAAK,OAAO,GAAG;UACf,GAAG,OAAO,KAAK;QACjB;MACF;MACA,GAAI,MAAM;QAAE;MAAI,IAAI,CAAC,CAAC;IACxB;EACF;EACA,IAAI,UAAU,QAAQ,QAAQ,CAAC,CAAC,QAAU,MAAM,GAAG,EAAE,UAAU,KAAK;EACpE,IAAI,WAAW,WAAW,SAAS;EACnC,OAAO;IACL;IACA,GAAI,WAAW;MAAE;IAAS,IAAI,CAAC,CAAC;IAChC,GAAI,UAAU;MAAE;IAAQ,IAAI,CAAC,CAAC;EAChC;AACF,EAAC;AAED,6EAA6E;AAC7E,2EAA2E;AAC3E,0DAA0D;AAC1D,OAAO,IAAI,cAAc,CACvB,SACA;EAEA,IAAI,OAAO,KAAK,GAAG,CAAC,GAAG,EAAE,IAAI,IAAI;EACjC,IAAI,QAAQ,KAAK,GAAG,CAAC,GAAG,EAAE,KAAK,IAAI;EACnC,IAAI,QAAQ,KAAK,GAAG,CAAC,GAAG,EAAE,KAAK,IAAI;EACnC,IAAI,SAAS,OAAO,IAChB,QAAQ,KAAK,CAAC,CAAC,QACf,QAAQ,MAAM,CAAC,CAAC,QAAU,MAAM,GAAG,GAAG;EAC1C,OAAO,QAAQ,IAAI,OAAO,KAAK,CAAC,GAAG,SAAS;AAC9C,EAAC"}
package/entry_log.ts ADDED
@@ -0,0 +1,214 @@
1
+ // A session's transcript as the page draws it. Each entry is one yak entry
2
+ // (packages/session/README.md#the-transcript): what kind it is, and whether the
3
+ // transcript is still working, are @yaks/session's own reads (`kindOf`,
4
+ // `statusOf`, `openCalls`), so the page and the host never disagree about them.
5
+ // A model or a tool is a referenced entity; `name` turns its eid into words.
6
+ import { kindOf, openCalls, statusOf, textOf } from '@yaks/session/status'
7
+ import type { Bundle } from 'jsr:@yaks/graph@0.2.36'
8
+ import { type LogRow } from './types.js'
9
+ import { doing } from '@yaks/tools/title'
10
+ import { refusalText } from '@yaks/tools/errors'
11
+
12
+ export type EntryRow = {
13
+ eid: string
14
+ seq: number
15
+ comps: Record<string, Record<string, unknown>>
16
+ }
17
+
18
+ export type GraphLogEntry = {
19
+ eid: string
20
+ call?: string
21
+ seq: number
22
+ line: string
23
+ row?: LogRow
24
+ }
25
+
26
+ export type GraphLog = {
27
+ entries: GraphLogEntry[]
28
+ activity?: { kind: 'tool' | 'model' | 'runner'; label: string }
29
+ context?: number
30
+ }
31
+
32
+ /** The words for a referenced entity (a model, a tool), when they're held. */
33
+ export type Names = (eid: string) => string | undefined
34
+
35
+ let text = (value: unknown) => String(value ?? '')
36
+ let clip = (value: unknown, limit = 240) => {
37
+ let out = text(value).replace(/\s+/g, ' ').trim()
38
+ return out.length > limit ? `${out.slice(0, limit - 1)}…` : out
39
+ }
40
+
41
+ let bundle = (row: EntryRow): Bundle => ({
42
+ entity: { eid: row.eid },
43
+ ...row.comps,
44
+ })
45
+
46
+ // Token counts as the turn row serializes them, by @yaks/model `usage`'s own
47
+ // names.
48
+ let usage = (u?: Record<string, unknown>) => {
49
+ if (!u) return undefined
50
+ let n = (k: string) => Number(u[k] ?? 0)
51
+ return {
52
+ input: n('input_tokens'),
53
+ json: JSON.stringify({
54
+ input_tokens: n('input_tokens'),
55
+ cached_tokens: n('cached_tokens'),
56
+ output_tokens: n('output_tokens'),
57
+ reasoning_tokens: n('reasoning_tokens'),
58
+ }),
59
+ }
60
+ }
61
+
62
+ let toolOf = (c: EntryRow['comps'], name: Names) =>
63
+ name(text(c.call?.to)) || 'tool'
64
+
65
+ let failure = (c: EntryRow['comps']) => {
66
+ let refusal = c.refusal
67
+ return c.exception
68
+ ? text(c.exception.value) || text(c.content?.body) || 'exception'
69
+ : refusal
70
+ ? refusalText(text(refusal.code), text(c.content?.body))
71
+ : undefined
72
+ }
73
+
74
+ let shown = (
75
+ row: EntryRow,
76
+ byEid: Map<string, EntryRow>,
77
+ name: Names,
78
+ ): LogRow | undefined => {
79
+ let c = row.comps
80
+ let b = bundle(row)
81
+ let kind = kindOf(b)
82
+ // A result carrying its call's refusal is shown as the refusal it is.
83
+ if (kind == 'exception' || kind == 'refusal' || c.refusal) {
84
+ return { kind: 'error', text: failure(c)! }
85
+ }
86
+ if (kind == 'stop') return { kind: 'sys', tag: 'stop' }
87
+ if (kind == 'ask') {
88
+ let model = name(text(c.ask?.to)) ?? name(text(c.using?.model))
89
+ let u = usage(c.usage)
90
+ return u
91
+ ? {
92
+ kind: 'turn',
93
+ model,
94
+ usage: u.json,
95
+ ...u.input ? { context: u.input } : {},
96
+ }
97
+ : { kind: 'sys', tag: 'ask', ...model ? { text: model } : {} }
98
+ }
99
+ if (kind == 'call') {
100
+ let args = (c.call?.args ?? {}) as Record<string, unknown>
101
+ let tool = toolOf(c, name)
102
+ return typeof args.command == 'string'
103
+ ? { kind: 'exec', command: args.command, desc: tool }
104
+ : { kind: 'tool', name: tool, detail: clip(JSON.stringify(args)) }
105
+ }
106
+ if (c.tool_progress) {
107
+ return { kind: 'sys', tag: 'pending', text: textOf(b) }
108
+ }
109
+ if (kind == 'result') {
110
+ let call = byEid.get(text(c.result?.call))
111
+ let body = clip(textOf(b))
112
+ let code = c.exit?.code == null ? undefined : Number(c.exit.code)
113
+ return {
114
+ kind: 'tool',
115
+ name: `↳ ${call ? toolOf(call.comps, name) : 'tool'}`,
116
+ ...body ? { detail: body } : {},
117
+ ...code == null ? {} : { ok: code == 0 },
118
+ }
119
+ }
120
+ if (c.cancel) {
121
+ return { kind: 'sys', tag: 'cancel', text: text(c.cancel.target) }
122
+ }
123
+ if (c.checkpoint) return { kind: 'sys', tag: 'checkpoint' }
124
+ if (c.attention) return { kind: 'sys', tag: 'attention' }
125
+ let body = textOf(b)
126
+ if (kind == 'reasoning') {
127
+ return body ? { kind: 'reason', text: body } : undefined
128
+ }
129
+ if (kind == 'output') {
130
+ return { kind: 'say', role: 'agent', text: body }
131
+ }
132
+ if (kind == 'input') {
133
+ // Instructions admitted into the transcript (@yaks/context `prompt`),
134
+ // passive context (`notice`) and words the platform wrote (`system`) are
135
+ // the harness's, not something said.
136
+ if (c.prompt) return { kind: 'sys', tag: 'instructions', text: clip(body) }
137
+ if (c.notice) return { kind: 'sys', tag: 'notice', text: clip(body) }
138
+ if (c.system) return { kind: 'sys', tag: 'system', text: clip(body) }
139
+ return { kind: 'say', role: 'user', text: body }
140
+ }
141
+ return undefined
142
+ }
143
+
144
+ // What the transcript is waiting on, when it's working: a call no result has
145
+ // answered yet, the model, or the daemon that has an input to ask about.
146
+ let activityOf = (
147
+ bundles: Bundle[],
148
+ name: Names,
149
+ ): GraphLog['activity'] => {
150
+ let status = statusOf(bundles)
151
+ if (status != 'running' && status != 'pending') return undefined
152
+ let call = openCalls(bundles).at(-1)
153
+ if (call) {
154
+ let tool = toolOf(call as EntryRow['comps'], name)
155
+ return { kind: 'tool', label: doing(tool) }
156
+ }
157
+ return status == 'running'
158
+ ? { kind: 'model', label: 'waiting for model…' }
159
+ : { kind: 'runner', label: 'waiting for runner…' }
160
+ }
161
+
162
+ export let graphLog = (
163
+ source: EntryRow[],
164
+ name: Names = () => undefined,
165
+ ): GraphLog => {
166
+ let rows = source.toSorted((a, b) => a.seq - b.seq)
167
+ let byEid = new Map(rows.map((row) => [row.eid, row]))
168
+ let bundles = rows.map(bundle)
169
+ let entries = rows.map((source) => {
170
+ let row = shown(source, byEid, name)
171
+ let at = text(source.comps.created?.at)
172
+ if (row && at && !row.at) row = { ...row, at }
173
+ return {
174
+ eid: source.eid,
175
+ ...(source.comps.result?.call
176
+ ? { call: text(source.comps.result.call) }
177
+ : {}),
178
+ seq: source.seq,
179
+ // Raw source is only read on disclosure (eid-backed rows use EntryLens).
180
+ // Keep it exact without serializing every transcript payload on paint.
181
+ get line() {
182
+ return JSON.stringify({
183
+ eid: source.eid,
184
+ seq: source.seq,
185
+ ...source.comps,
186
+ })
187
+ },
188
+ ...(row ? { row } : {}),
189
+ }
190
+ })
191
+ let context = entries.findLast((entry) => entry.row?.context)?.row?.context
192
+ let activity = activityOf(bundles, name)
193
+ return {
194
+ entries,
195
+ ...(activity ? { activity } : {}),
196
+ ...(context ? { context } : {}),
197
+ }
198
+ }
199
+
200
+ // Bound rendered entries for callers that already hold a log. A paged reader
201
+ // may pass graphLog one page; a result whose call is on an older page then
202
+ // keeps the generic tool label until that page is loaded.
203
+ export let pageEntries = (
204
+ entries: GraphLogEntry[],
205
+ p: { after?: number; tail?: number; limit?: number },
206
+ ): GraphLogEntry[] => {
207
+ let tail = Math.max(0, p.tail ?? 0)
208
+ let after = Math.max(0, p.after ?? 0)
209
+ let limit = Math.max(0, p.limit ?? 0)
210
+ let picked = tail > 0
211
+ ? entries.slice(-tail)
212
+ : entries.filter((entry) => entry.seq > after)
213
+ return limit > 0 ? picked.slice(0, limit) : picked
214
+ }
package/failure.js ADDED
@@ -0,0 +1,22 @@
1
+ // Browsers report through their page tracker; terminal commands supply their
2
+ // host's durable tracker reporter at the same catch sites.
3
+ let reporter;
4
+ export let onFailure = (next)=>{
5
+ let prior = reporter;
6
+ reporter = next;
7
+ return ()=>{
8
+ reporter = prior;
9
+ };
10
+ };
11
+ export let failure = (error, place, tags)=>{
12
+ let page = Reflect.get(globalThis, Symbol.for('yaks.report-caught'));
13
+ if (reporter) {
14
+ if (tags) reporter(error, place, tags);
15
+ else reporter(error, place);
16
+ } else if (page) page(error, place, tags);
17
+ else {
18
+ let said = error instanceof Error ? error.message : String(error);
19
+ console.error(`${place}: ${said}`, error);
20
+ }
21
+ };
22
+ //# sourceMappingURL=failure.js.map
package/failure.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"failure.js","sources":["./failure.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,2DAA2D;AAM3D,IAAI;AAEJ,OAAO,IAAI,YAAY,CAAC;EACtB,IAAI,QAAQ;EACZ,WAAW;EACX,OAAO;IACL,WAAW;EACb;AACF,EAAC;AAED,OAAO,IAAI,UAAU,CACnB,OACA,OACA;EAEA,IAAI,OAAO,QAAQ,GAAG,CAAC,YAAY,OAAO,GAAG,CAAC;EAG9C,IAAI,UAAU;IACZ,IAAI,MAAM,SAAS,OAAO,OAAO;SAC5B,SAAS,OAAO;EACvB,OAAO,IAAI,MAAM,KAAK,OAAO,OAAO;OAC/B;IACH,IAAI,OAAO,iBAAiB,QAAQ,MAAM,OAAO,GAAG,OAAO;IAC3D,QAAQ,KAAK,CAAC,GAAG,MAAM,EAAE,EAAE,MAAM,EAAE;EACrC;AACF,EAAC"}
package/failure.ts ADDED
@@ -0,0 +1,34 @@
1
+ // Browsers report through their page tracker; terminal commands supply their
2
+ // host's durable tracker reporter at the same catch sites.
3
+ export type Reporter = (
4
+ error: unknown,
5
+ place: string,
6
+ tags?: Record<string, string>,
7
+ ) => void
8
+ let reporter: Reporter | undefined
9
+
10
+ export let onFailure = (next: Reporter): () => void => {
11
+ let prior = reporter
12
+ reporter = next
13
+ return () => {
14
+ reporter = prior
15
+ }
16
+ }
17
+
18
+ export let failure = (
19
+ error: unknown,
20
+ place: string,
21
+ tags?: Record<string, string>,
22
+ ): void => {
23
+ let page = Reflect.get(globalThis, Symbol.for('yaks.report-caught')) as
24
+ | Reporter
25
+ | undefined
26
+ if (reporter) {
27
+ if (tags) reporter(error, place, tags)
28
+ else reporter(error, place)
29
+ } else if (page) page(error, place, tags)
30
+ else {
31
+ let said = error instanceof Error ? error.message : String(error)
32
+ console.error(`${place}: ${said}`, error)
33
+ }
34
+ }
package/front.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "$vocabulary": {
3
+ "https://yak.sh/vocab/core": true
4
+ },
5
+ "title": "browse front",
6
+ "description": "The browsing app's own state in the page graph, never synced.",
7
+ "$defs": {
8
+ "commentBox": {
9
+ "component": true,
10
+ "type": "object",
11
+ "sync": "none",
12
+ "durable": "connection",
13
+ "description": "a reply composer open on a comment; its words are a synced draft, not page state",
14
+ "properties": {
15
+ "open": {
16
+ "type": "boolean",
17
+ "description": "the reply composer is open"
18
+ }
19
+ }
20
+ },
21
+ "Sidebar": {
22
+ "component": true,
23
+ "type": "object",
24
+ "sync": "none",
25
+ "durable": "connection",
26
+ "description": "the browse sidebar: sections and packages folded on this page; its query words live in the shared filter draft",
27
+ "properties": {
28
+ "closed": {
29
+ "type": "array",
30
+ "items": {
31
+ "type": "string"
32
+ },
33
+ "description": "section names or package eids the reader folded"
34
+ },
35
+ "hover": {
36
+ "type": "boolean",
37
+ "description": "a draggable entity is over the sidebar"
38
+ },
39
+ "open": {
40
+ "type": "boolean",
41
+ "description": "the sidebar is visible"
42
+ }
43
+ }
44
+ },
45
+ "Configuration": {
46
+ "component": true,
47
+ "type": "object",
48
+ "sync": "none",
49
+ "durable": "connection",
50
+ "description": "progress of a private configuration operation; never holds credential input",
51
+ "properties": {
52
+ "busy": {
53
+ "type": "boolean"
54
+ },
55
+ "message": {
56
+ "type": "string"
57
+ }
58
+ }
59
+ }
60
+ }
61
+ }