mirror of
https://github.com/YuJunZhiXue/dsh-purge.git
synced 2026-12-03 21:30:22 +08:00
fix: 桌面可补共享预设,空提示词拦截统一走一处
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
fedda6d338
commit
ed08f0c431
2 files changed
+21
-11
No files matched your search
+2
-1
@@ -734,7 +734,8 @@ export function pathZone(fp) {
|
|||||||
export function allowTargetPath(fp, surface = detectSurface()) {
|
export function allowTargetPath(fp, surface = detectSurface()) {
|
||||||
const zone = pathZone(fp);
|
const zone = pathZone(fp);
|
||||||
if (adapterFor(surface) === "desktop") {
|
if (adapterFor(surface) === "desktop") {
|
||||||
return zone === "desktop-install" || zone === "desktop-profile";
|
// 桌面只动本机桌面树 + 共享的 $DSH_HOME/.agent-presets,不碰 Web / npm-global。
|
||||||
|
return zone === "desktop-install" || zone === "desktop-profile" || zone === "shared";
|
||||||
}
|
}
|
||||||
return zone !== "desktop-install" && zone !== "desktop-profile";
|
return zone !== "desktop-install" && zone !== "desktop-profile";
|
||||||
}
|
}
|
||||||
|
|||||||
+19
-10
@@ -162,6 +162,14 @@ function injectSnapshotFromBox(dshHome, boxText) {
|
|||||||
return { injectSource: "none", injectRuleId: ruleId, needPrompt: true };
|
return { injectSource: "none", injectRuleId: ruleId, needPrompt: true };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const NEED_PROMPT_ERROR = "提示词和规则集都是空的,必须先添加提示词";
|
||||||
|
|
||||||
|
function rejectIfNeedPrompt(dshHome, boxText) {
|
||||||
|
const snap = injectSnapshotFromBox(dshHome, boxText);
|
||||||
|
if (!snap.needPrompt) return null;
|
||||||
|
return { ...snap, error: NEED_PROMPT_ERROR };
|
||||||
|
}
|
||||||
|
|
||||||
export function registerPromptSections(ctx, config, _injectFile) {
|
export function registerPromptSections(ctx, config, _injectFile) {
|
||||||
ctx.systemPrompt.section({
|
ctx.systemPrompt.section({
|
||||||
name: "dsh-purge",
|
name: "dsh-purge",
|
||||||
@@ -302,9 +310,10 @@ async function handlePurgeCommand(rawInput, config) {
|
|||||||
if (!state.ai_base) {
|
if (!state.ai_base) {
|
||||||
return { kind: "error", text: core.missingAiBaseMessage() };
|
return { kind: "error", text: core.missingAiBaseMessage() };
|
||||||
}
|
}
|
||||||
|
const blocked = rejectIfNeedPrompt(state.dsh_home);
|
||||||
|
if (blocked) return { kind: "error", text: blocked.error };
|
||||||
await core.backupAll(state.ai_base);
|
await core.backupAll(state.ai_base);
|
||||||
const report = await core.applyPatches(state.ai_base);
|
const report = await core.applyPatches(state.ai_base);
|
||||||
await core.installOverride(state.dsh_home, false);
|
|
||||||
const shimResult = await core.patchAllShims();
|
const shimResult = await core.patchAllShims();
|
||||||
const flash = core.silenceCmdFlash(state.ai_base);
|
const flash = core.silenceCmdFlash(state.ai_base);
|
||||||
const lines = report.map((r) => {
|
const lines = report.map((r) => {
|
||||||
@@ -646,9 +655,10 @@ export function apply(ctx, config) {
|
|||||||
const scrubbed = core.sanitizeDesktopCommandRuntimes();
|
const scrubbed = core.sanitizeDesktopCommandRuntimes();
|
||||||
const state = await core.gatherState();
|
const state = await core.gatherState();
|
||||||
if (!state.ai_base) return { text: "ERROR: " + core.missingAiBaseMessage() };
|
if (!state.ai_base) return { text: "ERROR: " + core.missingAiBaseMessage() };
|
||||||
|
const blocked = rejectIfNeedPrompt(state.dsh_home);
|
||||||
|
if (blocked) return { text: "ERROR: " + blocked.error };
|
||||||
await core.backupAll(state.ai_base);
|
await core.backupAll(state.ai_base);
|
||||||
const report = await core.applyPatches(state.ai_base);
|
const report = await core.applyPatches(state.ai_base);
|
||||||
await core.installOverride(state.dsh_home, false);
|
|
||||||
await core.patchAllShims();
|
await core.patchAllShims();
|
||||||
const flash = core.silenceCmdFlash(state.ai_base);
|
const flash = core.silenceCmdFlash(state.ai_base);
|
||||||
const applied = report.filter((r) => r.status === "applied").length;
|
const applied = report.filter((r) => r.status === "applied").length;
|
||||||
@@ -691,6 +701,7 @@ export function apply(ctx, config) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function installWebServer(ctx, cfg) {
|
function installWebServer(ctx, cfg) {
|
||||||
|
// 桌面端内嵌 @deepseek-ai/dsh-web-app,设置页同样走 webServer(常见 43120),不是只给官方 dsh web。
|
||||||
watchWebTreeReady(ctx);
|
watchWebTreeReady(ctx);
|
||||||
ctx.inject(["webServer"], (host) => {
|
ctx.inject(["webServer"], (host) => {
|
||||||
host.effect(() => {
|
host.effect(() => {
|
||||||
@@ -930,15 +941,14 @@ function installWebServer(ctx, cfg) {
|
|||||||
const body = await readJsonBody(request);
|
const body = await readJsonBody(request);
|
||||||
const ui = await core.readOverrideForUi(state.dsh_home);
|
const ui = await core.readOverrideForUi(state.dsh_home);
|
||||||
const boxText = typeof body?.content === "string" ? body.content : ui.content;
|
const boxText = typeof body?.content === "string" ? body.content : ui.content;
|
||||||
const snap = injectSnapshotFromBox(state.dsh_home, boxText);
|
const blocked = rejectIfNeedPrompt(state.dsh_home, boxText);
|
||||||
if (snap.needPrompt) {
|
if (blocked) {
|
||||||
sendJson(response, 400, {
|
sendJson(response, 400, {
|
||||||
ok: false,
|
ok: false,
|
||||||
needPrompt: true,
|
needPrompt: true,
|
||||||
error: "提示词和规则集都是空的,必须先添加提示词",
|
|
||||||
override_content: boxText,
|
override_content: boxText,
|
||||||
defaultContent: ui.defaultContent,
|
defaultContent: ui.defaultContent,
|
||||||
...snap,
|
...blocked,
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1051,13 +1061,12 @@ function installWebServer(ctx, cfg) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const home = core.findDshHome();
|
const home = core.findDshHome();
|
||||||
const snap = injectSnapshotFromBox(home, content);
|
const blocked = rejectIfNeedPrompt(home, content);
|
||||||
if (snap.needPrompt) {
|
if (blocked) {
|
||||||
sendJson(response, 400, {
|
sendJson(response, 400, {
|
||||||
ok: false,
|
ok: false,
|
||||||
error: "提示词和规则集都是空的,必须先添加提示词",
|
|
||||||
content,
|
content,
|
||||||
...snap,
|
...blocked,
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user