Skip to content

feat(policy): show every policy setting on its own row in policy show - #78

Merged
Sahilb315 merged 2 commits into
mainfrom
claude/pensive-sagan-3x8any-policy-show
Nov 21, 2026
Merged

Sahilb315 merged 2 commits into
mainfrom
claude/pensive-sagan-3x8any-policy-show

Conversation

@abhisek

@abhisek abhisek commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

What was wrong

safedep policy show printed the policy settings on one line, joined by ·:

Default policy  revision 2 · scan_gate.fail_on: high · scan_gate.fail_on_attacks: fail · scan_gate.licenses.deny: GPL-2.0, GPL-2.0-only, ... · scan_gate.licenses.unknown: allow
  • Long lines. The line grows with every setting and every list item, so it wraps badly and does not scale.
  • The wrong layer. It showed only SafeDep's default policy, never the tenant's base. If the base set fail_on: medium, the view still printed high.
  • No sign of what an override changes. The reader had to run policy get.
  • No wrapping. The head revision line and the overrides table's description could pass 80 columns.

What changes

A settings section lists every setting the CLI knows, grouped by parent path. Each row shows the value that applies and the layer that sets it: base, default policy, or - with "not set, each tool uses its local value". Under a setting, each override that sets it gets its own row, highest priority first, and an expired override is marked , expired.

At 80 columns:

Policy          default-team.safedep-io.safedep.io
Head revision   4 · published 14d ago by abhisek@safedep.io ·
                "update package rule r_p0jz0vqmxa"
Open changes    none
Package rules   1 (0 trust, 1 block) · safedep policy rule list
Default policy  revision 2

Settings
SETTING            SOURCE          VALUE
package_admission.cooldown
  min_age          -               not set, each tool uses its local value
scan_gate
  fail_on          default policy  high
  fail_on_attacks  default policy  fail
scan_gate.licenses
  deny             default policy  GPL-2.0, GPL-2.0-only, GPL-2.0-or-later,
                                   GPL-3.0, GPL-3.0-only, GPL-3.0-or-later,
                                   AGPL-3.0, AGPL-3.0-only, AGPL-3.0-or-later
  allow            -               not set, each tool uses its local value
  unknown          default policy  allow
See the settings document: safedep policy get
  • Wrapping.
    • Values wrap to the width of stdout, after a list item and otherwise at a space.
    • The SOURCE column grows for override sources up to a third of the width. A wider source goes on its own line.
    • The overrides table's description cell wraps too.
    • When stdout is not a terminal, nothing wraps.
  • Unknown settings. When the policy holds a setting that this CLI's SDK does not know, a note asks the reader to update the CLI.
  • Hints. The Package rules line points to safedep policy rule list.
  • Shared helpers. cloudpolicy.WrapWords counts display columns and serves both the edit template and this view. The template output is byte-identical.
  • Machine output. JSON and plain output do not change. Plain output keeps no settings rows.

Tests

  • TestShowRenderTable and TestShowRenderTable_Example cover:

    • a long license list at 80 and 140 columns;
    • an empty base;
    • no overrides, and several overrides with an expired one;
    • a 63-character override name;
    • a list item with spaces;
    • escaped server text;
    • unknown settings;
    • a narrow terminal;
    • no wrap off a terminal.

    Each case checks that no line passes the width.

  • TestLeafPathsMergeByReplace fails if a setting stops merging by replace. The SOURCE column assumes the nearest layer wins.

  • TestWrapWords checks wrapping by display width.

Known limits

  • A long word still overflows. One token with no space, such as a long LicenseRef- id, can pass the width.
  • The overrides table cannot wrap a long name. dry/tui's table has no width or cell-wrap option, so a long override name widens the table. wrapLastColumn works around the missing option for the description cell. A dry/tui table width option would remove that workaround.

Generated by Claude Code

Summary by CodeRabbit

  • New Features
    • The policy display now shows settings with their base, default, and override values, including override expiry and matching details.
    • Unknown settings are identified, and package-rule details include a shortcut to view the rules when rules are present.
    • Policy output wraps to the terminal width for easier reading.
  • Documentation
    • Updated the policy display guide with descriptions of the settings and a revised example.

The table view of `safedep policy show` put every setting of the SafeDep
default policy on one "Default policy" line, joined by middle dots. A license
deny list made the line run far past an 80 column terminal, and each new
setting made it longer. The view also never showed the settings of the
tenant base, so a base value hid behind the default value on that line, and
it did not say which settings a policy override changes.

The view now has a Settings section with one setting on each row, grouped by
the parent of its path, as scan_gate.licenses. Each row shows the value that
every subject gets and its layer, base or default policy, in the source
words of the subject policy views. Each policy override that sets the field
adds a row below it, from the highest priority to the lowest. A list value
wraps after an item to the terminal width. The head revision line, the empty
messages and the override description also wrap, so no line passes the
terminal width. The summary keeps a short "Default policy  revision N" row
and points to `safedep policy rule list` and `safedep policy get`.

