@jive-sh/workflow-platform 0.7.0 → 1.1.0

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 (195) hide show
  1. package/README.md +70 -435
  2. package/component/_generated/api.ts +72 -0
  3. package/component/_generated/component.ts +629 -0
  4. package/component/_generated/dataModel.ts +60 -0
  5. package/component/_generated/server.ts +169 -0
  6. package/component/convex.config.ts +3 -0
  7. package/component/engine.ts +756 -0
  8. package/component/errors.ts +66 -0
  9. package/component/events.ts +17 -0
  10. package/component/notes.ts +19 -0
  11. package/component/places.ts +136 -0
  12. package/component/retention.ts +205 -0
  13. package/component/runEngine.ts +25 -0
  14. package/component/schema.ts +135 -0
  15. package/component/steps.ts +188 -0
  16. package/component/store.ts +513 -0
  17. package/component/tasks.ts +290 -0
  18. package/component/worker.ts +109 -0
  19. package/component/workflows.ts +83 -0
  20. package/dist/definition/agent-runner.js +9 -0
  21. package/dist/definition/agent-runner.js.map +1 -0
  22. package/dist/definition/file-store.js +9 -0
  23. package/dist/definition/file-store.js.map +1 -0
  24. package/dist/definition/program-build.js +10 -0
  25. package/dist/definition/program-build.js.map +1 -0
  26. package/dist/definition/step.js +1 -0
  27. package/dist/definition/step.js.map +1 -0
  28. package/dist/definition/task-schema.js +5 -0
  29. package/dist/definition/task-schema.js.map +1 -0
  30. package/dist/definition/tasks.js +9 -0
  31. package/dist/definition/tasks.js.map +1 -0
  32. package/dist/definition/workflow.js +117 -0
  33. package/dist/definition/workflow.js.map +1 -0
  34. package/dist/graph.js +310 -9
  35. package/dist/graph.js.map +1 -1
  36. package/dist/index.js +7 -196
  37. package/dist/index.js.map +1 -1
  38. package/package.json +9 -4
  39. package/src/definition/agent-runner.ts +59 -0
  40. package/src/definition/file-store.ts +20 -0
  41. package/src/definition/program-build.ts +30 -0
  42. package/src/definition/step.ts +106 -0
  43. package/src/definition/task-schema.ts +15 -0
  44. package/src/definition/tasks.ts +43 -0
  45. package/src/definition/workflow.ts +262 -0
  46. package/src/graph.ts +352 -19
  47. package/src/index.ts +8 -238
  48. package/worker/directory-file-store.ts +42 -0
  49. package/worker/index.ts +12 -0
  50. package/worker/platform-client.ts +144 -0
  51. package/worker/step-meter.ts +80 -0
  52. package/worker/worker-tasks.ts +27 -0
  53. package/worker/worker.test.ts +200 -0
  54. package/worker/worker.ts +240 -0
  55. package/dist/budget-states.js +0 -30
  56. package/dist/budget-states.js.map +0 -1
  57. package/dist/cpu-limit/limiter.js +0 -839
  58. package/dist/cpu-limit/limiter.js.map +0 -1
  59. package/dist/cpu-limit/use.js +0 -139
  60. package/dist/cpu-limit/use.js.map +0 -1
  61. package/dist/dashboard/agent-usage.js +0 -25
  62. package/dist/dashboard/agent-usage.js.map +0 -1
  63. package/dist/dashboard/dashboard.css +0 -148
  64. package/dist/dashboard/drilldown.js +0 -47
  65. package/dist/dashboard/drilldown.js.map +0 -1
  66. package/dist/dashboard/queue-lines.js +0 -44
  67. package/dist/dashboard/queue-lines.js.map +0 -1
  68. package/dist/dashboard/queue-table.js +0 -16
  69. package/dist/dashboard/queue-table.js.map +0 -1
  70. package/dist/dashboard/run-doing-words.js +0 -29
  71. package/dist/dashboard/run-doing-words.js.map +0 -1
  72. package/dist/dashboard/setting-words.js +0 -18
  73. package/dist/dashboard/setting-words.js.map +0 -1
  74. package/dist/dashboard/spending-words.js +0 -24
  75. package/dist/dashboard/spending-words.js.map +0 -1
  76. package/dist/failure.js +0 -35
  77. package/dist/failure.js.map +0 -1
  78. package/dist/keep-running.js +0 -79
  79. package/dist/keep-running.js.map +0 -1
  80. package/dist/outside-failure.js +0 -31
  81. package/dist/outside-failure.js.map +0 -1
  82. package/dist/pick-wakes.js +0 -125
  83. package/dist/pick-wakes.js.map +0 -1
  84. package/dist/project.js +0 -1
  85. package/dist/project.js.map +0 -1
  86. package/dist/queue-counts.js +0 -51
  87. package/dist/queue-counts.js.map +0 -1
  88. package/dist/reasons.js +0 -33
  89. package/dist/reasons.js.map +0 -1
  90. package/dist/retention.js +0 -59
  91. package/dist/retention.js.map +0 -1
  92. package/dist/settings.js +0 -88
  93. package/dist/settings.js.map +0 -1
  94. package/dist/spending-limit.js +0 -82
  95. package/dist/spending-limit.js.map +0 -1
  96. package/dist/step-files.js +0 -200
  97. package/dist/step-files.js.map +0 -1
  98. package/dist/step-meter.js +0 -97
  99. package/dist/step-meter.js.map +0 -1
  100. package/dist/step-times.js +0 -114
  101. package/dist/step-times.js.map +0 -1
  102. package/dist/step-usage.js +0 -19
  103. package/dist/step-usage.js.map +0 -1
  104. package/dist/steps.js +0 -1205
  105. package/dist/steps.js.map +0 -1
  106. package/dist/storage/agent-claims.js +0 -3
  107. package/dist/storage/agent-claims.js.map +0 -1
  108. package/dist/storage/budgets.js +0 -121
  109. package/dist/storage/budgets.js.map +0 -1
  110. package/dist/storage/engine-records.js +0 -91
  111. package/dist/storage/engine-records.js.map +0 -1
  112. package/dist/storage/engine-storage.js +0 -67
  113. package/dist/storage/engine-storage.js.map +0 -1
  114. package/dist/storage/input-records.js +0 -12
  115. package/dist/storage/input-records.js.map +0 -1
  116. package/dist/storage/move-store.js +0 -251
  117. package/dist/storage/move-store.js.map +0 -1
  118. package/dist/storage/sqlite-store.js +0 -901
  119. package/dist/storage/sqlite-store.js.map +0 -1
  120. package/dist/storage/step-records.js +0 -11
  121. package/dist/storage/step-records.js.map +0 -1
  122. package/dist/storage/storage-error.js +0 -19
  123. package/dist/storage/storage-error.js.map +0 -1
  124. package/dist/storage/task-store.js +0 -30
  125. package/dist/storage/task-store.js.map +0 -1
  126. package/dist/system-workflows.js +0 -54
  127. package/dist/system-workflows.js.map +0 -1
  128. package/dist/tasks.js +0 -500
  129. package/dist/tasks.js.map +0 -1
  130. package/dist/views/format.js +0 -37
  131. package/dist/views/format.js.map +0 -1
  132. package/dist/views/runs-now.js +0 -117
  133. package/dist/views/runs-now.js.map +0 -1
  134. package/dist/views/step-funnel.js +0 -98
  135. package/dist/views/step-funnel.js.map +0 -1
  136. package/dist/views/step-graph.js +0 -39
  137. package/dist/views/step-graph.js.map +0 -1
  138. package/dist/views/workflows-view.js +0 -236
  139. package/dist/views/workflows-view.js.map +0 -1
  140. package/src/budget-states.ts +0 -54
  141. package/src/cpu-limit/limiter.ts +0 -935
  142. package/src/cpu-limit/use.ts +0 -166
  143. package/src/dashboard/agent-usage-line.tsx +0 -28
  144. package/src/dashboard/agent-usage.ts +0 -48
  145. package/src/dashboard/dashboard.css +0 -148
  146. package/src/dashboard/drilldown.ts +0 -70
  147. package/src/dashboard/index.tsx +0 -4
  148. package/src/dashboard/limits-and-runs.tsx +0 -191
  149. package/src/dashboard/machine-controls.tsx +0 -53
  150. package/src/dashboard/queue-bar.tsx +0 -62
  151. package/src/dashboard/queue-chart.tsx +0 -149
  152. package/src/dashboard/queue-lines.ts +0 -87
  153. package/src/dashboard/queue-table.ts +0 -37
  154. package/src/dashboard/run-doing-words.ts +0 -41
  155. package/src/dashboard/setting-words.ts +0 -30
  156. package/src/dashboard/spending-limit-control.tsx +0 -47
  157. package/src/dashboard/spending-words.ts +0 -32
  158. package/src/dashboard/time-distribution.tsx +0 -61
  159. package/src/dashboard/workflow-dag.tsx +0 -322
  160. package/src/dashboard/workflow-drilldown.tsx +0 -31
  161. package/src/dashboard/workflows-dashboard.tsx +0 -532
  162. package/src/failure.ts +0 -36
  163. package/src/keep-running.ts +0 -85
  164. package/src/outside-failure.ts +0 -39
  165. package/src/pick-wakes.ts +0 -182
  166. package/src/project.ts +0 -127
  167. package/src/queue-counts.ts +0 -64
  168. package/src/reasons.ts +0 -30
  169. package/src/retention.ts +0 -90
  170. package/src/settings.ts +0 -171
  171. package/src/spending-limit.ts +0 -139
  172. package/src/step-files.ts +0 -208
  173. package/src/step-meter.ts +0 -120
  174. package/src/step-times.ts +0 -151
  175. package/src/step-usage.ts +0 -23
  176. package/src/steps.ts +0 -1616
  177. package/src/storage/agent-claims.ts +0 -63
  178. package/src/storage/budgets.ts +0 -152
  179. package/src/storage/engine-records.ts +0 -119
  180. package/src/storage/engine-storage.ts +0 -82
  181. package/src/storage/input-records.ts +0 -43
  182. package/src/storage/move-store.ts +0 -265
  183. package/src/storage/sqlite-store.ts +0 -1022
  184. package/src/storage/step-records.ts +0 -358
  185. package/src/storage/storage-error.ts +0 -35
  186. package/src/storage/task-store.ts +0 -235
  187. package/src/system-workflows.ts +0 -70
  188. package/src/tasks.ts +0 -586
  189. package/src/views/format.ts +0 -40
  190. package/src/views/runs-now.ts +0 -188
  191. package/src/views/step-funnel.ts +0 -163
  192. package/src/views/step-graph.ts +0 -77
  193. package/src/views/workflows-view.ts +0 -484
  194. package/src/workflow-dag.test.tsx +0 -89
  195. package/src/workflow-page.test.tsx +0 -170
