// AGENT INSTRUCTION: After every write (INSERT/UPDATE/DELETE), you MUST: // 1. Insert activity feed entry // 2. Call pg.notify('project_e_events', JSON.stringify({ type, action, id, workspace_id })) // See AGENTS.md for full rules. import { NextRequest, NextResponse } from 'next/server'; import { withAuth, createErrorResponse } from '@/lib/auth'; import { createPocketBaseClient } from '@/lib/pocketbase'; // ── Helpers ────────────────────────────────────────────────────────────────── /** Parse a "YYYY-MM-DD" string into start/end ISO boundaries (UTC). */ function dayBounds(dateStr: string) { const start = new Date(`${dateStr}T00:00:00.000Z`); const end = new Date(`${dateStr}T23:59:59.999Z`); return { start: start.toISOString(), end: end.toISOString() }; } /** Format minutes into a human-readable "Xh Ym" string. */ function formatMinutes(total: number): string { if (total < 60) return `${total}m`; const h = Math.floor(total / 60); const m = total % 60; return m > 0 ? `${h}h ${m}m` : `${h}h`; } /** Escape HTML special characters. */ function esc(text: string): string { return text .replace(/&/g, '&') .replace(//g, '>') .replace(/"/g, '"'); } /** Build an