@rebasepro/cli 0.31.0 → 0.32.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/{agent-setup-DqAcoDcn.js → agent-setup-Cg_zBWoW.js} +3 -3
- package/dist/{agent-setup-DqAcoDcn.js.map → agent-setup-Cg_zBWoW.js.map} +1 -1
- package/dist/api-TbmW33D7.js +275 -0
- package/dist/api-TbmW33D7.js.map +1 -0
- package/dist/{api-keys-eIUjMqWn.js → api-keys-fPQ55DCm.js} +151 -158
- package/dist/api-keys-fPQ55DCm.js.map +1 -0
- package/dist/{apps-DExO4PEl.js → apps-DBTRoOeP.js} +18 -13
- package/dist/apps-DBTRoOeP.js.map +1 -0
- package/dist/{args-CaCcrYE1.js → args-DHyrshtI.js} +3 -132
- package/dist/args-DHyrshtI.js.map +1 -0
- package/dist/{atlas-dev-database-DOCKk6ht.js → atlas-dev-database-D6h65f2x.js} +3 -3
- package/dist/{atlas-dev-database-DOCKk6ht.js.map → atlas-dev-database-D6h65f2x.js.map} +1 -1
- package/dist/{auth-ofQETpM5.js → auth-BpyYLEFY.js} +93 -12
- package/dist/auth-BpyYLEFY.js.map +1 -0
- package/dist/auth-session-B6aT0Dyj.js +371 -0
- package/dist/auth-session-B6aT0Dyj.js.map +1 -0
- package/dist/{backend-guard-C0mVkXBw.js → backend-guard-Cf8eMK_f.js} +2 -2
- package/dist/{backend-guard-C0mVkXBw.js.map → backend-guard-Cf8eMK_f.js.map} +1 -1
- package/dist/{branch-pointer-DMPyvZoK.js → branch-pointer-BJOF2Ubv.js} +1 -1
- package/dist/{build-CA5R07tw.js → build-BfdT-AUR.js} +12 -10
- package/dist/{build-CA5R07tw.js.map → build-BfdT-AUR.js.map} +1 -1
- package/dist/{bundle-DgILeA5b.js → bundle-CIiKGrte.js} +78 -12
- package/dist/bundle-CIiKGrte.js.map +1 -0
- package/dist/bundle.d.ts +31 -1
- package/dist/{cloud-CYMk92iG.js → cloud-MqnyPnmX.js} +1540 -1531
- package/dist/cloud-MqnyPnmX.js.map +1 -0
- package/dist/{cms-directories-BK3vcswg.js → cms-directories-BaV-Is9a.js} +2 -2
- package/dist/{cms-directories-BK3vcswg.js.map → cms-directories-BaV-Is9a.js.map} +1 -1
- package/dist/codemod/collections-to-tables/backend.d.ts +0 -2
- package/dist/codemod/collections-to-tables/customization.d.ts +2 -1
- package/dist/codemod/collections-to-tables/modules.d.ts +32 -0
- package/dist/codemod/collections-to-tables/plan-context.d.ts +7 -1
- package/dist/{command-D5lhW_-B.js → command-D9g46gg9.js} +68 -42
- package/dist/command-D9g46gg9.js.map +1 -0
- package/dist/commands/api-keys.d.ts +89 -52
- package/dist/commands/api.d.ts +114 -0
- package/dist/commands/auth-session.d.ts +94 -0
- package/dist/commands/auth.d.ts +1 -1
- package/dist/commands/cloud/alerts.d.ts +29 -0
- package/dist/commands/cloud/context.d.ts +8 -0
- package/dist/commands/cloud/debug.d.ts +16 -1
- package/dist/commands/cloud/deploy-hooks.d.ts +19 -0
- package/dist/commands/cloud/deploy.d.ts +25 -0
- package/dist/commands/cloud/env.d.ts +1 -0
- package/dist/commands/cloud/index.d.ts +5 -0
- package/dist/commands/cloud/maintenance.d.ts +26 -1
- package/dist/commands/cloud/not-served.d.ts +27 -0
- package/dist/commands/cloud/orgs.d.ts +5 -0
- package/dist/commands/cloud/resources.d.ts +82 -2
- package/dist/commands/cloud/runtime-logs.d.ts +57 -0
- package/dist/commands/cloud/settings.d.ts +3 -0
- package/dist/commands/cron.d.ts +68 -0
- package/dist/commands/data.d.ts +197 -0
- package/dist/commands/functions.d.ts +38 -0
- package/dist/commands/logs.d.ts +22 -0
- package/dist/commands/rls.d.ts +31 -0
- package/dist/commands/schema-reconcile.d.ts +2 -1
- package/dist/commands/schema-show.d.ts +38 -0
- package/dist/commands/storage-objects.d.ts +88 -0
- package/dist/commands/storage.d.ts +18 -2
- package/dist/commands/users.d.ts +147 -0
- package/dist/{consent-BXLIrMl8.js → consent-UV6ObCME.js} +2 -2
- package/dist/{consent-BXLIrMl8.js.map → consent-UV6ObCME.js.map} +1 -1
- package/dist/{console-DjThnr3f.js → console-BVoYOLAO.js} +6 -6
- package/dist/{console-DjThnr3f.js.map → console-BVoYOLAO.js.map} +1 -1
- package/dist/{context--JwaHaZp.js → context-BOMEoKxn.js} +80 -9
- package/dist/{context--JwaHaZp.js.map → context-BOMEoKxn.js.map} +1 -1
- package/dist/cron-CpUsQ739.js +298 -0
- package/dist/cron-CpUsQ739.js.map +1 -0
- package/dist/cron-ZRXsla0v.js +259 -0
- package/dist/cron-ZRXsla0v.js.map +1 -0
- package/dist/{daemon-w30PsdwV.js → daemon-D5gdG7gx.js} +3 -3
- package/dist/{daemon-w30PsdwV.js.map → daemon-D5gdG7gx.js.map} +1 -1
- package/dist/{daemon-entry-zOC1revO.js → daemon-entry--ummUJnk.js} +2 -2
- package/dist/{daemon-entry-zOC1revO.js.map → daemon-entry--ummUJnk.js.map} +1 -1
- package/dist/data-BJ9AZFUC.js +947 -0
- package/dist/data-BJ9AZFUC.js.map +1 -0
- package/dist/{db-Bz2RFGJj.js → db-D_iF4E-v.js} +38 -34
- package/dist/{db-Bz2RFGJj.js.map → db-D_iF4E-v.js.map} +1 -1
- package/dist/debug-nNbbxAeo.js +1114 -0
- package/dist/debug-nNbbxAeo.js.map +1 -0
- package/dist/{derive-C3ezmY-p.js → derive-Mky_u59_.js} +3 -3
- package/dist/{derive-C3ezmY-p.js.map → derive-Mky_u59_.js.map} +1 -1
- package/dist/{dev-D8TxrE_I.js → dev-bj6dEeSQ.js} +13 -13
- package/dist/{dev-D8TxrE_I.js.map → dev-bj6dEeSQ.js.map} +1 -1
- package/dist/dev-db/pull.d.ts +13 -3
- package/dist/{dev-preflight-DjvcV6SK.js → dev-preflight-BMOf2N6r.js} +2 -2
- package/dist/{dev-preflight-DjvcV6SK.js.map → dev-preflight-BMOf2N6r.js.map} +1 -1
- package/dist/{dev-server-BLxCbQEP.js → dev-server-2XHSHM_q.js} +2 -2
- package/dist/{dev-server-BLxCbQEP.js.map → dev-server-2XHSHM_q.js.map} +1 -1
- package/dist/{doctor-Du-mSxoE.js → doctor-2Jlau0Rm.js} +9 -8
- package/dist/{doctor-Du-mSxoE.js.map → doctor-2Jlau0Rm.js.map} +1 -1
- package/dist/{eject-Bhzd6hgb.js → eject-DK_M9kor.js} +4 -4
- package/dist/{eject-Bhzd6hgb.js.map → eject-DK_M9kor.js.map} +1 -1
- package/dist/{fold-static-CKewnAPX.js → fold-static-2t3UUX4z.js} +10 -6
- package/dist/fold-static-2t3UUX4z.js.map +1 -0
- package/dist/fold-static.d.ts +7 -0
- package/dist/functions-B4JR6EZL.js +120 -0
- package/dist/functions-B4JR6EZL.js.map +1 -0
- package/dist/{generate-view-CTOluXvH.js → generate-view-BMaLQm8H.js} +5 -5
- package/dist/{generate-view-CTOluXvH.js.map → generate-view-BMaLQm8H.js.map} +1 -1
- package/dist/{generate_sdk-De-aLC1L.js → generate_sdk-ByD-gTsK.js} +7 -7
- package/dist/{generate_sdk-De-aLC1L.js.map → generate_sdk-ByD-gTsK.js.map} +1 -1
- package/dist/index.es.js +123 -47
- package/dist/index.es.js.map +1 -1
- package/dist/{init-Dtl-IcXf.js → init-DHCe5mJ5.js} +59 -11
- package/dist/init-DHCe5mJ5.js.map +1 -0
- package/dist/{invoked-command-CG_rIa_o.js → invoked-command-FBeIBS8o.js} +2 -2
- package/dist/{invoked-command-CG_rIa_o.js.map → invoked-command-FBeIBS8o.js.map} +1 -1
- package/dist/last-dev-database-CBVkEUEl.js +2 -0
- package/dist/logs-CIgfLBsu.js +192 -0
- package/dist/logs-CIgfLBsu.js.map +1 -0
- package/dist/{manifest-C3uLDrrJ.js → manifest-RjqxfCpb.js} +114 -5
- package/dist/manifest-RjqxfCpb.js.map +1 -0
- package/dist/{migrate-VrKoi3nB.js → migrate-Cx8-Y4TG.js} +5 -4
- package/dist/{migrate-VrKoi3nB.js.map → migrate-Cx8-Y4TG.js.map} +1 -1
- package/dist/{normalize-imports-DwxqEMYq.js → normalize-imports-P86NVfpo.js} +3 -3
- package/dist/{normalize-imports-DwxqEMYq.js.map → normalize-imports-P86NVfpo.js.map} +1 -1
- package/dist/{path-flags-7O5uPBcQ.js → path-flags-ekLdkbra.js} +3 -3
- package/dist/{path-flags-7O5uPBcQ.js.map → path-flags-ekLdkbra.js.map} +1 -1
- package/dist/{prepare-Ccxspoj-.js → prepare-BaJe0Zik.js} +4 -4
- package/dist/{prepare-Ccxspoj-.js.map → prepare-BaJe0Zik.js.map} +1 -1
- package/dist/{project-CLcF5i8c.js → project-DALmhb5R.js} +2 -2
- package/dist/{project-CLcF5i8c.js.map → project-DALmhb5R.js.map} +1 -1
- package/dist/project-command-Cl9EZzjr.js +662 -0
- package/dist/project-command-Cl9EZzjr.js.map +1 -0
- package/dist/{project-schema-CsSOG2gE.js → project-schema-Dm6Jk0Y_.js} +4 -2
- package/dist/{project-schema-CsSOG2gE.js.map → project-schema-Dm6Jk0Y_.js.map} +1 -1
- package/dist/{pull-BMuiUyjb.js → pull-CTIsST6T.js} +66 -5
- package/dist/pull-CTIsST6T.js.map +1 -0
- package/dist/resolve-C36px9tR.js +2 -0
- package/dist/{resources-Dpfs2y8P.js → resources-Db3USuPO.js} +5 -5
- package/dist/{resources-Dpfs2y8P.js.map → resources-Db3USuPO.js.map} +1 -1
- package/dist/rls-BxrQ0P50.js +133 -0
- package/dist/rls-BxrQ0P50.js.map +1 -0
- package/dist/{schema-Dv6nHkb0.js → schema-_FzZEoB8.js} +54 -40
- package/dist/schema-_FzZEoB8.js.map +1 -0
- package/dist/{schema-dir-Cd1kvYbf.js → schema-dir-ChcYfWjP.js} +2 -2
- package/dist/{schema-dir-Cd1kvYbf.js.map → schema-dir-ChcYfWjP.js.map} +1 -1
- package/dist/schema-reconcile-DV14XY4o.js +2 -0
- package/dist/schema-show-h72UJ9zH.js +127 -0
- package/dist/schema-show-h72UJ9zH.js.map +1 -0
- package/dist/{skills-CXjA9TWw.js → skills-DQ2bZGkj.js} +6 -5
- package/dist/{skills-CXjA9TWw.js.map → skills-DQ2bZGkj.js.map} +1 -1
- package/dist/star-nudge.d.ts +28 -0
- package/dist/{start-Bwbtt2W5.js → start-Cjx4W0bJ.js} +7 -7
- package/dist/{start-Bwbtt2W5.js.map → start-Cjx4W0bJ.js.map} +1 -1
- package/dist/{status-BTgTWzlQ.js → status-CDBk25VO.js} +9 -9
- package/dist/{status-BTgTWzlQ.js.map → status-CDBk25VO.js.map} +1 -1
- package/dist/{storage-iTqj5-Av.js → storage-Clc8dLG8.js} +79 -36
- package/dist/storage-Clc8dLG8.js.map +1 -0
- package/dist/storage-objects-CfRKlTDe.js +279 -0
- package/dist/storage-objects-CfRKlTDe.js.map +1 -0
- package/dist/{telemetry-BP_1Cl9r.js → telemetry-DZU2-NCm.js} +5 -4
- package/dist/{telemetry-BP_1Cl9r.js.map → telemetry-DZU2-NCm.js.map} +1 -1
- package/dist/{telemetry-M3HjlyhZ.js → telemetry-EVtASbKb.js} +2 -2
- package/dist/{telemetry-M3HjlyhZ.js.map → telemetry-EVtASbKb.js.map} +1 -1
- package/dist/unknown-command-DnZ2uhGs.js +139 -0
- package/dist/unknown-command-DnZ2uhGs.js.map +1 -0
- package/dist/{upgrade-oZzJ13jM.js → upgrade-DhpUFb6p.js} +5 -5
- package/dist/{upgrade-oZzJ13jM.js.map → upgrade-DhpUFb6p.js.map} +1 -1
- package/dist/users-5PkqBY6R.js +561 -0
- package/dist/users-5PkqBY6R.js.map +1 -0
- package/dist/utils/project-command.d.ts +38 -0
- package/dist/utils/project-target.d.ts +193 -0
- package/dist/{verify-BkUVGLqo.js → verify-BdeqNb-V.js} +138 -12
- package/dist/verify-BdeqNb-V.js.map +1 -0
- package/dist/{version-Buyyo1ut.js → version-ONIeo7jl.js} +7 -2
- package/dist/{version-Buyyo1ut.js.map → version-ONIeo7jl.js.map} +1 -1
- package/package.json +10 -10
- package/dist/api-keys-eIUjMqWn.js.map +0 -1
- package/dist/apps-DExO4PEl.js.map +0 -1
- package/dist/args-CaCcrYE1.js.map +0 -1
- package/dist/auth-ofQETpM5.js.map +0 -1
- package/dist/bundle-DgILeA5b.js.map +0 -1
- package/dist/cloud-CYMk92iG.js.map +0 -1
- package/dist/command-D5lhW_-B.js.map +0 -1
- package/dist/fold-static-CKewnAPX.js.map +0 -1
- package/dist/init-Dtl-IcXf.js.map +0 -1
- package/dist/last-dev-database-Dc8cP01o.js +0 -2
- package/dist/manifest-C3uLDrrJ.js.map +0 -1
- package/dist/pull-BMuiUyjb.js.map +0 -1
- package/dist/resolve-BY7bSFRT.js +0 -2
- package/dist/schema-Dv6nHkb0.js.map +0 -1
- package/dist/schema-reconcile-CjxLaRHB.js +0 -2
- package/dist/storage-iTqj5-Av.js.map +0 -1
- package/dist/verify-BkUVGLqo.js.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as detectPackageManager } from "./package-manager-DSEOwTqM.js";
|
|
2
|
-
import { n as cliVersion } from "./version-
|
|
3
|
-
import { a as installSkills, i as detectInstalledAgents, n as AGENT_KEYS, s as loadBundledSkills, t as AGENTS } from "./skills-
|
|
2
|
+
import { n as cliVersion } from "./version-ONIeo7jl.js";
|
|
3
|
+
import { a as installSkills, i as detectInstalledAgents, n as AGENT_KEYS, s as loadBundledSkills, t as AGENTS } from "./skills-DQ2bZGkj.js";
|
|
4
4
|
import chalk from "chalk";
|
|
5
5
|
import fs from "fs";
|
|
6
6
|
import path from "path";
|
|
@@ -448,4 +448,4 @@ function installAgentHooks(projectDir, { force = false, templateDir = path.join(
|
|
|
448
448
|
//#endregion
|
|
449
449
|
export { AGENT_HOOK_SCRIPT, MCP_SERVER_NAME, cliPackageRoot, configureAgents, ensureMcpDependency, installAgentHooks, mcpDependencyNote, mcpServerRegistered, printAgentSetup, promptForAgents, retargetScaffoldMcpConfig, writeMcpConfig };
|
|
450
450
|
|
|
451
|
-
//# sourceMappingURL=agent-setup-
|
|
451
|
+
//# sourceMappingURL=agent-setup-Cg_zBWoW.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-setup-DqAcoDcn.js","names":[],"sources":["../src/commands/agent-setup.ts"],"sourcesContent":["/**\n * Setting a project up for the AI coding assistants a developer uses: the\n * Rebase skills, and the Rebase MCP server in each assistant's own config.\n *\n * `rebase init` used to end by *printing* `rebase skills install`, and nothing\n * ran it — so a generated project had pointer files telling every assistant to\n * read skills that were not there, and an MCP server only Claude Code knew\n * about. This asks once, while the project is being made, pre-ticking the\n * assistants installed on the machine.\n */\nimport chalk from \"chalk\";\nimport { createHash } from \"crypto\";\nimport fs from \"fs\";\nimport path from \"path\";\nimport inquirer from \"inquirer\";\nimport {\n AGENT_KEYS,\n AGENTS,\n type AgentKey,\n detectInstalledAgents,\n installSkills,\n type LoadedSkill,\n loadBundledSkills\n} from \"./skills\";\nimport { fileURLToPath } from \"url\";\nimport { detectPackageManager, type PackageManager } from \"../utils/package-manager\";\nimport { cliVersion } from \"../utils/version\";\n\n/** The name the server is registered under, in every config. */\nexport const MCP_SERVER_NAME = \"rebase\";\n\n/** The MCP server's package: a devDependency of the project, pinned with the rest. */\nexport const MCP_PACKAGE = \"@rebasepro/mcp\";\n\n/** The bin {@link MCP_PACKAGE} declares. */\nexport const MCP_BIN = \"rebase-mcp\";\n\n/** The command an assistant spawns, and its arguments. */\nexport interface McpLaunch {\n command: string;\n args: string[];\n}\n\n/**\n * How an assistant starts the Rebase MCP server: the project's own copy, through\n * the project's package manager.\n *\n * Not `npx -y @rebasepro/mcp`, which fetched the newest release on every first\n * start. The server drives the project's own CLI (`pnpm exec rebase …`) and calls\n * the project's own backend (`/api/admin/schema/plan`, …), whose versions the\n * lockfile pins — so a server from the registry ran ahead of both, at every\n * start, and downloaded before it could answer. `@rebasepro/mcp` is a\n * devDependency of the scaffold, pinned to the CLI's version like every other\n * `@rebasepro` package, and this runs that copy.\n *\n * `npx --no`, not `npx`: an assistant spawns the server with no TTY, and npx\n * then assumes \"yes\" and installs a missing package from the registry under the\n * name it was given. `--no` makes a missing install an error instead.\n */\nexport function mcpLaunch(pm: PackageManager): McpLaunch {\n return pm === \"npm\"\n ? { command: \"npx\", args: [\"--no\", MCP_BIN] }\n : { command: \"pnpm\", args: [\"exec\", MCP_BIN] };\n}\n\n/** What writing one MCP config did. */\nexport type McpWriteStatus =\n /** The file was created, or the server was added beside the ones in it. */\n | \"added\"\n /** A `rebase` server was already there. It is left exactly as it was. */\n | \"present\"\n /** The file exists but is not something this can edit without losing data. */\n | \"unreadable\";\n\nexport interface McpWriteResult {\n /** Project-relative path of the config file. */\n file: string;\n status: McpWriteStatus;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\n/**\n * Add the server to a JSON config under `key`, keeping everything else in it.\n *\n * A file that does not parse as plain JSON is left alone: VS Code and Gemini\n * both accept comments in these files, and rewriting one through\n * `JSON.stringify` would delete them. Refusing costs one line of hand-editing;\n * the alternative silently costs the developer theirs.\n */\nfunction addJsonServer(filePath: string, key: string, entry: Record<string, unknown>): McpWriteStatus {\n let doc: Record<string, unknown> = {};\n if (fs.existsSync(filePath)) {\n let parsed: unknown;\n try {\n parsed = JSON.parse(fs.readFileSync(filePath, \"utf-8\"));\n } catch {\n return \"unreadable\";\n }\n if (!isRecord(parsed)) return \"unreadable\";\n doc = parsed;\n }\n\n const servers = doc[key] ?? {};\n if (!isRecord(servers)) return \"unreadable\";\n if (MCP_SERVER_NAME in servers) return \"present\";\n\n doc[key] = { ...servers, [MCP_SERVER_NAME]: entry };\n fs.mkdirSync(path.dirname(filePath), { recursive: true });\n fs.writeFileSync(filePath, `${JSON.stringify(doc, null, 2)}\\n`, \"utf-8\");\n return \"added\";\n}\n\n/**\n * The Codex block, as TOML. Appended rather than merged: there is no TOML\n * parser here, and an append keeps every byte already in the file.\n */\nexport function renderCodexServer(projectDir: string, launch: McpLaunch): string {\n // A JSON string literal is a valid TOML basic string for these values.\n const str = (v: string) => JSON.stringify(v);\n return [\n `[mcp_servers.${MCP_SERVER_NAME}]`,\n `command = ${str(launch.command)}`,\n `args = [${launch.args.map(str).join(\", \")}]`,\n \"\",\n `[mcp_servers.${MCP_SERVER_NAME}.env]`,\n `REBASE_PROJECT_DIR = ${str(projectDir)}`,\n \"\"\n ].join(\"\\n\");\n}\n\nfunction addCodexServer(filePath: string, projectDir: string, launch: McpLaunch): McpWriteStatus {\n const existing = fs.existsSync(filePath) ? fs.readFileSync(filePath, \"utf-8\") : \"\";\n const table = new RegExp(`^\\\\s*\\\\[mcp_servers\\\\.(?:${MCP_SERVER_NAME}|\"${MCP_SERVER_NAME}\")\\\\]`, \"m\");\n if (table.test(existing)) return \"present\";\n\n const separator = existing === \"\" ? \"\" : existing.endsWith(\"\\n\") ? \"\\n\" : \"\\n\\n\";\n fs.mkdirSync(path.dirname(filePath), { recursive: true });\n fs.writeFileSync(filePath, `${existing}${separator}${renderCodexServer(projectDir, launch)}`, \"utf-8\");\n return \"added\";\n}\n\n/**\n * Register the Rebase MCP server in the agent's project-level config, started\n * through the project's package manager (see {@link mcpLaunch}).\n *\n * Returns null for an agent with no project-level config to write.\n */\nexport function writeMcpConfig(\n agentKey: AgentKey,\n projectDir: string,\n pm: PackageManager = detectPackageManager(projectDir)\n): McpWriteResult | null {\n const mcp = AGENTS[agentKey].mcp;\n if (!mcp) return null;\n\n const filePath = path.join(projectDir, mcp.file);\n const env = { REBASE_PROJECT_DIR: mcp.projectDir };\n const { command, args } = mcpLaunch(pm);\n const write = (): McpWriteStatus => {\n switch (mcp.format) {\n case \"mcpServers\":\n return addJsonServer(filePath, \"mcpServers\", { command, args, env });\n case \"vscode\":\n // VS Code's own shape: `servers`, and an explicit transport.\n return addJsonServer(filePath, \"servers\", { type: \"stdio\", command, args, env });\n case \"codexToml\":\n return addCodexServer(filePath, mcp.projectDir, { command, args });\n }\n };\n return { file: mcp.file, status: write() };\n}\n\n/** What making sure the project depends on the MCP server did. */\nexport type McpDependencyStatus =\n /** Added to `devDependencies`, at this CLI's version: an install is due. */\n | \"added\"\n /** Already a dependency. Left at the version the project chose. */\n | \"present\"\n /** No `package.json`, or one that is not plain JSON: left alone. */\n | \"unreadable\";\n\n/**\n * Make the project depend on {@link MCP_PACKAGE}, which the config written by\n * {@link writeMcpConfig} runs from the project's own install.\n *\n * Pinned to this CLI's version, as `rebase init` pins every `@rebasepro`\n * package; a project that already lists it keeps its own choice.\n */\nexport function ensureMcpDependency(projectDir: string): McpDependencyStatus {\n const manifestPath = path.join(projectDir, \"package.json\");\n if (!fs.existsSync(manifestPath)) return \"unreadable\";\n const text = fs.readFileSync(manifestPath, \"utf-8\");\n let manifest: unknown;\n try {\n manifest = JSON.parse(text);\n } catch {\n return \"unreadable\";\n }\n if (!isRecord(manifest)) return \"unreadable\";\n for (const field of [\"dependencies\", \"devDependencies\"] as const) {\n const deps = manifest[field];\n if (isRecord(deps) && MCP_PACKAGE in deps) return \"present\";\n }\n const devDependencies = isRecord(manifest.devDependencies) ? manifest.devDependencies : {};\n const version = cliVersion();\n manifest.devDependencies = { ...devDependencies, [MCP_PACKAGE]: version === \"unknown\" ? \"latest\" : version };\n // The file's own indentation, so the change is one line in a diff.\n const indent = /\\n([ \\t]+)\"/.exec(text)?.[1] ?? \" \";\n fs.writeFileSync(manifestPath, `${JSON.stringify(manifest, null, indent)}\\n`, \"utf-8\");\n return \"added\";\n}\n\n/**\n * Point the scaffold's `.mcp.json` at the project's package manager.\n *\n * The template ships the pnpm spelling (`pnpm exec rebase-mcp`); an npm project\n * has no pnpm to run it with. Only the entry the template wrote is rewritten.\n */\nexport function retargetScaffoldMcpConfig(projectDir: string, pm: PackageManager): void {\n const filePath = path.join(projectDir, \".mcp.json\");\n if (!fs.existsSync(filePath)) return;\n let doc: unknown;\n try {\n doc = JSON.parse(fs.readFileSync(filePath, \"utf-8\"));\n } catch {\n return;\n }\n const servers = isRecord(doc) ? doc.mcpServers : undefined;\n const entry = isRecord(servers) ? servers[MCP_SERVER_NAME] : undefined;\n const shipped = mcpLaunch(\"pnpm\");\n if (!isRecord(doc) || !isRecord(servers) || !isRecord(entry)) return;\n if (entry.command !== shipped.command || JSON.stringify(entry.args) !== JSON.stringify(shipped.args)) return;\n const wanted = mcpLaunch(pm);\n if (wanted.command === shipped.command && JSON.stringify(wanted.args) === JSON.stringify(shipped.args)) return;\n servers[MCP_SERVER_NAME] = { ...entry, command: wanted.command, args: wanted.args };\n fs.writeFileSync(filePath, `${JSON.stringify(doc, null, 4)}\\n`, \"utf-8\");\n}\n\n/**\n * Whether the agent's project-level config already registers the Rebase\n * server: `null` for an agent that has no such config, `false` when the file\n * is missing or does not name it. Reads only — for the hint `rebase skills\n * install` prints when it was not asked to write one.\n */\nexport function mcpServerRegistered(agentKey: AgentKey, projectDir: string): boolean | null {\n const mcp = AGENTS[agentKey].mcp;\n if (!mcp) return null;\n const filePath = path.join(projectDir, mcp.file);\n if (!fs.existsSync(filePath)) return false;\n const text = fs.readFileSync(filePath, \"utf-8\");\n if (mcp.format === \"codexToml\") {\n return new RegExp(`^\\\\s*\\\\[mcp_servers\\\\.(?:${MCP_SERVER_NAME}|\"${MCP_SERVER_NAME}\")\\\\]`, \"m\").test(text);\n }\n try {\n const doc: unknown = JSON.parse(text);\n const servers = isRecord(doc) ? doc[mcp.format === \"vscode\" ? \"servers\" : \"mcpServers\"] : undefined;\n return isRecord(servers) && MCP_SERVER_NAME in servers;\n } catch {\n // Not plain JSON (comments): cannot tell, so do not nag.\n return null;\n }\n}\n\n/** What `configureAgents` did for one agent. */\nexport interface AgentSetupResult {\n agent: AgentKey;\n /** Skills written, or null when the bundle could not be loaded. */\n skills: number | null;\n /** An earlier agent in the same run that already wrote the skills directory. */\n sharedWith?: AgentKey;\n mcp: McpWriteResult | null;\n}\n\n/**\n * Install the skills and register the MCP server for each agent.\n *\n * Never throws for a missing skills bundle — the scaffold it runs inside must\n * not fail over its assistants — and reports it as `skills: null` instead.\n */\nexport function configureAgents(\n agents: readonly AgentKey[],\n projectDir: string,\n load: () => LoadedSkill[] = loadBundledSkills,\n pm: PackageManager = detectPackageManager(projectDir)\n): { results: AgentSetupResult[]; skillsError?: string; mcpDependency?: McpDependencyStatus } {\n let skillsError: string | undefined;\n let installed: ReturnType<typeof installSkills> = [];\n try {\n installed = installSkills(agents, load(), projectDir);\n } catch (err) {\n skillsError = err instanceof Error ? err.message : String(err);\n }\n\n const results = agents.map((agent): AgentSetupResult => {\n const skills = installed.find(r => r.agent === agent);\n return {\n agent,\n skills: skills ? skills.skills : null,\n sharedWith: skills?.sharedWith,\n mcp: writeMcpConfig(agent, projectDir, pm)\n };\n });\n // A config that runs the project's copy of the server needs the project to\n // have one.\n const registered = results.some(r => r.mcp?.status === \"added\" || r.mcp?.status === \"present\");\n return { results, skillsError, ...(registered && { mcpDependency: ensureMcpDependency(projectDir) }) };\n}\n\n/** The line to print when {@link ensureMcpDependency} changed or could not change the manifest. */\nexport function mcpDependencyNote(status: McpDependencyStatus | undefined, pm: PackageManager): string | undefined {\n if (status === \"added\") {\n return `Added ${MCP_PACKAGE} to devDependencies — run \\`${pm} install\\` before your assistant starts it.`;\n }\n if (status === \"unreadable\") {\n return `Could not add ${MCP_PACKAGE} to package.json — add it to devDependencies by hand; the MCP config runs the project's own copy.`;\n }\n return undefined;\n}\n\n/** One line per agent, for the scaffold's output. */\nexport function printAgentSetup(\n { results, skillsError, mcpDependency }: ReturnType<typeof configureAgents>,\n pm: PackageManager = \"pnpm\"\n): void {\n for (const result of results) {\n const agent = AGENTS[result.agent];\n const parts: string[] = [];\n\n if (result.sharedWith) {\n parts.push(`skills in ${chalk.gray(agent.targetDir)} ${chalk.gray(`(shared with ${AGENTS[result.sharedWith].label})`)}`);\n } else if (result.skills !== null) {\n parts.push(`${result.skills} skills in ${chalk.gray(agent.targetDir)}`);\n }\n\n if (result.mcp?.status === \"added\") {\n parts.push(`MCP server in ${chalk.gray(result.mcp.file)}`);\n } else if (result.mcp?.status === \"present\") {\n parts.push(`MCP server already in ${chalk.gray(result.mcp.file)}`);\n }\n\n // A tick is a claim that something was written; with nothing, it isn't.\n const mark = parts.length ? chalk.green(\"✓\") : chalk.yellow(\"!\");\n console.log(` ${mark} ${chalk.bold(agent.label)}${parts.length ? ` — ${parts.join(\", \")}` : \"\"}`);\n\n if (result.mcp?.status === \"unreadable\") {\n console.log(chalk.yellow(` ${result.mcp.file} is not plain JSON, so it was left alone — add the \"${MCP_SERVER_NAME}\" server by hand.`));\n } else if (!result.mcp) {\n console.log(chalk.gray(` ${agent.label} has no project-level MCP config — add @rebasepro/mcp in its MCP settings.`));\n }\n }\n\n const dependencyNote = mcpDependencyNote(mcpDependency, pm);\n if (dependencyNote) console.log(chalk.gray(` ${dependencyNote}`));\n\n if (skillsError) {\n console.log(chalk.yellow(` Could not install the Rebase skills: ${skillsError}`));\n console.log(chalk.yellow(\" Run `rebase skills install` in the project once dependencies are installed.\"));\n }\n}\n\n/**\n * Ask whether to set up AI agents, then which, pre-ticking what is installed.\n *\n * Interactive only; the caller has already refused a non-TTY. Returns [] when\n * the developer says no or unticks everything.\n */\nexport async function promptForAgents(home?: string): Promise<AgentKey[]> {\n const { configure } = await inquirer.prompt([{\n type: \"confirm\",\n name: \"configure\",\n message: \"Set up Rebase skills and the Rebase MCP server for your AI coding agent(s)?\",\n default: true\n }]);\n if (!configure) return [];\n\n // Installed first, so the pre-ticked boxes are the ones under the cursor.\n const detected = detectInstalledAgents(home);\n const installed = [...detected.filter(a => a.found), ...detected.filter(a => !a.found)];\n console.log(\"\");\n console.log(\"Detecting installed AI coding agents...\");\n for (const { label, marker, found } of installed) {\n if (found) console.log(` ${chalk.green(\"✓\")} ${label} — ${marker}`);\n else if (marker) console.log(chalk.gray(` ✗ ${label} — ${marker} (not found)`));\n else console.log(chalk.gray(` · ${label} — can't be detected; tick it below if you use it`));\n }\n console.log(\"\");\n\n const { selectedAgents } = await inquirer.prompt([{\n type: \"checkbox\",\n name: \"selectedAgents\",\n message: \"Select agents to configure:\",\n choices: installed.map(({ key, label, found }) => {\n const { targetDir, mcp } = AGENTS[key];\n const writes = mcp ? `${targetDir} + ${mcp.file}` : targetDir;\n return { name: `${label} ${chalk.gray(`— ${writes}`)}`, short: label, value: key, checked: found };\n })\n }]);\n\n return AGENT_KEYS.filter(key => selectedAgents.includes(key));\n}\n\n// ─── Claude Code guardrail hooks ──────────────────────────────────────────────\n\n/**\n * The guardrail every scaffold ships for Claude Code: a PostToolUse hook that\n * runs `rebase verify --quiet` after each edit under `backend/schema/` (or the\n * `tables` directory rebase.json names) or `frontend/src/cms/`, and hands any\n * problem back to the agent (exit 2, the message on stderr).\n *\n * The script keeps the file name it first shipped with: it is how\n * {@link installAgentHooks} and the settings entry find a copy already installed.\n *\n * The files live in the template, under `.claude/`, so `rebase init` copies\n * them like everything else and `rebase skills --hooks` installs the very same\n * bytes into a project that predates them. Paths are project-relative.\n */\nexport const AGENT_HOOK_SCRIPT = \".claude/hooks/post-edit-collection.sh\";\nexport const AGENT_HOOK_SETTINGS = \".claude/settings.json\";\n\n/** What installing one hook file did. */\nexport type HookWriteStatus =\n /** Written, or merged into the settings beside the hooks already there. */\n | \"added\"\n /** Already there, unchanged — or, for the settings, already registered. */\n | \"present\"\n /** There, and edited: left as it was. `--force` replaces it. */\n | \"kept\"\n /** There, edited, and replaced because `--force` asked. */\n | \"replaced\"\n /** The settings file is not plain JSON with a `hooks` object: left alone. */\n | \"unreadable\";\n\nexport interface HookWriteResult {\n file: string;\n status: HookWriteStatus;\n}\n\n/** The CLI package's own directory, from wherever this module was bundled to. */\nexport function cliPackageRoot(): string {\n let dir = path.dirname(fileURLToPath(import.meta.url));\n while (dir !== path.dirname(dir)) {\n const manifest = path.join(dir, \"package.json\");\n if (fs.existsSync(manifest)) {\n try {\n const parsed: unknown = JSON.parse(fs.readFileSync(manifest, \"utf-8\"));\n if (isRecord(parsed) && parsed.name === \"@rebasepro/cli\") return dir;\n } catch {\n // Not ours; keep walking.\n }\n }\n dir = path.dirname(dir);\n }\n throw new Error(\"Could not find the @rebasepro/cli package directory to read the hook templates from.\");\n}\n\n/**\n * Register the shipped PostToolUse hook in an existing settings file, keeping\n * every other setting and hook in it. A file that is not plain JSON is left\n * alone, for the reason {@link addJsonServer} gives.\n */\nfunction mergeHookSettings(filePath: string, shippedText: string): HookWriteStatus {\n if (!fs.existsSync(filePath)) {\n fs.mkdirSync(path.dirname(filePath), { recursive: true });\n fs.writeFileSync(filePath, shippedText, \"utf-8\");\n return \"added\";\n }\n const text = fs.readFileSync(filePath, \"utf-8\");\n let doc: unknown;\n try {\n doc = JSON.parse(text);\n } catch {\n return \"unreadable\";\n }\n const shipped: unknown = JSON.parse(shippedText);\n const shippedEntries = isRecord(shipped) && isRecord(shipped.hooks) && Array.isArray(shipped.hooks.PostToolUse)\n ? shipped.hooks.PostToolUse\n : [];\n if (!isRecord(doc)) return \"unreadable\";\n const hooks = doc.hooks ?? {};\n if (!isRecord(hooks)) return \"unreadable\";\n const post = hooks.PostToolUse ?? [];\n if (!Array.isArray(post)) return \"unreadable\";\n if (JSON.stringify(post).includes(path.basename(AGENT_HOOK_SCRIPT))) return \"present\";\n\n doc.hooks = { ...hooks, PostToolUse: [...post, ...shippedEntries] };\n const indent = /\\n([ \\t]+)\"/.exec(text)?.[1] ?? \" \";\n fs.writeFileSync(filePath, `${JSON.stringify(doc, null, indent)}\\n`, \"utf-8\");\n return \"added\";\n}\n\n/**\n * The SHA-256 of every version of `post-edit-collection.sh` this CLI has ever\n * written, oldest first, the current one last — hashed with CRLF read as LF,\n * so a Windows checkout of an untouched copy still matches.\n *\n * A copy that differs from today's script was read as \"edited\" and kept, so a\n * fix to the hook never reached a project scaffolded before it: `rebase skills\n * install --hooks` answered \"was edited, so it was kept — pass --force\" about a\n * file nobody had touched. A copy whose hash is one of ours is our old\n * version, and is replaced like any stale file; only a copy we never shipped is\n * the developer's.\n *\n * Append, never replace: `agent-hooks.test.ts` fails when the shipped script's\n * hash is not here, so changing the hook means adding its new hash — and the\n * old one stays, which is the whole point.\n */\nexport const SHIPPED_HOOK_SCRIPT_SHA256S: readonly string[] = [\n \"335c56f268876293c93696cb557c0ff3d8e16b60f81f67ebccbab75b0df457ac\", // 4451138e43 — first version\n \"d624f805e1eb635d87cf769ad5e6f877d07d6aa8d547052d2d7ce9d6d6b3a27b\", // ac7c5059d2 — Windows paths\n \"25c307e0c9a8838703c6e59ab5ea62ff249966823f071d26dd0dd8c2508f83a4\", // c694488bfe — CLI predating verify\n \"7a0eeaa301f3cb6b90d5675199ccfcb8fe1c2a80a327e3f7b53bc82c3f4541c2\", // af6eac33cb — rebase.json config dir\n \"dbdbfcec9c4c4e1d2643900a615585594869f6ba9fc19b5652013526367363f6\", // 08a7cd9ec8 — skip when not installed\n \"beda0ca36c3700933aab02162bca47b582a6c231bf94e494bbe84131d5e72fa8\" // backend/schema and frontend/src/cms, not config/collections\n];\n\n/** The hash {@link SHIPPED_HOOK_SCRIPT_SHA256S} records for a script's text. */\nexport function hookScriptSha256(text: string): string {\n return createHash(\"sha256\").update(text.replace(/\\r\\n/g, \"\\n\")).digest(\"hex\");\n}\n\n/**\n * Install the Claude Code guardrail into a project: the hook script, and its\n * registration in `.claude/settings.json`.\n *\n * A script the developer edited is kept unless `force`; a version this CLI\n * shipped earlier is replaced. The settings are always merged, never\n * overwritten.\n */\nexport function installAgentHooks(\n projectDir: string,\n { force = false, templateDir = path.join(cliPackageRoot(), \"templates\", \"template\") }: { force?: boolean; templateDir?: string } = {}\n): HookWriteResult[] {\n const shippedScript = fs.readFileSync(path.join(templateDir, AGENT_HOOK_SCRIPT), \"utf-8\");\n const scriptPath = path.join(projectDir, AGENT_HOOK_SCRIPT);\n let scriptStatus: HookWriteStatus;\n if (!fs.existsSync(scriptPath)) {\n scriptStatus = \"added\";\n } else {\n const current = fs.readFileSync(scriptPath, \"utf-8\");\n if (current === shippedScript) {\n scriptStatus = \"present\";\n } else {\n const ours = SHIPPED_HOOK_SCRIPT_SHA256S.includes(hookScriptSha256(current));\n scriptStatus = force || ours ? \"replaced\" : \"kept\";\n }\n }\n if (scriptStatus === \"added\" || scriptStatus === \"replaced\") {\n fs.mkdirSync(path.dirname(scriptPath), { recursive: true });\n fs.writeFileSync(scriptPath, shippedScript, \"utf-8\");\n }\n if (scriptStatus !== \"kept\") fs.chmodSync(scriptPath, 0o755);\n\n const settingsStatus = mergeHookSettings(\n path.join(projectDir, AGENT_HOOK_SETTINGS),\n fs.readFileSync(path.join(templateDir, AGENT_HOOK_SETTINGS), \"utf-8\")\n );\n return [\n { file: AGENT_HOOK_SCRIPT, status: scriptStatus },\n { file: AGENT_HOOK_SETTINGS, status: settingsStatus }\n ];\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA6BA,IAAa,kBAAkB;;AAG/B,IAAa,cAAc;;AAG3B,IAAa,UAAU;;;;;;;;;;;;;;;;;AAwBvB,SAAgB,UAAU,IAA+B;CACrD,OAAO,OAAO,QACR;EAAE,SAAS;EAAO,MAAM,CAAC,QAAQ,OAAO;CAAE,IAC1C;EAAE,SAAS;EAAQ,MAAM,CAAC,QAAQ,OAAO;CAAE;AACrD;AAiBA,SAAS,SAAS,OAAkD;CAChE,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAC9E;;;;;;;;;AAUA,SAAS,cAAc,UAAkB,KAAa,OAAgD;CAClG,IAAI,MAA+B,CAAC;CACpC,IAAI,GAAG,WAAW,QAAQ,GAAG;EACzB,IAAI;EACJ,IAAI;GACA,SAAS,KAAK,MAAM,GAAG,aAAa,UAAU,OAAO,CAAC;EAC1D,QAAQ;GACJ,OAAO;EACX;EACA,IAAI,CAAC,SAAS,MAAM,GAAG,OAAO;EAC9B,MAAM;CACV;CAEA,MAAM,UAAU,IAAI,QAAQ,CAAC;CAC7B,IAAI,CAAC,SAAS,OAAO,GAAG,OAAO;CAC/B,IAAA,YAAuB,SAAS,OAAO;CAEvC,IAAI,OAAO;EAAE,GAAG;GAAU,kBAAkB;CAAM;CAClD,GA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AAG,aAAa,KAAK,KAAK,aAAa,iBAAiB,GAAG,OAAO;CACxF,MAAM,aAAa,KAAK,KAAK,YAAY,iBAAiB;CAC1D,IAAI;CACJ,IAAI,CAAC,GAAG,WAAW,UAAU,GACzB,eAAe;MACZ;EACH,MAAM,UAAU,GAAG,aAAa,YAAY,OAAO;EACnD,IAAI,YAAY,eACZ,eAAe;OACZ;GACH,MAAM,OAAO,4BAA4B,SAAS,iBAAiB,OAAO,CAAC;GAC3E,eAAe,SAAS,OAAO,aAAa;EAChD;CACJ;CACA,IAAI,iBAAiB,WAAW,iBAAiB,YAAY;EACzD,GAAG,UAAU,KAAK,QAAQ,UAAU,GAAG,EAAE,WAAW,KAAK,CAAC;EAC1D,GAAG,cAAc,YAAY,eAAe,OAAO;CACvD;CACA,IAAI,iBAAiB,QAAQ,GAAG,UAAU,YAAY,GAAK;CAE3D,MAAM,iBAAiB,kBACnB,KAAK,KAAK,YAAY,mBAAmB,GACzC,GAAG,aAAa,KAAK,KAAK,aAAa,mBAAmB,GAAG,OAAO,CACxE;CACA,OAAO,CACH;EAAE,MAAM;EAAmB,QAAQ;CAAa,GAChD;EAAE,MAAM;EAAqB,QAAQ;CAAe,CACxD;AACJ"}
|
|
1
|
+
{"version":3,"file":"agent-setup-Cg_zBWoW.js","names":[],"sources":["../src/commands/agent-setup.ts"],"sourcesContent":["/**\n * Setting a project up for the AI coding assistants a developer uses: the\n * Rebase skills, and the Rebase MCP server in each assistant's own config.\n *\n * `rebase init` used to end by *printing* `rebase skills install`, and nothing\n * ran it — so a generated project had pointer files telling every assistant to\n * read skills that were not there, and an MCP server only Claude Code knew\n * about. This asks once, while the project is being made, pre-ticking the\n * assistants installed on the machine.\n */\nimport chalk from \"chalk\";\nimport { createHash } from \"crypto\";\nimport fs from \"fs\";\nimport path from \"path\";\nimport inquirer from \"inquirer\";\nimport {\n AGENT_KEYS,\n AGENTS,\n type AgentKey,\n detectInstalledAgents,\n installSkills,\n type LoadedSkill,\n loadBundledSkills\n} from \"./skills\";\nimport { fileURLToPath } from \"url\";\nimport { detectPackageManager, type PackageManager } from \"../utils/package-manager\";\nimport { cliVersion } from \"../utils/version\";\n\n/** The name the server is registered under, in every config. */\nexport const MCP_SERVER_NAME = \"rebase\";\n\n/** The MCP server's package: a devDependency of the project, pinned with the rest. */\nexport const MCP_PACKAGE = \"@rebasepro/mcp\";\n\n/** The bin {@link MCP_PACKAGE} declares. */\nexport const MCP_BIN = \"rebase-mcp\";\n\n/** The command an assistant spawns, and its arguments. */\nexport interface McpLaunch {\n command: string;\n args: string[];\n}\n\n/**\n * How an assistant starts the Rebase MCP server: the project's own copy, through\n * the project's package manager.\n *\n * Not `npx -y @rebasepro/mcp`, which fetched the newest release on every first\n * start. The server drives the project's own CLI (`pnpm exec rebase …`) and calls\n * the project's own backend (`/api/admin/schema/plan`, …), whose versions the\n * lockfile pins — so a server from the registry ran ahead of both, at every\n * start, and downloaded before it could answer. `@rebasepro/mcp` is a\n * devDependency of the scaffold, pinned to the CLI's version like every other\n * `@rebasepro` package, and this runs that copy.\n *\n * `npx --no`, not `npx`: an assistant spawns the server with no TTY, and npx\n * then assumes \"yes\" and installs a missing package from the registry under the\n * name it was given. `--no` makes a missing install an error instead.\n */\nexport function mcpLaunch(pm: PackageManager): McpLaunch {\n return pm === \"npm\"\n ? { command: \"npx\", args: [\"--no\", MCP_BIN] }\n : { command: \"pnpm\", args: [\"exec\", MCP_BIN] };\n}\n\n/** What writing one MCP config did. */\nexport type McpWriteStatus =\n /** The file was created, or the server was added beside the ones in it. */\n | \"added\"\n /** A `rebase` server was already there. It is left exactly as it was. */\n | \"present\"\n /** The file exists but is not something this can edit without losing data. */\n | \"unreadable\";\n\nexport interface McpWriteResult {\n /** Project-relative path of the config file. */\n file: string;\n status: McpWriteStatus;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\n/**\n * Add the server to a JSON config under `key`, keeping everything else in it.\n *\n * A file that does not parse as plain JSON is left alone: VS Code and Gemini\n * both accept comments in these files, and rewriting one through\n * `JSON.stringify` would delete them. Refusing costs one line of hand-editing;\n * the alternative silently costs the developer theirs.\n */\nfunction addJsonServer(filePath: string, key: string, entry: Record<string, unknown>): McpWriteStatus {\n let doc: Record<string, unknown> = {};\n if (fs.existsSync(filePath)) {\n let parsed: unknown;\n try {\n parsed = JSON.parse(fs.readFileSync(filePath, \"utf-8\"));\n } catch {\n return \"unreadable\";\n }\n if (!isRecord(parsed)) return \"unreadable\";\n doc = parsed;\n }\n\n const servers = doc[key] ?? {};\n if (!isRecord(servers)) return \"unreadable\";\n if (MCP_SERVER_NAME in servers) return \"present\";\n\n doc[key] = { ...servers, [MCP_SERVER_NAME]: entry };\n fs.mkdirSync(path.dirname(filePath), { recursive: true });\n fs.writeFileSync(filePath, `${JSON.stringify(doc, null, 2)}\\n`, \"utf-8\");\n return \"added\";\n}\n\n/**\n * The Codex block, as TOML. Appended rather than merged: there is no TOML\n * parser here, and an append keeps every byte already in the file.\n */\nexport function renderCodexServer(projectDir: string, launch: McpLaunch): string {\n // A JSON string literal is a valid TOML basic string for these values.\n const str = (v: string) => JSON.stringify(v);\n return [\n `[mcp_servers.${MCP_SERVER_NAME}]`,\n `command = ${str(launch.command)}`,\n `args = [${launch.args.map(str).join(\", \")}]`,\n \"\",\n `[mcp_servers.${MCP_SERVER_NAME}.env]`,\n `REBASE_PROJECT_DIR = ${str(projectDir)}`,\n \"\"\n ].join(\"\\n\");\n}\n\nfunction addCodexServer(filePath: string, projectDir: string, launch: McpLaunch): McpWriteStatus {\n const existing = fs.existsSync(filePath) ? fs.readFileSync(filePath, \"utf-8\") : \"\";\n const table = new RegExp(`^\\\\s*\\\\[mcp_servers\\\\.(?:${MCP_SERVER_NAME}|\"${MCP_SERVER_NAME}\")\\\\]`, \"m\");\n if (table.test(existing)) return \"present\";\n\n const separator = existing === \"\" ? \"\" : existing.endsWith(\"\\n\") ? \"\\n\" : \"\\n\\n\";\n fs.mkdirSync(path.dirname(filePath), { recursive: true });\n fs.writeFileSync(filePath, `${existing}${separator}${renderCodexServer(projectDir, launch)}`, \"utf-8\");\n return \"added\";\n}\n\n/**\n * Register the Rebase MCP server in the agent's project-level config, started\n * through the project's package manager (see {@link mcpLaunch}).\n *\n * Returns null for an agent with no project-level config to write.\n */\nexport function writeMcpConfig(\n agentKey: AgentKey,\n projectDir: string,\n pm: PackageManager = detectPackageManager(projectDir)\n): McpWriteResult | null {\n const mcp = AGENTS[agentKey].mcp;\n if (!mcp) return null;\n\n const filePath = path.join(projectDir, mcp.file);\n const env = { REBASE_PROJECT_DIR: mcp.projectDir };\n const { command, args } = mcpLaunch(pm);\n const write = (): McpWriteStatus => {\n switch (mcp.format) {\n case \"mcpServers\":\n return addJsonServer(filePath, \"mcpServers\", { command, args, env });\n case \"vscode\":\n // VS Code's own shape: `servers`, and an explicit transport.\n return addJsonServer(filePath, \"servers\", { type: \"stdio\", command, args, env });\n case \"codexToml\":\n return addCodexServer(filePath, mcp.projectDir, { command, args });\n }\n };\n return { file: mcp.file, status: write() };\n}\n\n/** What making sure the project depends on the MCP server did. */\nexport type McpDependencyStatus =\n /** Added to `devDependencies`, at this CLI's version: an install is due. */\n | \"added\"\n /** Already a dependency. Left at the version the project chose. */\n | \"present\"\n /** No `package.json`, or one that is not plain JSON: left alone. */\n | \"unreadable\";\n\n/**\n * Make the project depend on {@link MCP_PACKAGE}, which the config written by\n * {@link writeMcpConfig} runs from the project's own install.\n *\n * Pinned to this CLI's version, as `rebase init` pins every `@rebasepro`\n * package; a project that already lists it keeps its own choice.\n */\nexport function ensureMcpDependency(projectDir: string): McpDependencyStatus {\n const manifestPath = path.join(projectDir, \"package.json\");\n if (!fs.existsSync(manifestPath)) return \"unreadable\";\n const text = fs.readFileSync(manifestPath, \"utf-8\");\n let manifest: unknown;\n try {\n manifest = JSON.parse(text);\n } catch {\n return \"unreadable\";\n }\n if (!isRecord(manifest)) return \"unreadable\";\n for (const field of [\"dependencies\", \"devDependencies\"] as const) {\n const deps = manifest[field];\n if (isRecord(deps) && MCP_PACKAGE in deps) return \"present\";\n }\n const devDependencies = isRecord(manifest.devDependencies) ? manifest.devDependencies : {};\n const version = cliVersion();\n manifest.devDependencies = { ...devDependencies, [MCP_PACKAGE]: version === \"unknown\" ? \"latest\" : version };\n // The file's own indentation, so the change is one line in a diff.\n const indent = /\\n([ \\t]+)\"/.exec(text)?.[1] ?? \" \";\n fs.writeFileSync(manifestPath, `${JSON.stringify(manifest, null, indent)}\\n`, \"utf-8\");\n return \"added\";\n}\n\n/**\n * Point the scaffold's `.mcp.json` at the project's package manager.\n *\n * The template ships the pnpm spelling (`pnpm exec rebase-mcp`); an npm project\n * has no pnpm to run it with. Only the entry the template wrote is rewritten.\n */\nexport function retargetScaffoldMcpConfig(projectDir: string, pm: PackageManager): void {\n const filePath = path.join(projectDir, \".mcp.json\");\n if (!fs.existsSync(filePath)) return;\n let doc: unknown;\n try {\n doc = JSON.parse(fs.readFileSync(filePath, \"utf-8\"));\n } catch {\n return;\n }\n const servers = isRecord(doc) ? doc.mcpServers : undefined;\n const entry = isRecord(servers) ? servers[MCP_SERVER_NAME] : undefined;\n const shipped = mcpLaunch(\"pnpm\");\n if (!isRecord(doc) || !isRecord(servers) || !isRecord(entry)) return;\n if (entry.command !== shipped.command || JSON.stringify(entry.args) !== JSON.stringify(shipped.args)) return;\n const wanted = mcpLaunch(pm);\n if (wanted.command === shipped.command && JSON.stringify(wanted.args) === JSON.stringify(shipped.args)) return;\n servers[MCP_SERVER_NAME] = { ...entry, command: wanted.command, args: wanted.args };\n fs.writeFileSync(filePath, `${JSON.stringify(doc, null, 4)}\\n`, \"utf-8\");\n}\n\n/**\n * Whether the agent's project-level config already registers the Rebase\n * server: `null` for an agent that has no such config, `false` when the file\n * is missing or does not name it. Reads only — for the hint `rebase skills\n * install` prints when it was not asked to write one.\n */\nexport function mcpServerRegistered(agentKey: AgentKey, projectDir: string): boolean | null {\n const mcp = AGENTS[agentKey].mcp;\n if (!mcp) return null;\n const filePath = path.join(projectDir, mcp.file);\n if (!fs.existsSync(filePath)) return false;\n const text = fs.readFileSync(filePath, \"utf-8\");\n if (mcp.format === \"codexToml\") {\n return new RegExp(`^\\\\s*\\\\[mcp_servers\\\\.(?:${MCP_SERVER_NAME}|\"${MCP_SERVER_NAME}\")\\\\]`, \"m\").test(text);\n }\n try {\n const doc: unknown = JSON.parse(text);\n const servers = isRecord(doc) ? doc[mcp.format === \"vscode\" ? \"servers\" : \"mcpServers\"] : undefined;\n return isRecord(servers) && MCP_SERVER_NAME in servers;\n } catch {\n // Not plain JSON (comments): cannot tell, so do not nag.\n return null;\n }\n}\n\n/** What `configureAgents` did for one agent. */\nexport interface AgentSetupResult {\n agent: AgentKey;\n /** Skills written, or null when the bundle could not be loaded. */\n skills: number | null;\n /** An earlier agent in the same run that already wrote the skills directory. */\n sharedWith?: AgentKey;\n mcp: McpWriteResult | null;\n}\n\n/**\n * Install the skills and register the MCP server for each agent.\n *\n * Never throws for a missing skills bundle — the scaffold it runs inside must\n * not fail over its assistants — and reports it as `skills: null` instead.\n */\nexport function configureAgents(\n agents: readonly AgentKey[],\n projectDir: string,\n load: () => LoadedSkill[] = loadBundledSkills,\n pm: PackageManager = detectPackageManager(projectDir)\n): { results: AgentSetupResult[]; skillsError?: string; mcpDependency?: McpDependencyStatus } {\n let skillsError: string | undefined;\n let installed: ReturnType<typeof installSkills> = [];\n try {\n installed = installSkills(agents, load(), projectDir);\n } catch (err) {\n skillsError = err instanceof Error ? err.message : String(err);\n }\n\n const results = agents.map((agent): AgentSetupResult => {\n const skills = installed.find(r => r.agent === agent);\n return {\n agent,\n skills: skills ? skills.skills : null,\n sharedWith: skills?.sharedWith,\n mcp: writeMcpConfig(agent, projectDir, pm)\n };\n });\n // A config that runs the project's copy of the server needs the project to\n // have one.\n const registered = results.some(r => r.mcp?.status === \"added\" || r.mcp?.status === \"present\");\n return { results, skillsError, ...(registered && { mcpDependency: ensureMcpDependency(projectDir) }) };\n}\n\n/** The line to print when {@link ensureMcpDependency} changed or could not change the manifest. */\nexport function mcpDependencyNote(status: McpDependencyStatus | undefined, pm: PackageManager): string | undefined {\n if (status === \"added\") {\n return `Added ${MCP_PACKAGE} to devDependencies — run \\`${pm} install\\` before your assistant starts it.`;\n }\n if (status === \"unreadable\") {\n return `Could not add ${MCP_PACKAGE} to package.json — add it to devDependencies by hand; the MCP config runs the project's own copy.`;\n }\n return undefined;\n}\n\n/** One line per agent, for the scaffold's output. */\nexport function printAgentSetup(\n { results, skillsError, mcpDependency }: ReturnType<typeof configureAgents>,\n pm: PackageManager = \"pnpm\"\n): void {\n for (const result of results) {\n const agent = AGENTS[result.agent];\n const parts: string[] = [];\n\n if (result.sharedWith) {\n parts.push(`skills in ${chalk.gray(agent.targetDir)} ${chalk.gray(`(shared with ${AGENTS[result.sharedWith].label})`)}`);\n } else if (result.skills !== null) {\n parts.push(`${result.skills} skills in ${chalk.gray(agent.targetDir)}`);\n }\n\n if (result.mcp?.status === \"added\") {\n parts.push(`MCP server in ${chalk.gray(result.mcp.file)}`);\n } else if (result.mcp?.status === \"present\") {\n parts.push(`MCP server already in ${chalk.gray(result.mcp.file)}`);\n }\n\n // A tick is a claim that something was written; with nothing, it isn't.\n const mark = parts.length ? chalk.green(\"✓\") : chalk.yellow(\"!\");\n console.log(` ${mark} ${chalk.bold(agent.label)}${parts.length ? ` — ${parts.join(\", \")}` : \"\"}`);\n\n if (result.mcp?.status === \"unreadable\") {\n console.log(chalk.yellow(` ${result.mcp.file} is not plain JSON, so it was left alone — add the \"${MCP_SERVER_NAME}\" server by hand.`));\n } else if (!result.mcp) {\n console.log(chalk.gray(` ${agent.label} has no project-level MCP config — add @rebasepro/mcp in its MCP settings.`));\n }\n }\n\n const dependencyNote = mcpDependencyNote(mcpDependency, pm);\n if (dependencyNote) console.log(chalk.gray(` ${dependencyNote}`));\n\n if (skillsError) {\n console.log(chalk.yellow(` Could not install the Rebase skills: ${skillsError}`));\n console.log(chalk.yellow(\" Run `rebase skills install` in the project once dependencies are installed.\"));\n }\n}\n\n/**\n * Ask whether to set up AI agents, then which, pre-ticking what is installed.\n *\n * Interactive only; the caller has already refused a non-TTY. Returns [] when\n * the developer says no or unticks everything.\n */\nexport async function promptForAgents(home?: string): Promise<AgentKey[]> {\n const { configure } = await inquirer.prompt([{\n type: \"confirm\",\n name: \"configure\",\n message: \"Set up Rebase skills and the Rebase MCP server for your AI coding agent(s)?\",\n default: true\n }]);\n if (!configure) return [];\n\n // Installed first, so the pre-ticked boxes are the ones under the cursor.\n const detected = detectInstalledAgents(home);\n const installed = [...detected.filter(a => a.found), ...detected.filter(a => !a.found)];\n console.log(\"\");\n console.log(\"Detecting installed AI coding agents...\");\n for (const { label, marker, found } of installed) {\n if (found) console.log(` ${chalk.green(\"✓\")} ${label} — ${marker}`);\n else if (marker) console.log(chalk.gray(` ✗ ${label} — ${marker} (not found)`));\n else console.log(chalk.gray(` · ${label} — can't be detected; tick it below if you use it`));\n }\n console.log(\"\");\n\n const { selectedAgents } = await inquirer.prompt([{\n type: \"checkbox\",\n name: \"selectedAgents\",\n message: \"Select agents to configure:\",\n choices: installed.map(({ key, label, found }) => {\n const { targetDir, mcp } = AGENTS[key];\n const writes = mcp ? `${targetDir} + ${mcp.file}` : targetDir;\n return { name: `${label} ${chalk.gray(`— ${writes}`)}`, short: label, value: key, checked: found };\n })\n }]);\n\n return AGENT_KEYS.filter(key => selectedAgents.includes(key));\n}\n\n// ─── Claude Code guardrail hooks ──────────────────────────────────────────────\n\n/**\n * The guardrail every scaffold ships for Claude Code: a PostToolUse hook that\n * runs `rebase verify --quiet` after each edit under `backend/schema/` (or the\n * `tables` directory rebase.json names) or `frontend/src/cms/`, and hands any\n * problem back to the agent (exit 2, the message on stderr).\n *\n * The script keeps the file name it first shipped with: it is how\n * {@link installAgentHooks} and the settings entry find a copy already installed.\n *\n * The files live in the template, under `.claude/`, so `rebase init` copies\n * them like everything else and `rebase skills --hooks` installs the very same\n * bytes into a project that predates them. Paths are project-relative.\n */\nexport const AGENT_HOOK_SCRIPT = \".claude/hooks/post-edit-collection.sh\";\nexport const AGENT_HOOK_SETTINGS = \".claude/settings.json\";\n\n/** What installing one hook file did. */\nexport type HookWriteStatus =\n /** Written, or merged into the settings beside the hooks already there. */\n | \"added\"\n /** Already there, unchanged — or, for the settings, already registered. */\n | \"present\"\n /** There, and edited: left as it was. `--force` replaces it. */\n | \"kept\"\n /** There, edited, and replaced because `--force` asked. */\n | \"replaced\"\n /** The settings file is not plain JSON with a `hooks` object: left alone. */\n | \"unreadable\";\n\nexport interface HookWriteResult {\n file: string;\n status: HookWriteStatus;\n}\n\n/** The CLI package's own directory, from wherever this module was bundled to. */\nexport function cliPackageRoot(): string {\n let dir = path.dirname(fileURLToPath(import.meta.url));\n while (dir !== path.dirname(dir)) {\n const manifest = path.join(dir, \"package.json\");\n if (fs.existsSync(manifest)) {\n try {\n const parsed: unknown = JSON.parse(fs.readFileSync(manifest, \"utf-8\"));\n if (isRecord(parsed) && parsed.name === \"@rebasepro/cli\") return dir;\n } catch {\n // Not ours; keep walking.\n }\n }\n dir = path.dirname(dir);\n }\n throw new Error(\"Could not find the @rebasepro/cli package directory to read the hook templates from.\");\n}\n\n/**\n * Register the shipped PostToolUse hook in an existing settings file, keeping\n * every other setting and hook in it. A file that is not plain JSON is left\n * alone, for the reason {@link addJsonServer} gives.\n */\nfunction mergeHookSettings(filePath: string, shippedText: string): HookWriteStatus {\n if (!fs.existsSync(filePath)) {\n fs.mkdirSync(path.dirname(filePath), { recursive: true });\n fs.writeFileSync(filePath, shippedText, \"utf-8\");\n return \"added\";\n }\n const text = fs.readFileSync(filePath, \"utf-8\");\n let doc: unknown;\n try {\n doc = JSON.parse(text);\n } catch {\n return \"unreadable\";\n }\n const shipped: unknown = JSON.parse(shippedText);\n const shippedEntries = isRecord(shipped) && isRecord(shipped.hooks) && Array.isArray(shipped.hooks.PostToolUse)\n ? shipped.hooks.PostToolUse\n : [];\n if (!isRecord(doc)) return \"unreadable\";\n const hooks = doc.hooks ?? {};\n if (!isRecord(hooks)) return \"unreadable\";\n const post = hooks.PostToolUse ?? [];\n if (!Array.isArray(post)) return \"unreadable\";\n if (JSON.stringify(post).includes(path.basename(AGENT_HOOK_SCRIPT))) return \"present\";\n\n doc.hooks = { ...hooks, PostToolUse: [...post, ...shippedEntries] };\n const indent = /\\n([ \\t]+)\"/.exec(text)?.[1] ?? \" \";\n fs.writeFileSync(filePath, `${JSON.stringify(doc, null, indent)}\\n`, \"utf-8\");\n return \"added\";\n}\n\n/**\n * The SHA-256 of every version of `post-edit-collection.sh` this CLI has ever\n * written, oldest first, the current one last — hashed with CRLF read as LF,\n * so a Windows checkout of an untouched copy still matches.\n *\n * A copy that differs from today's script was read as \"edited\" and kept, so a\n * fix to the hook never reached a project scaffolded before it: `rebase skills\n * install --hooks` answered \"was edited, so it was kept — pass --force\" about a\n * file nobody had touched. A copy whose hash is one of ours is our old\n * version, and is replaced like any stale file; only a copy we never shipped is\n * the developer's.\n *\n * Append, never replace: `agent-hooks.test.ts` fails when the shipped script's\n * hash is not here, so changing the hook means adding its new hash — and the\n * old one stays, which is the whole point.\n */\nexport const SHIPPED_HOOK_SCRIPT_SHA256S: readonly string[] = [\n \"335c56f268876293c93696cb557c0ff3d8e16b60f81f67ebccbab75b0df457ac\", // 4451138e43 — first version\n \"d624f805e1eb635d87cf769ad5e6f877d07d6aa8d547052d2d7ce9d6d6b3a27b\", // ac7c5059d2 — Windows paths\n \"25c307e0c9a8838703c6e59ab5ea62ff249966823f071d26dd0dd8c2508f83a4\", // c694488bfe — CLI predating verify\n \"7a0eeaa301f3cb6b90d5675199ccfcb8fe1c2a80a327e3f7b53bc82c3f4541c2\", // af6eac33cb — rebase.json config dir\n \"dbdbfcec9c4c4e1d2643900a615585594869f6ba9fc19b5652013526367363f6\", // 08a7cd9ec8 — skip when not installed\n \"beda0ca36c3700933aab02162bca47b582a6c231bf94e494bbe84131d5e72fa8\" // backend/schema and frontend/src/cms, not config/collections\n];\n\n/** The hash {@link SHIPPED_HOOK_SCRIPT_SHA256S} records for a script's text. */\nexport function hookScriptSha256(text: string): string {\n return createHash(\"sha256\").update(text.replace(/\\r\\n/g, \"\\n\")).digest(\"hex\");\n}\n\n/**\n * Install the Claude Code guardrail into a project: the hook script, and its\n * registration in `.claude/settings.json`.\n *\n * A script the developer edited is kept unless `force`; a version this CLI\n * shipped earlier is replaced. The settings are always merged, never\n * overwritten.\n */\nexport function installAgentHooks(\n projectDir: string,\n { force = false, templateDir = path.join(cliPackageRoot(), \"templates\", \"template\") }: { force?: boolean; templateDir?: string } = {}\n): HookWriteResult[] {\n const shippedScript = fs.readFileSync(path.join(templateDir, AGENT_HOOK_SCRIPT), \"utf-8\");\n const scriptPath = path.join(projectDir, AGENT_HOOK_SCRIPT);\n let scriptStatus: HookWriteStatus;\n if (!fs.existsSync(scriptPath)) {\n scriptStatus = \"added\";\n } else {\n const current = fs.readFileSync(scriptPath, \"utf-8\");\n if (current === shippedScript) {\n scriptStatus = \"present\";\n } else {\n const ours = SHIPPED_HOOK_SCRIPT_SHA256S.includes(hookScriptSha256(current));\n scriptStatus = force || ours ? \"replaced\" : \"kept\";\n }\n }\n if (scriptStatus === \"added\" || scriptStatus === \"replaced\") {\n fs.mkdirSync(path.dirname(scriptPath), { recursive: true });\n fs.writeFileSync(scriptPath, shippedScript, \"utf-8\");\n }\n if (scriptStatus !== \"kept\") fs.chmodSync(scriptPath, 0o755);\n\n const settingsStatus = mergeHookSettings(\n path.join(projectDir, AGENT_HOOK_SETTINGS),\n fs.readFileSync(path.join(templateDir, AGENT_HOOK_SETTINGS), \"utf-8\")\n );\n return [\n { file: AGENT_HOOK_SCRIPT, status: scriptStatus },\n { file: AGENT_HOOK_SETTINGS, status: settingsStatus }\n ];\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA6BA,IAAa,kBAAkB;;AAG/B,IAAa,cAAc;;AAG3B,IAAa,UAAU;;;;;;;;;;;;;;;;;AAwB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AU,YAAY,GAAK;CAE3D,MAAM,iBAAiB,kBACnB,KAAK,KAAK,YAAY,mBAAmB,GACzC,GAAG,aAAa,KAAK,KAAK,aAAa,mBAAmB,GAAG,OAAO,CACxE;CACA,OAAO,CACH;EAAE,MAAM;EAAmB,QAAQ;CAAa,GAChD;EAAE,MAAM;EAAqB,QAAQ;CAAe,CACxD;AACJ"}
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import { a as wantsHelp, n as parseCommandArgs, t as UsageError } from "./args-DHyrshtI.js";
|
|
2
|
+
import { a as projectTarget, d as PROJECT_TARGET_FLAGS, i as printProjectHelp, l as startProjectCommand, r as parsedLine, s as reportTargetError } from "./project-command-Cl9EZzjr.js";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
import fs from "fs";
|
|
5
|
+
//#region src/commands/api.ts
|
|
6
|
+
/**
|
|
7
|
+
* CLI command: rebase api [METHOD] <path>
|
|
8
|
+
*
|
|
9
|
+
* Any route a Rebase app serves, with the target and credential every project
|
|
10
|
+
* command resolves (`utils/project-target.ts`): the local `rebase dev`, a
|
|
11
|
+
* server named by `--url` or `REBASE_BASE_URL`, or a Rebase Cloud project
|
|
12
|
+
* through the console's Studio proxy. Shaped after `gh api`.
|
|
13
|
+
*
|
|
14
|
+
* The answer is printed as it came: JSON pretty-printed, anything else as
|
|
15
|
+
* text. A non-2xx answer is still printed — the app's error envelope is the
|
|
16
|
+
* useful part — and the command exits 1.
|
|
17
|
+
*
|
|
18
|
+
* It exists so the long tail needs no command of its own: a row's history, a
|
|
19
|
+
* materialized view's refresh, the RLS audit, the schema editor's status, a
|
|
20
|
+
* custom function, `/api/meta/contract`. The everyday operations have their
|
|
21
|
+
* own commands (`data`, `users`, `cron`, `storage`, …), which validate their
|
|
22
|
+
* input and confirm what they delete.
|
|
23
|
+
*/
|
|
24
|
+
/** The flags `rebase api` takes, on top of the target flags. */
|
|
25
|
+
var API_FLAGS = {
|
|
26
|
+
...PROJECT_TARGET_FLAGS,
|
|
27
|
+
"--method": String,
|
|
28
|
+
"-X": "--method",
|
|
29
|
+
"--field": [String],
|
|
30
|
+
"-f": "--field",
|
|
31
|
+
"--raw-field": [String],
|
|
32
|
+
"-F": "--raw-field",
|
|
33
|
+
"--input": String,
|
|
34
|
+
"--header": [String],
|
|
35
|
+
"-H": "--header",
|
|
36
|
+
"--include": Boolean,
|
|
37
|
+
"-i": "--include",
|
|
38
|
+
"--silent": Boolean
|
|
39
|
+
};
|
|
40
|
+
var METHODS = /* @__PURE__ */ new Set([
|
|
41
|
+
"GET",
|
|
42
|
+
"POST",
|
|
43
|
+
"PUT",
|
|
44
|
+
"PATCH",
|
|
45
|
+
"DELETE",
|
|
46
|
+
"HEAD",
|
|
47
|
+
"OPTIONS"
|
|
48
|
+
]);
|
|
49
|
+
/**
|
|
50
|
+
* The path a request goes to: `/…` as written, anything else under `/api/`
|
|
51
|
+
* — `data/posts` is `/api/data/posts`, as `gh api repos/x` is relative to its
|
|
52
|
+
* API root. A full URL is refused: the target flags say where requests go, so
|
|
53
|
+
* a URL in the path would send the credential somewhere they did not choose.
|
|
54
|
+
*/
|
|
55
|
+
function resolveApiPath(raw) {
|
|
56
|
+
const trimmed = raw.trim();
|
|
57
|
+
if (/^[a-z][a-z0-9+.-]*:\/\//i.test(trimmed)) throw new UsageError(`\`rebase api\` takes a path, not a URL (${trimmed}). Name the server with --url and the path after it: rebase api --url https://example.com /api/health.`);
|
|
58
|
+
return trimmed.startsWith("/") ? trimmed : `/api/${trimmed}`;
|
|
59
|
+
}
|
|
60
|
+
/** `key=value` split at its first `=`. */
|
|
61
|
+
function splitField(raw, flag) {
|
|
62
|
+
const at = raw.indexOf("=");
|
|
63
|
+
if (at <= 0) throw new UsageError(`${flag} takes key=value (got "${raw}").`);
|
|
64
|
+
return [raw.slice(0, at), raw.slice(at + 1)];
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* A typed field's value, as `gh api -F` reads one: `true`, `false` and `null`
|
|
68
|
+
* as themselves, a number as a number, `@file` as that file's text, a JSON
|
|
69
|
+
* array or object as JSON, anything else as the string.
|
|
70
|
+
*/
|
|
71
|
+
function typedFieldValue(raw) {
|
|
72
|
+
if (raw === "true") return true;
|
|
73
|
+
if (raw === "false") return false;
|
|
74
|
+
if (raw === "null") return null;
|
|
75
|
+
if (/^-?\d+(\.\d+)?$/.test(raw)) return Number(raw);
|
|
76
|
+
if (raw.startsWith("@")) {
|
|
77
|
+
const file = raw.slice(1);
|
|
78
|
+
try {
|
|
79
|
+
return fs.readFileSync(file === "-" ? 0 : file, "utf8");
|
|
80
|
+
} catch (e) {
|
|
81
|
+
throw new UsageError(`Cannot read ${file}: ${e instanceof Error ? e.message : String(e)}`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (raw.startsWith("{") && raw.endsWith("}") || raw.startsWith("[") && raw.endsWith("]")) try {
|
|
85
|
+
return JSON.parse(raw);
|
|
86
|
+
} catch {
|
|
87
|
+
return raw;
|
|
88
|
+
}
|
|
89
|
+
return raw;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Resolve a line into the request it describes. Exported for its tests.
|
|
93
|
+
*
|
|
94
|
+
* The method is the first argument when it is one (`rebase api DELETE
|
|
95
|
+
* data/posts/1`), `--method`, or GET — POST when the line carries a body.
|
|
96
|
+
* Fields go into the query string of a GET, HEAD or DELETE and into a JSON
|
|
97
|
+
* body otherwise, as with `gh api`.
|
|
98
|
+
*/
|
|
99
|
+
function resolveApiRequest(rawArgs) {
|
|
100
|
+
const { flags, positionals } = parseApiLine(rawArgs);
|
|
101
|
+
let words = positionals;
|
|
102
|
+
let method = flags["--method"]?.toUpperCase();
|
|
103
|
+
if (words.length === 2) {
|
|
104
|
+
const first = words[0].toUpperCase();
|
|
105
|
+
if (!METHODS.has(first)) throw new UsageError(`\`rebase api\` takes [METHOD] <path>; "${words[0]}" is not an HTTP method.`);
|
|
106
|
+
if (method && method !== first) throw new UsageError(`The method is given twice: ${first} and --method ${method}.`);
|
|
107
|
+
method = first;
|
|
108
|
+
words = words.slice(1);
|
|
109
|
+
}
|
|
110
|
+
if (words.length !== 1) throw new UsageError("`rebase api` needs a path: rebase api data/posts (see `rebase api --help`).");
|
|
111
|
+
return {
|
|
112
|
+
plan: buildApiPlan({
|
|
113
|
+
method,
|
|
114
|
+
path: resolveApiPath(words[0]),
|
|
115
|
+
fields: flags["--field"],
|
|
116
|
+
rawFields: flags["--raw-field"],
|
|
117
|
+
input: flags["--input"],
|
|
118
|
+
headers: flags["--header"]
|
|
119
|
+
}),
|
|
120
|
+
flags
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Resolve the parts of a line into the request they describe. Shared by
|
|
125
|
+
* `rebase api` and `rebase functions invoke`. Exported for tests.
|
|
126
|
+
*
|
|
127
|
+
* The method is the one given, or GET — POST with `--input`. Fields go into
|
|
128
|
+
* the query string of a GET, HEAD or DELETE and into a JSON body otherwise.
|
|
129
|
+
* Unlike `gh api`, a field alone never makes the request a POST.
|
|
130
|
+
*/
|
|
131
|
+
function buildApiPlan(parts) {
|
|
132
|
+
const method = parts.method?.toUpperCase();
|
|
133
|
+
if (method && !METHODS.has(method)) throw new UsageError(`--method ${method} is not an HTTP method.`);
|
|
134
|
+
const fields = [...(parts.fields ?? []).map((raw) => splitField(raw, "--field")), ...(parts.rawFields ?? []).map((raw) => {
|
|
135
|
+
const [key, value] = splitField(raw, "--raw-field");
|
|
136
|
+
return [key, typedFieldValue(value)];
|
|
137
|
+
})];
|
|
138
|
+
let input;
|
|
139
|
+
if (parts.input !== void 0) {
|
|
140
|
+
const file = parts.input;
|
|
141
|
+
try {
|
|
142
|
+
input = fs.readFileSync(file === "-" ? 0 : file, "utf8");
|
|
143
|
+
} catch (e) {
|
|
144
|
+
throw new UsageError(`Cannot read --input ${file}: ${e instanceof Error ? e.message : String(e)}`);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
const resolvedMethod = method ?? (input !== void 0 ? "POST" : "GET");
|
|
148
|
+
const inQuery = resolvedMethod === "GET" || resolvedMethod === "HEAD" || resolvedMethod === "DELETE";
|
|
149
|
+
if (input !== void 0 && fields.length > 0 && !inQuery) throw new UsageError("--input is the whole body; fields cannot be added to it. Give one or the other.");
|
|
150
|
+
const headers = {};
|
|
151
|
+
for (const raw of parts.headers ?? []) {
|
|
152
|
+
const at = raw.indexOf(":");
|
|
153
|
+
if (at <= 0) throw new UsageError(`--header takes "Name: value" (got "${raw}").`);
|
|
154
|
+
const name = raw.slice(0, at).trim();
|
|
155
|
+
if (/^authorization$/i.test(name)) throw new UsageError("Pass a bearer with --token, not an Authorization header: the target decides where credentials go.");
|
|
156
|
+
headers[name] = raw.slice(at + 1).trim();
|
|
157
|
+
}
|
|
158
|
+
const query = {};
|
|
159
|
+
const [bare, search] = parts.path.split(/\?(.*)/s, 2);
|
|
160
|
+
if (search) for (const [key, value] of new URLSearchParams(search)) (query[key] ??= []).push(value);
|
|
161
|
+
const plan = {
|
|
162
|
+
method: resolvedMethod,
|
|
163
|
+
path: bare,
|
|
164
|
+
query,
|
|
165
|
+
headers
|
|
166
|
+
};
|
|
167
|
+
if (inQuery) for (const [key, value] of fields) (query[key] ??= []).push(typeof value === "string" ? value : JSON.stringify(value));
|
|
168
|
+
if (input !== void 0) {
|
|
169
|
+
plan.body = input;
|
|
170
|
+
plan.contentType = looksLikeJson(input) ? "application/json" : "application/octet-stream";
|
|
171
|
+
} else if (fields.length > 0 && !inQuery) {
|
|
172
|
+
plan.body = JSON.stringify(Object.fromEntries(fields));
|
|
173
|
+
plan.contentType = "application/json";
|
|
174
|
+
}
|
|
175
|
+
return plan;
|
|
176
|
+
}
|
|
177
|
+
function looksLikeJson(text) {
|
|
178
|
+
try {
|
|
179
|
+
JSON.parse(text);
|
|
180
|
+
return true;
|
|
181
|
+
} catch {
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
function parseApiLine(rawArgs) {
|
|
186
|
+
return parseCommandArgs({
|
|
187
|
+
spec: API_FLAGS,
|
|
188
|
+
rawArgs,
|
|
189
|
+
commandWords: 1,
|
|
190
|
+
command: "api",
|
|
191
|
+
maxPositionals: 2
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
async function apiCommand(rawArgs) {
|
|
195
|
+
startProjectCommand(rawArgs);
|
|
196
|
+
if (wantsHelp(rawArgs)) {
|
|
197
|
+
printApiHelp();
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
const { plan, flags } = parsedLine(() => resolveApiRequest(rawArgs));
|
|
201
|
+
await sendApiPlan(await projectTarget(flags, { command: "api" }), plan, {
|
|
202
|
+
include: flags["--include"] === true,
|
|
203
|
+
silent: flags["--silent"] === true
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Send a resolved request and print the answer as it came: JSON
|
|
208
|
+
* pretty-printed, anything else as text, the status line and headers first
|
|
209
|
+
* with `include`. A non-2xx answer is printed too, and exits 1.
|
|
210
|
+
*/
|
|
211
|
+
async function sendApiPlan(target, plan, options = {}) {
|
|
212
|
+
let res;
|
|
213
|
+
try {
|
|
214
|
+
res = await target.request(plan.path, {
|
|
215
|
+
method: plan.method,
|
|
216
|
+
query: plan.query,
|
|
217
|
+
body: plan.body,
|
|
218
|
+
headers: {
|
|
219
|
+
...plan.headers,
|
|
220
|
+
...plan.contentType ? { "Content-Type": plan.contentType } : {}
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
} catch (e) {
|
|
224
|
+
reportTargetError(e, target);
|
|
225
|
+
}
|
|
226
|
+
if (options.include) {
|
|
227
|
+
process.stdout.write(`HTTP ${res.status} ${res.statusText}\n`);
|
|
228
|
+
res.headers.forEach((value, name) => process.stdout.write(`${name}: ${value}\n`));
|
|
229
|
+
process.stdout.write("\n");
|
|
230
|
+
}
|
|
231
|
+
const text = plan.method === "HEAD" ? "" : await res.text();
|
|
232
|
+
if (!options.silent && text) {
|
|
233
|
+
let printed = text;
|
|
234
|
+
try {
|
|
235
|
+
printed = JSON.stringify(JSON.parse(text), null, 2);
|
|
236
|
+
} catch {}
|
|
237
|
+
process.stdout.write(printed.endsWith("\n") ? printed : `${printed}\n`);
|
|
238
|
+
}
|
|
239
|
+
if (res.status >= 300) {
|
|
240
|
+
process.stderr.write(chalk.red(`✗ HTTP ${res.status} from ${target.label}\n`));
|
|
241
|
+
process.exit(1);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
function printApiHelp() {
|
|
245
|
+
printProjectHelp({
|
|
246
|
+
command: "api",
|
|
247
|
+
usage: "[METHOD] <path>",
|
|
248
|
+
title: "Send any request to the app's API, with the project's credential",
|
|
249
|
+
actions: [{
|
|
250
|
+
action: "[METHOD] <path>",
|
|
251
|
+
description: "data/posts is /api/data/posts; a path starting with / is sent as written",
|
|
252
|
+
flags: [
|
|
253
|
+
["--method, -X <method>", "The HTTP method (else GET; POST with --input — a field alone never writes)"],
|
|
254
|
+
["--field, -f <key=value>", "A string field: query string on GET/HEAD/DELETE, JSON body otherwise"],
|
|
255
|
+
["--raw-field, -F <key=value>", "A typed field: true/false/null, numbers, JSON, @file"],
|
|
256
|
+
["--input <file|->", "The whole request body, from a file or stdin"],
|
|
257
|
+
["--header, -H <\"Name: value\">", "An extra request header (never Authorization: use --token)"],
|
|
258
|
+
["--include, -i", "Print the status line and response headers first"],
|
|
259
|
+
["--silent", "Print nothing; only the exit code says how it went"]
|
|
260
|
+
]
|
|
261
|
+
}],
|
|
262
|
+
notes: [
|
|
263
|
+
"Examples:",
|
|
264
|
+
" rebase api data/posts -f status=eq.published -f limit=5",
|
|
265
|
+
" rebase api POST data/posts -F title=Hello -F published=true",
|
|
266
|
+
" rebase api /api/admin/rls-audit --project acme",
|
|
267
|
+
" rebase api functions/hello --anon",
|
|
268
|
+
"A non-2xx answer is printed and exits 1. The everyday operations have their own commands: rebase data, users, cron, storage, functions, logs."
|
|
269
|
+
]
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
//#endregion
|
|
273
|
+
export { apiCommand, buildApiPlan, sendApiPlan };
|
|
274
|
+
|
|
275
|
+
//# sourceMappingURL=api-TbmW33D7.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-TbmW33D7.js","names":[],"sources":["../src/commands/api.ts"],"sourcesContent":["/**\n * CLI command: rebase api [METHOD] <path>\n *\n * Any route a Rebase app serves, with the target and credential every project\n * command resolves (`utils/project-target.ts`): the local `rebase dev`, a\n * server named by `--url` or `REBASE_BASE_URL`, or a Rebase Cloud project\n * through the console's Studio proxy. Shaped after `gh api`.\n *\n * The answer is printed as it came: JSON pretty-printed, anything else as\n * text. A non-2xx answer is still printed — the app's error envelope is the\n * useful part — and the command exits 1.\n *\n * It exists so the long tail needs no command of its own: a row's history, a\n * materialized view's refresh, the RLS audit, the schema editor's status, a\n * custom function, `/api/meta/contract`. The everyday operations have their\n * own commands (`data`, `users`, `cron`, `storage`, …), which validate their\n * input and confirm what they delete.\n */\nimport fs from \"fs\";\nimport type arg from \"arg\";\nimport chalk from \"chalk\";\n\nimport { parseCommandArgs, UsageError, wantsHelp } from \"../utils/args\";\nimport { PROJECT_TARGET_FLAGS, type ProjectTarget } from \"../utils/project-target\";\nimport {\n parsedLine,\n printProjectHelp,\n projectTarget,\n reportTargetError,\n startProjectCommand\n} from \"../utils/project-command\";\n\n/** The flags `rebase api` takes, on top of the target flags. */\nexport const API_FLAGS = {\n ...PROJECT_TARGET_FLAGS,\n \"--method\": String,\n \"-X\": \"--method\",\n \"--field\": [String],\n \"-f\": \"--field\",\n \"--raw-field\": [String],\n \"-F\": \"--raw-field\",\n \"--input\": String,\n \"--header\": [String],\n \"-H\": \"--header\",\n \"--include\": Boolean,\n \"-i\": \"--include\",\n \"--silent\": Boolean\n} satisfies arg.Spec;\n\nconst METHODS = new Set([\"GET\", \"POST\", \"PUT\", \"PATCH\", \"DELETE\", \"HEAD\", \"OPTIONS\"]);\n\n/** What one `rebase api` line asks for. Exported for its tests. */\nexport interface ApiRequestPlan {\n method: string;\n path: string;\n query: Record<string, string[]>;\n body?: string;\n contentType?: string;\n headers: Record<string, string>;\n}\n\n/**\n * The path a request goes to: `/…` as written, anything else under `/api/`\n * — `data/posts` is `/api/data/posts`, as `gh api repos/x` is relative to its\n * API root. A full URL is refused: the target flags say where requests go, so\n * a URL in the path would send the credential somewhere they did not choose.\n */\nexport function resolveApiPath(raw: string): string {\n const trimmed = raw.trim();\n if (/^[a-z][a-z0-9+.-]*:\\/\\//i.test(trimmed)) {\n throw new UsageError(\n `\\`rebase api\\` takes a path, not a URL (${trimmed}). Name the server with --url and the path after it: `\n + \"rebase api --url https://example.com /api/health.\"\n );\n }\n return trimmed.startsWith(\"/\") ? trimmed : `/api/${trimmed}`;\n}\n\n/** `key=value` split at its first `=`. */\nfunction splitField(raw: string, flag: string): [string, string] {\n const at = raw.indexOf(\"=\");\n if (at <= 0) throw new UsageError(`${flag} takes key=value (got \"${raw}\").`);\n return [raw.slice(0, at), raw.slice(at + 1)];\n}\n\n/**\n * A typed field's value, as `gh api -F` reads one: `true`, `false` and `null`\n * as themselves, a number as a number, `@file` as that file's text, a JSON\n * array or object as JSON, anything else as the string.\n */\nexport function typedFieldValue(raw: string): unknown {\n if (raw === \"true\") return true;\n if (raw === \"false\") return false;\n if (raw === \"null\") return null;\n if (/^-?\\d+(\\.\\d+)?$/.test(raw)) return Number(raw);\n if (raw.startsWith(\"@\")) {\n const file = raw.slice(1);\n try {\n return fs.readFileSync(file === \"-\" ? 0 : file, \"utf8\");\n } catch (e) {\n throw new UsageError(`Cannot read ${file}: ${e instanceof Error ? e.message : String(e)}`);\n }\n }\n if ((raw.startsWith(\"{\") && raw.endsWith(\"}\")) || (raw.startsWith(\"[\") && raw.endsWith(\"]\"))) {\n try {\n return JSON.parse(raw);\n } catch {\n return raw;\n }\n }\n return raw;\n}\n\n/**\n * Resolve a line into the request it describes. Exported for its tests.\n *\n * The method is the first argument when it is one (`rebase api DELETE\n * data/posts/1`), `--method`, or GET — POST when the line carries a body.\n * Fields go into the query string of a GET, HEAD or DELETE and into a JSON\n * body otherwise, as with `gh api`.\n */\nexport function resolveApiRequest(rawArgs: string[]): { plan: ApiRequestPlan; flags: ReturnType<typeof parseApiLine>[\"flags\"] } {\n const { flags, positionals } = parseApiLine(rawArgs);\n let words = positionals;\n let method = flags[\"--method\"]?.toUpperCase();\n if (words.length === 2) {\n const first = words[0].toUpperCase();\n if (!METHODS.has(first)) {\n throw new UsageError(`\\`rebase api\\` takes [METHOD] <path>; \"${words[0]}\" is not an HTTP method.`);\n }\n if (method && method !== first) throw new UsageError(`The method is given twice: ${first} and --method ${method}.`);\n method = first;\n words = words.slice(1);\n }\n if (words.length !== 1) throw new UsageError(\"`rebase api` needs a path: rebase api data/posts (see `rebase api --help`).\");\n const plan = buildApiPlan({\n method,\n path: resolveApiPath(words[0]),\n fields: flags[\"--field\"],\n rawFields: flags[\"--raw-field\"],\n input: flags[\"--input\"],\n headers: flags[\"--header\"]\n });\n return { plan, flags };\n}\n\n/** What a line says about a request, before it is resolved into one. */\nexport interface ApiRequestParts {\n method?: string;\n /** The path, `/api/…` already resolved, optionally with a query string. */\n path: string;\n fields?: readonly string[];\n rawFields?: readonly string[];\n input?: string;\n headers?: readonly string[];\n}\n\n/**\n * Resolve the parts of a line into the request they describe. Shared by\n * `rebase api` and `rebase functions invoke`. Exported for tests.\n *\n * The method is the one given, or GET — POST with `--input`. Fields go into\n * the query string of a GET, HEAD or DELETE and into a JSON body otherwise.\n * Unlike `gh api`, a field alone never makes the request a POST.\n */\nexport function buildApiPlan(parts: ApiRequestParts): ApiRequestPlan {\n const method = parts.method?.toUpperCase();\n if (method && !METHODS.has(method)) throw new UsageError(`--method ${method} is not an HTTP method.`);\n\n const fields: Array<[string, unknown]> = [\n ...(parts.fields ?? []).map((raw): [string, unknown] => splitField(raw, \"--field\")),\n ...(parts.rawFields ?? []).map((raw): [string, unknown] => {\n const [key, value] = splitField(raw, \"--raw-field\");\n return [key, typedFieldValue(value)];\n })\n ];\n\n let input: string | undefined;\n if (parts.input !== undefined) {\n const file = parts.input;\n try {\n input = fs.readFileSync(file === \"-\" ? 0 : file, \"utf8\");\n } catch (e) {\n throw new UsageError(`Cannot read --input ${file}: ${e instanceof Error ? e.message : String(e)}`);\n }\n }\n\n // GET unless the line says otherwise. `gh api` switches to POST as soon as\n // a field is added; here that would turn `rebase api data/posts -f limit=5`\n // into creating a row. A write is named (`POST`, `-X PATCH`) or carries a\n // whole body (`--input`).\n const resolvedMethod = method ?? (input !== undefined ? \"POST\" : \"GET\");\n const inQuery = resolvedMethod === \"GET\" || resolvedMethod === \"HEAD\" || resolvedMethod === \"DELETE\";\n if (input !== undefined && fields.length > 0 && !inQuery) {\n throw new UsageError(\"--input is the whole body; fields cannot be added to it. Give one or the other.\");\n }\n\n const headers: Record<string, string> = {};\n for (const raw of parts.headers ?? []) {\n const at = raw.indexOf(\":\");\n if (at <= 0) throw new UsageError(`--header takes \"Name: value\" (got \"${raw}\").`);\n const name = raw.slice(0, at).trim();\n if (/^authorization$/i.test(name)) {\n throw new UsageError(\"Pass a bearer with --token, not an Authorization header: the target decides where credentials go.\");\n }\n headers[name] = raw.slice(at + 1).trim();\n }\n\n const query: Record<string, string[]> = {};\n const [bare, search] = parts.path.split(/\\?(.*)/s, 2);\n if (search) {\n for (const [key, value] of new URLSearchParams(search)) (query[key] ??= []).push(value);\n }\n\n const plan: ApiRequestPlan = { method: resolvedMethod, path: bare, query, headers };\n if (inQuery) {\n for (const [key, value] of fields) (query[key] ??= []).push(typeof value === \"string\" ? value : JSON.stringify(value));\n }\n if (input !== undefined) {\n plan.body = input;\n plan.contentType = looksLikeJson(input) ? \"application/json\" : \"application/octet-stream\";\n } else if (fields.length > 0 && !inQuery) {\n plan.body = JSON.stringify(Object.fromEntries(fields));\n plan.contentType = \"application/json\";\n }\n return plan;\n}\n\nfunction looksLikeJson(text: string): boolean {\n try {\n JSON.parse(text);\n return true;\n } catch {\n return false;\n }\n}\n\nfunction parseApiLine(rawArgs: string[]) {\n return parseCommandArgs({\n spec: API_FLAGS,\n rawArgs,\n commandWords: 1,\n command: \"api\",\n maxPositionals: 2\n });\n}\n\nexport async function apiCommand(rawArgs: string[]): Promise<void> {\n startProjectCommand(rawArgs);\n if (wantsHelp(rawArgs)) {\n printApiHelp();\n return;\n }\n const { plan, flags } = parsedLine(() => resolveApiRequest(rawArgs));\n const target = await projectTarget(flags, { command: \"api\" });\n await sendApiPlan(target, plan, { include: flags[\"--include\"] === true, silent: flags[\"--silent\"] === true });\n}\n\n/**\n * Send a resolved request and print the answer as it came: JSON\n * pretty-printed, anything else as text, the status line and headers first\n * with `include`. A non-2xx answer is printed too, and exits 1.\n */\nexport async function sendApiPlan(\n target: ProjectTarget,\n plan: ApiRequestPlan,\n options: { include?: boolean; silent?: boolean } = {}\n): Promise<void> {\n let res: Response;\n try {\n res = await target.request(plan.path, {\n method: plan.method,\n query: plan.query,\n body: plan.body,\n headers: { ...plan.headers, ...(plan.contentType ? { \"Content-Type\": plan.contentType } : {}) }\n });\n } catch (e) {\n reportTargetError(e, target);\n }\n\n if (options.include) {\n process.stdout.write(`HTTP ${res.status} ${res.statusText}\\n`);\n res.headers.forEach((value, name) => process.stdout.write(`${name}: ${value}\\n`));\n process.stdout.write(\"\\n\");\n }\n\n const text = plan.method === \"HEAD\" ? \"\" : await res.text();\n if (!options.silent && text) {\n let printed = text;\n try {\n printed = JSON.stringify(JSON.parse(text), null, 2);\n } catch {\n // Not JSON: printed as it came.\n }\n process.stdout.write(printed.endsWith(\"\\n\") ? printed : `${printed}\\n`);\n }\n\n if (res.status >= 300) {\n // The body above says why; this is the exit code a script branches on,\n // and one line for whoever reads the terminal.\n process.stderr.write(chalk.red(`✗ HTTP ${res.status} from ${target.label}\\n`));\n process.exit(1);\n }\n}\n\nfunction printApiHelp(): void {\n printProjectHelp({\n command: \"api\",\n usage: \"[METHOD] <path>\",\n title: \"Send any request to the app's API, with the project's credential\",\n actions: [\n {\n action: \"[METHOD] <path>\",\n description: \"data/posts is /api/data/posts; a path starting with / is sent as written\",\n flags: [\n [\"--method, -X <method>\", \"The HTTP method (else GET; POST with --input — a field alone never writes)\"],\n [\"--field, -f <key=value>\", \"A string field: query string on GET/HEAD/DELETE, JSON body otherwise\"],\n [\"--raw-field, -F <key=value>\", \"A typed field: true/false/null, numbers, JSON, @file\"],\n [\"--input <file|->\", \"The whole request body, from a file or stdin\"],\n [\"--header, -H <\\\"Name: value\\\">\", \"An extra request header (never Authorization: use --token)\"],\n [\"--include, -i\", \"Print the status line and response headers first\"],\n [\"--silent\", \"Print nothing; only the exit code says how it went\"]\n ]\n }\n ],\n notes: [\n \"Examples:\",\n \" rebase api data/posts -f status=eq.published -f limit=5\",\n \" rebase api POST data/posts -F title=Hello -F published=true\",\n \" rebase api /api/admin/rls-audit --project acme\",\n \" rebase api functions/hello --anon\",\n \"A non-2xx answer is printed and exits 1. The everyday operations have their own commands: rebase data, users, cron, storage, functions, logs.\"\n ]\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAiCA,IAAa,YAAY;CACrB,GAAG;CACH,YAAY;CACZ,MAAM;CACN,WAAW,CAAC,MAAM;CAClB,MAAM;CACN,eAAe,CAAC,MAAM;CACtB,MAAM;CACN,WAAW;CACX,YAAY,CAAC,MAAM;CACnB,MAAM;CACN,aAAa;CACb,MAAM;CACN,YAAY;AAChB;AAEA,IAAM,0BAAU,IAAI,IAAI;CAAC;CAAO;CAAQ;CAAO;CAAS;CAAU;CAAQ;AAAS,CAAC;;;;;;;AAkBpF,SAAgB,eAAe,KAAqB;CAChD,MAAM,UAAU,IAAI,KAAK;CACzB,IAAI,2BAA2B,KAAK,OAAO,GACvC,MAAM,IAAI,WACN,2CAA2C,QAAQ,uGAEvD;CAEJ,OAAO,QAAQ,WAAW,GAAG,IAAI,UAAU,QAAQ;AACvD;;AAGA,SAAS,WAAW,KAAa,MAAgC;CAC7D,MAAM,KAAK,IAAI,QAAQ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