@simetrajs/designer 0.1.0 → 0.2.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 -4
- package/dist/{command-CRUaUglx.js → command-BCAw6Fsb.js} +81 -17
- package/dist/default-dir-DerxTbci.js +158 -0
- package/dist/{errors-D5pJLrjP.js → errors-Brw6UjAD.js} +1 -2
- package/dist/init-jr0Xsrpp.js +832 -0
- package/dist/main.js +6 -6
- package/dist/{mcp-CJDCleh-.js → mcp-ChltmHBb.js} +108 -72
- package/dist/mcp-args-D63akJ97.js +56 -0
- package/dist/package-Dg3MXPve.js +4 -0
- package/dist/{report-D2jBS_04.js → report-DV4deFdu.js} +733 -224
- package/dist/{schema-engine-DAsJEc8K.js → schema-engine-DPPnife2.js} +82 -78
- package/dist/{types-CSc8XWLd.js → types-iWavtmdS.js} +6 -3
- package/package.json +12 -11
- package/skills/simetra-adoption/SKILL.md +15 -1
- package/skills/simetra-metadata/SKILL.md +71 -68
- package/skills/simetra-metadata/references/agents-over-mcp.md +119 -0
- package/skills/simetra-metadata/references/object-modules.md +60 -0
- package/skills/simetra-metadata/references/people-and-rights.md +609 -8
- package/skills/simetra-metadata/references/project-setup.md +28 -0
- package/skills/simetra-metadata/references/sql-trust-boundary.md +194 -0
- package/dist/package-DDuGk6yE.js +0 -5
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Project setup
|
|
2
|
+
|
|
3
|
+
`simetra init` connects a project to the installed tools: it links the
|
|
4
|
+
package skills into `.agents/skills/` and `.claude/skills/` and writes the MCP
|
|
5
|
+
server entry for the chosen agents. Run it from the project root — the
|
|
6
|
+
directory the agent starts in, where `metadata/` lives.
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
pnpm exec simetra init
|
|
10
|
+
pnpm exec simetra init --agents claude,codex,cursor,vscode
|
|
11
|
+
pnpm exec simetra init --dry-run
|
|
12
|
+
pnpm exec simetra init --check --agents claude,codex
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
- Without `--agents` only Claude Code's `.mcp.json` is written. The skill
|
|
16
|
+
links are made in both skill directories for every agent.
|
|
17
|
+
- The links and configs belong in git. In CI run `init --check` with the same
|
|
18
|
+
`--agents`: it exits 1 when a link or an MCP entry is missing or stale, and
|
|
19
|
+
changes nothing.
|
|
20
|
+
- `init` never overwrites what it does not own: a skill directory with the
|
|
21
|
+
same name, or a `simetra` MCP entry with another command, is left alone and
|
|
22
|
+
reported as a note. Arguments you add to its own entry — `--read-only`, a
|
|
23
|
+
metadata directory — are kept.
|
|
24
|
+
- A config `init` cannot read safely (JSON with comments, an ambiguous TOML
|
|
25
|
+
table) stops the whole run with exit 2; nothing is written.
|
|
26
|
+
- After `pnpm up @simetrajs/designer` the links show the new skill content by
|
|
27
|
+
themselves. A new skill or a moved binary is reported by `init --check`;
|
|
28
|
+
run `init` again.
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
# SQL trust boundary
|
|
2
|
+
|
|
3
|
+
What application SQL may do around the tables of a kind, and how to fix each
|
|
4
|
+
refusal; the router is `SKILL.md`. Every diagnostic below carries a hint with
|
|
5
|
+
the exact allowlist: read it, do not reword the statement until it passes.
|
|
6
|
+
|
|
7
|
+
Contents:
|
|
8
|
+
|
|
9
|
+
- Policies and triggers on a table of a kind
|
|
10
|
+
- Writes to a table of a kind
|
|
11
|
+
- Function bodies
|
|
12
|
+
- Code that runs inside a command
|
|
13
|
+
- Reading `sql.head-not-allowed`
|
|
14
|
+
- Session settings
|
|
15
|
+
- Other paths into a command
|
|
16
|
+
- Before a promotion
|
|
17
|
+
|
|
18
|
+
## Policies and triggers on a table of a kind
|
|
19
|
+
|
|
20
|
+
Only the platform attaches policies and triggers to a table of a kind (and to
|
|
21
|
+
its tabular sections), in any `.sql` file, shared `sql/` folder included.
|
|
22
|
+
A verbatim `CREATE POLICY` or `CREATE TRIGGER` there is the error
|
|
23
|
+
`sql.kind-table-verbatim`, and the unit can never be listed in
|
|
24
|
+
`sql-debt.json`. A hand-written policy would open rows past the rights, a
|
|
25
|
+
hand-written trigger would act inside every command. Use what replaces them:
|
|
26
|
+
|
|
27
|
+
- a policy → a right: a role's `grant` (with an extent), `ownership`,
|
|
28
|
+
`access` or `publicRead` on the object;
|
|
29
|
+
- a trigger → an `EventSubscription` with a handler that only checks (below).
|
|
30
|
+
|
|
31
|
+
The same statement on a `CustomTable` is ordinary SQL debt until the table is
|
|
32
|
+
promoted into a kind.
|
|
33
|
+
|
|
34
|
+
## Writes to a table of a kind
|
|
35
|
+
|
|
36
|
+
Only commands write a table of a kind: write a change of its rows as a
|
|
37
|
+
command of the object or its TypeScript hook. No application SQL, in any
|
|
38
|
+
file and in debt too, writes one: an `INSERT`, `UPDATE`, `DELETE` or `MERGE`
|
|
39
|
+
in a function or procedure body whose target is a table of a kind, a tabular
|
|
40
|
+
section, a view of the model over one, or the provider's account table
|
|
41
|
+
(`auth.users`) is `sql.kind-table-verbatim` with the form `functionBody`, also
|
|
42
|
+
inside a literal `EXECUTE`, a `DO` block or a function the body creates.
|
|
43
|
+
Reading the table (`SELECT`, `FOR UPDATE`, `UPDATE … FROM`, `MERGE … USING`)
|
|
44
|
+
and `LOCK` are fine. An unqualified table name counts in every schema,
|
|
45
|
+
because the body may run with any `search_path`: qualify the names of your
|
|
46
|
+
own tables. Such a function is never debt.
|
|
47
|
+
|
|
48
|
+
## Function bodies
|
|
49
|
+
|
|
50
|
+
The body of any function or procedure, in any file and in debt too, runs only
|
|
51
|
+
the statements the hint of `sql.function-body-statement` lists; the field
|
|
52
|
+
`statement` names the one refused. A body never changes the schema: move DDL
|
|
53
|
+
into metadata or a migration.
|
|
54
|
+
|
|
55
|
+
- `nonLiteralExecute`, `dynamicText` (a call of a builtin or provider
|
|
56
|
+
function that executes SQL text, such as `query_to_xml` or `dblink`) and
|
|
57
|
+
`language` (a language other than `sql` and `plpgsql`) cannot be judged:
|
|
58
|
+
rewrite the function with static SQL or remove it. Partition maintenance or
|
|
59
|
+
statistics through `EXECUTE format(…)` is refused on adoption for the same
|
|
60
|
+
reason.
|
|
61
|
+
- `unread`: the compiler could not read part of the body; simplify it.
|
|
62
|
+
- A temporary table of the body is `CREATE TEMP TABLE … ON COMMIT DROP`, and
|
|
63
|
+
every later reference to it (`DROP`, DML, a read) is `pg_temp.<name>`: an
|
|
64
|
+
unqualified name could hit a table of the same name in your schema.
|
|
65
|
+
|
|
66
|
+
Application SQL anywhere (a body, a view, a policy, a domain `CHECK`, a
|
|
67
|
+
default) calls only the platform and generated functions that read, such as
|
|
68
|
+
`simetra.current_user_id()`; calling another one is
|
|
69
|
+
`sql.platform-function-call`. Run the write through a command instead.
|
|
70
|
+
|
|
71
|
+
Expressions — a view, the `USING` and `WITH CHECK` of a policy, and the
|
|
72
|
+
defaults, generated columns, checks and index expressions of an adopted
|
|
73
|
+
table — call only allowlisted builtins, functions of the model by
|
|
74
|
+
`schema.name` and the listed provider functions, in any file and in debt too
|
|
75
|
+
(`sql.expression-call-not-allowed`): `set_config` and functions that execute
|
|
76
|
+
SQL text are refused there. A column default may also call
|
|
77
|
+
`nextval('<schema>.<sequence>')` of a sequence declared in the model.
|
|
78
|
+
|
|
79
|
+
The shell of every judged function (volatility, `SECURITY`, `search_path`,
|
|
80
|
+
`SET` options) is read from its `CREATE FUNCTION`. A separate
|
|
81
|
+
`ALTER FUNCTION` that changes it is refused
|
|
82
|
+
(`sql.function-settings-shell`, `RESET ALL` included): move the option into
|
|
83
|
+
`CREATE FUNCTION` and remove the `ALTER FUNCTION` statement.
|
|
84
|
+
|
|
85
|
+
## Code that runs inside a command
|
|
86
|
+
|
|
87
|
+
Kind module functions, subscription handlers, scope set functions, access
|
|
88
|
+
dimension value functions and movement query blocks run in the middle of a
|
|
89
|
+
command or a policy. The compiler judges them, and every function of the
|
|
90
|
+
model they call, by an allowlist (`sql.head-not-allowed`):
|
|
91
|
+
|
|
92
|
+
- **A handler only checks.** It reads with `SELECT … INTO`, assigns fields of
|
|
93
|
+
`NEW`, raises errors and returns `NEW` or `NULL`. It writes no table and runs
|
|
94
|
+
no `EXECUTE`, `CALL`, `SET` or cursor. A `beforeWrite` handler on a provider
|
|
95
|
+
table (`auth.users`) does not assign `NEW` either. A write the handler did
|
|
96
|
+
belongs to a command or a TypeScript hook.
|
|
97
|
+
- **Everything else is a query function.** `LANGUAGE sql`, a string body of
|
|
98
|
+
exactly one `SELECT` (no `INTO`, no `FOR UPDATE`, no data-modifying `WITH`),
|
|
99
|
+
`SET search_path = ''` and no other `SET` option. It reads only qualified
|
|
100
|
+
tables of kinds, adopted tables and views of the model, and calls only query
|
|
101
|
+
functions of the model, generated functions that read,
|
|
102
|
+
`simetra.current_user_id()`, the listed provider functions and allowlisted
|
|
103
|
+
builtins. A function of a kind module that is not of this form belongs in
|
|
104
|
+
a shared `sql/` file, called by nothing inside a command.
|
|
105
|
+
|
|
106
|
+
## Reading `sql.head-not-allowed`
|
|
107
|
+
|
|
108
|
+
The diagnostic names the head, the chain from the head to the construct, and
|
|
109
|
+
`construct` (with `detail`: the statement kind, function or relation):
|
|
110
|
+
|
|
111
|
+
| `construct` | Fix |
|
|
112
|
+
| --- | --- |
|
|
113
|
+
| `call` | Schema-qualify the call, or replace it with an allowlisted builtin, a query function or a reading function of the platform |
|
|
114
|
+
| `unqualified` | Qualify the name: `pg_catalog.<name>` for a builtin in a view or a policy, `<schema>.<name>` for your own relation or function |
|
|
115
|
+
| `relation` | Read a table of a kind, an adopted table or a view of the model instead |
|
|
116
|
+
| `statement` | Move the write, `EXECUTE`, `CALL` or `SET` into a command or a TypeScript hook |
|
|
117
|
+
| `query` | Make the body one plain `SELECT` |
|
|
118
|
+
| `language`, `searchPath`, `setting`, `sqlBody` | Fix the shell: `LANGUAGE sql`, `SET search_path = ''`, no other `SET` option, an `AS $$ … $$` body |
|
|
119
|
+
| `operator` | Use an operator of `pg_catalog` |
|
|
120
|
+
| `unread` | Simplify the part the compiler could not read |
|
|
121
|
+
|
|
122
|
+
## Session settings
|
|
123
|
+
|
|
124
|
+
- Any application SQL unit (subscription handlers wherever they live,
|
|
125
|
+
object-module functions, and every statement of shared `sql/` files:
|
|
126
|
+
functions, `ALTER FUNCTION`, views, domains, aggregates, policies) must not
|
|
127
|
+
change the platform's session settings — `simetra.*`, the request claims
|
|
128
|
+
(`request.jwt.*`), `session_replication_role` and the role (`SET ROLE`,
|
|
129
|
+
`SET SESSION AUTHORIZATION` and their `RESET`) — in any form (`set_config`
|
|
130
|
+
however it is qualified, `SET`/`RESET`, a function option, a write to
|
|
131
|
+
`pg_settings` or a view over it, a literal `EXECUTE`): compiler error
|
|
132
|
+
`sql.command-context-write`. The command context, the user and the role
|
|
133
|
+
belong to the platform.
|
|
134
|
+
- In a debt unit — a statement of the `.sql` file of a `CustomTable` or a
|
|
135
|
+
`PgEnum`, or of a shared `sql/` file, that is listed in `sql-debt.json`
|
|
136
|
+
(a function in the closed shell, a subscription handler and a scope set
|
|
137
|
+
function are never debt) — the rule is split by setting. A write to
|
|
138
|
+
`simetra.*` or `session_replication_role`, `RESET ALL` and a write to
|
|
139
|
+
`pg_settings` stay errors (`sql.command-context-write`, marked
|
|
140
|
+
`unit: debt`). A write to the role or the request claims is a warning
|
|
141
|
+
(`sql.debt-session-write`): it may stay while the unit is debt, because
|
|
142
|
+
code inside a command calls only query functions, which have no such write.
|
|
143
|
+
Converting the unit into a closed-shell function turns that warning into
|
|
144
|
+
the error above, so remove the named statement when you convert the unit;
|
|
145
|
+
write a `set_config` name as a literal, because a name built at run time
|
|
146
|
+
counts as a write.
|
|
147
|
+
|
|
148
|
+
## Other paths into a command
|
|
149
|
+
|
|
150
|
+
Postgres also runs SQL implicitly in the middle of a command. Each such path
|
|
151
|
+
is closed by its own rule:
|
|
152
|
+
|
|
153
|
+
- **Domain `CHECK`** — follows the rules of a query function: allowlisted
|
|
154
|
+
builtins as `pg_catalog.<name>`, query functions of the model
|
|
155
|
+
(`sql.domain-check-not-allowed`).
|
|
156
|
+
- **Foreign key from a `CustomTable` to a table of a kind** — `onDelete` and
|
|
157
|
+
`onUpdate` are only `restrict` or `noAction`
|
|
158
|
+
(`customTable.fk-action-on-kind-table`): a cascade would write the child
|
|
159
|
+
table from inside a command. Clean up the child rows in a TypeScript hook of
|
|
160
|
+
the command, or promote the child table. The target names the key, not
|
|
161
|
+
columns: `references: { object, key: "ref" }` (one local column) or
|
|
162
|
+
`key: "scopedRef"` — the in-tenant composite key (scope column, key) of a
|
|
163
|
+
scoped object that is not the scope root (two local columns: scope, then
|
|
164
|
+
key). `scopedRef` guarantees that the target lies in the tenant named by the
|
|
165
|
+
local scope column; that this column is the row's own tenant is up to the
|
|
166
|
+
write policy of the `CustomTable`. `columns` on a table of a kind, or `key` on a `CustomTable` target,
|
|
167
|
+
is `customTable.fk-target-not-key`. A foreign key check bypasses row
|
|
168
|
+
level security, so a key on a guessable value (a code, a number) would
|
|
169
|
+
reveal whether a row exists in another tenant; and the command role updates
|
|
170
|
+
unique attributes, while the key never changes.
|
|
171
|
+
- **Scope root** — `onRootDelete: "cascade"` only when the root is an object
|
|
172
|
+
of a kind (`scope.root-cascade-not-kind`): a `CustomTable` root is deleted by
|
|
173
|
+
your SQL, and its cascade would write tables of kinds. Promote the root, or
|
|
174
|
+
delete tenants through a command.
|
|
175
|
+
- **Extensions** — `CREATE EXTENSION … SCHEMA extensions` (a schema of the
|
|
176
|
+
provider); without `SCHEMA` or with another schema it is the warning
|
|
177
|
+
`sql.debt-extension-schema`. Until you fix it, code inside a command calls
|
|
178
|
+
no function of the model in that schema, and none at all while an
|
|
179
|
+
extension has no `SCHEMA`.
|
|
180
|
+
|
|
181
|
+
## Before a promotion
|
|
182
|
+
|
|
183
|
+
- A debt unit that writes a table being promoted is refused before any change
|
|
184
|
+
(`promote.debt-writes-table`, every unit listed): rewrite the unit without
|
|
185
|
+
the write, or delete it, then promote.
|
|
186
|
+
- A closed-shell function of the adopted table moves to the kind's module
|
|
187
|
+
only when it is a query function; the others move to
|
|
188
|
+
`sql/<schema>/<function>.sql`.
|
|
189
|
+
- An incoming foreign key with `cascade`, `setNull` or `setDefault` from a
|
|
190
|
+
table that stays a `CustomTable` is set to `restrict` by the promotion
|
|
191
|
+
itself (warning `promote.cascade-to-restrict`, one per key and event). The
|
|
192
|
+
plan needs the permission `delete:<table>.<constraint>` for `ON DELETE` and
|
|
193
|
+
`update:<table>.<constraint>` for `ON UPDATE`: after it, deleting the
|
|
194
|
+
promoted row with child rows, or changing its key, is refused.
|