Skip to content

Commit a6b3b57

Browse files
committed
feat(kimi): add Kimi usage adapter
1 parent 4aedac0 commit a6b3b57

27 files changed

Lines changed: 1021 additions & 52 deletions

‎apps/ccusage/README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
2626
## Supported Sources
2727

28-
The main CLI tool for analyzing Claude Code, Codex, OpenCode, Amp, and pi-agent usage from local data. Track daily, weekly, monthly, and session-based usage with beautiful tables.
28+
The main CLI tool for analyzing Claude Code, Codex, OpenCode, Amp, pi-agent, and Kimi usage from local data. Track daily, weekly, monthly, and session-based usage with beautiful tables.
2929

3030
## Installation
3131

@@ -89,7 +89,7 @@ bunx ccusage monthly --compact # Compact monthly report
8989
- 📊 **Daily Report**: View token usage and costs aggregated by date
9090
- 📅 **Monthly Report**: View token usage and costs aggregated by month
9191
- 💬 **Session Report**: View usage grouped by conversation sessions
92-
- 🤖 **Unified CLI Reports**: View Claude Code, Codex, OpenCode, Amp, and pi-agent usage from one CLI
92+
- 🤖 **Unified CLI Reports**: View Claude Code, Codex, OpenCode, Amp, pi-agent, and Kimi usage from one CLI
9393
- ⏰ **5-Hour Blocks Report**: Track usage within Claude's billing windows with active block monitoring
9494
- 🚀 **Statusline Integration**: Compact usage display for Claude Code status bar hooks (Beta)
9595
- 🤖 **Model Tracking**: See which models are used across supported sources

‎apps/ccusage/config-schema.json‎

Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2164,6 +2164,220 @@
21642164
"additionalProperties": false,
21652165
"description": "pi-agent command configuration",
21662166
"markdownDescription": "pi-agent command configuration"
2167+
},
2168+
"kimi": {
2169+
"type": "object",
2170+
"properties": {
2171+
"defaults": {
2172+
"type": "object",
2173+
"properties": {
2174+
"json": {
2175+
"type": "boolean",
2176+
"description": "Output in JSON format",
2177+
"markdownDescription": "Output in JSON format",
2178+
"default": false
2179+
},
2180+
"since": {
2181+
"type": "string",
2182+
"description": "Filter from date (YYYY-MM-DD or YYYYMMDD)",
2183+
"markdownDescription": "Filter from date (YYYY-MM-DD or YYYYMMDD)"
2184+
},
2185+
"until": {
2186+
"type": "string",
2187+
"description": "Filter until date (inclusive)",
2188+
"markdownDescription": "Filter until date (inclusive)"
2189+
},
2190+
"timezone": {
2191+
"type": "string",
2192+
"description": "Timezone for date grouping (IANA)",
2193+
"markdownDescription": "Timezone for date grouping (IANA)"
2194+
},
2195+
"offline": {
2196+
"type": "boolean",
2197+
"description": "Use cached pricing data instead of fetching from LiteLLM",
2198+
"markdownDescription": "Use cached pricing data instead of fetching from LiteLLM",
2199+
"default": false
2200+
},
2201+
"compact": {
2202+
"type": "boolean",
2203+
"description": "Force compact table layout for narrow terminals",
2204+
"markdownDescription": "Force compact table layout for narrow terminals",
2205+
"default": false
2206+
},
2207+
"color": {
2208+
"type": "boolean",
2209+
"description": "Enable colored output (default: auto). FORCE_COLOR=1 has the same effect.",
2210+
"markdownDescription": "Enable colored output (default: auto). FORCE_COLOR=1 has the same effect."
2211+
},
2212+
"noColor": {
2213+
"type": "boolean",
2214+
"description": "Disable colored output (default: auto). NO_COLOR=1 has the same effect.",
2215+
"markdownDescription": "Disable colored output (default: auto). NO_COLOR=1 has the same effect."
2216+
}
2217+
},
2218+
"additionalProperties": false,
2219+
"description": "Default values for kimi commands",
2220+
"markdownDescription": "Default values for kimi commands"
2221+
},
2222+
"commands": {
2223+
"type": "object",
2224+
"properties": {
2225+
"daily": {
2226+
"type": "object",
2227+
"properties": {
2228+
"json": {
2229+
"type": "boolean",
2230+
"description": "Output in JSON format",
2231+
"markdownDescription": "Output in JSON format",
2232+
"default": false
2233+
},
2234+
"since": {
2235+
"type": "string",
2236+
"description": "Filter from date (YYYY-MM-DD or YYYYMMDD)",
2237+
"markdownDescription": "Filter from date (YYYY-MM-DD or YYYYMMDD)"
2238+
},
2239+
"until": {
2240+
"type": "string",
2241+
"description": "Filter until date (inclusive)",
2242+
"markdownDescription": "Filter until date (inclusive)"
2243+
},
2244+
"timezone": {
2245+
"type": "string",
2246+
"description": "Timezone for date grouping (IANA)",
2247+
"markdownDescription": "Timezone for date grouping (IANA)"
2248+
},
2249+
"offline": {
2250+
"type": "boolean",
2251+
"description": "Use cached pricing data instead of fetching from LiteLLM",
2252+
"markdownDescription": "Use cached pricing data instead of fetching from LiteLLM",
2253+
"default": false
2254+
},
2255+
"compact": {
2256+
"type": "boolean",
2257+
"description": "Force compact table layout for narrow terminals",
2258+
"markdownDescription": "Force compact table layout for narrow terminals",
2259+
"default": false
2260+
},
2261+
"color": {
2262+
"type": "boolean",
2263+
"description": "Enable colored output (default: auto). FORCE_COLOR=1 has the same effect.",
2264+
"markdownDescription": "Enable colored output (default: auto). FORCE_COLOR=1 has the same effect."
2265+
},
2266+
"noColor": {
2267+
"type": "boolean",
2268+
"description": "Disable colored output (default: auto). NO_COLOR=1 has the same effect.",
2269+
"markdownDescription": "Disable colored output (default: auto). NO_COLOR=1 has the same effect."
2270+
}
2271+
},
2272+
"additionalProperties": false
2273+
},
2274+
"monthly": {
2275+
"type": "object",
2276+
"properties": {
2277+
"json": {
2278+
"type": "boolean",
2279+
"description": "Output in JSON format",
2280+
"markdownDescription": "Output in JSON format",
2281+
"default": false
2282+
},
2283+
"since": {
2284+
"type": "string",
2285+
"description": "Filter from date (YYYY-MM-DD or YYYYMMDD)",
2286+
"markdownDescription": "Filter from date (YYYY-MM-DD or YYYYMMDD)"
2287+
},
2288+
"until": {
2289+
"type": "string",
2290+
"description": "Filter until date (inclusive)",
2291+
"markdownDescription": "Filter until date (inclusive)"
2292+
},
2293+
"timezone": {
2294+
"type": "string",
2295+
"description": "Timezone for date grouping (IANA)",
2296+
"markdownDescription": "Timezone for date grouping (IANA)"
2297+
},
2298+
"offline": {
2299+
"type": "boolean",
2300+
"description": "Use cached pricing data instead of fetching from LiteLLM",
2301+
"markdownDescription": "Use cached pricing data instead of fetching from LiteLLM",
2302+
"default": false
2303+
},
2304+
"compact": {
2305+
"type": "boolean",
2306+
"description": "Force compact table layout for narrow terminals",
2307+
"markdownDescription": "Force compact table layout for narrow terminals",
2308+
"default": false
2309+
},
2310+
"color": {
2311+
"type": "boolean",
2312+
"description": "Enable colored output (default: auto). FORCE_COLOR=1 has the same effect.",
2313+
"markdownDescription": "Enable colored output (default: auto). FORCE_COLOR=1 has the same effect."
2314+
},
2315+
"noColor": {
2316+
"type": "boolean",
2317+
"description": "Disable colored output (default: auto). NO_COLOR=1 has the same effect.",
2318+
"markdownDescription": "Disable colored output (default: auto). NO_COLOR=1 has the same effect."
2319+
}
2320+
},
2321+
"additionalProperties": false
2322+
},
2323+
"session": {
2324+
"type": "object",
2325+
"properties": {
2326+
"json": {
2327+
"type": "boolean",
2328+
"description": "Output in JSON format",
2329+
"markdownDescription": "Output in JSON format",
2330+
"default": false
2331+
},
2332+
"since": {
2333+
"type": "string",
2334+
"description": "Filter from date (YYYY-MM-DD or YYYYMMDD)",
2335+
"markdownDescription": "Filter from date (YYYY-MM-DD or YYYYMMDD)"
2336+
},
2337+
"until": {
2338+
"type": "string",
2339+
"description": "Filter until date (inclusive)",
2340+
"markdownDescription": "Filter until date (inclusive)"
2341+
},
2342+
"timezone": {
2343+
"type": "string",
2344+
"description": "Timezone for date grouping (IANA)",
2345+
"markdownDescription": "Timezone for date grouping (IANA)"
2346+
},
2347+
"offline": {
2348+
"type": "boolean",
2349+
"description": "Use cached pricing data instead of fetching from LiteLLM",
2350+
"markdownDescription": "Use cached pricing data instead of fetching from LiteLLM",
2351+
"default": false
2352+
},
2353+
"compact": {
2354+
"type": "boolean",
2355+
"description": "Force compact table layout for narrow terminals",
2356+
"markdownDescription": "Force compact table layout for narrow terminals",
2357+
"default": false
2358+
},
2359+
"color": {
2360+
"type": "boolean",
2361+
"description": "Enable colored output (default: auto). FORCE_COLOR=1 has the same effect.",
2362+
"markdownDescription": "Enable colored output (default: auto). FORCE_COLOR=1 has the same effect."
2363+
},
2364+
"noColor": {
2365+
"type": "boolean",
2366+
"description": "Disable colored output (default: auto). NO_COLOR=1 has the same effect.",
2367+
"markdownDescription": "Disable colored output (default: auto). NO_COLOR=1 has the same effect."
2368+
}
2369+
},
2370+
"additionalProperties": false
2371+
}
2372+
},
2373+
"additionalProperties": false,
2374+
"description": "Command-specific configuration overrides for kimi",
2375+
"markdownDescription": "Command-specific configuration overrides for kimi"
2376+
}
2377+
},
2378+
"additionalProperties": false,
2379+
"description": "kimi command configuration",
2380+
"markdownDescription": "kimi command configuration"
21672381
}
21682382
},
21692383
"additionalProperties": false

