@igorjpimenta/manifold 0.0.0-bootstrap.1

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 +1584 -0
  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 +51 -0
  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,99 @@
1
+ // TranscriptPane — chat-style timeline of the subagent sessions a flow
2
+ // spawned. Reads parsed messages from `/api/runs/:flowId/transcripts`.
3
+ //
4
+ // Each transcript is one (agent, node, item) trio — corresponds to one
5
+ // session JSONL file under `~/.openclaw/agents/<agent>/sessions/`. The
6
+ // pane groups them by agent, lists them collapsed, expands to a
7
+ // user→assistant chat view on click. Thinking content (when present)
8
+ // is rendered subdued in a separate block from the assistant's reply.
9
+
10
+ import { useEffect, useMemo, useState } from "react";
11
+ import { Card, CardHeader, CardTitle } from "@/components/ui/card";
12
+ import { Badge } from "@/components/ui/badge";
13
+ import { TranscriptRow } from "@/components/TranscriptRow";
14
+ import { api } from "@/api/client";
15
+ import type { Transcript } from "@/api/types";
16
+
17
+ interface TranscriptPaneProps {
18
+ flowId: string;
19
+ /** If parent passes transcripts (lifted-state pattern), skip internal fetch. */
20
+ transcripts?: Transcript[] | null;
21
+ }
22
+
23
+ export function TranscriptPane({ flowId, transcripts: externalTranscripts }: TranscriptPaneProps) {
24
+ const [internalTranscripts, setInternalTranscripts] = useState<Transcript[] | null>(null);
25
+ const [error, setError] = useState<string | null>(null);
26
+ const [openKey, setOpenKey] = useState<string | null>(null);
27
+ const useExternal = externalTranscripts !== undefined;
28
+ const transcripts = useExternal ? externalTranscripts : internalTranscripts;
29
+
30
+ useEffect(() => {
31
+ if (useExternal) return; // parent provides data; no fetch
32
+ let cancelled = false;
33
+ setInternalTranscripts(null);
34
+ setError(null);
35
+ api.runTranscripts(flowId)
36
+ .then((ts) => { if (!cancelled) setInternalTranscripts(ts); })
37
+ .catch((e) => { if (!cancelled) setError(e?.message ?? String(e)); });
38
+ return () => { cancelled = true; };
39
+ }, [flowId, useExternal]);
40
+
41
+ const byAgent = useMemo(() => {
42
+ if (!transcripts) return new Map<string, Transcript[]>();
43
+ const m = new Map<string, Transcript[]>();
44
+ for (const t of transcripts) {
45
+ const arr = m.get(t.agent) ?? [];
46
+ arr.push(t);
47
+ m.set(t.agent, arr);
48
+ }
49
+ return m;
50
+ }, [transcripts]);
51
+
52
+ return (
53
+ <Card>
54
+ <CardHeader>
55
+ <CardTitle>transcripts</CardTitle>
56
+ {transcripts && (
57
+ <span className="font-mono text-xs text-fg-dim">
58
+ {transcripts.length === 0
59
+ ? "no subagent sessions for this flow"
60
+ : `${transcripts.length} session${transcripts.length === 1 ? "" : "s"} across ${byAgent.size} agent${byAgent.size === 1 ? "" : "s"}`}
61
+ </span>
62
+ )}
63
+ </CardHeader>
64
+
65
+ {error && <div className="text-status-red text-sm">{error}</div>}
66
+ {!transcripts && !error && <div className="text-fg-dim italic text-sm">loading…</div>}
67
+ {transcripts && transcripts.length === 0 && (
68
+ <div className="text-fg-dim italic text-sm">
69
+ This flow didn't spawn any subagent sessions, or the sessions don't
70
+ match the manifold default pattern.
71
+ </div>
72
+ )}
73
+
74
+ {transcripts && transcripts.length > 0 && (
75
+ <div className="grid gap-3">
76
+ {[...byAgent.entries()].map(([agent, list]) => (
77
+ <div key={agent} className="border border-border rounded p-2 bg-bg-elev2/30">
78
+ <div className="flex items-center gap-2 mb-2 flex-wrap">
79
+ <Badge variant="kind">{agent}</Badge>
80
+ <span className="text-fg-dim text-xs font-mono">{list.length} session{list.length === 1 ? "" : "s"}</span>
81
+ </div>
82
+ <div className="grid grid-cols-1 gap-1">
83
+ {list.map((t) => (
84
+ <TranscriptRow
85
+ key={t.session}
86
+ transcript={t}
87
+ isOpen={openKey === t.session}
88
+ onToggle={() => setOpenKey(openKey === t.session ? null : t.session)}
89
+ />
90
+ ))}
91
+ </div>
92
+ </div>
93
+ ))}
94
+ </div>
95
+ )}
96
+ </Card>
97
+ );
98
+ }
99
+
@@ -0,0 +1,69 @@
1
+ // Shared transcript-row + turn renderers, used by TranscriptPane (full
2
+ // list view) and SubflowsCard (per-subflow drill-down). Lifted out of
3
+ // TranscriptPane so both surfaces use identical styling and behavior.
4
+
5
+ import { formatTime } from "@/lib/format";
6
+ import { cn } from "@/lib/utils";
7
+ import type { Transcript, TranscriptTurn } from "@/api/types";
8
+
9
+ interface TranscriptRowProps {
10
+ transcript: Transcript;
11
+ isOpen: boolean;
12
+ onToggle: () => void;
13
+ /** Hide the itemKey column when the parent already groups by it (e.g. subflow drill-down). */
14
+ hideItemKey?: boolean;
15
+ }
16
+
17
+ export function TranscriptRow({ transcript, isOpen, onToggle, hideItemKey }: TranscriptRowProps) {
18
+ const { nodeId, itemKey, turns, startedAt } = transcript;
19
+ return (
20
+ <div className="border border-border rounded">
21
+ <button
22
+ onClick={onToggle}
23
+ className="w-full flex items-center gap-3 px-2 py-1.5 text-left hover:bg-bg-elev2 min-w-0"
24
+ >
25
+ <span className="text-fg-dim font-mono text-xs w-4 shrink-0">{isOpen ? "▾" : "▸"}</span>
26
+ <span className="font-mono text-sm flex-1 min-w-0 truncate">{nodeId}</span>
27
+ {!hideItemKey && itemKey && (
28
+ <span className="font-mono text-fg-dim text-xs truncate hidden sm:inline">· {itemKey}</span>
29
+ )}
30
+ <span className="font-mono text-fg-dim text-xs whitespace-nowrap shrink-0">{turns.length} turn{turns.length === 1 ? "" : "s"}</span>
31
+ <span className="text-fg-dim text-xs whitespace-nowrap shrink-0 hidden md:inline">{formatTime(startedAt)}</span>
32
+ </button>
33
+ {isOpen && (
34
+ <div className="border-t border-border p-3 grid gap-3">
35
+ {turns.length === 0
36
+ ? <div className="text-fg-dim italic text-xs">(empty session)</div>
37
+ : turns.map((turn, i) => <Turn key={i} turn={turn} />)
38
+ }
39
+ </div>
40
+ )}
41
+ </div>
42
+ );
43
+ }
44
+
45
+ export function Turn({ turn }: { turn: TranscriptTurn }) {
46
+ const isUser = turn.role === "user";
47
+ return (
48
+ <div className="grid grid-cols-[68px_1fr] gap-2 min-w-0">
49
+ <span className={cn(
50
+ "font-mono text-[11px] uppercase tracking-[0.5px] pt-0.5",
51
+ isUser ? "text-accent" : "text-status-green"
52
+ )}>
53
+ {turn.role}
54
+ </span>
55
+ <div className="min-w-0">
56
+ {turn.thinking && (
57
+ <details className="mb-1">
58
+ <summary className="text-fg-dim text-xs cursor-pointer hover:text-fg">thinking ({turn.thinking.length} chars)</summary>
59
+ <pre className="text-xs text-fg-dim whitespace-pre-wrap break-words bg-bg-elev2/40 rounded p-2 mt-1 max-h-64 overflow-auto">{turn.thinking}</pre>
60
+ </details>
61
+ )}
62
+ <pre className="text-sm whitespace-pre-wrap break-words font-sans">{turn.text}</pre>
63
+ {turn.truncated && (
64
+ <div className="text-fg-dim italic text-xs mt-1">…truncated at 8KB on the server</div>
65
+ )}
66
+ </div>
67
+ </div>
68
+ );
69
+ }
@@ -0,0 +1,38 @@
1
+ import { cva, type VariantProps } from "class-variance-authority";
2
+ import type { HTMLAttributes } from "react";
3
+ import { cn } from "@/lib/utils";
4
+
5
+ // Status variants match the run-status palette established in v0
6
+ // (succeeded → blue tint, failed → red, etc.). New variants `pill-*` are
7
+ // for the path-trail / per-step pills that appear inside tables.
8
+ const badgeVariants = cva(
9
+ "inline-block px-2 py-[2px] rounded-[10px] font-mono text-[11px] border border-transparent leading-snug whitespace-nowrap",
10
+ {
11
+ variants: {
12
+ variant: {
13
+ default: "bg-bg-elev2 text-fg-dim border-border",
14
+ running: "bg-status-green/15 text-status-green border-status-green/40",
15
+ waiting: "bg-status-amber/15 text-status-amber border-status-amber/40",
16
+ blocked: "bg-status-amber/15 text-status-amber border-status-amber/40",
17
+ succeeded: "bg-status-blue/15 text-[#79b8ff] border-status-blue/40",
18
+ failed: "bg-status-red/15 text-status-red border-status-red/40",
19
+ cancelled: "bg-status-grey/15 text-status-grey border-status-grey/40",
20
+ kind: "bg-bg-elev2 text-fg-dim border-border",
21
+ historical: "bg-status-grey/15 text-fg-dim border-border",
22
+ },
23
+ size: {
24
+ default: "text-[11px] px-2",
25
+ sm: "text-[10px] px-[6px] py-px",
26
+ },
27
+ },
28
+ defaultVariants: { variant: "default", size: "default" },
29
+ }
30
+ );
31
+
32
+ export interface BadgeProps extends HTMLAttributes<HTMLSpanElement>, VariantProps<typeof badgeVariants> {}
33
+
34
+ export function Badge({ className, variant, size, ...props }: BadgeProps) {
35
+ return <span className={cn(badgeVariants({ variant, size }), className)} {...props} />;
36
+ }
37
+
38
+ export { badgeVariants };
@@ -0,0 +1,28 @@
1
+ import { forwardRef, type ButtonHTMLAttributes } from "react";
2
+ import { cva, type VariantProps } from "class-variance-authority";
3
+ import { cn } from "@/lib/utils";
4
+
5
+ const buttonVariants = cva(
6
+ "inline-flex items-center justify-center font-mono transition-colors disabled:opacity-50 disabled:pointer-events-none",
7
+ {
8
+ variants: {
9
+ variant: {
10
+ default: "bg-bg-elev2 text-fg border border-border rounded-md px-3 py-1.5 text-xs hover:bg-bg-elev",
11
+ link: "bg-transparent text-accent border-0 p-0 hover:underline",
12
+ chip: "bg-transparent text-fg-dim border border-border rounded-full px-[10px] py-[3px] text-[12px] hover:bg-bg-elev2",
13
+ },
14
+ },
15
+ defaultVariants: { variant: "default" },
16
+ }
17
+ );
18
+
19
+ export interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement>, VariantProps<typeof buttonVariants> {}
20
+
21
+ export const Button = forwardRef<HTMLButtonElement, ButtonProps>(
22
+ ({ className, variant, ...props }, ref) => (
23
+ <button ref={ref} className={cn(buttonVariants({ variant }), className)} {...props} />
24
+ )
25
+ );
26
+ Button.displayName = "Button";
27
+
28
+ export { buttonVariants };
@@ -0,0 +1,42 @@
1
+ import { forwardRef, type HTMLAttributes } from "react";
2
+ import { cn } from "@/lib/utils";
3
+
4
+ export const Card = forwardRef<HTMLDivElement, HTMLAttributes<HTMLDivElement>>(
5
+ ({ className, ...props }, ref) => (
6
+ <div
7
+ ref={ref}
8
+ className={cn("bg-bg-elev border border-border rounded-md p-3 sm:p-4 mb-4", className)}
9
+ {...props}
10
+ />
11
+ )
12
+ );
13
+ Card.displayName = "Card";
14
+
15
+ export const CardHeader = forwardRef<HTMLDivElement, HTMLAttributes<HTMLDivElement>>(
16
+ ({ className, ...props }, ref) => (
17
+ <div
18
+ ref={ref}
19
+ className={cn("flex items-center justify-between mb-3", className)}
20
+ {...props}
21
+ />
22
+ )
23
+ );
24
+ CardHeader.displayName = "CardHeader";
25
+
26
+ export const CardTitle = forwardRef<HTMLHeadingElement, HTMLAttributes<HTMLHeadingElement>>(
27
+ ({ className, ...props }, ref) => (
28
+ <h3
29
+ ref={ref}
30
+ className={cn("text-sm font-semibold m-0", className)}
31
+ {...props}
32
+ />
33
+ )
34
+ );
35
+ CardTitle.displayName = "CardTitle";
36
+
37
+ export const CardContent = forwardRef<HTMLDivElement, HTMLAttributes<HTMLDivElement>>(
38
+ ({ className, ...props }, ref) => (
39
+ <div ref={ref} className={cn("", className)} {...props} />
40
+ )
41
+ );
42
+ CardContent.displayName = "CardContent";
@@ -0,0 +1,9 @@
1
+ // Pulsing placeholder block. Shape-mimicking skeletons across the
2
+ // dashboard compose these so the layout doesn't reflow when async
3
+ // data arrives.
4
+
5
+ import { cn } from "@/lib/utils";
6
+
7
+ export function Skeleton({ className }: { className?: string }) {
8
+ return <div className={cn("bg-bg-elev2 rounded animate-pulse", className)} />;
9
+ }
@@ -0,0 +1,62 @@
1
+ import { forwardRef, type HTMLAttributes, type TdHTMLAttributes, type ThHTMLAttributes } from "react";
2
+ import { cn } from "@/lib/utils";
3
+
4
+ // Wrapped in an overflow-x container so tables that exceed the viewport on
5
+ // narrow screens become horizontally scrollable instead of blowing out the
6
+ // parent layout. The negative-margin/positive-padding trick lets the scroll
7
+ // area bleed past the Card's inner padding so the table edge meets the card
8
+ // edge on mobile (where every horizontal pixel matters).
9
+ export const Table = forwardRef<HTMLTableElement, HTMLAttributes<HTMLTableElement>>(
10
+ ({ className, ...props }, ref) => (
11
+ <div className="-mx-3 sm:-mx-4 px-3 sm:px-4 overflow-x-auto">
12
+ <table
13
+ ref={ref}
14
+ className={cn("min-w-full border-collapse text-[13px] whitespace-nowrap", className)}
15
+ {...props}
16
+ />
17
+ </div>
18
+ )
19
+ );
20
+ Table.displayName = "Table";
21
+
22
+ export const THead = forwardRef<HTMLTableSectionElement, HTMLAttributes<HTMLTableSectionElement>>(
23
+ ({ className, ...props }, ref) => <thead ref={ref} className={cn("", className)} {...props} />
24
+ );
25
+ THead.displayName = "THead";
26
+
27
+ export const TBody = forwardRef<HTMLTableSectionElement, HTMLAttributes<HTMLTableSectionElement>>(
28
+ ({ className, ...props }, ref) => <tbody ref={ref} className={cn("", className)} {...props} />
29
+ );
30
+ TBody.displayName = "TBody";
31
+
32
+ export const TR = forwardRef<HTMLTableRowElement, HTMLAttributes<HTMLTableRowElement>>(
33
+ ({ className, ...props }, ref) => (
34
+ <tr ref={ref} className={cn("[&:not(:last-child)]:border-b border-border", className)} {...props} />
35
+ )
36
+ );
37
+ TR.displayName = "TR";
38
+
39
+ export const TH = forwardRef<HTMLTableCellElement, ThHTMLAttributes<HTMLTableCellElement>>(
40
+ ({ className, ...props }, ref) => (
41
+ <th
42
+ ref={ref}
43
+ className={cn(
44
+ "text-left px-[10px] py-[6px] text-fg-dim font-normal uppercase tracking-[0.4px] text-[11px] border-b border-border",
45
+ className
46
+ )}
47
+ {...props}
48
+ />
49
+ )
50
+ );
51
+ TH.displayName = "TH";
52
+
53
+ export const TD = forwardRef<HTMLTableCellElement, TdHTMLAttributes<HTMLTableCellElement>>(
54
+ ({ className, ...props }, ref) => (
55
+ <td
56
+ ref={ref}
57
+ className={cn("text-left px-[10px] py-[6px]", className)}
58
+ {...props}
59
+ />
60
+ )
61
+ );
62
+ TD.displayName = "TD";
@@ -0,0 +1,26 @@
1
+ @tailwind base;
2
+ @tailwind components;
3
+ @tailwind utilities;
4
+
5
+ @layer base {
6
+ html, body {
7
+ @apply m-0 bg-bg text-fg;
8
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
9
+ font-size: 14px;
10
+ line-height: 1.5;
11
+ }
12
+ a { @apply text-accent no-underline; }
13
+ a:hover { @apply underline; }
14
+ }
15
+
16
+ @layer components {
17
+ /* shared card / table tweaks the design system expects everywhere */
18
+ .scrollable-pre {
19
+ @apply font-mono text-xs bg-bg border border-border rounded p-2 overflow-auto max-h-96;
20
+ }
21
+ }
22
+
23
+ @layer utilities {
24
+ /* opacity-modulated text color helpers (matching the v0 .dim usage). */
25
+ .text-dim { color: theme('colors.fg.dim'); }
26
+ }
@@ -0,0 +1,42 @@
1
+ // Per-day anomaly detection for sparkline charts. A bar is flagged
2
+ // when its value exceeds the mean of the other bars by a configurable
3
+ // factor (default 1.5×). Conservative: skips bars where the value is
4
+ // zero (no work that day shouldn't count as anomalous), and bails out
5
+ // entirely when fewer than 3 non-zero bars exist (no meaningful
6
+ // baseline to compare against).
7
+ //
8
+ // Returns a Set<day-key> for O(1) lookup in the bar render loop, plus
9
+ // a `ratios` map so the chart can show "2.4× mean" in tooltips and
10
+ // pinned labels.
11
+
12
+ export interface AnomalyResult {
13
+ flagged: Set<string>;
14
+ ratios: Map<string, number>;
15
+ }
16
+
17
+ export function computeAnomalies<T extends { day: string }>(
18
+ perDay: T[],
19
+ getValue: (d: T) => number,
20
+ threshold = 1.5,
21
+ ): AnomalyResult {
22
+ const flagged = new Set<string>();
23
+ const ratios = new Map<string, number>();
24
+ if (!perDay || perDay.length < 3) return { flagged, ratios };
25
+ const nonZeroCount = perDay.reduce((n, d) => n + (getValue(d) > 0 ? 1 : 0), 0);
26
+ if (nonZeroCount < 3) return { flagged, ratios };
27
+
28
+ for (const d of perDay) {
29
+ const v = getValue(d);
30
+ if (v <= 0) continue;
31
+ const others = perDay.filter((x) => x.day !== d.day).map(getValue).filter((x) => x > 0);
32
+ if (others.length < 2) continue;
33
+ const mean = others.reduce((s, x) => s + x, 0) / others.length;
34
+ if (mean <= 0) continue;
35
+ const ratio = v / mean;
36
+ if (ratio > threshold) {
37
+ flagged.add(d.day);
38
+ ratios.set(d.day, ratio);
39
+ }
40
+ }
41
+ return { flagged, ratios };
42
+ }
@@ -0,0 +1,30 @@
1
+ export function formatDuration(ms: number | null | undefined): string {
2
+ if (ms == null) return "—";
3
+ if (ms < 1000) return `${ms.toFixed(0)}ms`;
4
+ const s = ms / 1000;
5
+ if (s < 60) return `${s.toFixed(1)}s`;
6
+ const m = s / 60;
7
+ if (m < 60) return `${m.toFixed(1)}m`;
8
+ const h = m / 60;
9
+ return `${h.toFixed(1)}h`;
10
+ }
11
+
12
+ export function formatTime(ms: number | null | undefined): string {
13
+ if (!ms) return "";
14
+ const d = new Date(ms);
15
+ const iso = d.toISOString();
16
+ return `${iso.slice(0, 10)} ${iso.slice(11, 19)}`;
17
+ }
18
+
19
+ export function formatBytes(n: number | null | undefined): string {
20
+ if (n == null) return "";
21
+ if (n < 1024) return `${n} B`;
22
+ if (n < 1024 * 1024) return `${(n / 1024).toFixed(1)} KB`;
23
+ return `${(n / 1024 / 1024).toFixed(1)} MB`;
24
+ }
25
+
26
+ export function formatNum(n: number | null | undefined): string {
27
+ if (n == null) return "—";
28
+ if (Number.isInteger(n)) return String(n);
29
+ return n.toFixed(1);
30
+ }
@@ -0,0 +1,13 @@
1
+ /** Build a Set<"from→to"> of edges that were actually traversed, given an
2
+ * ordered list of visited node ids (GraphView derives this from GET
3
+ * /manifold/runs/:flowId/tree's items). Walks adjacent pairs in the
4
+ * history; the first transition is always __start__ → history[0]. */
5
+ export function buildTracedEdges(history: string[] | null | undefined): Set<string> {
6
+ const edges = new Set<string>();
7
+ if (!history || history.length === 0) return edges;
8
+ edges.add(`__start__→${history[0]}`);
9
+ for (let i = 1; i < history.length; i++) {
10
+ edges.add(`${history[i - 1]}→${history[i]}`);
11
+ }
12
+ return edges;
13
+ }
@@ -0,0 +1,154 @@
1
+ // Subflow-classification helpers used by the run-detail subflows card +
2
+ // the subflow parent's outcome indicator.
3
+ //
4
+ // `SubflowData` = an entry from `state.subflows[<groupId>][<subflowKey>]`.
5
+
6
+ import type { SubflowData, PipelineNode } from "@/api/types";
7
+
8
+ export interface SubflowOutcomeCounts {
9
+ total: number;
10
+ succeeded: number;
11
+ failed: number;
12
+ awaiting: number;
13
+ running: number;
14
+ /** Terminal-without-business-success: GATE rejected, SUBMIT_CODE
15
+ * blocked (infra-unavailable, already-sent dedup, etc.), or other
16
+ * silent skips. Used to be just `rejected` (GATE-only). */
17
+ skipped: number;
18
+ }
19
+
20
+ /** Sub-node data marker for "this step was a non-business skip" — used
21
+ * by subflowStatus + classifySubflows to distinguish silent terminals
22
+ * (GATE-rejected, infra-skip) from real successes. */
23
+ function subflowEndedAsSkip(data: Record<string, any>): boolean {
24
+ // GATE rejected → STAMP_REJECT sub-step ran
25
+ if (data.STAMP_REJECT) return true;
26
+ // GATE rejected (older shape without STAMP_REJECT capture)
27
+ if (data.GATE?.decision && data.GATE.decision !== "approve") return true;
28
+ // SUBMIT_CODE blocked: infra-unavailable, already-sent dedup, etc.
29
+ // (Operator-actionable blocks add `_error` which routes through
30
+ // failedAt above; only silent blocks reach this check.)
31
+ if (data.SUBMIT_CODE?.ok === false && data.SUBMIT_CODE?.error_type === "blocked") return true;
32
+ return false;
33
+ }
34
+
35
+ export function classifySubflows(parallelGroup?: Record<string, SubflowData>): SubflowOutcomeCounts {
36
+ const out: SubflowOutcomeCounts = { total: 0, succeeded: 0, failed: 0, awaiting: 0, running: 0, skipped: 0 };
37
+ if (!parallelGroup || typeof parallelGroup !== "object") return out;
38
+ for (const b of Object.values(parallelGroup)) {
39
+ if (!b) continue;
40
+ out.total++;
41
+ if (b.failedAt) { out.failed++; continue; }
42
+ if (b.awaiting) { out.awaiting++; continue; }
43
+ if (b.step !== "__end__") { out.running++; continue; }
44
+ const data = b.data ?? {};
45
+ let businessFail = false;
46
+ for (const d of Object.values(data)) {
47
+ if (!d || typeof d !== "object") continue;
48
+ if (d._error) { businessFail = true; break; }
49
+ if (d.ok === false) { businessFail = true; break; }
50
+ }
51
+ if (businessFail) { out.failed++; continue; }
52
+ if (subflowEndedAsSkip(data)) { out.skipped++; continue; }
53
+ out.succeeded++;
54
+ }
55
+ return out;
56
+ }
57
+
58
+ /** Map outcome counts to a CSS class on the cytoscape compound parent. */
59
+ export function subgraphOutcomeClass(c: SubflowOutcomeCounts): string {
60
+ if (!c || c.total === 0) return "group-untouched";
61
+ if (c.failed > 0) return "group-failed";
62
+ if (c.awaiting > 0) return "group-engaged";
63
+ if (c.running > 0) return "group-running";
64
+ return "group-primary-ok";
65
+ }
66
+
67
+ /** Comparable signature of a subflow's trajectory; same outcome at each step → same sig. */
68
+ export function pathSignature(subflow: SubflowData | null | undefined, subSteps: string[]): string {
69
+ if (!subflow) return "";
70
+ const parts: string[] = [];
71
+ for (const step of subSteps) {
72
+ const d = subflow.data?.[step];
73
+ if (d) {
74
+ if (d._error) parts.push(`${step}!`);
75
+ else if (step === "GATE" && d.decision && d.decision !== "approve") parts.push(`${step}✗`);
76
+ else if (step === "SUBMIT" && d.ok === false) parts.push(`${step}!`);
77
+ // SUBMIT_CODE blocked without _error = silent skip (infra,
78
+ // already-sent dedup). Mark with ⊘ to distinguish from real
79
+ // ok submissions on path histograms.
80
+ else if (step === "SUBMIT_CODE" && d.ok === false && d.error_type === "blocked") parts.push(`${step}⊘`);
81
+ else parts.push(step);
82
+ } else if (subflow.awaiting?.subNodeId === step) {
83
+ parts.push(`${step}⏳`);
84
+ }
85
+ }
86
+ return parts.join("|");
87
+ }
88
+
89
+ /** Subflow status label used in the table column + sort order.
90
+ * `skipped` = terminal-without-business-success (GATE rejected,
91
+ * SUBMIT_CODE blocked for infra-unavailable / already-sent / etc.). */
92
+ export type SubflowStatus = "failed" | "awaiting" | "running" | "done" | "skipped" | "unknown";
93
+
94
+ export function subflowStatus(b: SubflowData | null | undefined): SubflowStatus {
95
+ if (!b) return "unknown";
96
+ if (b.failedAt) return "failed";
97
+ if (b.awaiting) return "awaiting";
98
+ if (b.step !== "__end__") return "running";
99
+ // Terminal — distinguish business outcome from silent skip
100
+ if (subflowEndedAsSkip(b.data ?? {})) return "skipped";
101
+ return "done";
102
+ }
103
+
104
+ export function statusRank(b: SubflowData): number {
105
+ switch (subflowStatus(b)) {
106
+ case "failed": return 0;
107
+ case "awaiting": return 1;
108
+ case "running": return 2;
109
+ case "skipped": return 3;
110
+ case "done": return 4;
111
+ default: return 5;
112
+ }
113
+ }
114
+
115
+ /** Variant name to pass to <Badge variant=...>. */
116
+ export function badgeVariantForSubflow(status: SubflowStatus): "failed" | "waiting" | "running" | "succeeded" | "cancelled" {
117
+ if (status === "failed") return "failed";
118
+ if (status === "awaiting") return "waiting";
119
+ if (status === "running") return "running";
120
+ if (status === "done") return "succeeded";
121
+ if (status === "skipped") return "cancelled";
122
+ return "cancelled";
123
+ }
124
+
125
+ /**
126
+ * Infer sub-step topological order from a subflow node's flow
127
+ * definition, with a fallback to observed `subflow.step` values when the
128
+ * pipeline def isn't loaded (historical pipelines).
129
+ */
130
+ export function inferSubStepOrder(
131
+ pipelineNode: PipelineNode | undefined,
132
+ observedSubflows: SubflowData[]
133
+ ): string[] {
134
+ const edges = pipelineNode?.flow?.edges;
135
+ if (edges && edges.length) {
136
+ const order: string[] = [];
137
+ const seen = new Set<string>();
138
+ let cur = "__start__";
139
+ for (let i = 0; i < 20; i++) {
140
+ const outs = edges.filter((e) => e.from === cur).map((e) => e.to);
141
+ const next = outs.find((t) => t !== "__end__" && !seen.has(t));
142
+ if (!next) break;
143
+ seen.add(next);
144
+ order.push(next);
145
+ cur = next;
146
+ }
147
+ if (order.length) return order;
148
+ }
149
+ const seen = new Set<string>();
150
+ for (const b of observedSubflows) {
151
+ if (b?.step && b.step !== "__end__" && !seen.has(b.step)) seen.add(b.step);
152
+ }
153
+ return [...seen];
154
+ }
@@ -0,0 +1,28 @@
1
+ // Fires when a mousedown/touchstart lands outside the given element.
2
+ // Used by chart components to unpin the focused day when the operator
3
+ // taps anywhere else on the page. mousedown is preferred over click so
4
+ // the unpin happens before the next bar's own click handler resolves
5
+ // — avoids a flicker where pin → unpin → re-pin races on the same tap.
6
+
7
+ import { useEffect, type RefObject } from "react";
8
+
9
+ export function useClickOutside<T extends HTMLElement>(
10
+ ref: RefObject<T | null>,
11
+ onOutside: () => void,
12
+ ) {
13
+ useEffect(() => {
14
+ function handle(event: MouseEvent | TouchEvent) {
15
+ const node = ref.current;
16
+ const target = event.target;
17
+ if (!node || !(target instanceof Node)) return;
18
+ if (node.contains(target)) return;
19
+ onOutside();
20
+ }
21
+ document.addEventListener("mousedown", handle);
22
+ document.addEventListener("touchstart", handle);
23
+ return () => {
24
+ document.removeEventListener("mousedown", handle);
25
+ document.removeEventListener("touchstart", handle);
26
+ };
27
+ }, [ref, onOutside]);
28
+ }