Commit 853bb25
committed
feat(cli): stats — fast direct-to-daemon analytics CLI
Migrate `mempalace stats` from a 3-4-call MCP-tool fan-out to a single
`GET /stats` REST hit. The unified envelope returns three blocks:
`kg` (entities, triples, relationship_types), `graph` (rooms,
tunnels, edges), `status` (drawer counts, wings, rooms, protocol /
AAAK text). One network hop instead of four — same data, faster.
New flags:
- `--format=table|json` with `--json` shorthand for legacy callers
- `--section=kg|graph|status|all` (default `all`) narrows table
output to a single block; json mode always passes through the
full envelope so jq pipelines see the daemon contract unchanged
- `--no-relationship-types` suppresses the relationship_types list
(1000+ entries in production); table shows the count, json
replaces the list with `{"relationship_types_count": N}`
Preserved flags: `--top N` (default 10, 0 means show all),
`--tags` (still fires a separate `mempalace_list_tags` MCP call
since /stats doesn't carry the tag breakdown — tag counts can be
100K+ entries and don't belong in a fast-path summary).
Table mode suppresses `protocol` and `aaak_dialect` (text blobs,
not analytics); json mode passes them through to preserve the
daemon envelope contract for jq pipelines.
Failure modes now match cmd_list/cmd_graph/cmd_cypher: daemon
unreachable → exit 1 (was exit 2 under the multi-call path),
404/401/403 → exit 1, inner-error envelope → exit 2, no
`PALACE_DAEMON_URL` → exit 2. The exit-code shift on the
unreachable path is intentional — all four sibling commands now
share one failure shape.
32 tests in tests/test_cli_stats.py — TestStatsFlagPropagation,
TestStatsFormats, TestStatsEmpty, TestStatsDaemonDown, plus a
parser-wiring class. Mocks `urllib.request.urlopen` so the
dispatcher logic is exercised without a real daemon.
Slice of #191.1 parent eef0ec4 commit 853bb25
2 files changed
Lines changed: 585 additions & 490 deletions
0 commit comments