@jive-sh/workflow-platform 0.5.2 → 0.6.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 (50) hide show
  1. package/README.md +50 -5
  2. package/dist/dashboard/queue-table.js +10 -2
  3. package/dist/dashboard/queue-table.js.map +1 -1
  4. package/dist/dashboard/spending-words.js +32 -0
  5. package/dist/dashboard/spending-words.js.map +1 -0
  6. package/dist/index.js +13 -4
  7. package/dist/index.js.map +1 -1
  8. package/dist/project.js +0 -4
  9. package/dist/project.js.map +1 -1
  10. package/dist/queue-counts.js +7 -1
  11. package/dist/queue-counts.js.map +1 -1
  12. package/dist/spending-limit.js +87 -0
  13. package/dist/spending-limit.js.map +1 -0
  14. package/dist/steps.js +125 -14
  15. package/dist/steps.js.map +1 -1
  16. package/dist/storage/budgets.js +27 -2
  17. package/dist/storage/budgets.js.map +1 -1
  18. package/dist/storage/sqlite-store.js +13 -2
  19. package/dist/storage/sqlite-store.js.map +1 -1
  20. package/dist/storage/task-store.js +10 -1
  21. package/dist/storage/task-store.js.map +1 -1
  22. package/dist/tasks.js +35 -5
  23. package/dist/tasks.js.map +1 -1
  24. package/dist/views/format.js +2 -0
  25. package/dist/views/format.js.map +1 -1
  26. package/dist/views/runs-now.js +12 -0
  27. package/dist/views/runs-now.js.map +1 -1
  28. package/dist/views/workflows-view.js +9 -2
  29. package/dist/views/workflows-view.js.map +1 -1
  30. package/package.json +1 -1
  31. package/src/dashboard/dashboard.css +5 -0
  32. package/src/dashboard/queue-bar.tsx +5 -5
  33. package/src/dashboard/queue-table.ts +17 -3
  34. package/src/dashboard/spending-limit-control.tsx +50 -0
  35. package/src/dashboard/spending-words.ts +50 -0
  36. package/src/dashboard/workflow-dag.tsx +1 -1
  37. package/src/dashboard/workflow-drilldown.tsx +5 -5
  38. package/src/dashboard/workflows-dashboard.tsx +28 -3
  39. package/src/index.ts +13 -4
  40. package/src/project.ts +35 -0
  41. package/src/queue-counts.ts +8 -1
  42. package/src/spending-limit.ts +155 -0
  43. package/src/steps.ts +140 -19
  44. package/src/storage/budgets.ts +34 -2
  45. package/src/storage/sqlite-store.ts +14 -3
  46. package/src/storage/task-store.ts +17 -1
  47. package/src/tasks.ts +43 -5
  48. package/src/views/format.ts +3 -0
  49. package/src/views/runs-now.ts +4 -0
  50. package/src/views/workflows-view.ts +27 -4
package/README.md CHANGED
@@ -25,14 +25,30 @@ items. The platform does the rest the same way for every workflow:
25
25
  starts (a timer, its inputs changing, its queue, a request), passes its run limit (`steps.ts` `gatedExecute`): a new run
26
26
  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
27
27
  of work its agents' limit. That kind of workflow also keeps its run limit's number of runs going, and at most its agents'
28
- limit of them are in an agent step at once: a run at an agent step with no agent free waits there, its task kept and its
29
- record saying so, until a limit is set. At 0 agents nothing gets past a first agent step. Setting either limit
28
+ 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
29
+ 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
30
30
  (`runPlanChanged`) has the run planner plan again at once. The run limit is the one way to stop a workflow: at 0 no run
31
31
  of it starts, and a run already going ends before it takes on more work (`steps.ts` `standDownIfSurplus`). In a workflow
32
32
  its budget keeps going that is before an agent step: the run still picks and tests with no agent, and ends at a Pick
33
33
  that finds nothing. In any other it is before a Pick, before an agent step, or at its first step when the engine
34
34
  resumes it after a restart. A step between those still runs, so what an agent step just made is checked and recorded.
35
35
  There is no pause beside it.
