Skip to content

Build from source

You build PiSharp from source to work on it, to run its tests, or to use a feature that is on the main branch but in no release yet: to use one, you reference the projects from your app.

Tool Version Needed for
.NET SDK 10.0.401 exactly Everything. global.json pins it with "rollForward": "disable" to match the deterministic offline contract. Run ./tools/bootstrap-sdk.ps1 (Windows/PowerShell) or ./tools/bootstrap-sdk.sh (macOS/Linux) to install the exact pinned SDK locally under .dotnet/ without touching your system SDKs.
Git Any recent Cloning, and the test cases that run git.
Node.js 22.13 or later, with npm The Node bridge for Pi’s TypeScript extensions, the ExtensionParity suite, and the Node tools under tools/.
Node.js 22 or later The website.
PowerShell 7 tools/release/build-release-packages.ps1 and the other release scripts.

You need a network connection, or a NuGet cache that already holds the packages, for the third-party packages listed in Restore and lock files. The libraries and the CLI target net10.0.

Terminal window
git clone https://github.com/jkelly/PiSharp.git
cd PiSharp

main holds the latest work, including unreleased features. Each release has a tag, such as v1.5.0. Check out the tag to build exactly what shipped.

Folder Contents
src/ The libraries and the CLI (PiSharp.Cli). See Architecture.
tests/ The test suites, which are console programs. See Tests.
samples/ Runnable sample apps and two native extensions. See Samples.
benchmarks/ PiSharp.Durable.Benchmarks, ports of upstream’s durable benchmarks.
tools/ The Node bridge host scripts, the compatibility and integrity tools, and the release and packaging scripts.
compatibility/ The Pi baseline locks, sync worklists, the durable port map and the release record. See How the port tracks Pi.
fixtures/ Captured and authored test fixtures.
docs/ Design documents, decision records, plans and release notes.
schemas/ JSON schemas for extension manifests.
website/ This site.
third-party/ License files of the third-party code PiSharp ships.

At the root, PiSharp.slnx lists every library, the core, companion and release test suites, the samples other than the extension samples, and the benchmarks. Directory.Build.props holds the settings every project shares, and NuGet.Config clears every package feed.

Build one project and the projects it references:

Terminal window
dotnet build src/PiSharp.Cli/PiSharp.Cli.csproj -c Release -p:RestoreSources=https://api.nuget.org/v3/index.json -p:RestoreLockedMode=false

The CLI lands in src/PiSharp.Cli/bin/Release/net10.0/. Run it with dotnet:

Terminal window
dotnet src/PiSharp.Cli/bin/Release/net10.0/PiSharp.Cli.dll --help

To build everything in the solution, pass PiSharp.slnx instead of a project. The solution holds about 95 projects, so building one project is faster when that is all you need.

Every project gets these settings from Directory.Build.props:

Setting Value Effect
VersionPrefix 1.6.0 The version a build reports, unless you pass -p:VersionPrefix. A build of main reports it even when it holds unreleased features.
TargetFramework net10.0
Nullable, ImplicitUsings enable
TreatWarningsAsErrors true Any compiler warning fails the build.
Deterministic true
RestorePackagesWithLockFile true Restore reads and writes packages.lock.json.
NuGetAudit false Restore does not query vulnerability data.

The CLI has one build switch of its own. -p:EnablePromptTemplateYaml=false builds it without PiSharp.PromptTemplates.Yaml and YamlDotNet, and restores against packages.prompt-yaml-disabled.lock.json. It defaults to true.

The committed NuGet.Config clears every package source. A project with no third-party packages restores without any feed. A project that has them restores only when the packages are already in your NuGet cache, or when you name a feed, as the CI and release builds do:

Terminal window
dotnet build src/PiSharp.Codemode/PiSharp.Codemode.csproj -p:RestoreSources=https://api.nuget.org/v3/index.json -p:RestoreLockedMode=false

These projects use third-party packages:

Project Packages
PiSharp.Codemode Jint 4.16.3 (and Acornima, which Jint brings)
PiSharp.PromptTemplates.Yaml YamlDotNet 16.3.0
PiSharp.Tools.Skia SkiaSharp 4.152.1 and its native assets for Windows, macOS and Linux
PiSharp.Durable.Sqlite Microsoft.Data.Sqlite 10.0.12 and SQLitePCLRaw 2.1.12
PiSharp.CustomAgents.Scripting Microsoft.CodeAnalysis.CSharp 5.6.0

Each project commits a packages.lock.json. Some of them still record the sibling PiSharp projects at an older version, so the official builds restore with lock-file checking off (RestoreLockedMode=false). Lock-file checking is not on by default, but pass the switch anyway to match them.

Don’t commit lock-file changes a restore makes as a side effect: delete untracked lock files it creates and revert tracked ones it rewrites. When you add or change a package reference on purpose, commit the updated lock file with it.

dotnet run builds the CLI and starts it. Arguments after -- go to pisharp:

Terminal window
dotnet run --project src/PiSharp.Cli -p:RestoreSources=https://api.nuget.org/v3/index.json -- --help
dotnet run --project src/PiSharp.Cli -- -p "Summarize this repository"
dotnet run --project src/PiSharp.Cli -- durable

