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
components.tsx27.9 KB · 887 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
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
import type { FC } from "hono/jsx";
import { html } from "hono/html";
import type { GitCommit, GitTreeEntry, GitDiffFile } from "../git/repository";
import type { Repository } from "../db/schema";
import { parseDiff, pairLines } from "../lib/diff";
import type { DiffLine, ParsedFile, SplitRow } from "../lib/diff";

/**
 * Describes the most recent push to a repo, used by RepoHeader to render
 * the Push Watch discoverability indicator.
 *
 * - ageMs < 5 min  \u2192 pulsing red "\u25cf Live" badge
 * - ageMs < 24 hr  \u2192 dimmer "\u25cb Watch" link
 * - otherwise      \u2192 nothing shown
 */
export interface RecentPush {
  sha: string;
  ageMs: number;
}

export const RepoHeader: FC<{
  owner: string;
  repo: string;
  starCount?: number;
  starred?: boolean;
  forkCount?: number;
  currentUser?: string | null;
  forkedFrom?: string | null;
  archived?: boolean;
  isTemplate?: boolean;
  /** Most recent push info for Push Watch discoverability indicator. */
  recentPush?: RecentPush | null;
  /** 0-100 health score badge rendered after the repo name. Optional — omit to hide. */
  healthScore?: number;
}> = ({
  owner,
  repo,
  starCount,
  starred,
  forkCount,
  currentUser,
  forkedFrom,
  archived,
  isTemplate,
  recentPush,
  healthScore,
}) => {
  const FIVE_MIN = 5 * 60 * 1000;
  const TWENTY_FOUR_HR = 24 * 60 * 60 * 1000;
  const isLive = recentPush != null && recentPush.ageMs < FIVE_MIN;
  const isRecent = recentPush != null && recentPush.ageMs < TWENTY_FOUR_HR;

  const healthColor =
    healthScore === undefined ? null :
    healthScore >= 80 ? "#34d399" :
    healthScore >= 50 ? "#facc15" :
    "#f87171";

  return (
    <div class="repo-header">
      <div>
        <div class="repo-header-title">
          <a href={`/${owner}`} class="owner">
            {owner}
          </a>
          <span class="separator">/</span>
          <a href={`/${owner}/${repo}`} class="name">
            {repo}
          </a>
          {archived && (
            <span
              class="repo-header-pill repo-header-pill-archived"
              title="Read-only: pushes and new issues/PRs disabled"
            >
              Archived
            </span>
          )}
          {isTemplate && (
            <span
              class="repo-header-pill repo-header-pill-template"
              title="This repository can be used as a template"
            >
              Template
            </span>
          )}
          {healthScore !== undefined && healthColor && (
            <a
              href={`/${owner}/${repo}/health`}
              title={`Repository health score: ${healthScore}/100click for breakdown`}
              style={`display:inline-flex;align-items:center;gap:4px;padding:2px 8px;border-radius:9999px;font-size:11px;font-weight:700;text-decoration:none;color:${healthColor};background:${healthColor}22;border:1px solid ${healthColor}44;`}
            >
              &#x2665; Health {healthScore}
            </a>
          )}
          {isLive && recentPush && (
            <a
              href={`/${owner}/${repo}/push/${recentPush.sha}`}
              class="repo-header-live-badge repo-header-live-badge--live"
              title="Push in progress \u2014 watch live gate + deploy status"
              aria-label="Live push \u2014 click to watch status"
            >
              <span class="repo-header-live-dot" aria-hidden="true">{"\u25cf"}</span>
              Live
            </a>
          )}
          {!isLive && isRecent && recentPush && (
            <a
              href={`/${owner}/${repo}/push/${recentPush.sha}`}
              class="repo-header-live-badge repo-header-live-badge--recent"
              title="Watch the most recent push's gate + deploy results"
              aria-label="Watch most recent push"
            >
              <span aria-hidden="true">{"\u25cb"}</span>
              Watch
            </a>
          )}
        </div>
        {forkedFrom && (
          <div class="repo-header-fork">
            forked from <a href={`/${forkedFrom}`}>{forkedFrom}</a>
          </div>
        )}
      </div>
      <div class="repo-header-actions">
        {currentUser && currentUser !== owner && (
          <form method="post" action={`/${owner}/${repo}/fork`} style="display:inline">
            <button type="submit" class="star-btn">
              {"\u2442"} Fork {forkCount !== undefined && forkCount > 0 ? forkCount : ""}
            </button>
          </form>
        )}
        {starCount !== undefined && (
          currentUser ? (
            <form method="post" action={`/${owner}/${repo}/star`} style="display:inline">
              <button
                type="submit"
                class={`star-btn${starred ? " starred" : ""}`}
              >
                {starred ? "\u2605" : "\u2606"} {starCount}
              </button>
            </form>
          ) : (
            <span class="star-btn">
              {"\u2606"} {starCount}
            </span>
          )
        )}
      </div>
    </div>
  );
};

