@wasit-dev/cli 0.7.0 → 0.8.0-beta.1

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/style.js ADDED
@@ -0,0 +1,195 @@
1
+ /**
2
+ * Colours and line layout for a person watching the terminal (Najmi,
3
+ * 2026-11-19): Wasit's own look, in the palette the site and the dashboard use
4
+ * (`dashboard/theme.ts`), a spinner while a check runs, and the run's duration.
5
+ *
6
+ * Colour is a layer over the plain text, never a second wording: every line is
7
+ * sanitised first (`sanitizeText`), then styled, so nothing a service sent can
8
+ * carry an escape sequence of its own. Output that a program reads stays plain:
9
+ * `--json`, a pipe, CI and `NO_COLOR` all get the exact text Wasit printed
10
+ * before colours existed.
11
+ */
12
+ import { THEME } from "./dashboard/theme.js";
13
+ function set(value) {
14
+ return value !== undefined && value !== "";
15
+ }
16
+ /**
17
+ * True when lines may carry colour: `NO_COLOR` set turns it off, `FORCE_COLOR`
18
+ * set (and not "0") turns it on, a dumb terminal and CI are plain, otherwise a
19
+ * TTY is coloured and anything else is not.
20
+ */
21
+ export function colorEnabled(stream, env) {
22
+ if (set(env["NO_COLOR"]))
23
+ return false;
24
+ if (set(env["FORCE_COLOR"]) && env["FORCE_COLOR"] !== "0")
25
+ return true;
26
+ if (env["TERM"] === "dumb")
27
+ return false;
28
+ if (set(env["CI"]) || set(env["GITHUB_ACTIONS"]))
29
+ return false;
30
+ return stream.isTTY === true;
31
+ }
32
+ /**
33
+ * True when a line may be rewritten in place (the running line and its
34
+ * spinner): colour on, and a real terminal. A forced colour into a pipe gets
35
+ * colour but no cursor movement.
36
+ */
37
+ export function liveEnabled(stream, env) {
38
+ return colorEnabled(stream, env) && stream.isTTY === true && !set(env["CI"]) && !set(env["GITHUB_ACTIONS"]);
39
+ }
40
+ /** True when the terminal says it shows 24-bit colour; the brand colours are then exact. */
41
+ export function truecolorEnabled(env) {
42
+ const value = (env["COLORTERM"] ?? "").toLowerCase();
43
+ return value === "truecolor" || value === "24bit";
44
+ }
45
+ export function colorDepth(env) {
46
+ if (truecolorEnabled(env))
47
+ return 24;
48
+ if ((env["TERM"] ?? "").includes("256"))
49
+ return 256;
50
+ return 16;
51
+ }
52
+ /** Each role: its brand colour, and the 16-colour code a plain terminal gets instead. */
53
+ const ROLES = {
54
+ accent: { hex: THEME.accent, basic: 35 },
55
+ muted: { hex: THEME.muted, basic: 90 },
56
+ success: { hex: THEME.success, basic: 32 },
57
+ warning: { hex: THEME.warning, basic: 33 },
58
+ danger: { hex: THEME.danger, basic: 31 },
59
+ error: { hex: "#d946ef", basic: 95 },
60
+ };
61
+ function rgb(hex) {
62
+ const value = Number.parseInt(hex.slice(1), 16);
63
+ return `${(value >> 16) & 255};${(value >> 8) & 255};${value & 255}`;
64
+ }
65
+ /** Black ink on the light backgrounds (green, yellow), white on the dark ones (red, magenta). */
66
+ const BADGE_DARK_INK = { success: true, warning: true, danger: false, error: false };
67
+ /** The 256-colour backgrounds nearest the brand colours. */
68
+ const BADGE_256 = { success: 41, warning: 214, danger: 203, error: 171 };
69
+ const BADGE_16 = { success: 42, warning: 43, danger: 41, error: 45 };
70
+ /**
71
+ * The SGR parameters of a badge. The ink is given exactly (24-bit or 256-colour
72
+ * black and white), never as a bold colour of the 16: a terminal that draws bold
73
+ * text in bright colours (VS Code and iTerm2 by default) turns bold black into
74
+ * grey, which melts into a green or yellow background. On a 16-colour terminal
75
+ * black ink is not bold, for the same reason.
76
+ */
77
+ function badgeParams(role, depth) {
78
+ const dark = BADGE_DARK_INK[role];
79
+ if (depth === 24)
80
+ return `1;${dark ? "38;2;0;0;0" : "38;2;255;255;255"};48;2;${rgb(ROLES[role].hex)}`;
81
+ if (depth === 256)
82
+ return `1;${dark ? "38;5;16" : "38;5;231"};48;5;${BADGE_256[role]}`;
83
+ return dark ? `30;${BADGE_16[role]}` : `1;97;${BADGE_16[role]}`;
84
+ }
85
+ /**
86
+ * A styler. `depth` is the terminal's colour depth (`colorDepth`); `true` is
87
+ * read as 24-bit, `false` or nothing as the 16 colours of every terminal.
88
+ */
89
+ export function styler(enabled, depth = 16) {
90
+ const bits = depth === true ? 24 : depth === false ? 16 : depth;
91
+ const truecolor = bits === 24;
92
+ return {
93
+ enabled,
94
+ badge(label, role) {
95
+ if (!enabled)
96
+ return label;
97
+ return `\u001b[${badgeParams(role, bits)}m ${label} \u001b[22;39;49m`;
98
+ },
99
+ paint(text, ...roles) {
100
+ if (!enabled || roles.length === 0 || text === "")
101
+ return text;
102
+ let open = "";
103
+ let close = "";
104
+ for (const role of roles) {
105
+ if (role === "bold" || role === "dim") {
106
+ open += role === "bold" ? "\u001b[1m" : "\u001b[2m";
107
+ close = `\u001b[22m${close}`;
108
+ continue;
109
+ }
110
+ const { hex, basic } = ROLES[role];
111
+ open += truecolor ? `\u001b[38;2;${rgb(hex)}m` : `\u001b[${basic}m`;
112
+ close = `\u001b[39m${close}`;
113
+ }
114
+ return `${open}${text}${close}`;
115
+ },
116
+ };
117
+ }
118
+ /** The SGR sequences this module writes, and only those, for measuring a line. */
119
+ const SGR = /\u001b\[[0-9;]*m/g;
120
+ /** The width a line takes on screen: its length without the colour codes. */
121
+ export function visibleLength(text) {
122
+ return [...text.replace(SGR, "")].length;
123
+ }
124
+ /**
125
+ * A check's status as a mark and a badge that agree (Najmi, 2026-11-20):
126
+ * ✓ PASS, ✗ FAIL, ○ SKIP, ! ERROR (the check could not run). Text marks, not
127
+ * emoji: an emoji takes two columns in many terminals and breaks the columns.
128
+ */
129
+ export const MARKS = {
130
+ PASS: { mark: "✓", markRole: "success", badge: "PASS", badgeRole: "success" },
131
+ FAIL: { mark: "✗", markRole: "danger", badge: "FAIL", badgeRole: "danger" },
132
+ SKIP: { mark: "○", markRole: "warning", badge: "SKIP", badgeRole: "warning" },
133
+ ERROR: { mark: "!", markRole: "error", badge: "ERROR", badgeRole: "error" },
134
+ };
135
+ /** The spinner's frames, as the dashboard draws them, one every 80 ms. */
136
+ export const SPINNER_FRAMES = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
137
+ export const SPINNER_MS = 80;
138
+ /** "12ms" under a second, "6.82s" from a second on. */
139
+ export function duration(ms) {
140
+ if (ms < 1000)
141
+ return `${Math.max(0, Math.round(ms))}ms`;
142
+ return `${(ms / 1000).toFixed(2)}s`;
143
+ }
144
+ /**
145
+ * `left` and `right` on one line, `right` flush with the width. A line that
146
+ * does not fit keeps two spaces between them and runs over.
147
+ */
148
+ export function spread(left, right, width) {
149
+ if (right === "")
150
+ return left;
151
+ const gap = Math.max(2, width - visibleLength(left) - visibleLength(right));
152
+ return `${left}${" ".repeat(gap)}${right}`;
153
+ }
154
+ /** Cuts plain text to `max` characters, ending in "…". */
155
+ export function truncate(text, max) {
156
+ const chars = [...text];
157
+ if (chars.length <= max)
158
+ return text;
159
+ if (max <= 1)
160
+ return "…".slice(0, Math.max(0, max));
161
+ return `${chars.slice(0, max - 1).join("")}…`;
162
+ }
163
+ /**
164
+ * Plain text wrapped to `width` columns, every line after `indent`. A word
165
+ * longer than a line (a URL, a hash) is kept whole and runs over.
166
+ */
167
+ export function wrap(text, width, indent) {
168
+ const room = Math.max(20, width - [...indent].length);
169
+ const lines = [];
170
+ let current = "";
171
+ for (const word of text.split(/\s+/).filter((part) => part !== "")) {
172
+ if (current === "")
173
+ current = word;
174
+ else if ([...current].length + 1 + [...word].length <= room)
175
+ current += ` ${word}`;
176
+ else {
177
+ lines.push(current);
178
+ current = word;
179
+ }
180
+ }
181
+ if (current !== "")
182
+ lines.push(current);
183
+ return lines.map((line) => `${indent}${line}`);
184
+ }
185
+ /**
186
+ * The width lines are laid out to: one column less than the terminal's (a line
187
+ * as wide as the screen makes some terminals start a new line), at most 100,
188
+ * 80 when unknown.
189
+ */
190
+ export function lineWidth(stream) {
191
+ const columns = stream.columns;
192
+ if (columns === undefined || !Number.isFinite(columns) || columns <= 0)
193
+ return 80;
194
+ return Math.max(20, Math.min(100, Math.floor(columns) - 1));
195
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wasit-dev/cli",
3
- "version": "0.7.0",
3
+ "version": "0.8.0-beta.1",
4
4
  "description": "CLI for x402/MPP protocol-conformance testing on Stellar — verifies a service's payment flow settles on-chain per spec.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -37,11 +37,11 @@
37
37
  },
38
38
  "scripts": {
39
39
  "build": "tsc -p tsconfig.json",
40
- "test": "node --import tsx --test \"test/unit/**/*.test.ts*\"",
40
+ "test": "node --import tsx --test --test-timeout=120000 \"test/unit/**/*.test.ts*\"",
41
41
  "typecheck": "tsc -p test/tsconfig.json"
42
42
  },
43
43
  "dependencies": {
44
- "@wasit-dev/core": "^0.7.0",
44
+ "@wasit-dev/core": "^0.8.0-beta.1",
45
45
  "cfonts": "^3.3.1",
46
46
  "commander": "^15.0.0",
47
47
  "dotenv": "^17.4.2",