mirror of
https://github.com/YuJunZhiXue/dsh-purge.git
synced 2026-11-27 15:50:22 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ff4431e1ba | ||
|
|
bcf28a639c |
No files matched your search
@@ -9122,29 +9122,156 @@ body[data-ds-dark-theme] .rt-scope-testing,.dshp-dock[data-theme="dusk"] .rt-sco
|
||||
}
|
||||
|
||||
|
||||
/* #208:undo 按钮不再注册进 conversation.input.right。
|
||||
Android WebView 切后台返回时,宿主 composer 的 React 子树只要在提交阶段抛一次,
|
||||
整块输入框就会被卸载;把按钮挪到 body 上的 fixed 宿主 + createPortal,
|
||||
渲染树完全离开 composer,位置按 .standardControls 的矩形对齐。 */
|
||||
const REWIND_HOST_ATTR = "data-dsh-purge-rewind-host";
|
||||
const REWIND_RESERVE_PX = 64;
|
||||
|
||||
function rewindControlsAnchor() {
|
||||
if (typeof document === "undefined") return null;
|
||||
// 取最靠下的那一组:输入框在页面底部;消息工具条里的同名控件更高,别抢。
|
||||
const list = document.querySelectorAll('[class*="standardControls"]');
|
||||
let best = null;
|
||||
let bestTop = -Infinity;
|
||||
for (let i = 0; i < list.length; i += 1) {
|
||||
const el = list[i];
|
||||
if (el.hidden) continue;
|
||||
const rect = el.getBoundingClientRect();
|
||||
if (!(rect.width > 0) || !(rect.height > 0)) continue;
|
||||
if (rect.top >= bestTop) { best = el; bestTop = rect.top; }
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
function placeRewindHost(host, anchor, reserve) {
|
||||
if (!host || !anchor) return;
|
||||
const rect = anchor.getBoundingClientRect();
|
||||
if (!(rect.width > 0) || anchor.hidden) {
|
||||
host.style.display = "none";
|
||||
return;
|
||||
}
|
||||
const width = host.offsetWidth || 60;
|
||||
const height = host.offsetHeight || 28;
|
||||
host.style.display = "block";
|
||||
host.style.left = Math.max(0, Math.round(rect.left + (reserve - width) / 2)) + "px";
|
||||
host.style.top = Math.round(rect.top + (rect.height - height) / 2) + "px";
|
||||
}
|
||||
|
||||
function RewindDockMount() {
|
||||
const t = useT();
|
||||
const [host, setHost] = useState(null);
|
||||
const [, bump] = useState(0);
|
||||
const sessionId = currentSessionId(rewindSessions);
|
||||
// 没有会话时不留空位:按钮不显示,padding 也一起归还。
|
||||
const sessionRef = useRef(null);
|
||||
sessionRef.current = sessionId;
|
||||
const placeRef = useRef(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (typeof document === "undefined") return undefined;
|
||||
let el = document.querySelector("[" + REWIND_HOST_ATTR + "]");
|
||||
if (!el) {
|
||||
el = document.createElement("div");
|
||||
el.setAttribute(REWIND_HOST_ATTR, "");
|
||||
document.body.appendChild(el);
|
||||
}
|
||||
el.style.cssText = "position:fixed;z-index:2147482500;display:none;left:0;top:0;";
|
||||
setHost(el);
|
||||
let padded = null;
|
||||
let warned = false;
|
||||
let lastQuery = 0;
|
||||
const startedAt = Date.now();
|
||||
const place = (force) => {
|
||||
// 缓存锚点 + 1s 节流:只有锚点缺失/掉线时才全文档查一次,
|
||||
// 否则长会话里每帧扫 [class*=...] 会拖慢滚动。
|
||||
if (!padded || !padded.isConnected) {
|
||||
const now = Date.now();
|
||||
if (force || now - lastQuery > 1000) {
|
||||
lastQuery = now;
|
||||
const next = rewindControlsAnchor();
|
||||
if (padded && padded !== next) padded.style.paddingLeft = padded.dataset.dshpPad || "";
|
||||
if (next && next !== padded) next.dataset.dshpPad = next.style.paddingLeft || "";
|
||||
padded = next;
|
||||
}
|
||||
}
|
||||
const anchor = padded;
|
||||
if (!anchor) {
|
||||
el.style.display = "none";
|
||||
if (!warned && Date.now() - startedAt > 5000) {
|
||||
warned = true;
|
||||
try { console.warn("[dsh-purge] rewind: composer standardControls anchor missing"); } catch { /* ignore */ }
|
||||
}
|
||||
return;
|
||||
}
|
||||
// 按钮标签会随失败提示变长,预留宽度跟着实测宽度走,避免压到模型选择器。
|
||||
const reserve = Math.max(REWIND_RESERVE_PX, (el.offsetWidth || 60) + 12);
|
||||
const pad = sessionRef.current ? reserve + "px" : (anchor.dataset.dshpPad || "");
|
||||
if (anchor.style.paddingLeft !== pad) anchor.style.paddingLeft = pad;
|
||||
if (!sessionRef.current) {
|
||||
el.style.display = "none";
|
||||
return;
|
||||
}
|
||||
placeRewindHost(el, anchor, reserve);
|
||||
};
|
||||
place(true);
|
||||
placeRef.current = place;
|
||||
const onMove = () => place(false);
|
||||
const iv = setInterval(onMove, 500);
|
||||
window.addEventListener("resize", onMove);
|
||||
document.addEventListener("scroll", onMove, true);
|
||||
return () => {
|
||||
clearInterval(iv);
|
||||
placeRef.current = null;
|
||||
window.removeEventListener("resize", onMove);
|
||||
document.removeEventListener("scroll", onMove, true);
|
||||
if (padded) {
|
||||
padded.style.paddingLeft = padded.dataset.dshpPad || "";
|
||||
delete padded.dataset.dshpPad;
|
||||
}
|
||||
try { el.remove(); } catch { /* ignore */ }
|
||||
};
|
||||
}, []);
|
||||
|
||||
// 会话切换/首次挂载时立刻对齐,不用等 500ms 定时器。
|
||||
useEffect(() => {
|
||||
if (placeRef.current) placeRef.current(true);
|
||||
}, [sessionId, host]);
|
||||
|
||||
useEffect(() => {
|
||||
const offs = [];
|
||||
const watch = (store) => {
|
||||
try {
|
||||
if (store && typeof store.subscribe === "function") {
|
||||
offs.push(store.subscribe(() => bump((n) => (n + 1) % 1e9)));
|
||||
}
|
||||
} catch { /* ignore */ }
|
||||
};
|
||||
watch(rewindWorkspace && rewindWorkspace.selection);
|
||||
watch(rewindSessions && rewindSessions.list);
|
||||
const iv = setInterval(() => bump((n) => (n + 1) % 1e9), 2000);
|
||||
return () => {
|
||||
for (const off of offs) { try { off(); } catch { /* ignore */ } }
|
||||
clearInterval(iv);
|
||||
};
|
||||
}, []);
|
||||
|
||||
if (!host || !sessionId) return null;
|
||||
try {
|
||||
const rd = require("react-dom");
|
||||
if (rd && typeof rd.createPortal === "function") {
|
||||
return rd.createPortal(h(RewindSafe, { sessionId, t }), host);
|
||||
}
|
||||
} catch { /* host 可能没暴露 react-dom */ }
|
||||
return null;
|
||||
}
|
||||
|
||||
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",
|
||||
order: 20,
|
||||
inject: (sessionId) => ({
|
||||
sessionId,
|
||||
t: ctx.locale.bind(NS),
|
||||
}),
|
||||
}, RewindSafe));
|
||||
// ctx.slots.inject("conversation.input.right", () => ctx.slots.register({
|
||||
// name: "conversation.input.right",
|
||||
// id: "dsh-purge-continue",
|
||||
// order: 21,
|
||||
// inject: (sessionId) => ({
|
||||
// sessionId,
|
||||
// t: ctx.locale.bind(NS),
|
||||
// }),
|
||||
// }, ContinueSafe));
|
||||
ctx.effect(() => installRewindWatch(ctx), "dsh-purge: rewind watch");
|
||||
}
|
||||
|
||||
@@ -9201,7 +9328,7 @@ body[data-ds-dark-theme] .rt-scope-testing,.dshp-dock[data-theme="dusk"] .rt-sco
|
||||
name: "shell.overlay",
|
||||
id: "dsh-purge-dock",
|
||||
order: 50,
|
||||
}, () => h(react.Fragment, null, h(WelcomeNotice), h(PurgeLauncher), h(PurgeDock), h(HeroNewSessionMount), h(TabRowPurgeMount), h(EnvAdaptSendGate))));
|
||||
}, () => h(react.Fragment, null, h(WelcomeNotice), h(PurgeLauncher), h(PurgeDock), h(HeroNewSessionMount), h(TabRowPurgeMount), h(EnvAdaptSendGate), h(RewindDockMount))));
|
||||
try {
|
||||
if (typeof ctx.inject === "function") {
|
||||
ctx.inject(["sessions", "uiWorkspace", "workspaces", "conversation"], (host) => installRewindUi(host));
|
||||
|
||||
+66
-22
@@ -3615,7 +3615,7 @@ const NEW_TOOL_PATCHES = [
|
||||
},
|
||||
// rc.5 的 web-app-lib 已经不含这段提示词;留一个代码注释标记,避免整条补丁永远显示 drifted。
|
||||
{
|
||||
pattern: "export { Config, apply, inject, internals, name };",
|
||||
pattern: /export \{ Config, apply, inject, internals, name \};(?!\s*(?:\/\* \[dsh-purge\] web surface prohibition cleared|\/\/ \[dsh-purge\] web surface identity neutralized))/,
|
||||
replace: "export { Config, apply, inject, internals, name }; // [dsh-purge] web surface identity neutralized",
|
||||
},
|
||||
],
|
||||
@@ -4711,7 +4711,7 @@ const NEW_TOOL_PATCHES = [
|
||||
// rc.5 的 web-app-lib 已经不含这段文案;留一个代码注释标记,
|
||||
// 避免该文件既无 pattern 又无 marker,把整条补丁拖成 drifted。
|
||||
{
|
||||
pattern: /export \{ Config, apply, inject, internals, name \};/,
|
||||
pattern: /export \{ Config, apply, inject, internals, name \};(?!\s*\/\* \[dsh-purge\] web surface prohibition cleared)/,
|
||||
replace:
|
||||
"export { Config, apply, inject, internals, name }; /* [dsh-purge] web surface prohibition cleared */",
|
||||
insertProbe: "[dsh-purge] web surface prohibition cleared",
|
||||
@@ -4880,36 +4880,80 @@ const NEW_TOOL_PATCHES = [
|
||||
markers: ["[dsh-purge] close no-fail v2"],
|
||||
},
|
||||
{
|
||||
// #194:host 被信号杀时 #83 直接静默 resolve,UI 端永远不知道 host 已经没了,
|
||||
// 窗口自然不出现。这里保持“不弹对话框”,但把退出事实写进持久化日志,
|
||||
// 下次排查至少能看到 signal / code / stderr 尾巴。
|
||||
id: 91,
|
||||
name: "DESKTOP_HOST_SIGNAL_EXIT_LOG",
|
||||
// #207:dir 模式静默退出时,host 的 close 回调是唯一知道真实退出码的地方。
|
||||
// #83 在 signal 分支直接 resolve 不记录,这里把每条退出路径都记下来。
|
||||
id: 92,
|
||||
name: "DESKTOP_HOST_EXIT_TRACE",
|
||||
layer: "代码",
|
||||
layer_en: "Code",
|
||||
desc: "host 被信号杀时写持久化退出日志(仍不弹对话框) / persist a trace when the host dies by signal",
|
||||
desc: "host 每次退出都写 code/signal/stderr 到持久化日志 / persist every host exit",
|
||||
file: ["desktop-shell"],
|
||||
surfaces: ["desktop"],
|
||||
optional: true,
|
||||
skipIfMarked: true,
|
||||
replacements: [
|
||||
{
|
||||
pattern: "if (code === null || signal) { resolve(); return; }",
|
||||
pattern:
|
||||
"\t\t\tchild.once(\"close\", (code, signal) => {\n" +
|
||||
"\t\t\t\tconst suffix = this.stderr.trim() === \"\" ? \"\" : `: ${this.stderr.trim()}`;",
|
||||
replace:
|
||||
"if (code === null || signal) {\n" +
|
||||
"\t\t\t\t\t/* [dsh-purge] host signal exit logged */\n" +
|
||||
"\t\t\t\t\ttry {\n" +
|
||||
"\t\t\t\t\t\tconst _req = typeof require === \"function\" ? require : null;\n" +
|
||||
"\t\t\t\t\t\tconst _fs = typeof process.getBuiltinModule === \"function\" ? process.getBuiltinModule(\"node:fs\") : (_req ? _req(\"node:fs\") : null);\n" +
|
||||
"\t\t\t\t\t\tconst _os = typeof process.getBuiltinModule === \"function\" ? process.getBuiltinModule(\"node:os\") : (_req ? _req(\"node:os\") : null);\n" +
|
||||
"\t\t\t\t\t\tconst _log = _fs && _os ? _os.tmpdir() + \"/dsh-purge-desktop.log\" : \"\";\n" +
|
||||
"\t\t\t\t\t\tif (_log) _fs.appendFileSync(_log, new Date().toISOString() + \" [desktop.hostExit] signal=\" + String(signal) + \" code=\" + String(code) + suffix + \"\\n\", \"utf8\");\n" +
|
||||
"\t\t\t\t\t} catch {}\n" +
|
||||
"\t\t\t\t\tresolve(); return;\n" +
|
||||
"\t\t\t\t}",
|
||||
"\t\t\tchild.once(\"close\", (code, signal) => {\n" +
|
||||
"\t\t\t\tconst suffix = this.stderr.trim() === \"\" ? \"\" : `: ${this.stderr.trim()}`;\n" +
|
||||
"\t\t\t\t// [dsh-purge] host exit logged: 所有退出路径都留痕,dir 模式静默退出才查得动\n" +
|
||||
"\t\t\t\ttry {\n" +
|
||||
"\t\t\t\t\tconst _fs = typeof process.getBuiltinModule === \"function\" ? process.getBuiltinModule(\"node:fs\") : null;\n" +
|
||||
"\t\t\t\t\tconst _os = typeof process.getBuiltinModule === \"function\" ? process.getBuiltinModule(\"node:os\") : null;\n" +
|
||||
"\t\t\t\t\tif (_fs && _os) _fs.appendFileSync(_os.tmpdir() + \"/dsh-purge-desktop.log\", new Date().toISOString() + \" [desktop.hostExit] code=\" + String(code) + \" signal=\" + String(signal) + suffix + \"\\n\", \"utf8\");\n" +
|
||||
"\t\t\t\t} catch {}",
|
||||
},
|
||||
],
|
||||
markers: ["[dsh-purge] host signal exit logged"],
|
||||
markers: ["[dsh-purge] host exit logged"],
|
||||
},
|
||||
{
|
||||
// #207:主进程自己静默退出时完全没人记录原因。挂一层生命周期日志,
|
||||
// 记录 before-quit / will-quit / quit(exitCode) / 渲染进程崩溃 / 信号 / 未捕获异常。
|
||||
id: 93,
|
||||
name: "DESKTOP_MAIN_EXIT_TRACE",
|
||||
layer: "代码",
|
||||
layer_en: "Code",
|
||||
desc: "主进程退出原因写持久化日志(quit/信号/崩溃/未捕获异常) / trace why the desktop main process exits",
|
||||
file: ["desktop-shell"],
|
||||
surfaces: ["desktop"],
|
||||
optional: true,
|
||||
replacements: [
|
||||
{
|
||||
pattern: "if (claimDesktopSingleInstance(app, () => {\n\tfocusPrimaryWindow();\n}))",
|
||||
replace:
|
||||
"/* [dsh-purge] desktop exit trace */\n" +
|
||||
"try {\n" +
|
||||
"\tconst _df = typeof process.getBuiltinModule === \"function\" ? process.getBuiltinModule(\"node:fs\") : null;\n" +
|
||||
"\tconst _do = typeof process.getBuiltinModule === \"function\" ? process.getBuiltinModule(\"node:os\") : null;\n" +
|
||||
"\tconst _dlog = _df && _do ? _do.tmpdir() + \"/dsh-purge-desktop.log\" : \"\";\n" +
|
||||
"\tif (_dlog) {\n" +
|
||||
"\t\tconst _dt = (tag, extra) => {\n" +
|
||||
"\t\t\ttry { _df.appendFileSync(_dlog, new Date().toISOString() + \" [desktop.exit] \" + tag + (extra === void 0 ? \"\" : \" \" + String(extra)) + \"\\n\", \"utf8\"); } catch {}\n" +
|
||||
"\t\t};\n" +
|
||||
"\t\t_dt(\"boot pid=\" + process.pid + \" appPath=\" + app.getAppPath() + \" electron=\" + process.versions.electron);\n" +
|
||||
"\t\tprocess.on(\"exit\", (code) => _dt(\"process.exit code=\" + String(code)));\n" +
|
||||
"\t\t// 只用 monitor:挂 uncaughtException 本体就会吞掉崩溃、把退出改成继续跑。\n" +
|
||||
"\t\tprocess.on(\"uncaughtExceptionMonitor\", (error) => _dt(\"uncaughtException\", error && error.stack || error));\n" +
|
||||
"\t\tfor (const sig of [\"SIGTERM\", \"SIGINT\", \"SIGBREAK\"]) process.on(sig, () => _dt(\"signal \" + sig));\n" +
|
||||
"\t\tapp.on(\"before-quit\", () => _dt(\"before-quit\"));\n" +
|
||||
"\t\tapp.on(\"will-quit\", () => _dt(\"will-quit\"));\n" +
|
||||
"\t\tapp.on(\"quit\", (_event, code) => _dt(\"quit code=\" + String(code)));\n" +
|
||||
"\t\tapp.on(\"window-all-closed\", () => _dt(\"window-all-closed\"));\n" +
|
||||
"\t\tapp.on(\"render-process-gone\", (_event, _contents, details) => {\n" +
|
||||
"\t\t\tlet _tail = \"\";\n" +
|
||||
"\t\t\ttry { _tail = \" console=\" + JSON.stringify(rendererConsole.snapshot()); } catch {}\n" +
|
||||
"\t\t\t_dt(\"render-process-gone\", JSON.stringify(details) + _tail);\n" +
|
||||
"\t\t});\n" +
|
||||
"\t\tapp.on(\"child-process-gone\", (_event, details) => _dt(\"child-process-gone\", JSON.stringify(details)));\n" +
|
||||
"\t\tsetInterval(() => _dt(\"alive\"), 60000).unref();\n" +
|
||||
"\t}\n" +
|
||||
"} catch {}\n" +
|
||||
"if (claimDesktopSingleInstance(app, () => {\n\tfocusPrimaryWindow();\n}))",
|
||||
},
|
||||
],
|
||||
markers: ["[dsh-purge] desktop exit trace"],
|
||||
},
|
||||
{
|
||||
id: 67,
|
||||
|
||||
+35
-7
@@ -1017,6 +1017,10 @@ export const ASAR_SWAP_PS1 = [
|
||||
" [Parameter(Mandatory = $true)][string]$ExePath",
|
||||
")",
|
||||
"$ErrorActionPreference = 'Continue'",
|
||||
"$log = Join-Path $env:TEMP 'dsh-purge-desktop.log'",
|
||||
"function Write-SwapLog([string]$message) {",
|
||||
" try { Add-Content -LiteralPath $log -Value ((Get-Date).ToUniversalTime().ToString('o') + ' [asar-swap] ' + $message) -ErrorAction SilentlyContinue } catch {}",
|
||||
"}",
|
||||
"$installRoot = (Split-Path -Parent $ExePath).TrimEnd('\\')",
|
||||
"$exeNorm = $ExePath.ToLower()",
|
||||
"function Stop-HarnessInstall {",
|
||||
@@ -1072,33 +1076,43 @@ export const ASAR_SWAP_PS1 = [
|
||||
" & robocopy.exe $unpacked $appDir /E /XC /XN /XO /NFL /NDL /NJH /NJS /nc /ns /np | Out-Null",
|
||||
"}",
|
||||
"$moved = -not (Test-Path -LiteralPath $AsarPath)",
|
||||
"$hadAsar = -not $moved",
|
||||
"$moveErr = ''",
|
||||
"if (Test-Path -LiteralPath $AsarPath) {",
|
||||
" $bak = \"$AsarPath.bak\"",
|
||||
" if (Test-Path -LiteralPath $bak) { Remove-Item -LiteralPath $bak -Force -ErrorAction SilentlyContinue }",
|
||||
" for ($i = 0; $i -lt 80; $i++) {",
|
||||
" try {",
|
||||
" Move-Item -LiteralPath $AsarPath -Destination $bak -Force",
|
||||
" $moved = $true",
|
||||
" Move-Item -LiteralPath $AsarPath -Destination $bak -Force -ErrorAction Stop",
|
||||
" $moveErr = ''",
|
||||
" break",
|
||||
" } catch {",
|
||||
" $moveErr = $_.Exception.Message",
|
||||
" if ($i -eq 20 -or $i -eq 50) { Stop-HarnessInstall; Start-Sleep -Seconds 1 }",
|
||||
" Start-Sleep -Milliseconds 400",
|
||||
" }",
|
||||
" }",
|
||||
" if ((Test-Path -LiteralPath $AsarPath) -and $moveErr) {",
|
||||
" # Move-Item 偶尔报『拒绝访问』但其实只是句柄没释放;.NET 直调再试一次并保留真实错误。",
|
||||
" try {",
|
||||
" if (Test-Path -LiteralPath $bak) { [System.IO.File]::Delete($bak) }",
|
||||
" [System.IO.File]::Move($AsarPath, $bak)",
|
||||
" $moveErr = ''",
|
||||
" } catch { $moveErr = $_.Exception.Message }",
|
||||
" }",
|
||||
" $moved = ($moveErr -eq '') -and (-not (Test-Path -LiteralPath $AsarPath))",
|
||||
"}",
|
||||
"$lock = $AsarPath + '.rename-pending'",
|
||||
"if ($moved) {",
|
||||
" Remove-Item -LiteralPath $lock -Force -ErrorAction SilentlyContinue",
|
||||
" Remove-Item Env:ELECTRON_RUN_AS_NODE -ErrorAction SilentlyContinue",
|
||||
" Write-SwapLog $(if ($hadAsar) { 'moved asar -> bak (verified)' } else { 'asar already absent' })",
|
||||
" Start-Process -FilePath $ExePath",
|
||||
"} else {",
|
||||
" # #197b: 挪不动(asar 仍被占用)时不要把用户扔在空桌面上——把原版拉起来,",
|
||||
" # 留下 rename-pending 让下一次空闲重试;失败原因写进 dsh-purge 日志。",
|
||||
" Set-Content -LiteralPath $lock -Value ((Get-Date).ToString('o')) -Encoding ascii",
|
||||
" try {",
|
||||
" $log = Join-Path $env:TEMP 'dsh-purge-desktop.log'",
|
||||
" Add-Content -LiteralPath $log -Value ((Get-Date).ToUniversalTime().ToString('o') + ' [asar-swap] move failed; relaunching original app (asar still sealed)')",
|
||||
" } catch {}",
|
||||
" Write-SwapLog ('move failed: ' + $moveErr + '; relaunching original app (asar still sealed)')",
|
||||
" Remove-Item Env:ELECTRON_RUN_AS_NODE -ErrorAction SilentlyContinue",
|
||||
" Start-Process -FilePath $ExePath",
|
||||
"}",
|
||||
@@ -1113,6 +1127,7 @@ const ASAR_RENAME_WHEN_IDLE_PS1 = [
|
||||
")",
|
||||
"$ErrorActionPreference = 'Continue'",
|
||||
"$deadline = (Get-Date).AddMinutes(30)",
|
||||
"$tries = 0",
|
||||
"while ((Get-Date) -lt $deadline) {",
|
||||
" $restartFlag = Join-Path $env:TEMP 'dsh-purge-official-restarting'",
|
||||
" if (Test-Path -LiteralPath $restartFlag) {",
|
||||
@@ -1134,9 +1149,22 @@ const ASAR_RENAME_WHEN_IDLE_PS1 = [
|
||||
" }",
|
||||
" $bak = \"$AsarPath.bak\"",
|
||||
" if (Test-Path -LiteralPath $bak) { Remove-Item -LiteralPath $bak -Force -ErrorAction SilentlyContinue }",
|
||||
" $tries++",
|
||||
" try {",
|
||||
" Move-Item -LiteralPath $AsarPath -Destination $bak -Force -ErrorAction Stop",
|
||||
" } catch {",
|
||||
" $renameErr = ''",
|
||||
" } catch { $renameErr = $_.Exception.Message }",
|
||||
" if ($renameErr -or (Test-Path -LiteralPath $AsarPath)) {",
|
||||
" try {",
|
||||
" if (Test-Path -LiteralPath $bak) { [System.IO.File]::Delete($bak) }",
|
||||
" [System.IO.File]::Move($AsarPath, $bak)",
|
||||
" $renameErr = ''",
|
||||
" } catch { $renameErr = $_.Exception.Message }",
|
||||
" }",
|
||||
" if (Test-Path -LiteralPath $AsarPath) {",
|
||||
" if ($tries -eq 1 -or ($tries % 300) -eq 0) {",
|
||||
" try { Add-Content -LiteralPath (Join-Path $env:TEMP 'dsh-purge-desktop.log') -Value ((Get-Date).ToUniversalTime().ToString('o') + ' [asar-idle] move failed: ' + $renameErr) } catch {}",
|
||||
" }",
|
||||
" Start-Sleep -Milliseconds 400",
|
||||
" continue",
|
||||
" }",
|
||||
|
||||
+55
-18
@@ -12,6 +12,9 @@ const CWD_STATIC_SUFFIX = "Your working directory is the current workspace.";
|
||||
const CWD_TOKEN = /\{\{\s*cwd\s*\}\}|\[\s*cwd\s*\]/g;
|
||||
const CWD_TOKEN_TEST = /\{\{\s*cwd\s*\}\}|\[\s*cwd\s*\]/;
|
||||
const CWD_PLAIN = "the current workspace";
|
||||
// #204:优先写真实 cwd 字面量,这样 0.2.1 不注册 {{cwd}} 也能保留工作目录提示。
|
||||
// 只认路径形状,用户自定义的 "Your working directory is <某句话>." 不抢。
|
||||
const CWD_LITERAL_SUFFIX = /^Your working directory is (?:[A-Za-z]:[\\/]|\\\\|\/|~[\\/])[^\r\n]{0,1024}\.?$/;
|
||||
export { PHASE1_KEEP_EXPR, widenPhase1KeepFilter } from "./phase1-keep.js";
|
||||
|
||||
const DSH_INTERPOLATE_ALLOWED = new Set(["cwd", "model", "provider"]);
|
||||
@@ -207,10 +210,38 @@ function isHardcodedExecRule(section) {
|
||||
|
||||
function isCwdOnlyText(text) {
|
||||
const t = String(text || "").trim();
|
||||
return t === CWD_ONLY_SUFFIX
|
||||
|| t === CWD_STATIC_SUFFIX
|
||||
|| t === "Working directory: {{cwd}}."
|
||||
|| t === "Working directory: {{cwd}}";
|
||||
if (t === CWD_ONLY_SUFFIX || t === CWD_STATIC_SUFFIX) return true;
|
||||
if (t === "Working directory: {{cwd}}." || t === "Working directory: {{cwd}}") return true;
|
||||
return CWD_LITERAL_SUFFIX.test(t);
|
||||
}
|
||||
|
||||
/** 会话头里的真实 cwd;拿不到返回空串。 */
|
||||
export function resolveCwdFromContext(context) {
|
||||
try {
|
||||
const cwd = context?.agent?.session?.header?.cwd;
|
||||
return typeof cwd === "string" ? cwd.trim() : "";
|
||||
} catch {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/** workdir 句:真实 cwd > 宿主已注册的 {{cwd}} > 静态兜底。 */
|
||||
function cwdSuffixEntry(options = {}) {
|
||||
const cwd = String(options.cwd || "").trim();
|
||||
if (cwd) return { text: `Your working directory is ${cwd}.`, interpolate: false };
|
||||
if (options.cwdSupported !== false) return { text: CWD_ONLY_SUFFIX, interpolate: true };
|
||||
return { text: CWD_STATIC_SUFFIX, interpolate: false };
|
||||
}
|
||||
|
||||
/** 把真实 cwd 补进 assembly.variables,用户模板里的 {{cwd}} 才渲染得出来(#204)。 */
|
||||
function withCwdVariable(assembled, cwd) {
|
||||
if (!cwd) return assembled && assembled.variables;
|
||||
const vars = assembled && assembled.variables;
|
||||
if (vars && typeof vars === "object" && !Array.isArray(vars)) {
|
||||
if (Object.hasOwn(vars, "cwd") && vars.cwd !== undefined) return vars;
|
||||
return { ...vars, cwd };
|
||||
}
|
||||
return { cwd };
|
||||
}
|
||||
|
||||
/** cwd 变量是否真的会被宿主插值。0.2.1 起装配对象常常没有 cwd。 */
|
||||
@@ -223,17 +254,19 @@ export function cwdVariableSupported(assembled) {
|
||||
return Object.hasOwn(vars, "cwd") && vars.cwd !== undefined;
|
||||
}
|
||||
|
||||
function replaceCwdToken(text) {
|
||||
return String(text).replace(CWD_TOKEN, CWD_PLAIN);
|
||||
function replaceCwdToken(text, cwd) {
|
||||
return String(text).replace(CWD_TOKEN, cwd || CWD_PLAIN);
|
||||
}
|
||||
|
||||
function sanitizeCwdTokens(sections, assembled) {
|
||||
if (cwdVariableSupported(assembled)) return sections;
|
||||
return sections.map((section) => (
|
||||
section && typeof section.text === "string" && CWD_TOKEN_TEST.test(section.text)
|
||||
? { ...section, text: replaceCwdToken(section.text) }
|
||||
: section
|
||||
));
|
||||
function sanitizeCwdTokens(sections, assembled, sessionCwd) {
|
||||
const canInterpolate = Boolean(sessionCwd) || cwdVariableSupported(assembled);
|
||||
return sections.map((section) => {
|
||||
if (!section || typeof section.text !== "string" || !CWD_TOKEN_TEST.test(section.text)) return section;
|
||||
// 不插值的段(dsh-purge 注入、锚点)拿到 token 只会原样印给模型,直接写真实路径。
|
||||
if (section.interpolate === false) return { ...section, text: replaceCwdToken(section.text, sessionCwd) };
|
||||
if (canInterpolate) return section;
|
||||
return { ...section, text: replaceCwdToken(section.text, "") };
|
||||
});
|
||||
}
|
||||
|
||||
function looksLikeOfficialIdentity(text) {
|
||||
@@ -246,7 +279,7 @@ function looksLikeOfficialIdentity(text) {
|
||||
|
||||
/** 关掉官方身份,只留工作目录。红队操作稿在 prefix 里时不动。 */
|
||||
export function overlayOfficialIdentity(sections, options = {}) {
|
||||
const suffixText = options.cwdSupported === false ? CWD_STATIC_SUFFIX : CWD_ONLY_SUFFIX;
|
||||
const suffix = cwdSuffixEntry(options);
|
||||
const list = Array.isArray(sections) ? sections : [];
|
||||
const out = [];
|
||||
let sawSuffix = false;
|
||||
@@ -264,7 +297,7 @@ export function overlayOfficialIdentity(sections, options = {}) {
|
||||
sawSuffix = true;
|
||||
const raw = String(section.text || "");
|
||||
if (!raw.trim() || looksLikeOfficialIdentity(raw) || isCwdOnlyText(raw)) {
|
||||
out.push({ ...section, text: suffixText });
|
||||
out.push({ ...section, text: suffix.text, interpolate: suffix.interpolate });
|
||||
} else {
|
||||
out.push(section);
|
||||
}
|
||||
@@ -275,8 +308,9 @@ export function overlayOfficialIdentity(sections, options = {}) {
|
||||
if (!sawSuffix) {
|
||||
out.push({
|
||||
name: "deployment:persona-suffix",
|
||||
text: suffixText,
|
||||
text: suffix.text,
|
||||
order: 10200,
|
||||
interpolate: suffix.interpolate,
|
||||
});
|
||||
}
|
||||
return out;
|
||||
@@ -998,9 +1032,10 @@ export function rewritePromptAssembly(assembled, fallbackInject = "", options =
|
||||
const withOps = attachRedteamOpsOnly(sections);
|
||||
sections = insertRoleSection(insertCardSection(withOps, opts.cardText), opts.roleText);
|
||||
}
|
||||
const sessionCwd = resolveCwdFromContext(opts.context);
|
||||
let outSections = overlayOfficialIdentity(
|
||||
sanitizeAssemblySections(leadWithInject(sections, injectText, protocol)),
|
||||
{ cwdSupported: cwdVariableSupported(assembled) },
|
||||
{ cwd: sessionCwd, cwdSupported: cwdVariableSupported(assembled) },
|
||||
);
|
||||
if (injectText) {
|
||||
const needle = injectText.slice(0, 80);
|
||||
@@ -1019,7 +1054,7 @@ export function rewritePromptAssembly(assembled, fallbackInject = "", options =
|
||||
];
|
||||
}
|
||||
}
|
||||
outSections = sanitizeCwdTokens(outSections, assembled);
|
||||
outSections = sanitizeCwdTokens(outSections, assembled, sessionCwd);
|
||||
// [dsh-purge] 尾部锚点。
|
||||
// waterfall 返回的 sections 数组顺序就是渲染顺序,order 字段不参与排序,
|
||||
// 所以只能物理追加到数组末尾,不能靠 order 值。
|
||||
@@ -1032,10 +1067,12 @@ export function rewritePromptAssembly(assembled, fallbackInject = "", options =
|
||||
{ name: ANCHOR_SECTION, text: anchorText, order: ANCHOR_ORDER, interpolate: false },
|
||||
];
|
||||
}
|
||||
const cwdVariable = withCwdVariable(assembled, sessionCwd);
|
||||
return {
|
||||
...assembled,
|
||||
sections: outSections,
|
||||
contexts: Array.isArray(assembled.contexts) ? assembled.contexts : [],
|
||||
tools: Array.isArray(assembled.tools) ? assembled.tools : [],
|
||||
...(cwdVariable && cwdVariable !== assembled.variables ? { variables: cwdVariable } : {}),
|
||||
};
|
||||
}
|
||||
+2
-2
@@ -19,6 +19,7 @@ import {
|
||||
modePromptText,
|
||||
peelChatmlEnvelope,
|
||||
escapeDshInterpolation,
|
||||
resolveCwdFromContext,
|
||||
rewritePromptAssembly,
|
||||
} from "./identity.js";
|
||||
import { capabilityProtocolText, CAPABILITY_SECTION } from "./capability-protocol.js";
|
||||
@@ -623,8 +624,7 @@ function rewriteLiveAssembly(config, assembled, context, decision = { mode: "ful
|
||||
const redteam = sigRedteam;
|
||||
const full = enabled ? readInjectFallback(context) : "";
|
||||
const dshHome = sigHome;
|
||||
let cwd = "";
|
||||
try { cwd = String(context?.agent?.session?.header?.cwd || "").trim(); } catch { /* ignore */ }
|
||||
const cwd = resolveCwdFromContext(context);
|
||||
if (dshHome && cwd) {
|
||||
try { rules.writeLastCwd(dshHome, cwd); } catch { /* ignore */ }
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "dsh-purge",
|
||||
"version": "1.1.88",
|
||||
"version": "1.1.90",
|
||||
"description": "DeepSeek Harness 破甲:让所有模型都能破甲,不同模型可换不同提示词;默认提示词面向国模「小码酱」。Jailbreak for every model — swap prompts per model. 求 Star 收藏 ⭐ 如要二开,请查看署名要求部分",
|
||||
"type": "module",
|
||||
"main": "lib/index.js",
|
||||
|
||||
@@ -1,3 +1,51 @@
|
||||
# 1.1.90
|
||||
|
||||
## 中文
|
||||
|
||||
- 版本 **1.1.90**。
|
||||
- **#208 Android 切后台回来输入框整块消失**:撤销按钮原先注册在宿主的 `conversation.input.right` 槽位,这个槽位渲染在 composer 的 React 子树里。宿主在提交阶段只要抛一次错,React 会把整棵树卸载,症状就是输入框连带按钮一起没了。
|
||||
- 撤销按钮不再走任何槽位。改为在 `body` 上挂一个 `position: fixed` 的宿主节点,用 `createPortal` 把按钮传进去,渲染树完全脱离 composer;composer 内部再出错也牵连不到它。
|
||||
- 位置按最靠下的那组 `.standardControls`(就是 composer 底部工具条)的矩形实时对齐,并给它留 `padding-left` 空位,不遮住模型选择器;预留宽度跟着按钮实测宽度走。
|
||||
- 会话切换、窗口尺寸变化、页面滚动都会重新对齐;没有会话时按钮不显示、留白也一起归还。
|
||||
- 锚点查找带缓存和节流,只在锚点缺失或掉线时才扫一次 DOM,长会话滚动不受影响。
|
||||
- **验证**:`client.js` 语法检查通过;`conversation.input.right` 在本插件中已无任何注册点;双宿主 `standardControls` 类名核对一致。
|
||||
|
||||
## English
|
||||
|
||||
- **1.1.90**.
|
||||
- **#208 the whole composer vanished after switching apps**: the undo button was registered into the host's `conversation.input.right` slot, which renders inside the composer's React subtree. One throw during a commit phase makes React unmount that tree, and the input box goes with it.
|
||||
- The undo button no longer uses any slot. It renders through `createPortal` into a `position: fixed` host appended to `body`, fully outside the composer subtree, so a composer error can no longer take it down.
|
||||
- It aligns itself to the rectangle of the bottom-most `.standardControls` (the composer toolbar) and reserves `padding-left` there so the model picker is not covered; the reserved width follows the button's measured width.
|
||||
- It re-aligns on session change, resize and scroll, and releases both the button and the reserved space when there is no session.
|
||||
- Anchor lookup is cached and throttled: the DOM is scanned only when the anchor is missing or detached, so long chats keep scrolling smoothly.
|
||||
- **Verification**: `client.js` passes the syntax check; no `conversation.input.right` registration remains in the plugin; the `standardControls` class name matches on both hosts.
|
||||
|
||||
# 1.1.89
|
||||
|
||||
## 中文
|
||||
|
||||
- 版本 **1.1.89**。
|
||||
- **#204 工作目录提示恢复**:`deployment:persona-suffix` 优先写会话真实 cwd 字面量(`interpolate: false`),拿不到才退静态描述;同时把 `cwd` 补进 `assembly.variables`,用户自己模板里的 `{{cwd}}` 也能渲染。0.2.1 不再抛 `unknown prompt variable`,工作目录提示不再变成 `the current workspace`。
|
||||
- **#207 桌面静默退出可诊断**:
|
||||
- 新增 #92:宿主每次退出都把 `code` / `signal` / stderr 尾巴写进 `%TEMP%\dsh-purge-desktop.log`(不再只记 signal 分支)。
|
||||
- 新增 #93:主进程记录 `boot` / `before-quit` / `will-quit` / `quit code` / `window-all-closed` / `render-process-gone`(附渲染进程最后几行 console)/ `child-process-gone` / 信号 / 每分钟心跳。只用 `uncaughtExceptionMonitor`,不改变崩溃行为。
|
||||
- asar 换包脚本:`Move-Item` 失败后改用 `.NET File.Move` 重试,成功/失败都 `Test-Path` 复核并记录真实错误;空闲改名脚本同样记录失败原因(限流,不刷屏)。
|
||||
- **#202 原子写**:`atomicWriteFile` 保持 `writeFile + rename`(不依赖 hostFs 白名单里没有的 `open`);CLI `--apply` 成功后补打应用戳,下次启动 settle 不会误判未对齐再重打。
|
||||
- **修复重复标记**:#32 / #53 的 export 行锚点原来自我匹配,每点一次「应用」就多追加一行注释;改成带负向前瞻的正则,连续应用保持幂等。
|
||||
- **验证**:web + desktop 双宿主现有补丁全部 applied;rc.2 夹具与 rc.5 实机 pattern 全绿;沙箱 42 个目标文件 apply/revert 字节级还原;生成的 PowerShell 脚本通过 `Parser::ParseFile` 语法检查。
|
||||
|
||||
## English
|
||||
|
||||
- **1.1.89**.
|
||||
- **#204 working directory restored**: the persona suffix now uses the real session cwd as a literal (`interpolate: false`) and only falls back to the static sentence when no cwd is available; `cwd` is also added to `assembly.variables`, so user templates with `{{cwd}}` render. 0.2.1 no longer throws `unknown prompt variable`, and the prompt keeps the real path instead of `the current workspace`.
|
||||
- **#207 desktop exit is diagnosable**:
|
||||
- New #92: every host exit writes `code` / `signal` / stderr tail to `%TEMP%\dsh-purge-desktop.log`.
|
||||
- New #93: main process logs `boot` / `before-quit` / `will-quit` / `quit code` / `window-all-closed` / `render-process-gone` (with the renderer console tail) / `child-process-gone` / signals / a one-minute heartbeat. Uses `uncaughtExceptionMonitor` only, so crash behavior is unchanged.
|
||||
- ASAR swap: falls back to `.NET File.Move` after `Move-Item` fails, verifies with `Test-Path`, and records the real error; the idle rename script logs failures too (rate-limited).
|
||||
- **#202 atomic writes**: `atomicWriteFile` stays on `writeFile + rename` (the hostFs whitelist has no `open`); the CLI `--apply` now also writes the applied stamp so the next boot's settle does not re-apply.
|
||||
- **Duplicate markers fixed**: the #32 / #53 export-line anchors matched their own output and appended another comment on every Apply; both now use negative lookaheads and are idempotent.
|
||||
- **Verified**: all existing patches applied on both web and desktop hosts; rc.2 fixtures and rc.5 real files green; sandbox apply/revert restored 42 target files byte-for-byte; generated PowerShell scripts pass `Parser::ParseFile`.
|
||||
|
||||
# 1.1.88
|
||||
|
||||
## 中文
|
||||
|
||||
Reference in new issue
Block a user