trident
Copilot instructions31 starsChanged 12 months agoMITView on GitHub
These instructions apply to Copilot agents working in this repo — both agents writing code and agents reviewing pull requests. The PR-review rules below are review-only. The "Nits" and "Architecture & structural soundness" sections apply to both writers (follow them when generating new code) and reviewers (see Reviewer etiquette for when to surface them). Trident formats with rustfmt (workspace-wide — see rustfmt.toml). Everything below is in addition to cargo fmt and is aspirational: real files don't follow every rule 100%…
The file
Show its rules and text
We split this copilot-instructions.md into the rules it gives an agent
23 rules. About 0 are common, 17 are distinctive, and 6 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈17
Distinctive · estimate
This author's own choices. Worth a look.
6
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 12
Only comment on issues that are specific to the diff (avoid generic best-practice reminders).
- Distinctive: line 13
Avoid repeating the same point across multiple files.
- Distinctive: line 14
ALWAYS check previous reviews: before commenting. Do NOT repeat points that have already been made in previous reviews if they have been …
- Distinctive: line 22
Test gaps only when risk is high or behavior changed
- Distinctive: line 26
Do NOT suggest stylistic refactors unless they fix a bug or prevent a clear maintenance issue.
- Distinctive: line 27
Do NOT request documentation unless public APIs changed.
- Distinctive: line 28
Do NOT comment on naming unless it causes real ambiguity.
- Distinctive: line 29
Do NOT suggest "add null checks" if the code is already guarded or types guarantee non-null.
- Distinctive: line 33
Prefer fewer, higher-signal comments.
- Distinctive: line 34
Use this structure when leaving feedback:
- Distinctive: line 121
Strictly prefer imports over full paths at the call site: Never:
- Very specific: line 136
When two imports would collide on the same name, prefer a sensible use … as … alias over reaching for a full path — e.g.
- Very specific: line 173
Don't alias anyhow::Result.
- Very specific: line 202
Use
anyhow::Contextto build informative error chains: when each layer adds genuinely new information (which subject failed, which path, … - Very specific: line 275
Aim for shorter expressions that remain readable: Prefer a sensible match over nested if/else if chains, especially when branching on …
- Distinctive: line 356
Before introducing a new utility, check — in this order:
- Very specific: line 369
Existing workspace dependencies: before adding a new one. Skim [workspace.dependencies] in the root Cargo.toml — glob, regex, itertools, …
- Distinctive: line 401
Prefer adding a small wrapper to the right layer and calling it over duplicating a system invocation in a subsystem.
- Distinctive: line 415
Don't drag pre-existing violations into a PR's diff: If a file already violates a nit (or already has a layering issue) on untouched lines, …
- Distinctive: line 418
Cluster comments: When a diff has several small nits in one region, leave one comment listing them — not one per occurrence.
- Distinctive: line 434
Treat the pull request description as the canonical record of the change and its validation.
- Distinctive: line 445
Never summarize validation only as "tests passed." Include the exact command or check name.
- Very specific: line 448
Delete Follow-ups and Notes when they would otherwise be empty.
≈ “Common” is an estimate: at least 1 in 5 of the 1,644 Copilot instructions files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Copilot Agent Instructions
These instructions apply to Copilot agents working in this repo — both agents writing code and agents reviewing pull requests. The PR-review rules below are review-only. The "Nits" and "Architecture & structural soundness" sections apply to both writers (follow them when generating new code) and reviewers (see Reviewer etiquette for when to surface them).
PR Review Scope
- Only comment on issues that are specific to the diff (avoid generic best-practice reminders).
- Avoid repeating the same point across multiple files. If one example demonstrates a pattern, mention it once and reference the pattern.
- ALWAYS check previous reviews before commenting. Do NOT repeat points that have already been made in previous reviews if they have been acknowledged, dismissed, or closed.
What to focus on (in priority order)
- Correctness and logic bugs
- Security issues (input validation, authz/authn, secrets, injection)
- Performance regressions (hot paths only)
- API/contract changes and backward compatibility
- Test gaps only when risk is high or behavior changed
What to avoid
- Do NOT suggest stylistic refactors unless they fix a bug or prevent a clear maintenance issue.
- Do NOT request documentation unless public APIs changed.
- Do NOT comment on naming unless it causes real ambiguity.
- Do NOT suggest "add null checks" if the code is already guarded or types guarantee non-null.
Output style
- Prefer fewer, higher-signal comments.
- Use this structure when leaving feedback:
- Issue (why it matters)
- Evidence (where in diff / what behavior)
- Suggestion (concrete fix)
Nits (Rust, applies to writers and reviewers)
Trident formats with rustfmt (workspace-wide — see rustfmt.toml).
Everything below is in addition to cargo fmt and is aspirational: real
files don't follow every rule 100% of the time. A counter-example in the tree
is not a license to ignore the rule in new code.
Imports
One
usestatement per top-level path, with a brace-tree for everything under it. Never write twouselines that share a root:// BAD use std::fs; use std::path::PathBuf; // GOOD use std::{fs, path::PathBuf};So the
stdblock is a singleuse std::{…};, each external crate is a singleuse somecrate::{…};, each workspace-local crate is a singleuse workspacecrate::{…};, andcrate::andsuper::each get exactly oneuseper group.File ordering of imports. Order the top-of-file import region in groups separated by a single blank line, alphabetical within each group:
use std::{…};- external crates (
anyhow,serde,tokio, …) - workspace-local crates (
osutils,sysdefs,trident_api,trident-proto, …) use crate::{…};use super::{…};
Then a blank line, then submodule declarations:
mod mysubmodule; mod othermodule;Then, only when necessary, submodule imports:
use mysubmodule::Foo; use othermodule::bar;A full example:
use std::{collections::HashMap, path::PathBuf}; use anyhow::{Context, Error}; use log::{debug, info}; use osutils::{files, mountpoint}; use trident_api::error::{TridentError, TridentResultExt}; use crate::engine::EngineContext; use super::Subsystem; mod inner; mod helpers; use inner::InnerThing;- Test modules: the very first line inside
mod tests { … }isuse super::*;on its own, followed by a blank line and then the standard import groups above (rules 1 and 2). - Uppercase identifiers — import directly. Types, enums, traits,
structs:
use foo::Bar;→Bar::new(…). - Lowercase identifiers (free functions) — import the parent module, not the
function.
use osutils::files;→files::write(…), notuse osutils::files::write;→write(…). This keeps call sites self-documenting and avoids name collisions. - Macros — import directly, even though their names are lowercase:
use anyhow::{bail, ensure};→bail!(…), neveranyhow::bail!(…)at the call site. Same forlog::{debug, info, warn, error, trace}. Strictly prefer imports over full paths at the call site. Never:
// BAD let a = std::submodule::Type::new(...);Always:
use std::submodule::Type; // … let a = Type::new(...);When two imports would collide on the same name, prefer a sensible
use … as …alias over reaching for a full path — e.g. when multipleContexttypes are in scope,use tera::Context as TeraCtx;and thenTeraCtx::new(…)at the call site. There is no fixed naming scheme for aliases; pick a short, locally-readable name case by case. Reach for a fully-qualified path only when even an alias would be misleading (e.g. a one-off use where the full path is the clearest documentation).When a crate provides its own
Resultalias and a file uses it more than ~5 times, prefer importing the alias. Example: in a file doing a lot of IO,use std::io::Result as IoResult; fn my_func() -> IoResult<Type> { … }over
fn my_func() -> Result<Type, IoError> { … }For imports that overload language primitives (
Result,Error,Option), always alias — never shadow the prelude name in ausewithout anas. Alias naming is case-by-case (IoResult,TeraCtx, …).Exception:
anyhow. Trident handlesanyhowerrors explicitly — importanyhow::Errorand spellResult<T, Error>out:use anyhow::Error; fn my_fn() -> Result<T, Error> { … }Don't alias
anyhow::Result.
Visibility & module layout
- Default to the strictest visibility that compiles. New items start
private (
fn,struct), graduate topub(super), thenpub(crate), and only becomepubwhen they intentionally cross the crate boundary. Be especially skeptical ofpubthat creates a dependency between distant modules — apub(crate)re-export atlib.rsis usually a better answer than reaching deep into a submodule from elsewhere.
Error handling
- Domain errors are
thiserrorenums intrident_api::error(e.g.InitializationError,InvalidInputError,ServicingError,InternalError). Prefer adding a variant to an existing enum over introducing a new one. Variants use#[serde(rename_all = "kebab-case")]on the enum and a clear#[error("…")]message. - Lift
anyhow/Result<_, E>intoTridentErrorwith.structured(<ErrorKind>)and attach human context with.message("…")(both fromTridentResultExt/ReportError). Once a result is aTridentError, prefer.message(…)over.context(…). anyhow::Resultis fine in helper modules (osutils, subsystem internals) whose callers handle errors withanyhowalready. Don't returnanyhow::Errorfrom APIs whose callers need to discriminate variants — return a structuredTridentErrorso the variant is preserved end-to-end.- Avoid
unwrap()/expect()/panic!in non-test code. Accepted patterns: (a) lift toTridentErrorvia.structured(…).message(…); (b).expect("invariant: …")documenting a static invariant. - Use
anyhow::Contextto build informative error chains when each layer adds genuinely new information (which subject failed, which path, which iteration). It is not required at every?— redundant context like.context("failed to do thing")on a function literally nameddo_thingis noise. The point is to make authors think about whether the next reader of the error can reconstruct what went wrong. - When context is a
format!(...), use.with_context(|| format!(…))instead of.context(format!(…))so the string is only built on the error path. Plain string literals stay on.context("…").
Logging
- Use the
logcrate (use log::{debug, info, warn, error, trace};) for application logging.tracingis reserved for the existingtracestream/journald wiring — don't introduce newtracing::info!callsites in code that's already usinglog.
Tests
- Inline
#[cfg(test)] mod tests { … }at the bottom of the file under test (vs. separatetests/files), unless the test crosses crate boundaries. - Prefer
.unwrap()/.unwrap_err()overassert!(x.is_ok())/assert!(x.is_err())— the panic surfaces the underlying error. For variant assertions:assert!(matches!(err, ErrorKind::Foo { .. }), "got {err:?}"). - Use
indoc!/formatdoc!for multi-line literals in tests; both are already on the workspace dep list.
Serde / config types (trident_api::config)
- Public config types derive
Serialize, Deserialize, Debug, Default, Clone, PartialEq, Eq(in that ordering when adding new ones) and usedeny_unknown_fields. Casing convention: structs use#[serde(rename_all = "camelCase", deny_unknown_fields)]for their fields; enums use#[serde(rename_all = "kebab-case", deny_unknown_fields)]for their variants. (Same rule applies to any serialized type outsideconfig, e.g. status / RPC payloads.) Optional fields:#[serde(default, skip_serializing_if = "Option::is_none")]. Non-Option defaults:#[serde(default, skip_serializing_if = "is_default")]. - Gate
JsonSchemabehind theschemarsfeature:#[cfg_attr(feature = "schemars", derive(JsonSchema))], with the import#[cfg(feature = "schemars")] use schemars::JsonSchema;.
Cargo & workspace hygiene
- All third-party deps come from
[workspace.dependencies]— every crate'sCargo.tomlsaysfoo = { workspace = true }, never an inline version. New deps are added to the rootCargo.tomlfirst. - Workspace-local deps use a
path = "..."reference (see existing# Local Crate Dependenciesblocks).
Misc Rust idioms
- Inline format args (
format!("{name}"),info!("done: {count}")) over positional (format!("{}", name)). Fall back to positional only when the expression isn't a bare identifier or a simpleexpr.field/expr.method(). - Prefer
impl AsRef<Path>over&Path/&PathBuffor function arguments that just need to read a path, unless there is a concrete reason not to (e.g. you actually need a&Pathto feed a sibling API in a hot loop, or you want to deliberately constrain callers). Same principle forimpl AsRef<str>/impl AsRef<[u8]>where appropriate. Inside the function body, immediately bind once:let path = path.as_ref();. - No magic numbers or magic strings. Names like
0o755,300,"/etc/trident/datastore","trident-overlay"should beconsts with explanatory names, scoped as tightly as the use justifies. Module-local constants live at the top of the file; cross-module constants belong intrident_api::constants(orosutils::*'s relevant module). Reach fortrident_api::constants::internal_params::*for tunables that are also surfaced as host-config knobs. - Comments explain why, not what. A doc that restates the function name is noise; a doc that names the invariant or links to the relevant design section is signal.
- Aim for shorter expressions that remain readable. Prefer a sensible
matchover nestedif/else ifchains, especially when branching on multiple values at once (match (a, b) { … }). Lean on iterators (.iter().filter().map().collect()) when they're clearer than a manual loop, but prefer loops when an iterator chain would become too cumbersome or cryptic and a loop provides a more self-documenting solution. Reduce duplication with a local closure (let normalize = |s: &str| …;) instead of repeating a 3-line block four times. Avoid verbose blocks that can be expressed more succinctly — but stop short of cleverness that hurts the next reader (one-line iterator chains with side effects, deeply nested closures). The bar is: a reasonable reviewer should read the code at roughly the same speed as a more verbose version, with fewer tokens to skim.
Architecture & structural soundness
The trident workspace is layered. New code belongs in the lowest layer where it logically fits. Adding code at the wrong layer is the most common way to accumulate cross-cutting tangles, and it is one of the few "stylistic" issues that is worth flagging in review.
Crate map (lowest to highest)
| Crate | Layer | Owns | Depends on |
sysdefs | System definitions | High-level definitions of generic computing concepts — machines, operating systems, sometimes specific OSes. Holds the axiomatic types/enums/constants (architectures, filesystems, partition-type GUIDs, TPM2, OS UUIDs). No I/O, no behavior, no dependencies. | nothing |
trident-proto | Wire types | gRPC/protobuf-generated types for Trident's control surface. | tonic/prost |
trident_api | Public API / contract | How Trident talks to the world. The wire/file contract callers use to tell Trident what to do (HostConfiguration + validation) and what Trident reports back (HostStatus, TridentError/ErrorKind). Also cross-crate constants (trident_api::constants). | sysdefs, trident-proto |
osutils | OS-interaction wrappers | Thin, single-purpose wrappers around system tools/syscalls (lsblk, mkfs, mount, systemd, grub, repart, chroot, efivar, …). No business logic, no policy decisions. | sysdefs, trident_api |
osmodifier | OS configuration applier | Native-Rust replacement for the Go osmodifier; applies OS-config changes (hostname, modules, services, users, selinux, grub) under a chrooted root. | (largely standalone) |
trident | Business logic / binary | The actual servicing engine — orchestrator, subsystems (storage, osconfig, network, selinux, extensions, initrd, esp, management, hooks), engine (clean install / A-B / runtime update / rollback), CLI, server, datastore, logging, gRPC client. | everything below |
trident-acl-agent | Update client (Harpoon) | Omaha-protocol client that fetches updated HostConfiguration documents for Trident. | trident-proto |
docbuilder | Tooling | Builds markdown docs from the HostConfiguration schema, the CLI definitions, and architecture pages. Not on the runtime path. | trident_api (with feature flags) |
pytest / pytest_gen | Test tooling | Proc-macro + runtime that lets Rust functions register themselves as Python pytest cases for functional/E2E test discovery. | — |
Where does this code go?
Apply these questions in order; stop at the first "yes":
- Is it a generic, axiomatic definition of a computing concept — a
machine/architecture/OS/filesystem/partition/TPM concept — with no
behavior and no dependencies? →
sysdefs. - Is it part of the on-the-wire Trident control protocol? →
trident-proto(regenerated fromproto/). - Is it part of how Trident talks to the world? — the schema callers
use to tell Trident what to do (Host Configuration / validation) or
what Trident replies (Host Status, error contract), or a constant
shared across multiple crates →
trident_api. - Is it a thin wrapper around a system tool, syscall, or
/proc//sysread? (e.g. "runmkfs.ext4", "parselsblk -J", "read efivars") →osutils. The litmus test: a non-trident project should plausibly be able to use this function. No subsystem-level decisions live inosutils. - Does it apply OS configuration under a chrooted root (hostname,
modules, services, users, selinux, grub)? →
osmodifier. - Does it make a Trident-specific decision ("should we A/B?", "what
order do subsystems run in?", "is this rollback safe?") or sequence
multiple
osutilscalls into a workflow? →trident(underengine/,subsystems/,orchestrate.rs, …).
Layering rules (enforced socially, not by the compiler today)
- Lower layers do not import higher layers.
osutilsdoes not depend ontrident.trident_apidoes not depend onosutils.sysdefsdepends on nothing. osutilsis policy-free. A function inosutilsanswers "how do I invokemkfs.ext4with these options?", not "should we runmkfs.ext4here?". Decision-making belongs intrident's subsystem / engine code.trident_apiis Trident's public surface — keep it behavior-free. It defines the types callers send in (Host Configuration), the types Trident sends back (Host Status, structured errors), and their validation. It does not execute servicing, perform I/O, or know about internal subsystems. If you're adding I/O or a workflow step totrident_api, it belongs intridentinstead.trident-acl-agent(harpoon) is standalone. It is a separate binary that talks to Trident over the gRPC contract; do not couple it totrident's internals.docbuilderandpytest/pytest_genare dev-only. They must not appear in the runtime dependency graph oftridentortrident-acl-agent.
Code reuse (do this before writing anything)
Before introducing a new utility, check — in this order:
osutilsfirst. It already coversblkid,block_devices,bootloaders,chroot,container,dependencies,df,e2fsck,efibootmgr,efivar,encryption,exe,files,filesystems,findmnt,grub,hostname,installation_media,lsblk,lsof,machine_id,mdadm,mkfs,mkinitrd,mount,mountpoint,netplan,osrelease,overlay,path,pcrlock,repart,resize2fs,scripts,sfdisk,swap,systemd,tabfile,tune2fs,udevadm,uki,uname,veritysetup,virt,wipefs. If your task smells like one of these, the wrapper almost certainly exists already.sysdefsandtrident_api::constantsfor any constant you are about to type as a literal.- Existing workspace dependencies before adding a new one. Skim
[workspace.dependencies]in the rootCargo.toml—glob,regex,itertools,serde_yaml,tempfile,humantime,chrono,uuid,which,tera,tar,zstd,oci-client, etc. are already in the tree. Adding a new top-level dep should be a deliberate decision, not a reflex. - If the right home is
osutilsbut the wrapper doesn't exist, add the wrapper inosutilsand call it from the subsystem. Binary invocations belong inosutils— do not inline astd::process::Command::new("…")invocation inside a subsystem or anywhere outsideosutils(one-off exceptions exist, but each is a reviewable choice, not a default). - Inside
osutils, route binary invocations through theosutils::dependencies::Dependencyenum, not rawstd::process::Command. Useosutils::dependencies::Dependency::Foo.cmd().arg(…).run_and_check()so the binary iswhich-resolved, errors are uniformly typed (DependencyError→TridentErrorwith the rightMissingBinary/CommandCouldNotExecute/CommandFailedvariants), and the dependency appears in the workspace's central registry. If the binary you need isn't in theDependencyenum yet, add it to the enum — don't bypass the enum. - Generic OS-concept path manipulation belongs in
osutils— anything that converts a system identifier into a kernel-blessed path (e.g. partition UUID →/dev/disk/by-partuuid/<uuid>, label →/dev/disk/by-label/<…>, mount point munging,/sys//proclookups). Seeosutils::block_devices,osutils::path,osutils::mountpoint, etc. for existing helpers — extend them rather than reconstructing the path inline in a subsystem.
When in doubt
Prefer adding a small wrapper to the right layer and calling it over
duplicating a system invocation in a subsystem. The two most common
review nits in this category are: (a) "this std::process::Command::new("foo")
belongs in osutils::foo, routed through Dependency::Foo"; (b) "this
constant duplicates trident_api::constants::FOO".
Reviewer etiquette (Nits & Architecture)
The "What to avoid" rules at the top of this file still apply: do not open a separate review comment just to flag a nit on otherwise-correct code. Nits and architectural notes are for writers to follow proactively, and for reviewers to use as a checklist when a diff already touches the area. Specifically:
- Don't drag pre-existing violations into a PR's diff. If a file already violates a nit (or already has a layering issue) on untouched lines, ignore it. Use a separate, dedicated PR.
- Cluster comments. When a diff has several small nits in one region, leave one comment listing them — not one per occurrence.
- Never block a PR on a nit alone. Mark nit-only comments as non-blocking, or fold them into a broader comment whose primary point is substantive.
- Layering violations are blocking when they introduce a new dependency
across layers (e.g., a new
std::process::Command::new(...)outsideosutils, or insideosutilsbypassing theDependencyenum; a newosutilsfunction that takes aHostConfigurationand decides what to do; a newtrident_apiitem that performs I/O). They are not blocking when they only continue an existing local pattern.
Pull request descriptions
These rules apply to agents writing code:
- Treat the pull request description as the canonical record of the change and its validation. Update it after implementation and testing, rather than posting a separate test-summary comment.
- Complete every applicable section of the pull request template. Remove all instructional comments, placeholders, and optional sections that do not contain useful information.
- In Validation, list every command actually run, its exact result, and its
relevant scope or limitations. Use
Passed,Failed,Not run, orPending; explain everyNot runorPendingentry. - Distinguish tests run by the agent from independent CI checks. Do not report CI as passed unless its result was observed for the current commit.
- Never summarize validation only as "tests passed." Include the exact command or check name. If a command failed, record the failure and whether it remains unresolved.
- Delete Follow-ups and Notes when they would otherwise be empty. Link
tracked issues for real follow-up work; never leave
TODO,None, or placeholder issue numbers in the pull request description.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

