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_modulesand 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
| Trigger | Consequence | Guard |
|---|---|---|
| A required entry file is missing or a shared chunk is orphaned | The package can install with an incomplete or unreachable runtime | verifyBuildArtifacts checks required files and chunk reachability |
| A host artifact imports a package that the host does not install | Amp or OpenClaw fails when it loads the plug-in | Bundling plus managed-artifact checks reject unresolved runtime imports |
| Implicit source-alias resolution fails in the build process | A runtime, Amp, OpenClaw, or DeepSeek artifact is not produced even though the source is valid | The build registers an explicit source-alias resolver for runtime bundle builds |
| A public declaration is filtered out or left at its bundler path | TypeScript consumers cannot use a supported entry point, or internal types become public | The declaration allow-list, cleanup step, and root-level moves define the supported type outputs |
| A CLI loses its Node shebang or executable mode | Direct command execution fails on supported non-Windows systems | The build applies mode 0755 and the build and package checks verify it |
| A packaged bundle exposes the internal rule synchronization operation | Consumers can reach an internal package contract that should remain private | Package verification scans the packed runtime and integration bundles for _operation |
| An oversized rulebook or source configuration is handled without a safe validation limit | The packaged CLI can expose sensitive rule data or leave partial state | Package verification checks a fail-closed result with no rule content, lock, cache, or network side effect |
| The package tarball exceeds 700,000 bytes | Packaging fails before an oversized artifact reaches consumers | verifyPackage rejects the packed result above the size limit |
| A third-party runtime dependency is bundled without a package notice | Consumers receive an incomplete license record for the shipped code | Add 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 artifact | Install or doctor tools can miss the managed plug-in, or the host can skip loading it | Artifact headers and host manifests are generated together and verified |
| The tarball contains repository lifecycle behavior | Installation can run an unintended build or mutate the consumer environment | Tarball staging removes prepare and packs with scripts ignored |
| The requested commit identifier is missing or differs in the packed manifest | Release tracking cannot identify the exact source used for the package | Tarball verification validates a full SHA input and compares it with the packed manifest |
| The DeepSeek harness patch points to a missing or renamed bundle entry | The harness cannot load the packaged safety guard | The 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 filter | Windows can run the slow v2 peer install, or supported platforms can skip the v2 type check | The isolated consumer filter detects peers by the package name |
| One release manifest has a different version or uses an unstable version string | Release preparation or release-state checks reject the release before publication | assertReleaseVersion validates stable semantic versions and release state compares all five manifest versions |
| The configuration validator changes without a matching schema asset change | Editors accept invalid configuration or reject valid configuration | The 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 ambiguous | A host may reject the tree or load an incomplete hook set | Tree verification checks size, count, lockfiles, line length, and bundle export coverage |
Key files
| File | Why to read it |
|---|---|
| scripts/build.ts | Main build coordinator and stage order |
| scripts/build-plugin-tree.ts | Repository plugin tree assembly, metadata generation, README release links, and tree limits |
| scripts/build-output.ts | Defines which generated type declarations are public |
| scripts/build-runtime.ts | Runtime, Amp, OpenClaw, DeepSeek, and bundled template goals and output layouts |
| assets/cc-safety-net.schema.json | Published configuration schema for editor tooling |
| tests/…/schema-asset.test.ts | Schema alignment contract |
| src/…/assets.ts | Self-contained GUI document assembly |
| scripts/gui-assets.ts | Embedding of GUI and skill-template content into runtime bundles |
| scripts/verify-build.ts | Required output, shared-chunk, executable, and self-containment contract |
| scripts/integration-host-scripts.ts | Host boundary models used by integration checks |
| scripts/verify-package.ts | Tarball 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.ts | Coordinated release version preparation for npm and repository plug-in manifests |
| scripts/release-state.ts | Stable version and cross-manifest release-state rules |
| package.json | Public package entry points, build commands, published file set, version, and optional host peer contracts |
| src/…/index.ts | DeepSeek harness plug-in entry and registration contract |
| src/…/artifact.ts | Amp artifact identity and load path |
| src/…/artifact.ts | OpenClaw artifact identity and metadata contract |