commit 55ee52ba31d02a60e1ede78f7bbcd9bce4951cee
parent 06edae8f3f06a3d2d610b7b8ddd7ba7420cd7c80
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Tue, 17 Nov 2026 20:05:27 -0500
x-trending S1: the listing carries a captured thumbnail and a judgement; key-count pin
A list view (the channel page now, umtool's Posts library in slice 3) gets per post
its first captured picture's path (posts-media/<id>/<name>, once the post is
captured) and its judgement once trending/judgements.json holds one. That file and
the judge-trending body ({slug, by, set: [{id, state, note?, topic?}]}) are
reserved, not written yet. The store stays a plain common module over the corpus on
disk. channelConfigSchema's key count is 49 with `xTrending`.
Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat:
8 files changed, 149 insertions(+), 25 deletions(-)
diff --git a/COMMANDS.md b/COMMANDS.md
@@ -373,11 +373,14 @@ get cookies [fresh] is the /cookies screen's rows, one per service the
get trending <slug> [--topic <topicId>] [--limit <n>] is an X trending
library's topics and posts, read from its own files (a library is in no
index): topics [{id, title, posts, sources: [{trendId, url, reads,
- lastReadAt}]}], posts [{id, author, createdAt, url, text, media: {count,
- kinds}, topic, reads: [{read, trendId, at}]}] (the newest read's first,
- in page order; --limit 1-500, default 100; total is the count before
- it) and reads (the saved reads' ids, newest first). Never the raw
- capture, a cookie or a token.
+ lastReadAt}]}], posts [{id, author, authorName, createdAt, url, text,
+ media: {count, kinds, thumbnail?}, topic, reads: [{read, trendId, at}],
+ judgement?}] (the newest read's first, in page order; --limit 1-500,
+ default 100; total is the count before it) and reads (the saved reads'
+ ids, newest first). thumbnail is a captured post's first picture
+ (posts-media/<id>/<name>, relative to the channel); judgement is {state:
+ keep | drop | undecided, note?, by, at} once a post has one. Never the
+ raw capture, a cookie or a token.
get x-run [<run id>] is the X run as /review's X run console shows it:
the latest run (or the one named) — each channel's status (queued,
running, done with its new posts, deferred, failed), "summary" ("N
diff --git a/common/lib/channelConfigSchema.test.ts b/common/lib/channelConfigSchema.test.ts
@@ -39,7 +39,7 @@ test("one key list: docs = coercions = schema shape, sync-state keys inside it",
assert.deepEqual(Object.keys(CHANNEL_CONFIG_COERCIONS), [...CHANNEL_CONFIG_KEYS]);
assert.deepEqual(Object.keys(channelConfigObjectSchema.shape), [...CHANNEL_CONFIG_KEYS]);
assert.deepEqual(Object.keys(CHANNEL_CONFIG_FIELD_DOCS), [...CHANNEL_CONFIG_KEYS]);
- assert.equal(CHANNEL_CONFIG_KEYS.length, 48); // 2026-11-13: `excludeFromCompaction`; 2026-11-11: `cleanAfterCaptureUnverified`; lane/local-media: opt-in `localMedia`; demo epic D1: `remoteOnly`, `remoteArchive`, `remoteUrl`
+ assert.equal(CHANNEL_CONFIG_KEYS.length, 49); // lane x-trending: `xTrending`; 2026-11-13: `excludeFromCompaction`; 2026-11-11: `cleanAfterCaptureUnverified`; lane/local-media: opt-in `localMedia`; demo epic D1: `remoteOnly`, `remoteArchive`, `remoteUrl`
assert.equal(sameKeys, true);
assert.equal(fits, true);
for (const k of CHANNEL_SYNC_STATE_KEYS) assert.ok(CHANNEL_CONFIG_KEYS.includes(k), k);
diff --git a/common/lib/xTrending/store.test.ts b/common/lib/xTrending/store.test.ts
@@ -1,6 +1,6 @@
import { after, test } from "node:test";
import assert from "node:assert/strict";
-import { mkdirSync, mkdtempSync, readFileSync, rmSync } from "node:fs";
+import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import path from "node:path";
import {
@@ -217,3 +217,34 @@ test("the listing gives each post's words, author, media, reads and topic — an
test("an empty library lists nothing", async () => {
assert.deepEqual(await listXTrending(root("empty")), { topics: [], posts: [], total: 0, reads: [] });
});
+
+test("a row carries its first captured picture and its judgement, once there are any", async () => {
+ const dir = root("captured");
+ await writePosts(dir, [post("401", "a", "one"), post("402", "b", "two"), post("403", "c", "three")]);
+ await recordXTrendingRead(dir, { readId: READ_A, at: "2026-11-17T10:00:00.000Z", ref: REF, topic: "T", postIds: ["401", "402", "403"], added: 3 });
+ // 401: a capture with an attached image and a shot; 402: a shot alone; 403: none.
+ for (const [id, files] of [["401", ["shot.png", "401_2.jpg", "401_1.jpg", "capture.json", "shot-thread.png"]], ["402", ["shot.png", "capture.json", "402_1.mp4"]]] as const) {
+ mkdirSync(path.join(dir, "posts-media", id), { recursive: true });
+ for (const f of files) writeFileSync(path.join(dir, "posts-media", id, f), "x");
+ }
+ writeFileSync(
+ path.join(dir, "trending", "judgements.json"),
+ JSON.stringify({
+ version: 1,
+ posts: {
+ "401": { state: "keep", note: "the opening", by: "agent", at: "2026-11-17T11:00:00.000Z" },
+ "402": { state: "maybe", by: "agent", at: "2026-11-17T11:00:00.000Z" },
+ "403": { state: "drop", by: "nobody", at: "2026-11-17T11:00:00.000Z" },
+ },
+ }),
+ );
+ const { posts } = await listXTrending(dir);
+ const by = Object.fromEntries(posts.map((p) => [p.id, p]));
+ assert.equal(by["401"].media.thumbnail, "posts-media/401/401_1.jpg");
+ assert.deepEqual(by["401"].judgement, { state: "keep", note: "the opening", by: "agent", at: "2026-11-17T11:00:00.000Z" });
+ assert.equal(by["402"].media.thumbnail, "posts-media/402/shot.png");
+ // An ill-shaped judgement is no judgement.
+ assert.equal(by["402"].judgement, undefined);
+ assert.equal(by["403"].media.thumbnail, undefined);
+ assert.equal(by["403"].judgement, undefined);
+});
diff --git a/common/lib/xTrending/store.ts b/common/lib/xTrending/store.ts
@@ -22,12 +22,22 @@
// never moves one out of the topic it is in.
//
// The listing reads these files and the posts shards — never the index (the
-// library is in no index build).
+// library is in no index build). It is a plain module over the corpus on
+// disk, with no editor-only import, so umtool's Posts library page (slice 3)
+// reads a library exactly as the editor does.
+//
+// channels/<lib>/trending/judgements.json RESERVED for slice 3: post id →
+// {state: "keep" | "drop" | "undecided", note?, by: "agent" |
+// "operator", at}. Written by ONE writer, the editor's `judge-trending`
+// ({slug, by, set: [{id, state, note?, topic?}]}), not built yet; the
+// listing already reads it, so a row carries its judgement once one
+// exists.
//
// SERVER-ONLY (node:fs).
import path from "node:path";
import { readdir } from "node:fs/promises";
+import { POSTS_MEDIA_DIRNAME, SHOT_FILENAME } from "../../social/postCapture";
import { readJsonFile, withJsonFileLock, writeJsonAtomic } from "../jsonFile-server";
import { readAllPosts } from "../posts-server";
import type { Post } from "../posts";
@@ -66,6 +76,59 @@ function membershipPath(channelRoot: string): string {
export type XTrendingMediaKind = "image" | "video" | "gif";
export type XTrendingMedia = { count: number; kinds: XTrendingMediaKind[] };
+function judgementsPath(channelRoot: string): string {
+ return path.join(trendingDir(channelRoot), "judgements.json");
+}
+
+export type XTrendingJudgementState = "keep" | "drop" | "undecided";
+export const X_TRENDING_JUDGEMENT_STATES: readonly XTrendingJudgementState[] = ["keep", "drop", "undecided"];
+
+// A post's judgement (slice 3 writes it; this slice only reads it).
+export type XTrendingJudgement = {
+ state: XTrendingJudgementState;
+ note?: string;
+ by: "agent" | "operator";
+ at: string;
+};
+
+// judgements.json, or {} while there is none. Ill-shaped entries are dropped.
+export async function readXTrendingJudgements(channelRoot: string): Promise<Record<string, XTrendingJudgement>> {
+ const read = await readJsonFile(judgementsPath(channelRoot));
+ const posts = read.ok ? (read.value as { posts?: unknown } | null)?.posts : null;
+ if (!posts || typeof posts !== "object" || Array.isArray(posts)) return {};
+ const out: Record<string, XTrendingJudgement> = {};
+ for (const [id, j] of Object.entries(posts as Record<string, Partial<XTrendingJudgement> | null>)) {
+ if (!/^\d+$/.test(id) || !j || typeof j !== "object") continue;
+ if (!X_TRENDING_JUDGEMENT_STATES.includes(j.state as XTrendingJudgementState)) continue;
+ if ((j.by !== "agent" && j.by !== "operator") || typeof j.at !== "string" || !j.at) continue;
+ out[id] = {
+ state: j.state as XTrendingJudgementState,
+ ...(typeof j.note === "string" && j.note ? { note: j.note } : {}),
+ by: j.by,
+ at: j.at,
+ };
+ }
+ return out;
+}
+
+const IMAGE_FILE = /\.(?:jpe?g|png|webp|gif)$/i;
+
+// A captured post's first picture, as a path relative to the channel
+// (`posts-media/<id>/<name>`): its first attached image, else its screenshot.
+// Undefined while the post has no capture (archiving is slice 2).
+export async function firstCapturedThumbnail(channelRoot: string, id: string): Promise<string | undefined> {
+ if (!/^\d+$/.test(id)) return undefined;
+ let names: string[];
+ try {
+ names = (await readdir(path.join(channelRoot, POSTS_MEDIA_DIRNAME, id))).sort();
+ } catch {
+ return undefined;
+ }
+ const media = names.find((n) => IMAGE_FILE.test(n) && !n.startsWith("shot") && !n.startsWith("article"));
+ const pick = media ?? (names.includes(SHOT_FILENAME) ? SHOT_FILENAME : undefined);
+ return pick ? `${POSTS_MEDIA_DIRNAME}/${id}/${pick}` : undefined;
+}
+
export type XTrendingSourceRead = {
// The read's id (`reads/<id>/`), when it ran, the posts it showed and how
// many of them were new to the library.
@@ -364,9 +427,10 @@ export type XTrendingTopicRow = {
}>;
};
-// One post of the library, as the listing gives it: what it says, who said
-// it, what media it carries, which reads showed it, and its topic. Never the
-// raw capture.
+// One post of the library, as the listing gives it — everything a list view
+// needs: what it says, who said it and when, what media it carries (and the
+// first picture's path once the post is captured), which reads showed it, its
+// topic, and its judgement once it has one. Never the raw capture.
export type XTrendingPostRow = {
id: string;
author: string;
@@ -374,9 +438,10 @@ export type XTrendingPostRow = {
createdAt: string;
url: string;
text: string;
- media: XTrendingMedia;
+ media: XTrendingMedia & { thumbnail?: string };
topic: string;
reads: Array<{ read: string; trendId: string; at: string }>;
+ judgement?: XTrendingJudgement;
};
export type XTrendingListing = {
@@ -408,10 +473,11 @@ export async function listXTrending(
channelRoot: string,
opts: { topic?: string; limit?: number; posts?: ReadonlyArray<Post> } = {},
): Promise<XTrendingListing> {
- const [topics, membership, reads] = await Promise.all([
+ const [topics, membership, reads, judgements] = await Promise.all([
readXTrendingTopics(channelRoot),
readXTrendingMembership(channelRoot),
listXTrendingReadIds(channelRoot),
+ readXTrendingJudgements(channelRoot),
]);
const archived = new Map((opts.posts ?? (await readAllPosts(channelRoot))).map((p) => [p.id, p]));
const count = new Map<string, number>();
@@ -433,6 +499,7 @@ export async function listXTrending(
media: m.media ?? { count: post.mediaCount ?? 0, kinds: [] },
topic: m.topic,
reads: m.seen.map((s) => ({ read: s.read, trendId: s.trendId, at: s.at })),
+ ...(judgements[id] ? { judgement: judgements[id] } : {}),
});
}
const rank = (id: string) => {
@@ -460,7 +527,13 @@ export async function listXTrending(
lastReadAt: s.reads.reduce<string | null>((a, r) => (a === null || r.at > a ? r.at : a), null),
})),
})),
- posts: rows.slice(0, limit),
+ // The thumbnail is looked up for the rows returned only (one readdir each).
+ posts: await Promise.all(
+ rows.slice(0, limit).map(async (row) => {
+ const thumbnail = await firstCapturedThumbnail(channelRoot, row.id);
+ return thumbnail ? { ...row, media: { ...row.media, thumbnail } } : row;
+ }),
+ ),
total: rows.length,
reads,
};
diff --git a/editor/app/api/ops/trending/route.ts b/editor/app/api/ops/trending/route.ts
@@ -12,7 +12,8 @@ export const dynamic = "force-dynamic";
// -> { ok, slug, name, topics: [{id, title, posts, sources: [{trendId, url,
// title?, summary?, reads, lastReadAt}]}],
// posts: [{id, author, authorName?, createdAt, url, text,
-// media: {count, kinds}, topic, reads: [{read, trendId, at}]}],
+// media: {count, kinds, thumbnail?}, topic,
+// reads: [{read, trendId, at}], judgement?}],
// total, reads: [<readId>, …] }
//
// An X trending library's topics and posts (lane x-trending) — `pnpm ops get
@@ -22,8 +23,12 @@ export const dynamic = "force-dynamic";
// the posts to one topic; `limit` (default 100, at most 500) caps them, the
// newest read's first, in page order; `total` is the count before the cap.
//
-// NEVER the raw capture, a cookie or a token: a post is its id, author, words,
-// media by kind, the reads that showed it and its topic.
+// Everything a list view needs per post. `media.thumbnail` is the first
+// captured picture's path relative to the channel (`posts-media/<id>/<name>`,
+// served by /api/channels/<slug>/posts-media/<id>/<name>), present once the
+// post is captured; `judgement` ({state: keep | drop | undecided, note?, by:
+// agent | operator, at}) once it has one (written by `judge-trending`, a later
+// slice). NEVER the raw capture, a cookie or a token.
export async function GET(request: Request) {
const denied = opsAuth(request);
if (denied) return denied;
diff --git a/mcp/src/xTrending.test.ts b/mcp/src/xTrending.test.ts
@@ -41,9 +41,10 @@ const LISTING = {
createdAt: "2026-11-16T13:00:00.000Z",
url: "https://x.com/saucer_fan/status/1900000000000001002",
text: "Second.",
- media: { count: 0, kinds: [] },
+ media: { count: 0, kinds: [], thumbnail: "posts-media/1900000000000001002/shot.png" },
topic: "kettle-festival",
reads: [{ read: READ, trendId: "1900000000000000001", at: "2026-11-17T10:00:00.000Z" }],
+ judgement: { state: "keep", note: "the reply everyone quotes", by: "agent", at: "2026-11-17T11:00:00.000Z" },
},
],
total: 5,
@@ -94,6 +95,8 @@ test("x_trending_posts: each post's id, author, words, media, reads and topic",
" https://x.com/saucer_fan/status/1900000000000001002",
" Second.",
` shown by: ${READ} (2026-11-17 10:00 UTC)`,
+ " captured: posts-media/1900000000000001002/shot.png",
+ " judged keep by agent (2026-11-17 11:00 UTC): the reply everyone quotes",
"… 3 more (raise limit, or narrow by topic).",
].join("\n"),
);
diff --git a/mcp/src/xTrending.ts b/mcp/src/xTrending.ts
@@ -33,9 +33,10 @@ type PostRow = {
createdAt: string;
url: string;
text: string;
- media?: { count: number; kinds?: string[] };
+ 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 };
};
type ListingBody = { name?: string; topics?: Topic[]; posts?: PostRow[]; total?: number; reads?: string[] };
@@ -75,6 +76,10 @@ 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.judgement) {
+ lines.push(` judged ${p.judgement.state} by ${p.judgement.by} (${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).`);
return lines.join("\n");
@@ -145,7 +150,8 @@ export const X_TRENDING_TOOLS = [
name: "x_trending_posts",
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, and its topic — the " +
+ "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 / undecided) — 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/scripts/archilyzer-ops.mjs b/scripts/archilyzer-ops.mjs
@@ -1294,11 +1294,14 @@ export function usage() {
"get trending <slug> [--topic <topicId>] [--limit <n>] is an X trending",
" library's topics and posts, read from its own files (a library is in no",
" index): topics [{id, title, posts, sources: [{trendId, url, reads,",
- " lastReadAt}]}], posts [{id, author, createdAt, url, text, media: {count,",
- " kinds}, topic, reads: [{read, trendId, at}]}] (the newest read's first,",
- " in page order; --limit 1-500, default 100; total is the count before",
- " it) and reads (the saved reads' ids, newest first). Never the raw",
- " capture, a cookie or a token.",
+ " lastReadAt}]}], posts [{id, author, authorName, createdAt, url, text,",
+ " media: {count, kinds, thumbnail?}, topic, reads: [{read, trendId, at}],",
+ " judgement?}] (the newest read's first, in page order; --limit 1-500,",
+ " default 100; total is the count before it) and reads (the saved reads'",
+ " ids, newest first). thumbnail is a captured post's first picture",
+ " (posts-media/<id>/<name>, relative to the channel); judgement is {state:",
+ " keep | drop | undecided, note?, by, at} once a post has one. Never the",
+ " raw capture, a cookie or a token.",
"get x-run [<run id>] is the X run as /review's X run console shows it:",
" the latest run (or the one named) — each channel's status (queued,",
" running, done with its new posts, deferred, failed), \"summary\" (\"N",