@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/dist/main.js CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
- import { t as version } from "./package-DDuGk6yE.js";
3
- import { n as TOOL_NAMES } from "./types-CSc8XWLd.js";
2
+ import { t as version } from "./package-Dg3MXPve.js";
3
+ import { n as TOOL_NAMES } from "./types-iWavtmdS.js";
4
4
  import { defineCommand, runCommand, runMain, showUsage } from "citty";
5
- //#region src/main.ts
5
+ // src/main.ts
6
6
  const main = defineCommand({
7
7
  meta: {
8
8
  name: "simetra",
@@ -10,8 +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-CRUaUglx.js").then((m) => m.commandByName(name))])),
14
- mcp: () => import("./mcp-CJDCleh-.js").then((m) => m.default)
13
+ ...Object.fromEntries(TOOL_NAMES.map((name) => [name, () => import("./command-BCAw6Fsb.js").then((m) => m.commandByName(name))])),
14
+ mcp: () => import("./mcp-ChltmHBb.js").then((m) => m.default),
15
+ init: () => import("./init-jr0Xsrpp.js").then((m) => m.default)
15
16
  }
16
17
  });
17
18
  const rawArgs = process.argv.slice(2);
@@ -25,5 +26,4 @@ else try {
25
26
  } else console.error(error);
26
27
  process.exitCode = 2;
27
28
  }
28
- //#endregion
29
29
  export {};
@@ -1,11 +1,13 @@
1
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";
2
+ import { a as invoke, c as summarizeData, f as checkEnvName, h as databaseResource, i as renderPlan, l as toJson, m as parseDataLaunch, n as renderApply, o as TOOLS, p as dataResource, r as renderDiff, t as formatDiagnostics } from "./report-DV4deFdu.js";
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-Dg3MXPve.js";
5
+ import { t as mcpArgs } from "./mcp-args-D63akJ97.js";
4
6
  import { defineCommand } from "citty";
5
7
  import { z } from "zod";
6
8
  import { StdioServerTransport } from "@modelcontextprotocol/server/stdio";
7
9
  import { McpServer } from "@modelcontextprotocol/server";
8
- //#region src/mcp/tools.ts
10
+ // src/mcp/tools.ts
9
11
  const dryRun = z.boolean().optional().meta({ description: "Report the changes without writing them." });
10
12
  const confirm = z.boolean().optional().meta({ description: "Must be true to actually perform a destructive change." });
11
13
  /**
@@ -21,6 +23,7 @@ function mcpInputSchema(tool) {
21
23
  break;
22
24
  case "write": previews = true;
23
25
  }
26
+ if (tool.cliOnly) return tool.input;
24
27
  if (!previews && !tool.destructive) return tool.input;
25
28
  if (!(tool.input instanceof z.ZodObject)) throw new Error(`tool ${tool.name} needs an object input for dryRun/confirm`);
26
29
  return tool.input.extend({
@@ -40,13 +43,32 @@ function toResponse(tool, result, o, dry) {
40
43
  ok,
41
44
  written,
42
45
  changes,
43
- diagnostics
46
+ diagnostics,
47
+ refusal: {
48
+ reason: refusal.reason,
49
+ ...refusal.detail === void 0 ? {} : { detail: refusal.detail }
50
+ }
44
51
  },
45
52
  content: [{
46
53
  type: "text",
47
54
  text: refusal.message
48
55
  }]
49
56
  };
57
+ if ((tool.name === "data-read" || tool.name === "data-command") && result.data !== void 0) {
58
+ const data = result.data;
59
+ return {
60
+ isError: !ok,
61
+ structuredContent: {
62
+ ok,
63
+ diagnostics,
64
+ ...toJson(data)
65
+ },
66
+ content: [{
67
+ type: "text",
68
+ text: summarizeData(tool.name, data)
69
+ }]
70
+ };
71
+ }
50
72
  if (tool.name === "explain" && ok && result.data !== void 0) return {
51
73
  structuredContent: { ...result.data },
52
74
  content: [{
@@ -142,31 +164,37 @@ function toResponse(tool, result, o, dry) {
142
164
  }
143
165
  /** Реєструє весь каталог: транспорт лише переказує `confirm`/`dryRun` у `invoke`. */
