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 / cli-command-workflows

CLI command workflows

cc-safety-net is the operator-facing command line for checking protection, managing rule policy, connecting coding-agent hosts, and inspecting guard activity. It turns a command line or hook request into one of the shared safety workflows, then reports a human-readable result or a machine-safe protocol response. This page gives the broad CLI model; see operator interfaces, diagnostics and audit interfaces, and browser GUI for related interfaces.

CLI entry flow

Argument parsing

The CLI uses one small argument model for all commands. Each command declares its boolean flags, value flags, list flags, and positional-argument policy. The parser separates recognized options, values, lists, positionals, and errors so each command can apply its own semantic checks after common syntax checks. -h and --help are accepted for every command. A bare -- makes all later text positional, and a value flag never consumes a following token that starts with - (src/…/args.ts• L1-20, src/…/args.ts• L21-97).

Commands report all parse errors before they stop. This keeps bad invocations clear and prevents an unknown option from being treated as command input. Commands with special grammar add checks for valid subcommands and incompatible option combinations after parsing (src/…/args.ts• L79-101, src/…/index.ts• L15-44).

References: src/…/args.ts• L1-20 src/…/args.ts• L21-101 src/…/index.ts• L15-44

Startup and dispatch

The entry point first parses global help and version options, then gives the explicit help command its own path. It resolves the first token as a command name or alias and sends the remaining tokens to that command’s handler. Known command help takes priority over normal command execution, while a missing or unknown command produces the top-level help or an error (src/…/main.ts• L15-33, src/…/main.ts• L98-138).

The command registry is the source for command lookup and help order. Lookup is case-insensitive. The registered workflows are status, diagnostics, logs, explain, rule management, policy management, installation, update, uninstall, hooks, GUI, and statusline (src/…/index.ts• L15-44). The handler map must cover the same command names, so registration and execution stay aligned (src/…/main.ts• L35-96).

The CLI keeps compatibility for the old top-level --statusline form. A bare hook command reports that it needs exactly one integration flag, while unknown commands and options go to stderr with a help hint. An uncaught command error is also reported on stderr and returns a failure exit code (src/…/main.ts• L35-42, src/…/main.ts• L122-138).

References: src/…/main.ts• L15-33 src/…/main.ts• L35-96 src/…/main.ts• L98-138 src/…/index.ts• L15-44

Help output

Help is generated from the same command definitions that drive routing. The main help lists the registered workflows, global options, environment controls, and the help <command> form. A command help page shows its usage, options, subcommands, and examples, so the displayed contract stays close to the dispatch contract (src/…/help.ts• L36-80, src/…/help.ts• L82-163).

The entry point gives command-specific help priority when a known command is present. The displayed command name must be the canonical name rather than an alias for showCommandHelp, while lookup itself still accepts aliases. Help errors use stderr while successful help uses stdout, which keeps protocol output separate from operator guidance (src/…/main.ts• L104-115, src/…/main.ts• L132-138, src/…/help.ts• L169-181).

Rule help follows the same model for nested workflows. rule exposes source management, migration, validation, transparent wrapper management, and declared command-tool management. Its flags are checked against the selected subcommand, so scope flags and action flags cannot silently apply to a different rule operation (src/…/rule.ts• L22-74, src/…/index.ts• L91-125, src/…/index.ts• L221-392).

References: src/…/help.ts• L36-80 src/…/help.ts• L82-163 src/…/help.ts• L165-181 src/…/main.ts• L104-115 src/…/rule.ts• L22-74 src/…/index.ts• L91-125 src/…/index.ts• L221-392

Startup presentation

Long-running operator commands prepare their work before showing a banner. A TTY sees the install banner and a spinner only when the pending work lasts long enough to need feedback. Non-interactive output does not receive terminal control codes, which keeps scripts and pipes usable (src/…/banner.ts• L27-65, src/…/banner.ts• L67-77).

The same pattern supports installation, update, and non-JSON diagnostics. The command finishes its work before printing the final report, and it restores the cursor even when the work fails. JSON diagnostic output skips the decorative banner so it remains suitable for another program (src/…/index.ts• L943-965, src/…/index.ts• L38-61).

Operator reports use terminal colors only when stdout is a terminal and NO_COLOR is not set. Table layout measures visible text rather than color control codes, so colored reports keep their column alignment (src/…/colors.ts• L1-22, src/…/format.ts• L23-47).

References: src/…/banner.ts• L27-77 src/…/index.ts• L943-965 src/…/index.ts• L38-61 src/…/colors.ts• L1-22 src/…/format.ts• L23-47

Hook integration workflow

Integration selection

The hook command is the protocol entry point used by supported coding-agent hosts. It requires exactly one integration flag. The flag selects an adapter for the host’s input and output shape; it is not a separate top-level command. The supported runtime integrations are Antigravity CLI, Claude Code, Codex, GitHub Copilot CLI, Cursor, Gemini CLI, Grok Build, Hermes Agent, and Kimi Code (src/…/hook.ts• L4-24, src/…/hook-integrations.ts• L14-42, src/…/catalog.ts• L25-201).

The selector accepts current short and long forms, plus selected legacy forms. No flag, more than one integration flag, an unknown option, or trailing input produces a usage error on stderr and no stdout. This matters because stdout belongs to the host hook protocol (src/…/hook-integrations.ts• L45-75, tests/…/hook-integrations.test.ts• L23-40, tests/…/commands.test.ts• L130-147).

References: src/…/hook.ts• L4-24 src/…/hook-integrations.ts• L14-75 src/…/catalog.ts• L25-201 tests/…/commands.test.ts• L130-147

Hook request flow

Each selected adapter reads one JSON request from stdin, maps the host fields to a common tool call, and passes that call to the shared runtime guard. The guard checks the request in its trusted working context, records denial audit data, and projects the result back into the host’s expected response shape. Allowed calls produce the host-specific allow response when that host needs one (src/…/common.ts• L62-100, src/…/common.ts• L170-268, src/…/common.ts• L311-320).

The workflow is fail-closed for malformed or unsafe hook input. Missing JSON, invalid JSON, oversized input, missing tool data, unusable working paths, and guard failures become a denial or a host error according to the host contract. Unsupported event types can be ignored when the host sends events that are outside the adapter’s scope. The input reader bounds raw stdin at 8 MiB so a hook cannot buffer unlimited data (src/…/common.ts• L52-76, src/…/common.ts• L79-121).

This diagram shows how a host request becomes a policy decision and then a host response.

flowchart LR
    A[Agent hook JSON] --> B[Select integration adapter]
    B --> C[Read and validate input]
    C --> D[Build common tool call]
    D --> E[Shared runtime guard]
    E --> F{Decision}
    F -->|allow| G[Host allow result]
    F -->|deny or guard failure| H[Host deny result]
    E --> I[Denial audit record]

References: src/…/common.ts• L52-121 src/…/common.ts• L170-268 src/…/common.ts• L311-320

Host protocol mapping

The adapters preserve the meaning of a decision while matching each host’s protocol. Claude Code and Kimi Code return hook-specific permission decisions. Gemini CLI and Antigravity CLI return deny records with reasons. Cursor returns an allow or deny object, while Copilot CLI returns a permission decision. Hermes Agent returns a block action and stays silent for an allowed call (src/…/hook.ts• L27-66, src/…/hook.ts• L23-59, src/…/hook.ts• L25-56, src/…/hook.ts• L18-62, src/…/hook.ts• L25-43).

The adapters also supply the host’s command-tool names and working-directory rules. This lets the shared guard analyze shell commands and other tool inputs without making the guard depend on one agent’s JSON format. Host-specific workspace containment remains part of the adapter boundary for hosts that can name a separate working directory (src/…/hook.ts• L61-77, src/…/hook.ts• L96-152, src/…/hook.ts• L59-99, src/…/hook.ts• L46-74).

