@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
@@ -0,0 +1,162 @@
1
+ import { unfound } from '@yaks/fts'
2
+ import type { Bundle, Comp, Eid, Graph } from 'jsr:@yaks/graph@0.2.36'
3
+ import {
4
+ absent,
5
+ and,
6
+ eq,
7
+ fields,
8
+ limit,
9
+ list,
10
+ present,
11
+ text,
12
+ } from '@yaks/query'
13
+
14
+ type Directory = Pick<Graph, 'vocab' | 'read' | 'get'>
15
+ type Match = { entity: Eid; snippet: string }
16
+
17
+ let value = (row: Bundle, comp: string, prop: string) =>
18
+ String((row[comp] as Comp | undefined)?.[prop] ?? '')
19
+
20
+ let name = (row: Bundle) => value(row, 'doc', 'title')
21
+ let same = (a: string, b: string) => a.toLowerCase() == b.toLowerCase()
22
+ let named = (title: string, words: string) =>
23
+ same(title, words) ||
24
+ title.toLowerCase().startsWith(`${words.toLowerCase()} `)
25
+
26
+ let people = async (
27
+ graph: Directory,
28
+ words: string,
29
+ hidden: string[],
30
+ n: number,
31
+ ) =>
32
+ (await graph.read(and(
33
+ present('person'),
34
+ text(words),
35
+ fields('doc.title'),
36
+ limit(n),
37
+ ...hidden.map(absent),
38
+ ))).filter((row) => named(name(row), words))
39
+
40
+ let relatives = async (
41
+ graph: Directory,
42
+ words: string,
43
+ hidden: string[],
44
+ n: number,
45
+ ): Promise<Match[]> => {
46
+ if (!graph.vocab.comp('relationship')) return []
47
+ let possessive = words.match(/^(.+?)['’]s ([\p{L}-]+)$/iu)
48
+ let related = possessive ?? words.match(/^(.+) ([\p{L}-]+)$/u)
49
+ if (!related) return []
50
+ let [, anchor, role] = related
51
+ let anchors = await people(graph, anchor, hidden, n)
52
+ if (!anchors.length) return []
53
+ let links = await graph.read(and(
54
+ eq('relationship.role', role.toLowerCase()),
55
+ eq(
56
+ possessive ? 'edge.to' : 'edge.from',
57
+ list(...anchors.map((row) => row.entity.eid)),
58
+ ),
59
+ fields('edge'),
60
+ limit(n),
61
+ ...hidden.map(absent),
62
+ ))
63
+ let ends = new Set(
64
+ links.flatMap((
65
+ row,
66
+ ) => [value(row, 'edge', 'from'), value(row, 'edge', 'to')]),
67
+ )
68
+ let rows = await graph.get([...ends], ['person', 'doc.title', ...hidden])
69
+ let by = new Map(
70
+ rows.filter((row) => row.person && !hidden.some((c) => row[c]))
71
+ .map((row) => [row.entity.eid, row]),
72
+ )
73
+ return links.flatMap((row) => {
74
+ let from = value(row, 'edge', 'from'), to = by.get(value(row, 'edge', 'to'))
75
+ return by.has(from) && to
76
+ ? [{ entity: from, snippet: `${name(to)}'s ${role}` }]
77
+ : []
78
+ })
79
+ }
80
+
81
+ let accounts = async (
82
+ graph: Directory,
83
+ words: string,
84
+ hidden: string[],
85
+ n: number,
86
+ ): Promise<Match[]> => {
87
+ if (!graph.vocab.comp('yaks_account')) return []
88
+ let rows = await graph.read(and(
89
+ present('yaks_account'),
90
+ text(words),
91
+ fields('yaks_account'),
92
+ limit(n),
93
+ ...hidden.map(absent),
94
+ ))
95
+ return rows.flatMap((row) => {
96
+ let holder = value(row, 'yaks_account', 'holder')
97
+ let label = ['name', 'handle'].map((prop) =>
98
+ value(row, 'yaks_account', prop)
99
+ )
100
+ .find((value) => same(value, words))
101
+ return holder && label ? [{ entity: holder, snippet: label }] : []
102
+ })
103
+ }
104
+
105
+ let onYaks = async (graph: Directory, matches: Match[], hidden: string[]) => {
106
+ if (!matches.length || !graph.vocab.comp('yaks_account')) return []
107
+ let rows = await graph.read(and(
108
+ eq('yaks_account.holder', list(...new Set(matches.map((h) => h.entity)))),
109
+ fields('yaks_account.holder', 'yaks_account.handle'),
110
+ ...hidden.map(absent),
111
+ ))
112
+ let spaces = new Map<Eid, string[]>()
113
+ for (let row of rows) {
114
+ let holder = value(row, 'yaks_account', 'holder')
115
+ let handle = value(row, 'yaks_account', 'handle')
116
+ if (handle) {
117
+ spaces.set(holder, [...spaces.get(holder) ?? [], `${handle}.yaks.app`])
118
+ }
119
+ }
120
+ return matches.flatMap((match) => {
121
+ let urls = spaces.get(match.entity)
122
+ return urls?.length
123
+ ? [{
124
+ ...match,
125
+ snippet: [match.snippet, urls.sort().join(', ')].filter(Boolean).join(
126
+ ' · ',
127
+ ),
128
+ }]
129
+ : []
130
+ })
131
+ }
132
+
133
+ // Resolve short name and relationship lookups from the graph before merging
134
+ // the general full-text and meaning ranks of documents and transcripts.
135
+ export let peopleSearch = async (
136
+ graph: Directory,
137
+ words: string,
138
+ n: number,
139
+ ): Promise<Match[]> => {
140
+ if (!graph.vocab.comp('person') || !graph.vocab.prop('doc', 'title')) {
141
+ return []
142
+ }
143
+ let phrase = words.trim().replace(/^"(.*)"$/, '$1').replace(/\s+/g, ' ')
144
+ let withAccount = / yaks\.app(?: (?:account|space))?$/iu
145
+ let subject = phrase.replace(withAccount, '')
146
+ if (
147
+ !/^[\p{L}\p{N}][\p{L}\p{N} .&'’_-]{0,79}$/u.test(phrase) ||
148
+ subject.split(' ').length > 5
149
+ ) return []
150
+ let hidden = unfound(graph.vocab).not ?? []
151
+ let [names, relations, handles] = await Promise.all([
152
+ people(graph, subject, hidden, n),
153
+ relatives(graph, subject, hidden, n),
154
+ accounts(graph, subject, hidden, n),
155
+ ])
156
+ let matches = [
157
+ ...names.map((row) => ({ entity: row.entity.eid, snippet: '' })),
158
+ ...relations,
159
+ ...handles,
160
+ ]
161
+ return subject == phrase ? matches : onYaks(graph, matches, hidden)
162
+ }
package/platform.js ADDED
@@ -0,0 +1,184 @@
1
+ // The subcommands a remote MCP server contributes: every tool `tools/list`
2
+ // names becomes a subcommand of the same name, with that tool's own input
3
+ // schema as its grammar and its own help page. This is what `yak` has always
4
+ // done; it is a separate module so that the account subcommands and the apps'
5
+ // commands can sit beside these in one list, all printed by one usage page.
6
+ //
7
+ // The tool list is fetched once and cached (store.ts), so it costs a round
8
+ // trip on a cold cache and nothing after that. What a tool result reports
9
+ // about that list on the way back is read here too — `printed` is the one
10
+ // place a tool's result becomes stdout, an exit code, and a cache that is
11
+ // still current.
12
+ //
13
+ // A result's answer is shown the way a local graph's is, through the views
14
+ // (./answer.ts): the reply carries the bundles the tool answered, and the
15
+ // server's vocabulary, asked for once, says what they are and which packages'
16
+ // views draw them. Only a reply with no bundles in it — a tool with an output
17
+ // schema of its own, a server that is not a graph — is printed as the text it
18
+ // came as.
19
+ import { initialize } from "./rpc.js";
20
+ import { schemaOf } from "./member.js";
21
+ import { rosterAfter, saidBy, versionIn } from "./roster.js";
22
+ import { cached, forget, remember } from "./store.js";
23
+ import { spelling } from "./tool.js";
24
+ /** The tool list for a host: the cached one, or an `initialize` handshake
25
+ * followed by `tools/list` — always the latter when `fresh`. The protocol
26
+ * version is negotiated on that same path and cached beside the list, and so
27
+ * is the roster `version` an `about` answered just before it (roster.ts). */ export let rosterOf = async (host, ask, state, fresh = false, version)=>{
28
+ let kept = fresh ? null : await cached(host, state);
29
+ if (kept) return kept;
30
+ let hello = await initialize(ask);
31
+ let listed = await ask('tools/list');
32
+ let roster = {
33
+ ...version ? {
34
+ version
35
+ } : {},
36
+ protocol: String(hello.protocolVersion ?? ''),
37
+ tools: listed.tools ?? []
38
+ };
39
+ await remember(host, roster, state);
40
+ return roster;
41
+ };
42
+ // A reply's answer as entities: the bundles under `structuredContent.result`,
43
+ // which every tool whose answer is entities sends (@yaks/mcp `answerSchema`).
44
+ // A tool with an output schema of its own sends its value there instead.
45
+ let answered = (said)=>{
46
+ let result = said.structuredContent?.result;
47
+ return Array.isArray(result) ? result : null;
48
+ };
49
+ // The server's vocabulary in full: the index `graph_schema` answers with no
50
+ // arguments names every component, and asking for all of them by name returns
51
+ // each as declared — the letter its ids are printed with, and which kind wins
52
+ // the display. Asked once and kept beside the tool list, so it goes when the
53
+ // list does. A server that lists no `graph_schema` has none to give.
54
+ let vocabOf = async (c, held)=>{
55
+ let roster = held ?? await rosterOf(c.host, c.ask, c.state);
56
+ if (roster.vocab) return roster.vocab;
57
+ if (!roster.tools.some((t)=>t.name == 'graph_schema')) return null;
58
+ let whole = await schemaOf(c.ask);
59
+ if (!whole) return null;
60
+ await remember(c.host, {
61
+ ...roster,
62
+ vocab: whole
63
+ }, c.state);
64
+ return whole;
65
+ };
66
+ let prepare = (doc)=>import("./reported.js").then(({ reported })=>reported(doc));
67
+ // A cached vocabulary and a declared entity answer let independent, pure
68
+ // drawing preparation run beside the tool call. Its failure is reported only
69
+ // if that answer actually needs drawing; tool errors retain their own output.
70
+ let preparing = (c, roster, t, load)=>{
71
+ if (c.json || !roster.vocab || t.outputSchema?.properties?.result?.type != 'array') return;
72
+ let doc = roster.vocab;
73
+ let ready = load(doc);
74
+ void ready.catch(()=>{});
75
+ return {
76
+ doc,
77
+ ready
78
+ };
79
+ };
80
+ /**
81
+ * Show a tool's result, and the roster notice the server added beside it
82
+ * (roster.ts). Returns the exit code. A caller holding no tool list passes
83
+ * `null` — a staleness notice still drops the cache. `tool` is what the server
84
+ * listed about the tool that decides how its answer is drawn (./answer.ts
85
+ * `Drawn`).
86
+ */ export let printed = async (c, roster, name, said, args = {}, tool = {
87
+ readOnly: true
88
+ }, drawing)=>{
89
+ let { text, stale } = saidBy(said);
90
+ // What this result reported about the tool list this client is holding
91
+ // (roster.ts). A staleness notice alone is enough to drop the cache; a
92
+ // caller holding no list has nothing of its own to keep fresh, and must not
93
+ // throw away somebody else's. An `about` that did not confirm the list is
94
+ // the moment to list again: the version it named is the one to stamp.
95
+ let held = roster && rosterAfter(roster, name, said);
96
+ let seen = name == 'about' ? versionIn(said) : undefined;
97
+ if (roster && !held && seen) {
98
+ held = await rosterOf(c.host, c.ask, c.state, true, seen).catch(()=>null);
99
+ }
100
+ if ((roster || stale) && !held) await forget(c.host, c.state);
101
+ if (stale) c.note(stale);
102
+ if (said.isError) {
103
+ c.note(text || 'the tool erred and said nothing');
104
+ return 1;
105
+ }
106
+ if (c.json) {
107
+ c.out(JSON.stringify(said.structuredContent ?? said, null, 2));
108
+ return 0;
109
+ }
110
+ let answer = answered(said);
111
+ let vocab = answer && await vocabOf(c, held ?? undefined);
112
+ if (answer && vocab) {
113
+ // Imported only to draw, so a command that never does pays nothing.
114
+ let [{ show }, { reported }] = await Promise.all([
115
+ import("./tty.js"),
116
+ import("./reported.js")
117
+ ]);
118
+ let { views, vocab: read, components } = await (drawing?.doc == vocab ? drawing.ready : reported(vocab));
119
+ // What the drawing asks for beyond the answer — the entities its
120
+ // references name, a page's links and comments — asked of the same host
121
+ // in the same app the call named. A drawing that cannot get them draws
122
+ // without them.
123
+ let scope = Object.fromEntries([
124
+ 'app',
125
+ 'space'
126
+ ].flatMap((k)=>args[k] == null ? [] : [
127
+ [
128
+ k,
129
+ args[k]
130
+ ]
131
+ ]));
132
+ let asked = (tool, more)=>c.ask('tools/call', {
133
+ name: tool,
134
+ arguments: {
135
+ ...scope,
136
+ ...more
137
+ }
138
+ }).then((r)=>answered(r) ?? [], ()=>[]);
139
+ await show(c, views, read, answer, c.tty || c.tui ? {
140
+ views: await components()
141
+ } : {}, {
142
+ lookup: (ids)=>asked('graph_show', {
143
+ ids
144
+ }),
145
+ query: (q)=>asked('graph_query', {
146
+ q
147
+ })
148
+ }, tool);
149
+ } else if (text) c.out(text);
150
+ return 0;
151
+ };
152
+ // One tool the server listed, as a subcommand this program runs: its published
153
+ // input schema is the command-line grammar, and running the subcommand makes
154
+ // the call. The tool's two words and its argument layout come along where it
155
+ // declared them (tool.ts `spelling`), so `yak task new 'ship it'` is typed the
156
+ // way the tool declared, and a server that declares neither still lists the
157
+ // tool under one flat name.
158
+ let toolOf = (roster, t, load)=>({
159
+ name: t.name,
160
+ ...spelling(t),
161
+ ...t.title ?? t.annotations?.title ? {
162
+ title: t.title ?? t.annotations?.title
163
+ } : {},
164
+ description: t.description ?? '',
165
+ run: async (args, c)=>{
166
+ let drawing = preparing(c, roster, t, load);
167
+ return await printed(c, roster, t.name, await c.ask('tools/call', {
168
+ name: t.name,
169
+ arguments: args
170
+ }), args, {
171
+ readOnly: t.annotations?.readOnlyHint,
172
+ page: spelling(t).page
173
+ }, drawing);
174
+ }
175
+ });
176
+ /** A held roster as commands. Drawing preparation is a separate boundary
177
+ * so a tool error or plain reply can be answered even if its views fail. */ export let commands = (roster, load = prepare)=>roster.tools.map((t)=>toolOf(roster, t, load));
178
+ /** Every tool this server lists, as a subcommand. This is the list that costs
179
+ * a round trip (run.ts `more`), so a command that never needs it pays
180
+ * nothing, and `fresh` asks the server past the cache. */ export let listed = async (c, o = {})=>{
181
+ let roster = await rosterOf(c.host, c.ask, c.state, o.fresh);
182
+ return commands(roster);
183
+ };
184
+ //# sourceMappingURL=platform.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"platform.js","sources":["./platform.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,0EAA0E;AAC1E,6EAA6E;AAC7E,8EAA8E;AAC9E,4EAA4E;AAC5E,EAAE;AACF,2EAA2E;AAC3E,0EAA0E;AAC1E,0EAA0E;AAC1E,0EAA0E;AAC1E,iBAAiB;AACjB,EAAE;AACF,2EAA2E;AAC3E,0EAA0E;AAC1E,8EAA8E;AAC9E,8EAA8E;AAC9E,8EAA8E;AAC9E,WAAW;AAMX,SAAS,UAAU,mBAA4B;AAC/C,SAAS,QAAQ,sBAAqB;AACtC,SAAsB,WAAW,EAAE,MAAM,EAAE,SAAS,sBAAqB;AACzE,SAAS,MAAM,EAAE,MAAM,EAAE,QAAQ,qBAAiC;AAClE,SAAsB,QAAQ,oBAAmB;AAEjD;;;2EAG2E,GAC3E,OAAO,IAAI,WAAW,OACpB,MACA,KACA,OACA,QAAQ,KAAK,EACb;EAEA,IAAI,OAAO,QAAQ,OAAO,MAAM,OAAO,MAAM;EAC7C,IAAI,MAAM,OAAO;EACjB,IAAI,QAAQ,MAAM,WAAW;EAC7B,IAAI,SAAS,MAAM,IAAI;EACvB,IAAI,SAAiB;IACnB,GAAG,UAAU;MAAE;IAAQ,IAAI,CAAC,CAAC;IAC7B,UAAU,OAAO,MAAM,eAAe,IAAI;IAC1C,OAAQ,OAAO,KAAK,IAAI,EAAE;EAC5B;EACA,MAAM,SAAS,MAAM,QAAQ;EAC7B,OAAO;AACT,EAAC;AAED,8EAA8E;AAC9E,8EAA8E;AAC9E,yEAAyE;AACzE,IAAI,WAAW,CAAC;EACd,IAAI,SAAU,KAAK,iBAAiB,EACh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;wDAEwD,GACxD,OAAO,IAAI,SAAS,OAClB,GACA,IAAyB,CAAC,CAAC;EAE3B,IAAI,SAAS,MAAM,SAAS,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE,EAAE,KAAK,EAAE,EAAE,KAAK;EAC3D,OAAO,SAAS;AAClB,EAAC"}
package/platform.ts ADDED
@@ -0,0 +1,224 @@
1
+ // The subcommands a remote MCP server contributes: every tool `tools/list`
2
+ // names becomes a subcommand of the same name, with that tool's own input
3
+ // schema as its grammar and its own help page. This is what `yak` has always
4
+ // done; it is a separate module so that the account subcommands and the apps'
5
+ // commands can sit beside these in one list, all printed by one usage page.
6
+ //
7
+ // The tool list is fetched once and cached (store.ts), so it costs a round
8
+ // trip on a cold cache and nothing after that. What a tool result reports
9
+ // about that list on the way back is read here too — `printed` is the one
10
+ // place a tool's result becomes stdout, an exit code, and a cache that is
11
+ // still current.
12
+ //
13
+ // A result's answer is shown the way a local graph's is, through the views
14
+ // (./answer.ts): the reply carries the bundles the tool answered, and the
15
+ // server's vocabulary, asked for once, says what they are and which packages'
16
+ // views draw them. Only a reply with no bundles in it — a tool with an output
17
+ // schema of its own, a server that is not a graph — is printed as the text it
18
+ // came as.
19
+
20
+ import type { Bundle } from 'jsr:@yaks/graph@0.2.36'
21
+ import type { VocabDoc } from 'jsr:@yaks/vocab@0.2.36'
22
+ import type { Command, Ctx } from './run.ts'
23
+ import type { Drawn } from './answer.ts'
24
+ import { initialize, type Rpc } from './rpc.js'
25
+ import { schemaOf } from './member.js'
26
+ import { type Result, rosterAfter, saidBy, versionIn } from './roster.js'
27
+ import { cached, forget, remember, type Roster } from './store.js'
28
+ import { type Listed, spelling } from './tool.js'
29
+
30
+ /** The tool list for a host: the cached one, or an `initialize` handshake
31
+ * followed by `tools/list` — always the latter when `fresh`. The protocol
32
+ * version is negotiated on that same path and cached beside the list, and so
33
+ * is the roster `version` an `about` answered just before it (roster.ts). */
34
+ export let rosterOf = async (
35
+ host: string,
36
+ ask: Rpc,
37
+ state?: string,
38
+ fresh = false,
39
+ version?: string,
40
+ ): Promise<Roster> => {
41
+ let kept = fresh ? null : await cached(host, state)
42
+ if (kept) return kept
43
+ let hello = await initialize(ask)
44
+ let listed = await ask('tools/list')
45
+ let roster: Roster = {
46
+ ...version ? { version } : {},
47
+ protocol: String(hello.protocolVersion ?? ''),
48
+ tools: (listed.tools ?? []) as Listed[],
49
+ }
50
+ await remember(host, roster, state)
51
+ return roster
52
+ }
53
+
54
+ // A reply's answer as entities: the bundles under `structuredContent.result`,
55
+ // which every tool whose answer is entities sends (@yaks/mcp `answerSchema`).
56
+ // A tool with an output schema of its own sends its value there instead.
57
+ let answered = (said: Result): Bundle[] | null => {
58
+ let result = (said.structuredContent as { result?: unknown } | undefined)
59
+ ?.result
60
+ return Array.isArray(result) ? result : null
61
+ }
62
+
63
+ // The server's vocabulary in full: the index `graph_schema` answers with no
64
+ // arguments names every component, and asking for all of them by name returns
65
+ // each as declared — the letter its ids are printed with, and which kind wins
66
+ // the display. Asked once and kept beside the tool list, so it goes when the
67
+ // list does. A server that lists no `graph_schema` has none to give.
68
+ let vocabOf = async (c: Ctx, held?: Roster): Promise<VocabDoc | null> => {
69
+ let roster = held ?? await rosterOf(c.host, c.ask, c.state)
70
+ if (roster.vocab) return roster.vocab
71
+ if (!roster.tools.some((t) => t.name == 'graph_schema')) return null
72
+ let whole = await schemaOf(c.ask)
73
+ if (!whole) return null
74
+ await remember(c.host, { ...roster, vocab: whole }, c.state)
75
+ return whole
76
+ }
77
+
78
+ type Drawing = {
79
+ doc: VocabDoc
80
+ ready: Promise<Awaited<ReturnType<typeof import('./reported.js').reported>>>
81
+ }
82
+
83
+ type Prepare = (doc: VocabDoc) => Drawing['ready']
84
+ let prepare: Prepare = (doc) =>
85
+ import('./reported.js').then(({ reported }) => reported(doc))
86
+
87
+ // A cached vocabulary and a declared entity answer let independent, pure
88
+ // drawing preparation run beside the tool call. Its failure is reported only
89
+ // if that answer actually needs drawing; tool errors retain their own output.
90
+ let preparing = (
91
+ c: Ctx,
92
+ roster: Roster,
93
+ t: Listed,
94
+ load: Prepare,
95
+ ): Drawing | undefined => {
96
+ if (
97
+ c.json || !roster.vocab ||
98
+ t.outputSchema?.properties?.result?.type != 'array'
99
+ ) return
100
+ let doc = roster.vocab
101
+ let ready = load(doc)
102
+ void ready.catch(() => {})
103
+ return { doc, ready }
104
+ }
105
+
106
+ /**
107
+ * Show a tool's result, and the roster notice the server added beside it
108
+ * (roster.ts). Returns the exit code. A caller holding no tool list passes
109
+ * `null` — a staleness notice still drops the cache. `tool` is what the server
110
+ * listed about the tool that decides how its answer is drawn (./answer.ts
111
+ * `Drawn`).
112
+ */
113
+ export let printed = async (
114
+ c: Ctx,
115
+ roster: Roster | null,
116
+ name: string,
117
+ said: Result,
118
+ args: Record<string, unknown> = {},
119
+ tool: Drawn = { readOnly: true },
120
+ drawing?: Drawing,
121
+ ): Promise<number> => {
122
+ let { text, stale } = saidBy(said)
123
+ // What this result reported about the tool list this client is holding
124
+ // (roster.ts). A staleness notice alone is enough to drop the cache; a
125
+ // caller holding no list has nothing of its own to keep fresh, and must not
126
+ // throw away somebody else's. An `about` that did not confirm the list is
127
+ // the moment to list again: the version it named is the one to stamp.
128
+ let held = roster && rosterAfter(roster, name, said)
129
+ let seen = name == 'about' ? versionIn(said) : undefined
130
+ if (roster && !held && seen) {
131
+ held = await rosterOf(c.host, c.ask, c.state, true, seen)
132
+ .catch(() => null)
133
+ }
134
+ if ((roster || stale) && !held) await forget(c.host, c.state)
135
+ if (stale) c.note(stale)
136
+ if (said.isError) {
137
+ c.note(text || 'the tool erred and said nothing')
138
+ return 1
139
+ }
140
+ if (c.json) {
141
+ c.out(JSON.stringify(said.structuredContent ?? said, null, 2))
142
+ return 0
143
+ }
144
+ let answer = answered(said)
145
+ let vocab = answer && await vocabOf(c, held ?? undefined)
146
+ if (answer && vocab) {
147
+ // Imported only to draw, so a command that never does pays nothing.
148
+ let [{ show }, { reported }] = await Promise.all([
149
+ import('./tty.js'),
150
+ import('./reported.js'),
151
+ ])
152
+ let { views, vocab: read, components } =
153
+ await (drawing?.doc == vocab ? drawing.ready : reported(vocab))
154
+ // What the drawing asks for beyond the answer — the entities its
155
+ // references name, a page's links and comments — asked of the same host
156
+ // in the same app the call named. A drawing that cannot get them draws
157
+ // without them.
158
+ let scope = Object.fromEntries(
159
+ ['app', 'space'].flatMap((k) => args[k] == null ? [] : [[k, args[k]]]),
160
+ )
161
+ let asked = (tool: string, more: Record<string, unknown>) =>
162
+ c.ask('tools/call', { name: tool, arguments: { ...scope, ...more } })
163
+ .then((r) => answered(r as Result) ?? [], () => [])
164
+ await show(
165
+ c,
166
+ views,
167
+ read,
168
+ answer,
169
+ c.tty || c.tui ? { views: await components() } : {},
170
+ {
171
+ lookup: (ids) => asked('graph_show', { ids }),
172
+ query: (q) => asked('graph_query', { q }),
173
+ },
174
+ tool,
175
+ )
176
+ } else if (text) c.out(text)
177
+ return 0
178
+ }
179
+
180
+ // One tool the server listed, as a subcommand this program runs: its published
181
+ // input schema is the command-line grammar, and running the subcommand makes
182
+ // the call. The tool's two words and its argument layout come along where it
183
+ // declared them (tool.ts `spelling`), so `yak task new 'ship it'` is typed the
184
+ // way the tool declared, and a server that declares neither still lists the
185
+ // tool under one flat name.
186
+ let toolOf = (roster: Roster, t: Listed, load: Prepare): Command => ({
187
+ name: t.name,
188
+ ...spelling(t),
189
+ ...(t.title ?? t.annotations?.title
190
+ ? { title: t.title ?? t.annotations?.title }
191
+ : {}),
192
+ description: t.description ?? '',
193
+ run: async (args, c) => {
194
+ let drawing = preparing(c, roster, t, load)
195
+ return await printed(
196
+ c,
197
+ roster,
198
+ t.name,
199
+ await c.ask('tools/call', {
200
+ name: t.name,
201
+ arguments: args,
202
+ }) as Result,
203
+ args,
204
+ { readOnly: t.annotations?.readOnlyHint, page: spelling(t).page },
205
+ drawing,
206
+ )
207
+ },
208
+ })
209
+
210
+ /** A held roster as commands. Drawing preparation is a separate boundary
211
+ * so a tool error or plain reply can be answered even if its views fail. */
212
+ export let commands = (roster: Roster, load: Prepare = prepare): Command[] =>
213
+ roster.tools.map((t) => toolOf(roster, t, load))
214
+
215
+ /** Every tool this server lists, as a subcommand. This is the list that costs
216
+ * a round trip (run.ts `more`), so a command that never needs it pays
217
+ * nothing, and `fresh` asks the server past the cache. */
218
+ export let listed = async (
219
+ c: Ctx,
220
+ o: { fresh?: boolean } = {},
221
+ ): Promise<Command[]> => {
222
+ let roster = await rosterOf(c.host, c.ask, c.state, o.fresh)
223
+ return commands(roster)
224
+ }
@@ -0,0 +1,5 @@
1
+ import { workspaceEffects } from "@yaks/machine/effects";
2
+ /** The box's operations use its chosen workspace connectors. */ export let platformEffects = (h)=>({
3
+ ...h.workspaces ? workspaceEffects(h.graph, async (id, _actor, run)=>await run(await h.workspaces.connect(id))) : {}
4
+ });
5
+ //# sourceMappingURL=platform_effects.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"platform_effects.js","sources":["./platform_effects.ts"],"names":[],"mappings":"AAEA,SAAS,gBAAgB,qCAA0C;AAEnE,8DAA8D,GAC9D,OAAO,IAAI,kBAAkB,CAAC,IAAuC,CAAC;IACpE,GAAG,EAAE,UAAU,GACX,iBACA,EAAE,KAAK,EACP,OAAO,IAAI,QAAQ,MAAQ,MAAM,IAAI,MAAM,EAAE,UAAU,CAAE,OAAO,CAAC,QAEjE,CAAC,CAAC;EACR,CAAC,EAAC"}
@@ -0,0 +1,13 @@
1
+ import type { Operation } from 'jsr:@yaks/effects@0.2.36/invocation'
2
+ import type { Host } from 'jsr:@yaks/host@0.2.36'
3
+ import { workspaceEffects } from '@yaks/machine/effects'
4
+
5
+ /** The box's operations use its chosen workspace connectors. */
6
+ export let platformEffects = (h: Host): Record<string, Operation> => ({
7
+ ...h.workspaces
8
+ ? workspaceEffects(
9
+ h.graph,
10
+ async (id, _actor, run) => await run(await h.workspaces!.connect(id)),
11
+ )
12
+ : {},
13
+ })
package/prepare.js ADDED
@@ -0,0 +1,40 @@
1
+ // One module graph for a command's runtime and the facets it will consume.
2
+ // Metadata discovery imports none of this code; graph tools and rendering
3
+ // arrive only when a command asks for them.
4
+ import { subpaths, used } from "./config.js";
5
+ import { declarations } from "./declarations.js";
6
+ import { ROLES, rolesOf } from "./roles.js";
7
+ export let prepare = async (config, command, selected, draw = false)=>{
8
+ let said = await declarations(config, true);
9
+ let roles = rolesOf(command, said.pooled);
10
+ let web = roles.includes('web');
11
+ let owner = command.name && said.owners[command.name];
12
+ selected ??= owner ? [
13
+ owner,
14
+ 'tools'
15
+ ] : undefined;
16
+ let factories = new Set(said.vocabs.filter((v)=>v.factories).map((v)=>v.plugin));
17
+ let requests = (config.plugins ?? []).map(used).flatMap((plugin)=>{
18
+ let names = [];
19
+ for (let role of roles){
20
+ if (Object.hasOwn(ROLES, role)) {
21
+ names.push(...ROLES[role].filter((name)=>name != 'tools' && (name != 'vocab' || factories.has(plugin))));
22
+ } else if (role == plugin) names.push('service');
23
+ }
24
+ if (selected?.[0] == plugin) names.push(selected[1]);
25
+ // A web draws its answer only once it stops: its views load then, and
26
+ // not before it listens.
27
+ if (draw && !web && selected?.[1] != 'cli') names.push('views');
28
+ return [
29
+ ...new Set(names)
30
+ ].filter((name)=>said.facets[plugin].includes(name)).map((name)=>[
31
+ plugin,
32
+ name
33
+ ]);
34
+ });
35
+ let modules = await subpaths(requests, [
36
+ new URL('./local.ts', import.meta.url).href
37
+ ]);
38
+ return modules.at(-1);
39
+ };
40
+ //# sourceMappingURL=prepare.js.map
package/prepare.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prepare.js","sources":["./prepare.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,0EAA0E;AAC1E,4CAA4C;AAC5C,SAAsB,QAAQ,EAAE,IAAI,sBAAqB;AACzD,SAAS,YAAY,4BAA2B;AAChD,SAAS,KAAK,EAAE,OAAO,qBAAoB;AAG3C,OAAO,IAAI,UAAU,OACnB,QACA,SACA,UACA,OAAO,KAAK;EAEZ,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