‎apps/ccusage/scripts/generate-json-schema.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const COMMAND_EXCLUDE_KEYS: Record<string, string[]> = {
3939
blocks: ['live', 'refreshInterval'],
4040
};
4141

42-
const AGENT_NAMES = ['claude', 'codex', 'opencode', 'amp', 'pi'] as const;
42+
const AGENT_NAMES = ['claude', 'codex', 'opencode', 'amp', 'pi', 'kimi'] as const;
4343
type AgentName = (typeof AGENT_NAMES)[number];
4444
type JsonSchemaNode = {
4545
[key: string]: unknown;
@@ -242,6 +242,7 @@ function createConfigSchemaJson(): JsonSchemaNode {
242242
opencode: createAgentJsonSchema('opencode', agentCommandSchemas.opencode),
243243
amp: createAgentJsonSchema('amp', agentCommandSchemas.amp),
244244
pi: createAgentJsonSchema('pi', agentCommandSchemas.pi),
245+
kimi: createAgentJsonSchema('kimi', agentCommandSchemas.kimi),
245246
},
246247
additionalProperties: false,
247248
},
@@ -464,6 +465,7 @@ if (import.meta.vitest != null) {
464465
expect(properties).toHaveProperty('commands');
465466
expect(properties).toHaveProperty('claude');
466467
expect(properties).toHaveProperty('codex');
468+
expect(properties).toHaveProperty('kimi');
467469
});
468470

