Skip to content

feat(cli): add verbose success diagnostics#69

Merged
AmanVarshney01 merged 1 commit into
mainfrom
aman/verbose-success-diagnostics
Jun 5, 2026
Merged

feat(cli): add verbose success diagnostics#69
AmanVarshney01 merged 1 commit into
mainfrom
aman/verbose-success-diagnostics

Conversation

@AmanVarshney01
Copy link
Copy Markdown
Member

@AmanVarshney01 AmanVarshney01 commented Jun 4, 2026

Summary

This makes the global diagnostics flags useful in the way we discussed:

  • --verbose enriches successful human output with safe state/context.
  • --trace stays failure-only for stacks, API/debug details, and deeper causes.
  • JSON output stays stable and does not include verbose-only diagnostics.
  • Quiet output stays quiet.
  • Internal errors hide stacks by default and only show them with --trace.

What changed

Verbose success diagnostics

Successful human commands append a Local context block when --verbose is enabled:

  • command duration
  • current working directory
  • local CLI state file path
  • git ref / short sha / dirty state when available

The git lookup is fail-soft and bounded, so missing git, detached repos, non-repo directories, and slow git commands do not break CLI execution.

Example:

$ prisma-cli project show --verbose
Project show -> This directory is linked to the following platform project.

│  local repo  ~/dev/app
│  platform    Billing API

Resolved context:
│  workspace:       Prisma Team
│  workspace id:    ws_123
│  project:         Billing API
│  project id:      proj_123
│  project source:  .prisma/local.json

Local context:
│  duration:    58ms
│  cwd:         ~/dev/app
│  state file:  ~/dev/app/.prisma/cli/local.json
│  git ref:     main
│  git sha:     95dd50a
│  git dirty:   no

Command-specific resolved context

project show --verbose and the main app/project commands now include resolved workspace/project context before the generic local context.

Covered commands:

  • app deploy
  • app show
  • app list-deploys
  • app open
  • app promote
  • app rollback
  • app remove
  • project env add/update/list/remove
  • branch list

The repeated workspace/project/source formatting lives in a shared presenter helper so the output stays consistent across commands.

App deploy verbose settings

app deploy --verbose now answers “what exactly did we deploy?” with safe deploy settings:

  • framework and build type
  • framework resolution source
  • entrypoint or “derived from build output”
  • HTTP port
  • region / existing app region
  • env var names only, never values
  • branch DB setup status, env var names, and schema action when applicable

Example:

$ prisma-cli app deploy --verbose
Live in 12.3s
https://api.prisma.build

Logs
│  prisma-cli app logs

Resolved context:
│  workspace:          Prisma Team
│  workspace id:       ws_123
│  project:            Billing API
│  project id:         proj_123
│  project source:     .prisma/local.json
│  target name:        Billing API (.prisma/local.json)
│  branch:             main (production)
│  branch id:          br_main
│  app:                api
│  app id:             app_123
│  deployment id:      dep_123
│  deployment status:  running
│  local pin:          .prisma/local.json
│  deploy duration:    12.3s

Deploy settings:
│  framework:         Hono (bun)
│  framework source:  detected from package.json
│  entrypoint:        src/index.ts
│  http port:         8080
│  region:            fra
│  env vars:          DATABASE_URL
│  branch db:         created (preview-db)
│  branch db env:     DATABASE_URL
│  branch db schema:  prisma migrate deploy (prisma-orm, prisma/schema.prisma)

Local context:
│  duration:    12.4s
│  cwd:         ~/dev/app
│  state file:  ~/dev/app/.prisma/cli/local.json
│  git ref:     main
│  git sha:     95dd50a
│  git dirty:   yes

Project env and branch verbose context

project env * --verbose shows where env vars are being written/read without leaking values:

$ prisma-cli project env list --branch feature/auth --verbose

Env target:
│  project id:     proj_123
│  scope:          branch:feature/auth
│  target source:  explicit
│  env map:        preview
│  branch:         feature/auth
│  branch id:      br_feature_auth
│  keys:           DATABASE_URL, STRIPE_KEY

branch list --verbose includes the resolved workspace/project block as well.

Trace remains failure-only

Unexpected CLI errors avoid dumping stack traces by default:

$ prisma-cli some-command
Unexpected CLI error: boom
More: Re-run with --trace for deeper diagnostics

With --trace, stack/debug details are shown:

$ prisma-cli some-command --trace
Error: boom
    at explode (...)

For structured CliError failures, the existing Trace: behavior stays behind --trace.

JSON stays clean

