AI-powered virtual executive team — a single coherent executive persona backed by 8 specialist agents (FastAPI + Next.js).
fix(briefing): stop first-week nudges for steps already done (#632)
Rufusc04bd4235b1d
diff --git a/packages/core/openexecutive/briefing/first_week.py b/packages/core/openexecutive/briefing/first_week.pyindex 5e333e23..f07e5586 100644--- a/packages/core/openexecutive/briefing/first_week.py+++ b/packages/core/openexecutive/briefing/first_week.py@@ -42,10 +42,13 @@ import asyncioimport loggingfrom dataclasses import dataclass, fieldfrom datetime import UTC, datetime, timedelta-from typing import Any+from typing import TYPE_CHECKING, Anyfrom openexecutive.alerts.lifecycle import parse_aware+if TYPE_CHECKING:+ from openexecutive.departments.models import Goal+logger = logging.getLogger(__name__)FIRST_WEEK = timedelta(days=7)@@ -110,7 +113,7 @@ def first_week_started(now: datetime | None = None) -> datetime | None:def _goal_lines(solo: bool = False) -> tuple[list[str], list[str], list[str]]:"""(goal lines, leaderless lines, keys). Solo has no team, so nodepartment names and no leaders to name."""- from openexecutive.departments.store import list_departments+ from openexecutive.departments.store import list_all_goals, list_departmentsgoals: list[str] = []leaderless: list[str] = []@@ -121,16 +124,25 @@ def _goal_lines(solo: bool = False) -> tuple[list[str], list[str], list[str]]:leaderless.append(f"- {title}")keys.append(f"leaderless:{dept.config.slug}")for goal in dept.goals:- line = f"- {_one_line(goal.key_result)}" if solo else f"- [{title}] {_one_line(goal.key_result)}"- if goal.target:- line += f" — target {_one_line(goal.target, 60)}"- if goal.period_value:- line += f" ({_one_line(goal.period_value, 30)})"- goals.append(line)+ goals.append(_goal_line(goal, None if solo else title))+ keys.append(f"goal:{goal.id}:{goal.status}")+ # Goals with no area sit under no department row.+ for goal in list_all_goals():+ if not goal.department_slug:+ goals.append(_goal_line(goal, None))keys.append(f"goal:{goal.id}:{goal.status}")return goals[:_GOALS_MAX], leaderless[:_LEADERLESS_MAX], keys+def _goal_line(goal: Goal, area: str | None) -> str:+ line = f"- [{area}] {_one_line(goal.key_result)}" if area else f"- {_one_line(goal.key_result)}"+ if goal.target:+ line += f" — target {_one_line(goal.target, 60)}"+ if goal.period_value:+ line += f" ({_one_line(goal.period_value, 30)})"+ return line++def _priority_lines() -> tuple[list[str], list[str]]:"""(lines, keys) for this year's priorities from the saved profile: whatthe principal said they are working on, before any goal row exists."""@@ -390,9 +402,11 @@ def first_week_card(now: datetime | None = None) -> FirstWeekCard | None:return Nonecard = FirstWeekCard()try:- from openexecutive.departments.store import list_departments+ from openexecutive.departments.store import list_all_goals- card.needs_goal = not any(dept.goals for dept in list_departments())+ # Every goal counts, with or without an area: the card's own Set a+ # goal saves one with no area unless the person names one.+ card.needs_goal = not list_all_goals()except Exception:logger.warning("first_week: departments unreadable", exc_info=True)try:diff --git a/packages/core/tests/unit/test_briefing_first_week.py b/packages/core/tests/unit/test_briefing_first_week.pyindex 17446d16..f59306c7 100644--- a/packages/core/tests/unit/test_briefing_first_week.py+++ b/packages/core/tests/unit/test_briefing_first_week.py@@ -46,7 +46,12 @@ def setup(monkeypatch: pytest.MonkeyPatch) -> SimpleNamespace:],)monkeypatch.setattr("openexecutive.people.store.find_principal_person", lambda *a, **k: state.principal)+ state.loose_goals = []monkeypatch.setattr("openexecutive.departments.store.list_departments", lambda *a, **k: state.departments)+ monkeypatch.setattr(+ "openexecutive.departments.store.list_all_goals",+ lambda *a, **k: [g for d in state.departments for g in d.goals] + state.loose_goals,+ )return state@@ -376,6 +381,19 @@ def test_card_drops_the_ask_once_a_goal_is_set_and_hides_with_nothing_to_say(carassert first_week.first_week_card(NOW) is None+def test_card_drops_the_ask_for_a_goal_with_no_area(card: SimpleNamespace) -> None:+ card.loose_goals = [_goal(9, "", "Sign 3 pilots by December")]+ out = first_week.first_week_card(NOW)+ assert out is not None and not out.needs_goal+++def test_shared_block_lists_a_goal_with_no_area(setup: SimpleNamespace) -> None:+ setup.loose_goals = [_goal(9, "", "Sign 3 pilots by December")]+ lines, _, keys = first_week._goal_lines()+ assert lines[-1] == "- Sign 3 pilots by December (Q4 2026)"+ assert any(k.startswith("goal:9:") for k in keys)++def test_card_without_findings_still_asks_for_a_goal(card: SimpleNamespace) -> None:card.artifact = "# Executive research\n\nNo findings surfaced this run."out = first_week.first_week_card(NOW)diff --git a/packages/ui/src/components/Briefing.tsx b/packages/ui/src/components/Briefing.tsxindex 64cc40c9..bcbaff89 100644--- a/packages/ui/src/components/Briefing.tsx+++ b/packages/ui/src/components/Briefing.tsx@@ -8,6 +8,7 @@ import {approveAlert,approveDecision,bulkAckAlerts,+ getDelegation,getToday,markTodaySeen,rejectDecision,@@ -699,6 +700,17 @@ export default function Briefing({ onContinue, showHeader = false, firstName, ba// day isn't called quiet and the summary line points at it.const firstWeekCard = today?.first_week_card ?? null;const firstWeek = Boolean(today?.first_week);+ // The first week's empty Needs you points at the own-mailbox step only+ // while that mailbox isn't connected (null until known, so no flash).+ const [ownMailboxConnected, setOwnMailboxConnected] = useState<boolean | null>(null);+ useEffect(() => {+ if (!firstWeek) return;+ const ctrl = new AbortController();+ getDelegation(ctrl.signal)+ .then((d) => setOwnMailboxConnected(d ? d.gmail.status === "connected" : null))+ .catch(() => undefined);+ return () => ctrl.abort();+ }, [firstWeek]);const briefFreshness = today? today.narrative_stale? "Refreshing…"@@ -891,11 +903,16 @@ export default function Briefing({ onContinue, showHeader = false, firstName, ba</div>) : firstWeek ? (<p className="rounded-2xl border border-dashed border-line px-4 py-5 text-[15px] text-fg-muted">- Nothing waiting on you yet. Decisions and replies to send land here.{" "}- <Link href={FIRST_RUN_LINKS.ownMailbox} className="font-medium text-accent hover:underline">- Let it read your mailbox- </Link>{" "}- to get draft replies here.+ Nothing waiting on you yet. Decisions and replies to send land here.+ {ownMailboxConnected === false && (+ <>+ {" "}+ <Link href={FIRST_RUN_LINKS.ownMailbox} className="font-medium text-accent hover:underline">+ Let it read your mailbox+ </Link>{" "}+ to get draft replies here.+ </>+ )}</p>) : !isQuiet ? (<p className="rounded-2xl border border-dashed border-line px-4 py-5 text-[15px] text-fg-muted">