Introducing a new way to review your PRs.

Read the announcement

kenryu42 / cc-safety-net

A pre-execution guard for AI coding agents. It blocks destructive Git and file system commands, plus common attempts to access sensitive files, before a tool call runs. Supports Amp Code, Antigravity CLI, Claude Code, Codex, Cursor, DeepSeek Harness, Devin CLI, GitHub Copilot CLI, Grok Build, Hermes Agent, Kimi Code, OpenClaw, OpenCode, and Pi.

View on GitHub

20 documents · Updated Nov 23, 2026

docs / operator-interfaces

Operator interfaces

Safety Net gives engineers two main operator surfaces: a command-line interface (CLI) for repeatable setup, checks, configuration, and diagnosis, and a local browser GUI for visual policy and activity control. Both surfaces work with the same protection state, rule sources, integrations, and audit history, so operators can move from setup to review without changing the system under inspection.

Operator surface map

An operator interface is a user-facing way to control or inspect Safety Net. The CLI is the direct path for terminal work and automation. The browser GUI is a local dashboard for policy, activity, rules, integrations, and maintenance.

flowchart LR
    A[Install or configure] --> B[Protection and rule state]
    B --> C[Agent hooks]
    C --> D[Safety decisions]
    D --> E[Local audit history]
    B --> F[CLI inspection and diagnosis]
    E --> F
    B --> G[Local browser GUI]
    E --> G
    G --> B

The operator surfaces do not replace the hook path that protects tool calls. They expose the state that the hook path uses and provide controlled ways to change installation, policy, and rule sources.

Command-line interface

The CLI is the primary surface for installation, maintenance, inspection, and diagnosis. The top-level runner applies shared options and sends each command to one focused workflow, which returns a process result that people and scripts can use.

Command groups

The command set follows the operator lifecycle rather than exposing internal engine stages. Installation can use an interactive target picker on a terminal, while non-interactive use names one target explicitly.

Operator needCLI surfaceOutcome
Install or remove agent supportinstall, uninstall, updateAgent CLIs receive, lose, or refresh their Safety Net integration.
Manage custom protectionsrule init, rule add, rule remove, rule update, rule migrate, rule sync, rule wrapper, rule tool, rule list, rule verify, rule docRule sources, wrappers, declared shell tools, and rulebooks are created, synchronized, checked, listed, migrated, or explained.
Propose or apply policy changespolicy check, policy applyA policy file is validated and shown as a diff before an interactive apply.
See current enforcementstatusThe operator sees the active posture and inactive conditions.
Check system healthdoctorInstallation, hooks, configuration, effective safety, engine self-test, environment, activity, and updates are assessed together.
Inspect past decisionslogsRetained audit entries can be filtered, viewed, exported, or safely cleaned up when they are legacy records.
Understand one commandexplainA command receives a step-by-step analysis without being run.
Open the visual surfaceguiA local policy and activity interface starts in the browser.
Provide agent-facing display datahook, statuslineHook input is evaluated or a compact safety state is printed for an agent display.

The hook and statusline commands are mainly called by integrations rather than typed by an operator. The hook surface resolves one named integration at a time, so an invalid or ambiguous selection does not run an unintended hook.

References: src/…/main.ts• L35-138 src/…/index.ts• L1-32 src/…/rule.ts• L22-79 src/…/index.ts• L467-513 src/…/index.ts• L801-947 src/…/index.ts• L60-73

CLI input and output contract

Each command declares its accepted options and argument shape. The shared argument layer gives commands consistent help handling, unknown-option errors, required-value checks, list values, and positional-argument rules. This makes terminal use predictable for people and scripts.

Operators can use command help to discover a workflow. doctor, logs, and explain can emit structured results for scripts or support tools, while human output stays focused on action and diagnosis. Exit codes distinguish a completed check from a command that could not provide a valid result.

Terminal output uses color only when stdout is an interactive terminal and the operator has not set NO_COLOR. This keeps the same messages usable in redirected output and scripts.

