mirror of
https://github.com/YuJunZhiXue/dsh-purge.git
synced 2026-11-27 14:00:22 +08:00
fix: strip leftover toolFilter from installed redteam presets on DSH 0.2.1.
This commit is contained in:
1 parent
8b6f3608fb
commit
b57944042b
1 file changed
+38
-3
+38
-3
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user