Second hostile review of 1aadca91 found nine ordinary urgent phrasings
bypassing the deterministic gate at detector and service layers, plus
punctuation-fragile contextual exclusions. Replace the accumulated
narrow regex table with a structured, versioned, frozen urgent-expression
grammar and one shared surface normalizer:
- normalizeUrgentText: case folding, apostrophe unification, contraction
expansion (can't/cant/can not -> cannot, haven't -> have not, ...),
hyphen splitting, punctuation stripping, whitespace collapse
- URGENT_EXPRESSION_GRAMMAR v2.0: per-flag ordered match expressions with
bounded nonclinical anchor exclusions; anchors veto only the occurrence
they sit beside (36-char window), so arbitrary future symptom language
keeps escalating with no continuation-word allowlist
- new RED->GREEN coverage at every layer: 9 review phrases + 5 prior
phrases with tense/plural/pronoun/word-order/case/contraction/
punctuation variants, normalization-equivalence groups, anti-allowlist
continuation sweep (147 combos), grammar structure audit, service
zero-Hermes-call interception, and live-HTTP wiring proof with the
bounded fake adapter (tests/escalation-http.test.js)
Gates: npm test 99/99, check:syntax, check:diff, audit 0 vulns,
staging-deploy 20/20, test:ui/test:photo/test:sleek against this
checkout. No merge, no deploy.
Issue #21 (epic #5). Prove model behavior can never suppress or soften
urgent symptom handling.
- Pin the six authoritative red flags, their canonical order, and the
exact urgent copy as read-only exports; hostile provider output
cannot reassemble it.
- Grow the positive text matrix from 24 to 56 pinned clinical phrases
across all flags (bloody stool, dark-red/black descriptions, severe
abdominal pain variants, vomiting tenses/slang, fever phrasings,
inability to pass gas) and pin 27 idiomatic negatives that must not
escalate (threw up my hands, yellow fever history class, black tea).
- Authoritative boundary suite: every red-flag phrase and confirmed
ledger symptom/note intercepts chat with zero Hermes calls;
malicious/missing provider replies cannot weaken the deterministic
response; truthy junk symptoms can neither fabricate nor suppress
escalation.
- Wiring suite: the single chat gate screens urgency before any agent
turn in both service and browser code; detection stays centralized
in the frozen domain pattern table.
RED evidence: URGENT_MESSAGE unexported, 9 matrix misses (bleeding from
my rectum, bloody stool/poop, severe pain in my abdomen), 8 false
positives (I threw up my hands, feverish about the election).
GREEN: 87/87 npm test, syntax/diff gates clean, 0 vulnerabilities,
browser suites pass with zero /api/agent/chat calls on urgent input.
Closes#21