agentleFS
ricardoquesadaricardoquesada/regenerator2000/AGENTS.md

regenerator2000

AGENTS.md166 starsChanged 10 months agoApache-2.0View on GitHub

Regenerator 2000 is an interactive 6502 disassembler TUI written in Rust, targeting Commodore 8-bit machines. It uses ratatui + crossterm for the terminal UI and exposes an MCP (Model Context Protocol) server for programmatic access. The project is split into four workspace crates forming a one-way dependency DAG (regenerator2000 -> regenerator2000-tui -> regenerator2000-core -> regenerator2000-unpacker -> mos6502, with regenerator2000-tui also depending directly on regenerator2000-unpacker and regenerator2000 depending on both regenerator2000-core and regenerator2000-tui):

  • Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about code style.

    Of the AGENTS.md files we read, the 35,337 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.

  • In this repositoryOne other file it gives its agents.

The file

Show its rules and text

We split this AGENTS.md into the rules it gives an agent

41 rules. About 0 are common, 2 are distinctive, and 39 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 39

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    When adding or modifying a feature, ask: *"Would this logic need to be duplicated if a third client (e.g., a GUI, a CLI) were added?"* If …

    line 80
  2. Very specific:

    Never hardcode platform constants: Do not hardcode machine-specific memory addresses (such as $0800 RAM start, $0801 BASIC start, $0400 …

    line 86
  3. Very specific:

    Keep Documentation System-Agnostic: When updating docs/unpacker.md or adding unpacker documentation, describe memory boundaries and …

    line 88
  4. Very specific:

    All AI-generated code MUST follow the rules below.

    line 114
  5. Very specific:

    Thin mod.rs files: Keep non-leaf mod.rs files limited to module declarations, module doc comments (//!), and pub use re-exports.

    line 118
  6. Very specific:

    Flat use statements: Import items from one module per use statement — avoid nested use trees (write separate use …

    line 119
  7. Very specific:

    No glob imports in production code: Avoid use foo::*;. Glob imports are permitted only for facade re-exports (pub use error::*.

    line 121
  8. Very specific:

    No check-then-unwrap or check-then-expect: Prefer pattern matching (if let Some(val) = ..., let Some(val) = ...

    line 129
  9. Very specific:

    Use anyhow::Result for application-level errors where context strings suffice, and typed thiserror enums for library-facing error surfaces.

    line 131
  10. Very specific:

    All three library lib.rs files gate these lints via:

    line 133
  11. Distinctive:

    Do not remove these attributes.

    line 138
  12. Very specific:

    Prefer ? over manual match/if let for error propagation.

    line 142
  13. Very specific:

    Add context with .context("what was attempted") (from anyhow) when propagating errors across module boundaries.

    line 143
  14. Very specific:

    Do not silently swallow errors with let _ = some_fallible_call();.

    line 144
  15. Very specific:

    Add #[must_use] to every pure function (one with no side effects whose return value carries meaning).

    line 149
  16. Very specific:

    Add #[must_use] to error, outcome, and small value types (such as CorpusError) when ignoring a returned instance is likely a bug.

    line 150
  17. Very specific:

    Descriptive lifetimes on public types: Prefer named domain lifetimes ('app, 'ctx, 'mem, 'emu, 'cfg) over generic 'a on public structs …

    line 154
  18. Very specific:

    Run cargo clippy -- -W clippy::must_use_candidate to find unannotated candidates in existing code.

    line 155
  19. Very specific:

    Use shorthand intra-doc links (` [TypeName] ) to cross-reference types rather than redundant explicit targets such as EnumDefinition …

    line 163
  20. Very specific:

    Run RUSTDOCFLAGS="-D warnings" cargo doc --workspace --no-deps --all-features and cargo clippy -p regenerator2000-unpacker -p …

    line 164
  21. Very specific:

    Prefer newtypes over raw primitives when a value has a distinct semantic meaning (e.g., Addr(u16) instead of raw u16).

    line 168
  22. Very specific:

    Avoid bool parameters in public APIs: Use descriptive two-variant enums instead (AssetReload, Reanalysis, ExternalXRefs, BlockItemTarget, …

    line 173
  23. Very specific:

    Prefer &str over &String, &[T] over &Vec<T>, and &Path over &PathBuf in function signatures.

    line 177
  24. Very specific:

    Use impl Into<String> (or impl AsRef<str>) for constructor arguments that store a String, as System::new does.

    line 178
  25. Very specific:

    Avoid unnecessary .clone() (clippy::redundant_clone) and redundant clone assignments (buf = src.clone(), clippy::assigning_clones) — pass …

    line 179
  26. Very specific:

    When passing closures that only forward to a free function (|x| f(x)), write f directly (clippy::redundant_closure).

    line 181
  27. Very specific:

    Use BTreeMap/BTreeSet for address-keyed maps that must be iterated in order (deterministic output for project files).

    line 186
  28. Very specific:

    Prefer .entry().or_default() over if !map.contains_key() { map.insert() }.

    line 187
  29. Very specific:

    Run cargo fmt --all before committing (enforced by pre-commit hook and CI).

    line 191
  30. Very specific:

    Prefer .is_some_and(...) / .is_ok_and(...) over .map_or(false, ...) (clippy::manual_is_variant_and).

    line 192
  31. Very specific:

    Prefer write!(buf, "{x}") over buf.push_str(&format!("{x}")) (clippy::format_push_string) and avoid .map(...).collect::<String>() …

    line 193
  32. Very specific:

    Use inline format capture syntax (format!("{x}"), clippy::uninlined_format_args) rather than positional format!("{}", x).

    line 194
  33. Very specific:

    Every non-trivial function in regenerator2000-core should have at least one unit test in the same file (#[cfg(test)]).

    line 199
  34. Very specific:

    Avoid check-then-expect in tests: Do not write assert!(x.is_some()).

    line 202
  35. Very specific:

    Use AppState::new() (not a manually built struct) as the test baseline.

    line 204
  36. Very specific:

    New Block Type: Add to BlockType enum in types.rs, update analyzer.rs, and add a shortcut in input.rs.

    line 256
  37. Very specific:

    New Assembler: Add to Assembler enum, implement Formatter trait in disassembler/formatter_*.rs.

    line 257
  38. Very specific:

    New Command: Add variant to Command in commands.rs, implement apply and undo.

    line 258
  39. Very specific:

    Use present tense, imperative mood (e.g., Add support for D71 disk images).

    line 263
  40. Distinctive:

    Never: create a git commit automatically after completing a task.

    line 267
  41. Very specific:

    Verification: Always run cargo test --workspace --all-features, cargo clippy --workspace --all-targets --all-features -- -D warnings, and …

    line 273

≈ “Common” is an estimate: at least 1 in 5 of the 45,344 AGENTS.md 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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
AGENTS.md

Regenerator 2000 - Agent Instructions

Regenerator 2000 is an interactive 6502 disassembler TUI written in Rust, targeting Commodore 8-bit machines. It uses ratatui + crossterm for the terminal UI and exposes an MCP (Model Context Protocol) server for programmatic access.

Architecture & Crate Structure

The project is split into four workspace crates forming a one-way dependency DAG (regenerator2000 -> regenerator2000-tui -> regenerator2000-core -> regenerator2000-unpacker -> mos6502, with regenerator2000-tui also depending directly on regenerator2000-unpacker and regenerator2000 depending on both regenerator2000-core and regenerator2000-tui):

  • regenerator2000-unpacker (crates/regenerator2000-unpacker/): Standalone 6502 emulation binary unpacker and 26-family packer detector (mos6502, thiserror, log).
    • system.rs: Closed #[non_exhaustive] TargetMachine hardware profile enum (Copy), IrqVector, default_machine(), and platform memory-map helpers (ram_start, default_basic_start, screen_ram, default_irq, is_c64, etc.).
    • roms.rs: Optional embedded C64 ROM blobs (C64_BASIC_ROM, C64_KERNAL_ROM, C64_CHAR_ROM, gated behind the default embedded-roms feature) and zero-copy default_*_rom(TargetMachine) -> Option<&'static [u8]> helpers.
    • basic.rs: Commodore BASIC SYS token parser (find_sys_address).
    • error.rs: UnpackError enum.
    • bus.rs, cia.rs, machine.rs, engine.rs, detector.rs, runner.rs: 2-phase 6502 emulation unpacker sandbox (UnpackConfig with target_machine and Option<Cow<'static, [u8]>> ROM overrides, UnpackResult, unpack, UnpackReport, and BoundSource).
    • packers/: Declarative 6502 binary packer specifications (PackerSpec, Signature, Hints, MemoryPatch, PackerHooks in spec.rs, PackerInfo in info.rs, and the ordered REGISTRY in registry.rs).
  • regenerator2000-unpacker-corpus (crates/regenerator2000-unpacker-corpus/, publish = false): Internal differential corpus test harness (tests/unpack_corpus.rs) and unpacker_compare_all benchmark CLI against unp64 (src/bin/unpacker_compare_all/{corpus/constants.rs,unp64/runner.rs}).
  • regenerator2000-core (crates/regenerator2000-core/): Contains all UI-agnostic reverse-engineering and state logic (no direct mos6502 dependency).
    • action_handlers/: Modular domain action handlers (context.rs [ActionContext, DisassemblyViewAnchor, DomainActionHandler], file_handler.rs, disassembly_handler.rs, debug_handler.rs, navigation_handler.rs).
    • analyzer.rs: Auto-analysis (walking code, generating labels, building typed cross-references).
    • assets.rs: System asset loading (labels, comments, exclude lists) and C64 ROM re-exports/delegation to regenerator2000-unpacker.
    • commands.rs: The Command enum and UndoStack. Every undoable action is a command.
    • config.rs: System-wide configuration management.
    • core.rs: Central orchestration logic (Core combining AppState and CoreViewState, and apply_action dispatch).
    • cpu.rs: 6502 opcode table, addressing mode logic, and Opcode::xref_kind().
    • disassembler/: 6502 decoding, shared DisassemblyLine geometry/lowering (line.rs, context.rs), Disassembler engine (engine.rs, pipeline.rs, symbols.rs, data_blocks.rs, handlers.rs), and assembler formatters (formatter_*.rs: 64tass, ACME, KickAssembler, ca65).
    • error.rs: Typed thiserror error hierarchy (CoreError, wrapping re-exported UnpackError).
    • event.rs: Application event types (CoreEvent, DialogType).
    • exporter/: 3-stage Exporter IR pipeline (ir.rs), pure ASM/HTML backends (asm.rs, html.rs), and roundtrip verification (verify.rs).
    • mcp/: MCP server implementation (stdio and HTTP transports). Contains handler.rs dispatcher and tools/ submodules (analysis_tools, navigation_tools, modification_tools, session_tools, common).
    • navigation.rs: Address navigation logic.
    • parser/: File format parsers (.prg, .d64/.d71/.d81, .t64, .crt, .vsf snapshots, .dis65, VICE labels; basic.rs delegates find_sys_address to regenerator2000-unpacker).
    • state/: Persistent application state (AppState), sparse AnnotationManager, domain types (TargetSystem delegating hardware queries to TargetMachine), and project serialization.
    • utils.rs: Shared utility functions.
    • vice/: VICE binary monitor protocol client for live debugging.
    • view_state.rs: View state management (CoreViewState).
  • regenerator2000-tui (crates/regenerator2000-tui/): Contains all terminal UI-related code.
    • ui/: Top-level frame composition (render.rs, re-exported via thin mod.rs), TUI widgets (widget.rs, navigable.rs, minimap_bar.rs, statusbar.rs, scoped_input.rs), top menu (menu/: menu_model.rs, menu_render.rs, menu_action.rs, menu_widget.rs, thin mod.rs), views (view_disassembly/ submodule breakdown [layout.rs, navigation.rs, mouse.rs, render.rs, view.rs, mod.rs], HexDump, Sprites, Charset, Bitmap, Blocks, Debugger), and modal dialogs (dialog_*.rs, including unified FileBrowserDialog, PromptDialog, ContainerPickerDialog, and table-driven DocumentSettingsDialog).
    • ui_state.rs: Transient UI state (cursor, scroll, active dialog, wrapping CoreViewState via Deref).
    • events/: Event loop (runner.rs), event enum (app_event.rs), global input mapping (input.rs), background MCP coordination (mcp.rs), and VICE monitor integration (vice.rs), re-exported via thin mod.rs.
    • terminal_graphics.rs: Terminal image protocol probing, Kitty/iTerm2/Sixel helpers, and headless picker setup.
    • theme.rs: Color scheme and styling logic.
    • theme_file.rs: Theme file parsing and custom theme support.
    • utils.rs: TUI utility functions.

Core Domain Model

Key Types (crates/regenerator2000-core/src/state/types.rs)

  • Addr: A wrapper around u16 representing a 6502 address.
  • TargetSystem (System alias): Target machine (C64, C128, Vic20, Pet20, Pet40, Plus4, C16, C1541, C1571, C1581, Custom).
  • Assembler: Target assembler syntax (Tass64, Acme, Ca65, Kick).
  • BlockType: How a range of bytes is interpreted (Code, DataByte, DataWord, Address, PetsciiText, ScreencodeText, LoHiAddress, HiLoAddress, LoHiWord, HiLoWord, ExternalFile, Undefined).
  • LabelType: Semantic meaning of a label (Subroutine, Jump, Branch, Return, Pointer, ZeroPagePointer, Field, ZeroPageField, AbsoluteAddress, ZeroPageAbsoluteAddress, ExternalJump, Predefined, UserDefined, LocalUserDefined).
  • XRef / XRefKind: Typed cross-reference edge (from: Addr, kind: XRefKind — Read, Write, ReadModifyWrite, Call, Jump, Offset).

State Management

  • AppState (crates/regenerator2000-core/src/state/app_state.rs): The single source of truth for persistent data. Includes raw_data, block_types, labels, annotations (AnnotationManager consolidating comments, immediate value formats, bookmarks, scopes, and enum usages), undo_stack, settings, cross_refs (BTreeMap<Addr, Vec<XRef>>), and splitters. Serialized to .regen2000proj.
  • UIState (crates/regenerator2000-tui/src/ui_state.rs): Transient state like cursor positions, scroll offsets, and active dialogs (wrapping CoreViewState). Never serialized.

Application Logic Flow

Regenerator 2000 follows a unidirectional data flow (Redux/Elm style):

  1. Input: crates/regenerator2000-tui/src/events/input.rs and Widget::handle_input map key events to AppAction (MenuAction).
  2. Dispatch: handle_menu_action (crates/regenerator2000-tui/src/ui/menu/menu_action.rs) forwards AppAction to Core::apply_action, which delegates to action_handlers/ and converts actions into Command variants and CoreEvent notifications.
  3. Execution: Command::apply(&mut AppState) modifies the state and pushes to UndoStack.
  4. Analysis: AppState::perform_analysis() (via analyzer.rs) updates labels and typed cross-references (XRef).
  5. Render: ui() in crates/regenerator2000-tui/src/ui/render.rs (re-exported from ui/mod.rs) re-renders the TUI from AppState + UIState.

No Logic Duplication — State Logic Lives in Core

All validation, business rules, and state-mutation logic must live in regenerator2000-core (typically as methods on AppState in state/). Both the TUI (regenerator2000-tui) and the MCP server (mcp/ handler + mcp/tools/ submodules) are consumers of core logic — they must call shared AppState methods, not re-implement the same checks independently.

For example, if label creation needs to reject duplicate names, that validation belongs in an AppState method (e.g., create_set_user_label_command). The MCP tool submodules (mcp/tools/) and the TUI dialogs both call that single method. Never add domain logic directly into mcp/tools/ or events/input.rs if it can be expressed as a core method. TUI disassembly rendering belongs in view_disassembly/render.rs, view navigation in view_disassembly/navigation.rs, visual layout math in view_disassembly/layout.rs, and mouse interaction in view_disassembly/mouse.rs.

When adding or modifying a feature, ask: "Would this logic need to be duplicated if a third client (e.g., a GUI, a CLI) were added?" If yes, it belongs in regenerator2000-core.

System-Agnostic Design & Unpacker Rules

The core disassembler and binary unpacker (crates/regenerator2000-unpacker/src/ directory) target Commodore 8-bit machines (C64, C128, VIC-20, PET, Plus/4).

  • Never hardcode platform constants: Do not hardcode machine-specific memory addresses (such as $0800 RAM start, $0801 BASIC start, $0400 screen RAM, or $0314 IRQ vector) directly in crates/regenerator2000-unpacker/src/ or documentation. Always query machine properties via TargetMachine methods (machine.ram_start(), machine.default_basic_start(), machine.screen_ram(), machine.default_irq(), machine.is_c64()).
  • Guard platform-specific features: System-specific behavior (such as C64 PLA processor port $01 banking or zero-page template copying) must be explicitly guarded (e.g. if machine.is_c64()).
  • Keep Documentation System-Agnostic: When updating docs/unpacker.md or adding unpacker documentation, describe memory boundaries and zero-page setups in a system-agnostic way (referencing system RAM start $0800 on C64, $1C00 on C128, $1000 on VIC-20, $0400 on PET) rather than assuming C64 defaults globally.

AI Agent Skills & Subagents (.agent/)

Specialized agents (.agent/agents/) and skills (.agent/skills/) are available for common tasks:

Custom Agents (.agent/agents/)

  • r2000-cbm-principal-swe: Commodore 8-Bit (CBM) and MOS 6502 Principal Systems, Demo-Coding, and Reverse-Engineering agent (r2000_cbm_principal_swe.md). Used by the r2000-analyze-* skills and for 6502 assembly tasks.

Skills (.agent/skills/)

  • r2000-analyze-basic: Analyze BASIC programs and mark pointers (uses r2000-cbm-principal-swe).
  • r2000-analyze-blocks: Auto-detect and set block types (text, data) (uses r2000-cbm-principal-swe).
  • r2000-analyze-program: Orchestrate 2-tier MapReduce full-program analysis using r2000-cbm-principal-swe subagents across BASIC, blocks, routines, and symbols.
  • r2000-analyze-routine: Trace a subroutine and mark code paths (uses r2000-cbm-principal-swe).
  • r2000-analyze-symbol: Find and label all references to a specific address (uses r2000-cbm-principal-swe).
  • compare-unpacker: Benchmark Regenerator 2000 unpacker against unp64 and generate comparison reports.
  • add-mcp-tool: Templates for adding new programmatic tools to the MCP server.
  • bump-version: Automate version bumping and changelog updates.
  • update-keyboard-shortcuts: Sync keyboard shortcuts across docs and source files.
  • update-mcp-docs: Sync docs/mcp.md with the actual MCP tools.
  • verify-mcp: Run MCP integration test suite to verify server functionality.

Rust Best Practices

All AI-generated code MUST follow the rules below. The workspace enforces baseline lints through cargo clippy -- -D warnings; violations will block CI.

Module Layout and Imports

  • Thin mod.rs files: Keep non-leaf mod.rs files limited to module declarations, module doc comments (//!), and pub use re-exports. Place structs, traits, implementations, and unit tests in named leaf submodules (e.g., action_handlers/context.rs, disassembler/engine.rs, disassembler/line.rs, packers/info.rs, crates/regenerator2000-unpacker/src/runner.rs, bin/unpacker_compare_all/{corpus/constants.rs,unp64/runner.rs}, events/runner.rs, ui/render.rs, ui/menu/menu_widget.rs, and ui/view_disassembly/view.rs).
  • Flat use statements: Import items from one module per use statement — avoid nested use trees (write separate use std::collections::BTreeMap; and use std::fs; imports rather than use std::{collections::BTreeMap, fs};). Grouping sibling items from the same module in {...} is fine (e.g., use crate::state::{Addr, AppState};).
  • Import types; avoid inline multi-segment paths: Import types, traits, and enums at module scope (or inside #[cfg(test)] mod tests) and refer to them unqualified (Range<usize>, HashSet<Addr>, Path). Qualify free functions with their parent module when it improves clarity or avoids name collisions (fs::read, analyzer::analyze, navigation::resolve_jump_content_line_index, basic::find_sys_address). Exceptions: disambiguating shadowed prelude names (std::result::Result where crate::Result is in scope) and $crate::... paths inside macro_rules!.
  • No glob imports in production code: Avoid use foo::*;. Glob imports are permitted only for facade re-exports (pub use error::*; in lib.rs, pub use ...::*; in state/mod.rs) and use super::*; inside #[cfg(test)] mod tests.

Panic Safety

Production code must never panic silently.

  • Never use .unwrap() or .expect() outside of #[cfg(test)] blocks. Both are banned by clippy::unwrap_used / clippy::expect_used.
  • Never use std::panic::catch_unwind for control flow or error recovery.
  • No check-then-unwrap or check-then-expect: Prefer pattern matching (if let Some(val) = ..., let Some(val) = ... else { ... };) over checking .is_some() / .is_ok() followed by unwrapping or .expect().
  • Return Result or Option and propagate errors with ?.
  • Use anyhow::Result for application-level errors where context strings suffice, and typed thiserror enums for library-facing error surfaces.
  • unreachable!() inside exhaustive match arms (e.g., an enum variant that logically cannot appear) is acceptable. All other panic macros require a comment explaining why the invariant holds.
  • All three library lib.rs files gate these lints via:
    #![cfg_attr(not(test), deny(clippy::unwrap_used, clippy::panic))]
    #![cfg_attr(test, allow(clippy::unwrap_used, clippy::expect_used, clippy::panic))]
    Do not remove these attributes.

Error Handling

  • Prefer ? over manual match/if let for error propagation.
  • Add context with .context("what was attempted") (from anyhow) when propagating errors across module boundaries.
  • Do not silently swallow errors with let _ = some_fallible_call();. Log or propagate them.
  • MCP tool handler functions must return explicit McpError variants for invalid/missing parameters — see mcp/tools/ submodules for the established pattern.

API Hygiene and Naming

  • Add #[must_use] to every pure function (one with no side effects whose return value carries meaning). This includes constructors (fn new), getters, and any function returning bool, a numeric type, or a wrapped newtype.
  • Add #[must_use] to error, outcome, and small value types (such as CorpusError) when ignoring a returned instance is likely a bug.
  • Functions that mutate state (&mut self) and return () do not need #[must_use].
  • #[must_use] on an impl block annotates every method — use sparingly; prefer per-method annotations.
  • No get_ prefix on public getters: Name simple getters after the concept (opcodes(), pointer(), formatter(), line_index_for_address(), hardware_name(), basic_start()). Use descriptive verbs (parse_*, find_*, resolve_*) for fallible parsing or non-trivial lookups (e.g., parse_address_arg).
  • Descriptive lifetimes on public types: Prefer named domain lifetimes ('app, 'ctx, 'mem, 'emu, 'cfg) over generic 'a on public structs holding borrowed references (ActionContext<'app>, DisassemblyContext<'app>, HandleArgs<'ctx>, LoadedImage<'mem>, StepContext<'emu>, UnpackEngine<'cfg>).
  • Run cargo clippy -- -W clippy::must_use_candidate to find unannotated candidates in existing code.

Documentation

  • All pub items in regenerator2000-unpacker, regenerator2000-core, and regenerator2000-tui — including modules (//!), structs, struct fields, enums, enum variants, functions, and constants — must have doc comments (///).
  • Functions returning Result must include a # Errors section explaining when they fail.
  • Functions that can panic (outside tests) must include a # Panics section.
  • Wrap code identifiers, CamelCase names (e.g., `AppState`, `KickAssembler`), hex addresses ($0801), flags, and file paths in backticks (clippy::doc_markdown).
  • Use shorthand intra-doc links ([`TypeName`]) to cross-reference types rather than redundant explicit targets such as [`EnumDefinition`](EnumDefinition) (rustdoc::redundant_explicit_links).
  • Run RUSTDOCFLAGS="-D warnings" cargo doc --workspace --no-deps --all-features and cargo clippy -p regenerator2000-unpacker -p regenerator2000-core -p regenerator2000-tui --all-targets --all-features -- -D warnings -D missing_docs -D clippy::doc_markdown to verify doc links, doc-tests, and coverage.

Type Design

  • Prefer newtypes over raw primitives when a value has a distinct semantic meaning (e.g., Addr(u16) instead of raw u16). See state/types.rs for the established pattern.
  • Prefer named structs over multi-element tuples in public APIs: Define small documented structs with named fields instead of returning or accepting unlabeled tuples (AddrSpan, OffsetSpan, IrqVector, EffectiveTarget, DecodedPacket, ParsedCrt, ExpandedBlocks, AnalysisOutcome, DetectedPacker, ResolvedEnumValue, ViceLabel).
  • Derive #[derive(Debug, Clone, Copy, PartialEq, Eq)] for all small value types. Add Hash when the type is used as a map key, Ord/PartialOrd when ordering is needed.
  • Implement standard library traits (Display, From/TryFrom, Error) where appropriate instead of custom conversion or formatting methods.
  • Implement Default for options/config structs (UnpackConfig, DocumentSettings); use #[derive(Default)] and #[default] on enum variants when zero-values apply, or an explicit Default impl for non-zero defaults.
  • Avoid bool parameters in public APIs: Use descriptive two-variant enums instead (AssetReload, Reanalysis, ExternalXRefs, BlockItemTarget, LabelLocality, PetsciiCharset, TrimMode) so call sites are self-documenting and cannot transpose arguments.

Ownership and Borrowing

  • Prefer &str over &String, &[T] over &Vec<T>, and &Path over &PathBuf in function signatures.
  • Use impl Into<String> (or impl AsRef<str>) for constructor arguments that store a String, as System::new does.
  • Avoid unnecessary .clone() (clippy::redundant_clone) and redundant clone assignments (buf = src.clone(), clippy::assigning_clones) — pass references or borrow slices where ownership is not needed.
  • Pass borrowed views or references instead of unused owned values (clippy::needless_pass_by_value).
  • When passing closures that only forward to a free function (|x| f(x)), write f directly (clippy::redundant_closure).
  • Provide explicit type annotations when type inference would obscure a non-obvious type (such as .collect() destination types).

Collections

  • Use BTreeMap/BTreeSet for address-keyed maps that must be iterated in order (deterministic output for project files). Use HashMap/HashSet only when iteration order does not matter and performance is critical.
  • Prefer .entry().or_default() over if !map.contains_key() { map.insert() }.

Formatting and Style

  • Run cargo fmt --all before committing (enforced by pre-commit hook and CI).
  • Prefer .is_some_and(...) / .is_ok_and(...) over .map_or(false, ...) (clippy::manual_is_variant_and).
  • Prefer write!(buf, "{x}") over buf.push_str(&format!("{x}")) (clippy::format_push_string) and avoid .map(...).collect::<String>() formatting loops (clippy::format_collect).
  • Use inline format capture syntax (format!("{x}"), clippy::uninlined_format_args) rather than positional format!("{}", x).
  • match arms that do nothing should use the _ => {} form, not _ => unreachable!() unless you are genuinely asserting the arm is unreachable.

Tests

  • Every non-trivial function in regenerator2000-core should have at least one unit test in the same file (#[cfg(test)]).
  • Integration tests live in tests/ and cover cross-module behavior (disassembler output, project serialization, MCP protocol, unpacker corpus).
  • Prefer .expect("reason") / .expect_err("reason") over .unwrap() / .unwrap_err() in all unit tests, integration tests, and doc-tests (#![cfg_attr(test, allow(...))] exempts tests from clippy errors, so write clear failure context rather than bare unwraps).
  • Avoid check-then-expect in tests: Do not write assert!(x.is_some()); let v = x.expect(...); — call .expect("...") directly or pattern match.
  • Add context strings to non-obvious assertions (assert!, assert_eq!), especially inside loops or table-driven test cases.
  • Use AppState::new() (not a manually built struct) as the test baseline; it sets a safe throwaway config path that never touches the real user config.

Clippy Configuration

Lint policy is defined in [workspace.lints.clippy] in the root Cargo.toml. All crates inherit it via [lints] workspace = true in their own Cargo.toml — do not add per-crate [lints.clippy] blocks.

Currently enforced (error in CI via -D warnings):

LintCategory
unwrap_usedPanic safety
expect_usedPanic safety
panicPanic safety
must_use_candidateAPI hygiene
missing_errors_docDocumentation
missing_panics_docDocumentation

Aspirational / Readability Checks (apply to new code, enforced via -D on regenerator2000-unpacker, regenerator2000-core, and regenerator2000-tui readability passes):

LintCategory / Apply when
missing_docsPublic API docs in regenerator2000-unpacker, regenerator2000-core, and regenerator2000-tui
clippy::doc_markdownBacktick code/identifiers in doc comments
clippy::redundant_cloneUnnecessary .clone() calls
clippy::assigning_clonesReassigning via .clone() instead of clone_from / slice copy
clippy::needless_pass_by_valueWriting new functions taking unused owned params
clippy::manual_is_variant_andBoolean checks on Option / Result
clippy::uninlined_format_argsFormat string readability
clippy::format_collectBuilding strings in loops (write! instead)
clippy::redundant_closurePassing single-arg closures (f instead of |x| f(x))

Development Workflow

Commands

cargo build                                                              # Debug build
cargo run -- [file.prg]                                                  # Run with optional file
cargo test --workspace --all-features                                    # Run all workspace unit, integration, and doc tests
cargo fmt --all -- --check                                               # Check formatting
cargo clippy --workspace --all-targets --all-features -- -D warnings     # Workspace lints (warnings are errors)
RUSTDOCFLAGS="-D warnings" cargo doc --workspace --no-deps --all-features # Verify rustdoc builds and intra-doc links
cargo clippy -p regenerator2000-unpacker -p regenerator2000-core -p regenerator2000-tui --all-targets --all-features -- \
  -D warnings -D missing_docs -D clippy::doc_markdown \
  -D clippy::redundant_clone -D clippy::assigning_clones \
  -D clippy::needless_pass_by_value -D clippy::manual_is_variant_and \
  -D clippy::uninlined_format_args -D clippy::format_collect              # Strict readability lint pass

Adding Features

  • New Block Type: Add to BlockType enum in types.rs, update analyzer.rs, and add a shortcut in input.rs.
  • New Assembler: Add to Assembler enum, implement Formatter trait in disassembler/formatter_*.rs.
  • New Command: Add variant to Command in commands.rs, implement apply and undo.
  • New Packer: Create a new module file in crates/regenerator2000-unpacker/src/packers/<name>.rs defining pub static SPEC: PackerSpec with declarative Signature patterns (Anchor, sig!), Hints (AddrSource), optional patches (MemoryPatch), optional resolve escape hatch (fn(&LoadedImage<'_>, &SignatureMatch) -> Option<ResolvedSpec>), optional hooks factory (PackerHooks with StepContext and RefineContext), and a synthetic fixture (fixture_load_addr). Export pub mod <name>; in src/packers/mod.rs, register &<name>::SPEC in ascending priority order in REGISTRY in src/packers/registry.rs, add a unit test, and (when a real packed .prg fixture is available) add a [[case]] entry to tests/6502/unpack_corpus.toml, record its unp64 reference with cargo run -p regenerator2000-unpacker-corpus --bin unpacker_compare_all -- --update, and update tests/6502/unpack_baseline.toml (UPDATE_UNPACK_BASELINE=1 cargo test -p regenerator2000-unpacker-corpus --test unpack_corpus).

Git Commit Style

Use present tense, imperative mood (e.g., Add support for D71 disk images). Limit first line to 72 chars.

No Automatic Commits

Never create a git commit automatically after completing a task. Only commit when the user explicitly asks for it (e.g., "commit this", "create a commit"). Staged changes (git add) are acceptable as part of normal workflow, but the final git commit requires an explicit user instruction.

Testing

  • Unit Tests: Located in src files (e.g., cpu.rs).
  • Integration Tests: Located in tests/ (workspace root), crates/regenerator2000-unpacker/tests/ (unpacker_fuzz_test.rs), and crates/regenerator2000-unpacker-corpus/tests/ (unpack_corpus.rs). Use these for testing disassembler output, project serialization, MCP functionality, and unpacker corpus/fuzz behavior.
  • Verification: Always run cargo test --workspace --all-features, cargo clippy --workspace --all-targets --all-features -- -D warnings, and RUSTDOCFLAGS="-D warnings" cargo doc --workspace --no-deps --all-features before finalizing changes.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.