Add interactive Project setup to project link#53
Conversation
Summary by CodeRabbit
WalkthroughThis PR makes the ChangesInteractive Project Linking
🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
✨ Simplify code
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 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/project.ts`:
- Around line 240-251: The current branch treats any non-empty projectRef as an
explicit target; change the condition so that a bare backslash ("\") is treated
as the setup sentinel and routed to the interactive/error path instead of
resolved as a project id/name. Concretely, update the check around projectRef
(used where resolveProjectForSetup, bindProjectToDirectory,
resolveInteractiveProjectLinkSetup, and projectLinkTargetRequiredError are
invoked) to only take the explicit-resolution branch when projectRef.trim() is
non-empty AND projectRef.trim() !== "\\"; otherwise fall through to the
interactive prompt (resolveInteractiveProjectLinkSetup) or the
projectLinkTargetRequiredError for non-interactive contexts.
In `@packages/cli/src/lib/project/interactive-setup.ts`:
- Around line 36-39: The project picker builds each choice from sortedProjects
with label: project.name which makes duplicates ambiguous; update the mapping in
interactive-setup.ts to disambiguate by appending a unique identifier (e.g.,
project.id, project.path, or project.directory) to the label while keeping the
value as { kind: "project", project } so selection still returns the correct
Project object; ensure the displayed string includes both name and the chosen
unique field (for example "MyProject — <id or path>") so users can distinguish
identical names.
In `@skills/journey-tests/01-nextjs-first-deploy.md`:
- Around line 37-40: Update the checklist wording to explicitly name the CLI
commands that trigger the interactive setup: state that the agent should run
prisma-cli app deploy --framework nextjs (which automatically enters the setup
prompt when the repo is unlinked) or run the bare prisma-cli project link
command (which also triggers the interactive picker) and ensure that prisma-cli
project link <id-or-name> is only invoked when the user has explicitly chosen or
named the Project.
🪄 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: dd1d419d-5b2b-461f-87cd-c78b2bdc8cf4
📒 Files selected for processing (17)
docs/product/cli-style-guide.mddocs/product/command-spec.mddocs/product/error-conventions.mddocs/product/output-conventions.mdpackages/cli/src/commands/project/index.tspackages/cli/src/controllers/app.tspackages/cli/src/controllers/project.tspackages/cli/src/lib/project/interactive-setup.tspackages/cli/src/lib/project/resolution.tspackages/cli/src/lib/project/setup.tspackages/cli/src/presenters/project.tspackages/cli/src/shell/command-meta.tspackages/cli/tests/project-controller.test.tspackages/cli/tests/project.test.tsskills/journey-tests/01-nextjs-first-deploy.mdskills/prisma-cli-deploy-nextjs/SKILL.mdskills/prisma-cli/SKILL.md
| if (projectRef?.trim()) { | ||
| const project = resolveProjectForSetup(projectRef.trim(), projects, workspace); | ||
| result = await bindProjectToDirectory(context, workspace, toProjectSummary(project), "linked"); | ||
| } else if (canPrompt(context) && !context.flags.yes) { | ||
| result = await resolveInteractiveProjectLinkSetup( | ||
| context, | ||
| workspace, | ||
| projects, | ||
| provider, | ||
| ); | ||
| } else { | ||
| throw await projectLinkTargetRequiredError(context, projects); |
There was a problem hiding this comment.
Treat bare \ as the setup sentinel before resolving a project.
Line 240 currently sends any non-empty projectRef down the explicit-resolution path. That means prisma-cli project link \ will try to resolve "\\" as a Project id/name instead of opening the setup picker in TTY mode or returning PROJECT_LINK_TARGET_REQUIRED in non-interactive mode, which breaks the advertised flow.
Proposed fix
- let result: ProjectSetupResult;
- if (projectRef?.trim()) {
- const project = resolveProjectForSetup(projectRef.trim(), projects, workspace);
+ const normalizedProjectRef = projectRef?.trim();
+ const wantsProjectSetup = normalizedProjectRef === "\\";
+
+ let result: ProjectSetupResult;
+ if (normalizedProjectRef && !wantsProjectSetup) {
+ const project = resolveProjectForSetup(normalizedProjectRef, projects, workspace);
result = await bindProjectToDirectory(context, workspace, toProjectSummary(project), "linked");
- } else if (canPrompt(context) && !context.flags.yes) {
+ } else if (canPrompt(context) && !context.flags.yes) {
result = await resolveInteractiveProjectLinkSetup(
context,
workspace,
projects,
provider,
);
} else {
throw await projectLinkTargetRequiredError(context, projects);
}🤖 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 `@packages/cli/src/controllers/project.ts` around lines 240 - 251, The current
branch treats any non-empty projectRef as an explicit target; change the
condition so that a bare backslash ("\") is treated as the setup sentinel and
routed to the interactive/error path instead of resolved as a project id/name.
Concretely, update the check around projectRef (used where
resolveProjectForSetup, bindProjectToDirectory,
resolveInteractiveProjectLinkSetup, and projectLinkTargetRequiredError are
invoked) to only take the explicit-resolution branch when projectRef.trim() is
non-empty AND projectRef.trim() !== "\\"; otherwise fall through to the
interactive prompt (resolveInteractiveProjectLinkSetup) or the
projectLinkTargetRequiredError for non-interactive contexts.
There was a problem hiding this comment.
♻️ Duplicate comments (1)
packages/cli/src/lib/project/interactive-setup.ts (1)
31-34:⚠️ Potential issue | 🔴 Critical | ⚡ Quick winFix the duplicate detection logic to catch all duplicates.
The current logic only identifies the 2nd, 3rd, etc. occurrences of a duplicate name, not the first. For example, if two Projects are named "foo",
duplicateNameswill only contain "foo" after processing the second occurrence, so the first "foo" will still display as just "foo" (without the ID), leaving both choices partially ambiguous.
projectNames.indexOf(name)always returns the first index wherenameappears, soindex !== projectNames.indexOf(name)is only true for non-first occurrences.🐛 Proposed fix to detect all names that appear more than once
const projectNames = sortedProjects.map((project) => project.name); +const nameCounts = new Map<string, number>(); +for (const name of projectNames) { + nameCounts.set(name, (nameCounts.get(name) ?? 0) + 1); +} const duplicateNames = new Set( - projectNames.filter((name, index) => projectNames.indexOf(name) !== index), + Array.from(nameCounts.entries()) + .filter(([_, count]) => count > 1) + .map(([name]) => name), );🤖 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 `@packages/cli/src/lib/project/interactive-setup.ts` around lines 31 - 34, The duplicate detection in interactive-setup.ts misses the first occurrence because duplicateNames is built by checking projectNames.indexOf(name) !== index; instead compute duplicates by checking whether a name appears more than once (e.g., use projectNames.indexOf(name) !== projectNames.lastIndexOf(name) or build a frequency map) and populate duplicateNames with every name whose count > 1 so that all duplicate project names (not just subsequent occurrences) are detected; update the logic that builds duplicateNames (referencing projectNames and duplicateNames) and ensure downstream code that displays sortedProjects uses duplicateNames to append IDs for every duplicate.
🤖 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.
Duplicate comments:
In `@packages/cli/src/lib/project/interactive-setup.ts`:
- Around line 31-34: The duplicate detection in interactive-setup.ts misses the
first occurrence because duplicateNames is built by checking
projectNames.indexOf(name) !== index; instead compute duplicates by checking
whether a name appears more than once (e.g., use projectNames.indexOf(name) !==
projectNames.lastIndexOf(name) or build a frequency map) and populate
duplicateNames with every name whose count > 1 so that all duplicate project
names (not just subsequent occurrences) are detected; update the logic that
builds duplicateNames (referencing projectNames and duplicateNames) and ensure
downstream code that displays sortedProjects uses duplicateNames to append IDs
for every duplicate.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 612c53aa-cbba-45e1-91aa-680289ffa213
📒 Files selected for processing (3)
packages/cli/src/lib/project/interactive-setup.tspackages/cli/tests/project.test.tsskills/journey-tests/01-nextjs-first-deploy.md
Summary
project linkenter the Project setup picker in interactive modePROJECT_LINK_TARGET_REQUIREDwith candidates, suggested name, recovery commands, and nextActions in non-interactive modeReview
lib/project/interactive-setup.tsand reusing it from app deploy and project link.Validation
corepack pnpm --filter @prisma/cli buildcorepack pnpm --filter @prisma/cli testcorepack pnpm lint:skillscorepack pnpm test:skillsgit diff --check