fix: strip leftover toolFilter from installed redteam presets on DSH 0.2.1.

This commit is contained in:
叫我小杨同学 committed 2026-10-23 17:46:57 +08:00
1 parent 0aeef1e428
commit e8e444dfec
1 file changed
+38 -3
+38 -3
View File
@@ -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 后,预设里的工具行包名要跟着改。 */ /** 从独立红队包迁进 dsh-purge 后,预设里的工具行包名要跟着改。 */
function renderToolsPackage(text) { function renderToolsPackage(text) {
if (!text.includes('dsh-redteam-mode/tools')) { if (!text.includes('dsh-redteam-mode/tools')) {
@@ -368,9 +398,10 @@ export function installPreset(options = {}) {
} }
const rendered = renderSkillsDir(text) const rendered = renderSkillsDir(text)
const tools = renderToolsPackage(rendered.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 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') writeFileSync(presetFile, next.replace(/\r\n/g, '\n').replace(/\r/g, '\n'), 'utf8')
log( log(
(rendered.changed (rendered.changed
@@ -380,8 +411,11 @@ export function installPreset(options = {}) {
+ ',已改为 dshHomePath(\'redteam/skills\')' + ',已改为 dshHomePath(\'redteam/skills\')'
: '') : '')
+ (tools.changed ? (rendered.changed ? ';' : '') + '工具包名已改为 dsh-purge/redteam/tools' : '') + (tools.changed ? (rendered.changed ? ';' : '') + '工具包名已改为 dsh-purge/redteam/tools' : '')
+ (filter.changed
? ((rendered.changed || tools.changed) ? ';' : '') + '已去掉 0.2.1 废弃的 toolFilter'
: '')
+ (delegation.changed + (delegation.changed
? ((rendered.changed || tools.changed) ? ';' : '') + '已修复指挥派活约束 / 重新启用 subagent' ? ((rendered.changed || tools.changed || filter.changed) ? ';' : '') + '已修复指挥派活约束 / 重新启用 subagent'
: ''), : ''),
) )
} }
@@ -392,6 +426,7 @@ export function installPreset(options = {}) {
const repaired = [ const repaired = [
rendered.changed ? rendered.reason : null, rendered.changed ? rendered.reason : null,
tools.changed ? 'tools-package' : null, tools.changed ? 'tools-package' : null,
filter.changed ? 'toolFilter' : null,
delegation.changed ? 'delegation' : null, delegation.changed ? 'delegation' : null,
anchor === 'inserted' ? 'anchor-gate' : null, anchor === 'inserted' ? 'anchor-gate' : null,
anchor === 'updated' ? 'anchor-script' : null, anchor === 'updated' ? 'anchor-script' : null,