/** * Prompt-time cards for the people and companies a prompt names, so the user * never has to re-explain who someone is. Reads files only; no model call. */ import { type Entity, list } from "../../tools/knowledge/lib"; import { buildNameIndex, entityKey, findMentions, type Mention, type NamedEntity, type NameIndex, } from "./entity-names"; import { identity } from "./settings"; const MAX_CARDS = 3; const MAX_LATEST = 160; function stringList(value: unknown): string[] { return Array.isArray(value) ? value.filter((v): v is string => typeof v === "string") : []; } function textField(entity: Entity, key: string): string { const value = entity.frontmatter[key]; return typeof value === "string" ? value.trim() : ""; } function namedEntity(entity: Entity): NamedEntity { return { slug: entity.slug, domain: entity.domain === "Companies" ? "Companies" : "People", title: entity.frontmatter.title, aliases: stringList(entity.frontmatter.aliases), domainName: textField(entity, "domain_name") || undefined, }; } export function loadKnownEntities(rootDir?: string): Entity[] { return [...list("People", rootDir), ...list("Companies", rootDir)]; } export function excludedNames(): string[] { const id = identity(); return [id.principal.name, id.ai.name]; } export function loadNameIndex(entities: Entity[]): NameIndex { return buildNameIndex(entities.map(namedEntity), excludedNames()); } function isSourceLine(line: string): boolean { return ( line.startsWith("### ") || line.startsWith("