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
org-health.tsx16.7 KB · 548 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
/**
 * Org-level team health dashboard.
 *
 *   GET  /orgs/:slug/health            — ranked health page (worst-first)
 *   POST /orgs/:slug/health/recompute  — invalidate caches + redirect
 *
 * Reuses `computeOrgHealth` from src/lib/org-health.ts and the
 * `getHealthScore` signal breakdown already built in src/lib/repo-health.ts.
 * No new tables — leverages repo_health_cache + bus_factor_cache etc.
 */

import { Hono } from "hono";
import { eq, and } from "drizzle-orm";
import { db } from "../db";
import { organizations, orgMembers } from "../db/schema";
import { Layout } from "../views/layout";
import { softAuth, requireAuth } from "../middleware/auth";
import type { AuthEnv } from "../middleware/auth";
import {
  computeOrgHealth,
  invalidateOrgHealthAndRepos,
  type OrgRepoHealth,
} from "../lib/org-health";
import { loadOrgForUser, orgRoleAtLeast } from "../lib/orgs";

const orgHealthRoutes = new Hono<AuthEnv>();
orgHealthRoutes.use("*", softAuth);

// ---------------------------------------------------------------------------
// Helpers
// ---------------------------------------------------------------------------

function scoreColor(score: number): string {
  if (score >= 80) return "#34d399";
  if (score >= 50) return "#fbbf24";
  return "#f87171";
}

function scorePillClass(score: number): string {
  if (score >= 80) return "oh-pill--good";
  if (score >= 50) return "oh-pill--warn";
  return "oh-pill--bad";
}

function trendArrow(trend: "up" | "down" | "stable"): string {
  if (trend === "up") return "↑";
  if (trend === "down") return "↓";
  return "→";
}

function trendClass(trend: "up" | "down" | "stable"): string {
  if (trend === "up") return "oh-trend--up";
  if (trend === "down") return "oh-trend--down";
  return "oh-trend--stable";
}

function badgeStyle(score: number): string {
  const color = scoreColor(score);
  return `background:rgba(0,0,0,0.25);color:${color};border:1px solid ${color}40;padding:2px 6px;border-radius:4px;font-size:11px;font-family:var(--font-mono);font-weight:600`;
}

// ---------------------------------------------------------------------------
// Scoped CSS — every class prefixed `.oh-`
// ---------------------------------------------------------------------------

