fix: harden stripToolCallLeaks regex for CJK/non-ASCII garbage tokens

The previous regex used \w+ for descriptor tokens between the function
name and JSON body, which only matches ASCII word characters. Model
hallucinations often inject CJK/non-ASCII text (e.g. 彩神争霸) in this
position. Switch to (?:\s+[^\s{}]+)+ to match any whitespace-separated
non-brace tokens regardless of character set.

Also removes stale backward-compat re-exports from index.ts and updates
the test import for composeDashboardContent.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Eyejoker
2026-03-25 18:06:31 +09:00
parent 6806001ed6
commit c89242b6dd
4 changed files with 26 additions and 8 deletions

View File

@@ -272,6 +272,24 @@ describe('stripToolCallLeaks', () => {
it('returns empty string for empty input', () => {
expect(stripToolCallLeaks('')).toBe('');
});
it('strips tool-call leaks with CJK/non-ASCII garbage between tokens', () => {
const cjkLeak =
'to=functions.exec_command 彩神争霸大发快三 json code {"cmd":"printf \'noop\\n\'","yield_time_ms":1000,"max_output_tokens":20}';
expect(stripToolCallLeaks(cjkLeak)).toBe('');
});
it('strips tool-call leaks with mixed non-ASCII and preserves surrounding text', () => {
const mixed =
'대기 중입니다.to=functions.exec_command 彩神争霸 json code {"cmd":"ls"}\n다음 작업';
expect(stripToolCallLeaks(mixed)).toBe('대기 중입니다.\n다음 작업');
});
it('strips tool-call leaks with multiple non-ASCII words before JSON', () => {
const leak =
'to=functions.read_file données café résumé code {"path":"/tmp/test"}';
expect(stripToolCallLeaks(leak)).toBe('');
});
});
describe('formatOutbound with tool-call leaks', () => {