AGENT SKILL

Cratis 代码审查

cratis-code-review

依据编译器无法检查的架构、风格和规格覆盖标准,审查 Cratis 应用中变更的代码,并生成结构化报告,将阻塞性问题与建议分开列出。当被要求审查、检查或验证变更时使用。不要将其替代专项安全审计,也不要重复转述专家的性能分析结论。

License 许可
MIT
最近更新
2026-11-14
Stars
★ 1
Forks
1

01 前言 Front Matter

name
cratis-code-review
license
MIT
description
Review changed code in a Cratis application against the architecture, style, and specification-coverage criteria that the compiler cannot check, and produce a structured report with blocking issues separated from suggestions. Use when asked to review, check, or validate a change. Do not substitute it for a focused security audit and do not restate specialist performance findings.

02 资源文件 3

03 SKILL.md 正文

<!-- cratis-ai-managed: skills/cratis-code-review/SKILL.md -->

Cratis code review

A review is worth the reader's time only when it separates what must change from what could. Everything below is a criterion an analyzer does not already enforce — if the build is clean and this list is clean, the change is sound on the axes a reviewer can judge.

Review the change, not the file. A pre-existing violation in a line the change did not touch is a note, never a blocker.

Verified product sources

Package Purpose
Cratis.Arc.Core Command, query, validation and analyzer surface (ARC0001–ARC0026, including operations, authorization, generated values and explicit query selection)
Cratis.Chronicle Event, projection, read-model and constraint surface
Cratis.Fundamentals ConceptAs<T>, IInstancesOf<T>, the DI conventions

Fundamentals: ConceptAs<T> is the typed-value record; InstancesOf<T> discovers implementations and resolves them when enumerated; DI conventions honor [Singleton] and [Scoped], defaulting to transient.

Reverify against the owning product repository before asserting a framework contract this file does not already state.

Route near misses

  • A focused authentication, authorization, data-exposure, or event-sourcing security audit: use cratis-security-review.
  • A focused Chronicle, database, .NET or React scalability analysis: use cratis-performance-review. The performance items below are the ones a general reviewer should catch in passing; do not duplicate the specialist's findings when both have run.
  • Deciding whether the behavior is right at all: that is modeling, not review.

Step 1 — Run the gates first

A review that reports what the build already says is noise. Confirm the change builds clean in Debug and Release, its specifications pass, and lint and the TypeScript build are clean. Report a gate failure as the finding and stop — there is nothing to review under a red build.

Step 2 — Architecture

  • Each slice is its own folder, <Module>/<Feature>/<Slice>/<Slice>.cs, with the backend artifacts together. No top-level Features/ wrapper.
  • Namespace mirrors the folder path under the source root.
  • Commands are record types with Handle() on the record. No separate handler class.
  • Business rejection returns a ValidationResult or Result<TEvent, ValidationResult>, or comes from a validator. Never thrown from Provide() or Handle() — a throw is HTTP 500, not a validation error.
  • Fetched or computed handler data is in Provide(), not inline in Handle().
  • Events are record types: past tense, no mutable and no nullable properties, never carrying the event-source id, and each has an XML <summary>.
  • Identity concepts derive from EventSourceId<T>, not ConceptAs<Guid>.
  • Domain values are concepts, not raw Guid, string, or int.
  • Projections consume events, never read models. AutoMap is on by default — .AutoMap() appears only inside a scope disabled with .NoAutoMap().
  • A [Projection] id, once given explicitly and deployed, is permanent. The argument is optional; adding one to an existing projection after the fact changes its identity.
  • Model-bound query custom paths use [Path("...")], never ASP.NET [Route].
  • No service locator: IServiceProvider is not injected. Implementation sets come from IInstancesOf<T>, never IEnumerable<T>.
  • No explicit singleton registration where [Singleton] suffices.
  • No [Singleton] takes a scoped dependency — the event store and anything off it, a MongoDB collection/database/client, a DbContext, a read model by key. Such a type is transient or scoped instead; IServiceScopeFactory is only for a service the host itself resolves once.
  • Logging lives in a *Logging.cs partial with [LoggerMessage], not inline in domain code.
  • No shared mutable state between commands.
  • Read protection is Off by default; new code sets <CratisReadProtection>On</CratisReadProtection>. Under Off an injected model or validator read is advisory, not a concurrency guard. Under On, review that state rules sit in validators or handlers with the model as a parameter, [Unprotected("why")] carries a real reason, and a conflict spec (AppendConcurrently plus ConcurrencyViolation) exists.
  • Use Cratis.Arc.Core.CodeAnalysis and Cratis.Arc.Chronicle.CodeAnalysis. ARCCHR0011 (Info, Off only) and 0012 flag unprotected reads/immediate bypasses; 0013 (Info) recommends definitions; 0014 checks declared observer streams; 0015 warns on nullable events; 0016 flags ignored concurrency flags; 0017/0018 check stream-id templates; 0019 warns on folds exposed as queries. ARC0015 checks concept query inputs, ARC0016–18 operations, ARC0019–21 authorization, ARC0022–25 generated values and ARC0026 explicit/ambiguous queries. A clean build cannot prove the Info-level decision advisories were addressed. Sources: Arc Source/DotNET/Arc.Core.CodeAnalysis/DiagnosticDescriptors.cs and Source/DotNET/Chronicle.CodeAnalysis/DiagnosticDescriptors.cs.

