Skip to content

Latest commit

 

History

History
197 lines (152 loc) · 21 KB

context.md

File metadata and controls

197 lines (152 loc) · 21 KB

LLM Agent Instructions

Procedural skills are in the skills/ directory.


Repository Overview

Package: com.wallstop-studios.unity-helpers Version: 3.7.2 Repository: https://github.com/wallstop/unity-helpers Root Namespace: WallstopStudios.UnityHelpers

Design Principles: Zero boilerplate, performance-proven (19,000+ tests, IL2CPP/WebGL compatible), DRY architecture, self-documenting code (minimal comments, descriptive names).


Project Structure

Runtime/                   # Runtime C# libraries
  Core/                    # Attributes, DataStructure, Extension, Helper, Math,
                           # Model, OneOf, Random, Serialization, Threading
  Tags/                    # Effects/attribute system (AttributeEffect, TagHandler, Cosmetics)
  Visuals/                 # Visual components (EnhancedImage, LayeredImage)

Editor/                    # Editor-only tooling
  CustomDrawers/           # Property drawers (including Odin/ subdirectory)
  CustomEditors/           # Custom inspectors (including Odin inspectors)
  Tools/                   # Editor windows (Animation Creator, Texture tools, etc.)

Tests/                     # Runtime/ (PlayMode), Editor/ (EditMode), Core/ (shared utilities)

Samples~/                  # Sample projects (imported via Package Manager)

Skills Reference

See the generated Skills Index. Regenerate it after adding or editing any skill's trigger comment with pwsh -NoProfile -File scripts/generate-skills-index.ps1 (validated by scripts/lint-llm-instructions.ps1).

Critical Rules Summary

See create-csharp-file for detailed C# rules.

C# Code Rules

  1. using directives INSIDE namespace; #if blocks INSIDE namespace; #define at file top

  2. NO underscores in method names (including tests)

  3. Explicit types over var. Prefer compiler-proven definite assignment or direct initialization over placeholder default assignments; retain default when it expresses a real return or failure contract.

  4. NEVER use #region or #endregion (see no-regions)

  5. NEVER use nullable reference types (string?)

  6. One file per MonoBehaviour/ScriptableObject (production AND tests). One member ordering across the codebase (#672): const, events, delegates, static properties, static fields, properties, fields, constructors, static methods, methods -- each tier ordered public → protected → internal → private, including const. A nested type goes at the END of its containing type or in its own file, never between members. npm run lint:nested-type-placement enforces both and :fix reorders what it can; a member whose move would cross a #if boundary or a directive is reported, never moved (#575, #672; see create-csharp-file)

  7. NEVER use ?., ??, ??= on UnityEngine.Object types

  8. Aim for zero comments. Reach for a better name before a better sentence, and spell names out rather than abbreviating. A comment that survives that explains why, never what; a non-doc comment INSIDE a type or member spanning more than one line uses the /* ... */ block form, the two-line license header excepted (see create-csharp-file). npm run lint:comment-block-form enforces the block form and :fix converts what it can; Runtime/, Editor/, Tests/ and Generator~/ are enforced without baseline exemptions (#635). Delete before converting -- a run that only restates the code says what

  9. Generate .meta files with ./scripts/generate-meta.sh <path> after creating ANY file/folder -- never commit Unity's auto-written stub, which omits the importer block. And an AddComponent-able MonoBehaviour belongs in a runtime-capable test assembly: Unity refuses one it can identify as an editor script, and a type with no MonoScript merely escapes that policy until someone gives it a correctly-named file (12 red tests, session 244). npm run lint:editor-assembly-monobehaviours now holds it statically from includePlatforms plus asmdef ownership, over the 14 that legitimately live in an Editor-only assembly -- each carrying a reason and a FROZEN AddComponent site count, so a new call site reds the excuse instead of hiding behind it (#678). Exception: no .meta for dot folders (.llm/, .github/, .git/, .vscode/). See create-unity-meta

  10. Enums: explicit values, None/Unknown = 0 with [Obsolete] (see create-enum)

  11. Never reflect on our own code; expose actual implementation members through internal + [InternalsVisibleTo]. Production code must contain no test-only methods, wrappers, state, callbacks, branches or instrumentation. Do not add or rename ForTest, ForTesting, ForTests, TestHooks or TestOnly members. Keep test setup and simulated failures in test assemblies; use real implementation phases and filesystem/lifecycle controls. Legitimate production discovery of test assemblies remains supported (see avoid-reflection).

  12. Never use magic strings; use nameof() (see avoid-magic-strings)

  13. All code must follow high-performance-csharp and defensive-programming (never throw from public APIs; use TryXxx patterns; handle all inputs gracefully)

  14. For forbidden patterns and alternatives, see forbidden-patterns reference

  15. All editor mutation paths must follow the complete undo policy (see editor-undo-complete); classify paths as Tier A/B/C and never claim full reversal for Tier C file/reimport side effects

  16. AssetPostprocessor callbacks MUST defer non-trivial work through AssetPostprocessorDeferral.Schedule to avoid SendMessage cannot be called... warnings during Unity's import phase — and deferral is necessary, not sufficient: a deferred LoadAllAssetsAtPath still deserializes the asset and still runs the consumer's OnValidate, so never answer a metadata question with a load (see asset-postprocessor-safety)

  17. The package ships four compiler-input assemblies; diagnostics belong to their matching analyzer. WPROTO### (Generator~/WallstopStudios.UnityHelpers.Proto.Generator) reports a serialization contract that cannot be honoured, so it is an error -- the alternative is an exception from inside a shipped player. WUH### (Generator~/WallstopStudios.UnityHelpers.Analyzers) reports an allocation or footgun in code that already works, so it is capped at DiagnosticSeverity.Warning and suppressible: taking a package upgrade must never fail a consumer's build. On by default, with nine exceptions -- WUH010 (a dictionary read by indexer), WUH013 (a counting loop that can use foreach), WUH018 (string equality whose comparison policy is implicit), WUH019 (repeated stable loop bounds), WUH021 (repeated size observations), WUH023 (public structs without typed equality), WUH024 (typed enum helper suggestions), WUH029 (member declaration order), and WUH030 (implicit string comparison or culture) remain opt-in for consumers because their correct shapes are ubiquitous. The package opts into WUH010, WUH013, and WUH018 in its shared check-project ruleset; WUH019, WUH021 and WUH023 are enabled by the production-only ruleset for Runtime, Editor, and integration checks. The excluded-source audit covers WUH013, WUH019, WUH021, WUH023, WUH026 and WUH028 with reporting controls. The enum generator (Generator~/WallstopStudios.UnityHelpers.Enum.Generator) reports WENUM001 as a warning when an annotated enum cannot receive generated overloads; it never changes a build result. Every owned Generator~ project self-hosts all shipped compiler inputs and promotes shared WUH### policies; WUH019, WUH021 and WUH023 promotion is limited to production checks; the five Unity source gates cover Runtime, Editor, integrations, and both test trees without changing consumer defaults. Retain indexed loops when the index is needed or enumeration changes behavior. The independent Odin migration generator emits editor bindings without depending on the protobuf generator DLL. All four DLLs are committed under Runtime/Analyzers, byte-compared in CI, and an edit to any of them is not finished until you rebuild it. See analyzers

  18. NEVER size an allocation from a number a payload states -- only from what it delivers. A length prefix is safe because the reader refuses one longer than the bytes it holds; a capacity is a bare claim, and six bytes can ask for 8 GB. Clamp it with SerializationCapacityLimits.Clamp where it is a growth hint, refuse it with TryAccept where it is semantic. A stackalloc sized from a caller's argument is the same rule with a worse failure -- StackOverflowException is caught by nothing, so a length must be a compile-time constant or compared against one in the same statement, with a SystemArrayPool rent above StackAllocation.MaxByteBudget; npm run lint:unsafe-code holds it over 56 sites (#637). See untrusted-payload-limits. The same gate refuses [Il2CppSetOption(Option.NullChecks, false)] and the ArrayBoundsChecks/DivideByZeroChecks forms, however spelled -- deleting IL2CPP's runtime checks reaches the same undefined behaviour as unsafe with neither the keyword nor allowUnsafeCode, so nothing else can see it. Writing one with true, or with no value, leaves the check on and stays green. Zero sites exist and there is no baseline: the first one reds the build, and the gate carries a positive control because a zero-subject scan cannot prove itself

  19. Named methods and local functions use brace bodies; properties, accessors, operators and lambdas may use expression bodies. Use prefix increment when the prior value is discarded; retain postfix when its value is used. npm run lint:csharp-syntax enforces both with Roslyn over all conditional-symbol combinations in Runtime, Editor, Tests, Generator, Samples and Styles sources; Local Gates runs it with reporting and compiled IL-equivalence controls (#836, #866).

  20. Default to string.IsNullOrWhiteSpace for string validation, including identifiers, GUIDs, paths, required names and labels. Keep IsNullOrEmpty only when whitespace is valid data or an empty-only serialization branch must preserve invalid-content handling; record that contract and test it. Never mechanically change payloads, literal queries, separators or persisted keys (see defensive-programming).

  21. Public ordinary structs implement IEquatable<TSelf> with matching object equality and hashing; Unity C# cannot apply this interface to ref structs. Put each new named class in its own .cs file. The current file-naming gate only enforces this for MonoBehaviour and ScriptableObject; #865 tracks the wider migration and enforcement policy.

Documentation Rules

  • Documentation is NOT optional. Every user-facing change MUST update: CHANGELOG, XML docs, feature docs in docs/
  • CHANGELOG is for USER-FACING changes ONLY. Internal changes (CI/CD, build scripts, dev tooling) do NOT belong
  • CHANGELOG entries are SHORT -- one or two sentences, plain language, lead with the user-visible effect, and start with the verb its section names (Add, Fix, Bound, ...). No root-cause narration, no mechanism, no run IDs or "verified on...". Longer explanations go in a docs/ guide with a link. npm run lint:changelog fails an entry over 300 rendered characters (issue references and link targets are not counted), so the limit is enforced rather than remembered
  • A fix for a defect that was never in a release -- including a post-merge review correction -- is NOT a Fixed entry (nor a Changed/Security one). The feature ships correct: fold what the fix guarantees a user into that feature's [Unreleased] Added entry and update that same entry in the follow-up PR; if that Added entry is already in a released section, leave the released section unchanged and add no Fixed entry for the defect. When asked why no entry exists, cite the existing line. Decide by reading or running the tagged implementation and tracing the affected path (not only whether the file, symbol or current code pattern exists) -- git show <tag>:<path> -- not memory
  • Public members carry a minimal <summary> -- this is a public library, and a consumer reads the API surface without the source. Minimal means one short sentence; <remarks> is for when it is genuinely needed
  • See update-documentation for detailed standards

Markdown & Links

  • Internal links MUST use ./ or ../ prefix; never use absolute GitHub Pages paths (/unity-helpers/...)
  • Never use backtick-wrapped markdown file references; use proper links
  • Escape example links with code blocks/backticks; escape pipe characters in tables with \|
  • Markdown code blocks require language specifiers; never use emphasis as headings

Formatting & Validation (Run After Each Change)

Run formatters/linters immediately after each file change, not batched at task end:

  • C#, MSBuild, and XML: dotnet tool run csharpier format <file> (or npm run format:csharp for the whole repository). npm run agent:preflight:fix formats changed supported files and npm run agent:preflight / validate:local fail on formatting drift, including linker XML, so a later edit is caught locally rather than by CI
  • Non-C# (.md, .json, .yaml, .yml): node scripts/run-prettier.js --write -- <file> (repo-local launcher; run npm install first on the host that runs hooks)
  • Markdown: npm run lint:docs + npm run lint:markdown
  • YAML: pwsh -NoProfile -File scripts/lint-yaml.ps1 -Paths <changed files> (then actionlint <changed workflows>)
  • Spelling: npm run lint:spelling (add valid terms to cspell.json). Run it manually before completion; npm run agent:preflight and CI provide the final safety net
  • Tests: pwsh -NoProfile -File scripts/lint-tests.ps1 -FixNullChecks -Paths <changed test files>, then pwsh -NoProfile -File scripts/lint-tests.ps1 -Paths <changed test files>. Passing more than one path only works because every -Paths script declares BOTH a ValueFromRemainingArguments sibling and [CmdletBinding(PositionalBinding = $false)] -- pwsh -File binds the first token and offers the rest to the other named parameters positionally, so the sibling alone only works when every neighbor happens to be a [switch]. Measured: ensure-editor.ps1 -RequiredEditorPayloadRelativePath a b put b in -InstallRoot. PWS005 enforces both halves
  • Skills, references and context: pwsh -NoProfile -File scripts/lint-skill-sizes.ps1 after edits; files of 200 or more lines fail, and default preflight also rejects the critical 199-line boundary
  • Commit prep: stage files, then run npm run agent:preflight:fix (includes changed spell-checkable file checks) before any commit attempt
  • Pre-push validation: run npm run validate:prepush before push; it is a roughly one-second last-resort Git/config safety check. Run relevant changed-file checks through npm run agent:preflight; use npm run validate:local only when a complete repository-wide aggregate is warranted. When hook or agent-preflight behavior changes, also run npm run validate:tests:hook-regressions. CI always runs the combined validate:tests aggregate. Treat git hooks as last-resort only. Follow ship-changes Step 9 for the push step.

See formatting and validate-before-commit for details.

Additional Technical Rules

Read technical rules when changing runtime, editor, or test code.

Naming Conventions

Element Convention Example
Types, public members PascalCase SerializableDictionary
Non-private fields, locals camelCase keyValue, itemCount
Private instance fields _camelCase _itemCount
Interfaces I prefix IResolver, ISpatialTree
Type parameters T prefix TKey, TValue
Events On prefix OnValueChanged
Constants (public) PascalCase DefaultCapacity
  • C# files: 4 spaces indentation; config files (.json, .yaml, .asmdef): 2 spaces
  • Preserve existing serialized field names and raw Unity JSON keys. The naming gate carries explicit historical field exceptions; a style rename must not change persisted data.
  • Line endings: CRLF for most files; YAML/.github/**/Markdown/Jekyll includes use LF
  • Encoding: UTF-8 (no BOM)

cspell Dictionary Quick Reference

Add unknown words to the appropriate dictionary in cspell.json:

Dictionary Purpose Examples
unity-terms Unity Engine APIs, components, lifecycle MonoBehaviour, GetComponent, OnValidate
csharp-terms C# language features, .NET types readonly, nullable, LINQ, StringBuilder
package-terms This package's public API and type names WallstopStudios, IRandom, SpatialHash
tech-terms General programming/tooling terms async, config, JSON, middleware
root words Project-specific tokens, incl. lint-error-code prefixes UNH, PWS (covers UNH001, PWS002…)

Lint-error-code prefixes (^[A-Z]{2,}\d{3}$ tokens like UNH001, PWS002) must be registered in the root words array. npm run validate:lint-error-codes is the contract test and will fail with a copy-pasteable patch on drift.


Assembly Definitions

Assembly Purpose
WallstopStudios.UnityHelpers Runtime code
WallstopStudios.UnityHelpers.Editor Editor code
WallstopStudios.UnityHelpers.Tests.Runtime Runtime tests
WallstopStudios.UnityHelpers.Tests.Editor Editor tests (parent)
WallstopStudios.UnityHelpers.Tests.Editor.* Feature-specific editor tests
WallstopStudios.UnityHelpers.Tests.Core Shared test utilities

Critical: Test assemblies use overrideReferences: true, so each must independently list ALL required precompiled DLLs it directly compiles against. Odin-specific source must list the Sirenix DLLs it directly compiles against and define WALLSTOP_UNITY_HELPERS_ODIN_INSPECTOR from the odininspector package. Runtime Odin bases use that package-owned define with Unity fallbacks, and the runtime asmdef stays in editor-style auto-reference mode (overrideReferences: false) so no-Odin registry installs never name missing Sirenix DLLs. See manage-assembly-definitions.


Agent Workflow and CI

Keep the root goal limited to the general objective of advancing the root plan and broad completion criteria; keep the root plan a general strategy to drive open issues toward zero, ordered by priority. Never store specific issue selections, PR state, session logs, progress tracking, status updates, validation results, or retrospectives in either file; follow maintain-plan. Route session records and temporary next actions to ignored progress/ files, scope and remaining acceptance to canonical issues, durable evidence to issues or commit bodies, and reusable guidance to context, skills, or references. A cleanup does not complete or cancel the underlying work.

Read build commands before running local checks. Read agent operations before GitHub, git, or review work. Read CI and test guidance before validation or pushing.