Skip to content

Commit ba43df2

Browse files
Merge pull request #268 from TimeWarpEngineering/dev
Agent context regions: skill extraction, AGENTS.md maintenance rule, 160-file backfill (050-010)
2 parents a9a45c6 + 3c5e4ca commit ba43df2

164 files changed

Lines changed: 1946 additions & 74 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

AGENTS.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# AGENTS.md
2+
3+
Guidance for all coding agents working in this repository (included by CLAUDE.md).
4+
5+
## Agent Context Regions — maintenance rule
6+
7+
Non-trivial source files carry embedded context regions (`#region Purpose`, `#region Design`,
8+
optionally `#region Open Questions`). These are part of the code, not decoration:
9+
10+
- **When you edit a file that has regions, reconcile them with your change before finishing.**
11+
A Design region describing the old approach is a bug you just introduced.
12+
- **When you create a non-trivial source file, add `Purpose` and `Design` regions** at the top,
13+
before the namespace.
14+
- **When you read an unanswered question in `#region Open Questions` that you can answer,**
15+
answer it (or implement the answer and remove the pair).
16+
17+
Formats, lifecycle, and what counts as trivial: see the `agent-context-regions` skill.

CLAUDE.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
44

5+
@AGENTS.md
6+
57
## Repository Structure
68

79
This is a **multi-project repository** containing .NET project templates and supporting infrastructure:
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Add #region Purpose and #region Design to all migrated source files
2+
3+
## Parent
4+
050-establish-root-directory-structure-source-tests-in-kebab-case
5+
6+
## Summary
7+
8+
All 050-x migration subtasks are complete; this is the deferred backfill pass. Add
9+
`#region Purpose` and `#region Design` blocks to every non-trivial .cs file under `source/`, per
10+
the **agent-context-regions** skill. Deferred until after migration so regions are written with
11+
full architectural context.
12+
13+
Adoption at task start: **4 of 304** .cs files have `#region Purpose`; 0 have `#region Design`.
14+
15+
## Scope
16+
17+
All .cs files under `source/`:
18+
- `source/foundation/` (foundation-contracts, -contracts-generators, -domain, -application,
19+
-infrastructure, -server)
20+
- `source/libraries/` (timewarp-modules)
21+
- `source/analyzers/` (timewarp-architecture-attributes, -analyzers, -contract-analyzers)
22+
- `source/container-apps/` (web, api, grpc, aspire, yarp)
23+
24+
## Skills
25+
26+
- agent-context-regions (format, placement, maintenance rule, what counts as trivial)
27+
- csharp (surrounding style)
28+
29+
## Checklist
30+
31+
### Phase 1: Inventory
32+
- [x] Inventory: 168 non-trivial candidates (excluded markers, global-usings, generated, <12-line
33+
files, and the 4 already done).
34+
- [x] Grouped path-ordered into 14 slices of ~12 files for project-affine context.
35+
36+
### Phase 2: Add Regions
37+
- [x] 14-agent workflow backfilled **160 files** (commit `98c63180`; 1,861 insertions, **0 deletions**
38+
— verified insertion-only via `git diff --numstat`).
39+
- [x] **8 skipped with recorded reasons**: dead commented-out entities (`category.cs`, `product.cs`),
40+
`#if false` body (`user-claims-base.cs`), sub-threshold stubs (`greeter-service.cs`,
41+
`SideNavigationLink.razor.cs`, `assembly-extensions.cs`), and files whose single design fact
42+
was already an inline comment (`constants.cs`, `java-script-interop-constants.cs`).
43+
- [x] Rules enforced in agent prompts: why-not-what, no temporal language, insertion-only, ≤14 lines.
44+
45+
### Phase 3: Verify
46+
- [x] `dev build` green (0/0) — regions coexist with source-generated partials.
47+
- [x] Random spot-checks carry genuine *why* (e.g. service-uri-provider: browser can't read Aspire
48+
env vars → server exposes /service-discovery; policy-registration: explicit always-true
49+
Anonymous policy avoids special-casing).
50+
51+
## Result
52+
53+
Region coverage went from 4/304 to 164/304 `.cs` files, with the remainder deliberately trivial.
54+
Freshness from here on is the `AGENTS.md` maintenance rule; presence enforcement via an analyzer
55+
remains a candidate follow-up (see Notes).
56+
57+
## Notes
58+
59+
- Ongoing freshness is covered by the maintenance rule in `AGENTS.md` (included by CLAUDE.md):
60+
every edit reconciles the file's regions. This task is the one-time backfill.
61+
- Candidate follow-up (own task): a `TWPA` analyzer in `timewarp-architecture-contract-analyzers`
62+
flagging non-trivial files without `#region Purpose` — presence enforcement, same lesson as the
63+
nullability analyzer.
64+
65+
## Session
66+
- Created: ses_2d78597cfffeIe36aerm1ibchw (2026-04-21)