References: src/…/hook.ts• L27-66 src/…/hook.ts• L23-59 src/…/hook.ts• L25-56 src/…/hook.ts• L18-62 src/…/hook.ts• L25-43 src/…/hook.ts• L96-152

Installation workflows

Target selection

install and uninstall connect CC Safety Net to an agent host. A target is one integration named by an install flag. Host metadata supplies the display name, artifact type, and flag used by the command’s help and examples (src/…/install.ts• L1-19, src/…/install.ts• L21-38). The broader target catalog supplies the host probe and ordering used by detection and execution (src/…/catalog.ts• L10-23, src/…/catalog.ts• L229-243, src/…/targets.ts• L8-27).

With an explicit target flag, the command requires exactly one target. With no target in an interactive terminal, it detects available and configured hosts and opens a multi-select screen. The picker shows unavailable targets but lets the operator move only across available targets. The selected targets run in stable catalog order. DeepSeek Harness Desktop becomes selectable only when its desktop CLI is discoverable; its web path can remain available through the package probe. In a non-interactive session, the command does not wait for a prompt and instead requires the explicit target form (src/…/index.ts• L401-419, src/…/index.ts• L466-511, src/…/index.ts• L188-199, src/…/prompt.ts• L51-60, src/…/prompt.ts• L265-277).

The picker can also hand off to update from an install session. Canceling is a successful no-change decision, while an interrupt follows the terminal signal path after the prompt restores terminal state. Confirming without a selection keeps the prompt open and signals that a selection is required (src/…/prompt.ts• L63-75, src/…/prompt.ts• L287-319, src/…/index.ts• L943-1005).

References: src/…/install.ts• L1-19 src/…/install.ts• L21-46 src/…/targets.ts• L8-35 src/…/index.ts• L401-419 src/…/index.ts• L466-511 src/…/index.ts• L188-199 src/…/prompt.ts• L51-60 src/…/prompt.ts• L265-277

Install and uninstall actions

The install runner applies the target’s host-specific connection method. A target can use a native host command, a managed plugin artifact, or a host configuration file. The runner can refresh an existing installation instead of adding a second one, and it reports unchanged, installed, updated, or removed state to the operator (src/…/index.ts• L514-559, src/…/index.ts• L640-665).

Cursor installation now uses its hook configuration path only. The command no longer offers a native Cursor marketplace plugin method, because that path can pin the plugin to an old marketplace revision that update cannot refresh (src/…/index.ts• L561-591, src/…/index.ts• L761-790).

The operation protects host state at the integration boundary. It checks existing installations, may enable a disabled plugin, clears stale package caches when needed, verifies selected runtimes, and performs cleanup for older names or artifacts. A host failure is turned into a readable error with a nonzero result; independent update targets can still finish and report their own failures (src/…/index.ts• L640-655, src/…/index.ts• L668-688, src/…/index.ts• L894-927, src/…/index.ts• L1006-1025).

DeepSeek Harness can have separate web and Desktop profiles. Install plans the profiles that are available, refuses to change the Desktop profile while the app is running, and checks that each added plugin is enabled. If the Desktop app is present but its CLI is not in a known location, the command gives manual plugin-page guidance. Uninstall removes every discoverable installed profile; when a Desktop copy remains undiscoverable, it reports the incomplete removal instead of claiming success (src/…/index.ts• L335-338, src/…/index.ts• L761-783, src/…/install.ts• L101-185).

Kimi Code has two install paths because its global hook and native plugin are different operating choices. The interactive path asks which one to use. A non-interactive install selects the global hook path, while the native plugin path prints steps for the user to complete inside Kimi Code. The printed guidance warns that Kimi’s native hook is fail-open and that an existing global hook must be removed after the plugin is active (src/…/index.ts• L698-758, src/…/index.ts• L986-1003).

References: src/…/index.ts• L335-338 src/…/index.ts• L514-559 src/…/index.ts• L561-591 src/…/index.ts• L640-665 src/…/index.ts• L668-790 src/…/index.ts• L698-758 src/…/index.ts• L894-927 src/…/index.ts• L986-1025 src/…/install.ts• L101-185

