diff --git a/Cargo.lock b/Cargo.lock index 51f7d227d4..438cd4ae01 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3844,7 +3844,6 @@ dependencies = [ "rig-core", "rocm-dash-collectors", "rocm-dash-core", - "rocm-deps", "serde", "serde_json", "thiserror 2.0.21", diff --git a/crates/rocm-dash-collectors/src/lemonade.rs b/crates/rocm-dash-collectors/src/lemonade.rs index ede9edd37f..65e58a0559 100644 --- a/crates/rocm-dash-collectors/src/lemonade.rs +++ b/crates/rocm-dash-collectors/src/lemonade.rs @@ -317,8 +317,8 @@ mod tests { assert!(collector.fetch_stats().await.is_err()); } - /// Integration-gated: scrape a REAL local Lemonade server (start it first via - /// `rocm skill run install-lemonade --apply`). Not run in CI. + /// Integration-gated: scrape a REAL local Lemonade server (install the engine + /// with `rocm engines install lemonade` and start it first). Not run in CI. #[tokio::test] #[ignore = "requires a running Lemonade server on :13305"] async fn live_lemonade_scrape_produces_instance() { diff --git a/crates/rocm-dash-tui/Cargo.toml b/crates/rocm-dash-tui/Cargo.toml index 21b4c5a6c1..23b7e54989 100644 --- a/crates/rocm-dash-tui/Cargo.toml +++ b/crates/rocm-dash-tui/Cargo.toml @@ -16,7 +16,6 @@ path = "src/lib.rs" [dependencies] rocm-dash-core = { path = "../rocm-dash-core" } -rocm-deps = { path = "../rocm-deps" } # Unified dashboard TUI base: ratatui 0.30 + crossterm 0.28. This is the only # ratatui in the workspace — the `rocm` binary no longer carries a (dead) 0.29 # dependency, so no second major is pulled in. Exact wrapped-row counts must @@ -36,7 +35,7 @@ color-eyre = "0.6" anyhow = "1" chrono = { version = "0.4", features = ["serde"] } thiserror = "2" -# Skill manifests are TOML (the external-team contribution contract). +# `app/chat.rs` serializes the chat endpoint back into the dashboard config. toml = "1.1" async-trait = "0.1" # Header types for the custom auth header some gateways require (e.g. APIM's diff --git a/crates/rocm-dash-tui/src/agent/clients.rs b/crates/rocm-dash-tui/src/agent/clients.rs index 0546b57144..949f8ce048 100644 --- a/crates/rocm-dash-tui/src/agent/clients.rs +++ b/crates/rocm-dash-tui/src/agent/clients.rs @@ -263,7 +263,7 @@ where let fired: FiredLog = Arc::new(Mutex::new(Vec::new())); let agent = apply_inference_params(agent, params); - // Telemetry + skill registry tools (shared registration site). + // Telemetry tools (shared registration site). let agent = register_telemetry_tools(agent, &snap, &fired); // Read-only ROCm machine-inspection tools (forward across the seam). let agent = register_rocm_read_tools(agent, executor, &fired); @@ -1703,11 +1703,11 @@ mod tests { // `run_agent_request_registers_tool_sets_and_enforces_turn_limit` below // asserts those tools are actually sent on the wire from that one site. // - // Telemetry/skill set: register_telemetry_tools registers exactly the + // Telemetry set: register_telemetry_tools registers exactly the // SKILL_NAMES tools (GpuStatus, ListInstances, BenchSummary, - // TokensPerWatt, ListSkills, SkillPlan). Pinning the size here means the - // telemetry registration can't silently diverge from the canonical set. - assert_eq!(SKILL_NAMES.len(), 6, "canonical telemetry/skill set size"); + // TokensPerWatt). Pinning the size here means the telemetry + // registration can't silently diverge from the canonical set. + assert_eq!(SKILL_NAMES.len(), 4, "canonical telemetry set size"); for n in SKILL_NAMES { assert!(!n.is_empty(), "empty telemetry/skill tool name"); // Telemetry tools are disjoint from both ROCm sets. @@ -1803,16 +1803,20 @@ mod tests { .iter() .map(|t| t.name.as_str()) .collect(); - for expected in SKILL_NAMES + // Exactly the canonical registry reaches the model: nothing registered + // outside the three name tables (the retired `list_skills` and + // `skill_plan` included), and nothing in them left unregistered. A new + // tool is added to its table in the same change, which keeps this true. + let expected_tool_names: std::collections::BTreeSet<&str> = SKILL_NAMES .iter() .chain(ROCM_READ_TOOL_NAMES.iter()) .chain(ROCM_MUTATING_TOOL_NAMES.iter()) - { - assert!( - sent_tool_names.contains(expected), - "registered tool {expected} missing from the wire request" - ); - } + .copied() + .collect(); + assert_eq!( + sent_tool_names, expected_tool_names, + "the tool names sent on the wire must equal the canonical registry" + ); // Sanity bound on the request count: enough to have tried every // scripted turn up to the limit, not an early bail-out or a runaway diff --git a/crates/rocm-dash-tui/src/agent/mod.rs b/crates/rocm-dash-tui/src/agent/mod.rs index 3198762347..496f93f97b 100644 --- a/crates/rocm-dash-tui/src/agent/mod.rs +++ b/crates/rocm-dash-tui/src/agent/mod.rs @@ -49,11 +49,10 @@ pub use tools::{ AutomationsRocmTool, BenchSummaryTool, BridgeSnapshotRocmTool, DoctorRocmTool, EnginesRocmTool, ExamineRocmTool, GpuSnapshotRocmTool, GpuStatusArgs, GpuStatusTool, InstallEngineRocmTool, InstallSdkDryRunRocmTool, InstallSdkRocmTool, LaunchServerRocmTool, ListInstancesTool, - ListSkillsTool, NaturalLanguagePlanRocmTool, NoArgs, PathExistsRocmTool, PortStatusRocmTool, + NaturalLanguagePlanRocmTool, NoArgs, PathExistsRocmTool, PortStatusRocmTool, ROCM_MUTATING_TOOL_NAMES, ROCM_READ_TOOL_NAMES, RocmCommandRocmTool, SKILL_NAMES, - ServiceLogsRocmTool, ServicesRocmTool, SkillPlanArgs, SkillPlanTool, StopServerRocmTool, - TokensPerWattTool, ToolError, UpdateCheckRocmTool, WatcherDisableRocmTool, - WatcherEnableRocmTool, + ServiceLogsRocmTool, ServicesRocmTool, StopServerRocmTool, TokensPerWattTool, ToolError, + UpdateCheckRocmTool, WatcherDisableRocmTool, WatcherEnableRocmTool, }; /// One-shot request budget. A hung backend becomes a timeout error turn, never diff --git a/crates/rocm-dash-tui/src/agent/tools.rs b/crates/rocm-dash-tui/src/agent/tools.rs index 0416d26b36..2fcf0b0ec4 100644 --- a/crates/rocm-dash-tui/src/agent/tools.rs +++ b/crates/rocm-dash-tui/src/agent/tools.rs @@ -178,90 +178,12 @@ impl Tool for TokensPerWattTool { } } -/// Read-only tool exposing the rocm-dash **skills** registry (auto-config / auto-install). -/// -/// The agent can list skills and fetch a skill's dry-run plan; -/// it never executes a skill (execution is `--apply`-gated in the CLI). -pub struct ListSkillsTool { - pub fired: FiredLog, -} - -impl Tool for ListSkillsTool { - const NAME: &'static str = "list_skills"; - type Error = ToolError; - type Args = NoArgs; - type Output = Value; - - async fn definition(&self, _prompt: String) -> ToolDefinition { - ToolDefinition { - name: Self::NAME.to_string(), - description: "List the available rocm-dash skills (auto-config / \ - auto-install helpers like install-lemonade and \ - auto-config-endpoint) the user can run." - .to_string(), - parameters: json!({ "type": "object", "properties": {} }), - } - } - - async fn call(&self, _args: Self::Args) -> Result { - record(&self.fired, Self::NAME); - let skills: Vec = crate::skills::builtin_skills() - .iter() - .map(|s| json!({ "name": s.name, "description": s.description })) - .collect(); - Ok(json!({ "skills": skills, "skill_count": skills.len() })) - } -} - -/// Read-only tool returning a skill's ordered dry-run plan (no execution). -pub struct SkillPlanTool { - pub fired: FiredLog, -} - -#[derive(Debug, Deserialize, Default)] -pub struct SkillPlanArgs { - pub name: String, -} - -impl Tool for SkillPlanTool { - const NAME: &'static str = "skill_plan"; - type Error = ToolError; - type Args = SkillPlanArgs; - type Output = Value; - - async fn definition(&self, _prompt: String) -> ToolDefinition { - ToolDefinition { - name: Self::NAME.to_string(), - description: "Show the ordered dry-run step plan for a named skill \ - WITHOUT executing it. Use after list_skills." - .to_string(), - parameters: json!({ - "type": "object", - "properties": { - "name": { "type": "string", "description": "Skill name, e.g. install-lemonade." } - }, - "required": ["name"] - }), - } - } - - async fn call(&self, args: Self::Args) -> Result { - record(&self.fired, Self::NAME); - match crate::skills::builtin_skill(&args.name) { - Some(m) => Ok(json!({ "name": m.name, "plan": crate::skills::build_plan(&m) })), - None => Ok(json!({ "error": format!("unknown skill: {}", args.name) })), - } - } -} - /// All Skill names, for definition/uniqueness checks and docs. -pub const SKILL_NAMES: [&str; 6] = [ +pub const SKILL_NAMES: [&str; 4] = [ GpuStatusTool::NAME, ListInstancesTool::NAME, BenchSummaryTool::NAME, TokensPerWattTool::NAME, - ListSkillsTool::NAME, - SkillPlanTool::NAME, ]; // --------------------------------------------------------------------------- @@ -708,17 +630,15 @@ where }) } -/// Register the telemetry + skill registry tools (GpuStatus, ListInstances, -/// BenchSummary, TokensPerWatt — snapshot-backed; ListSkills, SkillPlan — -/// read-only registry) on a fresh Rig `AgentBuilder`, cloning the snapshot + -/// shared `fired` log into each. Kept generic over the builder's completion -/// model + preamble so all three backends (RigAgentClient, ChatGptAgentClient, -/// AnthropicAgentClient) reuse one registration site (DRY — the tool list lives -/// in exactly one place, mirroring [`register_rocm_read_tools`]). Takes the base -/// builder (`NoToolConfig`) and returns it in `WithBuilderTools` because the -/// first `.tool()` transitions the type-state; the ROCm read/mutating -/// registrations chain after it. Note: ListSkillsTool/SkillPlanTool take only -/// `fired`; the other four take `snap` + `fired`. +/// Register the telemetry tools (GpuStatus, ListInstances, BenchSummary, +/// TokensPerWatt — all snapshot-backed) on a fresh Rig `AgentBuilder`, cloning +/// the snapshot + shared `fired` log into each. Kept generic over the builder's +/// completion model + preamble so all three backends (RigAgentClient, +/// ChatGptAgentClient, AnthropicAgentClient) reuse one registration site (DRY — +/// the tool list lives in exactly one place, mirroring +/// [`register_rocm_read_tools`]). Takes the base builder (`NoToolConfig`) and +/// returns it in `WithBuilderTools` because the first `.tool()` transitions the +/// type-state; the ROCm read/mutating registrations chain after it. pub(super) fn register_telemetry_tools( builder: rig::agent::AgentBuilder, snap: &Arc, @@ -745,13 +665,6 @@ where snap: snap.clone(), fired: fired.clone(), }) - // Skills registry tools (read-only: list + dry-run plan; never execute). - .tool(ListSkillsTool { - fired: fired.clone(), - }) - .tool(SkillPlanTool { - fired: fired.clone(), - }) } /// Register every read-only ROCm tool on a Rig `AgentBuilder`, cloning the @@ -759,8 +672,8 @@ where /// builder's completion model + preamble so all three backends (the /// OpenAI-compatible, ChatGPT, and Anthropic paths) reuse one registration /// site (DRY — the tool list lives in exactly one place). The builder is -/// already in the `WithBuilderTools` state because the telemetry/skill tools -/// were registered first. +/// already in the `WithBuilderTools` state because the telemetry tools were +/// registered first. pub(super) fn register_rocm_read_tools( builder: rig::agent::AgentBuilder, executor: Option<&SharedRocmToolExecutor>, @@ -902,53 +815,20 @@ mod tests { } } - #[tokio::test] - async fn skill_tools_expose_both_demo_skills() { - // list_skills returns both demo skills (the agent can see them). - let list = ListSkillsTool { - fired: Arc::new(Mutex::new(Vec::new())), - }; - let def = list.definition(String::new()).await; - assert_eq!(def.name, "list_skills"); - let out = list.call(NoArgs::default()).await.expect("list ok"); - let names: Vec = out["skills"] - .as_array() - .unwrap() - .iter() - .map(|s| s["name"].as_str().unwrap().to_string()) - .collect(); - assert!(names.contains(&"install-lemonade".to_string())); - assert!(names.contains(&"auto-config-endpoint".to_string())); - - // skill_plan returns the ordered dry-run plan for a named skill. - let plan_tool = SkillPlanTool { - fired: Arc::new(Mutex::new(Vec::new())), - }; - let out = plan_tool - .call(SkillPlanArgs { - name: "install-lemonade".to_string(), - }) - .await - .expect("plan ok"); - let plan = out["plan"].as_array().unwrap(); - assert!( - plan.iter() - .any(|l| l.as_str().unwrap().contains("lemonade-sdk")) - ); - // Unknown skill → graceful error object, not a panic. - let miss = plan_tool - .call(SkillPlanArgs { - name: "nope".to_string(), - }) - .await - .unwrap(); - assert!(miss["error"].is_string()); - } - #[test] - fn skill_tool_names_registered_in_skill_names() { - assert!(SKILL_NAMES.contains(&"list_skills")); - assert!(SKILL_NAMES.contains(&"skill_plan")); + fn retired_skill_registry_tools_are_not_advertised() { + // `list_skills` / `skill_plan` described install steps (a GitHub + // releases download plus a `tar` extraction) that are not how the product + // installs an engine, and no executor ever applied their plans. They + // must not come back in any tool set the model is offered. + for gone in ["list_skills", "skill_plan"] { + assert!(!SKILL_NAMES.contains(&gone), "{gone} is retired"); + assert!(!ROCM_READ_TOOL_NAMES.contains(&gone), "{gone} is retired"); + assert!( + !ROCM_MUTATING_TOOL_NAMES.contains(&gone), + "{gone} is retired" + ); + } } /// Minimal executor that echoes a fixed JSON value for any tool call. diff --git a/crates/rocm-dash-tui/src/lib.rs b/crates/rocm-dash-tui/src/lib.rs index bcf5eca57d..cd56d4ed31 100644 --- a/crates/rocm-dash-tui/src/lib.rs +++ b/crates/rocm-dash-tui/src/lib.rs @@ -16,7 +16,6 @@ pub mod llm; pub mod reconnect; pub mod registry_probe; pub mod replay; -pub mod skills; pub mod tool_exec; pub mod transport; pub mod ui; diff --git a/crates/rocm-dash-tui/src/llm.rs b/crates/rocm-dash-tui/src/llm.rs index 9c9958daa0..f83f85e687 100644 --- a/crates/rocm-dash-tui/src/llm.rs +++ b/crates/rocm-dash-tui/src/llm.rs @@ -217,18 +217,26 @@ where }) } -const LOCAL_ENDPOINT_CANDIDATES: [&str; 3] = [ - crate::skills::LEMONADE_ENDPOINT, - crate::skills::VLLM_ENDPOINT, - crate::skills::ROCM_SERVE_ENDPOINT, -]; +/// Lemonade's default OpenAI-compatible endpoint. +const LEMONADE_ENDPOINT: &str = "http://localhost:13305/v1"; +/// vLLM's conventional OpenAI-compatible endpoint. +const VLLM_ENDPOINT: &str = "http://localhost:8000/v1"; +/// `rocm serve`'s (non-managed) default vLLM endpoint. +/// +/// The port mirrors `rocm_core::DEFAULT_LOCAL_PORT`; duplicated as a literal +/// because this crate deliberately carries no `rocm-core` dependency (see +/// `AppState::model_recipes`). +const ROCM_SERVE_ENDPOINT: &str = "http://localhost:11435/v1"; + +const LOCAL_ENDPOINT_CANDIDATES: [&str; 3] = + [LEMONADE_ENDPOINT, VLLM_ENDPOINT, ROCM_SERVE_ENDPOINT]; /// Probe the known local serving endpoints (Lemonade, vLLM, then `rocm /// serve`'s non-managed default) concurrently and return the highest-priority /// one that answered. /// /// Used by the TUI's in-app "detect a local engine" action, and by chat -/// startup, so the user need not run the CLI skill first. +/// startup, so the user need not configure an endpoint first. pub fn detect_local_endpoint() -> Option<&'static str> { probe_first_reachable(&LOCAL_ENDPOINT_CANDIDATES, probe_endpoint) } @@ -539,11 +547,7 @@ mod tests { fn local_endpoint_candidates_preserve_supported_order() { assert_eq!( LOCAL_ENDPOINT_CANDIDATES, - [ - crate::skills::LEMONADE_ENDPOINT, - crate::skills::VLLM_ENDPOINT, - crate::skills::ROCM_SERVE_ENDPOINT, - ] + [LEMONADE_ENDPOINT, VLLM_ENDPOINT, ROCM_SERVE_ENDPOINT] ); } } diff --git a/crates/rocm-dash-tui/src/skills.rs b/crates/rocm-dash-tui/src/skills.rs deleted file mode 100644 index 44349d0c6d..0000000000 --- a/crates/rocm-dash-tui/src/skills.rs +++ /dev/null @@ -1,632 +0,0 @@ -// Copyright © Advanced Micro Devices, Inc., or its affiliates. -// -// SPDX-License-Identifier: MIT - -//! Skills — declarative manifest + plan model for rocm-dash's auto-config / -//! auto-install mechanism. -//! -//! A **skill** is a TOML manifest (the external-team contribution contract): -//! `name`, `description`, optional `requires`, optional `detect` (how to tell if -//! it's already satisfied), and an ordered list of typed `steps`. This module is -//! the pure model: parse + validate + build an ordered plan + the -//! detect→config mapping for `auto-config-endpoint`. It has **no rig/reqwest** -//! dependency (the agent-tool wrappers live in `agent/tools.rs`); execution + I/O live -//! in the `rocm` binary's `skills_cmd`. - -use serde::{Deserialize, Serialize}; - -/// Lemonade's default OpenAI-compatible endpoint + port. -pub const LEMONADE_PORT: u16 = 13305; -pub const LEMONADE_ENDPOINT: &str = "http://localhost:13305/v1"; -/// vLLM's conventional OpenAI-compatible endpoint + port. -pub const VLLM_PORT: u16 = 8000; -pub const VLLM_ENDPOINT: &str = "http://localhost:8000/v1"; -/// `rocm serve`'s (non-managed) default vLLM port. -/// -/// Mirrors `rocm_core::DEFAULT_LOCAL_PORT`; duplicated as a literal because -/// this crate deliberately carries no `rocm-core` dependency (see -/// `AppState::model_recipes`). -pub const ROCM_SERVE_PORT: u16 = 11_435; -pub const ROCM_SERVE_ENDPOINT: &str = "http://localhost:11435/v1"; - -/// One typed step in a skill manifest. Tagged by `type` in TOML. -#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] -#[serde(tag = "type", rename_all = "snake_case")] -pub enum Step { - /// A read-only idempotency/health check command. - Check { command: String }, - /// Run a command with args (the side-effecting step). - Run { - cmd: String, - #[serde(default)] - args: Vec, - }, - /// Download a file to a destination. - Download { url: String, dest: String }, - /// Write a key into the rocm-dash config. - WriteConfig { key: String, value: String }, -} - -impl Step { - /// One-line, human-readable rendering for a plan. - pub fn describe(&self) -> String { - match self { - Self::Check { command } => format!("check: {command}"), - Self::Run { cmd, args } => format!("run: {cmd} {}", args.join(" ")) - .trim_end() - .to_string(), - Self::Download { url, dest } => format!("download: {url} -> {dest}"), - Self::WriteConfig { key, value } => format!("write-config: {key} = {value}"), - } - } -} - -/// How to detect whether a skill is already satisfied. -#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] -pub struct DetectSpec { - pub kind: DetectKind, - pub target: String, -} - -#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] -#[serde(rename_all = "snake_case")] -pub enum DetectKind { - /// `target` is a binary expected on PATH. - Binary, - /// `target` is an endpoint expected to be reachable. - Endpoint, -} - -/// A parsed, validated skill manifest. -#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] -pub struct SkillManifest { - pub name: String, - pub description: String, - #[serde(default)] - pub requires: Vec, - #[serde(default)] - pub detect: Option, - pub steps: Vec, -} - -/// Skill loading/validation errors. String-only at the boundary; never panics. -#[derive(Debug, thiserror::Error, PartialEq, Eq)] -pub enum SkillError { - #[error("skill manifest parse error: {0}")] - Parse(String), - #[error("skill manifest invalid: {0}")] - Invalid(String), - #[error("unknown skill: {0}")] - Unknown(String), -} - -/// Parse + validate a TOML skill manifest. Clear errors, never panics. -pub fn parse_manifest(toml_str: &str) -> Result { - let manifest: SkillManifest = - toml::from_str(toml_str).map_err(|e| SkillError::Parse(e.to_string()))?; - validate(&manifest)?; - Ok(manifest) -} - -fn validate(m: &SkillManifest) -> Result<(), SkillError> { - if m.name.trim().is_empty() { - return Err(SkillError::Invalid("name must not be empty".to_string())); - } - if m.description.trim().is_empty() { - return Err(SkillError::Invalid( - "description must not be empty".to_string(), - )); - } - if m.steps.is_empty() { - return Err(SkillError::Invalid("steps must not be empty".to_string())); - } - Ok(()) -} - -/// Build an ordered, human-readable plan (the dry-run output). Pure. -pub fn build_plan(m: &SkillManifest) -> Vec { - m.steps - .iter() - .enumerate() - .map(|(i, s)| format!("{}. {}", i + 1, s.describe())) - .collect() -} - -// --------------------------------------------------------------------------- -// Built-in skills (compiled in). External teams can drop additional `.toml` -// manifests in the user skills dir; discovery merges them in (in the binary). -// --------------------------------------------------------------------------- - -/// install-lemonade: install AMD's Lemonade local LLM server from the official **embeddable SDK** release. -/// -/// Installs the `lemond` server + `lemonade` CLI, not pip. -/// The real apply path is special-cased + `--apply`-gated in the binary -/// (`apply_install_lemonade`): it queries the latest GitHub release, picks the -/// per-OS embeddable archive, downloads + extracts it into a rocm-owned dir, and -/// forces port 13305. `--dry-run` prints this plan only. The steps below are the -/// human-readable preview of that flow (the executor resolves the concrete OS/ -/// version/URL at apply time). No Python, no pip. -pub const INSTALL_LEMONADE_TOML: &str = r#" -name = "install-lemonade" -description = "Install Lemonade — AMD's local OpenAI-compatible LLM server — from the official embeddable SDK release (lemond server, no pip)." - -[detect] -kind = "endpoint" -target = "http://localhost:13305/v1" - -[[steps]] -type = "check" -command = "probe http://localhost:13305/v1 (skip if Lemonade already running)" - -[[steps]] -type = "run" -cmd = "curl" -args = ["-fsSL", "https://api.github.com/repos/lemonade-sdk/lemonade/releases/latest"] - -[[steps]] -type = "run" -cmd = "tar" -args = ["-xf", "lemonade-embeddable--.{tar.gz|zip}", "-C", "~/.local/share/rocm-dash/lemonade//"] - -[[steps]] -type = "write_config" -key = "default_engine" -value = "lemonade" -"#; - -/// auto-config-endpoint: detect a running local LLM endpoint (Lemonade/vLLM) and set `default_engine` for `serve`. -/// -/// Chat keeps the user's configured backend -/// (e.g. the LLM gateway); `tui.chat_url` is filled only when it is unset. -pub const AUTO_CONFIG_ENDPOINT_TOML: &str = r#" -name = "auto-config-endpoint" -description = "Detect a running local LLM endpoint (Lemonade/vLLM) and set default_engine for serve. Chat keeps your configured backend; chat_url is set only when unset." - -[detect] -kind = "endpoint" -target = "http://localhost:13305/v1" - -[[steps]] -type = "check" -command = "probe http://localhost:13305/v1 (Lemonade) then http://localhost:8000/v1 (vLLM)" - -[[steps]] -type = "write_config" -key = "default_engine" -value = "" - -[[steps]] -type = "write_config" -key = "tui.chat_url" -value = " (ONLY if tui.chat_url is unset; an existing chat backend is preserved)" -"#; - -/// The compiled-in skills. Malformed builtins are skipped (never panic) — they -/// are covered by tests so this stays exhaustive in practice. -pub fn builtin_skills() -> Vec { - [INSTALL_LEMONADE_TOML, AUTO_CONFIG_ENDPOINT_TOML] - .iter() - .filter_map(|t| parse_manifest(t).ok()) - .collect() -} - -/// Look up a built-in skill by name. -pub fn builtin_skill(name: &str) -> Option { - builtin_skills().into_iter().find(|s| s.name == name) -} - -// --------------------------------------------------------------------------- -// auto-config-endpoint: pure detect → config mapping. -// --------------------------------------------------------------------------- - -/// The config change `auto-config-endpoint` would apply for a detected endpoint. -#[derive(Debug, Clone, PartialEq, Eq)] -pub struct ConfigChange { - pub chat_url: String, - pub default_engine: String, -} - -/// Map a detected endpoint URL to the exact config change. Pure — no I/O. -/// `None` when nothing was detected. The engine is inferred from the port -/// (Lemonade 13305, vLLM 8000), defaulting to `local`. -pub fn auto_config_change(detected_endpoint: Option<&str>) -> Option { - let endpoint = detected_endpoint?; - let default_engine = if endpoint.contains(&LEMONADE_PORT.to_string()) { - "lemonade" - } else if endpoint.contains(&VLLM_PORT.to_string()) { - "vllm" - } else { - "local" - }; - Some(ConfigChange { - chat_url: endpoint.to_string(), - default_engine: default_engine.to_string(), - }) -} - -// --------------------------------------------------------------------------- -// Embeddable Lemonade SDK — pure asset selection. -// -// Lemonade is installed from the official **embeddable** release archives -// (`lemonade-embeddable--.{tar.gz|zip}`) published on GitHub, not -// from pip. These functions are PURE (no network/disk): the executor in the -// `rocm` binary does the curl/tar I/O and calls these to decide *what* to fetch. -// --------------------------------------------------------------------------- - -/// GitHub repo that publishes the Lemonade embeddable archives. -pub use rocm_deps::LEMONADE_GITHUB_REPO; - -/// Embeddable version used as the offline fallback when the GitHub releases API -/// is unreachable. -/// -/// This is the same pin the `lemonade` engine adapter installs, resolved from -/// `runtime-deps.toml` rather than restated here — the two used to be separate -/// constants and silently drifted five minor versions apart. -#[must_use] -pub fn lemonade_embeddable_fallback_version() -> String { - rocm_deps::LEMONADE_VERSION.to_owned() -} - -/// A selected embeddable archive for a host triple — enough to download, extract, -/// and locate the server binary. Pure data; no I/O. -#[derive(Debug, Clone, PartialEq, Eq)] -pub struct EmbeddableArtifact { - /// Version without a leading `v`, e.g. `11.5.1`. - pub version: String, - /// The archive's `browser_download_url`. - pub url: String, - /// The archive file name, e.g. `lemonade-embeddable-11.5.1-ubuntu-x64.tar.gz`. - pub archive_name: String, - /// The unpacked server executable name (`lemond` / `lemond.exe`). - pub server_bin: String, -} - -/// Map a host (os, arch) — `std::env::consts::{OS, ARCH}` values — to the -/// embeddable asset's `` token + archive extension. `None` for an -/// unsupported triple (only these three are supported here; the release also -/// ships `ubuntu-arm64`, which we do not select). -fn embeddable_os_arch(os: &str, arch: &str) -> Option<(&'static str, &'static str)> { - match (os, arch) { - ("linux", "x86_64") => Some(("ubuntu-x64", "tar.gz")), - ("windows", "x86_64") => Some(("windows-x64", "zip")), - ("macos", "aarch64") => Some(("macos-arm64", "tar.gz")), - _ => None, - } -} - -/// The unpacked server executable name for an OS. -fn server_bin_for(os: &str) -> &'static str { - if os == "windows" { - "lemond.exe" - } else { - "lemond" - } -} - -/// Strip a leading `v` from a release tag (`v11.5.1` → `11.5.1`). -fn strip_v(tag: &str) -> &str { - rocm_deps::strip_v(tag) -} - -/// PURE: build the canonical embeddable artifact for `(os, arch, version)` with no -/// network — the offline-fallback path. `None` for an unsupported triple. -pub fn embeddable_artifact(os: &str, arch: &str, version: &str) -> Option { - let (os_arch, ext) = embeddable_os_arch(os, arch)?; - let ver = strip_v(version); - let archive_name = rocm_deps::lemonade_archive_name(ver, os_arch, ext); - let url = rocm_deps::lemonade_download_url(ver, &archive_name); - Some(EmbeddableArtifact { - version: ver.to_string(), - url, - archive_name, - server_bin: server_bin_for(os).to_string(), - }) -} - -/// PURE: pick the embeddable asset from a GitHub `releases/latest` JSON body for the host `(os, arch)`. -/// -/// Reads `tag_name` + `assets[].{name, browser_download_url}` -/// and matches the `lemonade-embeddable-*-.` asset, skipping the -/// `.pkg`/`.rpm`/`.msi` decoys. Returns `None` for an unsupported triple, malformed -/// JSON, or a missing asset/url. Never panics. The release publishes no checksum -/// asset, so integrity rests on TLS + the official-org URL (see recon note). -pub fn pick_embeddable_asset( - release_json: &str, - os: &str, - arch: &str, -) -> Option { - let (os_arch, ext) = embeddable_os_arch(os, arch)?; - let value: serde_json::Value = serde_json::from_str(release_json).ok()?; - let obj = value.as_object()?; - let tag = obj.get("tag_name")?.as_str()?; - let version = strip_v(tag).to_string(); - let suffix = format!("-{os_arch}.{ext}"); - let assets = obj.get("assets")?.as_array()?; - for asset in assets { - let Some(name) = asset.get("name").and_then(|n| n.as_str()) else { - continue; - }; - if name.starts_with("lemonade-embeddable-") && name.ends_with(&suffix) { - let url = asset - .get("browser_download_url") - .and_then(|u| u.as_str()) - .unwrap_or_default(); - if url.is_empty() { - continue; - } - return Some(EmbeddableArtifact { - version, - url: url.to_string(), - archive_name: name.to_string(), - server_bin: server_bin_for(os).to_string(), - }); - } - } - None -} - -/// The config `auto-config-endpoint` would actually apply, after the -/// chat-precedence policy is taken into account. Either field being `None` means -/// "leave it unchanged". -#[derive(Debug, Clone, PartialEq, Eq, Default)] -pub struct AutoConfigPlan { - /// New `tui.chat_url`, or `None` to leave the existing one untouched. - pub set_chat_url: Option, - /// New `default_engine`, or `None` when nothing was detected. - pub set_default_engine: Option, - /// A local endpoint was detected but `chat_url` was deliberately left alone - /// because a chat backend is already configured (drives user messaging). - pub kept_existing_chat: bool, -} - -impl AutoConfigPlan { - /// True when applying this plan would write nothing. - pub const fn is_noop(&self) -> bool { - self.set_chat_url.is_none() && self.set_default_engine.is_none() - } -} - -/// Decide the config change for `auto-config-endpoint`, honoring chat precedence. -/// -/// Policy (see the chat-endpoint design notes): the chat backend defaults to the -/// user's configured endpoint — typically the LLM gateway — and is **never** -/// overwritten by local detection. Running a local engine is a `serve` concern, -/// not a reason to hijack the chatbot. Therefore: -/// - `default_engine` always follows the detected local engine (for `serve`). -/// - `chat_url` is filled **only when no chat backend is configured yet**; an -/// existing `chat_url` is preserved (`kept_existing_chat = true`). -/// -/// To point chat at a local engine, the user sets `tui.chat_url` explicitly — -/// detection will not do it for them. -pub fn auto_config_plan( - detected_endpoint: Option<&str>, - chat_url_configured: bool, -) -> AutoConfigPlan { - match auto_config_change(detected_endpoint) { - None => AutoConfigPlan::default(), - Some(change) => AutoConfigPlan { - set_chat_url: (!chat_url_configured).then_some(change.chat_url), - set_default_engine: Some(change.default_engine), - kept_existing_chat: chat_url_configured, - }, - } -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn parse_valid_manifest_builds_ordered_plan() { - let m = parse_manifest(INSTALL_LEMONADE_TOML).expect("valid manifest"); - assert_eq!(m.name, "install-lemonade"); - // Embeddable install needs no Python/pip toolchain. - assert!(m.requires.is_empty(), "no python3/pip requires"); - // Detection is now endpoint-based (the unpacked server answering on :13305), - // not a `lemonade` binary on PATH. - assert!(matches!( - m.detect, - Some(DetectSpec { - kind: DetectKind::Endpoint, - .. - }) - )); - let plan = build_plan(&m); - assert!(plan[0].starts_with("1. check:")); - // The plan describes the embeddable flow, never pip. - assert!(plan.iter().any(|l| l.contains("releases/latest"))); - assert!(plan.iter().any(|l| l.contains("lemonade-embeddable-"))); - // Guard the pivot: ban the deprecated `pip install lemonade-sdk` command. - // NB: the GitHub *org* is literally `lemonade-sdk/lemonade` (the URL we now - // download from), so a bare `lemonade-sdk` substring is legitimate — only - // the `pip install` invocation is forbidden. - assert!( - !INSTALL_LEMONADE_TOML.contains("pip install") - && !INSTALL_LEMONADE_TOML.contains(r#"cmd = "pip""#), - "install-lemonade TOML must not invoke pip" - ); - } - - // The captured real `releases/latest` body (Phase 1 fixture). - const RELEASE_FIXTURE: &str = include_str!("../tests/fixtures/lemonade_release_latest.json"); - - #[test] - fn pick_embeddable_asset_selects_per_triple() { - let linux = pick_embeddable_asset(RELEASE_FIXTURE, "linux", "x86_64").expect("linux"); - assert_eq!( - linux.archive_name, - "lemonade-embeddable-10.6.0-ubuntu-x64.tar.gz" - ); - assert_eq!(linux.version, "10.6.0"); - assert_eq!(linux.server_bin, "lemond"); - assert!( - linux - .url - .starts_with("https://github.com/lemonade-sdk/lemonade/releases/download/v10.6.0/") - ); - - let win = pick_embeddable_asset(RELEASE_FIXTURE, "windows", "x86_64").expect("windows"); - assert_eq!( - win.archive_name, - "lemonade-embeddable-10.6.0-windows-x64.zip" - ); - assert_eq!(win.server_bin, "lemond.exe"); - - let mac = pick_embeddable_asset(RELEASE_FIXTURE, "macos", "aarch64").expect("macos"); - assert_eq!( - mac.archive_name, - "lemonade-embeddable-10.6.0-macos-arm64.tar.gz" - ); - assert_eq!(mac.server_bin, "lemond"); - } - - #[test] - fn pick_embeddable_asset_none_for_unsupported_triple() { - // Release ships only ubuntu-x64 / windows-x64 / macos-arm64. - assert!(pick_embeddable_asset(RELEASE_FIXTURE, "linux", "aarch64").is_none()); - assert!(pick_embeddable_asset(RELEASE_FIXTURE, "freebsd", "x86_64").is_none()); - } - - #[test] - fn pick_embeddable_asset_malformed_json_is_none_not_panic() { - for body in ["", "not json", "{}", "[1,2,3]", r#"{"tag_name":"v10.6.0"}"#] { - assert!( - pick_embeddable_asset(body, "linux", "x86_64").is_none(), - "body {body:?} must yield None" - ); - } - } - - #[test] - fn embeddable_artifact_builds_canonical_urls() { - let a = embeddable_artifact("linux", "x86_64", "10.6.0").expect("linux"); - assert_eq!( - a.url, - "https://github.com/lemonade-sdk/lemonade/releases/download/v10.6.0/lemonade-embeddable-10.6.0-ubuntu-x64.tar.gz" - ); - // Tolerates a leading `v` on the version input. - let b = embeddable_artifact("windows", "x86_64", "v10.6.0").expect("windows"); - assert_eq!( - b.url, - "https://github.com/lemonade-sdk/lemonade/releases/download/v10.6.0/lemonade-embeddable-10.6.0-windows-x64.zip" - ); - assert_eq!(b.server_bin, "lemond.exe"); - // Unsupported triple → None. - assert!(embeddable_artifact("linux", "aarch64", "10.6.0").is_none()); - } - - /// The offline fallback and the version the `lemonade` engine adapter - /// installs must never disagree. They cannot: both come from the single - /// `runtime-deps.toml` pin, and this pins that down against a regression - /// that reintroduces a second constant. - #[test] - fn fallback_version_is_the_single_pinned_version() { - let fallback = lemonade_embeddable_fallback_version(); - assert_eq!(fallback, rocm_deps::LEMONADE_VERSION); - let artifact = embeddable_artifact("linux", "x86_64", &fallback).expect("linux"); - assert_eq!(artifact.version, fallback); - assert_eq!( - artifact.archive_name, - rocm_deps::lemonade_archive_name(&fallback, "ubuntu-x64", "tar.gz") - ); - assert!( - artifact.url.contains(&format!("/download/v{fallback}/")), - "url {} does not carry the pinned version", - artifact.url - ); - } - - #[test] - fn malformed_manifest_is_clear_error_not_panic() { - // Not valid TOML. - assert!(matches!( - parse_manifest("name = "), - Err(SkillError::Parse(_)) - )); - // Valid TOML but missing required fields → Invalid. - let err = parse_manifest("name = \"x\"\ndescription = \"y\"\nsteps = []\n").unwrap_err(); - assert_eq!( - err, - SkillError::Invalid("steps must not be empty".to_string()) - ); - // Empty name → Invalid. - assert!(matches!( - parse_manifest( - "name = \"\"\ndescription = \"d\"\n[[steps]]\ntype=\"check\"\ncommand=\"x\"\n" - ), - Err(SkillError::Invalid(_)) - )); - } - - #[test] - fn builtins_include_both_demo_skills() { - let names: Vec = builtin_skills().into_iter().map(|s| s.name).collect(); - assert!(names.contains(&"install-lemonade".to_string())); - assert!(names.contains(&"auto-config-endpoint".to_string())); - assert!(builtin_skill("install-lemonade").is_some()); - assert!(builtin_skill("nope").is_none()); - } - - #[test] - fn auto_config_change_maps_endpoint_to_config_immutably() { - // Lemonade port → lemonade engine. - let c = auto_config_change(Some(LEMONADE_ENDPOINT)).expect("change"); - assert_eq!(c.chat_url, LEMONADE_ENDPOINT); - assert_eq!(c.default_engine, "lemonade"); - // vLLM port → vllm engine. - let c = auto_config_change(Some(VLLM_ENDPOINT)).expect("change"); - assert_eq!(c.default_engine, "vllm"); - // Unknown port → local. - let c = auto_config_change(Some("http://localhost:9999/v1")).expect("change"); - assert_eq!(c.default_engine, "local"); - // Nothing detected → no change. - assert_eq!(auto_config_change(None), None); - } - - #[test] - fn auto_config_plan_never_clobbers_configured_chat() { - // A chat backend is already configured (e.g. the gateway): default_engine - // updates for serve, but chat_url is preserved. - let plan = auto_config_plan(Some(LEMONADE_ENDPOINT), true); - assert_eq!( - plan.set_chat_url, None, - "must not overwrite configured chat" - ); - assert_eq!(plan.set_default_engine.as_deref(), Some("lemonade")); - assert!(plan.kept_existing_chat); - assert!(!plan.is_noop()); - } - - #[test] - fn auto_config_plan_fills_chat_only_when_unset() { - // No chat backend configured → fill chat_url with the detected endpoint. - let plan = auto_config_plan(Some(VLLM_ENDPOINT), false); - assert_eq!(plan.set_chat_url.as_deref(), Some(VLLM_ENDPOINT)); - assert_eq!(plan.set_default_engine.as_deref(), Some("vllm")); - assert!(!plan.kept_existing_chat); - } - - #[test] - fn auto_config_plan_noop_when_nothing_detected() { - // Nothing running → write nothing at all, regardless of chat config. - assert!(auto_config_plan(None, true).is_noop()); - assert!(auto_config_plan(None, false).is_noop()); - } - - #[test] - fn auto_config_endpoint_manifest_parses() { - let m = parse_manifest(AUTO_CONFIG_ENDPOINT_TOML).expect("valid"); - assert_eq!(m.name, "auto-config-endpoint"); - assert!(matches!( - m.detect, - Some(DetectSpec { - kind: DetectKind::Endpoint, - .. - }) - )); - // It writes both config keys. - let plan = build_plan(&m); - assert!(plan.iter().any(|l| l.contains("tui.chat_url"))); - assert!(plan.iter().any(|l| l.contains("default_engine"))); - } -} diff --git a/crates/rocm-dash-tui/tests/fixtures/lemonade_release_latest.json b/crates/rocm-dash-tui/tests/fixtures/lemonade_release_latest.json deleted file mode 100644 index aaa0b3bf9c..0000000000 --- a/crates/rocm-dash-tui/tests/fixtures/lemonade_release_latest.json +++ /dev/null @@ -1,45 +0,0 @@ -{ - "tag_name": "v10.6.0", - "name": "Lemonade v10.6.0", - "html_url": "https://github.com/lemonade-sdk/lemonade/releases/tag/v10.6.0", - "draft": false, - "prerelease": false, - "assets": [ - { - "name": "Lemonade-10.6.0-Darwin.pkg", - "content_type": "application/octet-stream", - "size": 9868497, - "browser_download_url": "https://github.com/lemonade-sdk/lemonade/releases/download/v10.6.0/Lemonade-10.6.0-Darwin.pkg" - }, - { - "name": "lemonade-embeddable-10.6.0-macos-arm64.tar.gz", - "content_type": "application/gzip", - "size": 2827730, - "browser_download_url": "https://github.com/lemonade-sdk/lemonade/releases/download/v10.6.0/lemonade-embeddable-10.6.0-macos-arm64.tar.gz" - }, - { - "name": "lemonade-embeddable-10.6.0-ubuntu-x64.tar.gz", - "content_type": "application/gzip", - "size": 3425958, - "browser_download_url": "https://github.com/lemonade-sdk/lemonade/releases/download/v10.6.0/lemonade-embeddable-10.6.0-ubuntu-x64.tar.gz" - }, - { - "name": "lemonade-embeddable-10.6.0-windows-x64.zip", - "content_type": "application/zip", - "size": 2891846, - "browser_download_url": "https://github.com/lemonade-sdk/lemonade/releases/download/v10.6.0/lemonade-embeddable-10.6.0-windows-x64.zip" - }, - { - "name": "lemonade-server-10.6.0-fc44.x86_64.rpm", - "content_type": "application/x-redhat-package-manager", - "size": 3879912, - "browser_download_url": "https://github.com/lemonade-sdk/lemonade/releases/download/v10.6.0/lemonade-server-10.6.0-fc44.x86_64.rpm" - }, - { - "name": "lemonade.msi", - "content_type": "application/x-msdownload", - "size": 8052736, - "browser_download_url": "https://github.com/lemonade-sdk/lemonade/releases/download/v10.6.0/lemonade.msi" - } - ] -} diff --git a/xtask/src/ascii_output_contract.rs b/xtask/src/ascii_output_contract.rs index e6c46786e0..ee2d81c6d9 100644 --- a/xtask/src/ascii_output_contract.rs +++ b/xtask/src/ascii_output_contract.rs @@ -967,10 +967,10 @@ mod tests { /// decided by the *including file's path*, not by whether the /// `include_str!` sits in a `#[cfg(test)]` block. So a production file /// that embeds a fixture from inside its own test module is still walked - /// -- `crates/rocm-dash-tui/src/skills.rs:451` does exactly that, from - /// inside the `#[cfg(test)] mod tests` beginning at `:415`, and passes - /// only because that fixture is pure ASCII. A fixture carrying a real - /// non-ASCII character would be a false positive here. + /// -- `apps/rocm/src/remote/doctor.rs` does exactly that, embedding + /// `tests/remote-ssh/examination.json` from inside its `#[cfg(test)] mod + /// tests`, and passes only because that fixture is pure ASCII. A fixture + /// carrying a real non-ASCII character would be a false positive here. /// /// That is deliberate, not an oversight. Scoping by call site would mean /// asking the hand-rolled test-span tracker in [`non_ascii_literals`] diff --git a/xtask/src/crate_edges.rs b/xtask/src/crate_edges.rs index 028e629d30..e3c828ca9d 100644 --- a/xtask/src/crate_edges.rs +++ b/xtask/src/crate_edges.rs @@ -60,7 +60,6 @@ const ALLOWLIST: &[(&str, &str)] = &[ ("rocm-dash-daemon", "rocm-dash-collectors"), ("rocm-dash-tui", "rocm-dash-collectors"), ("rocm-dash-tui", "rocm-dash-core"), - ("rocm-dash-tui", "rocm-deps"), ("rocm-engine-aim", "rocm-core"), ("rocm-engine-aim", "rocm-engine-protocol"), ("rocm-engine-lemonade", "rocm-core"),