Skip to content

graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs

Python

gui: wire Kimi OAuth device-code re-auth (same flow as the CLI)

Rach Pradhan1348f9917927
diff --git a/gui/src-tauri/src/dto/runtime.rs b/gui/src-tauri/src/dto/runtime.rs
index ce3f600d..15148f0d 100644
--- a/gui/src-tauri/src/dto/runtime.rs
+++ b/gui/src-tauri/src/dto/runtime.rs
@@ -300,6 +300,9 @@ pub enum ProviderAuthMethodKindDto {
AwsProfile,
CodexDevice,
CodegraffDevice,
+ /// Kimi Code device-code OAuth (`graff login kimi`). Kimi also accepts an
+ /// API key, so this is offered as a second auth method alongside `ApiKey`.
+ KimiDevice,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, TS)]
diff --git a/gui/src-tauri/src/runtime/simple.rs b/gui/src-tauri/src/runtime/simple.rs
index fd09b6ae..79572ff6 100644
--- a/gui/src-tauri/src/runtime/simple.rs
+++ b/gui/src-tauri/src/runtime/simple.rs
@@ -358,6 +358,13 @@ impl RuntimeManager {
"Codex login launched in Terminal. Complete the browser OAuth flow there, then finish setup here.",
))
}
+ ProviderAuthMethodKindDto::KimiDevice => {
+ launch_codegraff_login(Some("kimi")).await?;
+ Ok(cli_login_session(
+ &input.provider_id,
+ "Kimi login launched in Terminal. Complete the device-code flow there, then finish setup here.",
+ ))
+ }
_ => anyhow::bail!("Unsupported auth method for {}", input.provider_id),
}
}
@@ -3000,14 +3007,24 @@ fn provider_summary_with_key_list(
provider: &CodegraffProvider,
key_list: &str,
) -> ProviderSummaryDto {
+ let mut auth_methods = vec![ProviderAuthMethodDto {
+ kind: provider.auth_method.clone(),
+ label: provider_auth_label(provider),
+ }];
+ // Kimi accepts both an API key and a device-code OAuth login (`graff login
+ // kimi`). Offer both so users can re-auth via the CLI's OAuth flow when
+ // their key is removed or expires — mirroring codegraff/codex.
+ if provider.id == "kimi" {
+ auth_methods.push(ProviderAuthMethodDto {
+ kind: ProviderAuthMethodKindDto::KimiDevice,
+ label: "Kimi Code device login".into(),
+ });
+ }
ProviderSummaryDto {
id: provider.id.clone(),
name: provider.name.clone(),
configured: provider_configured(provider, key_list),
- auth_methods: vec![ProviderAuthMethodDto {
- kind: provider.auth_method.clone(),
- label: provider_auth_label(provider),
- }],
+ auth_methods,
env_override: provider_env_override(provider),
}
}
@@ -3090,6 +3107,7 @@ fn provider_auth_label(provider: &CodegraffProvider) -> String {
.unwrap_or_else(|| "API key".into()),
ProviderAuthMethodKindDto::CodegraffDevice => "Codegraff device login".into(),
ProviderAuthMethodKindDto::CodexDevice => "Codex browser login".into(),
+ ProviderAuthMethodKindDto::KimiDevice => "Kimi Code device login".into(),
_ => "Unsupported".into(),
}
}
@@ -3120,6 +3138,10 @@ fn provider_login_configured(
|| key_list_mentions_provider(key_list, &provider.id)
}
"codex" => home_codex_auth_has_valid_token(home),
+ "kimi" => {
+ key_list_mentions_provider(key_list, &provider.id)
+ || kimi_auth_has_valid_token(home)
+ }
_ => key_list_mentions_provider(key_list, &provider.id),
}
}
@@ -3146,6 +3168,27 @@ fn home_codex_auth_has_valid_token(home: Option<&Path>) -> bool {
.unwrap_or(false)
}
+/// Kimi OAuth login (`graff login kimi`) writes a JSON token file to
+/// `~/.kimi/credentials/graff-oauth.json`. The CLI auto-refreshes the
+/// access token when near expiry, so a non-empty access_token means logged in.
+fn kimi_auth_has_valid_token(home: Option<&Path>) -> bool {
+ home.map(|home| {
+ let path = home.join(".kimi/credentials/graff-oauth.json");
+ let Ok(text) = std::fs::read_to_string(&path) else {
+ return false;
+ };
+ let Ok(value) = serde_json::from_str::<serde_json::Value>(&text) else {
+ return false;
+ };
+ value
+ .get("access_token")
+ .and_then(|token| token.as_str())
+ .map(|token| !token.trim().is_empty())
+ .unwrap_or(false)
+ })
+ .unwrap_or(false)
+}
+
fn codex_auth_file_has_valid_token(path: &Path) -> bool {
let Ok(text) = std::fs::read_to_string(path) else {
return false;
@@ -3259,6 +3302,9 @@ fn remove_stored_credential(provider_id: &str) -> Result<()> {
"codex" => {
let _ = std::fs::remove_file(home.join(".codex/auth.json"));
}
+ "kimi" => {
+ let _ = std::fs::remove_file(home.join(".kimi/credentials/graff-oauth.json"));
+ }
_ => {}
}
}
diff --git a/gui/src/components/providers-settings/utils/providerAuth.ts b/gui/src/components/providers-settings/utils/providerAuth.ts
index d0977481..af742720 100644
--- a/gui/src/components/providers-settings/utils/providerAuth.ts
+++ b/gui/src/components/providers-settings/utils/providerAuth.ts
@@ -11,6 +11,7 @@ function getAuthMethodPriority(method: ProviderAuthMethod) {
case "o_auth_device":
case "codex_device":
case "codegraff_device":
+ case "kimi_device":
return 1;
case "google_adc":
return 2;
@@ -29,7 +30,7 @@ export function getSortedAuthMethods(provider: ProviderSummary) {
export function supportsOauth(provider: ProviderSummary) {
return provider.authMethods.some((method) =>
- ["o_auth_code", "o_auth_device", "codex_device", "codegraff_device"].includes(method.kind),
+ ["o_auth_code", "o_auth_device", "codex_device", "codegraff_device", "kimi_device"].includes(method.kind),
);
}
diff --git a/gui/src/services/desktop/types/contracts.generated.ts b/gui/src/services/desktop/types/contracts.generated.ts
index 80315826..07a038ae 100644
--- a/gui/src/services/desktop/types/contracts.generated.ts
+++ b/gui/src/services/desktop/types/contracts.generated.ts
@@ -47,7 +47,7 @@ export type PromptSettings = { availableModels: Array<PromptModelOption>, select
export type UpdatePromptSettingsInput = { workspacePath: string | null, providerId: string, modelId: string, reasoningEffort: string | null, };
-export type ProviderAuthMethodKind = "api_key" | "o_auth_device" | "o_auth_code" | "google_adc" | "aws_profile" | "codex_device" | "codegraff_device";
+export type ProviderAuthMethodKind = "api_key" | "o_auth_device" | "o_auth_code" | "google_adc" | "aws_profile" | "codex_device" | "codegraff_device" | "kimi_device";
export type ProviderAuthMethod = { kind: ProviderAuthMethodKind, label: string, };