subc-config
[!WARNING] Alpha. subc-config is in early development and is not yet released for general use. Breaking changes will happen between versions, including changes to its settings, stored data and interfaces. Pin an exact version if you depend on it.
The shared, published configuration-gate contract. This crate performs no I/O, vault resolution,
network discovery, approval or persistence. The daemon checks the approved schema before asking
an admitted module to review. Modules own full JSON Schema draft 2020-12 validation, merge and
cross-field policy; Schema::review_tuple is a module-side helper for the shared merge/bound rules,
not a second authoritative daemon merge engine.
Canonical JSON and digests
canonical_json implements RFC 8785: compact JSON, recursive UTF-16 property sorting, JSON string
escaping, and ECMAScript shortest number formatting. Ryu supplies shortest digits; this crate lays
those digits out using the ECMAScript decimal/scientific notation thresholds. Integers are exact
only within ±(2^53−1). Non-integers must be finite f64. Other numbers are refused, never clamped.
The restriction applies even to an integral f64. Null can be canonicalized, but is never a layer
value. No float_roundtrip or arbitrary_precision serde_json feature is enabled by this crate.
Only this Rust code computes configuration digests. Apps and the TypeScript SDK echo the daemon's
full digest; they do not recompute it. digest hashes the canonical bytes of:
The version is DIGEST_VERSION. Purpose constants are PURPOSE_VALUE, PURPOSE_SCHEMA,
PURPOSE_DECLARATION, PURPOSE_REVIEW, PURPOSE_APPLY_PLAN, PURPOSE_PLAN, PURPOSE_CHANGESET,
PURPOSE_GENERATION, and PURPOSE_SNAPSHOT. Unknown purposes are refused. Digest validates the
complete sha256: plus 64 lowercase hex representation. raw_digest is plain SHA-256 over exact
file bytes: comments, BOMs, line endings and absent files remain distinct snapshot inputs.
Schemas and layers
vocabulary.schema.json publishes the policy annotation meta-schema, also exported as
VOCABULARY_META_SCHEMA. Schema::new normalizes local references and use-site policies. Remote,
recursive, unresolved references, conditional/ambiguous policy compositions and nullable types are
refused. propertyNames and not are refused at the settings node's path unless they occur in an
opaque x-ck-kind: "json" schema. Structural objects require unevaluatedProperties: false.
Dynamic maps use a constrained patternProperties value schema, not arbitrary additional JSON.
Every primitive, replacement array, item and map value needs a description and effective
x-ck-apply and x-ck-layers.
Except for credential references, these fields need a default or an explicit x-ck-required.
An object marked x-ck-required: false with no default stays absent until a layer sets it;
that layer starts from the defaults of the object's members.
true requires an effective value; false with no default leaves the field absent until a layer
sets it. With a default, false still uses the default. An absent overlay inherits the lower value;
neither null nor an empty array means absent.
Structural policies propagate; children may narrow layers, not widen them.
Apply transitions must agree or increase disruption (live to a deferred transition, or a
transition to daemon restart). new_sessions counts as live here: either may hold children of
any kind. Process-wide restart fields are user-only.
The apply kinds are live, module_restart, daemon_restart, next_supervision, route_rebind,
new_sessions. A new_sessions change is delivered at once, exactly like live, but the module
applies it only to sessions that start afterwards. Earlier versions refuse it as an unknown kind
and refuse the module's whole declaration, so a module declares new_sessions only after the
core it runs under accepts it.
x-ck-kind: "model_ref" marks a single value as a model id. Optional display annotations
let apps present tables and pickers:
x-ck-tableis a table id matching^[a-z][a-z0-9_]{0,39}$. Maps with the same id in one module form a table whose rows are the union of their keys. Each map is a separate column with its own settings path, layers and apply class.x-ck-key-kind: "model_ref"is the only supported key kind. It tells apps to offer the model catalog picker for new keys, without validating keys against a catalog.x-ck-pathmust be"folder"or"file"on a string leaf withx-ck-kind: "path". It selects the system picker. An array whose string items carry"folder"is shown as one row per folder.x-ck-ordered: truemarks an array whose item order carries behaviour, such as a fallback ladder of models or runners. The Settings form shows reorder controls only for such lists. Absent means the order carries no meaning: apps keep the stored order when saving and show no reorder controls.
x-ck-table and x-ck-key-kind require a dynamic map (an object with patternProperties
and no named properties). All columns of a table must have the exact same key pattern
string and the same x-ck-key-kind, or all omit the key kind. x-ck-ordered requires
type: "array", and only the value true is admitted: false or any other value is
refused, since absence is the only way to say unordered. Invalid values, placements
and conflicting columns are refused as schema_invalid at the offending node. All four
annotations are display hints only: they do not change value validation, layer merging
(arrays still replace wholesale) or approval semantics
and are never part of review text. Earlier cores refuse the annotations and the module's whole
declaration; use them only once the running core accepts them.
Allowed layers are user, workspace, project, in that order; defaults sit below user. There is no agent layer. Canonical project/workspace root identity, registry mappings, shared-root deduplication and completeness of the affected project set are snapshot responsibilities of the caller, not path lookups performed by this crate. Re-review every affected approved project tuple when a lower layer changes, even when the changeset does not edit that project's file.
Layer overlays inherit absent keys and source attribution. Objects/maps deep-merge; {} does not
clear them. Arrays replace in order, including [], with complete items and no id-based merge.
Declared item ids must be unique. Outside opaque values, unknown keys and null are refused.
A managed field normally has one type, but a nonempty type list can combine string, number,
integer, and boolean. A higher layer replaces the value and can use a different listed type;
object, array, and null are not permitted in a managed type list. A managed oneOf must
either list titled string values (below) or describe tagged object variants. Each variant
must have a unique required const discriminator. The first layer to set a tagged union
may select a different variant and replace the schema default wholesale, or deep-merge into the
default's variant. A lower layer's edits to any field in a variant fix it for higher layers, even
if the lower layer does not set the discriminator explicitly.
For a string picker with human-readable labels, declare type: "string" and put at least two
titled constants in oneOf. Each branch has a unique string const, a title, and optionally
a string description, with no other branch keys. Titles must be trimmed, contain 1–80 Unicode
characters, and have no control characters. The setting still needs its usual description and
policies, and any default must equal one of the constants. For example, with inherited policies:
Layers replace the string just as they would with enum. The normalized schema retains the
titles, so changing a title changes the schema digest without changing the allowed values.
Full effective schema and cross-field checks remain mandatory in the module's review reply; the shared helper's type/enum/range/required checks do not replace a full draft 2020-12 validator.
Declare "x-ck-kind": "json" to treat a value as one opaque field. The settings key is still
managed, but the module owns the value's inner keys. The user layer replaces the whole value;
workspace and project writes give layer_forbidden at the field. Review diffs likewise report
one field with the whole old and new values. Defaults are allowed and validated. The field itself
cannot be null, but nested JSON may contain nulls. Literal {env: and {file: tokens are still
refused; singleton objects with env or file keys are ordinary data inside an opaque field.
Outside opaque fields, {"env": "<string>"} and {"file": "<string>"} are refused as the old
value-reference forms; a lone env or file key holding a map or list is ordinary data.
An opaque field can omit type and other JSON assertions to accept any non-null JSON, or use
constraints such as "type": ["boolean", "object"] or a oneOf without a discriminator.
Supported assertions include type, enum, const, oneOf, anyOf, allOf, not, string
lengths and regex patterns, numeric ranges, object properties, patterns, names, sizes and required
keys, and array items, prefix items, lengths and uniqueness. Boolean subschemas and acyclic local
JSON Pointer $refs are supported. Unsupported keywords refuse the schema at the keyword's path.
Do not put x-ck-kind, x-ck-bound, x-ck-options, x-ck-action, x-ck-table, x-ck-key-kind,
x-ck-path, or x-ck-ordered inside the opaque schema.
x-ck-bound restricts only workspace and project writes. Each is compared against the effective
value from lower layers, or the schema default if no lower layer supplied a value. An optional
field with no lower value has nothing to compare. The user layer is never checked against the
default. A bound on a field only the user layer can set has no effect. This includes opaque
fields, which normalize any layer list that includes user to ["user"].
raise_only and lower_only compare finite numbers; subset_only compares arrays as sets of
strings, numbers, or booleans without changing array order. Boolean and enum monotonic bounds
require x-ck-ordering: an enum's values from lowest to highest, or exactly [false,true] for a
boolean. Scalar type lists need an explicit enum ordering unless all types are numeric. No
lexical order is inferred.
Bounds refuse instead of clamping. Default 5, user 10, project 15 is valid under raise_only;
changing user to 20 refuses project 15 with bound_violated and the project id until the project
override is removed or corrected.
Static enum pickers and closed x-ck-options sets reject out-of-set values with value_invalid.
Closed dynamic sets are caller-supplied pinned local evidence in ValidationContext::closed_options;
missing evidence refuses validation. The daemon remains responsible for dispatching options/actions only through operations declared
read-only in the module manifest pinned to that module's admitted program build, dependency/cache
invalidation, and approval of any side effect. Schema
labels and descriptions are never trusted approval text.
Credentials and safe records
A credential field has x-ck-kind: credential_ref and holds {"vault_ref":"<id>"}. The id is
opaque, 1–256 bytes of printable ASCII without spaces. This crate checks shape only; a module
resolves the reference through the vault using the daemon's attestation of the caller's module
identity and approved layer/project context. The vault must check that context against the
credential's entitlement rather than trusting a caller-supplied project string. The reference never contains a
secret. Environment/file expansion tokens are refused, never expanded.
Credential fields cannot have defaults. For an optional credential field, an omitted reference
means no credential and the field is left out of effective settings.
Project/workspace references require an entitlement supplied by the validator for the particular
module and project (ValidationContext::project_credentials, canonical reference digests). Copying
a user reference into a project does not grant entitlement. Copied user references and an endpoint
override paired with an inherited user credential give credential_shared; project-owned
references still require entitlement. Modules declare credential/destination relationships through
credential_destinations, not a heuristic based on field names. The caller must populate these
relationships and entitlement evidence when reviewing affected credential fields. Actual vault
entitlement enforcement is a prerequisite to adopting those fields; this crate does not claim to
provide it or support explicit sharing.
Call Schema::record before retaining any submitted value, including rejected literals. It
retains only the canonical value digest and a redacted: true marker at credential paths. Valid
vault-reference ids are redacted too. Unknown keys are redacted conservatively. Refusals contain
only a code, field pointer and project id, never values or schema text. Raw proposal bytes and the
raw LayerValue request are ephemeral validation inputs, not history/activity/plan records. Build
RecordedValue, FieldChange and Changeset from this projection; putting raw JSON directly in a
record defeats redaction. The crate does not log submitted values.
Plans and generations
Plan binds base revision, base generation, active-generation vector, daemon incarnation,
InputVector and Changeset. Input keys identify the complete read set: subc.jsonc, and all layers,
declarations and covered program files for each touched module. Caller snapshot records (and their
digests) must include root/file identities, registry mapping, raw and parsed digests and explicit
absence. InputState::Absent is not an empty file. Plan::check_fresh compares the base revision
and the saved read set; extra unrelated inputs do not stale a plan. Delivery/proposal/status writes
do not change the base revision. A plan_stale refusal carries no replacement digest.
Changesets retain effective old/new values, source changes even for equal values, policy changes,
affected projects, launch manifests and the complete apply plan. These are review records, not
approval authority. Generation records serial ids, approved plan/input/declaration digests,
per-module delivery state, active vectors, never-redeliver markers and development provenance.
Generation allocation, commit locking, approval consumption and delivery state transitions belong
to the daemon. Development generations do not move active vectors.
All public structs are non-exhaustive and have constructors; all public enums are non-exhaustive. Serde names are snake_case. Request structs reject unknown fields; replies and records tolerate future fields. Constructors and validation helpers do not authorize an apply request.