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 / delivery-engineering

Build, packaging, and release engineering

CC Safety Net turns TypeScript source into checked delivery artifacts for its command-line interface, library entry points, and agent integrations. Build and release work keeps source code, generated policy data, bundled assets, package contents, and published versions aligned before users receive them. The package uses Bun 1.4.4 for project commands and supports Node 22 or later for consumers.

Delivery model

The delivery model treats source code as the input and several agent-facing artifacts as the output. Users receive the product through package imports, a CLI, native plugin formats, and a standalone plugin tree, so delivery checks protect both shared behavior and each host's loading contract.

Distribution surfaces

Each surface supports a different part of the user journey. The npm package serves direct installs and library users. Plugin directories and files let agent hosts load CC Safety Net without a checkout or a second package install.

SurfacePurposeDelivery concern
Node packageProvide the public import, API subpath, OpenCode compatibility export, and CLI commandsStable exports, executable CLI, and bounded package contents
Claude Code pluginRegister the pre-tool hook for Claude CodeMatching version, tracked metadata, and the expected hook target
Codex pluginRegister the pre-tool hook for CodexMatching version, tracked metadata, and the expected hook target
Kimi Code pluginDescribe the Kimi Code hook and related assetsMatching version and a valid hook entry
Cursor plugin treeProvide a self-contained tree with hook bundles, manifests, and agent assetsBounded tree size, readable output, and valid host metadata
Pi extensionLoad the agent extension from the packageA published extension path that resolves after install
DeepSeek Harness bundleLoad the agent guard through the Harness bundle and its patchA published bundle path and a valid patch entry
Amp pluginLoad a self-contained plugin treeA managed artifact with its runtime dependencies included
OpenClaw pluginDiscover and start a native pluginMatching manifest identity, version, activation, and entry path

References: package.json• L1-26 package.json• L35-59 package.json• L105-145 scripts/build-plugin-tree.ts• L12-23 scripts/build-plugin-tree.ts• L136-172 .claude-plugin/plugin.json• L1-23 .codex-plugin/plugin.json• L1-20 hooks/hooks.json• L1-14 hooks/codex.json• L1-14 kimi.plugin.json• L1-26 scripts/build-runtime.ts• L32-58 scripts/build-runtime.ts• L117-163 src/…/artifact.ts• L7-18 src/…/artifact.ts• L10-20

Delivery relationships

The build creates runtime surfaces first. It then creates declarations and the configuration schema before it checks the full artifact set. The standalone plugin-tree command creates a host-ready directory from hook bundles, metadata, and agent assets. Release automation uses these outputs instead of building a different package at publish time. The detailed build path is described in Build and package orchestration. The checks around tags and publication are described in Release and verification workflows.

The flow below shows how source changes become a release candidate and then a public release.

flowchart LR
    S[TypeScript source and agent metadata] --> B[Build runtime and agent assets]
    B --> G[Generate declarations, schema, and licenses]
    G --> V[Verify outputs and package behavior]
    V --> T[Create tag-bound package tarball]
    T --> P[Publish exact tarball to npm and GitHub]
    P --> D[Notify downstream distribution]

References: scripts/build.ts• L10-52 scripts/build-runtime.ts• L32-58 scripts/build-plugin-tree.ts• L136-225 package.json• L60-87 .github/…/prepare-release.yml• L71-116 .github/…/publish.yml• L37-65 .github/…/publish.yml• L105-170

Build outputs

The build produces a small set of intentional outputs instead of copying the source tree into distribution. Node targets share chunks and include a vendored runtime dependency for checkout-based hosts. Standalone host formats receive self-contained runtime assets when the host cannot install or resolve dependencies.

Runtime artifacts

The runtime build exposes the package entry, API subpath, executable CLI, Pi extension, and DeepSeek Harness bundle. It also supplies the package's command hook loader and the schema runtime to Node bundles that run without package installation. Separate Amp and OpenClaw builds include their runtime needs so those hosts can load a complete plugin directory from a local or packaged install.

The runtime entry loader enables Node's compile cache before it loads the command hook bundle. This keeps the published CLI entry separate from the bundled hook while preserving the package's executable contract.

The build also freezes GUI values and the skill template into the bundles. This makes those assets available to a packed artifact without a source-tree lookup.