const styles = `
  .oh-wrap { max-width: 1680px; margin: 0 auto; padding: var(--space-5) var(--space-4); }

  /* Hero */
  .oh-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;
  }
  .oh-hero::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 2px;
    background: linear-gradient(90deg, transparent 0%, #34d399 30%, #fbbf24 70%, transparent 100%);
    opacity: 0.75;
    pointer-events: none;
  }
  .oh-hero-orb {
    position: absolute;
    inset: -30% -15% auto auto;
    width: 420px; height: 420px;
    background: radial-gradient(circle, rgba(52,211,153,0.18), rgba(251,191,36,0.08) 45%, transparent 70%);
    filter: blur(80px);
    opacity: 0.6;
    pointer-events: none;
    z-index: 0;
  }
  .oh-hero-inner {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-4);
    flex-wrap: wrap;
  }
  .oh-hero-text { max-width: 720px; }
  .oh-eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    text-transform: uppercase;
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 0.18em;
    color: var(--text-muted);
    font-weight: 600;
    margin-bottom: 14px;
  }
  .oh-eyebrow-dot {
    width: 8px; height: 8px;
    border-radius: 9999px;
    background: linear-gradient(135deg, #34d399, #fbbf24);
    box-shadow: 0 0 0 3px rgba(52,211,153,0.18);
  }
  .oh-title {
    font-family: var(--font-display);
    font-size: clamp(26px, 4vw, 38px);
    font-weight: 800;
    letter-spacing: -0.025em;
    line-height: 1.05;
    margin: 0 0 var(--space-2);
    color: var(--text-strong);
  }
  .oh-title-grad {
    background-image: linear-gradient(135deg, #6ee7b7 0%, #34d399 50%, #fbbf24 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    color: transparent;
  }
  .oh-sub {
    font-size: 15px;
    color: var(--text-muted);
    margin: 0;
    line-height: 1.55;
  }
  .oh-back {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: 10px;
    border: 1px solid var(--border-strong, var(--border));
    background: transparent;
    color: var(--text);
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    transition: background 120ms ease, border-color 120ms ease;
    white-space: nowrap;
  }
  .oh-back:hover {
    background: rgba(52,211,153,0.06);
    border-color: rgba(52,211,153,0.45);
    text-decoration: none;
  }

  /* Avg score pill */
  .oh-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 64px; height: 64px;
    border-radius: 9999px;
    font-family: var(--font-display);
    font-size: 22px;
    font-weight: 800;
    border: 3px solid;
    margin-top: 14px;
    font-variant-numeric: tabular-nums;
  }
  .oh-pill--good { color: #34d399; border-color: rgba(52,211,153,0.5); background: rgba(52,211,153,0.08); }
  .oh-pill--warn { color: #fbbf24; border-color: rgba(251,191,36,0.5); background: rgba(251,191,36,0.08); }
  .oh-pill--bad  { color: #f87171; border-color: rgba(248,113,113,0.5); background: rgba(248,113,113,0.08); }

  /* AI summary card */
  .oh-ai-card {
    margin-bottom: var(--space-5);
    padding: var(--space-4) var(--space-5);
    background: rgba(59,130,246,0.05);
    border: 1px solid rgba(59,130,246,0.3);
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.65;
    color: var(--text);
    white-space: pre-wrap;
  }
  .oh-ai-label {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: #93c5fd;
    margin-bottom: var(--space-2);
  }
  .oh-ai-dot {
    width: 6px; height: 6px;
    border-radius: 9999px;
    background: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59,130,246,0.2);
  }

  /* Repo table */
  .oh-table-wrap {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 14px;
    overflow: hidden;
    margin-bottom: var(--space-5);
  }
  .oh-table-head {
    padding: var(--space-3) var(--space-4);
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
    gap: var(--space-2);
  }
  .oh-table-title {
    margin: 0;
    font-family: var(--font-display);
    font-size: 16px;
    font-weight: 700;
    letter-spacing: -0.015em;
    color: var(--text-strong);
  }
  .oh-table-sub { font-size: 12px; color: var(--text-muted); }
  table.oh-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
  }
  .oh-table th {
    padding: 10px 14px;
    text-align: left;
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
  }
  .oh-table td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
  }
  .oh-table tr:last-child td { border-bottom: none; }
  .oh-table tr:hover td { background: rgba(255,255,255,0.02); }
  .oh-rank {
    width: 28px; height: 28px;
    border-radius: 8px;
    background: rgba(140,109,255,0.10);
    color: #b69dff;
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: inset 0 0 0 1px rgba(140,109,255,0.28);
  }
  .oh-repo-link {
    color: var(--text-strong);
    font-weight: 600;
    text-decoration: none;
    font-size: 13.5px;
  }
  .oh-repo-link:hover { color: var(--accent); }

  /* Score bar */
  .oh-bar-track {
    width: 120px;
    height: 6px;
    background: rgba(255,255,255,0.08);
    border-radius: 3px;
    overflow: hidden;
    display: inline-block;
    vertical-align: middle;
    margin-right: 8px;
  }

  /* Trend arrows */
  .oh-trend--up    { color: #34d399; font-weight: 700; }
  .oh-trend--down  { color: #f87171; font-weight: 700; }
  .oh-trend--stable { color: var(--text-muted); }

  /* Recompute button */
  .oh-recompute-form { margin-top: var(--space-2); }
  .oh-recompute-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 10px;
    border: 1px solid var(--border-strong, var(--border));
    background: transparent;
    color: var(--text);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 120ms ease, border-color 120ms ease;
  }
  .oh-recompute-btn:hover {
    background: rgba(52,211,153,0.07);
    border-color: rgba(52,211,153,0.4);
  }

  /* Empty state */
  .oh-empty {
    padding: var(--space-6) var(--space-4);
    text-align: center;
    color: var(--text-muted);
    border: 1px dashed var(--border-strong, var(--border));
    border-radius: 14px;
  }
  .oh-empty strong {
    display: block;
    font-size: 16px;
    font-weight: 700;
    color: var(--text-strong);
    margin-bottom: 8px;
  }

  /* Generated-at footer */
  .oh-footer {
    font-size: 11.5px;
    color: var(--text-muted);
    margin-top: var(--space-3);
    font-family: var(--font-mono);
  }
`;

// ---------------------------------------------------------------------------
// GET /orgs/:slug/health
// ---------------------------------------------------------------------------

