fix: restore rule detail dependencies

This commit is contained in:
wren
2026-05-07 18:31:25 +08:00
parent add399e126
commit 5fc3a7a254
2 changed files with 67 additions and 15 deletions
+29 -5
View File
@@ -288,7 +288,7 @@ function parseRules(source: string): RuleSummary[] {
for (let index = start + 1; index < lines.length; index += 1) {
const line = lines[index];
const lineIndent = line.match(/^\s*/)?.[0].length || 0;
if (line.trim() && lineIndent <= baseIndent) {
if (line.trim() && lineIndent <= baseIndent && !/^\s*-\s+/.test(line)) {
break;
}
const match = line.match(/^\s*-\s+(.+)$/);
@@ -313,7 +313,7 @@ function parseRules(source: string): RuleSummary[] {
values.push(stripYamlValue(match[1]));
continue;
}
if (line.trim() && lineIndent <= indent) break;
if (line.trim() && lineIndent <= indent && !/^\s*-\s+/.test(line)) break;
}
return values;
@@ -331,7 +331,7 @@ function parseRules(source: string): RuleSummary[] {
for (let index = start + 1; index < lines.length; index += 1) {
const line = lines[index];
const lineIndent = line.match(/^\s*/)?.[0].length || 0;
if (line.trim() && lineIndent <= baseIndent) {
if (line.trim() && lineIndent <= baseIndent && !/^\s*-\s+/.test(line)) {
break;
}
const match = line.match(/^\s*-\s+(.+)$/);
@@ -342,6 +342,19 @@ function parseRules(source: string): RuleSummary[] {
return values;
};
const readStageScalar = (block: string, key: string): string => stripYamlValue(block.match(new RegExp(`^\\s+${key}:\\s*(.+)$`, 'm'))?.[1] || '');
const readStagePairValues = (block: string): string[] => {
const lines = block.split('\n');
const values: string[] = [];
for (let index = 0; index < lines.length; index += 1) {
const match = lines[index].match(/^\s+(?:source|target|ref_field):\s*(.+)$/);
if (match) {
values.push(stripYamlValue(match[1]));
}
}
return values;
};
const summarizeStage = (stageBlock: string): string => {
const fields = readStageList(stageBlock, 'fields');
const field = readStageScalar(stageBlock, 'field');
@@ -376,11 +389,22 @@ function parseRules(source: string): RuleSummary[] {
const ruleId = stripYamlValue(ruleBlock.match(/^\s*-\s+rule_id:\s*(.+)$/m)?.[1] || '');
const name = stripYamlValue(ruleBlock.match(/^\s+name:\s*(.+)$/m)?.[1] || '未命名规则');
const checkTypes = Array.from(new Set(Array.from(ruleBlock.matchAll(/^\s+(?:check|type):\s*(.+)$/gm)).map(match => stripYamlValue(match[1]))));
const stageDependencies = Array.from(ruleBlock.matchAll(/^\s+(?:field|number|chinese|left|right|left_field|right_field|target|element|seal_id|signature_id):\s*(.+)$/gm))
const stageDependencies = Array.from(ruleBlock.matchAll(/^\s+(?:field|number|chinese|left|right|left_field|right_field|target|element|seal_id|signature_id|ref_field):\s*(.+)$/gm))
.map(match => normalizeDependency(match[1]));
const stageFieldDependencies = splitBlocks(ruleBlock, /^\s{4,}-\s+id:\s*/)
.flatMap(stageBlock => [
...readStageList(stageBlock, 'fields'),
...readStagePairValues(stageBlock),
])
.map(normalizeDependency);
const prompts = readPrompts(ruleBlock);
const promptDependencies = readPromptDependencies(prompts).map(normalizeDependency);
const dependencies = Array.from(new Set([...readExplicitDependencies(ruleBlock), ...stageDependencies, ...promptDependencies]));
const dependencies = Array.from(new Set([
...readExplicitDependencies(ruleBlock),
...stageDependencies,
...stageFieldDependencies,
...promptDependencies,
]));
const scope = Array.from(new Set(Array.from(ruleBlock.matchAll(/^\s{4,}-\s*([^:\n]+)$/gm)).map(match => stripYamlValue(match[1])).filter(value => !/^\d+$/.test(value))));
const subRules = readSubRules(ruleBlock);