@simetrajs/designer 0.0.0-stage → 0.1.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/LICENSE +190 -0
- package/README.md +44 -2
- package/dist/command-CRUaUglx.js +730 -0
- package/dist/errors-D5pJLrjP.js +36 -0
- package/dist/main.js +29 -0
- package/dist/mcp-CJDCleh-.js +241 -0
- package/dist/package-DDuGk6yE.js +5 -0
- package/dist/report-D2jBS_04.js +1550 -0
- package/dist/schema-engine-DAsJEc8K.js +2805 -0
- package/dist/types-CSc8XWLd.js +28 -0
- package/package.json +66 -3
- package/skills/simetra-adoption/SKILL.md +171 -0
- package/skills/simetra-metadata/SKILL.md +491 -0
- package/skills/simetra-metadata/references/people-and-rights.md +156 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
//#region src/tools/types.ts
|
|
3
|
+
/** Імена окремо від записів каталогу: `main.ts` реєструє лінощі підкоманди, не тягнучи компілятор. */
|
|
4
|
+
const TOOL_NAMES = [
|
|
5
|
+
"compile",
|
|
6
|
+
"explain",
|
|
7
|
+
"fix",
|
|
8
|
+
"create",
|
|
9
|
+
"add",
|
|
10
|
+
"rename",
|
|
11
|
+
"delete",
|
|
12
|
+
"promote",
|
|
13
|
+
"introspect",
|
|
14
|
+
"diff",
|
|
15
|
+
"plan",
|
|
16
|
+
"apply"
|
|
17
|
+
];
|
|
18
|
+
/**
|
|
19
|
+
* Каталог артефактів плану в корені проєкту, поруч із текою метаданих:
|
|
20
|
+
* єдиний виняток із межі теки для запису (спека designer §3.2).
|
|
21
|
+
*/
|
|
22
|
+
const PLANS_DIR = "plans";
|
|
23
|
+
/** Виводить типи входу й даних з аргументів, щоб записи не писали generics. */
|
|
24
|
+
function defineTool(tool) {
|
|
25
|
+
return tool;
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
export { TOOL_NAMES as n, defineTool as r, PLANS_DIR as t };
|
package/package.json
CHANGED
|
@@ -1,6 +1,69 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simetrajs/designer",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Simetra developer tools: command line and MCP server over the metadata compiler",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"simetra",
|
|
7
|
+
"metadata",
|
|
8
|
+
"postgres",
|
|
9
|
+
"cli",
|
|
10
|
+
"mcp",
|
|
11
|
+
"schema"
|
|
12
|
+
],
|
|
13
|
+
"homepage": "https://github.com/VSydorenko/Simetra#readme",
|
|
14
|
+
"bugs": "https://github.com/VSydorenko/Simetra/issues",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/VSydorenko/Simetra.git",
|
|
18
|
+
"directory": "packages/designer"
|
|
19
|
+
},
|
|
20
|
+
"license": "Apache-2.0",
|
|
21
|
+
"type": "module",
|
|
22
|
+
"engines": {
|
|
23
|
+
"node": ">=24"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist",
|
|
27
|
+
"skills"
|
|
28
|
+
],
|
|
29
|
+
"bin": {
|
|
30
|
+
"simetra": "./dist/main.js"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@modelcontextprotocol/server": "2.2.0",
|
|
34
|
+
"@supabase/pg-delta": "1.0.0-alpha.56",
|
|
35
|
+
"citty": "0.2.2",
|
|
36
|
+
"pg": "8.23.1",
|
|
37
|
+
"zod": "4.6.5",
|
|
38
|
+
"simetra": "0.1.0"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@arethetypeswrong/cli": "0.18.5",
|
|
42
|
+
"@eslint/js": "^10.0.1",
|
|
43
|
+
"@modelcontextprotocol/client": "2.2.0",
|
|
44
|
+
"@types/node": "^24.13.6",
|
|
45
|
+
"@types/pg": "^8.23.1",
|
|
46
|
+
"@typescript/native": "npm:typescript@^7.0.2",
|
|
47
|
+
"eslint": "^10.11.0",
|
|
48
|
+
"publint": "0.3.25",
|
|
49
|
+
"tsdown": "0.23.1",
|
|
50
|
+
"tsx": "4.23.15",
|
|
51
|
+
"typescript": "npm:@typescript/typescript6@^6.0.2",
|
|
52
|
+
"typescript-eslint": "^8.70.1",
|
|
53
|
+
"vitest": "^5.0.2"
|
|
54
|
+
},
|
|
55
|
+
"publishConfig": {
|
|
56
|
+
"access": "public"
|
|
57
|
+
},
|
|
58
|
+
"scripts": {
|
|
59
|
+
"build": "tsc --noEmit",
|
|
60
|
+
"build:package": "tsdown",
|
|
61
|
+
"lint": "eslint",
|
|
62
|
+
"format": "prettier --write \"**/*.{ts,tsx}\"",
|
|
63
|
+
"typecheck": "tsc --noEmit",
|
|
64
|
+
"test": "vitest run --project unit",
|
|
65
|
+
"test:watch": "vitest --project unit",
|
|
66
|
+
"test:db": "vitest run --project db",
|
|
67
|
+
"test:packaging": "vitest run --project packaging"
|
|
68
|
+
}
|
|
6
69
|
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: simetra-adoption
|
|
3
|
+
description: Use when bringing an existing live PostgreSQL database under Simetra metadata for the first time — reading its schemas into a `metadata/` directory with `simetra introspect`, then proving with `simetra diff` that the metadata and the database match. Covers choosing the scope (`--schemas`, `--tables`), the connection and shadow database settings, exit codes, and how to treat unrepresentable objects and non-empty results. Not for everyday editing of metadata (that is `simetra-metadata`).
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Simetra adoption — introspect a live database, then diff
|
|
7
|
+
|
|
8
|
+
Adoption is a one-time onboarding: the database already exists, and the
|
|
9
|
+
metadata is derived from it. `introspect` reads the database into metadata;
|
|
10
|
+
`diff` compares the database with the metadata through a throwaway shadow
|
|
11
|
+
database. Neither ever writes to the database. Run the CLI from the project root
|
|
12
|
+
as `pnpm exec simetra …`; every command defaults to `./metadata`. The same tools
|
|
13
|
+
are served by `simetra mcp` with the same input.
|
|
14
|
+
|
|
15
|
+
## The connection
|
|
16
|
+
|
|
17
|
+
- The connection string comes **only from the environment**: the variable
|
|
18
|
+
`SIMETRA_DATABASE_URL`, or another one named with
|
|
19
|
+
`--database-url-env <NAME>` (CLI and `simetra mcp`). Export it in the shell
|
|
20
|
+
or the server's environment; never paste a connection string into a command,
|
|
21
|
+
a file or a tool input. Output shows only `host:port/db`.
|
|
22
|
+
- Without the variable the call is refused with its name (exit 2).
|
|
23
|
+
- The target is only read, in short read-only transactions that leave no
|
|
24
|
+
session state behind.
|
|
25
|
+
- `diff` builds the shadow database on the target's server by default, so the
|
|
26
|
+
connecting role needs `CREATEDB`. Otherwise name a variable with
|
|
27
|
+
`--shadow-url-env <NAME>` pointing at another server of the **same
|
|
28
|
+
PostgreSQL major version**; a different major version is refused.
|
|
29
|
+
- Roles are cluster infrastructure: they are not described in metadata, and
|
|
30
|
+
grants to them are. A role the database grants to is assumed to exist; a
|
|
31
|
+
shadow on another server must have the same roles, or the metadata does not
|
|
32
|
+
load there.
|
|
33
|
+
|
|
34
|
+
## Steps
|
|
35
|
+
|
|
36
|
+
1. **Choose the scope.** A directory without `project.meta.json` needs
|
|
37
|
+
`--schemas` (MCP: `schemas`); the first schema becomes the project's default
|
|
38
|
+
schema. In an existing project the scope is the schemas of its metadata plus
|
|
39
|
+
any named with `--schemas`. Provider schemas (`auth`, `storage`, …) are not
|
|
40
|
+
introspected, and naming the platform's own schema `simetra` is refused. The project file is never rewritten: a `--project-name` or
|
|
41
|
+
`--attribute-case` that differs from it is an error, not a silent override.
|
|
42
|
+
A new project records its database provider explicitly (MCP:
|
|
43
|
+
`project.database.provider`, CLI: `--database-provider`; the default is
|
|
44
|
+
`supabase`); an existing project keeps the one in its file.
|
|
45
|
+
2. **Preview.** Run `introspect` with `--dry-run` (MCP: `dryRun: true`) and read
|
|
46
|
+
the diagnostics.
|
|
47
|
+
3. **Unrepresentable objects are reported, not worked around.** When anything
|
|
48
|
+
cannot be represented (an `EXCLUDE` constraint, an owner other than the
|
|
49
|
+
session role, …), `introspect` writes nothing and the diagnostics name the
|
|
50
|
+
object. Do not edit the database or the generated files to get past it;
|
|
51
|
+
report the object to the owner.
|
|
52
|
+
4. **Introspect.** Run it without `--dry-run`. Tables become `CustomTable`,
|
|
53
|
+
enum types `PgEnum`, everything else verbatim `.sql` files; ids of objects
|
|
54
|
+
already described are kept, so a second run on an unchanged database
|
|
55
|
+
changes nothing.
|
|
56
|
+
The platform's row mechanics (`simetra.touch()`, its grants and the
|
|
57
|
+
`<table>_simetra_touch` triggers calling it) are never written, even into
|
|
58
|
+
a directory without metadata: the platform generates them. Another trigger
|
|
59
|
+
that calls `simetra.touch()` is the table's own and is written.
|
|
60
|
+
5. **Diff.** Run `diff` on the same directory. **An empty diff right after
|
|
61
|
+
introspect is the baseline; any non-empty result is a finding** — report it
|
|
62
|
+
instead of editing the metadata until it disappears.
|
|
63
|
+
The one expected exception: adopting from scratch a database that
|
|
64
|
+
Simetra deployed shows the removal of each `<table>_simetra_touch`
|
|
65
|
+
trigger, a step that needs a permission, because a kind table comes back
|
|
66
|
+
as a `CustomTable` without the row mechanics (the adoption row of the
|
|
67
|
+
system schema and users spec in the Simetra repository,
|
|
68
|
+
`docs/superpowers/specs/2026-10-07-system-schema-users-design.md`).
|
|
69
|
+
6. **Narrow when reconciling part of the schema.** `--tables` (MCP: `tables`)
|
|
70
|
+
narrows the plan, the differences and the diagnostics to the named tables
|
|
71
|
+
(`schema.table` or `table`) together with their enum types and sequences;
|
|
72
|
+
an unknown table is refused. A diagnostic that cannot be tied to a table
|
|
73
|
+
(one about the whole schema, a function, a view) stays, so a narrowed run
|
|
74
|
+
can still exit 1 because of an object outside the tables: judge the plan
|
|
75
|
+
and the differences, not the exit code alone.
|
|
76
|
+
|
|
77
|
+
## Examples
|
|
78
|
+
|
|
79
|
+
A new project from the `app` schema:
|
|
80
|
+
|
|
81
|
+
```json simetra:introspect
|
|
82
|
+
{
|
|
83
|
+
"schemas": ["app"],
|
|
84
|
+
"project": { "name": "Shop", "attributeCase": "snake_case" }
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Compare two tables of it:
|
|
89
|
+
|
|
90
|
+
```json simetra:diff
|
|
91
|
+
{ "tables": ["app.orders", "app.order_lines"] }
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
The same from a shell:
|
|
95
|
+
|
|
96
|
+
```sh
|
|
97
|
+
pnpm exec simetra introspect --schemas app --project-name Shop --dry-run
|
|
98
|
+
pnpm exec simetra introspect --schemas app --project-name Shop
|
|
99
|
+
pnpm exec simetra diff
|
|
100
|
+
pnpm exec simetra diff --tables app.orders,app.order_lines --format json
|
|
101
|
+
pnpm exec simetra diff --database-url-env STAGING_DATABASE_URL --shadow-url-env SHADOW_DATABASE_URL
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## SQL debt
|
|
105
|
+
|
|
106
|
+
`introspect` also writes `metadata/sql-debt.json`: the verbatim SQL it could
|
|
107
|
+
not express through metadata (CustomTable and PgEnum modules, shared
|
|
108
|
+
`metadata/sql/`, statements a closed form does not accept).
|
|
109
|
+
|
|
110
|
+
- The list is a ratchet and only shrinks. `introspect` is the only writer and
|
|
111
|
+
derives it from the database; `fix` only removes stale entries; `compile`
|
|
112
|
+
fails with `sql.debt-grows` on a debt unit that is not listed and with
|
|
113
|
+
`sql.debt-stale` on an entry that is no longer debt. Without that, verbatim
|
|
114
|
+
SQL would grow back unnoticed.
|
|
115
|
+
- Never edit the list by hand to get a green compile. Replace the statement
|
|
116
|
+
with a property, an `EventSubscription` or a closed-shell function (see
|
|
117
|
+
`simetra-metadata`), then run `fix`: it removes the entry that became stale.
|
|
118
|
+
- A project that already has a `sql/` folder but no list is seeded by running
|
|
119
|
+
`introspect` again on the same directory.
|
|
120
|
+
|
|
121
|
+
## Adopted triggers
|
|
122
|
+
|
|
123
|
+
An adopted trigger stays verbatim debt while its table is a `CustomTable`.
|
|
124
|
+
When `promote` turns the table into a kind, a trigger gets the
|
|
125
|
+
class `platform` only when the kind replaces it, and `plan` refuses
|
|
126
|
+
(`plan.platform-replacement-missing`) otherwise:
|
|
127
|
+
|
|
128
|
+
- `moddatetime` fired `BEFORE UPDATE … FOR EACH ROW` on the column that becomes
|
|
129
|
+
`updatedAt` → the row mechanics (`<table>_simetra_touch`). The mechanics also
|
|
130
|
+
fires on insert, which only makes the date and the version right there too.
|
|
131
|
+
- A trigger calling the same handler with the same timing, level and events →
|
|
132
|
+
an `EventSubscription` with that handler (see `simetra-metadata`).
|
|
133
|
+
- `INSERT OR UPDATE OF <columns>` → a subscription with `whenChanged` on the
|
|
134
|
+
same columns. The plan warns (`plan.update-of-narrowed`): the subscription
|
|
135
|
+
fires only when a value actually changes, not on every `UPDATE` that sets
|
|
136
|
+
the column.
|
|
137
|
+
- A trigger on `UPDATE` alone has no replacement: a write subscription fires
|
|
138
|
+
on insert too. Give it the class `removed` (the plan then needs the
|
|
139
|
+
`remove:` permission) and let the subscription's handler check `TG_OP`.
|
|
140
|
+
- A numbering trigger or default has no replacement until the platform
|
|
141
|
+
generates counters: keep the table a `CustomTable`, or remove it with the
|
|
142
|
+
permission and accept that the number is no longer filled.
|
|
143
|
+
- Anything else — another `WHEN`, other events, trigger arguments, another
|
|
144
|
+
function — has no replacement either.
|
|
145
|
+
- A foreign trigger on a provider table (`auth.users`) that holds the name of
|
|
146
|
+
a generated one → `plan` refuses with `plan.provider-trigger-taken`, or with
|
|
147
|
+
`engine.shadow-load-failed` "trigger … already exists" when the trigger's
|
|
148
|
+
function lives in the provider schema. Rename or drop the existing trigger;
|
|
149
|
+
for a subscription, another `physicalName` also works. Introspecting the
|
|
150
|
+
trigger does not help: it becomes a debt unit, and a subscription with the
|
|
151
|
+
same name is then a duplicate (`sql.unit-duplicate`).
|
|
152
|
+
|
|
153
|
+
## Exit codes
|
|
154
|
+
|
|
155
|
+
| Code | `introspect` | `diff` |
|
|
156
|
+
| ---- | ------------------------------------- | --------------------------------- |
|
|
157
|
+
| `0` | written (or previewed) without errors | the database matches the metadata |
|
|
158
|
+
| `1` | error diagnostics, nothing written | differences or error diagnostics |
|
|
159
|
+
| `2` | the call was refused | the call was refused |
|
|
160
|
+
|
|
161
|
+
- Refused (exit 2; MCP `isError` without diagnostics): no connection variable,
|
|
162
|
+
an unreachable database, a failed login, a missing database or privilege, a
|
|
163
|
+
bad flag or input. Fix the connection or the call and rerun.
|
|
164
|
+
- A failure during the database work itself is the diagnostic
|
|
165
|
+
`database.failed` with its SQLSTATE (exit 1; MCP `isError`). The driver's
|
|
166
|
+
text is withheld because it may carry credentials.
|
|
167
|
+
- `--format json` (MCP `structuredContent`) carries the plan, the differences
|
|
168
|
+
and the diagnostics as data.
|
|
169
|
+
- `diff` also reports `applyState`: `absent` while the database holds none of
|
|
170
|
+
the platform's apply state (the first `apply` creates it, so it is not a
|
|
171
|
+
difference), `present` otherwise.
|