Update workflow

update finds integrations that are already present and reapplies their current installation definitions. It does not install a new host merely because that host is available. Native host checks can skip a target whose executable is no longer present, while cache-dependent targets share the required cache refresh before they run (src/…/index.ts• L793-821, src/…/index.ts• L844-863).

Updates run independent targets together after detection, then print one report per target. A missing host is a skip, not an install, and a target failure does not hide the results for other targets. The workflow also refreshes the CLI’s own ephemeral package cache so later hook runs use the current release. The command returns failure when one or more selected updates fail (src/…/index.ts• L864-927).

Cursor installations that contain only the native marketplace plugin are not converted into hook installs by update. This keeps update from silently adding a second integration path while the old plugin remains pinned (src/…/index.ts• L798-821).

When the installed CLI itself has a newer release, update also prints a package-manager nudge. It avoids that check when the command already runs from a temporary bunx or npx entry, because those launchers manage the CLI version (src/…/index.ts• L824-842).

The public command definition presents update as a no-argument workflow with help and one example. The target flags belong to install and uninstall, which keeps update behavior distinct from new host selection (src/…/install.ts• L4-46).

References: src/…/index.ts• L793-927 src/…/index.ts• L798-821 src/…/index.ts• L824-842 src/…/install.ts• L4-46

Rule management workflows

Rule configuration lifecycle

The rule command manages the policy sources and local rule configuration that the guard uses. The command supports user scope with --global and project scope by default. Initialization creates the needed configuration and can create an inactive starter rulebook with --example; it does not fetch or synchronize sources (src/…/rule.ts• L22-49, src/…/index.ts• L107-140).

Rule sources move through an explicit lifecycle: add or remove a source, update one source or all configured sources, then list the active result. rule add can select the official rulebook repository when given --only or --ref without a source. rule update re-fetches and vendors remote rulebooks. rule sync is deprecated and now only migrates lock and cache leftovers from an older install. Offline validation belongs to rule verify; there is no rule dry-run flag (src/…/index.ts• L144-193, src/…/sync-migrate.ts• L24-30). Removing a source can also delete a clean local source directory when the operator asks for --delete-source (src/…/index.ts• L166-181).

The command also manages declared command tools. A command tool is a community shell tool that the guard does not know by default. rule tool add records its name and can record the argument that carries its working directory. User and project declarations stay separate, while rule tool list shows both scopes. Built-in tools are rejected because they already have analysis support (src/…/rule.ts• L39-44, src/…/index.ts• L460-529).

The command keeps user and project policy distinct when it lists sources and command tools. It rejects project writes when the current project path resolves to the user rule configuration. This makes it possible to see which scope supplies a rulebook or tool before changing the policy that applies to a project (src/…/index.ts• L113-127, src/…/index.ts• L510-529).

References: src/…/rule.ts• L22-49 src/…/index.ts• L107-193 src/…/index.ts• L113-127 src/…/index.ts• L460-529 src/…/sync-migrate.ts• L24-30

Transparent wrapper management

A transparent wrapper is a trusted command name that the policy treats as a pass-through boundary. rule wrapper add, remove, and list manage these names in the selected policy scope. Add and remove validate the command shape and reject reserved names before writing the policy (src/…/index.ts• L407-449).

Wrapper changes affect command analysis rather than host installation. A wrapper can therefore change how a command is interpreted even when no agent integration changes. The CLI keeps wrapper operations separate from rulebook source operations so an engineer can inspect and change this trust list directly (src/…/rule.ts• L36-38, src/…/index.ts• L369-449).

References: src/…/rule.ts• L36-38 src/…/index.ts• L407-449

Rule reports

