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 / build-and-package-orchestration

Build and package orchestration

Build and package orchestration turns CC Safety Net source into runtime artifacts, an embedded GUI, host plug-ins, and an installable package. It keeps public entry points, host metadata, version data, configuration assets, and file modes aligned. This page is part of Delivery engineering and relates to Release and verification workflows.

Build pipeline

The build pipeline creates the artifacts that supported hosts can run and checks that the result has the expected shape. The package build command removes the old dist directory before it starts. Runtime bundle builds resolve the repository source alias explicitly so they do not depend on resolver behavior from test processes.

Build coordination

The scripts/build.ts entry point coordinates the build stages in a fixed order. It builds the shared Node runtime, builds the Amp and OpenClaw host plug-ins, creates public type declarations, applies executable permissions, and runs artifact checks.

The pipeline stops at the first failed stage. This prevents a partial dist directory from being mistaken for a usable package. The final checks also print the size of the main runtime and integration artifacts so large or missing outputs are visible during a build.

References: scripts/build.ts• L10-72 package.json• L60-68

Repository plugin tree

The repository plugin tree is a separate package shape for hosts that discover plug-ins from a directory. It combines grouped hook bundles with the manifests, hook definitions, skills, logos, license, and README data needed by supported repository-based hosts.

The tree keeps imports between hook groups as links to shared bundle files instead of duplicating every module. It also adds host-specific logo references and rewrites README links for the versioned release. It checks file size, file count, lockfiles beside a package manifest, and unreadable generated JavaScript. These checks protect host discovery and review of the generated package.

References: scripts/build-plugin-tree.ts• L136-173 scripts/build-plugin-tree.ts• L175-225

Schema asset

The configuration schema is a hand-maintained JSON Schema asset for tools that edit CC Safety Net configuration. A focused check keeps its fields, limits, patterns, and allowed decision intents aligned with the runtime configuration rules. The runtime build does not generate this asset, so schema changes are part of the configuration contract rather than a build by-product.

References: assets/cc-safety-net.schema.json• L1-111 tests/…/schema-asset.test.ts• L13-43

Runtime artifact set

The output set serves several consumers without requiring them to know the source tree. The package manifest maps the library API and command line tool to stable paths. Host-specific directories give Amp, OpenClaw, and Pi the files they expect. The DeepSeek harness output includes both its bundled entry and the host patch that points the harness at that entry.

Node runtime

The Node build supports importable ESM library entry points, the cc-safety-net and ccsn commands, the Pi extension, and the DeepSeek harness. The package exposes the root library entry, the explicit ./api entry, and the ./opencode/v2 type entry. Shared chunks reduce repeated code while bundled outputs keep runtime consumers independent from the repository layout.

The public type output is limited to supported declarations for the root API, the explicit API entry point, and the OpenCode entry point. Internal declarations are removed so downstream TypeScript users do not receive accidental entry points. The published command uses a small CommonJS launcher beside a self-contained hook bundle. The full CLI remains a separate ESM entry.

References: scripts/build-runtime.ts• L32-115 scripts/build.ts• L38-51 scripts/build-output.ts• L1-11 package.json• L35-58

Host plug-ins

The Amp and OpenClaw builds provide plug-ins that can run inside their host systems. They inline the runtime dependencies needed by those hosts and keep host metadata beside the code when the host requires discovery before execution.

The OpenClaw directory includes an activation manifest and a package manifest that point to the same entry file. The shared artifact identity matters because installers and host tools use the marker and version to recognize a managed installation.

References: scripts/build-runtime.ts• L117-163 src/…/artifact.ts• L7-18 src/…/artifact.ts• L10-79

DeepSeek harness bundle

The DeepSeek harness bundle provides a packaged host entry that registers the CC Safety Net guard with the host tool set. Its companion patch tells the harness to load the generated bundle entry, so package consumers do not need source paths or a second installation step.

References: scripts/build-runtime.ts• L24-30 scripts/build-runtime.ts• L32-58 src/…/index.ts• L1-7

GUI assets

The GUI asset build prepares browser content that the published CLI can serve without reading source files. It turns the page and its supporting resources into content that travels with the runtime bundle.

