@nathanstephenson/flow 0.1.10-beta.5 → 0.1.10-beta.6

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 (44) hide show
  1. package/build/backend-worker-chunks/{chunk-JOI2POLP.mjs → chunk-U73G6KK4.mjs} +18 -0
  2. package/build/backend-worker-chunks/{claude-GY27HBAY.mjs → claude-THGSOTC2.mjs} +7 -1
  3. package/build/backend-worker-chunks/{pi-JV6MWPW7.mjs → pi-5LAWIJNE.mjs} +82 -3
  4. package/build/backend-worker.mjs +7 -3
  5. package/dist/backend/claude/index.js +6 -0
  6. package/dist/backend/fake/index.js +6 -0
  7. package/dist/backend/pi/index.js +34 -2
  8. package/dist/backend/pi/plan-limits.js +41 -0
  9. package/dist/backend/plan-limits.js +17 -0
  10. package/dist/backend/worker/entry.js +4 -1
  11. package/dist/backend/worker/index.js +5 -0
  12. package/dist/backend/worker/protocol.js +2 -1
  13. package/dist/build-id +1 -1
  14. package/dist/cli/bootstrap.js +1 -1
  15. package/dist/client/context-usage.js +1 -1
  16. package/dist/client/markdown.js +3 -2
  17. package/dist/daemon/config-store.js +1 -0
  18. package/dist/daemon/config.js +31 -2
  19. package/dist/daemon/github-image.js +18 -0
  20. package/dist/daemon/host.js +147 -6
  21. package/dist/daemon/runtime.js +1 -1
  22. package/dist/daemon/server.js +26 -0
  23. package/dist/daemon/skills.js +24 -0
  24. package/dist/daemon/spend-ledger.js +118 -0
  25. package/dist/daemon/summariser.js +11 -4
  26. package/dist/daemon/tour.js +42 -0
  27. package/dist/daemon/workflow-builder.js +3 -1
  28. package/dist/daemon/workflow-execution-resources.js +1 -1
  29. package/dist/daemon/workflow-routes.js +19 -0
  30. package/dist/daemon/workflow-schedules.js +6 -5
  31. package/dist/protocol/plan-limits.js +1 -0
  32. package/dist/protocol/spend.js +2 -0
  33. package/dist/workflows/scheduler.js +26 -14
  34. package/dist/workflows/store.js +16 -2
  35. package/package.json +1 -1
  36. package/web/dist/assets/index-BhfJhrVJ.js +51 -0
  37. package/web/dist/assets/index-BvkM2cWL.css +2 -0
  38. package/web/dist/assets/{settings-mcp-BwOPXAfH.js → settings-mcp-3cgqQB28.js} +1 -1
  39. package/web/dist/assets/{settings-workflows-DocTa31_.js → settings-workflows-Cutm8isB.js} +1 -1
  40. package/web/dist/assets/{workflows-DJqUuGyg.js → workflows-D6oEUUhj.js} +3 -3
  41. package/web/dist/assets/{workflows-pane-oM1fO_BC.js → workflows-pane-KIdSDKJB.js} +1 -1
  42. package/web/dist/index.html +3 -3
  43. package/web/dist/assets/index-BqZ_iUmY.css +0 -2
  44. package/web/dist/assets/index-CxdSb7k0.js +0 -51
@@ -254,15 +254,16 @@ export class WorkflowScheduleService {
254
254
  }
255
255
  }
256
256
  }
