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.
Hostile verification of the fever continuation-word allowlist found ordinary
symptom false negatives at the authoritative zero-Hermes-call boundary:
'I have a fever right now', 'my fever is 103', 'fever started this morning',
plus 'severe pain in/around the abdomen' against the hard-coded 'my' in the
pain pattern.
- fever: drop the continuation-word allowlist entirely; the bare clinical
word escalates with any continuation. Nonclinical controls become
structured exclusions (malaria/yellow/dengue/cabin compounds, fever tree,
figurative 'feverish about'/'feverish with excitement'), so future natural
symptom wording can never be narrowed again.
- severePain: accept any determiner or none plus location qualifiers
(lower/upper/left/right) between preposition and organ.
- blood: differential audit against origin/main caught the same regression
class in the PR's rewrite: 'poop/stool with blood' (escalated on main)
was lost while 'my stool has been normal' / 'the poop contains seeds'
became false positives. Restored explicit blood shapes with bounded verbs.
RED regressions first: matrix grows 56 -> 82 pinned positives (fever +20,
severePain +6 with case/punctuation/contraction variants), a pinned
preserved-behavior list for main's blood shapes, and two boundary suites
proving every review phrase and variant escalates at the detector AND
intercepts chat at the service layer with exactly zero Hermes calls.
Gates: npm test 90/90, staging-deploy 20/20 OK, test:ui/test:photo/
test:sleek pass, check:syntax clean, check:diff clean, npm audit 0
vulnerabilities, diff secret scan clean.
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