Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@ sign.
- The **.NET 10 runtime**, for the `net10.0` test legs (the .NET 10 SDK carries it).
It must be the latest .NET 10 runtime patch: the build
targets the newest patch the pinned SDK knows (`TargetLatestRuntimePatch`)
- On Windows, the **.NET Framework 4.7.2 targeting pack** for the `net472` legs
- [Bun](https://bun.sh/) at the exact version in `external/opencode/package.json`'s
`packageManager` field, first on `PATH` — the pinned-server fixture and CI use that runtime, and
`OpenCode.Sdk.Tests` refuses to run under any other Bun
`packageManager` field, first on `PATH` — required by default and in CI; the explicit local-host
exception is in [quality-gates.md](../docs/engineering/quality-gates.md#completion-gate)
- [ripgrep 15.1.0](https://github.com/BurntSushi/ripgrep/releases/tag/15.1.0) on `PATH` — the
filesystem live tests run against an offline simulated server that refuses the on-demand download
upstream would otherwise perform
Expand All @@ -61,9 +60,9 @@ sign.

`external/` holds read-only upstream checkouts used as protocol evidence and as the pinned-server
test fixture. They are **never** hand-edited. If you cloned without `--recurse-submodules`, run
`git submodule update --init --depth 1 external/opencode`. Then install the pinned server's
dependencies once, with the pinned Bun first on `PATH`:
`cd external/opencode && bun install --frozen-lockfile --ignore-scripts`.
`git submodule update --init --depth 1 external/opencode`. Complete the
[fresh-checkout preparation](../docs/engineering/quality-gates.md#completion-gate) before the
build and tests below; it installs both the pinned server's dependencies and the clone detector.

2. **Build the Project**

Expand Down
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Run from the repository root — see [`docs/engineering/quality-gates.md`](../do
- [ ] No new analyzer warnings; any new suppression follows the policy in [`docs/engineering/slop-review.md`](../docs/engineering/slop-review.md) and is named below
- [ ] The change passes the slop rubric in the same file
- [ ] No tests skipped, weakened, or deleted to make the suite pass
- [ ] All tests pass locally
- [ ] The [required local checks](../docs/engineering/quality-gates.md#completion-gate) pass, or the documented exemption applies
- [ ] Branch is up to date with the target branch, no merge conflicts
- [ ] Commit messages follow [Conventional Commits](https://www.conventionalcommits.org/) and carry **no AI-attribution trailers**

Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ The next SDK version is **2.0.0**, on the same opencode **2.3.0** pin already re
- `OpenCodeClientOptions.Headers` and `OpenCodeRequestOptions.Headers` set client-wide and per-call HTTP headers, with per-call values winning; on the message and inbox reads, the capability header `MediaReferences` sends replaces both.
- `OpenCodeServer.ResolveAsync` selects an explicit endpoint, an owned standalone server or the shared service with the CLI's precedence, including the saved `disabled` flag. Connections expose resolve-time `ServerVersion`; explicit mismatches can invoke `OnServerVersionMismatch`. Managed `ServiceOperations` reconnect or restart with a best-effort persistent-terminal handoff using the resolve-time snapshot.
- `OpenCodeServerStopOptions.Pty` accepts `OpenCodeServerStopPtyMode.Handoff` so that `StopAsync` attempts a best-effort persistent-terminal handoff after it reads the registration and before it signals the process. Follow it with `EnsureAsync` using the same registration selection to restart as the managed connection does; preservation depends on preparing and adopting the ticket before it expires. Null and `Clear` keep the default: terminals end with the service, as with the CLI's `service restart`.
- `Plugins.WaitForPluginsAsync` waits for a location's plugins to load, as the CLI does before listing agents, models and integrations; `LanguageModels.WaitForDefaultAsync` now runs it.
- `Plugins.WaitForPluginsAsync` runs the bounded, best-effort plugin poll that opencode's CLI runs before it lists agents, models and integrations; returning does not guarantee activation completed. `LanguageModels.WaitForDefaultAsync` now runs it.
- `OpenCodeServer.ShutdownPersistentPtyAsync` discovers the background service and, when one is running, shuts down its persistent terminals, as opencode's CLI does before an uninstall; with no service it does nothing. It is experimental (`OPENCODE002`).
- Virtual `EventsClient.GetConnectionState()` and `WatchConnectionAsync(CancellationToken)` expose `EventConnectionState` and `EventConnectionStatus` (Idle, Connecting, Connected, Reconnecting). Watches coalesce to the latest unread state and do not start or retain a source.
- `OpenCodeEventSubscriberOverflowException.Capacity` reports the SDK's fixed 4,096 bound, including for instances constructed through its standard public constructors.
Expand Down
4 changes: 2 additions & 2 deletions GLOSSARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ A persistent conversation with an Agent, and the API's central concept.

**Session metadata**:
Host-supplied annotations on a Session: arbitrary keys with JSON values, opaque to opencode and
durable from creation. Children and forks inherit the parent's unless their creator supplies its
own.
durable from creation. Children inherit the parent's unless creation supplies an override; forks
copy the parent's metadata.

**Message**:
One entry in a Session's projected history, of one kind: user, assistant, synthetic, system, skill,
Expand Down
44 changes: 30 additions & 14 deletions docs/ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@ to issues in [the milestones](https://github.com/opencode-dotnet/opencode-sdk-do
per release, and [`1.x`](https://github.com/opencode-dotnet/opencode-sdk-dotnet/milestone/2) for the
work deferred from `1.0.0`.

The next SDK release is **2.0.0**, as `../Directory.Build.props` declares. The shared event connection
([#902](https://github.com/opencode-dotnet/opencode-sdk-dotnet/pull/902),
[ADR-0041](adr/0041-one-shared-event-feed-per-client.md)) replaces per-enumeration connections with one
background source per root client. Ordinary attempt failures retry indefinitely
and reach connection state instead of ending subscriptions. These hand-written runtime/error-channel
breaks require a major release, on the same opencode **2.3.0** pin already shipped in SDK `1.1.0`
([Unreleased breaking changes](../CHANGELOG.md#-breaking-changes)).

Separately, milestone [`Next`](https://github.com/opencode-dotnet/opencode-sdk-dotnet/milestone/5)
is the current unversioned first-party parity and fix queue, not a promise that every item ships in
`2.0.0`.

## Status

**Released, and the protocol surface is complete.** The callable surface is generated from an
Expand Down Expand Up @@ -48,27 +60,29 @@ accepted OpenAPI snapshot and rides one hand-written transport runtime.
still lists 1.x releases. The pin tracks upstream 2.x release tags and is refreshed under receipt
right before a release, not between releases. The accepted protocol identity is owned by `../spec/SNAPSHOT.md`.
- **Packages** — the two packages publish as `OpenCodeDotNet.Sdk` and
`OpenCodeDotNet.Sdk.Extensions` (the assemblies stay `OpenCode.Sdk`) and pack at the
single-sourced `VersionPrefix 1.1.1`, the next version. Every `master` push publishes a nightly of
it to the organization's GitHub Packages feed, and `1.1.0`, the latest release, is on NuGet.org, owned by
`OpenCodeDotNet.Sdk.Extensions`; their assembly and namespace names are unchanged
([package boundary](architecture/platform-and-packaging.md#packages)). They pack at the next version
declared by `../Directory.Build.props`. Nightly publication follows the
[publication policy](architecture/platform-and-packaging.md#repository-and-versioning), and
`1.1.0`, the latest release, is on NuGet.org, owned by
`OpenCode.NET` and pushed through the manual lane over Trusted Publishing. The ids carry
`OpenCodeDotNet` because nuget.org reserves the `OpenCode.` prefix for an unrelated owner. The
earlier ids, `OpenCodeAI.Sdk` and `OpenCodeAI.Sdk.Extensions`, receive no further versions.

## Road to 1.0

Releases stayed `0.9.0-preview.N` until the freeze; `1.0.0` ships from the release-candidate commit,
with no `-rc` package. Each workstream has a
short plan in the private companion repository when it starts, and its issues sit in milestone
`1.0` on the project board. Only work that breaks or decides the public surface, the gates that enforce the freeze,
and the items named below come before `1.0.0`; additive and internal work waits in milestone
`1.x`. In order:
`1.0.0`, `1.0.1`, and `1.1.0` are released; milestones `1.0` and `1.0.1` are closed. The workstreams
below record the road to 1.0; step 6's release rehearsal is the release check, and
[#796](https://github.com/opencode-dotnet/opencode-sdk-dotnet/issues/796), the `1.0.0` benchmark
record, is still open in milestone `1.x`.
Milestone `1.x` holds deferred additive and internal work. The current release and parity/fix queue
are identified above.

1. **Support policy.** The MCP server's repository (ADR-0030), the target-framework policy
(ADR-0002), and the end of the .NET 5–7 promise
([#51](https://github.com/opencode-dotnet/opencode-sdk-dotnet/issues/51)). **Complete.**
2. **Target-framework transition.** `net11.0` joins now on its go-live release candidate and
`net8.0` and `net9.0` leave now, ahead of their end of support on 2026-11-10, across packages,
2. **Target-framework transition.** `net11.0` is targeted; `net8.0` and `net9.0` are not, and
`global.json` pins GA SDK `11.0.100` with prereleases disabled. The matrix covers packages,
tests, CI legs, the public API check, and the docs; no non-preview package is built on a pre-GA
SDK (one exception, `1.0.0`: step 8). A consumer whose target falls back to the `netstandard2.0`
asset on an unsupported runtime gets a build warning. It ships in `0.9.0-preview.10`. Launcher
Expand All @@ -79,8 +93,10 @@ and the items named below come before `1.0.0`; additive and internal work waits
ladder. `OpenCodeServer.Exited`
([#174](https://github.com/opencode-dotnet/opencode-sdk-dotnet/issues/174)) reports how a
standalone server ended — exit code, signal, or unknown, as upstream's `exited` does — on every
target and OS. **Landed.** Exit: every leg runs `netstandard2.0`, `net472`, `net10.0`, and
`net11.0` as its platform allows.
target and OS. **Landed.** Exit: build `netstandard2.0`, `net472`, `net10.0`, and `net11.0` package
assets; tests execute on `net10.0`/`net11.0` and on `net472` on Windows
([target policy](architecture/platform-and-packaging.md#target-frameworks),
[gate](engineering/quality-gates.md#completion-gate)).
3. **Maintainability review.** A time-boxed, read-only review limited to what feeds the freeze:
a pass over the public API baseline
([#183](https://github.com/opencode-dotnet/opencode-sdk-dotnet/issues/183)), the terminal receive
Expand Down Expand Up @@ -142,7 +158,7 @@ and the items named below come before `1.0.0`; additive and internal work waits

## Parallel tracks

These do not block `1.0.0` and run beside the road.
These are parallel workstreams alongside the current release and deferred-work queues.

- **MCP server** in its own repository (ADR-0030), a thin adapter over the published SDK. The
namespace decision keeps the public namespaces, so code against the SDK can start.
Expand Down
3 changes: 2 additions & 1 deletion docs/adr/0004-generated-model-principles.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ null. A source-generation-proven in-band JSON-null carrier remains non-nullable.
uses `IReadOnlyList<T>` / `IReadOnlyDictionary<string, T>` without defensive copies, read-only
wrappers, empty normalization, or recursive item/value validation. `IReadOnly*` is an API view, not
a deep-immutability guarantee; caller-supplied collection ownership stays with the caller
(ADR-0014).
(ADR-0014). The open-model `AdditionalProperties` bag is the exception; its ownership rules live in
[Generated model shape](../architecture/protocol-and-generation.md#generated-model-shape).

A literal used for union dispatch emits as a constant/get-only property because successful
dispatch already proved it; a prefix-tagged discriminator emits as a required string because
Expand Down
3 changes: 2 additions & 1 deletion docs/adr/0007-error-model.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ from selecting a member a stream or traversal must refuse at run time.

Outside the shared event bus's retry loop, transport and protocol failures throw
`OpenCodeTransportException`. The spec's tagged error
payloads are generated as typed models under an `OpenCodeError` base and ride **as data** on either
payloads are generated as typed models implementing `IOpenCodeError` (the interface representation
of [ADR-0011](0011-union-membership-as-interfaces.md)) and ride **as data** on either
channel, pattern-matchable without string sniffing. There is no client-level switch. Throwing API
errors retain the raw body on `OpenCodeApiException`; `NoThrow` responses retain it on their shared
response spine, including when a typed error cannot be parsed. This deliberately renders upstream's
Expand Down
6 changes: 4 additions & 2 deletions docs/adr/0008-generated-operation-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ breaks the build for explicit review. Exclusion is
reserved for transports the HTTP pipeline cannot carry: `pty.connect` upgrades to
WebSocket, which leaves HTTP after the handshake and needs a different client stack
entirely. Non-JSON response bodies stay generated via a fail-closed
content-type→payload map (`application/octet-stream` → `Stream` payload on a disposable
envelope; `text/*` → `string`); an unknown content type breaks generation.
content-type→payload map (`text/*` → `string`); an unknown content type breaks generation.
The current binary response rule is in
[Operations, streams, and exclusions](../architecture/protocol-and-generation.md#operations-streams-and-exclusions)
and ADR-0029.

## Consequences

Expand Down
11 changes: 7 additions & 4 deletions docs/adr/0014-runtime-materializes-the-dotnet-shape.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ optional-and-nullable property uses `WhenWritingDefault` instead, because its ab
wrapper's `default` rather than CLR null. Optional collections remain nullable
rather than normalizing absence to empty. Generated collections are shallow `init`-only
`IReadOnlyList<T>` / `IReadOnlyDictionary<string, T>` surfaces: the SDK does not copy or wrap
caller-supplied collections, and callers own later mutation.
caller-supplied collections, and callers own later mutation. The open-model `AdditionalProperties`
bag is the exception to the collection rules; its ownership and absent-bag representation live in
[Generated model shape](../architecture/protocol-and-generation.md#generated-model-shape).

Union discriminator checks remain because they select the concrete C# type; unknown tags retain
their explicit raw-payload carriers. Required members, non-null top-level payloads, enum token
Expand All @@ -35,9 +37,10 @@ string enums: ADR-0035.

## Consequences

- Null-rejecting optional-property converters, collection-child scans, empty normalization,
defensive collection copies, and non-discriminator literal validation are removed. The closed
`Optional<T?>` converters are not that validation returning: they carry an admitted JSON null
- Apart from the open-model bag's collection rules, null-rejecting optional-property converters,
collection-child scans, empty normalization, defensive collection copies, and non-discriminator
literal validation are removed. The closed `Optional<T?>` converters are not that validation
returning: they carry an admitted JSON null
into a distinct CLR state instead of refusing it, and refuse nothing the schema admits.
- A valid UTF-8 one-shot success may materialize directly from bytes. Charset/BOM selection and
malformed-UTF-8 replacement remain equivalent to `HttpContent` string decoding, so the fast path
Expand Down
5 changes: 3 additions & 2 deletions docs/adr/0024-owned-and-shared-local-server-handles.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ Date: 2026-09-16

`OpenCodeServer` is the one process-backed local-server handle. `StartAsync` returns an owned
standalone child whose disposal stops it; `DiscoverAsync` and `EnsureAsync` return a shared
registered service whose disposal is a no-op, and only the static `StopAsync` ends the current
registration. Ownership stays visible through `OwnsProcess`. A discovered handle has one operation
registered service whose disposal is a no-op. Deliberate stop and restart follow the
[connection lifecycle](../architecture/client-runtime.md#connection-modes).
Ownership stays visible through `OwnsProcess`. A discovered handle has one operation
(`CreateClient`) and an empty disposal, the shape ADR-0019 rejects for generated API handles; that
ceremony is accepted here as the price of one type instead of a second near-identical public type
whose only difference would be disposal semantics. ADR-0019 governs generated family handles and
Expand Down
4 changes: 2 additions & 2 deletions docs/adr/0028-generated-tostring-masks-secret-members.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ generator's format pass strips it; structural unions override `ToString()` for t
unchanged.
- A refresh that adds a secret-shaped member fails generation until a row decides it; the
pending-operation probe sets that wall aside, since a missing row is curation, not a shape wall.
- Response envelopes are hand-written records outside this mechanism; their printed form leaves
out the raw error body.
- Response envelopes use separate envelope emission and inherit raw-error-body omission from the
hand-written `OpenCodeResponse` spine.
- Reversal: upstream projects a secret marker into the OpenAPI document (for example
`format: password` or `writeOnly` from Effect's `Schema.Redacted`); the marker then becomes the
floor and the recorder list a cross-check.
7 changes: 7 additions & 0 deletions docs/architecture/protocol-and-generation.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,13 @@ Curation may:
operation identity, never an `operationNames` row (ADR-0008);
- declare that a family emits an internal raw layer rather than a public surface, where
hand-written code owns that family's public doors (ADR-0021);
- project session ownership through `sessionScopedEvent`: its configured unions (`IEvent` and
`ISessionEventDurable`) and member path (`data.sessionID`) qualify an event only when the
identifier is required and references the configured schema (`Session.ID`), not merely a
string-shaped schema. A qualifying event's payload must be required and non-nullable and its
identifier must bind to a non-nullable string, or generation fails. A row with no qualifying event
refuses as stale. Qualified records implement
`ISessionScopedEvent.SessionId` explicitly through that path, leaving serialization unchanged;
- document a generated type or one of its members where the wire says too little, through a
reason-bearing `descriptions` row keyed by the generated C# type and optional member: its summary
replaces the generated one and its remarks join any the type already carries; a row on an
Expand Down
16 changes: 11 additions & 5 deletions docs/engineering/developing-on-windows.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Developing on Windows

Date: 2026-11-06
Date: 2026-11-17

Operational guidance for a Windows workstation. Everything here is about the developer's machine;
the test suite's own isolation rules live in `testing-style.md` and the gates in `quality-gates.md`.
Expand Down Expand Up @@ -55,14 +55,20 @@ so the two installs clobber each other's daemon binary.
cd ~/repos/opencode-sdk-dotnet/external/opencode
bun install --frozen-lockfile --ignore-scripts
```
4. Serve from `packages/cli` under isolated XDG roots and a fixed password, so the run touches no
real profile and the Windows side can authenticate:
4. Serve from `packages/cli` with a fresh `/tmp/ocsdk` tree and a fixed password. The clean child
environment drops inherited config/database and provider selectors; the isolation rules are in
[testing-style.md](testing-style.md#6-owned-servers-are-hermetic). The server also reads
`/etc/opencode`; if it exists, move it aside first.
```sh
cd ~/repos/opencode-sdk-dotnet/external/opencode/packages/cli
mkdir -p /tmp/ocsdk/data /tmp/ocsdk/cache /tmp/ocsdk/config /tmp/ocsdk/state
rm -rf /tmp/ocsdk
mkdir -p /tmp/ocsdk/{data,cache,config,state,home,tmp}
touch /tmp/ocsdk/home/.zshrc
env -i PATH="$PATH" HOME=/tmp/ocsdk/home OPENCODE_TEST_HOME=/tmp/ocsdk/home \
XDG_DATA_HOME=/tmp/ocsdk/data XDG_CACHE_HOME=/tmp/ocsdk/cache \
XDG_CONFIG_HOME=/tmp/ocsdk/config XDG_STATE_HOME=/tmp/ocsdk/state \
OPENCODE_CONFIG_CONTENT='{}' OPENCODE_DISABLE_MODELS_FETCH=1 OPENCODE_PASSWORD=<pw> \
TMPDIR=/tmp/ocsdk/tmp OPENCODE_DISABLE_PROJECT_CONFIG=1 \
OPENCODE_CONFIG_CONTENT='{}' OPENCODE_DISABLE_MODELS_FETCH=1 OPENCODE_PASSWORD='<pw>' \
bun src/index.ts serve --port 4097
```
5. On Windows, point the fixture at it and run the persistent PTY legs:
Expand Down
Loading
Loading