orbital-command 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +396 -0
- package/bin/orbital.js +362 -0
- package/dist/assets/WorkflowVisualizer-BZ21PIIF.js +84 -0
- package/dist/assets/WorkflowVisualizer-BZV40eAE.css +1 -0
- package/dist/assets/charts-D__PA1zp.js +72 -0
- package/dist/assets/index-D1G6i0nS.css +1 -0
- package/dist/assets/index-DpItvKpf.js +419 -0
- package/dist/assets/ui-BvF022GT.js +53 -0
- package/dist/assets/vendor-Dzv9lrRc.js +59 -0
- package/dist/index.html +19 -0
- package/dist/scanner-sweep.png +0 -0
- package/dist/server/server/adapters/index.js +34 -0
- package/dist/server/server/adapters/iterm2-adapter.js +29 -0
- package/dist/server/server/adapters/subprocess-adapter.js +21 -0
- package/dist/server/server/adapters/terminal-adapter.js +1 -0
- package/dist/server/server/config.js +156 -0
- package/dist/server/server/database.js +90 -0
- package/dist/server/server/index.js +372 -0
- package/dist/server/server/init.js +811 -0
- package/dist/server/server/parsers/event-parser.js +64 -0
- package/dist/server/server/parsers/scope-parser.js +188 -0
- package/dist/server/server/routes/config-routes.js +163 -0
- package/dist/server/server/routes/data-routes.js +461 -0
- package/dist/server/server/routes/dispatch-routes.js +215 -0
- package/dist/server/server/routes/git-routes.js +92 -0
- package/dist/server/server/routes/scope-routes.js +215 -0
- package/dist/server/server/routes/sprint-routes.js +116 -0
- package/dist/server/server/routes/version-routes.js +130 -0
- package/dist/server/server/routes/workflow-routes.js +185 -0
- package/dist/server/server/schema.js +90 -0
- package/dist/server/server/services/batch-orchestrator.js +253 -0
- package/dist/server/server/services/claude-session-service.js +352 -0
- package/dist/server/server/services/config-service.js +132 -0
- package/dist/server/server/services/deploy-service.js +51 -0
- package/dist/server/server/services/event-service.js +63 -0
- package/dist/server/server/services/gate-service.js +83 -0
- package/dist/server/server/services/git-service.js +309 -0
- package/dist/server/server/services/github-service.js +145 -0
- package/dist/server/server/services/readiness-service.js +184 -0
- package/dist/server/server/services/scope-cache.js +72 -0
- package/dist/server/server/services/scope-service.js +424 -0
- package/dist/server/server/services/sprint-orchestrator.js +312 -0
- package/dist/server/server/services/sprint-service.js +293 -0
- package/dist/server/server/services/workflow-service.js +397 -0
- package/dist/server/server/utils/cc-hooks-parser.js +49 -0
- package/dist/server/server/utils/dispatch-utils.js +305 -0
- package/dist/server/server/utils/logger.js +86 -0
- package/dist/server/server/utils/terminal-launcher.js +388 -0
- package/dist/server/server/utils/worktree-manager.js +98 -0
- package/dist/server/server/watchers/event-watcher.js +81 -0
- package/dist/server/server/watchers/scope-watcher.js +33 -0
- package/dist/server/shared/api-types.js +5 -0
- package/dist/server/shared/default-workflow.json +616 -0
- package/dist/server/shared/workflow-config.js +44 -0
- package/dist/server/shared/workflow-engine.js +353 -0
- package/index.html +15 -0
- package/package.json +110 -0
- package/postcss.config.js +6 -0
- package/schemas/orbital.config.schema.json +83 -0
- package/scripts/postinstall.js +24 -0
- package/scripts/start.sh +20 -0
- package/server/adapters/index.ts +41 -0
- package/server/adapters/iterm2-adapter.ts +37 -0
- package/server/adapters/subprocess-adapter.ts +25 -0
- package/server/adapters/terminal-adapter.ts +24 -0
- package/server/config.ts +234 -0
- package/server/database.ts +107 -0
- package/server/index.ts +452 -0
- package/server/init.ts +891 -0
- package/server/parsers/event-parser.ts +74 -0
- package/server/parsers/scope-parser.ts +240 -0
- package/server/routes/config-routes.ts +182 -0
- package/server/routes/data-routes.ts +548 -0
- package/server/routes/dispatch-routes.ts +275 -0
- package/server/routes/git-routes.ts +112 -0
- package/server/routes/scope-routes.ts +262 -0
- package/server/routes/sprint-routes.ts +142 -0
- package/server/routes/version-routes.ts +156 -0
- package/server/routes/workflow-routes.ts +198 -0
- package/server/schema.ts +90 -0
- package/server/services/batch-orchestrator.ts +286 -0
- package/server/services/claude-session-service.ts +441 -0
- package/server/services/config-service.ts +151 -0
- package/server/services/deploy-service.ts +98 -0
- package/server/services/event-service.ts +98 -0
- package/server/services/gate-service.ts +126 -0
- package/server/services/git-service.ts +391 -0
- package/server/services/github-service.ts +183 -0
- package/server/services/readiness-service.ts +250 -0
- package/server/services/scope-cache.ts +81 -0
- package/server/services/scope-service.ts +476 -0
- package/server/services/sprint-orchestrator.ts +361 -0
- package/server/services/sprint-service.ts +415 -0
- package/server/services/workflow-service.ts +461 -0
- package/server/utils/cc-hooks-parser.ts +70 -0
- package/server/utils/dispatch-utils.ts +395 -0
- package/server/utils/logger.ts +109 -0
- package/server/utils/terminal-launcher.ts +462 -0
- package/server/utils/worktree-manager.ts +104 -0
- package/server/watchers/event-watcher.ts +100 -0
- package/server/watchers/scope-watcher.ts +38 -0
- package/shared/api-types.ts +20 -0
- package/shared/default-workflow.json +616 -0
- package/shared/workflow-config.ts +170 -0
- package/shared/workflow-engine.ts +427 -0
- package/src/App.tsx +33 -0
- package/src/components/AgentBadge.tsx +40 -0
- package/src/components/BatchPreflightModal.tsx +115 -0
- package/src/components/CardDisplayToggle.tsx +74 -0
- package/src/components/ColumnHeaderActions.tsx +55 -0
- package/src/components/ColumnMenu.tsx +99 -0
- package/src/components/DeployHistory.tsx +141 -0
- package/src/components/DispatchModal.tsx +164 -0
- package/src/components/DispatchPopover.tsx +139 -0
- package/src/components/DragOverlay.tsx +25 -0
- package/src/components/DriftSidebar.tsx +140 -0
- package/src/components/EnvironmentStrip.tsx +88 -0
- package/src/components/ErrorBoundary.tsx +62 -0
- package/src/components/FilterChip.tsx +105 -0
- package/src/components/GateIndicator.tsx +33 -0
- package/src/components/IdeaDetailModal.tsx +190 -0
- package/src/components/IdeaFormDialog.tsx +113 -0
- package/src/components/KanbanColumn.tsx +201 -0
- package/src/components/MarkdownRenderer.tsx +114 -0
- package/src/components/NeonGrid.tsx +128 -0
- package/src/components/PromotionQueue.tsx +89 -0
- package/src/components/ScopeCard.tsx +234 -0
- package/src/components/ScopeDetailModal.tsx +255 -0
- package/src/components/ScopeFilterBar.tsx +152 -0
- package/src/components/SearchInput.tsx +102 -0
- package/src/components/SessionPanel.tsx +335 -0
- package/src/components/SprintContainer.tsx +303 -0
- package/src/components/SprintDependencyDialog.tsx +78 -0
- package/src/components/SprintPreflightModal.tsx +138 -0
- package/src/components/StatusBar.tsx +168 -0
- package/src/components/SwimCell.tsx +67 -0
- package/src/components/SwimLaneRow.tsx +94 -0
- package/src/components/SwimlaneBoardView.tsx +108 -0
- package/src/components/VersionBadge.tsx +139 -0
- package/src/components/ViewModeSelector.tsx +114 -0
- package/src/components/config/AgentChip.tsx +53 -0
- package/src/components/config/AgentCreateDialog.tsx +321 -0
- package/src/components/config/AgentEditor.tsx +175 -0
- package/src/components/config/DirectoryTree.tsx +582 -0
- package/src/components/config/FileEditor.tsx +550 -0
- package/src/components/config/HookChip.tsx +50 -0
- package/src/components/config/StageCard.tsx +198 -0
- package/src/components/config/TransitionZone.tsx +173 -0
- package/src/components/config/UnifiedWorkflowPipeline.tsx +216 -0
- package/src/components/config/WorkflowPipeline.tsx +161 -0
- package/src/components/source-control/BranchList.tsx +93 -0
- package/src/components/source-control/BranchPanel.tsx +105 -0
- package/src/components/source-control/CommitLog.tsx +100 -0
- package/src/components/source-control/CommitRow.tsx +47 -0
- package/src/components/source-control/GitHubPanel.tsx +110 -0
- package/src/components/source-control/GitHubSetupGuide.tsx +52 -0
- package/src/components/source-control/GitOverviewBar.tsx +101 -0
- package/src/components/source-control/PullRequestList.tsx +69 -0
- package/src/components/source-control/WorktreeList.tsx +80 -0
- package/src/components/ui/badge.tsx +41 -0
- package/src/components/ui/button.tsx +55 -0
- package/src/components/ui/card.tsx +78 -0
- package/src/components/ui/dialog.tsx +94 -0
- package/src/components/ui/popover.tsx +33 -0
- package/src/components/ui/scroll-area.tsx +54 -0
- package/src/components/ui/separator.tsx +28 -0
- package/src/components/ui/tabs.tsx +52 -0
- package/src/components/ui/toggle-switch.tsx +35 -0
- package/src/components/ui/tooltip.tsx +27 -0
- package/src/components/workflow/AddEdgeDialog.tsx +217 -0
- package/src/components/workflow/AddListDialog.tsx +201 -0
- package/src/components/workflow/ChecklistEditor.tsx +239 -0
- package/src/components/workflow/CommandPrefixManager.tsx +118 -0
- package/src/components/workflow/ConfigSettingsPanel.tsx +189 -0
- package/src/components/workflow/DirectionSelector.tsx +133 -0
- package/src/components/workflow/DispatchConfigPanel.tsx +180 -0
- package/src/components/workflow/EdgeDetailPanel.tsx +236 -0
- package/src/components/workflow/EdgePropertyEditor.tsx +251 -0
- package/src/components/workflow/EditToolbar.tsx +138 -0
- package/src/components/workflow/HookDetailPanel.tsx +250 -0
- package/src/components/workflow/HookExecutionLog.tsx +24 -0
- package/src/components/workflow/HookSourceModal.tsx +129 -0
- package/src/components/workflow/HooksDashboard.tsx +363 -0
- package/src/components/workflow/ListPropertyEditor.tsx +251 -0
- package/src/components/workflow/MigrationPreviewDialog.tsx +237 -0
- package/src/components/workflow/MovementRulesPanel.tsx +188 -0
- package/src/components/workflow/NodeDetailPanel.tsx +245 -0
- package/src/components/workflow/PresetSelector.tsx +414 -0
- package/src/components/workflow/SkillCommandBuilder.tsx +174 -0
- package/src/components/workflow/WorkflowEdgeComponent.tsx +145 -0
- package/src/components/workflow/WorkflowNode.tsx +147 -0
- package/src/components/workflow/graphLayout.ts +186 -0
- package/src/components/workflow/mergeHooks.ts +85 -0
- package/src/components/workflow/useEditHistory.ts +88 -0
- package/src/components/workflow/useWorkflowEditor.ts +262 -0
- package/src/components/workflow/validateConfig.ts +70 -0
- package/src/hooks/useActiveDispatches.ts +198 -0
- package/src/hooks/useBoardSettings.ts +170 -0
- package/src/hooks/useCardDisplay.ts +57 -0
- package/src/hooks/useCcHooks.ts +24 -0
- package/src/hooks/useConfigTree.ts +51 -0
- package/src/hooks/useEnforcementRules.ts +46 -0
- package/src/hooks/useEvents.ts +59 -0
- package/src/hooks/useFileEditor.ts +165 -0
- package/src/hooks/useGates.ts +57 -0
- package/src/hooks/useIdeaActions.ts +53 -0
- package/src/hooks/useKanbanDnd.ts +410 -0
- package/src/hooks/useOrbitalConfig.ts +54 -0
- package/src/hooks/usePipeline.ts +47 -0
- package/src/hooks/usePipelineData.ts +338 -0
- package/src/hooks/useReconnect.ts +25 -0
- package/src/hooks/useScopeFilters.ts +125 -0
- package/src/hooks/useScopeSessions.ts +44 -0
- package/src/hooks/useScopes.ts +67 -0
- package/src/hooks/useSearch.ts +67 -0
- package/src/hooks/useSettings.tsx +187 -0
- package/src/hooks/useSocket.ts +25 -0
- package/src/hooks/useSourceControl.ts +105 -0
- package/src/hooks/useSprintPreflight.ts +55 -0
- package/src/hooks/useSprints.ts +154 -0
- package/src/hooks/useStatusBarHighlight.ts +18 -0
- package/src/hooks/useSwimlaneBoardSettings.ts +104 -0
- package/src/hooks/useTheme.ts +9 -0
- package/src/hooks/useTransitionReadiness.ts +53 -0
- package/src/hooks/useVersion.ts +155 -0
- package/src/hooks/useViolations.ts +65 -0
- package/src/hooks/useWorkflow.tsx +125 -0
- package/src/hooks/useZoomModifier.ts +19 -0
- package/src/index.css +797 -0
- package/src/layouts/DashboardLayout.tsx +113 -0
- package/src/lib/collisionDetection.ts +20 -0
- package/src/lib/scope-fields.ts +61 -0
- package/src/lib/swimlane.ts +146 -0
- package/src/lib/utils.ts +15 -0
- package/src/main.tsx +19 -0
- package/src/socket.ts +11 -0
- package/src/types/index.ts +497 -0
- package/src/views/AgentFeed.tsx +339 -0
- package/src/views/DeployPipeline.tsx +59 -0
- package/src/views/EnforcementView.tsx +378 -0
- package/src/views/PrimitivesConfig.tsx +500 -0
- package/src/views/QualityGates.tsx +1012 -0
- package/src/views/ScopeBoard.tsx +454 -0
- package/src/views/SessionTimeline.tsx +516 -0
- package/src/views/Settings.tsx +183 -0
- package/src/views/SourceControl.tsx +95 -0
- package/src/views/WorkflowVisualizer.tsx +382 -0
- package/tailwind.config.js +161 -0
- package/templates/agents/AUTO-INVOKE.md +180 -0
- package/templates/agents/CONFLICT-RESOLUTION.md +128 -0
- package/templates/agents/QUICK-REFERENCE.md +122 -0
- package/templates/agents/README.md +188 -0
- package/templates/agents/SKILL-TRIGGERS.md +100 -0
- package/templates/agents/blue-team/frontend-designer.md +424 -0
- package/templates/agents/green-team/architect.md +526 -0
- package/templates/agents/green-team/rules-enforcer.md +131 -0
- package/templates/agents/red-team/attacker-learned.md +24 -0
- package/templates/agents/red-team/attacker.md +486 -0
- package/templates/agents/red-team/chaos.md +548 -0
- package/templates/agents/reference/component-registry.md +82 -0
- package/templates/agents/workflows/full-mode.md +218 -0
- package/templates/agents/workflows/quick-mode.md +118 -0
- package/templates/agents/workflows/security-mode.md +283 -0
- package/templates/anti-patterns/dangerous-shortcuts.md +427 -0
- package/templates/config/agent-triggers.json +92 -0
- package/templates/hooks/agent-team-gate.sh +31 -0
- package/templates/hooks/agent-trigger.sh +97 -0
- package/templates/hooks/block-push.sh +66 -0
- package/templates/hooks/block-workarounds.sh +61 -0
- package/templates/hooks/blocker-check.sh +28 -0
- package/templates/hooks/completion-checklist.sh +28 -0
- package/templates/hooks/decision-capture.sh +15 -0
- package/templates/hooks/dependency-check.sh +27 -0
- package/templates/hooks/end-session.sh +31 -0
- package/templates/hooks/exploration-logger.sh +37 -0
- package/templates/hooks/files-changed-summary.sh +37 -0
- package/templates/hooks/get-session-id.sh +49 -0
- package/templates/hooks/git-commit-guard.sh +34 -0
- package/templates/hooks/init-session.sh +93 -0
- package/templates/hooks/orbital-emit.sh +79 -0
- package/templates/hooks/orbital-report-deploy.sh +78 -0
- package/templates/hooks/orbital-report-gates.sh +40 -0
- package/templates/hooks/orbital-report-violation.sh +36 -0
- package/templates/hooks/orbital-scope-update.sh +53 -0
- package/templates/hooks/phase-verify-reminder.sh +26 -0
- package/templates/hooks/review-gate-check.sh +82 -0
- package/templates/hooks/scope-commit-logger.sh +37 -0
- package/templates/hooks/scope-create-cleanup.sh +36 -0
- package/templates/hooks/scope-create-gate.sh +80 -0
- package/templates/hooks/scope-create-tracker.sh +17 -0
- package/templates/hooks/scope-file-sync.sh +53 -0
- package/templates/hooks/scope-gate.sh +35 -0
- package/templates/hooks/scope-helpers.sh +188 -0
- package/templates/hooks/scope-lifecycle-gate.sh +139 -0
- package/templates/hooks/scope-prepare.sh +244 -0
- package/templates/hooks/scope-transition.sh +172 -0
- package/templates/hooks/session-enforcer.sh +143 -0
- package/templates/hooks/time-tracker.sh +33 -0
- package/templates/lessons-learned.md +15 -0
- package/templates/orbital.config.json +35 -0
- package/templates/presets/development.json +42 -0
- package/templates/presets/gitflow.json +712 -0
- package/templates/presets/minimal.json +23 -0
- package/templates/quick/rules.md +218 -0
- package/templates/scopes/_template.md +255 -0
- package/templates/settings-hooks.json +98 -0
- package/templates/skills/git-commit/SKILL.md +85 -0
- package/templates/skills/git-dev/SKILL.md +99 -0
- package/templates/skills/git-hotfix/SKILL.md +223 -0
- package/templates/skills/git-main/SKILL.md +84 -0
- package/templates/skills/git-production/SKILL.md +165 -0
- package/templates/skills/git-staging/SKILL.md +112 -0
- package/templates/skills/scope-create/SKILL.md +81 -0
- package/templates/skills/scope-fix-review/SKILL.md +168 -0
- package/templates/skills/scope-implement/SKILL.md +110 -0
- package/templates/skills/scope-post-review/SKILL.md +144 -0
- package/templates/skills/scope-pre-review/SKILL.md +211 -0
- package/templates/skills/scope-verify/SKILL.md +201 -0
- package/templates/skills/session-init/SKILL.md +62 -0
- package/templates/skills/session-resume/SKILL.md +201 -0
- package/templates/skills/test-checks/SKILL.md +171 -0
- package/templates/skills/test-code-review/SKILL.md +252 -0
- package/tsconfig.json +25 -0
- package/vite.config.ts +38 -0
|
@@ -0,0 +1,1012 @@
|
|
|
1
|
+
import { useState, useMemo, useEffect, useCallback } from 'react';
|
|
2
|
+
import { useSearchParams } from 'react-router-dom';
|
|
3
|
+
import {
|
|
4
|
+
ShieldCheck, ArrowRight, CheckCircle2, XCircle, MinusCircle,
|
|
5
|
+
AlertTriangle, Clock, Terminal, Shield, ShieldAlert, Eye, Cog,
|
|
6
|
+
} from 'lucide-react';
|
|
7
|
+
import { formatDistanceToNow } from 'date-fns';
|
|
8
|
+
import {
|
|
9
|
+
BarChart, Bar, XAxis, YAxis, Tooltip as RechartsTooltip,
|
|
10
|
+
ResponsiveContainer, Cell, AreaChart, Area, CartesianGrid,
|
|
11
|
+
PieChart, Pie, Legend,
|
|
12
|
+
} from 'recharts';
|
|
13
|
+
import { useScopes } from '@/hooks/useScopes';
|
|
14
|
+
import { useTransitionReadiness } from '@/hooks/useTransitionReadiness';
|
|
15
|
+
import { useGates } from '@/hooks/useGates';
|
|
16
|
+
import { useViolations } from '@/hooks/useViolations';
|
|
17
|
+
import { useEnforcementRules } from '@/hooks/useEnforcementRules';
|
|
18
|
+
import { useWorkflow } from '@/hooks/useWorkflow';
|
|
19
|
+
import { GateIndicator } from '@/components/GateIndicator';
|
|
20
|
+
import { Badge } from '@/components/ui/badge';
|
|
21
|
+
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
|
22
|
+
import { Button } from '@/components/ui/button';
|
|
23
|
+
import { cn } from '@/lib/utils';
|
|
24
|
+
import type { Scope, GateStatus, HookStatus, EnforcementRule, ViolationTrendPoint, OrbitalEvent } from '@/types';
|
|
25
|
+
|
|
26
|
+
function formatGateName(name: string): string {
|
|
27
|
+
return name.replace(/-/g, ' ').replace(/\b\w/g, (c) => c.toUpperCase());
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const ENFORCEMENT_COLORS: Record<string, string> = {
|
|
31
|
+
blocker: 'text-red-400 bg-red-500/10 border-red-500/20',
|
|
32
|
+
advisor: 'text-amber-400 bg-amber-500/10 border-amber-500/20',
|
|
33
|
+
operator: 'text-cyan-400 bg-cyan-500/10 border-cyan-500/20',
|
|
34
|
+
silent: 'text-zinc-400 bg-zinc-500/10 border-zinc-500/20',
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const CATEGORY_LABELS: Record<string, string> = {
|
|
38
|
+
guard: 'GUARD', gate: 'GATE', lifecycle: 'LIFECYCLE', observer: 'OBSERVER',
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const CATEGORY_ICON: Record<string, typeof Shield> = {
|
|
42
|
+
guard: Shield, gate: ShieldAlert, lifecycle: Cog, observer: Eye,
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// ─── Main Page ──────────────────────────────────────────────
|
|
46
|
+
|
|
47
|
+
export function QualityGates() {
|
|
48
|
+
const { scopes } = useScopes();
|
|
49
|
+
const { engine } = useWorkflow();
|
|
50
|
+
const [searchParams, setSearchParams] = useSearchParams();
|
|
51
|
+
const [selectedScopeId, setSelectedScopeId] = useState<number | null>(() => {
|
|
52
|
+
const param = searchParams.get('scope');
|
|
53
|
+
return param ? Number(param) : null;
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
if (selectedScopeId != null) {
|
|
58
|
+
setSearchParams({ scope: String(selectedScopeId) }, { replace: true });
|
|
59
|
+
}
|
|
60
|
+
}, [selectedScopeId, setSearchParams]);
|
|
61
|
+
|
|
62
|
+
const activeScopes = useMemo(() => {
|
|
63
|
+
return scopes
|
|
64
|
+
.filter((s) => !engine.isTerminalStatus(s.status) && s.status !== 'icebox' && !s.is_ghost)
|
|
65
|
+
.sort((a, b) => a.id - b.id);
|
|
66
|
+
}, [scopes, engine]);
|
|
67
|
+
|
|
68
|
+
const scopesByStatus = useMemo(() => {
|
|
69
|
+
const map = new Map<string, Scope[]>();
|
|
70
|
+
for (const scope of activeScopes) {
|
|
71
|
+
const existing = map.get(scope.status) ?? [];
|
|
72
|
+
existing.push(scope);
|
|
73
|
+
map.set(scope.status, existing);
|
|
74
|
+
}
|
|
75
|
+
return map;
|
|
76
|
+
}, [activeScopes]);
|
|
77
|
+
|
|
78
|
+
const effectiveScopeId = selectedScopeId ?? activeScopes[0]?.id ?? null;
|
|
79
|
+
const { readiness, loading: readinessLoading } = useTransitionReadiness(effectiveScopeId);
|
|
80
|
+
const selectedScope = activeScopes.find((s) => s.id === effectiveScopeId);
|
|
81
|
+
|
|
82
|
+
return (
|
|
83
|
+
<div className="flex-1 min-h-0 overflow-y-auto space-y-6">
|
|
84
|
+
{/* ═══ Section 1: Transition Readiness ═══ */}
|
|
85
|
+
<section>
|
|
86
|
+
<div className="mb-4 flex items-center gap-3">
|
|
87
|
+
<ShieldCheck className="h-4 w-4 text-primary" />
|
|
88
|
+
<h1 className="text-xl font-light">Safeguards</h1>
|
|
89
|
+
{readiness && (
|
|
90
|
+
<Badge variant="secondary">
|
|
91
|
+
{readiness.transitions.filter((t) => t.ready).length}/{readiness.transitions.length} ready
|
|
92
|
+
</Badge>
|
|
93
|
+
)}
|
|
94
|
+
</div>
|
|
95
|
+
|
|
96
|
+
{/* Scope Selector */}
|
|
97
|
+
<div className="mb-4 flex flex-wrap gap-1.5">
|
|
98
|
+
{engine.getLists()
|
|
99
|
+
.filter((l) => !engine.isTerminalStatus(l.id) && l.id !== 'icebox' && scopesByStatus.has(l.id))
|
|
100
|
+
.map((list) => (
|
|
101
|
+
<div key={list.id} className="flex items-center gap-1">
|
|
102
|
+
<span className="mr-0.5 text-[10px] uppercase tracking-wider text-muted-foreground/50">
|
|
103
|
+
{list.label}
|
|
104
|
+
</span>
|
|
105
|
+
{(scopesByStatus.get(list.id) ?? []).map((scope) => (
|
|
106
|
+
<button
|
|
107
|
+
key={scope.id}
|
|
108
|
+
onClick={() => setSelectedScopeId(scope.id)}
|
|
109
|
+
className={cn(
|
|
110
|
+
'rounded border px-2 py-0.5 text-xs font-mono transition-all',
|
|
111
|
+
scope.id === effectiveScopeId
|
|
112
|
+
? 'border-primary/50 bg-primary/10 text-primary'
|
|
113
|
+
: 'border-border/50 bg-surface-light/30 text-muted-foreground hover:border-primary/30 hover:text-foreground',
|
|
114
|
+
)}
|
|
115
|
+
>
|
|
116
|
+
{String(scope.id).padStart(3, '0')}
|
|
117
|
+
</button>
|
|
118
|
+
))}
|
|
119
|
+
<span className="mx-1.5 text-border">|</span>
|
|
120
|
+
</div>
|
|
121
|
+
))}
|
|
122
|
+
{activeScopes.length === 0 && (
|
|
123
|
+
<span className="text-xs text-muted-foreground">No active scopes</span>
|
|
124
|
+
)}
|
|
125
|
+
</div>
|
|
126
|
+
|
|
127
|
+
{/* Scope Readiness Overview Chart */}
|
|
128
|
+
{activeScopes.length > 0 && (
|
|
129
|
+
<ScopeReadinessOverview
|
|
130
|
+
scopes={activeScopes}
|
|
131
|
+
selectedId={effectiveScopeId}
|
|
132
|
+
onSelect={setSelectedScopeId}
|
|
133
|
+
/>
|
|
134
|
+
)}
|
|
135
|
+
|
|
136
|
+
{/* Transition Cards + Scope Sidebar */}
|
|
137
|
+
{effectiveScopeId && selectedScope && (
|
|
138
|
+
<div className="grid gap-5 lg:grid-cols-3">
|
|
139
|
+
<div className="lg:col-span-2 space-y-4">
|
|
140
|
+
{readinessLoading ? (
|
|
141
|
+
<div className="flex h-32 items-center justify-center">
|
|
142
|
+
<div className="h-6 w-6 animate-spin rounded-full border-2 border-primary border-t-transparent" />
|
|
143
|
+
</div>
|
|
144
|
+
) : readiness && readiness.transitions.length > 0 ? (
|
|
145
|
+
readiness.transitions.map((transition) => (
|
|
146
|
+
<TransitionCard
|
|
147
|
+
key={`${transition.from}-${transition.to}`}
|
|
148
|
+
transition={transition}
|
|
149
|
+
scopeId={effectiveScopeId}
|
|
150
|
+
/>
|
|
151
|
+
))
|
|
152
|
+
) : (
|
|
153
|
+
<Card>
|
|
154
|
+
<CardContent className="py-8 text-center">
|
|
155
|
+
<CheckCircle2 className="mx-auto mb-3 h-8 w-8 text-muted-foreground/50" />
|
|
156
|
+
<p className="text-sm text-muted-foreground">
|
|
157
|
+
No forward transitions from <span className="font-mono">{selectedScope.status}</span>
|
|
158
|
+
</p>
|
|
159
|
+
</CardContent>
|
|
160
|
+
</Card>
|
|
161
|
+
)}
|
|
162
|
+
</div>
|
|
163
|
+
|
|
164
|
+
<div className="space-y-4">
|
|
165
|
+
<ScopeInfoCard scope={selectedScope} />
|
|
166
|
+
{readiness && readiness.transitions.length > 0 && readiness.transitions[0].gates.length > 0 && (
|
|
167
|
+
<CIGatesCard gates={readiness.transitions[0].gates} />
|
|
168
|
+
)}
|
|
169
|
+
</div>
|
|
170
|
+
</div>
|
|
171
|
+
)}
|
|
172
|
+
</section>
|
|
173
|
+
|
|
174
|
+
{/* ═══ Section 2: Rule Configuration ═══ */}
|
|
175
|
+
<RuleConfigSection />
|
|
176
|
+
|
|
177
|
+
{/* ═══ Section 3: Enforcement Activity ═══ */}
|
|
178
|
+
<EnforcementActivitySection />
|
|
179
|
+
|
|
180
|
+
{/* ═══ Section 4: CI Gates ═══ */}
|
|
181
|
+
<GlobalCISection />
|
|
182
|
+
</div>
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// ─── Section: Scope Info ────────────────────────────────────
|
|
187
|
+
|
|
188
|
+
function ScopeInfoCard({ scope }: { scope: Scope }) {
|
|
189
|
+
const id = String(scope.id).padStart(3, '0');
|
|
190
|
+
const title = scope.title.length > 30 ? scope.title.slice(0, 30) + '...' : scope.title;
|
|
191
|
+
|
|
192
|
+
return (
|
|
193
|
+
<Card>
|
|
194
|
+
<CardHeader className="pb-2">
|
|
195
|
+
<CardTitle className="text-sm font-mono">{id} {title}</CardTitle>
|
|
196
|
+
</CardHeader>
|
|
197
|
+
<CardContent className="space-y-2 text-xs">
|
|
198
|
+
<div className="flex justify-between">
|
|
199
|
+
<span className="text-muted-foreground">Status</span>
|
|
200
|
+
<Badge variant="outline" className="text-[10px]">{scope.status}</Badge>
|
|
201
|
+
</div>
|
|
202
|
+
{scope.priority && (
|
|
203
|
+
<div className="flex justify-between">
|
|
204
|
+
<span className="text-muted-foreground">Priority</span>
|
|
205
|
+
<span>{scope.priority}</span>
|
|
206
|
+
</div>
|
|
207
|
+
)}
|
|
208
|
+
{scope.blocked_by.length > 0 && (
|
|
209
|
+
<div className="flex justify-between">
|
|
210
|
+
<span className="text-muted-foreground">Blocked by</span>
|
|
211
|
+
<span className="font-mono text-amber-400">
|
|
212
|
+
{scope.blocked_by.map((bid) => String(bid).padStart(3, '0')).join(', ')}
|
|
213
|
+
</span>
|
|
214
|
+
</div>
|
|
215
|
+
)}
|
|
216
|
+
{Object.keys(scope.sessions).length > 0 && (
|
|
217
|
+
<div className="pt-1 border-t border-border/50">
|
|
218
|
+
<span className="text-muted-foreground text-[10px] uppercase tracking-wider">Sessions</span>
|
|
219
|
+
{Object.entries(scope.sessions).map(([key, ids]) => (
|
|
220
|
+
<div key={key} className="flex justify-between mt-1">
|
|
221
|
+
<span className="text-muted-foreground">{key}</span>
|
|
222
|
+
<span className="font-mono text-[10px]">{ids.length} recorded</span>
|
|
223
|
+
</div>
|
|
224
|
+
))}
|
|
225
|
+
</div>
|
|
226
|
+
)}
|
|
227
|
+
</CardContent>
|
|
228
|
+
</Card>
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function CIGatesCard({ gates }: { gates: Array<{ gate_name: string; status: string; duration_ms: number | null }> }) {
|
|
233
|
+
return (
|
|
234
|
+
<Card>
|
|
235
|
+
<CardHeader className="pb-2">
|
|
236
|
+
<CardTitle className="text-sm">CI Gates</CardTitle>
|
|
237
|
+
</CardHeader>
|
|
238
|
+
<CardContent className="space-y-0.5">
|
|
239
|
+
{gates.map((gate) => (
|
|
240
|
+
<div key={gate.gate_name} className="flex items-center gap-2 py-0.5">
|
|
241
|
+
<GateIndicator status={gate.status as GateStatus} />
|
|
242
|
+
<span className="flex-1 text-[11px]">{formatGateName(gate.gate_name)}</span>
|
|
243
|
+
{gate.duration_ms != null && (
|
|
244
|
+
<span className="font-mono text-[10px] text-muted-foreground">
|
|
245
|
+
{(gate.duration_ms / 1000).toFixed(1)}s
|
|
246
|
+
</span>
|
|
247
|
+
)}
|
|
248
|
+
</div>
|
|
249
|
+
))}
|
|
250
|
+
</CardContent>
|
|
251
|
+
</Card>
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// ─── Section: Transition Card ───────────────────────────────
|
|
256
|
+
|
|
257
|
+
function TransitionCard({
|
|
258
|
+
transition,
|
|
259
|
+
scopeId,
|
|
260
|
+
}: {
|
|
261
|
+
transition: import('@/types').TransitionReadiness;
|
|
262
|
+
scopeId: number;
|
|
263
|
+
}) {
|
|
264
|
+
const [dispatching, setDispatching] = useState(false);
|
|
265
|
+
const command = transition.edge.command?.replace('{id}', String(scopeId)) ?? null;
|
|
266
|
+
|
|
267
|
+
async function handleDispatch() {
|
|
268
|
+
if (!command) return;
|
|
269
|
+
setDispatching(true);
|
|
270
|
+
try {
|
|
271
|
+
await fetch('/api/orbital/dispatch', {
|
|
272
|
+
method: 'POST',
|
|
273
|
+
headers: { 'Content-Type': 'application/json' },
|
|
274
|
+
body: JSON.stringify({
|
|
275
|
+
scope_id: scopeId,
|
|
276
|
+
command,
|
|
277
|
+
transition: { from: transition.from, to: transition.to },
|
|
278
|
+
}),
|
|
279
|
+
});
|
|
280
|
+
} catch {
|
|
281
|
+
// dispatch error
|
|
282
|
+
} finally {
|
|
283
|
+
setDispatching(false);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
return (
|
|
288
|
+
<Card className={cn('transition-all', transition.ready ? 'border-bid-green/20' : 'border-border')}>
|
|
289
|
+
<CardHeader className="pb-2">
|
|
290
|
+
<div className="flex items-center justify-between">
|
|
291
|
+
<div className="flex items-center gap-2">
|
|
292
|
+
<Badge variant="outline" className="text-[10px] font-mono">{transition.from}</Badge>
|
|
293
|
+
<ArrowRight className="h-3 w-3 text-muted-foreground" />
|
|
294
|
+
<Badge variant="outline" className="text-[10px] font-mono">{transition.to}</Badge>
|
|
295
|
+
<span className="text-xs text-muted-foreground ml-1">{transition.edge.label}</span>
|
|
296
|
+
</div>
|
|
297
|
+
<div className="flex items-center gap-2">
|
|
298
|
+
{transition.ready && (
|
|
299
|
+
<Badge className="bg-bid-green/10 text-bid-green border-bid-green/20 text-[10px]">Ready</Badge>
|
|
300
|
+
)}
|
|
301
|
+
{command && transition.edge.dispatchOnly && (
|
|
302
|
+
<Button
|
|
303
|
+
size="sm"
|
|
304
|
+
variant={transition.ready ? 'default' : 'outline'}
|
|
305
|
+
className="h-6 text-[11px] gap-1"
|
|
306
|
+
disabled={!transition.ready || dispatching}
|
|
307
|
+
onClick={handleDispatch}
|
|
308
|
+
>
|
|
309
|
+
<Terminal className="h-3 w-3" />
|
|
310
|
+
{dispatching ? 'Dispatching...' : 'Dispatch'}
|
|
311
|
+
</Button>
|
|
312
|
+
)}
|
|
313
|
+
</div>
|
|
314
|
+
</div>
|
|
315
|
+
{command && (
|
|
316
|
+
<code className="text-[10px] font-mono text-muted-foreground/60 mt-1">{command}</code>
|
|
317
|
+
)}
|
|
318
|
+
</CardHeader>
|
|
319
|
+
<CardContent className="space-y-3">
|
|
320
|
+
{transition.hooks.length > 0 && (
|
|
321
|
+
<div>
|
|
322
|
+
<span className="text-[10px] uppercase tracking-wider text-muted-foreground/50 mb-1.5 block">
|
|
323
|
+
Workflow Hooks
|
|
324
|
+
</span>
|
|
325
|
+
<div className="space-y-1">
|
|
326
|
+
{transition.hooks.map((hook) => (
|
|
327
|
+
<HookStatusRow key={hook.id} hook={hook} />
|
|
328
|
+
))}
|
|
329
|
+
</div>
|
|
330
|
+
</div>
|
|
331
|
+
)}
|
|
332
|
+
{transition.edge.checklist && transition.edge.checklist.length > 0 && (
|
|
333
|
+
<div>
|
|
334
|
+
<span className="text-[10px] uppercase tracking-wider text-muted-foreground/50 mb-1.5 block">Checklist</span>
|
|
335
|
+
<div className="space-y-1">
|
|
336
|
+
{transition.edge.checklist.map((item, idx) => (
|
|
337
|
+
<div key={idx} className="flex items-start gap-2 text-xs text-muted-foreground">
|
|
338
|
+
<MinusCircle className="h-3 w-3 mt-0.5 flex-shrink-0 text-muted-foreground/40" />
|
|
339
|
+
<span>{item}</span>
|
|
340
|
+
</div>
|
|
341
|
+
))}
|
|
342
|
+
</div>
|
|
343
|
+
</div>
|
|
344
|
+
)}
|
|
345
|
+
{transition.blockers.length > 0 && (
|
|
346
|
+
<div className="rounded border border-red-500/20 bg-red-500/5 p-2">
|
|
347
|
+
<div className="flex items-center gap-1.5 mb-1">
|
|
348
|
+
<AlertTriangle className="h-3 w-3 text-red-400" />
|
|
349
|
+
<span className="text-[10px] font-medium text-red-400">
|
|
350
|
+
{transition.blockers.length} Blocker{transition.blockers.length !== 1 ? 's' : ''}
|
|
351
|
+
</span>
|
|
352
|
+
</div>
|
|
353
|
+
{transition.blockers.map((blocker, idx) => (
|
|
354
|
+
<p key={idx} className="text-[11px] text-red-400/80 ml-4.5">{blocker}</p>
|
|
355
|
+
))}
|
|
356
|
+
</div>
|
|
357
|
+
)}
|
|
358
|
+
</CardContent>
|
|
359
|
+
</Card>
|
|
360
|
+
);
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
function HookStatusRow({ hook }: { hook: HookStatus }) {
|
|
364
|
+
const statusIcon = hook.status === 'pass'
|
|
365
|
+
? <CheckCircle2 className="h-3.5 w-3.5 text-bid-green" />
|
|
366
|
+
: hook.status === 'fail'
|
|
367
|
+
? <XCircle className="h-3.5 w-3.5 text-red-400" />
|
|
368
|
+
: <MinusCircle className="h-3.5 w-3.5 text-muted-foreground/50" />;
|
|
369
|
+
|
|
370
|
+
return (
|
|
371
|
+
<div className="flex items-center gap-2 rounded px-2 py-1 hover:bg-surface-light/50">
|
|
372
|
+
{statusIcon}
|
|
373
|
+
<span className="flex-1 text-xs">{hook.label}</span>
|
|
374
|
+
<Badge
|
|
375
|
+
variant="outline"
|
|
376
|
+
className={cn('text-[9px] px-1.5 py-0 h-4 border', ENFORCEMENT_COLORS[hook.enforcement])}
|
|
377
|
+
>
|
|
378
|
+
{CATEGORY_LABELS[hook.category]}
|
|
379
|
+
</Badge>
|
|
380
|
+
{hook.reason && (
|
|
381
|
+
<span className="text-[10px] text-muted-foreground/60 max-w-[200px] truncate">{hook.reason}</span>
|
|
382
|
+
)}
|
|
383
|
+
</div>
|
|
384
|
+
);
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
// ─── Section: Rule Configuration ────────────────────────────
|
|
388
|
+
|
|
389
|
+
function RuleConfigSection() {
|
|
390
|
+
const { data: rulesData, loading } = useEnforcementRules();
|
|
391
|
+
|
|
392
|
+
if (loading || !rulesData || rulesData.rules.length === 0) return null;
|
|
393
|
+
|
|
394
|
+
return (
|
|
395
|
+
<section>
|
|
396
|
+
<div className="mb-3 flex items-center gap-3">
|
|
397
|
+
<Shield className="h-4 w-4 text-muted-foreground" />
|
|
398
|
+
<h2 className="text-base font-light">Rule Configuration</h2>
|
|
399
|
+
</div>
|
|
400
|
+
|
|
401
|
+
{/* Summary strip + Donut */}
|
|
402
|
+
<div className="mb-4 grid gap-4 lg:grid-cols-4">
|
|
403
|
+
<div className="lg:col-span-3 flex flex-wrap items-center gap-3 rounded-lg border border-border/50 bg-surface-light/20 px-4 py-2 self-start">
|
|
404
|
+
<SummaryChip count={rulesData.summary.guards} label="guards" color="text-red-400" />
|
|
405
|
+
<SummaryChip count={rulesData.summary.gates} label="gates" color="text-amber-400" />
|
|
406
|
+
<SummaryChip count={rulesData.summary.lifecycle} label="lifecycle" color="text-cyan-400" />
|
|
407
|
+
<SummaryChip count={rulesData.summary.observers} label="observers" color="text-zinc-400" />
|
|
408
|
+
<span className="text-border">|</span>
|
|
409
|
+
<span className="text-xs text-muted-foreground">
|
|
410
|
+
{rulesData.totalEdges} edge{rulesData.totalEdges !== 1 ? 's' : ''}
|
|
411
|
+
</span>
|
|
412
|
+
</div>
|
|
413
|
+
<Card className="flex items-center justify-center">
|
|
414
|
+
<CardContent className="p-2">
|
|
415
|
+
<HookCategoryDonut summary={rulesData.summary} />
|
|
416
|
+
</CardContent>
|
|
417
|
+
</Card>
|
|
418
|
+
</div>
|
|
419
|
+
|
|
420
|
+
{/* Matrix */}
|
|
421
|
+
<Card>
|
|
422
|
+
<CardContent className="p-0">
|
|
423
|
+
<div className="overflow-x-auto">
|
|
424
|
+
<table className="w-full text-xs">
|
|
425
|
+
<thead>
|
|
426
|
+
<tr className="border-b border-border text-left text-[10px] text-muted-foreground uppercase tracking-wider">
|
|
427
|
+
<th className="px-4 py-2 font-medium">Hook</th>
|
|
428
|
+
<th className="px-4 py-2 font-medium">Category</th>
|
|
429
|
+
<th className="px-4 py-2 font-medium">Level</th>
|
|
430
|
+
<th className="px-4 py-2 font-medium">Edges</th>
|
|
431
|
+
<th className="px-4 py-2 font-medium text-right">Violations</th>
|
|
432
|
+
<th className="px-4 py-2 font-medium text-right">Overrides</th>
|
|
433
|
+
<th className="px-4 py-2 font-medium text-right">Last Fired</th>
|
|
434
|
+
</tr>
|
|
435
|
+
</thead>
|
|
436
|
+
<tbody>
|
|
437
|
+
{rulesData.rules.map((rule) => (
|
|
438
|
+
<RuleRow key={rule.hook.id} rule={rule} />
|
|
439
|
+
))}
|
|
440
|
+
</tbody>
|
|
441
|
+
</table>
|
|
442
|
+
</div>
|
|
443
|
+
</CardContent>
|
|
444
|
+
</Card>
|
|
445
|
+
</section>
|
|
446
|
+
);
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
function RuleRow({ rule }: { rule: EnforcementRule }) {
|
|
450
|
+
const Icon = CATEGORY_ICON[rule.hook.category] ?? Shield;
|
|
451
|
+
return (
|
|
452
|
+
<tr className="border-b border-border/30 last:border-0 hover:bg-surface-light/30">
|
|
453
|
+
<td className="px-4 py-2">
|
|
454
|
+
<div className="flex items-center gap-1.5">
|
|
455
|
+
<Icon className="h-3 w-3 text-muted-foreground/50" />
|
|
456
|
+
<span className="font-medium">{rule.hook.label}</span>
|
|
457
|
+
</div>
|
|
458
|
+
</td>
|
|
459
|
+
<td className="px-4 py-2">
|
|
460
|
+
<Badge variant="outline" className={cn('text-[9px] border', ENFORCEMENT_COLORS[rule.enforcement])}>
|
|
461
|
+
{rule.hook.category}
|
|
462
|
+
</Badge>
|
|
463
|
+
</td>
|
|
464
|
+
<td className="px-4 py-2">
|
|
465
|
+
<span className={cn('text-[10px]', ENFORCEMENT_COLORS[rule.enforcement]?.split(' ')[0])}>
|
|
466
|
+
{rule.enforcement}
|
|
467
|
+
</span>
|
|
468
|
+
</td>
|
|
469
|
+
<td className="px-4 py-2">
|
|
470
|
+
{rule.edges.length > 0 ? (
|
|
471
|
+
<div className="flex flex-wrap gap-1">
|
|
472
|
+
{rule.edges.slice(0, 3).map((e, idx) => (
|
|
473
|
+
<span key={idx} className="inline-flex items-center gap-0.5 text-[9px] text-muted-foreground font-mono">
|
|
474
|
+
{e.from}<ArrowRight className="h-2 w-2" />{e.to}
|
|
475
|
+
</span>
|
|
476
|
+
))}
|
|
477
|
+
{rule.edges.length > 3 && (
|
|
478
|
+
<span className="text-[9px] text-muted-foreground">+{rule.edges.length - 3}</span>
|
|
479
|
+
)}
|
|
480
|
+
</div>
|
|
481
|
+
) : (
|
|
482
|
+
<span className="text-[9px] text-muted-foreground">-</span>
|
|
483
|
+
)}
|
|
484
|
+
</td>
|
|
485
|
+
<td className="px-4 py-2 text-right font-mono">
|
|
486
|
+
{rule.stats.violations > 0 ? (
|
|
487
|
+
<span className="text-red-400">{rule.stats.violations}</span>
|
|
488
|
+
) : (
|
|
489
|
+
<span className="text-muted-foreground/40">0</span>
|
|
490
|
+
)}
|
|
491
|
+
</td>
|
|
492
|
+
<td className="px-4 py-2 text-right font-mono">
|
|
493
|
+
{rule.stats.overrides > 0 ? (
|
|
494
|
+
<span className="text-amber-400">{rule.stats.overrides}</span>
|
|
495
|
+
) : (
|
|
496
|
+
<span className="text-muted-foreground/40">0</span>
|
|
497
|
+
)}
|
|
498
|
+
</td>
|
|
499
|
+
<td className="px-4 py-2 text-right text-muted-foreground/60">
|
|
500
|
+
{rule.stats.last_triggered
|
|
501
|
+
? formatDistanceToNow(new Date(rule.stats.last_triggered), { addSuffix: true })
|
|
502
|
+
: '-'}
|
|
503
|
+
</td>
|
|
504
|
+
</tr>
|
|
505
|
+
);
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
// ─── Section: Enforcement Activity ──────────────────────────
|
|
509
|
+
|
|
510
|
+
function EnforcementActivitySection() {
|
|
511
|
+
const { byRule, overrides, totalViolations, totalOverrides, loading: violationsLoading } = useViolations();
|
|
512
|
+
const { trend, loading: trendLoading } = useEnforcementRules();
|
|
513
|
+
|
|
514
|
+
const [recentViolations, setRecentViolations] = useState<OrbitalEvent[]>([]);
|
|
515
|
+
const fetchRecent = useCallback(async () => {
|
|
516
|
+
try {
|
|
517
|
+
const res = await fetch('/api/orbital/events?type=VIOLATION&limit=15');
|
|
518
|
+
if (res.ok) setRecentViolations(await res.json());
|
|
519
|
+
} catch { /* ok */ }
|
|
520
|
+
}, []);
|
|
521
|
+
useEffect(() => { fetchRecent(); }, [fetchRecent]);
|
|
522
|
+
|
|
523
|
+
const overrideRate = (totalViolations + totalOverrides) > 0
|
|
524
|
+
? Math.round((totalOverrides / (totalViolations + totalOverrides)) * 100) : 0;
|
|
525
|
+
|
|
526
|
+
const isLoading = violationsLoading || trendLoading;
|
|
527
|
+
|
|
528
|
+
return (
|
|
529
|
+
<section>
|
|
530
|
+
{/* Header with inline stats */}
|
|
531
|
+
<div className="mb-3 flex items-center gap-3 flex-wrap">
|
|
532
|
+
<ShieldAlert className="h-4 w-4 text-red-400" />
|
|
533
|
+
<h2 className="text-base font-light">Enforcement Activity</h2>
|
|
534
|
+
<div className="flex items-center gap-3 ml-auto text-xs">
|
|
535
|
+
<span><span className="text-red-400 font-medium">{totalViolations}</span> <span className="text-muted-foreground">violations</span></span>
|
|
536
|
+
<span><span className="text-amber-400 font-medium">{totalOverrides}</span> <span className="text-muted-foreground">overrides</span></span>
|
|
537
|
+
<span className={cn('font-medium', overrideRate > 50 ? 'text-amber-400' : 'text-muted-foreground')}>{overrideRate}% <span className="font-normal text-muted-foreground">override rate</span></span>
|
|
538
|
+
</div>
|
|
539
|
+
</div>
|
|
540
|
+
|
|
541
|
+
{isLoading ? (
|
|
542
|
+
<div className="flex h-20 items-center justify-center">
|
|
543
|
+
<div className="h-5 w-5 animate-spin rounded-full border-2 border-primary border-t-transparent" />
|
|
544
|
+
</div>
|
|
545
|
+
) : (
|
|
546
|
+
<div className="grid gap-4 lg:grid-cols-2">
|
|
547
|
+
{/* Left: charts */}
|
|
548
|
+
<div className="space-y-4">
|
|
549
|
+
<ViolationsVsOverridesChart byRule={byRule} overrides={overrides} />
|
|
550
|
+
<ViolationTrendChart trend={trend} />
|
|
551
|
+
</div>
|
|
552
|
+
|
|
553
|
+
{/* Right: tables */}
|
|
554
|
+
<div className="space-y-4">
|
|
555
|
+
<Card>
|
|
556
|
+
<CardHeader className="pb-1"><CardTitle className="text-sm">Recent Violations</CardTitle></CardHeader>
|
|
557
|
+
<CardContent className={recentViolations.length > 0 ? 'p-0' : undefined}>
|
|
558
|
+
{recentViolations.length === 0 ? (
|
|
559
|
+
<p className="text-xs text-muted-foreground text-center py-3">No violations recorded</p>
|
|
560
|
+
) : (
|
|
561
|
+
<div className="overflow-x-auto">
|
|
562
|
+
<table className="w-full text-xs">
|
|
563
|
+
<thead>
|
|
564
|
+
<tr className="border-b border-border text-left text-[10px] text-muted-foreground uppercase tracking-wider">
|
|
565
|
+
<th className="px-3 py-1.5 font-medium">Rule</th>
|
|
566
|
+
<th className="px-3 py-1.5 font-medium">Scope</th>
|
|
567
|
+
<th className="px-3 py-1.5 font-medium">Outcome</th>
|
|
568
|
+
<th className="px-3 py-1.5 font-medium text-right">Time</th>
|
|
569
|
+
</tr>
|
|
570
|
+
</thead>
|
|
571
|
+
<tbody>
|
|
572
|
+
{recentViolations.map((v) => {
|
|
573
|
+
const data = v.data as Record<string, string>;
|
|
574
|
+
return (
|
|
575
|
+
<tr key={v.id} className="border-b border-border/30 last:border-0 hover:bg-surface-light/30">
|
|
576
|
+
<td className="px-3 py-1 font-mono text-red-400">{data?.rule ?? '-'}</td>
|
|
577
|
+
<td className="px-3 py-1 font-mono text-muted-foreground">
|
|
578
|
+
{v.scope_id ? String(v.scope_id).padStart(3, '0') : '-'}
|
|
579
|
+
</td>
|
|
580
|
+
<td className="px-3 py-1">
|
|
581
|
+
<Badge variant="outline" className="text-[9px] border-red-500/30 text-red-400">
|
|
582
|
+
{data?.outcome ?? 'blocked'}
|
|
583
|
+
</Badge>
|
|
584
|
+
</td>
|
|
585
|
+
<td className="px-3 py-1 text-right text-muted-foreground/60">
|
|
586
|
+
{v.timestamp ? formatDistanceToNow(new Date(v.timestamp), { addSuffix: true }) : '-'}
|
|
587
|
+
</td>
|
|
588
|
+
</tr>
|
|
589
|
+
);
|
|
590
|
+
})}
|
|
591
|
+
</tbody>
|
|
592
|
+
</table>
|
|
593
|
+
</div>
|
|
594
|
+
)}
|
|
595
|
+
</CardContent>
|
|
596
|
+
</Card>
|
|
597
|
+
|
|
598
|
+
<Card>
|
|
599
|
+
<CardHeader className="pb-1"><CardTitle className="text-sm">Recent Overrides</CardTitle></CardHeader>
|
|
600
|
+
<CardContent>
|
|
601
|
+
{overrides.length === 0 ? (
|
|
602
|
+
<p className="text-xs text-muted-foreground text-center py-3">No overrides recorded</p>
|
|
603
|
+
) : (
|
|
604
|
+
<div className="space-y-1.5">
|
|
605
|
+
{overrides.slice(0, 8).map((o, idx) => (
|
|
606
|
+
<div key={idx} className="rounded border border-amber-500/20 bg-amber-500/5 px-2.5 py-1.5">
|
|
607
|
+
<div className="flex items-center justify-between gap-2">
|
|
608
|
+
<span className="text-[11px] font-medium text-amber-400">{o.rule ?? 'unknown'}</span>
|
|
609
|
+
<span className="flex-shrink-0 text-[9px] text-muted-foreground/50">
|
|
610
|
+
{o.date ? formatDistanceToNow(new Date(o.date), { addSuffix: true }) : '-'}
|
|
611
|
+
</span>
|
|
612
|
+
</div>
|
|
613
|
+
{o.reason && <p className="mt-0.5 text-[10px] text-muted-foreground line-clamp-1">{o.reason}</p>}
|
|
614
|
+
</div>
|
|
615
|
+
))}
|
|
616
|
+
</div>
|
|
617
|
+
)}
|
|
618
|
+
</CardContent>
|
|
619
|
+
</Card>
|
|
620
|
+
</div>
|
|
621
|
+
</div>
|
|
622
|
+
)}
|
|
623
|
+
</section>
|
|
624
|
+
);
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
// ─── Section: Global CI ─────────────────────────────────────
|
|
628
|
+
|
|
629
|
+
function GlobalCISection() {
|
|
630
|
+
const { gates, stats, loading } = useGates();
|
|
631
|
+
|
|
632
|
+
const totalPassed = stats.reduce((sum, s) => sum + s.passed, 0);
|
|
633
|
+
const totalRuns = stats.reduce((sum, s) => sum + s.total, 0);
|
|
634
|
+
const passRate = totalRuns > 0 ? Math.round((totalPassed / totalRuns) * 100) : 0;
|
|
635
|
+
const passing = gates.filter((g) => g.status === 'pass').length;
|
|
636
|
+
|
|
637
|
+
return (
|
|
638
|
+
<section>
|
|
639
|
+
{/* Header with inline pass rate */}
|
|
640
|
+
<div className="mb-3 flex items-center gap-3 flex-wrap">
|
|
641
|
+
<CheckCircle2 className="h-4 w-4 text-muted-foreground" />
|
|
642
|
+
<h2 className="text-base font-light">CI Gates</h2>
|
|
643
|
+
{gates.length > 0 && (
|
|
644
|
+
<Badge variant="secondary" className="text-[10px]">{passing}/{gates.length} passing</Badge>
|
|
645
|
+
)}
|
|
646
|
+
{totalRuns > 0 && (
|
|
647
|
+
<div className="ml-auto flex items-center gap-2">
|
|
648
|
+
<span className="text-xs text-muted-foreground">Pass rate</span>
|
|
649
|
+
<span className="text-sm font-medium">{passRate}%</span>
|
|
650
|
+
<div className="h-1.5 w-16 overflow-hidden rounded-full bg-muted">
|
|
651
|
+
<div className="h-full rounded-full bg-bid-green transition-all" style={{ width: `${passRate}%` }} />
|
|
652
|
+
</div>
|
|
653
|
+
</div>
|
|
654
|
+
)}
|
|
655
|
+
</div>
|
|
656
|
+
|
|
657
|
+
{loading ? (
|
|
658
|
+
<div className="flex h-20 items-center justify-center">
|
|
659
|
+
<div className="h-5 w-5 animate-spin rounded-full border-2 border-primary border-t-transparent" />
|
|
660
|
+
</div>
|
|
661
|
+
) : (
|
|
662
|
+
<div className="grid gap-4 lg:grid-cols-2">
|
|
663
|
+
{/* Latest run */}
|
|
664
|
+
<Card>
|
|
665
|
+
<CardHeader className="pb-1"><CardTitle className="text-sm">Latest Run</CardTitle></CardHeader>
|
|
666
|
+
<CardContent>
|
|
667
|
+
{gates.length === 0 ? (
|
|
668
|
+
<p className="text-xs text-muted-foreground text-center py-3">
|
|
669
|
+
No gate results yet. Run <code className="rounded bg-muted px-1">/test-checks</code> to populate.
|
|
670
|
+
</p>
|
|
671
|
+
) : (
|
|
672
|
+
<div className="space-y-0.5">
|
|
673
|
+
{gates.map((gate) => (
|
|
674
|
+
<div key={gate.id} className="flex items-center gap-3 rounded px-2 py-0.5 hover:bg-surface-light/50">
|
|
675
|
+
<GateIndicator status={gate.status as GateStatus} />
|
|
676
|
+
<span className="flex-1 text-[11px]">{formatGateName(gate.gate_name)}</span>
|
|
677
|
+
{gate.duration_ms != null && (
|
|
678
|
+
<span className="font-mono text-[10px] text-muted-foreground">{(gate.duration_ms / 1000).toFixed(1)}s</span>
|
|
679
|
+
)}
|
|
680
|
+
<span className="text-[10px] text-muted-foreground/50">
|
|
681
|
+
<Clock className="inline h-2.5 w-2.5 mr-0.5" />
|
|
682
|
+
{formatDistanceToNow(new Date(gate.run_at), { addSuffix: true })}
|
|
683
|
+
</span>
|
|
684
|
+
</div>
|
|
685
|
+
))}
|
|
686
|
+
</div>
|
|
687
|
+
)}
|
|
688
|
+
</CardContent>
|
|
689
|
+
</Card>
|
|
690
|
+
|
|
691
|
+
{/* Charts: history + duration */}
|
|
692
|
+
<div className="space-y-4">
|
|
693
|
+
<Card>
|
|
694
|
+
<CardHeader className="pb-1"><CardTitle className="text-sm">Gate History</CardTitle></CardHeader>
|
|
695
|
+
<CardContent>
|
|
696
|
+
{stats.length === 0 ? (
|
|
697
|
+
<ChartEmpty height={120} message="No history data" />
|
|
698
|
+
) : (
|
|
699
|
+
<ResponsiveContainer width="100%" height={Math.max(120, stats.length * 18)}>
|
|
700
|
+
<BarChart
|
|
701
|
+
data={stats.map((s) => ({ name: s.gate_name.replace(/-/g, ' ').slice(0, 12), passed: s.passed, failed: s.failed }))}
|
|
702
|
+
layout="vertical" margin={{ left: 0, right: 10, top: 0, bottom: 0 }}
|
|
703
|
+
>
|
|
704
|
+
<XAxis type="number" hide />
|
|
705
|
+
<YAxis dataKey="name" type="category" width={85}
|
|
706
|
+
tick={{ fontSize: 9, fill: 'hsl(var(--muted-foreground))' }} />
|
|
707
|
+
<RechartsTooltip contentStyle={{
|
|
708
|
+
background: 'hsl(var(--card))', border: '1px solid hsl(var(--border))',
|
|
709
|
+
borderRadius: '6px', fontSize: '11px',
|
|
710
|
+
}} />
|
|
711
|
+
<Bar dataKey="passed" stackId="a" radius={[0, 0, 0, 0]}>
|
|
712
|
+
{stats.map((_, idx) => <Cell key={idx} fill="#00c853" />)}
|
|
713
|
+
</Bar>
|
|
714
|
+
<Bar dataKey="failed" stackId="a" radius={[0, 4, 4, 0]}>
|
|
715
|
+
{stats.map((_, idx) => <Cell key={idx} fill="#ff1744" />)}
|
|
716
|
+
</Bar>
|
|
717
|
+
</BarChart>
|
|
718
|
+
</ResponsiveContainer>
|
|
719
|
+
)}
|
|
720
|
+
</CardContent>
|
|
721
|
+
</Card>
|
|
722
|
+
|
|
723
|
+
<Card>
|
|
724
|
+
<CardHeader className="pb-1"><CardTitle className="text-sm">Gate Duration</CardTitle></CardHeader>
|
|
725
|
+
<CardContent>
|
|
726
|
+
{!gates.some((g) => g.duration_ms != null) ? (
|
|
727
|
+
<ChartEmpty height={120} message="No duration data" />
|
|
728
|
+
) : (
|
|
729
|
+
<ResponsiveContainer width="100%" height={Math.max(120, gates.filter((g) => g.duration_ms != null).length * 18)}>
|
|
730
|
+
<BarChart
|
|
731
|
+
data={gates
|
|
732
|
+
.filter((g) => g.duration_ms != null)
|
|
733
|
+
.map((g) => ({
|
|
734
|
+
name: g.gate_name.replace(/-/g, ' ').slice(0, 12),
|
|
735
|
+
seconds: Number((g.duration_ms! / 1000).toFixed(1)),
|
|
736
|
+
status: g.status,
|
|
737
|
+
}))}
|
|
738
|
+
layout="vertical" margin={{ left: 0, right: 10, top: 0, bottom: 0 }}
|
|
739
|
+
>
|
|
740
|
+
<XAxis type="number" unit="s" tick={{ fontSize: 9, fill: 'hsl(var(--muted-foreground))' }} />
|
|
741
|
+
<YAxis dataKey="name" type="category" width={85}
|
|
742
|
+
tick={{ fontSize: 9, fill: 'hsl(var(--muted-foreground))' }} />
|
|
743
|
+
<RechartsTooltip
|
|
744
|
+
formatter={(val: number) => [`${val}s`, 'Duration']}
|
|
745
|
+
contentStyle={{
|
|
746
|
+
background: 'hsl(var(--card))', border: '1px solid hsl(var(--border))',
|
|
747
|
+
borderRadius: '6px', fontSize: '11px',
|
|
748
|
+
}}
|
|
749
|
+
/>
|
|
750
|
+
<Bar dataKey="seconds" radius={[0, 4, 4, 0]}>
|
|
751
|
+
{gates.filter((g) => g.duration_ms != null).map((g, idx) => (
|
|
752
|
+
<Cell key={idx} fill={g.status === 'pass' ? '#00c85340' : g.status === 'fail' ? '#ff174440' : '#06b6d440'} />
|
|
753
|
+
))}
|
|
754
|
+
</Bar>
|
|
755
|
+
</BarChart>
|
|
756
|
+
</ResponsiveContainer>
|
|
757
|
+
)}
|
|
758
|
+
</CardContent>
|
|
759
|
+
</Card>
|
|
760
|
+
</div>
|
|
761
|
+
</div>
|
|
762
|
+
)}
|
|
763
|
+
</section>
|
|
764
|
+
);
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
// ─── Shared Components ──────────────────────────────────────
|
|
768
|
+
|
|
769
|
+
function SummaryChip({ count, label, color }: { count: number; label: string; color: string }) {
|
|
770
|
+
return (
|
|
771
|
+
<span className="flex items-center gap-1">
|
|
772
|
+
<span className={cn('text-sm font-medium', color)}>{count}</span>
|
|
773
|
+
<span className="text-[11px] text-muted-foreground">{label}</span>
|
|
774
|
+
</span>
|
|
775
|
+
);
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
|
|
779
|
+
// ─── Chart: Scope Readiness Overview ────────────────────────
|
|
780
|
+
|
|
781
|
+
function ScopeReadinessOverview({
|
|
782
|
+
scopes,
|
|
783
|
+
}: {
|
|
784
|
+
scopes: Scope[];
|
|
785
|
+
selectedId: number | null;
|
|
786
|
+
onSelect: (id: number) => void;
|
|
787
|
+
}) {
|
|
788
|
+
// For each scope, we show a mini readiness indicator
|
|
789
|
+
// Fetch readiness for all active scopes would be expensive,
|
|
790
|
+
// so we show a distribution bar based on scope status position in the workflow
|
|
791
|
+
const { engine } = useWorkflow();
|
|
792
|
+
const lists = engine.getLists().filter((l) => !engine.isTerminalStatus(l.id) && l.id !== 'icebox');
|
|
793
|
+
const statusCounts = new Map<string, number>();
|
|
794
|
+
for (const scope of scopes) {
|
|
795
|
+
statusCounts.set(scope.status, (statusCounts.get(scope.status) ?? 0) + 1);
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
const chartData = lists
|
|
799
|
+
.filter((l) => statusCounts.has(l.id))
|
|
800
|
+
.map((l) => ({
|
|
801
|
+
name: l.label,
|
|
802
|
+
count: statusCounts.get(l.id) ?? 0,
|
|
803
|
+
color: l.hex,
|
|
804
|
+
}));
|
|
805
|
+
|
|
806
|
+
if (chartData.length === 0) return null;
|
|
807
|
+
|
|
808
|
+
return (
|
|
809
|
+
<Card className="mb-4">
|
|
810
|
+
<CardHeader className="pb-1">
|
|
811
|
+
<CardTitle className="text-sm">Scope Distribution</CardTitle>
|
|
812
|
+
</CardHeader>
|
|
813
|
+
<CardContent>
|
|
814
|
+
<ResponsiveContainer width="100%" height={100}>
|
|
815
|
+
<BarChart data={chartData} margin={{ left: 0, right: 10, top: 5, bottom: 0 }}>
|
|
816
|
+
<XAxis dataKey="name" tick={{ fontSize: 10, fill: 'hsl(var(--muted-foreground))' }} />
|
|
817
|
+
<YAxis allowDecimals={false} tick={{ fontSize: 9, fill: 'hsl(var(--muted-foreground))' }} width={20} />
|
|
818
|
+
<RechartsTooltip
|
|
819
|
+
contentStyle={{
|
|
820
|
+
background: 'hsl(var(--card))', border: '1px solid hsl(var(--border))',
|
|
821
|
+
borderRadius: '6px', fontSize: '11px',
|
|
822
|
+
}}
|
|
823
|
+
/>
|
|
824
|
+
<Bar dataKey="count" radius={[4, 4, 0, 0]}>
|
|
825
|
+
{chartData.map((d, idx) => <Cell key={idx} fill={d.color} fillOpacity={0.7} />)}
|
|
826
|
+
</Bar>
|
|
827
|
+
</BarChart>
|
|
828
|
+
</ResponsiveContainer>
|
|
829
|
+
</CardContent>
|
|
830
|
+
</Card>
|
|
831
|
+
);
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
// ─── Chart: Hook Category Donut ─────────────────────────────
|
|
835
|
+
|
|
836
|
+
const CATEGORY_DONUT_COLORS: Record<string, string> = {
|
|
837
|
+
guards: '#EF4444',
|
|
838
|
+
gates: '#F59E0B',
|
|
839
|
+
lifecycle: '#3B82F6',
|
|
840
|
+
observers: '#71717A',
|
|
841
|
+
};
|
|
842
|
+
|
|
843
|
+
function HookCategoryDonut({ summary }: { summary: { guards: number; gates: number; lifecycle: number; observers: number } }) {
|
|
844
|
+
const data = [
|
|
845
|
+
{ name: 'Guards', value: summary.guards },
|
|
846
|
+
{ name: 'Gates', value: summary.gates },
|
|
847
|
+
{ name: 'Lifecycle', value: summary.lifecycle },
|
|
848
|
+
{ name: 'Observers', value: summary.observers },
|
|
849
|
+
].filter((d) => d.value > 0);
|
|
850
|
+
|
|
851
|
+
const colors = [
|
|
852
|
+
CATEGORY_DONUT_COLORS.guards,
|
|
853
|
+
CATEGORY_DONUT_COLORS.gates,
|
|
854
|
+
CATEGORY_DONUT_COLORS.lifecycle,
|
|
855
|
+
CATEGORY_DONUT_COLORS.observers,
|
|
856
|
+
];
|
|
857
|
+
|
|
858
|
+
const total = data.reduce((sum, d) => sum + d.value, 0);
|
|
859
|
+
|
|
860
|
+
return (
|
|
861
|
+
<div className="relative">
|
|
862
|
+
<ResponsiveContainer width={120} height={120}>
|
|
863
|
+
<PieChart>
|
|
864
|
+
<Pie
|
|
865
|
+
data={data}
|
|
866
|
+
cx="50%"
|
|
867
|
+
cy="50%"
|
|
868
|
+
innerRadius={32}
|
|
869
|
+
outerRadius={50}
|
|
870
|
+
paddingAngle={3}
|
|
871
|
+
dataKey="value"
|
|
872
|
+
stroke="none"
|
|
873
|
+
>
|
|
874
|
+
{data.map((_, idx) => <Cell key={idx} fill={colors[idx]} fillOpacity={0.8} />)}
|
|
875
|
+
</Pie>
|
|
876
|
+
<RechartsTooltip
|
|
877
|
+
contentStyle={{
|
|
878
|
+
background: 'hsl(var(--card))', border: '1px solid hsl(var(--border))',
|
|
879
|
+
borderRadius: '6px', fontSize: '11px',
|
|
880
|
+
}}
|
|
881
|
+
/>
|
|
882
|
+
</PieChart>
|
|
883
|
+
</ResponsiveContainer>
|
|
884
|
+
<div className="absolute inset-0 flex items-center justify-center pointer-events-none">
|
|
885
|
+
<span className="text-lg font-light text-foreground">{total}</span>
|
|
886
|
+
</div>
|
|
887
|
+
</div>
|
|
888
|
+
);
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
// ─── Empty overlay for charts ───────────────────────────────
|
|
892
|
+
|
|
893
|
+
function ChartEmpty({ height, message }: { height: number; message: string }) {
|
|
894
|
+
return (
|
|
895
|
+
<div className="relative">
|
|
896
|
+
<div style={{ height }} className="opacity-30">
|
|
897
|
+
<ResponsiveContainer width="100%" height={height}>
|
|
898
|
+
<BarChart data={[{ name: '', value: 0 }]} layout="vertical" margin={{ left: 10, right: 20, top: 0, bottom: 0 }}>
|
|
899
|
+
<CartesianGrid strokeDasharray="3 3" stroke="hsl(var(--border))" opacity={0.4} />
|
|
900
|
+
<XAxis type="number" domain={[0, 10]} tick={{ fontSize: 9, fill: 'hsl(var(--muted-foreground))' }} />
|
|
901
|
+
<YAxis dataKey="name" type="category" width={80} tick={{ fontSize: 9, fill: 'hsl(var(--muted-foreground))' }} />
|
|
902
|
+
</BarChart>
|
|
903
|
+
</ResponsiveContainer>
|
|
904
|
+
</div>
|
|
905
|
+
<div className="absolute inset-0 flex items-center justify-center">
|
|
906
|
+
<span className="text-xs text-muted-foreground">{message}</span>
|
|
907
|
+
</div>
|
|
908
|
+
</div>
|
|
909
|
+
);
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
// ─── Chart: Violations vs Overrides ─────────────────────────
|
|
913
|
+
|
|
914
|
+
function ViolationsVsOverridesChart({
|
|
915
|
+
byRule,
|
|
916
|
+
overrides,
|
|
917
|
+
}: {
|
|
918
|
+
byRule: Array<{ rule: string; count: number }>;
|
|
919
|
+
overrides: Array<{ rule: string }>;
|
|
920
|
+
}) {
|
|
921
|
+
const overrideCountByRule = new Map<string, number>();
|
|
922
|
+
for (const o of overrides) {
|
|
923
|
+
const rule = o.rule ?? 'unknown';
|
|
924
|
+
overrideCountByRule.set(rule, (overrideCountByRule.get(rule) ?? 0) + 1);
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
const chartData = byRule.map((r) => ({
|
|
928
|
+
name: String(r.rule ?? 'unknown').slice(0, 22),
|
|
929
|
+
violations: r.count,
|
|
930
|
+
overrides: overrideCountByRule.get(String(r.rule)) ?? 0,
|
|
931
|
+
}));
|
|
932
|
+
|
|
933
|
+
const empty = chartData.length === 0;
|
|
934
|
+
|
|
935
|
+
return (
|
|
936
|
+
<Card>
|
|
937
|
+
<CardHeader className="pb-2"><CardTitle className="text-sm">Violations vs Overrides by Rule</CardTitle></CardHeader>
|
|
938
|
+
<CardContent>
|
|
939
|
+
{empty ? (
|
|
940
|
+
<ChartEmpty height={120} message="No violation data yet" />
|
|
941
|
+
) : (
|
|
942
|
+
<ResponsiveContainer width="100%" height={Math.max(140, chartData.length * 30)}>
|
|
943
|
+
<BarChart data={chartData} layout="vertical" margin={{ left: 10, right: 20, top: 0, bottom: 0 }}>
|
|
944
|
+
<XAxis type="number" hide />
|
|
945
|
+
<YAxis dataKey="name" type="category" width={150}
|
|
946
|
+
tick={{ fontSize: 10, fill: 'hsl(var(--muted-foreground))' }} />
|
|
947
|
+
<RechartsTooltip contentStyle={{
|
|
948
|
+
background: 'hsl(var(--card))', border: '1px solid hsl(var(--border))',
|
|
949
|
+
borderRadius: '6px', fontSize: '11px',
|
|
950
|
+
}} />
|
|
951
|
+
<Legend verticalAlign="top" height={24} iconSize={8}
|
|
952
|
+
wrapperStyle={{ fontSize: '10px', color: 'hsl(var(--muted-foreground))' }} />
|
|
953
|
+
<Bar dataKey="violations" stackId="a" fill="#EF4444" fillOpacity={0.8} radius={[0, 0, 0, 0]} />
|
|
954
|
+
<Bar dataKey="overrides" stackId="a" fill="#F59E0B" fillOpacity={0.8} radius={[0, 4, 4, 0]} />
|
|
955
|
+
</BarChart>
|
|
956
|
+
</ResponsiveContainer>
|
|
957
|
+
)}
|
|
958
|
+
</CardContent>
|
|
959
|
+
</Card>
|
|
960
|
+
);
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
// ─── Chart: Violation Trend ─────────────────────────────────
|
|
964
|
+
|
|
965
|
+
function ViolationTrendChart({ trend }: { trend: ViolationTrendPoint[] }) {
|
|
966
|
+
const dailyTotals = new Map<string, number>();
|
|
967
|
+
for (const point of trend) {
|
|
968
|
+
dailyTotals.set(point.day, (dailyTotals.get(point.day) ?? 0) + point.count);
|
|
969
|
+
}
|
|
970
|
+
const chartData = [...dailyTotals.entries()]
|
|
971
|
+
.map(([day, count]) => ({ day: day.slice(5), count }))
|
|
972
|
+
.slice(-30);
|
|
973
|
+
|
|
974
|
+
const empty = chartData.length < 2;
|
|
975
|
+
|
|
976
|
+
return (
|
|
977
|
+
<Card>
|
|
978
|
+
<CardHeader className="pb-2"><CardTitle className="text-sm">Violation Trend (30d)</CardTitle></CardHeader>
|
|
979
|
+
<CardContent>
|
|
980
|
+
{empty ? (
|
|
981
|
+
<div className="relative">
|
|
982
|
+
<div style={{ height: 120 }} className="opacity-30">
|
|
983
|
+
<ResponsiveContainer width="100%" height={120}>
|
|
984
|
+
<AreaChart data={[{ day: '', count: 0 }]} margin={{ left: 0, right: 10, top: 5, bottom: 0 }}>
|
|
985
|
+
<CartesianGrid strokeDasharray="3 3" stroke="hsl(var(--border))" opacity={0.4} />
|
|
986
|
+
<XAxis dataKey="day" tick={{ fontSize: 9, fill: 'hsl(var(--muted-foreground))' }} />
|
|
987
|
+
<YAxis domain={[0, 10]} tick={{ fontSize: 9, fill: 'hsl(var(--muted-foreground))' }} width={30} />
|
|
988
|
+
</AreaChart>
|
|
989
|
+
</ResponsiveContainer>
|
|
990
|
+
</div>
|
|
991
|
+
<div className="absolute inset-0 flex items-center justify-center">
|
|
992
|
+
<span className="text-xs text-muted-foreground">No trend data yet</span>
|
|
993
|
+
</div>
|
|
994
|
+
</div>
|
|
995
|
+
) : (
|
|
996
|
+
<ResponsiveContainer width="100%" height={140}>
|
|
997
|
+
<AreaChart data={chartData} margin={{ left: 0, right: 10, top: 5, bottom: 0 }}>
|
|
998
|
+
<CartesianGrid strokeDasharray="3 3" stroke="hsl(var(--border))" opacity={0.3} />
|
|
999
|
+
<XAxis dataKey="day" tick={{ fontSize: 9, fill: 'hsl(var(--muted-foreground))' }} />
|
|
1000
|
+
<YAxis tick={{ fontSize: 9, fill: 'hsl(var(--muted-foreground))' }} width={30} />
|
|
1001
|
+
<RechartsTooltip contentStyle={{
|
|
1002
|
+
background: 'hsl(var(--card))', border: '1px solid hsl(var(--border))',
|
|
1003
|
+
borderRadius: '6px', fontSize: '11px',
|
|
1004
|
+
}} />
|
|
1005
|
+
<Area type="monotone" dataKey="count" stroke="#EF4444" fill="#EF444420" strokeWidth={1.5} />
|
|
1006
|
+
</AreaChart>
|
|
1007
|
+
</ResponsiveContainer>
|
|
1008
|
+
)}
|
|
1009
|
+
</CardContent>
|
|
1010
|
+
</Card>
|
|
1011
|
+
);
|
|
1012
|
+
}
|