mirror of
https://github.com/YuJunZhiXue/dsh-purge.git
synced 2026-11-28 06:40:22 +08:00
feat: 发布 1.1.7,Web / 桌面端分开安装并跟随当前桌面目录清洗
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
2529db6088
commit
e84671d20a
14 files changed
+1370
-345
No files matched your search
+144
-83
@@ -12,6 +12,8 @@ import {
|
||||
resolveDshBinRoot,
|
||||
revertHideConsoleFromBin,
|
||||
} from "./hide-console.js";
|
||||
import * as desktop from "./desktop.js";
|
||||
import { adapterFor, detectSurface } from "./surface.js";
|
||||
|
||||
const isWindows = process.platform === "win32";
|
||||
const SHIM_NAMES = ["dsh.cmd", "dsh.ps1", "dsh"];
|
||||
@@ -251,27 +253,14 @@ export function dirHasDshLauncher(dir) {
|
||||
}
|
||||
|
||||
export function isDesktopCommandRuntimeDir(dir) {
|
||||
if (!dir) return false;
|
||||
const n = path.normalize(dir).replace(/\\/g, "/").toLowerCase();
|
||||
// host-commands/<profile>/bin
|
||||
if (n.includes("/host-commands/") && /(^|\/)bin\/?$/.test(n)) return true;
|
||||
// %APPDATA%/DSH Desktop/.../bin
|
||||
if (n.includes("/dsh desktop/") && /(^|\/)bin\/?$/.test(n)) return true;
|
||||
return false;
|
||||
return desktop.isSealedRuntimeDir(dir);
|
||||
}
|
||||
|
||||
export function listDesktopCommandRuntimeDirs() {
|
||||
const candidates = [...pathEnvDirs()];
|
||||
const appdata = process.env.APPDATA || path.join(os.homedir(), "AppData", "Roaming");
|
||||
const root = path.join(appdata, "DSH Desktop", "host-commands");
|
||||
if (isDir(root)) {
|
||||
try {
|
||||
for (const ent of fs.readdirSync(root, { withFileTypes: true })) {
|
||||
if (ent.isDirectory()) candidates.push(path.join(root, ent.name, "bin"));
|
||||
}
|
||||
} catch {}
|
||||
}
|
||||
return collectDirs(candidates).filter(isDesktopCommandRuntimeDir);
|
||||
return collectDirs([
|
||||
...pathEnvDirs(),
|
||||
...desktop.listSealedRuntimeBins(),
|
||||
]).filter(isDesktopCommandRuntimeDir);
|
||||
}
|
||||
|
||||
function ensureDirSync(dir) {
|
||||
@@ -722,10 +711,41 @@ export function silenceLiangshenPhase1Strip(dshHome = findDshHome()) {
|
||||
return hit;
|
||||
}
|
||||
|
||||
function realNorm(fp) {
|
||||
if (!fp) return "";
|
||||
try {
|
||||
return fs.realpathSync(fp).replace(/\\/g, "/").toLowerCase();
|
||||
} catch {
|
||||
return path.resolve(fp).replace(/\\/g, "/").toLowerCase();
|
||||
}
|
||||
}
|
||||
|
||||
export function pathZone(fp) {
|
||||
if (!fp) return "missing";
|
||||
const n = realNorm(fp);
|
||||
if (desktop.isInsideDesktopInstall(fp) || desktop.isInsideDesktopInstall(n)) return "desktop-install";
|
||||
if (/\/profiles\/desktop(\/|$)/.test(n)) return "desktop-profile";
|
||||
if (/\/profiles\/web(\/|$)/.test(n)) return "web-profile";
|
||||
if (n.includes("/npm-global")) return "web-install";
|
||||
return "shared";
|
||||
}
|
||||
|
||||
export function allowTargetPath(fp, surface = detectSurface()) {
|
||||
const zone = pathZone(fp);
|
||||
if (adapterFor(surface) === "desktop") {
|
||||
return zone === "desktop-install" || zone === "desktop-profile";
|
||||
}
|
||||
return zone !== "desktop-install" && zone !== "desktop-profile";
|
||||
}
|
||||
|
||||
function keepSurfaceFile(fp) {
|
||||
return fp && isFile(fp) && allowTargetPath(fp);
|
||||
}
|
||||
|
||||
function listLiangshenBootstrapFiles(dshHome) {
|
||||
const out = [];
|
||||
const push = (fp) => {
|
||||
if (fp && isFile(fp) && !out.includes(fp)) out.push(fp);
|
||||
if (keepSurfaceFile(fp) && !out.includes(fp)) out.push(fp);
|
||||
};
|
||||
const profilesRoot = path.join(dshHome, "profiles");
|
||||
push(path.join(profilesRoot, "web", "node_modules", "@linxin666", "dsh-liangshen", "presets", "liangshen", "tool-bootstrap.mjs"));
|
||||
@@ -811,7 +831,7 @@ export function silenceMnemonGitFlash(dshHome = findDshHome()) {
|
||||
function listMnemonIndexFiles(dshHome) {
|
||||
const out = [];
|
||||
const push = (fp) => {
|
||||
if (fp && isFile(fp) && !out.includes(fp)) out.push(fp);
|
||||
if (keepSurfaceFile(fp) && !out.includes(fp)) out.push(fp);
|
||||
};
|
||||
push(path.join(dshHome, "profiles", "web", "node_modules", "dsh-mnemon", "lib", "index.js"));
|
||||
push(path.join(dshHome, "profiles", "desktop", "node_modules", "dsh-mnemon", "lib", "index.js"));
|
||||
@@ -851,7 +871,7 @@ function listPiAiApiFiles(dshHome, aiBase, filename) {
|
||||
const out = [];
|
||||
const seen = new Set();
|
||||
const push = (fp) => {
|
||||
if (!fp || !isFile(fp)) return;
|
||||
if (!keepSurfaceFile(fp)) return;
|
||||
let key = fp;
|
||||
try { key = fs.realpathSync(fp); } catch { /* keep fp */ }
|
||||
key = String(key).toLowerCase();
|
||||
@@ -1403,6 +1423,7 @@ export function findShimDir() {
|
||||
}
|
||||
|
||||
export function listShimDirsForPatch() {
|
||||
if (adapterFor(detectSurface()) === "desktop") return [];
|
||||
return collectDirs([
|
||||
findShimDir(),
|
||||
...listDesktopCommandRuntimeDirs(),
|
||||
@@ -1413,21 +1434,61 @@ export function listShimDirsForPatch() {
|
||||
.filter((dir) => !isDesktopCommandRuntimeDir(dir));
|
||||
}
|
||||
|
||||
// Electron unpacked:app.asar.unpacked/node_modules/@deepseek-ai
|
||||
function findDesktopAiBase() {
|
||||
const candidates = [];
|
||||
if (typeof process.resourcesPath === "string" && process.resourcesPath.trim()) {
|
||||
candidates.push(path.join(process.resourcesPath, "app.asar.unpacked", "node_modules", "@deepseek-ai"));
|
||||
function findAiBaseDesktop() {
|
||||
const env = process.env.DSH_BASE;
|
||||
if (env && env.trim()) {
|
||||
const p = path.normalize(env.trim());
|
||||
if (isAiBase(p) && desktop.isInsideDesktopInstall(p)) return p;
|
||||
}
|
||||
const resolved = desktop.resolveDesktopAiBase();
|
||||
if (resolved) return resolved;
|
||||
const starts = [];
|
||||
if (process.argv[1]) {
|
||||
try { starts.push(path.resolve(process.argv[1])); } catch {}
|
||||
}
|
||||
if (process.resourcesPath) starts.push(path.normalize(process.resourcesPath));
|
||||
if (desktop.isDesktopExecutable(process.execPath)) starts.push(path.dirname(process.execPath));
|
||||
for (const start of starts) {
|
||||
try {
|
||||
const hit = walkAncestorsForAiBase(isDir(start) ? start : path.dirname(start));
|
||||
if (hit && desktop.isInsideDesktopInstall(hit)) return hit;
|
||||
} catch {}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function findAiBaseWeb() {
|
||||
const env = process.env.DSH_BASE;
|
||||
if (env && env.trim()) {
|
||||
const p = path.normalize(env.trim());
|
||||
if (isAiBase(p) && !desktop.isInsideDesktopInstall(p)) return p;
|
||||
}
|
||||
|
||||
// ELECTRON_RUN_AS_NODE 无稳定 resourcesPath,从 execPath 回推 Contents/Resources。
|
||||
const contentsDir = path.dirname(path.dirname(process.execPath));
|
||||
candidates.push(path.join(contentsDir, "Resources", "app.asar.unpacked", "node_modules", "@deepseek-ai"));
|
||||
const fromProcess = findAiBaseFromRunningProcess();
|
||||
if (fromProcess && !desktop.isInsideDesktopInstall(fromProcess)) return fromProcess;
|
||||
|
||||
for (const candidate of candidates) {
|
||||
if (fs.existsSync(path.join(candidate, "dsh-agent-instructions", "lib"))) {
|
||||
return path.normalize(candidate);
|
||||
}
|
||||
const fromHome = findAiBaseFromDshHome(findDshHome());
|
||||
if (fromHome && !desktop.isInsideDesktopInstall(fromHome)) return fromHome;
|
||||
|
||||
const nested = nestedAiPath();
|
||||
const prefix = findNpmPrefix();
|
||||
const shim = findShimDir();
|
||||
const search = [];
|
||||
for (const base of [prefix, ...launcherDirsOf(prefix), shim]) {
|
||||
search.push(...aiBaseGuessesFor(base));
|
||||
}
|
||||
for (const cand of search) {
|
||||
if (cand && isAiBase(cand) && !desktop.isInsideDesktopInstall(cand)) return path.normalize(cand);
|
||||
}
|
||||
const npmRoot = npmQuery(["root", "-g"]);
|
||||
for (const cand of [path.join(npmRoot, nested), path.join(npmRoot, "@deepseek-ai")]) {
|
||||
if (cand && isAiBase(cand) && !desktop.isInsideDesktopInstall(cand)) return path.normalize(cand);
|
||||
}
|
||||
|
||||
const needle = path.join("node_modules", nested);
|
||||
for (const sr of [findDshHome(), path.join(findDshHome(), ".."), os.homedir()]) {
|
||||
const found = findAiBaseRecursive(sr, needle, 0);
|
||||
if (found && !desktop.isInsideDesktopInstall(found)) return found;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -1444,47 +1505,20 @@ export function missingAiBaseMessage() {
|
||||
if (env.set && !env.valid) {
|
||||
return `DSH_BASE 已设置但不是有效的插件根(需要其下有 dsh-agent-instructions/lib): ${env.path}`;
|
||||
}
|
||||
if (adapterFor(detectSurface()) === "desktop") {
|
||||
const exe = desktop.findDesktopAppExecutable();
|
||||
if (exe) {
|
||||
return `已找到桌面应用 ${exe},但其 resources/app(或 app.asar.unpacked)下没有 @deepseek-ai`;
|
||||
}
|
||||
return "未定位到当前桌面应用的 @deepseek-ai。请在桌面端内打开设置再点「应用」(不要用官方 dsh)。安装目录可以是任意盘符;也可设置 DSH_DESKTOP_INSTALL 为安装目录,或 DSH_BASE 为该树下的 @deepseek-ai";
|
||||
}
|
||||
return "插件根未找到 / set DSH_BASE";
|
||||
}
|
||||
|
||||
export function findAiBase() {
|
||||
return remember("ai", () => {
|
||||
const env = process.env.DSH_BASE;
|
||||
if (env && env.trim()) {
|
||||
const p = path.normalize(env.trim());
|
||||
if (isAiBase(p)) return p;
|
||||
}
|
||||
|
||||
const fromProcess = findAiBaseFromRunningProcess();
|
||||
if (fromProcess) return fromProcess;
|
||||
|
||||
const fromHome = findAiBaseFromDshHome(findDshHome());
|
||||
if (fromHome) return fromHome;
|
||||
|
||||
const desktopBase = findDesktopAiBase();
|
||||
if (desktopBase) return desktopBase;
|
||||
|
||||
const nested = nestedAiPath();
|
||||
const prefix = findNpmPrefix();
|
||||
const shim = findShimDir();
|
||||
const search = [];
|
||||
for (const base of [prefix, ...launcherDirsOf(prefix), shim]) {
|
||||
search.push(...aiBaseGuessesFor(base));
|
||||
}
|
||||
for (const cand of search) {
|
||||
if (cand && isAiBase(cand)) return path.normalize(cand);
|
||||
}
|
||||
const npmRoot = npmQuery(["root", "-g"]);
|
||||
for (const cand of [path.join(npmRoot, nested), path.join(npmRoot, "@deepseek-ai")]) {
|
||||
if (cand && isAiBase(cand)) return path.normalize(cand);
|
||||
}
|
||||
|
||||
const needle = path.join("node_modules", nested);
|
||||
for (const sr of [findDshHome(), path.join(findDshHome(), ".."), os.homedir()]) {
|
||||
const found = findAiBaseRecursive(sr, needle, 0);
|
||||
if (found) return found;
|
||||
}
|
||||
return null;
|
||||
if (adapterFor(detectSurface()) === "desktop") return findAiBaseDesktop();
|
||||
return findAiBaseWeb();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -2217,7 +2251,7 @@ const NEW_TOOL_PATCHES = [
|
||||
{
|
||||
id: 25, name: "PRESET_FETCH_ENABLED", layer: "代码", layer_en: "Code",
|
||||
desc: "preset tool-web fetch 打开 / preset fetch enabled",
|
||||
file: ["preset-unrestricted", "preset-standard", "preset-code", "preset-cordis", "preset-ptc"],
|
||||
file: ["preset-unrestricted", "preset-standard", "preset-cordis", "preset-ptc", "preset-liangshen", "preset-liangshen-pkg"],
|
||||
rel: ["agent.cordis.yml"],
|
||||
replacements: [
|
||||
{
|
||||
@@ -2248,7 +2282,6 @@ const NEW_TOOL_PATCHES = [
|
||||
"web-app",
|
||||
"headless",
|
||||
"preset-standard",
|
||||
"preset-code",
|
||||
"preset-cordis",
|
||||
"preset-unrestricted",
|
||||
"preset-ptc",
|
||||
@@ -3034,15 +3067,15 @@ function userPresetYml(dshHome, name) {
|
||||
}
|
||||
|
||||
function firstExisting(candidates) {
|
||||
return candidates.find((fp) => fp && fs.existsSync(fp)) ?? candidates[0];
|
||||
return candidates.find((fp) => fp && fs.existsSync(fp) && allowTargetPath(fp)) ?? "";
|
||||
}
|
||||
|
||||
function allExisting(candidates) {
|
||||
const hit = [];
|
||||
for (const fp of candidates) {
|
||||
if (fp && fs.existsSync(fp) && !hit.includes(fp)) hit.push(fp);
|
||||
if (fp && fs.existsSync(fp) && allowTargetPath(fp) && !hit.includes(fp)) hit.push(fp);
|
||||
}
|
||||
return hit.length ? hit : (candidates[0] ? [candidates[0]] : []);
|
||||
return hit;
|
||||
}
|
||||
|
||||
function pathsOf(files, key) {
|
||||
@@ -3157,9 +3190,26 @@ function removeWebFetchWorkspaceLinkIfUnused(aiBase) {
|
||||
}
|
||||
}
|
||||
|
||||
function filterTargetFiles(files) {
|
||||
const out = {};
|
||||
for (const [key, val] of Object.entries(files)) {
|
||||
if (Array.isArray(val)) {
|
||||
const kept = val.filter((fp) => !fp || !fs.existsSync(fp) || allowTargetPath(fp));
|
||||
const existing = kept.filter((fp) => fp && fs.existsSync(fp) && allowTargetPath(fp));
|
||||
out[key] = existing.length ? existing : [];
|
||||
} else if (val && fs.existsSync(val) && !allowTargetPath(val)) {
|
||||
out[key] = "";
|
||||
} else {
|
||||
out[key] = val;
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
export function targetFiles(aiBase, dshHome = findDshHome()) {
|
||||
const root = packageRootFromAiBase(aiBase);
|
||||
return {
|
||||
const desktopHost = adapterFor(detectSurface()) === "desktop";
|
||||
const files = {
|
||||
"agent-instructions": firstExisting([
|
||||
path.join(aiBase, "dsh-agent-instructions", "lib", "index.js"),
|
||||
...(root ? [path.join(root, "packages", "context", "agent-instructions", "lib", "index.js")] : []),
|
||||
@@ -3178,11 +3228,17 @@ export function targetFiles(aiBase, dshHome = findDshHome()) {
|
||||
path.join(aiBase, "dsh-headless", "cordis.patch.yml"),
|
||||
...(root ? [path.join(root, "packages", "bundle", "headless", "cordis.patch.yml")] : []),
|
||||
]),
|
||||
"profile-web": firstExisting([
|
||||
path.join(dshHome, "profiles", "web", "cordis.patch.yml"),
|
||||
path.join(aiBase, "dsh-web-app", "cordis.patch.yml"),
|
||||
...(root ? [path.join(root, "packages", "bundle", "web-app", "cordis.patch.yml")] : []),
|
||||
]),
|
||||
"profile-web": firstExisting(desktopHost
|
||||
? [
|
||||
path.join(dshHome, "profiles", "desktop", "cordis.patch.yml"),
|
||||
path.join(aiBase, "dsh-web-app", "cordis.patch.yml"),
|
||||
...(root ? [path.join(root, "packages", "bundle", "web-app", "cordis.patch.yml")] : []),
|
||||
]
|
||||
: [
|
||||
path.join(dshHome, "profiles", "web", "cordis.patch.yml"),
|
||||
path.join(aiBase, "dsh-web-app", "cordis.patch.yml"),
|
||||
...(root ? [path.join(root, "packages", "bundle", "web-app", "cordis.patch.yml")] : []),
|
||||
]),
|
||||
"agent-preset": firstExisting([
|
||||
...userPresetYml(dshHome, "unrestricted"),
|
||||
...shippedPresetYml(root, "standard", aiBase),
|
||||
@@ -3250,7 +3306,6 @@ export function targetFiles(aiBase, dshHome = findDshHome()) {
|
||||
]),
|
||||
"preset-unrestricted": firstExisting(userPresetYml(dshHome, "unrestricted")),
|
||||
"preset-standard": allExisting(shippedPresetYml(root, "standard", aiBase)),
|
||||
"preset-code": allExisting(shippedPresetYml(root, "code", aiBase)),
|
||||
"preset-cordis": allExisting(shippedPresetYml(root, "cordis", aiBase)),
|
||||
"preset-minimal": allExisting(shippedPresetYml(root, "minimal", aiBase)),
|
||||
"preset-ptc": allExisting(shippedPresetYml(root, "ptc", aiBase)),
|
||||
@@ -3274,10 +3329,11 @@ export function targetFiles(aiBase, dshHome = findDshHome()) {
|
||||
...nestedPkg(aiBase, "dsh-tool-pwsh", "lib", "index.js"),
|
||||
...(root ? [path.join(root, "packages", "pwsh", "tool-pwsh", "lib", "index.js")] : []),
|
||||
]),
|
||||
"preset-liangshen": firstExisting(userPresetYml(dshHome, "liangshen")),
|
||||
"preset-liangshen-pkg": firstExisting([
|
||||
"preset-liangshen": allExisting(userPresetYml(dshHome, "liangshen")),
|
||||
"preset-liangshen-pkg": allExisting([
|
||||
path.join(dshHome, "profiles", "web", "node_modules", "@linxin666", "dsh-liangshen", "presets", "liangshen", "agent.cordis.yml"),
|
||||
path.join(dshHome, "profiles", "desktop", "node_modules", "@linxin666", "dsh-liangshen", "presets", "liangshen", "agent.cordis.yml"),
|
||||
path.join(dshHome, "profiles", "web", ".dsh-module-fallback", "node_modules", "@linxin666", "dsh-liangshen", "presets", "liangshen", "agent.cordis.yml"),
|
||||
path.join(dshHome, "profiles", "web", "node_modules", "@linxin666", "dsh-web-all", "node_modules", "@linxin666", "dsh-liangshen", "presets", "liangshen", "agent.cordis.yml"),
|
||||
]),
|
||||
"liangshen-tool-bootstrap": listLiangshenBootstrapFiles(dshHome),
|
||||
@@ -3320,6 +3376,7 @@ export function targetFiles(aiBase, dshHome = findDshHome()) {
|
||||
"pi-ai-completions": allExisting(listPiAiApiFiles(dshHome, aiBase, "openai-completions.js")),
|
||||
"pi-ai-responses-shared": allExisting(listPiAiApiFiles(dshHome, aiBase, "openai-responses-shared.js")),
|
||||
};
|
||||
return filterTargetFiles(files);
|
||||
}
|
||||
|
||||
function asLf(text) {
|
||||
@@ -4236,8 +4293,12 @@ export async function gatherState() {
|
||||
shim_bin = shimFileStatus(path.join(shimDir, "dsh"));
|
||||
}
|
||||
return {
|
||||
surface: detectSurface(),
|
||||
dsh_home: dshHome,
|
||||
ai_base: aiBase,
|
||||
desktop_install: adapterFor(detectSurface()) === "desktop"
|
||||
? (desktop.findDesktopAppExecutable() || desktop.listDesktopInstallRoots()[0] || "")
|
||||
: "",
|
||||
shim_dir: shimDir,
|
||||
desktop_runtimes,
|
||||
files,
|
||||
|
||||
Reference in new issue
Block a user