Policy proposals have a deliberate review boundary. policy check validates a proposal and prints its changes. policy apply requires terminal confirmation and does not provide a silent approval option.

The rule interface keeps successful changes and validation results separate from errors. Rule changes report their scope and active rulebook summary. rule list then shows active sources and rules, disabled rules, reason overrides, transparent wrappers, issues, and warnings. rule tool list is the separate view for declared command tools. rule doc provides the reference for rule scopes, sources, and matching behavior. rule migrate converts legacy inline rule files into rulebooks, syncs the new source, and removes the old file only after verification when --cleanup is used.

explain analyzes one command without running it. The command may use --cwd to select an existing working directory and --shell to select auto, posix, or powershell parsing. Human output shows the trace in a terminal-friendly step layout with command tokens and rule results, while --json supports machine use. The human layout uses ASCII-safe borders when output is not an interactive color terminal. The parser accepts the command as the remaining positional input and tells the operator to use -- when a command starts with option-like dashes. If command syntax, tool input, or path work exceeds a safety limit, the CLI returns a clear error and a failing exit code instead of hiding the incomplete analysis.

References: src/…/args.ts• L1-102 src/…/help.ts• L82-168 src/…/index.ts• L41-135 src/…/explain.ts• L3-33 src/…/flags.ts• L5-60 src/…/run.ts• L22-63 src/…/format-helpers.ts• L23-263 src/…/rule.ts• L22-79 src/…/index.ts• L77-215 src/…/index.ts• L222-370 src/…/format.ts• L10-174 src/…/doc.ts• L1-19 src/…/migrate.ts• L52-159 src/…/verify.ts• L39-191

Rule source workflow

Custom rules extend built-in protections through user and project rule configurations. An operator can create a config, add local or repository rulebook sources, refresh vendored copies, and inspect the effective result without changing the built-in safety layer.

The workflow also covers two ways to describe commands that Safety Net must understand:

  • A transparent wrapper names a command that runs a visible child command.
  • A command tool names a shell tool supplied by an agent. It can include the argument that carries the tool's working directory.

User and project scopes remain distinct. A project operation cannot silently write the user config, and a command tool added with --project stays in project scope. rule list presents the effective rulebooks, overrides, wrappers, and diagnostics. rule tool list presents declared command tools from the available scopes.

Legacy inline configs are ignored by normal rule loading. rule migrate writes their rules into a rulebook and syncs the new source. It keeps the legacy file when cleanup is not requested. With --cleanup, it verifies that the new rulebook contains the same rules before removing the old file. The migration covers both project and user scopes, and skips a project path that resolves to the user rule config.

rule verify reports invalid active configs, inactive legacy configs, invalid rulebook directories, and fixture failures. A valid config can also receive the rule schema link when it is missing.

Rule changes show the affected scope and summarize each active rulebook with its name, version, rule count, and source. The list view separates active rules from disabled rules and reason overrides, then reports transparent wrappers, issues, and warnings. Declared command tools show their scope and any configured working-directory argument.

References: src/…/rule.ts• L3-79 src/…/index.ts• L107-215 src/…/index.ts• L282-370 src/…/index.ts• L394-539 src/…/format.ts• L10-174 src/…/doc.ts• L5-19 src/…/migrate.ts• L52-159 src/…/migrate.ts• L201-300 src/…/verify.ts• L214-281

Browser GUI

The browser GUI is a local control panel for policy, activity, rulebooks, integrations, and maintenance. The gui command starts a short-lived HTTP service on loopback, gives the page a session token and saved display preferences, and opens the browser unless the operator requests the URL only.

GUI session

The server binds to the local machine and keeps running until the process receives a shutdown signal. Each page session receives a random token. Browser requests must carry it in the URL, and write requests must also send it in a header.

The server rejects requests without the matching token and limits request bodies to a fixed size. This protects the local control surface from unauthenticated or unbounded state changes. If the system cannot open a browser, the CLI prints the URL so the operator can open it manually. --no-open provides the same manual flow without trying to launch a browser.

