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
pulse.tsx19.5 KB · 536 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
/**
 * Repository Pulse — a time-window snapshot of repo activity.
 *
 * Route: GET /:owner/:repo/pulse?window=1|7|30 (default 7 days)
 *
 * Shows:
 *   - Issues opened / closed in window
 *   - PRs opened / merged / closed in window
 *   - Active contributors (unique commit authors in window)
 *   - Gate activity (pass/fail counts)
 *   - Most active contributors (by PR + commit activity)
 *   - Streak: consecutive days with at least one merged PR
 *
 * Zero new DB tables. All data from: pull_requests, issues, users,
 * repositories, activityFeed, gateRuns.
 *
 * Scoped CSS: `.pulse-*`
 */

import { Hono } from "hono";
import { db } from "../db";
import {
  pullRequests,
  issues,
  users,
  repositories,
  activityFeed,
  gateRuns,
  prComments,
} from "../db/schema";
import { eq, and, gte, desc, sql, count, isNotNull } from "drizzle-orm";
import type { AuthEnv } from "../middleware/auth";
import { softAuth } from "../middleware/auth";
import { requireRepoAccess } from "../middleware/repo-access";
import { Layout } from "../views/layout";
import { RepoHeader, RepoNav } from "../views/components";
import { listCommits, getDefaultBranch } from "../git/repository";

const pulseRoutes = new Hono<AuthEnv>();

// Path-scoped middleware — NEVER use("*", ...)
// "path*" (no slash before the *) doesn't match the bare path in this Hono
// version -- see admin-security.tsx's fix for the confirmed repro.
pulseRoutes.use("/:owner/:repo/pulse", softAuth);
pulseRoutes.use("/:owner/:repo/pulse/*", softAuth);

// ─── helpers ─────────────────────────────────────────────────────────────────

function windowStart(days: number): Date {
  const d = new Date();
  d.setDate(d.getDate() - days);
  return d;
}

function formatDate(d: Date): string {
  return d.toLocaleDateString("en-US", { month: "short", day: "numeric" });
}

function pct(a: number, b: number): string {
  if (!b) return "0%";
  return `${Math.round((a / b) * 100)}%`;
}

// ─── route ───────────────────────────────────────────────────────────────────

