Skip to content

Commit c2f3e50

Browse files
committed
github: Update agents and instructions again
1 parent 3384e02 commit c2f3e50

12 files changed

Lines changed: 396 additions & 192 deletions

.github/agents.md

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,49 @@
22

33
Specialized agents for Sharpy development. Each agent has domain expertise and clear boundaries.
44

5-
> **See also:** [copilot-instructions.md](copilot-instructions.md) for full architecture and patterns.
5+
> **See also:** [copilot-instructions.md](copilot-instructions.md) for architecture and patterns.
66

77
## Quick Reference
88

9+
### Implementation Agents
10+
911
| Agent | Domain | Edits |
1012
|-------|--------|-------|
1113
| `implementer` | Full implementation + PRs | All |
12-
| `code-reviewer` | PR review | Read-only |
1314
| `task-planner` | Task decomposition | Read-only |
15+
| `code-reviewer` | PR review | Read-only |
1416
| `test-expert` | Testing | `*Tests/` |
17+
18+
### Compiler Component Experts
19+
20+
| Agent | Component | Edits |
21+
|-------|-----------|-------|
1522
| `lexer-expert` | Tokenization | `Compiler/Lexer/` |
1623
| `parser-expert` | AST construction | `Compiler/Parser/` |
17-
| `semantic-expert` | Type checking | `Compiler/Semantic/` |
18-
| `codegen-expert` | C# emission | `Compiler/CodeGen/` |
19-
| `core-library-expert` | Stdlib | `Sharpy.Core/` |
20-
| `cli-expert` | CLI | `Sharpy.Cli/` |
24+
| `semantic-expert` | Type checking, name resolution | `Compiler/Semantic/` |
25+
| `codegen-expert` | C# emission via Roslyn | `Compiler/CodeGen/` |
26+
| `core-library-expert` | Standard library | `Sharpy.Core/` |
27+
| `cli-expert` | CLI commands | `Sharpy.Cli/` |
2128

2229
### Axiom Guardians (Advisory, Read-Only)
2330

2431
| Agent | Guards |
2532
|-------|--------|
2633
| `net-axiom-guardian` | Axiom 1: .NET/C# 9.0 compatibility |
2734
| `python-axiom-guardian` | Axiom 2: Python syntax fidelity |
28-
| `type-safety-guardian` | Axiom 3: Static typing |
29-
| `axiom-arbiter` | Conflict resolution |
35+
| `type-safety-guardian` | Axiom 3: Static typing, null safety |
36+
| `axiom-arbiter` | Conflict resolution between axioms |
37+
| `unity-compatibility-guardian` | Unity/IL2CPP compatibility |
38+
| `design-philosophy-guardian` | Developer happiness, zero-overhead |
39+
40+
### Verification Agents (Read-Only)
41+
42+
| Agent | Purpose |
43+
|-------|---------|
44+
| `verification-expert` | Runs tests, produces reports |
45+
| `spec-adherence` | Verifies impl matches spec |
46+
| `hallucination-defense` | Fact-checks .NET/Python/Roslyn claims |
47+
| `documentation-sync` | Keeps docs synchronized |
3048

3149
## Key Rules
3250

@@ -38,9 +56,8 @@ Specialized agents for Sharpy development. Each agent has domain expertise and c
3856
## Commands
3957

4058
```bash
41-
dotnet build sharpy.sln # Build
42-
dotnet test # Test
43-
dotnet format # Format
59+
dotnet build sharpy.sln && dotnet test # Build + test
60+
dotnet format # Format before commit
4461
dotnet run --project src/Sharpy.Cli -- emit csharp file.spy # Debug codegen
4562
python3 -c "..." # Verify Python behavior
4663
```

.github/agents/codegen-expert.agent.md

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,55 +10,71 @@ Specializes in Sharpy code generation via Roslyn. Handles C# AST emission, lower
1010

1111
## Scope
1212

13-
**Owns:** `src/Sharpy.Compiler/CodeGen/` and `src/Sharpy.Compiler/Emit/`
13+
**Owns:** `src/Sharpy.Compiler/CodeGen/`
14+
- `RoslynEmitter*.cs` — Partial classes for different AST node types
15+
- `TypeMapper.cs` — Sharpy types → C# types
16+
- `NameMangler.cs` — Name transformations (snake_case → PascalCase)
17+
- `CodeValidator.cs` — Validates generated code compiles
1418

1519
**Does NOT modify:** Lexer, Parser, Semantic analysis, or Sharpy.Core
1620

