Commit History
-
fix: harden privacy, access limits, drafts and graceful shutdown
DONG-WEI-YANGf609b94
-
docs: document the raw-SQL DB init gotcha in feedback.ts and ragStore.ts
DONG-WEI-YANG +1: Claude Sonnet 5Investigated the "3 incompatible DB init strategies" backlog item. src/db/index.ts (main app.db) tracks real drizzle-kit migrations plus one idempotent runtime patch (ensureKeyPrefixColumn) for the column that predates migration tracking. feedback.ts and ragStore.ts instead create their tables via raw `CREATE TABLE IF NOT EXISTS` — a second, separately-maintained copy of feedback-schema.ts/rag-schema.ts's shape, currently in sync but with nothing enforcing that it stays that way. Deliberately not doing either of the two more invasive options: - Migrating these onto real drizzle-kit migrations now would mean generating a first migration against tables that already exist from raw SQL in already-deployed databases — the same "risky first migration against live data" class of problem as the key_prefix situation already deferred pending explicit user sign-off. - Building idempotent ALTER TABLE scaffolding preemptively would be speculative future-proofing for a column addition tha…720b4c5 -
chore(lint): add ESLint, fix mechanical violations, remove dead code
DONG-WEI-YANG +1: Claude Sonnet 5No lint tooling existed in this project at all. Added ESLint 9 flat config (eslint.config.js) with typescript-eslint, eslint-plugin-react, and only the two classic eslint-plugin-react-hooks rules (rules-of-hooks, exhaustive-deps) rather than its full v7 "recommended" preset — that preset bundles the entire React Compiler rule set (set-state-in-effect, immutability, purity, etc.) as errors, which flags common existing patterns (e.g. syncing a tRPC query's error into local state via useEffect) that are safe today since this codebase doesn't use the Compiler. Adopting those is a deliberate future decision, not a side effect of adding lint tooling. `npm run lint` / `lint:fix` added. Ran eslint --fix for the mechanically-safe violations (useless escapes, useless try/catch, prefer-const, unused eslint-disable directives), then fixed the rest by hand: - target="_blank" without rel="noreferrer" on 3 external links (Home.tsx, Privacy.tsx x2) — real reverse-tabnabbing risk in older browsers.…01fbb71
-
fix(db): add missing indexes on hot lookup paths
DONG-WEI-YANG +1: Claude Sonnet 5SQLite does not auto-index foreign key columns. genograms.record_id, ecomaps.record_id, and encrypted_files.record_id were all unindexed, so every genogram/ecomap load and every daily cleanup cascade-delete did a full table scan. Adds a real drizzle migration (0001) for these three — safe since nothing has ever manually patched them, unlike key_prefix. records(key_prefix, expires_at) needed the same treatment but can't go through a normal drizzle migration: key_prefix itself was never captured by a real migration (see ensureColumns.ts), so drizzle-kit's diff against the last snapshot always wants to re-propose `ALTER TABLE records ADD key_prefix` alongside any new migration touching that table -- which would throw "duplicate column name" on every already-deployed database that already has the column via the existing runtime patch. Manually stripped that line out of the generated 0001 migration (with a comment explaining why, plus a test asserting no migration file ever reintroduces it…601f85f
-
fix(db): repair key_prefix column after migrations on fresh databases
DONG-WEI-YANG +1: Claude Fable 5Migration 0000 creates records without key_prefix; the import-time ALTER in src/db/index.ts runs before migrate() on first boot, so it silently no-ops against the missing table and every records query then fails (health check: 'no such column: key_prefix'). Broke all fresh deploys. ensureKeyPrefixColumn() distinguishes added/exists/no-table instead of swallowing all errors; the server re-runs it right after migrate(). Verified: fresh data dir + production server → /health now returns ok. 287/287 tests green (4 new regression tests). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>a8dc994
-
feat(rag): genogram coding-guide seed + ragStore helpers
DONG-WEI-YANG +1: Claude Opus 4.7 (1M context)Adds: - deleteByCategory(role, category, source) — scoped DELETE for safe re-seeding without touching unrelated rows - countDocuments(role, opts?) — gate for auto-seed-if-empty (T6) - src/db/seeds/rag-genogram-guide.ts — 18 hand-authored chunks covering kinship decomposition (父系/母系/姻親/後代/直系/領養/ 同父異母/雙胞胎/離婚/同居), relationship quality enum mapping, health-status disambiguation (失智→mental, 中風→disabled, priority order), and McGoldrick schema conventions - 'db:seed:rag-genogram' package.json script Seeder is idempotent: deletes (source='manual', category='genogram') before inserting, scoped only to social_worker's rag store. 4 new unit tests covering count/delete behavior. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>ba6cdcd
-
fix: stability — graceful shutdown, health check, memory leak prevention
DONG-WEI-YANG +1: Claude Opus 4.6 (1M context)- Add SIGTERM/SIGINT handlers: close HTTP server, flush SQLite WAL, close feedback DB — prevents file lock corruption on HF Spaces restart - Strengthen /health endpoint: verify SQLite read + tinyNlp model status, return 503 on failure so HF Spaces auto-restarts unhealthy containers - Log model warmup failures instead of silently swallowing them - Cap snippetStore at 5000 entries with FIFO eviction (prevents OOM) - Add periodic cleanup of failedModels circuit breaker Map (every 5min) - Add closeFeedbackDb() export for clean shutdown Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>f60ddac
-
fix: comprehensive security hardening, iOS voice fallback, and UX resilience
DONG-WEI-YANG +1: Claude Opus 4.6 (1M context)- iOS voice fallback: MIME type detection + record-only mode when Web Speech API unavailable - HF Whisper fallback for audio transcription when Gemini fails - OpenCC s2twp layer in NLP pipeline for simplified→traditional Chinese conversion - localStorage draft autosave (useAutosave hook) across all 6 form pages - AI fill no longer overwrites user-entered fields (skip-if-filled pattern) - DB transaction wrapping for record creation (prevents orphaned data) - keyPrefix column for O(1) record lookup (replaces O(n) bcrypt scan) - Prompt injection fix: sanitizeForPrompt + Zod array/string constraints - Security headers: HSTS, X-Frame-Options, X-Content-Type-Options, Permissions-Policy - CSP: removed unsafe-eval, kept unsafe-inline for HF Spaces compatibility - AI-specific rate limiter (10 req/min), retrieve limiter tightened to 3/min - Crypto upgrades: bcrypt 10→12 rounds, key entropy 15→32 bytes - Role-recordType cross validation via Zod .refine() - fileName sanitization + file array .max(…94a07ff
-
feat: add feedback system, flow guide, Word export cleanup
DONG-WEI-YANG +1: Claude Opus 4.6 (1M context)- Isolated feedback SQLite (data/feedback.db) with submit/list API - FeedbackWidget: floating button on every page, 5 categories - FlowGuide: 8-step visual operation flow (intent proof) - Word export: removed header/footer branding (UI-only authorization) - Registered feedback + export routers in appRouter Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>9fa0cea -
feat: complete Group B+C+D — full system implementation
DONG-WEI-YANG +1: Claude Opus 4.6 (1M context)Backend (Group B): - tRPC routers: record, genogram, ecomap, voice, ltc3, consent, export, rag - Services: crypto (AES-256-GCM+HKDF), Word export, voice structuring, LTC3 matching, cleanup cron, crawl targets - Middleware: rate limiter per endpoint Frontend (Group C): - Role selection home page with 9 shared UI components - Social worker workspace: visit record + social assessment forms - Nurse workspace: SOAP + nursing note + nursing plan forms - Case manager workspace: care tracking with LTC3 code mapping - Supervisor workspace: quality check with compliance review - Canvas editors: genogram (1422 lines, McGoldrick) + ecomap (865 lines) - Voice recorder (Web Speech API) + LTC3 code suggestions - Consent dialog + key/QR display + retrieve form with QR scanner RAG + AI (Group D): - Per-role distributed SQLite RAG stores (4 databases) - Embedder (Transformers.js all-MiniLM-L6-v2) - Hybrid search (0.7*vector + 0.3*BM25) - Record ingester with PII anonymization - Auto-crawler (9 LTC r…7c280c7 -
feat: Group A foundation — scaffolding, schema, crypto, LTC3, types
DONG-WEI-YANG +1: Claude Opus 4.6 (1M context)- Project scaffolding: React + tRPC + Express + Drizzle + Vite - Database schema: records, genograms, ecomaps, encrypted_files, consent_logs, ltc3_codes, RAG tables - Crypto service: AES-256-GCM + HKDF + bcrypt + QR code generation - LTC 3.0 codes: 74 service codes with keyword matching + frequency extraction - Rate limiter: per-endpoint express-rate-limit - Shared types: all record schemas + role configs + constants - Authorization: 馬偕醫護管理專科學校智慧科技長期照顧科授權使用 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>1cab9d0