@krapht/ork 1.0.0-alpha.2 → 1.0.0-alpha.21

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 (75) hide show
  1. package/README.md +12 -7
  2. package/dist/__build_info__-0wqQ-rtf.mjs +180 -0
  3. package/dist/apply-Mb0fNpCX.mjs +17 -0
  4. package/dist/argument-error-CihH46Le.mjs +27 -0
  5. package/dist/attach-C0-YyNoY.mjs +92 -0
  6. package/dist/attach-CAKNqnUK.mjs +1259 -0
  7. package/dist/bin.mjs +1885 -1609
  8. package/dist/brief-C2hew8cS.mjs +116 -0
  9. package/dist/{decide-CGyx9rv7.mjs → builtin-files-YYAnbZGD.mjs} +3 -51
  10. package/dist/chips-CP_pgKlj.mjs +48 -0
  11. package/dist/command-tree-CEkzWNy6.mjs +63 -0
  12. package/dist/{completion-CSU5vkEt.mjs → completion-K4rAVsrf.mjs} +200 -30
  13. package/dist/context-B-fjPJky.mjs +106 -0
  14. package/dist/context-DMK0U1w0.mjs +160 -0
  15. package/dist/detached-q0AYG0Bs.mjs +39 -0
  16. package/dist/extra-arguments-BxQMXARO.mjs +13 -0
  17. package/dist/{find-D6Gj1sxg.mjs → find-Ct5CNl1J.mjs} +2 -2
  18. package/dist/flags-C90N4J1i.mjs +145 -0
  19. package/dist/follow-ups-D3HPyNYM.mjs +568 -0
  20. package/dist/format-CiPhQqbX.mjs +260 -0
  21. package/dist/{help-groups-BwYoAWsh.mjs → help-groups-BQvcKQ9H.mjs} +49 -78
  22. package/dist/in-a-run-D_wg4iJi.mjs +27 -0
  23. package/dist/install-Hji6LIei.mjs +259 -0
  24. package/dist/{limits-B1-DYc3d.mjs → limits-BD6RZRCS.mjs} +2 -2
  25. package/dist/{mcp-DE_EmyVm.mjs → mcp-CpbDmBLG.mjs} +6 -6
  26. package/dist/once-J8Qn5fTG.mjs +112 -0
  27. package/dist/orphan-guard-BFKg8VSd.mjs +58 -0
  28. package/dist/output-DXZbnFt_.mjs +458 -0
  29. package/dist/outputs-text-CNTJ7Qq_.mjs +19 -0
  30. package/dist/{pause-CL6N_Xrj.mjs → pause-Cl4ZYA35.mjs} +7 -4
  31. package/dist/print-DzugGZQB.mjs +19 -0
  32. package/dist/project-records-CtkmlsHN.mjs +233 -0
  33. package/dist/refusals-DQQX3AIb.mjs +116 -0
  34. package/dist/{relay-0SD0erwf.mjs → relay-CiP77vga.mjs} +2 -2
  35. package/dist/run-CtuNY3mE.mjs +234 -0
  36. package/dist/send-DRYGks8K.mjs +104 -0
  37. package/dist/short-flags-DkJLWVqh.mjs +1 -0
  38. package/dist/short-flags-Qf21as0E.mjs +83 -0
  39. package/dist/src-BMFQKHz4.mjs +3122 -0
  40. package/dist/{src-BbyEoMn4.mjs → src-BrFfDKux.mjs} +800 -235
  41. package/dist/{src-Dujmvv4s.mjs → src-BuF9Lbow.mjs} +12580 -5505
  42. package/dist/{src-DOcK8Jfp.mjs → src-k0A_QpST.mjs} +1024 -590
  43. package/dist/store-rTgRu8xy.mjs +25 -0
  44. package/dist/ui/THIRD_PARTY_LICENSES.txt +612 -0
  45. package/dist/ui/assets/app-BYxpKJRh.css +1 -0
  46. package/dist/ui/assets/app-SEFEJLkF.js +112 -0
  47. package/dist/ui/assets/{index-9dFha9Qn.js → index-Cb6Voq_W.js} +3 -3
  48. package/dist/ui/assets/theme-CdXvqTQ6.js +1 -0
  49. package/dist/ui/index.html +2 -2
  50. package/dist/{ui-CTmO2Xzu.mjs → ui-C2f37TSb.mjs} +57 -25
  51. package/dist/usage-BuvGcQSk.mjs +256 -0
  52. package/dist/validate-ObP5lt29.mjs +1 -0
  53. package/dist/validate-_HjACtk9.mjs +632 -0
  54. package/dist/verdict-B592j1W3.mjs +84 -0
  55. package/dist/{watch-CtbgDAcz.mjs → watch-DV3ixCYj.mjs} +45 -17
  56. package/dist/{workflows-D1_WVukk.mjs → workflows-QLjBhGNS.mjs} +30 -5
  57. package/dist/worktrees-D3ubG_Qw.mjs +302 -0
  58. package/dist/yolo-BSH1E_kE.mjs +33 -0
  59. package/package.json +10 -8
  60. package/dist/__build_info__-fy6L1Mrd.mjs +0 -615
  61. package/dist/clean-DaHjs__2.mjs +0 -88
  62. package/dist/context-DT8MfEIR.mjs +0 -274
  63. package/dist/format-Dnfv8zMT.mjs +0 -427
  64. package/dist/in-a-run-pLAZeNys.mjs +0 -22
  65. package/dist/list-BrH8KRSJ.mjs +0 -110
  66. package/dist/output-BLQWD6MJ.mjs +0 -950
  67. package/dist/remove-BeGdqroy.mjs +0 -194
  68. package/dist/report-DK4LGqwF.mjs +0 -129
  69. package/dist/send-C8tunWhv.mjs +0 -163
  70. package/dist/src-CCUKRX51.mjs +0 -1204
  71. package/dist/ui/assets/app-BNT0SuIz.css +0 -1
  72. package/dist/ui/assets/app-T7wVAhgx.js +0 -67
  73. package/dist/ui/assets/theme-3xH5jxKs.js +0 -1
  74. package/dist/usage-DYUmP0i4.mjs +0 -419
  75. package/dist/worktrees-DdMYoNOC.mjs +0 -212