36
+ - **A task that needs an agent no run can have gives its run slot up** (`steps.ts` `untilAgentSlot`). Where no agent
37
+ 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
38
+ instead of waiting there: its task goes to the back of its queue, marked "needs an agent" with why in words, and its
39
+ slot goes to work that needs none. Its Pick passes over marked tasks while no agent can be had, and takes them in queue
40
+ order once one can. Something new from outside the workflow clears the mark (a return to its queue, a move to the
41
+ front, any note by a person or another workflow), and so do an agent step that ran on the task and its final check
42
+ passing. A run with no task, or one waiting for an agent another run holds, still waits. The status table's queued row
43
+ says how many need agent, "804 queued (12 need agent)", and an open workflow lists them by reason.
44
+ - **One spending limit for the whole account: "agents stop at X% of the week"** (`spending-limit.ts`, 95 when none is
45
+ set). While the newest good reading of the week is at or past X, every agent step of every workflow waits before its
46
+ 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
47
+ X%", and goes on by itself once a reading is below X. It judges the account's week, not the step records' tokens,
48
+ because the week also counts what no workflow runs (agent threads run by hand). The project gives the reading
49
+ (`WorkflowProject.weekUsage`) and tells the platform of each one it takes (`platform.spending.readingTaken`); a project
50
+ that gives none has no spending limit. A failed or old reading never lifts it: the limit keeps the newest good reading's
51
+ verdict, however old, and the page says the reading is stale and why. An unreadable one holds every agent step.
36
52
  - **Each queue's counts, kept current.** When a queue may have changed (a wake of its Picks, or a Pick claiming an item),
37
53
  the process that runs the workflows counts it within 5 seconds and stores each status's count where it moved
38
54
  (`queue-counts.ts`, `queue_counts`). A page reads the newest rows and their history and never counts.
@@ -126,12 +142,13 @@ Each module's inputs come from `createWorkflowPlatform` (`src/index.ts`), which
126
142
 
127
143
  | Module | What it does | Takes | Gives |
128
144
  |---|---|---|---|
129
- | `project.ts` | What a project tells the platform about itself | n/a | `WorkflowProject`, `ProcessIdentity`, `UsageSink`, `TextStore`, `ProjectTree` |
145
+ | `project.ts` | What a project tells the platform about itself | n/a | `WorkflowProject`, `ProcessIdentity`, `UsageSink`, `TextStore`, `ProjectTree`, `WeekUsage` |
130
146
  | `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` |
131
147
  | `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` |
132
148
  | `storage/task-store.ts` | The task store's interface: tasks, their append-only notes, their listing | n/a | `TaskStore`, `TaskNote`, `TaskRef`, `Listed` |
133
149
  | `storage/engine-records.ts` | Which runs the engine has not finished, from its `cluster_*` tables | the engine's file | `EngineRecords`, `sqliteEngineRecords`, `ensureEngineIndexes` |
134
- | `storage/budgets.ts` | Each workflow's two limits: runs going and agents in an agent step | the file with `workflow_budgets` | `LimitStore`, `runLimit`, the limit SQL |
150
+ | `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 |
151
+ | `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` |
135
152
  | `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` |
136
153
  | `reasons.ts` | Why a step ended as it did, in a line, read from its result | a step's result | `standardReason`, `oneLine` |
137
154
  | `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` |
@@ -172,7 +189,7 @@ SQL client it runs the engine on), and on a dashboard file importing anything bu
172
189
  (`relayTo`, then `wake` there).
173
190
  - A task's inputs changed by anything but a note, a listing or one of its workflow's runs ending (another workflow's write,
174
191
  say) wake no waiting Pick: the next of those events reads them.
175
- - A run waiting at an agent step keeps its task for as long as it waits; a lease the project keeps on the item itself can
192
+ - 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
176
193
  run out meanwhile.
177
194
  - The scheduler's job ledger (which job turn is due) is still the first project's own.
178
195
 
@@ -198,6 +215,11 @@ At the top it also draws what the project gives of its machine and its agents' a
198
215
  limit with − and + (`setCpuLimit`, `cpu.threads`), the stop of everything and its resume (`stopEverything`, `resume`,
199
216
  `stopped`), and what the account has used of each of its limits (`usage`, `src/dashboard/agent-usage.ts`).
200
217
 
218
+ On every level it draws the spending limit where the project reads its week (`view.spending`,
219
+ `src/dashboard/spending-limit-control.tsx`): what it is set to with − and + (`setSpendingLimit`), the week's reading
220
+ against it and whether it holds every agent step, why the reading is stale where it is, and which agent steps wait on it,
221
+ each in words.
222
+
201
223
  ```tsx