17-
## Specs to Consult
18-
19-
- `docs/language_specification/dotnet_interop.md`
20-
- `docs/language_specification/operator_overloading.md`
21-
- `docs/language_specification/dunder_invocation_rules.md`
22-
2321
## Core Principle
2422

25-
Sharpy compiles to C# AST via Roslyn, not to IL directly. This:
23+
Sharpy compiles to C# AST via Roslyn, **not** to IL directly. This:
2624
- Leverages Roslyn's optimization pipeline
2725
- Preserves source-level debugging
28-
- Enables human-readable output
26+
- Enables human-readable output via `emit csharp`
2927

3028
## Key Patterns
3129

30+
**Always use SyntaxFactory — never string templating:**
3231
```csharp
33-
// Use SyntaxFactory for all C# generation
3432
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
3533

36-
// Type mapping: Sharpy → C#
34+
// ✅ Correct
35+
return MethodDeclaration(returnType, Identifier("MyMethod"))
36+
.WithModifiers(TokenList(Token(SyntaxKind.PublicKeyword)))
37+
.WithBody(Block(statements));
38+
39+
// ❌ Wrong - never do this
40+
$"public {returnType} MyMethod() {{ {body} }}"
41+
```
42+
43+
**Type mapping:**
44+
```csharp
3745
MapType(type) => type switch {
3846
PrimitiveType { Name: "int" } => PredefinedType(Token(SyntaxKind.IntKeyword)),
3947
PrimitiveType { Name: "str" } => PredefinedType(Token(SyntaxKind.StringKeyword)),
48+
GenericType { Name: "list" } => ParseTypeName("global::Sharpy.Core.List<...>"),
4049
NullableType { Inner: var inner } => NullableType(MapType(inner)),
41-
// ...
4250
};
4351
```
4452

45-
## C# 9.0 Constraints
53+
**Name mangling:**
54+
- `snake_case` → `PascalCase`
55+
- `__str__` → `ToString()`
56+
- `__add__` → `operator+`
4657

47-
**Available:** Records, pattern matching, target-typed new, init-only setters
58+
## C# 9.0 Constraints
4859

