feat(cli): add init, the compute config formalizer#108
Conversation
|
Warning Review limit reachedYou’ve reached a temporary PR review limit under our Fair Usage Limits Policy. Next review available in: 7 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (13)
WalkthroughThe PR adds a new top-level 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
✨ Simplify code
Comment |
luanvdw
left a comment
There was a problem hiding this comment.
🚀
This looks great and the happy path is well covered. There's two edge cases that I think we can tighten a bit,
-
--entryis silently ignored for frameworks that don’t support entrypoints. InresolveInitEntry, we return early whenframework.usesEntrypointis false, before checking whether the user explicitly passed--entry. Soprisma-cli init --framework nextjs --entry src/index.tsexits successfully but drops the user’s flag. I think this should match deploy’s behavior and fail with a usage error instead. -
Interactive framework adjustment can leave
entryout of sync with the final framework.runInitresolvesentrybeforemaybeAdjustSettings, then writes that oldentrywith the adjusted framework. If the detected framework is Hono/Bun and the user switches to Next.js, we can write an invalidprisma.compute.tswithentryon a non-entrypoint framework. If the user switches the other way, we may miss the entrypoint we should have pinned.
and then a small docs cleanup, the new INIT_CONFIG_EXISTS / INIT_DETECTION_FAILED codes are in command-spec.md, but not in the central error-conventions.md MVP code list. Since agents/CI branch on these codes, I’d add them there as part of this PR.
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
docs/product/command-spec.md (2)
400-400: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winFix the preview/adjust order.
The controller applies the framework/http-port adjustment before rendering the preview, so the preview is showing the final values rather than being followed by an adjust step. Rephrase this bullet to match the actual flow.
Suggested wording
-- previews the resolved values with per-value source annotations (`detected`, `framework default`, `package.json`, `flag`) before writing; in interactive mode the preview is followed by an optional adjust step for framework and HTTP port, and `--yes` accepts the preview as shown +- in interactive mode, an optional adjust step for framework and HTTP port runs before the preview; the preview then shows the final resolved values with per-value source annotations (`detected`, `framework default`, `package.json`, `flag`), and `--yes` accepts them as shown🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@docs/product/command-spec.md` at line 400, The preview/adjust sequence description in the command spec is out of order: the current flow renders the preview before the interactive adjustment, not after it. Update the bullet in the command-spec text to describe that the resolved values are previewed first with source annotations, then in interactive mode the framework and HTTP port can be adjusted, and `--yes` accepts the preview as shown; use the wording consistent with the controller flow around the preview and adjust step.
395-410: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winClarify that
--installis also a remote step.The spec says linking is the only remote step, but
resolveInitTypes()can runexeca(...)to install@prisma/compute-sdkafter the config write, which also depends on network/package-registry access. Please split "local config write" from the optional install/link steps so the contract matches the controller.Suggested wording
-- writing the config requires no auth and no network; linking is the only remote step +- writing the config requires no auth and no network; optional install/link steps may use the network after the file is written🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@docs/product/command-spec.md` around lines 395 - 410, The init spec currently says linking is the only remote step, but `resolveInitTypes()` can also trigger an install via `execa(...)` for `@prisma/compute-sdk`, so update the wording to separate the local config write from optional remote package-manager actions. Clarify in the `init` section that writing the config is always local/no-network, while type installation (whether via `--install` or the interactive prompt) is an optional networked step handled after the write. Refer to `resolveInitTypes()` and the `init` contract text so the controller behavior and documentation stay aligned.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/cli/src/controllers/init.ts`:
- Around line 200-227: The `resolveInitTypes` step can throw after
`prisma.compute.ts` has already been written, which makes `runInit` report a
failure even though init partially succeeded. Mirror the protection used in
`resolveInitLink`: wrap the `readBunPackageJson` call in `resolveInitTypes` with
error handling, treat non-ENOENT read failures as a warning via the existing
`hooks.onWarning`, and return a safe skipped/unchanged `InitTypesState` instead
of letting the exception escape. Use the `resolveInitTypes`,
`readBunPackageJson`, and `hooks.onWarning` symbols to locate the fix, and add a
regression test for malformed `package.json`.
---
Outside diff comments:
In `@docs/product/command-spec.md`:
- Line 400: The preview/adjust sequence description in the command spec is out
of order: the current flow renders the preview before the interactive
adjustment, not after it. Update the bullet in the command-spec text to describe
that the resolved values are previewed first with source annotations, then in
interactive mode the framework and HTTP port can be adjusted, and `--yes`
accepts the preview as shown; use the wording consistent with the controller
flow around the preview and adjust step.
- Around line 395-410: The init spec currently says linking is the only remote
step, but `resolveInitTypes()` can also trigger an install via `execa(...)` for
`@prisma/compute-sdk`, so update the wording to separate the local config write
from optional remote package-manager actions. Clarify in the `init` section that
writing the config is always local/no-network, while type installation (whether
via `--install` or the interactive prompt) is an optional networked step handled
after the write. Refer to `resolveInitTypes()` and the `init` contract text so
the controller behavior and documentation stay aligned.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: f3db233d-ece3-419d-90a0-3ba58f3a474e
📒 Files selected for processing (6)
docs/product/command-spec.mdpackages/cli/src/commands/init/index.tspackages/cli/src/controllers/init.tspackages/cli/src/presenters/init.tspackages/cli/src/types/init.tspackages/cli/tests/init.test.ts
|
@luanvdw Both edge cases fixed in 99f5386:
|
d546f7e to
d03ebd8
Compare
init writes a committed prisma.compute.ts for the app in the invocation directory: it detects the framework with the same registry deploy uses, previews every value with its source, and pins the app's identity (name, framework, httpPort, entry for entrypoint frameworks, region only when passed). It never writes a build block, never overwrites an existing config anywhere up to the repo root (INIT_CONFIG_EXISTS), and never scaffolds code; create-prisma owns scaffolding. Writing the config needs no auth. The optional link step reuses the project link flow (interactive question, --link/--no-link/--project), and link failures after the write downgrade to warnings so the config stands. Detection failure prompts interactively and fails with INIT_DETECTION_FAILED plus the framework list in JSON mode. app deploy success output now hints "Config prisma-cli init" when the deploy ran on inferred settings without a config file.
init's next steps, link hints, error recovery commands, and the deploy Config hint now render through the project's detected package runner (pnpm dlx / bunx / yarn dlx / npx -y with @prisma/cli@latest), matching the agent group's convention, instead of hardcoding the prisma-cli bin name. Descriptor examples switch to the runner-aware form.
The generated config's typed import resolves at deploy time without a local install, but editors need @prisma/compute-sdk locally for types. After writing the config, init now detects an existing dependency, otherwise offers the detected package manager's add command (pnpm add -D / bun add -d / yarn add -D / npm install -D). --install forces it, --no-install skips, non-interactive skips with the add command in nextSteps, and a failed install downgrades to a visible warning with the exact command; the config write always stands. Also surfaces types/link failures in human output directly, since the runner does not render success warnings in human mode.
- --entry now fails with a usage error for frameworks that derive their entrypoint from build output, instead of being silently dropped - entry resolution moved after the interactive adjust step and validates against the final framework, so a framework switch cannot write a stale or missing entry - the post-write types step degrades to a skip with a warning when package.json is unreadable, so a malformed file cannot fail the command after the config was written (retry no longer gets stuck on INIT_CONFIG_EXISTS) - init presenter drops its bespoke warning lines now that the runner renders success warnings (cherry-picked from the project PR) - INIT_CONFIG_EXISTS and INIT_DETECTION_FAILED registered in error-conventions.md
d03ebd8 to
28399f1
Compare
prisma-cli initwrites a committedprisma.compute.tsfor the app in the current directory. Deploy stays zero-config; init pins what deploy would infer so the setup is reviewable and stable for teammates and CI. It never overwrites an existing config, never scaffolds code (that's create-prisma's job), and needs no auth except for the optional link step.More examples:
Design notes
name,framework,httpPort,entryfor entrypoint frameworks,regiononly when passed). Nobuildblock, so build-command inference stays live until a user opts into owning it.--framework customappends a commentedbuildstub since custom artifacts require it.INIT_CONFIG_EXISTSwhen any config exists up to the repo root (nested configs refused, steering monorepos to one root config);INIT_DETECTION_FAILEDwith the framework list in--json, an interactive picker otherwise.app deploysuccess output now hintsConfig prisma-cli initwhen the deploy ran on inferred settings.Testing: 10 new integration tests (572 total green), lint/typecheck/build clean, plus a live run shown above.