202
224
  import { usePolledJson, WorkflowsDashboard, type WorkflowsPageData } from '@jive-sh/workflow-platform/dashboard';
203
225
 
@@ -214,6 +236,29 @@ release exports the main entry only, so a host names the dashboard's two files b
214
236
  `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
215
237
  app's copies (`aoe2-in-browser/decomp-dashboard/next.config.ts` does this).
216
238
 
239
+ ## The spending limit, and tasks that need an agent (0.6.0, 2026-11-20)
240
+
241
+ A project gets a spending limit by giving its week and storing the setting:
242
+
243
+ - **`WorkflowProject.weekUsage`**: `now()`, its newest good reading of the week (used percent, when read, when it resets)
244
+ and a read that failed after it; and `staleAfterSeconds`, when a page calls the reading stale. Without it nothing
245
+ changes.
246
+ - **`platform.spending.readingTaken()`** after each reading it stores: a verdict that changed wakes every waiting step.
247
+ - **A table `spending_limit`** in the file with `workflow_budgets` (`storage/budgets.ts` gives its shape); no row is 95%.
248
+ - **A route** that calls `platform.spending.set({ weekPercent, from, write })`, which checks the percent, writes it with
249
+ the platform's statement, wakes every waiting step and logs who asked; and the page's `setSpendingLimit`.
250
+
251
+ Three shapes grew: `LimitStore` has `spendingLimit`, `WorkflowsView` has `spending`, and `StepRunsNow` has
252
+ `heldBySpendingLimit`, so a store of its own, or a test building these by hand, needs them.
253
+
254
+ The same release marks a task that needs an agent no run can have (above). Nothing stored changes shape: the mark is two
255
+ new note kinds, `needs an agent` and `an agent step ran` (`storage/task-store.ts`), and the queued tasks marked are a
256
+ count of their own in `queue_counts` (`queue-counts.ts` `QUEUED_NEEDING_AN_AGENT`). A workflow that branches on
257
+ `isStoodDown` treats the new end of a run, `NEEDS_AN_AGENT_STOOD_DOWN`, as it treats a run that stood down: no try, its
258
+ item given back. Shapes that grew: `TaskState` and `TaskSummary` have `needsAgent`, a fake `AgentBudgets.agentSlot`
259
+ answers `unavailable` beside `why`, `WorkflowFigures` has `needingAnAgent`, `WorkflowView` has `queuedNeedingAnAgent`,
260
+ and `QueueBar` takes it.
261
+
217
262
  ## Moving from six buckets to four statuses (0.x, 2026-11-19)
218
263
 
219
264
  Until this version a task stood in one of six derived buckets (queued, running, waiting, stuck, held, done) and its queue
@@ -1,8 +1,16 @@
1
1
  /** A count as the table writes it: thousands separated, as every figure on the page is. */
2
2
  const written = (tasks) => tasks.toLocaleString('en-US');
3
- export const queueSum = (queue) => {
4
- const addends = Object.entries(queue).map(([category, tasks]) => ({ category, tasks, text: written(tasks) }));
3
+ /** "12 need agent", "1 needs agent": Alex, 2026-11-20: "(12 need agent) is fine. no 'an'". */
4
+ const needWords = (tasks) => `${written(tasks)} ${tasks === 1 ? 'needs' : 'need'} agent`;
5
+ /** `queuedNeedingAnAgent`: how many queued tasks are marked as needing an agent; none where none can be (`WorkflowView`). */
6
+ export const queueSum = (queue, queuedNeedingAnAgent = null) => {
7
+ const addends = Object.entries(queue).map(([category, tasks]) => ({
8
+ category, tasks, text: written(tasks),
9
+ note: category === 'queued' && queuedNeedingAnAgent !== null ? needWords(queuedNeedingAnAgent) : null,
10
+ }));
5
11
  const total = addends.reduce((sum, a) => sum + a.tasks, 0);
6
12
  return { addends, total, totalText: written(total) };
7
13
  };
14
+ /** An addend's label as the table and its one-line form write it: "queued (12 need agent)". */
15
+ export const addendLabel = (a) => (a.note === null ? a.category : `${a.category} (${a.note})`);
8
16
  //# sourceMappingURL=queue-table.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"queue-table.js","sourceRoot":"","sources":["../../../../src/dashboard/queue-table.ts"],"names":[],"mappings":"AAeA,2FAA2F;AAC3F,MAAM,OAAO,GAAG,CAAC,KAAa,EAAU,EAAE,CAAC,KAAK,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;AAEzE,MA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C,IAAI,EAAE,QAAQ,KAAK,QAAQ,IAAI,oBAAoB,KAAK,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC,IAAI;KACtG,CAAC,CAAC,CAAC;IACJ,MAAM,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IAC3D,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;AACvD,CAAC,CAAC;AAEF,+FAA+F;AAC/F,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,CAA8B,EAAU,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,QAAQ,KAAK,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC"}
@@ -0,0 +1,32 @@
1
+ import { percentCut, whenAgo } from '../views/format';
2
+ /** Every agent step the limit holds a run at now, from where runs are now. */
3
+ export const heldSteps = (runsNow) => runsNow.flatMap((p) => p.workflows.flatMap((w) => w.steps.filter((s) => s.heldBySpendingLimit > 0).map((s) => ({ workflow: w.workflow, step: s.step, runs: s.heldBySpendingLimit }))));
4
+ /** What the limit is set to: "agents stop at 95% of the week (the default)". */
5
+ export const spendingSettingWords = (s) => `Spending limit: agents stop at ${s.limitPercent}% of the week${s.setAt === null ? ' (the default)' : ''}`;
6
+ /** The week's reading against the limit, and whether it holds every agent step. */
7
+ export const spendingVerdictWords = (s, now) => {
8
+ if (s.reading === null) {
9
+ return s.failedSince === null
10
+ ? "Holds nothing: there is no reading of the week's use yet."
11
+ : `Holds nothing: there is no good reading of the week's use yet; the newest read failed at ${whenAgo(s.failedSince.at, now)}: ${s.failedSince.error}`;
12
+ }
13
+ const reading = `the week's use is ${percentCut(s.reading.usedPercent)}, read ${whenAgo(s.reading.readAt, now)}`;
14
+ return s.holds
15
+ ? `Holding every agent step: ${reading}, at or past the limit. Each waits before its agent call until a reading is below ${s.limitPercent}%.`
16
+ : `Holds nothing: ${reading}, below the limit.`;
17
+ };
18
+ /** Why the reading is stale and what the limit does meanwhile; none while it is current. */
19
+ export const spendingStaleWords = (s, now) => {
20
+ if (!s.stale)
21
+ return null;
22
+ return s.failedSince === null
23
+ ? "The reading is stale: none came since. The limit keeps that reading's verdict until a new one."
24
+ : `The reading is stale: the newest read failed at ${whenAgo(s.failedSince.at, now)} (${s.failedSince.error}). The limit keeps the last good reading's verdict until a read succeeds.`;
25
+ };
26
+ /** Which agent steps wait on it; none to say while it holds nothing and nothing waits. */
27
+ export const heldStepsWords = (s, held) => {
28
+ if (held.length === 0)
29
+ return s.holds ? 'No agent step has reached it yet.' : null;
30
+ return `Waiting on it: ${held.map((h) => `${h.workflow}, step ${h.step} (${h.runs} run${h.runs === 1 ? '' : 's'})`).join('; ')}.`;
31
+ };
32
+ //# sourceMappingURL=spending-words.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spending-words.js","sourceRoot":"","sources":["../../../../src/dashboard/spending-words.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAStD,8EAA8E;AAC9E,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,OAAoC,EAA2B,EAAE,CACzF,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,mBAAmB,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,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AC,gGAAgG;QAClG,CAAC,CAAC,mDAAmD,OAAO,CAAC,CAAC,CAAC,WAAW,CAAC,EAAE,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,WAAW,CAAC,KAAK,2EAA2E,CAAC;AAC3L,CAAC,CAAC;AAEF,0FAA0F;AAC1F,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAoC,EAAE,IAA6B,EAAiB,EAAE;IACnH,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,mCAAmC,CAAC,CAAC,CAAC,IAAI,CAAC;IACnF,OAAO,kBAAkB,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,QAAQ,UAAU,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC;AACpI,CAAC,CAAC"}
package/dist/index.js CHANGED
@@ -12,9 +12,10 @@ import { makePickWakes } from './pick-wakes';
12
12
  import { makeStepFiles } from './step-files';
