@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.
Files changed (210) hide show
  1. package/README.md +2 -1583
  2. package/package.json +4 -49
  3. package/.migrations/ops/0000_futuristic_karma.sql +0 -111
  4. package/.migrations/ops/0001_low_maximus.sql +0 -7
  5. package/.migrations/ops/meta/0000_snapshot.json +0 -763
  6. package/.migrations/ops/meta/0001_snapshot.json +0 -173
  7. package/.migrations/ops/meta/_journal.json +0 -20
  8. package/.migrations/runtime/0000_real_boomer.sql +0 -180
  9. package/.migrations/runtime/0001_hot_dakota_north.sql +0 -2
  10. package/.migrations/runtime/0002_breezy_vertigo.sql +0 -8
  11. package/.migrations/runtime/0003_dashing_jack_flag.sql +0 -5
  12. package/.migrations/runtime/0004_panoramic_ego.sql +0 -1
  13. package/.migrations/runtime/0005_tidy_ben_grimm.sql +0 -10
  14. package/.migrations/runtime/0006_wet_nightmare.sql +0 -57
  15. package/.migrations/runtime/0007_ambiguous_chronomancer.sql +0 -8
  16. package/.migrations/runtime/0008_wealthy_thundra.sql +0 -301
  17. package/.migrations/runtime/0009_lying_shocker.sql +0 -96
  18. package/.migrations/runtime/0010_solid_phantom_reporter.sql +0 -160
  19. package/.migrations/runtime/0011_windy_demogoblin.sql +0 -175
  20. package/.migrations/runtime/0012_restore_harness_fks.sql +0 -103
  21. package/.migrations/runtime/meta/0000_snapshot.json +0 -1181
  22. package/.migrations/runtime/meta/0001_snapshot.json +0 -1209
  23. package/.migrations/runtime/meta/0002_snapshot.json +0 -1261
  24. package/.migrations/runtime/meta/0003_snapshot.json +0 -1292
  25. package/.migrations/runtime/meta/0004_snapshot.json +0 -1240
  26. package/.migrations/runtime/meta/0006_snapshot.json +0 -1310
  27. package/.migrations/runtime/meta/0007_snapshot.json +0 -1362
  28. package/.migrations/runtime/meta/0008_snapshot.json +0 -1742
  29. package/.migrations/runtime/meta/0009_snapshot.json +0 -2413
  30. package/.migrations/runtime/meta/0010_snapshot.json +0 -2562
  31. package/.migrations/runtime/meta/0011_snapshot.json +0 -2812
  32. package/.migrations/runtime/meta/0012_snapshot.json +0 -2812
  33. package/.migrations/runtime/meta/_journal.json +0 -97
  34. package/RELEASING.md +0 -89
  35. package/agent/fleet.js +0 -100
  36. package/bin/cli.js +0 -854
  37. package/bin/manifold.js +0 -4
  38. package/boot/flow-revival.js +0 -536
  39. package/budget/index.js +0 -495
  40. package/budget/lib.js +0 -59
  41. package/dashboard/cost.js +0 -528
  42. package/dashboard/dist/assets/index-CUfp63sj.css +0 -1
  43. package/dashboard/dist/assets/index-Qy9JMpma.js +0 -371
  44. package/dashboard/dist/index.html +0 -13
  45. package/dashboard/event-log.js +0 -267
  46. package/dashboard/index.html +0 -12
  47. package/dashboard/package-lock.json +0 -2877
  48. package/dashboard/package.json +0 -37
  49. package/dashboard/pipeline-graph.js +0 -131
  50. package/dashboard/postcss.config.js +0 -6
  51. package/dashboard/search.js +0 -183
  52. package/dashboard/server.js +0 -1015
  53. package/dashboard/src/App.tsx +0 -42
  54. package/dashboard/src/api/client.ts +0 -118
  55. package/dashboard/src/api/types.ts +0 -510
  56. package/dashboard/src/api/ws.tsx +0 -112
  57. package/dashboard/src/components/CancelButton.tsx +0 -63
  58. package/dashboard/src/components/ClickToCopy.tsx +0 -68
  59. package/dashboard/src/components/CopyButton.tsx +0 -61
  60. package/dashboard/src/components/DailyCostTrend.tsx +0 -85
  61. package/dashboard/src/components/DailyTimeTrend.tsx +0 -94
  62. package/dashboard/src/components/Funnel.tsx +0 -149
  63. package/dashboard/src/components/GateForm.tsx +0 -158
  64. package/dashboard/src/components/GraphView.tsx +0 -302
  65. package/dashboard/src/components/GroupPathsSummary.tsx +0 -47
  66. package/dashboard/src/components/Histogram.tsx +0 -292
  67. package/dashboard/src/components/Layout.tsx +0 -28
  68. package/dashboard/src/components/NeedsAttention.tsx +0 -98
  69. package/dashboard/src/components/NodeContextCard.tsx +0 -132
  70. package/dashboard/src/components/PathTrail.tsx +0 -35
  71. package/dashboard/src/components/PipelineCostBreakdown.tsx +0 -277
  72. package/dashboard/src/components/RerunButton.tsx +0 -46
  73. package/dashboard/src/components/RunComparison.tsx +0 -53
  74. package/dashboard/src/components/Sparkline.tsx +0 -94
  75. package/dashboard/src/components/StatStrip.tsx +0 -147
  76. package/dashboard/src/components/StateTree.tsx +0 -84
  77. package/dashboard/src/components/StatusBadge.tsx +0 -18
  78. package/dashboard/src/components/SubflowPathPills.tsx +0 -38
  79. package/dashboard/src/components/SubflowSummary.tsx +0 -24
  80. package/dashboard/src/components/SubflowsCard.tsx +0 -327
  81. package/dashboard/src/components/TodayStrip.tsx +0 -86
  82. package/dashboard/src/components/TranscriptPane.tsx +0 -99
  83. package/dashboard/src/components/TranscriptRow.tsx +0 -69
  84. package/dashboard/src/components/ui/badge.tsx +0 -38
  85. package/dashboard/src/components/ui/button.tsx +0 -28
  86. package/dashboard/src/components/ui/card.tsx +0 -42
  87. package/dashboard/src/components/ui/skeleton.tsx +0 -9
  88. package/dashboard/src/components/ui/table.tsx +0 -62
  89. package/dashboard/src/index.css +0 -26
  90. package/dashboard/src/lib/anomaly.ts +0 -42
  91. package/dashboard/src/lib/format.ts +0 -30
  92. package/dashboard/src/lib/step-history.ts +0 -13
  93. package/dashboard/src/lib/subflow.ts +0 -154
  94. package/dashboard/src/lib/use-click-outside.ts +0 -28
  95. package/dashboard/src/lib/use-ignored-clusters.ts +0 -67
  96. package/dashboard/src/lib/utils.ts +0 -6
  97. package/dashboard/src/main.tsx +0 -10
  98. package/dashboard/src/types/shims.d.ts +0 -4
  99. package/dashboard/src/views/Home.tsx +0 -478
  100. package/dashboard/src/views/PipelineDetail.tsx +0 -1185
  101. package/dashboard/src/views/PipelinesList.tsx +0 -111
  102. package/dashboard/src/views/RunDetail.tsx +0 -248
  103. package/dashboard/src/views/Search.tsx +0 -196
  104. package/dashboard/stats.js +0 -668
  105. package/dashboard/tailwind.config.ts +0 -43
  106. package/dashboard/tree-stats.js +0 -12
  107. package/dashboard/tsconfig.json +0 -25
  108. package/dashboard/views.js +0 -231
  109. package/dashboard/vite.config.ts +0 -34
  110. package/drizzle.config.js +0 -12
  111. package/drizzle.config.ops.js +0 -12
  112. package/elevation.js +0 -116
  113. package/engine/admission-promotion-resume.js +0 -127
  114. package/engine/agent-dispatch.js +0 -64
  115. package/engine/child-resume-trigger.js +0 -315
  116. package/engine/executor-budget.js +0 -87
  117. package/engine/executor-cancel.js +0 -83
  118. package/engine/executor-errors.js +0 -122
  119. package/engine/executor-helpers.js +0 -254
  120. package/engine/executor-nodes.js +0 -292
  121. package/engine/executor-persist.js +0 -212
  122. package/engine/executor-subflow-children.js +0 -275
  123. package/engine/executor.js +0 -1013
  124. package/engine/global-concurrency.js +0 -33
  125. package/engine/loader.js +0 -528
  126. package/engine/needs-resolver.js +0 -229
  127. package/engine/pipelines-watcher.js +0 -133
  128. package/engine/result-replay.js +0 -34
  129. package/engine/revival-messages.js +0 -11
  130. package/engine/spawn-child.js +0 -55
  131. package/engine/wait-for-flow-settlement.js +0 -109
  132. package/events/catalog.js +0 -26
  133. package/events/emit.js +0 -44
  134. package/events/kinds.js +0 -118
  135. package/events/serve-ws.js +0 -74
  136. package/events/stream.js +0 -35
  137. package/events/ws-dialog.js +0 -257
  138. package/events/ws-frame.js +0 -194
  139. package/events/ws-run-events.js +0 -70
  140. package/events.js +0 -32
  141. package/gates/gate-resolver.js +0 -576
  142. package/gates/paused-flows.js +0 -55
  143. package/graphql/columns.js +0 -67
  144. package/graphql/schema.js +0 -333
  145. package/index.js +0 -49
  146. package/mcp/http.js +0 -159
  147. package/mcp/identity.js +0 -94
  148. package/mcp/stdio.js +0 -80
  149. package/mcp/tools.js +0 -245
  150. package/mcp/wire-ops.js +0 -178
  151. package/routes/bearer-auth.js +0 -57
  152. package/routes/discuss-audio.js +0 -87
  153. package/routes/discuss-component.js +0 -39
  154. package/routes/discuss-draft.js +0 -159
  155. package/routes/discuss-helpers.js +0 -20
  156. package/routes/discuss.js +0 -848
  157. package/routes/failures.js +0 -104
  158. package/routes/graphql.js +0 -61
  159. package/routes/health.js +0 -54
  160. package/routes/operator-discuss.js +0 -193
  161. package/routes/operator-resume.js +0 -32
  162. package/routes/operator-retry.js +0 -301
  163. package/routes/operator.js +0 -539
  164. package/routes/pipelines.js +0 -118
  165. package/routes/runs.js +0 -1129
  166. package/scripts/ci/import-check.mjs +0 -50
  167. package/scripts/link-core-self.mjs +0 -31
  168. package/scripts/with-guard.sh +0 -24
  169. package/server/app.js +0 -503
  170. package/server/registry.js +0 -53
  171. package/server/serve.js +0 -163
  172. package/state/admission-queue-store.js +0 -325
  173. package/state/attribution-registries.js +0 -102
  174. package/state/batch-writer.js +0 -162
  175. package/state/db-guard.js +0 -63
  176. package/state/db-health.js +0 -27
  177. package/state/db.js +0 -122
  178. package/state/discuss-store.js +0 -299
  179. package/state/failure-store.js +0 -427
  180. package/state/migrate.js +0 -104
  181. package/state/node-cost.js +0 -67
  182. package/state/node-executions.js +0 -775
  183. package/state/node-health-store.js +0 -124
  184. package/state/ops-merge.js +0 -93
  185. package/state/paths.js +0 -146
  186. package/state/pipeline-dirs.js +0 -99
  187. package/state/pipeline-registry.js +0 -449
  188. package/state/run-store.js +0 -697
  189. package/state/schema.js +0 -438
  190. package/state/schema.ops.js +0 -44
  191. package/state/session-index.js +0 -177
  192. package/state/session-keys.js +0 -39
  193. package/state/state-store.js +0 -311
  194. package/state/subflow-state.js +0 -126
  195. package/state/tool-handoff.js +0 -169
  196. package/telemetry/budget-alert.js +0 -353
  197. package/telemetry/cli.js +0 -331
  198. package/telemetry/grammar.js +0 -119
  199. package/telemetry/http-budget.js +0 -132
  200. package/telemetry/http-cost.js +0 -670
  201. package/telemetry/http-helpers.js +0 -134
  202. package/telemetry/http-tree.js +0 -349
  203. package/telemetry/http.js +0 -44
  204. package/telemetry/index.js +0 -307
  205. package/telemetry/ingest.js +0 -134
  206. package/telemetry/labels.js +0 -115
  207. package/telemetry/pricer.js +0 -77
  208. package/telemetry/resolver.js +0 -314
  209. package/telemetry/store.js +0 -147
  210. package/utils/run-patch.js +0 -43
@@ -1,67 +0,0 @@
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 };
package/graphql/schema.js DELETED
@@ -1,333 +0,0 @@
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 DELETED
@@ -1,49 +0,0 @@
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 DELETED
@@ -1,159 +0,0 @@
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
- }