limn-review 0.1.123
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +110 -0
- package/README.md +133 -0
- package/dist/ai/runtime.js +535 -0
- package/dist/api/plugins/auth.js +169 -0
- package/dist/api/plugins/error-handler.js +114 -0
- package/dist/api/plugins/rate-limit.js +855 -0
- package/dist/api/plugins/security.js +321 -0
- package/dist/api/routes/activity.js +103 -0
- package/dist/api/routes/ai-runtime.js +67 -0
- package/dist/api/routes/auth.js +194 -0
- package/dist/api/routes/billing.js +209 -0
- package/dist/api/routes/bot-triage.js +1289 -0
- package/dist/api/routes/conflicts.js +730 -0
- package/dist/api/routes/contact.js +318 -0
- package/dist/api/routes/daily-brief.js +58 -0
- package/dist/api/routes/flow.js +71 -0
- package/dist/api/routes/health.js +7 -0
- package/dist/api/routes/insights.js +200 -0
- package/dist/api/routes/me.js +458 -0
- package/dist/api/routes/mentions.js +22 -0
- package/dist/api/routes/mergers.js +8 -0
- package/dist/api/routes/ml-labels.js +109 -0
- package/dist/api/routes/open-prs.js +35 -0
- package/dist/api/routes/prs.js +1633 -0
- package/dist/api/routes/reactions.js +217 -0
- package/dist/api/routes/repos.js +563 -0
- package/dist/api/routes/search.js +41 -0
- package/dist/api/routes/threads.js +118 -0
- package/dist/api/routes/timeline.js +150 -0
- package/dist/api/routes/users.js +67 -0
- package/dist/api/routes/webhooks.js +181 -0
- package/dist/api/routes/workspaces.js +322 -0
- package/dist/app.js +274 -0
- package/dist/ascii.js +19 -0
- package/dist/auth/account.js +482 -0
- package/dist/auth/crypto.js +46 -0
- package/dist/bot-triage/resolve.js +59 -0
- package/dist/cli.js +388 -0
- package/dist/coding/activity.js +80 -0
- package/dist/coding/agent.js +288 -0
- package/dist/coding/ai-fix/auto-fix.js +212 -0
- package/dist/coding/ai-fix/manager.js +370 -0
- package/dist/coding/ai-fix/persist.js +213 -0
- package/dist/coding/ai-fix/pr-context.js +58 -0
- package/dist/coding/ai-fix/prompts.js +138 -0
- package/dist/coding/ai-fix/review-seed.js +357 -0
- package/dist/coding/ai-fix/routes.js +425 -0
- package/dist/coding/git-ops.js +321 -0
- package/dist/coding/git.js +184 -0
- package/dist/coding/merge.js +262 -0
- package/dist/coding/safe-path.js +75 -0
- package/dist/coding/schema.js +43 -0
- package/dist/config.js +648 -0
- package/dist/conflict/diff.js +304 -0
- package/dist/conflict/git.js +118 -0
- package/dist/conflict/hash.js +73 -0
- package/dist/conflict/janitor.js +218 -0
- package/dist/conflict/land.js +675 -0
- package/dist/conflict/model-types.js +2 -0
- package/dist/conflict/model.js +1081 -0
- package/dist/conflict/parse.js +142 -0
- package/dist/conflict/seam.js +136 -0
- package/dist/conflict/session.js +532 -0
- package/dist/conflict/suggestion.js +398 -0
- package/dist/conflict/tokens.js +72 -0
- package/dist/data-dir.js +112 -0
- package/dist/db/actor-lanes.js +213 -0
- package/dist/db/automation-ids.js +97 -0
- package/dist/db/automation-output.js +349 -0
- package/dist/db/blast-radius-query.js +36 -0
- package/dist/db/blast-radius.js +226 -0
- package/dist/db/bot-dormancy.js +115 -0
- package/dist/db/bot-overlap.js +579 -0
- package/dist/db/bot-volume.js +722 -0
- package/dist/db/bot-window.js +35 -0
- package/dist/db/branch-queries.js +310 -0
- package/dist/db/change-shape.js +243 -0
- package/dist/db/changepoint.js +75 -0
- package/dist/db/cleanup.js +36 -0
- package/dist/db/client.js +102 -0
- package/dist/db/code-loc.js +388 -0
- package/dist/db/credits.js +79 -0
- package/dist/db/daily-brief.js +406 -0
- package/dist/db/dependency-cards.js +145 -0
- package/dist/db/erase-account.js +255 -0
- package/dist/db/export-account.js +189 -0
- package/dist/db/failing-checks.js +124 -0
- package/dist/db/file-coupling.js +197 -0
- package/dist/db/flow-detail.js +661 -0
- package/dist/db/flow-pointers.js +197 -0
- package/dist/db/flow-settings.js +67 -0
- package/dist/db/forecast.js +114 -0
- package/dist/db/line-overlap.js +81 -0
- package/dist/db/merge-queue.js +189 -0
- package/dist/db/migrate.js +17 -0
- package/dist/db/migrations/0000_purple_ben_grimm.sql +155 -0
- package/dist/db/migrations/0001_colorful_ozymandias.sql +31 -0
- package/dist/db/migrations/0002_famous_sersi.sql +9 -0
- package/dist/db/migrations/0003_clever_shinobi_shaw.sql +3 -0
- package/dist/db/migrations/0004_pale_scalphunter.sql +1 -0
- package/dist/db/migrations/0005_daffy_guardian.sql +2 -0
- package/dist/db/migrations/0006_cute_violations.sql +45 -0
- package/dist/db/migrations/0007_dark_anthem.sql +2 -0
- package/dist/db/migrations/0008_multitenant_accounts.sql +44 -0
- package/dist/db/migrations/0009_lean_bodies.sql +13 -0
- package/dist/db/migrations/0010_lean_bodies_nullable.sql +56 -0
- package/dist/db/migrations/0011_pr_diff_size.sql +10 -0
- package/dist/db/migrations/0012_findings_included_default.sql +7 -0
- package/dist/db/migrations/0013_review_routing.sql +9 -0
- package/dist/db/migrations/0014_account_last_active.sql +6 -0
- package/dist/db/migrations/0015_repos_inbox_watch.sql +9 -0
- package/dist/db/migrations/0016_repo_viewer_permission.sql +7 -0
- package/dist/db/migrations/0017_account_display_name.sql +7 -0
- package/dist/db/migrations/0018_finding_comment_kind.sql +7 -0
- package/dist/db/migrations/0019_finding_file_in_diff.sql +7 -0
- package/dist/db/migrations/0020_claude_review_cost_telemetry.sql +11 -0
- package/dist/db/migrations/0021_account_feed_last_seen.sql +7 -0
- package/dist/db/migrations/0022_ci_status_events.sql +21 -0
- package/dist/db/migrations/0023_ai_usage.sql +21 -0
- package/dist/db/migrations/0024_pr_head_ref_name.sql +6 -0
- package/dist/db/migrations/0025_account_billing.sql +7 -0
- package/dist/db/migrations/0026_ai_credit_allowance.sql +5 -0
- package/dist/db/migrations/0027_user_github_type.sql +6 -0
- package/dist/db/migrations/0028_bot_review_classification.sql +21 -0
- package/dist/db/migrations/0029_bot_mute_rules.sql +19 -0
- package/dist/db/migrations/0030_teams.sql +32 -0
- package/dist/db/migrations/0031_events_pr_idx.sql +7 -0
- package/dist/db/migrations/0032_benchmark_contributions.sql +29 -0
- package/dist/db/migrations/0033_thread_addressed_confidence.sql +9 -0
- package/dist/db/migrations/0034_thread_resolved_at.sql +6 -0
- package/dist/db/migrations/0035_pr_first_review_requested_at.sql +5 -0
- package/dist/db/migrations/0036_search_index.sql +25 -0
- package/dist/db/migrations/0037_author_indexes.sql +15 -0
- package/dist/db/migrations/0038_auto_merge_requests.sql +37 -0
- package/dist/db/migrations/0039_branch_status.sql +44 -0
- package/dist/db/migrations/0040_pr_review_decision.sql +10 -0
- package/dist/db/migrations/0041_branch_commit_detail.sql +38 -0
- package/dist/db/migrations/0042_repo_reviewers.sql +176 -0
- package/dist/db/migrations/0043_account_reviewers.sql +131 -0
- package/dist/db/migrations/0044_workspaces.sql +138 -0
- package/dist/db/migrations/0045_workspace_reviewers.sql +180 -0
- package/dist/db/migrations/0046_drop_inbox_watch.sql +25 -0
- package/dist/db/migrations/0047_ml_comment_labels.sql +40 -0
- package/dist/db/migrations/0048_ml_vendor_severity.sql +31 -0
- package/dist/db/migrations/0049_seat_pricing_repo_description.sql +21 -0
- package/dist/db/migrations/0050_users_app_slug.sql +12 -0
- package/dist/db/migrations/0051_auto_merge_queue.sql +17 -0
- package/dist/db/migrations/0052_trunk_ci_status_events.sql +43 -0
- package/dist/db/migrations/0053_automation_roles.sql +79 -0
- package/dist/db/migrations/0054_automation_vendor_kinds.sql +514 -0
- package/dist/db/migrations/0055_auto_merge_phase.sql +12 -0
- package/dist/db/migrations/0056_pr_mentions.sql +22 -0
- package/dist/db/migrations/0057_large_pr_threshold.sql +14 -0
- package/dist/db/migrations/0058_pending_mute.sql +53 -0
- package/dist/db/migrations/0059_merge_queue_state.sql +33 -0
- package/dist/db/migrations/0060_drop_my_turn_dismissals.sql +33 -0
- package/dist/db/migrations/0061_auto_merge_durable_anchors.sql +27 -0
- package/dist/db/migrations/0062_blast_radius_config.sql +21 -0
- package/dist/db/migrations/0063_repo_file_coupling.sql +33 -0
- package/dist/db/migrations/0064_pr_content_kind.sql +21 -0
- package/dist/db/migrations/0065_workspace_flow_settings.sql +13 -0
- package/dist/db/migrations/0066_review_request_events.sql +31 -0
- package/dist/db/migrations/0067_pr_security_signals.sql +86 -0
- package/dist/db/migrations/0068_my_turn_settings.sql +18 -0
- package/dist/db/migrations/0069_my_turn_dismissals.sql +41 -0
- package/dist/db/migrations/0070_claude_review_follow_up_ticket.sql +22 -0
- package/dist/db/migrations/0071_claude_review_trigger.sql +11 -0
- package/dist/db/migrations/0072_commit_message_headline.sql +13 -0
- package/dist/db/migrations/0073_claude_review_chat.sql +31 -0
- package/dist/db/migrations/0074_adopt_agentic_tables.sql +98 -0
- package/dist/db/migrations/0075_review_lens_drop_learnings.sql +15 -0
- package/dist/db/migrations/0076_claude_review_threads.sql +17 -0
- package/dist/db/migrations/0077_claude_review_ci_failures.sql +10 -0
- package/dist/db/migrations/0078_ai_fix_change_report.sql +17 -0
- package/dist/db/migrations/0079_claude_finding_story.sql +16 -0
- package/dist/db/migrations/meta/0000_snapshot.json +1116 -0
- package/dist/db/migrations/meta/0001_snapshot.json +1321 -0
- package/dist/db/migrations/meta/0002_snapshot.json +1375 -0
- package/dist/db/migrations/meta/0003_snapshot.json +1396 -0
- package/dist/db/migrations/meta/0004_snapshot.json +1416 -0
- package/dist/db/migrations/meta/0005_snapshot.json +1430 -0
- package/dist/db/migrations/meta/0006_snapshot.json +1745 -0
- package/dist/db/migrations/meta/0007_snapshot.json +1759 -0
- package/dist/db/migrations/meta/_journal.json +566 -0
- package/dist/db/migrations-pg/0000_tired_alex_power.sql +268 -0
- package/dist/db/migrations-pg/0001_dizzy_mockingbird.sql +3 -0
- package/dist/db/migrations-pg/0002_glorious_ikaris.sql +4 -0
- package/dist/db/migrations-pg/0003_melted_secret_warriors.sql +2 -0
- package/dist/db/migrations-pg/0004_numerous_triton.sql +1 -0
- package/dist/db/migrations-pg/0005_thick_blockbuster.sql +2 -0
- package/dist/db/migrations-pg/0006_majestic_dracula.sql +1 -0
- package/dist/db/migrations-pg/0007_same_human_torch.sql +2 -0
- package/dist/db/migrations-pg/0008_slimy_toxin.sql +1 -0
- package/dist/db/migrations-pg/0009_fuzzy_jubilee.sql +4 -0
- package/dist/db/migrations-pg/0010_late_hammerhead.sql +1 -0
- package/dist/db/migrations-pg/0011_happy_leech.sql +16 -0
- package/dist/db/migrations-pg/0012_woozy_captain_midlands.sql +16 -0
- package/dist/db/migrations-pg/0013_yielding_nicolaos.sql +1 -0
- package/dist/db/migrations-pg/0014_wakeful_bill_hollister.sql +2 -0
- package/dist/db/migrations-pg/0015_aspiring_black_tom.sql +1 -0
- package/dist/db/migrations-pg/0016_cute_ghost_rider.sql +30 -0
- package/dist/db/migrations-pg/0017_far_changeling.sql +24 -0
- package/dist/db/migrations-pg/0018_fancy_miss_america.sql +1 -0
- package/dist/db/migrations-pg/0019_benchmark_contributions.sql +22 -0
- package/dist/db/migrations-pg/0020_majestic_edwin_jarvis.sql +3 -0
- package/dist/db/migrations-pg/0021_green_salo.sql +1 -0
- package/dist/db/migrations-pg/0022_wise_baron_strucker.sql +1 -0
- package/dist/db/migrations-pg/0023_search_index.sql +19 -0
- package/dist/db/migrations-pg/0024_author_indexes.sql +9 -0
- package/dist/db/migrations-pg/0025_auto_merge_requests.sql +26 -0
- package/dist/db/migrations-pg/0026_branch_status.sql +32 -0
- package/dist/db/migrations-pg/0027_pr_review_decision.sql +5 -0
- package/dist/db/migrations-pg/0028_branch_commit_detail.sql +9 -0
- package/dist/db/migrations-pg/0029_repo_reviewers.sql +127 -0
- package/dist/db/migrations-pg/0030_account_reviewers.sql +77 -0
- package/dist/db/migrations-pg/0031_workspaces.sql +131 -0
- package/dist/db/migrations-pg/0032_workspace_reviewers.sql +165 -0
- package/dist/db/migrations-pg/0033_drop_inbox_watch.sql +14 -0
- package/dist/db/migrations-pg/0034_ml_comment_labels.sql +33 -0
- package/dist/db/migrations-pg/0035_ml_vendor_severity.sql +16 -0
- package/dist/db/migrations-pg/0036_seat_pricing_repo_description.sql +12 -0
- package/dist/db/migrations-pg/0037_users_app_slug.sql +9 -0
- package/dist/db/migrations-pg/0038_auto_merge_queue.sql +10 -0
- package/dist/db/migrations-pg/0039_trunk_ci_status_events.sql +27 -0
- package/dist/db/migrations-pg/0040_automation_roles.sql +63 -0
- package/dist/db/migrations-pg/0041_automation_vendor_kinds.sql +488 -0
- package/dist/db/migrations-pg/0042_auto_merge_phase.sql +8 -0
- package/dist/db/migrations-pg/0043_pr_mentions.sql +19 -0
- package/dist/db/migrations-pg/0044_large_pr_threshold.sql +6 -0
- package/dist/db/migrations-pg/0045_pending_mute.sql +26 -0
- package/dist/db/migrations-pg/0046_merge_queue_state.sql +18 -0
- package/dist/db/migrations-pg/0047_drop_my_turn_dismissals.sql +21 -0
- package/dist/db/migrations-pg/0048_auto_merge_durable_anchors.sql +27 -0
- package/dist/db/migrations-pg/0049_blast_radius_config.sql +8 -0
- package/dist/db/migrations-pg/0050_repo_file_coupling.sql +13 -0
- package/dist/db/migrations-pg/0051_pr_content_kind.sql +6 -0
- package/dist/db/migrations-pg/0052_workspace_flow_settings.sql +4 -0
- package/dist/db/migrations-pg/0053_review_request_events.sql +18 -0
- package/dist/db/migrations-pg/0054_pr_security_signals.sql +59 -0
- package/dist/db/migrations-pg/0055_my_turn_settings.sql +6 -0
- package/dist/db/migrations-pg/0056_my_turn_dismissals.sql +21 -0
- package/dist/db/migrations-pg/0057_claude_review_follow_up_ticket.sql +8 -0
- package/dist/db/migrations-pg/0058_claude_review_trigger.sql +4 -0
- package/dist/db/migrations-pg/0059_commit_message_headline.sql +3 -0
- package/dist/db/migrations-pg/0060_claude_review_chat.sql +24 -0
- package/dist/db/migrations-pg/0061_adopt_agentic_tables.sql +79 -0
- package/dist/db/migrations-pg/0062_review_lens_drop_learnings.sql +5 -0
- package/dist/db/migrations-pg/0063_claude_review_threads.sql +7 -0
- package/dist/db/migrations-pg/0064_claude_review_ci_failures.sql +4 -0
- package/dist/db/migrations-pg/0065_ai_fix_change_report.sql +9 -0
- package/dist/db/migrations-pg/0066_claude_finding_story.sql +7 -0
- package/dist/db/migrations-pg/meta/0000_snapshot.json +2137 -0
- package/dist/db/migrations-pg/meta/0001_snapshot.json +2143 -0
- package/dist/db/migrations-pg/meta/0002_snapshot.json +2170 -0
- package/dist/db/migrations-pg/meta/0003_snapshot.json +2182 -0
- package/dist/db/migrations-pg/meta/0004_snapshot.json +2188 -0
- package/dist/db/migrations-pg/meta/0005_snapshot.json +2201 -0
- package/dist/db/migrations-pg/meta/0006_snapshot.json +2207 -0
- package/dist/db/migrations-pg/meta/0007_snapshot.json +2219 -0
- package/dist/db/migrations-pg/meta/0008_snapshot.json +2226 -0
- package/dist/db/migrations-pg/meta/0009_snapshot.json +2250 -0
- package/dist/db/migrations-pg/meta/0010_snapshot.json +2256 -0
- package/dist/db/migrations-pg/meta/0011_snapshot.json +2412 -0
- package/dist/db/migrations-pg/meta/0012_snapshot.json +2528 -0
- package/dist/db/migrations-pg/meta/0013_snapshot.json +2534 -0
- package/dist/db/migrations-pg/meta/0014_snapshot.json +2547 -0
- package/dist/db/migrations-pg/meta/0015_snapshot.json +2553 -0
- package/dist/db/migrations-pg/meta/0016_snapshot.json +2774 -0
- package/dist/db/migrations-pg/meta/0017_snapshot.json +2999 -0
- package/dist/db/migrations-pg/meta/0018_snapshot.json +3020 -0
- package/dist/db/migrations-pg/meta/0020_snapshot.json +3228 -0
- package/dist/db/migrations-pg/meta/0021_snapshot.json +3234 -0
- package/dist/db/migrations-pg/meta/0022_snapshot.json +3240 -0
- package/dist/db/migrations-pg/meta/_journal.json +475 -0
- package/dist/db/ml-labels.js +1666 -0
- package/dist/db/my-turn-dismissals.js +343 -0
- package/dist/db/my-turn-settings.js +34 -0
- package/dist/db/pending-classify.js +46 -0
- package/dist/db/pending-mute.js +171 -0
- package/dist/db/pending-tabs.js +238 -0
- package/dist/db/period-metrics.js +820 -0
- package/dist/db/person-period.js +763 -0
- package/dist/db/pr-intervals.js +930 -0
- package/dist/db/pr-liveness.js +240 -0
- package/dist/db/pr-mentions.js +279 -0
- package/dist/db/pr-merge-queue-stamp.js +91 -0
- package/dist/db/queries.js +14631 -0
- package/dist/db/reaction-targets.js +94 -0
- package/dist/db/repo-activity.js +171 -0
- package/dist/db/retention.js +138 -0
- package/dist/db/review-threads-for-review.js +240 -0
- package/dist/db/run-migrations.js +24 -0
- package/dist/db/schema.pg.js +1220 -0
- package/dist/db/schema.sqlite.js +1801 -0
- package/dist/db/search.js +317 -0
- package/dist/db/security-alerts.js +218 -0
- package/dist/db/synthesis-input.js +565 -0
- package/dist/db/triage.js +320 -0
- package/dist/db/usage.js +63 -0
- package/dist/db/work-plan.js +1086 -0
- package/dist/db/working-hours.js +161 -0
- package/dist/feed/my-turn.js +122 -0
- package/dist/github/actions-logs.js +397 -0
- package/dist/github/auth.js +86 -0
- package/dist/github/branch-queries.js +229 -0
- package/dist/github/client.js +454 -0
- package/dist/github/codeowners.js +221 -0
- package/dist/github/commit-checks.js +105 -0
- package/dist/github/compare.js +110 -0
- package/dist/github/diff-anchor.js +227 -0
- package/dist/github/mutations.js +706 -0
- package/dist/github/pr-file-content.js +254 -0
- package/dist/github/pr-liveness.js +161 -0
- package/dist/github/queries.js +875 -0
- package/dist/github/rate-budget.js +129 -0
- package/dist/github/reactions.js +161 -0
- package/dist/github/reviewer-suggest.js +104 -0
- package/dist/github/team-reviewers.js +96 -0
- package/dist/index.js +184 -0
- package/dist/merge/auto-merge-runner.js +960 -0
- package/dist/ml/severity-client.js +218 -0
- package/dist/pr/detail-enricher.js +26 -0
- package/dist/pro/bind.js +302 -0
- package/dist/pro/contract.js +37 -0
- package/dist/pro/migrate.js +64 -0
- package/dist/review/agent-context.js +127 -0
- package/dist/review/agent.js +385 -0
- package/dist/review/agentic.js +59 -0
- package/dist/review/auth.js +94 -0
- package/dist/review/chat-agent.js +179 -0
- package/dist/review/claude-review/ai-ready.js +16 -0
- package/dist/review/claude-review/auto-settings.js +139 -0
- package/dist/review/claude-review/auto.js +244 -0
- package/dist/review/claude-review/chat.js +489 -0
- package/dist/review/claude-review/ci-failures.js +350 -0
- package/dist/review/claude-review/follow-up.js +310 -0
- package/dist/review/claude-review/manager.js +686 -0
- package/dist/review/claude-review/persist.js +996 -0
- package/dist/review/claude-review/prompts.js +357 -0
- package/dist/review/claude-review/routes.js +518 -0
- package/dist/review/claude-review/routing.js +61 -0
- package/dist/review/claude-review/specialists.js +190 -0
- package/dist/review/claude-review/threads.js +265 -0
- package/dist/review/claude-review/ticket.js +282 -0
- package/dist/review/clone-hygiene.js +380 -0
- package/dist/review/clone-manager.js +367 -0
- package/dist/review/llm.js +113 -0
- package/dist/review/model-options.js +48 -0
- package/dist/review/plugin-providers.js +12 -0
- package/dist/review/post-review.js +216 -0
- package/dist/review/post-seam.js +161 -0
- package/dist/review/prepare.js +168 -0
- package/dist/review/pricing.js +17 -0
- package/dist/review/schema.js +156 -0
- package/dist/review/submit-map.js +41 -0
- package/dist/review/usage.js +90 -0
- package/dist/shared/claude-review.js +335 -0
- package/dist/shared/conflict-fold.js +151 -0
- package/dist/shared/conflicts.js +30 -0
- package/dist/shared/flow-settings.js +191 -0
- package/dist/shared/index.js +8 -0
- package/dist/shared/my-turn-settings.js +238 -0
- package/dist/shared/pending-rules.js +281 -0
- package/dist/shared/product.js +54 -0
- package/dist/shared/types.js +896 -0
- package/dist/status.js +386 -0
- package/dist/sync/adaptive.js +185 -0
- package/dist/sync/app-attribution.js +66 -0
- package/dist/sync/auth-notices.js +36 -0
- package/dist/sync/backfill-ci-history.js +315 -0
- package/dist/sync/backfill-commit-headlines.js +136 -0
- package/dist/sync/backfill-pr-security.js +175 -0
- package/dist/sync/backfill-review-requests.js +97 -0
- package/dist/sync/benchmark-rollup.js +50 -0
- package/dist/sync/bot-detection.js +309 -0
- package/dist/sync/bot-resolution-markers.js +30 -0
- package/dist/sync/branch-status.js +634 -0
- package/dist/sync/classify-change-shape.js +150 -0
- package/dist/sync/commit-files.js +74 -0
- package/dist/sync/derive-thread-state.js +99 -0
- package/dist/sync/drain-review-threads.js +212 -0
- package/dist/sync/hydrate-detail.js +482 -0
- package/dist/sync/mention-scan.js +89 -0
- package/dist/sync/ml-enrichment.js +478 -0
- package/dist/sync/pr-change-signal.js +96 -0
- package/dist/sync/pr-liveness-sweep.js +139 -0
- package/dist/sync/pr-settle.js +381 -0
- package/dist/sync/refresh-pr.js +163 -0
- package/dist/sync/reparse-vendor-badges.js +495 -0
- package/dist/sync/resync-after-write.js +280 -0
- package/dist/sync/review-fingerprint.js +117 -0
- package/dist/sync/reviewer-behavior.js +103 -0
- package/dist/sync/reviewer-classify.js +503 -0
- package/dist/sync/routing-files.js +97 -0
- package/dist/sync/scheduled-jobs.js +12 -0
- package/dist/sync/scheduler.js +159 -0
- package/dist/sync/security-detect.js +521 -0
- package/dist/sync/sync-manager.js +750 -0
- package/dist/sync/sync-one-pr.js +205 -0
- package/dist/sync/sync-repo.js +400 -0
- package/dist/sync/unsettled-prs.js +506 -0
- package/dist/sync/upsert.js +1190 -0
- package/package.json +56 -0
- package/public/apple-touch-icon.png +0 -0
- package/public/assets/AiFixTab-CQP6PT5u.js +2 -0
- package/public/assets/ClaudeReviewTab-DQJ-58ZA.js +8 -0
- package/public/assets/PrBotBehaviourTab-CCnFrWbC.js +1 -0
- package/public/assets/archivo-latin-600-BN-JkNrl.woff2 +0 -0
- package/public/assets/highlight-BEHUn5zE.css +10 -0
- package/public/assets/highlight-CIIZLa6Z.js +12 -0
- package/public/assets/index-BDnYs6zg.js +73 -0
- package/public/assets/index-mCuI--RC.css +1 -0
- package/public/assets/markdown-I_JLLVAZ.js +32 -0
- package/public/assets/perfProbe-Da13EhTE.js +1 -0
- package/public/assets/tanstack-5qsxxaLe.js +17 -0
- package/public/assets/vis-C3BCkP5U.js +1280 -0
- package/public/assets/vis-ziCVehMy.css +1 -0
- package/public/favicon-16.png +0 -0
- package/public/favicon-32.png +0 -0
- package/public/favicon-48.png +0 -0
- package/public/favicon.svg +5 -0
- package/public/index.html +41 -0
- package/public-landing/apple-touch-icon.png +0 -0
- package/public-landing/assets/archivo-latin-500-BWmvx2Mg.woff2 +0 -0
- package/public-landing/assets/archivo-latin-600-BN-JkNrl.woff2 +0 -0
- package/public-landing/assets/index-CA3eEGXO.js +40 -0
- package/public-landing/assets/index-naQrQ6Fe.css +1 -0
- package/public-landing/assets/jetbrains-mono-latin-400-RruCX7RW.woff2 +0 -0
- package/public-landing/assets/newsreader-latin-400-DExrRRrN.woff2 +0 -0
- package/public-landing/assets/newsreader-latin-400-italic-b0I-AwbV.woff2 +0 -0
- package/public-landing/bots/index.html +156 -0
- package/public-landing/contact/index.html +156 -0
- package/public-landing/cookies/index.html +156 -0
- package/public-landing/demo/limn-walkthrough-poster.jpg +0 -0
- package/public-landing/demo/limn-walkthrough.cues.json +44 -0
- package/public-landing/demo/limn-walkthrough.mp4 +0 -0
- package/public-landing/favicon-16.png +0 -0
- package/public-landing/favicon-32.png +0 -0
- package/public-landing/favicon-48.png +0 -0
- package/public-landing/favicon.svg +5 -0
- package/public-landing/features/index.html +156 -0
- package/public-landing/for-developers/index.html +156 -0
- package/public-landing/for-managers/index.html +156 -0
- package/public-landing/how-it-works/index.html +156 -0
- package/public-landing/how-we-measure/index.html +156 -0
- package/public-landing/icon-192.png +0 -0
- package/public-landing/icon-512.png +0 -0
- package/public-landing/index.html +156 -0
- package/public-landing/insights/index.html +156 -0
- package/public-landing/og-image.png +0 -0
- package/public-landing/pricing/index.html +156 -0
- package/public-landing/privacy/index.html +156 -0
- package/public-landing/pro/index.html +156 -0
- package/public-landing/reviews/index.html +156 -0
- package/public-landing/robots.txt +8 -0
- package/public-landing/shots/benchmark.png +0 -0
- package/public-landing/shots/bot-roi.png +0 -0
- package/public-landing/shots/bot-settings.png +0 -0
- package/public-landing/shots/chronology.png +0 -0
- package/public-landing/shots/feed.png +0 -0
- package/public-landing/shots/flow-metrics.png +0 -0
- package/public-landing/shots/free-reports.png +0 -0
- package/public-landing/shots/pending-board.png +0 -0
- package/public-landing/shots/pending-card.png +0 -0
- package/public-landing/shots/period-report.png +0 -0
- package/public-landing/shots/pr-detail.png +0 -0
- package/public-landing/shots/pr-threads.png +0 -0
- package/public-landing/shots/reach.png +0 -0
- package/public-landing/shots/repo-rows.png +0 -0
- package/public-landing/shots/severity-findings.png +0 -0
- package/public-landing/shots/severity-strip.png +0 -0
- package/public-landing/site.webmanifest +14 -0
- package/public-landing/sitemap.xml +51 -0
- package/public-landing/terms/index.html +156 -0
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
// Targeted single-PR sync — the shared core of Phase 0 real-time sync
|
|
2
|
+
// (see docs/REALTIME-SYNC.md).
|
|
3
|
+
//
|
|
4
|
+
// Instead of re-walking a repo's whole `since` window on a clock, `syncOnePr` fetches
|
|
5
|
+
// exactly ONE PR by number and runs it through the same idempotent persist path as the
|
|
6
|
+
// page walk (`persistPr`), so a webhook (cloud) or the adaptive scheduler (local) can
|
|
7
|
+
// refresh only what changed. Costs ~1 GraphQL point vs a multi-page walk.
|
|
8
|
+
//
|
|
9
|
+
// `enqueuePrSync` sits in front of it: a burst of change signals for the same PR — a push
|
|
10
|
+
// emits push + synchronize + check_run within seconds — coalesces into ONE syncOnePr
|
|
11
|
+
// fired after the burst settles (config.webhookDebounceMs). Nothing calls these yet;
|
|
12
|
+
// Phase 1 (webhooks) and Phase 2 (adaptive polling) wire them in.
|
|
13
|
+
import { eq } from 'drizzle-orm';
|
|
14
|
+
import { db, schema } from '../db/client.js';
|
|
15
|
+
import { config } from '../config.js';
|
|
16
|
+
import { getAccessToken } from '../auth/account.js';
|
|
17
|
+
import { getGraphqlClientFor, graphqlChecksHint, graphqlTolerant, isSamlBlock, summarizeGraphqlErrors, } from '../github/client.js';
|
|
18
|
+
import { PR_ACTIVITY_ONE_QUERY, } from '../github/queries.js';
|
|
19
|
+
import { clearSamlBlock, recordSamlBlock } from './auth-notices.js';
|
|
20
|
+
import { ensureCommitFiles } from './commit-files.js';
|
|
21
|
+
import { drainReviewThreads } from './drain-review-threads.js';
|
|
22
|
+
import { createUserResolver, persistPr } from './upsert.js';
|
|
23
|
+
const { repos } = schema;
|
|
24
|
+
const errMsg = (err) => err instanceof Error ? err.message : String(err);
|
|
25
|
+
// One in-flight targeted sync per (repoId, prNumber). Mirrors sync-manager's `running`
|
|
26
|
+
// set: reserved synchronously before any await so a concurrent trigger stands down.
|
|
27
|
+
// It holds the in-flight PROMISE (not just the key) so a caller that cannot accept the
|
|
28
|
+
// stand-down — see `waitForInFlight` on syncOnePr — can queue behind it.
|
|
29
|
+
const running = new Map();
|
|
30
|
+
const keyOf = (repoId, prNumber) => `${repoId}:${prNumber}`;
|
|
31
|
+
// How many times a `waitForInFlight` caller will queue behind someone else's run before
|
|
32
|
+
// giving up. Bounded so a stream of writers on one hot PR can't spin here indefinitely.
|
|
33
|
+
const MAX_SERIALIZE_ATTEMPTS = 3;
|
|
34
|
+
/**
|
|
35
|
+
* Is a targeted sync in flight for this PR right now? Read-only. The refresh route
|
|
36
|
+
* (sync/refresh-pr.ts) samples this BEFORE a no-wait syncOnePr so it can report a
|
|
37
|
+
* stand-down as "a sync is running" rather than as a failure — the poll's answer is
|
|
38
|
+
* whatever freshness that run produces, not an error.
|
|
39
|
+
*/
|
|
40
|
+
export function isPrSyncInFlight(repoId, prNumber) {
|
|
41
|
+
return running.has(keyOf(repoId, prNumber));
|
|
42
|
+
}
|
|
43
|
+
// Resolve a repo's coordinates + owning account from its local id. The id already
|
|
44
|
+
// encodes the account (repos PK), so the caller passes only repoId and isolation is
|
|
45
|
+
// structural — the token + every persisted row use THIS row's accountId.
|
|
46
|
+
async function getRepoTarget(repoId) {
|
|
47
|
+
const rows = await db
|
|
48
|
+
.select({ owner: repos.owner, name: repos.name, accountId: repos.accountId })
|
|
49
|
+
.from(repos)
|
|
50
|
+
.where(eq(repos.id, repoId))
|
|
51
|
+
.limit(1)
|
|
52
|
+
.execute();
|
|
53
|
+
return rows[0] ?? null;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Sync a single PR by number into the DB, reusing the idempotent persist path. Returns
|
|
57
|
+
* true when the PR was fetched + persisted, false on any no-op (already in flight, repo
|
|
58
|
+
* or PR gone, no token). Never throws — failures are logged and swallowed so a bad
|
|
59
|
+
* webhook/poll can't crash the caller; the periodic backstop sync reconciles anything
|
|
60
|
+
* missed.
|
|
61
|
+
*
|
|
62
|
+
* `waitForInFlight` (used by the post-write resync — see sync/resync-after-write.ts):
|
|
63
|
+
* a caller that just WROTE to this PR cannot accept the stand-down, because the run
|
|
64
|
+
* already in flight may have read GitHub BEFORE that write, so its success proves
|
|
65
|
+
* nothing about the new row. With the flag set the caller queues behind the running
|
|
66
|
+
* sync and then does its OWN fetch.
|
|
67
|
+
*/
|
|
68
|
+
export async function syncOnePr(repoId, prNumber, log, opts) {
|
|
69
|
+
const key = keyOf(repoId, prNumber);
|
|
70
|
+
for (let attempt = 0; attempt < MAX_SERIALIZE_ATTEMPTS; attempt++) {
|
|
71
|
+
const inFlight = running.get(key);
|
|
72
|
+
if (!inFlight) {
|
|
73
|
+
// Reserved synchronously on this path (nothing is awaited above it), so a
|
|
74
|
+
// concurrent enqueue/caller still sees the slot taken, exactly as before. The
|
|
75
|
+
// `.finally` is attached AT CREATION, so it has already released the slot by the
|
|
76
|
+
// time any `await inFlight` below resumes — a waiter can never see a stale slot.
|
|
77
|
+
const run = runOnePrSync(repoId, prNumber, log).finally(() => {
|
|
78
|
+
running.delete(key);
|
|
79
|
+
});
|
|
80
|
+
running.set(key, run);
|
|
81
|
+
return run;
|
|
82
|
+
}
|
|
83
|
+
if (!opts?.waitForInFlight)
|
|
84
|
+
return false;
|
|
85
|
+
// runOnePrSync never rejects, so this needs no catch.
|
|
86
|
+
await inFlight;
|
|
87
|
+
}
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
// The actual fetch + persist. Split out from `syncOnePr` so the in-flight bookkeeping
|
|
91
|
+
// (which now has to hand the promise to waiters) lives in exactly one place. Keeps its
|
|
92
|
+
// own try/catch, so it NEVER rejects.
|
|
93
|
+
async function runOnePrSync(repoId, prNumber, log) {
|
|
94
|
+
try {
|
|
95
|
+
const target = await getRepoTarget(repoId);
|
|
96
|
+
if (!target) {
|
|
97
|
+
log.warn(`syncOnePr: repo ${repoId} not found (deleted?) — skipping #${prNumber}`);
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
const { owner, name, accountId } = target;
|
|
101
|
+
let token;
|
|
102
|
+
try {
|
|
103
|
+
token = await getAccessToken(accountId);
|
|
104
|
+
}
|
|
105
|
+
catch (err) {
|
|
106
|
+
log.error(`syncOnePr ${owner}/${name}#${prNumber}: no access token for account ${accountId}: ${errMsg(err)}`);
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
const client = getGraphqlClientFor(token);
|
|
110
|
+
let samlBlocked = false;
|
|
111
|
+
const resp = await graphqlTolerant(client, PR_ACTIVITY_ONE_QUERY, { owner, name, number: prNumber }, (errors) => {
|
|
112
|
+
if (isSamlBlock(errors))
|
|
113
|
+
samlBlocked = true;
|
|
114
|
+
log.warn(`syncOnePr ${owner}/${name}#${prNumber}: partial GraphQL — continuing without forbidden fields${graphqlChecksHint(errors)}. ${summarizeGraphqlErrors(errors)}`);
|
|
115
|
+
});
|
|
116
|
+
const pr = resp.repository?.pullRequest ?? null;
|
|
117
|
+
if (!pr) {
|
|
118
|
+
// A SAML wall forbids the whole `repository` node → flag the owner's org for the
|
|
119
|
+
// "Reconnect GitHub" banner (mirrors sync-repo). Otherwise the PR is simply gone /
|
|
120
|
+
// inaccessible (deleted, wrong number, lost access) — nothing to persist.
|
|
121
|
+
if (samlBlocked)
|
|
122
|
+
recordSamlBlock(accountId, owner);
|
|
123
|
+
log.warn(`syncOnePr ${owner}/${name}#${prNumber}: no PR data returned — skipping`);
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
// Read cleanly → the token IS authorized for this owner's org; self-dismiss any
|
|
127
|
+
// prior SAML flag (guarded so a partial SAML error can't erroneously clear it).
|
|
128
|
+
if (!samlBlocked)
|
|
129
|
+
clearSamlBlock(accountId, owner);
|
|
130
|
+
// Drain the review-thread tail before anything reads the list — same ordering rule as
|
|
131
|
+
// the per-repo walk: the SHA cutoff below is derived from the unresolved threads, and
|
|
132
|
+
// persistPr must see ONE complete list. Costs nothing unless this PR overflows one page.
|
|
133
|
+
await drainReviewThreads(pr.reviewThreads, {
|
|
134
|
+
owner,
|
|
135
|
+
name,
|
|
136
|
+
number: prNumber,
|
|
137
|
+
accountId,
|
|
138
|
+
token,
|
|
139
|
+
log,
|
|
140
|
+
});
|
|
141
|
+
// Gather the commit SHAs whose changed files the thread-state heuristic needs —
|
|
142
|
+
// commits that landed AFTER an unresolved thread's last comment (identical to the
|
|
143
|
+
// per-PR logic in sync-repo). persistPr only reads the SHAs its own commits need.
|
|
144
|
+
const shas = [];
|
|
145
|
+
const unresolved = pr.reviewThreads.nodes.filter((t) => !t.isResolved && t.comments.nodes.length > 0);
|
|
146
|
+
if (unresolved.length > 0) {
|
|
147
|
+
const threshold = Math.min(...unresolved.map((t) => Date.parse(t.comments.nodes.at(-1).createdAt)));
|
|
148
|
+
for (const c of pr.commits.nodes) {
|
|
149
|
+
if (Date.parse(c.commit.committedDate) > threshold)
|
|
150
|
+
shas.push(c.commit.oid);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
const commitFilesBySha = await ensureCommitFiles(owner, name, shas, token, config.commitFileConcurrency);
|
|
154
|
+
const resolver = createUserResolver();
|
|
155
|
+
await persistPr(pr, repoId, resolver, commitFilesBySha, accountId);
|
|
156
|
+
log.info(`syncOnePr ${owner}/${name}#${prNumber} done (cost ${resp.rateLimit?.cost ?? 0}, ${resp.rateLimit?.remaining ?? '?'} remaining)`);
|
|
157
|
+
return true;
|
|
158
|
+
}
|
|
159
|
+
catch (err) {
|
|
160
|
+
log.error(`syncOnePr repo ${repoId} #${prNumber} failed: ${errMsg(err)}`);
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
// Pending debounce timers, one per (repoId, prNumber). A fresh signal for a key resets
|
|
165
|
+
// its timer, so a burst collapses to a single trailing run.
|
|
166
|
+
const pending = new Map();
|
|
167
|
+
/**
|
|
168
|
+
* Debounced, coalescing trigger for a targeted sync. Multiple calls for the same PR
|
|
169
|
+
* within `config.webhookDebounceMs` collapse into ONE `syncOnePr` fired after the burst
|
|
170
|
+
* settles. If a sync is already in flight for the PR when the timer fires, it re-arms
|
|
171
|
+
* (rather than dropping the just-arrived change) so the newer state is still picked up.
|
|
172
|
+
* Fire-and-forget: `syncOnePr` swallows its own errors.
|
|
173
|
+
*/
|
|
174
|
+
export function enqueuePrSync(repoId, prNumber, log) {
|
|
175
|
+
const key = keyOf(repoId, prNumber);
|
|
176
|
+
const arm = () => {
|
|
177
|
+
const existing = pending.get(key);
|
|
178
|
+
if (existing)
|
|
179
|
+
clearTimeout(existing);
|
|
180
|
+
const timer = setTimeout(() => {
|
|
181
|
+
pending.delete(key);
|
|
182
|
+
// A sync is mid-flight for this PR — re-arm so the change that arrived during it
|
|
183
|
+
// isn't lost, instead of firing a syncOnePr that would just no-op on the guard.
|
|
184
|
+
if (running.has(key)) {
|
|
185
|
+
arm();
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
void syncOnePr(repoId, prNumber, log);
|
|
189
|
+
}, config.webhookDebounceMs);
|
|
190
|
+
// Don't keep the process alive solely for a pending targeted sync (e.g. at shutdown).
|
|
191
|
+
// Guarded because faked/mocked timers may not expose unref.
|
|
192
|
+
if (typeof timer.unref === 'function')
|
|
193
|
+
timer.unref();
|
|
194
|
+
pending.set(key, timer);
|
|
195
|
+
};
|
|
196
|
+
arm();
|
|
197
|
+
}
|
|
198
|
+
// Test-only: reset the module's in-memory state between cases.
|
|
199
|
+
export function __resetTargetedSyncState() {
|
|
200
|
+
for (const timer of pending.values())
|
|
201
|
+
clearTimeout(timer);
|
|
202
|
+
pending.clear();
|
|
203
|
+
running.clear();
|
|
204
|
+
}
|
|
205
|
+
//# sourceMappingURL=sync-one-pr.js.map
|
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
import { performance } from 'node:perf_hooks';
|
|
2
|
+
import { db, schema } from '../db/client.js';
|
|
3
|
+
import { getGraphqlClientFor, graphqlChecksHint, graphqlTolerant, isRateLimitError, isSamlBlock, summarizeGraphqlErrors, withGithubRetry, } from '../github/client.js';
|
|
4
|
+
import { gateBudget, noteBudget, noteLimited } from '../github/rate-budget.js';
|
|
5
|
+
import { clearSamlBlock, recordSamlBlock } from './auth-notices.js';
|
|
6
|
+
import { REPO_ACTIVITY_QUERY } from '../github/queries.js';
|
|
7
|
+
import { ensureCommitFiles } from './commit-files.js';
|
|
8
|
+
import { drainReviewThreads } from './drain-review-threads.js';
|
|
9
|
+
import { syncBranchStatus } from './branch-status.js';
|
|
10
|
+
import { createUserResolver, persistPr, upsertRepo } from './upsert.js';
|
|
11
|
+
const { syncState } = schema;
|
|
12
|
+
const consoleLogger = {
|
|
13
|
+
info: (m, ...a) => console.log(m, ...a),
|
|
14
|
+
warn: (m, ...a) => console.warn(m, ...a),
|
|
15
|
+
error: (m, ...a) => console.error(m, ...a),
|
|
16
|
+
};
|
|
17
|
+
function clamp01(n) {
|
|
18
|
+
return n < 0 ? 0 : n > 1 ? 1 : n;
|
|
19
|
+
}
|
|
20
|
+
// How many consecutive rate-limit waits ONE page may absorb before the error is allowed
|
|
21
|
+
// through to the real failure path. Each wait already sleeps until the reported window
|
|
22
|
+
// reset, so hitting this cap means GitHub kept refusing across ~5 windows — genuinely
|
|
23
|
+
// unrecoverable, not a budget blip.
|
|
24
|
+
const MAX_RATE_LIMIT_WAITS_PER_PAGE = 5;
|
|
25
|
+
export async function syncRepo(opts) {
|
|
26
|
+
const { owner, name, accountId, mode, since, onProgress } = opts;
|
|
27
|
+
const commitState = opts.commitState ?? true;
|
|
28
|
+
const log = opts.log ?? consoleLogger;
|
|
29
|
+
const client = getGraphqlClientFor(opts.token);
|
|
30
|
+
const resolver = createUserResolver();
|
|
31
|
+
// Set if any page's fetch is SAML-forbidden (token not authorized for the owner's org) — the
|
|
32
|
+
// owner org is then flagged for the "Reconnect GitHub" banner (see sync/auth-notices.ts).
|
|
33
|
+
let samlBlocked = false;
|
|
34
|
+
let cursor = opts.startCursor ?? null;
|
|
35
|
+
// The `after` value used to fetch the page currently being processed. When we
|
|
36
|
+
// stop at the `since` cutoff mid-page, this (not the page's endCursor) is what a
|
|
37
|
+
// follow-on phase resumes from, so the cutoff page's older PRs aren't skipped.
|
|
38
|
+
let pageStartCursor = cursor;
|
|
39
|
+
let repoId = null;
|
|
40
|
+
let prCount = 0;
|
|
41
|
+
let pages = 0;
|
|
42
|
+
let totalCost = 0;
|
|
43
|
+
let lastRemaining = 0;
|
|
44
|
+
// Per-stage wall-clock accumulators, so the final log attributes the 2-3 min:
|
|
45
|
+
// page fetch (network/GraphQL) vs commit-file REST fan-out vs DB persist. This
|
|
46
|
+
// is the baseline that tells us which stage to optimise next.
|
|
47
|
+
let graphqlMs = 0;
|
|
48
|
+
let commitFilesMs = 0;
|
|
49
|
+
let persistMs = 0;
|
|
50
|
+
const timingSummary = () => `graphql ${(graphqlMs / 1000).toFixed(1)}s / commit-files ` +
|
|
51
|
+
`${(commitFilesMs / 1000).toFixed(1)}s / persist ${(persistMs / 1000).toFixed(1)}s`;
|
|
52
|
+
// Time-walked progress: PRs arrive newest-first and we stop at `since`, so the
|
|
53
|
+
// span [since .. newest] is the work and the current PR's updatedAt marks how
|
|
54
|
+
// far through it we are.
|
|
55
|
+
let newestMs = null;
|
|
56
|
+
const sinceMs = since?.getTime() ?? null;
|
|
57
|
+
// The last reported percent, so a pause/resume update can re-emit the bar exactly where
|
|
58
|
+
// it stands rather than snapping it to a recomputed value mid-wait.
|
|
59
|
+
let lastPercent = 0;
|
|
60
|
+
const reportProgress = (currentMs) => {
|
|
61
|
+
if (!onProgress)
|
|
62
|
+
return;
|
|
63
|
+
let percent = 0;
|
|
64
|
+
if (newestMs != null && sinceMs != null && newestMs > sinceMs && currentMs != null) {
|
|
65
|
+
percent = clamp01((newestMs - currentMs) / (newestMs - sinceMs));
|
|
66
|
+
}
|
|
67
|
+
lastPercent = percent;
|
|
68
|
+
onProgress({ percent, prsProcessed: prCount, pages });
|
|
69
|
+
};
|
|
70
|
+
// Wait out the account's rate budget, if any (github/rate-budget.ts). The paused flag
|
|
71
|
+
// rides the normal onProgress plumbing, so the UI shows a 'running' sync that is
|
|
72
|
+
// honestly holding still — never the red error path — and is cleared by a plain update
|
|
73
|
+
// the moment the walk moves again. Returns false when a user cancel arrived mid-wait;
|
|
74
|
+
// the caller then bails exactly like any cancelled page.
|
|
75
|
+
const pauseForBudget = async () => {
|
|
76
|
+
let paused = false;
|
|
77
|
+
const gate = await gateBudget(accountId, {
|
|
78
|
+
shouldCancel: opts.shouldCancel,
|
|
79
|
+
onWait: (resumeAt) => {
|
|
80
|
+
paused = true;
|
|
81
|
+
log.info(`sync ${owner}/${name}: pausing for GitHub rate limit — resuming ~${resumeAt.toISOString()}`);
|
|
82
|
+
onProgress?.({
|
|
83
|
+
percent: lastPercent,
|
|
84
|
+
prsProcessed: prCount,
|
|
85
|
+
pages,
|
|
86
|
+
paused: { reason: 'rate_limit', resumeAt: resumeAt.toISOString() },
|
|
87
|
+
});
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
if (gate === 'cancelled')
|
|
91
|
+
return false;
|
|
92
|
+
if (paused)
|
|
93
|
+
onProgress?.({ percent: lastPercent, prsProcessed: prCount, pages });
|
|
94
|
+
return true;
|
|
95
|
+
};
|
|
96
|
+
try {
|
|
97
|
+
let stop = false;
|
|
98
|
+
let cancelled = false;
|
|
99
|
+
do {
|
|
100
|
+
if (opts.shouldCancel?.()) {
|
|
101
|
+
cancelled = true;
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
// PRE-EMPTIVE budget gate: when the account's remaining rate budget is under the
|
|
105
|
+
// floor (fed from every page's rateLimit block below) or a hard limit was observed
|
|
106
|
+
// anywhere on this token, wait out the window HERE — paused, cancellable — instead
|
|
107
|
+
// of spending the page and slamming into the 403.
|
|
108
|
+
if (!(await pauseForBudget())) {
|
|
109
|
+
cancelled = true;
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
pageStartCursor = cursor;
|
|
113
|
+
// Tolerate partial errors so a forbidden sub-field (e.g. `statusCheckRollup` check runs on
|
|
114
|
+
// a private repo the token can't reach, or a token minted before its scope covered checks)
|
|
115
|
+
// doesn't abort the whole sync — the PRs, reviews, comments and review REQUESTS still
|
|
116
|
+
// persist; only CI check detail is dropped (the `ciStatus` rollup, when readable, is kept).
|
|
117
|
+
// Retry the page fetch on a TRANSIENT GitHub fault (a 502/timeout from the edge —
|
|
118
|
+
// the fat query on a big repo routinely 502s) so one hiccup can't abort the whole
|
|
119
|
+
// multi-page backfill. Partial-data (forbidden sub-field) responses are handled
|
|
120
|
+
// inside graphqlTolerant and are NOT retried.
|
|
121
|
+
// Whether THIS page's response was a tolerant-salvaged partial. Load-bearing for the
|
|
122
|
+
// description write below: GraphQL nulls an ERRORED field in partial data (the key is
|
|
123
|
+
// present, not absent), so inside a partial response `description: null` is
|
|
124
|
+
// indistinguishable from GitHub positively saying "no description" — and the
|
|
125
|
+
// clear-only-on-a-positive-statement rule then forbids treating it as a clear.
|
|
126
|
+
let pagePartial = false;
|
|
127
|
+
// A rate-limited page is NOT a failure: note the limit, wait it out (paused,
|
|
128
|
+
// cancellable), and RE-FETCH THE SAME PAGE — `cursor` is untouched, and the
|
|
129
|
+
// pageStartCursor/endCursor resume contract already supports an exact re-fetch.
|
|
130
|
+
// Capped so a token GitHub keeps refusing eventually reaches the real error path.
|
|
131
|
+
// The retry wraps OUTSIDE withGithubRetry/graphqlTolerant, so partial-data semantics
|
|
132
|
+
// (onPartial fires only on a salvaged response) are untouched.
|
|
133
|
+
let resp = null;
|
|
134
|
+
let rateLimitWaits = 0;
|
|
135
|
+
while (resp == null) {
|
|
136
|
+
pagePartial = false;
|
|
137
|
+
const tPage = performance.now();
|
|
138
|
+
try {
|
|
139
|
+
resp = await withGithubRetry(() => graphqlTolerant(client, REPO_ACTIVITY_QUERY, { owner, name, cursor }, (errors) => {
|
|
140
|
+
pagePartial = true;
|
|
141
|
+
if (isSamlBlock(errors))
|
|
142
|
+
samlBlocked = true;
|
|
143
|
+
log.warn(`sync ${owner}/${name}: partial GraphQL — continuing without forbidden fields${graphqlChecksHint(errors)}. ${summarizeGraphqlErrors(errors)}`);
|
|
144
|
+
}), {
|
|
145
|
+
onRetry: (attempt, delayMs, err) => log.warn(`sync ${owner}/${name}: transient GitHub error on page ${pages + 1} ` +
|
|
146
|
+
`(attempt ${attempt}, retrying in ${delayMs}ms): ` +
|
|
147
|
+
`${err instanceof Error ? err.message.slice(0, 200) : String(err)}`),
|
|
148
|
+
});
|
|
149
|
+
graphqlMs += performance.now() - tPage;
|
|
150
|
+
}
|
|
151
|
+
catch (err) {
|
|
152
|
+
graphqlMs += performance.now() - tPage;
|
|
153
|
+
const rl = isRateLimitError(err);
|
|
154
|
+
if (!rl.limited || rateLimitWaits >= MAX_RATE_LIMIT_WAITS_PER_PAGE)
|
|
155
|
+
throw err;
|
|
156
|
+
rateLimitWaits += 1;
|
|
157
|
+
noteLimited(accountId, rl.resumeAt);
|
|
158
|
+
log.warn(`sync ${owner}/${name}: GitHub rate limit on page ${pages + 1} — waiting it ` +
|
|
159
|
+
`out (${rateLimitWaits}/${MAX_RATE_LIMIT_WAITS_PER_PAGE}), then retrying the same page`);
|
|
160
|
+
if (!(await pauseForBudget())) {
|
|
161
|
+
cancelled = true;
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
// Only reachable via a cancel during a rate-limit wait — bail like any cancel.
|
|
167
|
+
if (resp == null)
|
|
168
|
+
break;
|
|
169
|
+
pages += 1;
|
|
170
|
+
// `rateLimit` is a top-level sibling of `repository`, so it survives a partial
|
|
171
|
+
// (forbidden-subfield) response — but guard it so a genuinely rateLimit-less partial
|
|
172
|
+
// (e.g. a NOT_FOUND payload salvaged by graphqlTolerant) can't NPE before the
|
|
173
|
+
// `!resp.repository` 404 below gets to fire.
|
|
174
|
+
totalCost += resp.rateLimit?.cost ?? 0;
|
|
175
|
+
lastRemaining = resp.rateLimit?.remaining ?? lastRemaining;
|
|
176
|
+
// Feed the per-account budget so the NEXT page — and any sibling walk sharing this
|
|
177
|
+
// token — can pause pre-emptively instead of running into the hard 403.
|
|
178
|
+
if (resp.rateLimit) {
|
|
179
|
+
noteBudget(accountId, {
|
|
180
|
+
remaining: resp.rateLimit.remaining ?? null,
|
|
181
|
+
resetAt: resp.rateLimit.resetAt ? new Date(resp.rateLimit.resetAt) : null,
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
if (!resp.repository) {
|
|
185
|
+
// A SAML wall forbids the whole `repository` node → flag the owner's org for the
|
|
186
|
+
// "Reconnect GitHub" banner (an authorization gap the user can self-fix), then fail
|
|
187
|
+
// this repo's sync as usual.
|
|
188
|
+
if (samlBlocked)
|
|
189
|
+
recordSamlBlock(accountId, owner);
|
|
190
|
+
// ⚠ THIS BAIL MUST STAY ABOVE THE upsertRepo BELOW. GitHub declining to resolve the
|
|
191
|
+
// repository is the only moment we can refuse to MINT a repos row for a name that
|
|
192
|
+
// does not resolve — and a row that exists is a row the scheduler walks forever.
|
|
193
|
+
// (An existing row is left ALONE, never deleted: a null `repository` is equally what
|
|
194
|
+
// a revoked token, a rename and a SAML wall look like, and auto-deleting would
|
|
195
|
+
// destroy real synced history on a transient permission change. The failure is
|
|
196
|
+
// surfaced instead — see `knownRepoId` and the catch at the bottom.)
|
|
197
|
+
const err = new Error(`Repository ${owner}/${name} not found or inaccessible`);
|
|
198
|
+
err.statusCode = 404;
|
|
199
|
+
throw err;
|
|
200
|
+
}
|
|
201
|
+
// Repository read cleanly (no SAML error anywhere in this response) → the token IS
|
|
202
|
+
// authorized for this owner's org; clear any prior flag so the "Reconnect" banner
|
|
203
|
+
// self-dismisses on recovery. Guard on !samlBlocked so a partial SAML error can't
|
|
204
|
+
// erroneously self-dismiss. Idempotent per page.
|
|
205
|
+
if (!samlBlocked)
|
|
206
|
+
clearSamlBlock(accountId, owner);
|
|
207
|
+
if (repoId == null) {
|
|
208
|
+
repoId = await upsertRepo(owner, name, resp.repository.id, resp.repository.defaultBranchRef?.name ?? null, accountId, resp.repository.viewerPermission ?? null,
|
|
209
|
+
// Passed RAW (no `?? null`): `undefined` = not received → upsertRepo preserves the
|
|
210
|
+
// stored description; `null` = GitHub positively says none → clears. A PARTIAL
|
|
211
|
+
// response can never make that positive statement (an errored field arrives as
|
|
212
|
+
// null with the key present), so it degrades to undefined — a stale description
|
|
213
|
+
// beats silently clearing a real one on every tick of a partially-forbidden token.
|
|
214
|
+
pagePartial ? undefined : resp.repository.description);
|
|
215
|
+
}
|
|
216
|
+
const { nodes, pageInfo } = resp.repository.pullRequests;
|
|
217
|
+
// First select the in-window PRs on this page and gather every commit SHA
|
|
218
|
+
// whose changed files we need (commits that could plausibly have addressed
|
|
219
|
+
// an open thread, i.e. landed after its last comment).
|
|
220
|
+
const pagePrs = [];
|
|
221
|
+
const pageShas = [];
|
|
222
|
+
for (const pr of nodes) {
|
|
223
|
+
if (opts.shouldCancel?.()) {
|
|
224
|
+
cancelled = true;
|
|
225
|
+
break;
|
|
226
|
+
}
|
|
227
|
+
const updatedMs = new Date(pr.updatedAt).getTime();
|
|
228
|
+
if (since && updatedMs < since.getTime()) {
|
|
229
|
+
stop = true;
|
|
230
|
+
break;
|
|
231
|
+
}
|
|
232
|
+
newestMs ??= updatedMs;
|
|
233
|
+
// Drain the review-thread tail BEFORE anything reads the list. Ordering is
|
|
234
|
+
// load-bearing twice over: the SHA gather below derives its cutoff from the
|
|
235
|
+
// unresolved threads, so a tail that arrived late would have its commits skipped for
|
|
236
|
+
// the addressed-state heuristic; and persistPr must receive ONE complete list (see
|
|
237
|
+
// drain-review-threads.ts). No request at all unless GitHub said this PR overflows,
|
|
238
|
+
// which is the overwhelming majority of PRs — the walk's cost is unchanged for them.
|
|
239
|
+
const tDrain = performance.now();
|
|
240
|
+
const drained = await drainReviewThreads(pr.reviewThreads, {
|
|
241
|
+
owner,
|
|
242
|
+
name,
|
|
243
|
+
number: pr.number,
|
|
244
|
+
accountId,
|
|
245
|
+
token: opts.token,
|
|
246
|
+
log,
|
|
247
|
+
shouldCancel: opts.shouldCancel,
|
|
248
|
+
});
|
|
249
|
+
graphqlMs += performance.now() - tDrain;
|
|
250
|
+
totalCost += drained.pages;
|
|
251
|
+
const unresolved = pr.reviewThreads.nodes.filter((t) => !t.isResolved && t.comments.nodes.length > 0);
|
|
252
|
+
if (unresolved.length > 0) {
|
|
253
|
+
const threshold = Math.min(...unresolved.map((t) => Date.parse(t.comments.nodes.at(-1).createdAt)));
|
|
254
|
+
for (const c of pr.commits.nodes) {
|
|
255
|
+
if (Date.parse(c.commit.committedDate) > threshold)
|
|
256
|
+
pageShas.push(c.commit.oid);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
pagePrs.push({ pr, updatedMs });
|
|
260
|
+
}
|
|
261
|
+
// Fetch the whole page's commit files in one saturated pool (replacing the
|
|
262
|
+
// old per-PR serial waves), then persist each in-window PR. persistPr only
|
|
263
|
+
// reads the SHAs its own commits need, so a page-wide superset map is fine.
|
|
264
|
+
// Skip entirely if a cancel arrived mid-gather — don't do network/DB work
|
|
265
|
+
// we're about to throw away.
|
|
266
|
+
if (!cancelled && pagePrs.length > 0) {
|
|
267
|
+
const tFiles = performance.now();
|
|
268
|
+
const commitFilesBySha = await ensureCommitFiles(owner, name, pageShas, opts.token, opts.commitFileConcurrency,
|
|
269
|
+
// So a rate-limited fan-out can note the account's budget (the next page's gate
|
|
270
|
+
// then pauses) instead of burning the remaining quota on doomed fetches.
|
|
271
|
+
accountId);
|
|
272
|
+
commitFilesMs += performance.now() - tFiles;
|
|
273
|
+
for (const { pr, updatedMs } of pagePrs) {
|
|
274
|
+
if (opts.shouldCancel?.()) {
|
|
275
|
+
cancelled = true;
|
|
276
|
+
break;
|
|
277
|
+
}
|
|
278
|
+
const tPersist = performance.now();
|
|
279
|
+
await persistPr(pr, repoId, resolver, commitFilesBySha, accountId);
|
|
280
|
+
persistMs += performance.now() - tPersist;
|
|
281
|
+
prCount += 1;
|
|
282
|
+
reportProgress(updatedMs);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
cursor = pageInfo.endCursor;
|
|
286
|
+
if (cancelled || stop || !pageInfo.hasNextPage)
|
|
287
|
+
break;
|
|
288
|
+
} while (cursor);
|
|
289
|
+
// Cancelled mid-walk: return WITHOUT writing a syncState timestamp, so the
|
|
290
|
+
// repo stays "never synced" (an initial backfill) and the cancel endpoint can
|
|
291
|
+
// safely delete it. Already-persisted PRs are harmless (idempotent) and get
|
|
292
|
+
// cleaned up with the repo, or resumed on the next sync for an existing repo.
|
|
293
|
+
if (cancelled) {
|
|
294
|
+
log.info(`sync ${owner}/${name} cancelled after ${prCount} PRs / ${pages} page(s) — timing: ${timingSummary()}`);
|
|
295
|
+
return {
|
|
296
|
+
repoId: repoId ?? -1,
|
|
297
|
+
prCount,
|
|
298
|
+
pages,
|
|
299
|
+
rateLimitRemaining: lastRemaining,
|
|
300
|
+
rateLimitCost: totalCost,
|
|
301
|
+
cancelled: true,
|
|
302
|
+
endCursor: pageStartCursor,
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
// Reached the cutoff / last page — the walk is complete.
|
|
306
|
+
reportProgress(sinceMs);
|
|
307
|
+
if (repoId === null) {
|
|
308
|
+
throw new Error(`Repository ${owner}/${name} returned no data`);
|
|
309
|
+
}
|
|
310
|
+
// Default-branch snapshot ("is trunk green?") — one extra ~1-point GraphQL round trip per
|
|
311
|
+
// repo per sync. STRICTLY NON-FATAL: it is an informational readout, and a token that can
|
|
312
|
+
// walk the PRs but chokes on the branch history (or a repo with no default branch at all)
|
|
313
|
+
// must never cost the caller the PR sync that just succeeded. It runs on the two-phase
|
|
314
|
+
// foreground pass as well as the deep one — the repeat is idempotent, and a freshly added
|
|
315
|
+
// repo showing trunk status within seconds is worth the duplicate point.
|
|
316
|
+
try {
|
|
317
|
+
await syncBranchStatus({
|
|
318
|
+
owner,
|
|
319
|
+
name,
|
|
320
|
+
repoId,
|
|
321
|
+
accountId,
|
|
322
|
+
token: opts.token,
|
|
323
|
+
log,
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
catch (err) {
|
|
327
|
+
log.warn(`sync ${owner}/${name}: default-branch status failed (non-fatal): ` +
|
|
328
|
+
`${err instanceof Error ? err.message.slice(0, 200) : String(err)}`);
|
|
329
|
+
}
|
|
330
|
+
// commitState=false (a two-phase foreground pass) deliberately does NOT stamp
|
|
331
|
+
// the repo as synced — the authoritative timestamp is written by the deeper
|
|
332
|
+
// pass that follows, so planSync keeps treating the repo as not-yet-fully-
|
|
333
|
+
// synced (and the cancel endpoint as an initial backfill) until then.
|
|
334
|
+
if (commitState) {
|
|
335
|
+
const now = new Date();
|
|
336
|
+
const statePatch = mode === 'full'
|
|
337
|
+
? { lastFullSyncAt: now, lastIncrementalSyncAt: now }
|
|
338
|
+
: { lastIncrementalSyncAt: now };
|
|
339
|
+
await db
|
|
340
|
+
.insert(syncState)
|
|
341
|
+
.values({ repoId, ...statePatch, lastSyncStatus: 'ok', lastSyncError: null })
|
|
342
|
+
.onConflictDoUpdate({
|
|
343
|
+
target: syncState.repoId,
|
|
344
|
+
set: { ...statePatch, lastSyncStatus: 'ok', lastSyncError: null },
|
|
345
|
+
})
|
|
346
|
+
.execute();
|
|
347
|
+
}
|
|
348
|
+
const phase = commitState ? mode : `${mode} foreground`;
|
|
349
|
+
log.info(`sync ${owner}/${name} [${phase}] done: ${prCount} PRs over ${pages} page(s), ` +
|
|
350
|
+
`cost ${totalCost}, ${lastRemaining} remaining — timing: ${timingSummary()}`);
|
|
351
|
+
// Resume point for a follow-on phase: re-fetch the cutoff page (so its older
|
|
352
|
+
// PRs aren't skipped) if we stopped there, else the final cursor.
|
|
353
|
+
return {
|
|
354
|
+
repoId,
|
|
355
|
+
prCount,
|
|
356
|
+
pages,
|
|
357
|
+
rateLimitRemaining: lastRemaining,
|
|
358
|
+
rateLimitCost: totalCost,
|
|
359
|
+
cancelled: false,
|
|
360
|
+
endCursor: stop ? pageStartCursor : cursor,
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
catch (err) {
|
|
364
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
365
|
+
// The walk's OWN id once the first page landed, else the caller's — see `knownRepoId`.
|
|
366
|
+
// Without the fallback, every failure that happens BEFORE the first page is parsed
|
|
367
|
+
// (404 / no such repo, dead token, SAML wall, a network fault on page one) writes
|
|
368
|
+
// nothing at all and the repo reads 'idle', forever.
|
|
369
|
+
const stateRepoId = repoId ?? opts.knownRepoId ?? null;
|
|
370
|
+
if (stateRepoId !== null) {
|
|
371
|
+
// UPSERT, not a bare UPDATE. A FIRST backfill that fails has no syncState row yet
|
|
372
|
+
// (phase 1 runs commitState:false → never inserts; phase 2 inserts only on success),
|
|
373
|
+
// so an UPDATE would match zero rows and the failure would VANISH — the repo sits
|
|
374
|
+
// half-loaded, reports status 'idle' with lastSyncError null, and the user just sees
|
|
375
|
+
// "nothing loaded". Insert-or-update records the error either way, WITHOUT stamping the
|
|
376
|
+
// sync timestamps (they stay null), so the repo is still treated as never-fully-synced
|
|
377
|
+
// and gets retried on the next scheduled tick.
|
|
378
|
+
try {
|
|
379
|
+
await db
|
|
380
|
+
.insert(syncState)
|
|
381
|
+
.values({ repoId: stateRepoId, lastSyncStatus: 'error', lastSyncError: message })
|
|
382
|
+
.onConflictDoUpdate({
|
|
383
|
+
target: syncState.repoId,
|
|
384
|
+
set: { lastSyncStatus: 'error', lastSyncError: message },
|
|
385
|
+
})
|
|
386
|
+
.execute();
|
|
387
|
+
}
|
|
388
|
+
catch (stateErr) {
|
|
389
|
+
// Recording the failure must never REPLACE it. With knownRepoId the row is the
|
|
390
|
+
// caller's claim rather than one this walk just upserted, so a repo deleted mid-walk
|
|
391
|
+
// would fail the FK here and mask the real error the caller is about to see.
|
|
392
|
+
log.warn(`sync ${owner}/${name}: could not record the failure on sync_state: ` +
|
|
393
|
+
`${stateErr instanceof Error ? stateErr.message.slice(0, 200) : String(stateErr)}`);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
log.error(`sync ${owner}/${name} failed: ${message}`);
|
|
397
|
+
throw err;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
//# sourceMappingURL=sync-repo.js.map
|