commit 25f18031d777249ed31d1672ba552e15d8d93ab7
parent fc5f479e6e275718b5654b581fbbe485634171b5
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Wed, 11 Nov 2026 14:17:37 -0500
settings: a lookouts group — saved lookouts (channels, days, prompt, cap, zone), off and empty by default
settings.lookouts {enabled, afterSync, items[]}: each item {id, label, channels, days 7, prompt, maxVideos 40,
minSeconds 90, timeZone "" (the machine's), siteOrigin}, coerced by sanitizeLookouts (an item with no usable id
or a repeated id is dropped; an unknown zone falls back to ""). No channel is named in code. SETTINGS.md and
settings.json.example regenerated.
Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat:
7 files changed, 324 insertions(+), 1 deletion(-)
diff --git a/SETTINGS.md b/SETTINGS.md
@@ -58,6 +58,7 @@ A copied example PINS every default it spells — including each lane's `autoQue
| [`clips`](#clips) | object — see below |
| [`jobs`](#jobs) | object — see below |
| [`serviceCookies`](#servicecookies) | object — see below |
+| [`lookouts`](#lookouts) | object — see below |
## `adminTitle`
@@ -1370,3 +1371,41 @@ Default:
]
}
```
+
+## `lookouts`
+
+Saved lookouts (lane/lookout): each names channels, a number of days back and an optional prompt, and a run reads those channels' recent transcripts — by air date, duplicate uploads and stream cut-downs folded in — and answers with video ideas. OFF and empty by default; nothing a lookout writes is published. `pnpm ops get lookouts` is the readout, `pnpm ops lookout-run --json '{"id":"…","dryRun":true}'` lists what one would read. See LookoutsSettings and common/lib/lookoutSettings.ts.
+
+#### `lookouts`
+
+| Key | Default | Description |
+|---|---|---|
+| `enabled` | `false` | The lookouts' master switch. Off: no lookout runs, by hand or after a sync; a dry run (`pnpm ops lookout-run --json '{"id":"…","dryRun":true}'`) still lists what a lookout would read, and writes nothing. Default false. |
+| `afterSync` | `false` | Run each lookout after a sync of one of its channels finishes — at most once a day per lookout, never while render mode holds the machine. Not acted on before the after-sync slice lands. Default false. |
+| `items` | `[]` | The saved lookouts, one entry each (`lookouts.items[]` below). The list is replaced whole by a settings patch. Default [] — no lookout. |
+
+#### `lookouts.items[]`
+
+Per entry — each entry spells its own values.
+
+| Key | Description |
+|---|---|
+| `id` | The lookout's id: a lowercase slug (`a-z`, `0-9`, `-`, at most 64), the name its runs and verdicts are kept under (`transcripts/.lookouts/<id>/`). Omitted: made from `label`. An entry with neither is dropped, and so is a second entry with an id already used. |
+| `label` | What the lookout is called on its page. Omitted: the id. |
+| `channels` | The channel slugs it reads (`transcripts/channels/<slug>/`). A local media library channel, or a slug this archive does not hold (a channel only on a remote site), is refused by name when the lookout runs. |
+| `days` | How many days back it reads, today included, by AIR date in `timeZone` (`release_timestamp`, else `timestamp`, from the video's metadata — not yt-dlp's UTC `upload_date`). Clamped to [1, 60]; default 7. |
+| `prompt` | What the operator wants from the ideas, added to the grouping step only — the per-video reading is the same for every lookout. At most 4000 characters; default "". |
+| `maxVideos` | The most recordings one run reads, after duplicate uploads and stream cut-downs are folded in: the longest first, and every one left out listed as skipped for the cap. Clamped to [1, 500]; default 40. |
+| `minSeconds` | Videos shorter than this are not read (and are counted as skipped). Clamped to [0, 3600]; default 90. |
+| `timeZone` | The IANA time zone its days are counted in ("America/New_York"). "" = the machine's. An unknown zone is dropped to "". Default "". |
+| `siteOrigin` | The public site its links are built on ("https://example.pages.dev"), when the channels are published; "" = each video's source URL with its start second. Default "". |
+
+Default:
+
+```json
+{
+ "enabled": false,
+ "afterSync": false,
+ "items": []
+}
+```
diff --git a/common/lib/lookoutSettings.test.ts b/common/lib/lookoutSettings.test.ts
@@ -0,0 +1,78 @@
+import { test } from "node:test";
+import assert from "node:assert/strict";
+import {
+ DEFAULT_LOOKOUTS_SETTINGS,
+ lookoutById,
+ lookoutIdFrom,
+ sanitizeLookoutItem,
+ sanitizeLookouts,
+} from "./lookoutSettings";
+import { defaults, siteSettingsSchema } from "./settingsSchema";
+
+// Run with:
+// pnpm --filter yt-dlp-transcript-common exec tsx --test lib/lookoutSettings.test.ts
+
+test("off and empty by default, in the schema too", () => {
+ assert.deepEqual(DEFAULT_LOOKOUTS_SETTINGS, { enabled: false, afterSync: false, items: [] });
+ assert.deepEqual(sanitizeLookouts(undefined), DEFAULT_LOOKOUTS_SETTINGS);
+ assert.deepEqual(defaults().lookouts, DEFAULT_LOOKOUTS_SETTINGS);
+ assert.deepEqual(siteSettingsSchema.parse({ lookouts: "nonsense" }).lookouts, DEFAULT_LOOKOUTS_SETTINGS);
+});
+
+test("an item gets every default it leaves out", () => {
+ assert.deepEqual(sanitizeLookoutItem({ id: "weekly", channels: ["example-news", "example-live"] }), {
+ id: "weekly",
+ label: "weekly",
+ channels: ["example-news", "example-live"],
+ days: 7,
+ prompt: "",
+ maxVideos: 40,
+ minSeconds: 90,
+ timeZone: "",
+ siteOrigin: "",
+ });
+});
+
+test("an item is coerced, never thrown on", () => {
+ const item = sanitizeLookoutItem({
+ label: " Example Week! ",
+ channels: ["example-news", "example-news", "", 7, "../escape", "ok.slug_1"],
+ days: 999,
+ maxVideos: "12",
+ minSeconds: -5,
+ timeZone: "Mars/Olympus",
+ siteOrigin: "https://example.pages.dev/some/path?q=1",
+ prompt: "x".repeat(5000),
+ });
+ assert.ok(item);
+ assert.equal(item.id, "example-week");
+ assert.equal(item.label, "Example Week!");
+ assert.deepEqual(item.channels, ["example-news", "ok.slug_1"]);
+ assert.equal(item.days, 60);
+ assert.equal(item.maxVideos, 12);
+ assert.equal(item.minSeconds, 0);
+ assert.equal(item.timeZone, "", "an unknown zone falls back to the machine's");
+ assert.equal(item.siteOrigin, "https://example.pages.dev");
+ assert.equal(item.prompt.length, 4000);
+ assert.equal(sanitizeLookoutItem({ timeZone: "America/Chicago", id: "a" })?.timeZone, "America/Chicago");
+ assert.equal(sanitizeLookoutItem({ siteOrigin: "ftp://x.example", id: "a" })?.siteOrigin, "");
+});
+
+test("an item with no usable id is dropped, and so is a second with the same id", () => {
+ const s = sanitizeLookouts({
+ enabled: true,
+ afterSync: "yes",
+ items: [{ channels: ["a"] }, { id: "one", channels: ["a"] }, { id: "one", channels: ["b"] }, "junk", { label: "Two" }],
+ });
+ assert.equal(s.enabled, true);
+ assert.equal(s.afterSync, false, "only true is true");
+ assert.deepEqual(s.items.map((i) => [i.id, i.channels]), [["one", ["a"]], ["two", []]]);
+ assert.equal(lookoutById(s, "two")?.label, "Two");
+ assert.equal(lookoutById(s, "three"), null);
+});
+
+test("lookoutIdFrom makes a slug", () => {
+ assert.equal(lookoutIdFrom("Café Weekly — News"), "cafe-weekly-news");
+ assert.equal(lookoutIdFrom("!!!"), "");
+ assert.equal(lookoutIdFrom("a".repeat(80)).length, 64);
+});
diff --git a/common/lib/lookoutSettings.ts b/common/lib/lookoutSettings.ts
@@ -0,0 +1,182 @@
+// settings.lookouts — saved lookouts (lane/lookout). A lookout is a saved set of
+// channels, a number of days back and an optional prompt; a run reads those
+// channels' recent transcripts and answers with video ideas. Pure: the types,
+// the defaults, the sanitizer settingsSchema.ts runs the block through, and the
+// per-field docs SETTINGS.md renders.
+//
+// OFF AND EMPTY BY DEFAULT, and no channel is named here or anywhere in code: a
+// lookout is configured on the machine that runs it (`pnpm ops settings`), so
+// adding one is a settings patch, never a code change.
+//
+// Slice 1 reads this for the selection only (controller/lookoutPlan.ts, the
+// `lookout-run` dry run); the model run, `afterSync` and the umtool page come in
+// later slices and read the same fields.
+
+import type { FieldDocs } from "./fieldDocs";
+
+export type LookoutItem = {
+ id: string;
+ label: string;
+ channels: string[];
+ days: number;
+ prompt: string;
+ maxVideos: number;
+ minSeconds: number;
+ timeZone: string;
+ siteOrigin: string;
+};
+
+export type LookoutsSettings = {
+ enabled: boolean;
+ afterSync: boolean;
+ items: LookoutItem[];
+};
+
+export const DEFAULT_LOOKOUTS_SETTINGS: LookoutsSettings = {
+ enabled: false,
+ afterSync: false,
+ items: [],
+};
+
+export const LOOKOUT_DEFAULT_DAYS = 7;
+export const LOOKOUT_MAX_DAYS = 60;
+export const LOOKOUT_DEFAULT_MAX_VIDEOS = 40;
+export const LOOKOUT_MAX_MAX_VIDEOS = 500;
+export const LOOKOUT_DEFAULT_MIN_SECONDS = 90;
+export const LOOKOUT_MAX_MIN_SECONDS = 3600;
+export const LOOKOUT_MAX_PROMPT_CHARS = 4000;
+
+// A lookout id is a path segment (`transcripts/.lookouts/<id>/`), so it is a
+// lowercase slug, nothing else.
+export const LOOKOUT_ID_RE = /^[a-z0-9][a-z0-9-]{0,63}$/;
+// A channel slug as the channels tree names it (the citations' segment rule).
+const CHANNEL_SLUG_RE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
+
+export const LOOKOUTS_SETTINGS_FIELD_DOCS: FieldDocs<LookoutsSettings> = {
+ enabled:
+ "The lookouts' master switch. Off: no lookout runs, by hand or after a sync; a dry run " +
+ "(`pnpm ops lookout-run --json '{\"id\":\"…\",\"dryRun\":true}'`) still lists what a lookout would read, " +
+ "and writes nothing. Default false.",
+ afterSync:
+ "Run each lookout after a sync of one of its channels finishes — at most once a day per lookout, never while " +
+ "render mode holds the machine. Not acted on before the after-sync slice lands. Default false.",
+ items:
+ "The saved lookouts, one entry each (`lookouts.items[]` below). The list is replaced whole by a settings " +
+ "patch. Default [] — no lookout.",
+};
+
+export const LOOKOUT_ITEM_FIELD_DOCS: FieldDocs<LookoutItem> = {
+ id:
+ "The lookout's id: a lowercase slug (`a-z`, `0-9`, `-`, at most 64), the name its runs and verdicts are kept " +
+ "under (`transcripts/.lookouts/<id>/`). Omitted: made from `label`. An entry with neither is dropped, and so " +
+ "is a second entry with an id already used.",
+ label: "What the lookout is called on its page. Omitted: the id.",
+ channels:
+ "The channel slugs it reads (`transcripts/channels/<slug>/`). A local media library channel, or a slug this " +
+ "archive does not hold (a channel only on a remote site), is refused by name when the lookout runs.",
+ days:
+ "How many days back it reads, today included, by AIR date in `timeZone` (`release_timestamp`, else " +
+ "`timestamp`, from the video's metadata — not yt-dlp's UTC `upload_date`). Clamped to [1, 60]; default 7.",
+ prompt:
+ "What the operator wants from the ideas, added to the grouping step only — the per-video reading is the same " +
+ "for every lookout. At most 4000 characters; default \"\".",
+ maxVideos:
+ "The most recordings one run reads, after duplicate uploads and stream cut-downs are folded in: the longest " +
+ "first, and every one left out listed as skipped for the cap. Clamped to [1, 500]; default 40.",
+ minSeconds:
+ "Videos shorter than this are not read (and are counted as skipped). Clamped to [0, 3600]; default 90.",
+ timeZone:
+ "The IANA time zone its days are counted in (\"America/New_York\"). \"\" = the machine's. An unknown zone is " +
+ "dropped to \"\". Default \"\".",
+ siteOrigin:
+ "The public site its links are built on (\"https://example.pages.dev\"), when the channels are published; " +
+ "\"\" = each video's source URL with its start second. Default \"\".",
+};
+
+function clampInt(value: unknown, fallback: number, min: number, max: number): number {
+ const n = typeof value === "number" ? value : typeof value === "string" && value.trim() ? Number(value) : NaN;
+ if (!Number.isFinite(n)) return fallback;
+ return Math.min(max, Math.max(min, Math.round(n)));
+}
+
+/** Whether `tz` is an IANA zone this runtime knows. "" is not a zone (it means the machine's). */
+export function isKnownTimeZone(tz: string): boolean {
+ if (!tz) return false;
+ try {
+ new Intl.DateTimeFormat("en-US", { timeZone: tz });
+ return true;
+ } catch {
+ return false;
+ }
+}
+
+/** A lowercase slug made from free text: "My Lookout!" → "my-lookout". */
+export function lookoutIdFrom(text: string): string {
+ return text
+ .normalize("NFKD")
+ .replace(/[̀-ͯ]/g, "")
+ .toLowerCase()
+ .replace(/[^a-z0-9]+/g, "-")
+ .replace(/^-+|-+$/g, "")
+ .slice(0, 64)
+ .replace(/-+$/, "");
+}
+
+function siteOriginOf(value: unknown): string {
+ if (typeof value !== "string" || !value.trim()) return "";
+ try {
+ const u = new URL(value.trim());
+ if (u.protocol !== "https:" && u.protocol !== "http:") return "";
+ return u.origin;
+ } catch {
+ return "";
+ }
+}
+
+/** One entry, coerced; null when it has no usable id. */
+export function sanitizeLookoutItem(value: unknown): LookoutItem | null {
+ if (!value || typeof value !== "object" || Array.isArray(value)) return null;
+ const r = value as Record<string, unknown>;
+ const rawId = typeof r.id === "string" ? r.id.trim() : "";
+ const rawLabel = typeof r.label === "string" ? r.label.trim() : "";
+ const id = LOOKOUT_ID_RE.test(rawId) ? rawId : lookoutIdFrom(rawId || rawLabel);
+ if (!LOOKOUT_ID_RE.test(id)) return null;
+ const channels: string[] = [];
+ if (Array.isArray(r.channels)) {
+ for (const c of r.channels) {
+ if (typeof c !== "string") continue;
+ const slug = c.trim();
+ if (slug && slug !== ".." && CHANNEL_SLUG_RE.test(slug) && !channels.includes(slug)) channels.push(slug);
+ }
+ }
+ const tz = typeof r.timeZone === "string" ? r.timeZone.trim() : "";
+ const prompt = typeof r.prompt === "string" ? r.prompt.trim().slice(0, LOOKOUT_MAX_PROMPT_CHARS) : "";
+ return {
+ id,
+ label: rawLabel || id,
+ channels,
+ days: clampInt(r.days, LOOKOUT_DEFAULT_DAYS, 1, LOOKOUT_MAX_DAYS),
+ prompt,
+ maxVideos: clampInt(r.maxVideos, LOOKOUT_DEFAULT_MAX_VIDEOS, 1, LOOKOUT_MAX_MAX_VIDEOS),
+ minSeconds: clampInt(r.minSeconds, LOOKOUT_DEFAULT_MIN_SECONDS, 0, LOOKOUT_MAX_MIN_SECONDS),
+ timeZone: isKnownTimeZone(tz) ? tz : "",
+ siteOrigin: siteOriginOf(r.siteOrigin),
+ };
+}
+
+export function sanitizeLookouts(value: unknown): LookoutsSettings {
+ const r = (value && typeof value === "object" && !Array.isArray(value) ? value : {}) as Record<string, unknown>;
+ const items: LookoutItem[] = [];
+ if (Array.isArray(r.items)) {
+ for (const raw of r.items) {
+ const item = sanitizeLookoutItem(raw);
+ if (item && !items.some((i) => i.id === item.id)) items.push(item);
+ }
+ }
+ return { enabled: r.enabled === true, afterSync: r.afterSync === true, items };
+}
+
+/** The saved lookout with this id, or null. */
+export function lookoutById(settings: LookoutsSettings, id: string): LookoutItem | null {
+ return settings.items.find((i) => i.id === id) ?? null;
+}
diff --git a/common/lib/settingsDocs.ts b/common/lib/settingsDocs.ts
@@ -15,6 +15,8 @@ import {
ARCHIVES_SETTINGS_FIELD_DOCS,
CLIPS_SETTINGS_FIELD_DOCS,
JOBS_SETTINGS_FIELD_DOCS,
+ LOOKOUTS_SETTINGS_FIELD_DOCS,
+ LOOKOUT_ITEM_FIELD_DOCS,
SERVICE_COOKIES_SETTINGS_FIELD_DOCS,
VOICE_CONVERT_SETTINGS_FIELD_DOCS,
VOICE_ENHANCE_SETTINGS_FIELD_DOCS,
@@ -358,6 +360,14 @@ export function blockTables(d: SiteSettings): Partial<Record<keyof SiteSettings,
defaults: fromObject(d.serviceCookies),
},
],
+ lookouts: [
+ {
+ path: "lookouts",
+ docs: LOOKOUTS_SETTINGS_FIELD_DOCS,
+ defaults: fromObject(d.lookouts),
+ },
+ { path: "lookouts.items[]", docs: LOOKOUT_ITEM_FIELD_DOCS },
+ ],
};
}
diff --git a/common/lib/settingsSchema.test.ts b/common/lib/settingsSchema.test.ts
@@ -36,6 +36,7 @@ import type { ArchivesSettings } from "./archives/settings";
import type { ClipsSettings } from "./clipSettings";
import type { JobsSettings } from "./jobsSettings";
import type { ServiceCookiesSettings } from "./serviceCookieSettings";
+import type { LookoutsSettings } from "./lookoutSettings";
import type { VoiceSettings } from "./voiceSettings";
import type { GenerationSettings } from "./generationSettings";
import type {
@@ -132,13 +133,15 @@ type PreSchemaSiteSettings = {
jobs: JobsSettings;
// The cookie refresh alerts' proactive timer (2026-10-31).
serviceCookies: ServiceCookiesSettings;
+ // Saved lookouts (lane/lookout).
+ lookouts: LookoutsSettings;
};
// Bracketed so the conditional does not distribute (see commit 8c43231).
type Same<A, B> = [A] extends [B] ? ([B] extends [A] ? true : false) : false;
const shapeUnchanged: Same<SiteSettings, PreSchemaSiteSettings> = true;
-test("SiteSettings keeps its 46 fields, in file order", () => {
+test("SiteSettings keeps its 47 fields, in file order", () => {
assert.equal(shapeUnchanged, true);
assert.deepEqual(Object.keys(siteSettingsSchema.shape), [
"adminTitle",
@@ -187,6 +190,7 @@ test("SiteSettings keeps its 46 fields, in file order", () => {
"clips",
"jobs",
"serviceCookies",
+ "lookouts",
]);
// A parsed object carries every key, in that order — writeSettings writes
// exactly this, so the order is the on-disk order.
diff --git a/common/lib/settingsSchema.ts b/common/lib/settingsSchema.ts
@@ -84,6 +84,7 @@ import { sanitizeVoice, type VoiceSettings } from "./voiceSettings";
import { sanitizeArchives, type ArchivesSettings } from "./archives/settings";
import { sanitizeClips, type ClipsSettings } from "./clipSettings";
import { sanitizeJobs, type JobsSettings } from "./jobsSettings";
+import { sanitizeLookouts, type LookoutsSettings } from "./lookoutSettings";
import { sanitizeServiceCookies, type ServiceCookiesSettings } from "./serviceCookieSettings";
import { sanitizeGeneration, type GenerationSettings } from "./generationSettings";
export {
@@ -111,6 +112,7 @@ export {
export { ARCHIVES_SETTINGS_FIELD_DOCS, type ArchivesSettings } from "./archives/settings";
export { CLIPS_SETTINGS_FIELD_DOCS, type ClipsSettings } from "./clipSettings";
export { JOBS_SETTINGS_FIELD_DOCS, type JobsSettings } from "./jobsSettings";
+export { LOOKOUTS_SETTINGS_FIELD_DOCS, LOOKOUT_ITEM_FIELD_DOCS, type LookoutsSettings, type LookoutItem } from "./lookoutSettings";
export { SERVICE_COOKIES_SETTINGS_FIELD_DOCS, type ServiceCookiesSettings } from "./serviceCookieSettings";
import {
DEFAULT_COOKIE_MODE,
@@ -2071,6 +2073,9 @@ export const siteSettingsSchema = z.object({
serviceCookies: settingsField((v): ServiceCookiesSettings => sanitizeServiceCookies(v)).describe(
"The cookie refresh alerts' PROACTIVE timer (plans/cookie-refresh-alerts.md): how often the editor rechecks raised alerts, probes Rumble's clearance with no alert up, and re-reads X's cookie jar age, by itself — so the dashboard banner goes up before a sync or a download fails. See ServiceCookiesSettings and common/controller/serviceCookieTimer.ts.",
),
+ lookouts: settingsField((v): LookoutsSettings => sanitizeLookouts(v)).describe(
+ "Saved lookouts (lane/lookout): each names channels, a number of days back and an optional prompt, and a run reads those channels' recent transcripts — by air date, duplicate uploads and stream cut-downs folded in — and answers with video ideas. OFF and empty by default; nothing a lookout writes is published. `pnpm ops get lookouts` is the readout, `pnpm ops lookout-run --json '{\"id\":\"…\",\"dryRun\":true}'` lists what one would read. See LookoutsSettings and common/lib/lookoutSettings.ts.",
+ ),
});
export type SiteSettings = z.infer<typeof siteSettingsSchema>;
diff --git a/settings.json.example b/settings.json.example
@@ -370,5 +370,10 @@
"probeServices": [
"rumble"
]
+ },
+ "lookouts": {
+ "enabled": false,
+ "afterSync": false,
+ "items": []
}
}