@jive-sh/workflow-platform 0.4.0 → 0.5.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.
@@ -11,7 +11,7 @@ import {
11
11
  stepErrorKept, type FunnelStepRecord, type ItemCost, type ItemHistoryRow, type LastStepNow, type NewestStepRecord, type RunCost, type RunOutcomeRow, type StepEdgeTaken,
12
12
  type StepFileCount, type StepRecords, type StepRunRow, type UndeclaredWrites, type WorkStep, AGENT_LIVE_SECONDS,
13
13
  } from './step-records';
14
- import { LISTED_AGAIN, MOVED_TO_FRONT, STATUS_KINDS, STOOD_DOWN_OUTCOME, TRIES_START_AGAIN_KINDS, type Listed, type NewNote, type QueueCount, type TaskNote, type TaskRef, type TaskState, type TaskStore } from './task-store';
14
+ import { LISTED_AGAIN, MOVED_TO_FRONT, STATUS_KINDS, STOOD_DOWN_OUTCOME, TRIES_START_AGAIN_KINDS, type Listed, type ListedWait, type NewNote, type QueueCount, type ReturnedBetween, type TaskNote, type TaskRef, type TaskState, type TaskStore } from './task-store';
15
15
  import type { InputRecords, InputRun } from './input-records';
16
16
  import { storeCall, storeCalls } from './storage-error';
17
17
 
