Pre-launch — Gluecron is in final validation. Public signups and git hosting for non-owner users open after launch review.
CodeIssuesDiscussionsWikiPull RequestsProjectsCommitsActionsReleasesContributorsPulse● GatesSecuritySettingsDeploymentsPipelineInsightsAgents✨ Explain✨ Ask AI✨ Workspace✨ Spec✨ Tests▓ Debt Map✨ NL Search🏛 Archaeology
claude/adoring-hopper-5x74bqclaude/affectionate-feynman-ykrf1hclaude/architecture-audit-design-wxprenclaude/build-status-update-3MXsfclaude/charming-meitner-mllb5rclaude/compare-gate-gluecron-s4mFQclaude/confident-faraday-tikcwbclaude/continue-work-XMTlIclaude/crontech-gluecron-deploy-7MIECclaude/crontech-platform-setup-SeKfwclaude/design-2026claude/ecstatic-ptolemy-jMdigclaude/enhance-github-integration-QNHdGclaude/fix-aa-loop-issue-PonMQclaude/fix-actions-and-processclaude/fix-desktop-errors-XqoW8claude/fix-red-workflowsclaude/fix-website-access-6FKJNclaude/gatetest-integration-hardeningclaude/github-audit-improvements-bDFr9claude/gluecron-launch-status-FoMRlclaude/hopeful-lamport-olfCTclaude/issue-to-pr-and-protectionsclaude/jolly-heisenberg-2sg1Qclaude/launch-preparation-QmTb6claude/new-session-xk1l7claude/plan-platform-architecture-kkN4yclaude/platform-analysis-roadmap-1nUGLclaude/platform-launch-assessment-8dWV8claude/polish-platform-release-AeDrUclaude/resume-previous-work-KzyLwclaude/review-crontech-handoff-qYEVqclaude/review-project-completeness-lHhS2claude/review-readme-docs-ulqPKclaude/serene-edison-rj87weclaude/setup-multi-repo-dev-BCwNQclaude/ship-fixes-and-tests-Jvz1cclaude/site-audit-competitive-pctlwgclaude/site-migration-vercel-XstpKclaude/standalone-product-repos-XHFTDcopilot/feat-smart-empty-states-keyboard-first-enhancementcopilot/feat-smart-morning-digest-review-context-restorecopilot/fix-and-process-workflowscopilot/update-ai-powered-code-reviewfeat/debt-mapfeat/push-policy-codeowners-hardeningfeat/smart-digest-contextfeat/stage-impactfeat/t1-secret-migrationfeat/u-polishfeat/w-self-hostfeat/w2-claude-configfix/agent-journey-orphan-sweepgatetest/auto-fix-1776586424172gatetest/auto-fix-1776586534814gatetest/auto-fix-1776590685143gatetest/auto-fix-1776590808199mainops/redeploy-retriggerstyle/dxt-cta-themeworktree-agent-a3377aad30d55da26worktree-agent-a7ef607b7ee1d6c74
migration-assistant.tsx22.6 KB · 719 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
/**
 * Major-version migration assistant UI.
 *
 *   GET  /:owner/:repo/migrations/propose           — picker form
 *   POST /:owner/:repo/migrations/propose           — drives proposeMajorMigration
 *
 * Owner-only. Renders the result inline (Claude's explanation + diff
 * preview + "Open PR" deep-link). Lives behind its own scoped `.migprop-*`
 * class system — does NOT touch layout/components/ui.
 */

import { Hono } from "hono";
import { and, eq } from "drizzle-orm";
import { db } from "../db";
import { repositories, users, pullRequests } from "../db/schema";
import { Layout } from "../views/layout";
import { RepoHeader } from "../views/components";
import { IssueNav } from "./issues";
import { softAuth, requireAuth } from "../middleware/auth";
import type { AuthEnv } from "../middleware/auth";
import {
  proposeMajorMigration,
  findManifest,
  type ProposeMigrationResult,
} from "../lib/migration-assistant";
import { parseManifest } from "../lib/dep-updater";
import { resolveRef } from "../git/repository";