Verbose diagnostics are intentionally not added to JSON output:

$ prisma-cli project show --verbose --json
{
  "ok": true,
  "command": "project.show",
  "result": { ... },
  "warnings": [],
  "nextSteps": [],
  "nextActions": []
}

app deploy also strips verbose-only deploy settings/local pin/branch id from JSON serialization.

Dependency updates

  • @prisma/compute-sdk: 0.20.0 -> 0.21.0
  • @prisma/management-api-sdk: 1.35.0 -> 1.37.0

Checks

  • pnpm --filter @prisma/cli test
  • pnpm --filter @prisma/cli build
  • git diff --check

Note: pnpm --filter @prisma/cli lint is not available because the package does not define a lint script.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 4, 2026

Review Change Stack

Summary by CodeRabbit

  • New Features

    • Enhanced --verbose output across CLI commands: shows resolved project context, deploy settings, and additional verbose blocks for apps, branches, projects, and env operations; optionally appends local diagnostics (cwd, state file, Git status, duration).
  • Bug Fixes

    • Improved unexpected-error display with a concise user message and optional full trace when requested.
  • Chores

    • Bumped Prisma SDK dependencies for the CLI.

Walkthrough

This PR adds comprehensive verbose context and local diagnostics to the CLI output. It introduces infrastructure to capture resolved project context (workspace, project, branch, resolution) and local command diagnostics (Git status, working directory, state file path, duration), then renders this information when the --verbose flag is enabled. The changes thread context through controllers and presenters, update error output formatting to support a --trace flag, and integrate diagnostics collection into the command runner. New shell UI utilities provide verbose block rendering with value masking and color formatting support.

🚥 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 'feat(cli): add verbose success diagnostics' accurately and clearly summarizes the main feature: adding verbose diagnostics output on successful CLI commands.
Description check ✅ Passed The description comprehensively explains the changes, including verbose diagnostics behavior, command-specific context, trace handling, JSON stability, and dependency updates with detailed examples.
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 aman/verbose-success-diagnostics
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch aman/verbose-success-diagnostics

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

@AmanVarshney01 AmanVarshney01 force-pushed the aman/verbose-success-diagnostics branch 2 times, most recently from c31173f to 2cb3cfc Compare June 4, 2026 12:16
@AmanVarshney01 AmanVarshney01 marked this pull request as ready for review June 4, 2026 14:32
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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/cli/src/presenters/branch.ts (1)

19-22: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Verbose resolved context is skipped when branch list is empty.

Line 21 returns before renderBranchResolvedContextBlock(...) is appended, so branch list --verbose drops the "Resolved context" block on empty results.

Suggested fix
   if (result.branches.length === 0) {
     lines.push(`${rail}  ${ui.dim("No branches found.")}`);
+    lines.push(...renderBranchResolvedContextBlock(context, result));
     return lines;
   }
@@
-  lines.push(...renderBranchResolvedContextBlock(context, result));
+  lines.push(...renderBranchResolvedContextBlock(context, result));
   return lines;

Also applies to: 34-35

