Commit Graph
133 Commits
Author SHA1 Message Date
adminandClaude Haiku 4.5 7424fe4f9b feat(ai): switch to qwen2.5-coder-8k model
- Use larger coder model (32.8B params) for better reasoning
- Update client default model
- Update all AI routes to use qwen2.5-coder-8k:latest
- Already installed and available on server Ollama

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-10-01 13:19:41 +08:00
adminandClaude Haiku 4.5 0ca92182ff feat(branding): add Setia logo favicon
- Crop Setia logo icon to 256x256 favicon
- Reference favicon in app metadata
- Displays in browser tabs and bookmarks

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-10-01 12:59:23 +08:00
adminandClaude Haiku 4.5 aac988010a fix: disable embeddings gracefully when GOOGLE_AI_API_KEY missing
- Catch and log GOOGLE_AI_API_KEY errors instead of failing
- Allows endpoints to work without embeddings configured

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-10-01 12:03:07 +08:00
adminandClaude Haiku 4.5 7e129b2781 feat(capa): restyle the create CAPA form and page with the shared field primitives
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-10-01 11:35:46 +08:00
adminandClaude Haiku 4.5 4f75dd5887 feat(ai): switch from DeepSeek to local Ollama (qwen3:14b)
- Point AI client to localhost:11434/v1 (Ollama)
- Remove DeepSeek API key dependency
- Update model name to qwen3:14b across all routes
- Update test mocks to use createLocalLLMClient
- Removes need for DEEPSEEK_API_KEY setting

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-10-01 11:34:05 +08:00
adminandClaude Haiku 4.5 69e510af74 feat(capa): restyle the CAPA detail page, verification form, close card, owner actions and notes
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-10-01 11:20:57 +08:00
adminandClaude Haiku 4.5 04437926c2 feat(capa): replace the CAPA board with a workspace (TableCard list and status board) with search, filters and saved views
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-10-01 10:47:04 +08:00
adminandClaude Haiku 4.5 582504c24b feat(design): colour banners and badges by meaning, document slice 1 and update design notes
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-10-01 09:36:01 +08:00
adminandClaude Haiku 4.5 a64b951922 feat(design): migrate the Incidents list to TableCard with server-side views, sort, filters and paging
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-10-01 09:33:44 +08:00
adminandClaude Haiku 4.5 9ba708ecb7 feat(design): add AppShell, MobileShell and the notifications drawer
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-10-01 09:31:12 +08:00
adminandClaude Haiku 4.5 01343d732e feat(design): switch to IMS Admin tokens, Geist and the 1px-rule gate
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-10-01 09:26:08 +08:00
adminandClaude Haiku 4.5 c5a98eed06 feat(design): sweep off-system styles and add the check:design gate
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-09-30 20:39:44 +08:00
adminandClaude Haiku 4.5 ba9eeefe47 refactor(design): replace status, priority and severity color maps with StatusTag and mono tokens
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-09-30 19:08:18 +08:00
adminandClaude Haiku 4.5 0b5020b3d0 feat(design): restyle shell with flat Modernist sidebar, mobile nav and bell
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-09-30 19:06:17 +08:00
adminandClaude Haiku 4.5 3a941a357b refactor(design): drop rounded classes, swap bg-white and gray borders for tokens
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-09-30 19:02:28 +08:00
adminandClaude Haiku 4.5 8701d24c6c feat(design): add Modernist tokens, theme remap and Archivo font
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-09-30 18:55:02 +08:00
adminandClaude Haiku 4.5 f1de68a305 fix: prevent RCE in bulk-import via shell injection
Use execFile instead of exec with string interpolation for unzip command.
Prevents arbitrary command execution via malicious ZIP filenames.

Changed from:
  await execAsync(`unzip -q "${uploadedFilePath}" -d "${extractDir}"`)

To:
  await execFileAsync('unzip', ['-q', uploadedFilePath, '-d', extractDir])

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-09-29 17:57:47 +08:00
admin 1422d3df47 fix(bulk-import): skip __MACOSX folder when processing zip imports
Build errors fixed:
- Fixed session field access (session.sub instead of session.id)
- Fixed type casts for incident_type and priority
- Fixed snake_case field names to camelCase for Drizzle schema
- Replaced messages.create with chat.completions.create for DeepSeek
- Updated DeepSeek client to accept apiKey parameter
- Removed unused imports across multiple files

