A word-boundary rebrand regex still breaks your parsed headers
Find-and-replace rebrands break prompt headers, server names and env prefixes that code parses. The regex that nearly did it, and a five-minute check.
The product is being renamed from awe to awe. The rebrand script is 89 lines of Python, and its docstring said it was safe. It promised to leave AWE_* env names, awe_* storage keys and Installawe-style code names alone, because those have “no word boundary, so the patterns below never match them.” The main rule was \bawe\b → awe.
I believed that docstring for two days. The word boundary was the whole safety argument, and it protects the wrong things.
\bawe\b matches ### awe Memory: DEGRADED
Our engine hands the gateway a context block made of Markdown sections. The gateway reads those headers as protocol. In MCP-servers/awe-console/src/llm.ts the retry path checks first.startsWith('### awe Memory: DEGRADED'), and the double-fire guard tests /### awe Tool Results \(auto-routed/i before it decides whether to run a tool a second time. Each of those headers has a space after “awe”, and a space is a word boundary.
Hyphens are boundaries too. awe-recall, awe-script-executor and awe-enhanced-thinking are MCP server names that agent configs look up by exact string. The script protected one of them, awe-console, by name. The others would have become awe-recall, and a lookup for a server that doesn’t exist is not an error in most hosts. It just finds nothing. The same goes for “awe CLI” and “awe Bridge”, which read like product copy but are matched as presence and client identifiers.
The engine is a separate binary and the script never touches it. So after a rewrite, the engine would still send ### awe Memory: DEGRADED, the gateway would test for ### awe Memory: DEGRADED, the startsWith would return false, and the degraded-memory retry would silently stop happening. No exception, no failing request, just an agent that confidently reports “no record” about things it knows. On 2026-10-13 the rule went into my notes as a list of what the script must never touch: the ### awe … engine-to-gateway headers, hyphenated server names, “awe Bridge”, “awe CLI”, AWE_*, and lowercase awe.
Excluding paths fails when llm.ts holds both kinds of string
The standard advice for a mass rename, as in the Zebra Book’s sed recipe, is to run sed over git ls-tree output and grep -v the paths you want to skip. That works when contracts and copy live in different files. Here they share a file and sometimes a line. llm.ts contains the system prompt (“You are awe…”, which should change) a few hundred lines above the regex that parses ### awe Tool Results, which must not. Worse, the operator prompt tells the model “If the turn carries ### awe Memory: DEGRADED, re-query yourself.” That sentence is prose, but its reader is an LLM matching a literal header, so it is a contract as well.
griffen.codes gets closest: the old name is “baked into things you can never touch again,” such as localStorage keys and cookie names. Correct, but that framing is about data a user already saved. My case had no user data at all. The consumer was a sibling process in the same repo, shipped on a different release train, parsing text.
Renames that break strings another component parses
The class: a global rename can’t tell display text from a string that some other component compares against. It shows up in LLM prompt templates whose sections are split by header, in MCP server and tool names in agent configs, in Kubernetes service names and env var prefixes, and in npm or PyPI module names.
The invariant: every string literal that code compares, looks up, or matches must come out of the rename unchanged, unless both producer and consumer change in the same deploy. That is checkable. Pull out the literals that sit next to a comparison, put each through your rename, and fail if any of them changes:
#!/usr/bin/env python3
# usage (repo root): python3 contract_check.py OLD 'rename-regex' 'replacement'
import re, subprocess, sys
old, pat, rep = sys.argv[1:4]
lit = r'([^\'"`/\n]*' + re.escape(old) + r'[^\'"`/\n]*)'
CONTRACT = [
# a literal handed to a comparison, a lookup, or an env read
re.compile(r'(?:startsWith|endsWith|includes|indexOf|match|replace|split|==|!=|getenv|environ)\W{0,4}' + lit),
# a regex literal that is tested against something: /.../i.test(x)
re.compile(r'/' + lit + r'/[a-z]*\.(?:test|exec)\('),
# a SCREAMING_CASE constant: almost always a marker somebody compares to
re.compile(r'\b[A-Z][A-Z0-9_]{3,}\s*=\s*[\'"`]' + lit),
]
hits = 0
for f in subprocess.run(['git', 'ls-files'], capture_output=True, text=True).stdout.splitlines():
try:
lines = open(f, encoding='utf-8').read().splitlines()
except (UnicodeDecodeError, OSError):
continue
for n, line in enumerate(lines, 1):
for rx in CONTRACT:
for m in rx.finditer(line):
after = re.sub(pat, rep, m.group(1))
if after != m.group(1):
hits += 1
print(f'{f}:{n}: {m.group(1)!r} -> {after!r}')
print(f'{hits} parsed literal(s) your rename would change')
sys.exit(1 if hits else 0)
Passing output is one line, 0 parsed literal(s) your rename would change, with exit 0. On our gateway, python3 contract_check.py awe '\bawe\b' awe printed 73, and 26 of those were in non-test source, including src/llm.ts:4273: '### awe Tool Results \\(auto-routed' -> '### awe Tool Results \\(auto-routed' and src/graph-offer.ts:23: '### awe Workflow Offer' -> '### awe Workflow Offer'. It also flagged the “You are awe” system prompt, which is real copy and should change. The check gives you a list to triage, not a verdict, and a list is what the script was missing.
Changing the rule to \bawe(?!-)\b brought the count down to 49. That removed the server names and left every header, which is the real lesson: tightening the regex shrinks the list, but only listing the parsed literals tells you what’s still on it.
Run the check before your rename, not after. Anything on that list is a protocol string, and a protocol string gets renamed in a versioned migration with both sides moving together, not by sed.