Skip to content

Add interactive Project setup to project link#53

Merged
luanvdw merged 2 commits into
mainfrom
feat/project-link-setup-choice
Jun 1, 2026
Merged

Add interactive Project setup to project link#53
luanvdw merged 2 commits into
mainfrom
feat/project-link-setup-choice

Conversation

@luanvdw
Copy link
Copy Markdown
Member

@luanvdw luanvdw commented Jun 1, 2026

Summary

  • make bare project link enter the Project setup picker in interactive mode
  • return PROJECT_LINK_TARGET_REQUIRED with candidates, suggested name, recovery commands, and nextActions in non-interactive mode
  • update Project setup copy, docs, skills, and journey tests so agents treat Project selection as a user-choice boundary

Review

  • Ran local thermonuclear review; fixed the maintainability finding by extracting the shared Project setup picker into lib/project/interactive-setup.ts and reusing it from app deploy and project link.

Validation

  • corepack pnpm --filter @prisma/cli build
  • corepack pnpm --filter @prisma/cli test
  • corepack pnpm lint:skills
  • corepack pnpm test:skills
  • git diff --check

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 1, 2026

Review Change Stack

Summary by CodeRabbit

  • New Features

    • prisma-cli project link accepts an optional argument; running it without arguments in interactive TTY prompts to pick or create a Project.
    • Deploy now triggers interactive project selection when no explicit target is provided.
  • Documentation

    • Clarified CLI guidance, command spec, help text, and “next steps” messaging to distinguish linking vs creating and to show the no-argument link example.
  • Bug Fixes / Behavior

    • Non-interactive/CI runs now return a structured error when no link target is available.
  • Tests

    • Tests added/updated to cover interactive picker, creation, and JSON-mode error output.

Walkthrough

This PR makes the prisma-cli project link argument optional and adds interactive project selection/creation when no target is specified. It introduces a shared interactive setup helper reused by app deploy, defines new error codes, updates controllers and tests, and clarifies agent behavior in skill documentation.

Changes

Interactive Project Linking

Layer / File(s) Summary
Error codes and command specifications
docs/product/error-conventions.md, docs/product/command-spec.md
New PROJECT_LINK_TARGET_REQUIRED error code (164/204) and updated specs for project link [id-or-name] with documented interactive/non-interactive behavior and project list candidate clarifications.
Interactive project setup helper
packages/cli/src/lib/project/interactive-setup.ts
New promptForProjectSetupChoice function and InteractiveProjectSetupResult interface that prompt users to select an existing project, create a new one with validation/suggestion, or cancel with guidance.
Shared setup validation and next-actions
packages/cli/src/lib/project/setup.ts, packages/cli/src/lib/project/resolution.ts
Exported validateProjectSetupNameText helper and updated buildProjectSetupNextActions to present link-versus-create user choice.
Project link command and controller implementation
packages/cli/src/commands/project/index.ts, packages/cli/src/controllers/project.ts
Made project link argument optional; rewrote runProjectLink to handle optional projectRef, fetch candidates, perform interactive prompting in TTY mode, or throw PROJECT_LINK_TARGET_REQUIRED in non-interactive contexts; added helpers for binding and error construction.
App deploy controller refactoring
packages/cli/src/controllers/app.ts
Refactored deploy interactive project setup to use shared promptForProjectSetupChoice helper instead of inline implementation, reducing duplication.
UI and presentation updates
packages/cli/src/presenters/project.ts, packages/cli/src/shell/command-meta.ts, docs/product/cli-style-guide.md, docs/product/output-conventions.md
Updated next-steps messaging to "Link an existing Project you choose", adjusted command examples and help text to reflect optional argument behavior.
Test coverage for optional linking and messaging
packages/cli/tests/project-controller.test.ts, packages/cli/tests/project.test.ts
Added tests for interactive project link without arguments, cancellation, JSON error response (PROJECT_LINK_TARGET_REQUIRED), and --yes flag constraints; updated expected output text throughout.
Skill and journey documentation
skills/journey-tests/01-nextjs-first-deploy.md, skills/prisma-cli-deploy-nextjs/SKILL.md, skills/prisma-cli/SKILL.md
Clarified project selection boundaries, constraints against inferring projects from plausible matches, and requirements for user confirmation before project link/project create.

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title directly and clearly summarizes the main change: adding interactive Project setup functionality to the project link command.
Description check ✅ Passed The description is relevant to the changeset, providing clear summary of changes, review approach, and validation steps performed.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/project-link-setup-choice
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch feat/project-link-setup-choice

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 672d2c2 and 844bfb4.

📒 Files selected for processing (17)
  • docs/product/cli-style-guide.md
  • docs/product/command-spec.md
  • docs/product/error-conventions.md
  • docs/product/output-conventions.md
  • packages/cli/src/commands/project/index.ts
  • packages/cli/src/controllers/app.ts
  • packages/cli/src/controllers/project.ts
  • packages/cli/src/lib/project/interactive-setup.ts
  • packages/cli/src/lib/project/resolution.ts
  • packages/cli/src/lib/project/setup.ts
  • packages/cli/src/presenters/project.ts
  • packages/cli/src/shell/command-meta.ts
  • packages/cli/tests/project-controller.test.ts
  • packages/cli/tests/project.test.ts
  • skills/journey-tests/01-nextjs-first-deploy.md
  • skills/prisma-cli-deploy-nextjs/SKILL.md
  • skills/prisma-cli/SKILL.md

Comment on lines +240 to +251
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);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

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.

Comment thread packages/cli/src/lib/project/interactive-setup.ts
Comment thread skills/journey-tests/01-nextjs-first-deploy.md Outdated
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (1)
packages/cli/src/lib/project/interactive-setup.ts (1)

31-34: ⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Fix 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", duplicateNames will 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 where name appears, so index !== 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

📥 Commits

Reviewing files that changed from the base of the PR and between 844bfb4 and 7ccca0f.

📒 Files selected for processing (3)
  • packages/cli/src/lib/project/interactive-setup.ts
  • packages/cli/tests/project.test.ts
  • skills/journey-tests/01-nextjs-first-deploy.md

@luanvdw luanvdw merged commit a5db9e0 into main Jun 1, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant