koder 0.4.9__tar.gz → 0.4.11__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. {koder-0.4.9 → koder-0.4.11}/PKG-INFO +19 -5
  2. {koder-0.4.9 → koder-0.4.11}/README.md +18 -4
  3. {koder-0.4.9 → koder-0.4.11}/koder_agent/agentic/agent.py +41 -4
  4. {koder-0.4.9 → koder-0.4.11}/koder_agent/auth/base.py +7 -3
  5. {koder-0.4.9 → koder-0.4.11}/koder_agent/auth/cli_handler.py +96 -32
  6. {koder-0.4.9 → koder-0.4.11}/koder_agent/auth/client_integration.py +10 -20
  7. {koder-0.4.9 → koder-0.4.11}/koder_agent/auth/litellm_oauth.py +3 -3
  8. {koder-0.4.9 → koder-0.4.11}/koder_agent/auth/providers/antigravity.py +103 -25
  9. {koder-0.4.9 → koder-0.4.11}/koder_agent/auth/providers/chatgpt.py +12 -5
  10. {koder-0.4.9 → koder-0.4.11}/koder_agent/auth/providers/claude.py +10 -3
  11. {koder-0.4.9 → koder-0.4.11}/koder_agent/auth/providers/google.py +12 -5
  12. {koder-0.4.9 → koder-0.4.11}/koder_agent/auth/tool_utils.py +18 -19
  13. {koder-0.4.9 → koder-0.4.11}/koder_agent/core/commands.py +4 -4
  14. {koder-0.4.9 → koder-0.4.11}/koder_agent/core/scheduler.py +19 -30
  15. {koder-0.4.9 → koder-0.4.11}/koder_agent/utils/client.py +31 -21
  16. {koder-0.4.9 → koder-0.4.11}/pyproject.toml +16 -1
  17. koder-0.4.9/.claude/settings.local.json +0 -47
  18. koder-0.4.9/.github/dependabot.yml +0 -11
  19. koder-0.4.9/.uv-cache/.gitignore +0 -1
  20. koder-0.4.9/.uv-cache/CACHEDIR.TAG +0 -1
  21. koder-0.4.9/.uv-cache/interpreter-v4/aarch64/72afda6228b75bee.msgpack +0 -1
  22. koder-0.4.9/.uv-cache/sdists-v7/.git +0 -0
  23. koder-0.4.9/.uv-cache/sdists-v7/.gitignore +0 -0
  24. koder-0.4.9/AGENTS.md +0 -112
  25. koder-0.4.9/CLAUDE.md +0 -112
  26. koder-0.4.9/CONTRIBUTING.md +0 -165
  27. koder-0.4.9/GEMINI.md +0 -1
  28. koder-0.4.9/docs/configuration.md +0 -392
  29. koder-0.4.9/scripts/generate_codex_prompts.py +0 -161
  30. koder-0.4.9/scripts/upgrade_dependency.py +0 -105
  31. koder-0.4.9/tests/auth/__init__.py +0 -1
  32. koder-0.4.9/tests/auth/test_oauth_providers.py +0 -376
  33. koder-0.4.9/tests/auth/test_token_refresh.py +0 -299
  34. koder-0.4.9/tests/auth/test_token_storage.py +0 -201
  35. koder-0.4.9/tests/auth/test_tool_calling.py +0 -514
  36. koder-0.4.9/tests/auth/test_tool_utils.py +0 -574
  37. koder-0.4.9/tests/fixtures/skills/large-skill/SKILL.md +0 -106
  38. koder-0.4.9/tests/fixtures/skills/large-skill/reference.md +0 -24
  39. koder-0.4.9/tests/fixtures/skills/medium-skill/SKILL.md +0 -74
  40. koder-0.4.9/tests/fixtures/skills/small-skill/SKILL.md +0 -56
  41. koder-0.4.9/tests/fixtures/skills/template-skill/SKILL.md +0 -20
  42. koder-0.4.9/tests/integration/__init__.py +0 -10
  43. koder-0.4.9/tests/integration/conftest.py +0 -33
  44. koder-0.4.9/tests/integration/test_antigravity_oauth.py +0 -95
  45. koder-0.4.9/tests/integration/test_chatgpt_oauth.py +0 -87
  46. koder-0.4.9/tests/integration/test_claude_oauth.py +0 -108
  47. koder-0.4.9/tests/integration/test_google_oauth.py +0 -86
  48. koder-0.4.9/tests/test_capture_usage.py +0 -217
  49. koder-0.4.9/tests/test_file_tools.py +0 -1071
  50. koder-0.4.9/tests/test_llm_completion_responses.py +0 -65
  51. koder-0.4.9/tests/test_model_info.py +0 -142
  52. koder-0.4.9/tests/test_model_resolution.py +0 -129
  53. koder-0.4.9/tests/test_security_guard.py +0 -11
  54. koder-0.4.9/tests/test_shell_background.py +0 -378
  55. koder-0.4.9/tests/test_skill_loader.py +0 -518
  56. koder-0.4.9/tests/test_skill_restrictions.py +0 -713
  57. koder-0.4.9/tests/test_skill_token_efficiency.py +0 -241
  58. koder-0.4.9/tests/test_streaming_display.py +0 -381
  59. koder-0.4.9/tests/test_usage_tracker.py +0 -233
  60. koder-0.4.9/tests/test_web.py +0 -402
  61. koder-0.4.9/uv.lock +0 -4053
  62. {koder-0.4.9 → koder-0.4.11}/.gitignore +0 -0
  63. {koder-0.4.9 → koder-0.4.11}/LICENSE +0 -0
  64. {koder-0.4.9 → koder-0.4.11}/koder_agent/__init__.py +0 -0
  65. {koder-0.4.9 → koder-0.4.11}/koder_agent/agentic/__init__.py +0 -0
  66. {koder-0.4.9 → koder-0.4.11}/koder_agent/agentic/approval_hooks.py +0 -0
  67. {koder-0.4.9 → koder-0.4.11}/koder_agent/agentic/hooks.py +0 -0
  68. {koder-0.4.9 → koder-0.4.11}/koder_agent/agentic/skill_guardrail.py +0 -0
  69. {koder-0.4.9 → koder-0.4.11}/koder_agent/auth/__init__.py +0 -0
  70. {koder-0.4.9 → koder-0.4.11}/koder_agent/auth/callback_server.py +0 -0
  71. {koder-0.4.9 → koder-0.4.11}/koder_agent/auth/codex_prompts.py +0 -0
  72. {koder-0.4.9 → koder-0.4.11}/koder_agent/auth/constants.py +0 -0
  73. {koder-0.4.9 → koder-0.4.11}/koder_agent/auth/providers/__init__.py +0 -0
  74. {koder-0.4.9 → koder-0.4.11}/koder_agent/auth/token_storage.py +0 -0
  75. {koder-0.4.9 → koder-0.4.11}/koder_agent/cli.py +0 -0
  76. {koder-0.4.9 → koder-0.4.11}/koder_agent/config/__init__.py +0 -0
  77. {koder-0.4.9 → koder-0.4.11}/koder_agent/config/cli_handler.py +0 -0
  78. {koder-0.4.9 → koder-0.4.11}/koder_agent/config/manager.py +0 -0
  79. {koder-0.4.9 → koder-0.4.11}/koder_agent/config/models.py +0 -0
  80. {koder-0.4.9 → koder-0.4.11}/koder_agent/core/__init__.py +0 -0
  81. {koder-0.4.9 → koder-0.4.11}/koder_agent/core/interactive.py +0 -0
  82. {koder-0.4.9 → koder-0.4.11}/koder_agent/core/keyboard_listener.py +0 -0
  83. {koder-0.4.9 → koder-0.4.11}/koder_agent/core/security.py +0 -0
  84. {koder-0.4.9 → koder-0.4.11}/koder_agent/core/session.py +0 -0
  85. {koder-0.4.9 → koder-0.4.11}/koder_agent/core/status_line.py +0 -0
  86. {koder-0.4.9 → koder-0.4.11}/koder_agent/core/streaming_display.py +0 -0
  87. {koder-0.4.9 → koder-0.4.11}/koder_agent/core/usage_tracker.py +0 -0
  88. {koder-0.4.9 → koder-0.4.11}/koder_agent/mcp/__init__.py +0 -0
  89. {koder-0.4.9 → koder-0.4.11}/koder_agent/mcp/cli_handler.py +0 -0
  90. {koder-0.4.9 → koder-0.4.11}/koder_agent/mcp/server_config.py +0 -0
  91. {koder-0.4.9 → koder-0.4.11}/koder_agent/mcp/server_factory.py +0 -0
  92. {koder-0.4.9 → koder-0.4.11}/koder_agent/mcp/server_manager.py +0 -0
  93. {koder-0.4.9 → koder-0.4.11}/koder_agent/tools/__init__.py +0 -0
  94. {koder-0.4.9 → koder-0.4.11}/koder_agent/tools/engine.py +0 -0
  95. {koder-0.4.9 → koder-0.4.11}/koder_agent/tools/file.py +0 -0
  96. {koder-0.4.9 → koder-0.4.11}/koder_agent/tools/search.py +0 -0
  97. {koder-0.4.9 → koder-0.4.11}/koder_agent/tools/shell.py +0 -0
  98. {koder-0.4.9 → koder-0.4.11}/koder_agent/tools/skill.py +0 -0
  99. {koder-0.4.9 → koder-0.4.11}/koder_agent/tools/skill_context.py +0 -0
  100. {koder-0.4.9 → koder-0.4.11}/koder_agent/tools/task.py +0 -0
  101. {koder-0.4.9 → koder-0.4.11}/koder_agent/tools/todo.py +0 -0
  102. {koder-0.4.9 → koder-0.4.11}/koder_agent/tools/web.py +0 -0
  103. {koder-0.4.9 → koder-0.4.11}/koder_agent/utils/__init__.py +0 -0
  104. {koder-0.4.9 → koder-0.4.11}/koder_agent/utils/model_info.py +0 -0
  105. {koder-0.4.9 → koder-0.4.11}/koder_agent/utils/prompts.py +0 -0
  106. {koder-0.4.9 → koder-0.4.11}/koder_agent/utils/queue.py +0 -0
  107. {koder-0.4.9 → koder-0.4.11}/koder_agent/utils/sessions.py +0 -0
  108. {koder-0.4.9 → koder-0.4.11}/koder_agent/utils/terminal_theme.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: koder
