@kaynooo/cli-guard 0.11.1 → 0.12.0

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 (2) hide show
  1. package/dist/cli.js +282 -78
  2. package/package.json +5 -5
package/dist/cli.js CHANGED
@@ -2,12 +2,12 @@
2
2
  // @bun
3
3
 
4
4
  // src/cli.ts
5
- import { appendFileSync as appendFileSync2, existsSync as existsSync3, mkdirSync as mkdirSync2, readFileSync as readFileSync5, rmSync, statSync, writeFileSync } from "fs";
6
- import { homedir as homedir3 } from "os";
7
- import { dirname as dirname4 } from "path";
8
- import process14 from "process";
5
+ import { appendFileSync as appendFileSync2, existsSync as existsSync5, mkdirSync as mkdirSync2, readFileSync as readFileSync6, rmSync, statSync as statSync2, writeFileSync } from "fs";
6
+ import { homedir as homedir4 } from "os";
7
+ import { dirname as dirname5 } from "path";
8
+ import process16 from "process";
9
9
  // ../kit/src/args.ts
10
- import process7 from "process";
10
+ import process9 from "process";
11
11
  import { parseArgs } from "util";
12
12
 
13
13
  // ../kit/src/mode.ts
@@ -29,7 +29,7 @@ function outputMode(stream = process2.stdout, env = process2.env) {
29
29
  }
30
30
 
31
31
  // ../kit/src/style.ts
32
- import process4 from "process";
32
+ import process6 from "process";
33
33
 
34
34
  // ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-x450vn3m.js
35
35
  var G = /^[a-f0-9]+$/i;
@@ -86,28 +86,49 @@ function Fe(r = {}) {
86
86
  }
87
87
  var o = Fe();
88
88
 
89
+ // ../kit/src/theme.ts
90
+ import { existsSync as existsSync3, readFileSync as readFileSync2, statSync } from "fs";
91
+ import { homedir as homedir2 } from "os";
92
+ import { join as join3, resolve as resolve2 } from "path";
93
+ import process5 from "process";
94
+
95
+ // ../kit/src/config.ts
96
+ import { existsSync } from "fs";
97
+ import { dirname, join, resolve } from "path";
98
+ import process3 from "process";
99
+ function findUp(names, from = process3.cwd(), stop = () => false) {
100
+ const wanted = typeof names === "string" ? [names] : names;
101
+ for (let dir = resolve(from);; dir = dirname(dir)) {
102
+ const found = wanted.map((name) => join(dir, name)).find((path) => existsSync(path));
103
+ if (found !== undefined)
104
+ return found;
105
+ if (stop(dir) || dirname(dir) === dir)
106
+ return;
107
+ }
108
+ }
109
+
89
110
  // ../kit/src/user-config.ts
90
- import { existsSync, readFileSync } from "fs";
111
+ import { existsSync as existsSync2, readFileSync } from "fs";
91
112
  import { homedir } from "os";
92
- import { join } from "path";
93
- import process3 from "process";
113
+ import { join as join2 } from "path";
114
+ import process4 from "process";
94
115
  function configBase(where = {}) {
95
- const xdg = where.xdg ?? (where.home === undefined ? process3.env.XDG_CONFIG_HOME : undefined);
96
- return xdg !== undefined && xdg !== "" ? xdg : join(where.home ?? homedir(), ".config");
116
+ const xdg = where.xdg ?? (where.home === undefined ? process4.env.XDG_CONFIG_HOME : undefined);
117
+ return xdg !== undefined && xdg !== "" ? xdg : join2(where.home ?? homedir(), ".config");
97
118
  }
98
119
  function userConfigPath(bin, where = {}) {
99
- return join(configBase(where), "kaynooo-cli", `${bin}.json`);
120
+ return join2(configBase(where), "kaynooo-cli", `${bin}.json`);
100
121
  }
101
122
  function userConfigReadPath(bin, legacy = [], where = {}) {
102
123
  const current = userConfigPath(bin, where);
103
- if (existsSync(current))
124
+ if (existsSync2(current))
104
125
  return current;
105
126
  const base = configBase(where);
106
- return legacy.map((parts) => join(base, ...parts)).find((path) => existsSync(path)) ?? current;
127
+ return legacy.map((parts) => join2(base, ...parts)).find((path) => existsSync2(path)) ?? current;
107
128
  }
