feat(cli): nerve sense query — query sense SQLite data from CLI #60

Closed
opened 2026-04-23 06:55:57 +00:00 by xiaoju · 0 comments
Owner

Motivation

Sense data is stored in SQLite (data/senses/<name>.db) but there is no way to inspect it from the CLI. Users have to manually locate the db file and use external tools.

Proposed Commands

nerve sense schema <name>

Print the table schema(s) of a sense database.

$ nerve sense schema linux-system-health
CREATE TABLE snapshots (
  ts INTEGER PRIMARY KEY,
  cpu_load_1m REAL NOT NULL,
  ...
);

nerve sense query <name> [sql]

Run a SQL query against a sense database. If sql is omitted, default to showing the latest 10 rows from the primary table.

# Custom query
$ nerve sense query linux-system-health "SELECT avg(cpu_load_1m) FROM snapshots WHERE ts > ..."

# Default: latest 10 rows
$ nerve sense query linux-system-health

Output should be formatted as a table for humans, with --json flag for machine consumption.

Implementation Notes

  • DB path: <workspace>/data/senses/<name>.db
  • Open as readonly
  • Use better-sqlite3 (already a dependency of nerve-daemon)
  • schema: use SELECT sql FROM sqlite_master WHERE type="table"
  • query: run the SQL with .all(), format output
  • Default query: detect the first table name from sqlite_master, SELECT * FROM <table> ORDER BY rowid DESC LIMIT 10

— 小橘 🍊(NEKO Team)

## Motivation Sense data is stored in SQLite (`data/senses/<name>.db`) but there is no way to inspect it from the CLI. Users have to manually locate the db file and use external tools. ## Proposed Commands ### `nerve sense schema <name>` Print the table schema(s) of a sense database. ```bash $ nerve sense schema linux-system-health CREATE TABLE snapshots ( ts INTEGER PRIMARY KEY, cpu_load_1m REAL NOT NULL, ... ); ``` ### `nerve sense query <name> [sql]` Run a SQL query against a sense database. If `sql` is omitted, default to showing the latest 10 rows from the primary table. ```bash # Custom query $ nerve sense query linux-system-health "SELECT avg(cpu_load_1m) FROM snapshots WHERE ts > ..." # Default: latest 10 rows $ nerve sense query linux-system-health ``` Output should be formatted as a table for humans, with `--json` flag for machine consumption. ## Implementation Notes - DB path: `<workspace>/data/senses/<name>.db` - Open as readonly - Use better-sqlite3 (already a dependency of nerve-daemon) - `schema`: use `SELECT sql FROM sqlite_master WHERE type="table"` - `query`: run the SQL with `.all()`, format output - Default query: detect the first table name from sqlite_master, `SELECT * FROM <table> ORDER BY rowid DESC LIMIT 10` — 小橘 🍊(NEKO Team)
This repo is archived. You cannot comment on issues.
No Label
1 Participants
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: uncaged/nerve#60