Artifact groupResult
Node runtimePackage entry, API subpath, CLI, Pi extension, DeepSeek Harness bundle, command hook loader, shared chunks, and a vendored runtime dependency
Agent plugin runtimeSelf-contained Amp and OpenClaw plugin artifacts
Public type surfaceRoot declaration output for package consumers
Configuration contractJSON Schema generated from the rules configuration schema
Dependency noticeThird-party license text for bundled dependencies
Embedded agent assetsGUI values and the skill template included in runtime bundles

References: scripts/build.ts• L10-52 scripts/build-runtime.ts• L32-58 scripts/build-runtime.ts• L60-115 scripts/build-runtime.ts• L117-163 scripts/gui-assets.ts• L3-23 scripts/build-schema.ts• L5-33 scripts/generate-third-party-licenses.ts• L6-29 package.json• L35-87

Standalone plugin tree

The standalone plugin tree is a host-ready directory for agent environments that consume files and hook bundles as a unit. It groups the CLI hook's modules into named shared bundles, links imports across those bundles, and copies the metadata, hooks, skills, license, logo, and host marketplace data that the tree needs.

The tree is built from the same compile-cache CLI loader used by the runtime build. Its final check limits file count and size, rejects lockfiles beside a local package manifest, and rejects unreadable long lines. These limits keep the tree portable and reviewable.

References: scripts/build-plugin-tree.ts• L12-23 scripts/build-plugin-tree.ts• L24-44 scripts/build-plugin-tree.ts• L61-132 scripts/build-plugin-tree.ts• L136-173 scripts/build-plugin-tree.ts• L175-225 scripts/build-runtime.ts• L60-77

Artifact identity

Agent hosts need more than executable code. The Amp and OpenClaw artifacts carry managed-file markers and package versions so installers and diagnostics can identify ownership and detect stale files. OpenClaw also receives metadata that ties its plugin identity to the runtime entry and enables startup activation.

The DeepSeek Harness artifact includes a package-owned patch that names the bundled entry. This lets the packed verification flow resolve the agent bundle through the same path that distribution provides.

References: src/…/artifact.ts• L1-18 src/…/artifact.ts• L22-79 scripts/build-runtime.ts• L24-30 scripts/build-runtime.ts• L137-163 scripts/verify-build.ts• L58-149 scripts/verify-package.ts• L587-601

Verification gates

Verification checks the product at several boundaries: source quality, generated output freshness, artifact structure, package installation, and host behavior. This layered approach catches failures that a successful TypeScript compile cannot detect, such as a missing shared chunk, a wrong plugin path, or a package that works only inside the repository.

Source and build checks

Continuous integration runs on relevant pushes to main, pull requests, and manual dispatches. Its path filter skips documentation and unrelated agent, evaluation, and scanner changes while still including workflow changes, so delivery logic changes continue to trigger the gate.

CI audits dependencies, runs source checks, and runs end-to-end stability checks. It also checks that source files express their intent through names, values, and types instead of unexplained comments. The comment check permits only required tool directives or reviewed external-tool facts, and it rejects stale allowlist entries or files that cannot be parsed.

CI rebuilds owned artifacts and requires at least 90% line and function coverage from a valid LCOV report. It then rejects generated-file drift and verifies repository plugin and package surfaces. The package verification matrix repeats the packed-package check across supported Node versions and operating systems. A separate Windows job checks native command behavior.

References: package.json• L60-87 package.json• L130-136 scripts/comment-allowlist.json• L1-49 scripts/check-comments.ts• L7-21 scripts/check-comments.ts• L23-85 scripts/verify-coverage.ts• L10-68 .github/…/ci.yml• L3-31 .github/…/ci.yml• L36-67 .github/…/ci.yml• L138-167 .github/…/test-windows.yml• L19-48

Artifact checks

Build verification requires the expected entry artifacts and shared chunks. It rejects extra or orphaned files, checks CLI mode and shebang, confirms managed headers and versions, and rejects runtime imports that need an undeclared package or a missing bundled dependency. This keeps each host-facing artifact usable without files that the package does not deliver.

