suppa-mcp-2 1.10.0 → 1.12.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 +39 -10
- package/dist/server.js +14 -6
- package/dist/tools/entityCode.js +49 -7
- package/package.json +4 -2
- package/skills/suppa-entity-code/SKILL.md +31 -5
- package/skills/suppa-entity-code/references/enforcement.md +110 -0
- package/skills/suppa-entity-code/scripts/entity-code-guard.mjs +318 -0
- package/skills/suppa-entity-code/scripts/house-rules.mjs +30 -0
- package/skills/suppa-entity-code/scripts/install-entity-code-guards.mjs +261 -0
- package/skills/suppa-entity-code/scripts/validate-suppa-schema.mjs +559 -13
- package/skills/suppa-entity-code/templates/AGENTS.entity-code.md +73 -0
- package/skills/suppa-entity-code/templates/relation-target-stub.template.ts +29 -0
package/README.md
CHANGED
|
@@ -205,7 +205,7 @@ work normally. Erasing data for good is an admin action in the platform's own UI
|
|
|
205
205
|
| `suppa_logout` | Remove stored credentials for a tenant |
|
|
206
206
|
| `suppa_diagnostics` | Validate the whole multi-tenant setup |
|
|
207
207
|
| `suppa_health_check` | Config + upstream connectivity check (reports `version`) |
|
|
208
|
-
| `suppa_version` | Running build vs newest published, and how to upgrade |
|
|
208
|
+
| `suppa_version` | Running build vs newest published, and how to upgrade |
|
|
209
209
|
| `suppa_validate_entity_code` | Run the schema gate over an app repo before calling entity code done |
|
|
210
210
|
|
|
211
211
|
### Tasks
|
|
@@ -371,17 +371,46 @@ instead. An entity or seed left out of `EntityModule.forFeature()` fires
|
|
|
371
371
|
E301/E302, naming the module file to edit so the fix is a find-and-add, not a
|
|
372
372
|
search. Use the `write_entity_code` MCP prompt to drive it from any client.
|
|
373
373
|
|
|
374
|
-
|
|
374
|
+
**Make the rules unskippable.** Stating a rule in a skill, in the server
|
|
375
|
+
instructions and in a tool description is optional at the moment code gets
|
|
376
|
+
written — an agent may open none of them, and that is exactly how an entity
|
|
377
|
+
shipped with restated defaults and four bare relation stand-ins. Install the
|
|
378
|
+
guards into an application repo:
|
|
379
|
+
|
|
380
|
+
```bash
|
|
381
|
+
node node_modules/suppa-mcp-2/skills/suppa-entity-code/scripts/install-entity-code-guards.mjs .
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
Five layers, each covering a way the previous one is missed: Claude Code hooks
|
|
385
|
+
put the rules in an agent's context **before** it writes `*.entity.ts` and the
|
|
386
|
+
gate's findings in front of it **after**, a `Stop` hook refuses to end a turn
|
|
387
|
+
while a changed schema file still fails, `.githooks/pre-commit` refuses the
|
|
388
|
+
commit, a `.gitlab/suppa-schema-gate.yml` job refuses the merge request, and a
|
|
389
|
+
managed section in `AGENTS.md` / `CLAUDE.md` carries the same rules to editors
|
|
390
|
+
with no hook support. Re-running the installer is safe, `--dry-run` prints the
|
|
391
|
+
plan, and details are in `skills/suppa-entity-code/references/enforcement.md`.
|
|
392
|
+
|
|
393
|
+
It also enforces the **authoring rules** the platform doc does not: a
|
|
375
394
|
relation property must carry a TypeScript type that agrees with its decorator
|
|
376
|
-
(E114/E115/W610
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
395
|
+
(E114/E115/W610, and W615 when the type names no class at all — `any`), enum
|
|
396
|
+
member keys are PascalCase (W611), no field option may be written at its
|
|
397
|
+
platform default (W612), `@Enum`/`@MultiEnum` take a global name only when
|
|
398
|
+
the enum is actually shared (W613), and a relation target that already exists on
|
|
399
|
+
the tenant is declared as a **stub**: `@Entity({ name, key })` + `extends
|
|
400
|
+
SystemBaseEntity`, an **empty body**, alone in a `<name>.stub.entity.ts` file,
|
|
401
|
+
registered in `forFeature()`. A bare `export class Accounts {}` satisfies the
|
|
402
|
+
thunk but registers nothing, so the platform cannot resolve the relation — the
|
|
403
|
+
target is chased through its import (relative, `.js`-suffixed or tsconfig-aliased)
|
|
404
|
+
into the file that declares it and reported as E116. A stub that kept its fields
|
|
405
|
+
is E117, because each field is a column the migration would create on a table
|
|
406
|
+
another application owns; the `.stub.entity.ts` name is what makes that rule
|
|
407
|
+
checkable (W617 when it is missing, W616 when stubs share a file). Those, plus
|
|
380
408
|
`owner` first in a tabular part's `importKeyFields` (W607) and no `inverse` on
|
|
381
|
-
`@ManyToOne`/`@ManyToMany` (W609), are **rule violations
|
|
382
|
-
|
|
383
|
-
`--no-strict` demotes them
|
|
384
|
-
|
|
409
|
+
`@ManyToOne`/`@ManyToMany` (W609), are the **rule violations** — W607, W609,
|
|
410
|
+
W610, W611, W612, W613, W615, W616, W617 — and like errors they exit 1, because a
|
|
411
|
+
rule that only warns is a rule that gets ignored. `--no-strict` demotes them for a legacy repo, and says so:
|
|
412
|
+
they print as `[rule violation, demoted]` and the summary ends `NOT a clean
|
|
413
|
+
run`. Advisory warnings — W601-W606, W608, W614 — never block; they report what
|
|
385
414
|
the checker could not see.
|
|
386
415
|
|
|
387
416
|
Tabular parts (owned child sub-tables like checklist items or order lines)
|
package/dist/server.js
CHANGED
|
@@ -269,12 +269,13 @@ ENTITY BUILDER (create + edit fields; removal is UI-only)
|
|
|
269
269
|
- Existing fields CAN be edited with suppa_update_field (name, title, notNull/unique/default, relation target, and the options above), within the platform's own limits: a field's TYPE can never be changed, its SUBTYPE only toggles 'encrypted' on/off (text fields only), and a system field takes just title + the options keys. Removing a field is still UI-only — this server has no remove-field call.
|
|
270
270
|
|
|
271
271
|
WRITING ENTITY CODE (*.entity.ts in an application repo — NOT the API tools above)
|
|
272
|
-
These
|
|
272
|
+
These five rules are house rules of this platform. They OVERRIDE the platform's own migrations doc, which contradicts two of them, and they override the style of the entities already in the repo you are editing — an existing file that breaks them is the habit these rules exist to stop, not a convention to match. The full skill is skills/suppa-entity-code/SKILL.md inside the installed suppa-mcp-2 package; these five bind whether or not you open it.
|
|
273
273
|
1. TYPE EVERY RELATION PROPERTY to match its decorator: @ManyToOne -> \`owner: Target;\` (\`owner?: Target\` when the relation is nullable), @ManyToMany/@OneToMany/@ManyToManyBackRef -> \`peers: Target[];\`. Never \`any\`.
|
|
274
274
|
2. ENUM MEMBER KEYS ARE PascalCase — \`NotFilled = 'Not filled'\`. The stored value is the string on the right and need not match the key.
|
|
275
275
|
3. NEVER WRITE A FIELD OPTION AT ITS DEFAULT. canGroup, canSort, showInTable, editFromTable and canFilter are already true; readOnly and searchable are already false. Write one ONLY where the field departs from that (usually just \`searchable: true\`). A field with all seven spelled out is wrong even though it works.
|
|
276
276
|
4. @Enum/@MultiEnum TAKE THE GLOBAL NAME ONLY WHEN THE ENUM IS GLOBAL — shared by another entity, or referenced from a seed record. Otherwise omit the first argument entirely: \`@Enum(StatusEnum, StatusTitles, { … })\`, and the decorator derives <ClassName>.<propertyName>. A field's own \`key: 'Entity.field'\` is the rename key, NOT a reference, and does not make the enum global.
|
|
277
|
-
|
|
277
|
+
5. A RELATION TARGET THAT ALREADY EXISTS on the tenant (created earlier, or owned by another application) gets a STUB, and a stub is three things at once: \`@Entity({ name: 'Accounts', key: 'Accounts' }) export class Accounts extends SystemBaseEntity {}\` with an EMPTY body, ALONE in a file named \`accounts.stub.entity.ts\`, and REGISTERED in forFeature() with the entities you create. Never a bare \`export class Accounts {}\` — it satisfies the thunk but registers nothing, so the platform cannot resolve the relation (E116). Never fields on a stub — every field is a column the migration would create on a table you do not own (E117). Platform system entities need no stub — import UsersEntity/FilesEntity/IconsEntity from @suppa/sdk.
|
|
278
|
+
Before reporting the file done, run the gate: call suppa_validate_entity_code(path=<app-root>). It fails on every one of the five and names file:line. passed=false means fix and re-run, not "note and move on". (Same checker on the command line: node node_modules/suppa-mcp-2/skills/suppa-entity-code/scripts/validate-suppa-schema.mjs <app-root>.)
|
|
278
279
|
|
|
279
280
|
ATTACHMENTS (files on a record)
|
|
280
281
|
- A record can carry files only if its entity has a 'file' or 'multi-file' field; check with suppa_describe_entity and add one with suppa_add_field if it has none.
|
|
@@ -2174,13 +2175,19 @@ export function buildServer() {
|
|
|
2174
2175
|
" bundled suppa-entity-code skill names as its close-out gate, and it catches what tsc\n" +
|
|
2175
2176
|
" cannot: an unregistered entity class (no table is ever created for it), a JS value in\n" +
|
|
2176
2177
|
" 'default' where a SQL string is required, a relation without a thunk, seed records that\n" +
|
|
2177
|
-
" duplicate on every restart — plus the
|
|
2178
|
+
" duplicate on every restart — plus the house rules, which fail the gate:\n" +
|
|
2178
2179
|
" * a relation property must be typed to match its decorator (Target / Target[], and\n" +
|
|
2179
2180
|
" optional when the relation is nullable) — never 'any';\n" +
|
|
2180
2181
|
" * enum member keys are PascalCase;\n" +
|
|
2181
2182
|
" * no field option may be written at its default (canGroup/canSort/showInTable/\n" +
|
|
2182
2183
|
" editFromTable/canFilter are already true, readOnly/searchable already false);\n" +
|
|
2183
|
-
" * @Enum/@MultiEnum take a global name ONLY when the enum is shared or seed-referenced
|
|
2184
|
+
" * @Enum/@MultiEnum take a global name ONLY when the enum is shared or seed-referenced;\n" +
|
|
2185
|
+
" * a relation target that already exists on the tenant gets a STUB — @Entity({name,key})\n" +
|
|
2186
|
+
" + extends SystemBaseEntity, EMPTY body, its own file, registered in forFeature();\n" +
|
|
2187
|
+
" a bare 'export class Accounts {}' registers nothing (E116), and stubs sharing a file\n" +
|
|
2188
|
+
" are W616;\n" +
|
|
2189
|
+
" * 'owner' comes first in a tabular part's importKeyFields, and no 'inverse' is passed\n" +
|
|
2190
|
+
" to @ManyToOne/@ManyToMany.\n" +
|
|
2184
2191
|
' Pass the app ROOT, not one file: several rules read the whole repo ("nothing references\n' +
|
|
2185
2192
|
" this enum name\" cannot be judged from a single file).\n" +
|
|
2186
2193
|
" passed=false means fix and re-run — it is not advisory.",
|
|
@@ -2191,8 +2198,9 @@ export function buildServer() {
|
|
|
2191
2198
|
strict: z
|
|
2192
2199
|
.boolean()
|
|
2193
2200
|
.default(true)
|
|
2194
|
-
.describe("true (default): the
|
|
2195
|
-
"for a legacy repo you are not cleaning up in this pass,
|
|
2201
|
+
.describe("true (default): the house rules above (W607/W609-W613, W615, W616) fail the gate. false: " +
|
|
2202
|
+
"they are reported as advisory — for a legacy repo you are not cleaning up in this pass, " +
|
|
2203
|
+
"never for a file you just wrote. Errors, E116 included, block either way."),
|
|
2196
2204
|
},
|
|
2197
2205
|
annotations: _READ,
|
|
2198
2206
|
}, async (a) => text(await entityCode.validateEntityCode(a.path, a.strict)));
|
package/dist/tools/entityCode.js
CHANGED
|
@@ -12,20 +12,41 @@
|
|
|
12
12
|
* skills/suppa-entity-code/scripts/validate-suppa-schema.mjs — loaded from the
|
|
13
13
|
* installed package, never reimplemented — reporting the same codes.
|
|
14
14
|
*/
|
|
15
|
-
import { existsSync, statSync } from "node:fs";
|
|
15
|
+
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
16
16
|
import { dirname, isAbsolute, join, resolve } from "node:path";
|
|
17
17
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
18
18
|
import { jsonResponse } from "../utils.js";
|
|
19
|
-
/**
|
|
20
|
-
function
|
|
19
|
+
/** A bundled skill script, from dist/tools/ or src/tools/ alike. */
|
|
20
|
+
function skillScript(name) {
|
|
21
21
|
const here = dirname(fileURLToPath(import.meta.url));
|
|
22
22
|
for (const root of [join(here, "..", ".."), join(here, "..", "..", "..")]) {
|
|
23
|
-
const p = join(root, "skills", "suppa-entity-code", "scripts",
|
|
23
|
+
const p = join(root, "skills", "suppa-entity-code", "scripts", name);
|
|
24
24
|
if (existsSync(p))
|
|
25
25
|
return p;
|
|
26
26
|
}
|
|
27
27
|
return null;
|
|
28
28
|
}
|
|
29
|
+
function validatorPath() {
|
|
30
|
+
return skillScript("validate-suppa-schema.mjs");
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* What the gate blocks on, read from the file that defines the rules rather than
|
|
34
|
+
* restated here. A hand-written list understated it: it named four rules while
|
|
35
|
+
* the checker blocked on seven, so an agent whose run failed on a code the note
|
|
36
|
+
* never mentioned could reasonably read the failure as advisory.
|
|
37
|
+
*/
|
|
38
|
+
async function blockingSummary() {
|
|
39
|
+
const p = skillScript("house-rules.mjs");
|
|
40
|
+
if (!p)
|
|
41
|
+
return "the house rules in skills/suppa-entity-code/SKILL.md";
|
|
42
|
+
try {
|
|
43
|
+
const mod = await import(pathToFileURL(p).href);
|
|
44
|
+
return String(mod.BLOCKING_SUMMARY ?? "").trim() || "the house rules in SKILL.md";
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return "the house rules in skills/suppa-entity-code/SKILL.md";
|
|
48
|
+
}
|
|
49
|
+
}
|
|
29
50
|
/**
|
|
30
51
|
* Run the schema gate over an application repo (or a single file).
|
|
31
52
|
*
|
|
@@ -84,6 +105,28 @@ export async function validateEntityCode(path, strict = true) {
|
|
|
84
105
|
}
|
|
85
106
|
}
|
|
86
107
|
else {
|
|
108
|
+
// A named file with no schema in it — a README, a tsconfig, a util — was
|
|
109
|
+
// analyzed and reported passed: true. "Checked and clean" having checked
|
|
110
|
+
// nothing is the one answer a gate must never give. (The CLI refuses the
|
|
111
|
+
// same input with exit 2.)
|
|
112
|
+
const isTypeScript = /\.tsx?$/.test(target) && !/\.d\.ts$/.test(target);
|
|
113
|
+
const looksLikeSchema = isTypeScript &&
|
|
114
|
+
(/\.(entity|seed)\.ts$/.test(target) ||
|
|
115
|
+
(() => {
|
|
116
|
+
try {
|
|
117
|
+
return /EntityModule\.forFeature|@Entity\s*\(|createSeed\s*\(/.test(readFileSync(target, "utf-8"));
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
})());
|
|
123
|
+
if (!looksLikeSchema) {
|
|
124
|
+
return jsonResponse({
|
|
125
|
+
error: `'${target}' contains no schema code, so nothing was analyzed and nothing was verified. ` +
|
|
126
|
+
"Expected *.entity.ts, *.seed.ts, or a .ts file containing EntityModule.forFeature — " +
|
|
127
|
+
"or point this at the application repo's ROOT, which is what it wants anyway.",
|
|
128
|
+
});
|
|
129
|
+
}
|
|
87
130
|
files = [resolve(target)];
|
|
88
131
|
}
|
|
89
132
|
let res;
|
|
@@ -126,8 +169,7 @@ export async function validateEntityCode(path, strict = true) {
|
|
|
126
169
|
? advisory.length
|
|
127
170
|
? "Gate passed. The advisory warnings say what could NOT be checked (content delivered by reference, a missing tsconfig) — read them before trusting a clean run."
|
|
128
171
|
: "Gate passed."
|
|
129
|
-
: "Gate FAILED — do not report the file done. Fix every entry in errors and rule_violations, then
|
|
130
|
-
|
|
131
|
-
"default, and no global enum name on a local enum.",
|
|
172
|
+
: "Gate FAILED — do not report the file done. Fix every entry in errors and rule_violations, then " +
|
|
173
|
+
`re-run. What blocks: ${await blockingSummary()}.`,
|
|
132
174
|
});
|
|
133
175
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "suppa-mcp-2",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.12.0",
|
|
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": {
|
|
@@ -25,7 +25,9 @@
|
|
|
25
25
|
"test": "node scripts/check-version-literals.mjs && vitest run",
|
|
26
26
|
"test:watch": "vitest",
|
|
27
27
|
"prepublishOnly": "npm run build && npm test",
|
|
28
|
-
"inspect": "npx @modelcontextprotocol/inspector node dist/bin.js"
|
|
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"
|
|
29
31
|
},
|
|
30
32
|
"keywords": [
|
|
31
33
|
"mcp",
|
|
@@ -40,13 +40,13 @@ Confirm all 5 before writing anything:
|
|
|
40
40
|
## Hard rules
|
|
41
41
|
|
|
42
42
|
1. Every entity extends `SystemBaseEntity`; never declare `id`, `createdAt`, `updatedAt`, `deletedAt`, `createdBy`, `removedBy` yourself — it already provides them.
|
|
43
|
-
2. An entity class that is not in `EntityModule.forFeature()` does not exist — the platform creates no table for it (doc: "An entity class that is never passed to forFeature() is invisible"). Write the entity and register it in the SAME step; never move on to the next entity, or report progress, with an unregistered class. Being *named* in a `forFeature()` is not enough: the call's result must be consumed by an `@Module`'s `imports` (rule
|
|
43
|
+
2. An entity class that is not in `EntityModule.forFeature()` does not exist — the platform creates no table for it (doc: "An entity class that is never passed to forFeature() is invisible"). Write the entity and register it in the SAME step; never move on to the next entity, or report progress, with an unregistered class. Being *named* in a `forFeature()` is not enough: the call's result must be consumed by an `@Module`'s `imports` (rule 20), or nothing is registered at all.
|
|
44
44
|
3. `default` is a SQL expression string — `'false'`, `"'draft'"` — never a JS value; a JS value is rejected at migration time.
|
|
45
45
|
4. Scalars only via `@Column({ type: FieldTypeEnum.X })`; relations/enums/files are NEVER declared via `@Column` — use the `@ManyToOne`/`@ManyToMany`/`@OneToMany`/`@ManyToManyBackRef`/`@Enum`/`@MultiEnum`/`@File`/`@MultiFile` families.
|
|
46
46
|
5. Relation targets are thunks — `() => Target`, never the class itself — or circular imports break.
|
|
47
47
|
6. Do not pass the optional `inverse` selector to `@ManyToOne`/`@ManyToMany` — write `@ManyToOne(() => Target, { … })`. Add one only when the target class declares the paired back-reference and you are deliberately linking the two sides. An `inverse` must select a RELATION property on the target (`(task) => task.project`); `(e) => e.id` is always wrong — `id` is a system column, not a back-reference.
|
|
48
48
|
7. If an option isn't in the reference tables (`references/entities.md`, `references/seeds.md`, `references/registration.md`), it doesn't exist — stop and ask, don't guess.
|
|
49
|
-
8. Every entity class must appear in the class array passed as `forFeature()`'s FIRST argument (there is no `entities` option — rule
|
|
49
|
+
8. Every entity class must appear in the class array passed as `forFeature()`'s FIRST argument (there is no `entities` option — rule 20); every seed in the options object's `seeds` array, dependencies first — `workflowsSeed` before `stageWorkflowsSeed`.
|
|
50
50
|
9. Seeds: every record carries all `importKeyFields` (or `$key`); relations are referenced by the target's import-key object, never a numeric id; no system columns; no `$readAccess`/`$updateAccess`/`$instanceAccess`; no reverse `@OneToMany` field, even as `[]`.
|
|
51
51
|
10. Autoload paths (`entitiesPath`/`seedsPath`) point at `dist/`, never `src/` — autoloading reads compiled output.
|
|
52
52
|
11. Renames need `key` set on `@Entity()`/`@Column()` BEFORE the rename ships — otherwise it's a drop-and-create, not a rename.
|
|
@@ -60,7 +60,25 @@ Confirm all 5 before writing anything:
|
|
|
60
60
|
**This rule overrides the platform doc**, which says flatly "Give the enum a global name (first argument)" (migrations.html → `references/entities.md`) and passes one in every example. Follow the rule, not the example.
|
|
61
61
|
**A field's `key` is not a reference.** `key: '<Entity>.<field>'` on the same field is the rename key (rule 11) and is spelled exactly like a global enum name — it does not make the enum shared, and it is not what a seed resolves against.
|
|
62
62
|
18. Repeating rows owned by one parent record are a **tabular part**, never a plain entity: `type: 'tabular-part'` + `relationEntityName` (the parent's `@Entity()` name) + a `@ManyToOne` field named exactly `owner` pointing at the parent class — all three required, the platform infers none of them. Put `owner` FIRST in `importKeyFields` — it scopes the business key to the parent, or rows collide across different parents.
|
|
63
|
-
19.
|
|
63
|
+
19. **A relation target that ALREADY EXISTS on the tenant gets a STUB — four requirements, none inferred.** When a relation points at an entity this package does not define (owned by another application, or created outside this package), declare a stand-in. All four bind, and each has its own finding:
|
|
64
|
+
|
|
65
|
+
| # | Requirement | Why | Broken |
|
|
66
|
+
|---|---|---|---|
|
|
67
|
+
| 1 | `@Entity({ name, key })` on the class | the platform resolves the relation by that name; a bare `export class Accounts {}` satisfies the thunk at compile time and registers NOTHING | **E116** |
|
|
68
|
+
| 2 | `extends SystemBaseEntity` | it contributes `id`/`createdAt`/…, and relation properties typed with the stub are only usable with them | **E101** |
|
|
69
|
+
| 3 | **EMPTY body — no fields, ever** | the stub names a table you do NOT own; every field it declares is a column the migration creates or alters on that real table | **E117** |
|
|
70
|
+
| 4 | Alone in `<kebab-name>.stub.entity.ts`, exported from the barrel, **registered** in `forFeature()` | the filename is the only thing in the code that says "stub", and it is what makes requirement 3 checkable; an unregistered class is invisible to the platform | **W617** (wrong file) / **W616** (sharing a file) / **E301** (unregistered) |
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
// accounts.stub.entity.ts — one stub, one file
|
|
74
|
+
import { Entity, SystemBaseEntity } from '@suppa/sdk';
|
|
75
|
+
|
|
76
|
+
@Entity({ name: 'Accounts', key: 'Accounts' })
|
|
77
|
+
export class Accounts extends SystemBaseEntity {}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
`.stub.entity.ts` still ends in `.entity.ts`, so discovery and `entitiesPath` autoload are unchanged. **Registration is not what protects the real table — the empty body is.** Leaving a stub out of `forFeature()` to "keep the migration away from it" only makes the relation unresolvable (E301); a *fielded* stub that is registered is the actual disaster, and E117 is the rule that stops it. Platform system entities (`Users`, `Files`, `Icons`, …) need no stub at all — import `UsersEntity`/`FilesEntity`/`IconsEntity` from `@suppa/sdk`. Template: `templates/relation-target-stub.template.ts`.
|
|
81
|
+
20. **`EntityModule.forFeature()` must be consumed by an `@Module`, and has exactly two shapes.** It RETURNS a module: put it in `@Module({ imports: [...] })` and export that class from `src/index.ts` as `AppModule` — a bare `EntityModule.forFeature(...);` statement discards the result and registers nothing (E307). The two shapes (`references/registration.md`) are `forFeature([A, B], { seeds: [...] })` — classes FIRST, options second — and `forFeature({ entitiesPath, seedsPath })` for autoloading. The options object accepts only `seeds`, `entitiesPath` and `seedsPath`. `forFeature({ entities: [...] })` looks reasonable and registers NOTHING: the classes are dropped with the unknown option and no table is created for any of them. E306.
|
|
64
82
|
|
|
65
83
|
## Decorator decision table
|
|
66
84
|
|
|
@@ -76,6 +94,7 @@ Confirm all 5 before writing anything:
|
|
|
76
94
|
| …the same, but shared across entities or referenced from a seed | `@Enum('<Entity>.<field>', <Field>Enum, <Field>Titles?, options?)` |
|
|
77
95
|
| Fixed multi-select value set | `@MultiEnum(...)` — same signatures as `@Enum` |
|
|
78
96
|
| Foreign key on this entity | `@ManyToOne(() => Target, options?)` → `prop: Target;` — **no inverse** |
|
|
97
|
+
| Relation to an entity that ALREADY EXISTS on the tenant (another application's, or created outside this package) | **Stub** — `@Entity({ name, key }) export class X extends SystemBaseEntity {}`, EMPTY body, its own file, registered in `forFeature()`; see `templates/relation-target-stub.template.ts` (rule 19). System entities: import `UsersEntity`/`FilesEntity`/… from `@suppa/sdk` instead |
|
|
79
98
|
| Pivot table between two entities | `@ManyToMany(() => Target, options?)` → `prop: Target[];` — **no inverse** |
|
|
80
99
|
| Reverse side of a `@ManyToMany` | `@ManyToManyBackRef(() => Target, (t) => t.<thisRelationProp>, options?)` → `prop: Target[];` |
|
|
81
100
|
| Reverse side of a `@ManyToOne` | `@OneToMany(() => Target, (t) => t.<thisRelationProp>, options?)` → `prop: Target[];` |
|
|
@@ -120,6 +139,7 @@ A `@ManyToOne` without `nullable: false` is written `owner?: ProductMatrixEntity
|
|
|
120
139
|
| Thing | Convention | Example |
|
|
121
140
|
|---|---|---|
|
|
122
141
|
| Entity/seed file | kebab-case, plural | `stage-workflows.entity.ts` / `stage-workflows.seed.ts` |
|
|
142
|
+
| **Stub file** (rule 19) | kebab-case + `.stub.entity.ts` — one stub per file; the suffix is what makes the empty-body rule checkable | `accounts.stub.entity.ts` |
|
|
123
143
|
| Entity class | PascalCase, plural = `@Entity()`'s `name` | `StageWorkflows` |
|
|
124
144
|
| Seed export | camelCase plural + `Seed` | `stageWorkflowsSeed` |
|
|
125
145
|
| Enum | PascalCase + `Enum` | `StageStatusEnum` |
|
|
@@ -212,7 +232,7 @@ If that prints nothing, the entity is not registered.
|
|
|
212
232
|
## Close-out gate (all steps, in order — no "done" before all pass)
|
|
213
233
|
|
|
214
234
|
```
|
|
215
|
-
1. suppa_validate_entity_code(path=<app-root>) # passed: true
|
|
235
|
+
1. suppa_validate_entity_code(path=<app-root>) # passed: true
|
|
216
236
|
(or on the command line, same checker: node <this-skill-dir>/scripts/validate-suppa-schema.mjs <app-root> # exit 0)
|
|
217
237
|
(installed via npm: node_modules/suppa-mcp-2/skills/suppa-entity-code/scripts/validate-suppa-schema.mjs)
|
|
218
238
|
2. npx tsc --noEmit # in the app repo
|
|
@@ -224,7 +244,7 @@ Step 1 exists to catch exactly this: an unregistered class is E301 and the gate
|
|
|
224
244
|
|
|
225
245
|
`validate-suppa-schema.mjs` exits `0` on a clean run, `1` on violations, `2` on a usage error or a missing path. The gate requires exit `0`.
|
|
226
246
|
|
|
227
|
-
**Two classes of finding block it.** Errors (`E…`) always do. So do the *rule violations* — `W607`, `W609`, `W610`, `W611`, `W612`, `W613`, `W615` — the codes that name a HOUSE RULE (rules 14-
|
|
247
|
+
**Two classes of finding block it.** Errors (`E…`) always do. So do the *rule violations* — `W607`, `W609`, `W610`, `W611`, `W612`, `W613`, `W615`, `W616`, `W617` — the codes that name a HOUSE RULE (rules 14-19) broken on a specific line, because a rule that only warns is a rule that gets ignored (that is exactly how an entity shipped with seven restated defaults on every field). Everything else is advisory and never blocks: `W601`-`W606` and `W608`, `W614`, which report what the checker could not see or could not verify, plus style advice the doc itself does not mandate.
|
|
228
248
|
|
|
229
249
|
`--no-strict` demotes the rule violations back to warnings. It exists for a legacy repo you are not cleaning up in this pass; it is not for making your own new file pass, and the run says so — demoted findings print as `[rule violation, demoted]` and the summary ends with `NOT a clean run`. `W613` argues from absence ("nothing references this name"), so it only blocks when a DIRECTORY was given: the checker then scans every `.ts` from the application's package root, including services and DTOs it never parses, so a name used anywhere in the repo counts as referenced. On an explicit file list it can only warn.
|
|
230
250
|
|
|
@@ -267,5 +287,11 @@ The validator parses with the TypeScript compiler API, read from the app repo yo
|
|
|
267
287
|
| Duplicate tabular-part rows across different parents | `owner` is missing from `importKeyFields`, so the key is matched globally instead of per-parent | E110 |
|
|
268
288
|
| A tabular part's rows land on/read from the wrong parent | `owner`'s `@ManyToOne` target resolves to an entity whose `@Entity()` name doesn't match `relationEntityName` | E109 |
|
|
269
289
|
| A tabular part's business key isn't scoped to its parent | `owner` is present in `importKeyFields` but not first | W607 |
|
|
290
|
+
| A relation targets a bare class (`export class Accounts {}`), or one respelled as `const Accounts = class {}` | Not an `@Entity` class — the thunk compiles but the platform cannot resolve the relation. Declare a stub per rule 19 | E116 |
|
|
291
|
+
| A stub kept its fields, and the migration altered a table another application owns | The empty body is the whole point of a stub — a fielded one converges columns onto the real table | E117 |
|
|
292
|
+
| A field-less entity that is really a stub, in an ordinary `*.entity.ts` | Nothing marks it as a stub, so E117 cannot apply — rename to `<name>.stub.entity.ts` | W617 (blocks the gate) |
|
|
293
|
+
| Several stubs piled into one `relation-targets.ts` | Each existing-entity stub lives in its OWN file | W616 (blocks the gate) |
|
|
294
|
+
| A stub was left out of `forFeature()` "so the migration can't touch the real table" | A stub is registered like any other entity — its EMPTY body is what protects the real table, not the missing registration | E301 |
|
|
295
|
+
| The gate passes, but nobody ran it | Install the guards: `node scripts/install-entity-code-guards.mjs <app-root>` — hooks put the rules in front of an agent before it writes and the gate in front of it after, a pre-commit refusal catches whoever had no hooks, and a CI job catches whatever reached the branch. See `references/enforcement.md` | — |
|
|
270
296
|
| Validator warns W606 | Content delivered via spread or reference — options, `default`, `subType`, `importKeyFields`, seed records, enum refs, `$key`, autoload paths, registration arrays, tabular-part `type`/`relationEntityName` — is not statically verifiable; the matching check is skipped. Inline it so the validator can check | W606 |
|
|
271
297
|
| Validator warns W608 | No `tsconfig.json` at the given root, so `experimentalDecorators`/`emitDecoratorMetadata` could not be verified — point the validator at the app root | W608 |
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# Making the rules unskippable
|
|
2
|
+
|
|
3
|
+
Stating a rule is not enforcing it. Every channel this skill used to rely on is
|
|
4
|
+
optional at the moment the code gets written:
|
|
5
|
+
|
|
6
|
+
| Channel | How it is missed |
|
|
7
|
+
|---|---|
|
|
8
|
+
| `SKILL.md` | an agent may never open it |
|
|
9
|
+
| MCP server instructions | some clients never surface the `instructions` field; a long-running server keeps whatever build it started with, so a rule released today reaches nobody until every client restarts |
|
|
10
|
+
| Tool description | only read if that tool is called |
|
|
11
|
+
| Code review | the reviewer is the same agent that wrote the code |
|
|
12
|
+
|
|
13
|
+
That is not a hypothetical list — it is the post-mortem of an entity that
|
|
14
|
+
shipped with seven restated default options on every field, a global enum name
|
|
15
|
+
on a purely local enum, and four bare `export class Accounts {}` stand-ins that
|
|
16
|
+
registered nothing. The author's agent had none of the rules in context, and
|
|
17
|
+
the gate that would have caught all of it was never run.
|
|
18
|
+
|
|
19
|
+
So the rules are attached to **events** instead. Install them into an
|
|
20
|
+
application repo with:
|
|
21
|
+
|
|
22
|
+
```
|
|
23
|
+
node node_modules/suppa-mcp-2/skills/suppa-entity-code/scripts/install-entity-code-guards.mjs .
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Re-running is safe: managed regions are fenced with markers and replaced, hooks
|
|
27
|
+
the repo configured itself are left alone, and `--dry-run` prints the plan.
|
|
28
|
+
|
|
29
|
+
## The five layers
|
|
30
|
+
|
|
31
|
+
Each one covers a way the previous one is missed.
|
|
32
|
+
|
|
33
|
+
### 1. Before the write — `PreToolUse`
|
|
34
|
+
|
|
35
|
+
`Write`/`Edit` on a `*.entity.ts` / `*.seed.ts` path injects the rules digest
|
|
36
|
+
into the agent's context as `additionalContext`. It does **not** block, and it
|
|
37
|
+
deliberately sends no `permissionDecision`: a guard must never approve a write
|
|
38
|
+
the user's own permission settings would gate.
|
|
39
|
+
|
|
40
|
+
Cost of it firing: a few hundred tokens on exactly the turns that need them.
|
|
41
|
+
|
|
42
|
+
### 2. After the write — `PostToolUse`
|
|
43
|
+
|
|
44
|
+
The gate runs over the file's application root (nearest `package.json`). A
|
|
45
|
+
failure exits `2`, which puts the findings — with the rules attached — in front
|
|
46
|
+
of the agent as the next thing it reads. `PostToolUse` cannot undo the write;
|
|
47
|
+
this makes the violation the agent's immediate problem instead of a surprise at
|
|
48
|
+
review time.
|
|
49
|
+
|
|
50
|
+
If the gate cannot run (no `typescript` in the target repo), the guard says so
|
|
51
|
+
as context and exits `0`. A guard that walls off unrelated edits gets
|
|
52
|
+
uninstalled, and then it protects nothing.
|
|
53
|
+
|
|
54
|
+
### 3. Before the turn ends — `Stop`
|
|
55
|
+
|
|
56
|
+
If any schema file in the working tree is changed and its root fails the gate,
|
|
57
|
+
the turn is refused. This is the layer that stops "I will fix the gate findings
|
|
58
|
+
later" — there is no later. `stop_hook_active` is honoured, so a turn that is
|
|
59
|
+
already inside a Stop continuation is never blocked twice.
|
|
60
|
+
|
|
61
|
+
### 4. Before the commit — `.githooks/pre-commit`
|
|
62
|
+
|
|
63
|
+
The same gate over **staged** schema files, exit `1`. This catches the case the
|
|
64
|
+
hooks cannot: a human editing by hand, an agent in an editor with no hook
|
|
65
|
+
support, a `--dangerously-skip-permissions` run with hooks disabled.
|
|
66
|
+
|
|
67
|
+
The installer sets `core.hooksPath=.githooks` only when it is unset. If the repo
|
|
68
|
+
already uses husky or lefthook, it says so and leaves the setting alone — chain
|
|
69
|
+
the call from the existing hook:
|
|
70
|
+
|
|
71
|
+
```sh
|
|
72
|
+
node node_modules/suppa-mcp-2/skills/suppa-entity-code/scripts/entity-code-guard.mjs --pre-commit
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### 5. Before the merge — CI
|
|
76
|
+
|
|
77
|
+
`.gitlab/suppa-schema-gate.yml` runs `--ci` over the repo on merge-request
|
|
78
|
+
pipelines. This is the copy nothing local can skip — no hooks, no
|
|
79
|
+
`--no-verify`, no "my agent said it was fine". If you install only one layer,
|
|
80
|
+
install this one.
|
|
81
|
+
|
|
82
|
+
## Agents in editors without hooks
|
|
83
|
+
|
|
84
|
+
`AGENTS.md` and `CLAUDE.md` get a managed section carrying the same rules.
|
|
85
|
+
Copilot, Cursor, Gemini CLI and Claude Code all read these files, and they are
|
|
86
|
+
in the repo, so they travel with the code rather than with a client's config.
|
|
87
|
+
|
|
88
|
+
## What the guard does, by mode
|
|
89
|
+
|
|
90
|
+
```
|
|
91
|
+
entity-code-guard.mjs --pre-tool-use hook: rules into context (stdin: hook JSON)
|
|
92
|
+
--post-tool-use hook: gate the written file, exit 2 on failure
|
|
93
|
+
--stop hook: refuse to end the turn while a change fails
|
|
94
|
+
--pre-commit git: refuse the commit, exit 1 on failure
|
|
95
|
+
--ci [roots…] pipeline / human: one run, exit 1 on failure
|
|
96
|
+
--print-rules the digest, for a doc or a human
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Every mode exits `0` on a repo with no schema files, no git, or no compiler, and
|
|
100
|
+
says why. The blocking split is the CLI's own: errors always block, and so do the
|
|
101
|
+
authoring-rule warnings (`W607`, `W609`-`W613`, `W615`-`W617`).
|
|
102
|
+
|
|
103
|
+
## The rules themselves live in one file
|
|
104
|
+
|
|
105
|
+
`scripts/house-rules.mjs` exports `HOUSE_RULES_DIGEST`. The server instructions,
|
|
106
|
+
the guard's hook output, the failure report and this skill all quote it, and
|
|
107
|
+
`test/entityCodeHouseRules.test.ts` fails the build if a copy drifts. That test
|
|
108
|
+
exists because the rules were once written out by hand in five places, adding
|
|
109
|
+
one rule updated three of them, and the tool description went on telling agents
|
|
110
|
+
there were four.
|