|
2 | 2 |
|
3 | 3 | All guidance for working with this repository is in this single file. |
4 | 4 |
|
| 5 | +## Workflow |
| 6 | + |
| 7 | +### Alignment Before Action |
| 8 | +- For non-trivial tasks, do not jump straight into implementation. First summarize: |
| 9 | + (1) your understanding of the problem, (2) the proposed approach, (3) key trade-offs or risks. |
| 10 | + Keep this short (a few sentences, not an essay). Wait for confirmation before proceeding. |
| 11 | +- **Act autonomously on clear bugs**: When the bug has a clear reproduction (failing test, error |
| 12 | + log, stack trace), go fix it — don't ask the user to guide each step. Still follow: write a |
| 13 | + failing test first, then fix, then validate. The alignment rule above still applies for ambiguous |
| 14 | + bugs where the root cause or intended behavior is unclear. |
| 15 | +- When the user requests a different approach after seeing an implementation: |
| 16 | + briefly compare the old and new approaches — state the concrete pros and cons of each. |
| 17 | + If the new approach has significant drawbacks compared to the previous one, say so clearly before implementing. |
| 18 | + The user can still choose the new approach, but the decision should be informed. |
| 19 | + |
| 20 | +### Context Management |
| 21 | +- Offload codebase exploration and research to subagents (Explore/Plan types). The main context |
| 22 | + should contain decisions and results, not the search process. |
| 23 | +- For multi-step implementations (e.g., feature + tests + adjustments), use subagents for isolated |
| 24 | + subtasks when the main context is already large. Prefer splitting into: (1) implement the feature, |
| 25 | + (2) write/adjust tests, (3) fix issues found in review. |
| 26 | +- When the user requests adjustments or additional tests after an implementation, assess whether |
| 27 | + the main context has grown large. If so, delegate the follow-up work to a subagent with a clear |
| 28 | + description of what was implemented and what needs to change. |
| 29 | + |
| 30 | +### Concurrency Awareness |
| 31 | +This codebase has concurrency concerns in bulk operations, temp table management, and test |
| 32 | +isolation. When modifying code in these areas: |
| 33 | +- Identify shared mutable state and how it is protected (e.g., temp table suffix leasing, |
| 34 | + connection/transaction lifecycle in context factories). |
| 35 | +- Consider whether new code respects existing isolation boundaries (e.g., SQL Server test lock |
| 36 | + tables, `DbContext` single-thread usage). |
| 37 | +- When adding async code, consider: cancellation propagation, `IAsyncDisposable` cleanup ordering, |
| 38 | + and whether operations need to be atomic within a transaction scope. |
| 39 | +- Remember that `DbContext` is not thread-safe — never share instances across threads. |
| 40 | + |
| 41 | +### Self-Review Before Completion |
| 42 | +Before presenting work as complete: |
| 43 | +- Re-read the final state of all changed files (not from memory — actually re-read them). |
| 44 | +- Check for: unused variables, missing null checks, inconsistent naming, unhandled edge cases. |
| 45 | +- Simplicity check: for each new variable, ask whether it's necessary — does it name a complex |
| 46 | + expression, get reused, or aid debugging? If it only holds a value used once immediately, inline it. |
| 47 | + Apply the same scrutiny to wrapper methods, intermediate collections, and extra parameters. |
| 48 | +- Verify the changes compile (`dotnet build -c Release`). |
| 49 | +- Run affected tests (`dotnet test -c Release --no-build`, or a specific test project). |
| 50 | +- For query translation changes: verify the generated SQL matches expectations using |
| 51 | + `CollectExecutedCommands()`. |
| 52 | +- Final gut-check: "Would a staff engineer approve this?" — if anything feels over-engineered, |
| 53 | + unnecessarily clever, or under-justified, simplify before presenting. |
| 54 | + |
| 55 | +### Planning |
| 56 | +- Enter plan mode for tasks that touch 3+ files or require architectural decisions. |
| 57 | +- If an approach hits a wall (repeated failures, wrong assumptions), stop and re-plan rather than |
| 58 | + pushing through. Do this immediately — do not attempt further fixes on a broken approach. |
| 59 | + Re-planning means stepping back to reassess the strategy, not retrying the same idea with tweaks. |
| 60 | + |
| 61 | +### After Corrections |
| 62 | +- When the user corrects a mistake that reflects a project-wide pattern or convention, update the |
| 63 | + relevant section of CLAUDE.md. |
| 64 | +- Corrections must become **concrete rules in the relevant section**, not vague lessons. For example, |
| 65 | + if corrected about missing `CancellationToken` propagation, update the "EF Core Specifics" section |
| 66 | + with the rule — don't append a generic note somewhere else. |
| 67 | + |
5 | 68 | ## Quick Reference |
6 | 69 |
|
7 | 70 | ```powershell |
@@ -159,7 +222,7 @@ private NpgsqlBulkOperationExecutor SUT => field ??= ActDbContext.GetService<Npg |
159 | 222 | | **Bulk Operations** | `IBulkInsertExecutor`, `IBulkUpdateExecutor`, `IBulkInsertOrUpdateExecutor` | SQL Server: `SqlBulkCopy`/MERGE; PostgreSQL: COPY protocol/INSERT ON CONFLICT; SQLite: batched INSERT/UPDATE | |
160 | 223 | | **Bulk Update from Query** | `SqlServerBulkOperationsDbSetExtensions.BulkUpdateAsync`, `NpgsqlBulkOperationsDbSetExtensions.BulkUpdateAsync`, `SqliteBulkOperationsDbSetExtensions.BulkUpdateAsync`, `SetPropertyBuilder<TTarget, TSource>` | All three providers; SQL Server: `UPDATE t SET ... FROM target INNER JOIN (subquery) AS s ON ...`; PostgreSQL/SQLite: `UPDATE target AS t SET ... FROM (subquery) AS s WHERE ...`; fluent `Set` builder; accepts `IQueryable<TSource>` as source; optional `filter` parameter (`Expression<Func<TTarget, TSource, bool>>`) restricts which rows are updated (can reference both target and source properties) | |
161 | 224 | | **Bulk Insert from Query** | `SqlServerBulkOperationsDbSetExtensions.BulkInsertAsync`, `NpgsqlBulkOperationsDbSetExtensions.BulkInsertAsync`, `SqliteBulkOperationsDbSetExtensions.BulkInsertAsync`, `InsertPropertyBuilder<TTarget, TSource>` | All three providers; generates `INSERT INTO target (cols) SELECT s.cols FROM (subquery) AS s`; fluent `Map` builder; accepts `IQueryable<TSource>` as source | |
162 | | -| **Temp Tables** | `ITempTableCreator`, `ITempTableReference`, `ITempTableQuery<T>` | Queryable wrapper with auto-cleanup; name conflict prevention via `TempTableSuffixLeasing` | |
| 225 | +| **Temp Tables** | `ITempTableCreator`, `ITempTableReference`, `ITempTableQuery<T>`, `CreateTempTableAsync`, `BulkInsertIntoTempTableAsync`, `BulkInsertValuesIntoTempTableAsync` | Two workflows: all-in-one (create+insert via `BulkInsertIntoTempTableAsync`) or two-step (`CreateTempTableAsync` for empty table + insert later); auto-cleanup via `IAsyncDisposable`; name conflict prevention via `TempTableSuffixLeasing` | |
163 | 226 | | **Window Functions** | `EF.Functions.RowNumber()`, `.Average()`, etc. | Fluent `PartitionBy()`/`OrderBy()`; all three providers | |
164 | 227 | | **Table Hints** | `query.WithTableHints(SqlServerTableHint.NoLock)` | SQL Server only | |
165 | 228 | | **Nested Transactions** | `NestedRelationalTransactionManager` | Root = real transaction; children = logical | |
|
0 commit comments