@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,277 @@
1
+ // Overview-level cost breakdown: one row per pipeline, mirroring
2
+ // PipelineDetail's NodeCostBreakdown structure (single grid +
3
+ // display:contents + tap-to-expand). Answers "which pipeline is
4
+ // eating my budget" at the home view, the same way NodeCostBreakdown
5
+ // answers "which step is eating my pipeline's budget."
6
+ //
7
+ // Mode toggle: $ (total spend) / time (typical-run latency p50).
8
+ // Expansion: per-pipeline details + trend sparkline reusing the
9
+ // daily-cost lens with a total / p50 sub-toggle in $ mode (same UX
10
+ // as the per-node row expansions).
11
+
12
+ import { Fragment, useEffect, useRef, useState } from "react";
13
+ import type { AllPipelinesCostEntry, Pipeline } from "@/api/types";
14
+ import { formatDuration } from "@/lib/format";
15
+ import { cn } from "@/lib/utils";
16
+ import { useClickOutside } from "@/lib/use-click-outside";
17
+ import { computeAnomalies } from "@/lib/anomaly";
18
+
19
+ const HISTORICAL_PREF_KEY = "gf:cost-by-pipeline:show-historical";
20
+
21
+ export function PipelineCostBreakdown({
22
+ entries,
23
+ pipelines,
24
+ }: {
25
+ entries: AllPipelinesCostEntry[];
26
+ /** Pipeline defs from /api/pipelines — used to mark historical pipelines and look up display metadata. */
27
+ pipelines: Pipeline[];
28
+ }) {
29
+ const [mode, setMode] = useState<"cost" | "time">("cost");
30
+ const [expanded, setExpanded] = useState<string | null>(null);
31
+ // Historical pipelines (source file removed but runs still in the
32
+ // DB) are noise in the everyday view — they hold a row but never
33
+ // contribute current-window spend. Default to hidden; persist the
34
+ // operator's choice so audit sessions don't re-toggle every reload.
35
+ const [showHistorical, setShowHistorical] = useState<boolean>(() => {
36
+ if (typeof localStorage === "undefined") return false;
37
+ return localStorage.getItem(HISTORICAL_PREF_KEY) === "1";
38
+ });
39
+ useEffect(() => {
40
+ if (typeof localStorage === "undefined") return;
41
+ localStorage.setItem(HISTORICAL_PREF_KEY, showHistorical ? "1" : "0");
42
+ }, [showHistorical]);
43
+
44
+ const pipelineById = new Map(pipelines.map((p) => [p.id, p]));
45
+ const everything = entries.filter((e) => {
46
+ if (pipelineById.get(e.pipelineId)?.historical) return true;
47
+ return e.total > 0 || (e.p50Ms ?? 0) > 0;
48
+ });
49
+ const historicalCount = everything.filter((e) => pipelineById.get(e.pipelineId)?.historical).length;
50
+ const visible = showHistorical
51
+ ? everything
52
+ : everything.filter((e) => !pipelineById.get(e.pipelineId)?.historical);
53
+ if (visible.length === 0 && historicalCount === 0) {
54
+ return <div className="italic text-fg-dim py-2 text-xs">no pipelines in window</div>;
55
+ }
56
+
57
+ // $-mode = total spend, time-mode = typical-run p50 latency. No
58
+ // total/p50 sub-toggle: typical-call cost lives in the per-pipeline
59
+ // detail page; here the operator wants the cleaner spend ranking.
60
+ const totalSpend = visible.reduce((s, e) => s + e.total, 0);
61
+ const max = mode === "cost"
62
+ ? Math.max(...visible.map((e) => e.total))
63
+ : Math.max(...visible.map((e) => e.p50Ms ?? 0));
64
+ const totalTime = visible.reduce((s, e) => s + (e.p50Ms ?? 0) * e.runs, 0);
65
+
66
+ return (
67
+ <div>
68
+ <div className="flex items-center gap-2 mb-2">
69
+ <div className="text-xs text-fg-dim">by pipeline — {mode === "cost" ? "spend" : "typical-run latency"}</div>
70
+ <div className="ml-auto inline-flex items-center gap-2">
71
+ {historicalCount > 0 && (
72
+ <button
73
+ type="button"
74
+ onClick={() => setShowHistorical((v) => !v)}
75
+ className="text-[10px] font-mono text-fg-dim hover:text-fg underline-offset-2 hover:underline"
76
+ title={showHistorical
77
+ ? `hide historical pipelines (source removed but runs in DB) — ${historicalCount} hidden`
78
+ : `show ${historicalCount} historical pipeline${historicalCount === 1 ? "" : "s"} — source file removed, kept for run-history context`
79
+ }
80
+ >
81
+ {showHistorical ? `hide historical (${historicalCount})` : `+${historicalCount} historical`}
82
+ </button>
83
+ )}
84
+ <div className="inline-flex rounded border border-border overflow-hidden text-[10px] font-mono">
85
+ <button
86
+ onClick={() => setMode("cost")}
87
+ className={cn("px-2 py-0.5", mode === "cost" ? "bg-status-blue/20 text-fg" : "text-fg-dim hover:text-fg")}
88
+ >$</button>
89
+ <button
90
+ onClick={() => setMode("time")}
91
+ className={cn("px-2 py-0.5 border-l border-border", mode === "time" ? "bg-status-blue/20 text-fg" : "text-fg-dim hover:text-fg")}
92
+ >time</button>
93
+ </div>
94
+ </div>
95
+ </div>
96
+ {/*
97
+ Same display:contents grid pattern as NodeCostBreakdown. 4
98
+ columns: name | bar | primary | share. Expansion uses col-span-4.
99
+ */}
100
+ <div className="grid grid-cols-[auto_1fr_auto_auto] items-center gap-x-2 gap-y-1">
101
+ {visible.map((e) => {
102
+ const isOpen = expanded === e.pipelineId;
103
+ const p50 = formatDuration(e.p50Ms);
104
+ const p95 = formatDuration(e.p95Ms);
105
+ const barValue = mode === "cost" ? e.total : (e.p50Ms ?? 0);
106
+ const barPct = max > 0 ? Math.round((barValue / max) * 100) : 0;
107
+ const share = mode === "cost"
108
+ ? (totalSpend > 0 ? (e.total / totalSpend) * 100 : 0)
109
+ : (totalTime > 0 ? ((e.p50Ms ?? 0) * e.runs / totalTime) * 100 : 0);
110
+ const primaryCompact = mode === "cost" ? `$${e.total.toFixed(2)}` : p50;
111
+ const isHistorical = pipelineById.get(e.pipelineId)?.historical === true;
112
+ return (
113
+ <Fragment key={e.pipelineId}>
114
+ <button
115
+ type="button"
116
+ onClick={() => setExpanded(isOpen ? null : e.pipelineId)}
117
+ aria-expanded={isOpen}
118
+ className="contents text-left group"
119
+ title={`${e.pipelineId} · ${e.runs} run${e.runs === 1 ? "" : "s"} · $${e.total.toFixed(4)} · p50 ${p50} · p95 ${p95}`}
120
+ >
121
+ <span className={cn("flex items-center gap-1.5 min-w-0 text-xs group-hover:bg-bg-elev2/40 rounded-l-[2px] pl-0.5", isHistorical && "opacity-65 italic")}>
122
+ <a
123
+ href={`#/pipelines/${encodeURIComponent(e.pipelineId)}`}
124
+ onClick={(ev) => ev.stopPropagation()}
125
+ className="font-mono truncate hover:underline underline-offset-2"
126
+ >
127
+ {e.pipelineId}
128
+ </a>
129
+ <span className="text-[10px] text-fg-dim shrink-0">{isOpen ? "▾" : "▸"}</span>
130
+ {isHistorical && (
131
+ <span
132
+ className="bg-bg-elev2 text-fg-dim border border-border rounded-[10px] px-1.5 py-px font-mono text-[9px] shrink-0"
133
+ title="pipeline source no longer on disk — kept for historical run context"
134
+ >
135
+ historical
136
+ </span>
137
+ )}
138
+ </span>
139
+ <span className="relative h-2 w-full bg-bg-elev2 rounded-[1px]">
140
+ <span className="absolute left-0 top-0 bottom-0 bg-status-blue rounded-[1px]" style={{ width: `${barPct}%` }} />
141
+ </span>
142
+ <span className="font-mono text-fg-dim tabular-nums text-right whitespace-nowrap text-xs group-hover:bg-bg-elev2/40">
143
+ {primaryCompact}
144
+ </span>
145
+ <span className="font-mono text-fg-dim tabular-nums text-right whitespace-nowrap text-[10px] group-hover:bg-bg-elev2/40 rounded-r-[2px] pr-0.5">
146
+ ({share.toFixed(0)}%)
147
+ </span>
148
+ </button>
149
+ {isOpen && (
150
+ <div className="col-span-4 pl-5 pr-1 pt-0.5 pb-1 text-[10px] font-mono text-fg-dim grid grid-cols-2 sm:grid-cols-4 gap-x-3 gap-y-0.5">
151
+ <span><span className="text-fg-dim">runs:</span> {e.runs}</span>
152
+ <span><span className="text-fg-dim">succeeded:</span> {e.succeeded}</span>
153
+ <span>
154
+ <span className="text-fg-dim">$ / ok:</span>{" "}
155
+ {e.costPerSuccess != null ? `$${e.costPerSuccess.toFixed(2)}` : "—"}
156
+ </span>
157
+ <span><span className="text-fg-dim">$ total:</span> ${e.total.toFixed(4)}</span>
158
+ <span><span className="text-fg-dim">p50 time:</span> {p50}</span>
159
+ <span><span className="text-fg-dim">p95 time:</span> {p95}</span>
160
+ <span><span className="text-fg-dim">p50 $/run:</span> {e.p50Cost != null ? `$${e.p50Cost.toFixed(4)}` : "—"}</span>
161
+ <span><span className="text-fg-dim">p95 $/run:</span> {e.p95Cost != null ? `$${e.p95Cost.toFixed(4)}` : "—"}</span>
162
+ {/* Trend sparkline — $-mode is total daily spend,
163
+ time-mode is daily p50 latency. No total/p50
164
+ sub-toggle at this surface. */}
165
+ {(mode === "time" || e.total > 0) && (
166
+ <PipelineTrendSparkline perDay={e.perDay} mode={mode} />
167
+ )}
168
+ </div>
169
+ )}
170
+ </Fragment>
171
+ );
172
+ })}
173
+ </div>
174
+ <p className="text-[10px] text-fg-dim mt-1">
175
+ columns: <span className="font-mono">pipeline · bar · {mode === "cost" ? "$ (share of spend)" : "p50 (share of typical wall time)"}</span> — tap a row for full detail.
176
+ </p>
177
+ </div>
178
+ );
179
+ }
180
+
181
+ type DayPoint = { day: string; cost: number; runs: number; ms: number; p50Cost: number | null; p50Ms: number | null };
182
+
183
+ function PipelineTrendSparkline({ perDay, mode }: {
184
+ perDay: DayPoint[];
185
+ mode: "cost" | "time";
186
+ }) {
187
+ // Local total/p50 toggle for $-mode — matches the per-node row
188
+ // expansion's deepest-surface toggle. p50 here = median per-run cost
189
+ // that day, so the operator can see "is the typical run getting more
190
+ // expensive" even when daily totals look flat.
191
+ const [costMetric, setCostMetric] = useState<"total" | "p50">("total");
192
+ // Tap-to-pin day label (no native hover on mobile).
193
+ const [pinned, setPinned] = useState<string | null>(null);
194
+ const rootRef = useRef<HTMLDivElement>(null);
195
+ useClickOutside(rootRef, () => setPinned(null));
196
+ if (!perDay || perDay.length === 0) return <span className="col-span-2 sm:col-span-4 text-fg-dim italic">no per-day samples yet</span>;
197
+ const metric = (d: DayPoint): number | null => {
198
+ if (mode === "time") return d.p50Ms;
199
+ return costMetric === "p50" ? d.p50Cost : d.cost;
200
+ };
201
+ const max = Math.max(0.0001, ...perDay.map((d) => metric(d) ?? 0));
202
+ const pinnedDay = pinned ? perDay.find((d) => d.day === pinned) : null;
203
+ const anomalies = computeAnomalies(perDay, (d) => metric(d) ?? 0);
204
+ const pinnedRatio = pinnedDay ? anomalies.ratios.get(pinnedDay.day) : undefined;
205
+ const fmt = (d: DayPoint) =>
206
+ mode === "cost"
207
+ ? (costMetric === "p50"
208
+ ? `${d.day}: p50 $${(d.p50Cost ?? 0).toFixed(4)} · ${d.runs} run${d.runs === 1 ? "" : "s"}`
209
+ : `${d.day}: total $${d.cost.toFixed(4)} · ${d.runs} run${d.runs === 1 ? "" : "s"}`)
210
+ : `${d.day}: p50 ${formatDuration(d.p50Ms ?? 0)} · ${d.runs} run${d.runs === 1 ? "" : "s"}`;
211
+ const subtitle = mode === "cost"
212
+ ? `daily ${costMetric === "p50" ? "p50 $/run" : "$ total"}`
213
+ : "daily p50 latency";
214
+ return (
215
+ <div ref={rootRef} className="col-span-2 sm:col-span-4 mt-1">
216
+ <div className="flex items-center justify-between mb-1">
217
+ <span className="text-[9px] text-fg-dim font-mono">{subtitle}</span>
218
+ {mode === "cost" && (
219
+ <div
220
+ className="inline-flex rounded border border-border overflow-hidden text-[9px] font-mono"
221
+ onClick={(e) => e.stopPropagation()}
222
+ >
223
+ <button
224
+ type="button"
225
+ onClick={() => setCostMetric("total")}
226
+ className={costMetric === "total" ? "px-1.5 py-px bg-status-blue/20 text-fg" : "px-1.5 py-px text-fg-dim hover:text-fg"}
227
+ >total</button>
228
+ <button
229
+ type="button"
230
+ onClick={() => setCostMetric("p50")}
231
+ className={costMetric === "p50" ? "px-1.5 py-px border-l border-border bg-status-blue/20 text-fg" : "px-1.5 py-px border-l border-border text-fg-dim hover:text-fg"}
232
+ >p50</button>
233
+ </div>
234
+ )}
235
+ </div>
236
+ <div className="text-right text-[9px] text-fg font-mono mb-0.5 min-h-[12px]">
237
+ {pinnedDay && (
238
+ <span>
239
+ {fmt(pinnedDay)}
240
+ {pinnedRatio != null && <span className="text-status-amber"> · {pinnedRatio.toFixed(1)}× mean</span>}
241
+ </span>
242
+ )}
243
+ </div>
244
+ <div className="flex gap-[2px] h-10">
245
+ {perDay.map((d) => {
246
+ const v = metric(d) ?? 0;
247
+ const h = v > 0 ? Math.max(2, Math.round((v / max) * 100)) : 2;
248
+ const isPinned = pinned === d.day;
249
+ const muted = pinned !== null && !isPinned;
250
+ const isAnomaly = anomalies.flagged.has(d.day);
251
+ const ratio = anomalies.ratios.get(d.day);
252
+ const fill = v > 0 ? (isAnomaly ? "bg-status-amber" : "bg-status-blue") : "bg-bg-elev2";
253
+ const tip = isAnomaly && ratio != null ? `${fmt(d)} · ${ratio.toFixed(1)}× mean` : fmt(d);
254
+ return (
255
+ <button
256
+ type="button"
257
+ key={d.day}
258
+ onClick={(ev) => { ev.stopPropagation(); setPinned(isPinned ? null : d.day); }}
259
+ className="flex-1 min-w-[4px] relative h-full"
260
+ title={tip}
261
+ >
262
+ <span
263
+ className={`absolute bottom-0 left-0 right-0 rounded-[1px] ${fill} ${muted ? "opacity-65" : ""}`}
264
+ style={{ height: `${h}%` }}
265
+ />
266
+ </button>
267
+ );
268
+ })}
269
+ </div>
270
+ <div className="flex justify-between mt-1 text-[9px] text-fg-dim font-mono">
271
+ <span>{perDay[0].day}</span>
272
+ <span>{perDay.length}d</span>
273
+ <span>{perDay[perDay.length - 1].day}</span>
274
+ </div>
275
+ </div>
276
+ );
277
+ }
@@ -0,0 +1,46 @@
1
+ // RerunButton — starts a fresh run of the same pipeline with the same
2
+ // args (overridable in a future iteration). Only renders for terminal
3
+ // flows: the singleton-per-pipeline guard rejects starting while the
4
+ // source is still running, and there's no operator value in re-running
5
+ // a flow that's still in flight.
6
+ //
7
+ // On success, navigates to the new run's detail page.
8
+
9
+ import { useState } from "react";
10
+ import { Button } from "@/components/ui/button";
11
+ import { api } from "@/api/client";
12
+ import { cn } from "@/lib/utils";
13
+
14
+ export function RerunButton({ flowId }: { flowId: string }) {
15
+ const [busy, setBusy] = useState(false);
16
+ const [error, setError] = useState<string | null>(null);
17
+
18
+ async function click() {
19
+ setBusy(true);
20
+ setError(null);
21
+ try {
22
+ const result = await api.rerun(flowId);
23
+ window.location.hash = `#/runs/${result.flowId}`;
24
+ } catch (e) {
25
+ setError(e instanceof Error ? e.message : String(e));
26
+ setBusy(false);
27
+ }
28
+ }
29
+
30
+ return (
31
+ <div className="flex items-center gap-2">
32
+ {error && <span className="text-status-red text-xs">{error}</span>}
33
+ <Button
34
+ variant="chip"
35
+ onClick={click}
36
+ disabled={busy}
37
+ className={cn(
38
+ "text-accent border-accent/40 hover:bg-accent/10",
39
+ busy && "opacity-60",
40
+ )}
41
+ >
42
+ {busy ? "starting…" : "re-run"}
43
+ </Button>
44
+ </div>
45
+ );
46
+ }
@@ -0,0 +1,53 @@
1
+ // "This run vs N prior succeeded" card on run-detail.
2
+
3
+ import { Card, CardHeader, CardTitle } from "./ui/card";
4
+ import { formatDuration } from "@/lib/format";
5
+ import { cn } from "@/lib/utils";
6
+ import type { FlowRunFull, RunCompare } from "@/api/types";
7
+
8
+ export function RunComparison({ compare, run }: { compare: RunCompare | null; run: FlowRunFull }) {
9
+ if (!compare || compare.peerCount === 0) return null;
10
+ const dur = formatDuration(compare.durationMs);
11
+ const med = formatDuration(compare.durationMedianMs);
12
+ const ratio = compare.durationRatio;
13
+ let deltaCls = "bg-bg-elev2 text-fg-dim";
14
+ let deltaTxt = "≈";
15
+ if (ratio != null) {
16
+ if (ratio < 0.85) {
17
+ deltaCls = "bg-status-green/15 text-status-green";
18
+ deltaTxt = `${Math.round((1 - ratio) * 100)}% faster`;
19
+ } else if (ratio > 1.15) {
20
+ deltaCls = "bg-status-red/15 text-status-red";
21
+ deltaTxt = `${Math.round((ratio - 1) * 100)}% slower`;
22
+ } else {
23
+ deltaTxt = "near median";
24
+ }
25
+ }
26
+ return (
27
+ <Card>
28
+ <CardHeader>
29
+ <CardTitle>this run vs {compare.peerCount} prior succeeded runs of {run.pipelineId}</CardTitle>
30
+ </CardHeader>
31
+ <div className="grid gap-3 grid-cols-[repeat(auto-fit,minmax(150px,1fr))]">
32
+ <Stat label="duration" value={dur}>
33
+ <div className="text-xs text-fg-dim font-mono">
34
+ median {med} · <span className={cn("inline-block px-2 py-px rounded-[10px] font-mono text-[11px]", deltaCls)}>{deltaTxt}</span>
35
+ </div>
36
+ </Stat>
37
+ <Stat label="revisions" value={String(compare.revision)}>
38
+ <div className="text-xs text-fg-dim font-mono">median {compare.revisionMedian ?? "?"}</div>
39
+ </Stat>
40
+ </div>
41
+ </Card>
42
+ );
43
+ }
44
+
45
+ function Stat({ label, value, children }: { label: string; value: string; children?: React.ReactNode }) {
46
+ return (
47
+ <div className="bg-bg-elev border border-border rounded-md px-[14px] py-3">
48
+ <div className="text-fg-dim text-[11px] uppercase tracking-[0.5px]">{label}</div>
49
+ <div className="font-mono text-2xl font-semibold leading-tight mt-0.5">{value}</div>
50
+ {children}
51
+ </div>
52
+ );
53
+ }
@@ -0,0 +1,94 @@
1
+ import { useMemo, useRef, useState } from "react";
2
+ import type { PerDayBucket } from "@/api/types";
3
+ import { useClickOutside } from "@/lib/use-click-outside";
4
+ import { computeAnomalies } from "@/lib/anomaly";
5
+
6
+ export function Sparkline({
7
+ buckets,
8
+ pinned: controlledPinned,
9
+ onPinChange,
10
+ }: {
11
+ buckets: PerDayBucket[];
12
+ /** When provided, makes the component controlled — Home can react to the pinned day (e.g. filter the runs table). */
13
+ pinned?: string | null;
14
+ onPinChange?: (day: string | null) => void;
15
+ }) {
16
+ // Hybrid: uncontrolled by default (own state), controlled when the
17
+ // parent passes `pinned` + `onPinChange`. Same component works on
18
+ // the home (filters runs table) and anywhere else standalone.
19
+ const [internalPinned, setInternalPinned] = useState<string | null>(null);
20
+ const pinned = controlledPinned !== undefined ? controlledPinned : internalPinned;
21
+ const setPinned = (day: string | null) => {
22
+ if (controlledPinned === undefined) setInternalPinned(day);
23
+ onPinChange?.(day);
24
+ };
25
+ const rootRef = useRef<HTMLDivElement>(null);
26
+ useClickOutside(rootRef, () => setPinned(null));
27
+ const anomalies = useMemo(() => computeAnomalies(buckets ?? [], (d) => d.total), [buckets]);
28
+ if (!buckets?.length) return <div className="italic text-fg-dim py-4">no daily data</div>;
29
+ const max = Math.max(1, ...buckets.map((d) => d.total));
30
+ const pinnedBucket = pinned ? buckets.find((d) => d.day === pinned) : null;
31
+ const pinnedRatio = pinnedBucket ? anomalies.ratios.get(pinnedBucket.day) : undefined;
32
+ return (
33
+ <div ref={rootRef}>
34
+ {/* Outlier chip + pinned label slot mirror DailyCostTrend's
35
+ structure so the three daily charts read as one family.
36
+ The CardHeader above already carries the section title
37
+ ("runs / day"), so we don't repeat it here. */}
38
+ {anomalies.flagged.size > 0 && (
39
+ <div className="text-[9px] text-status-amber font-mono mb-1" title="amber bars (inner success fill) exceed the other days' mean by 1.5×+ — outliers in the window">
40
+ ▲ {anomalies.flagged.size} outlier{anomalies.flagged.size === 1 ? "" : "s"}
41
+ </div>
42
+ )}
43
+ <div className="text-right text-[10px] text-fg font-mono mb-1 min-h-[14px]">
44
+ {pinnedBucket && (
45
+ <span>
46
+ {pinnedBucket.day}: {pinnedBucket.total} runs ({pinnedBucket.succeeded} ok · {pinnedBucket.failed} fail · {pinnedBucket.cancelled} canc)
47
+ {pinnedRatio != null && <span className="text-status-amber"> · {pinnedRatio.toFixed(1)}× mean</span>}
48
+ </span>
49
+ )}
50
+ </div>
51
+ <div className="flex gap-[2px] h-12">
52
+ {buckets.map((d) => {
53
+ const h = Math.round((d.total / max) * 100);
54
+ const okShare = d.total > 0 ? d.succeeded / d.total : 0;
55
+ const isAnomaly = anomalies.flagged.has(d.day);
56
+ const ratio = anomalies.ratios.get(d.day);
57
+ const tip = isAnomaly && ratio != null
58
+ ? `${d.day}: ${d.total} runs (${d.succeeded} ok) · ${ratio.toFixed(1)}× mean`
59
+ : `${d.day}: ${d.total} runs (${d.succeeded} ok)`;
60
+ const isPinned = pinned === d.day;
61
+ const muted = pinned !== null && !isPinned;
62
+ // Anomaly = amber inner fill; the outer slot stays
63
+ // bg-elev2 since it represents total volume regardless of
64
+ // outcome — only the success-rate fill carries the color.
65
+ const innerColor = isAnomaly ? "bg-status-amber" : "bg-status-blue";
66
+ return (
67
+ <button
68
+ type="button"
69
+ key={d.day}
70
+ onClick={() => setPinned(isPinned ? null : d.day)}
71
+ className="flex-1 min-w-[6px] relative h-full"
72
+ title={tip}
73
+ >
74
+ <span
75
+ className={`absolute left-0 right-0 bottom-0 bg-bg-elev2 rounded-[1px] ${muted ? "opacity-65" : ""}`}
76
+ style={{ height: `${h}%` }}
77
+ >
78
+ <span
79
+ className={`absolute left-0 right-0 bottom-0 rounded-[1px] ${innerColor}`}
80
+ style={{ height: `${Math.round(okShare * 100)}%` }}
81
+ />
82
+ </span>
83
+ </button>
84
+ );
85
+ })}
86
+ </div>
87
+ <div className="flex justify-between mt-1.5 text-fg-dim font-mono text-[11px]">
88
+ <span>{buckets[0]?.day}</span>
89
+ <span>{buckets.length} day{buckets.length === 1 ? "" : "s"}</span>
90
+ <span>{buckets[buckets.length - 1]?.day}</span>
91
+ </div>
92
+ </div>
93
+ );
94
+ }
@@ -0,0 +1,147 @@
1
+ // Overview stat strip used on the home view + pipeline-detail. Each stat card
2
+ // is a label + big mono value + sub-line; the runs card adds a stacked bar
3
+ // breaking down by status. Color helper picks green/amber/red for success-rate
4
+ // based on banding from the v0 design.
5
+
6
+ import { formatDuration } from "@/lib/format";
7
+ import { cn } from "@/lib/utils";
8
+ import type { DurationStats, RevisionStats } from "@/api/types";
9
+
10
+ export interface StatStripInput {
11
+ total: number;
12
+ succeeded: number;
13
+ failed: number;
14
+ cancelled: number;
15
+ active?: number;
16
+ terminated: number;
17
+ successRate: number | null;
18
+ duration: DurationStats;
19
+ revision?: RevisionStats;
20
+ }
21
+
22
+ function classForRate(r: number | null): string {
23
+ if (r == null) return "";
24
+ if (r >= 0.7) return "text-status-green";
25
+ if (r >= 0.4) return "text-status-amber";
26
+ return "text-status-red";
27
+ }
28
+
29
+ function widthPct(n: number, total: number): string {
30
+ return total > 0 ? `${(n / total * 100).toFixed(1)}%` : "0%";
31
+ }
32
+
33
+ export function StatStrip({ stats, searchScope }: { stats: StatStripInput; searchScope?: string }) {
34
+ const { total, succeeded, failed, cancelled, active = 0, terminated, successRate, duration } = stats;
35
+ // When the caller passes a `searchScope` (PipelineDetail does — the
36
+ // pipeline id), the runs number + each status sub-count become
37
+ // individual links to the search page. Total → free-text q only;
38
+ // each sub-count → q + structured status filter (exact equality
39
+ // server-side, doesn't false-positive on the substring "failed"
40
+ // showing up in error messages). Home view passes no scope so the
41
+ // tile renders as plain text.
42
+ const hrefFor = (status?: string) => {
43
+ if (!searchScope) return null;
44
+ const qp = new URLSearchParams({ q: searchScope });
45
+ if (status) qp.set("status", status);
46
+ return `#/search?${qp.toString()}`;
47
+ };
48
+ return (
49
+ <div className="grid gap-3 mb-4 grid-cols-[repeat(auto-fit,minmax(150px,1fr))]">
50
+ <StatCard
51
+ label="runs"
52
+ value={String(total)}
53
+ valueHref={hrefFor()}
54
+ valueHrefTitle="see all runs in search"
55
+ >
56
+ <div
57
+ className="flex h-1.5 rounded mt-2 bg-bg-elev2 overflow-hidden"
58
+ title={`${succeeded} succeeded · ${failed} failed · ${cancelled} cancelled · ${active} active`}
59
+ >
60
+ <span className="bg-status-blue" style={{ width: widthPct(succeeded, total) }} />
61
+ <span className="bg-status-red" style={{ width: widthPct(failed, total) }} />
62
+ <span className="bg-status-grey" style={{ width: widthPct(cancelled, total) }} />
63
+ <span className="bg-status-green" style={{ width: widthPct(active, total) }} />
64
+ </div>
65
+ <div className="text-fg-dim text-xs mt-1 font-mono">
66
+ <StatusLink count={succeeded} label="ok" href={hrefFor("succeeded")} />
67
+ {" · "}
68
+ <StatusLink count={failed} label="fail" href={hrefFor("failed")} />
69
+ {" · "}
70
+ <StatusLink count={cancelled} label="canc" href={hrefFor("cancelled")} />
71
+ {active > 0 && <>
72
+ {" · "}
73
+ <StatusLink count={active} label="active" href={hrefFor("running")} />
74
+ </>}
75
+ </div>
76
+ </StatCard>
77
+ <StatCard
78
+ label="success rate"
79
+ value={successRate != null ? `${(successRate * 100).toFixed(1)}%` : "—"}
80
+ valueClassName={classForRate(successRate)}
81
+ sub={`${succeeded} / ${terminated} terminated`}
82
+ />
83
+ <StatCard
84
+ label="median duration"
85
+ value={formatDuration(duration.p50Ms)}
86
+ sub={`p95 ${formatDuration(duration.p95Ms)} · n=${duration.n}`}
87
+ />
88
+ <StatCard
89
+ label="mean duration"
90
+ value={formatDuration(duration.meanMs)}
91
+ sub={`across ${duration.n} succeeded`}
92
+ />
93
+ {stats.revision && (
94
+ <StatCard
95
+ label="median revisions"
96
+ value={stats.revision.p50 != null ? String(stats.revision.p50) : "—"}
97
+ sub={`p95 ${stats.revision.p95 ?? "—"} · n=${stats.revision.n}`}
98
+ />
99
+ )}
100
+ </div>
101
+ );
102
+ }
103
+
104
+ function StatCard({
105
+ label, value, sub, children, valueClassName, valueHref, valueHrefTitle,
106
+ }: {
107
+ label: string;
108
+ value: string;
109
+ sub?: string;
110
+ children?: React.ReactNode;
111
+ valueClassName?: string;
112
+ /** When set, the big value is wrapped in an anchor — used for drill-into-search affordance. Sub-counts handle their own linking. */
113
+ valueHref?: string | null;
114
+ valueHrefTitle?: string;
115
+ }) {
116
+ const valueEl = (
117
+ <span className={cn("font-mono text-2xl font-semibold leading-tight mt-0.5 inline-block", valueClassName)}>{value}</span>
118
+ );
119
+ return (
120
+ <div className="bg-bg-elev border border-border rounded-md px-[14px] py-3">
121
+ <div className="text-fg-dim text-[11px] uppercase tracking-[0.5px]">{label}</div>
122
+ <div>
123
+ {valueHref
124
+ ? <a href={valueHref} title={valueHrefTitle} className="hover:bg-bg-elev2 rounded px-1 -mx-1 transition-colors">{valueEl}</a>
125
+ : valueEl}
126
+ </div>
127
+ {children}
128
+ {sub && <div className="text-fg-dim text-xs font-mono mt-0.5">{sub}</div>}
129
+ </div>
130
+ );
131
+ }
132
+
133
+ // Inline status link in the runs sub-line. Renders as plain text when
134
+ // no href (Home view, no search scope) so the layout stays identical.
135
+ function StatusLink({ count, label, href }: { count: number; label: string; href: string | null }) {
136
+ const body = <><span className="text-fg">{count}</span> {label}</>;
137
+ if (!href) return <span>{body}</span>;
138
+ return (
139
+ <a
140
+ href={href}
141
+ title={`see ${label === "ok" ? "succeeded" : label === "canc" ? "cancelled" : label === "active" ? "running" : label} runs in search`}
142
+ className="hover:bg-bg-elev2 rounded px-0.5 -mx-0.5 transition-colors"
143
+ >
144
+ {body}
145
+ </a>
146
+ );
147
+ }