M0: compilable skeleton — Kigi 0.1.0 fork surgery
Hard fork of xai-org/grok-build (Apache-2.0) re-targeted as Kigi, an
unofficial Kimi Code CLI community build.
Rename & identity
- 72 xai-*/xai-grok-* crates -> kigi-* (explicit: xai-grok-pager-bin ->
kigi-bin [binary `kigi`], xai-grok-pager -> kigi-tui; rest mechanical);
ptyctl, ptyctl-cli, third_party/ unchanged; proto package
xai.grok.tools.v1 -> kigi.tools.v1
- Config home ~/.kigi (KIGI_SHARE_DIR override), env prefix GROK_* ->
KIGI_*, `kigi --version` carries the unofficial-community-build notice
- clap identity, help text, startup banner, prompt templates rebranded
(templates re-encrypted)
Deletions (PRD removal list #5/#6/#7/#9/#10)
- voice input (xai-grok-voice) and all TUI wiring
- telemetry: Mixpanel client, external OTel stream, Sentry, OTLP layers,
trace/GCS/S3 upload queues (kigi-file-utils halved), workspace upload
module & dc_log, heap-profile uploader, auth-diagnostics uploader,
session-analytics halves of feedback; local zero-egress observability
preserved in new kigi-log crate (unified log, --debug firehose,
subsystem file logs, opt-in instrumentation)
- announcements (crate, remote-settings fields, TUI surfaces)
- plugin marketplace (crate, sources/browse/CTA/extensions-modal tab);
direct plugin install/uninstall/update via kigi-agent git_install kept
- relay/gateway/assets endpoints and features (agent relay, headless
relay transport, gateway bridge, LeaderEnvUrls); leader IPC socket now
~/.kigi/leader.sock + KIGI_LEADER_SOCKET, no ws-url derivation
- functional types rehomed instead of deleted: PermissionMode ->
kigi-config-types, McpInitStrategy -> kigi-mcp, PrCreationSource ->
session signals, TerminalDiagnostics -> kigi-pager-render, agent_id ->
shell util
Endpoints
- kigi-env rewritten: single production KigiEndpoints {coding_api_base_url
https://api.kimi.com/coding/v1 (KIGI_CODE_BASE_URL), oauth_host
https://auth.kimi.com (KIGI_OAUTH_HOST), update_base_url (GitHub
Releases API), upgrade_page_url}; GrokBuildEnvironment enum deleted
Toolchain & workspace hygiene
- Rust 1.97.0 pinned; edition 2024; full cargo update; git2 hoisted to
workspace at 0.21 (Option->Result API migration), quick-xml 0.41
- Root Cargo.toml hand-maintained (PRD §8.1): version 0.1.0 inherited by
all members, members sorted, unused deps pruned
- cargo-deny advisories gate (deny.toml with documented transitive
exceptions); CI workflow (check/clippy/fmt/deny/test, macOS+Linux)
- cross-crate test seams re-gated behind `test-support` cargo feature;
insta snapshot baselines renamed to the kigi_tui prefix
- clippy --workspace --all-targets: zero warnings; fmt clean
Fixes surfaced by the port
- updater probe/installer divergence (bin/kigi vs bin/grok symlink set)
- idle model-metadata refresh dead under KIGI_CODE_BASE_URL override
(new is_effective_coding_endpoint_url, loopback+override aware)
- macOS symlinked-TMPDIR fixture canonicalization (foreign_sessions,
fast-worktree); RSS measurement tests serialized via serial_test
Docs & legal (Apache §4)
- NOTICE added (upstream attribution + change statement); THIRD-PARTY
notices sustained; kigi-tools ported-code notices extended; README,
CONTRIBUTING, SECURITY, AGENTS.md rewritten
Out of scope for M0 (tracked): Kimi auth/inference (M1), search/fetch,
command parity, config import (M2), Computer Hub excision & final
brand-token sweep (M2), distribution & self-update rewrite (M3).
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
//! Contains the registry for all the tools
|
||||
|
||||
pub mod proto_convert;
|
||||
pub mod types;
|
||||
@@ -0,0 +1,226 @@
|
||||
//! Conversion from the gRPC wire config types (`kigi-tools-api`) to the
|
||||
//! runtime registry types ([`ToolConfig`] / [`ToolServerConfig`]).
|
||||
//!
|
||||
//! The `params_json` parse/validation contract lives in
|
||||
//! [`kigi_tools_api::config_validation`] so every consumer (this
|
||||
//! converter, save-time config validation, ...) shares one source of
|
||||
//! truth. The error types are re-exported here for back-compat.
|
||||
|
||||
use super::types::{ToolConfig, ToolServerConfig};
|
||||
|
||||
pub use kigi_tools_api::config_validation::{ToolConfigEntryError, ToolConfigEntryErrorKind};
|
||||
|
||||
/// Convert one wire [`kigi_tools_api::ToolConfigEntry`] to a runtime
|
||||
/// [`ToolConfig`].
|
||||
///
|
||||
/// `index` is only used for error reporting. The result always has
|
||||
/// `kind: None`: the wire format carries no capability kind, and
|
||||
/// capability-mode filtering intentionally keeps baseline `kind: None` tools.
|
||||
pub fn tool_config_from_entry(
|
||||
index: usize,
|
||||
entry: kigi_tools_api::ToolConfigEntry,
|
||||
) -> Result<ToolConfig, ToolConfigEntryError> {
|
||||
let kigi_tools_api::ToolConfigEntry {
|
||||
id,
|
||||
params_json,
|
||||
name_override,
|
||||
params_name_overrides,
|
||||
behavior_version,
|
||||
description_override,
|
||||
} = entry;
|
||||
let params =
|
||||
kigi_tools_api::config_validation::parse_params_json(index, &id, params_json.as_deref())?;
|
||||
kigi_tools_api::config_validation::validate_name_override(
|
||||
index,
|
||||
&id,
|
||||
name_override.as_deref(),
|
||||
)?;
|
||||
Ok(ToolConfig {
|
||||
id,
|
||||
params,
|
||||
name_override,
|
||||
params_name_overrides: if params_name_overrides.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(params_name_overrides)
|
||||
},
|
||||
description_override,
|
||||
behavior_version,
|
||||
kind: None,
|
||||
})
|
||||
}
|
||||
|
||||
/// Convert a wire tool-config list to a runtime [`ToolServerConfig`].
|
||||
/// Fails on the first invalid entry.
|
||||
///
|
||||
/// `behavior_preset` is always `None` (the `"current"` default); per-tool
|
||||
/// `behavior_version` overrides on individual entries still apply.
|
||||
pub fn tool_server_config_from_entries(
|
||||
entries: Vec<kigi_tools_api::ToolConfigEntry>,
|
||||
) -> Result<ToolServerConfig, ToolConfigEntryError> {
|
||||
let tools = entries
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
.map(|(idx, entry)| tool_config_from_entry(idx, entry))
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
Ok(ToolServerConfig {
|
||||
tools,
|
||||
behavior_preset: None,
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn entry(id: &str) -> kigi_tools_api::ToolConfigEntry {
|
||||
kigi_tools_api::ToolConfigEntry {
|
||||
id: id.to_owned(),
|
||||
params_json: None,
|
||||
name_override: None,
|
||||
params_name_overrides: Default::default(),
|
||||
behavior_version: None,
|
||||
description_override: None,
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn minimal_entry_converts_with_defaults() {
|
||||
let cfg = tool_config_from_entry(0, entry("GrokBuild:read_file")).unwrap();
|
||||
assert_eq!(cfg.id, "GrokBuild:read_file");
|
||||
assert_eq!(cfg.params, None);
|
||||
assert_eq!(cfg.name_override, None);
|
||||
assert_eq!(cfg.params_name_overrides, None);
|
||||
assert_eq!(cfg.description_override, None);
|
||||
assert_eq!(cfg.behavior_version, None);
|
||||
assert_eq!(cfg.kind, None, "wire entries never carry a kind");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fully_populated_entry_converts_field_by_field() {
|
||||
let mut e = entry("GrokBuild:grep");
|
||||
e.params_json = Some(r#"{"max_results": 50}"#.to_owned());
|
||||
e.name_override = Some("search".to_owned());
|
||||
e.params_name_overrides =
|
||||
std::collections::HashMap::from([("pattern".to_owned(), "query".to_owned())]);
|
||||
e.behavior_version = Some("legacy-0.4.10".to_owned());
|
||||
e.description_override = Some("Search the codebase".to_owned());
|
||||
|
||||
let cfg = tool_config_from_entry(0, e).unwrap();
|
||||
assert_eq!(
|
||||
cfg.params,
|
||||
Some(
|
||||
serde_json::json!({"max_results": 50})
|
||||
.as_object()
|
||||
.cloned()
|
||||
.unwrap()
|
||||
)
|
||||
);
|
||||
assert_eq!(cfg.name_override.as_deref(), Some("search"));
|
||||
assert_eq!(
|
||||
cfg.params_name_overrides.as_ref().unwrap()["pattern"],
|
||||
"query"
|
||||
);
|
||||
assert_eq!(cfg.behavior_version.as_deref(), Some("legacy-0.4.10"));
|
||||
assert_eq!(
|
||||
cfg.description_override.as_deref(),
|
||||
Some("Search the codebase")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invalid_params_json_is_a_parse_error() {
|
||||
let mut e = entry("GrokBuild:bash");
|
||||
e.params_json = Some("{not json".to_owned());
|
||||
let err = tool_config_from_entry(3, e).unwrap_err();
|
||||
assert_eq!(err.index, 3);
|
||||
assert_eq!(err.tool_id, "GrokBuild:bash");
|
||||
assert_eq!(err.field_path(), "tools[3].params_json");
|
||||
assert!(matches!(
|
||||
&err.kind,
|
||||
ToolConfigEntryErrorKind::ParamsJsonParse { raw, .. } if raw == "{not json"
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn non_object_params_json_is_a_type_error() {
|
||||
let mut e = entry("GrokBuild:bash");
|
||||
e.params_json = Some("[1, 2]".to_owned());
|
||||
let err = tool_config_from_entry(1, e).unwrap_err();
|
||||
assert_eq!(
|
||||
err.kind,
|
||||
ToolConfigEntryErrorKind::ParamsJsonNotObject {
|
||||
value: serde_json::json!([1, 2])
|
||||
}
|
||||
);
|
||||
assert_eq!(err.field_path(), "tools[1].params_json");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn name_override_valid_tool_id_charset_is_accepted() {
|
||||
for name in ["search", "GrokBuild:grep", "a-b_C9"] {
|
||||
let mut e = entry("GrokBuild:grep");
|
||||
e.name_override = Some(name.to_owned());
|
||||
let cfg = tool_config_from_entry(0, e).unwrap();
|
||||
assert_eq!(cfg.name_override.as_deref(), Some(name));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn name_override_outside_tool_id_charset_is_rejected() {
|
||||
for name in ["has space", "", "a:b:c", "emoji✨", "dot.name"] {
|
||||
let mut e = entry("GrokBuild:grep");
|
||||
e.name_override = Some(name.to_owned());
|
||||
let err = tool_config_from_entry(2, e).unwrap_err();
|
||||
assert_eq!(err.index, 2, "name={name:?}");
|
||||
assert_eq!(err.tool_id, "GrokBuild:grep");
|
||||
assert_eq!(err.field_path(), "tools[2].name_override");
|
||||
assert!(
|
||||
matches!(
|
||||
&err.kind,
|
||||
ToolConfigEntryErrorKind::NameOverrideInvalid { name: n, .. } if n == name
|
||||
),
|
||||
"name={name:?} kind={:?}",
|
||||
err.kind
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn server_config_conversion_rejects_invalid_name_override_entry() {
|
||||
let mut bad = entry("GrokBuild:grep");
|
||||
bad.name_override = Some("bad name".to_owned());
|
||||
let err = tool_server_config_from_entries(vec![entry("ok"), bad]).unwrap_err();
|
||||
assert_eq!(err.index, 1, "fails closed on the offending entry");
|
||||
assert!(matches!(
|
||||
err.kind,
|
||||
ToolConfigEntryErrorKind::NameOverrideInvalid { .. }
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn server_config_conversion_preserves_valid_name_overrides() {
|
||||
let mut a = entry("GrokBuild:grep");
|
||||
a.name_override = Some("search".to_owned());
|
||||
let cfg = tool_server_config_from_entries(vec![a, entry("GrokBuild:bash")]).unwrap();
|
||||
assert_eq!(cfg.tools.len(), 2);
|
||||
assert_eq!(cfg.tools[0].name_override.as_deref(), Some("search"));
|
||||
assert_eq!(cfg.tools[1].name_override, None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn server_config_conversion_maps_all_entries_with_default_preset() {
|
||||
let cfg = tool_server_config_from_entries(vec![entry("a"), entry("b")]).unwrap();
|
||||
assert_eq!(cfg.tools.len(), 2);
|
||||
assert_eq!(cfg.behavior_preset, None, "always the 'current' default");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn server_config_conversion_fails_on_first_invalid_entry_with_index() {
|
||||
let mut bad = entry("bad");
|
||||
bad.params_json = Some("nope".to_owned());
|
||||
let err = tool_server_config_from_entries(vec![entry("ok"), bad]).unwrap_err();
|
||||
assert_eq!(err.index, 1);
|
||||
assert_eq!(err.tool_id, "bad");
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user