@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
@@ -0,0 +1,50 @@
1
+ // The cost of reading one transcript's computed status while another holds a
2
+ // large history of calls. Both doors are used by a Store reading call rows.
3
+
4
+ import { type Bundle, graph } from 'jsr:@yaks/graph@0.2.36'
5
+ import { loadVocab } from 'jsr:@yaks/vocab@0.2.36'
6
+ import { storage } from 'jsr:@yaks/sqlite@0.2.36'
7
+ import { open } from 'jsr:@yaks/sqlite@0.2.36/db'
8
+ import { toolsDoc } from 'jsr:@yaks/tools@0.2.36/vocab'
9
+ import { modelDoc } from 'jsr:@yaks/model@0.2.36/vocab'
10
+ import { sessionDoc } from './comp.ts'
11
+ import { sessionDerived } from './status.ts'
12
+ import { standaloneMain } from '../../bench/standalone-main.ts'
13
+
14
+ if (import.meta.main) {
15
+ await standaloneMain('session-status')
16
+ } else {
17
+ let vocab = loadVocab([sessionDoc, toolsDoc, modelDoc])
18
+ let db = open(':memory:')
19
+ addEventListener('unload', () => db.close())
20
+ let store = storage(db, vocab, { derived: sessionDerived(vocab) })
21
+ store.install()
22
+ let g = graph({ storage: store, vocab })
23
+ store.tx((tx) =>
24
+ tx.patch([
25
+ { entity: { eid: 'target' }, session: { id: 'target' } },
26
+ { entity: { eid: 'other' }, session: { id: 'other' } },
27
+ ])
28
+ )
29
+ for (let from = 0; from < 48_000; from += 1000) {
30
+ let rows: Bundle[] = []
31
+ for (let i = from; i < Math.min(from + 1000, 48_000); i++) {
32
+ rows.push({
33
+ entity: { eid: `e${i}` },
34
+ entry: { session: i == 0 ? 'target' : 'other', seq: i },
35
+ ...(i > 0 && i <= 2700
36
+ ? { call: {}, execution: { state: 'done' } }
37
+ : { content: { body: 'line' } }),
38
+ })
39
+ }
40
+ store.tx((tx) => tx.patch(rows))
41
+ }
42
+
43
+ Deno.bench('status by identity beside 2,700 other calls', () => {
44
+ g.get(['target'])
45
+ })
46
+
47
+ Deno.bench('status by query beside 2,700 other calls', () => {
48
+ g.read('.entity.eid=target&*')
49
+ })
50
+ }
package/statusline.js ADDED
@@ -0,0 +1,187 @@
1
+ // Claude Code's status line, answered by the hook door (./routes.ts): what
2
+ // room each plan has left, read from the `rate_limit` rows (@yaks/model) of
3
+ // every provider and account this graph knows, so a person on one plan sees
4
+ // where the conversation can go next (`/yak:continue`).
5
+ //
6
+ // Claude Code hands its status line the limits of the account the session
7
+ // signs in with, which no transcript holds; each render's reading is kept as
8
+ // that account's rows, as a `claude -p` run's are (./readers.ts).
9
+ import { accountEid, limitRows } from "@yaks/model";
10
+ import { identityEid } from "@yaks/graph/identity";
11
+ import { and, every, present } from "@yaks/query";
12
+ let comp = (b, name)=>b?.[name];
13
+ // The windows Claude Code names, in minutes.
14
+ let WINDOWS = {
15
+ five_hour: 300,
16
+ seven_day: 10080
17
+ };
18
+ /** The Claude Code account a transcript is kept in: the directory holding
19
+ * its `projects`. */ export let accountOf = (transcript)=>{
20
+ let at = transcript?.lastIndexOf('/projects/') ?? -1;
21
+ return at > 0 ? transcript.slice(0, at) : undefined;
22
+ };
23
+ /**
24
+ * The plan limits a status line was handed, as readings of the account whose
25
+ * transcript it names.
26
+ *
27
+ * ```ts
28
+ * import { statusLimits } from './statusline.ts'
29
+ * import { accountEid } from '@yaks/model'
30
+ * import { equal } from '@yaks/testing'
31
+ *
32
+ * equal(statusLimits({
33
+ * transcript_path: '/u/.claude-work/projects/-w/s.jsonl',
34
+ * rate_limits: { five_hour: { used_percentage: 12, resets_at: 1793098800 } },
35
+ * }), [{
36
+ * provider: 'claude', account: accountEid('/u/.claude-work'), window: 300,
37
+ * used: 12, resets: '2026-10-27T11:00:00.000Z',
38
+ * }])
39
+ * equal(statusLimits({}), [])
40
+ * ```
41
+ */ export let statusLimits = (s)=>{
42
+ let home = accountOf(s.transcript_path);
43
+ return Object.entries(s.rate_limits ?? {}).flatMap(([name, r])=>{
44
+ let window = WINDOWS[name];
45
+ if (!window || typeof r?.used_percentage != 'number') return [];
46
+ return [
47
+ {
48
+ provider: 'claude',
49
+ ...home ? {
50
+ account: accountEid(home)
51
+ } : {},
52
+ window,
53
+ used: r.used_percentage,
54
+ ...r.resets_at ? {
55
+ resets: new Date(r.resets_at * 1000).toISOString()
56
+ } : {}
57
+ }
58
+ ];
59
+ });
60
+ };
61
+ let span = (minutes)=>minutes % 10080 == 0 ? minutes == 10080 ? 'wk' : `${minutes / 10080}wk` : minutes % 1440 == 0 ? `${minutes / 1440}d` : minutes % 60 == 0 ? `${minutes / 60}h` : `${minutes}m`;
62
+ let until = (at, now)=>{
63
+ let m = Math.max(0, Math.round((Date.parse(at) - now) / 60000));
64
+ return m >= 2880 ? `${Math.round(m / 1440)}d` : m >= 120 ? `${Math.round(m / 60)}h` : `${m}m`;
65
+ };
66
+ /**
67
+ * Each plan's room, the plan this session runs on first: for each window,
68
+ * the percent left, and when it resets where little is. A reading from a
69
+ * window that has since reset says nothing of the one running now.
70
+ *
71
+ * ```ts
72
+ * import { room } from './statusline.ts'
73
+ * import { equal } from '@yaks/testing'
74
+ *
75
+ * let now = Date.parse('2026-11-23T12:00:00Z')
76
+ * equal(room([
77
+ * { plan: 'codex', window: 10080, used: 30 },
78
+ * { plan: 'claude', window: 300, used: 95, resets: '2026-11-23T14:00:00Z' },
79
+ * { plan: 'claude', window: 10080, used: 40 },
80
+ * { plan: 'claude', window: 10080, model: 'fable', used: 50 },
81
+ * { plan: 'grok', window: 300, used: 80, resets: '2026-11-23T11:00:00Z' },
82
+ * ], now, 'claude'), 'claude 5h 5% (2h) · wk 60% · fable 50% │ codex wk 70%')
83
+ * ```
84
+ */ export let room = (rooms, now, first)=>{
85
+ let current = rooms.filter((r)=>r.window > 0 && !(r.resets && Date.parse(r.resets) <= now));
86
+ let plans = [
87
+ ...new Set(current.map((r)=>r.plan))
88
+ ].sort((a, b)=>Number(b == first) - Number(a == first) || a.localeCompare(b));
89
+ return plans.map((plan)=>`${plan} ` + current.filter((r)=>r.plan == plan).sort((a, b)=>Number(!!a.model) - Number(!!b.model) || a.window - b.window).map((r)=>{
90
+ let left = Math.max(0, Math.round(100 - r.used));
91
+ let soon = left < 10 && r.resets ? ` (${until(r.resets, now)})` : '';
92
+ return `${r.model ?? span(r.window)} ${left}%${soon}`;
93
+ }).join(' · ')).join(' │ ');
94
+ };
95
+ // A plan's name: its account's directory, without the dot (`claude-work`),
96
+ // else its provider's name.
97
+ let planOf = (home, provider)=>typeof home == 'string' ? home.slice(home.lastIndexOf('/') + 1).replace(/^\./, '') : String(provider ?? '?');
98
+ /**
99
+ * Keep what a status line was handed, then answer it: the session's model
100
+ * and how full its context is, and each plan's room ({@link room}). A reading
101
+ * is written only where it moved, since the line is asked for on every
102
+ * render.
103
+ */ export let statusLine = async (g, s, now = Date.now())=>{
104
+ await keep(g, statusLimits(s), accountOf(s.transcript_path), now);
105
+ let limits = await g.read(and(present('rate_limit'), every()));
106
+ let named = [
107
+ ...new Set(limits.flatMap((b)=>{
108
+ let r = comp(b, 'rate_limit');
109
+ return [
110
+ r.provider,
111
+ r.account,
112
+ r.model
113
+ ].filter(Boolean).map(String);
114
+ }))
115
+ ];
116
+ let rows = new Map((named.length ? await g.get(named) : []).filter(Boolean).map((b)=>[
117
+ b.entity.eid,
118
+ b
119
+ ]));
120
+ let name = (eid, c)=>comp(rows.get(String(eid)), c)?.name;
121
+ let rooms = limits.map((b)=>{
122
+ let r = comp(b, 'rate_limit');
123
+ return {
124
+ plan: planOf(comp(rows.get(String(r.account)), 'account')?.home, name(r.provider, 'provider')),
125
+ window: Number(r.window),
126
+ ...r.model ? {
127
+ model: name(r.model, 'model') ?? 'model'
128
+ } : {},
129
+ used: Number(r.used),
130
+ ...r.resets ? {
131
+ resets: String(r.resets)
132
+ } : {}
133
+ };
134
+ });
135
+ let home = accountOf(s.transcript_path);
136
+ let context = s.context_window?.used_percentage;
137
+ return [
138
+ [
139
+ s.model?.display_name,
140
+ typeof context == 'number' ? `ctx ${Math.round(context)}%` : undefined
141
+ ].filter(Boolean).join(' '),
142
+ room(rooms, now, home ? planOf(home, undefined) : 'claude')
143
+ ].filter(Boolean).join(' │ ');
144
+ };
145
+ // Write readings where they differ from the rows kept, and the account and
146
+ // provider they name where those are missing.
147
+ let keep = async (g, limits, home, now)=>{
148
+ if (!limits.length || !g.vocab.comp('rate_limit')) return;
149
+ let rows = limitRows(limits, new Date(now).toISOString());
150
+ let provider = identityEid('provider', [
151
+ 'claude'
152
+ ]);
153
+ let account = home ? accountEid(home) : undefined;
154
+ let kept = new Map((await g.get([
155
+ ...rows.map((b)=>b.entity.eid),
156
+ ...account ? [
157
+ account
158
+ ] : []
159
+ ])).filter(Boolean).map((b)=>[
160
+ b.entity.eid,
161
+ b
162
+ ]));
163
+ let moved = rows.filter((b)=>{
164
+ let was = comp(kept.get(b.entity.eid), 'rate_limit');
165
+ let r = comp(b, 'rate_limit');
166
+ if (!r) return !kept.has(b.entity.eid);
167
+ return !was || was.used != r.used || was.resets != r.resets;
168
+ });
169
+ if (!moved.some((b)=>b.rate_limit)) return;
170
+ await g.apply([
171
+ ...account && !comp(kept.get(account), 'account') ? [
172
+ {
173
+ entity: {
174
+ eid: account
175
+ },
176
+ account: {
177
+ home,
178
+ provider
179
+ }
180
+ }
181
+ ] : [],
182
+ ...moved
183
+ ], {
184
+ trusted: true
185
+ });
186
+ };
187
+ //# sourceMappingURL=statusline.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"statusline.js","sources":["./statusline.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,4EAA4E;AAC5E,4EAA4E;AAC5E,wDAAwD;AACxD,EAAE;AACF,0EAA0E;AAC1E,6EAA6E;AAC7E,kEAAkE;AAGlE,SAAS,UAAU,EAAc,SAAS,2BAAgC;AAC1E,SAAS,WAAW,oCAAyC;AAC7D,SAAS,GAAG,EAAE,KAAK,EAAE,OAAO,2BAAgC;AAE5D,I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M,EAAE,UAAU,GAAG;EACtC,MAAM,EAAE,KAAK,CAAC;OACT,WAAW,CAAC,KAAK,KAAK,GAAG,CAAC,UAAU,aACnC;MAAC;QAAE,QAAQ;UAAE,KAAK;QAAQ;QAAG,SAAS;UAAE;UAAM;QAAS;MAAE;KAAE,GAC3D,EAAE;OACH;GACJ,EAAE;IAAE,SAAS;EAAK;AACrB"}
package/statusline.ts ADDED
@@ -0,0 +1,232 @@
1
+ // Claude Code's status line, answered by the hook door (./routes.ts): what
2
+ // room each plan has left, read from the `rate_limit` rows (@yaks/model) of
3
+ // every provider and account this graph knows, so a person on one plan sees
4
+ // where the conversation can go next (`/yak:continue`).
5
+ //
6
+ // Claude Code hands its status line the limits of the account the session
7
+ // signs in with, which no transcript holds; each render's reading is kept as
8
+ // that account's rows, as a `claude -p` run's are (./readers.ts).
9
+
10
+ import type { Bundle, Comp, Eid, Graph } from 'jsr:@yaks/graph@0.2.36'
11
+ import { accountEid, type Limit, limitRows } from '@yaks/model'
12
+ import { identityEid } from '@yaks/graph/identity'
13
+ import { and, every, present } from '@yaks/query'
14
+
15
+ let comp = (b: Bundle | undefined, name: string) =>
16
+ b?.[name] as Comp | undefined
17
+
18
+ /** What Claude Code hands its status line, as far as it is read here. */
19
+ export type Status = {
20
+ transcript_path?: string
21
+ model?: { display_name?: string }
22
+ context_window?: { used_percentage?: number }
23
+ rate_limits?: Record<
24
+ string,
25
+ { used_percentage?: number; resets_at?: number } | undefined
26
+ >
27
+ }
28
+
29
+ // The windows Claude Code names, in minutes.
30
+ let WINDOWS: Record<string, number> = { five_hour: 300, seven_day: 10080 }
31
+
32
+ /** The Claude Code account a transcript is kept in: the directory holding
33
+ * its `projects`. */
34
+ export let accountOf = (transcript?: string): string | undefined => {
35
+ let at = transcript?.lastIndexOf('/projects/') ?? -1
36
+ return at > 0 ? transcript!.slice(0, at) : undefined
37
+ }
38
+
39
+ /**
40
+ * The plan limits a status line was handed, as readings of the account whose
41
+ * transcript it names.
42
+ *
43
+ * ```ts
44
+ * import { statusLimits } from './statusline.ts'
45
+ * import { accountEid } from '@yaks/model'
46
+ * import { equal } from '@yaks/testing'
47
+ *
48
+ * equal(statusLimits({
49
+ * transcript_path: '/u/.claude-work/projects/-w/s.jsonl',
50
+ * rate_limits: { five_hour: { used_percentage: 12, resets_at: 1793098800 } },
51
+ * }), [{
52
+ * provider: 'claude', account: accountEid('/u/.claude-work'), window: 300,
53
+ * used: 12, resets: '2026-10-27T11:00:00.000Z',
54
+ * }])
55
+ * equal(statusLimits({}), [])
56
+ * ```
57
+ */
58
+ export let statusLimits = (s: Status): Limit[] => {
59
+ let home = accountOf(s.transcript_path)
60
+ return Object.entries(s.rate_limits ?? {}).flatMap(([name, r]) => {
61
+ let window = WINDOWS[name]
62
+ if (!window || typeof r?.used_percentage != 'number') return []
63
+ return [{
64
+ provider: 'claude',
65
+ ...home ? { account: accountEid(home) } : {},
66
+ window,
67
+ used: r.used_percentage,
68
+ ...r.resets_at
69
+ ? { resets: new Date(r.resets_at * 1000).toISOString() }
70
+ : {},
71
+ }]
72
+ })
73
+ }
74
+
75
+ /** A plan's room in one window, as {@link room} draws it. */
76
+ export type Room = {
77
+ /** the plan: its account's directory, else its provider */
78
+ plan: string
79
+ window: number
80
+ /** the one model a window meters, where it is not the whole plan */
81
+ model?: string
82
+ used: number
83
+ resets?: string
84
+ }
85
+
86
+ let span = (minutes: number) =>
87
+ minutes % 10080 == 0
88
+ ? minutes == 10080 ? 'wk' : `${minutes / 10080}wk`
89
+ : minutes % 1440 == 0
90
+ ? `${minutes / 1440}d`
91
+ : minutes % 60 == 0
92
+ ? `${minutes / 60}h`
93
+ : `${minutes}m`
94
+
95
+ let until = (at: string, now: number) => {
96
+ let m = Math.max(0, Math.round((Date.parse(at) - now) / 60000))
97
+ return m >= 2880
98
+ ? `${Math.round(m / 1440)}d`
99
+ : m >= 120
100
+ ? `${Math.round(m / 60)}h`
101
+ : `${m}m`
102
+ }
103
+
104
+ /**
105
+ * Each plan's room, the plan this session runs on first: for each window,
106
+ * the percent left, and when it resets where little is. A reading from a
107
+ * window that has since reset says nothing of the one running now.
108
+ *
109
+ * ```ts
110
+ * import { room } from './statusline.ts'
111
+ * import { equal } from '@yaks/testing'
112
+ *
113
+ * let now = Date.parse('2026-11-23T12:00:00Z')
114
+ * equal(room([
115
+ * { plan: 'codex', window: 10080, used: 30 },
116
+ * { plan: 'claude', window: 300, used: 95, resets: '2026-11-23T14:00:00Z' },
117
+ * { plan: 'claude', window: 10080, used: 40 },
118
+ * { plan: 'claude', window: 10080, model: 'fable', used: 50 },
119
+ * { plan: 'grok', window: 300, used: 80, resets: '2026-11-23T11:00:00Z' },
120
+ * ], now, 'claude'), 'claude 5h 5% (2h) · wk 60% · fable 50% │ codex wk 70%')
121
+ * ```
122
+ */
123
+ export let room = (rooms: Room[], now: number, first?: string): string => {
124
+ let current = rooms.filter((r) =>
125
+ r.window > 0 && !(r.resets && Date.parse(r.resets) <= now)
126
+ )
127
+ let plans = [...new Set(current.map((r) => r.plan))].sort((a, b) =>
128
+ Number(b == first) - Number(a == first) || a.localeCompare(b)
129
+ )
130
+ return plans.map((plan) =>
131
+ `${plan} ` + current.filter((r) => r.plan == plan)
132
+ .sort((a, b) =>
133
+ Number(!!a.model) - Number(!!b.model) || a.window - b.window
134
+ )
135
+ .map((r) => {
136
+ let left = Math.max(0, Math.round(100 - r.used))
137
+ let soon = left < 10 && r.resets ? ` (${until(r.resets, now)})` : ''
138
+ return `${r.model ?? span(r.window)} ${left}%${soon}`
139
+ }).join(' · ')
140
+ ).join(' │ ')
141
+ }
142
+
143
+ // A plan's name: its account's directory, without the dot (`claude-work`),
144
+ // else its provider's name.
145
+ let planOf = (home: unknown, provider: unknown): string =>
146
+ typeof home == 'string'
147
+ ? home.slice(home.lastIndexOf('/') + 1).replace(/^\./, '')
148
+ : String(provider ?? '?')
149
+
150
+ /**
151
+ * Keep what a status line was handed, then answer it: the session's model
152
+ * and how full its context is, and each plan's room ({@link room}). A reading
153
+ * is written only where it moved, since the line is asked for on every
154
+ * render.
155
+ */
156
+ export let statusLine = async (
157
+ g: Graph,
158
+ s: Status,
159
+ now = Date.now(),
160
+ ): Promise<string> => {
161
+ await keep(g, statusLimits(s), accountOf(s.transcript_path), now)
162
+ let limits = await g.read(and(present('rate_limit'), every()))
163
+ let named = [
164
+ ...new Set(
165
+ limits.flatMap((b) => {
166
+ let r = comp(b, 'rate_limit')!
167
+ return [r.provider, r.account, r.model].filter(Boolean).map(String)
168
+ }),
169
+ ),
170
+ ]
171
+ let rows = new Map(
172
+ (named.length ? await g.get(named) : []).filter(Boolean)
173
+ .map((b) => [b!.entity.eid, b!]),
174
+ )
175
+ let name = (eid: unknown, c: string) =>
176
+ comp(rows.get(String(eid)), c)?.name as string | undefined
177
+ let rooms = limits.map((b): Room => {
178
+ let r = comp(b, 'rate_limit')!
179
+ return {
180
+ plan: planOf(
181
+ comp(rows.get(String(r.account)), 'account')?.home,
182
+ name(r.provider, 'provider'),
183
+ ),
184
+ window: Number(r.window),
185
+ ...r.model ? { model: name(r.model, 'model') ?? 'model' } : {},
186
+ used: Number(r.used),
187
+ ...r.resets ? { resets: String(r.resets) } : {},
188
+ }
189
+ })
190
+ let home = accountOf(s.transcript_path)
191
+ let context = s.context_window?.used_percentage
192
+ return [
193
+ [
194
+ s.model?.display_name,
195
+ typeof context == 'number' ? `ctx ${Math.round(context)}%` : undefined,
196
+ ].filter(Boolean).join(' '),
197
+ room(rooms, now, home ? planOf(home, undefined) : 'claude'),
198
+ ].filter(Boolean).join(' │ ')
199
+ }
200
+
201
+ // Write readings where they differ from the rows kept, and the account and
202
+ // provider they name where those are missing.
203
+ let keep = async (
204
+ g: Graph,
205
+ limits: Limit[],
206
+ home: string | undefined,
207
+ now: number,
208
+ ) => {
209
+ if (!limits.length || !g.vocab.comp('rate_limit')) return
210
+ let rows = limitRows(limits, new Date(now).toISOString())
211
+ let provider: Eid = identityEid('provider', ['claude'])
212
+ let account = home ? accountEid(home) : undefined
213
+ let kept = new Map(
214
+ (await g.get([
215
+ ...rows.map((b) => b.entity.eid),
216
+ ...account ? [account] : [],
217
+ ])).filter(Boolean).map((b) => [b!.entity.eid, b!]),
218
+ )
219
+ let moved = rows.filter((b) => {
220
+ let was = comp(kept.get(b.entity.eid), 'rate_limit')
221
+ let r = comp(b, 'rate_limit')
222
+ if (!r) return !kept.has(b.entity.eid)
223
+ return !was || was.used != r.used || was.resets != r.resets
224
+ })
225
+ if (!moved.some((b) => b.rate_limit)) return
226
+ await g.apply([
227
+ ...account && !comp(kept.get(account), 'account')
228
+ ? [{ entity: { eid: account }, account: { home, provider } }]
229
+ : [],
230
+ ...moved,
231
+ ], { trusted: true })
232
+ }