@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,112 @@
1
+ // Live event subscription for the dashboard. The server pushes events over
2
+ // the /api/events/ws WebSocket; this module wraps it into a React-friendly
3
+ // surface so views can opt in via `useWs(callback)` without each one
4
+ // managing reconnects.
5
+
6
+ import {
7
+ createContext,
8
+ useCallback,
9
+ useContext,
10
+ useEffect,
11
+ useRef,
12
+ useState,
13
+ type ReactNode,
14
+ } from "react";
15
+ import type { LiveEvent } from "./types";
16
+
17
+ type Listener = (event: LiveEvent) => void;
18
+ type ConnState = "connecting" | "live" | "dead";
19
+
20
+ interface WsContextValue {
21
+ state: ConnState;
22
+ subscribe: (cb: Listener) => () => void;
23
+ }
24
+
25
+ const WsContext = createContext<WsContextValue | null>(null);
26
+
27
+ function wsUrl(): string {
28
+ const proto = window.location.protocol === "https:" ? "wss:" : "ws:";
29
+ return `${proto}//${window.location.host}${import.meta.env.BASE_URL}api/events/ws`;
30
+ }
31
+
32
+ export function WsProvider({ children }: { children: ReactNode }) {
33
+ const [state, setState] = useState<ConnState>("connecting");
34
+ const listenersRef = useRef<Set<Listener>>(new Set());
35
+ // Hold the latest socket so manual reconnects don't leak.
36
+ const wsRef = useRef<WebSocket | null>(null);
37
+
38
+ useEffect(() => {
39
+ let cancelled = false;
40
+ let backoff: ReturnType<typeof setTimeout> | null = null;
41
+
42
+ function connect() {
43
+ if (cancelled) return;
44
+ setState("connecting");
45
+ let ws: WebSocket;
46
+ try {
47
+ ws = new WebSocket(wsUrl());
48
+ } catch {
49
+ if (cancelled) return;
50
+ setState("dead");
51
+ backoff = setTimeout(connect, 1500);
52
+ return;
53
+ }
54
+ wsRef.current = ws;
55
+ ws.onopen = () => { if (!cancelled) setState("live"); };
56
+ const reconnect = () => {
57
+ if (cancelled) return;
58
+ setState("dead");
59
+ try { ws.close(); } catch { /* swallow */ }
60
+ // Brief backoff, then reconnect. The connection is local-loopback so
61
+ // any drop usually just means the dashboard server restarted.
62
+ backoff = setTimeout(connect, 1500);
63
+ };
64
+ ws.onerror = reconnect;
65
+ ws.onclose = reconnect;
66
+ ws.onmessage = (e) => {
67
+ let evt: LiveEvent | null = null;
68
+ try { evt = JSON.parse(e.data) as LiveEvent; } catch { return; }
69
+ if (!evt) return;
70
+ for (const cb of listenersRef.current) {
71
+ try { cb(evt); } catch (err) { console.warn("ws listener error", err); }
72
+ }
73
+ };
74
+ }
75
+
76
+ connect();
77
+ return () => {
78
+ cancelled = true;
79
+ if (backoff) clearTimeout(backoff);
80
+ try { wsRef.current?.close(); } catch { /* swallow */ }
81
+ };
82
+ }, []);
83
+
84
+ const subscribe = useCallback((cb: Listener) => {
85
+ listenersRef.current.add(cb);
86
+ return () => { listenersRef.current.delete(cb); };
87
+ }, []);
88
+
89
+ return (
90
+ <WsContext.Provider value={{ state, subscribe }}>
91
+ {children}
92
+ </WsContext.Provider>
93
+ );
94
+ }
95
+
96
+ export function useWsState(): ConnState {
97
+ const ctx = useContext(WsContext);
98
+ return ctx?.state ?? "connecting";
99
+ }
100
+
101
+ /** Subscribe to live events for the duration of the component's lifetime. */
102
+ export function useWs(cb: Listener) {
103
+ const ctx = useContext(WsContext);
104
+ // Latest-ref pattern so callers can update their handler each render
105
+ // without re-subscribing on every keystroke-level state change.
106
+ const cbRef = useRef(cb);
107
+ useEffect(() => { cbRef.current = cb; }, [cb]);
108
+ useEffect(() => {
109
+ if (!ctx) return;
110
+ return ctx.subscribe((evt) => cbRef.current(evt));
111
+ }, [ctx]);
112
+ }
@@ -0,0 +1,63 @@
1
+ // CancelButton — terminal-transition control for a non-terminal flow.
2
+ // Two-click affordance (click → "click again to confirm" within 4s)
3
+ // so a misclick doesn't cancel a long-running flow. The button is
4
+ // silently absent for terminal flows; the parent decides whether to
5
+ // render based on `run.status`.
6
+
7
+ import { useEffect, useRef, useState } from "react";
8
+ import { Button } from "@/components/ui/button";
9
+ import { api } from "@/api/client";
10
+ import { cn } from "@/lib/utils";
11
+
12
+ const CONFIRM_WINDOW_MS = 4_000;
13
+
14
+ export function CancelButton({ flowId }: { flowId: string }) {
15
+ // 'idle' → first click arms 'armed' for CONFIRM_WINDOW_MS, second click commits
16
+ const [phase, setPhase] = useState<"idle" | "armed" | "busy">("idle");
17
+ const [error, setError] = useState<string | null>(null);
18
+ const disarmTimer = useRef<number | null>(null);
19
+
20
+ useEffect(() => () => {
21
+ if (disarmTimer.current != null) window.clearTimeout(disarmTimer.current);
22
+ }, []);
23
+
24
+ function arm() {
25
+ setPhase("armed");
26
+ setError(null);
27
+ if (disarmTimer.current != null) window.clearTimeout(disarmTimer.current);
28
+ disarmTimer.current = window.setTimeout(() => setPhase("idle"), CONFIRM_WINDOW_MS);
29
+ }
30
+
31
+ async function commit() {
32
+ if (disarmTimer.current != null) window.clearTimeout(disarmTimer.current);
33
+ setPhase("busy");
34
+ try {
35
+ await api.cancel(flowId);
36
+ // The live feed (run.ended) refreshes the parent; the button disappears
37
+ // once `run.status` flips terminal.
38
+ } catch (e) {
39
+ setError(e instanceof Error ? e.message : String(e));
40
+ setPhase("idle");
41
+ }
42
+ }
43
+
44
+ return (
45
+ <div className="flex items-center gap-2">
46
+ {error && <span className="text-status-red text-xs">{error}</span>}
47
+ <Button
48
+ variant="chip"
49
+ onClick={phase === "armed" ? commit : arm}
50
+ disabled={phase === "busy"}
51
+ className={cn(
52
+ "text-status-red border-status-red/40 hover:bg-status-red/10",
53
+ phase === "armed" && "bg-status-red/15 border-status-red/60",
54
+ phase === "busy" && "opacity-60",
55
+ )}
56
+ >
57
+ {phase === "busy" ? "cancelling…"
58
+ : phase === "armed" ? "click again to confirm"
59
+ : "cancel run"}
60
+ </Button>
61
+ </div>
62
+ );
63
+ }
@@ -0,0 +1,68 @@
1
+ // Wraps a label/text node so a click on it copies `value` to the clipboard
2
+ // instead of triggering parent handlers (e.g. a row's onClick navigation).
3
+ // Used in dense tables where an inline ⧉ icon would add clutter; detail
4
+ // pages keep the explicit CopyButton because there's no competing click.
5
+
6
+ import { useState } from "react";
7
+ import { cn } from "@/lib/utils";
8
+
9
+ interface ClickToCopyProps {
10
+ value: string;
11
+ /** Optional descriptor for the title attribute — defaults to "copy". */
12
+ label?: string;
13
+ className?: string;
14
+ children: React.ReactNode;
15
+ }
16
+
17
+ export function ClickToCopy({ value, label = "copy", className, children }: ClickToCopyProps) {
18
+ const [state, setState] = useState<"idle" | "ok" | "err">("idle");
19
+
20
+ async function onClick(e: React.MouseEvent) {
21
+ e.preventDefault();
22
+ e.stopPropagation();
23
+ try {
24
+ if (navigator.clipboard?.writeText) {
25
+ await navigator.clipboard.writeText(value);
26
+ } else {
27
+ const ta = document.createElement("textarea");
28
+ ta.value = value;
29
+ ta.style.position = "fixed";
30
+ ta.style.opacity = "0";
31
+ document.body.appendChild(ta);
32
+ ta.select();
33
+ document.execCommand("copy");
34
+ document.body.removeChild(ta);
35
+ }
36
+ setState("ok");
37
+ } catch {
38
+ setState("err");
39
+ }
40
+ setTimeout(() => setState("idle"), 1200);
41
+ }
42
+
43
+ return (
44
+ <span
45
+ role="button"
46
+ tabIndex={0}
47
+ onClick={onClick}
48
+ onKeyDown={(e) => {
49
+ if (e.key === "Enter" || e.key === " ") {
50
+ // Cast — KeyboardEvent reuses the same handler intent (copy on
51
+ // activate), not a real mouse-event sequence.
52
+ onClick(e as unknown as React.MouseEvent);
53
+ }
54
+ }}
55
+ title={`${label}: ${value}`}
56
+ aria-label={`${label} ${value}`}
57
+ className={cn(
58
+ "cursor-copy hover:text-fg transition-colors",
59
+ state === "ok" && "text-status-green",
60
+ state === "err" && "text-status-red",
61
+ className,
62
+ )}
63
+ >
64
+ {children}
65
+ {state === "ok" && <span aria-hidden className="ml-1 text-status-green">✓</span>}
66
+ </span>
67
+ );
68
+ }
@@ -0,0 +1,61 @@
1
+ // One-tap clipboard button for IDs the operator routinely hands off to
2
+ // CLI commands (`openclaw manifold cancel <flowId>`, etc.). Falls back
3
+ // to a non-secure copy when navigator.clipboard isn't available (rare on
4
+ // the tailnet but possible if served from a non-https origin).
5
+
6
+ import { useState } from "react";
7
+ import { cn } from "@/lib/utils";
8
+
9
+ interface CopyButtonProps {
10
+ value: string;
11
+ /** Optional descriptor for hover/aria — defaults to "copy". */
12
+ label?: string;
13
+ className?: string;
14
+ }
15
+
16
+ export function CopyButton({ value, label = "copy", className }: CopyButtonProps) {
17
+ const [state, setState] = useState<"idle" | "ok" | "err">("idle");
18
+
19
+ async function onClick(e: React.MouseEvent) {
20
+ e.preventDefault();
21
+ e.stopPropagation();
22
+ try {
23
+ if (navigator.clipboard?.writeText) {
24
+ await navigator.clipboard.writeText(value);
25
+ } else {
26
+ // Fallback: hidden textarea + document.execCommand. Required when
27
+ // the dashboard is served from http (no Clipboard API) on a non-
28
+ // secure origin.
29
+ const ta = document.createElement("textarea");
30
+ ta.value = value;
31
+ ta.style.position = "fixed";
32
+ ta.style.opacity = "0";
33
+ document.body.appendChild(ta);
34
+ ta.select();
35
+ document.execCommand("copy");
36
+ document.body.removeChild(ta);
37
+ }
38
+ setState("ok");
39
+ } catch {
40
+ setState("err");
41
+ }
42
+ setTimeout(() => setState("idle"), 1200);
43
+ }
44
+
45
+ return (
46
+ <button
47
+ type="button"
48
+ onClick={onClick}
49
+ title={`${label}: ${value}`}
50
+ aria-label={label}
51
+ className={cn(
52
+ "inline-flex items-center align-middle text-fg-dim hover:text-fg leading-none px-1 py-0.5 rounded border border-transparent hover:border-border text-xs",
53
+ state === "ok" && "text-status-green",
54
+ state === "err" && "text-status-red",
55
+ className,
56
+ )}
57
+ >
58
+ {state === "ok" ? "✓" : state === "err" ? "✕" : "⧉"}
59
+ </button>
60
+ );
61
+ }
@@ -0,0 +1,85 @@
1
+ // Daily cost trend bar chart: total spend per day, normalized to the
2
+ // busiest day in the window. Renders pipeline cadence ("am I spending
3
+ // more this week?") with no external chart library. p50/run isn't
4
+ // surfaced here — typical-call cost lives in the row-expansion
5
+ // sparklines where it has per-node / per-pipeline context.
6
+ //
7
+ // Tap any bar to pin its day + value in a label strip below; tap again
8
+ // (or tap a different bar) to swap. Title-attr tooltips don't work on
9
+ // mobile, so this is the touch-friendly equivalent.
10
+
11
+ import { useMemo, useRef, useState } from "react";
12
+ import { useClickOutside } from "@/lib/use-click-outside";
13
+ import { computeAnomalies } from "@/lib/anomaly";
14
+
15
+ export function DailyCostTrend({ perDay }: {
16
+ perDay: { day: string; cost: number; runs: number }[];
17
+ }) {
18
+ const [pinned, setPinned] = useState<string | null>(null);
19
+ const rootRef = useRef<HTMLDivElement>(null);
20
+ useClickOutside(rootRef, () => setPinned(null));
21
+ const anomalies = useMemo(() => computeAnomalies(perDay ?? [], (d) => d.cost), [perDay]);
22
+ if (!perDay?.length) return null;
23
+ const max = Math.max(0.0001, ...perDay.map((d) => d.cost));
24
+ const pinnedDay = pinned ? perDay.find((d) => d.day === pinned) : null;
25
+ const pinnedRatio = pinnedDay ? anomalies.ratios.get(pinnedDay.day) : undefined;
26
+ return (
27
+ <div ref={rootRef} className="border border-border rounded p-2 flex-1 flex flex-col">
28
+ <div className="flex items-center gap-2 mb-1">
29
+ <div className="text-xs text-fg-dim">daily cost</div>
30
+ {anomalies.flagged.size > 0 && (
31
+ <span className="text-[9px] text-status-amber font-mono" title="amber bars exceed the other days' mean by 1.5×+ — outliers in the window">
32
+ ▲ {anomalies.flagged.size} outlier{anomalies.flagged.size === 1 ? "" : "s"}
33
+ </span>
34
+ )}
35
+ </div>
36
+ <div className="text-right text-[10px] text-fg font-mono mb-1 min-h-[14px]">
37
+ {pinnedDay && (
38
+ <span>
39
+ {pinnedDay.day}: ${pinnedDay.cost.toFixed(4)} · {pinnedDay.runs} run{pinnedDay.runs === 1 ? "" : "s"}
40
+ {pinnedRatio != null && <span className="text-status-amber"> · {pinnedRatio.toFixed(1)}× mean</span>}
41
+ </span>
42
+ )}
43
+ </div>
44
+ {/*
45
+ Each slot is a full-height button so the click target spans
46
+ the entire column rather than just the visible bar height —
47
+ tapping a thin bar is otherwise nearly impossible. The
48
+ colored fill renders as an absolute child anchored to the
49
+ bottom of the slot.
50
+ */}
51
+ <div className="flex gap-[2px] flex-1 min-h-12">
52
+ {perDay.map((d) => {
53
+ const h = d.cost > 0 ? Math.max(2, Math.round((d.cost / max) * 100)) : 2;
54
+ const isPinned = pinned === d.day;
55
+ const muted = pinned !== null && !isPinned;
56
+ const isAnomaly = anomalies.flagged.has(d.day);
57
+ const ratio = anomalies.ratios.get(d.day);
58
+ const fill = d.cost > 0 ? (isAnomaly ? "bg-status-amber" : "bg-status-blue") : "bg-bg-elev2";
59
+ const tip = isAnomaly && ratio != null
60
+ ? `${d.day}: $${d.cost.toFixed(4)} · ${d.runs} run${d.runs === 1 ? "" : "s"} · ${ratio.toFixed(1)}× mean`
61
+ : `${d.day}: $${d.cost.toFixed(4)} · ${d.runs} run${d.runs === 1 ? "" : "s"}`;
62
+ return (
63
+ <button
64
+ type="button"
65
+ key={d.day}
66
+ onClick={() => setPinned(isPinned ? null : d.day)}
67
+ className="flex-1 min-w-[6px] relative h-full"
68
+ title={tip}
69
+ >
70
+ <span
71
+ className={`absolute bottom-0 left-0 right-0 rounded-[1px] ${fill} ${muted ? "opacity-65" : ""}`}
72
+ style={{ height: `${h}%` }}
73
+ />
74
+ </button>
75
+ );
76
+ })}
77
+ </div>
78
+ <div className="flex justify-between mt-1.5 text-fg-dim font-mono text-[11px]">
79
+ <span>{perDay[0].day}</span>
80
+ <span>{perDay.length} day{perDay.length === 1 ? "" : "s"}</span>
81
+ <span>{perDay[perDay.length - 1].day}</span>
82
+ </div>
83
+ </div>
84
+ );
85
+ }
@@ -0,0 +1,94 @@
1
+ // Daily wall-time trend, sibling of DailyCostTrend. Toggle picks p50
2
+ // (typical-run duration, default) vs p95 (tail-run duration). Bars
3
+ // represent the chosen percentile of run durations completing that
4
+ // day, so the operator can see at a glance whether runs are getting
5
+ // slower over time and whether the tail is drifting away from the
6
+ // median. Used by both the home overview (portfolio-wide) and the
7
+ // per-pipeline detail.
8
+
9
+ import { useMemo, useRef, useState } from "react";
10
+ import { formatDuration } from "@/lib/format";
11
+ import { useClickOutside } from "@/lib/use-click-outside";
12
+ import { computeAnomalies } from "@/lib/anomaly";
13
+
14
+ export function DailyTimeTrend({ perDay }: {
15
+ perDay: { day: string; cost: number; runs: number; p50Ms: number | null; p95Ms: number | null }[];
16
+ }) {
17
+ const [metric, setMetric] = useState<"p50" | "p95">("p50");
18
+ const [pinned, setPinned] = useState<string | null>(null);
19
+ const rootRef = useRef<HTMLDivElement>(null);
20
+ useClickOutside(rootRef, () => setPinned(null));
21
+ if (!perDay?.length) return null;
22
+ const value = (d: { p50Ms: number | null; p95Ms: number | null }): number =>
23
+ metric === "p95" ? (d.p95Ms ?? 0) : (d.p50Ms ?? 0);
24
+ const max = Math.max(1, ...perDay.map(value));
25
+ const pinnedDay = pinned ? perDay.find((d) => d.day === pinned) : null;
26
+ // eslint-disable-next-line react-hooks/exhaustive-deps
27
+ const anomalies = useMemo(() => computeAnomalies(perDay, value), [perDay, metric]);
28
+ const pinnedRatio = pinnedDay ? anomalies.ratios.get(pinnedDay.day) : undefined;
29
+ return (
30
+ <div ref={rootRef} className="border border-border rounded p-2 flex-1 flex flex-col">
31
+ <div className="flex items-center gap-2 mb-1">
32
+ <div className="text-xs text-fg-dim">daily {metric} run duration</div>
33
+ {anomalies.flagged.size > 0 && (
34
+ <span className="text-[9px] text-status-amber font-mono" title="amber bars exceed the other days' mean by 1.5×+ — outliers in the window">
35
+ ▲ {anomalies.flagged.size}
36
+ </span>
37
+ )}
38
+ <div className="ml-auto inline-flex rounded border border-border overflow-hidden text-[10px] font-mono">
39
+ <button
40
+ type="button"
41
+ onClick={() => setMetric("p50")}
42
+ className={metric === "p50" ? "px-2 py-0.5 bg-status-blue/20 text-fg" : "px-2 py-0.5 text-fg-dim hover:text-fg"}
43
+ >p50</button>
44
+ <button
45
+ type="button"
46
+ onClick={() => setMetric("p95")}
47
+ className={metric === "p95" ? "px-2 py-0.5 border-l border-border bg-status-blue/20 text-fg" : "px-2 py-0.5 border-l border-border text-fg-dim hover:text-fg"}
48
+ >p95</button>
49
+ </div>
50
+ </div>
51
+ <div className="text-right text-[10px] text-fg font-mono mb-1 min-h-[14px]">
52
+ {pinnedDay && (
53
+ <span>
54
+ {pinnedDay.day}: {metric} {formatDuration(value(pinnedDay))} · {pinnedDay.runs} run{pinnedDay.runs === 1 ? "" : "s"}
55
+ {pinnedRatio != null && <span className="text-status-amber"> · {pinnedRatio.toFixed(1)}× mean</span>}
56
+ </span>
57
+ )}
58
+ </div>
59
+ <div className="flex gap-[2px] flex-1 min-h-12">
60
+ {perDay.map((d) => {
61
+ const v = value(d);
62
+ const h = v > 0 ? Math.max(2, Math.round((v / max) * 100)) : 2;
63
+ const isPinned = pinned === d.day;
64
+ const muted = pinned !== null && !isPinned;
65
+ const isAnomaly = anomalies.flagged.has(d.day);
66
+ const ratio = anomalies.ratios.get(d.day);
67
+ const fill = v > 0 ? (isAnomaly ? "bg-status-amber" : "bg-status-blue") : "bg-bg-elev2";
68
+ const tip = isAnomaly && ratio != null
69
+ ? `${d.day}: ${metric} ${formatDuration(v)} · ${d.runs} run${d.runs === 1 ? "" : "s"} · ${ratio.toFixed(1)}× mean`
70
+ : `${d.day}: ${metric} ${formatDuration(v)} · ${d.runs} run${d.runs === 1 ? "" : "s"}`;
71
+ return (
72
+ <button
73
+ type="button"
74
+ key={d.day}
75
+ onClick={() => setPinned(isPinned ? null : d.day)}
76
+ className="flex-1 min-w-[6px] relative h-full"
77
+ title={tip}
78
+ >
79
+ <span
80
+ className={`absolute bottom-0 left-0 right-0 rounded-[1px] ${fill} ${muted ? "opacity-65" : ""}`}
81
+ style={{ height: `${h}%` }}
82
+ />
83
+ </button>
84
+ );
85
+ })}
86
+ </div>
87
+ <div className="flex justify-between mt-1.5 text-fg-dim font-mono text-[11px]">
88
+ <span>{perDay[0].day}</span>
89
+ <span>{perDay.length} day{perDay.length === 1 ? "" : "s"}</span>
90
+ <span>{perDay[perDay.length - 1].day}</span>
91
+ </div>
92
+ </div>
93
+ );
94
+ }
@@ -0,0 +1,149 @@
1
+ import { Fragment, useState } from "react";
2
+ import type { FunnelStage } from "@/api/types";
3
+ import { formatNum } from "@/lib/format";
4
+
5
+ export function Funnel({ stages }: { stages: FunnelStage[] | null }) {
6
+ // Tap-to-expand reveals p95 + min per stage, plus a per-subflow
7
+ // sub-funnel for subflow parents. We default to compact (p50
8
+ // only) because most days the distribution is well-behaved — the
9
+ // expanded view exists for "this stage looks healthy, prove it" inspection.
10
+ const [expanded, setExpanded] = useState<string | null>(null);
11
+ if (!stages || stages.length === 0) {
12
+ return <div className="italic text-fg-dim py-4">no funnel definition for this pipeline</div>;
13
+ }
14
+ const max = Math.max(1, ...stages.map((s) => s.total));
15
+ const overall = stages[stages.length - 1].conversionFromStart;
16
+ return (
17
+ <>
18
+ {/*
19
+ Single grid container so all rows share one column-template — the
20
+ same pattern as NodeCostBreakdown in PipelineDetail. Each per-row
21
+ button uses `display: contents` (Tailwind `contents`) so its four
22
+ cells participate directly in the parent grid; the `auto` first
23
+ column sizes to the widest stage label across all rows. The
24
+ expanded detail block uses `col-span-4`.
25
+ */}
26
+ {/*
27
+ 5 columns: label | bar | total count | (p50 …) | conv%. Splitting
28
+ the count and the parenthetical onto separate auto-sized columns
29
+ keeps each one right-aligned to its own boundary so numbers
30
+ stack cleanly across stages (e.g. 3-digit and 1-digit totals
31
+ line up by their right edges; the parens column lines up by its
32
+ right edge too).
33
+ */}
34
+ <div className="grid grid-cols-[auto_1fr_auto_auto_auto] items-center gap-x-3 gap-y-2 font-mono text-xs">
35
+ {stages.map((s, i) => {
36
+ const conv = s.conversionFromPrev;
37
+ const convTxt = i === 0 ? "" : conv == null ? "—" : `${(conv * 100).toFixed(0)}%`;
38
+ const drop = conv != null && conv < 0.5;
39
+ const isOpen = expanded === s.id;
40
+ // "Ran dry" amber: at least one run yielded 0 at this stage even
41
+ // though the typical run filled it. Only flag the FIRST stage
42
+ // where min drops to 0 — once a run is empty upstream, the
43
+ // emptiness propagates downstream by construction (empty array
44
+ // → empty filter → empty shortlist), so amber-ing every
45
+ // downstream stage is noise. The first drop is the actionable
46
+ // signal.
47
+ const prevMin = i > 0 ? stages[i - 1].min : null;
48
+ const ranDry = s.min === 0 && (s.p50 ?? 0) > 0 && (prevMin == null || prevMin > 0);
49
+ return (
50
+ <Fragment key={s.id}>
51
+ <button
52
+ type="button"
53
+ onClick={() => setExpanded(isOpen ? null : s.id)}
54
+ aria-expanded={isOpen}
55
+ className="contents text-left group"
56
+ >
57
+ <span className="text-fg-dim group-hover:bg-bg-elev2/40 rounded-l-[2px] pl-0.5 whitespace-nowrap inline-flex items-center gap-1">
58
+ <span>{s.label}</span>
59
+ <span className="text-[10px] text-fg-dim/80">{isOpen ? "▾" : "▸"}</span>
60
+ </span>
61
+ <span className="relative h-[18px] bg-bg-elev2 rounded-[3px] overflow-hidden">
62
+ <span
63
+ className="absolute top-0 left-0 bottom-0"
64
+ style={{
65
+ width: `${(s.total / max * 100).toFixed(1)}%`,
66
+ background: "linear-gradient(90deg, #1f6feb, #58a6ff)",
67
+ }}
68
+ />
69
+ </span>
70
+ <span className="text-right whitespace-nowrap tabular-nums group-hover:bg-bg-elev2/40">{s.total}</span>
71
+ <span className={`text-right whitespace-nowrap tabular-nums group-hover:bg-bg-elev2/40 ${ranDry ? "text-status-amber" : "text-fg-dim"}`}>
72
+ (p50 {formatNum(s.p50)}{ranDry ? " · min 0" : ""})
73
+ </span>
74
+ <span className={`text-right whitespace-nowrap tabular-nums group-hover:bg-bg-elev2/40 rounded-r-[2px] pr-0.5 ${drop ? "text-status-amber" : "text-fg-dim"}`}>{convTxt}</span>
75
+ </button>
76
+ {isOpen && (
77
+ <div className="col-span-5 pl-0.5 pr-1 pt-0.5 pb-1.5">
78
+ <div className="text-[10px] text-fg-dim grid grid-cols-2 sm:grid-cols-4 gap-x-3 gap-y-0.5">
79
+ <span><span className="text-fg-dim">p50:</span> {formatNum(s.p50)}</span>
80
+ <span><span className="text-fg-dim">p95:</span> {formatNum(s.p95)}</span>
81
+ <span><span className="text-fg-dim">min:</span> {formatNum(s.min)}</span>
82
+ <span><span className="text-fg-dim">mean:</span> {formatNum(s.mean)}</span>
83
+ <span className="col-span-2 sm:col-span-4"><span className="text-fg-dim">n:</span> {s.n} runs</span>
84
+ </div>
85
+ {s.subStages && s.subStages.length > 0 && (
86
+ <SubFunnel stages={s.subStages} />
87
+ )}
88
+ </div>
89
+ )}
90
+ </Fragment>
91
+ );
92
+ })}
93
+ </div>
94
+ {overall != null && (
95
+ <div className="mt-2.5 font-mono text-fg-dim text-xs">
96
+ overall: {(overall * 100).toFixed(1)}% ({stages[0].label} → {stages[stages.length - 1].label}) across {stages[0].n} run(s)
97
+ </div>
98
+ )}
99
+ </>
100
+ );
101
+ }
102
+
103
+ // Per-subflow attrition funnel rendered inside an expanded
104
+ // loop stage. The unit is *subflows* (one per item the
105
+ // parent's selector emitted) rather than runs, so e.g. POLL with 175
106
+ // runs may have 7000+ subflows across them. Visually muted to read as
107
+ // a child of the parent row.
108
+ function SubFunnel({ stages }: { stages: FunnelStage[] }) {
109
+ if (!stages.length) return null;
110
+ const max = Math.max(1, ...stages.map((s) => s.total));
111
+ return (
112
+ <div className="mt-2 ml-3 pl-2 border-l border-border/60">
113
+ <div className="text-[10px] text-fg-dim/80 mb-1 italic">per-subflow sub-funnel</div>
114
+ <div className="grid grid-cols-[auto_1fr_auto_auto] items-center gap-x-3 gap-y-1 font-mono text-[11px]">
115
+ {stages.map((s, i) => {
116
+ const conv = s.conversionFromPrev;
117
+ // Avoid the "11/8106 = 0%" trap: show <1% (and one decimal in
118
+ // the 0–10 band) so tiny-but-nonzero conversions read as
119
+ // *signal*, not zero.
120
+ const convTxt = i === 0
121
+ ? ""
122
+ : conv == null
123
+ ? "—"
124
+ : conv === 0
125
+ ? "0%"
126
+ : conv < 0.01
127
+ ? "<1%"
128
+ : conv < 0.1
129
+ ? `${(conv * 100).toFixed(1)}%`
130
+ : `${(conv * 100).toFixed(0)}%`;
131
+ const drop = conv != null && conv < 0.5;
132
+ return (
133
+ <Fragment key={s.id}>
134
+ <span className="text-fg-dim whitespace-nowrap">{s.label}</span>
135
+ <span className="relative h-[12px] bg-bg-elev2 rounded-[2px] overflow-hidden">
136
+ <span
137
+ className="absolute top-0 left-0 bottom-0 bg-status-blue/70"
138
+ style={{ width: `${(s.total / max * 100).toFixed(1)}%` }}
139
+ />
140
+ </span>
141
+ <span className="text-right whitespace-nowrap tabular-nums text-fg-dim">{s.total}</span>
142
+ <span className={`text-right whitespace-nowrap tabular-nums ${drop ? "text-status-amber" : "text-fg-dim"}`}>{convTxt}</span>
143
+ </Fragment>
144
+ );
145
+ })}
146
+ </div>
147
+ </div>
148
+ );
149
+ }