108
129
  function readUserConfig(bin, where = {}, legacy = []) {
109
130
  const path = userConfigReadPath(bin, legacy, where);
110
- if (!existsSync(path))
131
+ if (!existsSync2(path))
111
132
  return {};
112
133
  try {
113
134
  const parsed = Bun.JSONC.parse(readFileSync(path, "utf8"));
@@ -123,17 +144,196 @@ function configuredNumber(bin, key, fallback, where = {}, legacy = []) {
123
144
 
124
145
  // ../kit/src/theme.ts
125
146
  var ENDS = new Map;
147
+ var DEFAULT = {
148
+ 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" },
149
+ 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" },
150
+ accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
151
+ bins: {},
152
+ gradient: ["#c084fc", "#67e8f9"]
153
+ };
154
+ 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" };
155
+ 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" };
156
+ var ASCII = { ok: "+", warn: "!", problem: "x", note: ">", plan: "?", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+", open: "*", leaf: "-", guide: "|" };
157
+ var PRESETS = {
158
+ default: {},
159
+ "high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"], gradient: ["#d8b4fe", "#a5f3fc"] },
160
+ mono: { colors: MONO, accents: ["bold"], gradient: undefined },
161
+ ascii: { glyphs: ASCII }
162
+ };
126
163
  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"]);
164
+ var HEX = /^#[0-9a-f]{6}$/i;
165
+ var CONTROL = /\p{Cc}/u;
127
166
  var MAX_FILE_BYTES = 64 * 1024;
167
+ var SPACES = /\s+/;
168
+ function isColorSpec(spec) {
169
+ if (typeof spec === "number")
170
+ return Number.isInteger(spec) && spec >= 0 && spec <= 255;
171
+ return typeof spec === "string" && spec.trim() !== "" && spec.trim().split(SPACES).every((token) => STYLES.has(token) || HEX.test(token));
172
+ }
173
+ var CUBE = [0, 95, 135, 175, 215, 255];
174
+ function cubeLevel(channel) {
175
+ return CUBE.reduce((best, value, level) => Math.abs(value - channel) < Math.abs(CUBE[best] - channel) ? level : best, 0);
176
+ }
177
+ function nearest256(hex) {
178
+ const rgb = [1, 3, 5].map((at) => Number.parseInt(hex.slice(at, at + 2), 16));
179
+ const levels = rgb.map(cubeLevel);
180
+ const cube = levels.map((level) => CUBE[level]);
181
+ const grey = Math.min(23, Math.max(0, Math.round((rgb.reduce((sum, channel) => sum + channel, 0) / 3 - 8) / 10)));
182
+ const greyValue = 8 + grey * 10;
183
+ const distance = (colour) => colour.reduce((sum, channel, at) => sum + (channel - rgb[at]) ** 2, 0);
184
+ return distance([greyValue, greyValue, greyValue]) < distance(cube) ? 232 + grey : 16 + 36 * levels[0] + 6 * levels[1] + levels[2];
185
+ }
186
+ function hasTrueColor(env) {
187
+ return env.COLORTERM === "truecolor" || env.COLORTERM === "24bit";
188
+ }
189
+ function tinted(colors, spec, env = process5.env) {
190
+ if (typeof spec === "number")
191
+ return colors.ansi256(spec);
192
+ return spec.trim().split(SPACES).reduce((chain, token) => {
193
+ if (HEX.test(token))
194
+ return hasTrueColor(env) ? chain.hex(token) : chain.ansi256(nearest256(token));
195
+ return chain[token] ?? chain;
196
+ }, colors);
197
+ }
198
+ function isRecord(value) {
199
+ return typeof value === "object" && value !== null && !Array.isArray(value);
200
+ }
201
+ function readThemeFile(path, warn) {
202
+ try {
203
+ const stat = statSync(path, { throwIfNoEntry: false });
204
+ if (stat === undefined)
205
+ return;
206
+ if (!stat.isFile() || stat.size > MAX_FILE_BYTES) {
207
+ warn(`${path} is not a regular file under ${MAX_FILE_BYTES / 1024} KiB, theme ignored`);
208
+ return;
209
+ }
210
+ const parsed = JSON.parse(readFileSync2(path, "utf8"));
211
+ if (isRecord(parsed))
212
+ return parsed;
213
+ warn(`${path} is not a JSON object, theme ignored`);
214
+ } catch (error) {
215
+ warn(`${path} does not parse (${error instanceof Error ? error.message : String(error)}), theme ignored`);
216
+ }
217
+ return;
218
+ }
219
+ function applyPreset(theme, name, warn, where) {
220
+ if (name === undefined)
221
+ return;
222
+ if (typeof name !== "string" || !Object.hasOwn(PRESETS, name)) {
223
+ warn(`${where}: no preset ${String(name)}, one of ${Object.keys(PRESETS).join(", ")}`);
224
+ return;
225
+ }
226
+ const preset = PRESETS[name];
227
+ Object.assign(theme.colors, preset.colors);
228
+ Object.assign(theme.glyphs, preset.glyphs);
229
+ if (preset.accents !== undefined)
230
+ theme.accents = [...preset.accents];
231
+ if (Object.hasOwn(preset, "gradient"))
232
+ theme.gradient = preset.gradient;
233
+ return name;
234
+ }
235
+ function applyFile(theme, file, where, warn) {
236
+ if (isRecord(file.colors)) {
237
+ for (const [key, value] of Object.entries(file.colors)) {
238
+ if (!Object.hasOwn(DEFAULT.colors, key))
239
+ warn(`${where}: no colour ${key}, one of ${Object.keys(DEFAULT.colors).join(", ")}`);
240
+ else if (!isColorSpec(value))
241
+ warn(`${where}: colour ${key} is not an ANSI name, \`#rrggbb\` or a number up to 255`);
242
+ else
243
+ theme.colors[key] = value;
244
+ }
245
+ }
246
+ if (isRecord(file.glyphs)) {
247
+ for (const [key, value] of Object.entries(file.glyphs)) {
248
+ if (!Object.hasOwn(DEFAULT.glyphs, key))
249
+ warn(`${where}: no glyph ${key}, one of ${Object.keys(DEFAULT.glyphs).join(", ")}`);
250
+ else if (typeof value !== "string" || CONTROL.test(value) || Bun.stringWidth(value) !== 1)
251
+ warn(`${where}: glyph ${key} must be one visible character wide, with no control character`);
252
+ else
253
+ theme.glyphs[key] = value;
254
+ }
255
+ }
256
+ if (Array.isArray(file.accents) && file.accents.length > 0 && file.accents.every(isColorSpec))
257
+ theme.accents = [...file.accents];
258
+ else if (file.accents !== undefined)
259
+ warn(`${where}: accents must be a non-empty list of colours`);
260
+ if (file.gradient === null)
261
+ theme.gradient = undefined;
262
+ else if (Array.isArray(file.gradient) && file.gradient.length === 2 && file.gradient.every((end) => typeof end === "string" && HEX.test(end)))
263
+ theme.gradient = [file.gradient[0], file.gradient[1]];
264
+ else if (file.gradient !== undefined)
265
+ warn(`${where}: gradient must be two \`#rrggbb\` colours, or null for none`);
266
+ if (isRecord(file.bins)) {
267
+ for (const [bin, value] of Object.entries(file.bins)) {
268
+ if (isColorSpec(value))
269
+ theme.bins[bin] = value;
270
+ else
271
+ warn(`${where}: bin ${bin} has no valid colour`);
272
+ }
273
+ }
274
+ }
275
+ function endsWalk(home) {
276
+ return (dir) => dir === resolve2(home) || existsSync3(join3(dir, ".git"));
277
+ }
128
278
  var warned = new Set;
279
+ function warnOnce(message) {
280
+ if (warned.has(message))
281
+ return;
282
+ warned.add(message);
283
+ console.error(`warning: theme ${message}`);
284
+ }
285
+ function isPath(chosen) {
286
+ return chosen.includes("/") || chosen.endsWith(".json");
287
+ }
288
+ function loadTheme({ env = process5.env, from = process5.cwd(), home = homedir2(), warn = warnOnce } = {}) {
289
+ const theme = { colors: { ...DEFAULT.colors }, glyphs: { ...DEFAULT.glyphs }, accents: [...DEFAULT.accents], bins: Object.create(null), gradient: DEFAULT.gradient };
290
+ const sources = [];
291
+ const chosen = env.KIT_THEME ?? "";
292
+ const wanted = chosen === "" ? [userConfigPath("theme", { home, xdg: env.XDG_CONFIG_HOME }), findUp(join3(".kaynooo", "theme.json"), from, endsWalk(home))] : [];
293
+ if (isPath(chosen))
294
+ wanted.push(resolve2(from, chosen));
295
+ const files = [];
296
+ for (const path of wanted) {
297
+ const file = path === undefined ? undefined : readThemeFile(path, warn);
298
+ if (path !== undefined && file !== undefined)
299
+ files.push({ path, file });
300
+ }
301
+ let preset = "default";
302
+ if (chosen !== "" && !isPath(chosen)) {
303
+ preset = applyPreset(theme, chosen, warn, "KIT_THEME") ?? preset;
304
+ } else {
305
+ const named = files.findLast(({ file }) => file.preset !== undefined);
306
+ if (named !== undefined)
307
+ preset = applyPreset(theme, named.file.preset, warn, named.path) ?? preset;
308
+ }
309
+ for (const { path, file } of files) {
310
+ applyFile(theme, file, path, warn);
311
+ sources.push(path);
312
+ }
313
+ return { theme, sources, preset };
314
+ }
315
+ var current;
316
+ var currentKey = "";
317
+ function activeTheme() {
318
+ const key = `${process5.cwd()}\x00${process5.env.KIT_THEME ?? ""}\x00${process5.env.XDG_CONFIG_HOME ?? ""}`;
319
+ if (current === undefined || key !== currentKey) {
320
+ current = loadTheme();
321
+ currentKey = key;
322
+ }
323
+ return current;
324
+ }
129
325
 
130
326
  // ../kit/src/style.ts
131
- function takesControlCodes(stream, env = process4.env) {
327
+ function takesControlCodes(stream, env = process6.env) {
132
328
  return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
133
329
  }
134
- function paint(stream, env = process4.env) {
330
+ function paint(stream, env = process6.env) {
135
331
  return Fe({ stream: { isTTY: takesControlCodes(stream, env) }, env });
136
332
  }
333
+ function role(name, stream, env = process6.env) {
334
+ const colors = paint(stream, env);
335
+ return takesControlCodes(stream, env) ? tinted(colors, activeTheme().theme.colors[name], env) : colors;
336
+ }
137
337
  var STATUS_WORDS = {
138
338
  passed: ["passed", "success", "succeeded", "ok"],
139
339
  failed: ["failed", "failure", "error", "errored"],
@@ -151,27 +351,27 @@ function upTo(text, separator) {
151
351
  var ESCAPE = String.fromCharCode(27);
152
352
 
153
353
  // ../kit/src/help.ts
154
- import process5 from "process";
354
+ import process7 from "process";
155
355
  var OPTIONAL = /\[[^\]]+\]/g;
156
356
  var USAGE_PREFIX = /^usage:\s*/i;
157
357
  var FULL_STOP = /\.$/;
158
- function usageLine(usage, colors = paint(process5.stdout)) {
358
+ function usageLine(usage, colors = paint(process7.stdout)) {
159
359
  return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
160
360
  }
161
- function helpText(usage, options, colors = paint(process5.stdout), { examples = [], replaces, exits = [] } = {}) {
361
+ function helpText(usage, options, colors = paint(process7.stdout), { examples = [], replaces, exits = [] } = {}) {
162
362
  return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
163
363
  `);
164
364
  }
165
- function exitRows(exits, colors = paint(process5.stdout)) {
365
+ function exitRows(exits, colors = paint(process7.stdout)) {
166
366
  if (exits.length === 0)
167
367
  return [];
168
368
  const width = Math.max(...exits.map(([code]) => String(code).length));
169
369
  return ["", colors.bold("Exits:"), ...exits.map(([code, meaning]) => ` ${colors.cyan(String(code).padEnd(width))} ${meaning}`)];
170
370
  }
171
- function replacesRows(replaces, colors = paint(process5.stdout)) {
371
+ function replacesRows(replaces, colors = paint(process7.stdout)) {
172
372
  return replaces === undefined || outputMode() === "agent" ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
173
373
  }
174
- function wantsHelpJson(env = process5.env) {
374
+ function wantsHelpJson(env = process7.env) {
175
375
  return env.KIT_HELP === "json";
176
376
  }
177
377
  function description(usage, { examples = [], replaces, exits } = {}, options) {
@@ -190,12 +390,12 @@ function description(usage, { examples = [], replaces, exits } = {}, options) {
190
390
  ...options === undefined ? {} : { options: Object.entries(options).map(([name, { short, description }]) => ({ name, ...short === undefined ? {} : { short }, ...description === undefined ? {} : { description } })) }
191
391
  };
192
392
  }
193
- function exampleRows(examples, colors = paint(process5.stdout)) {
393
+ function exampleRows(examples, colors = paint(process7.stdout)) {
194
394
  if (examples.length === 0 || outputMode() === "agent")
195
395
  return [];
196
396
  return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
197
397
  }
198
- function optionRows(options, colors = paint(process5.stdout)) {
398
+ function optionRows(options, colors = paint(process7.stdout)) {
199
399
  const rows = Object.entries(options).map(([name, option]) => {
200
400
  const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
201
401
  const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
@@ -227,10 +427,10 @@ function closest(name, names) {
227
427
  return best !== undefined && best.far <= (name.length < 4 ? 1 : 2) ? best.known : undefined;
228
428
  }
229
429
  // ../kit/src/input.ts
230
- import process6 from "process";
430
+ import process8 from "process";
231
431
  async function readInput(path, { noStdin = "nothing is piped on stdin" } = {}) {
232
432
  if (path === "-") {
233
- if (process6.stdin.isTTY)
433
+ if (process8.stdin.isTTY)
234
434
  fail(noStdin);
235
435
  return Bun.stdin.text();
236
436
  }
@@ -288,7 +488,7 @@ var OUTPUT_OPTIONS = {
288
488
  color: { type: "string", description: "auto (on a terminal alone), always or never" },
289
489
  plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
290
490
  };
291
- function applyOutput(color, plain, env = process7.env) {
491
+ function applyOutput(color, plain, env = process9.env) {
292
492
  const when = plain === true ? "never" : color ?? "auto";
293
493
  if (when === "auto")
294
494
  return;
@@ -458,32 +658,32 @@ function nearestOption(message, options, allowNegative) {
458
658
  return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
459
659
  }
460
660
  // ../kit/src/argv.ts
461
- import { readFileSync as readFileSync2, realpathSync } from "fs";
462
- import { resolve } from "path";
463
- import process8 from "process";
661
+ import { readFileSync as readFileSync3, realpathSync } from "fs";
662
+ import { resolve as resolve3 } from "path";
663
+ import process10 from "process";
464
664
  function commandLine() {
465
665
  try {
466
- return readFileSync2("/proc/self/cmdline", "utf8").split("\x00").slice(0, -1);
666
+ return readFileSync3("/proc/self/cmdline", "utf8").split("\x00").slice(0, -1);
467
667
  } catch {
468
668
  return;
469
669
  }
470
670
  }
471
671
  function realPath(word) {
472
672
  try {
473
- return realpathSync(resolve(word));
673
+ return realpathSync(resolve3(word));
474
674
  } catch {
475
675
  return;
476
676
  }
477
677
  }
478
- function scriptArgs(argv = process8.argv.slice(2), cmdline = commandLine(), script = process8.argv[1]) {
678
+ function scriptArgs(argv = process10.argv.slice(2), cmdline = commandLine(), script = process10.argv[1]) {
479
679
  const target = script === undefined ? undefined : realPath(script) ?? script;
480
- const at = cmdline === undefined || target === undefined ? -1 : cmdline.findIndex((word, index) => index > 0 && (resolve(word) === script || realPath(word) === target));
680
+ const at = cmdline === undefined || target === undefined ? -1 : cmdline.findIndex((word, index) => index > 0 && (resolve3(word) === script || realPath(word) === target));
481
681
  const after = at === -1 ? [] : cmdline.slice(at + 1);
482
682
  return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
483
683
  }
484
684
  // ../kit/src/process.ts
485
685
  import { constants } from "os";
486
- import process9 from "process";
686
+ import process11 from "process";
487
687
  var KILL_GRACE_MS = 2000;
488
688
  function exitCodeOf(code, signal) {
489
689
  if (code !== null)
@@ -503,7 +703,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
503
703
  return;
504
704
  try {
505
705
  if (grouped)
506
- process9.kill(-proc.pid, killing);
706
+ process11.kill(-proc.pid, killing);
507
707
  else
508
708
  proc.kill(killing);
509
709
  } catch {}
@@ -577,15 +777,15 @@ var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x
577
777
  var RESET_STYLE = `${ESC}[0m`;
578
778
  var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
579
779
  // ../kit/src/cli.ts
580
- import { readFileSync as readFileSync3, realpathSync as realpathSync2 } from "fs";
581
- import { dirname as dirname2, join as join3 } from "path";
582
- import process11 from "process";
780
+ import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs";
781
+ import { dirname as dirname3, join as join5 } from "path";
782
+ import process13 from "process";
583
783
 
584
784
  // ../kit/src/usage.ts
585
785
  import { appendFileSync, mkdirSync } from "fs";
586
- import { homedir as homedir2 } from "os";
587
- import { dirname, isAbsolute, join as join2 } from "path";
588
- import process10 from "process";
786
+ import { homedir as homedir3 } from "os";
787
+ import { dirname as dirname2, isAbsolute, join as join4 } from "path";
788
+ import process12 from "process";
589
789
 
590
790
  // ../kit/src/logs.ts
591
791
  var DAY_MS = 24 * 60 * 60 * 1000;
@@ -599,14 +799,14 @@ var usageError;
599
799
  function noteUsageError(message) {
600
800
  usageError = message;
601
801
  }
602
- function stateHome(env = process10.env) {
802
+ function stateHome(env = process12.env) {
603
803
  const dir = env.XDG_STATE_HOME;
604
- return dir !== undefined && isAbsolute(dir) ? dir : join2(homedir2(), ".local", "state");
804
+ return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
605
805
  }
606
- function usagePath(env = process10.env) {
607
- return join2(stateHome(env), CLI_FOLDER, "usage.jsonl");
806
+ function usagePath(env = process12.env) {
807
+ return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
608
808
  }
609
- function usageRecorded(env = process10.env) {
809
+ function usageRecorded(env = process12.env) {
610
810
  const off = env.KAYNOOO_CLI_NO_USAGE;
611
811
  return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
612
812
  }
@@ -620,12 +820,12 @@ function usageEntry(bin, command, argv, code, now = new Date) {
620
820
  usageError = undefined;
621
821
  return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
622
822
  }
623
- function recordUsage(entry, env = process10.env) {
823
+ function recordUsage(entry, env = process12.env) {
624
824
  if (!usageRecorded(env))
625
825
  return;
626
826
  try {
627
827
  const path = usagePath(env);
628
- mkdirSync(dirname(path), { recursive: true, mode: 448 });
828
+ mkdirSync(dirname2(path), { recursive: true, mode: 448 });
629
829
  appendFileSync(path, `${JSON.stringify(entry)}
630
830
  `, { mode: 384 });
631
831
  } catch {}
@@ -711,8 +911,8 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
711
911
  `);
712
912
  }
713
913
  function printError(prefix, message, hint, cause) {
714
- const colors = paint(process11.stderr);
715
- const styled = takesControlCodes(process11.stderr);
914
+ const colors = paint(process13.stderr);
915
+ const styled = takesControlCodes(process13.stderr);
716
916
  const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
717
917
  const under = (label, text, tint) => text === undefined ? "" : `
718
918
  ${styled ? tint(label) : `${label}:`} ${text}`;
@@ -755,11 +955,11 @@ async function dispatch(level, typed, { version, redact }) {
755
955
  }
756
956
  }
757
957
  if (name === undefined && level.path.length > 1) {
758
- console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process11.stderr));
958
+ console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process13.stderr));
759
959
  return 2;
760
960
  }
761
961
  if (name === undefined || name === "help" || name === "--help" || name === "-h") {
762
- console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process11.stdout));
962
+ console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process13.stdout));
763
963
  return 0;
