@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/handoff.ts ADDED
@@ -0,0 +1,147 @@
1
+ // What a model is told when it takes over a conversation another harness
2
+ // (Claude Code, Codex, Grok, Antigravity) ran: what it ran on, that the tool
3
+ // calls in it were that harness's own, and the files it worked on. A model
4
+ // whose window cannot hold the conversation reads it summarized, as any long
5
+ // transcript is (./compact.ts).
6
+
7
+ import type { Bundle, Comp, Eid, Graph } from 'jsr:@yaks/graph@0.2.36'
8
+ import { line, sub } from '@yaks/query'
9
+ import { ordered } from './state.js'
10
+
11
+ let comp = (b: Bundle | undefined, name: string) =>
12
+ b?.[name] as Comp | undefined
13
+
14
+ // The argument names a file path goes by in the tools of Claude Code, Codex,
15
+ // Grok, Antigravity and the harness.
16
+ let PATHS = [
17
+ 'file_path',
18
+ 'path',
19
+ 'filePath',
20
+ 'notebook_path',
21
+ 'AbsolutePath',
22
+ 'TargetFile',
23
+ 'target_file',
24
+ ]
25
+
26
+ // The files a patch names (`*** Update File: a.ts`), as Codex's apply_patch
27
+ // writes them.
28
+ let patched = (text: string) =>
29
+ [...text.matchAll(/^\*\*\* (?:Add|Update|Delete) File: (.+)$/gm)]
30
+ .map((m) => m[1].trim())
31
+
32
+ /** The files a transcript's calls named, newest first, each once. */
33
+ export let touched = (entries: Bundle[]): string[] => {
34
+ let files = ordered(entries).flatMap((b) => {
35
+ let args = comp(b, 'call')?.args as Record<string, unknown> | undefined
36
+ if (!args) return []
37
+ return [
38
+ ...PATHS.map((k) => args[k]).filter((v): v is string =>
39
+ typeof v == 'string' && !!v
40
+ ),
41
+ ...Object.values(args).flatMap((v) =>
42
+ typeof v == 'string' ? patched(v) : []
43
+ ),
44
+ ]
45
+ })
46
+ return [...new Set(files.toReversed())]
47
+ }
48
+
49
+ /**
50
+ * The note a session gets when another model takes over its conversation
51
+ * from another harness: what the conversation ran on so far, by the names
52
+ * `names` gives the provider and model rows its newest `using` or ask names,
53
+ * and the files its calls named, at most `limit`.
54
+ *
55
+ * ```ts
56
+ * import { handoff } from './handoff.ts'
57
+ * import { assertEquals } from '@std/assert'
58
+ *
59
+ * let entries = [
60
+ * { entity: { eid: 'u' }, entry: { session: 's', seq: 1 }, using: { provider: 'p' } },
61
+ * { entity: { eid: 'c' }, entry: { session: 's', seq: 2 },
62
+ * call: { name: 'Edit', args: { file_path: '/w/a.ts' } } },
63
+ * ]
64
+ * assertEquals(handoff(entries, new Map([['p', 'claude']])),
65
+ * 'Until here this conversation ran on claude, and another model takes ' +
66
+ * 'it over now. The tool calls above were made with that harness\'s own ' +
67
+ * 'tools, and their results are as it saw them; call your own tools from ' +
68
+ * 'here on.\n\nFiles it worked on, newest first:\n- /w/a.ts')
69
+ * ```
70
+ */
71
+ export let handoff = (
72
+ entries: Bundle[],
73
+ names: Map<Eid, string>,
74
+ limit = 40,
75
+ ): string => {
76
+ let newest = ordered(entries).toReversed()
77
+ let using = newest.map((b) => comp(b, 'using')).find(Boolean)
78
+ let model = using?.model ??
79
+ newest.map((b) => comp(b, 'ask')?.to).find(Boolean)
80
+ let ran = [using?.provider, model]
81
+ .map((eid) => eid && names.get(String(eid)))
82
+ .filter(Boolean).join(' ')
83
+ let files = touched(entries)
84
+ return [
85
+ `Until here this conversation ran ${ran ? `on ${ran}` : 'elsewhere'}, ` +
86
+ 'and another model takes it over now. The tool calls above were made ' +
87
+ "with that harness's own tools, and their results are as it saw them; " +
88
+ 'call your own tools from here on.',
89
+ ...files.length
90
+ ? [
91
+ 'Files it worked on, newest first:\n' +
92
+ files.slice(0, limit).map((f) => `- ${f}`).join('\n') +
93
+ (files.length > limit ? `\n- and ${files.length - limit} more` : ''),
94
+ ]
95
+ : [],
96
+ ].join('\n\n')
97
+ }
98
+
99
+ /** The note for `session` ({@link handoff}) where another harness ran its
100
+ * conversation so far: its newest model selection or request was read from
101
+ * that harness's file (`lines{file, start}`), not asked here. Nothing where
102
+ * this harness asked it last, or nothing asked it yet. */
103
+ export let handoffOf = async (
104
+ g: Graph,
105
+ session: Eid,
106
+ ): Promise<string | undefined> => {
107
+ let own = line`.entry.session=${session}`
108
+ let [last] = await g.read(
109
+ line`${
110
+ sub(own)
111
+ }&(.using|.ask)&.order=-entry.seq&.limit=1&.fields=entry.seq,lines.file`,
112
+ )
113
+ if (!comp(last, 'lines')?.file) return undefined
114
+ let [calls, said] = await Promise.all([
115
+ g.read(line`${sub(own)}&.call&.fields=entry.seq,call.args`),
116
+ g.read(
117
+ line`${
118
+ sub(own)
119
+ }&(.using|.ask)&.order=-entry.seq&.limit=8&.fields=entry.seq,using.provider,using.model,ask.to`,
120
+ ),
121
+ ])
122
+ return handoff([...calls, ...said], await namesOf(g, said))
123
+ }
124
+
125
+ /** The names of the providers and models entries' `using` and `ask` name,
126
+ * by their rows' eids: what {@link handoff} says a conversation ran on. */
127
+ export let namesOf = async (
128
+ g: Graph,
129
+ entries: Bundle[],
130
+ ): Promise<Map<Eid, string>> => {
131
+ let named = [
132
+ ...new Set(
133
+ entries.flatMap((b) => [
134
+ comp(b, 'using')?.provider,
135
+ comp(b, 'using')?.model,
136
+ comp(b, 'ask')?.to,
137
+ ]).filter((v): v is string => typeof v == 'string'),
138
+ ),
139
+ ]
140
+ let rows = named.length ? await g.get(named) : []
141
+ return new Map(
142
+ rows.flatMap((r) => {
143
+ let name = comp(r, 'provider')?.name ?? comp(r, 'model')?.name
144
+ return typeof name == 'string' ? [[r.entity.eid, name] as const] : []
145
+ }),
146
+ )
147
+ }
package/help.js ADDED
@@ -0,0 +1,432 @@
1
+ // A project's helper: the run that takes what waits for its operator, so the
2
+ // operator's own session, with its whole context, is not woken for it.
3
+ //
4
+ // ./routine.ts marks a knock `routine{project}` in the write that leaves it.
5
+ // `session_help` runs after that commit and starts the helper: one session
6
+ // wearing the project's `helper{persona}`, marked `helping{project}`, whose
7
+ // first input is every routine knock waiting, each said whole as a listener
8
+ // would say it and marked `notified` in the same write. That input carries
9
+ // `using`, so the run is started the way any is: by whatever answers a
10
+ // `using` (@yaks/spawn for a command-line provider).
11
+ //
12
+ // One helper is at work at a time, and it takes everything waiting, so a
13
+ // storm of bugs is one helper's batch. Knocks that come while it works wait
14
+ // for its `exit`, which asks again, and the helper is over from then on, so
15
+ // nothing it was told of wakes it again. Two workers racing to start one read the
16
+ // same waiting knocks, and the guard on each knock's `notified` lets one
17
+ // write through.
18
+ //
19
+ // Only a hand-up reaches the operator: a knock written through a helper,
20
+ // which ./routine.ts leaves unmarked. The helper writes its own with
21
+ // `session_handup` ({@link handed}), and so does a session opened on a topic,
22
+ // which is no helper and has no other way to reach another session. This file
23
+ // writes two, each naming what the helper had taken: one that ended badly,
24
+ // and one the next routine item stops because it said nothing for
25
+ // {@link QUIET} or was still going after {@link LIMIT}. A run that has said
26
+ // its last words can linger for good on a background command it started, and
27
+ // everything behind it would wait.
28
+ //
29
+ // A run's ending and a task's mark are not routine to the session that
30
+ // started the run or watches the task, only their reading is. When a helper
31
+ // exits, each task it took one for reaches that session as one line: the
32
+ // task, its verdict as the helper leaves it (done, cancelled, stopped for a
33
+ // run somebody asked to stop, ended early for one that otherwise did not end
34
+ // cleanly, or not ready), and the report's id.
35
+ //
36
+ // The helpers' trail is `.helping.project=<project>`: each session, with what
37
+ // it wrote under `.created.via=<session>` and the knocks it took under
38
+ // `.notified.via=<session>`.
39
+ import { mint } from "@yaks/graph";
40
+ import { Stale } from "@yaks/graph/errors";
41
+ import { derivedEid } from "@yaks/graph/identity";
42
+ import { signed } from "@yaks/graph/provenance";
43
+ import { token } from "@yaks/graph/sha256";
44
+ import { human } from "@yaks/id";
45
+ import { absent, and, eq, every, fields, line, present } from "@yaks/query";
46
+ import { SESSION } from "./comp.js";
47
+ import { ended as over, owing, worksFor } from "./listen.js";
48
+ import { HELPER, HELPING, ROUTINE } from "./routine.js";
49
+ import { operatorOf } from "./watch.js";
50
+ import { STOP_ENTRY } from "./native.js";
51
+ import { cleanEnd } from "./wake.js";
52
+ import { settled, statusOf } from "@yaks/task";
53
+ /** How long a helper may go on before the next routine item stops it and
54
+ * starts another (ms). */ export let LIMIT = 30 * 60_000;
55
+ /** How long a helper may say nothing, its transcript gaining no entry, before
56
+ * the next routine item stops it and starts another (ms). */ export let QUIET = 5 * 60_000;
57
+ let comp = (b, name)=>b?.[name] ?? {};
58
+ let str = (v)=>typeof v == 'string' ? v : '';
59
+ let s = (n)=>n == 1 ? '' : 's';
60
+ let unique = (ids)=>[
61
+ ...new Set(ids.filter(Boolean))
62
+ ];
63
+ // A turn the model or a tool owes an answer: a helper not yet launched.
64
+ let WORKING = [
65
+ 'pending',
66
+ 'running'
67
+ ];
68
+ /** The routine knocks and letters waiting for a project's helper. */ export let waiting = (g, project)=>Promise.resolve(g.read(and(eq(`${ROUTINE}.project`, project), absent('notified'), every())));
69
+ // Who hears a project's hand-up: its operator while one can hear, else the
70
+ // project, where it waits for the next session a person opens.
71
+ let hears = async (g, project)=>await operatorOf(g, project) ?? project;
72
+ /** The knock `session` hands up with: one line at the operator of the project
73
+ * it works for (a helper's `helping.project`, else the home of the persona it
74
+ * wears), led by the id of the entity it concerns. The door writes it through
75
+ * that session, which is what makes it a hand-up for a helper and for a
76
+ * session opened on a topic (./routine.ts). None where the session works for
77
+ * no project. */ export let handed = async (g, session, about, line)=>{
78
+ let [from] = await g.get([
79
+ session
80
+ ], [
81
+ HELPING,
82
+ SESSION
83
+ ]);
84
+ let project = str(comp(from, HELPING).project) || (await worksFor(g, from))[0];
85
+ if (!project) return;
86
+ let [concerns] = await g.get([
87
+ about
88
+ ]);
89
+ return {
90
+ entity: {
91
+ eid: '$knock'
92
+ },
93
+ knock: {
94
+ target: await hears(g, project),
95
+ about
96
+ },
97
+ doc: {
98
+ body: `${human(g.vocab)(concerns)}: ${line.trim()}`
99
+ }
100
+ };
101
+ };
102
+ // A knock at the operator written through `helper`, which makes it a hand-up
103
+ // (./routine.ts). Named for what it tells, so a run again tells it once.
104
+ let handUp = async (g, helper, key, body, to)=>{
105
+ to ??= await hears(g, str(comp(helper, HELPING).project));
106
+ try {
107
+ await g.apply(signed([
108
+ {
109
+ entity: {
110
+ eid: derivedEid(`session help ${key} ${helper.entity.eid}`)
111
+ },
112
+ knock: {
113
+ target: to
114
+ },
115
+ doc: {
116
+ body
117
+ },
118
+ $was: {
119
+ knock: {
120
+ target: null
121
+ }
122
+ }
123
+ }
124
+ ], {
125
+ via: helper.entity.eid
126
+ }), {
127
+ trusted: true
128
+ });
129
+ } catch (error) {
130
+ if (!(error instanceof Stale)) throw error;
131
+ }
132
+ };
133
+ // What a helper had taken, as the ids a reader looks them up by.
134
+ let taken = async (g, helper)=>{
135
+ let held = await g.read(and(present(ROUTINE), eq('notified.via', helper), every()));
136
+ return held.length ? `${held.length} taken and maybe not handled: ` + held.map(human(g.vocab)).join(', ') : 'nothing taken';
137
+ };
138
+ // The helpers of a project that are not over: no `exit`, nobody asked to
139
+ // stop, not `session.ended`, and a process running or a first turn still
140
+ // owed. A native helper ends with `session.ended` and never an `exit`, so
141
+ // without that test every helper the project ever had is read and its
142
+ // status computed from its transcript.
143
+ let going = async (g, project)=>{
144
+ let has = (name)=>!!g.vocab.comp(name);
145
+ let rows = await g.read(and(eq(`${HELPING}.project`, project), ...[
146
+ 'exit',
147
+ 'stop'
148
+ ].filter(has).map((name)=>absent(name)), absent(`${SESSION}.ended`), fields(`${HELPING}.project`, 'created.at', `${SESSION}.status`, ...has('process') ? [
149
+ 'process.pid'
150
+ ] : [])));
151
+ return rows.filter((b)=>b.process || WORKING.includes(str(comp(b, SESSION).status)));
152
+ };
153
+ // A transcript's newest entry.
154
+ let newest = async (g, session)=>(await g.read(line`.entry.session=${session}&.order=-entry.seq&.limit=1&*`))[0];
155
+ let fold = (text, max)=>{
156
+ let line = text.replace(/\s+/g, ' ').trim();
157
+ return line.length > max ? `${line.slice(0, max)}…` : line;
158
+ };
159
+ // Whether a helper is at work for the project. One that said nothing for
160
+ // `quiet`, or is past the limit, is asked to stop and handed up with its last
161
+ // words, and does not count: what waits behind it would otherwise wait for
162
+ // good.
163
+ let atWork = async (g, project, o)=>{
164
+ let now = (o.now ?? Date.now)();
165
+ let limit = o.limit ?? LIMIT, quiet = o.quiet ?? QUIET;
166
+ let since = (b)=>now - Date.parse(str(comp(b, 'created').at));
167
+ let min = (ms)=>Math.round(ms / 60_000);
168
+ let busy = false;
169
+ for (let b of (await going(g, project))){
170
+ let last = await newest(g, b.entity.eid);
171
+ let over = since(b) >= limit;
172
+ if (!over && since(last ?? b) < quiet) {
173
+ busy = true;
174
+ continue;
175
+ }
176
+ await g.apply([
177
+ {
178
+ entity: {
179
+ eid: b.entity.eid
180
+ },
181
+ stop: {}
182
+ }
183
+ ]);
184
+ let words = last?.output ? fold(str(comp(last, 'content').body), 200) : '';
185
+ await handUp(g, b, 'overdue', `helper ${human(g.vocab)(b)} ` + (over ? `was still going after ${min(limit)} min` : `said nothing for ${min(quiet)} min`) + ` and was stopped, with ${await taken(g, b.entity.eid)}` + (words ? `. Its last words: ${words}` : ''));
186
+ }
187
+ return busy;
188
+ };
189
+ // What a helper is told: whose place it takes, how to hand up, and each
190
+ // waiting knock whole. How each kind is handled is its persona's to say.
191
+ let brief = (g, home, owed)=>{
192
+ let name = human(g.vocab);
193
+ let project = [
194
+ name(home),
195
+ str(comp(home, 'doc').title)
196
+ ].filter(Boolean).join(' ');
197
+ return [
198
+ `You are the helper of ${project}'s operator. ${owed.length} ` + `item${s(owed.length)} arrived for the operator and ${owed.length == 1 ? 'is' : 'are'} yours to handle. Record your work in the graph and keep the named actor ` + "when passing on a decision. Hand up only what needs the operator's judgment or a " + 'person, as one short line about the entity it concerns, with ' + '`session_handup`. When handing up a scheduled wake, carry forward its ' + 'firing date and the conditions in its note.',
199
+ ...owed.map((o)=>o.line)
200
+ ].join('\n\n');
201
+ };
202
+ /** Start the project's helper on everything waiting for it, unless one is at
203
+ * work or nothing waits. A project that no longer wears `helper`, or whose
204
+ * `helper` names no provider, gives what waits back to its operator. */ export let take = async (g, project, o = {})=>{
205
+ // Read what waits before asking who is at work: two workers that both find
206
+ // nobody at work then hold a knock in common, and its guard lets one write.
207
+ let knocks = await waiting(g, project);
208
+ if (!knocks.length) return;
209
+ let [home] = await g.get([
210
+ project
211
+ ]);
212
+ let { persona, provider, model, effort } = comp(home, HELPER);
213
+ if (!provider) {
214
+ await g.apply(knocks.map((b)=>({
215
+ entity: {
216
+ eid: b.entity.eid
217
+ },
218
+ [ROUTINE]: null
219
+ })), {
220
+ trusted: true
221
+ });
222
+ return;
223
+ }
224
+ if (await atWork(g, project, o)) return;
225
+ let owed = await owing(g, knocks);
226
+ let session = mint();
227
+ let by = persona ? {
228
+ by: str(persona)
229
+ } : {};
230
+ let said = (b, guarded)=>({
231
+ entity: {
232
+ eid: b.entity.eid
233
+ },
234
+ notified: {},
235
+ ...guarded ? {
236
+ $was: {
237
+ notified: {
238
+ at: token(null)
239
+ }
240
+ }
241
+ } : {},
242
+ $actor: {
243
+ ...by,
244
+ via: session
245
+ }
246
+ });
247
+ try {
248
+ await g.apply([
249
+ {
250
+ entity: {
251
+ eid: session
252
+ },
253
+ [SESSION]: {
254
+ operator: false,
255
+ ...persona ? {
256
+ persona
257
+ } : {}
258
+ },
259
+ [HELPING]: {
260
+ project
261
+ },
262
+ // The native harness answers it, isolated as every session outside
263
+ // words start is (@yaks/harness/isolated), never an outside CLI
264
+ // holding the box's shell. No `spawned` link: its ending is this
265
+ // file's to tell, and would otherwise wake the operator.
266
+ ...g.vocab.comp('native') ? {
267
+ native: {}
268
+ } : {},
269
+ $actor: by
270
+ },
271
+ {
272
+ entity: {
273
+ eid: mint()
274
+ },
275
+ entry: {
276
+ session
277
+ },
278
+ content: {
279
+ body: brief(g, home, owed)
280
+ },
281
+ using: {
282
+ provider,
283
+ ...model ? {
284
+ model
285
+ } : {},
286
+ ...effort ? {
287
+ effort
288
+ } : {}
289
+ },
290
+ $actor: by
291
+ },
292
+ ...owed.flatMap(({ item, same })=>[
293
+ said(item, true),
294
+ ...same.map((b)=>said(b, false))
295
+ ])
296
+ ], {
297
+ trusted: true
298
+ });
299
+ } catch (error) {
300
+ // Another worker's helper took one of these first: its exit asks again
301
+ // for whatever it did not take.
302
+ if (!(error instanceof Stale)) throw error;
303
+ }
304
+ };
305
+ // A helper that ended any way but cleanly, when nobody asked it to stop, is
306
+ // handed up with what it had taken.
307
+ let ended = async (g, helper)=>{
308
+ let code = comp(helper, 'exit').code;
309
+ if (code === 0 || helper.stop) return;
310
+ // A native helper has no exit: its transcript's status says how it ended.
311
+ let status = str(comp(helper, SESSION).status);
312
+ if (!helper.exit && status == 'settled') return;
313
+ await handUp(g, helper, 'ended', `helper ${human(g.vocab)(helper)} ` + `${!helper.exit ? status : code == null ? 'ended with no exit code' : `exited ${code}`}, with ` + await taken(g, helper.entity.eid));
314
+ };
315
+ // A helper whose work is done is over at once, not after the quiet that ends
316
+ // a session with no process to ask about (./ended.ts): until then it watches
317
+ // every task it was told of or spoke of, and each change to one would knock it
318
+ // awake to check work its operator hears of anyway (./watch.ts `targets`).
319
+ // An observation, as ./ended.ts writes it, so `updated` stays as it was.
320
+ let rest = (g, helper)=>g.apply([
321
+ {
322
+ entity: {
323
+ eid: helper
324
+ },
325
+ [SESSION]: {
326
+ ended: true
327
+ }
328
+ }
329
+ ], {
330
+ trusted: true,
331
+ stamp: false
332
+ });
333
+ // Where a taken item's line goes: the session it knocked while that can still
334
+ // hear, else the operator.
335
+ let hearer = async (g, item)=>{
336
+ let to = str(comp(item, 'knock').target);
337
+ let [row] = to ? await g.get([
338
+ to
339
+ ], [
340
+ SESSION
341
+ ]) : [];
342
+ return row?.[SESSION] && !(await over(g, [
343
+ row
344
+ ])).has(to) ? to : undefined;
345
+ };
346
+ // The verdict on a task as a helper leaves it: settled; for a run somebody
347
+ // asked to stop, stopped; for one that did not end cleanly otherwise, ended
348
+ // early; and otherwise not ready.
349
+ let verdict = (status, run)=>{
350
+ if (status == 'done' || status == 'cancelled') return status;
351
+ if (run?.[STOP_ENTRY]) return 'stopped';
352
+ return run && !cleanEnd(run) ? 'ended early' : 'not ready';
353
+ };
354
+ // Each task a helper took a run's ending (its report, a comment on the task)
355
+ // or a mark for, as one line to whoever it knocked. A comment anyone else
356
+ // wrote stays the helper's.
357
+ let verdicts = async (g, helper)=>{
358
+ let has = (name)=>!!g.vocab.comp(name);
359
+ if (!has('task')) return;
360
+ let held = await g.read(and(present(ROUTINE), present('knock'), eq('notified.via', helper.entity.eid), every()));
361
+ let ran = (b)=>b.comment ? str(comp(b, 'comment').target) : '';
362
+ let marked = (b)=>b.comment ? '' : str(comp(b, 'knock').about);
363
+ let about = unique(held.map((b)=>ran(b) || marked(b)));
364
+ if (!about.length) return;
365
+ let tasks = new Map((await g.get(about)).filter((b)=>b.task).map((b)=>[
366
+ b.entity.eid,
367
+ b
368
+ ]));
369
+ let name = human(g.vocab);
370
+ let seen = new Set();
371
+ // A run's report first: where a run and a mark tell of one task, the line
372
+ // names the report.
373
+ for (let item of [
374
+ ...held.filter(ran),
375
+ ...held.filter((b)=>!ran(b))
376
+ ]){
377
+ let report = ran(item);
378
+ let task = tasks.get(report || marked(item));
379
+ if (!task || seen.has(task.entity.eid)) continue;
380
+ let via = report ? str(comp(item, 'created').via) : '';
381
+ let [run] = via ? await g.get([
382
+ via
383
+ ], [
384
+ 'process',
385
+ 'exit',
386
+ STOP_ENTRY
387
+ ].filter(has)) : [];
388
+ let status = statusOf(g.vocab, task);
389
+ if (report ? !run?.process || !run.exit : !settled(status)) continue;
390
+ seen.add(task.entity.eid);
391
+ let title = fold(str(comp(task, 'doc').title), 80);
392
+ await handUp(g, helper, `told ${task.entity.eid}`, `${name(task)} ${verdict(status, run)}` + (title ? `: ${title}` : '') + (report ? ` (report ${name(item)})` : ''), await hearer(g, item));
393
+ }
394
+ };
395
+ /** The code behind `session_help`, for the entity a commit moved: a routine
396
+ * knock, a helper that exited or whose native transcript ended (./run.ts
397
+ * tells that), or a project whose `helper` went. */ export let help = async (g, eid, o = {})=>{
398
+ let has = (name)=>!!g.vocab.comp(name);
399
+ let [row] = await g.get([
400
+ eid
401
+ ], [
402
+ ROUTINE,
403
+ HELPING,
404
+ 'project',
405
+ 'exit',
406
+ 'stop',
407
+ 'native'
408
+ ].filter(has));
409
+ if (!row) return;
410
+ // A native helper's status is computed from its transcript, which a get
411
+ // does not read.
412
+ if (row[HELPING] && row.native) {
413
+ let [read] = await g.read(line`.entity.eid=${eid}&.fields=session.status`);
414
+ row = {
415
+ ...row,
416
+ [SESSION]: comp(read, SESSION)
417
+ };
418
+ }
419
+ let finished = row.native && [
420
+ 'settled',
421
+ 'failed',
422
+ 'stopped'
423
+ ].includes(str(comp(row, SESSION).status));
424
+ if (row[HELPING] && (row.exit || finished)) {
425
+ await rest(g, eid);
426
+ await ended(g, row);
427
+ await verdicts(g, row);
428
+ }
429
+ let project = str(comp(row, ROUTINE).project) || str(comp(row, HELPING).project) || (row.project ? eid : '');
430
+ if (project) await take(g, project, o);
431
+ };
432
+ //# sourceMappingURL=help.js.map
package/help.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"help.js","sources":["./help.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,uEAAuE;AACvE,EAAE;AACF,6EAA6E;AAC7E,2EAA2E;AAC3E,4EAA4E;AAC5E,4EAA4E;AAC5E,2EAA2E;AAC3E,uEAAuE;AACvE,qDAAqD;AACrD,EAAE;AACF,yEAAyE;AACzE,4EAA4E;AAC5E,4EAA4E;AAC5E,kFAAkF;AAClF,yEAAyE;AACzE,iBAAiB;AACjB,EAAE;AACF,yEAAyE;AACzE,qEAAqE;AACrE,8EAA8E;AAC9E,8EAA8E;AAC9E,2EAA2E;AAC3E,kEAAkE;AAClE,4EAA4E;AAC5E,6EAA6E;AAC7E,mCAAmC;AACnC,EAAE;AACF,uEAAuE;AACvE,4EAA4E;AAC5E,yEAAyE;AACzE,4EAA4E;AAC5E,6EAA6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