From 25987377b7d3b041eff98c1a6be2b0ab1181edd3 Mon Sep 17 00:00:00 2001 From: Seto Elkahfi Date: Mon, 9 Nov 2026 14:12:51 +0100 Subject: [PATCH] Add Onde.Code as a NuGet .NET tool Onde.Cli, SiGit.Code and SmbCloud.* are on NuGet; onde-code was the odd one out. packaging/nuget/onde-code is a launcher that picks the bundled binary for the host and passes stdio through, so ACP over a pipe and the terminal UI both still see the real handles. release-nuget.yml runs on the same v* tag as the npm and GitHub releases. It builds the five targets only (no Windows arm64, and the launcher says so), builds just the onde-code bin so the test-only fake-mcp-server stays out of the package, and publishes through NuGet trusted publishing. The nuget.org policy and the NUGET_USER secret have to exist before the first release. Co-Authored-By: Claude Sonnet 5.5 --- .agents/AGENTS.md | 2 + .github/workflows/release-nuget.yml | 349 ++++++++++++++++++++++ .gitignore | 7 + README.md | 2 + docs/install.md | 10 + packaging/nuget/onde-code/OndeCode.csproj | 42 +++ packaging/nuget/onde-code/Program.cs | 120 ++++++++ packaging/nuget/onde-code/README.md | 59 ++++ 8 files changed, 591 insertions(+) create mode 100644 .github/workflows/release-nuget.yml create mode 100644 packaging/nuget/onde-code/OndeCode.csproj create mode 100644 packaging/nuget/onde-code/Program.cs create mode 100644 packaging/nuget/onde-code/README.md diff --git a/.agents/AGENTS.md b/.agents/AGENTS.md index 7bd7fb5..75a0c20 100644 --- a/.agents/AGENTS.md +++ b/.agents/AGENTS.md @@ -42,4 +42,6 @@ Push a `v*` tag matching the `[workspace.package]` version in the root `Cargo.to `release-npm.yml` ("Code Release npm") runs on the same tag and publishes `@ondeinference/onde-code` (a Node launcher in `packaging/npm/onde-code`) plus five platform packages, `@ondeinference/onde-code-{darwin-arm64,darwin-x64,linux-x64,linux-arm64,windows-x64}`. Auth is npm Trusted Publishing; npm authenticates with OIDC, not a token. Trusted Publishers are configured per package (all six point at `release-npm.yml`), so a new package needs one before its first CI publish; run `packaging/npm/scripts/setup-trusted-publishing.sh` to create and attach them. Verify with `npm view @ondeinference/onde-code version`. +`release-nuget.yml` ("Code Release NuGet") runs on the same tag and publishes `Onde.Code`, a .NET tool (`packaging/nuget/onde-code`) that bundles the five binaries and launches the one for the host. Auth is NuGet Trusted Publishing: nuget.org needs a policy for this repo and `release-nuget.yml`, and the `NUGET_USER` repo secret holds the profile name that owns the package. Its jobs check out `inputs.tag`, so a manual dispatch only works for tags that already contain `packaging/nuget/`. Verify with `https://api.nuget.org/v3-flatcontainer/onde.code/index.json`. + **winget:** `release-winget.yml` files the Package Request issue with `WINGET_ISSUE_TOKEN` (`public_repo`), then opens the manifest PR with `WINGET_PR_TOKEN`, a classic PAT with `public_repo`, `read:org`, `read:discussion`, and `workflow`. The first three cover forking and the `gh pr edit` GraphQL query. `workflow` is there because wingetcreate fast-forwards the token owner's fork before it branches, and GitHub refuses that sync once an upstream commit changes a file under `.github/workflows`. "The forked repository could not be synced with the upstream commits" can mean the PAT lacks `workflow`, or that the fork has simply drifted too far behind upstream; add the scope, or sync the fork by hand and rerun. diff --git a/.github/workflows/release-nuget.yml b/.github/workflows/release-nuget.yml new file mode 100644 index 0000000..afcf7ae --- /dev/null +++ b/.github/workflows/release-nuget.yml @@ -0,0 +1,349 @@ +name: Code Release NuGet + +# Publishes Onde.Code, a .NET tool that bundles the native onde-code binaries, on the same v* +# tag that release-github.yml and release-npm.yml build from. +# +# Auth is NuGet Trusted Publishing (OIDC), so no long-lived API key is stored. nuget.org needs a +# trusted publishing policy for this repository and workflow (release-nuget.yml), and the +# NUGET_USER repo secret must hold the nuget.org profile name that owns the package. + +on: + push: + tags: ["v*"] + workflow_dispatch: + inputs: + tag: + description: "Release tag (e.g. v1.0.4)" + required: true + +concurrency: + # A re-pushed or re-dispatched tag fires this a second time. Queue the + # duplicate behind the original instead of cancelling it: cancelling a run + # mid-publish can leave a channel half-uploaded, whereas a queued duplicate + # just hits the "already published" check and exits clean. + group: ${{ github.workflow }}-${{ github.event.inputs.tag || github.ref_name }} + cancel-in-progress: false + +permissions: + contents: read + +env: + CARGO_TERM_COLOR: always + DOTNET_VERSION: 8.0.x + NUGET_PACKAGE_ID: Onde.Code + +jobs: + # The launcher's version comes from the tag, but the binary reports CARGO_PKG_VERSION, so a + # mismatch would publish a package that lies about its version. + verify-version: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + with: + ref: ${{ github.event.inputs.tag || github.ref }} + - name: Tag matches Cargo.toml + shell: bash + env: + TAG: ${{ github.event.inputs.tag || github.ref_name }} + run: | + crate=$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -1) + if [ "$TAG" != "v$crate" ]; then + echo "::error::tag $TAG does not match Cargo.toml version $crate" + exit 1 + fi + + build-native-binaries: + name: Build native binary (${{ matrix.build.NAME }}) + needs: verify-version + runs-on: ${{ matrix.build.OS }} + strategy: + fail-fast: false + matrix: + build: + - { NAME: darwin-arm64, OS: macos-latest, TARGET: aarch64-apple-darwin } + - { NAME: darwin-x64, OS: macos-15-intel, TARGET: x86_64-apple-darwin } + - { NAME: linux-x64, OS: ubuntu-latest, TARGET: x86_64-unknown-linux-gnu } + - { NAME: linux-arm64, OS: ubuntu-24.04-arm, TARGET: aarch64-unknown-linux-gnu } + - { NAME: windows-x64, OS: windows-latest, TARGET: x86_64-pc-windows-msvc } + steps: + - name: Checkout + uses: actions/checkout@v6 + with: + ref: ${{ github.event.inputs.tag || github.ref }} + + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@stable + with: + targets: ${{ matrix.build.TARGET }} + + - name: Setup Rust cache + uses: Swatinem/rust-cache@v2 + with: + key: nuget-${{ matrix.build.TARGET }} + + # --bin keeps the test-only fake-mcp-server out of the package. + - name: Build binary + shell: bash + run: cargo build --locked --release -p onde-code --bin onde-code --target ${{ matrix.build.TARGET }} + + # The exe must not import the VC++ runtime DLLs (see .cargo/config.toml), or it fails to + # load on a machine without the redistributable. + - name: Check static CRT + if: matrix.build.NAME == 'windows-x64' + shell: pwsh + run: ./packaging/windows/check-static-crt.ps1 -Path target/${{ matrix.build.TARGET }}/release/onde-code.exe + + - name: Prepare artifact + shell: bash + env: + BUILD_NAME: ${{ matrix.build.NAME }} + run: | + executable_name="onde-code" + if [[ "${BUILD_NAME}" == windows-* ]]; then + executable_name="onde-code.exe" + fi + + mkdir -p "nuget-artifacts/native/${{ matrix.build.NAME }}" + cp "target/${{ matrix.build.TARGET }}/release/${executable_name}" \ + "nuget-artifacts/native/${{ matrix.build.NAME }}/${executable_name}" + + - name: Upload native artifact + uses: actions/upload-artifact@v4 + with: + name: nuget-native-${{ matrix.build.NAME }} + path: nuget-artifacts/native + + pack-nuget: + name: Pack NuGet .NET tool + runs-on: ubuntu-latest + needs: build-native-binaries + steps: + - name: Checkout + uses: actions/checkout@v6 + with: + ref: ${{ github.event.inputs.tag || github.ref }} + + - name: Set the release version + shell: bash + run: | + if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then + release_version="${GITHUB_REF_NAME#v}" + else + release_version="${{ github.event.inputs.tag }}" + release_version="${release_version#v}" + fi + echo "RELEASE_VERSION=${release_version}" >> "$GITHUB_ENV" + + - name: Download native artifacts + uses: actions/download-artifact@v4 + with: + pattern: nuget-native-* + path: packaging/nuget/onde-code/native + merge-multiple: true + + - name: Setup .NET SDK + uses: actions/setup-dotnet@v4 + with: + dotnet-version: ${{ env.DOTNET_VERSION }} + + - name: Pack .NET tool + shell: bash + run: | + dotnet pack packaging/nuget/onde-code/OndeCode.csproj \ + --configuration Release \ + --output packaging/nuget/dist \ + -p:PackageVersion="${RELEASE_VERSION}" + + # All five binaries ship in one package, so this sits closer to nuget.org's + # 250 MB ceiling than the single-platform npm and PyPI artifacts do. Fail + # here with a clear message rather than at `dotnet nuget push`, where the + # error is just "the package file exceeds the size limit". + - name: Check package size against the NuGet limit + shell: bash + run: | + package="$(find packaging/nuget/dist -name '*.nupkg' | head -n 1)" + size_bytes="$(wc -c < "${package}")" + limit_bytes=$((250 * 1024 * 1024)) + + echo "Package: ${package}" + echo "Size: $((size_bytes / 1024 / 1024)) MiB" + + if [ "${size_bytes}" -gt "${limit_bytes}" ]; then + echo "::error::${package} is over nuget.org's 250 MB package limit. Split the tool into RID-specific packages (.NET 10 DotnetToolRidPackage) instead of bundling every target." >&2 + exit 1 + fi + + - name: Upload package artifact + uses: actions/upload-artifact@v4 + with: + name: nuget-package + path: packaging/nuget/dist/*.nupkg + + smoke-test: + name: Smoke test (${{ matrix.os }}) + runs-on: ${{ matrix.os }} + needs: pack-nuget + strategy: + fail-fast: false + matrix: + os: + - ubuntu-latest + - windows-latest + - macos-latest + steps: + - name: Checkout + uses: actions/checkout@v6 + with: + ref: ${{ github.event.inputs.tag || github.ref }} + + - name: Set the release version + shell: bash + run: | + if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then + release_version="${GITHUB_REF_NAME#v}" + else + release_version="${{ github.event.inputs.tag }}" + release_version="${release_version#v}" + fi + echo "RELEASE_VERSION=${release_version}" >> "$GITHUB_ENV" + + - name: Download package artifact + uses: actions/download-artifact@v4 + with: + name: nuget-package + path: packaging/nuget/dist + + - name: Setup .NET SDK + uses: actions/setup-dotnet@v4 + with: + dotnet-version: ${{ env.DOTNET_VERSION }} + + - name: Install tool from local package + shell: pwsh + run: | + $packageSource = (Resolve-Path "packaging/nuget/dist").Path + @" + + + + + + + + "@ | Set-Content -Path "packaging/nuget/NuGet.Config" + + dotnet tool install ` + --tool-path ".tool" ` + --configfile "packaging/nuget/NuGet.Config" ` + --version "$env:RELEASE_VERSION" ` + "$env:NUGET_PACKAGE_ID" + + - name: Verify bundled native binary + shell: pwsh + run: | + $runtimeIdentifier = if ($IsWindows) { + if ([System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture -eq [System.Runtime.InteropServices.Architecture]::Arm64) { "windows-arm64" } else { "windows-x64" } + } elseif ($IsMacOS) { + if ([System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture -eq [System.Runtime.InteropServices.Architecture]::Arm64) { "darwin-arm64" } else { "darwin-x64" } + } else { + if ([System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture -eq [System.Runtime.InteropServices.Architecture]::Arm64) { "linux-arm64" } else { "linux-x64" } + } + + $binaryName = if ($IsWindows) { "onde-code.exe" } else { "onde-code" } + $nativeBinary = Get-ChildItem ".tool/.store" -Recurse -File | Where-Object { + $_.FullName -like "*native*${runtimeIdentifier}*${binaryName}" + } | Select-Object -First 1 + + if (-not $nativeBinary) { + Write-Error "The onde-code native binary for ${runtimeIdentifier} was not bundled in the installed .NET tool package." + } + + Write-Host "Found bundled native binary at $($nativeBinary.FullName)" + + publish-nuget: + name: Publish to NuGet + runs-on: ubuntu-latest + needs: smoke-test + # Trusted Publishing exchanges a GitHub OIDC token for a short-lived NuGet + # API key, so no long-lived NUGET_API_KEY secret is stored. Requires a + # trusted publishing policy on nuget.org for this repository and workflow + # (release-nuget.yml); without one the login step fails. + permissions: + contents: read + id-token: write + steps: + - name: Set the release version + shell: bash + run: | + if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then + release_version="${GITHUB_REF_NAME#v}" + else + release_version="${{ github.event.inputs.tag }}" + release_version="${release_version#v}" + fi + echo "RELEASE_VERSION=${release_version}" >> "$GITHUB_ENV" + + - name: Download package artifact + uses: actions/download-artifact@v4 + with: + name: nuget-package + path: packaging/nuget/dist + + - name: Setup .NET SDK + uses: actions/setup-dotnet@v4 + with: + dotnet-version: ${{ env.DOTNET_VERSION }} + + - name: Check whether release already exists on NuGet + id: nuget-check + shell: bash + run: | + package_index_url="https://api.nuget.org/v3-flatcontainer/onde.code/index.json" + + # Keep the fetch and the version match separate. Piping curl into + # grep hides a failed fetch behind an empty match, so an outage or a + # blocked request would read as "not published yet" and send the + # publish below into a version that is already there. A 404 here + # means the package itself is not on NuGet, which is the first + # release and a real "not published". + index=$(mktemp) + STATUS=$(curl -sS -o "${index}" -w '%{http_code}' \ + --retry 3 --retry-delay 2 --retry-all-errors "${package_index_url}") + + case "$STATUS" in + 200) + if grep -F "\"${RELEASE_VERSION}\"" "${index}" >/dev/null; then + echo "${NUGET_PACKAGE_ID} ${RELEASE_VERSION} already exists on NuGet, skipping publish" + echo "exists=true" >> "$GITHUB_OUTPUT" + else + echo "exists=false" >> "$GITHUB_OUTPUT" + fi + ;; + 404) + echo "${NUGET_PACKAGE_ID} is not on NuGet yet, publishing its first version" + echo "exists=false" >> "$GITHUB_OUTPUT" + ;; + *) + echo "Unexpected ${STATUS} from NuGet while checking whether ${NUGET_PACKAGE_ID} ${RELEASE_VERSION} is published" >&2 + exit 1 + ;; + esac + + # Exchange the workflow's OIDC token for a short-lived NuGet API key. The + # key is written to the environment for the subsequent `dotnet nuget push` + # via the NUGET_API_KEY variable this action sets. + - name: NuGet trusted-publishing login + if: steps.nuget-check.outputs.exists != 'true' + uses: NuGet/login@v1 + id: nuget-login + with: + user: ${{ secrets.NUGET_USER }} + + - name: Publish package + if: steps.nuget-check.outputs.exists != 'true' + shell: bash + run: | + dotnet nuget push packaging/nuget/dist/*.nupkg \ + --api-key "${{ steps.nuget-login.outputs.NUGET_API_KEY }}" \ + --source https://api.nuget.org/v3/index.json \ + --skip-duplicate diff --git a/.gitignore b/.gitignore index d63106f..ff621d8 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,10 @@ # Node (npm launcher) node_modules/ + +# NuGet (.NET tool) +packaging/nuget/**/bin/ +packaging/nuget/**/obj/ +packaging/nuget/**/native/ +packaging/nuget/dist/ +packaging/nuget/NuGet.Config diff --git a/README.md b/README.md index 1d5cceb..5e73942 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@