const migrationAssistant = new Hono<AuthEnv>();

migrationAssistant.use("*", softAuth);

/* ──────────────────────────────────────────────────────────────────────
 * Scoped CSS — `.migprop-*`. Gradient hairline + orb hero, polished
 * form, result panel. Never overrides layout primitives.
 * ────────────────────────────────────────────────────────────────── */
const migpropStyles = `
  .migprop-wrap { max-width: 980px; margin: 0 auto; padding: var(--space-5) var(--space-4) var(--space-8); }

  .migprop-hero {
    position: relative;
    margin-bottom: var(--space-5);
    padding: var(--space-5) var(--space-6);
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 16px;
    overflow: hidden;
  }
  .migprop-hero::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 2px;
    background: linear-gradient(90deg, transparent 0%, #8c6dff 30%, #36c5d6 70%, transparent 100%);
    opacity: 0.7;
    pointer-events: none;
  }
  .migprop-hero-orb {
    position: absolute;
    inset: -20% -10% auto auto;
    width: 380px; height: 380px;
    background: radial-gradient(circle, rgba(140,109,255,0.20), rgba(54,197,214,0.10) 45%, transparent 70%);
    filter: blur(80px);
    opacity: 0.7;
    pointer-events: none;
    z-index: 0;
  }
  .migprop-hero-inner { position: relative; z-index: 1; }
  .migprop-eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    text-transform: uppercase;
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 0.16em;
    color: var(--text-muted);
    font-weight: 600;
    margin-bottom: 10px;
  }
  .migprop-eyebrow-dot {
    width: 8px; height: 8px;
    border-radius: 9999px;
    background: linear-gradient(135deg, #8c6dff, #36c5d6);
    box-shadow: 0 0 0 3px rgba(140,109,255,0.18);
  }
  .migprop-title {
    font-family: var(--font-display);
    font-size: clamp(28px, 4vw, 40px);
    font-weight: 800;
    letter-spacing: -0.028em;
    line-height: 1.05;
    margin: 0 0 var(--space-2);
    color: var(--text-strong);
  }
  .migprop-title-grad {
    background-image: linear-gradient(135deg, #a48bff 0%, #8c6dff 50%, #36c5d6 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    color: transparent;
  }
  .migprop-sub {
    font-size: 15px;
    color: var(--text-muted);
    margin: 0;
    line-height: 1.5;
    max-width: 640px;
  }
  .migprop-sub code {
    font-family: var(--font-mono);
    font-size: 13px;
    background: var(--bg-tertiary);
    padding: 1px 5px;
    border-radius: 4px;
  }

  /* ── Form card ── */
  .migprop-card {
    margin-bottom: var(--space-5);
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 14px;
    overflow: hidden;
    position: relative;
  }
  .migprop-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 2px;
    background: linear-gradient(90deg, transparent 0%, #8c6dff 30%, #36c5d6 70%, transparent 100%);
    opacity: 0.45;
    pointer-events: none;
  }
  .migprop-card-body { padding: var(--space-5) var(--space-5) var(--space-4); }
  .migprop-card-title {
    margin: 0 0 var(--space-2);
    font-family: var(--font-display);
    font-size: 16px;
    font-weight: 700;
    color: var(--text-strong);
    letter-spacing: -0.018em;
  }
  .migprop-card-sub {
    margin: 0 0 var(--space-4);
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.45;
  }

  .migprop-fields {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr;
    gap: var(--space-3);
    align-items: end;
  }
  @media (max-width: 720px) {
    .migprop-fields { grid-template-columns: 1fr; }
  }
  .migprop-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
  }
  .migprop-label {
    font-size: 12px;
    text-transform: uppercase;
    font-family: var(--font-mono);
    color: var(--text-muted);
    letter-spacing: 0.06em;
    font-weight: 600;
  }
  .migprop-input {
    font-family: var(--font-mono);
    font-size: 13px;
    padding: 9px 11px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-strong);
    line-height: 1.3;
    outline: none;
    transition: border-color 100ms ease, background 100ms ease;
  }
  .migprop-input:focus {
    border-color: rgba(140,109,255,0.55);
    background: var(--bg-secondary);
  }

  .migprop-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: var(--space-4);
    flex-wrap: wrap;
  }
  .migprop-cta {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 10px 18px;
    font-size: 13.5px;
    font-weight: 600;
    border-radius: 10px;
    border: 1px solid transparent;
    cursor: pointer;
    font: inherit;
    line-height: 1;
    white-space: nowrap;
    text-decoration: none;
    color: #ffffff;
    background: linear-gradient(135deg, #8c6dff 0%, #36c5d6 100%);
    box-shadow: 0 6px 18px -6px rgba(140,109,255,0.50), inset 0 1px 0 rgba(255,255,255,0.16);
    transition: transform 120ms ease, box-shadow 120ms ease;
  }
  .migprop-cta:hover {
    transform: translateY(-1px);
    box-shadow: 0 10px 24px -8px rgba(140,109,255,0.60), inset 0 1px 0 rgba(255,255,255,0.20);
    color: #ffffff;
    text-decoration: none;
  }
  .migprop-hint {
    font-size: 12px;
    color: var(--text-muted);
    font-family: var(--font-mono);
  }

  /* ── Result panel ── */
  .migprop-result {
    margin-top: var(--space-5);
    padding: var(--space-5);
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--bg-elevated);
    position: relative;
    overflow: hidden;
  }
  .migprop-result::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 2px;
    background: linear-gradient(90deg, transparent 0%, #6ee7b7 30%, #36c5d6 70%, transparent 100%);
    opacity: 0.55;
  }
  .migprop-result-title {
    font-family: var(--font-display);
    font-size: 18px;
    font-weight: 700;
    color: var(--text-strong);
    margin: 10px 0 6px;
  }
  .migprop-result-sub {
    margin: 0 0 var(--space-4);
    font-size: 13px;
    color: var(--text-muted);
  }
  .migprop-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 9px;
    border-radius: 9999px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    background: rgba(110,231,183,0.14);
    color: #6ee7b7;
    box-shadow: inset 0 0 0 1px rgba(110,231,183,0.32);
  }
  .migprop-pill.is-error {
    background: rgba(248,113,113,0.14);
    color: #fca5a5;
    box-shadow: inset 0 0 0 1px rgba(248,113,113,0.32);
  }
  .migprop-explanation {
    margin: 0 0 var(--space-4);
    padding: var(--space-3);
    background: rgba(255,255,255,0.025);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 13.5px;
    line-height: 1.55;
    color: var(--text);
    white-space: pre-wrap;
  }
  .migprop-meta {
    font-family: var(--font-mono);
    font-size: 12.5px;
    color: var(--text-muted);
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
    margin-bottom: var(--space-3);
  }
  .migprop-meta code {
    font-family: var(--font-mono);
    background: var(--bg-tertiary);
    padding: 2px 7px;
    border-radius: 5px;
    border: 1px solid var(--border);
  }

  .migprop-notice {
    max-width: 540px;
    margin: var(--space-12) auto;
    padding: var(--space-6);
    text-align: center;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 16px;
  }
  .migprop-notice h2 {
    font-family: var(--font-display);
    font-size: 22px;
    margin: 0 0 8px;
    color: var(--text-strong);
  }
  .migprop-notice p { color: var(--text-muted); margin: 0; font-size: 14px; }
`;

