Skip to content

fix(cli): TUI defaults and clearer --watch handling#23

Merged
mahimairaja merged 10 commits intomainfrom
cursor/tui-watch-path-handling-3694
Mar 22, 2026
Merged

fix(cli): TUI defaults and clearer --watch handling#23
mahimairaja merged 10 commits intomainfrom
cursor/tui-watch-path-handling-3694

Conversation

@mahimairaja
Copy link
Owner

@mahimairaja mahimairaja commented Mar 22, 2026

Summary

  • openrtc tui with no flags now tails ./openrtc-metrics.jsonl in the current working directory (same as the default for --watch). Users can still pass --watch /path/to/file.jsonl for a custom file.
  • Convention: start the worker with --metrics-jsonl ./openrtc-metrics.jsonl so the TUI and worker share one file. The filename is defined as DEFAULT_METRICS_JSONL_FILENAME in metrics_stream.py.
  • --metrics-jsonl help mentions pairing with the default TUI file.
  • Directory --watch still fails with a clear error (from the earlier commit on this branch).
  • Initial TUI status shows the resolved watch path so custom --watch values are not misleading.

Tests

  • test_tui_help_documents_default_watch_path
  • test_tui_command_without_watch_uses_default_metrics_path
  • Existing TUI / CLI tests unchanged in behavior (explicit --watch still works).
Open in Web Open in Cursor 

Summary by CodeRabbit

  • New Features

    • CLI accepts agents directory and optional metrics JSONL as positional arguments (e.g., openrtc dev ./agents ./openrtc-metrics.jsonl).
    • openrtc tui tails ./openrtc-metrics.jsonl by default when no path is provided.
  • Documentation

    • Updated README and docs CLI examples to show positional-argument usage and revised TUI/metrics guidance.
  • Bug Fixes

    • TUI now validates watch path and errors if given a directory.
  • Tests

    • Added tests covering positional-argument rewriting and TUI watch-path behavior.

The TUI tails a JSONL file from --metrics-jsonl; passing an agents directory
raised IsADirectoryError. Validate early, log a helpful message, and exit 1.
Clarify --watch help text.

Co-authored-by: Mahimai Raja J <mahimairaja3@gmail.com>
@coderabbitai
Copy link

coderabbitai bot commented Mar 22, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: d21d438c-4478-4c5f-986e-59b58b120b1f

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds positional-argument support to OpenRTC CLI: agents directory and metrics JSONL paths can be supplied positionally. Implements argv-rewrite helpers, updates CLI defaults/help, adjusts TUI metrics defaults/validation, updates docs, and adds tests to cover the new behavior.

Changes

Cohort / File(s) Summary
Documentation
.agents/skills/openrtc-python/SKILL.md, AGENTS.md, README.md, docs/cli.md, docs/getting-started.md
Rewrote CLI examples and help text to prefer positional agents and metrics paths (e.g., openrtc dev ./agents [./metrics.jsonl]) and adjusted TUI/docs to reflect default metrics filename and positional usage.
CLI positional injection
src/openrtc/cli_livekit.py
Added inject_cli_positional_paths and inject_worker_positional_paths to rewrite positional shortcuts into explicit flags (--agents-dir, --metrics-jsonl, --watch) before Typer parsing; preserves explicit flags when present.
CLI defaults & wiring
src/openrtc/cli_app.py, src/openrtc/cli_types.py
Updated help strings and option metadata to document positional usage; changed tui_command default for watch to use the new default filename; main() now calls positional-path injection for provided argv and rewrites sys.argv when running normally.
Metrics & TUI behavior
src/openrtc/metrics_stream.py, src/openrtc/tui_app.py
Added DEFAULT_METRICS_JSONL_FILENAME = "openrtc-metrics.jsonl"; added validate_metrics_watch_path() to reject directory paths for --watch; updated TUI status text to include resolved watch path.
Tests
tests/test_cli.py, tests/test_tui_app.py
Added tests exercising positional-argument rewriting, default metrics file resolution, TUI --watch behavior, and validation that --watch pointing to a directory is rejected.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested labels

enhancement

Poem

🐰 I hopped through flags and found a lane,
Positional paths now ease the strain.
Agents and metrics, tidy and neat,
CLI hops faster on nimble feet. ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 64.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: making TUI defaults work without flags and improving --watch documentation/handling.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch cursor/tui-watch-path-handling-3694

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@CLAassistant
Copy link

