refactor: dedupe command config lowercase helpers

This commit is contained in:
Peter Steinberger
2026-04-07 19:54:16 +01:00
parent 493e1c246e
commit 182d41d678
29 changed files with 85 additions and 45 deletions

View File

@@ -1,3 +1,4 @@
import { normalizeLowercaseStringOrEmpty } from "../string-coerce.js";
import { findCodeRegions, isInsideCode } from "./code-regions.js";
import { stripModelSpecialTokens } from "./model-special-tokens.js";
import {
@@ -133,7 +134,7 @@ function parseToolCallTagAt(text: string, start: number): ParsedToolCallTag | nu
cursor += 1;
}
const tagName = text.slice(nameStart, cursor).toLowerCase();
const tagName = normalizeLowercaseStringOrEmpty(text.slice(nameStart, cursor));
if (!TOOL_CALL_TAG_NAMES.has(tagName) || !isToolCallBoundary(text[cursor])) {
return null;
}
@@ -391,7 +392,7 @@ export function stripDowngradedToolCallText(text: string): string {
while (index < input.length && (input[index] === " " || input[index] === "\t")) {
index += 1;
}
if (input.slice(index, index + 9).toLowerCase() === "arguments") {
if (normalizeLowercaseStringOrEmpty(input.slice(index, index + 9)) === "arguments") {
index += 9;
if (input[index] === ":") {
index += 1;

View File

@@ -1,3 +1,5 @@
import { normalizeLowercaseStringOrEmpty } from "../string-coerce.js";
const FILE_REF_EXTENSIONS = ["md", "go", "py", "pl", "sh", "am", "at", "be", "cc"] as const;
export const FILE_REF_EXTENSIONS_WITH_TLD = new Set<string>(FILE_REF_EXTENSIONS);
@@ -11,7 +13,7 @@ export function isAutoLinkedFileRef(href: string, label: string): boolean {
if (dotIndex < 1) {
return false;
}
const ext = label.slice(dotIndex + 1).toLowerCase();
const ext = normalizeLowercaseStringOrEmpty(label.slice(dotIndex + 1));
if (!FILE_REF_EXTENSIONS_WITH_TLD.has(ext)) {
return false;
}