144
166
  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
167
+ for (const tool of TOOLS) {
168
+ if (tool.cliOnly) continue;
169
+ server.registerTool(tool.name, {
170
+ description: tool.description,
171
+ inputSchema: mcpInputSchema(tool),
172
+ annotations: {
173
+ readOnlyHint: tool.files === "read" && tool.database !== "write" && tool.data !== "write",
174
+ destructiveHint: tool.destructive || tool.data === "write"
175
+ }
176
+ }, async (args) => {
177
+ const { dryRun: dry, confirm: confirmed, ...input } = args ?? {};
178
+ const result = await invoke(tool, input, {
179
+ dir: o.dir,
180
+ readOnly: o.readOnly,
181
+ allowDatabaseWrite: o.allowDatabaseWrite === true,
182
+ allowDataWrite: o.allowDataWrite === true,
183
+ allowRightsWrite: o.allowRightsWrite === true,
184
+ dryRun: dry === true,
185
+ confirmed: confirmed === true,
186
+ channel: "mcp",
187
+ database: o.database,
188
+ ...o.databaseEnv === void 0 ? {} : { databaseEnv: o.databaseEnv },
189
+ ...o.data === void 0 ? {} : { data: o.data },
190
+ ...o.dataEnv === void 0 ? {} : { dataEnv: o.dataEnv },
191
+ launchArgs: o.launchArgs
192
+ });
193
+ return toResponse(tool, result, o, dry === true);
164
194
  });
165
- return toResponse(tool, result, o, dry === true);
166
- });
195
+ }
167
196
  }
168
- //#endregion
169
- //#region src/mcp/server.ts
197
+ // src/mcp/server.ts
170
198
  /**
171
199
  * Сервер не знає транспорту: stdio підключає команда, тести — пару в пам'яті.
172
200
  * Інструменти запису видно завжди: з `--read-only` вони відмовляють із
@@ -177,8 +205,12 @@ function createMcpServer(o) {
177
205
  const instructions = [
178
206
  `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
207
  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."
208
+ ...o.readOnly ? [] : [o.allowDatabaseWrite === true ? "Database writes are enabled: apply needs confirm: true and the planHash of the plan you showed." : databaseWriteHint(o.launchArgs, {
209
+ refusal: false,
210
+ tools: "apply and roles"
211
+ })],
212
+ "dryRun does not apply to apply: review with plan, and rehearse it before applying.",
213
+ ...o.data === void 0 ? [] : [`Data tools act as user ${o.data.as} on ${o.data.describe}, with that user's rights.`, ...o.readOnly ? [] : [...o.allowDataWrite === true ? [] : [dataWriteHint(o.launchArgs, { refusal: false })], ...o.allowRightsWrite === true ? [] : [`Rights catalogs and creating a scope root whose creator receives a role are closed: data-command refuses them without ${ALLOW_RIGHTS_WRITE_FLAG}.`]]]
182
214
  ].join(" ");
183
215
  const server = new McpServer({
184
216
  name: "simetra",
@@ -187,55 +219,59 @@ function createMcpServer(o) {
187
219
  registerCatalog(server, o);
188
220
  return server;
189
221
  }
190
- //#endregion
191
- //#region src/commands/mcp.ts
222
+ // src/commands/mcp.ts
223
+ /**
224
+ * Опції сервера з argv і середовища запуску — чиста функція, щоб умови
225
+ * запуску перевірялися без stdio. Імена змінних фіксуються тут: агент не
226
+ * може спрямувати виклик на іншу базу чи діяти від чужого імені, а відмова
227
+ * без підключення називає саме цю змінну. Ім'я перевіряється до будь-якого
228
+ * тексту: підказки й `instructions` повторюють argv, тож рядок підключення,
229
+ * переданий замість імені, потрапив би агентові.
230
+ */
231
+ function mcpOptionsFrom(args, env, argv) {
232
+ const databaseEnv = args["database-url-env"];
233
+ const shadow = args["shadow-url-env"];
234
+ checkEnvName("--database-url-env", databaseEnv);
235
+ if (shadow !== void 0) checkEnvName("--shadow-url-env", shadow);
236
+ const launch = parseDataLaunch({
237
+ dataUrlEnv: args["data-url-env"],
238
+ as: args.as,
239
+ agent: args.agent
240
+ });
241
+ const data = launch === void 0 ? void 0 : dataResource(env, launch);
242
+ return {
243
+ dir: trimSlash(args.dir ?? "./metadata"),
244
+ readOnly: args["read-only"],
245
+ allowDatabaseWrite: args["allow-database-write"],
246
+ allowDataWrite: args["allow-data-write"],
247
+ allowRightsWrite: args["allow-rights-write"],
248
+ database: databaseResource(env, {
249
+ url: databaseEnv,
250
+ ...shadow === void 0 ? {} : { shadow }
251
+ }),
252
+ databaseEnv,
253
+ ...data === void 0 ? {} : { data },
254
+ ...launch === void 0 ? {} : { dataEnv: launch.urlEnv },
255
+ launchArgs: argv
256
+ };
257
+ }
192
258
  var mcp_default = defineCommand({
193
259
  meta: {
194
260
  name: "mcp",
195
261
  description: "Serve the compiler operations over MCP (stdio)"
196
262
  },
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
- },
263
+ args: mcpArgs,
223
264
  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());
