suppa-mcp-2 1.45.0 → 1.46.1

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 CHANGED
@@ -30,7 +30,7 @@ No API key needed to start — the server authenticates interactively via the `s
30
30
 
31
31
  ## The `suppa` command
32
32
 
33
- The same 108 operations the MCP server exposes are available as a command, for
33
+ The same 110 operations the MCP server exposes are available as a command, for
34
34
  shells, scripts and CI:
35
35
 
36
36
  ```bash
@@ -59,11 +59,16 @@ refused or not fully done (`passed: false`, `created: false`, a non-zero
59
59
  For an endpoint no command covers there is `suppa api <METHOD> <path>` — the raw
60
60
  call, with the CLI's session and tenant resolution. It exists only in the CLI,
61
61
  never as an MCP tool, and it is gated because it skips every check the commands
62
- make. Reads (GET, and POST to `…/select`, `…/search`, `…/query`, `…/count`) are
63
- sent at once. Anything else prints the request and sends nothing. With
64
- `--confirm` it is sent, but only to a tenant named by `--tenant`, never to the
65
- remembered one. The permanent delete stays refused. `suppa help api` has the
66
- flags. In Git Bash, leave off the path's leading slash (`core/schema`): MSYS
62
+ make. Every call names its tenant with `--tenant` — reads too: on Windows,
63
+ `suppa.cmd` runs through cmd.exe, which ends the command at an `&`, so a flag after
64
+ a `?a=1&b=2` path never arrived and the read went to the remembered tenant. Query
65
+ parameters go as `--query key=value`, or the whole call as `--args-file`
66
+ {method, path, query, body, tenant}. Reads (GET, and POST to `…/select`,
67
+ `…/search`, `…/query`, `…/count`, and the register reads `registers/<name>/balance`,
68
+ `turnovers`, `balance-and-turnovers`, `movements`, `slice-last`, `slice-first`,
69
+ `registers/recorders/status`) are sent at once; what was sent is said on stderr.
70
+ Anything else prints the request and sends nothing until `--confirm`. The permanent
71
+ delete stays refused. `suppa help api` has the flags. In Git Bash, leave off the path's leading slash (`core/schema`): MSYS
67
72
  rewrites an argument that starts with `/` into a Windows path, and the command
68
73
  refuses that path and says why.
69
74
 
@@ -414,7 +419,7 @@ extension table is created outside that check and is not subject to it.
414
419
 
415
420
  ## Available tools
416
421
 
417
- 108 tools across the areas below.
422
+ 110 tools across the areas below.
418
423
 
419
424
  ### Session & identity
420
425
 
@@ -479,7 +484,7 @@ extension table is created outside that check and is not subject to it.
479
484
  | `suppa_list_entities` | List entities (tables) |
480
485
  | `suppa_describe_entity` | Field definitions + types for an entity (compact by default; `full=true` for the raw schema) |
481
486
  | `suppa_list_tabular_parts` | List tabular parts (ТЧ) of an entity |
482
- | `suppa_search_records` | Search / filter records in any entity — nested AND/OR groups, auto-diagnoses an empty result (`deleted_scope` finds soft-deleted rows) |
487
+ | `suppa_search_records` | Search / filter records in any entity — nested AND/OR groups, auto-diagnoses an empty result (`deleted_scope` finds soft-deleted rows); `order_by='custom_order(page, 12)'` reads the platform's manual order of a list |
483
488
  | `suppa_validate_select` | Check a select/filter payload against the entity without running it — names the field that does not resolve |
484
489
  | `suppa_query` | Run one read-only SuppaSQL statement (SELECT/WITH) with the caller's read permissions — check a SQL chart or table source before writing the form |
485
490
  | `suppa_sql_kb` | The SuppaSQL skill offline (`skills/writing-suppa-sql`): rules, cheat sheet, common mistakes, references by section, and `check` — what the platform refuses and the measured slow shapes a draft's text shows |
@@ -506,6 +511,8 @@ extension table is created outside that check and is not subject to it.
506
511
  | `suppa_delete_record` | Soft-delete a record — reversible (confirm-gated); permanent delete is blocked server-wide |
507
512
  | `suppa_restore_record` | Undo a soft delete: clear `deletedAt` on a record (confirm-gated) |
508
513
  | `suppa_copy_record` | Duplicate a record, optionally with its files / related records |
514
+ | `suppa_reorder_records` | Move records within any entity's manual order — a board column, a hierarchy's children; a hierarchy kept per owner orders its top level under the owner (`custom_order(page, 12)` for a page's blocks) and each parent's children under `custom_order(parent, <id>)`; rows checked with your rights first (confirm-gated) |
515
+ | `suppa_insert_record_at` | Create records at a place in any entity's manual order (before / after a record, first / last) |
509
516
  | `suppa_attach_file_to_record` | Attach a local file to any record |
510
517
  | `suppa_list_record_files` | List the files attached to a record |
511
518
  | `suppa_download_file` | Download one attachment (original, preview, or generated PDF) |
package/dist/bin.js CHANGED
@@ -41,10 +41,41 @@ process.on("uncaughtException", (err) => {
41
41
  * process at once, since no answer can arrive anyway.
42
42
  */
43
43
  const DRAIN_MS = 30_000;
44
+ /**
45
+ * How long after its last answer the process waits before it is ended even though something still
46
+ * holds the event loop (the reason this exit exists: a Windows npx parent that never lets go).
47
+ */
48
+ const EXIT_GRACE_MS = 1_000;
49
+ /**
50
+ * End the process — never with a process.exit() in the same breath as a fetch. On Windows,
51
+ * process.exit() right after a fetch aborts Node with 0xC0000409 (STATUS_STACK_BUFFER_OVERRUN, libuv's
52
+ * assert on an async handle undici is still closing). Measured 2026-11-16, Node 26, ten children each,
53
+ * two fetches then exit: at 0 ms 10/10 crashed, at 50 ms 9/10, at 250 ms 0/10, at 1000 ms 0/10; a
54
+ * natural exit 0/10. A user reported the crash ("the suppa processes die with 0xC0000409"), and the
55
+ * in-flight test hit it as soon as one call made two requests. So: the exit code is set and stdin let go,
56
+ * the event loop ends the process when nothing holds it, and the hard exit — unref'd, so it never keeps
57
+ * the process alive itself — comes only after the grace.
58
+ */
59
+ function endProcess() {
60
+ process.exitCode = 0;
61
+ try {
62
+ process.stdin.destroy();
63
+ }
64
+ catch {
65
+ /* already gone */
66
+ }
67
+ setTimeout(() => process.exit(0), EXIT_GRACE_MS).unref();
68
+ }
44
69
  function exitWhenClientIsGone(transport) {
45
70
  const inFlight = new Set();
46
71
  let leaving = false;
47
- const done = () => process.exit(0);
72
+ let ended = false;
73
+ const done = () => {
74
+ if (ended)
75
+ return;
76
+ ended = true;
77
+ endProcess();
78
+ };
48
79
  const deliver = transport.onmessage;
49
80
  transport.onmessage = (message, extra) => {
50
81
  if (message && message.method !== undefined && message.id !== undefined)
package/dist/cli/api.js CHANGED
@@ -8,11 +8,15 @@
8
8
  * there). So the user's decision (2026-09-29) is the gate:
9
9
  *
10
10
  * - CLI only. There is no MCP tool for it.
11
- * - Reads run at once: GET, and a POST whose last segment is select / search / query / count.
12
- * `resolve` is NOT one — `/forms/:id/inheritance-issues/:id/resolve` writes.
13
- * - Anything else prints the request and sends nothing. With `--confirm` it is sent — and only
14
- * to a tenant named by `--tenant`, never to the remembered one: the tenant a CLI remembers can
15
- * be production, and one forgotten flag must not put a raw write there.
11
+ * - Reads run at once: GET, a POST whose last segment is select / search / query / count, and the
12
+ * register reads listed in READ_POST_PATHS. `resolve` is NOT one —
13
+ * `/forms/:id/inheritance-issues/:id/resolve` writes.
14
+ * - Anything else prints the request and sends nothing. With `--confirm` it is sent.
15
+ * - EVERY call names its tenant (`--tenant`, or `tenant` in --args-file) — since 2026-11-16, reads
16
+ * too. A Windows shell cuts a command at an `&`: through `suppa.cmd` (cmd.exe), PowerShell's
17
+ * `suppa api GET "core/x?a=1&b=2" --tenant t` arrives as `api GET core/x?a=1` — the `--tenant` is
18
+ * gone and the read went to the remembered tenant without a word (reported 2026-11-16). A call
19
+ * that must name its tenant is refused instead, and the refusal says why.
16
20
  * - The platform's permanent delete is refused whatever is passed (the same block the HTTP
17
21
  * client enforces on every request, checked here first so it is never offered as a preview).
18
22
  */
@@ -22,32 +26,57 @@ import { pointAtTenant } from "./tenantPoint.js";
22
26
  import { readOnlyProblem } from "../tools/query.js";
23
27
  export const API_METHODS = ["GET", "POST", "PUT", "PATCH", "DELETE"];
24
28
  export const READ_POST_SUFFIXES = ["select", "search", "query", "count"];
25
- /** A read is sent at once; a write is shown first. Decided from the method and the last segment. */
29
+ /**
30
+ * POST endpoints that only read, by their exact shape — read in entity-builder (develop, 2026-11-16)
31
+ * registers.controller.ts: `recorders/status` (RegisterRecorderService.statuses) and the register
32
+ * reads `:name/balance | turnovers | balance-and-turnovers | movements | slice-last | slice-first`
33
+ * (RegisterQueryService — SELECTs through engineRead). NOT here, because they write or start work:
34
+ * `:name/balance/job` (a background job), `recorders/:e/:id/repost`, `repost`, `:name/check`,
35
+ * `:name/totals/rebuild`, `:name/held/release`, `violations/:id/resolve`, the jobs' pause / resume / cancel.
36
+ */
37
+ export const READ_POST_PATHS = [
38
+ /^\/api\/core\/registers\/recorders\/status$/,
39
+ /^\/api\/core\/registers\/[^/]+\/(balance|turnovers|balance-and-turnovers|movements|slice-last|slice-first)$/,
40
+ ];
41
+ /** A read is sent at once; a write is shown first. Decided from the method and the path. */
26
42
  export function classify(method, path) {
27
43
  const m = method.toUpperCase();
28
44
  if (m === "GET")
29
45
  return "read";
30
46
  if (m !== "POST")
31
47
  return "write";
32
- const last = path.split("?")[0].split("/").filter(Boolean).pop() ?? "";
48
+ const bare = path.split("?")[0];
49
+ if (READ_POST_PATHS.some((re) => re.test(bare)))
50
+ return "read";
51
+ const last = bare.split("/").filter(Boolean).pop() ?? "";
33
52
  return READ_POST_SUFFIXES.includes(last) ? "read" : "write";
34
53
  }
54
+ /** What the refusal says when no tenant arrived — the `&` cut is the likely reason, so it is named. */
55
+ export const NO_TENANT_REFUSAL = "a raw call names its tenant: add --tenant <alias> (or `tenant` in --args-file). If you DID pass " +
56
+ "--tenant, the shell cut the command before it: through suppa.cmd (cmd.exe — PowerShell runs it too) " +
57
+ "an `&` ends the command, so `core/x?a=1&b=2 --tenant t` arrives as `core/x?a=1`. Pass parameters with " +
58
+ "--query key=value, or the whole call with --args-file.";
35
59
  export const API_HELP = "suppa api <METHOD> <path> — a raw call to the platform API, with this CLI's session and tenant.\n\n" +
36
60
  " METHOD GET POST PUT PATCH DELETE\n" +
37
61
  " path /api/core/… or /core/… (a ?query in it is moved into --query); the\n" +
38
62
  " leading slash is optional — in Git Bash leave it off (core/schema)\n" +
39
- " --query <k=v> a query parameter; repeat the flag per parameter\n" +
63
+ " --tenant <alias> the tenant for this call — REQUIRED, reads included\n" +
64
+ " --query <k=v> a query parameter; repeat the flag per parameter — never `&` in the path\n" +
65
+ " on Windows: cmd.exe (suppa.cmd) cuts the command there\n" +
40
66
  " --body-file <json> the request body, from a file\n" +
41
67
  " --body-stdin the request body, from standard input\n" +
68
+ " --args-file <json> the call as one JSON object {method, path, query, body, tenant} — the way\n" +
69
+ " past a shell that cuts at `&` or garbles non-ASCII; flags win over it\n" +
42
70
  " --confirm send a write (see below)\n" +
43
- " --tenant <alias> the tenant for this call — REQUIRED to send a write\n" +
44
71
  " --pretty re-indent the JSON answer\n\n" +
45
- "Reads — GET, and POST to …/select, …/search, …/query, …/count — are sent at once.\n" +
46
- "Anything else is a write: without --confirm it prints the request and sends nothing; with\n" +
47
- "--confirm it goes only to the tenant --tenant names, never to the remembered one. A raw call\n" +
72
+ "Reads — GET, POST to …/select, …/search, …/query, …/count, and the register reads (registers/\n" +
73
+ "recorders/status, registers/<name>/balance | turnovers | balance-and-turnovers | movements |\n" +
74
+ "slice-last | slice-first) — are sent at once. Anything else is a write: without --confirm it\n" +
75
+ "prints the request and sends nothing. What was sent is said on stderr (→ METHOD url). A raw call\n" +
48
76
  "skips every check the operation commands make — prefer one when it exists (suppa help <group>).\n" +
49
77
  "The platform's permanent delete (/core/data/<entity>/delete) is refused always; /remove is the\n" +
50
78
  "reversible delete.\n";
79
+ const ARGS_FILE_KEYS = ["method", "path", "query", "body", "tenant"];
51
80
  export async function runApi(argv, io) {
52
81
  const { out, err, stdin } = io;
53
82
  const refuse = (...lines) => {
@@ -59,6 +88,7 @@ export async function runApi(argv, io) {
59
88
  const query = {};
60
89
  let bodyFile = null;
61
90
  let bodyStdin = false;
91
+ let argsFile = null;
62
92
  let confirm = false;
63
93
  let tenant = null;
64
94
  let pretty = false;
@@ -110,6 +140,9 @@ export async function runApi(argv, io) {
110
140
  case "--body-stdin":
111
141
  bodyStdin = bare();
112
142
  break;
143
+ case "--args-file":
144
+ argsFile = value();
145
+ break;
113
146
  case "--confirm":
114
147
  confirm = bare();
115
148
  break;
@@ -120,14 +153,55 @@ export async function runApi(argv, io) {
120
153
  pretty = bare();
121
154
  break;
122
155
  default:
123
- problems.push(`unknown flag ${flag} — this command takes --query, --body-file, --body-stdin, --confirm, --tenant, --pretty`);
156
+ problems.push(`unknown flag ${flag} — this command takes --tenant, --query, --body-file, --body-stdin, --args-file, --confirm, --pretty`);
124
157
  }
125
158
  }
126
159
  if (problems.length)
127
160
  return refuse(...problems);
161
+ // ---- --args-file: the whole call as JSON, for what a shell cannot carry -------------------
162
+ // Command-line values win, as in every other command: the file fills only what the line left out.
163
+ let fileBody = undefined;
164
+ if (argsFile !== null) {
165
+ let parsed;
166
+ try {
167
+ const text = readFileSync(argsFile, "utf-8");
168
+ parsed = JSON.parse(text.charCodeAt(0) === 0xfeff ? text.slice(1) : text);
169
+ }
170
+ catch (e) {
171
+ return refuse(`--args-file ${argsFile}: ${e instanceof Error ? e.message : String(e)}`);
172
+ }
173
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
174
+ return refuse(`--args-file ${argsFile} must hold a JSON object: {"method": "GET", "path": "core/…", "tenant": "…"}`);
175
+ }
176
+ const obj = parsed;
177
+ const unknown = Object.keys(obj).filter((k) => !ARGS_FILE_KEYS.includes(k));
178
+ if (unknown.length) {
179
+ return refuse(`unknown key${unknown.length > 1 ? "s" : ""} ${unknown.join(", ")} in --args-file — it takes ${ARGS_FILE_KEYS.join(", ")}; --confirm stays on the command line`);
180
+ }
181
+ for (const k of ["method", "path", "tenant"]) {
182
+ if (obj[k] !== undefined && typeof obj[k] !== "string")
183
+ return refuse(`--args-file: "${k}" must be a string`);
184
+ }
185
+ if (obj.query !== undefined) {
186
+ if (!obj.query || typeof obj.query !== "object" || Array.isArray(obj.query))
187
+ return refuse('--args-file: "query" must be an object of key → value');
188
+ for (const [k, v] of Object.entries(obj.query)) {
189
+ if (!(k in query))
190
+ query[k] = typeof v === "string" ? v : JSON.stringify(v);
191
+ }
192
+ }
193
+ if (positional.length === 0 && typeof obj.method === "string")
194
+ positional.push(obj.method);
195
+ if (positional.length === 1 && typeof obj.path === "string")
196
+ positional.push(obj.path);
197
+ if (tenant === null && typeof obj.tenant === "string")
198
+ tenant = obj.tenant;
199
+ if (obj.body !== undefined)
200
+ fileBody = obj.body;
201
+ }
128
202
  const [rawMethod, rawPath, ...extra] = positional;
129
203
  if (!rawMethod || !rawPath)
130
- return refuse("give a METHOD and a path: suppa api GET /core/schema");
204
+ return refuse("give a METHOD and a path: suppa api GET core/schema --tenant <alias>");
131
205
  if (extra.length)
132
206
  return refuse(`unexpected argument${extra.length > 1 ? "s" : ""}: ${extra.join(" ")}`);
133
207
  const method = rawMethod.toUpperCase();
@@ -186,14 +260,21 @@ export async function runApi(argv, io) {
186
260
  return refuse(`the body is not valid JSON: ${e instanceof Error ? e.message : String(e)}`);
187
261
  }
188
262
  }
263
+ else if (fileBody !== undefined) {
264
+ if (method === "GET")
265
+ return refuse("a GET carries no body — put it in \"query\" in --args-file, or use POST");
266
+ body = fileBody;
267
+ }
189
268
  // ---- the tenant, and the gate -----------------------------------------
269
+ if (tenant === null)
270
+ return refuse(NO_TENANT_REFUSAL);
190
271
  const point = await pointAtTenant(tenant, err);
191
272
  if (!point.ok)
192
273
  return 2;
193
274
  let kind = classify(method, path);
194
275
  // `…/query` is a read only for what suppa_query itself would send. The engine is SELECT-only,
195
- // but "read" here means "sent at once, to the remembered tenant" — so a statement suppa_query
196
- // would refuse is shown and gated like any write instead.
276
+ // but "read" here means "sent at once" — so a statement suppa_query would refuse is shown and
277
+ // gated like any write instead.
197
278
  let readRefusedBecause = null;
198
279
  if (kind === "read" && path === "/api/core/data/query") {
199
280
  const statement = body && typeof body === "object" ? body.query : undefined;
@@ -214,17 +295,17 @@ export async function runApi(argv, io) {
214
295
  out(JSON.stringify({
215
296
  status: "confirmation_required",
216
297
  message: "NOT sent. A raw write skips every check the operation commands make. Show this request to " +
217
- "the user; to send it, re-run with --confirm --tenant <alias> — a write never goes to the " +
218
- "remembered tenant by default.",
298
+ "the user; to send it, re-run with --confirm.",
219
299
  would_send: request,
220
300
  ...(readRefusedBecause ? { read_refused_because: readRefusedBecause } : {}),
221
301
  }, null, pretty ? 2 : undefined) + "\n");
222
302
  return 0;
223
303
  }
224
- if (kind === "write" && !point.explicit) {
225
- return refuse(`a raw write names its tenant: add --tenant <alias>. Without it this would go to the remembered tenant, ${point.host}.`);
226
- }
227
304
  // ---- send -------------------------------------------------------------
305
+ // Said on stderr, so it never mixes into the JSON answer: the tenant and the query that really
306
+ // went — a parameter a shell cut off is visible here rather than as a silently shorter answer.
307
+ const qs = Object.keys(query).length ? `?${new URLSearchParams(query).toString()}` : "";
308
+ err(`→ ${method} https://${point.host}${path}${qs}\n`);
228
309
  let answer;
229
310
  try {
230
311
  answer = await makeRequest(method, path, body, { raw: true, ...(Object.keys(query).length ? { query } : {}) });
package/dist/cli/run.js CHANGED
@@ -92,7 +92,7 @@ function parseArgsObject(text, source) {
92
92
  return { error: `${source} is not valid JSON: ${e instanceof Error ? e.message : String(e)}` };
93
93
  }
94
94
  if (json === null || typeof json !== "object" || Array.isArray(json)) {
95
- return { error: `${source} must hold a JSON object of arguments ({"entity_name": "Tasks", …})` };
95
+ return { error: `${source} must hold a JSON object of arguments ({"entity_name": "Orders", …} — a hypothetical entity; use the tenant's own)` };
96
96
  }
97
97
  return { args: json };
98
98
  }
@@ -106,10 +106,13 @@ function parseArgsObject(text, source) {
106
106
  * (migrate: 2 done, 3 failed used to exit 0). A nested `error` is NOT a
107
107
  * refusal: create_entity answers {entity, title_field: {error}} when the
108
108
  * entity exists and only a sub-step failed. {status: "confirmation_required"}
109
- * exits 0 deliberately — it is a prompt, not a failure.
109
+ * exits 0 deliberately — it is a prompt, not a failure. An `error` that is null, false or "" is the
110
+ * ABSENCE of one: set_title_field answers `error: null` on success, and the key alone made a done call
111
+ * exit 1 (reported 2026-11-16).
110
112
  */
111
113
  export function answerFailed(answer) {
112
- if ("error" in answer)
114
+ const e = answer.error;
115
+ if (e !== undefined && e !== null && e !== false && e !== "")
113
116
  return true;
114
117
  for (const key of ["passed", "created", "applied", "ok", "success"]) {
115
118
  if (answer[key] === false)
package/dist/server.js CHANGED
@@ -12,6 +12,7 @@ import { config } from "./config.js";
12
12
  import * as tasks from "./tools/tasks.js";
13
13
  import * as docs from "./tools/docs.js";
14
14
  import * as entity from "./tools/entity.js";
15
+ import * as recordOrder from "./tools/recordOrder.js";
15
16
  import * as customFields from "./tools/customFields.js";
16
17
  import * as customFieldSets from "./tools/customFieldSets.js";
17
18
  import * as customFieldsAsCode from "./tools/customFieldsAsCode.js";
@@ -142,6 +143,32 @@ const RecordValuesOrBatchJson = z
142
143
  .describe('JSON object of field values — or a JSON ARRAY of such objects to create many ' +
143
144
  'in one request. Relations/enums as {"id": N}, e.g. {"title": "X", ' +
144
145
  '"customer": {"id": 7}}; batch: [{"title": "A"}, {"title": "B"}].');
146
+ // The manual-order tools (suppa_reorder_records, suppa_insert_record_at): which
147
+ // list, where in it, and how the list is read. See tools/customOrder.ts.
148
+ const OrderContextField = z
149
+ .string()
150
+ .nullable()
151
+ .default(null)
152
+ .describe("The list's scoping field (many-to-one or enum), e.g. 'page'; null = the entity's own list.");
153
+ const OrderContextValue = z
154
+ .number()
155
+ .int()
156
+ .positive()
157
+ .nullable()
158
+ .default(null)
159
+ .describe("Id that scopes the list, e.g. the page id; null with a field = its empty group.");
160
+ const OrderWhereArg = z.enum(["before", "after", "first", "last"]);
161
+ const OrderAnchorId = z
162
+ .number()
163
+ .int()
164
+ .positive()
165
+ .nullable()
166
+ .default(null)
167
+ .describe("For before / after: a record of the same list.");
168
+ const OrderDirectionArg = z
169
+ .enum(["asc", "desc"])
170
+ .default("desc")
171
+ .describe("The direction you read the list in (default desc).");
145
172
  const MergeNamesJson = z
146
173
  .string()
147
174
  .nullable()
@@ -176,7 +203,7 @@ const BlocksJson = z
176
203
  'checkList|quote|callout|divider|code|table|toggle", "title": "text or HTML"}].');
177
204
  const EntityName = z
178
205
  .string()
179
- .describe("Exact entity name, e.g. 'Tasks' — discover via suppa_list_entities.");
206
+ .describe("Exact entity name as suppa_list_entities reports it (e.g. a hypothetical 'Orders').");
180
207
  /**
181
208
  * A field label: a plain string, or the LOCALIZATION OBJECT the builder doc
182
209
  * prescribes (`title | object | Localization object`, builder.txt:56).
@@ -334,7 +361,7 @@ ENTITY BUILDER (create + edit fields; core-field removal is UI-only) — suppa_a
334
361
  - OWNED CHILD COLLECTIONS ARE TABULAR PARTS: repeating rows that belong to ONE parent record (a part's BOM items) go through suppa_create_tabular_part(parent_entity, name), which creates the child's 'owner' relation and the parent link. Never model it by hand — suppa_add_field REFUSES field_type='one-to-many'; 'many-to-many' is for a shared lookup referenced by many records.
335
362
  - An enum value on a RECORD is a reference, {"id": <Enums row id>} (an array of those for multi-enum), never a bare code like "red" — that is refused. Read the ids with suppa_search_records on 'Enums' filtered by name.
336
363
 
337
- CUSTOM FIELDS — ANY entity, not just Tasks: one whose options.customFields is on (an admin enables it; suppa_describe_entity shows it) carries extra columns that vary BY CONTEXT, so which are live differs from record to record — suppa_resolve_custom_fields answers for a given record. Their values ride on the OWNER record under the reserved key customFields, e.g. fields_json {"customFields": {"budget": 600}}.
364
+ CUSTOM FIELDS — ANY entity: one whose options.customFields is on (an admin enables it; suppa_describe_entity shows it) carries extra columns that vary BY CONTEXT, so which are live differs from record to record — suppa_resolve_custom_fields answers for a given record. Their values ride on the OWNER record under the reserved key customFields, e.g. fields_json {"customFields": {"budget": 600}}.
338
365
 
339
366
  ${formV2.FORM_V2_INSTRUCTION_LINE}
340
367
 
@@ -567,14 +594,12 @@ export function buildToolTable() {
567
594
  return text(await tasks.closeTask(a.task_id));
568
595
  });
569
596
  reg("suppa_add_comment", {
570
- description: "Add a comment to a task. Supports HTML — plain text is auto-wrapped in <p>…</p>, so\n" +
571
- " start the string with < to pass raw markup. mention_ids: comma-separated\n" +
572
- " 'userId:Name' pairs for @mentions.",
597
+ description: "Add a comment to a task. Plain text is wrapped in <p>; a string starting with < is HTML.\n" +
598
+ " mention_ids: comma-separated 'userId:Name' pairs — one @mention each, in the first\n" +
599
+ " paragraph; a user the content already mentions is not added again.",
573
600
  inputSchema: {
574
601
  task_id: z.number().int(),
575
- content: z
576
- .string()
577
- .describe("Comment text; plain text is wrapped in <p>, raw HTML passes through."),
602
+ content: z.string().describe("Comment text or HTML."),
578
603
  mention_ids: z
579
604
  .string()
580
605
  .nullable()
@@ -912,7 +937,8 @@ export function buildToolTable() {
912
937
  // Entity tools
913
938
  // =========================================================================
914
939
  reg("suppa_list_entities", {
915
- description: "List all entities (database tables) on the platform. Optionally filter by name.",
940
+ description: "List all entities (database tables) on the platform, tabular parts too (type\n" +
941
+ " 'tabular-part', with their owner). Optionally filter by name.",
916
942
  inputSchema: {
917
943
  search: z
918
944
  .string()
@@ -959,6 +985,14 @@ export function buildToolTable() {
959
985
  " An EMPTY result (or a 400) is auto-diagnosed with select/validate: if the query\n" +
960
986
  ' references a field that does not exist you get "validation" naming it, not silence.\n' +
961
987
  " Returns {records, returned, has_more, next_offset, deleted_scope} — page with offset until has_more is false.\n\n" +
988
+ " MANUAL ORDER: order_by='custom_order(page, 12)' returns the rows of that list (any entity:\n" +
989
+ " context field, scoping record's id) in the order the platform keeps by hand; 'custom_order'\n" +
990
+ " = a flat entity's own list; ':asc' reads it reversed (default desc). A hierarchy kept per\n" +
991
+ " owner orders its top level under the owner (custom_order(page, 12): a page's top-level\n" +
992
+ " blocks), each parent's children under custom_order(parent, <id>); another hierarchy's top\n" +
993
+ ' level: custom_order(parent). Nested rows in order: {"children": "#expand_tree(10)"} in\n' +
994
+ " fields_json. Move rows with suppa_reorder_records; create at a place with\n" +
995
+ " suppa_insert_record_at.\n\n" +
962
996
  " Enum fields read back as objects {value, title, id} — project them as\n" +
963
997
  ' {"myEnum": {"value": true}} and read .value, not as a bare string.\n\n' +
964
998
  " SOFT-DELETED ROWS: deleted_scope='deleted' returns ONLY records that\n" +
@@ -968,7 +1002,7 @@ export function buildToolTable() {
968
1002
  inputSchema: {
969
1003
  entity_name: z
970
1004
  .string()
971
- .describe("Exact entity name, e.g. 'Tasks', 'Users' — see suppa_list_entities."),
1005
+ .describe("Exact entity name as suppa_list_entities reports it (e.g. a hypothetical 'Orders')."),
972
1006
  filters_json: z
973
1007
  .string()
974
1008
  .default("[]")
@@ -984,7 +1018,7 @@ export function buildToolTable() {
984
1018
  order_by: z
985
1019
  .string()
986
1020
  .default("createdAt:desc")
987
- .describe("'field:asc' or 'field:desc', e.g. 'createdAt:desc'."),
1021
+ .describe("'field:asc' or 'field:desc', e.g. 'createdAt:desc' — or 'custom_order(<field>, <id>)' for the manual order (see MANUAL ORDER)."),
988
1022
  match_any: z
989
1023
  .boolean()
990
1024
  .default(false)
@@ -1039,7 +1073,7 @@ export function buildToolTable() {
1039
1073
  inputSchema: {
1040
1074
  query: z
1041
1075
  .string()
1042
- .describe('The SuppaSQL statement, e.g. SELECT "stage.name", COUNT("id") AS "n" FROM Tasks GROUP BY "stage.name" LIMIT 100 — as a chart: sqlCategoryColumn "name", sqlValueColumns [{"key": "n"}].'),
1076
+ .describe('The SuppaSQL statement, e.g. SELECT "status.title", COUNT("id") AS "n" FROM Orders GROUP BY "status.title" LIMIT 100 (Orders is a hypothetical entity; use the one you found) — as a chart: sqlCategoryColumn "title", sqlValueColumns [{"key": "n"}].'),
1043
1077
  bind_params_json: z
1044
1078
  .string()
1045
1079
  .optional()
@@ -1312,7 +1346,7 @@ export function buildToolTable() {
1312
1346
  "platform's own docs say the backend never defaults them and every consumer " +
1313
1347
  "reads an absent key as FALSE — which is how agent-created fields ended up " +
1314
1348
  "non-groupable, unsortable and hidden from tables. The stored shape does look " +
1315
- "sparse: of 70 Tasks fields, 15 carry no options object at all. So if the new " +
1349
+ "sparse: of 70 fields on one live entity, 15 carry no options object at all. So if the new " +
1316
1350
  "field MUST be visible and sortable, pass the five explicitly rather than " +
1317
1351
  "trusting a default — it costs nothing — and read the field back afterwards. " +
1318
1352
  "Unknown keys are refused here (the platform would silently drop them)."),
@@ -1953,6 +1987,62 @@ export function buildToolTable() {
1953
1987
  },
1954
1988
  annotations: _ADD,
1955
1989
  }, async (a) => text(await entity.copyRecord(a.entity_name, a.record_id, a.fields_json, a.copy_files, a.copy_related_entities)));
1990
+ reg("suppa_reorder_records", {
1991
+ description: "Move records within an entity's MANUAL (hand-kept) order — page blocks, a hierarchy's children,\n" +
1992
+ " a board column. Changes no field, deletes nothing.\n\n" +
1993
+ " The order is per LIST: both null = the entity's own list; a hierarchy kept per owner keeps\n" +
1994
+ " its top level under the owner (PageBlocks of page 12 = context_field='page', context_value=12),\n" +
1995
+ " each parent's children under 'parent', <id>; another hierarchy's top level = 'parent', null.\n" +
1996
+ " Read it with suppa_search_records(order_by='custom_order(page, 12)'). record_ids land as one\n" +
1997
+ " block in the order given, before / after anchor_id or first / last. Refused before sending:\n" +
1998
+ " a record missing, not visible to you or in another list.\n\n" +
1999
+ " APPROVAL GATE: without confirm=true this returns a confirmation request and changes nothing.",
2000
+ inputSchema: {
2001
+ entity_name: EntityName,
2002
+ record_ids: z.array(z.number().int().positive()).describe("Ids to move, in the order they should stand (at most 200)."),
2003
+ context_field: OrderContextField,
2004
+ context_value: OrderContextValue,
2005
+ where: OrderWhereArg,
2006
+ anchor_id: OrderAnchorId,
2007
+ direction: OrderDirectionArg,
2008
+ confirm: Confirm,
2009
+ },
2010
+ annotations: _MUT,
2011
+ }, async (a) => {
2012
+ // A move rearranges what other people see in a list, like suppa_reorder_blocks:
2013
+ // gated, and the preview reads nothing.
2014
+ if (!a.confirm) {
2015
+ return text(confirmRequired("reorder records", {
2016
+ entity_name: a.entity_name,
2017
+ record_ids: a.record_ids,
2018
+ context_field: a.context_field,
2019
+ context_value: a.context_value,
2020
+ where: a.where,
2021
+ anchor_id: a.anchor_id,
2022
+ direction: a.direction,
2023
+ }));
2024
+ }
2025
+ return text(await recordOrder.reorderRecords(a.entity_name, a.record_ids, a.context_field, a.context_value, a.where, a.anchor_id, a.direction));
2026
+ });
2027
+ reg("suppa_insert_record_at", {
2028
+ description: "Create records AT A PLACE in an entity's manual order — e.g. a page block after block 40:\n" +
2029
+ " entity_name='PageBlocks', context_field='page', context_value=12, where='after', anchor_id=40,\n" +
2030
+ ' fields_json=[{"type": "text", "properties": {"title": "<p>Hi</p>"}, "format": {"block_color": ""}}].\n\n' +
2031
+ " fields_json as in suppa_create_record (an array is placed as one block, in order); the context\n" +
2032
+ " field is filled in. The list and place work as in suppa_reorder_records; a bad anchor is\n" +
2033
+ " refused BEFORE anything is created. If only the placing fails, the answer has inserted_ids:\n" +
2034
+ " move them with suppa_reorder_records, never insert again.",
2035
+ inputSchema: {
2036
+ entity_name: EntityName,
2037
+ fields_json: RecordValuesOrBatchJson,
2038
+ context_field: OrderContextField,
2039
+ context_value: OrderContextValue,
2040
+ where: OrderWhereArg,
2041
+ anchor_id: OrderAnchorId,
2042
+ direction: OrderDirectionArg,
2043
+ },
2044
+ annotations: _ADD,
2045
+ }, async (a) => text(await recordOrder.insertRecordAt(a.entity_name, a.fields_json, a.context_field, a.context_value, a.where, a.anchor_id, a.direction)));
1956
2046
  reg("suppa_list_record_files", {
1957
2047
  description: "List the files attached to one record of any entity.\n" +
1958
2048
  "\n" +
@@ -57,7 +57,7 @@ export function missingModule(err) {
57
57
  export function npxCacheDir(fromPath) {
58
58
  if (!fromPath)
59
59
  return null;
60
- // A file:// URL is not a path, and its percent-encoding (ANDRII%7E1.HER) does
60
+ // A file:// URL is not a path, and its percent-encoding (JOHNDO%7E1) does
61
61
  // not name a real directory. Passing one here once produced a confident
62
62
  // "Removed the broken cache directory file:///C:/..." for a removal that
63
63
  // never happened, so this refuses rather than guesses: callers convert with
package/dist/toolTable.js CHANGED
@@ -1,6 +1,6 @@
1
1
  export const PROFILES = {
2
2
  core: ["login", "logout", "use_tenant", "list_tenants", "get_me", "health_check", "diagnostics", "version"],
3
- data: ["search_records", "get_record", "create_record", "update_record", "delete_record", "restore_record", "copy_record", "validate_select", "query", "sql_kb", "query_analyze", "search_entities", "list_entities", "describe_entity", "search_users"],
3
+ data: ["search_records", "get_record", "create_record", "update_record", "delete_record", "restore_record", "copy_record", "reorder_records", "insert_record_at", "validate_select", "query", "sql_kb", "query_analyze", "search_entities", "list_entities", "describe_entity", "search_users"],
4
4
  tasks: ["search_tasks", "get_task", "create_task", "update_task", "close_task", "delete_task", "move_task", "count_tasks", "list_stages", "list_task_types", "list_workflows", "add_comment", "get_comments", "create_workspace", "add_menu_item"],
5
5
  files: ["attach_file", "attach_file_to_record", "download_file", "download_files_zip", "list_record_files"],
6
6
  schema: ["create_entity", "add_field", "update_field", "change_field_type", "update_entity_options", "set_title_field", "create_tabular_part", "list_tabular_parts", "list_field_types", "add_enum_values", "add_custom_field", "add_custom_fields_batch", "remove_custom_field", "restore_custom_field", "resolve_custom_fields", "link_custom_field", "apply_custom_fields", "validate_entity_code", "migrate_entities_from_v1", "read_v1_entities", "read_v1_entity_props", "read_v1_enum"],