Commit Graph

271 Commits

Author SHA1 Message Date
Badri Narayanan S
ea3d3ca4a4 format readme for headless server account addition 2026-01-04 14:59:29 +05:30
Badri Narayanan S
3c0a4845d6 Merge pull request #50 from badri-s2001/feature/headless-server
feat: add --no-browser OAuth mode for headless servers
2026-01-04 14:53:08 +05:30
Badri Narayanan S
1628696ca1 fix: correct state destructuring and document headless mode
- Fix extractCodeFromInput destructuring: returns { code, state } not
  { code, extractedState }, so state validation was being bypassed
- Add --no-browser hint to CLI banner for discoverability
- Document --no-browser mode in README.md and CLAUDE.md
- Add test:oauth script to package.json
- Add OAuth test to run-all.cjs test suite

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-04 14:51:05 +05:30
Caixiaopig
573ba57db6 feat: add --no-browser OAuth mode for headless servers
## Feature Description

Enables adding Google accounts on remote servers without a desktop
environment (headless Linux, Docker containers, SSH sessions) where
automatic browser opening is not possible. Users can manually copy the
authorization URL to a device with a browser, complete authentication,
and paste the authorization code back.

## Usage

npm run accounts:add -- --no-browser

## Code Architecture

### New Modules

1. oauth.js - extractCodeFromInput()
   - Parses user input (full callback URL or raw authorization code)
   - Extracts code and state parameters
   - Handles OAuth error responses

2. accounts.js - addAccountNoBrowser()
   - Account addition flow for no-browser mode
   - Displays authorization URL for manual copying
   - Waits for user to paste authorization code
   - Calls extractCodeFromInput to parse input
   - Completes OAuth flow and saves account

3. tests/test-oauth-no-browser.cjs
   - 13 unit tests covering valid URLs, raw codes, error handling, edge cases

### Modified Modules

1. accounts.js - interactiveAdd()
   - Added noBrowser parameter
   - Selects addAccount or addAccountNoBrowser based on mode

2. accounts.js - main()
   - Parses --no-browser CLI argument
   - Updated help information

## User Flow

┌─────────────────────────────────────────────────────────────┐
│                   Headless Server Terminal                   │
└─────────────────────────────────────────────────────────────┘
                              │
                              ▼
            ┌─────────────────────────────────┐
            │ npm run accounts:add -- --no-browser │
            └─────────────────────────────────┘
                              │
                              ▼
            ┌─────────────────────────────────┐
            │   Display Google OAuth URL       │
            │   (manual copy required)         │
            └─────────────────────────────────┘
                              │
         ┌────────────────────┴────────────────────┐
         │                                         │
         ▼                                         ▼
