@kaynooo/cli-stack 0.5.1 → 0.7.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 +374 -340
  2. package/package.json +2 -2
package/dist/cli.js CHANGED
@@ -1,303 +1,330 @@
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 process10 from "process";
5
+ import process15 from "process";
6
6
  // ../kit/src/args.ts
7
- import process4 from "process";
7
+ import process9 from "process";
8
8
  import { parseArgs } from "util";
9
9
 
10
- // ../kit/src/style.ts
10
+ // ../kit/src/format.ts
11
+ import process7 from "process";
12
+
13
+ // ../kit/src/mode.ts
11
14
  import process2 from "process";
15
+ var MODES = new Set(["terminal", "ci", "agent", "pipe"]);
16
+ var AGENT_VARIABLES = ["CLAUDECODE", "AI_AGENT"];
17
+ function isSet(value) {
18
+ return value !== undefined && value !== "" && value !== "0" && value.toLowerCase() !== "false";
19
+ }
20
+ function outputMode(stream = process2.stdout, env = process2.env) {
21
+ const chosen = env.KIT_MODE;
22
+ if (chosen !== undefined && MODES.has(chosen))
23
+ return chosen;
24
+ if (AGENT_VARIABLES.some((name) => isSet(env[name])))
25
+ return "agent";
26
+ if (stream.isTTY === true)
27
+ return "terminal";
28
+ return isSet(env.CI) ? "ci" : "pipe";
29
+ }
30
+
31
+ // ../kit/src/style.ts
32
+ import process6 from "process";
12
33
 
13
- // ../../node_modules/.bun/@kaynooo+utils@2.31.2+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-mtetydvc.js
14
- function x(s) {
15
- let r = s.startsWith("#") ? s.slice(1).toLowerCase() : s.toLowerCase();
16
- if (!/^[a-f0-9]+$/.test(r))
34
+ // ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-x450vn3m.js
35
+ var G = /^[a-f0-9]+$/i;
36
+ function b(r) {
37
+ let e = r.startsWith("#") ? r.slice(1) : r;
38
+ if (!G.test(e))
17
39
  return [0, 0, 0];
18
- let t = r.length, n = (c) => Number.parseInt(c, 16);
19
- if (t === 3 || t === 4) {
20
- 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;
21
- return g !== undefined ? [c, u, h, g] : [c, u, h];
22
- }
23
- if (t !== 6 && t !== 8)
24
- throw Error(`Invalid hex color length: ${t}`);
25
- 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;
26
- if ([a, b, o].some(Number.isNaN) || y !== undefined && Number.isNaN(y))
27
- throw Error(`Invalid hex color value: ${s}`);
28
- return y !== undefined ? [a, b, o, y] : [a, b, o];
29
- }
30
- function A(s) {
31
- let [r, t, n, a] = s;
32
- if (a)
33
- return `#${(r << 24 | t << 16 | n << 8 | Math.round((a ?? 1) * 255)).toString(16).padStart(8, "0").toUpperCase()}`;
34
- return `#${(r << 16 | t << 8 | n).toString(16).padStart(6, "0").toUpperCase()}`;
35
- }
36
- function R(s, r, t) {
37
- s = (s % 360 + 360) % 360, t /= 100;
38
- let n = r * Math.min(t, 1 - t) / 100, a = (b) => {
39
- let o = (b + s / 30) % 12, y = t - n * Math.max(Math.min(o - 3, 9 - o, 1), -1);
40
- return Math.round(255 * y);
41
- };
42
- return [a(0), a(8), a(4)];
43
- }
44
- function k(s) {
45
- let [r, t, n] = s;
46
- r /= 255, t /= 255, n /= 255;
47
- let a = Math.max(r, t, n), b = Math.min(r, t, n), o = 0, y = 0, c = (a + b) / 2;
48
- if (a !== b) {
49
- let u = a - b;
50
- if (y = c > 0 && c < 1 ? u / (1 - Math.abs(2 * c - 1)) : 0, a === r)
51
- o = (t - n) / u + (t < n ? 6 : 0);
52
- else if (a === t)
53
- o = (n - r) / u + 2;
54
- else
55
- o = (r - t) / u + 4;
56
- o /= 6;
57
- }
58
- return [Math.round(o * 360), Math.round(y * 100), Math.round(c * 100)];
59
- }
60
- function H(s, r, t) {
61
- s = (s % 360 + 360) % 360, r /= 100, t /= 100;
62
- let n = (a) => {
63
- let b = (a + s / 60) % 6, o = t - t * r * Math.max(Math.min(b, 4 - b, 1), 0);
64
- return Math.round(255 * o);
65
- };
66
- return [n(5), n(3), n(1)];
67
- }
68
- function f(s) {
69
- let [r, t, n] = s;
70
- r /= 255, t /= 255, n /= 255;
71
- 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;
72
- if (o !== 0) {
73
- if (a === r)
74
- y = (t - n) / o + (t < n ? 6 : 0);
75
- else if (a === t)
76
- y = (n - r) / o + 2;
77
- else
78
- y = (r - t) / o + 4;
79
- y /= 6;
80
- }
81
- return [Math.round(y * 360), Math.round(c * 100), Math.round(u * 100)];
82
- }
83
- function O(s) {
84
- let r = s[0] / 255, t = s[1] / 255, n = s[2] / 255, a = 1 - Math.max(r, t, n);
85
- if (a === 1)
86
- return [0, 0, 0, 100];
87
- let b = (1 - r - a) / (1 - a), o = (1 - t - a) / (1 - a), y = (1 - n - a) / (1 - a);
88
- return [Math.round(b * 100), Math.round(o * 100), Math.round(y * 100), Math.round(a * 100)];
89
- }
90
- function v(s, r, t, n) {
91
- 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))];
92
- }
93
- var m = (s) => s <= 0.04045 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4;
94
- var p = (s) => s <= 0.0031308 ? 12.92 * s : 1.055 * s ** 0.4166666666666667 - 0.055;
95
- var i = (s, r) => Math.round(s * 10 ** r) / 10 ** r;
96
- function T(s) {
97
- 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);
98
- 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)];
40
+ if (e.length === 3 || e.length === 4)
41
+ return [Number.parseInt(e[0] + e[0], 16), Number.parseInt(e[1] + e[1], 16), Number.parseInt(e[2] + e[2], 16)];
42
+ if (e.length !== 6 && e.length !== 8)
43
+ throw Error(`Invalid hex color length: ${e.length}`);
44
+ return [Number.parseInt(e.slice(0, 2), 16), Number.parseInt(e.slice(2, 4), 16), Number.parseInt(e.slice(4, 6), 16)];
45
+ }
46
+ var 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") => {
47
+ let [l, n, c] = b(r);
48
+ return [`${e === "fg" ? 38 : 48};2;${l};${n};${c}`, e === "fg" ? 39 : 49];
49
+ }, ansi256: (r, e = "fg") => [`${e === "fg" ? 38 : 48};5;${r}`, e === "fg" ? 39 : 49] };
50
+ var h = new Set(["", "1", "2", "3", "true"]);
51
+ function C(r, e = globalThis.process?.env ?? {}) {
52
+ if (e.FORCE_COLOR !== undefined)
53
+ return h.has(e.FORCE_COLOR);
54
+ if (e.NO_COLOR !== undefined || e.NODE_DISABLE_COLORS !== undefined || e.TERM === "dumb")
55
+ return false;
56
+ return r?.isTTY === true;
57
+ }
58
+ function f(r, e = []) {
59
+ let l = "", n = "";
60
+ for (let t = 0, i = e.length;t < i; t++)
61
+ l += `\x1B[${e[t][0]}m`, n = `\x1B[${e[t][1]}m${n}`;
62
+ let c = (t) => C(r.stream ?? globalThis.process?.stdout, r.env) ? l + t + n : t, g = new Map;
63
+ return new Proxy(c, { get(t, i) {
64
+ let a = B[i];
65
+ if (Array.isArray(a)) {
66
+ let s = g.get(i);
67
+ if (s === undefined)
68
+ s = f(r, [...e, a]), g.set(i, s);
69
+ return s;
70
+ }
71
+ if (typeof a === "function")
72
+ return (...s) => {
73
+ let y = `${i}:${s.join(",")}`, u = g.get(y);
74
+ if (u === undefined) {
75
+ if (g.size >= 64)
76
+ g.clear();
77
+ u = f(r, [...e, a(...s)]), g.set(y, u);
78
+ }
79
+ return u;
80
+ };
81
+ throw Error(`Unknown style: ${String(i)}`);
82
+ } });
99
83
  }
