Merge pull request #79 from nrslib/takt/issue-25-1769915145

detectRuleIndex を最後のマッチに変更する
This commit is contained in:
nrs 2026-02-01 14:32:22 +09:00 committed by GitHub
commit 05bf51cfbb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 2 deletions

View File

@ -66,4 +66,13 @@ describe('detectRuleIndex', () => {
expect(detectRuleIndex('[AI_REVIEW:1]', 'ai_review')).toBe(0); expect(detectRuleIndex('[AI_REVIEW:1]', 'ai_review')).toBe(0);
expect(detectRuleIndex('[SECURITY_FIX:2]', 'security_fix')).toBe(1); expect(detectRuleIndex('[SECURITY_FIX:2]', 'security_fix')).toBe(1);
}); });
it('should detect last occurrence when multiple tags exist', () => {
const content = 'Previous: [AI_REVIEW:1]\n\nActual result:\n[AI_REVIEW:2]';
expect(detectRuleIndex(content, 'ai_review')).toBe(1);
});
it('should detect last match with multiple occurrences', () => {
expect(detectRuleIndex('[PLAN:1] then [PLAN:2] finally [PLAN:3]', 'plan')).toBe(2);
});
}); });

View File

@ -43,8 +43,9 @@ export interface ClaudeCallOptions {
*/ */
export function detectRuleIndex(content: string, stepName: string): number { export function detectRuleIndex(content: string, stepName: string): number {
const tag = stepName.toUpperCase(); const tag = stepName.toUpperCase();
const regex = new RegExp(`\\[${tag}:(\\d+)\\]`, 'i'); const regex = new RegExp(`\\[${tag}:(\\d+)\\]`, 'gi');
const match = content.match(regex); const matches = [...content.matchAll(regex)];
const match = matches.at(-1);
if (match?.[1]) { if (match?.[1]) {
const index = Number.parseInt(match[1], 10) - 1; const index = Number.parseInt(match[1], 10) - 1;
return index >= 0 ? index : -1; return index >= 0 ? index : -1;