469471
it('should keep legacy top-level Claude config properties', () => {

‎apps/ccusage/src/adapter/index.ts‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { Result } from '@praha/byethrow';
1010
import { detectAmp, loadAmpRows } from './amp/index.ts';
1111
import { detectClaude, loadClaudeRows } from './claude/index.ts';
1212
import { detectCodex, loadCodexRows } from './codex/index.ts';
13+
import { detectKimi, loadKimiRows } from './kimi/index.ts';
1314
import { detectOpenCode, loadOpenCodeRows } from './opencode/index.ts';
1415
import { detectPi, loadPiRows } from './pi/index.ts';
1516
import { createEmptyRow, getRowAgents } from './shared.ts';
@@ -28,13 +29,14 @@ export function resolveAllAgents(options: AdapterOptions): AgentId[] {
2829

2930
export async function detectAllAgents(options: AdapterOptions): Promise<AgentId[]> {
3031
void options;
31-
const [claude, codex, opencode, amp, pi] = resolveDetectedAgents(
32+
const [claude, codex, opencode, amp, pi, kimi] = resolveDetectedAgents(
3233
await Promise.allSettled([
3334
detectClaude(),
3435
detectCodex(),
3536
detectOpenCode(),
3637
detectAmp(),
3738
detectPi(),
39+
detectKimi(),
3840
]),
3941
);
4042
const detected: AgentId[] = [];
@@ -53,18 +55,22 @@ export async function detectAllAgents(options: AdapterOptions): Promise<AgentId[
5355
if (pi) {
5456
detected.push('pi');
5557
}
58+
if (kimi) {
59+
detected.push('kimi');
60+
}
5661
return detected;
5762
}
5863

5964
function resolveDetectedAgents(
6065
results: Array<PromiseSettledResult<boolean>>,
61-
): [boolean, boolean, boolean, boolean, boolean] {
66+
): [boolean, boolean, boolean, boolean, boolean, boolean] {
6267
return [
6368
results[0]?.status === 'fulfilled' ? results[0].value : false,
6469
results[1]?.status === 'fulfilled' ? results[1].value : false,
6570
results[2]?.status === 'fulfilled' ? results[2].value : false,
6671
results[3]?.status === 'fulfilled' ? results[3].value : false,
6772
results[4]?.status === 'fulfilled' ? results[4].value : false,
73+
results[5]?.status === 'fulfilled' ? results[5].value : false,
6874
];
6975
}
7076

@@ -148,6 +154,8 @@ async function loadAgentRowsWithoutProgress(
148154
return loadAmpRows(kind, options, context);
149155
case 'pi':
150156
return loadPiRows(kind, options);
157+
case 'kimi':
158+
return loadKimiRows(kind, options, context);
151159
}
152160
return agent satisfies never;
153161
}
@@ -162,8 +170,9 @@ if (import.meta.vitest != null) {
162170
{ status: 'fulfilled', value: false },
163171
{ status: 'fulfilled', value: true },
164172
{ status: 'rejected', reason: new Error('permission denied') },
173+
{ status: 'fulfilled', value: true },
165174
]),
166-
).toEqual([true, false, false, true, false]);
175+
).toEqual([true, false, false, true, false, true]);
167176
});
168177

169178
it('groups rows by period and keeps per-agent breakdown rows', () => {
@@ -196,7 +205,7 @@ if (import.meta.vitest != null) {
196205
});
197206

198207
it('defaults to every supported coding agent', () => {
199-
expect(resolveAllAgents({})).toEqual(['claude', 'codex', 'opencode', 'amp', 'pi']);
208+
expect(resolveAllAgents({})).toEqual(['claude', 'codex', 'opencode', 'amp', 'pi', 'kimi']);
200209
});
201210
});
202211
}

0 commit comments

Comments
 (0)