fix(sys): parse natural install package lanes
Some checks are pending
ci / test (push) Waiting to run

This commit is contained in:
Phoebus 2026-10-02 05:19:09 -07:00
parent 6136fa1664
commit c9c17cc16f
6 changed files with 198 additions and 26 deletions

View file

@ -5,6 +5,14 @@ this file is the curated, human-readable summary.
## Unreleased — Fast defaults with user-controlled source builds ## 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 - **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. open the Assistant's update view directly, including without an AI model.
Its Apply action opens the existing interactive `sys` update flow in Kitty, Its Apply action opens the existing interactive `sys` update flow in Kitty,

View file

@ -3,6 +3,20 @@
Rolling note between work sessions. **Update this file before you finish**, then 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. 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 - **Phoebus Updates entry point (2026-10-02):** The Updates view now has a
dedicated launcher and Super+U shortcut, works without a connected model, dedicated launcher and Super+U shortcut, works without a connected model,
and opens the existing interactive `sys` apply flow in Kitty so review and and opens the existing interactive `sys` apply flow in Kitty so review and

View file

@ -48,6 +48,20 @@ disposable VM; `serial-driver.py recovery` now automates the same check.
## Matrix ## Matrix
Natural install lane parsing (2026-10-02): `sys` recognizes trailing
`through/via/using/with <lane>` 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 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 provide a dedicated launcher and Super+U shortcut that open the Assistant's
Updates view without needing a connected model. Review & Apply launches Updates view without needing a connected model. Review & Apply launches

View file

@ -51,11 +51,18 @@ sys ask "install firefox" # identical AI workflow
sys install firefox --flatpak # AI workflow constrained to Flatpak sys install firefox --flatpak # AI workflow constrained to Flatpak
sys install firefox --portage # AI workflow constrained to Portage sys install firefox --portage # AI workflow constrained to Portage
sys install nodejs --nix # AI workflow constrained to Nix 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 thunderbird --snap # AI workflow constrained to Snap
sys install MyTool --appimage # AI workflow constrained to AppImage sys install MyTool --appimage # AI workflow constrained to AppImage
sys install app-misc/my-thing --ebuild # AI workflow constrained to custom ebuild 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 Removal is also AI-first by default. The deterministic ownership discovery and
policy validation always run underneath; the connected model confirms the exact policy validation always run underneath; the connected model confirms the exact
discovered copy. An ambiguous multi-lane install still requires an explicit discovered copy. An ambiguous multi-lane install still requires an explicit

View file

