Based on my analysis of the codebase, here's the updated spec for adding .cat -T <topic> / .cat --topic <topic> functionality:
The .cat command flows through these layers:
- xs.nu wrapper → calls
xs catCLI with flags - src/main.rs CommandCat → parses CLI args, builds ReadOptions
- client/commands.rs cat() → makes HTTP GET to
/with query params - api.rs handle_stream_cat() → parses query into ReadOptions, calls Store::read
- store/mod.rs Store::read() → performs backlog scan + live subscription
- src/store/mod.rs: Add
topicfield toReadOptions, updatefrom_query/to_query_string, modifyStore::read()to use topic index for backlog and filter broadcasts - src/main.rs: Add
--topic/-Tflag toCommandCatstruct andcat()function - client/commands.rs: Pass topic parameter through HTTP client
- xs.nu: Add topic flag to
.catwrapper command
- src/store/tests.rs: Add topic filtering tests for both historical and live frames
- src/client/mod.rs or integration tests: Test end-to-end topic filtering
- docs/src/content/docs/reference/cli.mdx: Update
xs catcommand documentation - docs/src/content/docs/getting-started/first-stream.mdx: Update
.catexamples if applicable
- Historical filtering: Create frames with mixed topics, verify
--topic fooreturns only foo frames - Live filtering: Follow stream with topic filter, append mixed topics, verify only matching frames received
- Topic index optimization: Verify backlog scan uses topic index when topic specified
- Combined flags: Test
--topicwith--follow,--tail,--context,--limit - Non-existent topic: Verify graceful handling of topics with no frames
Add topic filtering to .cat command using -T --topic flags:
- Store layer: Add
topic: Option<String>toReadOptions, implement topic index scanning inStore::read()for backlog, filter broadcast frames by topic - CLI layer: Add
topic: Option<String>toCommandCat, pass to client layer - Client layer: Include topic in HTTP query parameters
- API layer: Parse topic from query into
ReadOptions - Nushell wrapper: Add
-T --topicflag to.catcommand inxs.nu - Tests: Add comprehensive topic filtering tests for historical and live scenarios
- Documentation: Update CLI reference and usage examples
The implementation leverages the existing topic index (idx_topic) for efficient backlog scanning when a topic is specified, falling back to full stream scan + filtering when no topic is provided.