mirror of
https://github.com/YuJunZhiXue/dsh-purge.git
synced 2026-11-28 10:10:22 +08:00
fix: 发布 1.1.45,稳住默认注入并修正清洗进度显示。
点应用即写入默认提示词,不必先保存。剥掉外层 project_instructions 壳并钉死会话系统提示,避免第二轮注入失效。未定位宿主不再显示 0/63,本机不需要的项计入已就绪。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
21dfd934a4
commit
f2c244c78f
36 files changed
+2309
-738
No files matched your search
+179
-1
@@ -301,7 +301,168 @@ export function registryInstallDirs() {
|
||||
return cachedRegistryDirs;
|
||||
}
|
||||
|
||||
/** NSIS / 商店默认位置;不是全盘扫描。自定义目录靠当前进程、卸载登记或 DSH_DESKTOP_INSTALL。 */
|
||||
const PORTABLE_INSTALL_NAMES = [
|
||||
"DeepSeek Harness",
|
||||
"DeepseekHarnessDesktop",
|
||||
"DeepSeekHarnessDesktop",
|
||||
"DSH Desktop",
|
||||
"deepseek-harness",
|
||||
];
|
||||
|
||||
function homeSiblingInstalls(env = process.env) {
|
||||
const homes = [env.DSH_HOME, env.DSH_BASE].filter(Boolean);
|
||||
const dirs = [];
|
||||
for (const raw of homes) {
|
||||
const start = path.normalize(String(raw));
|
||||
dirs.push(start, path.dirname(start), path.dirname(path.dirname(start)));
|
||||
}
|
||||
return uniquePaths(dirs).filter((dir) => firstExistingExe([dir]));
|
||||
}
|
||||
|
||||
/** 用户目录和各盘根下一层常见文件夹名。不扫整盘。 */
|
||||
function portableInstallGuesses(env = process.env) {
|
||||
const home = os.homedir();
|
||||
const cands = [];
|
||||
for (const folder of ["Desktop", "Documents", "Downloads"]) {
|
||||
for (const name of PORTABLE_INSTALL_NAMES) {
|
||||
cands.push(path.join(home, folder, name));
|
||||
}
|
||||
}
|
||||
for (const name of PORTABLE_INSTALL_NAMES) {
|
||||
cands.push(path.join(home, name));
|
||||
}
|
||||
if (process.platform === "win32") {
|
||||
for (const letter of "CDEFGHI") {
|
||||
for (const name of PORTABLE_INSTALL_NAMES) {
|
||||
cands.push(`${letter}:\\${name}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
return uniquePaths(cands).filter((dir) => firstExistingExe([dir]));
|
||||
}
|
||||
|
||||
function walkParentsForOfficialExe(start, maxUp = 8) {
|
||||
if (!start) return "";
|
||||
let dir = "";
|
||||
try {
|
||||
const abs = path.resolve(String(start));
|
||||
dir = isDir(abs) ? abs : path.dirname(abs);
|
||||
} catch {
|
||||
return "";
|
||||
}
|
||||
for (let i = 0; i < maxUp && dir; i += 1) {
|
||||
const hit = firstExistingExe([dir]);
|
||||
if (hit) return hit;
|
||||
const parent = path.dirname(dir);
|
||||
if (parent === dir) break;
|
||||
dir = parent;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
const PROCESS_EXE_SCRIPT = `
|
||||
[Console]::OutputEncoding = [System.Text.UTF8Encoding]::new($false)
|
||||
$re = 'DeepSeek Harness\\.exe$|deepseek-harness\\.exe$|DSH Desktop\\.exe$'
|
||||
$paths = @(Get-CimInstance Win32_Process -ErrorAction SilentlyContinue |
|
||||
Where-Object { $_.ExecutablePath -and $_.ExecutablePath -match $re } |
|
||||
Select-Object -ExpandProperty ExecutablePath)
|
||||
if ($paths) { @($paths) | ConvertTo-Json -Compress }
|
||||
`.trim();
|
||||
|
||||
let cachedRunningExes;
|
||||
function runningOfficialExecutables() {
|
||||
if (cachedRunningExes) return cachedRunningExes;
|
||||
if (process.platform !== "win32") {
|
||||
cachedRunningExes = [];
|
||||
return cachedRunningExes;
|
||||
}
|
||||
let text = "";
|
||||
try {
|
||||
text = execFileSync("powershell.exe", ["-NoProfile", "-Command", PROCESS_EXE_SCRIPT], {
|
||||
encoding: "utf8",
|
||||
windowsHide: true,
|
||||
timeout: 15000,
|
||||
});
|
||||
} catch {
|
||||
cachedRunningExes = [];
|
||||
return cachedRunningExes;
|
||||
}
|
||||
let rows = [];
|
||||
try {
|
||||
const parsed = JSON.parse(String(text || "").replace(/^\uFEFF/, "").trim() || "[]");
|
||||
rows = Array.isArray(parsed) ? parsed : parsed ? [parsed] : [];
|
||||
} catch {
|
||||
rows = [];
|
||||
}
|
||||
cachedRunningExes = uniquePaths(rows.map((item) => String(item || "").trim()).filter((fp) => isDesktopExecutable(fp) && isFile(fp)));
|
||||
return cachedRunningExes;
|
||||
}
|
||||
|
||||
const SHORTCUT_EXE_SCRIPT = `
|
||||
[Console]::OutputEncoding = [System.Text.UTF8Encoding]::new($false)
|
||||
$shell = New-Object -ComObject WScript.Shell
|
||||
$roots = @(
|
||||
[Environment]::GetFolderPath('StartMenu'),
|
||||
[Environment]::GetFolderPath('CommonStartMenu'),
|
||||
[Environment]::GetFolderPath('Desktop'),
|
||||
[Environment]::GetFolderPath('CommonDesktopDirectory')
|
||||
) | Where-Object { $_ }
|
||||
$pats = @('*DeepSeek*Harness*.lnk','*DSH Desktop*.lnk','*deepseek-harness*.lnk')
|
||||
$out = New-Object System.Collections.Generic.List[string]
|
||||
foreach ($root in $roots) {
|
||||
if (-not (Test-Path -LiteralPath $root)) { continue }
|
||||
foreach ($pat in $pats) {
|
||||
Get-ChildItem -LiteralPath $root -Filter $pat -Recurse -ErrorAction SilentlyContinue |
|
||||
Select-Object -First 16 | ForEach-Object {
|
||||
try {
|
||||
$t = $shell.CreateShortcut($_.FullName).TargetPath
|
||||
if ($t) { $out.Add([string]$t) }
|
||||
} catch {}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($out.Count) { @($out) | ConvertTo-Json -Compress }
|
||||
`.trim();
|
||||
|
||||
let cachedShortcutExes;
|
||||
function shortcutOfficialExecutables() {
|
||||
if (cachedShortcutExes) return cachedShortcutExes;
|
||||
if (process.platform !== "win32") {
|
||||
cachedShortcutExes = [];
|
||||
return cachedShortcutExes;
|
||||
}
|
||||
let text = "";
|
||||
try {
|
||||
text = execFileSync("powershell.exe", ["-NoProfile", "-Command", SHORTCUT_EXE_SCRIPT], {
|
||||
encoding: "utf8",
|
||||
windowsHide: true,
|
||||
timeout: 15000,
|
||||
});
|
||||
} catch {
|
||||
cachedShortcutExes = [];
|
||||
return cachedShortcutExes;
|
||||
}
|
||||
let rows = [];
|
||||
try {
|
||||
const parsed = JSON.parse(String(text || "").replace(/^\uFEFF/, "").trim() || "[]");
|
||||
rows = Array.isArray(parsed) ? parsed : parsed ? [parsed] : [];
|
||||
} catch {
|
||||
rows = [];
|
||||
}
|
||||
cachedShortcutExes = uniquePaths(rows.map((item) => String(item || "").trim()).filter((fp) => isDesktopExecutable(fp) && isFile(fp)));
|
||||
return cachedShortcutExes;
|
||||
}
|
||||
|
||||
function extraDiscoveredInstallDirs(env = process.env) {
|
||||
return uniquePaths([
|
||||
...homeSiblingInstalls(env),
|
||||
...portableInstallGuesses(env),
|
||||
...runningOfficialExecutables().map((exe) => path.dirname(exe)),
|
||||
...shortcutOfficialExecutables().map((exe) => path.dirname(exe)),
|
||||
]);
|
||||
}
|
||||
|
||||
/** NSIS / 商店默认位置;不是全盘扫描。自定义目录还看进程、快捷方式、各盘根下一层常见名。 */
|
||||
export function commonDesktopInstallDirs(env = process.env) {
|
||||
const home = os.homedir();
|
||||
const local = env.LOCALAPPDATA || path.join(home, "AppData", "Local");
|
||||
@@ -310,6 +471,7 @@ export function commonDesktopInstallDirs(env = process.env) {
|
||||
return uniquePaths([
|
||||
...extraInstallsFromEnv(env).filter(trustedInstallDir),
|
||||
...registryInstallDirs(),
|
||||
...extraDiscoveredInstallDirs(env),
|
||||
path.join(local, "Programs", "DeepSeek Harness"),
|
||||
path.join(local, "Programs", "DSH Desktop"),
|
||||
path.join(local, "DeepSeek Harness"),
|
||||
@@ -408,6 +570,22 @@ export function findDesktopAppExecutable(input = {}) {
|
||||
if (hit) return hit;
|
||||
}
|
||||
|
||||
const walkStarts = [execPath, resourcesPath, env.DSH_HOME, env.DSH_BASE];
|
||||
try { walkStarts.push(process.cwd()); } catch { /* ignore */ }
|
||||
for (const arg of argv) {
|
||||
if (typeof arg === "string") walkStarts.push(arg);
|
||||
}
|
||||
for (const start of walkStarts) {
|
||||
const hit = walkParentsForOfficialExe(start);
|
||||
if (hit) return hit;
|
||||
}
|
||||
|
||||
const running = runningOfficialExecutables();
|
||||
if (running[0]) return running[0];
|
||||
|
||||
const shortcuts = shortcutOfficialExecutables();
|
||||
if (shortcuts[0]) return shortcuts[0];
|
||||
|
||||
const guessed = firstExistingExe([
|
||||
...extraInstallsFromEnv(env),
|
||||
...commonDesktopInstallDirs(env),
|
||||
|
||||
Reference in new issue
Block a user