@tokentop/ttop 0.2.2 → 0.3.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 (158) hide show
  1. package/README.md +2 -5
  2. package/package.json +8 -5
  3. package/src/agents/aggregator.ts +39 -19
  4. package/src/agents/costing.ts +11 -9
  5. package/src/agents/index.ts +7 -9
  6. package/src/agents/types.ts +2 -2
  7. package/src/cli.ts +28 -23
  8. package/src/config/schema.test.ts +42 -40
  9. package/src/config/schema.ts +26 -26
  10. package/src/demo/simulator.ts +161 -122
  11. package/src/plugins/agents/index.ts +2 -2
  12. package/src/plugins/auth-sources.ts +42 -38
  13. package/src/plugins/lifecycle.ts +32 -32
  14. package/src/plugins/loader.test.ts +49 -49
  15. package/src/plugins/loader.ts +67 -63
  16. package/src/plugins/notification-bus.ts +21 -16
  17. package/src/plugins/notifications/index.ts +2 -2
  18. package/src/plugins/notifications/terminal-bell.ts +29 -23
  19. package/src/plugins/notifications/visual-flash.ts +21 -19
  20. package/src/plugins/npm-installer.ts +23 -25
  21. package/src/plugins/plugin-context-factory.ts +10 -10
  22. package/src/plugins/plugin-host.ts +12 -5
  23. package/src/plugins/providers/anthropic.ts +64 -57
  24. package/src/plugins/providers/antigravity.ts +81 -69
  25. package/src/plugins/providers/codex.ts +42 -42
  26. package/src/plugins/providers/gemini.ts +106 -87
  27. package/src/plugins/providers/github-copilot.ts +49 -45
  28. package/src/plugins/providers/index.ts +10 -12
  29. package/src/plugins/providers/minimax.ts +50 -44
  30. package/src/plugins/providers/openai-api.ts +82 -62
  31. package/src/plugins/providers/opencode-zen.ts +46 -39
  32. package/src/plugins/providers/perplexity.ts +55 -46
  33. package/src/plugins/providers/zai.ts +66 -57
  34. package/src/plugins/registry.ts +47 -43
  35. package/src/plugins/sandbox-guard.test.ts +45 -48
  36. package/src/plugins/sandbox-guard.ts +20 -25
  37. package/src/plugins/sandbox.ts +26 -48
  38. package/src/plugins/themes/catppuccin-latte.ts +29 -29
  39. package/src/plugins/themes/catppuccin-mocha.ts +29 -29
  40. package/src/plugins/themes/claude-code.ts +29 -29
  41. package/src/plugins/themes/dracula.ts +29 -29
  42. package/src/plugins/themes/github-light.ts +29 -29
  43. package/src/plugins/themes/gruvbox-dark.ts +29 -29
  44. package/src/plugins/themes/gruvbox-light.ts +29 -29
  45. package/src/plugins/themes/index.ts +15 -15
  46. package/src/plugins/themes/kanagawa.ts +29 -29
  47. package/src/plugins/themes/nord.ts +29 -29
  48. package/src/plugins/themes/one-dark.ts +29 -29
  49. package/src/plugins/themes/opencode.ts +31 -31
  50. package/src/plugins/themes/rose-pine-dawn.ts +29 -29
  51. package/src/plugins/themes/rose-pine.ts +29 -29
  52. package/src/plugins/themes/solarized-light.ts +29 -29
  53. package/src/plugins/themes/tokyo-night.ts +29 -29
  54. package/src/plugins/types/agent.ts +5 -5
  55. package/src/plugins/types/base.ts +35 -24
  56. package/src/plugins/types/index.ts +9 -9
  57. package/src/plugins/types/notification.ts +12 -12
  58. package/src/plugins/types/provider.ts +12 -8
  59. package/src/plugins/types/theme.ts +31 -23
  60. package/src/plugins/update-checker.ts +6 -6
  61. package/src/pricing/estimator.test.ts +39 -44
  62. package/src/pricing/estimator.ts +7 -13
  63. package/src/pricing/fallback.test.ts +30 -34
  64. package/src/pricing/fallback.ts +54 -27
  65. package/src/pricing/index.ts +18 -12
  66. package/src/pricing/models-dev.ts +6 -6
  67. package/src/storage/database.ts +56 -46
  68. package/src/storage/db.ts +12 -12
  69. package/src/storage/index.ts +44 -45
  70. package/src/storage/migrations/index.ts +2 -2
  71. package/src/storage/paths.ts +13 -13
  72. package/src/storage/repos/agentSessions.ts +33 -23
  73. package/src/storage/repos/providerSnapshots.ts +5 -5
  74. package/src/storage/repos/usageEvents.ts +40 -28
  75. package/src/storage/types.ts +5 -5
  76. package/src/tui/App.tsx +180 -137
  77. package/src/tui/components/CommandPalette.tsx +46 -34
  78. package/src/tui/components/DebugConsole.tsx +39 -33
  79. package/src/tui/components/DebugPanel.tsx +295 -177
  80. package/src/tui/components/FooterHints.tsx +2 -2
  81. package/src/tui/components/GhostProviderCard.tsx +37 -35
  82. package/src/tui/components/Header.tsx +68 -35
  83. package/src/tui/components/HelpOverlay.tsx +99 -29
  84. package/src/tui/components/InlineGauge.tsx +10 -7
  85. package/src/tui/components/InlineSparkline.tsx +17 -11
  86. package/src/tui/components/KpiStrip.tsx +128 -98
  87. package/src/tui/components/LimitGauge.tsx +96 -59
  88. package/src/tui/components/ModalBackdrop.tsx +4 -4
  89. package/src/tui/components/ProviderAggregateStrip.tsx +69 -38
  90. package/src/tui/components/ProviderCard.tsx +232 -226
  91. package/src/tui/components/ProviderDetailPanel.tsx +133 -58
  92. package/src/tui/components/ProviderLimitsPanel.tsx +126 -89
  93. package/src/tui/components/ProvidersList.tsx +215 -126
  94. package/src/tui/components/SessionDetailsDrawer.tsx +191 -94
  95. package/src/tui/components/SessionsTable.tsx +313 -166
  96. package/src/tui/components/SettingsModal.tsx +231 -214
  97. package/src/tui/components/SidebarBreakdown.tsx +30 -16
  98. package/src/tui/components/Skeleton.tsx +24 -17
  99. package/src/tui/components/SmartSidebar.tsx +360 -258
  100. package/src/tui/components/Sparkline.tsx +64 -52
  101. package/src/tui/components/Spinner.tsx +3 -3
  102. package/src/tui/components/StatusBar.tsx +27 -27
  103. package/src/tui/components/ThemePicker.tsx +67 -66
  104. package/src/tui/components/Toast.tsx +9 -6
  105. package/src/tui/components/UsageGauge.tsx +10 -13
  106. package/src/tui/components/index.ts +5 -5
  107. package/src/tui/contexts/AgentSessionContext.tsx +193 -144
  108. package/src/tui/contexts/ConfigContext.tsx +15 -13
  109. package/src/tui/contexts/DashboardRuntimeContext.tsx +26 -26
  110. package/src/tui/contexts/DemoModeContext.tsx +22 -15
  111. package/src/tui/contexts/DrawerContext.tsx +11 -9
  112. package/src/tui/contexts/InputContext.tsx +2 -2
  113. package/src/tui/contexts/LogContext.tsx +62 -47
  114. package/src/tui/contexts/PluginContext.tsx +232 -183
  115. package/src/tui/contexts/RealTimeActivityContext.tsx +70 -36
  116. package/src/tui/contexts/StorageContext.tsx +151 -117
  117. package/src/tui/contexts/ThemeContext.tsx +21 -16
  118. package/src/tui/contexts/TimeWindowContext.tsx +72 -61
  119. package/src/tui/contexts/ToastContext.tsx +10 -7
  120. package/src/tui/contexts/index.ts +9 -5
  121. package/src/tui/createApp.tsx +8 -12
  122. package/src/tui/debug/captureFrame.ts +25 -28
  123. package/src/tui/debug/snapshot.tsx +179 -162
  124. package/src/tui/driver/assertions.ts +30 -22
  125. package/src/tui/driver/cli.ts +231 -221
  126. package/src/tui/driver/coverage.ts +27 -44
  127. package/src/tui/driver/demo-snapshot.ts +33 -33
  128. package/src/tui/driver/diff.ts +26 -32
  129. package/src/tui/driver/driver.ts +43 -48
  130. package/src/tui/driver/index.ts +36 -40
  131. package/src/tui/driver/recorder.ts +37 -48
  132. package/src/tui/driver/test-workflow.ts +51 -51
  133. package/src/tui/driver/test.ts +25 -25
  134. package/src/tui/hooks/index.ts +24 -20
  135. package/src/tui/hooks/useAnimatedValue.ts +13 -18
  136. package/src/tui/hooks/useDashboardKeyboard.ts +118 -98
  137. package/src/tui/hooks/useDashboardState.ts +26 -24
  138. package/src/tui/hooks/useEmaActivity.ts +82 -74
  139. package/src/tui/hooks/useEntranceAnimation.ts +11 -11
  140. package/src/tui/hooks/useExitAnimation.ts +3 -3
  141. package/src/tui/hooks/usePulse.ts +4 -4
  142. package/src/tui/hooks/useSafeRenderer.ts +5 -5
  143. package/src/tui/hooks/useSessionEnrichedProviders.ts +150 -0
  144. package/src/tui/hooks/useValueFlash.ts +10 -14
  145. package/src/tui/index.tsx +29 -6
  146. package/src/tui/shutdown.ts +19 -0
  147. package/src/tui/utils/providerColor.ts +1 -1
  148. package/src/tui/views/Dashboard.tsx +127 -102
  149. package/src/tui/views/HistoricalTrendsView.tsx +579 -250
  150. package/src/tui/views/ProjectsView.tsx +466 -237
  151. package/src/tui/views/RealTimeDashboard.tsx +150 -111
  152. package/src/tui/views/SettingsView.tsx +222 -191
  153. package/src/tui/views/index.ts +2 -2
  154. package/src/types/opentui-test-utils.d.ts +7 -7
  155. package/src/utils/clipboard.ts +29 -29
  156. package/src/utils/currency.test.ts +53 -53
  157. package/src/utils/currency.ts +35 -32
  158. package/src/version.ts +1 -1