Website npm + NuGet Crates.io Release CI @@ -35,6 +36,7 @@ It is one static binary written in Rust, and it also accepts any OpenAI API comp ```sh npm install -g @ondeinference/onde-code # pulls in the binary for your platform +dotnet tool install -g Onde.Code # or as a .NET tool npx @ondeinference/onde-code --acp # or run it without installing, from an editor ``` diff --git a/docs/install.md b/docs/install.md index fd3cfdf..f0c3fde 100644 --- a/docs/install.md +++ b/docs/install.md @@ -30,6 +30,16 @@ install: npx @ondeinference/onde-code --acp ``` +## NuGet (.NET tool) + +```sh +dotnet tool install --global Onde.Code +``` + +The package bundles the binaries for macOS, Linux and Windows x64, plus macOS and Linux arm64, +so it is larger than the npm packages. There is no Windows arm64 build, and the launcher says so +when it runs there. + ## winget ```sh diff --git a/packaging/nuget/onde-code/OndeCode.csproj b/packaging/nuget/onde-code/OndeCode.csproj new file mode 100644 index 0000000..edca8b3 --- /dev/null +++ b/packaging/nuget/onde-code/OndeCode.csproj @@ -0,0 +1,42 @@ + + + Exe + net8.0 + + Major + enable + enable + true + onde-code + Onde.Code + 0.0.0-local + $(PackageVersion) + Seto Elkahfi + Copyright 2026 Splitfire AB + Coding agent for fine-tuning, managing and deploying models on Onde Inference. + README.md + Apache-2.0 + https://ondeinference.com + https://github.com/ondeinference/onde-code + onde;onde-inference;cli;ai;coding-agent;llm;acp;developer-tools;dotnet-tool + true + + + + + + + + diff --git a/packaging/nuget/onde-code/Program.cs b/packaging/nuget/onde-code/Program.cs new file mode 100644 index 0000000..b1b6bd7 --- /dev/null +++ b/packaging/nuget/onde-code/Program.cs @@ -0,0 +1,120 @@ +using System.ComponentModel; +using System.Diagnostics; +using System.Runtime.InteropServices; + +internal static class Program +{ + private const string CommandName = "onde-code"; + + public static async Task Main(string[] arguments) + { + try + { + string executablePath = ResolveExecutablePath(); + EnsureExecutablePermissions(executablePath); + return await RunAsync(executablePath, arguments); + } + catch (Exception exception) when ( + exception is FileNotFoundException or + PlatformNotSupportedException or + Win32Exception) + { + Console.Error.WriteLine($"{CommandName}: {exception.Message}"); + return 1; + } + } + + private static string ResolveExecutablePath() + { + string runtimeIdentifier = GetRuntimeIdentifier(); + string executableName = OperatingSystem.IsWindows() ? $"{CommandName}.exe" : CommandName; + string executablePath = Path.GetFullPath( + Path.Combine(AppContext.BaseDirectory, "native", runtimeIdentifier, executableName)); + + if (!File.Exists(executablePath)) + { + throw new FileNotFoundException( + $"The native {CommandName} executable for '{runtimeIdentifier}' is not bundled in this package.", + executablePath); + } + + return executablePath; + } + + private static string GetRuntimeIdentifier() + { + string operatingSystem = OperatingSystem.IsWindows() + ? "windows" + : OperatingSystem.IsMacOS() + ? "darwin" + : OperatingSystem.IsLinux() + ? "linux" + : throw new PlatformNotSupportedException( + $"{CommandName} does not support this operating system through the .NET tool package."); + + if (OperatingSystem.IsWindows() && RuntimeInformation.ProcessArchitecture == Architecture.Arm64) + { + throw new PlatformNotSupportedException( + $"{CommandName} does not ship a Windows arm64 build yet. Use the x64 build under emulation or run it from WSL."); + } + + string architecture = RuntimeInformation.ProcessArchitecture switch + { + Architecture.X64 => "x64", + Architecture.Arm64 => "arm64", + _ => throw new PlatformNotSupportedException( + $"{CommandName} does not support the '{RuntimeInformation.ProcessArchitecture}' architecture through the .NET tool package."), + }; + + return $"{operatingSystem}-{architecture}"; + } + + private static void EnsureExecutablePermissions(string executablePath) + { + if (OperatingSystem.IsWindows()) + { + return; + } + + UnixFileMode currentMode = File.GetUnixFileMode(executablePath); + UnixFileMode requiredMode = UnixFileMode.UserRead | + UnixFileMode.UserWrite | + UnixFileMode.UserExecute | + UnixFileMode.GroupRead | + UnixFileMode.GroupExecute | + UnixFileMode.OtherRead | + UnixFileMode.OtherExecute; + + if ((currentMode & requiredMode) == requiredMode) + { + return; + } + + File.SetUnixFileMode(executablePath, currentMode | requiredMode); + } + + private static async Task RunAsync(string executablePath, IReadOnlyList arguments) + { + // onde-code picks its mode from whether stdin is a TTY: a terminal gets + // the ratatui chat UI, a pipe gets the ACP server. Leaving all three + // streams unredirected makes the child inherit this process's handles, + // so that detection sees the real terminal (or the real pipe from an + // editor) rather than something this launcher introduced. + ProcessStartInfo startInfo = new(executablePath) + { + UseShellExecute = false, + WorkingDirectory = Environment.CurrentDirectory, + }; + + foreach (string argument in arguments) + { + startInfo.ArgumentList.Add(argument); + } + + using Process process = Process.Start(startInfo) + ?? throw new Win32Exception($"Failed to start '{CommandName}'."); + + await process.WaitForExitAsync(); + return process.ExitCode; + } +} diff --git a/packaging/nuget/onde-code/README.md b/packaging/nuget/onde-code/README.md new file mode 100644 index 0000000..1438169 --- /dev/null +++ b/packaging/nuget/onde-code/README.md @@ -0,0 +1,59 @@ +# Onde Code for .NET + +`onde-code` is the command-line interface for [Onde Code](https://ondeinference.com), a coding agent +for fine-tuning, managing and deploying models on Onde Inference. It works in any +[Agent Client Protocol](https://agentclientprotocol.com) (ACP) editor or in the terminal. + +## Install + +```sh +dotnet tool install --global Onde.Code +``` + +## Update + +```sh +dotnet tool update --global Onde.Code +``` + +## Run + +```sh +onde-code +``` + +In a terminal that opens the chat UI. When an editor starts it with its streams piped, the same +binary speaks ACP over stdio instead. Get an app key at [ondeinference.com](https://ondeinference.com). + +## Platform support + +This .NET tool bundles native `onde-code` binaries for: + +- macOS `arm64`, `x64` +- Linux `arm64`, `x64` (glibc) +- Windows `x64` + +There is no Windows `arm64` build yet, and the launcher says so instead of failing to start. + +Because all five binaries ship in one package, the install is larger than the npm packages, which +each download only the binary for your platform. + +## Other installation methods + +- npm: `npm install -g @ondeinference/onde-code` +- winget: `winget install OndeInference.OndeCode` +- GitHub Releases: + +## Source + +- Repository: +- Website: +- Issues: + +## License + +[Apache 2.0](https://github.com/ondeinference/onde-code/blob/main/LICENSE) + +## Copyright + +© 2026 [Splitfire AB](https://5mb.app) ([Onde Inference](https://ondeinference.com)).