feat(sys): show live progress and readable answers
Some checks are pending
ci / test (push) Waiting to run
Some checks are pending
ci / test (push) Waiting to run
This commit is contained in:
parent
b3dfb79883
commit
ba78284747
12 changed files with 659 additions and 21 deletions
|
|
@ -5,6 +5,17 @@ this file is the curated, human-readable summary.
|
|||
|
||||
## Unreleased — Fast defaults with user-controlled source builds
|
||||
|
||||
- **Readable `sys` progress (2026-10-01).** The terminal now names the active
|
||||
planning, evidence, effect-checking, execution and verification steps, shows
|
||||
a slow command's operation, and repeats the current step every ten seconds.
|
||||
Success and failure are visually distinct; command arguments and output are
|
||||
excluded from progress. Informational model answers are wrapped as prose
|
||||
without an irrelevant approval digest. Broker JSON and the assistant stdio
|
||||
protocol remain unchanged. Unit and CLI integration tests cover the
|
||||
progress lifecycle, redaction, heartbeat, wrapping and protocol boundary.
|
||||
A disposable visible playground run showed a legacy history command and a
|
||||
real OpenCode question with the new progress and concise answer rendering.
|
||||
|
||||
- **Desktop administrator authentication (2026-10-01).** Installed systems
|
||||
now give polkit the same `wheel` administrator group used by sudo. In the
|
||||
visible disposable VM, the default root-only polkit prompt rejected the
|
||||
|
|
|
|||
|
|
@ -3,6 +3,23 @@
|
|||
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` terminal presentation (2026-10-01, overlay VM VERIFIED):**
|
||||
Human CLI runs now show the current planning, evidence, effects, execution
|
||||
and verification phase; slow commands identify their operation and long
|
||||
steps print a ten-second heartbeat. Status is on stderr and redacted;
|
||||
results stay on stdout, while broker JSON and the assistant bridge are
|
||||
quiet. Informational model answers are wrapped and do not show an approval
|
||||
digest. Unit and CLI integration tests pass. The visible playground overlay
|
||||
was updated with a rebuilt `sys`: `sys history --legacy` visibly showed
|
||||
step transitions, and real OpenCode `sys ask what model are you using`
|
||||
showed model/evidence progress and a short wrapped answer. The final VM
|
||||
binary names `OpenCode (opencode-go/deepseek-v4.1-flash)` instead of the
|
||||
adapter's internal "local" label. The user's `sys find glances` request
|
||||
completed in the same VM with package-lane checks visible and a concise
|
||||
wrapped answer; a unit regression test covers the model label.
|
||||
A fresh ISO/install has not included this change. `make doctor` reports
|
||||
only 10 GiB free against its 20 GiB new-VM threshold; no new VM was made.
|
||||
|
||||
- **Polkit wheel administrator fix (2026-10-01, overlay VM VERIFIED):**
|
||||
The visible playground exposed a default root-only polkit prompt for
|
||||
software updates. The installed `phoebus` user's password worked with sudo
|
||||
|
|
|
|||
|
|
@ -123,6 +123,7 @@ disposable VM; `serial-driver.py recovery` now automates the same check.
|
|||
| Personal write ownership (elevated chown, symlink refusal, cross-uid refusal) | yes | yes (ownership-fixer seam + CLI refusal) | no | no |
|
||||
| Personal preference does not need the root-owned system transaction log | yes | yes (CLI regression: read-only transaction dir) | yes (installed VM acceptance) | n/a |
|
||||
| Installed `sys` acceptance matrix (read-only/failure) | yes | yes | yes (installed VM, HEAD binary on a golden overlay `serial-boot-20260929T092147Z-6f88907a`: read-only `SUMMARY PASS=49 FAIL=0`; root mutate `serial-boot-20260929T093329Z-4ef893cf`: `SUMMARY PASS=42 FAIL=0` incl. `mutate-install`/`mutate-remove`/`mutate-history`) | no |
|
||||
| `sys` terminal progress and prose answers | yes | yes (progress/redaction/heartbeat/wrapping, human CLI vs broker) | visible disposable playground overlay: `sys history --legacy` shows live phases; real OpenCode `sys ask` and `sys find glances` show model/evidence phases plus wrapped answers without approval digests; ten-second heartbeat timing unit-tested | no |
|
||||
| `sys` adversarial input battery (injection/traversal/boundaries) | yes | yes (54-case `tests/sys_adversarial.rs`; five validation gaps fixed: file-path metacharacters + `..`, application-name traversal, ebuild `..` category (real overlay escape), Flatpak empty element, Nix option prefix) | no | no |
|
||||
| Portage config readable for non-root queries (`normalize_config_permissions`) | yes | yes (modes + keyring exclusion) | yes (fresh VM install: 0755/0644 out of the box; non-root `search` returns 3 results, `updates` reports 10) | no |
|
||||
| Privileged catalogue mutations (install/remove/depclean/cache/apply updates, alternate-root) | yes | yes (unit) | yes (fresh installed VM via root: 7/7 PASS) | no |
|
||||
|
|
|
|||
12
docs/SYS.md
12
docs/SYS.md
|
|
@ -22,6 +22,18 @@ Run `sys --help` for the full list of flags. Mutating actions require root
|
|||
deterministic legacy alternative (`sys install <pkg> --legacy --<source>`)
|
||||
instead of silently falling back or switching sources.
|
||||
|
||||
### Terminal feedback
|
||||
|
||||
Interactive `sys` commands show the current phase on stderr: checking the
|
||||
system, investigating with the connected model, validating real package
|
||||
evidence, reviewing effects, applying each approved action, and verifying the
|
||||
result. A command that takes more than a moment shows its operation label;
|
||||
long steps repeat their current label and elapsed time every ten seconds.
|
||||
Progress never includes command arguments, command output, or credentials.
|
||||
Results remain on stdout. Broker JSON and the assistant's stdio protocol do
|
||||
not emit human progress. Informational model answers are wrapped as prose and
|
||||
omit the approval digest when no action is proposed.
|
||||
|
||||
> [!NOTE]
|
||||
> `--legacy` is the administrative flag for `sys` deterministic operations.
|
||||
> `--no-ai` is an installer-only break-glass flag reserved exclusively for
|
||||
|
|
|
|||
|
|
@ -3,6 +3,25 @@
|
|||
This records the first successful end-to-end install and boot of Phoebus OS
|
||||
against a disposable qcow2 disk. No physical disk was ever touched.
|
||||
|
||||
## 2026-10-01 Visible playground `sys` presentation
|
||||
|
||||
A rebuilt `sys` binary was installed only in the writable overlay of the
|
||||
visible `reliability-v7-a.qcow2` playground (final binary SHA-256
|
||||
`abf7c5de450751eb3a969091791c9da946eb59500f2c66cfe59d9cde94488abe`).
|
||||
`sys history --legacy` showed
|
||||
effect-checking and action progress with clear completion states. A real
|
||||
OpenCode Go `sys ask what model are you using` showed system/model/evidence
|
||||
steps and rendered the informational answer as wrapped prose, without an
|
||||
approval digest. The inspected screenshots are
|
||||
`/var/tmp/phoebus-vm/sys-progress-history.png` and
|
||||
`/var/tmp/phoebus-vm/sys-progress-final-model.png`. The final binary visibly
|
||||
named `OpenCode (opencode-go/deepseek-v4.1-flash)`, and the user's
|
||||
`sys find glances` request completed in about 15 seconds with package-lane
|
||||
checks and a wrapped answer (`/var/tmp/phoebus-vm/sys-progress-find-mid.png`).
|
||||
The ten-second
|
||||
heartbeat is unit-tested with a shortened interval, not timed in this VM
|
||||
run. No fresh ISO or install includes this source revision yet.
|
||||
|
||||
## 2026-10-01 Visible playground polkit correction
|
||||
|
||||
The visible playground booted a writable overlay of the verified
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
//! Execution context: the single place commands are run and logged.
|
||||
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::sync::Arc;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use phoebus_core::{Redactor, SecretString, TargetRoot};
|
||||
|
||||
|
|
@ -8,12 +10,56 @@ use crate::command::{CommandOutput, CommandSpec, ProcessRunner};
|
|||
use crate::error::{ExecError, Result};
|
||||
use crate::log::Logger;
|
||||
|
||||
/// User-facing progress is separate from the structured, redacted installer log.
|
||||
/// Labels are redacted before they leave `Exec`; command arguments and output
|
||||
/// never enter this channel.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum ProgressEvent {
|
||||
Started {
|
||||
label: String,
|
||||
detail: bool,
|
||||
},
|
||||
Finished {
|
||||
label: String,
|
||||
detail: bool,
|
||||
success: bool,
|
||||
elapsed: Duration,
|
||||
},
|
||||
}
|
||||
|
||||
pub type ProgressSink = Arc<dyn Fn(ProgressEvent) + Send + Sync>;
|
||||
|
||||
pub struct Exec {
|
||||
pub runner: Box<dyn ProcessRunner>,
|
||||
pub logger: Logger,
|
||||
pub dry_run: bool,
|
||||
pub root: PathBuf,
|
||||
pub state_dir: PathBuf,
|
||||
progress: Option<ProgressSink>,
|
||||
}
|
||||
|
||||
pub struct ProgressPhase<'a> {
|
||||
exec: &'a Exec,
|
||||
label: String,
|
||||
started: Instant,
|
||||
success: bool,
|
||||
}
|
||||
|
||||
impl ProgressPhase<'_> {
|
||||
pub fn complete(mut self) {
|
||||
self.success = true;
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for ProgressPhase<'_> {
|
||||
fn drop(&mut self) {
|
||||
self.exec.report(ProgressEvent::Finished {
|
||||
label: self.label.clone(),
|
||||
detail: false,
|
||||
success: self.success,
|
||||
elapsed: self.started.elapsed(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
impl Exec {
|
||||
|
|
@ -30,6 +76,32 @@ impl Exec {
|
|||
dry_run,
|
||||
root: root.into(),
|
||||
state_dir: state_dir.into(),
|
||||
progress: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_progress(mut self, sink: ProgressSink) -> Self {
|
||||
self.progress = Some(sink);
|
||||
self
|
||||
}
|
||||
|
||||
fn report(&self, event: ProgressEvent) {
|
||||
if let Some(sink) = &self.progress {
|
||||
sink(event);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn progress_phase(&self, label: &str) -> ProgressPhase<'_> {
|
||||
let label = self.redactor().redact(label);
|
||||
self.report(ProgressEvent::Started {
|
||||
label: label.clone(),
|
||||
detail: false,
|
||||
});
|
||||
ProgressPhase {
|
||||
exec: self,
|
||||
label,
|
||||
started: Instant::now(),
|
||||
success: false,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -64,7 +136,24 @@ impl Exec {
|
|||
&spec.args,
|
||||
stdin_hidden,
|
||||
);
|
||||
let output = self.runner.execute(&spec)?;
|
||||
let label = format!(
|
||||
"{} · {}",
|
||||
self.redactor().redact(&spec.stage),
|
||||
self.redactor().redact(&spec.operation)
|
||||
);
|
||||
self.report(ProgressEvent::Started {
|
||||
label: label.clone(),
|
||||
detail: true,
|
||||
});
|
||||
let started = Instant::now();
|
||||
let result = self.runner.execute(&spec);
|
||||
self.report(ProgressEvent::Finished {
|
||||
label,
|
||||
detail: true,
|
||||
success: result.as_ref().is_ok_and(|output| output.success),
|
||||
elapsed: started.elapsed(),
|
||||
});
|
||||
let output = result?;
|
||||
self.logger.command(crate::log::CommandRecord {
|
||||
stage: &spec.stage,
|
||||
operation: &spec.operation,
|
||||
|
|
@ -266,6 +355,55 @@ mod tests {
|
|||
assert!(msg.contains("mkfs.btrfs"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn progress_reports_redacted_command_and_outcome_without_arguments() {
|
||||
use std::sync::Mutex;
|
||||
|
||||
let runner = RecordingRunner::new();
|
||||
runner.fail("false", "failed");
|
||||
let events = Arc::new(Mutex::new(Vec::new()));
|
||||
let observed = Arc::clone(&events);
|
||||
let e = exec(runner).with_progress(Arc::new(move |event| {
|
||||
observed.lock().unwrap().push(event);
|
||||
}));
|
||||
let secret = SecretString::new("private-value");
|
||||
e.register_secret(&secret);
|
||||
let _ =
|
||||
e.run(CommandSpec::new("query", "check private-value", "false").arg("private-value"));
|
||||
let events = events.lock().unwrap();
|
||||
assert!(
|
||||
matches!(&events[0], ProgressEvent::Started { label, detail: true }
|
||||
if label == "query · check <redacted>")
|
||||
);
|
||||
assert!(
|
||||
matches!(&events[1], ProgressEvent::Finished { label, detail: true, success: false, .. }
|
||||
if label == "query · check <redacted>")
|
||||
);
|
||||
assert_eq!(events.len(), 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn progress_phase_finishes_only_when_marked_complete() {
|
||||
use std::sync::Mutex;
|
||||
|
||||
let events = Arc::new(Mutex::new(Vec::new()));
|
||||
let observed = Arc::clone(&events);
|
||||
let e = exec(RecordingRunner::new()).with_progress(Arc::new(move |event| {
|
||||
observed.lock().unwrap().push(event);
|
||||
}));
|
||||
e.progress_phase("first").complete();
|
||||
drop(e.progress_phase("second"));
|
||||
let events = events.lock().unwrap();
|
||||
assert!(matches!(
|
||||
&events[1],
|
||||
ProgressEvent::Finished { success: true, .. }
|
||||
));
|
||||
assert!(matches!(
|
||||
&events[3],
|
||||
ProgressEvent::Finished { success: false, .. }
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn find_true_in_path() {
|
||||
assert!(find_in_path("true").is_some());
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
use std::io::Write;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::ExitCode;
|
||||
use std::sync::Arc;
|
||||
|
||||
use clap::Parser;
|
||||
use phoebus_ai::provider::SystemFacts;
|
||||
|
|
@ -25,6 +26,9 @@ use phoebus_installer::approval;
|
|||
use phoebus_installer::conversation::{self, ConversationTurn, FollowupResolution};
|
||||
use phoebus_installer::service::{self, PreparedPlan};
|
||||
|
||||
#[path = "sys/progress.rs"]
|
||||
mod progress;
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(
|
||||
name = "sys",
|
||||
|
|
@ -245,19 +249,28 @@ fn main() -> ExitCode {
|
|||
fn run() -> std::result::Result<(), Box<dyn std::error::Error>> {
|
||||
let cli = Cli::parse();
|
||||
|
||||
// Broker stdout is a JSON protocol. The assistant bridge is also a stdio
|
||||
// protocol, so neither entry point gets human progress messages.
|
||||
let progress =
|
||||
(!cli.broker && !cli.assistant_bridge).then(|| Arc::new(progress::ProgressView::new()));
|
||||
|
||||
let mut state_dir = PathBuf::from("/run/phoebus-installer");
|
||||
if std::fs::create_dir_all(&state_dir).is_err() {
|
||||
state_dir = std::env::temp_dir().join("phoebus-installer");
|
||||
std::fs::create_dir_all(&state_dir).ok();
|
||||
}
|
||||
let logger = Logger::open(state_dir.join("sys.log"), Redactor::new(), false);
|
||||
let exec = Exec::new(
|
||||
let mut exec = Exec::new(
|
||||
Box::new(RealRunner::new()),
|
||||
logger,
|
||||
false,
|
||||
cli.root.clone(),
|
||||
state_dir,
|
||||
);
|
||||
if let Some(view) = &progress {
|
||||
let view = Arc::clone(view);
|
||||
exec = exec.with_progress(Arc::new(move |event| view.on_event(event)));
|
||||
}
|
||||
let plans = service::PlanStore::for_current_user();
|
||||
|
||||
// 1. Assistant Bridge
|
||||
|
|
@ -354,11 +367,15 @@ fn run() -> std::result::Result<(), Box<dyn std::error::Error>> {
|
|||
if let Some(b) = backend {
|
||||
let mut request = InstallRequest::new(&application);
|
||||
request.backend = Some(b);
|
||||
let phase = exec.progress_phase("Checking the selected package and its effects");
|
||||
let plan = service::plan_legacy_install(&plans, &exec, &cli.root, &request)?;
|
||||
phase.complete();
|
||||
return render_and_execute_plan(&cli, &exec, &plans, plan);
|
||||
} else {
|
||||
let phase = exec.progress_phase("Checking available package sources");
|
||||
let need = phoebus_core::selection::Need::new(&application);
|
||||
let candidates = chooser::resolve_candidates(&exec, &cli.root, &need);
|
||||
phase.complete();
|
||||
let available: Vec<_> = candidates.into_iter().filter(|c| c.available).collect();
|
||||
|
||||
if available.is_empty() {
|
||||
|
|
@ -413,7 +430,10 @@ fn run() -> std::result::Result<(), Box<dyn std::error::Error>> {
|
|||
}
|
||||
}
|
||||
if let Some(application) = parse_removal_text(&full_phrase) {
|
||||
let phase =
|
||||
exec.progress_phase("Finding installed copies and checking removal effects");
|
||||
let plan = service::plan_removal(&plans, &exec, &cli.root, &application, backend)?;
|
||||
phase.complete();
|
||||
return render_and_execute_plan(&cli, &exec, &plans, plan);
|
||||
}
|
||||
if full_phrase.trim().is_empty() {
|
||||
|
|
@ -576,7 +596,12 @@ fn execute_action(
|
|||
return Err("mutating actions require root; run `sudo sys ...`".into());
|
||||
}
|
||||
|
||||
let approved = match actions::resolve_effects(exec, &action, &cli.root) {
|
||||
let effects_phase = exec.progress_phase("Checking the exact effects");
|
||||
let resolved = actions::resolve_effects(exec, &action, &cli.root);
|
||||
if resolved.is_ok() {
|
||||
effects_phase.complete();
|
||||
}
|
||||
let approved = match resolved {
|
||||
// An established plan is bound to the approval even when it is empty
|
||||
// (a genuine "0 packages" result), so the review is exact.
|
||||
Ok(plan) if plan.established => {
|
||||
|
|
@ -604,8 +629,10 @@ fn execute_action(
|
|||
None
|
||||
};
|
||||
|
||||
let execution_phase = exec.progress_phase("Running the action and checking its result");
|
||||
let outcome =
|
||||
actions::execute_checked(exec, &action, auth.as_ref(), &cli.root, approved.as_ref())?;
|
||||
execution_phase.complete();
|
||||
if let Some(id) = &outcome.snapshot {
|
||||
println!("protective snapshot: {id}");
|
||||
}
|
||||
|
|
@ -616,6 +643,7 @@ fn execute_action(
|
|||
// `/var/lib/phoebus/transactions.toml` would fail for a normal account
|
||||
// (permission denied) even though the preference was saved successfully.
|
||||
if action.requires_root() {
|
||||
let history_phase = exec.progress_phase("Recording the completed operation");
|
||||
let described = action.describe();
|
||||
let record = TransactionRecord {
|
||||
id: 0,
|
||||
|
|
@ -629,6 +657,7 @@ fn execute_action(
|
|||
outcomes: vec![TransactionOutcome::completed(described)],
|
||||
};
|
||||
record_transaction(exec, &cli.root, record)?;
|
||||
history_phase.complete();
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -756,9 +785,17 @@ fn install_asker(cli: &Cli) -> Option<Box<AskFn>> {
|
|||
/// Explain that an unqualified install needs a model, and show the
|
||||
/// deterministic candidate selection without installing it.
|
||||
fn print_install_offer(cli: &Cli, exec: &Exec, application: &str) {
|
||||
let phase =
|
||||
exec.progress_phase("Checking available package sources for an offline alternative");
|
||||
let need = InstallRequest::new(application).need();
|
||||
match chooser::choose(exec, &cli.root, &need) {
|
||||
Ok(selection) => println!("{}", selection.render()),
|
||||
Ok(selection) => {
|
||||
phase.complete();
|
||||
println!(
|
||||
"{}",
|
||||
progress::wrap_text(&selection.render(), progress::terminal_columns())
|
||||
);
|
||||
}
|
||||
Err(e) => eprintln!("sys: the deterministic selector also found no candidate: {e}"),
|
||||
}
|
||||
eprintln!();
|
||||
|
|
@ -784,7 +821,9 @@ fn run_install(
|
|||
request.backend = backend;
|
||||
|
||||
let resolved = resolve_ai(cli);
|
||||
let facts_phase = exec.progress_phase("Checking this system and its package sources");
|
||||
let facts = gather_facts(exec);
|
||||
facts_phase.complete();
|
||||
if !resolved.is_configured() {
|
||||
if let Some(b) = backend {
|
||||
eprintln!("sys: no AI model is configured for this request.");
|
||||
|
|
@ -814,6 +853,7 @@ fn run_install(
|
|||
return Err(e.to_string().into());
|
||||
}
|
||||
};
|
||||
let model_label = connected_model_label(&resolved);
|
||||
let provider = resolved.provider;
|
||||
let endpoint = if resolved.backend == AiBackend::OpenCode {
|
||||
resolved.opencode_server.clone()
|
||||
|
|
@ -826,19 +866,6 @@ fn run_install(
|
|||
resolved.model.clone()
|
||||
};
|
||||
|
||||
if let Some(b) = backend {
|
||||
eprintln!(
|
||||
"Investigating `{application}` (constrained to {}) with {} (bounded, read-only evidence only)...",
|
||||
b.as_str(),
|
||||
provider.as_str()
|
||||
);
|
||||
} else {
|
||||
eprintln!(
|
||||
"Investigating `{application}` with {} (bounded, read-only evidence only)...",
|
||||
provider.as_str()
|
||||
);
|
||||
}
|
||||
|
||||
let ai = AiInstall {
|
||||
provider,
|
||||
endpoint,
|
||||
|
|
@ -852,6 +879,15 @@ fn run_install(
|
|||
root: &cli.root,
|
||||
ask: asker.as_deref(),
|
||||
};
|
||||
let investigation_label = match backend {
|
||||
Some(b) => format!(
|
||||
"Investigating `{application}` with {} ({} source)",
|
||||
model_label,
|
||||
b.as_str()
|
||||
),
|
||||
None => format!("Investigating `{application}` with {model_label}"),
|
||||
};
|
||||
let investigation = exec.progress_phase(&investigation_label);
|
||||
let plan = match service::plan_install(
|
||||
plans,
|
||||
exec,
|
||||
|
|
@ -861,7 +897,10 @@ fn run_install(
|
|||
Some(&ai),
|
||||
&facts,
|
||||
) {
|
||||
Ok(plan) => plan,
|
||||
Ok(plan) => {
|
||||
investigation.complete();
|
||||
plan
|
||||
}
|
||||
Err(e) => {
|
||||
// The model failed: offer the actionable legacy alternative and stop;
|
||||
// do not install through any backend.
|
||||
|
|
@ -910,8 +949,12 @@ fn run_remove(
|
|||
application: &str,
|
||||
backend: Option<Backend>,
|
||||
) -> std::result::Result<(), Box<dyn std::error::Error>> {
|
||||
let phase = exec.progress_phase("Finding installed copies and validating the removal plan");
|
||||
let plan = match run_remove_plan(cli, exec, plans, application, backend) {
|
||||
Ok(plan) => plan,
|
||||
Ok(plan) => {
|
||||
phase.complete();
|
||||
plan
|
||||
}
|
||||
Err(e) => {
|
||||
// The model failed: offer the actionable legacy alternative and
|
||||
// stop; do not silently remove deterministically.
|
||||
|
|
@ -995,7 +1038,15 @@ fn render_and_execute_plan(
|
|||
plans: &service::PlanStore,
|
||||
plan: PreparedPlan,
|
||||
) -> std::result::Result<(), Box<dyn std::error::Error>> {
|
||||
println!("{}", plan.render());
|
||||
let text = if plan.actions.is_empty() {
|
||||
format!("Phoebus\n\n{}", plan.summary.trim())
|
||||
} else {
|
||||
plan.render()
|
||||
};
|
||||
println!(
|
||||
"{}",
|
||||
progress::wrap_text(&text, progress::terminal_columns())
|
||||
);
|
||||
|
||||
// A purely informational answer (for example an AI-backed search summary)
|
||||
// has no actions and must not be sent to the execution boundary.
|
||||
|
|
@ -1031,7 +1082,9 @@ fn render_and_execute_plan(
|
|||
authorize(&confirmation, &plan.summary, "execute")?;
|
||||
}
|
||||
|
||||
let phase = exec.progress_phase("Running the approved plan and verifying the result");
|
||||
let outcome = service::execute_plan(exec, &cli.root, plans, &plan.id, &plan.digest, true)?;
|
||||
phase.complete();
|
||||
if let Some(snapshot) = outcome.snapshot {
|
||||
println!("protective snapshot: {snapshot}");
|
||||
}
|
||||
|
|
@ -1103,6 +1156,17 @@ fn resolve_ai(cli: &Cli) -> phoebus_installer::ai_setup::ResolvedAi {
|
|||
phoebus_installer::ai_setup::resolve(&cli.root, &overrides, conf.as_ref())
|
||||
}
|
||||
|
||||
fn connected_model_label(resolved: &phoebus_installer::ai_setup::ResolvedAi) -> String {
|
||||
if resolved.backend == AiBackend::OpenCode {
|
||||
format!(
|
||||
"OpenCode ({}/{})",
|
||||
resolved.opencode_provider, resolved.opencode_model
|
||||
)
|
||||
} else {
|
||||
format!("{} ({})", resolved.provider.as_str(), resolved.model)
|
||||
}
|
||||
}
|
||||
|
||||
fn deterministic_fallback(instruction: &str, backend: Option<Backend>) {
|
||||
eprintln!("No connected model is available. The deterministic legacy interface still works:");
|
||||
match parse_natural(instruction) {
|
||||
|
|
@ -1193,7 +1257,10 @@ fn run_ask(
|
|||
return Err(e.to_string().into());
|
||||
}
|
||||
};
|
||||
let model_label = connected_model_label(&resolved);
|
||||
let facts_phase = exec.progress_phase("Checking this system and its package sources");
|
||||
let facts = gather_facts(exec);
|
||||
facts_phase.complete();
|
||||
let provider = resolved.provider;
|
||||
let endpoint = if resolved.backend == AiBackend::OpenCode {
|
||||
resolved.opencode_server.clone()
|
||||
|
|
@ -1214,9 +1281,14 @@ fn run_ask(
|
|||
limits: phoebus_ai::install::Limits::default(),
|
||||
};
|
||||
|
||||
let investigation =
|
||||
exec.progress_phase(&format!("Asking {model_label} and validating its answer"));
|
||||
let plan =
|
||||
match service::plan_general(plans, exec, &cli.root, instruction, &facts, &ai, backend) {
|
||||
Ok(plan) => plan,
|
||||
Ok(plan) => {
|
||||
investigation.complete();
|
||||
plan
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("The model is unavailable or returned an unusable plan: {e}");
|
||||
deterministic_fallback(instruction, backend);
|
||||
|
|
@ -1249,3 +1321,28 @@ fn run_ask(
|
|||
fn _auto() -> AutoConfirm {
|
||||
AutoConfirm
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn opencode_progress_names_the_real_provider_and_model() {
|
||||
let resolved = phoebus_installer::ai_setup::resolve(
|
||||
Path::new("/"),
|
||||
&phoebus_installer::ai_setup::AiOverrides {
|
||||
backend: Some("opencode".into()),
|
||||
opencode_provider: Some("opencode-go".into()),
|
||||
opencode_model: Some("deepseek-v4.1-flash".into()),
|
||||
use_environment: false,
|
||||
..Default::default()
|
||||
},
|
||||
None,
|
||||
);
|
||||
assert_eq!(resolved.provider.as_str(), "local");
|
||||
assert_eq!(
|
||||
connected_model_label(&resolved),
|
||||
"OpenCode (opencode-go/deepseek-v4.1-flash)"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
283
installer-rs/crates/phoebus-installer/src/bin/sys/progress.rs
Normal file
283
installer-rs/crates/phoebus-installer/src/bin/sys/progress.rs
Normal file
|
|
@ -0,0 +1,283 @@
|
|||
//! Human-readable `sys` progress. It writes only to stderr, leaving broker
|
||||
//! JSON and the command's result on stdout unchanged.
|
||||
|
||||
use std::io::IsTerminal;
|
||||
use std::sync::{mpsc, Arc, Mutex};
|
||||
use std::thread::JoinHandle;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use phoebus_executor::exec::ProgressEvent;
|
||||
|
||||
type LineSink = Arc<dyn Fn(String) + Send + Sync>;
|
||||
|
||||
struct ActiveStep {
|
||||
label: String,
|
||||
detail: bool,
|
||||
started: Instant,
|
||||
last_update: Instant,
|
||||
shown: bool,
|
||||
}
|
||||
|
||||
pub struct ProgressView {
|
||||
active: Arc<Mutex<Vec<ActiveStep>>>,
|
||||
stop: mpsc::Sender<()>,
|
||||
worker: Mutex<Option<JoinHandle<()>>>,
|
||||
lines: LineSink,
|
||||
color: bool,
|
||||
}
|
||||
|
||||
impl ProgressView {
|
||||
pub fn new() -> Self {
|
||||
let color = std::io::stderr().is_terminal() && std::env::var_os("NO_COLOR").is_none();
|
||||
Self::with_options(
|
||||
Duration::from_secs(10),
|
||||
Duration::from_millis(700),
|
||||
Arc::new(|line| eprintln!("{line}")),
|
||||
color,
|
||||
)
|
||||
}
|
||||
|
||||
fn with_options(
|
||||
heartbeat: Duration,
|
||||
detail_delay: Duration,
|
||||
lines: LineSink,
|
||||
color: bool,
|
||||
) -> Self {
|
||||
let active = Arc::new(Mutex::new(Vec::<ActiveStep>::new()));
|
||||
let (stop, receiver) = mpsc::channel();
|
||||
let pending = Arc::clone(&active);
|
||||
let output = Arc::clone(&lines);
|
||||
let worker = std::thread::spawn(move || loop {
|
||||
match receiver.recv_timeout(Duration::from_millis(200)) {
|
||||
Ok(()) | Err(mpsc::RecvTimeoutError::Disconnected) => break,
|
||||
Err(mpsc::RecvTimeoutError::Timeout) => {}
|
||||
}
|
||||
let Ok(mut steps) = pending.lock() else {
|
||||
continue;
|
||||
};
|
||||
let Some(step) = steps.last_mut() else {
|
||||
continue;
|
||||
};
|
||||
let now = Instant::now();
|
||||
if step.detail && !step.shown && step.started.elapsed() >= detail_delay {
|
||||
output(format_line("↳", &step.label, color, 36));
|
||||
step.shown = true;
|
||||
}
|
||||
if now.duration_since(step.last_update) >= heartbeat {
|
||||
output(format_line(
|
||||
"…",
|
||||
&format!(
|
||||
"Still working on {} ({}s elapsed)",
|
||||
step.label,
|
||||
step.started.elapsed().as_secs()
|
||||
),
|
||||
color,
|
||||
36,
|
||||
));
|
||||
step.last_update = now;
|
||||
}
|
||||
});
|
||||
Self {
|
||||
active,
|
||||
stop,
|
||||
worker: Mutex::new(Some(worker)),
|
||||
lines,
|
||||
color,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn on_event(&self, event: ProgressEvent) {
|
||||
let Ok(mut steps) = self.active.lock() else {
|
||||
return;
|
||||
};
|
||||
match event {
|
||||
ProgressEvent::Started { label, detail } => {
|
||||
let label = clean_label(&label);
|
||||
if !detail {
|
||||
(self.lines)(format_line("○", &label, self.color, 36));
|
||||
}
|
||||
steps.push(ActiveStep {
|
||||
label,
|
||||
detail,
|
||||
started: Instant::now(),
|
||||
last_update: Instant::now(),
|
||||
shown: !detail,
|
||||
});
|
||||
}
|
||||
ProgressEvent::Finished {
|
||||
label,
|
||||
detail,
|
||||
success,
|
||||
elapsed,
|
||||
} => {
|
||||
let label = clean_label(&label);
|
||||
if let Some(index) = steps
|
||||
.iter()
|
||||
.rposition(|step| step.label == label && step.detail == detail)
|
||||
{
|
||||
let step = steps.remove(index);
|
||||
if step.shown || !success {
|
||||
let symbol = if success { "✓" } else { "✕" };
|
||||
let color = if success { 32 } else { 31 };
|
||||
(self.lines)(format_line(
|
||||
symbol,
|
||||
&format!("{} ({})", step.label, duration_label(elapsed)),
|
||||
self.color,
|
||||
color,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for ProgressView {
|
||||
fn drop(&mut self) {
|
||||
let _ = self.stop.send(());
|
||||
if let Ok(mut worker) = self.worker.lock() {
|
||||
if let Some(handle) = worker.take() {
|
||||
let _ = handle.join();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn clean_label(label: &str) -> String {
|
||||
let clean: String = label.chars().filter(|c| !c.is_control()).collect();
|
||||
let collapsed = clean.split_whitespace().collect::<Vec<_>>().join(" ");
|
||||
let mut chars = collapsed.chars();
|
||||
let head: String = chars.by_ref().take(120).collect();
|
||||
if chars.next().is_some() {
|
||||
format!("{head}…")
|
||||
} else {
|
||||
head
|
||||
}
|
||||
}
|
||||
|
||||
fn duration_label(duration: Duration) -> String {
|
||||
if duration.as_secs() >= 10 {
|
||||
format!("{}s", duration.as_secs())
|
||||
} else {
|
||||
format!("{:.1}s", duration.as_secs_f32())
|
||||
}
|
||||
}
|
||||
|
||||
fn format_line(symbol: &str, label: &str, color: bool, code: u8) -> String {
|
||||
if color {
|
||||
format!(" \x1b[{code}m{symbol}\x1b[0m {label}")
|
||||
} else {
|
||||
format!(" {symbol} {label}")
|
||||
}
|
||||
}
|
||||
|
||||
pub fn terminal_columns() -> usize {
|
||||
std::env::var("COLUMNS")
|
||||
.ok()
|
||||
.and_then(|value| value.parse::<usize>().ok())
|
||||
.filter(|width| (60..=240).contains(width))
|
||||
.unwrap_or(88)
|
||||
.min(120)
|
||||
}
|
||||
|
||||
/// Wrap prose without changing words, preserving the first-line indentation
|
||||
/// and giving continuation lines a small visual inset.
|
||||
pub fn wrap_text(text: &str, width: usize) -> String {
|
||||
let mut out = String::new();
|
||||
for line in text.lines() {
|
||||
let line: String = line
|
||||
.chars()
|
||||
.map(|ch| if ch.is_control() { ' ' } else { ch })
|
||||
.collect();
|
||||
let indent = line.chars().take_while(|c| *c == ' ').count();
|
||||
let continuation = " ".repeat(indent + 2);
|
||||
let mut rest = line;
|
||||
loop {
|
||||
if rest.chars().count() <= width {
|
||||
out.push_str(&rest);
|
||||
out.push('\n');
|
||||
break;
|
||||
}
|
||||
let break_at = rest
|
||||
.char_indices()
|
||||
.enumerate()
|
||||
.take_while(|(column, _)| *column <= width)
|
||||
.filter(|(_, (_, ch))| ch.is_whitespace())
|
||||
.map(|(_, (byte, _))| byte)
|
||||
.last();
|
||||
let first_word = rest
|
||||
.char_indices()
|
||||
.find(|(_, ch)| !ch.is_whitespace())
|
||||
.map(|(byte, _)| byte)
|
||||
.unwrap_or(0);
|
||||
let Some(at) = break_at.filter(|at| *at > first_word) else {
|
||||
out.push_str(&rest);
|
||||
out.push('\n');
|
||||
break;
|
||||
};
|
||||
out.push_str(rest[..at].trim_end());
|
||||
out.push('\n');
|
||||
rest = format!("{}{}", continuation, rest[at..].trim_start());
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn progress_keeps_results_readable_and_reports_long_waits() {
|
||||
let output = Arc::new(Mutex::new(Vec::new()));
|
||||
let collected = Arc::clone(&output);
|
||||
let view = ProgressView::with_options(
|
||||
Duration::from_millis(30),
|
||||
Duration::from_millis(10),
|
||||
Arc::new(move |line| {
|
||||
if let Ok(mut lines) = collected.lock() {
|
||||
lines.push(line);
|
||||
}
|
||||
}),
|
||||
false,
|
||||
);
|
||||
view.on_event(ProgressEvent::Started {
|
||||
label: "Asking the model".into(),
|
||||
detail: false,
|
||||
});
|
||||
std::thread::sleep(Duration::from_millis(260));
|
||||
view.on_event(ProgressEvent::Finished {
|
||||
label: "Asking the model".into(),
|
||||
detail: false,
|
||||
success: true,
|
||||
elapsed: Duration::from_millis(260),
|
||||
});
|
||||
drop(view);
|
||||
let lines = output.lock().unwrap();
|
||||
assert!(lines.iter().any(|line| line.contains("○ Asking the model")));
|
||||
assert!(lines
|
||||
.iter()
|
||||
.any(|line| line.contains("Still working on Asking the model")));
|
||||
assert!(lines.iter().any(|line| line.contains("✓ Asking the model")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn progress_removes_terminal_controls_from_labels() {
|
||||
assert_eq!(clean_label("\x1b[31m hello\nworld"), "[31m helloworld");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn long_prose_wraps_with_readable_continuation() {
|
||||
let formatted = wrap_text(
|
||||
" - Portage has several pending security updates that should be reviewed soon.",
|
||||
42,
|
||||
);
|
||||
assert!(formatted.contains("\n updates"), "{formatted}");
|
||||
assert!(
|
||||
formatted.lines().all(|line| line.len() <= 42),
|
||||
"{formatted}"
|
||||
);
|
||||
assert_eq!(wrap_text("hi\x1b[2J there", 42), "hi [2J there\n");
|
||||
assert_eq!(wrap_text(" abcdefghij", 5), " abcdefghij\n");
|
||||
}
|
||||
}
|
||||
|
|
@ -294,6 +294,11 @@ fn execute_claimed(
|
|||
outcomes.push(TransactionOutcome::unattempted(described));
|
||||
continue;
|
||||
}
|
||||
let action_phase = exec.progress_phase(&format!(
|
||||
"Applying step {} of {}: {described}",
|
||||
idx + 1,
|
||||
plan.actions.len()
|
||||
));
|
||||
// Only Portage transactions have a comparable `emerge --pretend` plan
|
||||
// at this boundary. Other lanes' effects were validated by
|
||||
// `validate_prepared_plan` (install revalidation / installed-copy
|
||||
|
|
@ -337,6 +342,7 @@ fn execute_claimed(
|
|||
};
|
||||
match actions::execute_inner(exec, action, auth, root, carried) {
|
||||
Ok(result) => {
|
||||
action_phase.complete();
|
||||
if result.snapshot.is_some() {
|
||||
snapshot = result.snapshot;
|
||||
}
|
||||
|
|
@ -391,6 +397,7 @@ fn execute_claimed(
|
|||
|
||||
// Post-execution verification. A verification error finishes the
|
||||
// transaction as a failed verification; it never leaves it "in progress".
|
||||
let verification_phase = exec.progress_phase("Verifying the completed plan");
|
||||
let verification_result = match plan.kind {
|
||||
PlanKind::Install | PlanKind::LegacyInstall => {
|
||||
if let (Some(cand), Some(act)) = (&plan.candidate, plan.actions.first()) {
|
||||
|
|
@ -453,6 +460,7 @@ fn execute_claimed(
|
|||
}
|
||||
_ => "ok".into(),
|
||||
};
|
||||
verification_phase.complete();
|
||||
|
||||
let launch = detect_launch(root, plan);
|
||||
|
||||
|
|
|
|||
|
|
@ -760,6 +760,8 @@ pub fn plan_general(
|
|||
requests
|
||||
.iter()
|
||||
.map(|request| {
|
||||
let phase =
|
||||
exec.progress_phase(&format!("Checking evidence for {}", request.describe()));
|
||||
let output = match constraint {
|
||||
Some(backend) => match constrain_action(request.clone(), backend) {
|
||||
Ok(action) => match actions::execute(exec, &action, None, root) {
|
||||
|
|
@ -773,6 +775,11 @@ pub fn plan_general(
|
|||
Err(e) => format!("investigation failed: {e}"),
|
||||
},
|
||||
};
|
||||
if !output.starts_with("investigation failed:")
|
||||
&& !output.starts_with("refused by the source constraint:")
|
||||
{
|
||||
phase.complete();
|
||||
}
|
||||
Evidence {
|
||||
request: request.describe(),
|
||||
output,
|
||||
|
|
@ -816,6 +823,7 @@ pub fn plan_general(
|
|||
let mut step_effects = Vec::new();
|
||||
|
||||
for act in &actions_list {
|
||||
let phase = exec.progress_phase(&format!("Checking effects for {}", act.describe()));
|
||||
let mut eff = actions::resolve_effects(exec, act, root).map_err(|e| {
|
||||
ExecError::operation(
|
||||
"service",
|
||||
|
|
@ -823,6 +831,7 @@ pub fn plan_general(
|
|||
format!("could not resolve effects for `{}`: {e}", act.describe()),
|
||||
)
|
||||
})?;
|
||||
phase.complete();
|
||||
// Normalize the stored digest so the per-step binding check sees a
|
||||
// digest that matches the contents.
|
||||
eff.recompute_digest();
|
||||
|
|
|
|||
|
|
@ -182,6 +182,16 @@ fn a_valid_model_plan_runs_through_the_connected_ai_path() {
|
|||
);
|
||||
let stdout = String::from_utf8_lossy(&out.stdout);
|
||||
assert!(stdout.contains("Assistant Plan"), "{stdout}");
|
||||
let stderr = String::from_utf8_lossy(&out.stderr);
|
||||
assert!(
|
||||
stderr.contains("Checking this system and its package sources"),
|
||||
"{stderr}"
|
||||
);
|
||||
assert!(stderr.contains("validating its answer"), "{stderr}");
|
||||
assert!(
|
||||
stderr.contains("Running the approved plan and verifying the result"),
|
||||
"{stderr}"
|
||||
);
|
||||
assert_eq!(stub.request_count(), 1, "a valid plan needs one turn");
|
||||
|
||||
// The bounded facts actually sent must not contain a personal path or a
|
||||
|
|
@ -192,6 +202,28 @@ fn a_valid_model_plan_runs_through_the_connected_ai_path() {
|
|||
assert!(!sent.contains("Bearer"), "a credential reached the model");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_informational_answer_reads_as_prose_without_an_approval_digest() {
|
||||
let root = tempfile::tempdir().expect("temp root");
|
||||
let stub = Stub::start(
|
||||
r#"{"version":1,"summary":"This system has a stable desktop and an encrypted root. Review the pending Portage updates before changing system packages.","actions":[],"rationale":[]}"#,
|
||||
);
|
||||
let out = sys_ask(root.path(), &stub.endpoint(), "how is this system?");
|
||||
assert!(
|
||||
out.status.success(),
|
||||
"{}",
|
||||
String::from_utf8_lossy(&out.stderr)
|
||||
);
|
||||
let stdout = String::from_utf8_lossy(&out.stdout);
|
||||
assert!(stdout.starts_with("Phoebus\n\n"), "{stdout}");
|
||||
assert!(stdout.contains("encrypted root"), "{stdout}");
|
||||
assert!(!stdout.contains("Approval digest"), "{stdout}");
|
||||
assert!(
|
||||
stdout.lines().all(|line| line.chars().count() <= 88),
|
||||
"{stdout}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_shell_action_from_the_model_fails_closed() {
|
||||
let root = tempfile::tempdir().expect("temp root");
|
||||
|
|
|
|||
|
|
@ -78,6 +78,10 @@ fn broker_allows_action_execution() {
|
|||
"stderr: {}",
|
||||
String::from_utf8_lossy(&out.stderr)
|
||||
);
|
||||
assert!(
|
||||
!String::from_utf8_lossy(&out.stderr).contains("Checking the exact effects"),
|
||||
"broker protocol must not emit human progress"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -99,6 +103,13 @@ fn read_only_history_succeeds_deterministically_with_legacy() {
|
|||
stdout.contains("no snapshot history") || stdout.contains("snapshots:"),
|
||||
"stdout: {stdout}"
|
||||
);
|
||||
let stderr = String::from_utf8_lossy(&out.stderr);
|
||||
assert!(stderr.contains("Checking the exact effects"), "{stderr}");
|
||||
assert!(
|
||||
stderr.contains("Running the action and checking its result"),
|
||||
"{stderr}"
|
||||
);
|
||||
assert!(stderr.contains("✓"), "{stderr}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue