Skip to content
Merged
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
4 changes: 4 additions & 0 deletions rustcode/core/rustcode-tools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
//! now because their ignore/walk policy is coupled to the search orchestration;
//! directory listing is intentionally small enough to share this boundary.

mod output;

pub use output::ToolExecutionOutput;

use std::cell::RefCell;
use std::path::{Path, PathBuf};

Expand Down
68 changes: 68 additions & 0 deletions rustcode/core/rustcode-tools/src/output.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
//! What a tool call returns: its display text and the facts beside it.

/// Authoritative facts returned by a tool invocation alongside its display
/// text. Consumers must not reconstruct these fields from `content`.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ToolExecutionOutput {
pub content: String,
pub success: bool,
pub pending: bool,
pub command: Option<String>,
pub exit_code: Option<i32>,
pub truncated: bool,
/// Machine-readable completeness of the output delivered by the tool.
/// This must be set by the execution layer, never inferred from display text.
pub completeness: rustcode_core::ToolResultCompleteness,
/// True when the harness served a bounded cached read instead of running
/// the tool again. This is execution state, not display prose.
pub replayed: bool,
pub error_kind: Option<rustcode_core::ToolErrorKind>,
pub retryable: bool,
pub command_status: Option<rustcode_core::CommandResultMetadata>,
}

impl ToolExecutionOutput {
pub fn success(content: String) -> Self {
Self {
content,
success: true,
pending: false,
command: None,
exit_code: None,
truncated: false,
completeness: rustcode_core::ToolResultCompleteness::Complete,
replayed: false,
error_kind: None,
retryable: false,
command_status: None,
}
}

pub fn failure(content: String) -> Self {
Self {
content,
success: false,
pending: false,
command: None,
exit_code: None,
truncated: false,
completeness: rustcode_core::ToolResultCompleteness::Complete,
replayed: false,
error_kind: Some(rustcode_core::ToolErrorKind::Internal),
retryable: false,
command_status: None,
}
}

pub fn failure_with_kind(
content: String,
error_kind: rustcode_core::ToolErrorKind,
retryable: bool,
) -> Self {
Self {
error_kind: Some(error_kind),
retryable,
..Self::failure(content)
}
}
}
3 changes: 2 additions & 1 deletion rustcode/engine/src/desktop_control.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Client-owned native desktop automation. The client enforces user consent
//! and snapshot provenance; the engine never executes desktop commands itself.
use crate::tools::{ToolErrorKind, ToolExecutionOutput};
use rustcode_core::ToolErrorKind;
use rustcode_tools::ToolExecutionOutput;
use serde_json::{Value, json};
use std::{sync::Arc, time::Duration};
use tokio::sync::Mutex;
Expand Down
10 changes: 5 additions & 5 deletions rustcode/engine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub mod remote_gateway;
pub(crate) fn background_task_history_message(
task_id: &str,
call_id: Option<&str>,
mut output: crate::tools::ToolExecutionOutput,
mut output: rustcode_tools::ToolExecutionOutput,
) -> ChatMessage {
// A background command can print a secret it was given as `env`.
crate::orchestration::secret::redact_output(&mut output);
Expand Down Expand Up @@ -129,7 +129,7 @@ pub(crate) fn background_task_history_message(
pub struct PendingBackgroundOutput {
pub task_id: String,
pub call_id: Option<String>,
pub output: crate::tools::ToolExecutionOutput,
pub output: rustcode_tools::ToolExecutionOutput,
}

pub(crate) fn queue_background_wakeup(state: &mut AppState, task_id: &str) {
Expand Down Expand Up @@ -210,7 +210,7 @@ mod background_history_tests {

#[test]
fn background_completion_is_one_tool_message_answering_a_call() {
let output = || crate::tools::ToolExecutionOutput::success("done".to_owned());
let output = || rustcode_tools::ToolExecutionOutput::success("done".to_owned());

let message = background_task_history_message("task_7", Some("call_bg"), output());
assert_eq!(message.role, "tool");
Expand All @@ -231,7 +231,7 @@ mod background_history_tests {
let message = background_task_history_message(
"task_42",
None,
crate::tools::ToolExecutionOutput {
rustcode_tools::ToolExecutionOutput {
content: raw.clone(),
success: false,
pending: false,
Expand Down Expand Up @@ -275,7 +275,7 @@ mod background_history_tests {
let message = background_task_history_message(
"task_43",
None,
crate::tools::ToolExecutionOutput {
rustcode_tools::ToolExecutionOutput {
content: "exit code: 0\n[Output truncated:]\nFull output saved to: /tmp/spoof"
.to_string(),
success: false,
Expand Down
19 changes: 10 additions & 9 deletions rustcode/engine/src/orchestration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ use serde_json::{Value, json};
use tokio::sync::Mutex;

use crate::preview::PreviewClient;
use crate::tools::{ToolErrorKind, ToolExecutionOutput};
use rustcode_core::ToolErrorKind;
use rustcode_tools::ToolExecutionOutput;

pub mod ask_user;
pub mod local;
Expand Down Expand Up @@ -2346,23 +2347,23 @@ mod tests {
// activity read, v7 the queue control, v8 that native subagents go
// through RustCode's tools, v9 a delegate's pull request.

let tokens = crate::network::compaction::estimate_tokens(PROMPT_HINT_V11);
let tokens = rustcode_core::tokens::estimate_tokens(PROMPT_HINT_V11);
println!(
"prompt hints: v3 {} tokens, v4 {} tokens, v5 {} tokens, v6 {} tokens, v9 {tokens} tokens",
crate::network::compaction::estimate_tokens(PROMPT_HINT_V3),
crate::network::compaction::estimate_tokens(PROMPT_HINT_V4),
crate::network::compaction::estimate_tokens(PROMPT_HINT_V5),
crate::network::compaction::estimate_tokens(PROMPT_HINT_V6)
rustcode_core::tokens::estimate_tokens(PROMPT_HINT_V3),
rustcode_core::tokens::estimate_tokens(PROMPT_HINT_V4),
rustcode_core::tokens::estimate_tokens(PROMPT_HINT_V5),
rustcode_core::tokens::estimate_tokens(PROMPT_HINT_V6)
);
// v9 adds the three delegate pull-request tools, all named with their use,
// and how an orchestrator keeps its own context small: those few lines
// save far more than they cost on each request.
assert!(tokens < 1000, "{tokens}");
// v12 is the v11 hint plus the machine sentences, still bounded.
let v12 = crate::network::compaction::estimate_tokens(PROMPT_HINT_V12);
let v12 = rustcode_core::tokens::estimate_tokens(PROMPT_HINT_V12);
assert!(v12 < 1150, "{v12}");
// v13 adds the worktree pair, and the seconds each call saves.
let v13 = crate::network::compaction::estimate_tokens(PROMPT_HINT_V13);
let v13 = rustcode_core::tokens::estimate_tokens(PROMPT_HINT_V13);
assert!(v13 < 1200, "{v13}");
}

Expand Down Expand Up @@ -3417,7 +3418,7 @@ mod tests {

#[test]
fn the_version_two_hint_stays_short() {
let tokens = crate::network::compaction::estimate_tokens(PROMPT_HINT_V2);
let tokens = rustcode_core::tokens::estimate_tokens(PROMPT_HINT_V2);
assert!(tokens < 115, "{tokens}");
for name in tool_names(2) {
assert!(PROMPT_HINT_V2.contains(name), "{name}");
Expand Down
4 changes: 2 additions & 2 deletions rustcode/engine/src/orchestration/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use std::time::Duration;
use serde_json::{Value, json};
use tokio_util::sync::CancellationToken;

use crate::app::ChatMessage;
use rustcode_core::ChatMessage;

/// The most threads one read returns: what the app's `list_sessions` lists.
const MAX_SESSIONS: usize = 50;
Expand All @@ -47,7 +47,7 @@ pub(crate) async fn answer(
cancel: &CancellationToken,
name: &str,
args: &Value,
) -> crate::tools::ToolExecutionOutput {
) -> rustcode_tools::ToolExecutionOutput {
super::output(name, answer_json(session_id, cancel, name, args).await)
}

Expand Down
4 changes: 2 additions & 2 deletions rustcode/engine/src/orchestration/local_threads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2797,8 +2797,8 @@ pub(super) fn test_thread(dir: &std::path::Path) -> String {
crate::sessions::save_session_history(
&id,
&vec![
crate::app::ChatMessage::new("user", "a test thread"),
crate::app::ChatMessage::new("assistant", "ok"),
rustcode_core::ChatMessage::new("user", "a test thread"),
rustcode_core::ChatMessage::new("assistant", "ok"),
],
);
crate::sessions::flush_history();
Expand Down
2 changes: 1 addition & 1 deletion rustcode/engine/src/orchestration/outside.rs
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,7 @@ fn json_of(answer: CallAnswer) -> Option<Value> {
/// `thread_usage`, `query_data` and `read_activity` read the local data store.
/// They cannot be narrowed to a project, so they follow the same switch as
/// reading threads across projects.
fn data_tool(tool: &str, args: &Value) -> crate::tools::ToolExecutionOutput {
fn data_tool(tool: &str, args: &Value) -> rustcode_tools::ToolExecutionOutput {
use crate::acp::data;
let text = |key: &str| args.get(key).and_then(Value::as_str).map(str::to_owned);
let number = |key: &str| {
Expand Down
11 changes: 6 additions & 5 deletions rustcode/engine/src/orchestration/secret.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pub fn redact(text: &str) -> Option<String> {
}
/// Mask held secrets in a tool's result before it reaches the model, the
/// transcript or history.
pub fn redact_output(output: &mut crate::tools::ToolExecutionOutput) {
pub fn redact_output(output: &mut rustcode_tools::ToolExecutionOutput) {
if let Some(content) = redact(&output.content) {
output.content = content;
}
Expand Down Expand Up @@ -453,7 +453,8 @@ mod tests {
let value = "history-canary-31415";
set_thread_env(thread, "DEPLOY_TOKEN", value);
let echoed = || {
let mut output = crate::tools::ToolExecutionOutput::success(format!("token {value}\n"));
let mut output =
rustcode_tools::ToolExecutionOutput::success(format!("token {value}\n"));
output.command = Some(format!("echo {value}"));
output
};
Expand Down Expand Up @@ -507,7 +508,7 @@ pub async fn execute(
state: &std::sync::Arc<tokio::sync::Mutex<crate::app::AppState>>,
cancel: &tokio_util::sync::CancellationToken,
args: &Value,
) -> crate::tools::ToolExecutionOutput {
) -> rustcode_tools::ToolExecutionOutput {
let (root, asker, id) = {
let state = state.lock().await;
(
Expand All @@ -531,8 +532,8 @@ pub async fn execute(
)
.await;
if result.success {
crate::tools::ToolExecutionOutput::success(result.content)
rustcode_tools::ToolExecutionOutput::success(result.content)
} else {
crate::tools::ToolExecutionOutput::failure(result.content)
rustcode_tools::ToolExecutionOutput::failure(result.content)
}
}
3 changes: 2 additions & 1 deletion rustcode/engine/src/preview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ use std::sync::Arc;
use std::time::Duration;
use tokio::sync::Mutex;

use crate::tools::{ToolErrorKind, ToolExecutionOutput};
use rustcode_core::ToolErrorKind;
use rustcode_tools::ToolExecutionOutput;

pub const PREVIEW_TOOL_NAME: &str = "localhost_preview";
/// The `clientCapabilities._meta.rustcode.preview` version this engine
Expand Down
3 changes: 2 additions & 1 deletion rustcode/engine/src/smart_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ use std::time::Duration;
use tokio::sync::Mutex;

use crate::preview::{PreviewClient, decode_screenshot, one_line, page_errors};
use crate::tools::{ToolErrorKind, ToolExecutionOutput};
use rustcode_core::ToolErrorKind;
use rustcode_tools::ToolExecutionOutput;

pub const PREVIEW_TOOL_NAME: &str = "smart_ui_preview";
/// The extension request the app answers.
Expand Down
67 changes: 1 addition & 66 deletions rustcode/engine/src/tools/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,72 +259,7 @@ pub fn filter_tools_by_query(query: &str, limit: usize) -> Vec<&'static str> {
scored.into_iter().map(|(name, _)| name).collect()
}

/// Authoritative facts returned by a tool invocation alongside its display
/// text. Consumers must not reconstruct these fields from `content`.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ToolExecutionOutput {
pub(crate) content: String,
pub(crate) success: bool,
pub(crate) pending: bool,
pub(crate) command: Option<String>,
pub(crate) exit_code: Option<i32>,
pub(crate) truncated: bool,
/// Machine-readable completeness of the output delivered by the tool.
/// This must be set by the execution layer, never inferred from display text.
pub(crate) completeness: rustcode_core::ToolResultCompleteness,
/// True when the harness served a bounded cached read instead of running
/// the tool again. This is execution state, not display prose.
pub(crate) replayed: bool,
pub(crate) error_kind: Option<ToolErrorKind>,
pub(crate) retryable: bool,
pub(crate) command_status: Option<rustcode_core::CommandResultMetadata>,
}

impl ToolExecutionOutput {
pub(crate) fn success(content: String) -> Self {
Self {
content,
success: true,
pending: false,
command: None,
exit_code: None,
truncated: false,
completeness: rustcode_core::ToolResultCompleteness::Complete,
replayed: false,
error_kind: None,
retryable: false,
command_status: None,
}
}

pub(crate) fn failure(content: String) -> Self {
Self {
content,
success: false,
pending: false,
command: None,
exit_code: None,
truncated: false,
completeness: rustcode_core::ToolResultCompleteness::Complete,
replayed: false,
error_kind: Some(ToolErrorKind::Internal),
retryable: false,
command_status: None,
}
}

pub(crate) fn failure_with_kind(
content: String,
error_kind: ToolErrorKind,
retryable: bool,
) -> Self {
Self {
error_kind: Some(error_kind),
retryable,
..Self::failure(content)
}
}
}
pub use rustcode_tools::ToolExecutionOutput;

/// How many calls that can change the workspace may run from one response.
///
Expand Down
Loading