257
- create(settings, enabled) {
258
- return this.serial(async () => { await this.driver.validate(settings); const saved = createSchedule(settings, this.now(), enabled); this.store.saveSchedule(saved); return saved; });
257
+ async create(settings, enabled) {
258
+ await this.driver.validate(settings);
259
+ return this.serial(() => { const saved = createSchedule(settings, this.now(), enabled); this.store.saveSchedule(saved); return saved; });
259
260
  }
260
- update(id, revision, settings, enabled) {
261
- return this.serial(async () => {
261
+ async update(id, revision, settings, enabled) {
262
+ await this.driver.validate(settings);
263
+ return this.serial(() => {
262
264
  const current = this.store.getSchedule(id);
263
265
  if (current.revision !== revision)
264
266
  throw new ScheduleRevisionConflict();
265
- await this.driver.validate(settings);
266
267
  const saved = editSchedule(current, settings, enabled, this.now());
267
268
  this.store.saveSchedule(saved, revision);
268
269
  return saved;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ export const SPEND_SOURCES = ["session", "workflow", "naming", "publish", "builder"];
2
+ export const SPEND_WINDOWS = ["day", "week", "month", "lifetime"];
@@ -27,7 +27,15 @@ export class WorkflowScheduler {
27
27
  this.executors = executors;
28
28
  this.onResume = onResume;
29
29
  for (const owner of store.listOwners()) {
30
- for (const record of store.listOwnedExecutions(owner)) {
30
+ let records;
31
+ try {
32
+ records = store.listOwnedExecutions(owner);
33
+ }
34
+ catch {
35
+ console.error('Workflow Execution owner records are invalid. Files retained for manual review.');
36
+ continue;
37
+ }
38
+ for (const record of records) {
31
39
  if (!occupied(record))
32
40
  continue;
33
41
  if (this.slots.has(executionOwnerKey(owner)))
@@ -320,20 +328,22 @@ export class WorkflowScheduler {
320
328
  }
321
329
  }
322
330
  reconcile(active) {
331
+ if (occupied(active.record)) {
332
+ for (const [id, state] of Object.entries(active.record.steps)) {
333
+ if (state.status !== 'running' || active.calls.has(id))
334
+ continue;
335
+ state.status = 'interrupted';
336
+ const attempt = state.attempts.at(-1);
337
+ attempt.error = { kind: 'interrupted', message: 'Execution was interrupted; effects may already have occurred' };
338
+ attempt.finishedAt ??= Date.now();
339
+ }
340
+ active.record.status = 'recovery-required';
341
+ active.stopped = !!active.parent?.stopped || Object.values(active.record.steps).some(state => state.status === 'interrupted');
342
+ for (const id of active.calls.keys())
343
+ this.armCall(active, id);
344
+ }
323
345
  for (const call of active.calls.values())
324
346
  this.reconcile(call.child);
325
- if (!occupied(active.record))
326
- return;
327
- for (const [id, state] of Object.entries(active.record.steps)) {
328
- if (state.status !== 'running' || active.calls.has(id))
329
- continue;
330
- state.status = 'interrupted';
331
- const attempt = state.attempts.at(-1);
332
- attempt.error = { kind: 'interrupted', message: 'Execution was interrupted; effects may already have occurred' };
333
- attempt.finishedAt ??= Date.now();
334
- }
335
- active.record.status = 'recovery-required';
336
- active.stopped = true;
337
347
  }
338
348
  releaseCancelledCall(active, stepId) {
339
349
  const call = active.calls.get(stepId);
@@ -617,7 +627,9 @@ export class WorkflowScheduler {
617
627
  else {
618
628
  const terminals = active.graph.order.filter(step => active.record.steps[step.id].status === 'completed' && (active.record.testStepId || !active.graph.outgoing.get(step.id).some(edge => this.edgeState(active, edge) === 'selected')));
619
629
  active.record.result = terminals.length === 1 ? active.record.steps[terminals[0].id].output : Object.fromEntries(terminals.map(step => [step.name, active.record.steps[step.id].output]));
620
- active.record.status = Object.values(active.record.loops ?? {}).some(loop => loop.grants.length) || Object.values((active.root ?? active).record.invocations ?? {}).some(invocation => invocation.status === 'completed-with-recovery') || states.some(([, state]) => state.attempts.some(attempt => attempt.error || attempt.action !== 'execute')) ? 'completed-with-recovery' : 'completed';
630
+ const invocations = (active.root ?? active).record.invocations ?? {};
631
+ const descends = (id) => id !== undefined && (id === active.record.id || descends(invocations[id].parentInvocationId));
632
+ active.record.status = Object.values(active.record.loops ?? {}).some(loop => loop.grants.length) || Object.values(invocations).some(invocation => invocation.status === 'completed-with-recovery' && (!active.parent || descends(invocation.parentInvocationId))) || states.some(([, state]) => state.attempts.some(attempt => attempt.error || attempt.action !== 'execute')) ? 'completed-with-recovery' : 'completed';
621
633
  active.record.finishedAt = Date.now();
622
634
  }
623
635
  this.persist(active);
@@ -63,9 +63,23 @@ export class WorkflowStore {
63
63
  const directory = join(stateRoot, 'workflow-schedules', 'executions');
64
64
  const occurrences = existsSync(directory) ? readdirSync(directory, { withFileTypes: true }).filter(entry => entry.isDirectory()).map(entry => ({ kind: 'occurrence', occurrenceId: entry.name })) : [];
65
65
  for (const owner of [...this.listSessionIds().map(sessionId => ({ kind: 'session', sessionId })), ...occurrences]) {
66
+ let history;
67
+ try {
68
+ history = this.historyPath(owner);
69
+ }
70
+ catch {
71
+ console.error('Workflow Execution owner directory is invalid. Directory retained for manual review.');
72
+ continue;
73
+ }
66
74
  this.owners.set(this.ownerIndexKey(owner), owner);
67
- for (const id of ids(this.historyPath(owner)))
68
- this.index(this.readExecution(owner, id));
75
+ for (const id of ids(history)) {
76
+ try {
77
+ this.index(this.readExecution(owner, id));
78
+ }
79
+ catch {
80
+ console.error('Workflow Execution checkpoint is invalid. File retained for manual review.');
81
+ }
82
+ }
69
83
  }
70
84
  }
71
85
  saveDefinition(definition) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nathanstephenson/flow",
3
- "version": "0.1.10-beta.5",
3
+ "version": "0.1.10-beta.6",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",