F3: Kimi inference pipeline + full grok cloud-surface excision

Sampler / inference (PRD F3):
- kimi_compat.rs: single adaptation point for the Kimi chat/completions
  dialect (thinking-field mapping, model_id stripping, empty-content
  tool-call message fix, stream_options.include_usage), with kimi-cli
  source citations
- Rate-limit handling reworked for Kimi/Moonshot semantics; UA kigi/{version}
- /models replaces the xAI models-v2 endpoint everywhere; idle model
  refresh carries X-Msh-* device headers only (X-XAI-Token-Auth and
  x-grok-client-mode/CLIENT_MODE_HEADER machinery deleted)

Cloud-surface excision (PRD §5, zero-egress):
- remote/ conversations lane, cli-chat-proxy-types crate, prod/ dir,
  share command, credit bar: deleted (single local session lane;
  paginate() replaces merge_and_paginate)
- Subscription/tier gate stack deleted end-to-end: AppView
  gate/tier/team/ZDR fields, app/subscription.rs watch loop,
  dispatch/billing.rs paywall + SuperGrok upsell, free-usage-exhausted
  chain, tier-restricted commands, GateInfo, RemoteSettings gate fields,
  SettingsUpdateNotification gate fields
- /privacy + coding-data-sharing setting deleted (backed by a dead xAI
  RPC; Kigi is zero-egress — nothing to share or retain remotely)

Auth UX correctness (user-reported):
- Device-flow fixtures now mirror the live Kimi payload shape
  (https://www.kimi.com/code/authorize_device?user_code=..., verified
  against auth.kimi.com); the fabricated auth.kimi.com/device?code=...
  URLs are gone
- open_browser_detached is a no-op under cfg(test): unit tests drove
  wiremock fixture URLs into the real browser (root cause of the
  "garbage mock link" ABCD-1234 tabs)
- Welcome/pager-minimal rebrand: Grok Build -> Kigi, grok.com ->
  kimi.com, "Sign in to Grok" -> "Sign in to Kimi"
This commit is contained in:
2026-07-17 16:05:51 -04:00
parent fe1f885bb3
commit ea0ce9d15f
231 changed files with 4730 additions and 26358 deletions
+6 -102
View File
@@ -1,7 +1,5 @@
use anyhow::Result;
use clap::Subcommand;
use kigi_shell::agent::config::Config as AgentConfig;
use kigi_shell::auth::{AuthManager, try_ensure_fresh_auth};
use kigi_shell::session::merge::MergedSession;
use kigi_shell::util::kigi_home::kigi_home;
#[derive(Debug, clap::Args, Clone)]
@@ -33,41 +31,17 @@ enum SessionsCommand {
},
}
pub async fn run(args: SessionsArgs, agent_config: &AgentConfig) -> Result<()> {
// Best-effort only. Do not force an interactive public login for enterprise
// deployments that only configure a deployment_key + custom xai_api_base_url.
// If the user has previously run the interactive `grok` TUI (which succeeds
// for these setups), any cached credential will be used. Otherwise we still
// proceed so the SessionRegistryClient can use the deployment_key when
// talking to the custom proxy.
let auth = try_ensure_fresh_auth(&agent_config.kimi_code_config).await;
let auth_manager = std::sync::Arc::new(AuthManager::new(
&kigi_home(),
agent_config.kimi_code_config.clone(),
));
let client = kigi_shell::agent::session_registry_client::SessionRegistryClient::new(
agent_config.endpoints.proxy_url(),
String::new(),
)
.with_deployment_key(agent_config.endpoints.deployment_key.clone())
.with_alpha_test_key(agent_config.endpoints.alpha_test_key.clone())
.with_auth(auth_manager.clone());
pub async fn run(args: SessionsArgs) -> Result<()> {
let cwd = std::env::current_dir().unwrap_or_else(|_| ".".into());
match args.command {
SessionsCommand::List { limit } => {
let sessions =
kigi_shell::session::merge::fetch_merged(Some(&client), cwd.to_str(), None, limit)
.await;
kigi_shell::session::merge::fetch_merged(None, cwd.to_str(), None, limit).await;
print_sessions_grouped(&sessions);
}
SessionsCommand::Search { query, limit } => {
use kigi_shell::session::merge::REMOTE_TIMEOUT;
use kigi_shell::session::storage::search::{SessionSearchRequest, execute_search};
use std::collections::HashSet;
let req = SessionSearchRequest {
query,
@@ -78,28 +52,7 @@ pub async fn run(args: SessionsArgs, agent_config: &AgentConfig) -> Result<()> {
};
let root = kigi_home();
let remote_limit = (limit * 3).max(100) as i64;
let (local_resp, remote_results) = tokio::join!(execute_search(&root, &req), async {
tokio::time::timeout(
REMOTE_TIMEOUT,
client.search(Some(&req.query), remote_limit),
)
.await
.unwrap_or_else(|_| {
eprintln!(
"warning: remote session search timed out, showing local results only"
);
Ok(Vec::new())
})
.unwrap_or_else(|e| {
eprintln!("warning: remote session search failed: {e}");
Vec::new()
})
});
let resp = local_resp?;
let local_ids: HashSet<&str> =
resp.results.iter().map(|r| r.session_id.as_str()).collect();
let resp = execute_search(&root, &req).await?;
for hit in &resp.results {
let title = if hit.title.is_empty() {
@@ -124,63 +77,14 @@ pub async fn run(args: SessionsArgs, agent_config: &AgentConfig) -> Result<()> {
);
}
let remaining = limit.saturating_sub(resp.results.len());
let mut remote_shown = 0usize;
for r in &remote_results {
if remote_shown >= remaining {
break;
}
if local_ids.contains(r.session_id.as_str()) {
continue;
}
let title = if r.summary.is_empty() {
"(untitled)"
} else {
&r.summary
};
let time = chrono::DateTime::parse_from_rfc3339(&r.updated_at)
.map(|dt| {
dt.with_timezone(&chrono::Local)
.format("%b %d, %l:%M%P")
.to_string()
})
.unwrap_or_default();
let snippet: String = r
.first_prompt
.as_deref()
.unwrap_or("")
.chars()
.take(80)
.collect();
println!(
"{} (remote) {}\n {}\n {}",
r.session_id, time, title, snippet
);
remote_shown += 1;
}
println!("\nTotal: {}", resp.results.len() + remote_shown);
println!("\nTotal: {}", resp.results.len());
}
SessionsCommand::Delete { id } => {
// Always attempt the remote delete when authenticated and not
// ZDR — `list` / `search` likewise query remote unconditionally
// rather than gating on storage mode (which the CLI cannot
// resolve here: it builds config without remote settings). The
// backend delete is idempotent (a `404` is treated as success),
// so this is safe for local-only sessions with no remote copy.
// ZDR teams never upload, so there is nothing remote to delete.
let needs_remote = auth.is_some();
// Pass `cwd = None` so the session is found by id regardless of
// which workspace it was created in; the local delete still uses
// the resolved per-session cwd.
let deletion = kigi_shell::session::persistence::delete_session_history(
&id,
None,
needs_remote,
auth_manager.clone(),
)
.await?;
let deletion =
kigi_shell::session::persistence::delete_session_history(&id, None).await?;
if deletion.any_removed() {
println!("Deleted session {id}");