email-activity agent: propose -> review -> approve grid notes (v0.1.0:64)

When a sent/received email is matched to an investor, a local-model agent drafts a
one-line dated note and queues it as a PENDING proposal (it never writes the grid
itself). On the Email Capture page a partner sees "Proposed grid notes", can edit the
text, and Approve (appends to that investor's grid notes cell, newest at bottom,
stamped with the approver) or Dismiss. Going-forward only: a cutoff (app_settings
email_activity_since, set on first run) means email dated before the feature was
enabled is never summarized, so the historical backfill makes no noise. Sovereign:
summaries run entirely on the local model (no redaction needed). Gmail sync interval
tightened 180 -> 15 min so outgoing email surfaces quickly.

Backend: migration 0002 (email_activity_proposals); propose_email_activity_notes()
runs via a new scheduler post_sync hook; list/decide functions + routes
GET /api/activity/proposals, POST .../{id}/approve|dismiss. Grid append stamps the
approving user (fundraising_state.updated_by has a FK to users). Test
test_email_activity.py (propose cutoff/idempotency, approve appends + edited note,
dismiss, already-decided guard) under FK enforcement.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Keysat
2026-06-06 15:55:26 -05:00
parent 3893a4fb9f
commit 069e60053b
9 changed files with 462 additions and 7 deletions
+9 -1
View File
@@ -57,7 +57,10 @@ def _conn_factory_from_env() -> Callable[[], sqlite3.Connection]:
return get_db
def start_sync_scheduler(conn_factory: Optional[Callable] = None) -> None:
def start_sync_scheduler(conn_factory: Optional[Callable] = None,
post_sync: Optional[Callable] = None) -> None:
"""Start the periodic Gmail sync loop. `post_sync`, if given, is called after each
sync pass (best-effort) — used to run the email-activity summarizer."""
if _state["thread"] is not None:
return # already running
@@ -98,6 +101,11 @@ def start_sync_scheduler(conn_factory: Optional[Callable] = None) -> None:
finally:
_state["running_now"] = False
_state["last_run"] = t0
if post_sync is not None:
try:
post_sync()
except Exception:
log.exception("post_sync hook failed; continuing")
if stop.wait(_cfg.CONFIG.sync_interval_sec):
return