commit 1bce636f1087d67fee7cb0de59024aeb9f039cac
parent 6ab038d5a9ce90c39e2411ec37a544619db713eb
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Mon, 2 Nov 2026 22:55:41 -0500
editor: capture-posts takes "context" and "contextOnly" -- the ops route, the action, the job replay
The ops route accepts "context" (default on for X) and "contextOnly"; the
action passes both to the controller and the job spec, so a replayed job asks
the same. contextOnly is a run of its own for the nothing-to-capture check and
is refused before any job on a channel that is not X ("Post context is X's
only; <fetcher> reads none.") and together with avatarsOnly (a context-only
run keeps the avatars it shows). The research tool's capture-posts spec takes
contextOnly too. The route unit test and the Bluesky e2e spec cover the keys
and the refusals (a Bluesky record carries no context).
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
6 files changed, 73 insertions(+), 10 deletions(-)
diff --git a/common/lib/report/draft/research/tools.ts b/common/lib/report/draft/research/tools.ts
@@ -128,10 +128,10 @@ export const ACTION_SPECS: Record<AcquisitionAction, ActionSpec> = {
action: "capture-posts",
editorAction: "capture-posts",
description:
- "Capture archived posts of a social channel: a screenshot and the attached media of each id; thread: an X reply also shot with the post it answers above it (shot-thread.png, the replied-to author blurred unless verified); X keeps each author's avatar (posts-media/_avatars/); avatarsOnly: only the avatars, one page per author.",
- properties: { slug: str, ids: strList, shots: bool, media: bool, articles: bool, thread: bool, avatarsOnly: bool },
+ "Capture archived posts of a social channel: a screenshot and the attached media of each id; thread: an X reply also shot with the post it answers above it (shot-thread.png, the replied-to author blurred unless verified); X keeps each author's avatar (posts-media/_avatars/) and each post's context (the post it quotes, the post it answers) in its capture.json; avatarsOnly: only the avatars, one page per author; contextOnly: only the context, one page per post.",
+ properties: { slug: str, ids: strList, shots: bool, media: bool, articles: bool, thread: bool, avatarsOnly: bool, contextOnly: bool },
required: ["slug", "ids"],
- body: (a) => pick(a, ["slug", "ids", "shots", "media", "articles", "thread", "avatarsOnly"]),
+ body: (a) => pick(a, ["slug", "ids", "shots", "media", "articles", "thread", "avatarsOnly", "contextOnly"]),
},
"import-post": {
action: "import-post",
diff --git a/editor/app/api/ops/capture-posts/route.test.ts b/editor/app/api/ops/capture-posts/route.test.ts
@@ -194,3 +194,24 @@ test("avatars and avatarsOnly: booleans; avatarsOnly is a run of its own, X's on
assert.match(bsky.error, /^Avatars are X's only; .* keeps none\.$/);
assert.deepEqual(await readdir(path.join(ROOT, ".jobs")).catch(() => []), []);
});
+
+test("context and contextOnly: booleans; contextOnly is a run of its own, X's only, not with avatarsOnly — refused before any job", async () => {
+ for (const key of ["context", "contextOnly"]) {
+ const bad = await post({ slug: SLUG, ids: ["111"], [key]: "yes" });
+ assert.equal(bad.status, 400, key);
+ assert.match(bad.error, new RegExp(`"${key}" must be a boolean`));
+ }
+ // Both halves off is no refusal for a context-only run: past it, to the
+ // next one (an id not archived).
+ const stray = await post({ slug: SLUG, ids: ["999"], shots: false, media: false, contextOnly: true });
+ assert.equal(stray.status, 400);
+ assert.equal(stray.error, "1 id(s) not in demo-x's posts archive: 999");
+ const both = await post({ slug: SLUG, ids: ["111"], contextOnly: true, avatarsOnly: true });
+ assert.equal(both.status, 400);
+ assert.match(both.error, /^"contextOnly" and "avatarsOnly" are two runs/);
+ // Another platform reads none (the channel the avatars test made).
+ const bsky = await post({ slug: "example-bsky-avatars", ids: ["1"], contextOnly: true });
+ assert.equal(bsky.status, 400);
+ assert.match(bsky.error, /^Post context is X's only; .* reads none\.$/);
+ assert.deepEqual(await readdir(path.join(ROOT, ".jobs")).catch(() => []), []);
+});
diff --git a/editor/app/api/ops/capture-posts/route.ts b/editor/app/api/ops/capture-posts/route.ts
@@ -10,7 +10,7 @@ import {
export const dynamic = "force-dynamic";
-// POST { slug, ids, shots?, media?, force?, articles?, thread?, threadRedact?, avatars?, avatarsOnly?, queueKey? } -> { ok: true, jobId }
+// POST { slug, ids, shots?, media?, force?, articles?, thread?, threadRedact?, avatars?, avatarsOnly?, context?, contextOnly?, queueKey? } -> { ok: true, jobId }
//
// Capture specific archived posts of a social channel: a screenshot of each
// (`shots`, default true) and its attached media (`media`, default true), into
@@ -34,14 +34,24 @@ export const dynamic = "force-dynamic";
// skipped unless `force`. One author's avatar is one page load:
// {"slug":"ObviousRises-x","ids":["<one of his post ids>"],"avatarsOnly":true}
//
+// X also reads each post's CONTEXT off the page the shot loads -- the post it
+// quotes and the post it answers (the archive often names neither) -- into
+// its capture.json's `context`; `context: false` turns that off.
+// `contextOnly: true` loads ONE page per post for that alone (and the avatars
+// it shows): the context written into the post's capture.json, nothing shot,
+// no media, article or thread shot, no availability; a post whose context is
+// already read is skipped unless `force`:
+// {"slug":"ObviousRises-x","ids":["<post id>", …],"contextOnly":true}
+//
// Every refusal is the action's own sentence: both halves off (an
// articles-only run names `articles: true`), a channel that
// is not a social one, a fetcher that cannot capture, an id not in the
-// channel's posts archive, `avatarsOnly` on a channel that is not X.
+// channel's posts archive, `avatarsOnly` or `contextOnly` on a channel that
+// is not X, both of them at once.
export async function POST(request: Request) {
return ops(
request,
- ["slug", "ids", "shots", "media", "force", "articles", "thread", "threadRedact", "avatars", "avatarsOnly", "queueKey"],
+ ["slug", "ids", "shots", "media", "force", "articles", "thread", "threadRedact", "avatars", "avatarsOnly", "context", "contextOnly", "queueKey"],
async (body) => {
const slug = reqSlug(body, "slug");
return jobResponse(
@@ -58,6 +68,8 @@ export async function POST(request: Request) {
threadRedact: body.threadRedact as boolean | Record<string, boolean> | undefined,
avatars: optBool(body, "avatars"),
avatarsOnly: optBool(body, "avatarsOnly"),
+ context: optBool(body, "context"),
+ contextOnly: optBool(body, "contextOnly"),
},
),
);
diff --git a/editor/app/channels/[slug]/socialActions.ts b/editor/app/channels/[slug]/socialActions.ts
@@ -45,6 +45,7 @@ import {
import {
avatarsOnlyProblem,
capturePosts,
+ contextOnlyProblem,
capturePostsProblem,
NOTHING_TO_CAPTURE,
nothingToCapture,
@@ -306,7 +307,9 @@ export async function fetchPostsAction(
// by the rule unless `threadRedact` says otherwise. X keeps the authors'
// avatars from the pages it loads (`avatars: false` turns that off);
// `avatarsOnly` loads one page per archived author for them alone (X only,
-// refused here elsewhere).
+// refused here elsewhere). X reads each post's context (the quoted post, the
+// parent) off the same pages (`context: false` turns that off); `contextOnly`
+// loads one page per post for it alone (X only; not with avatarsOnly).
export async function capturePostsAction(
slug: string,
ids: string[],
@@ -315,13 +318,20 @@ export async function capturePostsAction(
media?: boolean,
force?: boolean,
articles?: boolean,
- more: { thread?: boolean; threadRedact?: ThreadRedactKnob; avatars?: boolean; avatarsOnly?: boolean } = {},
+ more: {
+ thread?: boolean;
+ threadRedact?: ThreadRedactKnob;
+ avatars?: boolean;
+ avatarsOnly?: boolean;
+ context?: boolean;
+ contextOnly?: boolean;
+ } = {},
): Promise<StreamActionResult> {
- const { thread, avatars, avatarsOnly } = more;
+ const { thread, avatars, avatarsOnly, context, contextOnly } = more;
const redact = parseThreadRedact(more.threadRedact);
if (!redact.ok) return { ok: false, error: redact.error };
const threadRedact = redact.value;
- if (nothingToCapture({ shots, media, articles, thread, avatarsOnly })) return { ok: false, error: NOTHING_TO_CAPTURE };
+ if (nothingToCapture({ shots, media, articles, thread, avatarsOnly, contextOnly })) return { ok: false, error: NOTHING_TO_CAPTURE };
const wanted = [...new Set(ids)];
if (wanted.length === 0) return { ok: false, error: "No post ids to capture." };
const paths = getPaths();
@@ -334,6 +344,7 @@ export async function capturePostsAction(
// their captures, on archive.org's queue (release 37 S4).
const pages = isWaybackPagesChannel(config);
if (pages && avatarsOnly) return { ok: false, error: avatarsOnlyProblem(undefined, "a Wayback pages channel")! };
+ if (pages && contextOnly) return { ok: false, error: contextOnlyProblem(undefined, "a Wayback pages channel", { avatarsOnly })! };
if (!pages) {
await registerBuiltinSocialFetchers();
const fetcher = resolveSocialFetcher(config.postFetcher, config.url);
@@ -341,6 +352,8 @@ export async function capturePostsAction(
if (problem) return { ok: false, error: problem };
const nope = avatarsOnly ? avatarsOnlyProblem(fetcher?.platform, fetcher?.label ?? "") : null;
if (nope) return { ok: false, error: nope };
+ const noContext = contextOnly ? contextOnlyProblem(fetcher?.platform, fetcher?.label ?? "", { avatarsOnly }) : null;
+ if (noContext) return { ok: false, error: noContext };
}
const stray = strayCaptureIds(
wanted,
@@ -363,6 +376,8 @@ export async function capturePostsAction(
...(threadRedact !== undefined ? { threadRedact } : {}),
...(avatars !== undefined ? { avatars } : {}),
...(avatarsOnly ? { avatarsOnly } : {}),
+ ...(context !== undefined ? { context } : {}),
+ ...(contextOnly ? { contextOnly } : {}),
},
},
fn: async (onLog, signal, _progress, ctx) => {
@@ -379,6 +394,8 @@ export async function capturePostsAction(
threadRedact,
avatars,
avatarsOnly,
+ context,
+ contextOnly,
onLog,
signal,
drain: ctx.drainSignal,
diff --git a/editor/app/jobs/jobReplayRegistry.ts b/editor/app/jobs/jobReplayRegistry.ts
@@ -445,6 +445,8 @@ export const JOB_REPLAY_HANDLERS: Record<string, ReplayHandler> = {
threadRedact: p.threadRedact as boolean | Record<string, boolean> | undefined,
avatars: bool(p.avatars),
avatarsOnly: bool(p.avatarsOnly),
+ context: bool(p.context),
+ contextOnly: bool(p.contextOnly),
},
);
},
diff --git a/editor/e2e/capture-posts.spec.ts b/editor/e2e/capture-posts.spec.ts
@@ -133,6 +133,17 @@ test("capture-posts on a Bluesky channel: shots cropped to the post, its images,
});
expect(av.status()).toBe(400);
expect(((await av.json()) as { error?: string }).error).toMatch(/^Avatars are X's only; .* keeps none\.$/);
+
+ // So is a post's context (the quoted post, the parent): a Bluesky
+ // record carries none, and a context-only run is refused by name.
+ const textRecord = JSON.parse(await readFile(path.join(media, textOnly, "capture.json"), "utf8")) as { context?: unknown };
+ expect(textRecord.context).toBeUndefined();
+ const ctx = await request.post(`${baseUrl}/api/ops/capture-posts`, {
+ headers: AUTH,
+ data: { slug: SLUG, ids, contextOnly: true },
+ });
+ expect(ctx.status()).toBe(400);
+ expect(((await ctx.json()) as { error?: string }).error).toMatch(/^Post context is X's only; .* reads none\.$/);
} finally {
await rm(originFile, { force: true });
await bsky.close();