#!/usr/bin/env -S npx --yes tsx
// =============================================================================
// list_prs_no_active_review_ci_passing.ts — Open PRs with passing CI, zero
//                                            approvals, and no active
//                                            REQUEST_CHANGES reviews
//
// Part of: .opencode/skills/auto-agents-system/scripts/
//
// Delegates to list_prs.ts with hard-coded filters.
//
// Returns all OPEN pull requests that:
//   • have passing CI                                    (ci_status == 'passing')
//     i.e. all commit status checks have succeeded for the PR's head SHA.
//   • have zero active review approvals                  (approvals_count == 0)
//     i.e. no reviewer's most recent non-dismissed review is APPROVED.
//   • have NO active REQUEST_CHANGES reviews
//     (hasRequestChanges == false)
//     i.e. no reviewer's latest non-dismissed review is REQUEST_CHANGES.
//
// This bucket captures PRs that are waiting for a fresh review with no
// outstanding reviewer feedback to address.  It includes:
//   • PRs that have never been reviewed at all
//   • PRs where all previous reviews were COMMENT (non-blocking)
//   • PRs where previous REQUEST_CHANGES reviews have been dismissed
//   • PRs where a reviewer who previously requested changes later submitted
//     a COMMENT or had their review dismissed
//
// The common thread is: no reviewer is currently blocking the PR with a
// REQUEST_CHANGES stance, no one has approved it, and CI is green — the PR
// is ready for a full peer review from scratch.
//
// Hard-coded filters (not configurable):
//   state:             'open'      only open PRs are considered
//   ciStatus:          ['passing'] all CI checks must have succeeded
//   maxApprovals:      0           no active approvals from any reviewer
//   hasRequestChanges: false       no reviewer's latest review is REQUEST_CHANGES
//
// USAGE:
//   list_prs_no_active_review_ci_passing.ts --url URL --pat TOKEN --owner OWNER --repo REPO
//
// OUTPUT (stdout): JSON array — same schema as list_prs.ts
// DEPENDENCIES: Node.js >= 18 (native fetch), npx tsx (for TypeScript execution)
// =============================================================================
import { listPRs, parseConnectionArgs } from './list_prs.ts';

async function main(): Promise<void> {
  const config = parseConnectionArgs(process.argv);
  const prs    = await listPRs(config, {
    state:             'open',
    ciStatus:          ['passing'],
    maxApprovals:      0,
    hasRequestChanges: false,
  });
  process.stdout.write(JSON.stringify(prs, null, 2) + '\n');
}

main().catch((err: unknown) => {
  process.stderr.write(`ERROR: ${err instanceof Error ? err.message : String(err)}\n`);
  process.exit(1);
});
