@jive-sh/workflow-platform 0.6.3 → 1.0.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 (174) hide show
  1. package/README.md +66 -295
  2. package/component/_generated/api.ts +72 -0
  3. package/component/_generated/component.ts +621 -0
  4. package/component/_generated/dataModel.ts +60 -0
  5. package/component/_generated/server.ts +169 -0
  6. package/component/convex.config.ts +3 -0
  7. package/component/engine.ts +755 -0
  8. package/component/errors.ts +66 -0
  9. package/component/events.ts +17 -0
  10. package/component/notes.ts +13 -0
  11. package/component/places.ts +136 -0
  12. package/component/retention.ts +205 -0
  13. package/component/runEngine.ts +25 -0
  14. package/component/schema.ts +132 -0
  15. package/component/steps.ts +188 -0
  16. package/component/store.ts +512 -0
  17. package/component/tasks.ts +289 -0
  18. package/component/worker.ts +109 -0
  19. package/component/workflows.ts +83 -0
  20. package/dist/definition/agent-runner.js +9 -0
  21. package/dist/definition/agent-runner.js.map +1 -0
  22. package/dist/definition/file-store.js +9 -0
  23. package/dist/definition/file-store.js.map +1 -0
  24. package/dist/definition/program-build.js +10 -0
  25. package/dist/definition/program-build.js.map +1 -0
  26. package/dist/definition/step.js +1 -0
  27. package/dist/definition/step.js.map +1 -0
  28. package/dist/definition/task-schema.js +5 -0
  29. package/dist/definition/task-schema.js.map +1 -0
  30. package/dist/definition/tasks.js +9 -0
  31. package/dist/definition/tasks.js.map +1 -0
  32. package/dist/definition/workflow.js +111 -0
  33. package/dist/definition/workflow.js.map +1 -0
  34. package/dist/graph.js +301 -9
  35. package/dist/graph.js.map +1 -1
  36. package/dist/index.js +7 -133
  37. package/dist/index.js.map +1 -1
  38. package/package.json +9 -4
  39. package/src/definition/agent-runner.ts +59 -0
  40. package/src/definition/file-store.ts +20 -0
  41. package/src/definition/program-build.ts +30 -0
  42. package/src/definition/step.ts +106 -0
  43. package/src/definition/task-schema.ts +15 -0
  44. package/src/definition/tasks.ts +43 -0
  45. package/src/definition/workflow.ts +255 -0
  46. package/src/graph.ts +341 -19
  47. package/src/index.ts +8 -168
  48. package/worker/directory-file-store.ts +42 -0
  49. package/worker/index.ts +12 -0
  50. package/worker/platform-client.ts +138 -0
  51. package/worker/step-meter.ts +80 -0
  52. package/worker/worker-tasks.ts +27 -0
  53. package/worker/worker.test.ts +200 -0
  54. package/worker/worker.ts +240 -0
  55. package/dist/budget-states.js +0 -30
  56. package/dist/budget-states.js.map +0 -1
  57. package/dist/cpu-limit/limiter.js +0 -839
  58. package/dist/cpu-limit/limiter.js.map +0 -1
  59. package/dist/cpu-limit/use.js +0 -139
  60. package/dist/cpu-limit/use.js.map +0 -1
  61. package/dist/dashboard/agent-usage.js +0 -25
  62. package/dist/dashboard/agent-usage.js.map +0 -1
  63. package/dist/dashboard/dashboard.css +0 -134
  64. package/dist/dashboard/drilldown.js +0 -16
  65. package/dist/dashboard/drilldown.js.map +0 -1
  66. package/dist/dashboard/queue-lines.js +0 -44
  67. package/dist/dashboard/queue-lines.js.map +0 -1
  68. package/dist/dashboard/queue-table.js +0 -16
  69. package/dist/dashboard/queue-table.js.map +0 -1
  70. package/dist/dashboard/spending-words.js +0 -32
  71. package/dist/dashboard/spending-words.js.map +0 -1
  72. package/dist/failure.js +0 -35
  73. package/dist/failure.js.map +0 -1
  74. package/dist/keep-running.js +0 -77
  75. package/dist/keep-running.js.map +0 -1
  76. package/dist/outside-failure.js +0 -31
  77. package/dist/outside-failure.js.map +0 -1
  78. package/dist/pick-wakes.js +0 -125
  79. package/dist/pick-wakes.js.map +0 -1
  80. package/dist/project.js +0 -1
  81. package/dist/project.js.map +0 -1
  82. package/dist/queue-counts.js +0 -51
  83. package/dist/queue-counts.js.map +0 -1
  84. package/dist/reasons.js +0 -33
  85. package/dist/reasons.js.map +0 -1
  86. package/dist/spending-limit.js +0 -88
  87. package/dist/spending-limit.js.map +0 -1
  88. package/dist/step-files.js +0 -200
  89. package/dist/step-files.js.map +0 -1
  90. package/dist/step-meter.js +0 -97
  91. package/dist/step-meter.js.map +0 -1
  92. package/dist/step-usage.js +0 -19
  93. package/dist/step-usage.js.map +0 -1
  94. package/dist/steps.js +0 -920
  95. package/dist/steps.js.map +0 -1
  96. package/dist/storage/budgets.js +0 -85
  97. package/dist/storage/budgets.js.map +0 -1
  98. package/dist/storage/engine-records.js +0 -75
  99. package/dist/storage/engine-records.js.map +0 -1
  100. package/dist/storage/engine-storage.js +0 -67
  101. package/dist/storage/engine-storage.js.map +0 -1
  102. package/dist/storage/input-records.js +0 -12
  103. package/dist/storage/input-records.js.map +0 -1
  104. package/dist/storage/move-store.js +0 -251
  105. package/dist/storage/move-store.js.map +0 -1
  106. package/dist/storage/sqlite-store.js +0 -723
  107. package/dist/storage/sqlite-store.js.map +0 -1
  108. package/dist/storage/step-records.js +0 -11
  109. package/dist/storage/step-records.js.map +0 -1
  110. package/dist/storage/storage-error.js +0 -19
  111. package/dist/storage/storage-error.js.map +0 -1
  112. package/dist/storage/task-store.js +0 -24
  113. package/dist/storage/task-store.js.map +0 -1
  114. package/dist/tasks.js +0 -475
  115. package/dist/tasks.js.map +0 -1
  116. package/dist/views/format.js +0 -37
  117. package/dist/views/format.js.map +0 -1
  118. package/dist/views/runs-now.js +0 -75
  119. package/dist/views/runs-now.js.map +0 -1
  120. package/dist/views/step-funnel.js +0 -98
  121. package/dist/views/step-funnel.js.map +0 -1
  122. package/dist/views/step-graph.js +0 -34
  123. package/dist/views/step-graph.js.map +0 -1
  124. package/dist/views/workflow-flows.js +0 -53
  125. package/dist/views/workflow-flows.js.map +0 -1
  126. package/dist/views/workflows-view.js +0 -230
  127. package/dist/views/workflows-view.js.map +0 -1
  128. package/src/budget-states.ts +0 -55
  129. package/src/cpu-limit/limiter.ts +0 -935
  130. package/src/cpu-limit/use.ts +0 -166
  131. package/src/dashboard/agent-usage-line.tsx +0 -28
  132. package/src/dashboard/agent-usage.ts +0 -48
  133. package/src/dashboard/dashboard.css +0 -134
  134. package/src/dashboard/drilldown.ts +0 -43
  135. package/src/dashboard/index.tsx +0 -4
  136. package/src/dashboard/machine-controls.tsx +0 -53
  137. package/src/dashboard/queue-bar.tsx +0 -43
  138. package/src/dashboard/queue-chart.tsx +0 -150
  139. package/src/dashboard/queue-lines.ts +0 -87
  140. package/src/dashboard/queue-table.ts +0 -37
  141. package/src/dashboard/spending-limit-control.tsx +0 -50
  142. package/src/dashboard/spending-words.ts +0 -50
  143. package/src/dashboard/step-graph.tsx +0 -106
  144. package/src/dashboard/workflow-dag.tsx +0 -204
  145. package/src/dashboard/workflow-drilldown.tsx +0 -89
  146. package/src/dashboard/workflows-dashboard.tsx +0 -414
  147. package/src/failure.ts +0 -36
  148. package/src/keep-running.ts +0 -83
  149. package/src/outside-failure.ts +0 -39
  150. package/src/pick-wakes.ts +0 -182
  151. package/src/project.ts +0 -115
  152. package/src/queue-counts.ts +0 -64
  153. package/src/reasons.ts +0 -30
  154. package/src/spending-limit.ts +0 -156
  155. package/src/step-files.ts +0 -208
  156. package/src/step-meter.ts +0 -120
  157. package/src/step-usage.ts +0 -23
  158. package/src/steps.ts +0 -1239
  159. package/src/storage/budgets.ts +0 -113
  160. package/src/storage/engine-records.ts +0 -102
  161. package/src/storage/engine-storage.ts +0 -82
  162. package/src/storage/input-records.ts +0 -43
  163. package/src/storage/move-store.ts +0 -265
  164. package/src/storage/sqlite-store.ts +0 -829
  165. package/src/storage/step-records.ts +0 -306
  166. package/src/storage/storage-error.ts +0 -35
  167. package/src/storage/task-store.ts +0 -235
  168. package/src/tasks.ts +0 -561
  169. package/src/views/format.ts +0 -40
  170. package/src/views/runs-now.ts +0 -120
  171. package/src/views/step-funnel.ts +0 -163
  172. package/src/views/step-graph.ts +0 -68
  173. package/src/views/workflow-flows.ts +0 -97
  174. package/src/views/workflows-view.ts +0 -443