export const RepoNav: FC<{
  owner: string;
  repo: string;
  active:
    | "code"
    | "commits"
    | "issues"
    | "pulls"
    | "releases"
    | "actions"
    | "gates"
    | "insights"
    | "explain"
    | "changelog"
    | "semantic"
    | "wiki"
    | "projects"
    | "agents"
    | "discussions"
    | "security"
    | "settings"
    | "debt-map"
    | "migrate"
    | "deployments"
    | "nl-search"
    | "contributors"
    | "pulse"
    | "traffic"
    | "pipeline"
    | "workspace"
    | "archaeology";
  /** Current authenticated user — used for owner-only tab gating. */
  currentUser?: string | null;
  /** Repo owner username — used for owner-only tab gating. */
  repoOwner?: string;
}> = ({ owner, repo, active, currentUser, repoOwner }) => (
  <div class="repo-nav">
    <a href={`/${owner}/${repo}`} class={active === "code" ? "active" : ""}>
      Code
    </a>
    <a
      href={`/${owner}/${repo}/issues`}
      class={active === "issues" ? "active" : ""}
    >
      Issues
    </a>
    <a
      href={`/${owner}/${repo}/discussions`}
      class={active === "discussions" ? "active" : ""}
    >
      Discussions
    </a>
    <a
      href={`/${owner}/${repo}/wiki`}
      class={active === "wiki" ? "active" : ""}
    >
      Wiki
    </a>
    <a
      href={`/${owner}/${repo}/pulls`}
      class={active === "pulls" ? "active" : ""}
    >
      Pull Requests
    </a>
    <a
      href={`/${owner}/${repo}/projects`}
      class={active === "projects" ? "active" : ""}
    >
      Projects
    </a>
    <a
      href={`/${owner}/${repo}/commits`}
      class={active === "commits" ? "active" : ""}
    >
      Commits
    </a>
    <a
      href={`/${owner}/${repo}/actions`}
      class={active === "actions" ? "active" : ""}
    >
      Actions
    </a>
    <a
      href={`/${owner}/${repo}/releases`}
      class={active === "releases" ? "active" : ""}
    >
      Releases
    </a>
    <a
      href={`/${owner}/${repo}/contributors`}
      class={active === "contributors" ? "active" : ""}
    >
      Contributors
    </a>
    <a
      href={`/${owner}/${repo}/pulse`}
      class={active === "pulse" ? "active" : ""}
    >
      Pulse
    </a>
    {currentUser && repoOwner && currentUser === repoOwner && (
      <a
        href={`/${owner}/${repo}/traffic`}
        class={active === "traffic" ? "active" : ""}
      >
        Traffic
      </a>
    )}
    <a
      href={`/${owner}/${repo}/gates`}
      class={active === "gates" ? "active" : ""}
    >
      {"\u25CF"} Gates
    </a>
    <a
      href={`/${owner}/${repo}/security/vulnerabilities`}
      class={active === "security" ? "active" : ""}
    >
      Security
    </a>
    <a
      href={`/${owner}/${repo}/settings`}
      class={active === "settings" ? "active" : ""}
    >
      Settings
    </a>
    <a
      href={`/${owner}/${repo}/cloud-deployments`}
      class={active === "deployments" ? "active" : ""}
    >
      Deployments
    </a>
    <a
      href={`/${owner}/${repo}/pipeline`}
      class={active === "pipeline" ? "active" : ""}
    >
      Pipeline
    </a>
    <a
      href={`/${owner}/${repo}/insights`}
      class={active === "insights" ? "active" : ""}
    >
      Insights
    </a>
    <a
      href={`/${owner}/${repo}/agents`}
      class={active === "agents" ? "active" : ""}
    >
      Agents
    </a>
    <a
      href={`/${owner}/${repo}/explain`}
      class={`repo-nav-ai${active === "explain" ? " active" : ""}`}
      style="margin-left: auto"
    >
      {"\u2728"} Explain
    </a>
    <a href={`/${owner}/${repo}/ask`} class="repo-nav-ai">
      {"\u2728"} Ask AI
    </a>
    <a
      href={`/${owner}/${repo}/workspace`}
      class={`repo-nav-ai${active === "workspace" ? " active" : ""}`}
      title="AI Workspace — spec-to-PR, fix issues with AI, web editor"
    >
      {"✨"} Workspace
    </a>
    <a
      href={`/${owner}/${repo}/spec`}
      class="repo-nav-ai"
      title="Spec to PR — paste a feature spec, AI opens a draft PR"
    >
      {"\u2728"} Spec
    </a>
    <a
      href={`/${owner}/${repo}/ai/tests`}
      class="repo-nav-ai"
      title="AI Tests \u2014 generate failing test stubs from a source file"
    >
      {"\u2728"} Tests
    </a>
    <a
      href={`/${owner}/${repo}/debt-map`}
      class={`repo-nav-ai${active === "debt-map" ? " active" : ""}`}
      title="AI Debt Map \u2014 visual technical debt graph with Claude analysis"
    >
      {"\u2593"} Debt Map
    </a>
    <a
      href={`/${owner}/${repo}/search/nl`}
      class={`repo-nav-ai${active === "nl-search" ? " active" : ""}`}
      title="Natural Language Search \u2014 search by intent, not keywords"
    >
      {"\u2728"} NL Search
    </a>
    <a
      href={`/${owner}/${repo}/archaeology`}
      class={`repo-nav-ai${active === "archaeology" ? " active" : ""}`}
      title="AI Archaeology \u2014 excavate why any file exists using git history, PRs, and issues"
    >
      {"\ud83c\udfdb"} Archaeology
    </a>
  </div>
);

export const BranchSwitcher: FC<{
  owner: string;
  repo: string;
  currentRef: string;
  branches: string[];
  pathType: "tree" | "blob" | "commits";
  subPath?: string;
}> = ({ owner, repo, currentRef, branches, pathType, subPath }) => {
  if (branches.length <= 1) {
    return <div class="branch-selector">{currentRef}</div>;
  }

  return (
    <div class="branch-dropdown">
      <button class="branch-selector" type="button">
        {currentRef} &#9662;
      </button>
      <div class="branch-dropdown-content">
        {branches.map((branch) => {
          let href: string;
          if (pathType === "commits") {
            href = `/${owner}/${repo}/commits/${branch}`;
          } else if (subPath) {
            href = `/${owner}/${repo}/${pathType}/${branch}/${subPath}`;
          } else {
            href = `/${owner}/${repo}/tree/${branch}`;
          }
          return (
            <a
              href={href}
              class={branch === currentRef ? "active-branch" : ""}
            >
              {branch}
            </a>
          );
        })}
      </div>
    </div>
  );
};

export const Breadcrumb: FC<{
  owner: string;
  repo: string;
  ref: string;
  path: string;
}> = ({ owner, repo, ref, path }) => {
  const parts = path.split("/").filter(Boolean);
  const crumbs: { name: string; href: string }[] = [
    { name: repo, href: `/${owner}/${repo}/tree/${ref}` },
  ];
  let accumulated = "";
  for (const part of parts) {
    accumulated += (accumulated ? "/" : "") + part;
    crumbs.push({
      name: part,
      href: `/${owner}/${repo}/tree/${ref}/${accumulated}`,
    });
  }
  return (
    <div class="breadcrumb">
      {crumbs.map((crumb, i) => (
        <>
          {i > 0 && <span>/</span>}
          {i === crumbs.length - 1 ? (
            <strong>{crumb.name}</strong>
          ) : (
            <a href={crumb.href}>{crumb.name}</a>
          )}
        </>
      ))}
    </div>
  );
};