CLAassistant commented Mar 22, 2026

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 3 committers have signed the CLA.

✅ mahimairaja
❌ cursoragent
❌ Copilot
You have signed the CLA already but the status is still pending? Let us recheck it.

@codecov
Copy link

codecov bot commented Mar 22, 2026

Codecov Report

❌ Patch coverage is 87.30159% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.15%. Comparing base (1b68c00) to head (a25b493).
⚠️ Report is 11 commits behind head on main.

Files with missing lines Patch % Lines
src/openrtc/cli_livekit.py 88.09% 5 Missing ⚠️
src/openrtc/cli_app.py 78.57% 3 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #23      +/-   ##
==========================================
- Coverage   90.22%   90.15%   -0.08%     
==========================================
  Files          13       13              
  Lines        1361     1422      +61     
==========================================
+ Hits         1228     1282      +54     
- Misses        133      140       +7     
Files with missing lines Coverage Δ
src/openrtc/cli_types.py 100.00% <100.00%> (ø)
src/openrtc/metrics_stream.py 100.00% <100.00%> (ø)
src/openrtc/tui_app.py 100.00% <100.00%> (ø)
src/openrtc/cli_app.py 92.85% <78.57%> (-1.59%) ⬇️
src/openrtc/cli_livekit.py 86.09% <88.09%> (+0.77%) ⬆️

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1b68c00...a25b493. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Running `openrtc tui` with no flags now tails the conventional JSONL file in
the cwd; pair the worker with `--metrics-jsonl ./openrtc-metrics.jsonl`.
Document the constant in metrics_stream and align --metrics-jsonl help text.

Co-authored-by: Mahimai Raja J <mahimairaja3@gmail.com>
@cursor cursor bot changed the title fix(cli): TUI --watch rejects directories with a clear error fix(cli): TUI defaults and clearer --watch handling Mar 22, 2026
cursoragent and others added 5 commits March 22, 2026 18:00
Update CLI reference, README, getting started, AGENTS, and skill examples to
describe plain `openrtc tui`, the default watch file, and --watch overrides.

Co-authored-by: Mahimai Raja J <mahimairaja3@gmail.com>
Rewrite dev|start|console ./agents [./metrics.jsonl] to --agents-dir and
--metrics-jsonl before Typer parses (openrtc.cli_app.main). Add
inject_worker_positional_paths helper and tests. Update --agents-dir help and docs.

Co-authored-by: Mahimai Raja J <mahimairaja3@gmail.com>
…d tui

Generalize argv injection via inject_cli_positional_paths (inject_worker_positional_paths
remains an alias). Apply preprocessing for all subcommands in main() sys.argv path.
Document in README, docs/cli, getting-started, and AGENTS.

Co-authored-by: Mahimai Raja J <mahimairaja3@gmail.com>
Co-authored-by: Mahimai Raja J <mahimairaja3@gmail.com>
…etrics

Behavior unchanged: openrtc dev ./agents only sets --agents-dir. Improve --help,
epilog, MetricsJsonlArg/--agents-dir text, README, and docs/cli.md; add inject test.

Co-authored-by: Mahimai Raja J <mahimairaja3@gmail.com>
@mahimairaja
Copy link
Owner Author

@CodeRabbit full review

@coderabbitai
Copy link

coderabbitai bot commented Mar 22, 2026

✅ Actions performed

Full review triggered.

@mahimairaja
Copy link
Owner Author

@copilot review

Copy link
Contributor

Copilot AI commented Mar 22, 2026

@mahimairaja I've opened a new pull request, #24, to work on those changes. Once the pull request is ready, I'll request review from you.

@mahimairaja mahimairaja marked this pull request as ready for review March 22, 2026 18:56
Copilot AI review requested due to automatic review settings March 22, 2026 18:56
@mahimairaja
Copy link
Owner Author

@CodeRabbit full review

@coderabbitai
Copy link

coderabbitai bot commented Mar 22, 2026

✅ Actions performed

Full review triggered.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR improves the OpenRTC CLI/TUI ergonomics by standardizing a default metrics JSONL filename, making openrtc tui tail that file by default, and adding a pre-parse rewrite that allows common path arguments to be passed positionally (instead of requiring --agents-dir, --metrics-jsonl, or --watch).

Changes:

  • Introduces a shared default metrics JSONL filename (openrtc-metrics.jsonl) and uses it as the default watch target for openrtc tui.
  • Adds CLI argv rewriting (inject_cli_positional_paths) so commands like openrtc dev ./agents [./metrics.jsonl], openrtc list ./agents, and openrtc tui ./file.jsonl work.
  • Updates help text and docs to reflect new defaults and positional path shortcuts; adds targeted tests for the new behaviors.

Reviewed changes

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

Show a summary per file
File Description
src/openrtc/cli_app.py Sets TUI default watch path, improves TUI error handling, and applies positional-path argv rewriting in main().
src/openrtc/cli_livekit.py Implements positional-path rewriting helpers and exposes inject_cli_positional_paths.
src/openrtc/cli_types.py Updates CLI option help to document positional usage and default TUI watch file.
src/openrtc/metrics_stream.py Defines DEFAULT_METRICS_JSONL_FILENAME for consistent default naming.
src/openrtc/tui_app.py Adds validation to reject directory watch paths and improves initial status to show the resolved watch path.
tests/test_cli.py Adds tests for positional rewriting and for TUI default watch/help behavior.
tests/test_tui_app.py Adds a unit test for rejecting a directory as the watch path.
docs/getting-started.md Updates examples to use openrtc dev ./agents and openrtc tui default behavior.
docs/cli.md Documents positional path shortcuts across commands and updated TUI workflow/examples.
README.md Updates CLI/TUI usage examples to reflect positional paths and TUI default watch behavior.
AGENTS.md Updates quick references and notes to match the new CLI/TUI defaults.
.agents/skills/openrtc-python/SKILL.md Updates skill doc examples to use positional paths and the default TUI workflow.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +15 to +24
def validate_metrics_watch_path(path: Path) -> None:
"""Ensure *path* can be used as the metrics JSONL file (not a directory)."""
resolved = path.resolve()
if resolved.exists() and resolved.is_dir():
raise ValueError(
"'--watch' must be a JSONL file path (the same path you pass to "
"'--metrics-jsonl' on the OpenRTC worker). This value is a directory "
"— for example, use a file such as ./metrics.jsonl, not your agents "
f"folder. Got: {resolved}"
)
Copy link

Copilot AI Mar 22, 2026

Choose a reason for hiding this comment

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

