refactor(core): move stocks fetching, caching, and analysis into idx-core

Phase 3b of docs/DESIGN.md. `stocks` handlers are now argument parsing,
one idx-core call, and rendering.

- Idx (client.rs) is the entry point: Idx::new(CoreConfig) with
  market(), financial(), and analysis(). Live lookups return
  Fetched<T> { data, source, fetched_at, stale } and take a CachePolicy
  (Default | Offline | Refresh, from the --offline/--no-cache flags).
- One cached_fetch replaces the CLI's three cache flows; they differed
  only in whether a fresh entry is read via get or get_offline when
  offline, which yields the same data and diagnostics. Report-building
  errors (technical) still skip the stale-cache fallback.
- market.rs: quotes, history (history_source is resolved first so the
  CLI's fallback note keeps its position), and a typed screener
  (ScreenFilter/ScreenRegion with the same error messages).
- financial.rs: profile, statements, earnings, sentiment, insights,
  news, with StatementFilter/EarningsFilter.
- analysis: TechnicalReport moves to analysis::report; Analysis offers
  technical, growth, valuation, risk, fundamental, and compare.
- CoreConfig::load() owns provider/exchange/TTL settings from
  config.toml and IDX_*; the CLI's IdxConfig adds output and color.
  With two different invalid settings at once, the reported one may
  differ from before; every single-error message is unchanged.
- Cache gains fresh/any/offline accessors returning fetch metadata.

Unit tests moved with their code (core 157 -> 168, CLI 17 -> 7). All
143 goldens unchanged; live A/B against main: 16/16 stocks identical.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
hermes 2026-10-14 09:41:31 +00:00
commit 86cb1b4b7c
16 changed files with 1613 additions and 1301 deletions

View file

@ -4,16 +4,18 @@
The repo is a Cargo workspace with one shared version:
- `crates/idx-core` (library): providers (`api/`), `analysis/`, `cache`, config
file handling and provider selection (`config`), `ownership/` (SQLite, parsers,
discovery, snapshot sync), `error`, and `runtime` (quiet/info/warn). It owns the
shared test fixtures in `tests/fixtures/`.
- `crates/idx-core` (library): the `Idx` entry point with `market()`,
`financial()`, and `analysis()` (cache policy and `Fetched<T>` in `client.rs`),
providers (`api/`), `analysis/`, `cache`, `config` (`CoreConfig`),
`ownership/` (SQLite, parsers, discovery, snapshot sync), `error`, and
`runtime` (quiet/info/warn). It owns the shared test fixtures in
`tests/fixtures/`; the fixture-backed mock provider needs the `testing` feature.
- `crates/idx-cli` (binary `idx`): clap commands (`cli/`), output format and
color resolution (`config.rs`, `IdxConfig`), and rendering (`output/`). Its
`tests/` hold the CLI integration and golden output suites.
Some fetch/cache orchestration still lives in `crates/idx-cli/src/cli/` until
phase 3 of `docs/DESIGN.md` moves it into idx-core.
Ownership import/sync orchestration still lives in
`crates/idx-cli/src/cli/ownership.rs` until phase 3c of `docs/DESIGN.md`.
## Domain Map