rule list gives a view of the loaded policy rather than only a source list. It reports active sources and rules, disabled rules, reason overrides, transparent wrappers, declared command tools, issues, and warnings. Rule descriptions preserve the matching shape used by their rulebook version, so version 2 rules show command paths and exact argument conditions instead of empty version 1 fields (src/…/format.ts• L87-119, src/…/format.ts• L135-147).

Change commands print their scope or source result and then summarize the active rulebooks. A successful source add also reports newly added and already configured rulebooks plus the vendored revisions. A failed change prints errors without presenting it as a successful policy update. This gives operators both the action result and the policy view that follows it (src/…/format.ts• L9-23, src/…/format.ts• L26-80, src/…/format.ts• L170-172).

References: src/…/format.ts• L9-23 src/…/format.ts• L26-80 src/…/format.ts• L87-119 src/…/format.ts• L135-147 src/…/format.ts• L149-172

Migration and verification

rule migrate moves legacy inline rule data into the current policy form for user and project scopes. When the project path resolves to the user rule configuration, it skips the project migration instead of treating the user configuration as project data. The migration preserves existing source configuration and wrappers, creates a named migrated rulebook, and can remove each legacy file only after the new files pass a content check. A failed write or sync restores the files it changed (src/…/migrate.ts• L52-81, src/…/migrate.ts• L84-159, src/…/migrate.ts• L161-177). rule sync is a separate one-time migration for older lock and cache leftovers: it uses a matching digest and valid rulebook before restoring a vendored copy, then removes the old leftovers. It refuses to prune them when the active config is missing or unreadable (src/…/sync-migrate.ts• L45-83, src/…/sync-migrate.ts• L97-155).

rule verify checks user and project rule configuration, legacy files, and shareable rulebook directories in the current repository. It evaluates rulebook fixtures without executing their commands and adds the schema link to a valid current config when it is missing. Invalid current data returns failure, while an old file can produce a warning because the runtime ignores it (src/…/verify.ts• L51-191, src/…/verify.ts• L214-281, src/…/verify.ts• L370-386). rule doc prints the rulebook authoring guide and can print an update notice separately on stderr. The guide covers the two policy scopes, source selection, command tools, wrappers, and the rulebook workflow (src/…/index.ts• L203-216, src/…/doc.ts• L1-190).

These workflows separate conversion from normal rulebook updates. An engineer can migrate or validate policy without asking the CLI to fetch remote rulebook sources (src/…/index.ts• L179-216).

References: src/…/migrate.ts• L52-177 src/…/sync-migrate.ts• L45-155 src/…/verify.ts• L51-191 src/…/verify.ts• L214-281 src/…/verify.ts• L370-386 src/…/doc.ts• L1-190 src/…/index.ts• L179-216

Status and inspection workflows

Runtime status

status gives a short view of the policy snapshot that the runtime is enforcing now. It reports the overall snapshot state, destructive-command and secret protection, effective safety level, active rule count, policy paths, worktree relaxations, project-scope weakenings, and any diagnostics that make the result incomplete or inactive (src/…/status.ts• L11-49, src/…/status.ts• L50-100).

The verdict comes from the loaded snapshot rather than from one configuration field or one host integration. Effective custom destructive-command rules can change the displayed level to custom. Claude Code plugin state is shown as a Claude-specific issue, so a disabled Claude plugin does not imply that other integrations are disabled. Status is informational and does not set a failure exit code after argument validation (src/…/status.ts• L29-47, src/…/main.ts• L58-63).

References: src/…/status.ts• L11-49 src/…/status.ts• L50-100 src/…/main.ts• L58-63

Statusline output

statusline --claude-code produces a compact string for a Claude Code shell or prompt status line. It first checks whether the Claude Code plugin is explicitly enabled. If it is disabled or its settings cannot be read, it shows the inactive marker. Otherwise it shows the effective mode, custom rule state, worktree mode, project-scope weakening, and degraded snapshot marker (src/…/statusline.ts• L21-64, src/…/statusline.ts• L66-106).