┌─────────────────┐                    ┌─────────────────────┐
│  Local Browser  │                    │  Phone/Other Device │
│  Open URL       │                    │  Open URL           │
│  Google Sign-in │                    │  Google Sign-in     │
│  Authorize App  │                    │  Authorize App      │
└─────────────────┘                    └─────────────────────┘
         │                                         │
         └────────────────────┬────────────────────┘
                              │
                              ▼
            ┌─────────────────────────────────┐
            │ Browser redirects to localhost   │
            │ (page won't load - this is OK)   │
            │ Copy full URL or code parameter  │
            └─────────────────────────────────┘
                              │
                              ▼
            ┌─────────────────────────────────┐
            │ Return to server terminal        │
            │ Paste URL or authorization code  │
            └─────────────────────────────────┘
                              │
                              ▼
            ┌─────────────────────────────────┐
            │ ✓ Account added successfully     │
            └─────────────────────────────────┘

## Security Considerations

- Supports state parameter validation (when user pastes full URL)
- Warns on state mismatch but allows continuation (manual mode tolerance)
- Authorization code length validation to prevent incorrect input

## Compatibility

- Does not affect existing automatic browser OAuth flow
- All changes are additive, no modifications to upstream logic
- Easy to merge future upstream updates
2026-01-04 14:46:16 +05:30
Badri Narayanan S
d03c79cc39 Merge pull request #41 from badri-s2001/feature/model-fallback
Feature/model fallback
2026-01-04 02:32:32 +05:30
Badri Narayanan S
e0b3f90777 docs: update CLAUDE.md with model fallback and cross-model features
- Add --fallback and --debug startup flags to commands section
- Add test:crossmodel script for cross-model thinking tests
- Document fallback-config.js module in directory structure
- Add Model Fallback section explaining fallback behavior
- Add Cross-Model Thinking Signatures section explaining compatibility
- Update constants section with MODEL_FALLBACK_MAP

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-04 00:19:35 +05:30
Badri Narayanan S
141558dd62 Improve cross-model thinking handling and add gemini-3-flash fallback
- Add gemini-3-flash to MODEL_FALLBACK_MAP for completeness
- Add hasGeminiHistory() to detect Gemini→Claude cross-model switch
- Trigger recovery for Claude only when Gemini history detected
- Remove unnecessary thinking block filtering for Claude-only conversations
- Add comments explaining '.' placeholder usage
- Remove unused filterUnsignedThinkingFromMessages function

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-04 00:11:14 +05:30
Badri Narayanan S
53f8d7f6cc Add debug logging when stripping thinking blocks
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-03 23:29:21 +05:30
Badri Narayanan S
12e427e9d5 Fix needsThinkingRecovery to require tool loop context
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-03 23:24:52 +05:30
Badri Narayanan S
dc65499c49 Preserve valid thinking blocks during recovery
Instead of stripping all thinking blocks during thinking recovery,
now only strips invalid or incompatible blocks. Uses signature cache
to validate family compatibility for cross-model fallback scenarios.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-03 23:17:38 +05:30
Badri Narayanan S
668c7aef26 correct els if condition for state.inToolLoop 2026-01-03 22:38:46 +05:30
Badri Narayanan S
b7286059ee remove targetFamily from analyzeConversationState 2026-01-03 22:13:35 +05:30
Badri Narayanan S
602d6ca0f8 move fallback map to constants 2026-01-03 22:05:16 +05:30
Badri Narayanan S
ac9ec6b358 Signature handling for fallback 2026-01-03 22:01:57 +05:30
Badri Narayanan S
df6625b531 fallback changes from PR #35 2026-01-03 18:01:21 +05:30
Badri Narayanan S
9c4a712a9a Selective fixes from PR #35: Model-specific rate limits & robustness improvements (#37)
* feat: apply local user changes and fixes

* ;D

* Implement OpenAI support, model-specific rate limiting, and robustness fixes

* docs: update pr title

* feat: ensure unique openai models endpoint

* fix: startup banner alignment and removed duplicates

* feat: add model fallback system with --fallback flag

* fix: accounts cli hanging after completion

* feat: add exit option to accounts cli menu

* fix: remove circular dependency warning for fallback flag

* feat: show active modes in banner and hide their flags

* Remove OpenAI compatibility and fallback features from PR #35

Cherry-picked selective fixes from PR #35 while removing:
- OpenAI-compatible API endpoints (/openai/v1/*)
- Model fallback system (fallback-config.js)
- Thinking block skip for Gemini models
- Unnecessary files (pullrequest.md, test-fix.js, test-openai.js)

Retained improvements:
- Network error handling with retry logic
- Model-specific rate limiting
- Enhanced health check with quota info
- CLI fixes (exit option, process.exit)
- Startup banner alignment (debug mode only)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* banner alignment fix

* Refactor: Model-specific rate limits and cleanup deprecated code

- Remove global rate limit fields (isRateLimited, rateLimitResetTime) in favor of model-specific limits (modelRateLimits[modelId])
- Remove deprecated wrapper functions (is429Error, isAuthInvalidError) from handlers
- Filter fetchAvailableModels to only return Claude and Gemini models
- Fix getCurrentStickyAccount() to pass model param after waiting
- Update /account-limits endpoint to show model-specific limits
- Remove multi-account OAuth flow to avoid state mismatch errors

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* fix: show (x/y) limited status in account-limits table

- Status is now "ok" only when all models are available
- Shows "(x/y) limited" when x out of y models are exhausted
- Provides better visibility into partial rate limiting

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* docs: update CLAUDE.md with model-specific rate limiting

- Document modelRateLimits[modelId] for per-model rate tracking
- Add isNetworkError() helper to utilities section

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

---------

Co-authored-by: M1noa <minoa@minoa.cat>
Co-authored-by: Minoa <altgithub@minoa.cat>
Co-authored-by: Claude <noreply@anthropic.com>
2026-01-03 15:33:49 +05:30
Badri Narayanan S
2d05dd5b62 Fix: Reset invalid accounts on startup and improve project discovery logging
Fixes #33 - Accounts marked as invalid were permanently stuck because
the isInvalid flag was persisted to disk but never reset on startup.

Changes:
- Reset isInvalid flag for all accounts on server startup, giving them
  a fresh chance to refresh their OAuth tokens
- Add logging for project discovery failures (was silently failing)
- Add success logging when project is discovered
- Add warning message when falling back to default project

Bug introduced in 01cda83 (2025-12-25) when isInvalid persistence was
added without corresponding reset logic on load.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-02 12:34:35 +05:30
Badri Narayanan S
77089e0360 Fix issue where Antigravity auth is not working 2026-01-02 11:47:54 +05:30
Badri Narayanan S
8e4c4bdfd4 Fix accounts cli path 2026-01-02 00:03:43 +05:30
Badri Narayanan S
f02364d4ef refactor: Reorganize src/ into modular folder structure
Split large monolithic files into focused modules:
- cloudcode-client.js (1,107 lines) → src/cloudcode/ (9 files)
- account-manager.js (639 lines) → src/account-manager/ (5 files)
- Move auth files to src/auth/ (oauth, token-extractor, database)
- Move CLI to src/cli/accounts.js

Update all import paths and documentation.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-01 15:13:43 +05:30
Badri Narayanan S
1d91bc0d30 Improve logging, rate limiting, and error handling (#29)
* feat: apply local user changes and fixes

* ;D

* Clean up PR #28: Remove duplicate code lines and unnecessary file

- Remove pullrequest.md (PR notes file not needed in repo)
- Fix duplicate lines in account-manager.js:
  - rateLimitResetTime assignment
  - saveToDisk() calls in markRateLimited and markInvalid
  - invalidReason/invalidAt assignments
  - double return statement in discoverProject

Original PR by M2noa: fix sticky accs, 500s, logging updates, and rate limit handling

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: M2noa <226494568+M2noa@users.noreply.github.com>
Co-Authored-By: Claude <noreply@anthropic.com>

* chore: replace console.log with logger methods for consistency

- Replace all console.log calls with logger.warn/debug in:
  - src/cloudcode-client.js (4 places)
  - src/format/thinking-utils.js (7 places)

This ensures consistent logging behavior with the new logger utility,
respecting --debug mode for verbose output.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

---------

Co-authored-by: M1noa <minoa@minoa.cat>
Co-authored-by: M2noa <226494568+M2noa@users.noreply.github.com>
Co-authored-by: Claude <noreply@anthropic.com>
2026-01-01 14:35:06 +05:30
Badri Narayanan S
d05fb64e29 Fix: Add Windows support for SQLite database access (Issue #23)
Replace CLI-based sqlite3 extraction with better-sqlite3 library:
- Create shared src/db/database.js module for cross-platform SQLite access
- Remove duplicate extractTokenFromDB functions from token-extractor.js and account-manager.js
- Add better-sqlite3 dependency with prebuilt Windows/Mac/Linux binaries
- Improve error handling with specific messages for common issues

Fixes #23

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-30 18:47:05 +05:30
Badri Narayanan S
ead7632eec Fix: Read Image tool not working 2025-12-30 17:01:01 +05:30
Badri Narayanan S
1bf2362e98 chore: remove unused node-fetch dependency from lockfile
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-30 12:12:27 +05:30
Badri Narayanan S
f3f7189cba Updated readme to set hasCompletedOnboarding to true 2025-12-29 17:26:31 +05:30
Badri Narayanan S
2247df24df updated instructions to load environment variables 2025-12-29 14:46:11 +05:30
Badri Narayanan S
17e7cebef1 Merge pull request #13 from jroth1111/split/count-tokens
Add count_tokens stub
2025-12-29 14:18:26 +05:30
gwizz
306a8891c8 Add count_tokens stub endpoint 2025-12-29 10:57:47 +11:00
Badri Narayanan S
426acc494a Implement Gemini signature caching and thinking recovery
- Add in-memory signature cache to restore thoughtSignatures stripped by Claude Code
- Implement thinking recovery logic to handle interrupted tool loops for Gemini
- Enhance schema sanitizer to preserve constraints and enums as description hints
- Update CLAUDE.md with new architecture details

🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-28 14:34:03 +05:30
Badri Narayanan S
1eb2329f7c Gemini schema fix and modularize format converter 2025-12-28 03:28:05 +05:30
Badri Narayanan S
21c17d55f3 Removed standard anthropic name mapper as its unnecessary 2025-12-27 19:11:03 +05:30
Badri Narayanan S
937d23a75a Updated config details in readme 2025-12-27 16:40:43 +05:30
Badri Narayanan S
c1e1dbb0ef Added support for Gemini models 2025-12-27 14:09:20 +05:30
Badri Narayanan S
9b7dcf3a6c removing restcting of available models, fixing max tokens issues in test 2025-12-27 12:17:45 +05:30
Badri Narayanan S
f86c4f4d32 updating star history link to no cache 2025-12-26 23:23:12 +05:30
Badri Narayanan S
1dfb47325b docs: add banner image to README
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-26 20:53:54 +05:30
Badri Narayanan S
136535fd52 docs: add Buy Me a Coffee funding link
- Add .github/FUNDING.yml for GitHub Sponsor button
- Add Buy Me a Coffee badge to README

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-26 20:40:38 +05:30
Badri Narayanan S
07a09c1cb9 fallback to load antigravity default account, even if config file exists but with no accounts 2025-12-26 14:54:43 +05:30
Badri Narayanan S
1a9609054f chore: update repo URLs and title after GitHub rename 2025-12-26 01:09:11 +05:30
Badri Narayanan S
5465e91802 docs: add npm badges and rename title to Server 2025-12-26 00:39:20 +05:30
Badri Narayanan S
6504d77279 fix: auto-sync version from release tag in publish workflow 2025-12-26 00:31:15 +05:30
Badri Narayanan S
de873d5057 docs: update README with npm package installation instructions 2025-12-26 00:23:13 +05:30
Badri Narayanan S
277c28c7e3 1.0.2 2025-12-26 00:18:20 +05:30
Badri Narayanan S
e8bfc7ea04 fix: rename bin command to match package name for npx 2025-12-26 00:18:20 +05:30
Badri Narayanan S
6eca4ed792 1.0.1 2025-12-26 00:17:12 +05:30
Badri Narayanan S
5b1340d228 feat: add npm package support with CLI entry point 2025-12-26 00:17:12 +05:30
Badri Narayanan S
4d0e42471a updated correct star history link 2025-12-25 22:08:16 +05:30
Badri Narayanan S
b8677c9f6b feat: show remaining time for rate-limited accounts
Display rate limit remaining duration in Status column (e.g., "limited (1h23m45s)") instead of just "rate-limited"

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-25 22:00:48 +05:30
Badri Narayanan S
9b0b756e72 feat: consolidate /accounts into /account-limits endpoint
- Remove redundant /accounts endpoint
- Enhance /account-limits table output with account status, last used time, and quota reset time
- Filter model list to show only Claude models
- Use local time format for timestamps
- Update documentation (README.md, CLAUDE.md, index.js)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-25 21:55:03 +05:30
Badri Narayanan S
ed6bd3af2b fix oauth redirect URI not imported 2025-12-25 16:10:11 +05:30