Extend the per-client preview flow to the per-group "Generate Tasks"
button on the client page, backfill missing templates instead of
skipping groups/policies that already have any template task, and add
a reusable searchable ClientSelect component.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Bite-sized, TDD-ordered plan for docs/superpowers/specs/2026-07-18-task-generation-preview-and-per-client-design.md.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Adds a clientId targeting mode and a dryRun flag to the admin
generate-and-assign tool, plus a confirmation dialog showing summary
counts before any tasks are actually created.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Paused mid-brainstorm at user request. Records the approved architecture
shape (DB-trigger-based change capture, run-scoped restore, hourly rollup
for oversight) and the open items to pick up on resume.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Extracts the cron-only auto-generate logic into shared modules
(lib/sync/auto-generate.ts, automation-config.ts) and adds
group-auto-assign.ts, which attaches ungrouped policies to an existing
renewal group when their renewal dates are close. Both now also run
automatically after every AMS sync (sync-engine.ts), guarded by a
Postgres advisory lock so overlapping syncs cannot double-generate.
The external /api/cron/auto-generate endpoint remains for manual/
out-of-band triggering, delegating to the same shared engine.
Adds an admin settings UI + /api/admin/automation-settings route to
configure grace periods and toggles without a redeploy, and surfaces
the new audit actions (AUTO_GENERATE_TASKS_CLIENT, AUTO_ASSIGN_POLICY_GROUP)
in the audit log filters.
Includes a fixed AUTOMATION_GO_LIVE_AT floor (2026-07-07) in
automation-config.ts, applied to every candidate query in
auto-generate.ts and group-auto-assign.ts. Without it, the first run
after enabling this treated every historical policy/client/group that
happened to be old enough as newly eligible, generating tasks anchored
to old renewal/expiration dates in one burst (incident: 6,552 tasks
created 2026-07-07 02:01, most already 1-2 years overdue for Jeanne
Strong and Luke Billman; cleaned up same day after a verified backup).
The floor ensures automation only ever processes records created from
its go-live date forward.