3
- Version: 0.4.9
3
+ Version: 0.4.11
4
4
  Summary: An intuitive AI coding assistant and interactive CLI tool that boosts developer productivity with intelligent automation and context-aware support.
5
5
  Project-URL: Homepage, https://github.com/feiskyer/koder
6
6
  Project-URL: Repository, https://github.com/feiskyer/koder
@@ -74,14 +74,14 @@ pip install koder
74
74
  ## Quick Start
75
75
 
76
76
  ```bash
77
- # 1. Set your API key
78
- export OPENAI_API_KEY="your-api-key"
77
+ # 1. Set your API key (works with any provider)
78
+ export KODER_API_KEY="your-api-key"
79
79
 
80
80
  # 2. Run Koder
81
81
  koder
82
82
  ```
83
83
 
84
- That's it! Koder auto-detects your provider from the API key.
84
+ That's it! `KODER_API_KEY` works with any provider - no need to remember provider-specific variable names.
85
85
 
86
86
  ### Basic Usage
87
87
 
@@ -104,13 +104,27 @@ KODER_MODEL="claude-opus-4-20250514" koder "your prompt"
104
104
  Koder can be configured via (in priority order):
105
105
 
106
106
  1. **CLI arguments** - Highest priority
107
- 2. **Environment variables** - `KODER_MODEL`, `KODER_REASONING_EFFORT`
107
+ 2. **Environment variables** - Universal `KODER_*` vars override everything
108
108
  3. **Config file** - `~/.koder/config.yaml`