orgHealthRoutes.get("/orgs/:slug/health", async (c) => {
  const slug = c.req.param("slug");
  const user = c.get("user");

  const { org, role } = await loadOrgForUser(slug, user?.id);
  if (!org) return c.notFound();

  const report = await computeOrgHealth(org.id, org.slug);
  // Patch org name in case the lib used slug as placeholder
  const orgName = org.name;

  const isAdmin = !!role && orgRoleAtLeast(role, "admin");
  const avgScore = report.avgScore;

  return c.html(
    <Layout title={`${orgName} — Engineering Health`} user={user ?? null}>
      <div class="oh-wrap">
        {/* Hero */}
        <section class="oh-hero">
          <div class="oh-hero-orb" aria-hidden="true" />
          <div class="oh-hero-inner">
            <div class="oh-hero-text">
              <div class="oh-eyebrow">
                <span class="oh-eyebrow-dot" aria-hidden="true" />
                Team health · {slug}
              </div>
              <h2 class="oh-title">
                <span class="oh-title-grad">{orgName}</span>{" "}
                Engineering Health
              </h2>
              <p class="oh-sub">
                All repositories ranked worst-first by composite health score.
                Fix the bottom of the list to move the org average.
              </p>
              <div
                class={"oh-pill " + scorePillClass(avgScore)}
                title={`Org average: ${avgScore}/100`}
              >
                {avgScore}
              </div>
            </div>
            <div style="display:flex;flex-direction:column;align-items:flex-end;gap:var(--space-3)">
              <a href={`/orgs/${slug}`} class="oh-back">
                ← Back to {slug}
              </a>
              {isAdmin && (
                <form
                  method="post"
                  action={`/orgs/${slug}/health/recompute`}
                  class="oh-recompute-form"
                >
                  <button type="submit" class="oh-recompute-btn">
                    ↺ Recompute
                  </button>
                </form>
              )}
            </div>
          </div>
        </section>

        {/* AI Summary */}
        {report.aiSummary && (
          <div class="oh-ai-card">
            <div class="oh-ai-label">
              <span class="oh-ai-dot" aria-hidden="true" />
              AI Engineering Summary
            </div>
            {report.aiSummary}
          </div>
        )}

        {/* Repo table */}
        <div class="oh-table-wrap">
          <div class="oh-table-head">
            <h3 class="oh-table-title">Repository Health — Worst First</h3>
            <span class="oh-table-sub">{report.repos.length} repo{report.repos.length === 1 ? "" : "s"}</span>
          </div>

          {report.repos.length === 0 ? (
            <div class="oh-empty">
              <strong>No repositories found</strong>
              <p>This org has no active repositories yet, or health data is still loading.</p>
            </div>
          ) : (
            <table class="oh-table">
              <thead>
                <tr>
                  <th style="width:40px">#</th>
                  <th>Repository</th>
                  <th style="width:200px">Score</th>
                  <th style="width:60px">Trend</th>
                  <th style="width:55px">CI</th>
                  <th style="width:80px">BusFactor</th>
                  <th style="width:55px">CVEs</th>
                  <th style="width:60px">Review</th>
                  <th style="width:55px">Debt</th>
                </tr>
              </thead>
              <tbody>
                {report.repos.map((r: OrgRepoHealth, i: number) => {
                  const b = r.breakdown;
                  const barColor = scoreColor(r.score);
                  return (
                    <tr key={r.repoId}>
                      <td>
                        <span class="oh-rank">{i + 1}</span>
                      </td>
                      <td>
                        <a
                          href={`/${slug}/${r.repoName}`}
                          class="oh-repo-link"
                        >
                          {slug}/{r.repoName}
                        </a>
                      </td>
                      <td>
                        <span class="oh-bar-track">
                          <div
                            style={`width:${r.score}%;background:${barColor};height:6px;border-radius:3px`}
                          />
                        </span>
                        <span
                          style={`color:${barColor};font-family:var(--font-mono);font-size:13px;font-weight:700`}
                        >
                          {r.score}
                        </span>
                        <span style="color:var(--text-muted);font-size:11px">/100</span>
                      </td>
                      <td>
                        <span class={trendClass(r.trend)} title={`Trend: ${r.trend}`}>
                          {trendArrow(r.trend)}
                        </span>
                      </td>
                      <td>
                        <span style={badgeStyle(b.ciGreenRate.score)}>
                          {b.ciGreenRate.score}
                        </span>
                      </td>
                      <td>
                        <span style={badgeStyle(b.busFactor.score)}>
                          {b.busFactor.score}
                        </span>
                      </td>
                      <td>
                        <span style={badgeStyle(b.openCves.score)}>
                          {b.openCves.score}
                        </span>
                      </td>
                      <td>
                        <span style={badgeStyle(b.reviewVelocity.score)}>
                          {b.reviewVelocity.score}
                        </span>
                      </td>
                      <td>
                        <span style={badgeStyle(b.techDebt.score)}>
                          {b.techDebt.score}
                        </span>
                      </td>
                    </tr>
                  );
                })}
              </tbody>
            </table>
          )}
        </div>

        <div class="oh-footer">
          Generated {report.generatedAt.toISOString().replace("T", " ").slice(0, 19)} UTC · cached 1h
        </div>
      </div>
      <style dangerouslySetInnerHTML={{ __html: styles }} />
    </Layout>
  );
});

// ---------------------------------------------------------------------------
// POST /orgs/:slug/health/recompute — admin only, invalidate + redirect
// ---------------------------------------------------------------------------

orgHealthRoutes.post("/orgs/:slug/health/recompute", requireAuth, async (c) => {
  const slug = c.req.param("slug");
  const user = c.get("user")!;

  const { org, role } = await loadOrgForUser(slug, user.id);
  if (!org) return c.notFound();
  if (!role || !orgRoleAtLeast(role, "admin")) {
    return c.text("Forbidden", 403);
  }

  await invalidateOrgHealthAndRepos(org.id);
  return c.redirect(`/orgs/${slug}/health`);
});

export { orgHealthRoutes };
export default orgHealthRoutes;