/**
 * Resolve repo row + enforce owner-only access. Mirrors the helper in
 * dep-updater.tsx so the two routes have identical permission semantics.
 */
async function resolveOwnerRepo(
  c: any,
  ownerName: string,
  repoName: string
): Promise<
  | { kind: "ok"; repo: typeof repositories.$inferSelect }
  | { kind: "response"; res: Response }
> {
  const user = c.get("user");
  if (!user) {
    return {
      kind: "response",
      res: c.redirect(`/login?redirect=${encodeURIComponent(c.req.path)}`),
    };
  }
  try {
    const [owner] = await db
      .select()
      .from(users)
      .where(eq(users.username, ownerName))
      .limit(1);
    if (!owner) return { kind: "response", res: c.notFound() };
    if (owner.id !== user.id) {
      return {
        kind: "response",
        res: c.html(
          <Layout title="Unauthorized" user={user}>
            <div class="migprop-wrap">
              <div class="migprop-notice">
                <h2>Unauthorized</h2>
                <p>Only the repository owner can request a migration plan.</p>
              </div>
            </div>
            <style dangerouslySetInnerHTML={{ __html: migpropStyles }} />
          </Layout>,
          403
        ),
      };
    }
    const [repo] = await db
      .select()
      .from(repositories)
      .where(
        and(
          eq(repositories.ownerId, owner.id),
          eq(repositories.name, repoName)
        )
      )
      .limit(1);
    if (!repo) return { kind: "response", res: c.notFound() };
    return { kind: "ok", repo };
  } catch {
    return {
      kind: "response",
      res: c.html(
        <Layout title="Error" user={user}>
          <div class="migprop-wrap">
            <div class="migprop-notice">
              <h2>Service unavailable</h2>
              <p>The migration assistant is temporarily offline.</p>
            </div>
          </div>
          <style dangerouslySetInnerHTML={{ __html: migpropStyles }} />
        </Layout>,
        503
      ),
    };
  }
}

