Commit Graph

248 Commits

Author SHA1 Message Date
Alishahryar1 952a2351ec always enabled thinking 2026-02-14 19:46:29 -08:00
Alishahryar1 d13d8d3502 Removed docs 2026-02-14 19:42:07 -08:00
Alishahryar1 710e532888 lint 2026-02-14 19:17:51 -08:00
Alishahryar1 9be9943401 Improved test coverage 2026-02-14 19:17:19 -08:00
Alishahryar1 96747f2216 Updated token counting and removed non streaming support 2026-02-14 19:10:09 -08:00
Alishahryar1 256a426036 Updated dependencies 2026-02-14 18:55:43 -08:00
Alishahryar1 ba344f26c9 Revamped logging 2026-02-14 18:55:33 -08:00
Alishahryar1 64e5b10612 Refactor done by z-ai/glm5 2026-02-14 18:47:26 -08:00
Ali Khokhar 754ca99314 Merge pull request #12 from Alishahryar1/cursor/type-check-errors-1d86
Type check errors
2026-02-14 18:30:24 -08:00
Cursor Agent b5e95849e3 Apply ruff format
Co-authored-by: Ali Khokhar <alishahryar2@gmail.com>
2026-02-15 02:29:03 +00:00
Cursor Agent 1cface7f8c Fix all ty check errors without using type: ignore
- messaging/telegram.py: Remove unused type: ignore, fix retry_after typing
  with isinstance(timedelta), use local app variable for None narrowing
- messaging/tree_data.py: Replace _queue._queue access with drain-and-restore
  approach for get_queue_snapshot (avoids private API)
- tests/test_api.py: Use APIError instead of RuntimeError for status_code test
- tests/test_config.py: Use cast(Any, ...) for invalid validation tests
- tests/test_dependencies.py: Add isinstance check for NvidiaNimProvider
- tests/test_handler_markdown_and_status_edges.py: Use patch.object for
  tree_queue method mocks
- tests/test_response_models.py: Add isinstance narrowing for content blocks,
  use Literal list for stop_reason parametrization
- tests/test_restart_reply_restore.py: Use patch.object for enqueue mock
- tests/test_server_module.py: Use patch.object for uvicorn.run and
  get_settings
- tests/test_telegram_edge_cases.py: Use patch.object for method mocks
- tests/test_tree_concurrency.py: Add None assertions for get_node/get_tree

Co-authored-by: Ali Khokhar <alishahryar2@gmail.com>
2026-02-15 02:28:33 +00:00
Ali Khokhar d0ea0a450f Merge pull request #11 from Alishahryar1/cursor/context-preservation-api-calls-219c
Context preservation api calls
2026-02-14 18:09:00 -08:00
Cursor Agent ec71a2232c fix: preserve interleaved thinking, tool calls, and text in Anthropic↔NIM conversion
- Assistant messages: build content string in block order (thinking+text interleaved)
- User messages: emit text before tool results when order is text→tool_result
- Response: add extract_think_content_interleaved() to preserve <think>...</think> order
- Add tests and docs for context preservation bugs

Co-authored-by: Ali Khokhar <alishahryar2@gmail.com>
2026-02-15 02:08:35 +00:00
Alishahryar1 ce47ba5994 Updated readme 2026-02-14 18:01:06 -08:00
Alishahryar1 25b9d9d1e4 Added ruff and ty dependencies and lint 2026-02-14 18:00:21 -08:00
Ali Khokhar cefc11d399 Merge pull request #10 from Alishahryar1/cursor/codebase-quality-review-473a
Codebase quality review
2026-02-14 17:57:15 -08:00
Cursor Agent c6f87c4344 Improve README: add centered heading, badges, and license section
Co-authored-by: Ali Khokhar <alishahryar2@gmail.com>
2026-02-15 01:45:13 +00:00
Cursor Agent aec01041d4 Remove CODEBASE_QUALITY_REVIEW.md and IMPLEMENTATION_PLAN.md from PR
Co-authored-by: Ali Khokhar <alishahryar2@gmail.com>
2026-02-15 01:44:04 +00: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
Cursor Agent 0bab393c05 Phase 6: Remove dynamic attribute creation in NIM client
ContentBlockManager already declares task_arg_buffer, task_args_emitted,
tool_ids. Remove defensive getattr/isinstance checks from _process_tool_call
and _flush_task_arg_buffers.

