dsh-rewind-plugin 0.17.1 → 0.18.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.
package/lib/index.js CHANGED
@@ -9,15 +9,8 @@ function preferredLocale(preference) {
9
9
  return preference.toLowerCase().split("-")[0] === "zh" ? "zh" : "en";
10
10
  }
11
11
  var en = {
12
- "plan.rewinding": "Rewind to seq {targetSeq}, removing {count} node(s) from the model context (conversation log kept).",
13
- "plan.affects": "Affects {count} file(s):",
14
- "plan.restore": "restore {path}",
15
- "plan.delete": "delete {path}",
16
- "plan.noChanges": "No restorable changes after the target.",
17
- "plan.backupOff": "Snapshot backups are off; this restore may be incomplete.",
18
12
  "plan.skip": " not restored: {path} ({reason})",
19
13
  "skipReason.oversized": "over the {limit} backup limit, so the recorded state predates untracked edits",
20
- "uncovered.header": "{count} tracked file(s) exceed the {limit} backup limit and are not covered:",
21
14
  "error.invalidTarget": 'Cannot parse target "{raw}" (expected <index> or @<seq>)',
22
15
  "sep.list": ", ",
23
16
  "sep.clause": "; ",
@@ -35,7 +28,7 @@ var en = {
35
28
  "storeUnsupported": "file restore unavailable: these snapshots use a newer store format (v{version}) than this plugin understands; nothing was changed. Update the plugin or clear this session's snapshots.",
36
29
  "success": "Withdrawn seq {targetSeq} and everything after it (conversation returned to earlier){restore}.",
37
30
  "noUserMessages": "This session has no rewindable user messages yet.",
38
- "command.description": "Rewind the conversation and/or code to a previous point",
31
+ "command.description": "Rewind the conversation and/or files to a previous point",
39
32
  "command.undoDescription": "Alias of /rewind",
40
33
  "engine.description": "dsh-rewind internal command",
41
34
  "engine.rejected": "Internal command: use /rewind or /undo.",
@@ -62,15 +55,8 @@ var en = {
62
55
  "cleanup.usage": "Usage:\n /snapshot-auto-cleanup show status\n /snapshot-auto-cleanup on|off enable/disable auto-cleanup\n /snapshot-auto-cleanup max-age <days> set the idle cutoff\n /snapshot-auto-cleanup run [--apply] dry-run, or execute with --apply\n /snapshot-auto-cleanup run --current [--apply] dry-run/clear this session's snapshots"
63
56
  };
64
57
  var zh = {
65
- "plan.rewinding": "\u5C06\u56DE\u9000\u5230 seq {targetSeq}\uFF0C\u4ECE\u6A21\u578B\u4E0A\u4E0B\u6587\u79FB\u9664 {count} \u4E2A\u8282\u70B9\uFF08\u5BF9\u8BDD\u65E5\u5FD7\u4FDD\u7559\uFF09\u3002",
66
- "plan.affects": "\u5C06\u5F71\u54CD {count} \u4E2A\u6587\u4EF6\uFF1A",
67
- "plan.restore": "\u8FD8\u539F {path}",
68
- "plan.delete": "\u5220\u9664 {path}",
69
- "plan.noChanges": "\u76EE\u6807\u4E4B\u540E\u6CA1\u6709\u9700\u8981\u8FD8\u539F\u7684\u53D8\u66F4\u3002",
70
- "plan.backupOff": "\u5FEB\u7167\u5907\u4EFD\u5DF2\u5173\u95ED\uFF1B\u672C\u6B21\u8FD8\u539F\u53EF\u80FD\u4E0D\u5145\u5206\u3002",
71
58
  "plan.skip": " \u672A\u8FD8\u539F\uFF1A{path}\uFF08{reason}\uFF09",
72
59
  "skipReason.oversized": "\u5DF2\u8D85\u8FC7 {limit} \u7684\u5907\u4EFD\u4E0A\u9650\uFF0C\u8BB0\u5F55\u7684\u72B6\u6001\u65E9\u4E8E\u672A\u88AB\u8DDF\u8E2A\u7684\u4FEE\u6539",
73
- "uncovered.header": "{count} \u4E2A\u5DF2\u8DDF\u8E2A\u6587\u4EF6\u8D85\u8FC7 {limit} \u7684\u5907\u4EFD\u4E0A\u9650\uFF0C\u672A\u7EB3\u5165\u8BB0\u5F55\uFF1A",
74
60
  "error.invalidTarget": '\u65E0\u6CD5\u89E3\u6790\u76EE\u6807 "{raw}"\uFF08\u5E94\u4E3A <\u5E8F\u53F7> \u6216 @<seq>\uFF09',
75
61
  "sep.list": "\u3001",
76
62
  "sep.clause": "\uFF1B",
@@ -88,7 +74,7 @@ var zh = {
88
74
  "storeUnsupported": "\u6587\u4EF6\u8FD8\u539F\u4E0D\u53EF\u7528\uFF1A\u8FD9\u4E9B\u5FEB\u7167\u4F7F\u7528\u4E86\u6BD4\u672C\u63D2\u4EF6\u66F4\u65B0\u7684\u5B58\u50A8\u683C\u5F0F\uFF08v{version}\uFF09\uFF1B\u5DE5\u4F5C\u533A\u672A\u505A\u4EFB\u4F55\u6539\u52A8\u3002\u8BF7\u66F4\u65B0\u63D2\u4EF6\uFF0C\u6216\u6E05\u9664\u8BE5\u4F1A\u8BDD\u7684\u5FEB\u7167\u3002",
89
75
  "success": "\u5DF2\u64A4\u56DE seq {targetSeq} \u53CA\u4E4B\u540E\u5185\u5BB9\uFF08\u5BF9\u8BDD\u5DF2\u56DE\u5230\u6B64\u524D\uFF09{restore}\u3002",
90
76
  "noUserMessages": "\u5F53\u524D\u4F1A\u8BDD\u8FD8\u6CA1\u6709\u53EF\u56DE\u9000\u7684\u7528\u6237\u6D88\u606F\u3002",
91
- "command.description": "\u56DE\u9000\u5BF9\u8BDD\u548C/\u6216\u4EE3\u7801\u5230\u4E4B\u524D\u7684\u67D0\u6761\u6D88\u606F",
77
+ "command.description": "\u628A\u5BF9\u8BDD\u548C/\u6216\u6587\u4EF6\u56DE\u9000\u5230\u4E4B\u524D\u7684\u67D0\u6761\u6D88\u606F",
92
78
  "command.undoDescription": "/rewind \u7684\u522B\u540D",
93
79
  "engine.description": "dsh-rewind \u5185\u90E8\u547D\u4EE4",
94
80
  "engine.rejected": "\u5185\u90E8\u547D\u4EE4\uFF1A\u8BF7\u4F7F\u7528 /rewind \u6216 /undo\u3002",
@@ -182,14 +168,6 @@ function listRewindCandidates(events, surface, limit = DEFAULT_CANDIDATE_LIMIT)
182
168
  }
183
169
  return candidates;
184
170
  }
185
- var CANDIDATE_LIST_HEADER = "candidates=";
186
- function formatCandidateList(candidates) {
187
- const lines = [`${CANDIDATE_LIST_HEADER}${candidates.length}`];
188
- for (const candidate of candidates) {
189
- lines.push(`${candidate.seq} ${candidate.time} ${candidate.preview}`);
190
- }
191
- return lines.join("\n");
192
- }
193
171
  function planRewind(events, surface, target) {
194
172
  let targetSeq;
195
173
  if (target.kind === "seq") {
@@ -2319,6 +2297,7 @@ function shouldRunAutoSweep(lastAtMs, nowMs, intervalMs = AUTO_SWEEP_INTERVAL_MS
2319
2297
  var name = "dsh-rewind";
2320
2298
  var inject = ["commands", "tools", "settings"];
2321
2299
  var ENGINE_COMMAND = "rewind-plugin";
2300
+ var REWIND_RPC_CHANNEL = "/dsh-rewind";
2322
2301
  var DEFAULT_FILE_CHECKPOINTING_ENABLED = true;
2323
2302
  var Config = z.object({
2324
2303
  snapshotDir: z.string().required(false),
@@ -2357,7 +2336,7 @@ function t(key, params) {
2357
2336
  function warnCommandUnavailable(ctx, name2, error) {
2358
2337
  ctx.logger.warn(`[dsh-rewind] command "${name2}" was not registered: ${error instanceof Error ? error.message : String(error)}`);
2359
2338
  if (name2 === ENGINE_COMMAND) {
2360
- ctx.logger.warn(`[dsh-rewind] the internal "${ENGINE_COMMAND}" engine channel is unavailable; the rewind button and picker will not work.`);
2339
+ ctx.logger.warn(`[dsh-rewind] the internal "${ENGINE_COMMAND}" engine channel is unavailable; rewind execution will not work.`);
2361
2340
  }
2362
2341
  }
2363
2342
  async function discardCapture(capture) {
@@ -2489,31 +2468,6 @@ function formatBytes(bytes) {
2489
2468
  if (bytes >= 1024) return `${Math.round(bytes / 1024)} KiB`;
2490
2469
  return `${bytes} B`;
2491
2470
  }
2492
- function formatPlan(plan, files, uncovered = [], maxFileBytes = 0, checkpointingEnabled = true) {
2493
- const lines = [
2494
- t("plan.rewinding", { targetSeq: plan.targetSeq, count: plan.shadowedSeqs.length })
2495
- ];
2496
- if (files.length > 0) {
2497
- lines.push(t("plan.affects", { count: files.length }));
2498
- for (const file of files) {
2499
- lines.push(` ${file.action === "restore" ? t("plan.restore", { path: file.path }) : t("plan.delete", { path: file.path })}`);
2500
- }
2501
- } else {
2502
- lines.push(t("plan.noChanges"));
2503
- }
2504
- if (uncovered.length > 0) {
2505
- lines.push(t("uncovered.header", { count: uncovered.length, limit: formatBytes(maxFileBytes) }));
2506
- for (const file of uncovered.slice(0, 5)) lines.push(` ${file.path}`);
2507
- if (uncovered.length > 5) lines.push(" \u2026");
2508
- }
2509
- if (!checkpointingEnabled) lines.push(t("plan.backupOff"));
2510
- lines.push(`impact=${files.length}`);
2511
- for (const file of files) {
2512
- lines.push(`${file.action}:${file.path}`);
2513
- }
2514
- if (!checkpointingEnabled) lines.push("backup=off");
2515
- return lines.join("\n");
2516
- }
2517
2471
  function resolveOrError(events, surface, raw) {
2518
2472
  const target = parseRewindTarget(raw);
2519
2473
  if (target === void 0) {
@@ -2521,6 +2475,54 @@ function resolveOrError(events, surface, raw) {
2521
2475
  }
2522
2476
  return planRewind(events, surface, target);
2523
2477
  }
2478
+ async function previewImpact(store, session, seq, checkpointingEnabled) {
2479
+ const plan = resolveOrError(session.snapshotEvents(), session.surface.nodes, `@${seq}`);
2480
+ let impacts;
2481
+ try {
2482
+ impacts = await store.impactsAfter(session.id, plan.targetSeq);
2483
+ } catch (error) {
2484
+ if (!(error instanceof UnknownStoreVersionError)) throw error;
2485
+ throw new Error(t("storeUnsupported", { version: await store.readStoreVersion(session.id) ?? 0 }));
2486
+ }
2487
+ const uncovered = await store.uncoveredPaths(session.id).catch(() => []);
2488
+ return { files: impacts, uncovered, backupOff: !checkpointingEnabled };
2489
+ }
2490
+ function isRecord(value) {
2491
+ return typeof value === "object" && value !== null && !Array.isArray(value);
2492
+ }
2493
+ function rpcFailure(code, message) {
2494
+ return { ok: false, error: { code, message, details: {} } };
2495
+ }
2496
+ function createRewindRpcHandler(store, agentsOf, checkpointingEnabled) {
2497
+ return async (endpoint, payload) => {
2498
+ try {
2499
+ if (!isRecord(payload)) return rpcFailure("rewind/bad-request", "invalid payload");
2500
+ const sessionId = payload["sessionId"];
2501
+ if (typeof sessionId !== "string" || sessionId.length === 0) {
2502
+ return rpcFailure("rewind/bad-request", "sessionId must be a non-empty string");
2503
+ }
2504
+ const agents = agentsOf();
2505
+ if (agents === void 0) return rpcFailure("rewind/agents-unavailable", "agent registry is unavailable");
2506
+ const agent = agents.get(sessionId);
2507
+ if (agent === void 0) return rpcFailure("rewind/session-not-found", `session ${sessionId} is not attached`);
2508
+ const session = agent.session;
2509
+ if (endpoint === "preview") {
2510
+ const seq = payload["seq"];
2511
+ if (!Number.isSafeInteger(seq)) return rpcFailure("rewind/bad-request", "seq must be an integer");
2512
+ return { ok: true, value: await previewImpact(store, session, seq, checkpointingEnabled()) };
2513
+ }
2514
+ if (endpoint === "candidates") {
2515
+ return {
2516
+ ok: true,
2517
+ value: { candidates: listRewindCandidates(session.snapshotEvents(), session.surface.nodes) }
2518
+ };
2519
+ }
2520
+ return rpcFailure("rewind/unknown-endpoint", `unknown endpoint: ${endpoint}`);
2521
+ } catch (error) {
2522
+ return rpcFailure("rewind/failed", error instanceof Error ? error.message : String(error));
2523
+ }
2524
+ };
2525
+ }
2524
2526
  function renderFailures(failed) {
2525
2527
  if (failed.length === 0) return "";
2526
2528
  return t("failures.suffix", {
@@ -2678,29 +2680,6 @@ async function handleRewind(ctx, store, fs, invocation, inflight, checkpointingE
2678
2680
  return executeRewind(ctx, store, fs, invocation, `@${candidates[0].seq}`, "chat", inflight, checkpointingEnabled);
2679
2681
  }
2680
2682
  const parts = input.split(/\s+/);
2681
- if (parts[0] === "preview") {
2682
- const target2 = parts[1];
2683
- if (target2 === void 0) return { kind: "error", text: t("engine.rejected") };
2684
- let plan;
2685
- try {
2686
- plan = resolveOrError(session.snapshotEvents(), session.surface.nodes, target2);
2687
- } catch (error) {
2688
- return rewindErrorResult(error);
2689
- }
2690
- const impacts = await store.impactsAfter(session.id, plan.targetSeq).catch((error) => {
2691
- if (error instanceof UnknownStoreVersionError) return void 0;
2692
- throw error;
2693
- });
2694
- if (impacts === void 0) {
2695
- return { kind: "error", text: t("storeUnsupported", { version: await store.readStoreVersion(session.id) ?? 0 }) };
2696
- }
2697
- const uncovered = await store.uncoveredPaths(session.id).catch(() => []);
2698
- return { kind: "success", text: formatPlan(plan, impacts, uncovered, store.fileCapBytes, checkpointingEnabled) };
2699
- }
2700
- if (parts[0] === "__candidates") {
2701
- const candidates = listRewindCandidates(session.snapshotEvents(), session.surface.nodes);
2702
- return { kind: "success", text: formatCandidateList(candidates) };
2703
- }
2704
2683
  const target = parts[0];
2705
2684
  const mode = parts[1];
2706
2685
  if (mode !== void 0 && mode !== "chat" && mode !== "both") {
@@ -2978,6 +2957,23 @@ function apply(ctx, config) {
2978
2957
  }
2979
2958
  })();
2980
2959
  }, { global: true });
2960
+ ctx.inject(["connection"], (scope) => {
2961
+ try {
2962
+ const connection = scope.root.connection;
2963
+ if (connection === void 0) return;
2964
+ const dispose = connection.rpc.handle(
2965
+ REWIND_RPC_CHANNEL,
2966
+ createRewindRpcHandler(
2967
+ store,
2968
+ () => scope.get("agents"),
2969
+ () => isFileCheckpointingEnabled(config)
2970
+ )
2971
+ );
2972
+ scope.effect(() => dispose, "dsh-rewind RPC channel");
2973
+ } catch (error) {
2974
+ ctx.logger.warn(`[dsh-rewind] RPC channel registration failed: ${error instanceof Error ? error.message : String(error)}`);
2975
+ }
2976
+ });
2981
2977
  ctx.inject(["fs", "workingDirectory"], (scope) => {
2982
2978
  const fs = scope.fs;
2983
2979
  const workingDirectory = scope.workingDirectory;
@@ -75,15 +75,8 @@ export declare function rewindCandidatesOf(snap: CandidateChat, hidden: Readonly
75
75
  /** The candidates of a live chat snapshot, withdrawn rows already excluded. */
76
76
  export declare function rewindCandidatesOfChat(snap: CandidateChat): RewindCandidate[];
77
77
  /**
78
- * Parse the host's candidate-list encoding (see `formatCandidateList` in
79
- * src/rewind.ts) into typed candidates. Malformed lines are skipped; a
80
- * missing/zero header yields an empty list.
81
- */
82
- export declare function rewindCandidatesFromHostText(text: string): RewindCandidate[];
83
- /**
84
- * Map typed candidates to popupSelect rows (the host-derived path). The
85
- * popupSelect sources its options from the FULL host surface via the
86
- * `__candidates` channel instead of the windowed chat snapshot.
78
+ * Map typed candidates to popupSelect rows. The list comes from the host over
79
+ * RPC, so it covers the FULL host surface rather than the windowed chat snapshot.
87
80
  */
88
81
  export declare function rewindOptionsFromCandidates(candidates: readonly RewindCandidate[], t: Translate): SelectOption[];
89
82
  export {};
@@ -119,7 +119,7 @@ export interface MessageImageRef {
119
119
  export declare function messageAttachmentsAt(chat: HiddenChat | undefined, seq: number): readonly MessageImageRef[] | undefined;
120
120
  /**
121
121
  * Extract the rewind target seq from a `/rewind` command's structured `args`
122
- * (e.g. `@5 chat`, `preview @5 both`). Locale-independent — never parses the
122
+ * (e.g. `@5 chat`). Locale-independent — never parses the
123
123
  * host's human outcome copy.
124
124
  */
125
125
  export declare function targetSeqOfArgs(args: string | null | undefined): number | undefined;
@@ -132,28 +132,14 @@ export declare function targetSeqOfArgs(args: string | null | undefined): number
132
132
  */
133
133
  export declare function isExecutedRewindCommand(node: CommandNode, seq: number): boolean;
134
134
  /**
135
- * Whether a preview outcome reports tracked file changes — the availability
136
- * of the "rewind conversation and code" option (Claude Code hides the
137
- * code-restore options when the checkpoint has no tracked changes).
138
- *
139
- * Reads ONLY the machine-readable `impact=<n>` trailer the host appends to
140
- * preview text. Older host output without the trailer is treated as having no
141
- * changes (never guesses from human copy). Absent text (undefined) degrades to
142
- * always-show so a working option is never hidden on a failed probe.
143
- */
144
- export declare function hasFileImpact(text: string | undefined): boolean;
145
- /** Whether the preview reports that new file checkpoints are disabled. */
146
- export declare function hasBackupDisabled(text: string | undefined): boolean;
147
- /**
148
- * True when an engine command node is the internal candidate-list probe
149
- * (`__candidates`) the popupSelect runs to fetch the FULL candidate
150
- * list from the host. Like previews, its flow node never surfaces in the
151
- * transcript — it only feeds the popup — so it is hidden in every state.
135
+ * True when an engine command node is a legacy candidate-list probe
136
+ * (`__candidates`). New candidate lists travel over RPC; this only keeps
137
+ * probe rows in historical sessions hidden.
152
138
  */
153
139
  export declare function isCandidateCommand(command: CommandNode): boolean;
154
140
  /**
155
141
  * Anchor seqs that must be hidden from the rendered transcript so the user sees
156
- * the conversation as the agent sees it: every impact-preview flow node (it only
142
+ * the conversation as the agent sees it: every legacy probe flow node (it only
157
143
  * exists to feed the popover) and every SUCCESSFUL executed `/rewind` command
158
144
  * row, plus every message a rewind withdrew — the target, everything after it,
159
145
  * and the (unrendered) marker.
@@ -0,0 +1,45 @@
1
+ /**
2
+ * The browser half of the rewind RPC channel: the mode popover's impact
3
+ * preview and the `/rewind` candidate list. Both are read-only host queries,
4
+ * so they travel over Connection RPC instead of the human command channel.
5
+ *
6
+ * @module dsh-rewind/client/host-rpc
7
+ */
8
+ import type { RewindCandidate } from './candidates.ts';
9
+ /** One file affected by a rewind. */
10
+ export interface PreviewFileImpact {
11
+ readonly path: string;
12
+ readonly action: 'restore' | 'delete';
13
+ }
14
+ /** One impact probe resolved, failed, or timed out (`null`). */
15
+ export type PreviewOutcome = {
16
+ readonly kind: 'success';
17
+ readonly files: readonly PreviewFileImpact[];
18
+ readonly backupOff: boolean;
19
+ } | {
20
+ readonly kind: 'error';
21
+ readonly text: string;
22
+ } | null;
23
+ /** Fetch one target's impact through the registered RPC call. */
24
+ export type PreviewCall = (sessionId: string, seq: number) => Promise<PreviewOutcome>;
25
+ type RpcResult = {
26
+ readonly ok: true;
27
+ readonly value: unknown;
28
+ } | {
29
+ readonly ok: false;
30
+ readonly error: {
31
+ readonly code: string;
32
+ readonly message: string;
33
+ };
34
+ };
35
+ /** The slice of the client `connection` service this module reads. */
36
+ export interface ConnectionLike {
37
+ readonly rpc: {
38
+ call(channel: string, endpoint: string, payload: unknown, signal?: AbortSignal): Promise<RpcResult>;
39
+ };
40
+ }
41
+ /** Resolve one target's file impact over RPC. */
42
+ export declare function previewOverRpc(connection: ConnectionLike | undefined, sessionId: string, seq: number): Promise<PreviewOutcome>;
43
+ /** Fetch the full rewind candidate list over RPC. */
44
+ export declare function candidatesOverRpc(connection: ConnectionLike | undefined, sessionId: string): Promise<readonly RewindCandidate[] | undefined>;
45
+ export {};
@@ -8,9 +8,9 @@
8
8
  * so the plugin imports no conversation UI types and survives harness drift.
9
9
  * The command decoration (`ctx.commandUi.decorate`) makes a bare `/rewind` (or
10
10
  * its alias `/undo`) open the harness's own popupSelect instead of executing;
11
- * the parameterized `@<seq>` / `preview` forms stay internal channels the
12
- * button and the popover drive. The exported contract is specified in
13
- * `docs/contract/client-contract.md`.
11
+ * the parameterized `@<seq>` form stays the execution channel, while the
12
+ * popover's impact and candidate reads go over the host RPC channel. The
13
+ * exported contract is specified in `docs/contract/client-contract.md`.
14
14
  *
15
15
  * @module dsh-rewind/client
16
16
  */
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * The rewind mode-selection popover (plain DOM, no React). Step two of the
3
3
  * interaction: the target is already fixed (the clicked message); the popover
4
- * offers the two modes. Choosing "both" first fetches the impact list through
5
- * the engine channel's `preview @seq both` command and shows it before confirming.
4
+ * offers the two modes. Choosing "both" fetches the impact list over the host
5
+ * RPC channel and shows it before confirming.
6
6
  *
7
7
  * Keyboard: ↑/↓ move focus across the step's ACTION buttons only (the two
8
8
  * modes, or the confirm button on the impact step), Enter activates the
@@ -15,7 +15,8 @@
15
15
  */
16
16
  import type { SessionFace } from '@deepseek-ai/dsh-api-session-controller/client';
17
17
  import type { CommandNode } from '@deepseek-ai/dsh-client-ui-conversation/client';
18
- import { type ChatOf, type ChatWatch } from './hidden.ts';
18
+ import { type ChatOf } from './hidden.ts';
19
+ import type { PreviewCall } from './host-rpc.ts';
19
20
  import type { RewindKey } from './locales.ts';
20
21
  type Translate = (key: RewindKey, params?: Record<string, unknown>) => string;
21
22
  export interface PopoverOptions {
@@ -32,18 +33,6 @@ export interface PopoverOptions {
32
33
  /** Pending variant: executed after the retract confirm closes the popover. */
33
34
  readonly onRetract?: () => void;
34
35
  readonly preview: string;
35
- /**
36
- * Chat reader on the `uiConversation` "chat" view: the durable
37
- * variant's command probes scan the chat through it. Unused by the
38
- * pending-retract variant.
39
- */
40
- readonly chatOf: ChatOf;
41
- /**
42
- * Subscribe to one session's live chat-update signal, so a probe waiting on
43
- * a command's chat node can be woken when the chat snapshot changes. Passed
44
- * straight through to `waitForCommand`.
45
- */
46
- readonly watchChat: ChatWatch;
47
36
  /** The button that opened the popover (outside-click ignore target). */
48
37
  readonly anchor: HTMLElement;
49
38
  readonly t: Translate;
@@ -64,9 +53,8 @@ export declare function closePopover(): void;
64
53
  /**
65
54
  * Seqs of the command nodes currently matching `match`. Sample BEFORE issuing
66
55
  * a new command of the same shape so the subsequent wait can exclude them: a
67
- * repeated preview/rewind of the same target must not settle on the previous
68
- * command's stale outcome (e.g. an older preview that found file changes,
69
- * after those changes were already restored).
56
+ * repeated rewind of the same target must not settle on the previous command's
57
+ * stale outcome.
70
58
  */
71
59
  export declare function knownCommandSeqs(session: SessionFace, chatOf: ChatOf, match: (node: CommandNode) => boolean): Set<number>;
72
60
  /**
@@ -78,6 +66,8 @@ export declare function waitForCommand(session: SessionFace, chatOf: ChatOf, mat
78
66
  kind: 'success' | 'error';
79
67
  text?: string;
80
68
  } | null>;
69
+ /** Register the host RPC preview call (null clears it on unload). */
70
+ export declare function registerPreviewCall(call: PreviewCall | null): void;
81
71
  /** Open the mode-selection popover anchored near the given button. */
82
72
  export declare function openPopover(opts: PopoverOptions): void;
83
73
  export {};
@@ -32,4 +32,4 @@ export declare const CLASS: {
32
32
  */
33
33
  export declare const REWIND_ICON_SVG: string;
34
34
  /** One injected stylesheet (scoped under `.dsh-rewind-*`). */
35
- export declare const STYLE = "\n.dsh-rewind-btn {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n /* The neighbouring action buttons scale by this delta too. */\n width: calc(28px + var(--dsh-content-font-delta, 0px));\n height: calc(28px + var(--dsh-content-font-delta, 0px));\n padding: 6px;\n border: none;\n border-radius: var(--dsw-radius-sm, 8px);\n background: transparent;\n color: var(--dsw-alias-label-tertiary);\n cursor: pointer;\n}\n.dsh-rewind-btn svg {\n width: calc(15px + var(--dsh-content-font-delta, 0px));\n height: calc(15px + var(--dsh-content-font-delta, 0px));\n}\n.dsh-rewind-btn:hover {\n background: var(--dsw-alias-interactive-bg-hover);\n color: var(--dsw-alias-label-secondary);\n}\n\n.dsh-rewind-popover {\n position: fixed;\n z-index: 1000;\n width: 288px;\n padding: 12px;\n border: 1px solid var(--dsw-alias-border-l2);\n border-radius: 12px;\n background: var(--dsw-specific-menu, var(--dsw-alias-bg-layer-3));\n box-shadow: var(--dsw-shadow-lv3);\n font-size: 14px;\n line-height: 20px;\n color: var(--dsw-alias-label-primary);\n}\n.dsh-rewind-popover-title {\n font-size: 14px;\n font-weight: 600;\n line-height: 20px;\n}\n.dsh-rewind-popover-target {\n margin: 4px 0 10px;\n font-size: 12px;\n line-height: 16px;\n color: var(--dsw-alias-label-tertiary);\n word-break: break-all;\n}\n.dsh-rewind-popover-option {\n display: flex;\n flex-direction: column;\n gap: 2px;\n width: 100%;\n margin: 0 0 6px;\n padding: 8px 10px;\n border: 1px solid transparent;\n border-radius: 8px;\n background: transparent;\n color: inherit;\n font: inherit;\n text-align: left;\n cursor: pointer;\n}\n.dsh-rewind-popover-option:hover {\n background: var(--dsw-alias-interactive-bg-hover);\n}\n/* Arrow navigation moves real focus, so the focused row carries the pointer's\n fill and the browser ring is suppressed: in dark mode the UA two-tone ring\n draws its dark half against the filled row and reads as a residue edge (the\n harness Menu suppresses it the same way). */\n.dsh-rewind-popover-option:focus-visible:not(:disabled) {\n background: var(--dsw-alias-interactive-bg-hover);\n outline: none;\n}\n.dsh-rewind-popover-option:disabled {\n opacity: 0.5;\n cursor: default;\n}\n.dsh-rewind-popover-option-label {\n font-weight: 500;\n}\n.dsh-rewind-popover-option-hint {\n font-size: 12px;\n line-height: 16px;\n color: var(--dsw-alias-label-tertiary);\n}\n.dsh-rewind-popover-impact {\n margin: 4px 0 10px;\n padding: 8px 10px;\n border-radius: 8px;\n background: var(--dsw-alias-interactive-bg-hover);\n font-size: 12px;\n line-height: 16px;\n color: var(--dsw-alias-label-secondary);\n white-space: pre-wrap;\n max-height: 160px;\n overflow: auto;\n}\n.dsh-rewind-popover-note {\n margin-top: 6px;\n font-size: 11px;\n line-height: 15px;\n color: var(--dsw-alias-label-tertiary);\n}\n.dsh-rewind-popover-actions {\n display: flex;\n justify-content: flex-end;\n gap: 8px;\n}\n.dsh-rewind-popover-primary,\n.dsh-rewind-popover-ghost {\n padding: 5px 12px;\n border: none;\n border-radius: 8px;\n font: inherit;\n font-size: 13px;\n line-height: 18px;\n cursor: pointer;\n}\n.dsh-rewind-popover-primary {\n background: var(--dsw-alias-button-primary-fill);\n color: var(--dsw-alias-label-primary-foreground);\n}\n.dsh-rewind-popover-primary:hover:not(:disabled) {\n background: var(--dsw-alias-button-primary-hover);\n}\n.dsh-rewind-popover-primary:disabled {\n opacity: 0.5;\n cursor: default;\n}\n.dsh-rewind-popover-ghost {\n background: transparent;\n color: var(--dsw-alias-label-secondary);\n}\n.dsh-rewind-popover-ghost:hover {\n background: var(--dsw-alias-interactive-bg-hover);\n}\n\n.dsh-rewind-guard-hint {\n position: fixed;\n z-index: 1000;\n max-width: min(440px, calc(100vw - 24px));\n padding: 8px 12px;\n border: 1px solid var(--dsw-alias-border-l2);\n border-radius: 10px;\n background: var(--dsw-specific-menu, var(--dsw-alias-bg-layer-3));\n box-shadow: var(--dsw-shadow-lv3);\n font-size: 13px;\n line-height: 18px;\n color: var(--dsw-alias-label-primary);\n pointer-events: none;\n}\n\n/* ---- Plugin configuration form ---- */\n/* Only the card's own controls: the two switch rows, their hints, and the divider. */\n.dsh-rewind-settings-divider {\n border-top: 1px solid var(--dsw-alias-border-l2);\n}\n.dsh-rewind-settings-section {\n display: grid;\n gap: 6px;\n padding: 12px 0;\n}\n.dsh-rewind-settings-toggle-row {\n display: flex;\n align-items: flex-start;\n justify-content: space-between;\n gap: 16px;\n font-size: 13px;\n line-height: 1.5;\n color: var(--dsw-alias-label-primary);\n}\n.dsh-rewind-settings-toggle-label {\n flex: 1;\n min-width: 0;\n}\n.dsh-rewind-settings-hint {\n margin: 0;\n font-size: 12px;\n line-height: 1.5;\n color: var(--dsw-alias-label-tertiary);\n}\n";
35
+ export declare const STYLE = "\n.dsh-rewind-btn {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n /* The neighbouring action buttons scale by this delta too. */\n width: calc(28px + var(--dsh-content-font-delta, 0px));\n height: calc(28px + var(--dsh-content-font-delta, 0px));\n padding: 6px;\n border: none;\n border-radius: var(--dsw-radius-sm, 8px);\n background: transparent;\n color: var(--dsw-alias-label-tertiary);\n cursor: pointer;\n}\n.dsh-rewind-btn svg {\n width: calc(15px + var(--dsh-content-font-delta, 0px));\n height: calc(15px + var(--dsh-content-font-delta, 0px));\n}\n@media (hover: hover) {\n .dsh-rewind-btn:hover {\n background: var(--dsw-alias-interactive-bg-hover);\n color: var(--dsw-alias-label-secondary);\n }\n}\n\n.dsh-rewind-popover {\n position: fixed;\n z-index: 1100;\n box-sizing: border-box;\n width: min(300px, calc(100vw - 24px));\n padding: 16px;\n border: 0;\n border-radius: var(--dsw-radius-lg);\n background: var(--dsw-specific-menu, var(--dsw-alias-bg-layer-3));\n backdrop-filter: var(--dsw-menu-backdrop-filter);\n isolation: isolate;\n --dsw-elevation-stroke-color: var(--dsw-alias-border-l1);\n /* Elevated surface: match the menu cards' l2 scrollbar tokens. */\n --dsh-scrollbar-thumb: var(--dsw-alias-scrollbar-bg-l2);\n --dsh-scrollbar-thumb-hover: var(--dsw-alias-scrollbar-hover-l2);\n box-shadow: var(--dsw-elevation-prominent);\n font-size: 12px;\n line-height: 18px;\n color: var(--dsw-alias-label-primary);\n}\n.dsh-rewind-popover-title {\n font-size: 12px;\n font-weight: 500;\n line-height: 18px;\n}\n.dsh-rewind-popover-target {\n margin: 2px 0 10px;\n font-size: 12px;\n line-height: 18px;\n color: var(--dsw-alias-label-tertiary);\n word-break: break-all;\n /* The full message sits above the popover; two lines are enough context. */\n display: -webkit-box;\n -webkit-box-orient: vertical;\n -webkit-line-clamp: 2;\n overflow: hidden;\n}\n.dsh-rewind-popover-option {\n display: flex;\n flex-direction: column;\n gap: 2px;\n width: 100%;\n margin: 0 0 2px;\n padding: 6px 8px;\n border: 0;\n border-radius: 8px;\n background: transparent;\n color: inherit;\n font: inherit;\n text-align: left;\n cursor: pointer;\n}\n.dsh-rewind-popover-option:hover {\n background: var(--dsw-alias-interactive-bg-hover);\n}\n/* Arrow navigation moves real focus, so the focused row carries the pointer's\n fill and the browser ring is suppressed: in dark mode the UA two-tone ring\n draws its dark half against the filled row and reads as a residue edge (the\n harness Menu suppresses it the same way). */\n.dsh-rewind-popover-option:focus-visible:not(:disabled) {\n background: var(--dsw-alias-interactive-bg-hover);\n outline: none;\n}\n.dsh-rewind-popover-option:disabled {\n opacity: 0.4;\n cursor: default;\n}\n.dsh-rewind-popover-option-label {\n font-weight: 500;\n}\n.dsh-rewind-popover-option-hint {\n font-size: 12px;\n line-height: 16px;\n color: var(--dsw-alias-label-tertiary);\n}\n.dsh-rewind-popover-impact {\n margin: 4px 0 10px;\n padding: 8px 10px;\n border-radius: 8px;\n background: var(--dsw-alias-interactive-bg-hover);\n font-size: 12px;\n line-height: 16px;\n color: var(--dsw-alias-label-secondary);\n white-space: pre-wrap;\n max-height: 160px;\n overflow: auto;\n}\n.dsh-rewind-popover-note {\n margin-top: 6px;\n font-size: 11px;\n line-height: 15px;\n color: var(--dsw-alias-label-tertiary);\n}\n.dsh-rewind-popover-actions {\n display: flex;\n justify-content: flex-end;\n gap: 8px;\n margin-top: 8px;\n}\n.dsh-rewind-popover-primary,\n.dsh-rewind-popover-ghost {\n height: 28px;\n padding: 0 10px;\n border: none;\n border-radius: 8px;\n font: inherit;\n cursor: pointer;\n}\n.dsh-rewind-popover-primary {\n background: var(--dsw-alias-button-primary-fill);\n color: var(--dsw-alias-label-primary-foreground);\n}\n.dsh-rewind-popover-primary:hover:not(:disabled) {\n background: var(--dsw-alias-button-primary-hover);\n}\n.dsh-rewind-popover-primary:disabled {\n opacity: 0.4;\n cursor: default;\n}\n.dsh-rewind-popover-ghost {\n background: transparent;\n color: var(--dsw-alias-label-secondary);\n}\n.dsh-rewind-popover-ghost:hover {\n background: var(--dsw-alias-interactive-bg-hover);\n}\n.dsh-rewind-popover-ghost:active {\n background: var(--dsw-alias-interactive-bg-active);\n}\n\n.dsh-rewind-guard-hint {\n position: fixed;\n z-index: 1000;\n max-width: min(440px, calc(100vw - 24px));\n padding: 8px 12px;\n border: 0;\n border-radius: var(--dsw-radius-md);\n background: var(--dsw-specific-menu, var(--dsw-alias-bg-layer-3));\n backdrop-filter: var(--dsw-menu-backdrop-filter);\n isolation: isolate;\n --dsw-elevation-stroke-color: var(--dsw-alias-border-l1);\n box-shadow: var(--dsw-elevation-panel);\n font-size: 13px;\n line-height: 18px;\n color: var(--dsw-alias-label-primary);\n pointer-events: none;\n}\n\n/* ---- Plugin configuration form ---- */\n/* Only the card's own controls: the two switch rows, their hints, and the divider. */\n.dsh-rewind-settings-divider {\n border-top: 1px solid var(--dsw-alias-border-l2);\n}\n.dsh-rewind-settings-section {\n display: grid;\n gap: 6px;\n padding: 12px 0;\n}\n.dsh-rewind-settings-toggle-row {\n display: flex;\n align-items: flex-start;\n justify-content: space-between;\n gap: 16px;\n font-size: 13px;\n line-height: 1.5;\n color: var(--dsw-alias-label-primary);\n}\n.dsh-rewind-settings-toggle-label {\n flex: 1;\n min-width: 0;\n}\n.dsh-rewind-settings-hint {\n margin: 0;\n font-size: 12px;\n line-height: 1.5;\n color: var(--dsw-alias-label-tertiary);\n}\n";
@@ -4,8 +4,8 @@
4
4
  * lives in `src/client/`).
5
5
  *
6
6
  * Rewind mechanism: planning is pure (`src/rewind.ts`); execution appends a
7
- * marker `user/message` whose `surfaceOp` replaces every surface node after the
8
- * target with itself, cutting only the model-visible surface
7
+ * marker `user/message` whose `surfaceOp` replaces the target and every surface
8
+ * node after it with itself, cutting only the model-visible surface
9
9
  * (`docs/architecture.md`).
10
10
  *
11
11
  * File restore (mode `both`) follows Claude Code's checkpointing: unless
@@ -15,9 +15,8 @@
15
15
  * public read the settings UI and the client's own locale runtime perform.
16
16
  *
17
17
  * The client half (`src/client/locales.ts`) owns all interactive UI copy via
18
- * `ctx.locale` + `t()`; the host's human text is a machine channel the client
19
- * renders through machine tokens (`impact=<n>`, `args` @seq), never by parsing
20
- * host prose.
18
+ * `ctx.locale` + `t()`; the client never parses host prose (the popover reads
19
+ * travel over the RPC channel).
21
20
  *
22
21
  * DSH localizes only its OWN command descriptions via the client locale — a
23
22
  * closed `HOST_FACES` allowlist; third-party plugin descriptions are
@@ -45,15 +44,8 @@ export type HostLocaleId = 'zh' | 'en';
45
44
  export declare function preferredLocale(preference: unknown): HostLocaleId;
46
45
  /** English dictionary — the key-set source of truth (neutral default). */
47
46
  export declare const en: {
48
- 'plan.rewinding': string;
49
- 'plan.affects': string;
50
- 'plan.restore': string;
51
- 'plan.delete': string;
52
- 'plan.noChanges': string;
53
- 'plan.backupOff': string;
54
47
  'plan.skip': string;
55
48
  'skipReason.oversized': string;
56
- 'uncovered.header': string;
57
49
  'error.invalidTarget': string;
58
50
  'sep.list': string;
59
51
  'sep.clause': string;
@@ -4,10 +4,10 @@
4
4
  * and the ordered surface, so this module stays unit-testable.
5
5
  *
6
6
  * Rewind semantics: rewinding to a user message appends a marker node into the
7
- * session log whose `surfaceOp` replaces every surface node AFTER the target
8
- * with itself. The log (audit trail, rendered transcript) is untouched; only
9
- * the model-visible surface is cut, so the next request derives its context
10
- * from the target message onward. The marker is a `user/message` carrying a
7
+ * session log whose `surfaceOp` replaces the target and every surface node
8
+ * after it with itself. The log (audit trail, rendered transcript) is
9
+ * untouched; only the model-visible surface is cut, so the next request
10
+ * derives its context from before the target message. The marker is a `user/message` carrying a
11
11
  * replace `surfaceOp` and the producer-owned source `{ kind: 'dsh-rewind' }`
12
12
  * (see `marker.ts`); the shape's invariants and history are documented in
13
13
  * `docs/architecture.md`.
@@ -51,13 +51,13 @@ export interface RewindCandidate {
51
51
  }
52
52
  /** A validated rewind: the target plus the exact surface range to shadow. */
53
53
  export interface RewindPlan {
54
- /** Target user message seq (stays on the surface). */
54
+ /** Target user message seq (withdrawn with the surface range). */
55
55
  readonly targetSeq: number;
56
56
  /** The target's ordered position in the surface. */
57
57
  readonly targetIndex: number;
58
- /** Ordered surface node seqs the rewind shadows (everything after the target). */
58
+ /** Ordered surface node seqs the rewind shadows (the target and everything after it). */
59
59
  readonly shadowedSeqs: readonly number[];
60
- /** First surface node after the target — the replace range start (inclusive). */
60
+ /** The target — the replace range start (inclusive). */
61
61
  readonly surfaceStart: number;
62
62
  /** Last surface node — the replace range end (inclusive). */
63
63
  readonly surfaceEnd: number;
@@ -106,23 +106,6 @@ export declare function parseRewindTarget(raw: string): RewindTarget | undefined
106
106
  * @returns candidates numbered 1..N by recency.
107
107
  */
108
108
  export declare function listRewindCandidates(events: readonly SessionEvent[], surface: readonly number[], limit?: number): RewindCandidate[];
109
- /** Header line of the machine-readable candidate list (locale-independent). */
110
- export declare const CANDIDATE_LIST_HEADER = "candidates=";
111
- /**
112
- * Encode a candidate list as the host→client machine channel (the same
113
- * trailer pattern `formatPlan` uses for `impact=`). The client popupSelect
114
- * parses this instead of reading the windowed chat snapshot, so the candidate
115
- * list reflects the FULL host surface — not just the already-loaded history.
116
- *
117
- * Lines (each preview is already whitespace-collapsed and tab-free by
118
- * `messagePreview`):
119
- * candidates=<n>
120
- * <seq>\t<time>\t<preview>
121
- * … (one line per candidate, newest first, matching `listRewindCandidates`)
122
- *
123
- * A list with no candidates is just `candidates=0`.
124
- */
125
- export declare function formatCandidateList(candidates: readonly RewindCandidate[]): string;
126
109
  /**
127
110
  * Resolve a target against the session log and surface into a validated plan.
128
111
  * @param events - the full session event log.
@@ -179,7 +179,7 @@ export interface LinkEntry {
179
179
  export type StoredEntry = CheckpointEntry | LinkEntry;
180
180
  /** True when an entry is a dedup link (carries `ref`, not `before`). */
181
181
  export declare function isLinkEntry(entry: StoredEntry): entry is LinkEntry;
182
- /** Per-file restore impact preview (`/rewind preview @seq both`). */
182
+ /** Per-file restore impact preview (served by the host RPC channel). */
183
183
  export interface FileImpact {
184
184
  readonly path: string;
185
185
  /** `restore` = write the before content back; `delete` = remove the file. */