@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.
Files changed (210) hide show
  1. package/.migrations/ops/0000_futuristic_karma.sql +111 -0
  2. package/.migrations/ops/0001_low_maximus.sql +7 -0
  3. package/.migrations/ops/meta/0000_snapshot.json +763 -0
  4. package/.migrations/ops/meta/0001_snapshot.json +173 -0
  5. package/.migrations/ops/meta/_journal.json +20 -0
  6. package/.migrations/runtime/0000_real_boomer.sql +180 -0
  7. package/.migrations/runtime/0001_hot_dakota_north.sql +2 -0
  8. package/.migrations/runtime/0002_breezy_vertigo.sql +8 -0
  9. package/.migrations/runtime/0003_dashing_jack_flag.sql +5 -0
  10. package/.migrations/runtime/0004_panoramic_ego.sql +1 -0
  11. package/.migrations/runtime/0005_tidy_ben_grimm.sql +10 -0
  12. package/.migrations/runtime/0006_wet_nightmare.sql +57 -0
  13. package/.migrations/runtime/0007_ambiguous_chronomancer.sql +8 -0
  14. package/.migrations/runtime/0008_wealthy_thundra.sql +301 -0
  15. package/.migrations/runtime/0009_lying_shocker.sql +96 -0
  16. package/.migrations/runtime/0010_solid_phantom_reporter.sql +160 -0
  17. package/.migrations/runtime/0011_windy_demogoblin.sql +175 -0
  18. package/.migrations/runtime/0012_restore_harness_fks.sql +103 -0
  19. package/.migrations/runtime/meta/0000_snapshot.json +1181 -0
  20. package/.migrations/runtime/meta/0001_snapshot.json +1209 -0
  21. package/.migrations/runtime/meta/0002_snapshot.json +1261 -0
  22. package/.migrations/runtime/meta/0003_snapshot.json +1292 -0
  23. package/.migrations/runtime/meta/0004_snapshot.json +1240 -0
  24. package/.migrations/runtime/meta/0006_snapshot.json +1310 -0
  25. package/.migrations/runtime/meta/0007_snapshot.json +1362 -0
  26. package/.migrations/runtime/meta/0008_snapshot.json +1742 -0
  27. package/.migrations/runtime/meta/0009_snapshot.json +2413 -0
  28. package/.migrations/runtime/meta/0010_snapshot.json +2562 -0
  29. package/.migrations/runtime/meta/0011_snapshot.json +2812 -0
  30. package/.migrations/runtime/meta/0012_snapshot.json +2812 -0
  31. package/.migrations/runtime/meta/_journal.json +97 -0
  32. package/README.md +1583 -2
  33. package/RELEASING.md +89 -0
  34. package/agent/fleet.js +100 -0
  35. package/bin/cli.js +854 -0
  36. package/bin/manifold.js +4 -0
  37. package/boot/flow-revival.js +536 -0
  38. package/budget/index.js +495 -0
  39. package/budget/lib.js +59 -0
  40. package/dashboard/cost.js +528 -0
  41. package/dashboard/dist/assets/index-CUfp63sj.css +1 -0
  42. package/dashboard/dist/assets/index-Qy9JMpma.js +371 -0
  43. package/dashboard/dist/index.html +13 -0
  44. package/dashboard/event-log.js +267 -0
  45. package/dashboard/index.html +12 -0
  46. package/dashboard/package-lock.json +2877 -0
  47. package/dashboard/package.json +37 -0
  48. package/dashboard/pipeline-graph.js +131 -0
  49. package/dashboard/postcss.config.js +6 -0
  50. package/dashboard/search.js +183 -0
  51. package/dashboard/server.js +1015 -0
  52. package/dashboard/src/App.tsx +42 -0
  53. package/dashboard/src/api/client.ts +118 -0
  54. package/dashboard/src/api/types.ts +510 -0
  55. package/dashboard/src/api/ws.tsx +112 -0
  56. package/dashboard/src/components/CancelButton.tsx +63 -0
  57. package/dashboard/src/components/ClickToCopy.tsx +68 -0
  58. package/dashboard/src/components/CopyButton.tsx +61 -0
  59. package/dashboard/src/components/DailyCostTrend.tsx +85 -0
  60. package/dashboard/src/components/DailyTimeTrend.tsx +94 -0
  61. package/dashboard/src/components/Funnel.tsx +149 -0
  62. package/dashboard/src/components/GateForm.tsx +158 -0
  63. package/dashboard/src/components/GraphView.tsx +302 -0
  64. package/dashboard/src/components/GroupPathsSummary.tsx +47 -0
  65. package/dashboard/src/components/Histogram.tsx +292 -0
  66. package/dashboard/src/components/Layout.tsx +28 -0
  67. package/dashboard/src/components/NeedsAttention.tsx +98 -0
  68. package/dashboard/src/components/NodeContextCard.tsx +132 -0
  69. package/dashboard/src/components/PathTrail.tsx +35 -0
  70. package/dashboard/src/components/PipelineCostBreakdown.tsx +277 -0
  71. package/dashboard/src/components/RerunButton.tsx +46 -0
  72. package/dashboard/src/components/RunComparison.tsx +53 -0
  73. package/dashboard/src/components/Sparkline.tsx +94 -0
  74. package/dashboard/src/components/StatStrip.tsx +147 -0
  75. package/dashboard/src/components/StateTree.tsx +84 -0
  76. package/dashboard/src/components/StatusBadge.tsx +18 -0
  77. package/dashboard/src/components/SubflowPathPills.tsx +38 -0
  78. package/dashboard/src/components/SubflowSummary.tsx +24 -0
  79. package/dashboard/src/components/SubflowsCard.tsx +327 -0
  80. package/dashboard/src/components/TodayStrip.tsx +86 -0
  81. package/dashboard/src/components/TranscriptPane.tsx +99 -0
  82. package/dashboard/src/components/TranscriptRow.tsx +69 -0
  83. package/dashboard/src/components/ui/badge.tsx +38 -0
  84. package/dashboard/src/components/ui/button.tsx +28 -0
  85. package/dashboard/src/components/ui/card.tsx +42 -0
  86. package/dashboard/src/components/ui/skeleton.tsx +9 -0
  87. package/dashboard/src/components/ui/table.tsx +62 -0
  88. package/dashboard/src/index.css +26 -0
  89. package/dashboard/src/lib/anomaly.ts +42 -0
  90. package/dashboard/src/lib/format.ts +30 -0
  91. package/dashboard/src/lib/step-history.ts +13 -0
  92. package/dashboard/src/lib/subflow.ts +154 -0
  93. package/dashboard/src/lib/use-click-outside.ts +28 -0
  94. package/dashboard/src/lib/use-ignored-clusters.ts +67 -0
  95. package/dashboard/src/lib/utils.ts +6 -0
  96. package/dashboard/src/main.tsx +10 -0
  97. package/dashboard/src/types/shims.d.ts +4 -0
  98. package/dashboard/src/views/Home.tsx +478 -0
  99. package/dashboard/src/views/PipelineDetail.tsx +1185 -0
  100. package/dashboard/src/views/PipelinesList.tsx +111 -0
  101. package/dashboard/src/views/RunDetail.tsx +248 -0
  102. package/dashboard/src/views/Search.tsx +196 -0
  103. package/dashboard/stats.js +668 -0
  104. package/dashboard/tailwind.config.ts +43 -0
  105. package/dashboard/tree-stats.js +12 -0
  106. package/dashboard/tsconfig.json +25 -0
  107. package/dashboard/views.js +231 -0
  108. package/dashboard/vite.config.ts +34 -0
  109. package/drizzle.config.js +12 -0
  110. package/drizzle.config.ops.js +12 -0
  111. package/elevation.js +116 -0
  112. package/engine/admission-promotion-resume.js +127 -0
  113. package/engine/agent-dispatch.js +64 -0
  114. package/engine/child-resume-trigger.js +315 -0
  115. package/engine/executor-budget.js +87 -0
  116. package/engine/executor-cancel.js +83 -0
  117. package/engine/executor-errors.js +122 -0
  118. package/engine/executor-helpers.js +254 -0
  119. package/engine/executor-nodes.js +292 -0
  120. package/engine/executor-persist.js +212 -0
  121. package/engine/executor-subflow-children.js +275 -0
  122. package/engine/executor.js +1013 -0
  123. package/engine/global-concurrency.js +33 -0
  124. package/engine/loader.js +528 -0
  125. package/engine/needs-resolver.js +229 -0
  126. package/engine/pipelines-watcher.js +133 -0
  127. package/engine/result-replay.js +34 -0
  128. package/engine/revival-messages.js +11 -0
  129. package/engine/spawn-child.js +55 -0
  130. package/engine/wait-for-flow-settlement.js +109 -0
  131. package/events/catalog.js +26 -0
  132. package/events/emit.js +44 -0
  133. package/events/kinds.js +118 -0
  134. package/events/serve-ws.js +74 -0
  135. package/events/stream.js +35 -0
  136. package/events/ws-dialog.js +257 -0
  137. package/events/ws-frame.js +194 -0
  138. package/events/ws-run-events.js +70 -0
  139. package/events.js +32 -0
  140. package/gates/gate-resolver.js +576 -0
  141. package/gates/paused-flows.js +55 -0
  142. package/graphql/columns.js +67 -0
  143. package/graphql/schema.js +333 -0
  144. package/index.js +49 -0
  145. package/mcp/http.js +159 -0
  146. package/mcp/identity.js +94 -0
  147. package/mcp/stdio.js +80 -0
  148. package/mcp/tools.js +245 -0
  149. package/mcp/wire-ops.js +178 -0
  150. package/package.json +49 -4
  151. package/routes/bearer-auth.js +57 -0
  152. package/routes/discuss-audio.js +87 -0
  153. package/routes/discuss-component.js +39 -0
  154. package/routes/discuss-draft.js +159 -0
  155. package/routes/discuss-helpers.js +20 -0
  156. package/routes/discuss.js +848 -0
  157. package/routes/failures.js +104 -0
  158. package/routes/graphql.js +61 -0
  159. package/routes/health.js +54 -0
  160. package/routes/operator-discuss.js +193 -0
  161. package/routes/operator-resume.js +32 -0
  162. package/routes/operator-retry.js +301 -0
  163. package/routes/operator.js +539 -0
  164. package/routes/pipelines.js +118 -0
  165. package/routes/runs.js +1129 -0
  166. package/scripts/ci/import-check.mjs +50 -0
  167. package/scripts/link-core-self.mjs +31 -0
  168. package/scripts/with-guard.sh +24 -0
  169. package/server/app.js +503 -0
  170. package/server/registry.js +53 -0
  171. package/server/serve.js +163 -0
  172. package/state/admission-queue-store.js +325 -0
  173. package/state/attribution-registries.js +102 -0
  174. package/state/batch-writer.js +162 -0
  175. package/state/db-guard.js +63 -0
  176. package/state/db-health.js +27 -0
  177. package/state/db.js +122 -0
  178. package/state/discuss-store.js +299 -0
  179. package/state/failure-store.js +427 -0
  180. package/state/migrate.js +104 -0
  181. package/state/node-cost.js +67 -0
  182. package/state/node-executions.js +775 -0
  183. package/state/node-health-store.js +124 -0
  184. package/state/ops-merge.js +93 -0
  185. package/state/paths.js +146 -0
  186. package/state/pipeline-dirs.js +99 -0
  187. package/state/pipeline-registry.js +449 -0
  188. package/state/run-store.js +697 -0
  189. package/state/schema.js +438 -0
  190. package/state/schema.ops.js +44 -0
  191. package/state/session-index.js +177 -0
  192. package/state/session-keys.js +39 -0
  193. package/state/state-store.js +311 -0
  194. package/state/subflow-state.js +126 -0
  195. package/state/tool-handoff.js +169 -0
  196. package/telemetry/budget-alert.js +353 -0
  197. package/telemetry/cli.js +331 -0
  198. package/telemetry/grammar.js +119 -0
  199. package/telemetry/http-budget.js +132 -0
  200. package/telemetry/http-cost.js +670 -0
  201. package/telemetry/http-helpers.js +134 -0
  202. package/telemetry/http-tree.js +349 -0
  203. package/telemetry/http.js +44 -0
  204. package/telemetry/index.js +307 -0
  205. package/telemetry/ingest.js +134 -0
  206. package/telemetry/labels.js +115 -0
  207. package/telemetry/pricer.js +77 -0
  208. package/telemetry/resolver.js +314 -0
  209. package/telemetry/store.js +147 -0
  210. package/utils/run-patch.js +43 -0