109
109
 
110
+ ### Environment Variables
111
+
112
+ | Variable | Description | Example |
113
+ |----------|-------------|---------|
114
+ | `KODER_API_KEY` | Universal API key (works with any provider) | `sk-...` |
115
+ | `KODER_MODEL` | Model to use | `gpt-4o`, `claude-opus-4-20250514` |
116
+ | `KODER_BASE_URL` | Custom API endpoint | `http://localhost:8080/v1` |
117
+ | `KODER_REASONING_EFFORT` | For reasoning models | `low`, `medium`, `high` |
118
+
119
+ `KODER_API_KEY` and `KODER_BASE_URL` take priority over provider-specific variables (like `OPENAI_API_KEY`) and config file settings.
120
+
110
121
  ### Providers
111
122
 
123
+ Use `KODER_API_KEY` for any provider, or provider-specific variables:
124
+
112
125
  | Provider | Environment Variable | Model Example |
113
126
  |----------|---------------------|---------------|
127
+ | Any | `KODER_API_KEY` | Works with all providers |
114
128
  | OpenAI | `OPENAI_API_KEY` | `gpt-4o`, `gpt-4.1` |
115
129
  | Anthropic | `ANTHROPIC_API_KEY` | `claude-opus-4-20250514` |
116
130
  | Google | `GOOGLE_API_KEY` | `gemini/gemini-2.5-pro` |
@@ -36,14 +36,14 @@ pip install koder
36
36
  ## Quick Start
37
37
 
38
38
  ```bash
39
- # 1. Set your API key
40
- export OPENAI_API_KEY="your-api-key"
39
+ # 1. Set your API key (works with any provider)
40
+ export KODER_API_KEY="your-api-key"
41
41
 
42
42
  # 2. Run Koder
43
43
  koder
44
44
  ```
45
45
 
46
- That's it! Koder auto-detects your provider from the API key.
46
+ That's it! `KODER_API_KEY` works with any provider - no need to remember provider-specific variable names.
47
47
 
48
48
  ### Basic Usage
49
49
 
@@ -66,13 +66,27 @@ KODER_MODEL="claude-opus-4-20250514" koder "your prompt"
66
66
  Koder can be configured via (in priority order):
67
67
 
68
68
  1. **CLI arguments** - Highest priority
69
- 2. **Environment variables** - `KODER_MODEL`, `KODER_REASONING_EFFORT`
69
+ 2. **Environment variables** - Universal `KODER_*` vars override everything
70
70
  3. **Config file** - `~/.koder/config.yaml`
71
71
 
72
+ ### Environment Variables
73
+
74
+ | Variable | Description | Example |
75
+ |----------|-------------|---------|
76
+ | `KODER_API_KEY` | Universal API key (works with any provider) | `sk-...` |
77
+ | `KODER_MODEL` | Model to use | `gpt-4o`, `claude-opus-4-20250514` |
78
+ | `KODER_BASE_URL` | Custom API endpoint | `http://localhost:8080/v1` |
79
+ | `KODER_REASONING_EFFORT` | For reasoning models | `low`, `medium`, `high` |
80
+
81
+ `KODER_API_KEY` and `KODER_BASE_URL` take priority over provider-specific variables (like `OPENAI_API_KEY`) and config file settings.
82
+
72
83
  ### Providers
