From ba12c91ca0957176f412fae508288f1201b37e0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=AB=E6=88=91=E5=B0=8F=E6=9D=A8=E5=90=8C=E5=AD=A6?= <188421097+YuJunZhiXue@users.noreply.github.com> Date: Fri, 23 Oct 2026 17:46:57 +0800 Subject: [PATCH] fix: strip leftover toolFilter from installed redteam presets on DSH 0.2.1. --- lib/redteam/index.js | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/lib/redteam/index.js b/lib/redteam/index.js index f09e511..0e92bd1 100644 --- a/lib/redteam/index.js +++ b/lib/redteam/index.js @@ -191,6 +191,36 @@ function needsCompositionRepair(presetFile) { } } +/** 0.2.1 已废弃 toolFilter:旧用户预设里还留着就会让红队模式整份加载失败。 */ +function stripToolFilter(text) { + const lines = String(text || '').split(/\r?\n/) + const out = [] + let skipIndent = null + let changed = false + for (const line of lines) { + if (skipIndent !== null) { + const indent = (/^(\s*)/.exec(line) || ['', ''])[1].length + if (line.trim() !== '' && indent > skipIndent) { + changed = true + continue + } + skipIndent = null + } + const block = /^(\s*)toolFilter:\s*(?:#.*)?$/.exec(line) + if (block) { + skipIndent = block[1].length + changed = true + continue + } + if (/^\s*toolFilter:\s+\S/.test(line)) { + changed = true + continue + } + out.push(line) + } + return { text: out.join('\n'), changed } +} + /** 从独立红队包迁进 dsh-purge 后,预设里的工具行包名要跟着改。 */ function renderToolsPackage(text) { if (!text.includes('dsh-redteam-mode/tools')) { @@ -368,9 +398,10 @@ export function installPreset(options = {}) { } const rendered = renderSkillsDir(text) const tools = renderToolsPackage(rendered.text) - const delegation = repairDelegation(tools.text) + const filter = stripToolFilter(tools.text) + const delegation = repairDelegation(filter.text) const next = delegation.text - if (rendered.changed || tools.changed || delegation.changed) { + if (rendered.changed || tools.changed || filter.changed || delegation.changed) { writeFileSync(presetFile, next.replace(/\r\n/g, '\n').replace(/\r/g, '\n'), 'utf8') log( (rendered.changed @@ -380,8 +411,11 @@ export function installPreset(options = {}) { + ',已改为 dshHomePath(\'redteam/skills\')' : '') + (tools.changed ? (rendered.changed ? ';' : '') + '工具包名已改为 dsh-purge/redteam/tools' : '') + + (filter.changed + ? ((rendered.changed || tools.changed) ? ';' : '') + '已去掉 0.2.1 废弃的 toolFilter' + : '') + (delegation.changed - ? ((rendered.changed || tools.changed) ? ';' : '') + '已修复指挥派活约束 / 重新启用 subagent' + ? ((rendered.changed || tools.changed || filter.changed) ? ';' : '') + '已修复指挥派活约束 / 重新启用 subagent' : ''), ) } @@ -392,6 +426,7 @@ export function installPreset(options = {}) { const repaired = [ rendered.changed ? rendered.reason : null, tools.changed ? 'tools-package' : null, + filter.changed ? 'toolFilter' : null, delegation.changed ? 'delegation' : null, anchor === 'inserted' ? 'anchor-gate' : null, anchor === 'updated' ? 'anchor-script' : null,