Archilyzer · Source

archilyzer

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

commit 2416754fe4d70c8bea6492d067156e0c0639211a
parent c26eb53dfe9007f1467078eeac710fc39560040f
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Wed, 18 Nov 2026 05:47:01 -0500

x-trending review 2 (N2, N5): the operator outranks an agent about a post, by one rule; a failing watch is the operator's to restart

N2: xTrendingEffectiveJudgement is the one rule the writer, the listing and the kept ids use: the operator's entry, post or thread, outranks an agent's about the same post whatever the order in time, and between two of the same hand the post's own outranks the thread's. An agent's post write is skipped whenever the post's thread is the operator's; an agent's older entry under an operator's thread judgement stays in the file and decides nothing. N5: only by operator clears a failing pause, and an enqueue deletes only the refused pause it resolved.

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

Diffstat:
Mcommon/lib/xTrending/judgements.test.ts | 48+++++++++++++++++++++++++++++++++++++++++++++++-
Mcommon/lib/xTrending/judgements.ts | 37++++++++++++++++++++++---------------
Mcommon/lib/xTrending/store.ts | 35+++++++++++++++++++++++++++++------
Mcommon/lib/xTrending/watch.ts | 14++++++++++++++
4 files changed, 112 insertions(+), 22 deletions(-)