The expected set includes the DeepSeek Harness bundle and its patch, as well as the package hook loader. Shared chunks must be reachable from the built entries, so a build cannot pass with either a missing chunk or an unused chunk left in the distribution directory. The standalone plugin-tree build applies separate size, file-count, lockfile, and readability checks before it reports success.

References: scripts/verify-build.ts• L14-33 scripts/verify-build.ts• L58-135 scripts/verify-build.ts• L138-149 scripts/build-plugin-tree.ts• L175-225

Package checks

Package verification tests the actual npm tarball rather than only the working directory. It checks the exact file set, a 700,000-byte size cap, and file modes before installing the tarball in clean projects. It then confirms package and API loading paths, manifest exports, declaration use with each supported peer setup, and representative safe and blocked journeys through the CLI and agent integrations.

The packed host checks cover the CLI, Pi, DeepSeek Harness, OpenCode, and Amp paths. They confirm that safe commands remain available while destructive or dynamically hidden commands fail closed. The same check covers oversized rule data, incomplete Git configuration, large safe commands, shell-derived commands, the OpenCode v2 contract, library audit behavior, and the packed release identity. It also checks that internal rule synchronization operations do not leak into packed runtime bundles.

The host scripts provide small adapters for each supported host. Each adapter loads the packed artifact and exposes only the host callbacks needed by the verification journey. This keeps the package check focused on the distribution contract instead of on a repository-local import path.

References: scripts/verify-package.ts• L26-33 scripts/verify-package.ts• L84-182 scripts/verify-package.ts• L183-379 scripts/verify-package.ts• L382-433 scripts/verify-package.ts• L436-585 scripts/verify-package.ts• L587-601 scripts/verify-package.ts• L603-667 scripts/integration-host-scripts.ts• L1-196 scripts/opencode-v2-host.ts• L1-64

Release lifecycle

The release lifecycle separates preparation from publication. Preparation changes versioned release inputs on the current main commit and creates one immutable tag. Publication verifies that tag and distributes the exact package built from it.

Release preparation

The preparation workflow resolves a stable semantic version from an explicit value or a major, minor, or patch bump. It verifies that main is current and clean, rebuilds owned outputs, validates the package, and can run a dry transaction without changing Git. A real transaction commits only approved release paths and pushes the main commit and version tag as one atomic operation.

The workflow transfers a checksum-protected candidate to the mutation job and dispatches publication from the new tag. Version updates cover the package manifest and the Claude Code, Codex, and Kimi plugin manifests. The update helper validates the requested version before changing those four release inputs.

References: .github/…/prepare-release.yml• L51-116 .github/…/prepare-release.yml• L118-165 scripts/prepare-release-files.ts• L7-29 scripts/release-transaction.ts• L71-140 scripts/release-git.ts• L16-43

Release publication

Publication starts only from the immutable release tag and confirms that the workflow ref, tag, and commit agree. It rebuilds and verifies the tag contents, records the package tarball with a checksum and commit identity, and publishes that exact tarball with npm provenance. If a package version already exists, the workflow accepts it only when its recorded commit matches the tag.

References: .github/…/publish.yml• L18-65 .github/…/publish.yml• L67-103 scripts/release-state.ts• L18-45 scripts/verify-package.ts• L705-743

Release completion

The GitHub release is complete only when its asset set matches the verified tarball and checksum. The workflow preserves matching existing assets, uploads missing assets, rejects unexpected or duplicate assets, and then triggers landing-page and documentation updates.

The notification workflow sends the release tag, source repository, release URL, and release ID to the landing-page and documentation repositories. It runs only for the canonical repository and uses separate dispatch credentials for each downstream destination.

References: .github/…/publish.yml• L105-170 scripts/release-assets.ts• L5-24 .github/…/notify-landing-page-release.yml• L1-79 .github/…/release-notes.yml• L1-39

Repository safeguards

Local hooks and CI provide overlapping safeguards so generated artifacts and release inputs do not drift silently. A pre-commit build stages updated distribution files. Pre-push checks run the broad project check. Hosted workflows repeat these checks in clean environments with pinned tool versions.

Generated-file ownership

The repository tracks outputs that users and agent hosts consume, including the schema, license notice, plugin metadata, and distribution directory. CI rebuilds them and fails when the result differs from the committed state. A source change is therefore incomplete until its owned delivery artifacts are refreshed.

