Skip to content

Commit b386a5f

Browse files
authored
refactor(memory-wiki): share person-page classification (#134844)
1 parent 82f4fd1 commit b386a5f

3 files changed

Lines changed: 22 additions & 30 deletions

File tree

‎extensions/memory-wiki/src/compile.ts‎

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ import {
6565
WIKI_RELATED_START_MARKER,
6666
} from "./markdown.js";
6767
import { withMemoryWikiVaultMutation } from "./mutation-coordinator.js";
68+
import { isPersonLikePage } from "./person-page.js";
6869
import { readMemoryWikiSourceSyncState } from "./source-sync-state.js";
6970
import { activateExistingMemoryWikiVault, initializeMemoryWikiVault } from "./vault.js";
7071
import { buildMemoryWikiOverview, projectMemoryWikiOverviewItem } from "./wiki-overview.js";
@@ -510,18 +511,6 @@ function formatMaybeDetail(label: string, value: string | null | undefined): str
510511
return value ? `${label} ${value}` : null;
511512
}
512513

513-
function isPersonLikePage(page: WikiPageSummary): boolean {
514-
const entityType = normalizeLowercaseStringOrEmpty(page.entityType);
515-
const pageType = normalizeLowercaseStringOrEmpty(page.pageType);
516-
return (
517-
Boolean(page.personCard) ||
518-
entityType === "person" ||
519-
entityType === "maintainer" ||
520-
pageType === "person" ||
521-
pageType === "maintainer"
522-
);
523-
}
524-
525514
function formatPersonDirectoryLine(
526515
config: ResolvedMemoryWikiConfig,
527516
page: WikiPageSummary,
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { normalizeLowercaseStringOrEmpty } from "openclaw/plugin-sdk/string-coerce-runtime";
2+
import type { WikiPageSummary } from "./markdown.js";
3+
4+
export function isPersonLikePage(
5+
page: Pick<WikiPageSummary, "entityType" | "pageType" | "personCard">,
6+
): boolean {
7+
const entityType = normalizeLowercaseStringOrEmpty(page.entityType);
8+
const pageType = normalizeLowercaseStringOrEmpty(page.pageType);
9+
return (
10+
Boolean(page.personCard) ||
11+
entityType === "person" ||
12+
entityType === "maintainer" ||
13+
pageType === "person" ||
14+
pageType === "maintainer"
15+
);
16+
}

‎extensions/memory-wiki/src/query.ts‎

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
type WikiClaim,
2929
type WikiPageSummary,
3030
} from "./markdown.js";
31+
import { isPersonLikePage } from "./person-page.js";
3132
import { initializeMemoryWikiVault } from "./vault.js";
3233

3334
const QUERY_DIRS = ["entities", "concepts", "sources", "syntheses", "reports"] as const;
@@ -567,20 +568,6 @@ function hasRouteQuestionMatch(values: readonly string[], queryLower: string): b
567568
return hasAnyQueryMatch(values, queryLower, buildRouteQuestionTokens(queryLower));
568569
}
569570

570-
function isPersonLikeSummary(
571-
page: Pick<WikiPageSummary, "entityType" | "pageType" | "personCard">,
572-
): boolean {
573-
const entityType = normalizeLowercaseStringOrEmpty(page.entityType);
574-
const pageType = normalizeLowercaseStringOrEmpty(page.pageType);
575-
return (
576-
Boolean(page.personCard) ||
577-
entityType === "person" ||
578-
entityType === "maintainer" ||
579-
pageType === "person" ||
580-
pageType === "maintainer"
581-
);
582-
}
583-
584571
function scorePageSearchModeBoost(params: {
585572
page: QueryableWikiPage;
586573
matchingClaims: readonly WikiClaim[];
@@ -593,7 +580,7 @@ function scorePageSearchModeBoost(params: {
593580
case "auto":
594581
return 0;
595582
case "find-person": {
596-
let score = isPersonLikeSummary(page) ? 24 : -4;
583+
let score = isPersonLikePage(page) ? 24 : -4;
597584
if (
598585
hasAnyQueryMatch(
599586
[
@@ -613,7 +600,7 @@ function scorePageSearchModeBoost(params: {
613600
return score;
614601
}
615602
case "route-question": {
616-
let score = isPersonLikeSummary(page) ? 14 : 0;
603+
let score = isPersonLikePage(page) ? 14 : 0;
617604
if (hasRouteQuestionMatch(buildPageRouteQuestionFields(page), queryLower)) {
618605
score += 32;
619606
}
@@ -664,7 +651,7 @@ function scoreDigestSearchModeBoost(params: {
664651
case "auto":
665652
return 0;
666653
case "find-person": {
667-
let score = isPersonLikeSummary(page) ? 24 : -4;
654+
let score = isPersonLikePage(page) ? 24 : -4;
668655
if (
669656
hasAnyQueryMatch(
670657
[
@@ -684,7 +671,7 @@ function scoreDigestSearchModeBoost(params: {
684671
return score;
685672
}
686673
case "route-question": {
687-
let score = isPersonLikeSummary(page) ? 14 : 0;
674+
let score = isPersonLikePage(page) ? 14 : 0;
688675
if (hasRouteQuestionMatch(buildDigestRouteQuestionFields(page), queryLower)) {
689676
score += 32;
690677
}

0 commit comments

Comments
 (0)