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:
@@ -0,0 +1,172 @@
|
||||
//! Regression test: `update_config` must not leak values from
|
||||
//! `managed_config.toml` or `requirements.toml` into the user's `config.toml`.
|
||||
//!
|
||||
//! Bug: `update_config` used `load_effective_config()` (which merges all config
|
||||
//! layers) to populate the `Config` struct, then `save_config` wrote that merged
|
||||
//! result back to the user's `config.toml`. If `requirements.toml` contained
|
||||
//! `auto_update = false`, any unrelated config write (theme change, model
|
||||
//! preference, yolo toggle) would permanently poison the user's config.
|
||||
|
||||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::OnceLock;
|
||||
|
||||
use serial_test::serial;
|
||||
|
||||
/// Shared temp directory that lives for the entire test binary.
|
||||
/// All tests share this as KIGI_SHARE_DIR (the `OnceLock` in kigi-config
|
||||
/// only allows one value per process).
|
||||
fn test_home() -> &'static PathBuf {
|
||||
static HOME: OnceLock<PathBuf> = OnceLock::new();
|
||||
HOME.get_or_init(|| {
|
||||
let dir = tempfile::TempDir::new().unwrap();
|
||||
// Keep so the directory survives the entire test process.
|
||||
let path = dir.keep();
|
||||
// SAFETY: called once at init before other threads touch this var.
|
||||
unsafe { std::env::set_var("KIGI_SHARE_DIR", &path) };
|
||||
path
|
||||
})
|
||||
}
|
||||
|
||||
/// Clean up config files between tests.
|
||||
fn reset_config_files(home: &std::path::Path) {
|
||||
let _ = fs::remove_file(home.join("config.toml"));
|
||||
let _ = fs::remove_file(home.join("requirements.toml"));
|
||||
let _ = fs::remove_file(home.join("managed_config.toml"));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
async fn update_config_does_not_leak_requirements_into_user_config() {
|
||||
let home = test_home();
|
||||
reset_config_files(home);
|
||||
|
||||
// --- Arrange ---
|
||||
|
||||
// User's config.toml: auto_update = true
|
||||
fs::write(
|
||||
home.join("config.toml"),
|
||||
"[cli]\nauto_update = true\ninstaller = \"internal\"\n",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
// Enterprise requirements.toml overrides auto_update to false
|
||||
fs::write(
|
||||
home.join("requirements.toml"),
|
||||
"[cli]\nauto_update = false\n",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
// Sanity-check: effective config should show auto_update = false
|
||||
// (requirements wins over user config).
|
||||
let effective = kigi_shell::config::load_effective_config().unwrap();
|
||||
let effective_cfg = kigi_shell::util::config::load_config_from_toml(&effective);
|
||||
assert_eq!(
|
||||
effective_cfg.cli.auto_update,
|
||||
Some(false),
|
||||
"precondition: effective config should merge requirements (auto_update=false)"
|
||||
);
|
||||
|
||||
// --- Act ---
|
||||
// Simulate an unrelated config write (e.g. persisting a model preference).
|
||||
kigi_shell::util::config::update_config(|cfg| {
|
||||
cfg.models.default = Some("grok-3".to_string());
|
||||
})
|
||||
.await
|
||||
.expect("update_config should succeed");
|
||||
|
||||
// --- Assert ---
|
||||
// Read the user's config.toml back from disk (raw, no merge).
|
||||
let raw = fs::read_to_string(home.join("config.toml")).unwrap();
|
||||
let user_toml: toml::Value = toml::from_str(&raw).unwrap();
|
||||
let user_cfg = kigi_shell::util::config::load_config_from_toml(&user_toml);
|
||||
|
||||
assert_eq!(
|
||||
user_cfg.cli.auto_update,
|
||||
Some(true),
|
||||
"BUG REPRODUCED: auto_update in user config.toml was overwritten by \
|
||||
requirements.toml value. The raw file contents:\n{raw}"
|
||||
);
|
||||
|
||||
// Also verify the unrelated write succeeded.
|
||||
assert_eq!(user_cfg.models.default.as_deref(), Some("grok-3"));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
async fn update_config_preserves_none_when_only_requirements_sets_value() {
|
||||
let home = test_home();
|
||||
reset_config_files(home);
|
||||
|
||||
// User config has no auto_update field at all
|
||||
fs::write(
|
||||
home.join("config.toml"),
|
||||
"[cli]\ninstaller = \"internal\"\n",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
// requirements.toml sets auto_update = false
|
||||
fs::write(
|
||||
home.join("requirements.toml"),
|
||||
"[cli]\nauto_update = false\n",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
// Write an unrelated field
|
||||
kigi_shell::util::config::update_config(|cfg| {
|
||||
cfg.ui.yolo = true;
|
||||
})
|
||||
.await
|
||||
.expect("update_config should succeed");
|
||||
|
||||
// Read back
|
||||
let raw = fs::read_to_string(home.join("config.toml")).unwrap();
|
||||
let user_toml: toml::Value = toml::from_str(&raw).unwrap();
|
||||
let user_cfg = kigi_shell::util::config::load_config_from_toml(&user_toml);
|
||||
|
||||
assert_eq!(
|
||||
user_cfg.cli.auto_update, None,
|
||||
"auto_update should remain absent in user config — requirements.toml \
|
||||
value must not leak. Raw file:\n{raw}"
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
async fn update_config_does_not_leak_managed_config_values() {
|
||||
let home = test_home();
|
||||
reset_config_files(home);
|
||||
|
||||
// User config has no auto_update — only installer
|
||||
fs::write(
|
||||
home.join("config.toml"),
|
||||
"[cli]\ninstaller = \"internal\"\n",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
// managed_config.toml sets auto_update = false and channel = "stable"
|
||||
fs::write(
|
||||
home.join("managed_config.toml"),
|
||||
"[cli]\nauto_update = false\nchannel = \"stable\"\n",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
kigi_shell::util::config::update_config(|cfg| {
|
||||
cfg.models.default = Some("test-model".to_string());
|
||||
})
|
||||
.await
|
||||
.expect("update_config should succeed");
|
||||
|
||||
let raw = fs::read_to_string(home.join("config.toml")).unwrap();
|
||||
let user_toml: toml::Value = toml::from_str(&raw).unwrap();
|
||||
let user_cfg = kigi_shell::util::config::load_config_from_toml(&user_toml);
|
||||
|
||||
assert_eq!(
|
||||
user_cfg.cli.auto_update, None,
|
||||
"auto_update from managed_config.toml leaked into user config. Raw:\n{raw}"
|
||||
);
|
||||
assert_eq!(
|
||||
user_cfg.cli.channel, None,
|
||||
"channel from managed_config.toml leaked into user config. Raw:\n{raw}"
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user