@jive-sh/workflow-platform 0.3.3 → 0.5.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 (61) hide show
  1. package/README.md +68 -23
  2. package/dist/dashboard/agent-usage.js +25 -0
  3. package/dist/dashboard/agent-usage.js.map +1 -0
  4. package/dist/dashboard/drilldown.js +16 -0
  5. package/dist/dashboard/drilldown.js.map +1 -0
  6. package/dist/dashboard/queue-lines.js +44 -0
  7. package/dist/dashboard/queue-lines.js.map +1 -0
  8. package/dist/index.js +8 -6
  9. package/dist/index.js.map +1 -1
  10. package/dist/keep-running.js +1 -1
  11. package/dist/keep-running.js.map +1 -1
  12. package/dist/pick-wakes.js +4 -4
  13. package/dist/pick-wakes.js.map +1 -1
  14. package/dist/queue-counts.js +7 -9
  15. package/dist/queue-counts.js.map +1 -1
  16. package/dist/steps.js +157 -41
  17. package/dist/steps.js.map +1 -1
  18. package/dist/storage/sqlite-store.js +117 -38
  19. package/dist/storage/sqlite-store.js.map +1 -1
  20. package/dist/storage/task-store.js +14 -1
  21. package/dist/storage/task-store.js.map +1 -1
  22. package/dist/tasks.js +215 -267
  23. package/dist/tasks.js.map +1 -1
  24. package/dist/views/runs-now.js +3 -2
  25. package/dist/views/runs-now.js.map +1 -1
  26. package/dist/views/step-funnel.js +1 -1
  27. package/dist/views/step-funnel.js.map +1 -1
  28. package/dist/views/step-graph.js +1 -1
  29. package/dist/views/step-graph.js.map +1 -1
  30. package/dist/views/workflow-flows.js +2 -2
  31. package/dist/views/workflow-flows.js.map +1 -1
  32. package/dist/views/workflows-view.js +83 -17
  33. package/dist/views/workflows-view.js.map +1 -1
  34. package/package.json +1 -1
  35. package/src/dashboard/agent-usage-line.tsx +28 -0
  36. package/src/dashboard/agent-usage.ts +48 -0
  37. package/src/dashboard/dashboard.css +70 -29
  38. package/src/dashboard/drilldown.ts +43 -0
  39. package/src/dashboard/index.tsx +1 -0
  40. package/src/dashboard/machine-controls.tsx +53 -0
  41. package/src/dashboard/queue-bar.tsx +43 -0
  42. package/src/dashboard/queue-chart.tsx +89 -76
  43. package/src/dashboard/queue-lines.ts +87 -0
  44. package/src/dashboard/step-graph.tsx +18 -10
  45. package/src/dashboard/workflow-dag.tsx +31 -103
  46. package/src/dashboard/workflow-drilldown.tsx +89 -0
  47. package/src/dashboard/workflows-dashboard.tsx +117 -42
  48. package/src/index.ts +11 -9
  49. package/src/keep-running.ts +3 -3
  50. package/src/pick-wakes.ts +14 -9
  51. package/src/queue-counts.ts +10 -14
  52. package/src/steps.ts +213 -52
  53. package/src/storage/sqlite-store.ts +126 -39
  54. package/src/storage/step-records.ts +14 -3
  55. package/src/storage/task-store.ts +97 -22
  56. package/src/tasks.ts +235 -301
  57. package/src/views/runs-now.ts +5 -4
  58. package/src/views/step-funnel.ts +2 -2
  59. package/src/views/step-graph.ts +4 -4
  60. package/src/views/workflow-flows.ts +7 -7
  61. package/src/views/workflows-view.ts +117 -35
package/src/index.ts CHANGED
@@ -14,7 +14,7 @@ import { makePickWakes } from './pick-wakes';
14
14
  import { makeStepFiles } from './step-files';
15
15
  import { makeStepUsage } from './step-usage';
16
16
  import { keptRunningByItsBudget, makeSteps, runLimitOf } from './steps';
