xtap-core-lib 0.5.1

星TAP实验室通用 Rust 基座:跨平台路径/IO/硬件/MCP HTTP 服务/egui 主题与字体(features 按需裁剪)
Documentation
/*
 * mcp/instructions.rs
 * Project: core_lib
 * Description: 编译期 `_ai_instructions` 字符串构造宏
 *
 * 设计(抄 sts-x src/types/format.rs:17-21 的 concat!(env!("CARGO_PKG_VERSION"), ...) 模式):
 * - 全部在编译期用 concat! 拼成 &'static str,零运行时开销
 * - env!("CARGO_PKG_VERSION") 在“调用方 crate”展开,故版本号是使用该宏的 app 自己的版本
 * - 目的:让每个 MCP 工具的 JSON 输出都带一段自解释指令,AI 自发现、零学习成本
 */

/// 构造一段编译期 `_ai_instructions` 文本。
///
/// 用法:
/// ```ignore
/// // 在使用方 crate(例如 sts-x)里:
/// const HINT: &str = core_lib::ai_instructions!(
///     "STS-X",
///     "unified code+file search. CLI: sts-x search \"q\". MCP: POST /search."
/// );
/// // 展开 ≈ "I am STS-X 3.1.2. unified code+file search. ..."
/// ```
///
/// 第一个参数是服务名,其余参数按 `concat!` 依次拼接。版本号取自调用方 crate 的
/// `CARGO_PKG_VERSION`,因此各 app 无需手写版本。
#[macro_export]
macro_rules! ai_instructions {
    ($service:expr $(, $part:expr)+ $(,)?) => {
        concat!("I am ", $service, " ", env!("CARGO_PKG_VERSION"), ". " $(, $part)+)
    };
    ($service:expr $(,)?) => {
        concat!("I am ", $service, " ", env!("CARGO_PKG_VERSION"), ".")
    };
}