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,253 @@
|
||||
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)]
|
||||
pub struct SessionsArgs {
|
||||
#[command(subcommand)]
|
||||
command: SessionsCommand,
|
||||
}
|
||||
|
||||
#[derive(Debug, Subcommand, Clone)]
|
||||
enum SessionsCommand {
|
||||
/// List recent sessions (same as search with no query)
|
||||
List {
|
||||
/// Maximum number of sessions to show
|
||||
#[arg(short = 'n', long, default_value = "20")]
|
||||
limit: usize,
|
||||
},
|
||||
/// Search sessions by keyword
|
||||
Search {
|
||||
/// Search query (searches summaries and first prompts).
|
||||
query: String,
|
||||
/// Maximum number of sessions to show
|
||||
#[arg(short = 'n', long, default_value = "20")]
|
||||
limit: usize,
|
||||
},
|
||||
/// Permanently delete a session from history
|
||||
Delete {
|
||||
/// Session id to delete.
|
||||
id: String,
|
||||
},
|
||||
}
|
||||
|
||||
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.grok_com_config).await;
|
||||
|
||||
let auth_manager = std::sync::Arc::new(AuthManager::new(
|
||||
&kigi_home(),
|
||||
agent_config.grok_com_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());
|
||||
|
||||
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;
|
||||
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,
|
||||
cwd: Some(cwd.to_string_lossy().to_string()),
|
||||
limit,
|
||||
offset: 0,
|
||||
include_content: true,
|
||||
};
|
||||
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();
|
||||
|
||||
for hit in &resp.results {
|
||||
let title = if hit.title.is_empty() {
|
||||
"(untitled)"
|
||||
} else {
|
||||
&hit.title
|
||||
};
|
||||
let time = chrono::DateTime::from_timestamp(hit.updated_at_unix, 0)
|
||||
.map(|dt| {
|
||||
dt.with_timezone(&chrono::Local)
|
||||
.format("%b %d, %l:%M%P")
|
||||
.to_string()
|
||||
})
|
||||
.unwrap_or_default();
|
||||
println!(
|
||||
"{} (score: {:.2}) {}\n {}\n {}",
|
||||
hit.session_id,
|
||||
hit.score,
|
||||
time,
|
||||
title,
|
||||
hit.snippet.as_deref().unwrap_or("")
|
||||
);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
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.as_ref().is_some_and(|a| !a.is_zdr_team());
|
||||
|
||||
// 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?;
|
||||
|
||||
if deletion.any_removed() {
|
||||
println!("Deleted session {id}");
|
||||
} else {
|
||||
println!("No session found with id {id}.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Print sessions grouped by worktree label, preserving the original table
|
||||
/// format with a `Label: <label>` header before each group.
|
||||
fn print_sessions_grouped(sessions: &[MergedSession]) {
|
||||
if sessions.is_empty() {
|
||||
println!("No sessions found.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Group by worktree_label, sort alphabetically, None last.
|
||||
let mut groups: std::collections::BTreeMap<Option<&str>, Vec<&MergedSession>> =
|
||||
std::collections::BTreeMap::new();
|
||||
for s in sessions {
|
||||
groups
|
||||
.entry(s.worktree_label.as_deref())
|
||||
.or_default()
|
||||
.push(s);
|
||||
}
|
||||
|
||||
let header = format!(
|
||||
"{:<36} {:<10} {:<10} {:<10} {}",
|
||||
"SESSION ID", "CREATED", "UPDATED", "STATUS", "SUMMARY"
|
||||
);
|
||||
|
||||
// Labeled groups first (alphabetical), then unlabeled last.
|
||||
let none_group = groups.remove(&None);
|
||||
let print_group = |label_line: &str, members: &[&MergedSession]| {
|
||||
println!("\n{label_line}");
|
||||
println!("{header}");
|
||||
for s in members {
|
||||
let first_line;
|
||||
let summary: &str = if !s.summary.is_empty() {
|
||||
&s.summary
|
||||
} else if let Some(ref fp) = s.first_prompt
|
||||
&& let Some(line) = fp.lines().find(|l| !l.trim().is_empty())
|
||||
{
|
||||
first_line = line.trim().to_string();
|
||||
&first_line
|
||||
} else {
|
||||
"(no summary)"
|
||||
};
|
||||
let truncated: String = summary.chars().take(50).collect();
|
||||
let created = &s.created_at[..s.created_at.len().min(10)];
|
||||
let updated = &s.updated_at[..s.updated_at.len().min(10)];
|
||||
println!(
|
||||
"{} {} {} {} {}",
|
||||
s.session_id, created, updated, s.source, truncated
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
for (label, members) in &groups {
|
||||
let line = format!("Label: {}", label.unwrap_or(""));
|
||||
print_group(&line, members);
|
||||
}
|
||||
if let Some(members) = &none_group {
|
||||
print_group("(no label)", members);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user