Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

refactor(pages): get_page's quarantine read policy lives in get-page-projection.ts (readQuarantined), keeping pages.ts under its ceiling (#6259)

time-attack2a1ee890572d
diff --git a/src/core/ops/get-page-projection.ts b/src/core/ops/get-page-projection.ts
index 2ee1508335..6a23030aee 100644
--- a/src/core/ops/get-page-projection.ts
+++ b/src/core/ops/get-page-projection.ts
@@ -1,6 +1,8 @@
import type { Page } from '../types.ts';
import { serializePageToMarkdown } from '../markdown.ts';
-import { isQuarantined, QUARANTINE_KEY } from '../quarantine.ts';
+import { isQuarantined, pageQuarantinedNotice, QUARANTINE_KEY } from '../quarantine.ts';
+import { hasScope } from '../scope.ts';
+import type { OperationContext } from './contract.ts';
/** #6259: how a get_page reader sees a page the content-quality gate hid as junk. */
export interface QuarantinedView { reason: string; detail: string; assessed_at: string | null; body_omitted: boolean }
@@ -19,6 +21,13 @@ export function quarantinedView(page: Pick<Page, 'frontmatter'>, reader: { remot
}
+/** get_page's read of a quarantined page: its view for this caller (null when not quarantined), with the safety notice emitted. */
+export function readQuarantined(ctx: Pick<OperationContext, 'remote' | 'auth' | 'emitNotice'>, page: Pick<Page, 'slug' | 'frontmatter'>, includeQuarantined: boolean): QuarantinedView | null {
+ const view = quarantinedView(page, { remote: ctx.remote !== false, admin: hasScope(ctx.auth?.scopes ?? [], 'admin'), includeQuarantined });
+ if (view) ctx.emitNotice?.(pageQuarantinedNotice(page.slug, view, 'read'));
+ return view;
+}
+
export interface GetPageProjectionOpts {
revision: string;
tags: string[];
diff --git a/src/core/ops/pages.ts b/src/core/ops/pages.ts
index 26603ef788..f3c0f069a2 100644
--- a/src/core/ops/pages.ts
+++ b/src/core/ops/pages.ts
@@ -16,11 +16,10 @@ import type { Page } from '../types.ts';
import { decodeDeepResearchId, deepResearchPageUrl } from '../deep-research-id.ts';
import { PageSnapshotAmbiguousError, type PageSnapshot } from '../page-state/types.ts';
import { serializePageToMarkdown } from '../markdown.ts';
-import { projectGetPage, quarantinedView } from './get-page-projection.ts';
-import { hasScope } from '../scope.ts';
+import { projectGetPage, readQuarantined } from './get-page-projection.ts';
import { isAutoLinkEnabled } from '../link-extraction.ts';
import { sanitizeRemoteBody } from '../remote-body.ts';
-import { getContentFlag, pageQuarantinedNotice } from '../quarantine.ts';
+import { getContentFlag } from '../quarantine.ts';
import { fileHeldField, readHeldPages } from '../persistence/held-reads.ts';
import { bumpLastRetrievedAt } from '../last-retrieved.ts';
import { resolveExcludePrivatePages, isPrivatePage, findPrivateOnlySlugs } from '../search/private-visibility.ts';
@@ -176,11 +175,8 @@ const get_page: Operation = {
// inside bumpLastRetrievedAt (D2).
bumpLastRetrievedAt(ctx.engine, [page.id]);
- // #2200: resolve tags against the concrete page's source. `sourceOpts` may
- // be { sourceIds:[...] } (federated) with no scalar sourceId, which getTags
- // would otherwise fall back to 'default' for — the wrong source for a
- // non-default page. We already hold the resolved page, so its source is
- // unambiguous.
+ // #2200: tags come from the concrete page's source: federated `sourceOpts` has no
+ // scalar sourceId, and getTags would fall back to 'default' (the wrong source).
const tags = snapshot!.tags;
// Only explicitly trusted local reads retain protected body sections.
// Holder grants and page-visibility opt-outs do not bypass this boundary.
@@ -207,9 +203,7 @@ const get_page: Operation = {
// it would double every reader's payload for the round-trip minority.
const timelineEntries = includeTimelineEntries
? await ctx.engine.getTimeline(page.slug, await readPolicyOpts(ctx, { sourceId: page.source_id })) : undefined;
- // #6259: a quarantined page's body is withheld from untrusted readers (admin may ask); every reader gets a notice.
- const quarantined = quarantinedView(page, { remote: isUntrustedReader, admin: hasScope(ctx.auth?.scopes ?? [], 'admin'), includeQuarantined: p.include_quarantined === true });
- if (quarantined) ctx.emitNotice?.(pageQuarantinedNotice(page.slug, quarantined, 'read'));
+ const quarantined = readQuarantined(ctx, page, p.include_quarantined === true); // #6259
return projectGetPage(visibleBody, {
revision: snapshot!.revision, tags, includeContent, contentOnly: (p.content_only as boolean) === true, resolved_slug, content_flag, quarantined,
...(timelineEntries ? { timeline_entries: timelineEntries } : {}),