13
13
  import { makeStepUsage } from './step-usage';
14
14
  import { keptRunningByItsBudget, makeSteps, runLimitOf } from './steps';
15
- import { blockedReasons, makeTasks } from './tasks';
15
+ import { blockedReasons, makeTasks, needsAgentReasons } from './tasks';
16
16
  import { buildWorkflowFigures, buildWorkflowsView } from './views/workflows-view';
17
17
  import { makeQueueCounts } from './queue-counts';
18
+ import { makeSpendingLimit } from './spending-limit';
18
19
  import { sqliteBudgets } from './storage/budgets';
19
20
  import { sqliteEngineRecords } from './storage/engine-records';
20
21
  import { sqliteStore } from './storage/sqlite-store';
@@ -24,6 +25,7 @@ export * from './budget-states';
24
25
  export * from './keep-running';
25
26
  export * from './pick-wakes';
26
27
  export * from './queue-counts';
28
+ export * from './spending-limit';
27
29
  export * from './step-files';
28
30
  export * from './step-meter';
29
31
  export * from './steps';
@@ -69,10 +71,12 @@ export const createWorkflowPlatform = (input) => {
69
71
  const stepFiles = makeStepFiles({ tree: project.tree, runLightNow: project.runLightNow });
70
72
  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}`))); } });
71
73
  const tasks = makeTasks({ store: storage.tasks, engine: storage.engine, stepRecords: storage.stepRecords, wakes, texts: project.texts });
74
+ const spending = makeSpendingLimit({ store: storage.budgets, usage: project.weekUsage === undefined ? null : project.weekUsage, wakes });
72
75
  const steps = makeSteps({
73
76
  sourceRoot: project.sourceRoot, stepRecords: storage.stepRecords, engine: storage.engine, tasks, wakes, budgets: storage.budgets, stepFiles,
74
77
  CurrentStepUsage: stepUsage.CurrentStepUsage, isTransientFailure: project.isTransientFailure, thisProcess: project.processes.thisProcess, inputs: storage.inputs,
75
78
  queueChanged: (workflow) => queueCounts.changed(workflow),
79
+ spendingHoldsAgents: spending.holdsAgents,
76
80
  });
77
81
  const queueCounts = makeQueueCounts({
78
82
  store: storage.tasks, tasks, wakes,
@@ -109,16 +113,21 @@ export const createWorkflowPlatform = (input) => {
109
113
  */
110
114
  const view = (r) => Effect.gen(function* () {
111
115
  const limits = yield* limitsNow();
112
- return yield* buildWorkflowsView({ declared: steps.declaredWorkflows(), phases: r.phases, top: r.top, now: r.now, taskStore: storage.tasks, locate, limitsOf: (name) => limits[name] ?? null });
116
+ return yield* buildWorkflowsView({ declared: steps.declaredWorkflows(), phases: r.phases, top: r.top, now: r.now, taskStore: storage.tasks, locate, limitsOf: (name) => limits[name] ?? null, spending: yield* spending.state(r.now) });
113
117
  });
114
118
  /** One workflow's figures over the `hours` before `now`, read from its own records (`buildWorkflowFigures`); none for one not declared. */
115
119
  const figures = (r) => {
116
120
  const declaration = steps.declaredWorkflows().find((d) => d.name === r.workflow);
117
121
  return declaration === undefined ? Effect.succeed(null) : buildWorkflowFigures({
118
122
  declaration, now: r.now, hours: r.hours, records: storage.stepRecords, engine: storage.engine, locate,
119
- blocked: declaration.item === null ? Effect.succeed([]) : Effect.map(tasks.taskSummaries({ workflow: r.workflow }), blockedReasons),
123
+ reasons: declaration.item === null
124
+ ? Effect.succeed({ blocked: [], needingAnAgent: { reasons: [], passedOverBecause: null } })
125
+ : Effect.map(Effect.all({ summaries: tasks.taskSummaries({ workflow: r.workflow }), unavailable: steps.agentsUnavailable(r.workflow) }), ({ summaries, unavailable }) => ({
126
+ blocked: blockedReasons(summaries),
127
+ needingAnAgent: { reasons: needsAgentReasons(summaries), passedOverBecause: unavailable },
128
+ })),
120
129
  });
121
130
  };
122
- return { project, storage, wakes, stepFiles, stepUsage, tasks, steps, view, figures, limitsNow, queueCounts };
131
+ return { project, storage, wakes, stepFiles, stepUsage, tasks, steps, view, figures, limitsNow, queueCounts, spending };
123
132
  };
124
133
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAG7B,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,sBAAsB,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACxE,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpD,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAA+D,MAAM,wBA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EAAE,iBAAiB,EAAE,WAAW,EAAE;iBAC1F,CAAC,CAAC;SACN,CAAC,CAAC;IACL,CAAC,CAAC;IACF,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC;AAC1H,CAAC,CAAC"}
package/dist/project.js CHANGED
@@ -1,6 +1,2 @@
1
- /**
2
- * WHAT A PROJECT TELLS THE PLATFORM ABOUT ITSELF: the facts no generic code can know. Everything else (how a step is
3
- * measured, how a task is queued, when a waiting Pick wakes) is the platform's.
4
- */
5
1
  export {};
6
2
  //# sourceMappingURL=project.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"project.js","sourceRoot":"","sources":["../../../src/project.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
1
+ {"version":3,"file":"project.js","sourceRoot":"","sources":["../../../src/project.ts"],"names":[],"mappings":""}
@@ -13,10 +13,16 @@ import { Effect } from 'effect';
13
13
  import { statusCounts } from './tasks';
14
14
  /** How long after a queue's first change it is counted: every change in that time is in the one count. */
15
15
  export const COUNT_AFTER_MS = 5_000;
16
+ /**
17
+ * The count recorded beside the four statuses: how many queued tasks are marked as needing an agent (`tasks.ts`
18
+ * `TaskSummary.needsAgent`). Part of `queued`, never an addend of its own: a page shows it beside that row.
19
+ */
20
+ export const QUEUED_NEEDING_AN_AGENT = 'queued, needing an agent';
16
21
  export const makeQueueCounts = (deps) => {
17
22
  /** Counts one workflow's queue now and records it. */
18
23
  const count = (workflow) => Effect.gen(function* () {
19
- const counts = statusCounts(yield* deps.tasks.taskSummaries({ workflow }));
24
+ const summaries = yield* deps.tasks.taskSummaries({ workflow });
25
+ const counts = { ...statusCounts(summaries), [QUEUED_NEEDING_AN_AGENT]: summaries.filter((t) => t.status === 'queued' && t.needsAgent !== null).length };
20
26
  yield* deps.store.recordQueueCounts({ at: Date.now() / 1000, counts: Object.entries(counts).map(([bucket, tasks]) => ({ workflow, bucket, tasks })) });
21
27
  });
22
28
  let countSoon = () => undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"queue-counts.js","sourceRoot":"","sources":["../../../src/queue-counts.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAIhC,OAAO,EAAE,YAAY,EAAc,MAAM,SAAS,CAAC;AAEnD,0GAA0G;AAC1G,MAAM,CAAC,MAAM,cAAc,GAAG,KAAK,CAAC;AAEpC,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,IAQ/B,EAAE,EAAE;IACH,sDAAsD;IACtD,MAAM,KAAK,GAAG,CAAC,QAAgB,EAAqC,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;QACzF,MAAM,MAAM,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC;QAC3E,KAAK,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,iBAAiB,CAAC,EAAE,EAAE,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;IACzJ,CAAC,CAAC,CAAC;IAEH,IAAI,SAAS,GAA+B,GAAG,EAAE,CAAC,SAAS,CAAC;IAE5D;;;OAGG;IACH,MAAM,MAAM,GAAG,CAAC,GAAgE,EAAQ,EAAE;QACxF,MAAM,GAAG,GAAG,IAAI,GAAG,EAAU,CAAC;QAC9B,SAAS,GAAG,CAAC,QAAQ,EAAE,EAAE;YACvB,IAAI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AAC,QAAQ,CAAC,EAAE,CAAC;AACrF,CAAC,CAAC"}
@@ -0,0 +1,87 @@
1
+ /**
2
+ * THE SPENDING LIMIT: ONE SETTING FOR THE WHOLE ACCOUNT, "AGENTS STOP AT X% OF THE WEEK". Alex, 2026-11-20: "ideally the
3
+ * workflow platform offers a configurable spending limit", and, of this design, "yes to building the spending limit".
4
+ *
5
+ * While the project's newest good reading of its week (`WorkflowProject.weekUsage`) is at or past X, every agent step of
6
+ * every workflow waits before its agent call, as it waits at an agents' limit of 0 (`steps.ts` `untilAgentSlot`), its record
7
+ * saying why in words (`spendingWait`). An agent call already going is never cut off. The steps go on by themselves once a
8
+ * reading is below X, which the week's reset brings: the project tells the platform of each reading it takes
9
+ * (`readingTaken`), and a verdict that changed wakes every waiting step. None is set: X is 95 (`DEFAULT_SPENDING_LIMIT_PERCENT`).
10
+ *
11
+ * IT JUDGES THE ACCOUNT'S WEEK, NOT A COUNT OF TOKENS, because the week is the one figure that also counts spending the
12
+ * platform cannot see: agent threads run by hand, outside any workflow, which no step record holds. They were 73% of the
13
+ * spending of the week that ran out on 2026-11-01, 57 hours before its reset (the first project's `usage/pace.ts`).
14
+ *
15
+ * A READING THAT FAILS OR GROWS OLD NEVER LIFTS IT. The rule judges the newest good reading, however old, so a hold stands
16
+ * until a good reading below X, and a page says the reading is stale and why. That holds past the reset the reading named
17
+ * too: with every read failing, agents wait until one succeeds, rather than spend on a week nobody can see. A reading that
18
+ * cannot be read at all holds every agent step, as limits that cannot be read hold their runs. With no good reading yet
19
+ * there is nothing to judge, and nothing is held. A project that reads no week has no spending limit.
20
+ */
21
+ import { Effect, pipe, Result } from 'effect';
22
+ import { SET_SPENDING_LIMIT_SQL } from './storage/budgets';
23
+ import { percentCut } from './views/format';
24
+ /** The percent of the week at which agents stop where none is set. */
25
+ export const DEFAULT_SPENDING_LIMIT_PERCENT = 95;
26
+ /** What every agent step's record says while the limit holds it. */
27
+ export const spendingWait = (r) => `waits: the week's use is ${percentCut(r.usedPercent)}, at or past the spending limit of ${r.limitPercent}%`;
28
+ /** How every wait the spending limit gives starts, its unreadable one included. */
29
+ const SPENDING_WAIT_START = "waits: the week's use ";
30
+ /** Whether what a step waits on is the spending limit: what a page counts its waiting steps by. Pure. */
31
+ export const isSpendingLimitWait = (why) => why.startsWith(SPENDING_WAIT_START);
32
+ /** The limit against the week now. Pure. */
33
+ export const judgeSpending = (input) => {
34
+ const limitPercent = input.limit === null ? DEFAULT_SPENDING_LIMIT_PERCENT : input.limit.weekPercent;
35
+ const good = input.usage.good;
36
+ return {
37
+ limitPercent,
38
+ setAt: input.limit === null ? null : input.limit.changedAt,
39
+ reading: good,
40
+ failedSince: input.usage.failedSince,
41
+ stale: good !== null && (input.usage.failedSince !== null || input.now - good.readAt > input.staleAfterSeconds),
42
+ holds: good !== null && good.usedPercent >= limitPercent,
43
+ };
44
+ };
45
+ export const makeSpendingLimit = (deps) => {
46
+ const { usage } = deps;
47
+ const state = (now) => usage === null ? Effect.succeed(null) : Effect.map(Effect.all({ limit: deps.store.spendingLimit(), week: usage.now() }), ({ limit, week }) => judgeSpending({ limit, usage: week, staleAfterSeconds: usage.staleAfterSeconds, now }));
48
+ /** What the last reading told held, in this process; none before the first. */
49
+ let heldAtLastReading = null;
50
+ /** A step found the week unreadable since the last reading, so it waits for a wake that a changed verdict alone may not bring. */
51
+ let unreadSinceLastReading = false;
52
+ return {
53
+ holdsAgents: () => pipe(state(Date.now() / 1000), Effect.map((s) => (s === null || !s.holds || s.reading === null ? null : {
54
+ why: spendingWait({ usedPercent: s.reading.usedPercent, limitPercent: s.limitPercent }),
55
+ unavailable: `the week's use is ${percentCut(s.reading.usedPercent)}, at or past the spending limit of ${s.limitPercent}%`,
56
+ })), Effect.catchTag('StorageError', (e) => Effect.sync(() => {
57
+ unreadSinceLastReading = true;
58
+ return { why: `waits: the week's use could not be read (${e.reason}), so the spending limit holds every agent step`, unavailable: null };
59
+ }))),
60
+ state,
61
+ readingTaken: () => Effect.gen(function* () {
62
+ const judged = yield* Effect.result(state(Date.now() / 1000));
63
+ if (Result.isFailure(judged))
64
+ return yield* Effect.logError(`[spending limit] a reading was taken and could not be judged: ${judged.failure.reason}`);
65
+ const holds = judged.success !== null && judged.success.holds;
66
+ if (holds === heldAtLastReading && !unreadSinceLastReading)
67
+ return;
68
+ if (holds !== heldAtLastReading && judged.success !== null) {
69
+ yield* Effect.log(`[spending limit] ${holds ? 'holds every agent step' : 'holds nothing'}: the week's use is ${judged.success.reading === null ? 'not read yet' : percentCut(judged.success.reading.usedPercent)}, the limit ${judged.success.limitPercent}%`);
70
+ }
71
+ heldAtLastReading = holds;
72
+ unreadSinceLastReading = false;
73
+ deps.wakes.wakeEveryPick(holds ? 'a reading at or past the spending limit' : 'a reading below the spending limit');
74
+ }),
75
+ set: (r) => Effect.gen(function* () {
76
+ const weekPercent = r.weekPercent;
77
+ if (typeof weekPercent !== 'number' || !Number.isInteger(weekPercent) || weekPercent < 0 || weekPercent > 100) {
78
+ return { ok: false, error: 'weekPercent must be a whole number from 0 to 100' };
79
+ }
80
+ yield* r.write({ sql: SET_SPENDING_LIMIT_SQL, params: [weekPercent, Date.now() / 1000] });
81
+ deps.wakes.wakeEveryPick('the spending limit set');
82
+ yield* Effect.log(`[spending limit] ${weekPercent}%, from ${r.from}`);
83
+ return { ok: true, weekPercent };
84
+ }),
85
+ };
86
+ };
87
+ //# sourceMappingURL=spending-limit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spending-limit.js","sourceRoot":"","sources":["../../../src/spending-limit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAG9C,OAAO,EAAE,sBAAsB,EAA6C,MAAM,mBAAmB,CAAC;AAEtG,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C,sEAAsE;AACtE,MAAM,CAAC,MAAM,8BAA8B,GAA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