coderouter-cli 2.9.4__py3-none-any.whl → 2.11.0__py3-none-any.whl
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.
- coderouter/cli.py +125 -0
- coderouter/config/schemas.py +144 -10
- coderouter/ingress/launcher_routes.py +289 -22
- coderouter/launcher_devices.py +188 -4
- coderouter/launcher_speculative.py +5 -1
- coderouter/launcher_swap.py +11 -2
- coderouter/vscode_init.py +575 -0
- {coderouter_cli-2.9.4.dist-info → coderouter_cli-2.11.0.dist-info}/METADATA +5 -1
- {coderouter_cli-2.9.4.dist-info → coderouter_cli-2.11.0.dist-info}/RECORD +12 -11
- {coderouter_cli-2.9.4.dist-info → coderouter_cli-2.11.0.dist-info}/WHEEL +0 -0
- {coderouter_cli-2.9.4.dist-info → coderouter_cli-2.11.0.dist-info}/entry_points.txt +0 -0
- {coderouter_cli-2.9.4.dist-info → coderouter_cli-2.11.0.dist-info}/licenses/LICENSE +0 -0
coderouter/cli.py
CHANGED
|
@@ -336,6 +336,78 @@ def _build_parser() -> argparse.ArgumentParser:
|
|
|
336
336
|
),
|
|
337
337
|
)
|
|
338
338
|
|
|
339
|
+
# v2.10-A: `coderouter vscode-init` — scaffold a VSCode workspace so
|
|
340
|
+
# Claude Code launched from the integrated terminal auto-points at
|
|
341
|
+
# CodeRouter (no manual env-var juggling). Optionally writes .envrc
|
|
342
|
+
# for direnv users. Cline / Roo / Continue are covered by the cheat
|
|
343
|
+
# sheet printed on completion and docs/guides/vscode.md — this
|
|
344
|
+
# command deliberately does NOT touch those extensions' settings
|
|
345
|
+
# (their schemas change with their own release cadence).
|
|
346
|
+
vscode_init = sub.add_parser(
|
|
347
|
+
"vscode-init",
|
|
348
|
+
help="Scaffold VSCode workspace settings for CodeRouter (v2.10-A).",
|
|
349
|
+
description=(
|
|
350
|
+
"Write .vscode/settings.json (terminal.integrated.env.*) so a "
|
|
351
|
+
"Claude Code session launched from VSCode's integrated terminal "
|
|
352
|
+
"auto-points at CodeRouter. Optionally emit a direnv .envrc. "
|
|
353
|
+
"Idempotent: safe to re-run. Conflict-aware: refuses to overwrite "
|
|
354
|
+
"differing existing values without --force."
|
|
355
|
+
),
|
|
356
|
+
)
|
|
357
|
+
vscode_init.add_argument(
|
|
358
|
+
"--target",
|
|
359
|
+
default=".",
|
|
360
|
+
metavar="PATH",
|
|
361
|
+
help="Workspace root (default: current directory).",
|
|
362
|
+
)
|
|
363
|
+
vscode_init.add_argument(
|
|
364
|
+
"--port",
|
|
365
|
+
type=int,
|
|
366
|
+
default=None,
|
|
367
|
+
metavar="PORT",
|
|
368
|
+
help=(
|
|
369
|
+
"CodeRouter port for ANTHROPIC_BASE_URL. Defaults to 8088 "
|
|
370
|
+
"(matches every docs / quickstart example). Note that "
|
|
371
|
+
"`coderouter serve` alone defaults to 4000; if you serve on "
|
|
372
|
+
"4000, pass --port 4000 here too."
|
|
373
|
+
),
|
|
374
|
+
)
|
|
375
|
+
vscode_init.add_argument(
|
|
376
|
+
"--profile",
|
|
377
|
+
default=None,
|
|
378
|
+
metavar="NAME",
|
|
379
|
+
help=(
|
|
380
|
+
"Preload CODEROUTER_MODE=<profile> so the VSCode terminal "
|
|
381
|
+
"routes to a non-default profile without a per-request header."
|
|
382
|
+
),
|
|
383
|
+
)
|
|
384
|
+
vscode_init.add_argument(
|
|
385
|
+
"--with-envrc",
|
|
386
|
+
action="store_true",
|
|
387
|
+
help=(
|
|
388
|
+
"Also write .envrc (direnv). Run `direnv allow` once after "
|
|
389
|
+
"generation. Tip: keep secrets in a separate .envrc.local."
|
|
390
|
+
),
|
|
391
|
+
)
|
|
392
|
+
vscode_init.add_argument(
|
|
393
|
+
"--dry-run",
|
|
394
|
+
action="store_true",
|
|
395
|
+
help=(
|
|
396
|
+
"Compute all changes and print unified diffs, but do not write "
|
|
397
|
+
"any files. Byte-identical to the write path minus the final "
|
|
398
|
+
"os.replace."
|
|
399
|
+
),
|
|
400
|
+
)
|
|
401
|
+
vscode_init.add_argument(
|
|
402
|
+
"--force",
|
|
403
|
+
action="store_true",
|
|
404
|
+
help=(
|
|
405
|
+
"Overwrite existing conflicting values. Without this flag, a "
|
|
406
|
+
"conflict is reported with a diff and the file is left "
|
|
407
|
+
"untouched (exit 2)."
|
|
408
|
+
),
|
|
409
|
+
)
|
|
410
|
+
|
|
339
411
|
return parser
|
|
340
412
|
|
|
341
413
|
|
|
@@ -432,6 +504,9 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
432
504
|
if args.command == "replay":
|
|
433
505
|
return _run_replay(args)
|
|
434
506
|
|
|
507
|
+
if args.command == "vscode-init":
|
|
508
|
+
return _run_vscode_init(args)
|
|
509
|
+
|
|
435
510
|
print(f"unknown command: {args.command}", file=sys.stderr)
|
|
436
511
|
return 2
|
|
437
512
|
|
|
@@ -765,6 +840,56 @@ def _run_replay(args: argparse.Namespace) -> int:
|
|
|
765
840
|
return 0
|
|
766
841
|
|
|
767
842
|
|
|
843
|
+
def _run_vscode_init(args: argparse.Namespace) -> int:
|
|
844
|
+
"""v2.10-A: drive :func:`coderouter.vscode_init.run_vscode_init`.
|
|
845
|
+
|
|
846
|
+
Kept small and testable — the actual scaffolding logic lives in
|
|
847
|
+
:mod:`coderouter.vscode_init` so tests can exercise it without
|
|
848
|
+
argparse in the way. This wrapper's job is:
|
|
849
|
+
|
|
850
|
+
* resolve the ``--target`` argument to a real directory
|
|
851
|
+
* map ``--port`` (default None) to the module's ``DEFAULT_PORT``
|
|
852
|
+
* translate exceptions (missing target directory) to a friendly
|
|
853
|
+
stderr message + exit 1
|
|
854
|
+
* print the formatted result and propagate the module's exit code
|
|
855
|
+
"""
|
|
856
|
+
from coderouter.vscode_init import (
|
|
857
|
+
DEFAULT_PORT,
|
|
858
|
+
exit_code_for,
|
|
859
|
+
format_result,
|
|
860
|
+
run_vscode_init,
|
|
861
|
+
)
|
|
862
|
+
|
|
863
|
+
target = Path(args.target).expanduser()
|
|
864
|
+
if not target.is_dir():
|
|
865
|
+
print(
|
|
866
|
+
f"vscode-init: target directory does not exist: {target}",
|
|
867
|
+
file=sys.stderr,
|
|
868
|
+
)
|
|
869
|
+
return 1
|
|
870
|
+
|
|
871
|
+
port = args.port if args.port is not None else DEFAULT_PORT
|
|
872
|
+
|
|
873
|
+
try:
|
|
874
|
+
result = run_vscode_init(
|
|
875
|
+
target,
|
|
876
|
+
port=port,
|
|
877
|
+
profile=args.profile,
|
|
878
|
+
with_envrc=args.with_envrc,
|
|
879
|
+
dry_run=args.dry_run,
|
|
880
|
+
force=args.force,
|
|
881
|
+
)
|
|
882
|
+
except FileNotFoundError as exc:
|
|
883
|
+
# Raised only when target vanishes between the pre-check above
|
|
884
|
+
# and the module's own check — unlikely in practice, but map
|
|
885
|
+
# it to the same shape as the pre-check for consistency.
|
|
886
|
+
print(f"vscode-init: {exc}", file=sys.stderr)
|
|
887
|
+
return 1
|
|
888
|
+
|
|
889
|
+
print(format_result(result, dry_run=args.dry_run, port=port))
|
|
890
|
+
return exit_code_for(result)
|
|
891
|
+
|
|
892
|
+
|
|
768
893
|
def _run_check_env(arg_value: str) -> int:
|
|
769
894
|
"""v1.6.3: filesystem / git security checks for `.env`.
|
|
770
895
|
|
coderouter/config/schemas.py
CHANGED
|
@@ -17,7 +17,14 @@ import re
|
|
|
17
17
|
import warnings
|
|
18
18
|
from typing import Any, Literal, Self
|
|
19
19
|
|
|
20
|
-
from pydantic import
|
|
20
|
+
from pydantic import (
|
|
21
|
+
BaseModel,
|
|
22
|
+
ConfigDict,
|
|
23
|
+
Field,
|
|
24
|
+
HttpUrl,
|
|
25
|
+
field_validator,
|
|
26
|
+
model_validator,
|
|
27
|
+
)
|
|
21
28
|
|
|
22
29
|
|
|
23
30
|
class Capabilities(BaseModel):
|
|
@@ -394,7 +401,7 @@ class ProviderConfig(BaseModel):
|
|
|
394
401
|
default=False,
|
|
395
402
|
description="If true, only used when ALLOW_PAID=true (plan.md §2.3).",
|
|
396
403
|
)
|
|
397
|
-
timeout_s: float = Field(default=30.0, ge=1.0, le=
|
|
404
|
+
timeout_s: float = Field(default=30.0, ge=1.0, le=86400.0)
|
|
398
405
|
|
|
399
406
|
# v2.6 language-tax track: path to a LOCAL ``tokenizer.json`` for this
|
|
400
407
|
# provider's model, used to measure the CJK over-count vs the char/4
|
|
@@ -1414,6 +1421,29 @@ class LauncherBackendConfig(BaseModel):
|
|
|
1414
1421
|
binary: ~/llama.cpp/build/bin/llama-server
|
|
1415
1422
|
vllm:
|
|
1416
1423
|
binary: ~/.venv/bin/python
|
|
1424
|
+
|
|
1425
|
+
**Backend variants** (v2.11.0+, docs/designs/launcher-multi-build.md):
|
|
1426
|
+
a key may also be ``<base>-<variant>`` to register an additional build of
|
|
1427
|
+
the same backend — typically llama.cpp compiled for a specific GPU
|
|
1428
|
+
runtime. Each variant appears as its own entry in the Launcher's backend
|
|
1429
|
+
select, gets its own ``--list-devices`` probe (device IDs differ per
|
|
1430
|
+
build: ``CUDA0`` and ``Vulkan0`` are not the same GPU) and can carry its
|
|
1431
|
+
own ``option_profiles``. ``binary`` is **required** for a variant::
|
|
1432
|
+
|
|
1433
|
+
backends:
|
|
1434
|
+
llama.cpp: # 素のビルド (binary 省略可 = PATH)
|
|
1435
|
+
binary: ~/llm/apps/llama.cpp/build/bin/llama-server
|
|
1436
|
+
llama.cpp-cuda:
|
|
1437
|
+
binary: ~/llm/apps/llama.cpp/build-cuda/bin/llama-server
|
|
1438
|
+
llama.cpp-vulkan:
|
|
1439
|
+
binary: ~/llm/apps/llama.cpp/build-vulkan/bin/llama-server
|
|
1440
|
+
llama.cpp-rocm:
|
|
1441
|
+
binary: ~/llm/apps/llama.cpp/build-rocm/bin/llama-server
|
|
1442
|
+
|
|
1443
|
+
Variants are an advanced option: the matching GPU runtime (CUDA Toolkit /
|
|
1444
|
+
Vulkan runtime + ICD / ROCm) must already be installed by the operator.
|
|
1445
|
+
CodeRouter never selects a variant implicitly — omit them and both the UI
|
|
1446
|
+
and the resulting argv are identical to before.
|
|
1417
1447
|
"""
|
|
1418
1448
|
|
|
1419
1449
|
model_config = ConfigDict(extra="forbid")
|
|
@@ -1544,9 +1574,39 @@ class SwapModelSpec(BaseModel):
|
|
|
1544
1574
|
"only widens *catalog* matching for ``SwapManager.match``."
|
|
1545
1575
|
),
|
|
1546
1576
|
)
|
|
1547
|
-
backend:
|
|
1548
|
-
...,
|
|
1577
|
+
backend: str = Field(
|
|
1578
|
+
...,
|
|
1579
|
+
description=(
|
|
1580
|
+
"Same backend set as the manual launcher UI / _build_cmd: "
|
|
1581
|
+
"'llama.cpp' / 'vllm' / 'mlx', optionally with a '-<variant>' "
|
|
1582
|
+
"suffix naming a specific build declared in launcher.backends "
|
|
1583
|
+
"(e.g. 'llama.cpp-cuda' to pin this model to the CUDA build). "
|
|
1584
|
+
"Validated by the field validator below plus "
|
|
1585
|
+
"LauncherConfig._check_swap_backends_declared."
|
|
1586
|
+
),
|
|
1549
1587
|
)
|
|
1588
|
+
|
|
1589
|
+
@field_validator("backend")
|
|
1590
|
+
@classmethod
|
|
1591
|
+
def _check_backend_name(cls, v: str) -> str:
|
|
1592
|
+
"""基底名 or 既知基底名 + 妥当なバリアントのみ許す。
|
|
1593
|
+
|
|
1594
|
+
以前は ``Literal["llama.cpp","vllm","mlx"]`` だった。バリアント
|
|
1595
|
+
(``llama.cpp-cuda``) を通すため str に緩めたので、代わりに形式検証を
|
|
1596
|
+
ここで行う。既存の 3 値はそのまま通る (後方互換)。
|
|
1597
|
+
"""
|
|
1598
|
+
from coderouter.launcher_devices import (
|
|
1599
|
+
KNOWN_BASE_BACKENDS,
|
|
1600
|
+
is_valid_backend_name,
|
|
1601
|
+
)
|
|
1602
|
+
|
|
1603
|
+
if not is_valid_backend_name(v):
|
|
1604
|
+
raise ValueError(
|
|
1605
|
+
f"backend {v!r} is not valid. Expected one of "
|
|
1606
|
+
f"{list(KNOWN_BASE_BACKENDS)} or '<base>-<variant>' "
|
|
1607
|
+
"(e.g. 'llama.cpp-cuda')."
|
|
1608
|
+
)
|
|
1609
|
+
return v
|
|
1550
1610
|
model_path: str = Field(
|
|
1551
1611
|
...,
|
|
1552
1612
|
description=(
|
|
@@ -1802,10 +1862,13 @@ class LauncherConfig(BaseModel):
|
|
|
1802
1862
|
default_factory=dict,
|
|
1803
1863
|
description=(
|
|
1804
1864
|
"Per-backend binary path overrides. "
|
|
1805
|
-
"Keys are backend names ('llama.cpp', 'vllm')
|
|
1806
|
-
"
|
|
1807
|
-
"
|
|
1808
|
-
"
|
|
1865
|
+
"Keys are backend names ('llama.cpp', 'vllm', 'mlx') or backend "
|
|
1866
|
+
"variants ('llama.cpp-cuda', 'llama.cpp-vulkan', ...) naming an "
|
|
1867
|
+
"additional build of the same backend — see "
|
|
1868
|
+
"LauncherBackendConfig. When a base key is absent, the default "
|
|
1869
|
+
"executable is used ('llama-server' / 'python') and resolved via "
|
|
1870
|
+
"PATH. Variants must set 'binary' explicitly and additionally "
|
|
1871
|
+
"appear in the Launcher's backend select."
|
|
1809
1872
|
),
|
|
1810
1873
|
)
|
|
1811
1874
|
option_profiles: dict[str, list[LauncherOptionProfile]] = Field(
|
|
@@ -1813,6 +1876,10 @@ class LauncherConfig(BaseModel):
|
|
|
1813
1876
|
description=(
|
|
1814
1877
|
"Named option presets per backend. "
|
|
1815
1878
|
"Keys should be backend names: 'llama.cpp', 'vllm'. "
|
|
1879
|
+
"A backend-variant key ('llama.cpp-cuda') is also accepted: its "
|
|
1880
|
+
"presets are appended to the base backend's list, and a preset "
|
|
1881
|
+
"whose 'name' collides replaces the inherited one in place "
|
|
1882
|
+
"(see launcher_devices.resolve_option_profiles). "
|
|
1816
1883
|
"Each key maps to an ordered list of named presets. "
|
|
1817
1884
|
"A free-form 'extra args' field is always available in the UI "
|
|
1818
1885
|
"for one-off overrides without touching this config."
|
|
@@ -1929,15 +1996,82 @@ class LauncherConfig(BaseModel):
|
|
|
1929
1996
|
)
|
|
1930
1997
|
return self
|
|
1931
1998
|
|
|
1999
|
+
@model_validator(mode="after")
|
|
2000
|
+
def _check_backend_names_and_variant_binaries(self) -> LauncherConfig:
|
|
2001
|
+
"""``backends`` のキー形式と、バリアントの ``binary`` 必須を検証する。
|
|
2002
|
+
|
|
2003
|
+
設計: docs/designs/launcher-multi-build.md §5.2。
|
|
2004
|
+
|
|
2005
|
+
1. キーは既知基底名 (``llama.cpp`` / ``vllm`` / ``mlx``) そのもの、
|
|
2006
|
+
または ``<既知基底名>-<バリアント>`` (``llama.cpp-cuda`` 等) のみ。
|
|
2007
|
+
**破壊的変更**: これまで ``llamacpp:`` のような typo は黙って無視
|
|
2008
|
+
されていた (バックエンド一覧が固定 3 キーだったため)。今後は
|
|
2009
|
+
ロード時エラーになる。
|
|
2010
|
+
2. **バリアントは ``binary`` 必須**。``llama.cpp-cuda: {}`` を許すと
|
|
2011
|
+
既定名フォールバックで PATH の ``llama-server`` が使われ、CUDA
|
|
2012
|
+
ビルドを指定したつもりで素のビルドが静かに動く —— 本機能で最も
|
|
2013
|
+
気づきにくい事故なのでロード時に殺す。基底名は従来どおり
|
|
2014
|
+
``binary`` 省略可 (PATH 解決)。
|
|
2015
|
+
"""
|
|
2016
|
+
from coderouter.launcher_devices import (
|
|
2017
|
+
KNOWN_BASE_BACKENDS,
|
|
2018
|
+
is_valid_backend_name,
|
|
2019
|
+
is_variant,
|
|
2020
|
+
)
|
|
2021
|
+
|
|
2022
|
+
for name, bc in self.backends.items():
|
|
2023
|
+
if not is_valid_backend_name(name):
|
|
2024
|
+
raise ValueError(
|
|
2025
|
+
f"launcher.backends: invalid backend key {name!r}. "
|
|
2026
|
+
f"Expected one of {list(KNOWN_BASE_BACKENDS)} or "
|
|
2027
|
+
"'<base>-<variant>' where variant matches "
|
|
2028
|
+
"[a-z0-9][a-z0-9._-]* (e.g. 'llama.cpp-cuda')."
|
|
2029
|
+
)
|
|
2030
|
+
if is_variant(name) and not bc.binary:
|
|
2031
|
+
raise ValueError(
|
|
2032
|
+
f"launcher.backends[{name!r}]: 'binary' is required for a "
|
|
2033
|
+
"backend variant. Without it the launcher would fall back "
|
|
2034
|
+
"to the base default on PATH and silently run a different "
|
|
2035
|
+
"build than the one you selected."
|
|
2036
|
+
)
|
|
2037
|
+
return self
|
|
2038
|
+
|
|
2039
|
+
@model_validator(mode="after")
|
|
2040
|
+
def _check_swap_backends_declared(self) -> LauncherConfig:
|
|
2041
|
+
"""swap のモデルがバリアントを指すなら ``backends`` に実在すること。
|
|
2042
|
+
|
|
2043
|
+
設計 §5.2-3。基底名 (``llama.cpp`` 等) は ``backends`` に書かなくても
|
|
2044
|
+
PATH 解決で動くので従来どおり不要。バリアントは実行ファイルパスが
|
|
2045
|
+
``backends`` にしか無いので、宣言漏れをロード時に弾く。
|
|
2046
|
+
"""
|
|
2047
|
+
if self.swap is None:
|
|
2048
|
+
return self
|
|
2049
|
+
from coderouter.launcher_devices import is_variant
|
|
2050
|
+
|
|
2051
|
+
for spec in self.swap.models:
|
|
2052
|
+
if is_variant(spec.backend) and spec.backend not in self.backends:
|
|
2053
|
+
raise ValueError(
|
|
2054
|
+
f"launcher.swap.models[{spec.name!r}]: backend "
|
|
2055
|
+
f"{spec.backend!r} is a variant but is not declared in "
|
|
2056
|
+
"launcher.backends (its binary path is unknown)."
|
|
2057
|
+
)
|
|
2058
|
+
return self
|
|
2059
|
+
|
|
1932
2060
|
@model_validator(mode="after")
|
|
1933
2061
|
def _check_swap_option_profiles_exist(self) -> LauncherConfig:
|
|
1934
|
-
"""§5.4 #2: a swap model's ``option_profile`` must be a real preset.
|
|
2062
|
+
"""§5.4 #2: a swap model's ``option_profile`` must be a real preset.
|
|
2063
|
+
|
|
2064
|
+
バリアント backend の場合は基底名のプロファイルも継承されるので
|
|
2065
|
+
(:func:`resolve_option_profiles`)、マージ後の一覧で判定する。
|
|
2066
|
+
"""
|
|
1935
2067
|
if self.swap is None:
|
|
1936
2068
|
return self
|
|
2069
|
+
from coderouter.launcher_devices import resolve_option_profiles
|
|
2070
|
+
|
|
1937
2071
|
for spec in self.swap.models:
|
|
1938
2072
|
if spec.option_profile is None:
|
|
1939
2073
|
continue
|
|
1940
|
-
profiles = self.option_profiles
|
|
2074
|
+
profiles = resolve_option_profiles(self.option_profiles, spec.backend)
|
|
1941
2075
|
if not any(p.name == spec.option_profile for p in profiles):
|
|
1942
2076
|
raise ValueError(
|
|
1943
2077
|
f"launcher.swap.models[{spec.name!r}]: option_profile "
|