References: lefthook.yml• L1-16 .github/…/ci.yml• L43-50 .github/…/prepare-release.yml• L77-82 .github/…/test-windows.yml• L33-34

Distribution issue handling

The DSH Plugin Hub issue workflow handles known automatic reports outside the product's own failure path. When an opened issue has one of the known plugin-install or package-allowlist title prefixes, it closes the issue as not planned and gives the user the supported DeepSeek Harness install command. A real failure can be reopened after that command also fails.

References: .github/…/close-dsh-plugin-hub-issues.yml• L1-32

Release state

Release state is compared across four version manifests, the current commit, the immutable tag, and npm metadata. This comparison supports safe resume after an interrupted release. It rejects a version that exists without its tag, a tag that points elsewhere, or a published package with a different commit identity.

References: scripts/release-state.ts• L8-49 scripts/release-transaction.ts• L77-129

Toolchain consistency

Build commands use the Bun version declared by the package. The project wrapper ensures nested commands use that runtime and can find its executable even when Bun was started by an absolute path. The manifest also declares Node 22 or later as the runtime floor.

References: package.json• L130-136 scripts/project-bun.ts• L1-19

Change checklist

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

  • When changing package.json exports, bin, pi.extensions, peer ranges, or the package file boundary, keep built entry paths, declaration outputs, clean-install checks, isolated consumer checks, and host scripts aligned.
  • When changing the build:plugin command or standalone tree inputs, keep hook bundle grouping, copied agent assets, generated manifests, README release links, and tree limits aligned.
  • When changing plugin versions or metadata, update every release manifest and preserve each host's entry and activation contract.
  • When changing build output paths or splitting, update artifact allowlists, shared-chunk reachability checks, and package file expectations together.
  • When changing the DeepSeek Harness bundle or patch path, keep the patch entry, package manifest, packed bundle resolver, and host verification script aligned.
  • When changing host entry contracts, update the matching integration host script and preserve both safe and blocked command checks for that host.
  • When changing bundled dependencies or embedded assets, review the self-contained Amp and OpenClaw artifacts, the vendored runtime copy, the third-party license output, and the freeze plugins.
  • When changing package verification fixtures or platform skips, preserve coverage of both peer generations, the OpenCode v2 path, and the Windows verification path.
  • When changing source comment policy, keep the allowlist contract and stale-entry checks aligned with the comment checker.
  • When changing coverage reporting, preserve valid LCOV records and the 90% line and function thresholds used by the verification gate.
  • When changing release assets or downstream notifications, keep the checksum file, expected asset plan, existing-asset comparison, and release payload fields consistent.
  • When changing release inputs, preserve the exact-base check so the published tag cannot describe a different main commit from the verified candidate.
  • When changing the declared Bun version or nested build entry point, keep scripts/project-bun.ts and the package build command aligned.
  • When changing the package manager or supported Node range, keep local build execution, CI setup, package metadata, and clean-install verification aligned.
  • When changing the DSH Plugin Hub issue title patterns or install path, keep the issue match rules, close message, and supported DeepSeek Harness command aligned.

Important failure modes

