Start pipeline steps from the page, with live progress (#18) #65

Merged
chris-kreidl merged 1 commit from 18-jobs-ui into main 2026-11-13 16:43:46 +00:00
chris-kreidl commented 2026-11-13 16:35:29 +00:00 (Migrated from github.com)

🤖 Claude: Closes #18

A Pipeline panel above the rankings: each step's latest run (status, done / total and message with a progress bar, started, finished, a failed run's error), a Run button per step, and Run the whole pipeline.

How it works

  • Starting: POST /api/jobs { steps, restart? }. web.ts runs it as bun cli.ts <steps> (--restart for Start over), so a run from the page is the same run as one from the terminal: same job rows, conflict checks and checkpoints.
  • Live progress: /api/jobs/events (server-sent events) reads each step's latest jobs row every second and sends it when something changed. Because it reads the table, runs started from the CLI show up too.
  • One at a time: a step that's running, or queued in a run the page started, gets 409 and the page names it: "Analyze 10-Ks is already running (job 13, started …)" or "Rank is already queued in a run started from this page."
  • Resume or start over: clicking an interrupted refresh or enrich offers Resume it / Start over / Cancel.
  • Only the page: POST /api/jobs needs Origin: http://127.0.0.1:<port> (or localhost). If Origin is missing or belongs to another site, the request gets 403. The check is against the server's own address, not the Host header, so DNS rebinding doesn't get through.
  • Reload: when an analyze or enrich run ends, the table reloads and keeps the sector, cap, ROTC and EY filters. A rank run doesn't trigger a reload because it only writes the CSV, which the page doesn't read.
  • src/steps.ts now holds the step order, labels, and which steps resume, shared by the CLI, server and page.

Definition of Done

  • Acceptance criteria met and demonstrated, on real data at 127.0.0.1:3077:
    • Run the whole pipeline: refresh (10 new 10-Ks) → analyze (bar to 20,571 / 20,571) → enrich (16 price batches) → rank, with later steps shown as Queued. The table reloaded on its own ("Prices last updated Nov 13, 2026, 11:33 AM", new EY values).
    • Clicking Run on queued Rank, then on running Analyze, showed both messages above.
    • bun cli.ts refresh --full from a terminal showed live in the panel ("169 / 1,360 · Downloading SEC companyfacts"). After Ctrl-C it read Interrupted. Run then offered Resume it / Start over, and Start over ran a new refresh (job 17, resumes null).
    • curl: no Origin → 403, https://evil.example → 403, http://evil.example:3077 with that Host → 403, the page's origin → reaches validation.
  • bun test passes: 328 tests. New: the jobs API and event stream (test/server.test.ts), the panel in happy-dom (test/app.test.ts), web/jobs.ts (test/jobs-panel.test.ts), stopIndex (test/table.test.ts).
  • bun check is clean and bun fmt --check passes on changed files.
  • Runs end to end on real data (above).
  • Stand-up posted on #51 when the story started and when this PR opened: I missed the starting one. The ready-for-review stand-up is posted.
  • Open product questions filed as question issues and linked here: #64 (when the whole pipeline finds several interrupted steps, the page asks once for all of them; the interactive CLI asks per step).

Notes

  • The CLI's terminal output from page-started runs is discarded. Progress and errors come from the job rows, and web.ts logs a nonzero exit code.
  • If two pipeline steps' earlier runs are interrupted, the panel shows each one, but one Resume/Start over choice covers both (#64).

🤖 Generated with Claude Code

🤖 **Claude:** Closes #18 A **Pipeline** panel above the rankings: each step's latest run (status, done / total and message with a progress bar, started, finished, a failed run's error), a **Run** button per step, and **Run the whole pipeline**. ### How it works - **Starting:** `POST /api/jobs` `{ steps, restart? }`. `web.ts` runs it as `bun cli.ts <steps>` (`--restart` for Start over), so a run from the page is the same run as one from the terminal: same job rows, conflict checks and checkpoints. - **Live progress:** `/api/jobs/events` (server-sent events) reads each step's latest `jobs` row every second and sends it when something changed. Because it reads the table, runs started from the CLI show up too. - **One at a time:** a step that's running, or queued in a run the page started, gets 409 and the page names it: "Analyze 10-Ks is already running (job 13, started …)" or "Rank is already queued in a run started from this page." - **Resume or start over:** clicking an interrupted refresh or enrich offers Resume it / Start over / Cancel. - **Only the page:** `POST /api/jobs` needs `Origin: http://127.0.0.1:<port>` (or `localhost`). If Origin is missing or belongs to another site, the request gets 403. The check is against the server's own address, not the `Host` header, so DNS rebinding doesn't get through. - **Reload:** when an analyze or enrich run ends, the table reloads and keeps the sector, cap, ROTC and EY filters. A rank run doesn't trigger a reload because it only writes the CSV, which the page doesn't read. - `src/steps.ts` now holds the step order, labels, and which steps resume, shared by the CLI, server and page. ### Definition of Done - [x] Acceptance criteria met and demonstrated, on real data at `127.0.0.1:3077`: - Run the whole pipeline: refresh (10 new 10-Ks) → analyze (bar to 20,571 / 20,571) → enrich (16 price batches) → rank, with later steps shown as Queued. The table reloaded on its own ("Prices last updated Nov 13, 2026, 11:33 AM", new EY values). - Clicking Run on queued Rank, then on running Analyze, showed both messages above. - `bun cli.ts refresh --full` from a terminal showed live in the panel ("169 / 1,360 · Downloading SEC companyfacts"). After Ctrl-C it read Interrupted. Run then offered Resume it / Start over, and Start over ran a new refresh (job 17, `resumes` null). - curl: no Origin → 403, `https://evil.example` → 403, `http://evil.example:3077` with that Host → 403, the page's origin → reaches validation. - [x] `bun test` passes: 328 tests. New: the jobs API and event stream (`test/server.test.ts`), the panel in happy-dom (`test/app.test.ts`), `web/jobs.ts` (`test/jobs-panel.test.ts`), `stopIndex` (`test/table.test.ts`). - [x] `bun check` is clean and `bun fmt --check` passes on changed files. - [x] Runs end to end on real data (above). - [ ] Stand-up posted on #51 when the story started and when this PR opened: I missed the starting one. The ready-for-review stand-up is posted. - [x] Open product questions filed as `question` issues and linked here: #64 (when the whole pipeline finds several interrupted steps, the page asks once for all of them; the interactive CLI asks per step). ### Notes - The CLI's terminal output from page-started runs is discarded. Progress and errors come from the job rows, and `web.ts` logs a nonzero exit code. - If two pipeline steps' earlier runs are interrupted, the panel shows each one, but one Resume/Start over choice covers both (#64). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
claude[bot] commented 2026-11-13 16:36:21 +00:00 (Migrated from github.com)

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

🤖 Generated with Claude Code

## Code review No issues found. Checked for bugs and CLAUDE.md compliance. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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!65
No description provided.