suppa-mcp-2 1.15.0 → 1.16.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
@@ -386,6 +386,18 @@ node node_modules/suppa-mcp-2/skills/suppa-entity-code/scripts/install-entity-co
386
386
  It is idempotent, and it refuses to write a hook whose path does not resolve —
387
387
  hooks pointing at nothing behave exactly like no hooks at all.
388
388
 
389
+ **Adding the package runs this for you.** A `postinstall` installs the guards into
390
+ the repo the install was run from, so a developer who never reads this file still
391
+ gets them. It refuses far more often than it acts: never when
392
+ `SUPPA_NO_GUARD_INSTALL` is set, never in CI (where hooks do nothing and the CI job
393
+ is its own layer), never for a global install, and never for a repo with no sign of
394
+ Suppa schema code — no `@suppa/*` dependency and no `*.entity.ts`. A package install
395
+ is not permission to configure an unrelated project. It also never fails an install:
396
+ whatever happens, it exits 0 and prints one line saying what to run by hand.
397
+
398
+ One caveat worth knowing: `npm ci --ignore-scripts` skips it, which is common in CI
399
+ and in locked-down organisations. There the CI job is the layer that holds.
400
+
389
401
  Five layers, each covering a way the previous one is missed: Claude Code hooks
390
402
  put the rules in an agent's context **before** it writes `*.entity.ts` and the
391
403
  gate's findings in front of it **after**, a `Stop` hook refuses to end a turn
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "suppa-mcp-2",
3
- "version": "1.15.0",
3
+ "version": "1.16.1",
4
4
  "description": "MCP server for the Suppa platform (modern.suppa.me) — Tasks, Docs/Pages, Entities & Schema, Forms, Automations, and file attachments, with multi-tenant Google auth. Node port of PyPI suppa-mcp.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -24,6 +24,7 @@
24
24
  "start": "node dist/bin.js",
25
25
  "dev": "tsc --watch",
26
26
  "test": "node scripts/check-version-literals.mjs && vitest run",
27
+ "postinstall": "node skills/suppa-entity-code/scripts/postinstall.mjs",
27
28
  "test:watch": "vitest",
28
29
  "prepublishOnly": "npm run build && npm test",
29
30
  "inspect": "npx @modelcontextprotocol/inspector node dist/bin.js",
