Skip to content

Commit b78fbfc

Browse files
authored
fix: default category in ML schema + expose snippet in suggestions (#17)
* docs: update reentry and project state for ml defaults * fix: default category and expose snippet in suggestions
1 parent 3b9dfe3 commit b78fbfc

File tree

5 files changed

+15
-11
lines changed

5 files changed

+15
-11
lines changed

PROJECT_STATE.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
# PROJECT_STATE.md
2-
3-
Last updated: 2026-01-18 02:35 CST — Commit: pending
2+
Last updated: 2026-01-29 00:00 CST — Commit: pending
43

54
## 1. Technical Header (Snapshot Metadata)
65

76
PROJECT_NAME: Email Cleaner & Smart Notifications — Fastify Backend
8-
SNAPSHOT_DATE: 2026-01-18 02:35 CST
7+
SNAPSHOT_DATE: 2026-01-29 00:00 CST
98
COMMIT: pending
109
ENVIRONMENT: local
1110

1211
REPO_PATH: /Users/gil/Documents/email-cleaner/email-cleaner-fastify
13-
BRANCH: main
12+
BRANCH: develop
1413
WORKING_TREE_STATUS: Dirty (modified files present)
1514

1615
RUNTIME: Node.js (Fastify)
@@ -27,7 +26,7 @@ LAST_VERIFIED_TESTS_DATE: 2026-01-18 02:35 CST
2726
- OAuth flow validates `state`, issues `session_token`, and redirects to `${FRONTEND_ORIGIN}/auth/callback`.
2827
- Auth middleware accepts session cookie or Bearer session JWT and sets `request.user`.
2928
- `/api/v1/emails` returns raw Gmail emails without ML.
30-
- `/api/v1/suggestions` enriches emails with ML suggestions and publishes domain events when threshold is met.
29+
- `/api/v1/suggestions` enriches emails with ML suggestions, includes `snippet`, and publishes domain events when threshold is met.
3130
- `/api/v1/notifications/summary` aggregates `NotificationEvent` records by period.
3231
- Gmail OAuth client persists refreshed access tokens to the `Tokens` table.
3332
- OAuth tokens are encrypted at rest using `TOKEN_ENCRYPTION_KEY`.
@@ -67,6 +66,8 @@ LAST_VERIFIED_TESTS_DATE: 2026-01-18 02:35 CST
6766
- Gmail OAuth clients are created via `src/services/googleAuthService.js`.
6867
- ML service integration via `src/services/suggestionService.js` and `src/services/mlClient.js`.
6968
- n8n webhook listener exists (safe no-op).
69+
- Gmail metadata defaults `category` to `unknown` when no label match is found.
70+
- ML schema accepts missing `category` with default `unknown`.
7071

7172
---
7273

@@ -88,7 +89,7 @@ LAST_VERIFIED_TESTS_DATE: 2026-01-18 02:35 CST
8889
- Summary windowing uses `createdAt`; time zone alignment is not verified.
8990

9091
**Recent change:**
91-
- No change in this snapshot (commit: pending).
92+
- ML schema defaulted `category` and suggestions schema includes `snippet` (commit: pending).
9293

9394
### HU18 — Google OAuth session flow (backend)
9495

@@ -120,10 +121,11 @@ LAST_VERIFIED_TESTS_DATE: 2026-01-18 02:35 CST
120121

121122
## 6. Next Immediate Action
122123

123-
➡️ Commit changes on `main`.
124+
➡️ Commit Fastify fixes on a feature branch from `develop`.
124125

125126
---
126127

127128
## Version log
128129

129130
- 2026-01-18 02:35 CST — OAuth state, token encryption, and logging hardening (commit: pending)
131+
- 2026-01-29 00:00 CST — ML schema default category + suggestions schema includes snippet (commit: pending)

README_REENTRY.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717

1818
## 1) Current snapshot (minimum that matters)
1919

20-
- Branch: `main`
20+
- Branch: `develop`
2121
- Latest checkpoint: `PROJECT_STATE.md`
22-
- Backend tests: PASS (Jest, 13 suites / 47 tests)
22+
- Backend tests: last verified PASS (Jest, 13 suites / 47 tests) on 2026-01-18
2323
- Auth flow: Google OAuth validates `state`, sets httpOnly `session_token` cookie, and validates JWT via `authMiddleware`
2424
- OAuth tokens are encrypted at rest (`TOKEN_ENCRYPTION_KEY`)
2525
- Gmail client persists refreshed tokens to the `Tokens` table

python/classifier/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Email(BaseModel):
1313
from_: str = Field(..., alias="from")
1414
date: str
1515
isRead: bool
16-
category: str
16+
category: str = "unknown"
1717
attachmentSizeMb: float
1818

1919
from datetime import datetime, timezone

src/routes/suggestionRoutes.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const emailSuggestionSchema = {
1010
from: { type: 'string' },
1111
subject: { type: 'string' },
1212
date: { type: 'string' },
13+
snippet: { type: 'string' },
1314
isRead: { type: 'boolean' },
1415
category: { type: 'string' },
1516
attachmentSizeMb: { type: 'number' },
@@ -56,6 +57,7 @@ export default async function (fastify, opts) {
5657
from: "notificaciones@ejemplo.com",
5758
subject: "Promoción especial",
5859
date: "2024-07-01T12:00:00Z",
60+
snippet: "Short preview of the email body.",
5961
isRead: false,
6062
category: "promotions",
6163
attachmentSizeMb: 2.5,

src/services/gmailService.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export class GmailService {
9090
date: headers.date || '',
9191
labels: msgData.data.labelIds || [],
9292
isRead: !(msgData.data.labelIds?.includes('UNREAD')),
93-
category: detectCategoryFromLabels(msgData.data.labelIds || []),
93+
category: detectCategoryFromLabels(msgData.data.labelIds || []) || 'unknown',
9494
attachmentSizeMb: msgData.data.sizeEstimate
9595
? msgData.data.sizeEstimate / (1024 * 1024)
9696
: 0,

0 commit comments

Comments
 (0)