suppa-mcp-2 1.14.0 → 1.16.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 CHANGED
@@ -378,9 +378,26 @@ shipped with restated defaults and four bare relation stand-ins. Install the
378
378
  guards into an application repo:
379
379
 
380
380
  ```bash
381
+ npx suppa-entity-guards .
382
+ # or, without npx:
381
383
  node node_modules/suppa-mcp-2/skills/suppa-entity-code/scripts/install-entity-code-guards.mjs .
382
384
  ```
383
385
 
386
+ It is idempotent, and it refuses to write a hook whose path does not resolve —
387
+ hooks pointing at nothing behave exactly like no hooks at all.
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
+
384
401
  Five layers, each covering a way the previous one is missed: Claude Code hooks
385
402
  put the rules in an agent's context **before** it writes `*.entity.ts` and the
386
403
  gate's findings in front of it **after**, a `Stop` hook refuses to end a turn
package/package.json CHANGED
@@ -1,61 +1,63 @@
1
- {
2
- "name": "suppa-mcp-2",
3
- "version": "1.14.0",
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
- "type": "module",
6
- "bin": {
7
- "suppa-mcp": "dist/bin.js"
8
- },
9
- "main": "dist/bin.js",
10
- "files": [
11
- "dist",
12
- "skills",
13
- "README.md",
14
- "LICENSE"
15
- ],
16
- "engines": {
17
- "node": ">=18"
18
- },
19
- "scripts": {
20
- "build": "tsc",
21
- "clean": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\"",
22
- "rebuild": "npm run clean && npm run build",
23
- "start": "node dist/bin.js",
24
- "dev": "tsc --watch",
25
- "test": "node scripts/check-version-literals.mjs && vitest run",
26
- "test:watch": "vitest",
27
- "prepublishOnly": "npm run build && npm test",
28
- "inspect": "npx @modelcontextprotocol/inspector node dist/bin.js",
29
- "schema:gate": "node skills/suppa-entity-code/scripts/entity-code-guard.mjs --ci .",
30
- "guards:install": "node skills/suppa-entity-code/scripts/install-entity-code-guards.mjs"
31
- },
32
- "keywords": [
33
- "mcp",
34
- "model-context-protocol",
35
- "suppa",
36
- "modern-expo",
37
- "ai",
38
- "llm",
39
- "tools",
40
- "claude",
41
- "copilot",
42
- "cursor"
43
- ],
44
- "license": "MIT",
45
- "repository": {
46
- "type": "git",
47
- "url": "https://git.modern-expo.com/asu/me-development/skills.git",
48
- "directory": "suppa-mcp-node"
49
- },
50
- "homepage": "https://modern.suppa.me",
51
- "dependencies": {
52
- "@modelcontextprotocol/sdk": "^1.18.0",
53
- "@napi-rs/keyring": "^1.1.0",
54
- "zod": "^3.23.8"
55
- },
56
- "devDependencies": {
57
- "@types/node": "^20.0.0",
58
- "typescript": "^5.6.0",
59
- "vitest": "^2.1.0"
60
- }
61
- }
1
+ {
2
+ "name": "suppa-mcp-2",
3
+ "version": "1.16.0",
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
+ "type": "module",
6
+ "bin": {
7
+ "suppa-mcp": "dist/bin.js",
8
+ "suppa-entity-guards": "skills/suppa-entity-code/scripts/install-entity-code-guards.mjs"
9
+ },
10
+ "main": "dist/bin.js",
11
+ "files": [
12
+ "dist",
13
+ "skills",
14
+ "README.md",
15
+ "LICENSE"
16
+ ],
17
+ "engines": {
18
+ "node": ">=18"
19
+ },
20
+ "scripts": {
21
+ "build": "tsc",
22
+ "clean": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\"",
23
+ "rebuild": "npm run clean && npm run build",
24
+ "start": "node dist/bin.js",
25
+ "dev": "tsc --watch",
26
+ "test": "node scripts/check-version-literals.mjs && vitest run",
27
+ "postinstall": "node skills/suppa-entity-code/scripts/postinstall.mjs",
28
+ "test:watch": "vitest",
29
+ "prepublishOnly": "npm run build && npm test",
30
+ "inspect": "npx @modelcontextprotocol/inspector node dist/bin.js",
31
+ "schema:gate": "node skills/suppa-entity-code/scripts/entity-code-guard.mjs --ci .",
32
+ "guards:install": "node skills/suppa-entity-code/scripts/install-entity-code-guards.mjs"
33
+ },
34
+ "keywords": [
35
+ "mcp",
36
+ "model-context-protocol",
37
+ "suppa",
38
+ "modern-expo",
39
+ "ai",
40
+ "llm",
41
+ "tools",
42
+ "claude",
43
+ "copilot",
44
+ "cursor"
45
+ ],
46
+ "license": "MIT",
47
+ "repository": {
48
+ "type": "git",
49
+ "url": "https://git.modern-expo.com/asu/me-development/skills.git",
50
+ "directory": "suppa-mcp-node"
51
+ },
52
+ "homepage": "https://modern.suppa.me",
53
+ "dependencies": {
54
+ "@modelcontextprotocol/sdk": "^1.18.0",
55
+ "@napi-rs/keyring": "^1.1.0",
56
+ "zod": "^3.23.8"
57
+ },
58
+ "devDependencies": {
59
+ "@types/node": "^20.0.0",
60
+ "typescript": "^5.6.0",
61
+ "vitest": "^2.1.0"
62
+ }
63
+ }
@@ -26,7 +26,7 @@
26
26
 
