diff --git a/.agents/skills/codebase-standards/SKILL.md b/.agents/skills/codebase-standards/SKILL.md new file mode 100644 index 00000000..d25f6371 --- /dev/null +++ b/.agents/skills/codebase-standards/SKILL.md @@ -0,0 +1,68 @@ +--- +name: codebase-standards +description: devvm's standards for keeping its code clean and safe, as a short checklist for a commit and a review, drawn from what reviews of devvm's history kept finding (fallbacks that fail open, unbounded or trusted input from a VM, secrets in arguments, hand-rolled parsers, swallowed errors, processes without an owner, runs that a kill or a second devvm breaks, copies of an owner, running VMs at an upgrade, overclaims, fixes without a failing test, tests that need one machine), and how new code matches the existing code's style. Use before a commit, when reviewing a change or a branch, and when a review's finding may be one a standard covers. +--- + +# devvm's codebase standards + +Reviews of devvm's code kept finding the same mistakes, in code that different people and agents wrote for different features. This skill turns each of those into a standard, so a change meets it before a review has to find it, and it says how new code matches the code already there. It isn't a rulebook to apply line by line: a standard matters where a change touches its ground, and each one is here because it recurred or because missing it was costly. + +- [standards.md](standards.md) has a section for each standard: the rule, what the reviews found, sometimes a pair of devvm's code that breaks it and code that keeps it, and its guard. +- [rules.md](rules.md) lists the rules that AGENTS.md and the Contributing pages hold, each with what guards it, so a reviewer knows what the gate checks and what's left to read. + +A command follows the [cli skill](../cli/SKILL.md), prose and messages follow the [docs-voice skill](../docs-voice/SKILL.md), and a sandbox or a backend's emulation gets its threat check with the security-audit skill, so this skill doesn't restate them. + +## The checklist + +Go through the items that a change touches. Each links to its section in [standards.md](standards.md). + +Safety: + +1. **[Fail closed, on every path.](standards.md#fail-closed-on-every-path)** A refusal, a failure or a retry leaves things as strict as they were, and a weaker mode is visible, documented and chosen. +2. **[Bound what you don't control.](standards.md#bound-what-you-dont-control)** What a VM or another process can make devvm read, hold or wait for has a cap in size, count and time. +3. **[Treat what a VM can write as hostile.](standards.md#treat-what-a-vm-can-write-as-hostile)** Reach its files by descriptor, check what it hands back, escape its text, and run nothing it can plant. +4. **[Keep secrets and host data on the host.](standards.md#keep-secrets-and-host-data-on-the-host)** A secret stays out of arguments and shared environments, and only an allowlist crosses into a VM. +5. **[Parse once, with a real parser.](standards.md#parse-once-with-a-real-parser)** The function that checked a value reads it, and an address check knows IPv6. + +Failures and processes: + +1. **[Never fail silently, and name the real cause.](standards.md#never-fail-silently-and-name-the-real-cause)** An error is never dropped without a reason, and a message names the cause the code found. +2. **[Give every process an owner that ends it.](standards.md#give-every-process-an-owner-that-ends-it)** A context cancels it, something waits for it, and an accept loop goes on through `daemon.AcceptRetry`. +3. **[Survive a kill and a second devvm.](standards.md#survive-a-kill-and-a-second-devvm)** One good copy survives every step, and an OS file lock guards a change, with the state read again under it. + +Changes: + +1. **[Extend the owner, and wait for a third copy.](standards.md#extend-the-owner-and-wait-for-a-third-copy)** Find the owner first, and give a judge one owner at once. +2. **[Mind what's already running and released.](standards.md#mind-whats-already-running-and-released)** The CHANGELOG says what a running VM keeps, and a change to state runs on every frozen fixture. +3. **[Claim only what the code does, where precision belongs.](standards.md#claim-only-what-the-code-does-where-precision-belongs)** Precise pages hold every limit, and headline pages keep their short claims. + +Tests: + +1. **[Prove each fix with a test that fails without it.](standards.md#prove-each-fix-with-a-test-that-fails-without-it)** Its oracle comes from outside the code, an absence check has a control, and a sandbox is proven by attacking it. +2. **[Write tests that pass on any host, at any load.](standards.md#write-tests-that-pass-on-any-host-at-any-load)** A test stays off the real clock, assumes nothing about the machine, and uses stubs that behave like the real tool. + +## Match the codebase + +New code reads like the code around it. Before writing, read a neighbour in the same package and follow it. These are the habits that hold across the codebase, each with a place to see it: + +- **Names** are short and plain: `bounded`, `target`, `parsePort`, `vmLog`, and a getter has no `Get` prefix. A file holds one concern and is named for it in lower case, its words run together, such as `linksession.go` or `cloneseed.go`. A `_` in a file's name marks a build tag, a test, a generated file or a part of a parent's file, such as `internal/cli`'s `gc_caches.go` for a subcommand, since each Cobra command has its own file. A large package maps its files in a `doc.go`, as `internal/vm/doc.go` does, or in a README, as `internal/proxy` does. +- **Comments** are full sentences that say what a thing is and why it's that way, starting with its name, as `bounded` in `internal/vm/bounded.go` explains why its buffer isn't embedded. A struct's fields have a comment each where the name isn't enough, as in `vm.Options` and `vm.Env`. A test starts with a comment that states the behavior it checks, and comments describe the code as it is, never its history. +- **Errors** that the user sees are messages: `msg.PortInvalid(strconv.Quote(v)).Because(err)`, never prose built with `fmt` ([Messages](../../../docs/content/docs/contributing/cli.md#messages)). An error usually passes up as it is, as `return err`. When a caller adds context, the wrap is lower case, says what was being done or on what, and uses `%w`, such as `fmt.Errorf("reading devvm's %s: %w", name, err)` or `fmt.Errorf("backend %s: %w", name, err)`. A sentinel is a package-level `ErrX` or `errX` from `errors.New`, such as `safefile.ErrTooLong`, and callers test it with `errors.Is`. +- **Dependencies are fields.** A type's dependencies and test seams are exported fields that its constructor fills and a test replaces, as `NewEnv` fills `vm.Env`'s and a test changes the ones it needs. A call's choices go in a struct of fields, as `vm.Options` holds what `devvm` was asked for, never functional options. A package's type embeds the one `msg.Reporter` its constructor takes, and a package-level variable is rare enough that the structure test lists each one. +- **Tests** are table tests next to the code, as a map from input to what's wanted, as `TestPortsRows` has, or a slice of structs (`for _, tc := range []struct{…}{…}`), with `t.Run` where cases need names of their own. They use the standard library alone, with no assertion library, call `t.Fatal` on a setup step's error, and name the case and what came out against what was wanted, such as `t.Errorf("rows for %s: %v, want %s", shown, got, want)`. They compare a message by its ID (`msg.IDOf`, `msg.Recorder`) and run host commands through `stubtest` ([Go test helpers](../../../docs/content/docs/contributing/tests.md#go-test-helpers)). +- **Scripts in the VM** follow AGENTS.md's rules for bash 3.2 and pins, and they run on every base devvm supports, Alpine's BusyBox included, which has no `findmnt`. +- **Prose** follows the docs-voice skill, and Go follows [Go conventions](../../../docs/content/docs/contributing/_index.md#go-conventions), which the linters and the structure test enforce. + +## Reviewing a change + +1. **Read the whole diff,** and the code around each change, because a path used twice or a copy of an owner spans more than the lines that changed. +2. **Check each standard the change touches,** and the style of the code it adds against its neighbours. +3. **Check the claims** that the change adds or touches, in the docs, the CHANGELOG, comments and the commit message, against the code. +4. **Prove the fixes:** revert each fix and run its test, which must fail. +5. **Hand off what another skill owns:** a command to the cli skill's review, prose to the docs-voice skill, and a sandbox or a backend's emulation to the security-audit skill. +6. **Run the gate,** `mise run fmt && mise run lint && mise run test`, and the end-to-end sections for what changed when the change touches VMs. +7. **Report each finding** with the standard it breaks, where it is and what would fix it. A finding that no standard covers is fine to report as it is. + +## Adding a standard + +A finding becomes a standard when it has recurred, or when missing it was costly, and when a contributor can apply it while writing or reviewing a change. A one-off, a rule that a linter or a test already enforces, or a detail of one backend doesn't qualify. Before adding one, look for a standard it extends, because a short list gets used. A new standard gets a section in [standards.md](standards.md) with its rule, what the reviews found and its guard, and a line in the checklist. When a check that enforces it lands, the standard names that check as its guard. diff --git a/.agents/skills/codebase-standards/rules.md b/.agents/skills/codebase-standards/rules.md new file mode 100644 index 00000000..f3fb3912 --- /dev/null +++ b/.agents/skills/codebase-standards/rules.md @@ -0,0 +1,108 @@ +# The rules with an owner elsewhere + +These rules are written in [AGENTS.md](../../../AGENTS.md) and the [Contributing](../../../docs/content/docs/contributing/_index.md) pages, which stay their one home. Each table gives a rule in a few words, links to where it's written in full, and names what guards it, so a reviewer can skip what the gate already checks and read for the rest. A guard that names a test or a linter fails the gate when the rule breaks, except for the end-to-end checks, which `mise run e2e` runs, and the CI jobs a row names. "Review only" means nothing fails, so the reviewer checks it. + +## Go code + +| Rule | Written in | Guard | +| --- | --- | --- | +| Only `internal/ui` prints, and only `cmd/devvm` calls `os.Exit` | [Go lint rules](../../../docs/content/docs/contributing/_index.md#go-lint-rules) | forbidigo (`fmt.Print*`, `os.Stdout`, `os.Stderr`, `os.Exit`) | +| A function takes its caller's context, and a fresh one says why | [Go lint rules](../../../docs/content/docs/contributing/_index.md#go-lint-rules) | forbidigo (`context.Background`, `context.TODO`), contextcheck | +| Every `//nolint` names its linters and says why | [Go lint rules](../../../docs/content/docs/contributing/_index.md#go-lint-rules) | nolintlint | +| A function stays within 100 statements, 160 lines and a cognitive complexity of 75 | [Go lint rules](../../../docs/content/docs/contributing/_index.md#go-lint-rules) | revive | +| No type has more than 24 methods, no `func init`, and few package vars | [The structure test](../../../docs/content/docs/contributing/structure.md#the-structure-test) | the structure test's `max-methods`, `no-init` and `package-vars` | +| Packages import only down their layers | [The structure test](../../../docs/content/docs/contributing/structure.md#the-structure-test) | the structure test's `layers` | +| Test seams are fields, never package vars | [Go conventions](../../../docs/content/docs/contributing/_index.md#go-conventions) | reassign, and the structure test's `package-vars` | +| Dependencies stay on the allowlist, and the proxy's packages use the standard library alone | [Go lint rules](../../../docs/content/docs/contributing/_index.md#go-lint-rules) | depguard | +| External tools run as commands, through the UI's `LoggedCmd`, a backend's `Runner` or `internal/hostgit` | [CLI conventions](../../../docs/content/docs/contributing/cli.md#cli-conventions) | the structure test's `owners` (`commands`, `execSites`) | +| A string that goes into a shell is quoted with `shell.Quote` | [Go conventions](../../../docs/content/docs/contributing/_index.md#go-conventions) | the structure test's `literals` (`'\''` outside `internal/shell`), and `TestEmbeddedScripts` for scripts in Go strings | +| Code for one system goes behind build tags in `internal/platform` | [Go conventions](../../../docs/content/docs/contributing/_index.md#go-conventions) | forbidigo for the host's CPUs, memory and free space outside `internal/platform`, and the rest is review only | +| devvm builds with `CGO_ENABLED=0` | [Go conventions](../../../docs/content/docs/contributing/_index.md#go-conventions) | `mise.toml` and `.goreleaser.yaml` set it, and CI's `nocgo` job runs `internal/landlock`'s and `internal/proxy`'s tests that way | +| A nil value that may reach a dereference is fixed or triaged | [Nil checks](../../../docs/content/docs/contributing/_index.md#nil-checks) | `mise run nilaway` and CI's `nilaway` job, which warn without failing | +| A dependency with a known vulnerability is updated | [Tools and tasks](../../../docs/content/docs/contributing/_index.md#tools-and-tasks) | `mise run vuln` and CI's `vuln` job | + +## Owners + +| Rule | Written in | Guard | +| --- | --- | --- | +| Before adding a helper, a parser, a path, a reader, a message or a table, extend its owner | [One owner for each concern](../../../docs/content/docs/contributing/structure.md#one-owner-for-each-concern) | the checks below where an owner has one, and otherwise review only and [the consolidation pass](../../../docs/content/docs/contributing/structure.md#the-consolidation-pass) before a release | +| Each owner that has a check: `fetch`'s HTTP clients, `daemon`'s signals, `state`'s whole files, `safefile`'s reads, `paths`' folders and home, `msg.Safe`, `proxy.Public`, `proxy.NormHost`, `vmname.VM`, `redact.Secret`, `hostgit`, the agents' and toolchains' registries, and the rest | [The checks on owners](../../../docs/content/docs/contributing/structure.md#the-checks-on-owners) | the check each row of that table names, a forbidigo rule or the structure test, with `TestOwnersDoc` and `TestOwnersAgree` keeping the table and the checks together | +| A secret's value is a `redact.Secret`, revealed only where it's used, and a file that holds one writes it through its own wire type | [Secrets in the code](../../../docs/content/docs/contributing/structure.md#secrets-in-the-code) | forbidigo (`Reveal`), the structure test's checks of embedding and `Reveal() string`, and `TestSecret`, while a new secret held in a string is review only | +| Two places that must agree but can't be one have a test that they agree | [Agreement tests](../../../docs/content/docs/contributing/structure.md#agreement-tests) | each pair's own test, such as `TestDefsComplete` and `TestToolchainsComplete`, while a new pair is review only | + +## Processes and goroutines + +| Rule | Written in | Guard | +| --- | --- | --- | +| Every goroutine has something that waits for it, or says why nothing does | [The structure test](../../../docs/content/docs/contributing/structure.md#the-structure-test) | the structure test's `goroutines` (`goroutineSites`) | +| A package that starts goroutines checks for leaks | [Goroutine leaks](../../../docs/content/docs/contributing/tests.md#goroutine-leaks) | the structure test's `goroutines`, which requires `leaktest.Main`, and `leaktest.Check` in a test that starts and stops them | +| The startup check only reports, and devvm never installs host software without asking | [AGENTS.md's Rules](../../../AGENTS.md#rules) | review only | +| A command fails by returning its error, and `execute` alone prints it | [CLI conventions](../../../docs/content/docs/contributing/cli.md#cli-conventions) | `TestExecuteShowsEachFailure`, and forbidigo's printing rule | +| Whatever a failure would leave registers a cleanup with `AddCleanup`, which gets a fresh context | [CLI conventions](../../../docs/content/docs/contributing/cli.md#cli-conventions) | review only | +| A VM's state changes through `state.VM.Update`, under its lock, taken in order | [The checks on owners](../../../docs/content/docs/contributing/structure.md#the-checks-on-owners), in its paragraph on `vm.json` | `TestLockOrder`, as test builds panic on a lock taken out of order, and forbidigo's `os.WriteFile` rule | + +## The command line and messages + +| Rule | Written in | Guard | +| --- | --- | --- | +| A new or changed command follows the cli skill's checklist, then its review | [the cli skill](../cli/SKILL.md) | the tests each of its rules names, and its review for the rest | +| Arguments and flag values are checked before anything runs, and a usage error exits with 2 | [Command arguments](../../../docs/content/docs/contributing/cli.md#command-arguments) | `TestUsageErrorsEveryCommand` | +| Every message is in `locales/en.toml`, called through its generated function, with its doc link | [Messages](../../../docs/content/docs/contributing/cli.md#messages) | `TestGeneratedFileIsCurrent`, `TestEveryMessageRenders`, `TestEveryMessageIsUsed` and `TestDocLinks` | +| Prose is never built with `fmt` | [Messages](../../../docs/content/docs/contributing/cli.md#messages) | review only | +| Every question declares what answers it | [Questions](../../../docs/content/docs/contributing/cli.md#questions) | `TestQuestionsDeclareAnswers` | +| Tests check which message and with what, never its wording | [Names mode](../../../docs/content/docs/contributing/cli.md#names-mode) | the CLI tests run in names mode unless a script turns it off, while a Go test is review only | +| Messages follow the docs voice, only shorter | [the docs-voice skill's Messages](../docs-voice/SKILL.md#messages) | review only, with its `scan.sh` | + +## State and releases + +| Rule | Written in | Guard | +| --- | --- | --- | +| Every release's state keeps working, and its frozen fixture is never edited | [Released state](../../../docs/content/docs/contributing/structure.md#released-state) | `TestFixtureVMStates`, `TestFixtureVMsRead`, `TestFixtureSettings`, `TestFixtureAgentStore`, `TestStateFixturesListed`, `TestFixtureScripts` and the `fixture_v*.txtar` scripts, and a review checks that a fixture's files are unchanged | +| A change to existing state gets a Breaking entry in the CHANGELOG | [Changing what devvm does with state](../../../docs/content/docs/contributing/structure.md#changing-what-devvm-does-with-state) | review only | +| A change to the layout updates its listing, and a new layout version adds a migration | [Changing the state layout](../../../docs/content/docs/contributing/structure.md#changing-the-state-layout) | `layout.txtar`, `TestMigrations` and `TestCheckLayout` | +| Nothing goes in a project folder: state is in devvm's data and config folders | [AGENTS.md's Rules](../../../AGENTS.md#rules) | review only, as the structure test's check of paths covers only devvm's own folders | +| devvm never deletes a project VM on its own | [AGENTS.md's Rules](../../../AGENTS.md#rules) | the structure test's `owners` for the VM-name grammar (`vmname.IsVM`), so gc never takes a project VM for an image, and the rest is review only | + +## Backends + +| Rule | Written in | Guard | +| --- | --- | --- | +| A backend implements `backend.Backend`'s four roles, declares `Caps` for every feature and returns its errors | [How a backend plugs in](../../../docs/content/docs/contributing/extending.md#how-a-backend-plugs-in) | `TestRegisterChecksCaps`, `TestCapsCheck`, the conformance suite (`TestConformance`, `TestConformanceFinds`) and the structure test's `guardOwner` | +| A missing feature fails, naming the VM and what to do, and never falls back silently | [How a backend plugs in](../../../docs/content/docs/contributing/extending.md#how-a-backend-plugs-in) | the registry's guard (`TestGuardRefuses`, `TestGuardRoles`) | +| Every emulation is refused until it's reviewed | [AGENTS.md's Backends](../../../AGENTS.md#backends) | `TestUnreviewedEgressRefused` and `TestUnreviewedLetThrough`, and the review itself is a design note, a threat check and end-to-end checks | +| Lima edits only what differs, in one edit | [AGENTS.md's Backends](../../../AGENTS.md#backends) | `TestStartEditsOnlyWhatDiffers`, `TestStartWantInOneEdit`, and the fixture scripts' launches without a Lima edit | + +## Images, assets and scripts in the VM + +| Rule | Written in | Guard | +| --- | --- | --- | +| An image's key hashes everything that goes into it, the backend included | [AGENTS.md's Rules](../../../AGENTS.md#rules) | `TestKeyChangesWithEachField`, while a new input that bypasses `image.Input` is review only | +| Every download in `assets/` is pinned and checked | [AGENTS.md's Rules](../../../AGENTS.md#rules) | `TestBumpCoversPins` checks that `scripts/bump.sh` moves every pin, and a review checks that each download has one | +| A script sources the prelude before it reads its variables | [One owner for each concern](../../../docs/content/docs/contributing/structure.md#one-owner-for-each-concern) | `TestPreludeUsers` | +| Scripts in the VM are bash 3.2-safe and shellcheck-clean | [AGENTS.md's Rules](../../../AGENTS.md#rules) | shellcheck in `mise run lint:code`, and `TestEmbeddedScripts` for scripts in Go strings, while bash 3.2 is review only | +| Shared tools stay read-only in VMs | [AGENTS.md's Rules](../../../AGENTS.md#rules) | the end-to-end `tools` section's checks that the share is read-only, even for root, while a write redirected elsewhere is review only | +| Credentials never go into images, the host's agent history never goes into VMs, and devvm's own files never get a shared copy on disk | [AGENTS.md's Rules](../../../AGENTS.md#rules) | review only | +| A new or changed shared tool updates its page and follows Contributing's checklist | [Adding a toolchain](../../../docs/content/docs/contributing/extending.md#adding-a-toolchain) and [Adding a coding agent](../../../docs/content/docs/contributing/extending.md#adding-a-coding-agent) | `TestToolchainsComplete`, `TestDefsComplete`, `TestSharedToolsPolicies` and `TestConfigTools` | +| No build script is JavaScript but the docs' `docs/render-diagrams.mjs`, and no npm package is installed outside mise's tools but its pinned pele | [AGENTS.md's Rules](../../../AGENTS.md#rules) | review only | + +## Tests + +| Rule | Written in | Guard | +| --- | --- | --- | +| New logic gets a Go table test and a CLI test | [Go test helpers](../../../docs/content/docs/contributing/tests.md#go-test-helpers) | the coverage baselines ([Coverage](../../../docs/content/docs/contributing/tests.md#coverage)) | +| Tests never touch the Keychain, real VMs or your folders | [Go test helpers](../../../docs/content/docs/contributing/tests.md#go-test-helpers) | `scripts/test.sh` gives the tests a throwaway `HOME`, and the CLI tests run in a sandbox against the stubs, and the rest is review only | +| Timeouts and lifecycles are tested in a synctest bubble | [Time and lifecycles](../../../docs/content/docs/contributing/tests.md#time-and-lifecycles) | review only ([Write tests that pass on any host](standards.md#write-tests-that-pass-on-any-host-at-any-load)) | +| A test runs git only through `stubtest.Git` | [Go test helpers](../../../docs/content/docs/contributing/tests.md#go-test-helpers) | the structure test | +| The tests pass in any time zone | [Any time zone](../../../docs/content/docs/contributing/testing.md#any-time-zone) | CI runs `mise run test` in UTC on macOS and with `TZ=America/Los_Angeles` on Linux | +| A change that touches VMs passes the end-to-end sections for what changed | [End-to-end tests](../../../docs/content/docs/contributing/tests.md#end-to-end-tests) | review only | + +## Docs and commits + +| Rule | Written in | Guard | +| --- | --- | --- | +| Every behavior change updates its page in the same change | [AGENTS.md's Rules](../../../AGENTS.md#rules) | review only | +| Prose follows the docs voice | [the docs-voice skill](../docs-voice/SKILL.md) | Vale (`AIWords`, `Filler`, `QuotedCommand`) and `TestUserPageProse` in `mise run lint:docs`, and the rest is review only | +| User pages name no repo paths, Go identifiers or message names | [Writing docs](../../../docs/content/docs/contributing/docs.md#writing-docs) | review only | +| A devvm command line in the repo is one devvm has | [The CLI rule tests](../../../docs/content/docs/contributing/cli.md#the-cli-rule-tests) | `TestCommandLines` | +| The CLI reference is generated | [The CLI reference](../../../docs/content/docs/contributing/docs.md#the-cli-reference) | `TestReferenceIsCurrent` | +| One commit for each task, in Conventional Commits, with no tracker's IDs | [AGENTS.md's Commits and tasks](../../../AGENTS.md#commits-and-tasks) | CI's PR title job (`.github/workflows/pr-title.yml`) checks a pull request's title, its squashed commit's subject, against AGENTS.md's types, and the rest is review only | diff --git a/.agents/skills/codebase-standards/standards.md b/.agents/skills/codebase-standards/standards.md new file mode 100644 index 00000000..2692cb0c --- /dev/null +++ b/.agents/skills/codebase-standards/standards.md @@ -0,0 +1,243 @@ +# What reviews kept finding + +Reviews of devvm's code found the same kinds of mistake again and again, in code that different people and agents wrote for different features. Each section here is one of them, written as the standard that would have prevented it: the rule, what the reviews found, sometimes a short pair of devvm's code that breaks the rule and code that keeps it, and what guards it. A guard that names a test means `mise run test` fails when that test's case breaks, and "review only" means the reviewer checks it by hand. + +A standard applies where a change touches its ground, and judgment decides the rest. A change to how the CLI prints a table has no VM input to bound, and a refactor that keeps its tests passing needs no new failing test. + +## Fail closed, on every path + +A path that refuses, fails, falls back or tries again leaves things at least as strict as they were. A security step, such as a VM's confinement, its `.git` protection or a host check, sits on the one path that every start, retry and restart takes, rather than in each branch, so a new branch can't miss it. What a confined process reports about itself is checked against what devvm gave it, and when devvm can't tell whether something still holds, it stops the thing it can't vouch for and says so. + +A weaker mode is fine when the user sees it, the docs describe it and the maintainers chose it. devvm warns and runs a VM's proxy without its sandbox on a host that has none, for example, rather than refusing to start. What's never fine is a fallback that nobody sees. + +The reviews found this on the start's paths more than a dozen times. An export and rm's check of a `--clone` VM started it without the launch's `.git` check and network policy self-check, until both went through the launch's own start. The broker counted its own `SIGTERM` to a hung child as a failure of `sandbox-exec` and started the child again unconfined, and it took the confinement that a child's ready named, so a child it had started unconfined could report `full seatbelt`. A refused tier change could leave a looser proxy running. + +Wrong, keeping a running VM's proxy whatever it enforces: + +```go +if _, up := p.PID(vm); up && !touched { + p.Warn(msg.NetProxyKept(vm)) + return c, err +} +return c, unproxied(ctx, p, b, vm, err) +``` + +Right, as `netpolicy.Proxy.PrepareRunning` has it, keeping it only while it enforces the state's tier and both of its processes run: + +```go +if _, up := p.PID(vm); up && childProc(p, vm).Running() && !touched && enforcesNow(p, st) { + p.Warn(msg.NetProxyKept(vm)) + return c, err +} +return c, unproxied(ctx, p, b, vm, err) +``` + +**Guard:** each refusal and fallback that exists has tests, such as `TestPrepareRunningRefused`, `TestStartChildSandbox`, `TestSandboxFailed` and `TestReadConfined`, and the backend registry's guard refuses a missing feature (`TestGuardRefuses`). A new path is review only. + +## Bound what you don't control + +Anything that a VM, the proxy's child, a peer on a socket or another process can make devvm read, hold, wait for or do again has a bound in size, in count and in time. The bound goes on what devvm reads and holds, never on the pattern that recognizes it, so a long value is still found. A listener whose bytes a VM controls has read and header timeouts and a cap on its connections, and a wait on something another process holds, such as a lock, gives up after a deadline and says so. Arithmetic on a size a VM gave checks for overflow. + +The reviews found a rotation that read a sparse `proxy.log` whole into memory, a redaction that read one unended line from its start every second, locks that a child could hold for ever, and a password pattern given a length limit that then skipped a registry's long token. A writer that caps what it keeps must not embed its buffer, because `io.Copy`, as `os/exec` copies a command's output, then reads past the cap through the buffer's `ReadFrom`, as `bounded` in `internal/vm/bounded.go` explains. + +Wrong, as the proxy once read a log to rotate it: + +```go +data, err := os.ReadFile(r.path) +``` + +Right, as `internal/proxy/rotate.go` reads one, through its descriptor and no more than it keeps: + +```go +from := copyFrom(r.fd, fi.Size(), 2*r.limit) +if err := copyAtomic(r.path+".1", io.NewSectionReader(r.fd, from, fi.Size()-from), 0o600); err != nil { +``` + +**Guard:** `safefile`'s reads and `fetch.ReadCapped` have their caps, and tests keep the bounds that reviews found: `TestRotateCopiesAHugeLog`, `TestInLongLine`, `TestLongSecrets`, `TestRotateLockHeld`, `TestNixLockWaits`, `TestBounded`, and `FuzzBrokerFrames` and `FuzzFrameStreams` for the broker's frames. A new input is review only. + +## Treat what a VM can write as hostile + +A VM can write its project folder, its logs folder and the shared Nix cache, and it controls every byte it sends back. devvm reads all of it as an attacker's: + +- **Files by descriptor.** A file in a folder that a VM can write is opened once, without following a link in any part of its path and without blocking on a FIFO, through `internal/safefile`, an `os.Root` or `proxy.OpenLog`, and checked to be a regular file with one link. From then on, devvm reads, writes, empties and changes it through that descriptor (`f.Truncate`, `f.Chmod`, `futimes`), never by its path again, because the VM can swap the name between two uses. A folder, such as the project folder, is checked by its identity rather than its path. +- **Checked against what it can't choose.** What a VM hands back is checked against a source the VM can't pick. The packages a build VM records are checked on the host against Ubuntu's signed archive lists, every pocket's included, and a cached package file is hashed again before devvm keeps it. +- **Escaped for where it goes.** Text from a VM is data. It's escaped for the format it's written into, such as a systemd unit, a plist, YAML or the ssh config, and control characters are refused or dropped (`msg.OneLine`, `msg.Printable`). +- **Nothing it can plant runs on the host.** Host tools run by absolute path, with a minimal environment, and without anything that a project's config can name, such as git's hooks, filters or `core.sshCommand` (`internal/hostgit`). + +The reviews found devvm opening `proxy.log` again by its path at each start and emptying it by its path at each rotation, which would have followed a link a child left there into a file of yours, and a VM started on a project folder that was replaced after the finder found it. Host git once ran programs that a repo's config named. + +Wrong, as the Nix cache once marked a file used, by its path: + +```go +func touch(file string) { + now := time.Now() + _ = os.Chtimes(file, now, now) +} +``` + +Right, as `internal/proxy/nixcache.go` marks the file it opened (`touchFile` is `futimes` on macOS and `utimensat` with no path on Linux): + +```go +func touch(f *os.File) { _ = touchFile(f, time.Now()) } +``` + +**Guard:** forbidigo refuses `os.Open`, `os.OpenFile`, `os.ReadFile` and `os.Root`'s openers in the files that the `safefile` row of [the checks on owners](../../../docs/content/docs/contributing/structure.md#the-checks-on-owners) lists, and the child's seccomp filter on Linux refuses it a change by path (`TestSelf`). `TestOpenLogReplacesWhatIsPlanted`, `TestRotateCopiesWithoutItsPath`, `TestTrimNixCachePlanted`, `TestOneLineDropsInvisible` and `internal/hostgit`'s tests, such as `TestCommandNoHooks` and `TestCommandSSHOnly`, keep what reviews found, and the end-to-end `network` and `nix` sections plant links, FIFOs and hard links. A path-based change elsewhere is review only. + +## Keep secrets and host data on the host + +A secret never goes into a process's arguments, which any local user can read with `ps`, or into an environment that more than one process shares. It goes on standard input, into a file only you can read, or into the environment of the one child that needs it. A secret's value is a `redact.Secret`, revealed only where it's used ([Secrets in the code](../../../docs/content/docs/contributing/structure.md#secrets-in-the-code)). + +What crosses into a VM is an allowlist: the fields devvm parsed and knows, never a whole file with the known secrets taken out. A log that a VM can drive goes through `internal/vmlog`, which caps and redacts it, or through the proxy's own rotating log, and a rotation masks the start of a secret its cut leaves (`redact.Unended`). Credentials never go into an image, and your agents' history never goes into a VM. + +This was the most frequent security finding, about 15 times for secrets in arguments or a shared environment and about 11 for whole files sent to a VM. The VM's proxy password reached the guest through `limactl edit --set`, visible to `ps`, Codex and Claude Code VMs got every field of their login files rather than the ones devvm knows, and Lima's boot script, which runs under `set -x`, put the proxy password into the serial console log. + +**Guard:** forbidigo refuses `Reveal` without a `nolint` that says why, `TestStartConfined` checks that the proxy's password is in no command's arguments and goes into the VM's `lima.yaml` instead, and `TestRotateCutSecret`, `TestUnended` and `FuzzSplit` keep the redaction. The end-to-end `network` section's `netNoLeaks` looks for each VM's proxy password and the section's tokens in every run log, proxy log and Lima log. A new argument, environment variable or file sent to a VM is review only. + +## Parse once, with a real parser + +A value is read with a real parser for its format, such as `BurntSushi/toml` for mise's lock or `net/netip` for an address, never with a regular expression or `strings.Split` over a format that has quoting or escapes. The function that checked a value is the one that reads it later, so the two can't disagree, and when devvm needs a tool's effective setting, it asks the tool rather than parsing its config again. A check of an address handles IPv6, and the IPv6 forms that carry an IPv4 address (`::ffff:`, NAT64 and 6to4), as `proxy.Public` does. + +About 17 fixes came from this. Network policy files had a lenient reader in one place and a strict one in another, so a broken deny rule was skipped rather than refused. A ports value with a bad entry read as port 0, because one of several port parsers dropped `strconv.Atoi`'s error, until `backend.ParsePortRanges` became the only one. Transparent mode logged IPv6 connections as refusals, and a 6to4 address whose IPv4 address was private passed the proxy's floor as public. + +**Guard:** each owner's parser has its table tests and often a fuzz target, such as `TestParsePortRanges`, `FuzzPublicHostSite` and `TestInternalOwn6to4`, and [the checks on owners](../../../docs/content/docs/contributing/structure.md#the-checks-on-owners) keep some readers in their owner. A new hand-rolled parser is review only. + +## Never fail silently, and name the real cause + +No error is dropped without a reason in a comment: not a `Wait`'s, not a parse's, not a `|| true` in a script. A loop that skips an item it can't handle says so, and a check whose output is empty or shorter than it should be fails rather than passing. An error that devvm turns into a message keeps its cause with `.Because(err)`. + +Before a message names a cause, the code finds that cause. Errors that need different actions get different messages, and the advice in each one works in the state the user is in. A message that tells a user whose VM can't start to run devvm restart sends them in a circle. + +The reviews found about 16 swallowed errors and about 17 messages that named the wrong cause. A shared tool that failed to mount was skipped with only a line on standard error, which no page described and nobody had chosen, so mise downloaded it into the VM instead. The proxy's floor, which refuses this machine's addresses, refused none when it read no addresses. A name the host couldn't resolve was blocked with "can't resolve it" whatever the cause, so a lookup cancelled because its client went away looked like a DNS failure. + +**Guard:** errorlint, nilerr and nilnesserr catch some of it in the linters, and `TestExecuteShowsEachFailure` checks that a command's failure reaches the user. A dropped error assigned to `_` and a message's cause are review only. + +## Give every process an owner that ends it + +Every process and goroutine devvm starts has an owner that bounds it and ends it: a context that cancels it, a `WaitDelay` for its pipes, a stopper that kills a half-started pipeline, and something that waits for it. An accept loop goes on after an error that leaves its listener open, through `daemon.AcceptRetry`, because a loop that returns at the first `EMFILE` leaves its port bound and dead, while `http.Server`'s `Serve` tries again itself. + +The reviews found relays that outlived their forward and their link, and an ssh that a stuck relay held open. They also found the same accept loop written four ways, two of them returning at the first error, before `daemon.AcceptRetry` became its owner. + +**Guard:** the structure test's `goroutines` rule lists every function that starts a goroutine with what waits for it, `leaktest.Main` and `leaktest.Check` fail on a goroutine that outlives its tests ([Goroutine leaks](../../../docs/content/docs/contributing/tests.md#goroutine-leaks)), and only `internal/daemon` and `internal/platform` signal a process by its pid (forbidigo). `TestAcceptRetry` and each loop's own test, such as `TestForwarderAcceptRetries`, keep the accept loops, and `TestProcStop` stops real processes. A process's bound is review only. + +## Survive a kill and a second devvm + +Assume the last run was killed at the worst moment, and that another devvm runs beside this one: + +- **Killed runs.** A destructive step is ordered so that one good copy survives at every point, a "done" marker is written last, a file is written whole through `state.WriteFile`, and a cancelled or failed result is never cached. +- **Concurrent runs.** Two runs that change the same thing take an OS file lock (`platform`'s locks, `state.VM.Update`), and read the state again once they hold it. A lock is never a folder or a pid file, which a killed run leaves behind. + +About 13 fixes each came from these. A second devvm took a remake that was still running for one that had stopped and finished it, and an undo that failed partway could leave the saved home deleted. The remake holds the VM's lock and reads its state again under it, and it deletes the saved home only after its record is gone. Two runs that pinned a VM's host keys at once could lose one's change to `known_hosts`, and retention's lock was a folder, which a crash left held. + +**Guard:** forbidigo keeps whole-file writes in `internal/state`, and `TestLockOrder` panics in test builds on a lock taken out of order. The order of a destructive step is review only. + +## Extend the owner, and wait for a third copy + +Before adding a helper, a parser, a path, a file reader, a constant, a limit, a message or a table, find its owner and extend it, as [One owner for each concern](../../../docs/content/docs/contributing/structure.md#one-owner-for-each-concern) says. When the owner is out of reach, as most packages are for the proxy, move the owner to a package both can import. + +An owner that exists is always extended. Code that has no owner yet is different: a second copy of it is a judgment call, because a copy can be cheaper than the wrong shared helper, so wait for a third before extracting one. The exception is a copy of a judge, such as what counts as a public address or the one form of a host, because two judges that drift apart let through what one of them refuses. Those get one owner at once, and a forbidigo rule or a structure-test check where the check can be exact. + +The reviews found hosts read by hand in five packages besides the proxy, each lowercasing and trimming a dot in its own way, so a deny rule and the check it guarded could read one host as two, and `--from`'s registries judged public by a copy of `proxy.Public`. + +Wrong, as `netpolicy.RiskOf` once read a host: + +```go +host = strings.ToLower(strings.TrimSuffix(host, ".")) +``` + +Right, in the one form that every judge of a host compares: + +```go +h := proxy.NormHost(given) +``` + +**Guard:** the structure test's owner checks and the forbidigo rules in [the checks on owners](../../../docs/content/docs/contributing/structure.md#the-checks-on-owners), with `TestOwnersDoc` and `TestOwnersAgree` keeping that table current. Any other copy is review only, in [the consolidation pass](../../../docs/content/docs/contributing/structure.md#the-consolidation-pass) before a release. + +## Mind what's already running and released + +A user upgrades devvm with VMs running and with state from every release since 0.1.0, so a change says what happens to both: + +- **Running VMs.** A change to what devvm runs beside a VM, such as its proxy, its port forwarder, its agent relay or its Lima config, gets a line under After you upgrade in `CHANGELOG.md`'s Unreleased section, saying what a running VM keeps until its next start and what to run to get the change at once. The new devvm still stops, lists and reads the logs of what the old one left running. What devvm does to a running VM follows the start it runs under, not the stored setting, which the user may have changed since. +- **Released state.** A change that adds a state field runs the commands that read and write it on each frozen `testdata/v/` fixture, in the same commit, and so does a command the CHANGELOG tells users to run, as [Released state](../../../docs/content/docs/contributing/structure.md#released-state) says. A change to what devvm does with existing state gets a Breaking entry in the CHANGELOG. + +The agent relay, the ssh port that moved to one of the ports browsers refuse, and the proxy that became two processes each needed an After you upgrade line that a review found missing. The ssh config's agent once followed the stored setting rather than the VM's running start, and the settings that devvm mount-cache and devvm network transparent added to `vm.json` went in without a run of either command on 0.1.0's state. + +**Guard:** `TestFixtureScripts` and the `fixture_v*.txtar` scripts run today's commands on each release's state, and `TestV010ProxyConfigsStart` starts a broker and its child from 0.1.0's proxy configs. The CHANGELOG line is review only. + +## Claim only what the code does, where precision belongs + +The How it works pages, Staying safe, Contributing, the CHANGELOG, comments, commit messages and messages say what the code does, with its limits. A guarantee with "never", "only", "every" or "no" holds on every path, or it names the paths where it doesn't. Before a commit, check each claim the change makes, and each existing claim about the code it changed, against that code. + +The README, the home page and Getting started keep their short headline claims, such as "ready in seconds" or "reach only the hosts you allow", without qualifiers. A wrong fact gets fixed everywhere, but the precision goes on the safety and How it works pages, which those pages link to. + +Nearly every review found an overclaim on a precise page. The docs of an IPv6 fix said that every lookup in a confined VM with transparent mode off waits 35 to 40 seconds on a Linux host, from one tool's behavior. An end-to-end run on Fedora showed `getent` failing within 3 seconds and curl at once, and only workerd under wrangler dev waiting about 40 seconds. + +Wrong, from one case: + +```markdown +every lookup waits 35 to 40 seconds on a Linux host +``` + +Right, as the measurement showed: + +```markdown +most tools fail at once on macOS and Linux alike, and a few, such as workerd under wrangler dev, can wait about 40 seconds on a Linux host +``` + +**Guard:** `TestCommandLines` checks every devvm command line in the repo, `TestDocLinks` the messages' doc links, lychee the docs' links and `TestReferenceIsCurrent` the CLI reference, and the docs-voice skill's `facts.sh` checks that a rewrite kept every fact. Whether a claim is true is review only. + +## Prove each fix with a test that fails without it + +A fix lands with a test that fails without it: revert the fix, or break the code it guards, watch the test fail, then put the fix back. Code that has no test gets one that pins its current behavior before it changes. When a change breaks an assertion, either the change is wrong or the commit says why the assertion changed, and an assertion is never loosened to make a test pass. + +- **The oracle comes from outside the code under test:** the specification, a frozen copy of the old behavior, a list written by hand from the source, or the real program, never the code's own table or logic, which agrees with any bug. +- **An absence check has a control** that shows the probe can find what it looks for, such as the guest's own environment holding the token that `ps` must not show. +- **A security boundary is proven by attacking it.** A change to a sandbox, such as the proxy child's Seatbelt profile, its Landlock rules or its seccomp filter, is tested by a process under the real sandbox that tries what an attacker would, and other ways to the same thing, rather than by reading the rules back. The change also gets a threat check with the security-audit skill. + +The reviews found tests that still passed with their fix reverted, expected values taken from the function under test, and absence checks that couldn't have found anything. The Landlock filter took three rounds of review, because each attack found a call the filter allowed, such as `prlimit64` setting another process's CPU limit. + +Wrong, an oracle that is the code's own list: + +```go +if got := SSHPorts(); !slices.Equal(got, sshPorts) { +``` + +Right, as `TestSSHPorts` builds its own from the Fetch standard's list and Chromium's gaps: + +```go +want := slices.DeleteFunc(slices.Clone(fetch), func(n int) bool { return n < 1024 || slices.Contains(chromiumGaps, n) }) +if got := SSHPorts(); !slices.Equal(got, want) || len(got) != 17 { +``` + +**Guard:** the coverage baselines fail `mise run test` when a package's coverage falls ([Coverage](../../../docs/content/docs/contributing/tests.md#coverage)), and `TestSelf` and `TestChildProfileConfines` attack the proxy child's sandboxes. That a test fails without its fix, and where its oracle comes from, are review only. + +## Write tests that pass on any host, at any load + +A test passes on a loaded Linux CI runner, on a Mac in another time zone, and under `git rebase --exec`, as it does on your machine: + +- **Off the real clock.** A test of a timeout, a grace or a close runs in a `testing/synctest` bubble on stand-ins in memory ([Time and lifecycles](../../../docs/content/docs/contributing/tests.md#time-and-lifecycles)). A test that must use the real clock waits for the event, an absence included, rather than for a duration, and fails at once when what it waits on has exited. +- **No assumptions about the host.** A test brings its own git config (`stubtest.Git`), time zone, ports from its sandbox's block and temp folders, and it doesn't assume Linux or macOS, the number of CPUs, or GNU or BSD tools. +- **Stubs behave like the real tool.** A stub or fake is held to the real tool by a contract test or by golden output from the real tool, as the backend conformance suite holds the fake backend, the limactl stub and real Lima to one set of cases. +- **Stress what's timing-sensitive.** A test whose result depends on timing or order passes `go test -race -count=20` on a loaded Linux host before it counts as done, and a test that opens many connections has a cap and runs on a test host rather than your own machine. + +Tests that assumed their host failed about 25 times, on a machine's git-lfs or system git config, a time zone, a BSD tool's flags or a CPU count. The broker's start tests failed on loaded Linux hosts, because hashing the test binary took most of the 4 seconds a start waits, and a reviewer's flood test used up a Mac's local ports and broke every ssh to the test hosts. + +Wrong, sleeping out a grace on the real clock with a margin: + +```go +time.Sleep(grace + time.Second) +if !fired.Load() { +``` + +Right, as `TestGraceTimer` checks the moment itself: + +```go +synctest.Test(t, func(t *testing.T) { + var fired atomic.Bool + g := newGraceTimer(grace, func() { fired.Store(true) }) + tc.steps(g) + time.Sleep(grace - time.Nanosecond) + synctest.Wait() + if fired.Load() { +``` + +**Guard:** the structure test checks that a test runs git only through `stubtest.Git`, CI runs the tests in UTC on macOS and with `TZ=America/Los_Angeles` on Linux ([Any time zone](../../../docs/content/docs/contributing/testing.md#any-time-zone)), each CLI test's sandbox holds a block of ports, and `TestConformance` runs the backend conformance suite on the limactl stub and on real Lima's instances, while `TestConformanceFinds` checks that the suite fails a backend that breaks it. A real-clock test, the stress run and a flood's cap are review only. diff --git a/.agents/skills/docs-voice/SKILL.md b/.agents/skills/docs-voice/SKILL.md index 4060468d..db034b7b 100644 --- a/.agents/skills/docs-voice/SKILL.md +++ b/.agents/skills/docs-voice/SKILL.md @@ -69,7 +69,7 @@ All prose in the repo: - The command help that generates those CLI pages: `Short` and `Long` in `internal/cli/*.go`. Run `mise run cli-docs` after editing them. - `README.md`, `SECURITY.md`, `CONTRIBUTING.md`, `assets/oci/README.md` and `internal/proxy/README.md`. - The messages in `locales/en.toml`, which also follow the [Messages](#messages) rules below. -- The cli skill, `.agents/skills/cli/`. +- The cli skill, `.agents/skills/cli/`, and the codebase-standards skill, `.agents/skills/codebase-standards/`. These follow their own rules and are out of scope: diff --git a/.vale.ini b/.vale.ini index 139f624a..aa75a2a2 100644 --- a/.vale.ini +++ b/.vale.ini @@ -21,6 +21,10 @@ devvm.Filler = NO [.agents/skills/cli/*.md] BasedOnStyles = devvm +# The codebase-standards skill is prose for contributors too. +[.agents/skills/codebase-standards/*.md] +BasedOnStyles = devvm + # Not checked: .agents/skills/docs-voice/tropes.md, whose lists and examples # are the very words and quoted phrases every devvm rule flags, and # .agents/skills/security-audit/, which is vendored. diff --git a/AGENTS.md b/AGENTS.md index cfc7597c..0bea44fc 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -52,6 +52,7 @@ Each package's concerns and identifiers: [The packages](docs/content/docs/contri | `.agents/skills/security-audit/` | the security-audit skill, for backend reviews | | `.agents/skills/cli/` | the cli skill: devvm's command line rules, the checklist for adding a command, the tests behind each rule, `judgment.md` for the rest | | `.agents/skills/docs-voice/` | the docs-voice skill: the voice of the prose and messages, terms, tropes, `scan.sh` and `facts.sh` | +| `.agents/skills/codebase-standards/` | the codebase-standards skill: the checklist for a commit and a review from what reviews kept finding, matching the codebase's style, every rule's guard | ## Tasks @@ -72,11 +73,12 @@ Each package's concerns and identifiers: [The packages](docs/content/docs/contri - **In-VM scripts are bash 3.2-safe and shellcheck-clean** (`assets/`, `install.sh`): guard empty arrays (`${a[@]+"${a[@]}"}`), no associative arrays. Everything else is Go. - **The one exception, the docs build's Node script:** `docs/render-diagrams.mjs` (`mise run docs:diagrams`) draws the site's diagrams with pele, pinned in `docs/package.json` and its lock and installed with `npm ci --ignore-scripts`; no other build script is JavaScript, and no other npm package is installed outside mise's tools. - **Docs:** an easy-to-follow guide in full, joined sentences, every fact kept, written with the docs-voice skill; every behavior change updates its page in the same task, and the README stays high level ([Writing docs](docs/content/docs/contributing/docs.md#writing-docs)). +- **Every code change meets the codebase-standards skill** (`.agents/skills/codebase-standards/`): its checklist before committing, and its review when reviewing one. - **Adding or changing a command** follows the cli skill (`.agents/skills/cli/`): its checklist, then its review. - **Adding or changing a shared tool** updates its page and follows Contributing's checklist: `using/toolchains.md` for a toolchain ([Adding a toolchain](docs/content/docs/contributing/extending.md#adding-a-toolchain)), `using/coding-agents.md`'s Supported agents for an agent ([Adding a coding agent](docs/content/docs/contributing/extending.md#adding-a-coding-agent)). - **Docs by reader:** user pages name no repo paths, Go identifiers or message names; How it works explains mechanisms; Contributing has the paths and identifiers ([Writing docs](docs/content/docs/contributing/docs.md#writing-docs)). - **User pages lead with doing:** in `getting-started/`, `using/`, `safety/`, `backends/` and `compared/`, a task shows its command, and prose never runs to back-to-back paragraphs; one explanatory paragraph is fine, and longer mechanism moves to How it works, linked, every fact kept. -- **Extend the owner, don't copy it:** before adding a helper, parser, path, file reader, message or table, find its owner and extend it; a new owner gets a forbidigo rule or a structure-test check only when a second copy would be a bug ([Contributing](docs/content/docs/contributing/structure.md#one-owner-for-each-concern)). +- **Extend the owner, don't copy it:** before adding a helper, parser, path, file reader, message or table, find its owner and extend it (code with no owner yet gets one at its third copy, a judge at its second); a new owner gets a forbidigo rule or a structure-test check only when a second copy would be a bug ([Contributing](docs/content/docs/contributing/structure.md#one-owner-for-each-concern)). - **Edit files with the editor tools,** not `sed`, `awk`, `python`, heredocs or `cat >`. - **Ask first** before anything outward-facing (publishing, releases, repos, pushing) and before deleting anything you didn't create. - **A task that turns out wrong or incomplete:** say so and propose the change; don't quietly do something else. diff --git a/docs/content/docs/contributing/_index.md b/docs/content/docs/contributing/_index.md index 3dcf2476..9ec4a2c9 100644 --- a/docs/content/docs/contributing/_index.md +++ b/docs/content/docs/contributing/_index.md @@ -4,7 +4,7 @@ explainer: Build devvm, run its tests and follow its rules weight: 100 --- -The rules for working in the repo, for people and coding agents alike, are in [AGENTS.md](https://github.com/devvmhq/devvm/blob/main/AGENTS.md). +The rules for working in the repo, for people and coding agents alike, are in [AGENTS.md](https://github.com/devvmhq/devvm/blob/main/AGENTS.md). The [codebase-standards skill](https://github.com/devvmhq/devvm/blob/main/.agents/skills/codebase-standards/SKILL.md) turns what reviews of devvm's code kept finding into a short checklist for a commit and a review, says how new code matches the code already there, and lists what guards each rule. ## Building from source diff --git a/docs/content/docs/contributing/structure.md b/docs/content/docs/contributing/structure.md index 08400ec5..7899897a 100644 --- a/docs/content/docs/contributing/structure.md +++ b/docs/content/docs/contributing/structure.md @@ -41,7 +41,7 @@ Shell scripts that live in Go strings get shellcheck too, since lint's shellchec ## One owner for each concern -Each concern in devvm has one owner, the package or function that does it, such as `internal/hostgit` for every git command devvm runs on the host, `internal/paths` for every folder and file devvm uses, `internal/settings` for every default (`settings.Read` and `settings.Save`, over `config.toml` and `settings.json`, with each value's parser), and `locales/en.toml` for every message. Before you add a helper, a parser, a path, a file reader, a message or a table, find its owner and extend it. A second copy drifts from the first, and then one of them is wrong. [The packages](#the-packages) says what each package owns, and the failures of the checks below name the owners too. +Each concern in devvm has one owner, the package or function that does it, such as `internal/hostgit` for every git command devvm runs on the host, `internal/paths` for every folder and file devvm uses, `internal/settings` for every default (`settings.Read` and `settings.Save`, over `config.toml` and `settings.json`, with each value's parser), and `locales/en.toml` for every message. Before you add a helper, a parser, a path, a file reader, a message or a table, find its owner and extend it. A second copy drifts from the first, and then one of them is wrong. Code with no owner yet can have a second copy, because a copy can be cheaper than the wrong shared helper, so extract an owner at the third copy, or at once for a judge such as `proxy.Public` or `NormHost`, whose two copies would disagree on what's allowed. [The packages](#the-packages) says what each package owns, and the failures of the checks below name the owners too. ### The packages diff --git a/internal/cli/commandlines_test.go b/internal/cli/commandlines_test.go index 0c43012b..ac1d42ef 100644 --- a/internal/cli/commandlines_test.go +++ b/internal/cli/commandlines_test.go @@ -181,6 +181,7 @@ func commandLineFiles(t *testing.T) []string { "README.md", "AGENTS.md", "CHANGELOG.md", "SECURITY.md", "CONTRIBUTING.md", "install.sh", "docs/content", "locales", "internal", "cmd", "assets", "tests", "testdata/script", "scripts", "packaging", ".github", ".agents/skills/cli", ".agents/skills/docs-voice", + ".agents/skills/codebase-standards", } var files []string for _, s := range sources { diff --git a/mise.toml b/mise.toml index 5c73f02f..f1f1ef70 100644 --- a/mise.toml +++ b/mise.toml @@ -63,9 +63,9 @@ description = "Lint the docs" depends = ["docs:diagrams"] run = [ # Every Markdown file but the vendored security-audit skill's. - "markdownlint-cli2 'docs/content/**/*.md' '*.md' 'assets/**/*.md' 'internal/**/*.md' '.agents/skills/docs-voice/*.md' '.agents/skills/cli/*.md'", + "markdownlint-cli2 'docs/content/**/*.md' '*.md' 'assets/**/*.md' 'internal/**/*.md' '.agents/skills/docs-voice/*.md' '.agents/skills/cli/*.md' '.agents/skills/codebase-standards/*.md'", # .vale.ini says which rules each file gets, and which files get none. - "vale docs/content *.md assets/oci/README.md internal/proxy/README.md .agents/skills/docs-voice .agents/skills/cli", + "vale docs/content *.md assets/oci/README.md internal/proxy/README.md .agents/skills/docs-voice .agents/skills/cli .agents/skills/codebase-standards", "lychee --offline --no-progress --include-fragments 'docs/content/**/*.md'", # Message links: every doc link in internal/msg/docs.go is a message and # a page and heading in docs/content/docs.