Skip to main content

Module decisions

Module decisions 

Source
Expand description

Decision layer (D1): versioned project decisions in .leanctx/decisions/*.toml.

A decision record names what was decided, by whom, where it applies (repos, path globs, symbols) and, optionally, machine-checkable [[check]]s. This module loads and validates the records (strictly: an unknown key, a bad glob or a bad regex is an error naming the file), answers scope queries and renders the deterministic context suffix for reads (#498: no timestamps, no counters, stable header, sorted by id). check evaluates the checks against a change; crate::core::pre_edit runs them before an edit.

LeanCTX only detects, reports and hints. Refusing an edit is opt-in ([decisions] enforce = "refuse"); enforcing a land belongs to Weave.

Re-exports§

pub use check::OtherFiles;
pub use check::Violation;
pub use check::evaluate_change;
pub use check::evaluate_change_with;

Modules§

check
Evaluate decision [[check]]s against one file change.

Structs§

Check
A validated [[check]]. paths empty means “the decision’s scope”.
Decision
A validated decision record.
DecisionSet
Every record of one project, sorted by id, plus the files that failed.

Enums§

CheckKind
Status

Constants§

DECISIONS_DIR
Directory, relative to the project root, that holds one record per file.
SUFFIX_HEADER
Header of the read/compose suffix. Stable: prompt caches key on it.

Functions§

describe
Full, multi-line description of one decision (CLI show, ctx_knowledge).
find_root
The nearest ancestor of path (itself included when a directory) that holds a .leanctx/decisions directory, stopping at the first git root.
from_records
A set from record texts ((root-relative file, text or read error)), e.g. read from a base commit. repo_root answers scope.repos. The set knows no working tree, so require_regex needs an explicit check::OtherFiles (evaluate_change_with).
id_from_slug
dec-<slug> from free text: lower-case ASCII words joined by -.
load
Load (cached by file list, sizes and mtimes) the records under root. A project without .leanctx/decisions yields an empty set.
parse_decision
Parse and validate one record. file_stem must equal the record’s id; rel_file is kept for reporting. Errors name the offending key.
query_text
The decision query of ctx_knowledge action=decisions and lean-ctx decisions list: by path (decisions whose scope covers it), else by symbol, else all records; invalid records are listed after them.
relative_path
path relative to root with forward slashes; None outside root.
render_lines
One line per decision: id: title — statement.
scaffold
A fresh record for lean-ctx decisions new that parses as written.
suffix_for_compose
The suffix for a ctx_compose answer: decisions covering the files it names (path:line … and File: path lines that exist under root).
suffix_for_file
The suffix for a read of file (absolute or root-relative). Empty when the file is outside every project with decisions.
suffix_for_paths
Deterministic suffix for a read of rel_paths (deduplicated, sorted): empty when no active decision covers any of them.
suffix_for_read
The read suffix for a tool reply (ctx_read, ctx_compose): empty while a gateway policy is active, since decision records are repository text that the policy did not admit as a source of this reply.
suffix_for_root_paths
The suffix for paths a compose answer named, relative to root.