🤖 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/presenters/branch.ts` around lines 19 - 22, The
empty-branches early return drops the verbose "Resolved context" block; modify
the branch listing logic so after pushing the "No branches found." message into
lines (when result.branches.length === 0) you still call
renderBranchResolvedContextBlock(...) and append its output to lines when
verbose is enabled, then return; update the matching early-return at the similar
spot (the one flagged at 34-35) the same way. Ensure you reference and update
the code paths that use result.branches, lines, and
renderBranchResolvedContextBlock so the verbose flag produces the "Resolved
context" block even for empty results.
🤖 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.

Outside diff comments:
In `@packages/cli/src/presenters/branch.ts`:
- Around line 19-22: The empty-branches early return drops the verbose "Resolved
context" block; modify the branch listing logic so after pushing the "No
branches found." message into lines (when result.branches.length === 0) you
still call renderBranchResolvedContextBlock(...) and append its output to lines
when verbose is enabled, then return; update the matching early-return at the
similar spot (the one flagged at 34-35) the same way. Ensure you reference and
update the code paths that use result.branches, lines, and
renderBranchResolvedContextBlock so the verbose flag produces the "Resolved
context" block even for empty results.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 020c0557-d0aa-4029-b4f0-46a8cc3815e8

📥 Commits

Reviewing files that changed from the base of the PR and between c7e7b86 and 2cb3cfc.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (28)
  • packages/cli/package.json
  • packages/cli/src/cli.ts
  • packages/cli/src/controllers/app-env-file.ts
  • packages/cli/src/controllers/app-env.ts
  • packages/cli/src/controllers/app.ts
  • packages/cli/src/controllers/branch.ts
  • packages/cli/src/lib/diagnostics.ts
  • packages/cli/src/lib/git/local-status.ts
  • packages/cli/src/presenters/app-env.ts
  • packages/cli/src/presenters/app.ts
  • packages/cli/src/presenters/branch.ts
  • packages/cli/src/presenters/project.ts
  • packages/cli/src/presenters/verbose-context.ts
  • packages/cli/src/shell/command-runner.ts
  • packages/cli/src/shell/diagnostics-output.ts
  • packages/cli/src/shell/output.ts
  • packages/cli/src/shell/ui.ts
  • packages/cli/src/types/app-env.ts
  • packages/cli/src/types/app.ts
  • packages/cli/src/types/branch.ts
  • packages/cli/src/types/diagnostics.ts
  • packages/cli/tests/app-controller.test.ts
  • packages/cli/tests/app-env.test.ts
  • packages/cli/tests/app-presenter.test.ts
  • packages/cli/tests/branch-controller.test.ts
  • packages/cli/tests/command-runner.test.ts
  • packages/cli/tests/project.test.ts
  • packages/cli/tests/shell.test.ts

coderabbitai[bot]
coderabbitai Bot previously approved these changes Jun 4, 2026
Copy link
Copy Markdown
Member

@luanvdw luanvdw left a comment

Choose a reason for hiding this comment

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

@AmanVarshney01 thanks for pushing this through! The shape looks good overall. I found a few things I think are worth considering, take a look and let me know what you think.

  1. Makeing the post-success diagnostics fail-soft,

runCommand collects verbose diagnostics after the handler has already returned success, but still inside the main success try/catch.

That means if the user aborts while the diagnostic git subprocesses are running, the whole command can be reported as COMMAND_CANCELED even though the actual command already completed. For mutating commands, that could hide a real success and return exit code 130 after the side effect happened.

I think the diagnostics tail should be best-effort only. If it fails or aborts, omit the diagnostics rather than changing the command result.

Locations:

  • packages/cli/src/shell/command-runner.ts
  • packages/cli/src/lib/diagnostics.ts
  • packages/cli/src/lib/git/local-status.ts
  1. branch list --verbose drops context for empty results

The empty-list branch returns before appending the resolved context block, so branch list --verbose does not show the resolved workspace/project context when there are no branches. That context is especially useful in the empty state, since it helps explain what project was actually queried.

Location:

  • packages/cli/src/presenters/branch.ts

@AmanVarshney01
Copy link
Copy Markdown
Member Author

Addressed both review points:

  • post-success verbose diagnostics are now best-effort, so an abort/failure while collecting local git diagnostics no longer changes an already-successful command into a cancellation
  • branch list --verbose now includes the resolved context block even when the project has no branches

Validated with pnpm test, pnpm build:cli, and git diff --check.

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: 1

🤖 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/tests/app-presenter.test.ts`:
- Around line 4-11: Add a JSON contract assertion that verifies
serializeAppDeploy omits deploySettings, localPin, and branch.id: create a
minimal AppDeployResult fixture, call serializeAppDeploy(...) (or the exported
render/serializer used in tests), JSON.stringify/parse the result or compare
objects, and assert that the resulting object does not have keys deploySettings
or localPin and that branch (if present) does not include an id property; place
this assertion alongside the existing verbose output tests for
renderAppDeploy/renderAppDeploy serialization to lock the JSON shape.
🪄 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: 94a2c34e-91d0-4875-9709-d5adf6cf7c65

📥 Commits

Reviewing files that changed from the base of the PR and between 2cb3cfc and 0551127.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (29)
  • packages/cli/package.json
  • packages/cli/src/cli.ts
  • packages/cli/src/controllers/app-env-file.ts
  • packages/cli/src/controllers/app-env.ts
  • packages/cli/src/controllers/app.ts
  • packages/cli/src/controllers/branch.ts
  • packages/cli/src/lib/diagnostics.ts
  • packages/cli/src/lib/git/local-status.ts
  • packages/cli/src/presenters/app-env.ts
  • packages/cli/src/presenters/app.ts
  • packages/cli/src/presenters/branch.ts
  • packages/cli/src/presenters/project.ts
  • packages/cli/src/presenters/verbose-context.ts
  • packages/cli/src/shell/command-runner.ts
  • packages/cli/src/shell/diagnostics-output.ts
  • packages/cli/src/shell/output.ts
  • packages/cli/src/shell/ui.ts
  • packages/cli/src/types/app-env.ts
  • packages/cli/src/types/app.ts
  • packages/cli/src/types/branch.ts
  • packages/cli/src/types/diagnostics.ts
  • packages/cli/tests/app-controller.test.ts
  • packages/cli/tests/app-env.test.ts
  • packages/cli/tests/app-presenter.test.ts
  • packages/cli/tests/branch-controller.test.ts
  • packages/cli/tests/branch.test.ts
  • packages/cli/tests/command-runner.test.ts
  • packages/cli/tests/project.test.ts
  • packages/cli/tests/shell.test.ts

