Introducing a new way to review your PRs.

Read the announcement

hashgraph-online / hol-guard

Open-source antivirus and firewall for AI agents: block risky tools, secret access, prompt injection, malicious packages, MCP servers, plugins, and skills at runtime.

View on GitHub

44 documents · Updated Nov 23, 2026

docs / native-command-source-programs

Native command-source programs

Native command-source programs turn reviewed command definitions into a fixed, content-bound native admission program. The catalog describes extensions, permissions, rules, safe variants, trust, and compatibility links. Validation and compilation bind these definitions to native matchers, control identities, and bounded evidence. The resident loads one packaged program and does not run the source compiler during hook evaluation. The program is not authority by itself. Runtime controls and native evaluation complete the decision path described in Native runtime authority, with command results classified through Native command evaluation and classification.

Command-source catalog

The command-source catalog is the authoring model for command safety coverage. A source document names one extension and its permissions and rules. Each rule states the capability to inspect, the action and risk meaning, its default mode, and either a declarative matcher or a closed native capability binding. Safe variants identify command forms that can reduce the rule's effective match.

The catalog also carries the relationships needed to make a source usable as a product feature:

  • Extension identity, version, publisher, trust class, activation, dependencies, conflicts, executables, and project markers.
  • Permission ownership, baseline floors, configuration state, dependencies, implied permissions, and safer guidance.
  • Rule ownership, severity, action classes, risk classes, matcher coverage, and safe-variant coverage.
  • Optional MCP contribution metadata, which is lowered into the same extension and permission model.

Canonical MCP contribution records use the same catalog path as command sources. They describe direct commands, package launchers, or remote HTTPS endpoints and lower their tools into one external, opt-in safety permission. Unsafe launcher forms and duplicate command, package, endpoint, or alias identities are rejected before the contribution can enter the program.

The source contract is separate from derived trust, activation, indexes, and program digests. This keeps contributed definitions declarative while making release and runtime identity authoritative elsewhere. The build entry point accepts an owned versioned envelope with source records and separately supplied trust data. A packaged base is available only for controlled addition and fixture paths. Generated contribution descriptors expose source metadata and bind each descriptor to its source path and digest. The source entry point is defined in rust/…/native_command_source.rs• L65-136.

References: rust/…/native_command_source_catalog.rs• L77-143 rust/…/native_command_source_catalog.rs• L151-224 rust/…/native_command_program.rs• L152-224 rust/…/native_command_source.rs• L65-136

Native pretool admission

Native pretool admission supplies the base decision for a parsed command before catalog extensions add their floors. It blocks self-protection attacks, destructive commands, and clear secret-transfer flows. It allows only commands that meet a narrow native proof and sends the rest to review or fresh approval.

The result is monotonic: extension controls can strengthen the base action but do not turn a risky native result into an allow. The main outcomes are:

  • Bounded searches, exact benign commands, and some contained worktree operations can receive an explicit allow.
  • Destructive commands and commands that combine sensitive data access with network transfer receive a block.
  • Privileged execution wrappers require fresh approval.
  • Sensitive access, executable path overrides, and Git helper context receive review unless a bounded proof succeeds.
  • Commands that do not meet a safe proof receive review by default.

Path and execution context are part of a safe proof. The authority carries verified home and working-directory roots and relevant execution settings into Git routing, path checks, and worktree checks. A missing or unverified context keeps the command at review or uncertainty instead of creating a false safe result.

References: rust/…/pretool.rs• L181-214 rust/…/pretool.rs• L345-390 rust/…/pretool.rs• L497-695

Source validation

Source validation is the admission gate before any definition can become a native program. It checks both the shape of each definition and the links between definitions, so a valid-looking rule cannot point to an unknown permission, claim another extension's action, or create an unsafe dependency graph.

Validation covers the following contract groups:

Contract groupPurpose
Identity and metadataKeep IDs, versions, text, URLs, executables, and source types bounded and canonical.
Trust and activationPrevent external sources from becoming required and derive trusted publisher data from the reviewed trust map.
Permission and rule ownershipKeep action classes, permissions, rules, and capabilities within their declared extension.
Dependencies and conflictsReject missing links, asymmetric conflicts, replacement errors, cycles, and paths deeper than the allowed bound.
Matcher shapeRequire one predicate per rule and reject unsupported child forms, unknown operations, and unsafe matcher budgets.
Delegated protectionLimit package-firewall delegation to approved package owners with the required package metadata.

