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,131 @@
//! Project picker: select a project directory on first prompt from a non-project dir.
pub mod detection {
pub use kigi_file_utils::workspace_classifier::is_project_dir;
}
pub mod sources;
use std::path::{Path, PathBuf};
use kigi_tools::implementations::grok_build::ask_user_question::{Question, QuestionOption};
/// `resolved_paths` is index-aligned with the leading `question.options`.
/// The trailing "Don't ask me again" option at `dont_ask_index` has no
/// corresponding path (selecting it continues in the current directory).
pub struct ProjectQuestion {
pub question: Question,
pub resolved_paths: Vec<PathBuf>,
/// Option index of the "Don't ask me again" entry.
pub dont_ask_index: usize,
}
const MAX_RECENT_DIRS: usize = 5;
pub fn build_project_question(
recent_dirs: &[(PathBuf, chrono::DateTime<chrono::Utc>)],
cwd: &Path,
) -> ProjectQuestion {
let mut options = Vec::new();
let mut resolved_paths = Vec::new();
// First option: continue in the current directory.
let is_home = dirs::home_dir().is_some_and(|h| h == cwd);
let cwd_name = if is_home {
"~"
} else {
cwd.file_name()
.and_then(|n| n.to_str())
.unwrap_or("current directory")
};
options.push(QuestionOption {
label: format!("{cwd_name} (current)"),
description: sources::display_path(cwd),
preview: None,
id: None,
});
resolved_paths.push(cwd.to_path_buf());
// Recent project directories.
for (path, ts) in recent_dirs
.iter()
.filter(|(p, _)| p != cwd)
.take(MAX_RECENT_DIRS)
{
let raw_name = path.file_name().and_then(|n| n.to_str()).unwrap_or("?");
let name = crate::render::line_utils::truncate_str(raw_name, 22);
options.push(QuestionOption {
label: name,
description: format!(
"{} ({})",
sources::display_path(path),
crate::views::session_title::format_relative_time(
(chrono::Utc::now() - *ts).to_std().unwrap_or_default()
),
),
preview: None,
id: None,
});
resolved_paths.push(path.clone());
}
// Kept out of `resolved_paths` so the path options stay index-aligned.
let dont_ask_index = options.len();
options.push(QuestionOption {
label: "Don't ask me again".to_string(),
description: "Always start in the current directory (reset in config.toml)".to_string(),
preview: None,
id: None,
});
ProjectQuestion {
question: Question {
question: "Run Grok Build in a project directory?\n\n\
This gives Grok Build full context of your codebase for better results."
.into(),
id: None,
options,
multi_select: Some(false),
},
resolved_paths,
dont_ask_index,
}
}
#[cfg(test)]
mod tests {
use super::*;
use chrono::Utc;
#[test]
fn no_recent_dirs_returns_only_cwd() {
let pq = build_project_question(&[], Path::new("/home/user"));
assert_eq!(pq.resolved_paths.len(), 1);
assert_eq!(pq.resolved_paths[0], PathBuf::from("/home/user"));
}
#[test]
fn recent_dirs_index_aligned_with_options() {
let now = Utc::now();
let recent = vec![
(PathBuf::from("/projects/alpha"), now),
(PathBuf::from("/projects/beta"), now),
];
let pq = build_project_question(&recent, Path::new("/home/user"));
// Options carry one extra trailing "Don't ask me again" entry beyond
// the index-aligned path options.
assert_eq!(pq.question.options.len(), pq.resolved_paths.len() + 1);
assert_eq!(pq.resolved_paths[0], PathBuf::from("/home/user"));
assert_eq!(pq.resolved_paths[1], PathBuf::from("/projects/alpha"));
assert_eq!(pq.resolved_paths[2], PathBuf::from("/projects/beta"));
}
#[test]
fn dont_ask_option_is_last_and_excluded_from_paths() {
let pq = build_project_question(&[], Path::new("/home/user"));
assert_eq!(pq.dont_ask_index, pq.resolved_paths.len());
assert_eq!(pq.dont_ask_index, pq.question.options.len() - 1);
assert_eq!(
pq.question.options[pq.dont_ask_index].label,
"Don't ask me again"
);
}
}