//! What makes a memory sentence TECHNICAL — and where it goes instead.//!//! Memory is the owner's own words: beliefs, direction, preferences. The test//! for a sentence is whether the owner would say it himself, and whether a//! future pull request could make it false. The second kind never goes in//! memory; it goes in the repository, beside the code a change would make it//! false about, and is never briefed.//!//! The server cannot read intent, so it refuses on three marks a sentence in//! the owner's voice does not carry and an agent's technical note almost always//! does: a citation of one pull request, a file path, or a workflow name.//! "Write PR descriptions for the reviewer" is the owner's; "the pre-push hook//! is a real gate (#1035)" is an agent's decision. A machine-scoped entry (a//! fact true of one computer) may name a path on that computer, so the path//! mark is not applied to it; the pull request mark still is.use std::sync::LazyLock;use regex::Regex;/// Which mark a sentence carries.#[derive(Debug, Clone, Copy, PartialEq, Eq)]pubenumTechnicalMark {PullRequest,FilePath,Workflow,}implTechnicalMark {/// Its line in the `refusal` set's `memory.technical` lines.pubfn line(self) -> &'static str {matchself {TechnicalMark::PullRequest => "memory.technical.pull_request",TechnicalMark::FilePath => "memory.technical.file_path",TechnicalMark::Workflow => "memory.technical.workflow", } }}/// `#1025`, `PR 1025`, `pull request #1025`, `/pulls/1025`.static PULL_REQUEST: LazyLock<Regex> = LazyLock::new(|| {Regex::new(r"(?i)(?:^|[^\w&])#\d{2,}\b|\b(?:pr|pull request|pull)\s*#?\d{2,}\b|/pulls?/\d+") .expect("pull request pattern")});/// A path with a directory and an extension (`lib/remote.sh`), a/// path under one of the repository's roots (`crates/cotton-core/`), or a bare/// source or config file name (`forge.ts`, `Cargo.toml`).static FILE_PATH: LazyLock<Regex> = LazyLock::new(|| {Regex::new(concat!(r"[\w.~-]+/[\w./-]*\.[A-Za-z]{1,5}\b",r"|(?:^|[\s`(])\.?(?:crates|apps|scripts|packages|infra|docs|forgejo|github|cottondb)/",r"|\b[\w-]+\.(?:rs|ts|tsx|js|mjs|swift|kt|kts|sh|py|toml|json|sql|lock|plist|xcconfig)\b", )) .expect("file path pattern")});/// `verify-main.yml`, `release.yaml`, `workflow_dispatch`.static WORKFLOW: LazyLock<Regex> = LazyLock::new(|| {Regex::new(r"(?i)\b[\w-]+\.ya?ml\b|\bworkflow_dispatch\b").expect("workflow pattern")});/// The first technical mark `title` carries, or `None` when it reads as the/// owner's own words. `machine_scoped` exempts the path mark.pubfn technical_mark(title: &str, machine_scoped: bool) -> Option<TechnicalMark> {if PULL_REQUEST.is_match(title) {returnSome(TechnicalMark::PullRequest); }if WORKFLOW.is_match(title) {returnSome(TechnicalMark::Workflow); }if !machine_scoped && FILE_PATH.is_match(title) {returnSome(TechnicalMark::FilePath); }None}