Skip to content

Add watch/tail command for Cosmos DB change feed - #115

Merged
Mike Krüger (mkrueger) merged 4 commits into
mainfrom
feature/watch-change-feed
Jun 5, 2026
Merged

Mike Krüger (mkrueger) merged 4 commits into
mainfrom
feature/watch-change-feed

Conversation

@mkrueger

Copy link
Copy Markdown
Collaborator

Closes #100.

Summary

Adds a watch command (alias tail) that tails the Azure Cosmos DB change feed, streaming new and modified items as they arrive.

Behavior

  • Defaults to starting from now and follows the container, printing each change as highlighted JSON until Ctrl+C.
  • --from-beginning / -b replays the change feed from the start of the container.
  • --partition-key / -pk scopes the feed to a single partition.
  • --max / -m stops automatically after N changes.
  • --format / -f, --database / -db, --container / -con mirror existing commands.
  • Polls every 1s, treating HTTP 304 (caught up) as "no changes yet".
  • The change feed surfaces creates and updates, not deletes (Cosmos limitation).

Implementation notes

  • Uses ShellInterpreter.UserCancellationTokenSource.Token so the long-running tail is not killed by the per-command timeout, and catches OperationCanceledException for a clean Ctrl+C stop.
  • Marked [McpAnnotation(Restricted = true, ReadOnly = true)] because streaming/interactive output does not fit the HTTP-only MCP model.
  • Pure helpers BuildStartFrom and ParseChangeFeedDocuments are internal for unit testing.

Validation

  • dotnet build CosmosDBShell/CosmosDBShell.csproj ✅
  • dotnet build CosmosDBShell.Tests/CosmosDBShell.Tests.csproj ✅
  • New WatchCommandTests, localization audit, and help verification tests pass.

Docs

  • Added a watch section to docs/commands.md.
  • Updated the feature list in README.md.
Implements a streaming watch command (alias tail) that tails the change feed, printing new and modified items as highlighted JSON. Supports --from-beginning, --partition-key, --max, and --format. MCP-restricted since it is interactive/streaming. Adds unit tests for the parsing and start-position helpers, localization keys, and docs.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new interactive CLI command to follow a container’s Azure Cosmos DB change feed, plus docs/localization/tests to support it.

Changes:

  • Introduces watch (alias tail) command to stream change feed items with --from-beginning, --partition-key, --max, and output format/container/database overrides.
  • Adds help/localization strings and user documentation for the new command.
  • Adds unit tests for the pure helper methods (BuildStartFrom, ParseChangeFeedDocuments).

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
README.md Adds watch/tail to the feature list.
docs/commands.md Documents watch command usage and options.
CosmosDBShell/lang/en.ftl Adds localized help/error strings for watch.
CosmosDBShell/Azure.Data.Cosmos.Shell.Commands/WatchCommand.cs Implements the watch/tail command and its change feed loop/helpers.
CosmosDBShell.Tests/CommandTests/WatchCommandTests.cs Adds unit tests for change feed parsing and start position helper logic.
Comment thread CosmosDBShell/lang/en.ftl Resolved
- Use CreatePartitionKeyFromArgument so --partition-key supports typed and hierarchical keys instead of a raw string.
- Translate JsonException from an invalid partition key into a localized CommandException.
- Honor stdout redirection: suppress per-item highlighted output and return the collected JSON result (IsPrinted=false) when output is redirected, collecting changes even without --max.
- Clarify the --max help text to match actual behavior (omit/0/negative follows until Ctrl+C).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

@mkrueger
Mike Krüger (mkrueger) merged commit 9c8b7e3 into main Jun 5, 2026
7 checks passed
@mkrueger
Mike Krüger (mkrueger) deleted the feature/watch-change-feed branch June 5, 2026 12:54
Mike Krüger (mkrueger) added a commit that referenced this pull request Jul 1, 2026
….4 (#143)

## Summary

Rewrites the `1.1.114-preview` changelog section so it accurately
documents **all** changes merged since `1.1.4-preview`, not just the
server-side programming commands and two breaking changes.

PR #142 only stamped the release heading. This fills in the body.

## What changed

The `1.1.114-preview` entry now covers every PR merged on top of 1.1.4:

- **Highlights** of the major additions.
- **New features**: `theme` (#83), `filter` (#67), `watch`/`tail`
(#115), `edit` (#117), `index` (#116), `throughput` (#130),
`import`/`export` (#95), `sproc`/`udf`/`trigger` (#124), `--diagnostics`
(#127), `--otel` (#126).
- **Improvements**: incomplete-construct highlighting (#93),
theme-routed colors and JSON token highlighting (#97), source-caret
diagnostics (#99), refreshed prompt (#133), `ls` summaries (#129, #139).
- **Security**: MCP hardening (#120), CodeQL alerts in connect flow
(#132).
- **Fixes**: `;`-separator REPL highlighting (#141).
- **Breaking changes** (unchanged): `indexpolicy` removed/aliased to
`index` (#140); `theme edit --editor` removed.
- **Documentation** (#123) and **Build & pipeline** (#128, #121).

Items already shipped in 1.1.4 are not re-listed.

## Validation

- Documentation-only change; descriptions verified against
`docs/commands.md` and `docs/navigation.md`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

4 participants