@@ -1,532 +0,0 @@
1
- 'use client';
2
-
3
- /**
4
- * THE GENERIC VIEW OF A PROJECT'S WORKFLOWS, A WORKFLOW AT A TIME (`drilldown.ts`): the page enters at the project's top
5
- * workflow and opens one sub-workflow step at a time, a breadcrumb saying where it is. Alex, 2026-11-21: "a workflow is a
6
- * workflow. stop building bespoke pages". So every workflow, at every depth, the top included, gets one page with the same
7
- * sections, in the same order, whatever kind of workflow it is (`WorkflowPage`): its tasks as an addition with its runs and
8
- * limits, its steps as a graph (`workflow-dag.tsx`), its tasks over time, why its tasks are blocked or need an agent,
9
- * what its runs gave and cost, and where its runs stopped. A section with nothing to show says so in a line.
10
- *
11
- * Above it, the same on every page: what the project gives of its machine and its agents' account (the CPU limit, the stop
12
- * of everything, the spending limit and usage). It reads the platform's two readings (`views/workflows-view.ts`) and runs
13
- * now (`views/runs-now.ts`). Uses React, which the host page brings.
14
- */
15
- import { Fragment, useEffect, useState, type ReactNode } from 'react';
16
- import type { StepRunsNow, WorkflowRunsNow } from '../views/runs-now';
17
- import type { StepFunnel } from '../views/step-funnel';
18
- import type { SourceLink, StepCost, StepSummary, StepView, WorkflowFigures, WorkflowView, WorkflowsView } from '../views/workflows-view';
19
- import type { StepTimes } from '../step-times';
20
- import { TimeDistribution } from './time-distribution';
21
- import { compact, duration, localTime, whenAgo } from '../views/format';
22
- import { drillLevel, kindWords, workflowsUnder, type DrillLevel } from './drilldown';
23
- import { QueueBar } from './queue-bar';
24
- import { QueueChart } from './queue-chart';
25
- import { Breadcrumb, WorkflowTitle } from './workflow-drilldown';
26
- import { WorkflowDag, type StepBox } from './workflow-dag';
27
- import { AgentUsageLine } from './agent-usage-line';
28
- import type { AgentUsage } from './agent-usage';
29
- import { MachineControls } from './machine-controls';
30
- import { SpendingLimitControl } from './spending-limit-control';
31
- import { modelWords } from './setting-words';
32
- import { LimitControl, LimitLines, RetentionLines, RunsLines, type LimitName, type SetLimit, type SetSetting } from './limits-and-runs';
33
-
34
- export type { LimitName, SetLimit, SetSetting };
35
- import { runsGoingWords } from './run-doing-words';
36
-
37
- /** What the page is given at each poll, all of it read at the request: every workflow, and where runs are now. */
38
- export interface WorkflowsPageData {
39
- readonly view: WorkflowsView;
40
- readonly runsNow: ReadonlyArray<WorkflowRunsNow>;
41
- /**
42
- * The one CPU limit and the newest reading of what the project used (`CpuLimit`); `threads`, how many the machine has,
43
- * the most the limit can be set to.
44
- */
45
- readonly cpu: { readonly limit: number; readonly threads?: number; readonly use: { readonly at: number; readonly cores: number; readonly held: number; readonly waiting: number } | null };
46
- /** When everything was stopped by hand, unix seconds; none, or absent, while the project runs. */
47
- readonly stopped?: { readonly at: number } | null;
48
- /** What the agents' account has used of its limits (`agent-usage.ts`); absent where the project reads none. */
49
- readonly usage?: AgentUsage;
50
- }
51
-
52
- type WorkflowLimits = NonNullable<WorkflowView['limits']>;
53
-
54
- /** What starts a workflow's runs, in words. */
55
- const startsLine = (w: WorkflowView): string =>
56
- w.startsOn.kind === 'a step' ? `Runs as a step of ${w.startsOn.of.join(', ')}.`
57
- : w.startsOn.kind === 'its steps' ? 'Each of its steps is a workflow that runs on its own trigger.'
58
- : w.startsOn.kind === 'queue' ? 'Runs on its queue.'
59
- : w.startsOn.kind === 'inputs' ? `Runs when its inputs change: ${w.startsOn.says}.`
60
- : 'Runs on a timer or a request.';
61
-
62
- /** Where the project stands against its one CPU limit, in words. */
63
- const cpuLine = (cpu: WorkflowsPageData['cpu'], now: number): string =>
64
- cpu.use === null
65
- ? `CPU limit: ${cpu.limit} cores; no reading of what the project uses yet.`
66
- : `CPU: the project used ${cpu.use.cores.toFixed(1)} of its ${cpu.limit}-core limit at ${whenAgo(cpu.use.at, now)}; ${cpu.use.held} slot${cpu.use.held === 1 ? '' : 's'} held, ${cpu.use.waiting} waiting.`;
67
-
68
- export interface WorkflowsDashboardProps {
69
- readonly data: WorkflowsPageData | null;
70
- /** Why the data could not be read, if it could not; the last data read stays shown. */
71
- readonly error: string | null;
72
- /** Where one workflow's figures are read from when it is opened (`WorkflowFigures`): the project's route for them. */
73
- readonly figuresUrl: (workflow: string) => string;
74
- /** Where one workflow's step times are read from (`StepTimes`); with none, no step shows its time distribution. */
75
- readonly timesUrl?: (workflow: string) => string;
76
- /** Where a definition's link goes, where the project has somewhere to show its source; with none, no link shows. */
77
- readonly sourceHref?: (source: SourceLink) => string;
78
- /** The project's own lines above everything: its title. */
79
- readonly header?: ReactNode;
80
- /** How the page sets a limit; with none the limits show without controls. */
81
- readonly setLimit?: SetLimit;
82
- /** How the page sets a retention setting at a level; with none the settings show without controls. */
83
- readonly setSetting?: SetSetting;
84
- /** Stores a new CPU limit; with none the limit shows without buttons (`machine-controls.tsx`). */
85
- readonly setCpuLimit?: (limit: number) => Promise<void>;
86
- /** Stops everything the project runs, and resumes it; with neither, no button shows. */
87
- readonly stopEverything?: () => Promise<void>;
88
- readonly resume?: () => Promise<void>;
89
- /** Stores a new spending limit, a whole percent of the week; with none the limit shows without buttons (`spending-limit-control.tsx`). */
90
- readonly setSpendingLimit?: (weekPercent: number) => Promise<void>;
91
- /**
92
- * THE DRILL-DOWN (`drilldown.ts`): the sub-workflow steps opened below the top workflow, top first, and each level's
93
- * address, which the host page routes back here as `path`.
94
- */
95
- readonly path: ReadonlyArray<string>;
96
- readonly hrefOf: (path: ReadonlyArray<string>) => string;
97
- }
98
-
99
- /** Polls a JSON route one request at a time, the next asked for when this one has answered. */
100
- export const usePolledJson = <A,>(url: string | null, everyMs: number): { readonly data: A | null; readonly error: string | null } => {
101
- const [data, setData] = useState<A | null>(null);
102
- const [error, setError] = useState<string | null>(null);
103
- useEffect(() => {
104
- // No address, nothing to read: a part of the page the project gives no route for.
105
- if (url === null) return;
106
- let alive = true;
107
- let next: ReturnType<typeof setTimeout> | undefined;
108
- const tick = async () => {
109
- try {
110
- const r = await fetch(url, { cache: 'no-store' });
111
- if (!r.ok) throw new Error(`${r.status} ${(await r.text()).slice(0, 200)}`);
112
- const body = (await r.json()) as A;
113
- if (alive) { setData(body); setError(null); }
114
- } catch (e) {
115
- if (alive) setError(e instanceof Error ? e.message : String(e));
116
- }
117
- if (alive) next = setTimeout(() => void tick(), everyMs);
118
- };
119
- void tick();
120
- return () => { alive = false; clearTimeout(next); };
121
- }, [url, everyMs]);
122
- return { data, error };
123
- };
124
-
125
- /** Where a step's runs are now, in words: "2 in it", "1 waiting after it since 5:04 AM · 3 min ago". */
126
- const nowWords = (s: StepRunsNow | undefined, now: number): string => {
127
- if (s === undefined) return '';
128
- return [
129
- ...(s.inStep > 0 ? [`${s.inStep} run${s.inStep === 1 ? '' : 's'} in it`] : []),
130
- ...(s.waitingAfter > 0 ? [`${s.waitingAfter} after it${s.waitingSince === null ? '' : `, since ${whenAgo(s.waitingSince, now)}`}`] : []),
131
- ].join(', ');
132
- };
133
-
134
- /** What a step's calls cost in the window, in words: time, tokens (an agent step's), CPU, compiles and items. */
135
- const costWords = (c: StepCost, agentic: boolean): string => [
136
- duration(c.seconds),
137
- ...(agentic ? [`${compact(c.inputTokens)} / ${compact(c.outputTokens)} tokens`] : []),
138
- `${duration(c.cpuSeconds)} CPU`,
139
- ...(c.compiles === 0 ? [] : [`${compact(c.compiles)} compiles`]),
140
- ...(c.items === 0 ? [] : [`${c.items.toLocaleString('en-US')} item${c.items === 1 ? '' : 's'}`]),
141
- ].join(' · ');
142
-
143
- /**
144
- * A STEP'S OWN CALLS AS AN ADDITION, from its step records in the window (`StepCost`): in progress (its records still
145
- * open), failed, and done (ended without failing), adding up to its calls. Nothing records a task's status at a step, so
146
- * a step that is no workflow shows its calls, never its workflow's tasks. Pure.
147
- */
148
- export const stepCalls = (c: StepCost): Readonly<Record<string, number>> => ({ 'in progress': c.open, failed: c.failed, done: c.calls - c.open - c.failed });
149
-
150
- /** What its runs finished over the window, per run, per million tokens and per compile, with the window before beside it. */
151
- const yieldLine = (w: WorkflowFigures, finishedWord: string | null): string => {
152
- const { now, before } = w.yields;
153
- if (now.runs === 0 && before.runs === 0) return `No run of its own in the last ${2 * w.hours} h.`;
154
- const word = finishedWord ?? 'finished';
155
- const trend = now.finished === before.finished ? 'the same as' : now.finished > before.finished ? 'up from' : 'down from';
156
- return `${now.finished.toLocaleString('en-US')} ${word} in ${now.runs.toLocaleString('en-US')} runs, ${trend} ${before.finished.toLocaleString('en-US')} in the ${before.runs.toLocaleString('en-US')} before: `
157
- + `${per(now.perRun)} a run, ${per(now.perMillionTokens)} per million tokens, ${per(now.perCompile)} a compile (before: ${per(before.perRun)}, ${per(before.perMillionTokens)}, ${per(before.perCompile)}).`;
158
- };
159
-
160
- /** A figure to two places, or "none" where there was nothing to divide by. */
161
- const per = (n: number | null): string => (n === null ? 'none' : n === 0 ? '0' : n < 0.01 ? n.toPrecision(2) : n.toFixed(n >= 10 ? 0 : 2));
162
-
163
- /** What a run of it costs: the median run's time, tokens, CPU (its processes' part) and compiles, and its costliest run. */
164
- const runCostLine = (w: WorkflowFigures): string => {
165
- const c = w.runCosts;
166
- if (c.median === null) return 'No run of its own ended in the window.';
167
- const tokens = c.median.tokens === 0 ? '' : `, ${compact(c.median.tokens)} tokens`;
168
- const compiles = c.median.compiles === 0 ? '' : `, ${compact(c.median.compiles)} compiles`;
169
- const costliest = c.costliest === null ? '' : `; costliest ${duration(c.costliest.cpuSeconds)} of CPU, started ${localTime(c.costliest.started)}`;
170
- return `A run costs ${duration(c.median.seconds)}${tokens}, ${duration(c.median.cpuSeconds)} of CPU (${duration(c.median.childCpuSeconds)} in its processes)${compiles}, the median of ${c.runs.toLocaleString('en-US')} runs${costliest}.`;
171
- };
172
-
173
- /** Its steps' calls added up, in words. */
174
- const totalLine = (w: WorkflowFigures, usesAgents: boolean): string =>
175
- w.total.calls === 0 ? `No step of its own was called in the last ${w.hours} h.`
176
- : `Its steps in all, last ${w.hours} h: ${w.total.calls.toLocaleString('en-US')} calls, ${w.total.failed.toLocaleString('en-US')} failed, ${costWords(w.total, usesAgents)}.`;
177
-
178
- function FunnelTable({ funnel }: { readonly funnel: StepFunnel }) {
179
- if (funnel.runs === 0) return <p className="wp-line wp-mut">No run of its own began since {localTime(funnel.since)}.</p>;
180
- return (
181
- <>
182
- <p className="wp-line">
183
- {funnel.runs.toLocaleString('en-US')} run{funnel.runs === 1 ? '' : 's'} began since {localTime(funnel.since)}, {funnel.going.toLocaleString('en-US')} still going.
184
- </p>
185
- <div className="wp-tablewrap"><table className="wp-table">
186
- <thead><tr><th>step</th><th className="wp-r">reached</th><th className="wp-r">stopped here</th><th className="wp-r">finished here</th><th className="wp-r">median time</th></tr></thead>
187
- <tbody>
188
- {funnel.steps.map((s) => (
189
- <tr key={s.step} className={s.noneGotPast ? 'wp-bad' : ''}>
190
- <td>{s.step}{s.noneGotPast ? ' (none got past)' : ''}</td>
191
- <td className="wp-r">{s.reached.toLocaleString('en-US')}</td>
192
- <td className="wp-r">{s.stopped === 0 ? '' : s.stopped.toLocaleString('en-US')}</td>
193
- <td className="wp-r">{s.finished === 0 ? '' : s.finished.toLocaleString('en-US')}</td>
194
- <td className="wp-r">{s.medianSeconds === null ? '' : duration(s.medianSeconds)}</td>
195
- </tr>
196
- ))}
197
- </tbody>
198
- </table></div>
199
- {funnel.mostStopped === null ? null : (
200
- <p className="wp-line">
201
- Most stopped at {funnel.mostStopped.step} ({funnel.mostStopped.stopped.toLocaleString('en-US')}):{' '}
202
- {funnel.mostStopped.reasons.map((r) => `${r.reason} (${r.runs})`).join('; ')}
203
- {funnel.mostStopped.otherRuns > 0 ? `; ${funnel.mostStopped.otherRuns} for other reasons` : ''}.
204
- </p>
205
- )}
206
- </>
207
- );
208
- }
209
-
210
- /** A workflow's runs and agents now, and its limits with their controls: what its box shows below its tasks. */
211
- function WorkflowStatus({ workflow, runs, limits, setLimit }: { readonly workflow: WorkflowView; readonly runs: WorkflowRunsNow | undefined; readonly limits: WorkflowLimits | null; readonly setLimit: SetLimit | undefined }) {
212
- const going = runs?.runs ?? 0;
213
- const words = runsGoingWords({ runs: going, doing: runs?.doing ?? [], usesAgents: workflow.usesAgents, agentsLimit: limits?.agents ?? null });
214
- return (
215
- <div className="wp-node-status">
216
- <span className={going === 0 ? 'wp-mut' : ''} title="Each run going counted once, by its newest step record, read through a sub-workflow step to the run it started">{words}</span>
217
- {limits === null ? null : (
218
- <>
219
- <LimitControl workflow={workflow.name} limit="runs" value={limits.runs} isSet={limits.runsSet} setLimit={setLimit} />
220
- {limits.agents === null ? null : <LimitControl workflow={workflow.name} limit="agents" value={limits.agents} isSet setLimit={setLimit} />}
221
- </>
222
- )}
223
- </div>
224
- );
225
- }
226
-
227
- /**
228
- * The workflow whose tasks a workflow's box shows: its own where it records them; for one made of workflows, its main step's
229
- * (`StartsOn` `mainStep`), counted under that step's own workflow; none for any other.
230
- */
231
- const tasksShownOf = (w: WorkflowView, workflowOf: (name: string) => WorkflowView | undefined): WorkflowView | null => {
232
- if (w.queue !== null) return w;
233
- const main = w.startsOn.kind === 'its steps' && w.startsOn.mainStep !== null ? workflowOf(w.startsOn.mainStep) : undefined;
234
- return main !== undefined && main.queue !== null ? main : null;
235
- };
236
-
237
- /** A workflow's tasks as an addition, a main step's named in its total ("tasks in Decompile"); or a line saying it records none. */
238
- function Tasks({ workflow, workflowOf }: { readonly workflow: WorkflowView; readonly workflowOf: (name: string) => WorkflowView | undefined }) {
239
- const shown = tasksShownOf(workflow, workflowOf);
240
- return shown === null || shown.queue === null
241
- ? <p className="wp-line wp-mut">{noTasksWhy(workflow)}</p>
242
- : <QueueBar queue={shown.queue} queuedNeedingAnAgent={shown.queuedNeedingAnAgent} totalLabel={shown === workflow ? 'total' : `tasks in ${shown.name}`} />;
243
- }
244
-
245
- /** Why a workflow has no tasks of its own to count, in a line: they are other workflows', each counted once, under its own. */
246
- export const noTasksWhy = (w: Pick<WorkflowView, 'startsOn'>): string =>
247
- w.startsOn.kind === 'its steps' ? "Its tasks are its steps', each counted under its own workflow."
248
- : w.startsOn.kind === 'a step' ? `Its tasks are ${w.startsOn.of.join(' and ')}'s, passing through it.`
249
- : 'It records no tasks.';
250
-
251
- /**
252
- * A STEP'S CALLS IN THE WINDOW AS AN ADDITION (`stepCalls`): a step's own on its workflow's page, and on the page of a workflow
253
- * run as a step of another, that workflow's calls of it, its tasks passing through. The one drawing of both.
254
- */
255
- export function CallsBar({ cost, hours }: { readonly cost: StepCost; readonly hours: number }) {
256
- return <QueueBar queue={stepCalls(cost)} queuedNeedingAnAgent={null} counts="calls" totalLabel={`calls, ${hours} h`} />;
257
- }
258
-
259
- /** What its Pick does with its tasks marked as needing an agent, in words. */
260
- const needingAnAgentLine = (passedOverBecause: string | null): string =>
261
- passedOverBecause === null
262
- ? 'Each ended a run at an agent step when no agent was free for it. An agent is free now, so its Pick takes them in their queue\'s order again.'
263
- : `Each ended a run at an agent step when no agent was free for it. Its Pick passes over them now, because ${passedOverBecause}, and takes them in their queue's order once an agent is free.`;
264
-
265
- /** One step's box under its heading: a step that is a workflow shows that workflow's tasks and status; any other, its own calls. */
266
- function StepBody({ workflow, workflowOf, step, sub, subRuns, view, runsNow, hours, now, setLimit, setSetting, timing }: {
267
- /** The workflow whose page draws it. */
268
- readonly workflow: string;
269
- readonly workflowOf: (name: string) => WorkflowView | undefined;
270
- readonly step: StepSummary; readonly sub: WorkflowView | undefined; readonly subRuns: WorkflowRunsNow | undefined;
271
- readonly view: StepView | undefined; readonly runsNow: StepRunsNow | undefined; readonly hours: number; readonly now: number; readonly setLimit: SetLimit | undefined; readonly setSetting: SetSetting | undefined;
272
- /** Its time distribution (`StepTimesPart`); none until its times are read. */
273
- readonly timing: ReactNode;
274
- }) {
275
- // What it is and what it does, in words a phone shows: its kind, then its description, never only a hover.
276
- const kind = <><span className="wp-kind">{kindWords(step)}</span><p className="wp-node-what">{step.description}</p></>;
277
- // What it inherits or sets (`settings.ts`): how long its records are kept and, where it uses an agent, the model, each with where it is set.
278
- const here = { workflow, step: step.name };
279
- const settings = (
280
- <div className="wp-node-settings">
281
- <RetentionLines level={{ kind: 'step', workflow, step: step.name }} settings={step.retention} setSetting={setSetting} />
282
- {step.model === null ? null : <div className={step.model.value === null ? 'wp-bad' : undefined}>{modelWords(step.model, here)}</div>}
283
- </div>
284
- );
285
- const cost = view?.cost ?? null;
286
- const at = nowWords(runsNow, now);
287
- // The bar: a workflow step's own tasks where its workflow records them; otherwise this workflow's calls of the step, from
288
- // its own step records, which a workflow run as a step on this workflow's item records too (its tasks passing through it).
289
- const bar = sub !== undefined && tasksShownOf(sub, workflowOf) !== null ? <Tasks workflow={sub} workflowOf={workflowOf} />
290
- : cost !== null ? <CallsBar cost={cost} hours={hours} />
291
- : <p className="wp-line wp-mut">{sub === undefined || sub.startsOn.kind === 'a step' ? `No call in the last ${hours} h.` : noTasksWhy(sub)}</p>;
292
- return (
293
- <>
294
- {kind}
295
- {settings}
296
- {bar}
297
- {sub !== undefined ? <WorkflowStatus workflow={sub} runs={subRuns} limits={sub.limits} setLimit={setLimit} /> : (
298
- <div className="wp-node-status">
299
- <span className={at === '' ? 'wp-mut' : ''}>{at === '' ? 'no run in it' : at}</span>
300
- {runsNow?.waitingOn === null || runsNow?.waitingOn === undefined ? null : <span>waits: {runsNow.waitingOn}</span>}
301
- </div>
302
- )}
303
- {cost === null ? null : <div className="wp-node-status wp-mut">{costWords(cost, step.runs === 'agentic')}</div>}
304
- {view === undefined || view.endings.length === 0 ? null : (
305
- <div className="wp-node-status wp-mut" title={view.endings.map((e) => `${e.records} ${e.outcome}: ${e.reason}`).join('\n')}>
306
- ended: {view.endings[0]!.reason} ({view.endings[0]!.records})
307
- </div>
308
- )}
309
- {timing}
310
- </>
311
- );
312
- }
313
-
314
- /** What one of the platform's own workflows is, in words (`system-workflows.ts`): what the app may change of it and what it may not. */
315
- export const SYSTEM_WORKFLOW_WORDS = 'Part of the platform: the app sets its schedule, its run limit and the settings it inherits; its steps change only with the platform.';
316
-
317
- /**
318
- * THE PLATFORM'S OWN WORKFLOWS, on a top-level page, apart from the app's: each by name, said in words to be the
319
- * platform's, with how long its steps' records are kept and where that is set, and its runs and run limit.
320
- */
321
- function PlatformWorkflows({ workflows, runsOf, hrefOf, setLimit, setSetting }: { readonly workflows: ReadonlyArray<WorkflowView>; readonly runsOf: (name: string) => WorkflowRunsNow | undefined; readonly hrefOf: (path: ReadonlyArray<string>) => string; readonly setLimit: SetLimit | undefined; readonly setSetting: SetSetting | undefined }) {
322
- return (
323
- <>
324
- {workflows.map((w) => (
325
- <div key={w.name} className="wp-passing" data-system-workflow={w.name}>
326
- <p className="wp-line"><a href={hrefOf([w.name])}>{w.name}</a>: {w.description}</p>
327
- <p className="wp-line wp-mut">{SYSTEM_WORKFLOW_WORDS}</p>
328
- <RunsLines workflow={w} runs={runsOf(w.name)} />
329
- <LimitLines workflow={w} setLimit={setLimit} setSetting={setSetting} />
330
- </div>
331
- ))}
332
- </>
333
- );
334
- }
335
-
336
- /** One of the page's sections: a heading, and what it shows or a line saying why it shows nothing. */
337
- function Section({ name, children }: { readonly name: string; readonly children: ReactNode }) {
338
- return <section className="wp-section" data-section={name}><h3 className="wp-h3">{name}</h3>{children}</section>;
339
- }
340
-
341
- export interface WorkflowPageProps {
342
- readonly data: WorkflowsPageData;
343
- /** The opened workflow's figures as last read, and why they could not be read, if they could not. */
344
- readonly figures: { readonly data: WorkflowFigures | null; readonly error: string | null };
345
- readonly path: ReadonlyArray<string>;
346
- readonly hrefOf: (path: ReadonlyArray<string>) => string;
347
- readonly now: number;
348
- readonly sourceHref?: ((source: SourceLink) => string) | undefined;
349
- readonly setLimit?: SetLimit | undefined;
350
- readonly setSetting?: SetSetting | undefined;
351
- /** Its steps' times as last read (`step-times.ts`), and why they could not be read; absent where the project gives none. */
352
- readonly times?: { readonly data: StepTimes | null; readonly error: string | null } | undefined;
353
- }
354
-
355
- /**
356
- * ONE STEP'S TIME DISTRIBUTION IN ITS BOX: over the current version of its workflow, every task's value; before the first task
357
- * of a new version, the previous version's, said to be that. None until the times are first read.
358
- */
359
- function StepTimesPart({ step, times, now }: { readonly step: string; readonly times: StepTimes; readonly now: number }) {
360
- const current = times.steps.find((s) => s.step === step)?.values ?? [];
361
- if (current.length > 0) return <TimeDistribution values={current} />;
362
- if (times.previous === null) {
363
- return <p className="wp-line wp-mut">{times.steps.some((s) => s.values.length > 0) ? 'No task has left this step in this version yet.' : `No runs of this version yet, since ${localTime(times.since, now)}.`}</p>;
364
- }
365
- const before = times.previous.steps.find((s) => s.step === step)?.values ?? [];
366
- return (
367
- <>
368
- <p className="wp-line wp-mut">No runs of this version yet, since {localTime(times.since, now)}. The previous version{before.length === 0 ? ' had no task leave this step.' : ':'}</p>
369
- {before.length === 0 ? null : <TimeDistribution values={before} />}
370
- </>
371
- );
372
- }
373
-
374
- /**
375
- * ONE WORKFLOW'S PAGE, THE SAME FOR EVERY WORKFLOW AT EVERY DEPTH: the breadcrumb, then the workflow opened and each of its
376
- * sections in one order. Nothing here asks what kind of workflow it is; what differs is only what its records hold.
377
- */
378
- export function WorkflowPage({ data, figures: read, path, hrefOf, now, sourceHref, setLimit, setSetting, times }: WorkflowPageProps) {
379
- const level: DrillLevel = drillLevel(data.view, path);
380
- const all = data.view.workflows;
381
- const workflowOf = (name: string) => all.find((w) => w.name === name);
382
- const runsOf = (name: string) => data.runsNow.find((r) => r.workflow === name);
383
- const here = level.crumbs[level.crumbs.length - 1]!.path;
384
- const w = level.workflow;
385
- const figures = read.data !== null && read.data.workflow === level.name ? read.data : null;
386
- // The figures of the workflow opened before this one are never shown under this one's name.
387
- const withFigures = (show: (f: WorkflowFigures) => ReactNode): ReactNode => (figures !== null ? show(figures)
388
- : <p className={read.error === null ? 'wp-line wp-mut' : 'wp-line wp-bad'}>{read.error === null ? 'Reading its figures…' : `Its figures could not be read: ${read.error}`}</p>);
389
- const others = [data.view.top.name, ...data.view.outermost].filter((name) => name !== level.name);
390
- const box = (f: WorkflowFigures) => (name: string): StepBox => {
391
- const step = level.steps.find((s) => s.name === name);
392
- const sub = step?.workflow === null || step?.workflow === undefined ? undefined : workflowOf(step.workflow);
393
- return {
394
- href: sub === undefined ? null : hrefOf([...here, name]),
395
- title: sub === undefined ? name : `Open ${sub.name}`,
396
- body: step === undefined ? null : (
397
- <StepBody workflow={level.name} workflowOf={workflowOf} step={step} sub={sub} subRuns={sub === undefined ? undefined : runsOf(sub.name)} view={f.steps.find((s) => s.name === name)}
398
- runsNow={w === null ? undefined : runsOf(w.name)?.steps.find((s) => s.step === name)} hours={f.hours} now={now} setLimit={setLimit} setSetting={setSetting}
399
- timing={times?.data === null || times?.data === undefined ? null : <StepTimesPart step={name} times={times.data} now={now} />} />
400
- ),
401
- };
402
- };
403
- return (
404
- <section className="wp-drill">
405
- {/* Where it is, then what it is: the path from the top-level workflow, and the workflow this page shows. */}
406
- <Breadcrumb crumbs={level.crumbs} hrefOf={hrefOf} />
407
- <WorkflowTitle name={level.name} after={w === null || sourceHref === undefined ? null : <a className="wp-mut wp-drill-source" href={sourceHref(w.source)}>source</a>} />
408
- {level.notFound === null ? null : <p className="wp-line wp-bad">{level.name} has no sub-workflow step named {level.notFound}.</p>}
409
- {/* On a top-level workflow's page, the other top-level workflows: each a top of its own, never this one. */}
410
- {level.crumbs.length !== 1 || others.length === 0 ? null : (
411
- <p className="wp-line wp-others">Other top-level workflows: {others.map((name, i) => <Fragment key={name}>{i === 0 ? '' : ', '}<a href={hrefOf(name === data.view.top.name ? [] : [name])}>{name}</a></Fragment>)}</p>
412
- )}
413
- <p className="wp-line">{level.description}</p>
414
- {w === null || !w.system ? null : <p className="wp-line">{SYSTEM_WORKFLOW_WORDS}</p>}
415
- {w === null ? null : <p className="wp-line wp-mut">{startsLine(w)}</p>}
416
- <Section name="Tasks">
417
- {w === null ? <p className="wp-line wp-mut">It is not declared, so it records nothing.</p> : (
418
- <>
419
- {/* Its own tasks; or, run as a step of another, that workflow's tasks passing through it, the bar its box shows there. */}
420
- {tasksShownOf(w, workflowOf) !== null ? <Tasks workflow={w} workflowOf={workflowOf} /> : withFigures((f) => f.passingThrough.length === 0 ? <Tasks workflow={w} workflowOf={workflowOf} /> : f.passingThrough.map((p) => (
421
- <div key={`${p.workflow}>${p.step}`} className="wp-passing">
422
- <p className="wp-line">{p.workflow}&apos;s tasks at its step {p.step}, last {f.hours} h:</p>
423
- {p.cost === null ? <p className="wp-line wp-mut">None reached it.</p> : <CallsBar cost={p.cost} hours={f.hours} />}
424
- </div>
425
- )))}
426
- </>
427
- )}
428
- </Section>
429
- <Section name="Runs">
430
- {w === null ? <p className="wp-line wp-mut">It is not declared, so it has no runs.</p> : <RunsLines workflow={w} runs={runsOf(w.name)} />}
431
- </Section>
432
- <Section name="Limits">
433
- {w === null ? <p className="wp-line wp-mut">It is not declared, so it has no limits.</p> : <LimitLines workflow={w} setLimit={setLimit} setSetting={setSetting} />}
434
- </Section>
435
- <Section name="Steps">
436
- {level.steps.length === 0 ? <p className="wp-line wp-mut">It declares no steps.</p> : withFigures((f) => (
437
- <>
438
- <WorkflowDag graph={f.graph} box={box(f)} />
439
- <p className="wp-line wp-mut">{totalLine(f, w?.usesAgents ?? false)}</p>
440
- {f.steps.every((s) => s.declared) ? null : (
441
- <p className="wp-line wp-bad">Named by its records, no longer declared: {f.steps.filter((s) => !s.declared).map((s) => `${s.name} (${s.cost?.calls ?? 0} calls)`).join('; ')}</p>
442
- )}
443
- </>
444
- ))}
445
- </Section>
446
- <Section name="Tasks over time">
447
- {/* The workflow opened and every workflow under it, at any depth. */}
448
- <QueueChart view={data.view} level={path.join('/')} rowWord="workflow" workflows={w === null ? [] : workflowsUnder(data.view, w.name)} />
449
- </Section>
450
- <Section name="Blocked, by reason">
451
- {withFigures((f) => f.blocked.length === 0 ? <p className="wp-line wp-mut">None of its tasks is blocked.</p> : (
452
- <table className="wp-reasons">
453
- <tbody>{f.blocked.map((b) => <tr key={b.why}><td className="wp-r">{b.tasks.toLocaleString('en-US')}</td><td>{b.why}</td></tr>)}</tbody>
454
- </table>
455
- ))}
456
- </Section>
457
- <Section name="Queued, needing an agent">
458
- {withFigures((f) => f.needingAnAgent.reasons.length === 0 ? <p className="wp-line wp-mut">None of its queued tasks needs an agent.</p> : (
459
- <>
460
- <p className={f.needingAnAgent.passedOverBecause === null ? 'wp-line' : 'wp-line wp-bad'}>{needingAnAgentLine(f.needingAnAgent.passedOverBecause)}</p>
461
- <table className="wp-reasons">
462
- <tbody>{f.needingAnAgent.reasons.map((b) => <tr key={b.why}><td className="wp-r">{b.tasks.toLocaleString('en-US')}</td><td>{b.why}</td></tr>)}</tbody>
463
- </table>
464
- </>
465
- ))}
466
- </Section>
467
- <Section name="What its runs gave">
468
- {withFigures((f) => (
469
- <>
470
- <p className="wp-line wp-mut">Its figures over the last {f.hours} h, read {whenAgo(f.at, now)}.</p>
471
- <p className="wp-line">{yieldLine(f, w?.finishedWord ?? null)}</p>
472
- <p className="wp-line">{runCostLine(f)}</p>
473
- </>
474
- ))}
475
- </Section>
476
- <Section name="Where runs stopped">{withFigures((f) => <FunnelTable funnel={f.funnel} />)}</Section>
477
- {/* On an app's top-level page, the platform's own workflows, apart from the app's: like the other top-level
478
- workflows' line, no section of the workflow's own page, so every workflow's page keeps the same sections. */}
479
- {level.crumbs.length !== 1 || w?.system === true || data.view.system.length === 0 ? null : (
480
- <div className="wp-section" data-platform-workflows="">
481
- <h3 className="wp-h3">Platform workflows</h3>
482
- <PlatformWorkflows workflows={data.view.system.flatMap((name) => all.filter((x) => x.name === name))} runsOf={runsOf} hrefOf={hrefOf} setLimit={setLimit} setSetting={setSetting} />
483
- </div>
484
- )}
485
- </section>
486
- );
487
- }
488
-
489
- /** How often an open workflow's figures are read again. */
490
- const FIGURES_EVERY_MS = 15_000;
491
-
492
- /** How often an open workflow's step times are read again: they change as tasks leave steps, a minute is soon enough. */
493
- const TIMES_EVERY_MS = 60_000;
494
-
495
- /** The opened workflow's figures, read from its own records while it is open, and its steps' times where the project gives them. */
496
- function PolledWorkflowPage(props: Omit<WorkflowPageProps, 'figures' | 'times'> & { readonly figuresUrl: (workflow: string) => string; readonly timesUrl: ((workflow: string) => string) | undefined }) {
497
- const opened = drillLevel(props.data.view, props.path).name;
498
- const figures = usePolledJson<WorkflowFigures>(props.figuresUrl(opened), FIGURES_EVERY_MS);
499
- const times = usePolledJson<StepTimes>(props.timesUrl === undefined ? null : props.timesUrl(opened), TIMES_EVERY_MS);
500
- // Times of the workflow opened before this one are never shown under this one's name.
501
- const own = times.data !== null && times.data.workflow === opened ? times : { data: null, error: times.error };
502
- return <WorkflowPage {...props} figures={figures} {...(props.timesUrl === undefined ? {} : { times: own })} />;
503
- }
504
-
505
- export function WorkflowsDashboard({ data, error, figuresUrl, timesUrl, sourceHref, header, setLimit, setSetting, setCpuLimit, stopEverything, resume, setSpendingLimit, path, hrefOf }: WorkflowsDashboardProps) {
506
- const now = Date.now() / 1000;
507
- return (
508
- <div className="wp-page">
509
- {header}
510
- <p className={error === null ? 'wp-line wp-mut' : 'wp-line wp-bad'}>
511
- {error !== null ? `The workflows could not be read: ${error}` : data === null ? 'Reading the workflows…' : `Read from the records ${whenAgo(data.view.at, now)}.`}
512
- </p>
513
- {/* What the project gives of its machine and its agents' account: the same on every page. Nothing is drawn before the first read. */}
514
- {data === null ? null : (
515
- <>
516
- <p className={data.cpu.use !== null && data.cpu.use.cores > data.cpu.limit ? 'wp-line wp-bad' : 'wp-line'}>{cpuLine(data.cpu, now)}</p>
517
- {data.view.spending === null ? null : (
518
- <SpendingLimitControl spending={data.view.spending} now={now} {...(setSpendingLimit === undefined ? {} : { setSpendingLimit })} />
519
- )}
520
- <MachineControls cpu={data.cpu} stopped={data.stopped ?? null} now={now} {...(setCpuLimit === undefined ? {} : { setCpuLimit })} {...(stopEverything === undefined ? {} : { stopEverything })} {...(resume === undefined ? {} : { resume })} />
521
- {data.usage === undefined ? null : <AgentUsageLine usage={data.usage} now={now} />}
522
- {/* The app's own retention settings, above every workflow's: the same on every page. */}
523
- <div className="wp-app-settings" data-app-settings="">
524
- <p className="wp-line">The app's records, for every workflow that sets none of its own:</p>
525
- <RetentionLines level={{ kind: 'app' }} settings={data.view.appRetention} setSetting={setSetting} />
526
- </div>
527
- <PolledWorkflowPage data={data} path={path} hrefOf={hrefOf} now={now} figuresUrl={figuresUrl} timesUrl={timesUrl} sourceHref={sourceHref} setLimit={setLimit} setSetting={setSetting} />
528
- </>
529
- )}
530
- </div>
531
- );
532
- }
package/src/failure.ts DELETED
@@ -1,36 +0,0 @@
1
- /**
2
- * What a failure actually was, as one line.
3
- *
4
- * `Effect.runPromise` rejects with the typed failure itself, and a
5
- * `Schema.TaggedError` has an empty `message`: reading only that printed a
6
- * worker's label and nothing else, which reads as a successful quiet tick --
7
- * and recorded the gate canary's Docker failure as "", which hid from both a
8
- * reader and `/api/health` that the cause was outside the service.
9
- */
10
- /**
11
- * A long failure text as it is kept: whole when it fits in `cap`, else its start and its last `end` characters, with
12
- * how much was left out between. Never only the start: a failure's own words are usually last, and a step error cut
13
- * at 500 characters kept a compiler's source echo and ended "Refere", its `ReferenceError` lost (2026-11-07).
14
- */
15
- export const startAndEnd = (text: string, kept: { readonly cap: number; readonly end: number; readonly what: string }): string =>
16
- text.length <= kept.cap
17
- ? text
18
- : `${text.slice(0, kept.cap - kept.end)}\n[... ${text.length - kept.cap} characters of ${kept.what} left out ...]\n${text.slice(-kept.end)}`;
19
-
20
- export const describeFailure = (cause: unknown): string => {
21
- if (cause !== null && typeof cause === 'object') {
22
- const tagged = cause as { _tag?: unknown; message?: unknown };
23
- if (typeof tagged._tag === 'string') {
24
- const fields = Object.entries(cause as Record<string, unknown>)
25
- .filter(([key]) => key !== '_tag')
26
- .map(([key, value]) => `${key}=${typeof value === 'string' ? value : JSON.stringify(value)}`)
27
- .join(' ');
28
- return fields === '' ? tagged._tag : `${tagged._tag}: ${fields}`;
29
- }
30
- if (cause instanceof Error) {
31
- return cause.message === '' ? (cause.stack ?? String(cause)) : cause.message;
32
- }
33
- return JSON.stringify(cause);
34
- }
35
- return String(cause);
36
- };