Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: address codex review — correct linkedActivities/linkedCalendars shapes (#2157)
Adam Eivy758166ec6657
diff --git a/server/services/goalScorecard.js b/server/services/goalScorecard.jsindex b1becff2e8..382fbc8873 100644--- a/server/services/goalScorecard.js+++ b/server/services/goalScorecard.js@@ -139,9 +139,14 @@ export function goalKeywords(goal) {}// Build the deterministic goal→match ruleset. Each active goal gets a rule with-// derived keywords plus any explicitly-linked personIds / calendar ids. A-// per-goal override (keyed by goal id) can add keywords, replace personIds /-// subcalendarIds, or disable the goal from the scorecard entirely.+// derived keywords plus its linked calendars. A per-goal override (keyed by goal+// id) can add keywords, add participant personIds, replace the linked calendars,+// or disable the goal from the scorecard entirely.+//+// Note the real goal shapes (see server/services/identity/goals.js): a goal's+// `linkedActivities` are named tracked activities (`{ activityName, … }`), NOT+// tribe person ids — so their names fold into keywords. `linkedCalendars` are+// `{ subcalendarId, matchPattern }` objects (same shape dailyReview.js reads).export function buildMappingRules(goals = [], overrides = {}) {const rules = [];for (const goal of goals || []) {@@ -149,19 +154,35 @@ export function buildMappingRules(goals = [], overrides = {}) {if (goal.status && goal.status !== 'active') continue;const override = overrides[goal.id] || {};if (override.enabled === false) continue;++ const activityNames = Array.isArray(goal.linkedActivities)+ ? goal.linkedActivities.map((a) => String(a?.activityName || '').toLowerCase().trim()).filter(Boolean)+ : [];const keywords = Array.from(new Set([...goalKeywords(goal),+ ...activityNames,...((Array.isArray(override.keywords) ? override.keywords : []).map((k) => String(k).toLowerCase().trim()).filter(Boolean)),]));++ // Linked calendars → { subcalendarId, matchPattern } (matchPattern, when+ // present, further requires the event title to contain it — like dailyReview).+ let subcalendars = Array.isArray(goal.linkedCalendars)+ ? goal.linkedCalendars+ .filter((lc) => lc?.subcalendarId != null)+ .map((lc) => ({ subcalendarId: String(lc.subcalendarId), matchPattern: lc.matchPattern ? String(lc.matchPattern).toLowerCase() : null }))+ : [];+ if (Array.isArray(override.subcalendarIds)) {+ // Override supplies plain ids (no per-calendar pattern).+ subcalendars = override.subcalendarIds.map((id) => ({ subcalendarId: String(id), matchPattern: null }));+ }+rules.push({id: goal.id,title: goal.title || '(untitled goal)',category: goal.category || null,keywords,- personIds: Array.isArray(override.personIds) ? override.personIds.map(String)- : (Array.isArray(goal.linkedActivities) ? goal.linkedActivities.map(String) : []),- subcalendarIds: Array.isArray(override.subcalendarIds) ? override.subcalendarIds.map(String)- : (Array.isArray(goal.linkedCalendars) ? goal.linkedCalendars.map(String) : []),+ personIds: Array.isArray(override.personIds) ? override.personIds.map(String) : [],+ subcalendars,});}return rules;@@ -194,7 +215,9 @@ export function eventGoalMatches(event, rules = []) {for (const rule of rules) {const byKeyword = rule.keywords.some((k) => k && (k.includes(' ') ? text.includes(k) : words.has(k)));const byPerson = rule.personIds.some((id) => personIds.has(String(id)));- const byCalendar = subcal != null && rule.subcalendarIds.some((id) => String(id) === subcal);+ const byCalendar = subcal != null && rule.subcalendars.some((sc) => (+ sc.subcalendarId === subcal && (!sc.matchPattern || text.includes(sc.matchPattern))+ ));if (byKeyword || byPerson || byCalendar) matched.push(rule.id);}return Array.from(new Set(matched));diff --git a/server/services/goalScorecard.test.js b/server/services/goalScorecard.test.jsindex c3ce986b1e..8d8356a0fa 100644--- a/server/services/goalScorecard.test.js+++ b/server/services/goalScorecard.test.js@@ -94,7 +94,7 @@ describe('goalKeywords', () => {describe('buildMappingRules', () => {const goals = [{ id: 'g1', title: 'Musical Fluency', category: 'creative', status: 'active' },- { id: 'g2', title: 'Buy Humanoid Robot', category: 'financial', status: 'active', linkedCalendars: ['cal-x'] },+ { id: 'g2', title: 'Buy Humanoid Robot', category: 'financial', status: 'active', linkedCalendars: [{ subcalendarId: 'cal-x', matchPattern: null }] },{ id: 'g3', title: 'Archived goal', category: 'health', status: 'archived' },];@@ -103,9 +103,17 @@ describe('buildMappingRules', () => {expect(rules.map((r) => r.id)).toEqual(['g1', 'g2']);});- it('carries linkedCalendars into subcalendarIds', () => {+ it('carries linkedCalendars ({subcalendarId, matchPattern}) into subcalendars', () => {const rules = buildMappingRules(goals);- expect(rules.find((r) => r.id === 'g2').subcalendarIds).toEqual(['cal-x']);+ expect(rules.find((r) => r.id === 'g2').subcalendars).toEqual([{ subcalendarId: 'cal-x', matchPattern: null }]);+ });++ it('folds linkedActivities activityName values into keywords (not personIds)', () => {+ const rules = buildMappingRules([+ { id: 'gp', title: 'Piano', category: 'creative', status: 'active', linkedActivities: [{ activityName: 'Scales Drill', requiredFrequency: 3 }] },+ ]);+ expect(rules[0].keywords).toContain('scales drill');+ expect(rules[0].personIds).toEqual([]);});it('merges override keywords and can disable a goal', () => {@@ -119,19 +127,19 @@ describe('buildMappingRules', () => {expect(rules[0].keywords.filter((k) => k === 'guitar')).toHaveLength(1);});- it('override personIds/subcalendarIds replace the goal defaults', () => {+ it('override personIds add participants; override subcalendarIds replace linked calendars', () => {const rules = buildMappingRules(goals, { g2: { personIds: ['p9'], subcalendarIds: ['cal-y'] } });const r = rules.find((x) => x.id === 'g2');expect(r.personIds).toEqual(['p9']);- expect(r.subcalendarIds).toEqual(['cal-y']);+ expect(r.subcalendars).toEqual([{ subcalendarId: 'cal-y', matchPattern: null }]);});});describe('eventGoalMatches', () => {const rules = buildMappingRules([{ id: 'music', title: 'Musical Fluency', category: 'creative', status: 'active' },- { id: 'robot', title: 'Buy Humanoid Robot', category: 'financial', status: 'active', linkedActivities: ['p-bob'], linkedCalendars: ['cal-robot'] },- ]);+ { id: 'robot', title: 'Buy Humanoid Robot', category: 'financial', status: 'active', linkedCalendars: [{ subcalendarId: 'cal-robot', matchPattern: null }] },+ ], { robot: { personIds: ['p-bob'] } });it('matches by keyword in title/summary/participant name', () => {expect(eventGoalMatches(ev({ title: 'piano and musical practice' }), rules)).toEqual(['music']);@@ -139,7 +147,7 @@ describe('eventGoalMatches', () => {expect(eventGoalMatches(ev({ participants: [{ name: 'Robot Lab' }] }), rules)).toEqual(['robot']);});- it('matches by linked personId', () => {+ it('matches by override-linked personId', () => {expect(eventGoalMatches(ev({ participants: [{ personId: 'p-bob' }] }), rules)).toEqual(['robot']);});@@ -147,6 +155,15 @@ describe('eventGoalMatches', () => {expect(eventGoalMatches(ev({ kind: 'calendar.event', metadata: { subcalendarId: 'cal-robot' } }), rules)).toEqual(['robot']);});+ it('honors a calendar matchPattern (title must contain it)', () => {+ const patternRules = buildMappingRules([+ { id: 'gym', title: 'Fitness', category: 'health', status: 'active', linkedCalendars: [{ subcalendarId: 'cal-health', matchPattern: 'workout' }] },+ ]);+ expect(eventGoalMatches(ev({ kind: 'calendar.event', title: 'morning workout', metadata: { subcalendarId: 'cal-health' } }), patternRules)).toEqual(['gym']);+ // Same calendar, title without the pattern → no match.+ expect(eventGoalMatches(ev({ kind: 'calendar.event', title: 'dentist appt', metadata: { subcalendarId: 'cal-health' } }), patternRules)).toEqual([]);+ });+it('returns empty for an unaligned event', () => {expect(eventGoalMatches(ev({ title: 'random chatter' }), rules)).toEqual([]);});