Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

requirements.cli.distributed_guidance

Requirements index · View definition

evidence Valid

Requirement

Habeas’s bundled agent skills MUST explain distributed requirements under cite requirements.references.distributed.

Rationale

Obligation. requirements.cli.distributed_guidance says the bundled agent skills MUST explain distributed requirements as requirements.references.distributed defines them. The explanation lives in assets/skills/habeas/references/distributed-requirements.md. The habeas SKILL.md routes agents to it.

Test. tests/authoring_cli.rs#fn[bundled_skills_explain_distributed_requirements] is marked {test} for the subject. It loads the reference through distributed_reference and skill_file. It collapses whitespace with collapse, so wrapped lines still match. Its assertion helpers (assert_phrases, assert_text_in_order, assert_text) panic when a phrase is missing, so each check is enforced.

Mapping from the distributed requirement’s explainable parts to assertions. I read the reference file, and every asserted phrase appears in it.

  • Routing from the habeas skill. assert_phrases("habeas", …) requires the skill to say “read references/distributed-requirements.md before drafting it”.
  • What a distributed requirement is, in order. The ordered check covers these in sequence:
    • the # Distributed requirements heading and the statement that queries find sites and each site is reviewed separately;
    • the ## Queries heading and the {sites} and {violations} query kinds;
    • the within requirement for violation queries;
    • the list of body keys, ending with within, match and no_match;
    • “Each site-query match makes a site”.
  • Query contract. assert_text checks these against the reference:
    • one fenced yaml block per query;
    • a name that is a single identifier and unique across both query kinds;
    • the language list;
    • optional paths and exclude;
    • an ast-grep rule with utils and constraints;
    • within only for violation queries;
    • that only matches inside the site query’s sites count;
    • that a violation match is reported to the site containing it.
  • Validation failures. The same assert_text call checks these errors:
    • a query directive outside a requirement;
    • invalid YAML;
    • unknown keys;
    • a nonexistent site query;
    • unsupported languages;
    • rules that cannot compile;
    • empty match or no_match lists;
    • snippets that fail to parse or have the wrong match result;
    • a violation query without a site query;
    • a site query that matches nothing in the project.
  • Snippet semantics. It checks that match snippets cover what a query selects and no_match snippets cover nearby code it must not select. It also checks that habeas coverage runs every snippet.
  • Site reviews and references. It checks that sites need no reference (“Don’t reference the distributed requirement from a site just because it is a site”) and that a site review covers the site for Rust item coverage. It also checks that habeas author --all authors a site review for each site.

Remaining gaps. None that matter.

  • The test does not assert two details in the requirement’s text: the “innermost outline node” wording, and that sites are the distinct sites of all queries. The reference does state the innermost-node rule, and the ordered “Each site-query match makes a site” check still covers the site-making rule.
  • The requirement’s rules on ast-grep upgrades and badge rendering are maintainer-facing and need no agent guidance.
  • The refinements (.when, .queries, .site_text, .reviews, .lists, .bootstrap) are tested by their own {test} functions and are not assessed here.

Conclusion. The test covers the explainable parts of the cited requirement with real assertions, so I judge it adequate.

Inputs

Implementation

Input 4: outline assets/skills/habeas/references/distributed-requirements.md section[Distributed%20requirements]
# Distributed requirements

Some obligations apply on their own at each of many sites, such as a convention
every validation function follows. Marking every site `{impl}` spreads the
requirement across the codebase and asks one review to judge them all. A
distributed requirement instead declares queries that find its sites, and
Habeas reviews each site separately.

## Queries

A requirement becomes distributed by containing query directives, each with one
fenced `yaml` block and a name unique within the requirement:

- `:::{sites} <name>` selects the places the obligation applies.
- `:::{violations} <name>` selects constructs likely to break it, such as `?`,
  `return`, `continue`, or `break` in a function that must keep going after a
  failed check. Each needs `within: <site query>`, naming a site query of the same
  requirement; only matches inside that query's sites count. Violation queries
  point site reviews at likely problems; each site's review still judges the
  whole site, and a violation query that misses a construct does not by itself
  make the requirement false.