The validator also enforces a closed native capability table. A compatibility rule can enter the catalog only when its extension, rule, and permission ownership agree with the existing native compatibility inventory. This prevents a source from using a capability name as a free-form callback or from silently taking ownership of an unrelated native rule.

References: rust/…/native_command_source_validation.rs• L51-159 rust/…/native_command_source_validation.rs• L161-269 rust/…/native_command_source_validation.rs• L274-370 rust/…/native_command_source_catalog.rs• L125-143

Matcher compilation

Matcher compilation lowers an author-owned matcher tree into the typed native matcher graph embedded in the resident. The standalone matcher compiler returns only the graph root and nodes. It grants no activation or policy authority. Equivalent nodes receive one content-derived identity, which lets the packaged program refer to shared behavior without adding new runtime code. The matcher entry point is defined in rust/…/native_command_source.rs• L142-161.

The supported matcher families express bounded command structure rather than arbitrary code. They cover executable and argument checks, structured operands, package subcommands, pipelines, database-backed forms, common CLI forms, and specialized command forms. Combinators join child matchers with any or all, while pipeline matching keeps adjacent segments in the same execution context.

A rule with a declarative matcher receives native execution coverage. A rule with a compatibility capability receives compatibility-only attribution and still depends on the existing native compatibility evaluator. Both forms carry a matcher contract digest and a coverage record. The record states whether the rule was translated to declarative native IR or retained for compatibility attribution.

The admitted program keeps the rule graph, rule ownership, and content identities together with its catalog and trust digests. It also builds candidate indexes from executable names and keywords while retaining unindexed rules as eligible candidates. These indexes reduce normal search work, but they do not change which rules the program can evaluate.

This diagram shows how reviewed source data becomes the immutable runtime program.

flowchart LR
    A[Command-source definitions] --> B[Structural and relationship validation]
    B --> C[Matcher graph lowering]
    C --> D[Typed native node compilation]
    D --> E[Program admission and digest checks]
    E --> F[Packaged native command program]
    F --> G[Native runtime admission]

References: rust/…/native_command_source_catalog.rs• L226-335 rust/…/native_command_source.rs• L142-161 rust/…/native_command_program.rs• L286-321 rust/…/native_command_program.rs• L324-350 rust/…/native_command_program.rs• L374-399

Declarative work measurement

Declarative work measurement reports the scale of one resident request without exposing command text or rule identities. The program records how many extensions were active and how many candidate rules the declarative pass considered and evaluated. A process-wide maximum gives release and scale checks a view of the largest candidate set seen so far.

The per-request values start empty for each resident request. This keeps a request that reaches no controls or runs no declarative pass from inheriting counts from an earlier request on the same worker. These counters describe work only; they do not add authority or change candidate selection.

References: rust/…/native_command_program.rs• L94-116 rust/…/native_command_program_work_stats.rs• L1-62

Compatibility matching

Compatibility matching preserves native coverage that is not expressed as a declarative matcher. The compiler records these rules in the same program and checks that the compatibility inventory matches the catalog's compatibility-only rows. At evaluation time, native observation combines compatibility results with declarative results.

The compatibility evaluator accepts only an exact canonical command model within fixed input bounds. It rejects unsupported path, environment, wrapper, and command context. Git inspection uses verified caller path context when it resolves repository routing. Unsupported or context-free routing remains uncertainty instead of becoming a successful match. A relevant unsupported form produces an owned evaluation error rather than an empty successful observation set.

Candidate selection uses executable and keyword hints when they exist. Unindexed rules remain eligible. The program's candidate indexes are a search aid rather than a policy filter. The evaluator then applies the typed matcher graph with shared bounded work and a deadline. A match records the rule, extension and version identities, affected command segments, and redacted matcher evidence. Safe variants are evaluated per segment, so a safe form in one segment does not suppress a separate unsafe segment.

Executable safe-variant matching checks forbidden flags using both parsed flag presence and effective option names. This keeps assignment forms such as --home=/other from bypassing a forbidden store check. When fail-secure unknown-option handling applies, an accepted long-option abbreviation such as --hom /other also counts as the corresponding forbidden flag. A help or other benign variant therefore remains safe only when it does not redirect the protected store through an alternate spelling.

Compatibility attribution does not by itself lower the command's action floor. Compatibility-only rules provide identity and evidence for existing native behavior. Declarative rules supply native rule coverage, while control state and extension activation determine whether that coverage applies.