export const FileTable: FC<{
  entries: GitTreeEntry[];
  owner: string;
  repo: string;
  ref: string;
  path: string;
}> = ({ entries, owner, repo, ref, path }) => (
  <table class="file-table">
    <tbody>
      {entries.map((entry) => {
        const fullPath = path ? `${path}/${entry.name}` : entry.name;
        const href =
          entry.type === "tree"
            ? `/${owner}/${repo}/tree/${ref}/${fullPath}`
            : `/${owner}/${repo}/blob/${ref}/${fullPath}`;
        return (
          <tr>
            <td class="file-icon">
              {entry.type === "tree" ? "\u{1F4C1}" : "\u{1F4C4}"}
            </td>
            <td class="file-name">
              <a href={href}>{entry.name}</a>
            </td>
            <td style="text-align: right; color: var(--text-muted); font-size: 13px;">
              {entry.size !== undefined ? formatSize(entry.size) : ""}
            </td>
          </tr>
        );
      })}
    </tbody>
  </table>
);

export const HighlightedCode: FC<{
  highlightedHtml: string;
  lineCount: number;
}> = ({ highlightedHtml, lineCount }) => {
  const lineNums = Array.from({ length: lineCount }, (_, i) => i + 1);
  return (
    <div class="blob-code">
      <table>
        <tbody>
          <tr>
            <td class="line-num" style="vertical-align: top; padding-top: 0; padding-bottom: 0">
              <pre style="margin: 0; line-height: 1.6; font-size: 13px">
                {lineNums.map((n) => (
                  <>
                    <span>{n}</span>
                    {"\n"}
                  </>
                ))}
              </pre>
            </td>
            <td class="line-content" style="vertical-align: top; padding-top: 0; padding-bottom: 0">
              <pre style="margin: 0; line-height: 1.6; font-size: 13px">{html([highlightedHtml] as unknown as TemplateStringsArray)}</pre>
            </td>
          </tr>
        </tbody>
      </table>
    </div>
  );
};

export const PlainCode: FC<{ lines: string[] }> = ({ lines }) => (
  <div class="blob-code">
    <table>
      <tbody>
        {lines.map((line, i) => (
          <tr>
            <td class="line-num">{i + 1}</td>
            <td class="line-content">{line}</td>
          </tr>
        ))}
      </tbody>
    </table>
  </div>
);

export const CommitList: FC<{
  commits: GitCommit[];
  owner: string;
  repo: string;
  verifications?: Record<string, { verified: boolean; reason: string }>;
}> = ({ commits, owner, repo, verifications }) => (
  <div class="commit-list">
    {commits.map((commit) => {
      const v = verifications?.[commit.sha];
      return (
        <div class="commit-item">
          <div>
            <div class="commit-message">
              <a href={`/${owner}/${repo}/commit/${commit.sha}`}>
                {commit.message}
              </a>
              {v?.verified && (
                <a
                  href="/settings/signing-keys"
                  title="Signed with a registered key — manage your signing keys"
                  style="margin-left:8px;font-size:10px;padding:1px 6px;border-radius:3px;background:var(--green,#2ea043);color:#fff;text-transform:uppercase;letter-spacing:.4px;text-decoration:none"
                >
                  Verified
                </a>
              )}
            </div>
            <div class="commit-meta">
              {commit.author} committed {formatRelativeDate(commit.date)}
            </div>
          </div>
          <a
            href={`/${owner}/${repo}/commit/${commit.sha}`}
            class="commit-sha"
          >
            {commit.sha.slice(0, 7)}
          </a>
        </div>
      );
    })}
  </div>
);

// ---- Diff viewer ----------------------------------------------------------