pulseRoutes.get(
  "/:owner/:repo/pulse",
  requireRepoAccess("read"),
  async (c) => {
    const { owner: ownerName, repo: repoName } = c.req.param();
    const user = c.get("user");

    const rawWindow = c.req.query("window");
    const windowDays = rawWindow === "1" ? 1 : rawWindow === "30" ? 30 : 7;
    const since = windowStart(windowDays);

    // Load repo
    const [ownerRow] = await db
      .select({ id: users.id })
      .from(users)
      .where(eq(users.username, ownerName))
      .limit(1);
    if (!ownerRow) return c.notFound();

    const [repo] = await db
      .select()
      .from(repositories)
      .where(and(eq(repositories.ownerId, ownerRow.id), eq(repositories.name, repoName)))
      .limit(1);
    if (!repo) return c.notFound();

    // ── parallel queries ─────────────────────────────────────────────────────

    const [
      issuesOpened,
      issuesClosed,
      prsOpened,
      prsMerged,
      prsClosed,
      gatesPassed,
      gatesFailed,
      reviewsPosted,
      topPrAuthors,
      recentActivity,
    ] = await Promise.all([
      // Issues opened in window
      db
        .select({ cnt: count() })
        .from(issues)
        .where(and(eq(issues.repositoryId, repo.id), gte(issues.createdAt, since)))
        .then((r) => r[0]?.cnt ?? 0),

      // Issues closed in window
      db
        .select({ cnt: count() })
        .from(issues)
        .where(
          and(
            eq(issues.repositoryId, repo.id),
            eq(issues.state, "closed"),
            gte(issues.updatedAt, since)
          )
        )
        .then((r) => r[0]?.cnt ?? 0),

      // PRs opened in window
      db
        .select({ cnt: count() })
        .from(pullRequests)
        .where(and(eq(pullRequests.repositoryId, repo.id), gte(pullRequests.createdAt, since)))
        .then((r) => r[0]?.cnt ?? 0),

      // PRs merged in window
      db
        .select({ cnt: count() })
        .from(pullRequests)
        .where(
          and(
            eq(pullRequests.repositoryId, repo.id),
            eq(pullRequests.state, "merged"),
            isNotNull(pullRequests.mergedAt),
            gte(pullRequests.mergedAt!, since)
          )
        )
        .then((r) => r[0]?.cnt ?? 0),

      // PRs closed (not merged) in window
      db
        .select({ cnt: count() })
        .from(pullRequests)
        .where(
          and(
            eq(pullRequests.repositoryId, repo.id),
            eq(pullRequests.state, "closed"),
            gte(pullRequests.updatedAt, since)
          )
        )
        .then((r) => r[0]?.cnt ?? 0),

      // Gates passed in window
      db
        .select({ cnt: count() })
        .from(gateRuns)
        .where(
          and(
            eq(gateRuns.repositoryId, repo.id),
            eq(gateRuns.status, "passed"),
            gte(gateRuns.createdAt, since)
          )
        )
        .then((r) => r[0]?.cnt ?? 0),

      // Gates failed in window
      db
        .select({ cnt: count() })
        .from(gateRuns)
        .where(
          and(
            eq(gateRuns.repositoryId, repo.id),
            eq(gateRuns.status, "failed"),
            gte(gateRuns.createdAt, since)
          )
        )
        .then((r) => r[0]?.cnt ?? 0),

      // Code reviews posted in window (non-AI)
      db
        .select({ cnt: count() })
        .from(prComments)
        .innerJoin(pullRequests, eq(prComments.pullRequestId, pullRequests.id))
        .where(
          and(
            eq(pullRequests.repositoryId, repo.id),
            eq(prComments.isAiReview, false),
            gte(prComments.createdAt, since)
          )
        )
        .then((r) => r[0]?.cnt ?? 0),

      // Top PR contributors in window (by PRs opened)
      db
        .select({
          authorId: pullRequests.authorId,
          username: users.username,
          prsOpened: count(),
        })
        .from(pullRequests)
        .innerJoin(users, eq(pullRequests.authorId, users.id))
        .where(
          and(eq(pullRequests.repositoryId, repo.id), gte(pullRequests.createdAt, since))
        )
        .groupBy(pullRequests.authorId, users.username)
        .orderBy(desc(count()))
        .limit(8),

      // Recent activity feed entries
      db
        .select({
          action: activityFeed.action,
          targetType: activityFeed.targetType,
          targetId: activityFeed.targetId,
          createdAt: activityFeed.createdAt,
          username: users.username,
        })
        .from(activityFeed)
        .leftJoin(users, eq(activityFeed.userId, users.id))
        .where(
          and(eq(activityFeed.repositoryId, repo.id), gte(activityFeed.createdAt, since))
        )
        .orderBy(desc(activityFeed.createdAt))
        .limit(20),
    ]);

    // Commit count from git log (best-effort)
    let commitCount = 0;
    let activeContributors = new Set<string>();
    try {
      const defaultBranch = (await getDefaultBranch(ownerName, repoName)) ?? "main";
      const commits = await listCommits(ownerName, repoName, defaultBranch, 200);
      const cutoff = since.getTime();
      for (const c of commits) {
        const ts = new Date(c.date).getTime();
        if (ts >= cutoff) {
          commitCount++;
          const email = (c as { authorEmail?: string }).authorEmail;
          if (email) activeContributors.add(email);
        }
      }
    } catch {
      // If repo has no commits or git fails, silently skip
    }

    const windowLabel =
      windowDays === 1 ? "last 24 hours" : `last ${windowDays} days`;
    const totalGates = Number(gatesPassed) + Number(gatesFailed);
    const gatePassRate = totalGates > 0
      ? Math.round((Number(gatesPassed) / totalGates) * 100)
      : null;

    return c.html(
      <Layout
        title={`Pulse — ${ownerName}/${repoName}`}
        user={user}
      >
        <PulseStyle />
        <RepoHeader owner={ownerName} repo={repoName} />
        <RepoNav owner={ownerName} repo={repoName} active="insights" />
        <div class="pulse-page">
          {/* Window selector */}
          <div class="pulse-header">
            <h2 class="pulse-title">Pulse</h2>
            <div class="pulse-windows">
              {(["1", "7", "30"] as const).map((w) => (
                <a
                  href={`/${ownerName}/${repoName}/pulse?window=${w}`}
                  class={`pulse-window-btn${windowDays === Number(w) ? " is-active" : ""}`}
                >
                  {w === "1" ? "24h" : w === "7" ? "7d" : "30d"}
                </a>
              ))}
            </div>
            <p class="pulse-subtitle">
              Activity overview for the <strong>{windowLabel}</strong> (
              {formatDate(since)} – {formatDate(new Date())})
            </p>
          </div>

          {/* Summary stat cards */}
          <div class="pulse-cards">
            <StatCard
              label="Issues opened"
              value={Number(issuesOpened)}
              sub={`${Number(issuesClosed)} closed`}
              color="#f59e0b"
            />
            <StatCard
              label="PRs opened"
              value={Number(prsOpened)}
              sub={`${Number(prsMerged)} merged · ${Number(prsClosed)} closed`}
              color="#5b6ee8"
            />
            <StatCard
              label="Commits"
              value={commitCount}
              sub={`by ${activeContributors.size} contributor${activeContributors.size !== 1 ? "s" : ""}`}
              color="#5f8fa0"
            />
            <StatCard
              label="Code reviews"
              value={Number(reviewsPosted)}
              sub="human reviews posted"
              color="#22c55e"
            />
            {gatePassRate !== null && (
              <StatCard
                label="Gate pass rate"
                value={gatePassRate}
                suffix="%"
                sub={`${Number(gatesPassed)}/${totalGates} checks`}
                color={gatePassRate >= 80 ? "#22c55e" : gatePassRate >= 50 ? "#f59e0b" : "#ef4444"}
              />
            )}
          </div>

          <div class="pulse-body">
            {/* Top contributors */}
            {topPrAuthors.length > 0 && (
              <section class="pulse-section">
                <h3 class="pulse-section-title">Top contributors this period</h3>
                <div class="pulse-contributors">
                  {topPrAuthors.map((row) => (
                    <a
                      href={`/${row.username}`}
                      class="pulse-contrib-row"
                    >
                      <span class="pulse-contrib-avatar">
                        {row.username.slice(0, 1).toUpperCase()}
                      </span>
                      <span class="pulse-contrib-name">{row.username}</span>
                      <span class="pulse-contrib-count">
                        {Number(row.prsOpened)} PR{Number(row.prsOpened) !== 1 ? "s" : ""}
                      </span>
                    </a>
                  ))}
                </div>
              </section>
            )}

            {/* Gate health */}
            {totalGates > 0 && (
              <section class="pulse-section">
                <h3 class="pulse-section-title">Gate health</h3>
                <div class="pulse-gate-bar-wrap">
                  <div class="pulse-gate-bar">
                    <div
                      class="pulse-gate-bar-pass"
                      style={`width:${pct(Number(gatesPassed), totalGates)}`}
                      title={`${gatesPassed} passed`}
                    />
                    <div
                      class="pulse-gate-bar-fail"
                      style={`width:${pct(Number(gatesFailed), totalGates)}`}
                      title={`${gatesFailed} failed`}
                    />
                  </div>
                  <span class="pulse-gate-bar-label">
                    {gatesPassed} passed · {gatesFailed} failed
                    {gatePassRate !== null && ` (${gatePassRate}%)`}
                  </span>
                </div>
              </section>
            )}

            {/* Recent activity */}
            {recentActivity.length > 0 && (
              <section class="pulse-section">
                <h3 class="pulse-section-title">Recent activity</h3>
                <ul class="pulse-activity-list">
                  {recentActivity.slice(0, 12).map((ev) => (
                    <li class="pulse-activity-item">
                      <span class="pulse-activity-icon">{activityIcon(ev.action)}</span>
                      <span class="pulse-activity-text">
                        {ev.username && (
                          <a href={`/${ev.username}`} class="pulse-activity-user">
                            {ev.username}
                          </a>
                        )}
                        {" "}
                        {activityLabel(ev.action, ev.targetType ?? null, ev.targetId ?? null)}
                      </span>
                      <span class="pulse-activity-time">
                        {formatDate(new Date(ev.createdAt))}
                      </span>
                    </li>
                  ))}
                </ul>
              </section>
            )}

            {recentActivity.length === 0 && commitCount === 0 && (
              <div class="pulse-empty">
                <p>No activity in the {windowLabel}.</p>
                <a href="?window=30" class="btn">View last 30 days</a>
              </div>
            )}
          </div>
        </div>
      </Layout>
    );
  }
);