@@ -1,8 +1,8 @@
1
- import { useRef, useImperativeHandle, forwardRef, useEffect } from 'react';
2
- import type { ScrollBoxRenderable } from '@opentui/core';
3
- import { useColors } from '../contexts/ThemeContext.tsx';
4
- import { useLogs, type LogEntry, type LogLevel } from '../contexts/LogContext.tsx';
5
- import { copyToClipboard } from '@/utils/clipboard.ts';
1
+ import type { ScrollBoxRenderable } from "@opentui/core";
2
+ import { forwardRef, useEffect, useImperativeHandle, useRef } from "react";
3
+ import { copyToClipboard } from "@/utils/clipboard.ts";
4
+ import { type LogEntry, type LogLevel, useLogs } from "../contexts/LogContext.tsx";
5
+ import { useColors } from "../contexts/ThemeContext.tsx";
6
6
 
7
7
  interface DebugConsoleProps {
8
8
  height?: number;
@@ -17,7 +17,10 @@ export interface DebugConsoleHandle {
17
17
 
18
18
  const LOG_LEVEL_RANK: Record<LogLevel, number> = { debug: 0, info: 1, warn: 2, error: 3 };
19
19
 
20
- export const DebugConsole = forwardRef<DebugConsoleHandle, DebugConsoleProps>(function DebugConsole({ height = 15, follow = true, minLevel = 'info' }, ref) {
20
+ export const DebugConsole = forwardRef<DebugConsoleHandle, DebugConsoleProps>(function DebugConsole(
21
+ { height = 15, follow = true, minLevel = "info" },
22
+ ref,
23
+ ) {
21
24
  const colors = useColors();
22
25
  const { logs } = useLogs();
23
26
  const scrollboxRef = useRef<ScrollBoxRenderable>(null);
@@ -51,14 +54,14 @@ export const DebugConsole = forwardRef<DebugConsoleHandle, DebugConsoleProps>(fu
51
54
  };
52
55
 
53
56
  const levelLabels: Record<LogLevel, string> = {
54
- debug: 'DBG',
55
- info: 'INF',
56
- warn: 'WRN',
57
- error: 'ERR',
57
+ debug: "DBG",
58
+ info: "INF",
59
+ warn: "WRN",
60
+ error: "ERR",
58
61
  };
59
62
 
60
63
  const minRank = LOG_LEVEL_RANK[minLevel];
61
- const filtered = minRank === 0 ? logs : logs.filter(e => LOG_LEVEL_RANK[e.level] >= minRank);
64
+ const filtered = minRank === 0 ? logs : logs.filter((e) => LOG_LEVEL_RANK[e.level] >= minRank);
62
65
  const visibleLogs = filtered.slice(-50);
63
66
 
64
67
  return (
@@ -69,14 +72,14 @@ export const DebugConsole = forwardRef<DebugConsoleHandle, DebugConsoleProps>(fu
69
72
  borderColor={colors.border}
70
73
  backgroundColor={colors.background}
71
74
  >
72
- <box
73
- flexDirection="row"
74
- justifyContent="space-between"
75
- paddingX={1}
76
- backgroundColor={colors.foreground}
77
- height={1}
78
- flexShrink={0}
79
- >
75
+ <box
76
+ flexDirection="row"
77
+ justifyContent="space-between"
78
+ paddingX={1}
79
+ backgroundColor={colors.foreground}
80
+ height={1}
81
+ flexShrink={0}
82
+ >
80
83
  <text>
81
84
  <span fg={colors.primary}>
82
85
  <strong>Debug Console</strong>
@@ -107,7 +110,13 @@ export const DebugConsole = forwardRef<DebugConsoleHandle, DebugConsoleProps>(fu
107
110
  <text fg={colors.textSubtle}>No logs yet. Actions will appear here.</text>
108
111
  ) : (
109
112
  visibleLogs.map((entry) => (
110
- <LogLine key={entry.id} entry={entry} levelColors={levelColors} levelLabels={levelLabels} colors={colors} />
113
+ <LogLine
114
+ key={entry.id}
115
+ entry={entry}
116
+ levelColors={levelColors}
117
+ levelLabels={levelLabels}
118
+ colors={colors}
119
+ />
111
120
  ))
112
121
  )}
113
122
  </box>
@@ -124,25 +133,22 @@ interface LogLineProps {
124
133
  }
125
134
 
126
135
  function LogLine({ entry, levelColors, levelLabels, colors }: LogLineProps) {
127
- const time = new Date(entry.timestamp).toLocaleTimeString('en-US', {
136
+ const time = new Date(entry.timestamp).toLocaleTimeString("en-US", {
128
137
  hour12: false,
129
- hour: '2-digit',
130
- minute: '2-digit',
131
- second: '2-digit',
138
+ hour: "2-digit",
139
+ minute: "2-digit",
140
+ second: "2-digit",
132
141
  });
133
142
 
134
143
  const levelColor = levelColors[entry.level];
135
144
  const levelLabel = levelLabels[entry.level];
136
145
 
137
- const source = entry.source ? `[${entry.source}]` : '';
138
- const dataStr = entry.data ? ` ${JSON.stringify(entry.data)}` : '';
146
+ const source = entry.source ? `[${entry.source}]` : "";
147
+ const dataStr = entry.data ? ` ${JSON.stringify(entry.data)}` : "";
139
148
 
140
149
  return (
141
150
  <text>
142
- <span fg={colors.textSubtle}>{time}</span>
143
- {' '}
144
- <span fg={levelColor}>{levelLabel}</span>
145
- {' '}
151
+ <span fg={colors.textSubtle}>{time}</span> <span fg={levelColor}>{levelLabel}</span>{" "}
146
152
  {source && <span fg={colors.textMuted}>{source} </span>}
147
153
  <span fg={colors.text}>{entry.message}</span>
148
154
  {dataStr && <span fg={colors.textSubtle}>{dataStr}</span>}
@@ -153,9 +159,9 @@ function LogLine({ entry, levelColors, levelLabels, colors }: LogLineProps) {
153
159
  export async function copyLogsToClipboard(logs: LogEntry[]): Promise<void> {
154
160
  const lines = logs.map((entry) => {
155
161
  const time = new Date(entry.timestamp).toISOString();
156
- const src = entry.source ? `[${entry.source}]` : '';
157
- const dataStr = entry.data ? ` ${JSON.stringify(entry.data)}` : '';
162
+ const src = entry.source ? `[${entry.source}]` : "";
163
+ const dataStr = entry.data ? ` ${JSON.stringify(entry.data)}` : "";
158
164
  return `${time} ${entry.level.toUpperCase().padEnd(5)} ${src} ${entry.message}${dataStr}`;
159
165
  });
160
- await copyToClipboard(lines.join('\n'));
166
+ await copyToClipboard(lines.join("\n"));
161
167
  }