@igorjpimenta/manifold 0.0.0-stage → 2026.11.22-beta.3

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.
Files changed (210) hide show
  1. package/.migrations/ops/0000_futuristic_karma.sql +111 -0
  2. package/.migrations/ops/0001_low_maximus.sql +7 -0
  3. package/.migrations/ops/meta/0000_snapshot.json +763 -0
  4. package/.migrations/ops/meta/0001_snapshot.json +173 -0
  5. package/.migrations/ops/meta/_journal.json +20 -0
  6. package/.migrations/runtime/0000_real_boomer.sql +180 -0
  7. package/.migrations/runtime/0001_hot_dakota_north.sql +2 -0
  8. package/.migrations/runtime/0002_breezy_vertigo.sql +8 -0
  9. package/.migrations/runtime/0003_dashing_jack_flag.sql +5 -0
  10. package/.migrations/runtime/0004_panoramic_ego.sql +1 -0
  11. package/.migrations/runtime/0005_tidy_ben_grimm.sql +10 -0
  12. package/.migrations/runtime/0006_wet_nightmare.sql +57 -0
  13. package/.migrations/runtime/0007_ambiguous_chronomancer.sql +8 -0
  14. package/.migrations/runtime/0008_wealthy_thundra.sql +301 -0
  15. package/.migrations/runtime/0009_lying_shocker.sql +96 -0
  16. package/.migrations/runtime/0010_solid_phantom_reporter.sql +160 -0
  17. package/.migrations/runtime/0011_windy_demogoblin.sql +175 -0
  18. package/.migrations/runtime/0012_restore_harness_fks.sql +103 -0
  19. package/.migrations/runtime/meta/0000_snapshot.json +1181 -0
  20. package/.migrations/runtime/meta/0001_snapshot.json +1209 -0
  21. package/.migrations/runtime/meta/0002_snapshot.json +1261 -0
  22. package/.migrations/runtime/meta/0003_snapshot.json +1292 -0
  23. package/.migrations/runtime/meta/0004_snapshot.json +1240 -0
  24. package/.migrations/runtime/meta/0006_snapshot.json +1310 -0
  25. package/.migrations/runtime/meta/0007_snapshot.json +1362 -0
  26. package/.migrations/runtime/meta/0008_snapshot.json +1742 -0
  27. package/.migrations/runtime/meta/0009_snapshot.json +2413 -0
  28. package/.migrations/runtime/meta/0010_snapshot.json +2562 -0
  29. package/.migrations/runtime/meta/0011_snapshot.json +2812 -0
  30. package/.migrations/runtime/meta/0012_snapshot.json +2812 -0
  31. package/.migrations/runtime/meta/_journal.json +97 -0
  32. package/README.md +1583 -2
  33. package/RELEASING.md +89 -0
  34. package/agent/fleet.js +100 -0
  35. package/bin/cli.js +854 -0
  36. package/bin/manifold.js +4 -0
  37. package/boot/flow-revival.js +536 -0
  38. package/budget/index.js +495 -0
  39. package/budget/lib.js +59 -0
  40. package/dashboard/cost.js +528 -0
  41. package/dashboard/dist/assets/index-CUfp63sj.css +1 -0
  42. package/dashboard/dist/assets/index-Qy9JMpma.js +371 -0
  43. package/dashboard/dist/index.html +13 -0
  44. package/dashboard/event-log.js +267 -0
  45. package/dashboard/index.html +12 -0
  46. package/dashboard/package-lock.json +2877 -0
  47. package/dashboard/package.json +37 -0
  48. package/dashboard/pipeline-graph.js +131 -0
  49. package/dashboard/postcss.config.js +6 -0
  50. package/dashboard/search.js +183 -0
  51. package/dashboard/server.js +1015 -0
  52. package/dashboard/src/App.tsx +42 -0
  53. package/dashboard/src/api/client.ts +118 -0
  54. package/dashboard/src/api/types.ts +510 -0
  55. package/dashboard/src/api/ws.tsx +112 -0
  56. package/dashboard/src/components/CancelButton.tsx +63 -0
  57. package/dashboard/src/components/ClickToCopy.tsx +68 -0
  58. package/dashboard/src/components/CopyButton.tsx +61 -0
  59. package/dashboard/src/components/DailyCostTrend.tsx +85 -0
  60. package/dashboard/src/components/DailyTimeTrend.tsx +94 -0
  61. package/dashboard/src/components/Funnel.tsx +149 -0
  62. package/dashboard/src/components/GateForm.tsx +158 -0
  63. package/dashboard/src/components/GraphView.tsx +302 -0
  64. package/dashboard/src/components/GroupPathsSummary.tsx +47 -0
  65. package/dashboard/src/components/Histogram.tsx +292 -0
  66. package/dashboard/src/components/Layout.tsx +28 -0
  67. package/dashboard/src/components/NeedsAttention.tsx +98 -0
  68. package/dashboard/src/components/NodeContextCard.tsx +132 -0
  69. package/dashboard/src/components/PathTrail.tsx +35 -0
  70. package/dashboard/src/components/PipelineCostBreakdown.tsx +277 -0
  71. package/dashboard/src/components/RerunButton.tsx +46 -0
  72. package/dashboard/src/components/RunComparison.tsx +53 -0
  73. package/dashboard/src/components/Sparkline.tsx +94 -0
  74. package/dashboard/src/components/StatStrip.tsx +147 -0
  75. package/dashboard/src/components/StateTree.tsx +84 -0
  76. package/dashboard/src/components/StatusBadge.tsx +18 -0
  77. package/dashboard/src/components/SubflowPathPills.tsx +38 -0
  78. package/dashboard/src/components/SubflowSummary.tsx +24 -0
  79. package/dashboard/src/components/SubflowsCard.tsx +327 -0
  80. package/dashboard/src/components/TodayStrip.tsx +86 -0
  81. package/dashboard/src/components/TranscriptPane.tsx +99 -0
  82. package/dashboard/src/components/TranscriptRow.tsx +69 -0
  83. package/dashboard/src/components/ui/badge.tsx +38 -0
  84. package/dashboard/src/components/ui/button.tsx +28 -0
  85. package/dashboard/src/components/ui/card.tsx +42 -0
  86. package/dashboard/src/components/ui/skeleton.tsx +9 -0
  87. package/dashboard/src/components/ui/table.tsx +62 -0
  88. package/dashboard/src/index.css +26 -0
  89. package/dashboard/src/lib/anomaly.ts +42 -0
  90. package/dashboard/src/lib/format.ts +30 -0
  91. package/dashboard/src/lib/step-history.ts +13 -0
  92. package/dashboard/src/lib/subflow.ts +154 -0
  93. package/dashboard/src/lib/use-click-outside.ts +28 -0
  94. package/dashboard/src/lib/use-ignored-clusters.ts +67 -0
  95. package/dashboard/src/lib/utils.ts +6 -0
  96. package/dashboard/src/main.tsx +10 -0
  97. package/dashboard/src/types/shims.d.ts +4 -0
  98. package/dashboard/src/views/Home.tsx +478 -0
  99. package/dashboard/src/views/PipelineDetail.tsx +1185 -0
  100. package/dashboard/src/views/PipelinesList.tsx +111 -0
  101. package/dashboard/src/views/RunDetail.tsx +248 -0
  102. package/dashboard/src/views/Search.tsx +196 -0
  103. package/dashboard/stats.js +668 -0
  104. package/dashboard/tailwind.config.ts +43 -0
  105. package/dashboard/tree-stats.js +12 -0
  106. package/dashboard/tsconfig.json +25 -0
  107. package/dashboard/views.js +231 -0
  108. package/dashboard/vite.config.ts +34 -0
  109. package/drizzle.config.js +12 -0
  110. package/drizzle.config.ops.js +12 -0
  111. package/elevation.js +116 -0
  112. package/engine/admission-promotion-resume.js +127 -0
  113. package/engine/agent-dispatch.js +64 -0
  114. package/engine/child-resume-trigger.js +315 -0
  115. package/engine/executor-budget.js +87 -0
  116. package/engine/executor-cancel.js +83 -0
  117. package/engine/executor-errors.js +122 -0
  118. package/engine/executor-helpers.js +254 -0
  119. package/engine/executor-nodes.js +292 -0
  120. package/engine/executor-persist.js +212 -0
  121. package/engine/executor-subflow-children.js +275 -0
  122. package/engine/executor.js +1013 -0
  123. package/engine/global-concurrency.js +33 -0
  124. package/engine/loader.js +528 -0
  125. package/engine/needs-resolver.js +229 -0
  126. package/engine/pipelines-watcher.js +133 -0
  127. package/engine/result-replay.js +34 -0
  128. package/engine/revival-messages.js +11 -0
  129. package/engine/spawn-child.js +55 -0
  130. package/engine/wait-for-flow-settlement.js +109 -0
  131. package/events/catalog.js +26 -0
  132. package/events/emit.js +44 -0
  133. package/events/kinds.js +118 -0
  134. package/events/serve-ws.js +74 -0
  135. package/events/stream.js +35 -0
  136. package/events/ws-dialog.js +257 -0
  137. package/events/ws-frame.js +194 -0
  138. package/events/ws-run-events.js +70 -0
  139. package/events.js +32 -0
  140. package/gates/gate-resolver.js +576 -0
  141. package/gates/paused-flows.js +55 -0
  142. package/graphql/columns.js +67 -0
  143. package/graphql/schema.js +333 -0
  144. package/index.js +49 -0
  145. package/mcp/http.js +159 -0
  146. package/mcp/identity.js +94 -0
  147. package/mcp/stdio.js +80 -0
  148. package/mcp/tools.js +245 -0
  149. package/mcp/wire-ops.js +178 -0
  150. package/package.json +49 -4
  151. package/routes/bearer-auth.js +57 -0
  152. package/routes/discuss-audio.js +87 -0
  153. package/routes/discuss-component.js +39 -0
  154. package/routes/discuss-draft.js +159 -0
  155. package/routes/discuss-helpers.js +20 -0
  156. package/routes/discuss.js +848 -0
  157. package/routes/failures.js +104 -0
  158. package/routes/graphql.js +61 -0
  159. package/routes/health.js +54 -0
  160. package/routes/operator-discuss.js +193 -0
  161. package/routes/operator-resume.js +32 -0
  162. package/routes/operator-retry.js +301 -0
  163. package/routes/operator.js +539 -0
  164. package/routes/pipelines.js +118 -0
  165. package/routes/runs.js +1129 -0
  166. package/scripts/ci/import-check.mjs +50 -0
  167. package/scripts/link-core-self.mjs +31 -0
  168. package/scripts/with-guard.sh +24 -0
  169. package/server/app.js +503 -0
  170. package/server/registry.js +53 -0
  171. package/server/serve.js +163 -0
  172. package/state/admission-queue-store.js +325 -0
  173. package/state/attribution-registries.js +102 -0
  174. package/state/batch-writer.js +162 -0
  175. package/state/db-guard.js +63 -0
  176. package/state/db-health.js +27 -0
  177. package/state/db.js +122 -0
  178. package/state/discuss-store.js +299 -0
  179. package/state/failure-store.js +427 -0
  180. package/state/migrate.js +104 -0
  181. package/state/node-cost.js +67 -0
  182. package/state/node-executions.js +775 -0
  183. package/state/node-health-store.js +124 -0
  184. package/state/ops-merge.js +93 -0
  185. package/state/paths.js +146 -0
  186. package/state/pipeline-dirs.js +99 -0
  187. package/state/pipeline-registry.js +449 -0
  188. package/state/run-store.js +697 -0
  189. package/state/schema.js +438 -0
  190. package/state/schema.ops.js +44 -0
  191. package/state/session-index.js +177 -0
  192. package/state/session-keys.js +39 -0
  193. package/state/state-store.js +311 -0
  194. package/state/subflow-state.js +126 -0
  195. package/state/tool-handoff.js +169 -0
  196. package/telemetry/budget-alert.js +353 -0
  197. package/telemetry/cli.js +331 -0
  198. package/telemetry/grammar.js +119 -0
  199. package/telemetry/http-budget.js +132 -0
  200. package/telemetry/http-cost.js +670 -0
  201. package/telemetry/http-helpers.js +134 -0
  202. package/telemetry/http-tree.js +349 -0
  203. package/telemetry/http.js +44 -0
  204. package/telemetry/index.js +307 -0
  205. package/telemetry/ingest.js +134 -0
  206. package/telemetry/labels.js +115 -0
  207. package/telemetry/pricer.js +77 -0
  208. package/telemetry/resolver.js +314 -0
  209. package/telemetry/store.js +147 -0
  210. package/utils/run-patch.js +43 -0