73
84
 
85
+ Use `KODER_API_KEY` for any provider, or provider-specific variables:
86
+
74
87
  | Provider | Environment Variable | Model Example |
75
88
  |----------|---------------------|---------------|
89
+ | Any | `KODER_API_KEY` | Works with all providers |
76
90
  | OpenAI | `OPENAI_API_KEY` | `gpt-4o`, `gpt-4.1` |
77
91
  | Anthropic | `ANTHROPIC_API_KEY` | `claude-opus-4-20250514` |
78
92
  | Google | `GOOGLE_API_KEY` | `gemini/gemini-2.5-pro` |
@@ -19,6 +19,7 @@ from openai._models import construct_type
19
19
  from openai.types.shared import Reasoning
20
20
  from rich.console import Console
21
21
 
22
+ from ..auth.tool_utils import clean_json_schema
22
23
  from ..config import get_config
23
24
  from ..mcp import load_mcp_servers
24
25
  from ..tools.skill import SkillLoader
@@ -42,6 +43,36 @@ class RetryingLitellmModel(LitellmModel):
42
43
  getattr(_EXC, "InternalServerError", Exception),
43
44
  )
44
45
 
46
+ def _is_github_copilot(self) -> bool:
47
+ """Check if the current model is using GitHub Copilot."""
48
+ return "github_copilot" in str(self.model).lower()
49
+
50
+ def _clean_tools_for_github_copilot(self, tools: list) -> list:
51
+ """Clean tool schemas for GitHub Copilot compatibility.
52
+
53
+ GitHub Copilot doesn't support $ref/$defs in JSON schemas.
54
+ """
55
+ if not tools or not self._is_github_copilot():
56
+ return tools
57
+
58
+ for tool in tools:
59
+ if not hasattr(tool, "params_json_schema"):
60
+ continue
61
+
62
+ try:
63
+ tool.params_json_schema = clean_json_schema(tool.params_json_schema)
64
+ if hasattr(tool, "strict_json_schema"):
65
+ tool.strict_json_schema = False
66
+
67
+ except Exception as exc:
68
+ logger.debug(
69
+ "Failed to clean tool schema for %s: %s",
70
+ getattr(tool, "name", "unknown"),
71
+ exc,
72
+ )
73
+
74
+ return tools
75
+
45
76
  def _should_use_responses_api(self) -> bool:
46
77
  """
47
78
  GitHub Copilot Codex models are not accessible via /chat/completions.
@@ -158,12 +189,15 @@ class RetryingLitellmModel(LitellmModel):
158
189
  conversation_id: str | None = None, # unused for LiteLLM responses
159
190
  prompt: Any | None = None,
160
191
  ) -> ModelResponse:
192
+ # Clean tools for GitHub Copilot compatibility
193
+ cleaned_tools = self._clean_tools_for_github_copilot(tools)
194
+
161
195
  if not self._should_use_responses_api():
162
196
  return await super().get_response(
163
197
  system_instructions,
164
198
  input,
165
199
  model_settings,
166
- tools,
200
+ cleaned_tools,
167
201
  output_schema,
168
202
  handoffs,
169
203
  tracing,
@@ -182,7 +216,7 @@ class RetryingLitellmModel(LitellmModel):
182
216
  system_instructions,
183
217
  input,
184
218
  model_settings,
185
- tools,
219
+ cleaned_tools,
186
220
  output_schema,
187
221
  handoffs,
188
222
  previous_response_id=previous_response_id,
@@ -239,12 +273,15 @@ class RetryingLitellmModel(LitellmModel):
239
273
  conversation_id: str | None = None, # unused for LiteLLM responses
240
274
  prompt: Any | None = None,
241
275
  ):
276
+ # Clean tools for GitHub Copilot compatibility
277
+ cleaned_tools = self._clean_tools_for_github_copilot(tools)
278
+
242
279
  if not self._should_use_responses_api():
243
280
  async for chunk in super().stream_response(
244
281
  system_instructions,
245
282
  input,
246
283
  model_settings,
247
- tools,
284
+ cleaned_tools,
248
285
  output_schema,
249
286
  handoffs,
250
287
  tracing,
@@ -265,7 +302,7 @@ class RetryingLitellmModel(LitellmModel):
265
302
  system_instructions,
266
303
  input,
267
304
  model_settings,
268
- tools,
305
+ cleaned_tools,
269
306
  output_schema,
270
307
  handoffs,
271
308
  previous_response_id=previous_response_id,
@@ -315,15 +315,19 @@ class OAuthProvider(ABC):
315
315
  """
316
316
  return {"Authorization": f"Bearer {access_token}"}
317
317
 
