suppa-mcp-2 1.44.4 → 1.45.0
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 +16 -3
- package/dist/codeForm/api.js +150 -0
- package/dist/codeForm/typecheck.js +324 -0
- package/dist/codeForm/workspace.js +356 -0
- package/dist/httpClient.js +131 -6
- package/dist/projection.js +18 -3
- package/dist/server.js +49 -3
- package/dist/toolTable.js +1 -1
- package/dist/tools/automation.js +16 -1
- package/dist/tools/docs.js +5 -1
- package/dist/tools/entity.js +16 -6
- package/dist/tools/formCode.js +644 -0
- package/dist/tools/formV2.js +53 -41
- package/dist/tools/forms.js +4 -3
- package/dist/tools/tasks.js +7 -7
- package/package.json +5 -3
- package/skills/suppa-cli/SKILL.md +1 -1
- package/skills/suppa-form-v2/SKILL.md +7 -0
- package/skills/suppa-form-v2/code-form/SOURCE.json +19 -0
- package/skills/suppa-form-v2/code-form/sdk/index.d.ts +55926 -0
- package/skills/suppa-form-v2/references/code-form.md +174 -0
- package/skills/suppa-form-v2/scripts/code-form/code-form-core.mjs +562 -0
- package/skills/writing-suppa-sql/references/language.md +1 -1
|
@@ -0,0 +1,644 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* suppa_form_code — a FormBuilder 2.1 form's Code Form (TypeScript against the typed global `formAPI`), written
|
|
3
|
+
* the way the builder's own code editor checks it, without a browser tab.
|
|
4
|
+
*
|
|
5
|
+
* The fb-live MCP does this against a live builder tab (code_pull / code_api / code_check / code_push); this is
|
|
6
|
+
* the same workflow against the tenant:
|
|
7
|
+
* pull GET /core/forms/:id/schema (the draft) → a workspace folder: src/** + the typings the editor uses
|
|
8
|
+
* api the checker's own reading of the SDK: an element, a type, formAPI or a namespace — never the 7 MB file
|
|
9
|
+
* check tsc with the editor's options, the import rule, the formbuilder agent's rules as warnings
|
|
10
|
+
* push (suppa_push_form_code) PUT /core/forms/:id/schema { code, expectedRevision } — the server BUILDS the code on that save and
|
|
11
|
+
* answers buildErrors when the build fails (the form then keeps running its previous build)
|
|
12
|
+
* rules skills/suppa-form-v2/references/code-form.md
|
|
13
|
+
*
|
|
14
|
+
* The typings come from the front, vendored by scripts/sync-code-form.mjs: the SDK declarations
|
|
15
|
+
* (code-form/sdk/index.d.ts) and the generators the editor runs over a form's elements and variables
|
|
16
|
+
* (scripts/code-form/code-form-core.mjs). A form's own `formAPI` type is generated here from the draft's
|
|
17
|
+
* elements — for a child form from its merged tree (GET /core/forms/:id/effective-schema).
|
|
18
|
+
*/
|
|
19
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
20
|
+
import { join } from "node:path";
|
|
21
|
+
import { pathToFileURL } from "node:url";
|
|
22
|
+
import { makeRequest, selectEntity } from "../httpClient.js";
|
|
23
|
+
import { homeDir } from "../registry.js";
|
|
24
|
+
import { current as currentTenant } from "../tenants.js";
|
|
25
|
+
import { confirmRequired } from "../utils.js";
|
|
26
|
+
import { describeApi, formatApi } from "../codeForm/api.js";
|
|
27
|
+
import { checkWorkspace, diagnosticLine, formatCheck, newErrors } from "../codeForm/typecheck.js";
|
|
28
|
+
import * as ws from "../codeForm/workspace.js";
|
|
29
|
+
import { hasV2Evidence, hasV2Kind } from "./forms.js";
|
|
30
|
+
import { formLock, missingCodeRefs, skillFile, staleAnswer } from "./formV2.js";
|
|
31
|
+
const isObj = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
|
|
32
|
+
const msg = (e) => (e instanceof Error ? e.message : String(e));
|
|
33
|
+
let corePromise = null;
|
|
34
|
+
export function loadCore() {
|
|
35
|
+
corePromise ??= (async () => {
|
|
36
|
+
const p = skillFile("scripts", "code-form", "code-form-core.mjs");
|
|
37
|
+
if (!p)
|
|
38
|
+
throw new Error("the Code Form core (skills/suppa-form-v2/scripts/code-form/code-form-core.mjs) is missing — reinstall suppa-mcp-2");
|
|
39
|
+
return (await import(pathToFileURL(p).href));
|
|
40
|
+
})();
|
|
41
|
+
corePromise.catch(() => {
|
|
42
|
+
corePromise = null;
|
|
43
|
+
});
|
|
44
|
+
return corePromise;
|
|
45
|
+
}
|
|
46
|
+
function sdkSource() {
|
|
47
|
+
const p = skillFile("code-form", "sdk", "index.d.ts");
|
|
48
|
+
if (!p)
|
|
49
|
+
throw new Error("the Code Form SDK typings (skills/suppa-form-v2/code-form/sdk/index.d.ts) are missing — reinstall suppa-mcp-2");
|
|
50
|
+
return p;
|
|
51
|
+
}
|
|
52
|
+
/** Is the Code Form toolchain usable? For the health report: the core loads, the SDK is there, TypeScript resolves. */
|
|
53
|
+
export async function codeFormStatus() {
|
|
54
|
+
try {
|
|
55
|
+
const core = await loadCore();
|
|
56
|
+
sdkSource();
|
|
57
|
+
await import("typescript");
|
|
58
|
+
return `present (front ${String(core.FRONT_COMMIT).slice(0, 10)})`;
|
|
59
|
+
}
|
|
60
|
+
catch (e) {
|
|
61
|
+
return `UNUSABLE: ${msg(e)}`;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
// ── the workspace ────────────────────────────────────────────────────────────
|
|
65
|
+
/** The active tenant's host (`dev.suppa.me`, with a port when it has one) — the workspace folder and the manifest's key. */
|
|
66
|
+
const host = () => {
|
|
67
|
+
const base = String(currentTenant()?.baseUrl ?? "");
|
|
68
|
+
try {
|
|
69
|
+
return new URL(base).host || "tenant";
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
return base.replace(/^[a-z]+:\/\//i, "").replace(/\/.*$/, "") || "tenant";
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
function rootFor(dir) {
|
|
76
|
+
return ws.workspaceRoot({ dir, env: process.env.SUPPA_CODE_WORKSPACE || null, cwd: process.cwd(), home: homeDir() });
|
|
77
|
+
}
|
|
78
|
+
const formDir = (formId, dir) => ws.workspaceDir(rootFor(dir), host(), formId);
|
|
79
|
+
// ── the tenant ───────────────────────────────────────────────────────────────
|
|
80
|
+
/** The draft as the builder reads it. A form that is not 2.x has no Code Form. */
|
|
81
|
+
async function readDraft(formId) {
|
|
82
|
+
let got;
|
|
83
|
+
try {
|
|
84
|
+
got = await makeRequest("GET", `/api/core/forms/${formId}/schema`);
|
|
85
|
+
}
|
|
86
|
+
catch (e) {
|
|
87
|
+
if (e?.status === 404 || /^HTTP 404\b/.test(msg(e))) {
|
|
88
|
+
throw new Error(`no form ${formId} on ${host()} that this user can open in the builder`);
|
|
89
|
+
}
|
|
90
|
+
throw e;
|
|
91
|
+
}
|
|
92
|
+
if (!isObj(got))
|
|
93
|
+
throw new Error(`GET /core/forms/${formId}/schema answered 200 with ${got === null ? "null" : typeof got}, not a form`);
|
|
94
|
+
if (!hasV2Evidence(got) && !hasV2Kind(got)) {
|
|
95
|
+
throw new Error(`form ${formId} is a Suppa 1.0 form — Code Form exists only on FormBuilder 2.x forms`);
|
|
96
|
+
}
|
|
97
|
+
return got;
|
|
98
|
+
}
|
|
99
|
+
const filesOf = (draft) => (Array.isArray(draft.code) ? draft.code : []).filter((f) => isObj(f) && typeof f.path === "string" && typeof f.content === "string");
|
|
100
|
+
const parentOf = (draft) => {
|
|
101
|
+
const p = draft.parentForm ?? draft.parent;
|
|
102
|
+
const id = isObj(p) ? p.id : p;
|
|
103
|
+
return Number.isSafeInteger(id) && id > 0 ? id : null;
|
|
104
|
+
};
|
|
105
|
+
/** An element prop, where the stored schema keeps it — on the element or under `options`. */
|
|
106
|
+
const prop = (el, key) => (key in el ? el[key] : isObj(el.options) ? el.options[key] : undefined);
|
|
107
|
+
/** One element as the type generator takes it (FE useGeneratedFormTypes.toElementInput / usePresentations.otherElementInput). */
|
|
108
|
+
function elementInput(core, el) {
|
|
109
|
+
if (!isObj(el) || typeof el.name !== "string" || !el.name || typeof el.type !== "string")
|
|
110
|
+
return null;
|
|
111
|
+
const input = { name: el.name, type: el.type };
|
|
112
|
+
const chartType = prop(el, "chartType");
|
|
113
|
+
const widget = el.type === "dynamicComponent" ? prop(el, "source") : el.type === "chart" && chartType === "custom" ? prop(el, "customView") : undefined;
|
|
114
|
+
if (el.type === "dynamicComponent" || (el.type === "chart" && chartType === "custom")) {
|
|
115
|
+
input.apiMembers = core.extractWidgetApiMembers(typeof widget?.script === "string" ? widget.script : "");
|
|
116
|
+
}
|
|
117
|
+
if (el.type === "chart")
|
|
118
|
+
input.customSources = core.customSourcesOfSchema({ type: "chart", chartType, dataSources: prop(el, "dataSources") }) ?? [];
|
|
119
|
+
return input;
|
|
120
|
+
}
|
|
121
|
+
function variableInput(v) {
|
|
122
|
+
if (!isObj(v) || typeof v.name !== "string" || !v.name)
|
|
123
|
+
return null;
|
|
124
|
+
const entity = typeof v.entity === "string" ? v.entity : isObj(v.entity) && typeof v.entity.name === "string" ? v.entity.name : null;
|
|
125
|
+
return { name: v.name, type: typeof v.type === "string" ? v.type : "object", ...(entity ? { entity } : {}) };
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* The form's typings: its elements and variables as the runtime sees them. A child form's draft holds only its
|
|
129
|
+
* own layer, so its merged tree is read (GET /core/forms/:id/effective-schema) — the builder types a child's code
|
|
130
|
+
* against what renders, not against the layer.
|
|
131
|
+
*/
|
|
132
|
+
async function formTypes(core, formId, draft) {
|
|
133
|
+
const notes = [];
|
|
134
|
+
let desktop = Array.isArray(draft.schema?.components) ? draft.schema.components : [];
|
|
135
|
+
let mobile = Array.isArray(draft.mobileSchema?.components) ? draft.mobileSchema.components : null;
|
|
136
|
+
let variables = Array.isArray(draft.variables) ? draft.variables : [];
|
|
137
|
+
const parent = parentOf(draft);
|
|
138
|
+
if (parent) {
|
|
139
|
+
try {
|
|
140
|
+
const eff = (await makeRequest("GET", `/api/core/forms/${formId}/effective-schema`));
|
|
141
|
+
if (!isObj(eff) || !Array.isArray(eff.components))
|
|
142
|
+
throw new Error("no components in the answer");
|
|
143
|
+
desktop = eff.components;
|
|
144
|
+
mobile = Array.isArray(eff.mobileComponents) && eff.mobileComponents.length ? eff.mobileComponents : mobile;
|
|
145
|
+
if (Array.isArray(eff.variables) && eff.variables.length)
|
|
146
|
+
variables = eff.variables;
|
|
147
|
+
notes.push(`a child of form ${parent}: typed against its MERGED tree (effective-schema), as the builder does`);
|
|
148
|
+
}
|
|
149
|
+
catch (e) {
|
|
150
|
+
notes.push(`⚠ a child of form ${parent}, but its merged tree could not be read (${msg(e)}) — typed against its OWN layer only, so the inherited elements read as missing`);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
const elements = desktop.map((el) => elementInput(core, el)).filter((x) => !!x);
|
|
154
|
+
const others = mobile ? mobile.map((el) => elementInput(core, el)).filter((x) => !!x) : null;
|
|
155
|
+
const vars = variables.map(variableInput).filter((x) => !!x);
|
|
156
|
+
const input = { elements, presentation: "desktop", variables: vars };
|
|
157
|
+
if (others)
|
|
158
|
+
input.otherElements = others;
|
|
159
|
+
return {
|
|
160
|
+
typings: {
|
|
161
|
+
sdk: { source: sdkSource(), stamp: `0.0.0-front.${core.FRONT_COMMIT.slice(0, 10)}` },
|
|
162
|
+
globals: core.generateGlobalsDts(input),
|
|
163
|
+
environment: core.buildEnvironmentDts(),
|
|
164
|
+
sharedModules: core.buildSharedModulesDts(),
|
|
165
|
+
},
|
|
166
|
+
elements: [...desktop, ...(mobile ?? [])].filter(isObj),
|
|
167
|
+
counts: { desktop: elements.length, mobile: others ? others.length : null, variables: vars.length },
|
|
168
|
+
notes,
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
// ── rules the push keeps ─────────────────────────────────────────────────────
|
|
172
|
+
/** An import (static, re-export or dynamic) of a tenant shared module — `@shared/<name>`. */
|
|
173
|
+
const SHARED_IMPORT_RE = /(?:\bfrom\s*|\bimport\s*\(?\s*)(['"])@shared\//;
|
|
174
|
+
export const importsShared = (code) => typeof code === "string" && SHARED_IMPORT_RE.test(code);
|
|
175
|
+
/** The platform bundler's input cap (entity-builder: 512 KiB). */
|
|
176
|
+
const MAX_INPUT_BYTES = 512 * 1024;
|
|
177
|
+
const lines = (text) => (text ? text.split("\n").length - (text.endsWith("\n") ? 1 : 0) : 0);
|
|
178
|
+
function changeSummary(changes) {
|
|
179
|
+
return changes.map((c) => `${c.content === null ? "delete" : c.base === null ? "create" : "edit"} ${c.path}`).join(" · ");
|
|
180
|
+
}
|
|
181
|
+
/** What a change does to the lines of a file — for the plan, not a diff. */
|
|
182
|
+
function lineDelta(c) {
|
|
183
|
+
if (c.content === null)
|
|
184
|
+
return `delete ${c.path} (${lines(c.base ?? "")} lines)`;
|
|
185
|
+
if (c.base === null)
|
|
186
|
+
return `create ${c.path} (${lines(c.content)} lines)`;
|
|
187
|
+
const before = new Set((c.base ?? "").split("\n"));
|
|
188
|
+
const after = new Set(c.content.split("\n"));
|
|
189
|
+
const added = [...after].filter((l) => !before.has(l)).length;
|
|
190
|
+
const removed = [...before].filter((l) => !after.has(l)).length;
|
|
191
|
+
return `edit ${c.path} (+${added} −${removed} lines)`;
|
|
192
|
+
}
|
|
193
|
+
/** Refusals no save may pass: read-only files, the shared-module rule, the paths, the entry, the size. */
|
|
194
|
+
function pushRefusals(changes, current, saved) {
|
|
195
|
+
const out = [];
|
|
196
|
+
const tenant = new Map(current.map((f) => [f.path, f.content]));
|
|
197
|
+
for (const c of changes) {
|
|
198
|
+
if (!ws.isSourcePath(c.path)) {
|
|
199
|
+
out.push(`${c.path}: not a Code Form path — files live under src/, end in .ts, and use letters, digits, _ . / - only`);
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
// On a case-sensitive disk a case twin of the form's file is a new file here and the same file in the editor.
|
|
203
|
+
const twin = current.find((f) => f.path !== c.path && f.path.toLowerCase() === c.path.toLowerCase());
|
|
204
|
+
if (twin && c.content !== null) {
|
|
205
|
+
out.push(`${c.path} differs from the form's ${twin.path} only in case — edit that file instead`);
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
const was = c.base ?? tenant.get(c.path) ?? null;
|
|
209
|
+
if (importsShared(was)) {
|
|
210
|
+
out.push(`${c.path} imports a tenant shared module (@shared/…), so it is READ-ONLY — keep it byte for byte and make the change in another file (the module's code is invisible to every check, runs on import in every viewer's browser, and a public form's anonymous visitor cannot load it)`);
|
|
211
|
+
}
|
|
212
|
+
else if (c.content !== null && importsShared(c.content)) {
|
|
213
|
+
out.push(`${c.path} adds an @shared/… import — never add, rename or move a shared-module import; only a file that already has one may keep it`);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
if (saved.length && !saved.some((f) => f.path === ws.ENTRY_PATH)) {
|
|
217
|
+
out.push(`the code would have no ${ws.ENTRY_PATH} — it is the entry point every other file is reached from`);
|
|
218
|
+
}
|
|
219
|
+
const bytes = saved.reduce((n, f) => n + Buffer.byteLength(f.content), 0);
|
|
220
|
+
if (bytes > MAX_INPUT_BYTES)
|
|
221
|
+
out.push(`the code is ${Math.round(bytes / 1024)} KiB — the platform's build takes at most 512 KiB`);
|
|
222
|
+
return out;
|
|
223
|
+
}
|
|
224
|
+
/** Warnings a save carries but does not refuse. */
|
|
225
|
+
function pushWarnings(changes, manifest, saved) {
|
|
226
|
+
const out = [];
|
|
227
|
+
for (const c of changes) {
|
|
228
|
+
const origin = manifest.origins?.[c.path];
|
|
229
|
+
if (origin && !origin.modified && c.content !== null) {
|
|
230
|
+
out.push(`${c.path} is an UNTOUCHED copy of form ${origin.formId ?? "?"}'s code (detach) — once edited it is the author's own code and a later detach no longer refreshes it; edit it only when the user asked to change THAT behaviour`);
|
|
231
|
+
}
|
|
232
|
+
if (origin && c.content === null) {
|
|
233
|
+
out.push(`${c.path} is a copy of form ${origin.formId ?? "?"}'s code — removing it needs ${ws.ENTRY_PATH} without its import line in the same push`);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
if (!saved.length)
|
|
237
|
+
out.push("the save leaves the form with NO code — it clears the compiled build, and nothing of the form's own code runs any more");
|
|
238
|
+
return out;
|
|
239
|
+
}
|
|
240
|
+
// ── answers ──────────────────────────────────────────────────────────────────
|
|
241
|
+
function buildState(draft) {
|
|
242
|
+
const files = filesOf(draft);
|
|
243
|
+
const hasCode = files.some((f) => f.content.trim());
|
|
244
|
+
const art = isObj(draft.codeArtifact) ? draft.codeArtifact : null;
|
|
245
|
+
if (!hasCode)
|
|
246
|
+
return art ? "build: none needed — the draft has no code (an old build is still stored)" : `no code yet — create ${ws.ENTRY_PATH}`;
|
|
247
|
+
if (!art) {
|
|
248
|
+
return "⚠ build: the draft has code but NO compiled build — the form runs NONE of its code (a save whose build failed, or code that was never saved through the builder); a push rebuilds it";
|
|
249
|
+
}
|
|
250
|
+
return `build: the draft's code runs as built at ${art.builtAt ?? "?"}${art.sdkVersion ? ` (sdk ${art.sdkVersion})` : ""}`;
|
|
251
|
+
}
|
|
252
|
+
function ancestorChain(draft, formId) {
|
|
253
|
+
const chain = Array.isArray(draft.codeArtifacts) ? draft.codeArtifacts.filter((a) => isObj(a) && a.formId !== formId) : [];
|
|
254
|
+
if (!chain.length)
|
|
255
|
+
return null;
|
|
256
|
+
const ids = chain.map((a) => a.formId).filter((id) => id != null);
|
|
257
|
+
return `ancestor code runs too, before this form's: form${ids.length === 1 ? "" : "s"} ${ids.join(", ")} (not in this workspace — it is theirs; this form's own code is)`;
|
|
258
|
+
}
|
|
259
|
+
function readOnlyNotes(manifest) {
|
|
260
|
+
const out = [];
|
|
261
|
+
const shared = Object.entries(manifest.base).filter(([, c]) => importsShared(c)).map(([p]) => p);
|
|
262
|
+
if (shared.length)
|
|
263
|
+
out.push(`read-only: ${shared.join(", ")} — import${shared.length === 1 ? "s" : ""} a tenant shared module (@shared/…); keep byte for byte, change other files`);
|
|
264
|
+
const copies = Object.entries(manifest.origins ?? {});
|
|
265
|
+
if (copies.length) {
|
|
266
|
+
out.push(`ancestor copies (detach): ${copies.map(([p, o]) => `${p} (form ${o.formId ?? "?"}${o.modified ? ", already edited" : ", untouched"})`).join(", ")} — read them; edit one only when the user asks to change that behaviour`);
|
|
267
|
+
}
|
|
268
|
+
return out;
|
|
269
|
+
}
|
|
270
|
+
const divergedNote = (paths) => `⚠ the tenant's draft holds other code than your last sync in ${paths.join(", ")} — someone saved the form (the builder also reformats every file with Prettier on save); mode='pull' shows what it holds now`;
|
|
271
|
+
const RULES_POINTER = "rules: suppa_form_code mode='rules' — read them once before writing code";
|
|
272
|
+
// ── modes ────────────────────────────────────────────────────────────────────
|
|
273
|
+
export async function pull(formId, dir, force, inline) {
|
|
274
|
+
const core = await loadCore();
|
|
275
|
+
const workspace = formDir(formId, dir);
|
|
276
|
+
const pending = ws.unsyncedEdits(workspace, ws.readManifest(workspace));
|
|
277
|
+
if (pending.length && !force) {
|
|
278
|
+
return `refused — ${workspace} has edits that are not on the tenant yet: ${changeSummary(pending)}. Push them (suppa_push_form_code), or pull with force=true to discard them.`;
|
|
279
|
+
}
|
|
280
|
+
const stray = ws.strayFiles(workspace);
|
|
281
|
+
if (stray.length && !force) {
|
|
282
|
+
return `refused — a pull replaces src/, and it holds files that are not Code Form sources (only src/**/*.ts is the form's code): ${stray.join(", ")}. Move them out, or pull with force=true to delete them.`;
|
|
283
|
+
}
|
|
284
|
+
const draft = await readDraft(formId);
|
|
285
|
+
const types = await formTypes(core, formId, draft);
|
|
286
|
+
const manifest = ws.writeWorkspace(workspace, {
|
|
287
|
+
host: host(),
|
|
288
|
+
formId,
|
|
289
|
+
formName: typeof draft.name === "string" ? draft.name : null,
|
|
290
|
+
revision: typeof draft.updatedAt === "string" ? draft.updatedAt : null,
|
|
291
|
+
files: filesOf(draft),
|
|
292
|
+
typings: types.typings,
|
|
293
|
+
compilerOptions: core.codeFormTsconfigOptions(),
|
|
294
|
+
frontCommit: core.FRONT_COMMIT,
|
|
295
|
+
});
|
|
296
|
+
const held = Object.keys(manifest.base);
|
|
297
|
+
const out = [
|
|
298
|
+
`pulled the DRAFT code of form ${formId}${manifest.formName ? ` «${manifest.formName}»` : ""} (${host()}, revision ${manifest.revision ?? "?"}, status ${draft.status ?? "?"}) into`,
|
|
299
|
+
workspace,
|
|
300
|
+
held.length ? held.map((p) => `${p} (${lines(manifest.base[p])} lines)`).join(" · ") : `(no files — create ${ws.ENTRY_PATH})`,
|
|
301
|
+
`typed against ${types.counts.desktop} desktop element${types.counts.desktop === 1 ? "" : "s"}${types.counts.mobile !== null ? ` + ${types.counts.mobile} mobile` : ""} and ${types.counts.variables} variable${types.counts.variables === 1 ? "" : "s"}; SDK as of front ${core.FRONT_COMMIT.slice(0, 10)}`,
|
|
302
|
+
...types.notes,
|
|
303
|
+
buildState(draft),
|
|
304
|
+
...[ancestorChain(draft, formId)].filter((x) => !!x),
|
|
305
|
+
...readOnlyNotes(manifest),
|
|
306
|
+
`edit src/** with your file tools · mode='api' for what you may call · mode='check' type-checks · suppa_push_form_code saves to the draft (confirm=true)`,
|
|
307
|
+
RULES_POINTER,
|
|
308
|
+
];
|
|
309
|
+
if (manifest.skipped?.length)
|
|
310
|
+
out.push(`⚠ not in the workspace (not a Code Form path, or a name another file has in a different case): ${manifest.skipped.join(", ")}; a push keeps them as they are`);
|
|
311
|
+
if (inline)
|
|
312
|
+
for (const p of held)
|
|
313
|
+
out.push(`--- ${p}\n${manifest.base[p]}`);
|
|
314
|
+
return out.join("\n");
|
|
315
|
+
}
|
|
316
|
+
/** Re-type the workspace from the draft as it is now: the agent may have added an element since the pull. */
|
|
317
|
+
async function refresh(core, formId, workspace) {
|
|
318
|
+
try {
|
|
319
|
+
const draft = await readDraft(formId);
|
|
320
|
+
const types = await formTypes(core, formId, draft);
|
|
321
|
+
ws.writeTypings(workspace, types.typings);
|
|
322
|
+
return { draft, elements: types.elements, note: types.notes.find((n) => n.startsWith("⚠")) ?? null };
|
|
323
|
+
}
|
|
324
|
+
catch (e) {
|
|
325
|
+
return { draft: null, elements: [], note: `typings from the last pull (the form could not be read now: ${msg(e)})` };
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
function requireManifest(workspace, formId) {
|
|
329
|
+
const manifest = ws.readManifest(workspace);
|
|
330
|
+
if (!manifest)
|
|
331
|
+
throw new Error(`no workspace for form ${formId} in ${workspace} — run mode='pull' first`);
|
|
332
|
+
if (manifest.formId !== formId || manifest.host !== host()) {
|
|
333
|
+
throw new Error(`${workspace} holds form ${manifest.formId} of ${manifest.host}, not form ${formId} of ${host()} — pull again`);
|
|
334
|
+
}
|
|
335
|
+
return manifest;
|
|
336
|
+
}
|
|
337
|
+
/** Element names the code reaches through getElement('…') that the form does not have (TS types `elements.x` itself). */
|
|
338
|
+
function missingLookups(sources, elements, reported) {
|
|
339
|
+
const code = Object.entries(sources).map(([path, content]) => ({ path, content }));
|
|
340
|
+
const missing = missingCodeRefs(code, elements);
|
|
341
|
+
// The typed getElement overload already reports an unknown NAME as TS2345 ('"x"' is not assignable…).
|
|
342
|
+
return missing.filter((name) => !reported.some((d) => d.message.includes(`'${name}'`) || d.message.includes(`"${name}"`)));
|
|
343
|
+
}
|
|
344
|
+
export async function check(formId, dir) {
|
|
345
|
+
const core = await loadCore();
|
|
346
|
+
const workspace = formDir(formId, dir);
|
|
347
|
+
const manifest = requireManifest(workspace, formId);
|
|
348
|
+
const { draft, elements, note } = await refresh(core, formId, workspace);
|
|
349
|
+
const result = await checkWorkspace(workspace, core);
|
|
350
|
+
const out = [formatCheck(result)];
|
|
351
|
+
const sources = ws.readSources(workspace);
|
|
352
|
+
if (draft) {
|
|
353
|
+
const missing = missingLookups(sources, elements, result.diagnostics);
|
|
354
|
+
if (missing.length) {
|
|
355
|
+
out.push(`⚠ getElement(…) names no element of this form: ${missing.map((n) => `'${n}'`).join(", ")} — it answers undefined and that code silently does nothing`);
|
|
356
|
+
}
|
|
357
|
+
const diverged = ws.divergedFiles(filesOf(draft), manifest);
|
|
358
|
+
if (diverged.length)
|
|
359
|
+
out.push(divergedNote(diverged));
|
|
360
|
+
}
|
|
361
|
+
const changes = ws.localChanges(workspace, manifest);
|
|
362
|
+
const refusals = pushRefusals(changes, draft ? filesOf(draft) : [], ws.applyChanges(draft ? filesOf(draft) : Object.entries(manifest.base).map(([path, content]) => ({ path, content })), changes));
|
|
363
|
+
for (const r of refusals)
|
|
364
|
+
out.push(`✗ push would refuse: ${r}`);
|
|
365
|
+
if (note)
|
|
366
|
+
out.push(note);
|
|
367
|
+
out.push("a clean check does not guarantee the server's build: the backend builds with ITS SDK copy — the push answers with the build result");
|
|
368
|
+
return out.join("\n");
|
|
369
|
+
}
|
|
370
|
+
export async function api(formId, dir, subject, member, filter) {
|
|
371
|
+
const core = await loadCore();
|
|
372
|
+
let workspace;
|
|
373
|
+
let note = null;
|
|
374
|
+
if (formId === null) {
|
|
375
|
+
// No form: the SDK with the editor's baseline globals — an element type, formAPI, a namespace.
|
|
376
|
+
if (subject.path && /^formAPI\.(elements|variables)\./.test(subject.path)) {
|
|
377
|
+
throw new Error("a form's own element or variable needs form_id — or ask for its type: type='table'");
|
|
378
|
+
}
|
|
379
|
+
workspace = join(rootFor(dir), "_sdk");
|
|
380
|
+
if (!existsSync(join(workspace, "tsconfig.json")) || !existsSync(join(workspace, ws.SDK_PATH))) {
|
|
381
|
+
ws.writeFile(workspace, "tsconfig.json", `${JSON.stringify({ compilerOptions: core.codeFormTsconfigOptions(), include: ["generated/*.d.ts"] }, null, 2)}\n`);
|
|
382
|
+
}
|
|
383
|
+
ws.writeTypings(workspace, {
|
|
384
|
+
sdk: { source: sdkSource(), stamp: `0.0.0-front.${core.FRONT_COMMIT.slice(0, 10)}` },
|
|
385
|
+
globals: core.buildBaselineGlobalsDts(),
|
|
386
|
+
environment: core.buildEnvironmentDts(),
|
|
387
|
+
sharedModules: core.buildSharedModulesDts(),
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
else {
|
|
391
|
+
workspace = formDir(formId, dir);
|
|
392
|
+
const manifest = ws.readManifest(workspace);
|
|
393
|
+
if (!manifest) {
|
|
394
|
+
const orphans = ws.unsyncedEdits(workspace, null);
|
|
395
|
+
if (orphans.length)
|
|
396
|
+
throw new Error(`${workspace} holds sources but no manifest: ${changeSummary(orphans)} — run mode='pull' (force=true discards them)`);
|
|
397
|
+
await pull(formId, dir, false, false);
|
|
398
|
+
}
|
|
399
|
+
else {
|
|
400
|
+
requireManifest(workspace, formId);
|
|
401
|
+
note = (await refresh(core, formId, workspace)).note;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
const described = await describeApi(workspace, subject.type !== undefined ? { type: subject.type } : { path: subject.path });
|
|
405
|
+
return [formatApi(described, { member, filter }), note].filter(Boolean).join("\n");
|
|
406
|
+
}
|
|
407
|
+
const PUSH_ACTION = "save the form's Code Form to its DRAFT";
|
|
408
|
+
/**
|
|
409
|
+
* Everything a save is judged by, read fresh: the workspace against the draft as it is NOW. Answers a refusal
|
|
410
|
+
* (a sentence) or the save to make. A conflict is recorded here — the other version goes to the conflicts folder
|
|
411
|
+
* and becomes the base — so the agent can merge whether this ran as the preview or as the confirmed call.
|
|
412
|
+
*/
|
|
413
|
+
async function preparePush(core, formId, workspace, files, overwrite, allowErrors) {
|
|
414
|
+
const manifest = requireManifest(workspace, formId);
|
|
415
|
+
if (files?.length)
|
|
416
|
+
ws.writeInlineSources(workspace, files);
|
|
417
|
+
let draft;
|
|
418
|
+
try {
|
|
419
|
+
draft = await readDraft(formId);
|
|
420
|
+
}
|
|
421
|
+
catch (e) {
|
|
422
|
+
return { refused: `nothing saved — the form could not be read (${msg(e)}); a save built over an unread draft is how someone else's code disappears` };
|
|
423
|
+
}
|
|
424
|
+
const current = filesOf(draft);
|
|
425
|
+
const diverged = ws.divergedFiles(current, manifest);
|
|
426
|
+
const changes = ws.localChanges(workspace, manifest);
|
|
427
|
+
if (!changes.length) {
|
|
428
|
+
return {
|
|
429
|
+
refused: diverged.length
|
|
430
|
+
? `nothing to push from the workspace\n${divergedNote(diverged)}`
|
|
431
|
+
: "nothing to push — the workspace matches the form's draft",
|
|
432
|
+
};
|
|
433
|
+
}
|
|
434
|
+
const overwriteSet = new Set(overwrite ?? []);
|
|
435
|
+
const unmerged = ws.unmergedConflicts(manifest, changes, overwriteSet);
|
|
436
|
+
if (unmerged.length) {
|
|
437
|
+
return {
|
|
438
|
+
refused: [
|
|
439
|
+
`refused — nothing saved: ${unmerged.map((c) => c.path).join(", ")} still hold${unmerged.length === 1 ? "s" : ""} exactly the version refused because someone else had changed the file`,
|
|
440
|
+
`merge their version from ${ws.CONFLICTS_DIR}/<path> into src/ first; to replace theirs with yours anyway (the user agreed), push again with overwrite: [${unmerged.map((c) => `"${c.path}"`).join(", ")}]`,
|
|
441
|
+
].join("\n"),
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
const tenant = new Map(current.map((f) => [f.path, f.content]));
|
|
445
|
+
const conflicts = changes.filter((c) => diverged.includes(c.path) && !overwriteSet.has(c.path) && (tenant.get(c.path) ?? null) !== c.content);
|
|
446
|
+
if (conflicts.length) {
|
|
447
|
+
const written = ws.recordConflicts(workspace, manifest, current, conflicts);
|
|
448
|
+
return {
|
|
449
|
+
refused: [
|
|
450
|
+
"refused — nothing saved",
|
|
451
|
+
`someone saved ${conflicts.map((c) => c.path).join(", ")} after your pull${written.length ? ` — their version is in ${written.join(", ")}` : ""}${conflicts.some((c) => !tenant.has(c.path)) ? "; a file they deleted is no longer in the base" : ""}`,
|
|
452
|
+
"merge their changes into src/ (keep both sides' intent), then push again — it is now judged against their version; the same refused content pushed unchanged is refused again",
|
|
453
|
+
].join("\n"),
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
const saved = ws.applyChanges(current, changes);
|
|
457
|
+
const refusals = pushRefusals(changes, current, saved);
|
|
458
|
+
if (refusals.length)
|
|
459
|
+
return { refused: ["refused — nothing saved", ...refusals.map((r) => `✗ ${r}`)].join("\n") };
|
|
460
|
+
// The check, against the form as it is now — of exactly what the save sends (the tenant's list with this push's
|
|
461
|
+
// changes applied; the disk lacks what others saved meanwhile), judged against the same check of the form
|
|
462
|
+
// BEFORE the change: an error the change causes in a file it did not touch (a renamed export, a changed
|
|
463
|
+
// signature) is the change's, and an error the form already had is nobody's business here.
|
|
464
|
+
const types = await formTypes(core, formId, draft);
|
|
465
|
+
ws.writeTypings(workspace, types.typings);
|
|
466
|
+
const asFiles = (list) => Object.fromEntries(ws.partitionFiles(list).accepted.map((f) => [f.path, f.content]));
|
|
467
|
+
const before = await checkWorkspace(workspace, core, asFiles(current));
|
|
468
|
+
const result = await checkWorkspace(workspace, core, asFiles(saved));
|
|
469
|
+
const changed = new Set(changes.map((c) => c.path));
|
|
470
|
+
const blocking = newErrors(before.diagnostics, result.diagnostics);
|
|
471
|
+
const elsewhere = result.diagnostics.filter((d) => d.category === "error").length - blocking.length;
|
|
472
|
+
const typingNotes = types.notes.filter((n) => n.startsWith("⚠"));
|
|
473
|
+
if (blocking.length && !allowErrors) {
|
|
474
|
+
return {
|
|
475
|
+
refused: [
|
|
476
|
+
`refused — nothing saved: this change causes ${blocking.length} type error${blocking.length === 1 ? "" : "s"}`,
|
|
477
|
+
...blocking.slice(0, 30).map(diagnosticLine),
|
|
478
|
+
...typingNotes,
|
|
479
|
+
"fix them (suppa_form_code mode='check' lists everything). allow_errors=true saves anyway — only when the error is the vendored SDK lagging the tenant's front, and say so to the user: the server's build does not type-check, so a real error ships as broken behaviour",
|
|
480
|
+
].join("\n"),
|
|
481
|
+
};
|
|
482
|
+
}
|
|
483
|
+
const warnings = [
|
|
484
|
+
...pushWarnings(changes, manifest, saved),
|
|
485
|
+
...result.diagnostics.filter((d) => d.category === "warning" && d.file !== null && changed.has(d.file)).slice(0, 15).map((d) => `check: ${diagnosticLine(d)}`),
|
|
486
|
+
...(blocking.length ? [`saving DESPITE ${blocking.length} type error(s) this change causes (allow_errors)`] : []),
|
|
487
|
+
...(elsewhere > 0 ? [`${elsewhere} type error(s) the form already had before this change — not blocking`] : []),
|
|
488
|
+
...(draft.status === "published" ? ["the form is PUBLISHED: this save makes its status `editing`; what users see stays the published version until someone publishes"] : []),
|
|
489
|
+
...typingNotes,
|
|
490
|
+
];
|
|
491
|
+
return {
|
|
492
|
+
manifest,
|
|
493
|
+
draft,
|
|
494
|
+
changes,
|
|
495
|
+
saved,
|
|
496
|
+
check: formatCheck(result).split("\n")[0],
|
|
497
|
+
warnings,
|
|
498
|
+
revision: typeof draft.updatedAt === "string" ? draft.updatedAt : null,
|
|
499
|
+
};
|
|
500
|
+
}
|
|
501
|
+
/**
|
|
502
|
+
* suppa_push_form_code. Without confirm: the plan — or, as things stand, the refusal the confirmed call would
|
|
503
|
+
* give (still a confirmation request: a preview never answers with a write's outcome). With confirm=true: the
|
|
504
|
+
* same judgement made again from a fresh read, then PUT /core/forms/:id/schema { code, expectedRevision }.
|
|
505
|
+
*/
|
|
506
|
+
export async function push(formId, dir, files, overwrite, allowErrors, confirm) {
|
|
507
|
+
let prepared;
|
|
508
|
+
let workspace = "";
|
|
509
|
+
try {
|
|
510
|
+
if (!Number.isSafeInteger(formId) || formId <= 0)
|
|
511
|
+
throw new Error("form_id must be the Forms row id (the form= in the builder URL)");
|
|
512
|
+
const core = await loadCore();
|
|
513
|
+
workspace = formDir(formId, dir);
|
|
514
|
+
prepared = await preparePush(core, formId, workspace, files, overwrite, allowErrors);
|
|
515
|
+
}
|
|
516
|
+
catch (e) {
|
|
517
|
+
prepared = { refused: `nothing saved — ${msg(e)}` };
|
|
518
|
+
}
|
|
519
|
+
if (!confirm) {
|
|
520
|
+
if ("refused" in prepared) {
|
|
521
|
+
return confirmRequired(PUSH_ACTION, { form_id: formId, tenant: host() }, { will_refuse: prepared.refused }, [
|
|
522
|
+
`as things stand the confirmed call REFUSES and saves nothing: ${prepared.refused.split("\n")[0]}`,
|
|
523
|
+
]);
|
|
524
|
+
}
|
|
525
|
+
return confirmRequired(PUSH_ACTION, { form_id: formId, name: prepared.draft.name ?? null, status: prepared.draft.status ?? null, tenant: host() }, {
|
|
526
|
+
files: prepared.changes.map(lineDelta),
|
|
527
|
+
sends: `PUT /core/forms/${formId}/schema { code: ${prepared.saved.length} file${prepared.saved.length === 1 ? "" : "s"}, expectedRevision: ${prepared.revision ?? "none"} } — only the code; schema, settings, variables and texts are left as they are`,
|
|
528
|
+
check: prepared.check,
|
|
529
|
+
builds: "the server builds the code on this save; only a clean build replaces what the form runs",
|
|
530
|
+
publishes: false,
|
|
531
|
+
}, prepared.warnings);
|
|
532
|
+
}
|
|
533
|
+
if ("refused" in prepared)
|
|
534
|
+
return prepared.refused;
|
|
535
|
+
const { manifest, draft, changes, saved, warnings, revision } = prepared;
|
|
536
|
+
// Someone else has the form open in the builder: their next save would overwrite this one, or this one theirs.
|
|
537
|
+
let lockNote = null;
|
|
538
|
+
try {
|
|
539
|
+
const row = (await selectEntity("Forms", [{ field: "id", comparator: "=", value: formId }], {
|
|
540
|
+
id: true, lockedBy: { id: true, fullName: true }, lockedAt: true,
|
|
541
|
+
}));
|
|
542
|
+
if (row) {
|
|
543
|
+
const lock = await formLock(formId, row);
|
|
544
|
+
if (lock.refusal)
|
|
545
|
+
return ["refused — nothing saved", String(lock.refusal.error)].join("\n");
|
|
546
|
+
lockNote = lock.note;
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
catch (e) {
|
|
550
|
+
return `nothing saved — the form's lock could not be read (${msg(e)})`;
|
|
551
|
+
}
|
|
552
|
+
let answer;
|
|
553
|
+
try {
|
|
554
|
+
answer = (await makeRequest("PUT", `/api/core/forms/${formId}/schema`, {
|
|
555
|
+
code: saved,
|
|
556
|
+
...(revision ? { expectedRevision: revision } : {}),
|
|
557
|
+
}));
|
|
558
|
+
}
|
|
559
|
+
catch (e) {
|
|
560
|
+
if (staleAnswer(msg(e), formId))
|
|
561
|
+
return `nothing saved — form ${formId} changed after it was read for this push; push again (it re-reads and re-judges)`;
|
|
562
|
+
// A timeout or a dropped connection may come AFTER the server committed: say what is known, not "nothing saved".
|
|
563
|
+
return `the save did not answer cleanly (${msg(e)}) — it may or may not have landed; suppa_form_code mode='check' says whether the draft now matches the workspace, then push again if it does not`;
|
|
564
|
+
}
|
|
565
|
+
const after = isObj(answer) && Array.isArray(answer.code) ? filesOf(answer) : null;
|
|
566
|
+
const revisionNow = isObj(answer) && typeof answer.updatedAt === "string" ? answer.updatedAt : null;
|
|
567
|
+
const mismatch = after ? saved.filter((f) => after.find((a) => a.path === f.path)?.content !== f.content).map((f) => f.path) : [];
|
|
568
|
+
let bookkeeping = null;
|
|
569
|
+
try {
|
|
570
|
+
ws.recordPushed(workspace, manifest, changes, after ?? saved, revisionNow);
|
|
571
|
+
}
|
|
572
|
+
catch (e) {
|
|
573
|
+
// The save stands; only the workspace is behind it.
|
|
574
|
+
bookkeeping = `⚠ saved, but the workspace could not be updated (${msg(e)}) — pull with force=true before editing further`;
|
|
575
|
+
}
|
|
576
|
+
const buildErrors = Array.isArray(answer?.buildErrors) ? answer.buildErrors : [];
|
|
577
|
+
const art = isObj(answer?.codeArtifact) ? answer.codeArtifact : null;
|
|
578
|
+
const out = [
|
|
579
|
+
`saved to the DRAFT of form ${formId}: ${changeSummary(changes)} (nothing published${draft.status === "published" ? "; status now `editing`" : ""})`,
|
|
580
|
+
];
|
|
581
|
+
if (buildErrors.length) {
|
|
582
|
+
out.push(`✗ the server's BUILD FAILED — the code is saved, but the form keeps running its PREVIOUS build${art?.builtAt ? ` (built ${art.builtAt})` : " (none — it runs no code of its own)"}:`, ...buildErrors.slice(0, 20).map((b) => ` ${b.file ?? "(build)"}${b.line ? `:${b.line}` : ""} ${String(b.message ?? "").split("\n")[0]}`), "fix and push again — only a clean build runs. The usual cause: a member the server's SDK copy does not have yet (the editor's typings are newer than the backend's)");
|
|
583
|
+
}
|
|
584
|
+
else if (saved.length) {
|
|
585
|
+
out.push(`✓ the server built it${art?.builtAt ? ` at ${art.builtAt}` : ""} — the draft runs this code; users see it after a publish`);
|
|
586
|
+
}
|
|
587
|
+
if (mismatch.length)
|
|
588
|
+
out.push(`⚠ READ-BACK MISMATCH: the draft holds other content than sent in ${mismatch.join(", ")} — pull before editing further`);
|
|
589
|
+
if (revisionNow)
|
|
590
|
+
out.push(`revision now ${revisionNow}`);
|
|
591
|
+
if (bookkeeping)
|
|
592
|
+
out.push(bookkeeping);
|
|
593
|
+
if (lockNote)
|
|
594
|
+
out.push(`⚠ ${lockNote}`);
|
|
595
|
+
for (const w of warnings)
|
|
596
|
+
out.push(`note: ${w}`);
|
|
597
|
+
out.push("open the draft and try the form before calling it done; publishing is suppa_form_lifecycle, on the user's word");
|
|
598
|
+
return out.join("\n");
|
|
599
|
+
}
|
|
600
|
+
/** The rules, whole or one section (`## <heading>` of references/code-form.md, matched by a word of it). */
|
|
601
|
+
export function rules(topic) {
|
|
602
|
+
const p = skillFile("references", "code-form.md");
|
|
603
|
+
if (!p)
|
|
604
|
+
return "the Code Form rules (skills/suppa-form-v2/references/code-form.md) are missing — reinstall suppa-mcp-2";
|
|
605
|
+
const text = readFileSync(p, "utf8").replace(/\r\n/g, "\n");
|
|
606
|
+
const sections = text.split(/\n(?=## )/);
|
|
607
|
+
const headings = sections.slice(1).map((s) => s.slice(3, s.indexOf("\n") < 0 ? undefined : s.indexOf("\n")).trim());
|
|
608
|
+
if (!topic) {
|
|
609
|
+
// The head and the first section (the rules); the rest by name.
|
|
610
|
+
return `${sections.slice(0, 2).join("\n")}\n\nMore sections (topic='<word>'): ${headings.slice(1).join(" · ")}`;
|
|
611
|
+
}
|
|
612
|
+
const t = topic.trim().toLowerCase();
|
|
613
|
+
const hit = sections.slice(1).find((s, i) => headings[i].toLowerCase().includes(t));
|
|
614
|
+
return hit ?? `no section matching '${topic}' — sections: ${headings.join(" · ")}`;
|
|
615
|
+
}
|
|
616
|
+
/** suppa_form_code — the reading modes; saving is suppa_push_form_code (its own tool: it writes, behind confirm). */
|
|
617
|
+
export async function formCode(a) {
|
|
618
|
+
const mode = String(a.mode ?? "").trim();
|
|
619
|
+
const id = a.form_id ?? null;
|
|
620
|
+
const needId = (m) => {
|
|
621
|
+
if (!Number.isSafeInteger(id) || id <= 0)
|
|
622
|
+
throw new Error(`mode='${m}' needs form_id — the Forms row id (the form= in the builder URL)`);
|
|
623
|
+
return id;
|
|
624
|
+
};
|
|
625
|
+
try {
|
|
626
|
+
switch (mode) {
|
|
627
|
+
case "rules":
|
|
628
|
+
return rules(a.topic ?? null);
|
|
629
|
+
case "pull":
|
|
630
|
+
return await pull(needId("pull"), a.dir ?? null, a.force === true, a.inline === true);
|
|
631
|
+
case "check":
|
|
632
|
+
return await check(needId("check"), a.dir ?? null);
|
|
633
|
+
case "api":
|
|
634
|
+
return await api(id, a.dir ?? null, a.type ? { type: a.type } : { path: a.path ?? "formAPI" }, a.member ?? null, a.filter ?? null);
|
|
635
|
+
case "push":
|
|
636
|
+
return "saving is its own tool: suppa_push_form_code(form_id, confirm=true) — it writes the form's draft, so it asks first";
|
|
637
|
+
default:
|
|
638
|
+
return `unknown mode '${mode}' — modes: rules, pull, api, check (saving: suppa_push_form_code)`;
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
catch (e) {
|
|
642
|
+
return `error: ${msg(e)}`;
|
|
643
|
+
}
|
|
644
|
+
}
|