wave-code 1.0.7 → 1.0.9

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.
package/src/index.ts CHANGED
@@ -252,6 +252,136 @@ export async function main() {
252
252
  },
253
253
  );
254
254
  })
255
+ .command(
256
+ "daemon",
257
+ "Manage the wave daemon (client subcommands — to START a daemon use `wave --daemon <socket>` instead)",
258
+ (yargs) => {
259
+ return yargs
260
+ .help()
261
+ .command(
262
+ "list",
263
+ "List sessions hosted by the daemon (in-memory registry)",
264
+ {},
265
+ async () => {
266
+ const { daemonListCommand, DEFAULT_DAEMON_SOCKET } =
267
+ await import("./daemon/commands.js");
268
+ await daemonListCommand(DEFAULT_DAEMON_SOCKET);
269
+ },
270
+ )
271
+ .command(
272
+ "status <sessionId>",
273
+ "Show a session's progress and recent messages",
274
+ (yargs) => {
275
+ return yargs
276
+ .positional("sessionId", {
277
+ describe: "Session ID hosted by the daemon",
278
+ type: "string",
279
+ })
280
+ .option("lines", {
281
+ describe: "Number of recent messages to show",
282
+ default: 20,
283
+ type: "number",
284
+ });
285
+ },
286
+ async (argv) => {
287
+ const { daemonStatusCommand, DEFAULT_DAEMON_SOCKET } =
288
+ await import("./daemon/commands.js");
289
+ await daemonStatusCommand(
290
+ DEFAULT_DAEMON_SOCKET,
291
+ argv.sessionId as string,
292
+ argv.lines as number,
293
+ );
294
+ },
295
+ )
296
+ .command(
297
+ "send <sessionId> <message>",
298
+ "Inject a message into a session and wait for the reply",
299
+ (yargs) => {
300
+ return yargs
301
+ .positional("sessionId", {
302
+ describe: "Session ID hosted by the daemon",
303
+ type: "string",
304
+ })
305
+ .positional("message", {
306
+ describe: "Message to send",
307
+ type: "string",
308
+ })
309
+ .option("timeout", {
310
+ describe: "Seconds to wait for the reply (0 = no limit)",
311
+ default: 600,
312
+ type: "number",
313
+ });
314
+ },
315
+ async (argv) => {
316
+ const { daemonSendCommand, DEFAULT_DAEMON_SOCKET } =
317
+ await import("./daemon/commands.js");
318
+ await daemonSendCommand(
319
+ DEFAULT_DAEMON_SOCKET,
320
+ argv.sessionId as string,
321
+ argv.message as string,
322
+ { timeout: argv.timeout as number },
323
+ );
324
+ },
325
+ )
326
+ .command(
327
+ "respond <sessionId> <requestId>",
328
+ "Respond to a pending permission request",
329
+ (yargs) => {
330
+ return yargs
331
+ .positional("sessionId", {
332
+ describe: "Session ID hosting the pending request",
333
+ type: "string",
334
+ })
335
+ .positional("requestId", {
336
+ describe: "Pending permission request ID",
337
+ type: "string",
338
+ })
339
+ .option("allow", {
340
+ describe: "Allow the operation",
341
+ type: "boolean",
342
+ })
343
+ .option("deny", {
344
+ describe: "Deny the operation",
345
+ type: "boolean",
346
+ })
347
+ .option("reason", {
348
+ describe: "Reason for the decision (deny)",
349
+ type: "string",
350
+ })
351
+ .option("answer", {
352
+ describe: "Answers JSON for AskUserQuestion requests",
353
+ type: "string",
354
+ })
355
+ .option("rule", {
356
+ describe: "Persist an allowed rule (e.g. Bash(ls))",
357
+ type: "string",
358
+ })
359
+ .option("mode", {
360
+ describe: "Switch the session's permission mode",
361
+ type: "string",
362
+ });
363
+ },
364
+ async (argv) => {
365
+ const { daemonRespondCommand, DEFAULT_DAEMON_SOCKET } =
366
+ await import("./daemon/commands.js");
367
+ await daemonRespondCommand(
368
+ DEFAULT_DAEMON_SOCKET,
369
+ argv.sessionId as string,
370
+ argv.requestId as string,
371
+ {
372
+ allow: argv.allow as boolean | undefined,
373
+ deny: argv.deny as boolean | undefined,
374
+ reason: argv.reason as string | undefined,
375
+ answer: argv.answer as string | undefined,
376
+ rule: argv.rule as string | undefined,
377
+ mode: argv.mode as string | undefined,
378
+ },
379
+ );
380
+ },
381
+ )
382
+ .demandCommand(1, "Please specify a daemon subcommand");
383
+ },
384
+ )
255
385
  .command(
256
386
  "update",
257
387
  "Update WAVE Code to the latest version",
@@ -175,6 +175,8 @@ export class AgentBridge {
175
175
  return this.getSessionInfo(sessionId);
176
176
  case "listPendingPermissions":
177
177
  return this.listPendingPermissions();
178
+ case "listDaemonSessions":
179
+ return this.listDaemonSessions();
178
180
  case "updateConfig":
179
181
  return this.updateConfig(p as unknown as UpdateConfigParams, sessionId);
180
182
  case "getConfiguredModels":
@@ -790,10 +792,45 @@ export class AgentBridge {
790
792
  } catch {
791
793
  // Best-effort; don't block message sending on history save failure
792
794
  }
793
- await entry.agent.sendMessage(params.text, params.images);
795
+ await entry.agent.sendMessage(
796
+ params.text,
797
+ this.persistDataUrlImages(params.images),
798
+ );
794
799
  return null;
795
800
  }
796
801
 
802
+ /**
803
+ * Webview hosts (desktop/vscode/jetbrains) send pasted images as inline
804
+ * data URLs — there is no local file behind them. Persist each to a temp
805
+ * file so the model gets a real path it can reference with tools (aligned
806
+ * with Claude Code's `[Image source: <path>]` metadata). Real paths pass
807
+ * through untouched; unparseable data URLs pass through as-is and are
808
+ * skipped by the SDK rather than blocking the message.
809
+ */
810
+ private persistDataUrlImages(
811
+ images?: Array<{ path: string; mimeType: string }>,
812
+ ): Array<{ path: string; mimeType: string }> | undefined {
813
+ if (!images || images.length === 0) return images;
814
+ return images.map((img) => {
815
+ if (!img.path.startsWith("data:")) return img;
816
+ const match = /^data:([^;,]+);base64,(.*)$/s.exec(img.path);
817
+ if (!match) return img;
818
+ try {
819
+ const mimeType = match[1];
820
+ const ext = mimeType.split("/")[1]?.replace("jpeg", "jpg") || "png";
821
+ const filePath = join(
822
+ tmpdir(),
823
+ `wave-image-${Date.now()}-${Math.random().toString(36).slice(2, 8)}.${ext}`,
824
+ );
825
+ writeFileSync(filePath, Buffer.from(match[2], "base64"));
826
+ return { path: filePath, mimeType };
827
+ } catch (error) {
828
+ logger.warn("Failed to persist pasted image to temp file:", error);
829
+ return img;
830
+ }
831
+ });
832
+ }
833
+
797
834
  private async bang(command: string, sessionId?: string): Promise<null> {
798
835
  const entry = this.requireSession(sessionId);
799
836
  await entry.agent.bang(command);
@@ -849,7 +886,10 @@ export class AgentBridge {
849
886
  }> {
850
887
  const entry = this.requireSession(sessionId);
851
888
  const { messages } = await entry.agent.getFullMessageThread();
852
- const index = messages.findIndex((m) => m.id === messageId);
889
+ // 压缩是 append-only:同 id 消息(压缩前历史 + 压缩后 append 的重复)会
890
+ // 在磁盘完整线程中出现多次。用户看到的折叠视图对应最后一次出现,
891
+ // 因此匹配最后一个而非第一个,避免回滚时连压缩摘要一起删掉。
892
+ const index = messages.map((m) => m.id).lastIndexOf(messageId);
853
893
  if (index === -1) {
854
894
  throw new RpcError(
855
895
  PROTOCOL_INTERNAL_ERROR,
@@ -869,13 +909,19 @@ export class AgentBridge {
869
909
  }> {
870
910
  const entry = this.requireSession(sessionId);
871
911
  const { messages } = await entry.agent.getFullMessageThread();
872
- const checkpoints = messages
873
- .filter((m) => isUserCheckpointMessage(m) && m.id)
874
- .map((m) => ({
875
- id: m.id as string,
876
- content: getMessageContent(m).replace(/\s+/g, " ").trim(),
877
- }));
878
- return { checkpoints };
912
+ // 压缩 append-only 后同 id 消息在磁盘完整线程中重复出现(压缩前历史 +
913
+ // 压缩后 append 的重复)。按 id 去重并保留最后一次出现(与折叠后的
914
+ // UI/内存视图一致),避免弹窗把同一条用户消息显示两遍。
915
+ const checkpointMap = new Map<string, { id: string; content: string }>();
916
+ for (const m of messages) {
917
+ if (isUserCheckpointMessage(m) && m.id) {
918
+ checkpointMap.set(m.id, {
919
+ id: m.id,
920
+ content: getMessageContent(m).replace(/\s+/g, " ").trim(),
921
+ });
922
+ }
923
+ }
924
+ return { checkpoints: Array.from(checkpointMap.values()) };
879
925
  }
880
926
 
881
927
  private deleteQueuedMessage(index: number, sessionId?: string): null {
@@ -893,7 +939,7 @@ export class AgentBridge {
893
939
  const entry = this.requireSession(sessionId);
894
940
  const ok = entry.agent.updateQueuedMessageById(id, {
895
941
  content: text,
896
- images,
942
+ images: this.persistDataUrlImages(images),
897
943
  });
898
944
  return { ok };
899
945
  }
@@ -1144,6 +1190,26 @@ export class AgentBridge {
1144
1190
  };
1145
1191
  }
1146
1192
 
1193
+ /** Daemon list: expose the in-memory session registry (live sessions only,
1194
+ * not disk-scanning). Registration order is preserved. */
1195
+ private listDaemonSessions(): {
1196
+ sessions: Array<{
1197
+ sessionId: string;
1198
+ workingDirectory: string;
1199
+ isLoading: boolean;
1200
+ messageCount: number;
1201
+ }>;
1202
+ } {
1203
+ return {
1204
+ sessions: [...this.sessions.entries()].map(([sessionId, entry]) => ({
1205
+ sessionId,
1206
+ workingDirectory: entry.agent.workingDirectory,
1207
+ isLoading: entry.agent.isLoading,
1208
+ messageCount: entry.agent.messages.length,
1209
+ })),
1210
+ };
1211
+ }
1212
+
1147
1213
  // ── Auth (global) ────────────────────────────────────────────
1148
1214
 
1149
1215
  private async getAuthStatus(): Promise<{
@@ -79,6 +79,8 @@ export type RequestMethod =
79
79
  | "setModel"
80
80
  // Permissions (daemon attach: re-surface pending approvals after reconnect)
81
81
  | "listPendingPermissions"
82
+ // Daemon (global — list in-memory session registry, no session required)
83
+ | "listDaemonSessions"
82
84
  // Auth
83
85
  | "getAuthStatus"
84
86
  | "login"