@kaynooo/cli-probe 0.4.1 → 0.4.5

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 (3) hide show
  1. package/README.md +3 -3
  2. package/dist/probe.js +459 -170
  3. package/package.json +5 -5
package/README.md CHANGED
@@ -22,9 +22,9 @@ bun add -g @kaynooo/cli-probe
22
22
 
23
23
  ## JSON output
24
24
 
25
- One target prints one object, `{target, url, version, status, chain, timings, addresses, tls, certificate, headers, cdn, offers, httpRedirect, warnings}`, unchanged by the other options (`--json` is always the full report). Several targets print an array of those in the order given, an unreachable one being `{target, error}`.
25
+ One target prints one object, `{target, url, version, status, chain, timings, addresses, tls, certificate, headers, cdn, offers, httpRedirect, failedHop, warnings}`, unchanged by the other options (`--json` is always the full report). Several targets print an array of those in the order given, an unreachable one being `{target, error}`.
26
26
 
27
- Redirects are followed hop by hop, at most 10. The HTTP version and timings come from `curl --write-out '%{json}'`, the certificate from `node:tls`, which Bun's fetch exposes neither of. HTTP/3 is spoken only when `curl --version` lists it, otherwise h3 is reported from `alt-svc` alone.
27
+ Redirects are followed hop by hop, at most 10; a redirect to a target that does not answer is kept as `failedHop`, `{url, error}`, with a warning. The HTTP version and timings come from `curl --write-out '%{json}'`, the certificate from `node:tls`, which Bun's fetch exposes neither of. HTTP/3 is spoken only when `curl --version` lists it, otherwise h3 is reported from `alt-svc` alone.
28
28
 
29
29
  Warnings: a certificate with fewer than 14 days left, expired or not trusted, an `http://` twin that does not redirect to https (checked for a bare domain or an https URL on the default port), more than 10 redirects, a site not served over https.
30
30
 
