description: "Runtime invariant checks for live compositions: the registry service that runs package-owned checks, for users and maintainers choosing, configuring, or debugging them."
English | 中文
dsh-invariants runs package-owned runtime checks — invariants — inside a DeepSeek Harness composition: any package can ship a ./invariant companion that verifies its own durable relationships (authoritative event streams and mutable snapshots) while the composition runs. Checks run automatically, and a failed check reports an InvariantError attributed to the package that owns the violated relationship. Choose it for compositions that want self-checking diagnostics with a global switch and package-name filters; the standard agent composition already mounts it with the four core companions, and loading the service alone installs no checks.
Mount the registry when a composition should verify its own runtime contracts, then decide which packages' checks run. The service exposes ctx.invariants; companions register checks under their package's exact npm name, and every failure carries the owning package name.
Use the registry for compositions that want live diagnostics. dsh-sdk-minimal mounts it with the four core stateful companions — dsh-session, dsh-agent, dsh-scope, and dsh-agent-loop; dsh-base deliberately omits runtime diagnostics. Custom compositions mount the registry and add companions for any other loaded package whose contracts they want checked. Loading the registry alone installs no checks: it ships no product checks of its own, so a composition that never mounts a companion observes no diagnostic behavior.
The registry is enabled by default and checks every registered package unless filters say otherwise. Use enabled as a global switch, package_allowlist to admit only named packages, and package_blocklist to exclude packages after allowlist matching — a blocklist match overrides an allowlist match. Patterns are case-sensitive JavaScript regular-expression sources (unanchored unless they supply ^ and $), and an invalid, blank, or duplicate entry fails service startup instead of being skipped.
- name: '@deepseek-ai/dsh-invariants'
config:
enabled: true
package_allowlist:
- '^@deepseek-ai/dsh-'
| Field | Default | Meaning |
|---|---|---|
enabled |
true |
Global switch for all registered checks |
package_allowlist |
[] |
Regex sources admitting package names; empty admits all |
package_blocklist |
[] |
Regex sources excluding package names after allowlist matching |
The generated configuration catalog is the exhaustive source for every accepted field and its JSDoc.
Each companion protects relationships its package owns, and a companion installs a check only for an observable event or mutable-data relationship — never for a service or method presence. The shipped executable companions cover:
| Companion | Checks |
|---|---|
dsh-session, dsh-agent, dsh-scope, dsh-agent-loop |
Session log enclosure and call/result trace, agent-status transitions, scope-filtered dispatch subjects, loop-built request reconstruction |
dsh-llm, dsh-llm-retry, dsh-tools, dsh-system-prompt |
LLM stream grammar, retry-failure shape, tool-pipeline stage pairing and frozen results, prompt-assembly section names |
dsh-compaction, dsh-hook-protocol, dsh-sandbox-policy |
Compaction stream pairing, hook invocation/result pairing, sandbox mode values |
dsh-fs, dsh-subagent, dsh-workflow, dsh-tool-workflow |
Filesystem event identity, subagent provider and start/end pairing, workflow lifecycle identity, workflow record shape |
dsh-goal, dsh-goal-round-driver |
Durable goal-stream folds and reconstructed continuation prompts |
dsh-permission-presets, dsh-user-approval, dsh-commands |
Preset references to live presets, approval asked/decided pairing, command run/done pairing |
dsh-jobs, dsh-tool-todo, dsh-time-context |
Job snapshot field relationships, whole-list todo shape, durable clock readings |
dsh-credentials, dsh-settings, dsh-storage-domain, dsh-workspace |
Commit events against the live service or memory state, entity-cache mirroring |
dsh-agent-presets, dsh-session-title, dsh-plan-mode, dsh-schedule |
Preset mount placement, title source citation, plan-mode payload, schedule stream |
dsh-client-hmr, dsh-client-modules, dsh-client-runtime |
Browser/node-half stat-watcher lifecycle, boot entry graph, slot mutation versioning |
Every other workspace package omits the companion and states the package-specific reason in its README.
A companion is a normal plugin you mount beside the registry. It declares any services it needs and registers under its package's exact npm name; the registry joins its setup before the registration completes.
import type { Context } from '@deepseek-ai/cordis'
import InvariantRegistry from '@deepseek-ai/dsh-invariants'
import * as SessionInvariant from '@deepseek-ai/dsh-session/invariant'
declare const ctx: Context
ctx.plugin(InvariantRegistry, { enabled: true })
ctx.plugin(SessionInvariant)
A violation throws an InvariantError from the context that reported it: it carries the stable code INVARIANT, the full npm packageName of the owning package, and a message prefixed invariant violated by "<package>": …. The failure is therefore attributable to a package without the registry importing any product code. A companion whose installer itself fails is disposed and its registration rolled back, so a broken check cannot leave partial listeners behind.
Read these pages when the package-level contract is not enough. They move from the generated service reference to the decision evidence and the group map.
Config, the installer, the service, and the companion contract.None, as the observer validates requests but never rewrites their context.
Checks observe assembled requests and durable state without mutating request content, so provider cache reuse is exactly what the underlying composition produces.
These limits define when the registry is a poor fit or needs operational care. They are current package constraints, not a task backlog.
enabled, package_allowlist, and package_blocklist are compiled once at startup; changing them requires a Cordis plugin reload.dsh-agent-loop companion reconstructs requests explicitly built by the loop; direct one-shot LLM calls remain outside that contract even when callers freeze them or attach a session id.