@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.
- package/dist/cli.js +374 -340
- 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
|
|
5
|
+
import process15 from "process";
|
|
6
6
|
// ../kit/src/args.ts
|
|
7
|
-
import
|
|
7
|
+
import process9 from "process";
|
|
8
8
|
import { parseArgs } from "util";
|
|
9
9
|
|
|
10
|
-
// ../kit/src/
|
|
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@
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
let
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if (
|
|
33
|
-
return
|
|
34
|
-
return
|
|
35
|
-
}
|
|
36
|
-
function
|
|
37
|
-
|
|
38
|
-
let
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
|
|
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
|
|
101
|
-
|
|
102
|
-
return [u(o), u(y), u(c)];
|
|
84
|
+
function Fe(r = {}) {
|
|
85
|
+
return f(r);
|
|
103
86
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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
|
-
|
|
109
|
-
|
|
110
|
-
|
|
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
|
|
113
|
-
|
|
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
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
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
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
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
|
-
|
|
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
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
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
|
-
|
|
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
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
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
|
-
({
|
|
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
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
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
|
-
|
|
228
|
-
|
|
229
|
-
|
|
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
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
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
|
|
276
|
-
|
|
277
|
-
|
|
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 =
|
|
285
|
-
return
|
|
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 =
|
|
311
|
+
function marked(mark, text, stream, detail, env = process6.env) {
|
|
288
312
|
const colors = paint(stream, env);
|
|
289
|
-
|
|
290
|
-
|
|
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
|
|
294
|
-
passed:
|
|
295
|
-
failed:
|
|
296
|
-
running:
|
|
297
|
-
queued:
|
|
298
|
-
skipped:
|
|
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(
|
|
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(
|
|
339
|
+
console.log(jsonText(value));
|
|
310
340
|
}
|
|
311
341
|
|
|
312
342
|
// ../kit/src/help.ts
|
|
313
|
-
import
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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 =
|
|
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(
|
|
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(
|
|
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 =
|
|
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
|
|
625
|
-
import
|
|
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
|
|
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 =
|
|
674
|
+
function stateHome(env = process10.env) {
|
|
646
675
|
const dir = env.XDG_STATE_HOME;
|
|
647
|
-
return dir !== undefined && isAbsolute(dir) ? dir :
|
|
676
|
+
return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
|
|
648
677
|
}
|
|
649
|
-
function usagePath(env =
|
|
650
|
-
return
|
|
678
|
+
function usagePath(env = process10.env) {
|
|
679
|
+
return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
651
680
|
}
|
|
652
|
-
function usageRecorded(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 =
|
|
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(
|
|
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(
|
|
758
|
-
const styled = takesControlCodes(
|
|
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
|
|
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]),
|
|
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]),
|
|
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 =
|
|
951
|
+
for (let dir = dirname3(realpathSync(entry));; dir = dirname3(dir)) {
|
|
923
952
|
try {
|
|
924
|
-
const { version } = JSON.parse(
|
|
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 (
|
|
957
|
+
if (dirname3(dir) === dir)
|
|
929
958
|
return "0.0.0";
|
|
930
959
|
}
|
|
931
960
|
}
|
|
932
|
-
async function runCli(cli, argv =
|
|
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
|
|
1002
|
-
import { resolve as
|
|
1003
|
-
import
|
|
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
|
|
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",
|
|
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
|
|
1017
|
-
var line = (finding) => ` ${marked(finding.level === "error" ? "problem" : "warn", `[${finding.check}] ${finding.message}`,
|
|
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
|
|
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.`,
|
|
1060
|
+
return marked("ok", `${basename(result.root)}: compose ${result.composeFiles.join(", ")} and release.config.ts agree.`, process13.stdout);
|
|
1030
1061
|
return [
|
|
1031
|
-
...
|
|
1032
|
-
...
|
|
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
|
|
1040
|
-
import { join as
|
|
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
|
|
1044
|
-
import { isAbsolute as isAbsolute2, join as
|
|
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) &&
|
|
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) => !
|
|
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 !== "" && !
|
|
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("~") ?
|
|
1081
|
-
if (!
|
|
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 =
|
|
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
|
-
|
|
1209
|
-
|
|
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(
|
|
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 =
|
|
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" ?
|
|
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 =
|
|
1232
|
-
const text =
|
|
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
|
|
1238
|
-
import { basename as basename2, join as
|
|
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) =>
|
|
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 = [
|
|
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 =
|
|
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 =
|
|
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(
|
|
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(
|
|
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) =>
|
|
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 =
|
|
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:
|
|
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
|
-
|
|
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.
|
|
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.
|
|
31
|
+
"@kaynooo/cli-kit": "0.36.0"
|
|
32
32
|
}
|
|
33
33
|
}
|