Fix setup#59
Open
dgrieser wants to merge 21 commits into
Open
Conversation
- Added presence check for the `"text"` key before attempting to decode or pop it. - Prevents `KeyError` when messages lack a `"text"` field. - Improves robustness of message parsing logic.
- Accept token or full link from user input during authentication - Construct callback URL when a token is provided, safely quoting email and token - Import `quote` from `urllib.parse` for URL encoding purposes.
- Introduce a new executable `perplexity-cli` script. - Provides argument parsing for account email and prompt input. - Integrates `argcomplete` for shell autocomplete support. - Instantiates `Perplexity`, performs a search, outputs results, and closes the session. - Enables users to run Perplexity searches directly from the command line.
- Replace single `.perplexity_session` file with individual token files under `~/.cache/perplexity-cli` - Add `_token_path` helper to compute a safe file path for each email - Use `pathlib` and regex sanitization to create filesystem‑safe token filenames - Update session recovery, login, and termination to read/write the new token files - Remove all legacy `.perplexity_session` handling throughout the module
- Replace `input()` with a `sys.stderr` prompt and `sys.stdin.readline()` call - Allows token to be provided via piping or redirection without contaminating stdout - Improves compatibility in non‑interactive environments and scripts
- Wrap main execution in a try/except block to catch KeyboardInterrupt. - Exit with status code 130 on interrupt to signal user‑initiated termination. - Improves CLI behavior by providing a standard exit code for interrupts.
- Introduce `AnswerStreamParser` to extract incremental answer text from websocket events. - Export the parser from the package root for external use. - Update the CLI to process streamed answers, outputting text deltas in real‑time. - Add comprehensive parsing logic handling markdown blocks, chunks, and answer states.
- Introduce `-p/--pro` CLI option to request Pro (copilot) search - Pass appropriate `mode` argument to `Perplexity.search` based on the flag - Preserve default concise mode when the flag is not used
- Introduce `-s/--sources` option to the CLI to enable source inclusion. - Collect source URLs and names from streaming events in `AnswerStreamParser`. - Provide `format_sources` method to generate a readable sources list. - Append formatted sources to CLI output when the flag is used.
- Introduce `-r/--raw` option to output raw response events directly. - Bypass normal streaming processing when raw mode is enabled. - Adjust source output handling to skip when raw flag is used. - Enables users to inspect raw data for debugging or custom processing.
- Insert citation markers into streamed answers based on inline token annotations - Provide `has_citations`, `format_answer`, and `format_sources(cited_only)` helpers for citation-aware output - Collect annotations from markdown blocks to determine citation positions and source numbers - Update CLI to output formatted answer with citations when `--sources` is used and to list only cited sources - Preserve existing behavior when citations are not requested.
- Remove the `and not args.sources` guard so streamed deltas are always written. - Delete the block that formatted and printed answers when `--sources` was supplied. - Simplify the output flow by handling only raw streaming and regular text cases.
- Track raw_text separately and import regex utilities - Add formatting pipeline that respects code fences and formats inline citations - Introduce spacing logic to ensure citations are preceded by a space - Implement stable answer text handling to remove incomplete citation markers - Update chunk processing to use raw_text for accurate concatenation - Add helper methods for citation formatting and spacing cleanup
- Introduced `JSONDecodeError` and `RequestException` handling for safer session recovery. - Added `_reset_session` to reinitialize a fresh HTTP session with proper headers. - Refactored `_recover_session` to return a success flag and handle file/JSON errors. - Implemented `_bootstrap_socket_session` to encapsulate socket initialization with fallback logic. - Updated initialization flow to attempt session recovery, fallback to fresh login, and raise clear errors on failure. - Adjusted token persistence to write cookies only after a successful session lifecycle.
- Introduce `perplexity/config.py` to handle configuration storage, validation, and mail login setup. - Add `configure_mail` function and related helpers for interactive IMAP configuration. - Implement CLI `config mail` subcommand in `perplexity-cli` to configure mail settings. - Refactor token storage to use shared `config_dir` utility. - Integrate automatic retrieval of Perplexity login token from configured IMAP account in `Perplexity._login`. - Provide graceful fallback to manual token entry when mail retrieval fails. - Add comprehensive unit tests for mail URL extraction, config persistence, and login fallback. - Improve keyboard interrupt handling by flushing stderr before exiting.
Added an empty __init__.py so the tests directory is recognised as a Python package, allowing proper test discovery and relative imports.
…iguration - Introduce `loop_password` for secure password input with defaults. - Add yes/no validation helpers `is_valid_yes_no` and `parse_yes_no`. - Extend `configure_mail` to list existing accounts, use stored values as defaults, and prompt for folder and delete‑signin‑message options. - Store new settings (`folder`, `delete_signin_messages`) in configuration. - Implement `validate_mail_config` to verify IMAP credentials, TLS usage, and folder selection. - Update mailbox handling to respect configured folder and optional message deletion. - Expand test suite to cover new validation, defaults, folder handling, delete flag behavior, and interactive prompts.
…pport - Moved the entire CLI implementation from the executable script to a new `perplexity/cli.py` module - Added `OutputWriter` that conditionally uses Streamdown for rich markdown rendering - Introduced `build_parser`, `configure`, `run`, and `main` helpers for clearer separation of concerns - Updated the `perplexity-cli` entry point to delegate to `perplexity.cli.main` - Added `streamdown` as a runtime dependency in `setup.py` - Created comprehensive unit tests for the new CLI module covering raw output, rendered output, and configuration handling - Cleaned up unused imports and streamlined argument parsing flow.
- Introduce an internal buffer in `OutputWriter` to accumulate text until a double newline is encountered. - Render buffered content only when a complete paragraph is available, preventing premature rendering of partial lines. - Ensure any leftover buffer is flushed on `close`, guaranteeing all output is rendered. - Reset renderer state before each render to avoid list formatting artifacts. - Update tests to reflect the new rendering behavior, expecting combined paragraph outputs.
- Prepend a newline before the first rendered block and append one on close to ensure clean output separation. - Patch Streamdown setup to constrain terminal width and left‑align heading levels for better readability. - Reformat source sections in answers to use markdown headings and bullet list with links. - Wrap citation markers in backticks and adjust spacing logic for consistent markdown rendering. - Update tests to reflect the new output format, including the added newlines.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Otherwise I can't use setup.py with current python versions, e.g. 3.12