Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

typing unit U6 (dev rework): leave guard and advisory-page guard

garrytanc6655db2cbe5
diff --git a/src/core/link-temporal-evidence.ts b/src/core/link-temporal-evidence.ts
index c1cd75fd6d..fea4f6d0da 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, U5_EXCHANGE_AFTER, U5_EXCHANGE_BEFORE, U5_LEAVE, U6_START, typingUnitEnabled } from './link-typing-units.ts';
+import { U4_NOT_EMPLOYMENT_ROLE, U5_EXCHANGE_AFTER, U5_EXCHANGE_BEFORE, U5_LEAVE, U6_START, nonEmploymentRoleOnPage, typingUnitEnabled } from './link-typing-units.ts';
export interface OwnedRow {
from_slug: string;
@@ -232,9 +232,10 @@ 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.
+ // U5 ends, U6 starts and the uncued plain references to works_at targets, for the guards after the loop.
const u5 = typingUnitEnabled('U5');
- const u5Ends: Array<{ target: string; date: string; key: string }> = [];
+ const u6 = typingUnitEnabled('U6') && !nonEmploymentRoleOnPage(content);
+ const unitTransitions: 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.
@@ -271,14 +272,16 @@ export function deriveTemporalEvidence(page: PageForEvidence, rows: readonly Own
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 (r.link_type === 'works_at' && typingUnitEnabled('U6') && U6_START.test(window)) { kind = 'start'; rule = 'unit.u6.start_framing'; }
+ else if (u6 && r.link_type === 'works_at' && U6_START.test(window)) { kind = 'start'; rule = 'unit.u6.start_framing'; }
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) {
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 (rule.startsWith('unit.u5.') || rule.startsWith('unit.u6.')) {
+ unitTransitions.push({ target: other(r), date: line.date, key: `${r.from_slug}\0${r.to_slug}\0${r.link_type}\0${kind}\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);
@@ -287,9 +290,10 @@ 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) {
+ // U5 restart guard and U6 leave guard: a leave or start a unit adds is dropped when a later dated line names the same
+ // organization in plain words that no cue reads: for U5 a rejoin the lexicon cannot see (the leave would close a
+ // current stint for good), for U6 a leave it cannot see (the start would open a former job for good).
+ for (const e of unitTransitions) {
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);
diff --git a/src/core/link-typing-units.ts b/src/core/link-typing-units.ts
index b2342b12a9..0005c3f487 100644
--- a/src/core/link-typing-units.ts
+++ b/src/core/link-typing-units.ts
@@ -183,7 +183,7 @@ function inDatedEntry(context: string, linkStart: number): boolean {
/** The page names some organization in an advisory, board or investor role ("Took an advisory role with [X]"). */
const ROLE_ELSEWHERE = /\b(?:advis\w*|board|observer|investor|investing|invested|angel|non-executive|trustee)\b/i;
const LINK_OPEN = /\[\[|\[[^\]\n]*\]\(/g;
-function nonEmploymentRoleOnPage(pageText: string): boolean {
+export function nonEmploymentRoleOnPage(pageText: string): boolean {
for (const m of pageText.matchAll(LINK_OPEN)) if (ROLE_ELSEWHERE.test(clauseBefore(pageText, m.index ?? 0))) return true;
return false;
}
@@ -236,6 +236,10 @@ export const U5_EXCHANGE_AFTER = /^\s+for\s+(?:\[|the\s+\[|an?\s+\[)/i;
* U6: start framings: a first day, week or month at, day one at, kicking off a role, job, position, chapter or stint
* at, onboarding, "began working at/for", a new chapter at. Only dates a works_at relationship the page already
* asserts (natural cues never create one). "First day of the [X] summit" and an event line never start a job.
+ * Development rework (dev-units.md), the same two guards as U2/U5: a U6 start is dropped when a later dated entry names
+ * the organization in words no cue reads (an unread leave would keep a former job open for good), and U6 does not fire
+ * on a page that names any organization in an advisory, board or investor role (a newly dated employer then meets
+ * master's advisory-line start: wrong single-value closures on the E5 probe). U4 removes that cause.
*/
const START_ROLE = String.raw`(?:[\w&./-]+\s+){0,4}?`;
export const U6_START = new RegExp(String.raw`\b(?:(?:(?:her|his|their|my|a|the)\s+)?(?:first\s+(?:day|week|month)|day\s+one)\s+(?:as\s+${START_ROLE})?(?:at|with)|kick(?:ed|s|ing)?[\s-]?off\s+(?:(?:a|her|his|their|my)\s+)?(?:new\s+)?(?:role|job|position|chapter|stint)\s+(?:at|with)|(?:was\s+|got\s+|been\s+)?onboarded\s+(?:at|with|to|into|by)|onboarding\s+(?:week|day|period)\s+(?:at|with)|began\s+(?:work(?:ing)?\s+)?(?:at|for)|start(?:ed|ing|s)?\s+(?:a\s+|her\s+|his\s+|their\s+|my\s+)?new\s+chapter\s+(?:at|with)|(?:a\s+)?new\s+chapter\s+(?:at|with))\s*$`, 'i');
diff --git a/test/helpers/typing-unit-examples.ts b/test/helpers/typing-unit-examples.ts
index 7a7dde0128..72e6d404f8 100644
--- a/test/helpers/typing-unit-examples.ts
+++ b/test/helpers/typing-unit-examples.ts
@@ -332,6 +332,18 @@ const U6: TypingExample[] = [
off: { types: ['mentions', 'works_at'], transitions: [] }, on: { types: ['mentions', 'works_at'], transitions: [] } },
{ id: 'u6-began-working-with-collaboration', unit: 'U6', target: ACME, content: NOW_AT('note — Began working with {X} on a pilot'),
off: { types: ['mentions', 'works_at'], transitions: [] }, on: { types: ['mentions', 'works_at'], transitions: [] } },
+ // Leave guard: an unread leave after the start drops the U6 start (the former job would stay open for good); U5 reads
+ // this leave, so with U5 the start and the end both date the stint.
+ { id: 'u56-former-job-leave-guard', unit: ['U5', 'U6'], target: ACME,
+ content: page(`Alice worked at ${L(ACME)}. She works at ${L(BETA)} now.`, [`**2015-01-02** | linkedin — First day at ${L(ACME)} as engineer`, `**2019-03-04** | linkedin — Parted company with ${L(ACME)}`]),
+ off: { types: ['mentions', 'works_at'], transitions: [], live: { type: 'works_at', at: { '2016-01-01': false, today: false } } },
+ on: units => units.has('U5') && units.has('U6')
+ ? { 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, today: false } } }
+ : units.has('U5') ? { types: ['mentions', 'works_at'], transitions: ['works_at end 2019-03-04'], live: { type: 'works_at', at: { '2016-01-01': true, today: false } } }
+ : { types: ['mentions', 'works_at'], transitions: [], live: { type: 'works_at', at: { '2016-01-01': false, today: false } } } },
+ { id: 'u6-advisory-page-not-started', unit: 'U6', target: ACME,
+ content: page(`Alice works at ${L(ACME)} as designer. She also works at ${L(BETA)}.`, [`**2021-09-01** | linkedin — First day at ${L(ACME)} as designer`, `**2023-02-03** | note — Became an advisor at ${L(BETA)}`]),
+ off: { types: ['mentions', 'works_at'], transitions: [] }, on: { types: ['mentions', 'works_at'], transitions: [] } },
{ id: 'u6-untyped-target-not-started', unit: 'U6', target: BETA,
content: page(`Alice works at ${L(ACME)}.`, [`**2021-09-01** | linkedin — First day at ${L(BETA)}`]),
off: { types: ['mentions'], transitions: [] }, on: { types: ['mentions'], transitions: [] } },