suppa-mcp-2 1.37.0 → 1.39.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 +43 -2
- package/dist/cli/flags.js +317 -0
- package/dist/cli/help.js +97 -0
- package/dist/cli/rewrite.js +33 -0
- package/dist/cli/run.js +314 -0
- package/dist/cli/state.js +99 -0
- package/dist/cliBin.js +19 -0
- package/dist/server.js +152 -20
- package/dist/toolTable.js +25 -0
- package/dist/tools/customFields.js +89 -6
- package/dist/tools/entity.js +112 -5
- package/dist/tools/entityCode.js +24 -0
- package/dist/tools/formV2.js +508 -0
- package/package.json +6 -2
- package/skills/suppa-cli/SKILL.md +33 -0
- package/skills/suppa-entity-code/SKILL.md +19 -2
- package/skills/suppa-entity-code/references/custom-fields.md +3 -0
- package/skills/suppa-entity-code/references/entities.md +39 -0
- package/skills/suppa-entity-code/references/tabular-parts.md +10 -10
- package/skills/suppa-entity-code/scripts/entity-code-guard.mjs +17 -7
- package/skills/suppa-entity-code/scripts/house-rules.mjs +6 -1
- package/skills/suppa-entity-code/scripts/validate-suppa-schema.mjs +351 -2
- package/skills/suppa-entity-code/templates/custom-fields.template.ts +1 -1
- package/skills/suppa-form-v2/SKILL.md +177 -0
- package/skills/suppa-form-v2/SOURCE.json +9 -0
- package/skills/suppa-form-v2/data/base-props.json +255 -0
- package/skills/suppa-form-v2/data/component-index.json +336 -0
- package/skills/suppa-form-v2/data/component-props.json +4903 -0
- package/skills/suppa-form-v2/data/templates/hero-registration.json +122 -0
- package/skills/suppa-form-v2/data/templates/kpi-dashboard.json +109 -0
- package/skills/suppa-form-v2/data/templates/list-management.json +88 -0
- package/skills/suppa-form-v2/data/templates/record-detail-side-panel.json +306 -0
- package/skills/suppa-form-v2/data/templates/simple-form.json +142 -0
- package/skills/suppa-form-v2/data/templates/tabbed-settings.json +157 -0
- package/skills/suppa-form-v2/data/templates/wizard.json +237 -0
- package/skills/suppa-form-v2/notes/calendar.md +17 -0
- package/skills/suppa-form-v2/notes/chart.md +20 -0
- package/skills/suppa-form-v2/notes/comments.md +16 -0
- package/skills/suppa-form-v2/notes/date.md +22 -0
- package/skills/suppa-form-v2/notes/entityList.md +13 -0
- package/skills/suppa-form-v2/notes/kanban.md +21 -0
- package/skills/suppa-form-v2/notes/menuPanel.md +13 -0
- package/skills/suppa-form-v2/notes/progressBar.md +22 -0
- package/skills/suppa-form-v2/notes/resizableWindow.md +20 -0
- package/skills/suppa-form-v2/notes/richText.md +15 -0
- package/skills/suppa-form-v2/notes/select.md +23 -0
- package/skills/suppa-form-v2/notes/table.md +11 -0
- package/skills/suppa-form-v2/references/binding.md +58 -0
- package/skills/suppa-form-v2/references/charts.md +59 -0
- package/skills/suppa-form-v2/references/choosing-elements.md +37 -0
- package/skills/suppa-form-v2/references/conditions.md +44 -0
- package/skills/suppa-form-v2/references/layout.md +47 -0
- package/skills/suppa-form-v2/references/publishing.md +72 -0
- package/skills/suppa-form-v2/references/styling.md +48 -0
- package/skills/suppa-form-v2/references/tables.md +55 -0
- package/skills/suppa-form-v2/scripts/form-core.mjs +6297 -0
- package/skills/suppa-form-v2/scripts/form-rules.mjs +56 -0
- package/skills/suppa-form-v2/scripts/validate-form-schema.mjs +531 -0
package/README.md
CHANGED
|
@@ -28,6 +28,36 @@ No API key needed to start — the server authenticates interactively via the `s
|
|
|
28
28
|
|
|
29
29
|
---
|
|
30
30
|
|
|
31
|
+
## The `suppa` command
|
|
32
|
+
|
|
33
|
+
The same 96 operations the MCP server exposes are available as a command, for
|
|
34
|
+
shells, scripts and CI:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
npm install -g suppa-mcp-2
|
|
38
|
+
suppa help
|
|
39
|
+
|
|
40
|
+
# Or without a global install, use --package to select the CLI bin:
|
|
41
|
+
npx --package=suppa-mcp-2 -- suppa help
|
|
42
|
+
suppa use-tenant --tenant modern-expo
|
|
43
|
+
suppa search-records --entity-name Tasks --limit 5
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Both shells are generated from one table, so neither can drift from the other.
|
|
47
|
+
The command validates arguments against the same schema before sending
|
|
48
|
+
anything, and carries the same approval gates: `--confirm` is never implied.
|
|
49
|
+
|
|
50
|
+
Nothing about a value is guessed: numbers are plain decimals, a flag is never
|
|
51
|
+
read as another flag's value, and `--context-value 007` stays the text `007`.
|
|
52
|
+
JSON, non-ASCII text and typed numbers travel in `--args-file <path>` or
|
|
53
|
+
`--args-stdin` (a JSON object of arguments) — a shell that rewrites quotes,
|
|
54
|
+
as PowerShell does, cannot touch them there. `--tenant <alias>` points one
|
|
55
|
+
call elsewhere; `--pretty` re-indents the answer. Exit codes: `0` done, `1`
|
|
56
|
+
refused or not fully done (`passed: false`, `created: false`, a non-zero
|
|
57
|
+
`failed`), `2` refused before anything was sent.
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
31
61
|
## Authentication
|
|
32
62
|
|
|
33
63
|
There is **no API key to paste**. Run the **`suppa_login`** tool from your MCP client — it opens a browser for Google sign-in, then stores the resulting tokens in the OS keychain (Windows Credential Manager / macOS Keychain / libsecret). The server is **multi-tenant**: log in to more than one Suppa tenant and switch with `suppa_use_tenant`.
|
|
@@ -347,7 +377,7 @@ extension table is created outside that check and is not subject to it.
|
|
|
347
377
|
|
|
348
378
|
## Available tools
|
|
349
379
|
|
|
350
|
-
|
|
380
|
+
99 tools across the areas below.
|
|
351
381
|
|
|
352
382
|
### Session & identity
|
|
353
383
|
|
|
@@ -469,6 +499,17 @@ extension table is created outside that check and is not subject to it.
|
|
|
469
499
|
| `suppa_add_field_to_form` | Add a field element to a form (confirm-gated) |
|
|
470
500
|
| `suppa_list_form_field_types` | List form element types |
|
|
471
501
|
|
|
502
|
+
The seven above are **Suppa 1.0** forms: they read and write `data.formShema` (the platform's
|
|
503
|
+
misspelling) and the v1 field types. A **Suppa 2.0** entity-builder form is a different product —
|
|
504
|
+
the `schema` column on the row since 2.1, 58 component types — and is served by the two below plus the bundled
|
|
505
|
+
`skills/suppa-form-v2` skill. Neither touches a tenant: both read files inside the package.
|
|
506
|
+
|
|
507
|
+
| Tool | Description |
|
|
508
|
+
|---|---|
|
|
509
|
+
| `suppa_form_kb` | The 2.0 form knowledge base: the 58 element types, one type's prop table, a behaviour note, a reference topic, a template |
|
|
510
|
+
| `suppa_validate_form_schema` | Run the 2.0 form gate over a draft before writing it — 37 structural error codes (the authoring lints live in the source agent, not here) |
|
|
511
|
+
| `suppa_write_form_draft` | Save a checked draft to a form's `schema` column. Gates first, reads before it merges, creates no version — it never publishes |
|
|
512
|
+
|
|
472
513
|
### Migration (Suppa 1.0 → 2.0) & workspace
|
|
473
514
|
|
|
474
515
|
| Tool | Description |
|
|
@@ -540,7 +581,7 @@ shipped with restated defaults and four bare relation stand-ins. Install the
|
|
|
540
581
|
guards into an application repo:
|
|
541
582
|
|
|
542
583
|
```bash
|
|
543
|
-
npx suppa-entity-guards .
|
|
584
|
+
npx --package=suppa-mcp-2 -- suppa-entity-guards .
|
|
544
585
|
# or, without npx:
|
|
545
586
|
node node_modules/suppa-mcp-2/skills/suppa-entity-code/scripts/install-entity-code-guards.mjs .
|
|
546
587
|
```
|
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
/** suppa_search_records -> search-records */
|
|
2
|
+
export function commandOf(toolName) {
|
|
3
|
+
return toolName.replace(/^suppa_/, "").replace(/_/g, "-");
|
|
4
|
+
}
|
|
5
|
+
/** search-records -> suppa_search_records */
|
|
6
|
+
export function toolNameOf(command) {
|
|
7
|
+
return "suppa_" + command.replace(/-/g, "_");
|
|
8
|
+
}
|
|
9
|
+
/** entity_name -> --entity-name */
|
|
10
|
+
export function flagOf(param) {
|
|
11
|
+
return "--" + param.replace(/_/g, "-");
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* --entity-name -> entity_name (also accepts --no-x, which the caller handles)
|
|
15
|
+
*
|
|
16
|
+
* Not a true inverse of flagOf for a parameter whose own name starts with
|
|
17
|
+
* `no_` (e.g. `no_reply`): `--no-reply` reads as the negation of `reply`, not
|
|
18
|
+
* as that literal parameter. No such parameter exists among the current
|
|
19
|
+
* tools, and resolving the ambiguity here would need the shape this function
|
|
20
|
+
* doesn't take — left alone rather than guessed at.
|
|
21
|
+
*/
|
|
22
|
+
export function paramOf(flag) {
|
|
23
|
+
return flag.replace(/^--(no-)?/, "").replace(/-/g, "_");
|
|
24
|
+
}
|
|
25
|
+
/** Peel ZodOptional / ZodDefault / ZodNullable down to the type that matters. */
|
|
26
|
+
function unwrap(schema) {
|
|
27
|
+
let cur = schema;
|
|
28
|
+
for (let i = 0; i < 8 && cur?._def?.innerType; i++)
|
|
29
|
+
cur = cur._def.innerType;
|
|
30
|
+
return cur;
|
|
31
|
+
}
|
|
32
|
+
/** "ZodString" | "ZodNumber" | "ZodBoolean" | "ZodArray" | "ZodUnion" | "ZodEnum" | … */
|
|
33
|
+
export function kindOf(schema) {
|
|
34
|
+
return unwrap(schema)?._def?.typeName ?? "unknown";
|
|
35
|
+
}
|
|
36
|
+
/** The element type of an array parameter, or null. */
|
|
37
|
+
function elementKind(schema) {
|
|
38
|
+
const u = unwrap(schema);
|
|
39
|
+
return u?._def?.typeName === "ZodArray" ? u._def.type?._def?.typeName ?? null : null;
|
|
40
|
+
}
|
|
41
|
+
/** The member type names of a union parameter. */
|
|
42
|
+
export function unionKinds(schema) {
|
|
43
|
+
const u = unwrap(schema);
|
|
44
|
+
if (u?._def?.typeName !== "ZodUnion")
|
|
45
|
+
return [];
|
|
46
|
+
return (u._def.options ?? []).map((o) => o?._def?.typeName ?? "unknown");
|
|
47
|
+
}
|
|
48
|
+
/** The allowed values of a ZodEnum parameter, or [] for anything else. */
|
|
49
|
+
export function enumValues(schema) {
|
|
50
|
+
const u = unwrap(schema);
|
|
51
|
+
return u?._def?.typeName === "ZodEnum" ? [...(u._def.values ?? [])] : [];
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* A number, read strictly: an optional sign, digits, an optional decimal part.
|
|
55
|
+
* `Number()` accepts what no one typing an id means — `""` and `" "` are 0,
|
|
56
|
+
* `"0x10"` is 16, `"1e3"` is 1000, `" 5 "` is 5 — and every one of those went
|
|
57
|
+
* to the schema as a valid number. Leading zeros are refused too: `007` is a
|
|
58
|
+
* code, not the id 7. Returns null for anything that is not a plain decimal.
|
|
59
|
+
*/
|
|
60
|
+
export function parseNumber(raw) {
|
|
61
|
+
if (!/^[+-]?(0|[1-9]\d*)(\.\d+)?$/.test(raw))
|
|
62
|
+
return null;
|
|
63
|
+
return Number(raw);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* A union value, resolved WITHOUT guessing.
|
|
67
|
+
*
|
|
68
|
+
* `title` is string-or-object: a value that starts with `{` or `[` is JSON, an
|
|
69
|
+
* explicit syntax no shell produces by accident, and is passed parsed; any other
|
|
70
|
+
* text stays text. `context_value` is string-or-number: it stays the STRING it
|
|
71
|
+
* was typed as, always — the platform resolves it as a business key (an enum's
|
|
72
|
+
* stored value, an import key), and `007`, `02556` or `0x10` are exactly such
|
|
73
|
+
* keys. A caller who means a JSON number writes it in --args-file / --args-stdin,
|
|
74
|
+
* where types are what JSON says they are.
|
|
75
|
+
*/
|
|
76
|
+
function unionValue(raw, schema) {
|
|
77
|
+
const kinds = unionKinds(schema);
|
|
78
|
+
if (kinds.some((k) => k === "ZodRecord" || k === "ZodObject" || k === "ZodArray")) {
|
|
79
|
+
const t = raw.trim();
|
|
80
|
+
if (t.startsWith("{") || t.startsWith("[")) {
|
|
81
|
+
try {
|
|
82
|
+
return JSON.parse(t);
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
// Not valid JSON after all: fall through and let the schema refuse it
|
|
86
|
+
// with its own message rather than inventing one here.
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return raw;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Explicit, case-insensitive spellings for an inline boolean flag value
|
|
94
|
+
* (`--confirm=<value>`). Anything else — including the empty string from
|
|
95
|
+
* `--confirm=` — is refused rather than guessed: a destructive gate like
|
|
96
|
+
* `--confirm` must never read a value it does not recognise as truthy.
|
|
97
|
+
*/
|
|
98
|
+
const BOOLEAN_TRUE = new Set(["true", "1", "yes", "on"]);
|
|
99
|
+
const BOOLEAN_FALSE = new Set(["false", "0", "no", "off"]);
|
|
100
|
+
/** A token that is a flag, not a value: `--x`, `--x=…`, or the bare `--`. */
|
|
101
|
+
function looksLikeFlag(token) {
|
|
102
|
+
return token.startsWith("--");
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* argv (already stripped of node, the command and the global flags) ->
|
|
106
|
+
* arguments for the handler.
|
|
107
|
+
*
|
|
108
|
+
* Nothing is coerced beyond what the declared type asks for, and nothing
|
|
109
|
+
* unrecognised is dropped in silence: an unknown flag is an error, because a
|
|
110
|
+
* dropped flag is a call that quietly did something other than what was typed.
|
|
111
|
+
*/
|
|
112
|
+
export function parseArgv(argv, shape) {
|
|
113
|
+
const args = {};
|
|
114
|
+
const errors = [];
|
|
115
|
+
const seen = new Set();
|
|
116
|
+
for (let i = 0; i < argv.length; i++) {
|
|
117
|
+
const token = argv[i];
|
|
118
|
+
if (!looksLikeFlag(token)) {
|
|
119
|
+
errors.push(`unexpected value '${token}' — every argument needs its flag`);
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
const eq = token.indexOf("=");
|
|
123
|
+
const flag = eq === -1 ? token : token.slice(0, eq);
|
|
124
|
+
const inline = eq === -1 ? undefined : token.slice(eq + 1);
|
|
125
|
+
const negated = flag.startsWith("--no-");
|
|
126
|
+
const param = paramOf(flag);
|
|
127
|
+
if (!(param in shape)) {
|
|
128
|
+
errors.push(`unknown flag ${flag}`);
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
const schema = shape[param];
|
|
132
|
+
const kind = kindOf(schema);
|
|
133
|
+
if (negated && kind !== "ZodBoolean") {
|
|
134
|
+
errors.push(`${flag}: --no- applies only to boolean flags`);
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
if (negated && inline !== undefined) {
|
|
138
|
+
// `--no-confirm=true` says two things at once; neither is chosen for it.
|
|
139
|
+
errors.push(`${flag}=${inline}: --no-${param.replace(/_/g, "-")} takes no value — write --${param.replace(/_/g, "-")} or --no-${param.replace(/_/g, "-")}`);
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
// A scalar given twice has two values and one slot; last-wins is the
|
|
143
|
+
// quietest possible way to lose the first one. Arrays repeat by design.
|
|
144
|
+
if (kind !== "ZodArray") {
|
|
145
|
+
if (seen.has(param)) {
|
|
146
|
+
errors.push(`${flag} given twice — a flag takes one value; to pass several, the parameter must be a list`);
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
seen.add(param);
|
|
150
|
+
}
|
|
151
|
+
if (kind === "ZodBoolean") {
|
|
152
|
+
if (negated) {
|
|
153
|
+
args[param] = false;
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
if (inline === undefined) {
|
|
157
|
+
args[param] = true;
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
const normalized = inline.toLowerCase();
|
|
161
|
+
if (BOOLEAN_TRUE.has(normalized)) {
|
|
162
|
+
args[param] = true;
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
if (BOOLEAN_FALSE.has(normalized)) {
|
|
166
|
+
args[param] = false;
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
errors.push(`${flag}=${inline}: expected one of true/1/yes/on or false/0/no/off (case-insensitive)`);
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
let raw;
|
|
173
|
+
if (inline !== undefined) {
|
|
174
|
+
raw = inline;
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
const next = argv[i + 1];
|
|
178
|
+
if (next === undefined) {
|
|
179
|
+
errors.push(`${flag} given with no value`);
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
if (looksLikeFlag(next)) {
|
|
183
|
+
// The very shape that swallowed 844 flags: `--entity-name --confirm`
|
|
184
|
+
// read `--confirm` as the entity's name and the permission vanished.
|
|
185
|
+
errors.push(`${flag} given with no value — the next token '${next}' is a flag. ` +
|
|
186
|
+
`To pass a value that itself starts with --, write ${flag}=${next}`);
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
raw = next;
|
|
190
|
+
i++;
|
|
191
|
+
}
|
|
192
|
+
if (kind === "ZodArray") {
|
|
193
|
+
// `--types ["a","b"]` is the shape of the MCP argument and of the shared description, so it
|
|
194
|
+
// is what a reader writes first. Taken literally it becomes ONE element named `["a","b"]`,
|
|
195
|
+
// and the tool then reports that as an unknown value with exit 0 — a wrong answer delivered
|
|
196
|
+
// as a successful one. Name it instead.
|
|
197
|
+
if (/^\s*\[[\s\S]*\]\s*$/.test(raw)) {
|
|
198
|
+
let parsed = null;
|
|
199
|
+
try {
|
|
200
|
+
parsed = JSON.parse(raw);
|
|
201
|
+
}
|
|
202
|
+
catch {
|
|
203
|
+
parsed = null;
|
|
204
|
+
}
|
|
205
|
+
const items = Array.isArray(parsed) ? parsed.map((v) => String(v)) : [];
|
|
206
|
+
const flagName = `--${param.replace(/_/g, "-")}`;
|
|
207
|
+
errors.push(`${flag}: a list flag REPEATS, it does not take a JSON array — write ` +
|
|
208
|
+
(items.length
|
|
209
|
+
? items.map((v) => `${flagName} ${v}`).join(" ")
|
|
210
|
+
: `${flagName} <value> ${flagName} <value>`) +
|
|
211
|
+
". (The JSON form is the MCP argument, not the CLI one.)");
|
|
212
|
+
continue;
|
|
213
|
+
}
|
|
214
|
+
const list = Array.isArray(args[param]) ? args[param] : [];
|
|
215
|
+
if (elementKind(schema) === "ZodNumber") {
|
|
216
|
+
const n = parseNumber(raw);
|
|
217
|
+
if (n === null) {
|
|
218
|
+
errors.push(`${flag}: '${raw}' is not a number (a plain decimal like 42 or -1.5)`);
|
|
219
|
+
continue;
|
|
220
|
+
}
|
|
221
|
+
list.push(n);
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
list.push(raw);
|
|
225
|
+
}
|
|
226
|
+
args[param] = list;
|
|
227
|
+
continue;
|
|
228
|
+
}
|
|
229
|
+
if (kind === "ZodNumber") {
|
|
230
|
+
const n = parseNumber(raw);
|
|
231
|
+
if (n === null) {
|
|
232
|
+
errors.push(`${flag}: '${raw}' is not a number (a plain decimal like 42 or -1.5; no hex, no exponent, no leading zeros)`);
|
|
233
|
+
continue;
|
|
234
|
+
}
|
|
235
|
+
args[param] = n;
|
|
236
|
+
continue;
|
|
237
|
+
}
|
|
238
|
+
if (kind === "ZodUnion") {
|
|
239
|
+
args[param] = unionValue(raw, schema);
|
|
240
|
+
continue;
|
|
241
|
+
}
|
|
242
|
+
args[param] = raw;
|
|
243
|
+
}
|
|
244
|
+
return { args, errors };
|
|
245
|
+
}
|
|
246
|
+
/** Match threshold and the minimum lead the top candidate needs over the runner-up. */
|
|
247
|
+
const MATCH_THRESHOLD = 0.6;
|
|
248
|
+
const AMBIGUOUS_MARGIN = 0.05;
|
|
249
|
+
/**
|
|
250
|
+
* The flag the caller probably meant, or null.
|
|
251
|
+
*
|
|
252
|
+
* Deliberately conservative: a suggestion that is wrong is worse than none,
|
|
253
|
+
* because it sends the caller down a second wrong path. That means two
|
|
254
|
+
* distinct ways to decline: the best candidate can be too far from the typo
|
|
255
|
+
* (below MATCH_THRESHOLD), or it can be tied — or close enough to tied — with
|
|
256
|
+
* the runner-up (within AMBIGUOUS_MARGIN) that picking one over the other
|
|
257
|
+
* would be a guess dressed up as a suggestion. `filed_name` is one edit from
|
|
258
|
+
* both `field_name` (a transposition) and `file_name` (a deletion): a real,
|
|
259
|
+
* unrelated parameter can sit exactly as close as the one the caller meant, so
|
|
260
|
+
* a single best-match score is not enough — the margin check is what keeps
|
|
261
|
+
* that case silent instead of confidently wrong.
|
|
262
|
+
*
|
|
263
|
+
* MATCH_THRESHOLD 0.6: entity_nmae/entity_name and feild_name/field_name — the
|
|
264
|
+
* transposition typos this function exists to catch — score 0.9+ under
|
|
265
|
+
* `similarity` below; zzzzz against unrelated real params scores 0. 0.6 sits
|
|
266
|
+
* with room on both sides.
|
|
267
|
+
*/
|
|
268
|
+
export function nearestFlag(bad, shape) {
|
|
269
|
+
const name = nearestName(paramOf(bad), Object.keys(shape));
|
|
270
|
+
return name === null ? null : flagOf(name);
|
|
271
|
+
}
|
|
272
|
+
/** The same conservative matcher over any list of names (commands, groups). */
|
|
273
|
+
export function nearestName(target, candidates) {
|
|
274
|
+
const scored = candidates
|
|
275
|
+
.map((name) => ({ name, score: similarity(target, name) }))
|
|
276
|
+
.sort((x, y) => y.score - x.score);
|
|
277
|
+
const [best, runnerUp] = scored;
|
|
278
|
+
if (!best || best.score < MATCH_THRESHOLD)
|
|
279
|
+
return null;
|
|
280
|
+
if (runnerUp && best.score - runnerUp.score < AMBIGUOUS_MARGIN)
|
|
281
|
+
return null;
|
|
282
|
+
return best.name;
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Optimal-string-alignment distance: Levenshtein (insert / delete / substitute,
|
|
286
|
+
* each cost 1) plus one more move — swapping two adjacent characters counts as
|
|
287
|
+
* a single edit, not two substitutions. That one addition is what a real typo
|
|
288
|
+
* needs: without it, "nmae" is two edits from "name" (substitute m<->n twice
|
|
289
|
+
* over) instead of the one transposition a human actually made, and a genuine
|
|
290
|
+
* typo can score below an unrelated same-length word by coincidence alone.
|
|
291
|
+
*/
|
|
292
|
+
function editDistance(a, b) {
|
|
293
|
+
const m = a.length;
|
|
294
|
+
const n = b.length;
|
|
295
|
+
const d = Array.from({ length: m + 1 }, () => new Array(n + 1).fill(0));
|
|
296
|
+
for (let i = 0; i <= m; i++)
|
|
297
|
+
d[i][0] = i;
|
|
298
|
+
for (let j = 0; j <= n; j++)
|
|
299
|
+
d[0][j] = j;
|
|
300
|
+
for (let i = 1; i <= m; i++) {
|
|
301
|
+
for (let j = 1; j <= n; j++) {
|
|
302
|
+
const cost = a[i - 1] === b[j - 1] ? 0 : 1;
|
|
303
|
+
d[i][j] = Math.min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + cost);
|
|
304
|
+
if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1]) {
|
|
305
|
+
d[i][j] = Math.min(d[i][j], d[i - 2][j - 2] + 1);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
return d[m][n];
|
|
310
|
+
}
|
|
311
|
+
/** 1 for identical strings, falling toward 0 as the edit distance grows. */
|
|
312
|
+
function similarity(a, b) {
|
|
313
|
+
const longer = Math.max(a.length, b.length);
|
|
314
|
+
if (longer === 0)
|
|
315
|
+
return 1;
|
|
316
|
+
return 1 - editDistance(a, b) / longer;
|
|
317
|
+
}
|
package/dist/cli/help.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Three levels, because the reason this command exists is that 96 tools with
|
|
3
|
+
* full schemas in context is a cost paid whether or not anything is used.
|
|
4
|
+
*
|
|
5
|
+
* suppa the groups and their sizes (~330 chars)
|
|
6
|
+
* suppa help <group> one line per command
|
|
7
|
+
* suppa help <command> the full description and flags
|
|
8
|
+
*
|
|
9
|
+
* Level one is what an agent must know to discover the rest. It is kept under
|
|
10
|
+
* 400 characters by a test.
|
|
11
|
+
*/
|
|
12
|
+
import { z } from "zod";
|
|
13
|
+
import { PROFILES, profileOf } from "../toolTable.js";
|
|
14
|
+
import { commandOf, flagOf, kindOf, enumValues, nearestName } from "./flags.js";
|
|
15
|
+
import { compactDescription } from "../server.js";
|
|
16
|
+
import { rewriteToolNames } from "./rewrite.js";
|
|
17
|
+
/** The first sentence of a description — what fits on a listing line. */
|
|
18
|
+
function firstSentence(description) {
|
|
19
|
+
return compactDescription(description).split(/\.\s|\n/)[0].trim();
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The flags every command accepts besides its own. Listed once, here, so the
|
|
23
|
+
* per-command help stays the tool's own schema and nothing else.
|
|
24
|
+
*/
|
|
25
|
+
export const GLOBAL_FLAGS_LINE = "global: --args-file <json> --args-stdin --pretty --tenant <alias> --help";
|
|
26
|
+
export function helpRoot(table) {
|
|
27
|
+
const counts = new Map();
|
|
28
|
+
for (const spec of table) {
|
|
29
|
+
const p = profileOf(spec.name) ?? "other";
|
|
30
|
+
counts.set(p, (counts.get(p) ?? 0) + 1);
|
|
31
|
+
}
|
|
32
|
+
const groups = [...counts.entries()]
|
|
33
|
+
.sort((a, b) => b[1] - a[1])
|
|
34
|
+
.map(([name, n]) => `${name}(${n})`)
|
|
35
|
+
.join(" ");
|
|
36
|
+
return (`suppa — Suppa 2.0 from the shell. ${table.length} commands.\n` +
|
|
37
|
+
`groups: ${groups}\n` +
|
|
38
|
+
`suppa help <group> the commands in one group\n` +
|
|
39
|
+
`suppa help <command> its full description and flags\n` +
|
|
40
|
+
`${GLOBAL_FLAGS_LINE}\n`);
|
|
41
|
+
}
|
|
42
|
+
export function helpGroup(table, group) {
|
|
43
|
+
const known = new Set(table.map((s) => s.name));
|
|
44
|
+
const rows = table.filter((s) => profileOf(s.name) === group);
|
|
45
|
+
if (rows.length === 0) {
|
|
46
|
+
return `no group '${group}'. groups: ${Object.keys(PROFILES).join(", ")}\n`;
|
|
47
|
+
}
|
|
48
|
+
const width = Math.max(...rows.map((s) => commandOf(s.name).length)) + 2;
|
|
49
|
+
return (rows
|
|
50
|
+
.map((s) => ` ${commandOf(s.name).padEnd(width)}${rewriteToolNames(firstSentence(s.description), known)}`)
|
|
51
|
+
.join("\n") + "\n");
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* The help for one command — or, for a name that is none, the nearest real
|
|
55
|
+
* command OR group, whichever the conservative matcher (nearestName) is sure
|
|
56
|
+
* of. `suppa help autamation` used to be answered with a COMMAND
|
|
57
|
+
* (`get-automation`) when the caller plainly meant the group; groups are now
|
|
58
|
+
* candidates too, and a group match says so.
|
|
59
|
+
*/
|
|
60
|
+
export function helpCommand(table, command) {
|
|
61
|
+
const known = new Set(table.map((s) => s.name));
|
|
62
|
+
const spec = table.find((s) => commandOf(s.name) === command);
|
|
63
|
+
if (!spec) {
|
|
64
|
+
const commands = table.map((s) => commandOf(s.name));
|
|
65
|
+
const groups = Object.keys(PROFILES);
|
|
66
|
+
const near = nearestName(command, [...commands, ...groups]);
|
|
67
|
+
let hint = "";
|
|
68
|
+
if (near && groups.includes(near))
|
|
69
|
+
hint = `\ndid you mean the group '${near}'? run: suppa help ${near}`;
|
|
70
|
+
else if (near)
|
|
71
|
+
hint = `\ndid you mean: ${near}`;
|
|
72
|
+
return `unknown command '${command}'${hint}\nsuppa help lists every group\n`;
|
|
73
|
+
}
|
|
74
|
+
const shape = spec.inputSchema ?? {};
|
|
75
|
+
const names = Object.keys(shape);
|
|
76
|
+
if (names.length === 0) {
|
|
77
|
+
return `${command}\n\n${rewriteToolNames(compactDescription(spec.description), known)}\n\ntakes no arguments\n`;
|
|
78
|
+
}
|
|
79
|
+
const width = Math.max(...names.map((n) => flagOf(n).length)) + 2;
|
|
80
|
+
const flags = names.map((param) => {
|
|
81
|
+
const schema = shape[param];
|
|
82
|
+
const type = kindOf(schema).replace(/^Zod/, "").toLowerCase();
|
|
83
|
+
const required = typeof schema.isOptional === "function" && !schema.isOptional();
|
|
84
|
+
const values = enumValues(schema);
|
|
85
|
+
// A list flag REPEATS on this CLI. The shared description shows the MCP form
|
|
86
|
+
// (`['input','select']`), which taken literally becomes one value named `["input","select"]`
|
|
87
|
+
// — so the type column says how to pass it here.
|
|
88
|
+
const typeText = values.length
|
|
89
|
+
? `one of: ${values.join(", ")}`
|
|
90
|
+
: type === "array" ? "array (repeat the flag per value)" : type;
|
|
91
|
+
const doc = rewriteToolNames(String(schema.description ?? "").split("\n")[0], known);
|
|
92
|
+
return ` ${flagOf(param).padEnd(width)}${typeText}${required ? ", required" : ""}${doc ? " " + doc : ""}`;
|
|
93
|
+
});
|
|
94
|
+
return `${command}\n\n${rewriteToolNames(compactDescription(spec.description), known)}\n\nflags:\n${flags.join("\n")}\n`;
|
|
95
|
+
}
|
|
96
|
+
/** Kept for callers that build a fake shape: the zod namespace this module uses. */
|
|
97
|
+
export { z };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool names, rendered for the shell that is answering.
|
|
3
|
+
*
|
|
4
|
+
* The refusals this server writes are its best teaching, and they name tools:
|
|
5
|
+
* "Do NOT add them with suppa_add_field", "suppa_resolve_custom_fields answers
|
|
6
|
+
* that". In a shell those name nothing. Rewriting them here — one function on
|
|
7
|
+
* the way out — leaves all 108 call sites in src/tools/* untouched, which is
|
|
8
|
+
* the point: those files carry the platform knowledge, not the presentation.
|
|
9
|
+
*
|
|
10
|
+
* Known and accepted consequence: a record whose DATA literally contains a tool
|
|
11
|
+
* name — a task titled "suppa_add_field breaks X" is plausible on this tenant —
|
|
12
|
+
* will have that occurrence rewritten too. The set is the 96 exact names, the
|
|
13
|
+
* effect is cosmetic, and the alternative is rewriting at 108 call sites in
|
|
14
|
+
* src/tools/*, which is the coupling this design exists to avoid.
|
|
15
|
+
*/
|
|
16
|
+
import { commandOf } from "./flags.js";
|
|
17
|
+
/**
|
|
18
|
+
* Replace every known tool name with its backticked command form.
|
|
19
|
+
*
|
|
20
|
+
* Only names that ARE tools are touched. A name this server does not offer is
|
|
21
|
+
* left exactly as written — inventing a command for it would be worse than
|
|
22
|
+
* leaving the text alone.
|
|
23
|
+
*
|
|
24
|
+
* Uses negative lookbehind to avoid matching tool names embedded as suffixes of
|
|
25
|
+
* longer identifiers: x_suppa_add_field must be left alone. Without the
|
|
26
|
+
* lookbehind, the engine would skip the x_ and match suppa_add_field from
|
|
27
|
+
* index 2, rewriting only that piece and corrupting the result. Word boundary
|
|
28
|
+
* \b cannot help because _ is a word character in JS regex, so there is no
|
|
29
|
+
* boundary between _ and s.
|
|
30
|
+
*/
|
|
31
|
+
export function rewriteToolNames(text, known) {
|
|
32
|
+
return text.replace(/(?<![a-z0-9_])suppa_[a-z0-9_]+/g, (match) => known.has(match) ? "`suppa " + commandOf(match) + "`" : match);
|
|
33
|
+
}
|