Commit History
-
fix: harden privacy, access limits, drafts and graceful shutdown
DONG-WEI-YANGf609b94
-
fix(react): resolve stale-closure bugs surfaced by exhaustive-deps
DONG-WEI-YANG +1: Claude Sonnet 5The react-hooks/exhaustive-deps lint rule (just added in the previous commit) caught two real bugs, not just style nitpicks: 1. NewSOAP.tsx, NewNursingNote.tsx, NewNursingPlan.tsx: handleConfirm's useCallback read `orgName` state (org_name: orgName) but didn't list it as a dependency. Since the callback's other dependencies don't change every time orgName does, React can reuse a stale memoized closure — if a user fills in 機構名稱 last, without touching any other field afterward, the submitted record's org_name reflects whatever it was BEFORE that edit, not what they just typed. Reproduced and verified the fix in a real browser: filled every field, typed 機構名稱 last, submitted immediately, and confirmed via the network response that org_name now correctly matches what was actually typed (a prior row in the same table, created before this fix, has org_name permanently blank from hitting exactly this bug). 2. VoiceWizard.tsx's step-2 AI-extract handler read t…c61e606 -
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 -
test: add coverage for cmsQuota, complianceRules, crawlTargets, wordExport
DONG-WEI-YANG +1: Claude Sonnet 5Four files had zero test coverage despite being real, used product logic (flagged in the original audit backlog): - src/server/services/cmsQuota.ts: CMS-level quota math driving the usage bar in NewCareTracking.tsx (ai.getQuotaSummary). 21 tests covering frequency-string parsing across all supported formats, unknown/invalid CMS levels, unknown service codes falling back to the default price, and the remaining/utilizationPercent math (including the over-quota case where remaining floors at 0). No bugs found — all pass as written. - src/lib/complianceRules.ts: the LTC rule-hint lookup actually rendered in supervisor/NewQualityCheck.tsx. 5 tests covering known/unknown codes and case sensitivity. - src/server/services/complianceRules.ts: turned out to be a dead byte-for-byte duplicate of the lib version's data, plus two more functions (checkCompliance, getAllComplianceRules) that were never imported anywhere in the server — confirmed via grep before deleting. Same …80f80eb
-
refactor(backend): extract shared findRecordByKey helper
DONG-WEI-YANG +1: Claude Sonnet 5record.retrieve and export.word each had an identical copy-pasted block: pre-filter candidate records by keyPrefix, then bcrypt.compare against each to find the real match. Any future fix to this logic (timing-attack hardening, legacy-prefix cleanup) risked landing in only one copy. Extracted to src/server/services/recordLookup.ts. Pure refactor, no behavior change — standardized on the "金鑰錯誤或紀錄已過期" message (record.ts's version; export.ts previously said "金鑰錯誤或紀錄不存在" for the identical condition). Verified via the existing test suite, which already exercises both procedures extensively (no new tests needed for a same-behavior extraction). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>8c43020
-
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: Phase 3 — AI quality scoring + compliance analysis
DONG-WEI-YANG +1: Claude Opus 4.6 (1M context)- Add complianceRules.ts service with LTC 3.0 compliance rules for 9 service codes - Add client-side compliance rules lookup for UI hints - Add chatAndReturn for plain text LLM generation - Add generateImprovements tRPC endpoint for AI improvement suggestions - Add AI improvement button + compliance rule hints to quality check page Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>38348d5 -
feat: Phase 2 — CMS quota calculation + AI service combo suggestions
DONG-WEI-YANG +1: Claude Opus 4.6 (1M context)- Add cmsQuota.ts service with LTC 3.0 quota mapping and usage calculation - Add getQuotaSummary tRPC endpoint - Enhance case manager AI prompt with service combo suggestions by CMS level - Add QuotaDisplay component with color-coded progress bar Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>adf9b5d
-
fix: resolve HF Spaces Docker build failures — TS config + esbuild bundling
DONG-WEI-YANG +1: Claude Opus 4.6 (1M context)- Fix rootDir/include mismatch (TS6059) by switching tsconfig.server.json to noEmit - Silence baseUrl deprecation (TS5101) with ignoreDeprecations in tsconfig.json - Replace tsc emit with esbuild bundling to resolve ESM/CJS conflict at runtime - Set Vite outDir to dist/client to match express.static path - Fix RagSnippet/RagStoreStats type mapping and cron namespace import Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>d28eb48
-
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