diff --git a/common/lib/xTrending/judgements.test.ts b/common/lib/xTrending/judgements.test.ts @@ -3,7 +3,7 @@ import assert from "node:assert/strict"; import { mkdtempSync, readFileSync, rmSync, existsSync } from "node:fs"; import { tmpdir } from "node:os"; import path from "node:path"; -import { judgeXTrending, JUDGED_BY_OPERATOR, NOT_IN_THE_LIBRARY, xTrendingJudgeProblem } from "./judgements"; +import { judgeXTrending, JUDGED_BY_OPERATOR, NOT_IN_THE_LIBRARY, readXTrendingKeptIds, xTrendingJudgeProblem } from "./judgements"; import { listXTrending, readXTrendingJudgementsFile, recordXTrendingRead, writeXTrendingPosts } from "./store"; import type { Post } from "../posts"; @@ -179,3 +179,49 @@ test("M2: an agent cannot override the operator's thread judgement with a post-l await judgeXTrending(other, { by: "operator", set: [{ thread: "501", state: "later" }] }); assert.deepEqual((await judgeXTrending(other, { by: "agent", set: [{ thread: "501", state: "keep" }] })).skipped, [{ thread: "501", reason: JUDGED_BY_OPERATOR }]); }); + +// Review 2 N2: the operator outranks an agent about the same post, whatever the order. +test("N2: an agent's own post entry never outranks the operator's thread entry — not by a later write, not by an older one", async () => { + // The three steps: agent {P, later}; operator {thread, drop}; agent {P, keep}. + const dir = await library("n2-three-steps"); + await judgeXTrending(dir, { by: "agent", set: [{ id: "502", state: "later" }] }); + await judgeXTrending(dir, { by: "operator", set: [{ thread: "501", state: "drop" }] }); + const third = await judgeXTrending(dir, { by: "agent", set: [{ id: "502", state: "keep" }] }); + assert.deepEqual(third.written, []); + assert.deepEqual(third.skipped, [{ id: "502", reason: JUDGED_BY_OPERATOR }]); + assert.deepEqual(third.kept, []); + // The agent's older entry is still in the file, and decides nothing. + assert.equal((await readXTrendingJudgementsFile(dir)).posts["502"].state, "later"); + let row = (await listXTrending(dir)).posts.find((p) => p.id === "502"); + assert.deepEqual([row?.judgement?.state, row?.judgement?.by, row?.judgement?.from], ["drop", "operator", "thread"]); + assert.deepEqual([...(await readXTrendingKeptIds(dir))], []); + + // An OLDER agent keep does not survive the operator's later thread drop. + const older = await library("n2-older-keep"); + assert.deepEqual((await judgeXTrending(older, { by: "agent", set: [{ id: "502", state: "keep" }, { id: "504", state: "keep" }] })).kept, ["502", "504"]); + assert.deepEqual([...(await readXTrendingKeptIds(older))].sort(), ["502", "504"]); + await judgeXTrending(older, { by: "operator", set: [{ thread: "501", state: "drop" }] }); + assert.deepEqual([...(await readXTrendingKeptIds(older))], ["504"]); + row = (await listXTrending(older)).posts.find((p) => p.id === "502"); + assert.deepEqual([row?.judgement?.state, row?.judgement?.by], ["drop", "operator"]); + // The operator lifting the thread judgement lets the agent's suggestion show again. + await judgeXTrending(older, { by: "operator", set: [{ thread: "501", state: "undecided" }] }); + assert.deepEqual([...(await readXTrendingKeptIds(older))].sort(), ["502", "504"]); + + // Two entries of the operator's: the post's own still outranks the thread's, later or not. + const both = await library("n2-operator-both"); + await judgeXTrending(both, { by: "operator", set: [{ id: "502", state: "keep" }] }); + const later = await judgeXTrending(both, { by: "operator", set: [{ thread: "501", state: "drop" }] }); + assert.deepEqual(later.kept, []); + assert.deepEqual([...(await readXTrendingKeptIds(both))], ["502"]); + row = (await listXTrending(both)).posts.find((p) => p.id === "502"); + assert.deepEqual([row?.judgement?.state, row?.judgement?.from], ["keep", undefined]); + // Two of an agent's: the post's own outranks the thread's. + const agents = await library("n2-agent-both"); + await judgeXTrending(agents, { by: "agent", set: [{ thread: "501", state: "drop" }, { id: "503", state: "keep" }] }); + assert.deepEqual([...(await readXTrendingKeptIds(agents))], ["503"]); + // And an agent's thread entry never outranks the operator's entry for a post. + await judgeXTrending(agents, { by: "operator", set: [{ id: "502", state: "keep" }] }); + await judgeXTrending(agents, { by: "agent", set: [{ thread: "501", state: "later" }] }); + assert.deepEqual([...(await readXTrendingKeptIds(agents))].sort(), ["502", "503"]); +}); diff --git a/common/lib/xTrending/judgements.ts b/common/lib/xTrending/judgements.ts @@ -6,12 +6,17 @@ // undecided the entry is REMOVED: no entry is undecided. // // AN AGENT'S JUDGEMENT IS A SUGGESTION. A write `by: "agent"` over an entry the -// operator made is SKIPPED for that id and reported; nothing forces it — and -// "over" means the judgement in force: a post the operator judged through its -// THREAD is the operator's too, so an agent's post-level write for it is -// skipped. (An agent's thread-level write never reaches a post the operator -// judged itself: a post's own entry comes first.) The operator overturns -// anything. `by` is the caller's word: an agent is trusted to say "agent". +// operator made is SKIPPED for that id and reported; nothing forces it. +// +// THE PRECEDENCE IS ONE RULE (store.ts xTrendingEffectiveJudgement): the +// operator's entry, for the post or for its thread, always outranks an +// agent's about the same post, whatever the order in time; between two +// entries of the same hand the post's own outranks its thread's. So an +// agent's post-level write is skipped whenever the post's thread is the +// operator's, and an operator's thread judgement makes an OLDER agent entry +// for one of its posts ineffective at once (it stays in the file as history +// and decides nothing). The operator overturns anything. `by` is the caller's +// word: an agent is trusted to say "agent". // // A THREAD is judged by its root post's id (store.ts xTrendingThreadKey): a // post of it with no judgement of its own is taken to be the thread's. @@ -31,6 +36,7 @@ import { readXTrendingPosts, X_TRENDING_JUDGEMENT_STATES, xTrendingJudgementsPath, + xTrendingEffectiveJudgement, xTrendingThreadOf, type XTrendingJudgement, type XTrendingJudgementState, @@ -125,7 +131,7 @@ export async function judgeXTrending( } return withJsonFileLock(xTrendingJudgementsPath(channelRoot), async () => { const file = await readXTrendingJudgementsFile(channelRoot); - const effective = (id: string) => file.posts[id]?.state ?? file.threads[threadOf.get(id) ?? ""]?.state; + const effective = (id: string) => xTrendingEffectiveJudgement(file.posts[id], file.threads[threadOf.get(id) ?? ""])?.state; const before = new Map([...byId.keys()].map((id) => [id, effective(id)])); const written: XTrendingJudged[] = []; const skipped: XTrendingJudgeSkipped[] = []; @@ -139,13 +145,14 @@ export async function judgeXTrending( } const map = isThread ? file.threads : file.posts; const have: XTrendingJudgement | undefined = map[key]; - // The entry that decides this key's judgement NOW: its own, else — for - // a post — its thread's. An agent replaces neither when the operator - // made it (review 1 M2): a post in a thread the operator judged has the - // operator's judgement, and an agent's post-level entry would take - // precedence over it. - const deciding: XTrendingJudgement | undefined = have ?? (isThread ? undefined : file.threads[threadOf.get(key) ?? ""]); - if (ask.by === "agent" && deciding?.by === "operator") { + // AN AGENT NEVER WRITES WHERE THE OPERATOR HAS DECIDED (review 2 N2): not + // over the operator's entry for this key, and not a post-level entry + // for a post whose THREAD the operator judged — whether or not the post + // has an (agent's) entry of its own already. The operator's judgement + // is the one in force there (xTrendingEffectiveJudgement), and an + // agent's write would only be noise beside it. + const threads = isThread ? undefined : file.threads[threadOf.get(key) ?? ""]; + if (ask.by === "agent" && (have?.by === "operator" || threads?.by === "operator")) { skipped.push({ ...name, reason: JUDGED_BY_OPERATOR }); continue; } @@ -175,7 +182,7 @@ export async function readXTrendingKeptIds(channelRoot: string): Promise<Set<str const byId = new Map(posts.filter((p) => membership[p.id]).map((p) => [p.id, p])); const kept = new Set<string>(); for (const p of byId.values()) { - const state = file.posts[p.id]?.state ?? file.threads[xTrendingThreadOf(p, membership, byId)]?.state; + const state = xTrendingEffectiveJudgement(file.posts[p.id], file.threads[xTrendingThreadOf(p, membership, byId)])?.state; if (state === "keep") kept.add(p.id); } return kept; diff --git a/common/lib/xTrending/store.ts b/common/lib/xTrending/store.ts @@ -182,6 +182,27 @@ export async function readXTrendingJudgements(channelRoot: string): Promise<Reco return (await readXTrendingJudgementsFile(channelRoot)).posts; } +// WHICH JUDGEMENT IS IN FORCE FOR A POST — the ONE rule (review 2 N2), used by +// the writer, the listing and everything that asks whether a post is kept: +// +// - the OPERATOR's entry always outranks an agent's about the same post, +// whichever was written first and whichever is the post's own: an +// operator's judgement of the thread stands over an agent's entry for one +// of its posts; +// - between two entries of the same hand (two of the operator's, or two of +// an agent's), the post's own entry outranks its thread's. +// +// An agent's entry the operator's outranks stays in the file, as history; it +// decides nothing. +export function xTrendingEffectiveJudgement( + own: XTrendingJudgement | undefined, + thread: XTrendingJudgement | undefined, +): (XTrendingJudgement & { from?: "thread" }) | undefined { + if (own && thread && own.by === "agent" && thread.by === "operator") return { ...thread, from: "thread" }; + if (own) return own; + return thread ? { ...thread, from: "thread" } : undefined; +} + // A THREAD'S KEY is its root post's id. The source's own `threadId` when it // names ANOTHER post (X's conversation id) — a normalized X post always has // one, and when the answer gave no conversation id it is the post's own id, @@ -592,6 +613,8 @@ export type XTrendingReadRecord = { endedAt: string; probe: boolean; headed: boolean; + // The read was a watch's tick, not a person's ask. + watch?: true; limits: { scrolls: number; posts: number }; scrolls: number; // Why the scrolling stopped (xTrendingRead.ts TrendingReadStop). @@ -675,7 +698,8 @@ export type XTrendingPostRow = { capture?: XTrendingCaptureSummary; // The thread it belongs to: its root post's id (xTrendingThreadKey). thread: string; - // Its own judgement, else its thread's (`from: "thread"`). Absent: undecided. + // The judgement in force (xTrendingEffectiveJudgement): its own, or its + // thread's (`from: "thread"`). Absent: undecided. judgement?: XTrendingJudgement & { from?: "thread" }; }; @@ -739,11 +763,10 @@ export async function listXTrending( reads: m.seen.map((s) => ({ read: s.read, trendId: s.trendId, at: s.at })), ...(m.gone ? { gone: m.gone } : {}), thread, - ...(judgements.posts[id] - ? { judgement: judgements.posts[id] } - : judgements.threads[thread] - ? { judgement: { ...judgements.threads[thread], from: "thread" as const } } - : {}), + ...(() => { + const judgement = xTrendingEffectiveJudgement(judgements.posts[id], judgements.threads[thread]); + return judgement ? { judgement } : {}; + })(), }); } const rank = (id: string) => { diff --git a/common/lib/xTrending/watch.ts b/common/lib/xTrending/watch.ts @@ -191,6 +191,20 @@ export async function setXTrendingWatch(channelRoot: string, ask: SetWatchAsk): } const until = new Date(ask.now + ask.hours * 3_600_000).toISOString(); const live = watchIsLive(have) ? have : undefined; + // A watch paused for FAILING is the operator's to start again (review 2 + // N5): an agent switching it "on" would be the watch reading into failure + // with nobody having looked. + if (live?.paused?.reason === "failing" && ask.by !== "operator") { + return { + write: false, + result: { + ok: false, + error: + `The watch of "${topic.title}" is paused because its reads kept failing (${live.paused.sentence}) ` + + `Only the operator starts it again: Watch on the topic's page, or watch-trending with "by": "operator".`, + }, + }; + } const watch: XTrendingWatch = { on: true, intervalMinutes: ask.intervalMinutes,