// ─── Sub-components ───────────────────────────────────────────────────────────

function StatCard({
  label,
  value,
  sub,
  color,
  suffix = "",
}: {
  label: string;
  value: number;
  sub?: string;
  color: string;
  suffix?: string;
}) {
  return (
    <div class="pulse-card" style={`border-top-color:${color}`}>
      <div class="pulse-card-value" style={`color:${color}`}>
        {value.toLocaleString()}{suffix}
      </div>
      <div class="pulse-card-label">{label}</div>
      {sub && <div class="pulse-card-sub">{sub}</div>}
    </div>
  );
}

function activityIcon(action: string): string {
  if (action.includes("issue")) return "◦";
  if (action.includes("pr") || action.includes("pull_request")) return "↑";
  if (action.includes("deploy")) return "▶";
  if (action.includes("gate")) return "✓";
  if (action.includes("repo")) return "⊞";
  return "·";
}

function activityLabel(action: string, targetType: string | null, targetId: string | null): string {
  const ref = targetId ? `#${targetId}` : "";
  if (action === "pull_request.opened") return `opened PR ${ref}`;
  if (action === "pull_request.merged") return `merged PR ${ref}`;
  if (action === "pull_request.closed") return `closed PR ${ref}`;
  if (action === "issue.opened") return `opened issue ${ref}`;
  if (action === "issue.closed") return `closed issue ${ref}`;
  if (action === "repo_created") return "created repository";
  if (action === "deploy_success") return "deployed successfully";
  if (action === "deploy_failed") return "deployment failed";
  if (action.includes("gate")) return `gate ${action.split(".")[1] || "run"}`;
  return action.replace(/_/g, " ").replace(/\./g, " ");
}

