Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/sourceorigin-standard/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ A repository adopts the standard in four steps:
- `layout`: Every workspace crate lives under `crates/`, `apps/` or `tools/`, the `xtask` crate in `tools/xtask`, and `.cargo/config.toml` aliases `cargo xtask` to `run --locked --package xtask --`.
- `cargo-locked`: Every `cargo build`, `check`, `clippy`, `doc`, `llvm-cov`, `nextest`, `publish`, `run` and `test` in a justfile (and `*.just`), `.github` YAML file or `t3.json` passes `--locked` (or `--frozen`).
- `agent-files`: `AGENTS.md` sits at the root, and no `CLAUDE.md` exists. Each skill is `.agents/skills/<name>/SKILL.md`, its frontmatter's `name` is `<name>`, and `.claude/skills` is a symlink to `../.agents/skills`.
- `agents-md`: AGENTS.md names every workspace crate, by its name in backticks or its directory, and holds at most 150 lines.
<!-- rules:end -->

Each rule is a variant of [`Rule`]: its name is the one `standard.toml` and
Expand Down
53 changes: 53 additions & 0 deletions crates/sourceorigin-standard/src/rules/agents_md.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//! `agents-md`: AGENTS.md maps the workspace, briefly.

use std::path::Path;

use super::agent_files::AGENTS_MD;
use super::{Finding, Repository};

/// The most lines AGENTS.md may hold.
const LINES: usize = 150;

impl Repository {
/// Each workspace crate AGENTS.md names neither by its name in
/// backticks nor by its directory, and an AGENTS.md over [`LINES`].
/// Without AGENTS.md, `agent-files` fails instead.
pub(super) fn agents_md(&self) -> Vec<Finding> {
let Some(agents_md) = &self.agent_files.agents_md else {
return Vec::new();
};
let text = &agents_md.text;
let root = &self.metadata.workspace_root;
let mut findings: Vec<Finding> = self
.metadata
.packages
.iter()
.filter_map(|package| {
let dir = package.manifest_path.parent()?.strip_prefix(root).ok()?;
let named = text.contains(&format!("`{}`", package.name))
|| (dir != Path::new("") && text.contains(&*dir.to_string_lossy()));
(!named).then(|| Finding {
path: AGENTS_MD.into(),
line: 1,
message: format!(
"AGENTS.md doesn't name the crate `{}`: add it to the map of the \
workspace's crates, with a line saying what it is",
package.name
),
})
})
.collect();
let lines = text.lines().count();
if lines > LINES {
findings.push(Finding {
path: AGENTS_MD.into(),
line: LINES + 1,
message: format!(
"AGENTS.md holds {lines} lines, over {LINES}: keep what an agent can't infer \
from the code, and move the rest to the docs it links"
),
});
}
findings
}
}
4 changes: 4 additions & 0 deletions crates/sourceorigin-standard/src/rules/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//! their docs.

mod agent_files;
mod agents_md;
mod budget;
mod cargo_locked;
mod comments;
Expand Down Expand Up @@ -142,6 +143,9 @@ rules! {
/// is `.agents/skills/<name>/SKILL.md`, its frontmatter's `name` is
/// `<name>`, and `.claude/skills` is a symlink to `../.agents/skills`.
AgentFiles = "agent-files" => agent_files,
/// AGENTS.md names every workspace crate, by its name in backticks or
/// its directory, and holds at most 150 lines.
AgentsMd = "agents-md" => agents_md,
}

/// Why the rules couldn't be checked.
Expand Down
27 changes: 27 additions & 0 deletions crates/sourceorigin-standard/src/rules/tests/agents_md.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use super::{Fixture, INHERITS};
use crate::rules::Rule;

#[test]
fn agents_md_names_every_crate_briefly() {
let fixture = Fixture::new();
fixture
.add_crate("core", INHERITS)
.add_crate("store", INHERITS)
.add_crate("cli", INHERITS)
.write(
"AGENTS.md",
&format!(
"# Repository\n\n- `core`: the model.\n- crates/store: the database.\n{}",
"More.\n".repeat(150)
),
);
assert_eq!(
fixture.violations(Rule::AgentsMd),
[
"AGENTS.md:1: AGENTS.md doesn't name the crate `cli`: add it to the map of the \
workspace's crates, with a line saying what it is (agents-md)",
"AGENTS.md:151: AGENTS.md holds 154 lines, over 150: keep what an agent can't infer \
from the code, and move the rest to the docs it links (agents-md)",
]
);
}
1 change: 1 addition & 0 deletions crates/sourceorigin-standard/src/rules/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! A fixture workspace the rules check, shared by the tests of each rule.

mod agent_files;
mod agents_md;
mod budget;
mod cargo_locked;
mod comments;
Expand Down