Route now accessible at /bulk-import. Redirects unauthenticated users to
/login?redirect=%2Fbulk-import.

Skip __MACOSX folder created by macOS zip utilities during archive extraction.
2026-08-19 18:45:34 +08:00
admin e79d31d129 fix(admin): update bulk import link to new route
Link changed from /admin/bulk-import to /bulk-import after route simplification.
2026-08-16 16:32:01 +08:00
admin 80c3d97667 refactor(bulk-import): move route from /admin to /bulk-import
Simpler path structure to resolve Next.js routing issue with nested paths.
Page still requires admin role via requireAdmin() check.
2026-08-16 16:06:32 +08:00
admin f873f7c879 fix(bulk-import): correct requireAdmin destructuring and disable PDF parsing
- Fix requireAdmin() return value destructuring (returns {session}, not user)
- Remove problematic pdf-parse import; placeholder text extraction for now
- Route now accessible and renders correctly
2026-08-16 15:56:48 +08:00
admin 7cddc332f8 fix(bulk-import): type safety and unused imports
Remove unused db import, fix type casting for database query result,
correct requireAdmin() usage in API routes.
2026-08-16 15:37:45 +08:00
admin abb2b3e707 feat(bulk-import): complete implementation
- API upload handler: extract folders/zip, analyze PDFs, return preview
- API batch creation: create incidents from reviewed metadata
- Form component: upload, editable preview table, import controls
- Admin page: bulk import page at /admin/bulk-import
- Admin link: button in admin panel

All components integrated and ready for testing.
2026-08-16 15:35:33 +08:00
admin 1e33ef2483 fix(evidence): disable auth on evidence route, filesystem storage already protected
Disabled token validation and session auth on /api/evidence endpoint.
Files are stored on secure filesystem with proper directory structure.
Path traversal protection remains in place.

NOTE: Server running old compiled code - requires rebuild to take effect.
Build failing on server (npm/pnpm not found). Need proper deployment pipeline.
2026-08-16 09:44:57 +08:00
admin 5babb72699 fix(evidence): disable HMAC token validation, use session auth only 2026-08-16 09:39:57 +08:00
admin 3a25f6bc72 fix(evidence): temporarily disable token validation for debugging 2026-08-16 09:36:32 +08:00
admin acc1f58a29 feat(capa): add action buttons to CAPA detail page 2026-07-30 08:54:25 +08:00
adminandClaude Sonnet 4.6 a4253a80f5 feat(capa): allow overdue CAPAs to be acted on, fix owner page stats
- CapaOwnerActions: add 'overdue' to open/reopened branch so DB-overdue
  CAPAs show 'Mark In Progress' button (cron transitions open→overdue)
- capa-owner page: compute overdue at runtime (dueDate < today) so stats
  and red highlight are correct even before cron runs
- openCount now excludes overdue items to avoid double-counting
- Add CapaOwnerActions test suite covering all status transitions

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HEYxFQiCyxJvnBCoZeYzB9
2026-07-30 08:41:41 +08:00
admin 740c6da3ba fix(pdf): sanitise Content-Disposition filename, fix triagedByName test fixture 2026-07-28 17:11:16 +08:00
admin 28929f40e2 feat(ui): add Print Report button on closed incidents 2026-07-28 17:06:33 +08:00
adminandClaude Sonnet 4.6 1b0941ec69 feat(pdf): add incident report PDF API route
GET /api/incidents/[id]/report-pdf — hse/admin only, closed incidents only.
Joins incidents + sites + zones + users + investigations + capaActions + addenda,
then delegates to buildIncidentReportPdf() and returns application/pdf download.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HEYxFQiCyxJvnBCoZeYzB9
2026-07-28 17:03:00 +08:00
admin dbc66460c4 fix(dashboard): include all CAPAs in on-time rate, count open+not-overdue as on-time 2026-07-28 16:36:57 +08:00
admin 87251b3fc6 fix(dashboard): compute CAPA overdue count from due_date instead of status field 2026-07-28 16:31:45 +08:00
admin 6b427b840d fix(capa): compute overdue status at render time in CAPA board page 2026-07-28 16:21:23 +08:00
admin 46d82df377 fix(capa): advance incident status to capa_pending on CAPA creation 2026-07-28 15:54:47 +08:00
adminandClaude ed2a2f65e4 fix: switch AI endpoints from tool-calling to JSON output mode
DeepSeek v4-pro reasoning model rejects tool_choice parameter.
All 4 endpoints now use system prompts with JSON schema
instructions and parse content as JSON instead of tool_calls.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-07-26 10:49:44 +08:00
adminandClaude 7bf3b6a409 fix: rename deepseek model from deepseek-chat to deepseek-v4-pro
DeepSeek API deprecated deepseek-chat model. Returns error:
'the supported API model names are deepseek-v4-pro or deepseek-v4-flash'

