Skip to content

Polish /permissions command output into a bounded card - #205

Merged
gnanam1990 merged 3 commits into
mainfrom
worktree-command-ui-polish
Jun 15, 2026
Merged

Polish /permissions command output into a bounded card#205
gnanam1990 merged 3 commits into
mainfrom
worktree-command-ui-polish

Conversation

@Vasanthdev2004

@Vasanthdev2004 Vasanthdev2004 commented Jun 15, 2026

Copy link
Copy Markdown
Collaborator

What

Converts /permissions from the old status: ok plain-text dump into the bounded commandCard format already used by /tools and /context.

Before

Permissions
status: ok
State
  Permission mode: ask
Sandbox grants:
  persistent grants: 1
  - bash [allow/high] - ...

After

Permissions
ask permissions · 1 persistent grant
State
  mode  ask
Grants
  - bash [allow/high] - ...

Changes

  • internal/tui/command_views.gopermissionsText() now renders a commandCard with a bold summary line, aligned mode field, and bullet rows for each persistent sandbox grant.
  • Nil-store and error cases are rendered as cards instead of status: warning / status: blocked.
  • Updated internal/tui/command_polish_test.go and internal/tui/model_test.go assertions.
  • Added TestPermissionsCommandCardHandlesNilStoreAndEmptyGrants.

Validation

  • go test ./internal/tui -count=1
  • go vet ./internal/tui
  • go run ./cmd/zero-release build
  • go run ./cmd/zero-release smoke

Pre-existing unrelated failure: TestRunExecUsesProjectConfigAndOpenAICompatibleProvider in internal/cli fails on clean main with anthropic provider anthropic requires official baseURL https://api.anthropic.com.

Summary by CodeRabbit

  • Improvements
    • Enhanced /permissions output with structured, card-based sections for clearer State and Grants details, including mode and persistent grant counts.
    • Improved messaging when grant data is unavailable, empty, or fails—showing appropriate “unavailable/none/error” content and propagating error details when relevant.
  • Tests
    • Expanded /permissions rendering tests to cover nil, empty, and failure cases, and to ensure outdated flat status markers are no longer shown.

Replace status: ok style with commandCard format used by /tools and /context.

Summary shows mode and grant count; grants render as bullet rows.

Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions

github-actions Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Zero automated PR review

Verdict: No blockers found

Blockers

  • None found.

Validation

  • [pass] Diff hygiene: git diff --check
  • [pass] Tests: go test ./...
  • [pass] Build: go run ./cmd/zero-release build
  • [pass] Smoke build: go run ./cmd/zero-release smoke

Scope

Head: 64470c4d960c
Changed files (3): internal/tui/command_polish_test.go, internal/tui/command_views.go, internal/tui/model_test.go

This deterministic review checks validation status and basic diff hygiene. A human reviewer still owns product judgment and design quality.

@coderabbitai

coderabbitai Bot commented Jun 15, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 609aa2c2-6d8a-47ac-b41f-c955c78e9810

📥 Commits

Reviewing files that changed from the base of the PR and between 2b3e56e and 64470c4.

📒 Files selected for processing (1)
  • internal/tui/command_views.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/tui/command_views.go

Walkthrough

permissionsText is rewritten to emit a renderCommandCardTranscript permissions card instead of renderCommandOutput blocks. A new permissionsTextWithStore helper routes nil-store, list-error, and normal cases to card-based rendering. A formatGrantCount helper produces 0/1/many phrasing. Three test files are updated to assert the new structured card output with section headers and reject old status markers; a new comprehensive test covers nil-store, empty-store, and error cases.

Changes

Permissions card transcript rewrite

Layer / File(s) Summary
permissionsText rewrite and formatGrantCount helper
internal/tui/command_views.go
Adds sandbox import; refactors permissionsText to route through permissionsTextWithStore, which produces a renderCommandCardTranscript card for nil-store ("grants unavailable"), list-error ("grants error" with message), and normal cases. Introduces grantLister interface for test stubbing; adds formatGrantCount helper for 0/1/many grant summary strings; converts SandboxGrantSnapshots into commandRow entries in a "Grants" card section.
Test coverage for card output and error paths
internal/tui/command_polish_test.go, internal/tui/model_test.go
Adds errors import and test double stubGrantStore for grant-store failure simulation. Updates TestContextAndPermissionsCommandsRenderProductState and TestPermissionsCommandListsPersistentSandboxGrants assertions to expect card section headers ("State", "mode", "Grants") and adds assertNotContains checks for status: ok and Permission mode:. Adds TestPermissionsCommandCardHandlesNilStoreAndEmptyGrants covering nil-store ("grants unavailable"/"persistent grants: unavailable"), empty-store ("no persistent grants"/"none"), and list-error ("grants error" with message) paths, all without old status-marker text.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • Gitlawb/zero#201: Introduced the renderCommandCardTranscript infrastructure for /context and /tools that this PR now applies to /permissions.

Suggested reviewers

  • gnanam1990