The statusline can receive upstream text through stdin. It prefixes normal text with the safety status, but it does not echo Claude Code’s JSON status input. Oversized or unreadable decoration input is discarded rather than treated as a policy denial, so the statusline remains non-blocking. Claude settings can come from the normal settings location or the CLAUDE_SETTINGS_PATH override, and the plugin must be explicitly enabled in that file. The short -cc form and the old top-level --statusline form reach the same workflow (src/…/statusline.ts• L12-27, src/…/statusline.ts• L33-64, src/…/statusline.ts• L66-106, src/…/main.ts• L127-129).

This diagram shows the distinction between a compact display check and an enforcement decision.

flowchart TD
    A[Statusline request] --> B{Claude plugin enabled?}
    B -->|no| C[Show inactive marker]
    B -->|yes| D[Load policy snapshot]
    D --> E[Show mode and health markers]
    A --> F[Read bounded upstream text]
    F --> G{Plain text?}
    G -->|yes| H[Prefix text with status]
    G -->|no or unavailable| I[Show status only]

References: src/…/statusline.ts• L12-27 src/…/statusline.ts• L33-64 src/…/statusline.ts• L66-106

Supporting inspection commands

The CLI also exposes focused inspection workflows around the same runtime. doctor gathers host detection, configuration, effective safety, self-test, activity, and update information. Its terminal report groups these facts into hook, engine, configuration, environment, safety, findings, activity, system, and update sections; JSON mode returns the same report data for another tool. It derives findings from those facts and orders errors before warnings and information, so the most urgent repair path appears first. Findings can identify missing or broken integrations, invalid or degraded configuration, unsafe protected directories, invalid audit scope, old rulebook leftovers, and overrides that weaken a selected preset (src/…/index.ts• L34-61, src/…/index.ts• L63-131, src/…/index.ts• L134-163, src/…/format.ts• L50-81, src/…/format.ts• L154-252, src/…/findings.ts• L36-178, src/…/findings.ts• L180-192).

logs reads retained hook audit entries with filters or JSON output. By default it shows recent non-allow entries, while --all, suspect detection, direct ID lookup, and agent, rule, session, or project filters provide other views. It can also preview or remove legacy root-level log files without touching nested v2 logs. explain analyzes one command and prints a human trace or a structured JSON trace. The human view shows the input, command segments, decision path, matched rule details when blocked, and the policy context used for the result. Its terminal trace uses shared formatting helpers for box styles, token display, wrapped reasons, and visible decision steps, with an ASCII-safe form for terminals that need it. These commands complement status: status answers “what is active,” while the other views explain health, history, or one decision (src/…/index.ts• L34-61, src/…/format.ts• L50-405, src/…/findings.ts• L36-192, src/…/audit-log.ts• L37-204, src/…/audit-log.ts• L207-277, src/…/run.ts• L27-58, src/…/format.ts• L12-200, src/…/format-helpers.ts• L5-263).

The explain workflow accepts a command as one positional value or rebuilds it from several trailing arguments. It can analyze with an explicit working directory and shell mode, including auto, posix, or powershell. A missing directory, invalid shell mode, missing command, or parse error fails before analysis. The --json form keeps successful traces and recognized analysis-limit errors on stdout as machine-readable JSON; the human form reports recognized limits on stderr (src/…/explain.ts• L3-33, src/…/flags.ts• L5-60, src/…/run.ts• L22-63).

The policy command is another operator path for changing policy state. The CLI dispatcher sends it to its own policy workflow rather than merging it into terminal status output or rule source management (src/…/main.ts• L52-56, src/…/index.ts• L20-28). The GUI command is a separate operator path for editing local policy. The CLI dispatcher starts it but does not merge its browser workflow into terminal output (src/…/gui.ts• L1-12, src/…/main.ts• L90-92).

References: src/…/index.ts• L34-61 src/…/index.ts• L63-163 src/…/format.ts• L50-405 src/…/findings.ts• L36-192 src/…/audit-log.ts• L37-204 src/…/audit-log.ts• L207-277 src/…/run.ts• L22-63 src/…/flags.ts• L5-60 src/…/format.ts• L12-200 src/…/format-helpers.ts• L5-263 src/…/explain.ts• L3-33 src/…/main.ts• L52-56 src/…/main.ts• L90-92 src/…/index.ts• L20-28

