Archilyzer · Source

archilyzer

Archilyzer
git clone https://archilyzer.pages.dev/source/archilyzer.git
Log | Files | Refs | README | LICENSE

commit bc71d1e1f3f669ca72ccdd35ceb0e7a6d2c0b861
parent 5aedbbf9c579b329b598776423e1f6cc1ada237d
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Tue, 17 Nov 2026 22:52:21 -0500

x-trending review 2 (N9): a library's captured media is looked for under trending/

firstCapturedThumbnail reads channels/<lib>/trending/posts-media/<id>/ (where slice
2 will write), not the channel's own posts-media/, which umtool and the report
media read for an ordinary posts channel. A pin scans the lane's modules: none uses
the posts channel's media layout or names posts-media but the store. Both tests
were seen red first.

Co-Authored-By: Claude <noreply@anthropic.com>

Diffstat:
MCOMMANDS.md | 4++--
Mcommon/lib/xTrending/store.test.ts | 46++++++++++++++++++++++++++++++++++++++++++----
Mcommon/lib/xTrending/store.ts | 22++++++++++++++++------
Meditor/app/api/ops/trending/route.ts | 6+++---
Mmcp/src/xTrending.test.ts | 4++--
Mscripts/archilyzer-ops.mjs | 4++--
6 files changed, 67 insertions(+), 19 deletions(-)

diff --git a/COMMANDS.md b/COMMANDS.md @@ -378,8 +378,8 @@ get trending <slug> [--topic <topicId>] [--limit <n>] is an X trending 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 + (trending/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, diff --git a/common/lib/xTrending/store.test.ts b/common/lib/xTrending/store.test.ts @@ -223,10 +223,16 @@ test("a row carries its first captured picture and its judgement, once there are await writeXTrendingPosts(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. + // A library's media lives under trending/ (review 2 N9), never in the + // channel's own posts-media/, which is planted here to prove it is not read. 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"); + mkdirSync(path.join(dir, "trending", "posts-media", id), { recursive: true }); + for (const f of files) writeFileSync(path.join(dir, "trending", "posts-media", id, f), "x"); } + mkdirSync(path.join(dir, "posts-media", "403"), { recursive: true }); + writeFileSync(path.join(dir, "posts-media", "403", "shot.png"), "x"); + mkdirSync(path.join(dir, "posts-media", "402"), { recursive: true }); + writeFileSync(path.join(dir, "posts-media", "402", "402_9.jpg"), "x"); writeFileSync( path.join(dir, "trending", "judgements.json"), JSON.stringify({ @@ -240,11 +246,43 @@ test("a row carries its first captured picture and its judgement, once there are ); 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.equal(by["401"].media.thumbnail, "trending/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"); + assert.equal(by["402"].media.thumbnail, "trending/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); }); + +// Review 2 N9: nothing of the lane reads or writes channels/<lib>/posts-media. +test("no module of the lane reaches the channel's own posts-media: a library's media is under trending/", async () => { + const { readFileSync: read } = await import("node:fs"); + const repo = path.resolve(import.meta.dirname, "..", "..", ".."); + const lane = [ + "common/lib/xTrending/config.ts", + "common/lib/xTrending/marker.mjs", + "common/lib/xTrending/library-server.ts", + "common/lib/xTrending/store.ts", + "common/social/xTrendingParse.ts", + "common/social/xTrendingRead.ts", + "common/controller/readXTrending.ts", + "editor/app/channels/[slug]/xTrendingActions.ts", + "editor/app/channels/[slug]/components/XTrendingPanel.tsx", + "editor/app/api/ops/read-x-trending/route.ts", + "editor/app/api/ops/trending/route.ts", + "mcp/src/xTrending.ts", + ]; + for (const rel of lane) { + const code = read(path.join(repo, rel), "utf8") + .split("\n") + .filter((l) => !/^\s*(\/\/|\*|\/\*)/.test(l)) + .join("\n"); + assert.ok(!/postsMediaDir\(|postCaptureDir\(|social\/postCapture"/.test(code), `${rel} uses the posts channel's media layout`); + // The only posts-media path the lane builds is the store's, under trending/. + const mentions = code.match(/posts-media|POSTS_MEDIA/g) ?? []; + if (rel !== "common/lib/xTrending/store.ts") assert.deepEqual(mentions, [], `${rel} names posts-media`); + } + const { xTrendingPostsMediaDir } = await import("./store"); + assert.equal(xTrendingPostsMediaDir("/c/lib"), "/c/lib/trending/posts-media"); +}); diff --git a/common/lib/xTrending/store.ts b/common/lib/xTrending/store.ts @@ -39,7 +39,6 @@ import path from "node:path"; import { mkdir, readFile, readdir } from "node:fs/promises"; -import { POSTS_MEDIA_DIRNAME, SHOT_FILENAME } from "../../social/postCapture"; import { readJsonFile, withJsonFileLock, writeFileAtomic, writeJsonAtomic } from "../jsonFile-server"; import { readAllPosts, readSeenPostIds, writePosts, type WritePostsResult } from "../posts-server"; import type { Post } from "../posts"; @@ -155,20 +154,31 @@ export async function readXTrendingJudgements(channelRoot: string): Promise<Reco const IMAGE_FILE = /\.(?:jpe?g|png|webp|gif)$/i; +// WHERE A LIBRARY'S CAPTURED MEDIA LIVES (review 2 N9): under trending/, as +// its posts do — `channels/<lib>/trending/posts-media/<id>/` — never in the +// channel's own `posts-media/`, which umtool and the report media read for an +// ordinary posts channel. Slice 2 writes it; this slice only looks. +const LIBRARY_MEDIA_DIRNAME = "posts-media"; +const LIBRARY_SHOT_FILENAME = "shot.png"; + +export function xTrendingPostsMediaDir(channelRoot: string): string { + return path.join(trendingDir(channelRoot), LIBRARY_MEDIA_DIRNAME); +} + // 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). +// (`trending/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(); + names = (await readdir(path.join(xTrendingPostsMediaDir(channelRoot), 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; + const pick = media ?? (names.includes(LIBRARY_SHOT_FILENAME) ? LIBRARY_SHOT_FILENAME : undefined); + return pick ? `${TRENDING_DIRNAME}/${LIBRARY_MEDIA_DIRNAME}/${id}/${pick}` : undefined; } export type XTrendingSourceRead = { diff --git a/editor/app/api/ops/trending/route.ts b/editor/app/api/ops/trending/route.ts @@ -24,9 +24,9 @@ export const dynamic = "force-dynamic"; // newest read's first, in page order; `total` is the count before the cap. // // 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: +// captured picture's path relative to the channel +// (`trending/posts-media/<id>/<name>` — a library's media is kept under trending/, +// and no route serves it yet), 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) { diff --git a/mcp/src/xTrending.test.ts b/mcp/src/xTrending.test.ts @@ -41,7 +41,7 @@ const LISTING = { createdAt: "2026-11-16T13:00:00.000Z", url: "https://x.com/saucer_fan/status/1900000000000001002", text: "Second.", - media: { count: 0, kinds: [], thumbnail: "posts-media/1900000000000001002/shot.png" }, + media: { count: 0, kinds: [], thumbnail: "trending/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" }, @@ -95,7 +95,7 @@ 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", + " captured: trending/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/scripts/archilyzer-ops.mjs b/scripts/archilyzer-ops.mjs @@ -1299,8 +1299,8 @@ export function usage() { " 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", + " (trending/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,",