@@ -0,0 +1,458 @@
1
+ import { stripVTControlCharacters, styleText } from "node:util";
2
+ import { createInterface } from "node:readline/promises";
3
+ // src/term/theme.ts
4
+ /**
5
+ * @file The terminal kit's one theme: a role says what a piece of text means
6
+ * (accent, ok, warn, danger, muted), and the theme gives it a look that reads
7
+ * on dark and light terminals: the 16 ANSI colors only, and a fixed
8
+ * foreground on every chip background. Nothing is said by color alone: a chip
9
+ * carries words and a mark a symbol. In plain mode every call returns the
10
+ * text unstyled.
11
+ */
12
+ /** The text look of each role. */
13
+ const TEXT = {
14
+ accent: "cyan",
15
+ ok: "green",
16
+ warn: "yellow",
17
+ danger: "red",
18
+ muted: "dim"
19
+ };
20
+ /** The chip look of each role: a background and the foreground fixed on it. */
21
+ const CHIP = {
22
+ accent: ["bgCyan", "black"],
23
+ ok: ["bgGreen", "black"],
24
+ warn: ["bgYellow", "black"],
25
+ danger: ["bgRed", "whiteBright"],
26
+ muted: ["bgWhite", "black"]
27
+ };
28
+ /** The backgrounds a node chip takes, by a hash of its id. */
29
+ const NODE_PALETTE = [
30
+ ["bgCyan", "black"],
31
+ ["bgGreen", "black"],
32
+ ["bgYellow", "black"],
33
+ ["bgMagenta", "whiteBright"],
34
+ ["bgBlue", "whiteBright"],
35
+ ["bgWhite", "black"]
36
+ ];
37
+ /** `text` in `format` when the terminal is rich, else as is. */
38
+ const apply = (term, format, text) => term.rich ? styleText(format, text, { validateStream: false }) : text;
39
+ /** `text` in a role's color. */
40
+ const paint = (term, role, text) => apply(term, TEXT[role], text);
41
+ /** `text` in bold. */
42
+ const bold = (term, text) => apply(term, "bold", text);
43
+ /** Where a line's text starts, after its leading color codes (`ESC[…m`). */
44
+ const textStart = (line) => {
45
+ let at = 0;
46
+ while (line.startsWith("\x1B[", at)) {
47
+ const end = line.indexOf("m", at);
48
+ if (end === -1) return at;
49
+ at = end + 1;
50
+ }
51
+ return at;
52
+ };
53
+ /** `lines` with the bar in their first column, on a rich terminal. */
54
+ const barred = (t, lines) => {
55
+ if (!t.rich) return [...lines];
56
+ const bar = apply(t, "greenBright", "▌");
57
+ return lines.map((line) => {
58
+ const at = textStart(line);
59
+ return line[at] === " " ? `${bar}${line.slice(0, at)}${line.slice(at + 1)}` : line;
60
+ });
61
+ };
62
+ // src/term/keys.ts
63
+ /** What a `ESC [ …` or `ESC O …` sequence names. */
64
+ const SEQUENCES = {
65
+ "[A": "up",
66
+ "[B": "down",
67
+ "[C": "right",
68
+ "[D": "left",
69
+ "[H": "home",
70
+ "[F": "end",
71
+ "[1~": "home",
72
+ "[4~": "end",
73
+ "[7~": "home",
74
+ "[8~": "end",
75
+ "[3~": "delete",
76
+ OA: "up",
77
+ OB: "down",
78
+ OC: "right",
79
+ OD: "left",
80
+ OH: "home",
81
+ OF: "end"
82
+ };
83
+ const CONTROLS = {
84
+ "\r": "enter",
85
+ "\n": "enter",
86
+ "": "backspace",
87
+ "\b": "backspace",
88
+ "": "ctrl-c",
89
+ "": "ctrl-d",
90
+ "": "ctrl-a",
91
+ "": "ctrl-e",
92
+ "": "ctrl-u"
93
+ };
94
+ /** The keys in one chunk of input; what it does not know it skips. */
95
+ const parseKeys = (chunk) => {
96
+ const keys = [];
97
+ const chars = Array.from(chunk);
98
+ for (let i = 0; i < chars.length; i += 1) {
99
+ const char = chars[i] ?? "";
100
+ if (char === "\x1B") {
101
+ if (i === chars.length - 1) {
102
+ keys.push({ name: "escape" });
103
+ continue;
104
+ }
105
+ let end = i + (chars[i + 1] === "O" ? 3 : 2);
106
+ while (chars[i + 1] === "[" && end < chars.length + 1 && !/[A-Za-z~]/u.test(chars[end - 1] ?? "")) end += 1;
107
+ const name = SEQUENCES[chars.slice(i + 1, end).join("")];
108
+ if (name !== void 0) keys.push({ name });
109
+ i = end - 1;
110
+ continue;
111
+ }
112
+ const name = CONTROLS[char];
113
+ if (name !== void 0) keys.push({ name });
114
+ else if (char >= " ") keys.push({
115
+ name: "char",
116
+ text: char
117
+ });
118
+ }
119
+ return keys;
120
+ };
121
+ /**
122
+ * Reads keys from `input` in raw mode, calling `onKey` for each, until the
123
+ * returned function is called, which restores the mode and pauses the input.
124
+ */
125
+ const readKeys = (input, onKey) => {
126
+ const wasRaw = input.isRaw === true;
127
+ input.setRawMode?.(true);
128
+ input.resume();
129
+ const onData = (chunk) => {
130
+ for (const key of parseKeys(String(chunk))) onKey(key);
131
+ };
132
+ input.on("data", onData);
133
+ return () => {
134
+ input.off("data", onData);
135
+ input.setRawMode?.(wasRaw);
136
+ input.pause();
137
+ };
138
+ };
139
+ // src/term/layout.ts
140
+ /**
141
+ * @file Layout for plain text: its width, wrapped to a width, cut to one line
142
+ * with `…`, and hung under a lead. `wrap`, `cut` and `hang` take text before
143
+ * it is styled (they would cut inside an escape code), so style each piece
144
+ * after laying it out; `widthOf` and `rowsOf` ignore escape codes. Width
145
+ * counts one column per code point: wide characters (CJK, emoji) may overrun
146
+ * a line (specs/gaps.md).
147
+ */
148
+ /** The columns of `text`, escape codes not counted. */
149
+ const widthOf = (text) => Array.from(stripVTControlCharacters(text)).length;
150
+ /** `text` of one line within `width`, with `…` where it was cut. */
151
+ const cut = (text, width) => {
152
+ const chars = Array.from(text);
153
+ return chars.length <= width ? text : `${chars.slice(0, Math.max(0, width - 1)).join("")}…`;
154
+ };
155
+ /** A word that is over `width` is split into pieces of `width`. */
156
+ const pieces = (word, width) => {
157
+ const chars = Array.from(word);
158
+ const out = [];
159
+ for (let i = 0; i < chars.length; i += width) out.push(chars.slice(i, i + width).join(""));
160
+ return out;
161
+ };
162
+ /**
163
+ * `text` wrapped to lines of at most `width` columns, at spaces; each line
164
+ * break in `text` stays, and a blank line stays blank. A word longer than the
165
+ * width is split.
166
+ */
167
+ const wrap = (text, width) => text.split("\n").flatMap((paragraph) => {
168
+ const words = paragraph.split(/ +/u).filter((word) => word !== "");
169
+ const lines = [];
170
+ let line = "";
171
+ for (const word of words.flatMap((w) => pieces(w, width))) if (line === "") line = word;
172
+ else if (widthOf(line) + 1 + widthOf(word) <= width) line += ` ${word}`;
173
+ else {
174
+ lines.push(line);
175
+ line = word;
176
+ }
177
+ lines.push(line);
178
+ return lines;
179
+ });
180
+ /**
181
+ * `text` wrapped under `lead`: the first line starts with `lead`, the others
182
+ * with spaces as wide as `lead` (a hanging indent), all within `width`.
183
+ */
184
+ const hang = (lead, text, width) => {
185
+ const indent = " ".repeat(widthOf(lead));
186
+ return wrap(text, Math.max(1, width - indent.length)).map((line, index) => (index === 0 ? lead : indent).concat(line));
187
+ };
188
+ /** How many terminal rows `line` takes at `width` (at least one). */
189
+ const rowsOf = (line, width) => Math.max(1, Math.ceil(widthOf(line) / width));
190
+ const DEFAULT_WIDTH = 80;
191
+ const DEFAULT_ROWS = 24;
192
+ /** Whether `ORK_PLAIN` is on: set, and not `0` or `false`. */
193
+ const orkPlain = (value) => value !== void 0 && ![
194
+ "",
195
+ "0",
196
+ "false"
197
+ ].includes(value.toLowerCase());
198
+ /** Whether the environment asks for plain output (not the stream). */
199
+ const plainEnv = (env = process.env) => (env["NO_COLOR"] ?? "") !== "" || orkPlain(env["ORK_PLAIN"]) || env["TERM"] === "dumb";
200
+ /** How to write to `stream`, given `env`. */
201
+ const termOf = (stream, env = process.env) => ({
202
+ rich: stream.isTTY === true && !plainEnv(env),
203
+ width: Math.max(20, stream.columns ?? DEFAULT_WIDTH),
204
+ rows: stream.rows ?? DEFAULT_ROWS
205
+ });
206
+ /** Whether a prompt can take keys and redraw: rich output, a raw-mode input. */
207
+ const canKey = (input, output, env = process.env) => termOf(output, env).rich && input.isTTY === true && typeof input.setRawMode === "function";
208
+ /**
209
+ * Takes the global `--plain` flag out of `argv` (up to a `--`, after which
210
+ * words belong to a program). It sets `ORK_PLAIN=1` in `env`, which every child
211
+ * Ork starts then inherits.
212
+ */
213
+ const takePlainFlag = (argv, env = process.env) => {
214
+ const end = argv.indexOf("--");
215
+ const head = end === -1 ? argv : argv.slice(0, end);
216
+ if (!head.includes("--plain")) return [...argv];
217
+ env["ORK_PLAIN"] = "1";
218
+ return [...head.filter((word) => word !== "--plain"), ...argv.slice(head.length)];
219
+ };
220
+ // src/term/line.ts
221
+ /**
222
+ * @file The plain way to ask: one prompt, one line read. It is what every kit
223
+ * prompt falls back to (not a terminal, `NO_COLOR`, `--plain`), so scripts
224
+ * and tests that feed lines keep working, and what a screen reader sees.
225
+ */
226
+ /**
227
+ * Prints `prompt` and reads one line; `undefined` when the input ends first
228
+ * (Ctrl-D, a closed pipe). An aborted `signal` rejects.
229
+ */
230
+ const readLine = async (io, prompt, signal) => {
231
+ if (io.readLine !== void 0) return io.readLine(prompt, signal);
232
+ const rl = createInterface({
233
+ input: io.input,
234
+ output: io.output,
235
+ ...plainEnv(io.env) ? { terminal: false } : {}
236
+ });
237
+ const { promise: ended, resolve: end } = Promise.withResolvers();
238
+ rl.once("close", () => {
239
+ end();
240
+ });
241
+ try {
242
+ const answer = await Promise.race([signal === void 0 ? rl.question(prompt) : rl.question(prompt, { signal }), ended]);
243
+ return typeof answer === "string" ? answer : void 0;
244
+ } finally {
245
+ rl.close();
246
+ }
247
+ };
248
+ /** Ends a rich prompt on Ctrl-C: the caller's hook, else `SIGINT`. */
249
+ const interrupt = (io) => {
250
+ if (io.interrupt === void 0) process.kill(process.pid, "SIGINT");
251
+ else io.interrupt();
252
+ };
253
+ /** The error a withdrawn prompt rejects with: the signal's own, if it is one. */
254
+ const withdrawn = (signal) => signal?.reason instanceof Error ? signal.reason : /* @__PURE__ */ new Error("the prompt was withdrawn");
255
+ // src/term/screen.ts
256
+ /**
257
+ * @file A redrawn region of the terminal: a prompt draws its lines, and draws
258
+ * them again, moving the cursor up over its own lines and clearing down,
259
+ * never the screen. When it is done it leaves one line (or none). The cursor
260
+ * is hidden while a region is open unless a prompt places it, and is always
261
+ * restored by {@link Region.finish}. While a region is open, a line another
262
+ * part of the program prints (a run's transcript, from parallel nodes) goes
263
+ * through {@link printAbove}, which erases the region, prints the line and
264
+ * draws the region again, so the rows the region counts stay true.
265
+ */
266
+ const UP = (n) => n > 0 ? `\u001B[${String(n)}A` : "";
267
+ const CLEAR_DOWN = "\r\x1B[J";
268
+ const HIDE = "\x1B[?25l";
269
+ const SHOW = "\x1B[?25h";
270
+ /** The regions drawn now, the newest last. */
271
+ const open = /* @__PURE__ */ new Set();
272
+ /**
273
+ * Prints `text` above the open region, if one is drawn: `true`, and the caller
274
+ * writes nothing. `false` when no region is open, and the caller writes as
275
+ * usual.
276
+ */
277
+ const printAbove = (text) => {
278
+ const region = [...open].at(-1);
279
+ if (region === void 0) return false;
280
+ region.above(text);
281
+ return true;
282
+ };
283
+ /** A region at the cursor of `out`; `term` gives the width, read live. */
284
+ const createRegion = (out, term) => {
285
+ /** Rows between the cursor and the region's first row. */
286
+ let up = 0;
287
+ let last = {
288
+ lines: [],
289
+ column: void 0
290
+ };
291
+ const erase = () => `${UP(up)}${CLEAR_DOWN}`;
292
+ const draw = (lines, column) => {
293
+ open.add(region);
294
+ const width = term().width;
295
+ last = {
296
+ lines,
297
+ column
298
+ };
299
+ const rows = lines.reduce((sum, line) => sum + rowsOf(line, width), 0);
300
+ const placed = column === void 0 ? HIDE : `${SHOW}\r${column > 0 ? `\u001B[${String(column)}C` : ""}`;
301
+ out.write(`${erase()}${lines.join("\n")}${placed}`);
302
+ up = Math.max(0, rows - 1);
303
+ };
304
+ const region = {
305
+ draw,
306
+ redraw: () => {
307
+ draw(last.lines, last.column);
308
+ },
309
+ above: (text) => {
310
+ out.write(`${erase()}${text}\n`);
311
+ up = 0;
312
+ draw(last.lines, last.column);
313
+ },
314
+ finish: (line) => {
315
+ out.write(`${erase()}${line === void 0 ? "" : `${line}\n`}${SHOW}`);
316
+ up = 0;
317
+ last = {
318
+ lines: [],
319
+ column: void 0
320
+ };
321
+ open.delete(region);
322
+ }
323
+ };
324
+ return region;
325
+ };
326
+ // src/term/confirm.ts
327
+ /**
328
+ * @file The yes-or-no prompt: on a terminal, `Yes` and `No` that ←/→ (or `h`
329
+ * `l`, Space) move between, `y` and `n` answer at once, Enter takes the one
330
+ * shown, and Esc is no; it collapses to one line. Plain mode asks `question
331
+ * [y/N] ` and reads a line: anything but yes is no (the default, for an empty
332
+ * line), and a closed input is no.
333
+ */
334
+ /**
335
+ * Asks a yes-or-no question; `null` on Ctrl-C, after the terminal was restored
336
+ * and the interrupt sent, for a caller that must not carry on as if it were
337
+ * no.
338
+ */
339
+ const confirmOrStop = async (io, options) => {
340
+ const { question, signal } = options;
341
+ const fallback = options.default === true;
342
+ if (signal?.aborted === true) throw withdrawn(signal);
343
+ if (!canKey(io.input, io.output, io.env)) {
344
+ const answer = (await readLine(io, ` ${question} ${fallback ? "[Y/n]" : "[y/N]"} `, signal) ?? "").trim().toLowerCase();
345
+ return answer === "" ? fallback : ["y", "yes"].includes(answer);
346
+ }
347
+ const term = () => termOf(io.output, io.env);
348
+ const region = createRegion(io.output, term);
349
+ return new Promise((resolve, reject) => {
350
+ let yes = fallback;
351
+ const render = () => {
352
+ const t = term();
353
+ const asked = hang(" ? ", question, t.width).map((line, i) => i === 0 ? ` ${paint(t, "accent", "?")} ${bold(t, line.slice(3))}` : line);
354
+ const pick = (label, on) => on ? apply(t, "inverse", ` ${label} `) : ` ${label} `;
355
+ const keys = paint(t, "muted", "y/n · ←/→ · Enter");
356
+ region.draw(barred(t, [...asked, ` ${pick("Yes", yes)} ${pick("No", !yes)} ${keys}`]));
357
+ };
358
+ const finish = (answer) => {
359
+ stop();
360
+ io.output.off("resize", render);
361
+ signal?.removeEventListener("abort", onAbort);
362
+ const t = term();
363
+ const mark = answer ? paint(t, "ok", "✓") : paint(t, "danger", "✗");
364
+ region.finish(cut(` ${mark} ${question} · ${answer ? "Yes" : "No"}`, t.width));
365
+ resolve(answer);
366
+ };
367
+ const onAbort = () => {
368
+ stop();
369
+ io.output.off("resize", render);
370
+ region.finish();
371
+ reject(withdrawn(signal));
372
+ };
373
+ const stop = readKeys(io.input, (key) => {
374
+ if (key.name === "enter") finish(yes);
375
+ else if (key.name === "escape") finish(false);
376
+ else if (key.name === "ctrl-c") {
377
+ stop();
378
+ io.output.off("resize", render);
379
+ signal?.removeEventListener("abort", onAbort);
380
+ region.finish();
381
+ resolve(null);
382
+ interrupt(io);
383
+ } else if (key.name === "left" || key.name === "right") {
384
+ yes = !yes;
385
+ render();
386
+ } else if (key.name === "char") {
387
+ const c = key.text.toLowerCase();
388
+ if (c === "y") finish(true);
389
+ else if (c === "n") finish(false);
390
+ else if (c === "h" || c === "l" || c === " ") {
391
+ yes = !yes;
392
+ render();
393
+ }
394
+ }
395
+ });
396
+ io.output.on("resize", render);
397
+ signal?.addEventListener("abort", onAbort, { once: true });
398
+ render();
399
+ });
400
+ };
401
+ /** Asks a yes-or-no question; Ctrl-C (after restoring the terminal) is no. */
402
+ const confirm$1 = async (io, options) => await confirmOrStop(io, options) === true;
403
+ // src/output.ts
404
+ /**
405
+ * @file Terminal output helpers: styled text that turns plain when stdout is
406
+ * not a TTY or `NO_COLOR` is set, and a yes-or-no question on the terminal
407
+ * (through the terminal kit).
408
+ */
409
+ /**
410
+ * Styles text for stdout; plain when stdout is not a TTY, `NO_COLOR` is set, or
411
+ * `--plain` (`ORK_PLAIN`) was given. The environment is read on each call:
412
+ * `--plain` is set after the modules load.
413
+ */
414
+ const style = (format, text) => plainEnv() ? text : styleText(format, text, { stream: process.stdout });
415
+ /**
416
+ * Text from outside, fit for a terminal: escape sequences could hide a line on
417
+ * the very screen a person judges from, and a line break could forge one.
418
+ */
419
+ const plain = (text) => stripVTControlCharacters(text).replaceAll(/[\p{Cc}\p{Bidi_Control}]/gu, " ");
420
+ /** A line to stdout; above a prompt that is open on the same terminal. */
421
+ const write = (text) => {
422
+ if (process.stdout.isTTY && printAbove(text)) return;
423
+ process.stdout.write(`${text}\n`);
424
+ };
425
+ const writeErr = (text) => {
426
+ if (process.stderr.isTTY && printAbove(text)) return;
427
+ process.stderr.write(`${text}\n`);
428
+ };
429
+ /** What to run to follow, steer or stop the detached run `id` (ADR-081). */
430
+ const detachHint = (id) => `ork attach ${id} · ork logs ${id} -f · ork tree ${id} · ork decide · ork stop ${id}`;
431
+ /** What a run spent: `$0.0312`, or `$0.00` for nothing. */
432
+ const cost = (usd) => usd === 0 ? "$0.00" : `$${usd.toFixed(4)}`;
433
+ /**
434
+ * A dollar total that misses sessions on a driver with no dollars (RFC-015),
435
+ * said so, with the counted tokens beside it: `$1.2000 (partial) · 3.0k
436
+ * tokens`. A complete total reads as `cost` does.
437
+ */
438
+ const costOf = (usd, partial, tokens) => {
439
+ if (partial !== true) return cost(usd);
440
+ const units = tokens === void 0 ? "" : ` · ${shortCount(tokens)} tokens`;
441
+ return `${cost(usd)} (partial)${units}`;
442
+ };
443
+ /** `950`, `12.3k`, `1.2M`. */
444
+ const shortCount = (n) => {
445
+ if (n < 1e3) return String(n);
446
+ if (n < 1e6) return `${(n / 1e3).toFixed(1)}k`;
447
+ return `${(n / 1e6).toFixed(1)}M`;
448
+ };
449
+ /**
450
+ * Asks a yes-or-no question on the terminal (stderr), through the kit's confirm
451
+ * prompt; anything but yes is no. A trailing `[y/N]` in `question` is dropped:
452
+ * the prompt adds its own.
453
+ */
454
+ const confirm = (question) => confirm$1({
455
+ input: process.stdin,
456
+ output: process.stderr
457
+ }, { question: question.replace(/\s*\[y\/N\]\s*$/u, "") });
458
+ export { readKeys as C, apply as D, NODE_PALETTE as E, bold as O, wrap as S, CHIP as T, takePlainFlag as _, plain as a, hang as b, write as c, createRegion as d, interrupt as f, plainEnv as g, canKey as h, detachHint as i, paint as k, writeErr as l, withdrawn as m, cost as n, shortCount as o, readLine as p, costOf as r, style as s, confirm as t, confirmOrStop as u, termOf as v, barred as w, widthOf as x, cut as y };
@@ -0,0 +1,19 @@
1
+ import { stripVTControlCharacters } from "node:util";
2
+ const OUTPUT_MAX_CHARS = 2e3;
3
+ /** Escapes stripped, other control characters (not line breaks, tabs) blanked. */
4
+ const scrub = (value) => stripVTControlCharacters(value).replaceAll(/[^\P{Cc}\n\t]|\p{Bidi_Control}/gu, " ");
5
+ /**
6
+ * The declared outputs in key order, each scrubbed and cut to
7
+ * {@link OUTPUT_MAX_LINES} lines and {@link OUTPUT_MAX_CHARS} characters; empty
8
+ * when there are none.
9
+ */
10
+ const outputsText = (outputs) => Object.entries(outputs ?? {}).map(([name, value]) => {
11
+ const clean = scrub(value.replaceAll("\r\n", "\n")).trimEnd();
12
+ const text = clean.split("\n").slice(0, 20).join("\n").slice(0, OUTPUT_MAX_CHARS);
13
+ return {
14
+ name,
15
+ text,
16
+ cut: text.length < clean.length
17
+ };
18
+ });
19
+ export { outputsText as t };
@@ -1,7 +1,8 @@
1
- import { G as requestContinue, K as requestPause } from "./src-Dujmvv4s.mjs";
2
- import { t as findRun } from "./find-D6Gj1sxg.mjs";
3
- import { a as write, c as openStore, i as style, o as writeErr } from "./output-BLQWD6MJ.mjs";
4
- import { r as continueRefusal } from "./in-a-run-pLAZeNys.mjs";
1
+ import { An as requestContinue, R as openStore, jn as requestPause } from "./src-BuF9Lbow.mjs";
2
+ import { t as findRun } from "./find-Ct5CNl1J.mjs";
3
+ import { c as write, l as writeErr, s as style } from "./output-DXZbnFt_.mjs";
4
+ import { i as continueRefusal } from "./in-a-run-D_wg4iJi.mjs";
5
+ import { t as refuseExtraArguments } from "./extra-arguments-BxQMXARO.mjs";
5
6
  import { defineCommand } from "citty";
6
7
  // src/commands/pause.ts
7
8
  /**
@@ -43,6 +44,7 @@ const pause = defineCommand({
43
44
  name: "pause",
44
45
  description: "Pause a live run, or one node, before its next tool call"
45
46
  },
47
+ plugins: [refuseExtraArguments],
46
48
  args,
47
49
  run: ({ args: given }) => ask(given.run, (store, run) => requestPause(store, run, void 0, given.node), (run) => given.node === void 0 ? `Run ${run.id} pauses: nothing new starts, and running sessions wait before their next tool call. Go on with: ork continue ${run.id}` : `${given.node} in run ${run.id} pauses before its next tool call. Go on with: ork continue ${run.id} --node ${given.node}`)
48
50
  });
@@ -51,6 +53,7 @@ const continueRun = defineCommand({
51
53
  name: "continue",
52
54
  description: "Let a paused run, or one paused node, go on"
53
55
  },
56
+ plugins: [refuseExtraArguments],
54
57
  args,
55
58
  run: async ({ args: given }) => {
56
59
  const refused = continueRefusal();
@@ -0,0 +1,19 @@
1
+ import { c as write } from "./output-DXZbnFt_.mjs";
2
+ import { a as refuseIdsWithJson } from "./flags-C90N4J1i.mjs";
3
+ // src/list/print.ts
4
+ /**
5
+ * Prints `rows`: `--ids` their ids (`table.id`) comma-separated; `--json` the
6
+ * rows (or `json(rows)`); else `human(rows)`, which also says what an empty
7
+ * list is. `--ids` with `--json` is refused (said, exit code set).
8
+ */
9
+ const printList = (rows, table, args, human, json = (shown) => shown) => {
10
+ if (refuseIdsWithJson(args)) return;
11
+ if (args.ids === true) {
12
+ const id = table.id;
13
+ if (id !== void 0 && rows.length > 0) write(rows.map((row) => id(row)).join(","));
14
+ return;
15
+ }
16
+ if (args.json === true) write(JSON.stringify(json(rows), void 0, 2));
17
+ else human(rows);
18
+ };
19
+ export { printList as t };