Introduces the `--select` command-line option, allowing users to interactively choose specific books from their library for download.
Key changes and benefits:
- **Interactive Prompt:** Provides a user-friendly checkbox interface for selecting books.
- **Seamless Integration:** Wires the selection process directly into the main download pipeline.
- **TTY Safety:** Guards interactive selection to only function in interactive terminal environments.
- **Optimized Workflow:** The orchestrator now accepts pre-selected book objects, preventing redundant data conversions.
- **Limit Override:** `--limit` is automatically bypassed when interactive selection is active, with a clear user notification.
- **Comprehensive Testing:** Adds new tests for the selection module and its integration into the download flow.
Closes #47, Closes #48.
This PR implements the --select flag end-to-end, replacing the previous stub with a full interactive pipeline: a TTY guard, dict→Book conversion, a questionary checkbox prompt, and a Book passthrough to the orchestrator that avoids double-conversion.
selector.py is a new module exposing select_books() with a checkbox prompt, Ctrl+C propagation via unsafe_ask(), a confirmation step, and order-preserving return via identity set.
sync_run.py wires selection into the pipeline with sys.stdin.isatty() gating, --limit bypass (unconditionally notified when active), and passes pre-converted Book objects directly to the orchestrator.
orchestrator.py accepts list[dict | Book] via an isinstance check, keeping existing dict callers unaffected while eliminating the double-conversion path from select mode.
Confidence Score: 5/5
Safe to merge — the selection pipeline is well-guarded (TTY check, empty-selection exit, confirmation step) and all changes are backward-compatible.
The new --select path is well-isolated behind the TTY guard and select_mode flag, so existing download flows are entirely unaffected. The two comments are UX polish — neither can cause data loss or incorrect downloads.
No files require special attention for correctness. sync_run.py has the minor notification ordering issue flagged inline.
Important Files Changed
Filename
Overview
librofm_downloader/selector.py
New module implementing interactive book selection via questionary checkbox. Logic is clean and correct; uses unsafe_ask() for Ctrl+C propagation, id()-based set for order preservation, and handles empty/rejected selections. Uses plain print() inconsistently with the rest of the codebase.
librofm_downloader/sync_run.py
Replaces the --select stub with a full pipeline: TTY guard (correctly uses sys.stdin.isatty()), Book conversion, select_books() call, limit bypass, and Book passthrough to orchestrator. The --limit bypass notification is unconditional but appears after the selection dialog rather than before it.
librofm_downloader/orchestrator.py
download_all_books now accepts pre-converted Book objects via isinstance check, avoiding double-conversion from select mode. Type annotation updated correctly to list[dict
Adds 5 integration tests covering TTY guard, all-caught-up with select, empty selection, Book passthrough to orchestrator, and limit bypass. Replaces old not-implemented stub test.
tests/test_orchestrator.py
Adds one test confirming Book objects pass through download_all_books without triggering from_library_row conversion.
librofm_downloader/cli.py
Removes "[not implemented]" from --select help text. Minimal, correct change.
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[sync_run called\nwith select_mode=True] --> B{TTY check\nsys.stdin.isatty?}
B -- No --> C[Print error\nReturn fatal_error result]
B -- Yes --> D[Filter already-downloaded\nlimit bypass applied]
D --> E{new_books empty?}
E -- Yes --> F[All caught up!\nReturn empty result]
E -- No --> G[from_library_row\ndict to Book list]
G --> H[select_books\nquestionary checkbox]
H -- KeyboardInterrupt --> I[Propagated to caller]
H -- empty/rejected --> J[Return empty result]
H -- selected --> K{limit > 0?}
K -- Yes --> L[Print limit-superseded notice]
K -- No --> M[Pass Book list\nto download_all_books]
L --> M
M --> N{isinstance Book?}
N -- Yes --> O[Use directly\nno conversion]
N -- No --> P[from_library_row\nconvert dict]
O --> Q[ThreadPoolExecutor\ndownload]
P --> Q
<h3>Greptile Summary</h3>
This PR implements the `--select` flag end-to-end, replacing the previous stub with a full interactive pipeline: a TTY guard, dict→Book conversion, a `questionary` checkbox prompt, and a Book passthrough to the orchestrator that avoids double-conversion.
- **`selector.py`** is a new module exposing `select_books()` with a checkbox prompt, Ctrl+C propagation via `unsafe_ask()`, a confirmation step, and order-preserving return via identity set.
- **`sync_run.py`** wires selection into the pipeline with `sys.stdin.isatty()` gating, `--limit` bypass (unconditionally notified when active), and passes pre-converted `Book` objects directly to the orchestrator.
- **`orchestrator.py`** accepts `list[dict | Book]` via an `isinstance` check, keeping existing dict callers unaffected while eliminating the double-conversion path from select mode.
<h3>Confidence Score: 5/5</h3>
Safe to merge — the selection pipeline is well-guarded (TTY check, empty-selection exit, confirmation step) and all changes are backward-compatible.
The new --select path is well-isolated behind the TTY guard and select_mode flag, so existing download flows are entirely unaffected. The two comments are UX polish — neither can cause data loss or incorrect downloads.
No files require special attention for correctness. sync_run.py has the minor notification ordering issue flagged inline.
<h3>Important Files Changed</h3>
| Filename | Overview |
|----------|----------|
| librofm_downloader/selector.py | New module implementing interactive book selection via questionary checkbox. Logic is clean and correct; uses unsafe_ask() for Ctrl+C propagation, id()-based set for order preservation, and handles empty/rejected selections. Uses plain print() inconsistently with the rest of the codebase. |
| librofm_downloader/sync_run.py | Replaces the --select stub with a full pipeline: TTY guard (correctly uses sys.stdin.isatty()), Book conversion, select_books() call, limit bypass, and Book passthrough to orchestrator. The --limit bypass notification is unconditional but appears after the selection dialog rather than before it. |
| librofm_downloader/orchestrator.py | download_all_books now accepts pre-converted Book objects via isinstance check, avoiding double-conversion from select mode. Type annotation updated correctly to list[dict | Book]. |
| tests/test_selector.py | 9 tests covering formatting, selection ordering, empty/rejection flows, Ctrl+C propagation, and single-book case. |
| tests/test_sync_run.py | Adds 5 integration tests covering TTY guard, all-caught-up with select, empty selection, Book passthrough to orchestrator, and limit bypass. Replaces old not-implemented stub test. |
| tests/test_orchestrator.py | Adds one test confirming Book objects pass through download_all_books without triggering from_library_row conversion. |
| librofm_downloader/cli.py | Removes "[not implemented]" from --select help text. Minimal, correct change. |
</details>
<h3>Flowchart</h3>
```mermaid
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[sync_run called\nwith select_mode=True] --> B{TTY check\nsys.stdin.isatty?}
B -- No --> C[Print error\nReturn fatal_error result]
B -- Yes --> D[Filter already-downloaded\nlimit bypass applied]
D --> E{new_books empty?}
E -- Yes --> F[All caught up!\nReturn empty result]
E -- No --> G[from_library_row\ndict to Book list]
G --> H[select_books\nquestionary checkbox]
H -- KeyboardInterrupt --> I[Propagated to caller]
H -- empty/rejected --> J[Return empty result]
H -- selected --> K{limit > 0?}
K -- Yes --> L[Print limit-superseded notice]
K -- No --> M[Pass Book list\nto download_all_books]
L --> M
M --> N{isinstance Book?}
N -- Yes --> O[Use directly\nno conversion]
N -- No --> P[from_library_row\nconvert dict]
O --> Q[ThreadPoolExecutor\ndownload]
P --> Q
```
<!-- greptile_other_comments_section -->
<sub>Reviews (2): Last reviewed commit: ["fix(sync\_run): show limit-bypass notice ..."](https://github.com/alexkucera/librofm-downloader/commit/b9d90b7618b53f528801cfe5859003a8917707df) | [Re-trigger Greptile](https://app.greptile.com/api/retrigger?id=36000176)</sub>
The guard uses sys.stdout.isatty(), but interactive prompts read from stdin. If a user redirects stdout (e.g., librofm-dl --select 2>&1 | tee log.txt), this check returns False and blocks --select even though the keyboard is fully available. More critically, the inverse case is dangerous: if stdin is non-interactive (e.g., piped in CI), sys.stdout.isatty() can return True and allow the prompt to proceed, at which point questionary blocks waiting for keyboard input that will never arrive. The guard should check sys.stdin.isatty().
<a href="#"><img alt="P1" src="https://greptile-static-assets.s3.amazonaws.com/badges/p1.svg?v=9" align="top"></a> **TTY guard checks the wrong file descriptor**
The guard uses `sys.stdout.isatty()`, but interactive prompts read from **stdin**. If a user redirects stdout (e.g., `librofm-dl --select 2>&1 | tee log.txt`), this check returns `False` and blocks `--select` even though the keyboard is fully available. More critically, the inverse case is dangerous: if stdin is non-interactive (e.g., piped in CI), `sys.stdout.isatty()` can return `True` and allow the prompt to proceed, at which point questionary blocks waiting for keyboard input that will never arrive. The guard should check `sys.stdin.isatty()`.
The --limit bypass notification only prints when verbose=True. A user who runs --select --limit 5 without --verbose gets no indication their --limit flag was silently ignored — they may select 10 books expecting the limit to cap downloads and be surprised. The warning should be unconditional whenever limit > 0 and select_mode=True.
if limit:
console.print("[dim]Selection mode active -- --limit superseded by manual selection.[/dim]")
<a href="#"><img alt="P1" src="https://greptile-static-assets.s3.amazonaws.com/badges/p1.svg?v=9" align="top"></a> The `--limit` bypass notification only prints when `verbose=True`. A user who runs `--select --limit 5` without `--verbose` gets no indication their `--limit` flag was silently ignored — they may select 10 books expecting the limit to cap downloads and be surprised. The warning should be unconditional whenever `limit > 0` and `select_mode=True`.
```suggestion
if limit:
console.print("[dim]Selection mode active -- --limit superseded by manual selection.[/dim]")
```
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Introduces the
--selectcommand-line option, allowing users to interactively choose specific books from their library for download.Key changes and benefits:
--limitis automatically bypassed when interactive selection is active, with a clear user notification.Closes #47, Closes #48.
Greptile Summary
This PR implements the
--selectflag end-to-end, replacing the previous stub with a full interactive pipeline: a TTY guard, dict→Book conversion, aquestionarycheckbox prompt, and a Book passthrough to the orchestrator that avoids double-conversion.selector.pyis a new module exposingselect_books()with a checkbox prompt, Ctrl+C propagation viaunsafe_ask(), a confirmation step, and order-preserving return via identity set.sync_run.pywires selection into the pipeline withsys.stdin.isatty()gating,--limitbypass (unconditionally notified when active), and passes pre-convertedBookobjects directly to the orchestrator.orchestrator.pyacceptslist[dict | Book]via anisinstancecheck, keeping existing dict callers unaffected while eliminating the double-conversion path from select mode.Confidence Score: 5/5
Safe to merge — the selection pipeline is well-guarded (TTY check, empty-selection exit, confirmation step) and all changes are backward-compatible.
The new --select path is well-isolated behind the TTY guard and select_mode flag, so existing download flows are entirely unaffected. The two comments are UX polish — neither can cause data loss or incorrect downloads.
No files require special attention for correctness. sync_run.py has the minor notification ordering issue flagged inline.
Important Files Changed
Flowchart
Reviews (2): Last reviewed commit: "fix(sync_run): show limit-bypass notice ..." | Re-trigger Greptile
@@ -213,10 +214,26 @@ def sync_run(console.print("[green]All caught up! No new books to download.[/green]")The guard uses
sys.stdout.isatty(), but interactive prompts read from stdin. If a user redirects stdout (e.g.,librofm-dl --select 2>&1 | tee log.txt), this check returnsFalseand blocks--selecteven though the keyboard is fully available. More critically, the inverse case is dangerous: if stdin is non-interactive (e.g., piped in CI),sys.stdout.isatty()can returnTrueand allow the prompt to proceed, at which point questionary blocks waiting for keyboard input that will never arrive. The guard should checksys.stdin.isatty().--limitbypass notification only prints whenverbose=True. A user who runs--select --limit 5without--verbosegets no indication their--limitflag was silently ignored — they may select 10 books expecting the limit to cap downloads and be surprised. The warning should be unconditional wheneverlimit > 0andselect_mode=True.