@@ -779,6 +779,16 @@ export const sqliteStore = (options: {
779
779
  WHERE at >= ?1 OR at = (SELECT MAX(p.at) FROM queue_counts p WHERE p.workflow = q.workflow AND p.bucket = q.bucket AND p.at < ?1)
780
780
  ORDER BY at`,
781
781
  ).all(since) as ReadonlyArray<QueueCount>, [])),
782
+ returnedBetween: () => storeCall('tasks: returnedBetween', () =>
783
+ read((db) => db.query(
784
+ `SELECT n.by_workflow AS "from", t.workflow AS "to", COUNT(*) AS notes, MAX(n.at) AS last FROM task_notes n JOIN tasks t ON t.id = n.task
785
+ WHERE n.kind IN (${TRIES_START_AGAIN_KINDS.map((k) => `'${k}'`).join(', ')}) AND n.by_workflow IS NOT NULL AND n.by_workflow <> t.workflow GROUP BY 1, 2 ORDER BY 1, 2`,
786
+ ).all() as ReadonlyArray<ReturnedBetween>, [])),
787
+ listedWaits: () => storeCall('tasks: listedWaits', () =>
788
+ read((db) => db.query(
789
+ `SELECT workflow, json_extract(listed, '$.on') AS "on", json_extract(listed, '$.label') AS label, COUNT(*) AS tasks FROM tasks
790
+ WHERE listed IS NOT NULL AND json_extract(listed, '$.kind') = 'wait' GROUP BY 1, 2, 3 ORDER BY 1, 2, 3`,
791
+ ).all() as ReadonlyArray<ListedWait>, [])),
782
792
  writable: () => options.file() !== null,
783
793
  };
784
794
 
@@ -127,6 +127,25 @@ export interface QueueCount {
127
127
  readonly tasks: number;
128
128
  }
129
129
 
130
+ /**
131
+ * Tasks of one workflow that a step of another returned to their queue (`tasks.ts` `requeue`, `reopen`): how many notes,
132
+ * the last when.
133
+ */
134
+ export interface ReturnedBetween {
135
+ readonly from: string;
136
+ readonly to: string;
137
+ readonly notes: number;
138
+ readonly last: number;
139
+ }
140
+
141
+ /** A workflow's tasks its list last put on one wait, by what they wait on and the list's words for it. */
142
+ export interface ListedWait {
143
+ readonly workflow: string;
144
+ readonly on: string;
145
+ readonly label: string;
146
+ readonly tasks: number;
147
+ }
148
+
130
149
  /** What a reading of a workflow's list changed. */
131
150
  export interface ListingRecorded {
132
151
  /** Whether it put any task in the queue: one new to the list, or one it lists again. */
@@ -184,6 +203,10 @@ export interface TaskStore {
184
203
  readonly recordQueueCounts: (r: { readonly at: number; readonly counts: ReadonlyArray<Omit<QueueCount, 'at'>> }) => Effect.Effect<void, StorageError>;
185
204
  /** Each count recorded since `since`, and for each queue and status the last recorded before it, oldest first. */
186
205
  readonly queueCountsSince: (since: number) => Effect.Effect<ReadonlyArray<QueueCount>, StorageError>;
206
+ /** Every workflow a step of which returned another's tasks to their queue, by the two. */
207
+ readonly returnedBetween: () => Effect.Effect<ReadonlyArray<ReturnedBetween>, StorageError>;
208
+ /** Every wait a workflow's list puts its tasks on now, with how many. */
209
+ readonly listedWaits: () => Effect.Effect<ReadonlyArray<ListedWait>, StorageError>;
187
210
  /** Whether the store can be written: false in a test that named no store. */
188
211
  readonly writable: () => boolean;
189
212
  }
@@ -44,7 +44,7 @@ export interface PhaseRunsNow<Phase extends string = string> {
44
44
  readonly workflows: ReadonlyArray<WorkflowRunsNow>;
45
45
  }
46
46
 
47
- type Declared<Phase extends string> = { readonly name: string; readonly phase: Phase; readonly steps: () => ReadonlyArray<Pick<StepDeclaration, 'name' | 'agent'>> };
47
+ type Declared<Phase extends string> = { readonly name: string; readonly phase: Phase; readonly steps: () => ReadonlyArray<Pick<StepDeclaration, 'name' | 'runs'>> };
48
48
 
49
49
  const sum = <T>(xs: ReadonlyArray<T>, f: (x: T) => number) => xs.reduce((a, x) => a + f(x), 0);
50
50
 
@@ -53,7 +53,7 @@ const workflowRunsNow = <Phase extends string>(d: Declared<Phase>, runs: Readonl
53
53
  const r = newest.get(run);
54
54
  return r === undefined ? [] : [r];
55
55
  });
56
- const declared = d.steps().map((s) => ({ name: s.name, agent: s.agent }));
56
+ const declared = d.steps().map((s) => ({ name: s.name, agent: s.runs === 'agentic' }));
57
57
  const undeclared = [...new Set(records.map((r) => r.step))].filter((name) => !declared.some((s) => s.name === name))
58
58
  .map((name) => ({ name, agent: records.some((r) => r.step === name && r.agent === 1) }));
59
59
  const steps = [...declared, ...undeclared].map((s): StepRunsNow => {
@@ -62,7 +62,7 @@ export const FUNNEL_WINDOW_HOURS = [1, 24] as const;
62
62
  /** Reasons listed under the step most runs stopped at; the rest are counted together. */
63
63
  export const TOP_STOP_REASONS = 3;
64
64
 
65
- type Declared = { readonly item: string | null } & { readonly steps: () => ReadonlyArray<Pick<StepDeclaration, 'name' | 'agent'>> };
65
+ type Declared = { readonly item: string | null } & { readonly steps: () => ReadonlyArray<Pick<StepDeclaration, 'name' | 'runs'>> };
66
66
 
67
67
  /** The commonest of a run's item outcomes, so a batch run gives one reason. */
68
68
  const commonest = (xs: ReadonlyArray<string>): string => {
@@ -123,7 +123,7 @@ export const stepFunnel = (input: {
123
123
  return { step: last.step, finished, reason: finished ? null : stopReason(last, theirs) };
124
124
  });
125
125
 
126
- const declared = input.declaration.steps().map((s) => ({ name: s.name, agent: s.agent }));
126
+ const declared = input.declaration.steps().map((s) => ({ name: s.name, agent: s.runs === 'agentic' }));
127
127
  const undeclared = [...new Set(runs.flatMap(([, rs]) => rs.map((r) => r.step)))].filter((name) => !declared.some((s) => s.name === name))
128
128
  .map((name) => ({ name, agent: runs.some(([, rs]) => rs.some((r) => r.step === name && r.agent === 1)) }));
129
129
  const counted = [...declared, ...undeclared].map((s) => {
@@ -5,7 +5,7 @@
5
5
  */
6
6
  import type { LastStepNow, StepEdgeTaken } from '../storage/step-records';
7
7
  import { A_STEP_FAILS, isRetry, RUN_ENDS, RUN_STARTS, type StepEdge } from '../graph';
8
- import type { StepDeclaration } from '../steps';
8
+ import type { StepDeclaration, StepRuns } from '../steps';
9
9
 
10
10
  /** A step-to-step edge of a workflow's graph, and how many runs took it in the window. */
11
11
  export interface GraphEdge {
@@ -20,7 +20,7 @@ export interface WorkflowGraph {
20
20
  readonly workflow: string;
21
21
  /** False until the workflow declares its graph: then `edges` is empty and a page says so. */
22
22
  readonly declared: boolean;
23
- readonly steps: ReadonlyArray<{ readonly name: string; readonly agent: boolean; readonly description: string }>;
23
+ readonly steps: ReadonlyArray<{ readonly name: string; readonly runs: StepRuns | null; readonly description: string; readonly workflow: string | null }>;
24
24
  readonly edges: ReadonlyArray<GraphEdge>;
25
25
  readonly undeclared: ReadonlyArray<{ readonly from: string; readonly to: string; readonly runs: number }>;
26
26
  }
@@ -28,7 +28,7 @@ export interface WorkflowGraph {
28
28
  /** What of a declaration the graph reads. */
29
29
  interface Declared {
30
30
  readonly name: string;
31
- readonly steps: () => ReadonlyArray<Pick<StepDeclaration, 'name' | 'agent' | 'description'>>;
31
+ readonly steps: () => ReadonlyArray<Pick<StepDeclaration, 'name' | 'runs' | 'description' | 'workflow'>>;
32
32
  readonly graph?: (() => ReadonlyArray<StepEdge>) | undefined;
33
33
  }
34
34
 
@@ -61,7 +61,7 @@ export const workflowGraphs = (input: {
61
61
  return {
62
62
  workflow: d.name,
63
63
  declared: d.graph !== undefined,
64
- steps: d.steps().map((s) => ({ name: s.name, agent: s.agent, description: s.description })),
64
+ steps: d.steps().map((s) => ({ name: s.name, runs: s.runs, description: s.description, workflow: s.workflow ?? null })),
65
65
  edges: graph.map((e) => ({ ...e, runs: runs.get(`${e.from}\u0000${e.to}`) ?? 0 })),
66
66
  undeclared: [...undeclared.values()].sort((a, b) => b.runs - a.runs),
67
67
  };
@@ -0,0 +1,97 @@
1
+ /**
2
+ * WHERE WORK FLOWS BETWEEN WORKFLOWS: the edges of a project's DAG of workflows, and each workflow's place in its pipeline.
3
+ * Built from what the platform knows and nothing written for the page:
4
+ *
5
+ * feeds a workflow declares the other among those whose results it works on (`fedBy`);
6
+ * sends back a step of a workflow returned a task of one upstream of it, through feeds, to that one's queue (`requeue`);
7
+ * gives input it returned to its queue a task of one that is not upstream of it, with no feed declared between them;
8
+ * waits on its list puts tasks on a wait that names another workflow (`PendingWork.waits`), not the one that feeds it:
9
+ * the list's own words say why (`why`).
10
+ *
11
+ * Its place: its stage (the project's phases, in order), then how many feeds lead into it within its stage. Pure.
12
+ */
13
+ import type { ListedWait, ReturnedBetween } from '../storage/task-store';
14
+
15
+ export type FlowKind = 'feeds' | 'sends back' | 'gives input' | 'waits on';
16
+
17
+ /** One edge: work going from one workflow to another. */
18
+ export interface WorkflowFlow {
19
+ readonly from: string;
20
+ readonly to: string;
21
+ readonly kind: FlowKind;
22
+ /** Whether a declaration says it (`fedBy`); a recorded one only is not declared. */
23
+ readonly declared: boolean;
24
+ /** The returns to the queue recorded along it, and the last one's time; 0 and none where none was recorded. */
25
+ readonly notes: number;
26
+ readonly last: number | null;
27
+ /** Along a `waits on` edge: the tasks waiting, and the list's words for the wait; 0 and none on any other. */
28
+ readonly waiting: number;
29
+ readonly why: string | null;
30
+ }
31
+
32
+ /** A workflow's place in its pipeline: its stage's index, then its depth within the stage through feeds. */
33
+ export interface PipelinePlace {
34
+ readonly workflow: string;
35
+ readonly stage: number;
36
+ readonly depth: number;
37
+ }
38
+
39
+ /** Whether `to` reaches `from` through `feeds`: work goes from `to`, by way of others, to `from`. */
40
+ const reaches = (feeds: ReadonlyArray<{ readonly from: string; readonly to: string }>, start: string, target: string): boolean => {
41
+ const seen = new Set<string>([start]);
42
+ const next = [start];
43
+ while (next.length > 0) {
44
+ const at = next.pop()!;
45
+ for (const f of feeds) {
46
+ if (f.from !== at || seen.has(f.to)) continue;
47
+ if (f.to === target) return true;
48
+ seen.add(f.to);
49
+ next.push(f.to);
50
+ }
51
+ }
52
+ return false;
53
+ };
54
+
55
+ export const workflowFlows = (input: {
56
+ readonly declared: ReadonlyArray<{ readonly name: string; readonly fedBy?: ReadonlyArray<string> }>;
57
+ readonly returned: ReadonlyArray<ReturnedBetween>;
58
+ readonly waits: ReadonlyArray<ListedWait>;
59
+ }): ReadonlyArray<WorkflowFlow> => {
60
+ const names = new Set(input.declared.map((d) => d.name));
61
+ const recorded = (from: string, to: string) => input.returned.find((n) => n.from === from && n.to === to);
62
+ const feeds = input.declared.flatMap((d) => (d.fedBy ?? []).filter((f) => names.has(f) && f !== d.name).map((f) => ({ from: f, to: d.name })));
63
+ const declaredFlows: ReadonlyArray<WorkflowFlow> = feeds.map((f) => {
64
+ const r = recorded(f.from, f.to);
65
+ return { from: f.from, to: f.to, kind: 'feeds', declared: true, notes: r?.notes ?? 0, last: r?.last ?? null, waiting: 0, why: null };
66
+ });
67
+ const recordedOnly: ReadonlyArray<WorkflowFlow> = input.returned
68
+ .filter((n) => names.has(n.from) && names.has(n.to) && !feeds.some((f) => f.from === n.from && f.to === n.to))
69
+ .map((n) => ({ from: n.from, to: n.to, kind: reaches(feeds, n.to, n.from) ? 'sends back' : 'gives input', declared: false, notes: n.notes, last: n.last, waiting: 0, why: null }));
70
+ // A wait on the workflow that feeds it is that feed's work still to come, drawn as the feed; one on another is an edge.
71
+ const waitedOn: ReadonlyArray<WorkflowFlow> = input.waits
72
+ .filter((w) => names.has(w.on) && w.on !== w.workflow && !feeds.some((f) => f.from === w.on && f.to === w.workflow))
73
+ .map((w) => ({ from: w.workflow, to: w.on, kind: 'waits on', declared: false, notes: 0, last: null, waiting: w.tasks, why: w.label }));
74
+ return [...declaredFlows, ...recordedOnly, ...waitedOn];
75
+ };
76
+
77
+ /** Each workflow's place: its stage by `stageOf` in `stages`' order (one not among them after them), then its depth there. */
78
+ export const pipelinePlaces = (input: {
79
+ readonly workflows: ReadonlyArray<{ readonly name: string; readonly stage: string }>;
80
+ readonly stages: ReadonlyArray<string>;
81
+ readonly flows: ReadonlyArray<WorkflowFlow>;
82
+ }): ReadonlyArray<PipelinePlace> => {
83
+ const stageIndex = (s: string) => (input.stages.includes(s) ? input.stages.indexOf(s) : input.stages.length);
84
+ const stageOf = new Map(input.workflows.map((w) => [w.name, stageIndex(w.stage)]));
85
+ // Forward work only: feeds, and input given to one not upstream. A send-back points against the pipeline.
86
+ const forward = input.flows.filter((f) => f.kind !== 'sends back');
87
+ const depth = new Map<string, number>();
88
+ const depthOf = (name: string, path: ReadonlySet<string>): number => {
89
+ const known = depth.get(name);
90
+ if (known !== undefined) return known;
91
+ const into = forward.filter((f) => f.to === name && !path.has(f.from) && stageOf.get(f.from) === stageOf.get(name));
92
+ const d = into.length === 0 ? 0 : Math.max(...into.map((f) => depthOf(f.from, new Set([...path, name])) + 1));
93
+ depth.set(name, d);
94
+ return d;
95
+ };
96
+ return input.workflows.map((w) => ({ workflow: w.name, stage: stageIndex(w.stage), depth: depthOf(w.name, new Set()) }));
97
+ };
@@ -11,7 +11,8 @@
11
11
  * Built from the declarations and the stores alone, so any project's workflows read the same; a project adds its own
12
12
  * panels beside it. Where its runs are now (`runs-now.ts`) is read at each request too.
13
13
  */
14
- import { stepKindOf, stepUsesAnAgent, type SourceRef, type StepDeclaration, type StepKind, type WorkflowDeclaration } from '../steps';
14
+ import { stepKindOf, stepUsesAnAgent, type SourceRef, type StepDeclaration, type StepKind, type StepRuns, type WorkflowDeclaration } from '../steps';
15
+ import { pipelinePlaces, workflowFlows, type PipelinePlace, type WorkflowFlow } from './workflow-flows';
15
16
 
16
17
  /** A definition's link: its file and text, and the line that text is on now; none when the text is no longer in the file. */
17
18
  export interface SourceLink extends SourceRef {
@@ -33,7 +34,9 @@ import { workflowGraphs, type WorkflowGraph } from './step-graph';
33
34
  export type StartsOn =
34
35
  | { readonly kind: 'queue' }
35
36
  | { readonly kind: 'inputs'; readonly says: string }
36
- | { readonly kind: 'timer or request' };
37
+ | { readonly kind: 'timer or request' }
38
+ /** It runs only as a step of the workflows named (`defineSubWorkflow`). */
39
+ | { readonly kind: 'a step'; readonly of: ReadonlyArray<string> };
37
40
 
38
41
  /** How long the queues' history reaches back. */
39
42
  export const QUEUE_HISTORY_DAYS = 7;
@@ -57,7 +60,8 @@ export interface StepCost {
57
60
 
58
61
  export interface StepView {
59
62
  readonly name: string;
60
- readonly agent: boolean;
63
+ /** How it runs (`StepRuns`); none for a sub-workflow step, and for one no longer declared that no agent ran. */
64
+ readonly runs: StepRuns | null;
61
65
  readonly description: string;
62
66
  readonly source: SourceLink;
63
67
  /** Whether its declaration lists it; a step only the records name is no longer declared. */
@@ -150,8 +154,8 @@ export const yieldOf = (r: { readonly runs: number; readonly finished: number; r
150
154
  export interface StepSummary {
151
155
  readonly name: string;
152
156
  readonly kind: StepKind;
153
- /** Whether it uses an agent: an agent step, or a sub-workflow with one anywhere under it. */
154
- readonly usesAgent: boolean;
157
+ /** How it runs; none for a sub-workflow step, whose own steps say theirs. */
158
+ readonly runs: StepRuns | null;
155
159
  readonly description: string;
156
160
  /** For a sub-workflow: the workflow it runs, by name; none for any other kind. */
157
161
  readonly workflow: string | null;
@@ -187,6 +191,8 @@ export interface WorkflowView {
187
191
  readonly limits: { readonly agents: number | null; readonly runs: number | null; readonly runsSet: boolean } | null;
188
192
  /** Its tasks by status, as last counted (`queue-counts.ts`); none for a workflow with no item. */
189
193
  readonly queue: Readonly<Record<TaskStatus, number>> | null;
194
+ /** Its place among the project's workflows: what the map lays it out by (`workflow-flows.ts`). */
195
+ readonly place: PipelinePlace;
190
196
  /** What starts its runs. */
191
197
  readonly startsOn: StartsOn;
192
198
  }
@@ -199,6 +205,8 @@ export interface WorkflowsView {
199
205
  readonly groups: ReadonlyArray<{ readonly phase: string; readonly workflows: ReadonlyArray<WorkflowView> }>;
200
206
  /** Each queue's counts by status over the last `QUEUE_HISTORY_DAYS` (`historyByStatus`), a row where one changed, oldest first. */
201
207
  readonly queueHistory: ReadonlyArray<QueueCount>;
208
+ /** Where work goes between the top workflow's steps: the map's arrows (`workflow-flows.ts`). */
209
+ readonly flows: ReadonlyArray<WorkflowFlow>;
202
210
  }
203
211
 
204
212
  /** One workflow's figures over a window, read from its own records when it is opened. */
@@ -243,7 +251,7 @@ export const costOf = (rows: ReadonlyArray<StepRunRow>): StepCost | null =>
243
251
  items: new Set(rows.flatMap((r) => (r.subject === null ? [] : [r.subject.toLowerCase()]))).size,
244
252
  };
245
253
 
246
- type Declared = Pick<WorkflowDeclaration<string, unknown>, 'name' | 'phase' | 'description' | 'source' | 'item' | 'finishedWord' | 'graph' | 'pending' | 'items' | 'inputs'> & {
254
+ type Declared = Pick<WorkflowDeclaration<string, unknown>, 'name' | 'phase' | 'description' | 'source' | 'item' | 'finishedWord' | 'graph' | 'fedBy' | 'pending' | 'items' | 'inputs'> & {
247
255
  readonly steps: () => ReadonlyArray<StepDeclaration>;
248
256
  };
249
257
 
@@ -310,36 +318,44 @@ export const buildWorkflowsView = (input: {
310
318
  readonly phases: ReadonlyArray<string>;
311
319
  readonly now: number;
312
320
  /** The queues' history, from the task store. */
313
- readonly taskStore: Pick<TaskStore, 'queueCountsSince'>;
321
+ readonly taskStore: Pick<TaskStore, 'queueCountsSince' | 'returnedBetween' | 'listedWaits'>;
314
322
  /** The line a definition's text is on now. */
315
323
  readonly locate: (source: SourceRef) => number | null;
316
324
  readonly limitsOf: (workflow: string) => WorkflowView['limits'];
317
325
  /** The project's top workflow, in its own words, until it declares one. */
318
326
  readonly top: { readonly name: string; readonly description: string };
319
327
  }): Effect.Effect<WorkflowsView, StorageError> => Effect.gen(function* () {
320
- const stepSummary = (s: StepDeclaration): StepSummary => ({ name: s.name, kind: stepKindOf(s), usesAgent: stepUsesAnAgent(s), description: s.description, workflow: s.workflow ?? null });
328
+ const stepSummary = (s: StepDeclaration): StepSummary => ({ name: s.name, kind: stepKindOf(s), runs: s.runs, description: s.description, workflow: s.workflow ?? null });
321
329
  // Until the project declares its top workflow, its steps are every workflow no other workflow uses as a step.
322
330
  const usedAsAStep = new Set(input.declared.flatMap((d) => d.steps().flatMap((s) => (s.workflow === undefined ? [] : [s.workflow]))));
323
331
  const phases = [...input.phases, ...[...new Set(input.declared.map((d) => d.phase))].filter((p) => !input.phases.includes(p))];
324
332
  const queueHistory = historyByStatus(yield* input.taskStore.queueCountsSince(input.now - QUEUE_HISTORY_DAYS * 86_400));
325
333
  const queues = queuesNow(queueHistory);
334
+ // The map is of the top workflow's steps: a workflow used as a step of another is drawn inside that one, not here.
335
+ const onTheMap = input.declared.filter((d) => !usedAsAStep.has(d.name));
336
+ const flows = workflowFlows({ declared: onTheMap, returned: yield* input.taskStore.returnedBetween(), waits: yield* input.taskStore.listedWaits() });
337
+ const places = new Map(pipelinePlaces({ workflows: input.declared.map((d) => ({ name: d.name, stage: d.phase })), stages: phases, flows }).map((p) => [p.workflow, p]));
326
338
  const workflowView = (d: Declared): WorkflowView => ({
327
339
  name: d.name, steps: d.steps().map(stepSummary),
328
340
  phase: d.phase, description: d.description, source: { ...d.source, line: input.locate(d.source) }, item: d.item, finishedWord: d.finishedWord,
329
341
  usesAgents: d.steps().some(stepUsesAnAgent),
330
- limits: input.limitsOf(d.name),
342
+ // A workflow used as a step has no limit of its own to show: its starts are its parent's steps (`defineSubWorkflow`).
343
+ limits: usedAsAStep.has(d.name) ? null : input.limitsOf(d.name),
344
+ place: places.get(d.name)!,
331
345
  queue: d.item === null ? null : queues.get(d.name) ?? noTasks(),
332
- startsOn: d.pending !== undefined || d.items !== undefined ? { kind: 'queue' } : d.inputs !== undefined ? { kind: 'inputs', says: d.inputs.says } : { kind: 'timer or request' },
346
+ startsOn: usedAsAStep.has(d.name) ? { kind: 'a step', of: input.declared.filter((p) => p.steps().some((s) => s.workflow === d.name)).map((p) => p.name) }
347
+ : d.pending !== undefined || d.items !== undefined ? { kind: 'queue' } : d.inputs !== undefined ? { kind: 'inputs', says: d.inputs.says } : { kind: 'timer or request' },
333
348
  });
334
349
  const inPageOrder = phases.flatMap((phase) => input.declared.filter((d) => d.phase === phase));
335
350
  return {
336
351
  at: input.now,
337
352
  top: {
338
353
  ...input.top,
339
- steps: inPageOrder.filter((d) => !usedAsAStep.has(d.name)).map((d): StepSummary => ({ name: d.name, kind: 'sub-workflow', usesAgent: d.steps().some(stepUsesAnAgent), description: d.description, workflow: d.name })),
354
+ steps: inPageOrder.filter((d) => !usedAsAStep.has(d.name)).map((d): StepSummary => ({ name: d.name, kind: 'sub-workflow', runs: null, description: d.description, workflow: d.name })),
340
355
  },
341
356
  groups: phases.map((phase) => ({ phase, workflows: input.declared.filter((d) => d.phase === phase).map(workflowView) })).filter((g) => g.workflows.length > 0),
342
357
  queueHistory,
358
+ flows,
343
359
  };
344
360
  });
345
361
 
@@ -377,8 +393,8 @@ export const buildWorkflowFigures = (input: {
377
393
  const declaredSteps = d.steps();
378
394
  const onlyInRecords = [...new Set(own.map((r) => r.step))].filter((s) => !declaredSteps.some((x) => x.name === s));
379
395
  const steps: ReadonlyArray<StepView> = [
380
- ...declaredSteps.map((s) => ({ name: s.name, agent: s.agent, description: s.description, source: link(s.source), declared: true, cost: costOf(own.filter((r) => r.step === s.name)), endings: endingsOf(funnelRecords.records.filter((r) => r.step === s.name)) })),
381
- ...onlyInRecords.map((name) => ({ name, agent: own.some((r) => r.step === name && r.agent === 1), description: 'no longer declared', source: link(d.source), declared: false, cost: costOf(own.filter((r) => r.step === name)), endings: endingsOf(funnelRecords.records.filter((r) => r.step === name)) })),
396
+ ...declaredSteps.map((s) => ({ name: s.name, runs: s.runs, description: s.description, source: link(s.source), declared: true, cost: costOf(own.filter((r) => r.step === s.name)), endings: endingsOf(funnelRecords.records.filter((r) => r.step === s.name)) })),
397
+ ...onlyInRecords.map((name) => ({ name, runs: own.some((r) => r.step === name && r.agent === 1) ? 'agentic' as const : null, description: 'no longer declared', source: link(d.source), declared: false, cost: costOf(own.filter((r) => r.step === name)), endings: endingsOf(funnelRecords.records.filter((r) => r.step === name)) })),
382
398
  ];
383
399
  const funnel = stepFunnel({ declaration: d, records: funnelRecords.records, outcomes: funnelRecords.outcomes, unfinished: going, hours: input.hours, since, now: input.now });
384
400
  const funnelBefore = stepFunnel({ declaration: d, records: funnelBoth.records, outcomes: funnelBoth.outcomes, unfinished: going, hours: input.hours, since: before, now: since });