Update test_subagent_interception to set task_arg_buffer, task_args_emitted,
tool_ids on mock so it behaves like real ContentBlockManager.

Co-authored-by: Ali Khokhar <alishahryar2@gmail.com>
2026-02-15 01:39:43 +00:00
Cursor Agent 959d1bdf5b Phase 5: Encapsulation - Repository and MessageTree API
TreeRepository:
- Add has_node(node_id) -> bool
- Add tree_count() -> int

MessageTree:
- Add cancel_current_task() -> bool
- Add drain_queue_and_mark_cancelled() -> List[MessageNode]
- Add reset_processing_state()
- Add current_node_id property

TreeQueueManager:
- Remove _trees and _node_to_tree properties
- add_to_tree: use has_node() and get_tree_for_node()
- get_tree_count: use repository.tree_count()
- cancel_tree: use tree.cancel_current_task(), drain_queue_and_mark_cancelled(), reset_processing_state()

TreeQueueProcessor:
- cancel_current: delegate to tree.cancel_current_task()

Tests: update to use get_tree_count(), has_node(), get_tree_for_node()

Co-authored-by: Ali Khokhar <alishahryar2@gmail.com>
2026-02-15 01:38:35 +00:00
Cursor Agent 952e40dae7 Phase 4: O(1) find_node_by_status_message via reverse index
- Add _status_to_node: Dict[str, str] (status_msg_id -> node_id)
- Populate in __init__ (root), add_node, and from_dict
- find_node_by_status_message: O(n) -> O(1) lookup

Co-authored-by: Ali Khokhar <alishahryar2@gmail.com>
2026-02-15 01:37:00 +00:00
Cursor Agent f27c2caf18 Phase 3: Split _process_node into smaller methods
- _create_transcript_and_render_ctx(): returns transcript + RenderCtx
- _handle_session_info_event(): handles session_info, returns (captured, temp)
- _process_parsed_event(): processes single parsed event, returns (last_status, had_transcript_events)
- _process_node: now ~90 lines, delegates to helpers

Improves readability and testability.

Co-authored-by: Ali Khokhar <alishahryar2@gmail.com>
2026-02-15 01:36:12 +00:00
Cursor Agent 7496f67ae0 Phase 2: Extract markdown utilities to messaging/telegram_markdown.py
- Create messaging/telegram_markdown.py with all MarkdownV2 helpers
- Move escape_md_v2, escape_md_v2_code, escape_md_v2_link_url, mdv2_bold,
  mdv2_code_inline, format_status, render_markdown_to_mdv2
- Update handler.py to import from telegram_markdown (~300 lines removed)
- Update telegram.py to use shared escape_md_v2 (remove duplicate)
- Update tests to import from messaging.telegram_markdown

Co-authored-by: Ali Khokhar <alishahryar2@gmail.com>
2026-02-15 01:34:27 +00:00
Cursor Agent f80c7ce42e Remove _extract_text_from_content wrapper from logging_utils
Thin wrapper only used in tests. Tests now import extract_text_from_content
directly from utils.text.

Co-authored-by: Ali Khokhar <alishahryar2@gmail.com>
2026-02-15 01:32:04 +00:00
Cursor Agent 212b2b29b2 Remove dead code: extract_reasoning_from_delta
Exported but never used. NIM client uses getattr(delta, 'reasoning_content')
directly.

Co-authored-by: Ali Khokhar <alishahryar2@gmail.com>
2026-02-15 01:31:43 +00:00
Cursor Agent c4b52cb4ce Remove dead code: MessageTree.get_queue_position
Method always returned 0 and was never called. Queue positions
are computed on-the-fly in _update_queue_positions via get_queue_snapshot.

