wave-code 1.0.10 → 1.1.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 (248) hide show
  1. package/bin/wave-code.js +8 -2
  2. package/dist/bundle/wave.mjs +3231 -0
  3. package/package.json +24 -25
  4. package/src/cli.tsx +6 -1
  5. package/src/commands/update.ts +2 -7
  6. package/src/components/App.tsx +3 -7
  7. package/src/components/BtwDisplay.tsx +10 -1
  8. package/src/components/ChatInterface.tsx +21 -52
  9. package/src/components/ConfirmationDetails.tsx +144 -37
  10. package/src/components/DiffDisplay.tsx +335 -301
  11. package/src/components/InputBox.tsx +17 -2
  12. package/src/components/LoadingIndicator.tsx +16 -2
  13. package/src/components/MessageBlockItem.tsx +2 -4
  14. package/src/components/MessageList.tsx +75 -14
  15. package/src/components/ReasoningDisplay.tsx +2 -4
  16. package/src/components/SessionSelector.tsx +82 -11
  17. package/src/components/SkillsManager.tsx +312 -0
  18. package/src/components/StatusCommand.tsx +2 -9
  19. package/src/components/ToolDisplay.tsx +2 -4
  20. package/src/constants/commands.ts +6 -0
  21. package/src/contexts/useChat.tsx +245 -301
  22. package/src/daemon/commands.ts +57 -27
  23. package/src/daemon/jsonRpcClient.ts +1 -1
  24. package/src/daemon/socketClient.ts +2 -2
  25. package/src/hooks/useInputManager.ts +7 -1
  26. package/src/index.ts +57 -10
  27. package/src/managers/inputHandlers.ts +2 -0
  28. package/src/managers/inputReducer.ts +195 -104
  29. package/src/print-cli.ts +25 -17
  30. package/src/reducers/selectorReducer.ts +10 -0
  31. package/src/reducers/skillsManagerReducer.ts +91 -0
  32. package/src/session-selector-cli.tsx +269 -28
  33. package/src/stdio/agentBridge.ts +30 -21
  34. package/src/stdio/daemonServer.ts +3 -1
  35. package/src/stdio/protocol.ts +2 -0
  36. package/src/utils/clipboard.ts +21 -0
  37. package/src/utils/highlightUtils.ts +46 -1
  38. package/src/utils/readPackageJson.ts +29 -0
  39. package/src/utils/streamingText.ts +11 -0
  40. package/src/utils/worktree.ts +191 -43
  41. package/dist/cli.d.ts +0 -6
  42. package/dist/cli.js +0 -53
  43. package/dist/commands/plugin/disable.d.ts +0 -5
  44. package/dist/commands/plugin/disable.js +0 -15
  45. package/dist/commands/plugin/enable.d.ts +0 -5
  46. package/dist/commands/plugin/enable.js +0 -15
  47. package/dist/commands/plugin/install.d.ts +0 -5
  48. package/dist/commands/plugin/install.js +0 -21
  49. package/dist/commands/plugin/list.d.ts +0 -1
  50. package/dist/commands/plugin/list.js +0 -31
  51. package/dist/commands/plugin/marketplace.d.ts +0 -10
  52. package/dist/commands/plugin/marketplace.js +0 -90
  53. package/dist/commands/plugin/uninstall.d.ts +0 -3
  54. package/dist/commands/plugin/uninstall.js +0 -16
  55. package/dist/commands/plugin/update.d.ts +0 -3
  56. package/dist/commands/plugin/update.js +0 -15
  57. package/dist/commands/update.d.ts +0 -1
  58. package/dist/commands/update.js +0 -97
  59. package/dist/components/AgentsManager.d.ts +0 -7
  60. package/dist/components/AgentsManager.js +0 -109
  61. package/dist/components/App.d.ts +0 -9
  62. package/dist/components/App.js +0 -76
  63. package/dist/components/BackgroundTaskManager.d.ts +0 -5
  64. package/dist/components/BackgroundTaskManager.js +0 -99
  65. package/dist/components/BangDisplay.d.ts +0 -8
  66. package/dist/components/BangDisplay.js +0 -17
  67. package/dist/components/BtwDisplay.d.ts +0 -7
  68. package/dist/components/BtwDisplay.js +0 -19
  69. package/dist/components/ChatInterface.d.ts +0 -2
  70. package/dist/components/ChatInterface.js +0 -61
  71. package/dist/components/CommandSelector.d.ts +0 -10
  72. package/dist/components/CommandSelector.js +0 -66
  73. package/dist/components/CompactDisplay.d.ts +0 -8
  74. package/dist/components/CompactDisplay.js +0 -13
  75. package/dist/components/ConfirmationDetails.d.ts +0 -9
  76. package/dist/components/ConfirmationDetails.js +0 -45
  77. package/dist/components/ConfirmationSelector.d.ts +0 -13
  78. package/dist/components/ConfirmationSelector.js +0 -127
  79. package/dist/components/DiffDisplay.d.ts +0 -8
  80. package/dist/components/DiffDisplay.js +0 -201
  81. package/dist/components/DiscoverView.d.ts +0 -2
  82. package/dist/components/DiscoverView.js +0 -37
  83. package/dist/components/FileSelector.d.ts +0 -11
  84. package/dist/components/FileSelector.js +0 -50
  85. package/dist/components/HelpView.d.ts +0 -7
  86. package/dist/components/HelpView.js +0 -74
  87. package/dist/components/HistorySearch.d.ts +0 -8
  88. package/dist/components/HistorySearch.js +0 -66
  89. package/dist/components/InputBox.d.ts +0 -24
  90. package/dist/components/InputBox.js +0 -149
  91. package/dist/components/InstalledView.d.ts +0 -2
  92. package/dist/components/InstalledView.js +0 -45
  93. package/dist/components/LoadingIndicator.d.ts +0 -10
  94. package/dist/components/LoadingIndicator.js +0 -6
  95. package/dist/components/LoginCommand.d.ts +0 -5
  96. package/dist/components/LoginCommand.js +0 -153
  97. package/dist/components/Markdown.d.ts +0 -5
  98. package/dist/components/Markdown.js +0 -127
  99. package/dist/components/MarketplaceAddForm.d.ts +0 -2
  100. package/dist/components/MarketplaceAddForm.js +0 -55
  101. package/dist/components/MarketplaceDetail.d.ts +0 -2
  102. package/dist/components/MarketplaceDetail.js +0 -74
  103. package/dist/components/MarketplaceList.d.ts +0 -8
  104. package/dist/components/MarketplaceList.js +0 -17
  105. package/dist/components/MarketplaceView.d.ts +0 -2
  106. package/dist/components/MarketplaceView.js +0 -41
  107. package/dist/components/McpManager.d.ts +0 -9
  108. package/dist/components/McpManager.js +0 -88
  109. package/dist/components/MessageBlockItem.d.ts +0 -8
  110. package/dist/components/MessageBlockItem.js +0 -15
  111. package/dist/components/MessageList.d.ts +0 -10
  112. package/dist/components/MessageList.js +0 -80
  113. package/dist/components/ModelSelector.d.ts +0 -8
  114. package/dist/components/ModelSelector.js +0 -45
  115. package/dist/components/Notifications.d.ts +0 -7
  116. package/dist/components/Notifications.js +0 -9
  117. package/dist/components/PlanDisplay.d.ts +0 -7
  118. package/dist/components/PlanDisplay.js +0 -6
  119. package/dist/components/PluginDetail.d.ts +0 -2
  120. package/dist/components/PluginDetail.js +0 -87
  121. package/dist/components/PluginList.d.ts +0 -13
  122. package/dist/components/PluginList.js +0 -15
  123. package/dist/components/PluginManagerShell.d.ts +0 -6
  124. package/dist/components/PluginManagerShell.js +0 -92
  125. package/dist/components/PluginManagerTypes.d.ts +0 -35
  126. package/dist/components/PluginManagerTypes.js +0 -1
  127. package/dist/components/QueuedMessageList.d.ts +0 -2
  128. package/dist/components/QueuedMessageList.js +0 -18
  129. package/dist/components/ReasoningDisplay.d.ts +0 -8
  130. package/dist/components/ReasoningDisplay.js +0 -13
  131. package/dist/components/RewindCommand.d.ts +0 -12
  132. package/dist/components/RewindCommand.js +0 -78
  133. package/dist/components/SessionSelector.d.ts +0 -12
  134. package/dist/components/SessionSelector.js +0 -47
  135. package/dist/components/StatusCommand.d.ts +0 -5
  136. package/dist/components/StatusCommand.js +0 -28
  137. package/dist/components/StatusLine.d.ts +0 -6
  138. package/dist/components/StatusLine.js +0 -9
  139. package/dist/components/TaskList.d.ts +0 -5
  140. package/dist/components/TaskList.js +0 -197
  141. package/dist/components/TaskNotificationMessage.d.ts +0 -5
  142. package/dist/components/TaskNotificationMessage.js +0 -12
  143. package/dist/components/ToolDisplay.d.ts +0 -9
  144. package/dist/components/ToolDisplay.js +0 -55
  145. package/dist/components/WorkflowManager.d.ts +0 -5
  146. package/dist/components/WorkflowManager.js +0 -102
  147. package/dist/components/WorktreeExitPrompt.d.ts +0 -12
  148. package/dist/components/WorktreeExitPrompt.js +0 -35
  149. package/dist/constants/commands.d.ts +0 -2
  150. package/dist/constants/commands.js +0 -92
  151. package/dist/contexts/PluginManagerContext.d.ts +0 -3
  152. package/dist/contexts/PluginManagerContext.js +0 -9
  153. package/dist/contexts/useAppConfig.d.ts +0 -10
  154. package/dist/contexts/useAppConfig.js +0 -13
  155. package/dist/contexts/useChat.d.ts +0 -101
  156. package/dist/contexts/useChat.js +0 -993
  157. package/dist/contracts/status.d.ts +0 -7
  158. package/dist/contracts/status.js +0 -1
  159. package/dist/daemon/commands.d.ts +0 -49
  160. package/dist/daemon/commands.js +0 -341
  161. package/dist/daemon/jsonRpcClient.d.ts +0 -38
  162. package/dist/daemon/jsonRpcClient.js +0 -129
  163. package/dist/daemon/socketClient.d.ts +0 -13
  164. package/dist/daemon/socketClient.js +0 -26
  165. package/dist/daemon-cli.d.ts +0 -10
  166. package/dist/daemon-cli.js +0 -15
  167. package/dist/hooks/useInputManager.d.ts +0 -75
  168. package/dist/hooks/useInputManager.js +0 -583
  169. package/dist/hooks/usePluginManager.d.ts +0 -4
  170. package/dist/hooks/usePluginManager.js +0 -265
  171. package/dist/hooks/useTasks.d.ts +0 -1
  172. package/dist/hooks/useTasks.js +0 -5
  173. package/dist/index.d.ts +0 -4
  174. package/dist/index.js +0 -447
  175. package/dist/managers/inputHandlers.d.ts +0 -30
  176. package/dist/managers/inputHandlers.js +0 -625
  177. package/dist/managers/inputReducer.d.ts +0 -271
  178. package/dist/managers/inputReducer.js +0 -1121
  179. package/dist/plugin-manager-cli.d.ts +0 -5
  180. package/dist/plugin-manager-cli.js +0 -12
  181. package/dist/print-cli.d.ts +0 -10
  182. package/dist/print-cli.js +0 -209
  183. package/dist/reducers/agentsManagerReducer.d.ts +0 -26
  184. package/dist/reducers/agentsManagerReducer.js +0 -54
  185. package/dist/reducers/backgroundTaskManagerReducer.d.ts +0 -62
  186. package/dist/reducers/backgroundTaskManagerReducer.js +0 -106
  187. package/dist/reducers/confirmationReducer.d.ts +0 -37
  188. package/dist/reducers/confirmationReducer.js +0 -193
  189. package/dist/reducers/helpSelectorReducer.d.ts +0 -25
  190. package/dist/reducers/helpSelectorReducer.js +0 -52
  191. package/dist/reducers/marketplaceAddFormReducer.d.ts +0 -24
  192. package/dist/reducers/marketplaceAddFormReducer.js +0 -58
  193. package/dist/reducers/mcpManagerReducer.d.ts +0 -37
  194. package/dist/reducers/mcpManagerReducer.js +0 -74
  195. package/dist/reducers/pluginDetailReducer.d.ts +0 -32
  196. package/dist/reducers/pluginDetailReducer.js +0 -70
  197. package/dist/reducers/questionReducer.d.ts +0 -82
  198. package/dist/reducers/questionReducer.js +0 -375
  199. package/dist/reducers/rewindSelectorReducer.d.ts +0 -21
  200. package/dist/reducers/rewindSelectorReducer.js +0 -37
  201. package/dist/reducers/selectorReducer.d.ts +0 -23
  202. package/dist/reducers/selectorReducer.js +0 -42
  203. package/dist/reducers/workflowManagerReducer.d.ts +0 -40
  204. package/dist/reducers/workflowManagerReducer.js +0 -100
  205. package/dist/session-selector-cli.d.ts +0 -3
  206. package/dist/session-selector-cli.js +0 -25
  207. package/dist/stdio/agentBridge.d.ts +0 -139
  208. package/dist/stdio/agentBridge.js +0 -999
  209. package/dist/stdio/daemonServer.d.ts +0 -67
  210. package/dist/stdio/daemonServer.js +0 -191
  211. package/dist/stdio/index.d.ts +0 -5
  212. package/dist/stdio/index.js +0 -5
  213. package/dist/stdio/jsonRpcConnection.d.ts +0 -39
  214. package/dist/stdio/jsonRpcConnection.js +0 -135
  215. package/dist/stdio/protocol.d.ts +0 -41
  216. package/dist/stdio/protocol.js +0 -26
  217. package/dist/stdio/stdioServer.d.ts +0 -36
  218. package/dist/stdio/stdioServer.js +0 -51
  219. package/dist/stdio-cli.d.ts +0 -8
  220. package/dist/stdio-cli.js +0 -15
  221. package/dist/types.d.ts +0 -20
  222. package/dist/types.js +0 -1
  223. package/dist/utils/bracketedPaste.d.ts +0 -39
  224. package/dist/utils/bracketedPaste.js +0 -122
  225. package/dist/utils/clipboard.d.ts +0 -21
  226. package/dist/utils/clipboard.js +0 -347
  227. package/dist/utils/constants.d.ts +0 -16
  228. package/dist/utils/constants.js +0 -18
  229. package/dist/utils/highlightUtils.d.ts +0 -1
  230. package/dist/utils/highlightUtils.js +0 -93
  231. package/dist/utils/inputUtils.d.ts +0 -17
  232. package/dist/utils/inputUtils.js +0 -67
  233. package/dist/utils/logger.d.ts +0 -71
  234. package/dist/utils/logger.js +0 -259
  235. package/dist/utils/markdownTable.d.ts +0 -34
  236. package/dist/utils/markdownTable.js +0 -302
  237. package/dist/utils/rewindCheckpoints.d.ts +0 -8
  238. package/dist/utils/rewindCheckpoints.js +0 -17
  239. package/dist/utils/throttle.d.ts +0 -14
  240. package/dist/utils/throttle.js +0 -55
  241. package/dist/utils/toolParameterTransforms.d.ts +0 -18
  242. package/dist/utils/toolParameterTransforms.js +0 -73
  243. package/dist/utils/usageSummary.d.ts +0 -28
  244. package/dist/utils/usageSummary.js +0 -121
  245. package/dist/utils/version.d.ts +0 -1
  246. package/dist/utils/version.js +0 -4
  247. package/dist/utils/worktree.d.ts +0 -35
  248. package/dist/utils/worktree.js +0 -219
