Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ members = [
"crates/daemon",
"crates/desktop",
"crates/providers-cursor",
"crates/providers-kimi",
"crates/providers-openai",
"crates/providers-opencode-go",
"crates/providers-zai",
Expand All @@ -26,14 +27,15 @@ assert_cmd = "2.2.2"
async-trait = "0.1.89"
clap = { version = "4.6.1", features = ["derive"] }
directories = "6.0.0"
fs4 = "1.1.0"
gtk = { package = "gtk4", version = "0.11.4" }
insta = { version = "1.47.2", features = ["json"] }
jsonwebtoken = { version = "10.4.0", default-features = false }
keyring = { version = "4.1.2", default-features = false, features = ["v1"] }
libadwaita = { version = "0.9.1" }
predicates = "3.1.4"
relm4 = { version = "0.11.0", features = ["libadwaita", "gnome_50"] }
reqwest = { version = "0.13.4", default-features = false, features = ["json", "rustls"] }
reqwest = { version = "0.13.4", default-features = false, features = ["form", "json", "rustls"] }
rpassword = "7.3"
serde = { version = "1.0.228", features = ["derive"] }
serde_json = "1.0.150"
Expand Down
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# BrainDrain

BrainDrain shows coding-agent subscription usage in its CLI and desktop
frontends.

## Kimi Coding Plan

Install and sign in with the first-party
[Kimi Code CLI](https://github.com/MoonshotAI/kimi-cli), then run:

```console
braindrain check kimi
```

BrainDrain reads the OAuth credentials that Kimi Code stores at
`~/.kimi/credentials/kimi-code.json` (or under `KIMI_SHARE_DIR`), refreshes an
expiring token using the same cross-process lock and OAuth protocol, and fetches
subscription usage from `https://api.kimi.com/coding/v1/usages`. It preserves
unknown credential fields when Kimi rotates tokens. `KIMI_CODE_BASE_URL` can
override the API base for testing or compatible deployments; `KIMI_API_KEY` is
used only when no Kimi Code credential file exists.

Usage is subscription-wide and does not depend on a selected inference model, so
BrainDrain does not hard-code or rewrite Kimi's dynamic model catalog.

The implementation tracks the first-party protocol and storage layout at
MoonshotAI/kimi-cli commit
[`4a550eff`](https://github.com/MoonshotAI/kimi-cli/tree/4a550effdfcb29a25a5d325bf935296cc50cd417).
1 change: 1 addition & 0 deletions apps/linux/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub fn provider_title(id: &str) -> &str {
match id {
"openai" => "OpenAI",
"cursor" => "Cursor",
"kimi" => "Kimi Code",
"zai" => "z.ai",
"opencode-go" => "OpenCode Go",
other => other,
Expand Down
2 changes: 2 additions & 0 deletions apps/macos/Sources/BrainDrainApp/ProviderListModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ struct ProviderViewState: Identifiable {
"OpenAI"
case "cursor":
"Cursor"
case "kimi":
"Kimi Code"
case "zai":
"z.ai"
case "opencode-go":
Expand Down
3 changes: 3 additions & 0 deletions apps/plasma/package/contents/ui/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,9 @@ PlasmoidItem {
if (provider === "cursor") {
return "Cursor";
}
if (provider === "kimi") {
return "Kimi Code";
}
if (provider === "zai") {
return "z.ai";
}
Expand Down
5 changes: 5 additions & 0 deletions crates/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub struct ProviderId(String);
impl ProviderId {
pub const OPENAI: &'static str = "openai";
pub const CURSOR: &'static str = "cursor";
pub const KIMI: &'static str = "kimi";
pub const ZAI: &'static str = "zai";
pub const OPENCODE_GO: &'static str = "opencode-go";

Expand All @@ -33,6 +34,10 @@ impl ProviderId {
Self::new(Self::CURSOR)
}

pub fn kimi() -> Self {
Self::new(Self::KIMI)
}

pub fn zai() -> Self {
Self::new(Self::ZAI)
}
Expand Down
20 changes: 20 additions & 0 deletions crates/providers-kimi/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "braindrain-providers-kimi"
version.workspace = true
edition.workspace = true
license.workspace = true

[dependencies]
braindrain-core = { path = "../core" }
fs4 = { workspace = true }
reqwest = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
thiserror = { workspace = true }
time = { workspace = true }
tokio = { workspace = true }
url = { workspace = true }

[dev-dependencies]
tempfile = { workspace = true }
wiremock = { workspace = true }
Loading