kanban/to-do/050-010-add-region-purpose-and-region-design-to-all-migrated-source-files.md

Lines changed: 0 additions & 74 deletions
This file was deleted.

source/analyzers/timewarp-architecture-analyzers/diagnostics/diagnostic-descriptors.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
#region Purpose
2+
// Authoritative registry of the TWE diagnostic ID range for the [ApiEndpoint] generation contract.
3+
#endregion
4+
5+
#region Design
6+
// Centralized so IDs stay unique and stable across the generator and its validators; an ID may
7+
// exist here without a referencing check — reserve the ID first, wire the enforcement separately.
8+
// All are Errors: a violated generation contract yields a missing or broken endpoint at runtime,
9+
// so it must fail the build instead.
10+
#endregion
11+
112
namespace TimeWarp.Architecture.Analyzers;
213

314
internal static class DiagnosticDescriptors

source/analyzers/timewarp-architecture-analyzers/generators/fast-endpoint-source-generator.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
#region Purpose
2+
// Generates FastEndpoint classes from [ApiEndpoint] contract types in referenced assemblies.
3+
#endregion
4+
5+
#region Design
6+
// Opt-in via the EnableApiEndpointGeneration MSBuild property (default false) so any project can
7+
// reference the analyzers package without silently emitting endpoints.
8+
// Scans referenced-assembly symbols rather than the current compilation's syntax: contracts live
9+
// in a separate project from the server that hosts the generated endpoints.
10+
// Reports SG002 instead of failing when FastEndpoints/BaseFastEndpoint are absent — feature flags
11+
// can strip those references while the generator package remains attached.
12+
// Catches all exceptions (CA1031): a throwing generator would break the entire compilation.
13+
#endregion
14+
115
namespace TimeWarp.Architecture.Analyzers;
216

317
using TimeWarp.Architecture.Analyzers.Models;

source/analyzers/timewarp-architecture-analyzers/helpers/string-extensions.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
#region Purpose
2+
// Case-convention conversions shared by the analyzers and generator.
3+
#endregion
4+
5+
#region Design
6+
// ToKebabCase must mirror the repo's file-naming convention exactly — the partial-class file-name
7+
// analyzer derives expected file names from it, so a drift here changes what the analyzer accepts.
8+
#endregion
9+
110
namespace TimeWarp.Architecture.Analyzers;
211

312
using System.Globalization;

source/analyzers/timewarp-architecture-analyzers/models/endpoint-metadata.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
#region Purpose
2+
// Extracts everything the FastEndpoint generator needs from an [ApiEndpoint] contract symbol.
3+
#endregion
4+
5+
#region Design
6+
// One flat DTO decouples template emission from Roslyn symbol traversal, so the generated-code
7+
// template can change without touching symbol-walking logic.
8+
// OpenAPI summary/description come from the Query/Command XML docs — the contract is the single
9+
// authoring point for API documentation.
10+
// Tags default to the feature folder name (namespace segment above "Features"), keeping OpenAPI
11+
// grouping aligned with the vertical-slice layout without per-endpoint annotation.
12+
#endregion
13+
114
namespace TimeWarp.Architecture.Analyzers.Models;
215

316
internal sealed class EndpointMetadata

source/analyzers/timewarp-architecture-analyzers/partial-class-declaration-analyzer.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
#region Purpose
2+
// Enforces the primary/secondary file convention for multi-file partial classes (TWPA0001).
3+
#endregion
4+
5+
#region Design
6+
// The convention keeps one authoritative declaration — modifiers and base class — in the file
7+
// named after the type; secondary files (Type.behavior.cs, e.g. state action partials) stay
8+
// minimal so declarations across partials can never disagree.
9+
// Both PascalCase and kebab-case file names are accepted: the repo convention is kebab-case, but
10+
// the standard .NET convention must also pass for consumers of the packaged analyzer.
11+
// Interface implementations are allowed in secondary files (the 'I'-prefix heuristic); only class
12+
// inheritance is restricted, so the type's ancestry is stated exactly once.
13+
#endregion
14+
115
namespace TimeWarp.Architecture.Analyzers;
216

317
[DiagnosticAnalyzer(LanguageNames.CSharp)]

source/analyzers/timewarp-architecture-analyzers/validation/route-registry.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
#region Purpose
2+
// Detects duplicate route+verb registrations across generated endpoints (TWE003).
3+
#endregion
4+
5+
#region Design
6+
// Static because incremental-generator source outputs run per symbol with no shared pipeline
7+
// state; the generator resets it at Initialize so entries from a prior compilation cannot
8+
// produce false conflicts. ConcurrentDictionary guards parallel source-output invocations.
9+
// First registration wins — the conflicting endpoint is reported and simply not generated,
10+
// keeping the rest of the compilation usable.
11+
#endregion
12+
113
namespace TimeWarp.Architecture.Analyzers;
214

315
internal sealed class RouteRegistry

0 commit comments

Comments
 (0)