# Pass 1 — Instrumentation Only (Mission 001 Standard)

## Goal

Collect **keys-only / counts-only** evidence about YouTube continuation response shapes so we can patch the parser with confidence.

This pass **must not** change parsing logic (no extractor refactors, no new parsing branches).
Only add safe instrumentation and tiny helpers that compute **counts/booleans/keys**.

## Scope rules (hard guardrails)

Allowed file changes:
- `src/content/content_bridge.js` (primary)
- `antigravity/TESTING.md` (only if test steps need a small update)

Not allowed:

- `manifest.json` changes
- Permission/host-permission changes
- New network calls (beyond existing YouTube calls)
- Full payload logging / dumping JSON / logging tokens verbatim
- Parser refactors (that is Pass 2)

## Deliverables

1) One commit on branch `mission-001-continuations`:
   - **Commit message:** `Pass 1: continuation instrumentation (keys/counts only)`
2) Debug reports captured via popup Debug panel for:
   - Watch Later (`list=WL`)
   - One large normal playlist (`list=PL...`)
3) A short written summary in `antigravity/NOTES.md` (or PR description):
   - Which container(s) actually contain continuation items
   - Where the next continuation token appears
   - Whether `frameworkUpdates.entityBatchUpdate.mutations` is present and non-empty

---

## Response-shape inventory (what we must plan to support)

Current code must be expanded to support:

- `onResponseReceivedActions` (array of actions)
- `appendContinuationItemsAction.continuationItems` (standard)
- `reloadContinuationItemsCommand.continuationItems` (reload)
- `updateSectionListContinuation` (section-level update)
- `frameworkUpdates.entityBatchUpdate.mutations` (entity based)

Pass 1 confirms which of these are present **in your account/session**.

---

## Instrumentation requirements (exact)

### A) Continuation payload inventory (one log line per continuation response)

Add this **keys-only** log inside `extractItemsAndContinuationFromBrowseResponse(respJson)`:

- `rootKeys`: `Object.keys(respJson)`
- `hasContinuationContents`: boolean
- `hasFramework`: boolean
- `actionCount`: `respJson.onResponseReceivedActions?.length ?? 0`
- `firstActionKeys`: keys of the first action object (array of strings), limited to 12 max
- Counts found anywhere in the payload (deep scan; counts only):
  - `appendContinuationItemsActionCount`
  - `reloadContinuationItemsCommandCount`
  - `updateSectionListContinuationCount`
  - `continuationItemsArrayCount` (number of arrays discovered at `.continuationItems`)
  - `playlistVideoRendererCount`
  - `richItemRendererCount`
  - `continuationItemRendererCount`
  - `mutationCount` (`frameworkUpdates.entityBatchUpdate.mutations.length` if present else 0)
- Token/tracking presence (do NOT log values):
  - `hasNextToken`: boolean
  - `nextTokenLen`: number (length only)
  - `hasClickTrackingParams`: boolean
  - `clickTrackingParamsLen`: number (length only)

**No token strings. No request bodies. No full action objects.**

Example structure to log (do not copy tokens, only lengths):

```js
dbg("continuation payload inventory", {
  rootKeys,
  actionCount,
  firstActionKeys,
  hasFramework,
  hasContinuationContents,
  appendContinuationItemsActionCount,
  reloadContinuationItemsCommandCount,
  updateSectionListContinuationCount,
  continuationItemsArrayCount,
  playlistVideoRendererCount,
  richItemRendererCount,
  continuationItemRendererCount,
  mutationCount,
  hasNextToken,
  nextTokenLen,
  hasClickTrackingParams,
  clickTrackingParamsLen
});
```

## B)

### onResponseReceivedActions

### action-key enumeration (keys-only)

If onResponseReceivedActions exists, log **just the keys** of the first 1–2 action objects:

- onResponseReceivedActions[0] keys: [...]
- onResponseReceivedActions[1] keys: [...] (if present)

Limit to 12 keys per action.

### C) Alerts (safe)

If respJson.alerts exists, log:

- alert text strings only (already safe)
- do not log full alert objects

---

## Where to add logs (recommended)

- Inside extractItemsAndContinuationFromBrowseResponse(respJson)
- Only triggered during continuation fetch handling (not on every UI render)

---

## Acceptance criteria for Pass 1 (done means done)

Pass 1 is complete when the Debug reports clearly answer:

1. Which continuation container is actually used in your failing responses?
    - appendContinuationItemsAction top-level?
    - onResponseReceivedActions[*].appendContinuationItemsAction?
    - onResponseReceivedActions[*].updateSectionListContinuation?
    - entity/mutation based?
2. Where is the **next continuation token** discovered?
    - continuationItemRenderer inside continuationItems?
    - continuationContents?
    - action-level continuation?
3. Do we need entity parsing?
    - mutationCount > 0 and playlistVideoRendererCount == 0 strongly suggests entity-driven results.

---

## Next step (Pass 2)

After Pass 1 logs confirm the true shape, proceed to:

**Pass 2 — Parser refactor**

- implement a unified extractor based on the confirmed shape(s)
- keep only one summary log line per page (reduce noise)
- do not add new permissions