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 @@
//! Prompt component — renders the welcome screen prompt using PromptWidget.
use ratatui::buffer::Buffer;
use ratatui::layout::Rect;
use crate::views::prompt_widget::{PromptInfo, PromptStyle, PromptWidget};
use super::WelcomePromptFocus;
pub fn prompt_inset(compact: bool) -> u16 {
if compact { 0 } else { 2 }
}
/// Render the welcome prompt using the shared PromptWidget.
/// Returns the cursor position and ownership-bearing post-flush output.
#[allow(clippy::too_many_arguments)]
pub fn render_prompt(
area: Rect,
buf: &mut Buffer,
focus: WelcomePromptFocus,
prompt: &mut PromptWidget,
info: &PromptInfo<'_>,
pad_left: u16,
pad_right: u16,
compact: bool,
) -> (
Option<(u16, u16)>,
Option<crate::terminal::overlay::PostFlush>,
) {
let focused = focus == WelcomePromptFocus::Focused;
let style = PromptStyle {
focused,
show_prefix: true,
vpad_top: 1,
compact,
chrome: true,
chrome_pad_left: pad_left,
chrome_pad_right: pad_right,
placeholder_override: Some("Type a message..."),
..PromptStyle::default()
};
// Inset the prompt area so the selection box border sits over dark background.
// In compact mode, no inset (prompt_inset returns 0) to match session layout.
let inset = prompt_inset(compact);
let inset_area = Rect {
x: area.x + inset,
y: area.y,
width: area.width.saturating_sub(inset * 2),
height: area.height,
};
let result = prompt.draw(buf, inset_area, None, &style, Some(info));
(result.cursor_pos, result.post_flush_escapes.map(Into::into))
}
#[cfg(test)]
mod tests {
use super::*;
use crate::terminal::image::{GraphicsProtocol, set_protocol_for_test};
use crossterm::Command;
fn png() -> [u8; 8] {
[0x89, b'P', b'N', b'G', b'\r', b'\n', 0x1a, b'\n']
}
#[test]
fn prompt_post_flush_keeps_ownership_when_plain_bytes_are_appended() {
let _guard = set_protocol_for_test(GraphicsProtocol::Kitty);
crate::terminal::overlay::reset_owner();
let _ = crate::terminal::overlay::static_image(&png(), 20, 10, 0, 0, 71)
.unwrap()
.commit();
let area = Rect::new(0, 0, 80, 3);
let mut buf = Buffer::empty(area);
let mut prompt = PromptWidget::new();
let info = PromptInfo {
model_name: "test",
flags: &[],
multiline: false,
usage_warning: None,
usage_warning_critical: false,
};
let (_, post_flush) = render_prompt(
area,
&mut buf,
WelcomePromptFocus::Focused,
&mut prompt,
&info,
2,
2,
false,
);
let mut post_flush = post_flush.expect("welcome clear");
let mut cursor_bytes = String::new();
let _ = crate::terminal::SetPointerCursor.write_ansi(&mut cursor_bytes);
assert!(!cursor_bytes.is_empty());
post_flush.append_plain(&cursor_bytes);
assert!(post_flush.as_str().contains("a=d"));
assert!(post_flush.as_str().ends_with(cursor_bytes.as_str()));
assert!(
!crate::terminal::overlay::static_image(&png(), 20, 10, 0, 0, 71)
.unwrap()
.as_str()
.contains("a=t"),
"constructing welcome output must not commit its clear"
);
let mut emitted = Vec::new();
post_flush.write_to(&mut emitted).unwrap();
assert!(
crate::terminal::overlay::static_image(&png(), 20, 10, 0, 0, 71)
.unwrap()
.as_str()
.contains("a=t"),
"writing welcome output must commit its clear"
);
}
}