package/README.md CHANGED
@@ -1,310 +1,81 @@
1
1
  # @jive-sh/workflow-platform
2
2
 
3
- Durable workflows on Effect's workflow engine (`effect/workflow`), where every step of every run is measured and every
4
- item a workflow works on is a task in a queue.
3
+ Durable workflows in Convex. A workflow is one primitive, drawn as one diagram: a task schema, steps (code, an agent,
4
+ or another workflow), the lines between them, the events that bring tasks in, and the end states it names. Every line
5
+ is a queue, every step and line counts its tasks, and each workflow has an agent budget and a CPU budget. Workers on
6
+ your machines take tasks from Convex and run the code and agent steps; sub-workflow steps run inside Convex.
5
7
 
6
- A project defines its workflows here and supplies only what it alone knows: its files, its process runner, its words for
7
- items. The platform does the rest the same way for every workflow:
8
-
9
- - **One way to define a workflow and its steps.** Each step has a kind, which a page says in words: plain code, an agent
10
- step, a check (it decides whether the work passes) or a sub-workflow. It also says what it may write and which step can
11
- follow it. Nothing else defines a step.
12
- - **Workflows all the way down.** A workflow is a step of another through `defineSubWorkflow`: the step starts it as a run
13
- of its own and waits for it, the engine suspending the run above until it ends. One record in the workflow above names
14
- that run, its steps work on the item the run above works on, and its agent steps count against the agents' limit of the
15
- workflow at the top. The top of a project is one workflow, which a page enters at and drills down from.
16
- - **Every step is measured, never self-reported.** Time, tokens, CPU (its own and its child processes'), peak memory,
17
- files written and compiles go on one record per step run, per item.
18
- - **Every item is a task**, with an append-only log of notes and one of four statuses read from them: queued, in
19
- progress, blocked or done (`src/tasks.ts`). Done means its workflow's final check passed. A queue is first in, first out,
20
- and one call reorders it by hand (`moveToFront`). Blocking is the logic of the step that picks: 10 failed tries, flipping
21
- between two versions, nothing new since its last failed try, or a reason of the workflow's own, each in words on the task.
22
- A failed try is a run that did its work and ended without success: a run that stood down, or one an outside service
23
- failed (a step failing with `OutsideServiceUnavailable`, or Claude's own usage-limit or rate-limit words), is none
24
- (`src/outside-failure.ts`).
25
- - **Waiting is event-driven.** A Pick with nothing to claim waits for an event that can change that (a note, a new item,
26
- a run ending, a budget change) and never polls.
27
- - **A run limit on every workflow, and an agents' limit where it has agent steps.** Every start of every workflow, however it
28
- starts (a timer, its inputs changing, its queue, a request), passes its run limit (`steps.ts` `gatedExecute`): a new run
29
- starts only while fewer are going, 0 starts none, and none set is no limit, or for a workflow with an agent step and a list
30
- of work its agents' limit. That kind of workflow also keeps its run limit's number of runs going, and at most its agents'
31
- limit of them are in an agent step at once: a run at an agent step whose agents are all in use waits there, its task kept and its
32
- record saying so, until one frees. At 0 agents nothing gets past a first agent step: a run with a task ends there, its task marked as needing an agent (below). Setting either limit
33
- (`runPlanChanged`) has the run planner plan again at once. The run limit is the one way to stop a workflow: at 0 no run
34
- of it starts, and a run already going ends before it takes on more work (`steps.ts` `standDownIfSurplus`). In a workflow
35
- its budget keeps going that is before an agent step: the run still picks and tests with no agent, and ends at a Pick
36
- that finds nothing. In any other it is before a Pick, before an agent step, or at its first step when the engine
37
- resumes it after a restart. A step between those still runs, so what an agent step just made is checked and recorded.
38
- There is no pause beside it.
39
- - **A task that needs an agent no run can have gives its run slot up** (`steps.ts` `untilAgentSlot`). Where no agent
40
- can be had (its workflow's agents' limit is 0, or the spending limit holds), a run with a task ends at its agent step
41
- instead of waiting there: its task goes to the back of its queue, marked "needs an agent" with why in words, and its
42
- slot goes to work that needs none. Its Pick passes over marked tasks while no agent can be had, and takes them in queue
43
- order once one can. Something new from outside the workflow clears the mark (a return to its queue, a move to the
44
- front, any note by a person or another workflow), and so do an agent step that ran on the task and its final check
45
- passing. A run with no task, or one waiting for an agent another run holds, still waits. The status table's queued row
46
- says how many need agent, "804 queued (12 need agent)", and an open workflow lists them by reason.
47
- - **One spending limit for the whole account: "agents stop at X% of the week"** (`spending-limit.ts`, 95 when none is
48
- set). While the newest good reading of the week is at or past X, every agent step of every workflow waits before its
49
- agent call, as at an agents' limit of 0, its record saying "waits: the week's use is N%, at or past the spending limit of
50
- X%", and goes on by itself once a reading is below X. It judges the account's week, not the step records' tokens,
51
- because the week also counts what no workflow runs (agent threads run by hand). The project gives the reading
52
- (`WorkflowProject.weekUsage`) and tells the platform of each one it takes (`platform.spending.readingTaken`); a project
53
- that gives none has no spending limit. A failed or old reading never lifts it: the limit keeps the newest good reading's
54
- verdict, however old, and the page says the reading is stale and why. An unreadable one holds every agent step.
55
- - **Each queue's counts, kept current.** When a queue may have changed (a wake of its Picks, or a Pick claiming an item),
56
- the process that runs the workflows counts it within 5 seconds and stores each status's count where it moved
57
- (`queue-counts.ts`, `queue_counts`). A page reads the newest rows and their history and never counts.
58
- - **A page read from the records at each request.** Every workflow with its limits, its queue and where work goes between
59
- them is a few small readings (`platform.view`, under 100 ms for 52 workflows and 166,000 step records); one workflow's
60
- steps, costs, graph and funnel are read from its own records when a page opens it (`platform.figures`). Nothing is built
61
- on a schedule or stored for a page.
62
- Nothing else decides how many run, and a page can set both (`WorkflowsDashboard`'s `setLimit`).
63
- - **Runs only when their inputs change.** A workflow declares what it runs on (`inputs`); its trigger starts a run only
64
- when their fingerprint differs from its last successful run's, whose result stands meanwhile. A timer is only the fallback
65
- that checks. A workflow with a list of work can declare what each task runs on (`taskInputs`): each outcome records the
66
- task's fingerprint as its run left it, and its Pick blocks a task nothing new has reached since its last failed try.
67
- - **A reason with every outcome.** Each step record says why it ended as it did; the dashboard counts endings per step,
68
- where runs stopped and why, what each workflow yields per run, per million tokens and per compile against the window
69
- before, and what a run costs, its child processes included.
70
- - **A declared step graph.** Each workflow names which step can follow which and when; a run that takes another edge fails
71
- in tests.
72
- - **One CPU limit.** Every heavy process of the project holds a slot of one pool from before it starts until it exits, and
73
- running work is paused while what the project uses is over the limit (`makeCpuLimiter`). The project says only what it
74
- alone knows: where its pool lives, which commands are light, which processes are its own. The dashboard shows where the
75
- project stands against it.
76
- - **Storage is behind interfaces, in one database.** Step records, tasks, input runs, both limits and the engine's own
77
- records each have an interface and a SQLite implementation. Every call is an effect that fails with `StorageError`, so
78
- another database (Convex) can stand behind any of them; a step whose record cannot be written goes on and says so. The
79
- platform's tables, the CPU limit's pool and the engine's records live in the project's own database, beside the schema
80
- the project declares (`STORAGE.md`); a held lock is tried again while yielding, never waited on inside SQLite. The
81
- engine gets that from `lockRetryingSingleRunner`, effect/cluster's single runner on SQL storage whose every call is
82
- retried this way, with a client set to wait 0 ms (`busyTimeout: Duration.zero`).
83
-
84
- It runs today inside the aoe2-in-browser decompilation service, its first project
85
- (`aoe2-in-browser/decomp-service/src/workflows/platform.ts`).
86
-
87
- ## A first workflow
88
-
89
- ```ts
90
- import { createWorkflowPlatform, sqliteStorage, RUN_STARTS, RUN_ENDS } from '@jive-sh/workflow-platform';
91
- import { Effect, Schema } from 'effect';
92
-
93
- const platform = createWorkflowPlatform<'main', never>({
94
- project: {
95
- sourceRoot: ROOT,
96
- tree: { root: ROOT, snapshots: `${ROOT}/local/step-files`, notTree: ['local'] },
97
- texts: { write: storeText, read: readText },
98
- runLightNow,
99
- processes: { thisProcess, isAlive },
100
- stepRecordVariable: 'MY_STEP_RECORD',
101
- isTransientFailure: (e) => String(e).includes('database is locked'),
102
- },
103
- storage: sqliteStorage({ stepRecordsFile: () => `${ROOT}/local/app.db`, engineFile: () => `${ROOT}/local/app.db`, budgetsFile: () => `${ROOT}/local/app.db`, processes: { thisProcess, isAlive } }),
104
- });
105
- const { defineStep, defineWorkflow } = platform.steps;
106
-
107
- const COUNT = defineStep({ name: 'Count', runs: 'deterministic', shared: true, description: 'Counts the files.', at: import.meta.path, success: Schema.Number });
108
-
109
- export const CountFiles = defineWorkflow({
110
- phase: 'main', item: null, description: 'Counts the files.', at: import.meta.path, steps: () => [COUNT],
111
- graph: () => [{ from: RUN_STARTS, to: COUNT.name, when: 'each run' }, { from: COUNT.name, to: RUN_ENDS, when: 'always' }],
112
- })('Count files', { payload: { turn: Schema.Number }, idempotencyKey: ({ turn }) => String(turn), success: Schema.Number, error: Schema.String });
113
-
114
- export const CountFilesLive = CountFiles.toLayer(() => COUNT.run(Effect.succeed(42)));
115
- ```
116
-
117
- The step's record (start, end, outcome, CPU) is written by `COUNT.run`; the workflow body has no measuring code.
8
+ 1.0.0 replaces the 0.x platform (`effect/workflow` over SQLite), which lives on as the `v0` branch for fixes.
9
+ [DESIGN.md](DESIGN.md) holds the design and the decisions behind it, and [MIGRATION.md](MIGRATION.md) maps each
10
+ decomp-service workflow onto this one.
118
11
 
119
12
  ## Installing it
120
13
 
121
14
  ```sh
122
- bun add @jive-sh/workflow-platform effect
15
+ bun add @jive-sh/workflow-platform convex effect
123
16
  ```
124
17
 
125
- It runs on Bun (its stores are `bun:sqlite`) and shares its consumer's `effect` 4, a peer dependency. Each push to `main`
126
- with a new version publishes it to npm through Jive's pipeline (`.github/workflows/pipeline.yml`, the six `jive:cicd:*`
127
- scripts of `jive-abstract-library`); a push without a version bump publishes nothing.
128
-
129
- ## Using it from a checkout
130
-
131
- The package runs inside its consumer's processes and must share their one copy of `effect`, so a checkout beside its
132
- consumer has no packages of its own: `node_modules` here is a link to the consumer's (`aoe2-in-browser/install/setup.ts`
133
- makes it). Never run `bun install` in such a checkout: it would write through the link into the consumer's packages. The
134
- pipeline installs the package's own devDependencies from `bun.lock`, on a clean runner. The consumer imports
135
- it by path, through its tsconfig (`"@jive-sh/workflow-platform": ["../../workflow-platform/src/index.ts"]`).
136
-
137
- ```sh
138
- bun test # the package's own tests
139
- node_modules/.bin/tsc --noEmit # its typecheck
140
- ```
141
-
142
- ## Modules
143
-
144
- Each module's inputs come from `createWorkflowPlatform` (`src/index.ts`), which builds them in this order.
145
-
146
- | Module | What it does | Takes | Gives |
147
- |---|---|---|---|
148
- | `project.ts` | What a project tells the platform about itself | n/a | `WorkflowProject`, `ProcessIdentity`, `UsageSink`, `TextStore`, `ProjectTree`, `WeekUsage` |
149
- | `storage/storage-error.ts` | What every store call fails with, and a synchronous store's calls as effects | a store's calls | `StorageError`, `storeCall`, `storeCalls` |
150
- | `storage/step-records.ts` | The step records' interface: one record per step run, and every read of them | n/a | `StepRecords`, its row types, `noSpend`, `StepScope` |
151
- | `storage/task-store.ts` | The task store's interface: tasks, their append-only notes, their listing | n/a | `TaskStore`, `TaskNote`, `TaskRef`, `Listed` |
152
- | `storage/engine-records.ts` | Which runs the engine has not finished, from its `cluster_*` tables | the engine's file | `EngineRecords`, `sqliteEngineRecords`, `ensureEngineIndexes` |
153
- | `storage/budgets.ts` | Each workflow's two limits: runs going and agents in an agent step; and the one spending limit | the file with `workflow_budgets` and `spending_limit` | `LimitStore`, `runLimit`, the limit SQL |
154
- | `spending-limit.ts` | The spending limit: the rule, its verdict for a page, its wake on a reading, the one way to set it | limits, the project's `WeekUsage`, wakes | `makeSpendingLimit` (also `platform.spending`), `judgeSpending`, `spendingWait` |
155
- | `storage/input-records.ts` | What each run ran on and how it ended; the check of re-runs on unchanged inputs | runs a trigger started | `InputRecords`, `rerunsOnUnchangedInputs` |
156
- | `reasons.ts` | Why a step ended as it did, in a line, read from its result | a step's result | `standardReason`, `oneLine` |
157
- | `storage/sqlite-store.ts` | Step records, tasks and input runs in the project's database | its file, the project's processes, the file they moved from | `sqliteStore`, `applyStepRecordsSchema` |
158
- | `storage/move-store.ts` | The live move of the step records and tasks, and of the engine's records, from files of their own into the project's database | both files | `moveRecordsInto`, `catchUpMove`, `engineFileFree`, `moveEngineInto`, `movedInto` |
159
- | `storage/engine-storage.ts` | The engine's message and runner storage in the project's database, every call tried again while yielding on a held lock | a SQL client that waits 0 ms | `lockRetryingSingleRunner`, `lockRetryingMessageStorage`, `lockRetryingRunnerStorage`, `retryHeldLock`, `isHeldLock` |
160
- | `pick-wakes.ts` | What wakes a waiting Pick, and a minute's count of wakes by source | n/a | `PickWakes` |
161
- | `step-meter.ts` | Measures what a step uses: CPU, memory, compiles, files | process usage, files written | `StepMeter` |
162
- | `step-usage.ts` | Which step a piece of code works for, so its processes' usage reaches it | the step-record variable | `CurrentStepUsage` |
163
- | `step-files.ts` | What an agent step changed in the tree, and taking it back | the project's tree | `StepFiles`, `filesChanged` |
164
- | `tasks.ts` | The task rules (the four statuses, first-in-first-out order and the reorder call, the blocking a Pick runs) and the task writes | task store, engine records, step records, wakes, texts | `Tasks`, `queueOrder`, `standardBlock`, `PendingWork` |
165
- | `steps.ts` | `defineWorkflow`, `defineStep`, `defineItemTest`: running and recording every step | every store above | `Steps` |
166
- | `keep-running.ts` | The trigger's plan: how many runs of each budgeted workflow to start | declarations, budgets, runs going | `planRunStarts`, `oneTurnAtATime` |
167
- | `budget-states.ts` | Each budget against the runs it has, for a page | budgets, runs | `workflowBudgetStates` |
168
- | `failure.ts` | A failure as one line of text | any failure | `describeFailure`, `startAndEnd` |
169
- | `cpu-limit/use.ts` | The CPU limit's arithmetic: room to start, what project work uses, what to pause | `ps` output, the pool's counts | `roomInThreads`, `readUse`, `pauseOrResume` |
170
- | `cpu-limit/limiter.ts` | The CPU limit: the slot pool, the line, readings of use, holding work to the limit, the one way to start a process | the project's facts (`CpuLimiterFacts`) | `makeCpuLimiter`, `CpuLimiter` |
171
- | `graph.ts` | A workflow's declared step graph and the check of a move against it; no dependencies, so a page can import it | declared edges, a run's last step | `StepEdge`, `edgeDeclared`, `RUN_STARTS`, `RUN_ENDS` |
172
- | `views/runs-now.ts` | Where each unfinished run is now: the step it is in or waits after, and what a waiting step waits on | unfinished runs, their newest step records, the phase order | `runsNow`, `PhaseRunsNow` |
173
- | `views/step-funnel.ts` | For each step, the window's runs that reached it, stopped or finished there, and why most stopped | the window's step records and item outcomes | `stepFunnel` |
174
- | `views/step-graph.ts` | The declared graph with the window's runs on each edge, and the moves it does not declare | declarations, the window's moves | `workflowGraphs` |
175
- | `queue-counts.ts` | Each queue counted when it may have changed, and stored where a count moved | tasks, task store, wakes | `makeQueueCounts` (also `platform.queueCounts`) |
176
- | `views/workflows-view.ts` | The dashboard's two readings: every workflow (limits, queue, flows), and one workflow's figures (steps with their cost, graph, funnel) | task store, limits; step records, engine records | `buildWorkflowsView`, `buildWorkflowFigures` (also `platform.view`, `platform.figures`) |
177
- | `dashboard/` | React components for a project's page: `WorkflowsDashboard`, which a project gives its own header, phase names and controls; `dashboard.css` | the two readings and runs now, as JSON | `src/dashboard/index.tsx`, named by path from the host page |
178
-
179
- `src/imports.test.ts` fails on any import from outside this package other than effect, Bun and Node (and, in a test, the
180
- SQL client it runs the engine on), and on a dashboard file importing anything but React, its own folder, `graph.ts`,
181
- `views/format.ts` and other modules' types.
182
-
183
- ## Limits
18
+ It ships its source, and three entry points:
184
19
 
185
- - The CPU limit's pool (`cpu-limit/limiter.ts`) is not behind a store interface: it is this machine's, read every 250 ms,
186
- and opened by a project's setup before anything is installed, `effect` included.
187
- - A project still writes each workflow's limits with its own statements (`storage/budgets.ts`),
188
- and the engine's own writes are effect/cluster's `MessageStorage`: a store elsewhere needs its own of each.
189
- - Some stored names keep the first project's words: the per-item part table is `step_functions`, and a step with per-item
190
- parts has scope `'functions'`.
191
- - Wakes reach only the Picks of the process that raised them, and another process's only through the project's relay
192
- (`relayTo`, then `wake` there).
193
- - A task's inputs changed by anything but a note, a listing or one of its workflow's runs ending (another workflow's write,
194
- say) wake no waiting Pick: the next of those events reads them.
195
- - A run waiting at an agent step for an agent another run holds keeps its task for as long as it waits; a lease the project keeps on the item itself can
196
- run out meanwhile.
197
- - The scheduler's job ledger (which job turn is due) is still the first project's own.
20
+ | Import | Holds |
21
+ | --- | --- |
22
+ | `@jive-sh/workflow-platform` | Defining workflows (`Workflow.make`, `TaskSchema.make`), the step services (`AgentRunner`, `FileStore`, `ProgramBuild`, `Tasks`) and the graph types |
23
+ | `@jive-sh/workflow-platform/component/convex.config.js` | The Convex component a workforce installs once per workflow (`app.use(workflowPlatform, { name })`) |
24
+ | `@jive-sh/workflow-platform/worker/index.js` | The worker loop (`workOnce`, `workUntilIdle`, `workForever`) and its Convex client |
198
25
 
199
- ## The dashboard
26
+ Write `.js` in the import: TypeScript and Convex's bundler both resolve it to the shipped `.ts`. Convex's codegen
27
+ writes `@jive-sh/workflow-platform/component/_generated/component.js` into an app installing the component, for the
28
+ component's API types.
200
29
 
201
- A project serves `{ view, runsNow, cpu }` as JSON, all read at the request (`platform.view(...)` and `runsNow`), and one
202
- workflow's figures at a route of their own (`platform.figures(...)`), which the page reads while that workflow is open. In
203
- the process that runs its workflows it starts the queue counts once: `platform.queueCounts.record((count) => runtime.runPromise(count))`.
204
- It renders `WorkflowsDashboard` on a page of its own, which brings React. The page shows a workflow at a time
205
- (`src/dashboard/drilldown.ts`): it enters at the project's top workflow, a sub-workflow step opens that workflow's view,
206
- and a breadcrumb says where it is. The host routes each level's address back as `path`. A workflow's view draws:
30
+ ## A workflow
207
31
 
208
- - its tasks as a column addition, `queued + in progress + blocked + done = total` (`src/dashboard/queue-table.ts`), its
209
- runs now and its two limits with − and +;
210
- - its tasks over time, each line one status as a percent of the workflow's tasks, chosen in a table with a row per
211
- workflow and a column per status (`src/dashboard/queue-chart.tsx`);
212
- - its own steps, each with what it is (step, check, sub-workflow) and how it runs (deterministic, agentic, classification) in
213
- words (`src/dashboard/workflow-drilldown.tsx`), and at the top the map of its steps: each workflow a box whose name opens
214
- it, with the arrows work takes between them (`src/dashboard/workflow-dag.tsx`, `src/views/workflow-flows.ts`);
215
- - while it is open: why its blocked tasks are blocked, what each step cost, its step graph and where its runs stopped.
216
-
217
- At the top it also draws what the project gives of its machine and its agents' account, each only where given: the CPU
218
- limit with − and + (`setCpuLimit`, `cpu.threads`), the stop of everything and its resume (`stopEverything`, `resume`,
219
- `stopped`), and what the account has used of each of its limits (`usage`, `src/dashboard/agent-usage.ts`).
220
-
221
- On every level it draws the spending limit where the project reads its week (`view.spending`,
222
- `src/dashboard/spending-limit-control.tsx`): what it is set to with − and + (`setSpendingLimit`), the week's reading
223
- against it and whether it holds every agent step, why the reading is stale where it is, and which agent steps wait on it,
224
- each in words.
225
-
226
- ```tsx
227
- import { usePolledJson, WorkflowsDashboard, type WorkflowsPageData } from '@jive-sh/workflow-platform/dashboard';
228
-
229
- const { data, error } = usePolledJson<WorkflowsPageData>('/api/platform/workflows', 10_000);
230
- <WorkflowsDashboard data={data} error={error} path={path} hrefOf={(path) => `/workflows/${path.map(encodeURIComponent).join('/')}`}
231
- figuresUrl={(workflow) => `/api/platform/workflows/${encodeURIComponent(workflow)}`} setLimit={storeLimit} />
32
+ ```ts
33
+ import { TaskSchema, Workflow } from "@jive-sh/workflow-platform"
34
+ import { Schema } from "effect"
35
+
36
+ export const review = Workflow.make({
37
+ name: "review",
38
+ task: TaskSchema.make({ fields: Schema.Struct({ title: Schema.String, good: Schema.Boolean }) }),
39
+ endStates: ["approved", "rejected"],
40
+ budgets: { agents: 0, cpu: 1 },
41
+ events: { arrive: { kind: "task" } },
42
+ steps: (step) => ({
43
+ check: step.code({
44
+ endStates: ["ok", "bad"],
45
+ run: function* (task) {
46
+ return { endState: task.fields.good ? ("ok" as const) : ("bad" as const) }
47
+ },
48
+ }),
49
+ }),
50
+ lines: [
51
+ { from: { event: "arrive" }, to: { step: "check" } },
52
+ { from: { step: "check", endState: "ok" }, to: { end: "approved" } },
53
+ { from: { step: "check", endState: "bad" }, to: { end: "rejected" } },
54
+ ],
55
+ })
232
56
  ```
233
57
 
234
- The dashboard ships in the npm release as source, in `src/dashboard`: every file of it is a `.tsx` or a stylesheet, which
235
- the package's build (`jive-abstract-library`, compiling `src/**/*.ts` with no JSX) leaves for the host page's bundler. The
236
- release exports the main entry only, so a host names the dashboard's two files by path: alias
237
- `@jive-sh/workflow-platform/dashboard` to `node_modules/@jive-sh/workflow-platform/src/dashboard/index.tsx` and
238
- `@jive-sh/workflow-platform/dashboard/dashboard.css` to `.../src/dashboard/dashboard.css`, in the bundler and in
239
- `tsconfig.json`'s `paths`. It has no React of its own: add the package to `transpilePackages`, and alias `react` and `elkjs/lib/elk.bundled.js` to the
240
- app's copies (`aoe2-in-browser/decomp-dashboard/next.config.ts` does this).
241
-
242
- ## A block for failed tries lapses once fewer count (0.6.3, 2026-11-28)
243
-
244
- A Pick returns a task it blocked for its failed tries to the queue once fewer than 10 count, as it returns one blocked for
245
- nothing new once something new reaches it: the note is `unblocked`, "fewer than 10 failed tries count now". Its count
246
- stands, so its next failed try blocks it again. 0.6.2 stopped counting a run an outside service failed, but a task 0.6.1
247
- had already blocked for 11 tries, 2 of them weekly limits, stayed blocked with 9.
248
-
249
- ## A run an outside service failed is no try (0.6.2, 2026-11-28)
250
-
251
- A task is blocked after 10 failed tries, and only a run that did its work and ended without success is one now. A step
252
- that fails because a service outside it could not do the work fails with `OutsideServiceUnavailable` ({ service, reason }),
253
- and its outcome is no try. Claude's own usage-limit and rate-limit words in a failure are read the same way whatever
254
- error carries them, so outcomes recorded before 0.6.2 count right too: a task that had 9 tries and 2 such failures, and
255
- so was blocked, gets its tenth try without being returned to its queue. Nothing stored changes shape.
256
-
257
- ## The spending limit, and tasks that need an agent (0.6.0, 2026-11-20)
258
-
259
- A project gets a spending limit by giving its week and storing the setting:
260
-
261
- - **`WorkflowProject.weekUsage`**: `now()`, its newest good reading of the week (used percent, when read, when it resets)
262
- and a read that failed after it; and `staleAfterSeconds`, when a page calls the reading stale. Without it nothing
263
- changes.
264
- - **`platform.spending.readingTaken()`** after each reading it stores: a verdict that changed wakes every waiting step.
265
- - **A table `spending_limit`** in the file with `workflow_budgets` (`storage/budgets.ts` gives its shape); no row is 95%.
266
- - **A route** that calls `platform.spending.set({ weekPercent, from, write })`, which checks the percent, writes it with
267
- the platform's statement, wakes every waiting step and logs who asked; and the page's `setSpendingLimit`.
268
-
269
- Three shapes grew: `LimitStore` has `spendingLimit`, `WorkflowsView` has `spending`, and `StepRunsNow` has
270
- `heldBySpendingLimit`, so a store of its own, or a test building these by hand, needs them.
271
-
272
- The same release marks a task that needs an agent no run can have (above). Nothing stored changes shape: the mark is two
273
- new note kinds, `needs an agent` and `an agent step ran` (`storage/task-store.ts`), and the queued tasks marked are a
274
- count of their own in `queue_counts` (`queue-counts.ts` `QUEUED_NEEDING_AN_AGENT`). A workflow that branches on
275
- `isStoodDown` treats the new end of a run, `NEEDS_AN_AGENT_STOOD_DOWN`, as it treats a run that stood down: no try, its
276
- item given back. Shapes that grew: `TaskState` and `TaskSummary` have `needsAgent`, a fake `AgentBudgets.agentSlot`
277
- answers `unavailable` beside `why`, `WorkflowFigures` has `needingAnAgent`, `WorkflowView` has `queuedNeedingAnAgent`,
278
- and `QueueBar` takes it.
279
-
280
- ## Moving from six buckets to four statuses (0.x, 2026-11-19)
281
-
282
- Until this version a task stood in one of six derived buckets (queued, running, waiting, stuck, held, done) and its queue
283
- was ranked. A consumer changes this:
284
-
285
- | Before | Now |
286
- |---|---|
287
- | `createWorkflowPlatform({ ..., rules: { urgent } })` | No `rules`. A step that needs a task first calls `tasks.moveToFront`. |
288
- | `tasks.giveNewInput`, `tasks.releaseTask` | `tasks.requeue`: the task joins the back of its queue, its failed tries counted again. |
289
- | `tasks.hold` | `tasks.block`, with the reason in words. A run's own step can also block its task with its outcome (`RunOutcome.blocked`). |
290
- | `tasks.bucketOf`, `bucketCounts`, `BUCKETS`, `TaskSummary.bucket` | `tasks.statusOf`, `statusCounts`, `TASK_STATUSES`, `TaskSummary.status`. |
291
- | `TaskSummary.front`, `urgent`, `reopened`, `unchanged`, `PendingWork.last` | Gone, with the ordering rules they fed. `TaskSummary.returned`: a step or a person put it back, and it has not finished since. |
292
- | `tasks.recordListing(workflow, work)` | `tasks.recordListing({ workflow, work, everyItem })`. |
293
- | A waiting, stuck or held task | Blocked by its Pick, with the reason (`settleQueue`, which `queueNow` and `pickOrder` run). |
294
- | Done: off its workflow's list | Done: its final check passed (a run's outcome with `finished`). A task that only left a `pending` list is no longer its workflow's task and is not counted. |
295
-
296
- Nothing stored changes shape. Notes written before are read as what they did (`storage/task-store.ts` `STATUS_KINDS`),
297
- and counts recorded under the six names are drawn as the four (`views/workflows-view.ts` `historyByStatus`).
298
-
299
- A workflow keeps its `pending` list and works unchanged. It declares `items` in place of it (every item it has a task
300
- for, done or not) once its final check is the one thing that marks its task done.
301
-
302
- The dashboard changed with it. `WorkflowsDashboard` now takes two more props, both required: `path`, the sub-workflow
303
- steps opened below the top workflow, and `hrefOf`, each level's address, which the host page routes back as `path`.
304
- `platform.view` takes `top`, the project's top workflow in its own words. Each workflow's view shows its own steps with
305
- their kinds, its tasks as `queued + in progress + blocked + done = total`, and its blocked tasks counted by reason.
306
- The top level draws the map of workflows again (`src/dashboard/workflow-dag.tsx`): a box a workflow, its name a link to its own level, with the arrows work takes between them, from `fedBy` on a workflow and the store's `returnedBetween` and `listedWaits` (`views/workflow-flows.ts`). A host keeps its alias for `elkjs/lib/elk.bundled.js`, which lays the map out.
307
- A step declares how it runs, `runs: 'deterministic' | 'agentic' | 'classification'`, where it declared `agent: true` or `false`; its kind is what it is: step, check or sub-workflow. The `panels` and `phaseSummary` props are gone, and `sourceHref` is optional now. A sub-workflow step starts its workflow with no run limit of that workflow's own asked, and its steps stand down by the budget of the run at the top: a limit belongs to the workflow whose runs it lets start.
308
-
309
- Two projects run on the platform: the aoe2-in-browser decompilation service, by path from a checkout beside it, and
310
- skill-sync's daemon, on the published release. A release with these changes is a breaking one for the second.
58
+ A step's `access` lists what its code may use: services (the platform's or an organization's) and the workflows whose
59
+ tasks it may read and write. Nothing listed grants nothing, a `run` that uses anything else fails to compile, and the
60
+ worker gives a run only what its step lists.
61
+
62
+ ## What a workflow can do
63
+
64
+ - **Events:** a task, a request, a change to a field (which can resume a task waiting at an end state), a timer (whose
65
+ turn task is what the schema decodes from `{}`), and a declared item list kept in step by `step.syncList`.
66
+ - **Steps:** code, an agent, a sub-workflow (`step.workflow`, or `step.each` with `collect`), an inputs gate
67
+ (`step.inputsChanged`), retries with a delay and a give-up end state, notes on a task that later steps read, and
68
+ writes to other tasks (`StepOutcome.others`) in the same transaction as the step's own result.
69
+ - **Agents:** `AgentRunner` with no tools, a reading mode or a working mode with write scopes, a cached input, and a
70
+ turn limit; the organization implements it.
71
+ - **Queues:** requeue with a note, move tasks to the front, an in-progress limit per workflow or per field value (a
72
+ lock across steps), and retention of records (7 days and the newest 10,000 runs by default).
73
+ - **Records:** every step run's worker, times, end state, error, spend (tokens by kind, requests, cost, compiles),
74
+ CPU and memory, files and agent transcripts, read through the workforce's `stepStats`, `stepRuns`, `tasksAt`,
75
+ `counts` and `task` queries.
76
+
77
+ ## Developing it
78
+
79
+ `bun run typecheck` checks `src`, `component` and `worker` (`tsconfig.check.json`); `tsconfig.json` is the library
80
+ abstract's one line, which its build uses for `src`. `bun test src worker` runs the unit tests. The end-to-end tests
81
+ run in an organization package against a local anonymous Convex deployment.
@@ -0,0 +1,72 @@
1
+ /* eslint-disable */
2
+ /**
3
+ * Generated `api` utility.
4
+ *
5
+ * THIS CODE IS AUTOMATICALLY GENERATED.
6
+ *
7
+ * To regenerate, run `npx convex dev`.
8
+ * @module
9
+ */
10
+
11
+ import type * as engine from "../engine.js";
12
+ import type * as errors from "../errors.js";
13
+ import type * as events from "../events.js";
14
+ import type * as notes from "../notes.js";
15
+ import type * as places from "../places.js";
16
+ import type * as retention from "../retention.js";
17
+ import type * as runEngine from "../runEngine.js";
18
+ import type * as steps from "../steps.js";
19
+ import type * as store from "../store.js";
20
+ import type * as tasks from "../tasks.js";
21
+ import type * as worker from "../worker.js";
22
+ import type * as workflows from "../workflows.js";
23
+
24
+ import type {
25
+ ApiFromModules,
26
+ FilterApi,
27
+ FunctionReference,
28
+ } from "convex/server";
29
+ import { anyApi, componentsGeneric } from "convex/server";
30
+
31
+ const fullApi: ApiFromModules<{
32
+ engine: typeof engine;
33
+ errors: typeof errors;
34
+ events: typeof events;
35
+ notes: typeof notes;
36
+ places: typeof places;
37
+ retention: typeof retention;
38
+ runEngine: typeof runEngine;
39
+ steps: typeof steps;
40
+ store: typeof store;
41
+ tasks: typeof tasks;
42
+ worker: typeof worker;
43
+ workflows: typeof workflows;
44
+ }> = anyApi as any;
45
+
46
+ /**
47
+ * A utility for referencing Convex functions in your app's public API.
48
+ *
49
+ * Usage:
50
+ * ```js
51
+ * const myFunctionReference = api.myModule.myFunction;
52
+ * ```
53
+ */
54
+ export const api: FilterApi<
55
+ typeof fullApi,
56
+ FunctionReference<any, "public">
57
+ > = anyApi as any;
58
+
59
+ /**
60
+ * A utility for referencing Convex functions in your app's internal API.
61
+ *
62
+ * Usage:
63
+ * ```js
64
+ * const myFunctionReference = internal.myModule.myFunction;
65
+ * ```
66
+ */
67
+ export const internal: FilterApi<
68
+ typeof fullApi,
69
+ FunctionReference<any, "internal">
70
+ > = anyApi as any;
71
+
72
+ export const components = componentsGeneric() as unknown as {};