@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/external.ts ADDED
@@ -0,0 +1,435 @@
1
+ import { fault } from '@yaks/api/refuse'
2
+ import * as system from '@yaks/process/system'
3
+ import * as disk from '@yaks/file/io'
4
+ import { command as launchCommand } from '@yaks/process/command'
5
+ // `serve` owns HTTP, not duties. Fill uncovered duty roles with an independent
6
+ // invocation of this checkout's CLI; singleton services still take the host's
7
+ // leases, and effects remain a pool. A fallback worker drains when its requesting web host ends.
8
+
9
+ import type { Bundle, Graph, News } from 'jsr:@yaks/graph@0.2.36'
10
+ import {
11
+ EXIT,
12
+ gone,
13
+ PROCESS,
14
+ type Store,
15
+ store as machine,
16
+ } from '@yaks/process'
17
+ import { resolve } from 'node:path'
18
+ import { launching } from './release.js'
19
+ import { FLAGS } from './runtime.js'
20
+
21
+ /** The commits other hosts made, handed over as they arrive (@yaks/host). */
22
+ export type Feed = (each: (news: News) => void) => () => void
23
+
24
+ /** Which duty roles no live process serves, kept rather than read again.
25
+ *
26
+ * Every unexited process, read whole, scans the whole process history, and the
27
+ * feed hands a web a process row for every `yak` command run beside it, so
28
+ * reading them all on each change and every second held the web's one thread
29
+ * for hundreds of milliseconds at a time. They are read once. After that the
30
+ * rows the feed hears say which processes took up or gave up a duty role, and
31
+ * a look asks only whether the pids of the ones known still live; when the
32
+ * feed missed some, they are read once more. A read takes long enough for the
33
+ * feed to speak meanwhile, and may have looked before what it says, so what it
34
+ * hears during a read is folded into what the read found. A store with no
35
+ * feed says nothing of what changed, so each look reads it whole. */
36
+ export let coverage = (
37
+ processes: Store,
38
+ roles: readonly string[],
39
+ over: (eid: string) => Promise<boolean> = (eid) => gone(processes, eid),
40
+ fed = true,
41
+ ) => {
42
+ let wanted = new Set(roles)
43
+ // The duty roles a process row says it serves, or undefined when the row
44
+ // does not say (a patch that leaves its roles as they were).
45
+ let serves = (row: Bundle): string[] | undefined => {
46
+ let process = row[PROCESS]
47
+ if (process === null) return []
48
+ if (!process || typeof process != 'object' || !('roles' in process)) return
49
+ let said = process.roles
50
+ return Array.isArray(said) ? said.filter((role) => wanted.has(role)) : []
51
+ }
52
+ let known: Map<string, string[]> | undefined
53
+ // What the feed said of each process while a read was under way, in order.
54
+ let during: [string, string[]][] | undefined
55
+ let fold = (into: Map<string, string[]>, eid: string, duties: string[]) => {
56
+ if (duties.length) into.set(eid, duties)
57
+ else into.delete(eid)
58
+ }
59
+ let read = async (): Promise<Map<string, string[]>> => {
60
+ let said: [string, string[]][] = during = []
61
+ let found = new Map(
62
+ (await processes.running()).flatMap((row) => {
63
+ let duties = serves(row) ?? []
64
+ return duties.length ? [[row.entity.eid, duties] as const] : []
65
+ }),
66
+ )
67
+ // Missed news while reading leaves the read's moment unknown: read again.
68
+ if (during !== said) return read()
69
+ during = undefined
70
+ for (let [eid, duties] of said) fold(found, eid, duties)
71
+ return found
72
+ }
73
+ return {
74
+ /** Fold what other hosts committed; true when coverage may have moved. */
75
+ hear: ({ applied, missed }: News): boolean => {
76
+ if (missed) known = during = undefined
77
+ let moved = missed
78
+ for (let row of applied.flat()) {
79
+ let eid = row.entity.eid
80
+ let ended = row.$delete || row.tombstone || row[EXIT]
81
+ let duties = ended ? [] : serves(row)
82
+ if (!duties) continue
83
+ moved ||= duties.length > 0 || !!known?.has(eid) || !!during
84
+ during?.push([eid, duties])
85
+ if (known) fold(known, eid, duties)
86
+ }
87
+ return moved
88
+ },
89
+ /** The roles asked for that no live, unexited process serves. */
90
+ missing: async (): Promise<string[]> => {
91
+ if (!wanted.size) return []
92
+ if (!known || !fed) known = await read()
93
+ let needed = new Set(roles)
94
+ for (let [eid, duties] of [...known]) {
95
+ if (!duties.some((role) => needed.has(role))) continue
96
+ if (await over(eid)) known.delete(eid)
97
+ else duties.forEach((role) => needed.delete(role))
98
+ if (!needed.size) break
99
+ }
100
+ return roles.filter((role) => needed.has(role))
101
+ },
102
+ }
103
+ }
104
+
105
+ export type Monitor = {
106
+ /** The initial inspection and recovery attempt, not the monitor's lifetime. */
107
+ checked: Promise<void>
108
+ /** Stop observations and unfinished launches; successful workers watch the starter. */
109
+ close: () => Promise<void>
110
+ }
111
+
112
+ type Report = (error: unknown, role?: string) => void | Promise<void>
113
+ type After = (ms: number, run: () => void | Promise<void>) => () => void
114
+
115
+ /** How long a duty role lost after start-up has to be taken up again before
116
+ * it is a failure. A worker its supervisor restarts in place declares its
117
+ * roles again within seconds. */
118
+ export let GRACE = 30_000
119
+
120
+ /** Continuous coverage, with one inspection/launch at a time. Notifications
121
+ * inspect immediately; polling also catches vanished pids without exit rows.
122
+ * What the first inspection finds uncovered is start-up: started at once and
123
+ * never reported. A role lost after that is reported and started only once it
124
+ * has stayed unserved for `grace`, since a stand-in started sooner races the
125
+ * restarting worker for its service leases and keeps them, on this web's
126
+ * code, for as long as this web runs. Launch failures retry at most once per
127
+ * interval, even during a change storm. */
128
+ export let monitor = (options: {
129
+ uncovered: () => Promise<string[]>
130
+ start: (roles: string[], signal: AbortSignal) => Promise<void>
131
+ report: Report
132
+ subscribe?: (changed: () => void) => () => void
133
+ signal?: AbortSignal
134
+ interval?: number
135
+ grace?: number
136
+ after?: After
137
+ now?: () => number
138
+ }): Monitor => {
139
+ let interval = options.interval ?? 1000
140
+ if (!Number.isFinite(interval) || interval <= 0) {
141
+ throw new RangeError('Duty coverage interval must be positive and finite')
142
+ }
143
+ let grace = options.grace ?? GRACE
144
+ if (!Number.isFinite(grace) || grace < 0) {
145
+ throw new RangeError('Duty coverage grace must be finite, not negative')
146
+ }
147
+ let after: After = options.after ?? ((ms, run) => {
148
+ let timer = setTimeout(run, ms)
149
+ return () => clearTimeout(timer)
150
+ })
151
+ let now = options.now ?? Date.now
152
+ let stop = new AbortController()
153
+ let off = () => {}
154
+ let cancel = () => {}
155
+ let busy: Promise<void> | undefined
156
+ let dirty = false
157
+ // Each uncovered role: since when, and whether its loss was reported.
158
+ let lost: Map<string, { since: number; said: boolean }> | undefined
159
+ let retry = 0
160
+ // A telemetry outage must not prevent restoring coverage or retrying it.
161
+ let report = (error: unknown, role?: string) => {
162
+ try {
163
+ // Invoke before launch, but never wait for tracker delivery: the tracker
164
+ // may itself need the duty we are restoring. The host owns its flush.
165
+ void Promise.resolve(options.report(error, role)).catch(() => {})
166
+ } catch { /* the host owns telemetry delivery */ }
167
+ }
168
+ let check = async () => {
169
+ try {
170
+ let needed = await options.uncovered()
171
+ if (stop.signal.aborted) return
172
+ // What the first inspection finds is start-up: due at once, and no
173
+ // loss to report. A role lost later is due once it outlasts the grace.
174
+ let at = now()
175
+ let before = lost
176
+ let found = (role: string) =>
177
+ before?.get(role) ??
178
+ (before
179
+ ? { since: at, said: false }
180
+ : { since: -Infinity, said: true })
181
+ let losses = lost = new Map(needed.map((role) => [role, found(role)]))
182
+ let due = needed.filter((role) => at - losses.get(role)!.since >= grace)
183
+ for (let role of due) {
184
+ let loss = losses.get(role)!
185
+ if (loss.said) continue
186
+ loss.said = true
187
+ report(new Error(`No live process serves duty role "${role}"`), role)
188
+ }
189
+ if (!due.length || stop.signal.aborted || now() < retry) return
190
+ // Set before launching: its own process writes can notify us too.
191
+ retry = now() + interval
192
+ try {
193
+ await options.start(due, stop.signal)
194
+ } catch (error) {
195
+ retry = now() + interval
196
+ if (!stop.signal.aborted) {
197
+ for (let role of due) report(error, role)
198
+ }
199
+ }
200
+ } catch (error) {
201
+ if (!stop.signal.aborted) report(error)
202
+ }
203
+ }
204
+ let request = (): Promise<void> => {
205
+ if (stop.signal.aborted) return Promise.resolve()
206
+ dirty = true
207
+ if (busy) return busy
208
+ cancel()
209
+ busy = (async () => {
210
+ // Yield before inspecting so `busy` is assigned even for sync seams.
211
+ await Promise.resolve()
212
+ while (dirty && !stop.signal.aborted) {
213
+ dirty = false
214
+ await check()
215
+ }
216
+ })().finally(() => {
217
+ busy = undefined
218
+ if (!stop.signal.aborted) cancel = after(interval, request)
219
+ })
220
+ return busy
221
+ }
222
+ let close = async () => {
223
+ if (!stop.signal.aborted) {
224
+ stop.abort()
225
+ cancel()
226
+ off()
227
+ options.signal?.removeEventListener('abort', abort)
228
+ }
229
+ await busy
230
+ }
231
+ let abort = () => void close()
232
+ if (options.signal?.aborted) stop.abort()
233
+ else {
234
+ options.signal?.addEventListener('abort', abort, { once: true })
235
+ off = options.subscribe?.(() => void request()) ?? off
236
+ }
237
+ return { checked: request(), close }
238
+ }
239
+
240
+ type Child = {
241
+ pid: number
242
+ status: Promise<{ code: number }>
243
+ unref: () => void
244
+ kill: (signal: 'SIGTERM') => void
245
+ /** The end of what the worker wrote to stderr, once it closes. */
246
+ told?: Promise<string>
247
+ }
248
+
249
+ /** The last `limit` characters `stream` carries, once it ends. */
250
+ export let tail = async (
251
+ stream: ReadableStream<Uint8Array>,
252
+ limit = 4000,
253
+ ): Promise<string> => {
254
+ let text = ''
255
+ let decoder = new TextDecoder()
256
+ for await (let chunk of stream) {
257
+ text = (text + decoder.decode(chunk, { stream: true })).slice(-limit)
258
+ }
259
+ return (text + decoder.decode()).trim()
260
+ }
261
+
262
+ // What the worker said before it exited, waiting at most a second for its
263
+ // stderr to close: a process it started may still hold it open.
264
+ let telling = async (child: Child): Promise<string> => {
265
+ let timer: ReturnType<typeof setTimeout> | undefined
266
+ let late = new Promise<string>((done) => timer = setTimeout(done, 1000, ''))
267
+ try {
268
+ return await Promise.race([child.told ?? '', late])
269
+ } finally {
270
+ clearTimeout(timer)
271
+ }
272
+ }
273
+
274
+ /** Readiness is written only after the worker has assembled its duty host.
275
+ * Death and timeout are errors, not a web server silently leaving work owed.
276
+ * Only failed launches are stopped; this is not the managed process launcher. */
277
+ export let ready = async (
278
+ child: Child,
279
+ read: () => Promise<string | undefined>,
280
+ timeout = 120000,
281
+ pause: () => Promise<void> = () =>
282
+ new Promise((done) => setTimeout(done, 50)),
283
+ now: () => number = Date.now,
284
+ signal?: AbortSignal,
285
+ ): Promise<void> => {
286
+ let ended: number | undefined
287
+ child.unref()
288
+ child.status.then((status) => ended = status.code, () => ended = -1)
289
+ let deadline = now() + timeout
290
+ let abort = () => {}
291
+ let cancelled = new Promise<never>((_done, reject) => {
292
+ abort = () => reject(signal?.reason ?? new Error('Duty launch cancelled'))
293
+ if (signal?.aborted) abort()
294
+ else signal?.addEventListener('abort', abort, { once: true })
295
+ })
296
+ try {
297
+ while (true) {
298
+ let said = await Promise.race([read(), cancelled])
299
+ signal?.throwIfAborted()
300
+ if (ended != null) {
301
+ let told = await telling(child)
302
+ throw new Error(
303
+ `Duty worker exited before readiness (code ${ended})` +
304
+ (told ? `:\n${told}` : ''),
305
+ )
306
+ }
307
+ if (said?.trim() == String(child.pid)) return
308
+ if (now() >= deadline) {
309
+ throw new Error(`Duty worker did not become ready within ${timeout}ms`)
310
+ }
311
+ await Promise.race([pause(), cancelled])
312
+ }
313
+ } catch (error) {
314
+ if (ended == null) {
315
+ try {
316
+ child.kill('SIGTERM')
317
+ } catch (failure) {
318
+ if (!(failure instanceof disk.errors.NotFound)) throw failure
319
+ }
320
+ }
321
+ throw error
322
+ } finally {
323
+ signal?.removeEventListener('abort', abort)
324
+ }
325
+ }
326
+
327
+ // Each worker's open stdin, held for as long as the worker runs.
328
+ let tethers = new Set<WritableStream<Uint8Array>>()
329
+
330
+ let start = async (
331
+ path: string,
332
+ roles: string[],
333
+ signal: AbortSignal,
334
+ ): Promise<void> => {
335
+ let dir = await disk.makeTempDir({ prefix: 'yak-work-' })
336
+ let file = `${dir}/ready`
337
+ // The worker keeps its code record beside its ready file for as long as it
338
+ // runs (./code.ts), so the dir goes once the worker has ended.
339
+ let clear = () =>
340
+ disk.remove(dir, { recursive: true }).catch((error) =>
341
+ fault(error, `removing ${dir}`)
342
+ )
343
+ let launched = false
344
+ try {
345
+ // A detached child keeps the worker outside web shutdown's process group,
346
+ // on macOS too, which ships no setsid(1). Its stdin is the tether: this
347
+ // web holds the pipe and never writes it, so the worker sees it close when
348
+ // the web ends, however it ends. Never call `yak` from PATH: it may name
349
+ // another checkout.
350
+ signal.throwIfAborted()
351
+ // Role names may start with @ (a package service). The CLI expands @file
352
+ // values, so pass the list through a file rather than as a literal path.
353
+ let selected = `${dir}/roles`
354
+ await disk.writeTextFile(selected, roles.join(','))
355
+ let child = launchCommand(system.execPath(), {
356
+ args: [
357
+ 'run',
358
+ ...FLAGS,
359
+ '--config',
360
+ await launching(() => Promise.resolve(dir)),
361
+ // The `yak` this command runs, beside its config: a command from a
362
+ // checkout runs its snapshot's (./runtime.ts `launch`).
363
+ new URL('./yak.ts', import.meta.url).href,
364
+ '--config',
365
+ resolve(path),
366
+ 'work',
367
+ '--tethered',
368
+ '--roles',
369
+ `@${selected}`,
370
+ '--ready',
371
+ file,
372
+ ],
373
+ stdin: 'piped',
374
+ stdout: 'null',
375
+ // Read to its end, so a worker that dies says why; it never fills.
376
+ stderr: 'piped',
377
+ detached: true,
378
+ }).spawn()
379
+ launched = true
380
+ child.status.then(clear, clear)
381
+ let told = tail(child.stderr).catch((error) =>
382
+ `stderr unreadable: ${error}`
383
+ )
384
+ tethers.add(child.stdin)
385
+ let untie = () => void tethers.delete(child.stdin)
386
+ child.status.then(untie, untie)
387
+ await ready(
388
+ {
389
+ pid: child.pid,
390
+ status: child.status,
391
+ unref: () => child.unref(),
392
+ kill: (signal) => child.kill(signal),
393
+ told,
394
+ },
395
+ async () => {
396
+ try {
397
+ return await disk.readTextFile(file)
398
+ } catch (error) {
399
+ if (error instanceof disk.errors.NotFound) return undefined
400
+ throw error
401
+ }
402
+ },
403
+ undefined,
404
+ undefined,
405
+ undefined,
406
+ signal,
407
+ )
408
+ } catch (error) {
409
+ if (!launched) await clear()
410
+ throw error
411
+ }
412
+ }
413
+
414
+ /** Ensure duties outside this web host, without importing their facets here.
415
+ * The host's feed observes independent workers; polling covers dead pids and
416
+ * stores without a feed. A web with no inline duties still owns this monitor. */
417
+ export let external = (
418
+ graph: Pick<Graph, 'read' | 'apply' | 'get'>,
419
+ path: string,
420
+ roles: readonly string[],
421
+ options: { report: Report; signal: AbortSignal; feed?: Feed },
422
+ ): Monitor => {
423
+ if (!roles.length) {
424
+ return { checked: Promise.resolve(), close: () => Promise.resolve() }
425
+ }
426
+ let { feed, ...rest } = options
427
+ let covered = coverage(machine(graph), roles, undefined, !!feed)
428
+ return monitor({
429
+ ...rest,
430
+ subscribe: feed &&
431
+ ((changed) => feed((news) => void (covered.hear(news) && changed()))),
432
+ uncovered: covered.missing,
433
+ start: (roles, signal) => start(path, roles, signal),
434
+ })
435
+ }
package/facets.js ADDED
@@ -0,0 +1,214 @@
1
+ import { imported as observed, importing } from "@yaks/fp/imports";
2
+ import cli from './package.json' with {
3
+ type: 'json'
4
+ };
5
+ import versions from './release.json' with {
6
+ type: 'json'
7
+ };
8
+ import exports from './exports.json' with {
9
+ type: 'json'
10
+ };
11
+ /** Whether importing `spec` failed only because its package does not export
12
+ * that subpath: a module it does not have. Anything else that goes wrong
13
+ * importing one — a syntax error, a missing dependency, a throw at module
14
+ * scope — is that module failing, and is rethrown: a host that quietly runs
15
+ * without its rules is worse than one that refuses to start. A package from
16
+ * JSR is named with its version in Deno's refusal.
17
+ *
18
+ * ```ts
19
+ * import { assertEquals } from '@std/assert'
20
+ * let refusal = (message: string) => new TypeError(message)
21
+ * assertEquals(unexported(refusal("Unknown export './vocab' for '@yaks/mcp'.\n Package exports:"), '@yaks/mcp/vocab'), true)
22
+ * assertEquals(unexported(refusal("Unknown export './vocab' for '@yaks/mcp@0.2.12'.\n Package exports:"), 'jsr:@yaks/mcp@0.2.12/vocab'), true)
23
+ * assertEquals(unexported(refusal("Unknown export './vocab' for '@yaks/mcp@0.2.12'."), 'jsr:@yaks/doc@0.2.12/vocab'), false)
24
+ * assertEquals(unexported(refusal('Module not found "file:///p/vocab.ts".'), 'file:///p/vocab.ts'), true)
25
+ * assertEquals(unexported(new SyntaxError('Unexpected token'), '@yaks/mcp/vocab'), false)
26
+ * ```
27
+ */ export let unexported = (error, spec)=>{
28
+ if (!(error instanceof TypeError)) return false;
29
+ // A failed batched import may be cached with an importer location. Only
30
+ // its first line identifies the missing module; dependencies still differ.
31
+ let first = error.message.split('\n', 1)[0];
32
+ if (first == `Module not found "${spec}".`) return true;
33
+ let pkg = /^(?:jsr:)?(@[^/]+\/[^/@]+)(?:@[^/]+)?\/(.+)$/.exec(spec);
34
+ let said = /^Unknown export '\.\/(.+)' for '(@[^/]+\/[^/@']+)(?:@[^']*)?'\.$/.exec(first);
35
+ return !!pkg && !!said && said[1] == pkg[2] && said[2] == pkg[1];
36
+ };
37
+ /** Whether a plugin exports a subpath, asked of the resolver rather than by
38
+ * importing it: what a process checks before it hands a role to a thread
39
+ * that would only find the facet missing. A plugin named by a path answers
40
+ * yes, since only importing it can tell. */ export let exported = (plugin, name)=>{
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
+ /** Whether the release this CLI came from says the package `key` names
50
+ * exports its subpath, or undefined where it does not name the package: a
51
+ * checkout, or a plugin named by path (./release.ts `shipped`).
52
+ *
53
+ * ```ts
54
+ * import { assertEquals } from '@std/assert'
55
+ * let at = { '@yaks/doc': ['.', './vocab'] }
56
+ * assertEquals(ships('@yaks/doc/vocab', at), true)
57
+ * assertEquals(ships('@yaks/doc/routes', at), false)
58
+ * assertEquals(ships('@yaks/tools/vocab', at), undefined)
59
+ * assertEquals(ships('./plugins/mail/vocab', at), undefined)
60
+ * ```
61
+ */ export let ships = (key, release = exports)=>{
62
+ let [scope, name, ...rest] = key.split('/');
63
+ let said = Object.hasOwn(release, `${scope}/${name}`) ? release[`${scope}/${name}`] : undefined;
64
+ return said?.includes(rest.length ? `./${rest.join('/')}` : '.');
65
+ };
66
+ /** Where a bare `@yaks/…` name is imported from. Inside a workspace the
67
+ * import map resolves it; a `yak` installed from JSR has no map entry for a
68
+ * package it does not itself import (a plugin a config names, the views of a
69
+ * component another plugin declared), so the name goes to JSR at the release
70
+ * at the version this CLI's release pins it to (./release.ts `pinned`), which
71
+ * keeps every plugin and view one coherent set. `resolve` is
72
+ * `import.meta.resolve`, which throws for a name nothing maps.
73
+ *
74
+ * ```ts
75
+ * import { assertEquals } from '@std/assert'
76
+ * let none = (): string => {
77
+ * throw new TypeError('not a dependency')
78
+ * }
79
+ * let at = { '@yaks/tools': '1.2.3' }
80
+ * assertEquals(located('@yaks/tools/views', none, at), 'jsr:@yaks/tools@1.2.3/views')
81
+ * assertEquals(located('@yaks/tools/views', (s) => s, at), '@yaks/tools/views')
82
+ * assertEquals(located('./plugins/mail/vocab', none, at), './plugins/mail/vocab')
83
+ * ```
84
+ */ export let located = (spec, resolve = import.meta.resolve, release = versions)=>{
85
+ if (!spec.startsWith('@yaks/')) return spec;
86
+ try {
87
+ resolve(spec);
88
+ return spec;
89
+ } catch (error) {
90
+ if (String(error).includes('ERR_PACKAGE_PATH_NOT_EXPORTED')) return spec;
91
+ let [scope, name, ...rest] = spec.split('/');
92
+ let version = release[`${scope}/${name}`] ?? cli.version;
93
+ return [
94
+ 'jsr:' + scope,
95
+ `${name}@${version}`,
96
+ ...rest
97
+ ].join('/');
98
+ }
99
+ };
100
+ /** `import('<plugin>/<name>')`, or `null` where the package does not export
101
+ * that subpath — a facet, or the `./views` a caller draws with. Each answer is
102
+ * asked for once: a module is imported once a process whoever asks, and a
103
+ * subpath a package does not export stays unexported, where finding that out
104
+ * again costs an import that throws. */ export let subpath = (plugin, name)=>{
105
+ let key = `${plugin}/${name}`;
106
+ observed(dependencies.get(key) ?? []);
107
+ let known = imported.get(key);
108
+ if (known) return known;
109
+ let asked = optional(key);
110
+ imported.set(key, asked);
111
+ asked.catch(()=>imported.delete(key));
112
+ return asked;
113
+ };
114
+ /** Each plugin's `./views`, the ones a config names: warmed as one module
115
+ * graph when a registry asks for several (@yaks/cli answer.ts `registry`). */ export let pluginViews = Object.assign((plugin)=>subpath(plugin, 'views'), {
116
+ warm: (plugins)=>subpaths(plugins.map((p)=>[
117
+ p,
118
+ 'views'
119
+ ]))
120
+ });
121
+ /** Each plugin's `./tui`, what a held answer draws with first. */ export let pluginTui = (plugin)=>subpath(plugin, 'tui');
122
+ /** Load selected subpaths and required modules as one module graph where
123
+ * their exports are known: by the resolver for a file, by the release
124
+ * (`ships`) for a package from JSR. Deno otherwise builds a separate
125
+ * dependency graph per concurrent dynamic import, rediscovering shared
126
+ * dependencies for each. Module answers follow the subpath answers; only
127
+ * subpaths can be absent. A JSR package the release does not name still uses
128
+ * the ordinary loader, which alone can say whether its optional export
129
+ * exists. Nothing is written to disk. */ export let subpaths = async (requests, modules = [])=>{
130
+ let pending = [];
131
+ for (let [plugin, name] of requests){
132
+ let key = `${plugin}/${name}`;
133
+ observed(dependencies.get(key) ?? []);
134
+ if (imported.has(key) || pending.some((p)=>p.key == key)) continue;
135
+ let spec;
136
+ try {
137
+ spec = import.meta.resolve(key);
138
+ } catch (error) {
139
+ if (unexported(error, key)) {
140
+ imported.set(key, Promise.resolve(null));
141
+ continue;
142
+ }
143
+ }
144
+ if (spec?.startsWith('file:')) {
145
+ if (!/\.[cm]?[jt]sx?$/.test(spec)) continue;
146
+ } else {
147
+ // From JSR: mapped (spec) or not (located), as the release says.
148
+ let said = ships(key);
149
+ if (said === false) imported.set(key, Promise.resolve(null));
150
+ if (!said) continue;
151
+ spec = import.meta.resolve(located(key));
152
+ }
153
+ dependencies.set(key, [
154
+ spec
155
+ ]);
156
+ pending.push({
157
+ key,
158
+ spec,
159
+ slot: `m${pending.length}`
160
+ });
161
+ }
162
+ let roots = modules.map((spec, index)=>({
163
+ spec: import.meta.resolve(located(spec)),
164
+ slot: `r${index}`
165
+ }));
166
+ let required = [];
167
+ if (pending.length || roots.length) {
168
+ let source = [
169
+ ...pending,
170
+ ...roots
171
+ ].map(({ spec, slot })=>`export * as ${slot} from ${JSON.stringify(spec)};`).join('\n');
172
+ let loading = importing(`data:application/javascript,${encodeURIComponent(source)}`, [
173
+ ...pending,
174
+ ...roots
175
+ ].map(({ spec })=>spec));
176
+ for (let { key, slot } of pending){
177
+ // The batch cannot distinguish an absent file facet from a broken one.
178
+ // Let the ordinary loader classify each on failure, preserving its
179
+ // optional-export semantics and leaving unrelated modules usable.
180
+ let asked = loading.then((modules)=>modules[slot], ()=>optional(key));
181
+ imported.set(key, asked);
182
+ asked.catch(()=>imported.delete(key));
183
+ }
184
+ required = roots.map(({ spec, slot })=>loading.then((modules)=>modules[slot], ()=>importing(spec)));
185
+ }
186
+ return await Promise.all([
187
+ ...requests.map(([plugin, name])=>subpath(plugin, name)),
188
+ ...required
189
+ ]);
190
+ };
191
+ let imported = new Map();
192
+ let dependencies = new Map();
193
+ let optional = async (key)=>{
194
+ let spec = located(key);
195
+ let resolved = false;
196
+ try {
197
+ // Missing-module errors name the resolved URL, including for a plugin
198
+ // whose declaring package is an absolute path in a remote vocabulary.
199
+ spec = import.meta.resolve(spec);
200
+ resolved = true;
201
+ if (!spec.startsWith('file:') && ships(key) === false) return null;
202
+ dependencies.set(key, [
203
+ spec
204
+ ]);
205
+ return await importing(spec);
206
+ } catch (error) {
207
+ if (!resolved && String(error).includes('ERR_PACKAGE_PATH_NOT_EXPORTED')) {
208
+ return null;
209
+ }
210
+ if (unexported(error, spec)) return null;
211
+ throw error;
212
+ }
213
+ };
214
+ //# sourceMappingURL=facets.js.map
package/facets.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"facets.js","sources":["./facets.ts"],"names":[],"mappings":"AAAA,SAAS,YAAY,QAAQ,EAAE,SAAS,gCAAqC;AAC7E,OAAO,SAAS,sBAAsB;EAAE,MAAM;AAAO,EAAC;AAEtD,OAAO,cAAc,sBAAsB;EAAE,MAAM;AAAO,EAAC;AAC3D,OAAO,aAAa,sBAAsB;EAAE,MAAM;AAAO,EAAC;AAE1D;;;;;;;;;;;;;;;;CAgBC,GACD,OAAO,IAAI,aAAa,CAAC,OAAgB;EACvC,IAAI,CAAC,CAAC,iBAAiB,SAAS,GAAG,OAAO;EAC1C,wEAAwE;EACxE,2EAA2E;EAC3E,IAAI,QAAQ,MAAM,OAAO,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE;EAC3C,IAAI,SAAS,CAAC,kBAAkB,EAAE,KAAK,EAAE,CAAC,EAAE,OAAO;EACnD,IAAI,MAAM,+CAA+C,IAAI,CAA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