References: rust/…/native_command_program.rs• L152-171 rust/…/native_command_program.rs• L286-321 rust/…/native_command_program.rs• L374-381 rust/…/native_command_program_evaluation.rs• L182-333 rust/…/native_command_source_capabilities.rs• L221-247

Native control bindings

Native control bindings connect one exact packaged program to the active local and managed controls. The binding carries program, catalog, and trust digests plus control revisions, health state, effective control digest, and control layers. The resident rejects a binding that names another program or catalog, so controls cannot apply to a different definition set.

The control compiler resolves extension and permission controls against the admitted program. It combines local-admin and signed-cloud layers and activates external extensions only through explicit local enable. Trusted or required extensions follow their catalog status. A global block or an unhealthy control state strengthens the result to block. The first unenrolled baseline is a narrow exception that preserves packaged first-party protection without allowing external activation or permission overrides.

During evaluation, the binding passes verified caller path context into native observation and compound-command permission coverage. A protected control can explicitly enable a configurable permission, but that consent can settle only a generic review when every command segment is covered and the command has no intrinsic sensitive risk. Delegated package and MCP controls can tighten the floor but do not supply allow authority. Evaluation errors and uncertainty produce bounded evidence and strengthen the result to block.

The binding is a policy input, not a source of new matcher behavior. It can enable, disable, or globally restrict entries already present in the program. For the wider authority lifecycle, see Native runtime authority, Native runtime residency and recovery, and Native command catalog and pack lifecycle.

References: rust/…/native_command_controls.rs• L85-188 rust/…/native_command_controls.rs• L230-410 rust/…/native_command_controls_admission.rs• L27-57 rust/…/native_command_controls_floor.rs• L9-23

Evidence contracts

Native evidence is the identity-bound record that explains which admitted rules and permissions influenced a decision. It includes the exact program, catalog, trust, and control identities through a receipt binding. It also includes a digest of observations and bounded counts for observations and uncertainty.

The evidence contract accepts only bounded redacted data. Rule evidence names segment indexes and a safe executable name with a fixed detail string. It checks rule and permission ownership, versions, safe-variant coverage, effective segment indexes, duplicate identities, uncertainty counts, and the observation digest. The receiving layer then binds the evidence to command text, the registry, and the current control snapshot.

When native evaluation fails, the evidence contains no semantic observations and marks the known evaluation error. Runtime handling treats that state as a hard block rather than as proof that the command is safe. A mismatch in program, catalog, control revision, effective control digest, command text, or catalog identity rejects the evidence.

References: rust/…/native_command_controls.rs• L347-410 rust/…/native_command_program_observations.rs• L340-371 src/…/native_command_observations.py• L56-77 src/…/native_command_extension_evidence.py• L86-159

Pack release and composition

Pack release separates source compilation from delivery of large catalogs. A bounded source stream validates every command and MCP record, checks global relationships and the complete compatibility inventory, and emits one release root plus content-addressed objects. The root and selected dependency closure must be authenticated before the packs can become an active program.

The release and load path has three stages:

  1. Build-time ingestion validates framed records and the shared trust input.
  2. Release output stores pack programs, catalogs, descriptors, and indexes in bounded immutable objects. Reuse and caches reduce work but grant no authority.
  3. Runtime admission reads only the selected packs, validates their identities and interfaces, interns shared matcher nodes, and composes one program before controls are applied.

Object hashes prove content integrity, not policy authority. Fetches and filesystem reads occur during admission or release work. They do not occur during command evaluation. The composed program must contain a complete dependency closure and the complete compatibility inventory, and its final digest binds the selected pack identities and compiler implementation.

References: rust/…/native_command_source_stream.rs• L50-135 rust/…/native_command_source_packs.rs• L128-151 rust/…/native_command_source_packs.rs• L242-395 rust/…/native_command_program_collection_reader.rs• L33-110 rust/…/native_command_program_collection.rs• L6-102 rust/…/native_command_pack_objects.rs• L43-135

Offline evaluation and parity

Offline evaluation checks packaged behavior without granting persisted authority or executing target commands. A bounded batch reuses the production parser, packaged program, and synthetic control snapshot for up to 256 command cases. The request must use the batch schema, contain unique bounded case IDs, and contain at least one case. Unknown or duplicate fields are rejected. Optional home and working-directory paths are bounded, and an execution environment is accepted only when both paths are present.

