fragments/govern
coreRun Fragments design governance checks, review staged changes, and fix violations inline. Use when the user wants to check UI code for design issues, review changes before committing, run a governance check, fix accessibility or consistency problems, or validate code against design policies.
Fragments Govern
Run design governance checks, review pre-commit changes, and fix violations.
Prerequisites
@fragments-sdk/govern and @fragments-sdk/cli must be installed, and fragments.config.ts must exist. If not, run /fragments-cloud-setup first.
Modes
Parse $ARGUMENTS to determine the mode:
- check (default): Run checks and report violations
- fix: Run checks, then automatically fix violations that have auto-fixes
- review: Check only staged/uncommitted UI files (pre-commit review)
- status: Show current violation count and trends
If no mode is specified, default to check.
Check mode
- Verify @fragments-sdk/govern and @fragments-sdk/cli are installed. If not, offer to run /fragments-cloud-setup.
- If a file path is provided in $ARGUMENTS, scope the check to that path.
- Run:
sh
npx fragments govern check --cloud --format json - Parse the JSON output. The response shape:
json
{ "summary": { "errors": 3, "warnings": 7, "info": 1, "files": 4 }, "violations": [ { "rule": "accessibility/color-contrast", "severity": "error", "file": "src/components/Card.tsx", "line": 42, "message": "Contrast ratio 2.8:1 is below minimum 4.5:1", "fix": { "property": "color", "value": "var(--fui-text-primary)" } } ] } - Present results:
- Group violations by severity (error, warning, info)
- Group by file for easier navigation
- Show the rule name, line number, and a snippet of offending code
- Summarize: "X errors, Y warnings, Z info across N files"
Fix mode
- Run the check to identify violations.
- For violations with a fix field:
- Show the proposed change
- Apply it
- For violations without auto-fixes, explain what needs to change and why.
- Re-run the check to confirm fixes applied correctly.
Review mode
Pre-commit design review -- checks only changed files.
- Determine scope:
- If $ARGUMENTS contains --staged, check only git-staged files
- Otherwise check all uncommitted changes (staged + unstaged)
- Gather changed UI files:
sh
git diff --cached --name-only --diff-filter=ACMR -- '*.tsx' '*.jsx' '*.vue' '*.svelte' '*.astro' - Run the governance check scoped to those files:
If the --files flag is not available, pass each file path as a positional argument.sh
npx fragments govern check --cloud --format json --files <file-list> - Present findings grouped by file with line numbers.
- Offer to auto-fix violations that have fixes available.
- If no issues: confirm with "All clear -- ready to commit."
Status mode
- Run:
sh
npx fragments govern status --cloud --format json - The response shape:
json
{ "total": 11, "trend": { "previous": 14, "direction": "improving" }, "topRules": [ { "rule": "consistency/design-tokens", "count": 5 }, { "rule": "accessibility/color-contrast", "count": 3 }, { "rule": "responsive/touch-targets", "count": 2 } ], "topFiles": [ { "file": "src/components/Card.tsx", "count": 4 }, { "file": "src/pages/Settings.tsx", "count": 3 } ] } - Show: total open violations, trend vs. last check, top 3 most common violation types, files with the most violations.
Check categories reference
When explaining violations, reference these:
- accessibility: Color contrast, ARIA labels, keyboard navigation, focus management, alt text
- consistency: Design token usage, spacing patterns, component prop consistency, naming conventions
- responsive: Breakpoint coverage, flexible layouts, touch targets, viewport handling
Always show the exact rule name so users can look it up or create policy exceptions.
Common mistakes
CRITICAL: Missing --cloud flag with cloud-synced policies
Running govern check without --cloud only runs local rules. Cloud-synced policies and team-wide settings are skipped silently.
Wrong:
npx fragments govern check --format json
Correct:
npx fragments govern check --cloud --format json
If the project has cloud: true in fragments.config.ts, always include --cloud.
HIGH: Committing auto-fixes without review
Fix mode applies changes automatically, but some fixes may be incorrect (e.g., a token substitution that picks the wrong semantic color). Always review the diff before committing.
Wrong workflow:
npx fragments govern fix --cloud
git add . && git commit -m "fix violations"
Correct workflow:
npx fragments govern fix --cloud
git diff # review what changed
npx fragments govern check --cloud # confirm no new violations
git add -p # stage selectively
MEDIUM: Parsing human-readable output programmatically
Without --format json, the output is human-readable text that changes between versions.
Wrong:
npx fragments govern check --cloud | grep "error"
Correct:
npx fragments govern check --cloud --format json
Always use --format json when parsing output programmatically. Use --format github in GitHub Actions to get PR annotations.