mirror of
https://github.com/YuJunZhiXue/dsh-purge.git
synced 2026-11-28 13:30:22 +08:00
feat: 补齐 0.1.2 拦截清洗并按 Hub 版式重写安装说明
对齐 Claude 清洗手法补 bash/pwsh/沙箱升级拒绝话术与梁神 phase-1;身份只跟 prompt-inject。README 前置赞赏码、免责声明,以及 AI / Hub / 手动安装。
This commit is contained in:
1 parent
6ec2115687
commit
276eaa33bd
6 files changed
+992
-201
No files matched your search
+32
-8
@@ -15,6 +15,7 @@ import * as core from "./core.js";
|
||||
import * as rules from "./rules.js";
|
||||
import {
|
||||
GLOBAL_PROMPT_ORDER,
|
||||
buildIdentityCard,
|
||||
rewritePromptAssembly,
|
||||
} from "./identity.js";
|
||||
|
||||
@@ -78,21 +79,41 @@ function renderStatus(state) {
|
||||
return out.join("\n");
|
||||
}
|
||||
|
||||
function readInjectFile(injectFile) {
|
||||
try {
|
||||
if (!injectFile || !fs.existsSync(injectFile)) return "";
|
||||
return fs.readFileSync(injectFile, "utf8").trim();
|
||||
} catch {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
export function registerPromptSections(ctx, config, injectFile) {
|
||||
// Identity card at harness:identity order so it outranks product branding.
|
||||
const identityOrder =
|
||||
typeof ctx.systemPrompt.getSectionOrder === "function"
|
||||
? ctx.systemPrompt.getSectionOrder("HARNESS_IDENTITY")
|
||||
: -1000;
|
||||
ctx.systemPrompt.section({
|
||||
name: "dsh-purge:identity",
|
||||
order: Number.isFinite(identityOrder) ? identityOrder : -1000,
|
||||
text: () => {
|
||||
if (!config.enabled) return "";
|
||||
return buildIdentityCard(readInjectFile(injectFile));
|
||||
},
|
||||
});
|
||||
|
||||
// Only inject when prompt-inject.md has content.
|
||||
// Empty/missing = no inject section → cleaned official baseline only.
|
||||
// Non-empty = inject verbatim (user prompt is primary).
|
||||
// Non-empty = inject verbatim (user prompt is primary), card first.
|
||||
ctx.systemPrompt.section({
|
||||
name: "dsh-purge",
|
||||
order: GLOBAL_PROMPT_ORDER,
|
||||
text: () => {
|
||||
if (!config.enabled) return "";
|
||||
try {
|
||||
if (!fs.existsSync(injectFile)) return "";
|
||||
return fs.readFileSync(injectFile, "utf8").trim();
|
||||
} catch {
|
||||
return "";
|
||||
}
|
||||
const raw = readInjectFile(injectFile);
|
||||
if (!raw) return "";
|
||||
return `${buildIdentityCard(raw)}\n\n${raw}`;
|
||||
},
|
||||
});
|
||||
|
||||
@@ -262,6 +283,7 @@ async function handlePurgeCommand(rawInput, config) {
|
||||
const report = await core.applyPatches(state.ai_base);
|
||||
await core.installOverride(state.dsh_home, false);
|
||||
const shimResult = await core.patchAllShims();
|
||||
const flash = core.silenceCmdFlash(state.ai_base);
|
||||
const lines = report.map((r) => {
|
||||
const m = r.status === "applied" ? "✓ 已清洗" : r.status === "already" ? "- 已是最新" : r.status === "missing_file" ? "⚠ 文件缺失" : `✗ ${r.status}`;
|
||||
return ` ${m} patch #${String(r.patch_id).padEnd(2)} ${r.name}`;
|
||||
@@ -270,6 +292,7 @@ async function handlePurgeCommand(rawInput, config) {
|
||||
for (const [dir, st] of Object.entries(shimResult)) {
|
||||
lines.push(` · ${dir} → ${typeof st === "object" ? JSON.stringify(st) : st}`);
|
||||
}
|
||||
lines.push(` cmd-flash=${flash.entry} phase-1=${flash.phase1} ok=${flash.ok}`);
|
||||
if (scrubbed.length) {
|
||||
lines.push("", "Desktop in-bin .bak scrub:");
|
||||
for (const row of scrubbed) lines.push(` ✓ ${row.dir} → ${row.cleaned.join(", ")}`);
|
||||
@@ -539,10 +562,11 @@ export function apply(ctx, config) {
|
||||
const report = await core.applyPatches(state.ai_base);
|
||||
await core.installOverride(state.dsh_home, false);
|
||||
await core.patchAllShims();
|
||||
const flash = core.silenceCmdFlash(state.ai_base);
|
||||
const applied = report.filter((r) => r.status === "applied").length;
|
||||
const already = report.filter((r) => r.status === "already").length;
|
||||
const scrubNote = scrubbed.length ? ` desktop_scrub=${scrubbed.length}` : "";
|
||||
return { text: `清洗完成 / applied=${applied}, already=${already}.${scrubNote} 重启 dsh 生效.` };
|
||||
return { text: `清洗完成 / applied=${applied}, already=${already}.${scrubNote} phase-1=${flash.phase1} 重启 dsh 生效.` };
|
||||
},
|
||||
});
|
||||
ctx.tools.register({
|
||||
|
||||
Reference in new issue
Block a user