The synthetic snapshot can model local and managed controls, global lockdown, caller path context, execution environment, and authority health. It can also model the first-install state through an explicit never_enrolled binding. A health value of unenrolled without that binding represents lost authority and blocks every command. The first-install binding accepts only an unenrolled, empty, revision-zero snapshot, so it preserves packaged first-party protection without accepting synthetic controls. Managed controls can override local controls through the same binding rules used by the production path.

Each case uses production parsing and carries its command model with the evaluation payload. A command that exceeds the production command limit remains a case result with a parsed uncertainty model rather than making the batch request invalid. The result includes program and catalog identity, the synthetic control binding, observations, and explicit zero command execution. It is marked as an offline simulation rather than an authenticated receipt. Case IDs are unique and bounded, while command size behavior remains owned by the production parser.

Fixture checks use the packaged program as the authority for an already admitted extension. They accept a fixture only when the supplied source reproduces the packaged extension, rules, coverage, and matcher nodes. A request that mixes replacement and addition is rejected rather than silently treating a changed packaged extension as new. Parity checks compare full native evidence and report a real artifact difference when source changes alter the candidate result.

This flow keeps offline corpus and fixture checks useful without making their synthetic controls or results an authorization source.

References: rust/…/native_command_source_evaluation_batch.rs• L8-200 rust/…/native_command_source_fixture_catalog.rs• L18-79 rust/…/native_command_source_fixture_catalog.rs• L103-141 rust/…/native_command_source_tests.rs• L130-224

Build and release boundary

The source compiler runs during build or release work, not during hook evaluation. It reads reviewed command and MCP source catalogs plus the trust map. It writes the catalog projection, packaged program, descriptors, and their source and implementation identities. The resident loads the exact packaged artifact and exposes its program, catalog, and trust digests as its identity. Program admission checks the generated artifact before it can be used.

The complete catalog is the release form. Additive onboarding uses the packaged program as an immutable base. It can add extensions and nodes, but it cannot replace an existing extension or change an existing node identity. The resulting projection is marked as addition-only and is not a release catalog. The compiled artifact also binds source semantics to an implementation digest, so a change in either source meaning or compiler behavior produces a new program identity.

Offline fixture compilation is a separate test path. It may reuse the packaged program for an exact existing extension, but it does not change the packaged artifact or runtime authority. This boundary keeps source authoring, offline proof, release generation, and runtime admission separate.

References: rust/…/native_command_source.rs• L83-136 rust/…/native_command_source_catalog.rs• L331-369 rust/…/native_command_source_catalog.rs• L372-457 rust/…/native_command_source_addition.rs• L19-89 rust/…/native_command_program.rs• L60-84 rust/…/native_command_program.rs• L302-321

Change checklist

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

  • When a source field or rule relationship changes, regenerate the source projection, descriptors, catalog, native program, and any affected pack root together. Their digests and generated identities must remain aligned.
  • When a matcher operation or configuration changes, update source lowering, packaged-program admission, and pack composition. A source that compiles but cannot be admitted by the resident is not usable.
  • When a compatibility rule changes, update the closed capability table and compatibility inventory. Complete program and collection admission require the two sets to match.
  • When pack object, index, cache, or selection schemas change, preserve independent release-root authentication, bounded reads, dependency closure, and the rule that fetches stop before evaluation.
  • When offline batch or fixture schemas change, preserve bounded decoding, unique case identity, valid synthetic control and health bindings, first-install invariants, production pretool and parser parity, zero command execution, and the non-authoritative simulation label.
  • When compatibility model limits, unsupported contexts, deadlines, or caller path rules change, preserve the owned error path. Do not turn uncertainty into an empty successful observation set.
  • When native pretool precedence changes, preserve the strengthening relationship between the base command decision and extension control floors. A later control must not weaken a prior native block or reapproval requirement.
  • When evidence fields or safe-variant behavior changes, update native observation and receiving evidence validation together. The observation digest and effective segment indexes are part of the contract.
  • When candidate indexes or executable-gate logic change, preserve the eligibility of unindexed rules and the rule that indexes narrow search work without narrowing policy coverage.
  • When declarative work counters change, preserve per-request reset behavior and keep the measurements free of command text and rule identities. These counters must remain diagnostic rather than authoritative.
  • When the packaged artifact or default pack selection changes, refresh the embedded copy and verify that required first-party protection and control bindings name the new program and catalog digests.

Important failure modes