Step 3 — C# style

  • File-scoped namespaces; using directives sorted, none unused.
  • is null / is not null, never == null / != null.
  • var over an explicit type.
  • No Async, Impl, Service, Manager or Helper postfix on a class name.
  • No regions.
  • Custom exception types only — never InvalidOperationException, ArgumentException or another built-in (ARC0012 flags this on Arc artifacts). The XML doc starts with "The exception that is thrown when …".
  • Every public type, method and property carries a multiline XML doc. <summary> is never collapsed onto one line. Every parameter has a <param>; every non-void method has <returns>; every throw has an <exception cref>.
  • The copyright header is on every file; the file ends with one newline.

Step 4 — TypeScript and components

  • const over let over var; no unused imports.
  • No any. Use unknown with a type guard; widen through value as unknown as TargetType rather than (x as any).
  • No @ts-ignore or @ts-expect-error without a comment saying why.
  • Full descriptive names — never e, idx, prev, dir, pos.
  • CommandDialog from @cratis/components/CommandDialog for command dialogs; Dialog from @cratis/components/Dialogs for data-only dialogs. Never a vendor or hand-rolled modal.
  • No hard-coded hex or rgb colors — --cratis-* tokens only. No !important without a justifying comment.
  • Components live in the slice folder. No barrel index.ts that re-exports one component, and no technical hooks/ / utils/ / types/ grouping at feature level.
  • The copyright header is on every file.

Step 5 — Performance, in passing

Performance is part of an ordinary review, not only a separate pass. Flag the degradations a reviewer can see without measuring:

  • A projection joining on a read model; a reactor re-querying the event log inside a handler instead of using the event data.
  • A new projection that could not replay all earlier events; events carrying large blobs.
  • A query that does not filter on an indexed field; a growable list that does not return a shape Arc pages (IQueryable<T>, or MongoDB Observe); a query that pages or sorts itself or uses MongoDB AsQueryable(); hydrating a collection only to count it.
  • An N+1 pattern; a response payload with fields no client reads.
  • React: a growable list rendering every row; an inline object or array literal passed as a prop, changing identity every render; wrong useEffect dependencies.
  • .NET: .ToList() before .Where(); an IEnumerable<T> enumerated more than once.

Step 6 — Specification coverage

  • Pure command, reducer and reactor decisions have plain-call specifications (Specification plus a direct call); scenarios are added where pipelines, validation, constraints, projections or wiring contribute proof.
  • Every State Change command has a happy-path specification.
  • Every validation rule has a failure specification asserting both ShouldNotBeSuccessful() and ShouldHaveValidationErrors().
  • Every business-rule rejection has a specification.
  • Every constraint has an EventScenario specification asserting the constraint name by default.
  • Presentation message strings are not asserted by default. Exact wording is asserted only when it is the specified behavior, and the fact names that requirement.
  • Nothing trivial is specified — a property getter, a constructor pass-through, a delegation.
  • No specification sleeps to let the system catch up.

Step 7 — Report

Read and use .cratis/ai/rules/review-reports.md when writing the report.

Correctness regressions, broken contracts, and missing specification coverage that leaves changed behavior unverified belong in Blockers when they require correction before merge. Style preferences and maintainability improvements without such a consequence belong in Suggestions. Apply the shared verdict vocabulary to those findings.

What breaks

  • The review restates the compiler. The gates were not run first, so analyzer output is being reported as review findings.
  • Every finding is blocking. The distinction is what makes the report actionable; if everything blocks, nothing is prioritized.
  • A convention is reported as a framework contract. The slice folder shape and the single-file default are house conventions; Handle() on the record and the [Path] attribute are contracts. Saying "the framework requires this" of a convention loses the reader's trust for the findings that are contracts.

