Fix PII detection to scan all message roles (#25)
authorStefan Gasser <redacted>
Sun, 11 Jan 2026 18:42:09 +0000 (19:42 +0100)
committerGitHub <redacted>
Sun, 11 Jan 2026 18:42:09 +0000 (19:42 +0100)
commit92e2f720c82784be6df0dd2127622d972f9785d3
tree0df84513bdcef0c9e67aa0fa73f1d259d9c3d3e3
parentd71269c4a737db0f253f1fb9d19ce2ec2c700b95
Fix PII detection to scan all message roles (#25)

Previously, PII detection only scanned the last user message initially,
then did a full scan only if PII was found. This caused PII in system
messages (e.g., RAG context from PDFs) to be missed entirely when the
user message contained no PII.

Changes:
- Consolidate analyzeMessages() to always scan all messages
- Scan system, developer, user, and assistant roles
- Remove analyzeAllMessages() as it's no longer needed
- Simplify decision.ts by removing the redundant full scan call

This ensures PII in system messages (common in RAG patterns) is properly
detected and masked before being sent to upstream LLMs.

Fixes #17
src/services/decision.ts
src/services/pii-detector.test.ts [new file with mode: 0644]
src/services/pii-detector.ts
git clone https://git.99rst.org/PROJECT