Co-authored-by: Ali Khokhar <alishahryar2@gmail.com>
2026-02-15 01:31:26 +00:00
Cursor Agent c0fae51592 Use uv run pytest for all test commands in implementation plan
Co-authored-by: Ali Khokhar <alishahryar2@gmail.com>
2026-02-15 01:31:05 +00:00
Cursor Agent be2d5b1d9e Add implementation plan for code quality fixes
Phased approach:
- Phase 1: Dead code removal (low risk)
- Phase 2: Extract markdown utilities, consolidate escape_md_v2
- Phase 3: Split _process_node into smaller methods
- Phase 4: O(1) find_node_by_status_message via reverse index
- Phase 5: Repository encapsulation, MessageTree API
- Phase 6: ContentBlockManager explicit fields
- Phase 7-8: Optional routes/request_utils refactor

Includes step-by-step actions, verification, and rollback strategy.

Co-authored-by: Ali Khokhar <alishahryar2@gmail.com>
2026-02-15 01:30:37 +00:00
Cursor Agent 341ffe09b2 Add comprehensive codebase quality review
Covers:
- Code modularity: handler.py mixed concerns, request_utils organization
- Class design: TreeQueueManager encapsulation, MessageTree internals
- Code simplicity: extract markdown utils, split _process_node
- Encapsulation: repository direct access, SessionStore/TreeRepository overlap
- Dead code: get_queue_position, extract_reasoning_from_delta, _extract_text wrapper
- Time complexity: find_node_by_status_message O(n) -> O(1) with index

Co-authored-by: Ali Khokhar <alishahryar2@gmail.com>
2026-02-15 01:29:03 +00:00
Alishahryar1 42a833245f Removed all signal handler logic 2026-02-14 17:17:58 -08:00
Ali Khokhar 7e91cf3f6e Update ANTHROPIC_AUTH_TOKEN value in README 2026-02-14 16:08:29 -08:00
Ali Khokhar cab96429a7 Updated readme 2026-02-14 05:10:30 -08:00
Alishahryar1 bd1e097d74 fixed tool parser and added signal handlers 2026-02-14 04:25:12 -08:00
Alishahryar1 4b95429c32 fixed NIM_INTERCEPT for chunked tool calls 2026-02-14 03:25:32 -08:00
Alishahryar1 d2e6e52742 Subagent summarized display 2026-02-14 03:13:59 -08:00
Ali Khokhar 9f220d8c93 Fixed typo in readme 2026-02-14 02:50:36 -08:00
Alishahryar1 6887de9cab added more tests for parser and made it more robust 2026-02-14 02:49:21 -08:00
Alishahryar1 4247f411b0 Fixed truncation errors in telegram and added subagent display 2026-02-14 02:41:48 -08:00
Alishahryar1 b95f2ef9c4 Revamped telegram result display 2026-02-14 02:14:36 -08:00
Alishahryar1 85eed8a1bc updated heuristic tool parser for orphaned toolcall tags 2026-02-14 00:16:54 -08:00
Alishahryar1 8647aa52c5 Revert "force enabled thinking"
This reverts commit eaaaab2c42.
2026-02-13 22:59:54 -08:00
Alishahryar1 89edeaa6ac Migrated telegram rate limiter to sliding window 2026-02-13 22:12:33 -08:00
Alishahryar1 171dc11ae7 Merge branch 'main' of https://github.com/Alishahryar1/cc-nim 2026-02-13 22:02:36 -08:00
Alishahryar1 5471044258 limiter time complexity improved by kimi-k2.5 in claude-code 2026-02-13 22:02:34 -08:00
Ali Khokhar c621aa3c3e Update README.md 2026-02-13 22:02:15 -08:00
Alishahryar1 eaaaab2c42 force enabled thinking 2026-02-13 21:52:54 -08:00
Ali Khokhar 9e56866a28 Update README.md 2026-02-13 19:43:27 -08:00
Alishahryar1 665e24e2db Migrated from token bucket rate limiter to sliding window rate limiter 2026-02-13 19:05:16 -08:00
Ali Khokhar 8c7097d6f2 Update README with Anthropic model instructions
Added instructions for reverting to Anthropic models.
2026-02-13 18:33:54 -08:00