@nathanstephenson/flow 0.1.10-beta.1 → 0.1.10-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +52 -22
- package/build/backend-worker-chunks/{chunk-CYE5L6Z5.mjs → chunk-3KDHJA5P.mjs} +41 -10
- package/build/backend-worker-chunks/{chunk-UQDH2COY.mjs → chunk-K774KOGL.mjs} +2 -7
- package/build/backend-worker-chunks/chunk-LAEUXDNH.mjs +130 -0
- package/build/backend-worker-chunks/{chunk-MLOUI3ZM.mjs → chunk-NZZME2I3.mjs} +6 -1
- package/build/backend-worker-chunks/claude-JG2FXYBQ.mjs +35859 -0
- package/build/backend-worker-chunks/{pi-UKRC4DDM.mjs → pi-KJSP23AO.mjs} +2091 -92
- package/build/backend-worker.mjs +69 -122
- package/build/workflow-runtime.cjs +12 -12
- package/dist/backend/claude/background-calls.js +7 -3
- package/dist/backend/claude/import.js +415 -0
- package/dist/backend/claude/index.js +188 -25
- package/dist/backend/claude/subagents.js +41 -9
- package/dist/backend/claude/todo-list.js +114 -0
- package/dist/backend/claude/workflow-parent.js +1 -1
- package/dist/backend/diff-excerpt-instructions.js +8 -0
- package/dist/backend/fake/index.js +54 -6
- package/dist/backend/mcp.js +4 -1
- package/dist/backend/pi/agent-permissions.js +1 -1
- package/dist/backend/pi/cache-warming.js +8 -0
- package/dist/backend/pi/canonical-json.js +120 -0
- package/dist/backend/pi/compaction-model.js +3 -2
- package/dist/backend/pi/host-auth.js +258 -0
- package/dist/backend/pi/import.js +269 -0
- package/dist/backend/pi/index.js +118 -20
- package/dist/backend/pi/model-auth.js +159 -0
- package/dist/backend/pi/model-catalog.js +120 -0
- package/dist/backend/pi/model-config.js +5 -0
- package/dist/backend/pi/model-selection.js +32 -0
- package/dist/backend/pi/plan-limits.js +41 -0
- package/dist/backend/pi/state.js +19 -1
- package/dist/backend/pi/subagents.js +7 -3
- package/dist/backend/pi/todo-list.js +23 -0
- package/dist/backend/pi/work.js +9 -1
- package/dist/backend/pi/workflow-parent.js +1 -1
- package/dist/backend/pi/workflow-subagent.js +4 -3
- package/dist/backend/plan-limits.js +17 -0
- package/dist/backend/session-tools.js +1 -1
- package/dist/backend/worker/claude-state.js +48 -0
- package/dist/backend/worker/entry.js +42 -8
- package/dist/backend/worker/index.js +131 -15
- package/dist/backend/worker/launcher.js +11 -4
- package/dist/backend/worker/protocol.js +2 -1
- package/dist/backend/worker/rpc.js +13 -0
- package/dist/backend/worker/sandbox-mcp.js +18 -7
- package/dist/backend/workflow-tools.js +9 -7
- package/dist/build-id +1 -1
- package/dist/cli/application.js +48 -42
- package/dist/cli/bootstrap.js +2 -2
- package/dist/cli/host-control.js +1 -1
- package/dist/cli/install-guard.js +2 -2
- package/dist/cli/main.js +4 -4
- package/dist/cli/systemd-update.js +3 -3
- package/dist/cli/update.js +6 -6
- package/dist/cli/web-update.js +6 -6
- package/dist/client/connection.js +46 -0
- package/dist/client/context-usage.js +3 -4
- package/dist/client/diff.js +40 -0
- package/dist/client/enquiry.js +0 -6
- package/dist/client/markdown.js +3 -2
- package/dist/client/model-choices.js +1 -1
- package/dist/client/permission.js +1 -2
- package/dist/client/project-name.js +3 -1
- package/dist/client/reduce.js +77 -3
- package/dist/client/relative-time.js +1 -1
- package/dist/client/scope-kind.js +6 -3
- package/dist/client/search.js +1 -1
- package/dist/client/status.js +1 -1
- package/dist/client/subagent-tree.js +49 -0
- package/dist/client/tool-chains.js +1 -1
- package/dist/client/tool-summary.js +28 -18
- package/dist/daemon/changes.js +128 -0
- package/dist/daemon/commit.js +84 -0
- package/dist/daemon/config-store.js +8 -3
- package/dist/daemon/config.js +105 -4
- package/dist/daemon/diff-excerpts.js +52 -0
- package/dist/daemon/git-state.js +197 -0
- package/dist/daemon/git.js +53 -10
- package/dist/daemon/github-image.js +18 -0
- package/dist/daemon/github.js +54 -0
- package/dist/daemon/host-control-routes.js +1 -1
- package/dist/daemon/host.js +940 -119
- package/dist/daemon/http.js +4 -1
- package/dist/daemon/log.js +3 -0
- package/dist/daemon/mcp-auth.js +1 -1
- package/dist/daemon/models.js +2 -2
- package/dist/daemon/pi-model-cache.js +44 -0
- package/dist/daemon/pull-request.js +223 -138
- package/dist/daemon/push.js +43 -0
- package/dist/daemon/repository.js +123 -0
- package/dist/daemon/runtime.js +103 -22
- package/dist/daemon/secret-store.js +1 -1
- package/dist/daemon/server.js +111 -14
- package/dist/daemon/skills.js +24 -0
- package/dist/daemon/spend-ledger.js +118 -0
- package/dist/daemon/stack-metadata.js +12 -5
- package/dist/daemon/stack.js +162 -657
- package/dist/daemon/store.js +2 -0
- package/dist/daemon/summariser.js +30 -12
- package/dist/daemon/tour.js +56 -0
- package/dist/daemon/whisper.js +144 -0
- package/dist/daemon/workflow-authoring-scope-checks.js +1 -1
- package/dist/daemon/workflow-authoring-scope.js +1 -1
- package/dist/daemon/workflow-builder-files.js +2 -2
- package/dist/daemon/workflow-builder-guidance.js +1 -1
- package/dist/daemon/workflow-builder-routes.js +2 -2
- package/dist/daemon/workflow-builder.js +44 -17
- package/dist/daemon/workflow-environment.js +193 -0
- package/dist/daemon/workflow-execution-launch.js +77 -0
- package/dist/daemon/workflow-execution-resources.js +76 -0
- package/dist/daemon/workflow-execution-routes.js +12 -9
- package/dist/daemon/workflow-execution-values.js +128 -0
- package/dist/daemon/workflow-executions.js +400 -311
- package/dist/daemon/workflow-mcp-authoring-routes.js +2 -2
- package/dist/daemon/workflow-mcp-authoring.js +4 -4
- package/dist/daemon/workflow-mcp.js +1 -1
- package/dist/daemon/workflow-routes.js +60 -2
- package/dist/daemon/workflow-schedule-driver.js +251 -0
- package/dist/daemon/workflow-schedule-routes.js +137 -0
- package/dist/daemon/workflow-schedules.js +342 -0
- package/dist/isolation/filesystem.js +6 -2
- package/dist/isolation/sandbox.js +61 -18
- package/dist/isolation/shared-sandbox.js +3 -3
- package/dist/isolation/toolchain-assets.js +1 -1
- package/dist/protocol/events.js +3 -0
- package/dist/protocol/plan-limits.js +1 -0
- package/dist/protocol/settings.js +1 -0
- package/dist/protocol/spend.js +2 -0
- package/dist/protocol/stack.js +12 -39
- package/dist/protocol/workflow-schedules.js +1 -0
- package/dist/workflows/calls.js +53 -0
- package/dist/workflows/errors.js +2 -0
- package/dist/workflows/executors.js +6 -5
- package/dist/workflows/graph.js +83 -9
- package/dist/workflows/invocations.js +23 -0
- package/dist/workflows/mcp.js +1 -1
- package/dist/workflows/owner.js +45 -0
- package/dist/workflows/records.js +127 -11
- package/dist/workflows/recovery.js +38 -2
- package/dist/workflows/runtime-settings.js +16 -16
- package/dist/workflows/runtime.js +2 -2
- package/dist/workflows/schedule-errors.js +2 -0
- package/dist/workflows/schedule-store.js +385 -0
- package/dist/workflows/scheduler.js +367 -96
- package/dist/workflows/schedules.js +130 -0
- package/dist/workflows/schema.js +3 -1
- package/dist/workflows/store.js +126 -13
- package/package.json +10 -6
- package/web/dist/assets/index-C76t-z4w.css +2 -0
- package/web/dist/assets/{index-DRfeO6GJ.js → index-WPfbYVQ4.js} +39 -23
- package/web/dist/assets/{switch-DIogWclb.js → select-C5Ly2OpB.js} +1 -1
- package/web/dist/assets/{settings-mcp-Clp_jMWW.js → settings-mcp-BF-yqpeQ.js} +1 -1
- package/web/dist/assets/{settings-secrets-BIO_hXZ1.js → settings-secrets-WLarr2QP.js} +1 -1
- package/web/dist/assets/settings-workflows-DdcdRWFD.js +23 -0
- package/web/dist/assets/workflow-api-GjAmHc22.js +6 -0
- package/web/dist/assets/workflows-BhY3Uibo.js +149 -0
- package/web/dist/assets/workflows-pane-DElCcEpN.js +1 -0
- package/web/dist/index.html +6 -5
- package/build/backend-worker-chunks/claude-UXZDJKZQ.mjs +0 -30816
- package/dist/daemon/publish.js +0 -289
- package/dist/tui/app.js +0 -612
- package/dist/tui/keys.js +0 -90
- package/dist/tui/render.js +0 -411
- package/web/dist/assets/index-DgQFpKbn.css +0 -2
- package/web/dist/assets/settings-workflows-H-6eCff3.js +0 -23
- package/web/dist/assets/workflow-api-BfExddae.js +0 -6
- package/web/dist/assets/workflow-editors-CsbVx4WJ.js +0 -139
- package/web/dist/assets/workflows-Bv0sj7d0.js +0 -7
- package/web/dist/assets/workflows-pane-DHm44w7P.js +0 -1
- /package/dist/protocol/{publish.js → imports.js} +0 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
2
|
import { existsSync, mkdtempSync, realpathSync, rmSync, statSync } from 'node:fs';
|
|
3
3
|
import { isAbsolute, join, resolve } from 'node:path';
|
|
4
|
-
import { parseValue, toTypeScript } from
|
|
5
|
-
import { prepareFilesystemIsolation, validateFilesystemScope } from
|
|
6
|
-
import { sandboxUnavailable } from
|
|
4
|
+
import { parseValue, toTypeScript } from './schema.js';
|
|
5
|
+
import { prepareFilesystemIsolation, validateFilesystemScope } from '../isolation/filesystem.js';
|
|
6
|
+
import { sandboxUnavailable } from '../isolation/sandbox.js';
|
|
7
7
|
const environment = { PATH: '/usr/local/bin:/usr/bin:/bin', LANG: 'C.UTF-8' };
|
|
8
8
|
function probe(command, args, stdioFds = [], env = environment) {
|
|
9
9
|
if (!isAbsolute(command))
|
|
@@ -99,7 +99,7 @@ export async function createCodeExecutors(options) {
|
|
|
99
99
|
const stateRoot = options.stateRoot ? { stateRoot: options.stateRoot } : {};
|
|
100
100
|
const scope = canonicalScope(context.scope);
|
|
101
101
|
const runtimePath = realpathSync(options.runtimePath);
|
|
102
|
-
const sandbox = isolationMode === 'sandbox' ? await options.sandbox(context.sessionId) : undefined;
|
|
102
|
+
const sandbox = isolationMode === 'sandbox' ? await options.sandbox(context.ownerId ?? context.sessionId) : undefined;
|
|
103
103
|
const nodePath = sandbox ? sandbox.nodePath : realpathSync(options.nodePath);
|
|
104
104
|
const args = ['--noprofile', '--norc', '-c', 'ulimit -c 0; exec "$@"', 'flow-workflow', nodePath, '--max-old-space-size=128', runtimePath];
|
|
105
105
|
const timeout = Math.min(context.step.timeoutMs ?? 60_000, 2_147_000_000);
|
|
@@ -113,7 +113,8 @@ export async function createCodeExecutors(options) {
|
|
|
113
113
|
CLAUDE_CONFIG_DIR: process.env.CLAUDE_CONFIG_DIR };
|
|
114
114
|
const launch = sandbox?.command(scope, ['/bin/bash', ...args], environment);
|
|
115
115
|
const isolation = isolationEnabled && !sandbox ? await prepareFilesystemIsolation({ scope, expectedScope: resolve(context.scope),
|
|
116
|
-
...stateRoot, command: '/bin/bash', args, env, readablePaths: [nodePath, runtimePath], credentials: 'none'
|
|
116
|
+
...stateRoot, command: '/bin/bash', args, env, readablePaths: [nodePath, runtimePath], credentials: 'none',
|
|
117
|
+
scopeReadOnly: context.sessionId !== undefined && !!options.readOnly?.(context.sessionId) }) : undefined;
|
|
117
118
|
const release = sandbox?.hold();
|
|
118
119
|
try {
|
|
119
120
|
context.signal.throwIfAborted();
|
package/dist/workflows/graph.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { validateMcpSchemas } from
|
|
2
|
-
import { leadingSkillInvocation } from
|
|
1
|
+
import { validateMcpSchemas } from './mcp.js';
|
|
2
|
+
import { leadingSkillInvocation } from '../protocol/skills.js';
|
|
3
3
|
import { z } from 'zod';
|
|
4
|
-
import { validSecretName } from
|
|
5
|
-
import { Decisions } from
|
|
6
|
-
import { analyzeLoops } from
|
|
7
|
-
import { dictionaryKey, dictionaryRecord, declaredOutputSchema, partialSchema, schemaAssignable, schemaAt, unionSchema, validateSchema, valueAt, visualSchemaValidator } from
|
|
4
|
+
import { validSecretName } from '../protocol/secrets.js';
|
|
5
|
+
import { Decisions } from './decisions.js';
|
|
6
|
+
import { analyzeLoops } from './loops.js';
|
|
7
|
+
import { dictionaryKey, dictionaryRecord, declaredOutputSchema, parseValue, partialSchema, schemaAssignable, schemaAt, unionSchema, validateSchema, valueAt, visualSchemaValidator } from './schema.js';
|
|
8
8
|
const reference = z.discriminatedUnion('source', [
|
|
9
9
|
z.object({ source: z.literal('input'), path: z.array(z.string()) }).strict(),
|
|
10
10
|
z.object({ source: z.literal('step'), stepId: z.string(), path: z.array(z.string()) }).strict(),
|
|
@@ -37,12 +37,19 @@ export const workflowDefinitionValidator = z.object({
|
|
|
37
37
|
z.object({ ...base, kind: z.literal('typescript'), code: z.string(), outputSchema: visualSchemaValidator }).strict(),
|
|
38
38
|
z.object({ ...base, kind: z.literal('branch'), condition }).strict(),
|
|
39
39
|
z.object({ ...base, kind: z.literal('join') }).strict(),
|
|
40
|
+
z.object({ ...base, kind: z.literal('workflow'), workflowId: z.string().regex(/^[a-zA-Z0-9_-]{1,128}$/), contract: z.object({ inputSchema: visualSchemaValidator.refine(schema => schema.type === 'object'), outputSchema: visualSchemaValidator }).strict() }).strict(),
|
|
40
41
|
z.object({ ...base, kind: z.literal('mcp'), tool: z.object({ connectionId: z.string().min(1), connectionName: z.string(), identity: z.string().regex(/^[a-f0-9]{64}$/), serverIdentity: z.string().regex(/^[a-f0-9]{64}$/), toolName: z.string().min(1), inputSchema: originalSchema, outputSchema: originalSchema.optional() }).strict() }).strict(),
|
|
41
42
|
])).min(1),
|
|
42
43
|
loopSettings: dictionaryRecord(z.object({ maxTries: z.number().int().min(1).max(100) }).strict()).optional(),
|
|
43
44
|
edges: z.array(z.object({ id: z.string().min(1), from: z.string(), to: z.string(), outcome: z.enum(['success', 'failure', 'timeout', 'true', 'false']) }).strict()),
|
|
44
45
|
}).strict();
|
|
45
46
|
export function validateDefinition(value) {
|
|
47
|
+
return buildGraph(value);
|
|
48
|
+
}
|
|
49
|
+
export function mappingSourceGraph(value) {
|
|
50
|
+
return buildGraph(value, true);
|
|
51
|
+
}
|
|
52
|
+
function buildGraph(value, mappingSources = false) {
|
|
46
53
|
const definition = workflowDefinitionValidator.parse(value);
|
|
47
54
|
const skillStep = definition.steps.find(step => step.kind === 'agent' && leadingSkillInvocation(step.instructions));
|
|
48
55
|
if (skillStep && !definition.projectId) {
|
|
@@ -167,7 +174,31 @@ export function validateDefinition(value) {
|
|
|
167
174
|
node.items.forEach(inspect);
|
|
168
175
|
};
|
|
169
176
|
inspect(mapping.template);
|
|
170
|
-
|
|
177
|
+
const infer = (node) => {
|
|
178
|
+
if (node.kind === 'reference')
|
|
179
|
+
return referenceSchema(node.reference).schema;
|
|
180
|
+
if (node.kind === 'object')
|
|
181
|
+
return { type: 'object', fields: Object.fromEntries(Object.entries(node.fields).map(([key, value]) => [key, { schema: infer(value), required: true }])) };
|
|
182
|
+
if (node.kind === 'array')
|
|
183
|
+
return { type: 'array', items: node.items.length ? unionSchema(node.items.map(infer)) : { type: 'json' } };
|
|
184
|
+
const literal = (value) => {
|
|
185
|
+
if (value === null)
|
|
186
|
+
return { type: 'null' };
|
|
187
|
+
if (typeof value === 'string')
|
|
188
|
+
return { type: 'enum', values: [value] };
|
|
189
|
+
if (typeof value === 'number')
|
|
190
|
+
return { type: 'number', integer: Number.isInteger(value) };
|
|
191
|
+
if (typeof value === 'boolean')
|
|
192
|
+
return { type: 'boolean' };
|
|
193
|
+
if (Array.isArray(value))
|
|
194
|
+
return { type: 'array', items: value.length ? unionSchema(value.map(literal)) : { type: 'json' } };
|
|
195
|
+
return { type: 'object', fields: Object.fromEntries(Object.entries(value).map(([key, value]) => [key, { schema: literal(value), required: true }])) };
|
|
196
|
+
};
|
|
197
|
+
return literal(node.value);
|
|
198
|
+
};
|
|
199
|
+
input = step.kind === 'workflow' ? infer(mapping.template) : { type: 'json' };
|
|
200
|
+
if (step.kind === 'workflow' && !mappingSources && mapping.template.kind === 'literal')
|
|
201
|
+
parseValue(step.contract.inputSchema, mapping.template.value);
|
|
171
202
|
}
|
|
172
203
|
else if (mapping?.kind === 'reference') {
|
|
173
204
|
const field = referenceSchema(mapping.reference);
|
|
@@ -198,9 +229,16 @@ export function validateDefinition(value) {
|
|
|
198
229
|
}
|
|
199
230
|
if (step.inputSchema) {
|
|
200
231
|
validateSchema(step.inputSchema);
|
|
201
|
-
if (!schemaAssignable(input, step.inputSchema))
|
|
232
|
+
if (!(mappingSources && step.kind === 'workflow') && !schemaAssignable(input, step.inputSchema))
|
|
202
233
|
throw new Error('Input does not match the declared input schema');
|
|
203
234
|
}
|
|
235
|
+
if (step.kind === 'workflow') {
|
|
236
|
+
validateSchema(step.contract.inputSchema);
|
|
237
|
+
validateSchema(step.contract.outputSchema);
|
|
238
|
+
if (!mappingSources && (!schemaAssignable(input, step.contract.inputSchema) || (step.inputSchema && !schemaAssignable(step.inputSchema, step.contract.inputSchema))))
|
|
239
|
+
throw new Error('Input does not match the Workflow call input contract');
|
|
240
|
+
return step.contract.inputSchema;
|
|
241
|
+
}
|
|
204
242
|
return step.inputSchema ?? input;
|
|
205
243
|
};
|
|
206
244
|
const inputFor = (id) => {
|
|
@@ -235,7 +273,43 @@ export function validateDefinition(value) {
|
|
|
235
273
|
}
|
|
236
274
|
outputFor(step.id);
|
|
237
275
|
}
|
|
238
|
-
|
|
276
|
+
const terminalConditions = order.map(step => decisions.and(completed.get(step.id), decisions.not(any(outgoing.get(step.id).map(edge => selectedEdges.get(edge.id))))));
|
|
277
|
+
let finished = 1;
|
|
278
|
+
for (const step of order) {
|
|
279
|
+
const handled = any(outgoing.get(step.id).filter(edge => edge.outcome === 'failure' || edge.outcome === 'timeout').map(edge => selectedEdges.get(edge.id)));
|
|
280
|
+
finished = decisions.and(finished, decisions.or(decisions.not(reaches.get(step.id)), decisions.or(completed.get(step.id), handled)));
|
|
281
|
+
if (loops.length)
|
|
282
|
+
finished = decisions.and(finished, decisions.not(any(outgoing.get(step.id).filter(edge => backIds.has(edge.id)).map(edge => selectedEdges.get(edge.id)))));
|
|
283
|
+
}
|
|
284
|
+
const candidates = order.map((step, index) => ({ step, condition: terminalConditions[index] })).filter(({ condition }) => decisions.and(finished, condition) !== 0);
|
|
285
|
+
const variants = [];
|
|
286
|
+
let none = 1;
|
|
287
|
+
let one = 0;
|
|
288
|
+
let many = 0;
|
|
289
|
+
for (const { condition } of candidates) {
|
|
290
|
+
many = decisions.or(many, decisions.and(one, condition));
|
|
291
|
+
one = decisions.or(decisions.and(one, decisions.not(condition)), decisions.and(none, condition));
|
|
292
|
+
none = decisions.and(none, decisions.not(condition));
|
|
293
|
+
}
|
|
294
|
+
if (loops.length || definition.edges.some(edge => edge.outcome === 'failure' || edge.outcome === 'timeout')) {
|
|
295
|
+
const possible = order.filter(step => step.kind === 'branch'
|
|
296
|
+
? ['true', 'false'].some(outcome => !outgoing.get(step.id).some(edge => edge.outcome === outcome))
|
|
297
|
+
: !outgoing.get(step.id).some(edge => edge.outcome === 'success'));
|
|
298
|
+
variants.push(...possible.map(step => outputFor(step.id)));
|
|
299
|
+
if (possible.length > 1)
|
|
300
|
+
variants.push({ type: 'object', fields: Object.fromEntries(possible.map(step => [step.name, { schema: outputFor(step.id) }])) });
|
|
301
|
+
}
|
|
302
|
+
else {
|
|
303
|
+
for (const { step, condition } of candidates)
|
|
304
|
+
if (decisions.and(finished, decisions.and(one, condition)) !== 0)
|
|
305
|
+
variants.push(outputFor(step.id));
|
|
306
|
+
const multiple = decisions.and(finished, many);
|
|
307
|
+
if (multiple !== 0)
|
|
308
|
+
variants.push({ type: 'object', fields: Object.fromEntries(candidates.filter(({ condition }) => decisions.and(multiple, condition) !== 0).map(({ step, condition }) => [step.name, { schema: outputFor(step.id), required: decisions.implies(multiple, condition) }])) });
|
|
309
|
+
if (decisions.and(finished, none) !== 0)
|
|
310
|
+
variants.push({ type: 'object', fields: {} });
|
|
311
|
+
}
|
|
312
|
+
return { ...graph, resultSchema: variants.length ? unionSchema(variants) : { type: 'json' } };
|
|
239
313
|
}
|
|
240
314
|
export function recoverySchema(input, output) {
|
|
241
315
|
return { type: 'object', fields: {
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { executionIdentity } from './owner.js';
|
|
2
|
+
export class WorkflowInvocationNotFound extends Error {
|
|
3
|
+
}
|
|
4
|
+
export function invocationExecution(root, invocationId) {
|
|
5
|
+
if (!root.invocations || !Object.hasOwn(root.invocations, invocationId))
|
|
6
|
+
throw new WorkflowInvocationNotFound('Unknown workflow invocation');
|
|
7
|
+
const invocation = root.invocations[invocationId];
|
|
8
|
+
const retained = root.retainedDefinitions?.[invocation.definitionId];
|
|
9
|
+
if (!retained)
|
|
10
|
+
throw new Error('Missing retained Workflow Definition');
|
|
11
|
+
const definition = structuredClone(retained);
|
|
12
|
+
for (const correction of invocation.definitionUpdates ?? []) {
|
|
13
|
+
const index = definition.steps.findIndex(step => step.id === correction.stepId);
|
|
14
|
+
if (index < 0)
|
|
15
|
+
throw new Error('Invalid invocation correction');
|
|
16
|
+
definition.steps[index] = structuredClone(correction.nextStep);
|
|
17
|
+
}
|
|
18
|
+
return { ...structuredClone(invocation), ...executionIdentity(root), scope: root.scope, definition };
|
|
19
|
+
}
|
|
20
|
+
export function invocationCheckpoint(record, ownership) {
|
|
21
|
+
const { version: _, occurrenceId: _occurrence, runtime: _runtime, sessionId: __, scope: ___, definition: ____, ...state } = record;
|
|
22
|
+
return { ...state, ...ownership };
|
|
23
|
+
}
|
package/dist/workflows/mcp.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { compileJsonSchema, validateJsonSchema } from
|
|
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']) {
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
function storageId(value) {
|
|
3
|
+
if (!/^[a-zA-Z0-9_-]+$/.test(value))
|
|
4
|
+
throw new Error('Invalid storage ID');
|
|
5
|
+
return value;
|
|
6
|
+
}
|
|
7
|
+
export function executionOwnerOf(value) {
|
|
8
|
+
if (value.version === 1 && (value.occurrenceId !== undefined || !value.sessionId))
|
|
9
|
+
throw new Error('Invalid execution owner');
|
|
10
|
+
if (value.version === 2 && !value.occurrenceId)
|
|
11
|
+
throw new Error('Invalid execution owner');
|
|
12
|
+
if (value.occurrenceId !== undefined)
|
|
13
|
+
return { kind: 'occurrence', occurrenceId: storageId(value.occurrenceId) };
|
|
14
|
+
if (value.sessionId)
|
|
15
|
+
return { kind: 'session', sessionId: storageId(value.sessionId) };
|
|
16
|
+
throw new Error('Missing execution owner');
|
|
17
|
+
}
|
|
18
|
+
export function executionOwnerKey(owner) {
|
|
19
|
+
return owner.kind === 'occurrence' ? `occurrence-${storageId(owner.occurrenceId)}` : storageId(owner.sessionId);
|
|
20
|
+
}
|
|
21
|
+
export function parseExecutionOwnerKey(key) {
|
|
22
|
+
storageId(key);
|
|
23
|
+
return key.startsWith('occurrence-') ? { kind: 'occurrence', occurrenceId: storageId(key.slice(11)) } : { kind: 'session', sessionId: key };
|
|
24
|
+
}
|
|
25
|
+
export function executionOwnerPath(stateRoot, owner) {
|
|
26
|
+
return owner.kind === 'occurrence'
|
|
27
|
+
? join(stateRoot, 'workflow-schedules', 'executions', storageId(owner.occurrenceId))
|
|
28
|
+
: join(stateRoot, 'sessions', storageId(owner.sessionId));
|
|
29
|
+
}
|
|
30
|
+
export function executionIdentity(value) {
|
|
31
|
+
const owner = executionOwnerOf(value);
|
|
32
|
+
return owner.kind === 'session'
|
|
33
|
+
? { version: 1, sessionId: owner.sessionId }
|
|
34
|
+
: { version: 2, occurrenceId: owner.occurrenceId, ...(value.sessionId === undefined ? {} : { sessionId: storageId(value.sessionId) }) };
|
|
35
|
+
}
|
|
36
|
+
export function executionAssociation(value) {
|
|
37
|
+
return executionOwnerOf(value).kind === 'occurrence' ? value.sessionId : undefined;
|
|
38
|
+
}
|
|
39
|
+
export function executionAccessibleBy(value, owner) {
|
|
40
|
+
const requested = typeof owner === 'string' ? parseExecutionOwnerKey(owner) : owner;
|
|
41
|
+
const actual = executionOwnerOf(value);
|
|
42
|
+
if (requested.kind === 'occurrence')
|
|
43
|
+
return actual.kind === 'occurrence' && actual.occurrenceId === requested.occurrenceId;
|
|
44
|
+
return actual.kind === 'session' ? actual.sessionId === requested.sessionId : executionAssociation(value) === requested.sessionId;
|
|
45
|
+
}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import { boundedMcpValue, validateMcpOutput } from
|
|
1
|
+
import { boundedMcpValue, validateMcpOutput } from './mcp.js';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { isDeepStrictEqual } from 'node:util';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
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';
|
|
6
9
|
const errorValidator = z.object({ message: z.string(), kind: z.enum(['failure', 'timeout', 'interrupted']) }).strict();
|
|
7
10
|
const identityValidator = z.object({ headerId: z.string().min(1), activation: z.number().int().positive(), try: z.number().int().positive() }).strict();
|
|
8
11
|
const loopValidator = z.object({
|
|
@@ -12,25 +15,33 @@ const loopValidator = z.object({
|
|
|
12
15
|
}).strict();
|
|
13
16
|
const attemptValidator = z.object({
|
|
14
17
|
loops: z.array(identityValidator).optional(),
|
|
15
|
-
number: z.number().int().positive(), action: z.enum(['execute', 'retry', 'supply']), startedAt: z.number().nonnegative(), finishedAt: z.number().nonnegative().optional(),
|
|
18
|
+
number: z.number().int().positive(), action: z.enum(['execute', 'retry', 'supply']), startedAt: z.number().nonnegative(), deadlineAt: z.number().nonnegative().optional(), finishedAt: z.number().nonnegative().optional(),
|
|
16
19
|
input: z.json(), output: z.json().optional(), partialOutput: z.json().optional(), error: errorValidator.optional(),
|
|
17
20
|
}).strict();
|
|
18
|
-
|
|
19
|
-
version: z.literal(1), id: z.string().min(1), sessionId: z.string().min(1), scope: z.string(), definition: workflowDefinitionValidator,
|
|
21
|
+
const checkpointFields = {
|
|
20
22
|
definitionUpdates: z.array(z.object({
|
|
21
23
|
stepId: z.string().min(1), previousStep: workflowDefinitionValidator.shape.steps.element, nextStep: workflowDefinitionValidator.shape.steps.element,
|
|
22
24
|
appliedAt: z.number().nonnegative(), attempt: z.number().int().min(2),
|
|
23
25
|
}).strict()).optional(),
|
|
24
|
-
input: z.json(),
|
|
26
|
+
input: z.json(), status: z.enum(['running', 'recovery-required', 'completed', 'completed-with-recovery', 'cancelled']),
|
|
25
27
|
startedAt: z.number().nonnegative(), finishedAt: z.number().nonnegative().optional(), result: z.json().optional(),
|
|
26
|
-
loops:
|
|
27
|
-
steps:
|
|
28
|
+
loops: dictionaryRecord(loopValidator).optional(),
|
|
29
|
+
steps: dictionaryRecord(z.object({
|
|
28
30
|
status: z.enum(['pending', 'running', 'completed', 'failed', 'timed-out', 'interrupted', 'skipped', 'blocked', 'cancelled']), recovery: z.boolean().optional(),
|
|
29
31
|
attempts: z.array(attemptValidator), output: z.json().optional(), outcome: z.enum(['success', 'failure', 'timeout', 'true', 'false']).optional(),
|
|
30
32
|
}).strict()),
|
|
33
|
+
};
|
|
34
|
+
const invocationValidator = z.object({
|
|
35
|
+
...checkpointFields, id: z.string().min(1), parentInvocationId: z.string().min(1).optional(),
|
|
36
|
+
callStepId: z.string().min(1), callAttempt: z.number().int().positive(), definitionId: z.string().min(1),
|
|
31
37
|
}).strict();
|
|
32
|
-
export
|
|
33
|
-
|
|
38
|
+
export const workflowExecutionValidator = z.object({
|
|
39
|
+
...checkpointFields, version: z.union([z.literal(1), z.literal(2)]), occurrenceId: z.string().regex(/^[a-zA-Z0-9_-]+$/).optional(), runtime: z.object({ nodePath: z.string().optional(), isolationMode: z.enum(['none', 'bubblewrap', 'sandbox']) }).strict().optional(), id: z.string().min(1), sessionId: z.string().min(1).optional(), scope: z.string(), definition: workflowDefinitionValidator,
|
|
40
|
+
retainedDefinitions: z.preprocess(value => value && typeof value === 'object' && !Array.isArray(value) ? new Map(Object.entries(value)) : value, z.map(workflowDefinitionValidator.shape.id, workflowDefinitionValidator)).transform(entries => Object.fromEntries(entries)).optional(),
|
|
41
|
+
invocations: dictionaryRecord(invocationValidator).optional(),
|
|
42
|
+
launchId: z.string().min(1).optional(), naming: z.enum(['pending', 'requested']).optional(), testStepId: z.string().optional(),
|
|
43
|
+
}).strict();
|
|
44
|
+
function validateCheckpoint(record) {
|
|
34
45
|
const graph = validateDefinition(record.definition);
|
|
35
46
|
if (graph.order.length !== Object.keys(record.steps).length || graph.order.some(step => !Object.hasOwn(record.steps, step.id)))
|
|
36
47
|
throw new Error('Execution steps do not match the definition');
|
|
@@ -53,6 +64,7 @@ export function parseExecution(value) {
|
|
|
53
64
|
validateCompatibleDefinition(previous, definition, update.stepId);
|
|
54
65
|
definition = previous;
|
|
55
66
|
}
|
|
67
|
+
const original = definition;
|
|
56
68
|
if (record.testStepId && !Object.hasOwn(record.steps, record.testStepId))
|
|
57
69
|
throw new Error('Unknown test step');
|
|
58
70
|
if (record.testStepId && record.naming)
|
|
@@ -100,6 +112,11 @@ export function parseExecution(value) {
|
|
|
100
112
|
}
|
|
101
113
|
const containing = loops.filter(loop => loop.memberIds.includes(id));
|
|
102
114
|
for (const [index, attempt] of step.attempts.entries()) {
|
|
115
|
+
if (attempt.deadlineAt !== undefined) {
|
|
116
|
+
const configuration = stepConfiguration(record, original, id, attempt.number);
|
|
117
|
+
if (configuration?.kind !== 'workflow' || configuration.timeoutMs === undefined || attempt.deadlineAt !== attempt.startedAt + configuration.timeoutMs)
|
|
118
|
+
throw new Error('Invalid call attempt deadline');
|
|
119
|
+
}
|
|
103
120
|
if ((attempt.loops ?? []).length !== containing.length || containing.some(loop => !attempt.loops?.some(identity => identity.headerId === loop.headerId)))
|
|
104
121
|
throw new Error('Invalid attempt loop identities');
|
|
105
122
|
if (containing.length && index === 0 && attempt.action !== 'execute')
|
|
@@ -133,5 +150,104 @@ export function parseExecution(value) {
|
|
|
133
150
|
}
|
|
134
151
|
if (['completed', 'completed-with-recovery'].includes(record.status) && Object.values(record.steps).some(step => ['pending', 'running', 'interrupted', 'blocked'].includes(step.status)))
|
|
135
152
|
throw new Error('Completed execution contains unfinished work');
|
|
153
|
+
return original;
|
|
154
|
+
}
|
|
155
|
+
function stepConfiguration(record, original, stepId, attempt) {
|
|
156
|
+
let step = original.steps.find(step => step.id === stepId);
|
|
157
|
+
for (const update of record.definitionUpdates ?? [])
|
|
158
|
+
if (update.stepId === stepId && update.attempt <= attempt)
|
|
159
|
+
step = update.nextStep;
|
|
160
|
+
return step;
|
|
161
|
+
}
|
|
162
|
+
export function parseExecution(value) {
|
|
163
|
+
const record = workflowExecutionValidator.parse(value);
|
|
164
|
+
executionIdentity(record);
|
|
165
|
+
const original = validateCheckpoint(record);
|
|
166
|
+
const manifest = record.retainedDefinitions;
|
|
167
|
+
if (!manifest) {
|
|
168
|
+
if (record.invocations || record.definition.steps.some(step => step.kind === 'workflow'))
|
|
169
|
+
throw new Error('Missing retained Workflow Definitions');
|
|
170
|
+
return record;
|
|
171
|
+
}
|
|
172
|
+
for (const [id, definition] of Object.entries(manifest))
|
|
173
|
+
if (id !== definition.id)
|
|
174
|
+
throw new Error('Invalid retained definition identity');
|
|
175
|
+
if (!isDeepStrictEqual(manifest[original.id], original))
|
|
176
|
+
throw new Error('Retained root definition does not match the original checkpoint');
|
|
177
|
+
const resolved = resolveWorkflowCalls(original, id => {
|
|
178
|
+
if (!Object.hasOwn(manifest, id))
|
|
179
|
+
throw new Error('Missing retained definition');
|
|
180
|
+
return manifest[id];
|
|
181
|
+
}, record.testStepId);
|
|
182
|
+
if (!isDeepStrictEqual(resolved, manifest))
|
|
183
|
+
throw new Error('Retained definitions do not match the call manifest');
|
|
184
|
+
const locals = new Map();
|
|
185
|
+
const originals = new Map();
|
|
186
|
+
for (const [id, invocation] of Object.entries(record.invocations ?? {})) {
|
|
187
|
+
if (id !== invocation.id || id === record.id)
|
|
188
|
+
throw new Error('Invalid invocation identity');
|
|
189
|
+
const retained = manifest[invocation.definitionId];
|
|
190
|
+
if (!retained)
|
|
191
|
+
throw new Error('Missing invocation definition');
|
|
192
|
+
const definition = structuredClone(retained);
|
|
193
|
+
for (const update of invocation.definitionUpdates ?? []) {
|
|
194
|
+
const index = definition.steps.findIndex(step => step.id === update.stepId);
|
|
195
|
+
if (index < 0)
|
|
196
|
+
throw new Error('Unknown invocation correction step');
|
|
197
|
+
definition.steps[index] = structuredClone(update.nextStep);
|
|
198
|
+
}
|
|
199
|
+
const local = { ...invocation, ...executionIdentity(record), scope: record.scope, definition };
|
|
200
|
+
if (!isDeepStrictEqual(validateCheckpoint(local), retained))
|
|
201
|
+
throw new Error('Invocation corrections do not match the retained definition');
|
|
202
|
+
locals.set(id, local);
|
|
203
|
+
originals.set(id, retained);
|
|
204
|
+
}
|
|
205
|
+
const checked = new Set();
|
|
206
|
+
for (const id of locals.keys()) {
|
|
207
|
+
const path = new Set();
|
|
208
|
+
let current = id;
|
|
209
|
+
while (current !== undefined && !checked.has(current)) {
|
|
210
|
+
if (path.has(current))
|
|
211
|
+
throw new Error('Invocation parent cycle');
|
|
212
|
+
path.add(current);
|
|
213
|
+
const invocation = record.invocations[current];
|
|
214
|
+
if (!invocation)
|
|
215
|
+
throw new Error('Missing parent invocation');
|
|
216
|
+
current = invocation.parentInvocationId;
|
|
217
|
+
}
|
|
218
|
+
for (const ancestor of path)
|
|
219
|
+
checked.add(ancestor);
|
|
220
|
+
}
|
|
221
|
+
const owners = new Set();
|
|
222
|
+
for (const [id, invocation] of Object.entries(record.invocations ?? {})) {
|
|
223
|
+
const parentId = invocation.parentInvocationId;
|
|
224
|
+
const parent = parentId === undefined ? record : locals.get(parentId);
|
|
225
|
+
const parentOriginal = parentId === undefined ? original : originals.get(parentId);
|
|
226
|
+
const step = stepConfiguration(parent, parentOriginal, invocation.callStepId, invocation.callAttempt);
|
|
227
|
+
const state = parent.steps[invocation.callStepId];
|
|
228
|
+
const attempt = state?.attempts[invocation.callAttempt - 1];
|
|
229
|
+
if (step?.kind !== 'workflow' || step.workflowId !== invocation.definitionId || !attempt || attempt.action === 'supply' || (parent.testStepId !== undefined && parent.testStepId !== step.id))
|
|
230
|
+
throw new Error('Invalid invocation call ownership');
|
|
231
|
+
if (!isDeepStrictEqual(invocation.input, attempt.input))
|
|
232
|
+
throw new Error('Invocation input does not match the call attempt');
|
|
233
|
+
if (step.timeoutMs !== undefined && attempt.deadlineAt === undefined)
|
|
234
|
+
throw new Error('Missing call attempt deadline');
|
|
235
|
+
if (invocation.callAttempt < state.attempts.length && ['running', 'recovery-required'].includes(invocation.status))
|
|
236
|
+
throw new Error('Unfinished invocation belongs to an earlier call attempt');
|
|
237
|
+
const owner = JSON.stringify([parentId ?? null, invocation.callStepId, invocation.callAttempt]);
|
|
238
|
+
if (owners.has(owner))
|
|
239
|
+
throw new Error('Duplicate invocation call ownership');
|
|
240
|
+
owners.add(owner);
|
|
241
|
+
if (['completed', 'completed-with-recovery'].includes(invocation.status) && invocation.result === undefined)
|
|
242
|
+
throw new Error('Missing completed invocation result');
|
|
243
|
+
if (['completed', 'completed-with-recovery'].includes(record.status) && ['running', 'recovery-required'].includes(invocation.status))
|
|
244
|
+
throw new Error('Completed execution contains unfinished invocations');
|
|
245
|
+
if (!locals.has(id))
|
|
246
|
+
throw new Error('Missing invocation checkpoint');
|
|
247
|
+
}
|
|
136
248
|
return record;
|
|
137
249
|
}
|
|
250
|
+
/** Stable checkpoint owner, independent of optional Agent Session association. */
|
|
251
|
+
export function executionOwner(record) {
|
|
252
|
+
return executionOwnerKey(executionOwnerOf(record));
|
|
253
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
2
|
import { isDeepStrictEqual } from 'node:util';
|
|
3
|
-
import { validateDefinition } from
|
|
3
|
+
import { validateDefinition } from './graph.js';
|
|
4
|
+
import { invocationExecution } from './invocations.js';
|
|
4
5
|
// Object key order is not part of a saved definition's identity; array order is.
|
|
5
6
|
function canonical(value) {
|
|
6
7
|
if (Array.isArray(value))
|
|
@@ -48,17 +49,52 @@ export function validateCompatibleDefinition(previous, candidate, stepId) {
|
|
|
48
49
|
}
|
|
49
50
|
return graph;
|
|
50
51
|
}
|
|
52
|
+
export function recoverySteps(root, action, replacement) {
|
|
53
|
+
const steps = [];
|
|
54
|
+
let invocationId = action.invocationId, selected = true;
|
|
55
|
+
for (;;) {
|
|
56
|
+
const current = invocationId === undefined ? root : invocationExecution(root, invocationId);
|
|
57
|
+
const graph = validateDefinition(selected && replacement ? replacement : current.definition);
|
|
58
|
+
const repeating = new Set(current.testStepId ? [] : graph.loops.filter(loop => ['active', 'repeating', 'limit'].includes(current.loops?.[loop.headerId]?.phase ?? 'inactive')).flatMap(loop => loop.memberIds));
|
|
59
|
+
const owned = new Set(Object.values(root.invocations ?? {}).filter(invocation => {
|
|
60
|
+
const call = current.steps[invocation.callStepId];
|
|
61
|
+
return invocation.parentInvocationId === invocationId && call?.status === 'running' && invocation.callAttempt === call.attempts.length;
|
|
62
|
+
}).map(invocation => invocation.callStepId));
|
|
63
|
+
for (const step of graph.order) {
|
|
64
|
+
if (current.testStepId && current.testStepId !== step.id)
|
|
65
|
+
continue;
|
|
66
|
+
if (!repeating.has(step.id)) {
|
|
67
|
+
const state = current.steps[step.id];
|
|
68
|
+
if (!current.testStepId && ['failed', 'timed-out'].includes(state.status) && !state.recovery && graph.outgoing.get(step.id).some(edge => edge.outcome === state.outcome))
|
|
69
|
+
continue;
|
|
70
|
+
if (state.status === 'completed' || owned.has(step.id))
|
|
71
|
+
continue;
|
|
72
|
+
if (selected && action.kind === 'supply' && action.stepId === step.id)
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
steps.push(step);
|
|
76
|
+
}
|
|
77
|
+
if (invocationId === undefined)
|
|
78
|
+
return steps;
|
|
79
|
+
invocationId = root.invocations[invocationId].parentInvocationId;
|
|
80
|
+
selected = false;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
51
83
|
/** State identity, not wall-clock time: repeated notifications cannot mint new authority. */
|
|
52
84
|
export function recoveryRevision(record) {
|
|
53
85
|
return createHash('sha256').update(JSON.stringify({ id: record.id, status: record.status,
|
|
54
86
|
steps: Object.entries(record.steps).map(([id, step]) => [id, step.status, step.attempts.map(a => [a.number, a.action, a.finishedAt, a.error])]),
|
|
55
87
|
loops: record.loops, definition: savedDefinitionRevision(record.definition), definitionUpdates: record.definitionUpdates,
|
|
88
|
+
invocations: record.invocations, retainedDefinitions: record.retainedDefinitions,
|
|
56
89
|
})).digest('hex');
|
|
57
90
|
}
|
|
58
91
|
export function successfulProgress(record) {
|
|
59
|
-
|
|
92
|
+
const local = (execution) => Object.entries(execution.steps).reduce((count, [id, step]) => count + (execution.definition.steps.find(step => step.id === id)?.kind === 'workflow' ? 0 : step.attempts.filter(a => a.finishedAt !== undefined && a.output !== undefined && !a.error && a.action !== 'supply').length), 0);
|
|
93
|
+
return local(record) + Object.keys(record.invocations ?? {}).reduce((count, id) => count + local(invocationExecution(record, id)), 0);
|
|
60
94
|
}
|
|
61
95
|
export function safeAutomaticRecovery(record, action) {
|
|
96
|
+
if (action.invocationId)
|
|
97
|
+
record = invocationExecution(record, action.invocationId);
|
|
62
98
|
if (record.status !== 'recovery-required' || Object.values(record.loops ?? {}).some(loop => loop.phase === 'limit'))
|
|
63
99
|
return false;
|
|
64
100
|
if (action.kind === 'retry') {
|
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import { accessSync, constants, statSync } from 'node:fs';
|
|
2
2
|
import { delimiter, isAbsolute, join } from 'node:path';
|
|
3
|
-
import { DEFAULT_WORKFLOW_RUNTIME } from
|
|
4
|
-
export function
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
import { DEFAULT_WORKFLOW_RUNTIME } from '../protocol/settings.js';
|
|
4
|
+
export function findExecutable(name, search) {
|
|
5
|
+
for (const directory of search.split(delimiter)) {
|
|
6
|
+
if (!isAbsolute(directory))
|
|
7
|
+
continue;
|
|
8
|
+
const candidate = join(directory, name);
|
|
9
|
+
try {
|
|
10
|
+
if (!statSync(candidate).isFile())
|
|
8
11
|
continue;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
if (!statSync(candidate).isFile())
|
|
12
|
-
continue;
|
|
13
|
-
accessSync(candidate, constants.X_OK);
|
|
14
|
-
return candidate;
|
|
15
|
-
}
|
|
16
|
-
catch { }
|
|
12
|
+
accessSync(candidate, constants.X_OK);
|
|
13
|
+
return candidate;
|
|
17
14
|
}
|
|
18
|
-
|
|
19
|
-
}
|
|
15
|
+
catch { }
|
|
16
|
+
}
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
export function workflowRuntimeOptions(settings = DEFAULT_WORKFLOW_RUNTIME, path) {
|
|
20
20
|
return {
|
|
21
|
-
nodePath: settings.nodePath ??
|
|
21
|
+
nodePath: settings.nodePath ?? findExecutable('node', path ?? process.env.PATH ?? ''),
|
|
22
22
|
};
|
|
23
23
|
}
|
|
@@ -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
|
|
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(); };
|