@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
package/README.md
CHANGED
|
@@ -29,16 +29,51 @@ npx simetra mcp metadata # the same tools over MCP (stdio)
|
|
|
29
29
|
```
|
|
30
30
|
|
|
31
31
|
`simetra --help` lists every command, and `simetra <command> --help` its
|
|
32
|
-
options. Commands that
|
|
33
|
-
`
|
|
34
|
-
needs the hash of a reviewed plan file
|
|
32
|
+
options. Commands that work with the database take the connection string from
|
|
33
|
+
`SIMETRA_DATABASE_URL`;
|
|
34
|
+
`apply` needs the hash of a reviewed plan file, and `roles` creates the
|
|
35
|
+
platform's cluster roles once, before the first `plan`.
|
|
36
|
+
|
|
37
|
+
## Start a project
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
pnpm add simetra
|
|
41
|
+
pnpm add -D @simetrajs/designer
|
|
42
|
+
pnpm exec simetra init [--agents claude,codex,cursor,vscode]
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
`init` is idempotent and writes only inside the project:
|
|
46
|
+
|
|
47
|
+
- relative symlinks `.agents/skills/<skill>` and `.claude/skills/<skill>` to
|
|
48
|
+
the skills in `node_modules/@simetrajs/designer/skills/`, so an update of
|
|
49
|
+
the package updates the skills too (on Windows, junctions; a git checkout
|
|
50
|
+
without `core.symlinks` turns the committed links into files, and `init`
|
|
51
|
+
replaces them with junctions);
|
|
52
|
+
- the MCP server entry `simetra` for each agent in `--agents` (default:
|
|
53
|
+
`claude`): `.mcp.json`, `.codex/config.toml` (`[mcp_servers.simetra]`),
|
|
54
|
+
`.cursor/mcp.json` or `.vscode/mcp.json`. The server starts as
|
|
55
|
+
`node <path to the installed bin> mcp`.
|
|
56
|
+
|
|
57
|
+
Another directory or link with the same skill name, and another `simetra`
|
|
58
|
+
entry in a config, stay as they are; `init` prints a note. `init --dry-run`
|
|
59
|
+
prints the changes without writing; `init --check` exits with code 1 if
|
|
60
|
+
`init` would change anything. If `init` refuses, it writes nothing; an I/O
|
|
61
|
+
failure in the middle of writing may leave part of the changes done, and
|
|
62
|
+
running `init` again completes them.
|
|
63
|
+
|
|
64
|
+
Commit the links and the configs, and run `simetra init --check` in CI with
|
|
65
|
+
the same `--agents`. The server writes metadata by default; to forbid writes,
|
|
66
|
+
add `--read-only` to the `args` of the entry by hand. Codex reads
|
|
67
|
+
`.codex/config.toml` only in a trusted project. In a monorepo, run `init` in
|
|
68
|
+
the root the agent starts from, where the `metadata` directory lives.
|
|
35
69
|
|
|
36
70
|
## Agent skills
|
|
37
71
|
|
|
38
72
|
The package ships skills for AI agents working in a Simetra project under
|
|
39
73
|
`skills/`: `simetra-metadata` (editing metadata through the tools) and
|
|
40
74
|
`simetra-adoption` (bringing an existing database under metadata). They
|
|
41
|
-
match the installed version of the tools.
|
|
75
|
+
match the installed version of the tools. `simetra init` links them into the
|
|
76
|
+
project for the agents.
|
|
42
77
|
|
|
43
78
|
## License
|
|
44
79
|
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { a as
|
|
2
|
+
import { a as invoke, c as summarizeData, d as writeChanges, f as checkEnvName, h as databaseResource, i as renderPlan, m as parseDataLaunch, n as renderApply, p as dataResource, r as renderDiff, s as toolByName, t as formatDiagnostics, u as isMetadataFile } from "./report-DV4deFdu.js";
|
|
3
|
+
import { i as DEFAULT_DATABASE_URL_ENV, n as trimSlash, p as UsageError, t as DEFAULT_DIR } from "./default-dir-DerxTbci.js";
|
|
3
4
|
import { defineCommand } from "citty";
|
|
4
5
|
import { mkdtemp, readdir, rm, stat } from "node:fs/promises";
|
|
5
6
|
import { basename, dirname, join, resolve } from "node:path";
|
|
6
7
|
import { ATTRIBUTE_CASES, DATABASE_PROVIDERS, METADATA_KINDS } from "simetra/model";
|
|
7
8
|
import { DEFAULT_APPLY_TIMEOUTS, renderDesiredState } from "simetra/schema";
|
|
8
|
-
import { canonicalSnapshot, emitEntityTypes } from "simetra/compiler";
|
|
9
|
+
import { buildRuntimeCatalog, canonicalSnapshot, emitEntityTypes } from "simetra/compiler";
|
|
9
10
|
import { spawn } from "node:child_process";
|
|
10
11
|
import { tmpdir } from "node:os";
|
|
11
|
-
|
|
12
|
+
// src/tools/artifacts.ts
|
|
12
13
|
/**
|
|
13
14
|
* Артефакти компіляції як зміни файлів: рішення, куди й чи писати, ухвалює
|
|
14
15
|
* адаптер (`compile --out`), тут лише вміст.
|
|
@@ -26,11 +27,14 @@ function compileArtifacts(model) {
|
|
|
26
27
|
{
|
|
27
28
|
path: "entities.d.ts",
|
|
28
29
|
content: emitEntityTypes(model)
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
path: "runtime-catalog.json",
|
|
33
|
+
content: `${JSON.stringify(buildRuntimeCatalog(model), null, 2)}\n`
|
|
29
34
|
}
|
|
30
35
|
];
|
|
31
36
|
}
|
|
32
|
-
|
|
33
|
-
//#region src/cli/metadata-dirs.ts
|
|
37
|
+
// src/cli/metadata-dirs.ts
|
|
34
38
|
const PROJECT_FILE = "project.meta.json";
|
|
35
39
|
function git(cwd, args, input) {
|
|
36
40
|
return new Promise((resolve, reject) => {
|
|
@@ -205,8 +209,7 @@ async function readHeadMetadata(cwd, dir) {
|
|
|
205
209
|
const texts = entries.length === 0 ? [] : await readBlobs(at, entries.map((e) => e.sha));
|
|
206
210
|
return new Map(entries.map((e, i) => [e.key, texts[i] ?? ""]));
|
|
207
211
|
}
|
|
208
|
-
|
|
209
|
-
//#region src/cli/input.ts
|
|
212
|
+
// src/cli/input.ts
|
|
210
213
|
/**
|
|
211
214
|
* Читальні інструменти й `fix` мають зручні позиційні форми — це лише вигляд
|
|
212
215
|
* над тим самим входом каталогу. Усі інші беруть вхід каталогу як JSON.
|
|
@@ -218,7 +221,8 @@ const ERGONOMIC = /* @__PURE__ */ new Set([
|
|
|
218
221
|
"introspect",
|
|
219
222
|
"diff",
|
|
220
223
|
"plan",
|
|
221
|
-
"apply"
|
|
224
|
+
"apply",
|
|
225
|
+
"roles"
|
|
222
226
|
]);
|
|
223
227
|
/** `a,b` → `["a", "b"]`; порожні елементи — помилка написання, не фільтр. */
|
|
224
228
|
function list(flag, value) {
|
|
@@ -276,7 +280,7 @@ async function cliInput(tool, args, stdin) {
|
|
|
276
280
|
input: args.tables === void 0 ? {} : { tables: list("tables", args.tables) },
|
|
277
281
|
dirs: [trimSlash(positional[0] ?? "./metadata")]
|
|
278
282
|
};
|
|
279
|
-
if (tool.name === "plan") return {
|
|
283
|
+
if (tool.name === "plan" || tool.name === "roles") return {
|
|
280
284
|
input: {},
|
|
281
285
|
dirs: [trimSlash(positional[0] ?? "./metadata")]
|
|
282
286
|
};
|
|
@@ -313,8 +317,7 @@ async function cliInput(tool, args, stdin) {
|
|
|
313
317
|
dirs: [trimSlash(rest[0] ?? "./metadata")]
|
|
314
318
|
};
|
|
315
319
|
}
|
|
316
|
-
|
|
317
|
-
//#region src/cli/render.ts
|
|
320
|
+
// src/cli/render.ts
|
|
318
321
|
/** Текст пояснення об'єкта для терміналу; JSON-вигляд друкується як є. */
|
|
319
322
|
function renderExplanation(e) {
|
|
320
323
|
const lines = [`${e.object.kind} ${e.object.name} (${e.object.file})`];
|
|
@@ -401,6 +404,34 @@ function renderResult(tool, r, o) {
|
|
|
401
404
|
written: r.written
|
|
402
405
|
}) : renderApply(r.data, r.diagnostics, report) };
|
|
403
406
|
}
|
|
407
|
+
if (tool.name === "roles" && r.data !== void 0) {
|
|
408
|
+
const { roles, skipped } = r.data;
|
|
409
|
+
return { stdout: o.format === "json" ? JSON.stringify({
|
|
410
|
+
ok: r.ok,
|
|
411
|
+
roles,
|
|
412
|
+
skipped,
|
|
413
|
+
diagnostics: JSON.parse(report)
|
|
414
|
+
}, null, 2) : [
|
|
415
|
+
...roles.map((x) => `${x.server}: ${x.name} ${x.outcome}`),
|
|
416
|
+
...skipped.map((x) => `target: ${x.name} skipped: the directory has no project.meta.json, so database.provider is unknown; run roles in a metadata directory with a project file to create it`),
|
|
417
|
+
...r.diagnostics.length > 0 ? [report] : []
|
|
418
|
+
].join("\n") };
|
|
419
|
+
}
|
|
420
|
+
if (tool.name === "rights-maintenance" && r.data !== void 0) {
|
|
421
|
+
const done = r.data;
|
|
422
|
+
return { stdout: o.format === "json" ? JSON.stringify({
|
|
423
|
+
ok: r.ok,
|
|
424
|
+
...done,
|
|
425
|
+
diagnostics: JSON.parse(report)
|
|
426
|
+
}, null, 2) : `assigned ${done.assignment}${done.member === void 0 ? "" : ` to member ${done.member}`}` };
|
|
427
|
+
}
|
|
428
|
+
if ((tool.name === "data-read" || tool.name === "data-command") && r.data !== void 0) {
|
|
429
|
+
const data = r.data;
|
|
430
|
+
return { stdout: o.format === "json" ? JSON.stringify({
|
|
431
|
+
ok: r.ok,
|
|
432
|
+
...data
|
|
433
|
+
}, null, 2) : summarizeData(tool.name, data) };
|
|
434
|
+
}
|
|
404
435
|
if (tool.files === "read") return { stdout: report };
|
|
405
436
|
const changed = r.changes.map((c) => c.path);
|
|
406
437
|
if (o.format === "json") return { stdout: JSON.stringify({
|
|
@@ -418,8 +449,7 @@ function renderResult(tool, r, o) {
|
|
|
418
449
|
...tool.name === "promote" && r.data !== void 0 ? [renderPromotion(r.data, r.written)] : []
|
|
419
450
|
].join("\n") };
|
|
420
451
|
}
|
|
421
|
-
|
|
422
|
-
//#region src/cli/command.ts
|
|
452
|
+
// src/cli/command.ts
|
|
423
453
|
const readStdin = async () => {
|
|
424
454
|
const chunks = [];
|
|
425
455
|
for await (const chunk of process.stdin) chunks.push(chunk);
|
|
@@ -462,10 +492,18 @@ async function runTool(tool, argv, stdin = readStdin, cwd = process.cwd(), env =
|
|
|
462
492
|
} : await cliInput(tool, argv, stdin);
|
|
463
493
|
const { input } = parsed;
|
|
464
494
|
const databaseEnv = argv["database-url-env"] ?? "SIMETRA_DATABASE_URL";
|
|
495
|
+
checkEnvName("--database-url-env", databaseEnv);
|
|
496
|
+
if (argv["shadow-url-env"] !== void 0) checkEnvName("--shadow-url-env", argv["shadow-url-env"]);
|
|
465
497
|
const database = tool.database === "none" ? void 0 : databaseResource(env, {
|
|
466
498
|
url: databaseEnv,
|
|
467
499
|
...argv["shadow-url-env"] === void 0 ? {} : { shadow: argv["shadow-url-env"] }
|
|
468
500
|
});
|
|
501
|
+
const launch = tool.data === "none" ? void 0 : parseDataLaunch({
|
|
502
|
+
dataUrlEnv: argv["data-url-env"],
|
|
503
|
+
as: argv.as,
|
|
504
|
+
agent: argv.agent
|
|
505
|
+
});
|
|
506
|
+
const data = launch === void 0 ? void 0 : dataResource(env, launch);
|
|
469
507
|
let { dirs } = parsed;
|
|
470
508
|
const shown = dirs;
|
|
471
509
|
if (sweep) dirs = dirs.map((d) => resolve(cwd, d));
|
|
@@ -499,6 +537,10 @@ async function runTool(tool, argv, stdin = readStdin, cwd = process.cwd(), env =
|
|
|
499
537
|
dir,
|
|
500
538
|
readOnly: false,
|
|
501
539
|
allowDatabaseWrite: true,
|
|
540
|
+
allowDataWrite: true,
|
|
541
|
+
allowRightsWrite: argv["allow-rights-write"] === true,
|
|
542
|
+
...data === void 0 ? {} : { data },
|
|
543
|
+
...launch === void 0 ? {} : { dataEnv: launch.urlEnv },
|
|
502
544
|
dryRun: argv["dry-run"] === true,
|
|
503
545
|
confirmed: argv.yes === true,
|
|
504
546
|
channel: "cli",
|
|
@@ -552,7 +594,7 @@ function argsFor(tool) {
|
|
|
552
594
|
};
|
|
553
595
|
args.out = {
|
|
554
596
|
type: "string",
|
|
555
|
-
description: "Write snapshot.json, desired-state.sql, entities.d.ts here"
|
|
597
|
+
description: "Write snapshot.json, desired-state.sql, entities.d.ts, runtime-catalog.json here"
|
|
556
598
|
};
|
|
557
599
|
} else if (tool.name === "explain") {
|
|
558
600
|
args.target = {
|
|
@@ -627,7 +669,7 @@ function argsFor(tool) {
|
|
|
627
669
|
};
|
|
628
670
|
args.allow = {
|
|
629
671
|
type: "string",
|
|
630
|
-
description: "Comma-separated plan items to permit: step ids (s1,s2), drift, access:, delete:, remove: and repair: items (a name with a comma only via MCP)"
|
|
672
|
+
description: "Comma-separated plan items to permit: step ids (s1,s2), drift, access:, delete:, update:, remove: and repair: items (a name with a comma only via MCP)"
|
|
631
673
|
};
|
|
632
674
|
args.rehearse = {
|
|
633
675
|
type: "boolean",
|
|
@@ -653,6 +695,25 @@ function argsFor(tool) {
|
|
|
653
695
|
description: "Environment variable with a connection string to another server of the same PostgreSQL major version for the shadow database"
|
|
654
696
|
};
|
|
655
697
|
}
|
|
698
|
+
if (tool.data !== "none") {
|
|
699
|
+
args["data-url-env"] = {
|
|
700
|
+
type: "string",
|
|
701
|
+
description: "Environment variable with the connection string of the runtime login role to the development database"
|
|
702
|
+
};
|
|
703
|
+
args.as = {
|
|
704
|
+
type: "string",
|
|
705
|
+
description: "UUID of the user the command acts as, with that user's rights"
|
|
706
|
+
};
|
|
707
|
+
args.agent = {
|
|
708
|
+
type: "string",
|
|
709
|
+
description: "UUID of the agent, recorded as the act claim; it grants no rights"
|
|
710
|
+
};
|
|
711
|
+
}
|
|
712
|
+
if (tool.data === "write") args["allow-rights-write"] = {
|
|
713
|
+
type: "boolean",
|
|
714
|
+
default: false,
|
|
715
|
+
description: "Write rights catalogs and create scope roots whose creator receives a role"
|
|
716
|
+
};
|
|
656
717
|
if (tool.files === "write") args["dry-run"] = {
|
|
657
718
|
type: "boolean",
|
|
658
719
|
default: false,
|
|
@@ -701,7 +762,11 @@ function toCliArgs(args) {
|
|
|
701
762
|
allow: str(args.allow),
|
|
702
763
|
rehearse: args.rehearse === true,
|
|
703
764
|
"lock-timeout-ms": str(args["lock-timeout-ms"]),
|
|
704
|
-
"statement-timeout-ms": str(args["statement-timeout-ms"])
|
|
765
|
+
"statement-timeout-ms": str(args["statement-timeout-ms"]),
|
|
766
|
+
"data-url-env": str(args["data-url-env"]),
|
|
767
|
+
as: str(args.as),
|
|
768
|
+
agent: str(args.agent),
|
|
769
|
+
"allow-rights-write": args["allow-rights-write"] === true
|
|
705
770
|
};
|
|
706
771
|
}
|
|
707
772
|
/** Підкоманда з запису каталогу: опис, прапорці й дозволи беруться з нього. */
|
|
@@ -726,5 +791,4 @@ function commandByName(name) {
|
|
|
726
791
|
if (tool === void 0) throw new Error(`unknown tool: ${name}`);
|
|
727
792
|
return toolCommand(tool);
|
|
728
793
|
}
|
|
729
|
-
//#endregion
|
|
730
794
|
export { commandByName };
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { dirname, join, posix, relative, resolve, sep } from "node:path";
|
|
3
|
+
import { existsSync } from "node:fs";
|
|
4
|
+
// src/io/usage-error.ts
|
|
5
|
+
/**
|
|
6
|
+
* Помилка використання (немає теки, шлях поза текою): викликач може виправити
|
|
7
|
+
* її сам. Лише її `invoke` перетворює на відмову; будь-який інший виняток —
|
|
8
|
+
* баг, і він не повинен маскуватися під відмову.
|
|
9
|
+
*/
|
|
10
|
+
var UsageError = class extends Error {
|
|
11
|
+
name = "UsageError";
|
|
12
|
+
};
|
|
13
|
+
// src/io/package-path.ts
|
|
14
|
+
/**
|
|
15
|
+
* Тека встановленого пакета: перший предок `fromDir` (включно) з
|
|
16
|
+
* `node_modules/<pkg>/package.json`. Шлях навмисно не проходить `realpath`:
|
|
17
|
+
* pnpm робить `node_modules/<pkg>` симлінком у сховище, а значення, що потрапляє
|
|
18
|
+
* у файли метаданих, мусить бути однаковим на кожній машині й переживати
|
|
19
|
+
* перенос репо.
|
|
20
|
+
*/
|
|
21
|
+
function installedPackageDir(fromDir, pkg) {
|
|
22
|
+
const start = resolve(fromDir);
|
|
23
|
+
let current = start;
|
|
24
|
+
for (;;) {
|
|
25
|
+
const candidate = join(current, "node_modules", pkg);
|
|
26
|
+
if (existsSync(join(candidate, "package.json"))) return candidate;
|
|
27
|
+
const parent = dirname(current);
|
|
28
|
+
if (parent === current) throw new UsageError(`${pkg} is not installed in node_modules above ${start}`);
|
|
29
|
+
current = parent;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Відносний шлях із роздільниками `/`: він потрапляє у файли, які комітять і
|
|
34
|
+
* читають на будь-якій ОС (`$schema`, ціль лінка скіла, шлях до бінарника в
|
|
35
|
+
* MCP-конфігу), тож форма не може залежати від машини, де його пораховано.
|
|
36
|
+
*/
|
|
37
|
+
function posixRelative(fromDir, to) {
|
|
38
|
+
return relative(fromDir, to).split(sep).join(posix.sep);
|
|
39
|
+
}
|
|
40
|
+
// src/tools/hints.ts
|
|
41
|
+
const READ_ONLY_FLAG = "--read-only";
|
|
42
|
+
const ALLOW_DATABASE_WRITE_FLAG = "--allow-database-write";
|
|
43
|
+
const ALLOW_DATA_WRITE_FLAG = "--allow-data-write";
|
|
44
|
+
const ALLOW_RIGHTS_WRITE_FLAG = "--allow-rights-write";
|
|
45
|
+
/** Типова змінна середовища з рядком підключення; ім'я фіксується при запуску. */
|
|
46
|
+
const DEFAULT_DATABASE_URL_ENV = "SIMETRA_DATABASE_URL";
|
|
47
|
+
/**
|
|
48
|
+
* Єдине джерело тексту «як увімкнути запис»: його бачить і клієнт MCP в
|
|
49
|
+
* `instructions`, і агент у відмові на запис у режимі лише читання.
|
|
50
|
+
* `launchArgs` — справжній argv запуску сервера без node і скрипта, тобто
|
|
51
|
+
* лише ХВІСТ `args` у конфігу клієнта: лаунчер (`pnpm exec simetra …`,
|
|
52
|
+
* `npx …`, обгортка) додає свої аргументи попереду. Тому підказка каже
|
|
53
|
+
* «прибери прапорець» і показує хвіст до й після, а не видає його за повний
|
|
54
|
+
* `"args"` — буквальна заміна зламала б конфіг.
|
|
55
|
+
*/
|
|
56
|
+
function readOnlyHint(launchArgs = [
|
|
57
|
+
"simetra",
|
|
58
|
+
"mcp",
|
|
59
|
+
READ_ONLY_FLAG
|
|
60
|
+
]) {
|
|
61
|
+
const before = launchArgs.includes("--read-only") ? launchArgs : [...launchArgs, READ_ONLY_FLAG];
|
|
62
|
+
const after = before.filter((a) => a !== READ_ONLY_FLAG);
|
|
63
|
+
return [
|
|
64
|
+
`This server runs with ${READ_ONLY_FLAG}: tools that write are disabled.`,
|
|
65
|
+
`To enable them, remove ${READ_ONLY_FLAG} from this server's args in the MCP client config and restart it:`,
|
|
66
|
+
`args ending in ${JSON.stringify(before)} become ${JSON.stringify(after)}.`
|
|
67
|
+
].join(" ");
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Підказка відмови `apply` без прапорця запису в базу і її ж речення в
|
|
71
|
+
* `instructions`. Як і `readOnlyHint`, показує лише хвіст `args`: прапорець
|
|
72
|
+
* додається, а не замінює конфіг. Вмикає його людина, а не агент: запис у
|
|
73
|
+
* базу поза git, тож рішення — при запуску сервера.
|
|
74
|
+
*/
|
|
75
|
+
function databaseWriteHint(launchArgs = ["simetra", "mcp"], o = {}) {
|
|
76
|
+
const before = launchArgs.filter((a) => a !== ALLOW_DATABASE_WRITE_FLAG);
|
|
77
|
+
const after = [...before, ALLOW_DATABASE_WRITE_FLAG];
|
|
78
|
+
return [
|
|
79
|
+
`This server runs without ${ALLOW_DATABASE_WRITE_FLAG}: ${o.tools ?? "apply"} cannot write to the database.`,
|
|
80
|
+
`Only the owner may enable it: add ${ALLOW_DATABASE_WRITE_FLAG} to this server's args in the MCP client config and restart it:`,
|
|
81
|
+
`args ending in ${JSON.stringify(before)} become ${JSON.stringify(after)}.`,
|
|
82
|
+
...o.refusal === false ? [] : ["Nothing changed."]
|
|
83
|
+
].join(" ");
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Називає лише змінну, ніколи її значення: рядок підключення несе
|
|
87
|
+
* користувача й пароль, а відмова йде агентові й у журнали клієнта.
|
|
88
|
+
* Середовище команди задає сам викликач перед наступним запуском, а
|
|
89
|
+
* середовище MCP-сервера фіксується при його старті — звідси дві поради.
|
|
90
|
+
*/
|
|
91
|
+
function noDatabaseHint(envName, channel) {
|
|
92
|
+
const how = channel === "cli" ? `Export the environment variable ${envName} with the connection string of the target database, or name another variable with --database-url-env.` : `Set the environment variable ${envName} to the connection string of the target database in this server's environment and restart the server.`;
|
|
93
|
+
return [
|
|
94
|
+
`This tool needs a database connection, and ${channel === "cli" ? "none is configured" : "the server has none"}.`,
|
|
95
|
+
how,
|
|
96
|
+
"Nothing changed."
|
|
97
|
+
].join(" ");
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Підказка відмови запису даних без прапорця і її речення в `instructions`.
|
|
101
|
+
* Окремий прапорець від запису в базу: засів тестових даних не дає права
|
|
102
|
+
* змінювати схему, і навпаки. Форма — як `databaseWriteHint`: хвіст `args`
|
|
103
|
+
* до й після.
|
|
104
|
+
*/
|
|
105
|
+
function dataWriteHint(launchArgs = ["simetra", "mcp"], o = {}) {
|
|
106
|
+
const before = launchArgs.filter((a) => a !== ALLOW_DATA_WRITE_FLAG);
|
|
107
|
+
const after = [...before, ALLOW_DATA_WRITE_FLAG];
|
|
108
|
+
return [
|
|
109
|
+
`This server runs without ${ALLOW_DATA_WRITE_FLAG}: ${o.tools ?? "data-command"} cannot change application data.`,
|
|
110
|
+
`Only the owner may enable it: add ${ALLOW_DATA_WRITE_FLAG} to this server's args in the MCP client config and restart it:`,
|
|
111
|
+
`args ending in ${JSON.stringify(before)} become ${JSON.stringify(after)}.`,
|
|
112
|
+
...o.refusal === false ? [] : ["Nothing changed."]
|
|
113
|
+
].join(" ");
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Відмова запису прав без прапорця. Довідники прав (і створення кореня
|
|
117
|
+
* скоупу, творець якого отримує роль) змінюють, хто що може, тож їх вмикає
|
|
118
|
+
* людина окремим прапорцем навіть там, де запис даних уже дозволено. CLI
|
|
119
|
+
* радить прапорець команди, MCP — прапорець запуску сервера.
|
|
120
|
+
*/
|
|
121
|
+
function rightsWriteHint(launchArgs = ["simetra", "mcp"], channel = "mcp") {
|
|
122
|
+
const what = "This operation changes rights: it writes a rights catalog (roles or role assignments) or creates a scope root whose creator receives a role.";
|
|
123
|
+
if (channel === "cli") return [
|
|
124
|
+
what,
|
|
125
|
+
`Run the command again with ${ALLOW_RIGHTS_WRITE_FLAG} if you mean to change rights.`,
|
|
126
|
+
"Nothing changed."
|
|
127
|
+
].join(" ");
|
|
128
|
+
const before = launchArgs.filter((a) => a !== ALLOW_RIGHTS_WRITE_FLAG);
|
|
129
|
+
const after = [...before, ALLOW_RIGHTS_WRITE_FLAG];
|
|
130
|
+
return [
|
|
131
|
+
what,
|
|
132
|
+
`This server runs without ${ALLOW_RIGHTS_WRITE_FLAG}. Only the owner may enable it: add ${ALLOW_RIGHTS_WRITE_FLAG} to this server's args in the MCP client config and restart it:`,
|
|
133
|
+
`args ending in ${JSON.stringify(before)} become ${JSON.stringify(after)}.`,
|
|
134
|
+
"Nothing changed."
|
|
135
|
+
].join(" ");
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Відмова без ресурсу даних. Як і `noDatabaseHint`, називає лише змінну,
|
|
139
|
+
* ніколи її значення. Типової змінної немає: доступ від імені користувача —
|
|
140
|
+
* явне рішення людини (`--data-url-env` і `--as`), тож без імені підказка
|
|
141
|
+
* називає обидва прапорці, а з іменем — порожню змінну.
|
|
142
|
+
*/
|
|
143
|
+
function noDataHint(envName, channel) {
|
|
144
|
+
const flags = "--data-url-env <name of the environment variable with the connection string of the runtime login role> and --as <user uuid>";
|
|
145
|
+
let how;
|
|
146
|
+
if (envName === void 0) how = channel === "cli" ? `Pass ${flags}.` : `Add ${flags} to this server's args in the MCP client config and restart it.`;
|
|
147
|
+
else how = channel === "cli" ? `The environment variable ${envName} is empty: export it with the connection string of the development database.` : `The environment variable ${envName} is empty: set it to the connection string of the development database in this server's environment and restart the server.`;
|
|
148
|
+
return [
|
|
149
|
+
`This tool needs access to the development database data, and ${channel === "cli" ? "none is configured" : "the server has none"}.`,
|
|
150
|
+
how,
|
|
151
|
+
"Nothing changed."
|
|
152
|
+
].join(" ");
|
|
153
|
+
}
|
|
154
|
+
// src/io/default-dir.ts
|
|
155
|
+
/** Тека метаданих за замовчуванням — спільна для CLI і `simetra mcp`. */
|
|
156
|
+
const DEFAULT_DIR = "./metadata";
|
|
157
|
+
const trimSlash = (d) => d.replace(/(?<=.)[\\/]+$/, "");
|
|
158
|
+
export { dataWriteHint as a, noDatabaseHint as c, installedPackageDir as d, posixRelative as f, DEFAULT_DATABASE_URL_ENV as i, readOnlyHint as l, trimSlash as n, databaseWriteHint as o, UsageError as p, ALLOW_RIGHTS_WRITE_FLAG as r, noDataHint as s, DEFAULT_DIR as t, rightsWriteHint as u };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
// src/schema-engine/errors.ts
|
|
3
3
|
/**
|
|
4
4
|
* Помилки адаптера, які межа підключення (`io/database.ts`) розпізнає за
|
|
5
5
|
* класом. Окремий модуль без `pg` і pg-delta: межу імпортує кожен виклик
|
|
@@ -32,5 +32,4 @@ var ShadowServerError = class extends Error {
|
|
|
32
32
|
this.onShadowBase = onShadowBase;
|
|
33
33
|
}
|
|
34
34
|
};
|
|
35
|
-
//#endregion
|
|
36
35
|
export { ShadowServerError as n, ShadowServerMismatchError as r, ShadowCreateRefusedError as t };
|