@kaynooo/cli-guard 0.11.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +361 -82
- package/package.json +8 -8
package/dist/cli.js
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/cli.ts
|
|
5
|
-
import { appendFileSync as appendFileSync2, existsSync as
|
|
6
|
-
import { homedir as
|
|
7
|
-
import { dirname as
|
|
8
|
-
import
|
|
5
|
+
import { appendFileSync as appendFileSync2, existsSync as existsSync5, mkdirSync as mkdirSync2, readFileSync as readFileSync6, rmSync, statSync as statSync2, writeFileSync } from "fs";
|
|
6
|
+
import { homedir as homedir4 } from "os";
|
|
7
|
+
import { dirname as dirname5 } from "path";
|
|
8
|
+
import process16 from "process";
|
|
9
9
|
// ../kit/src/args.ts
|
|
10
|
-
import
|
|
10
|
+
import process9 from "process";
|
|
11
11
|
import { parseArgs } from "util";
|
|
12
12
|
|
|
13
13
|
// ../kit/src/mode.ts
|
|
@@ -29,7 +29,7 @@ function outputMode(stream = process2.stdout, env = process2.env) {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
// ../kit/src/style.ts
|
|
32
|
-
import
|
|
32
|
+
import process6 from "process";
|
|
33
33
|
|
|
34
34
|
// ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-x450vn3m.js
|
|
35
35
|
var G = /^[a-f0-9]+$/i;
|
|
@@ -86,19 +86,254 @@ function Fe(r = {}) {
|
|
|
86
86
|
}
|
|
87
87
|
var o = Fe();
|
|
88
88
|
|
|
89
|
+
// ../kit/src/theme.ts
|
|
90
|
+
import { existsSync as existsSync3, readFileSync as readFileSync2, statSync } from "fs";
|
|
91
|
+
import { homedir as homedir2 } from "os";
|
|
92
|
+
import { join as join3, resolve as resolve2 } from "path";
|
|
93
|
+
import process5 from "process";
|
|
94
|
+
|
|
95
|
+
// ../kit/src/config.ts
|
|
96
|
+
import { existsSync } from "fs";
|
|
97
|
+
import { dirname, join, resolve } from "path";
|
|
98
|
+
import process3 from "process";
|
|
99
|
+
function findUp(names, from = process3.cwd(), stop = () => false) {
|
|
100
|
+
const wanted = typeof names === "string" ? [names] : names;
|
|
101
|
+
for (let dir = resolve(from);; dir = dirname(dir)) {
|
|
102
|
+
const found = wanted.map((name) => join(dir, name)).find((path) => existsSync(path));
|
|
103
|
+
if (found !== undefined)
|
|
104
|
+
return found;
|
|
105
|
+
if (stop(dir) || dirname(dir) === dir)
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// ../kit/src/user-config.ts
|
|
111
|
+
import { existsSync as existsSync2, readFileSync } from "fs";
|
|
112
|
+
import { homedir } from "os";
|
|
113
|
+
import { join as join2 } from "path";
|
|
114
|
+
import process4 from "process";
|
|
115
|
+
function configBase(where = {}) {
|
|
116
|
+
const xdg = where.xdg ?? (where.home === undefined ? process4.env.XDG_CONFIG_HOME : undefined);
|
|
117
|
+
return xdg !== undefined && xdg !== "" ? xdg : join2(where.home ?? homedir(), ".config");
|
|
118
|
+
}
|
|
119
|
+
function userConfigPath(bin, where = {}) {
|
|
120
|
+
return join2(configBase(where), "kaynooo-cli", `${bin}.json`);
|
|
121
|
+
}
|
|
122
|
+
function userConfigReadPath(bin, legacy = [], where = {}) {
|
|
123
|
+
const current = userConfigPath(bin, where);
|
|
124
|
+
if (existsSync2(current))
|
|
125
|
+
return current;
|
|
126
|
+
const base = configBase(where);
|
|
127
|
+
return legacy.map((parts) => join2(base, ...parts)).find((path) => existsSync2(path)) ?? current;
|
|
128
|
+
}
|
|
129
|
+
function readUserConfig(bin, where = {}, legacy = []) {
|
|
130
|
+
const path = userConfigReadPath(bin, legacy, where);
|
|
131
|
+
if (!existsSync2(path))
|
|
132
|
+
return {};
|
|
133
|
+
try {
|
|
134
|
+
const parsed = Bun.JSONC.parse(readFileSync(path, "utf8"));
|
|
135
|
+
return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed) ? parsed : {};
|
|
136
|
+
} catch {
|
|
137
|
+
return {};
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
function configuredNumber(bin, key, fallback, where = {}, legacy = []) {
|
|
141
|
+
const value = readUserConfig(bin, where, legacy)[key];
|
|
142
|
+
return typeof value === "number" && Number.isInteger(value) && value > 0 ? value : fallback;
|
|
143
|
+
}
|
|
144
|
+
|
|
89
145
|
// ../kit/src/theme.ts
|
|
90
146
|
var ENDS = new Map;
|
|
147
|
+
var DEFAULT = {
|
|
148
|
+
colors: { accent: "cyan", id: "yellow", path: "blue", label: "dim", value: "bold", ok: "green", warn: "yellow", problem: "red", note: "dim", plan: "magenta", passed: "green", failed: "red", running: "cyan", queued: "yellow", skipped: "dim" },
|
|
149
|
+
glyphs: { ok: "\u2713", warn: "\u25B2", problem: "\u2717", note: "\u203A", plan: "\u25C7", passed: "\u2713", failed: "\u2717", running: "\u25CF", queued: "\u25CB", skipped: "-", bar: "\u2501", rule: "\u2500", corner: "\u256D", open: "\u2022", leaf: "\xB7", guide: "\u2502" },
|
|
150
|
+
accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
|
|
151
|
+
bins: {},
|
|
152
|
+
gradient: ["#c084fc", "#67e8f9"]
|
|
153
|
+
};
|
|
154
|
+
var BRIGHT = { accent: "cyanBright", id: "yellowBright", path: "blueBright", label: "white", value: "bold whiteBright", ok: "greenBright", warn: "yellowBright", problem: "redBright", note: "white", plan: "magentaBright", passed: "greenBright", failed: "redBright", running: "cyanBright", queued: "yellowBright", skipped: "white" };
|
|
155
|
+
var MONO = { accent: "bold", id: "bold", path: "underline", label: "dim", value: "bold", ok: "bold", warn: "bold", problem: "bold", note: "dim", plan: "dim", passed: "bold", failed: "bold", running: "bold", queued: "dim", skipped: "dim" };
|
|
156
|
+
var ASCII = { ok: "+", warn: "!", problem: "x", note: ">", plan: "?", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+", open: "*", leaf: "-", guide: "|" };
|
|
157
|
+
var PRESETS = {
|
|
158
|
+
default: {},
|
|
159
|
+
"high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"], gradient: ["#d8b4fe", "#a5f3fc"] },
|
|
160
|
+
mono: { colors: MONO, accents: ["bold"], gradient: undefined },
|
|
161
|
+
ascii: { glyphs: ASCII }
|
|
162
|
+
};
|
|
91
163
|
var STYLES = new Set(["bold", "dim", "italic", "underline", "inverse", "strikethrough", "black", "red", "green", "yellow", "blue", "magenta", "cyan", "white", "gray", "grey", "blackBright", "redBright", "greenBright", "yellowBright", "blueBright", "magentaBright", "cyanBright", "whiteBright"]);
|
|
164
|
+
var HEX = /^#[0-9a-f]{6}$/i;
|
|
165
|
+
var CONTROL = /\p{Cc}/u;
|
|
92
166
|
var MAX_FILE_BYTES = 64 * 1024;
|
|
167
|
+
var SPACES = /\s+/;
|
|
168
|
+
function isColorSpec(spec) {
|
|
169
|
+
if (typeof spec === "number")
|
|
170
|
+
return Number.isInteger(spec) && spec >= 0 && spec <= 255;
|
|
171
|
+
return typeof spec === "string" && spec.trim() !== "" && spec.trim().split(SPACES).every((token) => STYLES.has(token) || HEX.test(token));
|
|
172
|
+
}
|
|
173
|
+
var CUBE = [0, 95, 135, 175, 215, 255];
|
|
174
|
+
function cubeLevel(channel) {
|
|
175
|
+
return CUBE.reduce((best, value, level) => Math.abs(value - channel) < Math.abs(CUBE[best] - channel) ? level : best, 0);
|
|
176
|
+
}
|
|
177
|
+
function nearest256(hex) {
|
|
178
|
+
const rgb = [1, 3, 5].map((at) => Number.parseInt(hex.slice(at, at + 2), 16));
|
|
179
|
+
const levels = rgb.map(cubeLevel);
|
|
180
|
+
const cube = levels.map((level) => CUBE[level]);
|
|
181
|
+
const grey = Math.min(23, Math.max(0, Math.round((rgb.reduce((sum, channel) => sum + channel, 0) / 3 - 8) / 10)));
|
|
182
|
+
const greyValue = 8 + grey * 10;
|
|
183
|
+
const distance = (colour) => colour.reduce((sum, channel, at) => sum + (channel - rgb[at]) ** 2, 0);
|
|
184
|
+
return distance([greyValue, greyValue, greyValue]) < distance(cube) ? 232 + grey : 16 + 36 * levels[0] + 6 * levels[1] + levels[2];
|
|
185
|
+
}
|
|
186
|
+
function hasTrueColor(env) {
|
|
187
|
+
return env.COLORTERM === "truecolor" || env.COLORTERM === "24bit";
|
|
188
|
+
}
|
|
189
|
+
function tinted(colors, spec, env = process5.env) {
|
|
190
|
+
if (typeof spec === "number")
|
|
191
|
+
return colors.ansi256(spec);
|
|
192
|
+
return spec.trim().split(SPACES).reduce((chain, token) => {
|
|
193
|
+
if (HEX.test(token))
|
|
194
|
+
return hasTrueColor(env) ? chain.hex(token) : chain.ansi256(nearest256(token));
|
|
195
|
+
return chain[token] ?? chain;
|
|
196
|
+
}, colors);
|
|
197
|
+
}
|
|
198
|
+
function isRecord(value) {
|
|
199
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
200
|
+
}
|
|
201
|
+
function readThemeFile(path, warn) {
|
|
202
|
+
try {
|
|
203
|
+
const stat = statSync(path, { throwIfNoEntry: false });
|
|
204
|
+
if (stat === undefined)
|
|
205
|
+
return;
|
|
206
|
+
if (!stat.isFile() || stat.size > MAX_FILE_BYTES) {
|
|
207
|
+
warn(`${path} is not a regular file under ${MAX_FILE_BYTES / 1024} KiB, theme ignored`);
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
const parsed = JSON.parse(readFileSync2(path, "utf8"));
|
|
211
|
+
if (isRecord(parsed))
|
|
212
|
+
return parsed;
|
|
213
|
+
warn(`${path} is not a JSON object, theme ignored`);
|
|
214
|
+
} catch (error) {
|
|
215
|
+
warn(`${path} does not parse (${error instanceof Error ? error.message : String(error)}), theme ignored`);
|
|
216
|
+
}
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
function applyPreset(theme, name, warn, where) {
|
|
220
|
+
if (name === undefined)
|
|
221
|
+
return;
|
|
222
|
+
if (typeof name !== "string" || !Object.hasOwn(PRESETS, name)) {
|
|
223
|
+
warn(`${where}: no preset ${String(name)}, one of ${Object.keys(PRESETS).join(", ")}`);
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
const preset = PRESETS[name];
|
|
227
|
+
Object.assign(theme.colors, preset.colors);
|
|
228
|
+
Object.assign(theme.glyphs, preset.glyphs);
|
|
229
|
+
if (preset.accents !== undefined)
|
|
230
|
+
theme.accents = [...preset.accents];
|
|
231
|
+
if (Object.hasOwn(preset, "gradient"))
|
|
232
|
+
theme.gradient = preset.gradient;
|
|
233
|
+
return name;
|
|
234
|
+
}
|
|
235
|
+
function applyFile(theme, file, where, warn) {
|
|
236
|
+
if (isRecord(file.colors)) {
|
|
237
|
+
for (const [key, value] of Object.entries(file.colors)) {
|
|
238
|
+
if (!Object.hasOwn(DEFAULT.colors, key))
|
|
239
|
+
warn(`${where}: no colour ${key}, one of ${Object.keys(DEFAULT.colors).join(", ")}`);
|
|
240
|
+
else if (!isColorSpec(value))
|
|
241
|
+
warn(`${where}: colour ${key} is not an ANSI name, \`#rrggbb\` or a number up to 255`);
|
|
242
|
+
else
|
|
243
|
+
theme.colors[key] = value;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
if (isRecord(file.glyphs)) {
|
|
247
|
+
for (const [key, value] of Object.entries(file.glyphs)) {
|
|
248
|
+
if (!Object.hasOwn(DEFAULT.glyphs, key))
|
|
249
|
+
warn(`${where}: no glyph ${key}, one of ${Object.keys(DEFAULT.glyphs).join(", ")}`);
|
|
250
|
+
else if (typeof value !== "string" || CONTROL.test(value) || Bun.stringWidth(value) !== 1)
|
|
251
|
+
warn(`${where}: glyph ${key} must be one visible character wide, with no control character`);
|
|
252
|
+
else
|
|
253
|
+
theme.glyphs[key] = value;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
if (Array.isArray(file.accents) && file.accents.length > 0 && file.accents.every(isColorSpec))
|
|
257
|
+
theme.accents = [...file.accents];
|
|
258
|
+
else if (file.accents !== undefined)
|
|
259
|
+
warn(`${where}: accents must be a non-empty list of colours`);
|
|
260
|
+
if (file.gradient === null)
|
|
261
|
+
theme.gradient = undefined;
|
|
262
|
+
else if (Array.isArray(file.gradient) && file.gradient.length === 2 && file.gradient.every((end) => typeof end === "string" && HEX.test(end)))
|
|
263
|
+
theme.gradient = [file.gradient[0], file.gradient[1]];
|
|
264
|
+
else if (file.gradient !== undefined)
|
|
265
|
+
warn(`${where}: gradient must be two \`#rrggbb\` colours, or null for none`);
|
|
266
|
+
if (isRecord(file.bins)) {
|
|
267
|
+
for (const [bin, value] of Object.entries(file.bins)) {
|
|
268
|
+
if (isColorSpec(value))
|
|
269
|
+
theme.bins[bin] = value;
|
|
270
|
+
else
|
|
271
|
+
warn(`${where}: bin ${bin} has no valid colour`);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
function endsWalk(home) {
|
|
276
|
+
return (dir) => dir === resolve2(home) || existsSync3(join3(dir, ".git"));
|
|
277
|
+
}
|
|
93
278
|
var warned = new Set;
|
|
279
|
+
function warnOnce(message) {
|
|
280
|
+
if (warned.has(message))
|
|
281
|
+
return;
|
|
282
|
+
warned.add(message);
|
|
283
|
+
console.error(`warning: theme ${message}`);
|
|
284
|
+
}
|
|
285
|
+
function isPath(chosen) {
|
|
286
|
+
return chosen.includes("/") || chosen.endsWith(".json");
|
|
287
|
+
}
|
|
288
|
+
function loadTheme({ env = process5.env, from = process5.cwd(), home = homedir2(), warn = warnOnce } = {}) {
|
|
289
|
+
const theme = { colors: { ...DEFAULT.colors }, glyphs: { ...DEFAULT.glyphs }, accents: [...DEFAULT.accents], bins: Object.create(null), gradient: DEFAULT.gradient };
|
|
290
|
+
const sources = [];
|
|
291
|
+
const chosen = env.KIT_THEME ?? "";
|
|
292
|
+
const wanted = chosen === "" ? [userConfigPath("theme", { home, xdg: env.XDG_CONFIG_HOME }), findUp(join3(".kaynooo", "theme.json"), from, endsWalk(home))] : [];
|
|
293
|
+
if (isPath(chosen))
|
|
294
|
+
wanted.push(resolve2(from, chosen));
|
|
295
|
+
const files = [];
|
|
296
|
+
for (const path of wanted) {
|
|
297
|
+
const file = path === undefined ? undefined : readThemeFile(path, warn);
|
|
298
|
+
if (path !== undefined && file !== undefined)
|
|
299
|
+
files.push({ path, file });
|
|
300
|
+
}
|
|
301
|
+
let preset = "default";
|
|
302
|
+
if (chosen !== "" && !isPath(chosen)) {
|
|
303
|
+
preset = applyPreset(theme, chosen, warn, "KIT_THEME") ?? preset;
|
|
304
|
+
} else {
|
|
305
|
+
const named = files.findLast(({ file }) => file.preset !== undefined);
|
|
306
|
+
if (named !== undefined)
|
|
307
|
+
preset = applyPreset(theme, named.file.preset, warn, named.path) ?? preset;
|
|
308
|
+
}
|
|
309
|
+
for (const { path, file } of files) {
|
|
310
|
+
applyFile(theme, file, path, warn);
|
|
311
|
+
sources.push(path);
|
|
312
|
+
}
|
|
313
|
+
return { theme, sources, preset };
|
|
314
|
+
}
|
|
315
|
+
var current;
|
|
316
|
+
var currentKey = "";
|
|
317
|
+
function activeTheme() {
|
|
318
|
+
const key = `${process5.cwd()}\x00${process5.env.KIT_THEME ?? ""}\x00${process5.env.XDG_CONFIG_HOME ?? ""}`;
|
|
319
|
+
if (current === undefined || key !== currentKey) {
|
|
320
|
+
current = loadTheme();
|
|
321
|
+
currentKey = key;
|
|
322
|
+
}
|
|
323
|
+
return current;
|
|
324
|
+
}
|
|
94
325
|
|
|
95
326
|
// ../kit/src/style.ts
|
|
96
|
-
function takesControlCodes(stream, env =
|
|
327
|
+
function takesControlCodes(stream, env = process6.env) {
|
|
97
328
|
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
|
|
98
329
|
}
|
|
99
|
-
function paint(stream, env =
|
|
330
|
+
function paint(stream, env = process6.env) {
|
|
100
331
|
return Fe({ stream: { isTTY: takesControlCodes(stream, env) }, env });
|
|
101
332
|
}
|
|
333
|
+
function role(name, stream, env = process6.env) {
|
|
334
|
+
const colors = paint(stream, env);
|
|
335
|
+
return takesControlCodes(stream, env) ? tinted(colors, activeTheme().theme.colors[name], env) : colors;
|
|
336
|
+
}
|
|
102
337
|
var STATUS_WORDS = {
|
|
103
338
|
passed: ["passed", "success", "succeeded", "ok"],
|
|
104
339
|
failed: ["failed", "failure", "error", "errored"],
|
|
@@ -116,27 +351,27 @@ function upTo(text, separator) {
|
|
|
116
351
|
var ESCAPE = String.fromCharCode(27);
|
|
117
352
|
|
|
118
353
|
// ../kit/src/help.ts
|
|
119
|
-
import
|
|
354
|
+
import process7 from "process";
|
|
120
355
|
var OPTIONAL = /\[[^\]]+\]/g;
|
|
121
356
|
var USAGE_PREFIX = /^usage:\s*/i;
|
|
122
357
|
var FULL_STOP = /\.$/;
|
|
123
|
-
function usageLine(usage, colors = paint(
|
|
358
|
+
function usageLine(usage, colors = paint(process7.stdout)) {
|
|
124
359
|
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
125
360
|
}
|
|
126
|
-
function helpText(usage, options, colors = paint(
|
|
361
|
+
function helpText(usage, options, colors = paint(process7.stdout), { examples = [], replaces, exits = [] } = {}) {
|
|
127
362
|
return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
128
363
|
`);
|
|
129
364
|
}
|
|
130
|
-
function exitRows(exits, colors = paint(
|
|
365
|
+
function exitRows(exits, colors = paint(process7.stdout)) {
|
|
131
366
|
if (exits.length === 0)
|
|
132
367
|
return [];
|
|
133
368
|
const width = Math.max(...exits.map(([code]) => String(code).length));
|
|
134
369
|
return ["", colors.bold("Exits:"), ...exits.map(([code, meaning]) => ` ${colors.cyan(String(code).padEnd(width))} ${meaning}`)];
|
|
135
370
|
}
|
|
136
|
-
function replacesRows(replaces, colors = paint(
|
|
371
|
+
function replacesRows(replaces, colors = paint(process7.stdout)) {
|
|
137
372
|
return replaces === undefined || outputMode() === "agent" ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
138
373
|
}
|
|
139
|
-
function wantsHelpJson(env =
|
|
374
|
+
function wantsHelpJson(env = process7.env) {
|
|
140
375
|
return env.KIT_HELP === "json";
|
|
141
376
|
}
|
|
142
377
|
function description(usage, { examples = [], replaces, exits } = {}, options) {
|
|
@@ -155,12 +390,12 @@ function description(usage, { examples = [], replaces, exits } = {}, options) {
|
|
|
155
390
|
...options === undefined ? {} : { options: Object.entries(options).map(([name, { short, description }]) => ({ name, ...short === undefined ? {} : { short }, ...description === undefined ? {} : { description } })) }
|
|
156
391
|
};
|
|
157
392
|
}
|
|
158
|
-
function exampleRows(examples, colors = paint(
|
|
393
|
+
function exampleRows(examples, colors = paint(process7.stdout)) {
|
|
159
394
|
if (examples.length === 0 || outputMode() === "agent")
|
|
160
395
|
return [];
|
|
161
396
|
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
162
397
|
}
|
|
163
|
-
function optionRows(options, colors = paint(
|
|
398
|
+
function optionRows(options, colors = paint(process7.stdout)) {
|
|
164
399
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
165
400
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
166
401
|
const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
|
|
@@ -192,10 +427,10 @@ function closest(name, names) {
|
|
|
192
427
|
return best !== undefined && best.far <= (name.length < 4 ? 1 : 2) ? best.known : undefined;
|
|
193
428
|
}
|
|
194
429
|
// ../kit/src/input.ts
|
|
195
|
-
import
|
|
430
|
+
import process8 from "process";
|
|
196
431
|
async function readInput(path, { noStdin = "nothing is piped on stdin" } = {}) {
|
|
197
432
|
if (path === "-") {
|
|
198
|
-
if (
|
|
433
|
+
if (process8.stdin.isTTY)
|
|
199
434
|
fail(noStdin);
|
|
200
435
|
return Bun.stdin.text();
|
|
201
436
|
}
|
|
@@ -253,7 +488,7 @@ var OUTPUT_OPTIONS = {
|
|
|
253
488
|
color: { type: "string", description: "auto (on a terminal alone), always or never" },
|
|
254
489
|
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
255
490
|
};
|
|
256
|
-
function applyOutput(color, plain, env =
|
|
491
|
+
function applyOutput(color, plain, env = process9.env) {
|
|
257
492
|
const when = plain === true ? "never" : color ?? "auto";
|
|
258
493
|
if (when === "auto")
|
|
259
494
|
return;
|
|
@@ -422,9 +657,33 @@ function nearestOption(message, options, allowNegative) {
|
|
|
422
657
|
const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
|
|
423
658
|
return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
|
|
424
659
|
}
|
|
660
|
+
// ../kit/src/argv.ts
|
|
661
|
+
import { readFileSync as readFileSync3, realpathSync } from "fs";
|
|
662
|
+
import { resolve as resolve3 } from "path";
|
|
663
|
+
import process10 from "process";
|
|
664
|
+
function commandLine() {
|
|
665
|
+
try {
|
|
666
|
+
return readFileSync3("/proc/self/cmdline", "utf8").split("\x00").slice(0, -1);
|
|
667
|
+
} catch {
|
|
668
|
+
return;
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
function realPath(word) {
|
|
672
|
+
try {
|
|
673
|
+
return realpathSync(resolve3(word));
|
|
674
|
+
} catch {
|
|
675
|
+
return;
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
function scriptArgs(argv = process10.argv.slice(2), cmdline = commandLine(), script = process10.argv[1]) {
|
|
679
|
+
const target = script === undefined ? undefined : realPath(script) ?? script;
|
|
680
|
+
const at = cmdline === undefined || target === undefined ? -1 : cmdline.findIndex((word, index) => index > 0 && (resolve3(word) === script || realPath(word) === target));
|
|
681
|
+
const after = at === -1 ? [] : cmdline.slice(at + 1);
|
|
682
|
+
return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
|
|
683
|
+
}
|
|
425
684
|
// ../kit/src/process.ts
|
|
426
685
|
import { constants } from "os";
|
|
427
|
-
import
|
|
686
|
+
import process11 from "process";
|
|
428
687
|
var KILL_GRACE_MS = 2000;
|
|
429
688
|
function exitCodeOf(code, signal) {
|
|
430
689
|
if (code !== null)
|
|
@@ -444,7 +703,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
|
|
|
444
703
|
return;
|
|
445
704
|
try {
|
|
446
705
|
if (grouped)
|
|
447
|
-
|
|
706
|
+
process11.kill(-proc.pid, killing);
|
|
448
707
|
else
|
|
449
708
|
proc.kill(killing);
|
|
450
709
|
} catch {}
|
|
@@ -518,15 +777,15 @@ var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x
|
|
|
518
777
|
var RESET_STYLE = `${ESC}[0m`;
|
|
519
778
|
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
520
779
|
// ../kit/src/cli.ts
|
|
521
|
-
import { readFileSync, realpathSync } from "fs";
|
|
522
|
-
import { dirname as
|
|
523
|
-
import
|
|
780
|
+
import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs";
|
|
781
|
+
import { dirname as dirname3, join as join5 } from "path";
|
|
782
|
+
import process13 from "process";
|
|
524
783
|
|
|
525
784
|
// ../kit/src/usage.ts
|
|
526
785
|
import { appendFileSync, mkdirSync } from "fs";
|
|
527
|
-
import { homedir } from "os";
|
|
528
|
-
import { dirname, isAbsolute, join } from "path";
|
|
529
|
-
import
|
|
786
|
+
import { homedir as homedir3 } from "os";
|
|
787
|
+
import { dirname as dirname2, isAbsolute, join as join4 } from "path";
|
|
788
|
+
import process12 from "process";
|
|
530
789
|
|
|
531
790
|
// ../kit/src/logs.ts
|
|
532
791
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -540,14 +799,14 @@ var usageError;
|
|
|
540
799
|
function noteUsageError(message) {
|
|
541
800
|
usageError = message;
|
|
542
801
|
}
|
|
543
|
-
function stateHome(env =
|
|
802
|
+
function stateHome(env = process12.env) {
|
|
544
803
|
const dir = env.XDG_STATE_HOME;
|
|
545
|
-
return dir !== undefined && isAbsolute(dir) ? dir :
|
|
804
|
+
return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
|
|
546
805
|
}
|
|
547
|
-
function usagePath(env =
|
|
548
|
-
return
|
|
806
|
+
function usagePath(env = process12.env) {
|
|
807
|
+
return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
549
808
|
}
|
|
550
|
-
function usageRecorded(env =
|
|
809
|
+
function usageRecorded(env = process12.env) {
|
|
551
810
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
552
811
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
553
812
|
}
|
|
@@ -561,12 +820,12 @@ function usageEntry(bin, command, argv, code, now = new Date) {
|
|
|
561
820
|
usageError = undefined;
|
|
562
821
|
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
563
822
|
}
|
|
564
|
-
function recordUsage(entry, env =
|
|
823
|
+
function recordUsage(entry, env = process12.env) {
|
|
565
824
|
if (!usageRecorded(env))
|
|
566
825
|
return;
|
|
567
826
|
try {
|
|
568
827
|
const path = usagePath(env);
|
|
569
|
-
mkdirSync(
|
|
828
|
+
mkdirSync(dirname2(path), { recursive: true, mode: 448 });
|
|
570
829
|
appendFileSync(path, `${JSON.stringify(entry)}
|
|
571
830
|
`, { mode: 384 });
|
|
572
831
|
} catch {}
|
|
@@ -652,8 +911,8 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
|
|
|
652
911
|
`);
|
|
653
912
|
}
|
|
654
913
|
function printError(prefix, message, hint, cause) {
|
|
655
|
-
const colors = paint(
|
|
656
|
-
const styled = takesControlCodes(
|
|
914
|
+
const colors = paint(process13.stderr);
|
|
915
|
+
const styled = takesControlCodes(process13.stderr);
|
|
657
916
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
658
917
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
659
918
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -696,11 +955,11 @@ async function dispatch(level, typed, { version, redact }) {
|
|
|
696
955
|
}
|
|
697
956
|
}
|
|
698
957
|
if (name === undefined && level.path.length > 1) {
|
|
699
|
-
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
958
|
+
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process13.stderr));
|
|
700
959
|
return 2;
|
|
701
960
|
}
|
|
702
961
|
if (name === undefined || name === "help" || name === "--help" || name === "-h") {
|
|
703
|
-
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
962
|
+
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process13.stdout));
|
|
704
963
|
return 0;
|
|
705
964
|
}
|
|
706
965
|
if (level.path.length === 1 && (name === "--version" || name === "-v")) {
|
|
@@ -756,24 +1015,24 @@ function candidateLine(candidate) {
|
|
|
756
1015
|
}
|
|
757
1016
|
function positionalBeingTyped(before, { options, positionals }) {
|
|
758
1017
|
const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
|
|
759
|
-
|
|
1018
|
+
const typed = [];
|
|
760
1019
|
let at = 0;
|
|
761
1020
|
while (at < before.length) {
|
|
762
1021
|
const word = before[at];
|
|
763
1022
|
if (word === "--") {
|
|
764
|
-
|
|
1023
|
+
typed.push(...before.slice(at + 1));
|
|
765
1024
|
break;
|
|
766
1025
|
}
|
|
767
1026
|
if (!word.startsWith("-"))
|
|
768
|
-
|
|
1027
|
+
typed.push(word);
|
|
769
1028
|
else if (takesValue(word))
|
|
770
1029
|
at++;
|
|
771
1030
|
at++;
|
|
772
1031
|
}
|
|
773
1032
|
const last = positionals.at(-1);
|
|
774
|
-
if (
|
|
775
|
-
return positionals[
|
|
776
|
-
return last?.replace("]", "").endsWith("...") === true ? last : undefined;
|
|
1033
|
+
if (typed.length < positionals.length)
|
|
1034
|
+
return { name: positionals[typed.length], typed };
|
|
1035
|
+
return { name: last?.replace("]", "").endsWith("...") === true ? last : undefined, typed };
|
|
777
1036
|
}
|
|
778
1037
|
async function leafCandidates(run, words) {
|
|
779
1038
|
const completing = await completingOf(run);
|
|
@@ -781,12 +1040,12 @@ async function leafCandidates(run, words) {
|
|
|
781
1040
|
return Object.entries(completing.options).map(([name, option]) => option.description === undefined ? `--${name}` : `--${name} ${option.description}`);
|
|
782
1041
|
const flag = words.at(-2);
|
|
783
1042
|
const option = flag?.startsWith("-") === true ? Object.entries(completing.options).find(([name, { short }]) => flag === `--${name}` || flag === `-${short}`)?.[1] : undefined;
|
|
1043
|
+
const { name, typed } = positionalBeingTyped(words.slice(0, -1), completing);
|
|
784
1044
|
if (option?.type === "string") {
|
|
785
|
-
const values = option.choices === undefined ? await option.candidates?.() : option.choices;
|
|
1045
|
+
const values = option.choices === undefined ? await option.candidates?.(typed) : option.choices;
|
|
786
1046
|
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
787
1047
|
}
|
|
788
|
-
const
|
|
789
|
-
const values = name === undefined ? undefined : await completing.candidates[name]?.();
|
|
1048
|
+
const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
|
|
790
1049
|
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
791
1050
|
}
|
|
792
1051
|
async function candidates(scope, defaultCommand, words, before = []) {
|
|
@@ -817,17 +1076,21 @@ async function printCandidates(found) {
|
|
|
817
1076
|
return 0;
|
|
818
1077
|
}
|
|
819
1078
|
function packageVersion(entry = Bun.main) {
|
|
820
|
-
|
|
1079
|
+
let resolved = entry;
|
|
1080
|
+
try {
|
|
1081
|
+
resolved = realpathSync2(entry);
|
|
1082
|
+
} catch {}
|
|
1083
|
+
for (let dir = dirname3(resolved);; dir = dirname3(dir)) {
|
|
821
1084
|
try {
|
|
822
|
-
const { version } = JSON.parse(
|
|
1085
|
+
const { version } = JSON.parse(readFileSync4(join5(dir, "package.json"), "utf8"));
|
|
823
1086
|
if (typeof version === "string")
|
|
824
1087
|
return version;
|
|
825
1088
|
} catch {}
|
|
826
|
-
if (
|
|
1089
|
+
if (dirname3(dir) === dir)
|
|
827
1090
|
return "0.0.0";
|
|
828
1091
|
}
|
|
829
1092
|
}
|
|
830
|
-
async function runCli(cli, argv =
|
|
1093
|
+
async function runCli(cli, argv = scriptArgs()) {
|
|
831
1094
|
const version = cli.version ?? packageVersion();
|
|
832
1095
|
if (argv[0] === COMPLETE)
|
|
833
1096
|
return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
|
|
@@ -856,6 +1119,11 @@ function commandPath(scope, argv) {
|
|
|
856
1119
|
}
|
|
857
1120
|
// ../kit/src/folders.ts
|
|
858
1121
|
var SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
|
|
1122
|
+
function ignoredFolders(extra = [], where = {}) {
|
|
1123
|
+
const configured = readUserConfig("config", where).ignore;
|
|
1124
|
+
const names = Array.isArray(configured) ? configured.filter((name) => typeof name === "string" && name !== "") : [];
|
|
1125
|
+
return new Set([...SKIPPED_FOLDERS, ...extra, ...names]);
|
|
1126
|
+
}
|
|
859
1127
|
// ../kit/src/secrets.ts
|
|
860
1128
|
var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
|
|
861
1129
|
// ../kit/src/sessions.ts
|
|
@@ -1923,7 +2191,7 @@ function printsTrackedEnv(program, args) {
|
|
|
1923
2191
|
// ../env/src/files.ts
|
|
1924
2192
|
var ENV_FILE = /^(?:\.env(?:\..+)?|.+\.env|\.envrc)$/;
|
|
1925
2193
|
var TEMPLATE = /\.(?:example|sample|template|dist|defaults)$/;
|
|
1926
|
-
var SKIPPED =
|
|
2194
|
+
var SKIPPED = ignoredFolders([".git", ".kay"]);
|
|
1927
2195
|
|
|
1928
2196
|
// ../env/src/guard-paths.ts
|
|
1929
2197
|
var REDIRECT = /^\d*[<>]+&?/;
|
|
@@ -2294,7 +2562,10 @@ function commitMessageViolation(message) {
|
|
|
2294
2562
|
}
|
|
2295
2563
|
|
|
2296
2564
|
// ../out/src/fold.ts
|
|
2297
|
-
var FOLD_LINES = 150;
|
|
2565
|
+
var FOLD_LINES = configuredNumber("out", "lines", 150);
|
|
2566
|
+
var HEAD = configuredNumber("out", "head", 40);
|
|
2567
|
+
var TAIL = configuredNumber("out", "tail", 60);
|
|
2568
|
+
var MAX_WIDTH = configuredNumber("out", "width", 300);
|
|
2298
2569
|
|
|
2299
2570
|
// ../out/src/wrap.ts
|
|
2300
2571
|
var ASSIGNMENT4 = /^\w+=/;
|
|
@@ -2425,9 +2696,9 @@ function wrap(command) {
|
|
|
2425
2696
|
}
|
|
2426
2697
|
|
|
2427
2698
|
// ../pkg/src/added.ts
|
|
2428
|
-
import { existsSync, readdirSync, readFileSync as
|
|
2429
|
-
import { dirname as
|
|
2430
|
-
import
|
|
2699
|
+
import { existsSync as existsSync4, readdirSync, readFileSync as readFileSync5 } from "fs";
|
|
2700
|
+
import { dirname as dirname4, join as join6 } from "path";
|
|
2701
|
+
import process15 from "process";
|
|
2431
2702
|
var REDIRECT2 = /^\d*[<>]/;
|
|
2432
2703
|
var BARE_REDIRECT = /^\d*(?:[<>]|>>)$/;
|
|
2433
2704
|
var ADDS = {
|
|
@@ -2451,7 +2722,7 @@ var PUBLISH = /\b(?:ft|cli\.ts)\s+release\b|\b(?:bun|npm|pnpm|yarn)\s+publish\b|
|
|
|
2451
2722
|
var EXACT_SPEC = /^(?:@[^/]+\/)?[^@]+@\d+\.\d+\.\d+(?:[-+][\w.+-]+)?$/;
|
|
2452
2723
|
function manifestName(folder) {
|
|
2453
2724
|
try {
|
|
2454
|
-
const { name } = JSON.parse(
|
|
2725
|
+
const { name } = JSON.parse(readFileSync5(join6(folder, "package.json"), "utf8"));
|
|
2455
2726
|
return typeof name === "string" ? name : undefined;
|
|
2456
2727
|
} catch {
|
|
2457
2728
|
return;
|
|
@@ -2459,19 +2730,19 @@ function manifestName(folder) {
|
|
|
2459
2730
|
}
|
|
2460
2731
|
function ownPackages() {
|
|
2461
2732
|
const names = new Set;
|
|
2462
|
-
let folder =
|
|
2733
|
+
let folder = process15.cwd();
|
|
2463
2734
|
while (true) {
|
|
2464
2735
|
const name = manifestName(folder);
|
|
2465
2736
|
if (name !== undefined)
|
|
2466
2737
|
names.add(name);
|
|
2467
|
-
for (const member of
|
|
2468
|
-
const memberName = manifestName(
|
|
2738
|
+
for (const member of existsSync4(join6(folder, "packages")) ? readdirSync(join6(folder, "packages")) : []) {
|
|
2739
|
+
const memberName = manifestName(join6(folder, "packages", member));
|
|
2469
2740
|
if (memberName !== undefined)
|
|
2470
2741
|
names.add(memberName);
|
|
2471
2742
|
}
|
|
2472
|
-
if (
|
|
2743
|
+
if (existsSync4(join6(folder, ".git")) || dirname4(folder) === folder)
|
|
2473
2744
|
return names;
|
|
2474
|
-
folder =
|
|
2745
|
+
folder = dirname4(folder);
|
|
2475
2746
|
}
|
|
2476
2747
|
}
|
|
2477
2748
|
function specName(spec) {
|
|
@@ -2660,9 +2931,14 @@ var STAGE_BY_PATH = `Stage by path: the tree carries unrelated work and peer ses
|
|
|
2660
2931
|
var STASH = "Never `git stash`: a pop with nothing saved applies someone else's old stash. To prove a test fails without your change, `proof --keep <test> -- <cmd>` runs it at HEAD in a temporary worktree and again here; `base -- <cmd>` runs any command at HEAD (`--ref <rev>` another commit), the working tree untouched. To set edits aside before a cherry-pick, a rebase or a checkout, commit them with `gc` first, or do the other work in `git worktree add`.";
|
|
2661
2932
|
var ADD_ALL = `\`git add\` over the whole tree is refused. ${STAGE_BY_PATH}`;
|
|
2662
2933
|
var COMMIT_ALL = `\`git commit -a\` stages the whole tree and is refused. ${STAGE_BY_PATH}`;
|
|
2663
|
-
var PUSH = "`git push`
|
|
2934
|
+
var PUSH = "`git push` and `gp` run only when the user asked for a push in their latest prompt: say the commit is ready and let them ask.";
|
|
2664
2935
|
var CONFIG_OVERRIDE = "Never set git config that runs a program or defines a command (`-c alias.*`, `--config-env`, `core.sshCommand`, `core.hooksPath`, `core.pager`, credential helpers, `git config alias.*`): it sidesteps every rule here. Run the git command itself.";
|
|
2665
2936
|
var TAGS_APART = "A tag goes out with its branch in one `git push --atomic origin <branch> <tag>`, never a separate `git push --tags`.";
|
|
2937
|
+
function gitCommandOf(program, args) {
|
|
2938
|
+
if (program === "gp")
|
|
2939
|
+
return { name: "push", rest: args.includes("--") ? args.slice(args.indexOf("--") + 1) : [] };
|
|
2940
|
+
return program === "git" ? subcommandOf(args) : undefined;
|
|
2941
|
+
}
|
|
2666
2942
|
function subcommandOf(args) {
|
|
2667
2943
|
for (let i = 0;i < args.length; i++) {
|
|
2668
2944
|
const arg = args[i] ?? "";
|
|
@@ -2732,11 +3008,12 @@ function gitViolation(command, isPushAsked = false) {
|
|
|
2732
3008
|
const { program, args, assignments } = parseCommand(piece.command);
|
|
2733
3009
|
if (assignments.some((assignment) => RISKY_ENV.test(assignment)))
|
|
2734
3010
|
return CONFIG_OVERRIDE;
|
|
2735
|
-
|
|
3011
|
+
const git = gitCommandOf(program, args);
|
|
3012
|
+
if (git === undefined)
|
|
2736
3013
|
continue;
|
|
2737
|
-
if (overridesConfig(args))
|
|
3014
|
+
if (program === "git" && overridesConfig(args))
|
|
2738
3015
|
return CONFIG_OVERRIDE;
|
|
2739
|
-
const { name, rest } =
|
|
3016
|
+
const { name, rest } = git;
|
|
2740
3017
|
if (name === "config" && rest.length > 1 && rest.some((arg) => RISKY_CONFIG.test(arg)) && !rest.some((arg) => READS_CONFIG.has(arg)))
|
|
2741
3018
|
return CONFIG_OVERRIDE;
|
|
2742
3019
|
if (name === "stash" && !READ_ONLY_STASH.has(rest[0] ?? ""))
|
|
@@ -3020,10 +3297,10 @@ function destructiveViolation(command) {
|
|
|
3020
3297
|
const { program, args } = parseCommand(piece.command);
|
|
3021
3298
|
if (program === "rm" && removesBroadly(args))
|
|
3022
3299
|
return BROAD_RM;
|
|
3023
|
-
|
|
3300
|
+
const git = gitCommandOf(program, args);
|
|
3301
|
+
if (git === undefined)
|
|
3024
3302
|
continue;
|
|
3025
|
-
const
|
|
3026
|
-
const violation = gitDestructive(name, rest);
|
|
3303
|
+
const violation = gitDestructive(git.name, git.rest);
|
|
3027
3304
|
if (violation !== null)
|
|
3028
3305
|
return violation;
|
|
3029
3306
|
}
|
|
@@ -3573,8 +3850,10 @@ var BINS = {
|
|
|
3573
3850
|
sub: "`sub --from <text> --to <text> <file>...`: replaces text, writing nothing unless each match count is as expected (1, `-n N`, `--all`), `--regex`, `--dry-run --diff`; multi-line text goes as SEARCH/REPLACE blocks on stdin from a quoted heredoc (`sub <file> <<'EOF'`, see `sub --help`), no escaping; use it instead of sed -i, a bun -e or python editor.",
|
|
3574
3851
|
base: "`base [--ref <rev>] [--keep <path>...] -- <cmd>`: runs a command at HEAD (or a ref) in a temporary worktree, removed afterwards, ignored env files and node_modules/vendor linked; use it instead of git stash to see whether a test fails without your change (`--keep` the new test).",
|
|
3575
3852
|
proof: "`proof [--ref <rev>] [--keep <path>...] -- <cmd>`: runs the command at HEAD (or a ref) in a temporary worktree, then in the working tree, and exits 0 only when it fails before and passes now, printing the failing side's output; use it to prove a new test fails without your change (`--keep` the test).",
|
|
3576
|
-
gst: "`gst [--log N]`: branch, upstream, changed counts and HEAD in one line, then the changed paths by staged, unstaged and untracked; use it instead of `git status --short` and `git log --oneline`.",
|
|
3853
|
+
gst: "`gst [--log N]`: branch, upstream, changed counts and HEAD in one line, then the changed paths by staged, unstaged and untracked, `gst --repos` one line per repository nested below; use it instead of `git status --short` and `git log --oneline`.",
|
|
3577
3854
|
gc: "`gc <title> [-m <line>]... [--ticket <line>]... -- <path>...`: commits exactly those paths, refusing with nothing staged when the message breaks a commit rule, a path has no change or other files are already staged; use it instead of chaining git add, status and commit.",
|
|
3855
|
+
gp: "`gp [--repos] [dir]...`: pushes the current branch when it is ahead of its upstream, with `-u` to origin when it has none, `--repos` every repository nested below too, `--dry-run` saying what would go, flags for git push after `--`; only when the user asked for a push, like `git push`.",
|
|
3856
|
+
gb: "`gb [branch]`: switches to a branch, a remote one getting its tracking branch, `gb -c <name>` creating one; without a terminal it lists the branches (`--json`), with how each stands against its upstream and whether it is merged.",
|
|
3578
3857
|
waitfor: "`waitfor --file <log> --until <regex> [--fail <regex>]`, `--port <n>`, `--url <url>`, `--pid <n>` (`-t 5m`): waits until the line shows, the port listens, the URL answers 2xx or the process exits, exits 1 on a --fail line with the lines around it, 2 on a timeout with the last lines; `waitfor task <id>` waits for a background Bash task and prints its exit code, last lines and failure lines; use it instead of sleep and tail, `until ! pgrep -f` or polling loops.",
|
|
3579
3858
|
slot: "`slot [-l <lock>] -- <cmd>`: waits for one of the machine-wide slots shared by every session (half the CPUs), then runs the command; `--lock <name>` also holds a named lock for what must not run twice (a shared test database), `slot ls` lists holders and waiters; run heavy jobs (phpunit, playwright, vue-tsc, a full test suite) through it instead of a flock wrapper.",
|
|
3580
3859
|
gl: "`gl ci [ref]` waits for the GitLab pipeline covering a commit and prints each failed job's tests (exit 0/1/2), `gl runs`, `gl logs <pipeline> [-j job] [--full]`; use it instead of `glab ci` or `glab api .../pipelines/<id>/jobs` polled in a sleep loop.",
|
|
@@ -3731,15 +4010,15 @@ Exits 0 when it answered, 1 on a failure or an unknown event (never 2, which wou
|
|
|
3731
4010
|
var MAX_READ = 1e6;
|
|
3732
4011
|
function readText(path) {
|
|
3733
4012
|
try {
|
|
3734
|
-
const stats =
|
|
3735
|
-
return stats?.isFile() === true && stats.size <= MAX_READ ?
|
|
4013
|
+
const stats = statSync2(path, { throwIfNoEntry: false });
|
|
4014
|
+
return stats?.isFile() === true && stats.size <= MAX_READ ? readFileSync6(path, "utf8") : null;
|
|
3736
4015
|
} catch {
|
|
3737
4016
|
return null;
|
|
3738
4017
|
}
|
|
3739
4018
|
}
|
|
3740
4019
|
function report2(violations) {
|
|
3741
4020
|
for (const { rule, message } of violations)
|
|
3742
|
-
console.log(`${rule}: ${message}`);
|
|
4021
|
+
console.log(`${role("problem", process16.stdout)(rule)}: ${message}`);
|
|
3743
4022
|
}
|
|
3744
4023
|
async function check(args) {
|
|
3745
4024
|
const parsed = parse(args, checkUsage, checkOptions);
|
|
@@ -3751,14 +4030,14 @@ ${checkUsage}`);
|
|
|
3751
4030
|
const given = positionals[0] ?? "-";
|
|
3752
4031
|
const command = given === "-" ? await readInput("-", { noStdin: "give the command, or pipe it on stdin" }) : given;
|
|
3753
4032
|
const context = {
|
|
3754
|
-
cwd: values.cwd ??
|
|
3755
|
-
home:
|
|
4033
|
+
cwd: values.cwd ?? process16.cwd(),
|
|
4034
|
+
home: homedir4(),
|
|
3756
4035
|
isPushAsked: values["push-asked"] === true,
|
|
3757
4036
|
canRewrite: true,
|
|
3758
4037
|
canWrap: values["no-wrap"] !== true && Bun.which("out") !== null,
|
|
3759
4038
|
canSub: Bun.which("sub") !== null,
|
|
3760
4039
|
read: readText,
|
|
3761
|
-
exists:
|
|
4040
|
+
exists: existsSync5
|
|
3762
4041
|
};
|
|
3763
4042
|
const verdict = await checkCommand(command, context);
|
|
3764
4043
|
if (values.json === true)
|
|
@@ -3766,7 +4045,7 @@ ${checkUsage}`);
|
|
|
3766
4045
|
else
|
|
3767
4046
|
report2(verdict.violations);
|
|
3768
4047
|
if (values.json !== true && verdict.command !== command)
|
|
3769
|
-
console.log(
|
|
4048
|
+
console.log(`${role("label", process16.stdout)("runs as:")} ${verdict.command}${verdict.notes.map((note) => `
|
|
3770
4049
|
${note}`).join("")}`);
|
|
3771
4050
|
return verdict.violations.length > 0 ? 1 : 0;
|
|
3772
4051
|
}
|
|
@@ -3798,12 +4077,12 @@ function rules(args) {
|
|
|
3798
4077
|
return 0;
|
|
3799
4078
|
}
|
|
3800
4079
|
for (const rule of RULES2)
|
|
3801
|
-
console.log(`${rule.name.
|
|
4080
|
+
console.log(`${role("id", process16.stdout)(rule.name)}${" ".repeat(Math.max(0, 16 - rule.name.length))} ${rule.refuses}
|
|
3802
4081
|
${" ".repeat(16)} -> ${rule.route}${rule.runs === "hook" ? " (hook only)" : ""}`);
|
|
3803
4082
|
return 0;
|
|
3804
4083
|
}
|
|
3805
4084
|
function machine() {
|
|
3806
|
-
const home =
|
|
4085
|
+
const home = homedir4();
|
|
3807
4086
|
const stateDir = `${stateHome()}/guard`;
|
|
3808
4087
|
return {
|
|
3809
4088
|
home,
|
|
@@ -3811,9 +4090,9 @@ function machine() {
|
|
|
3811
4090
|
has: (bin) => Bun.which(bin) !== null,
|
|
3812
4091
|
run: async (argv, cwd) => runCommand(argv, { cwd }),
|
|
3813
4092
|
read: readText,
|
|
3814
|
-
exists:
|
|
4093
|
+
exists: existsSync5,
|
|
3815
4094
|
write: (path, text) => {
|
|
3816
|
-
mkdirSync2(
|
|
4095
|
+
mkdirSync2(dirname5(path), { recursive: true });
|
|
3817
4096
|
writeFileSync(path, text);
|
|
3818
4097
|
},
|
|
3819
4098
|
remove: (path) => rmSync(path, { force: true }),
|
|
@@ -3837,7 +4116,7 @@ ${hookUsage}`, 1);
|
|
|
3837
4116
|
console.log(JSON.stringify(reply));
|
|
3838
4117
|
return 0;
|
|
3839
4118
|
}
|
|
3840
|
-
|
|
4119
|
+
process16.exitCode = await runCli({
|
|
3841
4120
|
name: "guard",
|
|
3842
4121
|
usage: false,
|
|
3843
4122
|
about: "the safety rules a Claude Code Bash call is held to, each refusal naming the route",
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kaynooo/cli-guard",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.12.0",
|
|
5
5
|
"description": "guard: the safety rules a Claude Code Bash call is held to (git, remote machines, SQL writes, env files, package managers, commit messages), each refusal naming the route.",
|
|
6
6
|
"author": "Kaynooo <contact@kaynooo.fr>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -36,12 +36,12 @@
|
|
|
36
36
|
"guard": "$npm_execpath src/cli.ts"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@kaynooo/cli-db": "0.12.
|
|
40
|
-
"@kaynooo/cli-edit": "0.
|
|
41
|
-
"@kaynooo/cli-env": "0.13.
|
|
42
|
-
"@kaynooo/cli-git": "0.
|
|
43
|
-
"@kaynooo/cli-kit": "0.
|
|
44
|
-
"@kaynooo/cli-out": "0.
|
|
45
|
-
"@kaynooo/cli-pkg": "0.
|
|
39
|
+
"@kaynooo/cli-db": "0.12.1",
|
|
40
|
+
"@kaynooo/cli-edit": "0.10.0",
|
|
41
|
+
"@kaynooo/cli-env": "0.13.1",
|
|
42
|
+
"@kaynooo/cli-git": "0.15.0",
|
|
43
|
+
"@kaynooo/cli-kit": "0.38.2",
|
|
44
|
+
"@kaynooo/cli-out": "0.14.3",
|
|
45
|
+
"@kaynooo/cli-pkg": "0.14.0"
|
|
46
46
|
}
|
|
47
47
|
}
|