@@ -1,302 +0,0 @@
1
- import stringWidth from "string-width";
2
- import wrapAnsi from "wrap-ansi";
3
- import { stripAnsiColors } from "wave-agent-sdk";
4
- /**
5
- * Accounts for parent indentation (e.g. message prefix) and terminal
6
- * resize races. Without enough margin the table overflows its layout box
7
- * and Ink's clip truncates differently on alternating frames.
8
- */
9
- const SAFETY_MARGIN = 4;
10
- /** Minimum column width to prevent degenerate layouts */
11
- const MIN_COLUMN_WIDTH = 3;
12
- /**
13
- * Maximum number of lines per row before switching to vertical format.
14
- * When wrapping would make rows taller than this, vertical (key-value)
15
- * format provides better readability.
16
- */
17
- const MAX_ROW_LINES = 4;
18
- /** ANSI escape codes for text formatting */
19
- const ANSI_BOLD_START = "\x1b[1m";
20
- const ANSI_BOLD_END = "\x1b[22m";
21
- /**
22
- * Wrap text to fit within a given width, returning array of lines.
23
- * ANSI-aware: preserves styling across line breaks.
24
- *
25
- * @param hard - If true, break words that exceed width (needed when columns
26
- * are narrower than the longest word). Default false.
27
- */
28
- export function wrapText(text, width, options) {
29
- if (width <= 0)
30
- return [text];
31
- // Strip trailing whitespace/newlines before wrapping, otherwise extra
32
- // blank lines would appear in table cells.
33
- const trimmedText = text.trimEnd();
34
- const wrapped = wrapAnsi(trimmedText, width, {
35
- hard: options?.hard ?? false,
36
- trim: false,
37
- wordWrap: true,
38
- });
39
- // Filter out empty lines that result from trailing newlines or
40
- // multiple consecutive newlines in the source content.
41
- const lines = wrapped.split("\n").filter((line) => line.length > 0);
42
- // Ensure we always return at least one line (empty string for empty cells)
43
- return lines.length > 0 ? lines : [""];
44
- }
45
- /**
46
- * Pad `content` to `targetWidth` according to alignment. `displayWidth` is the
47
- * visible width of `content` (caller computes this, e.g. via stringWidth on
48
- * ANSI-stripped text, so ANSI codes in `content` don't affect padding).
49
- */
50
- export function padAligned(content, displayWidth, targetWidth, align) {
51
- const padding = Math.max(0, targetWidth - displayWidth);
52
- if (align === "center") {
53
- const leftPad = Math.floor(padding / 2);
54
- return " ".repeat(leftPad) + content + " ".repeat(padding - leftPad);
55
- }
56
- if (align === "right") {
57
- return " ".repeat(padding) + content;
58
- }
59
- return content + " ".repeat(padding);
60
- }
61
- /**
62
- * Render a markdown table to a box-drawing ANSI string for the terminal.
63
- * Handles terminal width by:
64
- * 1. Calculating minimum column widths based on longest word
65
- * 2. Distributing available space proportionally
66
- * 3. Wrapping text within cells (no truncation)
67
- * 4. Falling back to a vertical key-value format when rows would be too
68
- * tall or the table still overflows the terminal width
69
- *
70
- * @param token - marked table token
71
- * @param columns - terminal width
72
- * @param formatInline - formats inline tokens to an ANSI string (the caller
73
- * binds its marked parser so this module stays
74
- * parser-agnostic and directly testable)
75
- */
76
- export function renderMarkdownTable(token, columns, formatInline) {
77
- // Format cell content to ANSI string
78
- function formatCell(tokens) {
79
- return tokens && tokens.length > 0 ? formatInline(tokens) : "";
80
- }
81
- // Get plain text (stripped of ANSI codes)
82
- function getPlainText(tokens) {
83
- return stripAnsiColors(formatCell(tokens));
84
- }
85
- // Get the longest word width in a cell (minimum width to avoid breaking words)
86
- function getMinWidth(tokens) {
87
- const text = getPlainText(tokens);
88
- const words = text.split(/\s+/).filter((w) => w.length > 0);
89
- if (words.length === 0)
90
- return MIN_COLUMN_WIDTH;
91
- return Math.max(...words.map((w) => stringWidth(w)), MIN_COLUMN_WIDTH);
92
- }
93
- // Get ideal width (full content without wrapping)
94
- function getIdealWidth(tokens) {
95
- return Math.max(stringWidth(getPlainText(tokens)), MIN_COLUMN_WIDTH);
96
- }
97
- // Step 1: Get minimum (longest word) and ideal (full content) widths
98
- const minWidths = token.header.map((header, colIndex) => {
99
- let maxMinWidth = getMinWidth(header.tokens);
100
- for (const row of token.rows) {
101
- maxMinWidth = Math.max(maxMinWidth, getMinWidth(row[colIndex]?.tokens));
102
- }
103
- return maxMinWidth;
104
- });
105
- const idealWidths = token.header.map((header, colIndex) => {
106
- let maxIdeal = getIdealWidth(header.tokens);
107
- for (const row of token.rows) {
108
- maxIdeal = Math.max(maxIdeal, getIdealWidth(row[colIndex]?.tokens));
109
- }
110
- return maxIdeal;
111
- });
112
- // Step 2: Calculate available space
113
- // Border overhead: │ content │ content │ = 1 + (width + 3) per column
114
- const numCols = token.header.length;
115
- const borderOverhead = 1 + numCols * 3; // │ + (2 padding + 1 border) per col
116
- // Account for SAFETY_MARGIN to avoid triggering the fallback safety check
117
- const availableWidth = Math.max(columns - borderOverhead - SAFETY_MARGIN, numCols * MIN_COLUMN_WIDTH);
118
- // Step 3: Calculate column widths that fit available space
119
- const totalMin = minWidths.reduce((sum, w) => sum + w, 0);
120
- const totalIdeal = idealWidths.reduce((sum, w) => sum + w, 0);
121
- // Track whether columns are narrower than longest words (needs hard wrap)
122
- let needsHardWrap = false;
123
- let columnWidths;
124
- if (totalIdeal <= availableWidth) {
125
- // Everything fits - use ideal widths
126
- columnWidths = idealWidths;
127
- }
128
- else if (totalMin <= availableWidth) {
129
- // Need to shrink - give each column its min, distribute remaining space
130
- const extraSpace = availableWidth - totalMin;
131
- const overflows = idealWidths.map((ideal, i) => ideal - minWidths[i]);
132
- const totalOverflow = overflows.reduce((sum, o) => sum + o, 0);
133
- columnWidths = minWidths.map((min, i) => {
134
- if (totalOverflow === 0)
135
- return min;
136
- const extra = Math.floor((overflows[i] / totalOverflow) * extraSpace);
137
- return min + extra;
138
- });
139
- }
140
- else {
141
- // Table wider than terminal at minimum widths
142
- // Shrink columns proportionally to fit allowing word breaks
143
- needsHardWrap = true;
144
- const scaleFactor = availableWidth / totalMin;
145
- columnWidths = minWidths.map((w) => Math.max(Math.floor(w * scaleFactor), MIN_COLUMN_WIDTH));
146
- }
147
- // Step 4: Calculate max row lines to determine if vertical format is needed
148
- function calculateMaxRowLines() {
149
- let maxLines = 1;
150
- // Check header
151
- for (let i = 0; i < token.header.length; i++) {
152
- const content = formatCell(token.header[i].tokens);
153
- const wrapped = wrapText(content, columnWidths[i], {
154
- hard: needsHardWrap,
155
- });
156
- maxLines = Math.max(maxLines, wrapped.length);
157
- }
158
- // Check rows
159
- for (const row of token.rows) {
160
- for (let i = 0; i < row.length; i++) {
161
- const content = formatCell(row[i]?.tokens);
162
- const wrapped = wrapText(content, columnWidths[i], {
163
- hard: needsHardWrap,
164
- });
165
- maxLines = Math.max(maxLines, wrapped.length);
166
- }
167
- }
168
- return maxLines;
169
- }
170
- // Use vertical format if wrapping would make rows too tall
171
- const maxRowLines = calculateMaxRowLines();
172
- const useVerticalFormat = maxRowLines > MAX_ROW_LINES;
173
- // Render a single row with potential multi-line cells
174
- // Returns an array of strings, one per line of the row
175
- function renderRowLines(cells, isHeader) {
176
- // Get wrapped lines for each cell (preserving ANSI formatting)
177
- const cellLines = cells.map((cell, colIndex) => {
178
- const formattedText = formatCell(cell.tokens);
179
- const width = columnWidths[colIndex];
180
- return wrapText(formattedText, width, { hard: needsHardWrap });
181
- });
182
- // Find max number of lines in this row
183
- const maxLines = Math.max(...cellLines.map((lines) => lines.length), 1);
184
- // Calculate vertical offset for each cell (to center vertically)
185
- const verticalOffsets = cellLines.map((lines) => Math.floor((maxLines - lines.length) / 2));
186
- // Build each line of the row as a single string
187
- const result = [];
188
- for (let lineIdx = 0; lineIdx < maxLines; lineIdx++) {
189
- let line = "│";
190
- for (let colIndex = 0; colIndex < cells.length; colIndex++) {
191
- const lines = cellLines[colIndex];
192
- const offset = verticalOffsets[colIndex];
193
- const contentLineIdx = lineIdx - offset;
194
- const lineText = contentLineIdx >= 0 && contentLineIdx < lines.length
195
- ? lines[contentLineIdx]
196
- : "";
197
- const width = columnWidths[colIndex];
198
- // Headers always centered; data uses table alignment
199
- const align = isHeader
200
- ? "center"
201
- : (token.align?.[colIndex] ?? "left");
202
- line +=
203
- " " +
204
- padAligned(lineText, stringWidth(lineText), width, align) +
205
- " │";
206
- }
207
- result.push(line);
208
- }
209
- return result;
210
- }
211
- // Render horizontal border as a single string
212
- function renderBorderLine(type) {
213
- const [left, mid, cross, right] = {
214
- top: ["┌", "─", "┬", "┐"],
215
- middle: ["├", "─", "┼", "┤"],
216
- bottom: ["└", "─", "┴", "┘"],
217
- }[type];
218
- let line = left;
219
- columnWidths.forEach((width, colIndex) => {
220
- line += mid.repeat(width + 2);
221
- line += colIndex < columnWidths.length - 1 ? cross : right;
222
- });
223
- return line;
224
- }
225
- // Render vertical format (key-value pairs) for extra-narrow terminals
226
- function renderVerticalFormat() {
227
- const lines = [];
228
- const headers = token.header.map((h) => getPlainText(h.tokens));
229
- const separatorWidth = Math.min(columns - 1, 40);
230
- const separator = "─".repeat(separatorWidth);
231
- // Small indent for wrapped lines (just 2 spaces)
232
- const wrapIndent = " ";
233
- token.rows.forEach((row, rowIndex) => {
234
- if (rowIndex > 0) {
235
- lines.push(separator);
236
- }
237
- row.forEach((cell, colIndex) => {
238
- const label = headers[colIndex] || `Column ${colIndex + 1}`;
239
- // Clean value: trim, remove extra internal whitespace/newlines
240
- const rawValue = formatCell(cell.tokens).trimEnd();
241
- const value = rawValue.replace(/\n+/g, " ").replace(/\s+/g, " ").trim();
242
- // Wrap value to fit terminal, accounting for label on first line
243
- const firstLineWidth = columns - stringWidth(label) - 3;
244
- const subsequentLineWidth = columns - wrapIndent.length - 1;
245
- // Two-pass wrap: first line is narrower (label takes space),
246
- // continuation lines get the full width minus indent.
247
- const firstPassLines = wrapText(value, Math.max(firstLineWidth, 10));
248
- const firstLine = firstPassLines[0] || "";
249
- let wrappedValue;
250
- if (firstPassLines.length <= 1 ||
251
- subsequentLineWidth <= firstLineWidth) {
252
- wrappedValue = firstPassLines;
253
- }
254
- else {
255
- // Re-join remaining text and re-wrap to the wider continuation width
256
- const remainingText = firstPassLines
257
- .slice(1)
258
- .map((l) => l.trim())
259
- .join(" ");
260
- const rewrapped = wrapText(remainingText, subsequentLineWidth);
261
- wrappedValue = [firstLine, ...rewrapped];
262
- }
263
- // First line: bold label + value
264
- lines.push(`${ANSI_BOLD_START}${label}:${ANSI_BOLD_END} ${wrappedValue[0] || ""}`);
265
- // Subsequent lines with small indent (skip empty lines)
266
- for (let i = 1; i < wrappedValue.length; i++) {
267
- const line = wrappedValue[i];
268
- if (!line.trim())
269
- continue;
270
- lines.push(`${wrapIndent}${line}`);
271
- }
272
- });
273
- });
274
- return lines.join("\n");
275
- }
276
- // Choose format based on available width
277
- if (useVerticalFormat) {
278
- return renderVerticalFormat();
279
- }
280
- // Build the complete horizontal table as an array of strings
281
- const tableLines = [];
282
- tableLines.push(renderBorderLine("top"));
283
- tableLines.push(...renderRowLines(token.header, true));
284
- tableLines.push(renderBorderLine("middle"));
285
- token.rows.forEach((row, rowIndex) => {
286
- tableLines.push(...renderRowLines(row, false));
287
- if (rowIndex < token.rows.length - 1) {
288
- tableLines.push(renderBorderLine("middle"));
289
- }
290
- });
291
- tableLines.push(renderBorderLine("bottom"));
292
- // Safety check: verify no line exceeds terminal width.
293
- // This catches edge cases during terminal resize where calculations
294
- // were based on a different width than the current render target.
295
- const maxLineWidth = Math.max(...tableLines.map((line) => stringWidth(stripAnsiColors(line))));
296
- // If we're within SAFETY_MARGIN characters of the edge, use vertical format
297
- // to account for terminal resize race conditions.
298
- if (maxLineWidth > columns - SAFETY_MARGIN) {
299
- return renderVerticalFormat();
300
- }
301
- return tableLines.join("\n");
302
- }
@@ -1,8 +0,0 @@
1
- import type { Message } from "wave-agent-sdk";
2
- /**
3
- * 判断一条 user 消息能否作为 /rewind 检查点。
4
- * 后台任务通知(task_notification)、hook 注入的消息(source: "hook")
5
- * 与 bang 命令消息都是系统生成、用户不可见的,不能作为回滚点。
6
- * CLI 交互式选择器与 stdio listRewindCheckpoints 共用此判定,避免两处漂移。
7
- */
8
- export declare function isUserCheckpointMessage(m: Message): boolean;
@@ -1,17 +0,0 @@
1
- /**
2
- * 判断一条 user 消息能否作为 /rewind 检查点。
3
- * 后台任务通知(task_notification)、hook 注入的消息(source: "hook")
4
- * 与 bang 命令消息都是系统生成、用户不可见的,不能作为回滚点。
5
- * CLI 交互式选择器与 stdio listRewindCheckpoints 共用此判定,避免两处漂移。
6
- */
7
- export function isUserCheckpointMessage(m) {
8
- if (m.role !== "user" || m.isMeta)
9
- return false;
10
- if (m.blocks.some((b) => b.type === "task_notification"))
11
- return false;
12
- if (m.blocks.some((b) => b.type === "text" && b.source === "hook"))
13
- return false;
14
- if (m.blocks.some((b) => b.type === "bang"))
15
- return false;
16
- return true;
17
- }
@@ -1,14 +0,0 @@
1
- export interface ThrottleOptions {
2
- leading?: boolean;
3
- trailing?: boolean;
4
- }
5
- export interface ThrottledFunction<A extends unknown[]> {
6
- (...args: A): void;
7
- cancel: () => void;
8
- flush: () => void;
9
- }
10
- /**
11
- * Creates a throttled function that only invokes `func` at most once per
12
- * every `wait` milliseconds.
13
- */
14
- export declare function throttle<A extends unknown[]>(func: (...args: A) => void, wait: number, options?: ThrottleOptions): ThrottledFunction<A>;
@@ -1,55 +0,0 @@
1
- /**
2
- * Creates a throttled function that only invokes `func` at most once per
3
- * every `wait` milliseconds.
4
- */
5
- export function throttle(func, wait, options = { leading: true, trailing: true }) {
6
- let timeoutId = null;
7
- let lastArgs = null;
8
- let lastCallTime = 0;
9
- const invokeFunc = () => {
10
- if (lastArgs) {
11
- func(...lastArgs);
12
- lastCallTime = Date.now();
13
- lastArgs = null;
14
- }
15
- };
16
- const throttled = (...args) => {
17
- const now = Date.now();
18
- const remaining = wait - (now - lastCallTime);
19
- lastArgs = args;
20
- if (remaining <= 0 || remaining > wait) {
21
- if (timeoutId) {
22
- clearTimeout(timeoutId);
23
- timeoutId = null;
24
- }
25
- if (options.leading !== false || lastCallTime !== 0) {
26
- invokeFunc();
27
- }
28
- else {
29
- lastCallTime = now;
30
- }
31
- }
32
- else if (!timeoutId && options.trailing !== false) {
33
- timeoutId = setTimeout(() => {
34
- timeoutId = null;
35
- invokeFunc();
36
- }, remaining);
37
- }
38
- };
39
- throttled.cancel = () => {
40
- if (timeoutId) {
41
- clearTimeout(timeoutId);
42
- timeoutId = null;
43
- }
44
- lastArgs = null;
45
- lastCallTime = 0;
46
- };
47
- throttled.flush = () => {
48
- if (timeoutId) {
49
- clearTimeout(timeoutId);
50
- timeoutId = null;
51
- }
52
- invokeFunc();
53
- };
54
- return throttled;
55
- }
@@ -1,18 +0,0 @@
1
- /**
2
- * Tool parameter transformation utilities for UI rendering
3
- * Forces type judgment based on tool name using type assertions
4
- */
5
- import { type Change, type WriteToolParameters, type EditToolParameters } from "wave-agent-sdk";
6
- /**
7
- * Transform Write tool parameters to changes
8
- */
9
- export declare function transformWriteParameters(parameters: WriteToolParameters): Change[];
10
- /**
11
- * Transform Edit tool parameters to changes
12
- */
13
- export declare function transformEditParameters(parameters: EditToolParameters): Change[];
14
- /**
15
- * Transform tool block parameters into standardized Change[] array for diff display
16
- * Forces type judgment based on tool name using type assertions
17
- */
18
- export declare function transformToolBlockToChanges(toolName: string, parameters: string, startLineNumber?: number): Change[];
@@ -1,73 +0,0 @@
1
- /**
2
- * Tool parameter transformation utilities for UI rendering
3
- * Forces type judgment based on tool name using type assertions
4
- */
5
- import { logger } from "./logger.js";
6
- /**
7
- * Parse tool block parameters
8
- */
9
- function parseToolParameters(parameters) {
10
- if (!parameters) {
11
- return {};
12
- }
13
- try {
14
- return JSON.parse(parameters);
15
- }
16
- catch (error) {
17
- logger.warn("Failed to parse tool parameters:", error);
18
- return {};
19
- }
20
- }
21
- /**
22
- * Transform Write tool parameters to changes
23
- */
24
- export function transformWriteParameters(parameters) {
25
- return [
26
- {
27
- oldContent: "", // No previous content for write operations
28
- newContent: parameters.content,
29
- },
30
- ];
31
- }
32
- /**
33
- * Transform Edit tool parameters to changes
34
- */
35
- export function transformEditParameters(parameters) {
36
- return [
37
- {
38
- oldContent: parameters.old_string,
39
- newContent: parameters.new_string,
40
- },
41
- ];
42
- }
43
- /**
44
- * Transform tool block parameters into standardized Change[] array for diff display
45
- * Forces type judgment based on tool name using type assertions
46
- */
47
- export function transformToolBlockToChanges(toolName, parameters, startLineNumber) {
48
- try {
49
- if (!toolName) {
50
- return [];
51
- }
52
- const parsedParams = parseToolParameters(parameters);
53
- let changes = [];
54
- switch (toolName) {
55
- case "Write":
56
- changes = transformWriteParameters(parsedParams);
57
- break;
58
- case "Edit":
59
- changes = transformEditParameters(parsedParams);
60
- break;
61
- default:
62
- return [];
63
- }
64
- if (changes.length > 0 && startLineNumber !== undefined) {
65
- changes[0].startLineNumber = startLineNumber;
66
- }
67
- return changes;
68
- }
69
- catch (error) {
70
- logger.warn("Failed to transform tool block to changes:", error);
71
- return [];
72
- }
73
- }
@@ -1,28 +0,0 @@
1
- import type { Usage } from "wave-agent-sdk";
2
- /**
3
- * Token summary by model
4
- */
5
- export interface TokenSummary {
6
- model: string;
7
- prompt_tokens: number;
8
- completion_tokens: number;
9
- total_tokens: number;
10
- operations: {
11
- agent_calls: number;
12
- compactions: number;
13
- };
14
- cache_read_input_tokens?: number;
15
- cache_creation_input_tokens?: number;
16
- }
17
- /**
18
- * Calculate token usage summary by model from usage array
19
- * @param usages Array of usage data from agent operations
20
- * @returns Array of token summaries grouped by model
21
- */
22
- export declare function calculateTokenSummary(usages: Usage[]): Record<string, TokenSummary>;
23
- /**
24
- * Display usage summary in a formatted way
25
- * @param usages Array of usage data from agent operations
26
- * @param sessionFilePath Optional session file path to display
27
- */
28
- export declare function displayUsageSummary(usages: Usage[], sessionFilePath?: string): void;
@@ -1,121 +0,0 @@
1
- /**
2
- * Calculate token usage summary by model from usage array
3
- * @param usages Array of usage data from agent operations
4
- * @returns Array of token summaries grouped by model
5
- */
6
- export function calculateTokenSummary(usages) {
7
- const summaryMap = new Map();
8
- for (const usage of usages) {
9
- const model = usage.model || "unknown";
10
- if (!summaryMap.has(model)) {
11
- summaryMap.set(model, {
12
- model,
13
- prompt_tokens: 0,
14
- completion_tokens: 0,
15
- total_tokens: 0,
16
- operations: {
17
- agent_calls: 0,
18
- compactions: 0,
19
- },
20
- });
21
- }
22
- const summary = summaryMap.get(model);
23
- summary.prompt_tokens += usage.prompt_tokens;
24
- summary.completion_tokens += usage.completion_tokens;
25
- summary.total_tokens += usage.total_tokens;
26
- // Handle cache tokens if present and non-zero
27
- if (usage.cache_read_input_tokens && usage.cache_read_input_tokens > 0) {
28
- summary.cache_read_input_tokens =
29
- (summary.cache_read_input_tokens || 0) + usage.cache_read_input_tokens;
30
- }
31
- if (usage.cache_creation_input_tokens &&
32
- usage.cache_creation_input_tokens > 0) {
33
- summary.cache_creation_input_tokens =
34
- (summary.cache_creation_input_tokens || 0) +
35
- usage.cache_creation_input_tokens;
36
- }
37
- // Track operation types
38
- if (usage.operation_type === "agent") {
39
- summary.operations.agent_calls += 1;
40
- }
41
- else if (usage.operation_type === "compact") {
42
- summary.operations.compactions += 1;
43
- }
44
- }
45
- // Convert Map to Record and sort by total tokens
46
- const result = {};
47
- const sortedEntries = Array.from(summaryMap.entries()).sort((a, b) => b[1].total_tokens - a[1].total_tokens);
48
- for (const [model, summary] of sortedEntries) {
49
- result[model] = summary;
50
- }
51
- return result;
52
- }
53
- /**
54
- * Display usage summary in a formatted way
55
- * @param usages Array of usage data from agent operations
56
- * @param sessionFilePath Optional session file path to display
57
- */
58
- export function displayUsageSummary(usages, sessionFilePath) {
59
- if (usages.length === 0) {
60
- return; // No usage data to display
61
- }
62
- const summaries = calculateTokenSummary(usages);
63
- console.log("\nToken Usage Summary:");
64
- console.log("==================");
65
- if (sessionFilePath) {
66
- console.log(`Session: ${sessionFilePath}`);
67
- }
68
- let totalPrompt = 0;
69
- let totalCompletion = 0;
70
- let totalTokens = 0;
71
- let totalAgentCalls = 0;
72
- let totalCompactions = 0;
73
- let totalCacheRead = 0;
74
- let totalCacheCreation = 0;
75
- let hasCacheData = false;
76
- for (const [, summary] of Object.entries(summaries)) {
77
- console.log(`Model: ${summary.model}`);
78
- console.log(` Prompt tokens: ${summary.prompt_tokens.toLocaleString()}`);
79
- console.log(` Completion tokens: ${summary.completion_tokens.toLocaleString()}`);
80
- console.log(` Total tokens: ${summary.total_tokens.toLocaleString()}`);
81
- // Display cache information if available
82
- if (summary.cache_read_input_tokens ||
83
- summary.cache_creation_input_tokens) {
84
- hasCacheData = true;
85
- console.log(" Cache Usage:");
86
- if (summary.cache_read_input_tokens &&
87
- summary.cache_read_input_tokens > 0) {
88
- console.log(` Read from cache: ${summary.cache_read_input_tokens.toLocaleString()} tokens`);
89
- totalCacheRead += summary.cache_read_input_tokens;
90
- }
91
- if (summary.cache_creation_input_tokens &&
92
- summary.cache_creation_input_tokens > 0) {
93
- console.log(` Created cache: ${summary.cache_creation_input_tokens.toLocaleString()} tokens`);
94
- totalCacheCreation += summary.cache_creation_input_tokens;
95
- }
96
- }
97
- console.log(` Operations: ${summary.operations.agent_calls} agent calls, ${summary.operations.compactions} compactions`);
98
- console.log();
99
- totalPrompt += summary.prompt_tokens;
100
- totalCompletion += summary.completion_tokens;
101
- totalTokens += summary.total_tokens;
102
- totalAgentCalls += summary.operations.agent_calls;
103
- totalCompactions += summary.operations.compactions;
104
- }
105
- if (Object.keys(summaries).length > 1) {
106
- console.log("Overall Total:");
107
- console.log(` Prompt tokens: ${totalPrompt.toLocaleString()}`);
108
- console.log(` Completion tokens: ${totalCompletion.toLocaleString()}`);
109
- console.log(` Total tokens: ${totalTokens.toLocaleString()}`);
110
- if (hasCacheData) {
111
- console.log(" Cache Usage:");
112
- if (totalCacheRead > 0) {
113
- console.log(` Read from cache: ${totalCacheRead.toLocaleString()} tokens`);
114
- }
115
- if (totalCacheCreation > 0) {
116
- console.log(` Created cache: ${totalCacheCreation.toLocaleString()} tokens`);
117
- }
118
- }
119
- console.log(` Operations: ${totalAgentCalls} agent calls, ${totalCompactions} compactions`);
120
- }
121
- }
@@ -1 +0,0 @@
1
- export declare function isUpdateAvailable(currentVersion: string, latestVersion: string): boolean;
@@ -1,4 +0,0 @@
1
- import semver from "semver";
2
- export function isUpdateAvailable(currentVersion, latestVersion) {
3
- return semver.gt(latestVersion, currentVersion);
4
- }