feat(cli): add verbose success diagnostics#69
Conversation
Summary by CodeRabbit
WalkthroughThis 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)
✅ 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
Comment |
c31173f to
2cb3cfc
Compare
There was a problem hiding this comment.
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 winVerbose resolved context is skipped when branch list is empty.
Line 21 returns before
renderBranchResolvedContextBlock(...)is appended, sobranch list --verbosedrops 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
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (28)
packages/cli/package.jsonpackages/cli/src/cli.tspackages/cli/src/controllers/app-env-file.tspackages/cli/src/controllers/app-env.tspackages/cli/src/controllers/app.tspackages/cli/src/controllers/branch.tspackages/cli/src/lib/diagnostics.tspackages/cli/src/lib/git/local-status.tspackages/cli/src/presenters/app-env.tspackages/cli/src/presenters/app.tspackages/cli/src/presenters/branch.tspackages/cli/src/presenters/project.tspackages/cli/src/presenters/verbose-context.tspackages/cli/src/shell/command-runner.tspackages/cli/src/shell/diagnostics-output.tspackages/cli/src/shell/output.tspackages/cli/src/shell/ui.tspackages/cli/src/types/app-env.tspackages/cli/src/types/app.tspackages/cli/src/types/branch.tspackages/cli/src/types/diagnostics.tspackages/cli/tests/app-controller.test.tspackages/cli/tests/app-env.test.tspackages/cli/tests/app-presenter.test.tspackages/cli/tests/branch-controller.test.tspackages/cli/tests/command-runner.test.tspackages/cli/tests/project.test.tspackages/cli/tests/shell.test.ts
luanvdw
left a comment
There was a problem hiding this comment.
@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.
- 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.tspackages/cli/src/lib/diagnostics.tspackages/cli/src/lib/git/local-status.ts
branch list --verbosedrops 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
2cb3cfc to
0551127
Compare
|
Addressed both review points:
Validated with pnpm test, pnpm build:cli, and git diff --check. |
There was a problem hiding this comment.
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
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (29)
packages/cli/package.jsonpackages/cli/src/cli.tspackages/cli/src/controllers/app-env-file.tspackages/cli/src/controllers/app-env.tspackages/cli/src/controllers/app.tspackages/cli/src/controllers/branch.tspackages/cli/src/lib/diagnostics.tspackages/cli/src/lib/git/local-status.tspackages/cli/src/presenters/app-env.tspackages/cli/src/presenters/app.tspackages/cli/src/presenters/branch.tspackages/cli/src/presenters/project.tspackages/cli/src/presenters/verbose-context.tspackages/cli/src/shell/command-runner.tspackages/cli/src/shell/diagnostics-output.tspackages/cli/src/shell/output.tspackages/cli/src/shell/ui.tspackages/cli/src/types/app-env.tspackages/cli/src/types/app.tspackages/cli/src/types/branch.tspackages/cli/src/types/diagnostics.tspackages/cli/tests/app-controller.test.tspackages/cli/tests/app-env.test.tspackages/cli/tests/app-presenter.test.tspackages/cli/tests/branch-controller.test.tspackages/cli/tests/branch.test.tspackages/cli/tests/command-runner.test.tspackages/cli/tests/project.test.tspackages/cli/tests/shell.test.ts
Signed-off-by: Aman Varshney <amanvarshney.work@gmail.com>
0551127 to
dc84601
Compare
|
Did another stress pass and addressed the new JSON-contract guard:
Validated again with pnpm test, pnpm build:cli, and git diff --check. |
There was a problem hiding this comment.
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
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (29)
packages/cli/package.jsonpackages/cli/src/cli.tspackages/cli/src/controllers/app-env-file.tspackages/cli/src/controllers/app-env.tspackages/cli/src/controllers/app.tspackages/cli/src/controllers/branch.tspackages/cli/src/lib/diagnostics.tspackages/cli/src/lib/git/local-status.tspackages/cli/src/presenters/app-env.tspackages/cli/src/presenters/app.tspackages/cli/src/presenters/branch.tspackages/cli/src/presenters/project.tspackages/cli/src/presenters/verbose-context.tspackages/cli/src/shell/command-runner.tspackages/cli/src/shell/diagnostics-output.tspackages/cli/src/shell/output.tspackages/cli/src/shell/ui.tspackages/cli/src/types/app-env.tspackages/cli/src/types/app.tspackages/cli/src/types/branch.tspackages/cli/src/types/diagnostics.tspackages/cli/tests/app-controller.test.tspackages/cli/tests/app-env.test.tspackages/cli/tests/app-presenter.test.tspackages/cli/tests/branch-controller.test.tspackages/cli/tests/branch.test.tspackages/cli/tests/command-runner.test.tspackages/cli/tests/project.test.tspackages/cli/tests/shell.test.ts
luanvdw
left a comment
There was a problem hiding this comment.
@AmanVarshney01 CodeRabbit's feedback is minor, approving the PR so long 🙏
Summary
This makes the global diagnostics flags useful in the way we discussed:
--verboseenriches successful human output with safe state/context.--tracestays failure-only for stacks, API/debug details, and deeper causes.--trace.What changed
Verbose success diagnostics
Successful human commands append a
Local contextblock when--verboseis enabled: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: noCommand-specific resolved context
project show --verboseand the main app/project commands now include resolved workspace/project context before the generic local context.Covered commands:
app deployapp showapp list-deploysapp openapp promoteapp rollbackapp removeproject env add/update/list/removebranch listThe repeated workspace/project/source formatting lives in a shared presenter helper so the output stays consistent across commands.
App deploy verbose settings
app deploy --verbosenow answers “what exactly did we deploy?” with safe deploy settings: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: yesProject env and branch verbose context
project env * --verboseshows 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_KEYbranch list --verboseincludes 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 diagnosticsWith
--trace, stack/debug details are shown:$ prisma-cli some-command --trace Error: boom at explode (...)For structured
CliErrorfailures, the existingTrace: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 deployalso 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.0Checks
pnpm --filter @prisma/cli testpnpm --filter @prisma/cli buildgit diff --checkNote:
pnpm --filter @prisma/cli lintis not available because the package does not define alintscript.