Commit graph

69 commits

Author SHA1 Message Date
Alishahryar1
0cca5699cb fix(messaging): reuse parent CLI session for Telegram reply continuation (#233)
Pass parent_session_id into get_or_create_session so reply nodes align with
the fork/resume path instead of always allocating a fresh pending session.
Add unit coverage and update integration expectations.
2026-04-27 16:24:31 -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
Alishahryar1
b926f60f64 feat: Anthropic web server tools, provider metadata, messaging hardening
- Add local web_search/web_fetch SSE handling and optional tool schemas
- Extend HeuristicToolParser for JSON-style WebFetch/WebSearch text
- Consolidate provider defaults, ids, and exception typing; stream contracts
- Messaging: typed options, voice config injection, platform contract cleanup
- Tests for web server tools, converters, parsers, contracts; ignore debug-*.log
2026-04-24 23:01:14 -07:00
Alishahryar1
0e3b2c24b4 refactor: remove OpenRouter rollback, shims, and redundant layers
- OpenRouter: native Anthropic only; remove chat_request and OPENROUTER_TRANSPORT
- Drop OpenAICompatibleProvider alias, api.request_utils, voice_pipeline facade
- Simplify OpenRouter SSE, generic reasoning in conversion, messaging dispatch
- Shared markdown table helpers; API optimization response helper; contract guards
- Restore PLAN.md; update docs and tests
2026-04-24 21:08:38 -07:00
Alishahryar1
26b8a29537 Architecture refactor: core anthropic, runtime, smoke tiers, remove providers.common 2026-04-24 20:03:14 -07:00
Alishahryar1
66ef23072c Refactor provider routing and smoke coverage 2026-04-24 19:34:34 -07:00
Ali Khokhar
fae8a2a044
Remove over-engineering: drop tree_queue setter, _set_connected(), fi… (#63)
…x cancel_all() TOCTOU

- Remove tree_queue property setter (backward-compat hack; all callers
already migrated to replace_tree_queue()); keep property getter only
- Update 2 remaining tests that still used direct assignment to use
replace_tree_queue()
- Remove _set_connected() 1-line wrapper on DiscordPlatform; assign
_connected directly
- Fix cancel_all() TOCTOU: hold self._lock for the full loop so newly
created trees cannot slip through between the snapshot and cancellation

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-03-01 12:34:00 -08:00
Alishahryar1
35a2760f6e Fixed encapsulation violations 2026-03-01 04:28:22 -08:00
Alishahryar1
34757511a0 Improve deterministic error surfacing across stream and API 2026-03-01 01:32:52 -08:00
Ali Khokhar
aee9f0ad93
Add code review fix plan covering 11 issues across modularity, encapsulation, performance, and dead code (#62) 2026-03-01 00:45:33 -08:00
Alishahryar1
744eec2772 Major cleanup with GLM-5 2026-02-28 09:10:21 -08:00
Alishahryar1
a74ec74271 Major refactor done with minimax m2.5 2026-02-28 04:36:29 -08:00
Claude
99f99fce90
Remove max_cli_sessions — CLI session pool is now unbounded
The max_sessions cap in CLISessionManager was the only thing enforcing
a limit on concurrent CLI processes. Now that provider concurrency is
controlled at the streaming layer (PROVIDER_MAX_CONCURRENCY semaphore),
the CLI session pool cap is redundant and removed entirely.

Changes:
- cli/manager.py: remove max_sessions param, cap check, _cleanup_idle_sessions_unlocked, max_sessions from get_stats()
- config/settings.py: remove max_cli_sessions field
- api/app.py: remove max_sessions=settings.max_cli_sessions from CLISessionManager constructor
- messaging/handler.py: remove "Waiting for slot" status check; stats display no longer shows Max CLI
- .env.example: remove MAX_CLI_SESSIONS line
- tests/cli/test_cli.py: remove max_sessions args and assertion from manager tests
- tests/cli/test_cli_manager_edge_cases.py: remove two tests for cap/cleanup behavior
- tests/api/test_app_lifespan_and_errors.py: remove max_cli_sessions from all SimpleNamespace settings
- tests/config/test_config.py: remove max_cli_sessions isinstance assertion
- tests/conftest.py: remove max_sessions from mock stats
- tests/messaging/test_handler.py: merge slot/capacity tests into single new-conversation test; remove Max CLI assertion from stats test
- tests/messaging/test_handler_markdown_and_status_edges.py: remove "Waiting for slot" assertion; drop max_sessions from all stats mocks

https://claude.ai/code/session_014mrF1WMNgmNjtPBuoQHsbg
2026-02-19 14:31:47 +00:00
Alishahryar1
16fa9d90cd Add message_thread_id support across messaging components
- Introduced message_thread_id to the IncomingMessage model for handling forum topic IDs in Telegram.
- Updated messaging platforms (Discord and Telegram) to accept and process message_thread_id in send_message methods.
- Modified message handlers to utilize message_thread_id when sending messages.
- Enhanced test cases to validate the integration of message_thread_id in message handling.

This change improves support for forum supergroups in Telegram and enhances message management across platforms.
2026-02-18 16:10:57 -08:00
Alishahryar1
2220880671 Add voice note cancellation feature during transcription
- Implemented functionality to cancel pending voice transcriptions when a user replies with the /clear command.
- Updated the Telegram and Discord platform classes to manage pending voice messages, including registration and cancellation logic.
- Enhanced the message handler to delete associated messages and notify users when a voice note is cancelled.
- Added tests to ensure the cancellation feature works as expected during transcription.
2026-02-18 06:36:42 -08:00
Alishahryar1
b05d0d2703 new linter rules and fixes 2026-02-18 04:13:41 -08:00
Alishahryar1
7300156925 Add status message handling for voice note processing
- Introduced a new optional field `status_message_id` in the IncomingMessage model to track the status of voice note processing.
- Updated the Telegram and Discord platforms to utilize the `status_message_id` for editing status messages instead of sending new ones.
- Modified tests to assert the correct status message ID is used during voice note handling.
- Changed status message text from "Processing voice note..." to "Transcribing voice note..." for clarity.
2026-02-16 20:48:47 -08:00
Cursor Agent
4b4f87515d Phase 7: Directory restructuring (messaging/ and tests/)
- Create messaging/platforms/ (base, discord, telegram, factory)
- Create messaging/rendering/ (discord_markdown, telegram_markdown)
- Create messaging/trees/ (data, repository, processor, queue_manager)
- Organize tests/ into api/, providers/, messaging/, cli/, config/
- Add backward-compatible re-exports at old locations
- Update handler.py and test_messaging_factory.py imports
- Fix Telegram type hints for TELEGRAM_AVAILABLE=False case
- Fix Python 3 except syntax in discord_markdown

Co-authored-by: Ali Khokhar <alishahryar2@gmail.com>
2026-02-17 02:25:42 +00:00
Cursor Agent
794e64bba9 Fix ruff format for handler.py and session.py
Co-authored-by: Ali Khokhar <alishahryar2@gmail.com>
2026-02-17 02:03:04 +00:00
Cursor Agent
bfc781e0ed Phase 4-6: Dead code removal, performance, minor fixes
Phase 4:
- Remove legacy SessionRecord, _sessions, _msg_to_session from SessionStore
- Fix hardcoded provider in root endpoint (use settings.provider_type)
- Update session store tests

Phase 5:
- Use list-based string accumulation in ThinkingSegment, TextSegment, ToolCallSegment
- Cache MAX_MESSAGE_LOG_ENTRIES_PER_CHAT at SessionStore init
- Use iterative DFS in MessageTree.get_descendants

Phase 6:
- Add comment for abstract async generator workaround in BaseProvider
- Rename TELEGRAM_EDIT log tags to PLATFORM_EDIT in handler

Co-authored-by: Ali Khokhar <alishahryar2@gmail.com>
2026-02-17 02:01:01 +00:00
Alishahryar1
6abcdb4017 Add clear command functionality to message handler
- Implemented handling of the `/clear` command to clear specific branches or entire trees based on message replies.
- Added tests for various scenarios of the clear command, including clearing branches, handling unknown replies, and clearing entire trees.
- Enhanced `TreeQueueManager` with methods to cancel branches and remove subtrees, ensuring proper state management in the session store.
- Updated `SessionStore` and `TreeRepository` to support removal of node mappings and trees, improving data integrity during clear operations.
2026-02-16 16:23:26 -08:00
Alishahryar1
6511542bfe Implement Discord bot support and update README for messaging platform changes 2026-02-16 00:08:09 -08:00
Alishahryar1
539854fe7b Refactor done using GLM-5 2026-02-15 21:58:03 -08:00
Alishahryar1
7dfcad2a4c Enhance logging and error handling across multiple modules
- Added request ID context to logging in FastAPI routes and NVIDIA NIM provider.
- Improved logging format to include context variables for better traceability.
- Updated message handling in Telegram and Claude handlers to log message previews.
- Enhanced error logging in NVIDIA NIM provider with request ID for easier debugging.
- Added logging for tree repository actions to track tree and node registrations.
2026-02-15 02:01:57 -08:00
Alishahryar1
7259b1def8 Optimized code in hot paths with z-ai/glm5 2026-02-14 19:59:46 -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
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
Alishahryar1
25b9d9d1e4 Added ruff and ty dependencies and lint 2026-02-14 18:00:21 -08: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
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
fabca59f5c lint 2026-02-13 17:24:18 -08:00
Alishahryar1
98966fe688 fixed table rendering v2 2026-02-13 16:57:14 -08:00
Alishahryar1
28a56d3af8 fixed table rendering for telegram 2026-02-13 16:31:46 -08:00
Alishahryar1
4ee0114891 Implemented /clear command 2026-02-13 16:24:52 -08:00
Alishahryar1
459ce6e8fd introduced per reply /stop command to stop just that task and fixed context leakage in reply session forking 2026-02-13 14:53:48 -08:00
Alishahryar1
42bfb2da9b improve test coverage 2026-02-13 12:54:48 -08:00
Alishahryar1
ff22e9baa2 lint 2026-02-08 04:10:57 -08:00
Alishahryar1
697bc37faf Upon dequeue the current request immediately displays processing state instead of position 1 waiting 2026-02-08 04:06:41 -08:00
Alishahryar1
6d8f13d84e Added feature to update queue positions on telegram when messages are dequeued and added new tests 2026-02-08 04:00:58 -08:00
Alishahryar1
0cad642e4b Implemented markdownv2 rendering 2026-02-05 17:31:40 -08:00
Alishahryar1
3a69a51f62 fixed markdown errors for telegram 2026-02-05 17:22:00 -08:00
Alishahryar1
fcbe204f44 Major refactor done with kimi-k2.5 in claude code 2026-02-05 10:51:33 -08:00
Alishahryar1
78d0276d03 fixed /stop 2026-01-31 14:39:24 -08:00
Alishahryar1
8ce86f4267 fixed type errors 2026-01-31 14:13:09 -08:00
Alishahryar1
303767e346 fixed linter errors 2026-01-30 23:32:02 -08:00
Alishahryar1
07b0c9233e switched to start truncation from end truncation 2026-01-30 17:05:23 -08:00