clipwright/PLAN.md

266 lines
11 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# clipwright — YouTube Growth Roadmap
Working plan for evolving clipwright into the packaging/clipping engine for two
channels. **No code has been written yet.** This document is the agreed spec.
Related: `/home/pbento/Projects/cadence/PLAN.md` (the long-form editor side).
---
## Context
Two channels, neither monetized. Goal is growth (reach + subs), not AdSense yet.
| Channel | Niche | Subs | Notes |
|---|---|---|---|
| cseea | Retro Minecraft / Alpha | 10 | Shorts-feed driven (95%+). Mobile 72%. |
| Pedro Bento | Low-level systems (C/Linux/engines) | 59 | Long-form; Browse vs Suggested split. |
**Pipeline:** raw OBS recording → **cadence** (silence/filler edit + transcript)
→ Kdenlive render (master) → **clipwright** (moments + reframe + captions +
packaging) → **Postiz** (publish).
### Data findings that drive this plan
- **cseea:** Shorts feed is ~95% of discovery. Second distribution waves come
from *glitches / quirks / mechanics* with high loop rate + evergreen search
interest. Best Short hook = visual impossibility at frame 0. Long-form is
search-only with 0–0.83% CTR.
- **Pedro:** Browse = volume at **1.45% APV (1m31s)**; Suggested = few views at
**16.67% APV (14m12s)**. The first 90s is the leak. Mobile = clicks, desktop =
watch time. Editor recorded 1440p maximized.
- **Packaging is the cseea bottleneck:** two Shorts had 95%+ APV but <39%
"stayed to watch" — great content, weak first frame.
### Design rules
1. **Profiles are the schema root.** Machine-readable rules only; prose is
ignored by LLMs.
2. **Validate generated text, then re-ask once.** Shared helper for #2a and #3.
3. **Serialize edits to `layouts/reframe_v2.py`** (#2b and #7 both touch it).
4. **Never honor remote manifest paths** (arbitrary file read).
---
## Items
### #1 — Per-channel profiles (schema root) · M · no deps
Define `channels/<slug>.json` and thread `--channel <slug>` / `CHANNEL_PROFILE`
through the job subprocess (pattern already at `api/app.py:2145-2160`).
v0 fields (machine-readable):
- `language`, `tone`
- `title_rules`: `max_chars`, `mobile_chars`, `banned_patterns`,
`keyword_position`, `number_policy`, `required_signal`
(consequence/curiosity), `banned_openers` (task-descriptive)
- `hook_patterns`, `hook_style`
- `description_template`, `links`
- `thumbnail`: `role_order`, `palette`, `presenter_photo`
- `default_postiz_integration_id`
- `published_video_history`
Drives: #3, #4, #6, selection/hook style, #10 provenance.
**Files:** new `pipeline/profiles.py`; `api/app.py` (ProcessRequest + env,
`layout_env`); `media/thumbnail.py`; `pipeline/gemini_worker.py`;
`dashboard/src/components/MediaInput.jsx`.
**Verify:** loader unit tests; `--channel cseea` vs `--channel pedro` produce
visibly different prompts/titles.
---
### #2 — Words drive edits (hook-first boundaries + word punch-ins) · M
Merge the two sub-items; both need clip-relative word timings in the renderer.
**2b — word-aligned punch-ins.** Pass clip-relative word timings into
`punch_in.emphasis_times()` (today audio-envelope only — gap flagged at
`layouts/punch_in.py:17-20`). One call-site change in `layouts/reframe_v2.py`
+ threading in `pipeline/main.py` `_process_one_clip`.
**2a — hook-first boundaries.** Deterministic `find_hook_start` over word
timestamps (question / number / imperative / "segfault"), snap clip start, trim
wind-up; integrate with `snap_clip_to_words` (`pipeline/clip_selection.py:288`)
and `trim_to_best` (`:132`) inside `get_viral_clips` (`pipeline/main.py:1743`).
**Why:** attacks cseea's 57–80% swipe and Pedro's "85% gone by 1:08".
**Files:** `layouts/punch_in.py`, `layouts/reframe_v2.py`,
`pipeline/clip_selection.py`, `pipeline/main.py`.
**Verify:** unit tests for `find_hook_start`; existing proposed-vs-snapped log
(`main.py:1874`); `tools/verify_aesthetic.py`.
> Serialize with #7 on `reframe_v2.py`. Do 2b first (one line), then #7's loop.
---
### #3 + #4 — Packaging QA (merged) · M · depends on #1
**#3 title validator + retry.** Deterministic checks on the generated title
(length, ≤3 same first word, ≤2 colons, **must** contain consequence/curiosity
signal, **reject** task-descriptive openers); one re-ask on failure. Applied
after `analyze_video_for_titles` (`media/thumbnail.py:65`) and
`api/free_tools.shape_result()` (`:546`).
**#4 thumbnail concept roles.** Add `role: emotion | technical | curiosity` to
`plan_thumbnail_concepts` (`media/thumbnail.py:388`); enforce ≥1 of each in
`normalise_concepts` (`:422`); persist variants; return a recommended pick.
Enforce the **bottom-right safe area** in `burn_thumbnail_text` (`:462`).
**A/B reality:** automated A/B is not available via API. YouTube **Test &
Compare** is Studio-only but has *no view minimum* (only "advanced features") —
check Studio eligibility manually.
**Shared:** build `run_with_validation(generate, validate, retry_once)` once,
reused by #2a and #3.
**Files:** `media/thumbnail.py`, `api/free_tools.py`, `pipeline/gemini_worker.py`
prompts, thumbnail session API.
**Verify:** unit tests for the validator; `tools/verify_hooks.py`,
`tools/verify_aesthetic.py`.
---
### #6 — Shorts → long-form bridge · M · depends on #1
**API reality (verified):** the Shorts "Related video" link and comment pinning
are **not exposed by any API** (Studio-UI only). Postiz has `comments: false`.
Postiz **can** set a custom YouTube thumbnail.
Deliver:
1. Per-Short **description text** + **first-comment text** generated from the
profile + `published_video_history`.
2. Optional new YouTube Data API OAuth integration
(`integrations/youtube_data.py`) to auto-post the first comment
(`commentThreads.insert`, scope `youtube.force-ssl`, 50 units ≈ 200/day cap).
3. A copy-paste **Studio checklist** per Short (related-video target + pin).
**Files:** `api/app.py` publish region, new `integrations/youtube_data.py`,
clip metadata in `pipeline/main.py:2255-2264`, `dashboard/.../ResultCard.jsx`.
**Verify:** post a first comment on an unlisted test video; confirm pin remains
manual.
---
### #7 — CODE / TERMINAL vertical layout · L · independent
New `layouts/code_layout.py`, following the `camera_inset.py` pattern (module
`ENABLED`, detector → geometry, pure `code_filtergraph()`).
**Detector:** edge/row-column projection for the pane; temporal-stability gate;
editor-vs-terminal classification; optional `active_line_series` via frame
differencing. Fall back to SCREENCAST/WIDE when scale < `CODE_MIN_SCALE` (0.75).
At 1440p maximized this fallback should rarely trigger.
**Filtergraph:** `crop pane → scale out_w → overlay on blurred backdrop`;
optional face band; `sendcmd` scroll-follow for tall panes. Captions stay in the
bottom reserve.
**Wiring:** precedence in `layouts/reframe_v2.py` render after SPLIT/ALTERNATE,
before the screencast loop; `layouts/layout_picker.py` `DECISION_FLAGS` +
`api/app.py` `LAYOUT_ENV`; **add `"code"` to `hook_grounding.SCREEN_LAYOUTS`**
or code clips get topic-summary hooks.
Flags: `CODE_LAYOUT`, `CODE_FOLLOW`, `CODE_ZOOM`, `CODE_MIN_SCALE`,
`CODE_CAMERA_BAND`. Keep the count low; thresholds env-overridable.
**Also fix (bug found in review):** `content_ranges` is a **dead wire** —
SCREENCAST/WIDE/INSET upgrades gate on it (`reframe_v2.py:446-478`) but no
production caller passes it (`main.py:1332-1337`). Fix in the same PR. Do **not**
copy the `content_ranges` pattern for CODE; follow
`split_layout.detect_split_scenes` (self-detecting).
**Files:** new `layouts/code_layout.py`; `layouts/reframe_v2.py`,
`layouts/layout_picker.py`, `layouts/hook_grounding.py`, `api/app.py`,
`pipeline/gemini_worker.py` (picker prompt), `pipeline/main.py`.
**Verify:** `tests/test_code_layout.py` (pure), pipeline e2e precedence test,
`tools/verify_code_layout.py` on real recordings (thresholds need corpus tuning).
> Serialize with #2b on `reframe_v2.py`.
---
### #8 — cadence → clipwright handoff (clipwright ingest side) · S
Adapter side only. The emitter and schema live in
`/home/pbento/Projects/cadence/PLAN.md`.
- CLI: `python -m clipwright.pipeline.main -i master.mp4 --handoff
cadence.handoff.json -o out/` — load manifest; load `transcript.path` relative
to the manifest; **run `merge_continuation_words` on every segment's words on
load**; validate master duration ±1%; pass hints into `get_viral_clips`.
- Reuse the existing `--transcript` machinery (`pipeline/main.py:2033`,
`:2190-2200`).
- API: accept an uploaded `handoff_id` bundle and the master via the existing
`/api/uploads` PUT flow; write the transcript into the job dir like
`api/app.py:2239-2243`; append `--handoff`.
- **Never honor `sources[].path` from a remote manifest** (CLI-local only).
**v1:** transcript + manifest + master. Cut-from-sources deferred.
**Verify:** manifest validation unit test; tiny-video `--handoff` e2e.
---
### #10 — Retention instrumentation now, loop later · S now / L later · depends on #1
Verified: Analytics API gives retention curve (`elapsedVideoTimeRatio`), AVD/APV,
traffic sources, device, geo, subs — but **not** impressions/CTR (Studio-only).
Auth needs `youtube.readonly` + `yt-analytics.readonly`; service accounts do not
work (real-channel OAuth).
**Now:** record provenance on every clip — profile slug, validator/formula
version, chosen role, `predicted_score`, hook source, publish target. This makes
the future loop a data pull, not a re-architecture.
**Later:** build the learning loop once a channel has ~30+ published clips.
**Files:** `pipeline/main.py` metadata, `api/app.py`.
---
## Suggested build order
**Phase A — independent, high-visibility (serialize `reframe_v2.py`):**
1. #2b word-aligned punch-ins
2. #7 CODE layout (minimal) + SCREENCAST dead-wire fix
3. #1 v0 profiles (schema + env only)
**Phase B — backbone:**
4. #8 handoff ingest
5. #2a hook-first boundaries
6. #1 full (API + dashboard + publish defaults)
**Phase C — packaging:**
7. #3 + #4 packaging QA
8. #6 first-comment bridge + checklist
**Phase D — optional:**
9. #10 instrumentation now, loop later.
## Deferrals / cuts
- Automated retention loop (#10) — instrument only.
- Loudness (#9) — cadence-side; belongs in MLT/Kdenlive, see cadence PLAN.
- Candidate hook/title generation in cadence — keep cadence single-file,
no-network.
- Auto-pin comments (#6) — not exposed by the API.
## File-ownership conflicts (serialize)
- `layouts/reframe_v2.py`: #2b vs #7
- `media/thumbnail.py`: #1 / #3 / #4
- `pipeline/gemini_worker.py` prompts: #1 / #2 / #3 / #6 / #7 — batch per phase
- `api/app.py`: #1 / #6 / #7 / #8 / #10 — different regions; one owner late
## Open items
- Confirm Studio "Test & Compare" eligibility (advanced features; no view min).
- Corpus-tune #7 thresholds against real 1440p recordings before enabling the
picker default.