Commit History
-
Improve diagram layout, relationship correctness and validation; patch dependencies Running
DONG-WEI-YANG6ec5c72 -
fix: harden privacy, access limits, drafts and graceful shutdown
DONG-WEI-YANGf609b94
-
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(ai): log deviceAI runBuiltIn/runWasm failures instead of failing silently
DONG-WEI-YANG +1: Claude Sonnet 5Both catch blocks returned null with zero console output on failure. Falling back to the server is correct behavior; being silent about why is not -- this exact silent-catch shape (fail, return null, no log) is what let the offline-AI feature stay completely broken in production for months with no signal anywhere. Adds console.warn in both, verified with a test asserting the warning actually fires on a wllama init failure. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>130817c -
fix(security): patch critical vulnerabilities from full-app audit
DONG-WEI-YANG +1: Claude Sonnet 5- record.retrieve/genogram.load/ecomap.load now travel via POST body instead of GET, so the record access key never lands in URL query strings, proxy logs, browser history, or Referer headers (httpBatchLink methodOverride + allowMethodOverride) - express.json body limit 2mb -> 20mb, and ai.ts's imageBase64 gets an explicit .max() -- the old 2mb cap silently 413'd realistic photo uploads and multi-file record attachments before Zod ever ran - app.use('/trpc/ai.', aiLimiter) never actually matched in Express 5 (a path-prefix mount only matches when followed by '/' or EOS, never a procedure name) -- every paid AI call was silently running under only the generic 100/min limiter instead of the intended 10/min. Fixed via explicit req.path.startsWith() check; also caps tRPC batch size so one HTTP request can't smuggle dozens of AI calls past the per-request limiter - genogram.save/ecomap.save never verified the caller's key against the record's keyHash before encryptin…b81c93f
-
fix(offline-ai): 2 more bugs found via live browser inference (CSP wasm-eval, OPFS cache reporting)
DONG-WEI-YANG +1: Claude Fable 5Continuing the T11 smoke test after the prior 3-bug fix, live inference in Chromium surfaced two more real bugs: 1. CSP script-src lacked 'wasm-unsafe-eval', so WebAssembly.instantiate() itself was blocked ("Compiling or instantiating WebAssembly module violates CSP") — this only surfaces after the model finishes downloading, which is why it wasn't caught by the earlier connect-src/worker-src fix. Verified: with this added, a full download + WASM inference round-trip now succeeds end-to-end (confirmed via a real Qwen2.5-0.5B GGUF producing correct Traditional Chinese output in Chromium). 2. getCacheSize()/clearCache() checked the browser Cache API, but wllama 2.x actually persists downloaded models via OPFS through a CacheManager — Cache API was always empty, so the Privacy page permanently showed "未下載" (not cached) and the "清除模型快取" button stayed disabled even with a fully downloaded, working model. CacheManager has no standalone named export (only `e…03d636e -
fix(offline-ai): wllama never actually worked in production (3 bugs)
DONG-WEI-YANG +1: Claude Fable 5T11 cross-browser smoke test surfaced that the offline-AI feature shipped in the browser-wasm-wllama plan was completely non-functional end-to-end, with every failure silently swallowed (empty catch blocks / no banner update), so it looked done in code review but never ran in a real browser: 1. wllamaProvider.ts called `new Wllama()` with no arguments. The library requires an AssetsPathConfig as the first constructor arg and throws synchronously without it ("AssetsPathConfig is required"). Fixed by importing the single/multi-thread wasm files via Vite `?url` so they're bundled as static assets and passed to the constructor. Also added src/vite-env.d.ts to tsconfig.server.json's include so tsc recognizes the `*?url` ambient module type Vite declares. 2. CSP connect-src only allowed `https://*.huggingface.co`, which does NOT match the bare `https://huggingface.co` apex domain the default GGUF model URL points to (CSP wildcard subdomains never match the parent …2258f1d
-
refactor(ui): extract shouldOfferOfflineAI() helper, DRY the modal guard
DONG-WEI-YANG +1: Claude Opus 4.7 (1M context)Replaces 4 inline copies (3 in AiFillButton, 1 in SmartTranscript) of the enabled/declined check with a single helper in deviceAI.ts. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>dbfa411 -
refactor(device-ai): make Privacy dynamic-import wllamaProvider, eliminate Vite warning
DONG-WEI-YANG +1: Claude Opus 4.7 (1M context)DEFAULT_MODEL_URL moved to the lightweight wllamaProgress.ts (re-exported from wllamaProvider for back-compat). Privacy.tsx now dynamic-imports the wllama lifecycle functions inside event handlers instead of statically. With no static importers, wllamaProvider code-splits cleanly — the INEFFECTIVE_DYNAMIC_IMPORT warning is gone. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>394cdce -
refactor(device-ai): extract wllamaProgress pub-sub, fix Vite chunk warning
DONG-WEI-YANG +1: Claude Opus 4.7 (1M context)OfflineAIBanner now imports download-progress from the lightweight wllamaProgress.ts instead of the heavy wllamaProvider.ts — removing the static-import edge that prevented wllamaProvider from code-splitting. wllamaProvider re-exports onDownloadProgress/getDownloadProgress so existing importers (tests) are unchanged. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>a70fc1e -
feat(device-ai): replace runWasm stub with wllama integration
DONG-WEI-YANG +1: Claude Opus 4.7 (1M context)runWasm now talks to wllamaProvider (T1-T4): lazy-loads wllama, gated on localStorage `deviceAI.enabled` flag, builds task-specific 繁體中文 system prompts, returns null on any failure so the caller falls back to the server. buildMessagesForTask covers all 4 task types (correct / summarize / soap_classify / improve_suggest). The `correct` task — STT error correction — is the highest-value offline path. 6 new integration tests in tests/deviceAI.test.ts verify routing, opt-in gating, init-failure fallback, and abort handling. 249 -> 255. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>7ed6dd5
-
feat(device-ai): enable wasm path for all 4 task types
DONG-WEI-YANG64be83b -
feat(device-ai): wllama failure handling (quota / invalid GGUF / abort)
DONG-WEI-YANG880dca1 -
feat(device-ai): wllama download progress + cache size/clear
DONG-WEI-YANGf51be6b -
feat(device-ai): wllama session lifecycle with lazy load and cache
DONG-WEI-YANG +1: Claude Sonnet 4.6Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>62813fb -
feat(device-ai): scaffold wllamaProvider with @wllama /wllama dep
DONG-WEI-YANG7b971a5
-
test: add scenario, fuzz, adversarial tests (119 total) + fix canHandle crash
DONG-WEI-YANG +1: Claude Opus 4.6 (1M context)Three test dimensions (James Whittaker Tourist Methodology): - scenario.test.ts: real-world usage (STT correction, 3-gen genogram, device AI) - fuzz.test.ts: random/abnormal inputs (empty, long, special chars, XSS) - adversarial.test.ts: tourist zones (commercial, historical, rundown, tourist) Fix: canHandle() crashed on unknown task type (null guard added) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>2770a9b -
feat: family-unit-aware layoutGenogram with backward-compatible signature
DONG-WEI-YANG +1: Claude Sonnet 4.6Rewrites layoutGenogram() to accept an optional relationships parameter. When provided, couples are placed side-by-side (male left, female right) and children are centered below their parents' midpoint per McGoldrick standard. Old simple row-based layout is preserved as layoutGenogramSimple() and used as fallback when no relationships are given, keeping all existing callers intact. Adds 4 new tests covering couple placement, child centering, three generations, and no-relationships fallback (11/11 autoLayout tests passing). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>a90b098 -
feat: add buildFamilyUnits(), FamilyUnit, LayoutRelationship types with tests
DONG-WEI-YANG +1: Claude Sonnet 4.6Extends LayoutMember with optional gender/is_client fields. Exports LayoutRelationship and FamilyUnit interfaces. buildFamilyUnits() groups members into couple/single-parent family units, deduplicates children linked by both parents, handles divorced/separated/partner couple types, and sorts children by birth_year. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>938f2c5 -
feat: add DeviceAI service with BuiltInAI/WASM routing and full test coverage
DONG-WEI-YANG +1: Claude Sonnet 4.6Implements the client-side device AI acceleration layer (Task 3). detectCapabilities() probes window.ai (Chrome Prompt API) and WebAssembly, caches results, and routes soap_classify/summarize/correct/improve_suggest to the best available on-device provider or returns null for server fallback. WASM provider is a stub pending onnxruntime-web integration (Task 8+). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>c90c825 -
feat: vocabulary matching engine with 2-layer STT correction + vitest suite
DONG-WEI-YANG +1: Claude Sonnet 4.6Implements loadVocab/loadRoleVocab (with module-level cache), pinyinDistance (tone-stripped Levenshtein), and correctWithVocab (greedy sliding window, layer 1 exact guard + layer 2 O(1) sttError Map lookup). All 14 tests pass. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>39b9013
-
feat: add role-specific vocabulary data for STT correction (723 terms)
DONG-WEI-YANG +1: Claude Opus 4.6 (1M context)5 JSON files with pinyin and STT error mappings: - shared.json (159 terms): diseases, kinship, LTC services - nurse.json (202 terms): SOAP, vitals, nursing care, meds - socialWorker.json (152 terms): assessment, family dynamics - caseManager.json (120 terms): CMS, care plans, tracking - supervisor.json (90 terms): quality, compliance, audit Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>334eb15
-
feat: voice wizard, quick record UI, abuse arrow, quick mode toggle
DONG-WEI-YANG +1: Claude Opus 4.6 (1M context)Voice Step Wizard (/wizard): - 5-step guided genogram/ecomap construction via voice - Step 1: client info, Step 2: family members, Step 3: relationships - Step 4: external resources (ecomap), Step 5: preview + save - Each step: independent recording → AI extraction → editable cards - Embedded GenogramEditor/EcomapEditor preview in final step Quick Record (/quick): - Streamlined 3-step flow: choose role → voice record → AI fill → save - Designed for 3-minute record completion - Large role selection cards, full-width voice area Quick Mode Toggle (all 6 form pages): - "快速模式/完整模式" toggle button in page headers - Quick mode hides secondary form sections, keeps voice + key fields - Essential fields per role always visible Abuse Directed Arrow: - New quality type 'abuse' with zigzag + directional arrow - Arrow points from abuser (from_id) → victim (to_id) - AI prompt supports 虐待/施暴/家暴 Chinese mappings Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>5c4cd74 -
feat: complete McGoldrick-Gerson genogram + Hartman ecomap standard compliance
DONG-WEI-YANG +1: Claude Opus 4.6 (1M context)Genogram — new relationship qualities: - close_conflicted: double parallel line + zigzag overlay (親密衝突) - fused_hostile: triple parallel line + zigzag overlay (融合敵對) Genogram — new relationship types: - adopted: dashed line (收養) - foster: dotted line (寄養) - identical_twin / fraternal_twin: twin relationship types (雙胞胎) Genogram — new health type: - substance_abuse: dark amber color (物質濫用/酗酒/藥物成癮) Genogram — special member symbols: - pregnancy: small triangle, light blue (懷孕) - miscarriage: small triangle with X (流產) - stillbirth: small triangle with X, gray (死產) Genogram — layout: - autoLayout now sorts siblings by birth_year (oldest on left per standard) Ecomap — new system types: - recreation: emerald, musical note icon (休閒) - transportation: sky blue, bus icon (交通) - other: stone, asterisk icon (自訂) Ecomap — new flow option: - none: no arrows drawn (無流動) All Zod schemas, AI prompts, coercion enums, and offline extractor updated to match new types across 8 files. Co-Authored-…0aaeec3 -
fix: genogram/ecomap line rendering to McGoldrick-Gerson standard
DONG-WEI-YANG +1: Claude Opus 4.6 (1M context)Genogram (家系圖): - Close → double parallel line (═══) instead of thick single line - Very close/fused → triple parallel line (≡≡≡) instead of double - Cutoff → line with gap + perpendicular bars (─┃ ┃─) instead of solid - Conflict/hostile zigzag improved: sharper peaks, larger amplitude - Added 'separated' (分居) relationship type with single slash symbol Ecomap (生態圖): - Stressful connection → zigzag line (∿∿∿) instead of dashed line Also fixed genogram.ts Zod schema to include all 7 quality levels (was missing very_close, hostile) and added separated type. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>60cc41b
-
feat: adopt v3_CLI best practices — medical NLP, confidence scores, 7-level quality
DONG-WEI-YANG +1: Claude Opus 4.6 (1M context)Genogram/Ecomap accuracy improvements inspired by v3_CLI reference project: - Clause context protection rules prevent cross-person misattribution (e.g., "父親張明,55歲,有糖尿病" correctly attributes all to one person) - Medical dictionary with 60+ conditions across 8 specialties (cardiovascular, metabolic, respiratory, cancer, mental, disabled) - Confidence scoring (0-1) on every member, relationship, and ecomap system - Relationship quality expanded from 5 to 7 levels (McGoldrick standard): very_close, close, normal, distant, conflicted, hostile, cutoff - GenogramEditor updated with visual styles for new quality levels - Offline regex-based NLP extractor as API fallback (no LLM needed): kinship dictionary, age extraction, health condition classification - Health risk analyzer: genetic pattern detection, multi-morbidity, caregiver burden assessment with actionable recommendations Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>ce46768
-
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
-
fix: implement Word export for all 7 record pages and eliminate mock patterns
DONG-WEI-YANG +1: Claude Opus 4.6 (1M context)- Create shared useWordExport() hook (tRPC → base64 → Blob → download) - Wire Word download into all pages: NewSOAP, NewNursingNote, NewNursingPlan, NewRecord, Retrieve, NewCareTracking, NewQualityCheck - Replace Math.random() ID generation with crypto.randomUUID() - Replace random node positioning with deterministic grid layout - Update audit script with exclude filters for known-good patterns - All 7 audit categories now pass clean Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>c8d0859 -
feat: AI voice-to-structured-data for social worker records
DONG-WEI-YANG +1: Claude Opus 4.6 (1M context)Add HF Inference API client with Zod validation and retry, social worker system prompt and output schemas, AI tRPC router with structureFromVoice/supplementGenogram/supplementEcomap endpoints, auto-layout utilities for genogram and ecomap, and full frontend integration with AI fill button and supplement recording UI. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>ade6ae8
-
feat: Group E — Docker, HF Spaces, org_name field, server tsconfig
DONG-WEI-YANG +1: Claude Opus 4.6 (1M context)- Dockerfile: multi-stage build (node:20-alpine, vite + tsc) - docker-compose.yml + docker-compose.prod.yml - HF Spaces README.md with Docker SDK frontmatter - tsconfig.server.json for server-only compilation - BaseRecordFields: org_name added to all record types - ORG_NAME_PLACEHOLDER constant for form inputs - .dockerignore Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>19e55a3 -
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