@igorjpimenta/manifold 0.0.0-bootstrap.1 → 0.0.0-stage
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 +2 -1583
- package/package.json +4 -49
- package/.migrations/ops/0000_futuristic_karma.sql +0 -111
- package/.migrations/ops/0001_low_maximus.sql +0 -7
- package/.migrations/ops/meta/0000_snapshot.json +0 -763
- package/.migrations/ops/meta/0001_snapshot.json +0 -173
- package/.migrations/ops/meta/_journal.json +0 -20
- package/.migrations/runtime/0000_real_boomer.sql +0 -180
- package/.migrations/runtime/0001_hot_dakota_north.sql +0 -2
- package/.migrations/runtime/0002_breezy_vertigo.sql +0 -8
- package/.migrations/runtime/0003_dashing_jack_flag.sql +0 -5
- package/.migrations/runtime/0004_panoramic_ego.sql +0 -1
- package/.migrations/runtime/0005_tidy_ben_grimm.sql +0 -10
- package/.migrations/runtime/0006_wet_nightmare.sql +0 -57
- package/.migrations/runtime/0007_ambiguous_chronomancer.sql +0 -8
- package/.migrations/runtime/0008_wealthy_thundra.sql +0 -301
- package/.migrations/runtime/0009_lying_shocker.sql +0 -96
- package/.migrations/runtime/0010_solid_phantom_reporter.sql +0 -160
- package/.migrations/runtime/0011_windy_demogoblin.sql +0 -175
- package/.migrations/runtime/0012_restore_harness_fks.sql +0 -103
- package/.migrations/runtime/meta/0000_snapshot.json +0 -1181
- package/.migrations/runtime/meta/0001_snapshot.json +0 -1209
- package/.migrations/runtime/meta/0002_snapshot.json +0 -1261
- package/.migrations/runtime/meta/0003_snapshot.json +0 -1292
- package/.migrations/runtime/meta/0004_snapshot.json +0 -1240
- package/.migrations/runtime/meta/0006_snapshot.json +0 -1310
- package/.migrations/runtime/meta/0007_snapshot.json +0 -1362
- package/.migrations/runtime/meta/0008_snapshot.json +0 -1742
- package/.migrations/runtime/meta/0009_snapshot.json +0 -2413
- package/.migrations/runtime/meta/0010_snapshot.json +0 -2562
- package/.migrations/runtime/meta/0011_snapshot.json +0 -2812
- package/.migrations/runtime/meta/0012_snapshot.json +0 -2812
- package/.migrations/runtime/meta/_journal.json +0 -97
- package/RELEASING.md +0 -89
- package/agent/fleet.js +0 -100
- package/bin/cli.js +0 -854
- package/bin/manifold.js +0 -4
- package/boot/flow-revival.js +0 -536
- package/budget/index.js +0 -495
- package/budget/lib.js +0 -59
- package/dashboard/cost.js +0 -528
- package/dashboard/dist/assets/index-CUfp63sj.css +0 -1
- package/dashboard/dist/assets/index-Qy9JMpma.js +0 -371
- package/dashboard/dist/index.html +0 -13
- package/dashboard/event-log.js +0 -267
- package/dashboard/index.html +0 -12
- package/dashboard/package-lock.json +0 -2877
- package/dashboard/package.json +0 -37
- package/dashboard/pipeline-graph.js +0 -131
- package/dashboard/postcss.config.js +0 -6
- package/dashboard/search.js +0 -183
- package/dashboard/server.js +0 -1015
- package/dashboard/src/App.tsx +0 -42
- package/dashboard/src/api/client.ts +0 -118
- package/dashboard/src/api/types.ts +0 -510
- package/dashboard/src/api/ws.tsx +0 -112
- package/dashboard/src/components/CancelButton.tsx +0 -63
- package/dashboard/src/components/ClickToCopy.tsx +0 -68
- package/dashboard/src/components/CopyButton.tsx +0 -61
- package/dashboard/src/components/DailyCostTrend.tsx +0 -85
- package/dashboard/src/components/DailyTimeTrend.tsx +0 -94
- package/dashboard/src/components/Funnel.tsx +0 -149
- package/dashboard/src/components/GateForm.tsx +0 -158
- package/dashboard/src/components/GraphView.tsx +0 -302
- package/dashboard/src/components/GroupPathsSummary.tsx +0 -47
- package/dashboard/src/components/Histogram.tsx +0 -292
- package/dashboard/src/components/Layout.tsx +0 -28
- package/dashboard/src/components/NeedsAttention.tsx +0 -98
- package/dashboard/src/components/NodeContextCard.tsx +0 -132
- package/dashboard/src/components/PathTrail.tsx +0 -35
- package/dashboard/src/components/PipelineCostBreakdown.tsx +0 -277
- package/dashboard/src/components/RerunButton.tsx +0 -46
- package/dashboard/src/components/RunComparison.tsx +0 -53
- package/dashboard/src/components/Sparkline.tsx +0 -94
- package/dashboard/src/components/StatStrip.tsx +0 -147
- package/dashboard/src/components/StateTree.tsx +0 -84
- package/dashboard/src/components/StatusBadge.tsx +0 -18
- package/dashboard/src/components/SubflowPathPills.tsx +0 -38
- package/dashboard/src/components/SubflowSummary.tsx +0 -24
- package/dashboard/src/components/SubflowsCard.tsx +0 -327
- package/dashboard/src/components/TodayStrip.tsx +0 -86
- package/dashboard/src/components/TranscriptPane.tsx +0 -99
- package/dashboard/src/components/TranscriptRow.tsx +0 -69
- package/dashboard/src/components/ui/badge.tsx +0 -38
- package/dashboard/src/components/ui/button.tsx +0 -28
- package/dashboard/src/components/ui/card.tsx +0 -42
- package/dashboard/src/components/ui/skeleton.tsx +0 -9
- package/dashboard/src/components/ui/table.tsx +0 -62
- package/dashboard/src/index.css +0 -26
- package/dashboard/src/lib/anomaly.ts +0 -42
- package/dashboard/src/lib/format.ts +0 -30
- package/dashboard/src/lib/step-history.ts +0 -13
- package/dashboard/src/lib/subflow.ts +0 -154
- package/dashboard/src/lib/use-click-outside.ts +0 -28
- package/dashboard/src/lib/use-ignored-clusters.ts +0 -67
- package/dashboard/src/lib/utils.ts +0 -6
- package/dashboard/src/main.tsx +0 -10
- package/dashboard/src/types/shims.d.ts +0 -4
- package/dashboard/src/views/Home.tsx +0 -478
- package/dashboard/src/views/PipelineDetail.tsx +0 -1185
- package/dashboard/src/views/PipelinesList.tsx +0 -111
- package/dashboard/src/views/RunDetail.tsx +0 -248
- package/dashboard/src/views/Search.tsx +0 -196
- package/dashboard/stats.js +0 -668
- package/dashboard/tailwind.config.ts +0 -43
- package/dashboard/tree-stats.js +0 -12
- package/dashboard/tsconfig.json +0 -25
- package/dashboard/views.js +0 -231
- package/dashboard/vite.config.ts +0 -34
- package/drizzle.config.js +0 -12
- package/drizzle.config.ops.js +0 -12
- package/elevation.js +0 -116
- package/engine/admission-promotion-resume.js +0 -127
- package/engine/agent-dispatch.js +0 -64
- package/engine/child-resume-trigger.js +0 -315
- package/engine/executor-budget.js +0 -87
- package/engine/executor-cancel.js +0 -83
- package/engine/executor-errors.js +0 -122
- package/engine/executor-helpers.js +0 -254
- package/engine/executor-nodes.js +0 -292
- package/engine/executor-persist.js +0 -212
- package/engine/executor-subflow-children.js +0 -275
- package/engine/executor.js +0 -1013
- package/engine/global-concurrency.js +0 -33
- package/engine/loader.js +0 -528
- package/engine/needs-resolver.js +0 -229
- package/engine/pipelines-watcher.js +0 -133
- package/engine/result-replay.js +0 -34
- package/engine/revival-messages.js +0 -11
- package/engine/spawn-child.js +0 -55
- package/engine/wait-for-flow-settlement.js +0 -109
- package/events/catalog.js +0 -26
- package/events/emit.js +0 -44
- package/events/kinds.js +0 -118
- package/events/serve-ws.js +0 -74
- package/events/stream.js +0 -35
- package/events/ws-dialog.js +0 -257
- package/events/ws-frame.js +0 -194
- package/events/ws-run-events.js +0 -70
- package/events.js +0 -32
- package/gates/gate-resolver.js +0 -576
- package/gates/paused-flows.js +0 -55
- package/graphql/columns.js +0 -67
- package/graphql/schema.js +0 -333
- package/index.js +0 -49
- package/mcp/http.js +0 -159
- package/mcp/identity.js +0 -94
- package/mcp/stdio.js +0 -80
- package/mcp/tools.js +0 -245
- package/mcp/wire-ops.js +0 -178
- package/routes/bearer-auth.js +0 -57
- package/routes/discuss-audio.js +0 -87
- package/routes/discuss-component.js +0 -39
- package/routes/discuss-draft.js +0 -159
- package/routes/discuss-helpers.js +0 -20
- package/routes/discuss.js +0 -848
- package/routes/failures.js +0 -104
- package/routes/graphql.js +0 -61
- package/routes/health.js +0 -54
- package/routes/operator-discuss.js +0 -193
- package/routes/operator-resume.js +0 -32
- package/routes/operator-retry.js +0 -301
- package/routes/operator.js +0 -539
- package/routes/pipelines.js +0 -118
- package/routes/runs.js +0 -1129
- package/scripts/ci/import-check.mjs +0 -50
- package/scripts/link-core-self.mjs +0 -31
- package/scripts/with-guard.sh +0 -24
- package/server/app.js +0 -503
- package/server/registry.js +0 -53
- package/server/serve.js +0 -163
- package/state/admission-queue-store.js +0 -325
- package/state/attribution-registries.js +0 -102
- package/state/batch-writer.js +0 -162
- package/state/db-guard.js +0 -63
- package/state/db-health.js +0 -27
- package/state/db.js +0 -122
- package/state/discuss-store.js +0 -299
- package/state/failure-store.js +0 -427
- package/state/migrate.js +0 -104
- package/state/node-cost.js +0 -67
- package/state/node-executions.js +0 -775
- package/state/node-health-store.js +0 -124
- package/state/ops-merge.js +0 -93
- package/state/paths.js +0 -146
- package/state/pipeline-dirs.js +0 -99
- package/state/pipeline-registry.js +0 -449
- package/state/run-store.js +0 -697
- package/state/schema.js +0 -438
- package/state/schema.ops.js +0 -44
- package/state/session-index.js +0 -177
- package/state/session-keys.js +0 -39
- package/state/state-store.js +0 -311
- package/state/subflow-state.js +0 -126
- package/state/tool-handoff.js +0 -169
- package/telemetry/budget-alert.js +0 -353
- package/telemetry/cli.js +0 -331
- package/telemetry/grammar.js +0 -119
- package/telemetry/http-budget.js +0 -132
- package/telemetry/http-cost.js +0 -670
- package/telemetry/http-helpers.js +0 -134
- package/telemetry/http-tree.js +0 -349
- package/telemetry/http.js +0 -44
- package/telemetry/index.js +0 -307
- package/telemetry/ingest.js +0 -134
- package/telemetry/labels.js +0 -115
- package/telemetry/pricer.js +0 -77
- package/telemetry/resolver.js +0 -314
- package/telemetry/store.js +0 -147
- package/utils/run-patch.js +0 -43
package/bin/cli.js
DELETED
|
@@ -1,854 +0,0 @@
|
|
|
1
|
-
// cli.js — both CLI surfaces in one module: runCli(argv) serves MCP/WS
|
|
2
|
-
// in a standalone process (bin/manifold.js's thin
|
|
3
|
-
// entry calls it), and registerCliCommands(...) registers the
|
|
4
|
-
// `openclaw manifold` subcommands on the gateway's commander program.
|
|
5
|
-
// Neither surface imports the openclaw SDK, so this module loads under
|
|
6
|
-
// plain node for standalone use and node:test.
|
|
7
|
-
import { loadPipelines } from "../engine/loader.js";
|
|
8
|
-
import { resolveStorePaths } from "../state/paths.js";
|
|
9
|
-
import { listPaused, pause as pauseFlow, resume as resumeFlow } from "../gates/paused-flows.js";
|
|
10
|
-
import { createGateResolver } from "../gates/gate-resolver.js";
|
|
11
|
-
import { spawn } from "node:child_process";
|
|
12
|
-
import { getNodeExecutionsStore } from "../state/node-executions.js";
|
|
13
|
-
import { TERMINAL_STATUS_SET } from "../state/run-store.js";
|
|
14
|
-
import { createFailureStore } from "../state/failure-store.js";
|
|
15
|
-
import { createRetryFailure } from "../routes/operator-retry.js";
|
|
16
|
-
import { waitForFlowSettlement } from "../engine/wait-for-flow-settlement.js";
|
|
17
|
-
import { flipToRunningAndResume } from "../engine/child-resume-trigger.js";
|
|
18
|
-
import { wakePromotedRelease, drainDetachedResumes } from "../engine/admission-promotion-resume.js";
|
|
19
|
-
import { parseArgs } from "node:util";
|
|
20
|
-
import { startMcpServer } from "../mcp/stdio.js";
|
|
21
|
-
import { createRealOps } from "../mcp/wire-ops.js";
|
|
22
|
-
import { createEventStream } from "../events/stream.js";
|
|
23
|
-
import { startWsServer, DEFAULT_WS_PORT } from "../events/serve-ws.js";
|
|
24
|
-
|
|
25
|
-
// cli.js — registers the `openclaw manifold <subcommand>` CLI surface.
|
|
26
|
-
//
|
|
27
|
-
// IMPORTANT: CLI handlers run in a separate openclaw process from the gateway,
|
|
28
|
-
// so the `pipelinesRef` populated by the gateway's loader-service is NOT
|
|
29
|
-
// visible here. Every CLI handler that needs pipeline definitions must
|
|
30
|
-
// re-load them from disk on demand via ensurePipelinesLoaded(). Similarly,
|
|
31
|
-
// the executor loop runs in-process here (sync await), so CLI commands
|
|
32
|
-
// `start`, `rerun`, `retry`, and `approve` all block until the flow reaches
|
|
33
|
-
// terminal or blocked.
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
// Precedence: explicit --pipelines-dir flag wins, then the adapter seam
|
|
37
|
-
// (resolvePipelinesDir: table -> env -> config -> default), then the store
|
|
38
|
-
// seam (resolveStorePaths().pipelinesDir, honoring MANIFOLD_PIPELINES_DIR).
|
|
39
|
-
// Throws when nothing resolves — callers fail loudly naming the flag/env
|
|
40
|
-
// instead of silently falling back to a harness layout.
|
|
41
|
-
export function resolveCliPipelinesDir({ flagDir = null, resolvePipelinesDir = null, storePaths = null, env = process.env } = {}) {
|
|
42
|
-
if (flagDir) return { dir: flagDir, source: "flag" };
|
|
43
|
-
try {
|
|
44
|
-
const adapter = resolvePipelinesDir?.();
|
|
45
|
-
if (adapter?.dir) return adapter;
|
|
46
|
-
} catch { /* adapter unavailable — fall through to the store seam */ }
|
|
47
|
-
const fromStore = storePaths?.pipelinesDir ?? resolveStorePaths({ env }).pipelinesDir;
|
|
48
|
-
if (fromStore) return { dir: fromStore, source: env?.MANIFOLD_PIPELINES_DIR && !storePaths?.pipelinesDir ? "env" : "store" };
|
|
49
|
-
throw new Error("manifold: no pipelines directory resolved — pass --pipelines-dir <dir> or set MANIFOLD_PIPELINES_DIR");
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
async function ensurePipelinesLoaded(pipelinesRef, logger, dir) {
|
|
53
|
-
if (pipelinesRef.value && pipelinesRef.value.size > 0) return;
|
|
54
|
-
const loaded = await loadPipelines(dir, logger);
|
|
55
|
-
pipelinesRef.value = loaded;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// No subcommand exits on its own after a successful run: something opened
|
|
59
|
-
// during the plugin boot phase, before any subcommand-specific code even
|
|
60
|
-
// runs, holds the process open regardless of which subcommand ran, and it
|
|
61
|
-
// isn't a leftover socket or timer that Node's own introspection exposes,
|
|
62
|
-
// so waiting it out isn't an option. An explicit exit is the only reliable
|
|
63
|
-
// fix.
|
|
64
|
-
//
|
|
65
|
-
// Only safe to wrap an action once its own async work is FULLY done —
|
|
66
|
-
// fire-and-forget follow-on work scheduled as setImmediate/setTimeout (fine
|
|
67
|
-
// for a long-lived HTTP/Telegram/dashboard/companion-app caller) is dropped by the
|
|
68
|
-
// exit below. Every command must await its own work to completion: retry
|
|
69
|
-
// via routes/operator-retry.js's awaitCompletion, approve via
|
|
70
|
-
// gates/gate-resolver.js's awaitCompletion (which also covers
|
|
71
|
-
// applyResolutionsAndResume's own multi-round setTimeout-based retry chain
|
|
72
|
-
// on sustained revision contention, not just its setImmediate resume).
|
|
73
|
-
// Drains detached promotion resumes before exiting: any command that
|
|
74
|
-
// releases an admission can promote another flow, whose run is scheduled on
|
|
75
|
-
// a later tick (engine/admission-promotion-resume.js) — process.exit()
|
|
76
|
-
// right after would drop it with the row already flipped to 'running'.
|
|
77
|
-
function withExit(action) {
|
|
78
|
-
return async (...args) => {
|
|
79
|
-
await action(...args);
|
|
80
|
-
await drainDetachedResumes();
|
|
81
|
-
process.exit(0);
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export function registerCliCommands({ program, executor, store, pipelinesRef, logger, dashboardUrl, api, nodeHealthStore, ownerSessionKey, runStore, nodeExecutionsStore, admissionQueueStore, pipelineDirsStore = null, resolvePipelinesDir = null }) {
|
|
86
|
-
// Pipelines dir for every CLI load below, resolved lazily per command
|
|
87
|
-
// (the --pipelines-dir flag is only known after parse): flag wins, then
|
|
88
|
-
// the adapter seam, then the store seam. Refusal to resolve is fatal —
|
|
89
|
-
// there is no harness-layout fallback.
|
|
90
|
-
function resolveCliDir(harness = null) {
|
|
91
|
-
return resolveCliPipelinesDir({
|
|
92
|
-
flagDir: root.opts()?.pipelinesDir ?? null,
|
|
93
|
-
resolvePipelinesDir: resolvePipelinesDir ? () => resolvePipelinesDir(harness) : null,
|
|
94
|
-
env: process.env,
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
async function ensureCliLoaded() {
|
|
98
|
-
let resolved;
|
|
99
|
-
try {
|
|
100
|
-
resolved = resolveCliDir();
|
|
101
|
-
} catch (err) {
|
|
102
|
-
console.error(`manifold: ${err.message}`);
|
|
103
|
-
process.exit(1);
|
|
104
|
-
}
|
|
105
|
-
await ensurePipelinesLoaded(pipelinesRef, logger, resolved.dir);
|
|
106
|
-
}
|
|
107
|
-
const root = program.command("manifold");
|
|
108
|
-
root.option("--pipelines-dir <dir>", "Pipeline definitions directory (wins over MANIFOLD_PIPELINES_DIR and the store default).");
|
|
109
|
-
root.description("Run state-graph pipelines from the resolved pipelines directory.");
|
|
110
|
-
const failureStore = createFailureStore({ logger, nodeExecutionsStore });
|
|
111
|
-
|
|
112
|
-
// manifold list
|
|
113
|
-
root
|
|
114
|
-
.command("list")
|
|
115
|
-
.description("List loaded pipelines (from the resolved pipelines directory)")
|
|
116
|
-
.action(withExit(async () => {
|
|
117
|
-
await ensureCliLoaded();
|
|
118
|
-
const all = [...pipelinesRef.value.values()];
|
|
119
|
-
if (all.length === 0) {
|
|
120
|
-
console.log("manifold: no pipelines loaded.");
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
for (const p of all) {
|
|
124
|
-
console.log(` ${p.id}`);
|
|
125
|
-
if (p.goal) console.log(` goal: ${p.goal}`);
|
|
126
|
-
console.log(` nodes: ${Object.keys(p.nodes).length}, file: ${p._filepath}`);
|
|
127
|
-
}
|
|
128
|
-
}));
|
|
129
|
-
|
|
130
|
-
// manifold pipelines register --harness <h> --path <dir> — upsert a
|
|
131
|
-
// per-harness override (dir must exist). Takes effect on next gateway
|
|
132
|
-
// boot; `list` shows the currently effective dir.
|
|
133
|
-
// manifold pipelines list [--harness <h>] — table rows + effective dir.
|
|
134
|
-
const pipelinesCmd = root
|
|
135
|
-
.command("pipelines")
|
|
136
|
-
.description("Inspect or override per-harness pipeline directories.");
|
|
137
|
-
pipelinesCmd
|
|
138
|
-
.command("register")
|
|
139
|
-
.description("Register a per-harness pipeline directory override (upsert; dir must exist).")
|
|
140
|
-
.requiredOption("--harness <h>", "Harness this override applies to")
|
|
141
|
-
.requiredOption("--path <dir>", "Pipeline directory (must exist)")
|
|
142
|
-
.action(withExit(async (options) => {
|
|
143
|
-
if (!pipelineDirsStore) {
|
|
144
|
-
console.error("manifold: pipeline dir store unavailable in this process.");
|
|
145
|
-
process.exit(1);
|
|
146
|
-
}
|
|
147
|
-
try {
|
|
148
|
-
const reg = pipelineDirsStore.register({ harness: options.harness, dirPath: options.path });
|
|
149
|
-
console.log(`manifold: registered pipelines dir for harness "${reg.harness}": ${reg.path}`);
|
|
150
|
-
} catch (err) {
|
|
151
|
-
console.error(`manifold: ${err?.message ?? err}`);
|
|
152
|
-
process.exit(1);
|
|
153
|
-
}
|
|
154
|
-
}));
|
|
155
|
-
pipelinesCmd
|
|
156
|
-
.command("list")
|
|
157
|
-
.description("List registered per-harness pipeline dirs and the effective dir.")
|
|
158
|
-
.option("--harness <h>", "Harness to resolve the effective dir for")
|
|
159
|
-
.action(withExit(async (options) => {
|
|
160
|
-
if (!pipelineDirsStore) {
|
|
161
|
-
console.error("manifold: pipeline dir store unavailable in this process.");
|
|
162
|
-
process.exit(1);
|
|
163
|
-
}
|
|
164
|
-
const rows = pipelineDirsStore.list();
|
|
165
|
-
if (rows.length === 0) {
|
|
166
|
-
console.log("manifold: no per-harness pipeline dirs registered.");
|
|
167
|
-
} else {
|
|
168
|
-
for (const r of rows) console.log(` ${r.harness} ${r.path}`);
|
|
169
|
-
}
|
|
170
|
-
const h = options.harness ?? null;
|
|
171
|
-
let resolved;
|
|
172
|
-
try {
|
|
173
|
-
resolved = resolveCliDir(h);
|
|
174
|
-
} catch (err) {
|
|
175
|
-
console.error(`manifold: ${err.message}`);
|
|
176
|
-
process.exit(1);
|
|
177
|
-
}
|
|
178
|
-
console.log(`manifold: effective dir${h ? ` for harness "${h}"` : ""}: ${resolved.dir} (source: ${resolved.source})`);
|
|
179
|
-
}));
|
|
180
|
-
|
|
181
|
-
// manifold start <pipelineId>
|
|
182
|
-
root
|
|
183
|
-
.command("start <pipelineId>")
|
|
184
|
-
.description("Start a new run of a pipeline. Blocks until the flow reaches terminal or human-gate.")
|
|
185
|
-
.option("--args <json>", "JSON-encoded args to merge into initial state", "")
|
|
186
|
-
.action(withExit(async (pipelineId, options) => {
|
|
187
|
-
await ensureCliLoaded();
|
|
188
|
-
const args = options.args ? safeParseJson(options.args) : {};
|
|
189
|
-
if (args === null) {
|
|
190
|
-
console.error(`manifold: --args must be valid JSON`);
|
|
191
|
-
process.exit(1);
|
|
192
|
-
}
|
|
193
|
-
try {
|
|
194
|
-
const triggeredBy = {
|
|
195
|
-
kind: "cli",
|
|
196
|
-
label: `CLI · ${process.env.USER ?? "unknown"}`,
|
|
197
|
-
ts: Date.now(),
|
|
198
|
-
};
|
|
199
|
-
const record = await executor.start(pipelineId, args ?? {}, triggeredBy);
|
|
200
|
-
// Mint a synthetic trigger edge so the lineage tree shows a CLI
|
|
201
|
-
// anchor above this flow — mirrors the HTTP handler's behavior.
|
|
202
|
-
try {
|
|
203
|
-
const synthSession = `agent:operator:cli:${record.flowId}`;
|
|
204
|
-
await api?.runtime?.lineage?.recordTrigger?.({
|
|
205
|
-
flowId: record.flowId,
|
|
206
|
-
runId: record.stateJson?.runId ?? null,
|
|
207
|
-
pipelineId,
|
|
208
|
-
parentSessionKey: synthSession,
|
|
209
|
-
rootKind: "explicit",
|
|
210
|
-
rootLabel: pipelineId,
|
|
211
|
-
});
|
|
212
|
-
} catch (err) {
|
|
213
|
-
logger?.warn?.(`manifold start (cli): lineage edge skipped: ${err?.message ?? err}`);
|
|
214
|
-
}
|
|
215
|
-
console.log(`manifold: started ${pipelineId} → flowId=${record.flowId}`);
|
|
216
|
-
// The shared admission pool was full at start() time — the flow is
|
|
217
|
-
// durably queued (state/admission-queue-store.js) and will run once
|
|
218
|
-
// a slot frees, but that promotion happens via the long-running
|
|
219
|
-
// GATEWAY process's own resume wiring, not this one-shot CLI
|
|
220
|
-
// process. Nothing left for this invocation to usefully wait on —
|
|
221
|
-
// runFlow() would just no-op immediately (engine/executor.js's own
|
|
222
|
-
// isQueued guard) rather than actually drive it to completion.
|
|
223
|
-
if (record.status === "queued") {
|
|
224
|
-
console.log(` queued — waiting for a shared admission slot; will run automatically once the gateway has capacity`);
|
|
225
|
-
return;
|
|
226
|
-
}
|
|
227
|
-
console.log(` driving executor loop in-process; ctrl-c to stop\n`);
|
|
228
|
-
await executor.runFlow(record.flowId, "fresh");
|
|
229
|
-
// The await above only resolves once THIS flow itself goes
|
|
230
|
-
// blocked/terminal — a childFlows:true subflow node fires its
|
|
231
|
-
// children via a bare setImmediate and returns immediately, so
|
|
232
|
-
// without this, withExit's process.exit(0) below would kill those
|
|
233
|
-
// children (and any of their own descendants) before they ever
|
|
234
|
-
// ran. See wait-for-flow-settlement.js's header for the full
|
|
235
|
-
// incident this fixes.
|
|
236
|
-
await waitForFlowSettlement(record.flowId, { store, runStore, nodeExecutionsStore, logger });
|
|
237
|
-
const final = await store.get(record.flowId);
|
|
238
|
-
console.log(`\nmanifold: ${record.flowId} → ${final?.status ?? "?"} (step=${final?.lastStep ?? "?"})`);
|
|
239
|
-
} catch (err) {
|
|
240
|
-
console.error(`manifold: start failed: ${err.message}`);
|
|
241
|
-
process.exit(1);
|
|
242
|
-
}
|
|
243
|
-
}));
|
|
244
|
-
|
|
245
|
-
// manifold status <flowId>
|
|
246
|
-
root
|
|
247
|
-
.command("status <flowId>")
|
|
248
|
-
.description("Show current state and pending gates of a flow run")
|
|
249
|
-
.action(withExit(async (flowId) => {
|
|
250
|
-
const flow = await store.get(flowId);
|
|
251
|
-
if (!flow) {
|
|
252
|
-
console.error(`manifold: flow not found: ${flowId}`);
|
|
253
|
-
process.exit(1);
|
|
254
|
-
}
|
|
255
|
-
const state = flow.stateJson ?? {};
|
|
256
|
-
console.log(`manifold: ${flow.flowId}`);
|
|
257
|
-
console.log(` pipeline: ${state.pipelineId ?? "?"}`);
|
|
258
|
-
console.log(` status: ${flow.status}`);
|
|
259
|
-
console.log(` step: ${flow.lastStep}`);
|
|
260
|
-
console.log(` revision: ${flow.revision}`);
|
|
261
|
-
if (flow.waitJson) {
|
|
262
|
-
const kind = flow.waitJson.kind ?? "?";
|
|
263
|
-
const pending = flow.waitJson.pending ?? [];
|
|
264
|
-
console.log(` waiting: ${kind} (${pending.length} pending)`);
|
|
265
|
-
if (Array.isArray(pending) && pending.length > 0) {
|
|
266
|
-
for (const id of pending) console.log(` • ${id}`);
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
console.log(` state keys: ${Object.keys(state).join(", ")}`);
|
|
270
|
-
const flowErrors = await failureStore.queryErrorsByFlow(flow.flowId);
|
|
271
|
-
if (flowErrors.length) {
|
|
272
|
-
console.log(` errors (${flowErrors.length}):`);
|
|
273
|
-
for (const e of flowErrors.slice(-5)) {
|
|
274
|
-
console.log(` • ${e.nodeId}: ${e.message}`);
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
}));
|
|
278
|
-
|
|
279
|
-
// manifold retry <flowId>
|
|
280
|
-
//
|
|
281
|
-
// README.md's CLI table documented this command since before task #267's
|
|
282
|
-
// audit, but nothing ever registered it — the only working path to
|
|
283
|
-
// routes/operator-retry.js's retryFailureBranch (which takes a failure
|
|
284
|
-
// *id*, not a flowId) was the /manifold/_elev/retry-failure HTTP route.
|
|
285
|
-
// Closes that gap: looks up the flow's own most recent OPEN failure_events
|
|
286
|
-
// row (retryFailureBranch's own topology walk resolves the correct node
|
|
287
|
-
// to retry from regardless of which of a flow's open failures is passed,
|
|
288
|
-
// so ties don't matter — see that file's own `rootNode` derivation),
|
|
289
|
-
// then retries it the exact same way the HTTP route does — same code,
|
|
290
|
-
// same "works identically for a root-level flow and a childFlows
|
|
291
|
-
// subflow-item flow" fix this command exists to expose (a subflow item
|
|
292
|
-
// runs as a real flow_runs child with its own flowId, so this needs no
|
|
293
|
-
// special-casing for that case at all).
|
|
294
|
-
//
|
|
295
|
-
// Blocks until every retried flow reaches terminal or blocked — same
|
|
296
|
-
// "drives the executor loop in-process, in this one-shot CLI process"
|
|
297
|
-
// constraint `start` documents at the top of this file, and for the same
|
|
298
|
-
// reason: retryFailureBranch's own default behavior schedules the actual
|
|
299
|
-
// re-run via setImmediate and returns before it fires, which is correct
|
|
300
|
-
// for HTTP/Telegram callers (a long-lived process that keeps going) but
|
|
301
|
-
// fatal for a one-shot CLI process — it would exit before that scheduled
|
|
302
|
-
// work ever ran. Passing awaitCompletion:true switches it to await the
|
|
303
|
-
// retry directly instead.
|
|
304
|
-
root
|
|
305
|
-
.command("retry <flowId>")
|
|
306
|
-
.description("Retry a flow's most recent open failure (root-level or a childFlows subflow item). Blocks until the retried flow(s) reach terminal or blocked.")
|
|
307
|
-
.action(withExit(async (flowId) => {
|
|
308
|
-
await ensureCliLoaded();
|
|
309
|
-
const openFailures = (await failureStore.list({ resolved: false, limit: 1000 }))
|
|
310
|
-
.filter((f) => f.flow_id === flowId);
|
|
311
|
-
if (openFailures.length === 0) {
|
|
312
|
-
console.error(`manifold: no open failure found for flow ${flowId}`);
|
|
313
|
-
process.exit(1);
|
|
314
|
-
}
|
|
315
|
-
const failure = openFailures.reduce((a, b) => (a.failed_at >= b.failed_at ? a : b));
|
|
316
|
-
const { retryFailureBranch } = createRetryFailure({
|
|
317
|
-
store, readStore: runStore, failureStore, pipelinesRef, executor, runStore, ownerSessionKey, admissionQueueStore, logger, api,
|
|
318
|
-
});
|
|
319
|
-
const result = await retryFailureBranch({ id: failure.id, via: "cli", awaitCompletion: true });
|
|
320
|
-
if (result.code !== "ok") {
|
|
321
|
-
console.error(`manifold: retry failed (${result.code}): ${result.reason ?? "unknown"}`);
|
|
322
|
-
process.exit(1);
|
|
323
|
-
}
|
|
324
|
-
// retryFailureBranch's own awaitCompletion:true only awaits the ONE
|
|
325
|
-
// runFlow()/resume() call for the retried flow itself — if that
|
|
326
|
-
// retry re-enters a childFlows:true subflow node, the freshly
|
|
327
|
-
// (re-)spawned children fire via a bare setImmediate and are still
|
|
328
|
-
// in flight here. See wait-for-flow-settlement.js's header.
|
|
329
|
-
if (result.mode === "cascade-redirect") {
|
|
330
|
-
const okResults = result.results.filter((r) => r.code === "ok");
|
|
331
|
-
console.log(`manifold: retry for ${flowId} — redirected to ${result.redirectedTo.length} underlying failure(s), ${okResults.length} retried`);
|
|
332
|
-
for (const r of okResults) {
|
|
333
|
-
await waitForFlowSettlement(r.flowId, { store, runStore, nodeExecutionsStore, logger });
|
|
334
|
-
const final = await store.get(r.flowId);
|
|
335
|
-
console.log(` • ${r.flowId} → ${final?.status ?? "?"} (failureNode=${r.failureNode}, rootNode=${r.rootNode}, cleared=[${r.cleared.join(",")}])`);
|
|
336
|
-
}
|
|
337
|
-
} else {
|
|
338
|
-
await waitForFlowSettlement(flowId, { store, runStore, nodeExecutionsStore, logger });
|
|
339
|
-
const final = await store.get(flowId);
|
|
340
|
-
console.log(`manifold: retry for ${flowId} → ${final?.status ?? "?"} (failureNode=${result.failureNode}, rootNode=${result.rootNode}, cleared=[${result.cleared.join(",")}])`);
|
|
341
|
-
}
|
|
342
|
-
}));
|
|
343
|
-
|
|
344
|
-
// manifold node-health status [pipelineId]
|
|
345
|
-
// manifold node-health reset <pipelineId> <nodeId>
|
|
346
|
-
//
|
|
347
|
-
// Both live under one `node-health` parent command — Commander's
|
|
348
|
-
// `.command(nameAndArgs)` only reads the first whitespace-delimited
|
|
349
|
-
// token as the command name, so two top-level `.command("node-health
|
|
350
|
-
// ...")` calls would collide ("cannot add command 'node-health' as
|
|
351
|
-
// already have command 'node-health'"), crashing CLI registration for
|
|
352
|
-
// every `manifold` subcommand, not just these two.
|
|
353
|
-
const nodeHealthCmd = root
|
|
354
|
-
.command("node-health")
|
|
355
|
-
.description("Inspect or reset a node's agent-dispatch circuit breaker.");
|
|
356
|
-
|
|
357
|
-
// Lists nodes currently blocked by the circuit breaker — any "agent"-kind
|
|
358
|
-
// node that opts in via node.circuitBreaker: true is eligible (see
|
|
359
|
-
// executor-nodes.js's dispatchAgentEntry), including cascade sub-nodes
|
|
360
|
-
// dispatched as part of a kind:"subflow" node's own child flow. --all
|
|
361
|
-
// includes resolved history instead of only active blocks.
|
|
362
|
-
nodeHealthCmd
|
|
363
|
-
.command("status [pipelineId]")
|
|
364
|
-
.description("List nodes currently blocked (unhealthy) by the circuit breaker.")
|
|
365
|
-
.option("--all", "Include resolved history, not just active blocks", false)
|
|
366
|
-
.action(withExit(async (pipelineId, options) => {
|
|
367
|
-
const rows = await nodeHealthStore.list(pipelineId, options.all ? {} : { status: "blocked" });
|
|
368
|
-
if (rows.length === 0) {
|
|
369
|
-
console.log(pipelineId ? `manifold: no node-health blocks for ${pipelineId}` : "manifold: no node-health blocks");
|
|
370
|
-
return;
|
|
371
|
-
}
|
|
372
|
-
for (const r of rows) {
|
|
373
|
-
const when = new Date(r.created_at).toISOString();
|
|
374
|
-
console.log(`${r.status.padEnd(9)} ${r.pipeline_id}/${r.node_id} (${when})`);
|
|
375
|
-
console.log(` reason: ${r.reason}`);
|
|
376
|
-
if (r.blocked_by_flow_id) console.log(` flow: ${r.blocked_by_flow_id.slice(0, 8)}`);
|
|
377
|
-
if (r.status === "resolved") console.log(` resolved via: ${r.resolved_via ?? "?"}`);
|
|
378
|
-
}
|
|
379
|
-
}));
|
|
380
|
-
|
|
381
|
-
// Flags the active block resolved (row is kept for history, not deleted
|
|
382
|
-
// — see state/node-health-store.js). Does not itself retry any flow;
|
|
383
|
-
// the node simply becomes eligible for dispatch again on its next visit.
|
|
384
|
-
nodeHealthCmd
|
|
385
|
-
.command("reset <pipelineId> <nodeId>")
|
|
386
|
-
.description("Clear an unhealthy block so the node can be tried again.")
|
|
387
|
-
.action(withExit(async (pipelineId, nodeId) => {
|
|
388
|
-
const result = await nodeHealthStore.reset(pipelineId, nodeId, { via: "cli" });
|
|
389
|
-
if (result.reset === 0) {
|
|
390
|
-
console.log(`manifold: ${pipelineId}/${nodeId} was not blocked; nothing to reset`);
|
|
391
|
-
return;
|
|
392
|
-
}
|
|
393
|
-
console.log(`manifold: ${pipelineId}/${nodeId} reset — eligible for dispatch again`);
|
|
394
|
-
}));
|
|
395
|
-
|
|
396
|
-
// manifold approve <flowId> <itemId> <decision> [text]
|
|
397
|
-
//
|
|
398
|
-
// Blocks until the resumed flow reaches terminal or blocked again — same
|
|
399
|
-
// reasoning as `retry` above: gates/gate-resolver.js's
|
|
400
|
-
// applyResolutionsAndResume schedules the actual setRunning + executor.
|
|
401
|
-
// resume via setImmediate (and, on sustained revision contention, a
|
|
402
|
-
// further live retry round via setTimeout) and returns before either
|
|
403
|
-
// fires, which is correct for the long-lived HTTP/Telegram/dashboard/companion-app
|
|
404
|
-
// callers that share this resolver but fatal for this one-shot CLI
|
|
405
|
-
// process. Passing awaitCompletion:true switches it to await all of that
|
|
406
|
-
// directly instead.
|
|
407
|
-
root
|
|
408
|
-
.command("approve <flowId> <itemId> <decision>")
|
|
409
|
-
.description("Approve, reject, or edit a pending item on a gate node. Blocks until the resumed flow reaches terminal or blocked again.")
|
|
410
|
-
.option("--text <text>", "Edited text (only with decision=edit)")
|
|
411
|
-
.action(withExit(async (flowId, itemId, decision, options) => {
|
|
412
|
-
decision = String(decision).toLowerCase();
|
|
413
|
-
if (!["approve", "reject", "edit"].includes(decision)) {
|
|
414
|
-
console.error(`manifold: decision must be approve|reject|edit`);
|
|
415
|
-
process.exit(1);
|
|
416
|
-
}
|
|
417
|
-
if (decision === "edit" && !options.text) {
|
|
418
|
-
console.error(`manifold: edit requires --text`);
|
|
419
|
-
process.exit(1);
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
// Same channel-agnostic resolver the TG callback handler, the
|
|
423
|
-
// dashboard, and the /manifold/gate/resolve route use. Spun up
|
|
424
|
-
// here against this CLI process's own store + executor — the
|
|
425
|
-
// gateway has its own resolver instance, but writes still serialize
|
|
426
|
-
// through the underlying SQL store so cross-process resolution is
|
|
427
|
-
// safe. recordItemDecision drives setRunning + executor.resume
|
|
428
|
-
// internally once all items decide.
|
|
429
|
-
const gateResolver = createGateResolver({
|
|
430
|
-
api: { logger },
|
|
431
|
-
store,
|
|
432
|
-
executor,
|
|
433
|
-
pipelineLookup: (pipelineId) => pipelinesRef.value.get(pipelineId),
|
|
434
|
-
admissionQueueStore,
|
|
435
|
-
});
|
|
436
|
-
// executor.resume (fired from inside applyResolutionsAndResume) needs
|
|
437
|
-
// the pipeline definition loaded in this CLI process's pipelinesRef.
|
|
438
|
-
await ensureCliLoaded();
|
|
439
|
-
|
|
440
|
-
const result = await gateResolver.recordItemDecision({
|
|
441
|
-
flowId,
|
|
442
|
-
itemId,
|
|
443
|
-
decision,
|
|
444
|
-
source: "cli",
|
|
445
|
-
editedText: options.text,
|
|
446
|
-
awaitCompletion: true,
|
|
447
|
-
});
|
|
448
|
-
if (!result.ok) {
|
|
449
|
-
console.error(`manifold: ${result.code}`);
|
|
450
|
-
process.exit(1);
|
|
451
|
-
}
|
|
452
|
-
// recordItemDecision's own awaitCompletion:true only awaits the ONE
|
|
453
|
-
// executor.resume() call for THIS flow — if resuming re-enters a
|
|
454
|
-
// childFlows:true subflow node, freshly spawned children fire via a
|
|
455
|
-
// bare setImmediate and are still in flight here. See
|
|
456
|
-
// wait-for-flow-settlement.js's header.
|
|
457
|
-
await waitForFlowSettlement(flowId, { store, runStore, nodeExecutionsStore, logger });
|
|
458
|
-
const final = await store.get(flowId);
|
|
459
|
-
console.log(
|
|
460
|
-
`manifold: ${decision} "${itemId}" (${result.status})` +
|
|
461
|
-
(final ? ` — flow → ${final.status ?? "?"} (step=${final.lastStep ?? "?"})` : "")
|
|
462
|
-
);
|
|
463
|
-
}));
|
|
464
|
-
|
|
465
|
-
// manifold rerun <sourceFlowId> — start a fresh run of the same pipeline
|
|
466
|
-
// with the same args (or overridden via --args). Stamps state.rerunOf so
|
|
467
|
-
// the lineage is queryable. Subject to the singleton-per-pipeline guard.
|
|
468
|
-
root
|
|
469
|
-
.command("rerun <sourceFlowId>")
|
|
470
|
-
.description("Start a fresh run of the source flow's pipeline (new flowId, fresh state)")
|
|
471
|
-
.option("--args <json>", "JSON-encoded args; overrides the source flow's args", "")
|
|
472
|
-
.action(withExit(async (sourceFlowId, options) => {
|
|
473
|
-
await ensureCliLoaded();
|
|
474
|
-
const argsOverride = options.args ? safeParseJson(options.args) : undefined;
|
|
475
|
-
if (options.args && argsOverride === null) {
|
|
476
|
-
console.error(`manifold: --args must be valid JSON`);
|
|
477
|
-
process.exit(1);
|
|
478
|
-
}
|
|
479
|
-
let record;
|
|
480
|
-
try { record = await executor.rerun(sourceFlowId, argsOverride); }
|
|
481
|
-
catch (err) {
|
|
482
|
-
console.error(`manifold: rerun failed: ${err.message}`);
|
|
483
|
-
process.exit(1);
|
|
484
|
-
}
|
|
485
|
-
console.log(`manifold: re-ran ${sourceFlowId.slice(0, 8)} → flowId=${record.flowId}`);
|
|
486
|
-
try { await executor.runFlow(record.flowId, "fresh"); }
|
|
487
|
-
catch { /* ignore — error surface is the next status read */ }
|
|
488
|
-
// See wait-for-flow-settlement.js's header — the runFlow() await
|
|
489
|
-
// above only resolves once THIS flow itself goes blocked/terminal,
|
|
490
|
-
// not any childFlows:true children it spawned along the way.
|
|
491
|
-
await waitForFlowSettlement(record.flowId, { store, runStore, nodeExecutionsStore, logger });
|
|
492
|
-
const final = await store.get(record.flowId);
|
|
493
|
-
console.log(`manifold: ${record.flowId.slice(0, 8)} → ${final?.status ?? "?"} (step=${final?.lastStep ?? "?"})`);
|
|
494
|
-
}));
|
|
495
|
-
|
|
496
|
-
// manifold cancel <flowId> — terminal transition for a non-terminal flow.
|
|
497
|
-
// Does not preempt in-flight subagent calls; they finish and their results
|
|
498
|
-
// are discarded (the executor's setRunning fails the revision check).
|
|
499
|
-
root
|
|
500
|
-
.command("cancel <flowId>")
|
|
501
|
-
.description("Cancel a running, blocked, or waiting flow (terminal; cannot be undone)")
|
|
502
|
-
.option("--reason <text>", "Why this flow is being cancelled (recorded on the run)")
|
|
503
|
-
.action(withExit(async (flowId, options) => {
|
|
504
|
-
const flow = await store.get(flowId);
|
|
505
|
-
if (!flow) {
|
|
506
|
-
console.error(`manifold: flow not found: ${flowId}`);
|
|
507
|
-
process.exit(1);
|
|
508
|
-
}
|
|
509
|
-
if (TERMINAL_STATUS_SET.has(flow.status)) {
|
|
510
|
-
console.error(`manifold: flow is already terminal (status=${flow.status}); nothing to cancel`);
|
|
511
|
-
process.exit(1);
|
|
512
|
-
}
|
|
513
|
-
const result = await executor.cancel(flowId, options.reason ?? null);
|
|
514
|
-
if (!result?.cancelled) {
|
|
515
|
-
console.error(`manifold: cancel did not apply: ${result?.reason ?? "unknown"}`);
|
|
516
|
-
process.exit(1);
|
|
517
|
-
}
|
|
518
|
-
// executor.cancel() releases this flow's admission slot (and wakes a
|
|
519
|
-
// waiting parent) via state-store.js's own triggerAdmissionRelease /
|
|
520
|
-
// triggerParentResume before its promise resolves, so no second
|
|
521
|
-
// explicit release is needed here — by the time `cancel()` above
|
|
522
|
-
// returns, the real one has already landed.
|
|
523
|
-
console.log(`manifold: cancelled ${flowId.slice(0, 8)} (was ${flow.status})`);
|
|
524
|
-
}));
|
|
525
|
-
|
|
526
|
-
// manifold resume-admitted <flowId> — recovery for an "orphaned
|
|
527
|
-
// promotion": a flow stuck status='queued' whose flow-start/child-dispatch
|
|
528
|
-
// admission row is already 'admitted' (it holds a live pool slot) because
|
|
529
|
-
// some past release() promoted it and the promotion's resume was dropped
|
|
530
|
-
// (see engine/admission-promotion-resume.js's header). Deliberately does
|
|
531
|
-
// NOT call admissionQueueStore.admit() — the flow already holds a valid
|
|
532
|
-
// slot, and every "resume a queued flow" path that admits unconditionally
|
|
533
|
-
// (admitAndSetRunning, used by retry/approve/gate-resolve) would create a
|
|
534
|
-
// SECOND admission row here, permanently shrinking the shared pool by one
|
|
535
|
-
// more slot exactly like the bug this command recovers from. Refuses to
|
|
536
|
-
// run unless it can confirm the flow genuinely already holds that slot —
|
|
537
|
-
// this is a recovery tool for the specific stuck state, not a way to cut
|
|
538
|
-
// the queue.
|
|
539
|
-
root
|
|
540
|
-
.command("resume-admitted <flowId>")
|
|
541
|
-
.description("Force-resume a flow stuck 'queued' that already holds a live flow-start/child-dispatch admission slot (an orphaned promotion). Refuses if the flow doesn't already hold that slot.")
|
|
542
|
-
.action(withExit(async (flowId) => {
|
|
543
|
-
const flow = await store.get(flowId);
|
|
544
|
-
if (!flow) {
|
|
545
|
-
console.error(`manifold: flow not found: ${flowId}`);
|
|
546
|
-
process.exit(1);
|
|
547
|
-
}
|
|
548
|
-
if (flow.status !== "queued") {
|
|
549
|
-
console.error(`manifold: flow is not queued (status=${flow.status}); nothing to force-resume`);
|
|
550
|
-
process.exit(1);
|
|
551
|
-
}
|
|
552
|
-
const kind = flow.waitJson?.kind;
|
|
553
|
-
if (kind !== "flow-start" && kind !== "child-dispatch") {
|
|
554
|
-
console.error(`manifold: wait kind "${kind ?? "?"}" isn't resumable this way — only flow-start/child-dispatch hold a durable admission with no in-process waiter of their own`);
|
|
555
|
-
process.exit(1);
|
|
556
|
-
}
|
|
557
|
-
if (!admissionQueueStore) {
|
|
558
|
-
console.error("manifold: no admissionQueueStore wired in");
|
|
559
|
-
process.exit(1);
|
|
560
|
-
}
|
|
561
|
-
const admitted = await admissionQueueStore.listByStatus("admitted");
|
|
562
|
-
const held = admitted.find((r) => r.flowId === flowId && r.kind === kind);
|
|
563
|
-
if (!held) {
|
|
564
|
-
console.error(`manifold: flow does not hold a live '${kind}' admission — it's genuinely still queued, not orphaned. Wait for the normal release/promotion cycle instead of forcing this.`);
|
|
565
|
-
process.exit(1);
|
|
566
|
-
}
|
|
567
|
-
const result = await flipToRunningAndResume({ parentFlowId: flowId, runStore, resume: executor.resume, logger, api });
|
|
568
|
-
if (!result.resumed) {
|
|
569
|
-
console.error(`manifold: force-resume did not apply: ${result.reason ?? "unknown"}`);
|
|
570
|
-
process.exit(1);
|
|
571
|
-
}
|
|
572
|
-
await waitForFlowSettlement(flowId, { store, runStore, nodeExecutionsStore, logger });
|
|
573
|
-
// By now the flow is guaranteed terminal or gate-blocked (see
|
|
574
|
-
// waitForFlowSettlement's own contract) — either way its admission
|
|
575
|
-
// release went out via state-store.js's setWaiting/terminal hooks,
|
|
576
|
-
// fire-and-forget. This CLI invocation is short-lived: withExit's
|
|
577
|
-
// process.exit() right after this action returns gives that
|
|
578
|
-
// background release no guarantee of finishing its DB round-trip
|
|
579
|
-
// first, so release explicitly here before exiting. releaseByFlow is
|
|
580
|
-
// a safe no-op for whichever kind doesn't apply, and for the one the
|
|
581
|
-
// internal call already handled.
|
|
582
|
-
if (admissionQueueStore) {
|
|
583
|
-
const results = await Promise.all([
|
|
584
|
-
admissionQueueStore.releaseByFlow({ flowId, kind: "flow-start" }).catch(() => ({ released: false, promoted: null })),
|
|
585
|
-
admissionQueueStore.releaseByFlow({ flowId, kind: "child-dispatch" }).catch(() => ({ released: false, promoted: null })),
|
|
586
|
-
]);
|
|
587
|
-
await wakePromotedRelease(results, {
|
|
588
|
-
runStore, resume: executor.resume, logger, api, context: "manifold resume-admitted: cleanup-release",
|
|
589
|
-
});
|
|
590
|
-
}
|
|
591
|
-
const final = await store.get(flowId);
|
|
592
|
-
console.log(`manifold: force-resumed ${flowId.slice(0, 8)} → ${final?.status ?? "?"}`);
|
|
593
|
-
}));
|
|
594
|
-
|
|
595
|
-
// manifold release-leaked-admission <flowId> — recovery for the OTHER
|
|
596
|
-
// admission-pool failure mode (see engine/admission-promotion-resume.js's
|
|
597
|
-
// header for the orphaned-promotion one resume-admitted above handles): a
|
|
598
|
-
// flow_admission_queue row is only ever supposed to exist while its owning
|
|
599
|
-
// flow is genuinely non-terminal. If a terminal transition's own release
|
|
600
|
-
// (state-store.js's triggerAdmissionRelease) doesn't fire or doesn't land
|
|
601
|
-
// — a bug in the releasing code path, or a process exiting before that
|
|
602
|
-
// fire-and-forget write commits — the row is a leak: a dead flow
|
|
603
|
-
// permanently holding a live pool slot. boot/flow-revival.js sweeps for
|
|
604
|
-
// exactly this at every boot; this is the same check and release, scoped
|
|
605
|
-
// to one caller-specified flowId instead of a full-table scan, for when
|
|
606
|
-
// restarting the gateway isn't the right lever.
|
|
607
|
-
root
|
|
608
|
-
.command("release-leaked-admission <flowId>")
|
|
609
|
-
.description("Release a terminal flow's leaked flow_admission_queue row (status=admitted/queued for a flow that already finished) and resume whatever gets promoted into the freed slot.")
|
|
610
|
-
.action(withExit(async (flowId) => {
|
|
611
|
-
const flow = await store.get(flowId);
|
|
612
|
-
if (!flow) {
|
|
613
|
-
console.error(`manifold: flow not found: ${flowId}`);
|
|
614
|
-
process.exit(1);
|
|
615
|
-
}
|
|
616
|
-
if (!TERMINAL_STATUS_SET.has(flow.status)) {
|
|
617
|
-
console.error(`manifold: flow is not terminal (status=${flow.status}) — this command only cleans up a leak on an already-finished flow; use resume-admitted or cancel for a live one`);
|
|
618
|
-
process.exit(1);
|
|
619
|
-
}
|
|
620
|
-
if (!admissionQueueStore) {
|
|
621
|
-
console.error("manifold: no admissionQueueStore wired in");
|
|
622
|
-
process.exit(1);
|
|
623
|
-
}
|
|
624
|
-
let releasedCount = 0;
|
|
625
|
-
for (const kind of ["flow-start", "child-dispatch"]) {
|
|
626
|
-
const result = await admissionQueueStore.releaseByFlow({ flowId, kind });
|
|
627
|
-
if (!result.released) continue;
|
|
628
|
-
releasedCount++;
|
|
629
|
-
console.log(`manifold: released leaked ${kind} admission for ${flowId.slice(0, 8)}`);
|
|
630
|
-
if (result.promoted) {
|
|
631
|
-
const r = await wakePromotedRelease(result, {
|
|
632
|
-
runStore, resume: executor.resume, logger, api, context: `manifold release-leaked-admission [${flowId.slice(0, 8)}]`,
|
|
633
|
-
});
|
|
634
|
-
console.log(` promoted ${result.promoted.flowId.slice(0, 8)} (${result.promoted.kind}) into the freed slot — resumed=${r.resumed}${r.resumed ? "" : ` reason=${r.reason}`}`);
|
|
635
|
-
}
|
|
636
|
-
}
|
|
637
|
-
if (releasedCount === 0) {
|
|
638
|
-
console.log(`manifold: flow ${flowId.slice(0, 8)} held no live admission — nothing to release`);
|
|
639
|
-
}
|
|
640
|
-
}));
|
|
641
|
-
|
|
642
|
-
// manifold runs — list our managed runs
|
|
643
|
-
root
|
|
644
|
-
.command("runs")
|
|
645
|
-
.description("List flow runs created by manifold")
|
|
646
|
-
.option("--status <s>", "Filter by status (running, blocked, succeeded, failed, cancelled)")
|
|
647
|
-
.action(withExit(async (options) => {
|
|
648
|
-
const all = await store.list();
|
|
649
|
-
const filtered = options.status ? all.filter((f) => f.status === options.status) : all;
|
|
650
|
-
if (filtered.length === 0) {
|
|
651
|
-
console.log(`manifold: no runs${options.status ? ` with status=${options.status}` : ""}.`);
|
|
652
|
-
return;
|
|
653
|
-
}
|
|
654
|
-
filtered.sort((a, b) => (b.updatedAt ?? 0) - (a.updatedAt ?? 0));
|
|
655
|
-
for (const f of filtered.slice(0, 30)) {
|
|
656
|
-
const pipelineId = f.stateJson?.pipelineId ?? "?";
|
|
657
|
-
const stamp = f.updatedAt ? new Date(f.updatedAt).toISOString().slice(0, 19).replace("T", " ") : "?";
|
|
658
|
-
console.log(` ${f.flowId.slice(0, 8)} ${f.status.padEnd(10)} ${pipelineId.padEnd(35)} step=${f.lastStep ?? "?"} ${stamp}`);
|
|
659
|
-
}
|
|
660
|
-
if (filtered.length > 30) console.log(` ... and ${filtered.length - 30} more`);
|
|
661
|
-
}));
|
|
662
|
-
|
|
663
|
-
// manifold pause <flowId> — stop the before_dispatch hook from claiming
|
|
664
|
-
// operator messages for this flow. Useful when you want to talk to the
|
|
665
|
-
// main agent without disrupting an active Vulcan priming interview.
|
|
666
|
-
root
|
|
667
|
-
.command("pause <flowId>")
|
|
668
|
-
.description("Stop intercepting operator messages for this priming flow — operator can talk to the main agent. Use `resume` to re-engage.")
|
|
669
|
-
.action(withExit(async (flowId) => {
|
|
670
|
-
const record = await store.get(flowId);
|
|
671
|
-
if (!record) {
|
|
672
|
-
const matches = (await store.list()).filter((f) => f.flowId.startsWith(flowId));
|
|
673
|
-
if (matches.length === 1) flowId = matches[0].flowId;
|
|
674
|
-
else if (matches.length > 1) {
|
|
675
|
-
console.error(`manifold: ambiguous prefix "${flowId}" — ${matches.length} matches`);
|
|
676
|
-
process.exit(1);
|
|
677
|
-
} else {
|
|
678
|
-
console.error(`manifold: no flow found with id "${flowId}"`);
|
|
679
|
-
process.exit(1);
|
|
680
|
-
}
|
|
681
|
-
}
|
|
682
|
-
pauseFlow(flowId);
|
|
683
|
-
console.log(`manifold: paused ${flowId.slice(0, 8)} — operator messages will route to the main agent. Resume with: openclaw manifold resume ${flowId.slice(0, 8)}`);
|
|
684
|
-
}));
|
|
685
|
-
|
|
686
|
-
// manifold resume <flowId> — re-engage the before_dispatch claim.
|
|
687
|
-
root
|
|
688
|
-
.command("resume <flowId>")
|
|
689
|
-
.description("Re-engage the priming claim for this flow — operator messages route back to the priming session.")
|
|
690
|
-
.action(withExit(async (flowId) => {
|
|
691
|
-
const matches = (await store.list()).filter((f) => f.flowId.startsWith(flowId));
|
|
692
|
-
if (matches.length === 1) flowId = matches[0].flowId;
|
|
693
|
-
else if (matches.length > 1) {
|
|
694
|
-
console.error(`manifold: ambiguous prefix "${flowId}" — ${matches.length} matches`);
|
|
695
|
-
process.exit(1);
|
|
696
|
-
}
|
|
697
|
-
resumeFlow(flowId);
|
|
698
|
-
console.log(`manifold: resumed ${flowId.slice(0, 8)} — operator messages will route to the priming session again.`);
|
|
699
|
-
}));
|
|
700
|
-
|
|
701
|
-
// manifold dashboard — print URL and open the browser to the read-only UI.
|
|
702
|
-
// The dashboard service runs in the gateway process; the CLI just opens a
|
|
703
|
-
// window pointing at it. Doesn't check liveness — the user will see a
|
|
704
|
-
// connection error in their browser if the gateway isn't running.
|
|
705
|
-
root
|
|
706
|
-
.command("dashboard")
|
|
707
|
-
.description("Open the read-only manifold dashboard in your browser.")
|
|
708
|
-
.option("--no-open", "Just print the URL; don't launch a browser.")
|
|
709
|
-
.option("--url <url>", "Override the URL to open (defaults to the configured dashboard host/port).")
|
|
710
|
-
.action(withExit((options) => {
|
|
711
|
-
const url = options.url || dashboardUrl || "http://127.0.0.1:7430";
|
|
712
|
-
console.log(`manifold dashboard: ${url}`);
|
|
713
|
-
if (options.open === false) return;
|
|
714
|
-
const { cmd, args } = browserOpenCommand(url);
|
|
715
|
-
if (!cmd) {
|
|
716
|
-
console.log(`manifold dashboard: no platform-appropriate opener; open the URL manually.`);
|
|
717
|
-
return;
|
|
718
|
-
}
|
|
719
|
-
try {
|
|
720
|
-
const child = spawn(cmd, args, { stdio: "ignore", detached: true });
|
|
721
|
-
child.on("error", (err) => console.log(`manifold dashboard: opener "${cmd}" failed (${err.message}); open the URL manually.`));
|
|
722
|
-
child.unref();
|
|
723
|
-
} catch (err) {
|
|
724
|
-
console.log(`manifold dashboard: failed to launch browser (${err.message}); open the URL manually.`);
|
|
725
|
-
}
|
|
726
|
-
}));
|
|
727
|
-
|
|
728
|
-
// manifold paused — list paused flows
|
|
729
|
-
root
|
|
730
|
-
.command("paused")
|
|
731
|
-
.description("List flows currently paused (operator side-channel active).")
|
|
732
|
-
.action(withExit(async () => {
|
|
733
|
-
const paused = [...listPaused()];
|
|
734
|
-
if (paused.length === 0) {
|
|
735
|
-
console.log("manifold: no flows are paused.");
|
|
736
|
-
return;
|
|
737
|
-
}
|
|
738
|
-
for (const flowId of paused) {
|
|
739
|
-
const f = await store.get(flowId);
|
|
740
|
-
const pipelineId = f?.stateJson?.pipelineId ?? "(unknown)";
|
|
741
|
-
console.log(` ${flowId.slice(0, 8)} ${pipelineId} status=${f?.status ?? "(missing)"}`);
|
|
742
|
-
}
|
|
743
|
-
}));
|
|
744
|
-
}
|
|
745
|
-
|
|
746
|
-
function safeParseJson(s) {
|
|
747
|
-
try { return JSON.parse(s); } catch { return null; }
|
|
748
|
-
}
|
|
749
|
-
|
|
750
|
-
function browserOpenCommand(url) {
|
|
751
|
-
// Per-platform opener. macOS `open`, Linux `xdg-open`, Windows `start` via
|
|
752
|
-
// cmd /c. Returns { cmd, args } or { cmd: null } if the platform is unknown.
|
|
753
|
-
if (process.platform === "darwin") return { cmd: "open", args: [url] };
|
|
754
|
-
if (process.platform === "win32") return { cmd: "cmd", args: ["/c", "start", "", url] };
|
|
755
|
-
if (process.platform === "linux") return { cmd: "xdg-open", args: [url] };
|
|
756
|
-
return { cmd: null, args: [] };
|
|
757
|
-
}
|
|
758
|
-
|
|
759
|
-
const USAGE = `usage: manifold <command>
|
|
760
|
-
|
|
761
|
-
serve [--pipelines-dir DIR] boot the manifold app (API, executor, dashboard)
|
|
762
|
-
serve --mcp stdio|http [--port N] [--host H] [--pipelines-dir DIR]
|
|
763
|
-
serve the pipeline tools over MCP stdio or Streamable HTTP
|
|
764
|
-
(stdio harness from MANIFOLD_HARNESS env only; agent+session stamped per call;
|
|
765
|
-
http additionally needs MANIFOLD_BEARER + X-Manifold-Harness per session)
|
|
766
|
-
serve --ws [--port N] [--host H] stream push events over WebSocket (verbatim + history replay)`;
|
|
767
|
-
|
|
768
|
-
function fail(msg, code = 2) {
|
|
769
|
-
console.error(msg);
|
|
770
|
-
process.exit(code);
|
|
771
|
-
}
|
|
772
|
-
|
|
773
|
-
function stderrLogger() {
|
|
774
|
-
return {
|
|
775
|
-
info: (...a) => console.error(...a),
|
|
776
|
-
warn: (...a) => console.error(...a),
|
|
777
|
-
error: (...a) => console.error(...a),
|
|
778
|
-
};
|
|
779
|
-
}
|
|
780
|
-
|
|
781
|
-
export async function runCli(argv) {
|
|
782
|
-
const [cmd, ...rest] = argv;
|
|
783
|
-
switch (cmd) {
|
|
784
|
-
case undefined:
|
|
785
|
-
case "--help":
|
|
786
|
-
case "-h":
|
|
787
|
-
case "help":
|
|
788
|
-
console.log(USAGE);
|
|
789
|
-
return;
|
|
790
|
-
|
|
791
|
-
case "serve": {
|
|
792
|
-
let values;
|
|
793
|
-
try {
|
|
794
|
-
({ values } = parseArgs({
|
|
795
|
-
args: rest,
|
|
796
|
-
options: {
|
|
797
|
-
ws: { type: "boolean" },
|
|
798
|
-
mcp: { type: "string" },
|
|
799
|
-
port: { type: "string" },
|
|
800
|
-
host: { type: "string" },
|
|
801
|
-
"pipelines-dir": { type: "string" },
|
|
802
|
-
},
|
|
803
|
-
}));
|
|
804
|
-
} catch (err) {
|
|
805
|
-
if (/Unknown option|ERR_PARSE_ARGS_UNKNOWN_OPTION/.test(String(err?.message ?? err))) {
|
|
806
|
-
fail("manifold serve --mcp takes no --harness flag: set MANIFOLD_HARNESS in the environment.");
|
|
807
|
-
}
|
|
808
|
-
throw err;
|
|
809
|
-
}
|
|
810
|
-
if (values.mcp !== undefined && values.mcp !== "stdio" && values.mcp !== "http") {
|
|
811
|
-
fail(`manifold: --mcp must be stdio or http, got ${JSON.stringify(values.mcp)}`);
|
|
812
|
-
}
|
|
813
|
-
const modes = ["ws", "mcp"].filter((k) => values[k]);
|
|
814
|
-
if (modes.length > 1) {
|
|
815
|
-
fail("usage: manifold serve [--pipelines-dir DIR] | --ws | --mcp stdio|http");
|
|
816
|
-
}
|
|
817
|
-
const logger = stderrLogger();
|
|
818
|
-
if (modes.length === 0) {
|
|
819
|
-
// No mode flag: the full app — stores, executor, pipelines watcher,
|
|
820
|
-
// revival, HTTP API and dashboard — as its own process. The harness
|
|
821
|
-
// adapter spawns exactly this and bridges agent turns over HTTP.
|
|
822
|
-
if (values["pipelines-dir"]) process.env.MANIFOLD_PIPELINES_DIR = values["pipelines-dir"];
|
|
823
|
-
const { serve } = await import("../server/serve.js");
|
|
824
|
-
await serve({ logger }).catch((err) => fail(`manifold serve: ${err?.message ?? err}`, 1));
|
|
825
|
-
return;
|
|
826
|
-
}
|
|
827
|
-
const host = values.host ?? "127.0.0.1";
|
|
828
|
-
const port = values.port ? Number(values.port) : undefined;
|
|
829
|
-
if (port !== undefined && !(Number.isInteger(port) && port >= 1 && port <= 65535)) {
|
|
830
|
-
fail(`manifold: --port must be 1-65535, got ${JSON.stringify(values.port)}`);
|
|
831
|
-
}
|
|
832
|
-
const servePipelinesDir = values["pipelines-dir"] ?? null;
|
|
833
|
-
if (values.mcp === "stdio") {
|
|
834
|
-
const ops = await createRealOps({ pipelinesDir: servePipelinesDir, logger }).catch((err) => fail(`manifold: ops wiring failed: ${err?.message ?? err}`, 1));
|
|
835
|
-
// Harness is env-only here by design: the spawner owns identity.
|
|
836
|
-
await startMcpServer({ ops, logger }).catch((err) => fail(String(err?.message ?? err)));
|
|
837
|
-
return;
|
|
838
|
-
}
|
|
839
|
-
if (values.mcp === "http") {
|
|
840
|
-
const { startMcpHttpServer } = await import("../mcp/http.js");
|
|
841
|
-
const ops = await createRealOps({ pipelinesDir: servePipelinesDir, logger }).catch((err) => fail(`manifold: ops wiring failed: ${err?.message ?? err}`, 1));
|
|
842
|
-
await startMcpHttpServer({ ops, port, host, logger }).catch((err) => fail(String(err?.message ?? err)));
|
|
843
|
-
return;
|
|
844
|
-
}
|
|
845
|
-
const stream = createEventStream();
|
|
846
|
-
await startWsServer({ stream, port: port ?? DEFAULT_WS_PORT, host, logger });
|
|
847
|
-
logger.info(`manifold: events on ws://${host}:${port ?? DEFAULT_WS_PORT} (verbatim; subscribers track their own state)`);
|
|
848
|
-
return;
|
|
849
|
-
}
|
|
850
|
-
|
|
851
|
-
default:
|
|
852
|
-
fail(`unknown command: ${cmd}\n\n${USAGE}`);
|
|
853
|
-
}
|
|
854
|
-
}
|