The PRD's first acceptance gate now holds: grep -RinE '\bx\.ai\b|grok' crates/ --include='*.rs' → 0 matches (exempt: NOTICE and third-party license archives, README provenance, and the required 'Based on Grok Build Open Source' attribution, now sourced from version_attribution.txt). Wire-visible renames (both sides in this repo, changed in lockstep): - Auth method id 'grok.com' → 'kimi-code' (AuthMethodKind::KimiCode). - Every x.ai/* and _x.ai/* ACP ext method and meta key → kigi/* / _kigi/* (~200 names; grokShell → kigiShell). Session-file replay keeps a read-side alias for the legacy '_x.ai/session/update' method so existing updates.jsonl histories load; writes emit only the new name (both directions test-pinned). - Agent types grok-build* → kigi* with a documented legacy-prefix alias at resolution time so persisted sessions keep resolving. - ToolNamespace/BuiltinAgentName GrokBuild* → Kigi* (wire snake_case kigi/kigi_concise/kigi_hashline; schema regenerated); grok_build implementation dirs renamed to kigi*. - x-grok-* headers → x-kigi-*, __GROK_* sentinels → __KIGI_*, themes grokday/groknight → kigiday/kiginight (old persisted values fall back to the default theme), web_fetch allowlist xAI hosts → kimi.com + moonshot platforms, changelog CDN → this repo, grok-build changelog archives deleted. - BYOK default endpoint removed: [endpoints] api_base_url is now truly optional with NO default — consumers fail fast with the flag name when unset (no silent x.ai egress). Mock harnesses inject it explicitly. - System-prompt identity fixed: 'released by xAI' → 'an unofficial community CLI for Kimi' (template + regenerated encrypted form). Also repaired pre-existing grok-era test debt found by the sweep: the stale trace_classify default-model pin, the grok-pager UA label test, pty-harness stale-binary reuse and non-hermetic moonshot routing (a PTY test could previously reach the real api.moonshot.cn), and the outdated oauth fixture scope key. Gates: §9 grep 0; fmt clean; workspace check/clippy 0/0 (-D warnings); FULL cargo test --workspace: 234 suites, 21,961 passed, 0 failed; deny advisories ok.
140 lines
4.1 KiB
Rust
140 lines
4.1 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)]
|
|
|
|
/// Generated protobuf types.
|
|
pub mod pb {
|
|
include!(concat!(env!("OUT_DIR"), "/kigi.tools.v1.rs"));
|
|
}
|
|
|
|
pub mod config_validation;
|
|
pub mod slash_commands;
|
|
|
|
// Re-export commonly used types at the crate root for convenience
|
|
pub use pb::{
|
|
// Agent types
|
|
AgentCompletionRequirement,
|
|
AgentToolExecConfig,
|
|
AgentToolRetryConfig,
|
|
// Request/response types
|
|
ClearToolOverrideRequest,
|
|
ClearToolOverrideResponse,
|
|
DisableToolRequest,
|
|
DisableToolResponse,
|
|
EnableToolRequest,
|
|
EnableToolResponse,
|
|
// Enums
|
|
ErrorCode,
|
|
ExecuteToolRequest,
|
|
ExecuteToolResponse,
|
|
ExecutionMetadata,
|
|
ExecutionOptions,
|
|
FinalizeAgentRequest,
|
|
FinalizeAgentResponse,
|
|
FinalizeConfigValidationDetails,
|
|
FinalizeConfigViolation,
|
|
// Tool server config (finalize-time)
|
|
FinalizeToolServerConfigRequest,
|
|
FinalizeToolServerConfigResponse,
|
|
GetAgentInfoRequest,
|
|
GetAgentInfoResponse,
|
|
GetCompletionStateRequest,
|
|
GetCompletionStateResponse,
|
|
GetSystemPromptRequest,
|
|
GetSystemPromptResponse,
|
|
GetSystemRemindersRequest,
|
|
GetSystemRemindersResponse,
|
|
GetToolInfoRequest,
|
|
GetToolOptionsRequest,
|
|
GetToolOptionsResponse,
|
|
// Tool state
|
|
GetToolStateRequest,
|
|
GetToolStateResponse,
|
|
// Truncation config
|
|
GetTruncationConfigRequest,
|
|
GetTruncationConfigResponse,
|
|
ListToolsRequest,
|
|
ListToolsResponse,
|
|
// Output format specs
|
|
OutputFieldSpec,
|
|
OutputFormat,
|
|
OutputFormatSpec,
|
|
ResetCompletionStateRequest,
|
|
ResetCompletionStateResponse,
|
|
ResetToolOptionsRequest,
|
|
ResetToolOptionsResponse,
|
|
SetSystemRemindersRequest,
|
|
SetSystemRemindersResponse,
|
|
SetToolOptionsRequest,
|
|
SetToolOptionsResponse,
|
|
SetToolOverrideRequest,
|
|
SetToolOverrideResponse,
|
|
SetTruncationConfigRequest,
|
|
SetTruncationConfigResponse,
|
|
// Streaming types
|
|
StreamDataChunk,
|
|
StreamDataKind,
|
|
StreamFinalResult,
|
|
// Capability/metadata types
|
|
ToolCapabilities,
|
|
ToolCategory,
|
|
// Per-tool config entry
|
|
ToolConfigEntry,
|
|
ToolError,
|
|
ToolInfo,
|
|
ToolSource,
|
|
ToolStreamChunk,
|
|
ToolSuccess,
|
|
TruncationConfig,
|
|
// Version lifecycle warnings
|
|
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)
|
|
}
|
|
|
|
/// Convert ToolCategory enum to a string representation.
|
|
impl ToolCategory {
|
|
/// Get the string representation of the category.
|
|
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(""), "");
|
|
}
|
|
}
|