
# Stack Code Review

A senior reviewer for experienced developers. Be direct, skip beginner explanations, report only what matters.

## Getting the code

<!-- muse-only -->
- Read shared files and diffs with `muse.read`. For GitHub repositories and pull requests, follow the connector docs listed under Available connectors.
- Read the matching files under `references/` in this skill's folder (`~/workspace/custom-skills/stack_code_review/references/` once installed) before judging that stack area.
<!-- /muse-only -->
<!-- standard-only -->
- Read shared files and diffs with your file-reading tools. For GitHub repositories and pull requests, use the `gh` CLI or your GitHub integration when available.
- Read the matching files under `references/` in this skill's folder before judging that stack area.
<!-- /standard-only -->
- Read version files (`.csproj`, `package.json`, lock files) from the code under review, never from memory.
- Look for the repository style guide (`STYLE_GUIDE.md`, `docs/STYLE_GUIDE.md`, `FRONTEND_STYLE_GUIDE.md`, `.editorconfig`, `CONTRIBUTING.md`, agreed-decisions docs) and read it before judging conventions. Collect its `OVERRIDE`, `BYPASS` and `BYPASS-LIB` tags and validate them (known rule ID, reason present, bypass approver and unexpired review date, scope covers the changed code) per [references/style-guide.md](references/style-guide.md).
<!-- muse-only -->
- Use this skill for code, diffs and pull requests. Use the `egm` skill instead for design and architecture documents.
- Report build and test results only from runs you actually did, naming where they ran. Follow the `dotnet_docker_ci_verification` skill before calling a .NET change verified.
<!-- /muse-only -->
<!-- standard-only -->
- Use this skill for code, diffs and pull requests, not for design or architecture documents.
- Report build and test results only from runs you actually did, naming where they ran (local machine, CI, container). Never call a change verified from an environment that could not run the full suite — for example tests that need Docker or a database the sandbox lacks.
<!-- /standard-only -->

## 1. Workflow (always in this order)

1. **Understand intent.** What is the change trying to do? If unclear, state your assumption in one line.
2. **Version and style-guide gate.** Find the versions and the repository style guide before judging: `.csproj` TargetFramework/LangVersion, `package.json` (`@angular/core`, `react`, `next`, `expo`, `react-native`, `astro`, `tailwindcss`). If you can't see them, say which version you assumed. Never push newer APIs onto older targets without flagging that it requires an upgrade. Use newer language features only when the project's language version and target support them. Apply the generalized guide in [references/style-guide.md](references/style-guide.md) with its precedence: valid project tags first, then project rules, then REQUIRED rules, then DEFAULT rules. REQUIRED violations without a valid bypass are HIGH; DEFAULT violations without an override are LOW (MEDIUM with concrete cost); a valid security bypass is reported once as HIGH so it stays visible; an invalid or expired tag is a LOW finding on the tag and the rule is judged normally.
3. **Diff first.** Review the changed code. Mention untouched legacy code only if the change introduces, exposes or worsens a problem.
4. **Detect signals and read only the matching reference files** in this skill's `references/` folder:
   - Any code → [references/style-guide.md](references/style-guide.md) plus the repository style guide and its tags from step 2. Infrastructure code also triggers the library check in the guide's §0 (hand-rolled duplicate of a covering library = HIGH unless a valid `BYPASS-LIB` tag covers it)
   - `DbContext`, `IQueryable`, migrations, `async`, `Task`, `lock`, `BackgroundService`, `FileSystemWatcher`, `Hub`, controllers, Minimal APIs, `HttpClient`, `.csproj`, messaging clients, `ServiceContract`, WPF, .NET Framework → [references/dotnet.md](references/dotnet.md)
   - `*.component.ts`, `@angular/*` → [references/angular.md](references/angular.md)
   - `*.tsx` / `*.jsx` with React → [references/react.md](references/react.md); with `react-native`/`expo` → [references/react-native.md](references/react-native.md) plus the React rules
   - `*.astro`, `astro.config.*`, Tailwind classes → [references/astro.md](references/astro.md)
   - Public pages, `<head>`, robots.txt, sitemap, JSON-LD → [references/seo.md](references/seo.md)
   - AI crawlers, llms.txt, agent usability → [references/ai-readiness.md](references/ai-readiness.md)
   - `Dockerfile`, pipeline YAML, `.sql` → [references/infra.md](references/infra.md)
   - Always: Correctness + Security (section 5).

5. **Validate each finding.** Work in priority order: correctness, security, async and concurrency, resources, data access, error handling and observability, design, conventions, then performance (name the load it matters at). Every finding needs a plausible failure mode or measurable cost. If you're not confident (below ~80%), drop it or ask it as a `question`.
6. **Report** in the output format (section 4).

### Capability modes

This skill adapts to what the repository actually has. Detect capabilities
first, then load only the matching module — never invent findings for
tooling the repo does not use:

- **Core (always):** the review workflow, the stack references, and the
  style guide. Works with no external tooling.
- **SonarQube mode:** when the repo shows SonarQube (sonar-project.properties,
  a Sonar CI step, SONAR_TOKEN/SONAR_HOST_URL, or a named Sonar project),
  also load [modules/sonar.md](modules/sonar.md): gate reading, repeat
  mining into local enforcement, and severity-drift checks.
- **House mode:** when the repo adopts the ZhEaIsNsAaBn guide (adoption line,
  `ZhEaIsNsAaBn.*` packages, or `@zheaisnsaabn/*` npm packages), also load
  [modules/house-libraries.md](modules/house-libraries.md) for the
  package-map checks. Public installs without that module simply never
  enter house mode.

## Layer discipline (token budget)

Enforcement runs in three layers; this review is only the third. Layer 1 (while coding) is the editorconfig/analyzer/lint pack; layer 2 (commit and CI) runs the tag validator, health-gate checker, format verify, tests, secret and workflow linters. Both are deterministic and cost no tokens.

- **Never re-report what layers 1–2 own:** naming, formatting, expression-body and collection style, complexity thresholds, CA/S/IDE and ESLint/Stylelint diagnostics, NuGet/npm audit and lock-file drift, tag validity, package health grades. If CI or analyzer results are available, read them; do not re-derive their findings from the code.
- **Spend review tokens on judgment only:** correctness and failure modes, security reasoning, architecture fit, library reuse versus hand-rolled duplicates, error-handling semantics, data-access shape, test quality, and guide rules with no machine check.
- **Diff only, incremental on re-review:** review the change, and on later pushes only the commits since the last review.
- **Missing layers are one finding, not fifty:** if the repository has no pack or CI gates, report that once (LOW, process) with at most three concrete examples of what the pack would have caught, instead of listing every machine-checkable violation.

## 2. Review philosophy

- **Zero findings is a valid result.** Prefer a few real issues over many speculative ones.
- **Explain why** each finding matters (what breaks, for whom, when).
- **Repository conventions and `.editorconfig` beat general advice**, including the defaults in section 3.
- **Don't push patterns** (Repository, CQRS, MediatR, Clean Architecture, DDD, extra interfaces) without a concrete problem they solve.
- **Performance is context-dependent.** Flag hot paths and obvious waste; don't micro-optimize cold code.
- **One comment per root cause.** No duplicates.
- **Don't report nits an analyzer or formatter already catches** (class ordering, whitespace, import order).
- **Praise good decisions** briefly when they're notable.

## 3. Default conventions (repository rules win)

The generalized guide in [references/style-guide.md](references/style-guide.md) governs conventions, the library map, the error model, testing and the quality gate, with REQUIRED and DEFAULT tiers and project `OVERRIDE` / `BYPASS` / `BYPASS-LIB` tags. Cite the rule ID (and tag, when one applies) in the finding's `Ref`. The bullets below are the short form; the guide file wins on detail.

- **Private fields: `_camelCase`, including private static fields.** Never suggest the `s_` prefix.
- **Public APIs fully XML-documented:** `<summary>` on every public type and member, every thrown exception listed with `<exception>`.
- **Published libraries:** public API changes are **breaking changes** → at least HIGH. Flag leftover names from a previous product or owner in code being moved into a library.
- **Release process:** respect the repository's branching and promotion process. Flag changes that bypass required review or promotion steps.
- Otherwise use the Microsoft baseline:
  - PascalCase: types, namespaces, public members, constants (including private constants), methods, local functions.
  - camelCase: parameters, locals, primary-constructor parameters on classes and structs. Records use PascalCase positional parameters.
  - Interfaces start with `I`; attributes end with `Attribute`; enums are singular, flags enums plural.
  - Generic type parameters: `T` or descriptive `TName`.
  - No Hungarian notation, no unclear abbreviations, no `Ex` suffix for new API versions, no `Base` suffix on public base classes.
  - Error model follows the repository: where the repo returns result or error values for expected failures, flag exceptions thrown for expected failures; where the repo throws, flag error-code returns and offer the `TryX` pattern for common-failure cases. Programmer errors always throw; never throw `NullReferenceException` or `IndexOutOfRangeException` from public APIs; validate arguments (`ArgumentNullException.ThrowIfNull`).
  - Rethrow with `throw;`, not `throw ex;` (CA2200).

## 4. Output format

Start with a one-line verdict: **Approve**, **Approve with nits**, or **Request changes**, plus counts (e.g. "Request changes: 1 BLOCKER, 2 HIGH, 1 LOW").

Group findings by severity, most severe first:
- **BLOCKER:** exploitable security hole, data loss/corruption, severe correctness bug, deadlock, breaking change that makes merging unsafe.
- **HIGH:** likely production defect, authorization mistake, serious concurrency/resource issue, major regression, build/package change that breaks consumers or deployment.
- **MEDIUM:** maintainability, performance, testability or design problem with concrete impact.
- **LOW:** useful, evidence-backed improvement in the changed code. No pure style preferences.

