# Tasks — NSE Deep Research Engine (v1)

Each task = one Claude Code session's worth of work. Mark done only after the listed verification passes.

## Phase 1A — Foundation
- [ ] **T01** Scaffold repo: TypeScript + Fastify + Prisma project at /root/nse-research per design.md §1; `.env.example`; Prisma schema from design.md §2; `prisma migrate dev` creates database `nse_research`; git init + first commit. *(Req 8.2)*
  - Verify: `npx prisma studio` shows all tables; `npm run build` clean.
- [ ] **T02** `lib/tradingDay.ts` + NseHoliday seed (2026 NSE holiday list) + `lib/telegram.ts` with PublishedBrief dedup + error-alert helper. Unit tests for tradingDay. *(Req 1.5, 6.4, 6.5)*
  - Verify: test suite passes; manual `npm run job:test-telegram` sends and dedups.
- [ ] **T03** `lib/angelone.ts`: TOTP login, instrument master load, LTP + candle fetch with 3req/s throttle. *(Req 1.1, 1.4)*
  - Verify: script fetches RELIANCE last 30 daily candles and prints them.
- [ ] **T04** Universe sync: Nifty500 + F&O list → Symbol table with Angel tokens, isBankNbfc flag from sector. *(blueprint scope)*
  - Verify: Symbol count 500–700; spot-check 5 tokens fetch valid LTP.

## Phase 1B — Data pipeline
- [ ] **T05** `job:eod-ingest`: EOD candles for full universe → EodBar. JobRun logging. *(Req 1.1, 8.3)*
  - Verify: run for last trading day; ≥95% of universe has a bar; JobRun row ok=true.
- [ ] **T06** `lib/nse.ts` bhavcopy download (cookie bootstrap, retries) merged into eod-ingest → deliveryQty/deliveryPct populated. *(Req 1.2, 1.3)*
  - Verify: ≥90% of bars for the day have deliveryPct.
- [ ] **T07** `job:intraday-snapshot` at 2:55 PM pattern → IntradaySnapshot. *(Req 1.4)*
  - Verify: manual run during market hours populates all universe symbols in <3 min.
- [ ] **T08** NSE results calendar + announcements fetch into a ResultsCalendar table (add via migration). *(Req 3.2f)*
  - Verify: known upcoming result (check moneycontrol) appears for correct symbol/date.
- [ ] **T09** `job:fundamentals-refresh` → Fundamental rows per design §3.1/§2. *(Req 2.1–2.3)*
  - Verify: RELIANCE, HDFCBANK, TCS rows have non-null PE/ROE and 8 quarters JSON.

## Phase 1C — Scanners
- [ ] **T10** `lib/indicators.ts` with unit tests (fixtures). *(design §3.2)*
  - Verify: RSI/SMA outputs match reference values from a known dataset.
- [ ] **T11** BtstScanner + `job:btst-scan` → Recommendation rows. Config-driven weights. *(Req 3.1–3.5)*
  - Verify: dry-run on a historical date reproduces expected filter behavior; ≤5 rows; scoreDetail populated.
- [ ] **T12** SwingScanner + `job:swing-scan`. *(Req 4.1–4.5)*
  - Verify: dry-run produces ≤8 rows; fundamentals gate demonstrably excludes a loss-making symbol; OPEN-dup rule works on second run.

## Phase 1D — AI + delivery
- [ ] **T13** ResearchWriter with zod validation, retry, injected financials, deadline guard. *(Req 5.1–5.4)*
  - Verify: notes generated for 3 test candidates; malformed-JSON path exercised via forced bad prompt; note:null fallback works.
- [ ] **T14** TelegramPublisher brief formats + wiring into both scan jobs, including zero-candidate message. *(Req 6.1–6.4)*
  - Verify: full BTST pipeline manual run publishes header + per-stock notes; immediate re-run sends nothing.
- [ ] **T15** OutcomeTracker: `job:evaluate-outcomes` + `job:weekly-summary`. *(Req 7.1–7.4)*
  - Verify: seed a fake yesterday-BTST rec, run job, Outcome row correct HIT/MISS math; weekly summary message renders.

## Phase 1E — Operations
- [ ] **T16** Fastify server (/health, /jobs/:name/run with bearer token) + systemd unit. *(Req 8.1)*
  - Verify: `curl localhost:4300/health` shows per-job status; unauthorized trigger returns 401.
- [ ] **T17** Install crontab entries per design §3.8 (after timezone check); end-to-end live day observed: 2:55 snapshot → 3:00 scan → ≤3:12 brief → 5:50 outcomes → 6:30 swing brief.
  - Verify: one full trading day passes with all JobRun ok=true and both briefs received.

## Phase 2 (later, separate spec addendum)
- Next.js dashboard: recommendations table, note pages, performance stats, filters.
