rax-flow 0.1.8 → 0.2.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.
Files changed (224) hide show
  1. package/dist/bin.js +8 -6
  2. package/dist/bin.js.map +1 -1
  3. package/dist/hub/commands/index.d.ts.map +1 -1
  4. package/dist/hub/commands/index.js +7 -4
  5. package/dist/hub/commands/index.js.map +1 -1
  6. package/dist/hub/event-listener.d.ts +6 -0
  7. package/dist/hub/event-listener.d.ts.map +1 -1
  8. package/dist/hub/event-listener.js +10 -6
  9. package/dist/hub/event-listener.js.map +1 -1
  10. package/dist/hub/index.d.ts.map +1 -1
  11. package/dist/hub/index.js +12 -0
  12. package/dist/hub/index.js.map +1 -1
  13. package/dist/setup/components/ApiKeyInput.d.ts +25 -0
  14. package/dist/setup/components/ApiKeyInput.d.ts.map +1 -0
  15. package/dist/setup/components/ApiKeyInput.js +54 -0
  16. package/dist/setup/components/ApiKeyInput.js.map +1 -0
  17. package/dist/setup/components/AsciiBanner.d.ts +22 -0
  18. package/dist/setup/components/AsciiBanner.d.ts.map +1 -0
  19. package/dist/setup/components/AsciiBanner.js +55 -0
  20. package/dist/setup/components/AsciiBanner.js.map +1 -0
  21. package/dist/setup/components/CliDetector.d.ts +17 -0
  22. package/dist/setup/components/CliDetector.d.ts.map +1 -0
  23. package/dist/setup/components/CliDetector.js +79 -0
  24. package/dist/setup/components/CliDetector.js.map +1 -0
  25. package/dist/setup/components/ModeSelector.d.ts +8 -0
  26. package/dist/setup/components/ModeSelector.d.ts.map +1 -0
  27. package/dist/setup/components/ModeSelector.js +76 -0
  28. package/dist/setup/components/ModeSelector.js.map +1 -0
  29. package/dist/setup/components/ProviderSelector.d.ts +18 -0
  30. package/dist/setup/components/ProviderSelector.d.ts.map +1 -0
  31. package/dist/setup/components/ProviderSelector.js +97 -0
  32. package/dist/setup/components/ProviderSelector.js.map +1 -0
  33. package/dist/setup/components/SetupWizard.d.ts +2 -0
  34. package/dist/setup/components/SetupWizard.d.ts.map +1 -0
  35. package/dist/setup/components/SetupWizard.js +212 -0
  36. package/dist/setup/components/SetupWizard.js.map +1 -0
  37. package/dist/setup/components/StepIndicator.d.ts +13 -0
  38. package/dist/setup/components/StepIndicator.d.ts.map +1 -0
  39. package/dist/setup/components/StepIndicator.js +18 -0
  40. package/dist/setup/components/StepIndicator.js.map +1 -0
  41. package/dist/setup/components/SuccessScreen.d.ts +18 -0
  42. package/dist/setup/components/SuccessScreen.d.ts.map +1 -0
  43. package/dist/setup/components/SuccessScreen.js +38 -0
  44. package/dist/setup/components/SuccessScreen.js.map +1 -0
  45. package/dist/setup/index.d.ts +12 -0
  46. package/dist/setup/index.d.ts.map +1 -0
  47. package/dist/setup/index.js +29 -0
  48. package/dist/setup/index.js.map +1 -0
  49. package/dist/setup/utils/cli-detection.d.ts +12 -0
  50. package/dist/setup/utils/cli-detection.d.ts.map +1 -0
  51. package/dist/setup/utils/cli-detection.js +83 -0
  52. package/dist/setup/utils/cli-detection.js.map +1 -0
  53. package/dist/setup/utils/config-writer.d.ts +43 -0
  54. package/dist/setup/utils/config-writer.d.ts.map +1 -0
  55. package/dist/setup/utils/config-writer.js +180 -0
  56. package/dist/setup/utils/config-writer.js.map +1 -0
  57. package/dist/tui/App.d.ts +2 -1
  58. package/dist/tui/App.d.ts.map +1 -1
  59. package/dist/tui/App.js +88 -20
  60. package/dist/tui/App.js.map +1 -1
  61. package/dist/tui/components/AgentStateIcon.d.ts +18 -0
  62. package/dist/tui/components/AgentStateIcon.d.ts.map +1 -0
  63. package/dist/tui/components/AgentStateIcon.js +57 -0
  64. package/dist/tui/components/AgentStateIcon.js.map +1 -0
  65. package/dist/tui/components/AnimatedBranch.d.ts +39 -0
  66. package/dist/tui/components/AnimatedBranch.d.ts.map +1 -0
  67. package/dist/tui/components/AnimatedBranch.js +64 -0
  68. package/dist/tui/components/AnimatedBranch.js.map +1 -0
  69. package/dist/tui/components/ChatPanel.d.ts +2 -1
  70. package/dist/tui/components/ChatPanel.d.ts.map +1 -1
  71. package/dist/tui/components/ChatPanel.js +47 -28
  72. package/dist/tui/components/ChatPanel.js.map +1 -1
  73. package/dist/tui/components/DAGPanel.d.ts +14 -2
  74. package/dist/tui/components/DAGPanel.d.ts.map +1 -1
  75. package/dist/tui/components/DAGPanel.js +48 -27
  76. package/dist/tui/components/DAGPanel.js.map +1 -1
  77. package/dist/tui/components/ExecutionTimeline.d.ts +34 -0
  78. package/dist/tui/components/ExecutionTimeline.d.ts.map +1 -0
  79. package/dist/tui/components/ExecutionTimeline.js +67 -0
  80. package/dist/tui/components/ExecutionTimeline.js.map +1 -0
  81. package/dist/tui/components/Header.d.ts +2 -1
  82. package/dist/tui/components/Header.d.ts.map +1 -1
  83. package/dist/tui/components/Header.js +26 -19
  84. package/dist/tui/components/Header.js.map +1 -1
  85. package/dist/tui/components/HelpOverlay.d.ts +2 -1
  86. package/dist/tui/components/HelpOverlay.d.ts.map +1 -1
  87. package/dist/tui/components/HelpOverlay.js +59 -41
  88. package/dist/tui/components/HelpOverlay.js.map +1 -1
  89. package/dist/tui/components/InputBar.d.ts +3 -1
  90. package/dist/tui/components/InputBar.d.ts.map +1 -1
  91. package/dist/tui/components/InputBar.js +12 -7
  92. package/dist/tui/components/InputBar.js.map +1 -1
  93. package/dist/tui/components/LogsPanel.d.ts +9 -0
  94. package/dist/tui/components/LogsPanel.d.ts.map +1 -0
  95. package/dist/tui/components/LogsPanel.js +56 -0
  96. package/dist/tui/components/LogsPanel.js.map +1 -0
  97. package/dist/tui/components/MemoryPanel.d.ts +21 -0
  98. package/dist/tui/components/MemoryPanel.d.ts.map +1 -0
  99. package/dist/tui/components/MemoryPanel.js +51 -0
  100. package/dist/tui/components/MemoryPanel.js.map +1 -0
  101. package/dist/tui/components/MetricsPanel.d.ts +18 -0
  102. package/dist/tui/components/MetricsPanel.d.ts.map +1 -0
  103. package/dist/tui/components/MetricsPanel.js +27 -0
  104. package/dist/tui/components/MetricsPanel.js.map +1 -0
  105. package/dist/tui/components/StatusPanel.d.ts +3 -1
  106. package/dist/tui/components/StatusPanel.d.ts.map +1 -1
  107. package/dist/tui/components/StatusPanel.js +20 -18
  108. package/dist/tui/components/StatusPanel.js.map +1 -1
  109. package/dist/tui/components/TaskTree.d.ts +28 -0
  110. package/dist/tui/components/TaskTree.d.ts.map +1 -0
  111. package/dist/tui/components/TaskTree.js +29 -0
  112. package/dist/tui/components/TaskTree.js.map +1 -0
  113. package/dist/tui/components/animations/ProgressBar.d.ts +39 -0
  114. package/dist/tui/components/animations/ProgressBar.d.ts.map +1 -0
  115. package/dist/tui/components/animations/ProgressBar.js +39 -0
  116. package/dist/tui/components/animations/ProgressBar.js.map +1 -0
  117. package/dist/tui/components/animations/Pulse.d.ts +17 -0
  118. package/dist/tui/components/animations/Pulse.d.ts.map +1 -0
  119. package/dist/tui/components/animations/Pulse.js +47 -0
  120. package/dist/tui/components/animations/Pulse.js.map +1 -0
  121. package/dist/tui/components/animations/Spinner.d.ts +13 -0
  122. package/dist/tui/components/animations/Spinner.d.ts.map +1 -0
  123. package/dist/tui/components/animations/Spinner.js +36 -0
  124. package/dist/tui/components/animations/Spinner.js.map +1 -0
  125. package/dist/tui/components/animations/StatusAnimator.d.ts +27 -0
  126. package/dist/tui/components/animations/StatusAnimator.d.ts.map +1 -0
  127. package/dist/tui/components/animations/StatusAnimator.js +85 -0
  128. package/dist/tui/components/animations/StatusAnimator.js.map +1 -0
  129. package/dist/tui/components/animations/TypingEffect.d.ts +26 -0
  130. package/dist/tui/components/animations/TypingEffect.d.ts.map +1 -0
  131. package/dist/tui/components/animations/TypingEffect.js +59 -0
  132. package/dist/tui/components/animations/TypingEffect.js.map +1 -0
  133. package/dist/tui/components/animations/index.d.ts +8 -0
  134. package/dist/tui/components/animations/index.d.ts.map +1 -0
  135. package/dist/tui/components/animations/index.js +6 -0
  136. package/dist/tui/components/animations/index.js.map +1 -0
  137. package/dist/tui/hooks/useAnimation.d.ts +42 -0
  138. package/dist/tui/hooks/useAnimation.d.ts.map +1 -0
  139. package/dist/tui/hooks/useAnimation.js +212 -0
  140. package/dist/tui/hooks/useAnimation.js.map +1 -0
  141. package/dist/tui/hooks/useAppState.d.ts +10 -0
  142. package/dist/tui/hooks/useAppState.d.ts.map +1 -1
  143. package/dist/tui/hooks/useAppState.js +178 -75
  144. package/dist/tui/hooks/useAppState.js.map +1 -1
  145. package/dist/tui/services/orchestrator.d.ts +16 -0
  146. package/dist/tui/services/orchestrator.d.ts.map +1 -0
  147. package/dist/tui/services/orchestrator.js +152 -0
  148. package/dist/tui/services/orchestrator.js.map +1 -0
  149. package/dist/tui/styles/borders.d.ts +31 -0
  150. package/dist/tui/styles/borders.d.ts.map +1 -0
  151. package/dist/tui/styles/borders.js +47 -0
  152. package/dist/tui/styles/borders.js.map +1 -0
  153. package/dist/tui/styles/colors.d.ts +18 -0
  154. package/dist/tui/styles/colors.d.ts.map +1 -0
  155. package/dist/tui/styles/colors.js +18 -0
  156. package/dist/tui/styles/colors.js.map +1 -0
  157. package/dist/tui/styles/index.d.ts +6 -0
  158. package/dist/tui/styles/index.d.ts.map +1 -0
  159. package/dist/tui/styles/index.js +6 -0
  160. package/dist/tui/styles/index.js.map +1 -0
  161. package/dist/tui/styles/indicators.d.ts +67 -0
  162. package/dist/tui/styles/indicators.d.ts.map +1 -0
  163. package/dist/tui/styles/indicators.js +42 -0
  164. package/dist/tui/styles/indicators.js.map +1 -0
  165. package/dist/tui/styles/layout.d.ts +21 -0
  166. package/dist/tui/styles/layout.d.ts.map +1 -0
  167. package/dist/tui/styles/layout.js +42 -0
  168. package/dist/tui/styles/layout.js.map +1 -0
  169. package/dist/tui/styles/providers.d.ts +77 -0
  170. package/dist/tui/styles/providers.d.ts.map +1 -0
  171. package/dist/tui/styles/providers.js +31 -0
  172. package/dist/tui/styles/providers.js.map +1 -0
  173. package/dist/tui/utils/animation.d.ts +44 -0
  174. package/dist/tui/utils/animation.d.ts.map +1 -0
  175. package/dist/tui/utils/animation.js +107 -0
  176. package/dist/tui/utils/animation.js.map +1 -0
  177. package/package.json +8 -8
  178. package/src/bin.ts +8 -5
  179. package/src/hub/commands/index.ts +7 -4
  180. package/src/hub/event-listener.ts +14 -10
  181. package/src/hub/index.ts +14 -2
  182. package/src/setup/components/ApiKeyInput.tsx +158 -0
  183. package/src/setup/components/AsciiBanner.tsx +125 -0
  184. package/src/setup/components/CliDetector.tsx +230 -0
  185. package/src/setup/components/ModeSelector.tsx +137 -0
  186. package/src/setup/components/ProviderSelector.tsx +174 -0
  187. package/src/setup/components/SetupWizard.tsx +368 -0
  188. package/src/setup/components/StepIndicator.tsx +74 -0
  189. package/src/setup/components/SuccessScreen.tsx +229 -0
  190. package/src/setup/index.ts +34 -0
  191. package/src/setup/utils/cli-detection.ts +99 -0
  192. package/src/setup/utils/config-writer.ts +249 -0
  193. package/src/tui/App.tsx +117 -53
  194. package/src/tui/components/AgentStateIcon.tsx +84 -0
  195. package/src/tui/components/AnimatedBranch.tsx +134 -0
  196. package/src/tui/components/ChatPanel.tsx +85 -43
  197. package/src/tui/components/DAGPanel.tsx +150 -58
  198. package/src/tui/components/ExecutionTimeline.tsx +225 -0
  199. package/src/tui/components/Header.tsx +76 -43
  200. package/src/tui/components/HelpOverlay.tsx +118 -61
  201. package/src/tui/components/InputBar.tsx +33 -19
  202. package/src/tui/components/LogsPanel.tsx +129 -0
  203. package/src/tui/components/MemoryPanel.tsx +163 -0
  204. package/src/tui/components/MetricsPanel.tsx +149 -0
  205. package/src/tui/components/StatusPanel.tsx +84 -37
  206. package/src/tui/components/TaskTree.tsx +159 -0
  207. package/src/tui/components/animations/ProgressBar.tsx +160 -0
  208. package/src/tui/components/animations/Pulse.tsx +73 -0
  209. package/src/tui/components/animations/Spinner.tsx +54 -0
  210. package/src/tui/components/animations/StatusAnimator.tsx +153 -0
  211. package/src/tui/components/animations/TypingEffect.tsx +119 -0
  212. package/src/tui/components/animations/index.ts +16 -0
  213. package/src/tui/hooks/useAnimation.ts +290 -0
  214. package/src/tui/hooks/useAppState.ts +206 -67
  215. package/src/tui/services/orchestrator.ts +195 -0
  216. package/src/tui/styles/borders.ts +51 -0
  217. package/src/tui/styles/colors.ts +19 -0
  218. package/src/tui/styles/index.ts +20 -0
  219. package/src/tui/styles/indicators.ts +54 -0
  220. package/src/tui/styles/layout.ts +44 -0
  221. package/src/tui/styles/providers.ts +32 -0
  222. package/src/tui/utils/animation.ts +124 -0
  223. package/LICENSE +0 -21
  224. package/tsconfig.tsbuildinfo +0 -1