🚥 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
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main objective of the PR—converting the /permissions command output to a bounded card format, which is the primary focus across all modified files.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch worktree-command-ui-polish

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
internal/tui/command_views.go (1)

283-301: ⚡ Quick win

Add test coverage for the grant list error case.

The error path when sandboxStore.List() returns an error is not covered by tests. The nil store and empty grants cases are tested in TestPermissionsCommandCardHandlesNilStoreAndEmptyGrants, but the error case should also be validated to ensure the error card renders correctly.

🧪 Example test to add
func TestPermissionsCommandCardHandlesGrantListError(t *testing.T) {
	store := &stubGrantStore{listErr: errors.New("storage failure")}
	text := model{permissionMode: agent.PermissionModeAsk, sandboxStore: store}.permissionsText()
	for _, want := range []string{
		"Permissions",
		"ask permissions",
		"grants error",
		"mode  ask",
		"error: storage failure",
	} {
		assertContains(t, text, want)
	}
	assertNotContains(t, text, "status: warning")
}
🤖 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 `@internal/tui/command_views.go` around lines 283 - 301, Add test coverage for
the error case in the grant list retrieval path. Create a new test function
TestPermissionsCommandCardHandlesGrantListError that uses a stubGrantStore with
a listErr field set to a test error, then calls permissionsText() and verifies
that the error card renders correctly by asserting that expected strings like
"Permissions", "ask permissions", "grants error", and "error: storage failure"
appear in the output, while also asserting that unexpected strings like "status:
warning" do not appear.
🤖 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.

Nitpick comments:
In `@internal/tui/command_views.go`:
- Around line 283-301: Add test coverage for the error case in the grant list
retrieval path. Create a new test function
TestPermissionsCommandCardHandlesGrantListError that uses a stubGrantStore with
a listErr field set to a test error, then calls permissionsText() and verifies
that the error card renders correctly by asserting that expected strings like
"Permissions", "ask permissions", "grants error", and "error: storage failure"
appear in the output, while also asserting that unexpected strings like "status:
warning" do not appear.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: c1f26d6b-7dc9-4c91-962b-e210965092e9

📥 Commits

Reviewing files that changed from the base of the PR and between 135e3c5 and 25b9722.

📒 Files selected for processing (3)
  • internal/tui/command_polish_test.go
  • internal/tui/command_views.go
  • internal/tui/model_test.go

Vasanthdev2004 and others added 2 commits June 15, 2026 11:06
Adds TestPermissionsCommandCardHandlesGrantListError and a grantLister

interface so tests can inject a stub store without a real file path.

Co-Authored-By: Claude <noreply@anthropic.com>
Tabs alignment only; no functional change.

Co-Authored-By: Claude <noreply@anthropic.com>

@gnanam1990 gnanam1990 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Review — Polish /permissions into a bounded card

Verdict: Approve. Clean, well-scoped, well-tested, and the security-sensitive bit (grant-reason redaction) is preserved. CI green across all platforms; TUI-only, 3 files.

What it does

Converts /permissions from the legacy commandOutput (status: ok dump) to the commandCard format already used by /tools and /context: a bold summary line, an aligned mode field, and bulleted grant rows. The nil-store / List() error / empty-grants cases now render as cards (state in the summary) instead of status: warning|blocked.

Strengths

  • Redaction preserved (defense in depth). Grant reasons are redacted in SandboxGrantSnapshots (sandbox_snapshot.go:50) and every card line/row passes through redaction.RedactString via compactCommandOutputText (command_output.go:118,123). The tests assert [REDACTED] present and sk-proj-sensitive absent — no leak through the new path. ✅
  • Good testability seam. permissionsTextWithStore(grantLister) + the small grantLister interface let the new error-path test inject a stub store without reaching for a real filesystem path. Idiomatic.
  • Coverage. New TestPermissionsCommandCardHandlesNilStoreAndEmptyGrants exercises nil-store, empty-grants, and List()-error; existing tests are updated to the card format and add assertNotContains for the old status: ok / Permission mode: markers (guards against silent regression).
  • formatGrantCount pluralizes 0/1/n correctly. Provider-neutral, no new deps, no network/fs/exec.

Minor (non-blocking) suggestions

  1. Lines vs Rows in the Grants section. The success path uses Rows (renders - text), the nil/error paths use Lines (no bullet), and the empty case uses Rows{Text:"none"} (- none). Harmless, but a single shape for the Grants section across all states would read more uniformly.
  2. Status semantics for nil/error. The card has no status badge, so the old warning/blocked states are now conveyed only by the summary phrase (grants unavailable / grants error). That's the intended alignment with /tools//context — just confirm the error state still reads as clearly "something's wrong".

Risk: low

Rendering-only; no change to permission enforcement and no new surface. CI green (smoke macos/ubuntu/windows, perf, security, CodeRabbit).

@gnanam1990
gnanam1990 merged commit 265aa52 into main Jun 15, 2026
7 checks passed
@Vasanthdev2004
Vasanthdev2004 deleted the worktree-command-ui-polish branch June 28, 2026 08:27
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