arc402-cli 0.8.0 → 0.9.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.
Files changed (74) hide show
  1. package/INK6-UX-SPEC.md +446 -0
  2. package/dist/tui/App.d.ts.map +1 -1
  3. package/dist/tui/App.js +23 -7
  4. package/dist/tui/App.js.map +1 -1
  5. package/dist/tui/Header.d.ts +1 -1
  6. package/dist/tui/Header.d.ts.map +1 -1
  7. package/dist/tui/Header.js +6 -5
  8. package/dist/tui/Header.js.map +1 -1
  9. package/dist/tui/InputLine.d.ts +1 -2
  10. package/dist/tui/InputLine.d.ts.map +1 -1
  11. package/dist/tui/InputLine.js +76 -24
  12. package/dist/tui/InputLine.js.map +1 -1
  13. package/dist/tui/Viewport.d.ts.map +1 -1
  14. package/dist/tui/Viewport.js +4 -7
  15. package/dist/tui/Viewport.js.map +1 -1
  16. package/dist/tui/components/Button.d.ts +7 -0
  17. package/dist/tui/components/Button.d.ts.map +1 -0
  18. package/dist/tui/components/Button.js +18 -0
  19. package/dist/tui/components/Button.js.map +1 -0
  20. package/dist/tui/components/CeremonyView.d.ts +13 -0
  21. package/dist/tui/components/CeremonyView.d.ts.map +1 -0
  22. package/dist/tui/components/CeremonyView.js +7 -0
  23. package/dist/tui/components/CeremonyView.js.map +1 -0
  24. package/dist/tui/components/CompletionDropdown.d.ts +7 -0
  25. package/dist/tui/components/CompletionDropdown.d.ts.map +1 -0
  26. package/dist/tui/components/CompletionDropdown.js +20 -0
  27. package/dist/tui/components/CompletionDropdown.js.map +1 -0
  28. package/dist/tui/components/ConfirmPrompt.d.ts +9 -0
  29. package/dist/tui/components/ConfirmPrompt.d.ts.map +1 -0
  30. package/dist/tui/components/ConfirmPrompt.js +7 -0
  31. package/dist/tui/components/ConfirmPrompt.js.map +1 -0
  32. package/dist/tui/components/InteractiveTable.d.ts +14 -0
  33. package/dist/tui/components/InteractiveTable.d.ts.map +1 -0
  34. package/dist/tui/components/InteractiveTable.js +58 -0
  35. package/dist/tui/components/InteractiveTable.js.map +1 -0
  36. package/dist/tui/components/StepSpinner.d.ts +11 -0
  37. package/dist/tui/components/StepSpinner.d.ts.map +1 -0
  38. package/dist/tui/components/StepSpinner.js +29 -0
  39. package/dist/tui/components/StepSpinner.js.map +1 -0
  40. package/dist/tui/components/Toast.d.ts +18 -0
  41. package/dist/tui/components/Toast.d.ts.map +1 -0
  42. package/dist/tui/components/Toast.js +25 -0
  43. package/dist/tui/components/Toast.js.map +1 -0
  44. package/dist/tui/index.d.ts.map +1 -1
  45. package/dist/tui/index.js +15 -1
  46. package/dist/tui/index.js.map +1 -1
  47. package/dist/tui/useCommand.d.ts +3 -2
  48. package/dist/tui/useCommand.d.ts.map +1 -1
  49. package/dist/tui/useCommand.js +89 -7
  50. package/dist/tui/useCommand.js.map +1 -1
  51. package/dist/tui/useNotifications.d.ts +9 -0
  52. package/dist/tui/useNotifications.d.ts.map +1 -0
  53. package/dist/tui/useNotifications.js +14 -0
  54. package/dist/tui/useNotifications.js.map +1 -0
  55. package/dist/ui/banner.d.ts +12 -0
  56. package/dist/ui/banner.d.ts.map +1 -1
  57. package/dist/ui/banner.js +23 -0
  58. package/dist/ui/banner.js.map +1 -1
  59. package/package.json +1 -1
  60. package/src/tui/App.tsx +36 -17
  61. package/src/tui/Header.tsx +26 -5
  62. package/src/tui/InputLine.tsx +107 -32
  63. package/src/tui/Viewport.tsx +4 -7
  64. package/src/tui/components/Button.tsx +38 -0
  65. package/src/tui/components/CeremonyView.tsx +39 -0
  66. package/src/tui/components/CompletionDropdown.tsx +59 -0
  67. package/src/tui/components/ConfirmPrompt.tsx +36 -0
  68. package/src/tui/components/InteractiveTable.tsx +112 -0
  69. package/src/tui/components/StepSpinner.tsx +84 -0
  70. package/src/tui/components/Toast.tsx +59 -0
  71. package/src/tui/index.tsx +20 -1
  72. package/src/tui/useCommand.ts +98 -8
  73. package/src/tui/useNotifications.ts +28 -0
  74. package/src/ui/banner.ts +27 -0