764
964
  }
765
965
  if (level.path.length === 1 && (name === "--version" || name === "-v")) {
@@ -876,13 +1076,17 @@ async function printCandidates(found) {
876
1076
  return 0;
877
1077
  }
878
1078
  function packageVersion(entry = Bun.main) {
879
- for (let dir = dirname2(realpathSync2(entry));; dir = dirname2(dir)) {
1079
+ let resolved = entry;
1080
+ try {
1081
+ resolved = realpathSync2(entry);
1082
+ } catch {}
1083
+ for (let dir = dirname3(resolved);; dir = dirname3(dir)) {
880
1084
  try {
881
- const { version } = JSON.parse(readFileSync3(join3(dir, "package.json"), "utf8"));
1085
+ const { version } = JSON.parse(readFileSync4(join5(dir, "package.json"), "utf8"));
882
1086
  if (typeof version === "string")
883
1087
  return version;
884
1088
  } catch {}
885
- if (dirname2(dir) === dir)
1089
+ if (dirname3(dir) === dir)
886
1090
  return "0.0.0";
887
1091
  }
888
1092
  }
@@ -2492,9 +2696,9 @@ function wrap(command) {
2492
2696
  }
2493
2697
 
2494
2698
  // ../pkg/src/added.ts
2495
- import { existsSync as existsSync2, readdirSync, readFileSync as readFileSync4 } from "fs";
2496
- import { dirname as dirname3, join as join4 } from "path";
2497
- import process13 from "process";
2699
+ import { existsSync as existsSync4, readdirSync, readFileSync as readFileSync5 } from "fs";
2700
+ import { dirname as dirname4, join as join6 } from "path";
2701
+ import process15 from "process";
2498
2702
  var REDIRECT2 = /^\d*[<>]/;
2499
2703
  var BARE_REDIRECT = /^\d*(?:[<>]|>>)$/;
2500
2704
  var ADDS = {
@@ -2518,7 +2722,7 @@ var PUBLISH = /\b(?:ft|cli\.ts)\s+release\b|\b(?:bun|npm|pnpm|yarn)\s+publish\b|
2518
2722
  var EXACT_SPEC = /^(?:@[^/]+\/)?[^@]+@\d+\.\d+\.\d+(?:[-+][\w.+-]+)?$/;
2519
2723
  function manifestName(folder) {
2520
2724
  try {
2521
- const { name } = JSON.parse(readFileSync4(join4(folder, "package.json"), "utf8"));
2725
+ const { name } = JSON.parse(readFileSync5(join6(folder, "package.json"), "utf8"));
2522
2726
  return typeof name === "string" ? name : undefined;
2523
2727
  } catch {
2524
2728
  return;
@@ -2526,19 +2730,19 @@ function manifestName(folder) {
2526
2730
  }
2527
2731
  function ownPackages() {
2528
2732
  const names = new Set;
2529
- let folder = process13.cwd();
2733
+ let folder = process15.cwd();
2530
2734
  while (true) {
2531
2735
  const name = manifestName(folder);
2532
2736
  if (name !== undefined)
2533
2737
  names.add(name);
2534
- for (const member of existsSync2(join4(folder, "packages")) ? readdirSync(join4(folder, "packages")) : []) {
2535
- const memberName = manifestName(join4(folder, "packages", member));
2738
+ for (const member of existsSync4(join6(folder, "packages")) ? readdirSync(join6(folder, "packages")) : []) {
2739
+ const memberName = manifestName(join6(folder, "packages", member));
2536
2740
  if (memberName !== undefined)
2537
2741
  names.add(memberName);
2538
2742
  }
2539
- if (existsSync2(join4(folder, ".git")) || dirname3(folder) === folder)
2743
+ if (existsSync4(join6(folder, ".git")) || dirname4(folder) === folder)
2540
2744
  return names;
2541
- folder = dirname3(folder);
2745
+ folder = dirname4(folder);
2542
2746
  }
2543
2747
  }
2544
2748
  function specName(spec) {
@@ -3806,15 +4010,15 @@ Exits 0 when it answered, 1 on a failure or an unknown event (never 2, which wou
3806
4010
  var MAX_READ = 1e6;
3807
4011
  function readText(path) {
3808
4012
  try {
3809
- const stats = statSync(path, { throwIfNoEntry: false });
3810
- return stats?.isFile() === true && stats.size <= MAX_READ ? readFileSync5(path, "utf8") : null;
4013
+ const stats = statSync2(path, { throwIfNoEntry: false });
4014
+ return stats?.isFile() === true && stats.size <= MAX_READ ? readFileSync6(path, "utf8") : null;
3811
4015
  } catch {
3812
4016
  return null;
3813
4017
  }
3814
4018
  }
3815
4019
  function report2(violations) {
3816
4020
  for (const { rule, message } of violations)
3817
- console.log(`${rule}: ${message}`);
4021
+ console.log(`${role("problem", process16.stdout)(rule)}: ${message}`);
3818
4022
  }
3819
4023
  async function check(args) {
3820
4024
  const parsed = parse(args, checkUsage, checkOptions);
@@ -3826,14 +4030,14 @@ ${checkUsage}`);
3826
4030
  const given = positionals[0] ?? "-";
3827
4031
  const command = given === "-" ? await readInput("-", { noStdin: "give the command, or pipe it on stdin" }) : given;
3828
4032
  const context = {
3829
- cwd: values.cwd ?? process14.cwd(),
3830
- home: homedir3(),
4033
+ cwd: values.cwd ?? process16.cwd(),
4034
+ home: homedir4(),
3831
4035
  isPushAsked: values["push-asked"] === true,
3832
4036
  canRewrite: true,
3833
4037
  canWrap: values["no-wrap"] !== true && Bun.which("out") !== null,
3834
4038
  canSub: Bun.which("sub") !== null,
3835
4039
  read: readText,
3836
- exists: existsSync3
4040
+ exists: existsSync5
3837
4041
  };
3838
4042
  const verdict = await checkCommand(command, context);
3839
4043
  if (values.json === true)
@@ -3841,7 +4045,7 @@ ${checkUsage}`);
3841
4045
  else
3842
4046
  report2(verdict.violations);
3843
4047
  if (values.json !== true && verdict.command !== command)
3844
- console.log(`runs as: ${verdict.command}${verdict.notes.map((note) => `
4048
+ console.log(`${role("label", process16.stdout)("runs as:")} ${verdict.command}${verdict.notes.map((note) => `
3845
4049
  ${note}`).join("")}`);
3846
4050
  return verdict.violations.length > 0 ? 1 : 0;
3847
4051
  }
@@ -3873,12 +4077,12 @@ function rules(args) {
3873
4077
  return 0;
3874
4078
  }
3875
4079
  for (const rule of RULES2)
3876
- console.log(`${rule.name.padEnd(16)} ${rule.refuses}
4080
+ console.log(`${role("id", process16.stdout)(rule.name)}${" ".repeat(Math.max(0, 16 - rule.name.length))} ${rule.refuses}
3877
4081
  ${" ".repeat(16)} -> ${rule.route}${rule.runs === "hook" ? " (hook only)" : ""}`);
3878
4082
  return 0;
3879
4083
  }
3880
4084
  function machine() {
3881
- const home = homedir3();
4085
+ const home = homedir4();
3882
4086
  const stateDir = `${stateHome()}/guard`;
3883
4087
  return {
3884
4088
  home,
@@ -3886,9 +4090,9 @@ function machine() {
3886
4090
  has: (bin) => Bun.which(bin) !== null,
3887
4091
  run: async (argv, cwd) => runCommand(argv, { cwd }),
3888
4092
  read: readText,
3889
- exists: existsSync3,
4093
+ exists: existsSync5,
3890
4094
  write: (path, text) => {
3891
- mkdirSync2(dirname4(path), { recursive: true });
4095
+ mkdirSync2(dirname5(path), { recursive: true });
3892
4096
  writeFileSync(path, text);
3893
4097
  },
3894
4098
  remove: (path) => rmSync(path, { force: true }),
@@ -3912,7 +4116,7 @@ ${hookUsage}`, 1);
3912
4116
  console.log(JSON.stringify(reply));
3913
4117
  return 0;
3914
4118
  }
3915
- process14.exitCode = await runCli({
4119
+ process16.exitCode = await runCli({
3916
4120
  name: "guard",
3917
4121
  usage: false,
3918
4122
  about: "the safety rules a Claude Code Bash call is held to, each refusal naming the route",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kaynooo/cli-guard",
3
3
  "type": "module",
4
- "version": "0.11.1",
4
+ "version": "0.12.0",
5
5
  "description": "guard: the safety rules a Claude Code Bash call is held to (git, remote machines, SQL writes, env files, package managers, commit messages), each refusal naming the route.",
6
6
  "author": "Kaynooo <contact@kaynooo.fr>",
7
7
  "license": "MIT",
@@ -37,11 +37,11 @@
37
37
  },
38
38
  "devDependencies": {
39
39
  "@kaynooo/cli-db": "0.12.1",
40
- "@kaynooo/cli-edit": "0.9.1",
40
+ "@kaynooo/cli-edit": "0.10.0",
41
41
  "@kaynooo/cli-env": "0.13.1",
42
- "@kaynooo/cli-git": "0.13.1",
43
- "@kaynooo/cli-kit": "0.38.1",
42
+ "@kaynooo/cli-git": "0.15.0",
43
+ "@kaynooo/cli-kit": "0.38.2",
44
44
  "@kaynooo/cli-out": "0.14.3",
45
- "@kaynooo/cli-pkg": "0.13.3"
45
+ "@kaynooo/cli-pkg": "0.14.0"
46
46
  }
47
47
  }