265
+ let options;
266
+ try {
267
+ options = mcpOptionsFrom(args, process.env, process.argv.slice(2));
268
+ } catch (error) {
269
+ if (!(error instanceof UsageError)) throw error;
270
+ process.stderr.write(`error: ${error.message}\n`);
271
+ process.exitCode = 2;
272
+ return;
273
+ }
274
+ await createMcpServer(options).connect(new StdioServerTransport());
238
275
  }
239
276
  });
240
- //#endregion
241
277
  export { mcp_default as default };
@@ -0,0 +1,56 @@
1
+ #!/usr/bin/env node
2
+ import { i as DEFAULT_DATABASE_URL_ENV } from "./default-dir-DerxTbci.js";
3
+ // src/commands/mcp-args.ts
4
+ /**
5
+ * Аргументи `simetra mcp` окремим легким модулем: за цим же описом `init`
6
+ * розбирає `args` записів MCP-конфігів, і йому не треба тягнути сервер.
7
+ */
8
+ const mcpArgs = {
9
+ dir: {
10
+ type: "positional",
11
+ description: "Metadata directory (default: ./metadata)",
12
+ required: false
13
+ },
14
+ "read-only": {
15
+ type: "boolean",
16
+ default: false,
17
+ description: "Refuse the tools that write"
18
+ },
19
+ "allow-database-write": {
20
+ type: "boolean",
21
+ default: false,
22
+ description: "Let apply write to the database (it still needs confirm and the plan hash)"
23
+ },
24
+ "database-url-env": {
25
+ type: "string",
26
+ default: DEFAULT_DATABASE_URL_ENV,
27
+ description: "Environment variable with the connection string of the target database"
28
+ },
29
+ "shadow-url-env": {
30
+ type: "string",
31
+ description: "Environment variable with a connection string to another server of the same PostgreSQL major version for the shadow database"
32
+ },
33
+ "data-url-env": {
34
+ type: "string",
35
+ description: "Environment variable with the connection string of the runtime login role to the development database; enables the data tools together with --as"
36
+ },
37
+ as: {
38
+ type: "string",
39
+ description: "UUID of the user the data tools act as, with that user's rights"
40
+ },
41
+ agent: {
42
+ type: "string",
43
+ description: "UUID of the agent, recorded as the act claim; it grants no rights"
44
+ },
45
+ "allow-data-write": {
46
+ type: "boolean",
47
+ default: false,
48
+ description: "Let data-command change application data"
49
+ },
50
+ "allow-rights-write": {
51
+ type: "boolean",
52
+ default: false,
53
+ description: "Let data-command write rights catalogs and create scope roots whose creator receives a role"
54
+ }
55
+ };
56
+ export { mcpArgs as t };
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+ // package.json
3
+ var version = "0.2.0";
4
+ export { version as t };