@@ -0,0 +1,73 @@
1
+ import React, { memo } from "react";
2
+ import { Text } from "ink";
3
+ import { useAnimation } from "../../hooks/useAnimation.js";
4
+ import { tuiColors } from "../../styles/index.js";
5
+
6
+ const PULSE_FRAMES = ["●", "◐", "○", "◐"];
7
+ const BREATH_FRAMES = ["●", "●", "◐", "◐", "○", "○", "◐", "◐"];
8
+ const PING_FRAMES = ["●", "●", "●", "○", "○", "○", "○", "○", "○", "○"];
9
+
10
+ const FRAME_MAP = {
11
+ pulse: PULSE_FRAMES,
12
+ breath: BREATH_FRAMES,
13
+ ping: PING_FRAMES,
14
+ } as const;
15
+
16
+ const DEFAULT_INTERVALS = {
17
+ pulse: 300,
18
+ breath: 600,
19
+ ping: 400,
20
+ } as const;
21
+
22
+ interface PulseProps {
23
+ interval?: number;
24
+ color?: string;
25
+ isAnimating?: boolean;
26
+ type?: "pulse" | "breath" | "ping";
27
+ }
28
+
29
+ export const Pulse = memo(function Pulse({
30
+ interval,
31
+ color = tuiColors.success,
32
+ isAnimating = true,
33
+ type = "pulse"
34
+ }: PulseProps) {
35
+ const frames = FRAME_MAP[type];
36
+ const actualInterval = interval ?? DEFAULT_INTERVALS[type];
37
+ const { frame } = useAnimation({ interval: actualInterval, loop: true, autoStart: isAnimating, maxFps: 15 });
38
+ const currentFrame = frames[frame % frames.length];
39
+
40
+ return <Text color={color}>{currentFrame}</Text>;
41
+ });
42
+
43
+ export function usePulseFrame(tick: number, type: "pulse" | "breath" | "ping" = "pulse"): string {
44
+ const frames = FRAME_MAP[type];
45
+ return frames[tick % frames.length];
46
+ }
47
+
48
+ export function usePulseIntensity(tick: number, interval: number = 100): number {
49
+ const cycleLength = 20;
50
+ const phase = (tick % cycleLength) / cycleLength;
51
+ return 0.5 + Math.sin(phase * Math.PI * 2) * 0.5;
52
+ }
53
+
54
+ interface StatusPulseProps {
55
+ status: "online" | "offline" | "running" | "error";
56
+ tick?: number;
57
+ }
58
+
59
+ export const StatusPulse = memo(function StatusPulse({ status, tick }: StatusPulseProps) {
60
+ if (status === "running") {
61
+ return <Pulse interval={200} color={tuiColors.warning} type="pulse" />;
62
+ }
63
+
64
+ if (status === "online") {
65
+ return <Pulse interval={600} color={tuiColors.success} type="breath" />;
66
+ }
67
+
68
+ if (status === "error") {
69
+ return <Pulse interval={400} color={tuiColors.error} type="ping" />;
70
+ }
71
+
72
+ return <Text color={tuiColors.textTertiary}>○</Text>;
73
+ });
@@ -0,0 +1,54 @@
1
+ import React, { memo, useMemo } from "react";
2
+ import { Text } from "ink";
3
+ import { useAnimation } from "../../hooks/useAnimation.js";
4
+ import { tuiColors } from "../../styles/index.js";
5
+
6
+ export type SpinnerType = "dots" | "circle" | "pulse" | "brackets" | "arrows" | "hamburger" | "grow";
7
+
8
+ const SPINNER_FRAMES: Record<SpinnerType, string[]> = {
9
+ dots: ["⠋", "⠙", "⠹", "⠸", "⼸", "⠴", "⠦", "⠧", "⠇", "⠏"],
10
+ circle: ["◐", "◓", "◑", "◒"],
11
+ pulse: ["●", "◐", "○", "◐"],
12
+ brackets: ["[ ]", "[= ]", "[== ]", "[=== ]", "[==== ]", "[===== ]", "[====== ]", "[======= ]", "[======== ]", "[========= ]", "[==========]", "[ =========]", "[ ========]", "[ =======]", "[ ======]", "[ =====]", "[ ====]", "[ ===]", "[ ==]", "[ =]"],
13
+ arrows: ["←", "↖", "↑", "↗", "→", "↘", "↓", "↙"],
14
+ hamburger: ["☰", "☱", "ěr", "☳", "☴", "pě", "☲", "☶"],
15
+ grow: ["▁", "▂", "▃", "▄", "▅", "▆", "▇", "█", "▇", "▆", "▅", "▄", "▃", "▂"],
16
+ };
17
+
18
+ const DEFAULT_INTERVALS: Record<SpinnerType, number> = {
19
+ dots: 100,
20
+ circle: 120,
21
+ pulse: 200,
22
+ brackets: 80,
23
+ arrows: 100,
24
+ hamburger: 150,
25
+ grow: 100,
26
+ };
27
+
28
+ interface SpinnerProps {
29
+ type?: SpinnerType;
30
+ interval?: number;
31
+ color?: string;
32
+ isAnimating?: boolean;
33
+ }
34
+
35
+ export const Spinner = memo(function Spinner({
36
+ type = "dots",
37
+ interval,
38
+ color = tuiColors.primary,
39
+ isAnimating = true
40
+ }: SpinnerProps) {
41
+ const frames = SPINNER_FRAMES[type];
42
+ const actualInterval = interval ?? DEFAULT_INTERVALS[type];
43
+ const { frame } = useAnimation({ interval: actualInterval, loop: true, autoStart: isAnimating, maxFps: 20 });
44
+ const currentFrame = frames[frame % frames.length];
45
+
46
+ return <Text color={color}>{currentFrame}</Text>;
47
+ });
48
+
49
+ export function useSpinnerFrame(type: SpinnerType = "dots", tick: number): string {
50
+ const frames = SPINNER_FRAMES[type];
51
+ return frames[tick % frames.length];
52
+ }
53
+
54
+ export const spinnerTypes = Object.keys(SPINNER_FRAMES) as SpinnerType[];
@@ -0,0 +1,153 @@
1
+ import React, { useState, useEffect, memo, useRef } from "react";
2
+ import { Box, Text } from "ink";
3
+ import { tuiColors, getStatusIndicator } from "../../styles/index.js";
4
+ import { useAnimation } from "../../hooks/useAnimation.js";
5
+
6
+ export type TransitionStatus = "entering" | "active" | "exiting" | "hidden";
7
+
8
+ interface StatusAnimatorProps {
9
+ status: "pending" | "running" | "done" | "error" | "idle" | "queued";
10
+ label?: string;
11
+ showLabel?: boolean;
12
+ transitionDuration?: number;
13
+ }
14
+
15
+ const STATUS_COLORS: Record<string, string> = {
16
+ pending: tuiColors.textTertiary,
17
+ queued: tuiColors.warning,
18
+ running: tuiColors.primary,
19
+ done: tuiColors.success,
20
+ error: tuiColors.error,
21
+ idle: tuiColors.textQuaternary,
22
+ };
23
+
24
+ const RUNNING_FRAMES = ["◐", "◓", "◑", "◒"];
25
+ const TRANSITION_FRAMES = ["○", "◐", "◓", "●"];
26
+ const EXIT_FRAMES = ["●", "◑", "◒", "○"];
27
+
28
+ const STATUS_ORDER = ["pending", "queued", "running", "done", "error", "idle"];
29
+
30
+ function getStatusColor(status: string): string {
31
+ return STATUS_COLORS[status] || tuiColors.textTertiary;
32
+ }
33
+
34
+ export const StatusAnimator = memo(function StatusAnimator({
35
+ status,
36
+ label,
37
+ showLabel = true,
38
+ transitionDuration = 500,
39
+ }: StatusAnimatorProps) {
40
+ const [displayStatus, setDisplayStatus] = useState(status);
41
+ const [isTransitioning, setIsTransitioning] = useState(false);
42
+ const [transitionFrame, setTransitionFrame] = useState(0);
43
+ const timeoutRef = useRef<NodeJS.Timeout | null>(null);
44
+
45
+ const { frame } = useAnimation({ interval: 100, loop: true, maxFps: 15 });
46
+
47
+ useEffect(() => {
48
+ if (status !== displayStatus) {
49
+ setIsTransitioning(true);
50
+ timeoutRef.current = setTimeout(() => {
51
+ setDisplayStatus(status);
52
+ setIsTransitioning(false);
53
+ }, transitionDuration);
54
+ return () => {
55
+ if (timeoutRef.current) clearTimeout(timeoutRef.current);
56
+ };
57
+ }
58
+ }, [status, displayStatus, transitionDuration]);
59
+
60
+ const getAnimatedIcon = (): string => {
61
+ if (status === "running") {
62
+ return RUNNING_FRAMES[frame % RUNNING_FRAMES.length];
63
+ }
64
+
65
+ if (isTransitioning) {
66
+ const frames = STATUS_ORDER.indexOf(status) > STATUS_ORDER.indexOf(displayStatus)
67
+ ? TRANSITION_FRAMES
68
+ : EXIT_FRAMES;
69
+ return frames[transitionFrame % frames.length];
70
+ }
71
+
72
+ const statusInfo = getStatusIndicator(displayStatus);
73
+ return statusInfo.icon;
74
+ };
75
+
76
+ const color = getStatusColor(status);
77
+
78
+ return (
79
+ <Box flexDirection="row">
80
+ <Text color={color}>{getAnimatedIcon()}</Text>
81
+ {showLabel && label && (
82
+ <Text color={color}> {label}</Text>
83
+ )}
84
+ {showLabel && !label && (
85
+ <Text color={tuiColors.textSecondary}> [{status.toUpperCase()}]</Text>
86
+ )}
87
+ </Box>
88
+ );
89
+ });
90
+
91
+ interface MetricPulseProps {
92
+ value: number | string;
93
+ label: string;
94
+ unit?: string;
95
+ threshold?: { warning: number; critical: number };
96
+ isHighlighted?: boolean;
97
+ }
98
+
99
+ export const MetricPulse = memo(function MetricPulse({
100
+ value,
101
+ label,
102
+ unit,
103
+ threshold,
104
+ isHighlighted
105
+ }: MetricPulseProps) {
106
+ const { frame } = useAnimation({ interval: 200, loop: true, maxFps: 10 });
107
+ const numValue = typeof value === "number" ? value : parseFloat(value) || 0;
108
+
109
+ let color = tuiColors.success;
110
+ if (threshold) {
111
+ if (numValue >= threshold.critical) color = tuiColors.error;
112
+ else if (numValue >= threshold.warning) color = tuiColors.warning;
113
+ }
114
+
115
+ return (
116
+ <Box flexDirection="row">
117
+ <Text color={tuiColors.textTertiary}>{label}:</Text>
118
+ <Text color={color} bold={isHighlighted}> {value}{unit || ""}</Text>
119
+ </Box>
120
+ );
121
+ });
122
+
123
+ interface FitnessAnimatorProps {
124
+ value: number;
125
+ previousValue?: number;
126
+ }
127
+
128
+ export const FitnessAnimator = memo(function FitnessAnimator({ value, previousValue }: FitnessAnimatorProps) {
129
+ const { frame } = useAnimation({ interval: 150, loop: true, maxFps: 12 });
130
+ const diff = previousValue !== undefined ? value - previousValue : 0;
131
+ const isImproving = diff > 0;
132
+ const isDeclining = diff < 0;
133
+
134
+ let color = tuiColors.success;
135
+ if (value >= 0.9) color = tuiColors.success;
136
+ else if (value >= 0.7) color = tuiColors.warning;
137
+ else color = tuiColors.error;
138
+
139
+ const frames = ["●", "◐", "●", "◐"];
140
+ const animFrame = (isImproving || isDeclining) ? frames[frame % frames.length] : "●";
141
+
142
+ const statusLabel = value >= 0.9 ? "OPTIMAL" : value >= 0.7 ? "GOOD" : "IMPROVING";
143
+
144
+ return (
145
+ <Box flexDirection="row">
146
+ <Text color={tuiColors.textTertiary}>Fitness:</Text>
147
+ <Text color={color} bold> {value.toFixed(2)}</Text>
148
+ <Text color={tuiColors.textTertiary}> [{statusLabel}]</Text>
149
+ {isImproving && <Text color={tuiColors.success}> ↑</Text>}
150
+ {isDeclining && <Text color={tuiColors.error}> ↓</Text>}
151
+ </Box>
152
+ );
153
+ });
@@ -0,0 +1,119 @@
1
+ import React, { useState, useEffect, memo, useRef } from "react";
2
+ import { Box, Text } from "ink";
3
+ import { tuiColors } from "../../styles/index.js";
4
+ import { Spinner } from "./Spinner.js";
5
+
6
+ interface TypingEffectProps {
7
+ text: string;
8
+ speed?: number;
9
+ color?: string;
10
+ showCursor?: boolean;
11
+ cursorChar?: string;
12
+ onComplete?: () => void;
13
+ isAnimating?: boolean;
14
+ prefix?: string;
15
+ }
16
+
17
+ export const TypingEffect = memo(function TypingEffect({
18
+ text,
19
+ speed = 30,
20
+ color = tuiColors.textPrimary,
21
+ showCursor = true,
22
+ cursorChar = "█",
23
+ onComplete,
24
+ isAnimating = true,
25
+ prefix,
26
+ }: TypingEffectProps) {
27
+ const [displayedChars, setDisplayedChars] = useState(0);
28
+ const [isComplete, setIsComplete] = useState(false);
29
+ const timeoutRef = useRef<NodeJS.Timeout | null>(null);
30
+ const onCompleteRef = useRef(onComplete);
31
+ onCompleteRef.current = onComplete;
32
+
33
+ useEffect(() => {
34
+ if (!isAnimating) {
35
+ setDisplayedChars(text.length);
36
+ setIsComplete(true);
37
+ return;
38
+ }
39
+
40
+ if (displayedChars >= text.length) {
41
+ if (!isComplete) {
42
+ setIsComplete(true);
43
+ onCompleteRef.current?.();
44
+ }
45
+ return;
46
+ }
47
+
48
+ timeoutRef.current = setTimeout(() => {
49
+ setDisplayedChars((prev) => prev + 1);
50
+ }, speed);
51
+
52
+ return () => {
53
+ if (timeoutRef.current) clearTimeout(timeoutRef.current);
54
+ };
55
+ }, [displayedChars, text.length, speed, isComplete, isAnimating]);
56
+
57
+ const displayedText = text.slice(0, displayedChars);
58
+
59
+ return (
60
+ <Box flexDirection="row">
61
+ {prefix && <Text color={tuiColors.textTertiary}>{prefix}</Text>}
62
+ <Text color={color}>{displayedText}</Text>
63
+ {showCursor && !isComplete && <Text color={tuiColors.primary}>{cursorChar}</Text>}
64
+ </Box>
65
+ );
66
+ });
67
+
68
+ interface TypewriterMessageProps {
69
+ text: string;
70
+ speed?: number;
71
+ color?: string;
72
+ isComplete?: boolean;
73
+ }
74
+
75
+ export const TypewriterMessage = memo(function TypewriterMessage({
76
+ text,
77
+ speed = 20,
78
+ color = tuiColors.textPrimary,
79
+ isComplete
80
+ }: TypewriterMessageProps) {
81
+ const [displayedChars, setDisplayedChars] = useState(0);
82
+ const timeoutRef = useRef<NodeJS.Timeout | null>(null);
83
+
84
+ useEffect(() => {
85
+ if (isComplete) {
86
+ setDisplayedChars(text.length);
87
+ return;
88
+ }
89
+
90
+ if (displayedChars >= text.length) return;
91
+
92
+ timeoutRef.current = setTimeout(() => {
93
+ setDisplayedChars((prev) => prev + 1);
94
+ }, speed);
95
+
96
+ return () => {
97
+ if (timeoutRef.current) clearTimeout(timeoutRef.current);
98
+ };
99
+ }, [displayedChars, text.length, speed, isComplete]);
100
+
101
+ return <Text color={color}>{text.slice(0, displayedChars)}</Text>;
102
+ });
103
+
104
+ interface ProcessingIndicatorProps {
105
+ text?: string;
106
+ color?: string;
107
+ }
108
+
109
+ export const ProcessingIndicator = memo(function ProcessingIndicator({
110
+ text = "Processing",
111
+ color = tuiColors.warning
112
+ }: ProcessingIndicatorProps) {
113
+ return (
114
+ <Box flexDirection="row">
115
+ <Spinner type="dots" color={color} />
116
+ <Text color={color}> {text}...</Text>
117
+ </Box>
118
+ );
119
+ });
@@ -0,0 +1,16 @@
1
+ export { Spinner, useSpinnerFrame, spinnerTypes } from "./Spinner.js";
2
+ export type { SpinnerType } from "./Spinner.js";
3
+
4
+ export { Pulse, StatusPulse, usePulseFrame, usePulseIntensity } from "./Pulse.js";
5
+
6
+ export { TypingEffect, TypewriterMessage, ProcessingIndicator } from "./TypingEffect.js";
7
+
8
+ export { StatusAnimator, MetricPulse, FitnessAnimator } from "./StatusAnimator.js";
9
+ export type { TransitionStatus } from "./StatusAnimator.js";
10
+
11
+ export {
12
+ AnimatedProgressBar,
13
+ ProgressWithLabel,
14
+ SegmentedProgress,
15
+ WorkflowProgress
16
+ } from "./ProgressBar.js";
@@ -0,0 +1,290 @@
1
+ import { useState, useEffect, useCallback, useRef } from "react";
2
+
3
+ export interface AnimationOptions {
4
+ interval?: number;
5
+ loop?: boolean;
6
+ autoStart?: boolean;
7
+ totalFrames?: number;
8
+ maxFps?: number;
9
+ pauseOnHidden?: boolean;
10
+ }
11
+
12
+ export interface AnimationState {
13
+ frame: number;
14
+ tick: number;
15
+ isAnimating: boolean;
16
+ progress: number;
17
+ start: () => void;
18
+ stop: () => void;
19
+ reset: () => void;
20
+ toggle: () => void;
21
+ }
22
+
23
+ const DEFAULT_FPS_LIMIT = 24;
24
+ const FRAME_SKIP_THRESHOLD = 2;
25
+
26
+ export function useAnimation(options: AnimationOptions = {}): AnimationState {
27
+ const {
28
+ interval = 100,
29
+ loop = true,
30
+ autoStart = true,
31
+ totalFrames = 100,
32
+ maxFps = DEFAULT_FPS_LIMIT,
33
+ pauseOnHidden = true,
34
+ } = options;
35
+
36
+ const [frame, setFrame] = useState(0);
37
+ const [isAnimating, setIsAnimating] = useState(autoStart);
38
+ const intervalRef = useRef<NodeJS.Timeout | null>(null);
39
+ const lastFrameTimeRef = useRef<number>(0);
40
+ const frameCountRef = useRef<number>(0);
41
+ const isHiddenRef = useRef<boolean>(false);
42
+
43
+ useEffect(() => {
44
+ if (!pauseOnHidden || typeof document === "undefined") return;
45
+
46
+ const handleVisibility = () => {
47
+ isHiddenRef.current = document.hidden;
48
+ };
49
+
50
+ document.addEventListener("visibilitychange", handleVisibility);
51
+ return () => document.removeEventListener("visibilitychange", handleVisibility);
52
+ }, [pauseOnHidden]);
53
+
54
+ const start = useCallback(() => {
55
+ setIsAnimating(true);
56
+ }, []);
57
+
58
+ const stop = useCallback(() => {
59
+ setIsAnimating(false);
60
+ }, []);
61
+
62
+ const reset = useCallback(() => {
63
+ setFrame(0);
64
+ frameCountRef.current = 0;
65
+ lastFrameTimeRef.current = 0;
66
+ }, []);
67
+
68
+ const toggle = useCallback(() => {
69
+ setIsAnimating((prev) => !prev);
70
+ }, []);
71
+
72
+ useEffect(() => {
73
+ if (!isAnimating) {
74
+ if (intervalRef.current) {
75
+ clearInterval(intervalRef.current);
76
+ intervalRef.current = null;
77
+ }
78
+ return;
79
+ }
80
+
81
+ const minFrameTime = 1000 / maxFps;
82
+
83
+ intervalRef.current = setInterval(() => {
84
+ if (pauseOnHidden && isHiddenRef.current) return;
85
+
86
+ const now = performance.now();
87
+ const elapsed = now - lastFrameTimeRef.current;
88
+
89
+ if (elapsed < minFrameTime) return;
90
+
91
+ const framesToSkip = Math.floor(elapsed / interval) - 1;
92
+ const shouldSkipFrame = framesToSkip > FRAME_SKIP_THRESHOLD;
93
+
94
+ if (shouldSkipFrame) {
95
+ frameCountRef.current += framesToSkip;
96
+ }
97
+
98
+ lastFrameTimeRef.current = now;
99
+ frameCountRef.current++;
100
+
101
+ setFrame((prev) => {
102
+ if (loop) {
103
+ return prev + 1;
104
+ }
105
+ return prev >= totalFrames - 1 ? prev : prev + 1;
106
+ });
107
+ }, interval);
108
+
109
+ return () => {
110
+ if (intervalRef.current) {
111
+ clearInterval(intervalRef.current);
112
+ intervalRef.current = null;
113
+ }
114
+ };
115
+ }, [isAnimating, interval, loop, totalFrames, maxFps, pauseOnHidden]);
116
+
117
+ const progress = totalFrames > 0 ? (frame % totalFrames) / totalFrames : 0;
118
+
119
+ return {
120
+ frame,
121
+ tick: frame,
122
+ isAnimating,
123
+ progress,
124
+ start,
125
+ stop,
126
+ reset,
127
+ toggle,
128
+ };
129
+ }
130
+
131
+ export function usePulse(interval: number = 2000): { intensity: number; frame: number } {
132
+ const { frame } = useAnimation({ interval: 100, loop: true, maxFps: 15 });
133
+ const intensity = 0.5 + Math.sin((frame * 100 / interval) * Math.PI * 2) * 0.5;
134
+ return { intensity, frame };
135
+ }
136
+
137
+ export function useTypewriter(
138
+ text: string,
139
+ speed: number = 50,
140
+ startDelay: number = 0
141
+ ): { displayedText: string; isComplete: boolean; restart: () => void } {
142
+ const [displayedChars, setDisplayedChars] = useState(0);
143
+ const [isStarted, setIsStarted] = useState(false);
144
+ const [isComplete, setIsComplete] = useState(false);
145
+ const timeoutRef = useRef<NodeJS.Timeout | null>(null);
146
+
147
+ const restart = useCallback(() => {
148
+ if (timeoutRef.current) clearTimeout(timeoutRef.current);
149
+ setDisplayedChars(0);
150
+ setIsStarted(false);
151
+ setIsComplete(false);
152
+ }, []);
153
+
154
+ useEffect(() => {
155
+ restart();
156
+ }, [text, restart]);
157
+
158
+ useEffect(() => {
159
+ if (startDelay > 0 && !isStarted) {
160
+ const timeout = setTimeout(() => setIsStarted(true), startDelay);
161
+ return () => clearTimeout(timeout);
162
+ } else if (startDelay === 0) {
163
+ setIsStarted(true);
164
+ }
165
+ }, [startDelay, isStarted]);
166
+
167
+ useEffect(() => {
168
+ if (!isStarted || isComplete) return;
169
+
170
+ if (displayedChars >= text.length) {
171
+ setIsComplete(true);
172
+ return;
173
+ }
174
+
175
+ timeoutRef.current = setTimeout(() => {
176
+ setDisplayedChars((prev) => prev + 1);
177
+ }, speed);
178
+
179
+ return () => {
180
+ if (timeoutRef.current) clearTimeout(timeoutRef.current);
181
+ };
182
+ }, [isStarted, displayedChars, text.length, speed, isComplete]);
183
+
184
+ return {
185
+ displayedText: text.slice(0, displayedChars),
186
+ isComplete,
187
+ restart,
188
+ };
189
+ }
190
+
191
+ export function useCountdown(
192
+ initialSeconds: number,
193
+ options: { autoStart?: boolean; onComplete?: () => void } = {}
194
+ ): { seconds: number; isRunning: boolean; start: () => void; pause: () => void; reset: () => void } {
195
+ const { autoStart = false, onComplete } = options;
196
+ const [seconds, setSeconds] = useState(initialSeconds);
197
+ const [isRunning, setIsRunning] = useState(autoStart);
198
+ const onCompleteRef = useRef(onComplete);
199
+ const intervalRef = useRef<NodeJS.Timeout | null>(null);
200
+ onCompleteRef.current = onComplete;
201
+
202
+ const start = useCallback(() => setIsRunning(true), []);
203
+ const pause = useCallback(() => setIsRunning(false), []);
204
+ const reset = useCallback(() => {
205
+ setSeconds(initialSeconds);
206
+ setIsRunning(false);
207
+ }, [initialSeconds]);
208
+
209
+ useEffect(() => {
210
+ if (!isRunning || seconds <= 0) {
211
+ if (seconds <= 0 && isRunning) {
212
+ setIsRunning(false);
213
+ onCompleteRef.current?.();
214
+ }
215
+ return;
216
+ }
217
+
218
+ intervalRef.current = setInterval(() => {
219
+ setSeconds((prev) => prev - 1);
220
+ }, 1000);
221
+
222
+ return () => {
223
+ if (intervalRef.current) clearInterval(intervalRef.current);
224
+ };
225
+ }, [isRunning, seconds]);
226
+
227
+ return { seconds, isRunning, start, pause, reset };
228
+ }
229
+
230
+ export function useFps(targetFps: number = 24): number {
231
+ const [frame, setFrame] = useState(0);
232
+ const frameRef = useRef(0);
233
+ const lastTimeRef = useRef(performance.now());
234
+ const rafIdRef = useRef<number | null>(null);
235
+
236
+ useEffect(() => {
237
+ const interval = 1000 / targetFps;
238
+
239
+ const tick = () => {
240
+ const now = performance.now();
241
+ const delta = now - lastTimeRef.current;
242
+
243
+ if (delta >= interval) {
244
+ lastTimeRef.current = now - (delta % interval);
245
+ frameRef.current++;
246
+ setFrame(frameRef.current);
247
+ }
248
+
249
+ rafIdRef.current = requestAnimationFrame(tick);
250
+ };
251
+
252
+ rafIdRef.current = requestAnimationFrame(tick);
253
+ return () => {
254
+ if (rafIdRef.current) cancelAnimationFrame(rafIdRef.current);
255
+ };
256
+ }, [targetFps]);
257
+
258
+ return frame;
259
+ }
260
+
261
+ export function useDebouncedCallback<T extends (...args: unknown[]) => void>(
262
+ callback: T,
263
+ delay: number
264
+ ): T {
265
+ const timeoutRef = useRef<NodeJS.Timeout | null>(null);
266
+ const callbackRef = useRef(callback);
267
+ callbackRef.current = callback;
268
+
269
+ return useCallback(((...args: Parameters<T>) => {
270
+ if (timeoutRef.current) clearTimeout(timeoutRef.current);
271
+ timeoutRef.current = setTimeout(() => callbackRef.current(...args), delay);
272
+ }) as T, [delay]);
273
+ }
274
+
275
+ export function useThrottledCallback<T extends (...args: unknown[]) => void>(
276
+ callback: T,
277
+ delay: number
278
+ ): T {
279
+ const lastCallRef = useRef<number>(0);
280
+ const callbackRef = useRef(callback);
281
+ callbackRef.current = callback;
282
+
283
+ return useCallback(((...args: Parameters<T>) => {
284
+ const now = performance.now();
285
+ if (now - lastCallRef.current >= delay) {
286
+ lastCallRef.current = now;
287
+ callbackRef.current(...args);
288
+ }
289
+ }) as T, [delay]);
290
+ }