@@ -175,8 +175,10 @@ function gateRoots(roots) {
175
175
  const notes = [];
176
176
  for (const root of [...new Set(roots)]) {
177
177
  const r = runGate(root);
178
- if (r.toolchain) notes.push(`${root}: ${r.toolchain}`);
179
- else if (r.skipped) notes.push(`${root}: ${r.skipped}`);
178
+ // "could not run" and "nothing to run on" are not the same answer, and the
179
+ // two layers that decide what LANDS have to tell them apart.
180
+ if (r.toolchain) notes.push({ kind: "toolchain", root, text: `${root}: ${r.toolchain}` });
181
+ else if (r.skipped) notes.push({ kind: "skipped", root, text: `${root}: ${r.skipped}` });
180
182
  else if (!r.ok) failures.push({ root, lines: r.lines });
181
183
  }
182
184
  return { failures, notes };
@@ -268,7 +270,7 @@ function postToolUse() {
268
270
  if (notes.length) {
269
271
  emitHookJson(
270
272
  "PostToolUse",
271
- `The entity-code gate could not run: ${notes.join("; ")}. Run it yourself before reporting ` +
273
+ `The entity-code gate could not run: ${notes.map((n) => n.text).join("; ")}. Run it yourself before reporting ` +
272
274
  `this file done — suppa_validate_entity_code(path=<app-root>).`,
273
275
  );
274
276
  }
@@ -293,10 +295,39 @@ function stop() {
293
295
  return 2;
294
296
  }
295
297
 
298
+ /**
299
+ * A gate that could not run must never answer "clean".
300
+ *
301
+ * The checker parses with the TypeScript OF THE REPO it is checking, and a repo
302
+ * without one makes validateSchema throw. That arrived here as a note, was
303
+ * dropped, and the commit hook printed "suppa entity-code gate: clean" over
304
+ * schema code nothing had looked at. The hooks stay fail-open on purpose — they
305
+ * advise an agent mid-edit and must not wall off every write — but the two
306
+ * layers that decide what LANDS refuse instead.
307
+ */
308
+ function toolchainRefusal(notes) {
309
+ const broken = notes.filter((n) => n.kind === "toolchain");
310
+ if (!broken.length) return null;
311
+ return (
312
+ "suppa entity-code gate: COULD NOT RUN — " +
313
+ broken.map((n) => n.text).join("; ") +
314
+ "\nNothing was checked, so nothing can be called clean. The checker parses with the " +
315
+ "application repo's own TypeScript: install it there (npm i -D typescript@5) and try again."
316
+ );
317
+ }
318
+
296
319
  function preCommit() {
297
320
  const files = stagedSchemaFiles(process.cwd()).filter((f) => !isIgnored(appRootFor(f), f));
298
321
  if (!files.length) return 0;
299
- const { failures } = gateRoots(files.map(appRootFor));
322
+ const { failures, notes } = gateRoots(files.map(appRootFor));
323
+ const broken = toolchainRefusal(notes);
324
+ if (broken) {
325
+ process.stderr.write(
326
+ `${broken}\nCommit refused. Pass --no-verify only if you mean to commit schema code that ` +
327
+ `nothing verified.\n`,
328
+ );
329
+ return 1;
330
+ }
300
331
  if (!failures.length) {
301
332
  process.stdout.write("suppa entity-code gate: clean\n");
302
333
  return 0;
@@ -311,7 +342,12 @@ function preCommit() {
311
342
  function ci(args) {
312
343
  const roots = args.length ? args.map((p) => resolve(p)) : [process.cwd()];
313
344
  const { failures, notes } = gateRoots(roots);
314
- for (const n of notes) process.stdout.write(`note: ${n}\n`);
345
+ for (const n of notes) process.stdout.write(`note: ${n.text}\n`);
346
+ const broken = toolchainRefusal(notes);
347
+ if (broken) {
348
+ process.stdout.write(`${broken}\n`);
349
+ return 1;
350
+ }
315
351
  if (!failures.length) {
316
352
  process.stdout.write("suppa entity-code gate: clean\n");
317
353
  return 0;
@@ -0,0 +1,142 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Install the entity-code guards into the application repo that just added
4
+ * this package.
5
+ *
6
+ * Every layer of enforcement below the hooks depends on someone remembering to
7
+ * run one command — and the reason the hooks exist at all is that people (and
8
+ * agents) do not remember. `npm install` is the one moment every developer on
9
+ * a project passes through, so the guards land there.
10
+ *
11
+ * The cost of being wrong here is writing into somebody else's repository, so
12
+ * this refuses far more often than it acts:
13
+ *
14
+ * - never when SUPPA_NO_GUARD_INSTALL is set — the documented opt-out;
15
+ * - never in CI, where the hooks do nothing and the CI job is its own layer;
16
+ * - never for a global install, which has no application repo;
17
+ * - never for this package's own `npm install`;
18
+ * - never for a repo with no package.json;
19
+ * - and never for a repo with no sign of Suppa schema code in it — no
20
+ * @suppa/sdk dependency and no *.entity.ts. A package install is not
21
+ * permission to configure an unrelated project.
22
+ *
23
+ * It also never fails an install: whatever happens, this exits 0. A package
24
+ * that cannot be added because its postinstall threw is worse than a repo
25
+ * without hooks.
26
+ */
27
+
28
+ import { execFileSync } from "node:child_process";
29
+ import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
30
+ import { dirname, join, resolve } from "node:path";
31
+ import { fileURLToPath } from "node:url";
32
+
33
+ const HERE = dirname(fileURLToPath(import.meta.url));
34
+ const INSTALLER = join(HERE, "install-entity-code-guards.mjs");
35
+ const PACKAGE_ROOT = resolve(HERE, "..", "..", "..");
36
+
37
+ /** Say why nothing happened, but only where a reader would wonder. */
38
+ function skip(reason, loud = false) {
39
+ if (loud) process.stdout.write(`suppa-mcp-2: entity-code guards not installed — ${reason}\n`);
40
+ process.exit(0);
41
+ }
42
+
43
+ function readJson(path) {
44
+ try {
45
+ return JSON.parse(readFileSync(path, "utf-8"));
46
+ } catch {
47
+ return null;
48
+ }
49
+ }
50
+
51
+ /**
52
+ * Is there Suppa schema code here, or a declared dependency on the SDK that
53
+ * writes it? Walks a bounded slice of the tree: enough to find an entity file
54
+ * in the usual places, never enough to be felt on a large repo.
55
+ */
56
+ function looksLikeSuppaApp(root) {
57
+ const pkg = readJson(join(root, "package.json"));
58
+ if (!pkg) return false;
59
+ const deps = {
60
+ ...(pkg.dependencies ?? {}),
61
+ ...(pkg.devDependencies ?? {}),
62
+ ...(pkg.peerDependencies ?? {}),
63
+ };
64
+ if (Object.keys(deps).some((d) => d === "@suppa/sdk" || d.startsWith("@suppa/"))) return true;
65
+
66
+ const SKIP = new Set(["node_modules", ".git", "dist", "build", "coverage", ".next", "out"]);
67
+ const walk = (dir, depth) => {
68
+ if (depth > 5) return false;
69
+ let entries;
70
+ try {
71
+ entries = readdirSync(dir, { withFileTypes: true });
72
+ } catch {
73
+ return false;
74
+ }
75
+ for (const e of entries) {
76
+ if (e.isFile() && /\.(entity|seed)\.tsx?$/.test(e.name)) return true;
77
+ if (e.isDirectory() && !SKIP.has(e.name) && !e.name.startsWith(".")) {
78
+ if (walk(join(dir, e.name), depth + 1)) return true;
79
+ }
80
+ }
81
+ return false;
82
+ };
83
+ return walk(root, 0);
84
+ }
85
+
86
+ try {
87
+ if (process.env.SUPPA_NO_GUARD_INSTALL) skip("SUPPA_NO_GUARD_INSTALL is set");
88
+ if (process.env.CI) skip("running in CI");
89
+ if (process.env.npm_config_global === "true") skip("global install, no application repo");
90
+
91
+ // npm points INIT_CWD at the directory the install was run from — the
92
+ // application repo. Without it there is nothing to act on: the package's own
93
+ // directory is where this script runs, and that is never the target.
94
+ const root = process.env.INIT_CWD ? resolve(process.env.INIT_CWD) : null;
95
+ if (!root) skip("npm did not say where it was run from (INIT_CWD)");
96
+ if (root === PACKAGE_ROOT) skip("this is the package's own install");
97
+ if (!existsSync(join(root, "package.json"))) skip("no package.json there");
98
+ try {
99
+ if (!statSync(root).isDirectory()) skip("INIT_CWD is not a directory");
100
+ } catch {
101
+ skip("INIT_CWD does not exist");
102
+ }
103
+ if (!existsSync(INSTALLER)) skip("the installer is missing from this install", true);
104
+ if (!looksLikeSuppaApp(root)) {
105
+ // Quiet: most repos that pull this package in for its API tools have no
106
+ // schema code, and telling them about a schema gate is noise.
107
+ skip("no Suppa schema code or @suppa/* dependency here");
108
+ }
109
+
110
+ const out = execFileSync(process.execPath, [INSTALLER, root], {
111
+ cwd: root,
112
+ encoding: "utf-8",
113
+ stdio: ["ignore", "pipe", "pipe"],
114
+ });
115
+ // The installer's own report is written for someone who typed the command.
116
+ // Here it lands in the middle of an npm install, where a wall of "+ wrote"
117
+ // lines is noise — but its "·" lines are the ones that need a human: a git
118
+ // config it could not set, a settings.json it would not touch.
119
+ // Both scripts ship in the same package at the same version, so matching its
120
+ // wording here is a coupling that cannot drift apart in the wild: "already
121
+ // current" and a deliberate --no-git are the installer telling itself it had
122
+ // nothing to do, and nobody needs to read that during an install.
123
+ const noise = /already current|skipped \(--no-git\)/;
124
+ const needsAttention = out
125
+ .split("\n")
126
+ .filter((l) => l.trimStart().startsWith("·") && !noise.test(l));
127
+ process.stdout.write(
128
+ "suppa-mcp-2: entity-code guards in place (agent hooks, AGENTS.md/CLAUDE.md, pre-commit, " +
129
+ "CI job, npm run schema:gate). SUPPA_NO_GUARD_INSTALL=1 turns this off; " +
130
+ "`npx suppa-entity-guards .` re-runs it.\n",
131
+ );
132
+ for (const line of needsAttention) process.stdout.write(` ${line.trim()}\n`);
133
+ } catch (e) {
134
+ // An install that cannot be completed is a worse outcome than a repo without
135
+ // hooks, so this never propagates.
136
+ process.stdout.write(
137
+ `suppa-mcp-2: could not install the entity-code guards (${
138
+ e instanceof Error ? e.message.split("\n")[0] : String(e)
139
+ }). Run \`npx suppa-entity-guards .\` when convenient.\n`,
140
+ );
141
+ }
142
+ process.exit(0);