The page is built from the shared HTML, style, and browser scripts before it is served. The server places the session token and saved GUI preferences into the page bootstrap. The browser then uses that data to set its initial language and color scheme before the main views load.

The GUI exposes policy preview, policy explanation, policy save and repair, project policy selection and apply, activity, rules, integration status, integration install and uninstall, health, preferences, and maintenance actions. Integration changes run one at a time so concurrent page clicks do not change the same host configuration together.

References: src/…/index.ts• L143-205 src/…/index.ts• L225-263 src/…/index.ts• L683-705 src/…/assets.ts• L21-61 src/…/page.ts• L4-11 src/…/gui-data.ts• L1-6

GUI views

The GUI groups related operator work into views. The browser applies the selected view from the URL hash and loads shared policy and integration state first. Activity, overview, and other view data then use that shared state.

ViewOperator question
OverviewWhat has Safety Net blocked or analyzed, and is the protection state healthy?
ActivityWhich recent decisions, agents, rules, or commands need review?
ProtectionsWhich safety preset, protections, paths, and audit retention settings are active?
Custom rulesWhich custom rulebooks are enforced, and where are their problems?
AgentsWhich supported agent CLIs are detected, installed, disabled, or not inspected?
SettingsWhere are policy and audit data stored, what is the retention period, which browser appearance and language are selected, and what maintenance actions are available?

The views connect to each other. A blocked rule can lead to its recent activity, an activity item can lead to related policy or rule context, and a health warning can lead to agent repair. This lets an operator move from evidence to the action that can resolve it.

References: src/…/page.html• L13-31 src/…/page.html• L36-364 src/…/main.ts• L23-95 src/…/overview.ts• L17-90 src/…/health.ts• L13-48

GUI policy workflow

The Protections view separates an unsaved draft from the saved policy. Operators can select a safety level, adjust protections and paths, preview the result, test a command against the draft, and save the confirmed policy. Hook evaluations continue to use the saved policy until the draft is saved.

The GUI can also draft a project policy for a selected directory. It shows the effective diff before applying the change and rejects project proposals that try to set user-only audit settings. A directory revision prevents a draft from being applied after the selected project folder changes.

The policy surface supports recovery. It can report an unreadable policy, preserve valid settings when possible, restore defaults when needed, and keep an unsaved draft available in the same browser session. Custom rule authoring stays in the CLI rule workflow; the Custom rules view displays enforced rulebooks and can create a scoped prompt for an external coding agent.

References: src/…/index.ts• L266-409 src/…/index.ts• L553-667 src/…/policy.ts• L96-141 src/…/policy.ts• L733-877 src/…/rules.ts• L37-118

GUI activity and integration workflow

The Activity view presents retained local audit entries with time, decision, agent, and command filters. It lets an operator inspect a decision, copy its data, report a likely false positive, or start a custom-rule prompt from a blocked command.

The Agents view combines agent discovery with hook state and system information. An operator can install or uninstall a detected target from the page. The view distinguishes active, disabled, not-installed, and not-inspected targets, while health data points to repair when a detected agent lacks an active hook.

Project rule scope can use a native folder picker when the host supports one. If the picker is unavailable or fails, the operator can enter the path directly.

References: src/…/index.ts• L411-457 src/…/index.ts• L479-513 src/…/activity.ts• L118-208 src/…/activity.ts• L234-364 src/…/integrations.ts• L11-110 src/…/rules.ts• L120-179

GUI preferences and localization

The GUI stores language and theme preferences on the local machine. Operators can use English, Japanese, or Simplified Chinese, and can choose automatic, light, or dark display mode.

The page resolves a saved language first and otherwise uses the browser's language list. It formats counts, dates, relative times, labels, and messages with the selected locale. A preference change is saved through the local GUI service and takes effect after the page reloads.

References: src/…/preferences.ts• L1-49 src/…/head.ts• L1-6 src/…/i18n.ts• L1-37 src/…/en.ts• L6-470 src/…/ja.ts• L6-469 src/…/zh-CN.ts• L6-443 src/…/settings.ts• L26-44 src/…/main.ts• L63-81

