Compare commits
No commits in common. "32a124e3f90de196b0a40741158cef2d7bcef1d6" and "d36b2fe5fe0df2433ad0b3d34fa66056f563146e" have entirely different histories.
32a124e3f9
...
d36b2fe5fe
10 changed files with 26 additions and 258 deletions
|
|
@ -7,16 +7,6 @@ Format: Keep a Changelog. Dates are UTC.
|
||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
### Changed
|
|
||||||
- **Installing Phoebus now requires an AI.** The installer refuses an install
|
|
||||||
with no provider unless the explicit break-glass `--no-ai` (alias `--legacy`,
|
|
||||||
or `PHOEBUS_NO_AI=1`) is used. A new `local` provider (Ollama/llama.cpp/
|
|
||||||
LM Studio) and `--ai-endpoint` support a model the user downloaded; no model
|
|
||||||
is shipped.
|
|
||||||
- Desktop installs now include `sys-apps/xdg-desktop-portal`,
|
|
||||||
`xdg-desktop-portal-gtk` and `xdg-desktop-portal-wlr`, so Flatpak and
|
|
||||||
Wayland apps get file choosers and screencast support.
|
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
- `sys` offline package commands: `sys install <name>`, `sys remove <name>`,
|
- `sys` offline package commands: `sys install <name>`, `sys remove <name>`,
|
||||||
`sys search <query>` (plus the `remove_package`/`search_packages` typed
|
`sys search <query>` (plus the `remove_package`/`search_packages` typed
|
||||||
|
|
|
||||||
|
|
@ -17,20 +17,17 @@ commit it. It should be short and current; use `git log` for detail.
|
||||||
|
|
||||||
## Next actions (in order)
|
## Next actions (in order)
|
||||||
|
|
||||||
1. **Nix packaging**: author a `sys-apps/nix` ebuild (Phoebus overlay) +
|
1. **Physical-seat desktop**: run `/usr/local/bin/phoebus-session` on a real VT
|
||||||
`nix-daemon.service`, wire it into the installer, and VM-verify. This is the
|
|
||||||
remaining piece of "Nix is built in"; it was deliberately not faked.
|
|
||||||
2. **Physical-seat desktop**: run `/usr/local/bin/phoebus-session` on a real VT
|
|
||||||
and check kitty, XWayland, the polkit agent, logout/reap and reboot
|
and check kitty, XWayland, the polkit agent, logout/reap and reboot
|
||||||
(`docs/DEVELOPMENT.md` -> "Physical VT / real-seat check").
|
(`docs/DEVELOPMENT.md` -> "Physical VT / real-seat check").
|
||||||
3. **Matching signed binhost**: the official Gentoo binhost is OpenRC/hardened,
|
2. **Matching signed binhost**: the official Gentoo binhost is OpenRC/hardened,
|
||||||
so systemd/desktop packages compile from source. Publish (or point at) a
|
so systemd/desktop packages compile from source. Publish (or point at) a
|
||||||
systemd/desktop binhost to raise binary reuse; verify with `emerge -pv`.
|
systemd/desktop binhost to raise binary reuse; verify with `emerge -pv`.
|
||||||
4. **Rollback gate**: implement Btrfs default-subvolume + ESP handling and pass
|
3. **Rollback gate**: implement Btrfs default-subvolume + ESP handling and pass
|
||||||
a detached-boot test before exposing `sys undo`.
|
a detached-boot test before exposing `sys undo`.
|
||||||
5. **Live AI provider call**: exercise DeepSeek/OpenAI/local with a real 0600
|
4. **Live AI provider call**: exercise DeepSeek/OpenAI with a real 0600 key
|
||||||
key file; the path is currently fixture-verified only.
|
file; the path is currently fixture-verified only.
|
||||||
6. **Desktop graphical login**: exercise a real logind seat.
|
5. **Desktop graphical login**: exercise a real logind seat.
|
||||||
|
|
||||||
## Known blockers / risks
|
## Known blockers / risks
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,8 +21,7 @@ more interesting. Status vocabulary: **Done**, **Partial**, **Next**, **Later**.
|
||||||
| 14 | ISO / release pipeline | Partial | manifest/verify/assemble-plan tooling; no scheduling/publish/smoke test |
|
| 14 | ISO / release pipeline | Partial | manifest/verify/assemble-plan tooling; no scheduling/publish/smoke test |
|
||||||
| 15 | Recovery environment | Later | recovery BLS entry generated; full recovery image not built |
|
| 15 | Recovery environment | Later | recovery BLS entry generated; full recovery image not built |
|
||||||
| — | Rust TUI | Partial | ratatui UI with plan/ERASE and AI provider selection; not yet the default on all paths |
|
| — | Rust TUI | Partial | ratatui UI with plan/ERASE and AI provider selection; not yet the default on all paths |
|
||||||
| — | AI-guided install optimization | Partial | DeepSeek/OpenAI/local providers, evidence-gated typed review, mandatory at install with `--no-ai` break-glass; fixture-verified, no live call |
|
| — | AI-guided install optimization | Partial | DeepSeek/OpenAI providers, evidence-gated typed review, TUI opt-in; fixture-verified, no live call |
|
||||||
| — | Nix as a built-in second lane | Next | `sys-apps/nix` Portage overlay + `nix-daemon`; installer wiring; not yet packaged |
|
|
||||||
| — | Git workflow + agent guide | Done | this `docs/` set, `.githooks/`, `scripts/` |
|
| — | Git workflow + agent guide | Done | this `docs/` set, `.githooks/`, `scripts/` |
|
||||||
|
|
||||||
## Immediate next steps
|
## Immediate next steps
|
||||||
|
|
|
||||||
|
|
@ -285,17 +285,9 @@ the remaining step; no time estimate is claimed beyond the recorded ~26 min.
|
||||||
## Debian-Live installer appliance (actual ISO)
|
## Debian-Live installer appliance (actual ISO)
|
||||||
|
|
||||||
An appliance ISO was built **without root** by `installer/live/build.sh`
|
An appliance ISO was built **without root** by `installer/live/build.sh`
|
||||||
(Debian-Live 13.7 standard base + `/phoebus` overlay). The full-install
|
(Debian-Live 13.7 standard base + `/phoebus` overlay), SHA-256
|
||||||
evidence below was recorded with build
|
|
||||||
`c0105bc9a282fddcbefab42baa577ea99843060f00fa45a75bcbc8358186bfd5`.
|
`c0105bc9a282fddcbefab42baa577ea99843060f00fa45a75bcbc8358186bfd5`.
|
||||||
|
|
||||||
The current build is
|
|
||||||
`fec8e312bfe641c423f2656970ae4271a1544b3a6107b407a8a29cb71f8850be`; it carries
|
|
||||||
the mandatory-AI install gate (`--no-ai`/`--legacy` break-glass), the `local`
|
|
||||||
model provider, and the desktop portals. It was **not** re-run through the full
|
|
||||||
install in this session (resource constraints); treat the earlier run as the
|
|
||||||
boot/install evidence and this as the current artifact.
|
|
||||||
|
|
||||||
Firmware boot (UEFI/OVMF, no `-kernel`; the ISO's own grub chain):
|
Firmware boot (UEFI/OVMF, no `-kernel`; the ISO's own grub chain):
|
||||||
|
|
||||||
- auto-boots the live system on the serial console;
|
- auto-boots the live system on the serial console;
|
||||||
|
|
|
||||||
|
|
@ -22,9 +22,6 @@ pub enum ProviderKind {
|
||||||
None,
|
None,
|
||||||
DeepSeek,
|
DeepSeek,
|
||||||
OpenAi,
|
OpenAi,
|
||||||
/// An OpenAI-compatible server the user runs locally (Ollama, llama.cpp,
|
|
||||||
/// LM Studio, ...). No model is shipped; the user downloads and serves one.
|
|
||||||
Local,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ProviderKind {
|
impl ProviderKind {
|
||||||
|
|
@ -33,7 +30,6 @@ impl ProviderKind {
|
||||||
ProviderKind::None => "none",
|
ProviderKind::None => "none",
|
||||||
ProviderKind::DeepSeek => "deepseek",
|
ProviderKind::DeepSeek => "deepseek",
|
||||||
ProviderKind::OpenAi => "openai",
|
ProviderKind::OpenAi => "openai",
|
||||||
ProviderKind::Local => "local",
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -43,21 +39,16 @@ impl ProviderKind {
|
||||||
"" | "none" | "no" | "off" | "without" => Some(ProviderKind::None),
|
"" | "none" | "no" | "off" | "without" => Some(ProviderKind::None),
|
||||||
"deepseek" => Some(ProviderKind::DeepSeek),
|
"deepseek" => Some(ProviderKind::DeepSeek),
|
||||||
"openai" | "chatgpt" | "gpt" => Some(ProviderKind::OpenAi),
|
"openai" | "chatgpt" | "gpt" => Some(ProviderKind::OpenAi),
|
||||||
"local" | "ollama" | "llama" | "llamacpp" | "llama.cpp" | "lmstudio" | "lm-studio" => {
|
|
||||||
Some(ProviderKind::Local)
|
|
||||||
}
|
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The default chat-completions endpoint. For `Local` this is the common
|
/// The chat-completions endpoint.
|
||||||
/// Ollama OpenAI-compatible address; `--ai-endpoint` overrides it.
|
|
||||||
pub fn endpoint(self) -> &'static str {
|
pub fn endpoint(self) -> &'static str {
|
||||||
match self {
|
match self {
|
||||||
ProviderKind::None => "",
|
ProviderKind::None => "",
|
||||||
ProviderKind::DeepSeek => "https://api.deepseek.com/chat/completions",
|
ProviderKind::DeepSeek => "https://api.deepseek.com/chat/completions",
|
||||||
ProviderKind::OpenAi => "https://api.openai.com/v1/chat/completions",
|
ProviderKind::OpenAi => "https://api.openai.com/v1/chat/completions",
|
||||||
ProviderKind::Local => "http://127.0.0.1:11434/v1/chat/completions",
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -66,14 +57,11 @@ impl ProviderKind {
|
||||||
ProviderKind::None => "",
|
ProviderKind::None => "",
|
||||||
ProviderKind::DeepSeek => "deepseek-chat",
|
ProviderKind::DeepSeek => "deepseek-chat",
|
||||||
ProviderKind::OpenAi => "gpt-4o-mini",
|
ProviderKind::OpenAi => "gpt-4o-mini",
|
||||||
ProviderKind::Local => "llama3.1",
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Only the hosted providers need an API key; a local server usually does
|
|
||||||
/// not, but `--ai-api-key-file` may still be supplied if it does.
|
|
||||||
pub fn requires_key(self) -> bool {
|
pub fn requires_key(self) -> bool {
|
||||||
matches!(self, ProviderKind::DeepSeek | ProviderKind::OpenAi)
|
!matches!(self, ProviderKind::None)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -339,33 +327,16 @@ pub fn complete_proposal(
|
||||||
model: &str,
|
model: &str,
|
||||||
facts: &SystemFacts,
|
facts: &SystemFacts,
|
||||||
transport: &dyn ModelTransport,
|
transport: &dyn ModelTransport,
|
||||||
) -> Result<AiProposal, AiError> {
|
|
||||||
complete_proposal_at(provider, provider.endpoint(), model, facts, transport)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// As `complete_proposal`, but with an explicit endpoint (`--ai-endpoint`), for
|
|
||||||
/// a self-hosted model on a non-default port.
|
|
||||||
pub fn complete_proposal_at(
|
|
||||||
provider: ProviderKind,
|
|
||||||
endpoint: &str,
|
|
||||||
model: &str,
|
|
||||||
facts: &SystemFacts,
|
|
||||||
transport: &dyn ModelTransport,
|
|
||||||
) -> Result<AiProposal, AiError> {
|
) -> Result<AiProposal, AiError> {
|
||||||
if provider == ProviderKind::None {
|
if provider == ProviderKind::None {
|
||||||
return Err(AiError::ProviderUnavailable(
|
return Err(AiError::ProviderUnavailable(
|
||||||
"no AI provider selected".into(),
|
"no AI provider selected".into(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
if endpoint.trim().is_empty() {
|
|
||||||
return Err(AiError::ProviderUnavailable(
|
|
||||||
"no provider endpoint configured".into(),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
facts.validate_no_forbidden()?;
|
facts.validate_no_forbidden()?;
|
||||||
let request = build_request(provider, model, facts);
|
let request = build_request(provider, model, facts);
|
||||||
let body = serde_json::to_string(&request)?;
|
let body = serde_json::to_string(&request)?;
|
||||||
let response = transport.send(provider, endpoint, &body)?;
|
let response = transport.send(provider, provider.endpoint(), &body)?;
|
||||||
let content = extract_content(&response)?;
|
let content = extract_content(&response)?;
|
||||||
parse_proposal(&content)
|
parse_proposal(&content)
|
||||||
}
|
}
|
||||||
|
|
@ -458,36 +429,12 @@ mod tests {
|
||||||
);
|
);
|
||||||
assert_eq!(ProviderKind::parse("continue without AI"), None);
|
assert_eq!(ProviderKind::parse("continue without AI"), None);
|
||||||
assert_eq!(ProviderKind::parse("none"), Some(ProviderKind::None));
|
assert_eq!(ProviderKind::parse("none"), Some(ProviderKind::None));
|
||||||
assert_eq!(ProviderKind::parse("ollama"), Some(ProviderKind::Local));
|
|
||||||
assert_eq!(ProviderKind::parse("Local"), Some(ProviderKind::Local));
|
|
||||||
assert!(ProviderKind::OpenAi.endpoint().starts_with("https://"));
|
assert!(ProviderKind::OpenAi.endpoint().starts_with("https://"));
|
||||||
assert!(ProviderKind::None.endpoint().is_empty());
|
assert!(ProviderKind::None.endpoint().is_empty());
|
||||||
assert!(ProviderKind::Local
|
|
||||||
.endpoint()
|
|
||||||
.starts_with("http://127.0.0.1"));
|
|
||||||
assert!(ProviderKind::DeepSeek.requires_key());
|
assert!(ProviderKind::DeepSeek.requires_key());
|
||||||
assert!(ProviderKind::OpenAi.requires_key());
|
|
||||||
// A self-hosted local server needs no key.
|
|
||||||
assert!(!ProviderKind::Local.requires_key());
|
|
||||||
assert!(!ProviderKind::None.requires_key());
|
assert!(!ProviderKind::None.requires_key());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn local_provider_uses_an_explicit_endpoint() {
|
|
||||||
let proposal = r#"{"version":1,"changes":[{"action":"set_flatpak","value":true}]}"#;
|
|
||||||
let transport = TestTransport::proposal(proposal);
|
|
||||||
let parsed = complete_proposal_at(
|
|
||||||
ProviderKind::Local,
|
|
||||||
"http://127.0.0.1:8080/v1/chat/completions",
|
|
||||||
"qwen2.5-coder",
|
|
||||||
&facts(),
|
|
||||||
&transport,
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
assert_eq!(parsed.changes.len(), 1);
|
|
||||||
assert!(complete_proposal_at(ProviderKind::Local, "", "", &facts(), &transport).is_err());
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn request_has_no_secret_and_pins_the_schema() {
|
fn request_has_no_secret_and_pins_the_schema() {
|
||||||
let request = build_request(ProviderKind::DeepSeek, "", &facts());
|
let request = build_request(ProviderKind::DeepSeek, "", &facts());
|
||||||
|
|
|
||||||
|
|
@ -58,11 +58,6 @@ pub fn desktop_packages(profile: DesktopProfile) -> Vec<&'static str> {
|
||||||
"net-misc/networkmanager",
|
"net-misc/networkmanager",
|
||||||
"sys-auth/polkit",
|
"sys-auth/polkit",
|
||||||
"gnome-extra/polkit-gnome",
|
"gnome-extra/polkit-gnome",
|
||||||
// Desktop portals: required by Flatpak (file chooser, screencast,
|
|
||||||
// screenshots) and expected by many Wayland apps.
|
|
||||||
"sys-apps/xdg-desktop-portal",
|
|
||||||
"sys-apps/xdg-desktop-portal-gtk",
|
|
||||||
"gui-libs/xdg-desktop-portal-wlr",
|
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
|
@ -658,15 +653,6 @@ mod tests {
|
||||||
assert!(text.contains("uki_generator=none"));
|
assert!(text.contains("uki_generator=none"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn desktop_includes_portals_for_flatpak_and_wayland() {
|
|
||||||
let pkgs = desktop_packages(DesktopProfile::Dwl);
|
|
||||||
assert!(pkgs.contains(&"sys-apps/xdg-desktop-portal"));
|
|
||||||
assert!(pkgs.contains(&"sys-apps/xdg-desktop-portal-gtk"));
|
|
||||||
assert!(pkgs.contains(&"gui-libs/xdg-desktop-portal-wlr"));
|
|
||||||
assert!(desktop_packages(DesktopProfile::None).is_empty());
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn desktop_none_has_no_x_use_block() {
|
fn desktop_none_has_no_x_use_block() {
|
||||||
let mut cfg = InstallConfig::default();
|
let mut cfg = InstallConfig::default();
|
||||||
|
|
|
||||||
|
|
@ -41,19 +41,14 @@ pub fn load_api_key(path: &Path) -> Result<SecretString> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A transport that talks to an OpenAI-compatible endpoint with curl.
|
/// A transport that talks to an OpenAI-compatible endpoint with curl.
|
||||||
///
|
|
||||||
/// The API key is optional: a self-hosted local model usually needs none, while
|
|
||||||
/// DeepSeek/OpenAI require one.
|
|
||||||
pub struct CurlTransport<'a> {
|
pub struct CurlTransport<'a> {
|
||||||
exec: &'a Exec,
|
exec: &'a Exec,
|
||||||
api_key: Option<SecretString>,
|
api_key: SecretString,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> CurlTransport<'a> {
|
impl<'a> CurlTransport<'a> {
|
||||||
pub fn new(exec: &'a Exec, api_key: Option<SecretString>) -> Self {
|
pub fn new(exec: &'a Exec, api_key: SecretString) -> Self {
|
||||||
if let Some(key) = &api_key {
|
exec.register_secret(&api_key);
|
||||||
exec.register_secret(key);
|
|
||||||
}
|
|
||||||
Self { exec, api_key }
|
Self { exec, api_key }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -77,16 +72,13 @@ impl ModelTransport for CurlTransport<'_> {
|
||||||
|
|
||||||
// curl reads this config from stdin, so Exec marks the stdin as hidden
|
// curl reads this config from stdin, so Exec marks the stdin as hidden
|
||||||
// and never logs it. The key is therefore absent from argv and logs.
|
// and never logs it. The key is therefore absent from argv and logs.
|
||||||
let auth = match &self.api_key {
|
|
||||||
Some(key) => format!("header = \"Authorization: Bearer {}\"\n", key.expose()),
|
|
||||||
None => String::new(),
|
|
||||||
};
|
|
||||||
let config = format!(
|
let config = format!(
|
||||||
"url = \"{url}\"\n\
|
"url = \"{url}\"\n\
|
||||||
header = \"Content-Type: application/json\"\n\
|
header = \"Content-Type: application/json\"\n\
|
||||||
{auth}\
|
header = \"Authorization: Bearer {key}\"\n\
|
||||||
data = \"@{path}\"\n\
|
data = \"@{path}\"\n\
|
||||||
silent\nshow-error\nfail-with-body\nmax-time = 120\n",
|
silent\nshow-error\nfail-with-body\nmax-time = 120\n",
|
||||||
|
key = self.api_key.expose(),
|
||||||
path = request.path().display()
|
path = request.path().display()
|
||||||
);
|
);
|
||||||
let spec = CommandSpec::new("ai", "query model", "curl")
|
let spec = CommandSpec::new("ai", "query model", "curl")
|
||||||
|
|
@ -140,7 +132,7 @@ mod tests {
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
let exec = make_exec(runner.clone());
|
let exec = make_exec(runner.clone());
|
||||||
let transport = CurlTransport::new(&exec, Some(SecretString::new("sk-secret-value")));
|
let transport = CurlTransport::new(&exec, SecretString::new("sk-secret-value"));
|
||||||
let out = transport
|
let out = transport
|
||||||
.send(
|
.send(
|
||||||
ProviderKind::OpenAi,
|
ProviderKind::OpenAi,
|
||||||
|
|
@ -163,32 +155,4 @@ mod tests {
|
||||||
// And the key is registered for redaction.
|
// And the key is registered for redaction.
|
||||||
assert_eq!(exec.redactor().redact("sk-secret-value"), "<redacted>");
|
assert_eq!(exec.redactor().redact("sk-secret-value"), "<redacted>");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn curl_transport_omits_auth_without_a_key() {
|
|
||||||
let runner = RecordingRunner::new();
|
|
||||||
runner.set_response(
|
|
||||||
"curl",
|
|
||||||
CommandOutput {
|
|
||||||
status: 0,
|
|
||||||
success: true,
|
|
||||||
stdout: b"{}".to_vec(),
|
|
||||||
stderr: Vec::new(),
|
|
||||||
duration: Duration::from_millis(1),
|
|
||||||
},
|
|
||||||
);
|
|
||||||
let exec = make_exec(runner.clone());
|
|
||||||
let transport = CurlTransport::new(&exec, None);
|
|
||||||
transport
|
|
||||||
.send(
|
|
||||||
ProviderKind::Local,
|
|
||||||
"http://127.0.0.1:11434/v1/chat/completions",
|
|
||||||
"{}",
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
let spec = &runner.recorded()[0];
|
|
||||||
let stdin = String::from_utf8(spec.stdin.clone().unwrap()).unwrap();
|
|
||||||
assert!(!stdin.contains("Authorization"));
|
|
||||||
assert!(stdin.contains("http://127.0.0.1"));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,7 @@
|
||||||
|
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use phoebus_ai::provider::{
|
use phoebus_ai::provider::{complete_proposal, ModelTransport, ProviderKind, SystemFacts};
|
||||||
complete_proposal, complete_proposal_at, ModelTransport, ProviderKind, SystemFacts,
|
|
||||||
};
|
|
||||||
use phoebus_ai::{parse_proposal, review, AiError, ReviewOutcome};
|
use phoebus_ai::{parse_proposal, review, AiError, ReviewOutcome};
|
||||||
use phoebus_core::InstallConfig;
|
use phoebus_core::InstallConfig;
|
||||||
|
|
||||||
|
|
@ -56,20 +54,6 @@ pub fn generate_and_review(
|
||||||
review(config, &proposal)
|
review(config, &proposal)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// As `generate_and_review`, with an explicit endpoint (a self-hosted local
|
|
||||||
/// model on a non-default address).
|
|
||||||
pub fn generate_and_review_at(
|
|
||||||
config: &mut InstallConfig,
|
|
||||||
facts: &SystemFacts,
|
|
||||||
provider: ProviderKind,
|
|
||||||
endpoint: &str,
|
|
||||||
model: &str,
|
|
||||||
transport: &dyn ModelTransport,
|
|
||||||
) -> Result<ReviewOutcome, AiError> {
|
|
||||||
let proposal = complete_proposal_at(provider, endpoint, model, facts, transport)?;
|
|
||||||
review(config, &proposal)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
|
||||||
|
|
@ -101,15 +101,6 @@ struct Cli {
|
||||||
/// Print the system facts that would be sent to the model, then exit.
|
/// Print the system facts that would be sent to the model, then exit.
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
ai_facts: bool,
|
ai_facts: bool,
|
||||||
|
|
||||||
/// Override the provider endpoint (self-hosted/local models).
|
|
||||||
#[arg(long, value_name = "URL")]
|
|
||||||
ai_endpoint: Option<String>,
|
|
||||||
|
|
||||||
/// Install without AI (break-glass for recovery/automation). Also
|
|
||||||
/// `--legacy` or `PHOEBUS_NO_AI=1`.
|
|
||||||
#[arg(long, alias = "legacy")]
|
|
||||||
no_ai: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct TerminalConfirm;
|
struct TerminalConfirm;
|
||||||
|
|
@ -154,33 +145,8 @@ fn resolve_provider(
|
||||||
.ai_provider
|
.ai_provider
|
||||||
.as_deref()
|
.as_deref()
|
||||||
.unwrap_or(config.ai.provider.as_str());
|
.unwrap_or(config.ai.provider.as_str());
|
||||||
ProviderKind::parse(raw).ok_or_else(|| {
|
ProviderKind::parse(raw)
|
||||||
format!("unknown AI provider `{raw}` (use deepseek, openai, local or none)").into()
|
.ok_or_else(|| format!("unknown AI provider `{raw}` (use deepseek, openai or none)").into())
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Whether the user explicitly asked for a deterministic, no-AI run.
|
|
||||||
fn no_ai_requested(cli: &Cli) -> bool {
|
|
||||||
cli.no_ai
|
|
||||||
|| std::env::var("PHOEBUS_NO_AI")
|
|
||||||
.map(|v| matches!(v.to_ascii_lowercase().as_str(), "1" | "yes" | "true"))
|
|
||||||
.unwrap_or(false)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Installing Phoebus requires a connected model. `--no-ai`/`--legacy` is the
|
|
||||||
/// explicit, documented break-glass for recovery or automation.
|
|
||||||
fn require_ai_for_install(
|
|
||||||
cli: &Cli,
|
|
||||||
provider: ProviderKind,
|
|
||||||
) -> std::result::Result<(), Box<dyn std::error::Error>> {
|
|
||||||
if no_ai_requested(cli) || provider != ProviderKind::None {
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
Err("installing Phoebus requires a connected AI model.\n\
|
|
||||||
Connect a provider (--ai-provider deepseek|openai|local, with \
|
|
||||||
--ai-api-key-file and/or --ai-endpoint), or pass --no-ai (alias \
|
|
||||||
--legacy) for a deterministic install."
|
|
||||||
.into())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Apply AI guidance to the configuration before the plan is shown or install
|
/// Apply AI guidance to the configuration before the plan is shown or install
|
||||||
|
|
@ -215,29 +181,17 @@ fn run_ai_guidance(
|
||||||
);
|
);
|
||||||
eprintln!("{}", facts.render());
|
eprintln!("{}", facts.render());
|
||||||
|
|
||||||
let endpoint = cli
|
let key_path = cli
|
||||||
.ai_endpoint
|
.ai_api_key_file
|
||||||
.clone()
|
.as_ref()
|
||||||
.unwrap_or_else(|| provider.endpoint().to_string());
|
.ok_or("--ai-api-key-file is required for a live AI provider")?;
|
||||||
let api_key = match (&cli.ai_api_key_file, provider.requires_key()) {
|
let api_key = phoebus_executor::ai::load_api_key(key_path)?;
|
||||||
(Some(path), _) => Some(phoebus_executor::ai::load_api_key(path)?),
|
|
||||||
(None, true) => {
|
|
||||||
return Err(format!(
|
|
||||||
"--ai-api-key-file is required for provider `{}`",
|
|
||||||
provider.as_str()
|
|
||||||
)
|
|
||||||
.into());
|
|
||||||
}
|
|
||||||
// A self-hosted local model usually needs no key.
|
|
||||||
(None, false) => None,
|
|
||||||
};
|
|
||||||
let model = cli.ai_model.clone().unwrap_or_default();
|
let model = cli.ai_model.clone().unwrap_or_default();
|
||||||
let transport = phoebus_executor::ai::CurlTransport::new(&installer.exec, api_key);
|
let transport = phoebus_executor::ai::CurlTransport::new(&installer.exec, api_key);
|
||||||
match phoebus_installer::ai_guide::generate_and_review_at(
|
match phoebus_installer::ai_guide::generate_and_review(
|
||||||
&mut installer.config,
|
&mut installer.config,
|
||||||
&facts,
|
&facts,
|
||||||
provider,
|
provider,
|
||||||
&endpoint,
|
|
||||||
&model,
|
&model,
|
||||||
&transport,
|
&transport,
|
||||||
) {
|
) {
|
||||||
|
|
@ -366,12 +320,6 @@ fn run() -> std::result::Result<ExitCode, Box<dyn std::error::Error>> {
|
||||||
}
|
}
|
||||||
run_ai_guidance(&cli, &mut installer)?;
|
run_ai_guidance(&cli, &mut installer)?;
|
||||||
|
|
||||||
// AI is mandatory to install; a deterministic no-AI run needs the explicit
|
|
||||||
// break-glass. Dry-run and plan modes are exempt.
|
|
||||||
if do_install && !installer.config.runtime.dry_run {
|
|
||||||
require_ai_for_install(&cli, resolve_provider(&cli, &installer.config)?)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(path) = &cli.save_config {
|
if let Some(path) = &cli.save_config {
|
||||||
std::fs::write(path, installer.config.to_toml_string()?)?;
|
std::fs::write(path, installer.config.to_toml_string()?)?;
|
||||||
println!("wrote {}", path.display());
|
println!("wrote {}", path.display());
|
||||||
|
|
|
||||||
|
|
@ -100,45 +100,6 @@ fn invalid_value_is_refused() {
|
||||||
assert!(!out.status.success());
|
assert!(!out.status.success());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn install_without_ai_is_refused() {
|
|
||||||
// Installing Phoebus requires a connected model.
|
|
||||||
let out = Command::new(bin())
|
|
||||||
.args(["--install", "--yes"])
|
|
||||||
.output()
|
|
||||||
.expect("run phoebus-installer");
|
|
||||||
assert!(!out.status.success());
|
|
||||||
let err = String::from_utf8_lossy(&out.stderr);
|
|
||||||
assert!(err.contains("requires a connected AI"), "{err}");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn no_ai_is_the_explicit_break_glass() {
|
|
||||||
// `--no-ai` passes the gate; the (incomplete) default config then stops
|
|
||||||
// before any disk is touched, with no AI requirement.
|
|
||||||
for flag in ["--no-ai", "--legacy"] {
|
|
||||||
let out = Command::new(bin())
|
|
||||||
.args(["--install", "--yes", flag])
|
|
||||||
.output()
|
|
||||||
.expect("run phoebus-installer");
|
|
||||||
let err = String::from_utf8_lossy(&out.stderr);
|
|
||||||
assert!(!err.contains("requires a connected AI"), "{flag}: {err}");
|
|
||||||
assert!(err.contains("configuration is incomplete"), "{flag}: {err}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn local_provider_needs_no_key_at_the_gate() {
|
|
||||||
// A local provider satisfies the gate without --no-ai (it fails later at
|
|
||||||
// the incomplete config, not at the AI gate).
|
|
||||||
let out = Command::new(bin())
|
|
||||||
.args(["--install", "--yes", "--ai", "--ai-provider", "local"])
|
|
||||||
.output()
|
|
||||||
.expect("run phoebus-installer");
|
|
||||||
let err = String::from_utf8_lossy(&out.stderr);
|
|
||||||
assert!(!err.contains("requires a connected AI"), "{err}");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn no_ai_fallback_still_prints_a_plan() {
|
fn no_ai_fallback_still_prints_a_plan() {
|
||||||
let out = Command::new(bin())
|
let out = Command::new(bin())
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue