MCPcopy Create free account
hub / github.com/chhoumann/quickadd / assertAssignableVariableName

Function assertAssignableVariableName

src/ai/tools/assignableVariable.ts:9–43  ·  view source on GitHub ↗
(name: string)

Source from the content-addressed store, hash-verified

7 * {{VALUE:name}} grammar.
8 */
9export function assertAssignableVariableName(name: string): void {
10 const trimmed = name.trim();
11 if (!trimmed) throw new Error("assignToVariable cannot be empty.");
12 // `value` (the programmatic {{VALUE}} slot) and `title` (file-name title) are
13 // formatter-reserved; assigning them would silently hijack those tokens.
14 // Matched case-INSENSITIVELY because the formatter resolves {{VALUE:name}}
15 // that way (resolveExistingVariableKey -> findCaseInsensitiveMatch), so a
16 // `Value`/`TITLE` variant would otherwise slip the guard and still hijack the
17 // built-in token - consistent with isReservedVariableKey below.
18 if (new Set(["value", "title", "text", "meta"]).has(trimmed.toLowerCase())) {
19 throw new Error(
20 `assignToVariable "${trimmed}" is reserved (it would hijack a built-in formatter token).`,
21 );
22 }
23 // Case-insensitive for the same reason as the reserved-name set above: the
24 // formatter resolves {{VALUE:name}} case-insensitively, so `summary-Quoted`
25 // would still collide with the auto-generated `${key}-quoted` companion.
26 if (trimmed.toLowerCase().endsWith("-quoted")) {
27 throw new Error(
28 `assignToVariable "${trimmed}" cannot end with "-quoted" (collides with the quoted output variable).`,
29 );
30 }
31 // Reserved internal namespace (shared with the URI/CLI boundaries) and the
32 // pipe/comma characters the {{VALUE:name}} grammar cannot reference.
33 if (isReservedVariableKey(trimmed)) {
34 throw new Error(
35 `assignToVariable "${trimmed}" uses the reserved "__qa." prefix for QuickAdd internal variables.`,
36 );
37 }
38 if (/[|,]/.test(trimmed)) {
39 throw new Error(
40 `assignToVariable "${trimmed}" contains characters unreachable by {{VALUE:name}}.`,
41 );
42 }
43}

Callers 3

GetApiMethod · 0.90
assertAssignableNameMethod · 0.90

Calls 1

isReservedVariableKeyFunction · 0.90

Tested by

no test coverage detected