Change checklist

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

Important failure modes

TriggerConsequenceGuard
hook receives no integration flag, two flags, an unknown flag, or trailing inputThe process exits 1 and writes no protocol response to stdoutExact-one integration selection plus stderr help (src/…/hook-integrations.ts• L50-67, src/…/main.ts• L35-42)
Hook stdin is missing, invalid, or larger than the input limitThe host receives a denial or host-specific failure result instead of an unchecked callBounded input read and fail-closed preflight (src/…/common.ts• L52-76, src/…/common.ts• L170-213)
A hook supplies an unusable or out-of-scope working directoryThe tool call is denied because policy could be checked against the wrong directoryTrusted-root and containment checks at the adapter boundary (src/…/common.ts• L132-146, src/…/hook.ts• L59-99)
Install or update cannot reach a host executable, config path, or package cacheThe affected integration reports failure; other update targets can still report separatelyTarget probing, per-target settlement, and readable filesystem error mapping (src/…/index.ts• L844-927, src/…/index.ts• L1006-1025)
DeepSeek Harness Desktop is running during a Desktop profile changeThe command stops before changing the profileDetect the Desktop lock or process and require the app to close (src/…/install.ts• L67-81, src/…/install.ts• L101-107, src/…/install.ts• L165-168)
DeepSeek Harness has an installed Desktop profile but its CLI is not discoverableInstall may use the web profile, while uninstall reports that the Desktop copy remains and needs manual removalDetect known Desktop paths and fail rather than claim complete removal when the copy is left behind (src/…/install.ts• L64-65, src/…/install.ts• L153-185)
Interactive install confirms with no selected integrationThe prompt stays open and no target changesSelection-required confirmation in the target prompt (src/…/prompt.ts• L287-309)
A rule source or policy file is invalidRule management returns failure and status or diagnostics can show degraded policy stateRule verification, policy load errors, and snapshot diagnostics (src/…/index.ts• L61-69, src/…/verify.ts• L80-191, src/…/status.ts• L41-48)
rule sync finds lock or cache leftovers but cannot read the active configThe old files stay in place and the command asks the operator to restore the config before retryingConfig-presence check before migration and cleanup (src/…/sync-migrate.ts• L61-83)
rule migrate --cleanup cannot prove that the new rulebook contains the legacy rulesThe legacy file stays in place and the command returns failureContent check before deletion plus file snapshots for rollback (src/…/migrate.ts• L120-159, src/…/migrate.ts• L254-289)
rule migrate runs where the project policy path is the user policy pathThe project scope is skipped instead of risking a user/project scope mix-upExplicit project-policy identity check before project migration (src/…/migrate.ts• L56-71)
A declared command tool has an invalid name or duplicates a built-in toolThe tool change is rejected and no unsupported analyzer entry is writtenName validation and built-in tool refusal (src/…/index.ts• L465-480)
rule verify finds an invalid rulebook directory, missing file, or failing fixtureVerification returns failure and identifies the affected local sourceDirectory checks, schema validation, and fixture evaluation without command execution (src/…/verify.ts• L223-281)
Doctor finds an invalid audit scope or unsafe protected directoryDoctor reports a warning or error with a repair hint; allowed decisions may not be recorded when the scope is invalidFinding rules check audit values and directory posture, then sort findings by severity (src/…/findings.ts• L130-160, src/…/findings.ts• L180-192)
Claude Code settings do not explicitly enable the pluginThe Claude statusline shows inactive even when policy files are validExplicit plugin-state check with disabled as the safe default (src/…/statusline.ts• L33-64)
An audit log source cannot be read or contains malformed recordsThe log result is partial, but the command keeps its normal output and exit resultCount unreadable sources and warn on stderr without exposing their paths (src/…/audit-log.ts• L161-173)
Legacy log pruning is combined with search filters or runs without its required modeThe command rejects the request instead of mixing deletion with history lookupEnforce exclusive --prune-legacy and --dry-run combinations before file access (src/…/audit-log.ts• L100-139)
explain receives an invalid --cwd, unsupported shell mode, or no commandThe command exits before analysis and prints usage or a validation errorExistence check, fixed shell choices, positional reconstruction, and required-command validation (src/…/flags.ts• L17-59)
explain hits a recognized analysis work limitHuman mode reports the limit on stderr; JSON mode returns a machine-readable error on stdout with failure statusLimit classification in the runner and mode-specific output (src/…/run.ts• L40-63)