Query directives belong inside a requirement. Each name is a single identifier
(ASCII letters, digits, underscores, or hyphens), unique across both query kinds in
that requirement. Validation reports missing or extra YAML blocks, invalid YAML,
unknown query keys, unsupported languages, and rules that cannot compile. A
violation query naming a nonexistent site query in `within` is also invalid;
`within` belongs only to violation queries.
Validation also rejects empty `match` or `no_match` lists, snippets that fail to
parse or have the wrong match result, and violation queries without a site query.

Each body has these keys: `language` (`rust`, `python`, `typescript`, `tsx`,
`css`, `markdown`, `toml`, or `yaml`); optional `paths` and `exclude`, lists of
project-relative files or directories; an ast-grep `rule`, with optional `utils`
and `constraints`; `within`, required for violation queries; and `match` and
`no_match` snippet lists. Give the requirement a longer outer fence:

````text
::::{req} errors
A validation function that collects validation errors MUST hold them in a
parameter or local variable named `errors`, and a function with such a variable
is a site. After one of its checks fails, a site MUST still run every later check
that does not depend on the failed check's result.

:::{sites} error_accumulators
```yaml
language: rust
paths: [src]
rule:
  kind: function_item
  has:
    stopBy: { kind: function_item }
    any:
      - kind: parameter
        has: { field: pattern, regex: "^errors$" }
      - kind: let_declaration
        has: { field: pattern, regex: "^errors$" }
match:
  - "fn check(value: &str, errors: &mut Vec<String>) {}"
  - |
    fn run() {
        let mut errors = Vec::new();
        check("", &mut errors);
    }
no_match:
  - "fn check(value: &str, problems: &mut Vec<String>) {}"
  - |
    fn run() {
        let mut problems = Vec::new();
        check("", &mut problems);
    }
```
:::

:::{violations} early_exits
```yaml
language: rust
paths: [src]
within: error_accumulators
rule:
  any:
    - kind: try_expression
    - kind: return_expression
match:
  - |
    fn check(v: &Value, errors: &mut Vec<String>) -> Option<u8> {
        let n = v.as_u64()?;
        if v.is_null() { errors.push("null".into()); }
        Some(n as u8)
    }
  - |
    fn check(v: &Value, errors: &mut Vec<String>) {
        if !v.is_object() { errors.push("object".into()); return; }
        if v.is_null() { errors.push("null".into()); }
    }
no_match:
  - |
    fn parse(v: &Value) -> Option<u8> {
        let n = v.as_u64()?;
        Some(n as u8)
    }
  - |
    fn check(v: &Value, errors: &mut Vec<String>) {
        if v.is_null() { errors.push("null".into()); }
    }
```
:::
::::
````

Each site-query match makes a site: the innermost outline node containing the
match, such as the enclosing function. A violation match is reported to the site
that contains it.

## Do

- Make a requirement distributed only when its obligation applies on its own at
  each site; when particular code carries out the requirement as a whole, use
  `{impl}` there.
- Describe sites exactly as the site queries select them. When a query relies on
  a convention, such as how a variable is named, state the convention as an
  obligation, so code that breaks it is a real gap you fix in the code.
- Separate obligations each site upholds from obligations particular code
  carries out, and mark that code `{impl}`.
- State the requirement's scope in its text, and use `paths` and `exclude` for
  scope a rule cannot see, such as authoring code outside validation.
- Give every query `match` and `no_match` snippets that test its conditions the
  way you would test code: `match` snippets for what it selects, and `no_match`
  snippets for nearby code it must not select, such as the right type with the
  wrong name. A condition needs no snippet of its own. This applies to violation
  queries too.
- Write a violation query, with `within` naming the site query, for every kind
  of construct that could break the obligation, such as each early exit in a
  function that must keep going.
- Before the habeas-requirements review (its step 3), check that the site
  queries select every place the obligation
  applies and no others: think about places they could miss, such as a list
  held in a local variable or under another name, and places they select that
  the obligation does not cover. Widen or narrow the query, or state the
  convention as an obligation so a miss becomes a code gap. The requirement's
  review searches for both.
- Present the queries and snippets with the requirement text when reviewing it
  with the user.
- Check with `habeas info <full-name>` that the sites are the ones you expect.
- Let `habeas author --all` author the site reviews.

## Don't

- Don't describe sites more broadly than the queries select, as in "however it is
  named".
- Don't state a per-site obligation that a reviewer cannot check from the site
  and the helpers it calls, such as "not reported by another check", which needs
  reading other sites; narrow it to the site, such as "does not report one
  failure twice".
