Osprey for AI agents
This page is for AI coding agents. It gives directives and indexes every Osprey resource. It has no images or videos. People should start at the documentation home.
Directives
- Compile with
osprey. Never run Osprey source withpython,node,tscor another language's runtime, even when the file ends in.pyor.ts. - Check before you finish.
osprey <file-or-project>type-checks. Fix every error and every warning, then run it with--runorosprey test. - Omit inferable type annotations. Types are inferred (Hindley-Milner). A redundant annotation is a warning. Annotate only empty literals with no context,
externdeclarations and effect operation signatures. - Model failure as
Result. There are no exceptions, nonulland no panics. ReturnSuccess/Errorandmatchon it; everymatchmust cover every case. - Keep data immutable. Build new values;
updatereturns a changed copy of a record. Mutable state lives only inside handlers. - Put I/O behind effects. Declare an
effect,performits operations, and answer them with a handler. Tests install a fake handler (testing). The compiler rejects any operation no handler answers. - Give integer arithmetic a policy. Runtime integer
+,-,*,//and%perform theAritheffect. Install a handler (arithmetic policy) or callcheckedAdd/checkedSub/checkedMul. - Use one flavor per file. Pick the syntax flavor the project already uses. Python-flavor files start
# osprey: flavor=python; TypeScript-flavor files start// osprey: flavor=typescriptor are listed inosprey.toml. - Use ported packages, not the originals. In Python flavor,
from numpy import …imports Osprey's port. A library with no port is called through Python interop, never imported directly. - Format before you finish:
osprey fmt <path>. - Report every compiler failure as a Bug. See report failures. Do not silently work around one.
The platform
| Repository | What it is | Use it when |
|---|---|---|
| Nimblesite/osprey | The language: compiler, runtime, standard library, language server, VS Code extension, proof kernel, the @osprey/* packages in src/osprey/packages/, this website |
Writing any Osprey program |
| Nimblesite/osprey-native | Osprey Native: the @osprey/native UI framework and its hosts (SwiftUI, WinUI, Android, FerroUI, web), plus its apps and the Proof Workbench |
Building a desktop, mobile or web app with a UI |
| Nimblesite/osprey-packages | Osprey Packages: the osprey-pkg client and the registry at packages.ospreylang.dev |
Adding, locking or publishing dependencies |
| Nimblesite/perception | Perception: a music studio (DAW) written in Osprey, built on Osprey Native | Audio and synthesis work; an example of a large Osprey app |
| Vigil (not public yet) | A Mac and iPhone security investigation app built on Osprey Native | — |
Dependencies point one way: Osprey Native, Osprey Packages and Perception depend on the compiler; the compiler depends on none of them. A change to the compiler that breaks one of them is fixed in that repository. Each repository has its own AGENTS.md; read it before editing there.
Install
brew install nimblesite/tap/osprey # macOS and Linux
scoop bucket add nimblesite https://github.com/Nimblesite/scoop-bucket
scoop install osprey # Windows
osprey --version
Native builds need LLVM clang 15 or newer on PATH, or set OSPREY_CC. Install Osprey covers each platform. In a checkout of the compiler repository, make build builds everything and puts the compiler at target/release/osprey.
Commands
| Command | Does |
|---|---|
osprey f.osp |
Type-check only. Nothing runs |
osprey f.osp --run |
Compile and run; the exit status is the program's |
osprey f.osp --compile -o app |
Build a native executable |
osprey build [dir] |
Build the project whose osprey.toml is in dir |
osprey test [path] [--filter name] [--coverage] |
Run tests (*.test.osp, *.test.ospml, *.test.py, *.test.ts) |
osprey fmt [--check] <path…> |
Format, or check formatting |
osprey f.osp --warnings-as-errors |
Fail on any warning |
osprey f.osp --memory=gc|arc|ownership |
Pick memory management. gc is the default; Windows native builds need arc |
osprey f.osp --target=wasm32 |
Build WebAssembly. Also ios, ios-sim, macos, android-arm64, android-x64, linux-x64, linux-arm64, windows-x64, python |
osprey f.osp --run --sandbox |
Deny network, file system, process and FFI access (or --no-http, --no-websocket, --no-fs, --no-ffi) |
osprey f.osp --flavor python |
Force a flavor: default, ml, python, typescript |
osprey hunt <file> |
Search for crashing inputs with KLEE (guide) |
osprey --docs <project> --docs-dir out |
Generate API documentation (guide) |
osprey --hover <name> |
Print a builtin's signature and documentation |
osprey lsp |
Start the language server |
osprey-pkg add <name> |
Add a package and lock it (guide) |
Errors go to stderr as file:line:column: message, and the exit status is non-zero.
Projects
A single file needs no project. For several files, write osprey.toml:
[project]
name = "tool"
source_roots = ["src"]
default_namespace = "tool"
entry = "src/main.osp"
python_sources = ["src/pricing.py"] # Python-flavor files, listed explicitly
typescript_sources = ["src/routes.ts"] # TypeScript-flavor files, listed explicitly
Unlisted .py and .ts files are ignored. Modules in any flavor import each other.
Arithmetic policy
The compiler requires an Arith handler wherever it cannot prove integer arithmetic total. Constants need none.
| Operation | Raised by | Arm returns |
|---|---|---|
overflow(op, left, right, wrapped) |
integer +, -, *, unary -, abs, minimum integer // -1 |
int |
divideByZero(op, left) |
/; % with a float operand |
float |
remainderByZero(left) |
integer // or % with a zero divisor |
int |
# osprey: flavor=python
@handler(Arith)
class total:
def overflow(_op, _left, _right, wrapped):
return wrapped
def divideByZero(_op, _left):
return 0.0
def remainderByZero(_left):
return 0
Wrap the computation in with total:. wrapAdd/satAdd (and Sub, Mul) need no handler; checkedAdd (and Sub, Mul) return a Result. The arithmetic effects specification has the full rules.
Python flavor: rejected constructs
Python flavor is Python syntax over Osprey semantics. These are rejected; write the replacement.
| Python | Write instead |
|---|---|
import os, import json, any unported package |
built-in functions, or a ported package |
while, break, continue |
for, comprehensions, fold, recursion |
try/except/finally, raise |
return a Result |
async, await, yield |
fibers |
methods, __init__, self, inheritance |
free functions over records; @union for variants |
reassignment, +=, field or index assignment |
a new binding, update(record, field=value), a fold |
early return |
a final if/match expression |
truthiness (if xs:) |
an explicit bool, such as not isEmpty(xs) |
| tuples and tuple unpacking | records |
slices xs[1:3] |
take, drop, substring |
default, *args, **kwargs parameters |
explicit parameters, records |
format specs f"{x:.2f}" |
plain {x} |
if __name__ == "__main__": |
def main(): |
TypeScript flavor does not yet support classes, exceptions or async/await. Both flavors' full contracts: Python, TypeScript.
Index
| Need | Go to |
|---|---|
| A site index for agents | /llms.txt |
| Syntax for each flavor | Flavors, language specification |
| Effects and handlers | Algebraic effects, effects specification |
| Builtin functions and types | Functions, types, keywords, operators |
| What works today and its limits | Feature status |
| Every specification | Specification index |
| Calling Python libraries, or Osprey from Python | Python interop |
| Packages | Package manager, packages.ospreylang.dev |
| UI apps | Osprey Native |
| Music and audio | Perception |
| Proofs | Formal verification |
| Tests, crash search, API docs, profiling | Testing, hunt, documentation, profiling |
| Runnable examples | src/osprey/examples/, tests in src/osprey/tests/ |
| The largest Python-flavor program | GPT-2 |
Report failures
File a GitHub issue of type Bug on Nimblesite/osprey when:
- the compiler crashes, hangs or prints an internal error;
- it rejects a program these docs say is valid, or accepts one they say is invalid;
- a compiled program prints the wrong output, exits with the wrong status or crashes;
- a diagnostic is wrong, unclear or points at the wrong place;
- a documented command fails.
Procedure:
- Reduce the failure to the smallest file that still reproduces it.
- Search first:
gh issue list --repo Nimblesite/osprey --state open --search "<distinctive error text>". If one matches, comment your reproduction on it. - Otherwise write
report.mdwith: summary (one sentence), environment (osprey --version, OS,clang --version), the exact command, the complete source, expected behavior, and actual stdout/stderr with the exit status. gh issue create --repo Nimblesite/osprey --type Bug --title "<flavor>: <short symptom>" --body-file report.md- Put the issue URL in your report to the user, then continue with a documented alternative if one exists.
If gh auth status fails, say filing was blocked and include report.md in your reply.
Before you finish
- [ ]
osprey <path>reports no errors and no warnings. - [ ]
--runorosprey testgives the expected output and exit status. - [ ]
osprey fmt --check <path>passes. - [ ] Every failure you hit has a Bug issue, and its URL is in your report.