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,127 @@
//! Empty-composer Enter sends the top mid-turn queued follow-up now.
//!
//! Regression for send-now discoverability: plain Enter with text still
//! *queues*; a second bare Enter on the empty prompt is cancel-and-send — the
//! running turn is cancelled (silently: no "Turn cancelled by user" marker)
//! and the queued row runs as the next turn, arriving on the wire as a
//! standard `<user_query>` prompt with no interjection preamble.
use std::time::Duration;
use anyhow::{Context, Result, bail};
use super::wait_for_welcome;
use crate::{ContentController, PtyHarness, pager_binary};
const DEFAULT_ROWS: u16 = 50;
const DEFAULT_COLS: u16 = 120;
/// The interjection-merge preamble: send-now must never produce it.
const INTERJECTION_WIRE_PREFIX: &str = "The user sent a message while you were working";
fn slow_turn_text(sentinel: &str) -> String {
let mut s = String::from(sentinel);
for i in 0..30 {
s.push_str(&format!(" streaming{i}"));
}
s
}
fn all_user_message_blobs(content: &ContentController) -> Vec<String> {
content
.request_bodies()
.iter()
.flat_map(|b| {
let items = b["messages"].as_array().or_else(|| b["input"].as_array());
items
.into_iter()
.flatten()
.filter(|m| m["role"] == "user")
.map(|m| match m["content"].as_str() {
Some(s) => s.to_owned(),
None => m["content"].to_string(),
})
.collect::<Vec<_>>()
})
.collect()
}
/// Mid-turn queue via Enter, then empty Enter cancels the running turn and
/// runs that row as the next turn (cancel-and-send).
pub async fn assert_empty_enter_force_sends_top_queued() -> Result<()> {
let content = ContentController::start()
.await
.context("start ContentController")?;
// Gate turn 1's terminal event so the queue + empty-Enter provably land
// mid-turn — a paced-chunk window races turn end on slow (remote) workers.
content.hold_agent_completions();
content.set_turns([
slow_turn_text("TURNONE"),
"TURNTWO reply to the promoted follow-up.".to_owned(),
]);
let binary = pager_binary().context("resolve pager binary")?;
let mut harness =
PtyHarness::spawn_with_content(&binary, DEFAULT_ROWS, DEFAULT_COLS, &content, &[])
.context("spawn pager")?;
wait_for_welcome(&mut harness).await?;
harness.inject_keys(b"go\r").context("submit prompt")?;
harness
.wait_for_text("TURNONE", Duration::from_secs(30))
.context("turn 1 streaming")?;
harness
.inject_keys(b"please also check the logs\r")
.context("queue follow-up")?;
harness
.wait_for_text("please also check the logs", Duration::from_secs(10))
.context("queued text visible")?;
harness.inject_keys(b"\r").context("empty Enter send-now")?;
// Cancel-and-send: the shell cancels turn 1 (its held completion is
// irrelevant — the abort wins) and promotes the row to run as turn 2.
// Release the gate so any completion race resolves rather than hangs.
content.release_agent_completions();
// The promoted row renders as a standard user prompt block (" " prefix
// distinguishes the committed block from the prefix-less queue row) with
// the new turn's reply below it.
harness
.wait_for_text(
"\u{276F} please also check the logs",
Duration::from_secs(15),
)
.context("promoted prompt scrollback chrome")?;
harness
.wait_for_text("TURNTWO", Duration::from_secs(40))
.context("promoted turn reply")?;
// A send-now cancel is silent: no "Turn cancelled by user" marker may
// appear between the partial turn-1 output and the promoted prompt.
if harness.contains_text("Turn cancelled by user") {
bail!(
"send-now cancel must not render a cancelled marker\n{}",
harness.screen_contents()
);
}
let users = all_user_message_blobs(&content);
let Some(promoted) = users
.iter()
.find(|u| u.contains("please also check the logs"))
else {
bail!("queued follow-up never reached the wire: {users:#?}");
};
if promoted.contains(INTERJECTION_WIRE_PREFIX) {
bail!("send-now must not use the interjection preamble: {promoted}");
}
if !promoted.contains("<user_query>") {
bail!("send-now must arrive as a standard user_query prompt: {promoted}");
}
if harness.contains_text("panicked") {
bail!("pager panicked\n{}", harness.screen_contents());
}
harness.quit().context("clean quit")?;
Ok(())
}