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.
| Surface | Purpose | Delivery concern |
|---|---|---|
| Node package | Provide the public import, API subpath, OpenCode compatibility export, and CLI commands | Stable exports, executable CLI, and bounded package contents |
| Claude Code plugin | Register the pre-tool hook for Claude Code | Matching version, tracked metadata, and the expected hook target |
| Codex plugin | Register the pre-tool hook for Codex | Matching version, tracked metadata, and the expected hook target |
| Kimi Code plugin | Describe the Kimi Code hook and related assets | Matching version and a valid hook entry |
| Cursor plugin tree | Provide a self-contained tree with hook bundles, manifests, and agent assets | Bounded tree size, readable output, and valid host metadata |
| Pi extension | Load the agent extension from the package | A published extension path that resolves after install |
| DeepSeek Harness bundle | Load the agent guard through the Harness bundle and its patch | A published bundle path and a valid patch entry |
| Amp plugin | Load a self-contained plugin tree | A managed artifact with its runtime dependencies included |
| OpenClaw plugin | Discover and start a native plugin | Matching 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 group | Result |
|---|---|
| Node runtime | Package entry, API subpath, CLI, Pi extension, DeepSeek Harness bundle, command hook loader, shared chunks, and a vendored runtime dependency |
| Agent plugin runtime | Self-contained Amp and OpenClaw plugin artifacts |
| Public type surface | Root declaration output for package consumers |
| Configuration contract | JSON Schema generated from the rules configuration schema |
| Dependency notice | Third-party license text for bundled dependencies |
| Embedded agent assets | GUI 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:plugincommand 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
| Trigger | Consequence | Guard |
|---|---|---|
| A generated artifact or embedded asset is stale | The release can package behavior that does not match its source | CI rebuilds and compares owned distribution files, the schema, and the license notice |
| A source file has an unexplained or stale comment | Code intent is hidden or the allowlist no longer describes the source | Comment 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 signal | LCOV parsing and line/function threshold checks fail the verification gate |
| A bundled plugin keeps an external runtime import | A checkout-based or standalone host fails at load time | Build verification rejects non-built runtime imports |
| A plugin entry path or manifest identity drifts | The host does not discover or start the plugin | Build and repository-plugin verification check paths, markers, versions, and metadata |
| A standalone plugin tree has too many files, oversized files, lockfiles, or unreadable output | A host may reject the tree or the artifact may become hard to inspect and carry | The tree verifier enforces file, size, lockfile, and line-length limits |
| Hook modules export the same name across bundles | The generated tree can expose an ambiguous or incomplete hook API | Plugin-tree build checks bundle exports before it reports success |
| The DeepSeek Harness patch or bundle entry is missing | The Harness host cannot load the packed guard | Build verification requires both paths and package verification resolves the patch to the bundle |
| Package and Codex or Claude versions disagree | A host can load plugin metadata for a different package version | Repository-plugin verification compares the package and plugin manifests |
| The package contains an unexpected file or exceeds its 700,000-byte size cap | Distribution scope or package cost changes without review | Tarball file-set and size checks fail |
| A packed consumer sees a peer generation that it does not declare | Library or plugin consumers cannot type-check or load the intended API | Isolated consumer fixtures install each peer setup separately |
| Rule or Git input exceeds a safe limit | The packed CLI may expose sensitive input or perform an unsafe validation step | Package verification requires fail-closed output without secret echo, writes, or network access |
| Main advances during release preparation | The tag may omit a newer approved change or use unverified bytes | The release transaction requires the exact prepared base and atomic push |
| npm already has the version with another commit identity | Users may receive a package that does not match the repository tag | Publication compares npm gitHead with the immutable tag commit |
| A GitHub release has an unexpected or duplicate asset | Release downloads no longer represent the verified package | Asset planning rejects unexpected and duplicate names before completion |
| A downstream dispatch has the wrong tag or missing release identity | Landing-page or documentation state can point to the wrong release | The notification workflow sends the canonical release fields only for the canonical repository |
| A packed bundle exposes an internal synchronization operation | Consumers can observe an operation that should remain private to the source build | Package verification scans the packed runtime bundles for the internal operation marker |
| An automatic DSH Plugin Hub issue does not match the known title prefix | A known distribution report remains open for manual handling | The 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 version | The package or nested build steps can fail outside the supported toolchain | engines.node, packageManager, and the project Bun wrapper define the supported runtime contract |
Key files
| File | Why to read it |
|---|---|
| package.json | Defines public entry points, API subpaths, CLI aliases, agent extension path, scripts, runtime floor, package manager, optional peers, and package file boundary. |
| scripts/project-bun.ts | Keeps nested build commands on the package's declared Bun runtime. |
| scripts/build.ts | Shows the high-level build order and final artifact gate. |
| scripts/build-runtime.ts | Explains 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.ts | Shows 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.ts | Shows how GUI values and the skill template become bundled assets. |
| scripts/verify-build.ts | Defines the allowed distribution shape, shared-chunk reachability, managed artifact checks, and runtime-link checks. |
| scripts/comment-allowlist.json | Records the small set of source comments that the comment policy accepts as required context. |
| scripts/check-comments.ts | Defines the source comment policy and allowlist freshness check. |
| scripts/verify-coverage.ts | Defines the coverage report contract and minimum line and function coverage. |
| scripts/verify-package.ts | Shows how the real tarball is packed, installed, type-checked, and exercised outside the repository. |
| scripts/integration-host-scripts.ts | Models packed Pi, DeepSeek Harness, Amp, OpenCode, and OpenClaw host loading for integration checks. |
| scripts/opencode-v2-host.ts | Verifies the OpenCode v2 registry, tool denial, code-mode denial, and shell contract. |
| .github/…/ci.yml | Shows clean-environment source, build, package, cross-platform, and path-filter gates. |
| .github/…/close-dsh-plugin-hub-issues.yml | Shows the automated handling of known DSH Plugin Hub reports and the supported recovery command. |
| .github/…/prepare-release.yml | Shows how a version becomes a verified immutable release candidate. |
| scripts/prepare-release-files.ts | Updates the version across the package and agent release manifests. |
| .github/…/publish.yml | Shows how the tag-bound tarball reaches npm and GitHub without a rebuild gap. |
| .github/…/notify-landing-page-release.yml | Shows how a published release notifies the landing-page and documentation repositories. |
| scripts/release-transaction.ts | Defines allowed release changes and resumable release state. |
| scripts/release-state.ts | Defines the relationship between manifests, tags, commits, and npm publication. |
| scripts/release-assets.ts | Defines the expected GitHub release asset set. |