commit 1b6aaf57d191781788efd0bd0a9836c288cabf9a
parent 342830629fb66ab932e071a47b4cb1eafccbd195
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Wed, 18 Nov 2026 02:04:38 -0500
x-trending: the MCP shows watches, captures and gone marks; the privacy pins cover what slice 2 adds
x_trending_topics says each topic's watch (and why it is paused); x_trending_posts says a post's thread, what its capture holds and is owed, a thread's judgement, and gone from the page (never deleted). The four privacy pins (the index and composed site, the MCP's corpus tools, the report and article doors, umtool's post readers) now plant a kept, captured and watched post (a judgement's note, a shot, a media file in the store with its address, the capture's context, an availability sidecar) through the real writers and look for every one of its markers and file names in what each door gives out. The e2e spec drives a judgement by an agent and by the operator, a watch tick, a new post's media from a played-back CDN kept once, gone-from-the-page marks, and a stale jar pausing the watch with /review saying so.
Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat:
8 files changed, 341 insertions(+), 14 deletions(-)
diff --git a/common/bin/xTrendingPrivacy.test.ts b/common/bin/xTrendingPrivacy.test.ts
@@ -18,7 +18,7 @@
import { after, test } from "node:test";
import assert from "node:assert/strict";
-import { mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, statSync, writeFileSync } from "node:fs";
+import { existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, statSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import path from "node:path";
@@ -47,7 +47,7 @@ const { buildIndex } = await import("../controller/buildIndex");
const { main: composeSite } = await import("./compose-site");
const { getSite, writeSite } = await import("../lib/site");
const { writePosts } = await import("../lib/posts-server");
-const { recordXTrendingRead, writeXTrendingPosts, trendingReadDir, listXTrending } = await import("../lib/xTrending/store");
+const { recordXTrendingRead, writeXTrendingPosts, trendingReadDir, listXTrending, readXTrendingTopics: readXTrendingTopicsOf } = await import("../lib/xTrending/store");
const { X_TRENDING_NOT_ON_A_SITE } = await import("../lib/xTrending/config");
const { open } = await import("lmdb");
@@ -59,7 +59,11 @@ const POST_MARK = "trendpostmarkerq7x";
const HANDLE_MARK = "trendhandlemarkerz4k";
const TOPIC_MARK = "trendtopicmarkerw2p";
const RAW_MARK = "trendrawmarkerj9m";
-const MARKS = [POST_MARK, HANDLE_MARK, TOPIC_MARK, RAW_MARK];
+// Lane x-trending-2: the judgement's note, the captured media's bytes and
+// address, the capture's context and the shot — planted below, and looked for
+// in everything a build writes, like the four above.
+const { plantSlice2Library, SLICE2_FILE_NAMES, SLICE2_MARK_LIST } = await import("../lib/xTrending/__fixtures__/slice2Library");
+const MARKS = [POST_MARK, HANDLE_MARK, TOPIC_MARK, RAW_MARK, ...SLICE2_MARK_LIST];
const READ = "tr-01JA0000000000000000000000";
const quiet = () => {};
@@ -110,6 +114,9 @@ await recordXTrendingRead(libRoot, {
mkdirSync(trendingReadDir(libRoot, READ), { recursive: true });
writeFileSync(path.join(trendingReadDir(libRoot, READ), "responses.jsonl"), `${JSON.stringify({ n: 1, op: "Op", status: 200, body: { t: RAW_MARK } })}\n`);
+const planted = (await readXTrendingTopicsOf(libRoot))[0];
+await plantSlice2Library(libRoot, { postId: "1900000000000006001", topicId: planted.id });
+
const site = (channels: string[]) => ({
siteId: "priv", siteTitle: "priv", siteDescription: "fixture", headerTitle: "priv", homeTagline: "",
socialLinks: [], groups: [{ id: "default", name: "All channels", selectedByDefault: true }],
@@ -128,7 +135,7 @@ function filesUnder(dir: string): { rel: string; text: string }[] {
else if (e.isFile() || (e.isSymbolicLink() && statSync(p).isFile())) out.push({ rel: path.relative(dir, p), text: readFileSync(p).toString("latin1") });
}
};
- walk(dir);
+ if (existsSync(dir)) walk(dir);
return out;
}
@@ -218,6 +225,26 @@ test("the library's own listing needs no index: it reads its files", async () =>
assert.ok(!JSON.stringify(listing).includes(RAW_MARK));
});
+// Lane x-trending-2.
+test("what a keep, a capture and a watch leave in a library is in no build: not its words, not its bytes, not a file of its name", async () => {
+ // Planted for real: the files exist, where the editor leaves them.
+ for (const rel of ["judgements.json", "watch.json", "media-index.json", "posts-availability.json", ".gitignore", path.join("posts-media", "1900000000000006001", "capture.json")]) {
+ assert.ok(existsSync(path.join(libRoot, "trending", rel)), `${rel} was planted`);
+ }
+ const built = [...filesUnder(paths.exportIndexDir), ...filesUnder(paths.exportPublicDir)];
+ assert.ok(built.length > 0, "the builds above wrote files");
+ assertNoLeak(built, "index and public dirs");
+ for (const f of built) {
+ for (const name of [...SLICE2_FILE_NAMES, "posts-media"]) {
+ assert.ok(!f.rel.split(path.sep).includes(name), `a build wrote ${f.rel}`);
+ }
+ }
+ // The library's own listing does carry the judgement — and that is the only door.
+ const listing = await listXTrending(libRoot);
+ assert.equal(listing.posts[0].judgement?.state, "keep");
+ assert.equal(listing.topics[0].watch?.on, true);
+});
+
test("the search itself catches a leak", () => {
assert.throws(() => assertNoLeak([{ rel: path.join("posts", LIB, "page-0001.json"), text: "" }], "x"));
for (const mark of MARKS) assert.throws(() => assertNoLeak([{ rel: "page-0001.json", text: `{"q":"${mark}"}` }], "x"));
diff --git a/common/lib/xTrending/__fixtures__/slice2Library.ts b/common/lib/xTrending/__fixtures__/slice2Library.ts
@@ -0,0 +1,54 @@
+// WHAT LANE x-trending-2 ADDS TO A LIBRARY, PLANTED FOR THE PRIVACY PINS: a
+// judgement with a note, a watch, a captured post (its record, a shot, a
+// media file taken into the store with its address) and an availability
+// sidecar — each carrying a marker the pin then looks for in everything a
+// build, a report or a tool gives out. Written through the real writers, so
+// the layout is the one the editor leaves. Invented words throughout.
+
+import { mkdirSync, writeFileSync } from "node:fs";
+import path from "node:path";
+import { writePostAvailability } from "../../posts-server";
+import { judgeXTrending } from "../judgements";
+import { adoptXTrendingMedia, ensureXTrendingMediaIgnore } from "../mediaStore";
+import { trendingDir, xTrendingPostsMediaDir } from "../store";
+import { setXTrendingWatch } from "../watch";
+
+export const SLICE2_MARKS = {
+ note: "trendjudgenotemarkerh3v",
+ media: "trendmediabytesmarkerk8d",
+ address: "trendmediaaddressmarkerp5s",
+ context: "trendcapturecontextmarkern2c",
+ shot: "trendshotbytesmarkert6b",
+} as const;
+
+export const SLICE2_MARK_LIST: readonly string[] = Object.values(SLICE2_MARKS);
+
+// The names a build or a report must never carry a file of.
+export const SLICE2_FILE_NAMES: readonly string[] = ["judgements.json", "media-index.json", "watch.json", "media-store", "posts-availability.json"];
+
+// `postId` must be a post of the library, in a topic `topicId` that holds a page.
+export async function plantSlice2Library(libRoot: string, o: { postId: string; topicId: string }): Promise<void> {
+ await judgeXTrending(libRoot, { by: "operator", set: [{ id: o.postId, state: "keep", note: `kept ${SLICE2_MARKS.note}` }] });
+ await setXTrendingWatch(libRoot, { topic: o.topicId, on: true, intervalMinutes: 30, hours: 48, by: "operator", maxTopics: 4, now: Date.parse("2026-11-18T10:00:00.000Z") });
+ const dir = path.join(xTrendingPostsMediaDir(libRoot), o.postId);
+ mkdirSync(dir, { recursive: true });
+ writeFileSync(path.join(dir, `${o.postId}_1.jpg`), `picture ${SLICE2_MARKS.media}`);
+ writeFileSync(path.join(dir, "shot.png"), `shot ${SLICE2_MARKS.shot}`);
+ writeFileSync(
+ path.join(dir, "capture.json"),
+ JSON.stringify({
+ version: 1,
+ id: o.postId,
+ url: `https://x.com/i/status/${o.postId}`,
+ capturedAt: "2026-11-18T10:05:00.000Z",
+ state: "captured",
+ shot: { name: "shot.png", bytes: 1, sha256: "0".repeat(64) },
+ mediaState: "ok",
+ media: [{ name: `${o.postId}_1.jpg`, bytes: 1, sha256: "0".repeat(64), url: `https://pbs.twimg.com/media/${SLICE2_MARKS.address}.jpg` }],
+ context: { readAt: "2026-11-18T10:05:00.000Z", quoted: { text: `quoted ${SLICE2_MARKS.context}`, media: [] } },
+ }),
+ );
+ await adoptXTrendingMedia(libRoot, { postId: o.postId, name: `${o.postId}_1.jpg`, url: `https://pbs.twimg.com/media/${SLICE2_MARKS.address}.jpg` });
+ await ensureXTrendingMediaIgnore(libRoot);
+ await writePostAvailability(trendingDir(libRoot), { [o.postId]: { availability: "available", checkedAt: "2026-11-18T10:05:00.000Z" } });
+}
diff --git a/common/publish/xTrendingReportDoor.test.ts b/common/publish/xTrendingReportDoor.test.ts
@@ -89,6 +89,29 @@ writeJson(path.join(accountRoot, "config.json"), {
});
await writePosts(accountRoot, [post(ACCOUNT, SHARED_ID, "kettle_org", "the account's own copy")]);
+// Lane x-trending-2: the library's first post is KEPT and CAPTURED (a note,
+// a shot, a media file in the store, its context) and its topic watched. No
+// report door may give out any of it either.
+const { recordXTrendingRead, readXTrendingTopics } = await import("../lib/xTrending/store");
+const { plantSlice2Library, SLICE2_FILE_NAMES, SLICE2_MARK_LIST } = await import("../lib/xTrending/__fixtures__/slice2Library");
+await recordXTrendingRead(libRoot, {
+ readId: "tr-01JA0000000000000000000000",
+ at: "2026-11-17T10:00:00.000Z",
+ ref: { trendId: "1900000000000000001", url: "https://x.com/i/trending/1900000000000000001" },
+ topic: "Kettles",
+ postIds: [LIB_ID, SHARED_ID],
+ added: 2,
+});
+await plantSlice2Library(libRoot, { postId: LIB_ID, topicId: (await readXTrendingTopics(libRoot))[0].id });
+
+// Nothing lane x-trending-2 leaves in a library is in what a report door wrote.
+function assertNoSlice2(files: { rel: string; text: string }[], where: string): void {
+ for (const f of files) {
+ for (const mark of SLICE2_MARK_LIST) assert.ok(!f.text.includes(mark), `${where}: ${f.rel} holds ${mark}`);
+ for (const name of [...SLICE2_FILE_NAMES, "posts-media"]) assert.ok(!f.rel.split(path.sep).includes(name), `${where}: wrote ${f.rel}`);
+ }
+}
+
function filesUnder(dir: string): { rel: string; text: string }[] {
const out: { rel: string; text: string }[] = [];
const walk = (d: string) => {
@@ -209,6 +232,7 @@ test("N8a: behind a host that lets it through, compose still refuses a library's
return true;
});
for (const f of filesUnder(OUT)) assert.ok(!f.text.includes(MARK) && !f.text.includes(HANDLE), `${f.rel} holds the library's post`);
+ assertNoSlice2(filesUnder(OUT), "compose");
});
test("N8a: behind such a host, preparing media refuses a library's post, and no window of a library is planned", async () => {
@@ -219,6 +243,11 @@ test("N8a: behind such a host, preparing media refuses a library's post, and no
[["not-visible", `${LIB}/${LIB_ID}`, X_TRENDING_NOT_CITABLE(LIB)]],
);
assert.deepEqual(Object.keys(index.moments), []);
+ // The post is CAPTURED now (a shot and a media file under trending/): no
+ // report media is prepared from it all the same, and nothing of it is written.
+ assert.ok(!JSON.stringify(index).includes("posts-media"), "the media index names a capture");
+ for (const mark of SLICE2_MARK_LIST) assert.ok(!JSON.stringify(index).includes(mark), `the media index holds ${mark}`);
+ assertNoSlice2(filesUnder(OUT), "report media");
// A span cited on a library (a config edited by hand could carry videos).
writeJson(path.join(articleDir(paths, "art-lib-span"), "report.json"), {
diff --git a/editor/e2e/x-trending.spec.ts b/editor/e2e/x-trending.spec.ts
@@ -13,12 +13,18 @@
// an empty directory and a cookie jar with a made-up login.
import { test, expect } from "@playwright/test";
-import { mkdir, readFile, readdir, utimes, writeFile } from "node:fs/promises";
+import { mkdir, readFile, readdir, stat, utimes, writeFile } from "node:fs/promises";
import { generateReport, pathExists, readJson, resetData, resolvePath, testPaths, writeSettings, writeSite } from "./helpers";
import { baseUrl } from "./baseUrl";
// By relative path: a runtime import of the package specifier does not resolve
// under playwright's loader (digest.spec.ts says why).
-import { FIXTURE_TREND_URL, fixtureTrendingResponses } from "../../common/social/__fixtures__/xTrendingCapture";
+import {
+ FIXTURE_FIRST_PAGE,
+ FIXTURE_TIMELINE_OP,
+ FIXTURE_TREND_URL,
+ fixtureTimelineBody,
+ fixtureTrendingResponses,
+} from "../../common/social/__fixtures__/xTrendingCapture";
const TOKEN = "test-worker-token";
const AUTH = { authorization: `Bearer ${TOKEN}` };
@@ -173,3 +179,123 @@ test("an X trending library: the form, one read, the library by topic, the listi
expect(await pathExists(rel(`channels/${SLUG}/posts`))).toBe(false);
expect(await pathExists(rel(`channels/${SLUG}/posts-archive`))).toBe(false);
});
+
+// LANE x-trending-2: judge, watch, media kept once, gone from the page, and
+// the jar rule pausing the watch. Still no browser and no request to X or to
+// its media CDN: the fake page and the played-back CDN
+// (common/social/fakeXProfileBrowser.ts fakeXMediaFetch) answer everything.
+test("an X trending library: judgements, a watch tick, media kept once, gone from the page, a stale jar pauses the watch", async ({ page, request }) => {
+ test.setTimeout(180_000);
+ await seed();
+ const post = async (action: string, data: Record<string, unknown>) => {
+ const res = await request.post(`${baseUrl}/api/ops/${action}`, { headers: AUTH, data });
+ return { status: res.status(), json: (await res.json()) as Record<string, unknown> };
+ };
+ const listing = async () =>
+ (await (await request.get(`${baseUrl}/api/ops/trending?slug=${SLUG}`, { headers: AUTH })).json()) as {
+ topics: { id: string; watch?: { on: boolean; ticks: number; paused?: { reason: string }; sentence: string } }[];
+ posts: { id: string; gone?: { at: string }; capture?: { files: number; mediaState: string }; judgement?: { state: string; by: string } }[];
+ };
+ const made = await post("create-channel", { fields: { name: "Trending", slug: SLUG, handling: "transcribe", platform: "x-trending" } });
+ expect(made.status, JSON.stringify(made.json)).toBe(200);
+ expect((await post("read-x-trending", { slug: SLUG, url: FIXTURE_TREND_URL, topic: "Kettle Festival" })).status).toBe(200);
+ await expect.poll(archiveLines, { timeout: 60_000 }).toBe(4);
+
+ // JUDGE. An agent keeps one (marking only); the operator drops another on the page.
+ const A = "1900000000000001001";
+ const B = "1900000000000001002";
+ const kept = await post("judge-trending", { slug: SLUG, archive: false, set: [{ id: A, state: "keep", note: "the opening" }] });
+ expect(kept.json).toMatchObject({ ok: true, written: [{ id: A, state: "keep" }], skipped: [], kept: [A] });
+ await generateReport(page, SLUG);
+ await page.goto(`/channels/${SLUG}`);
+ const topic = page.locator('[data-x-trending-topic="kettle-festival"]');
+ await expect(topic.locator(`[data-x-trending-post="${A}"] [data-x-trending-judgement="keep"]`)).toContainText("keep by agent: the opening");
+ await page.getByRole("button", { name: `Drop ${B}`, exact: true }).click();
+ await expect(topic.locator(`[data-x-trending-post="${B}"] [data-x-trending-judgement="drop"]`)).toContainText("drop by operator");
+ // An agent's judgement never replaces the operator's.
+ const over = await post("judge-trending", { slug: SLUG, archive: false, set: [{ id: B, state: "keep" }] });
+ expect(over.json).toMatchObject({ written: [], skipped: [{ id: B, reason: "judged by the operator: an agent's judgement does not replace it" }] });
+ expect((await readJson<{ posts: Record<string, { state: string; by: string }> }>(rel(`channels/${SLUG}/trending/judgements.json`))).posts[B]).toMatchObject({ state: "drop", by: "operator" });
+
+ // WATCH the topic, from the page.
+ await topic.getByRole("button", { name: "Watch", exact: true }).click();
+ await expect(topic.locator("[data-x-trending-watch-state]")).toContainText("Watched every 30 min until");
+ await expect(topic).toContainText("it does not cover a night nobody refreshes in");
+ expect((await listing()).topics[0].watch).toMatchObject({ on: true, ticks: 0 });
+
+ // The page has changed: the opening post and a NEW one with two pictures; the rest are no longer shown.
+ const NEW = "1900000000000001006";
+ const picture = (i: number) => `https://pbs.twimg.com/media/Fixture1006${i}?format=jpg&name=orig`;
+ await writeFile(
+ t(".fake-x-profile-cookies.json"),
+ JSON.stringify({
+ cookies: [{ name: "auth_token", value: "fixture-not-a-real-token", domain: ".x.com" }],
+ trending: {
+ load: [
+ {
+ url: `https://x.com/i/api/graphql/fixtureQueryId2/${FIXTURE_TIMELINE_OP}?variables=%7B%7D`,
+ status: 200,
+ body: fixtureTimelineBody([FIXTURE_FIRST_PAGE[0], { id: NEW, handle: "spout_clips", text: "Two pictures of the queue.", media: ["photo", "photo"] }]),
+ },
+ ],
+ scrolls: [[], []],
+ },
+ // The same bytes at both addresses: one file in the library.
+ media: { [picture(0)]: { text: "FIXTURE PICTURE BYTES" }, [picture(1)]: { text: "FIXTURE PICTURE BYTES" } },
+ }),
+ );
+
+ // ONE SCAN (what the timer does once a minute; not armed on the test server): one read is started.
+ const tick = await post("watch-trending", { slug: SLUG, tick: true });
+ expect(tick.status, JSON.stringify(tick.json)).toBe(200);
+ expect(tick.json.scan).toMatchObject({ live: 1, enqueued: { slug: SLUG, topic: "kettle-festival", url: FIXTURE_TREND_URL }, paused: [] });
+ await expect.poll(archiveLines, { timeout: 60_000 }).toBe(5);
+ // A second scan at once starts nothing: the next tick is an interval away.
+ expect(((await post("watch-trending", { slug: SLUG, tick: true })).json.scan as { enqueued?: unknown }).enqueued).toBeUndefined();
+
+ // The new post's MEDIA came at once, from the (played-back) CDN, and is kept once.
+ const dir = t(`channels/${SLUG}/trending/posts-media/${NEW}`);
+ await expect.poll(async () => (await readdir(dir).catch(() => [] as string[])).sort(), { timeout: 60_000 }).toEqual([`${NEW}_1.jpg`, `${NEW}_2.jpg`, "capture.json"]);
+ expect(await readFile(`${dir}/${NEW}_1.jpg`, "utf8")).toBe("FIXTURE PICTURE BYTES");
+ expect((await stat(`${dir}/${NEW}_1.jpg`)).ino).toBe((await stat(`${dir}/${NEW}_2.jpg`)).ino);
+ const index = await readJson<{ blobs: Record<string, { posts: Record<string, string[]>; urls: string[] }> }>(rel(`channels/${SLUG}/trending/media-index.json`));
+ expect(Object.values(index.blobs)).toHaveLength(1);
+ expect(Object.values(index.blobs)[0].posts).toEqual({ [NEW]: [`${NEW}_1.jpg`, `${NEW}_2.jpg`] });
+ // Never committed, and never where a posts channel keeps its captures.
+ expect(await readFile(t(`channels/${SLUG}/trending/.gitignore`), "utf8")).toMatch(/^posts-media\/$/m);
+ expect(await pathExists(rel(`channels/${SLUG}/posts-media`))).toBe(false);
+
+ // GONE FROM THE PAGE: the three posts the page stopped showing, said so, never "deleted".
+ const after = await listing();
+ expect(after.posts.filter((p) => p.gone).map((p) => p.id).sort()).toEqual([B, "1900000000000001004", "1900000000000001005"]);
+ expect(after.posts.find((p) => p.id === NEW)?.capture).toMatchObject({ files: 2, mediaState: "ok" });
+ expect(after.topics[0].watch).toMatchObject({ on: true, ticks: 1 });
+ await page.reload();
+ await expect(topic.locator(`[data-x-trending-post="${B}"] [data-x-trending-gone]`)).toContainText("Gone from the page at");
+ await expect(topic.locator(`[data-x-trending-post="${A}"] [data-x-trending-gone]`)).toHaveCount(0);
+ await expect(page.locator("body")).not.toContainText(/deleted/i);
+
+ // THE JAR RULE: past its limit the watch PAUSES (nothing is enqueued, nothing refreshes the jar), and /review says so.
+ const old = new Date(Date.now() - 2 * 60 * 60_000);
+ await utimes(t(".x-session/cookies.txt"), old, old);
+ const paused = await post("watch-trending", { slug: SLUG, tick: true });
+ expect(paused.json.scan).toMatchObject({ paused: [{ slug: SLUG, topic: "kettle-festival", reason: "jar" }] });
+ expect((paused.json.scan as { enqueued?: unknown }).enqueued).toBeUndefined();
+ expect((await listing()).topics[0].watch?.sentence).toMatch(/PAUSED since .* UTC: X cookies were last refreshed 2 h ago \(limit 60 min\)/);
+ expect((await stat(t(".x-session/cookies.txt"))).mtimeMs).toBeLessThan(Date.now() - 60 * 60_000);
+ await page.goto("/review");
+ const section = page.getByRole("region", { name: "paused watches" });
+ await expect(section).toContainText("Paused watches (1)");
+ await expect(section).toContainText("Kettle Festival");
+ await expect(section).toContainText("It resumes by itself at the first scan after Refresh cookies on /cookies.");
+ // "Refreshed" (the jar written now): the first scan after it resumes the watch.
+ const now = new Date();
+ await utimes(t(".x-session/cookies.txt"), now, now);
+ const resumed = await post("watch-trending", { slug: SLUG, tick: true });
+ expect(resumed.json.scan).toMatchObject({ resumed: [{ slug: SLUG, topic: "kettle-festival" }], paused: [] });
+ await page.reload();
+ await expect(page.getByRole("region", { name: "paused watches" })).toHaveCount(0);
+ // Stop watching.
+ const off = await post("watch-trending", { slug: SLUG, topic: "kettle-festival", on: false, by: "operator" });
+ expect(off.json.sentence).toBe('The watch of "Kettle Festival" was switched off.');
+});
diff --git a/mcp/src/xTrending.test.ts b/mcp/src/xTrending.test.ts
@@ -127,3 +127,39 @@ test("with no editor configured, the tools say what is missing and ask nothing",
assert.ok(isError(res));
assert.equal(sent.length, 0);
});
+
+// Lane x-trending-2: what a watch, a capture, a thread's judgement and a page
+// that stopped showing a post look like to the agent.
+test("the tools say a topic's watch, and a post's thread, capture, gone-from-the-page mark and thread judgement", async () => {
+ const listing = {
+ ...LISTING,
+ topics: [
+ {
+ ...LISTING.topics[0],
+ watch: { on: true, paused: { reason: "jar" }, sentence: "Watched every 30 min until 2026-11-20 10:00 UTC — PAUSED since 2026-11-18 11:00 UTC: X cookies were last refreshed 61 min ago (limit 60 min)." },
+ },
+ ],
+ posts: [
+ {
+ ...LISTING.posts[0],
+ thread: "1900000000000000999",
+ gone: { at: "2026-11-18T10:30:00.000Z", read: READ, trendId: "1900000000000000001" },
+ capture: { at: "2026-11-18T10:05:00.000Z", state: "captured", shot: false, files: 1, mediaState: "error", mediaOwed: "kept" },
+ judgement: { state: "keep", by: "operator", at: "2026-11-18T09:00:00.000Z", from: "thread" },
+ },
+ ],
+ total: 1,
+ };
+ const { deps } = fakeEditor(() => ({ status: 200, body: listing }), env);
+ const client = await connectWith(deps);
+ const topics = body(await client.callTool({ name: "x_trending_topics", arguments: { channel: "trending" } }));
+ assert.match(topics, /^ {4}watch: Watched every 30 min until 2026-11-20 10:00 UTC — PAUSED since 2026-11-18 11:00 UTC: X cookies were last refreshed 61 min ago/m);
+ const posts = body(await client.callTool({ name: "x_trending_posts", arguments: { channel: "trending" } }));
+ assert.deepEqual(posts.split("\n").slice(4), [
+ ` shown by: ${READ} (2026-11-17 10:00 UTC)`,
+ " in thread 1900000000000000999",
+ ` gone from the page at 2026-11-18 10:30 UTC (read ${READ}; the page stopped showing it, which is not "deleted")`,
+ " captured 2026-11-18 10:05 UTC: captured, 1 media file; more media owed once it is kept",
+ " judged keep by operator (its thread) (2026-11-18 09:00 UTC)",
+ ]);
+});
diff --git a/mcp/src/xTrending.ts b/mcp/src/xTrending.ts
@@ -14,7 +14,9 @@ import type { ToolAnswer } from "./archivalTools";
//
// Reading a page into a library is the operator's or an agent's ask of the
// editor: `pnpm ops read-x-trending` (one job on X's queue, on a fresh cookie
-// jar — `pnpm ops get x-session` says whether one would start).
+// jar — `pnpm ops get x-session` says whether one would start). Judging a post
+// (`judge-trending`) and watching a topic (`watch-trending`) are asks of the
+// editor too; these tools only show what they left (lane x-trending-2).
const SLUG_RE = /^[a-z0-9][a-z0-9._-]*$/i;
export const X_TRENDING_POSTS_MAX = 500;
@@ -24,6 +26,8 @@ type Topic = {
title: string;
posts: number;
sources?: Array<{ trendId: string; url: string; title?: string; summary?: string; reads: number; lastReadAt: string | null }>;
+ // The topic's watch, once it has been watched; `sentence` says what it is doing.
+ watch?: { on: boolean; sentence: string; paused?: { reason: string }; ended?: { reason: string } };
};
type PostRow = {
@@ -36,7 +40,11 @@ type PostRow = {
media?: { count: number; kinds?: string[]; thumbnail?: string };
topic: string;
reads?: Array<{ read: string; trendId: string; at: string }>;
- judgement?: { state: string; note?: string; by: string; at: string };
+ judgement?: { state: string; note?: string; by: string; at: string; from?: string };
+ thread?: string;
+ // A page that showed it before did not show it at `at` (never "deleted").
+ gone?: { at: string; read: string; trendId: string };
+ capture?: { at: string; state: string; shot: boolean; files: number; mediaState: string; mediaOwed?: string };
};
type ListingBody = { name?: string; topics?: Topic[]; posts?: PostRow[]; total?: number; reads?: string[] };
@@ -53,6 +61,7 @@ export function renderXTrendingTopics(slug: string, body: ListingBody): string {
lines.push(` ${s.url}${s.title ? ` "${s.title}"` : ""} · read ${s.reads}×, last ${day(s.lastReadAt)} UTC`);
if (s.summary) lines.push(` X's summary: ${s.summary}`);
}
+ if (t.watch) lines.push(` watch: ${t.watch.sentence}`);
}
if (body.reads?.length) lines.push(`Saved reads (newest first): ${body.reads.join(", ")}`);
return lines.join("\n");
@@ -76,9 +85,19 @@ export function renderXTrendingPosts(slug: string, body: ListingBody, topic?: st
lines.push(` ${p.url}`);
lines.push(` ${p.text.replace(/\s*\n\s*/g, " / ")}`);
if (reads) lines.push(` shown by: ${reads}`);
- if (p.media?.thumbnail) lines.push(` captured: ${p.media.thumbnail}`);
+ if (p.thread && p.thread !== p.id) lines.push(` in thread ${p.thread}`);
+ if (p.gone) lines.push(` gone from the page at ${day(p.gone.at)} UTC (read ${p.gone.read}; the page stopped showing it, which is not "deleted")`);
+ if (p.capture) {
+ const owed = p.capture.mediaOwed === "kept" ? "; more media owed once it is kept" : p.capture.mediaOwed === "next" ? "; more media owed to the next capture" : "";
+ lines.push(
+ ` captured ${day(p.capture.at)} UTC: ${p.capture.state}${p.capture.shot ? ", shot" : ""}, ${p.capture.files} media file${p.capture.files === 1 ? "" : "s"}${owed}` +
+ (p.media?.thumbnail ? ` (${p.media.thumbnail})` : ""),
+ );
+ } else if (p.media?.thumbnail) lines.push(` captured: ${p.media.thumbnail}`);
if (p.judgement) {
- lines.push(` judged ${p.judgement.state} by ${p.judgement.by} (${day(p.judgement.at)} UTC)${p.judgement.note ? `: ${p.judgement.note}` : ""}`);
+ lines.push(
+ ` judged ${p.judgement.state} by ${p.judgement.by}${p.judgement.from === "thread" ? " (its thread)" : ""} (${day(p.judgement.at)} UTC)${p.judgement.note ? `: ${p.judgement.note}` : ""}`,
+ );
}
}
if (total > posts.length) lines.push(`… ${total - posts.length} more (raise limit, or narrow by topic).`);
@@ -133,7 +152,9 @@ export const X_TRENDING_TOOLS = [
description:
"An X TRENDING LIBRARY's topics: the operator's topics, each with the X trending pages " +
"(x.com/i/trending/<id>) read into it, how often and when, and its post count; and the " +
- "ids of the saved reads. A library is PRIVATE — on no site, in no index, so no other " +
+ "ids of the saved reads; and each topic's WATCH, when it has one — whether it is being " +
+ "read again on an interval, until when, and why it is paused (a watch runs only while " +
+ "X's cookie jar is fresh, so a stale jar pauses it until the operator refreshes). A library is PRIVATE — on no site, in no index, so no other " +
"tool here finds its posts. Read only: a page is read into a library with " +
"`pnpm ops read-x-trending` (one job on X's queue, on a fresh cookie jar). " +
"Needs ARCHILYZER_EDITOR_URL and WORKER_TOKEN.",
@@ -151,7 +172,10 @@ export const X_TRENDING_TOOLS = [
description:
"The posts of an X TRENDING LIBRARY (or of one of its topics): each post's id, author, " +
"date, words, media by kind and count, the reads that showed it, its topic, and — once " +
- "it has them — its captured picture's path and its judgement (keep / drop / later; none is undecided) — the " +
+ "it has them — the thread it belongs to, what its capture holds (and what media it is " +
+ "still owed), its judgement (keep / drop / later; none is undecided; its own, or its " +
+ "thread's), and whether a page stopped showing it (\"gone from the page at <time>\": a " +
+ "trending page is a ranked list, so this is NOT a claim the post was deleted) — the " +
"newest read's first, in the order the page showed them. For looking through what a " +
"trending page held before anything is archived or published. PRIVATE material: never " +
"quote it into a published report unless the operator says so. Read only. " +
diff --git a/mcp/src/xTrendingPrivacy.test.ts b/mcp/src/xTrendingPrivacy.test.ts
@@ -41,7 +41,7 @@ const { getPaths } = await import("yt-dlp-transcript-common/lib/paths");
const { buildIndex } = await import("yt-dlp-transcript-common/controller/buildIndex");
const { main: composeSite } = await import("yt-dlp-transcript-common/bin/compose-site");
const { writePosts } = await import("yt-dlp-transcript-common/lib/posts-server");
-const { recordXTrendingRead, writeXTrendingPosts, trendingReadDir } = await import("yt-dlp-transcript-common/lib/xTrending/store");
+const { recordXTrendingRead, writeXTrendingPosts, trendingReadDir, readXTrendingTopics } = await import("yt-dlp-transcript-common/lib/xTrending/store");
const { createCorpusTools } = await import("./callTool");
const paths = getPaths();
@@ -50,7 +50,10 @@ const PUBLIC_X = "kettle-org-x";
const PUBLIC_ID = "1900000000000005001";
const PUBLIC_POST = "an ordinary archived post about kettles";
const LIB_ID = "1900000000000006001";
-const MARKS = ["trendpostmarkerq7x", "trendhandlemarkerz4k", "trendtopicmarkerw2p", "trendrawmarkerj9m"];
+const { plantSlice2Library, SLICE2_MARK_LIST } = await import("yt-dlp-transcript-common/lib/xTrending/__fixtures__/slice2Library");
+// The last five are lane x-trending-2's: a judgement's note, a captured media
+// file's bytes and address, the capture's context, the shot.
+const MARKS = ["trendpostmarkerq7x", "trendhandlemarkerz4k", "trendtopicmarkerw2p", "trendrawmarkerj9m", ...SLICE2_MARK_LIST];
const READ = "tr-01JA0000000000000000000000";
const writeJson = (file: string, value: unknown) => {
@@ -98,6 +101,8 @@ await recordXTrendingRead(libRoot, {
});
mkdirSync(trendingReadDir(libRoot, READ), { recursive: true });
writeFileSync(path.join(trendingReadDir(libRoot, READ), "responses.jsonl"), `${JSON.stringify({ n: 1, op: "Op", status: 200, body: { t: `kettles ${MARKS[3]}` } })}\n`);
+// What a keep, a capture and a watch leave (lane x-trending-2).
+await plantSlice2Library(libRoot, { postId: LIB_ID, topicId: (await readXTrendingTopics(libRoot))[0].id });
// Written by hand, naming the library (the site writer would refuse it).
writeJson(path.join(paths.sitesDir, "priv", "site.json"), {
siteId: "priv", siteTitle: "priv", siteDescription: "fixture", headerTitle: "priv", homeTagline: "",
@@ -148,6 +153,9 @@ test("every read-only corpus tool over the composed site: the account's post, ne
assert.ok(!text.includes(mark), `${tool}: answers with ${mark}`);
}
assert.ok(!text.includes("responses.jsonl") && !text.includes(READ), `${tool}: names a raw capture`);
+ for (const name of ["judgements.json", "media-index.json", "media-store", "watch.json", "posts-media"]) {
+ assert.ok(!text.includes(name), `${tool}: names ${name}`);
+ }
}
// Asked for by id, the library's post is not found.
for (const tool of ["get_post_library", "get_post_library_named", "get_thread_library"]) {
diff --git a/umtool/lib/report/xTrendingLibrary.test.mjs b/umtool/lib/report/xTrendingLibrary.test.mjs
@@ -32,6 +32,19 @@ test("the post search, the channels offered and the reels' archive reader find n
await writeFile(path.join(channels, "trending-lib", "trending", "posts", "2026-11.jsonl"), JSON.stringify(row("trending-lib", "1900000000000006001", "trend_author", "kettles trendmarkerq7x")) + "\n");
await writeFile(path.join(channels, "trending-lib", "trending", "posts-archive"), "twitter 1900000000000006001\n");
+ // Lane x-trending-2: the library's post is kept, captured and watched —
+ // a judgement, a capture record, a shot, a media file, the store, a watch.
+ const lib = path.join(channels, "trending-lib", "trending");
+ await mkdir(path.join(lib, "posts-media", "1900000000000006001"), { recursive: true });
+ await mkdir(path.join(lib, "media-store", "ab"), { recursive: true });
+ await writeFile(path.join(lib, "posts-media", "1900000000000006001", "shot.png"), "shot trendshotmarkert6b");
+ await writeFile(path.join(lib, "posts-media", "1900000000000006001", "1900000000000006001_1.jpg"), "picture trendmediamarkerk8d");
+ await writeFile(path.join(lib, "posts-media", "1900000000000006001", "capture.json"), JSON.stringify({ version: 1, id: "1900000000000006001", state: "captured", mediaState: "ok", media: [] }));
+ await writeFile(path.join(lib, "media-store", "ab", `${"ab".repeat(32)}.jpg`), "picture trendmediamarkerk8d");
+ await writeFile(path.join(lib, "media-index.json"), JSON.stringify({ version: 1, blobs: {}, oversize: {} }));
+ await writeFile(path.join(lib, "judgements.json"), JSON.stringify({ version: 1, posts: { "1900000000000006001": { state: "keep", note: "kept trendnotemarkerh3v", by: "operator", at: "2026-11-18T10:00:00.000Z" } }, threads: {} }));
+ await writeFile(path.join(lib, "watch.json"), JSON.stringify({ version: 1, topics: {} }));
+
assert.deepEqual((await postChannels(channels, null)).map((c) => c.slug), ["kettle-org-x"]);
const control = await searchPostArchive(channels, "kettle-org-x", "kettles");
assert.equal(control.total, 1);
@@ -39,6 +52,16 @@ test("the post search, the channels offered and the reels' archive reader find n
assert.deepEqual(await searchPostArchive(channels, "trending-lib", ""), { slug: "trending-lib", archive: false, hits: [], total: 0 });
assert.equal((await readPostsArchive(channels, "kettle-org-x")).length, 1);
assert.deepEqual(await readPostsArchive(channels, "trending-lib"), []);
+ // Nothing any of them answered carries the kept post, its note or its media.
+ const answered = JSON.stringify([
+ await postChannels(channels, null),
+ await searchPostArchive(channels, "trending-lib", "kettles"),
+ await searchPostArchive(channels, "trending-lib", "trendnotemarkerh3v"),
+ await readPostsArchive(channels, "trending-lib"),
+ ]);
+ for (const leak of ["trendnotemarkerh3v", "trendmediamarkerk8d", "trendshotmarkert6b", "posts-media", "media-store", "judgements", "1900000000000006001"]) {
+ assert.ok(!answered.includes(leak), `a reader answered with ${leak}`);
+ }
} finally {
await rm(channels, { recursive: true, force: true });
}