@@ -40,4 +40,4 @@ Warnings: the system resolver behind the zone (`sudo resolvectl flush-caches` dr
40
40
 
41
41
  `--cors <origin>` sends `OPTIONS` with `Origin`, `Access-Control-Request-Method` and `Access-Control-Request-Headers`, the way a browser does, then applies the Fetch standard's checks: a 2xx status, `access-control-allow-origin` being `*` or the origin, `access-control-allow-methods` listing a method other than GET, HEAD or POST (or `*`), `access-control-allow-headers` covering every header (`*` covers all but `authorization`). The method is uppercased when it is one of the six fetch normalizes (DELETE, GET, HEAD, OPTIONS, POST, PUT) and otherwise sent and matched as typed, `patch` needing `patch` listed. `accept`, `accept-language` and `content-language` are left out of the preflight, a browser letting them through unlisted. Warnings: credentials allowed alongside a `*`, which a credentialed request does not get, and the request's origin allowed without `vary: origin`. `--json` is `{target, url, status, request, allowed, reasons, warnings, headers}`. `-H`, `--resolve`, `-k` and `-t` apply to the preflight too.
42
42
 
43
- Exits 0 when every site answered, 1 when one could not be reached, a CORS preflight was refused or no resolver knows a name, 2 on a usage error (a bad URL, header, origin or `--resolve` is refused before any request is made).
43
+ Exits 0 when every site answered, 1 when one could not be reached or one of its redirects led nowhere, a CORS preflight was refused or no resolver knows a name, 2 on a usage error (a bad URL, header, origin or `--resolve` is refused before any request is made).
package/dist/probe.js CHANGED
@@ -1,21 +1,19 @@
1
1
  #!/usr/bin/env -S bun --no-env-file --config=/dev/null
2
2
  // @bun
3
+ var __esm = (fn, res, err) => () => {
4
+ if (fn)
5
+ try {
6
+ res = fn(fn = 0);
7
+ } catch (e) {
8
+ err = [e];
9
+ }
10
+ if (err)
11
+ throw err[0];
12
+ return res;
13
+ };
3
14
 
4
- // src/probe.ts
5
- import { isIP as isIP2 } from "net";
6
- import process15 from "process";
7
- // ../kit/src/args.ts
8
- import process9 from "process";
9
- import { parseArgs } from "util";
10
-
11
- // ../kit/src/format.ts
12
- import process7 from "process";
13
-
14
- // ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-rxztfxgv.js
15
- var N = new Map;
16
- var Nt = /\s+\S*$/;
17
- var Y = /\s/;
18
- function ko(t, e, r = "...") {
15
+ // ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-rkhsft4a.js
16
+ function Ao(t, e, r = "...") {
19
17
  let { suffix: n = "...", includeSuffix: s = false, wordBoundary: o = false } = typeof r === "string" ? { suffix: r } : r;
20
18
  if (t.length <= e)
21
19
  return t;
@@ -26,13 +24,22 @@ function ko(t, e, r = "...") {
26
24
  c = c.trimEnd();
27
25
  return s ? (c + n).slice(0, l) : c + n;
28
26
  }
29
- var be = new Map(["\u20AC", "", "\u201A", "\u0192", "\u201E", "\u2026", "\u2020", "\u2021", "\u02C6", "\u2030", "\u0160", "\u2039", "\u0152", "", "\u017D", "", "", "\u2018", "\u2019", "\u201C", "\u201D", "\u2022", "\u2013", "\u2014", "\u02DC", "\u2122", "\u0161", "\u203A", "\u0153", "", "\u017E", "\u0178"].map((t, e) => [t, 128 + e]).filter(([t]) => t));
30
- var z = new Map;
27
+ var N, Nt, Y, be, W;
28
+ var init_chunk_rkhsft4a = __esm(() => {
29
+ N = new Map;
30
+ Nt = /\s+\S*$/;
31
+ Y = /\s/;
32
+ be = new Map(["\u20AC", "", "\u201A", "\u0192", "\u201E", "\u2026", "\u2020", "\u2021", "\u02C6", "\u2030", "\u0160", "\u2039", "\u0152", "", "\u017D", "", "", "\u2018", "\u2019", "\u201C", "\u201D", "\u2022", "\u2013", "\u2014", "\u02DC", "\u2122", "\u0161", "\u203A", "\u0153", "", "\u017E", "\u0178"].map((t, e) => [t, 128 + e]).filter(([t]) => t));
33
+ W = new Map;
34
+ });
35
+
36
+ // ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/text.js
37
+ var init_text = __esm(() => {
38
+ init_chunk_rkhsft4a();
39
+ });
31
40
 
32
41
  // ../kit/src/mode.ts
33
42
  import process2 from "process";
34
- var MODES = new Set(["terminal", "ci", "agent", "pipe"]);
35
- var AGENT_VARIABLES = ["CLAUDECODE", "AI_AGENT"];
36
43
  function isSet(value) {
37
44
  return value !== undefined && value !== "" && value !== "0" && value.toLowerCase() !== "false";
38
45
  }
@@ -46,12 +53,13 @@ function outputMode(stream = process2.stdout, env = process2.env) {
46
53
  return "terminal";
47
54
  return isSet(env.CI) ? "ci" : "pipe";
48
55
  }
56
+ var MODES, AGENT_VARIABLES;
57
+ var init_mode = __esm(() => {
58
+ MODES = new Set(["terminal", "ci", "agent", "pipe"]);
59
+ AGENT_VARIABLES = ["CLAUDECODE", "AI_AGENT"];
60
+ });
49
61
 
50
- // ../kit/src/style.ts
51
- import process6 from "process";
52
-
53
- // ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-x450vn3m.js
54
- var G2 = /^[a-f0-9]+$/i;
62
+ // ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-x450vn3m.js
55
63
  function b(r) {
56
64
  let e = r.startsWith("#") ? r.slice(1) : r;
57
65
  if (!G2.test(e))
@@ -62,11 +70,6 @@ function b(r) {
62
70
  throw Error(`Invalid hex color length: ${e.length}`);
63
71
  return [Number.parseInt(e.slice(0, 2), 16), Number.parseInt(e.slice(2, 4), 16), Number.parseInt(e.slice(4, 6), 16)];
64
72
  }
65
- var B2 = { reset: [0, 0], bold: [1, 22], dim: [2, 22], italic: [3, 23], underline: [4, 24], inverse: [7, 27], hidden: [8, 28], strikethrough: [9, 29], black: [30, 39], red: [31, 39], green: [32, 39], yellow: [33, 39], blue: [34, 39], magenta: [35, 39], cyan: [36, 39], white: [37, 39], gray: [90, 39], grey: [90, 39], blackBright: [90, 39], redBright: [91, 39], greenBright: [92, 39], yellowBright: [93, 39], blueBright: [94, 39], magentaBright: [95, 39], cyanBright: [96, 39], whiteBright: [97, 39], bgBlack: [40, 49], bgRed: [41, 49], bgGreen: [42, 49], bgYellow: [43, 49], bgBlue: [44, 49], bgMagenta: [45, 49], bgCyan: [46, 49], bgWhite: [47, 49], bgBlackBright: [100, 49], bgRedBright: [101, 49], bgGreenBright: [102, 49], bgYellowBright: [103, 49], bgBlueBright: [104, 49], bgMagentaBright: [105, 49], bgCyanBright: [106, 49], bgWhiteBright: [107, 49], rgb: (r, e, l, n = "fg") => [`${n === "fg" ? 38 : 48};2;${r};${e};${l}`, n === "fg" ? 39 : 49], hex: (r, e = "fg") => {
66
- let [l, n, c] = b(r);
67
- return [`${e === "fg" ? 38 : 48};2;${l};${n};${c}`, e === "fg" ? 39 : 49];
68
- }, ansi256: (r, e = "fg") => [`${e === "fg" ? 38 : 48};5;${r}`, e === "fg" ? 39 : 49] };
69
- var h = new Set(["", "1", "2", "3", "true"]);
70
73
  function C(r, e = globalThis.process?.env ?? {}) {
71
74
  if (e.FORCE_COLOR !== undefined)
72
75
  return h.has(e.FORCE_COLOR);
@@ -80,7 +83,7 @@ function f(r, e = []) {
80
83
  l += `\x1B[${e[t][0]}m`, n = `\x1B[${e[t][1]}m${n}`;
81
84
  let c = (t) => C(r.stream ?? globalThis.process?.stdout, r.env) ? l + t + n : t, g = new Map;
82
85
  return new Proxy(c, { get(t, i) {
83
- let a = B2[i];
86
+ let a = B[i];
84
87
  if (Array.isArray(a)) {
85
88
  let s = g.get(i);
86
89
  if (s === undefined)
@@ -103,13 +106,21 @@ function f(r, e = []) {
103
106
  function Fe(r = {}) {
104
107
  return f(r);
105
108
  }
106
- var o = Fe();
109
+ var G2, B, h, o;
110
+ var init_chunk_x450vn3m = __esm(() => {
111
+ G2 = /^[a-f0-9]+$/i;
112
+ B = { reset: [0, 0], bold: [1, 22], dim: [2, 22], italic: [3, 23], underline: [4, 24], inverse: [7, 27], hidden: [8, 28], strikethrough: [9, 29], black: [30, 39], red: [31, 39], green: [32, 39], yellow: [33, 39], blue: [34, 39], magenta: [35, 39], cyan: [36, 39], white: [37, 39], gray: [90, 39], grey: [90, 39], blackBright: [90, 39], redBright: [91, 39], greenBright: [92, 39], yellowBright: [93, 39], blueBright: [94, 39], magentaBright: [95, 39], cyanBright: [96, 39], whiteBright: [97, 39], bgBlack: [40, 49], bgRed: [41, 49], bgGreen: [42, 49], bgYellow: [43, 49], bgBlue: [44, 49], bgMagenta: [45, 49], bgCyan: [46, 49], bgWhite: [47, 49], bgBlackBright: [100, 49], bgRedBright: [101, 49], bgGreenBright: [102, 49], bgYellowBright: [103, 49], bgBlueBright: [104, 49], bgMagentaBright: [105, 49], bgCyanBright: [106, 49], bgWhiteBright: [107, 49], rgb: (r, e, l, n = "fg") => [`${n === "fg" ? 38 : 48};2;${r};${e};${l}`, n === "fg" ? 39 : 49], hex: (r, e = "fg") => {
113
+ let [l, n, c] = b(r);
114
+ return [`${e === "fg" ? 38 : 48};2;${l};${n};${c}`, e === "fg" ? 39 : 49];
115
+ }, ansi256: (r, e = "fg") => [`${e === "fg" ? 38 : 48};5;${r}`, e === "fg" ? 39 : 49] };
116
+ h = new Set(["", "1", "2", "3", "true"]);
117
+ o = Fe();
118
+ });
107
119
 
108
- // ../kit/src/theme.ts
109
- import { existsSync as existsSync2, readFileSync, statSync } from "fs";
110
- import { homedir as homedir2 } from "os";
111
- import { join as join3, resolve as resolve2 } from "path";
112
- import process5 from "process";
120
+ // ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/tools/colors.js
121
+ var init_colors = __esm(() => {
122
+ init_chunk_x450vn3m();
123
+ });
113
124
 
114
125
  // ../kit/src/config.ts
115
126
  import { existsSync } from "fs";
@@ -125,48 +136,36 @@ function findUp(names, from = process3.cwd(), stop = () => false) {
125
136
  return;
126
137
  }
127
138
  }
139
+ var init_config = __esm(() => {
140
+ init_args();
141
+ });
128
142
 
129
143
  // ../kit/src/user-config.ts
130
144
  import { homedir } from "os";
131
- import { join as join2 } from "path";
145
+ import { isAbsolute, join as join2 } from "path";
132
146
  import process4 from "process";
147
+ function xdgFolder(value, fallback) {
148
+ return value !== undefined && isAbsolute(value) ? value : fallback;
149
+ }
133
150
  function configBase(where = {}) {
134
151
  const xdg = where.xdg ?? (where.home === undefined ? process4.env.XDG_CONFIG_HOME : undefined);
135
- return xdg !== undefined && xdg !== "" ? xdg : join2(where.home ?? homedir(), ".config");
152
+ return xdgFolder(xdg, join2(where.home ?? homedir(), ".config"));
136
153
  }
137
154
  function userConfigPath(bin, where = {}) {
138
155
  return join2(configBase(where), "kaynooo-cli", `${bin}.json`);
139
156
  }
157
+ var init_user_config = () => {};
140
158
 
141
159
  // ../kit/src/theme.ts
142
- var ENDS = new Map;
143
- var DEFAULT = {
144
- colors: { accent: "cyan", id: "yellow", path: "blue", label: "dim", value: "bold", ok: "green", warn: "yellow", problem: "red", note: "dim", plan: "magenta", passed: "green", failed: "red", running: "cyan", queued: "yellow", skipped: "dim" },
145
- glyphs: { ok: "\u2713", warn: "\u25B2", problem: "\u2717", note: "\u203A", plan: "\u25C7", passed: "\u2713", failed: "\u2717", running: "\u25CF", queued: "\u25CB", skipped: "-", bar: "\u2501", rule: "\u2500", corner: "\u256D", open: "\u2022", leaf: "\xB7", guide: "\u2502" },
146
- accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
147
- bins: {},
148
- gradient: ["#c084fc", "#67e8f9"]
149
- };
150
- var BRIGHT = { accent: "cyanBright", id: "yellowBright", path: "blueBright", label: "white", value: "bold whiteBright", ok: "greenBright", warn: "yellowBright", problem: "redBright", note: "white", plan: "magentaBright", passed: "greenBright", failed: "redBright", running: "cyanBright", queued: "yellowBright", skipped: "white" };
151
- var MONO = { accent: "bold", id: "bold", path: "underline", label: "dim", value: "bold", ok: "bold", warn: "bold", problem: "bold", note: "dim", plan: "dim", passed: "bold", failed: "bold", running: "bold", queued: "dim", skipped: "dim" };
152
- var ASCII = { ok: "+", warn: "!", problem: "x", note: ">", plan: "?", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+", open: "*", leaf: "-", guide: "|" };
153
- var PRESETS = {
154
- default: {},
155
- "high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"], gradient: ["#d8b4fe", "#a5f3fc"] },
156
- mono: { colors: MONO, accents: ["bold"], gradient: undefined },
157
- ascii: { glyphs: ASCII }
158
- };
159
- var STYLES = new Set(["bold", "dim", "italic", "underline", "inverse", "strikethrough", "black", "red", "green", "yellow", "blue", "magenta", "cyan", "white", "gray", "grey", "blackBright", "redBright", "greenBright", "yellowBright", "blueBright", "magentaBright", "cyanBright", "whiteBright"]);
160
- var HEX = /^#[0-9a-f]{6}$/i;
161
- var CONTROL = /\p{Cc}/u;
162
- var MAX_FILE_BYTES = 64 * 1024;
163
- var SPACES = /\s+/;
160
+ import { existsSync as existsSync2, readFileSync, statSync } from "fs";
161
+ import { homedir as homedir2 } from "os";
162
+ import { join as join3, resolve as resolve2 } from "path";
163
+ import process5 from "process";
164
164
  function isColorSpec(spec) {
165
165
  if (typeof spec === "number")
166
166
  return Number.isInteger(spec) && spec >= 0 && spec <= 255;
167
167
  return typeof spec === "string" && spec.trim() !== "" && spec.trim().split(SPACES).every((token) => STYLES.has(token) || HEX.test(token));
168
168
  }
169
- var CUBE = [0, 95, 135, 175, 215, 255];
170
169
  function cubeLevel(channel) {
171
170
  return CUBE.reduce((best, value, level) => Math.abs(value - channel) < Math.abs(CUBE[best] - channel) ? level : best, 0);
172
171
  }
@@ -271,7 +270,6 @@ function applyFile(theme, file, where, warn) {
271
270
  function endsWalk(home) {
272
271
  return (dir) => dir === resolve2(home) || existsSync2(join3(dir, ".git"));
273
272
  }
274
- var warned = new Set;
275
273
  function warnOnce(message) {
276
274
  if (warned.has(message))
277
275
  return;
@@ -308,8 +306,6 @@ function loadTheme({ env = process5.env, from = process5.cwd(), home = homedir2(
308
306
  }
309
307
  return { theme, sources, preset };
310
308
  }
311
- var current;
312
- var currentKey = "";
313
309
  function activeTheme() {
314
310
  const key = `${process5.cwd()}\x00${process5.env.KIT_THEME ?? ""}\x00${process5.env.XDG_CONFIG_HOME ?? ""}`;
315
311
  if (current === undefined || key !== currentKey) {
@@ -318,9 +314,38 @@ function activeTheme() {
318
314
  }
319
315
  return current;
320
316
  }
317
+ var ENDS, DEFAULT, BRIGHT, MONO, ASCII, PRESETS, STYLES, HEX, CONTROL, MAX_FILE_BYTES, SPACES, CUBE, warned, current, currentKey = "";
318
+ var init_theme = __esm(() => {
319
+ init_config();
320
+ init_user_config();
321
+ ENDS = new Map;
322
+ DEFAULT = {
323
+ colors: { accent: "cyan", id: "yellow", path: "blue", label: "dim", value: "bold", ok: "green", warn: "yellow", problem: "red", note: "dim", plan: "magenta", passed: "green", failed: "red", running: "cyan", queued: "yellow", skipped: "dim" },
324
+ glyphs: { ok: "\u2713", warn: "\u25B2", problem: "\u2717", note: "\u203A", plan: "\u25C7", passed: "\u2713", failed: "\u2717", running: "\u25CF", queued: "\u25CB", skipped: "-", bar: "\u2501", rule: "\u2500", corner: "\u256D", open: "\u2022", leaf: "\xB7", guide: "\u2502" },
325
+ accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
326
+ bins: {},
327
+ gradient: ["#c084fc", "#67e8f9"]
328
+ };
329
+ BRIGHT = { accent: "cyanBright", id: "yellowBright", path: "blueBright", label: "white", value: "bold whiteBright", ok: "greenBright", warn: "yellowBright", problem: "redBright", note: "white", plan: "magentaBright", passed: "greenBright", failed: "redBright", running: "cyanBright", queued: "yellowBright", skipped: "white" };
330
+ MONO = { accent: "bold", id: "bold", path: "underline", label: "dim", value: "bold", ok: "bold", warn: "bold", problem: "bold", note: "dim", plan: "dim", passed: "bold", failed: "bold", running: "bold", queued: "dim", skipped: "dim" };
331
+ ASCII = { ok: "+", warn: "!", problem: "x", note: ">", plan: "?", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+", open: "*", leaf: "-", guide: "|" };
332
+ PRESETS = {
333
+ default: {},
334
+ "high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"], gradient: ["#d8b4fe", "#a5f3fc"] },
335
+ mono: { colors: MONO, accents: ["bold"], gradient: undefined },
336
+ ascii: { glyphs: ASCII }
337
+ };
338
+ STYLES = new Set(["bold", "dim", "italic", "underline", "inverse", "strikethrough", "black", "red", "green", "yellow", "blue", "magenta", "cyan", "white", "gray", "grey", "blackBright", "redBright", "greenBright", "yellowBright", "blueBright", "magentaBright", "cyanBright", "whiteBright"]);
339
+ HEX = /^#[0-9a-f]{6}$/i;
340
+ CONTROL = /\p{Cc}/u;
341
+ MAX_FILE_BYTES = 64 * 1024;
342
+ SPACES = /\s+/;
343
+ CUBE = [0, 95, 135, 175, 215, 255];
344
+ warned = new Set;
345
+ });
321
346
 
322
347
  // ../kit/src/style.ts
323
- var MARK_WORDS = { ok: "ok:", warn: "warning:", problem: "error:", note: "note:", plan: "would:" };
348
+ import process6 from "process";
324
349
  function takesControlCodes(stream, env = process6.env) {
325
350
  return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
326
351
  }
@@ -340,17 +365,24 @@ function role(name, stream, env = process6.env) {
340
365
  const colors = paint(stream, env);
341
366
  return takesControlCodes(stream, env) ? tinted(colors, activeTheme().theme.colors[name], env) : colors;
342
367
  }
343
- var STATUS_WORDS = {
344
- passed: ["passed", "success", "succeeded", "ok"],
345
- failed: ["failed", "failure", "error", "errored"],
346
- running: ["running", "in_progress", "started", "holding"],
347
- queued: ["queued", "waiting", "pending", "created", "blocked", "scheduled"],
348
- skipped: ["skipped", "cancelled", "canceled", "manual"]
349
- };
350
- var STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
368
+ var MARK_WORDS, STATUS_WORDS, STATUS_OF;
369
+ var init_style = __esm(() => {
370
+ init_colors();
371
+ init_mode();
372
+ init_theme();
373
+ MARK_WORDS = { ok: "ok:", warn: "warning:", problem: "error:", note: "note:", plan: "would:" };
374
+ STATUS_WORDS = {
375
+ passed: ["passed", "success", "succeeded", "ok"],
376
+ failed: ["failed", "failure", "error", "errored"],
377
+ running: ["running", "in_progress", "started", "holding"],
378
+ queued: ["queued", "waiting", "pending", "created", "blocked", "scheduled"],
379
+ skipped: ["skipped", "cancelled", "canceled", "manual"]
380
+ };
381
+ STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
382
+ });
351
383
 
352
384
  // ../kit/src/format.ts
353
- var UNITS = [["d", 86400], ["h", 3600], ["m", 60], ["s", 1]];
385
+ import process7 from "process";
354
386
  function formatSeconds(total) {
355
387
  let rest = Math.max(0, Math.round(total));
356
388
  const amounts = UNITS.map(([unit, size]) => {
@@ -372,10 +404,8 @@ function upTo(text, separator) {
372
404
  return end === -1 ? text : text.slice(0, end);
373
405
  }
374
406
  function truncate(text, width) {
375
- return ko(text, width, { suffix: "\u2026", includeSuffix: true });
407
+ return Ao(text, width, { suffix: "\u2026", includeSuffix: true });
376
408
  }
377
- var LINE_BREAKS = /\s*\n\s*/g;
378
- var ESCAPE = String.fromCharCode(27);
379
409
  function textWidth(text) {
380
410
  return Bun.stringWidth(text);
381
411
  }
@@ -424,14 +454,40 @@ function jsonText(value, replacer, { stream = process7.stdout, env = process7.en
424
454
  function printJson(value) {
425
455
  console.log(jsonText(value));
426
456
  }
457
+ var UNITS, LINE_BREAKS, ESCAPE;
458
+ var init_format = __esm(() => {
459
+ init_text();
460
+ init_mode();
461
+ init_style();
462
+ UNITS = [["d", 86400], ["h", 3600], ["m", 60], ["s", 1]];
463
+ LINE_BREAKS = /\s*\n\s*/g;
464
+ ESCAPE = String.fromCharCode(27);
465
+ });
427
466
 
428
467
  // ../kit/src/help.ts
429
468
  import process8 from "process";
430
- var OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
431
- var USAGE_PREFIX = /^usage:\s*/i;
432
- var FULL_STOP = /\.$/;
433
469
  function usageLine(usage, colors = paint(process8.stdout)) {
434
- return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
470
+ const lines = usage.replace(USAGE_PREFIX, "").split(`
471
+ `);
472
+ const blank = lines.indexOf("");
473
+ const synopses = blank === -1 ? lines : lines.slice(0, blank);
474
+ const details = blank === -1 ? [] : lines.slice(blank + 1);
475
+ const colon = synopses[0].indexOf(": ");
476
+ const inline = synopses[0].slice(colon + 2);
477
+ const summary = colon === -1 ? details.shift() : `${inline.charAt(0).toUpperCase()}${inline.slice(1)}`;
478
+ if (colon !== -1)
479
+ synopses[0] = synopses[0].slice(0, colon);
480
+ const head = `${colors.bold("Usage:")} ${synopses.map((line) => line.replaceAll(OPTIONAL, (part) => colors.dim(part))).join(`
481
+ `)}`;
482
+ const lead = summary === undefined ? [] : ["", colors.bold(prose(summary, colors))];
483
+ const rest = details.length === 0 ? [] : ["", ...details.map((line) => prose(line, colors))];
484
+ return [head, ...lead, ...rest].join(`
485
+ `);
486
+ }
487
+ function prose(line, colors) {
488
+ if (colors.cyan("x") === "x")
489
+ return line;
490
+ return line.replaceAll(PROSE_MARKS, (match, code, flag) => code === undefined ? colors.cyan(flag ?? match) : colors.bold(code));
435
491
  }
436
492
  function helpText(usage, options, colors = paint(process8.stdout), { examples = [], exits = [] } = {}) {
437
493
  return [usageLine(usage, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
@@ -466,7 +522,6 @@ function exampleRows(examples, colors = paint(process8.stdout)) {
466
522
  return [];
467
523
  return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
468
524
  }
469
- var MAX_INLINE_CHOICES = 24;
470
525
  function optionRows(options, colors = paint(process8.stdout)) {
471
526
  const rows = Object.entries(options).map(([name, option]) => {
472
527
  const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
@@ -481,6 +536,15 @@ function optionRows(options, colors = paint(process8.stdout)) {
481
536
  const width = Math.max(0, ...rows.map((row) => row.width));
482
537
  return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
483
538
  }
539
+ var OPTIONAL, USAGE_PREFIX, FULL_STOP, PROSE_MARKS, MAX_INLINE_CHOICES = 24;
540
+ var init_help = __esm(() => {
541
+ init_mode();
542
+ init_style();
543
+ OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
544
+ USAGE_PREFIX = /^usage:\s*/i;
545
+ FULL_STOP = /\.$/;
546
+ PROSE_MARKS = /`([^`\n]+)`|(?<![\w-])(--[a-z][\w-]*|-[a-z](?![\w-]))/gi;
547
+ });
484
548
 
485
549
  // ../kit/src/text.ts
486
550
  function distance(a, b) {
@@ -508,9 +572,9 @@ function closest(name, names) {
508
572
  const [best] = names.map((known) => ({ known, far: distance(name, known) })).sort((a, b) => a.far - b.far);
509
573
  return best !== undefined && best.far <= (name.length < 4 ? 1 : 2) ? best.known : undefined;
510
574
  }
575
+ var init_text2 = () => {};
576
+
511
577
  // ../kit/src/input.ts
512
- var DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
513
- var UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
514
578
  function duration(value, name, fallback, unit = "s") {
515
579
  if (value === undefined)
516
580
  return fallback;
@@ -520,40 +584,26 @@ function duration(value, name, fallback, unit = "s") {
520
584
  badUsage(`--${name} takes a duration such as 30s, 5m, 1h or 7d, not ${value}`);
521
585
  return ms;
522
586
  }
587
+ var DURATION, UNIT_MS;
588
+ var init_input = __esm(() => {
589
+ init_args();
590
+ DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
591
+ UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
592
+ });
523
593
 
524
594
  // ../kit/src/args.ts
525
- var DASHES = /^-+/;
595
+ import process9 from "process";
596
+ import { parseArgs } from "util";
526
597
  function jsonOption(holds) {
527
598
  return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
528
599
  }
529
- class Exit extends Error {
530
- code;
531
- hint;
532
- constructor(message, code, hint) {
533
- super(message);
534
- this.code = code;
535
- this.hint = hint;
536
- }
537
- }
538
600
  function fail(message, code = 2, hint) {
539
601
  throw new Exit(message, code, hint);
540
602
  }
541
-
542
- class UsageError extends Exit {
543
- constructor(message, hint) {
544
- super(message, 2, hint);
545
- }
546
- }
547
603
  function badUsage(message) {
548
604
  throw new UsageError(message);
549
605
  }
550
606
 
551
- class HelpShown extends Exit {
552
- constructor() {
553
- super("help shown", 0);
554
- }
555
- }
556
-
557
607
  class Completing {
558
608
  options;
559
609
  positionals;
@@ -564,11 +614,6 @@ class Completing {
564
614
  this.candidates = candidates;
565
615
  }
566
616
  }
567
- var completion = { active: false };
568
- var OUTPUT_OPTIONS = {
569
- color: { type: "string", description: "auto (on a terminal alone), always or never" },
570
- plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
571
- };
572
617
  function applyOutput(color, plain, env = process9.env) {
573
618
  const when = plain === true ? "never" : color ?? "auto";
574
619
  if (when === "auto")
@@ -722,7 +767,6 @@ function parseError(error) {
722
767
  const message = upTo(error instanceof Error ? error.message : String(error), ". ");
723
768
  return `${message.charAt(0).toLowerCase()}${message.slice(1)}`;
724
769
  }
725
- var UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
726
770
  function nearestOption(message, options, allowNegative) {
727
771
  const typed = UNKNOWN_OPTION.exec(message)?.[1];
728
772
  if (typed === undefined)
@@ -738,6 +782,62 @@ function nearestOption(message, options, allowNegative) {
738
782
  const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
739
783
  return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
740
784
  }
785
+ var DASHES, EXIT, Exit, UsageError, HelpShown, completion, OUTPUT_OPTIONS, UNKNOWN_OPTION;
786
+ var init_args = __esm(() => {
787
+ init_format();
788
+ init_help();
789
+ init_text2();
790
+ init_help();
791
+ init_input();
792
+ DASHES = /^-+/;
793
+ EXIT = Symbol.for("@kaynooo/cli-kit/Exit");
794
+ Exit = class Exit extends Error {
795
+ code;
796
+ hint;
797
+ [EXIT] = true;
798
+ constructor(message, code, hint) {
799
+ super(message);
800
+ this.code = code;
801
+ this.hint = hint;
802
+ }
803
+ static [Symbol.hasInstance](value) {
804
+ if (this !== Exit)
805
+ return Function.prototype[Symbol.hasInstance].call(this, value);
806
+ return typeof value === "object" && value !== null && value[EXIT] === true;
807
+ }
808
+ };
809
+ UsageError = class UsageError extends Exit {
810
+ constructor(message, hint) {
811
+ super(message, 2, hint);
812
+ }
813
+ };
814
+ HelpShown = class HelpShown extends Exit {
815
+ constructor() {
816
+ super("help shown", 0);
817
+ }
818
+ };
819
+ completion = { active: false };
820
+ OUTPUT_OPTIONS = {
821
+ color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
822
+ plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
823
+ };
824
+ UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
825
+ });
826
+
827
+ // ../kit/src/folders.ts
828
+ var SKIPPED_FOLDERS;
829
+ var init_folders = __esm(() => {
830
+ init_user_config();
831
+ SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
832
+ });
833
+
834
+ // src/probe.ts
835
+ import { isIP as isIP2 } from "net";
836
+ import process16 from "process";
837
+
838
+ // ../kit/src/index.ts
839
+ init_args();
840
+
741
841
  // ../kit/src/argv.ts
742
842
  import { readFileSync as readFileSync2, realpathSync } from "fs";
743
843
  import { resolve as resolve3 } from "path";
@@ -762,45 +862,176 @@ function scriptArgs(argv = process10.argv.slice(2), cmdline = commandLine(), scr
762
862
  const after = at === -1 ? [] : cmdline.slice(at + 1);
763
863
  return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
764
864
  }
865
+ // ../kit/src/chart.ts
866
+ init_format();
867
+ init_mode();
868
+ init_style();
869
+ init_theme();
870
+ // ../kit/src/ci.ts
871
+ init_args();
872
+ init_format();
873
+
765
874
  // ../kit/src/progress.ts
875
+ init_format();
876
+
877
+ // ../kit/src/process.ts
878
+ var GROUP_SIGNALS = new Set(["SIGINT", "SIGHUP"]);
879
+
880
+ // ../kit/src/progress.ts
881
+ init_style();
882
+ init_theme();
766
883
  var ESC = String.fromCharCode(27);
767
884
  var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x7E]|\\][^\\u0007${ESC}]*(?:\\u0007|${ESC}\\\\))`, "y");
768
885
  var RESET_STYLE = `${ESC}[0m`;
769
886
  var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
887
+
888
+ // ../kit/src/ci.ts
889
+ init_style();
890
+
891
+ // ../kit/src/tool.ts
892
+ init_format();
770
893
  // ../kit/src/cli.ts
894
+ init_args();
771
895
  import { readFileSync as readFileSync3, realpathSync as realpathSync2 } from "fs";
772
896
  import { dirname as dirname3, join as join5 } from "path";
773
- import process13 from "process";
897
+ import process14 from "process";
774
898
 
775
- // ../kit/src/notify.ts
899
+ // ../kit/src/askpass.ts
776
900
  import process11 from "process";
901
+ var SOCKET_VARIABLE = "KAYNOOO_ASKPASS_SOCKET";
902
+ async function askpassClient(argv) {
903
+ const socketPath = process11.env[SOCKET_VARIABLE];
904
+ if (socketPath === undefined)
905
+ return;
906
+ const request = { prompt: argv[0] ?? "", ...process11.env.SSH_ASKPASS_PROMPT === "none" ? { notice: true } : {} };
907
+ const { promise, resolve } = Promise.withResolvers();
908
+ let received = "";
909
+ try {
910
+ await Bun.connect({
911
+ unix: socketPath,
912
+ socket: {
913
+ open: (socket) => void socket.write(`${JSON.stringify(request)}
914
+ `),
915
+ data: (_, chunk) => {
916
+ received += chunk.toString();
917
+ },
918
+ close: () => resolve(received),
919
+ error: () => resolve("")
920
+ }
921
+ });
922
+ } catch {
923
+ return 1;
924
+ }
925
+ const reply = await promise;
926
+ if (reply === "")
927
+ return 1;
928
+ const { answer } = JSON.parse(reply);
929
+ if (request.notice === true)
930
+ return 0;
931
+ if (answer === undefined)
932
+ return 1;
933
+ process11.stdout.write(`${answer}
934
+ `);
935
+ return 0;
936
+ }
937
+
938
+ // ../kit/src/completions.ts
939
+ var COMPLETION_SHELLS = ["fish", "bash", "zsh"];
940
+ var FISH_FUNCTION = `functions -q __kaynooo_cli_complete; or function __kaynooo_cli_complete --argument-names bin --description 'what a @kaynooo/cli-kit bin offers for the word being typed'
941
+ set -l tokens (commandline -xpc 2>/dev/null; or commandline -opc)
942
+ set -l current (commandline -ct)
943
+ for line in ($bin __complete $tokens[2..-1] $current 2>/dev/null)
944
+ if test "$line" = __files__
945
+ __fish_complete_path $current
946
+ else
947
+ echo $line
948
+ end
949
+ end
950
+ end`;
951
+ var BASH_FUNCTION = `__kaynooo_cli_complete() {
952
+ local IFS=$'\\n' cur=\${COMP_WORDS[COMP_CWORD]} line words=
953
+ local -a lines
954
+ COMPREPLY=()
955
+ lines=($("\${COMP_WORDS[0]}" __complete "\${COMP_WORDS[@]:1:COMP_CWORD}" 2>/dev/null))
956
+ for line in "\${lines[@]}"; do
957
+ if [[ $line == __files__ ]]; then
958
+ COMPREPLY+=($(compgen -f -- "$cur"))
959
+ else
960
+ words+="\${line%%$'\\t'*}"$'\\n'
961
+ fi
962
+ done
963
+ COMPREPLY+=($(compgen -W "$words" -- "$cur"))
964
+ }`;
965
+ var ZSH_FUNCTION = `__kaynooo_cli_complete() {
966
+ local line
967
+ local -a described plain
968
+ for line in \${(f)"$("\${words[1]}" __complete "\${(@)words[2,CURRENT]}" 2>/dev/null)"}; do
969
+ if [[ $line == __files__ ]]; then
970
+ _files
971
+ elif [[ $line == *$'\\t'* ]]; then
972
+ described+=("\${\${line%%$'\\t'*}//:/\\\\:}:\${line#*$'\\t'}")
973
+ else
974
+ plain+=("$line")
975
+ fi
976
+ done
977
+ (( \${#described} )) && _describe -V value described
978
+ (( \${#plain} )) && compadd -- "\${plain[@]}"
979
+ return 0
980
+ }`;
981
+ function completionScript(shell, bins, header = `# Generated by \`${bins[0]} --completions ${shell}\``) {
982
+ if (shell === "fish")
983
+ return `${header}
984
+ ${FISH_FUNCTION}
985
+ ${bins.map((bin) => `complete -c ${bin} -f -a '(__kaynooo_cli_complete ${bin})'
986
+ `).join("")}`;
987
+ if (shell === "bash")
988
+ return `${header}
989
+ ${BASH_FUNCTION}
990
+ complete -F __kaynooo_cli_complete ${bins.join(" ")}
991
+ `;
992
+ return `${header}
993
+ ${ZSH_FUNCTION}
994
+ compdef __kaynooo_cli_complete ${bins.join(" ")}
995
+ `;
996
+ }
997
+
998
+ // ../kit/src/notify.ts
999
+ init_format();
1000
+ init_mode();
1001
+ import process12 from "process";
777
1002
  var NOTIFY_AFTER_MS = 1e4;
778
1003
  var CANCELLED = 130;
779
1004
  function base64(text) {
780
1005
  return Buffer.from(text).toString("base64");
781
1006
  }
782
- function notification(title, body, env = process11.env) {
783
- const id = `kit${process11.pid}`;
1007
+ function notification(title, body, env = process12.env) {
1008
+ const id = `kit${process12.pid}`;
784
1009
  const codes = [`\x1B]99;i=${id}:d=0:o=unfocused:e=1;${base64(title)}\x1B\\`, `\x1B]99;i=${id}:p=body:e=1;${base64(body)}\x1B\\`];
785
1010
  return codes.map((code) => env.TMUX === undefined || env.TMUX === "" ? code : `\x1BPtmux;${code.replaceAll("\x1B", "\x1B\x1B")}\x1B\\`).join("");
786
1011
  }
787
- function notifyEnd(command, code, ms, { stream = process11.stderr, env = process11.env } = {}) {
1012
+ function notifyEnd(command, code, ms, { stream = process12.stderr, env = process12.env } = {}) {
788
1013
  if (ms < NOTIFY_AFTER_MS || code === CANCELLED || outputMode(stream, env) !== "terminal")
789
1014
  return;
790
1015
  stream.write(notification(command, code === 0 ? `done in ${formatDuration(ms)}` : `failed with exit ${code} after ${formatDuration(ms)}`, env));
791
1016
  }
792
1017
 
1018
+ // ../kit/src/cli.ts
1019
+ init_style();
1020
+ init_text2();
1021
+
793
1022
  // ../kit/src/usage.ts
794
1023
  import { appendFileSync, mkdirSync } from "fs";
795
1024
  import { homedir as homedir3 } from "os";
796
- import { dirname as dirname2, isAbsolute, join as join4 } from "path";
797
- import process12 from "process";
1025
+ import { dirname as dirname2, join as join4 } from "path";
1026
+ import process13 from "process";
798
1027
 
799
1028
  // ../kit/src/logs.ts
1029
+ init_user_config();
800
1030
  var DAY_MS = 24 * 60 * 60 * 1000;
801
1031
  var CLI_FOLDER = "kaynooo-cli";
802
1032
 
803
1033
  // ../kit/src/usage.ts
1034
+ init_user_config();
804
1035
  var UNKNOWN_OPTION2 = /unknown option '(--[a-z][a-z0-9-]*)[=']/;
805
1036
  var FLAG_NAME = /^(?:--[a-z][a-z0-9-]*|-[a-zA-Z])$/;
806
1037
  var LONGEST_NAME = 40;
@@ -808,14 +1039,13 @@ var usageError;
808
1039
  function noteUsageError(message) {
809
1040
  usageError = message;
810
1041
  }
811
- function stateHome(env = process12.env) {
812
- const dir = env.XDG_STATE_HOME;
813
- return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
1042
+ function stateHome(env = process13.env) {
1043
+ return xdgFolder(env.XDG_STATE_HOME, join4(homedir3(), ".local", "state"));
814
1044
  }
815
- function usagePath(env = process12.env) {
1045
+ function usagePath(env = process13.env) {
816
1046
  return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
817
1047
  }
818
- function usageRecorded(env = process12.env) {
1048
+ function usageRecorded(env = process13.env) {
819
1049
  const off = env.KAYNOOO_CLI_NO_USAGE;
820
1050
  return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
821
1051
  }
@@ -824,12 +1054,12 @@ function flagNames(argv) {
824
1054
  const names = (end === -1 ? argv : argv.slice(0, end)).filter((word) => word.startsWith("-") && word !== "-").map((word) => word.includes("=") ? word.slice(0, word.indexOf("=")) : word);
825
1055
  return [...new Set(names)].filter((name) => name.length <= LONGEST_NAME && FLAG_NAME.test(name));
826
1056
  }
827
- function usageEntry(bin, command, argv, code, now = new Date) {
1057
+ function usageEntry(bin, command, argv, code, { ms, now = new Date } = {}) {
828
1058
  const unknown = code === 2 && usageError !== undefined ? UNKNOWN_OPTION2.exec(usageError)?.[1] : undefined;
829
1059
  usageError = undefined;
830
- return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
1060
+ return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown }, ...ms === undefined ? {} : { ms: Math.round(ms) } };
831
1061
  }
832
- function recordUsage(entry, env = process12.env) {
1062
+ function recordUsage(entry, env = process13.env) {
833
1063
  if (!usageRecorded(env))
834
1064
  return;
835
1065
  try {
@@ -845,10 +1075,14 @@ var LEVEL_OPTIONS = {
845
1075
  ...OUTPUT_OPTIONS,
846
1076
  help: { type: "boolean", short: "h", description: "show this help" }
847
1077
  };
848
- var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
1078
+ var TOP_OPTIONS = {
1079
+ ...LEVEL_OPTIONS,
1080
+ version: { type: "boolean", short: "v", description: "print the version" },
1081
+ completions: { type: "string", choices: COMPLETION_SHELLS, description: "print the shell completion script" }
1082
+ };
849
1083
  function printError(prefix, message, hint, cause) {
850
- const colors = paint(process13.stderr);
851
- const styled = takesControlCodes(process13.stderr);
1084
+ const colors = paint(process14.stderr);
1085
+ const styled = takesControlCodes(process14.stderr);
852
1086
  const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
853
1087
  const under = (label, text, tint) => text === undefined ? "" : `
854
1088
  ${styled ? tint(label) : `${label}:`} ${text}`;
@@ -925,6 +1159,19 @@ async function leafCandidates(run, words) {
925
1159
  const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
926
1160
  return values === undefined ? [FILES] : values.map(candidateLine);
927
1161
  }
1162
+ var COMPLETIONS = "--completions";
1163
+ function flagValue([flag = "", ...rest]) {
1164
+ return flag.includes("=") ? [flag.slice(flag.indexOf("=") + 1), ...rest] : rest;
1165
+ }
1166
+ function printCompletionScript(name, args) {
1167
+ const shell = COMPLETION_SHELLS.find((each) => each === args[0]);
1168
+ if (shell === undefined || args.length !== 1) {
1169
+ printError(name, `${COMPLETIONS} takes one of ${COMPLETION_SHELLS.join(", ")}`, `${name} ${COMPLETIONS} fish`);
1170
+ return 2;
1171
+ }
1172
+ console.log(completionScript(shell, [name]).trimEnd());
1173
+ return 0;
1174
+ }
928
1175
  async function printCandidates(found) {
929
1176
  for (const line of await found)
930
1177
  console.log(line);
@@ -946,8 +1193,13 @@ function packageVersion(entry = Bun.main) {
946
1193
  }
947
1194
  }
948
1195
  async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
1196
+ const answered = await askpassClient(argv);
1197
+ if (answered !== undefined)
1198
+ return answered;
949
1199
  if (argv[0] === COMPLETE)
950
1200
  return printCandidates(leafCandidates(run, argv.slice(1)));
1201
+ if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
1202
+ return printCompletionScript(name, flagValue(argv));
951
1203
  if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
952
1204
  console.log(version ?? packageVersion());
953
1205
  return 0;
@@ -962,19 +1214,53 @@ async function runMain({ name, version, run, redact, usage }, argv = scriptArgs(
962
1214
  notifyEnd(name, code, performance.now() - started);
963
1215
  if (usage !== false) {
964
1216
  try {
965
- recordUsage(usageEntry(name, undefined, argv, code));
1217
+ recordUsage(usageEntry(name, undefined, argv, code, { ms: performance.now() - started }));
966
1218
  } catch {}
967
1219
  }
968
1220
  return code;
969
1221
  }
970
- // ../kit/src/folders.ts
971
- var SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
1222
+
1223
+ // ../kit/src/index.ts
1224
+ init_config();
1225
+
1226
+ // ../kit/src/excerpt.ts
1227
+ init_text2();
1228
+
1229
+ // ../kit/src/index.ts
1230
+ init_folders();
1231
+ init_format();
1232
+
1233
+ // ../kit/src/git.ts
1234
+ init_args();
1235
+ // ../kit/src/limit.ts
1236
+ init_args();
1237
+
1238
+ // ../kit/src/index.ts
1239
+ init_mode();
1240
+
1241
+ // ../kit/src/report.ts
1242
+ init_style();
1243
+ init_text2();
972
1244
  // ../kit/src/secrets.ts
973
1245
  var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
1246
+ var NOT_PASSWORDS = new Set(["compass", "encompass", "bypass", "overpass", "underpass", "surpass", "trespass"]);
974
1247
  // ../kit/src/sessions.ts
975
1248
  var {Glob } = globalThis.Bun;
976
1249
  var SESSION_FILES = new Glob("*.json");
977
1250
  var ACCOUNT_DIRS = new Glob("*/sessions");
1251
+
1252
+ // ../kit/src/index.ts
1253
+ init_style();
1254
+ init_text2();
1255
+ init_theme();
1256
+ init_user_config();
1257
+
1258
+ // ../kit/src/watch.ts
1259
+ init_args();
1260
+ init_input();
1261
+ init_style();
1262
+ // ../kit/src/workspace-root.ts
1263
+ init_user_config();
978
1264
  // src/analyze.ts
979
1265
  var SOON_DAYS = 14;
980
1266
  var MAX_HOPS = 10;
@@ -1481,15 +1767,11 @@ async function tlsInfo(host, port, { address, timeoutS = CONNECT_TIMEOUT } = {})
1481
1767
  var LABEL_WIDTH = 13;
1482
1768
  var USAGE = `probe [options] <url|domain>...: reports each site's negotiated HTTP version, redirect chain, timings, addresses, TLS and certificate, the headers worth knowing and what warrants a warning
1483
1769
 
1484
- By default one line per target: the HTTP version, status, final URL, total time, redirects, certificate expiry, first address and the warnings. --verbose prints the whole table.
1485
- A bare domain is tried over https first and over http when that fails. Redirects are followed hop by hop (at most ${MAX_HOPS}), each hop's status and HTTP version listed. HTTP/3 is spoken only when the installed curl lists it, otherwise it is reported from alt-svc. The certificate is read even when it is not trusted, and --insecure also lets curl go on with it.
1486
- -H adds a header to every request, --resolve host:ip reaches a host at that address instead of the DNS answer (the certificate and the Host header stay the host's), both repeatable.
1487
-
1488
- Warns on a certificate with fewer than 14 days left or not trusted, and on an http:// twin that does not redirect to https (checked for a bare domain or an https URL on the default port).
1489
-
1490
- --dns makes no HTTP request: it asks the system resolver, Cloudflare, Google, Quad9 and each nameserver of the host's zone for its A, AAAA and CNAME records with their TTL, and warns on a resolver answering otherwise than the zone's nameservers, a change not reached it yet.
1491
- --cors <origin> sends the preflight a browser on that origin would send before a --method request carrying --cors-headers, and says whether the browser would go on, with each reason when it would not.`;
1492
- var EXITS = [[0, "every site answered, warnings or not"], [1, "a site could not be reached, a CORS preflight was refused, or no resolver knows a name"], [2, "a usage error"]];
1770
+ A bare domain is tried over https first, then http, and redirects are followed hop by hop (at most ${MAX_HOPS}).
1771
+ Warns on a certificate with fewer than 14 days left or not trusted, and on an http:// twin that does not redirect to https.
1772
+ --dns makes no HTTP request and compares the records the system resolver, public resolvers and the zone's nameservers give.
1773
+ --cors <origin> sends the preflight a browser on that origin would send and says whether it would go on, with each reason when not.`;
1774
+ var EXITS = [[0, "every site answered, warnings or not"], [1, "a site could not be reached or redirects where nothing answers, a CORS preflight was refused, or no resolver knows a name"], [2, "a usage error"]];
1493
1775
  var OPTIONS = {
1494
1776
  insecure: { type: "boolean", short: "k", description: "let curl go on with a certificate it does not trust" },
1495
1777
  header: { type: "string", short: "H", multiple: true, description: "a `Name: value` header sent with every request, repeatable" },
@@ -1500,17 +1782,17 @@ var OPTIONS = {
1500
1782
  cors: { type: "string", description: "the origin a browser would call from: whether its CORS preflight lets the request through", conflicts: ["dns", "verbose"] },
1501
1783
  method: { type: "string", description: "with --cors, the method of the request the preflight asks for (POST)" },
1502
1784
  "cors-headers": { type: "string", description: "with --cors, the headers it carries, comma separated, empty for none (content-type)" },
1503
- json: jsonOption("one object per target {target, url, version, status, chain, timings, addresses, tls, certificate, headers, cdn, offers, httpRedirect, warnings}, an array of them for several targets (an unreachable one is {target, error}); with --dns {target, zone, answers, agree, warnings}, with --cors {target, url, status, request, allowed, reasons, warnings, headers}")
1785
+ json: jsonOption("one object per target {target, url, version, status, chain, timings, addresses, tls, certificate, headers, cdn, offers, httpRedirect, failedHop: {url, error} or null, warnings}, an array of them for several targets (an unreachable one is {target, error}); with --dns {target, zone, answers, agree, warnings}, with --cors {target, url, status, request, allowed, reasons, warnings, headers}")
1504
1786
  };
1505
1787
  var BRACKETS2 = /^\[|\]$/g;
1506
1788
  var HEADER_LINE = /^[\w!#$%&'*+.^`|~-]+:/;
1507
1789
  async function follow(start, { insecure, wire }, http3) {
1508
1790
  const chain = [];
1509
1791
  let url = start;
1510
- while (chain.length < MAX_HOPS) {
1792
+ while (chain.length <= MAX_HOPS) {
1511
1793
  const { hop, errormsg } = await curlHop(url, { ...wire, http3: http3 && url.startsWith("https:"), insecure, get: false });
1512
1794
  if (hop === undefined)
1513
- return { chain, error: errormsg ?? "no response", tooMany: false };
1795
+ return { chain, failed: { url, error: errormsg ?? "no response" }, tooMany: false };
1514
1796
  chain.push(hop);
1515
1797
  const next = hop.location === undefined ? undefined : nextUrl(hop.url, hop.location);
1516
1798
  if (!isRedirect(hop.status) || next === undefined)
@@ -1523,16 +1805,19 @@ async function probe(target, input, settings) {
1523
1805
  const { wire } = settings;
1524
1806
  const http3 = await curlHasHttp3();
1525
1807
  let followed = await follow(target.url.href, settings, http3);
1808
+ let httpsError;
1526
1809
  if (followed.chain.length === 0 && target.bare) {
1527
1810
  const plain = new URL(target.url.href);
1528
1811
  plain.protocol = "http:";
1529
1812
  const second = await follow(plain.href, settings, http3);
1530
- if (second.chain.length > 0)
1813
+ if (second.chain.length > 0) {
1814
+ httpsError = followed.failed?.error;
1531
1815
  followed = second;
1816
+ }
1532
1817
  }
1533
1818
  const final = followed.chain.at(-1);
1534
1819
  if (final === undefined)
1535
- return { target: input, error: `could not reach ${target.url.host}: ${followed.error ?? "no response"}` };
1820
+ return { target: input, error: `could not reach ${target.url.host}: ${followed.failed?.error ?? "no response"}` };
1536
1821
  const finalUrl = new URL(final.url);
1537
1822
  const secure = finalUrl.protocol === "https:";
1538
1823
  const [addresses, tls, twin] = await Promise.all([
@@ -1543,8 +1828,10 @@ async function probe(target, input, settings) {
1543
1828
  const httpRedirect = httpRedirectOf(twin);
1544
1829
  const offers = offersOf({ alpn: tls?.alpn, version: final.version, altSvc: final.headers["alt-svc"] });
1545
1830
  const warnings = warningsOf({ cert: tls?.cert, authorizationError: tls?.authorizationError, httpRedirect, tooManyRedirects: followed.tooMany });
1831
+ if (followed.failed !== undefined)
1832
+ warnings.unshift(`the redirect to ${followed.failed.url} got no answer: ${followed.failed.error}`);
1546
1833
  if (!secure)
1547
- warnings.push("the site is not served over https");
1834
+ warnings.push(httpsError === undefined ? "the site is not served over https" : `the site is not served over https: ${httpsError}`);
1548
1835
  return {
1549
1836
  target: input,
1550
1837
  url: final.url,
@@ -1559,9 +1846,11 @@ async function probe(target, input, settings) {
1559
1846
  cdn: cdnHint(final.headers) ?? null,
1560
1847
  offers,
1561
1848
  httpRedirect: httpRedirect ?? null,
1849
+ failedHop: followed.failed ?? null,
1562
1850
  warnings
1563
1851
  };
1564
1852
  }
1853
+ var unreached = (report) => ("error" in report) || report.failedHop !== null;
1565
1854
  async function twinOf(url, { insecure, wire }) {
1566
1855
  const plain = new URL(url.href);
1567
1856
  plain.protocol = "http:";
@@ -1582,9 +1871,9 @@ function ms2(value) {
1582
1871
  return `${value}ms`;
1583
1872
  }
1584
1873
  function compact(report) {
1585
- const { dim } = paint(process15.stdout);
1874
+ const { dim } = paint(process16.stdout);
1586
1875
  const redirects = report.chain.length - 1;
1587
- const parts = [`${role("accent", process15.stdout)(versionLabel(report.version))} ${role("value", process15.stdout)(String(report.status))} ${role("path", process15.stdout)(report.url)}`, ms2(report.timings.total)];
1876
+ const parts = [`${role("accent", process16.stdout)(versionLabel(report.version))} ${role("value", process16.stdout)(String(report.status))} ${role("path", process16.stdout)(report.url)}`, ms2(report.timings.total)];
1588
1877
  const address = report.addresses.a[0] ?? report.addresses.aaaa[0];
1589
1878
  if (redirects > 0)
1590
1879
  parts.push(`${redirects} ${redirects === 1 ? "redirect" : "redirects"}`);
@@ -1593,14 +1882,14 @@ function compact(report) {
1593
1882
  if (address !== undefined)
1594
1883
  parts.push(address);
1595
1884
  const line = parts.join(dim(" "));
1596
- return report.warnings.length === 0 ? line : `${line} ${marked("warn", report.warnings.join("; "), process15.stdout)}`;
1885
+ return report.warnings.length === 0 ? line : `${line} ${marked("warn", report.warnings.join("; "), process16.stdout)}`;
1597
1886
  }
1598
1887
  function print(report) {
1599
- const label = role("label", process15.stdout);
1600
- const value = role("value", process15.stdout);
1601
- const accent = role("accent", process15.stdout);
1888
+ const label = role("label", process16.stdout);
1889
+ const value = role("value", process16.stdout);
1890
+ const accent = role("accent", process16.stdout);
1602
1891
  const row = (name, text) => console.log(`${label(name.padEnd(LABEL_WIDTH))} ${text}`);
1603
- console.log(`${accent(versionLabel(report.version))} ${value(String(report.status))} ${role("path", process15.stdout)(report.url)}`);
1892
+ console.log(`${accent(versionLabel(report.version))} ${value(String(report.status))} ${role("path", process16.stdout)(report.url)}`);
1604
1893
  console.log("");
1605
1894
  if (report.chain.length > 1) {
1606
1895
  console.log(table(report.chain.map((hop) => [String(hop.status), versionLabel(hop.version), ms2(hop.ms), hop.url]), { align: ["right", "left", "right", "left"] }));
@@ -1625,12 +1914,12 @@ function print(report) {
1625
1914
  if (report.httpRedirect !== null)
1626
1915
  row("http://", report.httpRedirect.toHttps ? `redirects to https (${report.httpRedirect.status})` : `answers ${report.httpRedirect.status}`);
1627
1916
  for (const warning of report.warnings)
1628
- console.log(marked("warn", warning, process15.stdout));
1917
+ console.log(marked("warn", warning, process16.stdout));
1629
1918
  }
1630
1919
  function printDns(report) {
1631
- const label = role("label", process15.stdout);
1920
+ const label = role("label", process16.stdout);
1632
1921
  const listed = (values) => values.length === 0 ? "-" : values.join(" ");
1633
- console.log(`${role("path", process15.stdout)(report.target)} ${label(report.zone === null ? "no zone found" : `zone ${report.zone}`)}`);
1922
+ console.log(`${role("path", process16.stdout)(report.target)} ${label(report.zone === null ? "no zone found" : `zone ${report.zone}`)}`);
1634
1923
  console.log(table([
1635
1924
  ["RESOLVER", "SERVER", "A", "AAAA", "CNAME", "TTL"],
1636
1925
  ...report.answers.map((answer) => [
@@ -1641,9 +1930,9 @@ function printDns(report) {
1641
1930
  ])
1642
1931
  ], { header: true }));
1643
1932
  if (report.agree)
1644
- console.log(marked("ok", "every resolver gives the same answer", process15.stdout));
1933
+ console.log(marked("ok", "every resolver gives the same answer", process16.stdout));
1645
1934
  for (const warning of report.warnings)
1646
- console.log(marked("warn", warning, process15.stdout));
1935
+ console.log(marked("warn", warning, process16.stdout));
1647
1936
  }
1648
1937
  async function dnsMain(inputs, timeoutMs, json) {
1649
1938
  const hosts = inputs.map((input) => {
@@ -1668,16 +1957,16 @@ async function dnsMain(inputs, timeoutMs, json) {
1668
1957
  return reports.every(known) ? 0 : 1;
1669
1958
  }
1670
1959
  function printCors(report) {
1671
- const label = role("label", process15.stdout);
1960
+ const label = role("label", process16.stdout);
1672
1961
  const { request } = report;
1673
1962
  const asked = `from ${request.origin}, ${request.method}${request.headers.length === 0 ? "" : ` with ${request.headers.join(", ")}`}`;
1674
- console.log(`${marked(report.allowed ? "ok" : "problem", report.allowed ? "allowed" : "refused", process15.stdout)} ${role("value", process15.stdout)(String(report.status))} ${role("path", process15.stdout)(report.url)} ${label(asked)}`);
1963
+ console.log(`${marked(report.allowed ? "ok" : "problem", report.allowed ? "allowed" : "refused", process16.stdout)} ${role("value", process16.stdout)(String(report.status))} ${role("path", process16.stdout)(report.url)} ${label(asked)}`);
1675
1964
  for (const [name, value] of Object.entries(report.headers))
1676
1965
  console.log(` ${label(name)} ${value}`);
1677
1966
  for (const reason of report.reasons)
1678
- console.log(marked("problem", reason, process15.stdout));
1967
+ console.log(marked("problem", reason, process16.stdout));
1679
1968
  for (const warning of report.warnings)
1680
- console.log(marked("warn", warning, process15.stdout));
1969
+ console.log(marked("warn", warning, process16.stdout));
1681
1970
  }
1682
1971
  async function corsMain(targets, request, { insecure, wire }, json) {
1683
1972
  const reports = await Promise.all(targets.map(async ({ input, target }) => {
@@ -1694,7 +1983,7 @@ async function corsMain(targets, request, { insecure, wire }, json) {
1694
1983
  } else {
1695
1984
  for (const report of reports) {
1696
1985
  if ("error" in report)
1697
- console.error(marked("problem", report.error, process15.stderr));
1986
+ console.error(marked("problem", report.error, process16.stderr));
1698
1987
  else
1699
1988
  printCors(report);
1700
1989
  }
@@ -1737,23 +2026,23 @@ async function main(args) {
1737
2026
  fail(only.error, 1);
1738
2027
  if (values.json === true) {
1739
2028
  printJson(reports.length === 1 ? only : reports);
1740
- return reports.some((report) => ("error" in report)) ? 1 : 0;
2029
+ return reports.some(unreached) ? 1 : 0;
1741
2030
  }
1742
2031
  let first = true;
1743
2032
  for (const report of reports) {
1744
2033
  if ("error" in report) {
1745
- console.error(marked("problem", report.error, process15.stderr));
2034
+ console.error(marked("problem", report.error, process16.stderr));
1746
2035
  } else if (values.verbose === true) {
1747
2036
  if (!first)
1748
2037
  console.log("");
1749
2038
  if (reports.length > 1)
1750
- console.log(role("label", process15.stdout)(report.target));
2039
+ console.log(role("label", process16.stdout)(report.target));
1751
2040
  print(report);
1752
2041
  } else {
1753
2042
  console.log(compact(report));
1754
2043
  }
1755
2044
  first = false;
1756
2045
  }
1757
- return reports.some((report) => ("error" in report)) ? 1 : 0;
2046
+ return reports.some(unreached) ? 1 : 0;
1758
2047
  }
1759
- process15.exitCode = await runMain({ name: "probe", run: main });
2048
+ process16.exitCode = await runMain({ name: "probe", run: main });
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "@kaynooo/cli-probe",
3
3
  "type": "module",
4
- "version": "0.4.1",
4
+ "version": "0.4.5",
5
5
  "description": "probe: a site's HTTP version, redirect chain, timings, addresses, TLS certificate and notable headers in one call, with warnings.",
6
6
  "author": "Kaynooo <contact@kaynooo.fr>",
7
7
  "license": "MIT",
8
- "homepage": "https://git.kaynooo.fr/kaynooo/cli/src/branch/main/packages/probe#readme",
8
+ "homepage": "https://github.com/Kayno0o/cli/tree/main/packages/probe#readme",
9
9
  "repository": {
10
10
  "type": "git",
11
- "url": "git+https://git.kaynooo.fr/kaynooo/cli.git",
11
+ "url": "git+https://github.com/Kayno0o/cli.git",
12
12
  "directory": "packages/probe"
13
13
  },
14
- "bugs": "https://git.kaynooo.fr/kaynooo/cli/issues",
14
+ "bugs": "https://github.com/Kayno0o/cli/issues",
15
15
  "keywords": [
16
16
  "cli",
17
17
  "http",
@@ -35,6 +35,6 @@
35
35
  "probe": "$npm_execpath src/probe.ts"
36
36
  },
37
37
  "devDependencies": {
38
- "@kaynooo/cli-kit": "0.39.0"
38
+ "@kaynooo/cli-kit": "0.46.1"
39
39
  }
40
40
  }