100
- function M(s, r, t) {
101
- 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)));
102
- return [u(o), u(y), u(c)];
84
+ function Fe(r = {}) {
85
+ return f(r);
103
86
  }
104
- function d(s) {
105
- let [r, t, n] = T(s), a = Math.sqrt(t * t + n * n), b = (Math.atan2(n, t) * 180 / Math.PI + 360) % 360;
106
- return [i(r, 4), i(a, 4), i(b, 2)];
87
+ var o = Fe();
88
+
89
+ // ../kit/src/theme.ts
90
+ import { existsSync as existsSync2, readFileSync, 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
+ }
107
108
  }
108
- function C(s, r, t) {
109
- let n = t * Math.PI / 180;
110
- return M(s, r * Math.cos(n), r * Math.sin(n));
109
+
110
+ // ../kit/src/user-config.ts
111
+ import { homedir } from "os";
112
+ import { join as join2 } from "path";
113
+ import process4 from "process";
114
+ function configBase(where = {}) {
115
+ const xdg = where.xdg ?? (where.home === undefined ? process4.env.XDG_CONFIG_HOME : undefined);
116
+ return xdg !== undefined && xdg !== "" ? xdg : join2(where.home ?? homedir(), ".config");
111
117
  }
112
- function l(s) {
113
- let r = s / 255;
114
- return r <= 0.03928 ? r / 12.92 : ((r + 0.055) / 1.055) ** 2.4;
118
+ function userConfigPath(bin, where = {}) {
119
+ return join2(configBase(where), "kaynooo-cli", `${bin}.json`);
115
120
  }
116
121
 
117
- class e {
118
- r;
119
- g;
120
- b;
121
- a;
122
- constructor(s, r, t, n = 1) {
123
- this.r = s, this.g = r, this.b = t, this.a = n;
124
- }
125
- static from(s, r) {
126
- if (s === "hex") {
127
- let [t, n, a, b] = x(r);
128
- return new e(t, n, a, b);
129
- }
130
- if (s === "rgb") {
131
- if (Array.isArray(r)) {
132
- let [o, y, c, u] = r;
133
- return new e(o, y, c, u);
134
- }
135
- let { r: t, g: n, b: a, a: b } = r;
136
- return new e(t, n, a, b);
137
- }
138
- if (s === "hsl") {
139
- let t, n, a, b;
140
- if (Array.isArray(r))
141
- [t, n, a, b] = r;
142
- else
143
- ({ h: t, s: n, l: a, a: b } = r);
144
- let [o, y, c] = R(t, n, a);
145
- return new e(o, y, c, b);
146
- }
147
- if (s === "hsv") {
148
- let t, n, a, b;
149
- if (Array.isArray(r))
150
- [t, n, a, b] = r;
151
- else
152
- ({ h: t, s: n, v: a, a: b } = r);
153
- let [o, y, c] = H(t, n, a);
154
- return new e(o, y, c, b);
122
+ // ../kit/src/theme.ts
123
+ var ENDS = new Map;
124
+ var DEFAULT = {
125
+ 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" },
126
+ 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" },
127
+ accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
128
+ bins: {},
129
+ gradient: ["#c084fc", "#67e8f9"]
130
+ };
131
+ 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" };
132
+ 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" };
133
+ var ASCII = { ok: "+", warn: "!", problem: "x", note: ">", plan: "?", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+", open: "*", leaf: "-", guide: "|" };
134
+ var PRESETS = {
135
+ default: {},
136
+ "high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"], gradient: ["#d8b4fe", "#a5f3fc"] },
137
+ mono: { colors: MONO, accents: ["bold"], gradient: undefined },
138
+ ascii: { glyphs: ASCII }
139
+ };
140
+ 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"]);
141
+ var HEX = /^#[0-9a-f]{6}$/i;
142
+ var CONTROL = /\p{Cc}/u;
143
+ var MAX_FILE_BYTES = 64 * 1024;
144
+ var SPACES = /\s+/;
145
+ function isColorSpec(spec) {
146
+ if (typeof spec === "number")
147
+ return Number.isInteger(spec) && spec >= 0 && spec <= 255;
148
+ return typeof spec === "string" && spec.trim() !== "" && spec.trim().split(SPACES).every((token) => STYLES.has(token) || HEX.test(token));
149
+ }
150
+ var CUBE = [0, 95, 135, 175, 215, 255];
151
+ function cubeLevel(channel) {
152
+ return CUBE.reduce((best, value, level) => Math.abs(value - channel) < Math.abs(CUBE[best] - channel) ? level : best, 0);
153
+ }
154
+ function nearest256(hex) {
155
+ const rgb = [1, 3, 5].map((at) => Number.parseInt(hex.slice(at, at + 2), 16));
156
+ const levels = rgb.map(cubeLevel);
157
+ const cube = levels.map((level) => CUBE[level]);
158
+ const grey = Math.min(23, Math.max(0, Math.round((rgb.reduce((sum, channel) => sum + channel, 0) / 3 - 8) / 10)));
159
+ const greyValue = 8 + grey * 10;
160
+ const distance = (colour) => colour.reduce((sum, channel, at) => sum + (channel - rgb[at]) ** 2, 0);
161
+ return distance([greyValue, greyValue, greyValue]) < distance(cube) ? 232 + grey : 16 + 36 * levels[0] + 6 * levels[1] + levels[2];
162
+ }
163
+ function hasTrueColor(env) {
164
+ return env.COLORTERM === "truecolor" || env.COLORTERM === "24bit";
165
+ }
166
+ function tinted(colors, spec, env = process5.env) {
167
+ if (typeof spec === "number")
168
+ return colors.ansi256(spec);
169
+ return spec.trim().split(SPACES).reduce((chain, token) => {
170
+ if (HEX.test(token))
171
+ return hasTrueColor(env) ? chain.hex(token) : chain.ansi256(nearest256(token));
172
+ return chain[token] ?? chain;
173
+ }, colors);
174
+ }
175
+ function isRecord(value) {
176
+ return typeof value === "object" && value !== null && !Array.isArray(value);
177
+ }
178
+ function readThemeFile(path, warn) {
179
+ try {
180
+ const stat = statSync(path, { throwIfNoEntry: false });
181
+ if (stat === undefined)
182
+ return;
183
+ if (!stat.isFile() || stat.size > MAX_FILE_BYTES) {
184
+ warn(`${path} is not a regular file under ${MAX_FILE_BYTES / 1024} KiB, theme ignored`);
185
+ return;
155
186
  }
156
- if (s === "cmyk") {
157
- let t, n, a, b, o;
158
- if (Array.isArray(r))
159
- [t, n, a, b, o] = r;
187
+ const parsed = JSON.parse(readFileSync(path, "utf8"));
188
+ if (isRecord(parsed))
189
+ return parsed;
190
+ warn(`${path} is not a JSON object, theme ignored`);
191
+ } catch (error) {
192
+ warn(`${path} does not parse (${error instanceof Error ? error.message : String(error)}), theme ignored`);
193
+ }
194
+ return;
195
+ }
196
+ function applyPreset(theme, name, warn, where) {
197
+ if (name === undefined)
198
+ return;
199
+ if (typeof name !== "string" || !Object.hasOwn(PRESETS, name)) {
200
+ warn(`${where}: no preset ${String(name)}, one of ${Object.keys(PRESETS).join(", ")}`);
201
+ return;
202
+ }
203
+ const preset = PRESETS[name];
204
+ Object.assign(theme.colors, preset.colors);
205
+ Object.assign(theme.glyphs, preset.glyphs);
206
+ if (preset.accents !== undefined)
207
+ theme.accents = [...preset.accents];
208
+ if (Object.hasOwn(preset, "gradient"))
209
+ theme.gradient = preset.gradient;
210
+ return name;
211
+ }
212
+ function applyFile(theme, file, where, warn) {
213
+ if (isRecord(file.colors)) {
214
+ for (const [key, value] of Object.entries(file.colors)) {
215
+ if (!Object.hasOwn(DEFAULT.colors, key))
216
+ warn(`${where}: no colour ${key}, one of ${Object.keys(DEFAULT.colors).join(", ")}`);
217
+ else if (!isColorSpec(value))
218
+ warn(`${where}: colour ${key} is not an ANSI name, \`#rrggbb\` or a number up to 255`);
160
219
  else
161
- ({ c: t, m: n, y: a, k: b, a: o } = r);
162
- let [y, c, u] = v(t, n, a, b);
163
- return new e(y, c, u, o);
220
+ theme.colors[key] = value;
164
221
  }
165
- if (s === "oklch") {
166
- let t, n, a, b;
167
- if (Array.isArray(r))
168
- [t, n, a, b] = r;
222
+ }
223
+ if (isRecord(file.glyphs)) {
224
+ for (const [key, value] of Object.entries(file.glyphs)) {
225
+ if (!Object.hasOwn(DEFAULT.glyphs, key))
226
+ warn(`${where}: no glyph ${key}, one of ${Object.keys(DEFAULT.glyphs).join(", ")}`);
227
+ else if (typeof value !== "string" || CONTROL.test(value) || Bun.stringWidth(value) !== 1)
228
+ warn(`${where}: glyph ${key} must be one visible character wide, with no control character`);
169
229
  else
170
- ({ l: t, c: n, h: a, a: b } = r);
171
- let [o, y, c] = C(t, n, a);
172
- return new e(o, y, c, b);
230
+ theme.glyphs[key] = value;
173
231
  }
174
- if (s === "oklab") {
175
- let t, n, a, b;
176
- if (Array.isArray(r))
177
- [t, n, a, b] = r;
232
+ }
233
+ if (Array.isArray(file.accents) && file.accents.length > 0 && file.accents.every(isColorSpec))
234
+ theme.accents = [...file.accents];
235
+ else if (file.accents !== undefined)
236
+ warn(`${where}: accents must be a non-empty list of colours`);
237
+ if (file.gradient === null)
238
+ theme.gradient = undefined;
239
+ else if (Array.isArray(file.gradient) && file.gradient.length === 2 && file.gradient.every((end) => typeof end === "string" && HEX.test(end)))
240
+ theme.gradient = [file.gradient[0], file.gradient[1]];
241
+ else if (file.gradient !== undefined)
242
+ warn(`${where}: gradient must be two \`#rrggbb\` colours, or null for none`);
243
+ if (isRecord(file.bins)) {
244
+ for (const [bin, value] of Object.entries(file.bins)) {
245
+ if (isColorSpec(value))
246
+ theme.bins[bin] = value;
178
247
  else
179
- ({ l: t, a: n, b: a, alpha: b } = r);
180
- let [o, y, c] = M(t, n, a);
181
- return new e(o, y, c, b);
182
- }
183
- throw Error("Invalid input");
184
- }
185
- to(s) {
186
- switch (s) {
187
- case "rgb":
188
- return [this.r, this.g, this.b];
189
- case "rgba":
190
- return [this.r, this.g, this.b, this.a];
191
- case "hex":
192
- return A([this.r, this.g, this.b]);
193
- case "hexa":
194
- return A([this.r, this.g, this.b, this.a]);
195
- case "hsl":
196
- return k([this.r, this.g, this.b]);
197
- case "hsla":
198
- return [...k([this.r, this.g, this.b]), this.a];
199
- case "hsv":
200
- return f([this.r, this.g, this.b]);
201
- case "hsva":
202
- return [...f([this.r, this.g, this.b]), this.a];
203
- case "cmyk":
204
- return O([this.r, this.g, this.b]);
205
- case "cmyka":
206
- return [...O([this.r, this.g, this.b]), this.a];
207
- case "oklch":
208
- return d([this.r, this.g, this.b]);
209
- case "oklcha":
210
- return [...d([this.r, this.g, this.b]), this.a];
211
- case "oklab":
212
- return T([this.r, this.g, this.b]);
213
- case "oklaba":
214
- return [...T([this.r, this.g, this.b]), this.a];
215
- default:
216
- return [this.r, this.g, this.b];
248
+ warn(`${where}: bin ${bin} has no valid colour`);
217
249
  }
218
250
  }
219
- getLuminance() {
220
- let s = l(this.r), r = l(this.g), t = l(this.b);
221
- return 0.2126 * s + 0.7152 * r + 0.0722 * t;
222
- }
223
- contrastRatio(s) {
224
- let r = this.getLuminance(), t = s.getLuminance(), [n, a] = r >= t ? [r, t] : [t, r];
225
- return (n + 0.05) / (a + 0.05);
251
+ }
252
+ function endsWalk(home) {
253
+ return (dir) => dir === resolve2(home) || existsSync2(join3(dir, ".git"));
254
+ }
255
+ var warned = new Set;
256
+ function warnOnce(message) {
257
+ if (warned.has(message))
258
+ return;
259
+ warned.add(message);
260
+ console.error(`warning: theme ${message}`);
261
+ }
262
+ function isPath(chosen) {
263
+ return chosen.includes("/") || chosen.endsWith(".json");
264
+ }
265
+ function loadTheme({ env = process5.env, from = process5.cwd(), home = homedir2(), warn = warnOnce } = {}) {
266
+ const theme = { colors: { ...DEFAULT.colors }, glyphs: { ...DEFAULT.glyphs }, accents: [...DEFAULT.accents], bins: Object.create(null), gradient: DEFAULT.gradient };
267
+ const sources = [];
268
+ const chosen = env.KIT_THEME ?? "";
269
+ const wanted = chosen === "" ? [userConfigPath("theme", { home, xdg: env.XDG_CONFIG_HOME }), findUp(join3(".kaynooo", "theme.json"), from, endsWalk(home))] : [];
270
+ if (isPath(chosen))
271
+ wanted.push(resolve2(from, chosen));
272
+ const files = [];
273
+ for (const path of wanted) {
274
+ const file = path === undefined ? undefined : readThemeFile(path, warn);
275
+ if (path !== undefined && file !== undefined)
276
+ files.push({ path, file });
277
+ }
278
+ let preset = "default";
279
+ if (chosen !== "" && !isPath(chosen)) {
280
+ preset = applyPreset(theme, chosen, warn, "KIT_THEME") ?? preset;
281
+ } else {
282
+ const named = files.findLast(({ file }) => file.preset !== undefined);
283
+ if (named !== undefined)
284
+ preset = applyPreset(theme, named.file.preset, warn, named.path) ?? preset;
226
285
  }
227
- bestContrastForeground() {
228
- let s = new e(255, 255, 255, 1), r = new e(0, 0, 0, 1), t = this.contrastRatio(s), n = this.contrastRatio(r);
229
- return t >= n ? s : r;
286
+ for (const { path, file } of files) {
287
+ applyFile(theme, file, path, warn);
288
+ sources.push(path);
230
289
  }
290
+ return { theme, sources, preset };
231
291
  }
232
-
233
- // ../../node_modules/.bun/@kaynooo+utils@2.31.2+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-y1msbssb.js
234
- var r = 39;
235
- var o = 49;
236
- var f2 = "\x1B[";
237
- 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") => {
238
- let [a, l, s] = e.from("hex", i).to("rgb");
239
- return [`${n === "fg" ? 38 : 48};2;${a};${l};${s}`, n === "fg" ? r : o];
240
- }, ansi256: (i, n = "fg") => [`${n === "fg" ? 38 : 48};5;${i}`, n === "fg" ? r : o] };
241
- var b = new Set(["", "1", "2", "3", "true"]);
242
- function h(i, n = globalThis.process?.env ?? {}) {
243
- if (n.FORCE_COLOR !== undefined)
244
- return b.has(n.FORCE_COLOR);
245
- if (n.NO_COLOR !== undefined || n.NODE_DISABLE_COLORS !== undefined || n.TERM === "dumb")
246
- return false;
247
- return i?.isTTY === true;
248
- }
249
- function d2(i, n, a) {
250
- if (!h(a.stream ?? globalThis.process?.stdout, a.env))
251
- return n;
252
- let l = "", s = "";
253
- for (let g = 0, y = i.length;g < y; g++) {
254
- let [c, p] = i[g];
255
- l += `${f2}${c}m`, s = `${f2}${p}m${s}`;
256
- }
257
- return l + n + s;
258
- }
259
- function u(i, n = []) {
260
- return new Proxy((l) => d2(n, l, i), { get(l, s) {
261
- let g = C2[s];
262
- if (Array.isArray(g))
263
- return u(i, [...n, g]);
264
- if (typeof g === "function")
265
- return (...y) => u(i, [...n, g(...y)]);
266
- throw Error(`Unknown style: ${String(s)}`);
267
- } });
268
- }
269
- function le(i = {}) {
270
- return u(i);
292
+ var current;
293
+ var currentKey = "";
294
+ function activeTheme() {
295
+ const key = `${process5.cwd()}\x00${process5.env.KIT_THEME ?? ""}\x00${process5.env.XDG_CONFIG_HOME ?? ""}`;
296
+ if (current === undefined || key !== currentKey) {
297
+ current = loadTheme();
298
+ currentKey = key;
299
+ }
300
+ return current;
271
301
  }
272
- var t = le();
273
302
 
274
303
  // ../kit/src/style.ts
275
- var MARKS = {
276
- ok: { symbol: "\u2713", word: "ok:", paint: (colors) => colors.green },
277
- warn: { symbol: "!", word: "warning:", paint: (colors) => colors.yellow },
278
- problem: { symbol: "\u2717", word: "error:", paint: (colors) => colors.red },
279
- note: { symbol: "\xB7", word: "note:", paint: (colors) => colors.dim }
280
- };
281
- function takesControlCodes(stream, env = process2.env) {
282
- return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb";
304
+ var MARK_WORDS = { ok: "ok:", warn: "warning:", problem: "error:", note: "note:", plan: "would:" };
305
+ function takesControlCodes(stream, env = process6.env) {
306
+ return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
283
307
  }
284
- function paint(stream, env = process2.env) {
285
- return le({ stream: { isTTY: takesControlCodes(stream, env) }, env });
308
+ function paint(stream, env = process6.env) {
309
+ return Fe({ stream: { isTTY: takesControlCodes(stream, env) }, env });
286
310
  }
287
- function marked(mark, text, stream, detail, env = process2.env) {
311
+ function marked(mark, text, stream, detail, env = process6.env) {
288
312
  const colors = paint(stream, env);
289
- const { symbol, word, paint: tint } = MARKS[mark];
290
- const head = takesControlCodes(stream, env) ? tint(colors)(symbol) : word;
313
+ let head = MARK_WORDS[mark];
314
+ if (takesControlCodes(stream, env)) {
315
+ const { theme } = activeTheme();
316
+ head = tinted(colors.bold, theme.colors[mark], env)(theme.glyphs[mark]);
317
+ }
291
318
  return `${head} ${text}${detail === undefined ? "" : ` ${colors.dim(detail)}`}`;
292
319
  }
293
- var STATUSES = {
294
- passed: { symbol: "\u2713", words: ["passed", "success", "succeeded", "ok"], paint: (colors) => colors.green },
295
- failed: { symbol: "\u2717", words: ["failed", "failure", "error", "errored"], paint: (colors) => colors.red },
296
- running: { symbol: "\u25CF", words: ["running", "in_progress", "started"], paint: (colors) => colors.cyan },
297
- queued: { symbol: "\u25CB", words: ["queued", "waiting", "pending", "created", "blocked", "scheduled"], paint: (colors) => colors.yellow },
298
- skipped: { symbol: "-", words: ["skipped", "cancelled", "canceled", "manual"], paint: (colors) => colors.dim }
320
+ var STATUS_WORDS = {
321
+ passed: ["passed", "success", "succeeded", "ok"],
322
+ failed: ["failed", "failure", "error", "errored"],
323
+ running: ["running", "in_progress", "started", "holding"],
324
+ queued: ["queued", "waiting", "pending", "created", "blocked", "scheduled"],
325
+ skipped: ["skipped", "cancelled", "canceled", "manual"]
299
326
  };
300
- var STATUS_OF = new Map(Object.entries(STATUSES).flatMap(([status, { words }]) => words.map((word) => [word, status])));
327
+ var STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
301
328
 
302
329
  // ../kit/src/format.ts
303
330
  function upTo(text, separator) {
@@ -305,32 +332,35 @@ function upTo(text, separator) {
305
332
  return end === -1 ? text : text.slice(0, end);
306
333
  }
307
334
  var ESCAPE = String.fromCharCode(27);
335
+ function jsonText(value, replacer, { stream = process7.stdout, env = process7.env } = {}) {
336
+ return JSON.stringify(value, replacer, outputMode(stream, env) === "agent" ? undefined : 2);
337
+ }
308
338
  function printJson(value) {
309
- console.log(JSON.stringify(value, undefined, 2));
339
+ console.log(jsonText(value));
310
340
  }
311
341
 
312
342
  // ../kit/src/help.ts
313
- import process3 from "process";
343
+ import process8 from "process";
314
344
  var OPTIONAL = /\[[^\]]+\]/g;
315
345
  var USAGE_PREFIX = /^usage:\s*/i;
316
346
  var FULL_STOP = /\.$/;
317
- function usageLine(usage, colors = paint(process3.stdout)) {
347
+ function usageLine(usage, colors = paint(process8.stdout)) {
318
348
  return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
319
349
  }
320
- function helpText(usage, options, colors = paint(process3.stdout), { examples = [], replaces, exits = [] } = {}) {
350
+ function helpText(usage, options, colors = paint(process8.stdout), { examples = [], replaces, exits = [] } = {}) {
321
351
  return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
322
352
  `);
323
353
  }
324
- function exitRows(exits, colors = paint(process3.stdout)) {
354
+ function exitRows(exits, colors = paint(process8.stdout)) {
325
355
  if (exits.length === 0)
326
356
  return [];
327
357
  const width = Math.max(...exits.map(([code]) => String(code).length));
328
358
  return ["", colors.bold("Exits:"), ...exits.map(([code, meaning]) => ` ${colors.cyan(String(code).padEnd(width))} ${meaning}`)];
329
359
  }
330
- function replacesRows(replaces, colors = paint(process3.stdout)) {
331
- return replaces === undefined ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
360
+ function replacesRows(replaces, colors = paint(process8.stdout)) {
361
+ return replaces === undefined || outputMode() === "agent" ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
332
362
  }
333
- function wantsHelpJson(env = process3.env) {
363
+ function wantsHelpJson(env = process8.env) {
334
364
  return env.KIT_HELP === "json";
335
365
  }
336
366
  function description(usage, { examples = [], replaces, exits } = {}, options) {
@@ -349,12 +379,12 @@ function description(usage, { examples = [], replaces, exits } = {}, options) {
349
379
  ...options === undefined ? {} : { options: Object.entries(options).map(([name, { short, description }]) => ({ name, ...short === undefined ? {} : { short }, ...description === undefined ? {} : { description } })) }
350
380
  };
351
381
  }
352
- function exampleRows(examples, colors = paint(process3.stdout)) {
353
- if (examples.length === 0)
382
+ function exampleRows(examples, colors = paint(process8.stdout)) {
383
+ if (examples.length === 0 || outputMode() === "agent")
354
384
  return [];
355
385
  return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
356
386
  }
357
- function optionRows(options, colors = paint(process3.stdout)) {
387
+ function optionRows(options, colors = paint(process8.stdout)) {
358
388
  const rows = Object.entries(options).map(([name, option]) => {
359
389
  const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
360
390
  const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
@@ -401,7 +431,6 @@ var DASHES = /^-+/;
401
431
  function jsonOption(holds) {
402
432
  return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
403
433
  }
404
-
405
434
  class Exit extends Error {
406
435
  code;
407
436
  hint;
@@ -445,7 +474,7 @@ var OUTPUT_OPTIONS = {
445
474
  color: { type: "string", description: "auto (on a terminal alone), always or never" },
446
475
  plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
447
476
  };
448
- function applyOutput(color, plain, env = process4.env) {
477
+ function applyOutput(color, plain, env = process9.env) {
449
478
  const when = plain === true ? "never" : color ?? "auto";
450
479
  if (when === "auto")
451
480
  return;
@@ -620,15 +649,15 @@ var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x
620
649
  var RESET_STYLE = `${ESC}[0m`;
621
650
  var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
622
651
  // ../kit/src/cli.ts
623
- import { readFileSync, realpathSync } from "fs";
624
- import { dirname as dirname2, join as join2 } from "path";
625
- import process6 from "process";
652
+ import { readFileSync as readFileSync2, realpathSync } from "fs";
653
+ import { dirname as dirname3, join as join5 } from "path";
654
+ import process11 from "process";
626
655
 
627
656
  // ../kit/src/usage.ts
628
657
  import { appendFileSync, mkdirSync } from "fs";
629
- import { homedir } from "os";
630
- import { dirname, isAbsolute, join } from "path";
631
- import process5 from "process";
658
+ import { homedir as homedir3 } from "os";
659
+ import { dirname as dirname2, isAbsolute, join as join4 } from "path";
660
+ import process10 from "process";
632
661
 
633
662
  // ../kit/src/logs.ts
634
663
  var DAY_MS = 24 * 60 * 60 * 1000;
@@ -642,14 +671,14 @@ var usageError;
642
671
  function noteUsageError(message) {
643
672
  usageError = message;
644
673
  }
645
- function stateHome(env = process5.env) {
674
+ function stateHome(env = process10.env) {
646
675
  const dir = env.XDG_STATE_HOME;
647
- return dir !== undefined && isAbsolute(dir) ? dir : join(homedir(), ".local", "state");
676
+ return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
648
677
  }
649
- function usagePath(env = process5.env) {
650
- return join(stateHome(env), CLI_FOLDER, "usage.jsonl");
678
+ function usagePath(env = process10.env) {
679
+ return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
651
680
  }
652
- function usageRecorded(env = process5.env) {
681
+ function usageRecorded(env = process10.env) {
653
682
  const off = env.KAYNOOO_CLI_NO_USAGE;
654
683
  return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
655
684
  }
@@ -663,12 +692,12 @@ function usageEntry(bin, command, argv, code, now = new Date) {
663
692
  usageError = undefined;
664
693
  return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
665
694
  }
666
- function recordUsage(entry, env = process5.env) {
695
+ function recordUsage(entry, env = process10.env) {
667
696
  if (!usageRecorded(env))
668
697
  return;
669
698
  try {
670
699
  const path = usagePath(env);
671
- mkdirSync(dirname(path), { recursive: true, mode: 448 });
700
+ mkdirSync(dirname2(path), { recursive: true, mode: 448 });
672
701
  appendFileSync(path, `${JSON.stringify(entry)}
673
702
  `, { mode: 384 });
674
703
  } catch {}
@@ -754,8 +783,8 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
754
783
  `);
755
784
  }
756
785
  function printError(prefix, message, hint, cause) {
757
- const colors = paint(process6.stderr);
758
- const styled = takesControlCodes(process6.stderr);
786
+ const colors = paint(process11.stderr);
787
+ const styled = takesControlCodes(process11.stderr);
759
788
  const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
760
789
  const under = (label, text, tint) => text === undefined ? "" : `
761
790
  ${styled ? tint(label) : `${label}:`} ${text}`;
@@ -774,7 +803,7 @@ function reportThrown(prefix, error, redact = (text) => text, json = false) {
774
803
  const help = error instanceof UsageError ? `run ${prefix} --help for its options` : undefined;
775
804
  const named = error instanceof Error && !(error instanceof Exit) && error.name !== "Error" ? `${error.name}: ${error.message}` : undefined;
776
805
  const cause = error instanceof Error && error.cause instanceof Error ? redact(error.cause.message) : undefined;
777
- if (error instanceof UsageError)
806
+ if (error instanceof Exit && error.code === 2)
778
807
  noteUsageError(error.message);
779
808
  const report = json ? printJsonError : (message, hint, causeText) => printError(prefix, message, hint, causeText);
780
809
  report(redact(named ?? (error instanceof Error ? error.message : String(error))), error instanceof Exit ? error.hint ?? help : undefined, cause);
@@ -798,11 +827,11 @@ async function dispatch(level, typed, { version, redact }) {
798
827
  }
799
828
  }
800
829
  if (name === undefined && level.path.length > 1) {
801
- console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process6.stderr));
830
+ console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process11.stderr));
802
831
  return 2;
803
832
  }
804
833
  if (name === undefined || name === "help" || name === "--help" || name === "-h") {
805
- console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process6.stdout));
834
+ console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process11.stdout));
806
835
  return 0;
807
836
  }
808
837
  if (level.path.length === 1 && (name === "--version" || name === "-v")) {
@@ -919,17 +948,17 @@ async function printCandidates(found) {
919
948
  return 0;
920
949
  }
921
950
  function packageVersion(entry = Bun.main) {
922
- for (let dir = dirname2(realpathSync(entry));; dir = dirname2(dir)) {
951
+ for (let dir = dirname3(realpathSync(entry));; dir = dirname3(dir)) {
923
952
  try {
924
- const { version } = JSON.parse(readFileSync(join2(dir, "package.json"), "utf8"));
953
+ const { version } = JSON.parse(readFileSync2(join5(dir, "package.json"), "utf8"));
925
954
  if (typeof version === "string")
926
955
  return version;
927
956
  } catch {}
928
- if (dirname2(dir) === dir)
957
+ if (dirname3(dir) === dir)
929
958
  return "0.0.0";
930
959
  }
931
960
  }
932
- async function runCli(cli, argv = process6.argv.slice(2)) {
961
+ async function runCli(cli, argv = process11.argv.slice(2)) {
933
962
  const version = cli.version ?? packageVersion();
934
963
  if (argv[0] === COMPLETE)
935
964
  return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
@@ -970,6 +999,8 @@ function composeError({ code, stderr }) {
970
999
  `).at(-1) ?? "";
971
1000
  return last === "" ? `exit ${code}` : last;
972
1001
  }
1002
+ // ../kit/src/folders.ts
1003
+ var SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
973
1004
  // ../kit/src/limit.ts
974
1005
  function limitOptions(fallback) {
975
1006
  return {
@@ -998,14 +1029,14 @@ var {Glob } = globalThis.Bun;
998
1029
  var SESSION_FILES = new Glob("*.json");
999
1030
  var ACCOUNT_DIRS = new Glob("*/sessions");
1000
1031
  // src/commands/audit.ts
1001
- import { homedir as homedir2 } from "os";
1002
- import { resolve as resolve2 } from "path";
1003
- import process9 from "process";
1032
+ import { homedir as homedir4 } from "os";
1033
+ import { resolve as resolve4 } from "path";
1034
+ import process14 from "process";
1004
1035
 
1005
1036
  // src/audit/compose.ts
1006
- import { join as join3 } from "path";
1037
+ import { join as join6 } from "path";
1007
1038
  var dockerCompose = async (root, files) => {
1008
- const result = await compose(["config", "--no-interpolate", "--format", "json"], { flags: ["--project-directory", root, ...files.flatMap((file) => ["-f", join3(root, file)])], env: { COMPOSE_FILE: "" } });
1039
+ const result = await compose(["config", "--no-interpolate", "--format", "json"], { flags: ["--project-directory", root, ...files.flatMap((file) => ["-f", join6(root, file)])], env: { COMPOSE_FILE: "" } });
1009
1040
  if (result.code !== 0)
1010
1041
  throw new Error(composeError(result));
1011
1042
  return JSON.parse(result.stdout);
@@ -1013,12 +1044,12 @@ var dockerCompose = async (root, files) => {
1013
1044
 
1014
1045
  // src/audit/render.ts
1015
1046
  import { basename } from "path";
1016
- import process8 from "process";
1017
- var line = (finding) => ` ${marked(finding.level === "error" ? "problem" : "warn", `[${finding.check}] ${finding.message}`, process8.stdout)}`;
1047
+ import process13 from "process";
1048
+ var line = (finding) => ` ${marked(finding.level === "error" ? "problem" : "warn", `[${finding.check}] ${finding.message}`, process13.stdout)}`;
1018
1049
  function errorsOf(result) {
1019
1050
  return result.findings.filter((finding) => finding.level === "error");
1020
1051
  }
1021
- function section(heading, findings, limit) {
1052
+ function section2(heading, findings, limit) {
1022
1053
  const { shown, footer } = capped(findings, limit);
1023
1054
  return findings.length === 0 ? [] : [heading, ...shown.map(line), ...footer === undefined ? [] : [` ${footer}`], ""];
1024
1055
  }
@@ -1026,22 +1057,22 @@ function render(result, limit = Number.POSITIVE_INFINITY) {
1026
1057
  const errors = errorsOf(result);
1027
1058
  const warnings = result.findings.filter((finding) => finding.level === "warn");
1028
1059
  if (result.findings.length === 0)
1029
- return marked("ok", `${basename(result.root)}: compose ${result.composeFiles.join(", ")} and release.config.ts agree.`, process8.stdout);
1060
+ return marked("ok", `${basename(result.root)}: compose ${result.composeFiles.join(", ")} and release.config.ts agree.`, process13.stdout);
1030
1061
  return [
1031
- ...section("Errors", errors, limit),
1032
- ...section("Warnings", warnings, limit),
1062
+ ...section2("Errors", errors, limit),
1063
+ ...section2("Warnings", warnings, limit),
1033
1064
  `${errors.length} error(s), ${warnings.length} warning(s)`
1034
1065
  ].join(`
1035
1066
  `);
1036
1067
  }
1037
1068
 
1038
1069
  // src/audit/run.ts
1039
- import { existsSync as existsSync3 } from "fs";
1040
- import { join as join6 } from "path";
1070
+ import { existsSync as existsSync5 } from "fs";
1071
+ import { join as join9 } from "path";
1041
1072
 
1042
1073
  // src/audit/checks.ts
1043
- import { existsSync, readFileSync as readFileSync2 } from "fs";
1044
- import { isAbsolute as isAbsolute2, join as join4, relative, resolve } from "path";
1074
+ import { existsSync as existsSync3, readFileSync as readFileSync3 } from "fs";
1075
+ import { isAbsolute as isAbsolute2, join as join7, relative, resolve as resolve3 } from "path";
1045
1076
  var ENV_REF = /(?<!\$)\$(?:\{([A-Z_]\w*)(\s*:?[-?+][^}]*)?\}|([A-Z_]\w*))/gi;
1046
1077
  var REQUIRED_OPERATOR = /^\s*:?\?/;
1047
1078
  var COMMENT_START = /(?:^|\s)#.*$/;
@@ -1057,18 +1088,18 @@ function before(text, separator) {
1057
1088
  }
1058
1089
  var stripDotSlash = (file) => file.replace(LEADING_DOT_SLASH, "");
1059
1090
  function composeLayout(root, config) {
1060
- const composeFiles = (config.deploySyncFiles ?? []).map(stripDotSlash).filter((file) => YAML_FILE.test(file) && existsSync(join4(root, file)));
1091
+ const composeFiles = (config.deploySyncFiles ?? []).map(stripDotSlash).filter((file) => YAML_FILE.test(file) && existsSync3(join7(root, file)));
1061
1092
  const [base] = composeFiles.toSorted((a, b) => a.length - b.length);
1062
1093
  return { composeFiles, base, overlays: composeFiles.filter((file) => file !== base) };
1063
1094
  }
1064
1095
  function syncFindings(root, config) {
1065
- return (config.deploySyncFiles ?? []).filter((file) => !existsSync(join4(root, stripDotSlash(file)))).map((file) => ({ level: "error", check: "sync", message: `deploySyncFiles entry does not exist: ${file}` }));
1096
+ return (config.deploySyncFiles ?? []).filter((file) => !existsSync3(join7(root, stripDotSlash(file)))).map((file) => ({ level: "error", check: "sync", message: `deploySyncFiles entry does not exist: ${file}` }));
1066
1097
  }
1067
1098
  function buildFindings(root, releases, env, home) {
1068
1099
  const findings = [];
1069
1100
  const missing = (release, key) => {
1070
1101
  const path = release[key];
1071
- if (path !== undefined && path !== "" && !existsSync(join4(root, path)))
1102
+ if (path !== undefined && path !== "" && !existsSync3(join7(root, path)))
1072
1103
  findings.push({ level: "error", check: "build", message: `${release.slug}: ${key} does not exist: ${path}` });
1073
1104
  };
1074
1105
  for (const release of releases) {
@@ -1077,8 +1108,8 @@ function buildFindings(root, releases, env, home) {
1077
1108
  missing(release, "dockerfile");
1078
1109
  for (const secret of release.buildSecrets ?? []) {
1079
1110
  if (secret.src !== undefined && secret.src !== "") {
1080
- const path = secret.src.startsWith("~") ? join4(home, secret.src.slice(1)) : resolve(root, secret.src);
1081
- if (!existsSync(path))
1111
+ const path = secret.src.startsWith("~") ? join7(home, secret.src.slice(1)) : resolve3(root, secret.src);
1112
+ if (!existsSync3(path))
1082
1113
  findings.push({ level: "error", check: "build", message: `${release.slug}: buildSecret "${secret.id}" src does not exist: ${secret.src}` });
1083
1114
  }
1084
1115
  if (secret.env !== undefined && secret.env !== "" && (env[secret.env] ?? "") === "")
@@ -1095,7 +1126,7 @@ function withoutComment(line) {
1095
1126
  }
1096
1127
  function envRefs(root, composeFiles) {
1097
1128
  return composeFiles.flatMap((file) => {
1098
- const text = readFileSync2(join4(root, file), "utf8").split(`
1129
+ const text = readFileSync3(join7(root, file), "utf8").split(`
1099
1130
  `).map(withoutComment).join(`
1100
1131
  `);
1101
1132
  return [...text.matchAll(ENV_REF)].map((match) => ({ name: match[1] ?? match[3], defaulted: match[2] !== undefined && !REQUIRED_OPERATOR.test(match[2]), file }));
@@ -1205,22 +1236,25 @@ function routingFindings(config, gated, model, base, overlays) {
1205
1236
  }
1206
1237
  return findings;
1207
1238
  }
1208
- function relativeSource(root, source) {
1209
- if (source === undefined)
1239
+ var SOURCE_END = /:(?![-+?=])/;
1240
+ var DEFAULTED_VARIABLE = /\$\{[A-Z_]\w*:?-([^}$]*)\}/gi;
1241
+ function relativeSource(root, written) {
1242
+ const source = written?.replaceAll(DEFAULTED_VARIABLE, "$1");
1243
+ if (source === undefined || source.includes("$"))
1210
1244
  return;
1211
1245
  if (source.startsWith("."))
1212
1246
  return source;
1213
- const inRoot = relative(resolve(root), source);
1247
+ const inRoot = relative(resolve3(root), source);
1214
1248
  return isAbsolute2(source) && inRoot !== "" && !inRoot.startsWith("..") ? `./${inRoot}` : undefined;
1215
1249
  }
1216
1250
  function layoutFindings(root, base, model) {
1217
1251
  if (base === undefined)
1218
1252
  return [];
1219
- const header = readFileSync2(join4(root, base), "utf8").split(SERVICES_KEY)[0] ?? "";
1253
+ const header = readFileSync3(join7(root, base), "utf8").split(SERVICES_KEY)[0] ?? "";
1220
1254
  const findings = [];
1221
1255
  for (const [name, service] of services(model)) {
1222
1256
  for (const volume of service.volumes ?? []) {
1223
- const source = relativeSource(root, typeof volume === "string" ? before(volume, ":") : volume.source);
1257
+ const source = relativeSource(root, typeof volume === "string" ? volume.split(SOURCE_END)[0] : volume.source);
1224
1258
  if (source !== undefined && !header.includes(stripDotSlash(source)))
1225
1259
  findings.push({ level: "warn", check: "layout", message: `service "${name}" bind-mounts ${source}, absent from the header's expected server layout` });
1226
1260
  }
@@ -1228,14 +1262,14 @@ function layoutFindings(root, base, model) {
1228
1262
  return findings;
1229
1263
  }
1230
1264
  function gitignoreFindings(root) {
1231
- const path = join4(root, ".gitignore");
1232
- const text = existsSync(path) ? readFileSync2(path, "utf8") : "";
1265
+ const path = join7(root, ".gitignore");
1266
+ const text = existsSync3(path) ? readFileSync3(path, "utf8") : "";
1233
1267
  return [".release-logs", ".release-worktrees"].filter((entry) => !text.includes(entry)).map((entry) => ({ level: "warn", check: "gitignore", message: `${entry}/ is not in .gitignore` }));
1234
1268
  }
1235
1269
 
1236
1270
  // src/audit/nuxt.ts
1237
- import { existsSync as existsSync2, readFileSync as readFileSync3 } from "fs";
1238
- import { basename as basename2, join as join5 } from "path";
1271
+ import { existsSync as existsSync4, readFileSync as readFileSync4 } from "fs";
1272
+ import { basename as basename2, join as join8 } from "path";
1239
1273
  var CAMEL_BOUNDARY = /([a-z0-9])([A-Z])/g;
1240
1274
  var KEY = /([A-Z_]\w*)\s*(?:\?\s*)?:/gi;
1241
1275
  var OPENS_BRACE = /^\s*\{/;
@@ -1278,21 +1312,21 @@ function schemaEnvNames(schema, iface, prefix) {
1278
1312
  }
1279
1313
  function nuxtFindings(root, releases, model) {
1280
1314
  const findings = [];
1281
- const dirs = [...new Set(releases.map((release) => release.buildContext).filter((context) => context !== undefined && context !== ""))].map((dir) => join5(root, dir)).filter((dir) => existsSync2(join5(dir, "nuxt.config.ts")));
1315
+ const dirs = [...new Set(releases.map((release) => release.buildContext).filter((context) => context !== undefined && context !== ""))].map((dir) => join8(root, dir)).filter((dir) => existsSync4(join8(dir, "nuxt.config.ts")));
1282
1316
  for (const dir of dirs) {
1283
- const schemaPath = [join5(dir, ".nuxt/types/schema.d.ts"), join5(dir, ".nuxt/types/runtime-config.d.ts")].find((path) => existsSync2(path));
1317
+ const schemaPath = [join8(dir, ".nuxt/types/schema.d.ts"), join8(dir, ".nuxt/types/runtime-config.d.ts")].find((path) => existsSync4(path));
1284
1318
  let allowed;
1285
1319
  let level = "error";
1286
1320
  let source;
1287
1321
  if (schemaPath !== undefined) {
1288
- const schema = readFileSync3(schemaPath, "utf8");
1322
+ const schema = readFileSync4(schemaPath, "utf8");
1289
1323
  allowed = new Set([
1290
1324
  ...schemaEnvNames(schema, "SharedRuntimeConfig", "NUXT_"),
1291
1325
  ...schemaEnvNames(schema, "SharedPublicRuntimeConfig", "NUXT_PUBLIC_")
1292
1326
  ]);
1293
1327
  source = `${basename2(dir)}/${schemaPath.slice(dir.length + 1)}`;
1294
1328
  } else {
1295
- const config = readFileSync3(join5(dir, "nuxt.config.ts"), "utf8");
1329
+ const config = readFileSync4(join8(dir, "nuxt.config.ts"), "utf8");
1296
1330
  const at = config.indexOf("runtimeConfig:");
1297
1331
  const block = at < 0 ? undefined : braceBody(config, at);
1298
1332
  if (block === undefined)
@@ -1323,7 +1357,7 @@ function installed(specifier, root) {
1323
1357
  }
1324
1358
  }
1325
1359
  async function loadConfig(root) {
1326
- const specifier = DEFINE_CONFIG_IMPORT.exec(await Bun.file(join6(root, CONFIG_FILE)).text())?.[1];
1360
+ const specifier = DEFINE_CONFIG_IMPORT.exec(await Bun.file(join9(root, CONFIG_FILE)).text())?.[1];
1327
1361
  if (specifier !== undefined && !installed(specifier, root)) {
1328
1362
  Bun.plugin({
1329
1363
  name: "release-stand-in",
@@ -1332,7 +1366,7 @@ async function loadConfig(root) {
1332
1366
  }
1333
1367
  });
1334
1368
  }
1335
- const config = (await import(join6(root, CONFIG_FILE))).default;
1369
+ const config = (await import(join9(root, CONFIG_FILE))).default;
1336
1370
  if (config === undefined)
1337
1371
  fail(`${CONFIG_FILE} has no default export`);
1338
1372
  return config;
@@ -1381,7 +1415,7 @@ async function audit(config, options) {
1381
1415
  ];
1382
1416
  return { root, composeFiles, findings };
1383
1417
  }
1384
- var hasConfig = (root) => existsSync3(join6(root, CONFIG_FILE));
1418
+ var hasConfig = (root) => existsSync5(join9(root, CONFIG_FILE));
1385
1419
 
1386
1420
  // src/commands/audit.ts
1387
1421
  var usage2 = `stack audit [dir]
@@ -1398,11 +1432,11 @@ var options = {
1398
1432
  };
1399
1433
  async function audit2(args, overrides = {}) {
1400
1434
  const parsed = parse(args, usage2, options);
1401
- const root = resolve2(parsed.positionals[0] ?? ".");
1435
+ const root = resolve4(parsed.positionals[0] ?? ".");
1402
1436
  if (!hasConfig(root)) {
1403
1437
  fail(`no ${CONFIG_FILE} in ${root}`);
1404
1438
  }
1405
- const result = await audit(await loadConfig(root), { root, loadCompose: dockerCompose, env: process9.env, home: homedir2(), ...overrides });
1439
+ const result = await audit(await loadConfig(root), { root, loadCompose: dockerCompose, env: process14.env, home: homedir4(), ...overrides });
1406
1440
  if (parsed.values.json === true)
1407
1441
  printJson(result);
1408
1442
  else
@@ -1466,7 +1500,7 @@ async function port(args) {
1466
1500
  }
1467
1501
 
1468
1502
  // src/cli.ts
1469
- process10.exitCode = await runCli({
1503
+ process15.exitCode = await runCli({
1470
1504
  name: "stack",
1471
1505
  about: "a stable port per service name, and a compose release audit",
1472
1506
  replaces: "picking a free host port by hand, and reading compose files against release.config.ts",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kaynooo/cli-stack",
3
3
  "type": "module",
4
- "version": "0.5.1",
4
+ "version": "0.7.0",
5
5
  "description": "stack: a stable port per service name, and an audit of a compose release setup against its release.config.ts.",
6
6
  "author": "Kaynooo <contact@kaynooo.fr>",
7
7
  "license": "MIT",
@@ -28,6 +28,6 @@
28
28
  "stack": "$npm_execpath src/cli.ts"
29
29
  },
30
30
  "devDependencies": {
31
- "@kaynooo/cli-kit": "0.21.0"
31
+ "@kaynooo/cli-kit": "0.36.0"
32
32
  }
33
33
  }