From c9c17cc16ffdf3fe07a0b1f837af184f29e3c3da Mon Sep 17 00:00:00 2001 From: Phoebus Date: Fri, 2 Oct 2026 05:19:09 -0700 Subject: [PATCH] fix(sys): parse natural install package lanes --- docs/CHANGELOG.md | 8 + docs/HANDOFF.md | 14 ++ docs/STATUS.md | 14 ++ docs/SYS.md | 7 + .../crates/phoebus-installer/src/bin/sys.rs | 159 +++++++++++++++--- .../crates/phoebus-installer/tests/sys_cli.rs | 22 +++ 6 files changed, 198 insertions(+), 26 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 9ade88d..e3e537b 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -5,6 +5,14 @@ this file is the curated, human-readable summary. ## Unreleased — Fast defaults with user-controlled source builds +- **Natural install lane parsing (2026-10-02).** `sys install chatgpt desktop + through nix` now separates the Nix lane from the descriptive application + name. If an AI plan fails, `sys` searches that lane and suggests a verified + exact package identifier, without installing it automatically. Model failures + no longer claim that no model is connected. The running QEMU VM's Nix + catalogue confirmed `chatgpt` as a desktop package; the fallback suggested + `sys install chatgpt --legacy --nix`. + - **Phoebus Updates entry point (2026-10-02).** The launcher and Super+U now open the Assistant's update view directly, including without an AI model. Its Apply action opens the existing interactive `sys` update flow in Kitty, diff --git a/docs/HANDOFF.md b/docs/HANDOFF.md index 5e8833e..1a39e61 100644 --- a/docs/HANDOFF.md +++ b/docs/HANDOFF.md @@ -3,6 +3,20 @@ Rolling note between work sessions. **Update this file before you finish**, then commit it. It should be short and current; use `git log` for detail. +- **`sys` natural install error (2026-10-02):** The phrase `sys install chatgpt + desktop through nix` used to pass the entire phrase as a package name and + print invalid legacy examples. The parser now extracts the requested lane; + failed model plans search the lane and suggest an exact catalogue match. + The running QEMU VM returned `chatgpt` from Nix and the revised binary + suggested `sys install chatgpt --legacy --nix` without installing anything. + Host regression and full check passed. OpenCode returned invalid proposal + JSON on the first run and a valid `chatgpt`/Nix plan on a later run; its + prose about GUI availability was inconsistent with the catalogue metadata. + The user's installed root `sys` requires authentication to replace. The + updated static binary is installed as `~/.local/bin/sys`, and the interactive + zsh PATH now prioritizes that directory. This lets the user's `sys` command + use the fix; `sudo sys` may still invoke the older root-owned binary. + - **Phoebus Updates entry point (2026-10-02):** The Updates view now has a dedicated launcher and Super+U shortcut, works without a connected model, and opens the existing interactive `sys` apply flow in Kitty so review and diff --git a/docs/STATUS.md b/docs/STATUS.md index cec5eb6..682cd32 100644 --- a/docs/STATUS.md +++ b/docs/STATUS.md @@ -48,6 +48,20 @@ disposable VM; `serial-driver.py recovery` now automates the same check. ## Matrix +Natural install lane parsing (2026-10-02): `sys` recognizes trailing +`through/via/using/with ` as a backend constraint. A model failure for a +descriptive package name searches the chosen lane and offers an exact +catalogue-backed command when possible; it never executes that command as a +fallback. Unit and CLI regression tests plus the full host check pass. In the +running disposable VM, the new static binary parsed `chatgpt desktop through +nix`, the connected OpenCode model returned invalid JSON, and the Nix +catalogue search found `chatgpt` with a desktop description. The revised +fallback suggested `sys install chatgpt --legacy --nix` without installing. +A second VM run produced a valid Nix install plan for candidate `chatgpt` but +did not install because the unprivileged command requires root. The updated +static binary is installed at `~/.local/bin/sys` and is first on the +interactive zsh PATH; the root-owned `/usr/local/bin/sys` remains older. + Phoebus Updates entry point (2026-10-02): the installed and live desktops provide a dedicated launcher and Super+U shortcut that open the Assistant's Updates view without needing a connected model. Review & Apply launches diff --git a/docs/SYS.md b/docs/SYS.md index a462513..ccc64c8 100644 --- a/docs/SYS.md +++ b/docs/SYS.md @@ -51,11 +51,18 @@ sys ask "install firefox" # identical AI workflow sys install firefox --flatpak # AI workflow constrained to Flatpak sys install firefox --portage # AI workflow constrained to Portage sys install nodejs --nix # AI workflow constrained to Nix +sys install chatgpt desktop through nix # AI workflow constrained to Nix; descriptive name sys install thunderbird --snap # AI workflow constrained to Snap sys install MyTool --appimage # AI workflow constrained to AppImage sys install app-misc/my-thing --ebuild # AI workflow constrained to custom ebuild ``` +An install phrase ending in `through`, `via`, `using`, or `with` plus a package +lane is parsed as a lane choice, not as part of the application name. If the +model cannot produce a valid plan for a descriptive name, `sys` searches the +requested lane and suggests an exact package identifier when the catalogue +confirms one. It does not install a fallback without review. + Removal is also AI-first by default. The deterministic ownership discovery and policy validation always run underneath; the connected model confirms the exact discovered copy. An ambiguous multi-lane install still requires an explicit diff --git a/installer-rs/crates/phoebus-installer/src/bin/sys.rs b/installer-rs/crates/phoebus-installer/src/bin/sys.rs index 8bd5aec..4af8ec6 100644 --- a/installer-rs/crates/phoebus-installer/src/bin/sys.rs +++ b/installer-rs/crates/phoebus-installer/src/bin/sys.rs @@ -19,7 +19,7 @@ use phoebus_core::transaction::{TransactionOutcome, TransactionRecord}; use phoebus_core::{AiBackend, InstallConfig, Redactor}; use phoebus_executor::install::{AiInstall, ExecutorSession, InstallRequest}; use phoebus_executor::{ - actions, authorize, chooser, probe, transaction, AutoConfirm, Confirmation, + actions, authorize, chooser, probe, query, transaction, AutoConfirm, Confirmation, DestructiveAuthorization, Exec, Logger, RealRunner, Result, }; use phoebus_installer::approval; @@ -371,7 +371,8 @@ fn run() -> std::result::Result<(), Box> { // 4. Explicit legacy mode (--legacy) if cli.legacy { - if let Some(application) = parse_install_text(&full_phrase) { + if let Some((application, source)) = parse_install_text(&full_phrase) { + let backend = combine_install_backend(backend, source)?; if let Some(b) = backend { let mut request = InstallRequest::new(&application); request.backend = Some(b); @@ -498,7 +499,8 @@ fn run() -> std::result::Result<(), Box> { } // Natural `sys install ` / `sys please install ` - if let Some(application) = parse_install_text(&full_phrase) { + if let Some((application, source)) = parse_install_text(&full_phrase) { + let backend = combine_install_backend(backend, source)?; return run_install(&cli, &exec, &plans, &application, backend); } @@ -704,8 +706,9 @@ fn backend_flag_name(backend: Backend) -> &'static str { } } -/// Parse `install ` / `add ` / `please install `. -fn parse_install_text(text: &str) -> Option { +/// Parse an install request, including a trailing `via/using/with/through `. +/// The lane is syntax, never part of the application name sent to the model. +fn parse_install_text(text: &str) -> Option<(String, Option)> { let mut trimmed = text.trim(); for prefix in ["please ", "Please "] { if let Some(rest) = trimmed.strip_prefix(prefix) { @@ -718,18 +721,68 @@ fn parse_install_text(text: &str) -> Option { if lower.starts_with(prefix) { // Strip surrounding quotes so a multi-word app name ("visual // studio code") is treated as one operand. - let app = trimmed[prefix.len()..] - .trim() - .trim_matches(['"', '\'']) - .trim(); + let operand = trimmed[prefix.len()..].trim(); + let lower_operand = operand.to_ascii_lowercase(); + let mut source = None; + let mut app = operand; + for (suffix, lane) in [ + (" through nix", Backend::Nix), + (" via nix", Backend::Nix), + (" using nix", Backend::Nix), + (" with nix", Backend::Nix), + (" through flatpak", Backend::Flatpak), + (" via flatpak", Backend::Flatpak), + (" using flatpak", Backend::Flatpak), + (" with flatpak", Backend::Flatpak), + (" through portage", Backend::PortageSource), + (" via portage", Backend::PortageSource), + (" using portage", Backend::PortageSource), + (" with portage", Backend::PortageSource), + (" through snap", Backend::Snap), + (" via snap", Backend::Snap), + (" using snap", Backend::Snap), + (" with snap", Backend::Snap), + (" through appimage", Backend::AppImage), + (" via appimage", Backend::AppImage), + (" using appimage", Backend::AppImage), + (" with appimage", Backend::AppImage), + (" through ebuild", Backend::CustomEbuild), + (" via ebuild", Backend::CustomEbuild), + (" using ebuild", Backend::CustomEbuild), + (" with ebuild", Backend::CustomEbuild), + ] { + if lower_operand.ends_with(suffix) { + app = operand[..operand.len() - suffix.len()].trim(); + source = Some(lane); + break; + } + } + let app = app.trim_matches(['"', '\'']).trim(); if !app.is_empty() && !app.starts_with('-') && !app.chars().any(char::is_control) { - return Some(app.to_string()); + return Some((app.to_string(), source)); } } } None } +fn combine_install_backend( + flag: Option, + phrase: Option, +) -> std::result::Result, Box> { + if let (Some(flag), Some(phrase)) = (flag, phrase) { + if flag != phrase { + return Err(format!( + "conflicting package sources: --{} and {} in the request", + backend_flag_name(flag), + phrase.as_str() + ) + .into()); + } + } + Ok(flag.or(phrase)) +} + /// Parse `remove ` / `uninstall ` / `delete ` / `please remove `. fn parse_removal_text(text: &str) -> Option { let mut trimmed = text.trim(); @@ -817,6 +870,52 @@ fn print_install_offer(cli: &Cli, exec: &Exec, application: &str) { eprintln!(" sys install {application} --legacy --ebuild"); } +fn print_explicit_install_recovery(exec: &Exec, root: &Path, application: &str, backend: Backend) { + let lane = backend_flag_name(backend); + if application.split_whitespace().count() > 1 { + eprintln!("`{application}` is a description, not an exact package identifier."); + let words: Vec<_> = application.split_whitespace().collect(); + let search_term = words[0]; + let phase = exec.progress_phase(&format!( + "Searching {} for `{search_term}`", + backend.as_str() + )); + let report = query::search(exec, root, search_term, Some(backend)); + phase.complete(); + let match_from_catalog = report.entries().find(|entry| { + entry.id.eq_ignore_ascii_case(search_term) + && words[1..].iter().all(|word| { + entry + .description + .as_deref() + .unwrap_or("") + .to_ascii_lowercase() + .contains(&word.to_ascii_lowercase()) + }) + }); + if let Some(entry) = match_from_catalog { + eprintln!( + "A matching {} package exists: {}", + backend.as_str(), + entry.id + ); + if let Some(description) = &entry.description { + eprintln!(" {description}"); + } + eprintln!("Install that verified package without a model:"); + eprintln!(" sys install {} --legacy --{lane}", entry.id); + return; + } + eprintln!("Find the package identifier first:"); + eprintln!(" sys search {search_term} --legacy --{lane}"); + eprintln!("Then install the verified result without a model:"); + eprintln!(" sys install --legacy --{lane}"); + } else { + eprintln!("Run deterministically without a model using legacy mode:"); + eprintln!(" sys install {application} --legacy --{lane}"); + } +} + /// `sys install `: the shared installation workflow. fn run_install( cli: &Cli, @@ -835,11 +934,7 @@ fn run_install( if !resolved.is_configured() { if let Some(b) = backend { eprintln!("sys: no AI model is configured for this request."); - eprintln!("Run deterministically without a model using legacy mode:"); - eprintln!( - " sys install {application} --legacy --{}", - backend_flag_name(b) - ); + print_explicit_install_recovery(exec, &cli.root, application, b); } else { print_install_offer(cli, exec, application); } @@ -850,11 +945,7 @@ fn run_install( Err(e) => { if let Some(b) = backend { eprintln!("sys: {e}"); - eprintln!("Run deterministically without a model using legacy mode:"); - eprintln!( - " sys install {application} --legacy --{}", - backend_flag_name(b) - ); + print_explicit_install_recovery(exec, &cli.root, application, b); } else { print_install_offer(cli, exec, application); } @@ -912,15 +1003,14 @@ fn run_install( Err(e) => { // The model failed: offer the actionable legacy alternative and stop; // do not install through any backend. + drop(investigation); if let Some(b) = backend { eprintln!("sys: the AI investigation did not produce a plan ({e})."); - eprintln!("Run deterministically without a model using legacy mode:"); - eprintln!( - " sys install {application} --legacy --{}", - backend_flag_name(b) - ); + print_explicit_install_recovery(exec, &cli.root, application, b); } else { - print_install_offer(cli, exec, application); + eprintln!("sys: the connected model did not produce a usable plan ({e})."); + eprintln!("Search for an exact package identifier and retry:"); + eprintln!(" sys search --legacy"); } return Err(format!("the AI investigation did not produce a plan: {e}").into()); } @@ -1334,6 +1424,23 @@ fn _auto() -> AutoConfirm { mod tests { use super::*; + #[test] + fn install_phrase_separates_application_from_package_lane() { + assert_eq!( + parse_install_text("install chatgpt desktop through nix"), + Some(("chatgpt desktop".into(), Some(Backend::Nix))) + ); + assert_eq!( + parse_install_text("please install 'visual studio code' via flatpak"), + Some(("visual studio code".into(), Some(Backend::Flatpak))) + ); + assert_eq!( + parse_install_text("install firefox"), + Some(("firefox".into(), None)) + ); + assert!(combine_install_backend(Some(Backend::Flatpak), Some(Backend::Nix)).is_err()); + } + #[test] fn opencode_progress_names_the_real_provider_and_model() { let resolved = phoebus_installer::ai_setup::resolve( diff --git a/installer-rs/crates/phoebus-installer/tests/sys_cli.rs b/installer-rs/crates/phoebus-installer/tests/sys_cli.rs index fe0ebbe..cadf505 100644 --- a/installer-rs/crates/phoebus-installer/tests/sys_cli.rs +++ b/installer-rs/crates/phoebus-installer/tests/sys_cli.rs @@ -408,6 +408,28 @@ fn source_flag_without_legacy_enters_ai_workflow_and_suggests_legacy() { ); } +#[test] +fn natural_install_lane_is_not_part_of_the_package_name() { + let root = tempfile::tempdir().expect("temp root"); + let out = sys() + .env("PHOEBUS_AI_PROVIDER", "none") + .arg("--root") + .arg(root.path()) + .args(["install", "chatgpt", "desktop", "through", "nix"]) + .output() + .expect("run sys"); + assert!(!out.status.success()); + let stderr = String::from_utf8_lossy(&out.stderr); + assert!( + stderr.contains("sys search chatgpt --legacy --nix"), + "{stderr}" + ); + assert!( + !stderr.contains("sys install chatgpt desktop through nix --legacy"), + "{stderr}" + ); +} + #[test] fn an_explicit_backend_never_falls_back_to_another_lane() { if effective_uid_is_root() {