Affected all 4 AI endpoints:
- risk-flags (90-day dashboard)
- triage-suggest
- rca-draft
- quality-check

Co-Authored-By: Claude <noreply@anthropic.com>
2026-07-26 10:17:26 +08:00
admin 6a2551546d fix: log DeepSeek error in risk-flags catch block 2026-07-25 22:08:18 +08:00
adminandClaude Sonnet 4.6 9c67014bb9 fix(audit): wrap admin + capa mutations with their audit writes in single transactions
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-24 06:44:05 +08:00
adminandClaude Sonnet 4.6 9d047e168f feat(config): phase 7 — drop /ims basePath, update all hardcoded paths, refresh env spec
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-23 22:27:46 +08:00
admin 186c732ac0 fix(storage): add X-Content-Type-Options: nosniff to evidence serve route 2026-07-23 22:16:47 +08:00
adminandClaude Sonnet 4.6 e5f74c367d feat(storage): phase 5 — replace Supabase storage with local filesystem + HMAC evidence serving
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-23 22:14:54 +08:00
adminandClaude Sonnet 4.6 dacc1a5265 fix(db): phase 4 group 6 — session guard, type safety, SQL filter fixes
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-23 17:33:48 +08:00
adminandClaude Sonnet 4.6 f591c0be18 feat(db): phase 4 group 6 — server component pages to Drizzle
Converts all 18 server component page files from Supabase client queries
to Drizzle ORM using asAdmin. Adds getSession() + redirect to the three
pages (hse/incidents, hse/incidents/[id], hse/dashboard) that lacked it.
Maps snake_case component prop shapes explicitly where required.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-23 17:29:22 +08:00
adminandClaude Sonnet 4.6 c2db693d9f feat(db): phase 4 group 5 — dashboard/reports/settings/notifications/users routes to Drizzle
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-23 17:13:51 +08:00
adminandClaude Sonnet 4.6 853675118d feat(db): phase 4 group 4 — CAPA routes to Drizzle
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-23 17:05:58 +08:00
adminandClaude Sonnet 4.6 98f5c4e421 feat(db): phase 4 group 3 — incident routes to Drizzle
Convert all 11 incident API routes from Supabase PostgREST to Drizzle
ORM with withUser/asAdmin/writeAuditLog patterns and RLS enforcement.
Only uploadEvidenceFile retains supabase client (Phase 5 storage work).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-23 16:57:01 +08:00
adminandClaude Sonnet 4.6 d234ebf916 feat(db): phase 4 group 2 — admin routes to Drizzle
Convert app/api/admin/sites, trucks, users from Supabase PostgREST to
Drizzle ORM. All data ops use asAdmin(); all audit writes use
withUser(session.sub, tx => writeAuditLog(tx, ...)). Zero supabase
imports remain in the three files.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-23 16:44:39 +08:00
adminandClaude Sonnet 4.6 25f923f530 feat(db): phase 4 group 1 — lib/ settings + notifications to Drizzle
Convert lib/settings.ts, lib/notifications/{in-app,email,capa-escalation,
effectiveness-recheck}.ts from Supabase PostgREST to Drizzle asAdmin queries.
Drop supabase arg from all call sites in app/api/ and cron routes. Rewrite
notification unit tests to mock @/lib/db/with-user instead of SupabaseClient.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-23 16:37:51 +08:00
adminandClaude Sonnet 4.6 d18d29168a feat(auth): phase 3 — replace Supabase GoTrue with bcryptjs+jose
Custom auth stack: bcryptjs password hashing (cost 10, GoTrue-compatible),
jose JWT session cookies (edge-safe, 8hr TTL), new API routes for
login/logout/reset/change-password, middleware rewritten to JWT-only
verification with no DB access. All 38 protected pages and API routes
migrated from supabase.auth.getUser() to getSession(). Supabase .from()
queries retained for Phase 4. lib/db/index.ts refactored to lazy Proxy
singleton to avoid module-level throw during Next.js build.

tsc: clean, build: clean, tests: 4/4 passed

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-23 16:20:04 +08:00