Commit Graph

43 Commits

Author SHA1 Message Date
Parasitic-Hollow
ac3788d52e fix: extend thought signature caching to Gemini 3 models
Add gemini-3 pattern matching to shouldCacheThinkingSignatures() to
enable proper thought signature handling for multi-turn conversations
with function calling on Gemini 3 models, alongside existing Claude support.
2025-12-31 21:40:46 -04:00
Tinh To
25def81b22 Merge pull request #58 from CasualDeveloper/fix/prevent-infinite-loop-normalize-empty-tool-schemas
fix: prevent infinite loop and normalize empty tool schemas for thinking models
2025-12-26 18:01:13 +07:00
tctinh
e4cb087ee9 refactor: remove medium tier models and update model resolution logic 2025-12-26 17:49:43 +07:00
CasualDeveloper
3a5a3fa50a fix: prevent infinite loop, normalize empty tool schemas, and retry thinking recovery
- Add guards when accountCount <= 1 to prevent infinite while(true) loop
- Force type: 'object' and inject placeholder property for empty Claude schemas
- Fix THINKING_RECOVERY_NEEDED to actually retry with closeToolLoopForThinking()
  instead of returning a useless 'send continue' error message

The thinking recovery now:
1. Detects API error indicating thinking_block_order issue
2. Sets forceThinkingRecovery flag and restarts endpoint loop
3. On retry, closeToolLoopForThinking() strips all thinking and injects
   synthetic messages to start a fresh turn
4. Only retries once to avoid infinite loops
2025-12-26 18:48:17 +08:00
tctinh
10fb25ad8c Merge origin/dev into feature/fix-tool-pairing
Resolves import conflicts in request.ts - keeps both transform imports
and detectErrorType import from recovery module.
2025-12-26 12:12:31 +07:00
tctinh
f145c7e5cb fix: add inline recovery for thinking_block_order errors
- Export detectErrorType() and isRecoverableError() from recovery.ts
- Import detectErrorType in request.ts
- Detect thinking_block_order errors in transformAntigravityResponse
- Throw THINKING_RECOVERY_NEEDED to trigger recovery in fetch wrapper
- Return synthetic error response with recovery instructions

The session.error hook wasn't being triggered for API 400 errors.
This fix catches recoverable errors inline and returns a user-friendly
message instructing them to send 'continue' to resume.
2025-12-26 12:07:45 +07:00
tctinh
ab86d6d8d1 fix: prevent tool_use without tool_result errors
Add defense-in-depth protection against Claude API tool pairing errors:

- findOrphanedToolUseIds(): Detect orphaned tool_use blocks
- fixClaudeToolPairing(): Inject placeholder tool_result responses
- validateAndFixClaudeToolPairing(): Nuclear fallback removes broken blocks
- 12 new unit tests covering all edge cases

Fixes permanent session corruption when ESC pressed or context compacted.
2025-12-26 11:44:06 +07:00
tctinh
6c1e3b7b40 feat: Implement session recovery module for handling recoverable errors
- Added recovery functionality for tool_result_missing, thinking_block_order, and thinking_disabled_violation errors.
- Introduced constants and types for session recovery.
- Created storage utilities for reading and writing session data.
- Enhanced debug logging capabilities in debug.ts.
- Refactored debug state management for better initialization and access.
2025-12-26 02:09:15 +07:00
tctinh
bd9e6ef1bc fix: add thinking recovery message for toast notifications in plugin 2025-12-26 01:35:07 +07:00
tctinh
a31141818e fix: add thinking recovery to prevent permanent session breakage
When Claude's conversation history gets corrupted (thinking blocks stripped
by context compaction, signature cache miss, etc.), the session would break
permanently with: 'Expected thinking or redacted_thinking, but found text'

This adds a 'last resort' recovery mechanism:

1. After all existing thinking/tool processing, analyze conversation state
2. If in tool loop WITHOUT thinking at turn start = corrupted state
3. Instead of trying to fix: close the turn and start fresh
   - Strip all (potentially corrupted) thinking blocks
   - Inject synthetic MODEL message: '[Tool execution completed.]'
   - Inject synthetic USER message: '[Continue]'
4. Clear signature cache for this session