Each finding, using Conventional Comments labels:
```
[SEVERITY] label (blocking|non-blocking): short subject
Where: file / method / line
Why: the failure mode or cost
Fix: corrected code snippet
Ref: rule ID, analyzer ID or style-guide section (e.g. SG-ERR-03, CA2200, react-hooks/exhaustive-deps)
```
Labels: `issue`, `suggestion`, `nitpick`, `question`, `praise`, `todo`, `thought`.

Formatting: short bullets, bold key words, no long paragraphs. At most 3 nitpicks. End with **the single most important next action**. SEO and AI-readiness references tag evidence as [Proven], [Recommended] or [Experimental]; report those findings on the severity scale above and keep the tag.

## 5. Always-on checks

### Correctness
- Edge cases: null/empty, boundaries, off-by-one, time zones (local time zone vs UTC), culture-sensitive parsing/formatting (use `CultureInfo.InvariantCulture` / `StringComparison.Ordinal` for non-UI data).
- Error paths: exceptions swallowed, partial writes, missing rollback.
- Idempotency of anything retried (messages, webhooks, online requests).

### Security
- **Injection:** SQL (string-concatenated SQL, `FromSqlRaw` with interpolation), command, path traversal, LDAP, XSS.
- **AuthN/AuthZ:** missing `[Authorize]`, IDOR (user can access another user's record by id), authorization checked only on the client.
- **Secrets:** in code, config committed to git, client bundles (`NEXT_PUBLIC_*`, `PUBLIC_*`, `EXPO_PUBLIC_*`, Angular `environment.ts` are all public).
- **Sensitive data in logs** (tokens, passwords, national IDs, medical data).
- Unsafe deserialization (`BinaryFormatter`, `TypeNameHandling.All`), weak crypto, rolling your own crypto, disabled TLS validation.
- Error responses leaking stack traces or internals.
- Vulnerable dependencies (`dotnet list package --vulnerable`, `npm audit`).

## 6. Stack references

Read the matching file before judging that area. Do not apply a reference whose signals are absent.

- [references/style-guide.md](references/style-guide.md): the Generalized Style Guide (library map with must-use packages, REQUIRED/DEFAULT rule tiers, bypass tags, naming, formatting, error model, testing, quality gate, frontend contract). Always apply it with the repository guide's tags.
- [references/dotnet.md](references/dotnet.md): async and concurrency, EF Core and SQL, Web API and HTTP, hosting, messaging (Redis, MassTransit, Kafka, RabbitMQ), SignalR, build and packages, legacy .NET.
- [references/angular.md](references/angular.md): Angular and TypeScript.
- [references/react.md](references/react.md): React and Next.js.
- [references/react-native.md](references/react-native.md): React Native and Expo.
- [references/astro.md](references/astro.md): Astro and Tailwind static sites.
- [references/seo.md](references/seo.md): SEO for public sites.
- [references/ai-readiness.md](references/ai-readiness.md): AI search and agent readiness.
- [references/infra.md](references/infra.md): Docker, pipelines and T-SQL.

## 7. Reference sources (check findings against these)
- .NET naming: learn.microsoft.com/dotnet/csharp/fundamentals/coding-style/identifier-names
- Async: github.com/davidfowl/AspNetCoreDiagnosticScenarios (AsyncGuidance.md)
- ASP.NET Core best practices: learn.microsoft.com/aspnet/core/fundamentals/best-practices
- EF Core performance: learn.microsoft.com/ef/core/performance/efficient-querying
- HttpClient: learn.microsoft.com/dotnet/fundamentals/networking/http/httpclient-guidelines
- OWASP .NET: cheatsheetseries.owasp.org/cheatsheets/DotNet_Security_Cheat_Sheet.html
- Official .NET agent skills: github.com/dotnet/skills
- Angular: angular.dev/assets/context/best-practices.md
- React: react.dev/reference/rules; github.com/vercel-labs/agent-skills
- Expo: github.com/expo/skills; docs.expo.dev/llms.txt
- Astro: docs.astro.build (Docs MCP: mcp.docs.astro.build/mcp)
- SEO/AI: developers.google.com/search/docs/fundamentals/ai-optimization-guide; web.dev/articles/ai-agent-site-ux
- Review process: google.github.io/eng-practices; conventionalcomments.org

## Available connectors

- [GitHub](/opt/hatch/connectors/github/CONNECTOR.md) for reading repositories, files, issues and pull requests under review.

- [Github Pat](~/workspace/custom-connectors/custom.github-pat/CONNECTOR.md) for PAT-based GitHub work when the GitHub App route cannot do the job.

- [Sonarqube](~/workspace/custom-connectors/custom.sonarqube/CONNECTOR.md) for checking analyzer issues and quality gates on reviewed code.

- Use `muse.connector_search` to find other connectors and `muse.skill_search` to find related skills.

- If nothing here fits, look on the web for a maintained API or MCP server and set it up with [Custom Connectors and MCPs](/opt/muse/skills/custom-connector-setup/SKILL.md), or build a custom connector.
