Commit graph

4 commits

Author SHA1 Message Date
Brandy Good
51112a4cf3
fix: only strip valid env assignments in command parsing (#229)
Some checks are pending
CI / checks (push) Waiting to run
## What changed
This updates the command parsing helpers to recognize leading
environment assignments only when they match shell-style variable syntax
like `FOO=bar`. The previous implementation treated any leading token
containing `=` as an env assignment, which could misclassify real
commands or file paths that happen to include `=`. Both
`_strip_env_assignments()` and `extract_command_prefix()` now share the
same validation helper so their behavior stays consistent.

## Why it matters
These helpers are used by fast-path request optimizations, so incorrect
prefix detection can bypass normal handling with the wrong result.
Restricting env stripping to valid assignment tokens fixes false
positives without changing the public API or the response format.

## How it was tested
I validated the updated logic against representative inputs such as
`FOO=bar git status`, plain commands like `git status`, and malformed or
path-like tokens containing `=` that should not be treated as env
assignments. The change is isolated to parsing logic and does not
introduce new dependencies.

---------

Co-authored-by: genoshide <genoshide@users.noreply.github.com>
2026-04-27 18:34:48 -07:00
Brandy Good
19ce65647e
fix: handle env-prefixed commands in filepath extraction (#207)
Some checks are pending
CI / checks (push) Waiting to run
## What changed
This updates `extract_filepaths_from_command()` to skip leading
environment variable assignments before detecting the actual command.
The same parsing pattern was already used in `extract_command_prefix()`,
but filepath extraction still treated the first token as the command
even when it was an env assignment.

## Why it matters
Commands like `FOO=bar cat README.md` or `DEBUG=1 grep pattern file.txt`
were incorrectly classified because `FOO=bar` was treated as the
executable name. That caused the optimization path to return an empty
`<filepaths>` block instead of the file paths the command actually
reads.

## How it was tested
Tested the updated logic against env-prefixed read commands such as
`FOO=bar cat README.md` and `DEBUG=1 grep needle app.py`. Also verified
existing behavior remains unchanged for plain commands like `cat
file.txt`, `grep pattern file.txt`, and listing commands like `ls`.

Co-authored-by: genoshide <genoshide@users.noreply.github.com>
2026-04-26 15:02:12 -07:00
Alishahryar1
f3a7528d49 Major refactor: API, providers, messaging, and Anthropic protocol
Some checks are pending
CI / checks (push) Waiting to run
Consolidates the incremental refactor work into a single change set: modular web tools (api/web_tools), native Anthropic request building and SSE block policy, OpenAI conversion and error handling, provider transports and rate limiting, messaging handler and tree queue, safe logging, smoke tests, and broad test coverage.
2026-04-26 03:01:14 -07:00
Cursor Agent
25c7123e33 Phase 7 & 8: Routes optimization refactor and request utils split
Phase 7 - Optimization handlers:
- Create api/optimization_handlers.py with try_prefix_detection,
  try_quota_mock, try_title_skip, try_suggestion_skip, try_filepath_mock
- Add try_optimizations() that runs handlers in order
- Refactor routes.create_message to use try_optimizations()
- Update test_routes_optimizations patch targets

Phase 8 - Request utils split:
- Create api/detection.py: is_quota_check_request, is_title_generation_request,
  is_prefix_detection_request, is_suggestion_mode_request,
  is_filepath_extraction_request
- Create api/command_utils.py: extract_command_prefix, extract_filepaths_from_command
- Slim request_utils.py to get_token_count + re-exports for backward compat

Co-authored-by: Ali Khokhar <alishahryar2@gmail.com>
2026-02-15 01:41:35 +00:00