@igorjpimenta/manifold 0.0.0-bootstrap.1 → 0.0.0-stage

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/README.md +2 -1583
  2. package/package.json +4 -49
  3. package/.migrations/ops/0000_futuristic_karma.sql +0 -111
  4. package/.migrations/ops/0001_low_maximus.sql +0 -7
  5. package/.migrations/ops/meta/0000_snapshot.json +0 -763
  6. package/.migrations/ops/meta/0001_snapshot.json +0 -173
  7. package/.migrations/ops/meta/_journal.json +0 -20
  8. package/.migrations/runtime/0000_real_boomer.sql +0 -180
  9. package/.migrations/runtime/0001_hot_dakota_north.sql +0 -2
  10. package/.migrations/runtime/0002_breezy_vertigo.sql +0 -8
  11. package/.migrations/runtime/0003_dashing_jack_flag.sql +0 -5
  12. package/.migrations/runtime/0004_panoramic_ego.sql +0 -1
  13. package/.migrations/runtime/0005_tidy_ben_grimm.sql +0 -10
  14. package/.migrations/runtime/0006_wet_nightmare.sql +0 -57
  15. package/.migrations/runtime/0007_ambiguous_chronomancer.sql +0 -8
  16. package/.migrations/runtime/0008_wealthy_thundra.sql +0 -301
  17. package/.migrations/runtime/0009_lying_shocker.sql +0 -96
  18. package/.migrations/runtime/0010_solid_phantom_reporter.sql +0 -160
  19. package/.migrations/runtime/0011_windy_demogoblin.sql +0 -175
  20. package/.migrations/runtime/0012_restore_harness_fks.sql +0 -103
  21. package/.migrations/runtime/meta/0000_snapshot.json +0 -1181
  22. package/.migrations/runtime/meta/0001_snapshot.json +0 -1209
  23. package/.migrations/runtime/meta/0002_snapshot.json +0 -1261
  24. package/.migrations/runtime/meta/0003_snapshot.json +0 -1292
  25. package/.migrations/runtime/meta/0004_snapshot.json +0 -1240
  26. package/.migrations/runtime/meta/0006_snapshot.json +0 -1310
  27. package/.migrations/runtime/meta/0007_snapshot.json +0 -1362
  28. package/.migrations/runtime/meta/0008_snapshot.json +0 -1742
  29. package/.migrations/runtime/meta/0009_snapshot.json +0 -2413
  30. package/.migrations/runtime/meta/0010_snapshot.json +0 -2562
  31. package/.migrations/runtime/meta/0011_snapshot.json +0 -2812
  32. package/.migrations/runtime/meta/0012_snapshot.json +0 -2812
  33. package/.migrations/runtime/meta/_journal.json +0 -97
  34. package/RELEASING.md +0 -89
  35. package/agent/fleet.js +0 -100
  36. package/bin/cli.js +0 -854
  37. package/bin/manifold.js +0 -4
  38. package/boot/flow-revival.js +0 -536
  39. package/budget/index.js +0 -495
  40. package/budget/lib.js +0 -59
  41. package/dashboard/cost.js +0 -528
  42. package/dashboard/dist/assets/index-CUfp63sj.css +0 -1
  43. package/dashboard/dist/assets/index-Qy9JMpma.js +0 -371
  44. package/dashboard/dist/index.html +0 -13
  45. package/dashboard/event-log.js +0 -267
  46. package/dashboard/index.html +0 -12
  47. package/dashboard/package-lock.json +0 -2877
  48. package/dashboard/package.json +0 -37
  49. package/dashboard/pipeline-graph.js +0 -131
  50. package/dashboard/postcss.config.js +0 -6
  51. package/dashboard/search.js +0 -183
  52. package/dashboard/server.js +0 -1015
  53. package/dashboard/src/App.tsx +0 -42
  54. package/dashboard/src/api/client.ts +0 -118
  55. package/dashboard/src/api/types.ts +0 -510
  56. package/dashboard/src/api/ws.tsx +0 -112
  57. package/dashboard/src/components/CancelButton.tsx +0 -63
  58. package/dashboard/src/components/ClickToCopy.tsx +0 -68
  59. package/dashboard/src/components/CopyButton.tsx +0 -61
  60. package/dashboard/src/components/DailyCostTrend.tsx +0 -85
  61. package/dashboard/src/components/DailyTimeTrend.tsx +0 -94
  62. package/dashboard/src/components/Funnel.tsx +0 -149
  63. package/dashboard/src/components/GateForm.tsx +0 -158
  64. package/dashboard/src/components/GraphView.tsx +0 -302
  65. package/dashboard/src/components/GroupPathsSummary.tsx +0 -47
  66. package/dashboard/src/components/Histogram.tsx +0 -292
  67. package/dashboard/src/components/Layout.tsx +0 -28
  68. package/dashboard/src/components/NeedsAttention.tsx +0 -98
  69. package/dashboard/src/components/NodeContextCard.tsx +0 -132
  70. package/dashboard/src/components/PathTrail.tsx +0 -35
  71. package/dashboard/src/components/PipelineCostBreakdown.tsx +0 -277
  72. package/dashboard/src/components/RerunButton.tsx +0 -46
  73. package/dashboard/src/components/RunComparison.tsx +0 -53
  74. package/dashboard/src/components/Sparkline.tsx +0 -94
  75. package/dashboard/src/components/StatStrip.tsx +0 -147
  76. package/dashboard/src/components/StateTree.tsx +0 -84
  77. package/dashboard/src/components/StatusBadge.tsx +0 -18
  78. package/dashboard/src/components/SubflowPathPills.tsx +0 -38
  79. package/dashboard/src/components/SubflowSummary.tsx +0 -24
  80. package/dashboard/src/components/SubflowsCard.tsx +0 -327
  81. package/dashboard/src/components/TodayStrip.tsx +0 -86
  82. package/dashboard/src/components/TranscriptPane.tsx +0 -99
  83. package/dashboard/src/components/TranscriptRow.tsx +0 -69
  84. package/dashboard/src/components/ui/badge.tsx +0 -38
  85. package/dashboard/src/components/ui/button.tsx +0 -28
  86. package/dashboard/src/components/ui/card.tsx +0 -42
  87. package/dashboard/src/components/ui/skeleton.tsx +0 -9
  88. package/dashboard/src/components/ui/table.tsx +0 -62
  89. package/dashboard/src/index.css +0 -26
  90. package/dashboard/src/lib/anomaly.ts +0 -42
  91. package/dashboard/src/lib/format.ts +0 -30
  92. package/dashboard/src/lib/step-history.ts +0 -13
  93. package/dashboard/src/lib/subflow.ts +0 -154
  94. package/dashboard/src/lib/use-click-outside.ts +0 -28
  95. package/dashboard/src/lib/use-ignored-clusters.ts +0 -67
  96. package/dashboard/src/lib/utils.ts +0 -6
  97. package/dashboard/src/main.tsx +0 -10
  98. package/dashboard/src/types/shims.d.ts +0 -4
  99. package/dashboard/src/views/Home.tsx +0 -478
  100. package/dashboard/src/views/PipelineDetail.tsx +0 -1185
  101. package/dashboard/src/views/PipelinesList.tsx +0 -111
  102. package/dashboard/src/views/RunDetail.tsx +0 -248
  103. package/dashboard/src/views/Search.tsx +0 -196
  104. package/dashboard/stats.js +0 -668
  105. package/dashboard/tailwind.config.ts +0 -43
  106. package/dashboard/tree-stats.js +0 -12
  107. package/dashboard/tsconfig.json +0 -25
  108. package/dashboard/views.js +0 -231
  109. package/dashboard/vite.config.ts +0 -34
  110. package/drizzle.config.js +0 -12
  111. package/drizzle.config.ops.js +0 -12
  112. package/elevation.js +0 -116
  113. package/engine/admission-promotion-resume.js +0 -127
  114. package/engine/agent-dispatch.js +0 -64
  115. package/engine/child-resume-trigger.js +0 -315
  116. package/engine/executor-budget.js +0 -87
  117. package/engine/executor-cancel.js +0 -83
  118. package/engine/executor-errors.js +0 -122
  119. package/engine/executor-helpers.js +0 -254
  120. package/engine/executor-nodes.js +0 -292
  121. package/engine/executor-persist.js +0 -212
  122. package/engine/executor-subflow-children.js +0 -275
  123. package/engine/executor.js +0 -1013
  124. package/engine/global-concurrency.js +0 -33
  125. package/engine/loader.js +0 -528
  126. package/engine/needs-resolver.js +0 -229
  127. package/engine/pipelines-watcher.js +0 -133
  128. package/engine/result-replay.js +0 -34
  129. package/engine/revival-messages.js +0 -11
  130. package/engine/spawn-child.js +0 -55
  131. package/engine/wait-for-flow-settlement.js +0 -109
  132. package/events/catalog.js +0 -26
  133. package/events/emit.js +0 -44
  134. package/events/kinds.js +0 -118
  135. package/events/serve-ws.js +0 -74
  136. package/events/stream.js +0 -35
  137. package/events/ws-dialog.js +0 -257
  138. package/events/ws-frame.js +0 -194
  139. package/events/ws-run-events.js +0 -70
  140. package/events.js +0 -32
  141. package/gates/gate-resolver.js +0 -576
  142. package/gates/paused-flows.js +0 -55
  143. package/graphql/columns.js +0 -67
  144. package/graphql/schema.js +0 -333
  145. package/index.js +0 -49
  146. package/mcp/http.js +0 -159
  147. package/mcp/identity.js +0 -94
  148. package/mcp/stdio.js +0 -80
  149. package/mcp/tools.js +0 -245
  150. package/mcp/wire-ops.js +0 -178
  151. package/routes/bearer-auth.js +0 -57
  152. package/routes/discuss-audio.js +0 -87
  153. package/routes/discuss-component.js +0 -39
  154. package/routes/discuss-draft.js +0 -159
  155. package/routes/discuss-helpers.js +0 -20
  156. package/routes/discuss.js +0 -848
  157. package/routes/failures.js +0 -104
  158. package/routes/graphql.js +0 -61
  159. package/routes/health.js +0 -54
  160. package/routes/operator-discuss.js +0 -193
  161. package/routes/operator-resume.js +0 -32
  162. package/routes/operator-retry.js +0 -301
  163. package/routes/operator.js +0 -539
  164. package/routes/pipelines.js +0 -118
  165. package/routes/runs.js +0 -1129
  166. package/scripts/ci/import-check.mjs +0 -50
  167. package/scripts/link-core-self.mjs +0 -31
  168. package/scripts/with-guard.sh +0 -24
  169. package/server/app.js +0 -503
  170. package/server/registry.js +0 -53
  171. package/server/serve.js +0 -163
  172. package/state/admission-queue-store.js +0 -325
  173. package/state/attribution-registries.js +0 -102
  174. package/state/batch-writer.js +0 -162
  175. package/state/db-guard.js +0 -63
  176. package/state/db-health.js +0 -27
  177. package/state/db.js +0 -122
  178. package/state/discuss-store.js +0 -299
  179. package/state/failure-store.js +0 -427
  180. package/state/migrate.js +0 -104
  181. package/state/node-cost.js +0 -67
  182. package/state/node-executions.js +0 -775
  183. package/state/node-health-store.js +0 -124
  184. package/state/ops-merge.js +0 -93
  185. package/state/paths.js +0 -146
  186. package/state/pipeline-dirs.js +0 -99
  187. package/state/pipeline-registry.js +0 -449
  188. package/state/run-store.js +0 -697
  189. package/state/schema.js +0 -438
  190. package/state/schema.ops.js +0 -44
  191. package/state/session-index.js +0 -177
  192. package/state/session-keys.js +0 -39
  193. package/state/state-store.js +0 -311
  194. package/state/subflow-state.js +0 -126
  195. package/state/tool-handoff.js +0 -169
  196. package/telemetry/budget-alert.js +0 -353
  197. package/telemetry/cli.js +0 -331
  198. package/telemetry/grammar.js +0 -119
  199. package/telemetry/http-budget.js +0 -132
  200. package/telemetry/http-cost.js +0 -670
  201. package/telemetry/http-helpers.js +0 -134
  202. package/telemetry/http-tree.js +0 -349
  203. package/telemetry/http.js +0 -44
  204. package/telemetry/index.js +0 -307
  205. package/telemetry/ingest.js +0 -134
  206. package/telemetry/labels.js +0 -115
  207. package/telemetry/pricer.js +0 -77
  208. package/telemetry/resolver.js +0 -314
  209. package/telemetry/store.js +0 -147
  210. package/utils/run-patch.js +0 -43
@@ -1,112 +0,0 @@
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
- }
@@ -1,63 +0,0 @@
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
- }
@@ -1,68 +0,0 @@
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
- }
@@ -1,61 +0,0 @@
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
- }
@@ -1,85 +0,0 @@
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
- }
@@ -1,94 +0,0 @@
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
- }
@@ -1,149 +0,0 @@
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
- }