wave-code 0.9.7 → 0.10.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.
@@ -0,0 +1,28 @@
1
+ import { Readable, Writable } from "node:stream";
2
+ import { AgentSideConnection, ndJsonStream } from "@agentclientprotocol/sdk";
3
+ import { WaveAcpAgent } from "./agent.js";
4
+ import { logger } from "../utils/logger.js";
5
+
6
+ export async function startAcpCli() {
7
+ // Redirect console.log to logger to avoid interfering with JSON-RPC over stdio
8
+ console.log = (...args: unknown[]) => {
9
+ logger.info(...args);
10
+ };
11
+
12
+ logger.info("Starting ACP bridge...");
13
+
14
+ // Convert Node.js stdio to Web streams
15
+ const stdin = Readable.toWeb(process.stdin) as ReadableStream<Uint8Array>;
16
+ const stdout = Writable.toWeb(process.stdout) as WritableStream<Uint8Array>;
17
+
18
+ // Create ACP stream
19
+ const stream = ndJsonStream(stdout, stdin);
20
+
21
+ // Initialize AgentSideConnection
22
+ const connection = new AgentSideConnection((conn) => {
23
+ return new WaveAcpAgent(conn);
24
+ }, stream);
25
+
26
+ // Wait for connection to close
27
+ await connection.closed;
28
+ }
package/src/acp-cli.ts ADDED
@@ -0,0 +1,5 @@
1
+ import { startAcpCli } from "./acp/index.js";
2
+
3
+ export async function runAcp() {
4
+ await startAcpCli();
5
+ }
@@ -72,7 +72,7 @@ export const ChatInterface: React.FC = () => {
72
72
 
73
73
  const terminalHeight = stdout?.rows || 24;
74
74
  const totalHeight = detailsHeight + selectorHeight + dynamicBlocksHeight;
75
- if (totalHeight > terminalHeight) {
75
+ if (totalHeight > terminalHeight - 3) {
76
76
  setIsConfirmationTooTall(true);
77
77
  }
78
78
  }, [
@@ -154,43 +154,87 @@ export const DiffDisplay: React.FC<DiffDisplayProps> = ({
154
154
 
155
155
  // Process line diffs
156
156
  const diffElements: React.ReactNode[] = [];
157
- lineDiffs.forEach((part, partIndex) => {
157
+ for (let i = 0; i < lineDiffs.length; i++) {
158
+ const part = lineDiffs[i];
158
159
  const lines = part.value.split("\n");
159
160
  // diffLines might return a trailing empty string if the content ends with a newline
160
161
  if (lines[lines.length - 1] === "") {
161
162
  lines.pop();
162
163
  }
163
164
 
164
- if (part.added) {
165
+ if (part.removed) {
166
+ // Look ahead for an added block
167
+ if (i + 1 < lineDiffs.length && lineDiffs[i + 1].added) {
168
+ const nextPart = lineDiffs[i + 1];
169
+ const addedLines = nextPart.value.split("\n");
170
+ if (addedLines[addedLines.length - 1] === "") {
171
+ addedLines.pop();
172
+ }
173
+
174
+ if (lines.length === addedLines.length) {
175
+ // Word-level diffing
176
+ lines.forEach((line, lineIndex) => {
177
+ const { removedParts, addedParts } = renderWordLevelDiff(
178
+ line,
179
+ addedLines[lineIndex],
180
+ `word-${changeIndex}-${i}-${lineIndex}`,
181
+ );
182
+ diffElements.push(
183
+ renderLine(
184
+ oldLineNum++,
185
+ null,
186
+ "-",
187
+ removedParts,
188
+ "red",
189
+ `remove-${changeIndex}-${i}-${lineIndex}`,
190
+ ),
191
+ );
192
+ diffElements.push(
193
+ renderLine(
194
+ null,
195
+ newLineNum++,
196
+ "+",
197
+ addedParts,
198
+ "green",
199
+ `add-${changeIndex}-${i}-${lineIndex}`,
200
+ ),
201
+ );
202
+ });
203
+ i++; // Skip the added block
204
+ continue;
205
+ }
206
+ }
207
+
208
+ // Fallback to standard removed rendering
165
209
  lines.forEach((line, lineIndex) => {
166
210
  diffElements.push(
167
211
  renderLine(
212
+ oldLineNum++,
168
213
  null,
169
- newLineNum++,
170
- "+",
214
+ "-",
171
215
  line,
172
- "green",
173
- `add-${changeIndex}-${partIndex}-${lineIndex}`,
216
+ "red",
217
+ `remove-${changeIndex}-${i}-${lineIndex}`,
174
218
  ),
175
219
  );
176
220
  });
177
- } else if (part.removed) {
221
+ } else if (part.added) {
178
222
  lines.forEach((line, lineIndex) => {
179
223
  diffElements.push(
180
224
  renderLine(
181
- oldLineNum++,
182
225
  null,
183
- "-",
226
+ newLineNum++,
227
+ "+",
184
228
  line,
185
- "red",
186
- `remove-${changeIndex}-${partIndex}-${lineIndex}`,
229
+ "green",
230
+ `add-${changeIndex}-${i}-${lineIndex}`,
187
231
  ),
188
232
  );
189
233
  });
190
234
  } else {
191
235
  // Context lines - show unchanged content
192
- const isFirstBlock = partIndex === 0;
193
- const isLastBlock = partIndex === lineDiffs.length - 1;
236
+ const isFirstBlock = i === 0;
237
+ const isLastBlock = i === lineDiffs.length - 1;
194
238
 
195
239
  let linesToDisplay = lines;
196
240
  let showEllipsisTop = false;
@@ -221,7 +265,7 @@ export const DiffDisplay: React.FC<DiffDisplayProps> = ({
221
265
 
222
266
  if (showEllipsisTop) {
223
267
  diffElements.push(
224
- <Box key={`ellipsis-top-${changeIndex}-${partIndex}`}>
268
+ <Box key={`ellipsis-top-${changeIndex}-${i}`}>
225
269
  <Text color="gray">{" ".repeat(maxDigits * 2 + 2)}...</Text>
226
270
  </Box>,
227
271
  );
@@ -239,7 +283,7 @@ export const DiffDisplay: React.FC<DiffDisplayProps> = ({
239
283
  oldLineNum += skipCount;
240
284
  newLineNum += skipCount;
241
285
  diffElements.push(
242
- <Box key={`ellipsis-mid-${changeIndex}-${partIndex}`}>
286
+ <Box key={`ellipsis-mid-${changeIndex}-${i}`}>
243
287
  <Text color="gray">
244
288
  {" ".repeat(maxDigits * 2 + 2)}...
245
289
  </Text>
@@ -254,7 +298,7 @@ export const DiffDisplay: React.FC<DiffDisplayProps> = ({
254
298
  " ",
255
299
  line,
256
300
  "white",
257
- `context-${changeIndex}-${partIndex}-${lineIndex}`,
301
+ `context-${changeIndex}-${i}-${lineIndex}`,
258
302
  ),
259
303
  );
260
304
  });
@@ -266,62 +310,14 @@ export const DiffDisplay: React.FC<DiffDisplayProps> = ({
266
310
  oldLineNum += skipCount;
267
311
  newLineNum += skipCount;
268
312
  diffElements.push(
269
- <Box key={`ellipsis-bottom-${changeIndex}-${partIndex}`}>
313
+ <Box key={`ellipsis-bottom-${changeIndex}-${i}`}>
270
314
  <Text color="gray">{" ".repeat(maxDigits * 2 + 2)}...</Text>
271
315
  </Box>,
272
316
  );
273
317
  }
274
318
  }
275
- });
276
-
277
- // If it's a single line change (one removed, one added), use word-level diff
278
- if (
279
- diffElements.length === 2 &&
280
- React.isValidElement(diffElements[0]) &&
281
- React.isValidElement(diffElements[1]) &&
282
- typeof diffElements[0].key === "string" &&
283
- diffElements[0].key.includes("remove-") &&
284
- typeof diffElements[1].key === "string" &&
285
- diffElements[1].key.includes("add-")
286
- ) {
287
- const removedText = extractTextFromElement(diffElements[0]);
288
- const addedText = extractTextFromElement(diffElements[1]);
289
- const oldLineNumVal = extractOldLineNumFromElement(diffElements[0]);
290
- const newLineNumVal = extractNewLineNumFromElement(diffElements[1]);
291
-
292
- if (removedText && addedText) {
293
- const { removedParts, addedParts } = renderWordLevelDiff(
294
- removedText,
295
- addedText,
296
- `word-${changeIndex}`,
297
- );
298
-
299
- allElements.push(
300
- renderLine(
301
- oldLineNumVal,
302
- null,
303
- "-",
304
- removedParts,
305
- "red",
306
- `word-diff-removed-${changeIndex}`,
307
- ),
308
- );
309
- allElements.push(
310
- renderLine(
311
- null,
312
- newLineNumVal,
313
- "+",
314
- addedParts,
315
- "green",
316
- `word-diff-added-${changeIndex}`,
317
- ),
318
- );
319
- } else {
320
- allElements.push(...diffElements);
321
- }
322
- } else {
323
- allElements.push(...diffElements);
324
319
  }
320
+ allElements.push(...diffElements);
325
321
  } catch (error) {
326
322
  console.warn(
327
323
  `Error rendering diff for change ${changeIndex}:`,
@@ -361,71 +357,3 @@ export const DiffDisplay: React.FC<DiffDisplayProps> = ({
361
357
  </Box>
362
358
  );
363
359
  };
364
-
365
- // Helper function to extract text content from a React element
366
- const extractTextFromElement = (element: React.ReactNode): string | null => {
367
- if (!React.isValidElement(element)) return null;
368
-
369
- // Navigate through Box -> Text structure
370
- // Our new structure is: Box -> Text (old), Text (new), Text (|), Text (prefix), Text (content)
371
- const children = (
372
- element.props as unknown as { children?: React.ReactNode[] }
373
- ).children;
374
- if (Array.isArray(children) && children.length >= 5) {
375
- const textElement = children[4]; // Fifth child should be the Text with content
376
- if (React.isValidElement(textElement)) {
377
- const textChildren = (textElement.props as Record<string, unknown>)
378
- .children;
379
- return Array.isArray(textChildren)
380
- ? textChildren.join("")
381
- : String(textChildren || "");
382
- }
383
- }
384
- return null;
385
- };
386
-
387
- const extractOldLineNumFromElement = (
388
- element: React.ReactNode,
389
- ): number | null => {
390
- if (!React.isValidElement(element)) return null;
391
- const children = (
392
- element.props as unknown as { children?: React.ReactNode[] }
393
- ).children;
394
- if (Array.isArray(children) && children.length >= 1) {
395
- const textElement = children[0];
396
- if (React.isValidElement(textElement)) {
397
- const textChildren = (textElement.props as Record<string, unknown>)
398
- .children;
399
- const val = (
400
- Array.isArray(textChildren)
401
- ? textChildren.join("")
402
- : String(textChildren || "")
403
- ).trim();
404
- return val ? parseInt(val, 10) : null;
405
- }
406
- }
407
- return null;
408
- };
409
-
410
- const extractNewLineNumFromElement = (
411
- element: React.ReactNode,
412
- ): number | null => {
413
- if (!React.isValidElement(element)) return null;
414
- const children = (
415
- element.props as unknown as { children?: React.ReactNode[] }
416
- ).children;
417
- if (Array.isArray(children) && children.length >= 2) {
418
- const textElement = children[1];
419
- if (React.isValidElement(textElement)) {
420
- const textChildren = (textElement.props as Record<string, unknown>)
421
- .children;
422
- const val = (
423
- Array.isArray(textChildren)
424
- ? textChildren.join("")
425
- : String(textChildren || "")
426
- ).trim();
427
- return val ? parseInt(val, 10) : null;
428
- }
429
- }
430
- return null;
431
- };
@@ -295,9 +295,6 @@ export const ChatProvider: React.FC<ChatProviderProps> = ({
295
295
  onPermissionModeChange: (mode) => {
296
296
  setPermissionModeState(mode);
297
297
  },
298
- onSlashCommandsChange: (commands) => {
299
- setSlashCommands([...commands]);
300
- },
301
298
  };
302
299
 
303
300
  try {
package/src/index.ts CHANGED
@@ -70,6 +70,11 @@ export async function main() {
70
70
  type: "string",
71
71
  global: false,
72
72
  })
73
+ .option("acp", {
74
+ description: "Run as an ACP bridge",
75
+ type: "boolean",
76
+ global: false,
77
+ })
73
78
  .command("plugin", "Manage plugins and marketplaces", (yargs) => {
74
79
  return yargs
75
80
  .help()
@@ -246,6 +251,12 @@ export async function main() {
246
251
  process.chdir(workdir);
247
252
  }
248
253
 
254
+ // Handle ACP mode
255
+ if (argv.acp) {
256
+ const { runAcp } = await import("./acp-cli.js");
257
+ return runAcp();
258
+ }
259
+
249
260
  // Handle restore session command
250
261
  if (
251
262
  argv.restore === "" ||