@jive-sh/workflow-platform 0.6.2 → 0.7.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 (89) hide show
  1. package/README.md +189 -42
  2. package/dist/budget-states.js +1 -1
  3. package/dist/budget-states.js.map +1 -1
  4. package/dist/dashboard/dashboard.css +42 -28
  5. package/dist/dashboard/drilldown.js +35 -4
  6. package/dist/dashboard/drilldown.js.map +1 -1
  7. package/dist/dashboard/run-doing-words.js +29 -0
  8. package/dist/dashboard/run-doing-words.js.map +1 -0
  9. package/dist/dashboard/setting-words.js +18 -0
  10. package/dist/dashboard/setting-words.js.map +1 -0
  11. package/dist/dashboard/spending-words.js +2 -10
  12. package/dist/dashboard/spending-words.js.map +1 -1
  13. package/dist/index.js +76 -13
  14. package/dist/index.js.map +1 -1
  15. package/dist/keep-running.js +4 -2
  16. package/dist/keep-running.js.map +1 -1
  17. package/dist/pick-wakes.js +2 -2
  18. package/dist/retention.js +59 -0
  19. package/dist/retention.js.map +1 -0
  20. package/dist/settings.js +88 -0
  21. package/dist/settings.js.map +1 -0
  22. package/dist/spending-limit.js +15 -21
  23. package/dist/spending-limit.js.map +1 -1
  24. package/dist/step-times.js +114 -0
  25. package/dist/step-times.js.map +1 -0
  26. package/dist/steps.js +399 -114
  27. package/dist/steps.js.map +1 -1
  28. package/dist/storage/agent-claims.js +3 -0
  29. package/dist/storage/agent-claims.js.map +1 -0
  30. package/dist/storage/budgets.js +40 -4
  31. package/dist/storage/budgets.js.map +1 -1
  32. package/dist/storage/engine-records.js +26 -10
  33. package/dist/storage/engine-records.js.map +1 -1
  34. package/dist/storage/sqlite-store.js +198 -20
  35. package/dist/storage/sqlite-store.js.map +1 -1
  36. package/dist/storage/task-store.js +11 -5
  37. package/dist/storage/task-store.js.map +1 -1
  38. package/dist/system-workflows.js +54 -0
  39. package/dist/system-workflows.js.map +1 -0
  40. package/dist/tasks.js +72 -29
  41. package/dist/tasks.js.map +1 -1
  42. package/dist/views/runs-now.js +80 -38
  43. package/dist/views/runs-now.js.map +1 -1
  44. package/dist/views/step-graph.js +6 -1
  45. package/dist/views/step-graph.js.map +1 -1
  46. package/dist/views/workflows-view.js +29 -23
  47. package/dist/views/workflows-view.js.map +1 -1
  48. package/package.json +1 -1
  49. package/src/budget-states.ts +2 -3
  50. package/src/dashboard/dashboard.css +42 -28
  51. package/src/dashboard/drilldown.ts +32 -5
  52. package/src/dashboard/index.tsx +1 -1
  53. package/src/dashboard/limits-and-runs.tsx +191 -0
  54. package/src/dashboard/queue-bar.tsx +30 -11
  55. package/src/dashboard/queue-chart.tsx +1 -2
  56. package/src/dashboard/run-doing-words.ts +41 -0
  57. package/src/dashboard/setting-words.ts +30 -0
  58. package/src/dashboard/spending-limit-control.tsx +5 -8
  59. package/src/dashboard/spending-words.ts +5 -23
  60. package/src/dashboard/time-distribution.tsx +61 -0
  61. package/src/dashboard/workflow-dag.tsx +247 -129
  62. package/src/dashboard/workflow-drilldown.tsx +13 -71
  63. package/src/dashboard/workflows-dashboard.tsx +345 -227
  64. package/src/index.ts +86 -16
  65. package/src/keep-running.ts +6 -4
  66. package/src/pick-wakes.ts +2 -2
  67. package/src/project.ts +12 -0
  68. package/src/retention.ts +90 -0
  69. package/src/settings.ts +171 -0
  70. package/src/spending-limit.ts +25 -42
  71. package/src/step-times.ts +151 -0
  72. package/src/steps.ts +512 -135
  73. package/src/storage/agent-claims.ts +63 -0
  74. package/src/storage/budgets.ts +43 -4
  75. package/src/storage/engine-records.ts +28 -11
  76. package/src/storage/sqlite-store.ts +225 -32
  77. package/src/storage/step-records.ts +59 -7
  78. package/src/storage/task-store.ts +29 -29
  79. package/src/system-workflows.ts +70 -0
  80. package/src/tasks.ts +69 -30
  81. package/src/views/runs-now.ts +119 -51
  82. package/src/views/step-graph.ts +11 -2
  83. package/src/views/workflows-view.ts +80 -39
  84. package/src/workflow-dag.test.tsx +89 -0
  85. package/src/workflow-page.test.tsx +170 -0
  86. package/dist/views/workflow-flows.js +0 -53
  87. package/dist/views/workflow-flows.js.map +0 -1
  88. package/src/dashboard/step-graph.tsx +0 -106
  89. package/src/views/workflow-flows.ts +0 -97
