Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(mentions): labels later in a line and a quoted name after "calls it" declare aliases

garrytan35766701022a
diff --git a/docs/designs/ALIAS_CONVENTIONS.md b/docs/designs/ALIAS_CONVENTIONS.md
index 046dc9c253..f768a683bc 100644
--- a/docs/designs/ALIAS_CONVENTIONS.md
+++ b/docs/designs/ALIAS_CONVENTIONS.md
@@ -69,6 +69,7 @@ A cue is followed by an optional `:`, `,`, `(` or `-`, an optional article
| Short names | `short name`, `short for`, `abbreviated`, `abbreviated as` | `Short name: QCAP` → `QCAP` | — |
| Codes | `code name`, `codename`, `account code`, `ticker`, `customer code`, `account ID` | `Account code: QUCO` → `QUCO` | — |
| Alias | `alias`, `aliases` | `alias "Red Kite"` → `Red Kite` | — |
+| Calls it (quoted only) | `calls it`, `call it`, `called it` followed by a quoted name | `the team also calls it "Copper Fox"` → `Copper Fox` | `the team calls it a success` → nothing |
## Label and value forms
@@ -93,6 +94,13 @@ A table row qualifies when its first cell is a label (the `:` is optional
there) and its second cell is the value. A header row or a separator row
(`---`) never qualifies.
+A label can also open a later sentence of a line, as record exports and
+generated sheets often write several fields on one line (`Account: Widget Co.
+Nickname used by the team: Copper Fox. Region: EMEA.`). Inside a line the label
+must carry the label noun within its first two words and have at most 7
+words, so `Account owner: Dana Example` or `Notes from the call: ...` never
+qualify; the value ends at the sentence's end.
+
## Quoted and parenthetical alternate names
Legal drafting and filings introduce a defined short name in parentheses right
@@ -121,3 +129,12 @@ prose cue and needs no name.
- Names declared only in free prose without a cue ("we just say Copper Fox")
are not parsed; the entity card's `identity_excerpt` shows such lines
verbatim instead.
+
+## Changelog
+
+- 2026-10-08: added labels that open a later sentence of a line and the
+ quoted-only "calls it" cue. Origin: the Cat 40 Hard development (calibration)
+ world, whose account sheets write `Nickname used by the team: X` mid-line and
+ `the team also calls it "X"`; both are general record-export and prose forms,
+ measured on that development split only (nicknames derived 0 of 2,845 before,
+ 2,829 of 2,845 after, no false aliases among 5,690 derived on its entity pages).
diff --git a/src/core/mentions/aliases.ts b/src/core/mentions/aliases.ts
index 949552e987..5ad3edd49b 100644
--- a/src/core/mentions/aliases.ts
+++ b/src/core/mentions/aliases.ts
@@ -41,6 +41,8 @@ const CUES = [
'd/b/a', 'dba', 'short name', 'short for', 'abbreviated as', 'abbreviated', 'code ?name', 'account code', 'customer code',
'account id', 'ticker', 'alias(?:es)?',
];
+/** Cues that declare a name only when it is quoted ("the team calls it \"Copper Fox\""). */
+const QUOTED_CUE_RE = /(?<![A-Za-z])(?:calls?|called|call) it\s+/gi;
const CUE_RE = new RegExp(`(?<![A-Za-z0-9])(?:${CUES.join('|')})(?![A-Za-z0-9])`, 'gi');
const LABEL_NOUN_RE = /(?<![a-z])(?:nicknames?|alias(?:es)?|aka|a\.k\.a\.?|also known as|short name|trading name|trade name|brand name|former (?:legal )?name|previous name|legal name|display name|dba|d\/b\/a|code ?name|account code|customer code|ticker)(?![a-z])/i;
const RELATIONAL_NOUN_RE = /\b(?:competitors?|rivals?|partners?|parent(?: company)?|subsidiar(?:y|ies)|affiliates?|vendors?|suppliers?|customers?|clients?|acquirers?|investors?)\b/i;
@@ -124,6 +126,11 @@ function labelValues(value: string, multiword: boolean): string[] {
const stripLineMarkup = (line: string) => line.replace(/^\s*(?:[-*+>]|\d+[.)])\s+/, '').replace(/\*\*|__/g, '').trim();
const isTableSeparator = (line: string | undefined) => !!line && /^\s*\|?\s*:?-{2,}/.test(line);
const isLabel = (label: string) => label.split(/\s+/).length <= 6 && LABEL_NOUN_RE.test(label);
+/** A label opening a sentence inside a line: an alias noun within its first two words, at most 7 words ("Nickname used by the team"). */
+const isLeadingLabel = (label: string) => {
+ const words = label.trim().split(/\s+/);
+ return words.length <= 7 && LABEL_NOUN_RE.test(words.slice(0, 2).join(' ')) && !RELATIONAL_NOUN_RE.test(label);
+};
/** Every declaration in `text` with its line, in line order, deduped by alias (first line wins). Not post-filtered. */
export function declarationsIn(text: string, opts: DeclarationOpts = {}): Declaration[] {
@@ -163,13 +170,27 @@ export function declarationsIn(text: string, opts: DeclarationOpts = {}): Declar
if (colon > 0 && colon <= 60 && isLabel(plain.slice(0, colon))) {
for (const name of labelValues(plain.slice(colon + 1), multiword)) push(name, i);
}
+ // A label can also open a later sentence of the line ("Account: X. Nickname used by the team: Y.").
+ for (const segment of plain.split(/(?<=[.;!?])\s+/).slice(1)) {
+ const at = segment.indexOf(':');
+ if (at > 0 && at <= 60 && isLeadingLabel(segment.slice(0, at))) {
+ for (const name of labelValues(segment.slice(at + 1), multiword)) push(name, i);
+ }
+ }
+ const sentenceBefore = (at: number) => {
+ const before = plain.slice(0, at);
+ return before.slice(Math.max(before.lastIndexOf('. '), before.lastIndexOf('; '), -1) + 1);
+ };
CUE_RE.lastIndex = 0;
for (const m of plain.matchAll(CUE_RE)) {
- const before = plain.slice(0, m.index);
- const sentence = before.slice(Math.max(before.lastIndexOf('. '), before.lastIndexOf('; '), -1) + 1);
- if (RELATIONAL_NOUN_RE.test(sentence)) continue;
+ if (RELATIONAL_NOUN_RE.test(sentenceBefore(m.index!))) continue;
push(captureName(plain.slice(m.index! + m[0].length), { multiword }), i);
}
+ for (const m of plain.matchAll(QUOTED_CUE_RE)) {
+ const rest = plain.slice(m.index! + m[0].length);
+ if (!QUOTES[rest[0] ?? ''] || RELATIONAL_NOUN_RE.test(sentenceBefore(m.index!))) continue;
+ push(captureName(rest, { multiword }), i);
+ }
if (ownLower.length) {
for (const m of plain.matchAll(PAREN_TERM_RE)) {
if (!endsWithOwnName(plain.slice(0, m.index))) continue;
diff --git a/src/core/mentions/pass.ts b/src/core/mentions/pass.ts
index f811531191..b6f3f16c06 100644
--- a/src/core/mentions/pass.ts
+++ b/src/core/mentions/pass.ts
@@ -55,9 +55,9 @@ import { maintenanceAttribution } from '../persistence/attribution.ts';
import { managedPersistenceEnabled } from '../persistence/ownership.ts';
/** Bump to rescan every page's mentions once (gazetteer or scanner behavior change). */
-export const MENTION_EXTRACTOR_VERSION = 3;
+export const MENTION_EXTRACTOR_VERSION = 4;
/** Bump to re-derive every entity page's declared aliases and title subject once. */
-export const ALIAS_DERIVATION_VERSION = 2;
+export const ALIAS_DERIVATION_VERSION = 3;
const RECONCILE_BATCH = 200;
const ALIAS_BATCH = 200;
diff --git a/test/mentions-policy-aliases.test.ts b/test/mentions-policy-aliases.test.ts
index 9099e44dfc..3896dda410 100644
--- a/test/mentions-policy-aliases.test.ts
+++ b/test/mentions-policy-aliases.test.ts
@@ -192,3 +192,24 @@ describe('declared-name grammar (alias conventions spec)', () => {
expect(performance.now() - t0).toBeLessThan(200);
});
});
+
+// Cat 40 Hard development round 1: a label can open a later sentence of the line, and "calls it" declares a quoted name.
+describe('declared-name grammar: mid-line labels and quoted "calls it"', () => {
+ const names = (text: string, name = 'Widget Co') => declaredNames(text, name);
+ test.each([
+ ['label after a first sentence, with qualifier words', 'Account: Widget Co. Nickname used by the team: Copper Fox. Industry: freight.', ['Copper Fox']],
+ ['parenthetical qualifier', 'Owner: Dana Example. Alias (legacy): Red Kite.', ['Red Kite']],
+ ['comma qualifier', 'Status: open. Short name, internal: WGCO.', ['WGCO']],
+ ['prepositional qualifier', 'Region: UK. Trading name in the UK: Northwind Ops.', ['Northwind Ops']],
+ ['quoted name after "calls it"', 'In notes and tickets the team also calls it "Copper Fox", or "the freight account".', ['Copper Fox']],
+ ])('%s', (_label, text, want) => { expect(names(text)).toEqual(want); });
+
+ test.each([
+ 'Region: west. Account owner: Dana Example.',
+ 'Status: closed. Notes from the call: Quarterly Review went well.',
+ 'Note: done. Our competitor alias: Blue Harbor.',
+ 'the team calls it a success',
+ 'We call it "the plan".',
+ 'Status: open. Our partner calls it "Blue Harbor".',
+ ])('no alias: %s', text => { expect(names(text)).toEqual([]); });
+});