@esneiderbravo/speclaw 2.0.17 → 2.0.18
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/commands/init.js +4 -1
- package/dist/cli/lib/ui.js +111 -7
- package/package.json +1 -1
|
@@ -7,7 +7,7 @@ import { buildIndex } from "../../modules/compass/indexer.js";
|
|
|
7
7
|
import { AGENTS, agentById } from "../../shared/agents.js";
|
|
8
8
|
import { loadPacks } from "../../modules/tools/packs.js";
|
|
9
9
|
import { list } from "../lib/args.js";
|
|
10
|
-
import { ui, c, banner, renderProgress, clearProgress } from "../lib/ui.js";
|
|
10
|
+
import { ui, c, banner, detectTheme, renderProgress, clearProgress } from "../lib/ui.js";
|
|
11
11
|
import { checkForUpdates } from "../lib/update-check.js";
|
|
12
12
|
import { reportTrackedLocalContent } from "../lib/untrack.js";
|
|
13
13
|
const PACK_LABELS = {};
|
|
@@ -37,6 +37,9 @@ export async function runInit(flags) {
|
|
|
37
37
|
let packs;
|
|
38
38
|
const availablePacks = loadPacks();
|
|
39
39
|
const packIds = Object.keys(availablePacks);
|
|
40
|
+
// Init is read once, top to bottom, on whatever background the user has —
|
|
41
|
+
// match the palette to it before the first styled line.
|
|
42
|
+
await detectTheme();
|
|
40
43
|
banner();
|
|
41
44
|
// Scaffolding with a stale version writes yesterday's foundation, so recommend
|
|
42
45
|
// upgrading first — prominently, before any prompts, so there's time to cancel.
|
package/dist/cli/lib/ui.js
CHANGED
|
@@ -16,6 +16,110 @@ export const PALETTE = Object.freeze({
|
|
|
16
16
|
amber: [245, 183, 61], // #F5B73D — warning (re-tuned)
|
|
17
17
|
red: [255, 92, 71], // #FF5C47 — deny: errors
|
|
18
18
|
});
|
|
19
|
+
// The same slots tuned for a light terminal: the ink palette is near-invisible
|
|
20
|
+
// on white (cream is ~1.1:1, signal cyan ~1.6:1), so each slot here holds at
|
|
21
|
+
// least 4.5:1 against white paper #FFFFFF instead.
|
|
22
|
+
// Covers: req~brand-terminal-palette~1
|
|
23
|
+
export const LIGHT_PALETTE = Object.freeze({
|
|
24
|
+
cyan: [0, 122, 140], // #007A8C — deep signal
|
|
25
|
+
cyanDim: [0, 122, 140], // #007A8C
|
|
26
|
+
cream: [31, 35, 40], // #1F2328 — primary text on light paper
|
|
27
|
+
muted: [95, 102, 112], // #5F6670 — secondary text
|
|
28
|
+
green: [26, 127, 55], // #1A7F37 — success
|
|
29
|
+
amber: [154, 103, 0], // #9A6700 — warning
|
|
30
|
+
red: [207, 34, 46], // #CF222E — errors
|
|
31
|
+
});
|
|
32
|
+
/**
|
|
33
|
+
* The theme an explicit signal asks for: `SPECLAW_THEME=light|dark` wins, then
|
|
34
|
+
* `COLORFGBG` (`fg;bg`, set by rxvt, Konsole, and others), whose background
|
|
35
|
+
* index 7 or 15 means a light terminal. Returns `undefined` when neither says.
|
|
36
|
+
*/
|
|
37
|
+
export function themeFromEnv(env = process.env) {
|
|
38
|
+
const forced = env.SPECLAW_THEME?.toLowerCase();
|
|
39
|
+
if (forced === "light" || forced === "dark")
|
|
40
|
+
return forced;
|
|
41
|
+
const bg = env.COLORFGBG?.split(";").pop();
|
|
42
|
+
if (bg === undefined || bg === "")
|
|
43
|
+
return undefined;
|
|
44
|
+
return bg === "7" || bg === "15" ? "light" : "dark";
|
|
45
|
+
}
|
|
46
|
+
let active = themeFromEnv() === "light" ? LIGHT_PALETTE : PALETTE;
|
|
47
|
+
/** Switch every brand color to the given theme's palette. */
|
|
48
|
+
export function setTheme(theme) {
|
|
49
|
+
active = theme === "light" ? LIGHT_PALETTE : PALETTE;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The theme an OSC 11 background-color reply implies
|
|
53
|
+
* (`ESC ] 11 ; rgb:RRRR/GGGG/BBBB` with 1–4 hex digits per channel): light when
|
|
54
|
+
* the background's relative luminance is above one half.
|
|
55
|
+
*/
|
|
56
|
+
export function themeFromOsc11(reply) {
|
|
57
|
+
const m = /rgb:([0-9a-f]{1,4})\/([0-9a-f]{1,4})\/([0-9a-f]{1,4})/i.exec(reply);
|
|
58
|
+
if (!m)
|
|
59
|
+
return undefined;
|
|
60
|
+
const [r, g, b] = [m[1], m[2], m[3]].map((h) => parseInt(h, 16) / (16 ** h.length - 1));
|
|
61
|
+
return 0.2126 * r + 0.7152 * g + 0.0722 * b > 0.5 ? "light" : "dark";
|
|
62
|
+
}
|
|
63
|
+
// Ask the terminal for its background color. Terminals that don't support the
|
|
64
|
+
// query never answer, so the wait is capped; a reply arriving after the cap
|
|
65
|
+
// would land in the next prompt's input, hence a generous-but-short window.
|
|
66
|
+
function queryBackground(timeoutMs = 200) {
|
|
67
|
+
const stdin = process.stdin;
|
|
68
|
+
if (!stdin.isTTY || !process.stdout.isTTY || typeof stdin.setRawMode !== "function") {
|
|
69
|
+
return Promise.resolve("");
|
|
70
|
+
}
|
|
71
|
+
return new Promise((resolve) => {
|
|
72
|
+
let buf = "";
|
|
73
|
+
const wasRaw = stdin.isRaw;
|
|
74
|
+
const done = () => {
|
|
75
|
+
clearTimeout(timer);
|
|
76
|
+
stdin.off("data", onData);
|
|
77
|
+
stdin.setRawMode(wasRaw);
|
|
78
|
+
stdin.pause();
|
|
79
|
+
resolve(buf);
|
|
80
|
+
};
|
|
81
|
+
const onData = (d) => {
|
|
82
|
+
buf += d.toString("latin1");
|
|
83
|
+
if (buf.includes("\x07") || buf.includes("\x1b\\"))
|
|
84
|
+
done();
|
|
85
|
+
};
|
|
86
|
+
const timer = setTimeout(done, timeoutMs);
|
|
87
|
+
stdin.setRawMode(true);
|
|
88
|
+
stdin.on("data", onData);
|
|
89
|
+
stdin.resume();
|
|
90
|
+
process.stdout.write("\x1b]11;?\x07");
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
// macOS appearance as a last resort: most terminals there follow the system
|
|
94
|
+
// theme by default. `AppleInterfaceStyle` exists only in dark mode.
|
|
95
|
+
async function macAppearance() {
|
|
96
|
+
if (process.platform !== "darwin")
|
|
97
|
+
return undefined;
|
|
98
|
+
const { execFile } = await import("node:child_process");
|
|
99
|
+
return new Promise((resolve) => {
|
|
100
|
+
execFile("defaults", ["read", "-g", "AppleInterfaceStyle"], { timeout: 500 }, (err, out) => {
|
|
101
|
+
if (err && typeof err.code !== "number")
|
|
102
|
+
return resolve(undefined);
|
|
103
|
+
resolve(/dark/i.test(String(out)) ? "dark" : "light");
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Detect the terminal's background and switch to the matching palette. An
|
|
109
|
+
* explicit env signal ({@link themeFromEnv}) wins; otherwise the terminal is
|
|
110
|
+
* asked directly (OSC 11), then the macOS appearance is consulted. Meant for
|
|
111
|
+
* interactive commands before their first styled line; does nothing when
|
|
112
|
+
* color is off.
|
|
113
|
+
*/
|
|
114
|
+
export async function detectTheme() {
|
|
115
|
+
const fromEnv = themeFromEnv();
|
|
116
|
+
let theme = fromEnv ?? "dark";
|
|
117
|
+
if (colorOn && !fromEnv) {
|
|
118
|
+
theme = themeFromOsc11(await queryBackground()) ?? (await macAppearance()) ?? "dark";
|
|
119
|
+
}
|
|
120
|
+
setTheme(theme);
|
|
121
|
+
return theme;
|
|
122
|
+
}
|
|
19
123
|
const colorOn = (Boolean(process.stdout.isTTY) || process.env.FORCE_COLOR === "1") && !process.env.NO_COLOR;
|
|
20
124
|
// Whether the terminal reliably renders the unicode box/block glyphs the brand
|
|
21
125
|
// output uses. Non-Windows terminals are assumed capable; a Windows console is
|
|
@@ -81,13 +185,13 @@ export function link(label, url) {
|
|
|
81
185
|
}
|
|
82
186
|
/** Brand color helpers for composing styled strings. */
|
|
83
187
|
export const c = {
|
|
84
|
-
cyan: (s) => paint(
|
|
85
|
-
cyanDim: (s) => paint(
|
|
86
|
-
cream: (s) => paint(
|
|
87
|
-
muted: (s) => paint(
|
|
88
|
-
green: (s) => paint(
|
|
89
|
-
amber: (s) => paint(
|
|
90
|
-
red: (s) => paint(
|
|
188
|
+
cyan: (s) => paint(active.cyan, s),
|
|
189
|
+
cyanDim: (s) => paint(active.cyanDim, s),
|
|
190
|
+
cream: (s) => paint(active.cream, s),
|
|
191
|
+
muted: (s) => paint(active.muted, s),
|
|
192
|
+
green: (s) => paint(active.green, s),
|
|
193
|
+
amber: (s) => paint(active.amber, s),
|
|
194
|
+
red: (s) => paint(active.red, s),
|
|
91
195
|
bold,
|
|
92
196
|
};
|
|
93
197
|
/** Styled output primitives used across the CLI. */
|