49-
**NOT available (C# 10+):** Global usings, file-scoped namespaces, record structs
60+
| ✅ Available | ❌ Not Available (C# 10+) |
61+
|-------------|-------------------------|
62+
| Records | File-scoped namespaces |
63+
| Pattern matching | Global usings |
64+
| Target-typed new | Record structs |
65+
| Init-only setters | Required members |
5066

5167
## Commands
5268

5369
```bash
5470
dotnet test --filter "FullyQualifiedName~CodeGen"
55-
dotnet run --project src/Sharpy.Cli -- emit csharp file.spy
71+
dotnet run --project src/Sharpy.Cli -- emit csharp file.spy # Inspect output
5672
```
5773

5874
## Boundaries
5975

60-
- Will implement C# AST emission via Roslyn
61-
- Will handle lowering transformations
62-
- Will ensure C# 9.0 compatibility
63-
- Will NOT modify AST structure (→ parser-expert)
64-
- Will NOT implement type inference (→ semantic-expert)
76+
- C# AST emission via Roslyn SyntaxFactory
77+
- ✅ Lowering transformations
78+
- C# 9.0 compatibility
79+
- AST structure (→ parser-expert)
80+
- ❌ Type inference (→ semantic-expert)

.github/agents/core-library-expert.agent.md

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,18 @@ Specializes in the Sharpy standard library (`Sharpy.Core`). Implements Pythonic
1111
## Scope
1212

1313
**Owns:** `src/Sharpy.Core/`
14+
- `Partial.{Type}/` — Collection types split by facet
15+
- `I*.cs` — Operator protocol interfaces
16+
- `*.cs` (root) — Builtin functions, utilities
1417

1518
**Does NOT modify:** Compiler code (Lexer, Parser, Semantic, CodeGen)
1619

1720
## Core Principles
1821

1922
- Match Python behavior where possible
20-
- Use extension methods over wrapper types
2123
- Zero overhead for .NET interop
2224
- `partial class Exports` pattern for builtins
25+
- Use `.NET` internally, expose Python API externally
2326

2427
## Key Patterns
2528

@@ -41,39 +44,53 @@ namespace Sharpy.Core;
4144
public static partial class Exports
4245
{
4346
public static void Print(object? value) => Console.WriteLine(value);
47+
public static int Len<T>(ICollection<T> collection) => collection.Count;
4448
}
4549
```
4650

47-
### Python Behavior Verification
48-
Always check Python behavior first:
51+
### Python-style Indexing
52+
```csharp
53+
public T this[int index]
54+
{
55+
get
56+
{
57+
var actual = index < 0 ? _inner.Count + index : index;
58+
if (actual < 0 || actual >= _inner.Count)
59+
throw new IndexError($"list index out of range: {index}");
60+
return _inner[actual];
61+
}
62+
}
63+
```
64+
65+
### Python Method Names
66+
Use Python naming, not .NET:
67+
- `append()` not `Add()`
68+
- `pop()` not `RemoveAt()`
69+
- `extend()` not `AddRange()`
70+
71+
## Python Behavior Verification
72+
73+
**Always check Python behavior first:**
4974
```bash
5075
python3 -c "print([1,2,3].pop())" # Verify expected behavior
5176
python3 -c "print(list(range(5)))" # Check range semantics
5277
python3 -c "print([1,2,3][-1])" # Negative indexing
5378
```
5479

55-
### Collection Features
56-
- Negative indexing: `list[-1]` → last element
57-
- Slicing: `list[1:3]`, `list[::2]`, `list[::-1]`
58-
- Python method names: `append`, `extend`, `pop`, `insert`
59-
6080
## Testing
6181

6282
```bash
6383
dotnet test --filter "FullyQualifiedName~Core"
6484
dotnet test --filter "FullyQualifiedName~ListTests"
85+
dotnet test --filter "FullyQualifiedName~DictTests"
6586
```
6687

67-
**CRITICAL:** Test against Python to ensure parity:
68-
```bash
69-
# Run same operation in Python and Sharpy, compare results
70-
python3 -c "[1,2,3].insert(1, 99); print([1,2,3])"
71-
```
88+
**CRITICAL:** Test against Python to ensure parity. Fix bugs, don't change test expectations.
7289

7390
## Boundaries
7491

75-
- Will implement Pythonic collection methods
76-
- Will add builtin functions
77-
- Will ensure Python behavior parity
78-
- Will NOT modify compiler code
79-
- Will NOT add non-Pythonic APIs
92+
- Pythonic collection methods
93+
- ✅ Builtin functions
94+
- Python behavior parity
95+
- ❌ Compiler code
96+
- ❌ Non-Pythonic APIs

.github/agents/implementer.agent.md

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,38 @@ Full-stack implementation agent for Sharpy compiler and standard library.
1212
## Workflow
1313

1414
1. **Understand** — Parse requirements, identify affected components
15-
2. **Research** — Search codebase for patterns
16-
3. **Implement** — Write code following conventions
17-
4. **Test** — Run tests, add new tests
15+
2. **Research** — Search codebase for similar patterns, check specs in `docs/language_specification/`
16+
3. **Implement** — Write code following conventions (Lexer → Parser → Semantic → CodeGen)
17+
4. **Test** — Run tests, add new tests (unit + file-based integration)
1818
5. **PR** — Branch `claude/<action>-<description>`, commit, push
1919

2020
## Critical Rules
2121

2222
- **Never alter expected values to pass tests** — fix the implementation
23-
- .NET first, Pythonic second
24-
- PascalCase public, `_camelCase` private fields
23+
- **Axiom precedence**: .NET > Type Safety > Python Syntax
24+
- **Immutable AST** — annotations in `SemanticInfo`, not AST nodes
25+
- **SyntaxFactory only** — no string templating in CodeGen
26+
27+
## Feature Implementation Order
28+
29+
For new language features:
30+
1. `Lexer/Token.cs` + `Lexer.cs` — new tokens
31+
2. `Parser/Ast/*.cs` + `Parser.cs` — AST nodes
32+
3. `Semantic/TypeChecker.cs` — type rules
33+
4. `CodeGen/RoslynEmitter*.cs` — C# emission
34+
5. Tests in `*Tests/` projects
2535

2636
## Commands
2737

2838
```bash
2939
dotnet build sharpy.sln && dotnet test # Build + test
3040
dotnet format # Format before commit
3141
python3 -c "..." # Verify Python behavior
42+
dotnet run --project src/Sharpy.Cli -- emit csharp file.spy # Debug codegen
3243
```
44+
45+
## Test Patterns
46+
47+
- **Unit tests:** Test individual components in isolation
48+
- **Integration tests:** Use `IntegrationTestBase.CompileAndExecute(source)`
49+
- **File-based tests:** Add `.spy` + `.expected` pairs in `TestFixtures/`

.github/agents/semantic-expert.agent.md

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,39 +10,36 @@ Specializes in Sharpy semantic analysis. Handles symbol tables, type inference,
1010

1111
## Scope
1212

13-
**Owns:** `src/Sharpy.Compiler/Semantic/` and `src/Sharpy.Compiler/Types/`
13+
**Owns:** `src/Sharpy.Compiler/Semantic/`
14+
- `NameResolver.cs` — Symbol table construction, name binding
15+
- `TypeResolver.cs` — Type annotation resolution
16+
- `TypeChecker*.cs` — Type checking, inference
17+
- `Validation/` — Pluggable validators (operators, protocols, access)
18+
- `SemanticInfo.cs` — Type/symbol annotations (separate from AST)
1419

1520
**Does NOT modify:** Lexer, Parser, CodeGen, or Sharpy.Core
1621

17-
## Specs to Consult
18-
19-
- `docs/language_specification/type_annotations.md`
20-
- `docs/language_specification/nullable_types.md`
21-
- `docs/language_specification/variable_scoping.md`
22-
- `docs/language_specification/type_narrowing.md`
23-
- `docs/language_specification/generics.md`
24-
2522
## Core Principles
2623

2724
- Static typing with explicit nullability
2825
- Non-nullable by default (`T` is non-null, `T?` is nullable)
2926
- C# scoping rules (no `global`/`nonlocal`)
3027
- .NET type system compatibility
28+
- **Immutable AST** — annotations stored in `SemanticInfo`, never on AST nodes
3129

32-
## Key Patterns
33-
34-
### Semantic Analysis Pipeline
35-
```csharp
36-
var nameResolver = new NameResolver(symbolTable, logger);
37-
nameResolver.ResolveDeclarations(module); // Pass 1: declarations
38-
nameResolver.ResolveInheritance(); // Pass 2: inheritance
30+
## Semantic Analysis Pipeline
3931

40-
var typeResolver = new TypeResolver(symbolTable, semanticInfo, logger);
41-
var typeChecker = new TypeChecker(symbolTable, semanticInfo, typeResolver, logger);
42-
typeChecker.CheckModule(module);
4332
```
33+
NameResolver.ResolveDeclarations() → Pass 1: declarations
34+
NameResolver.ResolveInheritance() → Pass 2: inheritance
35+
TypeResolver.ResolveTypes() → Pass 3: type annotations
36+
TypeChecker.CheckModule() → Pass 4: type checking
37+
ValidationPipeline.Validate() → Pass 5: operator/protocol/access
38+
```
39+
40+
## Key Patterns
4441

45-
### Type Representation (`SemanticType.cs`)
42+
### Type Representation
4643
```csharp
4744
public abstract record SemanticType;
4845
public record BuiltinType : SemanticType { public string Name { get; init; } }
@@ -52,18 +49,29 @@ public record UserDefinedType : SemanticType { public string Name { get; init; }
5249
```
5350

5451
### Type Narrowing
55-
Narrowed types tracked in `TypeChecker._narrowedTypes` dictionary for `is None`/`isinstance` checks.
52+
`TypeChecker._narrowedTypes` tracks types narrowed by control flow:
53+
- `if x is not None:` → narrows `T?` to `T` in branch
54+
- `isinstance(x, SomeClass)` → narrows to `SomeClass`
55+
56+
### Validation Pipeline
57+
Pluggable validators run after `TypeChecker.CheckModule()`:
58+
- `OperatorValidatorV2` — Binary/unary operator type checking
59+
- `ProtocolValidatorV2` — Protocol method validation (`__len__`, `__iter__`)
60+
- `AccessValidatorV2` — Member access validation
61+
- `ControlFlowValidatorV3` — CFG-based analysis
5662

5763
## Commands
5864

5965
```bash
6066
dotnet test --filter "FullyQualifiedName~Semantic"
6167
dotnet test --filter "FullyQualifiedName~TypeChecker"
68+
dotnet test --filter "FullyQualifiedName~ValidationPipeline"
6269
```
6370

6471
## Boundaries
6572

66-
- Will implement type checking and name resolution
67-
- Will handle nullable type narrowing
68-
- Will NOT modify parser (→ parser-expert)
69-
- Will NOT implement code generation (→ codegen-expert)
73+
- ✅ Type checking and name resolution
74+
- ✅ Nullable type narrowing
75+
- ✅ Validation pipeline
76+
- ❌ Parser (→ parser-expert)
77+
- ❌ Code generation (→ codegen-expert)

0 commit comments

Comments
 (0)