- Don't reference the distributed requirement from a site just because it is a
  site; sites need none. A site review reads its site, which covers it for Rust
  item coverage, but a site that is a root of another requirement gets
  `{impl}` of that one, and a site that carries out one of this requirement's
  other obligations, such as the function that reports the collected errors,
  gets `{impl}` of this one like any other root.
- Don't re-run a false site review for a different result; fix the site, or
  tighten the queries or the text, as the habeas-evidence skill's
  `references/reviews.md` describes.

## Gotchas

- Patterns parse as standalone code, so a type or parameter fragment needs
  ast-grep's `context` and `selector` form, such as
  `{ context: "fn f(x: &mut Vec<String>) {}", selector: reference_type }`. A plain
  pattern that parses differently silently matches nothing; the snippets catch
  this.
- Each snippet parses as a whole file, so a Rust snippet must be complete items,
  not a bare expression.
- `habeas coverage` runs every snippet and reports a wrong result, and a
  site query that matches nothing in the project.

## Review

`habeas author --all` authors a site review for each site, judging the per-site
obligations and each violation match in it. The requirement's own review checks
the Do list above.

Tests

Input 3: outline tests/authoring_cli.rs fn[bundled_skills_explain_distributed_requirements]
// {test}`requirements.cli.distributed_guidance`
#[test]
fn bundled_skills_explain_distributed_requirements() {
    assert_phrases(
        "habeas",
        &[
            "read [references/distributed-requirements.md](references/distributed-requirements.md) before drafting it",
        ],
    );
    // What they are, the two query kinds, and each query's keys.
    assert_text_in_order(
        "distributed requirements",
        &collapse(distributed_reference()),
        &[
            "# Distributed requirements",
            "A distributed requirement instead declares queries that find its sites, and Habeas reviews each site separately",
            "## Queries",
            "`:::{sites} <name>` selects the places the obligation applies",
            "`:::{violations} <name>` selects constructs likely to break it",
            "Each needs `within: <site query>`",
            "Each body has these keys: `language`",
            "`within`, required for violation queries; and `match` and `no_match` snippet lists",
            "Each site-query match makes a site",
        ],
    );
    assert_text(
        "distributed query contract",
        &collapse(distributed_reference()),
        &[
            "one fenced `yaml` block and a name unique within the requirement",
            "`css`, `markdown`, `toml`, or `yaml`",
            "optional `paths` and `exclude`, lists of project-relative files or directories",
            "an ast-grep `rule`, with optional `utils` and `constraints`",
            "A violation match is reported to the site that contains it",
            "Don't reference the distributed requirement from a site just because it is a site",
            "A site review reads its site, which covers it for Rust item coverage",
            "`habeas author --all` authors a site review for each site",
            "`habeas coverage` runs every snippet",
            "Query directives belong inside a requirement",
            "a single identifier",
            "invalid YAML",
            "unknown query keys",
            "a nonexistent site query",
            "unique across both query kinds",
            "`within` belongs only to violation queries",
            "unsupported languages",
            "rules that cannot compile",
            "empty `match` or `no_match` lists",
            "snippets that fail to parse or have the wrong match result",
            "violation queries without a site query",
            "only matches inside that query's sites count",
            "`match` snippets for what it selects",
            "`no_match` snippets for nearby code it must not select",
            "a site query that matches nothing in the project",
        ],
    );
}

Referenced definitions

Input 2: requirements selection requirements.references.distributed
:::{req} distributed
A requirement MAY be distributed: it states obligations that each of many sites
in the sources must uphold on its own, such as a convention every validation
function follows, and MAY also state obligations that particular code carries
out, which that code implements with `{impl}`. A `{req}` body declares a distributed requirement
by containing one or more nested query directives: `:::{sites} <name>` for a
site query, which finds the places the obligation applies, or
`:::{violations} <name>` for a violation query, which finds constructs likely to
break it. A requirement with a violation query MUST also have a site query.
Query names MUST be single identifier segments under
{cite}`requirements.ci.identifiers`, unique within the requirement. A query
directive outside a `{req}` body MUST be a validation error. Each query body
MUST be one fenced `yaml` code block containing a mapping with only these keys:

- `language`, required: the name of an outline profile with a grammar under
  {cite}`requirements.references.outlines`: `rust`, `python`, `typescript`,
  `tsx`, `css`, `markdown`, `toml`, or `yaml`.
- `paths`, optional: project-relative files or directories. Only sources at or
  under one of them are searched; without it, every source of the language is.
- `exclude`, optional: project-relative files or directories whose sources are
  not searched, even under `paths`.
- `rule`, required, with optional `utils` and `constraints`: an ast-grep rule
  core in the syntax of Habeas's pinned `ast-grep-config` version, matched
  against the language's pinned grammar.
- `within`, required for violation queries and not allowed for site queries:
  the name of a site query in the same requirement.
- `match` and `no_match`, required: nonempty lists of source snippets in the
  query's language. Each `match` snippet MUST contain at least one match of the
  query, and each `no_match` snippet none, where a violation query counts only matches inside a site of its `within` query in the same snippet.

Validation MUST report a query whose body is not such a mapping, whose rule does
not compile, whose `within` names no site query of the requirement, a violation query without `within`, or one of whose snippets fails to parse or has the wrong match result, and a site query
that matches nothing in the project. Queries MUST search exactly the sources
reference discovery considers under {cite}`requirements.references.discovery`, in
their original text.

A match's site MUST be the innermost outline node, under
{cite}`requirements.references.outlines`, whose range contains the match; for a violation query, it MUST instead be the innermost site of its `within` query that contains the match, and a match inside none of that query's
sites MUST be discarded. A requirement's sites MUST be the distinct sites of all
its queries' matches. Each site MUST have a site review under
{cite}`requirements.references.site_review`, and needs no reference to the
requirement; being a site MUST NOT count as a reference for
{cite}`requirements.references.rust_item_coverage`, because a distributed
requirement concerns a cross-cutting obligation, not why the item exists.
Upgrading `ast-grep-config` MAY change matches and MUST be treated as a
deliberate change. The book MUST render each query directive as a badge
naming its kind and name, followed by its code block.
:::

Other sources

Input 1: requirements selection requirements.cli.distributed_guidance
:::{req} distributed_guidance
Habeas's bundled agent skills MUST explain distributed requirements under {cite}`requirements.references.distributed`.
:::
Input 5: requirements selection requirements.cli.distributed_guidance*
:::{req} distributed_guidance
Habeas's bundled agent skills MUST explain distributed requirements under {cite}`requirements.references.distributed`.
:::

:::{req} distributed_guidance.bootstrap
The `habeas-bootstrap-requirements` skill MUST direct agents to propose a distributed requirement for a cross-cutting convention instead of marking each of its sites with `{impl}`.
:::

:::{req} distributed_guidance.lists
The `habeas` skill's reference on distributed requirements MUST give the guidance of {cite}`requirements.cli.distributed_guidance.when`, {cite}`requirements.cli.distributed_guidance.queries`, {cite}`requirements.cli.distributed_guidance.site_text`, and {cite}`requirements.cli.distributed_guidance.reviews` as a list of things to do and a list of things not to do.
:::

:::{req} distributed_guidance.queries
The bundled skills MUST direct agents to write site queries that select every place the obligation applies and no others, violation queries for every kind of construct that could break it, and, for every query, `match` and `no_match` snippets that test its conditions.
:::

:::{req} distributed_guidance.reviews
The bundled skills MUST tell agents that sites need no reference to the requirement, that `habeas author --all` authors site reviews under {cite}`requirements.references.site_review`, and that a false site review is addressed by fixing the site, or by tightening the queries or the requirement text when the site should not be covered or the text admits more than one reading, under {cite}`requirements.cli.flip_guidance`, not by re-running the review.
:::

:::{req} distributed_guidance.site_text
The bundled skills MUST direct agents to describe sites exactly as the site queries select them, to state as an obligation any convention the queries rely on, such as how a list is named, and to state only per-site obligations that a reviewer can check from the site and the helpers it calls.
:::

:::{req} distributed_guidance.when
The bundled skills MUST direct agents to make a requirement distributed only when its obligation applies on its own at each of many sites, such as a convention every validation function follows; to use `{impl}` instead when particular code carries out the requirement as a whole; and to mark with `{impl}` the code that carries out any obligation of a distributed requirement that its sites do not uphold.
:::