const _diffScript = `
function diffToggleView(id,mode){
  var v=document.getElementById(id);if(!v)return;
  v.querySelectorAll('.diff-table-inline').forEach(function(t){t.hidden=(mode==='split');});
  v.querySelectorAll('.diff-table-split').forEach(function(t){t.hidden=(mode!=='split');});
  v.querySelectorAll('.diff-view-btn').forEach(function(b){b.classList.remove('active');});
  var btn=v.querySelector('.diff-view-btn-'+mode);if(btn)btn.classList.add('active');
}
function diffToggleFile(id){
  var body=document.getElementById(id);if(!body)return;
  body.hidden=!body.hidden;
  var hdr=body.previousElementSibling;if(hdr)hdr.classList.toggle('collapsed',body.hidden);
}
`;

export const DiffView: FC<{ raw: string; files: GitDiffFile[] }> = ({
  raw,
  files,
}) => {
  const parsed = parseDiff(raw);
  const totalAdd = files.reduce((s, f) => s + f.additions, 0);
  const totalDel = files.reduce((s, f) => s + f.deletions, 0);

  if (parsed.length === 0 && files.length === 0) {
    return (
      <div class="diff-view">
        <p style="color:var(--text-muted);font-size:14px">No changes.</p>
      </div>
    );
  }

  return (
    <div class="diff-view" id="diff-view-main">
      <script dangerouslySetInnerHTML={{ __html: _diffScript }} />

      {/* Toolbar */}
      <div class="diff-toolbar">
        <div class="diff-summary">
          <strong>{files.length}</strong> file{files.length !== 1 ? "s" : ""} changed,{" "}
          <span class="stat-add">+{totalAdd}</span>{" "}
          <span class="stat-del">-{totalDel}</span>
        </div>
        <div class="diff-view-toggle">
          <button class="diff-view-btn diff-view-btn-inline active" onclick="diffToggleView('diff-view-main','inline')" type="button">Inline</button>
          <button class="diff-view-btn diff-view-btn-split" onclick="diffToggleView('diff-view-main','split')" type="button">Split</button>
        </div>
      </div>

      {/* File jump list (shown when > 1 file) */}
      {parsed.length > 1 && (
        <div class="diff-jump-list">
          {parsed.map((f, i) => {
            const isAdd = f.additions > 0 && f.deletions === 0;
            const isDel = f.additions === 0 && f.deletions > 0;
            return (
              <a class="diff-jump-item" href={`#diff-file-${i}`}>
                <span class={isAdd ? "stat-add" : isDel ? "stat-del" : "diff-jump-mod"}>
                  {isAdd ? "+" : isDel ? "−" : "~"}
                </span>{" "}
                {f.path.split("/").pop() || f.path}
              </a>
            );
          })}
        </div>
      )}

      {/* Per-file blocks */}
      {parsed.map((file, idx) => {
        const bodyId = `diff-body-${idx}`;
        const splitRows = pairLines(file.lines);
        return (
          <div class="diff-file" id={`diff-file-${idx}`}>
            <div class="diff-file-header" onclick={`diffToggleFile('${bodyId}')`}>
              <span class="diff-file-path" title={file.path}>{file.path}</span>
              <span class="diff-file-meta">
                {file.isBinary
                  ? <span style="color:var(--text-muted)">binary</span>
                  : <><span class="stat-add">+{file.additions}</span>{" "}<span class="stat-del">-{file.deletions}</span></>
                }
                <span class="diff-file-chevron"></span>
              </span>
            </div>
            <div id={bodyId}>
              {file.isBinary ? (
                <div class="diff-binary">Binary file changed</div>
              ) : (
                <>
                  {/* Inline table (default) */}
                  <table class="diff-table diff-table-inline">
                    <tbody>
                      {file.lines.map((line) => {
                        if (line.type === "hunk") {
                          return (
                            <tr class="diff-row diff-row-hunk">
                              <td class="diff-ln diff-ln-old"></td>
                              <td class="diff-ln diff-ln-new"></td>
                              <td class="diff-cell">{line.content}</td>
                            </tr>
                          );
                        }
                        const sigil = line.type === "add" ? "+" : line.type === "del" ? "-" : " ";
                        return (
                          <tr class={`diff-row diff-row-${line.type}${line.wsOnly ? " diff-row-ws" : ""}`}>
                            <td class="diff-ln diff-ln-old">{line.oldLine ?? ""}</td>
                            <td class="diff-ln diff-ln-new">{line.newLine ?? ""}</td>
                            <td class="diff-cell">
                              <span class="diff-sigil">{sigil}</span>
                              {line.content}
                              {line.wsOnly && <span class="diff-ws-badge" title="whitespace-only change">ws</span>}
                            </td>
                          </tr>
                        );
                      })}
                    </tbody>
                  </table>
                  {/* Split table (hidden until toggled) */}
                  <table class="diff-table diff-table-split" hidden>
                    <tbody>
                      {splitRows.map((row) => {
                        const isHunk = row.left?.type === "hunk" || row.right?.type === "hunk";
                        if (isHunk) {
                          const hunk = row.left ?? row.right;
                          return (
                            <tr class="diff-row diff-row-hunk">
                              <td class="diff-ln diff-ln-old"></td>
                              <td class="diff-cell">{hunk?.content ?? ""}</td>
                              <td class="diff-ln diff-ln-new"></td>
                              <td class="diff-cell"></td>
                            </tr>
                          );
                        }
                        const isCtx = row.left?.type === "ctx";
                        const L = row.left;
                        const R = row.right;
                        const leftCls = `diff-cell${L ? (isCtx ? " diff-cell-ctx" : " diff-cell-del") : " diff-cell-empty"}${L?.wsOnly ? " diff-cell-ws" : ""}`;
                        const rightCls = `diff-cell${R ? (isCtx ? " diff-cell-ctx" : " diff-cell-add") : " diff-cell-empty"}${R?.wsOnly ? " diff-cell-ws" : ""}`;
                        return (
                          <tr class="diff-row diff-split-row">
                            <td class="diff-ln diff-ln-old">{L?.oldLine ?? ""}</td>
                            <td class={leftCls}>
                              {L && <span class="diff-sigil">{isCtx ? " " : "-"}</span>}
                              {L?.content ?? ""}
                              {L?.wsOnly && <span class="diff-ws-badge" title="whitespace-only change">ws</span>}
                            </td>
                            <td class="diff-ln diff-ln-new">{R?.newLine ?? ""}</td>
                            <td class={rightCls}>
                              {R && <span class="diff-sigil">{isCtx ? " " : "+"}</span>}
                              {isCtx ? L?.content ?? "" : R?.content ?? ""}
                              {R?.wsOnly && !isCtx && <span class="diff-ws-badge" title="whitespace-only change">ws</span>}
                            </td>
                          </tr>
                        );
                      })}
                    </tbody>
                  </table>
                </>
              )}
            </div>
          </div>
        );
      })}
    </div>
  );
};

