chore(task): archive 07-02-emergency-incident-workspace

This commit is contained in:
2026-07-03 00:41:09 -07:00
parent a0e50a9e83
commit fe9db61bbb
6 changed files with 2 additions and 2 deletions

View File

@@ -0,0 +1 @@
{"_example": "Fill with {\"file\": \"<path>\", \"reason\": \"<why>\"}. Put spec/research files only — no code paths. Run `python3 .trellis/scripts/get_context.py --mode packages` to list available specs. Delete this line once real entries are added."}

View File

@@ -0,0 +1,80 @@
# Emergency Incident Workspace Design
## Summary
Replace `/app/emergency` with a real safety/emergency incident workspace using the existing `systemIncidents` Drizzle table. The MVP covers manual event creation, status triage, filters, and metrics.
## Route Boundary
- Unscoped route: `app/(app)/app/emergency/page.tsx`
- Scoped route: `app/(app)/app/[organizationSlug]/emergency/page.tsx`
- Navigation remains under `运营`.
- Permissions:
- read: `incident:read`
- mutate: `incident:manage`
Server Component behavior:
1. Load `getCurrentAuthContext()`.
2. Redirect unauthenticated users to `/login`.
3. Redirect users without `incident:read` to dashboard.
4. Require active organization.
5. Load incidents through `listEmergencyIncidentData(organizationId)`.
6. Render client workspace with `canManage`.
## Data Model
Use existing `system_incidents`:
- `organizationId`
- `severity`: `info | warning | critical`
- `status`: `open | acknowledged | resolved | closed`
- `title`
- `description`
- `source`
- acknowledgement / resolution account and time fields
No schema change is required for MVP. Elder/bed linking stays future work for the context optimization task.
## Server Helpers
Create `modules/emergency/`:
- `modules/emergency/types.ts`
- labels, DTOs, create/status validators.
- `modules/emergency/server/operations.ts`
- `listEmergencyIncidentData(organizationId: string)`
- `createEmergencyIncident(input)`
- `updateEmergencyIncidentStatus(input)`
- `modules/emergency/components/EmergencyWorkspaceClient.tsx`
- metrics, filters, event table, create dialog, status actions.
## API Design
- `GET /api/emergency/incidents`
- permission: `incident:read`
- response: `{ success: true; reason: string; data }`
- `POST /api/emergency/incidents`
- permission: `incident:manage`
- request: `{ severity; title; description; source }`
- creates an organization-scoped incident
- `PATCH /api/emergency/incidents/[id]`
- permission: `incident:manage`
- request: `{ status }`
- updates only rows in the active organization
All create/update mutations write audit logs after successful persistence.
## UI Design
- Metrics: open, acknowledged, critical, resolved/closed today.
- Filters: status, severity, search by title/source/description.
- Dense table columns: event, severity, status, source, created time, updated time, actions.
- Actions: acknowledge, resolve, close.
- Manual creation dialog for authorized operators.
- Read-only users can see rows but not mutation controls.
## Compatibility
- Existing `/api/system/incidents/[id]` stays for system status settings.
- The emergency workspace uses dedicated `/api/emergency/...` routes so tests and UI contracts are local to the operational module.

View File

@@ -0,0 +1 @@
{"_example": "Fill with {\"file\": \"<path>\", \"reason\": \"<why>\"}. Put spec/research files only — no code paths. Run `python3 .trellis/scripts/get_context.py --mode packages` to list available specs. Delete this line once real entries are added."}

View File