@@ -0,0 +1,67 @@
1
+ // localStorage-backed suppression state for failure clusters.
2
+ //
3
+ // Cluster key = `${pipelineId}::${step}`. Per-signature suppression
4
+ // would be more precise but adds UI surface area; start coarse and
5
+ // only refine if the operator hits noise on novel signatures within
6
+ // a step they've already silenced. Per-browser by design — the
7
+ // dashboard is a personal tool and a Mac-vs-phone split between
8
+ // "what I've triaged" is fine.
9
+
10
+ import { useCallback, useEffect, useState } from "react";
11
+
12
+ const STORAGE_KEY = "gf-ignored-clusters-v1";
13
+
14
+ export type IgnoredMap = Record<string, { at: number }>;
15
+
16
+ function read(): IgnoredMap {
17
+ try {
18
+ const raw = localStorage.getItem(STORAGE_KEY);
19
+ if (!raw) return {};
20
+ const parsed = JSON.parse(raw);
21
+ return parsed && typeof parsed === "object" ? parsed : {};
22
+ } catch {
23
+ return {};
24
+ }
25
+ }
26
+
27
+ function write(next: IgnoredMap) {
28
+ try { localStorage.setItem(STORAGE_KEY, JSON.stringify(next)); } catch {}
29
+ }
30
+
31
+ export function clusterKey(pipelineId: string | undefined | null, step: string): string {
32
+ return `${pipelineId ?? "?"}::${step}`;
33
+ }
34
+
35
+ export function useIgnoredClusters() {
36
+ const [ignored, setIgnored] = useState<IgnoredMap>(() => read());
37
+
38
+ // Cross-tab sync: if the same browser has the dashboard open in two
39
+ // tabs, ignoring in one should reflect in the other.
40
+ useEffect(() => {
41
+ function onStorage(e: StorageEvent) {
42
+ if (e.key !== STORAGE_KEY) return;
43
+ setIgnored(read());
44
+ }
45
+ window.addEventListener("storage", onStorage);
46
+ return () => window.removeEventListener("storage", onStorage);
47
+ }, []);
48
+
49
+ const ignore = useCallback((key: string) => {
50
+ setIgnored((prev) => {
51
+ const next = { ...prev, [key]: { at: Date.now() } };
52
+ write(next);
53
+ return next;
54
+ });
55
+ }, []);
56
+
57
+ const unignore = useCallback((key: string) => {
58
+ setIgnored((prev) => {
59
+ const next = { ...prev };
60
+ delete next[key];
61
+ write(next);
62
+ return next;
63
+ });
64
+ }, []);
65
+
66
+ return { ignored, ignore, unignore };
67
+ }
@@ -0,0 +1,6 @@
1
+ import { clsx, type ClassValue } from "clsx";
2
+ import { twMerge } from "tailwind-merge";
3
+
4
+ export function cn(...inputs: ClassValue[]) {
5
+ return twMerge(clsx(inputs));
6
+ }
@@ -0,0 +1,10 @@
1
+ import React from "react";
2
+ import ReactDOM from "react-dom/client";
3
+ import App from "./App";
4
+ import "./index.css";
5
+
6
+ ReactDOM.createRoot(document.getElementById("root")!).render(
7
+ <React.StrictMode>
8
+ <App />
9
+ </React.StrictMode>
10
+ );
@@ -0,0 +1,4 @@
1
+ /// <reference types="vite/client" />
2
+ // cytoscape-dagre ships a UMD bundle but no types. We don't need a typed
3
+ // export — cytoscape.use() accepts a plug-in function and that's all we call.
4
+ declare module "cytoscape-dagre";
@@ -0,0 +1,478 @@
1
+ import { useEffect, useMemo, useState } from "react";
2
+ import { Card, CardHeader, CardTitle } from "@/components/ui/card";
3
+ import { Button } from "@/components/ui/button";
4
+ import { Table, THead, TBody, TR, TH, TD } from "@/components/ui/table";
5
+ import { StatusBadge } from "@/components/StatusBadge";
6
+ import { StatStrip } from "@/components/StatStrip";
7
+ import { Sparkline } from "@/components/Sparkline";
8
+ import { Histogram } from "@/components/Histogram";
9
+ import { PipelineCostBreakdown } from "@/components/PipelineCostBreakdown";
10
+ import { DailyCostTrend } from "@/components/DailyCostTrend";
11
+ import { DailyTimeTrend } from "@/components/DailyTimeTrend";
12
+ import { Skeleton } from "@/components/ui/skeleton";
13
+ import { TodayStrip, estimateLast24hSpent, DAY_MS as TODAY_DAY_MS } from "@/components/TodayStrip";
14
+ import { formatDuration } from "@/lib/format";
15
+ import { SubflowSummary } from "@/components/SubflowSummary";
16
+ import { NeedsAttention } from "@/components/NeedsAttention";
17
+ import { ClickToCopy } from "@/components/ClickToCopy";
18
+ import { api } from "@/api/client";
19
+ import { useWs } from "@/api/ws";
20
+ import { formatTime } from "@/lib/format";
21
+ import { cn } from "@/lib/utils";
22
+ import type { AllPipelinesCost, FlowRunSummary, GlobalStats, Pipeline } from "@/api/types";
23
+
24
+ // "waiting" is never actually written anywhere (confirmed repo-wide) — gate
25
+ // pauses are always persisted as "blocked" — so it's not offered as a filter.
26
+ const STATUS_FILTERS = ["", "running", "blocked", "succeeded", "failed", "cancelled"] as const;
27
+ const RANGES = { all: null, "1h": 3_600_000, "24h": 86_400_000, "7d": 604_800_000, "30d": 2_592_000_000 } as const;
28
+ type RangeKey = keyof typeof RANGES;
29
+
30
+ // Filter state lives in the URL hash query so a filtered view is shareable
31
+ // and survives a refresh. The route prefix is `#/` (Home); anything after
32
+ // `?` is parsed as query params.
33
+ function readHashFilters() {
34
+ const hash = window.location.hash || "#/";
35
+ const qIdx = hash.indexOf("?");
36
+ const qs = qIdx >= 0 ? hash.slice(qIdx + 1) : "";
37
+ const params = new URLSearchParams(qs);
38
+ const range = (params.get("range") ?? "all") as RangeKey;
39
+ return {
40
+ status: params.get("status") ?? "",
41
+ pipeline: params.get("pipeline") ?? "",
42
+ range: (range in RANGES) ? range : "all" as RangeKey,
43
+ query: params.get("q") ?? "",
44
+ };
45
+ }
46
+
47
+ function writeHashFilters(f: { status: string; pipeline: string; range: RangeKey; query: string }) {
48
+ const params = new URLSearchParams();
49
+ if (f.status) params.set("status", f.status);
50
+ if (f.pipeline) params.set("pipeline", f.pipeline);
51
+ if (f.range !== "all") params.set("range", f.range);
52
+ if (f.query) params.set("q", f.query);
53
+ const qs = params.toString();
54
+ const next = qs ? `#/?${qs}` : "#/";
55
+ if (next !== window.location.hash) window.history.replaceState(null, "", next);
56
+ }
57
+
58
+ export function Home() {
59
+ const [stats, setStats] = useState<GlobalStats | null>(null);
60
+ // Nullable until first fetch lands — lets the skeleton distinguish
61
+ // "still loading" from "loaded, empty" (which renders the existing
62
+ // empty-state copy instead of a placeholder).
63
+ const [pipelines, setPipelines] = useState<Pipeline[] | null>(null);
64
+ const [pipelinesCost, setPipelinesCost] = useState<AllPipelinesCost | null>(null);
65
+ const [runs, setRuns] = useState<FlowRunSummary[] | null>(null);
66
+ // Unfiltered recent window feeds NeedsAttention so the strip reflects
67
+ // system-level signals (stuck / failed) regardless of the table filters.
68
+ const [allRecent, setAllRecent] = useState<FlowRunSummary[] | null>(null);
69
+ // Day pinned on the runs/day Sparkline → filters the runs table to
70
+ // that UTC calendar day. Drop-in extension of the existing filter
71
+ // chain; range/status/pipeline/query all still apply on top.
72
+ const [pinnedDay, setPinnedDay] = useState<string | null>(null);
73
+ const initial = readHashFilters();
74
+ const [status, setStatus] = useState<string>(initial.status);
75
+ const [pipeline, setPipeline] = useState<string>(initial.pipeline);
76
+ const [range, setRange] = useState<RangeKey>(initial.range);
77
+ const [query, setQuery] = useState<string>(initial.query);
78
+
79
+ const loadStats = () => { api.stats().then(setStats); };
80
+ const loadPipelines = () => { api.pipelines().then(setPipelines); };
81
+ // When a day is pinned, scope the fetch to that UTC day so older
82
+ // days (outside the default top-200-by-updatedAt window) populate.
83
+ // Without this, pinning a 7-day-old day on the chart shows N>0 on
84
+ // the bar but an empty table — the runs simply weren't fetched.
85
+ const loadRuns = () => {
86
+ const params: { status?: string; pipelineId?: string; limit?: number; since?: number; until?: number } = {
87
+ status, pipelineId: pipeline || undefined, limit: 200,
88
+ };
89
+ if (pinnedDay) {
90
+ const lo = Date.UTC(
91
+ Number(pinnedDay.slice(0, 4)),
92
+ Number(pinnedDay.slice(5, 7)) - 1,
93
+ Number(pinnedDay.slice(8, 10)),
94
+ );
95
+ params.since = lo;
96
+ params.until = lo + 86_400_000;
97
+ params.limit = 1000;
98
+ }
99
+ api.runs(params).then(setRuns);
100
+ };
101
+ const loadRecent = () => { api.runs({ limit: 200 }).then(setAllRecent); };
102
+ // Cost roll-up walks session JSONLs per run — slow at scale, so we
103
+ // refresh only on mount + on pipeline.catalog.updated (rare). Visiting the
104
+ // detail page hydrates the same data fresh.
105
+ const loadPipelinesCost = () => { api.allPipelinesCost(30).then(setPipelinesCost).catch(() => setPipelinesCost(null)); };
106
+
107
+ useEffect(() => { loadStats(); loadPipelines(); loadRecent(); loadPipelinesCost(); }, []);
108
+ useEffect(() => {
109
+ writeHashFilters({ status, pipeline, range, query });
110
+ loadRuns();
111
+ /* eslint-disable-line react-hooks/exhaustive-deps */
112
+ }, [status, pipeline, range, query, pinnedDay]);
113
+
114
+ useWs((evt) => {
115
+ if (evt.kind === "run.created" || evt.kind === "run.updated" || evt.kind === "run.ended") {
116
+ loadRuns();
117
+ loadRecent();
118
+ loadStats();
119
+ } else if (evt.kind === "pipeline.catalog.updated") {
120
+ loadPipelines();
121
+ loadPipelinesCost();
122
+ }
123
+ });
124
+
125
+ // Date range + free-text are applied client-side over the already-fetched
126
+ // 200-row window (status + pipeline are pushed to the server). With 200
127
+ // rows, client-side filtering stays well under a frame.
128
+ const visibleRuns = useMemo(() => {
129
+ const cutoff = RANGES[range];
130
+ const sinceMs = cutoff != null ? Date.now() - cutoff : null;
131
+ const needle = query.trim().toLowerCase();
132
+ // pinned-day filter is a UTC calendar bucket (matches the
133
+ // Sparkline's day keys which are UTC YYYY-MM-DD).
134
+ const dayLo = pinnedDay ? Date.UTC(
135
+ Number(pinnedDay.slice(0, 4)),
136
+ Number(pinnedDay.slice(5, 7)) - 1,
137
+ Number(pinnedDay.slice(8, 10)),
138
+ ) : null;
139
+ const dayHi = dayLo != null ? dayLo + 86_400_000 : null;
140
+ return (runs ?? []).filter((r) => {
141
+ if (sinceMs != null && (r.updatedAt ?? 0) < sinceMs) return false;
142
+ if (dayLo != null && dayHi != null) {
143
+ const t = r.createdAt ?? 0;
144
+ if (t < dayLo || t >= dayHi) return false;
145
+ }
146
+ if (needle) {
147
+ const hay = [r.pipelineId, r.currentStep, r.flowId, r.statusReason, r.waitKind]
148
+ .filter(Boolean).join(" ").toLowerCase();
149
+ if (!hay.includes(needle)) return false;
150
+ }
151
+ return true;
152
+ });
153
+ }, [runs, range, query, pinnedDay]);
154
+
155
+ const filtersActive = !!(status || pipeline || range !== "all" || query || pinnedDay);
156
+ const clearAll = () => { setStatus(""); setPipeline(""); setRange("all"); setQuery(""); setPinnedDay(null); };
157
+
158
+ return (
159
+ <>
160
+ <NeedsAttention runs={allRecent ?? []} />
161
+
162
+ {(() => {
163
+ const loading = allRecent === null || stats === null || pipelinesCost === null;
164
+ if (loading) return <TodayStrip loading runs={{ total: 0, ok: 0, failed: 0, active: 0 }} newFailures={0} spent={{ value: 0 }} />;
165
+ const since = Date.now() - TODAY_DAY_MS;
166
+ const rs = allRecent!.filter((r) => (r.updatedAt ?? 0) >= since);
167
+ return (
168
+ <TodayStrip
169
+ runs={{
170
+ total: rs.length,
171
+ ok: rs.filter((r) => r.status === "succeeded").length,
172
+ failed: rs.filter((r) => r.status === "failed").length,
173
+ active: rs.filter((r) => r.status === "running" || r.status === "blocked").length,
174
+ }}
175
+ newFailures={(stats!.failureStops ?? []).filter((c) => (c.lastFailedAt ?? 0) >= since).length}
176
+ spent={estimateLast24hSpent(pipelinesCost!.total.perDay)}
177
+ />
178
+ );
179
+ })()}
180
+
181
+ <h2 className="text-[15px] font-semibold uppercase tracking-[0.5px] text-fg-dim mt-6 mb-2.5">overview</h2>
182
+ {stats
183
+ ? <StatStrip stats={stats} />
184
+ : (
185
+ <div className="grid gap-3 mb-4 grid-cols-[repeat(auto-fit,minmax(150px,1fr))]">
186
+ {[0, 1, 2, 3].map((i) => (
187
+ <div key={i} className="bg-bg-elev border border-border rounded-md px-[14px] py-3">
188
+ <Skeleton className="h-3 w-16 mb-2" />
189
+ <Skeleton className="h-7 w-20" />
190
+ <Skeleton className="h-2 w-24 mt-2" />
191
+ </div>
192
+ ))}
193
+ </div>
194
+ )}
195
+
196
+ {/* Portfolio-wide cost section — mirrors PipelineDetail's cost
197
+ card layout (tiles + by-X breakdown + daily charts), but at
198
+ the cross-pipeline level.
199
+
200
+ The cost API walks every session JSONL on disk, so it lands
201
+ seconds after the other endpoints. Render a skeleton in the
202
+ meantime so the home doesn't reflow when data arrives. */}
203
+ {pipelinesCost === null && (
204
+ <Card>
205
+ <CardHeader><CardTitle>cost (last 30d)</CardTitle></CardHeader>
206
+ <div className="grid grid-cols-2 sm:grid-cols-3 gap-3">
207
+ {[0, 1, 2].map((i) => (
208
+ <div key={i} className="border border-border rounded p-2">
209
+ <Skeleton className="h-3 w-20 mb-1.5" />
210
+ <Skeleton className="h-6 w-24" />
211
+ <Skeleton className="h-2 w-32 mt-2" />
212
+ </div>
213
+ ))}
214
+ </div>
215
+ <div className="grid grid-cols-1 md:grid-cols-2 gap-3 mt-4">
216
+ <div className="border border-border rounded p-2">
217
+ <Skeleton className="h-3 w-28 mb-2" />
218
+ {[0, 1, 2, 3].map((i) => (
219
+ <div key={i} className="flex items-center gap-2 mb-1.5">
220
+ <Skeleton className="h-3 w-32" />
221
+ <Skeleton className="h-2 flex-1" />
222
+ <Skeleton className="h-3 w-12" />
223
+ </div>
224
+ ))}
225
+ </div>
226
+ <div className="flex flex-col gap-3">
227
+ {[0, 1].map((i) => (
228
+ <div key={i} className="border border-border rounded p-2 flex-1">
229
+ <Skeleton className="h-3 w-20 mb-2" />
230
+ <Skeleton className="h-3 w-full mb-1" />
231
+ <div className="flex gap-[2px] h-12">
232
+ {[0, 1, 2, 3, 4, 5].map((j) => (
233
+ <Skeleton key={j} className="flex-1 rounded-[1px]" />
234
+ ))}
235
+ </div>
236
+ </div>
237
+ ))}
238
+ </div>
239
+ </div>
240
+ </Card>
241
+ )}
242
+ {pipelinesCost && pipelinesCost.total.spend > 0 && (
243
+ <Card>
244
+ <CardHeader><CardTitle>cost (last 30d)</CardTitle></CardHeader>
245
+ <div className="grid grid-cols-2 sm:grid-cols-3 gap-3 text-sm">
246
+ <HomeCostTile
247
+ label="total spend"
248
+ value={`$${pipelinesCost.total.spend.toFixed(2)}`}
249
+ sub={`${pipelinesCost.total.runs} run${pipelinesCost.total.runs === 1 ? "" : "s"} across ${pipelinesCost.pipelines.length} pipeline${pipelinesCost.pipelines.length === 1 ? "" : "s"}`}
250
+ />
251
+ <HomeCostTile
252
+ label="mean / run"
253
+ value={pipelinesCost.total.mean != null ? `$${pipelinesCost.total.mean.toFixed(2)}` : "—"}
254
+ sub={pipelinesCost.total.p95Cost != null ? `p95 $${pipelinesCost.total.p95Cost.toFixed(2)}` : undefined}
255
+ />
256
+ <HomeCostTile
257
+ label="cost / success"
258
+ value={pipelinesCost.total.costPerSuccess != null ? `$${pipelinesCost.total.costPerSuccess.toFixed(2)}` : "—"}
259
+ sub={pipelinesCost.total.succeeded > 0 ? `${pipelinesCost.total.succeeded} succeeded` : "no successes yet"}
260
+ />
261
+ </div>
262
+ <div className="grid grid-cols-1 md:grid-cols-2 gap-3 mt-4">
263
+ <PipelineCostBreakdown entries={pipelinesCost.pipelines} pipelines={pipelines ?? []} />
264
+ <div className="flex flex-col gap-3">
265
+ <DailyCostTrend perDay={pipelinesCost.total.perDay} />
266
+ <DailyTimeTrend perDay={pipelinesCost.total.perDay} />
267
+ </div>
268
+ </div>
269
+ </Card>
270
+ )}
271
+
272
+ <div className="flex flex-col md:flex-row gap-3 md:gap-5">
273
+ <div className="flex-1 min-w-0">
274
+ <Card className="mb-0">
275
+ <CardHeader><CardTitle>runs / day (last 30d)</CardTitle></CardHeader>
276
+ {stats
277
+ ? <Sparkline buckets={stats.perDay} pinned={pinnedDay} onPinChange={setPinnedDay} />
278
+ : (
279
+ <>
280
+ <Skeleton className="h-3 w-20 self-end mb-1 ml-auto" />
281
+ <div className="flex gap-[2px] h-9 mt-1.5">
282
+ {Array.from({ length: 14 }, (_, i) => (
283
+ <Skeleton key={i} className="flex-1 min-w-[4px] rounded-[1px]" />
284
+ ))}
285
+ </div>
286
+ <div className="flex justify-between mt-1.5">
287
+ <Skeleton className="h-2.5 w-16" />
288
+ <Skeleton className="h-2.5 w-12" />
289
+ <Skeleton className="h-2.5 w-16" />
290
+ </div>
291
+ </>
292
+ )}
293
+ </Card>
294
+ </div>
295
+ <div className="flex-1 min-w-0">
296
+ <Card className="mb-0">
297
+ <CardHeader><CardTitle>top failure / cancel steps</CardTitle></CardHeader>
298
+ {stats
299
+ ? <Histogram entries={stats.failureStops} showPipeline />
300
+ : (
301
+ <div className="space-y-2">
302
+ {[0, 1].map((g) => (
303
+ <div key={g} className="border border-border rounded">
304
+ <div className="px-2 py-1 border-b border-border/60">
305
+ <Skeleton className="h-3 w-40" />
306
+ </div>
307
+ <div className="px-2 py-1.5 space-y-1.5">
308
+ {[0, 1].map((r) => (
309
+ <div key={r} className="flex items-center gap-2">
310
+ <Skeleton className="h-3 w-32" />
311
+ <Skeleton className="h-3 flex-1" />
312
+ <Skeleton className="h-3 w-10" />
313
+ </div>
314
+ ))}
315
+ </div>
316
+ </div>
317
+ ))}
318
+ </div>
319
+ )}
320
+ </Card>
321
+ </div>
322
+ </div>
323
+
324
+ {/* Pipelines sidebar dropped — the cost-by-pipeline breakdown
325
+ card above is a strict superset (name + cost + tone + tap-
326
+ to-expand detail). Historical pipelines (in DB but no source
327
+ on disk) surface there too with a dim row + badge. */}
328
+ <div>
329
+ <div>
330
+ <div className="flex items-baseline justify-between mb-2.5 gap-3 flex-wrap">
331
+ <h2 className="text-[15px] font-semibold uppercase tracking-[0.5px] text-fg-dim">runs</h2>
332
+ <span className="font-mono text-xs text-fg-dim">
333
+ {runs === null
334
+ ? "…"
335
+ : visibleRuns.length === runs.length ? `${runs.length}` : `${visibleRuns.length} / ${runs.length}`}
336
+ {filtersActive && (
337
+ <button onClick={clearAll} className="ml-2 underline hover:text-fg">clear filters</button>
338
+ )}
339
+ </span>
340
+ </div>
341
+
342
+ {/* Row 1: pipeline + range + search */}
343
+ <div className="flex gap-2 mb-2 flex-wrap">
344
+ <select
345
+ value={pipeline}
346
+ onChange={(e) => setPipeline(e.target.value)}
347
+ className="bg-bg-elev border border-border rounded px-2 py-1 text-sm font-mono text-fg min-w-0"
348
+ >
349
+ <option value="">all pipelines</option>
350
+ {(pipelines ?? []).map((p) => (
351
+ <option key={p.id} value={p.id}>{p.id}{p.historical ? " (historical)" : ""}</option>
352
+ ))}
353
+ </select>
354
+ <select
355
+ value={range}
356
+ onChange={(e) => setRange(e.target.value as RangeKey)}
357
+ className="bg-bg-elev border border-border rounded px-2 py-1 text-sm font-mono text-fg"
358
+ >
359
+ {(Object.keys(RANGES) as RangeKey[]).map((r) => (
360
+ <option key={r} value={r}>{r === "all" ? "all time" : `last ${r}`}</option>
361
+ ))}
362
+ </select>
363
+ <input
364
+ type="search"
365
+ value={query}
366
+ onChange={(e) => setQuery(e.target.value)}
367
+ placeholder="search step / pipeline / flowId…"
368
+ className="bg-bg-elev border border-border rounded px-2 py-1 text-sm text-fg flex-1 min-w-[160px]"
369
+ />
370
+ </div>
371
+
372
+ {/* Row 2: status chips */}
373
+ <div className="flex gap-2 flex-wrap mb-3 items-center">
374
+ {STATUS_FILTERS.map((s) => (
375
+ <Button
376
+ key={s || "all"}
377
+ variant="chip"
378
+ onClick={() => setStatus(s)}
379
+ className={cn(status === s && "bg-bg-elev2 text-fg border-fg-dim")}
380
+ >
381
+ {s || "all"}
382
+ </Button>
383
+ ))}
384
+ </div>
385
+ <Card>
386
+ {runs === null
387
+ ? (
388
+ <div className="space-y-2">
389
+ {[0, 1, 2, 3, 4, 5].map((i) => (
390
+ <div key={i} className="flex items-center gap-3 py-1">
391
+ <Skeleton className="h-3 w-16" />
392
+ <Skeleton className="h-3 w-40" />
393
+ <Skeleton className="h-4 w-16" />
394
+ <Skeleton className="h-3 w-24" />
395
+ <Skeleton className="h-3 w-12 ml-auto" />
396
+ </div>
397
+ ))}
398
+ </div>
399
+ )
400
+ : visibleRuns.length === 0
401
+ ? <div className="text-fg-dim italic">
402
+ no runs{filtersActive && " matching the current filters"}
403
+ </div>
404
+ : (
405
+ <>
406
+ {/*
407
+ Mobile-first card list (<sm). Drops wait + subflows
408
+ columns — too low-signal for the vertical space they
409
+ eat at 390px. Status pill leads each card so the
410
+ operator can scan failures/blocks at a glance.
411
+ */}
412
+ <div className="sm:hidden flex flex-col gap-2">
413
+ {visibleRuns.map((r) => (
414
+ <a
415
+ key={r.flowId}
416
+ href={`#/runs/${r.flowId}`}
417
+ className="block rounded border border-border bg-bg-elev2/30 hover:bg-bg-elev2 px-3 py-2"
418
+ >
419
+ <div className="flex items-center gap-2">
420
+ <StatusBadge status={r.status} />
421
+ <span className="font-mono text-sm truncate flex-1">{r.pipelineId ?? "?"}</span>
422
+ <span className="text-[10px] text-fg-dim shrink-0">{formatTime(r.updatedAt)}</span>
423
+ </div>
424
+ <div className="flex items-baseline gap-2 mt-0.5 text-xs text-fg-dim font-mono">
425
+ <span>{r.flowId.slice(0, 8)}</span>
426
+ {r.currentStep && <span>· {r.currentStep}</span>}
427
+ </div>
428
+ </a>
429
+ ))}
430
+ </div>
431
+ {/* Desktop / tablet table — unchanged. */}
432
+ <div className="hidden sm:block">
433
+ <Table>
434
+ <THead>
435
+ <TR>
436
+ <TH>flow</TH><TH>pipeline</TH><TH>status</TH><TH>step</TH><TH>wait</TH><TH>subflows</TH><TH>updated</TH>
437
+ </TR>
438
+ </THead>
439
+ <TBody>
440
+ {visibleRuns.map((r) => (
441
+ <TR key={r.flowId} className="cursor-pointer hover:bg-bg-elev2" onClick={() => { window.location.hash = `#/runs/${r.flowId}`; }}>
442
+ <TD className="font-mono text-xs">
443
+ <ClickToCopy value={r.flowId} label="copy flowId">{r.flowId.slice(0, 8)}</ClickToCopy>
444
+ </TD>
445
+ <TD className="font-mono">{r.pipelineId ?? "?"}</TD>
446
+ <TD><StatusBadge status={r.status} /></TD>
447
+ <TD className="font-mono text-fg-dim">{r.currentStep ?? "?"}</TD>
448
+ <TD className="font-mono text-fg-dim">{r.waitKind ?? ""}</TD>
449
+ <TD><SubflowSummary groups={r.subflows} /></TD>
450
+ <TD className="text-fg-dim">{formatTime(r.updatedAt)}</TD>
451
+ </TR>
452
+ ))}
453
+ </TBody>
454
+ </Table>
455
+ </div>
456
+ </>
457
+ )
458
+ }
459
+ </Card>
460
+ </div>
461
+ </div>
462
+ </>
463
+ );
464
+ }
465
+
466
+ // Cost tile for the overview's cost (last 30d) section. Same shape as
467
+ // PipelineDetail's CostTile but local to Home so the import surface
468
+ // stays small. Sub line accepts ReactNode so callers can colorize.
469
+ function HomeCostTile({ label, value, sub }: { label: string; value: string; sub?: React.ReactNode }) {
470
+ return (
471
+ <div className="border border-border rounded p-2">
472
+ <div className="text-xs text-fg-dim">{label}</div>
473
+ <div className="font-mono text-lg">{value}</div>
474
+ {sub && <div className="text-xs text-fg-dim mt-0.5">{sub}</div>}
475
+ </div>
476
+ );
477
+ }
478
+