mirror of
https://github.com/YuJunZhiXue/dsh-purge.git
synced 2026-11-28 09:10:22 +08:00
fix: 发布 1.1.67,#85/#84 + 启动种子 + 85 项清单一次性修复
- #85 continue 续跑加 failStreak 阈值;refundContinue 不清 lastContinueSeq,连错 3 次放弃 - #84 region gate denialStream 单批 text-chunks 带 .length,不再卡宿主 UI - 启动即种子:$DSH_HOME/prompt-inject.md 为空/缺失自动写加密默认稿,用户改过的不动 - Windows 重启脚本:pid+random 命名 + 直接 wscript.exe //B,不再 /IM 杀全名 - 官方 CLI shim 原子写 + .dsh-purge.bak 可回退 - WScript clean 判定两 null 放行,首装不卡;探测缓存不缓存空结果 - scheduleAsarRenameWhenIdle 的 .rename-pending 锁时钟回拨/30min 失效自动清 - 三处 execFileSync 加 maxBuffer: 8MB,大结果不再 ENOBUFS 静默 - net-scope / identity / hooks-deny / extract-asar / client.js / core.js / update.js / skills.js / refusal-recover / rewind / rules / reapply 等共 85 项修复
This commit is contained in:
1 parent
3df4f489b1
commit
d26e69a4fa
18 files changed
+1153
-403
No files matched your search
+163
-69
@@ -66,18 +66,13 @@ const log = (config, ...args) => {
|
||||
};
|
||||
|
||||
let webTreeReady = false;
|
||||
let continueRuntime = null;
|
||||
let refusalRecoverRuntime = null;
|
||||
let savedContinueSettings = {};
|
||||
let continuePluginCfg = { ...DEFAULTS };
|
||||
|
||||
function currentContinueConfig() {
|
||||
return continueRetry.mergeConfig(continuePluginCfg, savedContinueSettings);
|
||||
}
|
||||
|
||||
function watchWebTreeReady(ctx) {
|
||||
// 必须挂在 connection 上再 await,与官方打印 URL 同一时刻。
|
||||
// apply() 里立刻 await 会在后续入口尚未入树时提前结束,session.list 仍是空的。
|
||||
// 入口复位:热重载 / disposed 后再 apply 会复用上一次 ready=true,第二次 inject 之前跑的
|
||||
// /status 把旧标志当准,这里强制重置。
|
||||
webTreeReady = false;
|
||||
const mark = () => {
|
||||
webTreeReady = true;
|
||||
};
|
||||
@@ -226,12 +221,14 @@ function addPromptSection(ctx, section) {
|
||||
};
|
||||
try { push(ctx?.systemPrompt?.ctx); } catch { /* 代理未注入时点属性会抛 */ }
|
||||
push(ctx);
|
||||
const disposers = [];
|
||||
let registered = false;
|
||||
let lastError = null;
|
||||
for (const host of hosts) {
|
||||
try {
|
||||
host.systemPrompt.section(section);
|
||||
const d = host.systemPrompt.section(section);
|
||||
registered = true;
|
||||
if (typeof d === "function") disposers.push(d);
|
||||
} catch (error) {
|
||||
const msg = String(error && error.message || error);
|
||||
if (msg.includes("already registered")) registered = true;
|
||||
@@ -239,6 +236,17 @@ function addPromptSection(ctx, section) {
|
||||
}
|
||||
}
|
||||
if (!registered && lastError) throw lastError;
|
||||
// 让 ctx.effect 在 reload / dispose 时把 section 一并撤掉;host.systemPrompt.section
|
||||
// 当前多半不返回 disposer,这段只对返回 function 的实现生效,不改变旧行为。
|
||||
if (disposers.length && typeof ctx?.effect === "function") {
|
||||
try {
|
||||
ctx.effect(() => () => {
|
||||
for (const d of disposers) {
|
||||
try { d(); } catch { /* ignore */ }
|
||||
}
|
||||
});
|
||||
} catch { /* 死 ctx */ }
|
||||
}
|
||||
}
|
||||
|
||||
export function registerPromptSections(ctx, config, _injectFile) {
|
||||
@@ -273,9 +281,13 @@ export function registerPromptSections(ctx, config, _injectFile) {
|
||||
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}`);
|
||||
// 旧版 throw 会把整个 apply 炸掉;postPrompt 只是附加段,降级 skip 不影响核心注入。
|
||||
console.warn(
|
||||
`[dsh-purge] postPromptOrder (${config.postPromptOrder}) 需要是 > ${GLOBAL_PROMPT_ORDER} 的有限数;跳过 postPrompt 段`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
ctx.systemPrompt.section({
|
||||
addPromptSection(ctx, {
|
||||
name: "dsh-purge:post",
|
||||
order: config.postPromptOrder,
|
||||
text: () => (injectAllowedNow(config) ? postPrompt : ""),
|
||||
@@ -306,14 +318,32 @@ function installMnemonMessageStrip(ctx, config = {}) {
|
||||
if (messages.length === incoming.length && Array.isArray(decision.messages)) return decision;
|
||||
return { ...decision, messages };
|
||||
};
|
||||
// 旧版 late() + queueMicrotask(late) + setTimeout(late, 1500) 三连都成功时,
|
||||
// 同一个 wrap 会在 agent/pre-step 瀑布上叠 3 层;中间插件返回的 decision 每轮被过滤 3 次。
|
||||
// 这里用 mounted 闸:第一次成功挂上就不再重试,拿回 disposer 走 ctx.effect 回收。
|
||||
let mounted = false;
|
||||
let dispose = null;
|
||||
const late = () => {
|
||||
if (mounted) return;
|
||||
try {
|
||||
ctx.on("agent/pre-step", wrap, { global: true, prepend: true });
|
||||
} catch {}
|
||||
const d = ctx.on("agent/pre-step", wrap, { global: true, prepend: true });
|
||||
mounted = true;
|
||||
if (typeof d === "function") dispose = d;
|
||||
} catch { /* 下一次重试 */ }
|
||||
};
|
||||
late();
|
||||
queueMicrotask(late);
|
||||
setTimeout(late, 1500);
|
||||
if (!mounted) queueMicrotask(late);
|
||||
let retryTimer = null;
|
||||
if (!mounted) {
|
||||
retryTimer = setTimeout(late, 1500);
|
||||
if (typeof retryTimer.unref === "function") retryTimer.unref();
|
||||
}
|
||||
try {
|
||||
ctx.effect(() => () => {
|
||||
if (retryTimer) clearTimeout(retryTimer);
|
||||
try { dispose?.(); } catch { /* ignore */ }
|
||||
});
|
||||
} catch { /* 死 ctx 时无 effect,靠下一次 apply 覆盖 */ }
|
||||
}
|
||||
|
||||
function rewriteLiveAssembly(config, assembled, context) {
|
||||
@@ -415,19 +445,30 @@ function installRewindDeriveFilter(ctx) {
|
||||
function installIdentityOverride(ctx, config = {}) {
|
||||
if (typeof ctx.on !== "function") return;
|
||||
installSubagentRoleCapture(ctx);
|
||||
// installAssembleGuard 新契约:成功返回 dispose(), 失败/幂等返回 false。统一回收,避免
|
||||
// 预设切换 + session/created 事件连环叠层,每轮注入翻倍。
|
||||
const wrapDisposers = new Set();
|
||||
const trackDisposer = (d) => {
|
||||
if (typeof d === "function") wrapDisposers.add(d);
|
||||
return d;
|
||||
};
|
||||
const wrapAssemble = () => {
|
||||
try {
|
||||
return installAssembleGuard(ctx.systemPrompt, (assembled, context) => (
|
||||
return trackDisposer(installAssembleGuard(ctx.systemPrompt, (assembled, context) => (
|
||||
rewriteLiveAssembly(config, assembled, context)
|
||||
));
|
||||
)));
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
if (!ctx.__dshPurgeAssembleHook) {
|
||||
ctx.__dshPurgeAssembleHook = true;
|
||||
ctx.on("system-prompt/assemble", async (_assembly, context, next) => {
|
||||
const assembled = typeof next === "function" ? await next() : _assembly;
|
||||
// cordis 不同版本的 waterfall 可能是 (assembly, context) 或 (assembly, context, next):
|
||||
// 旧写法把 `next` 当函数直接取第 3 位,老宿主就拿到 context 当 next,await next() 立刻抛。
|
||||
ctx.on("system-prompt/assemble", async (...args) => {
|
||||
const [assembly, context] = args;
|
||||
const next = args.length >= 3 ? args[args.length - 1] : null;
|
||||
const assembled = typeof next === "function" ? await next() : assembly;
|
||||
return rewriteLiveAssembly(config, assembled, context);
|
||||
}, { global: true, prepend: true });
|
||||
}
|
||||
@@ -435,12 +476,14 @@ function installIdentityOverride(ctx, config = {}) {
|
||||
// 宿主在 assemble 之前调用这个函数,用的就是当前模式自己的 systemPrompt。
|
||||
const prepareAssemble = (loopCtx) => {
|
||||
try { refreshHungOperator(core.findDshHome()); } catch { /* 主目录还没有提示词 */ }
|
||||
const prompt = loopCtx && loopCtx.systemPrompt;
|
||||
// loopCtx 可能是宿主的 Proxy,访问 .systemPrompt 自身就会抛(代理层尚未注入服务)。
|
||||
let prompt = null;
|
||||
try { prompt = loopCtx && loopCtx.systemPrompt; } catch { prompt = null; }
|
||||
if (prompt) {
|
||||
try {
|
||||
installAssembleGuard(prompt, (assembled, context) => (
|
||||
trackDisposer(installAssembleGuard(prompt, (assembled, context) => (
|
||||
rewriteLiveAssembly(config, assembled, context)
|
||||
));
|
||||
)));
|
||||
} catch { /* 这一层代理包不上时,下面再包插件自己的 */ }
|
||||
}
|
||||
wrapAssemble();
|
||||
@@ -456,7 +499,6 @@ function installIdentityOverride(ctx, config = {}) {
|
||||
if (Date.now() - started > 20000) clearInterval(timer);
|
||||
}, 400);
|
||||
if (typeof timer.unref === "function") timer.unref();
|
||||
try { ctx.effect(() => () => clearInterval(timer)); } catch { /* 无 effect 时靠 unref */ }
|
||||
try { ctx.on("session/created", wrapAssemble); } catch { /* ignore */ }
|
||||
try {
|
||||
ctx.on("agent-preset/selected", () => {
|
||||
@@ -470,6 +512,20 @@ function installIdentityOverride(ctx, config = {}) {
|
||||
return typeof next === "function" ? next() : payload;
|
||||
}, { global: true, prepend: true });
|
||||
} catch { /* ignore */ }
|
||||
// 热重载/卸载时统一回收:轮询 timer、guard 代理层、暴露给 agent loop 的全局钩子,
|
||||
// 都在同一个 effect 里扫掉;避免下次 apply 再绑一层造成多次写入。
|
||||
try {
|
||||
ctx.effect(() => () => {
|
||||
clearInterval(timer);
|
||||
for (const d of wrapDisposers) {
|
||||
try { d(); } catch { /* ignore */ }
|
||||
}
|
||||
wrapDisposers.clear();
|
||||
if (globalThis.__dshPurgePrepareAssemble === prepareAssemble) {
|
||||
delete globalThis.__dshPurgePrepareAssemble;
|
||||
}
|
||||
});
|
||||
} catch { /* 无 effect 时靠 unref + 下次 apply 自覆盖 */ }
|
||||
}
|
||||
|
||||
function shimNeedsPatch(state) {
|
||||
@@ -528,6 +584,8 @@ async function settleInstalledPatches(config, ctx, life) {
|
||||
}
|
||||
reapply.markSettleRestart();
|
||||
log(config, "official upgrade reapplied; restarting onto the new build");
|
||||
// ctx 可能在 reapply.reapplyInstalled 的 await 中被 dispose;重启前再查一次。
|
||||
if (life && !life.alive) return "skip:inactive";
|
||||
try {
|
||||
hostctl.scheduleRestart(null, ctx, { openBrowser: false });
|
||||
} catch (e) {
|
||||
@@ -566,6 +624,8 @@ async function settleInstalledPatches(config, ctx, life) {
|
||||
}
|
||||
reapply.markSettleRestart();
|
||||
log(config, "reapply wrote patches; restarting");
|
||||
// reapplyInstalled 自带 await;重启前再查一次 life,避免对 disposed ctx 发起 scheduleRestart。
|
||||
if (life && !life.alive) return "skip:inactive";
|
||||
try {
|
||||
// web:自愈重启不弹浏览器,关窗后不应再被反复拉起新窗口(#59/#61)。
|
||||
hostctl.scheduleRestart(null, ctx, { openBrowser: false });
|
||||
@@ -580,9 +640,13 @@ async function settleInstalledPatches(config, ctx, life) {
|
||||
if (config.autoUpdateOnStart === true) {
|
||||
updater.autoUpdateIfNeeded()
|
||||
.then((r) => {
|
||||
// ctx 可能在 autoUpdate 等待网络的过程中被 dispose(热重载 / 卸载)。
|
||||
// 回调里再碰 ctx.scheduleRestart 会命中 INACTIVE_EFFECT。
|
||||
if (life && !life.alive) return;
|
||||
log(config, "auto-update:", JSON.stringify(r));
|
||||
if (r && r.needsFullQuit) bootFullQuit = true;
|
||||
if (r && r.restartAfter && settleMayRestart(currentSettleScope())) {
|
||||
if (life && !life.alive) return;
|
||||
try { hostctl.scheduleRestart(null, ctx, { openBrowser: false }); } catch (e) {
|
||||
console.warn("[dsh-purge] auto-update restart failed:", e);
|
||||
}
|
||||
@@ -784,18 +848,22 @@ async function handlePurgeCommand(rawInput, config) {
|
||||
case "edit":
|
||||
case "e": {
|
||||
const state = await core.gatherState();
|
||||
const r = core.editOverride(state.dsh_home);
|
||||
let r = core.editOverride(state.dsh_home);
|
||||
let created = false;
|
||||
if (!r.ok && r.needCreate) {
|
||||
await core.installOverride(state.dsh_home, true);
|
||||
const r2 = core.editOverride(state.dsh_home);
|
||||
return {
|
||||
kind: "success",
|
||||
text: `已创建默认注入文件并打开编辑器:${r2.path}\n重启 dsh 生效。`,
|
||||
};
|
||||
r = core.editOverride(state.dsh_home);
|
||||
created = true;
|
||||
}
|
||||
// 旧实现:r.ok 为 false 时仍然返回 kind:"success",用户看到"已打开"但进程根本没起来。
|
||||
if (!r.ok) {
|
||||
return { kind: "error", text: r.error || "打开编辑器失败" };
|
||||
}
|
||||
return {
|
||||
kind: "success",
|
||||
text: `已打开 ${r.editor} 编辑注入文件:${r.path}\n编辑完成后重启 dsh 生效。`,
|
||||
text: created
|
||||
? `已创建默认注入文件并打开编辑器:${r.path}\n重启 dsh 生效。`
|
||||
: `已打开 ${r.editor} 编辑注入文件:${r.path}\n编辑完成后重启 dsh 生效。`,
|
||||
};
|
||||
}
|
||||
case "help":
|
||||
@@ -1036,6 +1104,14 @@ export function apply(ctx, config) {
|
||||
try {
|
||||
const home = core.pinDshHome() || core.findDshHome();
|
||||
installHungPromptGlobal();
|
||||
// Apply→cleanup→restart 成功后,默认把加密提示词 seed 进 prompt-inject.md。
|
||||
// 用户已经改过的文件不动;只有「没有」或「仍是空文件」时才补写。
|
||||
try {
|
||||
const seed = core.seedPromptInjectAtBoot(home);
|
||||
log(cfg, "seed prompt-inject:", seed?.action || "noop", seed?.reason || "");
|
||||
} catch (e) {
|
||||
console.warn("[dsh-purge] seed prompt-inject failed:", String(e && e.message ? e.message : e));
|
||||
}
|
||||
refreshHungOperator(home);
|
||||
} catch { /* 主目录还没有时,组装会再挂内置默认 */ }
|
||||
try {
|
||||
@@ -1124,10 +1200,7 @@ function applyHostHooks(ctx, cfg) {
|
||||
} catch { /* 主目录尚未就绪 */ }
|
||||
installIdentityOverride(ctx, cfg);
|
||||
installRegionGate(ctx);
|
||||
try {
|
||||
refusalRecoverRuntime?.dispose?.();
|
||||
} catch { /* ignore */ }
|
||||
refusalRecoverRuntime = refusalRecover.installRefusalRecover(ctx, {
|
||||
const refusalRecoverRuntime = refusalRecover.installRefusalRecover(ctx, {
|
||||
getConfig: () => ({
|
||||
enabled: cfg.refusalRecover !== false,
|
||||
maxPerTurn: cfg.refusalRecoverMax ?? DEFAULTS.refusalRecoverMax,
|
||||
@@ -1140,10 +1213,18 @@ function applyHostHooks(ctx, cfg) {
|
||||
const injectFile = core.findOverrideFile(core.findDshHome());
|
||||
registerPromptSections(ctx, cfg, injectFile);
|
||||
|
||||
continuePluginCfg = cfg;
|
||||
savedContinueSettings = continueRetry.loadSettings(core.findDshHome());
|
||||
try { continueRuntime?.dispose?.(); } catch { /* ignore */ }
|
||||
continueRuntime = continueRetry.installContinueRetry(ctx, { getConfig: currentContinueConfig });
|
||||
// 本次 apply 作用域内的 continue-retry 状态;旧 ctx dispose 会把这些闭包一并带走。
|
||||
const continuePluginCfg = cfg;
|
||||
const savedContinueSettings = continueRetry.loadSettings(core.findDshHome());
|
||||
const continueRuntime = continueRetry.installContinueRetry(ctx, {
|
||||
getConfig: () => continueRetry.mergeConfig(continuePluginCfg, savedContinueSettings),
|
||||
});
|
||||
try {
|
||||
ctx.effect(() => () => {
|
||||
try { refusalRecoverRuntime?.dispose?.(); } catch { /* ignore */ }
|
||||
try { continueRuntime?.dispose?.(); } catch { /* ignore */ }
|
||||
});
|
||||
} catch { /* 无 effect 时靠 cordis scope 自己回收 */ }
|
||||
|
||||
const commands = ctx.get?.("commands");
|
||||
if (commands) {
|
||||
@@ -1331,13 +1412,20 @@ function installWebServer(ctx, cfg) {
|
||||
watchWebTreeReady(ctx);
|
||||
ctx.inject(["webServer"], (host) => {
|
||||
host.effect(() => {
|
||||
const registerPluginRoute = (spec, label) => host.webServer.register({
|
||||
// 收集所有子路由的 unregister disposer;host.effect 的 cleanup 一把全撤。
|
||||
// 旧版本只注册不收,plugin reload 时上一轮的 handler 仍挂着,新的叠在之上。
|
||||
const routeDisposers = [];
|
||||
const trackRoute = (d) => {
|
||||
if (typeof d === "function") routeDisposers.push(d);
|
||||
return d;
|
||||
};
|
||||
const registerPluginRoute = (spec, label) => trackRoute(host.webServer.register({
|
||||
...spec,
|
||||
handler: async (request, response) => {
|
||||
if (!allowPluginRequest(request, response)) return;
|
||||
return spec.handler(request, response);
|
||||
},
|
||||
}, label);
|
||||
}, label));
|
||||
registerPluginRoute({
|
||||
kind: "exact",
|
||||
path: "/dsh-purge/status",
|
||||
@@ -1621,7 +1709,14 @@ function installWebServer(ctx, cfg) {
|
||||
if (shouldRestart) reapply.markSettleRestart();
|
||||
let promptInjectInstall = "skipped";
|
||||
if (hostWritten && flash.ok === true) {
|
||||
promptInjectInstall = await core.installOverride(state.dsh_home, false);
|
||||
// Apply → cleanup → restart 成功后,默认把加密提示词 seed 进 prompt-inject.md。
|
||||
// 用户自改过的内容保留;仅当文件不存在或仍是插件旧默认时才写。
|
||||
try {
|
||||
const seed = core.seedPromptInjectAtBoot(state.dsh_home);
|
||||
promptInjectInstall = seed?.action || "noop";
|
||||
} catch (e) {
|
||||
promptInjectInstall = `error:${String(e && e.message ? e.message : e)}`;
|
||||
}
|
||||
}
|
||||
const hung = refreshHungOperator(state.dsh_home);
|
||||
const override = await core.readOverrideForUi(state.dsh_home);
|
||||
@@ -1735,7 +1830,8 @@ function installWebServer(ctx, cfg) {
|
||||
if (request.method === "GET") {
|
||||
try {
|
||||
const home = core.findDshHome();
|
||||
try { core.syncPromptInjectOnDiskSync(home); } catch { /* ignore */ }
|
||||
// 面板打开 override 面板时,确保默认加密提示词已 seed;用户自改保留。
|
||||
try { core.seedPromptInjectAtBoot(home); } catch { /* ignore */ }
|
||||
refreshHungOperator(home);
|
||||
const ui = await core.readOverrideForUi(home);
|
||||
sendJson(response, 200, { ok: true, ...ui, ...injectSnapshot(home) });
|
||||
@@ -1811,8 +1907,8 @@ function installWebServer(ctx, cfg) {
|
||||
response.end();
|
||||
},
|
||||
}, "dsh-purge: own-servers");
|
||||
installRulesHttp(host.webServer);
|
||||
installSkillsHttp(host.webServer);
|
||||
trackRoute(installRulesHttp(host.webServer));
|
||||
trackRoute(installSkillsHttp(host.webServer));
|
||||
registerPluginRoute({
|
||||
kind: "exact",
|
||||
path: "/dsh-purge/restart",
|
||||
@@ -1870,6 +1966,12 @@ function installWebServer(ctx, cfg) {
|
||||
}
|
||||
},
|
||||
}, "dsh-purge: restart");
|
||||
return () => {
|
||||
for (let i = routeDisposers.length - 1; i >= 0; i -= 1) {
|
||||
try { routeDisposers[i](); } catch { /* ignore */ }
|
||||
}
|
||||
routeDisposers.length = 0;
|
||||
};
|
||||
}, "dsh-purge: http routes");
|
||||
});
|
||||
}
|
||||
@@ -1899,9 +2001,14 @@ async function handleRulesOp(op, body, queryId) {
|
||||
if (!rules.validRuleId(id) || content === null) {
|
||||
return { status: 400, ok: false, error: "id and content (string) required" };
|
||||
}
|
||||
const target = typeof body?.target === "string" ? body.target : undefined;
|
||||
// 旧版本直接把 body.target 写进 rules.saveRule;非法目标会污染 agents_path 推导。
|
||||
if (target !== undefined && !rules.validTarget(target)) {
|
||||
return { status: 400, ok: false, error: `invalid target: ${target}(只能是 AGENTS.md 或 CLAUDE.md)` };
|
||||
}
|
||||
await rules.saveRule(dshHome, id, content, {
|
||||
name: typeof body?.name === "string" ? body.name : undefined,
|
||||
target: typeof body?.target === "string" ? body.target : undefined,
|
||||
target,
|
||||
});
|
||||
refreshHungOperator(dshHome);
|
||||
return { ok: true, id, ...injectSnapshot(dshHome) };
|
||||
@@ -2031,16 +2138,16 @@ function skillRouteTail(pathname) {
|
||||
}
|
||||
|
||||
function installSkillsHttp(webServer) {
|
||||
// 旧版把 /dsh-purge/skills[/op] 和 /dsh-purge/skill[/op] 分别 exact 注册 10+ 条,再加 prefix 兜底;
|
||||
// handler 内部本来就按 tail 分发 op,exact 列表只是把路由表撑大,热重载还更难拆。
|
||||
// 用 2 条 prefix 覆盖全部,handler 的 forcedOp="" 让 body.op/tail/op 查询串继续生效。
|
||||
const stop = [];
|
||||
const add = (spec) => stop.push(registerRoute(webServer, spec));
|
||||
for (const routePath of ["/dsh-purge/skills", "/dsh-purge/skill"]) {
|
||||
add({ kind: "exact", path: routePath, handler: skillsHttpHandler("") });
|
||||
}
|
||||
add({ kind: "prefix", path: "/dsh-purge/skills", handler: skillsHttpHandler("") });
|
||||
for (const op of ["status", "read", "save", "delete", "import"]) {
|
||||
add({ kind: "exact", path: `/dsh-purge/skills/${op}`, handler: skillsHttpHandler(op) });
|
||||
add({ kind: "exact", path: `/dsh-purge/skill/${op}`, handler: skillsHttpHandler(op) });
|
||||
}
|
||||
stop.push(registerRoute(webServer, {
|
||||
kind: "prefix", path: "/dsh-purge/skills", handler: skillsHttpHandler(""),
|
||||
}));
|
||||
stop.push(registerRoute(webServer, {
|
||||
kind: "prefix", path: "/dsh-purge/skill", handler: skillsHttpHandler(""),
|
||||
}));
|
||||
return () => {
|
||||
for (let i = stop.length - 1; i >= 0; i -= 1) {
|
||||
try { stop[i]?.(); } catch { /* ignore */ }
|
||||
@@ -2049,24 +2156,11 @@ function installSkillsHttp(webServer) {
|
||||
}
|
||||
|
||||
function installRulesHttp(webServer) {
|
||||
// 同 skills:prefix 一条覆盖 /dsh-purge/rules[/op];handler 按 tail 分发 op。
|
||||
const stop = [];
|
||||
stop.push(registerRoute(webServer, {
|
||||
kind: "exact",
|
||||
path: "/dsh-purge/rules",
|
||||
handler: rulesHttpHandler(""),
|
||||
kind: "prefix", path: "/dsh-purge/rules", handler: rulesHttpHandler(""),
|
||||
}));
|
||||
stop.push(registerRoute(webServer, {
|
||||
kind: "prefix",
|
||||
path: "/dsh-purge/rules",
|
||||
handler: rulesHttpHandler(""),
|
||||
}));
|
||||
for (const op of ["status", "read", "save", "activate", "delete", "reset"]) {
|
||||
stop.push(registerRoute(webServer, {
|
||||
kind: "exact",
|
||||
path: `/dsh-purge/rules/${op}`,
|
||||
handler: rulesHttpHandler(op),
|
||||
}));
|
||||
}
|
||||
return () => {
|
||||
for (let i = stop.length - 1; i >= 0; i -= 1) {
|
||||
try { stop[i]?.(); } catch { /* ignore */ }
|
||||
|
||||
Reference in new issue
Block a user