How it is proven

The build, the specifications, lint and the TypeScript build are all green before the report is written, and the report names both what was reviewed and what was not.

04 同仓库更多 Skills

Cratis
Cratis/Specifications

.NET SIMD 向量化代码

vectorization

设计、实现、优化和审查 .NET 中的 SIMD 代码:使用 TensorPrimitives、Vector64、Vector128、Vector256、Vector512 或硬件内部函数将标量循环向量化,并审查现有 SIMD 代码(包括泛型 Vector 类型)的契约等价性、尾部处理、内存安全性、可移植性、回退方案和实测性能。当正在编写或审查 .NET 循环或 SIMD 例程时使用。不用于与 SIMD 无关的性能工作。

软件开发工程师性能剖析与优化
★ 1
Cratis
Cratis/Specifications

MSBuild自定义目标编写

target-authoring

编写自定义 MSBuild target 的规范模式:DependsOnTargets 与 BeforeTargets、AfterTargets 的区别,Build-to-CoreBuild 三级模式,以及 XxxDependsOn 链式扩展模式。用于诊断或修复自定义 target 的反模式:Directory.Build.targets 重新定义 SDK target、target 替换而非扩展 CompileDependsOn、Outputs 与 Returns 误用导致返回过期结果、缺少 Inputs/Outputs 导致不必要的重新构建,或缺少 FileWrites 注册。不适用于增量构建调优或一般反模式审查(使用 msbuild 技能),也不适用于非 MSBuild 构建系统。

软件开发工程师开发环境与工具链管理
★ 1
Cratis
Cratis/Specifications

.NET测试命令执行

run-tests

选择并运行与仓库兼容的 .NET 测试命令:针对 MSTest、xUnit、NUnit 和 TUnit 的 classic、VSTest、bridged MTP 或 native MTP 语法。在运行 .NET 测试或需要给出测试命令/标志时使用:运行全部测试、单个测试、测试类、类别、trait 或目标框架、组合筛选器、--filter-query、--no-build、--diag、TRX、覆盖率收集、崩溃或挂起转储、筛选错误或无法识别的选项。不适用于仅做平台识别(使用 platform-detection)、编写或调试测试代码、解读覆盖率报告(使用 coverage-analysis)、CI 调查、迁移或持续的热重载循环。

测试工程师测试与质量保障
★ 1
Cratis
Cratis/Specifications

.NET 性能剖析

profiling

使用免费的官方 .NET 诊断 CLI 工具在代码仓库中进行性能剖析和运行时调查:CPU、GC 压力、分配增长、异常风暴、锁竞争和慢代码。当 .NET 应用程序需要性能或运行时剖析时使用。不适用于用临时跟踪替代真实的性能或负载测试、无暂停风险计划的生产堆内存采集、崩溃转储(使用 dump-collect),或基准测试设计(使用 microbenchmarking)。

软件开发工程师性能剖析与优化
★ 1
Cratis
Cratis/Specifications

.NET 测试平台识别

platform-detection

识别 .NET 项目的测试平台、框架、命令模式,以及 SDK 样式与经典项目系统,并解析 global.json、项目文件、packages.config、Directory.Build.props 和 Directory.Packages.props 对 MSTest、xUnit、NUnit 和 TUnit 的优先级。当询问“使用哪种测试平台或框架”“VSTest 还是 MTP”或“该项目使用什么测试运行器”时使用,包括桥接设置、UseVSTest 退出选项,以及 VSTest/MTP 配置冲突。不适用于运行或筛选测试、命令、标志、TRX、转储或测试命令错误(使用 run-tests),也不适用于热重载或迁移请求。

测试工程师测试与质量保障
★ 1
Cratis
Cratis/Specifications

Orleans 分布式系统设计

orleans

从每种原语的用途和失效模型出发设计 Microsoft Orleans 系统:grain、数字孪生、状态与数据库、事务、消息传递、流(streams)、计时器(timers)、提醒(reminders)、Durable Jobs(持久作业)、无状态工作进程、grain 服务、启动与托管。当任务需要做出 Orleans 设计决策时使用:检查版本与拓扑、选择原语、实现并验证。不适用于其他 actor 技术栈、批处理、纯关系型 CRUD,或不涉及 Orleans 决策的建议。

系统架构师系统架构设计模式
★ 1