/**
 * Pull the manifest off the default branch + return a flat list of
 * declared deps for the autocomplete datalist. Failure is non-fatal —
 * the form still renders, just with an empty datalist.
 */
async function listDeclaredDeps(
  owner: string,
  name: string,
  branch: string
): Promise<Array<{ name: string; range: string; kind: "dep" | "dev" }>> {
  try {
    const baseSha = await resolveRef(owner, name, branch);
    if (!baseSha) return [];
    const manifest = await findManifest(owner, name, baseSha);
    if (!manifest || manifest.path !== "package.json") return [];
    const parsed = parseManifest(manifest.content);
    const all: Array<{ name: string; range: string; kind: "dep" | "dev" }> = [];
    for (const [n, r] of Object.entries(parsed.dependencies || {})) {
      all.push({ name: n, range: r, kind: "dep" });
    }
    for (const [n, r] of Object.entries(parsed.devDependencies || {})) {
      all.push({ name: n, range: r, kind: "dev" });
    }
    return all;
  } catch {
    return [];
  }
}

function HeroBlock({
  ownerName,
  repoName,
  dep,
}: {
  ownerName: string;
  repoName: string;
  dep?: string;
}) {
  return (
    <section class="migprop-hero">
      <div class="migprop-hero-orb" aria-hidden="true" />
      <div class="migprop-hero-inner">
        <div class="migprop-eyebrow">
          <span class="migprop-eyebrow-dot" aria-hidden="true" />
          {ownerName}/{repoName} · Migration assistant
        </div>
        <h1 class="migprop-title">
          <span class="migprop-title-grad">
            {dep ? `Migrate ${dep}` : "Migrate a dependency"}
          </span>
        </h1>
        <p class="migprop-sub">
          Tell us which package to upgrade and to which major. Claude reads
          your manifest + call-sites, drafts the upgrade as a PR, and
          updates tests along with the source.
        </p>
      </div>
    </section>
  );
}

// ─────────────────────────────────────────────────────────────────────────
// GET — form
// ─────────────────────────────────────────────────────────────────────────