TriggerConsequenceGuard
A generated artifact or embedded asset is staleThe release can package behavior that does not match its sourceCI rebuilds and compares owned distribution files, the schema, and the license notice
A source file has an unexplained or stale commentCode intent is hidden or the allowlist no longer describes the sourceComment verification rejects disallowed comments, parse errors, and stale allowlist entries
A coverage report is empty, malformed, or below 90%CI accepts code with an unmeasured or weak test signalLCOV parsing and line/function threshold checks fail the verification gate
A bundled plugin keeps an external runtime importA checkout-based or standalone host fails at load timeBuild verification rejects non-built runtime imports
A plugin entry path or manifest identity driftsThe host does not discover or start the pluginBuild and repository-plugin verification check paths, markers, versions, and metadata
A standalone plugin tree has too many files, oversized files, lockfiles, or unreadable outputA host may reject the tree or the artifact may become hard to inspect and carryThe tree verifier enforces file, size, lockfile, and line-length limits
Hook modules export the same name across bundlesThe generated tree can expose an ambiguous or incomplete hook APIPlugin-tree build checks bundle exports before it reports success
The DeepSeek Harness patch or bundle entry is missingThe Harness host cannot load the packed guardBuild verification requires both paths and package verification resolves the patch to the bundle
Package and Codex or Claude versions disagreeA host can load plugin metadata for a different package versionRepository-plugin verification compares the package and plugin manifests
The package contains an unexpected file or exceeds its 700,000-byte size capDistribution scope or package cost changes without reviewTarball file-set and size checks fail
A packed consumer sees a peer generation that it does not declareLibrary or plugin consumers cannot type-check or load the intended APIIsolated consumer fixtures install each peer setup separately
Rule or Git input exceeds a safe limitThe packed CLI may expose sensitive input or perform an unsafe validation stepPackage verification requires fail-closed output without secret echo, writes, or network access
Main advances during release preparationThe tag may omit a newer approved change or use unverified bytesThe release transaction requires the exact prepared base and atomic push
npm already has the version with another commit identityUsers may receive a package that does not match the repository tagPublication compares npm gitHead with the immutable tag commit
A GitHub release has an unexpected or duplicate assetRelease downloads no longer represent the verified packageAsset planning rejects unexpected and duplicate names before completion
A downstream dispatch has the wrong tag or missing release identityLanding-page or documentation state can point to the wrong releaseThe notification workflow sends the canonical release fields only for the canonical repository
A packed bundle exposes an internal synchronization operationConsumers can observe an operation that should remain private to the source buildPackage verification scans the packed runtime bundles for the internal operation marker
An automatic DSH Plugin Hub issue does not match the known title prefixA known distribution report remains open for manual handlingThe issue workflow matches both supported title prefixes and posts the recovery command
A consumer uses a runtime below Node 22 or builds with a different Bun versionThe package or nested build steps can fail outside the supported toolchainengines.node, packageManager, and the project Bun wrapper define the supported runtime contract

Key files

FileWhy to read it
package.jsonDefines public entry points, API subpaths, CLI aliases, agent extension path, scripts, runtime floor, package manager, optional peers, and package file boundary.
scripts/project-bun.tsKeeps nested build commands on the package's declared Bun runtime.
scripts/build.tsShows the high-level build order and final artifact gate.
scripts/build-runtime.tsExplains shared Node outputs, the command hook loader, DeepSeek Harness bundle, self-contained agent artifacts, compile-cache entry, and embedded asset loading.
scripts/build-plugin-tree.tsShows how the standalone agent tree is assembled, how hook modules are grouped, how host metadata and README links are generated, and which portability limits it enforces.
scripts/gui-assets.tsShows how GUI values and the skill template become bundled assets.
scripts/verify-build.tsDefines the allowed distribution shape, shared-chunk reachability, managed artifact checks, and runtime-link checks.
scripts/comment-allowlist.jsonRecords the small set of source comments that the comment policy accepts as required context.
scripts/check-comments.tsDefines the source comment policy and allowlist freshness check.
scripts/verify-coverage.tsDefines the coverage report contract and minimum line and function coverage.
scripts/verify-package.tsShows how the real tarball is packed, installed, type-checked, and exercised outside the repository.
scripts/integration-host-scripts.tsModels packed Pi, DeepSeek Harness, Amp, OpenCode, and OpenClaw host loading for integration checks.
scripts/opencode-v2-host.tsVerifies the OpenCode v2 registry, tool denial, code-mode denial, and shell contract.
.github/…/ci.ymlShows clean-environment source, build, package, cross-platform, and path-filter gates.
.github/…/close-dsh-plugin-hub-issues.ymlShows the automated handling of known DSH Plugin Hub reports and the supported recovery command.
.github/…/prepare-release.ymlShows how a version becomes a verified immutable release candidate.
scripts/prepare-release-files.tsUpdates the version across the package and agent release manifests.
.github/…/publish.ymlShows how the tag-bound tarball reaches npm and GitHub without a rebuild gap.
.github/…/notify-landing-page-release.ymlShows how a published release notifies the landing-page and documentation repositories.
scripts/release-transaction.tsDefines allowed release changes and resumable release state.
scripts/release-state.tsDefines the relationship between manifests, tags, commits, and npm publication.
scripts/release-assets.tsDefines the expected GitHub release asset set.