@supacloud/cli 0.42.0 → 0.44.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.
Files changed (2) hide show
  1. package/dist/index.js +171 -14
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -238773,7 +238773,7 @@ var ACTION_POLICY = {
238773
238773
  database: {
238774
238774
  read: ["list_tables", "describe_columns", "list_indexes", "list_constraints", "list_extensions", "rls_status", "rls_policies", "list_auth_users", "get_auth_user", "connections", "stats", "slow_queries", "list_migrations", "migration_inventory", "project_url", "generate_types", "database_lint", "db_lint", "rpc_catalog", "list_rpcs"],
238775
238775
  local: ["lint_migrations", "lint"],
238776
- write: ["query", "apply_migration", "push_migrations", "baseline_migrations", "create_table_rls"]
238776
+ write: ["query", "execute", "apply_migration", "push_migrations", "baseline_migrations", "create_table_rls"]
238777
238777
  },
238778
238778
  supabase: {
238779
238779
  local: ["version", "migration_new", "db_diff", "db_reset", "db_pull", "db_dump", "migration_list", "gen_types"],
@@ -238837,7 +238837,7 @@ var ACTION_POLICY = {
238837
238837
  write: ["send", "receive", "ack", "release", "fail", "retry", "delete_message", "update_settings"]
238838
238838
  },
238839
238839
  ai: { local: ["show_skill", "install_skill"] },
238840
- app: { local: ["generate", "compile", "check", "graph", "explain"] },
238840
+ app: { local: ["generate", "compile", "check", "graph", "explain", "export-tools"] },
238841
238841
  db: { local: ["lint", "explain"], read: ["module_check"] },
238842
238842
  dev: { read: ["status"], write: ["sync", "watch", "migrate"] }
238843
238843
  };
@@ -240466,15 +240466,17 @@ function registerDatabaseTools(server2, http, config = {}) {
240466
240466
  "rpc_catalog",
240467
240467
  "list_rpcs"
240468
240468
  ];
240469
- const writeActions = ["apply_migration", "push_migrations", "baseline_migrations", "create_table_rls"];
240469
+ const writeActions = ["execute", "apply_migration", "push_migrations", "baseline_migrations", "create_table_rls"];
240470
240470
  const remoteActions = [...readActions, ...localActions];
240471
240471
  const allActions = localOnly ? localActions : readOnly ? remoteActions : [...remoteActions, ...writeActions];
240472
240472
  server2.tool("database", `Database operations: query, schema, RLS, migrations, stats.
240473
240473
  Actions: ${allActions.join(", ")}${localOnly ? " (local-only mode)" : readOnly ? " (read-only mode)" : ""}`, {
240474
240474
  action: withDescription(stringEnum(allActions), "Action"),
240475
240475
  ref: projectRef ? Type.Optional(Type.String()) : optional(Type.String(), "Project ref"),
240476
- sql: optional(Type.String(), "[query/apply_migration/lint_migrations/lint] SQL statement"),
240477
- file: optional(Type.String(), "[query/apply_migration/lint_migrations/lint] Read SQL from local file path (avoids shell escaping issues with $$ and multi-statement DDL)"),
240476
+ sql: optional(Type.String(), "[query/execute/apply_migration/lint_migrations/lint] SQL statement"),
240477
+ file: optional(Type.String(), "[query/execute/apply_migration/lint_migrations/lint] Read SQL from local file path (avoids shell escaping issues with $$ and multi-statement DDL)"),
240478
+ mode: optional(stringEnum(["read", "migration", "admin"]), "[query/execute] SQL execution mode: read, migration, or admin. execute defaults to migration; query defaults to read/auto"),
240479
+ admin: optional(Type.Boolean(), "[query/execute] Admin execution flag (required when mode=admin)"),
240478
240480
  dir: optional(Type.String(), "[push_migrations/baseline_migrations/lint_migrations/lint] Directory containing .sql migration files (default: supabase/migrations)"),
240479
240481
  dry_run: optional(Type.Boolean(), "[push_migrations/baseline_migrations] Preview changes without applying them"),
240480
240482
  strict: optional(Type.Boolean(), "[push_migrations/lint_migrations/lint/database_lint] Exit with error if high-risk issues or migrations are detected"),
@@ -240510,12 +240512,16 @@ Actions: ${allActions.join(", ")}${localOnly ? " (local-only mode)" : readOnly ?
240510
240512
  return { content: [{ type: "text", text: `❌ Failed to read file ${args.file}: ${e.message}` }] };
240511
240513
  }
240512
240514
  }
240513
- const execSql = async (sql, mode) => managementHttp().post(`/v1/projects/${ref}/database/sql`, mode ? { sql, mode } : { sql });
240515
+ const execSql = async (sql, mode, admin) => managementHttp().post(`/v1/projects/${ref}/database/sql`, {
240516
+ sql,
240517
+ ...mode ? { mode } : {},
240518
+ ...admin !== undefined ? { admin } : {}
240519
+ });
240514
240520
  let text;
240515
240521
  switch (action) {
240516
240522
  case "query": {
240517
240523
  if (!args.sql)
240518
- throw new Error("'sql' required");
240524
+ throw new Error("'sql' or 'file' required");
240519
240525
  if (readOnly) {
240520
240526
  const upper = args.sql.trim().toUpperCase();
240521
240527
  for (const kw of ["INSERT", "UPDATE", "DELETE", "DROP", "CREATE", "ALTER", "TRUNCATE"]) {
@@ -240523,7 +240529,18 @@ Actions: ${allActions.join(", ")}${localOnly ? " (local-only mode)" : readOnly ?
240523
240529
  return { content: [{ type: "text", text: `❌ Write blocked: ${kw} (read-only mode)` }] };
240524
240530
  }
240525
240531
  }
240526
- const r = await execSql(args.sql);
240532
+ const r = await execSql(args.sql, args.mode, args.admin);
240533
+ text = r.ok ? formatSqlResult(r.data) : `❌ Failed (${r.status}): ${JSON.stringify(r.data)}`;
240534
+ break;
240535
+ }
240536
+ case "execute": {
240537
+ if (readOnly) {
240538
+ return { content: [{ type: "text", text: "❌ Write blocked: execute (read-only mode)" }] };
240539
+ }
240540
+ if (!args.sql)
240541
+ throw new Error("'sql' or 'file' required");
240542
+ const mode = args.mode || "migration";
240543
+ const r = await execSql(args.sql, mode, args.admin);
240527
240544
  text = r.ok ? formatSqlResult(r.data) : `❌ Failed (${r.status}): ${JSON.stringify(r.data)}`;
240528
240545
  break;
240529
240546
  }
@@ -247665,6 +247682,120 @@ async function compileProject(options) {
247665
247682
  return { diagnostics, graph, written };
247666
247683
  }
247667
247684
 
247685
+ // src/shared/tools/app-tool-export.ts
247686
+ function sanitizeToolName(name) {
247687
+ const sanitized = name.replace(/[^a-zA-Z0-9_]/g, "_").slice(0, 64);
247688
+ return sanitized || "supacloud_command";
247689
+ }
247690
+ function uniqueToolName(name, moduleName, used) {
247691
+ const base = sanitizeToolName(name);
247692
+ if (!used.has(base)) {
247693
+ used.add(base);
247694
+ return base;
247695
+ }
247696
+ const prefix = sanitizeToolName(moduleName).slice(0, 32);
247697
+ const candidateBase = `${prefix}_${base}`.slice(0, 64);
247698
+ let candidate = candidateBase;
247699
+ let suffix = 2;
247700
+ while (used.has(candidate)) {
247701
+ candidate = `${candidateBase.slice(0, 64 - String(suffix).length - 1)}_${suffix}`;
247702
+ suffix += 1;
247703
+ }
247704
+ used.add(candidate);
247705
+ return candidate;
247706
+ }
247707
+ function findRouteForCommand(manifest, commandClassName) {
247708
+ for (const module of manifest.modules) {
247709
+ for (const controller of module.controllers) {
247710
+ for (const route of controller.routes) {
247711
+ if (route.command !== commandClassName)
247712
+ continue;
247713
+ return {
247714
+ httpMethod: route.method,
247715
+ path: `${controller.path}${route.path}`,
247716
+ bodySchema: route.body,
247717
+ paramsSchema: route.params,
247718
+ querySchema: route.query
247719
+ };
247720
+ }
247721
+ }
247722
+ }
247723
+ return;
247724
+ }
247725
+ function inputSchema(route) {
247726
+ const properties = {};
247727
+ if (route?.bodySchema) {
247728
+ properties.body = {
247729
+ type: "object",
247730
+ description: `Request body. Schema reference: ${route.bodySchema}`,
247731
+ additionalProperties: true
247732
+ };
247733
+ }
247734
+ if (route?.paramsSchema) {
247735
+ properties.params = {
247736
+ type: "object",
247737
+ description: `Path parameters. Schema reference: ${route.paramsSchema}`,
247738
+ additionalProperties: true
247739
+ };
247740
+ }
247741
+ if (route?.querySchema) {
247742
+ properties.query = {
247743
+ type: "object",
247744
+ description: `Query parameters. Schema reference: ${route.querySchema}`,
247745
+ additionalProperties: true
247746
+ };
247747
+ }
247748
+ return {
247749
+ type: "object",
247750
+ properties,
247751
+ required: [],
247752
+ additionalProperties: Object.keys(properties).length === 0
247753
+ };
247754
+ }
247755
+ function descriptionForCommand(command, route) {
247756
+ const parts = [`Command ${command.name}`, `permission ${command.permission}`];
247757
+ if (command.transaction === "required")
247758
+ parts.push("transaction required");
247759
+ if (command.idempotency === "required")
247760
+ parts.push("idempotent");
247761
+ if (command.audit)
247762
+ parts.push(`audit ${command.audit}`);
247763
+ if (route)
247764
+ parts.push(`HTTP ${route.httpMethod} ${route.path}`);
247765
+ return `${parts.join("; ")}.`;
247766
+ }
247767
+ function buildToolDefinitions(manifest) {
247768
+ const openai = [];
247769
+ const mcp = [];
247770
+ const usedNames = new Set;
247771
+ for (const module of manifest.modules) {
247772
+ for (const command of module.commands) {
247773
+ if (!command.permission)
247774
+ continue;
247775
+ const route = findRouteForCommand(manifest, command.className);
247776
+ const name = uniqueToolName(command.name, module.name, usedNames);
247777
+ const description = descriptionForCommand(command, route);
247778
+ const parameters = inputSchema(route);
247779
+ openai.push({
247780
+ type: "function",
247781
+ function: { name, description, parameters }
247782
+ });
247783
+ mcp.push({
247784
+ name,
247785
+ description,
247786
+ inputSchema: parameters,
247787
+ annotations: {
247788
+ readOnly: false,
247789
+ audited: !!command.audit,
247790
+ permission: command.permission,
247791
+ ...route ? { httpPath: route.path, httpMethod: route.httpMethod } : {}
247792
+ }
247793
+ });
247794
+ }
247795
+ }
247796
+ return { openai, mcp };
247797
+ }
247798
+
247668
247799
  // src/shared/tools/app-tools.ts
247669
247800
  function textResult(text, isError = false) {
247670
247801
  return { isError, content: [{ type: "text", text }] };
@@ -247969,19 +248100,43 @@ async function runExplain(args) {
247969
248100
  }
247970
248101
  return textResult(`未找到对象: ${target}`, true);
247971
248102
  }
248103
+ async function runExportTools(args) {
248104
+ const root = resolve7(args.root || process.cwd());
248105
+ const manifest = await readManifest(root);
248106
+ const definitions = buildToolDefinitions(manifest);
248107
+ const outDir = resolve7(args.out_dir || join7(root, "generated"));
248108
+ await mkdir2(outDir, { recursive: true });
248109
+ if (args.format === "json") {
248110
+ return textResult(JSON.stringify(definitions, null, 2));
248111
+ }
248112
+ const openaiPath = join7(outDir, "tool-definitions.openai.json");
248113
+ const mcpPath = join7(outDir, "tool-definitions.mcp.json");
248114
+ await writeFile2(openaiPath, JSON.stringify(definitions.openai, null, 2), "utf8");
248115
+ await writeFile2(mcpPath, JSON.stringify(definitions.mcp, null, 2), "utf8");
248116
+ const summary = [
248117
+ `exported ${definitions.openai.length} tool(s):`,
248118
+ ` openai → ${openaiPath}`,
248119
+ ` mcp → ${mcpPath}`,
248120
+ "",
248121
+ definitions.openai.map((t) => ` ${t.function.name}`).join(`
248122
+ `)
248123
+ ].join(`
248124
+ `);
248125
+ return textResult(summary);
248126
+ }
247972
248127
  function registerAppTools(server2) {
247973
- server2.tool("app", "Local @supacloud/app framework commands: scaffold, compile, check, graph and explain. Actions: generate, compile, check, graph, explain", {
247974
- action: withDescription(stringEnum(["generate", "compile", "check", "graph", "explain"]), "App action"),
248128
+ server2.tool("app", "Local @supacloud/app framework commands: scaffold, compile, check, graph, explain and export-tools. Actions: generate, compile, check, graph, explain, export-tools", {
248129
+ action: withDescription(stringEnum(["generate", "compile", "check", "graph", "explain", "export-tools"]), "App action"),
247975
248130
  kind: optional(stringEnum(["module", "command", "query", "controller"]), "[generate] Scaffold kind"),
247976
248131
  name: optional(Type.String(), "[generate] Object name (module name / command / query name)"),
247977
248132
  module: optional(Type.String(), "[generate] Target feature module (required for command/query/controller)"),
247978
248133
  dir: optional(Type.String(), "[generate] Feature root directory (default: src/features)"),
247979
248134
  force: optional(Type.Boolean(), "[generate] Overwrite existing files"),
247980
- root: optional(Type.String(), "[generate/compile/check/graph/explain] Project root (default: current directory)"),
248135
+ root: optional(Type.String(), "[generate/compile/check/graph/explain/export-tools] Project root (default: current directory)"),
247981
248136
  include: optional(Type.String(), "[compile/check] Comma-separated glob patterns for source files"),
247982
- out_dir: optional(Type.String(), "[compile] Output directory (default: <root>/generated)"),
248137
+ out_dir: optional(Type.String(), "[compile/export-tools] Output directory (default: <root>/generated)"),
247983
248138
  strict: optional(Type.Boolean(), "[compile/check] Promote warnings to errors"),
247984
- format: optional(stringEnum(["text", "json"]), "[graph] Output format (default: text)"),
248139
+ format: optional(stringEnum(["text", "json"]), "[graph/export-tools] Output format (default: text)"),
247985
248140
  target: optional(Type.String(), "[explain] Provider class name / token name / command name")
247986
248141
  }, async (request) => {
247987
248142
  switch (request.action) {
@@ -247995,6 +248150,8 @@ function registerAppTools(server2) {
247995
248150
  return runGraph(request);
247996
248151
  case "explain":
247997
248152
  return runExplain(request);
248153
+ case "export-tools":
248154
+ return runExportTools(request);
247998
248155
  default:
247999
248156
  return textResult(`Unknown app action: ${String(request.action)}`, true);
248000
248157
  }
@@ -251086,7 +251243,7 @@ function registerRemoteDevTools(server2, options = {}) {
251086
251243
  // package.json
251087
251244
  var package_default = {
251088
251245
  name: "@supacloud/cli",
251089
- version: "0.42.0",
251246
+ version: "0.44.0",
251090
251247
  description: "Project-scoped CLI for SupaCloud users",
251091
251248
  type: "module",
251092
251249
  main: "./dist/index.js",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@supacloud/cli",
3
- "version": "0.42.0",
3
+ "version": "0.44.0",
4
4
  "description": "Project-scoped CLI for SupaCloud users",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",