@kaynooo/cli-edit 0.7.0 → 0.9.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 +340 -313
  2. package/package.json +5 -2
package/dist/cli.js CHANGED
@@ -1,17 +1,39 @@
1
- #!/usr/bin/env -S bun --no-env-file
1
+ #!/usr/bin/env -S bun --no-env-file --config=/dev/null
2
2
  // @bun
3
3
 
4
4
  // src/cli.ts
5
- import { accessSync, chmodSync, constants, existsSync, readFileSync as readFileSync2, realpathSync as realpathSync2, renameSync, rmSync as rmSync2, statSync, writeFileSync as writeFileSync2 } from "fs";
6
- import { normalize, resolve } from "path";
7
- import process11 from "process";
5
+ import { accessSync, chmodSync, constants, existsSync as existsSync3, readFileSync as readFileSync3, realpathSync as realpathSync2, renameSync, rmSync as rmSync2, statSync as statSync2, writeFileSync as writeFileSync2 } from "fs";
6
+ import { normalize, resolve as resolve3 } from "path";
7
+ import process14 from "process";
8
8
  // ../kit/src/args.ts
9
- import process7 from "process";
9
+ import process10 from "process";
10
10
  import { parseArgs } from "util";
11
11
 
12
12
  // ../kit/src/format.ts
13
- import process4 from "process";
14
-
13
+ import process7 from "process";
14
+ // ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-rxztfxgv.js
15
+ var ct = /[aeiou]y$/;
16
+ var N = new Map;
17
+ var Ot = /(?:leaf|loaf|thief|wolf|half|calf|elf|sheaf|scarf|dwarf|hoof|wharf)$/;
18
+ var Gt = /(?:knife|life|wife)$/;
19
+ function K(t, e, { plural: r, zero: n = "singular" } = {}) {
20
+ if (e === 1 || e === 0 && n === "singular")
21
+ return t;
22
+ if (r !== undefined)
23
+ return r;
24
+ if (t.endsWith("y") && !ct.test(t))
25
+ return `${t.slice(0, -1)}ies`;
26
+ if (t.endsWith("s") || t.endsWith("x") || t.endsWith("z") || t.endsWith("ch") || t.endsWith("sh"))
27
+ return `${t}es`;
28
+ if (Ot.test(t))
29
+ return `${t.slice(0, -1)}ves`;
30
+ return Gt.test(t) ? `${t.slice(0, -2)}ves` : `${t}s`;
31
+ }
32
+ function go(t, e, { zero: r = "plural", ...n } = {}) {
33
+ return `${t} ${K(e, t, { ...n, zero: r })}`;
34
+ }
35
+ 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));
36
+ var z = new Map;
15
37
  // ../kit/src/mode.ts
16
38
  import process2 from "process";
17
39
  var MODES = new Set(["terminal", "ci", "agent", "pipe"]);
@@ -31,280 +53,287 @@ function outputMode(stream = process2.stdout, env = process2.env) {
31
53
  }
32
54
 
33
55
  // ../kit/src/style.ts
34
- import process3 from "process";
56
+ import process6 from "process";
35
57
 
