ductor icon indicating copy to clipboard operation
ductor copied to clipboard

[Bug]: gemini not know where find new model

Open attid opened this issue 7 months ago • 3 comments

What happened?

show only gemini 2.5

Steps to Reproduce

send start show gemini 2.5

Expected Behavior

show gemini-3-pro-preview

Operating System

Linux

Environment

Docker

Which LLM provider?

Gemini

ductor version

0.7

/diagnose output


Relevant log output


LLM self-diagnosis (optional)

No response

Additional context

FIX -

● Update(ductor_bot/cli/gemini_utils.py)
⎿  Added 12 lines, removed 2 lines
71 def discover_gemini_models() -> frozenset[str]:
72 """Discover Gemini models from the installed Gemini CLI config files.
73
74 - The canonical source is gemini-cli-core/dist/src/config/models.js,
75 - generated from upstream models.ts in the Gemini CLI project.
74 + Two layouts are supported:
75 +
76 + 1. Older releases ship gemini-cli-core/dist/src/config/models.js as
77 + a separate ESM module that re-exports VALID_GEMINI_MODELS.
78 + 2. @google/gemini-cli ≥ 0.37 ships everything as a pre-bundled 79 + bundle/*.js set; the model list lives inside one of the hashed
80 + chunks as VALID_GEMINI_MODELS = new Set([...]) referencing
81 + const identifiers defined in the same file.
82 """
83 for models_js in _gemini_models_js_candidates():
84 models = _discover_models_from_models_js(models_js)
85 if models:
86 return models
87 + for bundle_js in _gemini_bundle_candidates():
88 + models = _discover_models_from_bundle(bundle_js) 89 + if models: 90 + return models 91 return frozenset() 92

● Update(ductor_bot/cli/gemini_utils.py) ⎿  Added 107 lines
366 return set(pattern.findall(content)) 367
368
369 +# Matches VALID_GEMINI_MODELS = new Set([...]), tolerating an optional
370 +# /* @__PURE__ */ annotation inserted by esbuild.
371 +_VALID_GEMINI_SET_RE = re.compile(
372 + r"VALID_GEMINI_MODELS\s*=\s*(?:/*[^]*/\s*)?new\s+Set\s*(\s*[(.?)]\s)", 373 + re.DOTALL, 374 +) 375 +UPPER_IDENT_RE = re.compile(r"\b([A-Z][A-Z0-9])\b") 376 + 377 + 378 +def _extract_models_from_valid_set(content: str) -> set[str]: 379 + """Resolve identifiers listed inside VALID_GEMINI_MODELS = new Set([...]). 380 + 381 + Each identifier is looked up in content via 382 + IDENT = "gemini-..." (with or without const/var). 383 + Identifiers that cannot be resolved are silently skipped. 384 + """ 385 + set_block = _VALID_GEMINI_SET_RE.search(content) 386 + if not set_block: 387 + return set() 388 + idents = _UPPER_IDENT_RE.findall(set_block.group(1)) 389 + if not idents: 390 + return set() 391 + 392 + found: set[str] = set() 393 + for ident in dict.fromkeys(idents): 394 + ident_re = re.compile( 395 + r"\b" + re.escape(ident) + r"""\s=\s*'"['"]""" 396 + ) 397 + match = ident_re.search(content) 398 + if match: 399 + found.add(match.group(1)) 400 + return found 401 + 402 + 403 +def _gemini_bundle_candidates() -> tuple[Path, ...]: 404 + """Return bundle/*.js files of an installed @google/gemini-cli. 405 + 406 + Newer releases ship the model list inside one of the hashed chunks 407 + instead of a stable models.js location. 408 + """ 409 + candidates: list[Path] = [] 410 + for bundle_root in _gemini_bundle_roots(): 411 + try: 412 + for path in sorted(bundle_root.glob("*.js")): 413 + if path.is_file(): 414 + candidates.append(path) 415 + except OSError: 416 + continue 417 + 418 + seen: set[Path] = set() 419 + deduped: list[Path] = [] 420 + for path in candidates: 421 + if path in seen: 422 + continue 423 + seen.add(path) 424 + deduped.append(path) 425 + return tuple(deduped) 426 + 427 + 428 +def _gemini_bundle_roots() -> list[Path]: 429 + roots: list[Path] = [] 430 + 431 + npm_root = _npm_global_root() 432 + if npm_root is not None: 433 + roots.append(npm_root / "@google" / "gemini-cli" / "bundle") 434 + 435 + try: 436 + cli_path = Path(find_gemini_cli()).resolve() 437 + except (FileNotFoundError, OSError): 438 + cli_path = None 439 + 440 + if cli_path is not None: 441 + pkg_root = _find_gemini_cli_package_root(cli_path) 442 + if pkg_root is not None: 443 + roots.append(pkg_root / "bundle") 444 + 445 + node_version_dir = cli_path.parent.parent 446 + roots.append( 447 + node_version_dir 448 + / "lib" 449 + / "node_modules" 450 + / "@google" 451 + / "gemini-cli" 452 + / "bundle" 453 + ) 454 + roots.append(cli_path.parent / "node_modules" / "@google" / "gemini-cli" / "bundle") 455 + 456 + seen: set[Path] = set() 457 + deduped: list[Path] = [] 458 + for root in roots: 459 + if root in seen: 460 + continue 461 + seen.add(root) 462 + deduped.append(root) 463 + return deduped 464 + 465 + 466 +def _discover_models_from_bundle(bundle_js: Path) -> frozenset[str]: 467 + try: 468 + content = bundle_js.read_text(encoding="utf-8", errors="replace") 469 + except OSError: 470 + return frozenset() 471 + if "VALID_GEMINI_MODELS" not in content: 472 + return frozenset() 473 + return frozenset(sorted(_extract_models_from_valid_set(content))) 474 + 475 + 476 def _extract_models_from_source_map(models_js: Path) -> set[str]: 477 source_map = models_js.with_suffix(".js.map") 478 if not source_map.is_file():