GUI document

The GUI asset build creates one self-contained HTML document. It combines the page, browser script, style sheet, icon, and logo so the packaged CLI can serve the interface without a source checkout or a second browser build.

The browser script is built for a browser target before its contents are embedded. The runtime bundle then freezes the completed document as a value. This removes file-system and build-tool work from the published command.

References: src/…/assets.ts• L3-54 scripts/gui-assets.ts• L3-17 scripts/build-runtime.ts• L12-53

Skill template

The runtime build also freezes the host skill template into the bundle. This lets the published package provide the template even though the source document beside the repository is not part of the shipped package.

References: scripts/gui-assets.ts• L19-23 scripts/build-runtime.ts• L12-53

Integration host scripts

Integration host scripts provide small host models for package checks and end-to-end checks. They load the built plug-in as a real host would, expose the host callbacks that the plug-in needs, send tool requests, and return the plug-in result as JSON.

The scripts cover Pi, Amp, OpenCode, OpenClaw, and DeepSeek package journeys. Their purpose is to check the boundary between a packaged artifact and its host contract. They are not another production runtime and do not change plug-in behavior.

Host simulations

Each host model captures the result in the form that its host uses. A safe command must pass through. A protected command must produce the host-specific block or reject result. Registration checks also confirm that the plug-in exposes the expected hook or command before a tool call is sent.

The package verifier runs these scripts after installation from the tarball. It also checks that packaged entry bundles do not expose the internal rule synchronization operation. This catches failures that a source-level test can miss, such as a wrong entry path, missing bundled dependency, or host API mismatch.

References: scripts/integration-host-scripts.ts• L1-180 scripts/verify-package.ts• L120-182 scripts/verify-package.ts• L148-167 scripts/verify-package.ts• L450-599

Output contract

The output contract defines what must exist in dist and how those files may relate to one another. It protects package consumers from silent changes to entry paths, shared chunks, executable behavior, host metadata, or the DeepSeek harness patch.

Build artifact checks

The build verifier accepts known entry artifacts and hashed shared chunks only. It checks that every required entry exists, every referenced shared chunk exists, and no generated chunk is unused. It also checks the CLI shebang and executable mode.

For managed Amp and OpenClaw artifacts, the verifier checks the ownership marker, current version, and absence of unresolved non-built-in imports. These checks make a host artifact fail early instead of failing later in a host process with missing files.

References: scripts/verify-build.ts• L14-29 scripts/verify-build.ts• L58-149 scripts/build-output.ts• L1-11

Published paths

The package manifest is the public map from consumer behavior to built files. The root import uses dist/index.js and dist/index.d.ts. The ./api import uses dist/api.js and dist/api.d.ts. The ./opencode/v2 import uses dist/index.js with dist/opencode-v2.d.ts. Both command names use dist/…/cc-safety-net.js. The Pi extension uses dist/…/index.js.

The DeepSeek harness uses dist/…/index.js and its packaged patch under dist/…/cordis.patch.yml. The manifest publishes dist. Package staging adds the README and project license. The Amp and OpenClaw directories inside dist retain their host-specific layouts, so a generated path change requires a coordinated change to the package manifest or host metadata.

The package also declares optional peer contracts for the two OpenCode plug-in generations. These declarations let consumers select the matching host integration without forcing either host package into every install.

References: package.json• L35-58 package.json• L89-115 package.json• L129-137 scripts/build-runtime.ts• L24-30 scripts/verify-build.ts• L58-79 src/…/artifact.ts• L13-20

Package preparation

Package preparation creates the exact tarball that users install and tests it in an isolated install. It separates release inputs from the working tree, removes repository-only lifecycle behavior, and preserves the package identity needed by release tooling.

Release metadata

Release preparation updates the version in the npm manifest and the four repository plug-in manifests together. The process changes only the version text. This preserves the formatting that repository checks expect.

The release state check accepts only a stable semantic version and requires all five manifest versions to agree. This keeps the version stamped into built artifacts consistent with the version shown to each supported installer. A release process must prepare these manifests before it builds the final package.

