Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1801,6 +1801,20 @@ standard input, it sends one prompt and prints the reply.
2 minutes.
The timeout message names the wait that applied and this variable.

With `--prompt`, the reply and tool output are printed with terminal escape
sequences and invisible characters removed, so a reply cannot hide part of a
line, retitle the window or write the clipboard; text it tried to hide is
shown. Every `rocm` error report is printed the same way. A change the assistant asks for with `--tools` is not made from
`--prompt`: it is shown as an `advanced manual command:` line, quoted for a
POSIX shell. A value the assistant chose, in that line or in a plan it asked
for, is refused if it holds a character a Windows shell reads as syntax even
inside those quotes, such as `'`, `&` or `%`; the message tells you to run the
command yourself with that value. A folder the CLI takes from your own
request, such as `install therock into <folder>`, is shown as you typed it; a
folder that reaches the CLI through the assistant's request is held to the
rule, even if you named it first.
See the LLM tool-use design notes in the documentation for the exact set.

In the interactive chat session, if no local engine is reachable and no API
key or URL is configured, chat falls back to the no-key ChatGPT OAuth sign-in.
That backend logs a warning and ignores all three sampling flags. This is an
Expand Down
69 changes: 55 additions & 14 deletions apps/rocm/src/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ pub(crate) use crate::tool_policy::{
};
pub(crate) use crate::tool_policy::{
chat_tool_approval_request, chat_tool_call_is_read_only, validate_chat_tool_call,
validate_model_chosen_plan_result, validate_model_chosen_tool_call,
};
use crate::{ChatInferenceParams, providers};
use anyhow::{Context, Result};
Expand Down Expand Up @@ -130,23 +131,30 @@ fn piped_prompt_from_input(input: &str) -> Option<String> {
}

pub(crate) fn render_chat_text(paths: &AppPaths, provider: &str) -> Result<String> {
let status = providers::provider_status(paths, provider)?;
Ok(render_chat_status_text(&providers::provider_status(
paths, provider,
)?))
}

/// The `rocm chat` status screen for `status`. The model names come from a
/// provider's or a local server's listing, which this process did not write,
/// so each is sanitized on its own before it is composed with the screen's
/// lines; everything else on the screen is this process's own text.
fn render_chat_status_text(status: &providers::ProviderStatus) -> String {
use rocm_core::terminal::sanitize_terminal_text;
let mut output = String::new();
let _ = writeln!(output, "Chat assistant");
let _ = writeln!(output);
let _ = writeln!(
output,
"Assistant source: {}",
if status.provider == "local" {
"local model on this computer"
} else {
status.provider.as_str()
}
);
let source = if status.provider == "local" {
"local model on this computer".to_owned()
} else {
sanitize_terminal_text(&status.provider)
};
let _ = writeln!(output, "Assistant source: {source}");
let _ = writeln!(
output,
"Status: {}",
plain_provider_auth_status(&status.auth_status)
sanitize_terminal_text(&plain_provider_auth_status(&status.auth_status))
);
let _ = writeln!(
output,
Expand All @@ -161,8 +169,8 @@ pub(crate) fn render_chat_text(paths: &AppPaths, provider: &str) -> Result<Strin
let _ = writeln!(output, "Models: none found yet");
} else {
let _ = writeln!(output, "Models:");
for model in status.models {
let _ = writeln!(output, " - {model}");
for model in &status.models {
let _ = writeln!(output, " - {}", sanitize_terminal_text(model));
}
}
let _ = writeln!(output);
Expand All @@ -171,7 +179,7 @@ pub(crate) fn render_chat_text(paths: &AppPaths, provider: &str) -> Result<Strin
"Choose Chat source to switch between local and remote assistants."
);
let _ = writeln!(output, "Choose Settings to manage saved keys and defaults.");
Ok(output)
output
}

fn plain_provider_auth_status(status: &str) -> String {
Expand Down Expand Up @@ -235,6 +243,39 @@ pub(crate) fn parse_positive_u32(value: &str) -> Result<u32, String> {
mod tests {
use super::*;

/// The status screen prints model names a server listed and a provider
/// name from configuration: each is printed with its escape sequences
/// removed, and one left open cannot take the screen's own lines with it.
#[test]
fn the_status_screen_prints_listed_names_without_their_escapes() {
let status = providers::ProviderStatus {
provider: "remote\u{1b}]0;title\u{7}x".to_owned(),
auth_status: "ready".to_owned(),
models: vec![
"qwen\u{1b}]0;never closed".to_owned(),
"llama\u{9b}2K".to_owned(),
],
tool_call_schema: String::new(),
};
assert_eq!(
render_chat_status_text(&status),
"Chat assistant\n\nAssistant source: remotex\nStatus: Ready\nROCm help: not available\n\
Models:\n - qwen\n - llama\n\n\
Choose Chat source to switch between local and remote assistants.\n\
Choose Settings to manage saved keys and defaults.\n"
);
// The status itself can come from a provider, so it is cleaned too.
let status = providers::ProviderStatus {
auth_status: "key_\u{1b}]0;title\u{7}rejected\u{9b}2K".to_owned(),
..status
};
assert!(
render_chat_status_text(&status).contains("\nStatus: key rejected\n"),
"{:?}",
render_chat_status_text(&status)
);
}

#[test]
fn piped_prompt_keeps_everything_but_the_trailing_line_ending() {
// A piped prompt must reach the send path byte-identical to the same
Expand Down
7 changes: 6 additions & 1 deletion apps/rocm/src/chat/mcp_bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@ pub(crate) fn run_internal_mcp_call(
// same `StructuredRequestPlan`, so a provider-assisted plan (not
// guaranteed deterministic across calls) cannot describe one
// command in `text` and a different one in `action`.
let (text, action) = plan_freeform_request_with_context(&request, paths, &config);
let (text, action, planned_args) =
plan_freeform_request_with_context(&request, paths, &config);
let action = action.map(|action| {
serde_json::json!({
"args": action.args,
Expand All @@ -268,6 +269,10 @@ pub(crate) fn run_internal_mcp_call(
"request": request,
"text": text,
"action": action,
// Every action's argv, as its `tool_call:` line in `text`
// prints it, so a caller can hold a model's request to the
// model-only rules (`tool_policy::validate_model_chosen_plan`).
"planned_args": planned_args,
}),
))
}
Expand Down
Loading
Loading