$ show devswha/patina
Patina is a deterministic, pattern-based AI text detection and humanization tool, primarily targeting Korean but supporting English, Chinese, and Japanese. It operates as a Node.js CLI (`patina-cli`), a web API (Vercel serverless), and an agent skill (Claude Code, Codex, Cursor). The core workflow: analyze source text for AI-typical patterns (stylometry, lexicon, discourse tells), build a structured prompt, invoke an LLM backend (OpenAI, Claude, Gemini, Kimi, etc.), verify meaning preservation (MPS/fidelity), and output a humanized rewrite with a deterministic audit trail. It enforces strict meaning guards (number safety, polarity, causation) and provides scoring, diff, and verification modes. The architecture is modular: a shared deterministic analysis core (`src/features/`) runs identically in Node and browser; a prompt builder assembles context from pattern packs, document types, and personas; multiple backend adapters abstract LLM invocation; and a verification pipeline ensures fidelity. The project includes extensive research infrastructure (benchmarking, human evaluation panels, corpus management) and a commercial Pro tier with Polar license validation. It is well-tested with over 200 unit/e2e tests, CI/CD, and security hardening (SSRF guards, input fencing, atomic writes).
The LLM identified 5 files worth highlighting for reuse:
UTF-aware paragraph, sentence, and token splitting with CJK support. Exports `splitParagraphs`, `splitSentences`, `splitTokens` with configurable options. Isolated utility with no internal dependencies, easily extractable for any text processing project.
Robust extraction of JSON objects from LLM output using balanced-brace scanning and rich-object picking. Handles nested braces, JSON strings, and partial output. No internal dependencies, reusable for any project that needs to parse structured data from freeform text.
Deterministic meaning preservation signals: number safety (claims-based, supports CJK magnitudes, clock times, signed values), negation counting, and rare token recall. Pure functions with no internal imports, directly reusable for any text comparison or verification task.
Rate limiter with tier-specific limits, concurrency leases, and quota reservation. Includes KV adapters (`createMemoryKv`, `createRestKv`) that abstract storage. Isolated module with clear interfaces, reusable for any Node.js service needing rate limiting.
Backend abstraction defining concurrency slots (file-based semaphore with stale PID reclamation), retry policy, and spawn utilities (Windows batch, process groups). Exports `withBackendConcurrencySlot` and `resolveCliSpawnCommand`. Reusable for any CLI tool that needs to manage concurrent subprocess execution with resource limits.