@igorjpimenta/manifold 0.0.0-stage → 2026.11.22-beta.3
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/.migrations/ops/0000_futuristic_karma.sql +111 -0
- package/.migrations/ops/0001_low_maximus.sql +7 -0
- package/.migrations/ops/meta/0000_snapshot.json +763 -0
- package/.migrations/ops/meta/0001_snapshot.json +173 -0
- package/.migrations/ops/meta/_journal.json +20 -0
- package/.migrations/runtime/0000_real_boomer.sql +180 -0
- package/.migrations/runtime/0001_hot_dakota_north.sql +2 -0
- package/.migrations/runtime/0002_breezy_vertigo.sql +8 -0
- package/.migrations/runtime/0003_dashing_jack_flag.sql +5 -0
- package/.migrations/runtime/0004_panoramic_ego.sql +1 -0
- package/.migrations/runtime/0005_tidy_ben_grimm.sql +10 -0
- package/.migrations/runtime/0006_wet_nightmare.sql +57 -0
- package/.migrations/runtime/0007_ambiguous_chronomancer.sql +8 -0
- package/.migrations/runtime/0008_wealthy_thundra.sql +301 -0
- package/.migrations/runtime/0009_lying_shocker.sql +96 -0
- package/.migrations/runtime/0010_solid_phantom_reporter.sql +160 -0
- package/.migrations/runtime/0011_windy_demogoblin.sql +175 -0
- package/.migrations/runtime/0012_restore_harness_fks.sql +103 -0
- package/.migrations/runtime/meta/0000_snapshot.json +1181 -0
- package/.migrations/runtime/meta/0001_snapshot.json +1209 -0
- package/.migrations/runtime/meta/0002_snapshot.json +1261 -0
- package/.migrations/runtime/meta/0003_snapshot.json +1292 -0
- package/.migrations/runtime/meta/0004_snapshot.json +1240 -0
- package/.migrations/runtime/meta/0006_snapshot.json +1310 -0
- package/.migrations/runtime/meta/0007_snapshot.json +1362 -0
- package/.migrations/runtime/meta/0008_snapshot.json +1742 -0
- package/.migrations/runtime/meta/0009_snapshot.json +2413 -0
- package/.migrations/runtime/meta/0010_snapshot.json +2562 -0
- package/.migrations/runtime/meta/0011_snapshot.json +2812 -0
- package/.migrations/runtime/meta/0012_snapshot.json +2812 -0
- package/.migrations/runtime/meta/_journal.json +97 -0
- package/README.md +1583 -2
- package/RELEASING.md +89 -0
- package/agent/fleet.js +100 -0
- package/bin/cli.js +854 -0
- package/bin/manifold.js +4 -0
- package/boot/flow-revival.js +536 -0
- package/budget/index.js +495 -0
- package/budget/lib.js +59 -0
- package/dashboard/cost.js +528 -0
- package/dashboard/dist/assets/index-CUfp63sj.css +1 -0
- package/dashboard/dist/assets/index-Qy9JMpma.js +371 -0
- package/dashboard/dist/index.html +13 -0
- package/dashboard/event-log.js +267 -0
- package/dashboard/index.html +12 -0
- package/dashboard/package-lock.json +2877 -0
- package/dashboard/package.json +37 -0
- package/dashboard/pipeline-graph.js +131 -0
- package/dashboard/postcss.config.js +6 -0
- package/dashboard/search.js +183 -0
- package/dashboard/server.js +1015 -0
- package/dashboard/src/App.tsx +42 -0
- package/dashboard/src/api/client.ts +118 -0
- package/dashboard/src/api/types.ts +510 -0
- package/dashboard/src/api/ws.tsx +112 -0
- package/dashboard/src/components/CancelButton.tsx +63 -0
- package/dashboard/src/components/ClickToCopy.tsx +68 -0
- package/dashboard/src/components/CopyButton.tsx +61 -0
- package/dashboard/src/components/DailyCostTrend.tsx +85 -0
- package/dashboard/src/components/DailyTimeTrend.tsx +94 -0
- package/dashboard/src/components/Funnel.tsx +149 -0
- package/dashboard/src/components/GateForm.tsx +158 -0
- package/dashboard/src/components/GraphView.tsx +302 -0
- package/dashboard/src/components/GroupPathsSummary.tsx +47 -0
- package/dashboard/src/components/Histogram.tsx +292 -0
- package/dashboard/src/components/Layout.tsx +28 -0
- package/dashboard/src/components/NeedsAttention.tsx +98 -0
- package/dashboard/src/components/NodeContextCard.tsx +132 -0
- package/dashboard/src/components/PathTrail.tsx +35 -0
- package/dashboard/src/components/PipelineCostBreakdown.tsx +277 -0
- package/dashboard/src/components/RerunButton.tsx +46 -0
- package/dashboard/src/components/RunComparison.tsx +53 -0
- package/dashboard/src/components/Sparkline.tsx +94 -0
- package/dashboard/src/components/StatStrip.tsx +147 -0
- package/dashboard/src/components/StateTree.tsx +84 -0
- package/dashboard/src/components/StatusBadge.tsx +18 -0
- package/dashboard/src/components/SubflowPathPills.tsx +38 -0
- package/dashboard/src/components/SubflowSummary.tsx +24 -0
- package/dashboard/src/components/SubflowsCard.tsx +327 -0
- package/dashboard/src/components/TodayStrip.tsx +86 -0
- package/dashboard/src/components/TranscriptPane.tsx +99 -0
- package/dashboard/src/components/TranscriptRow.tsx +69 -0
- package/dashboard/src/components/ui/badge.tsx +38 -0
- package/dashboard/src/components/ui/button.tsx +28 -0
- package/dashboard/src/components/ui/card.tsx +42 -0
- package/dashboard/src/components/ui/skeleton.tsx +9 -0
- package/dashboard/src/components/ui/table.tsx +62 -0
- package/dashboard/src/index.css +26 -0
- package/dashboard/src/lib/anomaly.ts +42 -0
- package/dashboard/src/lib/format.ts +30 -0
- package/dashboard/src/lib/step-history.ts +13 -0
- package/dashboard/src/lib/subflow.ts +154 -0
- package/dashboard/src/lib/use-click-outside.ts +28 -0
- package/dashboard/src/lib/use-ignored-clusters.ts +67 -0
- package/dashboard/src/lib/utils.ts +6 -0
- package/dashboard/src/main.tsx +10 -0
- package/dashboard/src/types/shims.d.ts +4 -0
- package/dashboard/src/views/Home.tsx +478 -0
- package/dashboard/src/views/PipelineDetail.tsx +1185 -0
- package/dashboard/src/views/PipelinesList.tsx +111 -0
- package/dashboard/src/views/RunDetail.tsx +248 -0
- package/dashboard/src/views/Search.tsx +196 -0
- package/dashboard/stats.js +668 -0
- package/dashboard/tailwind.config.ts +43 -0
- package/dashboard/tree-stats.js +12 -0
- package/dashboard/tsconfig.json +25 -0
- package/dashboard/views.js +231 -0
- package/dashboard/vite.config.ts +34 -0
- package/drizzle.config.js +12 -0
- package/drizzle.config.ops.js +12 -0
- package/elevation.js +116 -0
- package/engine/admission-promotion-resume.js +127 -0
- package/engine/agent-dispatch.js +64 -0
- package/engine/child-resume-trigger.js +315 -0
- package/engine/executor-budget.js +87 -0
- package/engine/executor-cancel.js +83 -0
- package/engine/executor-errors.js +122 -0
- package/engine/executor-helpers.js +254 -0
- package/engine/executor-nodes.js +292 -0
- package/engine/executor-persist.js +212 -0
- package/engine/executor-subflow-children.js +275 -0
- package/engine/executor.js +1013 -0
- package/engine/global-concurrency.js +33 -0
- package/engine/loader.js +528 -0
- package/engine/needs-resolver.js +229 -0
- package/engine/pipelines-watcher.js +133 -0
- package/engine/result-replay.js +34 -0
- package/engine/revival-messages.js +11 -0
- package/engine/spawn-child.js +55 -0
- package/engine/wait-for-flow-settlement.js +109 -0
- package/events/catalog.js +26 -0
- package/events/emit.js +44 -0
- package/events/kinds.js +118 -0
- package/events/serve-ws.js +74 -0
- package/events/stream.js +35 -0
- package/events/ws-dialog.js +257 -0
- package/events/ws-frame.js +194 -0
- package/events/ws-run-events.js +70 -0
- package/events.js +32 -0
- package/gates/gate-resolver.js +576 -0
- package/gates/paused-flows.js +55 -0
- package/graphql/columns.js +67 -0
- package/graphql/schema.js +333 -0
- package/index.js +49 -0
- package/mcp/http.js +159 -0
- package/mcp/identity.js +94 -0
- package/mcp/stdio.js +80 -0
- package/mcp/tools.js +245 -0
- package/mcp/wire-ops.js +178 -0
- package/package.json +49 -4
- package/routes/bearer-auth.js +57 -0
- package/routes/discuss-audio.js +87 -0
- package/routes/discuss-component.js +39 -0
- package/routes/discuss-draft.js +159 -0
- package/routes/discuss-helpers.js +20 -0
- package/routes/discuss.js +848 -0
- package/routes/failures.js +104 -0
- package/routes/graphql.js +61 -0
- package/routes/health.js +54 -0
- package/routes/operator-discuss.js +193 -0
- package/routes/operator-resume.js +32 -0
- package/routes/operator-retry.js +301 -0
- package/routes/operator.js +539 -0
- package/routes/pipelines.js +118 -0
- package/routes/runs.js +1129 -0
- package/scripts/ci/import-check.mjs +50 -0
- package/scripts/link-core-self.mjs +31 -0
- package/scripts/with-guard.sh +24 -0
- package/server/app.js +503 -0
- package/server/registry.js +53 -0
- package/server/serve.js +163 -0
- package/state/admission-queue-store.js +325 -0
- package/state/attribution-registries.js +102 -0
- package/state/batch-writer.js +162 -0
- package/state/db-guard.js +63 -0
- package/state/db-health.js +27 -0
- package/state/db.js +122 -0
- package/state/discuss-store.js +299 -0
- package/state/failure-store.js +427 -0
- package/state/migrate.js +104 -0
- package/state/node-cost.js +67 -0
- package/state/node-executions.js +775 -0
- package/state/node-health-store.js +124 -0
- package/state/ops-merge.js +93 -0
- package/state/paths.js +146 -0
- package/state/pipeline-dirs.js +99 -0
- package/state/pipeline-registry.js +449 -0
- package/state/run-store.js +697 -0
- package/state/schema.js +438 -0
- package/state/schema.ops.js +44 -0
- package/state/session-index.js +177 -0
- package/state/session-keys.js +39 -0
- package/state/state-store.js +311 -0
- package/state/subflow-state.js +126 -0
- package/state/tool-handoff.js +169 -0
- package/telemetry/budget-alert.js +353 -0
- package/telemetry/cli.js +331 -0
- package/telemetry/grammar.js +119 -0
- package/telemetry/http-budget.js +132 -0
- package/telemetry/http-cost.js +670 -0
- package/telemetry/http-helpers.js +134 -0
- package/telemetry/http-tree.js +349 -0
- package/telemetry/http.js +44 -0
- package/telemetry/index.js +307 -0
- package/telemetry/ingest.js +134 -0
- package/telemetry/labels.js +115 -0
- package/telemetry/pricer.js +77 -0
- package/telemetry/resolver.js +314 -0
- package/telemetry/store.js +147 -0
- package/utils/run-patch.js +43 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// global-concurrency.js — the single shared concurrency ceiling
|
|
2
|
+
// state/admission-queue-store.js reads as its getLimit() — the pool of
|
|
3
|
+
// running flow runs: kind:"child-dispatch" (a subflow child) and
|
|
4
|
+
// kind:"flow-start" (a whole flow run, requested by executor.js's start()
|
|
5
|
+
// and re-requested on every resume from blocked — see engine/child-resume-
|
|
6
|
+
// trigger.js's admitAndSetRunning/flipToRunningAndResume). A run executes
|
|
7
|
+
// one node at a time, so this also bounds concurrent agent dispatches.
|
|
8
|
+
//
|
|
9
|
+
// The only per-pipeline escape hatch is `allowConcurrent: false`, and it is
|
|
10
|
+
// coarse: a singleton gate in executor.js's start() rejects a run outright if
|
|
11
|
+
// another non-terminal run of the same pipelineId exists. There is no way to
|
|
12
|
+
// raise or lower the ceiling for one pipeline — a pipeline needing tighter
|
|
13
|
+
// serialization than this shared number has to be handled by the
|
|
14
|
+
// pipeline author (e.g. via allowConcurrent or node-level guards).
|
|
15
|
+
|
|
16
|
+
const DEFAULT_MAX_CONCURRENT = 8;
|
|
17
|
+
|
|
18
|
+
let maxConcurrent = DEFAULT_MAX_CONCURRENT;
|
|
19
|
+
|
|
20
|
+
// Called once at plugin registration from pluginConfig, if set. A no-op
|
|
21
|
+
// (keeps the current value) for anything not a positive integer.
|
|
22
|
+
export function configureGlobalConcurrency({ maxConcurrent: max } = {}) {
|
|
23
|
+
if (Number.isInteger(max) && max > 0) maxConcurrent = max;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function getGlobalConcurrencyLimit() {
|
|
27
|
+
return maxConcurrent;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Test-only reset (module state is a singleton; tests need a clean slate).
|
|
31
|
+
export function _resetForTests(max = DEFAULT_MAX_CONCURRENT) {
|
|
32
|
+
maxConcurrent = max;
|
|
33
|
+
}
|
package/engine/loader.js
ADDED
|
@@ -0,0 +1,528 @@
|
|
|
1
|
+
// loader.js — discovery of pipeline definition directories.
|
|
2
|
+
|
|
3
|
+
import { readdir, stat, readFile } from "node:fs/promises";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { pathToFileURL } from "node:url";
|
|
6
|
+
import { loadFleet } from "../agent/fleet.js";
|
|
7
|
+
import { ENTRY_FIELDS } from "./needs-resolver.js";
|
|
8
|
+
|
|
9
|
+
// Phase 2: for every subflow node under `nodes`, register its .flow as an
|
|
10
|
+
// addressable pipeline (`${pipelineId}::${nodeId}`) so a real child
|
|
11
|
+
// flow_run can be started against it via the normal
|
|
12
|
+
// executor.start()/pipelinesRef path. Must happen HERE, inside
|
|
13
|
+
// loadPipelines() itself — registering it as a one-off
|
|
14
|
+
// pipelinesRef.value.set(...) elsewhere would be silently dropped on the
|
|
15
|
+
// next pipelines-watcher reload tick, since that merge only preserves
|
|
16
|
+
// stale entries backed by a real on-disk pipeline directory. Own
|
|
17
|
+
// try/catch per node so one bad subflow doesn't block the parent pipeline
|
|
18
|
+
// (already registered by the caller) or any other subflow node at the
|
|
19
|
+
// same nesting level. Renamed from kind:"loop".
|
|
20
|
+
//
|
|
21
|
+
// Recursive (first real nested-subflow site — freelance_workana-reply's
|
|
22
|
+
// REPLY > ENSURE_INFRA): a synthesized child pipeline's own `.nodes` can
|
|
23
|
+
// itself contain a `kind:"subflow"` sub-node (e.g.
|
|
24
|
+
// `freelance_workana-reply::REPLY::ENSURE_INFRA`), whose OWN children won't
|
|
25
|
+
// dispatch correctly unless THAT compound id is registered too —
|
|
26
|
+
// engine/executor-subflow-children.js computes a spawned child's
|
|
27
|
+
// pipelineId as `${state.pipelineId}::${nodeId}`, so a grandchild's
|
|
28
|
+
// pipelineId is exactly this function's own recursive `pipelineId`
|
|
29
|
+
// parameter one level down. No depth limit; genuinely unbounded nesting
|
|
30
|
+
// works the same way arbitrarily deep, though in practice one level is
|
|
31
|
+
// already rare.
|
|
32
|
+
function registerSubflowChildren(pipelineId, nodes, { result, indexPath, pipelineDir, entName, logger }, ancestorNodeMaps = [], proposalMeta = undefined) {
|
|
33
|
+
for (const [nodeId, node] of Object.entries(nodes ?? {})) {
|
|
34
|
+
if (node?.kind !== "subflow") continue;
|
|
35
|
+
const syntheticId = `${pipelineId}::${nodeId}`;
|
|
36
|
+
try {
|
|
37
|
+
// .flow.kind is copied through if declared (e.g. "cascade") onto the
|
|
38
|
+
// synthesized child's own `kind`, which that child's runFlow does
|
|
39
|
+
// read — executor.js's `pipeline.kind === "cascade"` throw path is
|
|
40
|
+
// what gives a cascade-shaped subflow its throw-then-retry-from-start
|
|
41
|
+
// semantics. A plain subflow has no .kind and this is simply
|
|
42
|
+
// undefined, so its dispatch is ordinary.
|
|
43
|
+
const synthetic = { id: syntheticId, kind: node.flow.kind, state: {}, nodes: node.flow.nodes, edges: node.flow.edges };
|
|
44
|
+
// Option B "needs:" — this synthetic child's own hop-1 ancestor is
|
|
45
|
+
// `nodes`, the map that contains the subflow node (nodeId) which
|
|
46
|
+
// spawns it; prepend it onto whatever ancestor chain THIS level was
|
|
47
|
+
// itself given, so a needs:{hops:N} declared anywhere inside the
|
|
48
|
+
// synthetic tree can be checked against a real node map, statically,
|
|
49
|
+
// at load time.
|
|
50
|
+
validatePipeline(synthetic, `${entName}/index.js (${nodeId}.flow)`, [nodes, ...ancestorNodeMaps]);
|
|
51
|
+
// proposalMeta (and any future root-level config a tool looks up by
|
|
52
|
+
// pipelineId) is declared once on the ROOT pipeline's own index.js,
|
|
53
|
+
// never on a subflow's .flow — but a per-item agent node dispatched
|
|
54
|
+
// from inside that subflow resolves its OWN pipelineId as this
|
|
55
|
+
// synthetic child's id (e.g. "freelance_freelancer-proposal::PROPOSE"),
|
|
56
|
+
// not the root's. Without carrying it through here, a tool that keys
|
|
57
|
+
// off pipelinesRef.value.get(pipelineId) would silently miss the
|
|
58
|
+
// root's config for every such dispatch. Threaded recursively so it
|
|
59
|
+
// survives arbitrarily deep nesting too.
|
|
60
|
+
result.set(syntheticId, {
|
|
61
|
+
...synthetic,
|
|
62
|
+
_filepath: indexPath, _dir: pipelineDir, _fleet: null, _synthetic: true,
|
|
63
|
+
_parentPipelineId: pipelineId, _parentNodeId: nodeId,
|
|
64
|
+
...(proposalMeta ? { proposalMeta } : {}),
|
|
65
|
+
});
|
|
66
|
+
logger?.info?.(`manifold loader: registered child-flow pipeline "${syntheticId}"`);
|
|
67
|
+
registerSubflowChildren(syntheticId, node.flow.nodes, { result, indexPath, pipelineDir, entName, logger }, [nodes, ...ancestorNodeMaps], proposalMeta);
|
|
68
|
+
} catch (err) {
|
|
69
|
+
logger?.warn?.(`manifold loader: ${entName}/ node "${nodeId}" subflow branch failed to register: ${err.message}`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Scan a directory for pipeline definitions.
|
|
76
|
+
*
|
|
77
|
+
* Layout: `<pipelinesDir>/<team>_<name>/index.js` (folder per pipeline).
|
|
78
|
+
* Each pipeline folder may also contain `design.md`, `runs.jsonl`, and a
|
|
79
|
+
* `runs/<runId>/` subdirectory for per-run artifacts.
|
|
80
|
+
*
|
|
81
|
+
* Each `index.js` must `export default { id, state, nodes, edges, goal? }`.
|
|
82
|
+
*
|
|
83
|
+
* Returns a Map<pipelineId, pipelineDef> with `_filepath` (the index.js)
|
|
84
|
+
* and `_dir` (the pipeline folder) attached for downstream use.
|
|
85
|
+
*/
|
|
86
|
+
export async function loadPipelines(dir, logger) {
|
|
87
|
+
const result = new Map();
|
|
88
|
+
let entries;
|
|
89
|
+
try {
|
|
90
|
+
entries = await readdir(dir, { withFileTypes: true });
|
|
91
|
+
} catch (err) {
|
|
92
|
+
if (err.code === "ENOENT") {
|
|
93
|
+
logger?.info?.(`manifold loader: pipelines dir not found at ${dir} (no pipelines loaded)`);
|
|
94
|
+
return result;
|
|
95
|
+
}
|
|
96
|
+
logger?.warn?.(`manifold loader: cannot read ${dir}: ${err.message}`);
|
|
97
|
+
return result;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
for (const ent of entries) {
|
|
101
|
+
if (ent.name.startsWith(".")) continue;
|
|
102
|
+
if (!ent.isDirectory()) {
|
|
103
|
+
if (ent.name.endsWith(".js")) {
|
|
104
|
+
logger?.warn?.(`manifold loader: skipping legacy flat-file pipeline ${ent.name}; convert to a folder with index.js`);
|
|
105
|
+
}
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
const pipelineDir = path.join(dir, ent.name);
|
|
109
|
+
const indexPath = path.join(pipelineDir, "index.js");
|
|
110
|
+
try { await stat(indexPath); } catch {
|
|
111
|
+
logger?.warn?.(`manifold loader: ${ent.name}/ has no index.js; skipping`);
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
try {
|
|
115
|
+
// Cache-bust strategy: read the file ourselves and import it as a
|
|
116
|
+
// `data:` URL. The original `?t=Date.now()` query-string approach LOOKS
|
|
117
|
+
// like a unique URL each call, but in Node 25's long-running ESM loader
|
|
118
|
+
// the dynamic-import cache still keys on the file:// path and returns
|
|
119
|
+
// the original module on every subsequent import — verified by
|
|
120
|
+
// debug-logging actual pipeline contents across watcher reloads. data:
|
|
121
|
+
// URLs are uncacheable per-path (each has a unique base64 payload) so
|
|
122
|
+
// editing the source file always yields a fresh module.
|
|
123
|
+
//
|
|
124
|
+
// Relative imports (`from "./lib"`) are rewritten to absolute file://
|
|
125
|
+
// URLs before encoding, so pipeline modules can use normal sibling
|
|
126
|
+
// imports without knowing their install path.
|
|
127
|
+
const source = await readFile(indexPath, "utf8");
|
|
128
|
+
const processed = resolveRelativeImports(source, pipelineDir);
|
|
129
|
+
const url = `data:text/javascript;base64,${Buffer.from(processed).toString("base64")}`;
|
|
130
|
+
const mod = await import(url);
|
|
131
|
+
const pipeline = mod.default ?? mod.pipeline ?? mod;
|
|
132
|
+
validatePipeline(pipeline, `${ent.name}/index.js`);
|
|
133
|
+
if (result.has(pipeline.id)) {
|
|
134
|
+
logger?.warn?.(`manifold loader: duplicate pipeline id "${pipeline.id}" in ${ent.name}/; keeping first`);
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
let _fleet = null;
|
|
138
|
+
try { _fleet = await loadFleet(pipelineDir); } catch {}
|
|
139
|
+
result.set(pipeline.id, { ...pipeline, _filepath: indexPath, _dir: pipelineDir, _fleet });
|
|
140
|
+
logger?.info?.(`manifold loader: loaded pipeline "${pipeline.id}" from ${ent.name}/${_fleet ? " (fleet.yaml found)" : ""}`);
|
|
141
|
+
|
|
142
|
+
// Phase 2: for every subflow node, register its .flow as an
|
|
143
|
+
// addressable pipeline (`${pipeline.id}::${nodeId}`) so a real child
|
|
144
|
+
// flow_run can be started against it via the normal
|
|
145
|
+
// executor.start()/pipelinesRef path. Must happen HERE, inside
|
|
146
|
+
// loadPipelines() itself — registering it as a one-off
|
|
147
|
+
// pipelinesRef.value.set(...) elsewhere would be silently dropped on
|
|
148
|
+
// the next pipelines-watcher reload tick, since that merge only
|
|
149
|
+
// preserves stale entries backed by a real on-disk pipeline
|
|
150
|
+
// directory. Own try/catch per node so one bad subflow doesn't block
|
|
151
|
+
// the parent pipeline (already registered above) or any other
|
|
152
|
+
// subflow node in the same pipeline. Renamed from kind:"loop".
|
|
153
|
+
registerSubflowChildren(pipeline.id, pipeline.nodes, { result, indexPath, pipelineDir, entName: ent.name, logger }, [], pipeline.proposalMeta);
|
|
154
|
+
} catch (err) {
|
|
155
|
+
logger?.warn?.(`manifold loader: ${ent.name}/ failed to load: ${err.message}`);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return result;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Build a memoized `ensurePipelinesLoaded()` for a given `pipelinesRef` box.
|
|
163
|
+
* All callers (the loader service, flow-revival, executor's per-flow
|
|
164
|
+
* fallback) share the SAME in-flight/resolved promise instead of each doing
|
|
165
|
+
* its own `pipelinesRef.value.size > 0` check-then-act — that heuristic let
|
|
166
|
+
* a caller race ahead of another's still-in-flight load, intermittently
|
|
167
|
+
* finding `pipelinesRef.value` empty and starting a redundant load whose
|
|
168
|
+
* completion the original caller never awaited (observed 2026-08-04: orphan
|
|
169
|
+
* flow revival at boot raced the loader service and failed with
|
|
170
|
+
* "pipeline not loaded: <id>" even though pipelines finished loading ~150ms
|
|
171
|
+
* later in the same boot).
|
|
172
|
+
*
|
|
173
|
+
* `load` is injectable for tests; defaults to the real `loadPipelines`.
|
|
174
|
+
*/
|
|
175
|
+
export function createPipelinesLoader(dir, logger, pipelinesRef, { load = loadPipelines } = {}) {
|
|
176
|
+
let pipelinesLoadedPromise = null;
|
|
177
|
+
return function ensurePipelinesLoaded() {
|
|
178
|
+
if (!pipelinesLoadedPromise) {
|
|
179
|
+
pipelinesLoadedPromise = load(dir, logger).then((loaded) => {
|
|
180
|
+
pipelinesRef.value = loaded;
|
|
181
|
+
return loaded;
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
return pipelinesLoadedPromise;
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function validatePipeline(p, filename, ancestorNodeMaps = []) {
|
|
189
|
+
if (!p || typeof p !== "object") throw new Error(`pipeline must export an object`);
|
|
190
|
+
if (!p.id || typeof p.id !== "string") throw new Error(`pipeline ${filename} missing .id`);
|
|
191
|
+
if (!p.state || typeof p.state !== "object") throw new Error(`pipeline ${p.id}: missing .state`);
|
|
192
|
+
if (!p.nodes || typeof p.nodes !== "object") throw new Error(`pipeline ${p.id}: missing .nodes`);
|
|
193
|
+
if (!p.edges || typeof p.edges !== "object") throw new Error(`pipeline ${p.id}: missing .edges`);
|
|
194
|
+
if (!p.edges.__start__) throw new Error(`pipeline ${p.id}: edges must define __start__`);
|
|
195
|
+
|
|
196
|
+
// Track groupIds claimed by subflow nodes so we can catch collisions.
|
|
197
|
+
// Subflow-mode subflows that omit groupId use their nodeId as the implicit key.
|
|
198
|
+
const usedGroupIds = new Map(); // effectiveGroupId → nodeId
|
|
199
|
+
|
|
200
|
+
for (const [nodeId, node] of Object.entries(p.nodes)) {
|
|
201
|
+
if (!node || typeof node !== "object") throw new Error(`pipeline ${p.id}: node "${nodeId}" not an object`);
|
|
202
|
+
if (!node.kind) throw new Error(`pipeline ${p.id}: node "${nodeId}" missing .kind`);
|
|
203
|
+
if (!["code", "agent", "subflow", "human-gate"].includes(node.kind)) {
|
|
204
|
+
throw new Error(`pipeline ${p.id}: node "${nodeId}" has unknown kind "${node.kind}"`);
|
|
205
|
+
}
|
|
206
|
+
validateNeeds(p, `node "${nodeId}"`, node, ancestorNodeMaps);
|
|
207
|
+
if (node.kind === "code") {
|
|
208
|
+
validateCodeKind(p, `node "${nodeId}"`, node);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
if (node.kind === "agent") {
|
|
212
|
+
validateAgentKind(p, `node "${nodeId}"`, node, { allowSkillShorthand: true });
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if (node.kind === "human-gate") {
|
|
216
|
+
if (typeof node.pendingSelector !== "function") {
|
|
217
|
+
throw new Error(`pipeline ${p.id}: node "${nodeId}" (human-gate) missing .pendingSelector function`);
|
|
218
|
+
}
|
|
219
|
+
if (typeof node.approvalRequestBuilder !== "function") {
|
|
220
|
+
throw new Error(`pipeline ${p.id}: node "${nodeId}" (human-gate) missing .approvalRequestBuilder function`);
|
|
221
|
+
}
|
|
222
|
+
// Optional: fired once per decided item, immediately after that
|
|
223
|
+
// item's decision commits (gates/gate-resolver.js's
|
|
224
|
+
// applyResolutionsAndResume) — the root-level-gate counterpart to
|
|
225
|
+
// a subflow's WRITE sub-node, without needing subflow machinery.
|
|
226
|
+
if (node.apply !== undefined && typeof node.apply !== "function") {
|
|
227
|
+
throw new Error(`pipeline ${p.id}: node "${nodeId}" (human-gate) .apply must be a function`);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
if (node.kind === "subflow") {
|
|
232
|
+
// groupId is always the node's own id — a custom groupId would make
|
|
233
|
+
// state/node-executions.js's listInvocationIdsForNode (keyed by the
|
|
234
|
+
// subflow's own node_id, plus branch_key IS NOT NULL to exclude
|
|
235
|
+
// ordinary sub-node timing rows) never find this subflow's children,
|
|
236
|
+
// permanently deadlocking the parent's resume-trigger. Top-level-only
|
|
237
|
+
// check (uniqueness across a nested subflow's own id and some other
|
|
238
|
+
// node's id is not a real collision risk — they live under
|
|
239
|
+
// different flowIds — so this isn't extended into
|
|
240
|
+
// validateSubflowNode's recursive nested-node validation below).
|
|
241
|
+
if (node.groupId !== undefined) {
|
|
242
|
+
throw new Error(`pipeline ${p.id}: node "${nodeId}" (subflow) must not set .groupId — it is always the node's own id`);
|
|
243
|
+
}
|
|
244
|
+
if (usedGroupIds.has(nodeId)) {
|
|
245
|
+
throw new Error(`pipeline ${p.id}: node "${nodeId}" implicit groupId collides with another subflow node using groupId "${nodeId}"`);
|
|
246
|
+
}
|
|
247
|
+
usedGroupIds.set(nodeId, nodeId);
|
|
248
|
+
|
|
249
|
+
// Option B "needs:" — node.flow.nodes' own hop-1 ancestor, once
|
|
250
|
+
// spawned, is this pipeline itself (p.nodes) — prepend it here so
|
|
251
|
+
// nested needs: entries resolve against a real ancestor chain.
|
|
252
|
+
validateSubflowNode(p, `node "${nodeId}"`, node, [p.nodes, ...ancestorNodeMaps]);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// Optional `groups` field — logical groupings of nodes the dashboard
|
|
257
|
+
// renders as compound parents. Each group's `members` array must list
|
|
258
|
+
// existing node ids; a single node cannot belong to more than one group.
|
|
259
|
+
//
|
|
260
|
+
// Members may be either:
|
|
261
|
+
// - top-level node ids (e.g. "SCAN_CODE"), or
|
|
262
|
+
// - qualified branch-internal ids (e.g. "PROPOSE.SUBMIT_CODE") where
|
|
263
|
+
// "PROPOSE" is a subflow node and "SUBMIT_CODE" lives in
|
|
264
|
+
// that node's flow.nodes. The dashboard renders these as a
|
|
265
|
+
// compound nested inside the subflow node's own compound.
|
|
266
|
+
//
|
|
267
|
+
// Mixing scopes inside a single group is forbidden — every member of a
|
|
268
|
+
// group must live in the same scope (all top-level, or all inside the
|
|
269
|
+
// same subflow). Cytoscape compound nodes can only have
|
|
270
|
+
// one parent, so a group's compound has to live entirely in one scope.
|
|
271
|
+
if (p.groups !== undefined) {
|
|
272
|
+
if (typeof p.groups !== "object" || Array.isArray(p.groups)) {
|
|
273
|
+
throw new Error(`pipeline ${p.id}: .groups must be an object`);
|
|
274
|
+
}
|
|
275
|
+
const membership = new Map();
|
|
276
|
+
for (const [groupId, group] of Object.entries(p.groups)) {
|
|
277
|
+
if (!group || typeof group !== "object") {
|
|
278
|
+
throw new Error(`pipeline ${p.id}: group "${groupId}" must be an object`);
|
|
279
|
+
}
|
|
280
|
+
if (!Array.isArray(group.members) || group.members.length === 0) {
|
|
281
|
+
throw new Error(`pipeline ${p.id}: group "${groupId}" must have a non-empty .members array`);
|
|
282
|
+
}
|
|
283
|
+
let scopeParent = null; // null = top-level; otherwise the subflow node id
|
|
284
|
+
for (const m of group.members) {
|
|
285
|
+
if (typeof m !== "string") {
|
|
286
|
+
throw new Error(`pipeline ${p.id}: group "${groupId}" member must be a string, got ${typeof m}`);
|
|
287
|
+
}
|
|
288
|
+
const dot = m.indexOf(".");
|
|
289
|
+
let memberScope = null;
|
|
290
|
+
if (dot === -1) {
|
|
291
|
+
if (!(m in p.nodes)) {
|
|
292
|
+
throw new Error(`pipeline ${p.id}: group "${groupId}" member "${m}" not found in .nodes`);
|
|
293
|
+
}
|
|
294
|
+
} else {
|
|
295
|
+
const parent = m.slice(0, dot);
|
|
296
|
+
const child = m.slice(dot + 1);
|
|
297
|
+
const parentNode = p.nodes[parent];
|
|
298
|
+
if (!parentNode) {
|
|
299
|
+
throw new Error(`pipeline ${p.id}: group "${groupId}" member "${m}" references unknown parent "${parent}"`);
|
|
300
|
+
}
|
|
301
|
+
if (parentNode.kind !== "subflow") {
|
|
302
|
+
throw new Error(`pipeline ${p.id}: group "${groupId}" member "${m}" — parent "${parent}" is "${parentNode.kind}", expected "subflow"`);
|
|
303
|
+
}
|
|
304
|
+
if (!parentNode.flow?.nodes || !(child in parentNode.flow.nodes)) {
|
|
305
|
+
throw new Error(`pipeline ${p.id}: group "${groupId}" member "${m}" — child "${child}" not in flow.nodes of "${parent}"`);
|
|
306
|
+
}
|
|
307
|
+
memberScope = parent;
|
|
308
|
+
}
|
|
309
|
+
if (scopeParent === null && memberScope !== null) scopeParent = memberScope;
|
|
310
|
+
else if (memberScope !== scopeParent) {
|
|
311
|
+
throw new Error(`pipeline ${p.id}: group "${groupId}" mixes scopes — members must all be top-level or all inside the same subflow`);
|
|
312
|
+
}
|
|
313
|
+
if (membership.has(m)) {
|
|
314
|
+
throw new Error(`pipeline ${p.id}: node "${m}" is in multiple groups ("${membership.get(m)}" and "${groupId}")`);
|
|
315
|
+
}
|
|
316
|
+
membership.set(m, groupId);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
// Option B "needs:" — any code/agent/subflow node, top-level or nested,
|
|
323
|
+
// may declare `.needs: { varName: {hops, nodeId}, ... }` — keyed by the
|
|
324
|
+
// LOCAL variable name it'll be resolved as via ctx.needs(varName), not by
|
|
325
|
+
// nodeId, so it reads like an ORM relation declaration rather than a bare
|
|
326
|
+
// fetch list.
|
|
327
|
+
// Validated here (not at runtime, per this codebase's own load-time-
|
|
328
|
+
// validation convention — see the analogous groups/.members check below)
|
|
329
|
+
// using `ancestorNodeMaps`, threaded down from validatePipeline/register
|
|
330
|
+
// SubflowChildren: since a subflow's synthetic childPipelineId is always
|
|
331
|
+
// `${parentPipelineId}::${nodeId}`, chained at every nesting level, the
|
|
332
|
+
// FULL ancestor chain of real node maps is statically knowable at load
|
|
333
|
+
// time — a needs: entry naming a hop that doesn't exist, or a nodeId that
|
|
334
|
+
// doesn't exist at that ancestor level, throws here rather than resolving
|
|
335
|
+
// to a silent runtime "not-found" indistinguishable from a race.
|
|
336
|
+
//
|
|
337
|
+
// A spec names EXACTLY ONE of `nodeId` (an ancestor's own node output) or
|
|
338
|
+
// `entry` (an ancestor flow's own entry/bookkeeping field — runId, args,
|
|
339
|
+
// etc., set at that flow's start(), never via any node's resultJson).
|
|
340
|
+
// `entry` is checked against ENTRY_FIELDS (needs-resolver.js) — `gates` is
|
|
341
|
+
// deliberately not on that list even though it's a real stateJson key; it
|
|
342
|
+
// has its own dedicated accessor (gate_records) precisely because reading
|
|
343
|
+
// it through the generic needs: path reopens a real bug that mechanism
|
|
344
|
+
// was built to close. An `entry`-type need still needs the same hop-depth
|
|
345
|
+
// check as a `nodeId`-type one (does the pipeline nest that deep at all)
|
|
346
|
+
// but skips the node-existence check, since it isn't naming a node.
|
|
347
|
+
//
|
|
348
|
+
// human-gate is deliberately excluded — ctx.needs() isn't wired into
|
|
349
|
+
// pendingSelector/approvalRequestBuilder yet (no real use case surfaced),
|
|
350
|
+
// so a human-gate node declaring .needs would validate fine and then have
|
|
351
|
+
// no way to ever call it — throwing here is louder and more honest than
|
|
352
|
+
// silently accepting something inert.
|
|
353
|
+
function validateNeeds(p, label, node, ancestorNodeMaps) {
|
|
354
|
+
if (node.needs === undefined) return;
|
|
355
|
+
if (node.kind === "human-gate") {
|
|
356
|
+
throw new Error(`pipeline ${p.id}: ${label} (human-gate) .needs is not yet supported — ctx.needs() is not wired into pendingSelector/approvalRequestBuilder`);
|
|
357
|
+
}
|
|
358
|
+
if (typeof node.needs !== "object" || node.needs === null || Array.isArray(node.needs)) {
|
|
359
|
+
throw new Error(`pipeline ${p.id}: ${label} .needs must be an object keyed by variable name: { varName: {hops, nodeId} }`);
|
|
360
|
+
}
|
|
361
|
+
for (const [varName, need] of Object.entries(node.needs)) {
|
|
362
|
+
if (!need || typeof need !== "object") {
|
|
363
|
+
throw new Error(`pipeline ${p.id}: ${label} .needs.${varName} must be an object {hops, nodeId}, {hops, entry}, or {hops, config}`);
|
|
364
|
+
}
|
|
365
|
+
const { hops, nodeId, entry, config } = need;
|
|
366
|
+
// hops:0 = same-flow (the declaring node's own flow — always exists,
|
|
367
|
+
// no nesting-depth check needed). hops>=1 = walk that many parent
|
|
368
|
+
// flows up, same as before.
|
|
369
|
+
if (!Number.isInteger(hops) || hops < 0) {
|
|
370
|
+
throw new Error(`pipeline ${p.id}: ${label} .needs.${varName}.hops must be a non-negative integer, got ${JSON.stringify(hops)}`);
|
|
371
|
+
}
|
|
372
|
+
const declared = [nodeId !== undefined, entry !== undefined, config !== undefined].filter(Boolean).length;
|
|
373
|
+
if (declared !== 1) {
|
|
374
|
+
throw new Error(`pipeline ${p.id}: ${label} .needs.${varName} must declare exactly one of .nodeId, .entry, or .config`);
|
|
375
|
+
}
|
|
376
|
+
if (nodeId !== undefined && (typeof nodeId !== "string" || !nodeId)) {
|
|
377
|
+
throw new Error(`pipeline ${p.id}: ${label} .needs.${varName}.nodeId must be a non-empty string`);
|
|
378
|
+
}
|
|
379
|
+
if (entry !== undefined && !ENTRY_FIELDS.has(entry)) {
|
|
380
|
+
throw new Error(`pipeline ${p.id}: ${label} .needs.${varName}.entry "${entry}" is not a recognized entry/bookkeeping field — see needs-resolver.js's ENTRY_FIELDS`);
|
|
381
|
+
}
|
|
382
|
+
// config isn't checkable against the target pipeline's own `state:`
|
|
383
|
+
// keys at load time the way entry/nodeId are — pipelines can load in
|
|
384
|
+
// any order and `state:` declares no schema. Just require a non-empty
|
|
385
|
+
// string; an unknown key resolves to `undefined` at runtime, same as
|
|
386
|
+
// reading a missing object property anywhere else in this codebase.
|
|
387
|
+
if (config !== undefined && (typeof config !== "string" || !config)) {
|
|
388
|
+
throw new Error(`pipeline ${p.id}: ${label} .needs.${varName}.config must be a non-empty string`);
|
|
389
|
+
}
|
|
390
|
+
if (need.fields !== undefined && (!Array.isArray(need.fields) || need.fields.length === 0 || !need.fields.every((f) => typeof f === "string" && f))) {
|
|
391
|
+
throw new Error(`pipeline ${p.id}: ${label} .needs.${varName}.fields must be a non-empty array of non-empty strings — always an array, even for a single field`);
|
|
392
|
+
}
|
|
393
|
+
if (hops === 0) {
|
|
394
|
+
if (nodeId !== undefined && !(nodeId in p.nodes)) {
|
|
395
|
+
throw new Error(`pipeline ${p.id}: ${label} needs.${varName} {hops:0, nodeId:"${nodeId}"} — no node "${nodeId}" in this pipeline`);
|
|
396
|
+
}
|
|
397
|
+
continue;
|
|
398
|
+
}
|
|
399
|
+
const ancestorMap = ancestorNodeMaps[hops - 1];
|
|
400
|
+
if (!ancestorMap) {
|
|
401
|
+
throw new Error(`pipeline ${p.id}: ${label} needs.${varName} {hops:${hops}} but this node's pipeline nesting doesn't go that deep`);
|
|
402
|
+
}
|
|
403
|
+
if (nodeId !== undefined && !(nodeId in ancestorMap)) {
|
|
404
|
+
throw new Error(`pipeline ${p.id}: ${label} needs.${varName} {hops:${hops}, nodeId:"${nodeId}"} — no node "${nodeId}" at that ancestor level`);
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
function validateCodeKind(p, label, obj) {
|
|
410
|
+
if (typeof obj.run !== "function") {
|
|
411
|
+
throw new Error(`pipeline ${p.id}: ${label} (code) missing .run function`);
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
// Shared shape validation for a kind:"subflow" node, called both for a
|
|
416
|
+
// top-level node and recursively for a nested one (a `flow.nodes` entry
|
|
417
|
+
// that is itself kind:"subflow" — first real site: freelance_workana-
|
|
418
|
+
// reply's REPLY > ENSURE_INFRA). `label` is already the caller's fully
|
|
419
|
+
// qualified prefix (e.g. `node "REPLY"` or `node "REPLY".flow.nodes.
|
|
420
|
+
// "ENSURE_INFRA"`), so nesting composes into a readable dotted path
|
|
421
|
+
// automatically. groupId-uniqueness is NOT checked here — see the
|
|
422
|
+
// top-level call site's own comment for why that stays top-level-only.
|
|
423
|
+
function validateSubflowNode(p, label, node, ancestorNodeMaps) {
|
|
424
|
+
if (typeof node.selector !== "function") {
|
|
425
|
+
throw new Error(`pipeline ${p.id}: ${label} (subflow) missing .selector function`);
|
|
426
|
+
}
|
|
427
|
+
// Required, not defaulted — a subflow node's children going terminal
|
|
428
|
+
// resumes the parent regardless of success/failure unless mode says
|
|
429
|
+
// otherwise (see child-resume-trigger.js's maybeResumeParent), so every
|
|
430
|
+
// author has to pick a propagation policy explicitly rather than
|
|
431
|
+
// silently inheriting "never fails the parent."
|
|
432
|
+
if (node.mode !== "any" && node.mode !== "all") {
|
|
433
|
+
throw new Error(`pipeline ${p.id}: ${label} (subflow) requires .mode to be "any" or "all"`);
|
|
434
|
+
}
|
|
435
|
+
// Every subflow node's items become real flow_runs children — requires a
|
|
436
|
+
// .flow definition (.flow.nodes/.edges); there is no other subflow shape,
|
|
437
|
+
// the old branch-worker engine having been deleted outright. Renamed from
|
|
438
|
+
// kind:"loop" — a selector returning a single-item array is the
|
|
439
|
+
// degenerate "spawn exactly one child" case, not a different kind.
|
|
440
|
+
if (!node.flow) {
|
|
441
|
+
throw new Error(`pipeline ${p.id}: ${label} (subflow) requires .flow (.flow.nodes/.edges)`);
|
|
442
|
+
}
|
|
443
|
+
if (!node.flow.nodes || typeof node.flow.nodes !== "object") {
|
|
444
|
+
throw new Error(`pipeline ${p.id}: ${label} .flow missing .nodes`);
|
|
445
|
+
}
|
|
446
|
+
if (!node.flow.edges || typeof node.flow.edges !== "object") {
|
|
447
|
+
throw new Error(`pipeline ${p.id}: ${label} .flow missing .edges`);
|
|
448
|
+
}
|
|
449
|
+
if (!node.flow.edges.__start__) {
|
|
450
|
+
throw new Error(`pipeline ${p.id}: ${label} .flow.edges must define __start__`);
|
|
451
|
+
}
|
|
452
|
+
validateFlowSubNodes(p, label, node.flow.nodes, ancestorNodeMaps);
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
// The `for (const [subId, sub] of ...)` loop over one subflow's
|
|
456
|
+
// flow.nodes, shared between the top-level subflow branch and
|
|
457
|
+
// validateSubflowNode's own recursive nested case. `sub.kind ===
|
|
458
|
+
// "subflow"` recurses back into validateSubflowNode — arbitrarily deep
|
|
459
|
+
// nesting validates the same way at every level.
|
|
460
|
+
function validateFlowSubNodes(p, label, flowNodes, ancestorNodeMaps = []) {
|
|
461
|
+
for (const [subId, sub] of Object.entries(flowNodes)) {
|
|
462
|
+
const subLabel = `${label}.flow.nodes."${subId}"`;
|
|
463
|
+
if (!sub || typeof sub !== "object") {
|
|
464
|
+
throw new Error(`pipeline ${p.id}: ${subLabel} not an object`);
|
|
465
|
+
}
|
|
466
|
+
if (!sub.kind) {
|
|
467
|
+
throw new Error(`pipeline ${p.id}: ${subLabel} missing .kind`);
|
|
468
|
+
}
|
|
469
|
+
if (!["code", "agent", "subflow", "human-gate"].includes(sub.kind)) {
|
|
470
|
+
throw new Error(`pipeline ${p.id}: ${subLabel} has unknown kind "${sub.kind}"`);
|
|
471
|
+
}
|
|
472
|
+
validateNeeds(p, subLabel, sub, ancestorNodeMaps);
|
|
473
|
+
if (sub.kind === "agent") {
|
|
474
|
+
validateAgentKind(p, subLabel, sub, { allowSkillShorthand: false });
|
|
475
|
+
}
|
|
476
|
+
if (sub.kind === "subflow") {
|
|
477
|
+
// Same pattern as the top-level loop: sub.flow.nodes' own hop-1
|
|
478
|
+
// ancestor, once spawned, is `flowNodes` (the map sub itself lives
|
|
479
|
+
// in) — prepend it before recursing.
|
|
480
|
+
validateSubflowNode(p, subLabel, sub, [flowNodes, ...ancestorNodeMaps]);
|
|
481
|
+
}
|
|
482
|
+
if (sub.kind === "human-gate") {
|
|
483
|
+
// A child is an ordinary flow — its gate sub-nodes need the
|
|
484
|
+
// same shape a root-level human-gate node does.
|
|
485
|
+
if (typeof sub.pendingSelector !== "function") {
|
|
486
|
+
throw new Error(`pipeline ${p.id}: ${subLabel} (human-gate) missing .pendingSelector function`);
|
|
487
|
+
}
|
|
488
|
+
if (typeof sub.approvalRequestBuilder !== "function") {
|
|
489
|
+
throw new Error(`pipeline ${p.id}: ${subLabel} (human-gate) missing .approvalRequestBuilder function`);
|
|
490
|
+
}
|
|
491
|
+
// Optional, same as the root-level human-gate check above.
|
|
492
|
+
if (sub.apply !== undefined && typeof sub.apply !== "function") {
|
|
493
|
+
throw new Error(`pipeline ${p.id}: ${subLabel} (human-gate) .apply must be a function`);
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
function validateAgentKind(p, label, obj, { allowSkillShorthand }) {
|
|
500
|
+
// Top-level agent nodes accept a `skill` shorthand string in place of
|
|
501
|
+
// `.promptBuilder`; subflow sub-nodes don't.
|
|
502
|
+
if (allowSkillShorthand) {
|
|
503
|
+
if (typeof obj.promptBuilder !== "function" && typeof obj.skill !== "string") {
|
|
504
|
+
throw new Error(`pipeline ${p.id}: ${label} (agent) missing .promptBuilder function`);
|
|
505
|
+
}
|
|
506
|
+
} else if (typeof obj.promptBuilder !== "function") {
|
|
507
|
+
throw new Error(`pipeline ${p.id}: ${label} (agent) missing .promptBuilder function`);
|
|
508
|
+
}
|
|
509
|
+
if (typeof obj.apply !== "function" && typeof obj.applyResult !== "function") {
|
|
510
|
+
throw new Error(`pipeline ${p.id}: ${label} (agent) missing .apply function`);
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
// Replace relative import specifiers (`from "./lib"`, `from "../shared"`,
|
|
515
|
+
// and dynamic `import("./file")`) with absolute file:// URLs so pipeline
|
|
516
|
+
// modules loaded via data: URLs can import sibling files normally.
|
|
517
|
+
function resolveRelativeImports(source, dir) {
|
|
518
|
+
const dirUrl = pathToFileURL(dir + "/").href;
|
|
519
|
+
return source
|
|
520
|
+
.replace(
|
|
521
|
+
/(\bfrom\s+["'])(\.\.?\/[^"']+)(["'])/g,
|
|
522
|
+
(_, prefix, rel, suffix) => `${prefix}${new URL(rel, dirUrl).href}${suffix}`,
|
|
523
|
+
)
|
|
524
|
+
.replace(
|
|
525
|
+
/(\bimport\s*\(\s*["'])(\.\.?\/[^"']+)(["']\s*\))/g,
|
|
526
|
+
(_, prefix, rel, suffix) => `${prefix}${new URL(rel, dirUrl).href}${suffix}`,
|
|
527
|
+
);
|
|
528
|
+
}
|