@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,42 @@
1
+ // Hash-routed shell. Four views; no react-router needed — the routes are
2
+ // stable and tiny. `useHash()` watches `hashchange`; views mount/unmount on
3
+ // route change, which gives us free WS-subscription cleanup via React effects.
4
+
5
+ import { useEffect, useMemo, useState } from "react";
6
+ import { Layout } from "./components/Layout";
7
+ import { Home } from "./views/Home";
8
+ import { PipelinesList } from "./views/PipelinesList";
9
+ import { PipelineDetail } from "./views/PipelineDetail";
10
+ import { RunDetail } from "./views/RunDetail";
11
+ import { Search } from "./views/Search";
12
+ import { WsProvider } from "./api/ws";
13
+
14
+ function useHash(): string {
15
+ const [hash, setHash] = useState<string>(() => window.location.hash || "#/");
16
+ useEffect(() => {
17
+ const onHash = () => setHash(window.location.hash || "#/");
18
+ window.addEventListener("hashchange", onHash);
19
+ return () => window.removeEventListener("hashchange", onHash);
20
+ }, []);
21
+ return hash;
22
+ }
23
+
24
+ export default function App() {
25
+ const hash = useHash();
26
+
27
+ const view = useMemo(() => {
28
+ const m = hash.match(/^#\/runs\/([0-9a-f-]+)$/i);
29
+ if (m) return <RunDetail flowId={m[1]} />;
30
+ const p = hash.match(/^#\/pipelines\/(.+)$/);
31
+ if (p) return <PipelineDetail pipelineId={decodeURIComponent(p[1])} />;
32
+ if (hash.startsWith("#/pipelines")) return <PipelinesList />;
33
+ if (hash.startsWith("#/search")) return <Search />;
34
+ return <Home />;
35
+ }, [hash]);
36
+
37
+ return (
38
+ <WsProvider>
39
+ <Layout>{view}</Layout>
40
+ </WsProvider>
41
+ );
42
+ }
@@ -0,0 +1,118 @@
1
+ // Typed fetch wrappers for the dashboard's read-only HTTP API. The server
2
+ // is dashboard/server.js (mounted by manifold). All endpoints return JSON.
3
+
4
+ import type {
5
+ AllPipelinesCost,
6
+ ArtifactEntry,
7
+ FlowRunFull,
8
+ FlowRunSummary,
9
+ FlowTreeItem,
10
+ GlobalStats,
11
+ NodeStats,
12
+ Pipeline,
13
+ PipelineCost,
14
+ PipelineStats,
15
+ PipelineViews,
16
+ RunCompare,
17
+ RunCost,
18
+ SearchResponse,
19
+ LiveEvent,
20
+ SubflowData,
21
+ Transcript,
22
+ } from "./types";
23
+
24
+ // vite sets BASE_URL to the configured base (with trailing slash). All API
25
+ // paths are prefixed so the dashboard works both at `/` locally and at
26
+ // `/graph/` behind the tailscale proxy without rebuilding per env.
27
+ const API = `${import.meta.env.BASE_URL}api`;
28
+
29
+ async function json<T>(url: string): Promise<T> {
30
+ const r = await fetch(url);
31
+ if (!r.ok) throw new Error(`${url}: HTTP ${r.status}`);
32
+ return r.json() as Promise<T>;
33
+ }
34
+
35
+ async function postJson<T>(url: string, body: unknown): Promise<T> {
36
+ const r = await fetch(url, {
37
+ method: "POST",
38
+ headers: { "Content-Type": "application/json" },
39
+ body: JSON.stringify(body),
40
+ });
41
+ const payload = await r.json().catch(() => ({} as Record<string, unknown>));
42
+ if (!r.ok) {
43
+ const errMsg = typeof (payload as { error?: unknown })?.error === "string"
44
+ ? (payload as { error: string }).error
45
+ : `HTTP ${r.status}`;
46
+ throw new Error(`${url}: ${errMsg}`);
47
+ }
48
+ return payload as T;
49
+ }
50
+
51
+ export const api = {
52
+ pipelines: () => json<Pipeline[]>(`${API}/pipelines`),
53
+ pipeline: (id: string) => json<Pipeline>(`${API}/pipelines/${encodeURIComponent(id)}`),
54
+ runs: (filters: { status?: string; pipelineId?: string; limit?: number; since?: number; until?: number } = {}) => {
55
+ const q = new URLSearchParams();
56
+ if (filters.status) q.set("status", filters.status);
57
+ if (filters.pipelineId) q.set("pipelineId", filters.pipelineId);
58
+ if (filters.limit) q.set("limit", String(filters.limit));
59
+ if (filters.since != null) q.set("since", String(filters.since));
60
+ if (filters.until != null) q.set("until", String(filters.until));
61
+ return json<FlowRunSummary[]>(`${API}/runs?${q.toString()}`);
62
+ },
63
+ run: (flowId: string) => json<FlowRunFull>(`${API}/runs/${flowId}`),
64
+ runEvents: (flowId: string) => json<LiveEvent[]>(`${API}/runs/${flowId}/events`),
65
+ runArtifacts: (flowId: string) => json<ArtifactEntry[]>(`${API}/runs/${flowId}/artifacts`),
66
+ runTranscripts:(flowId: string) => json<Transcript[]>(`${API}/runs/${flowId}/transcripts`),
67
+ runCompare: (flowId: string) => json<RunCompare | null>(`${API}/runs/${flowId}/compare`),
68
+ runSubflows: (flowId: string) => json<Record<string, Record<string, SubflowData>>>(`${API}/runs/${flowId}/subflows`),
69
+ runTree: (flowId: string) => json<{ items: FlowTreeItem[] }>(`${API}/runs/${flowId}/tree`),
70
+ stats: () => json<GlobalStats>(`${API}/stats`),
71
+ pipelineStats: (id: string) => json<PipelineStats>(`${API}/stats/pipelines/${encodeURIComponent(id)}`),
72
+ pipelineNodeStats: (pipelineId: string, nodeId: string) =>
73
+ json<NodeStats>(`${API}/pipelines/${encodeURIComponent(pipelineId)}/nodes/${encodeURIComponent(nodeId)}/stats`),
74
+ // `status` is a structured equality filter applied before the
75
+ // free-text match; q can be empty when status alone is enough.
76
+ search: (q: string, opts: { limit?: number; status?: string } = {}) => {
77
+ const limit = opts.limit ?? 50;
78
+ const qp = new URLSearchParams();
79
+ if (q) qp.set("q", q);
80
+ if (opts.status) qp.set("status", opts.status);
81
+ qp.set("limit", String(limit));
82
+ return json<SearchResponse>(`${API}/search?${qp.toString()}`);
83
+ },
84
+ runCost: (flowId: string) => json<RunCost>(`${API}/runs/${flowId}/cost`),
85
+ pipelineCost: (pipelineId: string, sinceDays = 30) =>
86
+ json<PipelineCost>(`${API}/stats/pipelines/${encodeURIComponent(pipelineId)}/cost?sinceDays=${sinceDays}`),
87
+ allPipelinesCost: (sinceDays = 30) =>
88
+ json<AllPipelinesCost>(`${API}/stats/cost?sinceDays=${sinceDays}`),
89
+ // Pipeline-declared dashboard views — each entry is the computed
90
+ // payload for one `views[]` declaration. Empty `views` array when
91
+ // the pipeline declares none; caller skips rendering.
92
+ pipelineViews: (pipelineId: string, sinceDays = 30) =>
93
+ json<PipelineViews>(`${API}/stats/pipelines/${encodeURIComponent(pipelineId)}/views?sinceDays=${sinceDays}`),
94
+
95
+ approve: (flowId: string, body: { itemId: string; decision: "approve" | "reject" | "edit"; text?: string }) =>
96
+ postJson<{ decision: string; itemId: string; stillPending: number; status: "blocked" | "resumed" }>(
97
+ `${API}/runs/${flowId}/approve`,
98
+ body,
99
+ ),
100
+
101
+ cancel: (flowId: string) =>
102
+ postJson<{ cancelled: true; wasStatus: string }>(`${API}/runs/${flowId}/cancel`, {}),
103
+
104
+ rerun: (sourceFlowId: string, body: { args?: Record<string, unknown> } = {}) =>
105
+ postJson<{ flowId: string; pipelineId: string | null; rerunOf: string }>(
106
+ `${API}/runs/${sourceFlowId}/rerun`,
107
+ body,
108
+ ),
109
+
110
+ respond: (flowId: string, text: string) =>
111
+ postJson<{ responded: true; nodeId: string; status: "resumed" }>(
112
+ `${API}/runs/${flowId}/respond`,
113
+ { text },
114
+ ),
115
+ };
116
+
117
+ export const artifactUrl = (flowId: string, name: string) =>
118
+ `${API}/runs/${flowId}/artifacts/${encodeURIComponent(name)}`;
@@ -0,0 +1,510 @@
1
+ // Type definitions for the API surface exposed by dashboard/server.js.
2
+ // These mirror what server.js + pipeline-graph.js + stats.js produce.
3
+ // Kept loose where the backend is loose (optional fields, unknown JSON state).
4
+
5
+ // ─── Pipeline definitions (from /api/pipelines/:id) ──────────────────────────
6
+
7
+ export type NodeKind =
8
+ | "start"
9
+ | "end"
10
+ | "code"
11
+ | "agent"
12
+ | "subflow"
13
+ | "human-gate";
14
+
15
+ export interface PipelineNode {
16
+ id: string;
17
+ kind: NodeKind | string;
18
+ agent?: string;
19
+ groupId?: string;
20
+ concurrency?: number;
21
+ waitKind?: string;
22
+ /** For subflow nodes, the inner flow pipeline. */
23
+ flow?: FlowTopology;
24
+ }
25
+
26
+ export interface FlowTopology {
27
+ parentNodeId: string;
28
+ groupId: string;
29
+ nodes: PipelineNode[];
30
+ edges: PipelineEdge[];
31
+ }
32
+
33
+ export interface PipelineEdge {
34
+ from: string;
35
+ to: string;
36
+ conditional: boolean;
37
+ /** Source text of the conditional edge function (truncated by the serializer). */
38
+ via?: string;
39
+ }
40
+
41
+ export interface PipelineGroup {
42
+ label?: string;
43
+ kind?: string;
44
+ members: string[];
45
+ }
46
+
47
+ export interface Pipeline {
48
+ id: string;
49
+ goal: string | null;
50
+ file: string | null;
51
+ dir: string | null;
52
+ nodes: PipelineNode[];
53
+ edges: PipelineEdge[];
54
+ groups: Record<string, PipelineGroup> | null;
55
+ /** Marker for /api/pipelines list — populated only when the pipeline def is gone but runs remain. */
56
+ historical?: boolean;
57
+ runs?: number;
58
+ }
59
+
60
+ // ─── Flow runs (from /api/runs and /api/runs/:flowId) ───────────────────────
61
+
62
+ // "waiting" is never actually written anywhere (confirmed repo-wide) — gate
63
+ // pauses are always persisted as "blocked".
64
+ export type RunStatus = "running" | "blocked" | "succeeded" | "failed" | "cancelled" | "skipped" | string;
65
+
66
+ export interface ParallelGroupSummary {
67
+ groupId: string;
68
+ total: number;
69
+ done: number;
70
+ failed: number;
71
+ awaiting: number;
72
+ running: number;
73
+ }
74
+
75
+ export interface FlowRunSummary {
76
+ flowId: string;
77
+ pipelineId: string | null;
78
+ runId: string | null;
79
+ status: RunStatus;
80
+ lastStep: string | null;
81
+ currentStep: string | null;
82
+ revision: number;
83
+ statusReason: string | null;
84
+ waitKind: string | null;
85
+ createdAt: number | null;
86
+ updatedAt: number | null;
87
+ endedAt: number | null;
88
+ errorsCount: number;
89
+ subflows: ParallelGroupSummary[] | null;
90
+ }
91
+
92
+ export interface WaitJson {
93
+ kind?: string;
94
+ nodeId?: string;
95
+ reason?: string;
96
+ needed?: string[];
97
+ hint?: string;
98
+ /**
99
+ * Pending entries are either raw string ids ("listing-123") or objects
100
+ * with at least `.id` (e.g. `{ id: "listing-123", reason: "approve to ship" }`).
101
+ * The GateForm handles both shapes; the type stays loose.
102
+ */
103
+ pending?: (string | { id: string; reason?: string; hint?: string; [k: string]: unknown })[];
104
+ items?: unknown[];
105
+ /**
106
+ * Optional opt-in, generic across wait kinds: a node's `blockedInfo.choices`
107
+ * is passed through verbatim onto `waitJson.choices` by the executor
108
+ * (see engine/executor.js). Each entry is a label a pipeline author can
109
+ * offer as a fixed response option. No dashboard component currently
110
+ * renders this — it's plumbed through as API surface for future use.
111
+ */
112
+ choices?: string[];
113
+ }
114
+
115
+ /**
116
+ * Canonical error-record shape shared across every consumer — SQL row
117
+ * (flow_node_executions), JSON wire response, this TS type, and client
118
+ * structs all use the same field set. Replaces the old per-field
119
+ * inconsistency (SubflowData.errors was typed string[] but the real wire
120
+ * payload could contain objects — that mistyping is what caused
121
+ * SubflowsCard.tsx's .slice() crash; RunState.errors was typed
122
+ * {node?,message?}[], a third, different shape).
123
+ */
124
+ export interface ErrorEntry {
125
+ nodeId: string;
126
+ /** null = root-level (flow) error; set = subflow sub-node error — both live in flow_node_executions now. */
127
+ subflowKey: string | null;
128
+ message: string;
129
+ at: number;
130
+ }
131
+
132
+ export interface SubflowData {
133
+ /** Subflow's most recently consumed sub-step. `__end__` when terminal. */
134
+ step?: string;
135
+ /** Per-sub-step outputs. Keys are sub-node ids (e.g. DRAFT, GATE, STAMP, SUBMIT). */
136
+ data?: Record<string, SubflowStepResult | undefined>;
137
+ /** Normalized error history sourced from flow_node_executions. */
138
+ errorEntries?: ErrorEntry[];
139
+ failedAt?: number;
140
+ doneAt?: number;
141
+ awaiting?: { subNodeId: string; requestPayload?: unknown; requestedAt?: number };
142
+ updatedAt?: number;
143
+ }
144
+
145
+ export interface SubflowStepResult {
146
+ _error?: string;
147
+ ok?: boolean;
148
+ decision?: string;
149
+ [key: string]: unknown;
150
+ }
151
+
152
+ /** One row from GET /manifold/runs/:flowId/tree (routes/runs.js's buildTreeNodeRows)
153
+ * — one per top-level (subflow_key IS NULL) invocation, ordered by invokedAt.
154
+ * Backs PathTrail/GraphView's executed-path rendering (SUBFLOW_PARENT_STATE_
155
+ * ACCESS.design.md's Phase 3b), replacing stateJson._stepHistory as the source. */
156
+ export interface FlowTreeItem {
157
+ type: "node";
158
+ invocationId: string;
159
+ nodeId: string;
160
+ kind: string | null;
161
+ agent: string | null;
162
+ status: RunStatus;
163
+ enteredAt: number | null;
164
+ exitedAt: number | null;
165
+ execKind: string | null;
166
+ executionCount: number;
167
+ everRetriedOrRevived: boolean;
168
+ hasChildren: boolean;
169
+ rollup?: { succeeded: number; failed: number; pending: number; skipped: number; cancelled: number };
170
+ }
171
+
172
+ export interface RunState {
173
+ pipelineId?: string;
174
+ runId?: string;
175
+ startedAt?: number;
176
+ endedAt?: number;
177
+ args?: Record<string, unknown>;
178
+ subflows?: Record<string, Record<string, SubflowData>>;
179
+ [key: string]: unknown;
180
+ }
181
+
182
+ export interface FlowRunFull {
183
+ flowId: string;
184
+ pipelineId: string | null;
185
+ runId: string | null;
186
+ status: RunStatus;
187
+ lastStep: string | null;
188
+ currentStep: string | null;
189
+ revision: number;
190
+ statusReason: string | null;
191
+ stateJson: RunState;
192
+ waitJson: WaitJson | null;
193
+ /** Phase 1.5: normalized error history sourced from flow_node_executions, sibling to stateJson (not nested — keeps flow-level and subflow-level shapes symmetric). */
194
+ errorEntries?: ErrorEntry[];
195
+ createdAt: number | null;
196
+ updatedAt: number | null;
197
+ endedAt: number | null;
198
+ }
199
+
200
+ // ─── Stats (from /api/stats and /api/stats/pipelines/:id) ────────────────────
201
+
202
+ export interface DurationStats {
203
+ n: number;
204
+ p50Ms: number | null;
205
+ p95Ms: number | null;
206
+ meanMs: number | null;
207
+ }
208
+
209
+ export interface RevisionStats {
210
+ n: number;
211
+ p50: number | null;
212
+ p95: number | null;
213
+ }
214
+
215
+ export interface PerDayBucket {
216
+ day: string;
217
+ total: number;
218
+ succeeded: number;
219
+ failed: number;
220
+ cancelled: number;
221
+ }
222
+
223
+ export interface HistogramEntry {
224
+ key: string;
225
+ /** Pipeline owning this cluster — only useful at the global overview, where the same step name can collide across pipelines. */
226
+ pipelineId?: string;
227
+ count: number;
228
+ /** Median block-time (run creation → terminal failure) for runs ending at this step. Null when block-time signal is missing. */
229
+ p50BlockMs?: number | null;
230
+ /** count × p50BlockMs — total operator-impact ranked unit. 0 when no block-time. */
231
+ impactMs?: number;
232
+ /** Timestamp of most recent failure in this cluster — drives the recency tone (today red / 7d amber / older dim). */
233
+ lastFailedAt?: number | null;
234
+ /** Failure count per day across a fixed window (default 14d). Aligned across all clusters so the sparkline canvases match. */
235
+ perDay?: { day: string; count: number }[];
236
+ /** Per-error breakdown inside this (pipeline, step) cluster. Different signatures stack as sub-rows in the tap-to-expand detail instead of duplicating top-level rows. Sorted by recency desc. */
237
+ errors?: {
238
+ signature: string;
239
+ count: number;
240
+ lastFailedAt: number | null;
241
+ exemplarMessage: string | null;
242
+ recentRuns: { flowId: string; status: string; at: number }[];
243
+ }[];
244
+ }
245
+
246
+ export interface PipelineBreakdownEntry {
247
+ pipelineId: string;
248
+ total: number;
249
+ succeeded: number;
250
+ failed: number;
251
+ cancelled: number;
252
+ active: number;
253
+ }
254
+
255
+ export interface GlobalStats {
256
+ total: number;
257
+ statusCounts: Record<string, number>;
258
+ succeeded: number;
259
+ failed: number;
260
+ cancelled: number;
261
+ active: number;
262
+ terminated: number;
263
+ successRate: number | null;
264
+ duration: DurationStats;
265
+ perDay: PerDayBucket[];
266
+ failureStops: HistogramEntry[];
267
+ pipelineBreakdown: PipelineBreakdownEntry[];
268
+ }
269
+
270
+ // ─── Declared dashboard views (from /api/stats/pipelines/:id/views) ─────────
271
+ // Each pipeline can declare an array of opt-in surfaces; the dashboard
272
+ // dispatches on `kind`. Unit + meaning are per-view-kind.
273
+
274
+ export interface DeclaredViewFunnelStage {
275
+ id: string;
276
+ label: string;
277
+ count: number;
278
+ conversionFromPrev: number | null;
279
+ conversionFromStart?: number;
280
+ }
281
+
282
+ export interface DeclaredViewFunnel {
283
+ id: string;
284
+ kind: "funnel";
285
+ label: string;
286
+ sinceMs: number | null;
287
+ total: number;
288
+ funnel: DeclaredViewFunnelStage[];
289
+ /** Per-`outcome` distribution when the underlying source carried an `outcome` field (frontmatter-dir source). Omitted otherwise. */
290
+ byOutcome?: Record<string, number>;
291
+ error?: string;
292
+ }
293
+
294
+ export interface DeclaredViewUnknown {
295
+ id: string;
296
+ kind: string;
297
+ label: string;
298
+ sinceMs: number | null;
299
+ error?: string;
300
+ }
301
+
302
+ export type DeclaredView = DeclaredViewFunnel | DeclaredViewUnknown;
303
+
304
+ export interface PipelineViews {
305
+ sinceMs: number | null;
306
+ views: DeclaredView[];
307
+ }
308
+
309
+ export interface FunnelStage {
310
+ id: string;
311
+ label: string;
312
+ key?: string;
313
+ n: number;
314
+ total: number;
315
+ p50: number | null;
316
+ /** 95th percentile per-run yield at this stage — pairs with `min` to surface variance the p50 hides. */
317
+ p95: number | null;
318
+ /** Minimum per-run yield — non-zero days are noise; a 0 here is "the funnel ran dry on at least one run." */
319
+ min: number | null;
320
+ mean: number | null;
321
+ conversionFromPrev?: number | null;
322
+ conversionFromStart?: number | null;
323
+ /** Per-subflow attrition funnel — present when the stage's underlying node is a subflow parent. */
324
+ subStages?: FunnelStage[];
325
+ }
326
+
327
+ export interface PipelineStats {
328
+ pipelineId: string;
329
+ /** Status breakdown for runs whose updatedAt landed in the last 24h. Feeds the per-pipeline TodayStrip. */
330
+ recent24h: { total: number; ok: number; failed: number; active: number };
331
+ total: number;
332
+ statusCounts: Record<string, number>;
333
+ succeeded: number;
334
+ failed: number;
335
+ cancelled: number;
336
+ terminated: number;
337
+ successRate: number | null;
338
+ duration: DurationStats;
339
+ revision: RevisionStats;
340
+ failureStops: HistogramEntry[];
341
+ funnel: FunnelStage[] | null;
342
+ recentRuns: unknown[];
343
+ }
344
+
345
+ export interface SearchMatch {
346
+ /** Where the hit lives: "flowId", "statusReason", "state.errors[2].message", "state.shortlist", … */
347
+ field: string;
348
+ /** ±~40 chars around the first token match, with `…` ellipses + whitespace collapsed. */
349
+ snippet: string;
350
+ /** Offset of the first token's first occurrence in the matched field's full text. */
351
+ matchedAt: number;
352
+ }
353
+
354
+ export interface SearchHit {
355
+ flowId: string;
356
+ pipelineId: string | null;
357
+ status: RunStatus;
358
+ lastStep: string | null;
359
+ currentStep: string | null;
360
+ updatedAt: number | null;
361
+ revision: number;
362
+ matches: SearchMatch[];
363
+ }
364
+
365
+ export interface SearchResponse {
366
+ query: string;
367
+ totalHits: number;
368
+ hits: SearchHit[];
369
+ truncated: boolean;
370
+ }
371
+
372
+ export interface RunCostNodeEntry {
373
+ cost: number;
374
+ durationMs: number;
375
+ calls: number;
376
+ }
377
+
378
+ export interface RunCost {
379
+ flowId: string;
380
+ total: number;
381
+ tokens: { input: number; output: number; cacheRead: number; cacheWrite: number };
382
+ byModel: Record<string, number>;
383
+ byNode: Record<string, RunCostNodeEntry>;
384
+ bySession: { session: string; agent: string; nodeId: string; itemKey: string | null; models: string[]; total: number; turns: number; durationMs: number }[];
385
+ }
386
+
387
+ export interface PipelineCostNodeEntry {
388
+ cost: number;
389
+ calls: number;
390
+ p50Ms: number | null;
391
+ p95Ms: number | null;
392
+ meanMs: number | null;
393
+ /** Median per-call cost. Null when no cost-bearing calls. */
394
+ p50Cost: number | null;
395
+ /** 95th percentile per-call cost — surfaces the runaway turn the mean hides. */
396
+ p95Cost: number | null;
397
+ /** Per-day rollup for the row-expansion sparkline. cost / ms are sums; p50Cost / p50Ms are per-call medians for that day; calls is the call count. */
398
+ perDay: { day: string; cost: number; calls: number; ms: number; p50Cost: number | null; p50Ms: number | null }[];
399
+ }
400
+
401
+ export interface PipelineCost {
402
+ pipelineId: string;
403
+ runs: number;
404
+ succeeded: number;
405
+ total: number;
406
+ mean: number;
407
+ /** 95th percentile of per-run cost — surfaces runaway runs the mean hides. */
408
+ p95: number | null;
409
+ /** Total spend ÷ count of succeeded runs. Null until at least one run has succeeded — the load-bearing ROI signal. */
410
+ costPerSuccess: number | null;
411
+ /** costPerSuccess over the same-length window immediately prior — for the trend delta. Null when no prior-window data. */
412
+ costPerSuccessPrior: number | null;
413
+ byModel: Record<string, number>;
414
+ byNode: Record<string, PipelineCostNodeEntry>;
415
+ perDay: { day: string; cost: number; runs: number; p50Cost: number | null; p50Ms: number | null; p95Ms: number | null }[];
416
+ since: number | null;
417
+ until: number | null;
418
+ perRun: { flowId: string; status: string; updatedAt: number | null; cost: number }[];
419
+ }
420
+
421
+ export interface AllPipelinesCostEntry {
422
+ pipelineId: string;
423
+ runs: number;
424
+ succeeded: number;
425
+ total: number;
426
+ costPerSuccess: number | null;
427
+ lastUpdatedAt: number;
428
+ /** Mean per-run spend. Null when no cost-bearing runs in the window. */
429
+ meanCost: number | null;
430
+ /** p50 / p95 of per-run cost — surfaces the runaway-run tail that the mean hides. */
431
+ p50Cost: number | null;
432
+ p95Cost: number | null;
433
+ /** Mean / p50 / p95 of per-run wall time. */
434
+ meanMs: number | null;
435
+ p50Ms: number | null;
436
+ p95Ms: number | null;
437
+ /** Per-day rollup — cost / runs / ms sums plus per-day p50 of the samples for the chart's p50 toggle. */
438
+ perDay: { day: string; cost: number; runs: number; ms: number; p50Cost: number | null; p50Ms: number | null }[];
439
+ }
440
+
441
+ export interface AllPipelinesCost {
442
+ sinceMs: number | null;
443
+ pipelines: AllPipelinesCostEntry[];
444
+ /** Cross-pipeline rollup for the overview tiles + portfolio-wide daily trend charts. Percentiles are over the union of run-level samples (NOT per-pipeline percentiles averaged). */
445
+ total: {
446
+ spend: number;
447
+ runs: number;
448
+ succeeded: number;
449
+ mean: number | null;
450
+ p50Cost: number | null;
451
+ p95Cost: number | null;
452
+ meanMs: number | null;
453
+ p50Ms: number | null;
454
+ p95Ms: number | null;
455
+ costPerSuccess: number | null;
456
+ perDay: { day: string; cost: number; runs: number; ms: number; p50Cost: number | null; p50Ms: number | null; p95Ms: number | null }[];
457
+ };
458
+ }
459
+
460
+ export interface NodeStats {
461
+ pipelineId: string;
462
+ nodeId: string;
463
+ visits: number;
464
+ failedHere: number;
465
+ blockedHere: number;
466
+ terminatedHere: number;
467
+ recentRuns: { flowId: string; status: string; lastStep: string | null; currentStep: string | null; updatedAt: number | null; revision: number }[];
468
+ totalRuns: number;
469
+ }
470
+
471
+ export interface RunCompare {
472
+ peerCount: number;
473
+ durationMs: number | null;
474
+ durationMedianMs: number | null;
475
+ durationRatio: number | null;
476
+ revision: number;
477
+ revisionMedian: number | null;
478
+ }
479
+
480
+ // ─── Live events (WS /api/events/ws + REST run history) ──────────────────────
481
+
482
+ export type LiveEvent =
483
+ | { kind: "run.created"; flowId: string; at: number; status: RunStatus; lastStep: string | null; currentStep: string | null; pipelineId: string | null }
484
+ | { kind: "run.updated"; flowId: string; at: number; prevStatus: RunStatus; currStatus: RunStatus; prevStep: string | null; currStep: string | null; revision: number; stateKeysAdded: string[]; stateKeysRemoved: string[]; waitKind: string | null }
485
+ | { kind: "run.ended"; flowId: string; at: number; status: RunStatus }
486
+ | { kind: "pipeline.catalog.updated"; at: number; size: number; ids: string[] };
487
+
488
+ export interface ArtifactEntry {
489
+ name: string;
490
+ size: number;
491
+ mtime: number;
492
+ }
493
+
494
+ export interface TranscriptTurn {
495
+ role: "user" | "assistant";
496
+ text: string;
497
+ thinking: string | null;
498
+ truncated: boolean;
499
+ timestamp: string | null;
500
+ }
501
+
502
+ export interface Transcript {
503
+ session: string;
504
+ agent: string;
505
+ nodeId: string;
506
+ itemKey: string | null;
507
+ startedAt: number | null;
508
+ updatedAt: number | null;
509
+ turns: TranscriptTurn[];
510
+ }