Skip to main content

Module agent_rules

Module agent_rules 

Source
Expand description

Agent-rules projection (decided.services.agent_rules) — decided export --agent-rules [--check], per PORT-CONTRACT.d/17 §3.

Distils the live corpus (Accepted, non-retired decisions) into a drift-guarded managed block spliced into per-client agent-context files. The provenance digest is sha256 over the canonical JSON serialization of the ordered entries (sort_keys, separators (",", ":"), ensure_ascii=False) — any byte deviation cascades into --check drift, so the canonical dump must match CPython exactly (pyjson::dumps_canonical_sorted).

Structs§

AgentRulesFileResult
AgentRulesResult
The outcome of a generate or check run (mirrors AgentRulesResult).
AgentRulesTarget
One per-client target file (selector + root-relative path), in the oracle’s fixed TARGETS order.

Constants§

STATE_IN_SYNC
STATE_MISSING
STATE_STALE
STATE_UPDATED
STATE_WRITTEN
TARGETS

Functions§

agent_rules_root
_agent_rules_root(directory, out) — explicit --out wins; else the parent of a decisions/-named directory (or . when that parent is .), else the directory itself.
check_agent_rules
check_agent_rules(directory, root, clients) — never writes; compares each present target’s embedded digest to the live projection.
generate_agent_rules
generate_agent_rules(directory, root, clients) — write/update the managed block in each target under root. Writes are skipped when the embedded digest already matches (idempotent). An io error surfaces as Err for the caller’s cannot write under {root} usage error.
py_path_str
str(PurePosixPath(p)): duplicate slashes and . components collapse, a trailing slash drops, "" becomes "."; a leading // (exactly two slashes) is preserved, /+ otherwise collapses to one.