References: scripts/prepare-release-files.ts• L7-29 scripts/release-state.ts• L1-29 scripts/build-runtime.ts• L41-50 package.json• L1-3

Tarball staging

Tarball staging copies the README, project license, and dist into a temporary package root. It writes a release manifest without the repository prepare script and can add a full commit identifier when release tracking needs it. The verifier also checks that the packed manifest contains exactly the requested commit identifier.

The staged root is packed with lifecycle scripts disabled. The verifier compares the tarball file list with the expected contract, checks that its size stays below 700,000 bytes, and checks its file modes. It installs the tarball in a temporary project and exercises the CLI, public library entry points, and packaged Pi, OpenCode, Amp, OpenClaw, and DeepSeek journeys. It also confirms that internal rule synchronization operations are not exposed by packaged bundles.

The installed checks cover safe and blocked command paths. They also confirm that the CLI fails closed on oversized live rulebooks and source configurations without exposing their contents or creating lock, cache, or network state. The isolated consumer fixtures include the OpenCode v2 package only on platforms where its full peer install is practical. The platform filter uses the package name rather than its pinned version, so a version bump does not silently restore the slow Windows install.

References: scripts/verify-package.ts• L84-182 scripts/verify-package.ts• L183-447 scripts/verify-package.ts• L450-599 scripts/verify-package.ts• L719-761

Third-party license coverage

The package has no third-party runtime dependency or license-generation stage. Its dependency declarations support development and optional host integration, while the package contains the built dist tree plus the project README and license. The verifier checks that the installed package does not declare ordinary runtime dependencies. If a future build starts bundling a third-party runtime package, the package contract must add a license notice and verify that the notice reaches the tarball.

References: package.json• L39-41 package.json• L89-115 scripts/verify-package.ts• L26-32 scripts/verify-package.ts• L331-355 scripts/verify-package.ts• L719-758

Change checklist

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

  • When a runtime entry path changes, update the package manifest, host metadata, artifact allow-list, output-path mapping, package verification paths, and DeepSeek harness patch together.
  • When public declaration entry points change, update the declaration allow-list, emitted-file cleanup, root-level declaration moves, package exports, and type checks together.
  • When shared-bundle layout or dependency loading changes, confirm that repository-checkout channels still work without node_modules and that no non-built-in import escapes into a self-contained host artifact.
  • When the Bun version or source alias rules change, confirm that the Node, Amp, OpenClaw, and DeepSeek bundle paths resolve source imports consistently in standalone and test-driven builds.
  • When GUI source names or served references change, confirm that the embedded document still contains the browser script and all visual assets.
  • When the skill template source or its package use changes, confirm that the published bundle still contains the template without the source document.
  • When an integration host contract changes, update its host simulation and the packaged journey that checks the contract.
  • When the DeepSeek harness entry or patch format changes, keep the generated patch target and the verifier's packaged path in agreement.
  • When package safety limits or validation commands change, keep the installed-package checks on live rulebooks and source configurations aligned. Confirm that failure output does not expose rule content or create lock, cache, or network state.
  • When OpenCode peer versions change, keep the platform-specific consumer selection based on the package identity rather than one version string. Confirm that the v2 type check still runs on supported platforms and remains excluded from the slow Windows install path.
  • When the tarball size limit changes, keep the package growth budget aligned with the files staged into the tarball and the verifier's 700,000-byte size check.
  • When a third-party runtime dependency is introduced, add its license notice to the package staging and verification contract. Do not treat a development-only dependency as a shipped runtime dependency.
  • When the configuration contract changes, update the hand-maintained schema asset and keep its fields, limits, patterns, and intent values aligned with the runtime validator.
  • When the repository plugin tree changes, keep hook bundle boundaries, copied host metadata, logo paths, README release links, and plugin-tree limits aligned with the host discovery contract.
  • When release version flow changes, keep the npm, Claude Code, Codex, Cursor, Kimi, artifact header, and host manifest versions in one update path.

Important failure modes

TriggerConsequenceGuard
A required entry file is missing or a shared chunk is orphanedThe package can install with an incomplete or unreachable runtimeverifyBuildArtifacts checks required files and chunk reachability
A host artifact imports a package that the host does not installAmp or OpenClaw fails when it loads the plug-inBundling plus managed-artifact checks reject unresolved runtime imports
Implicit source-alias resolution fails in the build processA runtime, Amp, OpenClaw, or DeepSeek artifact is not produced even though the source is validThe build registers an explicit source-alias resolver for runtime bundle builds
A public declaration is filtered out or left at its bundler pathTypeScript consumers cannot use a supported entry point, or internal types become publicThe declaration allow-list, cleanup step, and root-level moves define the supported type outputs
A CLI loses its Node shebang or executable modeDirect command execution fails on supported non-Windows systemsThe build applies mode 0755 and the build and package checks verify it
A packaged bundle exposes the internal rule synchronization operationConsumers can reach an internal package contract that should remain privatePackage verification scans the packed runtime and integration bundles for _operation
An oversized rulebook or source configuration is handled without a safe validation limitThe packaged CLI can expose sensitive rule data or leave partial statePackage verification checks a fail-closed result with no rule content, lock, cache, or network side effect
The package tarball exceeds 700,000 bytesPackaging fails before an oversized artifact reaches consumersverifyPackage rejects the packed result above the size limit
A third-party runtime dependency is bundled without a package noticeConsumers receive an incomplete license record for the shipped codeAdd notice generation or a checked notice file to the package contract before publishing
A plug-in marker, version, or host manifest points to the wrong artifactInstall or doctor tools can miss the managed plug-in, or the host can skip loading itArtifact headers and host manifests are generated together and verified
The tarball contains repository lifecycle behaviorInstallation can run an unintended build or mutate the consumer environmentTarball staging removes prepare and packs with scripts ignored
The requested commit identifier is missing or differs in the packed manifestRelease tracking cannot identify the exact source used for the packageTarball verification validates a full SHA input and compares it with the packed manifest
The DeepSeek harness patch points to a missing or renamed bundle entryThe harness cannot load the packaged safety guardThe build writes the patch beside the entry and the build verifier requires both paths
A pinned OpenCode v2 peer string changes without a package-name-based platform filterWindows can run the slow v2 peer install, or supported platforms can skip the v2 type checkThe isolated consumer filter detects peers by the package name
One release manifest has a different version or uses an unstable version stringRelease preparation or release-state checks reject the release before publicationassertReleaseVersion validates stable semantic versions and release state compares all five manifest versions
The configuration validator changes without a matching schema asset changeEditors accept invalid configuration or reject valid configurationThe schema asset test compares fields, limits, patterns, and intent values with the validator
A repository plugin tree exceeds host or review limits, or its hook bundle exports become ambiguousA host may reject the tree or load an incomplete hook setTree verification checks size, count, lockfiles, line length, and bundle export coverage

Key files

FileWhy to read it
scripts/build.tsMain build coordinator and stage order
scripts/build-plugin-tree.tsRepository plugin tree assembly, metadata generation, README release links, and tree limits
scripts/build-output.tsDefines which generated type declarations are public
scripts/build-runtime.tsRuntime, Amp, OpenClaw, DeepSeek, and bundled template goals and output layouts
assets/cc-safety-net.schema.jsonPublished configuration schema for editor tooling
tests/…/schema-asset.test.tsSchema alignment contract
src/…/assets.tsSelf-contained GUI document assembly
scripts/gui-assets.tsEmbedding of GUI and skill-template content into runtime bundles
scripts/verify-build.tsRequired output, shared-chunk, executable, and self-containment contract
scripts/integration-host-scripts.tsHost boundary models used by integration checks
scripts/verify-package.tsTarball staging, exact package file and mode checks, installed journeys, isolated consumer checks, fail-closed package safety checks, internal API exposure checks, and 700,000-byte tarball size limit
scripts/prepare-release-files.tsCoordinated release version preparation for npm and repository plug-in manifests
scripts/release-state.tsStable version and cross-manifest release-state rules
package.jsonPublic package entry points, build commands, published file set, version, and optional host peer contracts
src/…/index.tsDeepSeek harness plug-in entry and registration contract
src/…/artifact.tsAmp artifact identity and load path
src/…/artifact.tsOpenClaw artifact identity and metadata contract