use anyhow::{bail, Result};
const SKILL_SRC: &str = concat!(
// § k3v7hb6mk.d@9cfdk
"---\n",
"name: silcrow\n",
"description: Runs `silcrow agent` immediately and follows that output. Use when the repository follows Silcrow, when editing laws or markers, or when the Silcrow index is stale or out of context.\n",
"---\n",
// § end k3v7hb6mk.d
"\n",
// § k3v7hb6mk.f@dhs82
"Run `silcrow agent` immediately. Follow that output strictly.\n",
"\n",
"Then run `silcrow agent <topic>` for the chosen topic.\n",
"\n",
"If the index is stale, forgotten, or out of context, run `silcrow agent` again. Do not reconstruct it from memory.\n",
"\n",
"If `silcrow agent` is missing, install it from https://github.com/zifeo/silcrow.\n",
// § end k3v7hb6mk.f
);
const TOPICS: &[&str] = &[
"explore", "check", "fix", "squash", "accept", "eject", "code", "author", "verifier", "adopt",
"review", "cite", "monorepo",
];
pub fn print(topic: Option<&str>) -> Result<()> {
// § xyd17m6cv@j5m09
let text = match topic {
None => index(),
Some("explore") => topic_explore(),
Some("check") => topic_check(),
Some("fix") => topic_fix(),
Some("squash") => topic_squash(),
Some("accept") => topic_accept(),
Some("eject") => topic_eject(),
Some("code") => topic_code(),
Some("author") => topic_author(),
Some("verifier") => topic_verifier(),
Some("adopt") => topic_adopt(),
Some("review") => topic_review(),
Some("cite") => topic_cite(),
Some("monorepo") => topic_monorepo(),
Some("agent") => index(),
Some(other) => bail!("unknown agent topic: {other}\n{}", topics_line()),
};
print!("{text}");
Ok(())
}
pub fn pointer() -> String {
// § k3v7hb6mk.a@4femt
SKILL_SRC.to_string()
}
fn run() -> &'static str {
// § vz45j4qce@7ts5f
let in_repo = std::env::current_dir()
.is_ok_and(|cwd| crate::hook::is_silcrow_repo(&crate::workspace::root_of(&cwd)));
run_for(in_repo)
}
fn run_for(silcrow_repo: bool) -> &'static str {
// § vz45j4qce@0s9hb
if silcrow_repo {
"cargo run -q --"
} else {
"silcrow"
}
}
fn cmd(name: &str) -> String {
format!("{} {name}", run())
}
fn topics_line() -> String {
format!("topics: {}", TOPICS.join(", "))
}
fn index() -> String {
// § xyd17m6cv.a@882h6
let run = run();
let repo = if run == "silcrow" {
""
} else {
"This is the Silcrow repository. Every command is `cargo run -q -- <command>`. Never call a `silcrow` on PATH.\n\n"
};
let dev = if cfg!(debug_assertions) {
"This is a development build. Writes default to dry-run unless `--write` is passed.\n\n"
} else {
""
};
format!(
concat!(
"# Silcrow agent\n\
\n\
This binary owns the protocol. Follow the output of each call. Do not copy this into a skill file.\n\
\n\
{repo}{dev}\
## Topics\n\
\n\
- `explore`: design talk is not bound by the laws\n\
- `check`: what a finding means and how to answer it, your findings first, formatters, after a merge\n\
- `fix`: what it mints, rewrites, and pins, and what it never re-pins\n\
- `squash`: squash-merge semantics, drop what was born and struck on the branch\n\
- `accept`: accept a law or a clause as it now stands, remint and re-pin\n\
- `eject`: remove Silcrow from a project, leave its notes as plain prose\n\
- `code`: implement a law in code or docs, follow marks, pins that drift too often\n\
- `author`: draft or amend a decision note\n\
- `verifier`: cite, retire, implement, close the graph\n\
- `adopt`: bring an existing project under Silcrow, with a writer, a verifier and a gap finder\n\
- `review`: review another agent's change law by law, a finder per law and a verifier per finding\n\
- `cite`: how to name a law to a human in a session\n\
- `monorepo`: several projects in one repository, where to run each command, laws of another project, hooks and worktrees\n\
\n\
Run `{run} agent <topic>` for that protocol. Run `{run} <command> --help` for a command's flags, and `{run} help` for the verbs.\n\
\n\
Minting an id is a step of `fix`.\n\
\n\
## Every file you write\n\
\n",
// § zz2kta2ax@t02q5
"- State the product as it is, or as a person decided it will be. A decided promise whose code is not written yet is a draft, `**§? ...**` or `- (+)? ...`, as `{draft}` shows.\n",
// § end zz2kta2ax
// § zz2kta2ax.a@159m5
"- A dated record, a changelog entry, a research note or a rejected design states the past as past.\n",
// § end zz2kta2ax.a
// § zz2kta2ax.b@tt782
"- Write a current limit as the supported scope: \"runs on Linux and macOS\", not \"does not run on Windows yet\".\n",
// § end zz2kta2ax.b
// § zz2kta2ax.c@94aaj
"- A promise no person decided goes to the issue tracker, never into the tree.\n",
// § end zz2kta2ax.c
),
repo = repo,
dev = dev,
run = run,
draft = cmd("agent author"),
)
}
fn topic_explore() -> String {
// § ymabg4gp6.a@2b7rb
format!(
concat!(
"# Facet: Explore\n\
\n\
Use when this repository is Silcrow itself and the session is reviewing, redesigning, or arguing the framework. Silcrow is the subject, not the judge.\n\
\n",
// § ymabg4gp6@rskjn
"- Laws are material to read. They are not a constraint on the argument. Do not refuse an idea because a current law would forbid it. Do not steer the session toward what the graph already allows. A law that would block a better design is a candidate to amend.\n",
// § end ymabg4gp6
// § ymabg4gp6.c@sh8t7
"- Explore ends when the session starts declaring, citing, retiring, or writing code and docs that must carry a marker. Then the graph is live, as for any project.\n",
// § end ymabg4gp6.c
// § ymabg4gp6.b@8pzw8
"- A project checkout is never in explore by default.\n",
// § end ymabg4gp6.b
"- In this repository every Silcrow invocation is `cargo run -q -- <command>`. A development build defaults writes to dry-run unless `--write` is passed.\n\
\n\
Print this again with `{}`.\n",
),
cmd("agent explore")
)
}
fn topic_check() -> String {
// § xyd17m6cv.j@0qha8
format!(
concat!(
"# check\n\
\n\
Validate the graph. Never writes. Run `{check}` after `{fix}`. Bare `{run}` with no verb prints the help and checks nothing.\n\
\n\
- Do not declare the graph closed from memory or from a search.\n\
- A pointer that does not resolve is a defect. Fix the pointer or declare the missing law.\n\
- A drifted pin fails and names what moved under it. Read the span against its law or clause with `{diff} --law <address>`, then accept it as `{accept}` says. A span that no longer honors its clause is fixed in code, never re-pinned to pass.\n\
- A drifted pin over a whole function also warns with the laws of the callers that do not follow it: a pinned function is a boundary that only a `functional` or `follow` mark pierces. Re-read those spans too.\n\
- It checks the nearest project above the working directory, `{run} -C <dir> check` the project of `<dir>`, and `--all` every project of the workspace in one report, each finding prefixed by its project path, as `{monorepo}` details.\n\
- `{fix}` only pins bare markers and rewrites ids, links and marker digests, never code or secrets, so an agent sandbox can allowlist it.\n\
\n\
## Your findings first\n\
\n\
- It prints the findings of your change first, then under a heading of their own those already there at the fork point with the default branch. Answer yours. Never accept a drift that was already there: it is not yours to approve.\n\
- `--path <file>`, repeatable, keeps the findings in the files you touched and each drifted pin that reads one, such as a caller of a helper you edited. A filtered run passes or fails on what it keeps alone.\n\
- `--json` prints the same findings as one JSON object, each with its kind, project, file, line, the address it names, what moved under a drift, its text, and whether it is yours. `list`, `diff` and `stats` take `--json` too.\n\
- On a branch that no remote holds, the pre-commit hook prints each error as a warning and lets the commit through. Repair them before you push: once the branch is shared, the hooks block.\n\
\n",
// § xyd17m6cv.l@mt1gb
"## Formatters\n\
\n\
Run formatters and the linters that fix in place, such as `cargo fmt`, `cargo clippy --fix`, `ruff format`, `ruff check --fix`, `prettier` or `eslint --fix`, before Silcrow, and keep its hook last in the pre-commit order, so it checks the code they leave. A formatter rewrite moves no pin, but for the few the stated limits list. A linter autofix may, and its drift is read as any other: read each with `{diff} --law <address>`, then accept them in one call, `{run} accept <a> <b> ...`.\n\
\n",
// § end xyd17m6cv.l
"## After a merge or a sync\n\
\n\
- While a conflict is unresolved, `check`, `fix`, `accept`, `list` and `diff` fail before they read the graph, naming the merge, rebase or cherry-pick in progress and each conflicted file with its first conflict line. Resolve each conflict, then `git add` it.\n\
- Two branches that each re-pinned one marker conflict on its line alone. `{fix} --write` resolves exactly those blocks: it writes each such marker bare and names its address. Read each against its law or clause with `{diff} --law <address>`, then accept them all in one call, `{run} accept <a> <b> ...`. Never pick a digest by hand, and never resolve a digest conflict by taking either side, ours or theirs: that `@digest` hashed the code of one side, not the code the merge left.\n\
- Then make the `<silcrow>` block of `AGENTS.md` valid and run `{check}`.\n\
- When `check` opens with the steps of a hashing scheme change, follow them in order before anything else: `{fix} --remint`, a commit of that alone, then every drift left read and accepted in one call. A drift that `--remint` leaves moved by its code, which no remint settles.\n\
\n\
## A check that compares\n\
\n",
// § j44p1s9z8@wxxgt
"- Without `--base`, and outside CI, it reads the tree as it stands and compares nothing. A deletion that leaves no pointer behind passes, and `diff` lists it as deleted, or as removed when the published tree held it struck. A struck clause, a tombstone or an alias anchor that no law holds fails: it is what a deletion left.\n\
- With `--base <ref>`, or under `CI` where the forge names a merge target, it compares every project against that point, the merge-base of `HEAD` and the target in CI, and names, without failing, each change a person must see before the merge: every pin the point held that now carries another digest, is bare or is gone, every pin added for an address it held, every id reminted, every law deleted, struck or kept only as an alias anchor, every change to the text of a law or of a clause it held, even with no pin moved, every law or clause the point did not hold, every draft the point did not hold and every `?` added to a law or clause, every `!` added to or dropped from a head, and every attribute of the Silcrow block written otherwise. It prints the count of its named changes per law, then the `diff --md` packet whenever it holds a change under a law, named or not, appends both to the file `GITHUB_STEP_SUMMARY` names, writes them to the file `--review-out` names on a forge with no job summary, ends with the named changes grouped per law, and a person reads it before the merge, which is the approval. It still fails a head whose id a removed law carried, a letter the point wrote for a law that the tree still declares and no longer writes, and an active clause on a letter the point holds struck or as a tombstone, or that its history wrote. CI runs `{ci}` on a pull request, and a target the clone does not hold fails and names the fetch.\n",
// § end j44p1s9z8
),
check = cmd("check"),
fix = cmd("fix"),
diff = cmd("diff"),
accept = cmd("agent accept"),
monorepo = cmd("agent monorepo"),
run = run(),
ci = cmd("check --all"),
)
}
fn topic_fix() -> String {
// § jed5hb8sa@ascxb
format!(
"# fix\n\
\n\
The only verb that rewrites the graph. Run `{}`.\n\
\n\
- Mints the id of each `§ +<name>`, rewrites every pointer and cite link, and pins every new bare marker a tested grammar can delimit.\n\
- Never re-pins a pin that drifted. That is `accept`.\n\
- `--remint` follows a hashing scheme change: it re-pins every span unchanged since `HEAD` and names the rest for `accept`, or, when the history records no scheme change, remints every law id that does not hash its sentence.\n\
- Strips a `<projectpath>:` qualifier that names the current project, and rewrites one that names no project to the one project that declares the id. Qualifies an unqualified id that only one other project declares, `.:` for the root. `--all` fixes every project.\n\
- The pre-commit hook runs it on the staged files.\n\
- A development build simulates unless `--write` is passed.\n",
cmd("fix")
)
}
fn topic_squash() -> String {
// § mstqr8xqs@s1kw2
format!(
"# squash\n\
\n\
Squash-merge semantics for the notes. Run `{}` on the branch before the merge, or on the default branch right after.\n\
\n\
- A struck law or clause absent from the published tree is deleted.\n\
- A published struck clause becomes `(<letter>) **Retired.**`. A published struck law stays until `accept <id>` removes it.\n\
- Refuses while a pointer still names what it would delete.\n\
- A development build simulates unless `--write` is passed.\n",
cmd("squash")
)
}
fn topic_accept() -> String {
// § xnsbksxv6.c@hbba4
format!(
concat!(
"# accept\n\
\n\
Accept a law or a clause as it now stands. Run `{} <id>` or `{0} <id>.<letter>`.\n\
\n\
- Accept only the drift your change caused, by listing its addresses in one call, `{0} <a> <b>`: they are re-pinned in one reading of the tree, much faster than one call each. When one fails, or would remint or remove a law, nothing is written: accept that one alone.\n\
- `{0} --drifted` takes every drifted pin of the project, and with `--all` of every project, by the same rule. It approves them all, so use it only when every drift is yours to approve: after `{1} --remint` for a hashing scheme change, or after a refactor you just made and read in `diff`. `{0} --drifted --path <file>`, repeatable, takes only the drifted pins in those files or that read them: the drift of the files you touched.\n\
- A law whose sentence moved gets its id reminted and every pointer rewritten. A published id stays in the head as an alias anchor.\n\
- Every pin of that address in the current project is re-minted. Read each span against its text first: this is the review step.\n\
- A remint rewrites the qualified pointers of every other project. Each project re-pins its own markers of another project's law with `<projectpath>:<id>[.<letter>]`.\n\
- Use it for form: a typo, a clearer wording, a richer table or diagram. A change of sense is a later clause, or a strike and a successor.\n",
// § vw7bmw3s3@s8sty
"- On a struck law or clause it is the removal. It deletes every marker and explicit end of that address in every project, and the adoptions of it, and re-pins each pin that matched and whose span that moved. On a struck law whose strike the published tree holds, it also deletes the law, its clauses, tombstones and alias anchors, and each line that holds only references to it. It refuses, naming each one, while another law's text or a sentence of prose cites it.\n\
- A removed id is never minted again: a carrying sentence that mints one is reworded.\n",
// § end vw7bmw3s3
"- A development build simulates unless `--write` is passed.\n",
),
cmd("accept"),
cmd("fix")
)
}
fn topic_eject() -> String {
// § qeka6zh48@bky6c
format!(
"# eject\n\
\n\
Remove Silcrow from a project. Run `{}`.\n\
\n\
- Deletes every marker, explicit end, and follow mark line in code and documentation.\n\
- De-marks each decision note: a law head keeps its bold sentence, an active clause stays a list item, a cite link keeps its text. Adoptions, struck clauses, and tombstones go with their attached body.\n\
- Removes the `AGENTS.md` block, and the file when nothing else is left.\n\
- With the last project, deletes the skill pointer, its native copies, and the hooks `install` wrote. A file that is not ours stays.\n\
- Refuses while a project that stays names a project it ejects.\n\
- `--all` ejects every project of the workspace. Git history is never touched.\n\
- A development build simulates unless `--write` is passed.\n",
cmd("eject")
)
}
fn topic_code() -> String {
// § xyd17m6cv.b@fgy5b
format!(
concat!(
"# code\n\
\n",
// § k40z0sght.c@39bpv
"Before you edit a file, run `{list} --path <file>[:<line>]`: it prints each law and clause whose pin reads that file or line, with its text, the rules your edit can drift, then the drafts of the same notes, which your edit may be the one to implement. Read a whole decision note only when you change a law or need its reasons.\n\
\n",
// § end k40z0sght.c
// § xs2e8kj86@7e4w7
"When code carries a minted law, add `// § <id>` (or `// § <id>.a` for a clause) on a line of its own inside the block that implements it: ",
// § end xs2e8kj86
// § xs2e8kj86.b@kagve
"a comment after code is no marker and fails `check`. ",
// § end xs2e8kj86.b
// § d1bc2zca5.e@bfrm5
"Every authored clause. Never write a digest: `fix` pins the marker with `@<digest>`, a hash of the block and of the clause text. ",
// § end d1bc2zca5.e
// § rr512n5e2@6e5mz
"The span runs to that construct's close. Place the marker in the block that holds the clause first, and add a `§ end` only when the rest of the block is not governed by the clause: then close the stretch with `// § end <id>` (or `// § end <id>.a`) and the span runs from the marker to that line. ",
// § end rr512n5e2
// § rr512n5e2.e@z6q3v
"A marker outside every span pins nothing and fails `check` and `fix`: move it into the construct it carries. A marker on the line above a module-level function spans that function. ",
// § end rr512n5e2.e
// § rr512n5e2.f@agk48
"Each marker has a span of its own: two markers whose spans are the same code, or overlap without one holding the other, fail `check`, whatever their addresses. Give each address the statements that carry it, with its own construct or its own `§ end` stretch, or nest one strictly inside the other. ",
// § end rr512n5e2.f
// § rr512n5e2.h@qyza0
"A `// § one <address>, <address>` marker spans only the statement or member right below it, such as a field, an argument, a match arm or a dict entry, and gives each address of its list its own pin. Use it only when that statement carries the whole clause: a value computed there and used further down takes the block. It takes no `§ end`, needs a tested grammar, and fails `check` when its list names an address twice or a law beside its own clause. ",
// § end rr512n5e2.h
"A pin that drifts fails `check`. ",
// § kv22y3ap6@hvref
"A pin also hashes the local functions its span calls, except a function whose own pin covers its whole body, unless a follow mark says otherwise: that pin already guards it. ",
// § end kv22y3ap6
// § rr512n5e2.g@bb5tb
"A span whose every statement is a call its pin does not follow to a function the project declares, such as a method called on a value, discarded, returned or awaited, with only names and fields of names as its receivers and arguments, guards nothing and fails `check`: move the marker onto the code that acts, or mark the call `// silcrow:follow` so the pin reads its body. A call whose arguments hold a literal, a comparison or a closure carries what they decide, and so does a call to a library or standard function, by its name. ",
// § end rr512n5e2.g
// § rr512n5e2.ga@efhnd
"A call to a boundary whose own marker carries the span's law counts as followed: that boundary's pin guards the code that acts. ",
// § end rr512n5e2.ga
"A marker is not a comment to tidy: it binds the code to its law so a drift fails `check`. Never remove or reword one by hand, and never merge a digest by hand: after a merge, follow `{check_topic}`. To re-pin drifts, run one `accept` with all their addresses after reading each span against its law or clause, as `{accept_topic}` says, and fix the code when it no longer holds. `fix` pins no drift: a marker whose `@<digest>` is removed while its span changed since `HEAD` stays bare and fails. ",
// § p9e62dtvr.d@ks45f
"Code that carries no law carries no marker.\n",
// § end p9e62dtvr.d
// § xyd17m6cv.i@1ww2p
"\n\
A law written `**§? <id> ...**`, or a clause written `- (c)? ...`, is a draft: declared, cited and listed, and owing no marker until its code exists. To implement one, write its code and its marker, then run `{fix}`: it drops the `?` of each draft a marker names, and a marker on a draft fails `{check}` until it does. A clause of a draft law that no marker names keeps a `?` of its own.\n",
// § end xyd17m6cv.i
"\n\
A law of another project of the workspace is marked qualified with its project path, the directory from the workspace root (`.` for the root): `// § <projectpath>:<id>.a`, `// § end <projectpath>:<id>.a`. Such a marker is checked and pinned to that project's text, and pays no duty there. An unqualified id resolves in the current project only. `{monorepo}` gives the rest of a repository of several projects.\n\
\n",
// § xs2e8kj86.c@2v5zg
"A marker pays the code duty of its law or clause in a file the `code` list of the `AGENTS.md` block matches, every file when the block omits it. A Markdown file never pays it. A marker in test code fails `{check}` under `test-markers=\"error\"`, the default. The block admits it with a warning under `test-markers=\"warn\"` and without one under `test-markers=\"allow\"`, and then it pays the code duty as any other. Rules after the value set it per path, the last match winning: `test-markers=\"error tests/conformance/**:allow\"`. Test code is what the `tests` list of the block matches, or each language's convention when it omits it: `tests/`, Go `*_test.go`, Python `test_*.py` and `*_test.py`, JavaScript and TypeScript `*.test.*`, `*.spec.*` and `__tests__/`, Java and Kotlin `src/test/`, and Rust items compiled only for tests.\n\
\n\
Zone test code only where the law's deciding code lives in the test or outside this tree, with `test-markers=\"allow\"` in the block, and there place the marker on the assertions that check the clause, never on the setup.\n\
\n",
// § end xs2e8kj86.c
// § xs2e8kj86.f@mp0p4
"Documentation that carries a law is a file the `docs` list of the block matches: the project's public manual, user guide, API spec or FAQ, in any language with a comment syntax, such as `<!-- § <id> -->` (or `<!-- § <id>.a -->`) in Markdown or HTML. A law written `§!`, a public promise, owes a marker of itself or of a clause there, and `check` fails one while `docs` is empty. A plain law owes code alone, and may carry a doc marker too, which pins the page that explains it. A marker in any other Markdown file that is not a decision note fails `check`: internal docs, such as architecture notes, carry none. ",
// § end xs2e8kj86.f
// § xs2e8kj86.i@rh40m
"In MDX, whose compiler refuses an HTML comment, write it `{{/* § <id> */}}`, and its end `{{/* § end <id> */}}`. ",
// § end xs2e8kj86.i
// § rr512n5e2.a@2byz5
"`fix` pins it like code: in Markdown the span is its section, from its heading to the next heading of the same or a higher level, or up to `<!-- § end <id> -->`, `{{/* § end <id> */}}` in MDX. A rewrite of the section fails `check` until `accept` re-pins it. ",
// § end rr512n5e2.a
"That `§` does not declare. HTML comments stay out of decision notes.\n\
\n\
## Follow marks\n\
\n",
// § pyw49tg9j@nx2w1
"A pin reads the closure of its span: the span, the code of the function around it up to the span, the project functions, classes and constants its names denote, and the import lines of its file that spell those names. A name follows only into its cone, the directory of its file and below, and only when its own file, its qualifier, the file a relative import names or, in Rust, the workspace crate its path or `use` line starts at leaves it one declaration. Enums stay text. The rules and what is not read are one page: https://github.com/zifeo/silcrow/blob/main/docs/decisions/contract.md. ",
// § end pyw49tg9j
// § jncrstyg1@swbpm
"A function whose own marker covers its whole body is a boundary: its pin already guards it, so callers do not follow it. A follow mark changes that, in the comment wrapper of a marker, on the line before the function or the call.\n\
\n",
// § end jncrstyg1
// § jncrstyg1.c@ez1v9
"- `// silcrow:technical` before a function: no caller follows it. Put it on shared plumbing, such as logging, padding or formatting, so its edits do not churn every caller.\n\
- `// silcrow:skip` before one call: that call is not followed. Put it on one call that a law must not read.\n\
- `// silcrow:functional` before a function: every caller follows it, even when it is a boundary or outside the cone. Put it on a helper whose behaviour every caller's law depends on, with its own law or outside the cone.\n\
- `// silcrow:follow` before one call: that call is followed, even into a boundary or outside the cone, a method called on a value into the one method of its name other than the one around it. On a library call or a call on a value that names none, `once(x).map(fee)`, the mark passes to the project names it holds, and `check` fails when it reaches no single function, class or constant of the project. Put it on one call that must read such a helper.\n",
// § end jncrstyg1.c
// § jncrstyg1.d@c1bdk
"- Precedence, from first to last: out of the tree, `skip`, `technical`, `follow`, `functional`, boundary, cone. A move or a rename across files drifts the callers whose import lines it rewrites, since those lines are read as text, and the callers whose cone it enters or leaves.\n",
// § end jncrstyg1.d
// § jncrstyg1.e@gms0m
"- A declaration mark may sit above the doc comments, attributes and decorators of its function. A mark that names no known mark, or attaches to nothing, fails `check`.\n",
// § end jncrstyg1.e
"\n\
## Q&A\n\
\n\
My pins drift too often, what do I do?\n\
\n\
- Keep one law to one function: an edit above a span in its function drifts it.\n\
- Mark shared plumbing `// silcrow:technical`, or give it its own law with a marker over its whole body: it becomes a boundary its callers do not follow.\n\
- Close the span earlier with `// § end <address>`, so it covers the code that implements the clause and not the rest of the function.\n\
- Close every span on the statement that carries the clause, never in the middle of a fluent chain or inside a large config object, and read `{stats}` before handing on: a wide pin is a defect.\n\
- Put the marker on the clause the code implements, `// § <id>.<letter>`, not on the whole law.\n\
\n\
A business rule in a helper changed and nothing failed, why?\n\
\n\
- Check that the helper sits in the caller's directory or below, or is marked `// silcrow:functional`, and that no other function shares its name.\n\
- Check that the helper is neither `// silcrow:technical` nor a boundary: callers read neither.\n\
- Remove `// silcrow:technical` from it: no mark follows past it.\n\
- For a boundary, when every caller's law depends on it, mark it `// silcrow:functional`. When one call does, put `// silcrow:follow` before that call.\n\
- A call on a value (`x.f()`) or a trait's method is not followed. Call it by name, through its type or class (`Type::f()`, `Class.f()`), or through `self`, `this` or `cls`.\n\
\n\
Run `{list}` for the active register. Run `{fix}`, then `{check}`.\n",
),
list = cmd("list"),
fix = cmd("fix"),
check = cmd("check"),
stats = cmd("stats"),
monorepo = cmd("agent monorepo"),
check_topic = cmd("agent check"),
accept_topic = cmd("agent accept"),
)
}
fn topic_author() -> String {
format!(
concat!(
"# Facet: Author\n\
\n\
Use when the session writes or amends a decision note. The author does not invent the decision. It extracts binding clauses from the context already in front of you.\n\
\n",
// § q3ckz9sm8.b@rt52s
"- Write the why in a decision note: a Markdown file the `notes` list of the `AGENTS.md` block matches, `docs/decisions/**/*.md` when the block omits it. Documentation is what its `docs` list matches. Declare by opening the paragraph with the head, in markdown bold: `**§ <id> The binding sentence.**` A `§` that does not open its paragraph does not declare. Several `§` per `##` section are allowed. Do not open a heading only to hold a second `§`.\n",
// § end q3ckz9sm8.b
"- The carrying sentence binds read alone, outside its section and its file: a heading is a boundary for the reader, and a section gets renamed. One decision per law: a sentence that binds two independent things is two laws.\n",
// § hr2j2031z@ka4b9
"- Write each law for the person who reviews it. ",
// § end hr2j2031z
// § hr2j2031z.a@1t0cy
"Write a law or a clause in the present indicative and the active voice, with the product or an actor as its subject: \"`check` fails a note past its limit\", not \"a note past its limit shall be failed\". Use plain words, never RFC 2119 capitals such as MUST, SHALL or SHOULD.\n",
// § end hr2j2031z.a
// § hr2j2031z.b@bgq61
"- Give each clause one of five shapes: a rule that always holds; `When <event>, ...` for a response to an event; `While <state>, ...` for a behaviour in a state; `If <unwanted>, then ...` for a response to an unwanted case; `Where <feature>, ...` for a behaviour of an optional feature.\n",
// § end hr2j2031z.b
// § hr2j2031z.c@6sqqp
"- Write clauses that vary along one or two axes as a table of row clauses under the head, a header row then one `| (a) | ... |` row per case. Draw a state machine or a sequence as a mermaid diagram in the clause body. Write an enumeration inside a clause as a sub-list under its item.\n",
// § end hr2j2031z.c
// § hr2j2031z.d@57qrs
"- A term a clause defines is used as that clause defines it, in every note.\n",
// § end hr2j2031z.d
// § wqhsnrn8a.g@3e9ka
"- Author clauses as list items after the carrying sentence: `- (a)`, `- (b)`, ` - (aa)`. A blank line above each letter. ",
// § end wqhsnrn8a.g
// § wqhsnrn8a.b@08ee0
"A table, diagram, or code fence right after a clause belongs to it, until the next letter or a prose paragraph. A table right under the head may letter its rows: `| (a) ... |`. A line opening with `(a)` that is not `- (a)` fails. Unlettered lines are context. Never pick a positional `id.2`. Insert between two letters with a compound letter, `(aa)` after `(a)`. Never renumber a neighbour.\n",
// § end wqhsnrn8a.b
"- A letter states one obligation, permission, definition, or refusal that holds across time, and offers no choice. A line earns a letter when it obliges an implementer, fixes a form, names a refusal with the party it binds and what happens on breach, or states a condition a check can decide. A line whose deletion changes no one's obligation, or that only restates the carrying sentence, carries no letter. A line that leaves the decision open stays prose until the decision is taken.\n\
- A law or a clause says what the product does or supports, never only an absence: something not done, not needed or not supported. Write an unsupported scope as the supported one, \"runs on Linux and macOS\" rather than \"refuses Windows\", and cut a clause such as \"undoes nothing\" or \"needs no worker in the process\", or say what the product does instead.\n",
// § wqhsnrn8a.h@0nmqp
"- Keep a clause and a carrying sentence short: `{check}` warns past 60 words and fails past 120, since a longer one holds a second promise, a reason or an example.\n",
// § end wqhsnrn8a.h
"- Reasons, analogies, benchmarks, measurements, probabilities, statuses, versions, counts, dates, and every rejected design with the reason it lost are prose beside the law: a reason dressed as a letter looks binding, and the next writer amends it instead of the law. An enforced quantity is written as the bound an implementer can meet, not the measurement that justified it. A law that the mere passage of work would retire is malformed. A conformance note names the hand path, owes the markers of its letter, and is struck when the tree conforms. An example, a command transcript, or a diagram is labelled as context and carries no letter.\n\
- A letter no implementer can mark in code is a defect: `{check}` fails on it as a missing code marker.\n\
- Open a note with its context and its problem before its first `§`. Put each law next to the prose that argues for it, with its source: a design note, the as-built, a test or the code, named by its symbol, never by a line number. A sentence written to justify the law is no source.\n\
- Name a note by its topic, `refunds.md`, never with an ordinal prefix such as `01-`. The reading order comes from the links of the note that states the product's promises, and the notes follow the product's topics, never the order they were written in or the order of a reference document.\n\
- Keep a note under the `note-words` limit of the `AGENTS.md` block, 3000 words when it omits it: `{check}` fails a longer one, or warns on it where the block writes the limit `warn:<n>`. Split it by sub-topic into notes under a directory of the same name, `refunds/`, and link them from where the reader needs them.\n\
- A rule about how to write or name a law that no lint can decide is guidance, not a law. It lives in this text. It becomes a law, with its code marker, when a lint can refuse its violation.\n",
// § jnxf0eakp@2zkp9
"- Two active laws that contradict are a defect. ",
// § jnxf0eakp.a@69prh
"Neither wins by being later, more specific, or citing the other. ",
// § end jnxf0eakp.a
"Strike one and declare the successor under a new id. ",
// § jnxf0eakp.c@45w1q
"A condition that narrows a law is a clause of that law.\n",
// § end jnxf0eakp.c
// § end jnxf0eakp
"- A change that adds a member to an enumeration a law declares exhaustive adds its row in the same change.\n\
- Reference a law with a link, never a bare id: `[<id>](<path>#<id>)`, and `[<id>.<letter>](<path>#<id>)` for a clause. A law of another project qualifies the link text with its project path: `[<projectpath>:<id>](<path>#<id>)`.\n",
// § v8b14v6pn.a@jgyxx
"- In a monorepo every directory whose `AGENTS.md` carries the block is a project, with its own notes and policy. To take another project's law as a duty of this one, write a paragraph that is only `**§ <projectpath>:<id>**`, or `**§ <projectpath>:<id>.<letter>**` for one letter. It declares nothing, and its clauses then owe qualified markers here.\n",
// § end v8b14v6pn.a
// § eh0rt4jyr@0p2zn
"- Do not stop to mint an id. A new law carries `§ +<name>`: lowercase letters, digits and hyphens, unique within the change, spelled the same in every marker and cite. `{fix}` mints the real id, names the next clause letter, and rewrites cites. Never invent a nine-character id. Never rewrite an existing id, letter, or cite path by hand.\n",
// § end eh0rt4jyr
// § q3ckz9sm8.e@x0qx5
"- A law the project's public documentation promises its readers is a public promise: open its head `**§! +<name> ...**`. It owes a documentation marker in a file the `docs` list matches, besides its code, and `{check}` fails it while `docs` is empty. Every other law is a plain `§` and owes code alone. A draft public promise opens `§!?`, the `?` last. Like the `?`, the `!` is never hashed.\n",
// § end q3ckz9sm8.e
// § xyd17m6cv.i@m9mc2
"- Write a spec before its code as a draft, on any branch: `**§? +<name> The binding sentence.**` for a law, `- (+)? ...` for a clause. A draft owes no marker, its `?` is never hashed, and `{check}` lists it as not implemented. Then write its code and its marker and run `{fix}`, which drops the `?`. Never add a `?` to a published law or clause to silence a missing marker. A comparing check names every `?` added and every new draft for the person who merges.\n",
// § end xyd17m6cv.i
"- Freeze a law. A change of sense strikes it in place (`~~...~~`) and declares the successor. A change of form is `{accept}`. Never delete a published line by hand.\n\
- Retire, then remove. Strike the law in place and run `{accept} <id>`: its markers and explicit ends go in every project, the pins around them are re-pinned, and the struck text stays. Once the strike is merged, `{accept} <id>` again removes the law with its clauses, alias anchors, adoptions, and the lines that only reference it, and `diff` lists it as removed. It refuses while another law's text or a sentence of prose cites it: rewrite those first. A struck clause of a law that stays keeps its tombstone, which holds its letter.\n\
- Notes are readable markdown. No HTML comments in decision notes.\n\
- After writing, run `{fix}`, then `{check}`, then read `{list}` before handing the note on. What it prints is what the tree now believes binds.\n\
\n\
See `{cite}` for how to name a law to a human.\n",
),
check = cmd("check"),
fix = cmd("fix"),
accept = cmd("accept"),
list = cmd("list"),
cite = cmd("agent cite")
)
}
fn topic_verifier() -> String {
format!(
"# Facet: Verifier\n\
\n\
Use when the session reads or writes a pointer (a cite, a marker, a strike) or claims the graph is closed.\n\
\n\
- Run `{list}` to see the active register. Run `{diff}` for the review law by law, and `{diff} --all` in a workspace that nests projects, which a plain `{diff}` at the root names and does not read. Run `{check}` to verify. Do not declare the graph closed from memory or from a search.\n\
- A pointer that does not resolve is a defect. Fix the pointer or declare the missing law.\n\
- Code and documentation markers: `{code}`.\n\
- Do not invent a second graph. Do not embed. Do not use a commit SHA as a target. A trailer in git is an index, never a cite target or a store of the law.\n\
- Before or right after the merge, ask a person to run `{squash}`. Never run it yourself: a person runs it.\n\
- Only `install` writes the hooks, the `AGENTS.md` block, and the skill pointer. `check` fails when the block or the pointer differs from this binary, and warns when a hook does.\n",
list = cmd("list"),
diff = cmd("diff"),
check = cmd("check"),
code = cmd("agent code"),
squash = cmd("squash")
)
}
fn topic_adopt() -> String {
format!(
concat!(
"# Facet: Adopt\n\
\n\
Use when a project that already has code, docs and tests starts following Silcrow. Adoption invents no rule: it finds the decisions the project already made, writes each as a law beside the reason the project gives, and marks the code that decides it. Aim at the essence, what the product promises its users, its architecture and its invariants, complete at each pass. A clean list of checks and caps that misses how the system works has failed.\n\
\n\
## Before the first pass\n\
\n",
// § xyd17m6cv.g@c5yng
"- Run `{install}`. In a linked worktree it writes the block and the skill pointer and leaves the hooks to the main checkout. In any other checkout whose hooks another tree shares, never install hooks there, and never write the `AGENTS.md` block, the skill pointer or a hook by hand: only `install` writes them. Run `{install}` in a separate clone of the project, or ask the owner of the shared hooks to install. `{install} --dry-run` lists each hook, `AGENTS.md` block and skill file that differs from what this binary writes, and writes nothing.\n",
// § end xyd17m6cv.g
// § xyd17m6cv.h@xh5wc
"- Adopt with `docs=\"\"` in the `AGENTS.md` block: laws, clauses and code markers first. Once the laws are true and reviewed, ask the owner which public documentation the project has, such as a website, a manual or an API reference, and name it in `docs`, `docs=\"website/docs/**/*.html\"` for one. Then mark as `§!` only the laws those docs promise their readers: each owes a documentation marker there. Documentation markers go there alone, never in internal docs such as architecture notes or design records.\n\
- The doc duty never drives a law. Write public prose from the product, for its readers, never from a law. A docs line the adoption added stays correctable: fix it when it proves false.\n\
- A business rule that must not be public is still a law, a plain `§` with no `!`, and its note is its home: it owes no documentation marker, so it stays out of the public docs.\n",
// § end xyd17m6cv.h
"- Read `{author}` and `{code}`. Write each new law as `§ +<name>` with `(+)` clauses: `fix` mints.\n",
// § xyd17m6cv.i@5mxkw
"- A promise the project decided and whose code is not written yet is a draft: write it `§? +<name>`, or `- (+)?` for a clause, so it owes no marker until the code lands, and list it in the ledger as open work.\n",
// § end xyd17m6cv.i
"- Move any earlier attempt out of the notes and keep it as material, not as a version to patch.\n\
- Arrange the notes by the product's topics, each named by its topic with no ordinal prefix, never by the order below or the order of a reference document. The note of the promises links the others in reading order. Split a note past the `note-words` limit by sub-topic into a directory of the same name.\n",
// § xyd17m6cv.g@hzf01
"- Never write outside the project.\n",
// § end xyd17m6cv.g
"\n",
// § xyd17m6cv.c@f20p6
"## Roles\n\
\n\
The main agent spawns each role as a fresh agent and runs every stage itself: a role never spawns another. Without a subagent tool, run each in a fresh session. Write and verify with a frontier model.\n\
\n\
- Writer: drafts the laws of one note, each with its source and its carriers. Run one writer per note, in parallel.\n\
- Verifier: a different and stronger model than the writer, or at least a fresh context that sees only the code, the docs and the law text, never the writer's reasoning or verdicts. One model that writes and verifies its own work does not verify. Per law it asks: is it true in every host and copy, does a source independent of the adoption state it, is it a decision with a stated reason, is it one decision. ",
// § hr2j2031z.e@a9e00
"It asks too whether the law is singular, verifiable and unambiguous, whether it holds a vague word such as fast, appropriate or as needed, and whether a table of row clauses would read it better. ",
// § end hr2j2031z.e
"It answers holds, refuted with the symbol that refutes it, or unknown.\n\
- Gap finder: reads the ledger against the sources and names each promise, area, host or copy no law covers.\n\
- Give each role its material up front: the `{list}` output, the candidate carriers, the test names and the design notes of its note.\n\
- Every role writes as it goes. The verifier writes one line per address: stop a verifier that wrote no line for 20 minutes, and restart it on the addresses left.\n\
- The writer revises only what was refuted or unknown, and the verifier rechecks only those.\n\
\n\
## Order\n\
\n\
Top-down, and code last: code says what happens, the docs and the tests say what is promised.\n\
\n\
1. Promises: the README top, every section titled as guarantees or rules, and every \"not guaranteed\" list. One law per promise.\n\
2. Architecture and invariants: what is shared, where the commit point is, what is truth and what is a rebuildable hint, which component decides, the contract with each external dependency.\n\
3. Mechanisms, section by section of the reference and its error table: errors, ordering, idempotence, limits, what crosses a restart.\n\
4. Tests: read every test name. A name is often a clause already written, and a conformance test is the strongest evidence of a promise.\n\
5. Code: to find carriers and settle what the docs leave open.\n\
\n",
// § end xyd17m6cv.c
// § xyd17m6cv.d@m1986
"## What is a law\n\
\n\
A law has a reason the project states, correctness, compatibility or cost, someone relies on it, and changing it silently would hurt. Write it at the altitude of the promise, one decision per law, never as a restatement of the code. It says what the product does or supports, never only an absence: write an unsupported scope as the supported one, and cut a clause that only says what is not done, not needed or not supported, or say what the product does instead.\n\
\n\
Cite its source in the prose beside it, a source independent of the adoption: a design note, the as-built, a test or the code, named by its symbol, never by a line number. A sentence the adoption wrote, in a note or in the docs, is never a source.\n\
\n\
Not a law:\n\
\n\
- a value with no stated reason: a page size, a poll interval, a default. A law states the property a value buys, with its reason;\n\
- a host law that restates a core law: merge it into the core law and mark each host as a copy;\n\
- a per-host API detail, a library, a helper or an internal type;\n\
- a measurement, an example, a recipe, a list that only indexes the API, what is not implemented yet.\n\
\n",
// § end xyd17m6cv.d
"## Carriers\n\
\n\
- The code that decides the clause, in every copy: each host, backend and script in another language gets its own deciding marker. Each head has a deciding carrier of its own.\n\
- No marker on a forwarder, a constant, a type, a field, or code that does the opposite of the law.\n\
- Place each marker in the block that holds its clause first, and add a `§ end` only when the rest of the block is not governed by the clause. Two markers never share one span: give each address the statements that carry it. A `§ one` marker fits only a statement or member that carries the whole clause alone, such as a field, a match arm or a dict entry: a value computed there and used further down takes the block.\n\
- Close every span on the statement that carries the clause, never in the middle of a fluent chain or inside a large config object.\n\
- A test marker only for a law whose deciding code is not in this tree, such as a compiled module or another repository's service: one per law, in the cross-host suite when one checks it. That law lives in a nested project rooted at the artifact whose tree holds that suite, whose block sets `test-markers=\"allow\"`, so a test marker pays the code duty like any other, and a test of another project names it qualified, `// § <path>:<id>`. A law decided here marks its deciding code. Zone test code only where the deciding code lives in the test or outside this tree, and there place the marker on the assertions that check the clause.\n\
- Once `docs` names the public docs, a doc marker of each `§!` law around the one section that states it.\n\
- Ask of every marker, with its refusal path named: if this line did the opposite, would the law break? If the law broke, would this pin move? A marker that fails goes, or moves to the deciding code.\n\
- Read `{stats}` before handing on. A wide pin is a defect: close its span earlier or move it to the deciding code. Shared plumbing every pin follows wants `silcrow:technical`. A law whose pins drift on most unrelated edits, with no narrower carrier, goes to the open list.\n\
- When marker lines push a file past the repository's line ceiling, move code into a sibling file as a pure move, and prove it by its diff. Never add the file to an allowlist.\n\
\n",
// § xyd17m6cv.e@y0bag
"## Gaps between code and docs\n\
\n\
Settle each one yourself:\n\
\n\
- a documented promise wins over code that breaks it: change the code, and never leave a law active and false;\n\
- a promise decided and not built stays a draft, with its item on the open list;\n\
- hosts or copies that disagree align on the reference, else on the majority;\n\
- a silent drop becomes an explicit failure;\n\
- a value or a reason with no source stays out of the laws;\n\
- a missing test gets written.\n\
\n\
Each settled gap states the decided behaviour in its law, fixes the reference, and comes with a test in every host it touches. Ask the owner only a business choice no rule settles, such as the support matrix, the product scope or the owner's own rationale, with its evidence.\n\
\n",
// § end xyd17m6cv.e
// § xyd17m6cv.f@xzqvv
"## Ledger\n\
\n\
Keep it in `docs/silcrow-adoption.md`, outside the `notes` list: the notes speak about the product only. Keep three lists in it by hand, never pruned:\n\
\n\
- decided: each gap settled, by which rule, and the change made;\n\
- removed: each law cut, and where its content went;\n\
- open: each business question for the owner, with its evidence.\n\
\n\
Derive coverage and carriers from `{list}` and `{stats}`, never from a hand-kept inventory. Cite a symbol, never a line number.\n\
\n\
## Stop\n\
\n\
- Stop when every promise maps to a law, `{fix} --all` then `{check} --all` pass, and a fresh verifier finds no false law and no wrong carrier on a sample of the laws and their markers.\n\
- A law refuted three times goes to the open list with its evidence.\n\
- Stop iterating when two rounds in a row add no refutation and no uncovered promise, or when a round adds only laws that restate others or values with no reason.\n",
// § end xyd17m6cv.f
),
install = cmd("install"),
author = cmd("agent author"),
code = cmd("agent code"),
list = cmd("list"),
fix = cmd("fix"),
check = cmd("check"),
stats = cmd("stats")
)
}
fn topic_review() -> String {
// § pdjjwdpt2@syphv
format!(
concat!(
"# Facet: Reviewer\n\
\n\
Use when the session reviews a change that another agent or a person made, before it is accepted or merged. The main agent spawns every finder and verifier as a fresh agent and runs each stage itself: a finder never spawns a verifier. Without a subagent tool, run each in a fresh session.\n\
\n",
// § pdjjwdpt2.a@b47th
"## Find\n\
\n\
Run `{diff} --md`, with `<ref>` for the point the change started from. The packet holds one entry per law the change touched, riskiest first, then the changes under no law. The law is the unit, never the file.\n\
\n\
Spawn one finder per law entry. It gets the entry and the repository, never the author's summary. It reads the law's text on both sides, then each place: the span on both sides, the code before the span, the followed callees and the doc sections. It answers the entry's `Check:` line against the text as it now reads:\n\
\n\
- Deleted, retired or removed: no place still carries the old rule, and the successor, when there is one, carries it now.\n\
- Behaviour change accepted: the author re-pinned it. Judge the new code against the clause, not against the old code.\n\
- Reminted from one id to another: the new words state the same decision, since a change of sense is a strike and a successor.\n\
- New or text changed: the code does what the new text says. A clause with no place under it is not implemented. A law or a clause says what the product does or supports: one that states only an absence, something not done, not needed or not supported, is a finding, answered by the supported scope or by a cut.\n\
- Code changed: the pin still reads true, whatever moved in its span, its stretches or its callees.\n",
// § hr2j2031z.e@n90m0
"- Every law or clause whose text is new or changed: it is singular, verifiable and unambiguous, it holds no vague word such as fast, appropriate or as needed, and it reads no better as a table of row clauses. A miss is a finding that quotes the clause and cites its `path:line` in the note.\n",
// § end hr2j2031z.e
// § xyd17m6cv.i@6k7kt
"- Made a draft: the law or clause is meant to wait for code again, and nothing still relies on the code its markers covered. A draft that is new owes no place yet, and one that is no longer a draft has a marker on the code that carries it.\n",
// § end xyd17m6cv.i
"\n\
A marker belongs in the block that holds its clause, with a `§ end` only when the rest of the block is not governed by the clause: a stretch that leaves out code the clause governs is a finding, and so is a `§ one` marker on a statement whose value the clause still governs further down.\n\
\n\
Check that a `§ one` marker on a binding carries the decision, and not only a value that the decision uses further down.\n\
\n\
One more finder takes the changes under no law and says of each hunk whether it carries a business rule. One that does lacks a marker, or a law.\n\
\n\
A finding quotes the clause it breaks and cites the `path:line` that breaks it, with why. One without both is dropped. Holds is a full answer, and the right one when nothing breaks the text. Style, naming and taste are not findings.\n\
\n",
// § end pdjjwdpt2.a
// § pdjjwdpt2.b@h6vbn
"## Verify\n\
\n\
Spawn one fresh verifier per finding. It gets the law text and the cited code, never the finder's reasoning, and confirms with the line it read, or refutes. Keep only a confirmed finding whose `path:line` and quote resolve.\n\
\n",
// § end pdjjwdpt2.b
// § pdjjwdpt2.c@y8qsk
"## Report\n\
\n\
Report each law as holds, or does not hold with its confirmed findings, ranked by severity:\n\
\n\
- blocking: the code breaks a clause, or a retired rule still lives in a place;\n\
- important: a clause has no place, a marker sits on code that does not decide its clause, or a hunk carries a rule with no law;\n\
- minor: the rest worth a person's read. It never blocks.\n\
\n\
Name laws as `{cite}` says.\n\
\n",
// § end pdjjwdpt2.c
// § pdjjwdpt2.d@tv080
"## Stop\n\
\n\
After the author fixes, review again only the laws the fix touched and the open findings. A new finding counts only when the fix caused it, and a refuted one is raised again only with new evidence. Stop when a round confirms nothing new, or after three rounds, and hand what is still open to a person.\n\
\n",
// § end pdjjwdpt2.d
"Never run `accept` or `fix` on the change under review, with or without `--write`: a re-pin approves it, and a release build writes without `--write`. Run `{check}` to confirm the graph holds. `--json` prints the same review for a script.\n",
),
diff = cmd("diff"),
check = cmd("check"),
cite = cmd("agent cite")
)
}
fn topic_monorepo() -> String {
// § xyd17m6cv.k@5s97t
format!(
"# monorepo\n\
\n\
A repository of several projects, each a directory whose `AGENTS.md` holds a `<silcrow>` block.\n\
\n\
## Where to run\n\
\n\
- A verb acts on the nearest project above the working directory. A project's tree stops at the next project below it, so two projects can declare the same id.\n\
- Run each command from the project whose laws you touch, or name it: `{run} -C <dir> <verb>` runs as if started in `<dir>`, as `git -C` does.\n\
- `{check} --all`, `fix --all`, `list --all`, `diff --all`, `eject --all` and `accept --drifted --all` act on every project. CI runs `{check} --all`, which also fails on a marker in a file outside every project.\n\
- `{run} -C <dir> check` checks the project of `<dir>` alone, and `--path <file>` keeps the findings of a file and of each drifted pin that reads it.\n\
\n\
## Several blocks\n\
\n\
- A new nested project starts as an `AGENTS.md` with a block in its folder: write it, then run `{install}` there. Each project has its own notes and its own policy.\n\
- All blocks of a workspace name the same `default-branch`.\n\
\n\
## Laws of another project\n\
\n\
- A marker of another project's law names it by its path from the git root: `// § libs/money:k924mpp7r`. It is pinned against that project's text, so an edit of the law there fails the pin here.\n\
- A project that must implement another's law adopts it with a paragraph that is only the bold head, `**§ libs/money:k924mpp7r**`, in one of its notes, and then owes markers for it.\n\
\n\
## Hooks and worktrees\n\
\n\
- The hooks and the skill pointer live once, at the git root. In a linked worktree, `{install}` writes the block and the skill pointer and no hook, since every worktree runs the hooks of the main checkout.\n\
- Never run `{install}` where the repository's instructions say hooks are shared. Where `core.hooksPath`, hk, lefthook, pre-commit or a `hook.*` git config entry manages the hooks, `{install}` writes none and names the line `silcrow hook <event> \"$@\"` to add for each event: ask the owner to add them to the manager.\n",
run = run(),
check = cmd("check"),
install = cmd("install"),
)
}
fn topic_cite() -> String {
format!(
"# cite\n\
\n\
An id named in an interactive session is a link to the law and carries a short summary.\n\
\n\
- Link it. Write the id as a markdown link whose target is the note path from the git root plus `#<id>`. `{list}` prints the note path. Never write it as plain text or in backticks: both are inert.\n\
- Drop the fragment only in a client that mishandles it, and link the note alone there. Cursor is such a client: it does not split the `#` fragment from the path.\n\
- Never use a line number as the target.\n\
- A law of another project of the workspace is named `<projectpath>:<id>` in the link text.\n\
- Summarise it. Put a few words in parentheses right after the link, in your own phrasing. Do not quote the carrying sentence.\n\
- A range is two links, one per endpoint. Name every letter in between that matters.\n",
list = cmd("list")
)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn pointer_is_the_asset_in_every_build() {
assert_eq!(pointer(), SKILL_SRC);
assert!(SKILL_SRC.contains("\nname: silcrow\n"));
assert!(SKILL_SRC.contains("silcrow agent"));
assert!(!SKILL_SRC.contains("cargo run"));
assert!(!SKILL_SRC.contains("globs:"));
assert!(!SKILL_SRC.contains("## Bootstrap"));
assert!(!SKILL_SRC.contains("## Delegate"));
assert!(!SKILL_SRC.contains("agent explore"));
}
#[test]
fn index_lists_topics_and_explore_is_separate() {
let idx = index();
assert!(idx.contains("Silcrow agent"));
assert!(idx.contains("`explore`"));
assert!(idx.contains("`author`"));
assert!(!idx.contains("subject, not the judge"));
let explore = topic_explore();
assert!(explore.contains("subject, not the judge"));
assert!(!explore.contains("Facet: Verifier"));
assert!(!explore.contains("Facet: Author"));
}
#[test]
fn code_names_every_follow_mark_and_answers_drifting_pins() {
let code = topic_code();
for mark in [
"silcrow:technical",
"silcrow:functional",
"silcrow:skip",
"silcrow:follow",
] {
assert!(code.contains(mark), "{mark}");
}
assert!(code.contains("My pins drift too often"));
assert!(code.contains("A business rule in a helper changed and nothing failed"));
assert!(code.contains("`// § end <address>`"));
}
#[test]
fn code_says_code_that_carries_no_law_carries_no_marker() {
assert!(topic_code().contains("Code that carries no law carries no marker."));
}
#[test]
fn author_resolves_a_contradiction_by_a_strike_and_a_successor() {
let author = topic_author();
for line in [
"Two active laws that contradict are a defect.",
"Neither wins by being later, more specific, or citing the other.",
"Strike one and declare the successor under a new id.",
"A condition that narrows a law is a clause of that law.",
] {
assert!(author.contains(line), "{line}");
}
}
#[test]
fn author_never_invents_a_nine_character_id() {
assert!(topic_author().contains("Never invent a nine-character id."));
}
#[test]
fn accept_sends_a_change_of_sense_to_a_strike_and_a_successor() {
let accept = topic_accept();
assert!(accept.contains("Use it for form"), "{accept}");
assert!(
accept.contains("A change of sense is a later clause, or a strike and a successor."),
"{accept}"
);
}
#[test]
fn explore_names_the_acts_that_end_it() {
assert!(topic_explore().contains(
"Explore ends when the session starts declaring, citing, retiring, or writing code and docs that must carry a marker."
));
}
#[test]
fn review_judges_each_law_and_what_no_law_governs() {
let review = topic_review();
assert!(review.contains("diff --md"));
assert!(review.contains("Check:"));
assert!(review.contains("the changes under no law"));
assert!(index().contains("`review`"));
assert!(print(Some("review")).is_ok());
}
#[test]
fn review_sends_a_finder_per_law_and_a_blind_verifier_per_finding() {
let review = topic_review();
for line in [
"Spawn one finder per law entry.",
"never the author's summary",
"A finding quotes the clause it breaks and cites the `path:line` that breaks it",
"One without both is dropped.",
"Holds is a full answer",
"Spawn one fresh verifier per finding. It gets the law text and the cited code, never the finder's reasoning",
"Keep only a confirmed finding",
"ranked by severity",
"- blocking:",
"- important:",
"- minor:",
"review again only the laws the fix touched",
"Stop when a round confirms nothing new, or after three rounds",
"Never run `accept` or `fix` on the change under review, with or without `--write`",
] {
assert!(review.contains(line), "{line}");
}
}
#[test]
fn adopt_prints_roles_order_test_rule_ledger_and_stop() {
let adopt = topic_adopt();
for line in [
"Writer:",
"Run one writer per note, in parallel.",
"Verifier: a different and stronger model than the writer, or at least a fresh context that sees only the code, the docs and the law text, never the writer's reasoning or verdicts.",
"is it true in every host and copy, does a source independent of the adoption state it, is it a decision with a stated reason, is it one decision",
"stop a verifier that wrote no line for 20 minutes",
"the `cargo run -q -- list` output, the candidate carriers, the test names and the design notes",
"Gap finder:",
"1. Promises:",
"4. Tests:",
"5. Code:",
"A law has a reason the project states",
"a value with no stated reason",
"never as a restatement of the code",
"No marker on a forwarder, a constant, a type, a field, or code that does the opposite of the law.",
"if this line did the opposite, would the law break? If the law broke, would this pin move?",
"never in the middle of a fluent chain or inside a large config object",
"a pure move, and prove it by its diff. Never add the file to an allowlist.",
"merge it into the core law and mark each host as a copy",
"A sentence the adoption wrote, in a note or in the docs, is never a source.",
"a promise decided and not built stays a draft",
"Derive coverage and carriers from `cargo run -q -- list` and `cargo run -q -- stats`, never from a hand-kept inventory. Cite a symbol, never a line number.",
"A test marker only for a law whose deciding code is not in this tree",
"place the marker on the assertions that check the clause",
"a documented promise wins over code that breaks it",
"align on the reference, else on the majority",
"a silent drop becomes an explicit failure",
"a value or a reason with no source stays out of the laws",
"a missing test gets written",
"Ask the owner only a business choice no rule settles",
"`docs/silcrow-adoption.md`",
"- decided:",
"- removed:",
"- open:",
"no false law and no wrong carrier",
"A law refuted three times goes to the open list",
"never install hooks",
"in a separate clone of the project, or ask the owner of the shared hooks to install",
"lists each hook, `AGENTS.md` block and skill file that differs",
"Never write outside the project.",
] {
assert!(adopt.contains(line), "{line}");
}
assert!(
!adopt.contains("write the `AGENTS.md` block and the skill pointer by hand"),
"{adopt}"
);
assert!(index().contains("`adopt`"));
assert!(print(Some("adopt")).is_ok());
}
/// The topics an agent reads say what the laws say: a comparing check names every change a
/// person must see and the command CI runs, and a person runs `squash`.
#[test]
fn the_check_and_verifier_topics_follow_the_comparing_check_and_squash_laws() {
let check = topic_check();
for line in [
"names, without failing, each change a person must see before the merge",
"every law deleted, struck or kept only as an alias anchor",
"every change to the text of a law or of a clause it held",
"every attribute of the Silcrow block written otherwise",
"every draft the point did not hold",
"check --all` on a pull request",
] {
assert!(check.contains(line), "{line}");
}
let verifier = topic_verifier();
assert!(verifier.contains("ask a person to run"), "{verifier}");
assert!(!verifier.contains(", run `"), "{verifier}");
}
#[test]
fn author_adopt_and_review_state_a_law_as_what_the_product_does() {
assert!(topic_author().contains("never only an absence"));
assert!(
topic_author().contains("\"runs on Linux and macOS\" rather than \"refuses Windows\"")
);
assert!(topic_adopt().contains("never only an absence"));
assert!(topic_review().contains("one that states only an absence"));
}
#[test]
fn adopt_names_the_public_docs_last_and_keeps_a_private_rule_a_law() {
let adopt = topic_adopt();
for line in [
"Adopt with `docs=\"\"` in the `AGENTS.md` block",
"Once the laws are true and reviewed, ask the owner which public documentation the project has",
"never in internal docs such as architecture notes",
"The doc duty never drives a law. Write public prose from the product, for its readers, never from a law.",
"A docs line the adoption added stays correctable",
"A business rule that must not be public is still a law",
"a plain `§` with no `!`, and its note is its home: it owes no documentation marker",
] {
assert!(adopt.contains(line), "{line}");
}
assert!(!adopt.contains("too internal"), "{adopt}");
}
#[test]
fn code_re_pins_a_drift_with_accept_alone() {
let code = topic_code();
assert!(
code.contains("To re-pin drifts, run one `accept` with all their addresses"),
"{code}"
);
assert!(code.contains("`fix` pins no drift"), "{code}");
assert!(code.contains("a wide pin is a defect"), "{code}");
}
#[test]
fn check_gives_the_protocol_of_a_large_repository_and_a_merge() {
let check = topic_check();
for step in [
"Never accept a drift that was already there",
"--law <address>",
"agent accept` says",
"--path <file>",
"--json",
"On a branch that no remote holds",
"so an agent sandbox can allowlist it",
"Run formatters and the linters that fix in place",
"`cargo run -q -- fix --write` resolves exactly those blocks",
"never resolve a digest conflict by taking either side",
"--remint`, a commit of that alone",
" -C <dir> check",
] {
assert!(check.contains(step), "{step}\n{check}");
}
let code = topic_code();
assert!(!code.contains("## Large repositories"), "{code}");
assert!(code.contains("agent check"), "{code}");
assert!(topic_monorepo()
.contains("Never run `cargo run -q -- install` where the repository's instructions say hooks are shared"));
}
#[test]
fn code_adopt_and_review_place_a_marker_on_its_block_first() {
assert!(topic_code().contains("Place the marker in the block that holds the clause first"));
assert!(
topic_adopt().contains("Place each marker in the block that holds its clause first")
);
assert!(topic_review().contains("A marker belongs in the block that holds its clause"));
assert!(topic_code().contains(
"two markers whose spans are the same code, or overlap without one holding the other, fail `check`"
));
assert!(topic_code().contains("guards nothing and fails `check`"));
}
#[test]
fn code_adopt_and_review_keep_a_one_marker_to_a_statement_that_carries_the_whole_clause() {
let block = "a value computed there and used further down takes the block";
assert!(topic_code().contains(block));
assert!(topic_adopt().contains(block));
assert!(topic_review().contains(
"a `§ one` marker on a statement whose value the clause still governs further down"
));
assert!(topic_review().contains(
"Check that a `§ one` marker on a binding carries the decision, and not only a value that the decision uses further down."
));
}
#[test]
fn a_topic_that_repeats_help_is_gone() {
for topic in ["list", "diff", "log", "install", "help"] {
assert!(print(Some(topic)).is_err(), "{topic}");
}
}
#[test]
fn unknown_topic_fails() {
let err = print(Some("markers")).unwrap_err();
let msg = err.to_string();
assert!(msg.contains("unknown agent topic: markers"));
assert!(msg.contains("author"));
}
#[test]
fn monorepo_is_a_short_topic_the_index_and_code_name() {
// § xyd17m6cv.k@gvf0p
let text = topic_monorepo();
assert!(text.lines().count() < 40, "{text}");
for needle in [
" -C <dir> <verb>",
"check --all",
"`**§ libs/money:k924mpp7r**`",
"// § libs/money:k924mpp7r",
"linked worktree",
"silcrow hook <event>",
] {
assert!(text.contains(needle), "{needle}: {text}");
}
assert!(!text.contains("test-markers"), "{text}");
assert!(index().contains("- `monorepo`:"));
assert!(topic_code().contains("agent monorepo"));
assert!(print(Some("monorepo")).is_ok());
}
}