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:
ZacharyZhang-NY committed 2026-07-17 05:31:01 -04:00
commit d6c20fc13f
2612 files changed
+1353757

No files matched your search

@@ -0,0 +1,146 @@
mod golang;
mod javascript;
mod python;
mod rust;
mod ts;
pub mod types;
use std::collections::HashMap;
use std::hash::{Hash, Hasher};
use std::path::Path;
use std::sync::Arc;
pub use golang::golang;
pub use javascript::js_lang;
pub use python::python_lang;
pub use rust::rust_lang;
pub use ts::ts_lang;
pub use types::TSLanguageConfig;
/// Registry of all supported languages.
///
/// Provides lookup by extension and language ID, and can check if two
/// extensions belong to the same language family.
pub struct LanguageRegistry {
/// All registered language configs.
configs: Vec<Arc<TSLanguageConfig>>,
/// Mapping from file extension to language config.
by_extension: HashMap<String, Arc<TSLanguageConfig>>,
/// Mapping from language ID to language config.
by_id: HashMap<String, Arc<TSLanguageConfig>>,
}
impl LanguageRegistry {
/// Create a new language registry with all supported languages.
pub fn new() -> Self {
let configs: Vec<Arc<TSLanguageConfig>> = vec![
Arc::new(rust_lang()),
Arc::new(ts_lang()),
Arc::new(js_lang()),
Arc::new(golang()),
Arc::new(python_lang()),
];
let mut by_extension = HashMap::new();
let mut by_id = HashMap::new();
for config in &configs {
for ext in config.file_extensions() {
by_extension.insert(ext.clone(), Arc::clone(config));
}
for id in config.language_ids() {
by_id.insert(id.clone(), Arc::clone(config));
}
}
Self {
configs,
by_extension,
by_id,
}
}
/// Get a language config by file extension.
pub fn for_extension(&self, ext: &str) -> Option<Arc<TSLanguageConfig>> {
self.by_extension.get(ext).cloned()
}
/// Get a language config by language ID.
pub fn for_id(&self, id: &str) -> Option<Arc<TSLanguageConfig>> {
self.by_id.get(id).cloned()
}
/// Get a language config for a file path.
///
/// Extracts the extension from the path and looks up the config.
pub fn for_file_path(&self, path: impl AsRef<Path>) -> Option<Arc<TSLanguageConfig>> {
let path = path.as_ref();
let ext = path.extension()?.to_str()?;
self.for_extension(ext)
}
/// Check if a file path is supported (has a supported extension).
pub fn is_supported(&self, path: impl AsRef<Path>) -> bool {
self.for_file_path(path).is_some()
}
/// Get all supported file extensions.
pub fn supported_extensions(&self) -> Vec<&str> {
self.by_extension.keys().map(|s| s.as_str()).collect()
}
/// Get all language configs.
pub fn all_configs(&self) -> &[Arc<TSLanguageConfig>] {
&self.configs
}
/// Check if two file extensions belong to the same language.
///
/// Returns true if both extensions are registered under the same language config.
pub fn extensions_same_language(&self, ext1: &str, ext2: &str) -> bool {
if ext1 == ext2 {
return true;
}
match (self.by_extension.get(ext1), self.by_extension.get(ext2)) {
(Some(config1), Some(config2)) => {
// Compare by primary language ID (they point to the same config)
config1.primary_language_id() == config2.primary_language_id()
}
_ => false,
}
}
/// Compute a hash of all tree-sitter queries across all languages.
///
/// This is used to detect when queries change, which should trigger
/// a rebuild of the index even if file contents haven't changed.
///
/// The hash is computed by:
/// 1. Sorting languages by their primary ID for deterministic ordering
/// 2. Hashing each language's query string in order
/// 3. Combining into a single u64 hash
pub fn compute_query_hash(&self) -> u64 {
use std::collections::hash_map::DefaultHasher;
// Sort configs by primary language ID for deterministic ordering
let mut sorted_configs: Vec<_> = self.configs.iter().collect();
sorted_configs.sort_by_key(|c| c.primary_language_id());
let mut hasher = DefaultHasher::new();
for config in sorted_configs {
// Hash the language ID and query together
config.primary_language_id().hash(&mut hasher);
config.file_definition_queries().hash(&mut hasher);
}
hasher.finish()
}
}
impl Default for LanguageRegistry {
fn default() -> Self {
Self::new()
}
}