Six inline-edit toggles across two files all hand-rolled the same
state machine: editing/draft/saving + start/cancel/setSaving wrap.
Pull that into hooks/use-inline-edit.ts.
Migrated:
- ProjectInlineEditors.tsx: NameEditor, DescriptionEditor, StatusEditor,
MaturityEditor (4 editors, 221 → 200 lines)
- PersonDetail.tsx: name and description toggles (-30 lines of plumbing)
Each call site keeps its own validation/equality/transform — the hook
only owns the lifecycle. Net: -32 lines across the two files, and
adding a new inline editor anywhere is now ~3 calls of useInlineEdit.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Every "New X" form repeated the same label-wrapping div and an 80-char
Tailwind className for inputs/selects/textareas — 15 call sites with
the exact same string. Pull that into components/ui/form.tsx:
- FIELD_INPUT_CLASS: shared className constant
- <Field label required>: label + child wrapper
The four migrated forms (Person, Project, Goal, Subscription) now read
as the form, not the form-styling. A future global tweak to input
visuals lands in one place.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The four "New X" buttons (Person, Project, Goal, Subscription) all
hand-rolled the same flow: setSaving(true), POST, decode { ok, error },
router.refresh(), surface a fallback "Failed to create <thing>". Pull
that into hooks/use-create-mutation.ts.
Each consumer now declares only its body type, the request fn (or a
typed lib helper like createGoal), and an errorLabel. The reset-fields
+ close logic stays per-component since the field shape varies.
Net: -20 lines across the four call sites, and adding a fifth "New X"
button is now a one-page implementation.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
PromptRow and FeaturedCard each repeated the same showRun/showSchedule
useState pair plus the conditional <RunModal>/<ScheduleModal> renders.
Extract usePromptModals(template, projects) returning openRun,
openSchedule, and a modals JSX node. Both call sites now have one line
of state setup and one {modals} render — adding a third modal type
later means changing one file.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
When a child (e.g. an inline attribute editor) calls onReload(),
loading was no longer flashing because the loading derivation
(data?.id !== projectId) stays false during a same-projectId refetch.
That left the user with no feedback that the save updated the
displayed source-of-truth.
Add a separate `refetching` state set during every fetch and a small
animated Loader2 anchored to the drawer's top-right while refetching
with stale data on screen. The full-page loader still triggers on the
initial-load case (no data yet).
The setRefetching(true) call is wrapped in Promise.resolve().then() to
defer it off the synchronous effect path, satisfying
react-hooks/set-state-in-effect.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
ProjectDetailHeader.tsx (323 lines) tangled four inline-editing widgets
(name, description, status pill, maturity slider) with a tab bar and
the action toolbar in a single component. Splitting:
- ProjectInlineEditors.tsx (221L): Name/Description/Status/Maturity
editors as named exports. Each owns its editing/draft/saving state
and exposes a single onSave(next) callback. Container keeps the
optimistic-override state so the UI updates immediately on commit.
- ProjectDetailTabBar.tsx (50L): tab strip with overview/prompts/goals
badges.
- ProjectDetailHeader.tsx (156L): orchestration — resolves displayed
values from data + overrides, wires the four save handlers, and
composes the editors with the action toolbar and tab bar.
No behavior change. All three files are now under 300 lines with a
single concern.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
PromptLibraryClient.tsx (359 lines) housed four concerns: a compact
list row, a featured card, a category filter bar, and the search/scope
container. Splitting:
- PromptRow.tsx (89L): compact row with run/schedule/preview actions
- FeaturedCard.tsx (61L): larger card for the Quick Access grid
- CategoryBar.tsx (52L): "All (n)" + per-category filter chips
- PromptLibraryClient.tsx (148L): search, scope filter, and orchestration
Each file is now under the 300-line god-component threshold and owns a
single concern. ALL_CATEGORIES moved to CategoryBar and re-exported.
No behavior change.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
EventsGrid.tsx (371 lines) housed three concerns: an event card, an
inline create-event form, and the search/filter container. Splitting:
- EventCard.tsx (97L): presentation + delete + archive for one event
- AddEventForm.tsx (124L): self-contained inline create form
- EventsGrid.tsx (153L): search, type-chip filter, and list orchestration
Each file is now well under the 300-line god-component threshold and has
one job. No behavior change — purely a structural refactor.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
CLAUDE.md is explicit: 'Use shadcn theme tokens — never hardcode hex'.
The modal/drawer surface colors #0f1117 and #0c0e14 were duplicated
across 10 files, violating SSOT.
- globals.css: add --surface-modal / --surface-drawer custom properties
in :root and .dark, register as Tailwind colors via @theme inline
- 10 components: bg-[#0f1117] → bg-surface-modal,
bg-[#0c0e14] → bg-surface-drawer
A future palette tweak now changes 1 file, not 10.
Verified bg-surface-{modal,drawer} classes are present in the prod CSS.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
ESLint went from 6 errors / 17 warnings to 0/0:
react-hooks/set-state-in-effect (3 sites)
- ProjectDetail: derive loading from data?.id !== projectId, replace
reload() helper with a reloadKey trigger so the effect owns the fetch
- AskIvyModal speech recognition: defer setSupported via queueMicrotask
- AskIvyModal useElapsedTimer: defer setElapsed(0) reset via queueMicrotask
react-hooks/static-components (1 site)
- WeatherCard: extract WeatherIcon as a module-level component instead
of assigning a Lucide icon to a render-scope variable
react/no-unescaped-entities (2 sites)
- ProjectGrid: replace bare quotes around {query} with “/”
Plus: removed 14 unused imports/vars across 10 files.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Adds a per-habit history view showing a 30-day completion calendar,
streak indicator, and completion-rate stat. Wires /habits into the
sidebar navigation.
- getAllHabitsWithHistory query batches habits + completions in window
- HabitHeatmap renders due/done/missed cells, marks today, respects
per-habit frequency (daily, weekdays, weekly)
- Summary StatCards: active count, total completions, best streak
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
API: PATCH /api/habits/[id] now handles both toggle (done: bool) and
edit (title + frequency). Added updateHabit() query.
UI: pencil icon appears on hover alongside delete; clicking opens an
inline form (title input + frequency select) in place of the row.
Enter/Escape shortcuts, optimistic local update, Escape cancels.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Habits query is at index 7, stale contacts at 8 — destructuring had
them swapped, causing TS2352 type mismatch. Reorder to match array.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Fix: HabitsList newFreq state typed as HabitFrequency to accept select value.
Feat: getTodaySummary now runs a parallel SQL query counting habits due
today (respects daily/weekdays/weekly frequency) and completions for
current_date. SummaryBar shows 'X/Y habits' pill — green when all done,
neutral otherwise. Hidden when no habits configured.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Inline search-as-you-type component below SummaryBar on Today page.
Two-step flow: search person → pick channel + optional note → POST to
/api/people/[id]/interactions. Refreshes /today so stale contacts pill
count updates immediately after logging.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
When George approves a send_message/send_email/follow_up action tied
to an entity, createInteraction() now fires immediately so contact
health scores update without requiring a manual People → detail → log
interaction flow. Also revalidates /people on approval.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Events: archive button (hover) moves event to archived section;
archived events collapsible at bottom with count; PATCH /api/events/[id]
for status change; getArchivedEvents() query; page fetches both in parallel.
Commitments: inline edit mode per row (pencil icon on hover); PATCH
/api/commitments/[id] for description/dueDate/financialImpact; extracted
CommitmentItem client component, CommitmentsCard stays server component.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- getEvents: filter by EVENT_STATUS.ACTIVE (consistency with getEventsDueSoon)
- getGoalStats: use GOAL_STATUS constants in filter expressions
- getActionStats: use ACTION_STATUS constants in filter expressions
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
ACTION_STATUS covers the full draft→approved→executed/rejected/expired flow
with the iron-rule comment intact. ALERT_SEVERITY covers info/warning/urgent.
actions.ts, today.ts, AlertsCard.tsx now use constants throughout.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
today.ts line 87, money.ts commitments query, api/commitments/route.ts all
now use GOAL_STATUS/COMMITMENT_STATUS constants. Status SSOT is now complete.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
today.ts and money.ts now use GOAL_STATUS/SUB_STATUS/COMMITMENT_STATUS instead
of magic strings. Adds COMMITMENT_STATUS (active/fulfilled) and SUB_STATUS.UNVERIFIED
to complete the status constants SSOT across the full stack.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
goals/route.ts, goals/[id]/route.ts, subscriptions/route.ts now import from
lib/constants/statuses.ts instead of using magic strings. Completes SSOT for
status values across the full stack (DB → API → components).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Move the two helper components into project-overview-helpers.tsx.
ProjectOverviewTab drops from 401 → 257 lines.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
ProgressInput, DateInput, AddMilestoneInline, MilestoneRow moved out of
GoalCard.tsx into a dedicated helpers file. GoalCard drops 507 → 240 lines.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Extract ScheduleModal and RunModal from the 649-line god component into
separate files. Add shared types.ts for Project type used by both modals.
PromptLibraryClient drops from 649 → 338 lines.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
lib/api/goals.ts: new patchGoal/createGoal/deleteGoal/listGoals helpers,
replacing inline fetch blocks in GoalCard (removes local patchGoal fn),
NewGoalButton, DeleteGoalButton, and ProjectGoalsTab. Same pattern as
attrs/crons helpers established earlier.
lib/constants/statuses.ts: GOAL_STATUS and SUB_STATUS constants replace
hardcoded "active"/"completed"/"cancelled" strings across 7 files.
Type-safe, single rename point if values ever change.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
goals schema: export Milestone type as SSOT — removes duplicate local
definitions in GoalCard (correct shape) and ProjectDetail (narrower, missing date?).
lib/api/crons.ts: new helpers createCronJob/patchCronJob — eliminates
5 identical fetch blocks across AutopilotCard, ProjectDetail, PromptLibraryClient.
All callers now one-liners; API contract changes are a single-file edit.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
lib/api/attrs.ts: new SSOT for entity-attr mutation calls. Eliminates 9
identical fetch blocks (4 in ProjectDetail, 5 in PersonDetail) — all
now one-liners via setAttr/removeAttr.
SubscriptionActions: extract shared onDeleteRecord() to remove the
duplicate DELETE fetch from both <DeleteButton> onDelete callbacks.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Both confirmDelete patterns in SubscriptionActions (post-cancel branch
and main actions bar) now delegate to the shared <DeleteButton> component.
Removes ~50 lines of duplicated state + JSX.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Three SSOT violations fixed:
1. CronJob type was defined in an API route and imported by components/pages
— now lives in lib/crons.ts, re-exported from route for back-compat
2. system/page.tsx hardcoded the cron file path instead of using CRON_FILE
— replaced loadJobs() with readCronJobs() from lib/crons
3. getLinkedJobs() in projects API route duplicated the file-read pattern
— now delegates to readCronJobs(), simplified with filter+map
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
confirmDelete state + Yes/No UI was repeated in EventsGrid, PersonDetail,
ProjectDetail, and DeleteGoalButton. Extracted to components/ui/delete-button.tsx
which manages confirming/deleting state internally; callers pass only onDelete().
DeleteGoalButton simplified from 50 lines to 15.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Searches project name, description, and all attribute values.
Shows live count, zero-results message. No API round-trip — all
15 projects are already loaded.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
PersonDetail.tsx had its own copy of HEALTH_LABEL identical to the one
in lib/utils.ts. Import from the SSOT instead.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
router.refresh() updates server props but can't re-initialize useState that
was already mounted. Instead, PersonCard calls onLogged(id, at) immediately
on success; PeopleGrid uses setPeople to update lastInteraction,
interactionCount, and health (via deriveRelationshipHealth) in place.
Card reflects the new state without any network round-trip.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
actions.ts was directly writing DB operations (update subscriptions set
status=cancelled) instead of delegating to the queries layer. Extracted
cancelSubscription() to db/queries/money.ts; actions.ts now calls it.
Matches the pattern used by all other server actions (approveAction,
rejectAction, dismissAlert, fulfillCommitment).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The "X contacts need attention" pill now links to /people?health=fading,stale,unknown
so it's immediately actionable rather than just informational.
People page now reads searchParams.health to initialize the health filter for
SSR and passes initialHealthFilter to PeopleGrid, which uses it as the initial
useState value. The skipInitialFetch ref still correctly suppresses the
redundant client fetch since SSR data already matches the filter.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
SSOT fix: health day thresholds (14/30) were duplicated between lib/utils.ts
(JS) and db/queries/people.ts (SQL strings). Extracted HEALTH_ACTIVE_DAYS=14
and HEALTH_FADING_DAYS=30 from utils.ts; people.ts now imports and uses them
via make_interval(days => ${N}) for proper parameterized binding.
Mission: Today SummaryBar now shows "X contacts need attention" (amber pill)
counting all people not contacted in the last 14+ days. Query runs in parallel
with existing getTodaySummary queries. Gives daily relationship OS pulse
without needing Ivy to have generated check-in actions.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
opacity-0 group-hover:opacity-100 means hover never fires on touch —
buttons for edit/delete/clear on goals, events, people attrs, project
attrs are permanently invisible on mobile.
Changed to sm:opacity-0 sm:group-hover:opacity-100 across 5 components
(9 occurrences): always visible below sm breakpoint, hover-revealed on
desktop. Decorative Zap hint in ProjectGrid left hover-only.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The Log button used opacity-0 group-hover:opacity-100 which never fires
on touch devices. Changed to always-visible on mobile (opacity-100),
hover-revealed on sm+ (sm:opacity-0 sm:group-hover:opacity-100).
Also moved from absolute positioning to normal flow to avoid overlap.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>