@@ -0,0 +1,67 @@
1
+ // graphql/columns.js — derive GraphQL leaf fields from the drizzle
2
+ // table defs, so the query layer inherits the database schema instead
3
+ // of restating it.
4
+ //
5
+ // Single source of truth stays state/schema*.js (the same files
6
+ // drizzle-kit generates migrations from). What is PUBLIC is still an
7
+ // explicit choice: each GraphQL type lists the columns it exposes, so a
8
+ // new column is one word to publish and never leaks silently —
9
+ // internals like state_json or tokens stay out by default. A test
10
+ // asserts the built SDL, so a renamed column breaks loudly instead of
11
+ // drifting. Joined/derived extras (pipeline_id via flow_runs, joined
12
+ // node ids) are declared with explicit types beside the table list.
13
+ import {
14
+ GraphQLObjectType,
15
+ GraphQLString,
16
+ GraphQLInt,
17
+ GraphQLFloat,
18
+ GraphQLID,
19
+ GraphQLList,
20
+ GraphQLNonNull,
21
+ } from "graphql";
22
+ import { getTableConfig } from "drizzle-orm/sqlite-core";
23
+
24
+ const SCALARS = {
25
+ SQLiteText: GraphQLString,
26
+ SQLiteInteger: GraphQLInt,
27
+ SQLiteReal: GraphQLFloat,
28
+ };
29
+
30
+ function camel(name) {
31
+ return name.replace(/_([a-z])/g, (_, c) => c.toUpperCase());
32
+ }
33
+
34
+ /**
35
+ * Build the fields map for one GraphQL object type from a drizzle table.
36
+ * columns: exposed entries — a db snake_case name, or { name, as } to
37
+ * pin a stable API name that differs from the column (renames still
38
+ * break loudly: the db name must exist). Extras: { gqlName: type } for
39
+ * joined/derived values that travel beside the row. `id` columns
40
+ * surface as ID!; everything else stays nullable because LEFT JOINs and
41
+ * derivation make DB nullability a liar.
42
+ */
43
+ export function columnFields(table, columns, extras = {}) {
44
+ const byName = {};
45
+ for (const col of getTableConfig(table).columns) byName[col.name] = col;
46
+ const fields = {};
47
+ for (const entry of columns) {
48
+ const name = typeof entry === "string" ? entry : entry.name;
49
+ const gqlName = typeof entry === "string" ? camel(entry) : entry.as;
50
+ const col = byName[name];
51
+ if (!col) throw new Error(`graphql: column ${name} not on table ${getTableConfig(table).name}`);
52
+ const scalar = SCALARS[col.columnType] ?? GraphQLString;
53
+ fields[gqlName] = { type: name === "id" ? new GraphQLNonNull(GraphQLID) : scalar };
54
+ }
55
+ for (const [gqlName, type] of Object.entries(extras)) fields[gqlName] = { type };
56
+ return fields;
57
+ }
58
+
59
+ export function objectType({ name, table, columns, extras, description }) {
60
+ return new GraphQLObjectType({
61
+ name,
62
+ description,
63
+ fields: () => columnFields(table, columns, extras),
64
+ });
65
+ }
66
+
67
+ export { GraphQLString, GraphQLInt, GraphQLFloat, GraphQLID, GraphQLList, GraphQLNonNull };
@@ -0,0 +1,333 @@
1
+ // graphql/schema.js — client-agnostic query layer over manifold state.
2
+ //
3
+ // Any consumer (dashboard, CLI, harness client) picks the fields it needs;
4
+ // the edge stays client-agnostic and never duplicates this.
5
+ // Query-only by design: writes go through the POST routes, so reads
6
+ // never emit domain events (single-writer).
7
+ //
8
+ // Leaf types inherit the database schema (columns.js builds fields from
9
+ // the drizzle table defs — the same files migrations generate from), so
10
+ // a renamed column breaks loudly instead of drifting. Reads come from
11
+ // the domain stores where they exist (failureStore, runStore) and raw
12
+ // sqlite where no store reader exists (queue_items, gate_state,
13
+ // gate_records — same precedent as budget/index.js).
14
+ import os from "node:os";
15
+ import path from "node:path";
16
+ import {
17
+ GraphQLSchema,
18
+ GraphQLObjectType,
19
+ GraphQLString,
20
+ GraphQLInt,
21
+ GraphQLFloat,
22
+ GraphQLList,
23
+ GraphQLNonNull,
24
+ GraphQLID,
25
+ execute,
26
+ parse,
27
+ validate,
28
+ } from "graphql";
29
+ import { failureEvents, flowRuns, queueItems } from "../state/schema.js";
30
+ import { gateState } from "../state/schema.ops.js";
31
+ import { getSharedDb } from "../state/db.js";
32
+ import { objectType } from "./columns.js";
33
+ import { noteDbFailure } from "../state/db-guard.js";
34
+
35
+ export const DEFAULT_RUNTIME_DB = () => path.join(os.homedir(), ".openclaw", "runtime.sqlite");
36
+ export const DEFAULT_OPS_DB = () => path.join(os.homedir(), ".openclaw", "ops.sqlite");
37
+
38
+ // Public leaf subsets: one word to publish a new column, internals
39
+ // (state_json, tokens, handles) stay out by default. Joined extras
40
+ // declared with explicit types beside the table list.
41
+ const Failure = objectType({
42
+ name: "Failure",
43
+ table: failureEvents,
44
+ columns: ["id", "flow_id", "failed_at", { name: "failure_summary", as: "summary" }, "error_type"],
45
+ extras: { pipelineId: GraphQLString, nodeId: GraphQLString },
46
+ });
47
+
48
+ const Approval = objectType({
49
+ name: "Approval",
50
+ table: queueItems,
51
+ columns: ["id", "flow_id", "node", "label", "agent", "created_at"],
52
+ });
53
+
54
+ const Gate = objectType({
55
+ name: "Gate",
56
+ table: gateState,
57
+ columns: ["locked", "day"],
58
+ });
59
+
60
+ const FlowRun = objectType({
61
+ name: "FlowRun",
62
+ table: flowRuns,
63
+ columns: ["flow_id", "pipeline_id", "status", "created_at", "updated_at"],
64
+ extras: { flowId: new GraphQLNonNull(GraphQLID) },
65
+ });
66
+
67
+ const Snapshot = new GraphQLObjectType({
68
+ name: "Snapshot",
69
+ fields: {
70
+ failures: { type: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(Failure))) },
71
+ approvals: { type: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(Approval))) },
72
+ gate: { type: Gate },
73
+ runningCount: { type: new GraphQLNonNull(GraphQLInt) },
74
+ emittedAtMs: { type: GraphQLFloat },
75
+ },
76
+ });
77
+
78
+ const OpenGate = new GraphQLObjectType({
79
+ name: "OpenGate",
80
+ fields: {
81
+ activityId: { type: new GraphQLNonNull(GraphQLID) },
82
+ flowId: { type: new GraphQLNonNull(GraphQLString) },
83
+ itemId: { type: new GraphQLNonNull(GraphQLString) },
84
+ nodeId: { type: GraphQLString },
85
+ pipelineId: { type: GraphQLString },
86
+ agentName: { type: GraphQLString },
87
+ title: { type: GraphQLString },
88
+ emittedAtMs: { type: GraphQLFloat },
89
+ gateKind: { type: GraphQLString },
90
+ payload: { type: new GraphQLNonNull(GraphQLString) },
91
+ },
92
+ });
93
+
94
+ function openDb(dbPath) {
95
+ return getSharedDb(dbPath, { readonly: true }).then(({ client }) => client);
96
+ }
97
+
98
+ function toFailure(r) {
99
+ return {
100
+ id: r.id,
101
+ flowId: r.flow_id ?? r.flowId ?? null,
102
+ pipelineId: r.pipeline_id ?? r.pipelineId ?? null,
103
+ nodeId: r.failure_node ?? r.nodeId ?? null,
104
+ summary: r.failure_summary ?? r.summary ?? null,
105
+ errorType: r.error_type ?? r.errorType ?? null,
106
+ failedAt: r.failed_at ?? r.failedAt ?? null,
107
+ };
108
+ }
109
+
110
+ function toFlowRun(r) {
111
+ if (!r) return null;
112
+ return {
113
+ flowId: r.flowId ?? r.flow_id,
114
+ pipelineId: r.pipelineId ?? r.pipeline_id ?? null,
115
+ status: r.status ?? null,
116
+ createdAt: r.createdAtMs ?? r.createdAt ?? r.created_at ?? null,
117
+ updatedAt: r.updatedAtMs ?? r.updatedAt ?? r.updated_at ?? null,
118
+ };
119
+ }
120
+
121
+ export function createRootValue({
122
+ failureStore = null,
123
+ runStore = null,
124
+ runtimeDbPath = DEFAULT_RUNTIME_DB(),
125
+ opsDbPath = DEFAULT_OPS_DB(),
126
+ logger = null,
127
+ } = {}) {
128
+ const clamp = (limit) => (Number.isInteger(limit) && limit > 0 ? Math.min(limit, 200) : 50);
129
+
130
+ async function queryFailures(limit = 50) {
131
+ try {
132
+ const rows = await failureStore.list({ resolved: false, limit: clamp(limit) });
133
+ return (rows ?? []).map(toFailure);
134
+ } catch (err) {
135
+ logger?.warn?.(`graphql: failures query failed: ${err?.message ?? err}`);
136
+ noteDbFailure(err, { dbPath: runtimeDbPath, logger });
137
+ throw err;
138
+ }
139
+ }
140
+
141
+ async function queryApprovals() {
142
+ try {
143
+ const db = await openDb(runtimeDbPath);
144
+ await db.execute("PRAGMA busy_timeout = 30000");
145
+ const { rows } = await db.execute(
146
+ "SELECT id, flow_id, node, label, agent, created_at FROM queue_items WHERE status = 'pending' ORDER BY created_at DESC LIMIT 200",
147
+ );
148
+ return rows.map((r) => ({
149
+ id: r.id,
150
+ flowId: r.flow_id ?? null,
151
+ node: r.node ?? null,
152
+ label: r.label ?? null,
153
+ agent: r.agent ?? null,
154
+ createdAt: r.created_at ?? null,
155
+ }));
156
+ } catch (err) {
157
+ logger?.warn?.(`graphql: approvals query failed: ${err?.message ?? err}`);
158
+ noteDbFailure(err, { dbPath: runtimeDbPath, logger });
159
+ throw err;
160
+ }
161
+ }
162
+
163
+ async function queryGate() {
164
+ try {
165
+ const db = await openDb(opsDbPath);
166
+ await db.execute("PRAGMA busy_timeout = 30000");
167
+ const { rows } = await db.execute("SELECT locked, day FROM gate_state WHERE id = 'singleton' LIMIT 1");
168
+ const g = rows[0];
169
+ return g ? { locked: g.locked ?? 0, day: g.day ?? null } : null;
170
+ } catch (err) {
171
+ logger?.warn?.(`graphql: gate query failed: ${err?.message ?? err}`);
172
+ noteDbFailure(err, { dbPath: opsDbPath, logger });
173
+ throw err;
174
+ }
175
+ }
176
+
177
+ async function queryRuns(status = null, limit = 50) {
178
+ try {
179
+ const rows = await runStore.listRunsPage({
180
+ status: typeof status === "string" && status.length > 0 ? status : undefined,
181
+ limit: clamp(limit),
182
+ });
183
+ return (rows ?? []).map(toFlowRun);
184
+ } catch (err) {
185
+ logger?.warn?.(`graphql: runs query failed: ${err?.message ?? err}`);
186
+ noteDbFailure(err, { dbPath: runtimeDbPath, logger });
187
+ throw err;
188
+ }
189
+ }
190
+
191
+ async function queryRun(flowId) {
192
+ try {
193
+ return toFlowRun(await runStore.get(flowId));
194
+ } catch (err) {
195
+ logger?.warn?.(`graphql: run query failed: ${err?.message ?? err}`);
196
+ noteDbFailure(err, { dbPath: runtimeDbPath, logger });
197
+ throw err;
198
+ }
199
+ }
200
+
201
+ // Open gate items for triage surfaces, read from persisted gate_records
202
+ // (the engine writes requestPayload incl. layout at gate-block time;
203
+ // consumed records carry consumedAt). Pipeline context resolves per
204
+ // flow through the run store's indexed get — never a full flow_runs
205
+ // scan: on a multi-GB hot file, an unbounded scan races WAL growth
206
+ // and dies with SHORT_READ, while indexed point reads stay clear.
207
+ // Queue context merges from one bounded pending scan.
208
+ async function queryOpenGates() {
209
+ let gateRows = [];
210
+ try {
211
+ const db = await openDb(runtimeDbPath);
212
+ await db.execute("PRAGMA busy_timeout = 30000");
213
+ gateRows = (await db.execute("SELECT flow_id, node_id, record_json, updated_at FROM gate_records")).rows;
214
+ } catch (err) {
215
+ logger?.warn?.(`graphql: openGates records read failed: ${err?.message ?? err}`);
216
+ noteDbFailure(err, { dbPath: runtimeDbPath, logger });
217
+ throw err;
218
+ }
219
+ const agentByItem = {};
220
+ const labelByItem = {};
221
+ try {
222
+ const db = await openDb(runtimeDbPath);
223
+ await db.execute("PRAGMA busy_timeout = 30000");
224
+ const q = await db.execute("SELECT id, label, agent FROM queue_items WHERE status = 'pending'");
225
+ for (const r of q.rows) {
226
+ agentByItem[r.id] = r.agent ?? null;
227
+ labelByItem[r.id] = r.label ?? null;
228
+ }
229
+ } catch {}
230
+ const out = [];
231
+ for (const g of gateRows) {
232
+ let record;
233
+ try {
234
+ record = JSON.parse(g.record_json);
235
+ } catch {
236
+ continue;
237
+ }
238
+ if (record?.consumedAt != null) continue;
239
+ let pipelineId = null;
240
+ try {
241
+ const run = await runStore.get(g.flow_id);
242
+ pipelineId = run?.pipelineId ?? run?.pipeline_id ?? null;
243
+ } catch {}
244
+ for (const item of record?.items ?? []) {
245
+ if (!item?.itemId) continue;
246
+ const rp = item.requestPayload ?? {};
247
+ out.push({
248
+ activityId: `${g.flow_id}:${item.itemId}`,
249
+ flowId: g.flow_id,
250
+ itemId: item.itemId,
251
+ nodeId: g.node_id ?? null,
252
+ pipelineId,
253
+ agentName: agentByItem[item.itemId] ?? null,
254
+ title: rp.title ?? labelByItem[item.itemId] ?? null,
255
+ emittedAtMs: g.updated_at ?? null,
256
+ gateKind: record.kind ?? null,
257
+ payload: JSON.stringify(rp),
258
+ });
259
+ if (out.length >= 200) return out;
260
+ }
261
+ }
262
+ return out;
263
+ }
264
+
265
+ async function runningCount() {
266
+ const list = await queryRuns("running", 200);
267
+ return list.length;
268
+ }
269
+
270
+ return {
271
+ failures: ({ limit }) => queryFailures(limit),
272
+ approvals: () => queryApprovals(),
273
+ gate: () => queryGate(),
274
+ runs: ({ status, limit }) => queryRuns(status, limit),
275
+ run: ({ flowId }) => queryRun(flowId),
276
+ snapshot: async () => ({
277
+ failures: await queryFailures(50),
278
+ approvals: await queryApprovals(),
279
+ gate: await queryGate(),
280
+ runningCount: await runningCount(),
281
+ emittedAtMs: Date.now(),
282
+ }),
283
+ openGates: () => queryOpenGates(),
284
+ };
285
+ }
286
+
287
+ export const schema = new GraphQLSchema({
288
+ // No custom field resolvers: the root value's functions are invoked
289
+ // by the default resolver with (args), so the query layer stays a
290
+ // thin projection over createRootValue.
291
+ query: new GraphQLObjectType({
292
+ name: "Query",
293
+ fields: {
294
+ failures: {
295
+ type: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(Failure))),
296
+ args: { limit: { type: GraphQLInt, defaultValue: 50 } },
297
+ },
298
+ approvals: {
299
+ type: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(Approval))),
300
+ },
301
+ gate: { type: Gate },
302
+ runs: {
303
+ type: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(FlowRun))),
304
+ args: { status: { type: GraphQLString }, limit: { type: GraphQLInt, defaultValue: 50 } },
305
+ },
306
+ run: {
307
+ type: FlowRun,
308
+ args: { flowId: { type: new GraphQLNonNull(GraphQLID) } },
309
+ },
310
+ snapshot: { type: new GraphQLNonNull(Snapshot) },
311
+ openGates: {
312
+ type: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(OpenGate))),
313
+ },
314
+ },
315
+ }),
316
+ types: [Failure, Approval, Gate, FlowRun, Snapshot, OpenGate],
317
+ });
318
+
319
+ export async function executeQuery({ root, query, variables = {} }) {
320
+ let document;
321
+ try {
322
+ document = parse(query);
323
+ } catch (err) {
324
+ return { errors: [{ message: err?.message ?? "invalid query" }] };
325
+ }
326
+ try {
327
+ const validationErrors = validate(schema, document);
328
+ if (validationErrors.length > 0) return { errors: validationErrors.map((e) => ({ message: e.message })) };
329
+ return await execute({ schema, document, rootValue: root, variableValues: variables ?? {} });
330
+ } catch (err) {
331
+ return { errors: [{ message: err?.message ?? "execution failed" }] };
332
+ }
333
+ }
package/index.js ADDED
@@ -0,0 +1,49 @@
1
+ // manifold — neutral core entry: pipeline runtime factories. The gateway
2
+ // plugin entry that wires these factories to a live api lives in
3
+ // plugins/openclaw/manifold/index.js.
4
+
5
+ import { createExecutor } from "./engine/executor.js";
6
+ import { createPipelinesLoader } from "./engine/loader.js";
7
+ import { createStateStore } from "./state/state-store.js";
8
+ import { createRunStore } from "./state/run-store.js";
9
+ import { createFailureStore } from "./state/failure-store.js";
10
+ import { createDiscussStore } from "./state/discuss-store.js";
11
+ import { createSessionIndex } from "./state/session-index.js";
12
+ import { createNodeHealthStore } from "./state/node-health-store.js";
13
+ import { createAdmissionQueueStore } from "./state/admission-queue-store.js";
14
+ import { getNodeExecutionsStore } from "./state/node-executions.js";
15
+ import { createGateResolver } from "./gates/gate-resolver.js";
16
+ import { registerCliCommands } from "./bin/cli.js";
17
+ import { invokeElevated } from "./elevation.js";
18
+
19
+ export {
20
+ createExecutor,
21
+ createPipelinesLoader,
22
+ createStateStore,
23
+ createRunStore,
24
+ createFailureStore,
25
+ createDiscussStore,
26
+ createSessionIndex,
27
+ createNodeHealthStore,
28
+ createAdmissionQueueStore,
29
+ getNodeExecutionsStore,
30
+ createGateResolver,
31
+ registerCliCommands,
32
+ invokeElevated,
33
+ };
34
+
35
+ export default {
36
+ createExecutor,
37
+ createPipelinesLoader,
38
+ createStateStore,
39
+ createRunStore,
40
+ createFailureStore,
41
+ createDiscussStore,
42
+ createSessionIndex,
43
+ createNodeHealthStore,
44
+ createAdmissionQueueStore,
45
+ getNodeExecutionsStore,
46
+ createGateResolver,
47
+ registerCliCommands,
48
+ invokeElevated,
49
+ };
package/mcp/http.js ADDED
@@ -0,0 +1,159 @@
1
+ // http.js — shared Streamable HTTP MCP server.
2
+ // Same tools + same identity contract as stdio (mcp/stdio.js), different
3
+ // door: one TCP socket, many harnesses as HTTP clients.
4
+ //
5
+ // Auth: `Authorization: Bearer <MANIFOLD_BEARER>` checked before any tool
6
+ // runs (MANIFOLD_BEARER required; missing/empty refuses to start). Terminate
7
+ // TLS in front (reverse proxy / ingress) — the server itself speaks plain
8
+ // HTTP. Identity: `X-Manifold-Harness: <name>` declares the harness per
9
+ // session; agent+session still arrive per call via _meta.manifold or stamped
10
+ // args — identical to stdio resolution. GET /health is unauthenticated.
11
+
12
+ import http from "node:http";
13
+ import { randomUUID } from "node:crypto";
14
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
15
+ import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
16
+ import * as z from "zod/v4-mini";
17
+ import { TOOL_DEFS, createManifoldToolHandlers } from "./tools.js";
18
+ import { resolveIdentity, identitySessionKey, assertDeclaration } from "./identity.js";
19
+ import { toolErrorResult } from "./stdio.js";
20
+
21
+ function fieldFromJson(schema) {
22
+ if (!schema || typeof schema !== "object") return z.unknown();
23
+ if (schema.enum && Array.isArray(schema.enum)) return z.enum(schema.enum);
24
+ if (schema.type === "string") return z.string();
25
+ if (schema.type === "boolean") return z.boolean();
26
+ if (schema.type === "integer") return z.number();
27
+ if (schema.type === "array") return z.array(fieldFromJson(schema.items));
28
+ if (schema.type === "object") return z.object(shapeFromJson(schema));
29
+ return z.unknown();
30
+ }
31
+
32
+ function shapeFromJson(schema) {
33
+ const shape = {};
34
+ const required = new Set(schema.required ?? []);
35
+ for (const [key, sub] of Object.entries(schema.properties ?? {})) {
36
+ const field = fieldFromJson(sub);
37
+ shape[key] = required.has(key) ? field : z.optional(field);
38
+ }
39
+ shape.manifold_agent = z.optional(z.string());
40
+ shape.manifold_session = z.optional(z.string());
41
+ shape._meta = z.optional(z.unknown());
42
+ return shape;
43
+ }
44
+
45
+ function readBody(req) {
46
+ return new Promise((resolve, reject) => {
47
+ const chunks = [];
48
+ req.on("data", (c) => chunks.push(c));
49
+ req.on("end", () => {
50
+ if (chunks.length === 0) return resolve(undefined);
51
+ try {
52
+ resolve(JSON.parse(Buffer.concat(chunks).toString("utf8")));
53
+ } catch (err) {
54
+ reject(err);
55
+ }
56
+ });
57
+ req.on("error", reject);
58
+ });
59
+ }
60
+
61
+ export async function startMcpHttpServer({ ops, port = null, host = "127.0.0.1", logger } = {}) {
62
+ const bearer = process.env.MANIFOLD_BEARER;
63
+ if (!bearer || bearer.trim() === "") {
64
+ throw new Error("manifold: serve --mcp http refuses without MANIFOLD_BEARER. Set a bearer token in the environment.");
65
+ }
66
+ const listenPort = port ?? 38293;
67
+ const sessions = new Map();
68
+
69
+ async function sessionFor(req, base) {
70
+ const sid = req.headers["mcp-session-id"];
71
+ if (typeof sid === "string" && sessions.has(sid)) return sessions.get(sid);
72
+ const { handle } = createManifoldToolHandlers(ops);
73
+ const server = new McpServer({ name: "manifold", version: "0.1.0" });
74
+ for (const def of TOOL_DEFS) {
75
+ server.registerTool(
76
+ def.name,
77
+ { description: def.description, inputSchema: z.object(shapeFromJson(def.inputSchema)) },
78
+ async (args, extra) => {
79
+ try {
80
+ const identity = resolveIdentity({ meta: extra?._meta, args, base });
81
+ logger?.info?.(`manifold: ${def.name} from ${identitySessionKey(identity)}`);
82
+ const res = await handle(def.name, args, identity);
83
+ return { content: res.content };
84
+ } catch (err) {
85
+ return toolErrorResult(err);
86
+ }
87
+ }
88
+ );
89
+ }
90
+ const transport = new StreamableHTTPServerTransport({
91
+ sessionIdGenerator: () => randomUUID(),
92
+ onsessioninitialized: (id) => sessions.set(id, { server, transport }),
93
+ });
94
+ transport.onclose = () => {
95
+ for (const [id, entry] of sessions) {
96
+ if (entry.transport === transport) sessions.delete(id);
97
+ }
98
+ };
99
+ await server.connect(transport);
100
+ return { server, transport };
101
+ }
102
+
103
+ const httpServer = http.createServer(async (req, res) => {
104
+ try {
105
+ const url = new URL(req.url ?? "/", "http://x");
106
+ if (url.pathname === "/health") {
107
+ res.writeHead(200, { "content-type": "application/json" });
108
+ res.end(JSON.stringify({ ok: true }));
109
+ return;
110
+ }
111
+ if (url.pathname !== "/mcp") {
112
+ res.writeHead(404, { "content-type": "text/plain" });
113
+ res.end("manifold mcp-http: POST /mcp only\n");
114
+ return;
115
+ }
116
+ const auth = req.headers.authorization ?? "";
117
+ if (auth !== `Bearer ${bearer}`) {
118
+ res.writeHead(401, { "content-type": "application/json" });
119
+ res.end(JSON.stringify({ error: "unauthorized: bad or missing bearer" }));
120
+ return;
121
+ }
122
+ const harness = req.headers["x-manifold-harness"];
123
+ const pipelinesDir = req.headers["x-manifold-pipelines-dir"];
124
+ let base;
125
+ try {
126
+ base = assertDeclaration({
127
+ harness: Array.isArray(harness) ? harness[0] : harness,
128
+ pipelinesDir: Array.isArray(pipelinesDir) ? pipelinesDir[0] : pipelinesDir,
129
+ });
130
+ } catch {
131
+ res.writeHead(400, { "content-type": "application/json" });
132
+ res.end(JSON.stringify({ error: "missing or reserved X-Manifold-Harness" }));
133
+ return;
134
+ }
135
+ const { transport } = await sessionFor(req, base);
136
+ let body;
137
+ if (req.method === "POST") body = await readBody(req);
138
+ await transport.handleRequest(req, res, body);
139
+ } catch (err) {
140
+ logger?.warn?.(`manifold: mcp-http request failed: ${err?.message ?? err}`);
141
+ if (!res.headersSent) {
142
+ res.writeHead(500, { "content-type": "application/json" });
143
+ res.end(JSON.stringify({ error: "internal error" }));
144
+ }
145
+ }
146
+ });
147
+
148
+ return new Promise((resolve, reject) => {
149
+ httpServer.once("error", reject);
150
+ httpServer.listen(listenPort, host, () => {
151
+ logger?.info?.(`manifold: mcp-http on http://${host}:${httpServer.address().port}/mcp (Streamable HTTP; bearer + X-Manifold-Harness)`);
152
+ resolve({
153
+ port: httpServer.address().port,
154
+ host,
155
+ close: () => new Promise((res) => httpServer.close(() => res())),
156
+ });
157
+ });
158
+ });
159
+ }