@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/routes/discuss-audio.js
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
// Audio constants and filesystem helpers for discuss audio upload/serve/history.
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { resolveStorePaths, harnessMediaAudioDir } from "../state/paths.js";
|
|
4
|
-
import { assertDeclaration } from "../mcp/identity.js";
|
|
5
|
-
|
|
6
|
-
export const AUDIO_MIME_EXT = {
|
|
7
|
-
"audio/m4a": "m4a",
|
|
8
|
-
"audio/mp4": "m4a",
|
|
9
|
-
"audio/aac": "m4a",
|
|
10
|
-
"audio/x-m4a": "m4a",
|
|
11
|
-
"audio/mpeg": "mp3",
|
|
12
|
-
"audio/mp3": "mp3",
|
|
13
|
-
"audio/wav": "wav",
|
|
14
|
-
"audio/x-wav": "wav",
|
|
15
|
-
"audio/webm": "webm",
|
|
16
|
-
"audio/ogg": "ogg",
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export const EXT_TO_MIME = {
|
|
20
|
-
m4a: "audio/m4a",
|
|
21
|
-
mp3: "audio/mpeg",
|
|
22
|
-
wav: "audio/wav",
|
|
23
|
-
webm: "audio/webm",
|
|
24
|
-
ogg: "audio/ogg",
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
// Harness namespace for stored audio, declared per connection like every
|
|
28
|
-
// other harness identity (mcp/identity.js): the X-Manifold-Harness header
|
|
29
|
-
// on the request that delivered the audio. Never env, never defaulted —
|
|
30
|
-
// an undeclared harness refuses before any filesystem touch.
|
|
31
|
-
export function resolveAudioHarness(req) {
|
|
32
|
-
const header = req?.headers?.["x-manifold-harness"];
|
|
33
|
-
const { harness } = assertDeclaration({ harness: Array.isArray(header) ? header[0] : header });
|
|
34
|
-
return harness;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// Media root for the given harness: <store-home>/media/audio/<harness>.
|
|
38
|
-
// Resolved per call so a MANIFOLD_DATA_DIR change between import and first
|
|
39
|
-
// use still relocates the store. The harness is required — callers pass
|
|
40
|
-
// the connection-declared value (resolveAudioHarness), never a default.
|
|
41
|
-
export function harnessAudioDir(harness) {
|
|
42
|
-
return harnessMediaAudioDir(resolveStorePaths().dataDir, harness);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export function audioRootForFlow(flowId, harness) {
|
|
46
|
-
return path.join(harnessAudioDir(harness), flowId);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// Single search root: this harness's media dir. No cross-harness reads.
|
|
50
|
-
export function audioRootsForFlow(flowId, harness) {
|
|
51
|
-
return [audioRootForFlow(flowId, harness)];
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export function audioDirForFlow(flowId, itemId, harness) {
|
|
55
|
-
const safeItem = String(itemId).replace(/[^a-zA-Z0-9._-]+/g, "_").slice(0, 120) || "_";
|
|
56
|
-
return path.join(audioRootForFlow(flowId, harness), safeItem);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// Read all .meta.json sidecars under <store-home>/media/audio/<harness>/<flowId>/
|
|
60
|
-
// across every item sub-directory. Returns a flat array of parsed meta objects,
|
|
61
|
-
// [] when the root is absent.
|
|
62
|
-
export async function loadAudioMetasForFlow(flowId, harness) {
|
|
63
|
-
return (await readMetasUnder(audioRootForFlow(flowId, harness))) ?? [];
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// Null when the root is absent; an array otherwise.
|
|
67
|
-
async function readMetasUnder(root) {
|
|
68
|
-
const { readdir, readFile } = await import("node:fs/promises");
|
|
69
|
-
let itemDirs;
|
|
70
|
-
try { itemDirs = await readdir(root); }
|
|
71
|
-
catch { return null; }
|
|
72
|
-
const metas = [];
|
|
73
|
-
for (const itemDir of itemDirs) {
|
|
74
|
-
let files;
|
|
75
|
-
try { files = await readdir(path.join(root, itemDir)); }
|
|
76
|
-
catch { continue; }
|
|
77
|
-
for (const f of files) {
|
|
78
|
-
if (!f.endsWith(".meta.json")) continue;
|
|
79
|
-
try {
|
|
80
|
-
const text = await readFile(path.join(root, itemDir, f), "utf8");
|
|
81
|
-
const parsed = JSON.parse(text);
|
|
82
|
-
if (parsed && typeof parsed === "object") metas.push(parsed);
|
|
83
|
-
} catch { /* skip corrupt sidecar */ }
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
return metas;
|
|
87
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
// routes/discuss-component.js — component fan-out for gate discuss.
|
|
2
|
-
//
|
|
3
|
-
// componentEmitter persists the component, then emits the canonical
|
|
4
|
-
// discuss.component.proposed plus the derived discuss.pending.updated
|
|
5
|
-
// through the shared emitter. The pending derivation (draft→text,
|
|
6
|
-
// meta→fields) lives here, beside the emit — not duplicated in each
|
|
7
|
-
// producer — because it is what cold-reconnect replays.
|
|
8
|
-
export function createComponentEmitter({ discussStore, emit }) {
|
|
9
|
-
return function componentEmitter({ flowId, itemId, component }) {
|
|
10
|
-
return Promise.resolve().then(async () => {
|
|
11
|
-
try { await discussStore.setComponent(flowId, itemId, component); } catch {}
|
|
12
|
-
if (!emit) return;
|
|
13
|
-
try {
|
|
14
|
-
await emit("discuss.component.proposed", { flowId, itemId, component });
|
|
15
|
-
} catch {}
|
|
16
|
-
if (component.kind === "proposed_draft") {
|
|
17
|
-
try {
|
|
18
|
-
await emit("discuss.pending.updated", {
|
|
19
|
-
flowId,
|
|
20
|
-
itemId,
|
|
21
|
-
text: component.text ?? null,
|
|
22
|
-
fields: null,
|
|
23
|
-
updatedAt: component.updatedAt ?? Date.now(),
|
|
24
|
-
});
|
|
25
|
-
} catch {}
|
|
26
|
-
} else if (component.kind === "proposed_meta") {
|
|
27
|
-
try {
|
|
28
|
-
await emit("discuss.pending.updated", {
|
|
29
|
-
flowId,
|
|
30
|
-
itemId,
|
|
31
|
-
text: null,
|
|
32
|
-
fields: component.fields ?? null,
|
|
33
|
-
updatedAt: component.updatedAt ?? Date.now(),
|
|
34
|
-
});
|
|
35
|
-
} catch {}
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
};
|
|
39
|
-
}
|
package/routes/discuss-draft.js
DELETED
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
// Draft persistence helpers for discuss handlers.
|
|
2
|
-
// These functions mutate flow waitJson (via store.setWaiting).
|
|
3
|
-
import { looksLikeMetaNarration } from "./discuss-helpers.js";
|
|
4
|
-
|
|
5
|
-
export async function persistRevisedDraft({ flowId, itemId, newDraft, source, store, logger }) {
|
|
6
|
-
if (source !== "app" && looksLikeMetaNarration(newDraft)) {
|
|
7
|
-
return { applied: false, code: "rejected_meta_narration" };
|
|
8
|
-
}
|
|
9
|
-
{
|
|
10
|
-
const flow = await store.get(flowId);
|
|
11
|
-
if (!flow) return { applied: false, code: "flow_not_found" };
|
|
12
|
-
}
|
|
13
|
-
for (let attempt = 0; attempt < 5; attempt++) {
|
|
14
|
-
const flow = await store.get(flowId);
|
|
15
|
-
if (!flow) return { applied: false, code: "flow_not_found" };
|
|
16
|
-
if (flow.waitJson?.kind !== "human-gate" && flow.waitJson?.kind !== "gate") return { applied: false, code: "not_a_gate" };
|
|
17
|
-
const items = Array.isArray(flow.waitJson?.items) ? flow.waitJson.items : [];
|
|
18
|
-
const targetItemId = itemId ?? items[0]?.itemId;
|
|
19
|
-
const idx = items.findIndex((it) => it?.itemId === targetItemId);
|
|
20
|
-
if (idx < 0) return { applied: false, code: "item_not_found" };
|
|
21
|
-
const nextItems = items.map((it, i) => {
|
|
22
|
-
if (i !== idx) return it;
|
|
23
|
-
return {
|
|
24
|
-
...it,
|
|
25
|
-
requestPayload: {
|
|
26
|
-
...(it.requestPayload ?? {}),
|
|
27
|
-
editableText: newDraft,
|
|
28
|
-
},
|
|
29
|
-
};
|
|
30
|
-
});
|
|
31
|
-
const result = await store.setWaiting({
|
|
32
|
-
flowId,
|
|
33
|
-
expectedRevision: flow.revision,
|
|
34
|
-
lastStep: flow.lastStep,
|
|
35
|
-
stateJson: flow.stateJson,
|
|
36
|
-
waitJson: { ...flow.waitJson, items: nextItems },
|
|
37
|
-
statusReason: flow.statusReason,
|
|
38
|
-
});
|
|
39
|
-
if (result.applied) return { applied: true };
|
|
40
|
-
if (result.code !== "revision_conflict") return { applied: false, code: result.code };
|
|
41
|
-
await new Promise((r) => setTimeout(r, 25 + attempt * 25));
|
|
42
|
-
}
|
|
43
|
-
return { applied: false, code: "retry_exhausted" };
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// Field `type`s that a gate-layout.js declares for genuinely numeric data
|
|
47
|
-
// (currency amounts, day counts). A value destined for one of these MUST
|
|
48
|
-
// arrive as a real JS number — a numeric string (e.g. from a lenient
|
|
49
|
-
// client) is rejected outright rather than silently coerced, so a malformed
|
|
50
|
-
// edit fails loudly instead of writing a value nothing validated.
|
|
51
|
-
const NUMERIC_FIELD_TYPES = new Set(["money", "number"]);
|
|
52
|
-
|
|
53
|
-
function collectLayoutFieldTypes(layout) {
|
|
54
|
-
const types = {};
|
|
55
|
-
if (!Array.isArray(layout)) return types;
|
|
56
|
-
for (const entry of layout) {
|
|
57
|
-
if (!entry) continue;
|
|
58
|
-
if (entry.kind === "field" && typeof entry.id === "string" && typeof entry.type === "string") {
|
|
59
|
-
types[entry.id] = entry.type;
|
|
60
|
-
} else if (entry.kind === "field-group" && Array.isArray(entry.fields)) {
|
|
61
|
-
for (const f of entry.fields) {
|
|
62
|
-
if (f && typeof f.id === "string" && typeof f.type === "string") types[f.id] = f.type;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
return types;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export async function persistRevisedMeta({ flowId, itemId, fields, store, logger }) {
|
|
70
|
-
if (!fields || typeof fields !== "object" || Object.keys(fields).length === 0) {
|
|
71
|
-
return { applied: false, code: "empty_fields" };
|
|
72
|
-
}
|
|
73
|
-
{
|
|
74
|
-
const flow = await store.get(flowId);
|
|
75
|
-
if (!flow) return { applied: false, code: "flow_not_found" };
|
|
76
|
-
}
|
|
77
|
-
for (let attempt = 0; attempt < 5; attempt++) {
|
|
78
|
-
const flow = await store.get(flowId);
|
|
79
|
-
if (!flow) return { applied: false, code: "flow_not_found" };
|
|
80
|
-
if (flow.waitJson?.kind !== "human-gate" && flow.waitJson?.kind !== "gate") return { applied: false, code: "not_a_gate" };
|
|
81
|
-
const items = Array.isArray(flow.waitJson?.items) ? flow.waitJson.items : [];
|
|
82
|
-
const targetItemId = itemId ?? items[0]?.itemId;
|
|
83
|
-
const idx = items.findIndex((it) => it?.itemId === targetItemId);
|
|
84
|
-
if (idx < 0) return { applied: false, code: "item_not_found" };
|
|
85
|
-
// Reject the whole call if any field the pipeline declares numeric
|
|
86
|
-
// (type: "money"/"number" in its own gate-layout.js) is being set to
|
|
87
|
-
// something other than a real number — e.g. a numeric-looking string.
|
|
88
|
-
// Fields the layout doesn't know about (legacy callers, unknown ids)
|
|
89
|
-
// fall through unchecked since there's no declared type to enforce.
|
|
90
|
-
const fieldTypes = collectLayoutFieldTypes(items[idx]?.requestPayload?.layout);
|
|
91
|
-
for (const [key, v] of Object.entries(fields)) {
|
|
92
|
-
const declaredType = fieldTypes[key];
|
|
93
|
-
if (declaredType && NUMERIC_FIELD_TYPES.has(declaredType) && typeof v !== "number") {
|
|
94
|
-
return { applied: false, code: "invalid_field_type", field: key, expectedType: "number" };
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
const nextItems = items.map((it, i) => {
|
|
98
|
-
if (i !== idx) return it;
|
|
99
|
-
const rp = it.requestPayload ?? {};
|
|
100
|
-
// Legacy shape — no current gate-layout.js produces a top-level
|
|
101
|
-
// requestPayload.editableFields (executor-helpers.js enforces every
|
|
102
|
-
// gate declares `layout` explicitly), but patch it too in case
|
|
103
|
-
// anything still reads it.
|
|
104
|
-
const isPatchable = (v) => typeof v === "string" || typeof v === "number";
|
|
105
|
-
const nextFieldsArr = Array.isArray(rp.editableFields)
|
|
106
|
-
? rp.editableFields.map((f) => {
|
|
107
|
-
if (!f || typeof f.id !== "string") return f;
|
|
108
|
-
const v = fields[f.id];
|
|
109
|
-
if (!isPatchable(v)) return f;
|
|
110
|
-
return { ...f, value: String(v) };
|
|
111
|
-
})
|
|
112
|
-
: rp.editableFields;
|
|
113
|
-
// Real shape — gate-projector.js's projectGateItem() serves
|
|
114
|
-
// rp.layout verbatim to clients, so a budget/timeframe/language edit
|
|
115
|
-
// has to land here or the chip never reflects it, regardless of
|
|
116
|
-
// editableMeta/editableFields getting updated correctly.
|
|
117
|
-
const nextLayout = Array.isArray(rp.layout)
|
|
118
|
-
? rp.layout.map((entry) => {
|
|
119
|
-
if (!entry) return entry;
|
|
120
|
-
if (entry.kind === "field" && typeof entry.id === "string" && isPatchable(fields[entry.id])) {
|
|
121
|
-
return { ...entry, value: String(fields[entry.id]) };
|
|
122
|
-
}
|
|
123
|
-
if (entry.kind === "field-group" && Array.isArray(entry.fields)) {
|
|
124
|
-
return {
|
|
125
|
-
...entry,
|
|
126
|
-
fields: entry.fields.map((f) =>
|
|
127
|
-
f && typeof f.id === "string" && isPatchable(fields[f.id])
|
|
128
|
-
? { ...f, value: String(fields[f.id]) }
|
|
129
|
-
: f
|
|
130
|
-
),
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
return entry;
|
|
134
|
-
})
|
|
135
|
-
: rp.layout;
|
|
136
|
-
return {
|
|
137
|
-
...it,
|
|
138
|
-
requestPayload: {
|
|
139
|
-
...rp,
|
|
140
|
-
editableMeta: { ...(rp.editableMeta ?? {}), ...fields },
|
|
141
|
-
editableFields: nextFieldsArr,
|
|
142
|
-
layout: nextLayout,
|
|
143
|
-
},
|
|
144
|
-
};
|
|
145
|
-
});
|
|
146
|
-
const result = await store.setWaiting({
|
|
147
|
-
flowId,
|
|
148
|
-
expectedRevision: flow.revision,
|
|
149
|
-
lastStep: flow.lastStep,
|
|
150
|
-
stateJson: flow.stateJson,
|
|
151
|
-
waitJson: { ...flow.waitJson, items: nextItems },
|
|
152
|
-
statusReason: flow.statusReason,
|
|
153
|
-
});
|
|
154
|
-
if (result.applied) return { applied: true };
|
|
155
|
-
if (result.code !== "revision_conflict") return { applied: false, code: result.code };
|
|
156
|
-
await new Promise((r) => setTimeout(r, 25 + attempt * 25));
|
|
157
|
-
}
|
|
158
|
-
return { applied: false, code: "retry_exhausted" };
|
|
159
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
// Pure helpers for discuss handlers — no I/O, no closure deps, fully unit-testable.
|
|
2
|
-
|
|
3
|
-
export const DRAFT_META_PREFIXES = [
|
|
4
|
-
/^draft\b.{0,80}(written|saved|done|updated|complete)/i,
|
|
5
|
-
/^here'?s\s+/i,
|
|
6
|
-
/^below\s+is/i,
|
|
7
|
-
/^above\s+is/i,
|
|
8
|
-
/^the\s+(new|revised|updated)\s+(version|draft|reply|text)/i,
|
|
9
|
-
/^i\s+(have\s+)?revised/i,
|
|
10
|
-
/^revised\s+(version|draft)/i,
|
|
11
|
-
/^changes?:/i,
|
|
12
|
-
/^(before|after)\s*(\(|:)/i,
|
|
13
|
-
];
|
|
14
|
-
|
|
15
|
-
export function looksLikeMetaNarration(text) {
|
|
16
|
-
const trimmed = text.trim();
|
|
17
|
-
if (trimmed.length < 40) return true;
|
|
18
|
-
const firstLine = trimmed.split("\n", 1)[0].trim();
|
|
19
|
-
return DRAFT_META_PREFIXES.some((re) => re.test(firstLine));
|
|
20
|
-
}
|