Key files

FileWhy to read it
src/…/main.tsShows global argument scanning, command dispatch, compatibility paths, exit behavior, and the boundary between terminal commands and hook protocols.
src/…/args.tsDefines the shared option, list, and positional parsing contract used by the command workflows.
src/…/index.tsDefines the registered command set, aliases, and help display order.
src/…/install.tsDefines the public install, uninstall, and update usage, target options, and examples.
src/…/help.tsShows how operator help is generated from command definitions and how machine-friendly output is kept separate.
src/…/hook-integrations.tsConnects hook flags to runtime integration adapters and enforces exact-one selection.
src/…/common.tsShows the common hook request path from bounded JSON input through guard evaluation and denial output.
src/…/catalog.tsDefines the shared integration vocabulary for runtime hooks, installation targets, labels, and host probes.
src/…/targets.tsDefines the install target vocabulary and stable order used by selection and execution.
src/…/index.tsCoordinates target detection, interactive installation, hook-only Cursor installation, uninstall, update, host-specific actions, cache refresh, and result reporting.
src/…/install.tsExplains DeepSeek Harness web and Desktop profile discovery, safe profile changes, enablement checks, and incomplete-removal reporting.
src/…/prompt.tsExplains the interactive target picker, selection rules, terminal lifecycle, and separate Kimi Code method choice.
src/…/rule.tsDefines the rule command’s public subcommands, flags, and examples.
src/…/index.tsCoordinates rule initialization, source add/remove/update, scope selection, wrappers, command tools, migration, documentation, and verification.
src/…/format.tsDefines the operator reports for rule changes, source additions, command tools, and the full loaded-policy list.
src/…/migrate.tsShows legacy rule conversion for user and project scopes, project-scope detection, and cleanup safeguards.
src/…/sync-migrate.tsShows the deprecated offline migration from older rule locks and caches to live vendored files.
src/…/verify.tsShows current and legacy config checks, local rulebook checks, fixture validation, and schema repair.
src/…/doc.tsContains the rulebook authoring guide exposed through rule doc.
src/…/status.tsDefines the concise runtime health view and its snapshot-based verdict.
src/…/statusline.tsDefines the compact Claude Code display and its disabled, mode, weakened-project, degraded, and piped-input behavior.
src/…/findings.tsDefines the health findings, repair hints, severity order, and posture checks surfaced by doctor.
src/…/index.tsShows how the broader diagnostic report assembles host, policy, environment, activity, and update views.
src/…/format.tsDefines the terminal sections, tables, colors, and summary used to present the doctor report.
src/…/colors.tsDefines when terminal color is allowed and how colored command values are rendered.
src/…/explain.tsDefines the public explain command name, options, usage, and examples.
src/…/flags.tsDefines explain validation, shell selection, working-directory checks, and command reconstruction.
src/…/run.tsConnects validated explain input to analysis and keeps human and JSON error paths distinct.
src/…/format.tsDefines the human trace view and the structured JSON form for one command decision.
src/…/format-helpers.tsDefines the shared terminal box, token, reason, and trace-step formatting used by the human explain view.
src/…/audit-log.tsShows how retained hook decisions are filtered, rendered, looked up, and optionally returned as JSON, plus the isolated legacy-log cleanup path.