(args: argparse.Namespace)
| 360 | |
| 361 | |
| 362 | def cmd_init(args: argparse.Namespace) -> int: |
| 363 | force = cast(bool, args.force) |
| 364 | dest = Path("config.arc.yaml") |
| 365 | |
| 366 | if dest.exists() and not force: |
| 367 | print(f"{dest} already exists. Use --force to overwrite.", file=sys.stderr) |
| 368 | return 1 |
| 369 | |
| 370 | # Look for the example config: first in repo root (relative to package), |
| 371 | # then in CWD (for development), then bundled in the package data dir. |
| 372 | _candidates = [ |
| 373 | Path(__file__).resolve().parent.parent / EXAMPLE_CONFIG, # repo root |
| 374 | Path.cwd() / EXAMPLE_CONFIG, # cwd fallback |
| 375 | Path(__file__).resolve().parent / "data" / EXAMPLE_CONFIG, # packaged |
| 376 | ] |
| 377 | example = next((p for p in _candidates if p.exists()), None) |
| 378 | if example is None: |
| 379 | print( |
| 380 | f"Error: example config not found.\n" |
| 381 | f"Searched: {', '.join(str(c) for c in _candidates)}", |
| 382 | file=sys.stderr, |
| 383 | ) |
| 384 | return 1 |
| 385 | |
| 386 | # Interactive provider prompt (TTY only, else default to openai) |
| 387 | choice = "1" |
| 388 | if sys.stdin.isatty(): |
| 389 | print("Select LLM provider:") |
| 390 | print(" 1) openai (requires OPENAI_API_KEY)") |
| 391 | print(" 2) openrouter (requires OPENROUTER_API_KEY)") |
| 392 | print(" 3) deepseek (requires DEEPSEEK_API_KEY)") |
| 393 | print(" 4) acp (local AI agent — no API key needed)") |
| 394 | try: |
| 395 | raw = input("Choice [1]: ").strip() |
| 396 | except (EOFError, KeyboardInterrupt): |
| 397 | raw = "" |
| 398 | if raw in _PROVIDER_CHOICES: |
| 399 | choice = raw |
| 400 | |
| 401 | provider, api_key_env = _PROVIDER_CHOICES[choice] |
| 402 | |
| 403 | content = example.read_text(encoding="utf-8") |
| 404 | |
| 405 | # String-based replacement to preserve YAML comments |
| 406 | content = content.replace( |
| 407 | 'provider: "openai-compatible"', f'provider: "{provider}"' |
| 408 | ) |
| 409 | |
| 410 | if provider == "acp": |
| 411 | content = content.replace('api_key_env: "OPENAI_API_KEY"', 'api_key_env: ""') |
| 412 | else: |
| 413 | if api_key_env: |
| 414 | content = content.replace( |
| 415 | 'api_key_env: "OPENAI_API_KEY"', f'api_key_env: "{api_key_env}"' |
| 416 | ) |
| 417 | |
| 418 | if provider in _PROVIDER_MODELS: |
| 419 | primary, fallbacks = _PROVIDER_MODELS[provider] |
no test coverage detected