@simetrajs/designer 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +190 -0
- package/README.md +44 -2
- package/dist/command-CRUaUglx.js +730 -0
- package/dist/errors-D5pJLrjP.js +36 -0
- package/dist/main.js +29 -0
- package/dist/mcp-CJDCleh-.js +241 -0
- package/dist/package-DDuGk6yE.js +5 -0
- package/dist/report-D2jBS_04.js +1550 -0
- package/dist/schema-engine-DAsJEc8K.js +2805 -0
- package/dist/types-CSc8XWLd.js +28 -0
- package/package.json +66 -3
- package/skills/simetra-adoption/SKILL.md +171 -0
- package/skills/simetra-metadata/SKILL.md +491 -0
- package/skills/simetra-metadata/references/people-and-rights.md +156 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
//#region src/schema-engine/errors.ts
|
|
3
|
+
/**
|
|
4
|
+
* Помилки адаптера, які межа підключення (`io/database.ts`) розпізнає за
|
|
5
|
+
* класом. Окремий модуль без `pg` і pg-delta: межу імпортує кожен виклик
|
|
6
|
+
* CLI, а двигун вантажиться лише інструментом бази.
|
|
7
|
+
*/
|
|
8
|
+
/** Тінь на сервері іншої мажорної версії: каталоги двох версій не порівнюються. */
|
|
9
|
+
var ShadowServerMismatchError = class extends Error {
|
|
10
|
+
name = "ShadowServerMismatchError";
|
|
11
|
+
};
|
|
12
|
+
/** Роль підключення не має `CREATEDB` на сервері, де мала б з'явитися тінь. */
|
|
13
|
+
var ShadowCreateRefusedError = class extends Error {
|
|
14
|
+
onShadowBase;
|
|
15
|
+
name = "ShadowCreateRefusedError";
|
|
16
|
+
constructor(onShadowBase) {
|
|
17
|
+
super("the connecting role lacks CREATEDB");
|
|
18
|
+
this.onShadowBase = onShadowBase;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Збій створення тіні чи підключення до неї з причиною, якої адаптер не
|
|
23
|
+
* розпізнав: причина — у `cause`. Межа описує її адресою сервера, де мала
|
|
24
|
+
* з'явитися тінь, і називає вимогу тіні до режиму з'єднання (спека designer
|
|
25
|
+
* §3.2).
|
|
26
|
+
*/
|
|
27
|
+
var ShadowServerError = class extends Error {
|
|
28
|
+
onShadowBase;
|
|
29
|
+
name = "ShadowServerError";
|
|
30
|
+
constructor(cause, onShadowBase) {
|
|
31
|
+
super("the shadow could not be created or reached", { cause });
|
|
32
|
+
this.onShadowBase = onShadowBase;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
//#endregion
|
|
36
|
+
export { ShadowServerError as n, ShadowServerMismatchError as r, ShadowCreateRefusedError as t };
|
package/dist/main.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { t as version } from "./package-DDuGk6yE.js";
|
|
3
|
+
import { n as TOOL_NAMES } from "./types-CSc8XWLd.js";
|
|
4
|
+
import { defineCommand, runCommand, runMain, showUsage } from "citty";
|
|
5
|
+
//#region src/main.ts
|
|
6
|
+
const main = defineCommand({
|
|
7
|
+
meta: {
|
|
8
|
+
name: "simetra",
|
|
9
|
+
version,
|
|
10
|
+
description: "Simetra metadata tooling"
|
|
11
|
+
},
|
|
12
|
+
subCommands: {
|
|
13
|
+
...Object.fromEntries(TOOL_NAMES.map((name) => [name, () => import("./command-CRUaUglx.js").then((m) => m.commandByName(name))])),
|
|
14
|
+
mcp: () => import("./mcp-CJDCleh-.js").then((m) => m.default)
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
const rawArgs = process.argv.slice(2);
|
|
18
|
+
if (rawArgs.some((a) => a === "--help" || a === "-h" || a === "--version")) runMain(main);
|
|
19
|
+
else try {
|
|
20
|
+
await runCommand(main, { rawArgs });
|
|
21
|
+
} catch (error) {
|
|
22
|
+
if (error instanceof Error && error.name === "CLIError") {
|
|
23
|
+
await showUsage(main);
|
|
24
|
+
console.error(error.message);
|
|
25
|
+
} else console.error(error);
|
|
26
|
+
process.exitCode = 2;
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { t as version } from "./package-DDuGk6yE.js";
|
|
3
|
+
import { c as DEFAULT_DATABASE_URL_ENV, d as TOOLS, h as databaseResource, i as renderPlan, l as databaseWriteHint, n as renderApply, o as trimSlash, r as renderDiff, s as invoke, t as formatDiagnostics, u as readOnlyHint } from "./report-D2jBS_04.js";
|
|
4
|
+
import { defineCommand } from "citty";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
import { StdioServerTransport } from "@modelcontextprotocol/server/stdio";
|
|
7
|
+
import { McpServer } from "@modelcontextprotocol/server";
|
|
8
|
+
//#region src/mcp/tools.ts
|
|
9
|
+
const dryRun = z.boolean().optional().meta({ description: "Report the changes without writing them." });
|
|
10
|
+
const confirm = z.boolean().optional().meta({ description: "Must be true to actually perform a destructive change." });
|
|
11
|
+
/**
|
|
12
|
+
* Схема входу MCP = вхід каталогу плюс транспортні поля. Дозвіл, підтвердження
|
|
13
|
+
* й запис вирішує `invoke`, тож тут лише перелік полів, які він отримує.
|
|
14
|
+
*/
|
|
15
|
+
function mcpInputSchema(tool) {
|
|
16
|
+
let previews;
|
|
17
|
+
switch (tool.files) {
|
|
18
|
+
case "read":
|
|
19
|
+
case "artifact":
|
|
20
|
+
previews = false;
|
|
21
|
+
break;
|
|
22
|
+
case "write": previews = true;
|
|
23
|
+
}
|
|
24
|
+
if (!previews && !tool.destructive) return tool.input;
|
|
25
|
+
if (!(tool.input instanceof z.ZodObject)) throw new Error(`tool ${tool.name} needs an object input for dryRun/confirm`);
|
|
26
|
+
return tool.input.extend({
|
|
27
|
+
...previews ? { dryRun } : {},
|
|
28
|
+
...tool.destructive ? { confirm } : {}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
function lineFor(c, written) {
|
|
32
|
+
if (written) return `${c.deleted ? "deleted" : "written"} ${c.path}`;
|
|
33
|
+
return `${c.deleted ? "would delete" : "would write"} ${c.path}`;
|
|
34
|
+
}
|
|
35
|
+
function toResponse(tool, result, o, dry) {
|
|
36
|
+
const { ok, written, changes, diagnostics, refusal } = result;
|
|
37
|
+
if (refusal !== void 0) return {
|
|
38
|
+
isError: true,
|
|
39
|
+
structuredContent: {
|
|
40
|
+
ok,
|
|
41
|
+
written,
|
|
42
|
+
changes,
|
|
43
|
+
diagnostics
|
|
44
|
+
},
|
|
45
|
+
content: [{
|
|
46
|
+
type: "text",
|
|
47
|
+
text: refusal.message
|
|
48
|
+
}]
|
|
49
|
+
};
|
|
50
|
+
if (tool.name === "explain" && ok && result.data !== void 0) return {
|
|
51
|
+
structuredContent: { ...result.data },
|
|
52
|
+
content: [{
|
|
53
|
+
type: "text",
|
|
54
|
+
text: JSON.stringify(result.data, null, 2)
|
|
55
|
+
}]
|
|
56
|
+
};
|
|
57
|
+
const report = formatDiagnostics(diagnostics, {
|
|
58
|
+
dir: o.dir,
|
|
59
|
+
locale: "en",
|
|
60
|
+
format: "text"
|
|
61
|
+
});
|
|
62
|
+
if (tool.name === "diff" && result.data !== void 0) {
|
|
63
|
+
const data = result.data;
|
|
64
|
+
return {
|
|
65
|
+
isError: !ok,
|
|
66
|
+
structuredContent: {
|
|
67
|
+
ok,
|
|
68
|
+
written,
|
|
69
|
+
changes,
|
|
70
|
+
...data
|
|
71
|
+
},
|
|
72
|
+
content: [{
|
|
73
|
+
type: "text",
|
|
74
|
+
text: renderDiff(data, report)
|
|
75
|
+
}]
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
if (tool.name === "plan") {
|
|
79
|
+
const data = result.data;
|
|
80
|
+
return {
|
|
81
|
+
isError: !ok,
|
|
82
|
+
structuredContent: {
|
|
83
|
+
ok,
|
|
84
|
+
written,
|
|
85
|
+
artifacts: result.artifacts ?? [],
|
|
86
|
+
diagnostics,
|
|
87
|
+
...data
|
|
88
|
+
},
|
|
89
|
+
content: [{
|
|
90
|
+
type: "text",
|
|
91
|
+
text: renderPlan(data, report, {
|
|
92
|
+
ok,
|
|
93
|
+
written
|
|
94
|
+
})
|
|
95
|
+
}]
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
if (tool.name === "apply") {
|
|
99
|
+
const data = result.data;
|
|
100
|
+
return {
|
|
101
|
+
isError: !ok,
|
|
102
|
+
structuredContent: {
|
|
103
|
+
ok,
|
|
104
|
+
written,
|
|
105
|
+
artifacts: result.artifacts ?? [],
|
|
106
|
+
diagnostics,
|
|
107
|
+
...data
|
|
108
|
+
},
|
|
109
|
+
content: [{
|
|
110
|
+
type: "text",
|
|
111
|
+
text: renderApply(data, diagnostics, report)
|
|
112
|
+
}]
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
const record = tool.name === "promote" ? result.data : void 0;
|
|
116
|
+
const databaseFailed = diagnostics.some((d) => d.code === "database.failed");
|
|
117
|
+
const databaseUnreadable = diagnostics.some((d) => d.code === "engine.owner-not-member");
|
|
118
|
+
const lines = ok ? [
|
|
119
|
+
...changes.map((c) => lineFor(c, written)),
|
|
120
|
+
...dry && tool.files === "write" ? ["dry run: nothing written"] : [],
|
|
121
|
+
...tool.files === "read" ? [`${tool.name}: no errors`] : []
|
|
122
|
+
] : databaseFailed ? [`${tool.files === "write" ? "nothing written" : tool.name}: the database work failed`] : databaseUnreadable ? [`${tool.name}: the database has objects the engine cannot read`] : tool.files === "write" ? ["nothing written: the operation was refused or the result has errors"] : [`${tool.name}: the metadata has errors`];
|
|
123
|
+
return {
|
|
124
|
+
isError: !ok,
|
|
125
|
+
structuredContent: {
|
|
126
|
+
ok,
|
|
127
|
+
written,
|
|
128
|
+
changes,
|
|
129
|
+
diagnostics,
|
|
130
|
+
...tool.name === "introspect" && result.data !== void 0 ? result.data : {},
|
|
131
|
+
...record === void 0 ? {} : { record }
|
|
132
|
+
},
|
|
133
|
+
content: [{
|
|
134
|
+
type: "text",
|
|
135
|
+
text: [
|
|
136
|
+
...lines,
|
|
137
|
+
report,
|
|
138
|
+
...record === void 0 ? [] : ["promotion record:", JSON.stringify(record, null, 2)]
|
|
139
|
+
].join("\n")
|
|
140
|
+
}]
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
/** Реєструє весь каталог: транспорт лише переказує `confirm`/`dryRun` у `invoke`. */
|
|
144
|
+
function registerCatalog(server, o) {
|
|
145
|
+
for (const tool of TOOLS) server.registerTool(tool.name, {
|
|
146
|
+
description: tool.description,
|
|
147
|
+
inputSchema: mcpInputSchema(tool),
|
|
148
|
+
annotations: {
|
|
149
|
+
readOnlyHint: tool.files === "read" && tool.database !== "write",
|
|
150
|
+
destructiveHint: tool.destructive
|
|
151
|
+
}
|
|
152
|
+
}, async (args) => {
|
|
153
|
+
const { dryRun: dry, confirm: confirmed, ...input } = args ?? {};
|
|
154
|
+
const result = await invoke(tool, input, {
|
|
155
|
+
dir: o.dir,
|
|
156
|
+
readOnly: o.readOnly,
|
|
157
|
+
allowDatabaseWrite: o.allowDatabaseWrite === true,
|
|
158
|
+
dryRun: dry === true,
|
|
159
|
+
confirmed: confirmed === true,
|
|
160
|
+
channel: "mcp",
|
|
161
|
+
database: o.database,
|
|
162
|
+
...o.databaseEnv === void 0 ? {} : { databaseEnv: o.databaseEnv },
|
|
163
|
+
launchArgs: o.launchArgs
|
|
164
|
+
});
|
|
165
|
+
return toResponse(tool, result, o, dry === true);
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
//#endregion
|
|
169
|
+
//#region src/mcp/server.ts
|
|
170
|
+
/**
|
|
171
|
+
* Сервер не знає транспорту: stdio підключає команда, тести — пару в пам'яті.
|
|
172
|
+
* Інструменти запису видно завжди: з `--read-only` вони відмовляють із
|
|
173
|
+
* поясненням, а не зникають, тож агент знає, що запис існує, і що саме
|
|
174
|
+
* увімкнути.
|
|
175
|
+
*/
|
|
176
|
+
function createMcpServer(o) {
|
|
177
|
+
const instructions = [
|
|
178
|
+
`Metadata tools for the directory ${o.dir}: compile, explain, the editing tools, and introspect, diff, plan and apply against the database named by the server's environment.`,
|
|
179
|
+
o.readOnly ? readOnlyHint(o.launchArgs) : "Writing is enabled; destructive tools need confirm: true, and dryRun previews any file change.",
|
|
180
|
+
...o.readOnly ? [] : [o.allowDatabaseWrite === true ? "Database writes are enabled: apply needs confirm: true and the planHash of the plan you showed." : databaseWriteHint(o.launchArgs, { refusal: false })],
|
|
181
|
+
"dryRun does not apply to apply: review with plan, and rehearse it before applying."
|
|
182
|
+
].join(" ");
|
|
183
|
+
const server = new McpServer({
|
|
184
|
+
name: "simetra",
|
|
185
|
+
version
|
|
186
|
+
}, { instructions });
|
|
187
|
+
registerCatalog(server, o);
|
|
188
|
+
return server;
|
|
189
|
+
}
|
|
190
|
+
//#endregion
|
|
191
|
+
//#region src/commands/mcp.ts
|
|
192
|
+
var mcp_default = defineCommand({
|
|
193
|
+
meta: {
|
|
194
|
+
name: "mcp",
|
|
195
|
+
description: "Serve the compiler operations over MCP (stdio)"
|
|
196
|
+
},
|
|
197
|
+
args: {
|
|
198
|
+
dir: {
|
|
199
|
+
type: "positional",
|
|
200
|
+
description: "Metadata directory (default: ./metadata)",
|
|
201
|
+
required: false
|
|
202
|
+
},
|
|
203
|
+
"read-only": {
|
|
204
|
+
type: "boolean",
|
|
205
|
+
default: false,
|
|
206
|
+
description: "Refuse the tools that write"
|
|
207
|
+
},
|
|
208
|
+
"allow-database-write": {
|
|
209
|
+
type: "boolean",
|
|
210
|
+
default: false,
|
|
211
|
+
description: "Let apply write to the database (it still needs confirm and the plan hash)"
|
|
212
|
+
},
|
|
213
|
+
"database-url-env": {
|
|
214
|
+
type: "string",
|
|
215
|
+
default: DEFAULT_DATABASE_URL_ENV,
|
|
216
|
+
description: "Environment variable with the connection string of the target database"
|
|
217
|
+
},
|
|
218
|
+
"shadow-url-env": {
|
|
219
|
+
type: "string",
|
|
220
|
+
description: "Environment variable with a connection string to another server of the same PostgreSQL major version for the shadow database"
|
|
221
|
+
}
|
|
222
|
+
},
|
|
223
|
+
async run({ args }) {
|
|
224
|
+
const dir = trimSlash(args.dir ?? "./metadata");
|
|
225
|
+
const databaseEnv = args["database-url-env"];
|
|
226
|
+
const shadow = args["shadow-url-env"];
|
|
227
|
+
await createMcpServer({
|
|
228
|
+
dir,
|
|
229
|
+
readOnly: args["read-only"],
|
|
230
|
+
allowDatabaseWrite: args["allow-database-write"],
|
|
231
|
+
database: databaseResource(process.env, {
|
|
232
|
+
url: databaseEnv,
|
|
233
|
+
...shadow === void 0 ? {} : { shadow }
|
|
234
|
+
}),
|
|
235
|
+
databaseEnv,
|
|
236
|
+
launchArgs: process.argv.slice(2)
|
|
237
|
+
}).connect(new StdioServerTransport());
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
//#endregion
|
|
241
|
+
export { mcp_default as default };
|