36
- // ../../node_modules/.bun/@kaynooo+utils@2.31.2+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-mtetydvc.js
37
- function x(s) {
38
- let r = s.startsWith("#") ? s.slice(1).toLowerCase() : s.toLowerCase();
39
- if (!/^[a-f0-9]+$/.test(r))
58
+ // ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-x450vn3m.js
59
+ var G2 = /^[a-f0-9]+$/i;
60
+ function b(r) {
61
+ let e = r.startsWith("#") ? r.slice(1) : r;
62
+ if (!G2.test(e))
40
63
  return [0, 0, 0];
41
- let t = r.length, n = (c) => Number.parseInt(c, 16);
42
- if (t === 3 || t === 4) {
43
- let c = n(r[0] + r[0]), u = n(r[1] + r[1]), h = n(r[2] + r[2]), g = t === 4 ? n(r[3] + r[3]) : undefined;
44
- return g !== undefined ? [c, u, h, g] : [c, u, h];
45
- }
46
- if (t !== 6 && t !== 8)
47
- throw Error(`Invalid hex color length: ${t}`);
48
- let a = n(r.slice(0, 2)), b = n(r.slice(2, 4)), o = n(r.slice(4, 6)), y = t === 8 ? n(r.slice(6, 8)) : undefined;
49
- if ([a, b, o].some(Number.isNaN) || y !== undefined && Number.isNaN(y))
50
- throw Error(`Invalid hex color value: ${s}`);
51
- return y !== undefined ? [a, b, o, y] : [a, b, o];
52
- }
53
- function A(s) {
54
- let [r, t, n, a] = s;
55
- if (a)
56
- return `#${(r << 24 | t << 16 | n << 8 | Math.round((a ?? 1) * 255)).toString(16).padStart(8, "0").toUpperCase()}`;
57
- return `#${(r << 16 | t << 8 | n).toString(16).padStart(6, "0").toUpperCase()}`;
58
- }
59
- function R(s, r, t) {
60
- s = (s % 360 + 360) % 360, t /= 100;
61
- let n = r * Math.min(t, 1 - t) / 100, a = (b) => {
62
- let o = (b + s / 30) % 12, y = t - n * Math.max(Math.min(o - 3, 9 - o, 1), -1);
63
- return Math.round(255 * y);
64
- };
65
- return [a(0), a(8), a(4)];
66
- }
67
- function k(s) {
68
- let [r, t, n] = s;
69
- r /= 255, t /= 255, n /= 255;
70
- let a = Math.max(r, t, n), b = Math.min(r, t, n), o = 0, y = 0, c = (a + b) / 2;
71
- if (a !== b) {
72
- let u = a - b;
73
- if (y = c > 0 && c < 1 ? u / (1 - Math.abs(2 * c - 1)) : 0, a === r)
74
- o = (t - n) / u + (t < n ? 6 : 0);
75
- else if (a === t)
76
- o = (n - r) / u + 2;
77
- else
78
- o = (r - t) / u + 4;
79
- o /= 6;
80
- }
81
- return [Math.round(o * 360), Math.round(y * 100), Math.round(c * 100)];
82
- }
83
- function H(s, r, t) {
84
- s = (s % 360 + 360) % 360, r /= 100, t /= 100;
85
- let n = (a) => {
86
- let b = (a + s / 60) % 6, o = t - t * r * Math.max(Math.min(b, 4 - b, 1), 0);
87
- return Math.round(255 * o);
88
- };
89
- return [n(5), n(3), n(1)];
90
- }
91
- function f(s) {
92
- let [r, t, n] = s;
93
- r /= 255, t /= 255, n /= 255;
94
- let a = Math.max(r, t, n), b = Math.min(r, t, n), o = a - b, y = 0, c = a === 0 ? 0 : o / a, u = a;
95
- if (o !== 0) {
96
- if (a === r)
97
- y = (t - n) / o + (t < n ? 6 : 0);
98
- else if (a === t)
99
- y = (n - r) / o + 2;
100
- else
101
- y = (r - t) / o + 4;
102
- y /= 6;
103
- }
104
- return [Math.round(y * 360), Math.round(c * 100), Math.round(u * 100)];
105
- }
106
- function O(s) {
107
- let r = s[0] / 255, t = s[1] / 255, n = s[2] / 255, a = 1 - Math.max(r, t, n);
108
- if (a === 1)
109
- return [0, 0, 0, 100];
110
- let b = (1 - r - a) / (1 - a), o = (1 - t - a) / (1 - a), y = (1 - n - a) / (1 - a);
111
- return [Math.round(b * 100), Math.round(o * 100), Math.round(y * 100), Math.round(a * 100)];
112
- }
113
- function v(s, r, t, n) {
114
- return s /= 100, r /= 100, t /= 100, n /= 100, [Math.round(255 * (1 - s) * (1 - n)), Math.round(255 * (1 - r) * (1 - n)), Math.round(255 * (1 - t) * (1 - n))];
115
- }
116
- var m = (s) => s <= 0.04045 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4;
117
- var p = (s) => s <= 0.0031308 ? 12.92 * s : 1.055 * s ** 0.4166666666666667 - 0.055;
118
- var i = (s, r) => Math.round(s * 10 ** r) / 10 ** r;
119
- function T(s) {
120
- let r = m(s[0] / 255), t = m(s[1] / 255), n = m(s[2] / 255), a = Math.cbrt(0.4122214708 * r + 0.5363325363 * t + 0.0514459929 * n), b = Math.cbrt(0.2119034982 * r + 0.6806995451 * t + 0.1073969566 * n), o = Math.cbrt(0.0883024619 * r + 0.2817188376 * t + 0.6299787005 * n);
121
- return [i(0.2104542553 * a + 0.793617785 * b - 0.0040720468 * o, 4), i(1.9779984951 * a - 2.428592205 * b + 0.4505937099 * o, 4), i(0.0259040371 * a + 0.7827717662 * b - 0.808675766 * o, 4)];
64
+ if (e.length === 3 || e.length === 4)
65
+ return [Number.parseInt(e[0] + e[0], 16), Number.parseInt(e[1] + e[1], 16), Number.parseInt(e[2] + e[2], 16)];
66
+ if (e.length !== 6 && e.length !== 8)
67
+ throw Error(`Invalid hex color length: ${e.length}`);
68
+ return [Number.parseInt(e.slice(0, 2), 16), Number.parseInt(e.slice(2, 4), 16), Number.parseInt(e.slice(4, 6), 16)];
69
+ }
70
+ 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") => {
71
+ let [l, n, c] = b(r);
72
+ return [`${e === "fg" ? 38 : 48};2;${l};${n};${c}`, e === "fg" ? 39 : 49];
73
+ }, ansi256: (r, e = "fg") => [`${e === "fg" ? 38 : 48};5;${r}`, e === "fg" ? 39 : 49] };
74
+ var h = new Set(["", "1", "2", "3", "true"]);
75
+ function C(r, e = globalThis.process?.env ?? {}) {
76
+ if (e.FORCE_COLOR !== undefined)
77
+ return h.has(e.FORCE_COLOR);
78
+ if (e.NO_COLOR !== undefined || e.NODE_DISABLE_COLORS !== undefined || e.TERM === "dumb")
79
+ return false;
80
+ return r?.isTTY === true;
81
+ }
82
+ function f2(r, e = []) {
83
+ let l = "", n = "";
84
+ for (let t = 0, i = e.length;t < i; t++)
85
+ l += `\x1B[${e[t][0]}m`, n = `\x1B[${e[t][1]}m${n}`;
86
+ let c = (t) => C(r.stream ?? globalThis.process?.stdout, r.env) ? l + t + n : t, g = new Map;
87
+ return new Proxy(c, { get(t, i) {
88
+ let a = B2[i];
89
+ if (Array.isArray(a)) {
90
+ let s = g.get(i);
91
+ if (s === undefined)
92
+ s = f2(r, [...e, a]), g.set(i, s);
93
+ return s;
94
+ }
95
+ if (typeof a === "function")
96
+ return (...s) => {
97
+ let y = `${i}:${s.join(",")}`, u = g.get(y);
98
+ if (u === undefined) {
99
+ if (g.size >= 64)
100
+ g.clear();
101
+ u = f2(r, [...e, a(...s)]), g.set(y, u);
102
+ }
103
+ return u;
104
+ };
105
+ throw Error(`Unknown style: ${String(i)}`);
106
+ } });
122
107
  }