migrationAssistant.get(
  "/:owner/:repo/migrations/propose",
  requireAuth,
  async (c) => {
    const { owner: ownerName, repo: repoName } = c.req.param();
    const resolved = await resolveOwnerRepo(c, ownerName, repoName);
    if (resolved.kind === "response") return resolved.res;
    const { repo } = resolved;
    const user = c.get("user")!;

    const branch = repo.defaultBranch || "main";
    const declared = await listDeclaredDeps(ownerName, repoName, branch);
    const prefill = c.req.query("dep") || "";

    return c.html(
      <Layout title={`Migrate dep — ${ownerName}/${repoName}`} user={user}>
        <RepoHeader owner={ownerName} repo={repoName} />
        <IssueNav owner={ownerName} repo={repoName} active="code" />
        <div class="migprop-wrap">
          <HeroBlock ownerName={ownerName} repoName={repoName} dep={prefill} />
          <section class="migprop-card">
            <div class="migprop-card-body">
              <h2 class="migprop-card-title">Get a migration plan</h2>
              <p class="migprop-card-sub">
                We'll detect uses in your tree, ask Claude for a patch set,
                and (if it returns one) open a PR labeled{" "}
                <code>ai:major-migration</code>. Server must have an{" "}
                <code>ANTHROPIC_API_KEY</code> configured.
              </p>
              <form
                method="post"
                action={`/${ownerName}/${repoName}/migrations/propose`}
              >
                <div class="migprop-fields">
                  <div class="migprop-field">
                    <label class="migprop-label" for="migprop-dep">
                      Dependency
                    </label>
                    <input
                      id="migprop-dep"
                      class="migprop-input"
                      type="text"
                      name="dependency"
                      list="migprop-deplist"
                      placeholder="hono"
                      value={prefill}
                      required
                      autocomplete="off"
                    />
                    <datalist id="migprop-deplist">
                      {declared.map((d) => (
                        <option value={d.name}>
                          {d.range} ({d.kind})
                        </option>
                      ))}
                    </datalist>
                  </div>
                  <div class="migprop-field">
                    <label class="migprop-label" for="migprop-from">
                      From
                    </label>
                    <input
                      id="migprop-from"
                      class="migprop-input"
                      type="text"
                      name="fromVersion"
                      placeholder="^3.0.0"
                      required
                    />
                  </div>
                  <div class="migprop-field">
                    <label class="migprop-label" for="migprop-to">
                      To
                    </label>
                    <input
                      id="migprop-to"
                      class="migprop-input"
                      type="text"
                      name="toVersion"
                      placeholder="4.0.0"
                      required
                    />
                  </div>
                </div>
                <div class="migprop-actions">
                  <button type="submit" class="migprop-cta">
                    Get migration plan
                  </button>
                  <span class="migprop-hint">
                    Opens a PR on success. Bypasses the 7-day throttle.
                  </span>
                </div>
              </form>
            </div>
          </section>
        </div>
        <style dangerouslySetInnerHTML={{ __html: migpropStyles }} />
      </Layout>
    );
  }
);

// ─────────────────────────────────────────────────────────────────────────
// POST — run the assistant + render the result inline
// ─────────────────────────────────────────────────────────────────────────

