Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

typing unit U5: leave idioms and exchange moves, with a restart guard

garrytanfe4c334e2f68
diff --git a/src/core/link-temporal-evidence.ts b/src/core/link-temporal-evidence.ts
index 7f65ec4be1..32ec3ae42a 100644
--- a/src/core/link-temporal-evidence.ts
+++ b/src/core/link-temporal-evidence.ts
@@ -25,7 +25,7 @@ import {
type TransitionKind, type TransitionProducer,
} from './link-validity.ts';
import { KNOWN_LINK_TYPES } from './search/relational-intent.ts';
-import { U4_NOT_EMPLOYMENT_ROLE, typingUnitEnabled } from './link-typing-units.ts';
+import { U4_NOT_EMPLOYMENT_ROLE, U5_EXCHANGE_AFTER, U5_EXCHANGE_BEFORE, U5_LEAVE, typingUnitEnabled } from './link-typing-units.ts';
export interface OwnedRow {
from_slug: string;
@@ -209,9 +209,10 @@ export function deriveTemporalEvidence(page: PageForEvidence, rows: readonly Own
const temporalRows = rows.filter(r => relationSemantics(r.link_type) !== 'reference');
const other = (r: OwnedRow) => (r.from_slug === page.slug ? r.to_slug : r.from_slug);
const seen = new Set<string>();
+ const rules = new Map<DerivedTransition, string>();
const push = (t: DerivedTransition, rule: string) => {
const k = `${t.from_slug}\0${t.to_slug}\0${t.link_type}\0${t.kind}\0${t.occurred_on}\0${t.producer}`;
- if (!seen.has(k)) { seen.add(k); transitions.push(t); explain?.(t, rule); }
+ if (!seen.has(k)) { seen.add(k); transitions.push(t); rules.set(t, rule); }
};
// 1. Explicit grammar inside dated timeline entries.
@@ -231,6 +232,11 @@ export function deriveTemporalEvidence(page: PageForEvidence, rows: readonly Own
}
}
+ // U5 ends and the uncued plain references to works_at targets, for the restart guard after the loop.
+ const u5 = typingUnitEnabled('U5');
+ const u5Ends: Array<{ target: string; date: string; key: string }> = [];
+ const uncued: Array<{ target: string; date: string }> = [];
+
// 2. Natural cues on dated lines, for relationships this page asserts.
// State relations take a cue only when it governs the reference itself:
// not on investing/meeting/event lines, not when the reference is
@@ -262,10 +268,16 @@ export function deriveTemporalEvidence(page: PageForEvidence, rows: readonly Own
: /\b(?:(?:re-?)?joined|was\s+(?:added|named|appointed)\s+to)\s*$/i.test(window) ? 'start' : null;
rule = `cue.advisory_board.${kind}`;
} else if (cues.end.test(window)) { kind = 'end'; rule = `cue.${family}.end`; }
+ else if (u5 && r.link_type === 'works_at' && U5_LEAVE.test(window)) { kind = 'end'; rule = 'unit.u5.leave'; }
+ else if (u5 && r.link_type === 'works_at' && U5_EXCHANGE_BEFORE.test(window) && U5_EXCHANGE_AFTER.test(line.text.slice(ref.end))) { kind = 'end'; rule = 'unit.u5.exchange'; }
else if (cues.start.test(window)) { kind = 'start'; rule = `cue.${family}.start`; }
else if (prevEnded.has(r.link_type) && /^\s*(?:to|for)\s*$/i.test(between)) { kind = 'start'; rule = 'cue.after_end.to_for'; }
} else if (EVENT_START[r.link_type]?.test(window)) { kind = 'start'; rule = `cue.event.${r.link_type}`; }
- if (!kind) continue;
+ if (!kind) {
+ if (cues && !qualified && r.link_type === 'works_at') uncued.push({ target: other(r), date: line.date });
+ continue;
+ }
+ if (rule.startsWith('unit.u5.')) u5Ends.push({ target: other(r), date: line.date, key: `${r.from_slug}\0${r.to_slug}\0${r.link_type}\0end\0${line.date}` });
if (kind === 'end') endedHere.add(r.link_type);
push({ from_slug: r.from_slug, to_slug: r.to_slug, link_type: r.link_type, kind, occurred_on: line.date,
date_precision: 'day', producer: line.dream ? 'dream' : 'timeline', line_hash: lineHash(line.text) }, rule);
@@ -274,6 +286,14 @@ export function deriveTemporalEvidence(page: PageForEvidence, rows: readonly Own
}
}
+ // U5 restart guard: an idiomatic leave is dropped when a later dated line names the same organization in plain words
+ // that no cue reads (a rejoin the lexicon cannot see); otherwise it would close a current stint for good.
+ for (const e of u5Ends) {
+ if (!uncued.some(u => u.target === e.target && u.date > e.date)) continue;
+ const at = transitions.findIndex(t => `${t.from_slug}\0${t.to_slug}\0${t.link_type}\0${t.kind}\0${t.occurred_on}` === e.key);
+ if (at >= 0) transitions.splice(at, 1);
+ }
+
// 3. Frontmatter since/until on relationship objects ({name, since, until}).
const fm = page.frontmatter ?? {};
for (const r of temporalRows) {
@@ -309,6 +329,7 @@ export function deriveTemporalEvidence(page: PageForEvidence, rows: readonly Own
}
tense.set(rowKey(r), past > 0 && present === 0 && r.link_source !== 'frontmatter' ? 'past' : 'present');
}
+ if (explain) for (const t of transitions) explain(t, rules.get(t)!);
return { tense, transitions, unmatched };
}
diff --git a/src/core/link-typing-units.ts b/src/core/link-typing-units.ts
index 87c0cc0174..b7249d9da9 100644
--- a/src/core/link-typing-units.ts
+++ b/src/core/link-typing-units.ts
@@ -214,3 +214,12 @@ export function u2RoleRule(context: string, linkStart: number, linkEnd: number,
* employment start cues, so "Became an advisor at [X]" or "Took an advisory role with [X]" never starts a works_at stint.
*/
export const U4_NOT_EMPLOYMENT_ROLE = String.raw`(?!(?:\w+\s+){0,2}?(?:advis\w*|board|investor|investing|investment|angel|observer|non-executive|independent|trustee)\b)`;
+
+/** U5: leaves an object splits ("wrapped her time up at", "handed in her notice at") and quitting idioms. */
+const LEAVE_OBJECT = String.raw`(?:(?:her|his|their|my|a|the)\s+)?(?:time|stint|tenure|role|job|run|things|it|notice|resignation)\s+`;
+const SPLIT_LEAVE = String.raw`(?:wrapped|wound|finished)\s+${LEAVE_OBJECT}up\s+(?:at|with)|(?:handed|turned|put)\s+(?:in\s+${LEAVE_OBJECT}|${LEAVE_OBJECT}in\s+)(?:at|to|with)|(?:gave|submitted|tendered)\s+${LEAVE_OBJECT}(?:at|to)`;
+const IDIOM_LEAVE = String.raw`packed\s+(?:it|things)\s+in\s+(?:at|with)|call(?:ed|s|ing)?\s+(?:it\s+)?time\s+(?:on|at)|call(?:ed|s|ing)?\s+it\s+a\s+day\s+(?:at|with)|call(?:ed|s|ing)?\s+it\s+quits\s+(?:at|with)|bow(?:ed|s|ing)?\s+out\s+(?:of|from|at)|walk(?:ed|s|ing)?\s+(?:out\s+(?:of|on)|away\s+from)|thr(?:ew|ows|owing)\s+in\s+the\s+towel\s+(?:at|with)|hand(?:ed|s|ing)?\s+in\s+(?:(?:her|his|their|my)\s+)?(?:badge|keys|laptop)\s+(?:at|to)|clear(?:ed|s|ing)?\s+out\s+(?:(?:her|his|their|my)\s+)?desk\s+at|gave\s+up\s+(?:(?:her|his|their|my)\s+)?(?:job|role|post|position|seat)\s+at|left\s+(?:(?:her|his|their|my)\s+)?(?:job|role|post|position)\s+at|step(?:ped|s|ping)?\s+back\s+from|parted\s+company\s+with|said\s+(?:(?:her|his|their|my)\s+)?goodbyes?\s+to|bid(?:\s+a)?\s+farewell\s+to|exit\s+from`;
+export const U5_LEAVE = new RegExp(String.raw`\b(?:${SPLIT_LEAVE}|${IDIOM_LEAVE})\s*$`, 'i');
+/** U5: "traded [A] for [B]" ends A (the "for" then starts B). "Traded shares of [A]" is not an exchange. */
+export const U5_EXCHANGE_BEFORE = /\b(?:traded|swapped|exchanged|ditched|dropped)\s*$/i;
+export const U5_EXCHANGE_AFTER = /^\s+for\s+(?:\[|the\s+\[|an?\s+\[)/i;
diff --git a/test/helpers/typing-unit-examples.ts b/test/helpers/typing-unit-examples.ts
index 2952cc1282..c0985b667d 100644
--- a/test/helpers/typing-unit-examples.ts
+++ b/test/helpers/typing-unit-examples.ts
@@ -261,4 +261,45 @@ const U4: TypingExample[] = [
off: { types: ['advises'], transitions: ['advises start 2021-06-07'] } },
];
-export const EXAMPLES: TypingExample[] = [...U1, ...U2, ...U3, ...U4];
+// ─── U5: leave idioms and exchange moves (dated ends), with a restart guard ─
+const JOB = (lines: string[]) => page(`Alice worked at ${L(ACME)}. She works at ${L(BETA)} now.`, [`**2015-01-02** | linkedin — Joined ${L(ACME)} as engineer`, ...lines]);
+const U5: TypingExample[] = [
+ { id: 'u5-handed-in-notice', unit: 'U5', target: ACME, content: JOB([`**2019-03-04** | linkedin — Handed in her notice at ${L(ACME)}`]),
+ off: { types: ['mentions', 'works_at'], transitions: ['works_at start 2015-01-02'] },
+ on: { types: ['mentions', 'works_at'], transitions: ['works_at start 2015-01-02', 'works_at end 2019-03-04'], live: { type: 'works_at', at: { '2016-01-01': true, '2020-01-01': false } } } },
+ { id: 'u5-wrapped-time-up', unit: 'U5', target: ACME, content: JOB([`**2019-03-04** | linkedin — Wrapped her time up at ${L(ACME)}`]),
+ off: { types: ['mentions', 'works_at'], transitions: ['works_at start 2015-01-02'] }, on: { types: ['mentions', 'works_at'], transitions: ['works_at start 2015-01-02', 'works_at end 2019-03-04'] } },
+ { id: 'u5-packed-it-in', unit: 'U5', target: ACME, content: JOB([`**2019-03-04** | linkedin — Called it a day at ${L(ACME)} and packed it in`]),
+ off: { types: ['mentions', 'works_at'], transitions: ['works_at start 2015-01-02'] }, on: { types: ['mentions', 'works_at'], transitions: ['works_at start 2015-01-02', 'works_at end 2019-03-04'] } },
+ { id: 'u5-stepped-back-from', unit: 'U5', target: ACME, content: JOB([`**2019-03-04** | linkedin — Stepped back from ${L(ACME)}`]),
+ off: { types: ['mentions', 'works_at'], transitions: ['works_at start 2015-01-02'] }, on: { types: ['mentions', 'works_at'], transitions: ['works_at start 2015-01-02', 'works_at end 2019-03-04'] } },
+ { id: 'u5-parted-company-with', unit: 'U5', target: ACME, content: JOB([`**2019-03-04** | linkedin — Parted company with ${L(ACME)}`]),
+ off: { types: ['mentions', 'works_at'], transitions: ['works_at start 2015-01-02'] }, on: { types: ['mentions', 'works_at'], transitions: ['works_at start 2015-01-02', 'works_at end 2019-03-04'] } },
+ { id: 'u5-farewell', unit: 'U5', target: ACME, content: JOB([`**2019-03-04** | linkedin — Said goodbye to ${L(ACME)} after four years`]),
+ off: { types: ['mentions', 'works_at'], transitions: ['works_at start 2015-01-02'] }, on: { types: ['mentions', 'works_at'], transitions: ['works_at start 2015-01-02', 'works_at end 2019-03-04'] } },
+ { id: 'u5-exchange-ends-first', unit: 'U5', target: ACME, content: JOB([`**2019-03-04** | linkedin — Swapped ${L(ACME)} for ${L(BETA)} (designer)`]),
+ off: { types: ['mentions', 'works_at'], transitions: ['works_at start 2015-01-02'] }, on: { types: ['mentions', 'works_at'], transitions: ['works_at start 2015-01-02', 'works_at end 2019-03-04'] } },
+ { id: 'u5-exchange-starts-second', unit: 'U5', target: BETA, content: JOB([`**2019-03-04** | linkedin — Swapped ${L(ACME)} for ${L(BETA)} (designer)`]),
+ off: { types: ['mentions', 'works_at'], transitions: [] }, on: { types: ['mentions', 'works_at'], transitions: ['works_at start 2019-03-04'], live: { type: 'works_at', at: { '2018-01-01': false, today: true } } } },
+ { id: 'u5-traded-shares-control', unit: 'U5', target: ACME, content: JOB([`**2019-03-04** | note — Traded shares of ${L(ACME)} for cash`]),
+ off: { types: ['mentions', 'works_at'], transitions: ['works_at start 2015-01-02'] }, on: { types: ['mentions', 'works_at'], transitions: ['works_at start 2015-01-02'] } },
+ { id: 'u5-event-line-control', unit: 'U5', target: ACME, content: JOB([`**2019-03-04** | event — Said goodbye to ${L(ACME)} at the farewell dinner`]),
+ off: { types: ['mentions', 'works_at'], transitions: ['works_at start 2015-01-02'] }, on: { types: ['mentions', 'works_at'], transitions: ['works_at start 2015-01-02'] } },
+ { id: 'u5-qualified-control', unit: 'U5', target: ACME, content: JOB([`**2019-03-04** | note — Said goodbye to ${L(ACME)}'s old office`]),
+ off: { types: ['mentions', 'works_at'], transitions: ['works_at start 2015-01-02'] }, on: { types: ['mentions', 'works_at'], transitions: ['works_at start 2015-01-02'] } },
+ // Unsupported, frozen: U5 does not resolve the subject (a third party's leave on the page dates the subject's stint).
+ { id: 'u5-third-party-split-leave', unit: 'U5', target: ACME, content: JOB([`**2019-03-04** | note — Her manager handed in his notice at ${L(ACME)}`]),
+ off: { types: ['mentions', 'works_at'], transitions: ['works_at start 2015-01-02'] }, on: { types: ['mentions', 'works_at'], transitions: ['works_at start 2015-01-02', 'works_at end 2019-03-04'] } },
+ // Restart guard: a later plain mention no cue reads (an onboarding week) keeps the stint open; without the guard the
+ // leave would close the current job for good (the dev trace's onboarding losses).
+ { id: 'u5-rejoin-restart-guard', unit: 'U5', target: ACME,
+ content: page(`Alice works at ${L(ACME)} as head of sales.`, [`**2015-01-02** | linkedin — Joined ${L(ACME)} as engineer`, `**2018-03-04** | linkedin — Parted company with ${L(ACME)}`, `**2020-08-11** | linkedin — Onboarding week at ${L(ACME)} as head of sales`]),
+ off: { types: ['mentions', 'works_at'], transitions: ['works_at start 2015-01-02'], live: { type: 'works_at', at: { '2019-01-01': true, today: true } } },
+ on: { types: ['mentions', 'works_at'], transitions: ['works_at start 2015-01-02'], live: { type: 'works_at', at: { '2019-01-01': true, today: true } } } },
+ { id: 'u5-leave-not-guarded-by-event-mention', unit: 'U5', target: ACME,
+ content: JOB([`**2019-03-04** | linkedin — Parted company with ${L(ACME)}`, `**2021-05-06** | event — Back at ${L(ACME)} for the alumni dinner`]),
+ off: { types: ['mentions', 'works_at'], transitions: ['works_at start 2015-01-02'] },
+ on: { types: ['mentions', 'works_at'], transitions: ['works_at start 2015-01-02', 'works_at end 2019-03-04'], live: { type: 'works_at', at: { today: false } } } },
+];
+
+export const EXAMPLES: TypingExample[] = [...U1, ...U2, ...U3, ...U4, ...U5];