@yaks/cli 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 (331) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +1059 -2
  3. package/_dist/account-forward.d.ts +12 -0
  4. package/_dist/account-forward.d.ts.map +1 -0
  5. package/_dist/accounts.d.ts +23 -0
  6. package/_dist/accounts.d.ts.map +1 -0
  7. package/_dist/answer.d.ts +88 -0
  8. package/_dist/answer.d.ts.map +1 -0
  9. package/_dist/apply.d.ts +17 -0
  10. package/_dist/apply.d.ts.map +1 -0
  11. package/_dist/args.d.ts +86 -0
  12. package/_dist/args.d.ts.map +1 -0
  13. package/_dist/commands.d.ts +15 -0
  14. package/_dist/commands.d.ts.map +1 -0
  15. package/_dist/complete.d.ts +15 -0
  16. package/_dist/complete.d.ts.map +1 -0
  17. package/_dist/config.d.ts +37 -0
  18. package/_dist/config.d.ts.map +1 -0
  19. package/_dist/dependencies.d.ts +6 -0
  20. package/_dist/dependencies.d.ts.map +1 -0
  21. package/_dist/facets.d.ts +71 -0
  22. package/_dist/facets.d.ts.map +1 -0
  23. package/_dist/grammar.d.ts +5 -0
  24. package/_dist/grammar.d.ts.map +1 -0
  25. package/_dist/host.d.ts +164 -0
  26. package/_dist/host.d.ts.map +1 -0
  27. package/_dist/install.d.ts +43 -0
  28. package/_dist/install.d.ts.map +1 -0
  29. package/_dist/main.d.ts +16 -0
  30. package/_dist/main.d.ts.map +1 -0
  31. package/_dist/memo.d.ts +60 -0
  32. package/_dist/memo.d.ts.map +1 -0
  33. package/_dist/mod.d.ts +46 -0
  34. package/_dist/mod.d.ts.map +1 -0
  35. package/_dist/page.d.ts +73 -0
  36. package/_dist/page.d.ts.map +1 -0
  37. package/_dist/platform.d.ts +27 -0
  38. package/_dist/platform.d.ts.map +1 -0
  39. package/_dist/reader.d.ts +10 -0
  40. package/_dist/reader.d.ts.map +1 -0
  41. package/_dist/release.d.ts +48 -0
  42. package/_dist/release.d.ts.map +1 -0
  43. package/_dist/remote.d.ts +13 -0
  44. package/_dist/remote.d.ts.map +1 -0
  45. package/_dist/reported.d.ts +11 -0
  46. package/_dist/reported.d.ts.map +1 -0
  47. package/_dist/roles.d.ts +2 -0
  48. package/_dist/roles.d.ts.map +1 -0
  49. package/_dist/roster.d.ts +41 -0
  50. package/_dist/roster.d.ts.map +1 -0
  51. package/_dist/rpc.d.ts +29 -0
  52. package/_dist/rpc.d.ts.map +1 -0
  53. package/_dist/run.d.ts +164 -0
  54. package/_dist/run.d.ts.map +1 -0
  55. package/_dist/runtime.d.ts +4 -0
  56. package/_dist/runtime.d.ts.map +1 -0
  57. package/_dist/searching.d.ts +7 -0
  58. package/_dist/searching.d.ts.map +1 -0
  59. package/_dist/show.d.ts +22 -0
  60. package/_dist/show.d.ts.map +1 -0
  61. package/_dist/store.d.ts +25 -0
  62. package/_dist/store.d.ts.map +1 -0
  63. package/_dist/terminal.d.ts +17 -0
  64. package/_dist/terminal.d.ts.map +1 -0
  65. package/_dist/tool.d.ts +55 -0
  66. package/_dist/tool.d.ts.map +1 -0
  67. package/_dist/tty.d.ts +3 -0
  68. package/_dist/tty.d.ts.map +1 -0
  69. package/_dist/vault.d.ts +9 -0
  70. package/_dist/vault.d.ts.map +1 -0
  71. package/_dist/words.d.ts +11 -0
  72. package/_dist/words.d.ts.map +1 -0
  73. package/_dist/yak.d.ts +10 -0
  74. package/_dist/yak.d.ts.map +1 -0
  75. package/account-forward.js +40 -0
  76. package/account-forward.js.map +1 -0
  77. package/account-forward.ts +50 -0
  78. package/accounts.js +162 -0
  79. package/accounts.js.map +1 -0
  80. package/accounts.ts +228 -0
  81. package/answer.js +394 -0
  82. package/answer.js.map +1 -0
  83. package/answer.ts +569 -0
  84. package/apply.js +49 -0
  85. package/apply.js.map +1 -0
  86. package/apply.ts +54 -0
  87. package/args.js +420 -0
  88. package/args.js.map +1 -0
  89. package/args.ts +494 -0
  90. package/code.js +209 -0
  91. package/code.js.map +1 -0
  92. package/code.ts +227 -0
  93. package/commands.js +131 -0
  94. package/commands.js.map +1 -0
  95. package/commands.ts +142 -0
  96. package/complete.js +104 -0
  97. package/complete.js.map +1 -0
  98. package/complete.ts +152 -0
  99. package/config.js +125 -0
  100. package/config.js.map +1 -0
  101. package/config.ts +180 -0
  102. package/declarations.js +67 -0
  103. package/declarations.js.map +1 -0
  104. package/declarations.ts +84 -0
  105. package/deno.json +1 -0
  106. package/dependencies.js +126 -0
  107. package/dependencies.js.map +1 -0
  108. package/dependencies.ts +141 -0
  109. package/derive.js +102 -0
  110. package/derive.js.map +1 -0
  111. package/derive.ts +125 -0
  112. package/drain.js +83 -0
  113. package/drain.js.map +1 -0
  114. package/drain.ts +115 -0
  115. package/duties.ts +17 -0
  116. package/exports.json +1486 -0
  117. package/external.js +373 -0
  118. package/external.js.map +1 -0
  119. package/external.ts +435 -0
  120. package/facets.js +214 -0
  121. package/facets.js.map +1 -0
  122. package/facets.ts +232 -0
  123. package/feedback.js +54 -0
  124. package/feedback.js.map +1 -0
  125. package/feedback.ts +57 -0
  126. package/files.js +84 -0
  127. package/files.js.map +1 -0
  128. package/files.ts +112 -0
  129. package/get_starts.js +31 -0
  130. package/get_starts.js.map +1 -0
  131. package/get_starts.ts +34 -0
  132. package/git-credential.js +79 -0
  133. package/git-credential.js.map +1 -0
  134. package/git-credential.ts +77 -0
  135. package/grammar.js +4 -0
  136. package/grammar.js.map +1 -0
  137. package/grammar.ts +5 -0
  138. package/held.js +51 -0
  139. package/held.js.map +1 -0
  140. package/held.ts +66 -0
  141. package/host.js +1174 -0
  142. package/host.js.map +1 -0
  143. package/host.ts +1343 -0
  144. package/init.js +138 -0
  145. package/init.js.map +1 -0
  146. package/init.ts +139 -0
  147. package/install.js +216 -0
  148. package/install.js.map +1 -0
  149. package/install.ts +223 -0
  150. package/lifetime.js +56 -0
  151. package/lifetime.js.map +1 -0
  152. package/lifetime.ts +66 -0
  153. package/local-page.ts +114 -0
  154. package/local.js +417 -0
  155. package/local.js.map +1 -0
  156. package/local.ts +537 -0
  157. package/lockfile.js +20 -0
  158. package/lockfile.js.map +1 -0
  159. package/lockfile.ts +32 -0
  160. package/machines.js +33 -0
  161. package/machines.js.map +1 -0
  162. package/machines.ts +51 -0
  163. package/made/4f855610bdabcd736100d34e4e467ea5.json +1 -0
  164. package/main.js +534 -0
  165. package/main.js.map +1 -0
  166. package/main.ts +547 -0
  167. package/mcp.js +108 -0
  168. package/mcp.js.map +1 -0
  169. package/mcp.ts +113 -0
  170. package/member.js +103 -0
  171. package/member.js.map +1 -0
  172. package/member.ts +133 -0
  173. package/memo.js +503 -0
  174. package/memo.js.map +1 -0
  175. package/memo.ts +634 -0
  176. package/mod.js +46 -0
  177. package/mod.js.map +1 -0
  178. package/mod.ts +99 -0
  179. package/operations.js +53 -0
  180. package/operations.js.map +1 -0
  181. package/operations.ts +68 -0
  182. package/package.json +115 -4
  183. package/page.js +211 -0
  184. package/page.js.map +1 -0
  185. package/page.ts +308 -0
  186. package/parser.js +45 -0
  187. package/parser.js.map +1 -0
  188. package/parser.ts +77 -0
  189. package/people-search.js +112 -0
  190. package/people-search.js.map +1 -0
  191. package/people-search.ts +162 -0
  192. package/platform.js +184 -0
  193. package/platform.js.map +1 -0
  194. package/platform.ts +224 -0
  195. package/platform_effects.js +5 -0
  196. package/platform_effects.js.map +1 -0
  197. package/platform_effects.ts +13 -0
  198. package/prepare.js +40 -0
  199. package/prepare.js.map +1 -0
  200. package/prepare.ts +46 -0
  201. package/read_activity.js +54 -0
  202. package/read_activity.js.map +1 -0
  203. package/read_activity.ts +61 -0
  204. package/read_thread.js +387 -0
  205. package/read_thread.js.map +1 -0
  206. package/read_thread.ts +506 -0
  207. package/read_worker.ts +164 -0
  208. package/reader.js +48 -0
  209. package/reader.js.map +1 -0
  210. package/reader.ts +57 -0
  211. package/release.js +82 -0
  212. package/release.js.map +1 -0
  213. package/release.json +127 -0
  214. package/release.ts +98 -0
  215. package/remote-page.ts +70 -0
  216. package/remote.js +96 -0
  217. package/remote.js.map +1 -0
  218. package/remote.ts +153 -0
  219. package/report.js +83 -0
  220. package/report.js.map +1 -0
  221. package/report.ts +101 -0
  222. package/reported.js +32 -0
  223. package/reported.js.map +1 -0
  224. package/reported.ts +38 -0
  225. package/restart.js +349 -0
  226. package/restart.js.map +1 -0
  227. package/restart.ts +478 -0
  228. package/restore.js +32 -0
  229. package/restore.js.map +1 -0
  230. package/restore.ts +38 -0
  231. package/roles.js +32 -0
  232. package/roles.js.map +1 -0
  233. package/roles.ts +49 -0
  234. package/roster.js +65 -0
  235. package/roster.js.map +1 -0
  236. package/roster.ts +84 -0
  237. package/rpc.js +113 -0
  238. package/rpc.js.map +1 -0
  239. package/rpc.ts +159 -0
  240. package/run.js +533 -0
  241. package/run.js.map +1 -0
  242. package/run.ts +741 -0
  243. package/runtime.js +381 -0
  244. package/runtime.js.map +1 -0
  245. package/runtime.ts +433 -0
  246. package/sandboxes.js +26 -0
  247. package/sandboxes.js.map +1 -0
  248. package/sandboxes.ts +30 -0
  249. package/searching.js +33 -0
  250. package/searching.js.map +1 -0
  251. package/searching.ts +50 -0
  252. package/show.js +109 -0
  253. package/show.js.map +1 -0
  254. package/show.ts +144 -0
  255. package/shown.js +13 -0
  256. package/shown.js.map +1 -0
  257. package/shown.ts +44 -0
  258. package/stall.js +90 -0
  259. package/stall.js.map +1 -0
  260. package/stall.ts +156 -0
  261. package/stall_profile.js +113 -0
  262. package/stall_profile.js.map +1 -0
  263. package/stall_profile.ts +142 -0
  264. package/stall_wait.js +183 -0
  265. package/stall_wait.js.map +1 -0
  266. package/stall_wait.ts +249 -0
  267. package/stall_wait_worker.ts +11 -0
  268. package/start.js +349 -0
  269. package/start.js.map +1 -0
  270. package/start.ts +343 -0
  271. package/starvation.js +147 -0
  272. package/starvation.js.map +1 -0
  273. package/starvation.ts +224 -0
  274. package/store.js +118 -0
  275. package/store.js.map +1 -0
  276. package/store.ts +193 -0
  277. package/subcommands.js +62 -0
  278. package/subcommands.js.map +1 -0
  279. package/subcommands.ts +77 -0
  280. package/terminal.js +93 -0
  281. package/terminal.js.map +1 -0
  282. package/terminal.ts +128 -0
  283. package/text.js +20 -0
  284. package/text.js.map +1 -0
  285. package/text.ts +37 -0
  286. package/tool.js +76 -0
  287. package/tool.js.map +1 -0
  288. package/tool.ts +157 -0
  289. package/trace_control.js +231 -0
  290. package/trace_control.js.map +1 -0
  291. package/trace_control.ts +233 -0
  292. package/traces.js +138 -0
  293. package/traces.js.map +1 -0
  294. package/traces.ts +160 -0
  295. package/tracker.js +22 -0
  296. package/tracker.js.map +1 -0
  297. package/tracker.ts +27 -0
  298. package/tty.js +82 -0
  299. package/tty.js.map +1 -0
  300. package/tty.ts +142 -0
  301. package/unit_failure.js +178 -0
  302. package/unit_failure.js.map +1 -0
  303. package/unit_failure.ts +191 -0
  304. package/upkeep_thread.js +32 -0
  305. package/upkeep_thread.js.map +1 -0
  306. package/upkeep_thread.ts +35 -0
  307. package/upkeep_worker.ts +27 -0
  308. package/vault.js +186 -0
  309. package/vault.js.map +1 -0
  310. package/vault.ts +220 -0
  311. package/vocab-ids.js +63 -0
  312. package/vocab-ids.js.map +1 -0
  313. package/vocab-ids.ts +62 -0
  314. package/vocab.json +35 -0
  315. package/warm.js +138 -0
  316. package/warm.js.map +1 -0
  317. package/warm.ts +171 -0
  318. package/watch_revision.js +25 -0
  319. package/watch_revision.js.map +1 -0
  320. package/watch_revision.ts +30 -0
  321. package/words.js +29 -0
  322. package/words.js.map +1 -0
  323. package/words.ts +41 -0
  324. package/workspaces.js +40 -0
  325. package/workspaces.js.map +1 -0
  326. package/workspaces.ts +58 -0
  327. package/yak-unit-failure.conf +6 -0
  328. package/yak-unit-handoff.conf +2 -0
  329. package/yak.js +123 -0
  330. package/yak.js.map +1 -0
  331. package/yak.ts +136 -0