27
27
  import { execFileSync } from "node:child_process";
28
28
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
29
- import { dirname, join, relative, resolve } from "node:path";
29
+ import { dirname, isAbsolute, join, relative, resolve } from "node:path";
30
30
  import { fileURLToPath } from "node:url";
31
31
 
32
32
  const HERE = dirname(fileURLToPath(import.meta.url));
@@ -61,16 +61,36 @@ function readIfExists(path) {
61
61
  }
62
62
  }
63
63
 
64
+ /**
65
+ * The guard's path RELATIVE to the repo, or null when it lives outside it.
66
+ *
67
+ * `relative()` returns an ABSOLUTE path when the two sides sit on different
68
+ * Windows drives — a global install, or the repo on another drive. That path
69
+ * does not start with "..", so the old test read it as "inside the repo" and
70
+ * wrote `${CLAUDE_PROJECT_DIR}/D:/…`: a path that can never resolve, on hooks
71
+ * that then do nothing and say nothing. Guards installed and silently dead is
72
+ * the exact failure this installer exists to prevent.
73
+ */
74
+ function guardRelativeToRoot() {
75
+ const rel = relative(root, GUARD);
76
+ return rel && !rel.startsWith("..") && !isAbsolute(rel) ? rel.replace(/\\/g, "/") : null;
77
+ }
78
+
64
79
  /**
65
80
  * How the hook command should name the guard. Inside the repo (the normal
66
81
  * `pnpm add -D suppa-mcp-2` case) it is written relative to the project so the
67
82
  * settings file stays portable across machines; outside it, absolutely.
68
83
  */
69
84
  function guardPath() {
70
- const rel = relative(root, GUARD);
71
- return !rel.startsWith("..")
72
- ? `\${CLAUDE_PROJECT_DIR}/${rel.replace(/\\/g, "/")}`
73
- : GUARD.replace(/\\/g, "/");
85
+ const rel = guardRelativeToRoot();
86
+ return rel ? `\${CLAUDE_PROJECT_DIR}/${rel}` : GUARD.replace(/\\/g, "/");
87
+ }
88
+
89
+ /** Does the path just written actually land on the guard? */
90
+ function guardPathResolves(written) {
91
+ const prefix = "${CLAUDE_PROJECT_DIR}/";
92
+ const resolved = written.startsWith(prefix) ? join(root, written.slice(prefix.length)) : written;
93
+ return existsSync(resolved);
74
94
  }
75
95
 
76
96
  // ── 1. Claude Code hooks ──
@@ -87,6 +107,16 @@ function installHooks() {
87
107
  }
88
108
  }
89
109
  const guard = guardPath();
110
+ if (!guardPathResolves(guard)) {
111
+ // Never write a hook that points at nothing: it behaves exactly like no
112
+ // hook at all — no rules before the write, no gate after, and no message
113
+ // either way.
114
+ skipped.push(
115
+ `.claude/settings.json NOT written — the guard would be '${guard}', which does not exist. ` +
116
+ `Install suppa-mcp-2 in this repo (npm i -D suppa-mcp-2) and re-run.`,
117
+ );
118
+ return;
119
+ }
90
120
  const entry = (mode, statusMessage) => ({
91
121
  type: "command",
92
122
  command: "node",
@@ -149,9 +179,9 @@ function installGitHook() {
149
179
  skipped.push("git hook skipped (--no-git)");
150
180
  return;
151
181
  }
152
- const guard = relative(root, GUARD).startsWith("..")
153
- ? GUARD.replace(/\\/g, "/")
154
- : relative(root, GUARD).replace(/\\/g, "/");
182
+ // Same rule as the hooks: inside the repo it stays relative (git runs its
183
+ // hooks from the repo root), outside it is absolute.
184
+ const guard = guardRelativeToRoot() ?? GUARD.replace(/\\/g, "/");
155
185
  const hook = `#!/bin/sh
156
186
  # Managed by suppa-mcp-2 (skills/suppa-entity-code). Refuses a commit whose
157
187
  # staged *.entity.ts / *.seed.ts files fail the schema gate.
@@ -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);