@simetrajs/designer 0.3.0-next.1 → 0.3.0-next.10
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/dist/{command-CHk1P9Dp.js → command-BUIz4QxS.js} +13 -2
- package/dist/{init-jr0Xsrpp.js → init-BS7fCOls.js} +44 -18
- package/dist/{invoke-BwP_5iN6.js → invoke-B6ljdX5t.js} +166 -14
- package/dist/main.js +4 -4
- package/dist/{mcp-jLOz0W7f.js → mcp-CLc4ByOi.js} +6 -4
- package/dist/{package-hA0J8AMK.js → package-CJuyaMGH.js} +1 -1
- package/package.json +3 -2
- package/skills/simetra-metadata/SKILL.md +3 -0
- package/skills/simetra-metadata/references/agents-over-mcp.md +6 -3
- package/skills/simetra-metadata/references/people-and-rights.md +131 -4
- package/skills/simetra-metadata/references/project-setup.md +11 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { a as toolByName, c as writeChanges, d as parseDataLaunch, f as databaseResource, i as structureOf, l as checkEnvName, o as formatDiagnostics, r as presentation, s as isMetadataFile, t as invoke, u as dataResource } from "./invoke-
|
|
2
|
+
import { a as toolByName, c as writeChanges, d as parseDataLaunch, f as databaseResource, i as structureOf, l as checkEnvName, o as formatDiagnostics, r as presentation, s as isMetadataFile, t as invoke, u as dataResource } from "./invoke-B6ljdX5t.js";
|
|
3
3
|
import { i as DEFAULT_DATABASE_URL_ENV, n as trimSlash, p as UsageError, t as DEFAULT_DIR } from "./default-dir-DerxTbci.js";
|
|
4
4
|
import { defineCommand } from "citty";
|
|
5
5
|
import { mkdtemp, readdir, rm, stat } from "node:fs/promises";
|
|
@@ -290,10 +290,14 @@ async function cliInput(tool, args, stdin) {
|
|
|
290
290
|
input: args.tables === void 0 ? {} : { tables: list("tables", args.tables) },
|
|
291
291
|
dirs: [trimSlash(positional[0] ?? "./metadata")]
|
|
292
292
|
};
|
|
293
|
-
if (tool.name === "plan"
|
|
293
|
+
if (tool.name === "plan") return {
|
|
294
294
|
input: {},
|
|
295
295
|
dirs: [trimSlash(positional[0] ?? "./metadata")]
|
|
296
296
|
};
|
|
297
|
+
if (tool.name === "roles") return {
|
|
298
|
+
input: args["dev-passwords"] === true ? { devPasswords: true } : {},
|
|
299
|
+
dirs: [trimSlash(positional[0] ?? "./metadata")]
|
|
300
|
+
};
|
|
297
301
|
if (tool.name === "apply") {
|
|
298
302
|
const plan = positional[0];
|
|
299
303
|
if (plan === void 0) throw new UsageError("apply needs the plan file: simetra apply <plans/….plan.json> [dir] --plan-hash <hex> --yes.");
|
|
@@ -465,6 +469,7 @@ async function runTool(tool, argv, stdin = readStdin, cwd = process.cwd(), env =
|
|
|
465
469
|
channel: "cli",
|
|
466
470
|
database,
|
|
467
471
|
databaseEnv,
|
|
472
|
+
env,
|
|
468
473
|
...baseline === void 0 ? {} : { baseline }
|
|
469
474
|
});
|
|
470
475
|
if (result.refusal !== void 0) return fail(result.refusal.message);
|
|
@@ -604,6 +609,11 @@ function argsFor(tool) {
|
|
|
604
609
|
description: `statement_timeout of the apply transaction (default ${DEFAULT_APPLY_TIMEOUTS.statementTimeoutMs})`
|
|
605
610
|
};
|
|
606
611
|
}
|
|
612
|
+
if (tool.name === "roles") args["dev-passwords"] = {
|
|
613
|
+
type: "boolean",
|
|
614
|
+
default: false,
|
|
615
|
+
description: "Postgres provider, a database on this machine only: set the passwords of the login roles this run creates from SIMETRA_OWNER_DEV_PASSWORD, SIMETRA_AUTH_DEV_PASSWORD, SIMETRA_RUNTIME_DEV_PASSWORD and SIMETRA_SIGNALS_DEV_PASSWORD"
|
|
616
|
+
};
|
|
607
617
|
if (tool.database !== "none") {
|
|
608
618
|
args["database-url-env"] = {
|
|
609
619
|
type: "string",
|
|
@@ -680,6 +690,7 @@ function toCliArgs(args) {
|
|
|
680
690
|
"plan-hash": str(args["plan-hash"]),
|
|
681
691
|
allow: str(args.allow),
|
|
682
692
|
rehearse: args.rehearse === true,
|
|
693
|
+
"dev-passwords": args["dev-passwords"] === true,
|
|
683
694
|
"lock-timeout-ms": str(args["lock-timeout-ms"]),
|
|
684
695
|
"statement-timeout-ms": str(args["statement-timeout-ms"]),
|
|
685
696
|
"data-url-env": str(args["data-url-env"]),
|
|
@@ -3,7 +3,7 @@ import { d as installedPackageDir, f as posixRelative, p as UsageError, t as DEF
|
|
|
3
3
|
import { t as mcpArgs } from "./mcp-args-D63akJ97.js";
|
|
4
4
|
import { defineCommand, parseArgs } from "citty";
|
|
5
5
|
import { lstat, mkdir, readFile, readdir, readlink, realpath, rename, rm, stat, symlink, unlink, writeFile } from "node:fs/promises";
|
|
6
|
-
import { basename, dirname, join, posix, resolve, win32 } from "node:path";
|
|
6
|
+
import { basename, dirname, isAbsolute, join, posix, relative, resolve, win32 } from "node:path";
|
|
7
7
|
import { parse } from "smol-toml";
|
|
8
8
|
import { randomUUID } from "node:crypto";
|
|
9
9
|
// src/init/fs-probe.ts
|
|
@@ -60,6 +60,7 @@ const DEFAULT_AGENTS = ["claude"];
|
|
|
60
60
|
const MCP_SERVER_NAME = "simetra";
|
|
61
61
|
const WORKSPACE = "${workspaceFolder}";
|
|
62
62
|
const CURSOR_METADATA_DIR = `${WORKSPACE}/${DEFAULT_DIR.replace(/^\.\//, "")}`;
|
|
63
|
+
const argsOf = (l) => l.dir === void 0 ? l.args : [...l.args, l.dir];
|
|
63
64
|
const CLIENTS = {
|
|
64
65
|
claude: {
|
|
65
66
|
file: ".mcp.json",
|
|
@@ -67,7 +68,7 @@ const CLIENTS = {
|
|
|
67
68
|
container: "mcpServers",
|
|
68
69
|
entry: (l) => ({
|
|
69
70
|
command: l.command,
|
|
70
|
-
args: l
|
|
71
|
+
args: argsOf(l)
|
|
71
72
|
})
|
|
72
73
|
},
|
|
73
74
|
codex: {
|
|
@@ -76,20 +77,20 @@ const CLIENTS = {
|
|
|
76
77
|
container: "mcp_servers",
|
|
77
78
|
entry: (l) => ({
|
|
78
79
|
command: l.command,
|
|
79
|
-
args: l
|
|
80
|
+
args: argsOf(l)
|
|
80
81
|
})
|
|
81
82
|
},
|
|
82
83
|
cursor: {
|
|
83
84
|
file: ".cursor/mcp.json",
|
|
84
85
|
format: "json",
|
|
85
86
|
container: "mcpServers",
|
|
86
|
-
entry: ({ command, args: [bin, ...rest] }) => ({
|
|
87
|
+
entry: ({ command, args: [bin, ...rest], dir }) => ({
|
|
87
88
|
type: "stdio",
|
|
88
89
|
command,
|
|
89
90
|
args: [
|
|
90
91
|
`${WORKSPACE}/${bin}`,
|
|
91
92
|
...rest,
|
|
92
|
-
CURSOR_METADATA_DIR
|
|
93
|
+
dir === void 0 ? CURSOR_METADATA_DIR : `${WORKSPACE}/${dir}`
|
|
93
94
|
]
|
|
94
95
|
})
|
|
95
96
|
},
|
|
@@ -100,7 +101,7 @@ const CLIENTS = {
|
|
|
100
101
|
entry: (l) => ({
|
|
101
102
|
type: "stdio",
|
|
102
103
|
command: l.command,
|
|
103
|
-
args: l
|
|
104
|
+
args: argsOf(l),
|
|
104
105
|
cwd: WORKSPACE
|
|
105
106
|
})
|
|
106
107
|
}
|
|
@@ -616,14 +617,20 @@ async function classifyFile(path, expected) {
|
|
|
616
617
|
}
|
|
617
618
|
// src/init/plan.ts
|
|
618
619
|
/**
|
|
619
|
-
* Повний план `init`: лише читає диск. Пакет шукається вгору від
|
|
620
|
-
* самим механізмом, що й `$schema` (спека designer §4.2)
|
|
621
|
-
* `
|
|
620
|
+
* Повний план `init`: лише читає диск. Пакет шукається вгору від теки
|
|
621
|
+
* метаданих тим самим механізмом, що й `$schema` (спека designer §4.2): корінь
|
|
622
|
+
* агента може лежати над проєктом, чий `node_modules` до нього не видно. Його
|
|
623
|
+
* відсутність — `UsageError` з назвою пакета. Тека метаданих іде в запис MCP
|
|
624
|
+
* відносно кореня, коли вона не типова для нього.
|
|
622
625
|
*/
|
|
623
|
-
async function planInit(root, agents, platform) {
|
|
624
|
-
const pkgDir = installedPackageDir(
|
|
626
|
+
async function planInit(root, metadataDir, agents, platform) {
|
|
627
|
+
const pkgDir = installedPackageDir(metadataDir, DESIGNER_PACKAGE);
|
|
625
628
|
const skills = await planSkillLinks(root, pkgDir, platform);
|
|
626
|
-
const
|
|
629
|
+
const dir = posixRelative(root, metadataDir) || ".";
|
|
630
|
+
const configs = await planMcpConfigs(root, agents, {
|
|
631
|
+
...await mcpLaunch(root, pkgDir),
|
|
632
|
+
...dir === posixRelative(root, resolve(root, "./metadata")) ? {} : { dir }
|
|
633
|
+
}, platform);
|
|
627
634
|
return {
|
|
628
635
|
actions: [...skills.actions, ...configs.actions],
|
|
629
636
|
notes: [...skills.notes, ...configs.notes],
|
|
@@ -705,6 +712,15 @@ async function writeAtomic(path, content) {
|
|
|
705
712
|
}
|
|
706
713
|
// src/commands/init.ts
|
|
707
714
|
const initArgs = {
|
|
715
|
+
dir: {
|
|
716
|
+
type: "positional",
|
|
717
|
+
description: `Metadata directory (default: ${DEFAULT_DIR}); the package is looked up from it`,
|
|
718
|
+
required: false
|
|
719
|
+
},
|
|
720
|
+
root: {
|
|
721
|
+
type: "string",
|
|
722
|
+
description: "Directory the agent starts in, where the skill links and MCP configs are written (default: the current directory)"
|
|
723
|
+
},
|
|
708
724
|
agents: {
|
|
709
725
|
type: "string",
|
|
710
726
|
description: `Comma-separated agents to write MCP configs for: ${AGENTS.join(", ")} (default: ${DEFAULT_AGENTS.join(",")})`
|
|
@@ -720,6 +736,8 @@ const initArgs = {
|
|
|
720
736
|
};
|
|
721
737
|
const KNOWN_KEYS = /* @__PURE__ */ new Set([
|
|
722
738
|
"_",
|
|
739
|
+
"dir",
|
|
740
|
+
"root",
|
|
723
741
|
"agents",
|
|
724
742
|
"dry-run",
|
|
725
743
|
"dryRun",
|
|
@@ -745,11 +763,15 @@ var init_default = defineCommand({
|
|
|
745
763
|
* поганий аргумент, а не відсутній пакет.
|
|
746
764
|
*/
|
|
747
765
|
async function runInit(args, cwd, platform = process.platform) {
|
|
748
|
-
const
|
|
749
|
-
const rel = (path) => posixRelative(root, path);
|
|
766
|
+
const rel = (path) => posixRelative(resolve(cwd), path);
|
|
750
767
|
try {
|
|
751
|
-
const { agents, mode } = parseInitArgs(args);
|
|
752
|
-
const
|
|
768
|
+
const { agents, mode, dir, root: rootArg } = parseInitArgs(args);
|
|
769
|
+
const root = resolve(cwd, rootArg);
|
|
770
|
+
if (!await isDirectory(root)) throw new UsageError(`--root ${rootArg} is not a directory`);
|
|
771
|
+
if (dir !== void 0 && !await isDirectory(resolve(cwd, dir))) throw new UsageError(`metadata directory ${dir} is not a directory`);
|
|
772
|
+
const metadataDir = resolve(cwd, dir ?? "./metadata");
|
|
773
|
+
if (isAbsolute(relative(root, metadataDir))) throw new UsageError(`metadata directory ${dir ?? "./metadata"} is on another drive than the root ${rootArg}; keep them on one drive`);
|
|
774
|
+
const plan = await planInit(root, metadataDir, agents, platform);
|
|
753
775
|
if (plan.refusals.length > 0) return refused(plan, rel);
|
|
754
776
|
const lines = plan.actions.map(renderAction(rel));
|
|
755
777
|
const notes = plan.notes.map(renderNote(rel));
|
|
@@ -775,16 +797,20 @@ async function runInit(args, cwd, platform = process.platform) {
|
|
|
775
797
|
throw e;
|
|
776
798
|
}
|
|
777
799
|
}
|
|
800
|
+
const isDirectory = (path) => stat(path).then((s) => s.isDirectory(), () => false);
|
|
778
801
|
function parseInitArgs(args) {
|
|
779
802
|
for (const key of Object.keys(args)) if (!KNOWN_KEYS.has(key)) throw new UsageError(`unknown option --${key}`);
|
|
780
803
|
const positional = Array.isArray(args._) ? args._ : [];
|
|
781
|
-
if (positional.length >
|
|
804
|
+
if (positional.length > 1) throw new UsageError(`unexpected argument "${String(positional[1])}": init takes one metadata directory`);
|
|
805
|
+
if (args.root !== void 0 && typeof args.root !== "string") throw new UsageError("--root needs a directory");
|
|
782
806
|
const check = args.check === true;
|
|
783
807
|
const dryRun = args["dry-run"] === true;
|
|
784
808
|
if (check && dryRun) throw new UsageError("--check and --dry-run cannot be combined");
|
|
785
809
|
return {
|
|
786
810
|
agents: args.agents === void 0 ? DEFAULT_AGENTS : agentList(args.agents),
|
|
787
|
-
mode: check ? "check" : dryRun ? "dry-run" : "init"
|
|
811
|
+
mode: check ? "check" : dryRun ? "dry-run" : "init",
|
|
812
|
+
dir: positional.length === 0 ? void 0 : String(positional[0]),
|
|
813
|
+
root: args.root ?? "."
|
|
788
814
|
};
|
|
789
815
|
}
|
|
790
816
|
function agentList(value) {
|
|
@@ -4,7 +4,7 @@ import { a as dataWriteHint, c as noDatabaseHint, d as installedPackageDir, f as
|
|
|
4
4
|
import { a as ShadowTemplateMissingError, i as ShadowServerMismatchError, n as ShadowCreateRefusedError, o as shadowDropOf, r as ShadowServerError, t as ShadowBaseUnsupportedError } from "./errors-D1P2kKbL.js";
|
|
5
5
|
import { mkdir, readFile, readdir, rm, stat, writeFile } from "node:fs/promises";
|
|
6
6
|
import { dirname, join, relative, resolve, sep } from "node:path";
|
|
7
|
-
import { ATTRIBUTE_CASES, CENTRIFUGO_CHANNEL_MAX, CommandFailure, DATABASE_PROVIDERS, FUNCTIONS_FILE_SUFFIX, PLATFORM_LOGIN_ROLES, PLATFORM_ROLES, PLATFORM_SCHEMA, PROVIDER_API_ROLES, PROVIDER_IDENTITY_SOURCES, PROVIDER_SCHEMAS, SIGNAL_MERGE_THRESHOLD, SIGNAL_NOTIFY_CHANNEL, SIGNAL_OUTBOX, SQL_DEBT_FILE, UUID_TEXT, batchSchema, logicalTypeOf, metadataKindSchema, objectNameSchema, quoteIdent, readQuerySchema } from "simetra/model";
|
|
7
|
+
import { ATTRIBUTE_CASES, CENTRIFUGO_CHANNEL_MAX, CommandFailure, DATABASE_PROVIDERS, FUNCTIONS_FILE_SUFFIX, PLATFORM_LOGIN_ROLES, PLATFORM_ROLES, PLATFORM_SCHEMA, PROVIDER_API_ROLES, PROVIDER_IDENTITY_SOURCES, PROVIDER_LOGIN_ROLES, PROVIDER_OWNER_ROLES, PROVIDER_SCHEMAS, SIGNAL_MERGE_THRESHOLD, SIGNAL_NOTIFY_CHANNEL, SIGNAL_OUTBOX, SQL_DEBT_FILE, UUID_TEXT, batchSchema, logicalTypeOf, metadataKindSchema, objectNameSchema, quoteIdent, readQuerySchema } from "simetra/model";
|
|
8
8
|
import { ApplyConnectionLost, ApplyDbError, FINGERPRINT_VERSION, LOCK_MODE_SQL, PLATFORM_VERSION, applyStateOf, buildPlan, checkOwnerAttributes, checkOwnerMembership, checkPermissions, checkPlatformRoles, compareWithDesired, copiesShadowFromTemplate, desiredForApply, engineScope, ensurePlatformRoles, ensurePostgresCluster, executePlan, folderReference, parsePlan, parseRehearsal, planFileName, platformRoleSet, postgresClusterSet, readShadowEnvironment, rehearsalFileName, rehearsalReport, reverseGenerate, runRightsMaintenance, serializePlan, serializeRehearsal, verifyPlanHash } from "simetra/schema";
|
|
9
9
|
import pg from "pg";
|
|
10
10
|
import { agentWriteRefusal, createAgentCore, createCommandRuntime, fromPgPool, readRoleOf, toJson } from "simetra/server";
|
|
@@ -1617,7 +1617,75 @@ function summarizeData(name, data) {
|
|
|
1617
1617
|
if ("error" in data) return `${name}: ${data.error.code}${data.error.reason === void 0 ? "" : `: ${data.error.reason}`}`;
|
|
1618
1618
|
const count = (n, what) => `${n} ${what}${n === 1 ? "" : "s"}`;
|
|
1619
1619
|
if ("count" in data) return `${name}: ${data.capped === true ? "over " : ""}${count(data.count, "row")} counted`;
|
|
1620
|
-
|
|
1620
|
+
if ("rows" in data) return `${name}: ${count(data.rows.length, "row")}`;
|
|
1621
|
+
const created = data.result.changes.filter((c) => c.operation === "create").map((c) => `created ${c.object.kind} ${c.object.name} ${c.id}`);
|
|
1622
|
+
return [`${name}: ${count(data.result.changes.length, "change")}`, ...created].join("\n");
|
|
1623
|
+
}
|
|
1624
|
+
/**
|
|
1625
|
+
* `id` для `create` без нього (спека designer §3.2): ключ рядка — UUID, і викликач не
|
|
1626
|
+
* мусить його вигадувати. Корінь виду скоупу лишається без `id`: його генерує
|
|
1627
|
+
* T3 і відмовляє на переданий; невідомий об'єкт відхилить T3.
|
|
1628
|
+
*/
|
|
1629
|
+
function withCreateIds(catalog, batch, newId = () => crypto.randomUUID()) {
|
|
1630
|
+
return batch.map((op) => {
|
|
1631
|
+
if (op.action !== "create" || op.id !== void 0) return op;
|
|
1632
|
+
const object = catalog.objects.find((o) => o.kind === op.object.kind && o.name === op.object.name);
|
|
1633
|
+
if (object === void 0 || object.operations?.create?.root !== void 0) return op;
|
|
1634
|
+
return {
|
|
1635
|
+
...op,
|
|
1636
|
+
id: newId()
|
|
1637
|
+
};
|
|
1638
|
+
});
|
|
1639
|
+
}
|
|
1640
|
+
/**
|
|
1641
|
+
* Скоуп для `create` скоупленого об'єкта без нього (спека designer §3.2): єдиний скоуп
|
|
1642
|
+
* цього виду, де користувач — учасник; інакше вибір неоднозначний, і
|
|
1643
|
+
* designer відмовляє діагностикою, а не підставляє навмання. Скоупи
|
|
1644
|
+
* читаються лише тоді, коли хоч одній операції скоупу бракує.
|
|
1645
|
+
*/
|
|
1646
|
+
async function withCreateScopes(model, catalog, batch, myScopes) {
|
|
1647
|
+
let scopes;
|
|
1648
|
+
const operations = [];
|
|
1649
|
+
for (const [index, op] of batch.entries()) {
|
|
1650
|
+
const object = op.action === "create" ? catalog.objects.find((o) => o.kind === op.object.kind && o.name === op.object.name) : void 0;
|
|
1651
|
+
const attribute = object?.attributes.find((a) => a.column === object.scopeColumn);
|
|
1652
|
+
if (op.action !== "create" || object?.scopeKindId === void 0 || attribute?.insert !== true || Object.hasOwn(op.values ?? {}, attribute.name)) {
|
|
1653
|
+
operations.push(op);
|
|
1654
|
+
continue;
|
|
1655
|
+
}
|
|
1656
|
+
scopes ??= await myScopes();
|
|
1657
|
+
const mine = [...new Set(scopes.filter((s) => s.scopeKind === object.scopeKindId).map((s) => s.scope))];
|
|
1658
|
+
if (mine.length !== 1) {
|
|
1659
|
+
const kind = model.scopeKinds.find((k) => k.id === object.scopeKindId);
|
|
1660
|
+
return { diagnostic: diagnostic("data.scope-unspecified", "", `/operations/${index}/values`, {
|
|
1661
|
+
object: `${op.object.kind} ${op.object.name}`,
|
|
1662
|
+
scopeKind: kind?.name ?? object.scopeKindId,
|
|
1663
|
+
attribute: attribute.name,
|
|
1664
|
+
scopes: mine.length
|
|
1665
|
+
}) };
|
|
1666
|
+
}
|
|
1667
|
+
operations.push({
|
|
1668
|
+
...op,
|
|
1669
|
+
values: {
|
|
1670
|
+
...op.values,
|
|
1671
|
+
[attribute.name]: mine[0]
|
|
1672
|
+
}
|
|
1673
|
+
});
|
|
1674
|
+
}
|
|
1675
|
+
return { operations };
|
|
1676
|
+
}
|
|
1677
|
+
/**
|
|
1678
|
+
* Скоупи користувача сесії зі знімка прав (`members`). Проєкт без функцій
|
|
1679
|
+
* прав знімка не має (`command.invalid`) — тоді скоупів немає, і рішення
|
|
1680
|
+
* лишається за діагностикою, а не за помилкою рантайму.
|
|
1681
|
+
*/
|
|
1682
|
+
async function membersOf(runtime, session) {
|
|
1683
|
+
try {
|
|
1684
|
+
return (await runtime.rightsSnapshot(session)).snapshot.members;
|
|
1685
|
+
} catch (error) {
|
|
1686
|
+
if (error instanceof CommandFailure && error.error.code === "command.invalid") return [];
|
|
1687
|
+
throw error;
|
|
1688
|
+
}
|
|
1621
1689
|
}
|
|
1622
1690
|
const SQLSTATE = /^[0-9A-Z]{5}$/;
|
|
1623
1691
|
/**
|
|
@@ -1727,20 +1795,27 @@ const dataReadTool = defineTool({
|
|
|
1727
1795
|
});
|
|
1728
1796
|
const dataCommandTool = defineTool({
|
|
1729
1797
|
name: "data-command",
|
|
1730
|
-
description: "Change application data of the development database as the user given by --as, with that user's rights: a batch of create, update, markDeletion and delete operations in one transaction (update, markDeletion and delete need expectedVersion). A tabular section array in update replaces the section: every existing row must be in the array or in deleteIds. Rights catalogs and create of a scope root whose creator gets a role need --allow-rights-write; objects with a module are refused, and for such a root also when its membership catalog has one. BigInt values may be passed as decimal strings. Each result row has the shape of a read card: the tabular sections the operation wrote come under tabularSections. A runtime error comes as data.error with a code.",
|
|
1798
|
+
description: "Change application data of the development database as the user given by --as, with that user's rights: a batch of create, update, markDeletion and delete operations in one transaction (update, markDeletion and delete need expectedVersion). A create without id gets a fresh one; without its scope it takes the user's only scope of that kind. A tabular section array in update replaces the section: every existing row must be in the array or in deleteIds. Rights catalogs and create of a scope root whose creator gets a role need --allow-rights-write; objects with a module are refused, and for such a root also when its membership catalog has one. BigInt values may be passed as decimal strings. Each result row has the shape of a read card: the tabular sections the operation wrote come under tabularSections. A runtime error comes as data.error with a code.",
|
|
1731
1799
|
input: z.strictObject({ operations: batchSchema }),
|
|
1732
1800
|
files: "read",
|
|
1733
1801
|
database: "none",
|
|
1734
1802
|
data: "write",
|
|
1735
1803
|
destructive: false,
|
|
1736
1804
|
async run(ctx, input) {
|
|
1805
|
+
if (input.operations.some((op) => op.action === "issueInvitation")) return {
|
|
1806
|
+
ok: false,
|
|
1807
|
+
changes: [],
|
|
1808
|
+
diagnostics: [],
|
|
1809
|
+
refusal: "data-command never runs issueInvitation: the secret would reach the model. Issue invitations in the application."
|
|
1810
|
+
};
|
|
1737
1811
|
const compiled = await compileDir(ctx.dir);
|
|
1738
1812
|
if ("failed" in compiled) return compiled.failed;
|
|
1739
1813
|
const { model } = compiled;
|
|
1740
1814
|
const warnings = warningsFor(model, compiled.diagnostics, input.operations.map((op) => op.object));
|
|
1741
1815
|
const catalog = buildRuntimeCatalog(model);
|
|
1816
|
+
const operations = withCreateIds(catalog, input.operations);
|
|
1742
1817
|
const rightsWrite = ctx.allowRightsWrite === true;
|
|
1743
|
-
const refusal = dataPolicyRefusal(model, catalog,
|
|
1818
|
+
const refusal = dataPolicyRefusal(model, catalog, operations, { rightsWrite });
|
|
1744
1819
|
if (refusal?.kind === "command") return {
|
|
1745
1820
|
ok: false,
|
|
1746
1821
|
changes: [],
|
|
@@ -1753,12 +1828,20 @@ const dataCommandTool = defineTool({
|
|
|
1753
1828
|
diagnostics: [],
|
|
1754
1829
|
refusalReason: "rights-write-disabled"
|
|
1755
1830
|
};
|
|
1756
|
-
|
|
1831
|
+
const ran = await onRuntime("data-command", ctx, model, warnings, async (rt, session) => {
|
|
1832
|
+
const scoped = await withCreateScopes(model, catalog, operations, () => membersOf(rt, session));
|
|
1833
|
+
if ("diagnostic" in scoped) return scoped;
|
|
1757
1834
|
return { result: await createAgentCore({
|
|
1758
1835
|
runtime: rt,
|
|
1759
1836
|
permissions: { rightsWrite }
|
|
1760
|
-
}).execute(session,
|
|
1837
|
+
}).execute(session, scoped.operations) };
|
|
1761
1838
|
});
|
|
1839
|
+
if (ran.data !== void 0 && "diagnostic" in ran.data) return {
|
|
1840
|
+
ok: false,
|
|
1841
|
+
changes: [],
|
|
1842
|
+
diagnostics: [...warnings, ran.data.diagnostic]
|
|
1843
|
+
};
|
|
1844
|
+
return ran;
|
|
1762
1845
|
},
|
|
1763
1846
|
present: {
|
|
1764
1847
|
structure: (data) => toJson(data),
|
|
@@ -2052,6 +2135,60 @@ const rightsMaintenanceTool = defineTool({
|
|
|
2052
2135
|
});
|
|
2053
2136
|
// src/tools/roles-tool.ts
|
|
2054
2137
|
const PROJECT_FILE$1 = "project.meta.json";
|
|
2138
|
+
const [AUTH_ROLE] = PROVIDER_LOGIN_ROLES.postgres;
|
|
2139
|
+
if (AUTH_ROLE === void 0) throw new Error("the postgres profile data has no auth login role");
|
|
2140
|
+
/**
|
|
2141
|
+
* Змінні середовища з паролями розробника ролей входу профілю `postgres`
|
|
2142
|
+
* (спека профілю §3.4): імена ролей — з даних T0, змінні — ті самі, що в
|
|
2143
|
+
* стеку розробки (`login-secrets.env`).
|
|
2144
|
+
*/
|
|
2145
|
+
const DEV_PASSWORD_VARIABLES = [
|
|
2146
|
+
{
|
|
2147
|
+
role: PROVIDER_OWNER_ROLES.postgres,
|
|
2148
|
+
variable: "SIMETRA_OWNER_DEV_PASSWORD"
|
|
2149
|
+
},
|
|
2150
|
+
{
|
|
2151
|
+
role: AUTH_ROLE,
|
|
2152
|
+
variable: "SIMETRA_AUTH_DEV_PASSWORD"
|
|
2153
|
+
},
|
|
2154
|
+
{
|
|
2155
|
+
role: PLATFORM_LOGIN_ROLES.runtime,
|
|
2156
|
+
variable: "SIMETRA_RUNTIME_DEV_PASSWORD"
|
|
2157
|
+
},
|
|
2158
|
+
{
|
|
2159
|
+
role: PLATFORM_LOGIN_ROLES.signals,
|
|
2160
|
+
variable: "SIMETRA_SIGNALS_DEV_PASSWORD"
|
|
2161
|
+
}
|
|
2162
|
+
];
|
|
2163
|
+
/**
|
|
2164
|
+
* Паролі розробника за роллю або відмови до будь-якого з'єднання: хост, який
|
|
2165
|
+
* візьме `pg` (`?host=`, `PGHOST` теж), — лише ця машина, бо відомий пароль
|
|
2166
|
+
* на спільному сервері відкрив би його; кожна змінна задана й не порожня.
|
|
2167
|
+
* Значення в діагностики не потрапляють — лише імена змінних і хост.
|
|
2168
|
+
*/
|
|
2169
|
+
function devPasswordsFrom(env, url) {
|
|
2170
|
+
const diagnostics = [];
|
|
2171
|
+
let host;
|
|
2172
|
+
try {
|
|
2173
|
+
host = new pg.Client({ connectionString: url }).host;
|
|
2174
|
+
} catch {
|
|
2175
|
+
host = void 0;
|
|
2176
|
+
}
|
|
2177
|
+
if (!isLocalHost(host)) diagnostics.push(diagnostic("roles.dev-passwords-remote", "", "", { host: host === void 0 || host === "" ? "(none)" : host }));
|
|
2178
|
+
const passwords = /* @__PURE__ */ new Map();
|
|
2179
|
+
for (const { role, variable } of DEV_PASSWORD_VARIABLES) {
|
|
2180
|
+
const value = env[variable];
|
|
2181
|
+
if (value === void 0 || value === "") diagnostics.push(diagnostic("roles.dev-password-missing", "", "", { variable }));
|
|
2182
|
+
else passwords.set(role, value);
|
|
2183
|
+
}
|
|
2184
|
+
return diagnostics.length > 0 ? {
|
|
2185
|
+
ok: false,
|
|
2186
|
+
diagnostics
|
|
2187
|
+
} : {
|
|
2188
|
+
ok: true,
|
|
2189
|
+
passwords
|
|
2190
|
+
};
|
|
2191
|
+
}
|
|
2055
2192
|
/**
|
|
2056
2193
|
* Набір ролей теки проєкту (спека П4 §6.2): провайдер — з файлу проєкту, тим самим
|
|
2057
2194
|
* читачем, що й `compile`. Без файлу ролі входу пропускаються явно — пропуск
|
|
@@ -2112,7 +2249,12 @@ function clusterRoles(value) {
|
|
|
2112
2249
|
* ціль і шаблон; окремий сервер тіней там не підтримано.
|
|
2113
2250
|
* Решта провайдерів і проєкт без файлу — ролі на цілі й на сервері тіні.
|
|
2114
2251
|
*/
|
|
2115
|
-
async function runRoles(dbs, db, project) {
|
|
2252
|
+
async function runRoles(dbs, db, project, options = {}) {
|
|
2253
|
+
if (options.devPasswords !== void 0 && project.provider !== "postgres") return {
|
|
2254
|
+
roles: [],
|
|
2255
|
+
skipped: [],
|
|
2256
|
+
diagnostics: [diagnostic("roles.dev-passwords-unsupported", "", "", project.provider === void 0 ? {} : { provider: project.provider })]
|
|
2257
|
+
};
|
|
2116
2258
|
if (project.provider === "postgres") {
|
|
2117
2259
|
if (db.shadowBase !== void 0) return {
|
|
2118
2260
|
roles: [],
|
|
@@ -2129,13 +2271,19 @@ async function runRoles(dbs, db, project) {
|
|
|
2129
2271
|
error: "the database address names no database"
|
|
2130
2272
|
})]
|
|
2131
2273
|
};
|
|
2274
|
+
const dev = options.devPasswords === void 0 ? void 0 : devPasswordsFrom(options.devPasswords, db.target.url);
|
|
2275
|
+
if (dev?.ok === false) return {
|
|
2276
|
+
roles: [],
|
|
2277
|
+
skipped: [],
|
|
2278
|
+
diagnostics: dev.diagnostics
|
|
2279
|
+
};
|
|
2132
2280
|
const set = postgresClusterSet(database);
|
|
2133
2281
|
const { withDatabaseName } = await import("@supabase/pg-delta");
|
|
2134
2282
|
const result = await ensurePostgresCluster(dbs, {
|
|
2135
2283
|
maintenance: { url: withDatabaseName(db.target.url, "postgres") },
|
|
2136
2284
|
target: db.target,
|
|
2137
2285
|
template: { url: withDatabaseName(db.target.url, set.template) }
|
|
2138
|
-
}, set);
|
|
2286
|
+
}, set, dev === void 0 ? {} : { passwords: dev.passwords });
|
|
2139
2287
|
if (!result.ok) return {
|
|
2140
2288
|
roles: [],
|
|
2141
2289
|
skipped: [],
|
|
@@ -2147,7 +2295,8 @@ async function runRoles(dbs, db, project) {
|
|
|
2147
2295
|
name,
|
|
2148
2296
|
reason: "identity-table-missing"
|
|
2149
2297
|
})),
|
|
2150
|
-
diagnostics: []
|
|
2298
|
+
diagnostics: [],
|
|
2299
|
+
...dev === void 0 ? {} : { passwords: DEV_PASSWORD_VARIABLES.filter((v) => result.value.passwords?.includes(v.role)) }
|
|
2151
2300
|
};
|
|
2152
2301
|
}
|
|
2153
2302
|
const ran = await ensurePlatformRoles(dbs, [{
|
|
@@ -2171,13 +2320,13 @@ async function runRoles(dbs, db, project) {
|
|
|
2171
2320
|
*/
|
|
2172
2321
|
const rolesTool = defineTool({
|
|
2173
2322
|
name: "roles",
|
|
2174
|
-
description: "Create the platform roles: NOLOGIN roles that generated SQL grants to on the target and the shadow server, and the login roles (the runtime and the signals consumer) on the target only, each a member of its parents WITH INHERIT FALSE, SET TRUE; the signals login role also gets a role setting (ALTER ROLE … SET) that makes its consumer group the role of every new session. Reads
|
|
2175
|
-
input: z.strictObject({}),
|
|
2323
|
+
description: "Create the platform roles: NOLOGIN roles that generated SQL grants to on the target and the shadow server, and the login roles (the runtime and the signals consumer) on the target only, each a member of its parents WITH INHERIT FALSE, SET TRUE; the signals login role also gets a role setting (ALTER ROLE … SET) that makes its consumer group the role of every new session. Reads `database.provider` from the project file; without it the login roles are skipped, and the output says so. An existing role is only checked, its role setting included; the one change is a missing membership of an existing login role in a parent of its profile, added WITH INHERIT FALSE, SET TRUE and named in the output. Needs CREATEROLE, and ADMIN OPTION on every parent role of a login role (without it that login role alone is refused, a missing membership with the GRANT statement to run); refuses before creating anything when a server lacks CREATEROLE or a role has an unsafe shape. With the provider `postgres` it prepares the cluster instead, as a superuser (a superuser URL of the target database): the owner, auth, grant and request roles, the target database owned by the owner, the schemas `extensions` and `better_auth`, `plpgsql_check`, and the sealed template for shadows. It refuses before writing when the session is not a superuser, a database or role has an unsafe shape, a Simetra login role can connect to another database, or the server lacks plpgsql_check; a separate shadow server is not supported there. devPasswords (postgres, local database only) sets the password of each login role it creates from SIMETRA_{OWNER,AUTH,RUNTIME,SIGNALS}_DEV_PASSWORD.",
|
|
2324
|
+
input: z.strictObject({ devPasswords: z.boolean().optional() }),
|
|
2176
2325
|
files: "read",
|
|
2177
2326
|
database: "write",
|
|
2178
2327
|
data: "none",
|
|
2179
2328
|
destructive: false,
|
|
2180
|
-
async run({ dir, database }) {
|
|
2329
|
+
async run({ dir, database, env }, input) {
|
|
2181
2330
|
const set = await projectRoleSet(dir);
|
|
2182
2331
|
if (!set.ok) return {
|
|
2183
2332
|
ok: false,
|
|
@@ -2185,7 +2334,7 @@ const rolesTool = defineTool({
|
|
|
2185
2334
|
diagnostics: set.diagnostics
|
|
2186
2335
|
};
|
|
2187
2336
|
const { createApplyDatabase } = await import("./schema-engine-8rVHcVYO.js");
|
|
2188
|
-
const ran = await withDatabase(required$1(database), "roles", (db) => runRoles(createApplyDatabase({ readOnly: false }), db, set));
|
|
2337
|
+
const ran = await withDatabase(required$1(database), "roles", (db) => runRoles(createApplyDatabase({ readOnly: false }), db, set, input.devPasswords === true ? { devPasswords: env ?? {} } : {}));
|
|
2189
2338
|
if (!ran.ok) return {
|
|
2190
2339
|
ok: false,
|
|
2191
2340
|
changes: [],
|
|
@@ -2193,7 +2342,8 @@ const rolesTool = defineTool({
|
|
|
2193
2342
|
};
|
|
2194
2343
|
const data = {
|
|
2195
2344
|
roles: ran.value.roles,
|
|
2196
|
-
skipped: [...set.skipped, ...ran.value.skipped]
|
|
2345
|
+
skipped: [...set.skipped, ...ran.value.skipped],
|
|
2346
|
+
...ran.value.passwords === void 0 ? {} : { passwords: ran.value.passwords }
|
|
2197
2347
|
};
|
|
2198
2348
|
return {
|
|
2199
2349
|
ok: ran.value.diagnostics.length === 0,
|
|
@@ -2209,6 +2359,7 @@ const rolesTool = defineTool({
|
|
|
2209
2359
|
const at = x.name.lastIndexOf(":");
|
|
2210
2360
|
return `target: ${x.name.slice(0, at)}: ${x.name.slice(at + 1)} not granted yet — run the Better Auth migration, then simetra roles again`;
|
|
2211
2361
|
}),
|
|
2362
|
+
...(data.passwords ?? []).map((x) => `target: ${x.role} password set from ${x.variable}`),
|
|
2212
2363
|
...v.diagnostics.length > 0 ? [v.report] : []
|
|
2213
2364
|
].join("\n") }
|
|
2214
2365
|
});
|
|
@@ -2625,6 +2776,7 @@ async function invoke(tool, input, o) {
|
|
|
2625
2776
|
dir: o.dir,
|
|
2626
2777
|
root,
|
|
2627
2778
|
...tool.database === "none" ? {} : { database: o.database },
|
|
2779
|
+
...tool.database === "none" || o.env === void 0 ? {} : { env: o.env },
|
|
2628
2780
|
...tool.data === "none" ? {} : { data: o.data },
|
|
2629
2781
|
...tool.data === "write" ? { allowRightsWrite: o.allowRightsWrite === true } : {},
|
|
2630
2782
|
...o.baseline === void 0 ? {} : { baseline: o.baseline }
|
package/dist/main.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { t as version } from "./package-
|
|
2
|
+
import { t as version } from "./package-CJuyaMGH.js";
|
|
3
3
|
import { n as TOOL_NAMES } from "./types-CMcZhIci.js";
|
|
4
4
|
import { defineCommand, runCommand, runMain, showUsage } from "citty";
|
|
5
5
|
// src/main.ts
|
|
@@ -10,9 +10,9 @@ const main = defineCommand({
|
|
|
10
10
|
description: "Simetra metadata tooling"
|
|
11
11
|
},
|
|
12
12
|
subCommands: {
|
|
13
|
-
...Object.fromEntries(TOOL_NAMES.map((name) => [name, () => import("./command-
|
|
14
|
-
mcp: () => import("./mcp-
|
|
15
|
-
init: () => import("./init-
|
|
13
|
+
...Object.fromEntries(TOOL_NAMES.map((name) => [name, () => import("./command-BUIz4QxS.js").then((m) => m.commandByName(name))])),
|
|
14
|
+
mcp: () => import("./mcp-CLc4ByOi.js").then((m) => m.default),
|
|
15
|
+
init: () => import("./init-BS7fCOls.js").then((m) => m.default)
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
18
|
const rawArgs = process.argv.slice(2);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { d as parseDataLaunch, f as databaseResource, i as structureOf, l as checkEnvName, n as TOOLS, o as formatDiagnostics, r as presentation, t as invoke, u as dataResource } from "./invoke-
|
|
2
|
+
import { d as parseDataLaunch, f as databaseResource, i as structureOf, l as checkEnvName, n as TOOLS, o as formatDiagnostics, r as presentation, t as invoke, u as dataResource } from "./invoke-B6ljdX5t.js";
|
|
3
3
|
import { a as dataWriteHint, l as readOnlyHint, n as trimSlash, o as databaseWriteHint, p as UsageError, r as ALLOW_RIGHTS_WRITE_FLAG } from "./default-dir-DerxTbci.js";
|
|
4
|
-
import { t as version } from "./package-
|
|
4
|
+
import { t as version } from "./package-CJuyaMGH.js";
|
|
5
5
|
import { t as mcpArgs } from "./mcp-args-D63akJ97.js";
|
|
6
6
|
import { defineCommand } from "citty";
|
|
7
7
|
import { z } from "zod";
|
|
@@ -130,7 +130,8 @@ function registerCatalog(server, o) {
|
|
|
130
130
|
...o.databaseEnv === void 0 ? {} : { databaseEnv: o.databaseEnv },
|
|
131
131
|
...o.data === void 0 ? {} : { data: o.data },
|
|
132
132
|
...o.dataEnv === void 0 ? {} : { dataEnv: o.dataEnv },
|
|
133
|
-
launchArgs: o.launchArgs
|
|
133
|
+
launchArgs: o.launchArgs,
|
|
134
|
+
...o.env === void 0 ? {} : { env: o.env }
|
|
134
135
|
});
|
|
135
136
|
return toResponse(tool, result, o, dry === true);
|
|
136
137
|
});
|
|
@@ -194,7 +195,8 @@ function mcpOptionsFrom(args, env, argv) {
|
|
|
194
195
|
databaseEnv,
|
|
195
196
|
...data === void 0 ? {} : { data },
|
|
196
197
|
...launch === void 0 ? {} : { dataEnv: launch.urlEnv },
|
|
197
|
-
launchArgs: argv
|
|
198
|
+
launchArgs: argv,
|
|
199
|
+
env
|
|
198
200
|
};
|
|
199
201
|
}
|
|
200
202
|
var mcp_default = defineCommand({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simetrajs/designer",
|
|
3
|
-
"version": "0.3.0-next.
|
|
3
|
+
"version": "0.3.0-next.10",
|
|
4
4
|
"description": "Simetra developer tools: command line and MCP server over the metadata compiler",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"simetra",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"pg-connection-string": "2.14.1",
|
|
38
38
|
"smol-toml": "1.9.1",
|
|
39
39
|
"zod": "^4.6.7",
|
|
40
|
-
"simetra": "0.3.0-next.
|
|
40
|
+
"simetra": "0.3.0-next.10"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@arethetypeswrong/cli": "0.18.5",
|
|
@@ -57,6 +57,7 @@
|
|
|
57
57
|
"publishConfig": {
|
|
58
58
|
"access": "public"
|
|
59
59
|
},
|
|
60
|
+
"gitHead": "08adc247b23c7a9e52872db1a9f7318689f06fc6",
|
|
60
61
|
"scripts": {
|
|
61
62
|
"build": "tsc --noEmit",
|
|
62
63
|
"build:package": "tsdown",
|
|
@@ -323,6 +323,9 @@ system rights catalogs and tenant creation: a scope root whose creator gets a
|
|
|
323
323
|
}
|
|
324
324
|
```
|
|
325
325
|
|
|
326
|
+
A new scope kind comes with its root and membership catalog in one `add`
|
|
327
|
+
(`objects`): `references/people-and-rights.md`.
|
|
328
|
+
|
|
326
329
|
The PG schema `simetra` (identities, the current user, provisioning) belongs
|
|
327
330
|
to the platform and is reserved (`schema.reserved`); in SQL the current user is
|
|
328
331
|
`(select simetra.current_user_id())`. Both rules in full: the same reference.
|
|
@@ -156,8 +156,12 @@ Read a card with the rows its references point to:
|
|
|
156
156
|
}
|
|
157
157
|
```
|
|
158
158
|
|
|
159
|
-
Seed rows in one transaction (`
|
|
160
|
-
`
|
|
159
|
+
Seed rows in one transaction (`update`, `markDeletion` and `delete` also
|
|
160
|
+
need `expectedVersion`). A `create` without `id` gets a fresh UUID, and the
|
|
161
|
+
CLI text output prints `created <kind> <name> <id>` for every new row. A
|
|
162
|
+
`create` of a scoped object without its scope value takes the only scope of
|
|
163
|
+
that kind the `--as` user is a member of; with none or several the batch is
|
|
164
|
+
refused with `data.scope-unspecified` — pass the scope in `values` then:
|
|
161
165
|
|
|
162
166
|
```json simetra:data-command
|
|
163
167
|
{
|
|
@@ -165,7 +169,6 @@ Seed rows in one transaction (`id` is a new UUID you generate; `update`,
|
|
|
165
169
|
{
|
|
166
170
|
"action": "create",
|
|
167
171
|
"object": { "kind": "Catalog", "name": "Currency" },
|
|
168
|
-
"id": "0b9d4c5e-8f1a-4c3b-9e2d-6a7f8b9c0d1e",
|
|
169
172
|
"values": { "description": "US dollar", "symbol": "$" }
|
|
170
173
|
}
|
|
171
174
|
]
|
|
@@ -52,6 +52,38 @@ People are platform data, not tables you write yourself:
|
|
|
52
52
|
its scope set function from that catalog. Use it instead of a hand-written
|
|
53
53
|
member table and set function. One membership catalog per scope kind.
|
|
54
54
|
|
|
55
|
+
A scope kind needs its root (scoped by the kind itself) and, with
|
|
56
|
+
`"setFunction": "membership"`, a membership catalog; none of the three compiles
|
|
57
|
+
alone, so `add` creates them in one change with `objects`. Every existing
|
|
58
|
+
object that takes a scope must already declare one (`"scope": "none"` or a
|
|
59
|
+
kind), or the first kind fails with `scope.declaration-missing`:
|
|
60
|
+
|
|
61
|
+
```json simetra:add
|
|
62
|
+
{
|
|
63
|
+
"target": { "kind": "Project" },
|
|
64
|
+
"collection": "scopeKinds",
|
|
65
|
+
"element": {
|
|
66
|
+
"name": "org",
|
|
67
|
+
"root": { "object": { "kind": "Catalog", "name": "Organization" } },
|
|
68
|
+
"setFunction": "membership"
|
|
69
|
+
},
|
|
70
|
+
"objects": [
|
|
71
|
+
{ "kind": "Catalog", "name": "Organization", "data": { "scope": "org" } },
|
|
72
|
+
{
|
|
73
|
+
"kind": "Catalog",
|
|
74
|
+
"name": "OrgMember",
|
|
75
|
+
"data": {
|
|
76
|
+
"scope": "org",
|
|
77
|
+
"membership": { "user": "user" },
|
|
78
|
+
"attributes": [
|
|
79
|
+
{ "name": "user", "type": "Ref", "ref": { "kind": "Catalog", "name": "Users" } }
|
|
80
|
+
]
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
]
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
55
87
|
The platform layer (identities, the current user, provisioning) lives in the
|
|
56
88
|
PG schema `simetra`, generated when a users catalog exists, or when the
|
|
57
89
|
project has a membership source and its provider's user id is the `sub` claim
|
|
@@ -97,8 +129,51 @@ with a trigger on the target table, see "Carrier copies").
|
|
|
97
129
|
reference becomes a composite foreign key within the scope.
|
|
98
130
|
- **`rightsContainer`** — the catalog is a rights container: roles can be
|
|
99
131
|
assigned on its rows. `"rightsContainer": true`
|
|
100
|
-
- **`containerBinding`** — the
|
|
101
|
-
`"containerBinding": "<attribute>"
|
|
132
|
+
- **`containerBinding`** — the `Ref` attribute that binds a row to its
|
|
133
|
+
container. `"containerBinding": "<attribute>"`; the path form
|
|
134
|
+
`["<ref attribute>", "<attribute>"]` is a schema error (it stays valid for
|
|
135
|
+
`ownership` and `access`). The target is a `rightsContainer` catalog (a
|
|
136
|
+
direct binding) or an object with its own `containerBinding` (a chain, of
|
|
137
|
+
any length: comment → task → project, where only the project is a container). The container of a row is the first
|
|
138
|
+
`rightsContainer` the chain reaches, so a container never continues the
|
|
139
|
+
chain. A hierarchy (a kind whose rows point at a parent row of the same
|
|
140
|
+
kind) is not a chain: bind every node directly to its container, never
|
|
141
|
+
through the parent attribute, because a binding to the kind itself is a
|
|
142
|
+
cycle. Any cycle in the kind graph, including a
|
|
143
|
+
reference to itself and two containers bound to each other, is
|
|
144
|
+
`rights.container-binding-cycle` on every kind of the cycle; a target that
|
|
145
|
+
is neither a container nor bound is `rights.container-target`.
|
|
146
|
+
|
|
147
|
+
A chained row carries a platform-owned copy of its binding, a standard
|
|
148
|
+
column named from the binding attribute and the end column of the direct
|
|
149
|
+
binding (`rights.carrier-column-taken` on a clash). The platform writes it;
|
|
150
|
+
a value in a request is ignored. A read policy compares only that column, so
|
|
151
|
+
the cost of a read does not grow with the chain. A container role reads the
|
|
152
|
+
chained row when the grant covers its kind.
|
|
153
|
+
|
|
154
|
+
**Rebinding.** Changing the binding attribute of a row whose kind has chained
|
|
155
|
+
descendants moves all of them to another container. Besides the right to
|
|
156
|
+
update the row itself, the actor needs `update` at extent `any` on every
|
|
157
|
+
descendant kind, on every level below, in the container before and in the
|
|
158
|
+
container after: through a role on that container or a scope-level role.
|
|
159
|
+
An empty binding on either side needs the scope-level right. Otherwise the
|
|
160
|
+
command fails with `command.forbidden` / `no-right`, and the database error
|
|
161
|
+
names the descendant kind; the check runs before any copy is rewritten. A
|
|
162
|
+
change made by a `beforeWrite` handler is judged the same way. Moving a row
|
|
163
|
+
between targets of the same container needs no extra right, and neither
|
|
164
|
+
does the copy update that a rebinding cascades. Outside a command
|
|
165
|
+
(maintenance, a plan data step) the check does not run.
|
|
166
|
+
|
|
167
|
+
**Limits.** Reading costs the same at any depth. Writing pays: a rebind
|
|
168
|
+
rewrites the copies of all descendants on every level below, in the same
|
|
169
|
+
transaction, one `UPDATE` per level through the foreign key index. Measured
|
|
170
|
+
on one developer machine (16 cores, Postgres 17 on the local stack, light
|
|
171
|
+
load), one task moved between two projects, 5 replies per
|
|
172
|
+
comment: 10 comments (60 copies) 6.5 ms median, 100 comments (600 copies)
|
|
173
|
+
47 ms, 1 000 comments (6 000 copies) 489 ms (p90 528 ms), roughly 80 µs per
|
|
174
|
+
rewritten row. Keep the number of descendants of one row that can be
|
|
175
|
+
rebound in a single command in the low thousands, and give a deep or wide
|
|
176
|
+
subtree its own container instead of rebinding it.
|
|
102
177
|
- **`access`** — the project access dimensions that narrow the rows, each with
|
|
103
178
|
its carrier to the dimension's value catalog.
|
|
104
179
|
`"access": [{ "attribute": "<attribute>", "dimension": "<dimension>" }]` or
|
|
@@ -177,7 +252,11 @@ the role's key in an adopted assignment table of the same level).
|
|
|
177
252
|
objects of that scope kind, only `read` on unscoped ones. The scope kind
|
|
178
253
|
needs a membership.
|
|
179
254
|
- `{ "container": <ref> }` — per row of a `rightsContainer` catalog: objects
|
|
180
|
-
whose `containerBinding`
|
|
255
|
+
whose `containerBinding` chain ends in it. Any such assignment also gives
|
|
256
|
+
implicit `read` of the container's own row, even for a role with no grants.
|
|
257
|
+
It covers that row only: not its tabular sections, no write, no
|
|
258
|
+
change-channel subscription, and a `rights_require` check without a target
|
|
259
|
+
row does not take it.
|
|
181
260
|
- `"everyUser"` — every valid user without an assignment: unscoped objects,
|
|
182
261
|
`own` or a dimension extent only, no `fullAccess`, no source keys.
|
|
183
262
|
|
|
@@ -633,6 +712,34 @@ the scope kind in `project.meta.json`) says that no role reads any object of
|
|
|
633
712
|
that scope kind, so nobody will see their rows: grant `read` to a role or
|
|
634
713
|
declare one with `fullAccess`.
|
|
635
714
|
|
|
715
|
+
**Open self sign-up.** `"selfSignUp": true` in `project.meta.json` declares
|
|
716
|
+
that anyone may register, so whatever every signed-in user sees is open to
|
|
717
|
+
anyone. The warning `project.self-sign-up` then lists the objects with
|
|
718
|
+
`publicRead` `authenticated` and the grants of `everyUser` roles. List what you
|
|
719
|
+
open on purpose in `selfSignUpAccepted`, and the warning names only the rest;
|
|
720
|
+
a new object, action or wider form warns again:
|
|
721
|
+
|
|
722
|
+
```json
|
|
723
|
+
"selfSignUpAccepted": {
|
|
724
|
+
"objects": [{ "object": { "kind": "Catalog", "name": "Country" } }],
|
|
725
|
+
"grants": [
|
|
726
|
+
{
|
|
727
|
+
"role": { "kind": "Role", "name": "ClientOwner" },
|
|
728
|
+
"object": { "kind": "Catalog", "name": "Client" },
|
|
729
|
+
"actions": ["read", "update"],
|
|
730
|
+
"extent": "own"
|
|
731
|
+
}
|
|
732
|
+
]
|
|
733
|
+
}
|
|
734
|
+
```
|
|
735
|
+
|
|
736
|
+
`"published": true` on an object entry accepts only the published rows of the
|
|
737
|
+
conditional `publicRead`. The names are references: `rename` rewrites them, and
|
|
738
|
+
`delete` of an accepted object, role, custom action or dimension is refused
|
|
739
|
+
until the entry is removed. An entry that matches nothing open any more warns
|
|
740
|
+
with `project.self-sign-up-stale`: remove it, and accept the openness again
|
|
741
|
+
when it comes back.
|
|
742
|
+
|
|
636
743
|
## Who writes what
|
|
637
744
|
|
|
638
745
|
Kind tables are written **only by commands**: the write policies grant the
|
|
@@ -689,7 +796,8 @@ on the target only (`LOGIN NOINHERIT`, a member of `simetra_command` and, for
|
|
|
689
796
|
`supabase`, of `authenticated` and `anon`, each `WITH INHERIT FALSE, SET TRUE`). It reads
|
|
690
797
|
`database.provider` from the project file; without a project file it skips the
|
|
691
798
|
login role, and the output says why. The operator sets the login role's
|
|
692
|
-
password; the platform keeps no secrets
|
|
799
|
+
password; the platform keeps no secrets (the one exception, a database on your
|
|
800
|
+
machine, is `--dev-passwords` below).
|
|
693
801
|
|
|
694
802
|
The login role needs `ADMIN OPTION` on each of its parent roles in the role
|
|
695
803
|
that runs `roles`. Without it `roles` still creates the grant roles, but
|
|
@@ -710,6 +818,19 @@ the profile, the application database owned by `simetra_owner`,
|
|
|
710
818
|
`simetra_template` that shadows and proof copies are built from. Running it
|
|
711
819
|
again converges the declared state and creates nothing.
|
|
712
820
|
|
|
821
|
+
For a database on your machine, `simetra roles --dev-passwords` (MCP input
|
|
822
|
+
`devPasswords: true`) also sets the password of each login role this run
|
|
823
|
+
creates (`simetra_owner`, `simetra_auth`, `simetra_runtime`,
|
|
824
|
+
`simetra_signals`) from `SIMETRA_OWNER_DEV_PASSWORD`,
|
|
825
|
+
`SIMETRA_AUTH_DEV_PASSWORD`, `SIMETRA_RUNTIME_DEV_PASSWORD` and
|
|
826
|
+
`SIMETRA_SIGNALS_DEV_PASSWORD` in the environment. A role that already exists
|
|
827
|
+
keeps its password. It refuses before anything is written when a variable is
|
|
828
|
+
missing or empty (`roles.dev-password-missing`), when the database host is not
|
|
829
|
+
this machine — `localhost`, `127.0.0.0/8`, `::1` or a unix socket
|
|
830
|
+
(`roles.dev-passwords-remote`), or when the provider is not `postgres`
|
|
831
|
+
(`roles.dev-passwords-unsupported`). On any other server set the passwords
|
|
832
|
+
yourself.
|
|
833
|
+
|
|
713
834
|
The identity provider's own roles get their grants here too: the role of the
|
|
714
835
|
platform owner receives `USAGE` on the `better_auth` schema and `TRIGGER` and
|
|
715
836
|
`REFERENCES` on `better_auth."user"`, so the provision triggers and the foreign
|
|
@@ -737,6 +858,12 @@ otherwise:
|
|
|
737
858
|
restore it by hand around a new `roles` run (the template is only dropped).
|
|
738
859
|
- `roles.shared-cluster` — a Simetra login role has an explicit `CONNECT` on
|
|
739
860
|
other databases; one cluster serves one application.
|
|
861
|
+
- `roles.extension-unavailable` — the server does not offer `plpgsql_check`
|
|
862
|
+
in `pg_available_extensions`; install the extension's package on the
|
|
863
|
+
database server (`postgresql-<major>-plpgsql-check` from PGDG) and run
|
|
864
|
+
`roles` again. `apply` refuses the same way with
|
|
865
|
+
`apply.extension-unavailable` before it locks any table when its plan checks
|
|
866
|
+
function bodies with the extension and the server no longer offers it.
|
|
740
867
|
- `plan.owner-not-bypassrls` — the role of `plan`, `apply` or `rehearse` has
|
|
741
868
|
neither `BYPASSRLS` nor superuser; run `ALTER ROLE <role> BYPASSRLS` as a
|
|
742
869
|
superuser.
|
|
@@ -5,8 +5,18 @@ package skills into `.agents/skills/` and `.claude/skills/` and writes the MCP
|
|
|
5
5
|
server entry for the chosen agents. Run it from the project root — the
|
|
6
6
|
directory the agent starts in, where `metadata/` lives.
|
|
7
7
|
|
|
8
|
+
When the agent starts in another directory (a monorepo root above the app),
|
|
9
|
+
name it with `--root`, or run `init` from there with the metadata directory as
|
|
10
|
+
the argument. The package is looked up from the metadata directory; the links
|
|
11
|
+
and configs go into the root, and the MCP entry names the metadata directory
|
|
12
|
+
relative to the root. A directory an own entry already names is kept. A
|
|
13
|
+
named metadata directory must exist, and on Windows it must be on the same
|
|
14
|
+
drive as the root.
|
|
15
|
+
|
|
8
16
|
```sh
|
|
9
17
|
pnpm exec simetra init
|
|
18
|
+
pnpm exec simetra init --root ..
|
|
19
|
+
pnpm exec simetra init apps/app/metadata
|
|
10
20
|
pnpm exec simetra init --agents claude,codex,cursor,vscode
|
|
11
21
|
pnpm exec simetra init --dry-run
|
|
12
22
|
pnpm exec simetra init --check --agents claude,codex
|
|
@@ -15,7 +25,7 @@ pnpm exec simetra init --check --agents claude,codex
|
|
|
15
25
|
- Without `--agents` only Claude Code's `.mcp.json` is written. The skill
|
|
16
26
|
links are made in both skill directories for every agent.
|
|
17
27
|
- The links and configs belong in git. In CI run `init --check` with the same
|
|
18
|
-
`--agents
|
|
28
|
+
`--agents`, `--root` and metadata directory: it exits 1 when a link or an MCP entry is missing or stale, and
|
|
19
29
|
changes nothing.
|
|
20
30
|
- `init` never overwrites what it does not own: a skill directory with the
|
|
21
31
|
same name, or a `simetra` MCP entry with another command, is left alone and
|