suppa-mcp-2 1.46.1 → 1.47.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -5
- package/dist/server.js +189 -5
- package/dist/toolTable.js +3 -1
- package/dist/tools/entity.js +25 -5
- package/dist/tools/formInheritance.js +238 -0
- package/dist/tools/formLifecycle.js +117 -6
- package/dist/tools/formV2.js +126 -10
- package/dist/tools/query.js +33 -5
- package/dist/tools/registers.js +817 -0
- package/package.json +1 -1
- package/skills/suppa-cli/SKILL.md +1 -1
- package/skills/suppa-entity-code/references/entities.md +1 -0
- package/skills/suppa-entity-code/scripts/validate-suppa-schema.mjs +13 -1
- package/skills/suppa-form-v2/SKILL.md +5 -5
- package/skills/suppa-form-v2/SOURCE.json +4 -4
- package/skills/suppa-form-v2/data/base-props.json +9 -0
- package/skills/suppa-form-v2/data/component-index.json +32 -1
- package/skills/suppa-form-v2/data/component-props.json +1199 -19
- package/skills/suppa-form-v2/data/templates/entity-workspace.json +22 -23
- package/skills/suppa-form-v2/data/templates/list-management.json +22 -0
- package/skills/suppa-form-v2/notes/dynamicComponent.md +57 -1
- package/skills/suppa-form-v2/references/choosing-elements.md +2 -2
- package/skills/suppa-form-v2/references/code-form.md +13 -0
- package/skills/suppa-form-v2/references/publishing.md +2 -0
- package/skills/suppa-form-v2/scripts/form-core.mjs +979 -488
- package/skills/suppa-form-v2/scripts/form-rules.mjs +2 -2
- package/skills/suppa-form-v2/scripts/manifest-corrections.mjs +37 -0
- package/skills/suppa-form-v2/scripts/validate-form-schema.mjs +188 -10
- package/skills/suppa-registers/SKILL.md +49 -0
- package/skills/suppa-registers/references/concepts.md +75 -0
- package/skills/suppa-registers/references/errors.md +26 -0
- package/skills/suppa-registers/references/operations.md +55 -0
- package/skills/suppa-registers/references/reads.md +57 -0
- package/skills/suppa-registers/references/rules.md +63 -0
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A CHILD form judged by the tree a reader gets, not by the layer it stores.
|
|
3
|
+
*
|
|
4
|
+
* A 2.1 form with a `parent` stores only its own layer: the `schema.overrides` it applies to the parent and the
|
|
5
|
+
* elements it adds (entity-builder form-schema.service.ts getSchema: "draft mode stays the child's RAW own layer").
|
|
6
|
+
* Its `settings` are its own too, so the parent's grid (`settings.columnsNumber: 12`) is not in them. Gated on that
|
|
7
|
+
* layer alone, an element placed in an inherited container is `dangling_parent`, and one spanning the inherited
|
|
8
|
+
* 12-column root grid is `span_exceeds_parent_columns` against a root grid of 1 — the false refusals of seven
|
|
9
|
+
* create-form children on modern-expo.test (forms 1910–1916, 2026-12-01).
|
|
10
|
+
*
|
|
11
|
+
* What a publish freezes is the MERGED tree: entity-builder form-publish.service.ts `buildSnapshot` reads
|
|
12
|
+
* `buildEffectiveSchema` — the merge `GET /core/forms/:id/effective-schema` answers — and strips the inheritance
|
|
13
|
+
* bookkeeping (`stripInheritanceMeta`, `stripCollectionMeta`, `settingsEntriesToObject`). So the gate judges that
|
|
14
|
+
* tree, read the same way: an entry tagged `_state: 'removed'` (an inherited element the child deleted — the builder
|
|
15
|
+
* view tags it and never filters it) is not on the form, every other tag is dropped, and the settings arrive as an
|
|
16
|
+
* ARRAY of `{ key, value, _state }` entries that become the plain object a draft carries.
|
|
17
|
+
*
|
|
18
|
+
* The code-typing path (formCode.ts formTypes) reads the same endpoint for the same reason.
|
|
19
|
+
*/
|
|
20
|
+
import { makeRequest } from "../httpClient.js";
|
|
21
|
+
const isObj = (v) => !!v && typeof v === "object" && !Array.isArray(v);
|
|
22
|
+
const msgOf = (e) => (e instanceof Error ? e.message : String(e));
|
|
23
|
+
const isRefId = (v) => Number.isSafeInteger(v) && v > 0 ? v : isObj(v) ? isRefId(v.id) : null;
|
|
24
|
+
/** Keys a settings object never takes from a wire entry (entity-builder isForbiddenSettingsKey keeps the same out). */
|
|
25
|
+
const FORBIDDEN_KEYS = new Set(["__proto__", "constructor", "prototype"]);
|
|
26
|
+
/**
|
|
27
|
+
* The parent a form names, or null for a root form — `parentForm` (GET /core/forms/:id/schema) or `parent`
|
|
28
|
+
* (a Forms select), a real reference only: a positive id, or an object holding one.
|
|
29
|
+
*/
|
|
30
|
+
export function parentFormId(form) {
|
|
31
|
+
if (!isObj(form))
|
|
32
|
+
return null;
|
|
33
|
+
return isRefId(form.parentForm) ?? isRefId(form.parent);
|
|
34
|
+
}
|
|
35
|
+
/** The FormVersions row a child is pinned to (`parentVersion`, a number or `{ id }`), or null. */
|
|
36
|
+
export function parentVersionId(form) {
|
|
37
|
+
return isObj(form) ? isRefId(form.parentVersion) : null;
|
|
38
|
+
}
|
|
39
|
+
/** A collection entry without its inheritance tag, or null for one the child removed. */
|
|
40
|
+
function live(entry) {
|
|
41
|
+
if (!isObj(entry) || entry._state === "removed")
|
|
42
|
+
return null;
|
|
43
|
+
const { _state: _ignored, ...rest } = entry;
|
|
44
|
+
return rest;
|
|
45
|
+
}
|
|
46
|
+
const liveList = (list) => (Array.isArray(list) ? list : []).map(live).filter((e) => e !== null);
|
|
47
|
+
/** The effective settings: an array of `{ key, value, _state }` entries, or (an older answer) a plain object. */
|
|
48
|
+
function settingsOf(raw) {
|
|
49
|
+
if (isObj(raw))
|
|
50
|
+
return { ...raw };
|
|
51
|
+
const out = {};
|
|
52
|
+
for (const e of liveList(raw)) {
|
|
53
|
+
if (typeof e.key === "string" && e.key && !FORBIDDEN_KEYS.has(e.key))
|
|
54
|
+
out[e.key] = e.value;
|
|
55
|
+
}
|
|
56
|
+
return out;
|
|
57
|
+
}
|
|
58
|
+
/** The ids a list carries — of elements, or of wires. */
|
|
59
|
+
export function elementIdSet(list) {
|
|
60
|
+
const ids = new Set();
|
|
61
|
+
for (const e of Array.isArray(list) ? list : [])
|
|
62
|
+
if (isObj(e) && e.id != null)
|
|
63
|
+
ids.add(String(e.id));
|
|
64
|
+
return ids;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Every key a wire endpoint may name: an element's `name` or its `id`, nested `children` included — entity-builder
|
|
68
|
+
* effective-connections.ts `endpointKeys` over conflict-detection.ts `flatten`.
|
|
69
|
+
*/
|
|
70
|
+
function endpointKeys(components) {
|
|
71
|
+
const keys = new Set();
|
|
72
|
+
const stack = [...components];
|
|
73
|
+
while (stack.length) {
|
|
74
|
+
const c = stack.pop();
|
|
75
|
+
if (!isObj(c))
|
|
76
|
+
continue;
|
|
77
|
+
if (typeof c.name === "string" && c.name)
|
|
78
|
+
keys.add(c.name);
|
|
79
|
+
if (c.id != null)
|
|
80
|
+
keys.add(String(c.id));
|
|
81
|
+
if (Array.isArray(c.children))
|
|
82
|
+
stack.push(...c.children);
|
|
83
|
+
}
|
|
84
|
+
return keys;
|
|
85
|
+
}
|
|
86
|
+
/** Whether a wire has an endpoint no element answers to. */
|
|
87
|
+
function dangles(wire, keys) {
|
|
88
|
+
return ["from", "to"].some((end) => {
|
|
89
|
+
const e = wire[end];
|
|
90
|
+
const element = isObj(e) ? e.element : undefined;
|
|
91
|
+
return typeof element === "string" && element !== "" && !keys.has(element);
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* The wires a publish freezes. buildSnapshot drops every wire with an endpoint that no merged component answers to
|
|
96
|
+
* (`pruneDanglingConnections`, DSE-7253): a child that removed an inherited element leaves exactly these behind,
|
|
97
|
+
* and gated as they are they read as `dangling_element_ref`, so no such child could be published. The child's OWN
|
|
98
|
+
* wires are kept whatever they point at, so a dangling wire the child authored itself is still reported.
|
|
99
|
+
* `entries` still carry `_state`; the answer does not.
|
|
100
|
+
*/
|
|
101
|
+
function frozenWires(entries, components, isOwn) {
|
|
102
|
+
const keys = endpointKeys(components);
|
|
103
|
+
const wires = [];
|
|
104
|
+
let dropped = 0;
|
|
105
|
+
for (const raw of entries) {
|
|
106
|
+
if (!isObj(raw) || raw._state === "removed")
|
|
107
|
+
continue;
|
|
108
|
+
if (!isOwn(raw) && dangles(raw, keys)) {
|
|
109
|
+
dropped++;
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
const { _state: _ignored, ...wire } = raw;
|
|
113
|
+
wires.push(wire);
|
|
114
|
+
}
|
|
115
|
+
return { wires, dropped };
|
|
116
|
+
}
|
|
117
|
+
/** A wire is the child's own when the effective view tags it `local`, or its id is in the child's own layer. */
|
|
118
|
+
const ownWire = (ownConnectionIds) => (wire) => wire._state === "local" || (wire.id != null && ownConnectionIds.has(String(wire.id)));
|
|
119
|
+
/**
|
|
120
|
+
* The effective-schema answer as the envelope the gate reads — the tree `buildSnapshot` would freeze. A child
|
|
121
|
+
* stays a child on the tenant; this envelope names no parent, because the tree it carries is already whole.
|
|
122
|
+
* `ownConnectionIds` are the ids of the child's own `schema.connections`. An own wire that shadows an inherited id
|
|
123
|
+
* is tagged `overridden`, not `local` (mergeEffectiveConnections), and it is the child's own all the same.
|
|
124
|
+
*/
|
|
125
|
+
export function envelopeFromEffective(eff, ownConnectionIds = new Set()) {
|
|
126
|
+
if (!isObj(eff) || !Array.isArray(eff.components))
|
|
127
|
+
return { error: "the answer carries no `components` list" };
|
|
128
|
+
const components = liveList(eff.components);
|
|
129
|
+
const mobile = liveList(eff.mobileComponents);
|
|
130
|
+
const { wires, dropped } = frozenWires(Array.isArray(eff.connections) ? eff.connections : [], components, ownWire(ownConnectionIds));
|
|
131
|
+
const envelope = {
|
|
132
|
+
schema: components,
|
|
133
|
+
settings: settingsOf(eff.settings),
|
|
134
|
+
variables: liveList(eff.variables),
|
|
135
|
+
...(wires.length ? { connections: wires } : {}),
|
|
136
|
+
...(mobile.length ? { mobileSchema: mobile } : {}),
|
|
137
|
+
};
|
|
138
|
+
return { envelope, removed: eff.components.length - components.length, droppedWires: dropped };
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* The merged tree as it WILL be once a draft write replaces the child's own layer. It starts from the inherited part
|
|
142
|
+
* of the current effective tree: what the parent passes down, with the child's overrides applied (a draft write keeps
|
|
143
|
+
* `schema.overrides`, formV2.ts). The draft's own elements are then added. An own element whose id an inherited one
|
|
144
|
+
* carries SHADOWS it in place, as entity-builder `mergeEffective` does; the rest are appended.
|
|
145
|
+
*
|
|
146
|
+
* `own` holds the ids of the child's CURRENT own layer, whose entries the draft replaces. A `local` element that is
|
|
147
|
+
* not one of them came from an `add` override and stays. Wires work the same way: when the draft sends its wires,
|
|
148
|
+
* every effective wire whose id is in the child's own layer or in the draft's own list is replaced, whatever its tag.
|
|
149
|
+
* An own wire shadowing an inherited id is tagged `overridden`, so going by the tag alone would hold it twice:
|
|
150
|
+
* `invalid_layout`. The inherited wires left are pruned as a publish prunes them (frozenWires).
|
|
151
|
+
*
|
|
152
|
+
* Settings: the draft's keys over the effective ones (the write merges them into the child's own `settings`).
|
|
153
|
+
* Variables: the draft's list replaces the child's own when the file sends one. The mobile list is the effective
|
|
154
|
+
* one, because a draft write never sends `mobileSchema`.
|
|
155
|
+
*/
|
|
156
|
+
export function envelopeWithOwnLayer(eff, own, draft, sentVariables) {
|
|
157
|
+
if (!isObj(eff) || !Array.isArray(eff.components))
|
|
158
|
+
return { error: "the answer carries no `components` list" };
|
|
159
|
+
const keepInherited = (e) => isObj(e) && !(e._state === "local" && e.id != null && own.components.has(String(e.id)));
|
|
160
|
+
const components = liveList(eff.components.filter(keepInherited));
|
|
161
|
+
for (const el of Array.isArray(draft.schema) ? draft.schema : []) {
|
|
162
|
+
const at = isObj(el) && el.id != null ? components.findIndex((c) => String(c.id) === String(el.id)) : -1;
|
|
163
|
+
if (at === -1)
|
|
164
|
+
components.push(el);
|
|
165
|
+
else
|
|
166
|
+
components[at] = el;
|
|
167
|
+
}
|
|
168
|
+
let variables = liveList(eff.variables);
|
|
169
|
+
if (Array.isArray(sentVariables)) {
|
|
170
|
+
const sent = sentVariables.filter(isObj);
|
|
171
|
+
const names = new Set(sent.map((v) => String(v.name ?? "")));
|
|
172
|
+
const inherited = liveList((Array.isArray(eff.variables) ? eff.variables : []).filter((v) => isObj(v) && v._state !== "local"));
|
|
173
|
+
variables = [...inherited.filter((v) => !names.has(String(v.name ?? ""))), ...sent];
|
|
174
|
+
}
|
|
175
|
+
const effWires = Array.isArray(eff.connections) ? eff.connections : [];
|
|
176
|
+
let connections;
|
|
177
|
+
let droppedWires;
|
|
178
|
+
if (Array.isArray(draft.connections)) {
|
|
179
|
+
const sent = draft.connections.filter(isObj);
|
|
180
|
+
const replaced = new Set([...own.connections, ...elementIdSet(sent)]);
|
|
181
|
+
const inherited = effWires.filter((w) => isObj(w) && !(w.id != null && replaced.has(String(w.id))) && w._state !== "local");
|
|
182
|
+
const pruned = frozenWires(inherited, components, () => false);
|
|
183
|
+
connections = [...pruned.wires, ...sent];
|
|
184
|
+
droppedWires = pruned.dropped;
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
const kept = frozenWires(effWires, components, ownWire(own.connections));
|
|
188
|
+
connections = kept.wires;
|
|
189
|
+
droppedWires = kept.dropped;
|
|
190
|
+
}
|
|
191
|
+
const mobile = liveList(eff.mobileComponents);
|
|
192
|
+
return {
|
|
193
|
+
envelope: {
|
|
194
|
+
schema: components,
|
|
195
|
+
settings: { ...settingsOf(eff.settings), ...(isObj(draft.settings) ? draft.settings : {}) },
|
|
196
|
+
variables,
|
|
197
|
+
...(connections.length ? { connections } : {}),
|
|
198
|
+
...(mobile.length ? { mobileSchema: mobile } : {}),
|
|
199
|
+
},
|
|
200
|
+
droppedWires,
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
/** Why a child could not be judged — the gate then REFUSES; it never falls back to the own layer. */
|
|
204
|
+
export function mergedTreeUnavailable(formId, parent, why) {
|
|
205
|
+
return (`form ${formId} is a child of form ${parent}, and its merged tree (GET /core/forms/${formId}/effective-schema) ` +
|
|
206
|
+
`could not be read: ${why}. A child's own layer is not the form a reader gets — its inherited containers and the ` +
|
|
207
|
+
"parent's settings are not in it — so it is not judged on that layer alone, and nothing is passed unchecked. " +
|
|
208
|
+
"Retry; if the read keeps failing, check the form in the builder.");
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* The raw effective-schema answer of a child form, or why it could not be read. Null for a root form, whose own
|
|
212
|
+
* layer IS the form.
|
|
213
|
+
*/
|
|
214
|
+
export async function readChildTree(formId, form) {
|
|
215
|
+
const parent = parentFormId(form);
|
|
216
|
+
if (parent === null)
|
|
217
|
+
return null;
|
|
218
|
+
try {
|
|
219
|
+
const eff = await makeRequest("GET", `/api/core/forms/${formId}/effective-schema`);
|
|
220
|
+
if (!isObj(eff) || !Array.isArray(eff.components)) {
|
|
221
|
+
return { parent, error: mergedTreeUnavailable(formId, parent, "the answer carries no `components` list") };
|
|
222
|
+
}
|
|
223
|
+
return { parent, eff };
|
|
224
|
+
}
|
|
225
|
+
catch (e) {
|
|
226
|
+
return { parent, error: mergedTreeUnavailable(formId, parent, msgOf(e)) };
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* The note a merged judgment carries, so the answer says which tree was checked. Kept under 200 characters: a
|
|
231
|
+
* preview's `proposed_changes` replaces a longer string with its length (confirmRequired).
|
|
232
|
+
*/
|
|
233
|
+
export function mergedTreeNote(parent, envelope, ownCount, droppedWires = 0) {
|
|
234
|
+
const n = Array.isArray(envelope.schema) ? envelope.schema.length : 0;
|
|
235
|
+
return (`a child of form ${parent}: judged on its MERGED tree (effective-schema, ${n} element${n === 1 ? "" : "s"}` +
|
|
236
|
+
`${ownCount !== null ? `, ${ownCount} own` : ""}, the parent's settings included) — the form a reader gets` +
|
|
237
|
+
(droppedWires ? `; ${droppedWires} dead inherited wire${droppedWires === 1 ? "" : "s"} dropped, as on publish` : ""));
|
|
238
|
+
}
|
|
@@ -20,6 +20,11 @@
|
|
|
20
20
|
* the form gate on what gets frozen + version ownership. The gate's baseline is the version that
|
|
21
21
|
* is live now, so a finding the published form already carries does not block — only breakage the
|
|
22
22
|
* new version would introduce.
|
|
23
|
+
*
|
|
24
|
+
* A CHILD form (one with a `parent`) is gated on its MERGED tree — what buildSnapshot freezes, read off
|
|
25
|
+
* `GET /core/forms/:id/effective-schema` (formInheritance.ts) — never on the own layer its draft read returns. A
|
|
26
|
+
* child never published yet has no live version: its baseline is the parent's published version it is pinned to.
|
|
27
|
+
* A merged tree that cannot be read refuses the publish.
|
|
23
28
|
*/
|
|
24
29
|
import { randomUUID } from "node:crypto";
|
|
25
30
|
import { isAbsolute } from "node:path";
|
|
@@ -27,6 +32,7 @@ import { pathToFileURL } from "node:url";
|
|
|
27
32
|
import { makeRequest, searchEntity, selectEntity } from "../httpClient.js";
|
|
28
33
|
import { confirmRequired, jsonResponse } from "../utils.js";
|
|
29
34
|
import { checkerFailed, gateErrorLines, readJson, sentVariables, skillFile, subtractLiveFindings } from "./formV2.js";
|
|
35
|
+
import { elementIdSet, envelopeFromEffective, mergedTreeNote, mergedTreeUnavailable, parentVersionId, readChildTree } from "./formInheritance.js";
|
|
30
36
|
/** The FB2 kinds this can create. `workspace` inherits the base workspace form (setParent). */
|
|
31
37
|
export const CREATABLE_FORM_TYPES = ["create", "update", "custom"];
|
|
32
38
|
export const LIFECYCLE_ACTIONS = ["publish", "rollback", "discard", "promote"];
|
|
@@ -482,6 +488,70 @@ async function gateAgainstLive(envelope, live, what = { kind: "draft" }) {
|
|
|
482
488
|
const { added } = subtractLiveFindings(g.errors, base.checked ? base.errors : []);
|
|
483
489
|
return { ...g, ok: added.length === 0, errors: added, already_live: g.errors.length - added.length };
|
|
484
490
|
}
|
|
491
|
+
/**
|
|
492
|
+
* What a publish freezes, as the envelope the gate reads. A root form: its draft. A CHILD form: its MERGED tree
|
|
493
|
+
* (formInheritance.ts) — buildSnapshot freezes that, and the own layer the draft read returns is not a form on its
|
|
494
|
+
* own. A merged tree that cannot be read is an error, never the own layer: nothing unchecked is published.
|
|
495
|
+
*/
|
|
496
|
+
async function frozenEnvelope(id, draft) {
|
|
497
|
+
const tree = await readChildTree(id, draft);
|
|
498
|
+
if (!tree)
|
|
499
|
+
return { envelope: envelopeOf(draft), child: null };
|
|
500
|
+
if (tree.error !== undefined)
|
|
501
|
+
return { error: tree.error };
|
|
502
|
+
// The child's own wires (its draft's schema.connections) are kept even when they dangle; an inherited wire into an
|
|
503
|
+
// element the child removed is dropped, as buildSnapshot drops it.
|
|
504
|
+
const ownWires = elementIdSet(isObj(draft.schema) ? draft.schema.connections : null);
|
|
505
|
+
const merged = envelopeFromEffective(tree.eff, ownWires);
|
|
506
|
+
if ("error" in merged)
|
|
507
|
+
return { error: mergedTreeUnavailable(id, tree.parent, merged.error) };
|
|
508
|
+
const meta = isObj(tree.eff.inheritanceMeta) ? tree.eff.inheritanceMeta : {};
|
|
509
|
+
const pinned = parentVersionId(draft) ?? parentVersionId({ parentVersion: meta.parentVersionId });
|
|
510
|
+
return {
|
|
511
|
+
envelope: merged.envelope,
|
|
512
|
+
child: {
|
|
513
|
+
parent: tree.parent,
|
|
514
|
+
parentVersion: pinned,
|
|
515
|
+
note: mergedTreeNote(tree.parent, merged.envelope, componentIds(draft.schema).length, merged.droppedWires),
|
|
516
|
+
},
|
|
517
|
+
};
|
|
518
|
+
}
|
|
519
|
+
/**
|
|
520
|
+
* The «already live» baseline of a child that has never been published: the parent's published merge it inherits.
|
|
521
|
+
* First the snapshot of the parent version the child is pinned to — a FormVersions snapshot IS a merged tree
|
|
522
|
+
* (buildSnapshot) — checked to belong to the parent; else the parent's published read. Neither readable: no
|
|
523
|
+
* baseline, which only ever ADDS findings (every inherited one counts), so it is said and never weakens the gate.
|
|
524
|
+
*/
|
|
525
|
+
async function parentBaseline(child) {
|
|
526
|
+
if (child.parentVersion !== null) {
|
|
527
|
+
try {
|
|
528
|
+
const row = await readSnapshot(child.parentVersion);
|
|
529
|
+
const owner = isObj(row?.form) ? Number(row.form.id) : null;
|
|
530
|
+
if (row && isObj(row.snapshot) && owner === child.parent) {
|
|
531
|
+
return {
|
|
532
|
+
baseline: row.snapshot,
|
|
533
|
+
judgedAgainst: `form ${child.parent}'s published version ${row.versionNumber ?? `(FormVersions ${child.parentVersion})`} — the one this child is pinned to; the child itself was never published`,
|
|
534
|
+
};
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
catch {
|
|
538
|
+
/* the published read below */
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
try {
|
|
542
|
+
const pub = await makeRequest("GET", `/api/core/forms/${child.parent}/schema`, null, { query: { mode: "published" } });
|
|
543
|
+
if (isObj(pub) && pub.schema != null) {
|
|
544
|
+
return { baseline: pub, judgedAgainst: `form ${child.parent}'s published version (its published read); the child itself was never published` };
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
catch {
|
|
548
|
+
/* no baseline */
|
|
549
|
+
}
|
|
550
|
+
return {
|
|
551
|
+
baseline: null,
|
|
552
|
+
judgedAgainst: `nothing — the child was never published and form ${child.parent}'s published version could not be read, so every finding counts, inherited ones too`,
|
|
553
|
+
};
|
|
554
|
+
}
|
|
485
555
|
export async function formLifecycle(formId, action, versionId = null, confirm = false, description = null) {
|
|
486
556
|
const id = Number(formId);
|
|
487
557
|
const act = String(action ?? "");
|
|
@@ -541,10 +611,35 @@ export async function formLifecycle(formId, action, versionId = null, confirm =
|
|
|
541
611
|
if (act === "publish" || act === "discard") {
|
|
542
612
|
const draft = (await makeRequest("GET", `/api/core/forms/${id}/schema`));
|
|
543
613
|
if (act === "publish") {
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
614
|
+
const frozen = await frozenEnvelope(id, draft);
|
|
615
|
+
if ("error" in frozen) {
|
|
616
|
+
plan.freezes = { ...compare(liveSnap?.schema, draft.schema), status_now: draft.status };
|
|
617
|
+
plan.gate = frozen.error;
|
|
618
|
+
warnings.push(`the confirmed call will REFUSE this publish: ${frozen.error}`);
|
|
619
|
+
}
|
|
620
|
+
else {
|
|
621
|
+
plan.freezes = { ...compare(liveSnap?.schema, frozen.envelope.schema), status_now: draft.status };
|
|
622
|
+
let baseline = liveSnap;
|
|
623
|
+
if (frozen.child) {
|
|
624
|
+
plan.merged_tree = frozen.child.note;
|
|
625
|
+
if (liveSnap)
|
|
626
|
+
plan.judged_against = "the live version of this child — a merged tree, as every version is";
|
|
627
|
+
else if (live) {
|
|
628
|
+
// Published, but its snapshot did not come back: the parent's version is not this child's baseline.
|
|
629
|
+
plan.judged_against =
|
|
630
|
+
`nothing — the snapshot of this child's live version ${live.id} could not be read, so every finding counts; ` +
|
|
631
|
+
"the confirmed call reads it again and aborts if that fails";
|
|
632
|
+
}
|
|
633
|
+
else {
|
|
634
|
+
const pb = await parentBaseline(frozen.child);
|
|
635
|
+
baseline = pb.baseline;
|
|
636
|
+
plan.judged_against = pb.judgedAgainst;
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
const g = await gateAgainstLive(frozen.envelope, baseline);
|
|
640
|
+
plan.gate = g.checked ? { passes: g.ok, errors: g.errors.length, already_live: g.already_live, warnings: g.warnings.length } : g.error;
|
|
641
|
+
warnings.push(...gateErrorLines(g.errors), ...warningLines(g.warnings));
|
|
642
|
+
}
|
|
548
643
|
plan.effect = "publish: a new default version";
|
|
549
644
|
warnings.push("publishing makes this draft the version every user of this tenant sees; the draft itself is unchanged.");
|
|
550
645
|
}
|
|
@@ -584,10 +679,23 @@ export async function formLifecycle(formId, action, versionId = null, confirm =
|
|
|
584
679
|
if (act === "publish" || act === "rollback") {
|
|
585
680
|
let envelope;
|
|
586
681
|
let baseline;
|
|
682
|
+
let judgedAgainst = null;
|
|
587
683
|
try {
|
|
588
684
|
baseline = await readLiveSnapshot();
|
|
589
685
|
if (act === "publish") {
|
|
590
|
-
|
|
686
|
+
const frozen = await frozenEnvelope(id, (await makeRequest("GET", `/api/core/forms/${id}/schema`)));
|
|
687
|
+
if ("error" in frozen)
|
|
688
|
+
return jsonResponse({ done: false, published: false, error: `${frozen.error} Nothing was published.` });
|
|
689
|
+
envelope = frozen.envelope;
|
|
690
|
+
if (frozen.child && !baseline && live) {
|
|
691
|
+
// Published, yet its live version carries no snapshot: no baseline (stricter), never the parent's version.
|
|
692
|
+
judgedAgainst = `nothing — the snapshot of this child's live version ${live.id} could not be read, so every finding counts`;
|
|
693
|
+
}
|
|
694
|
+
else if (frozen.child && !baseline) {
|
|
695
|
+
const pb = await parentBaseline(frozen.child);
|
|
696
|
+
baseline = pb.baseline;
|
|
697
|
+
judgedAgainst = pb.judgedAgainst;
|
|
698
|
+
}
|
|
591
699
|
}
|
|
592
700
|
else {
|
|
593
701
|
const target = await readSnapshot(vid);
|
|
@@ -608,7 +716,10 @@ export async function formLifecycle(formId, action, versionId = null, confirm =
|
|
|
608
716
|
errors: g.errors,
|
|
609
717
|
warnings: g.warnings,
|
|
610
718
|
already_live: g.already_live,
|
|
611
|
-
|
|
719
|
+
...(judgedAgainst ? { judged_against: judgedAgainst } : {}),
|
|
720
|
+
note: (judgedAgainst
|
|
721
|
+
? `Nothing was published. Judged against ${judgedAgainst}; the findings that baseline already carries were set aside `
|
|
722
|
+
: "Nothing was published. The live version was gated too and its own findings were set aside ") +
|
|
612
723
|
`(${g.already_live} of them), so these are errors the new version would ADD. Fix the draft ` +
|
|
613
724
|
"(suppa_write_form_draft) and publish again.",
|
|
614
725
|
});
|
package/dist/tools/formV2.js
CHANGED
|
@@ -18,6 +18,7 @@ import { makeRequest, selectEntity } from "../httpClient.js";
|
|
|
18
18
|
import * as tasks from "./tasks.js";
|
|
19
19
|
import { confirmRequired, jsonResponse } from "../utils.js";
|
|
20
20
|
import { current as currentTenant } from "../tenants.js";
|
|
21
|
+
import { elementIdSet, envelopeFromEffective, envelopeWithOwnLayer, mergedTreeNote, readChildTree } from "./formInheritance.js";
|
|
21
22
|
/** A file inside the bundled suppa-form-v2 skill, from dist/tools/ or src/tools/ alike. */
|
|
22
23
|
export function skillFile(...parts) {
|
|
23
24
|
const here = dirname(fileURLToPath(import.meta.url));
|
|
@@ -38,7 +39,7 @@ export function skillFile(...parts) {
|
|
|
38
39
|
* agents with all 96 tools both reached for suppa_create_form, which writes the v1 blob.
|
|
39
40
|
*/
|
|
40
41
|
export const FORM_V2_INSTRUCTION_LINE = "FORMS — TWO PRODUCTS: suppa_create_form/update_form write `data.formShema` (Suppa 1.0). A Suppa 2.x form " +
|
|
41
|
-
"is the `schema` COLUMN,
|
|
42
|
+
"is the `schema` COLUMN, 62 types (pre-2.1: `data.formSchema`): suppa_get_form reads it; suppa_form_kb, " +
|
|
42
43
|
"suppa_validate_form_schema (skills/suppa-form-v2/SKILL.md). Publish only on the user's yes.";
|
|
43
44
|
/**
|
|
44
45
|
* Is the vendored core actually USABLE, not merely present?
|
|
@@ -200,7 +201,7 @@ export async function validateFormSchema(path, baselinePath, normalize = false,
|
|
|
200
201
|
}
|
|
201
202
|
let res;
|
|
202
203
|
try {
|
|
203
|
-
res = await mod.validateForm(draft.value, { baseline, normalize, purpose });
|
|
204
|
+
res = await mod.validateForm(draft.value, { baseline, normalize, purpose, mergesStoredSettings: Boolean(baseline) });
|
|
204
205
|
}
|
|
205
206
|
catch (e) {
|
|
206
207
|
// Measured by truncating the vendored core: a bare parse-error message here reads as "your
|
|
@@ -243,7 +244,7 @@ export async function validateFormSchema(path, baselinePath, normalize = false,
|
|
|
243
244
|
/**
|
|
244
245
|
* How many prop tables one `mode='api'` call may return.
|
|
245
246
|
*
|
|
246
|
-
* Twelve is more types than any one form needs at once and far less than the
|
|
247
|
+
* Twelve is more types than any one form needs at once and far less than the 62 that would hand an
|
|
247
248
|
* agent the whole catalog. It exists because the tool's own message promised the catalog could not
|
|
248
249
|
* be fetched in one call, and until this cap that promise was not kept.
|
|
249
250
|
*/
|
|
@@ -269,7 +270,7 @@ export async function formKb(mode, types, topic) {
|
|
|
269
270
|
if (!list.length) {
|
|
270
271
|
return jsonResponse({
|
|
271
272
|
error: "types is required for mode='api' — name the element types you are about to author, e.g. ['input','select'].",
|
|
272
|
-
note: `There is deliberately no way to fetch all
|
|
273
|
+
note: `There is deliberately no way to fetch all 62 at once: stripped of prose they are ~14,200 tokens, and the point of this tool is not to carry them. At most ${MAX_API_TYPES} per call.`,
|
|
273
274
|
});
|
|
274
275
|
}
|
|
275
276
|
// The cap is what makes the sentence above TRUE. Without it, listing all 58 in `types` returned
|
|
@@ -278,7 +279,7 @@ export async function formKb(mode, types, topic) {
|
|
|
278
279
|
if (list.length > MAX_API_TYPES) {
|
|
279
280
|
return jsonResponse({
|
|
280
281
|
error: `types names ${list.length} types; the cap is ${MAX_API_TYPES} per call.`,
|
|
281
|
-
note: "Name the types you are about to author — another call is free. Asking for all
|
|
282
|
+
note: "Name the types you are about to author — another call is free. Asking for all 62 is ~16,300 tokens, which is the cost this tool exists to avoid, not a shortcut.",
|
|
282
283
|
cap: MAX_API_TYPES,
|
|
283
284
|
asked: list.length,
|
|
284
285
|
});
|
|
@@ -302,7 +303,7 @@ export async function formKb(mode, types, topic) {
|
|
|
302
303
|
const haveNotes = list.filter((t) => notes && existsSync(join(notes, `${t}.md`)));
|
|
303
304
|
return jsonResponse({
|
|
304
305
|
props: out,
|
|
305
|
-
...(unknown.length ? { unknown_types: unknown, hint: "Not a V2 component type. Run mode='components' — there are
|
|
306
|
+
...(unknown.length ? { unknown_types: unknown, hint: "Not a V2 component type. Run mode='components' — there are 62, and the name you want may be one you have not met." } : {}),
|
|
306
307
|
...(haveNotes.length ? { notes_available: haveNotes, next: `These types have behaviour notes: mode='note', topic='<type>'. A prop that validates is not a prop that works.` } : {}),
|
|
307
308
|
reminder: "This is the options PANEL, not the runtime. Never invent a prop name or an option value.",
|
|
308
309
|
});
|
|
@@ -858,18 +859,129 @@ export function subtractLiveFindings(errors, live) {
|
|
|
858
859
|
* ({@link subtractLiveFindings}).
|
|
859
860
|
*
|
|
860
861
|
* `already_live` lists what was subtracted, so the answer says it rather than going quiet.
|
|
862
|
+
*
|
|
863
|
+
* A CHILD form (`child` given) is judged on its MERGED tree as the write will leave it (formInheritance.ts
|
|
864
|
+
* envelopeWithOwnLayer), against the merged tree it has now: its own layer alone reads every inherited container
|
|
865
|
+
* as missing and the root grid as 1 column. The own-layer pass still runs — it is what normalizes the draft and
|
|
866
|
+
* compiles its widgets, and its `draft` is what gets WRITTEN (never the merged tree: written as the child's own
|
|
867
|
+
* layer, that would detach the form from its parent) — but the verdict is the merged one. A merged tree that could
|
|
868
|
+
* not be read refuses: the own layer is never the fallback.
|
|
869
|
+
*
|
|
870
|
+
* `--normalize` on a child repairs its own layer against the MERGED settings (the parent's grid and gaps, not a
|
|
871
|
+
* child's empty own settings), and only the settings keys the draft itself carries are written back: the repair's
|
|
872
|
+
* defaults (columnsNumber 12, xGap, yGap …) would otherwise become the child's own settings and shadow the parent's
|
|
873
|
+
* for good.
|
|
861
874
|
*/
|
|
862
|
-
async function gateEdit(mod, draft, live, normalize) {
|
|
875
|
+
async function gateEdit(mod, draft, live, normalize, child = null, sentVars = null) {
|
|
863
876
|
const baseline = live ? liveEnvelope(live) : null;
|
|
864
877
|
// The form row's type is its purpose to the record-card kit (create / update); the gate maps it.
|
|
865
878
|
const purpose = live && typeof live.type === "string" ? live.type : null;
|
|
866
|
-
const
|
|
879
|
+
const context = child && normalize ? withMergedSettings(mod, draft, child) : null;
|
|
880
|
+
const input = context ? context.input : draft;
|
|
881
|
+
// This write merges the draft's settings over the row's, so a draft silent about the root's column count keeps the
|
|
882
|
+
// form's (mergesStoredSettings). A publish or a rollback freezes what is stored, unmerged, and never passes it.
|
|
883
|
+
const g = await mod.validateForm(input, baseline ? { baseline, normalize, purpose, mergesStoredSettings: true } : { normalize, purpose });
|
|
884
|
+
if (child && !g.refused)
|
|
885
|
+
return gateChildEdit(mod, g, child, live, sentVars, purpose, context ? context.ownKeys : null);
|
|
867
886
|
if (g.refused || g.ok || !baseline)
|
|
868
887
|
return { ...g, already_live: [] };
|
|
869
888
|
const own = await mod.validateForm(baseline, { baseline, purpose });
|
|
870
889
|
const { added, already } = subtractLiveFindings(g.errors ?? [], own.refused ? [] : (own.errors ?? []));
|
|
871
890
|
return { ...g, ok: added.length === 0, errors: added, already_live: already };
|
|
872
891
|
}
|
|
892
|
+
/**
|
|
893
|
+
* A child's own layer with the merged settings under its own — what `--normalize` repairs against — and the
|
|
894
|
+
* settings keys the draft itself carries, the only ones written back. Null when either cannot be read (the
|
|
895
|
+
* own-layer pass then runs on the file as it is, and the merged verdict refuses an unreadable tree anyway).
|
|
896
|
+
*/
|
|
897
|
+
function withMergedSettings(mod, draft, child) {
|
|
898
|
+
if (child.error !== undefined || typeof mod.normalizeEnvelope !== "function")
|
|
899
|
+
return null;
|
|
900
|
+
const env = mod.normalizeEnvelope(draft);
|
|
901
|
+
const merged = envelopeFromEffective(child.eff);
|
|
902
|
+
if (!env || env.error || "error" in merged)
|
|
903
|
+
return null;
|
|
904
|
+
const d = env.draft;
|
|
905
|
+
const own = Array.isArray(d.schema) ? d.schema : [];
|
|
906
|
+
const wires = Array.isArray(d.connections) ? { connections: d.connections } : {};
|
|
907
|
+
const ownSettings = d.settings && typeof d.settings === "object" ? d.settings : {};
|
|
908
|
+
const theme = draft && typeof draft === "object" && "theme" in draft ? { theme: draft.theme } : {};
|
|
909
|
+
return {
|
|
910
|
+
input: {
|
|
911
|
+
// An empty own layer is the 2.1 column shape, so that the gate still reads the form as a child (not E202).
|
|
912
|
+
...(own.length ? { schema: own, ...wires } : { schema: { components: [], ...wires } }),
|
|
913
|
+
settings: { ...merged.envelope.settings, ...ownSettings },
|
|
914
|
+
variables: Array.isArray(d.variables) ? d.variables : [],
|
|
915
|
+
...(Array.isArray(d.mobileSchema) ? { mobileSchema: d.mobileSchema } : {}),
|
|
916
|
+
...theme,
|
|
917
|
+
parent: { id: child.parent },
|
|
918
|
+
},
|
|
919
|
+
ownKeys: Object.keys(ownSettings),
|
|
920
|
+
};
|
|
921
|
+
}
|
|
922
|
+
/**
|
|
923
|
+
* The own-layer pass's explanations of a child judged on its layer alone («this is a CHILD form: … only this form's
|
|
924
|
+
* OWN layer», «this child form has NO components of its own … Nothing below was checked») — wrong next to a merged
|
|
925
|
+
* verdict, which did check the whole tree. When the --normalize pass was handed the rebuilt own layer
|
|
926
|
+
* (withMergedSettings), its note on where the element list was read from describes that rebuild, not the file.
|
|
927
|
+
*/
|
|
928
|
+
const OWN_LAYER_CHILD_NOTES = ["this is a CHILD form:", "this child form has NO components of its own"];
|
|
929
|
+
const REBUILT_LAYER_NOTE = "the element list was read from `schema.components`";
|
|
930
|
+
const ownLayerOnlyNote = (note, rebuilt) => {
|
|
931
|
+
const text = String(note);
|
|
932
|
+
return OWN_LAYER_CHILD_NOTES.some((p) => text.startsWith(p)) || (rebuilt && text.startsWith(REBUILT_LAYER_NOTE));
|
|
933
|
+
};
|
|
934
|
+
/** The --normalize note on a child — a count, not the key names: it stays under the 200 characters a preview keeps. */
|
|
935
|
+
export function childNormalizeNote(keysLeftToParent) {
|
|
936
|
+
const n = keysLeftToParent;
|
|
937
|
+
return ("--normalize on a child: repaired against the merged settings; only the draft's own keys are written" +
|
|
938
|
+
(n ? ` (${n} settings key${n === 1 ? " stays" : "s stay"} with the parent)` : "") +
|
|
939
|
+
"; own elements laid out without inherited siblings");
|
|
940
|
+
}
|
|
941
|
+
/** The merged verdict on a child's draft — see {@link gateEdit}. `g` is the own-layer pass, whose `draft` is written. */
|
|
942
|
+
async function gateChildEdit(mod, g, child, live, sentVars, purpose, ownKeys) {
|
|
943
|
+
const unavailable = (detail) => ({
|
|
944
|
+
...g,
|
|
945
|
+
ok: false,
|
|
946
|
+
errors: [{ code: "merged_tree_unavailable", detail }],
|
|
947
|
+
already_live: [],
|
|
948
|
+
});
|
|
949
|
+
if (child.error !== undefined)
|
|
950
|
+
return unavailable(child.error);
|
|
951
|
+
// Under --normalize the repair ran against the merged settings: write back only the keys the draft carries.
|
|
952
|
+
let draftOut = g.draft ?? {};
|
|
953
|
+
const normalizeNotes = [];
|
|
954
|
+
if (ownKeys) {
|
|
955
|
+
const repaired = draftOut.settings && typeof draftOut.settings === "object" ? draftOut.settings : {};
|
|
956
|
+
const kept = Object.fromEntries(Object.entries(repaired).filter(([k]) => ownKeys.includes(k)));
|
|
957
|
+
const left = Object.keys(repaired).filter((k) => !ownKeys.includes(k));
|
|
958
|
+
draftOut = { ...draftOut, settings: kept };
|
|
959
|
+
normalizeNotes.push(childNormalizeNote(left.length));
|
|
960
|
+
}
|
|
961
|
+
const liveSchema = live && live.schema && typeof live.schema === "object" && !Array.isArray(live.schema) ? live.schema : {};
|
|
962
|
+
const own = { components: elementIdSet(liveSchema.components), connections: elementIdSet(liveSchema.connections) };
|
|
963
|
+
const current = envelopeFromEffective(child.eff, own.connections);
|
|
964
|
+
const candidate = envelopeWithOwnLayer(child.eff, own, draftOut, sentVars);
|
|
965
|
+
if ("error" in current)
|
|
966
|
+
return unavailable(current.error);
|
|
967
|
+
if ("error" in candidate)
|
|
968
|
+
return unavailable(candidate.error);
|
|
969
|
+
// The own part is already normalized (and compiled) by the own-layer pass; the inherited part is the parent's and is
|
|
970
|
+
// never repaired here, so the merged pass runs without --normalize.
|
|
971
|
+
const m = await mod.validateForm(candidate.envelope, { baseline: current.envelope, purpose });
|
|
972
|
+
const ownCount = Array.isArray(draftOut.schema) ? draftOut.schema.length : null;
|
|
973
|
+
const notes = [
|
|
974
|
+
...(g.notes ?? []).filter((n) => !ownLayerOnlyNote(n, ownKeys !== null)),
|
|
975
|
+
mergedTreeNote(child.parent, candidate.envelope, ownCount, candidate.droppedWires),
|
|
976
|
+
...normalizeNotes,
|
|
977
|
+
];
|
|
978
|
+
const base = { ...g, draft: draftOut, notes };
|
|
979
|
+
if (m.refused)
|
|
980
|
+
return { ...base, ok: false, errors: m.errors ?? [], warnings: m.warnings ?? [], already_live: [] };
|
|
981
|
+
const self = await mod.validateForm(current.envelope, { baseline: current.envelope, purpose });
|
|
982
|
+
const { added, already } = subtractLiveFindings(m.errors ?? [], self.refused ? [] : (self.errors ?? []));
|
|
983
|
+
return { ...base, ok: added.length === 0, errors: added, warnings: m.warnings ?? [], already_live: already };
|
|
984
|
+
}
|
|
873
985
|
const alreadyLive = (list) => list.map((f) => ({ code: f?.code, elementId: f?.elementId ?? null }));
|
|
874
986
|
/**
|
|
875
987
|
* SOMEONE ELSE HAS IT OPEN. The builder holds `lockedBy` while a form is being edited; writing under them means
|
|
@@ -1061,7 +1173,9 @@ export async function writeFormDraft(formId, path, confirm = false, normalize =
|
|
|
1061
1173
|
if (s) {
|
|
1062
1174
|
const mod = await import(pathToFileURL(s).href);
|
|
1063
1175
|
const live = row && typeof row === "object" ? { ...row, ...(liveVars ? { variables: liveVars } : {}) } : null;
|
|
1064
|
-
|
|
1176
|
+
// A child is judged on its merged tree; an unreadable one is said here and refused on the confirmed call.
|
|
1177
|
+
const child = row ? await readChildTree(id, row) : null;
|
|
1178
|
+
const g = await gateEdit(mod, peek.value, live, normalize, child, draftVars);
|
|
1065
1179
|
draftSettings = (g.draft && typeof g.draft.settings === "object" && g.draft.settings) || {};
|
|
1066
1180
|
draftComponents = g.draft?.schema ?? null;
|
|
1067
1181
|
// The blocking findings travel in `warnings`, whole: a finding's detail is often longer
|
|
@@ -1268,9 +1382,11 @@ export async function writeFormDraft(formId, path, confirm = false, normalize =
|
|
|
1268
1382
|
});
|
|
1269
1383
|
}
|
|
1270
1384
|
}
|
|
1385
|
+
// A child is judged on its merged tree (see gateEdit); when that cannot be read the gate refuses the write.
|
|
1386
|
+
const child = await readChildTree(id, row);
|
|
1271
1387
|
let gate;
|
|
1272
1388
|
try {
|
|
1273
|
-
gate = await gateEdit(mod, read.value, liveVars ? { ...row, variables: liveVars } : row, normalize);
|
|
1389
|
+
gate = await gateEdit(mod, read.value, liveVars ? { ...row, variables: liveVars } : row, normalize, child, draftVars);
|
|
1274
1390
|
}
|
|
1275
1391
|
catch (e) {
|
|
1276
1392
|
return jsonResponse({
|