F7: one-time read-only import of the official kimi-cli configuration
New `kigi import-kimi` (with --dry-run) plus a one-time welcome-screen
hint when ~/.kimi/config.toml is present and unimported.
- Sources: ~/.kimi/config.toml (default_model, [models.*], [providers.*])
and ~/.kimi/mcp.json ({"mcpServers": ...} — parsed by the existing
McpConfig machinery). Shapes ported from kimi-cli 1.49.0 config.py with
citations.
- Strictly read-only over ~/.kimi: plain reads only; the test suite pins
byte-identical contents AND unchanged mtimes across scan+apply. Keyring
credentials are never imported; KIMI_SHARE_DIR / any KIMI_* env var is
never consulted (official dir hardcoded to ~/.kimi).
- Mapping: MCP servers merge into kigi [mcp_servers.*] without clobbering
existing names; models on non-built-in providers become kigi [model.*]
custom entries (base_url + api_key + context_window); providers that
duplicate kigi's built-in Kimi/Moonshot platforms are skipped with a
note; default_model maps to the imported alias or the managed catalog
key and never overwrites an existing default.
- One-time marker ~/.kigi/kimi_import_done (claude-import convention);
the startup hint and re-runs no-op once set. api_key values flow only
into the user's own config.toml and are redacted in every summary.
Verified end-to-end with the real binary in a sandboxed home: dry-run,
apply, `kigi mcp list` shows both imported servers, second run no-ops,
~/.kimi mtimes unchanged. 8 unit tests + CLI parse test.
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
//! `kigi import-kimi` — one-time, read-only import of the official kimi-cli
|
||||
//! configuration (`~/.kimi`), PRD F7.
|
||||
//!
|
||||
//! Reads `~/.kimi/config.toml` + `~/.kimi/mcp.json` without modifying them
|
||||
//! and merges MCP servers, custom model providers, and the default-model
|
||||
//! preference into `~/.kigi/config.toml`. Existing kigi entries are never
|
||||
//! overwritten. A marker file under the kigi home makes the import one-time.
|
||||
|
||||
use anyhow::Result;
|
||||
|
||||
pub fn run(dry_run: bool) -> Result<()> {
|
||||
if kigi_shell::kimi_import::is_kimi_import_marked() {
|
||||
println!(
|
||||
"kimi-cli settings were already imported (marker: {}).\n\
|
||||
Delete the marker file and re-run to import again.",
|
||||
kigi_shell::kimi_import::kimi_import_marker_path().display()
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
let Some(plan) = kigi_shell::kimi_import::scan()? else {
|
||||
println!("Nothing to import: no importable settings found in ~/.kimi.");
|
||||
return Ok(());
|
||||
};
|
||||
print!("{}", plan.summary());
|
||||
if dry_run {
|
||||
println!("\nDry run: nothing was written.");
|
||||
return Ok(());
|
||||
}
|
||||
let applied = kigi_shell::kimi_import::apply(&plan)?;
|
||||
println!();
|
||||
print!("{}", applied.summary());
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user