@ -19,7 +19,7 @@ use phoebus_core::transaction::{TransactionOutcome, TransactionRecord};
use phoebus_core::{AiBackend, InstallConfig, Redactor}; use phoebus_core::{AiBackend, InstallConfig, Redactor};
use phoebus_executor::install::{AiInstall, ExecutorSession, InstallRequest}; use phoebus_executor::install::{AiInstall, ExecutorSession, InstallRequest};
use phoebus_executor::{ use phoebus_executor::{
actions, authorize, chooser, probe, transaction, AutoConfirm, Confirmation, actions, authorize, chooser, probe, query, transaction, AutoConfirm, Confirmation,
DestructiveAuthorization, Exec, Logger, RealRunner, Result, DestructiveAuthorization, Exec, Logger, RealRunner, Result,
}; };
use phoebus_installer::approval; use phoebus_installer::approval;
@ -371,7 +371,8 @@ fn run() -> std::result::Result<(), Box<dyn std::error::Error>> {
// 4. Explicit legacy mode (--legacy) // 4. Explicit legacy mode (--legacy)
if cli.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 { if let Some(b) = backend {
let mut request = InstallRequest::new(&application); let mut request = InstallRequest::new(&application);
request.backend = Some(b); request.backend = Some(b);
@ -498,7 +499,8 @@ fn run() -> std::result::Result<(), Box<dyn std::error::Error>> {
} }
// Natural `sys install <app>` / `sys please install <app>` // Natural `sys install <app>` / `sys please install <app>`
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); return run_install(&cli, &exec, &plans, &application, backend);
} }
@ -704,8 +706,9 @@ fn backend_flag_name(backend: Backend) -> &'static str {
} }
} }
/// Parse `install <application>` / `add <application>` / `please install <application>`. /// Parse an install request, including a trailing `via/using/with/through <lane>`.
fn parse_install_text(text: &str) -> Option<String> { /// The lane is syntax, never part of the application name sent to the model.
fn parse_install_text(text: &str) -> Option<(String, Option<Backend>)> {
let mut trimmed = text.trim(); let mut trimmed = text.trim();
for prefix in ["please ", "Please "] { for prefix in ["please ", "Please "] {
if let Some(rest) = trimmed.strip_prefix(prefix) { if let Some(rest) = trimmed.strip_prefix(prefix) {
@ -718,18 +721,68 @@ fn parse_install_text(text: &str) -> Option<String> {
if lower.starts_with(prefix) { if lower.starts_with(prefix) {
// Strip surrounding quotes so a multi-word app name ("visual // Strip surrounding quotes so a multi-word app name ("visual
// studio code") is treated as one operand. // studio code") is treated as one operand.
let app = trimmed[prefix.len()..] let operand = trimmed[prefix.len()..].trim();
.trim() let lower_operand = operand.to_ascii_lowercase();
.trim_matches(['"', '\'']) let mut source = None;
.trim(); 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) { 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 None
} }
fn combine_install_backend(
flag: Option<Backend>,
phrase: Option<Backend>,
) -> std::result::Result<Option<Backend>, Box<dyn std::error::Error>> {
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 <application>` / `uninstall <application>` / `delete <application>` / `please remove <application>`. /// Parse `remove <application>` / `uninstall <application>` / `delete <application>` / `please remove <application>`.
fn parse_removal_text(text: &str) -> Option<String> { fn parse_removal_text(text: &str) -> Option<String> {
let mut trimmed = text.trim(); 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"); 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 <exact-package-id> --legacy --{lane}");
} else {
eprintln!("Run deterministically without a model using legacy mode:");
eprintln!(" sys install {application} --legacy --{lane}");
}
}
/// `sys install <application>`: the shared installation workflow. /// `sys install <application>`: the shared installation workflow.
fn run_install( fn run_install(
cli: &Cli, cli: &Cli,
@ -835,11 +934,7 @@ fn run_install(
if !resolved.is_configured() { if !resolved.is_configured() {
if let Some(b) = backend { if let Some(b) = backend {
eprintln!("sys: no AI model is configured for this request."); eprintln!("sys: no AI model is configured for this request.");
eprintln!("Run deterministically without a model using legacy mode:"); print_explicit_install_recovery(exec, &cli.root, application, b);
eprintln!(
" sys install {application} --legacy --{}",
backend_flag_name(b)
);
} else { } else {
print_install_offer(cli, exec, application); print_install_offer(cli, exec, application);
} }
@ -850,11 +945,7 @@ fn run_install(
Err(e) => { Err(e) => {
if let Some(b) = backend { if let Some(b) = backend {
eprintln!("sys: {e}"); eprintln!("sys: {e}");
eprintln!("Run deterministically without a model using legacy mode:"); print_explicit_install_recovery(exec, &cli.root, application, b);
eprintln!(
" sys install {application} --legacy --{}",
backend_flag_name(b)
);
} else { } else {
print_install_offer(cli, exec, application); print_install_offer(cli, exec, application);
} }
@ -912,15 +1003,14 @@ fn run_install(
Err(e) => { Err(e) => {
// The model failed: offer the actionable legacy alternative and stop; // The model failed: offer the actionable legacy alternative and stop;
// do not install through any backend. // do not install through any backend.
drop(investigation);
if let Some(b) = backend { if let Some(b) = backend {
eprintln!("sys: the AI investigation did not produce a plan ({e})."); eprintln!("sys: the AI investigation did not produce a plan ({e}).");
eprintln!("Run deterministically without a model using legacy mode:"); print_explicit_install_recovery(exec, &cli.root, application, b);
eprintln!(
" sys install {application} --legacy --{}",
backend_flag_name(b)
);
} else { } 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 <term> --legacy");
} }
return Err(format!("the AI investigation did not produce a plan: {e}").into()); return Err(format!("the AI investigation did not produce a plan: {e}").into());
} }
@ -1334,6 +1424,23 @@ fn _auto() -> AutoConfirm {
mod tests { mod tests {
use super::*; 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] #[test]
fn opencode_progress_names_the_real_provider_and_model() { fn opencode_progress_names_the_real_provider_and_model() {
let resolved = phoebus_installer::ai_setup::resolve( let resolved = phoebus_installer::ai_setup::resolve(

View file

@ -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] #[test]
fn an_explicit_backend_never_falls_back_to_another_lane() { fn an_explicit_backend_never_falls_back_to_another_lane() {
if effective_uid_is_root() { if effective_uid_is_root() {