Operator workflow

The interfaces support a progression from installation to review. Use the CLI when the task must be repeatable or scripted. Use the GUI when the task needs a visual view of policy, activity, or integration state.

  1. Install the needed agent integrations with install. Use update when installed integrations must match the current release.
  2. Run status for a short view of protection, policy, rules, and inactive conditions. Run doctor when the result needs system checks or a machine-readable report.
  3. Set or review policy in the GUI. For a file-based proposal, run policy check first and use policy apply only after reviewing its diff and confirming in a terminal.
  4. Use the rule commands for rulebook sources and custom-rule maintenance. Use rule verify for offline validation and rule migrate for legacy inline rule files.
  5. Use explain to understand one command before changing policy. Set --cwd or --shell when the command depends on a specific working directory or shell grammar. Use logs or the GUI Activity view to inspect decisions that already occurred.
  6. Return to doctor, status, or the GUI health and agent views after a change to confirm that the intended agent hook and policy state are active.

The detailed command lifecycle is covered in CLI command workflows. Decision inspection and audit behavior are covered in diagnostics and audit interfaces. The browser-specific page lifecycle and controls are covered in browser GUI.

Change checklist

When these files or sections are changed, remember to consider these:

  • When the command registry or a command definition changes, keep dispatch, aliases, help output, structured output, exit codes, and the related operator workflow aligned.
  • When install targets or detection states change, keep CLI selection, update discovery, GUI agent rows, health summaries, and agent-facing status consistent.
  • When rule subcommands or scopes change, keep command parsing, help examples, scope protection, output summaries, migration, and verification aligned.
  • When rule migration changes, keep project and user scope handling, legacy-file retention, rulebook provenance, sync behavior, rollback, and cleanup verification aligned.
  • When command tool or transparent-wrapper rules change, keep the config schema, built-in-tool refusals, effective rule listing, and runtime analysis contract aligned.
  • When rulebook validation changes, keep local validation, fixture checks, schema insertion, migration output, and inactive-source diagnostics aligned.
  • When policy proposal fields or scope rules change, keep CLI validation, project diff display, GUI draft serialization, revision checks, and saved policy contracts aligned.
  • When explanation flags, shell parsing, trace limits, or human trace formatting change, keep help text, command reconstruction, working-directory validation, ASCII-safe terminal output, JSON output, limit errors, and exit status aligned.
  • When the GUI request surface changes, preserve the token in the page bootstrap, the URL check for reads, the header check for state-changing requests, and the request size limit.
  • When GUI integration actions change, preserve single-action ordering and keep target validation aligned with the CLI install targets.
  • When audit retention or entry shape changes, check CLI log filters, GUI activity windows, aggregate counts, and incomplete-data messages together.
  • When GUI preference or translation keys change, keep preference validation, early page setup, view labels, formatted values, and all supported locale catalogs aligned.

Important failure modes