validate_metrics_watch_path() raises an error that specifically says "'--watch' must be...". Since the TUI also supports supplying the watch path positionally (openrtc tui ./file.jsonl), the message can be misleading (user didn't necessarily pass --watch). Consider wording it in terms of the watch path/metrics file argument (optionally mentioning --watch) so the error matches both invocation forms.

Copilot uses AI. Check for mistakes.
Comment on lines +337 to +338
cli.main(
args=inject_cli_positional_paths(list(argv)),
Copy link

Copilot AI Mar 22, 2026

Choose a reason for hiding this comment

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

When main() is invoked programmatically with argv (non-None), Click/Typer will parse args=... but sys.argv is left unchanged. The LiveKit handoff (_livekit_sys_argv) relies on sys.argv to preserve forwarded LiveKit flags (e.g. --reload) and will otherwise drop them because sys.argv[1] != subcommand. Consider setting sys.argv = [prog_name, *injected_args] (and restoring it in finally, as you already do) so programmatic main(["dev", "./agents", "--reload"]) behaves like the real CLI invocation.

Suggested change
cli.main(
args=inject_cli_positional_paths(list(argv)),
injected_args = inject_cli_positional_paths(list(argv))
# Mirror a real CLI invocation so LiveKit handoff logic that
# inspects sys.argv sees the injected arguments (e.g. --reload).
sys.argv = [previous_argv[0], *injected_args]
cli.main(
args=injected_args,

Copilot uses AI. Check for mistakes.
@mahimairaja
Copy link
Owner Author

@copilot open a new pull request to apply changes based on the comments in this thread

Copy link
Contributor

Copilot AI commented Mar 22, 2026

@mahimairaja I've opened a new pull request, #25, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
tests/test_cli.py (1)

688-707: Avoid asserting via private MetricsTuiApp._path (Line 699).

This test currently depends on openrtc.tui_app internals instead of CLI-facing behavior, which makes it brittle during harmless refactors.

♻️ Suggested refactor (assert `run_metrics_tui` call contract instead of private state)
 def test_tui_command_without_watch_uses_default_metrics_path(
     tmp_path: Path,
     monkeypatch: pytest.MonkeyPatch,
 ) -> None:
     pytest.importorskip("textual")
-    import openrtc.tui_app as tu
-    from openrtc.tui_app import MetricsTuiApp
+    import openrtc.tui_app as tui_app_mod

-    seen: list[Path] = []
+    seen: list[tuple[Path, bool]] = []

-    def fake_run(self: MetricsTuiApp) -> None:
-        seen.append(self._path)
+    def fake_run_metrics_tui(path: Path, *, from_start: bool) -> None:
+        seen.append((path, from_start))

     monkeypatch.chdir(tmp_path)
-    monkeypatch.setattr(tu.MetricsTuiApp, "run", fake_run)
+    monkeypatch.setattr(tui_app_mod, "run_metrics_tui", fake_run_metrics_tui)
     runner = CliRunner()
     result = runner.invoke(app, ["tui"], catch_exceptions=False)
     assert result.exit_code == 0
-    assert len(seen) == 1
-    assert seen[0] == (tmp_path / "openrtc-metrics.jsonl").resolve()
+    assert seen == [(Path("openrtc-metrics.jsonl"), False)]
As per coding guidelines: "Test public behavior, not private implementation details."
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/test_cli.py` around lines 688 - 707, The test is asserting a private
attribute MetricsTuiApp._path; instead, monkeypatch the public entrypoint (e.g.,
openrtc.tui_app.run_metrics_tui or the module-level function that the "tui" CLI
calls) to capture the path argument and assert that was called with (tmp_path /
"openrtc-metrics.jsonl").resolve(); replace
monkeypatch.setattr(tu.MetricsTuiApp, "run", fake_run) and
seen.append(self._path) with monkeypatching the public function (e.g.,
monkeypatch.setattr(tu, "run_metrics_tui", fake_run_path)) where
fake_run_path(path: Path) records the passed path, then assert the recorded path
equals the expected resolved path and remove uses of the private _path.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@tests/test_cli.py`:
- Around line 688-707: The test is asserting a private attribute
MetricsTuiApp._path; instead, monkeypatch the public entrypoint (e.g.,
openrtc.tui_app.run_metrics_tui or the module-level function that the "tui" CLI
calls) to capture the path argument and assert that was called with (tmp_path /
"openrtc-metrics.jsonl").resolve(); replace
monkeypatch.setattr(tu.MetricsTuiApp, "run", fake_run) and
seen.append(self._path) with monkeypatching the public function (e.g.,
monkeypatch.setattr(tu, "run_metrics_tui", fake_run_path)) where
fake_run_path(path: Path) records the passed path, then assert the recorded path
equals the expected resolved path and remove uses of the private _path.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 340a5d97-e37d-4f27-a135-35e486fee3a8

📥 Commits

Reviewing files that changed from the base of the PR and between 1b68c00 and 23224dc.

📒 Files selected for processing (12)
  • .agents/skills/openrtc-python/SKILL.md
  • AGENTS.md
  • README.md
  • docs/cli.md
  • docs/getting-started.md
  • src/openrtc/cli_app.py
  • src/openrtc/cli_livekit.py
  • src/openrtc/cli_types.py
  • src/openrtc/metrics_stream.py
  • src/openrtc/tui_app.py
  • tests/test_cli.py
  • tests/test_tui_app.py

Copilot AI and others added 2 commits March 22, 2026 19:03
…ys.argv for programmatic main(argv=...)

Co-authored-by: mahimairaja <81288263+mahimairaja@users.noreply.github.com>
Agent-Logs-Url: https://github.com/mahimairaja/openrtc-python/sessions/8c419ba3-63a6-4ee9-9afc-eed8d22cd894
[WIP] Fix TUI defaults and clearer --watch handling
@mahimairaja mahimairaja merged commit 3e5f5b6 into main Mar 22, 2026
6 of 7 checks passed
@mahimairaja mahimairaja deleted the cursor/tui-watch-path-handling-3694 branch March 23, 2026 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants