@nathanstephenson/flow 0.1.10-beta.4 → 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 (101) hide show
  1. package/README.md +2 -2
  2. package/build/backend-worker-chunks/{chunk-JOI2POLP.mjs → chunk-U73G6KK4.mjs} +18 -0
  3. package/build/backend-worker-chunks/{claude-GY27HBAY.mjs → claude-THGSOTC2.mjs} +7 -1
  4. package/build/backend-worker-chunks/{pi-JV6MWPW7.mjs → pi-5LAWIJNE.mjs} +82 -3
  5. package/build/backend-worker.mjs +7 -3
  6. package/build/workflow-runtime.cjs +12 -12
  7. package/dist/backend/claude/index.js +6 -0
  8. package/dist/backend/claude/workflow-parent.js +1 -1
  9. package/dist/backend/fake/index.js +6 -0
  10. package/dist/backend/pi/index.js +34 -2
  11. package/dist/backend/pi/model-auth.js +2 -2
  12. package/dist/backend/pi/plan-limits.js +41 -0
  13. package/dist/backend/pi/workflow-parent.js +1 -1
  14. package/dist/backend/plan-limits.js +17 -0
  15. package/dist/backend/worker/entry.js +4 -1
  16. package/dist/backend/worker/index.js +9 -3
  17. package/dist/backend/worker/launcher.js +11 -4
  18. package/dist/backend/worker/protocol.js +2 -1
  19. package/dist/build-id +1 -1
  20. package/dist/cli/application.js +5 -5
  21. package/dist/cli/bootstrap.js +1 -1
  22. package/dist/cli/host-control.js +1 -1
  23. package/dist/cli/install-guard.js +1 -1
  24. package/dist/cli/main.js +4 -4
  25. package/dist/cli/systemd-update.js +3 -3
  26. package/dist/cli/update.js +6 -6
  27. package/dist/cli/web-update.js +6 -6
  28. package/dist/client/context-usage.js +1 -1
  29. package/dist/client/markdown.js +3 -2
  30. package/dist/daemon/changes.js +116 -0
  31. package/dist/daemon/commit.js +84 -0
  32. package/dist/daemon/config-store.js +4 -3
  33. package/dist/daemon/config.js +31 -2
  34. package/dist/daemon/git-state.js +197 -0
  35. package/dist/daemon/github-image.js +18 -0
  36. package/dist/daemon/github.js +54 -0
  37. package/dist/daemon/host-control-routes.js +1 -1
  38. package/dist/daemon/host.js +280 -81
  39. package/dist/daemon/log.js +3 -0
  40. package/dist/daemon/mcp-auth.js +1 -1
  41. package/dist/daemon/pi-model-cache.js +1 -1
  42. package/dist/daemon/pull-request.js +156 -129
  43. package/dist/daemon/push.js +43 -0
  44. package/dist/daemon/repository.js +106 -0
  45. package/dist/daemon/runtime.js +28 -21
  46. package/dist/daemon/secret-store.js +1 -1
  47. package/dist/daemon/server.js +37 -10
  48. package/dist/daemon/skills.js +24 -0
  49. package/dist/daemon/spend-ledger.js +118 -0
  50. package/dist/daemon/stack-metadata.js +12 -5
  51. package/dist/daemon/stack.js +127 -656
  52. package/dist/daemon/summariser.js +30 -12
  53. package/dist/daemon/tour.js +42 -0
  54. package/dist/daemon/workflow-authoring-scope-checks.js +1 -1
  55. package/dist/daemon/workflow-authoring-scope.js +1 -1
  56. package/dist/daemon/workflow-builder-files.js +2 -2
  57. package/dist/daemon/workflow-builder-routes.js +2 -2
  58. package/dist/daemon/workflow-builder.js +8 -6
  59. package/dist/daemon/workflow-environment.js +5 -5
  60. package/dist/daemon/workflow-execution-launch.js +5 -5
  61. package/dist/daemon/workflow-execution-resources.js +4 -4
  62. package/dist/daemon/workflow-execution-routes.js +3 -3
  63. package/dist/daemon/workflow-execution-values.js +5 -5
  64. package/dist/daemon/workflow-executions.js +19 -19
  65. package/dist/daemon/workflow-mcp-authoring-routes.js +2 -2
  66. package/dist/daemon/workflow-mcp-authoring.js +4 -4
  67. package/dist/daemon/workflow-mcp.js +1 -1
  68. package/dist/daemon/workflow-routes.js +22 -3
  69. package/dist/daemon/workflow-schedule-driver.js +8 -8
  70. package/dist/daemon/workflow-schedule-routes.js +5 -5
  71. package/dist/daemon/workflow-schedules.js +9 -8
  72. package/dist/isolation/toolchain-assets.js +1 -1
  73. package/dist/protocol/spend.js +2 -0
  74. package/dist/protocol/stack.js +1 -41
  75. package/dist/workflows/calls.js +2 -2
  76. package/dist/workflows/executors.js +3 -3
  77. package/dist/workflows/graph.js +6 -6
  78. package/dist/workflows/invocations.js +1 -1
  79. package/dist/workflows/mcp.js +1 -1
  80. package/dist/workflows/records.js +6 -6
  81. package/dist/workflows/recovery.js +2 -2
  82. package/dist/workflows/runtime-settings.js +1 -1
  83. package/dist/workflows/runtime.js +2 -2
  84. package/dist/workflows/schedule-store.js +2 -2
  85. package/dist/workflows/scheduler.js +35 -23
  86. package/dist/workflows/schema.js +1 -1
  87. package/dist/workflows/store.js +19 -5
  88. package/package.json +3 -2
  89. package/web/dist/assets/index-BhfJhrVJ.js +51 -0
  90. package/web/dist/assets/index-BvkM2cWL.css +2 -0
  91. package/web/dist/assets/{settings-mcp-bcNKV147.js → settings-mcp-3cgqQB28.js} +1 -1
  92. package/web/dist/assets/settings-workflows-Cutm8isB.js +23 -0
  93. package/web/dist/assets/{switch-DIogWclb.js → switch-B00FEUA7.js} +1 -1
  94. package/web/dist/assets/{workflows-DHG-CIo3.js → workflows-D6oEUUhj.js} +31 -31
  95. package/web/dist/assets/{workflows-pane-9u_hJvgQ.js → workflows-pane-KIdSDKJB.js} +1 -1
  96. package/web/dist/index.html +4 -4
  97. package/dist/daemon/publish.js +0 -289
  98. package/web/dist/assets/index-BWKZK5HD.css +0 -2
  99. package/web/dist/assets/index-nIc09tKZ.js +0 -40
  100. package/web/dist/assets/settings-workflows-C_TKOhVa.js +0 -23
  101. /package/dist/protocol/{publish.js → plan-limits.js} +0 -0