Once the packages are in your cache, you can leave out -p:RestoreSources. The CLI built this way includes everything on main, including CLI features that are in no release yet. See Command line.

dotnet run starts in Debug. Add -c Release for the build the packages use. The build copies CHANGELOG.md next to the executable, where What’s New and /changelog read it.

To run your build as pisharp, pack it the way a release does and install it from the output folder. The macOS CI job does exactly this.

Terminal window
pwsh ./tools/release/build-release-packages.ps1 -Version 1.6.0.1 -SourceCommit (git rev-parse HEAD)

The script packs every library and the CLI into artifacts/packages/, and checks each package. It expects 29 packages there when it ends, so empty the folder before you run it again. The version’s first three numbers must match the Pi baseline in compatibility/target.lock.json (1.6.0 today), and -SourceCommit must be a full 40-character commit id. See Releasing for what it checks.

Then install the tool from a folder outside the repository, because the repository’s NuGet.Config would hide nuget.org, where the tool’s dependencies come from:

Terminal window
cd ..
dotnet tool install PiSharp.Cli --tool-path ./pisharp-dev --add-source PiSharp/artifacts/packages --version 1.6.0.1
./pisharp-dev/pisharp --version

A --tool-path install keeps your build apart from a dotnet tool install -g PiSharp.Cli from NuGet.

Features that are in no release yet have no NuGet package. To use them, add project references from your app to the PiSharp projects in your clone. This also works for any released library, when you want main or a local change.

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<!-- The experimental APIs this app uses. -->
<NoWarn>$(NoWarn);PISHARP_DURABLE001;PISHARP_AGENTS001</NoWarn>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="../PiSharp/src/PiSharp.CustomAgents/PiSharp.CustomAgents.csproj" />
<ProjectReference Include="../PiSharp/src/PiSharp.Durable.Sqlite/PiSharp.Durable.Sqlite.csproj" />
</ItemGroup>
</Project>

Your app must target net10.0. Reference every PiSharp library you use from source, and don’t mix in PiSharp NuGet packages: the packages are built from a release and the projects from your clone, and the two can differ. Restore your app with -p:RestoreSources=https://api.nuget.org/v3/index.json if it can’t find a third-party package that a PiSharp project needs.

Experimental APIs carry [Experimental], and using one is a compiler error until you suppress its id:

Feature Projects Suppress
Durable agents (experimental) PiSharp.Durable, PiSharp.Durable.Sqlite, PiSharp.Durable.Tools PISHARP_DURABLE001
Custom agents (experimental) PiSharp.CustomAgents, PiSharp.CustomAgents.JavaScript, PiSharp.CustomAgents.Scripting PISHARP_AGENTS001 and PISHARP_DURABLE001
Media library (experimental) PiSharp.AI, namespace PiSharp.AI.Media PISHARP_MEDIA001
Telemetry (experimental) PiSharp.Telemetry, and the telemetry members of PiSharp.AI PISHARP_TELEMETRY001

The Pi 1.5.0 sync adds more ids for single types and members; the SDK page lists them all.

The durable, custom agents and telemetry projects mark the whole assembly, so every type in them needs the suppression. The media and tier attributes sit on single types and members. An app inside the PiSharp folder, like the samples, also inherits Directory.Build.props, so its warnings are errors and restore writes a lock file for it.

The samples reference the src/ projects, so they always build against the code beside them. Run them from the repository root.

Sample What it shows Run
Durable.Chat One prompt answered by a real provider through a durable session, on SQLite by default, with optional coding tools. dotnet run --project samples/Durable.Chat -- --provider anthropic --model <id> "<prompt>"
Durable.Examples Ports of upstream’s durable examples on scripted models. Name examples by number or file name, or run them all. dotnet run --project samples/Durable.Examples -- [--storage memory|jsonl|sqlite] [example ...]
CustomAgents.Examples (experimental) An orders workflow, a team, and web search, on scripted models unless you pass --provider and --model. dotnet run --project samples/CustomAgents.Examples -- [orders|team|web|all]
CustomAgents.Research (experimental) A research workflow that writes a report. See its README. dotnet run --project samples/CustomAgents.Research -c Release -- "<question>"
extensions/StatefulTodo A native extension with a todo tool whose state lives in the session. See below.
extensions/SessionCheckpoint A native extension with a /checkpoint command that switches sessions. See below.

Durable.Chat reads the provider’s API key from its environment variable, such as ANTHROPIC_API_KEY. The custom agents samples are covered in Custom agents samples, and the durable ones in Pi Durable.

The extension samples are not in PiSharp.slnx. Build one, then load it for one run with -e:

Terminal window
dotnet build samples/extensions/StatefulTodo/StatefulTodo.csproj -c Release
pisharp -e samples/extensions/StatefulTodo/bin/Release/net10.0/pisharp-extension.json

Or copy the bin/Release/net10.0 folder into ~/.pi/agent/extensions/<name>/, where it loads like any extension. See Build an extension.

The durable benchmarks run the same way: dotnet run -c Release --project benchmarks/PiSharp.Durable.Benchmarks -- storage. docs/durable-benchmarks.md lists the benchmarks and their arguments.