TriggerConsequenceGuard
No supported integration is configuredNo coding-agent integration sends its supported activity through Safety Net.doctor reports the missing connection and directs the operator to install.
An agent is detected but its hook is not configuredThat agent does not send its supported activity through Safety Net.doctor, status, and the GUI Agents view expose the inactive state.
An install request names no target or more than one target in a non-interactive sessionThe CLI does not guess which host integration to change.Interactive selection resolves the choice; explicit use must name exactly one target.
An install target cannot write its host configurationThat integration remains unchanged or only partly changed.Install errors include a path-specific permission, missing-path, or invalid-parent hint.
A configured rulebook is invalid or dropped by an overrideIts custom rules are not enforced while other active protections continue.rule verify, rule list, status, doctor, and the GUI Custom rules view expose the issue.
A declared command tool is built in or has an invalid nameThe tool is not added to the custom tool set.rule tool rejects it and reports the required name form.
Legacy inline rule configuration remains in placeThe old rules enforce nothing because runtime loading ignores those files.doctor or rule verify reports the files and directs the operator to rule migrate.
Rule migration cannot sync or verify its new rulebookThe migration fails without leaving a partial config or rulebook change.Migration restores its file snapshots and removes the legacy file only after verification.
A project draft changes directory before applyThe reviewed diff may refer to a different directory than the one being written.The GUI checks the directory revision and rejects stale requests.
A browser request lacks the session token or a state-changing request lacks the token headerThe local GUI rejects the request before it reads or changes operator state.The server checks the URL token for all requests and the header token for POST requests.
An audit source cannot be readCLI and GUI history can be incomplete even when they return results.logs, doctor activity data, and the Activity view report unreadable sources.
A policy proposal is invalid or includes project-forbidden audit settingsNo policy is written.CLI validation and GUI project validation report diagnostics before apply.
A policy draft is changed but not savedHook evaluations continue to use the saved policy.The GUI marks the draft as dirty and separates preview from save.
explain receives invalid flags, a missing working directory, or an unsupported shellThe command is not analyzed.Flag parsing reports the usage error and returns a failing exit code.
A command cannot be parsed or analysis exceeds a safety limitexplain cannot provide a complete trace and does not claim success.Human output reports the limit; JSON output returns an error object with a failing exit code.
A saved GUI preference is invalid or a locale key is missingThe page falls back to a supported language or default display behavior, and part of the UI may lose its intended label.The server accepts only known preference values; locale catalogs implement the shared message contract.

Key files

FileWhy to read it
src/…/main.tsShows the top-level CLI lifecycle from global options to command dispatch and failure handling.
src/…/index.tsDefines the operator command surface and its display order.
src/…/rule.tsDefines the custom-rule command groups, options, and examples.
src/…/explain.tsDefines the public explain purpose, options, usage, and examples.
src/…/index.tsShows how target discovery becomes ordered install, uninstall, and update actions across agent integrations.
src/…/index.tsConnects rule commands to scope selection, source changes, command tools, migration, documentation, and validation.
src/…/format.tsShows how active rulebooks, overrides, wrappers, command tools, and diagnostics become operator-facing output.
src/…/doc.tsProvides the operator-facing custom-rules reference for scopes, sources, schemas, and matching behavior.
src/…/migrate.tsShows the conversion, sync, rollback, and optional cleanup path for legacy inline rule configuration.
src/…/verify.tsShows how rule configuration and rulebooks become operator-facing validation results.
src/…/index.tsShows how the health report combines hooks, policy, environment, activity, self-test, and update state.
src/…/flags.tsShows how explain validates its command, working directory, shell, and output flags.
src/…/run.tsShows how command traces become human or JSON output and how bounded analysis failures reach the operator.
src/…/format-helpers.tsShows how human command-analysis traces use step labels, rule results, and terminal-safe box formatting.
src/…/audit-log.tsDefines retained-history queries and the guarded cleanup path for legacy audit files.
src/…/index.tsShows the local GUI server lifecycle, session protection, browser API surface, policy actions, project draft checks, and integration actions.
src/…/assets.tsShows how the browser document and frontend assets become the served GUI page.
src/…/page.tsShows how session data and saved preferences enter the browser page.
src/…/page.htmlMaps the browser surface into Overview, Activity, Protections, Custom rules, Agents, and Settings views.
src/…/main.tsCoordinates translation, view selection, shared loading, preference changes, and the browser lifecycle.
src/…/preferences.tsDefines supported languages, themes, and preference validation.
src/…/i18n.tsDefines locale selection and localized formatting for browser data.
src/…/en.tsDefines the shared browser message contract and English operator text.
src/…/ja.tsProvides Japanese labels and messages for the browser operator surface.
src/…/zh-CN.tsProvides Simplified Chinese labels and messages for the browser operator surface.
src/…/policy.tsShows how policy drafts, previews, project scope, repair, and save actions become operator controls.
src/…/activity.tsShows how retained decisions become filters, details, reports, and rule follow-up actions.
src/…/integrations.tsShows how detected agents become install, uninstall, and status actions.
src/…/settings.tsShows how theme, language, retention, file paths, and policy reset become maintenance controls.