Browser GUI
The Browser GUI is a local operator surface for viewing safety activity, checking protection state, editing user and project policy, reviewing custom rules, managing agent hooks, and tailoring the messages shown when built-in rules block work. The CLI starts a short-lived loopback web server and opens a browser page that uses the same local policy and audit data as the other operator surfaces. See Operator interfaces for the wider CLI and browser model.
Local operator surface
The GUI joins local safety data with a browser view without turning safety-net into a remote service. The server listens on 127.0.0.1, serves one self-contained page, and keeps local reads and writes in the CLI process.
The GUI complements the other operator paths:
- Diagnostics and audit interfaces cover command-line health and audit views.
- CLI command workflows cover the command-line workflows that start and operate the local tool.
- The Browser GUI gives those same local facts an interactive visual surface.
The page uses a small browser facade. This is the browser-safe boundary for shared display helpers such as command grouping and relative time. It keeps the page separate from Node-only engine services while the server remains responsible for local data access.
References: src/…/index.ts• L143-207 src/…/browser-facade.ts• L1-2 src/…/facade.ts• L1-9
Server boundary
The GUI server is the local boundary between the browser and safety-net data. It exposes page data through JSON requests and keeps policy writes, activity reads, rulebook reads, health checks, preference writes, and hook actions in the local process.
The server groups its browser contract by operator need:
| Area | Operator result |
|---|---|
| Policy | Read, preview, explain, save, reset, or repair user policy; review and apply project policy |
| Activity | Read a retention-limited audit window |
| Rulebooks | View enforced custom rules and diagnostics |
| Integrations | View hook status and install or remove a hook |
| Health | View update status |
| Preferences | Save language and theme choices for the local GUI |
| Support | Show repository star state and blocked totals |
The page receives policy metadata that it needs to explain protection choices. It does not need to know how the safety engine derives those choices. JSON writes have a fixed size limit, so an oversized local request is rejected before it can consume unbounded memory.
References: src/…/index.ts• L209-517 src/…/index.ts• L519-540 src/…/index.ts• L616-625 src/…/index.ts• L695-717
Request protection
Each GUI session has a random token. The server places that token in the page and requires it on later requests. The browser includes the token in the request URL and in the x-cc-safety-net-token header, so reads and writes use the same session proof.
This protection limits use of the local control surface to a page that received the current session URL. It does not change the server into a network service because the listener still binds only to the local machine.
References: src/…/index.ts• L184-205 src/…/index.ts• L231-245 src/…/index.ts• L689-693 src/…/page.ts• L4-10 src/…/ui.ts• L22-35
GUI session lifecycle
The GUI session begins with a CLI command, creates a local server, and ends when the process receives a shutdown signal. The browser is a client of that session, so closing the browser page does not stop the server.
The lifecycle moves through these stages:
flowchart LR
A[cc-safety-net gui] --> B[Create session token]
B --> C[Listen on local loopback port]
C --> D[Print page URL]
D --> E{Open browser?}
E -->|Yes| F[Open tokenized page]
E -->|No| G[Operator opens URL]
F --> H[Browser loads page and requests local data]
G --> H
H --> I[Operator reads or changes safety state]
I --> J[Process receives SIGINT or SIGTERM]
J --> K[Close server]
The normal command keeps the process alive after the browser opens. --no-open prints the URL without launching a browser. A failed automatic browser launch does not prevent GUI use because the CLI prints the URL for manual opening.
References: src/…/index.ts• L143-177 src/…/index.ts• L180-212 src/…/index.ts• L743-775
Page initialization
The page starts by reading session data, applying the saved language and color preference, and selecting the Overview view. It loads integrations, update health, policy, overview activity, and the full activity feed during startup. Custom rules load when their view is first opened.
The URL hash selects one of six views: Overview, Activity, Protections, Custom rules, Agents, or Settings. A hash change changes the visible view without a full page load. Activity and policy filters also use the hash, so a focused view can be shared or revisited without losing its selection.
The frontend uses shared state and one view module for each major operator task. Policy state carries the loaded policy, unsaved status, and project-draft status between views. Policy loads before activity and overview so retention limits and rule links use current policy data.
Refresh controls recover after a failed reload so a temporary local error does not leave a view locked in a busy state. The page keeps unsaved user-policy edits in the browser session and warns before navigation away from them. It restores a draft only when its stored shape and safety level are recognized. An invalid stored draft is discarded instead of changing the loaded policy.
References: src/…/gui-data.ts• L1-6 src/…/head.ts• L1-6 src/…/main.ts• L23-95 src/…/preferences.ts• L1-49 src/…/ui.ts• L140-145 src/…/policy.ts• L1059-1117
Policy editing lifecycle
The Protections view separates a saved policy from a draft policy. Controls update the draft and ask the server for a preview. The preview lets the operator see the likely rule and capability state before saving. A command tester can also check one command against the current draft and link the result to the matching rule or rule composer without running the command.
Built-in rules can also have a custom block message. The operator edits the reason and the next-step intent, sees a preview of the message, and saves it with the user policy. The message changes what the agent is told after a block; it does not remove the block. The editor keeps the built-in reason available as a starting point and rejects a message that exceeds the allowed length.
The write path is deliberately explicit:
- Load the saved policy and its diagnostics.
- Change a draft control, path list, or block message.
- Preview the draft and show any validation error.
- Save the draft, or discard it and reload the saved policy.
- Repair or reset only after confirmation when the saved file needs recovery or replacement.
Project policy uses a second review path. The operator selects a project directory, marks the fields that belong to that project, reviews a difference from the existing project policy, and then applies the result. The project proposal excludes audit settings and custom block messages because those settings remain user-scoped. A directory revision prevents a stale draft from being applied to a different project.
The GUI does not treat a user-policy file as a project policy. If the draft directory resolves to the user policy, the page shows an empty project projection with a diagnostic and asks the operator to choose a project directory or launch the GUI from one. Diff and apply reject that draft until its directory changes.
The project draft keeps a baseline policy separate from fields marked for the project. Its projection shows inherited values while the server writes only reviewed project fields. This keeps a project policy from silently copying unrelated user settings.
Policy edits and audit retention are separate saves. This prevents a retention change in Settings from silently committing unrelated Protections edits. Lowering retention also warns that old audit records cannot be recovered.
References: src/…/index.ts• L266-409 src/…/index.ts• L546-632 src/…/policy.ts• L96-170 src/…/policy.ts• L343-445 src/…/policy.ts• L1288-1388 src/…/policy-summary.ts• L76-167 src/…/project-draft.ts• L4-45 src/…/rule-messages.ts• L15-57 src/…/settings.ts• L46-104
Directory selection
Directory selection supports project-policy drafting and the Custom rules view. The browser sends no path to the picker. The local process opens the native folder dialog and returns either an existing directory, a cancel result, or an error.
The availability rule reflects the user’s desktop context:
| Platform | Selection source | Availability condition |
|---|---|---|
| macOS | Native folder dialog | Operating system support |
| Windows | Native folder dialog | Operating system support |
| Linux | zenity or kdialog | An executable dialog program and a display session |
| Other systems | None | Picker is unavailable |
The Custom rules view starts with the directory where the GUI was launched. Project-policy drafting uses the same starting directory and keeps a per-session revision when the operator picks another folder. If the starting directory resolves to the user policy, the project view stays open but does not read or write that file as a project proposal. It shows the diagnostic and keeps the Change action available so the operator can select a real project directory.
When a working picker exists, the path is selected through the dialog instead of typed by hand. If the dialog fails after availability detection, the page unlocks the field so the operator can enter the path directly. A returned path must point to an existing directory. Cancel remains separate from failure.
References: src/…/choose-directory.ts• L5-97 src/…/index.ts• L348-385 src/…/index.ts• L553-577 src/…/policy.ts• L1225-1237 src/…/rules.ts• L31-45 src/…/rules.ts• L129-148
Activity presentation
The Activity view turns local audit records into an operator view of recent safety decisions. It shows allowed, blocked, evaluation-error, and likely false-positive entries in newest-first order. It adds rule and agent context when recorded and provides counts for blocked commands, analyzed commands, rules, agents, and evaluation errors.
The view supports several ways to narrow the feed:
- Decision: all, blocked, allowed, errors, or likely false positives.
- Agent: one detected agent or all agents.
- Text: a rule ID or command search.
- Command: one command signature reached from the Overview or another activity entry.
- Time: a window limited by audit retention.
The Overview presents the same window as summary tiles, daily activity bars, recent blocks, and the most-triggered rules. It turns disabled hooks, likely false positives, guard errors, and available updates into links under Needs attention. The server reads whole local calendar days within the requested retention window and prunes expired records before reading them.
The feed has a 500-entry display cap for each decision class. It reports when the list is truncated or an audit source cannot be read. This keeps a large denial burst from hiding all allowed activity while preserving totals for the full window.
The Overview can also show blocked totals for the retention window and offer a GitHub star action. The action uses the local GitHub CLI when available. If it cannot complete, the page gives the operator a normal repository link instead of claiming success.
References: src/…/activity.ts• L8-91 src/…/index.ts• L418-428 src/…/activity.ts• L36-232 src/…/overview.ts• L12-171 src/…/health.ts• L13-48 src/…/i18n.ts• L7-36
Activity actions
Activity is also a navigation surface into policy work. A rule or command from the Overview can open matching Activity entries. A blocked entry can open a rule composer, and a likely false positive can open a public GitHub form after local paths are scrubbed. A built-in rule link can open its Protections row and its custom message editor.
The page marks evaluation failures separately from policy denials. This distinction helps an operator investigate parser or guard errors without treating them as proof that a rule matched. The command copy action keeps the raw entry available for local diagnosis. If a report is too large for the GitHub form, the page moves omitted report fields to the clipboard when possible instead of silently claiming that the full report was submitted.
References: src/…/activity.ts• L72-77 src/…/activity.ts• L234-279 src/…/overview.ts• L103-150 src/…/report.ts• L1-49
Policy and rule views
The Protections view presents the safety posture as presets, capability overrides, protection groups, path lists, and per-rule block messages. It shows the effective state of built-in protections while preserving the difference between inherited settings, explicit overrides, environment-raised protection, and protections that cannot be disabled.
The view includes a command tester. It checks a command against the current draft, including unsaved changes and custom rules, but it does not run the command. A result links to the matching built-in protection or custom rule so the operator can move from a decision to the setting that caused it.
The same view can enter project scope. In that mode, the operator sees which fields come from the user policy and which fields are set for the selected project. Only marked project fields enter the proposal, so unrelated user settings stay outside the project file. Custom block messages remain in the user policy rather than entering this project proposal. A launch directory that is itself the user-policy location is not accepted as that project scope.
The Custom rules view is read-only for loaded rulebooks. It shows the rules enforced after overrides and provides a prompt composer for handing rule authoring to the coding agent. The composer supports project and all-project scopes and requires the project directory for project-scoped work. Rule requests include the current scope, selected project path when needed, existing rulebook names, and the operator’s request. This gives the coding agent the context needed to create a valid rule without making the browser author the rule itself.
Together, these views let an operator answer four different questions:
- Protections: What safety behavior is active, and what will a draft change do?
- Block messages: What should an agent be told when a built-in rule blocks a command?
- Project policy: Which settings apply only to this project, and what will be written?
- Rulebooks: Which custom rules are currently enforced, and where are they applied?
References: src/…/policy.ts• L343-445 src/…/policy.ts• L521-687 src/…/policy.ts• L739-785 src/…/rules.ts• L37-118 src/…/rules.ts• L120-179 src/…/policy-summary.ts• L7-74 src/…/project-draft.ts• L62-147 src/…/page.html• L88-295
Integration and maintenance views
The Agents view shows detected coding agents, hook status, agent version, and local runtime details. It can install or uninstall a hook for a detected target. The server serializes integration actions so concurrent browser clicks do not run installation work at the same time.
The Overview health strip combines integration status with a separate update check. It shows active hooks, detected but inactive hooks, likely false positives, guard errors, and available updates without making the Agents view responsible for the update request.
Settings shows policy and audit-log paths, audit retention, theme preference, language preference, package version, platform details, and a policy reset action. Theme and language choices stay in local GUI preferences. Audit retention changes the policy and refreshes the activity views after a successful save. These views connect safety behavior to the local files, agent setup, and retained activity that influence it.
References: src/…/index.ts• L461-521 src/…/index.ts• L778-884 src/…/integrations.ts• L5-110 src/…/overview.ts• L17-90 src/…/settings.ts• L26-154 src/…/preferences.ts• L13-49 src/…/health.ts• L5-48
Localization and presentation
The frontend supports English, Japanese, and Simplified Chinese. It chooses a saved language first, then a matching browser language, and otherwise uses English. Shared date, number, and relative-time formatting uses the selected locale.
The locale resources also define the user-facing vocabulary for all six views. They cover navigation, protection state, policy and project-draft warnings, per-rule block-message editing, rulebook actions, activity filters and report handoff, agent-hook status, settings changes, and failure messages. Each locale implements the same message contract, so the frontend can change language without changing its view or server behavior.
The page supports automatic, light, and dark themes. The layout changes for smaller screens by moving navigation to a compact bar, hiding secondary feed columns, and stacking controls. Focus rings, alerts, dialogs, reduced visual motion, and status colors make operator state visible without depending only on color. Block-message editors show length state and a preview while keeping the built-in and custom parts distinct.
References: src/…/preferences.ts• L1-49 src/…/i18n.ts• L1-36 src/…/en.ts• L245-274 src/…/ja.ts• L245-274 src/…/zh-CN.ts• L235-264 src/…/custom.css• L1641-1787 src/…/custom.css• L2333-2496
Static page assets
The served page is assembled as one document from the HTML shell, browser scripts, stylesheet, logo, and favicon. src/…/assets.ts reads those resources, builds the frontend for a browser target, and inlines the results so the published CLI can serve the GUI without reading source files or running a browser build at runtime.
The HTML defines the page structure and accessibility labels. The frontend scripts supply view state and behavior. Shared helpers supply requests, notifications, escaping, copy actions, preferences, and state events. The stylesheet supplies the responsive layout, themes, status colors, controls, dialogs, and operator feedback styles. The logo supplies the product wordmark, and the favicon supplies browser-tab identity.
This design makes the browser page a versioned part of CLI output. A change to a frontend source asset must reach the bundled document before users can see it. The page renderer injects session data as escaped JSON so the browser can authenticate later requests without treating the token as markup.
References: src/…/assets.ts• L3-61 src/…/page.ts• L1-11 src/…/page.html• L1-15 src/…/gui-data.ts• L1-6 src/…/ui.ts• L19-95 src/…/custom.css• L148-360
Change checklist
When these files or sections are changed, remember to consider these:
- Keep API response shapes in src/…/index.ts aligned with src/…/types.ts and the view modules. A renamed policy, rule, project, preference, or activity field can fail as an empty view rather than a clear type error in the browser.
- Keep the shared policy and integration events aligned with the Overview, Activity, Agents, and Settings views. A view can otherwise show an old status after another view changes it.
- Keep activity and policy hash parameters aligned with links that focus rules, commands, custom messages, suspect entries, and filtered views.
- Keep the project proposal, marked-field list, inherited display, project diff, and server-side validation aligned across src/…/project-draft.ts, src/…/policy.ts, and src/…/index.ts. Project proposals must continue to exclude user-only audit and block-message settings.
- Keep stable rule identifiers and activity jump links aligned between policy metadata, rule rendering, rulebooks, and audit entries.
- Keep policy draft, preview, save, repair, project diff, project apply, custom-message limits, and retention behavior aligned so a Settings write cannot commit or restore an unrelated draft.
- Keep the built-in message reason, selected intent, rendered preview, stored
RuleMessagesshape, and server-side policy normalization aligned. A message can otherwise look valid in the editor but change or disappear when saved. - Keep directory-picker availability, executable checks, cancel results, failure results, and the Protections and Custom rules path fields aligned across platforms.
- Keep activity totals, the 500-entry cap, decision filters, false-positive path scrubbing, report URL length handling, clipboard fallback, and truncation text consistent so the feed does not promise entries or report fields that the response does not include.
- Keep refresh error handling aligned across Activity, Custom rules, and Agents so a failed reload restores the control and does not leave stale state presented as a fresh result.
- Keep JSON body-size errors and their HTTP status visible to the browser’s shared request error handling.
- Keep preference parsing, saved preference shape, locale selection, theme application, and the language controls aligned across src/…/index.ts, src/…/preferences.ts, src/…/head.ts, and src/…/main.ts.
- Keep all message keys in src/…/en.ts aligned with the Japanese and Simplified Chinese locale objects. A missing key or changed interpolation argument can break localized labels or show the wrong operator message while the English view still works.
- Keep
src/gui/frontendasset references and the GUI asset bundle step aligned. A source page can appear correct while the published CLI still serves an older embedded page. - Keep integration status labels and install action results aligned with target and hook states. The Overview health strip must use integration rows for hook state and the separate health result for update state.
- Keep the session token injection point, URL query parameter, and browser request header aligned. Changing one without the others makes the whole page unauthorized.
- Keep Overview star context, blocked-total wording, star action result, and fallback repository link aligned so external failures do not appear as successful actions.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| The page sends a missing or stale session token | The server returns 403 Forbidden and does not serve data or accept writes | The server creates a fresh token and the page sends it on every request |
| A write request exceeds the JSON body limit | The server returns 413 and does not process the request | The server stops reading the request after the fixed size cap and the page reports the request error |
| Saved GUI preferences contain unknown language or theme values | The page falls back to supported preferences and browser language rules | Preference parsing accepts only known values and ignores malformed fields |
| The saved policy is empty, malformed, or invalid | The page shows the original data and blocks normal saving until repair | Policy load returns diagnostics; Repair preserves valid fields when possible and restores defaults when parsing fails |
| A stored browser draft has an unknown policy shape or safety level | The draft is discarded and the saved policy remains the source for the page | Draft restore checks the stored structure and accepts only known safety-level entries |
| A custom block message is empty or longer than the supported limit | The message is removed or saving is blocked, while the rule itself remains available | The editor trims empty values, counts message length, and the server normalizes policy input |
| A project draft includes a custom block message or audit setting | Project review or apply rejects the user-scoped field instead of copying it into a project file | Project proposal collection omits these fields and server validation rejects them if they are supplied |
| The GUI starts in a directory whose project-policy path is the user policy | The project view shows no project projection, and diff or apply returns the user-policy diagnostic instead of changing the user file | The server checks the resolved draft directory before reading or writing the project policy and keeps directory selection available |
| A project draft targets a changed directory revision | Review or apply is rejected instead of writing to the wrong project | The server compares the proposal revision with the current session revision and the page reloads the draft |
| A requested activity window exceeds audit retention | The Activity request fails instead of showing a misleading history window | The server limits accepted days to the resolved retention period and the page offers only retained windows |
| Audit sources cannot be read or the feed exceeds 500 entries | The visible activity list is incomplete or bounded | The response reports unreadable sources and truncation while keeping full-window counts |
| A false-positive report exceeds the GitHub URL limit | Some report fields are not prefilled in GitHub | The report builder drops the largest fields first and the page offers them through the clipboard when possible |
| No native directory picker can open, or the dialog fails | A project rule or policy path cannot be selected through the dialog | The page falls back to manual path entry and the picker reports cancel separately from failure |
| A refresh request fails | The view reports the load problem and its refresh control becomes usable again | Refresh actions restore the button in their completion path |
| The automatic browser opener is unavailable | The server still runs but no page opens automatically | The CLI prints the URL and asks the operator to open it manually |
| A hook install or uninstall action fails | The integration row remains available and shows the command output or error | The action result is captured and the row is not marked successful unless the command succeeds |
| The GitHub CLI or network is unavailable during the star action | The page shows a normal GitHub link instead of claiming that the repository was starred | Star status and the one-click action use bounded external calls and provide a fallback URL |
Key files
| File | Why to read it |
|---|---|
| src/…/index.ts | Defines the local server, session lifecycle, browser API, project-policy flow, activity endpoint, directory endpoints, preferences, and integration actions. |
| src/…/main.ts | Defines startup order, localization, hash-based view selection, and links between frontend view modules. |
| src/…/policy.ts | Defines the Protections view, command tester, user draft, project draft, custom block-message editor, review, repair, and save flow. |
| src/…/activity.ts | Defines the activity feed, filters, navigation actions, retention limits, and false-positive handoff. |
| src/…/overview.ts | Defines the safety summary, attention links, activity summary, update presentation, and star action. |
| src/…/rules.ts | Defines read-only rulebook presentation and the prompt handoff for new custom rules. |
| src/…/integrations.ts | Defines agent grouping and hook install or uninstall actions. |
| src/…/settings.ts | Defines theme, language-adjacent preference use, audit retention, path display, and policy reset behavior. |
| src/…/ui.ts | Defines browser requests, session-token use, shared state events, messages, confirmation, and copy behavior. |
| src/…/preferences.ts | Defines supported languages and themes plus preference validation and locale selection. |
| src/…/en.ts | Defines the shared message contract and English wording for all GUI views and operator states. |
| src/…/ja.ts | Provides the Japanese implementation of the shared frontend message contract. |
| src/…/zh-CN.ts | Provides the Simplified Chinese implementation of the shared frontend message contract. |
| src/…/page.html | Shows the user-facing views and the main questions the GUI helps an operator answer. |
| src/…/types.ts | Defines the shared shapes that connect server responses to frontend views. |
| src/…/project-draft.ts | Defines the boundary between user policy fields and project policy fields. |
| src/…/policy-summary.ts | Defines policy labels, effective-state notes, and the change summary shown before save. |
| src/…/rule-messages.ts | Defines block-message intents, message limits, and message previews. |
| src/…/report.ts | Defines local-path scrubbing and the size-bounded false-positive report handoff. |
| src/…/activity.ts | Defines the activity window, aggregate counts, entry cap, and unreadable-source reporting. |
| src/…/choose-directory.ts | Defines the cross-platform directory-selection contract used by project policy and rule authoring. |
| src/…/page.ts | Injects session data into the served document. |
| src/…/assets.ts | Describes how frontend resources become one served page. |
| src/…/browser-facade.ts | Defines the small browser-safe boundary for shared display helpers. |
| src/…/custom.css | Shows visual states, responsive layout, themes, block-message editing, and operator feedback styles used by the page. |