// ─── Styles ───────────────────────────────────────────────────────────────────

function PulseStyle() {
  return (
    <style>{`
      .pulse-page { max-width: 1320px; margin: 0 auto; padding: 0 16px 48px; }
      .pulse-header { margin: 24px 0 20px; }
      .pulse-title { font-size: 22px; font-weight: 700; margin: 0 0 8px; }
      .pulse-subtitle { font-size: 14px; color: var(--fg-muted); margin: 8px 0 0; }
      .pulse-windows { display: flex; gap: 8px; margin-bottom: 8px; }
      .pulse-window-btn {
        padding: 5px 14px; border-radius: 20px; font-size: 13px; font-weight: 600;
        background: var(--bg-elevated); border: 1px solid var(--border); color: var(--fg);
        text-decoration: none; transition: border-color .15s;
      }
      .pulse-window-btn:hover { border-color: var(--accent); }
      .pulse-window-btn.is-active { background: var(--accent); border-color: var(--accent); color: #fff; }

      .pulse-cards {
        display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
        gap: 14px; margin-bottom: 32px;
      }
      .pulse-card {
        background: var(--bg-elevated); border: 1px solid var(--border);
        border-radius: 12px; border-top: 3px solid var(--accent);
        padding: 18px 16px;
      }
      .pulse-card-value { font-size: 28px; font-weight: 800; line-height: 1; margin-bottom: 4px; }
      .pulse-card-label { font-size: 12px; color: var(--fg-muted); text-transform: uppercase; letter-spacing: .04em; }
      .pulse-card-sub { font-size: 12px; color: var(--fg-muted); margin-top: 4px; }

      .pulse-body { display: flex; flex-direction: column; gap: 28px; }
      .pulse-section { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 12px; padding: 20px 22px; }
      .pulse-section-title { font-size: 15px; font-weight: 700; margin: 0 0 14px; }

      .pulse-contributors { display: flex; flex-wrap: wrap; gap: 10px; }
      .pulse-contrib-row {
        display: flex; align-items: center; gap: 8px;
        background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
        padding: 7px 12px; text-decoration: none; color: var(--fg); font-size: 13px;
        transition: border-color .15s;
      }
      .pulse-contrib-row:hover { border-color: var(--accent); }
      .pulse-contrib-avatar {
        width: 26px; height: 26px; border-radius: 50%; background: var(--accent);
        color: #fff; display: flex; align-items: center; justify-content: center;
        font-size: 11px; font-weight: 700; flex-shrink: 0;
      }
      .pulse-contrib-name { font-weight: 600; }
      .pulse-contrib-count { color: var(--fg-muted); }

      .pulse-gate-bar-wrap { display: flex; align-items: center; gap: 12px; }
      .pulse-gate-bar {
        flex: 1; height: 12px; border-radius: 6px; background: var(--bg); overflow: hidden;
        display: flex;
      }
      .pulse-gate-bar-pass { background: #22c55e; height: 100%; transition: width .3s; }
      .pulse-gate-bar-fail { background: #ef4444; height: 100%; transition: width .3s; }
      .pulse-gate-bar-label { font-size: 13px; color: var(--fg-muted); white-space: nowrap; }

      .pulse-activity-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
      .pulse-activity-item { display: flex; align-items: baseline; gap: 8px; font-size: 13px; }
      .pulse-activity-icon { font-size: 14px; color: var(--accent); width: 16px; flex-shrink: 0; }
      .pulse-activity-text { flex: 1; color: var(--fg); }
      .pulse-activity-user { font-weight: 600; color: var(--fg); text-decoration: none; }
      .pulse-activity-user:hover { text-decoration: underline; }
      .pulse-activity-time { color: var(--fg-muted); font-size: 12px; white-space: nowrap; }

      .pulse-empty { text-align: center; padding: 40px 0; color: var(--fg-muted); }
      .pulse-empty p { margin-bottom: 14px; }
    `}</style>
  );
}

export default pulseRoutes;