export const RepoCard: FC<{ repo: Repository; ownerName: string }> = ({
  repo,
  ownerName,
}) => (
  <div class="card">
    <h3>
      <a href={`/${ownerName}/${repo.name}`}>{repo.name}</a>
    </h3>
    {repo.description && <p>{repo.description}</p>}
    <div class="card-meta">
      {repo.isPrivate && <span class="badge">Private</span>}
      <span>{"\u2606"} {repo.starCount}</span>
      {repo.pushedAt && (
        <span>Updated {formatRelativeDate(repo.pushedAt.toString())}</span>
      )}
    </div>
  </div>
);

function formatSize(bytes: number): string {
  if (bytes < 1024) return `${bytes} B`;
  if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
  return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
}

function formatRelativeDate(dateStr: string): string {
  const date = new Date(dateStr);
  const now = new Date();
  const diffMs = now.getTime() - date.getTime();
  const diffMins = Math.floor(diffMs / 60000);
  if (diffMins < 1) return "just now";
  if (diffMins < 60) return `${diffMins} minute${diffMins > 1 ? "s" : ""} ago`;
  const diffHours = Math.floor(diffMins / 60);
  if (diffHours < 24)
    return `${diffHours} hour${diffHours > 1 ? "s" : ""} ago`;
  const diffDays = Math.floor(diffHours / 24);
  if (diffDays < 30) return `${diffDays} day${diffDays > 1 ? "s" : ""} ago`;
  return date.toLocaleDateString("en-US", {
    month: "short",
    day: "numeric",
    year: "numeric",
  });
}