Philosophy: 'Let it crash and start again' - Don't fight corruption,
just abandon the corrupted turn and let Claude generate fresh thinking.

New file: src/plugin/thinking-recovery.ts
- analyzeConversationState(): Detect tool loops and thinking state
- closeToolLoopForThinking(): Inject synthetic messages to start fresh
- needsThinkingRecovery(): Check if recovery is needed

Integration in request.ts:
- Added as LAST RESORT after all existing processing (line ~1272)
- Only triggers when: isClaudeThinkingModel && inToolLoop && !turnHasThinking
- Logs warning when recovery is triggered for debugging
2025-12-26 00:14:38 +07:00
Noe
b7c6222ce3 feat: add option to preserve thinking blocks for Claude models with trade-offs 2025-12-24 10:44:05 +01:00
tctinh
0f74555d0c feat: improve thinking block handling in Antigravity request preparation 2025-12-24 15:09:02 +07:00
tctinh
dd5ea5556f feat: update Claude model handling to strip all thinking blocks, eliminating signature errors, improve parsing tool and thinking logic reference to CLIProxyAPI 2025-12-24 14:35:12 +07:00
tctinh
5d52ed0fa4 Add Antigravity schema cleaner and warmup fixes
Port CleanJSONSchemaForAntigravity from CLIProxyAPI to convert
unsupported JSON Schema features into description hints and remove
unsupported keywords. Add warmup tracking improvements: retry limit,
success marking, and cleanup when evicting old entries.
2025-12-24 12:25:47 +07:00
tctinh
e13bb8b4d7 Rename sessionId to signatureSessionKey 2025-12-23 23:13:18 +07:00
tctinh
9e430af3e6 feat: implement thinking signature safeguards and enhance filtering mechanisms 2025-12-23 14:40:27 +07:00
tctinh
66a7cacfbb feat: enhance thinking block filtering with cached signature validation 2025-12-23 09:10:22 +07:00
Noe
07e449fb66 PR Fixes 2 2025-12-22 23:27:53 +01:00
Noe
abba87ad12 PR Fixes 2025-12-22 23:24:20 +01:00
Noe
e382fcd644 Improves Gemini quota handling with dual pools
Enhances Gemini quota management by introducing dual quota pools (Antigravity and Gemini CLI) for increased quota availability.

Gemini models now automatically fall back to the second quota pool when the first is exhausted, effectively doubling the quota per account.
2025-12-22 23:07:57 +01:00
Noe
2a4909bdae PR fixes 2025-12-21 13:13:05 +01:00
Noe
33932280e0 feat: refactor debug logging to write to file and enhance plugin entry handling 2025-12-21 12:57:06 +01:00
Noe
c611e4dde4 feat: enhance logging functionality with configurable log directory and debug output 2025-12-21 12:40:08 +01:00
Noe
a5f2ff440c feat: implement auto-update checker for Antigravity plugin with installation instructions and model updates 2025-12-21 03:09:16 +01:00
Noe
684076eaba Improves Antigravity account management and debugging
Refactors account management to support sticky sessions, per-model-family rate limits, and enhanced debugging capabilities.

- Implements sticky account selection, preserving Anthropic's prompt cache by sticking to the same account until a rate limit is encountered.
- Tracks rate limits separately for Claude and Gemini models, allowing an account to be used for one model family even if rate-limited for another.
- Introduces a smart retry threshold for short rate limits, retrying on the same account to avoid unnecessary switching.
- Adds exponential backoff for consecutive rate limits, increasing delays with each subsequent 429 error.
- Includes quota reset times in rate limit toast notifications when available from the API.
- Debounces toast notifications to prevent spam during streaming responses.
- Introduces a quiet mode to suppress account-related toast notifications via an environment variable.
- Enhances debug logging with level-based verbosity, TUI integration, and auto-stripping of injected debug blocks.
2025-12-21 02:25:44 +01:00
Noe
dd17d3516c PR fixes 2025-12-18 12:10:02 +00:00
tctinh
ae86e3a5f5 feat: enhance removeTrailingThinkingBlocks to preserve signed thinking blocks 2025-12-18 10:47:12 +07:00
tctinh
08f9da97f7 feat: implement thinking block sanitization for Claude API compliance 2025-12-18 10:47:02 +07:00
Noe
314ac9d427 feat(claude): add multi-turn thinking signature caching and real-time SSE streaming
Implement comprehensive support for Claude thinking models with interleaved
thinking in multi-turn conversations:

- Add signature caching system to preserve and restore thinking block
  signatures across conversation turns, preventing "invalid signature" errors
- Enable real-time SSE streaming with immediate forwarding of thinking tokens
- Add interleaved-thinking-2025-05-14 beta header for Claude thinking models
- Implement smart system hints to encourage thinking during tool use
- Add VALIDATED mode for tool calling on Claude models
- Ensure output token limits accommodate thinking budgets
- Filter and sanitize thinking blocks, removing SDK-injected cache_control
- Add comprehensive test suites for auth, cache, and request-helpers modules
- Update build config to exclude test files from production builds
- Document streaming and thinking features in README
2025-12-17 15:52:40 +00:00
Noe
c42a90d645 feat(auth): add login mode selection and improve rate limit handling
- Add CLI prompt to choose between adding accounts or starting fresh
- Implement automatic retry with backoff for single-account rate limits
- Show toast notifications for account switching and rate limit status
- Clear stale account storage when OpenCode auth state changes
- Add sleep helper function with abort signal support
- Improve README with clearer step-by-step setup instructions

TUI flow now adds accounts non-destructively; CLI flow offers choice.
2025-12-17 00:09:17 +00:00
Noe
2052e4d580 Add multi-account load balancing and improved OAuth UX
Adds multi-account support and round-robin load balancing for Google Antigravity OAuth to increase request throughput and resilience. Introduces an on-disk account pool with cooldowns for rate-limited accounts, automatic removal of revoked refresh tokens, and persistence of rotation state.

Improves OAuth flows and UX: CLI flow can add multiple accounts with per-account project IDs, TUI flow remains single-account, improved browser opening/fallback copy-paste handling, and clearer prompts for pasting redirect URLs or codes. Adds robust parsing of callback input and better headless handling.

Makes token refresh handling explicit and typed (throws a specific error on invalid_grant) and centralizes account management logic into an in-memory manager with persistence utilities. Adds tests for account rotation and rate-limit behavior and bumps package version.

Overall, this increases reliability under rate limits, makes multi-account configuration straightforward, and improves error handling and developer/user experience.
2025-12-16 01:35:02 +00:00
tctinh
98fe23a19b feat: add headers initialization for response transformation in Antigravity 2025-12-13 17:00:10 +07:00
tctinh
09509c3038 Merge branch 'main' of github.com:tctinh/opencode-antigravity-auth 2025-12-13 16:57:54 +07:00
tctinh
a85e6be8dc feat: enhance schema normalization and streaming response handling in Antigravity requests 2025-12-13 16:39:45 +07:00
tctinh
85d2847baf feat: implement true streaming support for SSE responses with TransformStream and enhance response transformation 2025-12-13 10:36:48 +07:00
tctinh
52597a212b feat: enhance thinking/reasoning support with configuration extraction and filtering 2025-12-12 12:41:16 +07:00
tctinh
7bd9474a88 feat: add thinking/reasoning support for Claude and Gemini models
- Add transformThinkingParts() to transform thinking content in responses
- Handle both Gemini-style (thought: true) and Anthropic-style (type: thinking)
- Extract thinking config from extra_body and Anthropic-style options
- Auto-enable thinking for thinking-capable models (opus, gemini-3, thinking)
- Filter unsigned thinking blocks for Claude multi-turn conversations
- Apply transformations to both streaming and JSON responses
2025-12-12 11:36:03 +07:00
tctinh
e2b2e9b955 Fix tool call issue with claude model cause by multiples tool call result 2025-12-11 00:17:37 +07:00
Noe
8e58a2474c better repo config 2025-12-10 15:18:43 +00:00
Noe
fe39ca886d Fixed anthropic models tool use 2025-12-10 13:14:55 +00:00
Noe
d946805235 Updates to make it work with workspace accounts 2025-12-10 11:33:03 +00:00
Noe
6a801b6373 Removed fallback logic 2025-12-10 10:32:32 +00:00
Noe
5d229bf44e First commit - auth and models working 2025-12-09 23:59:18 +00:00