tilia-0.2.0.0: AGENTS.md
## General guidelines
See `HACKING.md`.
## Docs and comments
When you write docs in source code most of them must be a single sentence
that conveys the essence of the thing you are documenting. Do not be afraid
to use precise technical terms. Prefer them strongly to multi-word plain
English formulations. Each sentence after the first one needs justification
to be included—it must be important and non-trivial information.
Do not write line comments that explain what is going on inside the code,
unless the point they convey is truly important and non-trivial. Code should
dominate comments, not the other way around.
Instead of writing in Claudisms, try to write in a style that is already
used in the codebase.
Write lines that are no longer than 76 characters, if possible. The same
applies to commit messages and especially commit headers—they always have to
be under 76 characters.
## Code
Give every function you add or change a one-sentence Haddock. A function of
several arguments gets a `-- |` line before each of them; a function of one
argument, such as `gathered :: HsModule GhcPs -> Gathered`, gets none.
Bindings in a `where` take no comments.
Use one word for one concept across a module's name, its types and
functions, the docs, commit messages and the changelog. Grep for the word
before you take it, so that it does not already mean something else.
`Tilia.Doc` is the interface to documents, and only it imports
`Tilia.Doc.Internal`; renderers build documents with
`Tilia.Doc.Combinators`. Let the layout combinators (`layoutFrom`,
`layoutAcross`, a `variant` inside them) decide layout by how something was
written rather than checking spans. To say where a token was written, give
it a region (`keywordAt`, `located`); a `fence` scopes comments. Prefer
giving the renderer a region to adding a layout primitive or a combinator.
Fix the CPP support in the merge or the machinery around it, never with a
pass that rewrites the merged document, and never by checking for directives
in rendering code. Putting back what no configuration prints (conditionals,
directives, comments, and the empty lines written between conditionals) is
that machinery.
Export a record whole, as `T (..)`.
## Fixities
Resolve an import's fixities only among the build plan's library units,
matched by package name and version, through their exposed modules; the
project's own modules count only for the project's own imports. A module
several of the plan's packages hold is read from the first of them, and
no more of GHC's package machinery is modelled. Do not model which
`ghc-pkg` a run should ask, visibility per component, or cache keys finer
than a package's identity.
Fix a fixity finding only where a real project, from a Hackage scan or a
user's report, shows a false decline or a wrong fixity, and only within
these rules; document anything else as a limitation.
## Checking your implementations
Before declaring something done, ask yourself the question: is this the
simplest and irreducible implementation of this logic? Are
simplifications/ablations possible that make the solution more elegant?
Before fixing a defect, decide whether it is an oversight, a case the
existing machinery misses, or a mismatch between the design and real code,
which no local fix cures without leaving the shapes next to it broken.
Correct an oversight in the way the machinery already works, and meet a
mismatch with a principled redesign rather than an ad-hoc fix. Try the
shapes next to the one you fix, not only its reduction.
Where the smallest fix for a rare shape adds a primitive, a constructor or a
pipeline stage, report its size and ask before building it: declining such a
module is an acceptable outcome.
## Commits and pull requests
Make one commit per cause, with its vendored example. Its title, in the
imperative and under 76 characters, names the feature that changes and the
effect a user sees, not the mechanism: "Do not report a comment carried on
under the last import as lost" for a fix to `--check-ast`. The body says
what went wrong and why, what the change does, where the problem was found,
and what it costs in the benchmarks.
## Audits
When asked to perform an audit of the codebase it means that you should scan
it for redundant or obsolete fragments (both in code and documentation), as
well as potential bugs and design flaws. Fan out agents as necessary to
accomplish this.
## Hackage scans
A Hackage scan runs Tilia over packages nobody has reviewed and looks for
what it gets wrong. Unless told otherwise:
1. **Pick 100 packages** as a seeded random sample of the packages whose
latest release is from the last two years. Take at most two of any
generated family (`amazonka-`, `gogol-`, `stratosphere-`) and leave out
packages that need `pkg-config` or a `Configure` build. Give the seed in
the report.
2. **Build the binary from `origin/master`** and copy it out of
`dist-newstyle`, so that switching branches does not change what is
being tested. Name its commit in the report.
3. **Run outside the development shell**, with only the system's GHC and
Cabal on `PATH` and an `XDG_CACHE_HOME` of the scan's own. What Tilia
decides depends on the packages `ghc-pkg` sees, and the development
shell sees far more of them than a user's machine does.
4. **Fetch each package with `cabal get`** and give it a `cabal.project`
with `packages: .` and `allow-newer: all`. Where that leaves no build
plan, try again with `packages: .` alone.
5. **Format a copy of each package** with `tilia inplace --check-ast
--check-idempotence`. Append two empty lines to every `.hs` file first:
Tilia ends what it writes with exactly one newline, so the files that
lost the padding are the ones it formatted, and the rest go back as they
were. Then `tilia check --check-ast --check-idempotence` over the result
must find nothing to change.
Read the results in this order:
- **Failed checks**, exit 27 (the program changed), 28 (not idempotent) or
29 (an exception), are defects.
- **Declines**, sorted by cause. A parse error in a configuration that no
run of cpp produces is a defect, while a macro standing for syntax, such
as `CALLCONV`, is a known decline. A fixity said to differ between two
modules, or a module that "could not be read", is often a component
Cabal did not plan, such as a benchmark or a `buildable: False` one.
- **Screens of each output against its input.** Look for:
- a different number of directives;
- words that grew, which is copied code, mostly from the CPP merge;
- words that shrank, which is lost code;
- words that changed branch, with the conditionals paired in order;
- new lines over 120 columns;
- lone keywords or punctuation on a line.
Known normalisations show up here too: one extension per `LANGUAGE`
pragma, pragma keywords in capitals, and merged imports.
- **The diffs**, split into hunks that only move line breaks and spaces and
hunks that change the text. Read every hunk that changes the text against
the input; comments must stay where they were written.
Reduce each candidate to a few lines in a one-module package outside this
repository, where Tilia's own `.cabal` file does not apply. Format it twice
with `tilia for-editor`, which reports a decline on standard error only.
Before calling it a defect, check that it is none of these:
- intended: a vendored example shows it, the changelog describes it, or an
issue was closed as not planned;
- known: look through `gh issue list --state all`;
- being fixed in an open PR.
Also check whether it is a regression by trying a binary from before the
latest commits. Verify fixity findings with a fresh cache, since the cache
is not keyed by Tilia's version.
Present the findings before filing anything, most serious first:
1. changed or broken code;
2. wrong fixities;
3. copied code;
4. false declines;
5. moved comments;
6. the cosmetic.
Say what was checked and what is intended. An issue states the problem in
one sentence, gives the input and what it "comes out as", and ends with
"Found in `package-version` `path`". Run every claim in the issue before
posting it, and quote output exactly as it was printed.