// ---------------------------------------------------------------------------
// CiFailureProfileCard — Phase 2 Human-Agent Canvas
// ---------------------------------------------------------------------------

export interface CiTraceIteration {
  iteration: number;
  modelRoute: string;
  errorDelta: string;
  tokenCost: number;
}

export interface CiFailureProfileProps {
  gateRunId: string;
  failureTarget: string;
  errorDelta: string;
  mitigationHint: string;
  traceLog: CiTraceIteration[];
}

export const CiFailureProfileCard: FC<CiFailureProfileProps> = ({
  gateRunId,
  failureTarget,
  errorDelta,
  mitigationHint,
  traceLog,
}) => (
  <div class="ci-failure-profile-card">
    <style>{`
      .ci-failure-profile-card {
        background: #1a1a2e;
        border: 1px solid #2d2d4a;
        border-radius: 8px;
        padding: 16px;
        margin: 12px 0;
        font-family: monospace;
        color: #e0e0ff;
      }
      .ci-failure-profile-card h3 {
        margin: 0 0 12px;
        color: #ff6b6b;
        font-size: 14px;
        text-transform: uppercase;
        letter-spacing: 0.5px;
      }
      .ci-failure-profile-card .field-label {
        color: #888;
        font-size: 11px;
        text-transform: uppercase;
        margin-top: 10px;
      }
      .ci-failure-profile-card .field-value {
        color: #e0e0ff;
        font-size: 13px;
        margin: 2px 0 6px;
        white-space: pre-wrap;
        word-break: break-word;
      }
      .ci-failure-profile-card .trace-row {
        display: grid;
        grid-template-columns: 40px 1fr 80px;
        gap: 8px;
        padding: 4px 0;
        border-bottom: 1px solid #2d2d4a;
        font-size: 12px;
      }
      .ci-failure-profile-card .feedback-row {
        margin-top: 14px;
        display: flex;
        gap: 8px;
      }
      .ci-failure-profile-card .btn-feedback {
        padding: 6px 12px;
        border: none;
        border-radius: 6px;
        cursor: pointer;
        font-size: 12px;
        font-weight: bold;
      }
      .ci-failure-profile-card .btn-helpful {
        background: #1a6b3c;
        color: #7fff9e;
      }
      .ci-failure-profile-card .btn-hallucination {
        background: #6b1a1a;
        color: #ff9e9e;
      }
    `}</style>
    <h3>🔍 CI Failure Profile</h3>
    <div class="field-label">Failure Target</div>
    <div class="field-value">{failureTarget}</div>
    <div class="field-label">Error Delta</div>
    <div class="field-value">{errorDelta}</div>
    <div class="field-label">Mitigation Hint</div>
    <div class="field-value">{mitigationHint}</div>
    {traceLog.length > 0 && (
      <>
        <div class="field-label" style="margin-top:12px">Model Trace</div>
        {traceLog.map((t) => (
          <div class="trace-row" key={t.iteration}>
            <span>#{t.iteration}</span>
            <span>{t.modelRoute}</span>
            <span>{t.tokenCost}¢</span>
          </div>
        ))}
      </>
    )}
    <div class="feedback-row">
      <form method="post" action="/api/flywheel-telemetry/feedback" style="display:inline">
        <input type="hidden" name="gateRunId" value={gateRunId} />
        <input type="hidden" name="verdict" value="helpful" />
        <button type="submit" class="btn-feedback btn-helpful">
          👍 Diagnostic Helpful
        </button>
      </form>
      <form method="post" action="/api/flywheel-telemetry/feedback" style="display:inline">
        <input type="hidden" name="gateRunId" value={gateRunId} />
        <input type="hidden" name="verdict" value="hallucination" />
        <button type="submit" class="btn-feedback btn-hallucination">
          👎 Hallucination Flagged
        </button>
      </form>
    </div>
  </div>
);