@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.
- package/README.md +68 -23
- package/dist/dashboard/agent-usage.js +25 -0
- package/dist/dashboard/agent-usage.js.map +1 -0
- package/dist/dashboard/drilldown.js +16 -0
- package/dist/dashboard/drilldown.js.map +1 -0
- package/dist/dashboard/queue-lines.js +44 -0
- package/dist/dashboard/queue-lines.js.map +1 -0
- package/dist/index.js +8 -6
- package/dist/index.js.map +1 -1
- package/dist/keep-running.js +1 -1
- package/dist/keep-running.js.map +1 -1
- package/dist/pick-wakes.js +4 -4
- package/dist/pick-wakes.js.map +1 -1
- package/dist/queue-counts.js +7 -9
- package/dist/queue-counts.js.map +1 -1
- package/dist/steps.js +157 -41
- package/dist/steps.js.map +1 -1
- package/dist/storage/sqlite-store.js +117 -38
- package/dist/storage/sqlite-store.js.map +1 -1
- package/dist/storage/task-store.js +14 -1
- package/dist/storage/task-store.js.map +1 -1
- package/dist/tasks.js +215 -267
- package/dist/tasks.js.map +1 -1
- package/dist/views/runs-now.js +3 -2
- package/dist/views/runs-now.js.map +1 -1
- package/dist/views/step-funnel.js +1 -1
- package/dist/views/step-funnel.js.map +1 -1
- package/dist/views/step-graph.js +1 -1
- package/dist/views/step-graph.js.map +1 -1
- package/dist/views/workflow-flows.js +2 -2
- package/dist/views/workflow-flows.js.map +1 -1
- package/dist/views/workflows-view.js +83 -17
- package/dist/views/workflows-view.js.map +1 -1
- package/package.json +1 -1
- package/src/dashboard/agent-usage-line.tsx +28 -0
- package/src/dashboard/agent-usage.ts +48 -0
- package/src/dashboard/dashboard.css +70 -29
- package/src/dashboard/drilldown.ts +43 -0
- package/src/dashboard/index.tsx +1 -0
- package/src/dashboard/machine-controls.tsx +53 -0
- package/src/dashboard/queue-bar.tsx +43 -0
- package/src/dashboard/queue-chart.tsx +89 -76
- package/src/dashboard/queue-lines.ts +87 -0
- package/src/dashboard/step-graph.tsx +18 -10
- package/src/dashboard/workflow-dag.tsx +31 -103
- package/src/dashboard/workflow-drilldown.tsx +89 -0
- package/src/dashboard/workflows-dashboard.tsx +117 -42
- package/src/index.ts +11 -9
- package/src/keep-running.ts +3 -3
- package/src/pick-wakes.ts +14 -9
- package/src/queue-counts.ts +10 -14
- package/src/steps.ts +213 -52
- package/src/storage/sqlite-store.ts +126 -39
- package/src/storage/step-records.ts +14 -3
- package/src/storage/task-store.ts +97 -22
- package/src/tasks.ts +235 -301
- package/src/views/runs-now.ts +5 -4
- package/src/views/step-funnel.ts +2 -2
- package/src/views/step-graph.ts +4 -4
- package/src/views/workflow-flows.ts +7 -7
- 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 {
|
|
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
|
|
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
|
|
110
|
-
store: storage.tasks, tasks, wakes,
|
|
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
|
|
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({
|
|
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
|
};
|
package/src/keep-running.ts
CHANGED
|
@@ -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
|
-
*
|
|
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
|
-
/**
|
|
49
|
-
|
|
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
|
|
61
|
-
* so its run
|
|
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<
|
|
151
|
-
if (released) return resume(Effect.
|
|
152
|
-
if (pickWakesSoFar(input.workflow) !== input.after) return resume(Effect.
|
|
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.
|
|
162
|
+
resume(Effect.succeed('woken'));
|
|
158
163
|
},
|
|
159
164
|
release: () => {
|
|
160
165
|
waiters.delete(waiter);
|
|
161
|
-
resume(Effect.
|
|
166
|
+
resume(Effect.succeed('released'));
|
|
162
167
|
},
|
|
163
168
|
};
|
|
164
169
|
waiters.add(waiter);
|
package/src/queue-counts.ts
CHANGED
|
@@ -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
|
|
3
|
-
* counts. A workflow's tasks by
|
|
4
|
-
*
|
|
5
|
-
*
|
|
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 {
|
|
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 =
|
|
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.
|
|
34
|
-
const count = (workflow: string): Effect.Effect<void, StorageError
|
|
35
|
-
yield*
|
|
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
|
|
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;
|