@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/run.js ADDED
@@ -0,0 +1,533 @@
1
+ import * as system from "@yaks/process/system";
2
+ import * as files from "@yaks/file/io";
3
+ import { argsFor, commandFor, Usage } from "./args.js";
4
+ import { lineOf, safe, sketch, toolHelp } from "./show.js";
5
+ import { commandOf, titleOf } from "./tool.js";
6
+ import { timed } from "@yaks/api/timing";
7
+ import { doorUrl, rpc, Unauthorized } from "./rpc.js";
8
+ import { configPath } from "./config.js";
9
+ import { stateDir, tokenFor } from "./store.js";
10
+ // This process's environment: what every `env` seam here defaults to.
11
+ let own = (name)=>system.env.get(name);
12
+ // This process's stdout, where it is a terminal a person reads in color. A
13
+ // terminal that reports no size (`script` run without one) is the usual 80
14
+ // wide, rather than a width nothing fits in.
15
+ let terminal = (env)=>system.stdout.isTerminal() && !env('NO_COLOR') ? {
16
+ columns: system.consoleSize().columns || 80,
17
+ write: (t)=>console.log(t)
18
+ } : undefined;
19
+ /**
20
+ * The tools, refused where two of them answer to one command line. A two-word
21
+ * tool is reachable in either order, so `session list` and `list session` are
22
+ * the same tool, and a second tool using either pair is a command line that
23
+ * means two things.
24
+ *
25
+ * `cli` does not apply this to the whole list, because shadowing is the point
26
+ * of the order: a program that carries its own `login` means it. A contributor
27
+ * runs this over its own list, where two tools of one name are a mistake.
28
+ */ export let unique = (tools)=>{
29
+ let said = new Set();
30
+ for (let t of tools){
31
+ let words = t.noun && t.verb ? [
32
+ `${t.noun} ${t.verb}`,
33
+ `${t.verb} ${t.noun}`
34
+ ] : [
35
+ commandOf(t)
36
+ ];
37
+ if (!words[0]) throw new Error('a tool needs a name, or a noun and a verb');
38
+ for (let w of new Set(words)){
39
+ if (said.has(w)) throw new Error(`two tools answer to: ${w}`);
40
+ said.add(w);
41
+ }
42
+ }
43
+ return tools;
44
+ };
45
+ /**
46
+ * The tool a command line names, and the words left for its schema. A two-word
47
+ * tool takes the word after it in either order; a one-word tool takes none.
48
+ *
49
+ * ```ts
50
+ * commandFor([{noun: 'session', verb: 'list', description: '', run: () => 0}],
51
+ * ['list', 'session', '--all'])?.args // ['--all']
52
+ * ```
53
+ */ export { commandFor } from "./args.js";
54
+ // One column across the page, so it reads as one page. Capped: a long
55
+ // argument sketch pushes its own line out rather than every other line.
56
+ let WIDE = 30;
57
+ /** One tool per listed name, in the order they were given: where two answer
58
+ * to one command line, the first one wins. */ let once = (tools)=>{
59
+ let seen = new Set();
60
+ return tools.filter((t)=>!seen.has(commandOf(t)) && seen.add(commandOf(t)));
61
+ };
62
+ /**
63
+ * The tools grouped under the noun each is typed with: `graph` holds `apply`,
64
+ * `query` and the rest, and a tool that declared one word alone — or none — is
65
+ * grouped under `''`, which is the page's own first block. Nouns come in the
66
+ * order they were first named, so the order of the list is still the order of
67
+ * the page.
68
+ *
69
+ * ```ts
70
+ * nouns([{ noun: 'graph', verb: 'apply', description: '', run: () => 0 }])
71
+ * .map(([noun]) => noun) // ['graph']
72
+ * ```
73
+ */ export let nouns = (tools)=>{
74
+ let by = new Map([
75
+ [
76
+ '',
77
+ []
78
+ ]
79
+ ]);
80
+ for (let t of once(tools)){
81
+ let noun = t.noun && t.verb ? t.noun : '';
82
+ let said = by.get(noun) ?? [];
83
+ by.set(noun, said);
84
+ said.push(t);
85
+ }
86
+ return [
87
+ ...by
88
+ ].filter(([, said])=>said.length);
89
+ };
90
+ // The line to type, with the heading's own word left out: under `graph`, a
91
+ // tool is its verb and its arguments.
92
+ let lineIn = (noun, t, omit)=>noun ? `${t.verb} ${sketch(t, t.globals, omit)}`.trimEnd() : lineOf(t, t.globals, omit);
93
+ let helpFor = (t, opts)=>toolHelp(t, opts.name, (opts.globalFlags ?? []).filter((n)=>!t.globals?.includes(n)));
94
+ let lines = (noun, said, omit)=>said.map((t)=>({
95
+ text: lineIn(noun, t, omit),
96
+ title: titleOf(t)
97
+ }));
98
+ let block = (noun, said, wide)=>[
99
+ ...noun ? [
100
+ '',
101
+ noun
102
+ ] : [],
103
+ ...said.map(({ text, title })=>` ${text.padEnd(wide)} ${title}`.trimEnd())
104
+ ];
105
+ // Measure the same lines that are printed, without sketching their arguments
106
+ // again: a help page renders every tool's schema only once.
107
+ let column = (groups)=>Math.min(WIDE, Math.max(0, ...groups.flatMap(([, said])=>said.map((l)=>l.text.length))));
108
+ /** Every tool, one line each, its verbs grouped under their noun. */ export let usage = (tools, opts = {})=>{
109
+ let groups = nouns(tools).map(([noun, said])=>[
110
+ noun,
111
+ lines(noun, said, opts.globalFlags ?? [])
112
+ ]);
113
+ let wide = column(groups);
114
+ return [
115
+ ...opts.about ? [
116
+ opts.about,
117
+ ''
118
+ ] : [],
119
+ ...groups.flatMap(([noun, said])=>block(noun, said, wide)),
120
+ ...opts.notes ? [
121
+ '',
122
+ opts.notes
123
+ ] : []
124
+ ].join('\n');
125
+ };
126
+ /** One noun's own page: its verbs, one line each, under the word itself —
127
+ * what `yak graph` and `yak graph --help` print. Nothing where no tool here is
128
+ * typed under that word. */ export let nounUsage = (tools, word, reserved = [])=>{
129
+ let said = nouns(tools).find(([noun])=>noun && noun == word);
130
+ if (!said) return undefined;
131
+ let group = [
132
+ said[0],
133
+ lines(said[0], said[1], reserved)
134
+ ];
135
+ return block(group[0], group[1], column([
136
+ group
137
+ ])).slice(1).join('\n');
138
+ };
139
+ /** The flags a program keeps for itself, lifted off the command line before a
140
+ * command ever sees it. `host` and `config` are what the command line gave and
141
+ * nothing else — where a command runs when it gives neither is
142
+ * {@link aimed}'s answer. */ export let globals = (argv, env = own)=>{
143
+ let host;
144
+ let json = false;
145
+ let tui = false;
146
+ let duties = true;
147
+ let help = false;
148
+ let version = false;
149
+ let config;
150
+ // A whole process tree runs as one account with YAK_AS (`yak admin
151
+ // throwaway`); one command asks with the flag.
152
+ let as = env('YAK_AS') || undefined;
153
+ // A whole shell asks for the timing line with YAKS_TIMING=1; one command
154
+ // asks with the flag.
155
+ let timing = env('YAKS_TIMING') == '1';
156
+ let rest = [];
157
+ for(let i = 0; i < argv.length; i++){
158
+ let a = argv[i];
159
+ if (a == '--json') json = true;
160
+ else if (a == '--tui') tui = true;
161
+ else if (a == '--no-duties') duties = false;
162
+ else if (a == '--help' || a == '-h') help = true;
163
+ else if (a == '--version' && !rest.length) version = true;
164
+ else if (a == '--timing') timing = true;
165
+ else if (a == '--as') as = argv[++i] ?? as;
166
+ else if (a.startsWith('--as=')) as = a.slice(5);
167
+ else if (a == '--host') host = argv[++i] ?? host;
168
+ else if (a.startsWith('--host=')) host = a.slice(7);
169
+ else if (a == '--config') config = argv[++i] ?? config;
170
+ else if (a.startsWith('--config=')) config = a.slice(9);
171
+ else rest.push(a);
172
+ }
173
+ return {
174
+ host,
175
+ config,
176
+ as,
177
+ duties,
178
+ json,
179
+ tui,
180
+ help,
181
+ version,
182
+ timing,
183
+ rest
184
+ };
185
+ };
186
+ /**
187
+ * Where this command runs what it was asked: the graph a config file names,
188
+ * which it opens in this process, or an MCP server it calls over `/mcp`.
189
+ *
190
+ * A config names A graph. `yak --config yak.json task list` reads that file,
191
+ * composes its plugins over the SQLite file it names, runs the tool here and
192
+ * exits — no server, and nothing to wait for. `--host` is for a graph this
193
+ * machine cannot open as a file; given together the two name two places, which
194
+ * is a command line that means two things.
195
+ *
196
+ * In order: `--config`, `--host`, `$YAKS_HOST`, `$YAK_CONFIG`, the config this
197
+ * machine keeps for its own graph (`~/.yak/yak.json`), and the platform this
198
+ * program came with. A host name comes back either way, because it is also the
199
+ * name a bearer token is stored under.
200
+ *
201
+ * A config the line named is the one place the line means. A config found in
202
+ * the environment or at home is only the first place in the order, so a word
203
+ * its graph lacks goes `onward`, to the host: `yak app_list` on a machine that
204
+ * keeps a graph of its own still reaches the platform.
205
+ *
206
+ * A line that said nothing, on a machine that keeps no graph, falls to the
207
+ * platform only by default: it is `unplaced`, and a platform that will not
208
+ * answer it is not what the person was asking about.
209
+ *
210
+ * ```ts
211
+ * aimed({ host: 'yaks.app' }) // { host: 'yaks.app' }
212
+ * aimed({}, 'yaks.app', () => undefined) // { host: 'yaks.app', unplaced: true }
213
+ * aimed({}, 'yaks.app', (n) => n == 'YAK_CONFIG' ? 'yak.json' : undefined)
214
+ * // { config: 'yak.json', host: 'yaks.app', onward: true }
215
+ * ```
216
+ */ export let aimed = (said, dflt = 'yaks.app', env = own)=>{
217
+ if (said.host && said.config) {
218
+ throw new Usage('--host and --config name two places — a line names one');
219
+ }
220
+ if (said.config) return {
221
+ config: said.config,
222
+ host: dflt
223
+ };
224
+ let door = said.host ?? env('YAKS_HOST');
225
+ if (door) return {
226
+ host: door
227
+ };
228
+ let path = configPath(undefined, env);
229
+ return path ? {
230
+ config: path,
231
+ host: dflt,
232
+ onward: true
233
+ } : {
234
+ host: dflt,
235
+ unplaced: true
236
+ };
237
+ };
238
+ /** Claude Code keeps its session beside the process that starts an MCP
239
+ * client. Reading that parent's record preserves identity over stdio. */ export let parentVia = (env = own, parent = system.ppid, read = files.readTextFileSync)=>{
240
+ let directory = env('CLAUDE_CONFIG_DIR') || (env('HOME') ? `${env('HOME')}/.claude` : undefined);
241
+ if (!directory) return;
242
+ try {
243
+ let session = JSON.parse(read(`${directory}/sessions/${parent}.json`));
244
+ return typeof session.sessionId == 'string' ? session.sessionId : undefined;
245
+ } catch {
246
+ return undefined;
247
+ }
248
+ };
249
+ /**
250
+ * The run this command line is part of, as the environment names it: a harness
251
+ * sets it, every shell and hook under that harness inherits it, and a write
252
+ * made from any of them carries the transcript that produced it without
253
+ * anybody passing a flag. It is sent in the `x-via` header, which the server
254
+ * resolves to the session, and what the command writes is signed with it
255
+ * (@yaks/session/graph). A graph this process opened itself is asked the
256
+ * same way, through the same door (local.ts).
257
+ *
258
+ * The variable names are the harnesses' own. Claude Code hands a subagent its
259
+ * parent's session id and marks the shell as an agent's (`AI_AGENT=…_agent`),
260
+ * so the one place a subagent's own id shows is the worktree Claude Code made
261
+ * for it, `.claude/worktrees/agent-<id>`: a command a subagent runs there
262
+ * speaks for that subagent, whose session the harness's `SubagentStart` hook
263
+ * wrote (@yaks/session `session_context`). A subagent working in its parent's
264
+ * directory is told apart by nothing in its environment, and speaks for the
265
+ * parent.
266
+ */ export let via = (env = own, cwd = here(), parent = ()=>parentVia(env))=>{
267
+ let claude = env('CLAUDE_CODE_SESSION_ID');
268
+ let agent = claude && env('AI_AGENT')?.endsWith('_agent') ? cwd.match(WORKTREE)?.[1] : undefined;
269
+ return agent ?? claude ?? env('TASKS_SESSION') ?? env('CODEX_THREAD_ID') ?? parent();
270
+ };
271
+ // The worktree Claude Code makes for a subagent, named by the subagent's id.
272
+ let WORKTREE = /\/\.claude\/worktrees\/agent-([0-9a-f]+)(?:\/|$)/;
273
+ // This process's directory, or none where it was removed under it.
274
+ let here = ()=>{
275
+ try {
276
+ return system.cwd();
277
+ } catch {
278
+ return '';
279
+ }
280
+ };
281
+ let disk = {
282
+ cwd: system.cwd,
283
+ file: (path)=>files.readTextFile(path),
284
+ stdin: ()=>new Response(system.stdin.readable).text()
285
+ };
286
+ /**
287
+ * Run one command line. Returns the exit code a script reads: 0 succeeded, 1
288
+ * the tool or the server refused, 2 the command line was wrong.
289
+ */ export let cli = async (tools, opts = {})=>{
290
+ let out = opts.out ?? ((line)=>console.log(safe(line)));
291
+ let note = opts.note ?? ((line)=>console.error(safe(line)));
292
+ let env = opts.env ?? own;
293
+ let said = globals(opts.argv ?? system.args, env);
294
+ let { duties, json, tui, help, timing, rest, as } = said;
295
+ // Like the usage page, the version needs no graph, no network and nobody
296
+ // signed in.
297
+ if (said.version && opts.version) {
298
+ out(opts.version);
299
+ return 0;
300
+ }
301
+ // Where nothing placed this line, the host's refusal is not the answer: the
302
+ // program's own word for a machine with no graph is.
303
+ let lost = (why)=>why;
304
+ try {
305
+ // Where this command runs: a file it opens, or an MCP server it calls. A
306
+ // command line naming both is refused here, like any other that means two
307
+ // things.
308
+ let { config, host, onward, unplaced } = aimed(said, opts.host ?? 'yaks.app', env);
309
+ lost = (why)=>unplaced && opts.nowhere ? opts.nowhere : why;
310
+ let state = stateDir(env);
311
+ // A list that cannot be fetched is a reason printed on the page, not a
312
+ // page nobody gets: `yak` with no argument is what a person types when
313
+ // nothing works.
314
+ let extra;
315
+ let why;
316
+ let asked = false;
317
+ let fetched = async (fresh = false)=>{
318
+ if (!opts.more || extra && (!fresh || asked)) return extra ?? [];
319
+ asked ||= fresh;
320
+ try {
321
+ extra = [
322
+ ...await opts.more(c, {
323
+ fresh
324
+ })
325
+ ];
326
+ why = undefined;
327
+ } catch (e) {
328
+ extra = [];
329
+ why = e.message;
330
+ }
331
+ return extra;
332
+ };
333
+ let speaks = opts.via ?? via(env);
334
+ let c = {
335
+ host,
336
+ config,
337
+ as,
338
+ duties,
339
+ json,
340
+ tui,
341
+ // Only this process's own stdout can be a terminal: a caller that hands
342
+ // in `out` reads text.
343
+ tty: opts.out ? undefined : terminal(env),
344
+ help,
345
+ via: speaks,
346
+ state,
347
+ ask: opts.ask ?? rpc({
348
+ url: doorUrl(host),
349
+ token: ()=>tokenFor(host, state, {
350
+ config,
351
+ as,
352
+ env,
353
+ agent: !!speaks
354
+ }),
355
+ via: speaks,
356
+ fetch: timing ? timed(note) : undefined
357
+ }),
358
+ reads: opts.reads ?? disk,
359
+ out,
360
+ note,
361
+ all: async ()=>[
362
+ ...tools,
363
+ ...await fetched()
364
+ ],
365
+ page: async ()=>usage((await c.all()).filter((t)=>t.offered?.(c) ?? true), opts) + (why ? `\n\n (${lost(why)})` : '')
366
+ };
367
+ // The one thing that must work with no network and nobody signed in.
368
+ if (!rest.length) {
369
+ out(await c.page());
370
+ return 0;
371
+ }
372
+ // A stray is asked of the host, so a line that named a graph of its own
373
+ // has none: it names that graph, and a word the graph lacks is a word
374
+ // the graph lacks, not an app somewhere else. A graph the line did not
375
+ // name was only first in the order (`aimed`), so a word it lacks is
376
+ // asked of the host, exactly as a line aimed there would ask it.
377
+ let far = {
378
+ ...c,
379
+ config: undefined
380
+ };
381
+ let at = c;
382
+ // A held list is trusted for what it holds, never for what it lacks: a
383
+ // word it lacks is asked of its source again at once, and a line the
384
+ // schema it holds refuses (an argument added since) is read against the
385
+ // source's list once more before it is refused (`again`).
386
+ let lookup = async (list)=>{
387
+ let held = await list(false);
388
+ let found = commandFor(held, rest);
389
+ if (found) {
390
+ let again = async ()=>commandFor(await list(true), rest);
391
+ return {
392
+ found,
393
+ list: held,
394
+ again
395
+ };
396
+ }
397
+ let now = await list(true);
398
+ return {
399
+ found: commandFor(now, rest),
400
+ list: now,
401
+ again: undefined
402
+ };
403
+ };
404
+ let found = commandFor(tools, rest);
405
+ let again;
406
+ if (!found) ({ found, again } = await lookup(fetched));
407
+ let page = !found ? nounUsage(await c.all(), rest[0], opts.globalFlags) : undefined;
408
+ if (!found && !page) {
409
+ // A host whose list never came is the answer: past this point a line
410
+ // it would have understood reads as an app's stray, and its words as
411
+ // that app's arguments.
412
+ if (why) throw new Error(lost(why));
413
+ let stray = config ? undefined : await opts.stray?.(rest[0], rest.slice(1), c);
414
+ if (stray) found = {
415
+ verb: stray,
416
+ args: rest.slice(1)
417
+ };
418
+ else if (onward && opts.more) {
419
+ let more = opts.more;
420
+ let theirs;
421
+ try {
422
+ // The host's list is a cache too.
423
+ theirs = await lookup(async (fresh)=>[
424
+ ...await more(far, {
425
+ fresh
426
+ })
427
+ ]);
428
+ } catch (e) {
429
+ // Most often a typo, and the host only a second place to look: say
430
+ // where the commands are listed, then what asking the host needs.
431
+ throw new Error(`${config} has nothing called ${rest[0]} (\`yak help\` lists ` + `what it has), and ${host} could not be asked: ` + (e instanceof Unauthorized ? `sign in to it with \`yak auth ${host}\`` : e.message));
432
+ }
433
+ ;
434
+ ({ found, again } = theirs);
435
+ page = !found ? nounUsage([
436
+ ...tools,
437
+ ...theirs.list
438
+ ], rest[0], opts.globalFlags) : undefined;
439
+ if (!found && !page) {
440
+ let stray = await opts.stray?.(rest[0], rest.slice(1), far);
441
+ if (stray) found = {
442
+ verb: stray,
443
+ args: rest.slice(1)
444
+ };
445
+ }
446
+ if (found) at = far;
447
+ }
448
+ }
449
+ if (!found) {
450
+ // A noun on its own is a question, not a mistake: `yak graph` (and
451
+ // `yak graph --help`, which is the same command line with the flag
452
+ // lifted off) asks what that word can do, and the answer is its verbs.
453
+ if (page) {
454
+ if (rest.length > 1) {
455
+ throw new Usage(`Unknown command: ${rest[1]}\n\n${page}`);
456
+ }
457
+ out(page);
458
+ return 0;
459
+ }
460
+ let where = onward && opts.more ? `neither ${config} nor ${host} has anything` : `${config ?? host} has nothing`;
461
+ throw new Usage(`${where} called ${rest[0]} — try \`${opts.name ?? 'yak'} help\``);
462
+ }
463
+ if (help) {
464
+ out(helpFor(found.verb, opts));
465
+ return 0;
466
+ }
467
+ try {
468
+ let given = await argsFor(found.verb, found.args, c.reads).catch(async (e)=>{
469
+ let now = e instanceof Usage && await again?.();
470
+ if (!now) throw e;
471
+ found = now;
472
+ return await argsFor(now.verb, now.args, c.reads);
473
+ });
474
+ return await found.verb.run({
475
+ ...given,
476
+ ...Object.fromEntries((found.verb.globals ?? []).flatMap((name)=>said[name] === undefined ? [] : [
477
+ [
478
+ name,
479
+ said[name]
480
+ ]
481
+ ]))
482
+ }, at);
483
+ } catch (e) {
484
+ if (!(e instanceof Usage)) throw e;
485
+ note(`${opts.name ?? 'yak'}: ${e.message}\n\n${helpFor(found.verb, opts)}`);
486
+ return 2;
487
+ }
488
+ } catch (e) {
489
+ let message = e.message;
490
+ note(`${opts.name ?? 'yak'}: ${e instanceof Unauthorized ? lost(message) : message}`);
491
+ return e instanceof Usage ? 2 : 1;
492
+ }
493
+ };
494
+ /** The `help` command every program here carries: the whole usage page, or
495
+ * one subcommand's own. */ export let helpTool = (opts = {})=>({
496
+ name: 'help',
497
+ description: 'every command, one line each — or one command’s own page',
498
+ inputSchema: {
499
+ type: 'object',
500
+ additionalProperties: false,
501
+ properties: {
502
+ words: {
503
+ type: 'array',
504
+ items: {
505
+ type: 'string'
506
+ }
507
+ }
508
+ }
509
+ },
510
+ positional: [
511
+ 'words...'
512
+ ],
513
+ readOnly: true,
514
+ run: async (args, c)=>{
515
+ let words = args.words ?? [];
516
+ if (!words.length) {
517
+ c.out(await c.page());
518
+ return 0;
519
+ }
520
+ let found = commandFor(await c.all(), words);
521
+ if (found) {
522
+ c.out(helpFor(found.verb, opts));
523
+ return 0;
524
+ }
525
+ // `yak help graph` is the same question `yak graph` asks: the verbs that
526
+ // word holds.
527
+ let page = nounUsage(await c.all(), words[0], opts.globalFlags);
528
+ if (!page) throw new Usage(`nothing here is called ${words[0]}`);
529
+ c.out(page);
530
+ return 0;
531
+ }
532
+ });
533
+ //# sourceMappingURL=run.js.map
package/run.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run.js","sources":["./run.ts"],"names":[],"mappings":"AAAA,YAAY,wCAA6C;AACzD,YAAY,gCAAqC;AA8BjD,SAAS,OAAO,EAAE,UAAU,EAA4B,KAAK,oBAAmB;AAChF,SAAS,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,oBAAmB;AAC1D,SAAS,SAAS,EAAE,OAAO,oBAAmB;AAC9C,SAAS,KAAK,gCAAqC;AACnD,SAAS,OAAO,EAAY,GAAG,EAAE,YAAY,mBAAkB;AAC/D,SAAS,UAAU,sBAAqB;AAExC,SAAmB,QAAQ,EAAE,QAAQ,qBAAoB;AAEzD,sEAAsE;AACtE,IAAI,MAAW,CAAC,OAAS,OAAO,GAAG,CAAC,GAAG,CAAC;AA8CxC,2EAA2E;AAC3E,2EAA2E;AAC3E,6CAA6C;AAC7C,IAAI,WAAW,CAAC,MACd,OAAO,MAAM,CAAC,UAAU,MAAM,CAAC,IAAI,cAC/B;IACA,SAAS,OAAO,WAAW,GAAG,OAAO,IAAI;IACzC,OAAO,CAAC,IAAM,QAAQ,GAAG,CAAC;EAC5B,IACE;AAgFN;;;;;;;;;CASC,GACD,OAAO,IAAI,SAAS,CAAmB;EACrC,IAAI,OAAO,IAAI;EACf,KAAK,IAAI,KAAK,MAAO;IACnB,IAAI,QAAQ,EAAE,IAAI,IAAI,EAAE,IAAI,GACxB;MAAC,GAAG,EAAE,IAAI,CAAC,CAAC,EAAE,EAAE,IAAI,EAAE;MAAE,GAAG,EAAE,IAAI,CAAC,CAAC,EAAE,EAAE,IAAI,EAAE;KAAC,GAC9C;MAAC,UAAU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