@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/remote.ts ADDED
@@ -0,0 +1,153 @@
1
+ import * as system from '@yaks/process/system'
2
+ import { importing } from '@yaks/fp/imports'
3
+ // Account selection and delivery belong to the concrete host. Domain tools
4
+ // forward ordinary arguments and never handle credentials or MCP envelopes.
5
+ import type { Bundle } from 'jsr:@yaks/graph@0.2.36'
6
+ import { CallError } from '@yaks/tools/errors'
7
+ import { tokenFor } from './store.js'
8
+ import { doorUrl, rpc } from './rpc.js'
9
+ import { saidBy } from './roster.js'
10
+ import type { Result } from './roster.js'
11
+ import type { Host } from 'jsr:@yaks/host@0.2.36'
12
+ import { located, person } from './config.js'
13
+ import type { AccountOptions } from './accounts.ts'
14
+ import { adminForward, boxAccount, forwarded } from './account-forward.js'
15
+
16
+ type Selection = {
17
+ as?: string
18
+ via?: string
19
+ host?: string
20
+ state?: string
21
+ config?: string
22
+ env?: AccountOptions['env']
23
+ fetch?: typeof globalThis.fetch
24
+ credential?: (
25
+ host: string,
26
+ as?: string,
27
+ agent?: boolean,
28
+ ) => Promise<string | null>
29
+ }
30
+
31
+ /** Authenticated JSON delivery shared by HTTP commands and graph tools. */
32
+ export let readJson = async (
33
+ url: string | URL,
34
+ options: Selection = {},
35
+ ): Promise<unknown> => {
36
+ let origin = new URL(url)
37
+ if (
38
+ !['http:', 'https:'].includes(origin.protocol) || origin.username ||
39
+ origin.password
40
+ ) {
41
+ throw new CallError(
42
+ 'arguments',
43
+ 'Choose an HTTP(S) origin without credentials',
44
+ )
45
+ }
46
+ let key =
47
+ options.host && new URL(doorUrl(options.host)).origin == origin.origin
48
+ ? options.host
49
+ : origin.host
50
+ let token = options.credential
51
+ ? await options.credential(key, options.as, !!options.via)
52
+ : await tokenFor(key, options.state, {
53
+ config: options.config,
54
+ as: options.as,
55
+ env: options.env,
56
+ agent: !!options.via,
57
+ })
58
+ let headers = new Headers({ accept: 'application/json' })
59
+ if (token) headers.set('authorization', `Bearer ${token}`)
60
+ if (options.via) headers.set('x-via', options.via)
61
+ let destination = forwarded(origin.href, token, false, {
62
+ headers,
63
+ redirect: 'error',
64
+ cache: 'no-store',
65
+ })
66
+ let response = await (options.fetch ?? globalThis.fetch)(
67
+ destination.url,
68
+ destination.init,
69
+ )
70
+ if (!response.ok) {
71
+ await response.body?.cancel()
72
+ throw new Error(`HTTP ${response.status} ${response.statusText}`.trim())
73
+ }
74
+ return await response.json()
75
+ }
76
+
77
+ export let remote = async (
78
+ name: string,
79
+ args: Record<string, unknown>,
80
+ options: {
81
+ as?: string
82
+ via?: string
83
+ url?: string
84
+ mixedAuth?: boolean
85
+ credential?: Selection['credential']
86
+ state?: string
87
+ config?: string
88
+ } = {},
89
+ ): Promise<Bundle[]> => {
90
+ let origin = new URL(options.url ?? 'https://yaks.app')
91
+ if (
92
+ !['http:', 'https:'].includes(origin.protocol) || origin.username ||
93
+ origin.password
94
+ ) {
95
+ throw new CallError(
96
+ 'arguments',
97
+ 'Choose an HTTP(S) origin without credentials',
98
+ )
99
+ }
100
+ let door = new URL(doorUrl(origin.origin))
101
+ if (options.mixedAuth) door.searchParams.set('auth', 'mixed')
102
+ let ask = rpc({
103
+ url: door.href,
104
+ token: () =>
105
+ options.credential
106
+ ? options.credential(origin.origin, options.as, !!options.via)
107
+ : tokenFor(origin.origin, options.state, {
108
+ as: options.as,
109
+ config: options.config,
110
+ agent: !!options.via,
111
+ }),
112
+ via: options.via,
113
+ })
114
+ let reply = await ask('tools/call', { name, arguments: args }) as Result
115
+ if (reply.isError) throw new CallError('remote', saidBy(reply).text)
116
+ let result = (reply.structuredContent as { result?: unknown } | undefined)
117
+ ?.result
118
+ if (!Array.isArray(result)) throw new Error(`${name} returned no bundles`)
119
+ return result as Bundle[]
120
+ }
121
+
122
+ /** Bind delivery to this host's owner and vault, including nondefault configs. */
123
+ export let delivery = (
124
+ host: Pick<Host, 'graph' | 'config' | 'vault'>,
125
+ ): Pick<Host, 'remote' | 'readJson'> => {
126
+ let credential = async (
127
+ name: string,
128
+ as?: string,
129
+ agent?: boolean,
130
+ ): Promise<string | null> => {
131
+ let explicit = system.env.get('YAKS_TOKEN')
132
+ if (explicit) return explicit
133
+ let url = new URL(doorUrl(name))
134
+ if (url.origin == 'https://yaks.app') {
135
+ as = boxAccount(host.config, as, agent)
136
+ let forwarded = adminForward(host.config, as)
137
+ if (forwarded) return forwarded
138
+ }
139
+ let owner = await person(host)
140
+ if (!owner || !host.graph.vocab.comp('connection')) return null
141
+ let { accountCredential } = await importing(
142
+ import.meta.resolve(located('@yaks/connections')),
143
+ )
144
+ let integration = url.hostname == 'yaks.app' ? 'yaks.app' : url.href
145
+ return (await accountCredential(host, owner, integration, as))?.bearer ??
146
+ null
147
+ }
148
+ return {
149
+ remote: (name, args, options) =>
150
+ remote(name, args, { ...options, credential }),
151
+ readJson: (url, options) => readJson(url, { ...options, credential }),
152
+ }
153
+ }
package/report.js ADDED
@@ -0,0 +1,83 @@
1
+ import * as system from "@yaks/process/system";
2
+ import { command as launchCommand } from "@yaks/process/command";
3
+ import { caught, spool } from "@yaks/tracker/report";
4
+ import { files } from "@yaks/tracker/file";
5
+ import { runtimeRoot, runtimeStack } from "./runtime.js";
6
+ export let revision = async ()=>{
7
+ let pinned = runtimeRoot() ? system.env.get('YAK_RUNTIME_COMMIT') : undefined;
8
+ if (pinned) return pinned;
9
+ if (!import.meta.url.startsWith('file:')) return undefined;
10
+ try {
11
+ let result = await launchCommand('git', {
12
+ args: [
13
+ 'rev-parse',
14
+ 'HEAD'
15
+ ],
16
+ cwd: new URL('../../', import.meta.url),
17
+ stdout: 'piped',
18
+ stderr: 'null'
19
+ }).output();
20
+ return result.code == 0 ? new TextDecoder().decode(result.stdout).trim() : undefined;
21
+ } catch {
22
+ return undefined;
23
+ }
24
+ };
25
+ /// command(['serve', '--no-duties']) -> 'yak serve'
26
+ /// command(['graph', 'query', '.bug .order=-bug.hits']) -> 'yak graph query'
27
+ /// command(['memory', 'save', '@/tmp/body.md', '--id', 'M-1']) -> 'yak memory save'
28
+ /// command([]) -> 'yak'
29
+ /** The command a process runs, as its leading words: never an argument's
30
+ * value, which may be anything a person typed. */ export let command = (argv)=>{
31
+ let lead = argv.slice(0, 2), stop = lead.findIndex((w)=>!WORD.test(w));
32
+ return [
33
+ 'yak',
34
+ ...lead.slice(0, stop < 0 ? 2 : stop)
35
+ ].join(' ');
36
+ };
37
+ let WORD = /^[a-z][a-z-]*$/;
38
+ // Callers name their invocation; a supervisor using this spool is not a yak
39
+ // command merely because it shares the CLI's reporting boundary.
40
+ export let reporter = (config, actor, commit, tags = {})=>{
41
+ let file = config.tracker ? spool(files(config.tracker.spool).append) : undefined;
42
+ let pending = new Set();
43
+ let report = async (error, told = {})=>{
44
+ let context = await told;
45
+ try {
46
+ console.error(`${context.tags?.step ?? 'box'} failed —`, error);
47
+ } catch {}
48
+ if (!file) return;
49
+ let at = await commit;
50
+ await caught(error, {
51
+ actor,
52
+ commit: config.tracker?.commit ?? at,
53
+ environment: 'production',
54
+ ...context,
55
+ tags: {
56
+ source: 'box',
57
+ ...tags,
58
+ ...context.tags
59
+ },
60
+ sink: (rows)=>file(rows.map((row)=>{
61
+ let exception = row.exception;
62
+ return typeof exception?.stack == 'string' ? {
63
+ ...row,
64
+ exception: {
65
+ ...exception,
66
+ stack: runtimeStack(exception.stack)
67
+ }
68
+ } : row;
69
+ }))
70
+ });
71
+ };
72
+ return Object.assign((error, context)=>{
73
+ let delivery = report(error, context);
74
+ pending.add(delivery);
75
+ void delivery.then(()=>pending.delete(delivery));
76
+ return delivery;
77
+ }, {
78
+ close: async ()=>{
79
+ while(pending.size)await Promise.all(pending);
80
+ }
81
+ });
82
+ };
83
+ //# sourceMappingURL=report.js.map
package/report.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"report.js","sources":["./report.ts"],"names":[],"mappings":"AAAA,YAAY,wCAA6C;AACzD,SAAS,WAAW,aAAa,qCAA0C;AAK3E,SAAS,MAAM,EAAgB,KAAK,oCAAyC;AAC7E,SAAS,KAAK,kCAAuC;AAErD,SAAS,WAAW,EAAE,YAAY,uBAAsB;AAExD,OAAO,IAAI,WAAW;EACpB,IAAI,SAAS,gBAAgB,OAAO,GAAG,CAAC,GAAG,CAAC,wBAAwB;EACpE,IAAI,QAAQ,OAAO;EACnB,IAAI,CAAC,YAAY,GAAG,CAAC,UAAU,CAAC,UAAU,OAAO;EACjD,IAAI;IACF,IAAI,SAAS,MAAM,cAAc,OAAO;MACtC,MAAM;QAAC;QAAa;OAAO;MAC3B,KAAK,IAAI,IAAI,UAAU,YAAY,GAAG;MACtC,QAAQ;MACR,QAAQ;IACV,GAAG,MAAM;IACT,OAAO,OAAO,IAAI,IAAI,IAClB,IAAI,cAAc,MAAM,CAAC,OAAO,MAAM,EAAE,IAAI,KAC5C;EACN,EAAE,OAAM;IACN,OAAO;EACT;AACF,EAAC;AAED,oDAAoD;AACpD,6EAA6E;AAC7E,oFAAoF;AACpF,wBAAwB;AACxB;gDACgD,GAChD,OAAO,IAAI,UAAU,CAAC;EACpB,IAAI,OAAO,KAAK,KAAK,CAAC,GAAG,IAAI,OAAO,KAAK,SAAS,CAAC,CAAC,IAAM,CAAC,KAAK,IAAI,CAAC;EACrE,OAAO;IAAC;OAAU,KAAK,KAAK,CAAC,GAAG,OAAO,IAAI,IAAI;GAAM,CAAC,IAAI,CAAC;AAC7D,EAAC;AACD,IAAI,OAAO;AAMX,4EAA4E;AAC5E,iEAAiE;AACjE,OAAO,IAAI,WAAW,CACpB,QACA,OACA,QACA,OAAwB,CAAC,CAAC;EAK1B,IAAI,OAAO,OAAO,OAAO,GACrB,MAAM,MAAM,OAAO,OAAO,CAAC,KAAK,EAAE,MAAM,IACxC;EACJ,IAAI,UAAU,IAAI;EAClB,IAAI,SAAS,OAAO,OAAgB,OAAa,CAAC,CAAC;IACjD,IAAI,UAAU,MAAM;IACpB,IAAI;MACF,QAAQ,KAAK,CAAC,GAAG,QAAQ,IAAI,EAAE,QAAQ,MAAM,SAAS,CAAC,EAAE;IAC3D,EAAE,OAAM,CAA0C;IAClD,IAAI,CAAC,MAAM;IACX,IAAI,KAAK,MAAM;IACf,MAAM,OAAO,OAAO;MAClB;MACA,QAAQ,OAAO,OAAO,EAAE,UAAU;MAClC,aAAa;MACb,GAAG,OAAO;MACV,MAAM;QACJ,QAAQ;QACR,GAAG,IAAI;QACP,GAAG,QAAQ,IAAI;MACjB;MACA,MAAM,CAAC,OACL,KAAK,KAAK,GAAG,CAAC,CAAC;UACb,IAAI,YAAY,IAAI,SAAS;UAC7B,OAAO,OAAO,WAAW,SAAS,WAC9B;YACA,GAAG,GAAG;YACN,WAAW;cAAE,GAAG,SAAS;cAAE,OAAO,aAAa,UAAU,KAAK;YAAE;UAClE,IACE;QACN;IACJ;EACF;EACA,OAAO,OAAO,MAAM,CAAC,CAAC,OAAgB;IACpC,IAAI,WAAW,OAAO,OAAO;IAC7B,QAAQ,GAAG,CAAC;IACZ,KAAK,SAAS,IAAI,CAAC,IAAM,QAAQ,MAAM,CAAC;IACxC,OAAO;EACT,GAAG;IACD,OAAO;MACL,MAAO,QAAQ,IAAI,CAAE,MAAM,QAAQ,GAAG,CAAC;IACzC;EACF;AACF,EAAC"}
package/report.ts ADDED
@@ -0,0 +1,101 @@
1
+ import * as system from '@yaks/process/system'
2
+ import { command as launchCommand } from '@yaks/process/command'
3
+ // Box hosts report to a durable spool without opening the tracker graph. The
4
+ // tracker service owns admission, remote delivery and retry.
5
+
6
+ import type { Actor, Comp } from 'jsr:@yaks/graph@0.2.36'
7
+ import { caught, type Context, spool } from '@yaks/tracker/report'
8
+ import { files } from '@yaks/tracker/file'
9
+ import type { Config } from './config.ts'
10
+ import { runtimeRoot, runtimeStack } from './runtime.js'
11
+
12
+ export let revision = async (): Promise<string | undefined> => {
13
+ let pinned = runtimeRoot() ? system.env.get('YAK_RUNTIME_COMMIT') : undefined
14
+ if (pinned) return pinned
15
+ if (!import.meta.url.startsWith('file:')) return undefined
16
+ try {
17
+ let result = await launchCommand('git', {
18
+ args: ['rev-parse', 'HEAD'],
19
+ cwd: new URL('../../', import.meta.url),
20
+ stdout: 'piped',
21
+ stderr: 'null',
22
+ }).output()
23
+ return result.code == 0
24
+ ? new TextDecoder().decode(result.stdout).trim()
25
+ : undefined
26
+ } catch {
27
+ return undefined
28
+ }
29
+ }
30
+
31
+ /// command(['serve', '--no-duties']) -> 'yak serve'
32
+ /// command(['graph', 'query', '.bug .order=-bug.hits']) -> 'yak graph query'
33
+ /// command(['memory', 'save', '@/tmp/body.md', '--id', 'M-1']) -> 'yak memory save'
34
+ /// command([]) -> 'yak'
35
+ /** The command a process runs, as its leading words: never an argument's
36
+ * value, which may be anything a person typed. */
37
+ export let command = (argv: readonly string[]): string => {
38
+ let lead = argv.slice(0, 2), stop = lead.findIndex((w) => !WORD.test(w))
39
+ return ['yak', ...lead.slice(0, stop < 0 ? 2 : stop)].join(' ')
40
+ }
41
+ let WORD = /^[a-z][a-z-]*$/
42
+
43
+ // What a report is told about its failure, or a promise of it while the
44
+ // caller is still learning: the reporter's close waits for that too.
45
+ type Told = Partial<Context> | Promise<Partial<Context>>
46
+
47
+ // Callers name their invocation; a supervisor using this spool is not a yak
48
+ // command merely because it shares the CLI's reporting boundary.
49
+ export let reporter = (
50
+ config: Config,
51
+ actor?: Actor,
52
+ commit?: string | Promise<string | undefined>,
53
+ tags: Context['tags'] = {},
54
+ ): {
55
+ (error: unknown, context?: Told): Promise<void>
56
+ close: () => Promise<void>
57
+ } => {
58
+ let file = config.tracker
59
+ ? spool(files(config.tracker.spool).append)
60
+ : undefined
61
+ let pending = new Set<Promise<void>>()
62
+ let report = async (error: unknown, told: Told = {}) => {
63
+ let context = await told
64
+ try {
65
+ console.error(`${context.tags?.step ?? 'box'} failed —`, error)
66
+ } catch { /* telemetry cannot break the caller */ }
67
+ if (!file) return
68
+ let at = await commit
69
+ await caught(error, {
70
+ actor,
71
+ commit: config.tracker?.commit ?? at,
72
+ environment: 'production',
73
+ ...context,
74
+ tags: {
75
+ source: 'box',
76
+ ...tags,
77
+ ...context.tags,
78
+ },
79
+ sink: (rows) =>
80
+ file(rows.map((row) => {
81
+ let exception = row.exception as Comp | undefined
82
+ return typeof exception?.stack == 'string'
83
+ ? {
84
+ ...row,
85
+ exception: { ...exception, stack: runtimeStack(exception.stack) },
86
+ }
87
+ : row
88
+ })),
89
+ })
90
+ }
91
+ return Object.assign((error: unknown, context?: Told) => {
92
+ let delivery = report(error, context)
93
+ pending.add(delivery)
94
+ void delivery.then(() => pending.delete(delivery))
95
+ return delivery
96
+ }, {
97
+ close: async () => {
98
+ while (pending.size) await Promise.all(pending)
99
+ },
100
+ })
101
+ }
package/reported.js ADDED
@@ -0,0 +1,32 @@
1
+ // A server's vocabulary drawn with this machine's copies of its packages'
2
+ // views: the one place a remote answer meets the plugin loader.
3
+ import { loadVocab } from "@yaks/vocab/runtime";
4
+ import { understood } from "@yaks/host/keywords";
5
+ import { registry } from "./answer.js";
6
+ import { subpath, subpaths } from "./config.js";
7
+ // A package a server named that this machine has no copy of: its plugins are
8
+ // its own, so an answer is drawn with the views that are here.
9
+ let elsewhere = (error)=>error instanceof TypeError && error.message.includes('not a dependency');
10
+ /** A vocabulary a server reported (`graph_schema`), read the way a host reads
11
+ * its own — with the keywords every host understands — and the views of the
12
+ * packages it says declared its components, where this machine has them. */ export let reported = async (doc)=>{
13
+ let vocab = loadVocab([
14
+ doc
15
+ ], understood());
16
+ let plugins = vocab.all.flatMap((n)=>vocab.comp(n)?.namespace?.label ?? []);
17
+ let named = [
18
+ ...new Set(plugins)
19
+ ];
20
+ await subpaths(named.map((p)=>[
21
+ p,
22
+ 'views'
23
+ ])).catch((error)=>elsewhere(error) ? null : Promise.reject(error));
24
+ let load = (plugin)=>subpath(plugin, 'views').catch((error)=>elsewhere(error) ? null : Promise.reject(error));
25
+ let views = await registry(named, load);
26
+ return {
27
+ views,
28
+ vocab,
29
+ components: ()=>registry(named, load, undefined, true)
30
+ };
31
+ };
32
+ //# sourceMappingURL=reported.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reported.js","sources":["./reported.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,gEAAgE;AAChE,SAAS,SAAS,mCAAmE;AACrF,SAAS,UAAU,mCAAwC;AAE3D,SAAoB,QAAQ,sBAAiD;AAC7E,SAAS,OAAO,EAAE,QAAQ,sBAAqB;AAE/C,6EAA6E;AAC7E,+DAA+D;AAC/D,IAAI,YAAY,CAAC,QACf,iBAAiB,aAAa,MAAM,OAAO,CAAC,QAAQ,CAAC;AAEvD;;0EAE0E,GAC1E,OAAO,IAAI,WAAW,OACpB;EAIA,IAAI,QAAQ,UAAU;IAAC;GAAI,EAAE;EAC7B,IAAI,UAAU,MAAM,GAAG,CAAC,OAAO,CAAC,CAAC,IAAM,MAAM,IAAI,CAAC,IAAI,WAAW,SAAS,EAAE;EAC5E,IAAI,QAAQ;OAAI,IAAI,IAAI;GAAS;EACjC,MAAM,SAAS,MAAM,GAAG,CAAC,CAAC,IAAM;MAAC;MAAG;KAAQ,GAAY,KAAK,CAAC,CAAC,QAC7D,UAAU,SAAS,OAAO,QAAQ,MAAM,CAAC;EAE3C,IAAI,OAAc,CAAC,SACjB,QAAmB,QAAQ,SAAS,KAAK,CAAC,CAAC,QACzC,UAAU,SAAS,OAAO,QAAQ,MAAM,CAAC;EAE7C,IAAI,QAAQ,MAAM,SAAS,OAAO;EAClC,OAAO;IACL;IACA;IACA,YAAY,IAAM,SAAS,OAAO,MAAM,WAAW;EACrD;AACF,EAAC"}
package/reported.ts ADDED
@@ -0,0 +1,38 @@
1
+ // A server's vocabulary drawn with this machine's copies of its packages'
2
+ // views: the one place a remote answer meets the plugin loader.
3
+ import { loadVocab, type Vocab, type VocabDoc } from '@yaks/vocab/runtime'
4
+ import { understood } from '@yaks/host/keywords'
5
+ import type { Registry } from 'jsr:@yaks/render@0.2.36'
6
+ import { type Held, registry, type ViewFacet, type Views } from './answer.js'
7
+ import { subpath, subpaths } from './config.js'
8
+
9
+ // A package a server named that this machine has no copy of: its plugins are
10
+ // its own, so an answer is drawn with the views that are here.
11
+ let elsewhere = (error: unknown): boolean =>
12
+ error instanceof TypeError && error.message.includes('not a dependency')
13
+
14
+ /** A vocabulary a server reported (`graph_schema`), read the way a host reads
15
+ * its own — with the keywords every host understands — and the views of the
16
+ * packages it says declared its components, where this machine has them. */
17
+ export let reported = async (
18
+ doc: VocabDoc,
19
+ ): Promise<
20
+ { views: Registry; vocab: Vocab; components: () => Promise<Held> }
21
+ > => {
22
+ let vocab = loadVocab([doc], understood())
23
+ let plugins = vocab.all.flatMap((n) => vocab.comp(n)?.namespace?.label ?? [])
24
+ let named = [...new Set(plugins)]
25
+ await subpaths(named.map((p) => [p, 'views'] as const)).catch((error) =>
26
+ elsewhere(error) ? null : Promise.reject(error)
27
+ )
28
+ let load: Views = (plugin) =>
29
+ subpath<ViewFacet>(plugin, 'views').catch((error) =>
30
+ elsewhere(error) ? null : Promise.reject(error)
31
+ )
32
+ let views = await registry(named, load)
33
+ return {
34
+ views,
35
+ vocab,
36
+ components: () => registry(named, load, undefined, true),
37
+ }
38
+ }