You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add cost tracking and centralized logging; propagate LLM operation metadata
- Introduce cost tracking system and CLI:
- Add brain_core/cost_tracker.py for recording/aggregating LLM usage
- Add brain_cli/cost_commands.py to view summary, trends, estimate, breakdown, export, pricing
- Add cost.json example data
- Update .env.example and README with cost/logging/pricing options and new commands
- Centralized logging:
- Add brain_core/logging_config.py with setup_logging, helpers, and LLM/timing log functions
- Wire setup_logging into brain_cli/main.py and add --verbose/--debug flags + version callback
- LLM usage metadata and cost recording:
- Extend LLMClient.generate_sync signature to accept operation and entry_date
- AzureOpenAIClient now records token usage, estimates cost via CostTracker, and calls log_llm_call
- Propagate operation/entry_date parameters in template_generator, llm_analysis, report_generator, plan_commands
- Behavior and config tweaks:
- Update brain_core/config.py to expose cost/logging config
- Update constants: DAILY_PROMPT_COUNT=2, PROMPT_CONTEXT_DAYS=2, add AZURE_OPENAI_PRICING map
- Lower-level logging swapped to debug for LLM/prompt generation messages
- Tests:
- Update tests to use create_autospec(LLMClient) and assert operation/entry_date are passed for task extraction
This brings end-to-end cost tracking, richer logging, and consistent propagation of LLM call metadata across the codebase.
- Clean UX with smart log suppression (no interruptions during spinners)
36
+
- Multiple verbosity levels (--verbose, --debug)
37
+
- File and console output options
38
+
- Suppressed noisy third-party HTTP logs
39
+
26
40
**LLM Support:**
27
41
- Azure OpenAI - Full functionality for all commands
28
42
@@ -68,9 +82,23 @@ uv run brain notes search "topic" # Search book notes
68
82
uv run brain notes search "topic" --semantic --detailed
69
83
uv run brain notes status # Check connection
70
84
71
-
85
+
# Cost tracking and analysis
86
+
uv run brain cost summary # Usage summary for last 30 days
87
+
uv run brain cost trends 30 # Daily cost trends
88
+
uv run brain cost estimate # Monthly cost projection
89
+
uv run brain cost breakdown # Per-operation breakdown
90
+
uv run brain cost export data.json # Export to JSON
91
+
uv run brain cost pricing # Show pricing
92
+
93
+
# Logging (Rich-formatted, colored output)
94
+
uv run brain --verbose <command># Show key operations
95
+
uv run brain --debug <command># Full diagnostics with LLM details
72
96
```
73
97
98
+
> **Clean UX:** By default, logs are suppressed during operations to avoid interrupting spinners. Use `--verbose` or `--debug` for detailed information with beautiful Rich formatting.
99
+
100
+
> **Cost Tracking:** All Azure OpenAI usage is automatically tracked in a local SQLite database (`~/.brain/costs.db`). Data stays private and grows ~10-50 MB/year for typical use.
101
+
74
102
## Configuration
75
103
76
104
**Required Paths:**
@@ -88,6 +116,21 @@ uv run brain notes status # Check connection
88
116
-`AZURE_SEARCH_API_KEY` - Azure AI Search API key
89
117
-`AZURE_SEARCH_INDEX_NAME` - Search index name (default: second-brain-notes)
90
118
119
+
**Cost Tracking** (optional configuration):
120
+
-`BRAIN_COST_DB_PATH` - Path to cost tracking database (default: ~/.brain/costs.db)
0 commit comments