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:
2026-07-17 05:31:01 -04:00
commit d6c20fc13f
2612 changed files with 1353757 additions and 0 deletions
@@ -0,0 +1,226 @@
//! `From<ToolError> for ToolErrorWire` coverage for the struct-based ToolError.
use serde_json::json;
use kigi_tool_protocol::{ToolErrorWire, ToolId};
use kigi_tool_runtime::error::{ToolError, ToolErrorKind};
fn tid(name: &str) -> ToolId {
ToolId::new(name).unwrap()
}
#[test]
fn not_implemented_maps_to_custom_with_snake_case_code() {
let err = ToolError::not_implemented("nope");
let wire: ToolErrorWire = err.into();
match wire {
ToolErrorWire::Custom {
subcode, message, ..
} => {
assert_eq!(subcode, "not_implemented");
assert_eq!(message, "nope");
}
other => panic!("expected Custom, got {other:?}"),
}
}
#[test]
fn invalid_arguments_round_trips_message_and_details() {
let details = json!({"field": "name", "expected": "non-empty"});
let err = ToolError::invalid_arguments("bad name").with_details(details.clone());
let wire: ToolErrorWire = err.into();
match wire {
ToolErrorWire::InvalidArguments {
message,
details: d,
} => {
assert_eq!(message, "bad name");
assert_eq!(d, Some(details));
}
other => panic!("expected InvalidArguments, got {other:?}"),
}
}
#[test]
fn not_found_maps_to_tool_not_found() {
let err = ToolError::not_found(tid("missing"), "tool 'missing' not registered");
let wire: ToolErrorWire = err.into();
assert!(matches!(wire, ToolErrorWire::ToolNotFound { tool_id } if tool_id == tid("missing")));
}
#[test]
fn permission_denied_round_trips_reason() {
let err = ToolError::permission_denied("not authorised for write");
let wire: ToolErrorWire = err.into();
assert!(
matches!(wire, ToolErrorWire::PermissionDenied { reason } if reason == "not authorised for write")
);
}
#[test]
fn unauthorized_maps_to_custom_with_unauthorized_subcode() {
let err = ToolError::unauthorized("session expired");
let wire: ToolErrorWire = err.into();
match wire {
ToolErrorWire::Custom {
subcode, message, ..
} => {
assert_eq!(subcode, "unauthorized");
assert_eq!(message, "session expired");
}
other => panic!("expected Custom(unauthorized), got {other:?}"),
}
}
#[test]
fn timeout_with_details() {
let err = ToolError::timeout(tid("slow"), "image generation timed out")
.with_details(json!({"tool_id": "slow", "elapsed_ms": 2500}));
let wire: ToolErrorWire = err.into();
match wire {
ToolErrorWire::Timeout {
tool_id,
elapsed_ms,
} => {
assert_eq!(tool_id, tid("slow"));
assert_eq!(elapsed_ms, 2_500);
}
other => panic!("expected Timeout, got {other:?}"),
}
}
#[test]
fn cancelled_round_trips_tool_id() {
let err = ToolError::cancelled(tid("paused"), "user cancelled");
let wire: ToolErrorWire = err.into();
assert!(matches!(wire, ToolErrorWire::Cancelled { tool_id } if tool_id == tid("paused")));
}
#[test]
fn rate_limited_carries_detail_message() {
let err = ToolError::rate_limited("You've reached your image generation limit.");
let wire: ToolErrorWire = err.into();
match wire {
ToolErrorWire::Custom {
subcode, message, ..
} => {
assert_eq!(subcode, "rate_limited");
assert_eq!(message, "You've reached your image generation limit.");
}
other => panic!("expected Custom, got {other:?}"),
}
}
#[test]
fn service_unavailable_carries_detail() {
let err = ToolError::service_unavailable("Media service temporarily down.");
let wire: ToolErrorWire = err.into();
match wire {
ToolErrorWire::Custom {
subcode, message, ..
} => {
assert_eq!(subcode, "service_unavailable");
assert_eq!(message, "Media service temporarily down.");
}
other => panic!("expected Custom, got {other:?}"),
}
}
#[test]
fn network_error_maps_to_custom_with_message() {
let err = ToolError::network_error("dns failure");
let wire: ToolErrorWire = err.into();
match wire {
ToolErrorWire::Custom {
subcode, message, ..
} => {
assert_eq!(subcode, "network_error");
assert_eq!(message, "dns failure");
}
other => panic!("expected Custom, got {other:?}"),
}
}
#[test]
fn execution_uses_detail_as_message() {
let err = ToolError::execution(
tid("worker"),
"image generation failed: model returned empty response",
)
.with_source(anyhow::anyhow!("root cause"));
let wire: ToolErrorWire = err.into();
match wire {
ToolErrorWire::Execution { tool_id, message } => {
assert_eq!(tool_id, tid("worker"));
assert_eq!(
message,
"image generation failed: model returned empty response"
);
}
other => panic!("expected Execution, got {other:?}"),
}
}
#[test]
fn custom_round_trips_code_message_details() {
let err = ToolError::custom("billing_overflow", "quota exhausted")
.with_details(json!({"code": "billing_overflow", "limit": 1000}));
let wire: ToolErrorWire = err.into();
match wire {
ToolErrorWire::Custom {
subcode,
message,
details,
} => {
assert_eq!(subcode, "billing_overflow");
assert_eq!(message, "quota exhausted");
assert!(details.is_some());
}
other => panic!("expected Custom, got {other:?}"),
}
}
#[test]
fn variant_name_covers_all_kinds() {
let kinds = [
ToolErrorKind::NotImplemented,
ToolErrorKind::InvalidArguments,
ToolErrorKind::NotFound,
ToolErrorKind::PermissionDenied,
ToolErrorKind::Unauthorized,
ToolErrorKind::Timeout,
ToolErrorKind::Cancelled,
ToolErrorKind::RateLimited,
ToolErrorKind::ServiceUnavailable,
ToolErrorKind::NetworkError,
ToolErrorKind::Execution,
ToolErrorKind::BehaviorVersionUnsupported,
ToolErrorKind::RenderLimited,
ToolErrorKind::TerminalError,
ToolErrorKind::Custom,
];
let names: std::collections::HashSet<_> = kinds.iter().map(|k| k.as_str()).collect();
assert_eq!(names.len(), 15);
}
#[test]
fn display_shows_detail_not_kind() {
let err = ToolError::rate_limited("You've exceeded your quota.");
assert_eq!(err.to_string(), "You've exceeded your quota.");
}
#[test]
fn serde_json_error_converts_to_invalid_arguments() {
let err: ToolError = serde_json::from_str::<u32>("\"not a number\"")
.unwrap_err()
.into();
assert_eq!(err.kind, ToolErrorKind::InvalidArguments);
}
#[test]
fn with_source_preserves_detail() {
let err = ToolError::execution(tid("test"), "something broke")
.with_source(anyhow::anyhow!("inner cause"));
assert_eq!(err.detail, "something broke");
assert!(std::error::Error::source(&err).is_some());
}