TriggerConsequenceGuard
A build envelope has an unsupported schema, missing packaged validation base, unknown operation, malformed configuration, or invalid matcher tree.Compilation stops before a native program is produced.The source entry point validates the owned envelope and base requirements. Source lowering and typed node compilation reject unknown operations, bad children, invalid configuration, and graph cycles or depth overflow.
A permission, rule, extension dependency, or conflict points to an unknown or conflicting identity.The catalog cannot be admitted.Relationship validation checks ownership, duplicate IDs, reciprocal conflicts, replacements, and bounded acyclic dependency graphs.
A compatibility rule is missing from the closed capability inventory or has a different owner.Program or pack collection admission fails instead of silently changing compatibility coverage.Native program admission compares catalog compatibility-only rules with the native compatibility inventory.
The canonical command model is unsupported, exceeds compatibility limits, or reaches its deadline.Native extension evaluation produces no semantic observations and the control result strengthens to block.Compatibility matching returns an owned error; control binding records evaluation failure and fails closed.
A context-free or unverified Git path is used for inspection or permission coverage.The command keeps review or uncertainty instead of gaining a false safe attribution.Pretool and compatibility matching require verified caller path context and carry it through native controls.
A control binding names a different program, catalog, trust set, or control snapshot.Controls are rejected and cannot authorize the wrong catalog.Binding validation compares program identities, control revisions, and the effective digest.
A pack cache, object, index, or selected dependency closure is altered or incomplete.Pack admission fails before the collection can be published.Authenticated release roots, content hashes, bounded object reads, and complete dependency checks are required.
An executable or keyword candidate index omits a rule that has no index entry.A valid rule could be skipped during candidate selection.Unindexed rules remain eligible, and candidate indexes are treated as search hints rather than authority filters.
An MCP source uses an unsafe launcher form or collides with another command, package, endpoint, or alias.The contribution is rejected before it can add a native permission.MCP lowering applies canonical launch rules and validates the complete launch inventory.
An offline request has no cases, duplicate or malformed IDs, unknown fields, invalid context, invalid health, contradictory first-install fields, more than 256 cases, or exceeds the input byte limit.The batch is rejected before evaluation.The batch contract denies unknown fields, bounds the request and context, validates health and first-install invariants, requires unique IDs, and limits the input and case count.
Offline evaluation reaches a production parse or native evaluation error, or a caller supplies a command beyond the production size limit.The case returns conservative error evidence or a blocked result while the batch remains a non-authoritative simulation.Each case uses the production parser and control path. Results report the command model, bound identities, and target_commands_executed: 0.
Evidence has unknown identities, altered segment indexes, or a wrong observation digest.The evidence is rejected and cannot prove a safe or unsafe match.The wire contract checks identity ownership, redaction shape, counts, effective indexes, and the canonical digest.

Key files

FileWhy to read it
rust/…/native_command_source.rsDefines the owned build envelope, matcher-only compiler, and build-time source, stream, pack, offline, and parity boundaries.
rust/…/native_command_source_catalog.rsShows how validated sources become catalog, descriptor, trust, coverage, and program projections.
rust/…/native_command_source_validation.rsShows source admission rules and cross-document relationship checks.
rust/…/native_command_source_mcp.rsShows how canonical MCP contributions become opt-in native permissions and how launch identities stay unique.
rust/…/native_command_source_capabilities.rsDefines the closed ownership map for compatibility-only native rules.
rust/…/native_command_program.rsDefines the immutable packaged program, its content identities, embedded loading, candidate indexes, runtime coverage, and native matcher model.
rust/…/native_command_program_admission.rsDefines packaged and independently admitted pack validation, matcher coverage, and compatibility inventory checks.
rust/…/native_command_program_collection.rsDefines composition of admitted one-extension packs into one active program.
rust/…/native_command_pack_objects.rsDefines bounded content-addressed objects and authenticated index lookups.
rust/…/native_command_program_work_stats.rsDefines bounded per-request and process-wide measures for declarative candidate work.
rust/…/pretool.rsDefines the native base decision that extension controls can strengthen.
rust/…/native_command_controls.rsApplies the bound program and control snapshot to observations and action floors.
rust/…/native_command_source_evaluation_batch.rsDefines bounded offline evaluation with production parsing, synthetic controls, health binding, first-install behavior, and zero command execution.
rust/…/native_command_source_tests.rsDemonstrates artifact identity, control effects, packaged parity, and MCP admission guarantees.
src/…/native_command_observations.pyDefines the receiving-side observation and receipt contract.
src/…/native_command_extension_evidence.pyProjects validated native evidence onto the command extension registry.