chore: import upstream snapshot with attribution
FreeBSD Smoke / FreeBSD Smoke (x86_64) (push) Has been cancelled
CI / Quality Guardrails (push) Has been cancelled
CI / Build & Test (macos-latest) (push) Has been cancelled
CI / Build & Test (ubuntu-latest) (push) Has been cancelled
CI / Build & Test (windows-latest) (push) Has been cancelled
CI / Format (push) Has been cancelled
CI / PowerShell Syntax (push) Has been cancelled
CI / Windows Cross-Target Check (Linux) (push) Has been cancelled

This commit is contained in:
wehub-resource-sync
2026-07-13 13:10:34 +08:00
commit a789495a98
1551 changed files with 718128 additions and 0 deletions
+17
View File
@@ -0,0 +1,17 @@
[package]
name = "jcode-tool-core"
version = "0.1.0"
edition = "2024"
[lib]
name = "jcode_tool_core"
path = "src/lib.rs"
[dependencies]
anyhow = "1"
async-trait = "0.1"
jcode-agent-runtime = { path = "../jcode-agent-runtime" }
jcode-message-types = { path = "../jcode-message-types" }
jcode-tool-types = { path = "../jcode-tool-types" }
serde_json = "1"
tokio = { version = "1", features = ["sync"] }
+93
View File
@@ -0,0 +1,93 @@
use anyhow::Result;
use async_trait::async_trait;
use jcode_agent_runtime::InterruptSignal;
use jcode_message_types::ToolDefinition;
use jcode_tool_types::ToolOutput;
use serde_json::Value;
use std::path::{Path, PathBuf};
pub const TOOL_INTENT_DESCRIPTION: &str = concat!(
"Short natural-language label explaining why this tool call is being made. ",
"Used for compact UI display only. Optional; do not use this instead of required tool parameters."
);
pub fn intent_schema_property() -> Value {
serde_json::json!({
"type": "string",
"description": TOOL_INTENT_DESCRIPTION,
})
}
/// A request for stdin input from a running command.
pub struct StdinInputRequest {
pub request_id: String,
pub prompt: String,
pub is_password: bool,
pub response_tx: tokio::sync::oneshot::Sender<String>,
}
#[derive(Clone)]
pub struct ToolContext {
pub session_id: String,
pub message_id: String,
pub tool_call_id: String,
pub working_dir: Option<PathBuf>,
pub stdin_request_tx: Option<tokio::sync::mpsc::UnboundedSender<StdinInputRequest>>,
pub graceful_shutdown_signal: Option<InterruptSignal>,
pub execution_mode: ToolExecutionMode,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ToolExecutionMode {
AgentTurn,
Direct,
}
impl ToolContext {
pub fn for_subcall(&self, tool_call_id: String) -> Self {
Self {
session_id: self.session_id.clone(),
message_id: self.message_id.clone(),
tool_call_id,
working_dir: self.working_dir.clone(),
stdin_request_tx: self.stdin_request_tx.clone(),
graceful_shutdown_signal: self.graceful_shutdown_signal.clone(),
execution_mode: self.execution_mode,
}
}
pub fn resolve_path(&self, path: &Path) -> PathBuf {
if path.is_absolute() {
path.to_path_buf()
} else if let Some(ref base) = self.working_dir {
base.join(path)
} else {
path.to_path_buf()
}
}
}
/// A tool that can be executed by the agent.
#[async_trait]
pub trait Tool: Send + Sync {
/// Tool name (must match what's sent to the API).
fn name(&self) -> &str;
/// Human-readable description.
fn description(&self) -> &str;
/// JSON Schema for the input parameters.
fn parameters_schema(&self) -> Value;
/// Execute the tool with the given input.
async fn execute(&self, input: Value, ctx: ToolContext) -> Result<ToolOutput>;
/// Convert to API tool definition.
fn to_definition(&self) -> ToolDefinition {
ToolDefinition {
name: self.name().to_string(),
description: self.description().to_string(),
input_schema: self.parameters_schema(),
}
}
}