Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(links): keep SEGMENT_PIPELINE_VERSIONS.links at 1; move roleTriggerText to machine-sections (#7882)

garrytan4539d7787017
diff --git a/src/core/link-extraction.ts b/src/core/link-extraction.ts
index aa74c4194b..c42c6d63ed 100644
--- a/src/core/link-extraction.ts
+++ b/src/core/link-extraction.ts
@@ -17,7 +17,7 @@ import { ensureWellFormed } from './text-safe.ts';
import { stripCodeBlocks } from './markdown-code.ts';
import { maskLinksFence } from './links-fence.ts';
import { targetTakesVerb } from './link-target-roles.ts';
-import { inSuppressedRange, rolePriorSuppressedRanges } from './machine-sections.ts';
+import { inSuppressedRange, roleTriggerText, rolePriorSuppressedRanges } from './machine-sections.ts';
import { statedRelationTypes } from './line-grammar.ts';
import { isValidSourceId } from './source-id.ts';
import { isDatedTimelineLine, parseInlineCitationTimelineEntries, TIMELINE_LINE_RE, TIMELINE_LINE_RE_CN } from './timeline-citations.ts';
@@ -1345,23 +1345,6 @@ export function rolePriorPhrases(text: string): Array<string | null> {
return [PARTNER_ROLE_RE, ADVISOR_ROLE_RE, EMPLOYEE_ROLE_RE].map(re => re.exec(text)?.[0] ?? null);
}
-/**
- * The text the page-role priors read their trigger from (#7882): `text` without its machine-written sections
- * (rolePriorSuppressedRanges), the sections whose links never receive the prior either. `open` are the headings
- * still open before `text` (a segmented block, openHeadings), so a section that began in an earlier block still counts.
- */
-export function roleTriggerText(text: string, open: ReadonlyArray<string | null | undefined> = []): string {
- const head = open.filter(Boolean).map(h => `${h}\n`).join('');
- let kept = '';
- let at = 0;
- for (const [start, end] of rolePriorSuppressedRanges(stripCodeBlocks(head + text))) {
- if (end - head.length <= at) continue;
- if (start - head.length > at) kept += `${text.slice(at, start - head.length)}\n`;
- at = end - head.length;
- }
- return kept + text.slice(at);
-}
-
const EMPLOYEE_ROLE_RE = /\b(?:is an? (?:senior|staff|principal|lead|backend|frontend|full-?stack|ML|data|security|DevOps|platform)? ?engineer at|is an? (?:senior|staff|principal|lead)? ?(?:developer|designer|product manager|engineering manager|director|VP) (?:at|of)|holds? the (?:CTO|CEO|CFO|COO|CMO|CRO|VP) (?:role|position|seat|title) at|is the (?:CTO|CEO|CFO|COO|CMO|CRO) of|employee at|on the team at|works on .{0,30} at)\b/i;
diff --git a/src/core/machine-sections.ts b/src/core/machine-sections.ts
index 3d06a63523..e471fe56d9 100644
--- a/src/core/machine-sections.ts
+++ b/src/core/machine-sections.ts
@@ -5,6 +5,7 @@
* grammar (src/core/line-grammar.ts) never reads a typed relation or a fact
* line inside them: writers fill these sections with per-event references.
*/
+import { stripCodeBlocks } from './markdown-code.ts';
/**
* Content index ranges where the page-role prior must NOT apply: the
@@ -48,3 +49,20 @@ export function inSuppressedRange(ranges: Array<[number, number]>, idx: number):
}
return false;
}
+
+/**
+ * The text the page-role priors read their trigger from (#7882): `text` without its machine-written sections
+ * (rolePriorSuppressedRanges), the sections whose links never receive the prior either. `open` are the headings
+ * still open before `text` (a segmented block, openHeadings), so a section that began in an earlier block still counts.
+ */
+export function roleTriggerText(text: string, open: ReadonlyArray<string | null | undefined> = []): string {
+ const head = open.filter(Boolean).map(h => `${h}\n`).join('');
+ let kept = '';
+ let at = 0;
+ for (const [start, end] of rolePriorSuppressedRanges(stripCodeBlocks(head + text))) {
+ if (end - head.length <= at) continue;
+ if (start - head.length > at) kept += `${text.slice(at, start - head.length)}\n`;
+ at = end - head.length;
+ }
+ return kept + text.slice(at);
+}
diff --git a/src/core/page-body/segment-derive.ts b/src/core/page-body/segment-derive.ts
index 322f5fc889..ff20742393 100644
--- a/src/core/page-body/segment-derive.ts
+++ b/src/core/page-body/segment-derive.ts
@@ -25,8 +25,8 @@ import { ledgerApplies, readBodyLedger } from './segment-ledger.ts';
import { SEGMENTER_VERSION } from './segmenter.ts';
import type { BodyRegion, ManifestRow } from './types.ts';
-/** Bump a kind's version to re-derive every page's rows of that kind once. fences 2: rows keep fence digests, not fence text. links 2: role phrases skip machine sections (#7882). */
-export const SEGMENT_PIPELINE_VERSIONS = { links: 2, mentions: 1, timeline: 1, fences: 2 } as const satisfies Partial<Record<SegmentDerivationKind, number>>;
+/** Bump a kind's version to re-derive every page's rows of that kind once. fences 2: rows keep fence digests, not fence text. */
+export const SEGMENT_PIPELINE_VERSIONS = { links: 1, mentions: 1, timeline: 1, fences: 2 } as const satisfies Partial<Record<SegmentDerivationKind, number>>;
export type UnpaidDerivationKind = keyof typeof SEGMENT_PIPELINE_VERSIONS;
/**
diff --git a/src/core/page-body/segment-links.ts b/src/core/page-body/segment-links.ts
index 8490bd4e3f..95d8ab1cfd 100644
--- a/src/core/page-body/segment-links.ts
+++ b/src/core/page-body/segment-links.ts
@@ -18,9 +18,10 @@
*/
import type { BrainEngine } from '../engine.ts';
import {
- candidateKey, dedupeCandidates, extractBodyLinks, frontmatterLinks, LINK_EXTRACTOR_VERSION_TS, rolePriorPhrases, roleTriggerText, stripCodeBlocks,
+ candidateKey, dedupeCandidates, extractBodyLinks, frontmatterLinks, LINK_EXTRACTOR_VERSION_TS, rolePriorPhrases, stripCodeBlocks,
type BodyLinkCandidate, type ExtractPageLinksOptions, type PageLinksResult, type SlugResolver,
} from '../link-extraction.ts';
+import { roleTriggerText } from '../machine-sections.ts';
import { canonicalJson } from '../belief/keys.ts';
import { datedLines, narrativeRefs } from '../link-temporal-evidence.ts';
import { rangedRelationLines } from '../link-effective.ts';