Add Pixi-style project environments and SAT dependency solver

- Add orbit.toml project manifests, deterministic orbit.lock files, [tasks], and `orbit run`
- Add per-project .orbit/bin environments; `-g`/`--global` targets the global environment
- Replace greedy global resolution with a lazy CDCL SAT solver that explains conflicts
- Support channel::pkg dependency pins and comma-separated, comparison, and wildcard constraints
- Cache immutable sha256 manifests under ~/.orbit/cache/manifests
- Validate dependency keys and constraints in orbit.json
This commit is contained in:
nandi committed 2026-11-28 01:43:04 -08:00
1 parent 0919ce105c
commit 13aa7d7f77
9 files changed
+4563 -266

No files matched your search

+170 -22
View File
@@ -4,8 +4,22 @@
let usage : String =
#|orbit - packages as OCI artifacts
#|
#|usage:
#| orbit init create folders and config.toml
#|usage (project workflow, when orbit.toml is present):
#| orbit new [dir] create a project orbit.toml
#| orbit add [channel::]<name>[@constraint]...
#| solve, pin in orbit.toml, lock & sync
#| orbit install [--locked | --frozen] sync .orbit/ from orbit.toml / orbit.lock
#| orbit sync [--locked | --frozen] same as `orbit install` in a project
#| orbit lock [--update] resolve and write orbit.lock
#| orbit update [name...] upgrade locked packages within constraints
#| orbit remove <name>... remove from orbit.toml, re-lock & sync
#| orbit run [--locked | --frozen] <cmd|task> [args...]
#| run a command or [tasks] entry in .orbit
#| orbit list show locked project packages
#| orbit env print PATH for .orbit/bin + global bin
#|
#|usage (global & registry commands; add -g/--global inside a project):
#| orbit init [--project] create ~/.orbit (or --project for orbit.toml)
#| orbit login <host> [-u <user>] [-p <pass> | --password-stdin] [--plain-http]
#| log in to an OCI registry
#| orbit logout <host> remove stored registry credentials
@@ -13,19 +27,21 @@ let usage : String =
#| orbit channel add <name> <url> [--plain-http]
#| orbit publish <dir> [--channel <name>] [--no-latest]
#| push <dir>/orbit.json + <dir>/files/
#| orbit install [channel::]<name>[@constraint]...
#| install with dependencies
#| orbit remove <name>... [--force] remove, then drop unused dependencies
#| orbit upgrade [name...] upgrade within constraints
#| orbit rollback <name> switch to the previous build
#| orbit list installed packages
#| orbit install [-g] [channel::]<name>[@constraint]...
#| install globally with SAT dependency solving
#| orbit remove [-g] <name>... [--force] remove, then drop unused dependencies
#| orbit upgrade [-g] [name...] jointly upgrade within constraints
#| orbit rollback <name> switch to the previous global build
#| orbit list [-g] installed global packages
#| orbit info [channel::]<name> installed package details (local only)
#| orbit versions <name> published versions
#| orbit search [term] list repositories (needs catalog API)
#| orbit gc delete unused builds from the store
#| orbit env print the PATH line for your shell
#| orbit env [-g] print the PATH line for your shell
#|
#|constraints: 1.2.3 =1.2.3 1.2 ^1.2.0 ~1.2.0 >=1.2 *
#|flags: -g, --global --manifest-path <path> --locked --frozen
#|constraints: 1.2.3 =1.2.3 ==1.2.3 1.2.* ^1.2.0 ~1.2.0 >=1.2 <2.0 !=1.3.0 *
#| (comma-separated clauses are ANDed, e.g. ">=1.2.0, <2.0.0")
#|config: <orbit root>/config.toml
#|credentials: <orbit root>/auth.json (falls back to ~/.docker/config.json)
#|environment: ORBIT_ROOT (default ~/.orbit); ORBIT_REGISTRY and
@@ -62,6 +78,34 @@ fn need(pos : Array[String], n : Int32, what : String) -> Unit raise OrbitError
}
}
///|
async fn resolve_project_or_none(
force_global : Bool,
manifest_path : String?,
) -> String? raise OrbitError {
if force_global {
if manifest_path is Some(_) {
raise OrbitError("--global cannot be used with --manifest-path")
}
None
} else {
find_project_manifest(manifest_path)
}
}
///|
async fn require_project_manifest(
manifest_path : String?,
) -> String raise OrbitError {
match find_project_manifest(manifest_path) {
Some(mf) => mf
None =>
raise OrbitError(
"no orbit.toml found in current or parent directories (run `orbit new` to create one)",
)
}
}
///|
async fn dispatch(args : Array[String]) -> Unit raise OrbitError {
if args.length() == 0 {
@@ -74,10 +118,35 @@ async fn dispatch(args : Array[String]) -> Unit raise OrbitError {
let mut publish_to = MAIN_CHANNEL
let mut username : String? = None
let mut password : String? = None
let mut force_global = false
let mut manifest_path : String? = None
let mut i = 1
while i < args.length() {
if cmd == "run" && pos.length() > 0 {
// Forward all flags/args after the command/task name verbatim.
pos.push(args[i])
i = i + 1
continue
}
let a = args[i]
if a == "--channel" {
if a == "--" {
i = i + 1
while i < args.length() {
pos.push(args[i])
i = i + 1
}
break
} else if a == "-g" || a == "--global" {
force_global = true
} else if a == "--manifest-path" {
if i + 1 >= args.length() {
raise OrbitError("usage: --manifest-path <path>")
}
manifest_path = Some(args[i + 1])
i = i + 1
} else if has_prefix(a, "--manifest-path=") {
manifest_path = Some(drop_chars(a, 16))
} else if a == "--channel" {
if cmd != "publish" || i + 1 >= args.length() {
raise OrbitError("usage: orbit publish <dir> --channel <name>")
}
@@ -118,14 +187,23 @@ async fn dispatch(args : Array[String]) -> Unit raise OrbitError {
}
match cmd {
"help" | "-h" | "--help" => println(usage)
"init" => {
if pos.length() > 0 {
raise OrbitError(
"init takes no arguments; use `orbit channel add <name> <url>`",
)
"new" => {
if force_global {
raise OrbitError("--global cannot be used with `orbit new`")
}
cmd_init()
cmd_project_init(if pos.length() > 0 { Some(pos[0]) } else { None })
}
"init" =>
if flags.contains("--project") {
cmd_project_init(if pos.length() > 0 { Some(pos[0]) } else { None })
} else {
if pos.length() > 0 {
raise OrbitError(
"init takes no arguments; use `orbit channel add <name> <url>` or `orbit new <dir>`",
)
}
cmd_init()
}
"login" => {
need(
pos,
@@ -160,20 +238,90 @@ async fn dispatch(args : Array[String]) -> Unit raise OrbitError {
other => raise OrbitError("unknown channel command '\{other}'")
}
}
"env" => println("export PATH=\"\{orbit_root()}/bin:$PATH\"")
"lock" => {
if force_global {
raise OrbitError("--global cannot be used with `orbit lock`")
}
let mf = require_project_manifest(manifest_path)
cmd_project_lock(load_ctx(), mf, flags.contains("--update"))
}
"sync" => {
if force_global {
raise OrbitError("--global cannot be used with `orbit sync`")
}
let mf = require_project_manifest(manifest_path)
cmd_project_sync(
load_ctx(),
mf,
flags.contains("--locked"),
flags.contains("--frozen"),
)
}
"run" => {
if force_global {
raise OrbitError("--global cannot be used with `orbit run`")
}
let mf = require_project_manifest(manifest_path)
need(pos, 1, "run [--locked|--frozen] <command|task> [args...]")
cmd_project_run(
load_ctx(),
mf,
pos,
flags.contains("--locked"),
flags.contains("--frozen"),
)
}
"env" =>
match resolve_project_or_none(force_global, manifest_path) {
Some(mf) => cmd_project_env(load_ctx(), mf)
None => println("export PATH=\"\{orbit_root()}/bin:$PATH\"")
}
"publish" => {
need(pos, 1, "publish <dir>")
let ch = find_channel(load_ctx(), publish_to)
publish(ch, pos[0], !flags.contains("--no-latest"))
}
"install" | "add" => cmd_install(load_ctx(), pos)
"remove" | "rm" => cmd_remove(load_ctx(), pos, flags.contains("--force"))
"upgrade" | "up" => cmd_upgrade(load_ctx(), pos)
"install" =>
match resolve_project_or_none(force_global, manifest_path) {
Some(mf) =>
if pos.length() == 0 {
cmd_project_sync(
load_ctx(),
mf,
flags.contains("--locked"),
flags.contains("--frozen"),
)
} else {
raise OrbitError(
"in a project (found \{mf}), use `orbit add <pkg>...` to add dependencies or `orbit install -g <pkg>...` to install globally",
)
}
None => cmd_install(load_ctx(), pos)
}
"add" =>
match resolve_project_or_none(force_global, manifest_path) {
Some(mf) => cmd_project_add(load_ctx(), mf, pos)
None => cmd_install(load_ctx(), pos)
}
"remove" | "rm" =>
match resolve_project_or_none(force_global, manifest_path) {
Some(mf) => cmd_project_remove(load_ctx(), mf, pos)
None => cmd_remove(load_ctx(), pos, flags.contains("--force"))
}
"upgrade" | "up" | "update" =>
match resolve_project_or_none(force_global, manifest_path) {
Some(mf) => cmd_project_update(load_ctx(), mf, pos)
None => cmd_upgrade(load_ctx(), pos)
}
"rollback" => {
need(pos, 1, "rollback <name>")
cmd_rollback(load_ctx(), pos[0])
}
"list" | "ls" => cmd_list(load_ctx())
"list" | "ls" =>
match resolve_project_or_none(force_global, manifest_path) {
Some(mf) => cmd_project_list(load_ctx(), mf)
None => cmd_list(load_ctx())
}
"info" => {
need(pos, 1, "info [channel::]<name>")
cmd_info(load_ctx(), pos[0])