318
- async def list_models(self, access_token: str) -> list[str]:
318
+ async def list_models(self, access_token: str, verbose: bool = False) -> tuple[list[str], dict]:
319
319
  """List available models for this provider.
320
320
 
321
321
  Override in subclasses to call provider's models API.
322
322
 
323
323
  Args:
324
324
  access_token: Valid access token
325
+ verbose: If True, return detailed status info
325
326
 
326
327
  Returns:
327
- List of model names with provider prefix (e.g., "google/gemini-2.5-pro")
328
+ Tuple of (model list, status dict with 'source' and optional 'error')
329
+ - source: "api", "fallback", or "hardcoded"
330
+ - error: Error message if API call failed (None otherwise)
331
+ - reason: Optional explanation (e.g., "No public API available")
328
332
  """
329
- return []
333
+ return [], {"source": "hardcoded", "error": None}
@@ -88,7 +88,7 @@ async def handle_login(provider_id: str, timeout: float = 300) -> bool:
88
88
 
89
89
  # Fetch available models from provider API
90
90
  console.print("Fetching available models...")
91
- models = await provider.list_models(tokens.access_token)
91
+ models, _ = await provider.list_models(tokens.access_token)
92
92
  tokens.models = models
93
93
  tokens.models_fetched_at = int(time.time() * 1000)
94
94
 
@@ -184,12 +184,12 @@ async def _handle_manual_code_flow(auth_url: str, timeout: float) -> "CallbackRe
184
184
  )
185
185
 
186
186
 
187
- def handle_list() -> None:
188
- """List all configured OAuth providers with their cached models."""
187
+ async def handle_list() -> None:
188
+ """List all configured OAuth providers with their models."""
189
189
  storage = get_token_storage()
190
- tokens = storage.get_all_tokens()
190
+ all_tokens = storage.get_all_tokens()
191
191
 
192
- if not tokens:
192
+ if not all_tokens:
193
193
  console.print(
194
194
  "\n[yellow]No OAuth providers configured.[/yellow]\n"
195
195
  "Use 'koder auth login <provider>' to authenticate.\n"
@@ -197,23 +197,54 @@ def handle_list() -> None:
197
197
  )
198
198
  return
199
199
 
200
- for provider_id, token in tokens.items():
201
- # Build info panel
200
+ for provider_id, tokens in all_tokens.items():
202
201
  description = PROVIDER_DESCRIPTIONS.get(provider_id, "")
203
- info = (
204
- f"[bold]Account:[/bold] {token.email or 'Unknown'}\n[bold]Type:[/bold] {description}\n"
205
- )
206
-
207
- # Show cached models
208
- if token.models:
209
- cache_valid = token.is_models_cache_valid()
210
- cache_status = "[green]cached[/green]" if cache_valid else "[yellow]stale[/yellow]"
211
- info += f"\n[bold]Models ({len(token.models)}):[/bold] {cache_status}\n"
212
- # Show all models in a wrapped format
213
- for model in token.models:
202
+ # Claude doesn't provide user info via OAuth
203
+ account = tokens.email if tokens.email else None
204
+ if account:
205
+ info = f"[bold]Account:[/bold] {account}\n[bold]Type:[/bold] {description}\n"
206
+ else:
207
+ info = f"[bold]Type:[/bold] {description}\n"
208
+
209
+ # Auto-refresh token if expired
210
+ access_token = tokens.access_token
211
+ if tokens.is_expired():
212
+ console.print(f"[dim]Refreshing {provider_id} token...[/dim]")
213
+ try:
214
+ provider = get_provider(provider_id)
215
+ result = await provider.refresh_tokens(tokens.refresh_token)
216
+ if result.success and result.tokens:
217
+ storage.save(result.tokens)
218
+ tokens = result.tokens
219
+ access_token = tokens.access_token
220
+ except Exception as e:
221
+ info += f"\n[red]Token refresh failed: {e}[/red]\n"
222
+
223
+ # Fetch models from API if cache is stale or empty
224
+ models = tokens.models
225
+ source = "cached"
226
+
227
+ if not tokens.is_models_cache_valid() or not models:
228
+ try:
229
+ provider = get_provider(provider_id)
230
+ models, status = await provider.list_models(access_token)
231
+ source = status.get("source", "api")
232
+
233
+ # Update cache
234
+ tokens.models = models
235
+ tokens.models_fetched_at = int(time.time() * 1000)
236
+ storage.save(tokens)
237
+ except Exception:
238
+ source = "cached" if models else "unavailable"
239
+
240
+ # Display models
241
+ if models:
242
+ source_label = "[green]API[/green]" if source == "api" else "[cyan]cached[/cyan]"
243
+ info += f"\n[bold]Models ({len(models)}):[/bold] {source_label}\n"
244
+ for model in sorted(models):
214
245
  info += f" • {model}\n"
215
246
  else:
216
- info += "\n[dim]No models cached (re-login to fetch)[/dim]\n"
247
+ info += "\n[dim]No models available[/dim]\n"
217
248
 