@@ -0,0 +1,38 @@
# Implementation Plan
## 1. Types And Tests
- Add emergency DTOs and validators.
- Add `app/api/emergency/emergency-routes.test.ts` first.
- Cover list, create, status update, permission denial, missing organization, invalid input, and missing/cross-organization incident.
## 2. Server Operations And API Routes
- Add `modules/emergency/server/operations.ts`.
- Add `GET`/`POST /api/emergency/incidents`.
- Add `PATCH /api/emergency/incidents/[id]`.
- Use `requirePermission`, active organization checks, structured failures, and audit logs.
## 3. Workspace UI
- Replace `app/(app)/app/emergency/page.tsx`.
- Keep scoped route delegating to the unscoped route.
- Add `modules/emergency/components/EmergencyWorkspaceClient.tsx`.
- Implement metrics, filters, create dialog, and status action buttons.
## 4. Default Data
- Existing default workspace already inserts representative `systemIncidents`.
- Review whether the seed includes open/acknowledged/resolved and critical/warning/info; adjust only if needed.
## 5. Verification
- `pnpm test`
- `pnpm lint`
- `pnpm type-check`
- `pnpm build`
## Rollback Points
- Remove `modules/emergency`, emergency API routes, and page changes.
- No migration rollback expected unless implementation discovers schema changes are required.

View File

@@ -0,0 +1,65 @@
# 安全应急事件工作台
## Goal
Replace the current `安全应急` placeholder with a real emergency and safety event workspace. The MVP should let operators view, triage, update, and close persisted incidents inside the active organization.
## Confirmed Facts
- `/app/emergency` currently renders `ModulePage` only.
- `/app/{organizationSlug}/emergency` delegates to the unscoped emergency page.
- `systemIncidents` already exists in the Drizzle schema and supports severity, status, title, description, source, acknowledgement, resolution, and organization scoping.
- `app/api/system/incidents/[id]/route.ts` already supports incident status updates with audit logs.
- Settings status pages already use incident status actions.
## Requirements
- Replace `/app/emergency` and `/app/{organizationSlug}/emergency` with a real emergency workspace.
- Use existing persisted incident data as the starting model unless implementation analysis proves a separate emergency table is required.
- Show summary metrics by severity and status.
- Show an operational incident list/table with search and status/severity filters.
- Support status transitions for open, acknowledged, resolved, and closed events.
- Support creating a manual emergency/safety event if practical in the MVP.
- Link incidents to organization and optionally to elder/bed context in a future-compatible way.
- Mutations must record audit logs.
- Default workspace seed data must include representative safety/emergency events.
## Permissions
- Use existing `incident:read` for viewing.
- Use existing `incident:manage` for create/update/status transitions.
- Server-side permissions are required for all mutation APIs.
## Acceptance Criteria
- [ ] `/app/emergency` no longer renders the generic placeholder.
- [ ] `/app/{organizationSlug}/emergency` renders the same real emergency workspace.
- [ ] Emergency events are loaded from Drizzle and scoped to the active organization.
- [ ] The workspace shows severity/status metrics and a searchable event list.
- [ ] Authorized users can transition event status from the UI.
- [ ] Event status updates persist and survive reload.
- [ ] Authorized users can create a manual safety/emergency event if included in MVP implementation.
- [ ] Unauthorized mutation attempts return structured failures.
- [ ] Emergency mutations write audit log entries.
- [ ] Default seeded workspace includes safety/emergency events.
- [ ] `pnpm lint` passes.
- [ ] `pnpm type-check` passes.
- [ ] `pnpm build` passes.
## Dependencies
- Can start independently because `systemIncidents` already exists.
- Elder/bed context optimization may later add richer links from incidents to elders or beds.
- Dashboard integration should wait until this task is complete.
## Out Of Scope
- Device telemetry ingestion.
- Real-time alarm channels.
- SMS, phone, or push notification delivery.
- Dispatch routing engine.
- Post-incident regulatory reporting.
## Open Questions
- None currently blocking planning.

View File

@@ -0,0 +1,26 @@
{
"id": "emergency-incident-workspace",
"name": "emergency-incident-workspace",
"title": "安全应急事件工作台",
"description": "",
"status": "completed",
"dev_type": null,
"scope": null,
"package": null,
"priority": "P2",
"creator": "TalexDreamSoul",
"assignee": "TalexDreamSoul",
"createdAt": "2026-07-02",
"completedAt": "2026-07-03",
"branch": null,
"base_branch": "main",
"worktree_path": null,
"commit": null,
"pr_url": null,
"subtasks": [],
"children": [],
"parent": "07-02-operations-module-roadmap",
"relatedFiles": [],
"notes": "",
"meta": {}
}