Comment thread packages/cli/tests/app-presenter.test.ts Outdated
Signed-off-by: Aman Varshney <amanvarshney.work@gmail.com>
@AmanVarshney01 AmanVarshney01 force-pushed the aman/verbose-success-diagnostics branch from 0551127 to dc84601 Compare June 5, 2026 08:54
@AmanVarshney01
Copy link
Copy Markdown
Member Author

Did another stress pass and addressed the new JSON-contract guard:

  • added an app deploy serializer test that proves verbose-only fields stay out of JSON: deploySettings, localPin, and branch.id
  • rechecked the related serializers/empty states/diagnostics paths; no additional functional issue found

Validated again with pnpm test, pnpm build:cli, and git diff --check.

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: 2

🤖 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/lib/git/local-status.ts`:
- Around line 26-62: The runGit helper currently sets a 2_000ms timeout which is
too short for some repositories; update the timeout in function runGit to
5_000ms (change the timeout option from 2_000 to 5_000) so execFile calls in
runGit get a 5-second timeout and align with other git calls (e.g., git config)
while preserving the existing abort/error handling and fail-soft behavior.

In `@packages/cli/src/presenters/app-env.ts`:
- Around line 180-181: Add unit tests for the env serializers to assert
verbose-only fields are stripped: for serializeEnvAdd, serializeEnvUpdate,
serializeEnvList, and serializeEnvRemove create example result objects that
include verboseContext plus normal fields (e.g., projectId, scope, variable/list
entries) then call the corresponding function and assert the returned object
does not have verboseContext but does include expected non-verbose properties
(projectId, scope, variable/id/list items as appropriate); reference the
functions serializeEnvAdd, serializeEnvUpdate, serializeEnvList, and
serializeEnvRemove when writing the tests.
🪄 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: 6bd65110-8395-4351-b298-bac6b51da5c7

📥 Commits

Reviewing files that changed from the base of the PR and between 0551127 and dc84601.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (29)
  • packages/cli/package.json
  • packages/cli/src/cli.ts
  • packages/cli/src/controllers/app-env-file.ts
  • packages/cli/src/controllers/app-env.ts
  • packages/cli/src/controllers/app.ts
  • packages/cli/src/controllers/branch.ts
  • packages/cli/src/lib/diagnostics.ts
  • packages/cli/src/lib/git/local-status.ts
  • packages/cli/src/presenters/app-env.ts
  • packages/cli/src/presenters/app.ts
  • packages/cli/src/presenters/branch.ts
  • packages/cli/src/presenters/project.ts
  • packages/cli/src/presenters/verbose-context.ts
  • packages/cli/src/shell/command-runner.ts
  • packages/cli/src/shell/diagnostics-output.ts
  • packages/cli/src/shell/output.ts
  • packages/cli/src/shell/ui.ts
  • packages/cli/src/types/app-env.ts
  • packages/cli/src/types/app.ts
  • packages/cli/src/types/branch.ts
  • packages/cli/src/types/diagnostics.ts
  • packages/cli/tests/app-controller.test.ts
  • packages/cli/tests/app-env.test.ts
  • packages/cli/tests/app-presenter.test.ts
  • packages/cli/tests/branch-controller.test.ts
  • packages/cli/tests/branch.test.ts
  • packages/cli/tests/command-runner.test.ts
  • packages/cli/tests/project.test.ts
  • packages/cli/tests/shell.test.ts

Comment thread packages/cli/src/lib/git/local-status.ts
Comment thread packages/cli/src/presenters/app-env.ts
Copy link
Copy Markdown
Member

@luanvdw luanvdw left a comment

Choose a reason for hiding this comment

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

@AmanVarshney01 CodeRabbit's feedback is minor, approving the PR so long 🙏

@AmanVarshney01 AmanVarshney01 merged commit e18e83b into main Jun 5, 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.

2 participants