package/facets.ts ADDED
@@ -0,0 +1,232 @@
1
+ import { imported as observed, importing } from '@yaks/fp/imports'
2
+ import cli from './package.json' with { type: 'json' }
3
+ import type { Held, Tui, ViewFacet, Views } from './answer.ts'
4
+ import versions from './release.json' with { type: 'json' }
5
+ import exports from './exports.json' with { type: 'json' }
6
+
7
+ /** Whether importing `spec` failed only because its package does not export
8
+ * that subpath: a module it does not have. Anything else that goes wrong
9
+ * importing one — a syntax error, a missing dependency, a throw at module
10
+ * scope — is that module failing, and is rethrown: a host that quietly runs
11
+ * without its rules is worse than one that refuses to start. A package from
12
+ * JSR is named with its version in Deno's refusal.
13
+ *
14
+ * ```ts
15
+ * import { assertEquals } from '@std/assert'
16
+ * let refusal = (message: string) => new TypeError(message)
17
+ * assertEquals(unexported(refusal("Unknown export './vocab' for '@yaks/mcp'.\n Package exports:"), '@yaks/mcp/vocab'), true)
18
+ * assertEquals(unexported(refusal("Unknown export './vocab' for '@yaks/mcp@0.2.12'.\n Package exports:"), 'jsr:@yaks/mcp@0.2.12/vocab'), true)
19
+ * assertEquals(unexported(refusal("Unknown export './vocab' for '@yaks/mcp@0.2.12'."), 'jsr:@yaks/doc@0.2.12/vocab'), false)
20
+ * assertEquals(unexported(refusal('Module not found "file:///p/vocab.ts".'), 'file:///p/vocab.ts'), true)
21
+ * assertEquals(unexported(new SyntaxError('Unexpected token'), '@yaks/mcp/vocab'), false)
22
+ * ```
23
+ */
24
+ export let unexported = (error: unknown, spec: string): boolean => {
25
+ if (!(error instanceof TypeError)) return false
26
+ // A failed batched import may be cached with an importer location. Only
27
+ // its first line identifies the missing module; dependencies still differ.
28
+ let first = error.message.split('\n', 1)[0]
29
+ if (first == `Module not found "${spec}".`) return true
30
+ let pkg = /^(?:jsr:)?(@[^/]+\/[^/@]+)(?:@[^/]+)?\/(.+)$/.exec(spec)
31
+ let said = /^Unknown export '\.\/(.+)' for '(@[^/]+\/[^/@']+)(?:@[^']*)?'\.$/
32
+ .exec(first)
33
+ return !!pkg && !!said && said[1] == pkg[2] && said[2] == pkg[1]
34
+ }
35
+
36
+ /** Whether a plugin exports a subpath, asked of the resolver rather than by
37
+ * importing it: what a process checks before it hands a role to a thread
38
+ * that would only find the facet missing. A plugin named by a path answers
39
+ * yes, since only importing it can tell. */
40
+ export let exported = (plugin: string, name: string): boolean => {
41
+ let key = `${plugin}/${name}`
42
+ try {
43
+ let spec = import.meta.resolve(located(key))
44
+ return spec.startsWith('file:') || (ships(key) ?? true)
45
+ } catch {
46
+ return false
47
+ }
48
+ }
49
+
50
+ /** Whether the release this CLI came from says the package `key` names
51
+ * exports its subpath, or undefined where it does not name the package: a
52
+ * checkout, or a plugin named by path (./release.ts `shipped`).
53
+ *
54
+ * ```ts
55
+ * import { assertEquals } from '@std/assert'
56
+ * let at = { '@yaks/doc': ['.', './vocab'] }
57
+ * assertEquals(ships('@yaks/doc/vocab', at), true)
58
+ * assertEquals(ships('@yaks/doc/routes', at), false)
59
+ * assertEquals(ships('@yaks/tools/vocab', at), undefined)
60
+ * assertEquals(ships('./plugins/mail/vocab', at), undefined)
61
+ * ```
62
+ */
63
+ export let ships = (
64
+ key: string,
65
+ release: Readonly<Record<string, readonly string[]>> = exports,
66
+ ): boolean | undefined => {
67
+ let [scope, name, ...rest] = key.split('/')
68
+ let said = Object.hasOwn(release, `${scope}/${name}`)
69
+ ? release[`${scope}/${name}`]
70
+ : undefined
71
+ return said?.includes(rest.length ? `./${rest.join('/')}` : '.')
72
+ }
73
+
74
+ /** Where a bare `@yaks/…` name is imported from. Inside a workspace the
75
+ * import map resolves it; a `yak` installed from JSR has no map entry for a
76
+ * package it does not itself import (a plugin a config names, the views of a
77
+ * component another plugin declared), so the name goes to JSR at the release
78
+ * at the version this CLI's release pins it to (./release.ts `pinned`), which
79
+ * keeps every plugin and view one coherent set. `resolve` is
80
+ * `import.meta.resolve`, which throws for a name nothing maps.
81
+ *
82
+ * ```ts
83
+ * import { assertEquals } from '@std/assert'
84
+ * let none = (): string => {
85
+ * throw new TypeError('not a dependency')
86
+ * }
87
+ * let at = { '@yaks/tools': '1.2.3' }
88
+ * assertEquals(located('@yaks/tools/views', none, at), 'jsr:@yaks/tools@1.2.3/views')
89
+ * assertEquals(located('@yaks/tools/views', (s) => s, at), '@yaks/tools/views')
90
+ * assertEquals(located('./plugins/mail/vocab', none, at), './plugins/mail/vocab')
91
+ * ```
92
+ */
93
+ export let located = (
94
+ spec: string,
95
+ resolve: (spec: string) => string = import.meta.resolve,
96
+ release: Readonly<Record<string, string>> = versions,
97
+ ): string => {
98
+ if (!spec.startsWith('@yaks/')) return spec
99
+ try {
100
+ resolve(spec)
101
+ return spec
102
+ } catch (error) {
103
+ if (String(error).includes('ERR_PACKAGE_PATH_NOT_EXPORTED')) return spec
104
+ let [scope, name, ...rest] = spec.split('/')
105
+ let version = release[`${scope}/${name}`] ?? cli.version
106
+ return ['jsr:' + scope, `${name}@${version}`, ...rest].join('/')
107
+ }
108
+ }
109
+
110
+ /** `import('<plugin>/<name>')`, or `null` where the package does not export
111
+ * that subpath — a facet, or the `./views` a caller draws with. Each answer is
112
+ * asked for once: a module is imported once a process whoever asks, and a
113
+ * subpath a package does not export stays unexported, where finding that out
114
+ * again costs an import that throws. */
115
+ export let subpath = <M>(plugin: string, name: string): Promise<M | null> => {
116
+ let key = `${plugin}/${name}`
117
+ observed(dependencies.get(key) ?? [])
118
+ let known = imported.get(key) as Promise<M | null> | undefined
119
+ if (known) return known
120
+ let asked = optional<M>(key)
121
+ imported.set(key, asked)
122
+ asked.catch(() => imported.delete(key))
123
+ return asked
124
+ }
125
+ /** Each plugin's `./views`, the ones a config names: warmed as one module
126
+ * graph when a registry asks for several (@yaks/cli answer.ts `registry`). */
127
+ export let pluginViews: Views = Object.assign(
128
+ (plugin: string) => subpath<ViewFacet>(plugin, 'views'),
129
+ {
130
+ warm: (plugins: string[]) =>
131
+ subpaths(plugins.map((p) => [p, 'views'] as const)),
132
+ },
133
+ )
134
+
135
+ /** Each plugin's `./tui`, what a held answer draws with first. */
136
+ export let pluginTui: Tui = (plugin) => subpath<{ views?: Held }>(plugin, 'tui')
137
+
138
+ /** Load selected subpaths and required modules as one module graph where
139
+ * their exports are known: by the resolver for a file, by the release
140
+ * (`ships`) for a package from JSR. Deno otherwise builds a separate
141
+ * dependency graph per concurrent dynamic import, rediscovering shared
142
+ * dependencies for each. Module answers follow the subpath answers; only
143
+ * subpaths can be absent. A JSR package the release does not name still uses
144
+ * the ordinary loader, which alone can say whether its optional export
145
+ * exists. Nothing is written to disk. */
146
+ export let subpaths = async (
147
+ requests: readonly (readonly [plugin: string, name: string])[],
148
+ modules: readonly string[] = [],
149
+ ): Promise<unknown[]> => {
150
+ let pending: { key: string; spec: string; slot: string }[] = []
151
+ for (let [plugin, name] of requests) {
152
+ let key = `${plugin}/${name}`
153
+ observed(dependencies.get(key) ?? [])
154
+ if (imported.has(key) || pending.some((p) => p.key == key)) continue
155
+ let spec: string | undefined
156
+ try {
157
+ spec = import.meta.resolve(key)
158
+ } catch (error) {
159
+ if (unexported(error, key)) {
160
+ imported.set(key, Promise.resolve(null))
161
+ continue
162
+ }
163
+ }
164
+ if (spec?.startsWith('file:')) {
165
+ if (!/\.[cm]?[jt]sx?$/.test(spec)) continue
166
+ } else {
167
+ // From JSR: mapped (spec) or not (located), as the release says.
168
+ let said = ships(key)
169
+ if (said === false) imported.set(key, Promise.resolve(null))
170
+ if (!said) continue
171
+ spec = import.meta.resolve(located(key))
172
+ }
173
+ dependencies.set(key, [spec])
174
+ pending.push({ key, spec, slot: `m${pending.length}` })
175
+ }
176
+ let roots = modules.map((spec, index) => ({
177
+ spec: import.meta.resolve(located(spec)),
178
+ slot: `r${index}`,
179
+ }))
180
+ let required: Promise<unknown>[] = []
181
+ if (pending.length || roots.length) {
182
+ let source = [...pending, ...roots].map(({ spec, slot }) =>
183
+ `export * as ${slot} from ${JSON.stringify(spec)};`
184
+ ).join('\n')
185
+ let loading: Promise<Record<string, unknown>> = importing(
186
+ `data:application/javascript,${encodeURIComponent(source)}`,
187
+ [...pending, ...roots].map(({ spec }) => spec),
188
+ )
189
+ for (let { key, slot } of pending) {
190
+ // The batch cannot distinguish an absent file facet from a broken one.
191
+ // Let the ordinary loader classify each on failure, preserving its
192
+ // optional-export semantics and leaving unrelated modules usable.
193
+ let asked = loading.then(
194
+ (modules) => modules[slot],
195
+ () => optional(key),
196
+ )
197
+ imported.set(key, asked)
198
+ asked.catch(() => imported.delete(key))
199
+ }
200
+ required = roots.map(({ spec, slot }) =>
201
+ loading.then(
202
+ (modules) => modules[slot],
203
+ () => importing(spec),
204
+ )
205
+ )
206
+ }
207
+ return await Promise.all(
208
+ [...requests.map(([plugin, name]) => subpath(plugin, name)), ...required],
209
+ )
210
+ }
211
+
212
+ let imported = new Map<string, Promise<unknown>>()
213
+ let dependencies = new Map<string, string[]>()
214
+ let optional = async <M>(key: string): Promise<M | null> => {
215
+ let spec = located(key)
216
+ let resolved = false
217
+ try {
218
+ // Missing-module errors name the resolved URL, including for a plugin
219
+ // whose declaring package is an absolute path in a remote vocabulary.
220
+ spec = import.meta.resolve(spec)
221
+ resolved = true
222
+ if (!spec.startsWith('file:') && ships(key) === false) return null
223
+ dependencies.set(key, [spec])
224
+ return await importing(spec)
225
+ } catch (error) {
226
+ if (!resolved && String(error).includes('ERR_PACKAGE_PATH_NOT_EXPORTED')) {
227
+ return null
228
+ }
229
+ if (unexported(error, spec)) return null
230
+ throw error
231
+ }
232
+ }
package/feedback.js ADDED
@@ -0,0 +1,54 @@
1
+ import { description, feedback } from "@yaks/feedback";
2
+ import { argsOf } from "@yaks/graph/call";
3
+ import { said, worded } from "@yaks/tools/result";
4
+ import { valued, valueIn } from "@yaks/tools/value";
5
+ import { pinned } from "./release.js";
6
+ import { remote } from "./remote.js";
7
+ import { doorUrl } from "./rpc.js";
8
+ let declaration = {
9
+ name: feedback.name,
10
+ title: 'Send feedback about yak',
11
+ description: description + ' Sign in with yak auth yaks.app to keep the thread under your account. ' + 'If signed out, save the private receipt to read replies to the same thread.',
12
+ destructive: feedback.destructive,
13
+ openWorld: feedback.openWorld,
14
+ positional: [
15
+ 'text'
16
+ ],
17
+ inputSchema: {
18
+ ...feedback.input,
19
+ additionalProperties: false
20
+ }
21
+ };
22
+ let sending = (args)=>({
23
+ ...args,
24
+ yak_version: pinned['@yaks/cli']
25
+ });
26
+ /** The feedback tool a local yak host offers to MCP clients. */ export let feedbackTool = (host)=>({
27
+ ...declaration,
28
+ run: async (call)=>{
29
+ let rows = await host.remote(feedback.name, sending(argsOf(call)), {
30
+ mixedAuth: true
31
+ });
32
+ return [
33
+ {
34
+ ...said(call, worded(rows)),
35
+ output: valued(call, valueIn(rows)).output
36
+ }
37
+ ];
38
+ }
39
+ });
40
+ /** The CLI feedback command also works before a graph has been initialized. */ export let feedbackCommand = {
41
+ ...declaration,
42
+ run: async (args, ctx)=>{
43
+ let rows = await remote(feedback.name, sending(args), {
44
+ url: new URL(doorUrl(ctx.host)).origin,
45
+ mixedAuth: true,
46
+ as: ctx.as,
47
+ state: ctx.state,
48
+ config: ctx.config
49
+ });
50
+ ctx.out(ctx.json ? JSON.stringify(valueIn(rows), null, 2) : worded(rows));
51
+ return 0;
52
+ }
53
+ };
54
+ //# sourceMappingURL=feedback.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"feedback.js","sources":["./feedback.ts"],"names":[],"mappings":"AAAA,SAAS,WAAW,EAAE,QAAQ,8BAAmC;AAEjE,SAAS,MAAM,gCAAqC;AAEpD,SAAS,IAAI,EAAE,MAAM,kCAAuC;AAC5D,SAAS,MAAM,EAAE,OAAO,iCAAsC;AAC9D,SAAS,MAAM,uBAAsB;AACrC,SAAS,MAAM,sBAAqB;AACpC,SAAS,OAAO,mBAAkB;AAGlC,IAAI,cAAc;EAChB,MAAM,SAAS,IAAI;EACnB,OAAO;EACP,aAAa,cACX,4EACA;EACF,aAAa,SAAS,WAAW;EACjC,WAAW,SAAS,SAAS;EAC7B,YAAY;IAAC;GAAO;EACpB,aAAa;IAAE,GAAG,SAAS,KAAK;IAAE,sBAAsB;EAAM;AAChE;AAEA,IAAI,UAAU,CAAC,OAAkC,CAAC;IAChD,GAAG,IAAI;IACP,aAAa,MAAM,CAAC,YAAY;EAClC,CAAC;AAED,8DAA8D,GAC9D,OAAO,IAAI,eAAe,CAAC,OAA0C,CAAC;IACpE,GAAG,WAAW;IACd,KAAK,OAAO;MACV,IAAI,OAAO,MAAM,KAAK,MAAM,CAAE,SAAS,IAAI,EAAE,QAAQ,OAAO,QAAQ;QAClE,WAAW;MACb;MACA,OAAO;QAAC;UACN,GAAG,KAAK,MAAM,OAAO,MAAM;UAC3B,QAAQ,OAAO,MAAM,QAAQ,OAAO,MAAM;QAC5C;OAAE;IACJ;EACF,CAAC,EAAC;AAEF,6EAA6E,GAC7E,OAAO,IAAI,kBAA2B;EACpC,GAAG,WAAW;EACd,KAAK,OAAO,MAAM;IAChB,IAAI,OAAO,MAAM,OAAO,SAAS,IAAI,EAAE,QAAQ,OAAO;MACpD,KAAK,IAAI,IAAI,QAAQ,IAAI,IAAI,GAAG,MAAM;MACtC,WAAW;MACX,IAAI,IAAI,EAAE;MACV,OAAO,IAAI,KAAK;MAChB,QAAQ,IAAI,MAAM;IACpB;IACA,IAAI,GAAG,CAAC,IAAI,IAAI,GAAG,KAAK,SAAS,CAAC,QAAQ,OAAO,MAAM,KAAK,OAAO;IACnE,OAAO;EACT;AACF,EAAC"}
package/feedback.ts ADDED
@@ -0,0 +1,57 @@
1
+ import { description, feedback } from '@yaks/feedback'
2
+ import type { NamedTool } from 'jsr:@yaks/graph@0.2.36'
3
+ import { argsOf } from '@yaks/graph/call'
4
+ import type { Host } from 'jsr:@yaks/host@0.2.36'
5
+ import { said, worded } from '@yaks/tools/result'
6
+ import { valued, valueIn } from '@yaks/tools/value'
7
+ import { pinned } from './release.js'
8
+ import { remote } from './remote.js'
9
+ import { doorUrl } from './rpc.js'
10
+ import type { Command } from './run.ts'
11
+
12
+ let declaration = {
13
+ name: feedback.name,
14
+ title: 'Send feedback about yak',
15
+ description: description +
16
+ ' Sign in with yak auth yaks.app to keep the thread under your account. ' +
17
+ 'If signed out, save the private receipt to read replies to the same thread.',
18
+ destructive: feedback.destructive,
19
+ openWorld: feedback.openWorld,
20
+ positional: ['text'],
21
+ inputSchema: { ...feedback.input, additionalProperties: false },
22
+ }
23
+
24
+ let sending = (args: Record<string, unknown>) => ({
25
+ ...args,
26
+ yak_version: pinned['@yaks/cli'],
27
+ })
28
+
29
+ /** The feedback tool a local yak host offers to MCP clients. */
30
+ export let feedbackTool = (host: Pick<Host, 'remote'>): NamedTool => ({
31
+ ...declaration,
32
+ run: async (call) => {
33
+ let rows = await host.remote!(feedback.name, sending(argsOf(call)), {
34
+ mixedAuth: true,
35
+ })
36
+ return [{
37
+ ...said(call, worded(rows)),
38
+ output: valued(call, valueIn(rows)).output,
39
+ }]
40
+ },
41
+ })
42
+
43
+ /** The CLI feedback command also works before a graph has been initialized. */
44
+ export let feedbackCommand: Command = {
45
+ ...declaration,
46
+ run: async (args, ctx) => {
47
+ let rows = await remote(feedback.name, sending(args), {
48
+ url: new URL(doorUrl(ctx.host)).origin,
49
+ mixedAuth: true,
50
+ as: ctx.as,
51
+ state: ctx.state,
52
+ config: ctx.config,
53
+ })
54
+ ctx.out(ctx.json ? JSON.stringify(valueIn(rows), null, 2) : worded(rows))
55
+ return 0
56
+ },
57
+ }
package/files.js ADDED
@@ -0,0 +1,84 @@
1
+ // File references belong to the client that owns the files. HTTP tools receive
2
+ // only ordinary arguments; they never interpret paths on their own host.
3
+ import { CallError } from "@yaks/tools/errors";
4
+ export let FILES = 'Set "_files":true to read @/absolute/path in string arguments, including nested strings. Omit it for literal @ text.';
5
+ export let fileSchema = (schema)=>({
6
+ ...schema,
7
+ properties: {
8
+ ...schema.properties,
9
+ _files: {
10
+ type: 'boolean'
11
+ }
12
+ }
13
+ });
14
+ let parts = (schema, root)=>{
15
+ let ref = typeof schema.$ref == 'string' && schema.$ref.startsWith('#/') ? schema.$ref.slice(2).split('/').reduce((node, key)=>node?.[key.replace(/~1/g, '/').replace(/~0/g, '~')], root) : undefined;
16
+ return [
17
+ schema,
18
+ ...ref && typeof ref == 'object' ? parts(ref, root) : [],
19
+ ...[
20
+ 'allOf',
21
+ 'anyOf',
22
+ 'oneOf'
23
+ ].flatMap((key)=>Array.isArray(schema[key]) ? schema[key].flatMap((s)=>parts(s, root)) : [])
24
+ ];
25
+ };
26
+ // A schema with no keyword that narrows it accepts any value, and so does an
27
+ // object's undeclared property or an array's undeclared items (JSON Schema's
28
+ // default): a graph_apply bundle's components are strings of this kind.
29
+ let ANY = {};
30
+ let NARROWING = [
31
+ 'type',
32
+ '$ref',
33
+ 'allOf',
34
+ 'anyOf',
35
+ 'oneOf',
36
+ 'enum',
37
+ 'const'
38
+ ];
39
+ let open = (s)=>!NARROWING.some((key)=>key in s);
40
+ let typed = (s, type)=>s.type == type || Array.isArray(s.type) && s.type.includes(type);
41
+ let within = (child)=>child === undefined || child === true ? [
42
+ ANY
43
+ ] : child && typeof child == 'object' ? [
44
+ child
45
+ ] : [];
46
+ let expanded = async (value, schemas, root, read)=>{
47
+ let shapes = schemas.flatMap((s)=>parts(s, root));
48
+ if (typeof value == 'string') {
49
+ let string = shapes.some((s)=>open(s) || typed(s, 'string'));
50
+ if (!string || !value.startsWith('@')) return value;
51
+ try {
52
+ return await read(value.slice(1));
53
+ } catch (err) {
54
+ throw new CallError('file', `Cannot read ${value}: ${err.message}`);
55
+ }
56
+ }
57
+ if (Array.isArray(value)) {
58
+ let items = shapes.flatMap((s)=>open(s) || typed(s, 'array') ? within(s.items) : []);
59
+ return await Promise.all(value.map((v)=>expanded(v, items, root, read)));
60
+ }
61
+ if (value && typeof value == 'object') {
62
+ return Object.fromEntries(await Promise.all(Object.entries(value).map(async ([key, v])=>{
63
+ let children = shapes.flatMap((s)=>open(s) || typed(s, 'object') || s.properties ? within(s.properties?.[key] ?? s.additionalProperties) : []);
64
+ return [
65
+ key,
66
+ await expanded(v, children, root, read)
67
+ ];
68
+ })));
69
+ }
70
+ return value;
71
+ };
72
+ export let fileArgs = async (args, schema, read)=>{
73
+ if (!('_files' in args || '$files' in args)) return args;
74
+ // Keep calls made from the previously published schema working.
75
+ let { _files, $files, ...input } = args;
76
+ let files = _files ?? $files;
77
+ if (typeof files != 'boolean') {
78
+ throw new CallError('file', '_files wants true or false');
79
+ }
80
+ return files ? await expanded(input, [
81
+ schema
82
+ ], schema, read) : input;
83
+ };
84
+ //# sourceMappingURL=files.js.map
package/files.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"files.js","sources":["./files.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,yEAAyE;AACzE,SAAS,SAAS,kCAAuC;AAKzD,OAAO,IAAI,QACT,uHAAsH;AAExH,OAAO,IAAI,aAAa,CAAmB,SAAiB,CAAC;IAC3D,GAAG,MAAM;IACT,YAAY;MACV,GAAG,OAAO,UAAU;MACpB,QAAQ;QAAE,MAAM;MAAU;IAC5B;EACF,CAAC,EAAC;AAEF,IAAI,QAAQ,CAAC,QAAgB;EAC3B,IAAI,MAAM,OAAO,OAAO,IAAI,IAAI,YAAY,OAAO,IAAI,CAAC,UAAU,CAAC,QAC/D,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,KAAK,MAAM,CACtC,CAAC,MAAM,MACJ,MAAiB,CAAC,IAAI,OAAO,CAAC,OAAO,KAAK,OAAO,CAAC,OAAO,KAAK,EACjE,QAEA;EACJ,OAAO;IACL;OACG,OAAO,OAAO,OAAO,WAAW,MAAM,KAAe,QAAQ,EAAE;OAC/D;MAAC;MAAS;MAAS;KAAQ,CAAC,OAAO,CAAC,CAAC,MACtC,MAAM,OAAO,CAAC,MAAM,CAAC,IAAI,IACrB,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,IAAM,MAAM,GAAa,SAC9C,EAAE;GAET;AACH;AAEA,6EAA6E;AAC7E,6EAA6E;AAC7E,wEAAwE;AACxE,IAAI,MAAc,CAAC;AACnB,IAAI,YAAY;EAAC;EAAQ;EAAQ;EAAS;EAAS;EAAS;EAAQ;CAAQ;AAC5E,IAAI,OAAO,CAAC,IAAc,CAAC,UAAU,IAAI,CAAC,CAAC,MAAQ,OAAO;AAC1D,IAAI,QAAQ,CAAC,GAAW,OACtB,EAAE,IAAI,IAAI,QAAQ,MAAM,OAAO,CAAC,EAAE,IAAI,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC;AAC7D,IAAI,SAAS,CAAC,QACZ,UAAU,aAAa,UAAU,OAC7B;IAAC;GAAI,GACL,SAAS,OAAO,SAAS,WACzB;IAAC;GAAgB,GACjB,EAAE;AAER,IAAI,WAAW,OACb,OACA,SACA,MACA;EAEA,IAAI,SAAS,QAAQ,OAAO,CAAC,CAAC,IAAM,MAAM,GAAG;EAC7C,IAAI,OAAO,SAAS,UAAU;IAC5B,IAAI,SAAS,OAAO,IAAI,CAAC,CAAC,IAAM,KAAK,MAAM,MAAM,GAAG;IACpD,IAAI,CAAC,UAAU,CAAC,MAAM,UAAU,CAAC,MAAM,OAAO;IAC9C,IAAI;MACF,OAAO,MAAM,KAAK,MAAM,KAAK,CAAC;IAChC,EAAE,OAAO,KAAK;MACZ,MAAM,IAAI,UACR,QACA,CAAC,YAAY,EAAE,MAAM,EAAE,EAAE,AAAC,IAAc,OAAO,EAAE;IAErD;EACF;EACA,IAAI,MAAM,OAAO,CAAC,QAAQ;IACxB,IAAI,QAAQ,OAAO,OAAO,CAAC,CAAC,IAC1B,KAAK,MAAM,MAAM,GAAG,WAAW,OAAO,EAAE,KAAK,IAAI,EAAE;IAErD,OAAO,MAAM,QAAQ,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,IAAM,SAAS,GAAG,OAAO,MAAM;EACrE;EACA,IAAI,SAAS,OAAO,SAAS,UAAU;IACrC,OAAO,OAAO,WAAW,CACvB,MAAM,QAAQ,GAAG,CACf,OAAO,OAAO,CAAC,OAAO,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE;MACvC,IAAI,WAAW,OAAO,OAAO,CAAC,CAAC,IAC7B,KAAK,MAAM,MAAM,GAAG,aAAa,EAAE,UAAU,GACzC,OACA,AAAC,EAAE,UAAU,EAAa,CAAC,IAAI,IAAI,EAAE,oBAAoB,IAEzD,EAAE;MAER,OAAO;QAAC;QAAK,MAAM,SAAS,GAAG,UAAU,MAAM;OAAM;IACvD;EAGN;EACA,OAAO;AACT;AAEA,OAAO,IAAI,WAAW,OACpB,MACA,QACA;EAEA,IAAI,CAAC,CAAC,YAAY,QAAQ,YAAY,IAAI,GAAG,OAAO;EACpD,gEAAgE;EAChE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,GAAG;EACnC,IAAI,QAAQ,UAAU;EACtB,IAAI,OAAO,SAAS,WAAW;IAC7B,MAAM,IAAI,UAAU,QAAQ;EAC9B;EACA,OAAO,QACH,MAAM,SAAS,OAAO;IAAC;GAAO,EAAE,QAAQ,QACxC;AACN,EAAC"}
package/files.ts ADDED
@@ -0,0 +1,112 @@
1
+ // File references belong to the client that owns the files. HTTP tools receive
2
+ // only ordinary arguments; they never interpret paths on their own host.
3
+ import { CallError } from '@yaks/tools/errors'
4
+
5
+ type Schema = Record<string, unknown>
6
+ export type ReadFile = (path: string) => string | Promise<string>
7
+
8
+ export let FILES =
9
+ 'Set "_files":true to read @/absolute/path in string arguments, including nested strings. Omit it for literal @ text.'
10
+
11
+ export let fileSchema = <S extends Schema>(schema: S): S => ({
12
+ ...schema,
13
+ properties: {
14
+ ...schema.properties as Schema,
15
+ _files: { type: 'boolean' },
16
+ },
17
+ })
18
+
19
+ let parts = (schema: Schema, root: Schema): Schema[] => {
20
+ let ref = typeof schema.$ref == 'string' && schema.$ref.startsWith('#/')
21
+ ? schema.$ref.slice(2).split('/').reduce<unknown>(
22
+ (node, key) =>
23
+ (node as Schema)?.[key.replace(/~1/g, '/').replace(/~0/g, '~')],
24
+ root,
25
+ )
26
+ : undefined
27
+ return [
28
+ schema,
29
+ ...ref && typeof ref == 'object' ? parts(ref as Schema, root) : [],
30
+ ...['allOf', 'anyOf', 'oneOf'].flatMap((key) =>
31
+ Array.isArray(schema[key])
32
+ ? schema[key].flatMap((s) => parts(s as Schema, root))
33
+ : []
34
+ ),
35
+ ]
36
+ }
37
+
38
+ // A schema with no keyword that narrows it accepts any value, and so does an
39
+ // object's undeclared property or an array's undeclared items (JSON Schema's
40
+ // default): a graph_apply bundle's components are strings of this kind.
41
+ let ANY: Schema = {}
42
+ let NARROWING = ['type', '$ref', 'allOf', 'anyOf', 'oneOf', 'enum', 'const']
43
+ let open = (s: Schema) => !NARROWING.some((key) => key in s)
44
+ let typed = (s: Schema, type: string) =>
45
+ s.type == type || Array.isArray(s.type) && s.type.includes(type)
46
+ let within = (child: unknown): Schema[] =>
47
+ child === undefined || child === true
48
+ ? [ANY]
49
+ : child && typeof child == 'object'
50
+ ? [child as Schema]
51
+ : []
52
+
53
+ let expanded = async (
54
+ value: unknown,
55
+ schemas: Schema[],
56
+ root: Schema,
57
+ read: ReadFile,
58
+ ): Promise<unknown> => {
59
+ let shapes = schemas.flatMap((s) => parts(s, root))
60
+ if (typeof value == 'string') {
61
+ let string = shapes.some((s) => open(s) || typed(s, 'string'))
62
+ if (!string || !value.startsWith('@')) return value
63
+ try {
64
+ return await read(value.slice(1))
65
+ } catch (err) {
66
+ throw new CallError(
67
+ 'file',
68
+ `Cannot read ${value}: ${(err as Error).message}`,
69
+ )
70
+ }
71
+ }
72
+ if (Array.isArray(value)) {
73
+ let items = shapes.flatMap((s) =>
74
+ open(s) || typed(s, 'array') ? within(s.items) : []
75
+ )
76
+ return await Promise.all(value.map((v) => expanded(v, items, root, read)))
77
+ }
78
+ if (value && typeof value == 'object') {
79
+ return Object.fromEntries(
80
+ await Promise.all(
81
+ Object.entries(value).map(async ([key, v]) => {
82
+ let children = shapes.flatMap((s) =>
83
+ open(s) || typed(s, 'object') || s.properties
84
+ ? within(
85
+ (s.properties as Schema)?.[key] ?? s.additionalProperties,
86
+ )
87
+ : []
88
+ )
89
+ return [key, await expanded(v, children, root, read)]
90
+ }),
91
+ ),
92
+ )
93
+ }
94
+ return value
95
+ }
96
+
97
+ export let fileArgs = async (
98
+ args: Record<string, unknown>,
99
+ schema: Schema,
100
+ read: ReadFile,
101
+ ): Promise<Record<string, unknown>> => {
102
+ if (!('_files' in args || '$files' in args)) return args
103
+ // Keep calls made from the previously published schema working.
104
+ let { _files, $files, ...input } = args
105
+ let files = _files ?? $files
106
+ if (typeof files != 'boolean') {
107
+ throw new CallError('file', '_files wants true or false')
108
+ }
109
+ return files
110
+ ? await expanded(input, [schema], schema, read) as Record<string, unknown>
111
+ : input
112
+ }
package/get_starts.js ADDED
@@ -0,0 +1,31 @@
1
+ import * as system from "@yaks/process/system";
2
+ import * as disk from "@yaks/file/io";
3
+ // An explicitly armed, short-lived PID-local caller capture. Reading an
4
+ // absent sidecar never creates it. Consumption only decrements local memory.
5
+ export let getStarts = (db, pid = system.pid, now = Date.now)=>{
6
+ let file = `${db}.get-starts.json`;
7
+ let arm = '', left = 0, until = 0, checked = 0;
8
+ let kind = '', match = '';
9
+ return (event)=>{
10
+ let at = now();
11
+ if (at >= checked) {
12
+ checked = at + 250;
13
+ try {
14
+ let x = JSON.parse(disk.readTextFileSync(file));
15
+ if (x.pid == pid && typeof x.arm == 'string' && x.arm != arm && Number.isInteger(x.next) && x.next > 0 && x.next <= 16 && Number.isFinite(x.until) && x.until > at && x.until <= at + 30_000) {
16
+ arm = x.arm;
17
+ left = x.next;
18
+ until = x.until;
19
+ kind = typeof x.kind == 'string' ? x.kind : '';
20
+ match = typeof x.match == 'string' ? x.match.slice(0, 64) : '';
21
+ }
22
+ } catch {}
23
+ }
24
+ if (at >= until || left <= 0) return false;
25
+ if (kind && event?.kind != kind) return false;
26
+ if (match && !event?.sql?.includes(match)) return false;
27
+ left--;
28
+ return true;
29
+ };
30
+ };
31
+ //# sourceMappingURL=get_starts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get_starts.js","sources":["./get_starts.ts"],"names":[],"mappings":"AAAA,YAAY,wCAA6C;AACzD,YAAY,+BAAoC;AAChD,wEAAwE;AACxE,6EAA6E;AAC7E,OAAO,IAAI,YAAY,CAAC,IAAY,MAAM,OAAO,GAAG,EAAE,MAAM,KAAK,GAAG;EAClE,IAAI,OAAO,GAAG,GAAG,gBAAgB,CAAC;EAClC,IAAI,MAAM,IAAI,OAAO,GAAG,QAAQ,GAAG,UAAU;EAC7C,IAAI,OAAO,IAAI,QAAQ;EACvB,OAAO,CAAC;IACN,IAAI,KAAK;IACT,IAAI,MAAM,SAAS;MACjB,UAAU,KAAK;MACf,IAAI;QACF,IAAI,IAAI,KAAK,KAAK,CAAC,KAAK,gBAAgB,CAAC;QACzC,IACE,EAAE,GAAG,IAAI,OAAO,OAAO,EAAE,GAAG,IAAI,YAAY,EAAE,GAAG,IAAI,OACrD,OAAO,SAAS,CAAC,EAAE,IAAI,KAAK,EAAE,IAAI,GAAG,KAAK,EAAE,IAAI,IAAI,MACpD,OAAO,QAAQ,CAAC,EAAE,KAAK,KAAK,EAAE,KAAK,GAAG,MAAM,EAAE,KAAK,IAAI,KAAK,QAC5D;UACA,MAAM,EAAE,GAAG;UACX,OAAO,EAAE,IAAI;UACb,QAAQ,EAAE,KAAK;UACf,OAAO,OAAO,EAAE,IAAI,IAAI,WAAW,EAAE,IAAI,GAAG;UAC5C,QAAQ,OAAO,EAAE,KAAK,IAAI,WAAW,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,MAAM;QAC9D;MACF,EAAE,OAAM,CAAiE;IAC3E;IACA,IAAI,MAAM,SAAS,QAAQ,GAAG,OAAO;IACrC,IAAI,QAAQ,OAAO,QAAQ,MAAM,OAAO;IACxC,IAAI,SAAS,CAAC,OAAO,KAAK,SAAS,QAAQ,OAAO;IAClD;IACA,OAAO;EACT;AACF,EAAC"}
package/get_starts.ts ADDED
@@ -0,0 +1,34 @@
1
+ import * as system from '@yaks/process/system'
2
+ import * as disk from '@yaks/file/io'
3
+ // An explicitly armed, short-lived PID-local caller capture. Reading an
4
+ // absent sidecar never creates it. Consumption only decrements local memory.
5
+ export let getStarts = (db: string, pid = system.pid, now = Date.now) => {
6
+ let file = `${db}.get-starts.json`
7
+ let arm = '', left = 0, until = 0, checked = 0
8
+ let kind = '', match = ''
9
+ return (event?: { kind: string; sql?: string }) => {
10
+ let at = now()
11
+ if (at >= checked) {
12
+ checked = at + 250
13
+ try {
14
+ let x = JSON.parse(disk.readTextFileSync(file))
15
+ if (
16
+ x.pid == pid && typeof x.arm == 'string' && x.arm != arm &&
17
+ Number.isInteger(x.next) && x.next > 0 && x.next <= 16 &&
18
+ Number.isFinite(x.until) && x.until > at && x.until <= at + 30_000
19
+ ) {
20
+ arm = x.arm
21
+ left = x.next
22
+ until = x.until
23
+ kind = typeof x.kind == 'string' ? x.kind : ''
24
+ match = typeof x.match == 'string' ? x.match.slice(0, 64) : ''
25
+ }
26
+ } catch { /* Missing or malformed controls cannot affect graph reads. */ }
27
+ }
28
+ if (at >= until || left <= 0) return false
29
+ if (kind && event?.kind != kind) return false
30
+ if (match && !event?.sql?.includes(match)) return false
31
+ left--
32
+ return true
33
+ }
34
+ }