@@ -0,0 +1,170 @@
1
+ /**
2
+ * ONE PAGE FOR EVERY WORKFLOW. Alex, 2026-11-21: "a workflow is a workflow. stop building bespoke pages", and "why does only
3
+ * the decompile workflow sub view have a graph?".
4
+ *
5
+ * 1. The top (made of workflows), a part (made of workflows, used as a step) and a leaf (on its queue) render the same
6
+ * sections in the same order, each with a box for every one of its steps, each box with its description in words.
7
+ * 2. A workflow that declares no graph still has one: its steps in their declared order, from the run's start to its end,
8
+ * and ELK lays every edge of it out.
9
+ */
10
+ import { Database } from 'bun:sqlite';
11
+ import { afterAll, expect, test } from 'bun:test';
12
+ import { Effect, Schema } from 'effect';
13
+ import fs from 'node:fs';
14
+ import path from 'node:path';
15
+ import { renderToStaticMarkup } from 'react-dom/server';
16
+ import { createWorkflowPlatform, RUN_ENDS, RUN_STARTS, sqliteStorage, type WorkflowFigures } from './index';
17
+ import { layOut } from './dashboard/workflow-dag';
18
+ import { SYSTEM_WORKFLOW_WORDS, WorkflowPage, type WorkflowsPageData } from './dashboard/workflows-dashboard';
19
+
20
+ const scratch = path.join(import.meta.dir, '..', '.scratch', `workflow-page-${process.pid}`);
21
+ fs.mkdirSync(scratch, { recursive: true });
22
+ afterAll(() => fs.rmSync(scratch, { recursive: true, force: true }));
23
+ const budgetsFile = path.join(scratch, 'budgets.db');
24
+ new Database(budgetsFile, { create: true }).exec('CREATE TABLE workflow_budgets (workflow TEXT PRIMARY KEY, budget INTEGER NOT NULL, runs INTEGER, changed_at REAL NOT NULL)');
25
+ new Database(path.join(scratch, 'engine.db'), { create: true })
26
+ .exec('CREATE TABLE cluster_messages (request_id INTEGER, entity_type TEXT, entity_id TEXT, tag TEXT, processed INTEGER NOT NULL DEFAULT 0); CREATE TABLE cluster_replies (request_id INTEGER, payload TEXT);');
27
+ const processes = { thisProcess: () => ({ pid: process.pid, startedAt: 0 }), isAlive: () => true };
28
+ const platform = createWorkflowPlatform<never>({
29
+ project: {
30
+ sourceRoot: scratch, tree: { root: scratch, snapshots: path.join(scratch, 'snapshots'), notTree: [] },
31
+ texts: { write: () => '', read: () => '' },
32
+ runLightNow: () => ({ code: 0, stdout: '', stdoutBytes: new Uint8Array(), stderr: '' }),
33
+ processes, stepRecordVariable: 'TEST_STEP_RECORD', isTransientFailure: () => false, cpu: { limit: () => 1, newestUse: () => null },
34
+ },
35
+ storage: sqliteStorage({ stepRecordsFile: () => path.join(scratch, 'records.db'), engineFile: () => path.join(scratch, 'engine.db'), budgetsFile: () => budgetsFile, processes }),
36
+ });
37
+ const { defineStep, defineWorkflow, defineWorkflowStep, graphOfFeeds } = platform.steps;
38
+ const run = { payload: { run: Schema.String }, idempotencyKey: ({ run: r }: { readonly run: string }) => r, success: Schema.Void, error: Schema.String };
39
+
40
+ const PICK = defineStep({ name: 'Pick a page', runs: 'deterministic', description: 'Takes the first page of its queue.', at: import.meta.path, success: Schema.String });
41
+ const WRITE = defineStep({ name: 'Write the page', runs: 'agentic', model: 'test-model', description: 'An agent writes the page it took.', at: import.meta.path, success: Schema.String });
42
+ // The leaf: a workflow on its queue that declares no graph.
43
+ defineWorkflow({ item: 'page', finishedWord: 'done', at: import.meta.path, description: 'Writes pages.', steps: () => [PICK, WRITE], items: () => Effect.succeed(['a']), outcomes: () => [] })('Page writing', run);
44
+ const madeOf = (name: string, steps: ReadonlyArray<string>, mainStep?: string) =>
45
+ defineWorkflow({ item: null, at: import.meta.path, description: `${name}.`, steps: () => steps.map(defineWorkflowStep), graph: () => graphOfFeeds(steps), ...(mainStep === undefined ? {} : { mainStep }) })(name, run);
46
+ madeOf('Page part', ['Page writing'], 'Page writing');
47
+ madeOf('Page project', ['Page part']);
48
+ // A workflow on no item that a run of another starts as a step: its tasks are that workflow's, passing through it.
49
+ const CHECK = defineStep({ name: 'Check', runs: 'deterministic', description: 'Checks the page.', at: import.meta.path, success: Schema.String });
50
+ const Checking = defineWorkflow({ item: null, at: import.meta.path, description: 'Checks a page.', steps: () => [CHECK] })('Page check', run);
51
+ const CHECKING = platform.steps.defineSubWorkflow({ workflow: Checking, at: import.meta.path, success: Schema.Void });
52
+ defineWorkflow({ item: 'page', finishedWord: 'done', at: import.meta.path, description: 'Reviews pages.', steps: () => [CHECKING], items: () => Effect.succeed(['a']), outcomes: () => [] })('Page review', run);
53
+
54
+ const now = Date.now() / 1000;
55
+ const read = async () => {
56
+ const view = await Effect.runPromise(platform.view({ now, top: 'Page project' }));
57
+ const data: WorkflowsPageData = { view, runsNow: [], cpu: { limit: 1, use: null } };
58
+ const figuresOf = async (workflow: string): Promise<WorkflowFigures> => (await Effect.runPromise(platform.figures({ workflow, now, hours: 24 })))!;
59
+ return { data, figuresOf };
60
+ };
61
+
62
+ /** A page as a reader's browser gets it from the server, with its workflow's figures read. */
63
+ const page = async (at: ReadonlyArray<string>, workflow: string) => {
64
+ const { data, figuresOf } = await read();
65
+ const html = renderToStaticMarkup(<WorkflowPage data={data} figures={{ data: await figuresOf(workflow), error: null }} path={at} hrefOf={(p) => `/${p.join('/')}`} now={now} />);
66
+ return {
67
+ sections: [...html.matchAll(/data-section="([^"]+)"/g)].map((m) => m[1]),
68
+ boxes: [...html.matchAll(/data-step="([^"]+)" class="wp-node"/g)].map((m) => m[1]),
69
+ descriptions: [...html.matchAll(/<p class="wp-node-what">([^<]*)<\/p>/g)].map((m) => m[1]),
70
+ };
71
+ };
72
+
73
+ test('1. the top, a part and a leaf render the same sections in the same order, a box for each step with its description', async () => {
74
+ const top = await page([], 'Page project');
75
+ const part = await page(['Page part'], 'Page part');
76
+ const leaf = await page(['Page part', 'Page writing'], 'Page writing');
77
+ const sections = ['Tasks', 'Runs', 'Limits', 'Steps', 'Tasks over time', 'Blocked, by reason', 'Queued, needing an agent', 'What its runs gave', 'Where runs stopped'];
78
+ expect({ top: top.sections, part: part.sections, leaf: leaf.sections }).toEqual({ top: sections, part: sections, leaf: sections });
79
+ expect({ top: top.boxes, part: part.boxes, leaf: leaf.boxes }).toEqual({ top: ['Page part'], part: ['Page writing'], leaf: ['Pick a page', 'Write the page'] });
80
+ expect(leaf.descriptions).toEqual(['Takes the first page of its queue.', 'An agent writes the page it took.']);
81
+ });
82
+
83
+ test("1b. a top-level page shows the platform's own workflows apart, in words, with their run limits; a part's page does not; and one's own page says it is the platform's", async () => {
84
+ const { data, figuresOf } = await read();
85
+ const render = async (at: ReadonlyArray<string>, workflow: string) =>
86
+ renderToStaticMarkup(<WorkflowPage data={data} figures={{ data: await figuresOf(workflow), error: null }} path={at} hrefOf={(p) => `/${p.join('/')}`} now={now} />);
87
+ const top = await render([], 'Page project');
88
+ const block = top.slice(top.indexOf('data-platform-workflows'));
89
+ expect(block).toContain('<h3 class="wp-h3">Platform workflows</h3>');
90
+ expect(block).toContain('<a href="/Retention">Retention</a>');
91
+ expect(block).toContain(SYSTEM_WORKFLOW_WORDS);
92
+ expect(block).toContain('data-counts="runs"');
93
+ expect(block).toContain('no limit');
94
+ expect(block).toContain('10,000 runs');
95
+ expect(await render(['Page part'], 'Page part')).not.toContain('data-platform-workflows');
96
+ const own = await render(['Retention'], 'Retention');
97
+ expect({ words: own.includes(SYSTEM_WORKFLOW_WORDS), block: own.includes('data-platform-workflows') }).toEqual({ words: true, block: false });
98
+ });
99
+
100
+ test('2. a workflow that declares no graph has its steps in their declared order, and every edge of it is laid out', async () => {
101
+ const { figuresOf } = await read();
102
+ const figures = await figuresOf('Page writing');
103
+ expect({ declared: figures.graph.declared, edges: figures.graph.edges.map((e) => `${e.from} > ${e.to}`) })
104
+ .toEqual({ declared: false, edges: [`${RUN_STARTS} > Pick a page`, 'Pick a page > Write the page', `Write the page > ${RUN_ENDS}`] });
105
+ const laid = await layOut({ graph: figures.graph, heightOf: () => 80 });
106
+ expect({ boxes: [...laid.boxes.keys()], edges: laid.edges.filter((e) => e.points.length >= 2).length })
107
+ .toEqual({ boxes: [RUN_STARTS, 'Pick a page', 'Write the page', RUN_ENDS], edges: 3 });
108
+ // Down the page: each box below the one before it.
109
+ const ys = [RUN_STARTS, 'Pick a page', 'Write the page', RUN_ENDS].map((b) => laid.boxes.get(b)!.y);
110
+ expect(ys).toEqual([...ys].sort((a, b) => a - b));
111
+ });
112
+
113
+ /** Each addition of calls on a page, as its rows read: "1 in progress, 1 failed, 3 done, 5 calls, 24 h". */
114
+ const callsBars = (html: string): ReadonlyArray<string> =>
115
+ [...html.matchAll(/<table class="wp-sum" data-counts="calls">(.*?)<\/table>/g)]
116
+ .map((m) => [...m[1]!.matchAll(/class="wp-sum-n">([^<]*)<\/td><td class="wp-sum-label">([^<]*)</g)].map((x) => `${x[1]} ${x[2]}`).join(', '));
117
+
118
+ test('3. a workflow run as a step of another shows that workflow\'s calls of it as a bar, on its box there and on its own page alike', async () => {
119
+ const { data, figuresOf } = await read();
120
+ const cost = { calls: 5, failed: 1, open: 1, seconds: 10, inputTokens: 0, outputTokens: 0, cpuSeconds: 1, compiles: 0, items: 5 };
121
+ const parent = await figuresOf('Page review');
122
+ const onParent = renderToStaticMarkup(<WorkflowPage data={data} figures={{ data: { ...parent, steps: parent.steps.map((s) => (s.name === 'Page check' ? { ...s, cost } : s)) }, error: null }} path={['Page review']} hrefOf={(p) => `/${p.join('/')}`} now={now} />);
123
+ const own = await figuresOf('Page check');
124
+ expect(own.passingThrough).toEqual([{ workflow: 'Page review', step: 'Page check', cost: null }]);
125
+ const onItsOwn = renderToStaticMarkup(<WorkflowPage data={data} figures={{ data: { ...own, passingThrough: [{ ...own.passingThrough[0]!, cost }] }, error: null }} path={['Page review', 'Page check']} hrefOf={(p) => `/${p.join('/')}`} now={now} />);
126
+ const bar = '1 in progress, 1 failed, 3 done, 5 calls, 24 h';
127
+ expect({ onParent: callsBars(onParent), onItsOwn: callsBars(onItsOwn) }).toEqual({ onParent: [bar], onItsOwn: [bar] });
128
+ });
129
+
130
+ /** Where a page says it is: its path's links and its last part, its title, and the other top-level workflows it names. */
131
+ const whereItIs = async (at: ReadonlyArray<string>, workflow: string) => {
132
+ const { data, figuresOf } = await read();
133
+ const html = renderToStaticMarkup(<WorkflowPage data={data} figures={{ data: await figuresOf(workflow), error: null }} path={at} hrefOf={(p) => `/${p.join('/')}`} now={now} />);
134
+ const nav = /<nav class="wp-crumbs"[^>]*>(.*?)<\/nav>/.exec(html)?.[1] ?? '';
135
+ return {
136
+ links: [...nav.matchAll(/<a href="([^"]*)">([^<]*)<\/a>/g)].map((m) => `${m[2]} ${m[1]}`),
137
+ here: /<span class="wp-crumb-here"[^>]*>([^<]*)<\/span>/.exec(nav)?.[1] ?? null,
138
+ title: /<h2 class="wp-title">Workflow: <!-- -->([^<]*)/.exec(html)?.[1] ?? /<h2 class="wp-title">Workflow: ([^<]*)/.exec(html)?.[1] ?? null,
139
+ others: /<p class="wp-line wp-others">Other top-level workflows: (.*?)<\/p>/.exec(html)?.[1]?.replace(/<[^>]*>/g, '') ?? null,
140
+ };
141
+ };
142
+
143
+ test('4. every page says its path from the top, every part a link but its own, then its title, and names no other workflow but other top-level ones', async () => {
144
+ expect(await whereItIs([], 'Page project')).toEqual({ links: [], here: 'Page project', title: 'Page project', others: 'Page review' });
145
+ expect(await whereItIs(['Page part'], 'Page part')).toEqual({ links: ['Page project /'], here: 'Page part', title: 'Page part', others: null });
146
+ expect(await whereItIs(['Page part', 'Page writing'], 'Page writing')).toEqual({ links: ['Page project /', 'Page part /Page part'], here: 'Page writing', title: 'Page writing', others: null });
147
+ // Another top-level workflow's page names the project's top among the others, never itself.
148
+ expect(await whereItIs(['Page review'], 'Page review')).toEqual({ links: [], here: 'Page review', title: 'Page review', others: 'Page project' });
149
+ });
150
+
151
+ /** Each addition of tasks on a page, as its rows read: "3 queued, 1 in progress, 0 blocked, 6 done, 10 tasks in Page writing". */
152
+ const tasksBars = (html: string): ReadonlyArray<string> =>
153
+ [...html.matchAll(/<table class="wp-sum" data-counts="tasks">(.*?)<\/table>/g)]
154
+ .map((m) => [...m[1]!.matchAll(/class="wp-sum-n">([^<]*)<\/td><td class="wp-sum-label">([^<]*)</g)].map((x) => `${x[1]} ${x[2]}`).join(', '));
155
+
156
+ test("5. a workflow made of workflows shows its main step's tasks, named as that step's, on its box and on its own page; one naming none says its tasks are its steps'", async () => {
157
+ const { data: read0, figuresOf } = await read();
158
+ const counted = { queued: 3, 'in progress': 1, blocked: 0, done: 6 };
159
+ const data: WorkflowsPageData = { ...read0, view: { ...read0.view, workflows: read0.view.workflows.map((w) => (w.name === 'Page writing' ? { ...w, queue: counted } : w)) } };
160
+ expect(data.view.workflows.find((w) => w.name === 'Page part')?.startsOn).toEqual({ kind: 'its steps', mainStep: 'Page writing' });
161
+ const render = async (at: ReadonlyArray<string>, workflow: string) =>
162
+ renderToStaticMarkup(<WorkflowPage data={data} figures={{ data: await figuresOf(workflow), error: null }} path={at} hrefOf={(p) => `/${p.join('/')}`} now={now} />);
163
+ const bar = '3 queued (0 need agent), 1 in progress, 0 blocked, 6 done, 10 tasks in Page writing';
164
+ const top = await render([], 'Page project');
165
+ const part = await render(['Page part'], 'Page part');
166
+ // The top's Tasks section (before its first box) names no main step; the part's box on it, and the part's own page, show Page writing's.
167
+ expect({ topOwn: top.slice(0, top.indexOf('data-step=')).includes('data-counts="tasks"'), top: tasksBars(top), part: tasksBars(part).slice(0, 1) })
168
+ .toEqual({ topOwn: false, top: [bar], part: [bar] });
169
+ expect(top).toContain("Its tasks are its steps&#x27;, each counted under its own workflow.");
170
+ });
@@ -1,53 +0,0 @@
1
- /** Whether `to` reaches `from` through `feeds`: work goes from `to`, by way of others, to `from`. */
2
- const reaches = (feeds, start, target) => {
3
- const seen = new Set([start]);
4
- const next = [start];
5
- while (next.length > 0) {
6
- const at = next.pop();
7
- for (const f of feeds) {
8
- if (f.from !== at || seen.has(f.to))
9
- continue;
10
- if (f.to === target)
11
- return true;
12
- seen.add(f.to);
13
- next.push(f.to);
14
- }
15
- }
16
- return false;
17
- };
18
- export const workflowFlows = (input) => {
19
- const names = new Set(input.declared.map((d) => d.name));
20
- const recorded = (from, to) => input.returned.find((n) => n.from === from && n.to === to);
21
- const feeds = input.declared.flatMap((d) => (d.fedBy ?? []).filter((f) => names.has(f) && f !== d.name).map((f) => ({ from: f, to: d.name })));
22
- const declaredFlows = feeds.map((f) => {
23
- const r = recorded(f.from, f.to);
24
- return { from: f.from, to: f.to, kind: 'feeds', declared: true, notes: r?.notes ?? 0, last: r?.last ?? null, waiting: 0, why: null };
25
- });
26
- const recordedOnly = input.returned
27
- .filter((n) => names.has(n.from) && names.has(n.to) && !feeds.some((f) => f.from === n.from && f.to === n.to))
28
- .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 }));
29
- // 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.
30
- const waitedOn = input.waits
31
- .filter((w) => names.has(w.on) && w.on !== w.workflow && !feeds.some((f) => f.from === w.on && f.to === w.workflow))
32
- .map((w) => ({ from: w.workflow, to: w.on, kind: 'waits on', declared: false, notes: 0, last: null, waiting: w.tasks, why: w.label }));
33
- return [...declaredFlows, ...recordedOnly, ...waitedOn];
34
- };
35
- /** Each workflow's place: its stage by `stageOf` in `stages`' order (one not among them after them), then its depth there. */
36
- export const pipelinePlaces = (input) => {
37
- const stageIndex = (s) => (input.stages.includes(s) ? input.stages.indexOf(s) : input.stages.length);
38
- const stageOf = new Map(input.workflows.map((w) => [w.name, stageIndex(w.stage)]));
39
- // Forward work only: feeds, and input given to one not upstream. A send-back points against the pipeline.
40
- const forward = input.flows.filter((f) => f.kind !== 'sends back');
41
- const depth = new Map();
42
- const depthOf = (name, path) => {
43
- const known = depth.get(name);
44
- if (known !== undefined)
45
- return known;
46
- const into = forward.filter((f) => f.to === name && !path.has(f.from) && stageOf.get(f.from) === stageOf.get(name));
47
- const d = into.length === 0 ? 0 : Math.max(...into.map((f) => depthOf(f.from, new Set([...path, name])) + 1));
48
- depth.set(name, d);
49
- return d;
50
- };
51
- return input.workflows.map((w) => ({ workflow: w.name, stage: stageIndex(w.stage), depth: depthOf(w.name, new Set()) }));
52
- };
53
- //# sourceMappingURL=workflow-flows.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"workflow-flows.js","sourceRoot":"","sources":["../../../../src/views/workflow-flows.ts"],"names":[],"mappings":"AAsCA,qGAAqG;AACrG,MAAM,OAAO,GAAG,CAAC,KAAoE,EAAE,KAAa,EAAE,MAAc,EAAW,EAAE;IAC/H,MAAM,IAAI,GAAG,IAAI,GAAG,CAAS,CAAC,KAAK,CAAC,CAAC,CAAC;IACtC,MAAM,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC;IACrB,OAAO,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACvB,MAAM,EAAE,GAAG,IAAI,CAAC,GAAG,EAAG,CAAC;QACvB,KAAK,MAAM,CAAC,IAAI,KAAK,EAAE,CAAC;YACtB,IAAI,CAAC,CAAC,IAAI,KAAK,EAAE,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;gBAAE,SAAS;YAC9C,IAAI,CAAC,CAAC,EAAE,KAAK,MAAM;gBAAE,OAAO,IAAI,CAAC;YACjC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;YACf,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QAClB,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,KAI7B,EAA+B,EAAE;IAChC,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;IACzD,MAAM,QAAQ,GAAG,CAAC,IAAY,EAAE,EAAU,EAAE,EAAE,CAAC,KAA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AAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;QACpH,MAAM,CAAC,GAAG,IAAI,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,IAAI,GAAG,CAAC,CAAC,GAAG,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAC9G,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;QACnB,OAAO,CAAC,CAAC;IACX,CAAC,CAAC;IACF,OAAO,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,IAAI,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AAC3H,CAAC,CAAC"}
@@ -1,106 +0,0 @@
1
- 'use client';
2
-
3
- /**
4
- * ONE WORKFLOW'S DECLARED STEP GRAPH, DRAWN SMALL: its steps one under another in the order a run takes them, a step that
5
- * does not run deterministically marked with how it runs, in words, a sub-workflow step a link to its workflow's own level, and every edge an arrow with a number. The numbers' list below says each edge's condition and
6
- * how many runs took it in the window. An edge to the next row goes straight down; any other runs in a lane of its own on
7
- * the right, so it crosses no step.
8
- */
9
- import { useLayoutEffect, useRef, useState } from 'react';
10
- import { A_STEP_FAILS, RUN_ENDS, RUN_STARTS } from '../graph';
11
- import type { WorkflowGraph } from '../views/step-graph';
12
-
13
- /**
14
- * Each step's row, in the order the workflow declares its steps, which is the order a run takes them: the run's start (and
15
- * "a step fails", where an edge leaves it) first, then each step on a row of its own, then the run's end. Pure.
16
- */
17
- export const stepRows = (graph: WorkflowGraph): ReadonlyArray<ReadonlyArray<string>> => [
18
- [RUN_STARTS, ...(graph.edges.some((e) => e.from === A_STEP_FAILS) ? [A_STEP_FAILS] : [])],
19
- ...graph.steps.map((s) => [s.name]),
20
- [RUN_ENDS],
21
- ];
22
-
23
- export function StepGraph({ graph, hrefOfWorkflow }: { readonly graph: WorkflowGraph; readonly hrefOfWorkflow?: (workflow: string) => string }) {
24
- const box = useRef<HTMLDivElement>(null);
25
- const [paths, setPaths] = useState<ReadonlyArray<{ readonly key: string; readonly n: number; readonly d: string; readonly at: { readonly x: number; readonly y: number } }>>([]);
26
- const [size, setSize] = useState({ w: 0, h: 0 });
27
- const rows = stepRows(graph);
28
- const declared = new Map(graph.steps.map((s) => [s.name, s]));
29
- useLayoutEffect(() => {
30
- const el = box.current;
31
- if (el === null) return;
32
- const draw = () => {
33
- const at = el.getBoundingClientRect();
34
- const rect = (name: string) => el.querySelector(`[data-step="${CSS.escape(name)}"]`)?.getBoundingClientRect() ?? null;
35
- const right = Math.max(0, ...[...el.querySelectorAll('[data-step]')].map((s) => s.getBoundingClientRect().right - at.left));
36
- let lanes = 0;
37
- setSize({ w: el.scrollWidth, h: el.scrollHeight });
38
- setPaths(graph.edges.flatMap((e, i) => {
39
- const a = rect(e.from), b = rect(e.to);
40
- if (a === null || b === null) return [];
41
- const ax = a.left + a.width / 2 - at.left, bx = b.left + b.width / 2 - at.left;
42
- const nextRow = b.top >= a.bottom - 1 && b.top - a.bottom < 40;
43
- if (nextRow) {
44
- const y1 = a.bottom - at.top, y2 = b.top - at.top;
45
- return [{ key: `${e.from}>${e.to}`, n: i + 1, d: `M${ax},${y1} C${ax},${(y1 + y2) / 2} ${bx},${(y1 + y2) / 2} ${bx},${y2 - 5}`, at: { x: (ax + bx) / 2, y: (y1 + y2) / 2 } }];
46
- }
47
- // Back up, along its own row, or past a row: in a lane on the right.
48
- const lane = right + 12 + 10 * lanes++;
49
- const ay = a.top + a.height / 2 - at.top, by = b.top + b.height / 2 - at.top;
50
- return [{ key: `${e.from}>${e.to}`, n: i + 1, d: `M${a.right - at.left},${ay} H${lane} V${by} H${b.right - at.left + 5}`, at: { x: lane, y: (ay + by) / 2 } }];
51
- }));
52
- };
53
- draw();
54
- const watch = new ResizeObserver(draw);
55
- watch.observe(el);
56
- return () => watch.disconnect();
57
- }, [graph]);
58
-
59
- if (!graph.declared) return <p className="wp-line wp-bad">No step graph declared yet.</p>;
60
- return (
61
- <div className="wp-steps">
62
- <div ref={box} className="wp-steps-box">
63
- <svg className="wp-steps-edges" width={size.w} height={size.h} aria-hidden="true">
64
- <defs>
65
- <marker id="wp-step-arrow" viewBox="0 0 8 8" refX="7" refY="4" markerWidth="6" markerHeight="6" orient="auto-start-reverse">
66
- <path d="M0,0 L8,4 L0,8 z" fill="var(--wp-edge)" />
67
- </marker>
68
- </defs>
69
- {paths.map((p) => <path key={p.key} d={p.d} fill="none" stroke="var(--wp-edge)" strokeWidth="1.1" markerEnd="url(#wp-step-arrow)" />)}
70
- {paths.map((p) => (
71
- <g key={`n:${p.key}`}>
72
- <circle cx={p.at.x} cy={p.at.y} r="7" fill="var(--wp-bg)" stroke="var(--wp-edge)" strokeWidth="0.8" />
73
- <text x={p.at.x} y={p.at.y + 3} fontSize="8.5" textAnchor="middle" fill="var(--wp-fg)">{p.n}</text>
74
- </g>
75
- ))}
76
- </svg>
77
- {rows.map((row) => (
78
- <div key={row.join('|')} className="wp-steps-row">
79
- {row.map((name) => {
80
- const step = declared.get(name);
81
- const className = name === RUN_STARTS || name === RUN_ENDS || name === A_STEP_FAILS ? 'wp-step wp-step-end' : 'wp-step';
82
- const title = step?.description ?? name;
83
- // A sub-workflow step opens its workflow's own level, as its row in the list of steps does.
84
- if (step !== undefined && step.workflow !== null && hrefOfWorkflow !== undefined) {
85
- return <a key={name} data-step={name} className={`${className} wp-step-link`} href={hrefOfWorkflow(step.workflow)} title={title}>{name}<em> · sub-workflow, open ›</em></a>;
86
- }
87
- return (
88
- <span key={name} data-step={name} className={className} title={title}>
89
- {name}{step === undefined || step.runs === null || step.runs === 'deterministic' ? null : <em> · {step.runs}</em>}
90
- </span>
91
- );
92
- })}
93
- </div>
94
- ))}
95
- </div>
96
- <ol className="wp-steps-when">
97
- {graph.edges.map((e) => (
98
- <li key={`${e.from}>${e.to}`}>{e.from} → {e.to}: {e.when}{e.runs === 0 ? '' : ` (${e.runs.toLocaleString('en-US')} run${e.runs === 1 ? '' : 's'})`}</li>
99
- ))}
100
- </ol>
101
- {graph.undeclared.length === 0 ? null : (
102
- <p className="wp-line wp-bad">Taken but not declared: {graph.undeclared.map((e) => `${e.from} → ${e.to} (${e.runs})`).join('; ')}</p>
103
- )}
104
- </div>
105
- );
106
- }
@@ -1,97 +0,0 @@
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
- };