The JSON and plain output do not change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MhRi597EX9odoSDXbVBsxz
The first version of the settings section in `safedep policy show` had
gaps:

- One long override name widened the SOURCE column for every row, so each
  row passed the terminal edge. A name can have 63 characters.
- An override past its expiry showed its value as if it still applied.
- The section listed only the settings that a layer sets, and it hid a
  setting that this CLI's SDK does not know without a word.
- The view read the width of stderr, so output to a file wrapped at the
  terminal width, and output on a wide terminal with stderr redirected
  wrapped at 80 columns.
- The word wrap copied the one of the edit template.

Now the SOURCE column fits the layers and the override sources up to a
third of the width. A longer override source takes a line of its own, with
the value on the next line. An expired override keeps its row, with
", expired" after its source. The section lists every settings path of the
contract, with "-" and "not set" when no layer sets it, and a note when the
policy holds settings that this CLI does not know. The view wraps to the
width of stdout, and does not wrap when stdout is not a terminal.

cloudpolicy.WrapWords is now the one word wrap. It counts display columns,
and the edit template output does not change. A cloudpolicy test fails when
a settings path stops to merge by replace, because the SOURCE column
assumes that the nearest layer wins.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MhRi597EX9odoSDXbVBsxz
@safedep

safedep Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

SafeDep Report Summary

Green Malicious Packages Badge Green Vulnerable Packages Badge Green Risky License Badge

No dependency changes detected. Nothing to scan.

View complete scan results →

This report is generated by SafeDep GitHub App

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-20T13:52:40.805912Z 8f2d9c5 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The policy show command now collects base, default, and override settings and renders them in terminal-width-aware sections. The output includes setting sources, expiry labels, unknown-setting notices, and override details.

Changes: Policy Show

Layer / File(s) Summary
Collect policy settings
internal/cmd/policy/show.go, internal/cmd/policy/show_settings.go, internal/cmd/policy/view.go, internal/cloudpolicy/fields_test.go
The show result now carries base fields and unknown-setting status. Setting views follow contract leaf-path order, use base values ahead of defaults, mark unset values, and include override values and expiry status.
Add terminal-width rendering helpers
internal/cloudpolicy/render.go, internal/cloudpolicy/template.go, internal/cmd/policy/show_render.go, internal/tui/width.go, internal/cloudpolicy/fields_test.go
Shared helpers pad and wrap text, render override tables, and obtain stdout width. Policy template notes now use the shared word-wrapping helper.
Compose policy show output
internal/cmd/policy/show.go, internal/cmd/policy/show_settings.go, internal/cmd/policy/show_test.go, docs/cmd/policy-show.md
The command composes summary, settings, and override sections. The updated tests and documentation cover setting sources, expiry, unknown settings, wrapping, and the revised example output.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Feature

Suggested reviewers: sahilb315

Merge Risk: Minimal · up to 8f2d9

The change makes safedep policy show display each setting with its source, expiry labels, and terminal-width wrapping. This is a read-only display change, and I found no supported defect in the supplied code or tests, so merge-readiness risk is minimal.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: policy show now lists every policy setting on its own row. The raw summary and objectives confirm a new Settings section in the table view that lists each known settin…
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.
Full details: Title check

Explanation

The title names the main change: policy show now lists every policy setting on its own row. The raw summary and objectives confirm a new Settings section in the table view that lists each known setting with its effective value and source. The title is specific and matches the changeset, so it passes.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: QUIET
  • Plan: Advanced
  • Run ID: 8aee20f8-664f-447a-9716-31027ed371a9
Commits

Reviewing files that changed from the base of the PR and between 3acdc4b and 8f2d9c5.

Files selected for processing: 10

  • docs/cmd/policy-show.md
  • internal/cloudpolicy/fields_test.go
  • internal/cloudpolicy/render.go
  • internal/cloudpolicy/template.go
  • internal/cmd/policy/show.go
  • internal/cmd/policy/show_render.go
  • internal/cmd/policy/show_settings.go
  • internal/cmd/policy/show_test.go
  • internal/cmd/policy/view.go
  • internal/tui/width.go

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@Sahilb315 Sahilb315 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed the settings view, the wrap helpers and the override table. Build and the policy, cloudpolicy and tui tests pass on the head commit. Server text is escaped before it wraps. JSON and plain output keep their shape. TestLeafPathsMergeByReplace guards the rule that the nearest layer wins. No blocking issues.


Generated by Claude Code

@Sahilb315
Sahilb315 merged commit 274094a into main Nov 21, 2026
7 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.

3 participants