218
249
  console.print(
219
250
  Panel(
@@ -258,7 +289,7 @@ async def handle_revoke(provider_id: str) -> bool:
258
289
  return True
259
290
 
260
291
 
261
- def handle_status(provider_id: Optional[str] = None) -> None:
292
+ async def handle_status(provider_id: Optional[str] = None) -> None:
262
293
  """Show OAuth token status.
263
294
 
264
295
  Args:
@@ -273,7 +304,7 @@ def handle_status(provider_id: Optional[str] = None) -> None:
273
304
  console.print(f"[yellow]No tokens found for provider '{provider_id}'[/yellow]")
274
305
  return
275
306
 
276
- _print_token_details(provider_id, tokens)
307
+ await _print_token_details(provider_id, tokens, storage)
277
308
  else:
278
309
  # Show all providers
279
310
  all_tokens = storage.get_all_tokens()
@@ -282,12 +313,26 @@ def handle_status(provider_id: Optional[str] = None) -> None:
282
313
  return
283
314
 
284
315
  for pid, tokens in all_tokens.items():
285
- _print_token_details(pid, tokens)
316
+ await _print_token_details(pid, tokens, storage)
286
317
  console.print()
287
318
 
288
319
 
289
- def _print_token_details(provider_id: str, tokens) -> None:
290
- """Print detailed token information."""
320
+ async def _print_token_details(provider_id: str, tokens, storage) -> None:
321
+ """Print detailed token information with models."""
322
+ # Auto-refresh token if expired
323
+ access_token = tokens.access_token
324
+ if tokens.is_expired():
325
+ console.print(f"[dim]Refreshing {provider_id} token...[/dim]")
326
+ try:
327
+ provider = get_provider(provider_id)
328
+ result = await provider.refresh_tokens(tokens.refresh_token)
329
+ if result.success and result.tokens:
330
+ storage.save(result.tokens)
331
+ tokens = result.tokens
332
+ access_token = tokens.access_token
333
+ except Exception:
334
+ pass
335
+
291
336
  # Determine status
292
337
  if tokens.is_expired(0):
293
338
  status = "[red]EXPIRED[/red]"
@@ -304,24 +349,43 @@ def _print_token_details(provider_id: str, tokens) -> None:
304
349
  expires = datetime.fromtimestamp(tokens.expires_at / 1000)
305
350
 
306
351
  # Build detailed info
352
+ account_line = f"Account: {tokens.email}\n" if tokens.email else ""
307
353
  info = (
308
354
  f"Status: {status}\n"
309
- f"Account: {tokens.email or 'Unknown'}\n"
355
+ f"{account_line}"
310
356
  f"Expires: {expires.strftime('%Y-%m-%d %H:%M:%S')}\n"
311
357
  f"Time left: {time_left_mins} minutes\n"
312
358
  f"Access token: {tokens.access_token[:20]}...\n"
313
359
  f"Refresh token: {tokens.refresh_token[:20]}..."
314
360
  )
315
361
 
362
+ # Fetch models from API if cache is stale or empty
363
+ models = tokens.models
364
+ source = "cached"
365
+
366
+ if not tokens.is_models_cache_valid() or not models:
367
+ try:
368
+ provider = get_provider(provider_id)
369
+ models, status_info = await provider.list_models(access_token)
370
+ source = "api" if status_info.get("source") == "api" else "cached"
371
+
372
+ # Update cache
373
+ tokens.models = models
374
+ tokens.models_fetched_at = int(time.time() * 1000)
375
+ storage.save(tokens)
376
+ except Exception:
377
+ pass
378
+
316
379
  # Add models info
317
- if tokens.models:
318
- cache_valid = tokens.is_models_cache_valid()
319
- cache_status = "valid" if cache_valid else "stale (re-login to refresh)"
320
- info += f"\n\nCached models ({len(tokens.models)}): {cache_status}"
380
+ if models:
381
+ source_label = "[green]API[/green]" if source == "api" else "[cyan]cached[/cyan]"
382
+ info += f"\n\n[bold]Models ({len(models)}):[/bold] {source_label}\n"
383
+ for model in sorted(models):
384
+ info += f" • {model}\n"
321
385
 
322
386
  console.print(
323
387
  Panel(
324
- info,
388
+ info.strip(),
325
389
  title=f"[bold]{provider_id}[/bold]",
326
390
  border_style="blue",
327
391
  )
@@ -369,7 +433,7 @@ async def run_auth_command(args) -> int:
369
433
  return 0 if success else 1
370
434
 
371
435
  elif args.auth_command == "list":
372
- handle_list()
436
+ await handle_list()
373
437
  return 0
374
438
 
375
439
  elif args.auth_command == "revoke":
@@ -377,7 +441,7 @@ async def run_auth_command(args) -> int:
377
441
  return 0 if success else 1
378
442
 
379
443
  elif args.auth_command == "status":
380
- handle_status(getattr(args, "provider", None))
444
+ await handle_status(getattr(args, "provider", None))
381
445
  return 0
382
446
 
383
447
  else:
@@ -216,27 +216,17 @@ def get_provider_auth_info(provider: str) -> Tuple[Optional[str], Optional[Dict[
216
216
  def map_provider_to_oauth(model_provider: str) -> Optional[str]:
217
217
  """Map a model provider name to OAuth provider name.
218
218
 
219
+ Only OAuth providers (google, claude, chatgpt, antigravity) return themselves.
220
+ API-based providers (anthropic, openai, gemini, azure, etc.) return None.
221
+
219
222
  Args:
220
- model_provider: Provider name from model config (e.g., "google", "anthropic")
223
+ model_provider: Provider name from model config
221
224
 
222
225
  Returns:
223
- OAuth provider name or None if no mapping exists
224
-
225
- Note:
226
- OAuth providers use different names than API key providers:
227
- - google (OAuth) vs gemini (API key)
228
- - claude (OAuth) vs anthropic (API key)
229
- - chatgpt (OAuth) vs openai (API key)
226
+ OAuth provider name or None if not an OAuth provider
230
227
  """
231
- # Map model providers to OAuth provider names
232
- provider_map = {
233
- "google": "google",
234
- "gemini": "google",
235
- "anthropic": "claude",
236
- "claude": "claude",
237
- "openai": "chatgpt",
238
- "chatgpt": "chatgpt",
239
- "antigravity": "antigravity",
240
- }
241
-
242
- return provider_map.get(model_provider.lower())
228
+ if not model_provider:
229
+ return None
230
+ oauth_providers = {"google", "claude", "chatgpt", "antigravity"}
231
+ provider = model_provider.strip().lower()
232
+ return provider if provider in oauth_providers else None
@@ -19,10 +19,10 @@ from litellm import CustomLLM
19
19
  from litellm.types.utils import GenericStreamingChunk, ModelResponse, Usage
20
20
 
21
21
  from koder_agent.auth.client_integration import get_oauth_token
22
+ from koder_agent.auth.codex_prompts import CODEX_PROMPTS
22
23
  from koder_agent.auth.constants import (
23
24
  ANTHROPIC_BETA_HEADERS,
24
25
  )
25
- from koder_agent.auth.codex_prompts import CODEX_PROMPTS
26
26
 
27
27
  logger = logging.getLogger(__name__)
28
28
 
@@ -704,7 +704,7 @@ class ClaudeOAuthLLM(CustomLLM):
704
704
  **kwargs: Any,
705
705
  ) -> Dict[str, Any]:
706
706
  """Build Anthropic API request body."""
707
- from .tool_utils import clean_json_schema_for_antigravity, ensure_tool_has_properties
707
+ from .tool_utils import clean_json_schema, ensure_tool_has_properties
708
708
 
709
709
  # Extract system messages and build anthropic messages
710
710
  system_parts = []
@@ -853,7 +853,7 @@ class ClaudeOAuthLLM(CustomLLM):
853
853
  else:
854
854
  continue
855
855
  # Clean schema for Claude
856
- cleaned_params = clean_json_schema_for_antigravity(params)
856
+ cleaned_params = clean_json_schema(params)
857
857
  cleaned_params = ensure_tool_has_properties(cleaned_params)
858
858
  anthropic_tools.append(
859
859
  {
@@ -24,6 +24,13 @@ from koder_agent.auth.constants import (
24
24
  GOOGLE_USERINFO_URL,
25
25
  )
26
26
 
27
+ # Antigravity internal API endpoints
28
+ CLOUD_CODE_BASE_URL = "https://cloudcode-pa.googleapis.com"
29
+ LOAD_CODE_ASSIST_URL = f"{CLOUD_CODE_BASE_URL}/v1internal:loadCodeAssist"
30
+ FETCH_MODELS_URL = f"{CLOUD_CODE_BASE_URL}/v1internal:fetchAvailableModels"
31
+ ANTIGRAVITY_USER_AGENT = "antigravity/1.11.3 Darwin/arm64"
32
+ DEFAULT_PROJECT_ID = "bamboo-precept-lgxtn"
33
+
27
34
 
28
35
  class AntigravityOAuthProvider(OAuthProvider):
29
36
  """Antigravity OAuth provider for Gemini 3 + Claude access.
@@ -185,35 +192,106 @@ class AntigravityOAuthProvider(OAuthProvider):
185
192
  """
186
193
  return ANTIGRAVITY_API_BASE
187
194
 
188
- async def list_models(self, access_token: str) -> list[str]:
189
- """List available Antigravity models.
195
+ async def _fetch_project_id(self, access_token: str) -> tuple[Optional[str], Optional[str]]:
196
+ """Fetch project ID and subscription tier from loadCodeAssist API."""
197
+ try:
198
+ async with aiohttp.ClientSession() as session:
199
+ async with session.post(
200
+ LOAD_CODE_ASSIST_URL,
201
+ headers={
202
+ "Authorization": f"Bearer {access_token}",
203
+ "Content-Type": "application/json",
204
+ "User-Agent": ANTIGRAVITY_USER_AGENT,
205
+ },
206
+ json={"metadata": {"ideType": "ANTIGRAVITY"}},
207
+ ) as response:
208
+ if response.ok:
209
+ data = await response.json()
210
+ project_id = data.get("cloudaicompanionProject")
211
+ paid_tier = data.get("paidTier", {})
212
+ current_tier = data.get("currentTier", {})
213
+ tier_id = paid_tier.get("id") or current_tier.get("id")
214
+ return project_id, tier_id
215
+ except Exception:
216
+ pass
217
+ return None, None
190
218
 
191
- Note: Antigravity provides access to Gemini 3 + Claude models
192
- through Google OAuth. Model availability depends on quota.
219
+ async def _fetch_available_models(
220
+ self, access_token: str, project_id: str
221
+ ) -> tuple[list[str], dict]:
222
+ """Fetch available models from fetchAvailableModels API."""
223
+ models = []
224
+ status = {"source": "api", "error": None, "project_id": project_id}
225
+
226
+ try:
227
+ async with aiohttp.ClientSession() as session:
228
+ async with session.post(
229
+ FETCH_MODELS_URL,
230
+ headers={
231
+ "Authorization": f"Bearer {access_token}",
232
+ "Content-Type": "application/json",
233
+ "User-Agent": ANTIGRAVITY_USER_AGENT,
234
+ },
235
+ json={"project": project_id},
236
+ ) as response:
237
+ if response.ok:
238
+ data = await response.json()
239
+ models_data = data.get("models", {})
240
+
241
+ for model_name, model_info in models_data.items():
242
+ # Skip internal models
243
+ if model_info.get("isInternal"):
244
+ continue
245
+ # Only include models with quota info
246
+ if model_info.get("quotaInfo"):
247
+ models.append(f"{self.provider_id}/{model_name}")
248
+
249
+ status["model_count"] = len(models_data)
250
+ status["filtered_count"] = len(models)
251
+ else:
252
+ error_text = await response.text()
253
+ status["error"] = f"API returned {response.status}: {error_text[:200]}"
254
+ status["source"] = "fallback"
255
+ except Exception as e:
256
+ status["error"] = f"API request failed: {str(e)}"
257
+ status["source"] = "fallback"
258
+
259
+ return models, status
260
+
261
+ async def list_models(self, access_token: str, verbose: bool = False) -> tuple[list[str], dict]:
262
+ """List available Antigravity models from live API.
193
263
 
194
264
  Args:
195
265
  access_token: Valid Antigravity OAuth access token
266
+ verbose: If True, return detailed status info
196
267
 
197
268
  Returns:
198
- List of model names with antigravity/ prefix
269
+ Tuple of (model list, status dict with 'source' info)
199
270
  """
200
- # Antigravity models based on the reference implementation
201
- return [
202
- # Gemini 3 models (Antigravity quota)
203
- f"{self.provider_id}/antigravity-gemini-3-flash",
204
- f"{self.provider_id}/antigravity-gemini-3-pro-low",
205
- f"{self.provider_id}/antigravity-gemini-3-pro-high",
206
- # Claude models (Antigravity quota)
207
- f"{self.provider_id}/antigravity-claude-sonnet-4-5",
208
- f"{self.provider_id}/antigravity-claude-sonnet-4-5-thinking-low",
209
- f"{self.provider_id}/antigravity-claude-sonnet-4-5-thinking-medium",
210
- f"{self.provider_id}/antigravity-claude-sonnet-4-5-thinking-high",
211
- f"{self.provider_id}/antigravity-claude-opus-4-5-thinking-low",
212
- f"{self.provider_id}/antigravity-claude-opus-4-5-thinking-medium",
213
- f"{self.provider_id}/antigravity-claude-opus-4-5-thinking-high",
214
- # Gemini CLI quota fallback models
215
- f"{self.provider_id}/gemini-2.5-flash",
216
- f"{self.provider_id}/gemini-2.5-pro",
217
- f"{self.provider_id}/gemini-3-flash-preview",
218
- f"{self.provider_id}/gemini-3-pro-preview",
219
- ]
271
+ # Fetch project ID first
272
+ project_id, tier_id = await self._fetch_project_id(access_token)
273
+ project_id = project_id or DEFAULT_PROJECT_ID
274
+
275
+ # Fetch models from API
276
+ models, status = await self._fetch_available_models(access_token, project_id)
277
+
278
+ if tier_id:
279
+ status["subscription_tier"] = tier_id
280
+
281
+ # Fallback to hardcoded list if API fails
282
+ if not models:
283
+ status["source"] = "fallback"
284
+ if not status.get("error"):
285
+ status["error"] = "API returned no models"
286
+ models = [
287
+ f"{self.provider_id}/gemini-3-flash",
288
+ f"{self.provider_id}/gemini-3-pro-low",
289
+ f"{self.provider_id}/gemini-3-pro-high",
290
+ f"{self.provider_id}/claude-sonnet-4-5",
291
+ f"{self.provider_id}/claude-sonnet-4-5-thinking",
292
+ f"{self.provider_id}/claude-opus-4-5-thinking",
293
+ f"{self.provider_id}/gemini-2.5-flash",
294
+ f"{self.provider_id}/gemini-2.5-pro",
295
+ ]
296
+
297
+ return models, status