@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
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
3
|
+
import { Temporal } from '@js-temporal/polyfill';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
export const SCHEDULE_RETENTION_MS = 7 * 24 * 60 * 60 * 1000;
|
|
6
|
+
export const LIVE_DISPATCH_TOLERANCE_MS = 30_000;
|
|
7
|
+
export const storageId = z.string().regex(/^[a-zA-Z0-9_-]+$/).max(200);
|
|
8
|
+
export const timestamp = z.number().int().nonnegative().max(8_640_000_000_000_000);
|
|
9
|
+
const timezone = z.string().max(200).refine(value => {
|
|
10
|
+
try {
|
|
11
|
+
// Temporal also accepts numeric offsets; schedules deliberately require named zones.
|
|
12
|
+
return !/^[+\-\u2212]/.test(value) && Temporal.Instant.fromEpochMilliseconds(0).toZonedDateTimeISO(value).timeZoneId.length > 0;
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
}, 'Invalid IANA timezone');
|
|
18
|
+
export const timingValidator = z.discriminatedUnion('kind', [
|
|
19
|
+
z.object({ kind: z.literal('interval'), value: z.number().int().positive().max(Number.MAX_SAFE_INTEGER), unit: z.enum(['minutes', 'hours', 'days']) }).strict().refine(value => Number.isSafeInteger(value.value * intervalUnit(value.unit)) && value.value * intervalUnit(value.unit) <= 8_640_000_000_000_000, 'Interval is too large'),
|
|
20
|
+
z.object({ kind: z.literal('daily'), time: z.string().regex(/^(?:[01]\d|2[0-3]):[0-5]\d$/), timezone }).strict(),
|
|
21
|
+
]);
|
|
22
|
+
export const scheduleSettingsValidator = z.object({
|
|
23
|
+
name: z.string().trim().min(1).max(200), workflowId: storageId,
|
|
24
|
+
input: z.json(), projectId: z.string().min(1).max(4096),
|
|
25
|
+
mcpConnectionIds: z.array(storageId).max(100).refine(ids => new Set(ids).size === ids.length, 'Duplicate MCP selection'),
|
|
26
|
+
worktree: z.object({ from: z.string().min(1).max(1024) }).strict().optional(),
|
|
27
|
+
timing: timingValidator, concurrency: z.number().int().min(1).max(100).default(3),
|
|
28
|
+
}).strict();
|
|
29
|
+
export const scheduleValidator = scheduleSettingsValidator.extend({
|
|
30
|
+
version: z.literal(1), id: storageId, revision: z.number().int().positive(), activation: z.number().int().nonnegative(),
|
|
31
|
+
enabled: z.boolean(), createdAt: timestamp, updatedAt: timestamp,
|
|
32
|
+
nextDue: timestamp.optional(), deletedAt: timestamp.optional(),
|
|
33
|
+
}).strict().superRefine((value, context) => {
|
|
34
|
+
if (value.enabled !== (value.nextDue !== undefined) || (value.deletedAt !== undefined && value.enabled))
|
|
35
|
+
context.addIssue({ code: 'custom', message: 'Invalid schedule cursor' });
|
|
36
|
+
if (value.enabled && value.activation < 1)
|
|
37
|
+
context.addIssue({ code: 'custom', message: 'Missing activation' });
|
|
38
|
+
});
|
|
39
|
+
export const occurrenceValidator = z.object({
|
|
40
|
+
version: z.literal(1), id: storageId, scheduleId: storageId,
|
|
41
|
+
activation: z.number().int().positive(), revision: z.number().int().positive(), scheduledAt: timestamp,
|
|
42
|
+
missedThrough: timestamp.optional(), settings: scheduleSettingsValidator,
|
|
43
|
+
status: z.enum(['provisioning', 'running', 'recovery-required', 'completed', 'completed-with-recovery', 'cancelled', 'launch-failed', 'interrupted', 'capacity-skipped', 'missed']),
|
|
44
|
+
createdAt: timestamp, finishedAt: timestamp.optional(), sessionId: storageId.optional(), association: z.enum(['pending', 'attached', 'failed']).optional(), executionId: storageId.optional(),
|
|
45
|
+
scope: z.string().min(1).optional(), worktree: z.object({ path: z.string(), repo: z.string(), branch: z.string() }).strict().optional(),
|
|
46
|
+
outcome: z.string().max(2000).optional(),
|
|
47
|
+
warning: z.string().max(2000).optional(),
|
|
48
|
+
}).strict().superRefine((value, context) => {
|
|
49
|
+
if (value.id !== occurrenceId(value.scheduleId, value.activation, value.scheduledAt))
|
|
50
|
+
context.addIssue({ code: 'custom', message: 'Invalid occurrence identity' });
|
|
51
|
+
if (isActiveOccurrence(value) === (value.finishedAt !== undefined))
|
|
52
|
+
context.addIssue({ code: 'custom', message: 'Invalid occurrence completion' });
|
|
53
|
+
if (value.missedThrough !== undefined && (value.status !== 'missed' || value.missedThrough < value.scheduledAt))
|
|
54
|
+
context.addIssue({ code: 'custom', message: 'Invalid missed range' });
|
|
55
|
+
});
|
|
56
|
+
function intervalUnit(unit) { return { minutes: 60_000, hours: 3_600_000, days: 86_400_000 }[unit]; }
|
|
57
|
+
export function intervalMilliseconds(timing) {
|
|
58
|
+
timingValidator.parse(timing);
|
|
59
|
+
return timing.value * intervalUnit(timing.unit);
|
|
60
|
+
}
|
|
61
|
+
export function occurrenceId(scheduleId, activation, due) {
|
|
62
|
+
storageId.parse(scheduleId);
|
|
63
|
+
z.number().int().positive().parse(activation);
|
|
64
|
+
timestamp.parse(due);
|
|
65
|
+
return createHash('sha256').update(JSON.stringify([scheduleId, activation, due])).digest('hex');
|
|
66
|
+
}
|
|
67
|
+
/** Strictly future civil-time match. Gaps are skipped; folds use only their earlier instant. */
|
|
68
|
+
export function nextOccurrence(timing, after) {
|
|
69
|
+
timingValidator.parse(timing);
|
|
70
|
+
timestamp.parse(after);
|
|
71
|
+
if (timing.kind === 'interval')
|
|
72
|
+
return timestamp.parse(after + intervalMilliseconds(timing));
|
|
73
|
+
const instant = Temporal.Instant.fromEpochMilliseconds(after);
|
|
74
|
+
let date = instant.toZonedDateTimeISO(timing.timezone).toPlainDate();
|
|
75
|
+
const time = Temporal.PlainTime.from(timing.time);
|
|
76
|
+
// IANA transitions can skip a date, but cannot exhaust a week of daily candidates.
|
|
77
|
+
for (let day = 0; day < 8; day++, date = date.add({ days: 1 })) {
|
|
78
|
+
const civil = date.toPlainDateTime(time);
|
|
79
|
+
const candidate = civil.toZonedDateTime(timing.timezone, { disambiguation: 'earlier' });
|
|
80
|
+
if (!candidate.toPlainDateTime().equals(civil))
|
|
81
|
+
continue;
|
|
82
|
+
const due = candidate.epochMilliseconds;
|
|
83
|
+
if (due > after)
|
|
84
|
+
return timestamp.parse(due);
|
|
85
|
+
}
|
|
86
|
+
throw new Error('No representable future occurrence');
|
|
87
|
+
}
|
|
88
|
+
/** Advance an interval in constant time; daily timing is resolved directly at the target date. */
|
|
89
|
+
export function advancePast(timing, due, through) {
|
|
90
|
+
timestamp.parse(due);
|
|
91
|
+
timestamp.parse(through);
|
|
92
|
+
if (due > through)
|
|
93
|
+
return due;
|
|
94
|
+
if (timing.kind === 'interval') {
|
|
95
|
+
const interval = intervalMilliseconds(timing);
|
|
96
|
+
return timestamp.parse(due + (Math.floor((through - due) / interval) + 1) * interval);
|
|
97
|
+
}
|
|
98
|
+
return nextOccurrence(timing, through);
|
|
99
|
+
}
|
|
100
|
+
export function isActiveOccurrence(value) {
|
|
101
|
+
return ['provisioning', 'running', 'recovery-required'].includes(value.status);
|
|
102
|
+
}
|
|
103
|
+
export function projectExecution(occurrence, execution, now) {
|
|
104
|
+
if (execution.occurrenceId !== occurrence.id)
|
|
105
|
+
throw new Error('Execution occurrence mismatch');
|
|
106
|
+
const { finishedAt: _, ...saved } = occurrence;
|
|
107
|
+
return { ...saved, executionId: execution.id, ...(execution.sessionId ? { sessionId: execution.sessionId } : {}), status: execution.status,
|
|
108
|
+
...(isActiveOccurrence(execution) ? {} : { finishedAt: execution.finishedAt ?? now }) };
|
|
109
|
+
}
|
|
110
|
+
export function createSchedule(settings, now, enabled = false) {
|
|
111
|
+
const validated = scheduleSettingsValidator.parse(settings);
|
|
112
|
+
timestamp.parse(now);
|
|
113
|
+
return scheduleValidator.parse({ ...validated, version: 1, id: randomUUID(), revision: 1, activation: enabled ? 1 : 0, enabled, createdAt: now, updatedAt: now, ...(enabled ? { nextDue: nextOccurrence(validated.timing, now) } : {}) });
|
|
114
|
+
}
|
|
115
|
+
/** Timing edits and false→true activation reset the anchor; unrelated edits preserve it. */
|
|
116
|
+
export function editSchedule(saved, settings, enabled, now) {
|
|
117
|
+
scheduleValidator.parse(saved);
|
|
118
|
+
timestamp.parse(now);
|
|
119
|
+
if (saved.deletedAt !== undefined)
|
|
120
|
+
throw new Error('Schedule was deleted');
|
|
121
|
+
const validated = scheduleSettingsValidator.parse(settings);
|
|
122
|
+
const activate = enabled && (!saved.enabled || !isDeepStrictEqual(saved.timing, validated.timing));
|
|
123
|
+
const { nextDue: previousDue, ...rest } = saved;
|
|
124
|
+
return scheduleValidator.parse({ ...rest, ...validated, revision: saved.revision + 1, activation: saved.activation + Number(activate), enabled, updatedAt: now,
|
|
125
|
+
...(enabled ? { nextDue: activate ? nextOccurrence(validated.timing, now) : previousDue } : {}) });
|
|
126
|
+
}
|
|
127
|
+
export function occurrenceSettings(schedule) {
|
|
128
|
+
const { name, workflowId, input, projectId, mcpConnectionIds, timing, concurrency, worktree } = schedule;
|
|
129
|
+
return structuredClone({ name, workflowId, input, projectId, mcpConnectionIds, timing, concurrency, ...(worktree ? { worktree } : {}) });
|
|
130
|
+
}
|
package/dist/workflows/schema.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { compileJsonSchema, validateJsonSchema, jsonSchemaAt } from
|
|
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) {
|
|
@@ -76,6 +76,8 @@ export const shellOutputSchema = { type: 'object', fields: {
|
|
|
76
76
|
stderr: { schema: { type: 'string' }, required: true },
|
|
77
77
|
} };
|
|
78
78
|
export function declaredOutputSchema(step) {
|
|
79
|
+
if (step.kind === 'workflow')
|
|
80
|
+
return step.contract.outputSchema;
|
|
79
81
|
if (step.kind === 'mcp')
|
|
80
82
|
return { type: 'object', fields: { structuredContent: { required: true, schema: { type: 'json', ...(step.tool.outputSchema === undefined ? {} : { schema: step.tool.outputSchema }) } }, content: { required: true, schema: { type: 'array', items: { type: 'json' } } } } };
|
|
81
83
|
if (step.kind === 'shell')
|
package/dist/workflows/store.js
CHANGED
|
@@ -1,8 +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
|
|
5
|
-
import { parseExecution } from
|
|
4
|
+
import { validateDefinition } from './graph.js';
|
|
5
|
+
import { parseExecution } from './records.js';
|
|
6
|
+
import { executionAccessibleBy, executionAssociation, executionIdentity, executionOwnerKey, executionOwnerOf, executionOwnerPath, parseExecutionOwnerKey } from './owner.js';
|
|
6
7
|
function segment(value) {
|
|
7
8
|
if (!/^[a-zA-Z0-9_-]+$/.test(value))
|
|
8
9
|
throw new Error('Invalid storage ID');
|
|
@@ -54,7 +55,33 @@ function ids(directory) {
|
|
|
54
55
|
export class WorkflowStore {
|
|
55
56
|
stateRoot;
|
|
56
57
|
redact = value => value;
|
|
57
|
-
|
|
58
|
+
owners = new Map();
|
|
59
|
+
associations = new Map();
|
|
60
|
+
sessionsByOwner = new Map();
|
|
61
|
+
constructor(stateRoot) {
|
|
62
|
+
this.stateRoot = stateRoot;
|
|
63
|
+
const directory = join(stateRoot, 'workflow-schedules', 'executions');
|
|
64
|
+
const occurrences = existsSync(directory) ? readdirSync(directory, { withFileTypes: true }).filter(entry => entry.isDirectory()).map(entry => ({ kind: 'occurrence', occurrenceId: entry.name })) : [];
|
|
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
|
+
}
|
|
74
|
+
this.owners.set(this.ownerIndexKey(owner), owner);
|
|
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
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
58
85
|
saveDefinition(definition) {
|
|
59
86
|
const validated = validateDefinition(definition).definition;
|
|
60
87
|
atomicWrite(join(this.stateRoot, 'workflows'), validated.id, this.redact(validated));
|
|
@@ -72,22 +99,108 @@ export class WorkflowStore {
|
|
|
72
99
|
syncDirectory(directory);
|
|
73
100
|
}
|
|
74
101
|
saveExecution(execution) {
|
|
75
|
-
|
|
102
|
+
const saved = this.redact(execution);
|
|
103
|
+
executionIdentity(saved);
|
|
104
|
+
atomicWrite(this.historyPath(executionOwnerOf(saved)), saved.id, saved);
|
|
105
|
+
this.index(saved);
|
|
76
106
|
}
|
|
77
|
-
getExecution(
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
107
|
+
getExecution(ownerId, id) {
|
|
108
|
+
const owner = typeof ownerId === 'string' ? parseExecutionOwnerKey(ownerId) : ownerId;
|
|
109
|
+
const ownPath = join(this.historyPath(owner), `${segment(id)}.json`);
|
|
110
|
+
if (existsSync(ownPath) || owner.kind === 'occurrence')
|
|
111
|
+
return this.readExecution(owner, id);
|
|
112
|
+
const reference = [...(this.associations.get(owner.sessionId)?.values() ?? [])].find(reference => reference.id === id);
|
|
113
|
+
if (!reference)
|
|
114
|
+
return this.readExecution(owner, id);
|
|
115
|
+
const record = this.readExecution(reference.owner, id);
|
|
116
|
+
if (!executionAccessibleBy(record, owner))
|
|
117
|
+
throw new Error('Invalid workflow execution association');
|
|
118
|
+
return record;
|
|
119
|
+
}
|
|
120
|
+
deleteOwner(ownerId) {
|
|
121
|
+
const owner = typeof ownerId === 'string' ? parseExecutionOwnerKey(ownerId) : ownerId;
|
|
122
|
+
const directory = this.ownerPath(owner);
|
|
123
|
+
rmSync(directory, { recursive: true, force: true });
|
|
124
|
+
if (existsSync(dirname(directory)))
|
|
125
|
+
syncDirectory(dirname(directory));
|
|
126
|
+
const ownerKey = this.ownerIndexKey(owner);
|
|
127
|
+
for (const id of this.sessionsByOwner.get(ownerKey)?.keys() ?? [])
|
|
128
|
+
this.removeAssociation(ownerKey, id);
|
|
129
|
+
this.owners.delete(ownerKey);
|
|
82
130
|
}
|
|
83
|
-
|
|
84
|
-
|
|
131
|
+
listOwnedExecutions(owner) {
|
|
132
|
+
const identity = typeof owner === 'string' ? parseExecutionOwnerKey(owner) : owner;
|
|
133
|
+
return ids(this.historyPath(identity)).map(id => this.readExecution(identity, id));
|
|
134
|
+
}
|
|
135
|
+
listExecutions(ownerId) {
|
|
136
|
+
const owner = typeof ownerId === 'string' ? parseExecutionOwnerKey(ownerId) : ownerId;
|
|
137
|
+
const own = this.listOwnedExecutions(owner);
|
|
138
|
+
if (owner.kind === 'occurrence')
|
|
139
|
+
return own;
|
|
140
|
+
const associated = [...(this.associations.get(owner.sessionId)?.values() ?? [])]
|
|
141
|
+
.filter(reference => existsSync(join(this.historyPath(reference.owner), `${segment(reference.id)}.json`)))
|
|
142
|
+
.map(reference => {
|
|
143
|
+
const record = this.readExecution(reference.owner, reference.id);
|
|
144
|
+
if (!executionAccessibleBy(record, owner))
|
|
145
|
+
throw new Error('Invalid workflow execution association');
|
|
146
|
+
return record;
|
|
147
|
+
});
|
|
148
|
+
return [...own, ...associated];
|
|
85
149
|
}
|
|
86
150
|
listSessionIds() {
|
|
87
151
|
const directory = join(this.stateRoot, 'sessions');
|
|
88
152
|
return existsSync(directory) ? readdirSync(directory, { withFileTypes: true }).filter(entry => entry.isDirectory()).map(entry => entry.name) : [];
|
|
89
153
|
}
|
|
90
|
-
|
|
91
|
-
return
|
|
154
|
+
listOwners() {
|
|
155
|
+
return [...this.owners.values()].filter(owner => existsSync(this.ownerPath(owner))).map(owner => ({ ...owner }));
|
|
156
|
+
}
|
|
157
|
+
listOwnerIds() { return this.listOwners().map(executionOwnerKey); }
|
|
158
|
+
ownerPath(owner) {
|
|
159
|
+
return executionOwnerPath(this.stateRoot, typeof owner === 'string' ? parseExecutionOwnerKey(owner) : owner);
|
|
160
|
+
}
|
|
161
|
+
historyPath(owner) {
|
|
162
|
+
return join(this.ownerPath(owner), 'workflows');
|
|
163
|
+
}
|
|
164
|
+
ownerIndexKey(owner) {
|
|
165
|
+
return JSON.stringify(owner.kind === 'session' ? ['session', owner.sessionId] : ['occurrence', owner.occurrenceId]);
|
|
166
|
+
}
|
|
167
|
+
readExecution(owner, id) {
|
|
168
|
+
const value = parseExecution(readJson(join(this.historyPath(owner), `${segment(id)}.json`)));
|
|
169
|
+
if (value.id !== id || this.ownerIndexKey(executionOwnerOf(value)) !== this.ownerIndexKey(owner))
|
|
170
|
+
throw new Error('Invalid workflow execution identity');
|
|
171
|
+
return value;
|
|
172
|
+
}
|
|
173
|
+
index(record) {
|
|
174
|
+
const owner = executionOwnerOf(record);
|
|
175
|
+
const ownerKey = this.ownerIndexKey(owner);
|
|
176
|
+
const key = JSON.stringify([ownerKey, record.id]);
|
|
177
|
+
this.removeAssociation(ownerKey, record.id);
|
|
178
|
+
this.owners.set(ownerKey, owner);
|
|
179
|
+
const sessionId = executionAssociation(record);
|
|
180
|
+
if (sessionId === undefined)
|
|
181
|
+
return;
|
|
182
|
+
let references = this.associations.get(sessionId);
|
|
183
|
+
if (!references)
|
|
184
|
+
this.associations.set(sessionId, references = new Map());
|
|
185
|
+
references.set(key, { owner, id: record.id });
|
|
186
|
+
let sessions = this.sessionsByOwner.get(ownerKey);
|
|
187
|
+
if (!sessions)
|
|
188
|
+
this.sessionsByOwner.set(ownerKey, sessions = new Map());
|
|
189
|
+
sessions.set(record.id, sessionId);
|
|
190
|
+
}
|
|
191
|
+
removeAssociation(ownerKey, id) {
|
|
192
|
+
const sessions = this.sessionsByOwner.get(ownerKey);
|
|
193
|
+
if (!sessions)
|
|
194
|
+
return;
|
|
195
|
+
const sessionId = sessions.get(id);
|
|
196
|
+
if (sessionId === undefined)
|
|
197
|
+
return;
|
|
198
|
+
const references = this.associations.get(sessionId);
|
|
199
|
+
references.delete(JSON.stringify([ownerKey, id]));
|
|
200
|
+
if (!references.size)
|
|
201
|
+
this.associations.delete(sessionId);
|
|
202
|
+
sessions.delete(id);
|
|
203
|
+
if (!sessions.size)
|
|
204
|
+
this.sessionsByOwner.delete(ownerKey);
|
|
92
205
|
}
|
|
93
206
|
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nathanstephenson/flow",
|
|
3
|
-
"version": "0.1.10-beta.
|
|
3
|
+
"version": "0.1.10-beta.10",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/nathanstephenson/flow.git"
|
|
8
8
|
},
|
|
9
9
|
"engines": {
|
|
10
|
-
"node": ">=22"
|
|
10
|
+
"node": ">=22.19.0"
|
|
11
11
|
},
|
|
12
12
|
"bin": {
|
|
13
13
|
"flow": "./dist/cli/bootstrap.js"
|
|
@@ -38,10 +38,11 @@
|
|
|
38
38
|
"build:binary": "node --experimental-strip-types scripts/build-binary.mjs"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@anthropic-ai/claude-agent-sdk": "^0.3.
|
|
41
|
+
"@anthropic-ai/claude-agent-sdk": "^0.3.329",
|
|
42
42
|
"@codemirror/lang-javascript": "^6.2.5",
|
|
43
|
-
"@earendil-works/pi-ai": "^
|
|
44
|
-
"@earendil-works/pi-coding-agent": "^
|
|
43
|
+
"@earendil-works/pi-ai": "^1.6.0",
|
|
44
|
+
"@earendil-works/pi-coding-agent": "^1.6.0",
|
|
45
|
+
"@js-temporal/polyfill": "0.5.1",
|
|
45
46
|
"@modelcontextprotocol/sdk": "^1.31.0",
|
|
46
47
|
"@xyflow/react": "^12.11.6",
|
|
47
48
|
"ajv": "^8.20.0",
|
|
@@ -50,9 +51,10 @@
|
|
|
50
51
|
"marked": "^18.0.11",
|
|
51
52
|
"node-pty": "^1.1.0",
|
|
52
53
|
"openid-client": "^6.8.8",
|
|
54
|
+
"proper-lockfile": "4.1.2",
|
|
53
55
|
"quickjs-emscripten": "^0.32.0",
|
|
54
56
|
"typebox": "^1.3.7",
|
|
55
|
-
"typescript": "
|
|
57
|
+
"typescript-api": "npm:typescript@^5.9.3",
|
|
56
58
|
"ws": "^8.21.3",
|
|
57
59
|
"zod": "^4.6.5"
|
|
58
60
|
},
|
|
@@ -69,6 +71,7 @@
|
|
|
69
71
|
"@tailwindcss/vite": "^4.3.3",
|
|
70
72
|
"@types/node": "^22.20.1",
|
|
71
73
|
"@types/oidc-provider": "^9.12.1",
|
|
74
|
+
"@types/proper-lockfile": "4.1.4",
|
|
72
75
|
"@types/react": "^19.2.18",
|
|
73
76
|
"@types/react-dom": "^19.2.5",
|
|
74
77
|
"@types/ws": "^8.18.1",
|
|
@@ -86,6 +89,7 @@
|
|
|
86
89
|
"tailwind-merge": "^3.6.0",
|
|
87
90
|
"tailwindcss": "^4.3.3",
|
|
88
91
|
"tw-animate-css": "^1.4.0",
|
|
92
|
+
"typescript": "^7.0.2",
|
|
89
93
|
"vite": "^8.2.2"
|
|
90
94
|
}
|
|
91
95
|
}
|