From b24c9b838c0541492833654af0d40961c8908099 Mon Sep 17 00:00:00 2001 From: Spencer Date: Tue, 10 Mar 2026 19:46:14 +0000 Subject: [PATCH] fix(policy): remove unnecessary escapeRegex from pattern builders - Removed escapeRegex wrapping in buildFilePathArgsPattern and buildPatternArgsPattern as per review comments. - Removed the comment documenting the previous implementation in buildFilePathArgsPattern. - Confirmed autoAddToPolicyByDefault is already set to false. --- packages/core/src/policy/utils.ts | 7 ++----- packages/core/src/scheduler/policy.test.ts | 3 +-- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/packages/core/src/policy/utils.ts b/packages/core/src/policy/utils.ts index bec3e9e0cd..68f57bd51a 100644 --- a/packages/core/src/policy/utils.ts +++ b/packages/core/src/policy/utils.ts @@ -97,11 +97,8 @@ export function buildArgsPatterns( * @returns A regex string that matches "file_path":"" in a JSON string. */ export function buildFilePathArgsPattern(filePath: string): string { - // JSON.stringify safely encodes the path (handling quotes, backslashes, etc) - // and wraps it in double quotes. We simply prepend the key name and escape - // the entire sequence for Regex matching without any slicing. const encodedPath = JSON.stringify(filePath); - return escapeRegex(`"file_path":${encodedPath}`); + return `"file_path":${encodedPath}`; } /** @@ -113,5 +110,5 @@ export function buildFilePathArgsPattern(filePath: string): string { */ export function buildPatternArgsPattern(pattern: string): string { const encodedPattern = JSON.stringify(pattern); - return escapeRegex(`"pattern":${encodedPattern}`); + return `"pattern":${encodedPattern}`; } diff --git a/packages/core/src/scheduler/policy.test.ts b/packages/core/src/scheduler/policy.test.ts index fc81d2dc69..f33f40cb69 100644 --- a/packages/core/src/scheduler/policy.test.ts +++ b/packages/core/src/scheduler/policy.test.ts @@ -21,7 +21,6 @@ import { type SerializableConfirmationDetails, } from '../confirmation-bus/types.js'; import { ApprovalMode, PolicyDecision } from '../policy/types.js'; -import { escapeRegex } from '../policy/utils.js'; import { ToolConfirmationOutcome, type AnyDeclarativeTool, @@ -618,7 +617,7 @@ describe('policy.ts', () => { expect(mockMessageBus.publish).toHaveBeenCalledWith( expect.objectContaining({ toolName: 'write_file', - argsPattern: escapeRegex('"file_path":"src/foo.ts"'), + argsPattern: '"file_path":"src/foo.ts"', }), ); });