§9 acceptance: grep-zero sweep — every internal x.ai/grok identifier renamed

The PRD's first acceptance gate now holds: grep -RinE '\bx\.ai\b|grok'
crates/ --include='*.rs' → 0 matches (exempt: NOTICE and third-party
license archives, README provenance, and the required 'Based on Grok
Build Open Source' attribution, now sourced from version_attribution.txt).

Wire-visible renames (both sides in this repo, changed in lockstep):
- Auth method id 'grok.com' → 'kimi-code' (AuthMethodKind::KimiCode).
- Every x.ai/* and _x.ai/* ACP ext method and meta key → kigi/* /
  _kigi/* (~200 names; grokShell → kigiShell). Session-file replay keeps
  a read-side alias for the legacy '_x.ai/session/update' method so
  existing updates.jsonl histories load; writes emit only the new name
  (both directions test-pinned).
- Agent types grok-build* → kigi* with a documented legacy-prefix alias
  at resolution time so persisted sessions keep resolving.
- ToolNamespace/BuiltinAgentName GrokBuild* → Kigi* (wire snake_case
  kigi/kigi_concise/kigi_hashline; schema regenerated); grok_build
  implementation dirs renamed to kigi*.
- x-grok-* headers → x-kigi-*, __GROK_* sentinels → __KIGI_*, themes
  grokday/groknight → kigiday/kiginight (old persisted values fall back
  to the default theme), web_fetch allowlist xAI hosts → kimi.com +
  moonshot platforms, changelog CDN → this repo, grok-build changelog
  archives deleted.
- BYOK default endpoint removed: [endpoints] api_base_url is now truly
  optional with NO default — consumers fail fast with the flag name when
  unset (no silent x.ai egress). Mock harnesses inject it explicitly.
- System-prompt identity fixed: 'released by xAI' → 'an unofficial
  community CLI for Kimi' (template + regenerated encrypted form).

Also repaired pre-existing grok-era test debt found by the sweep: the
stale trace_classify default-model pin, the grok-pager UA label test,
pty-harness stale-binary reuse and non-hermetic moonshot routing (a PTY
test could previously reach the real api.moonshot.cn), and the outdated
oauth fixture scope key.

Gates: §9 grep 0; fmt clean; workspace check/clippy 0/0 (-D warnings);
FULL cargo test --workspace: 234 suites, 21,961 passed, 0 failed;
deny advisories ok.
This commit is contained in:
2026-07-18 02:48:46 -04:00
parent 86e3724310
commit 6f31415ed6
1056 changed files with 8410 additions and 18307 deletions
+1 -1
View File
@@ -36,7 +36,7 @@ pub(crate) fn non_blocking_file_writer(path: &Path) -> std::io::Result<NonBlocki
}
/// Drop all parked worker guards, flushing their non-blocking writers. Call at
/// process exit so short-lived runs (e.g. headless `grok -p`) don't lose buffered logs.
/// process exit so short-lived runs (e.g. headless `kigi -p`) don't lose buffered logs.
pub(crate) fn flush_file_log_guards() {
if let Some(m) = FILE_LOG_GUARDS.get() {
// Recover from a poisoned mutex so exit-flush still drains the guards.
+21 -21
View File
@@ -28,15 +28,15 @@ use kigi_config::kigi_home;
/// Which env var requested a single-file debug log (drives filter and diagnostics).
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum DebugSource {
GrokLogFile,
GrokDebugLog,
KigiLogFile,
KigiDebugLog,
}
impl DebugSource {
fn label(self) -> &'static str {
match self {
Self::GrokLogFile => "KIGI_LOG_FILE",
Self::GrokDebugLog => "KIGI_DEBUG_LOG",
Self::KigiLogFile => "KIGI_LOG_FILE",
Self::KigiDebugLog => "KIGI_DEBUG_LOG",
}
}
}
@@ -62,7 +62,7 @@ pub const RMCP_SSE_NOISE_TARGET: &str = "rmcp::transport::common::client_side_ss
// Broad firehose filter for the routing/KIGI_DEBUG_LOG sources: capture our
// crates at debug regardless of a narrowing RUST_LOG, with deps at info so they
// don't flood. Curated first-party allowlist: new grok crates default to `info`
// don't flood. Curated first-party allowlist: new kigi crates default to `info`
// until added here.
const FIREHOSE_BASE_DIRECTIVES: &str = "info,kigi_tui=debug,kigi_shell=debug,kigi_tools=debug,kigi_log=debug,kigi_agent=debug,kigi_mcp=debug,kigi_acp_lib=debug,sampling_log=off";
@@ -382,8 +382,8 @@ where
}
Some(DebugTarget::SingleFile { path, src }) => {
let filter = match src {
DebugSource::GrokLogFile => default_file_filter(),
DebugSource::GrokDebugLog => firehose_filter(),
DebugSource::KigiLogFile => default_file_filter(),
DebugSource::KigiDebugLog => firehose_filter(),
};
match build_file_layer::<S>(&path, filter) {
Ok(layer) => registry.with(layer).init(),
@@ -417,11 +417,11 @@ pub(crate) enum DebugTarget {
///
/// Read via `var_os` (not `var`) so a non-UTF-8 path isn't silently dropped.
pub(crate) fn resolve_debug_target() -> Option<DebugTarget> {
let grok_log_file = std::env::var_os("KIGI_LOG_FILE");
let grok_debug_log = std::env::var_os("KIGI_DEBUG_LOG");
let kigi_log_file = std::env::var_os("KIGI_LOG_FILE");
let kigi_debug_log = std::env::var_os("KIGI_DEBUG_LOG");
resolve_debug_target_inner(
grok_log_file.as_deref(),
grok_debug_log.as_deref(),
kigi_log_file.as_deref(),
kigi_debug_log.as_deref(),
&kigi_home().join("debug"),
)
}
@@ -447,19 +447,19 @@ fn os_path(v: &OsStr) -> PathBuf {
// `OsStr` so non-UTF-8 paths round-trip; only the bool-vs-path discrimination
// needs UTF-8 (a non-UTF-8 value can't be a bool keyword, so it's a path).
fn resolve_debug_target_inner(
grok_log_file: Option<&OsStr>,
grok_debug_log: Option<&OsStr>,
kigi_log_file: Option<&OsStr>,
kigi_debug_log: Option<&OsStr>,
debug_dir: &Path,
) -> Option<DebugTarget> {
if let Some(raw) = grok_log_file
if let Some(raw) = kigi_log_file
&& !is_blank(raw)
{
return Some(DebugTarget::SingleFile {
path: os_path(raw),
src: DebugSource::GrokLogFile,
src: DebugSource::KigiLogFile,
});
}
let raw = grok_debug_log?;
let raw = kigi_debug_log?;
match raw.to_str().map(str::trim) {
Some("" | "0" | "false" | "off" | "no") => None,
Some("1" | "true" | "on" | "yes") => Some(DebugTarget::PerSession {
@@ -468,7 +468,7 @@ fn resolve_debug_target_inner(
// Any other UTF-8 value, or a non-UTF-8 value (`None`), is an explicit path.
_ => Some(DebugTarget::SingleFile {
path: os_path(raw),
src: DebugSource::GrokDebugLog,
src: DebugSource::KigiDebugLog,
}),
}
}
@@ -596,7 +596,7 @@ mod tests {
target,
DebugTarget::SingleFile {
path: PathBuf::from("/tmp/custom.log"),
src: DebugSource::GrokDebugLog,
src: DebugSource::KigiDebugLog,
}
);
}
@@ -613,7 +613,7 @@ mod tests {
target,
DebugTarget::SingleFile {
path: PathBuf::from("/tmp/explicit.log"),
src: DebugSource::GrokLogFile,
src: DebugSource::KigiLogFile,
}
);
}
@@ -651,7 +651,7 @@ mod tests {
let target = resolve_debug_target_inner(None, Some(raw), Path::new("/debug")).unwrap();
match target {
DebugTarget::SingleFile { path, src } => {
assert_eq!(src, DebugSource::GrokDebugLog);
assert_eq!(src, DebugSource::KigiDebugLog);
assert_eq!(path.as_os_str(), raw);
}
other => panic!("expected SingleFile for non-UTF-8 path, got {other:?}"),
@@ -954,7 +954,7 @@ mod tests {
fn prune_old_logs_missing_dir_is_noop() {
// Best-effort: a nonexistent debug dir must not panic.
prune_old_logs(
Path::new("/no/such/grok/debug/dir"),
Path::new("/no/such/kigi/debug/dir"),
std::time::Duration::from_secs(1),
);
}
+3 -3
View File
@@ -12,9 +12,9 @@
//! ## Enabling
//!
//! ```bash
//! KIGI_HOOKS_LOG=1 grok # enable, write to ~/.kigi/logs/hooks.log
//! KIGI_HOOKS_LOG=/tmp/h.log grok # write to custom path
//! KIGI_HOOKS_LOG=0 grok # explicitly disable
//! KIGI_HOOKS_LOG=1 kigi # enable, write to ~/.kigi/logs/hooks.log
//! KIGI_HOOKS_LOG=/tmp/h.log kigi # write to custom path
//! KIGI_HOOKS_LOG=0 kigi # explicitly disable
//! tail -f ~/.kigi/logs/hooks.log # watch in another terminal
//! ```
+1 -1
View File
@@ -13,7 +13,7 @@
//!
//! ```bash
//! # build with memory logging enabled, then:
//! KIGI_MEMORY_LOG=0 grok # disable even when enabled
//! KIGI_MEMORY_LOG=0 kigi # disable even when enabled
//! tail -f ~/.kigi/logs/memory.log # watch in another terminal
//! ```
+13 -13
View File
@@ -1,7 +1,7 @@
//! Centralized unified log for cross-component session observability.
//!
//! Shell writes directly via [`emit()`]. Pager and desktop forward entries
//! over ACP (`x.ai/log` notifications); shell receives them in
//! over ACP (`kigi/log` notifications); shell receives them in
//! [`ingest_client_entries()`] and writes on their behalf.
use std::fs::{self, File, OpenOptions};
@@ -29,7 +29,7 @@ const LOG_FILE: &str = "unified.jsonl";
pub const MAX_SIZE: u64 = 5 * 1024 * 1024; // 5 MB
/// ACP method name for unified log notifications.
pub const LOG_METHOD: &str = "x.ai/log";
pub const LOG_METHOD: &str = "kigi/log";
// ---------------------------------------------------------------------------
// Log entry types
@@ -52,12 +52,12 @@ pub enum LogSource {
#[strum(serialize = "shell")]
#[serde(rename = "shell")]
Shell,
#[strum(serialize = "grok-pager")]
#[serde(rename = "grok-pager")]
GrokPager,
#[strum(serialize = "grok-desktop")]
#[serde(rename = "grok-desktop")]
GrokDesktop,
#[strum(serialize = "kigi-pager")]
#[serde(rename = "kigi-pager")]
KigiPager,
#[strum(serialize = "kigi-desktop")]
#[serde(rename = "kigi-desktop")]
KigiDesktop,
}
/// A single unified log entry, written as one JSONL line.
@@ -95,7 +95,7 @@ pub struct LogEntry {
pub ctx: Option<serde_json::Value>,
}
/// Wire format for the `x.ai/log` ACP notification params.
/// Wire format for the `kigi/log` ACP notification params.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LogNotificationParams {
/// Source component identifier.
@@ -254,7 +254,7 @@ pub fn emit(lvl: LogLevel, msg: &str, sid: Option<&str>, ctx: Option<serde_json:
/// Ingest a batch of log entries from a client (pager or desktop).
///
/// Called by the `x.ai/log` notification handler. Entries from
/// Called by the `kigi/log` notification handler. Entries from
/// [`LogSource::Shell`] are rejected to prevent spoofing.
pub fn ingest_client_entries(src: LogSource, entries: &[ClientLogEntry]) {
if matches!(src, LogSource::Shell) || entries.is_empty() {
@@ -381,7 +381,7 @@ mod tests {
fn log_entry_serializes_full() {
let entry = LogEntry {
ts: "2025-07-14T10:30:00.123Z".into(),
src: LogSource::GrokPager,
src: LogSource::KigiPager,
pid: Some(4242),
ver: Some("0.1.211".into()),
lvl: LogLevel::Warn,
@@ -465,7 +465,7 @@ mod tests {
for bad in &[
r#"{"src":"evil","entries":[]}"#,
r#"{"src":"","entries":[]}"#,
r#"{"src":"GROK-PAGER","entries":[]}"#,
r#"{"src":"KIGI-PAGER","entries":[]}"#,
] {
assert!(serde_json::from_str::<LogNotificationParams>(bad).is_err());
}
@@ -474,7 +474,7 @@ mod tests {
#[test]
fn notification_params_round_trip() {
let params = LogNotificationParams {
src: LogSource::GrokPager,
src: LogSource::KigiPager,
entries: vec![
ClientLogEntry {
ts: "2025-07-14T10:30:00.123Z".into(),