Skip to content

A self-improving RLM agent for coding workflows and long-running autonomous tasks.

Rust

make updates follow your channel and fix installer uploads (#3243)

kte55ea44498b6
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index c28089df23..86bf9a0553 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -813,7 +813,7 @@ jobs:
else
render_installer beta
publish_pointer_pair beta.json beta release-out/beta.json beta
- aws s3 cp /tmp/install-beta.sh "s3://${R2_BUCKET}/prime-agent/install-beta.sh" \
+ aws s3 cp /tmp/install-beta.sh "s3://${R2_BUCKET}/install-beta.sh" \
--endpoint-url "$R2_ENDPOINT_URL" \
--content-type text/x-shellscript \
--cache-control no-cache
@@ -834,12 +834,12 @@ jobs:
else
render_installer stable
publish_pointer_pair latest.json stable release-out/latest.json stable
- aws s3 cp /tmp/install-stable.sh "s3://${R2_BUCKET}/prime-agent/install.sh" \
+ aws s3 cp /tmp/install-stable.sh "s3://${R2_BUCKET}/install.sh" \
--endpoint-url "$R2_ENDPOINT_URL" \
--content-type text/x-shellscript \
--cache-control no-cache
render_installer beta
- aws s3 cp /tmp/install-beta.sh "s3://${R2_BUCKET}/prime-agent/install-beta.sh" \
+ aws s3 cp /tmp/install-beta.sh "s3://${R2_BUCKET}/install-beta.sh" \
--endpoint-url "$R2_ENDPOINT_URL" \
--content-type text/x-shellscript \
--cache-control no-cache
diff --git a/crates/pa-cli/src/client_settings.rs b/crates/pa-cli/src/client_settings.rs
index 39d2a0ea7a..ea75bf2c41 100644
--- a/crates/pa-cli/src/client_settings.rs
+++ b/crates/pa-cli/src/client_settings.rs
@@ -279,5 +279,8 @@ mod tests {
std::fs::read_to_string(agent_dir.join("settings.json")).expect("settings file");
let value: serde_json::Value = serde_json::from_str(&content).expect("parse");
assert_eq!(value["updateChannel"], "stable");
+ // ...and the /nightly on path's.
+ settings.set_update_channel("nightly").expect("channel");
+ assert_eq!(settings.update_channel().as_deref(), Some("nightly"));
}
}
diff --git a/crates/pa-cli/src/client_update.rs b/crates/pa-cli/src/client_update.rs
index e7668140fb..8bdabe3517 100644
--- a/crates/pa-cli/src/client_update.rs
+++ b/crates/pa-cli/src/client_update.rs
@@ -1,7 +1,8 @@
//! The composition root's `/update` runner: the installer funnel with the
//! output captured — the TUI stays mounted while the install runs, so the
//! installer's own progress never writes to the live frame, and the
-//! failure tail becomes the error row's message. The same body
+//! failure tail becomes the error row's message. It follows the same
+//! update channel as `prime-agent update`. The same body
//! `prime-agent update` runs (pa-core's installer module), so the TUI and
//! the CLI cannot diverge.
@@ -14,7 +15,12 @@ pub struct ClientUpdate;
impl pa_tui::update_command::UpdateCommands for ClientUpdate {
fn run_update(&self) -> pa_tui::update_command::UpdateRunFuture {
Box::pin(async {
- match installer::run_installer(InstallerOutput::Capture).await {
+ match installer::run_installer(
+ Some(crate::installer_update::requested_installer_channel(None)),
+ InstallerOutput::Capture,
+ )
+ .await
+ {
Ok(installed) => Ok(installed
.version
.unwrap_or_else(|| "the latest build".to_string())),
diff --git a/crates/pa-cli/src/command_registry.rs b/crates/pa-cli/src/command_registry.rs
index 915493144d..ab5e8575f9 100644
--- a/crates/pa-cli/src/command_registry.rs
+++ b/crates/pa-cli/src/command_registry.rs
@@ -198,15 +198,15 @@ pub const COMMAND_SPECS: &[CommandSpec] = &[
),
CommandSpec::new(
&["update"],
- "update [--check]",
+ "update [--check] [--nightly|--stable]",
"Update to the latest Rust build (uninstalls the TypeScript version)",
)
.options(&[
- "--check Print the latest available build vs the running version, without installing",
- "--force Reinstall even if the current version is the latest on the channel (the managed-install flow)",
+ "--check Print the update channel's latest release vs the running version, without installing",
+ "--force Reinstall the latest build of the channel",
"--rollback Restore the previous compiled release (the managed-install flow)",
- "--nightly Switch updates to the nightly channel (the managed-install flow)",
- "--stable Return updates to the stable channel (the managed-install flow)",
+ "--nightly Switch updates to the nightly channel (the latest main build)",
+ "--stable Return updates to the stable channel",
"--archive <path> Install a local release payload (the managed-install flow)",
"--source <url> The https:// origin recorded as the release's install source (required with --archive)",
])
diff --git a/crates/pa-cli/src/installer_update.rs b/crates/pa-cli/src/installer_update.rs
index 7f37571f3d..13cb7c0f1b 100644
--- a/crates/pa-cli/src/installer_update.rs
+++ b/crates/pa-cli/src/installer_update.rs
@@ -2,22 +2,78 @@
//! the update fetches the installer from the OFFICIAL DOMAIN endpoint
//! (`https://app.primeintellect.ai/prime-agent/install.sh`, never a
//! GitHub raw or workflow URL) and runs it; the script uninstalls the
-//! TypeScript version, installs the latest Rust build, and never touches
-//! `~/.prime/agent` (the sessions and configuration). The TUI's `/update`
-//! runs the same core out-of-band (`client_update.rs`), so the two
-//! surfaces cannot diverge. This command exists only in the Rust binary:
-//! the TypeScript version does not have it — the move happens when the
-//! user runs the installer's curl|sh URL (the README's Install section) or
-//! `prime-agent update` (after the Rust install exists).
+//! TypeScript version, installs the latest Rust build of the update
+//! channel, and never touches `~/.prime/agent` (the sessions and
+//! configuration). The TUI's `/update` runs the same core out-of-band
+//! (`client_update.rs`), so the two surfaces cannot diverge.
+use pa_core::update::install::current_platform_alias;
use pa_core::update::installer::{self, InstallerOutput};
+use pa_core::update::release::{artifact_for_platform, LatestRelease};
+use pa_core::update::version::UpdateChannel;
/// One parsed `prime-agent update` invocation.
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct UpdateOptions {
- /// `--check`: print the latest available build vs the running
- /// binary's version, without installing.
+ /// `--check`: print the latest release of the update channel vs the
+ /// running binary's version, without installing.
pub check: bool,
+ /// `--nightly` / `--stable`: switch the update channel (persisted once
+ /// the update completes).
+ pub channel: Option<UpdateChannel>,
+}
+
+/// The saved `updateChannel` setting (`/nightly on|off`, `--nightly`,
+/// `--stable`).
+fn saved_channel() -> Option<UpdateChannel> {
+ let cwd = std::env::current_dir().ok()?;
+ let saved = pa_core::settings::SettingsManager::create(&cwd, crate::config::get_agent_dir())
+ .get_update_channel()?;
+ Some(match saved {
+ pa_core::settings::UpdateChannel::Stable => UpdateChannel::Stable,
+ pa_core::settings::UpdateChannel::Nightly => UpdateChannel::Nightly,
+ })
+}
+
+/// The installer's channel name for an update channel.
+fn installer_channel(channel: UpdateChannel) -> &'static str {
+ match channel {
+ UpdateChannel::Stable => "stable",
+ UpdateChannel::Nightly => "beta",
+ }
+}
+
+/// The update channel: the flag, else the saved `updateChannel` setting,
+/// else the install marker's channel, else the one the running version
+/// implies (a `-beta*` build is a nightly install).
+fn resolve_channel(
+ flag: Option<UpdateChannel>,
+ saved: Option<UpdateChannel>,
+ marker: Option<&str>,
+ running: &str,
+) -> UpdateChannel {
+ flag.or(saved)
+ .or(marker.map(|marker| match marker {
+ "stable" => UpdateChannel::Stable,
+ _ => UpdateChannel::Nightly,
+ }))
+ .unwrap_or_else(|| pa_core::update::version::resolve_update_channel(running, None))
+}
+
+/// The channel `update`, `update --check`, and `/update` follow.
+fn update_channel(flag: Option<UpdateChannel>) -> UpdateChannel {
+ resolve_channel(
+ flag,
+ saved_channel(),
+ installer::installed_channel(&installer::install_prefix()),
+ crate::config::version(),
+ )
+}
+
+/// The installer's channel name for [`update_channel`].
+#[must_use]
+pub fn requested_installer_channel(flag: Option<UpdateChannel>) -> &'static str {
+ installer_channel(update_channel(flag))
}
/// Run the update command: the funnel (the installer script owns the
@@ -31,7 +87,7 @@ pub fn run(options: &UpdateOptions) -> i32 {
return 1;
};
if options.check {
- return runtime.block_on(run_check());
+ return runtime.block_on(run_check(options.channel));
}
// The RESOLVED URL, not the const: a PRIME_AGENT_RUST_INSTALLER_URL
// pin (a test or a pinned install) changes where the funnel actually
@@ -41,7 +97,11 @@ pub fn run(options: &UpdateOptions) -> i32 {
"Updating to the latest Rust build — fetching the installer from {}:",
installer::installer_script_url()
);
- match runtime.block_on(installer::run_installer(InstallerOutput::Inherit)) {
+ let channel = requested_installer_channel(options.channel);
+ match runtime.block_on(installer::run_installer(
+ Some(channel),
+ InstallerOutput::Inherit,
+ )) {
Ok(installed) => {
match installed.version {
Some(version) => {
@@ -53,6 +113,9 @@ pub fn run(options: &UpdateOptions) -> i32 {
);
}
}
+ if let Some(channel) = options.channel {
+ save_channel(channel);
+ }
0
}
Err(failure) => {
@@ -62,11 +125,26 @@ pub fn run(options: &UpdateOptions) -> i32 {
}
}
-/// The `--check` report: the platform's build, the running binary's
-/// version, the latest continuous run, and whether they match. Nothing
-/// downloads.
-async fn run_check() -> i32 {
- let running = crate::config::version();
+/// Persist an explicit channel switch (`--nightly` / `--stable`) after a
+/// completed update.
+fn save_channel(channel: UpdateChannel) {
+ let Ok(cwd) = std::env::current_dir() else {
+ return;
+ };
+ let setting = match channel {
+ UpdateChannel::Stable => pa_core::settings::UpdateChannel::Stable,
+ UpdateChannel::Nightly => pa_core::settings::UpdateChannel::Nightly,
+ };
+ let mut settings =
+ pa_core::settings::SettingsManager::create(&cwd, crate::config::get_agent_dir());
+ if settings.set_update_channel(setting).is_ok() {
+ println!("Updates now follow the {} channel.", channel.wire_name());
+ }
+}
+
+/// The `--check` report: the running version vs the update channel's
+/// published release (`latest.json` / `beta.json`). Nothing downloads.
+async fn run_check(flag: Option<UpdateChannel>) -> i32 {
let target = match installer::current_target() {
Ok(target) => target,
Err(error) => {
@@ -74,52 +152,158 @@ async fn run_check() -> i32 {
return 1;
}
};
+ let running = crate::config::version();
+ let channel = update_channel(flag);
+ let base = installer::download_base_url();
println!("Platform: {target}");
println!("Running: {running}");
- // The resolved source (the official endpoint unless the override
- // pins one): --check must verify the script the funnel will execute,
- // so its Source line can never disagree with the actual fetch.
+ println!("Channel: {}", channel.wire_name());
+ let latest = pa_core::update::release::latest_release(
+ running,
+ Some(channel),
+ &base,
+ std::time::Duration::from_secs(10),
+ )
+ .await;
+ let Ok(Some(latest)) = latest else {
+ eprintln!(
+ "Error: could not read the {} release manifest at {base}/{}",
+ channel.wire_name(),
+ channel.manifest_path()
+ );
+ return 1;
+ };
println!(
- "Source: {} (the endpoint `prime-agent update` fetches the installer from)",
- installer::installer_script_url()
+ "Latest: {} ({base}/{})",
+ latest.version,
+ channel.manifest_path()
);
- match installer::latest_continuous_run().await {
- Ok(latest) => {
- println!(
- "Latest: continuous run {} (commit {})",
- latest.id, latest.commit
- );
- let up_to_date =
- installer::running_commit(running).is_some_and(|commit| commit == latest.commit);
- println!("{}", check_verdict(up_to_date));
- 0
- }
- Err(error) => {
- eprintln!("Error: could not resolve the latest continuous run: {error:#}");
- 1
- }
- }
+ println!("{}", check_verdict(&latest, running, channel, flag));
+ 0
}
-/// The `--check` verdict line.
-fn check_verdict(up_to_date: bool) -> &'static str {
- if up_to_date {
- "Up to date."
- } else {
- "An update is available — run `prime-agent update` to install it."
+/// The `--check` verdict line: the channel's update policy decides (a
+/// channel switch accepts a same-base prerelease), an update needs a
+/// build for this platform, and the suggested command repeats the channel
+/// flag the check was given.
+fn check_verdict(
+ latest: &LatestRelease,
+ running: &str,
+ channel: UpdateChannel,
+ flag: Option<UpdateChannel>,
+) -> String {
+ if !pa_core::update::version::is_release_update_candidate(
+ &latest.version,
+ running,
+ Some(channel),
+ ) {
+ return "Up to date.".to_string();
}
+ if artifact_for_platform(latest).is_err() {
+ return format!(
+ "{} is the latest {} release, but no build of it is published for {}.",
+ latest.version,
+ channel.wire_name(),
+ current_platform_alias()
+ );
+ }
+ let command = match flag {
+ Some(UpdateChannel::Nightly) => "prime-agent update --nightly",
+ Some(UpdateChannel::Stable) => "prime-agent update --stable",
+ None => "prime-agent update",
+ };
+ format!("An update is available — run `{command}` to install it.")
}
#[cfg(test)]
mod tests {
use super::*;
+ use pa_core::update::release::ReleaseArtifact;
+
+ /// A release with a build for this platform.
+ fn release(version: &str) -> LatestRelease {
+ let platform = current_platform_alias();
+ LatestRelease {
+ version: version.to_string(),
+ artifacts: vec![ReleaseArtifact {
+ platform: platform.to_string(),
+ file: format!("prime-agent-{version}-{platform}.tar.gz"),
+ sha256: "0".repeat(64),
+ }],
+ }
+ }
+
#[test]
- fn the_check_verdict_names_the_install_command() {
- assert_eq!(check_verdict(true), "Up to date.");
+ fn the_check_verdict_follows_the_channel_policy() {
+ assert_eq!(
+ check_verdict(&release("1.2.3"), "1.2.3", UpdateChannel::Stable, None),
+ "Up to date."
+ );
assert_eq!(
- check_verdict(false),
+ check_verdict(&release("1.2.4"), "1.2.3", UpdateChannel::Stable, None),
"An update is available — run `prime-agent update` to install it."
);
+ // A switch onto nightly accepts the same-base prerelease the
+ // installer would install.
+ assert_eq!(
+ check_verdict(
+ &release("1.2.3-beta.5"),
+ "1.2.3",
+ UpdateChannel::Nightly,
+ Some(UpdateChannel::Nightly)
+ ),
+ "An update is available — run `prime-agent update --nightly` to install it."
+ );
+ assert_eq!(
+ check_verdict(
+ &release("1.2.2-beta.5"),
+ "1.2.3",
+ UpdateChannel::Nightly,
+ None
+ ),
+ "Up to date."
+ );
+ }
+
+ #[test]
+ fn the_check_verdict_needs_a_build_for_this_platform() {
+ let unbuilt = LatestRelease {
+ version: "1.2.4".to_string(),
+ artifacts: Vec::new(),
+ };
+ assert_eq!(
+ check_verdict(&unbuilt, "1.2.3", UpdateChannel::Stable, None),
+ format!(
+ "1.2.4 is the latest stable release, but no build of it is published for {}.",
+ current_platform_alias()
+ )
+ );
+ }
+
+ #[test]
+ fn the_channel_resolves_flag_then_saved_then_marker_then_version() {
+ use UpdateChannel::{Nightly, Stable};
+ assert_eq!(
+ resolve_channel(Some(Stable), Some(Nightly), Some("beta"), "1.2.3-beta.1"),
+ Stable
+ );
+ assert_eq!(
+ resolve_channel(None, Some(Nightly), Some("stable"), "1.2.3"),
+ Nightly
+ );
+ assert_eq!(
+ resolve_channel(None, None, Some("stable"), "1.2.3-beta.1"),
+ Stable
+ );
+ assert_eq!(resolve_channel(None, None, Some("beta"), "1.2.3"), Nightly);
+ assert_eq!(resolve_channel(None, None, None, "1.2.3-beta.1"), Nightly);
+ assert_eq!(resolve_channel(None, None, None, "1.2.3"), Stable);
+ }
+
+ #[test]
+ fn the_nightly_channel_runs_the_installer_on_beta() {
+ assert_eq!(installer_channel(UpdateChannel::Nightly), "beta");
+ assert_eq!(installer_channel(UpdateChannel::Stable), "stable");
}
}
diff --git a/crates/pa-cli/src/public_command.rs b/crates/pa-cli/src/public_command.rs
index 2bcd99b11e..1148a1ce7e 100644
--- a/crates/pa-cli/src/public_command.rs
+++ b/crates/pa-cli/src/public_command.rs
@@ -617,37 +617,36 @@ fn is_self_update_source(source: &str) -> bool {
source == "self" || source == "pi" || source == APP_NAME
}
-fn run_update(args: &[String]) -> PublicCommandResult {
- // The migration path's own surface: the bare command is the
- // installer takeover (the funnel), and `--check` reports the latest
- // available build vs the running one without installing. The
- // TS-parity staged-flow flags below keep their surface exactly as
- // before (the managed releases/ layout world the battery's wire
- // suites pin); an installer-based install reports it is not owned by
- // the installer there, while the bare command works everywhere the
- // installer does.
- if args.is_empty() {
- let options = crate::installer_update::UpdateOptions { check: false };
- return handled_with_exit(crate::installer_update::run(&options));
+/// A `--check` invocation: `--check` (or `--version`) with at most one
+/// `--nightly` / `--stable`. `None` when the arguments are not a check.
+fn check_invocation(args: &[String]) -> Option<crate::installer_update::UpdateOptions> {
+ use pa_core::update::version::UpdateChannel;
+ let mut check = false;
+ let mut channel = None;
+ for arg in args {
+ match arg.as_str() {
+ "--check" | "--version" => check = true,
+ "--nightly" if channel.is_none() => channel = Some(UpdateChannel::Nightly),
+ "--stable" if channel.is_none() => channel = Some(UpdateChannel::Stable),
+ _ => return None,
+ }
}
- // `--check` alone (alias `--version`) reports without installing;
- // mixed with anything else the staged parse below rejects it.
- if args
- .iter()
- .all(|arg| matches!(arg.as_str(), "--check" | "--version"))
- {
- let options = crate::installer_update::UpdateOptions { check: true };
+ check.then_some(crate::installer_update::UpdateOptions {
+ check: true,
+ channel,
+ })
+}
+
+fn run_update(args: &[String]) -> PublicCommandResult {
+ // `--check` (alias `--version`) reports without installing, optionally
+ // for one channel flag; mixed with anything else the parse below
+ // rejects it.
+ if let Some(options) = check_invocation(args) {
return handled_with_exit(crate::installer_update::run(&options));
}
let Some(options) = parse_update_options(args) else {
return handled_failed();
};
- // TS package-manager-cli's update case: the persisted `updateChannel`
- // setting (`/nightly off`) is the default the update follows
- // (`options.channel ?? persistedChannel`), an explicit nightly switch
- // warns and confirms, and a completed run persists the explicit
- // switch (`commitChannel`) — one shared body with the `package update`
- // self target (`crate::self_update`).
let persisted_wire = std::env::current_dir()
.ok()
.and_then(|cwd| {
@@ -664,6 +663,17 @@ fn run_update(args: &[String]) -> PublicCommandResult {
) {
return handled_with_exit(abort_code);
}
+ // The installer funnel serves the bare update and the channel flags:
+ // the channel is the flag, else the saved `updateChannel` setting
+ // (`/nightly on|off`), else the installed one. `--rollback` and
+ // `--archive` stay on the managed-install flow.
+ if !options.rollback && options.archive.is_none() {
+ let update = crate::installer_update::UpdateOptions {
+ check: false,
+ channel: options.channel,
+ };
+ return handled_with_exit(crate::installer_update::run(&update));
+ }
handled_with_exit(crate::self_update::run(&options, persisted_wire.as_deref()))
}
@@ -927,6 +937,29 @@ mod update_options_tests {
assert!(parse(&["--force"]).is_some());
}
+ #[test]
+ fn check_combines_with_one_channel_flag() {
+ use pa_core::update::version::UpdateChannel;
+ let channel = |args: &[&str]| {
+ let args: Vec<String> = args.iter().map(std::string::ToString::to_string).collect();
+ check_invocation(&args).map(|options| options.channel)
+ };
+ assert_eq!(channel(&["--check"]), Some(None));
+ assert_eq!(
+ channel(&["--nightly", "--version"]),
+ Some(Some(UpdateChannel::Nightly))
+ );
+ assert_eq!(
+ channel(&["--check", "--stable"]),
+ Some(Some(UpdateChannel::Stable))
+ );
+ assert_eq!(channel(&[]), None);
+ assert_eq!(channel(&["--nightly"]), None);
+ assert_eq!(channel(&["--check", "--nightly", "--stable"]), None);
+ assert_eq!(channel(&["--check", "--force"]), None);
+ assert_eq!(channel(&["--check", "--rollback"]), None);
+ }
+
#[test]
fn parses_the_ts_booleans() {
let invocation = parse(&["--force"]).unwrap();
diff --git a/crates/pa-core/src/update/installer.rs b/crates/pa-core/src/update/installer.rs
index 05b3135a8c..9f915e06d9 100644
--- a/crates/pa-core/src/update/installer.rs
+++ b/crates/pa-core/src/update/installer.rs
@@ -17,57 +17,34 @@ use anyhow::{anyhow, Context, Result};
use super::release::update_user_agent;
-/// `PRIME_AGENT_RUST_REPO`: the installer's own repo knob (the funnel reads
-/// the same environment, so the script and the report always agree).
-pub const ENV_REPO: &str = "PRIME_AGENT_RUST_REPO";
/// `PRIME_AGENT_RUST_PREFIX`: the installer's own prefix knob (the launcher
/// probe reads the same value the script installs under).
pub const ENV_PREFIX: &str = "PRIME_AGENT_RUST_PREFIX";
/// `PRIME_AGENT_RUST_INSTALLER_URL`: the installer script URL override —
/// tests serve their own script, a pinned install can point elsewhere.
pub const ENV_INSTALLER_URL: &str = "PRIME_AGENT_RUST_INSTALLER_URL";
-/// The installer's release-channel knob (the publish-rendered default the
-/// served script carries; the env override pins it — the funnel passes the
-/// INSTALLED channel so a beta install updates on beta).
+/// The installer's release-channel knob (`stable` | `beta`): the funnel
+/// passes the requested channel, else the installed one.
pub const ENV_RELEASE_CHANNEL: &str = "PRIME_AGENT_RELEASE_CHANNEL";
-/// `GITHUB_TOKEN`: the installer's own artifact-auth knob, sent on the
-/// run-list request when set (the run list is public; the token only lifts
-/// the anonymous rate limit).
-pub const ENV_GITHUB_TOKEN: &str = "GITHUB_TOKEN";
+/// The installer's download-base knob (the bucket holding the channel
+/// manifests and release archives).
+pub const ENV_DOWNLOAD_BASE_URL: &str = "PRIME_AGENT_DOWNLOAD_BASE_URL";
+/// `install-rust.sh`'s `DOWNLOAD_BASE_URL_DEFAULT`: where the channel
+/// manifests (`latest.json`, `beta.json`) are published.
+pub const DEFAULT_DOWNLOAD_BASE_URL: &str = "https://pub-728493de92a943e2a9b2d17b4719f318.r2.dev";
/// The official domain's install endpoint — the one source the funnel
/// fetches the installer from; never a GitHub raw or workflow URL (the
/// override env var stays for tests and pinned installs).
pub const OFFICIAL_INSTALLER_URL: &str = "https://app.primeintellect.ai/prime-agent/install.sh";
-/// The repo the run report resolves from (the run-list query's owner; the
-/// installer fetch itself never derives from it).
-pub const DEFAULT_REPO: &str = "PrimeIntellect-ai/prime-agent";
-/// The workflow whose artifacts the installer downloads (the same name
-/// the script's run-list query uses).
-pub const WORKFLOW: &str = "continuous";
-/// The branch the continuous runs resolve from (the run-list query's
-/// branch).
-pub const BRANCH: &str = "rust";
/// The small-file budget for the script download (the script is a few KB;
/// a hung fetch must not hang the update).
const SCRIPT_FETCH_TIMEOUT: Duration = Duration::from_secs(30);
-/// The run-list request budget (`--check`'s report is a quick read).
-const RUN_LIST_TIMEOUT: Duration = Duration::from_secs(10);
/// The launcher `--version` probe budget (the same bound the release
/// probe uses; a hung launcher must not hang the report).
const LAUNCHER_PROBE_TIMEOUT: Duration = Duration::from_secs(10);
-/// The repo the update installs from (`PRIME_AGENT_RUST_REPO`, the
-/// installer's default).
-#[must_use]
-pub fn repo() -> String {
- std::env::var(ENV_REPO)
- .ok()
- .filter(|value| !value.trim().is_empty())
- .unwrap_or_else(|| DEFAULT_REPO.to_string())
-}
-
/// The installer script URL: the official domain's install endpoint by
/// default (`PRIME_AGENT_RUST_INSTALLER_URL` overrides it — tests serve
/// their own script, a pinned install can point elsewhere).
@@ -81,6 +58,16 @@ pub fn installer_script_url() -> String {
OFFICIAL_INSTALLER_URL.to_string()
}
+/// The download base `--check` reads the channel manifest from: the
+/// installer's own knob, else its default.
+#[must_use]
+pub fn download_base_url() -> String {
+ std::env::var(ENV_DOWNLOAD_BASE_URL)
+ .ok()
+ .filter(|value| !value.trim().is_empty())
+ .unwrap_or_else(|| DEFAULT_DOWNLOAD_BASE_URL.to_string())
+}
+
/// The install prefix the launcher probe reads (`PRIME_AGENT_RUST_PREFIX`,
/// the installer's own `~/.local` default).
#[must_use]
@@ -137,78 +124,6 @@ pub fn running_commit(version: &str) -> Option<&str> {
hex.then_some(commit)
}
-/// One resolved continuous run (`--check`'s "latest available"): the run
-/// the installer would download from, and the exact commit it built.
-#[derive(Debug, Clone, PartialEq, Eq)]
-pub struct ContinuousRun {
- pub id: u64,
- pub commit: String,
-}
-
-/// The newest successful `continuous` run on the branch — the same query
-/// the installer's non-`gh` path sends (`--check` only reads it; nothing
-/// downloads). `GITHUB_TOKEN`, when set, is sent as the bearer (the same
-/// token the installer itself would use).
-///
-/// # Errors
-/// Returns an error when the request or the response read fails; a run
-/// list with no successful run is an error too — there is nothing to
-/// report against.
-pub async fn latest_continuous_run() -> Result<ContinuousRun> {
- let url = format!(
- "https://api.github.com/repos/{}/actions/workflows/{WORKFLOW}.yml/runs?branch={BRANCH}&status=success&per_page=1",
- repo()
- );
- let mut request = reqwest::Client::new()
- .get(&url)
- .header("User-Agent", update_user_agent(env!("CARGO_PKG_VERSION")))
- .header("accept", "application/vnd.github+json")
- .timeout(RUN_LIST_TIMEOUT);
- if let Ok(token) = std::env::var(ENV_GITHUB_TOKEN) {
- if !token.trim().is_empty() {
- request = request.bearer_auth(token);
- }
- }
- let response = request
- .send()
- .await
- .with_context(|| format!("request the {WORKFLOW} run list in {}", repo()))?;
- let status = response.status();
- let body = response
- .bytes()
- .await
- .with_context(|| "read the run list body")?;
- if !status.is_success() {
- anyhow::bail!("the {WORKFLOW} run list in {} answered {status}", repo());
- }
- parse_runs(&body).ok_or_else(|| {
- anyhow!(
- "no successful {WORKFLOW} run is listed for {BRANCH} in {}",
- repo()
- )
- })
-}
-
-/// Parse the run-list body's newest run (the fetch half of
-/// [`latest_continuous_run`] without the network).
-#[must_use]
-pub fn parse_runs(body: &[u8]) -> Option<ContinuousRun> {
- #[derive(serde::Deserialize)]
- struct RunRow {
- id: u64,
- head_sha: String,
- }
- #[derive(serde::Deserialize)]
- struct RunsDocument {
- #[serde(default)]
- workflow_runs: Vec<RunRow>,
- }
- let document: RunsDocument = serde_json::from_slice(body).ok()?;
- let run = document.workflow_runs.first()?;
- let commit = run.head_sha.trim().to_string();
- (!commit.is_empty()).then_some(ContinuousRun { id: run.id, commit })
-}
-
/// Where the installer's output goes while it runs.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum InstallerOutput {
@@ -235,15 +150,18 @@ pub struct UpdateFailure {
}
/// Run the takeover update with the environment's knobs (the script URL
-/// and the install prefix): the composition root's entry.
+/// and the install prefix): the composition root's entry. `channel` is the
+/// requested release channel (`stable` | `beta`); `None` keeps the
+/// installed one.
///
/// # Errors
/// Returns the failure message for every non-installing outcome (see
/// [`run_installer_from`]).
pub async fn run_installer(
+ channel: Option<&'static str>,
output: InstallerOutput,
) -> std::result::Result<Installed, UpdateFailure> {
- run_installer_from(&installer_script_url(), &install_prefix(), output).await
+ run_installer_from(&installer_script_url(), &install_prefix(), channel, output).await
}
/// Run the takeover update from one explicit script URL and install
@@ -263,6 +181,7 @@ pub async fn run_installer(
pub async fn run_installer_from(
url: &str,
prefix: &Path,
+ channel: Option<&'static str>,
output: InstallerOutput,
) -> std::result::Result<Installed, UpdateFailure> {
current_target().map_err(|error| UpdateFailure {
@@ -271,7 +190,7 @@ pub async fn run_installer_from(
let script = fetch_script(url).await.map_err(|error| UpdateFailure {
message: format!("could not download the installer from {url}: {error:#}"),
})?;
- execute_script(&script, prefix, output).await?;
+ execute_script(&script, prefix, channel, output).await?;
let version = launcher_version(prefix).await;
Ok(Installed { version })
}
@@ -352,17 +271,15 @@ async fn fetch_script(url: &str) -> Result<PathBuf> {
async fn execute_script(
script: &Path,
prefix: &Path,
+ channel: Option<&'static str>,
output: InstallerOutput,
) -> std::result::Result<(), UpdateFailure> {
let mut command = tokio::process::Command::new("/bin/sh");
command.arg(script).env(ENV_PREFIX, prefix);
- // THE CHANNEL-STICKINESS: an install made through install-beta.sh
- // (the beta render) records its channel in the install marker, and
- // the update must STAY on it — the fetched script's own default is
- // the stable render, so without the override a beta user's `update`
- // would silently switch channels. The marker's first line is
- // "channel <name>" (the installer writes it at publish).
- if let Some(channel) = installed_channel(prefix) {
+ // The requested channel wins; otherwise the update stays on the channel
+ // the install marker records (the fetched script's own default is the
+ // stable render, so a beta install would silently switch channels).
+ if let Some(channel) = channel.or_else(|| installed_channel(prefix)) {
command.env(ENV_RELEASE_CHANNEL, channel);
}
match output {
@@ -603,6 +520,7 @@ set -eu
mkdir -p "${PRIME_AGENT_RUST_PREFIX}/bin"
printf '#!/bin/sh\necho "9.9.9-continuous.0123456789abcdef"\n' > "${PRIME_AGENT_RUST_PREFIX}/bin/prime-agent"
chmod 0755 "${PRIME_AGENT_RUST_PREFIX}/bin/prime-agent"
+printf '%s' "${PRIME_AGENT_RELEASE_CHANNEL:-}" > "${PRIME_AGENT_RUST_PREFIX}/channel"
echo "installed: 9.9.9-continuous.0123456789abcdef"
"#;
@@ -693,31 +611,50 @@ echo "installed: 9.9.8-continuous.fedcba9876543210"
);
}
- #[test]
- fn the_run_list_parse_takes_the_newest_successful_run() {
- let run = parse_runs(
- br#"{"total_count": 3, "workflow_runs": [
- {"id": 42424242, "head_sha": "07f42eaa3a6159f942c6c24beb0352ce120a192c"}
- ]}"#,
+ /// The requested channel (an explicit flag or the saved setting) wins
+ /// over the install marker; without one the marker's channel rides.
+ #[tokio::test]
+ #[cfg(unix)]
+ async fn the_requested_channel_wins_over_the_install_marker() {
+ let (root, _preserve, prefix) = sandbox();
+ let share = prefix.join("share/prime-agent");
+ std::fs::create_dir_all(&share).unwrap();
+ std::fs::write(
+ share.join(".prime-agent-install"),
+ "install-rust.sh channel beta\nversion 0.10.0\n",
)
- .expect("the run parses");
- assert_eq!(run.id, 42_424_242);
- assert_eq!(run.commit, "07f42eaa3a6159f942c6c24beb0352ce120a192c");
- assert!(
- parse_runs(br#"{"workflow_runs": []}"#).is_none(),
- "an empty run list reports nothing"
+ .unwrap();
+ let url = serve(MOCK_INSTALLER);
+ run_installer_from(&url, &prefix, Some("stable"), InstallerOutput::Capture)
+ .await
+ .expect("the funnel installs");
+ assert_eq!(
+ std::fs::read_to_string(prefix.join("channel")).unwrap(),
+ "stable"
);
- assert!(parse_runs(b"not json").is_none());
+ let url = serve(MOCK_INSTALLER);
+ run_installer_from(&url, &prefix, None, InstallerOutput::Capture)
+ .await
+ .expect("the funnel installs");
+ assert_eq!(
+ std::fs::read_to_string(prefix.join("channel")).unwrap(),
+ "beta"
+ );
+ drop(root);
}
#[tokio::test]
#[cfg(unix)]
async fn the_funnel_runs_the_downloaded_installer_and_preserves_the_session_store() {
let (root, preserve, prefix) = sandbox();
- let installed =
- run_installer_from(&serve(MOCK_INSTALLER), &prefix, InstallerOutput::Capture)
- .await
- .expect("the funnel installs the mock build");
+ let installed = run_installer_from(
+ &serve(MOCK_INSTALLER),
+ &prefix,
+ None,
+ InstallerOutput::Capture,
+ )
+ .await
+ .expect("the funnel installs the mock build");
assert_eq!(
installed.version.as_deref(),
Some("9.9.9-continuous.0123456789abcdef"),
@@ -735,10 +672,14 @@ echo "installed: 9.9.8-continuous.fedcba9876543210"
#[cfg(unix)]
async fn the_probe_still_reads_a_pre_takeover_launchers_version() {
let (root, _preserve, prefix) = sandbox();
- let installed =
- run_installer_from(&serve(LEGACY_INSTALLER), &prefix, InstallerOutput::Capture)
- .await
- .expect("the funnel installs the legacy-named build");
+ let installed = run_installer_from(
+ &serve(LEGACY_INSTALLER),
+ &prefix,
+ None,
+ InstallerOutput::Capture,
+ )
+ .await
+ .expect("the funnel installs the legacy-named build");
assert_eq!(
installed.version.as_deref(),
Some("9.9.8-continuous.fedcba9876543210"),
@@ -763,6 +704,7 @@ echo "installed: 9.9.8-continuous.fedcba9876543210"
let failure = run_installer_from(
&serve("#!/bin/sh\necho 'install-rust.sh: the artifact download failed' >&2\nexit 3\n"),
&prefix,
+ None,
InstallerOutput::Capture,
)
.await
@@ -787,6 +729,7 @@ echo "installed: 9.9.8-continuous.fedcba9876543210"
let failure = run_installer_from(
"http://127.0.0.1:9/install-rust.sh",
&prefix,
+ None,
InstallerOutput::Capture,
)
.await
diff --git a/crates/pa-tui/src/session_ui/commands.rs b/crates/pa-tui/src/session_ui/commands.rs
index 102d1591ed..09366bac61 100644
--- a/crates/pa-tui/src/session_ui/commands.rs
+++ b/crates/pa-tui/src/session_ui/commands.rs
@@ -353,12 +353,9 @@ impl SessionUi {
self.handle_traces_command(resolved, view).await?;
}
// `/nightly [on|off|status]` (TS `interactive-mode.ts`
- // 5455-5484): status resolves the effective channel and
- // off/stable pins the settings channel — the settings surface
- // the TS product still shares. `on` (or bare) explains the
- // move instead of switching: the update installs the latest
- // continuous Rust build, so there is no nightly channel left
- // to switch to.
+ // 5455-5484): status resolves the effective channel; on (or
+ // bare) and off/stable save the `updateChannel` setting that
+ // `/update` and `prime-agent update` follow.
"nightly" => {
self.track_command_used("nightly");
let arg = resolved.args.trim().to_lowercase();
@@ -410,13 +407,16 @@ impl SessionUi {
self.error_row("Usage: /nightly [on|off|status]", view);
return Ok(());
}
- // The nightly channel moved: the update installs the
- // latest continuous Rust build (the TS release channels
- // this arm switched between belong to the TypeScript
- // product the migration uninstalls), so the arm explains
- // the move instead of parking an update plan.
+ let Some(settings) = &self.client_settings else {
+ self.note("/nightly is not available in this client yet", view);
+ return Ok(());
+ };
+ if let Err(error) = settings.set_update_channel("nightly") {
+ self.error_row(&format!("{error:#}"), view);
+ return Ok(());
+ }
self.note(
- "Nightly builds are now the continuous Rust build — run /update to install the latest.",
+ "Updates now follow the nightly channel. Run /update to install the latest nightly build.",
view,
);
}
diff --git a/crates/pa-tui/tests/nightly_command_headless.rs b/crates/pa-tui/tests/nightly_command_headless.rs
index ff264f991c..6998955ab8 100644
--- a/crates/pa-tui/tests/nightly_command_headless.rs
+++ b/crates/pa-tui/tests/nightly_command_headless.rs
@@ -415,25 +415,25 @@ fn nightly_status_and_usage_error_render_the_ts_wording() {
);
}
-/// `/nightly on` (or bare) explains the move: the update installs the
-/// latest continuous build, so there is no nightly channel to switch to
-/// (the 2026-09-27 operator directive — the channel no longer gates the
-/// update, and no update plan is parked).
+/// `/nightly on` (or bare) saves the nightly channel that `/update` and
+/// `prime-agent update` follow.
#[test]
-fn nightly_on_renders_the_migration_note() {
+fn nightly_on_saves_the_nightly_channel() {
let steps = vec![
HeadlessStep::Submit("/nightly on".to_string()),
HeadlessStep::WaitMs(200),
- HeadlessStep::Submit("/nightly".to_string()),
+ HeadlessStep::Submit("/nightly status".to_string()),
HeadlessStep::WaitMs(200),
];
let frames = run_plan(steps);
let all = frames.join("\n");
assert!(
- all.contains(
- "Nightly builds are now the continuous Rust build — run /update to install the latest."
- ),
- "the migration note rendered:\n{all}"
+ all.contains("Updates now follow the nightly channel."),
+ "the switch note rendered:\n{all}"
+ );
+ assert!(
+ all.contains("Updates follow the nightly channel (set in settings)."),
+ "the saved channel reads back:\n{all}"
);
}