@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/vault.ts ADDED
@@ -0,0 +1,220 @@
1
+ import * as disk from '@yaks/file/io'
2
+ // Where a box keeps its graph's secrets: one private file per secret, in a
3
+ // `secrets` directory beside the database. @yaks/secrets says what a vault is
4
+ // and keeps no storage of its own; this host owns `~/.yak`, so the files are
5
+ // its business, and it hands the vault to every plugin as `host.vault`
6
+ // (./host.ts).
7
+ //
8
+ // Beside the database and never inside it, so the database, its journal, its
9
+ // backups and the text dump a backup commits hold only handles. One rule
10
+ // rather than an option, so the plugin sealing a value and the host reading it
11
+ // back for a config can never disagree about where it went. A graph in memory
12
+ // keeps its secrets in memory too, for exactly as long.
13
+ //
14
+ // The discipline is the one a credential file on a shared machine needs: the
15
+ // directory is 0700, every file 0600, a write is a temporary file renamed over
16
+ // the old one so a reader never sees half a secret, and a symlink anywhere is
17
+ // refused rather than followed — the vault is exactly the files it wrote.
18
+ //
19
+ // One file per secret, rather than one file of all of them, so two processes
20
+ // sealing two secrets never write the same file, and deleting a secret is
21
+ // moving its file into private trash. A replacement keeps the previous file
22
+ // there too. Trash is never purged automatically and is excluded from active
23
+ // reads; recovery seals its saved value again through the same vault.
24
+
25
+ import type { Eid } from 'jsr:@yaks/graph@0.2.36'
26
+ import {
27
+ type Local,
28
+ queue,
29
+ ramVault,
30
+ type Sealed,
31
+ type Trashed,
32
+ } from '@yaks/secrets'
33
+
34
+ // A secret's id is derived from its name, so it is always a uuid. Anything
35
+ // else never came from this vault, and is never turned into a path.
36
+ let OURS = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/
37
+
38
+ let lstat = (path: string): disk.FileInfo | null => {
39
+ try {
40
+ return disk.lstatSync(path)
41
+ } catch (e) {
42
+ if (e instanceof disk.errors.NotFound) return null
43
+ throw e
44
+ }
45
+ }
46
+
47
+ let refuse = (path: string) => {
48
+ throw new Error(`${path} is not a vault's own file: refusing to follow it`)
49
+ }
50
+
51
+ // The directory, made private — or refused, where something other than the
52
+ // directory this vault made is standing there.
53
+ let own = (dir: string): void => {
54
+ let at = lstat(dir)
55
+ if (at && (at.isSymlink || !at.isDirectory)) refuse(dir)
56
+ if (!at) disk.mkdirSync(dir, { recursive: true, mode: 0o700 })
57
+ disk.chmodSync(dir, 0o700)
58
+ }
59
+
60
+ let readIn = (path: string): string | undefined => {
61
+ let at = lstat(path)
62
+ if (!at) return undefined
63
+ if (at.isSymlink || !at.isFile) refuse(path)
64
+ return disk.readTextFileSync(path)
65
+ }
66
+
67
+ let writeIn = (dir: string, path: string, text: string): void => {
68
+ own(dir)
69
+ let at = lstat(path)
70
+ if (at && (at.isSymlink || !at.isFile)) refuse(path)
71
+ let temp = `${path}.${crypto.randomUUID()}.tmp`
72
+ try {
73
+ disk.writeTextFileSync(temp, text, { createNew: true, mode: 0o600 })
74
+ disk.chmodSync(temp, 0o600)
75
+ disk.renameSync(temp, path)
76
+ } catch (e) {
77
+ try {
78
+ disk.removeSync(temp)
79
+ } catch { /* never written */ }
80
+ throw e
81
+ }
82
+ }
83
+
84
+ let unhex = (hex: string) =>
85
+ new Uint8Array(hex.match(/../g)!.map((b) => parseInt(b, 16)))
86
+ let hex = (bytes: Uint8Array) =>
87
+ [...bytes].map((b) => b.toString(16).padStart(2, '0')).join('')
88
+
89
+ /** The vault in a directory: `<dir>/<eid>.json` per secret, and `<dir>/salt`,
90
+ * the key its sentinels are hashed under, made the first time one is asked
91
+ * for. */
92
+ export let fileVault = (dir: string): Local => {
93
+ let file = (eid: Eid) => `${dir}/${eid}.json`
94
+ let held = queue()
95
+ let version = (path: string): { sealed: Sealed; at: number } => {
96
+ let data = JSON.parse(readIn(path)!)
97
+ return data.sealed
98
+ ? data
99
+ : { sealed: data, at: lstat(path)!.mtime!.getTime() }
100
+ }
101
+ let trash = (): Trashed[] => {
102
+ if (!lstat(`${dir}/trash`)) return []
103
+ own(`${dir}/trash`)
104
+ let out: Trashed[] = []
105
+ for (let entry of disk.readDirSync(`${dir}/trash`)) {
106
+ let [eid, id, ext] = entry.name.split('.')
107
+ if (ext != 'json' || !OURS.test(eid) || !OURS.test(id)) continue
108
+ let path = `${dir}/trash/${entry.name}`
109
+ let { sealed, at } = version(path)
110
+ out.push({
111
+ id,
112
+ eid,
113
+ handle: sealed.handle,
114
+ name: sealed.name,
115
+ at,
116
+ })
117
+ }
118
+ return out.sort((a, b) => b.at - a.at)
119
+ }
120
+ let archive = (eid: Eid, move = true) => {
121
+ let path = file(eid)
122
+ let text = readIn(path)
123
+ if (text === undefined) return
124
+ let at = Math.max(Date.now(), ...trash().map((entry) => entry.at + 1))
125
+ let to = `${dir}/trash/${eid}.${crypto.randomUUID()}.json`
126
+ writeIn(
127
+ `${dir}/trash`,
128
+ to,
129
+ JSON.stringify({ sealed: JSON.parse(text), at }) + '\n',
130
+ )
131
+ if (move) disk.removeSync(path)
132
+ }
133
+ let archived = (id: string) => {
134
+ let saved = trash().find((entry) => entry.id == id)
135
+ return saved &&
136
+ { ...saved, path: `${dir}/trash/${saved.eid}.${saved.id}.json` }
137
+ }
138
+ let salt: Uint8Array | undefined
139
+ return {
140
+ salt: () => {
141
+ if (salt) return salt
142
+ let said = readIn(`${dir}/salt`)?.trim()
143
+ if (said) return salt = unhex(said)
144
+ salt = crypto.getRandomValues(new Uint8Array(32))
145
+ writeIn(dir, `${dir}/salt`, hex(salt) + '\n')
146
+ return salt
147
+ },
148
+ read: (eid) => {
149
+ if (!OURS.test(eid)) return undefined
150
+ let text = readIn(file(eid))
151
+ return text ? JSON.parse(text) as Sealed : undefined
152
+ },
153
+ seal: (eid, sealed) => {
154
+ if (!OURS.test(eid)) throw new Error(`not a secret's id: ${eid}`)
155
+ let text = JSON.stringify(sealed) + '\n'
156
+ if (readIn(file(eid)) == text) return
157
+ archive(eid, false)
158
+ writeIn(dir, file(eid), text)
159
+ },
160
+ drop: (eid) => {
161
+ if (OURS.test(eid)) archive(eid)
162
+ },
163
+ all: () => {
164
+ if (!lstat(dir)) return []
165
+ let out: [Eid, Sealed][] = []
166
+ for (let e of disk.readDirSync(dir)) {
167
+ let eid = e.name.replace(/\.json$/, '')
168
+ if (e.name == eid || !OURS.test(eid)) continue
169
+ let text = readIn(file(eid))
170
+ if (text) out.push([eid, JSON.parse(text)])
171
+ }
172
+ return out
173
+ },
174
+ trash,
175
+ past: (id) => {
176
+ let saved = archived(id)
177
+ return saved ? version(saved.path).sealed : undefined
178
+ },
179
+ restore: (id) => {
180
+ let saved = archived(id)
181
+ if (!saved) return false
182
+ archive(saved.eid, false)
183
+ writeIn(
184
+ dir,
185
+ file(saved.eid),
186
+ JSON.stringify(version(saved.path).sealed) + '\n',
187
+ )
188
+ disk.removeSync(saved.path)
189
+ return true
190
+ },
191
+ purge: (id) => {
192
+ let saved = archived(id)
193
+ if (saved) disk.removeSync(saved.path)
194
+ },
195
+ // The other writers in this process wait in the queue; the other
196
+ // processes on the box wait on the lock file.
197
+ lock: (eid, fn) =>
198
+ held(eid, async () => {
199
+ if (!OURS.test(eid)) throw new Error(`not a secret's id: ${eid}`)
200
+ own(dir)
201
+ using lock = await disk.open(`${dir}/${eid}.lock`, {
202
+ create: true,
203
+ write: true,
204
+ mode: 0o600,
205
+ })
206
+ await lock.lock(true)
207
+ return await fn()
208
+ }),
209
+ }
210
+ }
211
+
212
+ /** The vault for the graph in the database at `db`: files in a `secrets`
213
+ * directory beside it, or memory for a graph in memory. Made once per graph
214
+ * and handed round, so the plugin sealing a value and the code reading it back
215
+ * hold the same vault — for a graph in memory, the only way they could. */
216
+ export let vaultOf = (db: string): Local => {
217
+ if (db == ':memory:') return ramVault()
218
+ let at = db.lastIndexOf('/')
219
+ return fileVault(`${at < 0 ? '.' : db.slice(0, at) || '/'}/secrets`)
220
+ }
package/vocab-ids.js ADDED
@@ -0,0 +1,63 @@
1
+ // The vocab formatter: mints a `$id` into each vocabulary document of a
2
+ // checkout's packages (a `vocab.json` or `*.vocab.json`) for every word that
3
+ // has none (@yaks/vocab/minted), like a lockfile, for the author to commit
4
+ // with the word. `yak serve` runs it on the checkout it starts from,
5
+ // `deno task test` on the one it tests, and `deno task vocab` by hand. Nobody
6
+ // writes a `$id` by hand.
7
+ //
8
+ // An app's source (a directory with an `index.html`, such as an app under
9
+ // apps/) is left alone, since its deploy mints its words' ids, and so are
10
+ // test fixtures.
11
+ //
12
+ // deno task vocab # prints each file it wrote, and formats it
13
+ import { mint } from "@yaks/graph/mint";
14
+ import * as disk from "@yaks/file/io";
15
+ import { minted } from "@yaks/vocab/minted";
16
+ let SKIP = new Set([
17
+ 'node_modules',
18
+ 'fixtures'
19
+ ]);
20
+ // The vocabulary documents under `dir`, a directory's URL, relative to `root`.
21
+ let documents = async (root, dir)=>{
22
+ let entries = await Array.fromAsync(disk.readDir(dir)).catch((e)=>disk.isNotFound(e) ? [] : Promise.reject(e));
23
+ if (entries.some((e)=>e.name == 'index.html')) return [];
24
+ let found = [];
25
+ for (let { name, isDirectory, isFile } of entries){
26
+ if (name.startsWith('.') || SKIP.has(name)) continue;
27
+ if (isDirectory) {
28
+ found.push(...await documents(root, new URL(`${name}/`, dir)));
29
+ } else if (isFile && (name == 'vocab.json' || name.endsWith('.vocab.json'))) {
30
+ found.push(new URL(name, dir).href.slice(root.href.length));
31
+ }
32
+ }
33
+ return found;
34
+ };
35
+ /** Mint the missing `$id`s into every vocabulary document under packages/ in
36
+ * the checkout at `root`, a directory's URL, and the files written, relative
37
+ * to it. */ export let mintIds = async (root)=>{
38
+ let wrote = [];
39
+ for (let file of (await documents(root, new URL('packages/', root)))){
40
+ let text = await disk.readTextFile(new URL(file, root));
41
+ let next = minted(text, mint);
42
+ if (next == text) continue;
43
+ await disk.writeTextFile(new URL(file, root), next);
44
+ wrote.push(file);
45
+ }
46
+ return wrote.sort();
47
+ };
48
+ if (import.meta.main) {
49
+ let { command } = await import("@yaks/process/command");
50
+ let { execPath } = await import("@yaks/process/system");
51
+ let wrote = await mintIds(new URL('../../', import.meta.url));
52
+ for (let file of wrote)console.log(file);
53
+ if (wrote.length) {
54
+ await command(execPath(), {
55
+ args: [
56
+ 'fmt',
57
+ '--quiet',
58
+ ...wrote
59
+ ]
60
+ }).output();
61
+ }
62
+ }
63
+ //# sourceMapp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AM,UAAU,MAAM,IAAI,IAAI,aAAa,MAAK,EAAG;IAClE,IAAI,OAAO,MAAM,KAAK,YAAY,CAAC,IAAI,IAAI,MAAM;IACjD,IAAI,OAAO,OAAO,MAAM;IACxB,IAAI,QAAQ,MAAM;IAClB,MAAM,KAAK,aAAa,CAAC,IAAI,IAAI,MAAM,OAAO;IAC9C,MAAM,IAAI,CAAC;EACb;EACA,OAAO,MAAM,IAAI;AACnB,EAAC;AAED,IAAI,YAAY,IAAI,EAAE;EACpB,IAAI,EAAE,OAAO,EAAE,GAAG,MAAM,MAAM,CAAC;EAC/B,IAAI,EAAE,QAAQ,EAAE,GAAG,MAAM,MAAM,CAAC;EAChC,IAAI,QAAQ,MAAM,QAAQ,IAAI,IAAI,UAAU,YAAY,GAAG;EAC3D,KAAK,IAAI,QAAQ,MAAO,QAAQ,GAAG,CAAC;EACpC,IAAI,MAAM,MAAM,EAAE;IAChB,MAAM,QAAQ,YAAY;MAAE,MAAM;QAAC;QAAO;WAAc;OAAM;IAAC,GAAG,MAAM;EAC1E;AACF"}
package/vocab-ids.ts ADDED
@@ -0,0 +1,62 @@
1
+ // The vocab formatter: mints a `$id` into each vocabulary document of a
2
+ // checkout's packages (a `vocab.json` or `*.vocab.json`) for every word that
3
+ // has none (@yaks/vocab/minted), like a lockfile, for the author to commit
4
+ // with the word. `yak serve` runs it on the checkout it starts from,
5
+ // `deno task test` on the one it tests, and `deno task vocab` by hand. Nobody
6
+ // writes a `$id` by hand.
7
+ //
8
+ // An app's source (a directory with an `index.html`, such as an app under
9
+ // apps/) is left alone, since its deploy mints its words' ids, and so are
10
+ // test fixtures.
11
+ //
12
+ // deno task vocab # prints each file it wrote, and formats it
13
+
14
+ import { mint } from '@yaks/graph/mint'
15
+ import * as disk from '@yaks/file/io'
16
+ import { minted } from '@yaks/vocab/minted'
17
+
18
+ let SKIP = new Set(['node_modules', 'fixtures'])
19
+
20
+ // The vocabulary documents under `dir`, a directory's URL, relative to `root`.
21
+ let documents = async (root: URL, dir: URL): Promise<string[]> => {
22
+ let entries = await Array.fromAsync(disk.readDir(dir))
23
+ .catch((e) => disk.isNotFound(e) ? [] : Promise.reject(e))
24
+ if (entries.some((e) => e.name == 'index.html')) return []
25
+ let found: string[] = []
26
+ for (let { name, isDirectory, isFile } of entries) {
27
+ if (name.startsWith('.') || SKIP.has(name)) continue
28
+ if (isDirectory) {
29
+ found.push(...await documents(root, new URL(`${name}/`, dir)))
30
+ } else if (
31
+ isFile && (name == 'vocab.json' || name.endsWith('.vocab.json'))
32
+ ) {
33
+ found.push(new URL(name, dir).href.slice(root.href.length))
34
+ }
35
+ }
36
+ return found
37
+ }
38
+
39
+ /** Mint the missing `$id`s into every vocabulary document under packages/ in
40
+ * the checkout at `root`, a directory's URL, and the files written, relative
41
+ * to it. */
42
+ export let mintIds = async (root: URL): Promise<string[]> => {
43
+ let wrote: string[] = []
44
+ for (let file of await documents(root, new URL('packages/', root))) {
45
+ let text = await disk.readTextFile(new URL(file, root))
46
+ let next = minted(text, mint)
47
+ if (next == text) continue
48
+ await disk.writeTextFile(new URL(file, root), next)
49
+ wrote.push(file)
50
+ }
51
+ return wrote.sort()
52
+ }
53
+
54
+ if (import.meta.main) {
55
+ let { command } = await import('@yaks/process/command')
56
+ let { execPath } = await import('@yaks/process/system')
57
+ let wrote = await mintIds(new URL('../../', import.meta.url))
58
+ for (let file of wrote) console.log(file)
59
+ if (wrote.length) {
60
+ await command(execPath(), { args: ['fmt', '--quiet', ...wrote] }).output()
61
+ }
62
+ }
package/vocab.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "$id": "urn:uuid:30982e84-79d3-44dd-882d-aa41c0e58087",
3
+ "title": "cli",
4
+ "$defs": {
5
+ "help": {
6
+ "tool": true,
7
+ "description": "List tools, or show one tool’s arguments.",
8
+ "readOnly": true,
9
+ "input": {
10
+ "words": {
11
+ "type": "array",
12
+ "items": {
13
+ "type": "string"
14
+ }
15
+ }
16
+ },
17
+ "positional": [
18
+ "words..."
19
+ ]
20
+ },
21
+ "restart": {
22
+ "tool": true,
23
+ "description": "Hand this box’s processes to ready replacements of the checkout’s code, queued in the background.",
24
+ "input": {
25
+ "replace": {
26
+ "type": "array",
27
+ "items": {
28
+ "type": "string"
29
+ },
30
+ "description": "Units to hand over even when they run this code. Accepts full names like yak-web or shorthand like web."
31
+ }
32
+ }
33
+ }
34
+ }
35
+ }
package/warm.js ADDED
@@ -0,0 +1,138 @@
1
+ // A graph tool, asked of the `yak serve` already running over the graph a
2
+ // command's config names. That server holds the whole read path loaded and
3
+ // warm, and answers in milliseconds what a command opening the graph itself
4
+ // spends half a second importing (./local.ts). Its `/mcp` is the door every
5
+ // agent's MCP tools already use, so a command and an MCP call run the same
6
+ // tool through the same runner. An answer printed to no terminal, and not as
7
+ // `--json`, is the text the server's own views draw (@yaks/api/address
8
+ // `TEXT`), which is what a command that opened the graph prints there
9
+ // (./local.ts `tool`, the host's `text`), so this process loads no views. One
10
+ // for a terminal is drawn here, with this config's own vocabulary and views,
11
+ // as a command that opened the graph draws it (./terminal.ts `shown`): the
12
+ // server's own account of its words is never needed, so no cached copy of it
13
+ // can be stale.
14
+ //
15
+ // Nothing has to be running: a command no server answers opens the graph
16
+ // itself, as it always could. The server is found at the address its config
17
+ // says it listens on (@yaks/api/address), and every request names the graph
18
+ // file it means. Only a server serving that file says it back, so an answer
19
+ // from one listening there for another graph (a copy's config naming the same
20
+ // port), or from one too old to say, is not taken for this graph's.
21
+ //
22
+ // A command runs here only where the server can run it exactly as this
23
+ // process would:
24
+ //
25
+ // - its tool declares no role beyond the graph (`serve` listens; a tool
26
+ // naming a plugin's role runs in that role's process);
27
+ // - it is not held in this terminal (`--tui`);
28
+ // - it reads, or it speaks for a session: the server signs a session's writes
29
+ // as that session (`x-via`, local.ts `signer`), and a line typed at a
30
+ // keyboard with none, which this process signs as the config's person,
31
+ // writes from here.
32
+ //
33
+ // Only a call the server never began is run again here: no server, one
34
+ // serving another graph, or one whose code predates the tool (an unknown
35
+ // tool). Once a call is under way, what the server says is the answer, and a
36
+ // connection lost during it is an error, never a second run.
37
+ import { ailing } from "@yaks/tools/check";
38
+ import { DB, served, TEXT } from "@yaks/api/address";
39
+ import { pluginViews, used } from "./config.js";
40
+ import { doorUrl, Refused, rpc } from "./rpc.js";
41
+ import { saidBy } from "./roster.js";
42
+ // JSON-RPC's invalid params, which an MCP server answers an unknown tool with
43
+ // before running anything.
44
+ let UNKNOWN = -32602;
45
+ /** Whether the server for `config` may run `declared` for this line. */ export let warmable = (c, config, declared)=>!!config.db && config.db != ':memory:' && !c.tui && !declared.roles?.some((role)=>role != 'graph') && (!!declared.readOnly || !!c.via);
46
+ /** `declared`, run by the server serving `config`'s graph and printed:
47
+ * the exit code, or undefined where no such server began it. */ export let warm = async (c, config, declared, args, fetch)=>{
48
+ if (!warmable(c, config, declared)) return;
49
+ let host = served(config);
50
+ let go = fetch ?? ((request)=>globalThis.fetch(request));
51
+ // The response to the request last sent, once one came: whether it said
52
+ // this graph's file back is whether this graph's server answered.
53
+ let last;
54
+ let ours = ()=>last?.headers.get(DB) == config.db;
55
+ let ask = rpc({
56
+ url: doorUrl(host),
57
+ via: c.via,
58
+ headers: {
59
+ [DB]: config.db,
60
+ ...c.json || c.tty ? {} : {
61
+ [TEXT]: 'drawn'
62
+ }
63
+ },
64
+ fetch: async (request)=>{
65
+ last = undefined;
66
+ return last = await go(request);
67
+ }
68
+ });
69
+ // A ping runs nothing, so whatever becomes of it, nothing has run yet.
70
+ try {
71
+ await ask('ping');
72
+ } catch {
73
+ return;
74
+ }
75
+ if (!ours()) return;
76
+ let said;
77
+ try {
78
+ said = await ask('tools/call', {
79
+ name: declared.name,
80
+ arguments: args
81
+ });
82
+ } catch (error) {
83
+ if (last && !ours()) return;
84
+ if (error instanceof Refused && error.code == UNKNOWN) return;
85
+ throw error;
86
+ }
87
+ if (last?.headers.has(TEXT)) {
88
+ let { text } = saidBy(said);
89
+ if (text) c.out(text);
90
+ return exit(declared, said);
91
+ }
92
+ return await printed(c, config, declared, said, ask);
93
+ };
94
+ // The bundles a reply answers with, which every tool whose answer is entities
95
+ // sends under `structuredContent.result` (@yaks/mcp `answerSchema`).
96
+ let bundles = (said)=>{
97
+ let result = said.structuredContent?.result;
98
+ return Array.isArray(result) ? result : undefined;
99
+ };
100
+ // The exit code ./local.ts `tool` would have returned: 1 for a refusal or a
101
+ // check whose own answer fails.
102
+ let exit = (declared, said)=>said.isError || ailing(declared, bundles(said) ?? []) ? 1 : 0;
103
+ // A reply printed as the command would have printed the answer had it run the
104
+ // tool itself (./local.ts `tool`): `--json` as the data, entities through the
105
+ // views, a refusal's exit code 1. A reply with no entities is its text.
106
+ let printed = async (c, config, declared, said, ask)=>{
107
+ let code = exit(declared, said);
108
+ let answer = bundles(said);
109
+ if (c.json && said.structuredContent !== undefined) {
110
+ c.out(JSON.stringify(said.structuredContent, null, 2));
111
+ return code;
112
+ }
113
+ if (!answer) {
114
+ let { text } = saidBy(said);
115
+ if (text) (code ? c.note : c.out)(text);
116
+ return code;
117
+ }
118
+ let plugins = (config.plugins ?? []).map(used);
119
+ let [{ vocab }, { registry }, { shown }] = await Promise.all([
120
+ import("./words.js").then(({ words })=>words(config)),
121
+ import("./answer.js"),
122
+ import("./shown.js")
123
+ ]);
124
+ let asked = (name, args)=>ask('tools/call', {
125
+ name,
126
+ arguments: args
127
+ }).then((r)=>bundles(r) ?? [], ()=>[]);
128
+ await shown(c, plugins, await registry(plugins, pluginViews), vocab, answer, {
129
+ lookup: (ids)=>asked('graph_show', {
130
+ ids
131
+ }),
132
+ query: (q)=>asked('graph_query', {
133
+ q
134
+ })
135
+ }, declared);
136
+ return code;
137
+ };
138
+ //# sourceMappingURL=warm.js.map
package/warm.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"warm.js","sources":["./warm.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,2EAA2E;AAC3E,4EAA4E;AAC5E,4EAA4E;AAC5E,2EAA2E;AAC3E,6EAA6E;AAC7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