● Update(tests/cli/test_gemini_utils.py) ⎿  Added 45 lines
186 result = discover_gemini_models() 187 assert result == frozenset()
188
189 + def test_from_prebundled_chunk(self, tmp_path: Path) -> None:
190 + """Newer @google/gemini-cli ships a bundle/.js chunk instead of models.js."""
191 + bundle_dir = tmp_path / "@google" / "gemini-cli" / "bundle"
192 + bundle_dir.mkdir(parents=True)
193
194 + # Mimic the real chunk layout from @google/gemini-cli 0.37.x: 195 + # const-style identifiers defined first, then a Set referencing them. 196 + chunk = bundle_dir / "chunk-ABC123.js" 197 + chunk.write_text( 198 + 'var DEFAULT_GEMINI_MODEL = "gemini-2.5-pro";\n' 199 + 'var DEFAULT_GEMINI_FLASH_MODEL = "gemini-2.5-flash";\n' 200 + 'var DEFAULT_GEMINI_FLASH_LITE_MODEL = "gemini-2.5-flash-lite";\n' 201 + 'var PREVIEW_GEMINI_MODEL = "gemini-3-pro-preview";\n' 202 + 'var PREVIEW_GEMINI_FLASH_MODEL = "gemini-3-flash-preview";\n' 203 + "var VALID_GEMINI_MODELS = /
@PURE */ new Set([\n" 204 + " PREVIEW_GEMINI_MODEL,\n" 205 + " PREVIEW_GEMINI_FLASH_MODEL,\n" 206 + " DEFAULT_GEMINI_MODEL,\n" 207 + " DEFAULT_GEMINI_FLASH_MODEL,\n" 208 + " DEFAULT_GEMINI_FLASH_LITE_MODEL\n" 209 + "]);\n" 210 + 'var DEFAULT_GEMINI_MODEL_AUTO = "auto-gemini-2.5";\n' # not in Set 211 + 'var IRRELEVANT = "gemini-1.0-legacy";\n' # not referenced 212 + ) 213 + # Distractor file in the same bundle dir without the marker. 214 + (bundle_dir / "chunk-OTHER.js").write_text("// nothing relevant here\n") 215 + 216 + with ( 217 + patch("ductor_bot.cli.gemini_utils.which", return_value="/usr/bin/npm"), 218 + patch( 219 + "ductor_bot.cli.gemini_utils.subprocess.check_output", 220 + return_value=str(tmp_path), 221 + ), 222 + ): 223 + result = discover_gemini_models() 224 + 225 + assert "gemini-2.5-pro" in result 226 + assert "gemini-2.5-flash" in result 227 + assert "gemini-2.5-flash-lite" in result 228 + assert "gemini-3-pro-preview" in result 229 + assert "gemini-3-flash-preview" in result 230 + # Strings outside the Set are intentionally excluded. 231 + assert "auto-gemini-2.5" not in result 232 + assert "gemini-1.0-legacy" not in result 233 + 234 + 235 class TestTrustWorkspace: 236 def test_creates_file(self, tmp_path: Path) -> None: 237 gemini_home = tmp_path / ".gemini"

Before submitting

  • [x] I have searched existing issues for duplicates.
  • [x] I am running the latest version.

attid avatar Apr 14 '26 03:04 attid

https://github.com/PleasePrompto/ductor/pull/105

attid avatar Apr 14 '26 13:04 attid

Fixed via PR #105 (@attid) in v0.16.0. The new bundled-chunks discovery path handles v0.38.x correctly and is version-robust going forward. Closing as duplicate of #108 which carries the full discussion.

PleasePrompto avatar Apr 21 '26 10:04 PleasePrompto

Fixed — landed via PR #105 (@attid) in v0.16.0. Duplicate of #108.

Thanks to @attid for tracing this to the Gemini CLI v0.38.x prebundled chunks. The model discovery now reads from the correct bundled path. Closing as duplicate of #108 which has the full discussion.

PleasePrompto avatar Apr 21 '26 10:04 PleasePrompto