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,121 @@
use super::*;
#[test]
fn protocol_matrix_matches_supported_terminals() {
for (brand, expected) in [
(TerminalName::Kitty, GraphicsProtocol::Kitty),
(TerminalName::Ghostty, GraphicsProtocol::Kitty),
(TerminalName::WezTerm, GraphicsProtocol::Kitty),
(TerminalName::WarpTerminal, GraphicsProtocol::Kitty),
(TerminalName::Iterm2, GraphicsProtocol::None),
(TerminalName::Unknown, GraphicsProtocol::None),
] {
assert_eq!(protocol_for_brand(brand, false), expected);
assert_eq!(protocol_for_brand(brand, true), GraphicsProtocol::None);
}
}
#[test]
fn scrollback_overlay_excludes_warp() {
assert!(scrollback_inline_overlay_active_for_brand(
GraphicsProtocol::Kitty,
TerminalName::Kitty,
));
assert!(!scrollback_inline_overlay_active_for_brand(
GraphicsProtocol::Kitty,
TerminalName::WarpTerminal,
));
}
#[test]
#[serial_test::serial]
fn force_off_overrides_capability() {
let _guard = set_protocol_for_test(GraphicsProtocol::Kitty);
set_inline_overlay_force_off(false);
assert!(scrollback_inline_overlay_active());
set_inline_overlay_force_off(true);
assert!(!scrollback_inline_overlay_active());
set_inline_overlay_force_off(false);
}
#[test]
fn kitty_escape_chunks_and_preserves_cursor() {
let small = render_kitty_image(&[0u8; 10], KittyImageFormat::Png, 40, 20);
assert!(small.contains("a=T"));
assert!(small.contains("f=100"));
assert!(small.contains("q=2"));
assert!(small.contains("C=1"));
assert!(small.contains("c=40"));
assert!(small.contains("r=20"));
assert!(small.contains("m=0"));
let large = render_kitty_image(&vec![0u8; 5000], KittyImageFormat::Png, 40, 20);
assert!(large.matches("\x1b_G").count() > 1);
}
#[test]
fn kitty_format_and_conversion_produce_png() {
use image::{ImageBuffer, Rgb};
let png = [0x89, b'P', b'N', b'G', b'\r', b'\n', 0x1a, b'\n'];
assert_eq!(kitty_format_from_bytes(&png), Some(KittyImageFormat::Png));
let buffer: ImageBuffer<Rgb<u8>, Vec<u8>> = ImageBuffer::from_pixel(4, 3, Rgb([128, 64, 32]));
let mut jpeg = Vec::new();
buffer
.write_to(
&mut std::io::Cursor::new(&mut jpeg),
image::ImageFormat::Jpeg,
)
.unwrap();
assert_eq!(kitty_format_from_bytes(&jpeg), None);
let converted = prepare_kitty_overlay_image_bytes(&jpeg).unwrap();
assert_eq!(
kitty_format_from_bytes(&converted),
Some(KittyImageFormat::Png)
);
}
#[test]
fn iterm_escape_preserves_requested_geometry() {
let escape = render_iterm2_image(&[0u8; 10], 30, 15);
assert!(escape.starts_with("\x1b]1337;File="));
assert!(escape.contains("width=30cells"));
assert!(escape.contains("height=15cells"));
assert!(escape.contains("preserveAspectRatio=1"));
}
#[test]
fn low_level_overlay_separates_transmit_from_placement() {
let png = [0x89, b'P', b'N', b'G', b'\r', b'\n', 0x1a, b'\n'];
let protocol = GraphicsProtocol::Kitty;
let first =
build_overlay_image_escapes_for_protocol(protocol, &png, 20, 10, 0, 0, true).unwrap();
let subsequent =
build_overlay_image_escapes_for_protocol(protocol, &png, 20, 10, 0, 0, false).unwrap();
assert!(first.contains("a=t") && first.contains("a=p"));
assert!(!first.contains("a=T"));
assert!(subsequent.contains("a=p"));
assert!(!subsequent.contains("a=t"));
}
#[test]
fn iterm_place_can_skip_inline_data() {
let _guard = set_protocol_for_test(GraphicsProtocol::ITerm2);
let area = ratatui::layout::Rect::new(0, 0, 40, 20);
let escape = place_inline_image(&[0u8; 10], 100, 50, area, 20, 0, 2, false).unwrap();
assert!(escape.starts_with("\x1b["));
assert!(!escape.contains("1337"));
}
#[test]
fn placement_only_steady_state_removes_payload_cost() {
let mut png = vec![0x89, b'P', b'N', b'G', b'\r', b'\n', 0x1a, b'\n'];
png.extend(std::iter::repeat_n(0u8, 200_000));
let protocol = GraphicsProtocol::Kitty;
let first =
build_overlay_image_escapes_for_protocol(protocol, &png, 40, 20, 0, 0, true).unwrap();
let subsequent =
build_overlay_image_escapes_for_protocol(protocol, &png, 40, 20, 0, 0, false).unwrap();
assert!(first.len() > 200_000);
assert!(subsequent.len() < 200);
assert!(!subsequent.contains("a=t"));
}