Skip to content

CLI update prompts and admin broadcast notifications #279

Closed

Description

@neuromechanist

Overview

Two complementary features for keeping users informed:

  1. CLI update prompts - notify users when a newer CLI version is available
  2. Admin broadcast emails - let admins send announcements to user groups

Feature 1: CLI Update Prompts

Approach: Hybrid (client-side check + backend notice)

A. Client-side npm registry check (primary)

Similar to how gh CLI does it:

  1. On each CLI invocation, spawn a non-blocking background check against the npm registry
  2. Cache the result locally (~/.nemar/update-check.json) with a TTL (e.g., 24 hours)
  3. If a newer version exists, print a yellow banner after command output:
A new version of nemar is available: 0.7.17 -> 0.8.0
Run `bun install -g nemar` to update

Implementation:

  • New module: src/lib/update-check.ts
  • Check URL: https://registry.npmjs.org/nemar/latest (tiny JSON response)
  • Compare with semver (skip pre-release versions like -dev)
  • Cache file: ~/.nemar/update-check.json with { lastCheck, latestVersion }
  • Environment variable NEMAR_NO_UPDATE_CHECK=1 to disable (for CI/scripts)
  • The check must never block or slow down the CLI; fire-and-forget with result used on next run

B. Backend notice field (supplementary)

Add an optional notice field to key API responses (e.g., auth status, dataset list):

{
  "data": { ... },
  "notice": {
    "message": "NEMAR CLI v0.8.0 is available with major improvements. Run `bun install -g nemar` to update.",
    "level": "info",
    "id": "update-0.8.0"
  }
}
  • Backend stores active notices in a D1 table or KV
  • CLI displays notices it hasn't shown before (track dismissed notice IDs locally)
  • Useful for messages beyond just version updates (maintenance windows, breaking changes, etc.)
  • Admin can set/clear notices via nemar admin notice set/clear

Notice levels: info (blue), warning (yellow), critical (red, can't dismiss)


Feature 2: Admin Broadcast Emails

Design

Extend the existing Resend email service to support broadcast emails.

New admin command

# Send to all approved users
nemar admin notify --to all --subject "New feature: dataset cloning" --body "We've added..."

# Send to admins only
nemar admin notify --to admins --subject "Maintenance window" --body "..."

# Send to specific role
nemar admin notify --to members --subject "..." --body "..."

# Preview (dry run, shows recipient count)
nemar admin notify --to all --subject "..." --body "..." --dry-run

# From a file (for longer messages)
nemar admin notify --to all --subject "..." --body-file announcement.md

Backend endpoint

POST /admin/notify
{
  "target": "all" | "admins" | "members",
  "subject": "...",
  "body": "...",          // Plain text or simple markdown
  "dry_run": false
}

Response:

{
  "sent_to": 42,
  "skipped_opted_out": 3,
  "failed": 0
}

Email preferences extension

Extend the existing email_preferences JSON column:

{
  "user_approval": true,
  "publication_request": true,
  "announcements": true       // new; defaults to true
}

Users who set announcements: false are skipped (except for critical level notices).

Safeguards

  • Owner/admin only (role check)
  • Confirmation prompt in CLI before sending ("Send to 42 users? [y/N]")
  • --dry-run flag to preview
  • Rate limit: max 1 broadcast per hour (prevent accidental double-sends)
  • Log broadcasts in D1 (admin_notifications table) for audit trail

Implementation Plan

Phase 1: CLI update check (client-side)

  • src/lib/update-check.ts with npm registry check + cache
  • Hook into CLI entry point (non-blocking)
  • NEMAR_NO_UPDATE_CHECK env var support
  • Display update banner after command output

Phase 2: Backend notices

  • D1 migration for notices table
  • Admin endpoints: POST /admin/notices, DELETE /admin/notices/:id
  • CLI commands: nemar admin notice set, nemar admin notice clear
  • Middleware to attach active notice to API responses
  • CLI display logic with local dismissal tracking

Phase 3: Admin broadcast emails

  • D1 migration for admin_notifications audit table
  • Extend email_preferences with announcements category
  • POST /admin/notify endpoint with role filtering
  • nemar admin notify CLI command with dry-run and confirmation
  • Email template for announcements

Open Questions

  • Should the backend notice system use D1 or KV? (KV is simpler for key-value notices, D1 better for audit)
  • Should broadcast emails support HTML/markdown rendering or plain text only?
  • Should there be a nemar preferences command for users to manage their own email preferences from the CLI?

Activity

  1. added 3 commits that reference this issue on Mar 11, 2026
    c84ffbe
    501382d
    1fea691
  2. neuromechanist commented on Mar 11, 2026

    @neuromechanist
    ContributorAuthor

    Implemented in PR #280. All three phases complete: CLI update check, system notices, admin broadcast emails. Migrations 0016/0017 applied to D1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew feature or enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions