Skip to content

Commit a789a43

Browse files
committed
feat(kilo): add Kilo usage adapter
Add a Kilo CLI adapter that reads local kilo.db SQLite usage rows from KILO_DATA_DIR or the default data directory. Wire Kilo into focused and all-agent reports, config namespaces, generated schema, and docs so it behaves like the other local usage sources. Use recorded costs when Kilo provides them, fall back to LiteLLM pricing otherwise, and skip timestamp-less rows to avoid assigning usage to the wrong day. Add adapter tests plus CLI JSON snapshot coverage for the new command surface.
1 parent 4aedac0 commit a789a43

25 files changed

Lines changed: 1018 additions & 28 deletions

‎apps/ccusage/README.md‎

Lines changed: 3 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 Kilo usage from local data. Track daily, weekly, monthly, and session-based usage with beautiful tables.
2929

3030
## Installation
3131

@@ -65,6 +65,7 @@ bunx ccusage opencode weekly
6565
bunx ccusage amp session
6666
bunx ccusage pi daily --pi-path /path/to/sessions
6767
bunx ccusage pi daily --pi-path /path/to/sessions,/archive/pi/sessions
68+
bunx ccusage kilo daily
6869

6970
# Explicit unified report
7071
bunx ccusage daily --all
@@ -89,7 +90,7 @@ bunx ccusage monthly --compact # Compact monthly report
8990
- 📊 **Daily Report**: View token usage and costs aggregated by date
9091
- 📅 **Monthly Report**: View token usage and costs aggregated by month
9192
- 💬 **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
93+
- 🤖 **Unified CLI Reports**: View Claude Code, Codex, OpenCode, Amp, pi-agent, and Kilo usage from one CLI
9394
- ⏰ **5-Hour Blocks Report**: Track usage within Claude's billing windows with active block monitoring
9495
- 🚀 **Statusline Integration**: Compact usage display for Claude Code status bar hooks (Beta)
9596
- 🤖 **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+
"kilo": {
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 kilo commands",
2220+
"markdownDescription": "Default values for kilo 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 kilo",
2375+
"markdownDescription": "Command-specific configuration overrides for kilo"
2376+
}
2377+
},
2378+
"additionalProperties": false,
2379+
"description": "kilo command configuration",
2380+
"markdownDescription": "kilo command configuration"
21672381
}
21682382
},
21692383
"additionalProperties": false

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

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { $ } from 'bun';
1717
import { allArgs } from '../src/commands/all.ts';
1818
// Import command definitions to access their args
1919
import { subCommandUnion } from '../src/commands/index.ts';
20+
import { AGENT_CONFIG_KEYS } from '../src/config-loader-tokens.ts';
2021
import { logger } from '../src/logger.ts';
2122

2223
/**
@@ -39,8 +40,7 @@ const COMMAND_EXCLUDE_KEYS: Record<string, string[]> = {
3940
blocks: ['live', 'refreshInterval'],
4041
};
4142

42-
const AGENT_NAMES = ['claude', 'codex', 'opencode', 'amp', 'pi'] as const;
43-
type AgentName = (typeof AGENT_NAMES)[number];
43+
type AgentName = (typeof AGENT_CONFIG_KEYS)[number];
4444
type JsonSchemaNode = {
4545
[key: string]: unknown;
4646
type?: string;
@@ -110,7 +110,7 @@ function tokensSchemaToJsonSchema(schema: TokenSchema): JsonSchemaNode {
110110

111111
function splitCommandName(name: string): { agent?: AgentName; report: string } {
112112
const [prefix, report] = name.split(':');
113-
if (report != null && AGENT_NAMES.includes(prefix as AgentName)) {
113+
if (report != null && AGENT_CONFIG_KEYS.includes(prefix as AgentName)) {
114114
return { agent: prefix as AgentName, report };
115115
}
116116
return { report: name };
@@ -186,10 +186,9 @@ function createAgentJsonSchema(
186186
*/
187187
function createConfigSchemaJson(): JsonSchemaNode {
188188
const topLevelCommandSchemas: Record<string, TokenSchema> = {};
189-
const agentCommandSchemas = Object.fromEntries(AGENT_NAMES.map((agent) => [agent, {}])) as Record<
190-
AgentName,
191-
Record<string, TokenSchema>
192-
>;
189+
const agentCommandSchemas = Object.fromEntries(
190+
AGENT_CONFIG_KEYS.map((agent) => [agent, {}]),
191+
) as Record<AgentName, Record<string, TokenSchema>>;
193192

194193
for (const [commandName, command] of subCommandUnion) {
195194
const { agent, report } = splitCommandName(commandName);
@@ -242,6 +241,7 @@ function createConfigSchemaJson(): JsonSchemaNode {
242241
opencode: createAgentJsonSchema('opencode', agentCommandSchemas.opencode),
243242
amp: createAgentJsonSchema('amp', agentCommandSchemas.amp),
244243
pi: createAgentJsonSchema('pi', agentCommandSchemas.pi),
244+
kilo: createAgentJsonSchema('kilo', agentCommandSchemas.kilo),
245245
},
246246
additionalProperties: false,
247247
},
@@ -464,6 +464,10 @@ if (import.meta.vitest != null) {
464464
expect(properties).toHaveProperty('commands');
465465
expect(properties).toHaveProperty('claude');
466466
expect(properties).toHaveProperty('codex');
467+
expect(properties).toHaveProperty('opencode');
468+
expect(properties).toHaveProperty('amp');
469+
expect(properties).toHaveProperty('pi');
470+
expect(properties).toHaveProperty('kilo');
467471
});
468472

469473
it('should keep legacy top-level Claude config properties', () => {
@@ -497,15 +501,20 @@ if (import.meta.vitest != null) {
497501
const properties = schemaProperties(mainSchema);
498502
const claudeCommands = schemaProperties(properties.claude ?? {}).commands ?? {};
499503
const codexCommands = schemaProperties(properties.codex ?? {}).commands ?? {};
504+
const kiloCommands = schemaProperties(properties.kilo ?? {}).commands ?? {};
500505
const claudeCommandProperties = schemaProperties(claudeCommands);
501506
const codexCommandProperties = schemaProperties(codexCommands);
507+
const kiloCommandProperties = schemaProperties(kiloCommands);
502508

503509
expect(claudeCommandProperties).toHaveProperty('daily');
504510
expect(claudeCommandProperties).toHaveProperty('blocks');
505511
expect(claudeCommandProperties).toHaveProperty('statusline');
506512
expect(codexCommandProperties).toHaveProperty('daily');
507513
expect(codexCommandProperties).toHaveProperty('monthly');
508514
expect(codexCommandProperties).toHaveProperty('session');
515+
expect(kiloCommandProperties).toHaveProperty('daily');
516+
expect(kiloCommandProperties).toHaveProperty('monthly');
517+
expect(kiloCommandProperties).toHaveProperty('session');
509518
});
510519
});
511520
}

0 commit comments

Comments
 (0)