# ThreatFeedAlgo v2 — How THE FEED Decides What You See

**Published by THREATSPHERE for study, 2026-11-25.**
This is the actual recommendation algorithm that orders THE FEED at
<https://www.thethreatwire.com/feed/> — not a simplified copy. The file
`threatfeed-algo.js` on this page was extracted verbatim from the live feed
page source: the core algorithm script, the dwell-scoring function, and the
explicit-action handlers, byte for byte. Only the header comment and section
banners were added.

## The one-sentence version

ThreatFeedAlgo is a **client-side recommender**: it runs entirely in the
visitor's browser, keeps the visitor's taste profile in that browser's
`localStorage`, and never sends a viewing profile to a server. There is no
account, no tracking pixel, and no backend model. If you clear your browser
storage, the algorithm forgets you completely — because it never knew you
anywhere else.

## How it works, step by step

### 1. Everything becomes a FeedItem

YouTube videos, TikTok clips, community uploads and Internet Archive films
are normalized into one schema: `id`, `sourceType`, `title`, `category`,
`tags`, `downloads`, `popularity`, plus display fields. Tags are extracted
from the title/caption: the item's own hashtags are kept, and the text is
matched against a fixed topic vocabulary (`TAGWORDS` — defcon, malware,
phishing, osint, ransomware, darkweb, retro, …), capped at 8 tags per item.
Categories are one of: Serious, Funny, Documentaries, Talks, Retro (and
Edits for TikTok clips).

### 2. Signals: what you do becomes weights

Every signal adjusts the weight of **every tag on the item and its
category**, stored in your profile. Category adjustments count the same as
tag adjustments when applied; when affinity is read back, the category
weight is multiplied by 1.5 (see §4).

**Dwell time** (measured when a card leaves the screen, after being the
active card; activation requires ~65% of the card visible):

| Time on card | Signal |
|---|---|
| Under 2.5 seconds | **−2** (fast skip — probably not for you) |
| 2.5 – 8 seconds | 0 (no signal — not enough evidence) |
| 8 – 25 seconds | **+2** (a real watch) |
| Over 25 seconds | **+5** (a strong watch) |

**Explicit actions:**

| Action | Signal |
|---|---|
| Boost (▲) | **+6** |
| Save (★) | **+8** |
| Share (any share target, or copy link) | **+10** |
| Not Interested (✕) | **−10**, plus the item is marked seen and upcoming queue items sharing ≥2 tags (or a title word) are pulled from your queue |
| Tapping a #tag on a card | +2, and the feed switches to that tag |

### 3. The scoring formula

Every candidate is scored as:

```
score = affinity × 0.65  +  popularity × 0.20  +  random × jitterWeight
```

- **affinity** — the sum of your profile weights for the item's tags, plus
  1.5 × your weight for its category, floored at 0 (negative taste never
  pushes an item below the popularity baseline).
- **popularity** — for Archive items with download counts:
  `log10(1 + downloads) / log10(1 + maxDownloads)` across the pool, so the
  most-downloaded item scores 1.0 and the scale is logarithmic. Items
  without download counts carry a fixed editorial popularity (0.3 default;
  0.45 YouTube catalog, 0.5 TikTok, 0.62 community uploads, 0.85 seed films).
- **jitter** — deliberate randomness so the feed never becomes a frozen
  ranked list. `jitterWeight` is **0.15** in steady state and boosted to
  **0.35 for the session's first 20 picks**, so a fresh visit opens with
  variety before your profile takes over. (Note: summaries of this
  algorithm sometimes quote "jitter × 0.15" — that is the steady-state
  weight; the code, which is authoritative, boosts it to 0.35 during the
  opening.)

### 4. Blending: the 70 / 20 / 10 batch

The queue is extended in batches of 10 (`blendBatch`):

| Slots | Source |
|---|---|
| 7 | **Affinity** — the highest-scored unseen items |
| 2 | **Discovery** — cross-source items ranked by downloads/popularity, preferring items whose tags are *not* already among your top tags with weight > 4 (so discovery actually crosses topics) |
| 1 | **Wildcard** — a random unseen item, preferring a deep Archive.org item |

If a batch can't be filled, remaining slots fall back to the scored list.

### 5. The opening: a fresh shuffle every visit

The first 10 cards are **not** the top-10 by score. They are a
session-seeded shuffle (`mulberry32` PRNG, new random seed every page
load) of the fresh (unseen) pool, with community uploads pinned first and
3–4 Archive films spliced into positions 3–10 as the Archive river lands.
Cards 11+ are score-ordered under the boosted opening jitter. That is why
the feed opens differently on every visit instead of greeting you with the
same videos.

### 6. Seen-tracking and reshuffle

- A card that stays active for ~1 second joins your seen history
  (`ts_feed_seen_v2`), so later visits open with different cards.
- Your own added videos and anything you Saved are **exempt** — they never
  rotate away.
- Unseen items are always preferred. When **every** item in the pool has
  been seen, the seen set for that pool is cleared and the full pool
  reshuffles — "the wire never stops." No repeats until the pool is
  exhausted.
- The Archive pool itself is endless: four Archive.org search endpoints
  (cyber subjects, hacker-conference titles, espionage/surveillance
  subjects, Computer Chronicles) are paged in the background whenever
  unseen items run low.

### 7. Modes

Filter pills re-run the same machinery on a subset: For You (all),
Serious, Funny, Docs & Talks (Documentaries + Talks), Saved, and per-tag
mode. Non-For-You modes sort unseen items purely by score.

## localStorage schema

| Key | Shape | Meaning |
|---|---|---|
| `ts_feed_algo_v2` | `{ "tags": {tag: weight}, "cats": {category: weight} }` | Your taste profile. Weights are plain numbers, positive or negative. |
| `ts_feed_seen_v2` | `[itemId, …]` | Everything you've been shown (~1s active). Drives no-repeat rotation. |
| `ts_feed_saved_v2` | `[itemId, …]` | Your Saved list (also mirrored to legacy key `tsFeedSaved`). |
| `ts_feed_user_items_v1` | `[rawItem, …]` | Videos you added yourself; pinned at the top of your feed. |
| `tsFeedSound` | `"on"` / `"off"` | Sound preference (not part of the profile). |
| `tsFeedTheme` | `"auto"` / `"dark"` / `"light"` | Feed theme preference. |

You can inspect your own profile any time in the feed's **ThreatFeedAlgo
tuning drawer**, and wipe it with **Reset Algo & History** (deletes
`ts_feed_algo_v2` and `ts_feed_seen_v2`).

## How to run / study it

1. Download `threatfeed-algo.js` from this page.
2. The file is the production code, written for the feed page: it expects
   the feed's catalog globals (`RAW_YT`, `RAW_TT`, `SEEDS`), a DOM, and
   `localStorage`. To study the math in isolation, lift `applySignal`,
   `affinity`, `score`, `blendBatch`, `mulberry32`/`shuffleSeeded` and the
   dwell table in `deactivate()` — they depend only on `profile`, `S`, and
   the pool arrays.
3. Or just open <https://www.thethreatwire.com/feed/>, watch a few videos,
   boost/save/skip, then open the tuning drawer and your browser's
   localStorage inspector side by side — every number on this page is one
   you can watch change.

## Honest limits

- This is a **ranking heuristic, not machine learning**. No embeddings, no
  collaborative filtering — with no server, there is nobody else's data to
  collaborate with. That is the privacy trade, made on purpose.
- Popularity for non-Archive items is an editorial constant, not a live
  view count.
- The profile is per-browser, per-device. It does not follow you — by
  design.