123
- function M(s, r, t) {
124
- let n = (s + 0.3963377774 * r + 0.2158037573 * t) ** 3, a = (s - 0.1055613458 * r - 0.0638541728 * t) ** 3, b = (s - 0.0894841775 * r - 1.291485548 * t) ** 3, o = p(4.0767416621 * n - 3.3077115913 * a + 0.2309699292 * b), y = p(-1.2684380046 * n + 2.6097574011 * a - 0.3413193965 * b), c = p(-0.0041960863 * n - 0.7034186147 * a + 1.707614701 * b), u = (h) => Math.min(255, Math.max(0, Math.round(h * 255)));
125
- return [u(o), u(y), u(c)];
108
+ function Fe2(r = {}) {
109
+ return f2(r);
126
110
  }
127
- function d(s) {
128
- let [r, t, n] = T(s), a = Math.sqrt(t * t + n * n), b = (Math.atan2(n, t) * 180 / Math.PI + 360) % 360;
129
- return [i(r, 4), i(a, 4), i(b, 2)];
111
+ var o2 = Fe2();
112
+
113
+ // ../kit/src/theme.ts
114
+ import { existsSync as existsSync2, readFileSync, statSync } from "fs";
115
+ import { homedir as homedir2 } from "os";
116
+ import { join as join3, resolve as resolve2 } from "path";
117
+ import process5 from "process";
118
+
119
+ // ../kit/src/config.ts
120
+ import { existsSync } from "fs";
121
+ import { dirname, join, resolve } from "path";
122
+ import process3 from "process";
123
+ function findUp(names, from = process3.cwd(), stop = () => false) {
124
+ const wanted = typeof names === "string" ? [names] : names;
125
+ for (let dir = resolve(from);; dir = dirname(dir)) {
126
+ const found = wanted.map((name) => join(dir, name)).find((path) => existsSync(path));
127
+ if (found !== undefined)
128
+ return found;
129
+ if (stop(dir) || dirname(dir) === dir)
130
+ return;
131
+ }
130
132
  }
131
- function C(s, r, t) {
132
- let n = t * Math.PI / 180;
133
- return M(s, r * Math.cos(n), r * Math.sin(n));
133
+
134
+ // ../kit/src/user-config.ts
135
+ import { homedir } from "os";
136
+ import { join as join2 } from "path";
137
+ import process4 from "process";
138
+ function configBase(where = {}) {
139
+ const xdg = where.xdg ?? (where.home === undefined ? process4.env.XDG_CONFIG_HOME : undefined);
140
+ return xdg !== undefined && xdg !== "" ? xdg : join2(where.home ?? homedir(), ".config");
134
141
  }
135
- function l(s) {
136
- let r = s / 255;
137
- return r <= 0.03928 ? r / 12.92 : ((r + 0.055) / 1.055) ** 2.4;
142
+ function userConfigPath(bin, where = {}) {
143
+ return join2(configBase(where), "kaynooo-cli", `${bin}.json`);
138
144
  }
139
145
 
140
- class e {
141
- r;
142
- g;
143
- b;
144
- a;
145
- constructor(s, r, t, n = 1) {
146
- this.r = s, this.g = r, this.b = t, this.a = n;
147
- }
148
- static from(s, r) {
149
- if (s === "hex") {
150
- let [t, n, a, b] = x(r);
151
- return new e(t, n, a, b);
152
- }
153
- if (s === "rgb") {
154
- if (Array.isArray(r)) {
155
- let [o, y, c, u] = r;
156
- return new e(o, y, c, u);
157
- }
158
- let { r: t, g: n, b: a, a: b } = r;
159
- return new e(t, n, a, b);
160
- }
161
- if (s === "hsl") {
162
- let t, n, a, b;
163
- if (Array.isArray(r))
164
- [t, n, a, b] = r;
165
- else
166
- ({ h: t, s: n, l: a, a: b } = r);
167
- let [o, y, c] = R(t, n, a);
168
- return new e(o, y, c, b);
169
- }
170
- if (s === "hsv") {
171
- let t, n, a, b;
172
- if (Array.isArray(r))
173
- [t, n, a, b] = r;
174
- else
175
- ({ h: t, s: n, v: a, a: b } = r);
176
- let [o, y, c] = H(t, n, a);
177
- return new e(o, y, c, b);
178
- }
179
- if (s === "cmyk") {
180
- let t, n, a, b, o;
181
- if (Array.isArray(r))
182
- [t, n, a, b, o] = r;
183
- else
184
- ({ c: t, m: n, y: a, k: b, a: o } = r);
185
- let [y, c, u] = v(t, n, a, b);
186
- return new e(y, c, u, o);
146
+ // ../kit/src/theme.ts
147
+ var ENDS = new Map;
148
+ var DEFAULT = {
149
+ 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" },
150
+ 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" },
151
+ accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
152
+ bins: {},
153
+ gradient: ["#c084fc", "#67e8f9"]
154
+ };
155
+ 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" };
156
+ 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" };
157
+ var ASCII = { ok: "+", warn: "!", problem: "x", note: ">", plan: "?", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+", open: "*", leaf: "-", guide: "|" };
158
+ var PRESETS = {
159
+ default: {},
160
+ "high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"], gradient: ["#d8b4fe", "#a5f3fc"] },
161
+ mono: { colors: MONO, accents: ["bold"], gradient: undefined },
162
+ ascii: { glyphs: ASCII }
163
+ };
164
+ 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"]);
165
+ var HEX = /^#[0-9a-f]{6}$/i;
166
+ var CONTROL = /\p{Cc}/u;
167
+ var MAX_FILE_BYTES = 64 * 1024;
168
+ var SPACES = /\s+/;
169
+ function isColorSpec(spec) {
170
+ if (typeof spec === "number")
171
+ return Number.isInteger(spec) && spec >= 0 && spec <= 255;
172
+ return typeof spec === "string" && spec.trim() !== "" && spec.trim().split(SPACES).every((token) => STYLES.has(token) || HEX.test(token));
173
+ }
174
+ var CUBE = [0, 95, 135, 175, 215, 255];
175
+ function cubeLevel(channel) {
176
+ return CUBE.reduce((best, value, level) => Math.abs(value - channel) < Math.abs(CUBE[best] - channel) ? level : best, 0);
177
+ }
178
+ function nearest256(hex) {
179
+ const rgb = [1, 3, 5].map((at) => Number.parseInt(hex.slice(at, at + 2), 16));
180
+ const levels = rgb.map(cubeLevel);
181
+ const cube = levels.map((level) => CUBE[level]);
182
+ const grey = Math.min(23, Math.max(0, Math.round((rgb.reduce((sum, channel) => sum + channel, 0) / 3 - 8) / 10)));
183
+ const greyValue = 8 + grey * 10;
184
+ const distance = (colour) => colour.reduce((sum, channel, at) => sum + (channel - rgb[at]) ** 2, 0);
185
+ return distance([greyValue, greyValue, greyValue]) < distance(cube) ? 232 + grey : 16 + 36 * levels[0] + 6 * levels[1] + levels[2];
186
+ }
187
+ function hasTrueColor(env) {
188
+ return env.COLORTERM === "truecolor" || env.COLORTERM === "24bit";
189
+ }
190
+ function tinted(colors, spec, env = process5.env) {
191
+ if (typeof spec === "number")
192
+ return colors.ansi256(spec);
193
+ return spec.trim().split(SPACES).reduce((chain, token) => {
194
+ if (HEX.test(token))
195
+ return hasTrueColor(env) ? chain.hex(token) : chain.ansi256(nearest256(token));
196
+ return chain[token] ?? chain;
197
+ }, colors);
198
+ }
199
+ function isRecord(value) {
200
+ return typeof value === "object" && value !== null && !Array.isArray(value);
201
+ }
202
+ function readThemeFile(path, warn) {
203
+ try {
204
+ const stat = statSync(path, { throwIfNoEntry: false });
205
+ if (stat === undefined)
206
+ return;
207
+ if (!stat.isFile() || stat.size > MAX_FILE_BYTES) {
208
+ warn(`${path} is not a regular file under ${MAX_FILE_BYTES / 1024} KiB, theme ignored`);
209
+ return;
187
210
  }
188
- if (s === "oklch") {
189
- let t, n, a, b;
190
- if (Array.isArray(r))
191
- [t, n, a, b] = r;
211
+ const parsed = JSON.parse(readFileSync(path, "utf8"));
212
+ if (isRecord(parsed))
213
+ return parsed;
214
+ warn(`${path} is not a JSON object, theme ignored`);
215
+ } catch (error) {
216
+ warn(`${path} does not parse (${error instanceof Error ? error.message : String(error)}), theme ignored`);
217
+ }
218
+ return;
219
+ }
220
+ function applyPreset(theme, name, warn, where) {
221
+ if (name === undefined)
222
+ return;
223
+ if (typeof name !== "string" || !Object.hasOwn(PRESETS, name)) {
224
+ warn(`${where}: no preset ${String(name)}, one of ${Object.keys(PRESETS).join(", ")}`);
225
+ return;
226
+ }
227
+ const preset = PRESETS[name];
228
+ Object.assign(theme.colors, preset.colors);
229
+ Object.assign(theme.glyphs, preset.glyphs);
230
+ if (preset.accents !== undefined)
231
+ theme.accents = [...preset.accents];
232
+ if (Object.hasOwn(preset, "gradient"))
233
+ theme.gradient = preset.gradient;
234
+ return name;
235
+ }
236
+ function applyFile(theme, file, where, warn) {
237
+ if (isRecord(file.colors)) {
238
+ for (const [key, value] of Object.entries(file.colors)) {
239
+ if (!Object.hasOwn(DEFAULT.colors, key))
240
+ warn(`${where}: no colour ${key}, one of ${Object.keys(DEFAULT.colors).join(", ")}`);
241
+ else if (!isColorSpec(value))
242
+ warn(`${where}: colour ${key} is not an ANSI name, \`#rrggbb\` or a number up to 255`);
192
243
  else
193
- ({ l: t, c: n, h: a, a: b } = r);
194
- let [o, y, c] = C(t, n, a);
195
- return new e(o, y, c, b);
244
+ theme.colors[key] = value;
196
245
  }
197
- if (s === "oklab") {
198
- let t, n, a, b;
199
- if (Array.isArray(r))
200
- [t, n, a, b] = r;
246
+ }
247
+ if (isRecord(file.glyphs)) {
248
+ for (const [key, value] of Object.entries(file.glyphs)) {
249
+ if (!Object.hasOwn(DEFAULT.glyphs, key))
250
+ warn(`${where}: no glyph ${key}, one of ${Object.keys(DEFAULT.glyphs).join(", ")}`);
251
+ else if (typeof value !== "string" || CONTROL.test(value) || Bun.stringWidth(value) !== 1)
252
+ warn(`${where}: glyph ${key} must be one visible character wide, with no control character`);
201
253
  else
202
- ({ l: t, a: n, b: a, alpha: b } = r);
203
- let [o, y, c] = M(t, n, a);
204
- return new e(o, y, c, b);
254
+ theme.glyphs[key] = value;
205
255
  }
206
- throw Error("Invalid input");
207
256
  }
208
- to(s) {
209
- switch (s) {
210
- case "rgb":
211
- return [this.r, this.g, this.b];
212
- case "rgba":
213
- return [this.r, this.g, this.b, this.a];
214
- case "hex":
215
- return A([this.r, this.g, this.b]);
216
- case "hexa":
217
- return A([this.r, this.g, this.b, this.a]);
218
- case "hsl":
219
- return k([this.r, this.g, this.b]);
220
- case "hsla":
221
- return [...k([this.r, this.g, this.b]), this.a];
222
- case "hsv":
223
- return f([this.r, this.g, this.b]);
224
- case "hsva":
225
- return [...f([this.r, this.g, this.b]), this.a];
226
- case "cmyk":
227
- return O([this.r, this.g, this.b]);
228
- case "cmyka":
229
- return [...O([this.r, this.g, this.b]), this.a];
230
- case "oklch":
231
- return d([this.r, this.g, this.b]);
232
- case "oklcha":
233
- return [...d([this.r, this.g, this.b]), this.a];
234
- case "oklab":
235
- return T([this.r, this.g, this.b]);
236
- case "oklaba":
237
- return [...T([this.r, this.g, this.b]), this.a];
238
- default:
239
- return [this.r, this.g, this.b];
257
+ if (Array.isArray(file.accents) && file.accents.length > 0 && file.accents.every(isColorSpec))
258
+ theme.accents = [...file.accents];
259
+ else if (file.accents !== undefined)
260
+ warn(`${where}: accents must be a non-empty list of colours`);
261
+ if (file.gradient === null)
262
+ theme.gradient = undefined;
263
+ else if (Array.isArray(file.gradient) && file.gradient.length === 2 && file.gradient.every((end) => typeof end === "string" && HEX.test(end)))
264
+ theme.gradient = [file.gradient[0], file.gradient[1]];
265
+ else if (file.gradient !== undefined)
266
+ warn(`${where}: gradient must be two \`#rrggbb\` colours, or null for none`);
267
+ if (isRecord(file.bins)) {
268
+ for (const [bin, value] of Object.entries(file.bins)) {
269
+ if (isColorSpec(value))
270
+ theme.bins[bin] = value;
271
+ else
272
+ warn(`${where}: bin ${bin} has no valid colour`);
240
273
  }
241
274
  }
242
- getLuminance() {
243
- let s = l(this.r), r = l(this.g), t = l(this.b);
244
- return 0.2126 * s + 0.7152 * r + 0.0722 * t;
275
+ }
276
+ function endsWalk(home) {
277
+ return (dir) => dir === resolve2(home) || existsSync2(join3(dir, ".git"));
278
+ }
279
+ var warned = new Set;
280
+ function warnOnce(message) {
281
+ if (warned.has(message))
282
+ return;
283
+ warned.add(message);
284
+ console.error(`warning: theme ${message}`);
285
+ }
286
+ function isPath(chosen) {
287
+ return chosen.includes("/") || chosen.endsWith(".json");
288
+ }
289
+ function loadTheme({ env = process5.env, from = process5.cwd(), home = homedir2(), warn = warnOnce } = {}) {
290
+ const theme = { colors: { ...DEFAULT.colors }, glyphs: { ...DEFAULT.glyphs }, accents: [...DEFAULT.accents], bins: Object.create(null), gradient: DEFAULT.gradient };
291
+ const sources = [];
292
+ const chosen = env.KIT_THEME ?? "";
293
+ const wanted = chosen === "" ? [userConfigPath("theme", { home, xdg: env.XDG_CONFIG_HOME }), findUp(join3(".kaynooo", "theme.json"), from, endsWalk(home))] : [];
294
+ if (isPath(chosen))
295
+ wanted.push(resolve2(from, chosen));
296
+ const files = [];
297
+ for (const path of wanted) {
298
+ const file = path === undefined ? undefined : readThemeFile(path, warn);
299
+ if (path !== undefined && file !== undefined)
300
+ files.push({ path, file });
245
301
  }
246
- contrastRatio(s) {
247
- let r = this.getLuminance(), t = s.getLuminance(), [n, a] = r >= t ? [r, t] : [t, r];
248
- return (n + 0.05) / (a + 0.05);
302
+ let preset = "default";
303
+ if (chosen !== "" && !isPath(chosen)) {
304
+ preset = applyPreset(theme, chosen, warn, "KIT_THEME") ?? preset;
305
+ } else {
306
+ const named = files.findLast(({ file }) => file.preset !== undefined);
307
+ if (named !== undefined)
308
+ preset = applyPreset(theme, named.file.preset, warn, named.path) ?? preset;
249
309
  }
250
- bestContrastForeground() {
251
- let s = new e(255, 255, 255, 1), r = new e(0, 0, 0, 1), t = this.contrastRatio(s), n = this.contrastRatio(r);
252
- return t >= n ? s : r;
310
+ for (const { path, file } of files) {
311
+ applyFile(theme, file, path, warn);
312
+ sources.push(path);
253
313
  }
254
- }
255
-
256
- // ../../node_modules/.bun/@kaynooo+utils@2.31.2+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-y1msbssb.js
257
- var r = 39;
258
- var o = 49;
259
- var f2 = "\x1B[";
260
- var C2 = { 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, r], red: [31, r], green: [32, r], yellow: [33, r], blue: [34, r], magenta: [35, r], cyan: [36, r], white: [37, r], gray: [90, r], grey: [90, r], blackBright: [90, r], redBright: [91, r], greenBright: [92, r], yellowBright: [93, r], blueBright: [94, r], magentaBright: [95, r], cyanBright: [96, r], whiteBright: [97, r], bgBlack: [40, o], bgRed: [41, o], bgGreen: [42, o], bgYellow: [43, o], bgBlue: [44, o], bgMagenta: [45, o], bgCyan: [46, o], bgWhite: [47, o], bgBlackBright: [100, o], bgRedBright: [101, o], bgGreenBright: [102, o], bgYellowBright: [103, o], bgBlueBright: [104, o], bgMagentaBright: [105, o], bgCyanBright: [106, o], bgWhiteBright: [107, o], rgb: (i, n, a, l = "fg") => [`${l === "fg" ? 38 : 48};2;${i};${n};${a}`, l === "fg" ? r : o], hex: (i, n = "fg") => {
261
- let [a, l, s] = e.from("hex", i).to("rgb");
262
- return [`${n === "fg" ? 38 : 48};2;${a};${l};${s}`, n === "fg" ? r : o];
263
- }, ansi256: (i, n = "fg") => [`${n === "fg" ? 38 : 48};5;${i}`, n === "fg" ? r : o] };
264
- var b = new Set(["", "1", "2", "3", "true"]);
265
- function h(i, n = globalThis.process?.env ?? {}) {
266
- if (n.FORCE_COLOR !== undefined)
267
- return b.has(n.FORCE_COLOR);
268
- if (n.NO_COLOR !== undefined || n.NODE_DISABLE_COLORS !== undefined || n.TERM === "dumb")
269
- return false;
270
- return i?.isTTY === true;
271
- }
272
- function d2(i, n, a) {
273
- if (!h(a.stream ?? globalThis.process?.stdout, a.env))
274
- return n;
275
- let l = "", s = "";
276
- for (let g = 0, y = i.length;g < y; g++) {
277
- let [c, p] = i[g];
278
- l += `${f2}${c}m`, s = `${f2}${p}m${s}`;
314
+ return { theme, sources, preset };
315
+ }
316
+ var current;
317
+ var currentKey = "";
318
+ function activeTheme() {
319
+ const key = `${process5.cwd()}\x00${process5.env.KIT_THEME ?? ""}\x00${process5.env.XDG_CONFIG_HOME ?? ""}`;
320
+ if (current === undefined || key !== currentKey) {
321
+ current = loadTheme();
322
+ currentKey = key;
279
323
  }
280
- return l + n + s;
281
- }
282
- function u(i, n = []) {
283
- return new Proxy((l) => d2(n, l, i), { get(l, s) {
284
- let g = C2[s];
285
- if (Array.isArray(g))
286
- return u(i, [...n, g]);
287
- if (typeof g === "function")
288
- return (...y) => u(i, [...n, g(...y)]);
289
- throw Error(`Unknown style: ${String(s)}`);
290
- } });
291
- }
292
- function le(i = {}) {
293
- return u(i);
324
+ return current;
294
325
  }
295
- var t = le();
296
-
297
- // ../kit/src/theme.ts
298
- 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"]);
299
- var MAX_FILE_BYTES = 64 * 1024;
300
- var warned = new Set;
301
326
 
302
327
  // ../kit/src/style.ts
303
- function takesControlCodes(stream, env = process3.env) {
328
+ function takesControlCodes(stream, env = process6.env) {
304
329
  return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
305
330
  }
306
- function paint(stream, env = process3.env) {
307
- return le({ stream: { isTTY: takesControlCodes(stream, env) }, env });
331
+ function paint(stream, env = process6.env) {
332
+ return Fe2({ stream: { isTTY: takesControlCodes(stream, env) }, env });
333
+ }
334
+ function role(name, stream, env = process6.env) {
335
+ const colors = paint(stream, env);
336
+ return takesControlCodes(stream, env) ? tinted(colors, activeTheme().theme.colors[name], env) : colors;
308
337
  }
309
338
  var STATUS_WORDS = {
310
339
  passed: ["passed", "success", "succeeded", "ok"],
@@ -321,7 +350,7 @@ function upTo(text, separator) {
321
350
  return end === -1 ? text : text.slice(0, end);
322
351
  }
323
352
  var ESCAPE = String.fromCharCode(27);
324
- function jsonText(value, replacer, { stream = process4.stdout, env = process4.env } = {}) {
353
+ function jsonText(value, replacer, { stream = process7.stdout, env = process7.env } = {}) {
325
354
  return JSON.stringify(value, replacer, outputMode(stream, env) === "agent" ? undefined : 2);
326
355
  }
327
356
  function printJson(value) {
@@ -329,27 +358,27 @@ function printJson(value) {
329
358
  }
330
359
 
331
360
  // ../kit/src/help.ts
332
- import process5 from "process";
361
+ import process8 from "process";
333
362
  var OPTIONAL = /\[[^\]]+\]/g;
334
363
  var USAGE_PREFIX = /^usage:\s*/i;
335
364
  var FULL_STOP = /\.$/;
336
- function usageLine(usage, colors = paint(process5.stdout)) {
365
+ function usageLine(usage, colors = paint(process8.stdout)) {
337
366
  return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
338
367
  }
339
- function helpText(usage, options, colors = paint(process5.stdout), { examples = [], replaces, exits = [] } = {}) {
368
+ function helpText(usage, options, colors = paint(process8.stdout), { examples = [], replaces, exits = [] } = {}) {
340
369
  return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
341
370
  `);
342
371
  }
343
- function exitRows(exits, colors = paint(process5.stdout)) {
372
+ function exitRows(exits, colors = paint(process8.stdout)) {
344
373
  if (exits.length === 0)
345
374
  return [];
346
375
  const width = Math.max(...exits.map(([code]) => String(code).length));
347
376
  return ["", colors.bold("Exits:"), ...exits.map(([code, meaning]) => ` ${colors.cyan(String(code).padEnd(width))} ${meaning}`)];
348
377
  }
349
- function replacesRows(replaces, colors = paint(process5.stdout)) {
378
+ function replacesRows(replaces, colors = paint(process8.stdout)) {
350
379
  return replaces === undefined || outputMode() === "agent" ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
351
380
  }
352
- function wantsHelpJson(env = process5.env) {
381
+ function wantsHelpJson(env = process8.env) {
353
382
  return env.KIT_HELP === "json";
354
383
  }
355
384
  function description(usage, { examples = [], replaces, exits } = {}, options) {
@@ -368,12 +397,12 @@ function description(usage, { examples = [], replaces, exits } = {}, options) {
368
397
  ...options === undefined ? {} : { options: Object.entries(options).map(([name, { short, description }]) => ({ name, ...short === undefined ? {} : { short }, ...description === undefined ? {} : { description } })) }
369
398
  };
370
399
  }
371
- function exampleRows(examples, colors = paint(process5.stdout)) {
400
+ function exampleRows(examples, colors = paint(process8.stdout)) {
372
401
  if (examples.length === 0 || outputMode() === "agent")
373
402
  return [];
374
403
  return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
375
404
  }
376
- function optionRows(options, colors = paint(process5.stdout)) {
405
+ function optionRows(options, colors = paint(process8.stdout)) {
377
406
  const rows = Object.entries(options).map(([name, option]) => {
378
407
  const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
379
408
  const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
@@ -405,7 +434,7 @@ function closest(name, names) {
405
434
  return best !== undefined && best.far <= (name.length < 4 ? 1 : 2) ? best.known : undefined;
406
435
  }
407
436
  // ../kit/src/input.ts
408
- import process6 from "process";
437
+ import process9 from "process";
409
438
  var WHOLE = /^\d+$/;
410
439
  function wholeNumber(value, name, fallback, min = 1) {
411
440
  if (value === undefined)
@@ -417,7 +446,7 @@ function wholeNumber(value, name, fallback, min = 1) {
417
446
  }
418
447
  async function readInput(path, { noStdin = "nothing is piped on stdin" } = {}) {
419
448
  if (path === "-") {
420
- if (process6.stdin.isTTY)
449
+ if (process9.stdin.isTTY)
421
450
  fail(noStdin);
422
451
  return Bun.stdin.text();
423
452
  }
@@ -432,7 +461,6 @@ var DASHES = /^-+/;
432
461
  function jsonOption(holds) {
433
462
  return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
434
463
  }
435
-
436
464
  class Exit extends Error {
437
465
  code;
438
466
  hint;
@@ -476,7 +504,7 @@ var OUTPUT_OPTIONS = {
476
504
  color: { type: "string", description: "auto (on a terminal alone), always or never" },
477
505
  plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
478
506
  };
479
- function applyOutput(color, plain, env = process7.env) {
507
+ function applyOutput(color, plain, env = process10.env) {
480
508
  const when = plain === true ? "never" : color ?? "auto";
481
509
  if (when === "auto")
482
510
  return;
@@ -651,15 +679,15 @@ var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x
651
679
  var RESET_STYLE = `${ESC}[0m`;
652
680
  var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
653
681
  // ../kit/src/cli.ts
654
- import { readFileSync, realpathSync } from "fs";
655
- import { dirname as dirname2, join as join2 } from "path";
656
- import process9 from "process";
682
+ import { readFileSync as readFileSync2, realpathSync } from "fs";
683
+ import { dirname as dirname3, join as join5 } from "path";
684
+ import process12 from "process";
657
685
 
658
686
  // ../kit/src/usage.ts
659
687
  import { appendFileSync, mkdirSync } from "fs";
660
- import { homedir } from "os";
661
- import { dirname, isAbsolute, join } from "path";
662
- import process8 from "process";
688
+ import { homedir as homedir3 } from "os";
689
+ import { dirname as dirname2, isAbsolute, join as join4 } from "path";
690
+ import process11 from "process";
663
691
 
664
692
  // ../kit/src/logs.ts
665
693
  var DAY_MS = 24 * 60 * 60 * 1000;
@@ -673,14 +701,14 @@ var usageError;
673
701
  function noteUsageError(message) {
674
702
  usageError = message;
675
703
  }
676
- function stateHome(env = process8.env) {
704
+ function stateHome(env = process11.env) {
677
705
  const dir = env.XDG_STATE_HOME;
678
- return dir !== undefined && isAbsolute(dir) ? dir : join(homedir(), ".local", "state");
706
+ return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
679
707
  }
680
- function usagePath(env = process8.env) {
681
- return join(stateHome(env), CLI_FOLDER, "usage.jsonl");
708
+ function usagePath(env = process11.env) {
709
+ return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
682
710
  }
683
- function usageRecorded(env = process8.env) {
711
+ function usageRecorded(env = process11.env) {
684
712
  const off = env.KAYNOOO_CLI_NO_USAGE;
685
713
  return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
686
714
  }
@@ -694,12 +722,12 @@ function usageEntry(bin, command, argv, code, now = new Date) {
694
722
  usageError = undefined;
695
723
  return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
696
724
  }
697
- function recordUsage(entry, env = process8.env) {
725
+ function recordUsage(entry, env = process11.env) {
698
726
  if (!usageRecorded(env))
699
727
  return;
700
728
  try {
701
729
  const path = usagePath(env);
702
- mkdirSync(dirname(path), { recursive: true, mode: 448 });
730
+ mkdirSync(dirname2(path), { recursive: true, mode: 448 });
703
731
  appendFileSync(path, `${JSON.stringify(entry)}
704
732
  `, { mode: 384 });
705
733
  } catch {}
@@ -712,8 +740,8 @@ var LEVEL_OPTIONS = {
712
740
  };
713
741
  var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
714
742
  function printError(prefix, message, hint, cause) {
715
- const colors = paint(process9.stderr);
716
- const styled = takesControlCodes(process9.stderr);
743
+ const colors = paint(process12.stderr);
744
+ const styled = takesControlCodes(process12.stderr);
717
745
  const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
718
746
  const under = (label, text, tint) => text === undefined ? "" : `
719
747
  ${styled ? tint(label) : `${label}:`} ${text}`;
@@ -796,17 +824,17 @@ async function printCandidates(found) {
796
824
  return 0;
797
825
  }
798
826
  function packageVersion(entry = Bun.main) {
799
- for (let dir = dirname2(realpathSync(entry));; dir = dirname2(dir)) {
827
+ for (let dir = dirname3(realpathSync(entry));; dir = dirname3(dir)) {
800
828
  try {
801
- const { version } = JSON.parse(readFileSync(join2(dir, "package.json"), "utf8"));
829
+ const { version } = JSON.parse(readFileSync2(join5(dir, "package.json"), "utf8"));
802
830
  if (typeof version === "string")
803
831
  return version;
804
832
  } catch {}
805
- if (dirname2(dir) === dir)
833
+ if (dirname3(dir) === dir)
806
834
  return "0.0.0";
807
835
  }
808
836
  }
809
- async function runMain({ name, version, run, redact, usage }, argv = process9.argv.slice(2)) {
837
+ async function runMain({ name, version, run, redact, usage }, argv = process12.argv.slice(2)) {
810
838
  if (argv[0] === COMPLETE)
811
839
  return printCandidates(leafCandidates(run, argv.slice(1)));
812
840
  if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
@@ -826,6 +854,8 @@ async function runMain({ name, version, run, redact, usage }, argv = process9.ar
826
854
  }
827
855
  return code;
828
856
  }
857
+ // ../kit/src/folders.ts
858
+ var SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
829
859
  // ../kit/src/secrets.ts
830
860
  var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
831
861
  // ../kit/src/sessions.ts
@@ -887,15 +917,15 @@ function parseBlocks(text) {
887
917
  // src/diff.ts
888
918
  import { mkdtempSync, rmSync, writeFileSync } from "fs";
889
919
  import { tmpdir } from "os";
890
- import { join as join3 } from "path";
920
+ import { join as join6 } from "path";
891
921
  async function diffTexts(path, before, after) {
892
- const dir = mkdtempSync(join3(tmpdir(), "sub-"));
922
+ const dir = mkdtempSync(join6(tmpdir(), "sub-"));
893
923
  try {
894
- writeFileSync(join3(dir, "before"), before);
895
- writeFileSync(join3(dir, "after"), after);
924
+ writeFileSync(join6(dir, "before"), before);
925
+ writeFileSync(join6(dir, "after"), after);
896
926
  let child;
897
927
  try {
898
- child = Bun.spawn(["diff", "-u", "--label", `a/${path}`, "--label", `b/${path}`, join3(dir, "before"), join3(dir, "after")], { stdout: "pipe", stderr: "pipe" });
928
+ child = Bun.spawn(["diff", "-u", "--label", `a/${path}`, "--label", `b/${path}`, join6(dir, "before"), join6(dir, "after")], { stdout: "pipe", stderr: "pipe" });
899
929
  } catch {
900
930
  throw new Error("diff is not installed, which sub needs to show its changes");
901
931
  }
@@ -949,7 +979,7 @@ function firstLineHint(text, from) {
949
979
  return "";
950
980
  const lines = text.split(`
951
981
  `).flatMap((line, i) => line.includes(first) ? [i + 1] : []);
952
- return lines.length === 0 ? "" : ` (its first line is on line${lines.length > 1 ? "s" : ""} ${listLines(lines)})`;
982
+ return lines.length === 0 ? "" : ` (its first line is on ${K("line", lines.length)} ${listLines(lines)})`;
953
983
  }
954
984
  function compile(source) {
955
985
  return new RegExp(source, "gm");
@@ -984,7 +1014,7 @@ function applyPairs(original, pairs) {
984
1014
  let where = ` on lines ${listLines(found)}: add context to --from, or pass --count ${indexes.length} or --all`;
985
1015
  if (indexes.length === 0)
986
1016
  where = pattern === undefined ? firstLineHint(text, from) : "";
987
- problems.push(`${label}matched ${indexes.length} time${indexes.length === 1 ? "" : "s"}, expected ${wanted}${where}`);
1017
+ problems.push(`${label}matched ${go(indexes.length, "time")}, expected ${wanted}${where}`);
988
1018
  continue;
989
1019
  }
990
1020
  lines.push(...found);
@@ -1040,7 +1070,7 @@ function pairFrom(item, i, defaults) {
1040
1070
  const { from, to, count, all, regex, ...rest } = item;
1041
1071
  const unknown = Object.keys(rest);
1042
1072
  if (unknown.length > 0)
1043
- fail(`${label}unknown key${unknown.length === 1 ? "" : "s"} ${unknown.join(", ")}, known: ${PAIR_KEYS.join(", ")}`);
1073
+ fail(`${label}unknown ${K("key", unknown.length)} ${unknown.join(", ")}, known: ${PAIR_KEYS.join(", ")}`);
1044
1074
  if (typeof from !== "string" || typeof to !== "string")
1045
1075
  fail(`${label}from and to must both be strings`);
1046
1076
  if (count !== undefined && (typeof count !== "number" || !Number.isInteger(count) || count < 1))
@@ -1064,9 +1094,6 @@ async function readPairs(path, defaults) {
1064
1094
  fail("--pairs takes a JSON array of at least one {from, to}");
1065
1095
  return items.map((item, i) => pairFrom(item, i, defaults));
1066
1096
  }
1067
- function plural(count, word) {
1068
- return `${count} ${word}${count === 1 ? "" : "s"}`;
1069
- }
1070
1097
  function writable(path) {
1071
1098
  try {
1072
1099
  accessSync(path, constants.W_OK);
@@ -1078,7 +1105,7 @@ function writable(path) {
1078
1105
  var UTF8 = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
1079
1106
  function readUtf8(path) {
1080
1107
  try {
1081
- return UTF8.decode(readFileSync2(path));
1108
+ return UTF8.decode(readFileSync3(path));
1082
1109
  } catch {
1083
1110
  return;
1084
1111
  }
@@ -1087,7 +1114,7 @@ function canonical(path) {
1087
1114
  try {
1088
1115
  return realpathSync2(path);
1089
1116
  } catch {
1090
- return resolve(path);
1117
+ return resolve3(path);
1091
1118
  }
1092
1119
  }
1093
1120
  function dedupe(paths) {
@@ -1101,10 +1128,10 @@ function dedupe(paths) {
1101
1128
  }
1102
1129
  function writeAtomic(path, text) {
1103
1130
  const target = realpathSync2(path);
1104
- const temp = `${target}.sub-${process11.pid}`;
1131
+ const temp = `${target}.sub-${process14.pid}`;
1105
1132
  try {
1106
1133
  writeFileSync2(temp, text);
1107
- chmodSync(temp, (statSync(target, { throwIfNoEntry: false })?.mode ?? 420) & 4095);
1134
+ chmodSync(temp, (statSync2(target, { throwIfNoEntry: false })?.mode ?? 420) & 4095);
1108
1135
  renameSync(temp, target);
1109
1136
  } catch (error) {
1110
1137
  rmSync2(temp, { force: true });
@@ -1113,30 +1140,30 @@ function writeAtomic(path, text) {
1113
1140
  }
1114
1141
  var STDIN_SILENCE_MS = 3000;
1115
1142
  async function blocksOnStdin(files) {
1116
- const extra = files.slice(1).filter((path) => !existsSync(path));
1143
+ const extra = files.slice(1).filter((path) => !existsSync3(path));
1117
1144
  const strings = extra.length === 0 ? "" : `${extra.map((path) => `no file ${path}`).join(", ")}: with several strings on the command line use --from and --to, as in sub --from old --to new ${files[0]}
1118
1145
 
1119
1146
  `;
1120
1147
  const hint = `${strings}give --from and --to, or pipe SEARCH/REPLACE blocks on stdin from a heredoc
1121
1148
 
1122
1149
  ${USAGE}`;
1123
- if (process11.stdin.isTTY)
1150
+ if (process14.stdin.isTTY)
1124
1151
  fail(hint);
1125
1152
  return new Promise((resolve) => {
1126
1153
  const chunks = [];
1127
1154
  const timer = setTimeout(() => {
1128
1155
  console.error(`error: sub: ${hint}`);
1129
- process11.exit(2);
1156
+ process14.exit(2);
1130
1157
  }, STDIN_SILENCE_MS);
1131
- process11.stdin.on("data", (chunk) => {
1158
+ process14.stdin.on("data", (chunk) => {
1132
1159
  clearTimeout(timer);
1133
1160
  chunks.push(chunk);
1134
1161
  });
1135
- process11.stdin.on("end", () => {
1162
+ process14.stdin.on("end", () => {
1136
1163
  clearTimeout(timer);
1137
1164
  if (chunks.length === 0 && extra.length > 0) {
1138
1165
  console.error(`error: sub: ${hint}`);
1139
- process11.exit(2);
1166
+ process14.exit(2);
1140
1167
  }
1141
1168
  resolve(Buffer.concat(chunks).toString("utf8"));
1142
1169
  });
@@ -1199,7 +1226,7 @@ async function main(argv) {
1199
1226
  const changes = [];
1200
1227
  const problems = [];
1201
1228
  for (const [path, pairs] of edits) {
1202
- if (!existsSync(path)) {
1229
+ if (!existsSync3(path)) {
1203
1230
  problems.push({ path, problem: "no such file" });
1204
1231
  continue;
1205
1232
  }
@@ -1243,9 +1270,9 @@ ${error instanceof Error ? error.message : String(error)}`);
1243
1270
  continue;
1244
1271
  }
1245
1272
  if (values.quiet !== true)
1246
- console.log(`${path}: ${plural(lines.length, "replacement")} on line${lines.length === 1 ? "" : "s"} ${listLines(lines)}, +${diff.added} -${diff.removed}`);
1273
+ console.log(`${role("path", process14.stdout)(path)}: ${go(lines.length, "replacement")} on ${K("line", lines.length, { zero: "plural" })} ${listLines(lines)}, ${role(diff.added === 0 ? "label" : "ok", process14.stdout)(`+${diff.added}`)} ${role(diff.removed === 0 ? "label" : "problem", process14.stdout)(`-${diff.removed}`)}`);
1247
1274
  if (values.diff === true && diff.unified !== "")
1248
- process11.stdout.write(diff.unified);
1275
+ process14.stdout.write(diff.unified);
1249
1276
  }
1250
1277
  if (json)
1251
1278
  printJson({ dryRun: values["dry-run"] === true, files: done });
@@ -1253,4 +1280,4 @@ ${error instanceof Error ? error.message : String(error)}`);
1253
1280
  console.log("dry run: nothing written");
1254
1281
  return 0;
1255
1282
  }
1256
- process11.exitCode = await runMain({ name: "sub", run: main });
1283
+ process14.exitCode = await runMain({ name: "sub", run: main });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kaynooo/cli-edit",
3
3
  "type": "module",
4
- "version": "0.7.0",
4
+ "version": "0.9.0",
5
5
  "description": "sub: text replaced in files for Claude Code, written only when every replacement matches as often as expected.",
6
6
  "author": "Kaynooo <contact@kaynooo.fr>",
7
7
  "license": "MIT",
@@ -35,7 +35,10 @@
35
35
  "build": "$npm_execpath build src/cli.ts --target bun --outdir dist",
36
36
  "sub": "$npm_execpath src/cli.ts"
37
37
  },
38
+ "dependencies": {
39
+ "@kaynooo/utils": "3.0.0"
40
+ },
38
41
  "devDependencies": {
39
- "@kaynooo/cli-kit": "0.22.0"
42
+ "@kaynooo/cli-kit": "0.35.0"
40
43
  }
41
44
  }