Files
Kigi-CLI/crates/codegen/kigi-tools-api/src/lib.rs
T
ZacharyZhang-NY a02b555e66 docs(comments): rewrite comments across all crates to the guidelines
Sweep every first-party crate source (1956 .rs files) to the project comment
guidelines: delete redundant restatements, decorative banners, change
narration, and end-of-line comments; keep and tighten the crucial ones
(invariants, bug rationale, SAFETY blocks, ported-source attribution).

No functional code changed. Every edit is proven comment-only against the
prior tree by a comment-stripping lexer (string/char/raw-string aware) plus a
separate doctest-fence check. Where removing a comment made rustfmt or clippy
want to re-lay-out adjacent code, the minimal triggering comment is restored so
code tokens stay byte-identical.

Gates green: cargo fmt --all --check (0 diffs), cargo check and cargo clippy
--workspace --all-targets (0 warnings).

Adds scripts/check_codegen_comment_guidelines.py — the enforcement gate for
these guidelines (flags banners, end-of-line comments, change narration, and
commented-out code).
2026-07-23 16:55:39 -04:00

77 lines
3.4 KiB
Rust

//! Shared API definitions for Kigi tools: protobuf types, config validation,
//! and canonical slash-command wording.
//!
//! Used by both the tools library and the gRPC server, and by host services
//! that must not depend on the tools implementation crate.
#![allow(clippy::derive_partial_eq_without_eq)]
pub mod pb {
include!(concat!(env!("OUT_DIR"), "/kigi.tools.v1.rs"));
}
pub mod config_validation;
pub mod slash_commands;
pub use pb::{
AgentCompletionRequirement, AgentToolExecConfig, AgentToolRetryConfig,
ClearToolOverrideRequest, ClearToolOverrideResponse, DisableToolRequest, DisableToolResponse,
EnableToolRequest, EnableToolResponse, ErrorCode, ExecuteToolRequest, ExecuteToolResponse,
ExecutionMetadata, ExecutionOptions, FinalizeAgentRequest, FinalizeAgentResponse,
FinalizeConfigValidationDetails, FinalizeConfigViolation, FinalizeToolServerConfigRequest,
FinalizeToolServerConfigResponse, GetAgentInfoRequest, GetAgentInfoResponse,
GetCompletionStateRequest, GetCompletionStateResponse, GetSystemPromptRequest,
GetSystemPromptResponse, GetSystemRemindersRequest, GetSystemRemindersResponse,
GetToolInfoRequest, GetToolOptionsRequest, GetToolOptionsResponse, GetToolStateRequest,
GetToolStateResponse, GetTruncationConfigRequest, GetTruncationConfigResponse,
ListToolsRequest, ListToolsResponse, OutputFieldSpec, OutputFormat, OutputFormatSpec,
ResetCompletionStateRequest, ResetCompletionStateResponse, ResetToolOptionsRequest,
ResetToolOptionsResponse, SetSystemRemindersRequest, SetSystemRemindersResponse,
SetToolOptionsRequest, SetToolOptionsResponse, SetToolOverrideRequest, SetToolOverrideResponse,
SetTruncationConfigRequest, SetTruncationConfigResponse, StreamDataChunk, StreamDataKind,
StreamFinalResult, ToolCapabilities, ToolCategory, ToolConfigEntry, ToolError, ToolInfo,
ToolSource, ToolStreamChunk, ToolSuccess, TruncationConfig, VersionWarning,
};
/// Default client-facing tool name derived from a namespaced tool id.
///
/// Tool ids are colon-separated `Namespace:tool` (e.g. `Kigi:grep`); the
/// default name is the segment after the FIRST colon, so an id with embedded
/// colons (`ns:a:b`) resolves to `a`. Ids without a colon are returned as-is.
///
/// This is the single source of truth shared by the tools server (which
/// advertises tools under this name unless `name_override` is set) and any
/// client that needs to predict the advertised name from a config entry
/// (e.g. prompt tool selection in a downstream service). Keeping both sides on
/// this helper prevents a silent desync that would drop tools from prompts.
pub fn default_client_name(id: &str) -> &str {
id.split(':').nth(1).unwrap_or(id)
}
impl ToolCategory {
pub fn as_str(&self) -> &'static str {
match self {
Self::Unspecified => "unspecified",
Self::File => "file",
Self::Search => "search",
Self::Shell => "shell",
Self::Workflow => "workflow",
Self::External => "external",
Self::Custom => "custom",
}
}
}
#[cfg(test)]
mod default_client_name_tests {
use super::default_client_name;
#[test]
fn pins_first_colon_derivation() {
assert_eq!(default_client_name("Kigi:grep"), "grep");
assert_eq!(default_client_name("ns:a:b"), "a");
assert_eq!(default_client_name("bare"), "bare");
assert_eq!(default_client_name(""), "");
}
}