mirror of
https://github.com/YuJunZhiXue/dsh-purge.git
synced 2026-11-28 12:50:23 +08:00
feat: upgrade purge patches to 25 and release 0.1.1-rc.1-0.2
This commit is contained in:
1 parent
8a190b66c4
commit
36b747f410
12 files changed
+1177
-82
No files matched your search
+37
-16
@@ -17,9 +17,13 @@ const DEFAULTS = {
|
||||
enabled: true,
|
||||
autoApplyOnStart: true,
|
||||
autoRevertOnMissing: false,
|
||||
postPrompt: "",
|
||||
postPromptOrder: 1000,
|
||||
verbose: false,
|
||||
};
|
||||
|
||||
const GLOBAL_PROMPT_ORDER = 100;
|
||||
|
||||
const log = (config, ...args) => {
|
||||
if (config?.verbose) console.log("[dsh-purge]", ...args);
|
||||
};
|
||||
@@ -63,6 +67,33 @@ function renderStatus(state) {
|
||||
return out.join("\n");
|
||||
}
|
||||
|
||||
export function registerPromptSections(ctx, config, injectFile) {
|
||||
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 postPrompt = typeof config.postPrompt === "string" ? config.postPrompt.trim() : "";
|
||||
if (!postPrompt) return;
|
||||
if (!Number.isFinite(config.postPromptOrder) || config.postPromptOrder <= GLOBAL_PROMPT_ORDER) {
|
||||
throw new TypeError(`postPromptOrder must be a finite number greater than ${GLOBAL_PROMPT_ORDER}`);
|
||||
}
|
||||
ctx.systemPrompt.section({
|
||||
name: "dsh-purge:post",
|
||||
order: config.postPromptOrder,
|
||||
text: postPrompt,
|
||||
});
|
||||
}
|
||||
|
||||
// ── 自动重洗 ──────────────────────────────────────────────────────
|
||||
|
||||
async function autoApply(config) {
|
||||
@@ -190,20 +221,7 @@ export function apply(ctx, config) {
|
||||
|
||||
// 2. systemPrompt 注入(注入用户"全局提示词"内容;默认空则什么都不注入)
|
||||
const injectFile = core.findOverrideFile(core.findDshHome());
|
||||
ctx.systemPrompt.section({
|
||||
name: "dsh-purge",
|
||||
order: 100,
|
||||
text: () => {
|
||||
if (!cfg.enabled) return "";
|
||||
try {
|
||||
if (!fs.existsSync(injectFile)) return "";
|
||||
const content = fs.readFileSync(injectFile, "utf8").trim();
|
||||
return content;
|
||||
} catch {
|
||||
return "";
|
||||
}
|
||||
},
|
||||
});
|
||||
registerPromptSections(ctx, cfg, injectFile);
|
||||
|
||||
// 3. /purge 命令
|
||||
const commands = ctx.get?.("commands");
|
||||
@@ -220,7 +238,7 @@ export function apply(ctx, config) {
|
||||
if (ctx.tools) {
|
||||
ctx.tools.register({
|
||||
name: "purge_status",
|
||||
description: "查看 dsh 指令权威性清洗状态(8 patch 清洗进度、shim 注入、override 文件)。",
|
||||
description: `查看 dsh 指令权威性清洗状态(${core.ALL_PATCHES.length} patch 清洗进度、shim 注入、override 文件)。`,
|
||||
parameters: {
|
||||
type: "object",
|
||||
additionalProperties: false,
|
||||
@@ -241,7 +259,7 @@ export function apply(ctx, config) {
|
||||
});
|
||||
ctx.tools.register({
|
||||
name: "purge_apply",
|
||||
description: "应用 dsh 指令权威性清洗:8 patch(提示词层+代码层)+ shim 注入 + override 文件。需重启 dsh 完全生效。",
|
||||
description: `应用 dsh 指令权威性清洗:${core.ALL_PATCHES.length} patch(提示词层+代码默认+引擎级审批/沙箱绕过)+ shim 注入 + override 文件。需重启 dsh 完全生效。`,
|
||||
parameters: {
|
||||
type: "object",
|
||||
additionalProperties: false,
|
||||
@@ -316,6 +334,8 @@ function installWebServer(ctx, cfg) {
|
||||
}
|
||||
try {
|
||||
const state = await core.gatherState();
|
||||
const patch_names = {};
|
||||
for (const p of core.ALL_PATCHES) patch_names[String(p.id)] = p.name;
|
||||
sendJson(response, 200, {
|
||||
ok: true,
|
||||
ai_base: state.ai_base,
|
||||
@@ -323,6 +343,7 @@ function installWebServer(ctx, cfg) {
|
||||
patches_pending: state.patches_pending,
|
||||
patches_total: core.ALL_PATCHES.length,
|
||||
patch_status: state.patch_status,
|
||||
patch_names,
|
||||
shim_cmd: state.shim_cmd,
|
||||
shim_ps1: state.shim_ps1,
|
||||
has_backup: state.has_backup,
|
||||
|
||||
Reference in new issue
Block a user