agent-host-protocol / dotnet
AGENTS.md386 starsChanged 2 months agoMITView on GitHub
Conventions for AI coding agents working on the .NET client. Cross-cutting repo rules are in the root AGENTS.md; release mechanics are in RELEASING.md. Generated files are produced by scripts/generate-csharp.ts (run from the repo root via npm run generate:dotnet) from the TypeScript definitions in types/. The generator is modeled on scripts/generate-go.ts and shares its curated struct / enum / union lists — they are protocol-driven, not language-specific. After changing anything under types/, regenerate and commit; CI fails on any diff between…
In this repository10 other files it gives its agents.
- AGENTS.mdAGENTS.md
- clients/go/AGENTS.mdAGENTS.md
- clients/kotlin/AGENTS.mdAGENTS.md
- clients/swift/AGENTS.mdAGENTS.md
- docs/guide/agents.mdAGENTS.md
- channels-migrationSkill
- ahp-clientSkill
- session-metadata-migrationSkill
- groom-backlogSkill
- release-ahpSkill
The file
Files
Agent Guide — .NET client
Conventions for AI coding agents working on the .NET client. Cross-cutting
repo rules are in the root AGENTS.md; release mechanics
are in RELEASING.md.
Layout
| Path | Contents |
src/AgentHostProtocol.Abstractions/Generated/*.generated.cs | Generated wire types. Do not edit. |
src/AgentHostProtocol.Abstractions/Json/, Transport/ | Hand-written serialization support (AhpUnion, UnionConverter, WireEnumConverter, StringOrMarkdown) and the ITransport / IAhpSerializer seams. |
src/AgentHostProtocol/ | AhpClient, the reducers, the default SystemTextJsonAhpSerializer, subscriptions, and the Hosts/ multi-host runtime. |
src/AgentHostProtocol/WebSocketTransport.cs | ClientWebSocket-based transport. |
tests/AgentHostProtocol.Tests/ | xUnit tests, including the shared reducer-fixture conformance suite. |
examples/ | Runnable console samples. |
Code generation
Generated files are produced by scripts/generate-csharp.ts (run from the repo
root via npm run generate:dotnet) from the TypeScript definitions in
types/. The generator is modeled on scripts/generate-go.ts and shares its
curated struct / enum / union lists — they are protocol-driven, not
language-specific. After changing anything under types/, regenerate and
commit; CI fails on any diff between the committed sources and a fresh run.
Type mapping (TS → C#)
number→long(ordoublewhen the property carries@format float).unknown/object→System.Text.Json.JsonElement;Record<string, unknown>→Dictionary<string, JsonElement>.- Optional (
?/| undefined/| null) fields → nullable +[JsonIgnore( Condition = JsonIgnoreCondition.WhenWritingNull)]. Required fields serialize their value (a required reference left null serializes asnull, mirroring Go'snil-slice semantics). - Closed (
@exhaustive) string enums → C#enumwith[WireValue("…")]per member, (de)serialized byWireEnumConverter<T>, which rejects an unrecognized wire value because the contract says it is invalid. Open (@nonexhaustive) string enums → areadonly structwrapping the raw wire string, with the known values exposed as static members and a generated per-type converter. A value added by a newer protocol version therefore round-trips verbatim instead of failing the whole message, asversioning.mdrequires (this mirrors Kotlin'svalue classand Rust'sUnknown(String)). Bitset enums →[Flags] enum : uint, serialized as their numeric value so unknown future bits round-trip. - Discriminated unions → a sealed wrapper deriving from
AhpUnion(carryingobject? Value) plus a generatedUnionConverter<T>. Whether an unknown discriminator is preserved verbatim as a rawJsonElementor rejected is derived from the discriminator enum's@exhaustive/@nonexhaustiveannotation (viadiscriminatedUnionAllowsUnknown), so an open union stays forward-compatible and a closed one keeps rejecting invalid values.
Reducers
The reducers are a faithful port of the Go client's reducers.go and mirror
the canonical TypeScript reducers. They mutate state in place. The shared
fixtures under types/test-cases/reducers/*.json are the cross-language parity
gate — run them with dotnet test. The resourceWatch reducer is an
intentional stub (parity with the Rust and Go clients).
Testing
The shipping libraries build for netstandard2.0 and net8.0; tests run
against net8.0:
- Shared reducer conformance —
FixtureDrivenReducerTestsreplays every cross-language reducer fixture (types/test-cases/reducers/*.json). The whole set counts as a single[Theory]. - Shared wire round-trip corpus —
TypesRoundTripFixturesdata-drives the language-agnostic round-trip corpus undertypes/test-cases/round-trips/*.jsonthrough the REAL serializer, asserting decode → re-encode is a byte-exact fixed point. A[Theory](CorpusFixture) iterates every fixture in the dir. - Native unit tests —
ClientTests(fullAhpClientover an in-memoryMemTransport, the port of Go'sclient_test.go),HostsTests,MultiHostClientTests,MultiHostStateMirrorTests,NativeReducerTests,ReconnectPolicyTests,ClientIdStoreTests,FileClientIdStoreTests,TransportTests,WebSocketTransportTests. The multi-host / host / client fake servers share one declarative loop helper,FakeHost. - Cross-implementation convergence —
CrossImplementationConvergenceTestsreplays a session trace captured from an independent host, whileRealSocketTypeScriptConformanceTestslaunches the repository-local TypeScript conformance host over a real WebSocket and proves current-version negotiation, snapshot seeding fromInitializeResult, and streamed action convergence through the handwritten C# reducers. The host imports the canonical TypeScriptsessionReducerdirectly and uses the development-onlywspackage for server framing; it does not use a published package or an external service.
Cross-language parity is verified by the shared fixture corpora the suite
replays — the 189 reducer fixtures (types/test-cases/reducers/*.json) and the
round-trip corpus (types/test-cases/round-trips/*.json), both of which every
client runs. (A .NET-only grep-based test-count gate used to live here; it was
retired in favor of relying on the shared corpora, which actually exercise the
behavior rather than counting method names.)
Architecture decisions
docs/decisions/sync.md— the full menu of .NET synchronization primitives, the distinct concurrency use cases in the client, which primitive each gets (ConcurrentDictionaryfor the collections,lockfor theHostEntryfield-bundle,SemaphoreSlimonly for the WebSocket send path,Channels/Interlocked/volatileelsewhere), and thenetstandard2.0compatibility strategy.docs/decisions/serialization.md— System.Text.Json (default, in-box, fastest) behind theIAhpSerializerseam, versus Newtonsoft / lazy-DOM / validating options, across speed, memory, lazy-vs-eager, validation, dependencies, and AOT.docs/decisions/reconnect.md— hand-rolled exponential backoff (with opt-in jitter) versus Polly /Microsoft.Extensions.Resilience, and why the core stays dependency-free.
These decision records live under docs/decisions/ and are repo-only — they are not packed into any NuGet
package (only README.md is).
Releasing
Sub-package releases publish the
Microsoft.VisualStudioCode.AgentHostProtocol* packages to NuGet.org.
pipeline.yml is the tag-driven Azure DevOps release pipeline: it signs the
assemblies and packages through ESRP before publishing. The
clients/dotnet/VERSION ↔ CHANGELOG.md heading match is enforced for every
PR by npm run verify:changelog.
Out of scope
JSON-Schema validation (a
Microsoft.VisualStudioCode.AgentHostProtocol.Validation decorator over
IAhpSerializer) and DI/extension helpers
(Microsoft.VisualStudioCode.AgentHostProtocol.Extensions) are planned
follow-ups, not part of this client yet.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