migrationAssistant.post(
  "/:owner/:repo/migrations/propose",
  requireAuth,
  async (c) => {
    const { owner: ownerName, repo: repoName } = c.req.param();
    const resolved = await resolveOwnerRepo(c, ownerName, repoName);
    if (resolved.kind === "response") return resolved.res;
    const { repo } = resolved;
    const user = c.get("user")!;

    const form = await c.req.parseBody();
    const dependency = String(form.dependency ?? "").trim();
    const fromVersion = String(form.fromVersion ?? "").trim();
    const toVersion = String(form.toVersion ?? "").trim();

    const renderError = (msg: string) =>
      c.html(
        <Layout title={`Migrate dep — ${ownerName}/${repoName}`} user={user}>
          <RepoHeader owner={ownerName} repo={repoName} />
          <IssueNav owner={ownerName} repo={repoName} active="code" />
          <div class="migprop-wrap">
            <HeroBlock
              ownerName={ownerName}
              repoName={repoName}
              dep={dependency}
            />
            <section class="migprop-result">
              <span class="migprop-pill is-error">Failed</span>
              <h2 class="migprop-result-title">
                Could not generate a migration plan
              </h2>
              <p class="migprop-result-sub">{msg}</p>
              <a
                class="migprop-cta"
                href={`/${ownerName}/${repoName}/migrations/propose`}
              >
                Try again
              </a>
            </section>
          </div>
          <style dangerouslySetInnerHTML={{ __html: migpropStyles }} />
        </Layout>
      );

    if (!dependency || !fromVersion || !toVersion) {
      return renderError("All three fields are required.");
    }

    const branch = repo.defaultBranch || "main";
    const baseSha = await resolveRef(ownerName, repoName, branch);
    if (!baseSha) {
      return renderError(
        `Could not resolve the default branch (\`${branch}\`).`
      );
    }

    let result: ProposeMigrationResult | null = null;
    try {
      result = await proposeMajorMigration({
        repositoryId: repo.id,
        dependency,
        fromVersion,
        toVersion,
        baseSha,
        // UI users explicitly want the migration; bypass the watcher's
        // 7-day cool-down.
        skipThrottle: true,
      });
    } catch (err) {
      console.error("[migrations] propose threw:", err);
      return renderError(
        "The migration assistant encountered an unexpected error."
      );
    }

    if (!result) {
      return renderError(
        "Claude did not return a usable patch. This usually means the model couldn't find safe, mechanical changes — try narrowing the scope or set ANTHROPIC_API_KEY if the server is missing it."
      );
    }

    // Look up the PR body so we can preview the explanation inline.
    let explanation = "";
    try {
      const [pr] = await db
        .select({ body: pullRequests.body })
        .from(pullRequests)
        .where(
          and(
            eq(pullRequests.repositoryId, repo.id),
            eq(pullRequests.number, result.prNumber)
          )
        )
        .limit(1);
      if (pr?.body) {
        // Extract the "### Summary" block. Best-effort — fall back to the
        // entire body when the marker isn't found.
        const match = pr.body.match(/### Summary\n([\s\S]*?)\n\n###/);
        explanation = match ? match[1].trim() : pr.body;
      }
    } catch {
      // ignore — we can still render the success page.
    }

    return c.html(
      <Layout title={`Migrate dep — ${ownerName}/${repoName}`} user={user}>
        <RepoHeader owner={ownerName} repo={repoName} />
        <IssueNav owner={ownerName} repo={repoName} active="code" />
        <div class="migprop-wrap">
          <HeroBlock
            ownerName={ownerName}
            repoName={repoName}
            dep={dependency}
          />
          <section class="migprop-result">
            <span class="migprop-pill">PR opened</span>
            <h2 class="migprop-result-title">Migration plan ready</h2>
            <p class="migprop-result-sub">
              Claude proposed a patch set for <code>{dependency}</code>{" "}
              {fromVersion} → {toVersion}. Review the diff and merge if the
              call-sites look right.
            </p>
            <div class="migprop-meta">
              <span>
                Branch: <code>{result.branch}</code>
              </span>
              <span>
                Base: <code>{branch}</code>
              </span>
              <span>
                PR: <code>#{result.prNumber}</code>
              </span>
            </div>
            {explanation ? (
              <div class="migprop-explanation">{explanation}</div>
            ) : null}
            <a
              class="migprop-cta"
              href={`/${ownerName}/${repoName}/pulls/${result.prNumber}`}
            >
              Open PR #{result.prNumber}
            </a>
          </section>
        </div>
        <style dangerouslySetInnerHTML={{ __html: migpropStyles }} />
      </Layout>
    );
  }
);

export default migrationAssistant;