/**
 * GET /api/watches — list background long-task watches (active first,
 * then recent terminal). Read-only management surface for the watch
 * runner that lives in chat-standalone; both share workflow.db.
 */
import { NextResponse } from 'next/server';
import { listWatches } from '@/lib/watch/watch-store';

export async function GET(req: Request) {
  const url = new URL(req.url);
  const limit = Math.min(200, Math.max(1, Number(url.searchParams.get('limit')) || 50));
  try {
    return NextResponse.json({ watches: listWatches(limit) });
  } catch (e) {
    return NextResponse.json({ error: (e as Error).message }, { status: 500 });
  }
}
