adanos-cli 1.30.0__tar.gz → 1.32.0__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 (51) hide show
  1. {adanos_cli-1.30.0 → adanos_cli-1.32.0}/.github/workflows/ci.yml +3 -0
  2. {adanos_cli-1.30.0 → adanos_cli-1.32.0}/CHANGELOG.md +28 -0
  3. {adanos_cli-1.30.0 → adanos_cli-1.32.0}/PKG-INFO +31 -2
  4. {adanos_cli-1.30.0 → adanos_cli-1.32.0}/README.md +30 -1
  5. adanos_cli-1.32.0/scripts/cli_audit.py +58 -0
  6. {adanos_cli-1.30.0 → adanos_cli-1.32.0}/src/adanos_cli/__init__.py +1 -1
  7. {adanos_cli-1.30.0 → adanos_cli-1.32.0}/src/adanos_cli/activity_log.py +5 -2
  8. {adanos_cli-1.30.0 → adanos_cli-1.32.0}/src/adanos_cli/commands/auth.py +2 -14
  9. {adanos_cli-1.30.0 → adanos_cli-1.32.0}/src/adanos_cli/commands/config.py +3 -1
  10. adanos_cli-1.32.0/src/adanos_cli/commands/secrets.py +54 -0
  11. {adanos_cli-1.30.0 → adanos_cli-1.32.0}/src/adanos_cli/config.py +17 -0
  12. {adanos_cli-1.30.0 → adanos_cli-1.32.0}/src/adanos_cli/main.py +394 -78
  13. {adanos_cli-1.30.0 → adanos_cli-1.32.0}/src/adanos_cli/nlp.py +27 -0
  14. {adanos_cli-1.30.0 → adanos_cli-1.32.0}/src/adanos_cli/summaries.py +87 -2
  15. {adanos_cli-1.30.0 → adanos_cli-1.32.0}/src/adanos_cli/tty.py +6 -1
  16. {adanos_cli-1.30.0 → adanos_cli-1.32.0}/tests/test_activity_log.py +16 -0
  17. {adanos_cli-1.30.0 → adanos_cli-1.32.0}/tests/test_agent_contract.py +147 -1
  18. {adanos_cli-1.30.0 → adanos_cli-1.32.0}/tests/test_auth.py +88 -2
  19. {adanos_cli-1.30.0 → adanos_cli-1.32.0}/tests/test_diagnostics.py +59 -0
  20. {adanos_cli-1.30.0 → adanos_cli-1.32.0}/tests/test_endpoint_coverage.py +31 -0
  21. {adanos_cli-1.30.0 → adanos_cli-1.32.0}/tests/test_onboarding.py +14 -0
  22. {adanos_cli-1.30.0 → adanos_cli-1.32.0}/tests/test_power_features.py +125 -2
  23. {adanos_cli-1.30.0 → adanos_cli-1.32.0}/tests/test_tty.py +18 -1
  24. {adanos_cli-1.30.0 → adanos_cli-1.32.0}/.github/workflows/cli-binaries.yml +0 -0
  25. {adanos_cli-1.30.0 → adanos_cli-1.32.0}/.github/workflows/publish-pypi.yml +0 -0
  26. {adanos_cli-1.30.0 → adanos_cli-1.32.0}/.gitignore +0 -0
  27. {adanos_cli-1.30.0 → adanos_cli-1.32.0}/LICENSE +0 -0
  28. {adanos_cli-1.30.0 → adanos_cli-1.32.0}/install.ps1 +0 -0
  29. {adanos_cli-1.30.0 → adanos_cli-1.32.0}/install.sh +0 -0
  30. {adanos_cli-1.30.0 → adanos_cli-1.32.0}/pyproject.toml +0 -0
  31. {adanos_cli-1.30.0 → adanos_cli-1.32.0}/scripts/build_cli_binary.py +0 -0
  32. {adanos_cli-1.30.0 → adanos_cli-1.32.0}/scripts/generate_homebrew_formula.py +0 -0
  33. {adanos_cli-1.30.0 → adanos_cli-1.32.0}/scripts/pyinstaller_entrypoint.py +0 -0
  34. {adanos_cli-1.30.0 → adanos_cli-1.32.0}/src/adanos_cli/__main__.py +0 -0
  35. {adanos_cli-1.30.0 → adanos_cli-1.32.0}/src/adanos_cli/commands/__init__.py +0 -0
  36. {adanos_cli-1.30.0 → adanos_cli-1.32.0}/src/adanos_cli/commands/extensions.py +0 -0
  37. {adanos_cli-1.30.0 → adanos_cli-1.32.0}/src/adanos_cli/endpoints.py +0 -0
  38. {adanos_cli-1.30.0 → adanos_cli-1.32.0}/src/adanos_cli/shell_history.py +0 -0
  39. {adanos_cli-1.30.0 → adanos_cli-1.32.0}/src/adanos_cli/update_notifier.py +0 -0
  40. {adanos_cli-1.30.0 → adanos_cli-1.32.0}/src/adanos_cli/utils.py +0 -0
  41. {adanos_cli-1.30.0 → adanos_cli-1.32.0}/src/adanos_cli/watchlists.py +0 -0
  42. {adanos_cli-1.30.0 → adanos_cli-1.32.0}/tests/__init__.py +0 -0
  43. {adanos_cli-1.30.0 → adanos_cli-1.32.0}/tests/conftest.py +0 -0
  44. {adanos_cli-1.30.0 → adanos_cli-1.32.0}/tests/test_account.py +0 -0
  45. {adanos_cli-1.30.0 → adanos_cli-1.32.0}/tests/test_config_runtime.py +0 -0
  46. {adanos_cli-1.30.0 → adanos_cli-1.32.0}/tests/test_distribution.py +0 -0
  47. {adanos_cli-1.30.0 → adanos_cli-1.32.0}/tests/test_extensions.py +0 -0
  48. {adanos_cli-1.30.0 → adanos_cli-1.32.0}/tests/test_logs.py +0 -0
  49. {adanos_cli-1.30.0 → adanos_cli-1.32.0}/tests/test_shell.py +0 -0
  50. {adanos_cli-1.30.0 → adanos_cli-1.32.0}/tests/test_update_notifier.py +0 -0
  51. {adanos_cli-1.30.0 → adanos_cli-1.32.0}/tests/test_watchlists.py +0 -0
@@ -20,6 +20,9 @@ jobs:
20
20
  - name: Install dependencies
21
21
  run: python -m pip install ".[dev]"
22
22
 
23
+ - name: Run CLI audit
24
+ run: python scripts/cli_audit.py
25
+
23
26
  - name: Run tests
24
27
  run: python -m pytest tests -q
25
28
 
@@ -5,6 +5,34 @@ All notable changes to `adanos-cli` will be documented in this file.
5
5
  Format: [Keep a Changelog](https://keepachangelog.com/en/1.1.0/)
6
6
  Versioning: [Semantic Versioning](https://semver.org/spec/v2.0.0.html)
7
7
 
8
+ ## [1.32.0] - 2026-08-09
9
+
10
+ ### Changed
11
+ - Synced CLI error and semantic guidance with Adanos Market Sentiment API `1.49.0`.
12
+ - Structured compare-limit errors now show `max_items`, and data-availability errors show `available_since`.
13
+ - Documented nullable Polymarket `unique_traders` and stable per-UTC-day `trend_history` semantics.
14
+
15
+ ## [1.31.0] - 2026-07-03
16
+
17
+ ### Added
18
+ - Added explicit `--no-color`, `--no-input`, and `--plain` global flags.
19
+ - Added `--api-key-stdin` and `--api-key-file` for `login`, `auth login`, and `config set`.
20
+ - Added grouped and filterable `adanos endpoint list --platform ... --search ...`.
21
+ - Added an offline CLI audit script and CI step for stable help/output contracts.
22
+
23
+ ### Changed
24
+ - Synced CLI human reports with Adanos Market Sentiment API `1.46.0`, including Polymarket `pulse`, representative `top_mentions` evidence, `market_status`, `daily_trend[].bullish_pct` / `bearish_pct`, and clearer `market_count` vs `current_market_count` breadth labels.
25
+ - Human output for endpoint-backed commands such as `trending`, `search`, `compare`, `stats`, `health`, and `endpoint call` now uses compact summaries/tables. Use `--json` or `--output json` for raw payloads.
26
+ - JSON report outputs now consistently include `kind` and `command`, with `subcommand` where relevant.
27
+ - Help output for `trending`, `endpoint call`, `watchlist`, `export`, and `scan` now starts from concrete examples.
28
+ - `capabilities` now documents output modes, secret input methods, config paths, exit codes, and the JSON contract.
29
+
30
+ ### Fixed
31
+ - Fixed `adanos ask` routing so common crypto prompts such as `How does BTC look?`, `How does ETH look?`, `How does SOL look?`, and `compare BTC and ETH` use crypto report/compare flows instead of stock reports.
32
+ - Fixed `--output text` so explicit text mode is respected even when stdout is redirected.
33
+ - Replaced raw connection-refused runtime errors with a concise API base URL/network/proxy hint.
34
+ - `doctor` now reports corrupt `config.json` or `credentials.json` instead of silently treating them as empty.
35
+
8
36
  ## [1.30.0] - 2026-06-23
9
37
 
10
38
  ### Added
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: adanos-cli
3
- Version: 1.30.0
3
+ Version: 1.32.0
4
4
  Summary: CLI for the Adanos Market Sentiment API
5
5
  Project-URL: Homepage, https://adanos.org
6
6
  Project-URL: API_Docs, https://api.adanos.org/docs
@@ -135,6 +135,8 @@ Persist a key locally:
135
135
 
136
136
  ```bash
137
137
  adanos login --api-key sk_live_xxx
138
+ printf '%s\n' "$ADANOS_API_KEY" | adanos login --api-key-stdin
139
+ adanos login --api-key-file ~/.config/adanos-cli/key.txt
138
140
  ```
139
141
 
140
142
  Request a recovery email for an existing account:
@@ -165,6 +167,14 @@ Priority order:
165
167
  - `ADANOS_API_KEY`
166
168
  - stored credentials in the active profile
167
169
 
170
+ Recommended secret input for automation is `--api-key-stdin` or `--api-key-file`. `--api-key` and `ADANOS_API_KEY` remain supported, but they are easier to leak through shell history or process inspection.
171
+
172
+ Use `--no-input` in CI or agents to make missing prompts fail fast:
173
+
174
+ ```bash
175
+ adanos --no-input login --api-key-stdin
176
+ ```
177
+
168
178
  ## Common Workflows
169
179
 
170
180
  Stock report:
@@ -197,6 +207,8 @@ Raw endpoint access:
197
207
 
198
208
  ```bash
199
209
  adanos endpoint list
210
+ adanos endpoint list --platform polymarket-stocks
211
+ adanos endpoint list --search mentions
200
212
  adanos endpoint call root.health
201
213
  adanos endpoint call reddit-stocks.trending --limit 10
202
214
  adanos endpoint call reddit-stocks.market-sentiment --from 2026-05-01 --to 2026-05-07
@@ -206,12 +218,14 @@ adanos endpoint call sentiment.analyze --text "TSLA looks like a short squeeze s
206
218
  ```
207
219
 
208
220
  Polymarket endpoint output includes both `market_count` for selected-window breadth and `current_market_count` for live-only active-market breadth.
221
+ For API `1.45.1+`, Polymarket `top_mentions` in stock detail output are representative sentiment evidence, not a liquidity leaderboard. When market status is available, the CLI shows `market_status` alongside the evidence. For API `1.46.0+`, human summaries prefer `daily_trend[].bullish_pct` and `daily_trend[].bearish_pct` over deprecated positive/negative/neutral count fields.
222
+ Polymarket `unique_traders` can be `null` when retained wallet-level trades do not fully cover the requested window. Across platforms, each `trend_history` value represents its own UTC calendar day; the current partial day's value is not expected to equal the top-level period `buzz_score`.
209
223
 
210
224
  Period-capable commands and endpoint calls accept `--from YYYY-MM-DD` and `--to YYYY-MM-DD` as inclusive UTC date windows. `--days N` remains available for v1 compatibility, but is legacy; combining `--from`, `--to` and `--days` returns API validation error `422`. Search commands are the exception: they accept only `--limit` and use the API-managed recent summary window.
211
225
 
212
226
  ## AI / Automation
213
227
 
214
- The CLI supports machine-readable output via `--output json` or `--quiet`.
228
+ The CLI supports explicit machine-readable output via `--output json` or `--quiet`.
215
229
 
216
230
  ```bash
217
231
  adanos --quiet capabilities
@@ -221,10 +235,25 @@ adanos --quiet ask "How does TSLA look?"
221
235
  adanos --quiet endpoint call news-stocks.trending --limit 3
222
236
  ```
223
237
 
238
+ Output modes:
239
+ - default auto: human text on a TTY, JSON when stdout is piped
240
+ - `--output text`: force human text, even when stdout is redirected
241
+ - `--plain`: force plain text and disable auto JSON
242
+ - `--output json`, `--json`, or `--quiet`: force JSON
243
+ - `--no-color`: disable ANSI color output; `NO_COLOR=1` is also honored
244
+
224
245
  JSON conventions:
225
246
  - object payloads include a stable `kind`
226
247
  - command wrappers include `command`, and `subcommand` when relevant
227
248
  - endpoint-backed payloads include `platform`, `route`, `endpoint`, `path`, and `data`
249
+ - raw endpoint payloads are available with `--json` / `--output json`; human mode prints compact tables or summaries
250
+
251
+ Exit codes:
252
+ - `0`: success
253
+ - `1`: runtime or network/API failure
254
+ - `2`: usage, auth, or missing configuration error
255
+
256
+ This CLI is a research and workflow tool, not investment advice.
228
257
 
229
258
  ## Diagnostics
230
259
 
@@ -109,6 +109,8 @@ Persist a key locally:
109
109
 
110
110
  ```bash
111
111
  adanos login --api-key sk_live_xxx
112
+ printf '%s\n' "$ADANOS_API_KEY" | adanos login --api-key-stdin
113
+ adanos login --api-key-file ~/.config/adanos-cli/key.txt
112
114
  ```
113
115
 
114
116
  Request a recovery email for an existing account:
@@ -139,6 +141,14 @@ Priority order:
139
141
  - `ADANOS_API_KEY`
140
142
  - stored credentials in the active profile
141
143
 
144
+ Recommended secret input for automation is `--api-key-stdin` or `--api-key-file`. `--api-key` and `ADANOS_API_KEY` remain supported, but they are easier to leak through shell history or process inspection.
145
+
146
+ Use `--no-input` in CI or agents to make missing prompts fail fast:
147
+
148
+ ```bash
149
+ adanos --no-input login --api-key-stdin
150
+ ```
151
+
142
152
  ## Common Workflows
143
153
 
144
154
  Stock report:
@@ -171,6 +181,8 @@ Raw endpoint access:
171
181
 
172
182
  ```bash
173
183
  adanos endpoint list
184
+ adanos endpoint list --platform polymarket-stocks
185
+ adanos endpoint list --search mentions
174
186
  adanos endpoint call root.health
175
187
  adanos endpoint call reddit-stocks.trending --limit 10
176
188
  adanos endpoint call reddit-stocks.market-sentiment --from 2026-05-01 --to 2026-05-07
@@ -180,12 +192,14 @@ adanos endpoint call sentiment.analyze --text "TSLA looks like a short squeeze s
180
192
  ```
181
193
 
182
194
  Polymarket endpoint output includes both `market_count` for selected-window breadth and `current_market_count` for live-only active-market breadth.
195
+ For API `1.45.1+`, Polymarket `top_mentions` in stock detail output are representative sentiment evidence, not a liquidity leaderboard. When market status is available, the CLI shows `market_status` alongside the evidence. For API `1.46.0+`, human summaries prefer `daily_trend[].bullish_pct` and `daily_trend[].bearish_pct` over deprecated positive/negative/neutral count fields.
196
+ Polymarket `unique_traders` can be `null` when retained wallet-level trades do not fully cover the requested window. Across platforms, each `trend_history` value represents its own UTC calendar day; the current partial day's value is not expected to equal the top-level period `buzz_score`.
183
197
 
184
198
  Period-capable commands and endpoint calls accept `--from YYYY-MM-DD` and `--to YYYY-MM-DD` as inclusive UTC date windows. `--days N` remains available for v1 compatibility, but is legacy; combining `--from`, `--to` and `--days` returns API validation error `422`. Search commands are the exception: they accept only `--limit` and use the API-managed recent summary window.
185
199
 
186
200
  ## AI / Automation
187
201
 
188
- The CLI supports machine-readable output via `--output json` or `--quiet`.
202
+ The CLI supports explicit machine-readable output via `--output json` or `--quiet`.
189
203
 
190
204
  ```bash
191
205
  adanos --quiet capabilities
@@ -195,10 +209,25 @@ adanos --quiet ask "How does TSLA look?"
195
209
  adanos --quiet endpoint call news-stocks.trending --limit 3
196
210
  ```
197
211
 
212
+ Output modes:
213
+ - default auto: human text on a TTY, JSON when stdout is piped
214
+ - `--output text`: force human text, even when stdout is redirected
215
+ - `--plain`: force plain text and disable auto JSON
216
+ - `--output json`, `--json`, or `--quiet`: force JSON
217
+ - `--no-color`: disable ANSI color output; `NO_COLOR=1` is also honored
218
+
198
219
  JSON conventions:
199
220
  - object payloads include a stable `kind`
200
221
  - command wrappers include `command`, and `subcommand` when relevant
201
222
  - endpoint-backed payloads include `platform`, `route`, `endpoint`, `path`, and `data`
223
+ - raw endpoint payloads are available with `--json` / `--output json`; human mode prints compact tables or summaries
224
+
225
+ Exit codes:
226
+ - `0`: success
227
+ - `1`: runtime or network/API failure
228
+ - `2`: usage, auth, or missing configuration error
229
+
230
+ This CLI is a research and workflow tool, not investment advice.
202
231
 
203
232
  ## Diagnostics
204
233
 
@@ -0,0 +1,58 @@
1
+ """Offline smoke audit for the installed adanos CLI."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ import shutil
7
+ import subprocess
8
+ import sys
9
+
10
+
11
+ def _command() -> list[str]:
12
+ adanos = shutil.which("adanos")
13
+ if adanos:
14
+ return [adanos]
15
+ return [sys.executable, "-m", "adanos_cli"]
16
+
17
+
18
+ def _run(*args: str) -> subprocess.CompletedProcess[str]:
19
+ return subprocess.run([*_command(), *args], text=True, capture_output=True, check=False)
20
+
21
+
22
+ def _assert_ok(name: str, result: subprocess.CompletedProcess[str]) -> None:
23
+ if result.returncode != 0:
24
+ raise AssertionError(f"{name} failed with rc={result.returncode}: {result.stderr or result.stdout}")
25
+
26
+
27
+ def main() -> int:
28
+ capabilities = _run("--output", "json", "capabilities")
29
+ _assert_ok("capabilities json", capabilities)
30
+ payload = json.loads(capabilities.stdout)
31
+ assert payload["kind"] == "capabilities"
32
+ assert payload["command"] == "capabilities"
33
+ assert "auto" in payload["output_modes"]
34
+ assert "--api-key-stdin" in payload["auth"]["secret_input"]
35
+
36
+ text_capabilities = _run("--output", "text", "capabilities")
37
+ _assert_ok("capabilities text", text_capabilities)
38
+ assert text_capabilities.stdout.startswith("CLI capabilities")
39
+ assert not text_capabilities.stdout.lstrip().startswith("{")
40
+
41
+ endpoint_list = _run("endpoint", "list", "--platform", "polymarket-stocks", "--search", "stock", "--json")
42
+ _assert_ok("endpoint list json", endpoint_list)
43
+ endpoints = json.loads(endpoint_list.stdout)
44
+ assert endpoints
45
+ assert all(row["id"].startswith("polymarket-stocks") for row in endpoints)
46
+
47
+ help_result = _run("trending", "--help")
48
+ _assert_ok("trending help", help_result)
49
+ assert "Examples:" in help_result.stdout
50
+
51
+ unknown = _run("wat")
52
+ assert unknown.returncode == 2
53
+ assert "hint:" in unknown.stderr
54
+ return 0
55
+
56
+
57
+ if __name__ == "__main__":
58
+ raise SystemExit(main())
@@ -1,4 +1,4 @@
1
1
  """Adanos CLI package."""
2
2
 
3
3
  __all__ = ["__version__"]
4
- __version__ = "1.30.0"
4
+ __version__ = "1.32.0"
@@ -26,13 +26,16 @@ def sanitize_argv(argv: list[str]) -> list[str]:
26
26
  sanitized.append("<redacted>")
27
27
  redact_next = False
28
28
  continue
29
- if token == "--api-key":
29
+ if token in {"--api-key", "--api-key-file"}:
30
30
  sanitized.append(token)
31
31
  redact_next = True
32
32
  continue
33
33
  if token.startswith("--api-key="):
34
34
  sanitized.append("--api-key=<redacted>")
35
35
  continue
36
+ if token.startswith("--api-key-file="):
37
+ sanitized.append("--api-key-file=<redacted>")
38
+ continue
36
39
  sanitized.append(token)
37
40
 
38
41
  if redact_next:
@@ -41,7 +44,7 @@ def sanitize_argv(argv: list[str]) -> list[str]:
41
44
 
42
45
 
43
46
  def _command_name(argv: list[str]) -> str | None:
44
- value_flags = {"--api-key", "--base-url", "--output"}
47
+ value_flags = {"--api-key", "--api-key-file", "--base-url", "--output"}
45
48
  skip_next = False
46
49
  for token in argv:
47
50
  if skip_next:
@@ -2,20 +2,12 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
- from getpass import getpass
6
5
  from argparse import Namespace
7
6
 
8
7
  from .. import config as cli_config
9
8
  from ..config import DEFAULT_BASE_URL, load_config_file, masked_key, save_config_file
9
+ from .secrets import read_api_key_arg
10
10
  from ..utils import CliUsageError, print_json, with_json_metadata
11
- from ..tty import is_interactive
12
-
13
-
14
- def _prompt_api_key() -> str:
15
- value = getpass("API key: ").strip()
16
- if not value:
17
- raise CliUsageError("API key must not be empty.")
18
- return value
19
11
 
20
12
 
21
13
  def handle_auth_command(args: Namespace) -> int:
@@ -25,11 +17,7 @@ def handle_auth_command(args: Namespace) -> int:
25
17
  validation_error = cli_config.validate_profile_name(profile_name)
26
18
  if validation_error:
27
19
  raise CliUsageError(validation_error)
28
- api_key = str(getattr(args, "api_key", "") or "").strip()
29
- if not api_key:
30
- if not is_interactive():
31
- raise CliUsageError("Non-interactive usage requires --api-key.")
32
- api_key = _prompt_api_key()
20
+ api_key = read_api_key_arg(args)
33
21
  save_config_file(
34
22
  api_key=api_key,
35
23
  base_url=args.base_url,
@@ -6,13 +6,15 @@ from argparse import Namespace
6
6
 
7
7
  from .. import config as cli_config
8
8
  from ..config import DEFAULT_BASE_URL, clear_config_file, load_config_file, masked_key, save_config_file
9
+ from .secrets import read_api_key_arg
9
10
  from ..utils import CliUsageError, print_json, with_json_metadata
10
11
 
11
12
 
12
13
  def handle_config_command(args: Namespace) -> int:
13
14
  if args._handler == "config_set":
15
+ api_key = read_api_key_arg(args)
14
16
  save_config_file(
15
- api_key=args.api_key,
17
+ api_key=api_key,
16
18
  base_url=args.base_url,
17
19
  profile_name=getattr(args, "profile", None),
18
20
  )
@@ -0,0 +1,54 @@
1
+ """Secret input helpers for command handlers."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import sys
6
+ from argparse import Namespace
7
+ from getpass import getpass
8
+ from pathlib import Path
9
+
10
+ from ..tty import is_interactive, stdin_is_tty
11
+ from ..utils import CliUsageError
12
+
13
+
14
+ def read_api_key_arg(args: Namespace) -> str:
15
+ sources = [
16
+ name
17
+ for name in ("api_key", "api_key_file", "api_key_stdin")
18
+ if bool(getattr(args, name, None))
19
+ ]
20
+ if len(sources) > 1:
21
+ raise CliUsageError("Use only one API key input source: --api-key, --api-key-file, or --api-key-stdin.")
22
+
23
+ api_key = str(getattr(args, "api_key", "") or "").strip()
24
+ if api_key:
25
+ return api_key
26
+
27
+ api_key_file = str(getattr(args, "api_key_file", "") or "").strip()
28
+ if api_key_file:
29
+ try:
30
+ value = Path(api_key_file).expanduser().read_text(encoding="utf-8").strip()
31
+ except (OSError, UnicodeDecodeError) as exc:
32
+ raise CliUsageError(f"Could not read API key file: {exc}") from exc
33
+ if not value:
34
+ raise CliUsageError("API key file is empty.")
35
+ return value
36
+
37
+ if bool(getattr(args, "api_key_stdin", False)):
38
+ if bool(getattr(args, "no_input", False)) and stdin_is_tty():
39
+ raise CliUsageError("Cannot read --api-key-stdin with --no-input from an interactive TTY.")
40
+ value = sys.stdin.readline().strip()
41
+ if not value:
42
+ raise CliUsageError("No API key received on stdin.")
43
+ return value
44
+
45
+ if bool(getattr(args, "no_input", False)):
46
+ raise CliUsageError("API key required with --no-input. Use --api-key-stdin or --api-key-file.")
47
+
48
+ if not is_interactive():
49
+ raise CliUsageError("Non-interactive usage requires --api-key, --api-key-file, or --api-key-stdin.")
50
+
51
+ value = getpass("API key: ").strip()
52
+ if not value:
53
+ raise CliUsageError("API key must not be empty.")
54
+ return value
@@ -40,6 +40,23 @@ class RuntimeConfig:
40
40
  profile_name: str | None = None
41
41
 
42
42
 
43
+ def inspect_json_file(path: Path) -> dict[str, Any]:
44
+ if not path.exists():
45
+ return {"path": str(path), "exists": False, "ok": True, "error": None}
46
+ try:
47
+ payload = json.loads(path.read_text(encoding="utf-8"))
48
+ except Exception as exc:
49
+ return {"path": str(path), "exists": True, "ok": False, "error": str(exc)}
50
+ if not isinstance(payload, dict):
51
+ return {
52
+ "path": str(path),
53
+ "exists": True,
54
+ "ok": False,
55
+ "error": "JSON root must be an object",
56
+ }
57
+ return {"path": str(path), "exists": True, "ok": True, "error": None}
58
+
59
+
43
60
  def _read_json_file(path: Path) -> dict[str, Any]:
44
61
  if not path.exists():
45
62
  return {}