@@ -1,7 +1,8 @@
1
- import React, { useState, useCallback } from "react";
1
+ import React, { useState, useCallback, useMemo } from "react";
2
2
  import { Box, Text, useInput } from "ink";
3
3
  import TextInput from "ink-text-input";
4
4
  import { createProgram } from "../program.js";
5
+ import { CompletionDropdown } from "./components/CompletionDropdown.js";
5
6
 
6
7
  const BUILTIN_CMDS = ["help", "exit", "quit", "clear", "status"];
7
8
 
@@ -11,8 +12,7 @@ interface InputLineProps {
11
12
  }
12
13
 
13
14
  /**
14
- * Input line with command history navigation and tab completion.
15
- * Uses ink-text-input for text input with cursor.
15
+ * Input line with command history navigation, tab completion, and dropdown.
16
16
  */
17
17
  export function InputLine({ onSubmit, isDisabled = false }: InputLineProps) {
18
18
  const [value, setValue] = useState("");
@@ -20,6 +20,11 @@ export function InputLine({ onSubmit, isDisabled = false }: InputLineProps) {
20
20
  const [historyIdx, setHistoryIdx] = useState(-1);
21
21
  const [historyTemp, setHistoryTemp] = useState("");
22
22
 
23
+ // Dropdown state
24
+ const [showDropdown, setShowDropdown] = useState(false);
25
+ const [dropdownIdx, setDropdownIdx] = useState(0);
26
+ const [dropdownCandidates, setDropdownCandidates] = useState<string[]>([]);
27
+
23
28
  // Lazily build command list for tab completion
24
29
  const [topCmds] = useState<string[]>(() => {
25
30
  try {
@@ -44,12 +49,30 @@ export function InputLine({ onSubmit, isDisabled = false }: InputLineProps) {
44
49
  }
45
50
  });
46
51
 
52
+ const getCompletions = useCallback(
53
+ (input: string): string[] => {
54
+ const allTop = [...BUILTIN_CMDS, ...topCmds];
55
+ const trimmed = input.trimStart();
56
+ const spaceIdx = trimmed.indexOf(" ");
57
+
58
+ if (spaceIdx === -1) {
59
+ return allTop.filter((cmd) => cmd.startsWith(trimmed));
60
+ }
61
+ const parent = trimmed.slice(0, spaceIdx);
62
+ const rest = trimmed.slice(spaceIdx + 1);
63
+ const subs = subCmds.get(parent) ?? [];
64
+ return subs
65
+ .filter((s) => s.startsWith(rest))
66
+ .map((s) => `${parent} ${s}`);
67
+ },
68
+ [topCmds, subCmds]
69
+ );
70
+
47
71
  const handleSubmit = useCallback(
48
72
  (val: string) => {
49
73
  const trimmed = val.trim();
50
74
  if (!trimmed) return;
51
75
 
52
- // Add to history (avoid duplicate of last entry)
53
76
  setHistory((prev) => {
54
77
  if (prev[prev.length - 1] === trimmed) return prev;
55
78
  return [...prev, trimmed];
@@ -57,6 +80,7 @@ export function InputLine({ onSubmit, isDisabled = false }: InputLineProps) {
57
80
  setHistoryIdx(-1);
58
81
  setHistoryTemp("");
59
82
  setValue("");
83
+ setShowDropdown(false);
60
84
 
61
85
  onSubmit(trimmed);
62
86
  },
@@ -67,7 +91,33 @@ export function InputLine({ onSubmit, isDisabled = false }: InputLineProps) {
67
91
  (_input, key) => {
68
92
  if (isDisabled) return;
69
93
 
70
- // Up arrow history prev
94
+ // ── Dropdown navigation ───────────────────────────────────────────
95
+ if (showDropdown) {
96
+ if (key.upArrow) {
97
+ setDropdownIdx((i) => Math.max(0, i - 1));
98
+ return;
99
+ }
100
+ if (key.downArrow) {
101
+ setDropdownIdx((i) =>
102
+ Math.min(dropdownCandidates.length - 1, i + 1)
103
+ );
104
+ return;
105
+ }
106
+ if (key.return) {
107
+ // Select the highlighted candidate
108
+ if (dropdownCandidates[dropdownIdx]) {
109
+ setValue(dropdownCandidates[dropdownIdx] + " ");
110
+ }
111
+ setShowDropdown(false);
112
+ return;
113
+ }
114
+ if (key.escape) {
115
+ setShowDropdown(false);
116
+ return;
117
+ }
118
+ }
119
+
120
+ // ── History navigation ────────────────────────────────────────────
71
121
  if (key.upArrow) {
72
122
  setHistory((hist) => {
73
123
  setHistoryIdx((idx) => {
@@ -88,7 +138,6 @@ export function InputLine({ onSubmit, isDisabled = false }: InputLineProps) {
88
138
  return;
89
139
  }
90
140
 
91
- // Down arrow — history next
92
141
  if (key.downArrow) {
93
142
  setHistory((hist) => {
94
143
  setHistoryIdx((idx) => {
@@ -109,32 +158,27 @@ export function InputLine({ onSubmit, isDisabled = false }: InputLineProps) {
109
158
  return;
110
159
  }
111
160
 
112
- // Tab — completion
161
+ // ── Tab — completion / dropdown ───────────────────────────────────
113
162
  if (_input === "\t") {
114
- const allTop = [...BUILTIN_CMDS, ...topCmds];
115
- const trimmed = value.trimStart();
116
- const spaceIdx = trimmed.indexOf(" ");
163
+ const completions = getCompletions(value);
117
164
 
118
- let completions: string[];
119
- if (spaceIdx === -1) {
120
- completions = allTop.filter((cmd) => cmd.startsWith(trimmed));
121
- } else {
122
- const parent = trimmed.slice(0, spaceIdx);
123
- const rest = trimmed.slice(spaceIdx + 1);
124
- const subs = subCmds.get(parent) ?? [];
125
- completions = subs
126
- .filter((s) => s.startsWith(rest))
127
- .map((s) => `${parent} ${s}`);
165
+ if (completions.length === 0) {
166
+ setShowDropdown(false);
167
+ return;
128
168
  }
129
169
 
130
- if (completions.length === 0) return;
131
-
132
170
  if (completions.length === 1) {
133
171
  setValue(completions[0] + " ");
172
+ setShowDropdown(false);
134
173
  return;
135
174
  }
136
175
 
137
- // Find common prefix
176
+ // Show dropdown with multiple candidates
177
+ setDropdownCandidates(completions);
178
+ setDropdownIdx(0);
179
+ setShowDropdown(true);
180
+
181
+ // Also advance to common prefix
138
182
  const common = completions.reduce((a, b) => {
139
183
  let i = 0;
140
184
  while (i < a.length && i < b.length && a[i] === b[i]) i++;
@@ -144,21 +188,52 @@ export function InputLine({ onSubmit, isDisabled = false }: InputLineProps) {
144
188
  setValue(common);
145
189
  }
146
190
  }
191
+
192
+ // ── Escape — dismiss dropdown ─────────────────────────────────────
193
+ if (key.escape) {
194
+ setShowDropdown(false);
195
+ }
147
196
  },
148
197
  { isActive: !isDisabled }
149
198
  );
150
199
 
200
+ // Dismiss dropdown when value changes (user types more)
201
+ const handleChange = useCallback(
202
+ (newVal: string) => {
203
+ setValue(newVal);
204
+ // If dropdown is open, update candidates live
205
+ if (showDropdown) {
206
+ const completions = getCompletions(newVal);
207
+ if (completions.length <= 1) {
208
+ setShowDropdown(false);
209
+ } else {
210
+ setDropdownCandidates(completions);
211
+ setDropdownIdx(0);
212
+ }
213
+ }
214
+ },
215
+ [showDropdown, getCompletions]
216
+ );
217
+
151
218
  return (
152
- <Box>
153
- <Text color="cyan">◈</Text>
154
- <Text dimColor> arc402 </Text>
155
- <Text color="white">{">"} </Text>
156
- <TextInput
157
- value={value}
158
- onChange={setValue}
159
- onSubmit={handleSubmit}
160
- focus={!isDisabled}
219
+ <Box flexDirection="column">
220
+ {/* Completion dropdown renders above the input */}
221
+ <CompletionDropdown
222
+ candidates={dropdownCandidates}
223
+ selectedIndex={dropdownIdx}
224
+ visible={showDropdown}
161
225
  />
226
+ <Box>
227
+ <Text color="cyan">◈</Text>
228
+ <Text dimColor> arc402 </Text>
229
+ <Text color="white">{">"} </Text>
230
+ <TextInput
231
+ value={value}
232
+ onChange={handleChange}
233
+ onSubmit={handleSubmit}
234
+ focus={!isDisabled}
235
+ />
236
+ </Box>
162
237
  </Box>
163
238
  );
164
239
  }
@@ -17,13 +17,10 @@ export function Viewport({ lines, scrollOffset, isAutoScroll }: ViewportProps) {
17
17
  const { stdout } = useStdout();
18
18
  const termRows = stdout?.rows ?? 24;
19
19
 
20
- // We'll compute the viewport height: total rows minus fixed areas
21
- // Header is approximately bannerLines + separator (~14-16 rows)
22
- // Footer is 1 row
23
- // We'll use a reasonable estimate here; the parent App can pass exact height
24
- const HEADER_ROWS = 15; // approximate
25
- const FOOTER_ROWS = 1;
26
- const viewportHeight = Math.max(1, termRows - HEADER_ROWS - FOOTER_ROWS);
20
+ // Approximate viewport height for scroll slicing.
21
+ // The actual flex layout handles visual sizing; this is for computing
22
+ // which lines to show in the scroll window.
23
+ const viewportHeight = Math.max(1, termRows - 18);
27
24
 
28
25
  // Compute the window slice
29
26
  // scrollOffset=0 → show last viewportHeight lines
@@ -0,0 +1,38 @@
1
+ import React from "react";
2
+ import { Box, Text, useFocus, useInput } from "ink";
3
+
4
+ export interface ButtonProps {
5
+ label: string;
6
+ onPress: () => void;
7
+ variant?: "primary" | "danger" | "dim";
8
+ }
9
+
10
+ const VARIANT_COLORS: Record<string, string> = {
11
+ primary: "cyan",
12
+ danger: "red",
13
+ dim: "gray",
14
+ };
15
+
16
+ export function Button({ label, onPress, variant = "primary" }: ButtonProps) {
17
+ const { isFocused } = useFocus();
18
+
19
+ useInput(
20
+ (_input, key) => {
21
+ if (key.return) {
22
+ onPress();
23
+ }
24
+ },
25
+ { isActive: isFocused }
26
+ );
27
+
28
+ const color = isFocused ? VARIANT_COLORS[variant] ?? "cyan" : "white";
29
+
30
+ return (
31
+ <Box>
32
+ <Text color={color} bold={isFocused}>
33
+ {isFocused ? "▸ " : " "}
34
+ {label}
35
+ </Text>
36
+ </Box>
37
+ );
38
+ }
@@ -0,0 +1,39 @@
1
+ import React from "react";
2
+ import { Box, Text } from "ink";
3
+ import { StepSpinner } from "./StepSpinner.js";
4
+ import type { StepStatus } from "./StepSpinner.js";
5
+
6
+ export interface CeremonyStep {
7
+ label: string;
8
+ status: StepStatus;
9
+ detail?: string;
10
+ error?: string;
11
+ }
12
+
13
+ export interface CeremonyViewProps {
14
+ title: string;
15
+ steps: CeremonyStep[];
16
+ }
17
+
18
+ export function CeremonyView({ title, steps }: CeremonyViewProps) {
19
+ return (
20
+ <Box flexDirection="column">
21
+ <Box marginBottom={1}>
22
+ <Text bold color="cyan">
23
+ ◈ {title}
24
+ </Text>
25
+ </Box>
26
+ {steps.map((step, i) => (
27
+ <StepSpinner
28
+ key={i}
29
+ step={i + 1}
30
+ total={steps.length}
31
+ label={step.label}
32
+ status={step.status}
33
+ detail={step.detail}
34
+ error={step.error}
35
+ />
36
+ ))}
37
+ </Box>
38
+ );
39
+ }
@@ -0,0 +1,59 @@
1
+ import React from "react";
2
+ import { Box, Text } from "ink";
3
+
4
+ export interface CompletionDropdownProps {
5
+ candidates: string[];
6
+ selectedIndex: number;
7
+ visible: boolean;
8
+ }
9
+
10
+ const MAX_VISIBLE = 8;
11
+
12
+ export function CompletionDropdown({
13
+ candidates,
14
+ selectedIndex,
15
+ visible,
16
+ }: CompletionDropdownProps) {
17
+ if (!visible || candidates.length === 0) return null;
18
+
19
+ // Window the list if there are too many candidates
20
+ let startIdx = 0;
21
+ if (candidates.length > MAX_VISIBLE) {
22
+ startIdx = Math.max(0, selectedIndex - Math.floor(MAX_VISIBLE / 2));
23
+ startIdx = Math.min(startIdx, candidates.length - MAX_VISIBLE);
24
+ }
25
+ const visibleCandidates = candidates.slice(
26
+ startIdx,
27
+ startIdx + MAX_VISIBLE
28
+ );
29
+
30
+ return (
31
+ <Box flexDirection="column" marginLeft={4}>
32
+ <Box>
33
+ <Text dimColor>{"┌─ completions ─"}</Text>
34
+ </Box>
35
+ {visibleCandidates.map((candidate, i) => {
36
+ const actualIdx = startIdx + i;
37
+ const isSelected = actualIdx === selectedIndex;
38
+ return (
39
+ <Box key={candidate}>
40
+ <Text dimColor>{"│"}</Text>
41
+ <Text color={isSelected ? "cyan" : "white"} bold={isSelected}>
42
+ {isSelected ? " ▸ " : " "}
43
+ {candidate}
44
+ </Text>
45
+ </Box>
46
+ );
47
+ })}
48
+ <Box>
49
+ <Text dimColor>{"└─"}</Text>
50
+ {candidates.length > MAX_VISIBLE && (
51
+ <Text dimColor>
52
+ {" "}
53
+ ({candidates.length} total)
54
+ </Text>
55
+ )}
56
+ </Box>
57
+ </Box>
58
+ );
59
+ }
@@ -0,0 +1,36 @@
1
+ import React from "react";
2
+ import { Box, Text } from "ink";
3
+ import { Button } from "./Button.js";
4
+
5
+ export interface ConfirmPromptProps {
6
+ message: string;
7
+ onConfirm: () => void;
8
+ onCancel: () => void;
9
+ confirmLabel?: string;
10
+ cancelLabel?: string;
11
+ }
12
+
13
+ export function ConfirmPrompt({
14
+ message,
15
+ onConfirm,
16
+ onCancel,
17
+ confirmLabel = "Confirm",
18
+ cancelLabel = "Cancel",
19
+ }: ConfirmPromptProps) {
20
+ return (
21
+ <Box flexDirection="column">
22
+ <Box marginBottom={1}>
23
+ <Text bold color="cyan">
24
+ ◈ {message}
25
+ </Text>
26
+ </Box>
27
+ <Box gap={2}>
28
+ <Button label={confirmLabel} onPress={onConfirm} variant="primary" />
29
+ <Button label={cancelLabel} onPress={onCancel} variant="dim" />
30
+ </Box>
31
+ <Box marginTop={1}>
32
+ <Text dimColor>Tab to switch · Enter to select</Text>
33
+ </Box>
34
+ </Box>
35
+ );
36
+ }
@@ -0,0 +1,112 @@
1
+ import React, { useState } from "react";
2
+ import { Box, Text, useInput } from "ink";
3
+
4
+ export interface Column {
5
+ header: string;
6
+ key: string;
7
+ width?: number;
8
+ align?: "left" | "right";
9
+ }
10
+
11
+ export interface InteractiveTableProps {
12
+ columns: Column[];
13
+ rows: Record<string, string>[];
14
+ onSelect?: (row: Record<string, string>, index: number) => void;
15
+ selectedIndex?: number;
16
+ }
17
+
18
+ const MAX_VISIBLE_ROWS = 15;
19
+
20
+ export function InteractiveTable({
21
+ columns,
22
+ rows,
23
+ onSelect,
24
+ selectedIndex: controlledIdx,
25
+ }: InteractiveTableProps) {
26
+ const [internalIdx, setInternalIdx] = useState(0);
27
+ const selectedIndex = controlledIdx ?? internalIdx;
28
+
29
+ useInput((_input, key) => {
30
+ if (key.upArrow) {
31
+ setInternalIdx((i) => Math.max(0, i - 1));
32
+ }
33
+ if (key.downArrow) {
34
+ setInternalIdx((i) => Math.min(rows.length - 1, i + 1));
35
+ }
36
+ if (key.return && onSelect && rows[selectedIndex]) {
37
+ onSelect(rows[selectedIndex], selectedIndex);
38
+ }
39
+ });
40
+
41
+ // Compute column widths
42
+ const colWidths = columns.map((col) => {
43
+ if (col.width) return col.width;
44
+ let max = col.header.length;
45
+ for (const row of rows) {
46
+ const val = row[col.key] ?? "";
47
+ if (val.length > max) max = val.length;
48
+ }
49
+ return Math.min(max + 2, 30);
50
+ });
51
+
52
+ const pad = (text: string, width: number, align: "left" | "right" = "left"): string => {
53
+ const truncated = text.length > width ? text.slice(0, width - 1) + "…" : text;
54
+ if (align === "right") return truncated.padStart(width);
55
+ return truncated.padEnd(width);
56
+ };
57
+
58
+ // Window visible rows
59
+ let startRow = 0;
60
+ if (rows.length > MAX_VISIBLE_ROWS) {
61
+ startRow = Math.max(0, selectedIndex - Math.floor(MAX_VISIBLE_ROWS / 2));
62
+ startRow = Math.min(startRow, rows.length - MAX_VISIBLE_ROWS);
63
+ }
64
+ const visibleRows = rows.slice(startRow, startRow + MAX_VISIBLE_ROWS);
65
+
66
+ // Header
67
+ const headerLine = columns
68
+ .map((col, i) => pad(col.header, colWidths[i], col.align))
69
+ .join(" ");
70
+ const separatorLine = "─".repeat(headerLine.length);
71
+
72
+ return (
73
+ <Box flexDirection="column">
74
+ <Box>
75
+ <Text bold color="white">
76
+ {" "}
77
+ {headerLine}
78
+ </Text>
79
+ </Box>
80
+ <Box>
81
+ <Text dimColor> {separatorLine}</Text>
82
+ </Box>
83
+ {visibleRows.map((row, vi) => {
84
+ const actualIdx = startRow + vi;
85
+ const isSelected = actualIdx === selectedIndex;
86
+ const line = columns
87
+ .map((col, i) => pad(row[col.key] ?? "", colWidths[i], col.align))
88
+ .join(" ");
89
+ return (
90
+ <Box key={actualIdx}>
91
+ <Text color={isSelected ? "cyan" : "white"} bold={isSelected}>
92
+ {isSelected ? "▸" : " "} {line}
93
+ </Text>
94
+ </Box>
95
+ );
96
+ })}
97
+ {rows.length > MAX_VISIBLE_ROWS && (
98
+ <Box>
99
+ <Text dimColor>
100
+ {" "}
101
+ ({rows.length} rows · ↑↓ navigate · Enter select)
102
+ </Text>
103
+ </Box>
104
+ )}
105
+ {rows.length <= MAX_VISIBLE_ROWS && rows.length > 0 && (
106
+ <Box>
107
+ <Text dimColor> (↑↓ navigate · Enter select)</Text>
108
+ </Box>
109
+ )}
110
+ </Box>
111
+ );
112
+ }
@@ -0,0 +1,84 @@
1
+ import React, { useState, useEffect } from "react";
2
+ import { Box, Text } from "ink";
3
+
4
+ const SPINNER_FRAMES = ["◈", "◇", "◆", "◇"];
5
+ const SPINNER_INTERVAL = 120;
6
+
7
+ export type StepStatus = "pending" | "running" | "done" | "error";
8
+
9
+ export interface StepSpinnerProps {
10
+ step: number;
11
+ total: number;
12
+ label: string;
13
+ status: StepStatus;
14
+ detail?: string;
15
+ error?: string;
16
+ }
17
+
18
+ export function StepSpinner({
19
+ step,
20
+ total,
21
+ label,
22
+ status,
23
+ detail,
24
+ error,
25
+ }: StepSpinnerProps) {
26
+ const [frame, setFrame] = useState(0);
27
+
28
+ useEffect(() => {
29
+ if (status !== "running") return;
30
+ const timer = setInterval(() => {
31
+ setFrame((f) => (f + 1) % SPINNER_FRAMES.length);
32
+ }, SPINNER_INTERVAL);
33
+ return () => clearInterval(timer);
34
+ }, [status]);
35
+
36
+ const prefix = `Step ${step}/${total}`;
37
+
38
+ if (status === "pending") {
39
+ return (
40
+ <Box>
41
+ <Text dimColor> {prefix} — {label}</Text>
42
+ </Box>
43
+ );
44
+ }
45
+
46
+ if (status === "running") {
47
+ return (
48
+ <Box flexDirection="column">
49
+ <Box>
50
+ <Text color="cyan"> {SPINNER_FRAMES[frame]} {prefix} — {label}...</Text>
51
+ </Box>
52
+ </Box>
53
+ );
54
+ }
55
+
56
+ if (status === "done") {
57
+ return (
58
+ <Box flexDirection="column">
59
+ <Box>
60
+ <Text color="green"> ✓ {prefix} — {label}</Text>
61
+ </Box>
62
+ {detail && (
63
+ <Box>
64
+ <Text dimColor> └ {detail}</Text>
65
+ </Box>
66
+ )}
67
+ </Box>
68
+ );
69
+ }
70
+
71
+ // error
72
+ return (
73
+ <Box flexDirection="column">
74
+ <Box>
75
+ <Text color="red"> ✗ {prefix} — {label}</Text>
76
+ </Box>
77
+ {error && (
78
+ <Box>
79
+ <Text color="red"> └ {error}</Text>
80
+ </Box>
81
+ )}
82
+ </Box>
83
+ );
84
+ }
@@ -0,0 +1,59 @@
1
+ import React, { useEffect } from "react";
2
+ import { Box, Text } from "ink";
3
+
4
+ export type ToastVariant = "info" | "success" | "warning" | "error";
5
+
6
+ export interface ToastData {
7
+ id: string;
8
+ message: string;
9
+ variant: ToastVariant;
10
+ duration?: number;
11
+ }
12
+
13
+ export interface ToastProps {
14
+ toast: ToastData;
15
+ onDismiss: (id: string) => void;
16
+ }
17
+
18
+ const VARIANT_CONFIG: Record<ToastVariant, { icon: string; color: string }> = {
19
+ info: { icon: "◈", color: "cyan" },
20
+ success: { icon: "✓", color: "green" },
21
+ warning: { icon: "⚠", color: "yellow" },
22
+ error: { icon: "✗", color: "red" },
23
+ };
24
+
25
+ export function Toast({ toast, onDismiss }: ToastProps) {
26
+ const { icon, color } = VARIANT_CONFIG[toast.variant];
27
+
28
+ useEffect(() => {
29
+ const timer = setTimeout(() => {
30
+ onDismiss(toast.id);
31
+ }, toast.duration ?? 5000);
32
+ return () => clearTimeout(timer);
33
+ }, [toast.id, toast.duration, onDismiss]);
34
+
35
+ return (
36
+ <Box>
37
+ <Text color={color}>
38
+ {icon} {toast.message}
39
+ </Text>
40
+ </Box>
41
+ );
42
+ }
43
+
44
+ export interface ToastContainerProps {
45
+ toasts: ToastData[];
46
+ onDismiss: (id: string) => void;
47
+ }
48
+
49
+ export function ToastContainer({ toasts, onDismiss }: ToastContainerProps) {
50
+ if (toasts.length === 0) return null;
51
+
52
+ return (
53
+ <Box flexDirection="column">
54
+ {toasts.map((toast) => (
55
+ <Toast key={toast.id} toast={toast} onDismiss={onDismiss} />
56
+ ))}
57
+ </Box>
58
+ );
59
+ }