validate

package
v0.7.30 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 7, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

The S1 half of local/remote validation parity.

Without it, `agentry validate` would run only the manifest V-rules and the S3/S4 content scan. That leaves a real gap: a committed .dylib, a vendored tarball, or a Latin-1 README passes locally and is rejected by the server's S1 inventory at submit — the "works on my machine, fails at publish" round-trip that parity exists to prevent.

This file closes that gap by running the same three S1 checks the pipeline runs, over the resolved include set, with the same severities:

S1/binary-executable  critical  content-sniffed ELF/Mach-O/PE/class
S1/nested-archive     critical  content-sniffed zip/gzip/zstd/bzip2/xz/tar
S1/non-utf8           low       text file that is not valid UTF-8

Detection is by MAGIC BYTES, never by extension: renaming evil.so to notes.md is the first thing anyone tries, and the server is not fooled by it either.

The fourth S1-adjacent check, oversized files against the archive quotas — is deliberately NOT repeated here: manifest rule V8 already enforces MaxFiles/MaxFileBytes/MaxImageFileBytes/MaxArchiveBytes over the same resolved include set, in the same command, and reporting one oversized file twice would make the output worse rather than safer.

Parity is by construction: the detection predicates are pkg/archive's, the ones the server's S1 stage classifies with (below).

Package validate is `agentry validate`'s workspace check: offline parity with the server's submit validation — every manifest rule pkg/manifest reports (ManifestRules), the S1 inventory subset (localscan.go), and the S3/S4 scan via pkg/rules, run over the files publish would actually ship. It lives outside the command's main package so that the Drafter's post-step (pkg/drafter) checks a draft with the same code in every client: `agentry validate`, `agentry draft` and the desktop's draft on this computer write one report, the `validate --json` shape.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Embedded

func Embedded() (*rules.Bundle, string, error)

Embedded is the S4 bundle embedded in this binary, the floor every client validates under.

func ManifestRules

func ManifestRules() string

ManifestRules names the manifest rules a validation runs, in the form the report and the command's help print them ("V1-V5, V7-V11"). It is read from pkg/manifest's own rule list, so a rule the core adds is named here without a change in this repository.

func ReadManifest

func ReadManifest(dir string) (*manifest.Manifest, error)

ReadManifest loads and parses dir/agent.yaml.

Types

type Finding

type Finding struct {
	RuleID     string            `json:"ruleId"`
	Scanner    string            `json:"scanner"`
	Severity   string            `json:"severity"`
	Confidence string            `json:"confidence"`
	Title      string            `json:"title"`
	FilePath   string            `json:"filePath"`
	LineStart  int               `json:"lineStart,omitempty"`
	LineEnd    int               `json:"lineEnd,omitempty"`
	Excerpt    string            `json:"excerpt,omitempty"`
	Detail     map[string]string `json:"detail,omitempty"`
}

Finding is one S3/S4 scanner hit.

type InventoryFinding

type InventoryFinding struct {
	Scanner  string `json:"scanner"`
	Severity string `json:"severity"`
	Title    string `json:"title"`
	FilePath string `json:"filePath"`
	Detail   string `json:"detail,omitempty"`
}

InventoryFinding is one S1-subset result.

type Issue

type Issue struct {
	Rule     string `json:"rule"`
	Severity string `json:"severity"`
	Path     string `json:"path,omitempty"`
	Message  string `json:"message"`
}

Issue is one manifest rule's result.

type Manifest

type Manifest struct {
	Namespace     string   `json:"namespace"`
	Name          string   `json:"name"`
	Version       string   `json:"version"`
	SchemaVersion int      `json:"schemaVersion"`
	Modes         []string `json:"modes"`
}

Manifest is the report's header: what agent.yaml said about itself.

type Options

type Options struct {
	// Strict treats manifest warnings as errors.
	Strict bool
	// Out is the narration, ErrOut its notes; nil discards them.
	Out, ErrOut io.Writer
	// Rules loads the S4 signature bundle and says where it came from; nil
	// is the bundle embedded in this binary (Embedded). A loader that fails
	// fails the check: it never passes content S4 did not examine.
	Rules RulesLoader
}

Options are how a workspace is checked.

type Report

type Report struct {
	Passed bool `json:"passed"`
	// Manifest is what agent.yaml said about itself.
	Manifest Manifest `json:"manifest"`
	// Issues are the manifest rules' results, errors and warnings.
	Issues []Issue `json:"issues"`
	// Inventory is the S1 subset over the resolved include set.
	Inventory []InventoryFinding `json:"inventory"`
	// Findings are the S3/S4 scanner hits.
	Findings []Finding `json:"findings"`
	// ReadErrors are include-set files that could not be read.
	ReadErrors []string `json:"readErrors"`
	FileCount  int      `json:"fileCount"`
	Bundle     struct {
		Version string `json:"version"`
		Source  string `json:"source"`
	} `json:"bundle"`
	Counts struct {
		Errors           int `json:"errors"`
		Warnings         int `json:"warnings"`
		InventoryFailing int `json:"inventoryFailing"`
		Findings         int `json:"findings"`
	} `json:"counts"`
	Strict bool `json:"strict"`
}

Report is the `validate --json` shape: the rules and scan findings as data, and the verdict `publish` would reach. A draft's draft.json carries it as its validation.

func Workspace

func Workspace(dir string, o Options) (Report, error)

Workspace is the validation itself, narrated to o.Out (notes to o.ErrOut): the report `validate --json` prints, and what a draft's post-step writes into the draft. An error is a validation that could not run (no manifest, a rule bundle that will not load), never a failed one.

type RulesLoader

type RulesLoader func() (*rules.Bundle, string, error)

RulesLoader loads the S4 signature bundle and says where it came from.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL