Skip to content

Latest commit

 

History

History
181 lines (134 loc) · 12.2 KB

AGENTS.md

File metadata and controls

181 lines (134 loc) · 12.2 KB

AGENTS.md

Guidance for coding agents working in this repository.

Project overview

Keeptrack is source-available (PolyForm Strict 1.0.0, see LICENSE, not open source). It saves and reviews everything read, watched, listened to or played: books, movies, TV shows, albums, video games, playlists, gear and collectibles, plus car, house and health journals.

Three-tier .NET 10 / C#: BlazorApp (Blazor Server UI), WebApi (ASP.NET REST API), MongoDB.

The design is described in docs/, starting at docs/README.md.

Hard rules

Never run a third party container image on this workstation. No docker run and no docker pull of any image not published by Docker or by GitHub. Security scanners are invoked as locally installed binaries, never containerised. A tool with no local install path is left unwired and recorded in docs/backlog.md.

An agent writes Markdown that is already correct, and never runs a linter for YAML or Markdown. No markdownlint, no yamllint, no npx invocation of any of them, since IstarCI's markup-lint job runs them on every commit, and an agent fixes what that job reports against its own changes. Reading a lint configuration and reshaping text to fit it, or rewrapping a paragraph so a tool would be quieter, is the same thing as running the linter. Test commands are not linters.

neatmd, the owner's own formatter, is not a linter, and finds format issues before a commit. If it is installed, as the npm package or the local repository, an agent runs node ~/repos/neatmd/bin/cli.js --check <files> after editing Markdown. It reads what a change would be with -o <file>, applies the changes that are right, and reports a wrong one as a neatmd issue instead of applying it.

Every command runs in the foreground, and the agent waits for it. No background command, no subagent, no fork, no parallel task, even for a long command.

Only GitHub Actions published by github or docker are allowed in workflows. Reusable actions owned by this account, in ../github-workflow-parts, are also allowed. Anything else is replaced by an explicit command that downloads the official release binary and verifies its SHA256 checksum.

IstarCI is recommended but optional, and runs from its package. The CI is the GitHub Actions pipeline, which IstarCI only runs locally first. task ci:setup, task ci, task ci:wait and task ci:logs use the installed @devpro/istarci package, and a clone of IstarCI is for developing IstarCI only (task ci:from-clone). A local run never receives a secret, not even a low-value one: a test needing a service gets a local stand-in, or skips. An agent never loads Local.runsettings, nor sets TEST_LIVE_PROVIDERS=true: every package a test loads can read what its process holds. If IstarCI is installed, as the npm package or the local repository, its daemon runs the pipeline on every commit by itself, linters and Sonar included, so an agent never starts a run. After committing, an agent waits for the result with istarci wait (or task ci:wait), which waits for the run of HEAD and prints the log of each failed job. It never polls task ci in a loop. The pre-push hook gates a push on the same run.

The harness is Node.js and bash only. Python scripts or code is not allowed.

Test before code when applicable. Tests are written before the implementation and versioned as the source of truth for expected behavior. A regression test is seen failing for the stated reason before the fix, a refactor of untested code gets its test first, seen green against the unmodified code.

Preserve existing comments and formatting when editing a file.

Commit only when asked, and never push. A branch is created only when a commit is asked for and the checkout is on main, and then it is a feature branch. A commit never names the agent, for example Claude, so it has no Co-Authored-By line for it. The first line of a commit message is short and summarizes the change, then an empty line, then the detailed description of the changes.

Documentation is as short as possible, and headers stay. Short documentation still has sections. It keeps what is needed to understand the code: why it is shaped this way and the known gotchas, never the story of how it got there.

Writing style

These are hard rules too. They apply to Markdown, code comments, commit messages, chat replies, command output, input descriptions, error message strings and any prose in scripts. They are the repository's conventions, applied by default: a report states what the repository does, never presents a convention as the reader's request.

Natural, simple English, in the style of ASD-STE100. Short sentences in the active voice, with common words.

One thought per line. Every sentence starts on its own line, and the renderer joins them back into a paragraph, so a diff shows only the sentence that changed. A sentence that runs long may continue on the next line at a clause boundary ("so", "and", ","), never mid-clause. Lines follow .editorconfig: at most 240 characters in Markdown, and 180 in YAML and code.

A comment says why, not what, and the why is timeless. The code says what it does. A comment records only what cannot be read off it: the failure it prevents, the constraint that made the obvious shape wrong, the alternative rejected and why. It is written as if it had always been so: never "used to", never "this replaced", never the story of the session that produced it. "filters the parent id with Eq, since MongoDB allows one $text per query" earns its place, "filter by parent" does not. A comment that would restate the member name, or a paragraph that walks through the method below it, is left out.

A code comment starts with a verb in lower case, with no full stop at the end of a single sentence. "sets X for Y", "uses X, because Y", "does X, so that Y". Not "Read by X as Y, the Z being W".

Never use the em dash (—) or the en dash (–), nor a spaced hyphen standing in for one. Use a colon when introducing an explanation, a comma when joining clauses, or a full stop and a new sentence.

Never use the second person. No "you", no "your", not even in placeholders such as <your-token>, which reads <token>. The documentation describes the repository, it does not address a reader. The contribution terms in CONTRIBUTING.md are legal text and the one exception.

Other conventions. Use ini as the fence language for .properties blocks, never properties. Prefer > over → for UI navigation, for example Project Settings > Quality Gate, arrows remain acceptable in diagrams.

Repository conventions

This file holds the rules and conventions an agent applies on every change. The design of each subject, its reasons and its gotchas live in docs/, one file per subject, indexed in docs/README.md. A fact is written in one place and linked from elsewhere, never copied, except commands. What was done and when is git history's, and a sentence that only says something used to be otherwise is deleted rather than kept.

Shell scripts are named in snake_case and committed with the executable bit set (git update-index --chmod=+x path/to/script.sh), since a script committed as 100644 fails on a fresh clone.

The root README.md stays as short as possible. CONTRIBUTING.md holds only the guided steps to be up and running. Known debt not yet scheduled is listed in docs/backlog.md.

Target platform is Linux, including WSL2, and bash.

Commands

dotnet restore && dotnet build

dotnet run --project src/WebApi      # https://localhost:5011/
dotnet run --project src/BlazorApp   # https://localhost:7042/

dotnet test --project test/WebApi.UnitTests/WebApi.UnitTests.csproj
dotnet test --filter-method "Keeptrack.WebApi.UnitTests.Services.WatchNextServiceTest.ComputeInProgressShows_*"

dotnet test --project test/WebApi.IntegrationTests/WebApi.IntegrationTests.csproj --filter-method "*WishlistResourceTest*"

E2E_ENABLED=true TEST_AUTHENTICATION_MODE=local dotnet test   # every suite, end-to-end included, before a commit

Every test runs locally before a commit that can affect them, then IstarCI runs on the commit. A change to documentation or to labs/ alone needs no run. The filtered runs above are for the loop while writing a test. IstarCI runs every suite (see .istarci.yml), and the tests of a live provider skip in both.

Integration tests need MongoDB, and authenticate locally with a key generated for the run. A live provider or Firebase run is the owner's: CONTRIBUTING.md explains both.

Where to read before changing

File Read before changing
Architecture A controller, error handling, a background job, authorization, the free tier, an admin setting, an outbound HTTP client
Authentication Sign-in, a token claim, the authentication mode, or a test identity
Data model A model, entity, DTO, mapper, repository filter, index or stored field name, or when adding a trackable type
Blazor UI A page, a list filter, persisted state, a shared component, styles or icons
Collections Ownership, gear, collectibles, playlists, Wishlist, Watch Next, Quick Add, user preferences
Journals Car, house or health, their metrics or charts
Sharing The wishlist link or collection sharing
Imports A transaction import or the TV Time import
Explore The Explore catalogue, its exclusion or paging
Reference data Enrichment, a reference link, ratings, the sync, the reference export or import
Reference matching Anything deciding whether a candidate is a work, before loosening any rule
Providers A provider client, its query, quota or registration
Testing A test fixture, cleanup, or an end-to-end test
CI and code quality A workflow, .istarci.yml, or a Sonar finding

A new finding is added to the file its subject belongs to, and a reported bug is checked against these files first, since some behavior is by design.

Quality bar

The owner has zero tolerance for bad design or duplicated algorithms, for new and existing code alike.

  • No duplicated algorithms or logic. Duplicated data shapes (Model, Entity and Dto) are expected, duplicated logic over them is not. Shared behavior belongs in a base class or shared method, following DataCrudControllerBase<TDto, TModel>, MongoDbRepositoryBase<TModel, TEntity>, InventoryPageBase<TDto>, ReferenceLinkedDetailPageBase, JournalDetailPageBase, OwnedItemImportCommitCoordinator, ChartAxes.
  • Every non-trivial piece of logic needs a test, especially per-type overrides like GetFilter, where bugs have historically hidden.
  • Don't guess when the information isn't there: resolution, imports and Watch Next leave something unresolved rather than ship a confident wrong answer.
  • A mocked-repository test cannot prove MongoDB semantics: filters, collation, null storage and indexes need a real-MongoDB integration test.
  • Current best practice for the library and framework version in use is verified before proposing a fix.

Code style

  • Enforced by .editorconfig: 4-space indent for C# and Razor, LF endings, var everywhere, braces required, _camelCase private fields, s_camelCase private static, PascalCase otherwise, no this..
  • Primary constructors are the norm for controllers, repositories and API clients.
  • Nullable reference types are on across src, with required for non-nullable properties with no sensible default.
  • Public WebApi.Contracts DTOs and controllers carry XML doc comments, which feed the OpenAPI/Scalar docs.
  • A log line is a [LoggerMessage] method, see Architecture.