diff --git a/.agents/AGENTS.md b/.agents/AGENTS.md index 75a0c20..7217d82 100644 --- a/.agents/AGENTS.md +++ b/.agents/AGENTS.md @@ -44,4 +44,6 @@ Push a `v*` tag matching the `[workspace.package]` version in the root `Cargo.to `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`. +`release-pypi.yml` ("Code Release PyPI") runs on the same tag and publishes `onde-code` to PyPI: maturin `bin` wheels for the five targets plus an sdist, built from `packaging/pypi/onde-code`. The wheel version comes from the workspace `Cargo.toml`, so there is nothing to sync. `fake-mcp-server` is gated behind the default-on `test-binaries` feature of `crates/cli` and `pyproject.toml` sets `no-default-features`, which is what keeps the test binary out of the wheel; do not make that feature mandatory for the shipped binary. Auth is PyPI Trusted Publishing: pypi.org needs a publisher (a pending one before the first release) for this repo and `release-pypi.yml` with no environment, otherwise the publish fails with `invalid-publisher`. The publish job needs every wheel and the sdist, so one failed target publishes nothing; a fix needs a new tag because the jobs check out the tag's sources. Verify with `https://pypi.org/pypi/onde-code/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/.agents/skills/release/SKILL.md b/.agents/skills/release/SKILL.md index c6c4a48..db257e0 100644 --- a/.agents/skills/release/SKILL.md +++ b/.agents/skills/release/SKILL.md @@ -77,14 +77,25 @@ the version, builds the five targets, publishes the five `@ondeinference/onde-code`. Publishing is skipped for a version that is already on npm, so re-running is safe. +`release-pypi.yml` ("Code Release PyPI") also triggers on the tag: it builds +maturin wheels for the five targets plus an sdist, smoke-tests each wheel +(`onde-code --version` must match the tag), and publishes only if every build +passed. A version already on PyPI is skipped, so re-running is safe. + Watch the run at `https://github.com/ondeinference/onde-code/actions`. -After both workflows finish, confirm the npm package: +After the workflows finish, confirm the npm and PyPI packages: ```sh npm view @ondeinference/onde-code version +curl -s https://pypi.org/pypi/onde-code/json | python3 -c 'import json,sys; print(json.load(sys.stdin)["info"]["version"])' ``` +PyPI uses Trusted Publishing too. The project needs a publisher for this repo +and `release-pypi.yml` (environment blank) on pypi.org, under Account → +Publishing as a pending publisher until the first release creates the project. +Without it the publish step fails with `invalid-publisher`. + A new package needs a Trusted Publisher before its first CI publish. Run `packaging/npm/scripts/setup-trusted-publishing.sh` (as an `@ondeinference` org member, logged in with `npm login`). It publishes a `0.0.0` placeholder if the diff --git a/.github/workflows/release-pypi.yml b/.github/workflows/release-pypi.yml new file mode 100644 index 0000000..f6e0068 --- /dev/null +++ b/.github/workflows/release-pypi.yml @@ -0,0 +1,230 @@ +name: Code Release PyPI + +# Publishes onde-code to PyPI as maturin `bin` wheels (the native binary lands on PATH) plus an +# sdist, on the same v* tag that release-github.yml, release-npm.yml and release-nuget.yml build from. +# +# Auth is PyPI Trusted Publishing (OIDC). pypi.org needs a publisher for this repository and +# workflow (release-pypi.yml) with no environment; for the first release that is a *pending* +# publisher, created under Account > Publishing. Without one the publish fails with +# `invalid-publisher`. +# +# Windows arm64 is not built: GitHub's hosted Windows runners provide x64 Python, and maturin +# refuses to build an arm64 wheel when the interpreter reports win-amd64. + +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 + PYPI_PACKAGE: onde-code + +jobs: + # The wheel's version comes from Cargo.toml, so a tag that disagrees with it 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-wheels: + name: Build wheel (${{ 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, MANYLINUX: "2_28" } + - { NAME: linux-arm64, OS: ubuntu-24.04-arm, TARGET: aarch64-unknown-linux-gnu, MANYLINUX: "2_28" } + - { 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: 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: Build wheel + uses: PyO3/maturin-action@v1 + with: + target: ${{ matrix.build.TARGET }} + manylinux: ${{ matrix.build.MANYLINUX || 'off' }} + rust-toolchain: stable + working-directory: packaging/pypi/onde-code + args: --release --locked --compatibility pypi --out dist + + # Install the wheel the way a user would and run it, so a wheel that builds but does not + # work never reaches the publish job. The Linux wheels are built in a container but are + # installed and run on the host here, which also checks the manylinux baseline holds. + - name: Smoke test wheel + shell: bash + working-directory: packaging/pypi/onde-code + run: | + python -m venv "${RUNNER_TEMP}/smoke" + if [ -d "${RUNNER_TEMP}/smoke/Scripts" ]; then + bin_dir="${RUNNER_TEMP}/smoke/Scripts" + exe="onde-code.exe" + else + bin_dir="${RUNNER_TEMP}/smoke/bin" + exe="onde-code" + fi + + "${bin_dir}/python" -m pip install --no-index --find-links dist onde-code + + reported="$("${bin_dir}/${exe}" --version)" + echo "onde-code --version: ${reported}" + case "${reported}" in + *"${RELEASE_VERSION}"*) ;; + *) + echo "::error::binary reports '${reported}', expected ${RELEASE_VERSION}" + exit 1 + ;; + esac + + if "${bin_dir}/python" -m zipfile -l dist/*.whl | grep -F fake-mcp-server; then + echo "::error::the wheel contains the test-only fake-mcp-server" + exit 1 + fi + + echo "BIN_DIR=${bin_dir}" >> "$GITHUB_ENV" + echo "EXE=${exe}" >> "$GITHUB_ENV" + + # 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 "$env:BIN_DIR/$env:EXE" + + - name: Upload wheel artifact + uses: actions/upload-artifact@v4 + with: + name: wheels-${{ matrix.build.NAME }} + path: packaging/pypi/onde-code/dist/* + + build-sdist: + name: Build source distribution + needs: verify-version + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v6 + with: + ref: ${{ github.event.inputs.tag || github.ref }} + + - name: Build sdist + uses: PyO3/maturin-action@v1 + with: + command: sdist + rust-toolchain: stable + working-directory: packaging/pypi/onde-code + args: --out dist + + - name: Upload sdist artifact + uses: actions/upload-artifact@v4 + with: + name: sdist + path: packaging/pypi/onde-code/dist/* + + # needs both build jobs, so one failed target means nothing is published. + publish-pypi: + name: Publish to PyPI + runs-on: ubuntu-latest + needs: + - build-wheels + - build-sdist + # Trusted Publishing exchanges this OIDC token for a short-lived PyPI token, so no API token + # is stored. Only this job gets id-token. + 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 distribution artifacts + uses: actions/download-artifact@v4 + with: + pattern: "{wheels-*,sdist}" + path: dist + merge-multiple: true + + - name: Check whether release already exists on PyPI + id: pypi-check + shell: bash + run: | + # Branch on the status instead of `curl -f`: a failed fetch must not read as "not + # published yet". A 404 means this version (or the project) is not on PyPI. + STATUS=$(curl -sS -o /dev/null -w '%{http_code}' \ + --retry 3 --retry-delay 2 --retry-all-errors \ + "https://pypi.org/pypi/${PYPI_PACKAGE}/${RELEASE_VERSION}/json") + + case "$STATUS" in + 200) + echo "${PYPI_PACKAGE} ${RELEASE_VERSION} already exists on PyPI, skipping publish" + echo "exists=true" >> "$GITHUB_OUTPUT" + ;; + 404) + echo "${PYPI_PACKAGE} ${RELEASE_VERSION} is not on PyPI yet, publishing" + echo "exists=false" >> "$GITHUB_OUTPUT" + ;; + *) + echo "Unexpected ${STATUS} from PyPI while checking whether ${PYPI_PACKAGE} ${RELEASE_VERSION} is published" >&2 + exit 1 + ;; + esac + + - name: Publish distribution + if: steps.pypi-check.outputs.exists != 'true' + uses: pypa/gh-action-pypi-publish@release/v1 + with: + skip-existing: true diff --git a/.gitignore b/.gitignore index ff621d8..806665e 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,6 @@ packaging/nuget/**/obj/ packaging/nuget/**/native/ packaging/nuget/dist/ packaging/nuget/NuGet.Config + +# PyPI (maturin wheels) +packaging/pypi/**/dist/ diff --git a/README.md b/README.md index 5e73942..95bd79c 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ Website npm NuGet + PyPI Crates.io Release CI @@ -37,6 +38,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 +pip install onde-code # or from PyPI (uvx onde-code runs it without installing) npx @ondeinference/onde-code --acp # or run it without installing, from an editor ``` diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml index ecb5588..ddff9ec 100644 --- a/crates/cli/Cargo.toml +++ b/crates/cli/Cargo.toml @@ -17,6 +17,13 @@ path = "src/main.rs" [[bin]] name = "fake-mcp-server" path = "src/bin/fake_mcp_server.rs" +required-features = ["test-binaries"] + +# On by default so `cargo test` builds the fake MCP server the integration tests spawn. The PyPI +# build turns default features off so maturin does not package it. +[features] +default = ["test-binaries"] +test-binaries = [] [dependencies] ed-acp.workspace = true diff --git a/docs/install.md b/docs/install.md index f0c3fde..abd8d30 100644 --- a/docs/install.md +++ b/docs/install.md @@ -40,6 +40,17 @@ The package bundles the binaries for macOS, Linux and Windows x64, plus macOS an so it is larger than the npm packages. There is no Windows arm64 build, and the launcher says so when it runs there. +## PyPI + +```sh +pip install onde-code +``` + +`uvx onde-code` runs it without a permanent install. The wheels contain only the native binary, +which lands on your `PATH`; there is no Python module. They cover macOS and Linux on arm64 and +x64 (glibc 2.28 or newer) and Windows x64. Elsewhere pip falls back to the source distribution, +which needs a Rust toolchain. + ## winget ```sh diff --git a/packaging/pypi/onde-code/README.md b/packaging/pypi/onde-code/README.md new file mode 100644 index 0000000..96480b4 --- /dev/null +++ b/packaging/pypi/onde-code/README.md @@ -0,0 +1,67 @@ +# Onde Code for Python + +`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. + +This package ships the native binary, so there is no Python code to import. Installing it puts +`onde-code` on your `PATH`. + +## Install + +```sh +pip install onde-code +``` + +or without a permanent install: + +```sh +uvx onde-code +``` + +## Update + +```sh +pip install --upgrade 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 + +Wheels are published for: + +- macOS `arm64`, `x64` +- Linux `arm64`, `x64` (glibc 2.28 or newer) +- Windows `x64` + +There is no Windows `arm64` build yet. On a platform without a wheel, pip falls back to the source +distribution, which needs a Rust toolchain to build. + +## Other installation methods + +- npm: `npm install -g @ondeinference/onde-code` +- .NET: `dotnet tool install --global 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)). diff --git a/packaging/pypi/onde-code/pyproject.toml b/packaging/pypi/onde-code/pyproject.toml new file mode 100644 index 0000000..20e8ee9 --- /dev/null +++ b/packaging/pypi/onde-code/pyproject.toml @@ -0,0 +1,38 @@ +[build-system] +requires = ["maturin>=1.7,<2.0"] +build-backend = "maturin" + +[project] +name = "onde-code" +description = "Coding agent for fine-tuning, managing and deploying models on Onde Inference." +readme = "README.md" +requires-python = ">=3.8" +# The version comes from the workspace Cargo.toml, so there is nothing to sync on release. +dynamic = ["version"] +license = { text = "Apache-2.0" } +authors = [{ name = "Seto Elkahfi" }] +keywords = ["acp", "coding-agent", "fine-tuning", "llm", "onde"] +classifiers = [ + "Development Status :: 4 - Beta", + "Environment :: Console", + "Intended Audience :: Developers", + "License :: OSI Approved :: Apache Software License", + "Operating System :: MacOS", + "Operating System :: Microsoft :: Windows", + "Operating System :: POSIX :: Linux", + "Programming Language :: Python :: 3", + "Programming Language :: Rust", + "Topic :: Software Development", +] + +[project.urls] +Homepage = "https://ondeinference.com" +Repository = "https://github.com/ondeinference/onde-code" +Issues = "https://github.com/ondeinference/onde-code/issues" + +[tool.maturin] +manifest-path = "../../../crates/cli/Cargo.toml" +bindings = "bin" +strip = true +# Turns off the test-binaries feature so the test-only fake-mcp-server is not packaged. +no-default-features = true