@@ -1,5 +1,5 @@
1
1
  import { z } from 'zod';
2
- import { compileJsonSchema, validateJsonSchema } from "./json-schema.js";
2
+ import { compileJsonSchema, validateJsonSchema } from './json-schema.js';
3
3
  /** Keep tool and schema context at discovery, save and execution boundaries. */
4
4
  export function validateMcpSchemas(tool) {
5
5
  for (const field of ['inputSchema', 'outputSchema']) {
@@ -1,11 +1,11 @@
1
- import { boundedMcpValue, validateMcpOutput } from "./mcp.js";
1
+ import { boundedMcpValue, validateMcpOutput } from './mcp.js';
2
2
  import { z } from 'zod';
3
3
  import { isDeepStrictEqual } from 'node:util';
4
- import { resolveWorkflowCalls } from "./calls.js";
5
- import { dictionaryRecord } from "./schema.js";
6
- import { validateDefinition, workflowDefinitionValidator } from "./graph.js";
7
- import { validateCompatibleDefinition } from "./recovery.js";
8
- import { executionIdentity, executionOwnerKey, executionOwnerOf } from "./owner.js";
4
+ import { resolveWorkflowCalls } from './calls.js';
5
+ import { dictionaryRecord } from './schema.js';
6
+ import { validateDefinition, workflowDefinitionValidator } from './graph.js';
7
+ import { validateCompatibleDefinition } from './recovery.js';
8
+ import { executionIdentity, executionOwnerKey, executionOwnerOf } from './owner.js';
9
9
  const errorValidator = z.object({ message: z.string(), kind: z.enum(['failure', 'timeout', 'interrupted']) }).strict();
10
10
  const identityValidator = z.object({ headerId: z.string().min(1), activation: z.number().int().positive(), try: z.number().int().positive() }).strict();
11
11
  const loopValidator = z.object({
@@ -1,7 +1,7 @@
1
1
  import { createHash } from 'node:crypto';
2
2
  import { isDeepStrictEqual } from 'node:util';
3
- import { validateDefinition } from "./graph.js";
4
- import { invocationExecution } from "./invocations.js";
3
+ import { validateDefinition } from './graph.js';
4
+ import { invocationExecution } from './invocations.js';
5
5
  // Object key order is not part of a saved definition's identity; array order is.
6
6
  function canonical(value) {
7
7
  if (Array.isArray(value))
@@ -1,6 +1,6 @@
1
1
  import { accessSync, constants, statSync } from 'node:fs';
2
2
  import { delimiter, isAbsolute, join } from 'node:path';
3
- import { DEFAULT_WORKFLOW_RUNTIME } from "../protocol/settings.js";
3
+ import { DEFAULT_WORKFLOW_RUNTIME } from '../protocol/settings.js';
4
4
  export function workflowRuntimeOptions(settings = DEFAULT_WORKFLOW_RUNTIME, path) {
5
5
  const discover = (name, search) => {
6
6
  for (const directory of search.split(delimiter)) {
@@ -2,9 +2,9 @@ import { spawn } from 'node:child_process';
2
2
  import { constants, mkdirSync, openSync, closeSync, readFileSync, fstatSync, writeFileSync, realpathSync } from 'node:fs';
3
3
  import { resolve, relative, isAbsolute } from 'node:path';
4
4
  import { createInterface } from 'node:readline';
5
- import ts from 'typescript';
5
+ import ts from 'typescript-api';
6
6
  import { getQuickJS } from 'quickjs-emscripten';
7
- import { libraries } from "./runtime-libs.js";
7
+ import { libraries } from './runtime-libs.js';
8
8
  const LIMIT = 100_000;
9
9
  const controller = new AbortController();
10
10
  let stop = () => { controller.abort(); };
@@ -3,8 +3,8 @@ import { z } from 'zod';
3
3
  import { randomUUID } from 'node:crypto';
4
4
  import { closeSync, existsSync, fsyncSync, mkdirSync, openSync, readFileSync, readdirSync, renameSync, rmSync, writeFileSync } from 'node:fs';
5
5
  import { dirname, join } from 'node:path';
6
- import { ScheduleValidationError } from "./schedule-errors.js";
7
- import { isActiveOccurrence, occurrenceValidator, scheduleValidator, SCHEDULE_RETENTION_MS, storageId, timestamp } from "./schedules.js";
6
+ import { ScheduleValidationError } from './schedule-errors.js';
7
+ import { isActiveOccurrence, occurrenceValidator, scheduleValidator, SCHEDULE_RETENTION_MS, storageId, timestamp } from './schedules.js';
8
8
  function sync(directory) {
9
9
  const fd = openSync(directory, 'r');
10
10
  try {
@@ -1,14 +1,14 @@
1
- import { executionOwner } from "./records.js";
2
- import { executionAccessibleBy, executionAssociation, executionIdentity, executionOwnerKey, executionOwnerOf } from "./owner.js";
1
+ import { executionOwner } from './records.js';
2
+ import { executionAccessibleBy, executionAssociation, executionIdentity, executionOwnerKey, executionOwnerOf } from './owner.js';
3
3
  import { randomUUID } from 'node:crypto';
4
4
  import { isDeepStrictEqual } from 'node:util';
5
- import { resolveMapping, validateDefinition } from "./graph.js";
6
- import { declaredOutputSchema, parseValue, valueAt } from "./schema.js";
7
- import { validateMcpOutput } from "./mcp.js";
8
- import { WorkflowStore } from "./store.js";
9
- import { recoverySteps, savedDefinitionRevision, validateCompatibleDefinition } from "./recovery.js";
10
- import { resolveWorkflowCalls } from "./calls.js";
11
- import { invocationCheckpoint, invocationExecution } from "./invocations.js";
5
+ import { resolveMapping, validateDefinition } from './graph.js';
6
+ import { declaredOutputSchema, parseValue, valueAt } from './schema.js';
7
+ import { validateMcpOutput } from './mcp.js';
8
+ import { WorkflowStore } from './store.js';
9
+ import { recoverySteps, savedDefinitionRevision, validateCompatibleDefinition } from './recovery.js';
10
+ import { resolveWorkflowCalls } from './calls.js';
11
+ import { invocationCheckpoint, invocationExecution } from './invocations.js';
12
12
  export class WorkflowStepError extends Error {
13
13
  partialOutput;
14
14
  constructor(message, partialOutput) { super(message); this.partialOutput = partialOutput; }
@@ -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);
@@ -1,4 +1,4 @@
1
- import { compileJsonSchema, validateJsonSchema, jsonSchemaAt } from "./json-schema.js";
1
+ import { compileJsonSchema, validateJsonSchema, jsonSchemaAt } from './json-schema.js';
2
2
  import { z } from 'zod';
3
3
  export const dictionaryKey = z.string().refine(key => !['__proto__', 'constructor', 'prototype'].includes(key), 'Reserved dictionary key');
4
4
  export function dictionaryRecord(value) {
@@ -1,9 +1,9 @@
1
1
  import { randomUUID } from 'node:crypto';
2
2
  import { closeSync, existsSync, fsyncSync, mkdirSync, openSync, readFileSync, readdirSync, renameSync, rmSync, writeFileSync } from 'node:fs';
3
3
  import { dirname, join } from 'node:path';
4
- import { validateDefinition } from "./graph.js";
5
- import { parseExecution } from "./records.js";
6
- import { executionAccessibleBy, executionAssociation, executionIdentity, executionOwnerKey, executionOwnerOf, executionOwnerPath, parseExecutionOwnerKey } from "./owner.js";
4
+ import { validateDefinition } from './graph.js';
5
+ import { parseExecution } from './records.js';
6
+ import { executionAccessibleBy, executionAssociation, executionIdentity, executionOwnerKey, executionOwnerOf, executionOwnerPath, parseExecutionOwnerKey } from './owner.js';
7
7
  function segment(value) {
8
8
  if (!/^[a-zA-Z0-9_-]+$/.test(value))
9
9
  throw new Error('Invalid storage ID');
@@ -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.4",
3
+ "version": "0.1.10-beta.6",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -54,7 +54,7 @@
54
54
  "proper-lockfile": "4.1.2",
55
55
  "quickjs-emscripten": "^0.32.0",
56
56
  "typebox": "^1.3.7",
57
- "typescript": "^5.9.3",
57
+ "typescript-api": "npm:typescript@^5.9.3",
58
58
  "ws": "^8.21.3",
59
59
  "zod": "^4.6.5"
60
60
  },
@@ -89,6 +89,7 @@
89
89
  "tailwind-merge": "^3.6.0",
90
90
  "tailwindcss": "^4.3.3",
91
91
  "tw-animate-css": "^1.4.0",
92
+ "typescript": "^7.0.2",
92
93
  "vite": "^8.2.2"
93
94
  }
94
95
  }