Skip to content

Add export CLI command for CSV/JSON data export #13

@roeimichael

Description

@roeimichael

Problem

All collected data is locked inside a SQLite database with no CLI or API path to extract it. Users who want to analyze trends in a spreadsheet, share cost data with a team, or back up data before a clear have no option.

What to do

Add an export command to the CLI with options:

context-analyzer-tool export --format csv --table tasks --output tasks.csv
context-analyzer-tool export --format json --table anomalies
context-analyzer-tool export --format csv --table snapshots --days 7

Implementation approach

  1. Add the command to src/context_analyzer_tool/cli.py with Typer options:
    • --format: csv or json (default: csv)
    • --table: events, tasks, snapshots, anomalies (required)
    • --output: file path (default: stdout)
    • --days: limit to last N days (optional)
  2. Open the database directly (like the prune command does with asyncio.run)
  3. For CSV: use csv.DictWriter; for JSON: use json.dump

Files to look at

  • src/context_analyzer_tool/cli.py — follow existing command patterns
  • src/context_analyzer_tool/db/ — existing query functions to reuse

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: cliCLI commands and optionsarea: databaseSQLite schema, queries, and migrationsdifficulty: intermediateRequires some familiarity with the codebaseenhancementNew feature or requesthelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions