@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/log.js ADDED
@@ -0,0 +1,78 @@
1
+ // A transcript's bytes are read and decoded a chunk at a time. Reading an old
2
+ // log never decodes the whole file in one turn of the server's event loop.
3
+ import * as fs from "@yaks/file/io";
4
+ /** The byte after `lines` complete lines, without decoding the log. */ export let after = async (path, lines)=>{
5
+ if (!lines) return 0;
6
+ let f;
7
+ try {
8
+ f = await fs.open(path);
9
+ } catch {
10
+ return 0 // never written: there is nothing to skip
11
+ ;
12
+ }
13
+ try {
14
+ let buf = new Uint8Array(64 * 1024), at = 0, seen = 0;
15
+ for(let n = await f.read(buf); n; n = await f.read(buf)){
16
+ let text = buf.subarray(0, n);
17
+ for(let i = text.indexOf(10); i >= 0; i = text.indexOf(10, i + 1)){
18
+ if (++seen == lines) return at + i + 1;
19
+ }
20
+ at += n;
21
+ }
22
+ return at;
23
+ } finally{
24
+ f.close();
25
+ }
26
+ };
27
+ // Each read closes before returning: a cursor parked between pulls holds no
28
+ // descriptor, even when its caller stops following the transcript.
29
+ let sip = async (t)=>{
30
+ let f;
31
+ try {
32
+ f = await fs.open(t.path);
33
+ } catch {
34
+ return '' // never written: the log has said nothing yet
35
+ ;
36
+ }
37
+ try {
38
+ await f.seek(t.at, 0);
39
+ let buf = new Uint8Array(64 * 1024);
40
+ let n = await f.read(buf);
41
+ if (!n) return '';
42
+ t.at += n;
43
+ return t.dec.decode(buf.subarray(0, n), {
44
+ stream: true
45
+ });
46
+ } finally{
47
+ f.close();
48
+ }
49
+ };
50
+ /** Complete lines in bounded reads. A partial line and split UTF-8 character
51
+ * stay on the cursor; a final read also yields the unterminated last line. */ export let batches = async function*(t, final = false) {
52
+ for(;;){
53
+ let text = t.rest, end = false;
54
+ if (!text.includes('\n')) {
55
+ let more = t.stream ? await t.stream.read() : await sip(t);
56
+ end = t.stream ? more === undefined || t.stream.done : !more;
57
+ text += more ?? '';
58
+ }
59
+ let parts = text.split('\n');
60
+ let flush = end && (t.stream ? t.stream.done : final);
61
+ t.rest = flush ? '' : parts.pop() ?? '';
62
+ if (flush && parts.at(-1) === '') parts.pop();
63
+ let skip = Math.min(t.skip ?? 0, parts.length);
64
+ if (t.skip) t.skip -= skip;
65
+ if (parts.length > skip) yield parts.slice(skip);
66
+ if (end) return;
67
+ }
68
+ };
69
+ /** A log followed from its first line, with no file held between lines. */ export let records = async function*(path) {
70
+ let t = {
71
+ path,
72
+ at: 0,
73
+ rest: '',
74
+ dec: new TextDecoder()
75
+ };
76
+ for await (let lines of batches(t, true))yield* lines;
77
+ };
78
+ //# sourceMappingURL=log.js.map
package/log.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log.js","sources":["./log.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,2EAA2E;AAC3E,YAAY,6BAAkC;AAY9C,qEAAqE,GACrE,OAAO,IAAI,QAAQ,OAAO,MAAc;EACtC,IAAI,CAAC,OAAO,OAAO;EACnB,IAAI;EACJ,IAAI;IACF,IAAI,MAAM,GAAG,IAAI,CAAC;EACpB,EAAE,OAAM;IACN,OAAO,EAAE,0CAA0C;;EACrD;EACA,IAAI;IACF,IAAI,MAAM,IAAI,WAAW,KAAK,OAAO,KAAK,GAAG,OAAO;IACpD,IAAK,IAAI,IAAI,MAAM,EAAE,IAAI,CAAC,MAAM,GAAG,IAAI,MAAM,EAAE,IAAI,CAAC,KAAM;MACxD,IAAI,OAAO,IAAI,QAAQ,CAAC,GAAG;MAC3B,IAAK,IAAI,IAAI,KAAK,OAAO,CAAC,KAAK,KAAK,GAAG,IAAI,KAAK,OAAO,CAAC,IAAI,IAAI,GAAI;QAClE,IAAI,EAAE,QAAQ,OAAO,OAAO,KAAK,IAAI;MACvC;MACA,MAAM;IACR;IACA,OAAO;EACT,SAAU;IACR,EAAE,KA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AAI;IACtB,IAAI,MAAM,MAAM,GAAG,MAAM,MAAM,MAAM,KAAK,CAAC;IAC3C,IAAI,KAAK;EACX;AACF,EAAC;AAED,yEAAyE,GACzE,OAAO,IAAI,UAAU,gBAAiB,IAAY;EAChD,IAAI,IAAI;IAAE;IAAM,IAAI;IAAG,MAAM;IAAI,KAAK,IAAI;EAAc;EACxD,WAAW,IAAI,SAAS,QAAQ,GAAG,MAAO,OAAO;AACnD,EAAC"}
package/log.ts ADDED
@@ -0,0 +1,88 @@
1
+ // A transcript's bytes are read and decoded a chunk at a time. Reading an old
2
+ // log never decodes the whole file in one turn of the server's event loop.
3
+ import * as fs from '@yaks/file/io'
4
+ import type { Chunks } from './archive.ts'
5
+
6
+ type Cursor = {
7
+ path: string
8
+ at: number
9
+ rest: string
10
+ dec: TextDecoder
11
+ stream?: Chunks
12
+ skip?: number
13
+ }
14
+
15
+ /** The byte after `lines` complete lines, without decoding the log. */
16
+ export let after = async (path: string, lines: number): Promise<number> => {
17
+ if (!lines) return 0
18
+ let f
19
+ try {
20
+ f = await fs.open(path)
21
+ } catch {
22
+ return 0 // never written: there is nothing to skip
23
+ }
24
+ try {
25
+ let buf = new Uint8Array(64 * 1024), at = 0, seen = 0
26
+ for (let n = await f.read(buf); n; n = await f.read(buf)) {
27
+ let text = buf.subarray(0, n)
28
+ for (let i = text.indexOf(10); i >= 0; i = text.indexOf(10, i + 1)) {
29
+ if (++seen == lines) return at + i + 1
30
+ }
31
+ at += n
32
+ }
33
+ return at
34
+ } finally {
35
+ f.close()
36
+ }
37
+ }
38
+
39
+ // Each read closes before returning: a cursor parked between pulls holds no
40
+ // descriptor, even when its caller stops following the transcript.
41
+ let sip = async (t: Cursor): Promise<string> => {
42
+ let f
43
+ try {
44
+ f = await fs.open(t.path)
45
+ } catch {
46
+ return '' // never written: the log has said nothing yet
47
+ }
48
+ try {
49
+ await f.seek(t.at, 0)
50
+ let buf = new Uint8Array(64 * 1024)
51
+ let n = await f.read(buf)
52
+ if (!n) return ''
53
+ t.at += n
54
+ return t.dec.decode(buf.subarray(0, n), { stream: true })
55
+ } finally {
56
+ f.close()
57
+ }
58
+ }
59
+
60
+ /** Complete lines in bounded reads. A partial line and split UTF-8 character
61
+ * stay on the cursor; a final read also yields the unterminated last line. */
62
+ export let batches = async function* (
63
+ t: Cursor,
64
+ final = false,
65
+ ): AsyncGenerator<string[]> {
66
+ for (;;) {
67
+ let text = t.rest, end = false
68
+ if (!text.includes('\n')) {
69
+ let more = t.stream ? await t.stream.read() : await sip(t)
70
+ end = t.stream ? more === undefined || t.stream.done : !more
71
+ text += more ?? ''
72
+ }
73
+ let parts = text.split('\n')
74
+ let flush = end && (t.stream ? t.stream.done : final)
75
+ t.rest = flush ? '' : parts.pop() ?? ''
76
+ if (flush && parts.at(-1) === '') parts.pop()
77
+ let skip = Math.min(t.skip ?? 0, parts.length)
78
+ if (t.skip) t.skip -= skip
79
+ if (parts.length > skip) yield parts.slice(skip)
80
+ if (end) return
81
+ }
82
+ }
83
+
84
+ /** A log followed from its first line, with no file held between lines. */
85
+ export let records = async function* (path: string): AsyncGenerator<string> {
86
+ let t = { path, at: 0, rest: '', dec: new TextDecoder() }
87
+ for await (let lines of batches(t, true)) yield* lines
88
+ }
package/mod.js ADDED
@@ -0,0 +1,107 @@
1
+ /**
2
+ * @yaks/session — a session is a transcript: the entries that make it up, the
3
+ * lock it holds, and the runner that reacts to its newest entry. The session
4
+ * component vocabulary for a {@link https://jsr.io/@yaks/graph | @yaks/graph}.
5
+ *
6
+ * No running process is implied. A `session` is identity only; what it is doing
7
+ * is read off its entries ({@link statusOf}, and the same rule expressed in SQL
8
+ * for the derived property, {@link sessionDerived}) and never stored. An
9
+ * `entry` is one line of the transcript, `{session, seq}`, and the component
10
+ * beside it is what makes it one kind rather than another:
11
+ *
12
+ * - `content{body}` — prose. Alone it is an input, an instruction from a
13
+ * person or a system; with an `output{source}` beside it (the ask it answers)
14
+ * it is what a model returned. A `result`, `refusal` or `exception` carries its
15
+ * prose the same way.
16
+ * - `ask{to, served, through}` — the runner asked a model, from the prefix
17
+ * ending at `through`; `served` is the model that answered, where the reply
18
+ * names another (an alias answered by a release). What the provider keeps about it is the provider's own component
19
+ * on the same entry (`@yaks/openai` declares `openai{response_id}`).
20
+ * - `call{to, id, args, source}` — a tool the model asked for, from that ask;
21
+ * `result{call}` is what the tool returned.
22
+ * - `using{provider, model, effort}` — set or switched on an input, recorded
23
+ * as served on an ask.
24
+ * - `stop`, `refusal{code}`, `exception` — a stop marker; a
25
+ * deliberate no; what was thrown while producing the entry.
26
+ *
27
+ * `fork{from}` on a session continues another transcript from one of its
28
+ * entries: the parent's entries up to it are the fork's prefix.
29
+ * `spawned{parent, call}` records delegation independently of that prefix.
30
+ * {@link sessionTools} exposes fork/spawn/wait; the runner delivers a child's
31
+ * final output to its parent's queue, idempotently.
32
+ *
33
+ * ## The runner
34
+ * {@link react} is one step: read the newest entry, do the one thing it calls
35
+ * for, append what happened. {@link settle} loops it under the transcript's
36
+ * lease, and {@link running} is the `session_run` handler any @yaks/effects
37
+ * worker runs it by. It is handed a @yaks/model `Model` and a table of tools
38
+ * and imports no platform API.
39
+ *
40
+ * ## A lock is a lease, not a patch
41
+ * A `claim{session}` is a session's lock, stored on the entity it locks.
42
+ * Writing one over somebody else's fails the whole batch loudly
43
+ * ({@link Bounced}) unless the host uses a guarded {@link handoffClaim}.
44
+ * The same session re-claiming is a
45
+ * no-op refresh, and a release is unguarded, because releasing is how a lock is
46
+ * handed over. The collision is recorded as a `conflict` row on the `audit`
47
+ * phase, after the rollback. `claim.session` is declared `death: 'release'`:
48
+ * delete a session's entity and its locks go while the documents live —
49
+ * declared in {@link sessionDoc}, carried out by @yaks/graph's cascade.
50
+ * {@link reapLeases} frees every lock whose holder is not a session in the
51
+ * graph; the `@yaks/session/service` duty runs it when it starts.
52
+ *
53
+ * ```ts
54
+ * import { loadVocab } from '@yaks/vocab'
55
+ * import { graph } from '@yaks/graph'
56
+ * import { ram } from '@yaks/ram'
57
+ * import { contextDoc } from '@yaks/context'
58
+ * import { modelDoc } from '@yaks/model'
59
+ * import { toolsDoc } from '@yaks/tools'
60
+ * import { sessionDoc, sessions } from '@yaks/session'
61
+ *
62
+ * // a transcript uses four packages' components, each declared once
63
+ * let vocab = loadVocab([sessionDoc, toolsDoc, contextDoc, modelDoc])
64
+ * let g = graph({ storage: ram(vocab), vocab, plugins: [sessions()] })
65
+ * ```
66
+ *
67
+ * @module
68
+ */ export * from "./comp.js";
69
+ export * from "./bounce.js";
70
+ export * from "./lease.js";
71
+ export * from "./audit.js";
72
+ export * from "./reap.js";
73
+ export * from "./plugin.js";
74
+ export * from "./native.js";
75
+ export * from "./status.js";
76
+ export * from "./told.js";
77
+ export * from "./cost.js";
78
+ export * from "./who.js";
79
+ export * from "./naming.js";
80
+ export * from "./react.js";
81
+ export * from "./run.js";
82
+ export * from "./wake.js";
83
+ export { knocks, operatorOf, reported, watchers, writers } from "./watch.js";
84
+ export { start, starting } from "./start.js";
85
+ export { RECALL, recall } from "./recall.js";
86
+ export { inputOf, intake, take, taskSession } from "./intake.js";
87
+ export { admitNext } from "./admission.js";
88
+ export { kindOf, seqOf } from "./state.js";
89
+ export * from "./providers.js";
90
+ export * from "./lines.js";
91
+ export * from "./readers.js";
92
+ export * from "./children.js";
93
+ export { forkAnswer, forkProgress, forkReceipt } from "./fork.js";
94
+ export { CONTEXT, tokens as estimateTokens } from "./compact.js";
95
+ export * from "./answer.js";
96
+ export { calledIn, noticeParent, raiseNotice } from "./child-notice.js";
97
+ export { appendEntry } from "./append.js";
98
+ export { imported, pieced } from "./imported.js";
99
+ export { grafted } from "./graft.js";
100
+ export { handoff, handoffOf, touched } from "./handoff.js";
101
+ export * from "./timing.js";
102
+ export * from "./window.js";
103
+ export * from "./reach.js";
104
+ export * from "./cache.js";
105
+ export { source } from "./source.js";
106
+ export * from "./asks.js";
107
+ //# sourceMappingURL=mod.js.map
package/mod.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.js","sources":["./mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmEC,GAED,0BAAyB;AACzB,4BAA2B;AAC3B,2BAA0B;AAC1B,2BAA0B;AAC1B,0BAAyB;AACzB,4BAA2B;AAC3B,4BAA2B;AAC3B,4BAA2B;AAC3B,0BAAyB;AACzB,0BAAyB;AACzB,yBAAwB;AACxB,4BAA2B;AAC3B,2BAA0B;AAC1B,yBAAwB;AACxB,0BAAyB;AACzB,SAAS,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,qBAAoB;AAC5E,SAAuB,KAAK,EAAiB,QAAQ,qBAAoB;AACzE,SAAsB,MAAM,EAAE,MAAM,sBAAqC;AACzE,SAAS,OAAO,EAAe,MAAM,EAAE,IAAI,EAAE,WAAW,sBAAqB;AAC7E,SAAS,SAAS,yBAAwB;AAC1C,SAAS,MAAM,EAAE,KAAK,qBAAoB;AAC1C,+BAA8B;AAC9B,2BAA0B;AAC1B,6BAA4B;AAE5B,8BAA6B;AAC7B,SAAS,UAAU,EAAE,YAAY,EAAE,WAAW,oBAAmB;AACjE,SAAS,OAAO,EAAE,UAAU,cAAc,uBAAsB;AAChE,4BAA2B;AAC3B,SAAS,QAAQ,EAAE,YAAY,EAAE,WAAW,4BAA2B;AAEvE,SAAS,WAAW,sBAAqB;AACzC,SAAS,QAAQ,EAAa,MAAM,wBAAuB;AAC3D,SAAS,OAAO,qBAAoB;AACpC,SAAS,OAAO,EAAE,SAAS,EAAE,OAAO,uBAAsB;AAC1D,4BAA2B;AAE3B,4BAA2B;AAC3B,2BAA0B;AAE1B,2BAA0B;AAE1B,SAAyB,MAAM,sBAAqB;AACpD,0BAAyB"}
package/mod.ts ADDED
@@ -0,0 +1,113 @@
1
+ /**
2
+ * @yaks/session — a session is a transcript: the entries that make it up, the
3
+ * lock it holds, and the runner that reacts to its newest entry. The session
4
+ * component vocabulary for a {@link https://jsr.io/@yaks/graph | @yaks/graph}.
5
+ *
6
+ * No running process is implied. A `session` is identity only; what it is doing
7
+ * is read off its entries ({@link statusOf}, and the same rule expressed in SQL
8
+ * for the derived property, {@link sessionDerived}) and never stored. An
9
+ * `entry` is one line of the transcript, `{session, seq}`, and the component
10
+ * beside it is what makes it one kind rather than another:
11
+ *
12
+ * - `content{body}` — prose. Alone it is an input, an instruction from a
13
+ * person or a system; with an `output{source}` beside it (the ask it answers)
14
+ * it is what a model returned. A `result`, `refusal` or `exception` carries its
15
+ * prose the same way.
16
+ * - `ask{to, served, through}` — the runner asked a model, from the prefix
17
+ * ending at `through`; `served` is the model that answered, where the reply
18
+ * names another (an alias answered by a release). What the provider keeps about it is the provider's own component
19
+ * on the same entry (`@yaks/openai` declares `openai{response_id}`).
20
+ * - `call{to, id, args, source}` — a tool the model asked for, from that ask;
21
+ * `result{call}` is what the tool returned.
22
+ * - `using{provider, model, effort}` — set or switched on an input, recorded
23
+ * as served on an ask.
24
+ * - `stop`, `refusal{code}`, `exception` — a stop marker; a
25
+ * deliberate no; what was thrown while producing the entry.
26
+ *
27
+ * `fork{from}` on a session continues another transcript from one of its
28
+ * entries: the parent's entries up to it are the fork's prefix.
29
+ * `spawned{parent, call}` records delegation independently of that prefix.
30
+ * {@link sessionTools} exposes fork/spawn/wait; the runner delivers a child's
31
+ * final output to its parent's queue, idempotently.
32
+ *
33
+ * ## The runner
34
+ * {@link react} is one step: read the newest entry, do the one thing it calls
35
+ * for, append what happened. {@link settle} loops it under the transcript's
36
+ * lease, and {@link running} is the `session_run` handler any @yaks/effects
37
+ * worker runs it by. It is handed a @yaks/model `Model` and a table of tools
38
+ * and imports no platform API.
39
+ *
40
+ * ## A lock is a lease, not a patch
41
+ * A `claim{session}` is a session's lock, stored on the entity it locks.
42
+ * Writing one over somebody else's fails the whole batch loudly
43
+ * ({@link Bounced}) unless the host uses a guarded {@link handoffClaim}.
44
+ * The same session re-claiming is a
45
+ * no-op refresh, and a release is unguarded, because releasing is how a lock is
46
+ * handed over. The collision is recorded as a `conflict` row on the `audit`
47
+ * phase, after the rollback. `claim.session` is declared `death: 'release'`:
48
+ * delete a session's entity and its locks go while the documents live —
49
+ * declared in {@link sessionDoc}, carried out by @yaks/graph's cascade.
50
+ * {@link reapLeases} frees every lock whose holder is not a session in the
51
+ * graph; the `@yaks/session/service` duty runs it when it starts.
52
+ *
53
+ * ```ts
54
+ * import { loadVocab } from '@yaks/vocab'
55
+ * import { graph } from '@yaks/graph'
56
+ * import { ram } from '@yaks/ram'
57
+ * import { contextDoc } from '@yaks/context'
58
+ * import { modelDoc } from '@yaks/model'
59
+ * import { toolsDoc } from '@yaks/tools'
60
+ * import { sessionDoc, sessions } from '@yaks/session'
61
+ *
62
+ * // a transcript uses four packages' components, each declared once
63
+ * let vocab = loadVocab([sessionDoc, toolsDoc, contextDoc, modelDoc])
64
+ * let g = graph({ storage: ram(vocab), vocab, plugins: [sessions()] })
65
+ * ```
66
+ *
67
+ * @module
68
+ */
69
+
70
+ export * from './comp.js'
71
+ export * from './bounce.js'
72
+ export * from './lease.js'
73
+ export * from './audit.js'
74
+ export * from './reap.js'
75
+ export * from './plugin.js'
76
+ export * from './native.js'
77
+ export * from './status.js'
78
+ export * from './told.js'
79
+ export * from './cost.js'
80
+ export * from './who.js'
81
+ export * from './naming.js'
82
+ export * from './react.js'
83
+ export * from './run.js'
84
+ export * from './wake.js'
85
+ export { knocks, operatorOf, reported, watchers, writers } from './watch.js'
86
+ export { type Opening, start, type Starting, starting } from './start.js'
87
+ export { type Beside, RECALL, recall, type Recalling } from './recall.js'
88
+ export { inputOf, type Intake, intake, take, taskSession } from './intake.js'
89
+ export { admitNext } from './admission.js'
90
+ export { kindOf, seqOf } from './state.js'
91
+ export * from './providers.js'
92
+ export * from './lines.js'
93
+ export * from './readers.js'
94
+
95
+ export * from './children.js'
96
+ export { forkAnswer, forkProgress, forkReceipt } from './fork.js'
97
+ export { CONTEXT, tokens as estimateTokens } from './compact.js'
98
+ export * from './answer.js'
99
+ export { calledIn, noticeParent, raiseNotice } from './child-notice.js'
100
+
101
+ export { appendEntry } from './append.js'
102
+ export { imported, type Open, pieced } from './imported.js'
103
+ export { grafted } from './graft.js'
104
+ export { handoff, handoffOf, touched } from './handoff.js'
105
+ export * from './timing.js'
106
+
107
+ export * from './window.js'
108
+ export * from './reach.js'
109
+
110
+ export * from './cache.js'
111
+
112
+ export { type InputText, source } from './source.js'
113
+ export * from './asks.js'
package/name.js ADDED
@@ -0,0 +1,51 @@
1
+ // What a session is called wherever one is named: by what it works on. Its
2
+ // handle (`#5b8062c912`) says nothing to a person, and the command that
3
+ // launched it (`claude -p --session-id … --append-system-prompt …`) carries a
4
+ // whole persona and brief, so neither is ever its name.
5
+ //
6
+ // The name is found in one place, here, from the session's own row and three
7
+ // bounded reads (`asks`): the task it holds, the task it worked (its title read
8
+ // across the `worked` edge), and its opening entries. Every door draws it through the session's portable `Title`
9
+ // (./lines.ts) or its inspector tile (./inspect.ts); naming a session never
10
+ // loads its transcript.
11
+ import { SESSION } from "./comp.js";
12
+ import { ENTRY } from "./native.js";
13
+ /** The bounded reads a session's name is found from, by what {@link Read}
14
+ * holds each answer under. */ export let asks = (eid)=>({
15
+ claim: `.claim.session=${eid}&.fields=doc.title&.limit=1`,
16
+ work: `.worked&.edge.from=${eid}&.fields=edge.to.doc.title&.limit=1`,
17
+ first: `.${ENTRY}.session=${eid}&.order=${ENTRY}.seq&.limit=12` + '&?content&?output&?notice&?prompt&?call&?result&?reasoning&?stop' + '&?exception&?refusal&?ask&?interrupted&?using&?lines'
18
+ });
19
+ /** How long a name drawn from words runs before it is cut. */ export let LONG = 180;
20
+ let str = (b, comp, prop)=>{
21
+ let v = b?.[comp]?.[prop];
22
+ return typeof v == 'string' ? v : '';
23
+ };
24
+ let cut = (text, n)=>text.length > n ? text.slice(0, n - 1).trimEnd() + '…' : text;
25
+ // An entry that is somebody's prose, rather than a model's reply, a tool's
26
+ // call or answer, or the bookkeeping of a turn.
27
+ let prose = (b)=>b.content && !b.output && !b.call && !b.result && !b.reasoning && !b.prompt && !b.stop && !b.ask && !b.exception && !b.refusal && !b.interrupted;
28
+ /** What a session's opening words are: the first a person said, else the
29
+ * instruction it was started with (a child's starts as a notice). */ export let firstWords = (read)=>{
30
+ let said = (read.first ?? []).filter(prose);
31
+ return str(said.find((b)=>!b.notice) ?? said[0], 'content', 'body');
32
+ };
33
+ /**
34
+ * What a session is called: the title of the task it holds or worked, its own
35
+ * title, its opening words or brief cut to {@link LONG}, or, for the
36
+ * owner's own conversation, `Personal conversation`. Empty when it has none of
37
+ * these: the caller names it by its id.
38
+ *
39
+ * ```ts
40
+ * import { sessionName } from './name.ts'
41
+ * import { equal } from '@yaks/testing'
42
+ *
43
+ * let s = { entity: { eid: 's1' }, session: { id: 's1' } }
44
+ * let task = { entity: { eid: 't1' }, doc: { title: 'Fix the cake' } }
45
+ * equal(sessionName(s, { claim: [task] }), 'Fix the cake')
46
+ * let words = { entity: { eid: 'e1' }, content: { body: 'hello there' } }
47
+ * equal(sessionName(s, { first: [words] }), 'hello there')
48
+ * equal(sessionName(s, {}), '')
49
+ * ```
50
+ */ export let sessionName = (e, read)=>str(read.claim?.[0], 'doc', 'title') || str(read.work?.find((b)=>b.doc), 'doc', 'title') || str(e, 'doc', 'title') || cut((firstWords(read) || str(e, 'brief', 'text')).trim().replace(/\s+/g, ' '), LONG) || (e[SESSION]?.operator ? 'Personal conversation' : '');
51
+ //# sourceMappingURL=name.js.map
package/name.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"name.js","sources":["./name.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,wEAAwE;AACxE,8EAA8E;AAC9E,wDAAwD;AACxD,EAAE;AACF,6EAA6E;AAC7E,gFAAgF;AAChF,iHAAiH;AACjH,4EAA4E;AAC5E,wBAAwB;AAGxB,SAAS,OAAO,oBAAmB;AACnC,SAAS,KAAK,sBAAqB;AAQnC;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O,YAC5B,IAAI,KAAK,IAAI,EAAE,KAAK,CAAC,IAAM,EAAE,GAAG,GAAG,OAAO,YAC1C,IAAI,GAAG,OAAO,YACd,IACE,CAAC,WAAW,SAAS,IAAI,GAAG,SAAS,OAAO,EAAE,IAAI,GAAG,OAAO,CAAC,QAAQ,MACrE,SAEF,CAAC,AAAC,CAAC,CAAC,QAAQ,EAAuB,WAAW,0BAA0B,EAAE,EAAC"}
package/name.ts ADDED
@@ -0,0 +1,84 @@
1
+ // What a session is called wherever one is named: by what it works on. Its
2
+ // handle (`#5b8062c912`) says nothing to a person, and the command that
3
+ // launched it (`claude -p --session-id … --append-system-prompt …`) carries a
4
+ // whole persona and brief, so neither is ever its name.
5
+ //
6
+ // The name is found in one place, here, from the session's own row and three
7
+ // bounded reads (`asks`): the task it holds, the task it worked (its title read
8
+ // across the `worked` edge), and its opening entries. Every door draws it through the session's portable `Title`
9
+ // (./lines.ts) or its inspector tile (./inspect.ts); naming a session never
10
+ // loads its transcript.
11
+
12
+ import type { Bundle } from 'jsr:@yaks/graph@0.2.36'
13
+ import { SESSION } from './comp.js'
14
+ import { ENTRY } from './native.js'
15
+
16
+ /** The rows a session's name is found from, each answering its query in
17
+ * {@link asks}: the task it holds, the `worked` edge and the task it worked,
18
+ * and its opening entries. Any may be missing; the name is found from what is
19
+ * there. */
20
+ export type Read = { claim?: Bundle[]; work?: Bundle[]; first?: Bundle[] }
21
+
22
+ /** The bounded reads a session's name is found from, by what {@link Read}
23
+ * holds each answer under. */
24
+ export let asks = (eid: string): Record<keyof Read, string> => ({
25
+ claim: `.claim.session=${eid}&.fields=doc.title&.limit=1`,
26
+ work: `.worked&.edge.from=${eid}&.fields=edge.to.doc.title&.limit=1`,
27
+ first: `.${ENTRY}.session=${eid}&.order=${ENTRY}.seq&.limit=12` +
28
+ '&?content&?output&?notice&?prompt&?call&?result&?reasoning&?stop' +
29
+ '&?exception&?refusal&?ask&?interrupted&?using&?lines',
30
+ })
31
+
32
+ /** How long a name drawn from words runs before it is cut. */
33
+ export let LONG = 180
34
+
35
+ type Comp = Record<string, unknown>
36
+ let str = (b: Bundle | undefined, comp: string, prop: string): string => {
37
+ let v = (b?.[comp] as Comp | undefined)?.[prop]
38
+ return typeof v == 'string' ? v : ''
39
+ }
40
+
41
+ let cut = (text: string, n: number) =>
42
+ text.length > n ? text.slice(0, n - 1).trimEnd() + '…' : text
43
+
44
+ // An entry that is somebody's prose, rather than a model's reply, a tool's
45
+ // call or answer, or the bookkeeping of a turn.
46
+ let prose = (b: Bundle) =>
47
+ b.content && !b.output && !b.call && !b.result && !b.reasoning &&
48
+ !b.prompt && !b.stop && !b.ask && !b.exception && !b.refusal &&
49
+ !b.interrupted
50
+
51
+ /** What a session's opening words are: the first a person said, else the
52
+ * instruction it was started with (a child's starts as a notice). */
53
+ export let firstWords = (read: Read): string => {
54
+ let said = (read.first ?? []).filter(prose)
55
+ return str(said.find((b) => !b.notice) ?? said[0], 'content', 'body')
56
+ }
57
+
58
+ /**
59
+ * What a session is called: the title of the task it holds or worked, its own
60
+ * title, its opening words or brief cut to {@link LONG}, or, for the
61
+ * owner's own conversation, `Personal conversation`. Empty when it has none of
62
+ * these: the caller names it by its id.
63
+ *
64
+ * ```ts
65
+ * import { sessionName } from './name.ts'
66
+ * import { equal } from '@yaks/testing'
67
+ *
68
+ * let s = { entity: { eid: 's1' }, session: { id: 's1' } }
69
+ * let task = { entity: { eid: 't1' }, doc: { title: 'Fix the cake' } }
70
+ * equal(sessionName(s, { claim: [task] }), 'Fix the cake')
71
+ * let words = { entity: { eid: 'e1' }, content: { body: 'hello there' } }
72
+ * equal(sessionName(s, { first: [words] }), 'hello there')
73
+ * equal(sessionName(s, {}), '')
74
+ * ```
75
+ */
76
+ export let sessionName = (e: Bundle, read: Read): string =>
77
+ str(read.claim?.[0], 'doc', 'title') ||
78
+ str(read.work?.find((b) => b.doc), 'doc', 'title') ||
79
+ str(e, 'doc', 'title') ||
80
+ cut(
81
+ (firstWords(read) || str(e, 'brief', 'text')).trim().replace(/\s+/g, ' '),
82
+ LONG,
83
+ ) ||
84
+ ((e[SESSION] as Comp | undefined)?.operator ? 'Personal conversation' : '')
package/naming.js ADDED
@@ -0,0 +1,96 @@
1
+ // The native rules: what a batch may say about a transcript, checked inside the
2
+ // transaction before anything moves.
3
+ //
4
+ // A `fork.from` names an entry that exists. A `using` names a provider and a
5
+ // model that exist. Both are references, so the vocabulary already rejects a
6
+ // dangling id at the engine on SQLite; this hook explains why in the error
7
+ // message, and works on a store with no foreign keys (@yaks/ram, a browser
8
+ // tab). A target minted in the same batch counts: the check is against the
9
+ // graph as the batch will leave it.
10
+ import { line } from "@yaks/query";
11
+ import { attemptState } from "./attempt.js";
12
+ import { after, over } from "@yaks/fp";
13
+ import { MODEL, PROVIDER } from "@yaks/model/vocab";
14
+ import { ENTRY, FORK, USING } from "./native.js";
15
+ /** A reference in one of this package's components named an entity of the
16
+ * wrong kind. */ export class Unnamed extends Error {
17
+ comp;
18
+ prop;
19
+ eid;
20
+ constructor(comp, prop, eid){
21
+ super(`${comp}.${prop} names ${eid}, which is not a ${prop}`), this.comp = comp, this.prop = prop, this.eid = eid;
22
+ this.name = 'Unnamed';
23
+ }
24
+ }
25
+ let ref = (b, comp, prop)=>{
26
+ let v = b[comp]?.[prop];
27
+ return v == null ? undefined : String(v);
28
+ };
29
+ let checks = (b)=>{
30
+ let out = [];
31
+ let from = ref(b, FORK, 'from');
32
+ if (from) out.push([
33
+ FORK,
34
+ 'from',
35
+ from,
36
+ ENTRY
37
+ ]);
38
+ let parent = ref(b, 'spawned', 'parent');
39
+ if (parent) out.push([
40
+ 'spawned',
41
+ 'parent',
42
+ parent,
43
+ 'session'
44
+ ]);
45
+ let call = ref(b, 'spawned', 'call');
46
+ if (call) out.push([
47
+ 'spawned',
48
+ 'call',
49
+ call,
50
+ ENTRY
51
+ ]);
52
+ let provider = ref(b, USING, PROVIDER);
53
+ if (provider) out.push([
54
+ USING,
55
+ PROVIDER,
56
+ provider,
57
+ PROVIDER
58
+ ]);
59
+ let model = ref(b, USING, MODEL);
60
+ if (model) out.push([
61
+ USING,
62
+ MODEL,
63
+ model,
64
+ MODEL
65
+ ]);
66
+ return out;
67
+ };
68
+ /** The precondition: every `fork.from` is an entry; every `using.provider` is a
69
+ * provider and `using.model` a model — in the graph, or in this batch. */ const names = (bundles, tx)=>{
70
+ let all = bundles.flatMap(checks);
71
+ if (!all.length) return bundles;
72
+ let inBatch = (eid, comp)=>bundles.some((b)=>b.entity.eid == eid && comp in b);
73
+ let asked = all.filter(([, , eid, comp])=>!inBatch(eid, comp));
74
+ if (!asked.length) return bundles;
75
+ return after(over(asked, ([comp, prop, eid, must])=>after(tx.read(line`.entity.eid=${eid}&.${must}&.fields=entity.eid`), (found)=>{
76
+ if (!found.length) throw new Unnamed(comp, prop, eid);
77
+ })), ()=>bundles);
78
+ };
79
+ /** Fork boundaries cannot include mutable, unfinished provider output. */ export const naming = (bundles, tx, err)=>after(over(bundles.filter((b)=>ref(b, FORK, 'from')), (b)=>{
80
+ const from = ref(b, FORK, 'from');
81
+ return after(tx.get([
82
+ from
83
+ ], [
84
+ ENTRY
85
+ ]), (rows)=>{
86
+ const anchor = bundles.find((v)=>v.entity.eid == from && v.entry) ?? rows[0];
87
+ const entry = anchor?.entry;
88
+ if (!entry) return;
89
+ return after(tx.read(line`.entry.session=${String(entry.session)}&.attempt&?interrupted`), (entries)=>{
90
+ if (entries.some((v)=>attemptState(v) == 'inflight' && Number(v.entry?.seq) <= Number(entry.seq))) {
91
+ throw new Error('Cannot fork through an in-flight provider attempt');
92
+ }
93
+ });
94
+ });
95
+ }), ()=>names(bundles, tx, err));
96
+ //# sourceMappingURL=naming.js.map
package/naming.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"naming.js","sources":["./naming.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,qCAAqC;AACrC,EAAE;AACF,6EAA6E;AAC7E,6EAA6E;AAC7E,2EAA2E;AAC3E,2EAA2E;AA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