17
- import { makeTasks, type TaskRules } from './tasks';
17
+ import { blockedReasons, makeTasks } from './tasks';
18
18
  import { buildWorkflowFigures, buildWorkflowsView, type WorkflowFigures, type WorkflowsView, type WorkflowView } from './views/workflows-view';
19
19
  import { makeQueueCounts } from './queue-counts';
20
20
  import { sqliteBudgets, type LimitStore } from './storage/budgets';
@@ -52,6 +52,7 @@ export * from './views/step-graph';
52
52
  export * from './views/workflows-view';
53
53
  export * from './views/workflow-flows';
54
54
  export type { NewNote, TaskStore, TextChange } from './storage/task-store';
55
+ export type { AgentUsage, UsageLimit } from './dashboard/agent-usage';
55
56
 
56
57
  /** Where a project's records live: each store an interface, so another database can stand behind any of them. */
57
58
  export interface WorkflowStorage {
@@ -89,25 +90,23 @@ export const sqliteStorage = (options: {
89
90
 
90
91
  /**
91
92
  * ONE PROJECT'S PLATFORM. `Phase` is where the project shows a workflow; `R` what its workflows' lists of work run under.
92
- * `rules` adds the project's own queue rules (`TaskRules`).
93
93
  */
94
94
  export const createWorkflowPlatform = <Phase extends string, R>(input: {
95
95
  readonly project: WorkflowProject;
96
96
  readonly storage: WorkflowStorage;
97
- readonly rules: TaskRules;
98
97
  }) => {
99
98
  const { project, storage } = input;
100
99
  const wakes = makePickWakes();
101
100
  const stepFiles = makeStepFiles({ tree: project.tree, runLightNow: project.runLightNow });
102
101
  const stepUsage = makeStepUsage({ variable: project.stepRecordVariable, addStepCompile: (record) => { Effect.runFork(Effect.catchTag(storage.stepRecords.addStepCompile(record), 'StorageError', (e) => Effect.logError(`[step-runs] a compile of step record ${record}: ${e.reason}`))); } });
103
- const tasks = makeTasks({ store: storage.tasks, engine: storage.engine, stepRecords: storage.stepRecords, wakes, texts: project.texts, rules: input.rules });
102
+ const tasks = makeTasks({ store: storage.tasks, engine: storage.engine, stepRecords: storage.stepRecords, wakes, texts: project.texts });
104
103
  const steps = makeSteps<Phase, R>({
105
104
  sourceRoot: project.sourceRoot, stepRecords: storage.stepRecords, engine: storage.engine, tasks, wakes, budgets: storage.budgets, stepFiles,
106
105
  CurrentStepUsage: stepUsage.CurrentStepUsage, isTransientFailure: project.isTransientFailure, thisProcess: project.processes.thisProcess, inputs: storage.inputs,
107
106
  queueChanged: (workflow) => queueCounts.changed(workflow),
108
107
  });
109
- const queueCounts = makeQueueCounts<R>({
110
- store: storage.tasks, tasks, wakes, readTaskInputs: steps.readTaskInputs,
108
+ const queueCounts = makeQueueCounts({
109
+ store: storage.tasks, tasks, wakes,
111
110
  withQueues: () => steps.declaredWorkflows().filter((d) => d.item !== null).map((d) => d.name),
112
111
  });
113
112
  /**
@@ -140,15 +139,18 @@ export const createWorkflowPlatform = <Phase extends string, R>(input: {
140
139
  * Every workflow as a dashboard shows it before one is opened, read now (`views/workflows-view.ts` `buildWorkflowsView`).
141
140
  * `phases` is the order the project's page shows them in.
142
141
  */
143
- const view = (r: { readonly now: number; readonly phases: ReadonlyArray<string> }): Effect.Effect<WorkflowsView, StorageError> => Effect.gen(function* () {
142
+ const view = (r: { readonly now: number; readonly phases: ReadonlyArray<string>; readonly top: { readonly name: string; readonly description: string } }): Effect.Effect<WorkflowsView, StorageError> => Effect.gen(function* () {
144
143
  const limits = yield* limitsNow();
145
- return yield* buildWorkflowsView({ declared: steps.declaredWorkflows(), phases: r.phases, now: r.now, taskStore: storage.tasks, locate, limitsOf: (name) => limits[name] ?? null });
144
+ return yield* buildWorkflowsView({ declared: steps.declaredWorkflows(), phases: r.phases, top: r.top, now: r.now, taskStore: storage.tasks, locate, limitsOf: (name) => limits[name] ?? null });
146
145
  });
147
146
 
148
147
  /** One workflow's figures over the `hours` before `now`, read from its own records (`buildWorkflowFigures`); none for one not declared. */
149
148
  const figures = (r: { readonly workflow: string; readonly now: number; readonly hours: number }): Effect.Effect<WorkflowFigures | null, StorageError> => {
150
149
  const declaration = steps.declaredWorkflows().find((d) => d.name === r.workflow);
151
- return declaration === undefined ? Effect.succeed(null) : buildWorkflowFigures({ declaration, now: r.now, hours: r.hours, records: storage.stepRecords, engine: storage.engine, locate });
150
+ return declaration === undefined ? Effect.succeed(null) : buildWorkflowFigures({
151
+ declaration, now: r.now, hours: r.hours, records: storage.stepRecords, engine: storage.engine, locate,
152
+ blocked: declaration.item === null ? Effect.succeed([]) : Effect.map(tasks.taskSummaries({ workflow: r.workflow }), blockedReasons),
153
+ });
152
154
  };
153
155
  return { project, storage, wakes, stepFiles, stepUsage, tasks, steps, view, figures, limitsNow, queueCounts };
154
156
  };
@@ -7,7 +7,7 @@
7
7
  * one trigger, with no code of its own: each turn it starts as many runs as the workflow's run limit keeps (`runLimit`) above
8
8
  * the runs going, as soon as a run ends and otherwise on a fallback timer. There is no sharing between workflows, no order,
9
9
  * no cap per item and no check of usage: a run with nothing to pick waits for an item (`steps.ts` `untilPicked`), and the
10
- * stuck bucket and the queue's order keep a run off what it cannot finish. A run limit of 0 holds one workflow.
10
+ * blocking a Pick runs and the queue's order keep a run off what it cannot finish. A run limit of 0 holds one workflow.
11
11
  */
12
12
  import { keptRunningByItsBudget, type WorkflowDeclaration } from './steps';
13
13
  import { runLimit, type WorkflowLimits } from './storage/budgets';
@@ -20,7 +20,7 @@ export const TURN_LIMIT_MS = 50_000;
20
20
  export const START_LIMIT_SECONDS = 20;
21
21
 
22
22
  /** The workflows this trigger keeps running, each with a budget. Pure. */
23
- export const budgetedWorkflows = <D extends Pick<WorkflowDeclaration<string, unknown>, 'pending' | 'steps'>>(declared: ReadonlyArray<D>): ReadonlyArray<D> =>
23
+ export const budgetedWorkflows = <D extends Pick<WorkflowDeclaration<string, unknown>, 'pending' | 'items' | 'steps'>>(declared: ReadonlyArray<D>): ReadonlyArray<D> =>
24
24
  declared.filter(keptRunningByItsBudget);
25
25
 
26
26
  /**
@@ -30,7 +30,7 @@ export const budgetedWorkflows = <D extends Pick<WorkflowDeclaration<string, unk
30
30
  export const runsToStart = (w: { readonly kept: number; readonly running: number }): number => Math.max(w.kept - w.running, 0);
31
31
 
32
32
  /** One turn's plan: for each budgeted workflow, the runs going and how many to start. Pure but for the reads it is given. */
33
- export const planRunStarts = <D extends Pick<WorkflowDeclaration<string, unknown>, 'name' | 'pending' | 'steps'>>(input: {
33
+ export const planRunStarts = <D extends Pick<WorkflowDeclaration<string, unknown>, 'name' | 'pending' | 'items' | 'steps'>>(input: {
34
34
  readonly declared: ReadonlyArray<D>;
35
35
  readonly limitsOf: (workflow: string) => WorkflowLimits;
36
36
  readonly runningRuns: (workflow: string) => number;
package/src/pick-wakes.ts CHANGED
@@ -45,8 +45,11 @@ export interface PickWakes {
45
45
  readonly onRunPlanChanged: (listener: (workflow: string | null) => void) => void;
46
46
  /** Calls `listener` on each wake that reaches this process, raised here or relayed: what else follows a queue's changes (`queue-counts.ts`). */
47
47
  readonly onWake: (listener: (wake: Wake) => void) => void;
48
- /** Waits until a wake reaches this workflow after `after` wakes; at once when one already has. */
49
- readonly untilPickWoken: (r: { readonly workflow: string; readonly after: number }) => Effect.Effect<void>;
48
+ /**
49
+ * Waits until a wake reaches this workflow after `after` wakes, at once when one already has: `woken`. `released`
50
+ * where its process is handing its runs to another (`releaseWaiting`), which a step answers by standing down.
51
+ */
52
+ readonly untilPickWoken: (r: { readonly workflow: string; readonly after: number }) => Effect.Effect<'woken' | 'released'>;
50
53
  /** A waiting Pick picked again after a wake: `ms` is how long that pick took. */
51
54
  readonly countRePick: (workflow: string, ms: number) => void;
52
55
  /**
@@ -57,8 +60,10 @@ export interface PickWakes {
57
60
  /** Applies a wake another process relayed, without relaying it again. */
58
61
  readonly wake: (wake: Wake) => void;
59
62
  /**
60
- * LETS EVERY WAITING PICK GO, now and from now on, for a process handing its runs to another: each wait ends interrupted,
61
- * so its run stops where it waited and the next process runs that Pick again. A waiting Pick has done no work, and kept
63
+ * LETS EVERY WAITING STEP GO, now and from now on, for a process handing its runs to another: each wait ends `released`,
64
+ * and its step stands down (`steps.ts` `HANDED_OVER`), so its run ends untried and the next process starts one. Ended
65
+ * interrupted, the engine tried the step again 10 times and then failed its run: a run waiting for an agent was recorded
66
+ * as a failed try of its task (2026-11-19). A waiting step has done no work, and kept
62
67
  * waiting it held its process's handover open for the engine's full limit, 10 minutes (2026-11-11).
63
68
  */
64
69
  readonly releaseWaiting: () => void;
@@ -147,18 +152,18 @@ export const makePickWakes = (): PickWakes => {
147
152
  for (const waiter of [...waiters]) waiter.release();
148
153
  },
149
154
  untilPickWoken: (input) =>
150
- Effect.callback<void>((resume) => {
151
- if (released) return resume(Effect.interrupt);
152
- if (pickWakesSoFar(input.workflow) !== input.after) return resume(Effect.void);
155
+ Effect.callback<'woken' | 'released'>((resume) => {
156
+ if (released) return resume(Effect.succeed('released'));
157
+ if (pickWakesSoFar(input.workflow) !== input.after) return resume(Effect.succeed('woken'));
153
158
  const waiter: Waiter = {
154
159
  workflow: input.workflow,
155
160
  wake: () => {
156
161
  waiters.delete(waiter);
157
- resume(Effect.void);
162
+ resume(Effect.succeed('woken'));
158
163
  },
159
164
  release: () => {
160
165
  waiters.delete(waiter);
161
- resume(Effect.interrupt);
166
+ resume(Effect.succeed('released'));
162
167
  },
163
168
  };
164
169
  waiters.add(waiter);
@@ -1,9 +1,8 @@
1
1
  /**
2
- * EACH QUEUE'S COUNTS, RECORDED WHEN ITS QUEUE MAY HAVE CHANGED (`queue_counts`), so a page reads the newest row and never
3
- * counts. A workflow's tasks by bucket are worked out from every task's notes (`tasks.ts` `summarize`): 0.7 s for a
4
- * project's 20,000 tasks on a busy machine, too long for a page load, and until 2026-11-17 a job did it every 5 minutes for
5
- * a stored page. Here it is done once per change, in the one process that runs the project's workflows, which is also the
6
- * one that has read each task's inputs as its Pick reads them, so the page and the Pick put a task in the same bucket.
2
+ * EACH QUEUE'S COUNTS, RECORDED WHEN ITS QUEUE MAY HAVE CHANGED (`queue_counts`), so a page reads the newest row and its
3
+ * history and never counts. A workflow's tasks by status are read from its tasks' notes (`tasks.ts` `taskSummaries`), once
4
+ * per change, in the one process that runs the project's workflows. A count only counts: blocking a task is its Pick's
5
+ * step, never a page's or this (`tasks.ts` `settleQueue`).
7
6
  *
8
7
  * WHAT COUNTS AS A CHANGE: every wake of a workflow's Picks (`pick-wakes.ts`: a note on one of its tasks, an item new to
9
8
  * its list, one of its runs ending, a limit set), and a Pick claiming an item (`changed`). Every change within
@@ -14,26 +13,23 @@ import { Effect } from 'effect';
14
13
  import type { PickWakes } from './pick-wakes';
15
14
  import type { StorageError } from './storage/storage-error';
16
15
  import type { TaskStore } from './storage/task-store';
17
- import { bucketCounts, type Tasks } from './tasks';
16
+ import { statusCounts, type Tasks } from './tasks';
18
17
 
19
18
  /** How long after a queue's first change it is counted: every change in that time is in the one count. */
20
19
  export const COUNT_AFTER_MS = 5_000;
21
20
 
22
- export const makeQueueCounts = <R>(deps: {
21
+ export const makeQueueCounts = (deps: {
23
22
  readonly store: Pick<TaskStore, 'recordQueueCounts'>;
24
23
  readonly tasks: Pick<Tasks, 'taskSummaries'>;
25
24
  readonly wakes: Pick<PickWakes, 'onWake'>;
26
25
  /** The workflows that have a queue, now. */
27
26
  readonly withQueues: () => ReadonlyArray<string>;
28
- /** Reads a workflow's tasks' inputs where it declares them (`steps.ts` `readTaskInputs`), as its Pick does before it reads its queue. */
29
- readonly readTaskInputs: (workflow: string) => Effect.Effect<unknown, unknown, R>;
30
27
  /** `COUNT_AFTER_MS` where absent; a test names a shorter one. */
31
28
  readonly countAfterMs?: number;
32
29
  }) => {
33
- /** Counts one workflow's queue now and records it. Its inputs unread, it is counted with those last read, and that is said. */
34
- const count = (workflow: string): Effect.Effect<void, StorageError, R> => Effect.gen(function* () {
35
- yield* Effect.catch(deps.readTaskInputs(workflow), (e) => Effect.logError(`[queue counts] ${workflow}: its tasks' inputs could not be read, so it is counted with those last read: ${String(e)}`));
36
- const counts = bucketCounts(yield* deps.tasks.taskSummaries({ workflow }));
30
+ /** Counts one workflow's queue now and records it. */
31
+ const count = (workflow: string): Effect.Effect<void, StorageError> => Effect.gen(function* () {
32
+ const counts = statusCounts(yield* deps.tasks.taskSummaries({ workflow }));
37
33
  yield* deps.store.recordQueueCounts({ at: Date.now() / 1000, counts: Object.entries(counts).map(([bucket, tasks]) => ({ workflow, bucket, tasks })) });
38
34
  });
39
35
 
@@ -43,7 +39,7 @@ export const makeQueueCounts = <R>(deps: {
43
39
  * Starts recording: for the one process that runs the project's workflows, which gives `run`, how it runs an effect of
44
40
  * theirs. Every queue is counted once at the start, then each on its changes.
45
41
  */
46
- const record = (run: (count: Effect.Effect<void, StorageError, R>) => Promise<void>): void => {
42
+ const record = (run: (count: Effect.Effect<void, StorageError>) => Promise<void>): void => {
47
43
  const due = new Set<string>();
48
44
  countSoon = (workflow) => {
49
45
  if (due.has(workflow) || !deps.withQueues().includes(workflow)) return;