S1-6: CLI on a shared core (#11) #48

Merged
chris-kreidl merged 2 commits from 11-cli into main 2026-11-11 19:45:09 +00:00
chris-kreidl commented 2026-11-11 16:38:18 +00:00 (Migrated from github.com)

🤖 Claude: Closes #11

The CLI (built with @clack/prompts, which Chris asked for)

  • bun cli.ts asks which steps to run. The multiselect has all four steps preselected, and each step's hint shows its current state: when the SEC data was last downloaded, how many companies are in the DB, how many companies enrich will price and about how long it will take, and when the CSV was last written. Ctrl-C exits with "Nothing run."
  • bun cli.ts analyze rank runs the named steps without asking. Steps always run in pipeline order. An unknown step, or no steps without a terminal (e.g. in CI), prints usage and exits 1. --help prints usage.
  • Each step shows a progress bar with an elapsed-time timer and then a one-line summary (analyze also warns about files it couldn't read). Rank ends with a top-10 table, and the session ends with the total time.
┌  screener · Magic Formula
◇  Analyze 10-Ks
◇  Analyzed 20550 filers [54s]
●  5455 with a 10-K from the last 13 months, 15095 older · 3660 have ROTC
◇  Rank
◇  Top 10 of 1391 ───────────────────────────────╮
│   #  Ticker  Company                    ROTC   EY │
│   1  ATRA    ATARA BIOTHERAPEUTICS, …   …       … │
├──────────────────────────────────────────────────╯
◆  Wrote magic_formula_ranked.csv
└  Done in 1 min

Structure

  • Each step is a function in src/ (refresh, analyze, enrich, rank). It reports progress through a small Reporter interface (src/report.ts) and returns a result, such as counts or the ranked list. Only cli.ts prints anything. Tests pass silent.
  • The four top-level scripts are gone. Three were moved into src/ (git shows renames), and the analyze loop joined analyzeCompany in src/analyze.ts. package.json scripts call the CLI; bun run export is now bun run rank.
  • Consolidations: the table schema and its migrations were in both analyze and enrich and now live once in src/db.ts. The SEC request headers now live once in src/sec.ts. Ranking is split into the pure rankCompanies and toCsv.
  • bun fmt on the whole repo. The only content-free changes are in the old refresh-data.ts and .github/workflows/claude-code-review.yml (quote style).
  • New dependency: @clack/[email protected].

No change to the data or the ranking is intended.

Definition of Done

  • Acceptance criteria met and demonstrated
    • The CLI runs refresh | analyze | enrich | rank, each a thin wrapper over src/
    • The old scripts are removed and package.json points to the CLI
    • The pipeline produces the CSV: on real data, bun cli.ts analyze rank gives a magic_formula_ranked.csv (1,391 companies) that is byte-identical to the old analyze.ts + export-ranking.ts run on the same data. The database was also identical after the first commit's run.
    • bun check and bun fmt --check . pass on the whole repo
  • bun test passes; new logic has tests: 204 pass, 0 fail. New: test/rank.test.ts (rank order, ties, eligibility filter, CSV escaping, live-market-cap EY from a DB), test/db.test.ts (migrating an old table), test/cli.test.ts (help, unknown step, no terminal), and analyze-step tests over the fixtures (upsert keeps the enrichment columns; stale filings are skipped; an unreadable file is reported but doesn't stop the run)
  • bun check is clean and bun fmt --check passes: no type errors in 25 files; all 35 files are formatted
  • Runs end to end on real data: analyze and rank ran on real data in a pseudo-terminal, and the interactive menu was rendered and cancelled there. refresh and enrich have not run since the move. Enrich is about 28 min (1,680 companies at 1 request/s), and refresh downloads the full SEC dataset.

🤖 Generated with Claude Code

🤖 **Claude:** Closes #11 **The CLI** (built with `@clack/prompts`, which Chris asked for) - `bun cli.ts` asks which steps to run. The multiselect has all four steps preselected, and each step's hint shows its current state: when the SEC data was last downloaded, how many companies are in the DB, how many companies enrich will price and about how long it will take, and when the CSV was last written. Ctrl-C exits with "Nothing run." - `bun cli.ts analyze rank` runs the named steps without asking. Steps always run in pipeline order. An unknown step, or no steps without a terminal (e.g. in CI), prints usage and exits 1. `--help` prints usage. - Each step shows a progress bar with an elapsed-time timer and then a one-line summary (analyze also warns about files it couldn't read). Rank ends with a top-10 table, and the session ends with the total time. ``` ┌ screener · Magic Formula ◇ Analyze 10-Ks ◇ Analyzed 20550 filers [54s] ● 5455 with a 10-K from the last 13 months, 15095 older · 3660 have ROTC ◇ Rank ◇ Top 10 of 1391 ───────────────────────────────╮ │ # Ticker Company ROTC EY │ │ 1 ATRA ATARA BIOTHERAPEUTICS, … … … │ ├──────────────────────────────────────────────────╯ ◆ Wrote magic_formula_ranked.csv └ Done in 1 min ``` **Structure** - Each step is a function in `src/` (`refresh`, `analyze`, `enrich`, `rank`). It reports progress through a small `Reporter` interface (`src/report.ts`) and returns a result, such as counts or the ranked list. Only `cli.ts` prints anything. Tests pass `silent`. - The four top-level scripts are gone. Three were moved into `src/` (git shows renames), and the analyze loop joined `analyzeCompany` in `src/analyze.ts`. `package.json` scripts call the CLI; **`bun run export` is now `bun run rank`**. - Consolidations: the table schema and its migrations were in both analyze and enrich and now live once in `src/db.ts`. The SEC request headers now live once in `src/sec.ts`. Ranking is split into the pure `rankCompanies` and `toCsv`. - `bun fmt` on the whole repo. The only content-free changes are in the old `refresh-data.ts` and `.github/workflows/claude-code-review.yml` (quote style). - New dependency: `@clack/[email protected]`. No change to the data or the ranking is intended. ### Definition of Done - [x] Acceptance criteria met and demonstrated - The CLI runs `refresh | analyze | enrich | rank`, each a thin wrapper over `src/` - The old scripts are removed and `package.json` points to the CLI - The pipeline produces the CSV: on real data, `bun cli.ts analyze rank` gives a `magic_formula_ranked.csv` (1,391 companies) that is **byte-identical** to the old `analyze.ts` + `export-ranking.ts` run on the same data. The database was also identical after the first commit's run. - `bun check` and `bun fmt --check .` pass on the whole repo - [x] `bun test` passes; new logic has tests: 204 pass, 0 fail. New: `test/rank.test.ts` (rank order, ties, eligibility filter, CSV escaping, live-market-cap EY from a DB), `test/db.test.ts` (migrating an old table), `test/cli.test.ts` (help, unknown step, no terminal), and analyze-step tests over the fixtures (upsert keeps the enrichment columns; stale filings are skipped; an unreadable file is reported but doesn't stop the run) - [x] `bun check` is clean and `bun fmt --check` passes: no type errors in 25 files; all 35 files are formatted - [x] Runs end to end on real data: **analyze and rank ran on real data in a pseudo-terminal**, and the interactive menu was rendered and cancelled there. **refresh and enrich have not run since the move.** Enrich is about 28 min (1,680 companies at 1 request/s), and refresh downloads the full SEC dataset. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
socket-security[bot] commented 2026-11-11 16:50:14 +00:00 (Migrated from github.com)

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Added@​clack/​prompts@​1.9.010010010096100

View full report

**Review the following changes in direct dependencies.** Learn more about [Socket for GitHub](https://socket.dev?utm_medium=gh). <table> <thead> <tr> <th>Diff</th> <th width="200px">Package</th> <th align="center" width="100px">Supply Chain<br/>Security</th> <th align="center" width="100px">Vulnerability</th> <th align="center" width="100px">Quality</th> <th align="center" width="100px">Maintenance</th> <th align="center" width="100px">License</th> </tr> </thead> <tbody> <tr><td align="center"><a href="https://socket.dev/dashboard/org/chris-kreidl/diff-scan/f12f80d7-1e94-4382-8da3-6ea88a17a096?tab=dependencies&dependency_item_key=101973647595"><img src="https://github-app-statics.socket.dev/diff-added.svg" title="Added" alt="Added" width="20" height="20"></a></td><td><a href="https://socket.dev/dashboard/org/chris-kreidl/diff-scan/f12f80d7-1e94-4382-8da3-6ea88a17a096?tab=dependencies&dependency_item_key=101973647595">@​clack/​prompts@​1.9.0</a></td><td align="center"><a href="https://socket.dev/dashboard/org/chris-kreidl/diff-scan/f12f80d7-1e94-4382-8da3-6ea88a17a096?tab=dependencies&dependency_item_key=101973647595"><img src="https://github-app-statics.socket.dev/score-100.svg" title="Supply Chain Security" width="40" height="40" alt="100"></a></td><td align="center"><a href="https://socket.dev/dashboard/org/chris-kreidl/diff-scan/f12f80d7-1e94-4382-8da3-6ea88a17a096?tab=dependencies&dependency_item_key=101973647595"><img src="https://github-app-statics.socket.dev/score-100.svg" title="Vulnerability" width="40" height="40" alt="100"></a></td><td align="center"><a href="https://socket.dev/dashboard/org/chris-kreidl/diff-scan/f12f80d7-1e94-4382-8da3-6ea88a17a096?tab=dependencies&dependency_item_key=101973647595"><img src="https://github-app-statics.socket.dev/score-100.svg" title="Quality" width="40" height="40" alt="100"></a></td><td align="center"><a href="https://socket.dev/dashboard/org/chris-kreidl/diff-scan/f12f80d7-1e94-4382-8da3-6ea88a17a096?tab=dependencies&dependency_item_key=101973647595"><img src="https://github-app-statics.socket.dev/score-96.svg" title="Maintenance" width="40" height="40" alt="96"></a></td><td align="center"><a href="https://socket.dev/dashboard/org/chris-kreidl/diff-scan/f12f80d7-1e94-4382-8da3-6ea88a17a096?tab=dependencies&dependency_item_key=101973647595"><img src="https://github-app-statics.socket.dev/score-100.svg" title="License" width="40" height="40" alt="100"></a></td></tr> </tbody> </table> [View full report](https://socket.dev/dashboard/org/chris-kreidl/diff-scan/f12f80d7-1e94-4382-8da3-6ea88a17a096?tab=dependencies) <!-- overview-comment -->
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
ckreidl/screener!48
No description provided.