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,1220 @@
|
|
|
1
|
+
// Postgres schema (cloud / Railway deployment mode, via node-postgres).
|
|
2
|
+
//
|
|
3
|
+
// The structural twin of `schema.sqlite.ts` — SAME table names, SAME column
|
|
4
|
+
// names, SAME `$type`s — with pg-core column types. Keep the two in lockstep by
|
|
5
|
+
// hand (the repo's "kept-in-sync copy" convention); `client.ts` casts the active
|
|
6
|
+
// driver+schema to this module's types, and `assertSchemaParity` guards drift.
|
|
7
|
+
//
|
|
8
|
+
// Type mapping from the sqlite twin:
|
|
9
|
+
// integer().primaryKey({autoIncrement}) -> serial().primaryKey()
|
|
10
|
+
// integer({mode:'timestamp'}) -> timestamp({withTimezone, mode:'date'}) (keeps the Date contract)
|
|
11
|
+
// integer({mode:'boolean'}) -> boolean()
|
|
12
|
+
// text({mode:'json'}).$type<T>() -> jsonb().$type<T>()
|
|
13
|
+
// real() -> doublePrecision()
|
|
14
|
+
// .default(sql`(unixepoch())`) -> .defaultNow()
|
|
15
|
+
// text({enum:[...]}) -> text({enum:[...]}) (kept as text, no native pg enum)
|
|
16
|
+
import { pgTable, text, integer, boolean, timestamp, jsonb, serial, doublePrecision, index, uniqueIndex, foreignKey, } from 'drizzle-orm/pg-core';
|
|
17
|
+
export const accounts = pgTable('accounts', {
|
|
18
|
+
id: serial('id').primaryKey(),
|
|
19
|
+
githubUserId: text('github_user_id').notNull().unique(),
|
|
20
|
+
githubLogin: text('github_login').notNull(),
|
|
21
|
+
// The user's GitHub display name (the `name` field from `gh api user` / OAuth
|
|
22
|
+
// `GET /user`). Nullable — GitHub `name` can be unset; the UI falls back to the
|
|
23
|
+
// login. Shown wherever the signed-in identity appears (header, greeting).
|
|
24
|
+
displayName: text('display_name'),
|
|
25
|
+
avatarUrl: text('avatar_url'),
|
|
26
|
+
accessTokenEnc: text('access_token_enc'),
|
|
27
|
+
isLocal: boolean('is_local').notNull().default(false),
|
|
28
|
+
createdAt: timestamp('created_at', { withTimezone: true, mode: 'date' })
|
|
29
|
+
.notNull()
|
|
30
|
+
.defaultNow(),
|
|
31
|
+
lastLoginAt: timestamp('last_login_at', { withTimezone: true, mode: 'date' }),
|
|
32
|
+
// Last time a loaded frontend was seen talking to the backend (cloud: stamped,
|
|
33
|
+
// throttled, by the per-request account hook + an SPA heartbeat). The scheduler
|
|
34
|
+
// syncs only accounts active within config.syncActiveWindowMinutes, so a tenant
|
|
35
|
+
// with no open tab stops being re-synced. Null until first activity.
|
|
36
|
+
lastActiveAt: timestamp('last_active_at', { withTimezone: true, mode: 'date' }),
|
|
37
|
+
// Last time this account viewed the Activity Feed — server-side "seen" marker (see the
|
|
38
|
+
// sqlite twin). Drives "new My Turn since you were last here"; null until the first view.
|
|
39
|
+
feedLastSeenAt: timestamp('feed_last_seen_at', { withTimezone: true, mode: 'date' }),
|
|
40
|
+
// Billing plan ('free' | 'pro') — set only by the Stripe webhook. See the
|
|
41
|
+
// sqlite twin. Kept in sync by hand (schema-parity.test.ts).
|
|
42
|
+
plan: text('plan').notNull().default('free'),
|
|
43
|
+
stripeCustomerId: text('stripe_customer_id'),
|
|
44
|
+
// Per-account monthly SUMMARY-AI credit allowance override (metered cloud plan). null =
|
|
45
|
+
// plan default (2,500 for paid cloud); local/unlimited accounts ignore it. See the sqlite
|
|
46
|
+
// twin. Kept in sync by hand (schema-parity.test.ts).
|
|
47
|
+
aiCreditAllowance: integer('ai_credit_allowance'),
|
|
48
|
+
// CLOUD-ONLY, opt-in (default OFF): contribute de-identified aggregate weekly review-bot
|
|
49
|
+
// outcome stats to the cross-org benchmark network. See the sqlite twin + benchmarkContributions.
|
|
50
|
+
benchmarkOptIn: boolean('benchmark_opt_in').notNull().default(false),
|
|
51
|
+
// The LARGE-PR FLAG's per-account code-churn threshold; NULL = the 1,500-line product default.
|
|
52
|
+
// See the sqlite twin. Kept in sync by hand (schema-parity.test.ts).
|
|
53
|
+
largePrCodeLocThreshold: integer('large_pr_code_loc_threshold'),
|
|
54
|
+
// BLAST RADIUS reading settings ({sensitivity, surfacesOff[], overrides?}); NULL = the product
|
|
55
|
+
// defaults, applied SPA-side. See the sqlite twin. Kept in sync by hand (schema-parity.test.ts).
|
|
56
|
+
blastRadiusConfig: jsonb('blast_radius_config').$type(),
|
|
57
|
+
// MY TURN settings (types shown, their order, the Do next weights); NULL = the product defaults,
|
|
58
|
+
// resolved by packages/shared. See the sqlite twin. Kept in sync by hand (schema-parity.test.ts).
|
|
59
|
+
myTurnSettings: jsonb('my_turn_settings').$type(),
|
|
60
|
+
});
|
|
61
|
+
export const repos = pgTable('repos', {
|
|
62
|
+
id: serial('id').primaryKey(),
|
|
63
|
+
accountId: integer('account_id')
|
|
64
|
+
.notNull()
|
|
65
|
+
.references(() => accounts.id),
|
|
66
|
+
owner: text('owner').notNull(),
|
|
67
|
+
name: text('name').notNull(),
|
|
68
|
+
githubNodeId: text('github_node_id').notNull(),
|
|
69
|
+
// The repo's GitHub "About" description — grounding for the workspace-purpose
|
|
70
|
+
// sprint-chat preset. See schema.sqlite.ts. Kept in sync by hand (schema-parity.test.ts).
|
|
71
|
+
description: text('description'),
|
|
72
|
+
defaultBranch: text('default_branch'),
|
|
73
|
+
// The viewer's permission on the repo (GraphQL Repository.viewerPermission).
|
|
74
|
+
// Drives whether the viewer may approve a PR (WRITE+). See schema.sqlite.ts.
|
|
75
|
+
// Kept in sync by hand (schema-parity.test.ts).
|
|
76
|
+
viewerPermission: text('viewer_permission'),
|
|
77
|
+
backfillUntil: timestamp('backfill_until', {
|
|
78
|
+
withTimezone: true,
|
|
79
|
+
mode: 'date',
|
|
80
|
+
}),
|
|
81
|
+
// Default-branch status snapshot ("is trunk green?") — the pg twin of schema.sqlite.ts.
|
|
82
|
+
// All nullable until the branch sync runs. Kept in sync by hand (schema-parity.test.ts).
|
|
83
|
+
defaultBranchName: text('default_branch_name'),
|
|
84
|
+
defaultBranchHeadSha: text('default_branch_head_sha'),
|
|
85
|
+
defaultBranchCiStatus: text('default_branch_ci_status', {
|
|
86
|
+
enum: ['success', 'failure', 'pending', 'error', 'expected', 'unknown'],
|
|
87
|
+
}),
|
|
88
|
+
defaultBranchUpdatedAt: timestamp('default_branch_updated_at', {
|
|
89
|
+
withTimezone: true,
|
|
90
|
+
mode: 'date',
|
|
91
|
+
}),
|
|
92
|
+
// When the repo was added to this account — My Turn's clock. See schema.sqlite.ts for why
|
|
93
|
+
// that is load-bearing. Kept in sync by hand (schema-parity.test.ts).
|
|
94
|
+
createdAt: timestamp('created_at', { withTimezone: true, mode: 'date' })
|
|
95
|
+
.notNull()
|
|
96
|
+
.defaultNow(),
|
|
97
|
+
}, (t) => ({
|
|
98
|
+
ownerNameUx: uniqueIndex('repos_account_owner_name').on(t.accountId, t.owner, t.name),
|
|
99
|
+
nodeUx: uniqueIndex('repos_account_node').on(t.accountId, t.githubNodeId),
|
|
100
|
+
accountIdx: index('repos_account_idx').on(t.accountId),
|
|
101
|
+
// Parent key for `workspace_repos`' composite FK — not a lookup index. Postgres accepts a
|
|
102
|
+
// plain UNIQUE INDEX here (a named UNIQUE CONSTRAINT is not required; verified on 16.13),
|
|
103
|
+
// which is what lets this be the same DDL as the sqlite twin. See schema.sqlite.ts.
|
|
104
|
+
// `workspaces_id_account` is the same trick for the workspace half of those FKs.
|
|
105
|
+
idAccountUx: uniqueIndex('repos_id_account').on(t.id, t.accountId),
|
|
106
|
+
}));
|
|
107
|
+
export const users = pgTable('users', {
|
|
108
|
+
id: serial('id').primaryKey(),
|
|
109
|
+
githubLogin: text('github_login').notNull().unique(),
|
|
110
|
+
githubNodeId: text('github_node_id').unique(),
|
|
111
|
+
displayName: text('display_name'),
|
|
112
|
+
avatarUrl: text('avatar_url'),
|
|
113
|
+
isBot: boolean('is_bot').notNull().default(false),
|
|
114
|
+
isBotOverridden: boolean('is_bot_overridden').notNull().default(false),
|
|
115
|
+
// GitHub GraphQL __typename of the actor, captured during sync — the pg twin of
|
|
116
|
+
// schema.sqlite.ts. Plain text (no enum), nullable, GLOBAL. Feeds the bot-triage
|
|
117
|
+
// classifier. Kept in sync by hand (schema-parity.test.ts).
|
|
118
|
+
githubType: text('github_type'),
|
|
119
|
+
// The GitHub App slug behind this actor's comments — the pg twin of schema.sqlite.ts
|
|
120
|
+
// (see the rationale there). Nullable, GLOBAL, never cleared by a later app-less comment.
|
|
121
|
+
appSlug: text('app_slug'),
|
|
122
|
+
});
|
|
123
|
+
export const pullRequests = pgTable('pull_requests', {
|
|
124
|
+
id: serial('id').primaryKey(),
|
|
125
|
+
githubNodeId: text('github_node_id').notNull(),
|
|
126
|
+
accountId: integer('account_id')
|
|
127
|
+
.notNull()
|
|
128
|
+
.references(() => accounts.id),
|
|
129
|
+
repoId: integer('repo_id')
|
|
130
|
+
.notNull()
|
|
131
|
+
.references(() => repos.id),
|
|
132
|
+
number: integer('number').notNull(),
|
|
133
|
+
title: text('title').notNull(),
|
|
134
|
+
body: text('body'),
|
|
135
|
+
authorId: integer('author_id').references(() => users.id),
|
|
136
|
+
mergedById: integer('merged_by_id').references(() => users.id),
|
|
137
|
+
baseRefName: text('base_ref_name'),
|
|
138
|
+
// The PR's SOURCE branch (GraphQL `headRefName`); carrier of a Jira/Linear ticket key,
|
|
139
|
+
// read by the Pro ticket-link enricher. Null until a sync backfills it.
|
|
140
|
+
headRefName: text('head_ref_name'),
|
|
141
|
+
state: text('state', { enum: ['open', 'merged', 'closed'] }).notNull(),
|
|
142
|
+
isDraft: boolean('is_draft').notNull().default(false),
|
|
143
|
+
openedAt: timestamp('opened_at', { withTimezone: true, mode: 'date' }).notNull(),
|
|
144
|
+
firstReviewAt: timestamp('first_review_at', {
|
|
145
|
+
withTimezone: true,
|
|
146
|
+
mode: 'date',
|
|
147
|
+
}),
|
|
148
|
+
// Earliest review-request time (first ReviewRequestedEvent) — clock start for review-pickup
|
|
149
|
+
// latency. See the sqlite twin for the rationale.
|
|
150
|
+
firstReviewRequestedAt: timestamp('first_review_requested_at', {
|
|
151
|
+
withTimezone: true,
|
|
152
|
+
mode: 'date',
|
|
153
|
+
}),
|
|
154
|
+
// Review-request HISTORY last written from a response carrying the selection (migration 0066
|
|
155
|
+
// / pg 0053). NULL = never received — "not known", never "never requested". See the sqlite twin.
|
|
156
|
+
reviewRequestsSyncedAt: timestamp('review_requests_synced_at', {
|
|
157
|
+
withTimezone: true,
|
|
158
|
+
mode: 'date',
|
|
159
|
+
}),
|
|
160
|
+
lastCommitAt: timestamp('last_commit_at', {
|
|
161
|
+
withTimezone: true,
|
|
162
|
+
mode: 'date',
|
|
163
|
+
}),
|
|
164
|
+
mergedAt: timestamp('merged_at', { withTimezone: true, mode: 'date' }),
|
|
165
|
+
closedAt: timestamp('closed_at', { withTimezone: true, mode: 'date' }),
|
|
166
|
+
updatedAt: timestamp('updated_at', { withTimezone: true, mode: 'date' }).notNull(),
|
|
167
|
+
headSha: text('head_sha'),
|
|
168
|
+
ciStatus: text('ci_status', {
|
|
169
|
+
enum: ['success', 'failure', 'pending', 'error', 'expected', 'unknown'],
|
|
170
|
+
}),
|
|
171
|
+
mergeable: text('mergeable', {
|
|
172
|
+
enum: ['mergeable', 'conflicting', 'unknown'],
|
|
173
|
+
}),
|
|
174
|
+
mergeStateStatus: text('merge_state_status', {
|
|
175
|
+
enum: [
|
|
176
|
+
'clean',
|
|
177
|
+
'dirty',
|
|
178
|
+
'unstable',
|
|
179
|
+
'blocked',
|
|
180
|
+
'behind',
|
|
181
|
+
'has_hooks',
|
|
182
|
+
'unknown',
|
|
183
|
+
],
|
|
184
|
+
}),
|
|
185
|
+
// GitHub's overall review decision (GraphQL PullRequest.reviewDecision, lowercased) — the
|
|
186
|
+
// pg twin of schema.sqlite.ts. Names the review half of a `blocked` merge state.
|
|
187
|
+
reviewDecision: text('review_decision', {
|
|
188
|
+
enum: ['approved', 'changes_requested', 'review_required'],
|
|
189
|
+
}),
|
|
190
|
+
// GitHub's native merge queue as a SYNCED fact — the pg twin of schema.sqlite.ts, which
|
|
191
|
+
// carries the full argument. In short: MergeStateStatus has no QUEUED member, so a queued
|
|
192
|
+
// PR reads like any other (its underlying state — 'clean' and 'unknown' have both been seen),
|
|
193
|
+
// and the Pending board may not fetch on mount to find out. ⚠ NULL MEANS "NOT OBSERVED", NOT "NOT QUEUED" — `false` is a
|
|
194
|
+
// positive statement from GitHub and null is the absence of one. Position and
|
|
195
|
+
// estimatedTimeToMerge stay live-only (volatile, and only the merge control renders them).
|
|
196
|
+
inMergeQueue: boolean('in_merge_queue'),
|
|
197
|
+
// GitHub's MergeQueueEntryState, lowercased. `unmergeable` is the value that earns the
|
|
198
|
+
// column: GitHub ejects an entry whose checks failed, and without it the PR just vanishes
|
|
199
|
+
// from the queue with nothing to tell the reader.
|
|
200
|
+
mergeQueueEntryState: text('merge_queue_entry_state', {
|
|
201
|
+
enum: ['awaiting_checks', 'locked', 'mergeable', 'queued', 'unmergeable'],
|
|
202
|
+
}),
|
|
203
|
+
labels: jsonb('labels').$type(),
|
|
204
|
+
checkRuns: jsonb('check_runs').$type(),
|
|
205
|
+
// ---- Diff size (GraphQL additions/deletions/changedFiles + files connection) ----
|
|
206
|
+
// Small metadata (not bulky text), so ALWAYS stored — independent of lean mode —
|
|
207
|
+
// and served straight from the DB for the PR-detail LOC label + "Changes" tab.
|
|
208
|
+
additions: integer('additions').notNull().default(0),
|
|
209
|
+
deletions: integer('deletions').notNull().default(0),
|
|
210
|
+
changedFiles: integer('changed_files').notNull().default(0),
|
|
211
|
+
// Per-file breakdown (capped at 100 files by the sync query). Nullable; the
|
|
212
|
+
// API resolves it to [] and computes each file's GitHub deep link on read.
|
|
213
|
+
files: jsonb('files').$type(),
|
|
214
|
+
// BLAST RADIUS: what the code churn consists of, plus the head sha it was read at (migration
|
|
215
|
+
// pg 0051). See the sqlite twin — NULL means "we did not look", and the sha is what stops a
|
|
216
|
+
// stale verdict outliving the commit it described. Kept in sync by hand.
|
|
217
|
+
contentKind: text('content_kind', { enum: ['comments', 'formatting', 'code'] }),
|
|
218
|
+
contentKindSha: text('content_kind_sha'),
|
|
219
|
+
// DEPENDENCY + SECURITY SIGNALS (migration pg 0054), read at sync from the PR's own title /
|
|
220
|
+
// branch / labels / FULL bodyText. See the sqlite twin — no bodies, the four are written
|
|
221
|
+
// together or not at all, and `security_checked_at` NULL is the backfill's worklist.
|
|
222
|
+
dependencyVendor: text('dependency_vendor'),
|
|
223
|
+
securityFix: text('security_fix', { enum: ['proven', 'inferred'] }),
|
|
224
|
+
advisoryIds: jsonb('advisory_ids').$type(),
|
|
225
|
+
securityCheckedAt: timestamp('security_checked_at', { withTimezone: true, mode: 'date' }),
|
|
226
|
+
}, (t) => ({
|
|
227
|
+
repoIdx: index('pr_repo_idx').on(t.repoId),
|
|
228
|
+
openedIdx: index('pr_opened_idx').on(t.openedAt),
|
|
229
|
+
accountIdx: index('pr_account_idx').on(t.accountId),
|
|
230
|
+
// Drives getUserStats (the contributor popover) from the person rather than the account.
|
|
231
|
+
authorIdx: index('pr_author_idx').on(t.authorId),
|
|
232
|
+
// Serves resolving a PR NUMBER to a local id within a repo (the branch strip's commit → PR
|
|
233
|
+
// link). See schema.sqlite.ts for why it isn't optional polish.
|
|
234
|
+
accountRepoNumberIdx: index('pr_account_repo_number_idx').on(t.accountId, t.repoId, t.number),
|
|
235
|
+
nodeUx: uniqueIndex('pr_account_node').on(t.accountId, t.githubNodeId),
|
|
236
|
+
// NOT a lookup index (`id` is the primary key). It exists solely as the PARENT KEY of
|
|
237
|
+
// `my_turn_dismissals`' composite FK `(pr_id, account_id) → pull_requests(id, account_id)` —
|
|
238
|
+
// the `repos_id_account` trick, for a PR id that arrives in a request path.
|
|
239
|
+
idAccountUx: uniqueIndex('pull_requests_id_account').on(t.id, t.accountId),
|
|
240
|
+
}));
|
|
241
|
+
export const reviewRequests = pgTable('review_requests', {
|
|
242
|
+
id: serial('id').primaryKey(),
|
|
243
|
+
prId: integer('pr_id')
|
|
244
|
+
.notNull()
|
|
245
|
+
.references(() => pullRequests.id),
|
|
246
|
+
userId: integer('user_id').references(() => users.id),
|
|
247
|
+
teamName: text('team_name'),
|
|
248
|
+
}, (t) => ({
|
|
249
|
+
prIdx: index('rr_pr_idx').on(t.prId),
|
|
250
|
+
userIdx: index('rr_user_idx').on(t.userId),
|
|
251
|
+
}));
|
|
252
|
+
// Review-request HISTORY (migration 0066 / pg 0053) — the pg twin. A PR child with no account_id,
|
|
253
|
+
// immutable once written, unique on (pr_id, github_node_id). Full rationale in the sqlite twin.
|
|
254
|
+
export const reviewRequestEvents = pgTable('review_request_events', {
|
|
255
|
+
id: serial('id').primaryKey(),
|
|
256
|
+
prId: integer('pr_id')
|
|
257
|
+
.notNull()
|
|
258
|
+
.references(() => pullRequests.id),
|
|
259
|
+
githubNodeId: text('github_node_id').notNull(),
|
|
260
|
+
kind: text('kind', { enum: ['requested', 'removed'] }).notNull(),
|
|
261
|
+
occurredAt: timestamp('occurred_at', { withTimezone: true, mode: 'date' }).notNull(),
|
|
262
|
+
reviewerKind: text('reviewer_kind', { enum: ['user', 'team', 'unknown'] }).notNull(),
|
|
263
|
+
reviewerUserId: integer('reviewer_user_id').references(() => users.id),
|
|
264
|
+
teamSlug: text('team_slug'),
|
|
265
|
+
}, (t) => ({
|
|
266
|
+
prNodeUx: uniqueIndex('review_request_events_pr_node').on(t.prId, t.githubNodeId),
|
|
267
|
+
}));
|
|
268
|
+
export const prViews = pgTable('pr_views', {
|
|
269
|
+
prId: integer('pr_id')
|
|
270
|
+
.primaryKey()
|
|
271
|
+
.references(() => pullRequests.id),
|
|
272
|
+
lastViewedSha: text('last_viewed_sha'),
|
|
273
|
+
lastViewedAt: timestamp('last_viewed_at', {
|
|
274
|
+
withTimezone: true,
|
|
275
|
+
mode: 'date',
|
|
276
|
+
}).notNull(),
|
|
277
|
+
});
|
|
278
|
+
export const reviewThreads = pgTable('review_threads', {
|
|
279
|
+
id: serial('id').primaryKey(),
|
|
280
|
+
githubNodeId: text('github_node_id').notNull(),
|
|
281
|
+
prId: integer('pr_id')
|
|
282
|
+
.notNull()
|
|
283
|
+
.references(() => pullRequests.id),
|
|
284
|
+
path: text('path').notNull(),
|
|
285
|
+
line: integer('line'),
|
|
286
|
+
isResolved: boolean('is_resolved').notNull(),
|
|
287
|
+
isOutdated: boolean('is_outdated').notNull().default(false),
|
|
288
|
+
derivedState: text('derived_state', {
|
|
289
|
+
enum: ['resolved', 'likely_addressed', 'replied_unresolved', 'untouched'],
|
|
290
|
+
}).notNull(),
|
|
291
|
+
// Deterministic "how sure are we it was addressed?" grade computed alongside derivedState
|
|
292
|
+
// (sync/derive-thread-state.ts). Additive to the 4-state contract — advisory only.
|
|
293
|
+
addressedConfidence: text('addressed_confidence', {
|
|
294
|
+
enum: ['none', 'low', 'medium', 'high'],
|
|
295
|
+
})
|
|
296
|
+
.notNull()
|
|
297
|
+
.default('none'),
|
|
298
|
+
// Compact machine tag explaining the grade (e.g. 'outdated+commit', 'bot-marker:coderabbit').
|
|
299
|
+
addressedReason: text('addressed_reason'),
|
|
300
|
+
// GitHub login of whoever resolved the thread (from `resolvedBy`), null when unresolved.
|
|
301
|
+
resolvedByLogin: text('resolved_by_login'),
|
|
302
|
+
// When we FIRST OBSERVED the thread flip unresolved→resolved (sync-observation time). Stamped
|
|
303
|
+
// only on a witnessed transition; a thread already resolved when first seen stays null. Powers
|
|
304
|
+
// the resolution-latency trend. See the sqlite twin for the full rationale.
|
|
305
|
+
resolvedAt: timestamp('resolved_at', { withTimezone: true, mode: 'date' }),
|
|
306
|
+
originalCommenterId: integer('original_commenter_id').references(() => users.id),
|
|
307
|
+
createdAt: timestamp('created_at', { withTimezone: true, mode: 'date' }).notNull(),
|
|
308
|
+
}, (t) => ({
|
|
309
|
+
prIdx: index('thread_pr_idx').on(t.prId),
|
|
310
|
+
nodeUx: uniqueIndex('thread_pr_node').on(t.prId, t.githubNodeId),
|
|
311
|
+
// "Which threads did this actor open?" — the per-repo reviewer footprint counts and migration
|
|
312
|
+
// pg 0029's backfill CTE both union on this column, which had no index at all. See the sqlite
|
|
313
|
+
// twin. Added in pg 0029 (sqlite 0042).
|
|
314
|
+
originalCommenterIdx: index('thread_original_commenter_idx').on(t.originalCommenterId),
|
|
315
|
+
}));
|
|
316
|
+
export const reviewComments = pgTable('review_comments', {
|
|
317
|
+
id: serial('id').primaryKey(),
|
|
318
|
+
githubNodeId: text('github_node_id').notNull(),
|
|
319
|
+
threadId: integer('thread_id')
|
|
320
|
+
.notNull()
|
|
321
|
+
.references(() => reviewThreads.id),
|
|
322
|
+
prId: integer('pr_id')
|
|
323
|
+
.notNull()
|
|
324
|
+
.references(() => pullRequests.id),
|
|
325
|
+
authorId: integer('author_id').references(() => users.id),
|
|
326
|
+
// ALWAYS persisted (the Feed renders full markdown; see the sqlite twin) — nullable
|
|
327
|
+
// only for legacy rows from the 2026-06 lean window. `excerpt` keeps a short preview.
|
|
328
|
+
body: text('body'),
|
|
329
|
+
excerpt: text('excerpt'),
|
|
330
|
+
diffHunk: text('diff_hunk'),
|
|
331
|
+
databaseId: text('database_id'),
|
|
332
|
+
createdAt: timestamp('created_at', { withTimezone: true, mode: 'date' }).notNull(),
|
|
333
|
+
}, (t) => ({
|
|
334
|
+
threadIdx: index('rc_thread_idx').on(t.threadId),
|
|
335
|
+
authorIdx: index('rc_author_idx').on(t.authorId),
|
|
336
|
+
nodeUx: uniqueIndex('rc_pr_node').on(t.prId, t.githubNodeId),
|
|
337
|
+
}));
|
|
338
|
+
export const prComments = pgTable('pr_comments', {
|
|
339
|
+
id: serial('id').primaryKey(),
|
|
340
|
+
githubNodeId: text('github_node_id').notNull(),
|
|
341
|
+
prId: integer('pr_id')
|
|
342
|
+
.notNull()
|
|
343
|
+
.references(() => pullRequests.id),
|
|
344
|
+
authorId: integer('author_id').references(() => users.id),
|
|
345
|
+
// ALWAYS persisted (the Feed renders full markdown; see the sqlite twin) — nullable
|
|
346
|
+
// only for legacy rows from the 2026-06 lean window.
|
|
347
|
+
body: text('body'),
|
|
348
|
+
databaseId: text('database_id'),
|
|
349
|
+
createdAt: timestamp('created_at', { withTimezone: true, mode: 'date' }).notNull(),
|
|
350
|
+
}, (t) => ({
|
|
351
|
+
prIdx: index('prc_pr_idx').on(t.prId),
|
|
352
|
+
authorIdx: index('prc_author_idx').on(t.authorId),
|
|
353
|
+
nodeUx: uniqueIndex('prc_pr_node').on(t.prId, t.githubNodeId),
|
|
354
|
+
}));
|
|
355
|
+
export const reviews = pgTable('reviews', {
|
|
356
|
+
id: serial('id').primaryKey(),
|
|
357
|
+
githubNodeId: text('github_node_id').notNull(),
|
|
358
|
+
prId: integer('pr_id')
|
|
359
|
+
.notNull()
|
|
360
|
+
.references(() => pullRequests.id),
|
|
361
|
+
authorId: integer('author_id').references(() => users.id),
|
|
362
|
+
state: text('state', {
|
|
363
|
+
enum: ['approved', 'changes_requested', 'commented', 'dismissed', 'pending'],
|
|
364
|
+
}).notNull(),
|
|
365
|
+
body: text('body'),
|
|
366
|
+
databaseId: text('database_id'),
|
|
367
|
+
submittedAt: timestamp('submitted_at', {
|
|
368
|
+
withTimezone: true,
|
|
369
|
+
mode: 'date',
|
|
370
|
+
}).notNull(),
|
|
371
|
+
}, (t) => ({
|
|
372
|
+
prIdx: index('rv_pr_idx').on(t.prId),
|
|
373
|
+
authorIdx: index('rv_author_idx').on(t.authorId),
|
|
374
|
+
nodeUx: uniqueIndex('reviews_pr_node').on(t.prId, t.githubNodeId),
|
|
375
|
+
}));
|
|
376
|
+
export const commits = pgTable('commits', {
|
|
377
|
+
id: serial('id').primaryKey(),
|
|
378
|
+
sha: text('sha').notNull(),
|
|
379
|
+
prId: integer('pr_id')
|
|
380
|
+
.notNull()
|
|
381
|
+
.references(() => pullRequests.id),
|
|
382
|
+
authorId: integer('author_id').references(() => users.id),
|
|
383
|
+
committerId: integer('committer_id').references(() => users.id),
|
|
384
|
+
message: text('message'),
|
|
385
|
+
// GitHub's `messageHeadline` (first line, <= 200 chars). Fetched on EVERY walk, not lean-gated,
|
|
386
|
+
// and written only when received: NULL is "not synced yet". Read by My Turn's "Pushed since"
|
|
387
|
+
// card (migration 0072 / pg 0059).
|
|
388
|
+
messageHeadline: text('message_headline'),
|
|
389
|
+
committedAt: timestamp('committed_at', {
|
|
390
|
+
withTimezone: true,
|
|
391
|
+
mode: 'date',
|
|
392
|
+
}).notNull(),
|
|
393
|
+
}, (t) => ({
|
|
394
|
+
prIdx: index('commit_pr_idx').on(t.prId),
|
|
395
|
+
shaPrUx: uniqueIndex('commit_sha_pr_ux').on(t.sha, t.prId),
|
|
396
|
+
}));
|
|
397
|
+
// BLAST RADIUS: the per-repo CO-CHANGE index (P2). One row per (account, repo), storing only
|
|
398
|
+
// the HUB paths — those at or above max(repo p90, HUB_MIN_DEGREE). See the sqlite twin for why
|
|
399
|
+
// both halves of that bar are load-bearing. Kept in sync by hand (schema-parity.test.ts).
|
|
400
|
+
export const repoFileCoupling = pgTable('repo_file_coupling', {
|
|
401
|
+
id: serial('id').primaryKey(),
|
|
402
|
+
accountId: integer('account_id')
|
|
403
|
+
.notNull()
|
|
404
|
+
.references(() => accounts.id),
|
|
405
|
+
repoId: integer('repo_id')
|
|
406
|
+
.notNull()
|
|
407
|
+
.references(() => repos.id),
|
|
408
|
+
hubBar: integer('hub_bar').notNull(),
|
|
409
|
+
prCount: integer('pr_count').notNull(),
|
|
410
|
+
hubs: jsonb('hubs').$type().notNull(),
|
|
411
|
+
builtAt: timestamp('built_at', { withTimezone: true }).notNull().defaultNow(),
|
|
412
|
+
}, (t) => ({
|
|
413
|
+
accountRepoUx: uniqueIndex('rfc_account_repo').on(t.accountId, t.repoId),
|
|
414
|
+
}));
|
|
415
|
+
export const commitFiles = pgTable('commit_files', {
|
|
416
|
+
sha: text('sha').primaryKey(),
|
|
417
|
+
paths: jsonb('paths').$type().notNull(),
|
|
418
|
+
fetchedAt: timestamp('fetched_at', { withTimezone: true, mode: 'date' })
|
|
419
|
+
.notNull()
|
|
420
|
+
.defaultNow(),
|
|
421
|
+
});
|
|
422
|
+
export const events = pgTable('events', {
|
|
423
|
+
id: serial('id').primaryKey(),
|
|
424
|
+
accountId: integer('account_id')
|
|
425
|
+
.notNull()
|
|
426
|
+
.references(() => accounts.id),
|
|
427
|
+
repoId: integer('repo_id')
|
|
428
|
+
.notNull()
|
|
429
|
+
.references(() => repos.id),
|
|
430
|
+
actorId: integer('actor_id').references(() => users.id),
|
|
431
|
+
prId: integer('pr_id').references(() => pullRequests.id),
|
|
432
|
+
type: text('type', {
|
|
433
|
+
enum: [
|
|
434
|
+
'pr_opened',
|
|
435
|
+
'pr_merged',
|
|
436
|
+
'pr_closed',
|
|
437
|
+
'pr_reopened',
|
|
438
|
+
'pr_ready_for_review',
|
|
439
|
+
'review_submitted',
|
|
440
|
+
'review_comment',
|
|
441
|
+
'pr_comment',
|
|
442
|
+
'commit_pushed',
|
|
443
|
+
],
|
|
444
|
+
}).notNull(),
|
|
445
|
+
occurredAt: timestamp('occurred_at', {
|
|
446
|
+
withTimezone: true,
|
|
447
|
+
mode: 'date',
|
|
448
|
+
}).notNull(),
|
|
449
|
+
refTable: text('ref_table'),
|
|
450
|
+
refId: integer('ref_id'),
|
|
451
|
+
dedupeKey: text('dedupe_key').notNull(),
|
|
452
|
+
}, (t) => ({
|
|
453
|
+
timeIdx: index('events_time_idx').on(t.occurredAt),
|
|
454
|
+
repoTimeIdx: index('events_repo_time_idx').on(t.repoId, t.occurredAt),
|
|
455
|
+
actorIdx: index('events_actor_idx').on(t.actorId),
|
|
456
|
+
accountIdx: index('events_account_idx').on(t.accountId),
|
|
457
|
+
// pr_id-correlated EXISTS lookups (open-PR staleness, feed joins) — see schema.sqlite.ts.
|
|
458
|
+
prTimeIdx: index('events_pr_idx').on(t.prId, t.occurredAt),
|
|
459
|
+
dedupeUx: uniqueIndex('events_account_dedupe').on(t.accountId, t.dedupeKey),
|
|
460
|
+
}));
|
|
461
|
+
// CI status transition history — the pg twin of schema.sqlite.ts ciStatusEvents. See
|
|
462
|
+
// there for the rationale (real CI failure-resolution + failure-reason metrics).
|
|
463
|
+
export const ciStatusEvents = pgTable('ci_status_events', {
|
|
464
|
+
id: serial('id').primaryKey(),
|
|
465
|
+
accountId: integer('account_id')
|
|
466
|
+
.notNull()
|
|
467
|
+
.references(() => accounts.id),
|
|
468
|
+
repoId: integer('repo_id')
|
|
469
|
+
.notNull()
|
|
470
|
+
.references(() => repos.id),
|
|
471
|
+
prId: integer('pr_id')
|
|
472
|
+
.notNull()
|
|
473
|
+
.references(() => pullRequests.id),
|
|
474
|
+
headSha: text('head_sha').notNull(),
|
|
475
|
+
status: text('status', {
|
|
476
|
+
enum: ['success', 'failure', 'pending', 'error', 'expected', 'unknown'],
|
|
477
|
+
}).notNull(),
|
|
478
|
+
failingChecks: jsonb('failing_checks').$type(),
|
|
479
|
+
observedAt: timestamp('observed_at', { withTimezone: true, mode: 'date' }).notNull(),
|
|
480
|
+
}, (t) => ({
|
|
481
|
+
accountPrObservedIdx: index('cse_account_pr_observed').on(t.accountId, t.prId, t.observedAt),
|
|
482
|
+
accountRepoObservedIdx: index('cse_account_repo_observed').on(t.accountId, t.repoId, t.observedAt),
|
|
483
|
+
}));
|
|
484
|
+
// Append-only AI-spend ledger (pg twin of the sqlite table). See schema.sqlite.ts.
|
|
485
|
+
export const aiUsage = pgTable('ai_usage', {
|
|
486
|
+
id: serial('id').primaryKey(),
|
|
487
|
+
accountId: integer('account_id')
|
|
488
|
+
.notNull()
|
|
489
|
+
.references(() => accounts.id),
|
|
490
|
+
seam: text('seam', { enum: ['summary', 'agent'] }).notNull(),
|
|
491
|
+
feature: text('feature').notNull(),
|
|
492
|
+
model: text('model').notNull(),
|
|
493
|
+
costUsd: doublePrecision('cost_usd').notNull(),
|
|
494
|
+
inputTokens: integer('input_tokens'),
|
|
495
|
+
outputTokens: integer('output_tokens'),
|
|
496
|
+
prId: integer('pr_id'),
|
|
497
|
+
repoId: integer('repo_id'),
|
|
498
|
+
occurredAt: timestamp('occurred_at', { withTimezone: true, mode: 'date' })
|
|
499
|
+
.notNull()
|
|
500
|
+
.defaultNow(),
|
|
501
|
+
}, (t) => ({
|
|
502
|
+
accountOccurredIdx: index('au_account_occurred').on(t.accountId, t.occurredAt),
|
|
503
|
+
}));
|
|
504
|
+
// ---- Auto-merge intents ── the pg twin of the sqlite autoMergeRequests table. See that file
|
|
505
|
+
// for the full rationale (Pierre-side standing intent, `expectedHeadOid` as the consent
|
|
506
|
+
// anchor, `expiresAt` as the backstop, one row per (account, PR)).
|
|
507
|
+
export const autoMergeRequests = pgTable('auto_merge_requests', {
|
|
508
|
+
id: serial('id').primaryKey(),
|
|
509
|
+
accountId: integer('account_id')
|
|
510
|
+
.notNull()
|
|
511
|
+
.references(() => accounts.id, { onDelete: 'cascade' }),
|
|
512
|
+
prId: integer('pr_id')
|
|
513
|
+
.notNull()
|
|
514
|
+
.references(() => pullRequests.id, { onDelete: 'cascade' }),
|
|
515
|
+
mergeMethod: text('merge_method', {
|
|
516
|
+
enum: ['merge', 'squash', 'rebase'],
|
|
517
|
+
}).notNull(),
|
|
518
|
+
updateStrategy: text('update_strategy', {
|
|
519
|
+
enum: ['rebase', 'merge', 'none'],
|
|
520
|
+
}).notNull(),
|
|
521
|
+
expectedHeadOid: text('expected_head_oid').notNull(),
|
|
522
|
+
// ---- TWO CONSENT/BOOKKEEPING ANCHORS THAT USED TO LIVE IN PROCESS MEMORY ----------------
|
|
523
|
+
//
|
|
524
|
+
// Both were module-level Maps in `merge/auto-merge-runner.ts`. A Map is fine for a hint; it
|
|
525
|
+
// is NOT fine for a fact the watcher DISARMS on, because a restart turns "I know why this
|
|
526
|
+
// happened" into "something unexplained happened" — and the safe direction for an unexplained
|
|
527
|
+
// head move is to disarm. Under `pnpm dev` that is every file save; in cloud it is every
|
|
528
|
+
// deploy.
|
|
529
|
+
//
|
|
530
|
+
// The base branch the user was looking at when they armed. The head pin cannot see a
|
|
531
|
+
// retarget (PATCH pulls/{n} with a new `base` leaves head.sha alone), so the watcher needs a
|
|
532
|
+
// second anchor — and it was reading the SYNCED `pull_requests.base_ref_name` at RUN time,
|
|
533
|
+
// which is not what the user consented to: any sync that corrects that column between arming
|
|
534
|
+
// and a tick reads as a retarget and disarms. NULL on rows armed before this column existed;
|
|
535
|
+
// the guard falls back to the synced ref for those, exactly as before.
|
|
536
|
+
expectedBaseRef: text('expected_base_ref'),
|
|
537
|
+
// The head SHA an in-flight `update-branch` was issued AGAINST. GitHub's update-branch
|
|
538
|
+
// returns 202 with no handle to poll, so the resulting head move lands on a later tick and
|
|
539
|
+
// `isOurUpdateMerge` needs this to tell it apart from a human push. NULL means no update is
|
|
540
|
+
// in flight — which is also the honest answer after a restart that happened before one.
|
|
541
|
+
updateIssuedAgainstOid: text('update_issued_against_oid'),
|
|
542
|
+
viaMergeQueue: boolean('via_merge_queue').notNull().default(false),
|
|
543
|
+
enqueuedAt: timestamp('enqueued_at', { withTimezone: true, mode: 'date' }),
|
|
544
|
+
state: text('state', {
|
|
545
|
+
enum: [
|
|
546
|
+
'armed',
|
|
547
|
+
'merged',
|
|
548
|
+
'disarmed_head_moved',
|
|
549
|
+
'disarmed_blocked',
|
|
550
|
+
'expired',
|
|
551
|
+
'failed',
|
|
552
|
+
],
|
|
553
|
+
}).notNull(),
|
|
554
|
+
armedAt: timestamp('armed_at', { withTimezone: true, mode: 'date' }).notNull(),
|
|
555
|
+
expiresAt: timestamp('expires_at', { withTimezone: true, mode: 'date' }).notNull(),
|
|
556
|
+
lastCheckedAt: timestamp('last_checked_at', { withTimezone: true, mode: 'date' }),
|
|
557
|
+
lastReason: text('last_reason'),
|
|
558
|
+
// shared ArmedMergePhase — the machine-readable half of `lastReason`. See the sqlite twin
|
|
559
|
+
// for why terminal outcomes stay on `state` and why null is a legitimate value.
|
|
560
|
+
phase: text('phase', {
|
|
561
|
+
enum: [
|
|
562
|
+
'pending_first_check',
|
|
563
|
+
'waiting_conflicts',
|
|
564
|
+
'waiting_behind',
|
|
565
|
+
'updating_rebase',
|
|
566
|
+
'updating_merge',
|
|
567
|
+
'awaiting_checks',
|
|
568
|
+
'awaiting_review',
|
|
569
|
+
'blocked_protection',
|
|
570
|
+
'enqueuing',
|
|
571
|
+
'queued',
|
|
572
|
+
// Limn's own per-repo hold — NOT GitHub's merge queue. See ArmedMergePhase in shared.
|
|
573
|
+
'queued_local',
|
|
574
|
+
'merging',
|
|
575
|
+
'retrying',
|
|
576
|
+
],
|
|
577
|
+
}),
|
|
578
|
+
createdAt: timestamp('created_at', { withTimezone: true, mode: 'date' })
|
|
579
|
+
.notNull()
|
|
580
|
+
.defaultNow(),
|
|
581
|
+
updatedAt: timestamp('updated_at', { withTimezone: true, mode: 'date' })
|
|
582
|
+
.notNull()
|
|
583
|
+
.defaultNow(),
|
|
584
|
+
}, (t) => ({
|
|
585
|
+
accountPrUx: uniqueIndex('amr_account_pr').on(t.accountId, t.prId),
|
|
586
|
+
accountIdx: index('amr_account_idx').on(t.accountId),
|
|
587
|
+
stateIdx: index('amr_state_idx').on(t.state),
|
|
588
|
+
}));
|
|
589
|
+
// ---- Default-branch commits ── the pg twin of the sqlite branchCommits table. See that file
|
|
590
|
+
// for the full rationale (trunk commits aren't derivable from the PR-scoped `commits` table;
|
|
591
|
+
// accountId denormalized for isolation; bounded recent window per repo).
|
|
592
|
+
export const branchCommits = pgTable('branch_commits', {
|
|
593
|
+
id: serial('id').primaryKey(),
|
|
594
|
+
accountId: integer('account_id')
|
|
595
|
+
.notNull()
|
|
596
|
+
.references(() => accounts.id, { onDelete: 'cascade' }),
|
|
597
|
+
repoId: integer('repo_id')
|
|
598
|
+
.notNull()
|
|
599
|
+
.references(() => repos.id, { onDelete: 'cascade' }),
|
|
600
|
+
sha: text('sha').notNull(),
|
|
601
|
+
messageHeadline: text('message_headline').notNull(),
|
|
602
|
+
authorUserId: integer('author_user_id').references(() => users.id),
|
|
603
|
+
authorName: text('author_name'),
|
|
604
|
+
authorAvatarUrl: text('author_avatar_url'),
|
|
605
|
+
committedAt: timestamp('committed_at', { withTimezone: true, mode: 'date' }).notNull(),
|
|
606
|
+
ciStatus: text('ci_status', {
|
|
607
|
+
enum: ['success', 'failure', 'pending', 'error', 'expected', 'unknown'],
|
|
608
|
+
}),
|
|
609
|
+
// The FAILING checks on this commit (failures only, so null on a green commit) and the PR
|
|
610
|
+
// this commit landed from (a plain number, never a FK). See schema.sqlite.ts for the full
|
|
611
|
+
// rationale on both — why failing_checks is NOT lean-gated despite pullRequests.checkRuns
|
|
612
|
+
// being, why it shares a column name with ci_status_events.failing_checks while carrying a
|
|
613
|
+
// different shape, and why pr_number is resolved to a local id at READ time.
|
|
614
|
+
failingChecks: jsonb('failing_checks').$type(),
|
|
615
|
+
prNumber: integer('pr_number'),
|
|
616
|
+
createdAt: timestamp('created_at', { withTimezone: true, mode: 'date' })
|
|
617
|
+
.notNull()
|
|
618
|
+
.defaultNow(),
|
|
619
|
+
}, (t) => ({
|
|
620
|
+
accountRepoShaUx: uniqueIndex('bc_account_repo_sha').on(t.accountId, t.repoId, t.sha),
|
|
621
|
+
accountRepoTimeIdx: index('bc_account_repo_time').on(t.accountId, t.repoId, t.committedAt),
|
|
622
|
+
accountIdx: index('bc_account_idx').on(t.accountId),
|
|
623
|
+
}));
|
|
624
|
+
// ---- Default-branch ("trunk") CI transition log ── the pg twin of the sqlite
|
|
625
|
+
// trunkCiStatusEvents table. See that file for the full rationale: `branch_commits.ciStatus` is
|
|
626
|
+
// updated IN PLACE, so the moment trunk turned red is otherwise unrecorded; rows are written
|
|
627
|
+
// only on a TRANSITION and only on a POSITIVE statement from GitHub; `observed_at` is OUR
|
|
628
|
+
// observation time; the table is bounded by its own per-repo trim (no PR to anchor the
|
|
629
|
+
// retention sweep to), which is HYBRID — newest TRUNK_CI_EVENT_WINDOW rows ∪ everything inside
|
|
630
|
+
// FEED_WINDOW_DAYS (`staleTrunkCiEventIds`), because neither half alone is correct.
|
|
631
|
+
// `failing_checks` carries `BranchCheckRun[]`, NOT ci_status_events' bare `string[]`.
|
|
632
|
+
export const trunkCiStatusEvents = pgTable('trunk_ci_status_events', {
|
|
633
|
+
id: serial('id').primaryKey(),
|
|
634
|
+
accountId: integer('account_id')
|
|
635
|
+
.notNull()
|
|
636
|
+
.references(() => accounts.id, { onDelete: 'cascade' }),
|
|
637
|
+
repoId: integer('repo_id')
|
|
638
|
+
.notNull()
|
|
639
|
+
.references(() => repos.id, { onDelete: 'cascade' }),
|
|
640
|
+
branchName: text('branch_name'),
|
|
641
|
+
headSha: text('head_sha').notNull(),
|
|
642
|
+
status: text('status', {
|
|
643
|
+
enum: ['success', 'failure', 'pending', 'error', 'expected', 'unknown'],
|
|
644
|
+
}).notNull(),
|
|
645
|
+
failingChecks: jsonb('failing_checks').$type(),
|
|
646
|
+
observedAt: timestamp('observed_at', { withTimezone: true, mode: 'date' }).notNull(),
|
|
647
|
+
}, (t) => ({
|
|
648
|
+
accountRepoObservedIdx: index('tcse_account_repo_observed').on(t.accountId, t.repoId, t.observedAt),
|
|
649
|
+
accountIdx: index('tcse_account_idx').on(t.accountId),
|
|
650
|
+
}));
|
|
651
|
+
export const syncState = pgTable('sync_state', {
|
|
652
|
+
repoId: integer('repo_id')
|
|
653
|
+
.primaryKey()
|
|
654
|
+
.references(() => repos.id),
|
|
655
|
+
lastFullSyncAt: timestamp('last_full_sync_at', {
|
|
656
|
+
withTimezone: true,
|
|
657
|
+
mode: 'date',
|
|
658
|
+
}),
|
|
659
|
+
lastIncrementalSyncAt: timestamp('last_incremental_sync_at', {
|
|
660
|
+
withTimezone: true,
|
|
661
|
+
mode: 'date',
|
|
662
|
+
}),
|
|
663
|
+
lastSyncStatus: text('last_sync_status'),
|
|
664
|
+
lastSyncError: text('last_sync_error'),
|
|
665
|
+
});
|
|
666
|
+
export const claudeReviews = pgTable('claude_reviews', {
|
|
667
|
+
id: serial('id').primaryKey(),
|
|
668
|
+
accountId: integer('account_id')
|
|
669
|
+
.notNull()
|
|
670
|
+
.references(() => accounts.id),
|
|
671
|
+
prId: integer('pr_id')
|
|
672
|
+
.notNull()
|
|
673
|
+
.references(() => pullRequests.id),
|
|
674
|
+
headSha: text('head_sha').notNull(),
|
|
675
|
+
status: text('status', {
|
|
676
|
+
enum: ['queued', 'running', 'succeeded', 'failed', 'cancelled'],
|
|
677
|
+
}).notNull(),
|
|
678
|
+
// Plain text, NO drizzle `enum:` — a stored run from a retired model keeps its id. See the
|
|
679
|
+
// schema.sqlite.ts twin.
|
|
680
|
+
model: text('model').notNull(),
|
|
681
|
+
scope: text('scope', { enum: ['diff_only', 'worktree'] }),
|
|
682
|
+
// Deterministic router decision + inputs, recorded before the agent runs. See
|
|
683
|
+
// the schema.sqlite.ts twin for the full rationale.
|
|
684
|
+
reviewMode: text('review_mode', { enum: ['skip', 'diff_only', 'worktree'] }),
|
|
685
|
+
routeReason: jsonb('route_reason').$type(),
|
|
686
|
+
summary: text('summary'),
|
|
687
|
+
verdict: text('verdict', {
|
|
688
|
+
enum: ['COMMENT', 'REQUEST_CHANGES', 'APPROVE'],
|
|
689
|
+
}),
|
|
690
|
+
userBody: text('user_body'),
|
|
691
|
+
userVerdict: text('user_verdict', {
|
|
692
|
+
enum: ['COMMENT', 'REQUEST_CHANGES', 'APPROVE'],
|
|
693
|
+
}),
|
|
694
|
+
costUsd: doublePrecision('cost_usd'),
|
|
695
|
+
inputTokens: integer('input_tokens'),
|
|
696
|
+
outputTokens: integer('output_tokens'),
|
|
697
|
+
// Cache-token split (a multi-turn run's input is mostly cache reads — the hidden
|
|
698
|
+
// cost driver the plain input_tokens column hid). Null when not captured.
|
|
699
|
+
cacheReadTokens: integer('cache_read_tokens'),
|
|
700
|
+
cacheCreationTokens: integer('cache_creation_tokens'),
|
|
701
|
+
numTurns: integer('num_turns'),
|
|
702
|
+
// Full (noise-stripped) diff size in chars + whether the diff-size cap truncated
|
|
703
|
+
// the prompt — for A/B cost comparison of capped vs uncapped runs.
|
|
704
|
+
diffBytes: integer('diff_bytes'),
|
|
705
|
+
diffCapped: boolean('diff_capped'),
|
|
706
|
+
error: text('error'),
|
|
707
|
+
excludedFiles: jsonb('excluded_files').$type(),
|
|
708
|
+
postedReviewId: text('posted_review_id'),
|
|
709
|
+
postedAt: timestamp('posted_at', { withTimezone: true, mode: 'date' }),
|
|
710
|
+
createdAt: timestamp('created_at', { withTimezone: true, mode: 'date' })
|
|
711
|
+
.notNull()
|
|
712
|
+
.defaultNow(),
|
|
713
|
+
finishedAt: timestamp('finished_at', { withTimezone: true, mode: 'date' }),
|
|
714
|
+
// User story / its assessment / the follow-up on the previous review. See the
|
|
715
|
+
// schema.sqlite.ts twin for the contracts. Migration pg 0057 (sqlite 0070).
|
|
716
|
+
ticket: jsonb('ticket').$type(),
|
|
717
|
+
ticketAssessment: jsonb('ticket_assessment').$type(),
|
|
718
|
+
followUp: jsonb('follow_up').$type(),
|
|
719
|
+
// 'manual' | 'auto' — who started the run. Twin of schema.sqlite.ts. Migration pg 0058 (sqlite 0071).
|
|
720
|
+
trigger: text('trigger', { enum: ['manual', 'auto'] }).notNull().default('manual'),
|
|
721
|
+
// Other reviewers' open threads + the comment half of the auto re-review key. Twin of
|
|
722
|
+
// schema.sqlite.ts. Migration pg 0063 (sqlite 0076).
|
|
723
|
+
threadAssessments: jsonb('thread_assessments').$type(),
|
|
724
|
+
commentsThrough: timestamp('comments_through', { withTimezone: true, mode: 'date' }),
|
|
725
|
+
// Failed CI on the reviewed head, diagnosed. Twin of schema.sqlite.ts. Migration pg 0064 (sqlite 0077).
|
|
726
|
+
ciFailures: jsonb('ci_failures').$type(),
|
|
727
|
+
}, (t) => ({
|
|
728
|
+
prIdx: index('cr_pr_idx').on(t.prId),
|
|
729
|
+
prShaIdx: index('cr_pr_sha_idx').on(t.prId, t.headSha),
|
|
730
|
+
accountIdx: index('cr_account_idx').on(t.accountId),
|
|
731
|
+
// Parent key of `claude_review_chat_messages`' composite tenancy FK (migration 0073 / pg
|
|
732
|
+
// 0060). `id` is the primary key, so this is never a lookup index.
|
|
733
|
+
idAccountUx: uniqueIndex('claude_reviews_id_account').on(t.id, t.accountId),
|
|
734
|
+
}));
|
|
735
|
+
export const claudeReviewFindings = pgTable('claude_review_findings', {
|
|
736
|
+
id: serial('id').primaryKey(),
|
|
737
|
+
reviewId: integer('review_id')
|
|
738
|
+
.notNull()
|
|
739
|
+
.references(() => claudeReviews.id),
|
|
740
|
+
path: text('path').notNull(),
|
|
741
|
+
line: integer('line'),
|
|
742
|
+
side: text('side', { enum: ['LEFT', 'RIGHT'] })
|
|
743
|
+
.notNull()
|
|
744
|
+
.default('RIGHT'),
|
|
745
|
+
severity: text('severity', {
|
|
746
|
+
enum: ['blocker', 'warning', 'nit', 'question', 'praise'],
|
|
747
|
+
}).notNull(),
|
|
748
|
+
title: text('title').notNull(),
|
|
749
|
+
body: text('body').notNull(),
|
|
750
|
+
editedBody: text('edited_body'),
|
|
751
|
+
suggestion: text('suggestion'),
|
|
752
|
+
diffHunk: text('diff_hunk'),
|
|
753
|
+
anchored: boolean('anchored').notNull().default(true),
|
|
754
|
+
// Whether the finding's file is part of the PR diff. true ⇒ an unanchored finding
|
|
755
|
+
// posts inline on the file's first change; false ⇒ outside the diff → posts as a
|
|
756
|
+
// standalone PR-level comment. Defaults true (back-compat: pre-existing findings).
|
|
757
|
+
fileInDiff: boolean('file_in_diff').notNull().default(true),
|
|
758
|
+
included: boolean('included').notNull().default(false),
|
|
759
|
+
postedAt: timestamp('posted_at', { withTimezone: true, mode: 'date' }),
|
|
760
|
+
githubCommentId: text('github_comment_id'),
|
|
761
|
+
// How a posted comment was attached: 'inline' (a review comment on a diff line)
|
|
762
|
+
// or 'pr_comment' (a standalone PR-level issue comment, for an unanchored
|
|
763
|
+
// finding posted individually). Null until posted; drives the correct GitHub
|
|
764
|
+
// permalink (#discussion_r vs #issuecomment).
|
|
765
|
+
postedCommentKind: text('posted_comment_kind', {
|
|
766
|
+
enum: ['inline', 'pr_comment'],
|
|
767
|
+
}),
|
|
768
|
+
createdAt: timestamp('created_at', { withTimezone: true, mode: 'date' })
|
|
769
|
+
.notNull()
|
|
770
|
+
.defaultNow(),
|
|
771
|
+
// A SOFT reference (no FK, same PR) to the previous-review finding this one re-raises. See
|
|
772
|
+
// the schema.sqlite.ts twin for why there is no FK. Migration pg 0057 (sqlite 0070).
|
|
773
|
+
priorFindingId: integer('prior_finding_id'),
|
|
774
|
+
// The specialist lens (schema.sqlite.ts twin). Migration pg 0062 (sqlite 0075).
|
|
775
|
+
lens: text('lens'),
|
|
776
|
+
// A story finding's origin (schema.sqlite.ts twin, where the contract lives). Migration pg
|
|
777
|
+
// 0066 (sqlite 0079).
|
|
778
|
+
storyIndex: integer('story_index'),
|
|
779
|
+
storyRef: text('story_ref'),
|
|
780
|
+
}, (t) => ({ reviewIdx: index('crf_review_idx').on(t.reviewId) }));
|
|
781
|
+
// Claude Review chat messages. Twin of schema.sqlite.ts claudeReviewChatMessages, where the
|
|
782
|
+
// contract lives. Migration pg 0060 (sqlite 0073).
|
|
783
|
+
export const claudeReviewChatMessages = pgTable('claude_review_chat_messages', {
|
|
784
|
+
id: serial('id').primaryKey(),
|
|
785
|
+
accountId: integer('account_id')
|
|
786
|
+
.notNull()
|
|
787
|
+
.references(() => accounts.id, { onDelete: 'cascade' }),
|
|
788
|
+
reviewId: integer('review_id').notNull(),
|
|
789
|
+
findingId: integer('finding_id').references(() => claudeReviewFindings.id, {
|
|
790
|
+
onDelete: 'cascade',
|
|
791
|
+
}),
|
|
792
|
+
role: text('role', { enum: ['user', 'assistant'] }).notNull(),
|
|
793
|
+
content: text('content').notNull(),
|
|
794
|
+
model: text('model'),
|
|
795
|
+
costUsd: doublePrecision('cost_usd'),
|
|
796
|
+
inputTokens: integer('input_tokens'),
|
|
797
|
+
outputTokens: integer('output_tokens'),
|
|
798
|
+
createdAt: timestamp('created_at', { withTimezone: true, mode: 'date' })
|
|
799
|
+
.notNull()
|
|
800
|
+
.defaultNow(),
|
|
801
|
+
}, (t) => ({
|
|
802
|
+
threadIdx: index('crcm_thread_idx').on(t.reviewId, t.findingId, t.id),
|
|
803
|
+
accountIdx: index('crcm_account_idx').on(t.accountId),
|
|
804
|
+
reviewAccountFk: foreignKey({
|
|
805
|
+
name: 'crcm_review_account_fk',
|
|
806
|
+
columns: [t.reviewId, t.accountId],
|
|
807
|
+
foreignColumns: [claudeReviews.id, claudeReviews.accountId],
|
|
808
|
+
}).onDelete('cascade'),
|
|
809
|
+
}));
|
|
810
|
+
// ---- AI Fix (CORE since pg 0061 / sqlite 0074) ----
|
|
811
|
+
// Twin of schema.sqlite.ts aiFixes, where the contract lives. Adopted in place from the plugin;
|
|
812
|
+
// same index names, no foreign keys. (review_learnings was dropped by pg 0062 / sqlite 0075.)
|
|
813
|
+
export const aiFixes = pgTable('ai_fixes', {
|
|
814
|
+
id: serial('id').primaryKey(),
|
|
815
|
+
accountId: integer('account_id').notNull(),
|
|
816
|
+
repoId: integer('repo_id').notNull(),
|
|
817
|
+
prId: integer('pr_id').notNull(),
|
|
818
|
+
sourceReviewId: integer('source_review_id'),
|
|
819
|
+
baseSha: text('base_sha').notNull(),
|
|
820
|
+
status: text('status').notNull(),
|
|
821
|
+
model: text('model').notNull(),
|
|
822
|
+
seed: text('seed').notNull(),
|
|
823
|
+
prompt: text('prompt'),
|
|
824
|
+
summary: text('summary'),
|
|
825
|
+
commitMessage: text('commit_message'),
|
|
826
|
+
patch: text('patch'),
|
|
827
|
+
filesChanged: text('files_changed'),
|
|
828
|
+
costUsd: doublePrecision('cost_usd'),
|
|
829
|
+
inputTokens: integer('input_tokens'),
|
|
830
|
+
outputTokens: integer('output_tokens'),
|
|
831
|
+
numTurns: integer('num_turns'),
|
|
832
|
+
error: text('error'),
|
|
833
|
+
pushedBranch: text('pushed_branch'),
|
|
834
|
+
pushedPrNumber: integer('pushed_pr_number'),
|
|
835
|
+
pushedPrUrl: text('pushed_pr_url'),
|
|
836
|
+
pushedAt: timestamp('pushed_at', { withTimezone: true, mode: 'date' }),
|
|
837
|
+
createdAt: timestamp('created_at', { withTimezone: true, mode: 'date' })
|
|
838
|
+
.notNull()
|
|
839
|
+
.defaultNow(),
|
|
840
|
+
finishedAt: timestamp('finished_at', { withTimezone: true, mode: 'date' }),
|
|
841
|
+
commentTargets: text('comment_targets'),
|
|
842
|
+
commentVerdicts: text('comment_verdicts'),
|
|
843
|
+
// pg 0065 — see schema.sqlite.ts aiFixes for the contract.
|
|
844
|
+
trigger: text('trigger'),
|
|
845
|
+
reviewItems: text('review_items'),
|
|
846
|
+
changeReport: text('change_report'),
|
|
847
|
+
}, (t) => ({
|
|
848
|
+
prCreatedIdx: index('af_account_pr_created').on(t.accountId, t.prId, t.createdAt),
|
|
849
|
+
statusIdx: index('af_account_status').on(t.accountId, t.status),
|
|
850
|
+
}));
|
|
851
|
+
// ---- Workspaces (CORE) ----
|
|
852
|
+
// A named grouping of an account's repos, and the ONE scope this app has — the pg twin of
|
|
853
|
+
// schema.sqlite.ts workspaces. Kept in sync BY HAND (schema-parity.test.ts, which compares
|
|
854
|
+
// columns but NOT indexes and NOT foreign keys — diff the FK blocks by eye). Exactly one row per
|
|
855
|
+
// account carries is_default: auto-created, RENAMEABLE, NOT deletable, and new repos land in it.
|
|
856
|
+
export const workspaces = pgTable('workspaces', {
|
|
857
|
+
id: serial('id').primaryKey(),
|
|
858
|
+
accountId: integer('account_id')
|
|
859
|
+
.notNull()
|
|
860
|
+
.references(() => accounts.id, { onDelete: 'cascade' }),
|
|
861
|
+
name: text('name').notNull(),
|
|
862
|
+
// Exactly one true row per account — ALSO enforced by a PARTIAL UNIQUE INDEX created in
|
|
863
|
+
// migrations-pg/0031 (`… ON workspaces (account_id) WHERE is_default`), not here: drizzle
|
|
864
|
+
// index predicates are DDL-only metadata nothing in this repo consumes, but the constraint
|
|
865
|
+
// itself is what makes ensureDefaultWorkspace's "INSERT … ON CONFLICT DO NOTHING then
|
|
866
|
+
// re-SELECT" race-safe. See the sqlite twin.
|
|
867
|
+
isDefault: boolean('is_default').notNull().default(false),
|
|
868
|
+
// The WORKSPACE half of the Pending mute (migration 0058 / pg 0045) — the pg twin. TRUE ⇒
|
|
869
|
+
// every repo in this workspace stops claiming the reader's turn (`getMyTurn` forces
|
|
870
|
+
// `relevance: 'none'`), while its rows and the broad `myTurn` count stay exactly where they
|
|
871
|
+
// are. A UNION with `pending_muted_repos`, never a parent of it; and NOT the dropped
|
|
872
|
+
// `repos.inbox_watch` visibility axis. Full rationale in the sqlite twin.
|
|
873
|
+
pendingMuted: boolean('pending_muted').notNull().default(false),
|
|
874
|
+
// Chronology's working hours and wait budgets (migration 0065 / pg 0052) — the pg twin.
|
|
875
|
+
// OVERRIDES ONLY, resolved through `resolveFlowSettings`. Full rationale in the sqlite twin.
|
|
876
|
+
flowSettings: jsonb('flow_settings').$type(),
|
|
877
|
+
// Auto Claude review (migration 0074 / pg 0061) — the pg twin. Full rationale in the sqlite twin.
|
|
878
|
+
autoReviewEnabled: boolean('auto_review_enabled'),
|
|
879
|
+
autoReviewEnabledAt: timestamp('auto_review_enabled_at', { withTimezone: true, mode: 'date' }),
|
|
880
|
+
createdAt: timestamp('created_at', { withTimezone: true, mode: 'date' })
|
|
881
|
+
.notNull()
|
|
882
|
+
.defaultNow(),
|
|
883
|
+
}, (t) => ({
|
|
884
|
+
accountNameUx: uniqueIndex('workspaces_account_name').on(t.accountId, t.name),
|
|
885
|
+
accountIdx: index('workspaces_account_idx').on(t.accountId),
|
|
886
|
+
// NOT a lookup index — `id` is already the PK. It is the PARENT KEY of the composite FKs on
|
|
887
|
+
// workspace_repos and workspace_reviewers, exactly as `repos_id_account` is for those tables'
|
|
888
|
+
// repo FKs. Postgres accepts a plain unique index as a parent key (no named UNIQUE constraint
|
|
889
|
+
// required; verified on 16.13). Drop it and both composite FKs become unexpressible.
|
|
890
|
+
idAccountUx: uniqueIndex('workspaces_id_account').on(t.id, t.accountId),
|
|
891
|
+
}));
|
|
892
|
+
// EXACTLY ONE WORKSPACE PER REPO, AS A DATABASE FACT — the pg twin of schema.sqlite.ts
|
|
893
|
+
// workspaceRepos. The unique on (account_id, repo_id) makes reassignment an UPSERT, i.e. a MOVE;
|
|
894
|
+
// no code path can produce a second membership row. See the sqlite twin for why this is a join
|
|
895
|
+
// table rather than a `repos.workspace_id` column, and for the two sides that close the
|
|
896
|
+
// "repo with no membership row is invisible" gap (upsertRepo on write, ensureRepoMemberships on
|
|
897
|
+
// read). The workspace cascade is a SAFETY NET, not the delete path: deleteWorkspace moves the
|
|
898
|
+
// repos to Default inside its transaction first.
|
|
899
|
+
export const workspaceRepos = pgTable('workspace_repos', {
|
|
900
|
+
id: serial('id').primaryKey(),
|
|
901
|
+
accountId: integer('account_id')
|
|
902
|
+
.notNull()
|
|
903
|
+
.references(() => accounts.id, { onDelete: 'cascade' }),
|
|
904
|
+
// No single-column FKs: both are the COMPOSITE declarations below.
|
|
905
|
+
workspaceId: integer('workspace_id').notNull(),
|
|
906
|
+
repoId: integer('repo_id').notNull(),
|
|
907
|
+
createdAt: timestamp('created_at', { withTimezone: true, mode: 'date' })
|
|
908
|
+
.notNull()
|
|
909
|
+
.defaultNow(),
|
|
910
|
+
}, (t) => ({
|
|
911
|
+
// One workspace per repo, structurally. Also the upsert conflict target for
|
|
912
|
+
// assignReposToWorkspace.
|
|
913
|
+
accountRepoUx: uniqueIndex('workspace_repos_account_repo').on(t.accountId, t.repoId),
|
|
914
|
+
accountWorkspaceIdx: index('workspace_repos_account_workspace_idx').on(t.accountId, t.workspaceId),
|
|
915
|
+
repoIdx: index('workspace_repos_repo_idx').on(t.repoId),
|
|
916
|
+
// Tenancy as a constraint. `workspaceId` arrives in a REQUEST BODY, so a plain
|
|
917
|
+
// `REFERENCES workspaces(id)` would accept (account 2, workspace 10) where workspace 10
|
|
918
|
+
// belongs to account 1 — both halves individually valid. NAMED because Postgres quotes the
|
|
919
|
+
// name in the violation message and the hand-written migration spells the same
|
|
920
|
+
// `CONSTRAINT "workspace_repos_workspace_account_fk"`; an unnamed declaration would be
|
|
921
|
+
// auto-named `workspace_repos_workspace_id_account_id_fkey` and the name here would match
|
|
922
|
+
// nothing live.
|
|
923
|
+
workspaceAccountFk: foreignKey({
|
|
924
|
+
name: 'workspace_repos_workspace_account_fk',
|
|
925
|
+
columns: [t.workspaceId, t.accountId],
|
|
926
|
+
foreignColumns: [workspaces.id, workspaces.accountId],
|
|
927
|
+
}).onDelete('cascade'),
|
|
928
|
+
repoAccountFk: foreignKey({
|
|
929
|
+
name: 'workspace_repos_repo_account_fk',
|
|
930
|
+
columns: [t.repoId, t.accountId],
|
|
931
|
+
foreignColumns: [repos.id, repos.accountId],
|
|
932
|
+
}).onDelete('cascade'),
|
|
933
|
+
}));
|
|
934
|
+
// ---- The REPO half of the Pending mute (CORE, free) ---- the pg twin of schema.sqlite.ts
|
|
935
|
+
// pendingMutedRepos. PRESENCE IS THE FACT (one row per muted (account, repo); no flag column,
|
|
936
|
+
// no "considered" row). The effective answer is `workspaces.pending_muted OR a row here` — TWO
|
|
937
|
+
// INDEPENDENT FACTS UNIONED, never an inheritance chain, and there is deliberately no
|
|
938
|
+
// `workspace_id` column (a repo belongs to exactly one workspace; copying that fact here would
|
|
939
|
+
// give the account two answers to the same question). Full rationale, including why this is NOT
|
|
940
|
+
// the dropped `repos.inbox_watch` visibility axis, in the sqlite twin.
|
|
941
|
+
export const pendingMutedRepos = pgTable('pending_muted_repos', {
|
|
942
|
+
id: serial('id').primaryKey(),
|
|
943
|
+
accountId: integer('account_id')
|
|
944
|
+
.notNull()
|
|
945
|
+
.references(() => accounts.id, { onDelete: 'cascade' }),
|
|
946
|
+
// No single-column FK: it is the COMPOSITE declaration below.
|
|
947
|
+
repoId: integer('repo_id').notNull(),
|
|
948
|
+
createdAt: timestamp('created_at', { withTimezone: true, mode: 'date' })
|
|
949
|
+
.notNull()
|
|
950
|
+
.defaultNow(),
|
|
951
|
+
}, (t) => ({
|
|
952
|
+
accountRepoUx: uniqueIndex('pending_muted_repos_account_repo').on(t.accountId, t.repoId),
|
|
953
|
+
// Tenancy as a constraint: `repoId` arrives in a REQUEST BODY. NAMED because Postgres quotes
|
|
954
|
+
// the name in the violation message and the hand-written migration spells the same
|
|
955
|
+
// `CONSTRAINT "pending_muted_repos_repo_account_fk"`; an unnamed declaration would be
|
|
956
|
+
// auto-named `pending_muted_repos_repo_id_account_id_fkey` and the name here would match
|
|
957
|
+
// nothing live.
|
|
958
|
+
repoAccountFk: foreignKey({
|
|
959
|
+
name: 'pending_muted_repos_repo_account_fk',
|
|
960
|
+
columns: [t.repoId, t.accountId],
|
|
961
|
+
foreignColumns: [repos.id, repos.accountId],
|
|
962
|
+
}).onDelete('cascade'),
|
|
963
|
+
}));
|
|
964
|
+
// ---- My Turn dismissals — see schema.sqlite.ts for the contract. ----
|
|
965
|
+
export const myTurnDismissals = pgTable('my_turn_dismissals', {
|
|
966
|
+
id: serial('id').primaryKey(),
|
|
967
|
+
accountId: integer('account_id')
|
|
968
|
+
.notNull()
|
|
969
|
+
.references(() => accounts.id, { onDelete: 'cascade' }),
|
|
970
|
+
prId: integer('pr_id'),
|
|
971
|
+
repoId: integer('repo_id'),
|
|
972
|
+
dismissedAt: timestamp('dismissed_at', { withTimezone: true, mode: 'date' }).notNull(),
|
|
973
|
+
}, (t) => ({
|
|
974
|
+
accountPrUx: uniqueIndex('my_turn_dismissals_account_pr').on(t.accountId, t.prId),
|
|
975
|
+
accountRepoUx: uniqueIndex('my_turn_dismissals_account_repo').on(t.accountId, t.repoId),
|
|
976
|
+
// NAMED, so the hand-written migration's CONSTRAINT names match what is live.
|
|
977
|
+
prAccountFk: foreignKey({
|
|
978
|
+
name: 'my_turn_dismissals_pr_account_fk',
|
|
979
|
+
columns: [t.prId, t.accountId],
|
|
980
|
+
foreignColumns: [pullRequests.id, pullRequests.accountId],
|
|
981
|
+
}).onDelete('cascade'),
|
|
982
|
+
repoAccountFk: foreignKey({
|
|
983
|
+
name: 'my_turn_dismissals_repo_account_fk',
|
|
984
|
+
columns: [t.repoId, t.accountId],
|
|
985
|
+
foreignColumns: [repos.id, repos.accountId],
|
|
986
|
+
}).onDelete('cascade'),
|
|
987
|
+
}));
|
|
988
|
+
// ---- Bot-Triage Platform (WS1 / WS6) ----
|
|
989
|
+
// THE BOT OBJECT: one row per (account, WORKSPACE, actor) — the pg twin of schema.sqlite.ts
|
|
990
|
+
// workspaceReviewers. It replaces BOTH `repo_reviewers` (judgement, per repo) and
|
|
991
|
+
// `account_reviewers` (identity + price, per account): with one workspace as the only scope both
|
|
992
|
+
// facts are about the same key, so a second table would key on the identical three columns.
|
|
993
|
+
//
|
|
994
|
+
// ⚠ THE TWO PROVENANCE FLAGS STAY SEPARATE COLUMNS and are honoured INDEPENDENTLY. `source` owns
|
|
995
|
+
// automated/role/confidence/reasons; `identity_source` owns kind/label. Inside one row that is
|
|
996
|
+
// code discipline (a narrowed `set:` object), not a table boundary — see the sqlite twin.
|
|
997
|
+
//
|
|
998
|
+
// ⚠ `monthly_cents` is in NO derived UPDATE. One writer (`setReviewerCost`), one row, keyed on
|
|
999
|
+
// (account_id, workspace_id, author_user_id). Price is a PER-WORKSPACE fact like every other
|
|
1000
|
+
// column here: no fan-out, no INSERT seed, and two workspaces may legitimately hold different
|
|
1001
|
+
// numbers. NULL = no price set, 0 = "recorded as free"; nothing inherits. `integer` CENTS in BOTH
|
|
1002
|
+
// dialects: `numeric` has no sqlite twin AND node-postgres hands it back as a STRING, breaking
|
|
1003
|
+
// the shared `number` wire type; the WIRE is DOLLARS, clamped to MAX_MONTHLY_CENTS. NEVER summed
|
|
1004
|
+
// ACROSS workspaces on one screen. Full rationale in the sqlite twin.
|
|
1005
|
+
export const workspaceReviewers = pgTable('workspace_reviewers', {
|
|
1006
|
+
id: serial('id').primaryKey(),
|
|
1007
|
+
accountId: integer('account_id')
|
|
1008
|
+
.notNull()
|
|
1009
|
+
.references(() => accounts.id, { onDelete: 'cascade' }),
|
|
1010
|
+
// No `.references()` here on purpose: the FK is the COMPOSITE one in the table config below,
|
|
1011
|
+
// `(workspace_id, account_id) → workspaces(id, account_id)`. See the sqlite twin.
|
|
1012
|
+
workspaceId: integer('workspace_id').notNull(),
|
|
1013
|
+
// No cascade: `users` is GLOBAL storage shared by every account and is never deleted.
|
|
1014
|
+
authorUserId: integer('author_user_id')
|
|
1015
|
+
.notNull()
|
|
1016
|
+
.references(() => users.id),
|
|
1017
|
+
// ── JUDGEMENT (owned by `source`) ──
|
|
1018
|
+
automated: boolean('automated').notNull(),
|
|
1019
|
+
// ReviewerRole — 'review' | 'quality_check' | 'dependency' | 'code_agent' | 'release' |
|
|
1020
|
+
// 'housekeeping'. A flag on this object, orthogonal to `kind`. The scoring sets narrow to
|
|
1021
|
+
// EXACTLY 'review'; see the sqlite twin for the full note and for migration 0053.
|
|
1022
|
+
role: text('role').notNull().default('review'),
|
|
1023
|
+
confidence: text('confidence').notNull(), // ClassificationConfidence — 'high'|'medium'|'low'
|
|
1024
|
+
source: text('source').notNull(), // ClassificationSource; 'manual' is never re-derived
|
|
1025
|
+
reasonsJson: jsonb('reasons_json').$type(),
|
|
1026
|
+
// ── IDENTITY (owned by `identity_source`) ──
|
|
1027
|
+
kind: text('kind'), // AutomatedReviewerKind | null
|
|
1028
|
+
label: text('label'), // human-set display name; null ⇒ brand name ⇒ login
|
|
1029
|
+
// Provenance of `kind` + `label` ONLY — a different field from `source`, sharing a row.
|
|
1030
|
+
identitySource: text('identity_source', { enum: ['auto', 'manual'] })
|
|
1031
|
+
.notNull()
|
|
1032
|
+
.default('auto'),
|
|
1033
|
+
// ── PRICE (owned by nothing derived; one writer only) ──
|
|
1034
|
+
monthlyCents: integer('monthly_cents'),
|
|
1035
|
+
// How `monthly_cents` is read: 'flat' = whole-workspace subscription; 'per_seat' = unit
|
|
1036
|
+
// price × derived seat count (product never stored). One writer (`setReviewerCost`).
|
|
1037
|
+
// See schema.sqlite.ts. Kept in sync by hand (schema-parity.test.ts).
|
|
1038
|
+
costModel: text('cost_model', { enum: ['flat', 'per_seat'] })
|
|
1039
|
+
.notNull()
|
|
1040
|
+
.default('flat'),
|
|
1041
|
+
updatedAt: timestamp('updated_at', { withTimezone: true, mode: 'date' })
|
|
1042
|
+
.notNull()
|
|
1043
|
+
.defaultNow(),
|
|
1044
|
+
}, (t) => ({
|
|
1045
|
+
// The upsert conflict target for EVERY writer. A stale target type-checks perfectly and
|
|
1046
|
+
// raises "no unique or exclusion constraint matching the ON CONFLICT specification" at
|
|
1047
|
+
// RUNTIME, only when a row is actually written.
|
|
1048
|
+
accountWorkspaceAuthorUx: uniqueIndex('workspace_reviewers_account_workspace_author').on(t.accountId, t.workspaceId, t.authorUserId),
|
|
1049
|
+
// Listing one workspace's reviewers (the Bots settings list).
|
|
1050
|
+
accountWorkspaceIdx: index('workspace_reviewers_account_workspace_idx').on(t.accountId, t.workspaceId),
|
|
1051
|
+
// Reaching every row of ONE actor across the account's workspaces.
|
|
1052
|
+
accountAuthorIdx: index('workspace_reviewers_account_author_idx').on(t.accountId, t.authorUserId),
|
|
1053
|
+
// Tenancy as a constraint: `workspace_id` arrives in a REQUEST BODY, and a single-column FK
|
|
1054
|
+
// would accept (account 2, workspace 10) where workspace 10 belongs to account 1. The
|
|
1055
|
+
// composite FK makes the PAIR the thing that must exist, and it needs the
|
|
1056
|
+
// `workspaces_id_account` unique index that exists for exactly this purpose. The `name` is
|
|
1057
|
+
// REAL — the hand-written migration spells `CONSTRAINT
|
|
1058
|
+
// "workspace_reviewers_workspace_account_fk"`, and Postgres quotes it in the violation.
|
|
1059
|
+
workspaceAccountFk: foreignKey({
|
|
1060
|
+
name: 'workspace_reviewers_workspace_account_fk',
|
|
1061
|
+
columns: [t.workspaceId, t.accountId],
|
|
1062
|
+
foreignColumns: [workspaces.id, workspaces.accountId],
|
|
1063
|
+
}).onDelete('cascade'),
|
|
1064
|
+
}));
|
|
1065
|
+
// NOTE: `repo_reviewers` + `account_reviewers` were the TWO-GRAIN bot store `workspace_reviewers`
|
|
1066
|
+
// replaces (judgement per repo; identity + price per actor). Both are DROPPED by pg migration
|
|
1067
|
+
// 0032 after their backfill — leaving either behind would leave a second, differently-keyed
|
|
1068
|
+
// answer to the same question in every database. No schema binding here on purpose.
|
|
1069
|
+
// NOTE: `bot_mute_rules` backed a removed feature (Pierre-only "hide" mute + the standing
|
|
1070
|
+
// auto-resolve cron) — dropped in favour of a strictly user-initiated, confirm-gated resolve.
|
|
1071
|
+
// No schema binding here on purpose; the pg baseline still creates the orphan table.
|
|
1072
|
+
// NOTE: `teams` + `team_repos` (the many-to-many grouping) are what `workspaces` +
|
|
1073
|
+
// `workspace_repos` above replace. Both are DROPPED by pg migration 0031, which preserves the
|
|
1074
|
+
// team IDS as workspace ids and gives every repo exactly one membership row. No schema binding
|
|
1075
|
+
// here on purpose.
|
|
1076
|
+
// ── Cross-org benchmark network (CORE, cloud-only, opt-in) ── the pg twin of the sqlite
|
|
1077
|
+
// benchmarkContributions table. See that file for the full rationale (aggregate-only, no PII,
|
|
1078
|
+
// in_house/pierre excluded, written only by the firewalled weekly rollup; serving is Phase 1).
|
|
1079
|
+
export const benchmarkContributions = pgTable('benchmark_contributions', {
|
|
1080
|
+
id: serial('id').primaryKey(),
|
|
1081
|
+
accountId: integer('account_id')
|
|
1082
|
+
.notNull()
|
|
1083
|
+
.references(() => accounts.id, { onDelete: 'cascade' }),
|
|
1084
|
+
vendorKind: text('vendor_kind').notNull(),
|
|
1085
|
+
weekStart: timestamp('week_start', { withTimezone: true, mode: 'date' }).notNull(),
|
|
1086
|
+
threads: integer('threads').notNull().default(0),
|
|
1087
|
+
comments: integer('comments').notNull().default(0),
|
|
1088
|
+
actedOn: integer('acted_on').notNull().default(0),
|
|
1089
|
+
untouched: integer('untouched').notNull().default(0),
|
|
1090
|
+
humanFollow: integer('human_follow').notNull().default(0),
|
|
1091
|
+
oldestUntouchedDays: integer('oldest_untouched_days'),
|
|
1092
|
+
orgSizeBucket: text('org_size_bucket').notNull(),
|
|
1093
|
+
mlMetrics: text('ml_metrics'),
|
|
1094
|
+
schemaVersion: integer('schema_version').notNull().default(1),
|
|
1095
|
+
createdAt: timestamp('created_at', { withTimezone: true, mode: 'date' })
|
|
1096
|
+
.notNull()
|
|
1097
|
+
.defaultNow(),
|
|
1098
|
+
}, (t) => ({
|
|
1099
|
+
uniq: uniqueIndex('bench_contrib_uniq').on(t.accountId, t.vendorKind, t.weekStart),
|
|
1100
|
+
accountIdx: index('bench_contrib_account_idx').on(t.accountId),
|
|
1101
|
+
cohortIdx: index('bench_contrib_cohort_idx').on(t.vendorKind, t.weekStart),
|
|
1102
|
+
}));
|
|
1103
|
+
// ── Cross-workspace full-text search index (CORE, no AI) ── the pg twin of the sqlite searchIndex
|
|
1104
|
+
// table. See that file for the full rationale (one row per searchable unit, accountId tenant anchor,
|
|
1105
|
+
// portable substring match, per-PR rebuild, cascading FKs). The (account_id, repo_id) btree already
|
|
1106
|
+
// bounds each search to one tenant's scoped rows; for cloud scale a `pg_trgm` GIN index on
|
|
1107
|
+
// lower(body) is a drop-in accelerator (`CREATE EXTENSION IF NOT EXISTS pg_trgm; CREATE INDEX …
|
|
1108
|
+
// USING gin (lower(body) gin_trgm_ops)`) — deliberately kept OUT of the migration so a permission-
|
|
1109
|
+
// locked Postgres can't fail startup; add it manually where the extension is available.
|
|
1110
|
+
export const searchIndex = pgTable('search_index', {
|
|
1111
|
+
id: serial('id').primaryKey(),
|
|
1112
|
+
accountId: integer('account_id')
|
|
1113
|
+
.notNull()
|
|
1114
|
+
.references(() => accounts.id, { onDelete: 'cascade' }),
|
|
1115
|
+
repoId: integer('repo_id')
|
|
1116
|
+
.notNull()
|
|
1117
|
+
.references(() => repos.id, { onDelete: 'cascade' }),
|
|
1118
|
+
prId: integer('pr_id')
|
|
1119
|
+
.notNull()
|
|
1120
|
+
.references(() => pullRequests.id, { onDelete: 'cascade' }),
|
|
1121
|
+
kind: text('kind', {
|
|
1122
|
+
enum: ['pr', 'review', 'review_comment', 'pr_comment'],
|
|
1123
|
+
}).notNull(),
|
|
1124
|
+
refId: integer('ref_id').notNull(),
|
|
1125
|
+
threadId: integer('thread_id'),
|
|
1126
|
+
authorId: integer('author_id').references(() => users.id),
|
|
1127
|
+
body: text('body').notNull(),
|
|
1128
|
+
createdAt: timestamp('created_at', { withTimezone: true, mode: 'date' }).notNull(),
|
|
1129
|
+
}, (t) => ({
|
|
1130
|
+
accountRepoIdx: index('search_account_repo_idx').on(t.accountId, t.repoId),
|
|
1131
|
+
prIdx: index('search_pr_idx').on(t.prId),
|
|
1132
|
+
}));
|
|
1133
|
+
// ── ML severity/category labels for BOT-authored text ── the pg twin of the sqlite
|
|
1134
|
+
// mlCommentLabels table. See that file for the full rationale (why accountId/repoId/prId/
|
|
1135
|
+
// authorUserId are denormalised, why target_id is not a foreign key, why cleanup rides the
|
|
1136
|
+
// cascading pr_id FK instead of the two hand-written delete paths). Contract: docs/ML-SEVERITY.md.
|
|
1137
|
+
export const mlCommentLabels = pgTable('ml_comment_labels', {
|
|
1138
|
+
id: serial('id').primaryKey(),
|
|
1139
|
+
accountId: integer('account_id')
|
|
1140
|
+
.notNull()
|
|
1141
|
+
.references(() => accounts.id, { onDelete: 'cascade' }),
|
|
1142
|
+
repoId: integer('repo_id')
|
|
1143
|
+
.notNull()
|
|
1144
|
+
.references(() => repos.id, { onDelete: 'cascade' }),
|
|
1145
|
+
prId: integer('pr_id')
|
|
1146
|
+
.notNull()
|
|
1147
|
+
.references(() => pullRequests.id, { onDelete: 'cascade' }),
|
|
1148
|
+
targetKind: text('target_kind', {
|
|
1149
|
+
enum: ['review_comment', 'pr_comment', 'review'],
|
|
1150
|
+
}).notNull(),
|
|
1151
|
+
targetId: integer('target_id').notNull(),
|
|
1152
|
+
authorUserId: integer('author_user_id')
|
|
1153
|
+
.notNull()
|
|
1154
|
+
.references(() => users.id),
|
|
1155
|
+
severity: text('severity', {
|
|
1156
|
+
enum: ['nit', 'minor', 'major', 'critical'],
|
|
1157
|
+
}).notNull(),
|
|
1158
|
+
severityOrd: integer('severity_ord').notNull(),
|
|
1159
|
+
severityProb: doublePrecision('severity_prob').notNull(),
|
|
1160
|
+
// The VENDOR'S own declared severity + the marker reader's confidence in it — kept beside
|
|
1161
|
+
// ours, never folded into it. Both nullable: most comments carry no vendor badge, and an
|
|
1162
|
+
// older severity-api omits the fields. Measurably less accurate than our own label
|
|
1163
|
+
// (0.474 exact / 0.697 ordinal MAE vs 0.700 / 0.303); stored only to be DISPLAYED next to
|
|
1164
|
+
// it. See the sqlite twin for the full argument.
|
|
1165
|
+
vendorSeverity: text('vendor_severity', {
|
|
1166
|
+
enum: ['nit', 'minor', 'major', 'critical'],
|
|
1167
|
+
}),
|
|
1168
|
+
vendorSeverityConfidence: text('vendor_severity_confidence', {
|
|
1169
|
+
enum: ['high', 'medium', 'low'],
|
|
1170
|
+
}),
|
|
1171
|
+
categories: jsonb('categories').$type().notNull(),
|
|
1172
|
+
categoryProbs: jsonb('category_probs').$type().notNull(),
|
|
1173
|
+
isSummary: boolean('is_summary').notNull(),
|
|
1174
|
+
backend: text('backend').notNull(),
|
|
1175
|
+
modelVersion: text('model_version').notNull(),
|
|
1176
|
+
bodyHash: text('body_hash').notNull(),
|
|
1177
|
+
targetCreatedAt: timestamp('target_created_at', {
|
|
1178
|
+
withTimezone: true,
|
|
1179
|
+
mode: 'date',
|
|
1180
|
+
}).notNull(),
|
|
1181
|
+
createdAt: timestamp('created_at', { withTimezone: true, mode: 'date' })
|
|
1182
|
+
.notNull()
|
|
1183
|
+
.defaultNow(),
|
|
1184
|
+
updatedAt: timestamp('updated_at', { withTimezone: true, mode: 'date' })
|
|
1185
|
+
.notNull()
|
|
1186
|
+
.defaultNow(),
|
|
1187
|
+
}, (t) => ({
|
|
1188
|
+
accountTargetUx: uniqueIndex('mcl_account_target').on(t.accountId, t.targetKind, t.targetId),
|
|
1189
|
+
accountPrIdx: index('mcl_account_pr_idx').on(t.accountId, t.prId),
|
|
1190
|
+
accountRepoAuthorIdx: index('mcl_account_repo_author_idx').on(t.accountId, t.repoId, t.authorUserId),
|
|
1191
|
+
}));
|
|
1192
|
+
// ── "@you" on a PR ── the pg twin of the sqlite prMentions table. See that file for the full
|
|
1193
|
+
// rationale (presence IS the fact, why it is a table and not a column on pull_requests, why
|
|
1194
|
+
// `login` is provenance rather than a denormalised copy of accounts.github_login). Written only
|
|
1195
|
+
// by sync/mention-scan.ts. Contract: docs/DATA-MODEL.md.
|
|
1196
|
+
export const prMentions = pgTable('pr_mentions', {
|
|
1197
|
+
id: serial('id').primaryKey(),
|
|
1198
|
+
accountId: integer('account_id')
|
|
1199
|
+
.notNull()
|
|
1200
|
+
.references(() => accounts.id, { onDelete: 'cascade' }),
|
|
1201
|
+
repoId: integer('repo_id')
|
|
1202
|
+
.notNull()
|
|
1203
|
+
.references(() => repos.id, { onDelete: 'cascade' }),
|
|
1204
|
+
prId: integer('pr_id')
|
|
1205
|
+
.notNull()
|
|
1206
|
+
.references(() => pullRequests.id, { onDelete: 'cascade' }),
|
|
1207
|
+
login: text('login').notNull(),
|
|
1208
|
+
// The newest non-automation, non-self mention's time and author; NULL = not stamped yet (no
|
|
1209
|
+
// card). See the sqlite twin.
|
|
1210
|
+
mentionedAt: timestamp('mentioned_at', { withTimezone: true, mode: 'date' }),
|
|
1211
|
+
mentionedByUserId: integer('mentioned_by_user_id'),
|
|
1212
|
+
createdAt: timestamp('created_at', { withTimezone: true, mode: 'date' })
|
|
1213
|
+
.notNull()
|
|
1214
|
+
.defaultNow(),
|
|
1215
|
+
}, (t) => ({
|
|
1216
|
+
accountPrUx: uniqueIndex('prm_account_pr').on(t.accountId, t.prId),
|
|
1217
|
+
accountRepoIdx: index('prm_account_repo_idx').on(t.accountId, t.repoId),
|
|
1218
|
+
prIdx: index('prm_pr_idx').on(t.prId),
|
|
1219
|
+
}));
|
|
1220
|
+
//# sourceMappingURL=schema.pg.js.map
|