@sns-myagent/cli 0.3.5 → 0.3.7
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/README.md +51 -1
- package/package.json +1 -1
- package/scripts/smoke-tui.ts +18 -22
- package/src/tui/chat-blocks.ts +85 -179
- package/src/tui/code-cell.ts +9 -9
- package/src/tui/command-palette.ts +56 -174
- package/src/tui/index.ts +1 -1
- package/src/tui/splash.ts +67 -111
- package/src/ui/error-display.ts +60 -103
- package/src/ui/gradient.ts +15 -95
- package/src/ui/index.ts +3 -9
- package/src/ui/memory-toast.ts +38 -77
- package/src/ui/status-bar.ts +24 -47
|
@@ -1,189 +1,71 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Command palette
|
|
3
|
-
*
|
|
4
|
-
* Fuzzy-searchable command overlay with gradient styling.
|
|
5
|
-
* Triggered by Ctrl+P or typing "/" in the input.
|
|
2
|
+
* Command palette — flat list, no box.
|
|
3
|
+
* Cyan highlight on selected row, dim otherwise.
|
|
6
4
|
*/
|
|
5
|
+
|
|
7
6
|
import chalk from "chalk";
|
|
8
|
-
import gradient from "gradient-string";
|
|
9
|
-
import { BRAND_GRADIENT, ACCENT_GRADIENT } from "../ui/colors.js";
|
|
10
7
|
|
|
11
8
|
export interface PaletteCommand {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
category: string;
|
|
18
|
-
/** Keyboard shortcut (optional). */
|
|
19
|
-
shortcut?: string;
|
|
20
|
-
/** Whether command is enabled. */
|
|
21
|
-
enabled?: boolean;
|
|
9
|
+
name: string;
|
|
10
|
+
description: string;
|
|
11
|
+
category: string;
|
|
12
|
+
shortcut?: string;
|
|
13
|
+
enabled?: boolean;
|
|
22
14
|
}
|
|
23
15
|
|
|
24
16
|
export interface CommandPaletteOptions {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
/** Currently highlighted index. */
|
|
30
|
-
highlighted?: number;
|
|
31
|
-
/** Width of the palette. */
|
|
32
|
-
width?: number;
|
|
17
|
+
commands: PaletteCommand[];
|
|
18
|
+
query?: string;
|
|
19
|
+
highlighted?: number;
|
|
20
|
+
width?: number;
|
|
33
21
|
}
|
|
34
22
|
|
|
35
|
-
// ── Pre-built command lists ──
|
|
36
|
-
|
|
37
23
|
export const CHAT_COMMANDS: PaletteCommand[] = [
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
24
|
+
{ name: "/help", description: "Show available commands", category: "General", shortcut: "?" },
|
|
25
|
+
{ name: "/clear", description: "Clear screen", category: "General", shortcut: "⌘K" },
|
|
26
|
+
{ name: "/exit", description: "Quit the chat", category: "General", shortcut: "⌘Q" },
|
|
27
|
+
{ name: "/model", description: "Show/switch model", category: "Config" },
|
|
28
|
+
{ name: "/history", description: "Show conversation history", category: "General" },
|
|
29
|
+
{ name: "/memory", description: "Recall from memory", category: "Memory" },
|
|
30
|
+
{ name: "/skills", description: "List available skills", category: "Extensibility" },
|
|
31
|
+
{ name: "/plugins", description: "List installed plugins", category: "Extensibility" },
|
|
32
|
+
{ name: "/mcp", description: "MCP server management", category: "Extensibility" },
|
|
33
|
+
{ name: "/theme", description: "Change terminal theme", category: "Config" },
|
|
34
|
+
{ name: "/bench", description: "Run benchmarks", category: "Debug" },
|
|
35
|
+
{ name: "/debug", description: "Debug info", category: "Debug" },
|
|
50
36
|
];
|
|
51
37
|
|
|
52
|
-
// ── Fuzzy match ──
|
|
53
|
-
|
|
54
|
-
function fuzzyMatch(query: string, text: string): number {
|
|
55
|
-
if (!query) return 1;
|
|
56
|
-
const q = query.toLowerCase();
|
|
57
|
-
const t = text.toLowerCase();
|
|
58
|
-
|
|
59
|
-
// Exact prefix match — highest score
|
|
60
|
-
if (t.startsWith(q)) return 1;
|
|
61
|
-
|
|
62
|
-
// Subsequence match
|
|
63
|
-
let qi = 0;
|
|
64
|
-
let score = 0;
|
|
65
|
-
let consecutive = 0;
|
|
66
|
-
for (let ti = 0; ti < t.length && qi < q.length; ti++) {
|
|
67
|
-
if (t[ti] === q[qi]) {
|
|
68
|
-
qi++;
|
|
69
|
-
consecutive++;
|
|
70
|
-
score += consecutive; // bonus for consecutive chars
|
|
71
|
-
} else {
|
|
72
|
-
consecutive = 0;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return qi === q.length ? score / (q.length * q.length) : 0;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// ── Renderer ──
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Render the command palette as a bordered overlay.
|
|
83
|
-
*/
|
|
84
38
|
export function renderCommandPalette(opts: CommandPaletteOptions): string {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
const fill = "─".repeat(Math.max(0, inner - 22));
|
|
118
|
-
lines.push(grad("╭─") + headerText + grad(fill + "─╮"));
|
|
119
|
-
|
|
120
|
-
// ── Search bar ──
|
|
121
|
-
const searchDisplay = query ? chalk.white(query) + chalk.dim("█") : chalk.dim("Type to search...");
|
|
122
|
-
const searchFill = " ".repeat(Math.max(0, inner - searchDisplay.length + 8));
|
|
123
|
-
lines.push(grad("│") + ` ${searchDisplay}${searchFill}` + grad("│"));
|
|
124
|
-
|
|
125
|
-
// ── Separator ──
|
|
126
|
-
lines.push(grad("├") + "─".repeat(inner) + grad("┤"));
|
|
127
|
-
|
|
128
|
-
// ── Commands ──
|
|
129
|
-
let globalIdx = 0;
|
|
130
|
-
for (const [category, items] of groups) {
|
|
131
|
-
// Category header
|
|
132
|
-
const catText = chalk.dim(` ${category.toUpperCase()} `);
|
|
133
|
-
const catFill = " ".repeat(Math.max(0, inner - category.length - 2));
|
|
134
|
-
lines.push(grad("│") + catText + catFill + grad("│"));
|
|
135
|
-
|
|
136
|
-
for (const { cmd } of items) {
|
|
137
|
-
const isSelected = globalIdx === highlighted;
|
|
138
|
-
const nameStr = isSelected
|
|
139
|
-
? chalk.bgCyan.black(` ${cmd.name} `)
|
|
140
|
-
: chalk.cyan(cmd.name);
|
|
141
|
-
const descStr = chalk.dim(cmd.description);
|
|
142
|
-
const shortcutStr = cmd.shortcut ? chalk.dim(` [${cmd.shortcut}]`) : "";
|
|
143
|
-
|
|
144
|
-
const line = ` ${nameStr} ${descStr}${shortcutStr}`;
|
|
145
|
-
const padding = " ".repeat(Math.max(0, inner - visibleLen(line) + 4));
|
|
146
|
-
|
|
147
|
-
if (isSelected) {
|
|
148
|
-
lines.push(grad("│") + chalk.bgHex("#1a1a2e")(line) + padding + grad("│"));
|
|
149
|
-
} else {
|
|
150
|
-
lines.push(grad("│") + line + padding + grad("│"));
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
globalIdx++;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
// ── Footer ──
|
|
158
|
-
const footer = chalk.dim(" ↑↓ navigate ⏎ select esc close ");
|
|
159
|
-
const footerFill = " ".repeat(Math.max(0, inner - footer.length + 4));
|
|
160
|
-
lines.push(grad("├") + "─".repeat(inner) + grad("┤"));
|
|
161
|
-
lines.push(grad("│") + footer + footerFill + grad("│"));
|
|
162
|
-
lines.push(grad("╰") + "─".repeat(inner) + grad("╯"));
|
|
163
|
-
|
|
164
|
-
return lines.join("\n");
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* Get filtered commands for a query.
|
|
169
|
-
*/
|
|
170
|
-
export function filterCommands(
|
|
171
|
-
commands: PaletteCommand[],
|
|
172
|
-
query: string,
|
|
173
|
-
): PaletteCommand[] {
|
|
174
|
-
return commands
|
|
175
|
-
.map(cmd => ({
|
|
176
|
-
cmd,
|
|
177
|
-
score: fuzzyMatch(query, cmd.name) + fuzzyMatch(query, cmd.description) * 0.5,
|
|
178
|
-
}))
|
|
179
|
-
.filter(s => s.score > 0)
|
|
180
|
-
.sort((a, b) => b.score - a.score)
|
|
181
|
-
.map(s => s.cmd);
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
// ── Helpers ──
|
|
185
|
-
|
|
186
|
-
function visibleLen(str: string): number {
|
|
187
|
-
// Strip ANSI escape sequences for length calculation
|
|
188
|
-
return str.replace(/\x1b\[[0-9;]*m/g, "").length;
|
|
39
|
+
const { commands, query = "", highlighted = 0 } = opts;
|
|
40
|
+
const filtered = commands.filter(
|
|
41
|
+
(c) => c.enabled !== false &&
|
|
42
|
+
(c.name.toLowerCase().includes(query.toLowerCase()) ||
|
|
43
|
+
c.description.toLowerCase().includes(query.toLowerCase()) ||
|
|
44
|
+
c.category.toLowerCase().includes(query.toLowerCase()))
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
const lines: string[] = [];
|
|
48
|
+
|
|
49
|
+
// Search line
|
|
50
|
+
lines.push(` ${chalk.cyan("?")} ${query}${chalk.dim(" (↑↓ navigate · Enter select · Esc cancel)")}`);
|
|
51
|
+
lines.push("");
|
|
52
|
+
|
|
53
|
+
if (filtered.length === 0) {
|
|
54
|
+
lines.push(` ${chalk.dim("no commands match")}`);
|
|
55
|
+
} else {
|
|
56
|
+
filtered.forEach((cmd, idx) => {
|
|
57
|
+
const isActive = idx === highlighted;
|
|
58
|
+
const prefix = isActive ? chalk.cyan("●") : " ";
|
|
59
|
+
const name = isActive ? chalk.cyan.bold(cmd.name) : chalk.cyan(cmd.name);
|
|
60
|
+
const desc = chalk.dim(cmd.description);
|
|
61
|
+
const cat = chalk.dim(` [${cmd.category}]`);
|
|
62
|
+
const shortcut = cmd.shortcut ? chalk.dim(` ${cmd.shortcut}`) : "";
|
|
63
|
+
lines.push(` ${prefix} ${name}${cat}${shortcut}`);
|
|
64
|
+
if (isActive) {
|
|
65
|
+
lines.push(` ${desc}`);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return lines.join("\n");
|
|
189
71
|
}
|
package/src/tui/index.ts
CHANGED
|
@@ -14,4 +14,4 @@ export * from "./width-aware-text";
|
|
|
14
14
|
export * from "./splash";
|
|
15
15
|
export * from "./chat-blocks";
|
|
16
16
|
export * from "./chat-ui";
|
|
17
|
-
export { renderCommandPalette,
|
|
17
|
+
export { renderCommandPalette, CHAT_COMMANDS, type PaletteCommand, type CommandPaletteOptions } from "./command-palette";
|
package/src/tui/splash.ts
CHANGED
|
@@ -1,130 +1,86 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* SNS-MyAgent splash
|
|
3
|
-
*
|
|
2
|
+
* SNS-MyAgent splash — flat list, no boxes.
|
|
3
|
+
* Single line brand + `●` prefixed info rows. No rounded borders, no
|
|
4
|
+
* gradient, no separator boxes. Reads like a status line.
|
|
4
5
|
*/
|
|
5
6
|
import chalk from "chalk";
|
|
6
|
-
import gradient from "gradient-string";
|
|
7
|
-
import boxen from "boxen";
|
|
8
7
|
import { readFileSync } from "node:fs";
|
|
9
8
|
import { dirname, resolve } from "node:path";
|
|
10
9
|
import { fileURLToPath } from "node:url";
|
|
11
10
|
|
|
12
|
-
const BANNER_ART = `
|
|
13
|
-
███╗ ██╗███████╗██╗ ██╗██╗ ██╗███████╗
|
|
14
|
-
████╗ ██║██╔════╝╚██╗██╔╝██║ ██║██╔════╝
|
|
15
|
-
██╔██╗ ██║█████╗ ╚███╔╝ ██║ ██║███████╗
|
|
16
|
-
██║╚██╗██║██╔══╝ ██╔██╗ ██║ ██║╚════██║
|
|
17
|
-
██║ ╚████║███████╗██╔╝ ╚██╗╚██████╔╝███████║
|
|
18
|
-
╚═╝ ╚═══╝╚══════╝╚═╝ ╚═╝ ╚═════╝ ╚══════╝`;
|
|
19
|
-
|
|
20
|
-
const SUBTITLE = "My-Agent • SnsAgent CLI";
|
|
21
|
-
|
|
22
|
-
const SNY_GRADIENT = ["#00d2ff", "#7b2ff7", "#ff6b9d"];
|
|
23
|
-
const ACCENT_GRADIENT = ["#7b2ff7", "#00d2ff"];
|
|
24
|
-
|
|
25
11
|
function readVersion(): string {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
return "0.0.0";
|
|
57
|
-
} catch {
|
|
58
|
-
return "0.0.0";
|
|
59
|
-
}
|
|
12
|
+
try {
|
|
13
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
14
|
+
const candidates = [
|
|
15
|
+
resolve(here, "..", "..", "package.json"),
|
|
16
|
+
resolve(here, "..", "package.json"),
|
|
17
|
+
resolve(here, "..", "..", "dist", "package.json"),
|
|
18
|
+
];
|
|
19
|
+
for (const pkgPath of candidates) {
|
|
20
|
+
try {
|
|
21
|
+
const raw = readFileSync(pkgPath, "utf8");
|
|
22
|
+
const pkg = JSON.parse(raw) as { version?: string };
|
|
23
|
+
if (pkg.version && pkg.version !== "0.0.0") return pkg.version;
|
|
24
|
+
} catch {}
|
|
25
|
+
}
|
|
26
|
+
let dir = process.cwd();
|
|
27
|
+
for (let i = 0; i < 5; i++) {
|
|
28
|
+
try {
|
|
29
|
+
const raw = readFileSync(resolve(dir, "package.json"), "utf8");
|
|
30
|
+
const pkg = JSON.parse(raw) as { name?: string; version?: string };
|
|
31
|
+
if (pkg.name === "@sns-myagent/cli" && pkg.version) return pkg.version;
|
|
32
|
+
} catch {}
|
|
33
|
+
const parent = dirname(dir);
|
|
34
|
+
if (parent === dir) break;
|
|
35
|
+
dir = parent;
|
|
36
|
+
}
|
|
37
|
+
return "0.0.0";
|
|
38
|
+
} catch {
|
|
39
|
+
return "0.0.0";
|
|
40
|
+
}
|
|
60
41
|
}
|
|
61
42
|
|
|
62
43
|
export interface SplashInfo {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
44
|
+
model?: string;
|
|
45
|
+
provider?: string;
|
|
46
|
+
cwd?: string;
|
|
47
|
+
platform?: string;
|
|
48
|
+
nodeVersion?: string;
|
|
68
49
|
}
|
|
69
50
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
const kv = (k: string, v: string) =>
|
|
76
|
-
` ${chalk.dim(k.padEnd(12))}${chalk.white(v)}`;
|
|
77
|
-
|
|
78
|
-
rows.push(sep);
|
|
79
|
-
if (info.model) rows.push(kv("Model", `${info.provider ?? "unknown"}/${info.model}`));
|
|
80
|
-
if (info.cwd) rows.push(kv("Working Dir", info.cwd));
|
|
81
|
-
if (info.platform) rows.push(kv("Platform", info.platform));
|
|
82
|
-
rows.push(kv("Version", readVersion()));
|
|
83
|
-
rows.push(sep);
|
|
84
|
-
|
|
85
|
-
const hint = chalk.dim(" Type your message to start chatting.");
|
|
86
|
-
const exit = chalk.dim(" /exit or Ctrl+C to quit.");
|
|
87
|
-
rows.push(hint);
|
|
88
|
-
rows.push(exit);
|
|
89
|
-
|
|
90
|
-
return rows.join("\n");
|
|
91
|
-
}
|
|
51
|
+
/**
|
|
52
|
+
* One-line prefix used throughout the TUI.
|
|
53
|
+
* `●` = present, default text. No rounded boxes.
|
|
54
|
+
*/
|
|
55
|
+
const BULLET = chalk.cyan("●");
|
|
92
56
|
|
|
93
57
|
export function renderSplash(info: SplashInfo = {}): string {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
margin: { top: 0, bottom: 0, left: 1, right: 1 },
|
|
115
|
-
borderStyle: "round",
|
|
116
|
-
borderColor: "cyan",
|
|
117
|
-
width: bannerWidth,
|
|
118
|
-
textAlignment: "center",
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
return box;
|
|
58
|
+
const ver = readVersion();
|
|
59
|
+
const lines: string[] = [];
|
|
60
|
+
|
|
61
|
+
// Brand line: MY · snsagent · v0.3.6
|
|
62
|
+
lines.push(` ${chalk.cyan.bold("MY")} ${chalk.bold("snsagent")} ${chalk.dim(`v${ver}`)}`);
|
|
63
|
+
lines.push(` ${chalk.dim("coding agent CLI")}`);
|
|
64
|
+
lines.push("");
|
|
65
|
+
|
|
66
|
+
// Status lines — flat, one per line, ● prefix
|
|
67
|
+
const row = (label: string, value: string) => ` ${BULLET} ${chalk.dim(label.padEnd(13))}${value}`;
|
|
68
|
+
if (info.model) lines.push(row("model", `${info.provider ?? "unknown"}/${info.model}`));
|
|
69
|
+
if (info.cwd) lines.push(row("dir", info.cwd));
|
|
70
|
+
if (info.platform) lines.push(row("platform", info.platform));
|
|
71
|
+
lines.push(row("version", ver));
|
|
72
|
+
|
|
73
|
+
// Hints
|
|
74
|
+
lines.push("");
|
|
75
|
+
lines.push(` ${chalk.dim("type to chat · /exit to quit")}`);
|
|
76
|
+
|
|
77
|
+
return lines.join("\n") + "\n";
|
|
122
78
|
}
|
|
123
79
|
|
|
124
80
|
export function renderInlineHeader(info: SplashInfo = {}): string {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
81
|
+
const ver = readVersion();
|
|
82
|
+
const model = info.model
|
|
83
|
+
? chalk.cyan(`${info.provider ?? "?"}/${info.model}`)
|
|
84
|
+
: chalk.dim("no model");
|
|
85
|
+
return ` ${chalk.cyan.bold("MY")} ${chalk.bold("snsagent")} ${chalk.dim(`v${ver}`)} ${chalk.dim("·")} ${model}\n`;
|
|
130
86
|
}
|
package/src/ui/error-display.ts
CHANGED
|
@@ -1,130 +1,87 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* Renders errors in styled bordered blocks with gradient accents.
|
|
5
|
-
* Supports error hierarchy: main error + optional cause chain.
|
|
2
|
+
* Error display — flat `●` prefix, severity icon.
|
|
3
|
+
* No box, no gradient, no nested borders. Just one line per item.
|
|
6
4
|
*/
|
|
7
|
-
import chalk from "chalk";
|
|
8
|
-
import gradient from "gradient-string";
|
|
9
|
-
import boxen from "boxen";
|
|
10
|
-
import { BRAND_GRADIENT, ROLE_HEX } from "./colors.js";
|
|
11
5
|
|
|
12
|
-
|
|
13
|
-
const WARN_GRADIENT = ["#ffd700", "#ff8c00"] as const;
|
|
6
|
+
import chalk from "chalk";
|
|
14
7
|
|
|
15
8
|
export type ErrorSeverity = "error" | "warning" | "info";
|
|
16
9
|
|
|
17
10
|
export interface ErrorDisplayOptions {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
severity?: ErrorSeverity;
|
|
26
|
-
/** Stack trace (shown collapsed). */
|
|
27
|
-
stack?: string;
|
|
28
|
-
/** Suggestion for fixing the error. */
|
|
29
|
-
suggestion?: string;
|
|
30
|
-
/** Additional context lines. */
|
|
31
|
-
context?: string[];
|
|
11
|
+
title: string;
|
|
12
|
+
message: string;
|
|
13
|
+
code?: string;
|
|
14
|
+
severity?: ErrorSeverity;
|
|
15
|
+
stack?: string;
|
|
16
|
+
suggestion?: string;
|
|
17
|
+
context?: string[];
|
|
32
18
|
}
|
|
33
19
|
|
|
34
|
-
function
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
20
|
+
function getSeverityMeta(severity: ErrorSeverity) {
|
|
21
|
+
switch (severity) {
|
|
22
|
+
case "error":
|
|
23
|
+
return { icon: chalk.red("●"), label: "ERROR" };
|
|
24
|
+
case "warning":
|
|
25
|
+
return { icon: chalk.yellow("●"), label: "WARNING" };
|
|
26
|
+
case "info":
|
|
27
|
+
return { icon: chalk.cyan("●"), label: "INFO" };
|
|
28
|
+
}
|
|
43
29
|
}
|
|
44
30
|
|
|
45
|
-
/**
|
|
46
|
-
* Render an error display block.
|
|
47
|
-
*/
|
|
48
31
|
export function renderErrorDisplay(opts: ErrorDisplayOptions): string {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const cols = process.stdout.columns ?? 80;
|
|
53
|
-
const width = Math.min(cols - 2, 72);
|
|
32
|
+
const severity = opts.severity ?? "error";
|
|
33
|
+
const meta = getSeverityMeta(severity);
|
|
34
|
+
const codeStr = opts.code ? chalk.dim(` [${opts.code}]`) : "";
|
|
54
35
|
|
|
55
|
-
|
|
36
|
+
const lines: string[] = [];
|
|
56
37
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
? chalk.red.bold(colors.icon)
|
|
60
|
-
: severity === "warning"
|
|
61
|
-
? chalk.yellow.bold(colors.icon)
|
|
62
|
-
: chalk.cyan(colors.icon);
|
|
63
|
-
const headerLabel = grad(` ${colors.label} `);
|
|
64
|
-
const codeStr = opts.code ? chalk.dim(` [${opts.code}]`) : "";
|
|
65
|
-
lines.push(`${headerIcon} ${headerLabel}${codeStr}`);
|
|
38
|
+
// Header
|
|
39
|
+
lines.push(` ${meta.icon} ${chalk.bold(meta.label)}${codeStr}`);
|
|
66
40
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
lines.push(chalk.bold.white(opts.title));
|
|
41
|
+
// Title
|
|
42
|
+
lines.push(` ${chalk.bold(opts.title)}`);
|
|
70
43
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
lines.push(chalk.white(line));
|
|
76
|
-
}
|
|
44
|
+
// Message
|
|
45
|
+
for (const line of opts.message.split("\n")) {
|
|
46
|
+
lines.push(` ${line}`);
|
|
47
|
+
}
|
|
77
48
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
49
|
+
// Context
|
|
50
|
+
if (opts.context && opts.context.length > 0) {
|
|
51
|
+
lines.push("");
|
|
52
|
+
lines.push(` ${chalk.dim("context:")}`);
|
|
53
|
+
for (const ctx of opts.context.slice(0, 5)) {
|
|
54
|
+
lines.push(` ${chalk.dim(ctx)}`);
|
|
55
|
+
}
|
|
56
|
+
if (opts.context.length > 5) {
|
|
57
|
+
lines.push(` ${chalk.dim(`... +${opts.context.length - 5} more`)}`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
89
60
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
61
|
+
// Suggestion
|
|
62
|
+
if (opts.suggestion) {
|
|
63
|
+
lines.push("");
|
|
64
|
+
lines.push(` ${chalk.cyan("→")} ${chalk.bold("suggestion:")}`);
|
|
65
|
+
lines.push(` ${opts.suggestion}`);
|
|
66
|
+
}
|
|
96
67
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
68
|
+
// Stack preview
|
|
69
|
+
if (opts.stack) {
|
|
70
|
+
lines.push("");
|
|
71
|
+
const stackLines = opts.stack.split("\n").slice(0, 3);
|
|
72
|
+
lines.push(` ${chalk.dim("stack (first 3):")}`);
|
|
73
|
+
for (const sl of stackLines) {
|
|
74
|
+
lines.push(` ${chalk.dim(sl.trim())}`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
106
77
|
|
|
107
|
-
|
|
108
|
-
const content = lines.join("\n");
|
|
109
|
-
return boxen(content, {
|
|
110
|
-
padding: { top: 1, bottom: 1, left: 2, right: 2 },
|
|
111
|
-
margin: { top: 0, bottom: 1, left: 0, right: 0 },
|
|
112
|
-
borderStyle: "round",
|
|
113
|
-
borderColor: colors.border,
|
|
114
|
-
width,
|
|
115
|
-
});
|
|
78
|
+
return lines.join("\n");
|
|
116
79
|
}
|
|
117
80
|
|
|
118
|
-
/**
|
|
119
|
-
* Quick error render — wraps a simple error message in a styled block.
|
|
120
|
-
*/
|
|
121
81
|
export function renderQuickError(title: string, message: string): string {
|
|
122
|
-
|
|
82
|
+
return renderErrorDisplay({ title, message, severity: "error" });
|
|
123
83
|
}
|
|
124
84
|
|
|
125
|
-
/**
|
|
126
|
-
* Render a warning display.
|
|
127
|
-
*/
|
|
128
85
|
export function renderWarning(title: string, message: string, suggestion?: string): string {
|
|
129
|
-
|
|
86
|
+
return renderErrorDisplay({ title, message, severity: "warning", suggestion });
|
|
130
87
|
}
|