From 97c8824dffde83db5559a249f0f10924d550b3cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=AB=E6=88=91=E5=B0=8F=E6=9D=A8=E5=90=8C=E5=AD=A6?= <188421097+HunYiSage@users.noreply.github.com> Date: Thu, 24 Sep 2026 15:54:29 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=9B=9E=E9=80=80=E5=88=87=E5=88=B0?= =?UTF-8?q?=E6=96=B0=E4=BC=9A=E8=AF=9D=EF=BC=8C=E9=80=82=E9=85=8D=20dsh=20?= =?UTF-8?q?0.1.7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 0.1.7 去掉了 sessions.open,回退建好会话后界面不切换。改走 uiWorkspace.openSession,失败显示在按钮上。 Co-authored-by: Cursor --- client.js | 102 ++++++++++++++++++++++++++++++++++++++--------- release-notes.md | 2 + 2 files changed, 86 insertions(+), 18 deletions(-) diff --git a/client.js b/client.js index 2d76809..713c8ef 100644 --- a/client.js +++ b/client.js @@ -2129,7 +2129,7 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => { .dshp-rewind:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover,rgba(127,127,127,.12));color:var(--dsw-alias-label-primary,currentColor)} .dshp-rewind:disabled{opacity:.4;cursor:default} .dshp-rewind svg{display:block} -.dshp-rewind-menu{position:absolute;right:0;bottom:calc(100% + 6px);z-index:100;box-sizing:border-box;min-width:196px;padding:4px;border:0;border-radius:12px;background:var(--dsw-specific-menu,#fff);color:var(--dsw-alias-label-primary,#1a1a1a);--dsw-elevation-stroke-color:var(--dsw-alias-border-l1);box-shadow:var(--dsw-elevation-prominent,0 8px 24px rgba(0,0,0,.16))} +.dshp-rewind-menu{position:absolute;right:0;bottom:calc(100% + 6px);z-index:1200;box-sizing:border-box;min-width:196px;padding:4px;border:0;border-radius:12px;background:var(--dsw-specific-menu,#fff);color:var(--dsw-alias-label-primary,#1a1a1a);--dsw-elevation-stroke-color:var(--dsw-alias-border-l1);box-shadow:var(--dsw-elevation-prominent,0 8px 24px rgba(0,0,0,.16))} body[data-ds-dark-theme] .dshp-rewind-menu{background:var(--dsw-specific-menu,#32312d);color:var(--dsw-alias-label-primary,#e6e2db);--dsw-elevation-stroke-color:var(--dsw-alias-border-l1,#3f3d38);box-shadow:var(--dsw-elevation-prominent,0 10px 28px rgba(0,0,0,.45))} .dshp-rewind-item{display:flex;flex-direction:column;gap:2px;width:100%;padding:8px 10px;border:0;border-radius:8px;background:transparent;color:inherit;text-align:left;cursor:pointer;font:12px/1.3 var(--ds-font-sans,system-ui,sans-serif)} .dshp-rewind-item:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(127,127,127,.12))} @@ -2144,11 +2144,13 @@ body[data-ds-dark-theme] .dshp-rewind-item span{color:var(--dsw-alias-label-tert `; const DRAFT_KEY = "dshp-rewind-draft:"; const ARM_KEY = "dshp-rewind-arm:"; - const FILL_DELAYS = [0, 50, 180]; + const FILL_DELAYS = [0, 50, 180, 400, 800]; const ARM_TTL_MS = 45 * 1000; let rewindSeenAt = 0; let rewindSessions = null; let rewindHost = null; + let rewindWorkspace = null; + let rewindConversation = null; let pendingComposer = { sessionId: "", text: "", at: 0 }; let armedFill = { sessionId: "", text: "", at: 0 }; @@ -2163,7 +2165,29 @@ body[data-ds-dark-theme] .dshp-rewind-item span{color:var(--dsw-alias-label-tert } function currentSessionId(sessions) { - try { return sessions?.list?.getSnapshot?.()?.current || ""; } catch { return ""; } + try { + const selected = rewindWorkspace?.selection?.getSnapshot?.()?.sessionId; + if (typeof selected === "string" && selected) return selected; + } catch { /* ignore */ } + try { + const snap = sessions?.list?.getSnapshot?.(); + if (typeof snap?.current === "string" && snap.current) return snap.current; + } catch { /* ignore */ } + return ""; + } + + function sessionKnown(sessions, sessionId) { + try { + const snap = sessions?.list?.getSnapshot?.(); + if (!snap || !sessionId) return false; + if (snap.byId && Object.prototype.hasOwnProperty.call(snap.byId, sessionId)) return true; + if (Array.isArray(snap.ids) && snap.ids.includes(sessionId)) return true; + } catch { /* ignore */ } + return false; + } + + function waitMs(ms) { + return new Promise((resolve) => window.setTimeout(resolve, ms)); } function isPluginDraft(text) { @@ -2222,14 +2246,27 @@ body[data-ds-dark-theme] .dshp-rewind-item span{color:var(--dsw-alias-label-tert return text; } + function conversationFace() { + if (rewindConversation) return rewindConversation; + const host = rewindHost; + if (host?.conversation) return host.conversation; + if (typeof host?.get === "function") { + try { return host.get("conversation"); } catch { return undefined; } + } + return undefined; + } + function conversationInput(sessionId) { try { - const host = rewindHost; - const conversation = host?.conversation || (typeof host?.get === "function" ? host.get("conversation") : undefined); - const sessions = host?.sessions || rewindSessions; + const input = conversationFace()?.input; + if (!input || !sessionId) return null; + if (typeof input.shell === "function") { + try { return input.shell(sessionId); } catch { /* session not retained yet */ } + } + const sessions = rewindHost?.sessions || rewindSessions; const actx = typeof sessions?.scope === "function" ? sessions.scope(sessionId) : undefined; - if (conversation?.input?.for && actx) return conversation.input.for(actx); - return conversation?.input || null; + if (typeof input.for === "function" && actx) return input.for(actx); + return null; } catch { return null; } @@ -2331,14 +2368,36 @@ body[data-ds-dark-theme] .dshp-rewind-item span{color:var(--dsw-alias-label-tert } async function openRewoundSession(sessions, sessionId) { - if (!sessions || !sessionId) return; - try { await sessions.refresh?.(); } catch { /* ignore */ } - try { sessions.open(sessionId); } catch { /* ignore */ } - await dropInheritedQueue(sessions, sessionId); - window.setTimeout(() => { - try { sessions.open(sessionId); } catch { /* ignore */ } - dropInheritedQueue(sessions, sessionId); - }, 250); + if (!sessionId) return; + const workspace = rewindWorkspace; + let lastError = null; + for (let attempt = 0; attempt < 25; attempt += 1) { + if (sessions && typeof sessions.refresh === "function" && !sessionKnown(sessions, sessionId)) { + try { await sessions.refresh(); } catch (error) { lastError = error; } + } + const known = sessionKnown(sessions, sessionId); + if (known || typeof sessions?.open === "function") { + try { + if (workspace && typeof workspace.openSession === "function") { + workspace.openSession(sessionId); + } else if (typeof sessions?.open === "function") { + sessions.open(sessionId); + } else { + throw new Error("无法打开回退后的会话"); + } + const selected = workspace?.selection?.getSnapshot?.()?.sessionId; + if (!workspace || selected === sessionId) { + await dropInheritedQueue(sessions, sessionId); + window.setTimeout(() => { dropInheritedQueue(sessions, sessionId); }, 250); + return; + } + } catch (error) { + lastError = error; + } + } + await waitMs(120); + } + throw new Error((lastError && lastError.message) || "回退后的会话没有打开"); } class RewindSafe extends Component { @@ -2564,7 +2623,12 @@ body[data-ds-dark-theme] .dshp-rewind-item span{color:var(--dsw-alias-label-tert } }; - const label = busy ? rewindText(t, "rewind.busy", "回退中…") : rewindText(t, "rewind.label", "回退"); + const failLabel = notice + ? (notice.length > 18 ? notice.slice(0, 18) + "…" : notice) + : ""; + const label = busy + ? rewindText(t, "rewind.busy", "回退中…") + : (failLabel || rewindText(t, "rewind.label", "回退")); const title = notice || rewindText(t, "rewind.aria", "回退"); return h("div", { className: "dshp-rewind-wrap", ref: wrapRef }, h("style", null, REWIND_CSS), @@ -2632,6 +2696,8 @@ body[data-ds-dark-theme] .dshp-rewind-item span{color:var(--dsw-alias-label-tert function installRewindUi(ctx) { rewindHost = ctx; rewindSessions = ctx.sessions; + rewindWorkspace = ctx.uiWorkspace || null; + rewindConversation = ctx.conversation || null; ctx.slots.inject("conversation.input.right", () => ctx.slots.register({ name: "conversation.input.right", id: "dsh-purge-rewind", @@ -2667,7 +2733,7 @@ body[data-ds-dark-theme] .dshp-rewind-item span{color:var(--dsw-alias-label-tert }, SettingsRoot)); try { if (typeof ctx.inject === "function") { - ctx.inject(["sessions"], (host) => installRewindUi(host)); + ctx.inject(["sessions", "uiWorkspace", "conversation"], (host) => installRewindUi(host)); } else if (ctx.sessions) { installRewindUi(ctx); } diff --git a/release-notes.md b/release-notes.md index a62c9fd..1512645 100644 --- a/release-notes.md +++ b/release-notes.md @@ -10,6 +10,7 @@ - Web 四个内置预设(standard、ptc、cordis、minimal)只清空身份句。工作目录、工具列表、`ptc` 模式,以及 minimal 的 `complete: true` 和 `includeRuntimeContext: false` 不动。 - `complete: true` 时,`prompt-inject.md` 仍接在这段前面。换宿主版本或旧钩子删段之后,注入不会丢。点「应用」之后仍要再点「重启」,新开一轮对话才进当前会话。 - `dsh-compaction-instant` 网页端从已删除的 `settingsScope` 改到 `configForms`,页面不再停在 Failed to load plugins。 +- 回退在 0.1.7 上会建出新会话,但界面仍停在旧对话,看起来像没反应。0.1.7 已没有 `sessions.open`。现在改用 `uiWorkspace.openSession` 切到新会话,并把上一句填回输入框。失败原因显示在按钮上。 - README 的赞赏区换成非盈利声明:严禁商业售卖、付费倒卖或黑灰产牟利,仅供技术参考。 ## English @@ -22,4 +23,5 @@ - The four built-in Web presets (standard, ptc, cordis, minimal) lose only the identity sentence. The working-directory suffix, tool lists, `ptc` mode, and minimal's `complete: true` plus `includeRuntimeContext: false` stay. - When `complete: true`, `prompt-inject.md` is still prepended to that section. A host upgrade or an older hook that drops the section does not drop the inject. After Apply you still click Restart and start a new chat before it enters the session. - The `dsh-compaction-instant` web client uses `configForms` instead of the removed `settingsScope`, so the page no longer stops on Failed to load plugins. +- Rewind on 0.1.7 created the new session and left the UI on the old chat, so the click looked dead. 0.1.7 has no `sessions.open`. The button now opens the new session with `uiWorkspace.openSession` and puts the previous user line back in the composer. A failure shows on the button. - The README sponsor block is now a non-profit notice: no commercial resale and no gray-market profit; technical reference only.