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
admin-status.tsx8.8 KB · 254 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
/**
 * BLOCK S4 — Site-admin synthetic-monitor dashboard.
 *
 *   GET  /admin/status      — red/green dashboard (SSE-live)
 *   POST /admin/status/run  — run the suite synchronously
 *
 * Both gated behind `isSiteAdmin`. The public `/status` page (see
 * `src/routes/status.tsx`) stays open to everyone; this is the detailed
 * 14-row health table for the owner.
 */

import { Hono } from "hono";
import { Layout } from "../views/layout";
import { softAuth } from "../middleware/auth";
import type { AuthEnv } from "../middleware/auth";
import { isSiteAdmin } from "../lib/admin";
import {
  latestStatusByCheck,
  recentRedChecks,
  runSyntheticChecks,
  persistChecks,
  SSE_TOPIC,
  SYNTHETIC_CHECKS,
  type SyntheticCheckResult,
} from "../lib/synthetic-monitor";

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

async function gate(c: any): Promise<{ user: any } | Response> {
  const user = c.get("user");
  if (!user) return c.redirect("/login?next=/admin/status");
  if (!(await isSiteAdmin(user.id))) {
    return c.html(
      <Layout title="Forbidden" user={user}>
        <div class="empty-state">
          <h2>403 — Not a site admin</h2>
          <p>You don't have permission to view this page.</p>
        </div>
      </Layout>,
      403
    );
  }
  return { user };
}

function statusDot(status: SyntheticCheckResult["status"] | undefined): string {
  if (status === "green") return "\u{1F7E2}"; // green circle
  if (status === "red") return "\u{1F534}"; // red circle
  if (status === "yellow") return "\u{1F7E1}"; // yellow circle
  return "⚪"; // white circle — never run
}

function fmtAgo(checkedAt: Date | undefined): string {
  if (!checkedAt) return "never";
  const diffMs = Date.now() - checkedAt.getTime();
  if (diffMs < 0) return "just now";
  const s = Math.floor(diffMs / 1000);
  if (s < 5) return "just now";
  if (s < 60) return `${s}s ago`;
  const m = Math.floor(s / 60);
  if (m < 60) return `${m}m ago`;
  const h = Math.floor(m / 60);
  if (h < 24) return `${h}h ago`;
  const d = Math.floor(h / 24);
  return `${d}d ago`;
}

adminStatus.get("/admin/status", async (c) => {
  const g = await gate(c);
  if (g instanceof Response) return g;
  const { user } = g;

  const latest = await latestStatusByCheck();
  const recent = await recentRedChecks(24, 25);

  const allGreen = SYNTHETIC_CHECKS.every(
    (spec) => latest[spec.name]?.status === "green"
  );

  // Find the most-recent checkedAt across all rows so we can render the
  // "last run Xs ago" badge.
  let lastRunAt: Date | null = null;
  for (const spec of SYNTHETIC_CHECKS) {
    const row = latest[spec.name];
    if (!row) continue;
    if (!lastRunAt || row.checkedAt > lastRunAt) lastRunAt = row.checkedAt;
  }

  return c.html(
    <Layout title="Synthetic monitor — admin" user={user}>
      <div style="max-width: 960px; margin: 0 auto; padding: 24px 16px">
        <div style="display: flex; align-items: center; gap: 12px; margin-bottom: 8px">
          <span
            style={`display: inline-block; width: 14px; height: 14px; border-radius: 50%; background: ${allGreen ? "var(--green, #2da44e)" : "var(--red, #cf222e)"}`}
          />
          <h1 style="margin: 0; font-size: 26px">
            {allGreen ? "All checks green" : "One or more checks failing"}
          </h1>
        </div>
        <p style="color: var(--text-muted); margin-bottom: 24px">
          Synthetic monitor — runs every autopilot tick. Last run{" "}
          <span data-last-run-at>{fmtAgo(lastRunAt ?? undefined)}</span>.
        </p>

        <div class="panel" style="margin-bottom: 20px">
          <table
            style="width: 100%; border-collapse: collapse; font-size: 14px"
            id="synthetic-table"
          >
            <thead>
              <tr style="text-align: left; color: var(--text-muted); font-size: 12px; text-transform: uppercase">
                <th style="padding: 8px 12px; width: 28px"></th>
                <th style="padding: 8px 12px">Check</th>
                <th style="padding: 8px 12px; width: 80px">Status</th>
                <th style="padding: 8px 12px; width: 90px">Duration</th>
                <th style="padding: 8px 12px; width: 110px">Last run</th>
              </tr>
            </thead>
            <tbody>
              {SYNTHETIC_CHECKS.map((spec) => {
                const row = latest[spec.name];
                return (
                  <tr
                    data-check-name={spec.name}
                    style="border-top: 1px solid var(--border)"
                  >
                    <td
                      style="padding: 8px 12px"
                      data-cell="dot"
                    >
                      {statusDot(row?.status)}
                    </td>
                    <td style="padding: 8px 12px">
                      <code>{spec.name}</code>
                      {row?.error ? (
                        <div
                          style="font-size: 11px; color: var(--red, #cf222e); margin-top: 2px"
                          data-cell="error"
                        >
                          {row.error}
                        </div>
                      ) : null}
                    </td>
                    <td style="padding: 8px 12px" data-cell="status-code">
                      {row?.statusCode ?? "—"}
                    </td>
                    <td style="padding: 8px 12px" data-cell="duration">
                      {row ? `${row.durationMs}ms` : "—"}
                    </td>
                    <td
                      style="padding: 8px 12px; color: var(--text-muted)"
                      data-cell="ago"
                    >
                      {fmtAgo(row?.checkedAt)}
                    </td>
                  </tr>
                );
              })}
            </tbody>
          </table>
        </div>

        <form
          action="/admin/status/run"
          method="post"
          style="margin-bottom: 32px"
        >
          <button class="btn-primary" type="submit">
            Run all checks now
          </button>
        </form>

        <h2 style="font-size: 16px; margin-bottom: 12px">
          Recent red checks (last 24h)
        </h2>
        {recent.length === 0 ? (
          <p style="color: var(--text-muted); font-size: 13px">
            No red checks in the last 24 hours.
          </p>
        ) : (
          <div class="panel">
            {recent.map((r) => (
              <div
                class="panel-item"
                style="justify-content: space-between; font-size: 13px"
              >
                <div>
                  <code>{r.name}</code>{" "}
                  <span style="color: var(--text-muted)">
                    — {r.error || "(no error message)"}
                  </span>
                </div>
                <span style="color: var(--text-muted); font-size: 12px">
                  {fmtAgo(r.checkedAt)}
                </span>
              </div>
            ))}
          </div>
        )}

        <script
          // Live update via SSE. Each event is a SyntheticCheckResult; we
          // patch the matching <tr data-check-name=...> in place.
          dangerouslySetInnerHTML={{
            __html: `
(function() {
  try {
    var src = new EventSource('/live-events/${SSE_TOPIC}');
    src.addEventListener('check', function(ev) {
      var data;
      try { data = JSON.parse(ev.data); } catch (e) { return; }
      var row = document.querySelector('tr[data-check-name="' + data.name + '"]');
      if (!row) return;
      var dot = row.querySelector('[data-cell="dot"]');
      var statusCode = row.querySelector('[data-cell="status-code"]');
      var duration = row.querySelector('[data-cell="duration"]');
      var ago = row.querySelector('[data-cell="ago"]');
      if (dot) dot.textContent = data.status === 'green' ? '\\uD83D\\uDFE2' : (data.status === 'red' ? '\\uD83D\\uDD34' : '\\uD83D\\uDFE1');
      if (statusCode) statusCode.textContent = data.statusCode != null ? String(data.statusCode) : '\\u2014';
      if (duration) duration.textContent = data.durationMs + 'ms';
      if (ago) ago.textContent = 'just now';
      var lastRun = document.querySelector('[data-last-run-at]');
      if (lastRun) lastRun.textContent = 'just now';
    });
  } catch (e) { /* SSE not available — page still renders the SSR snapshot */ }
})();
`,
          }}
        />
      </div>
    </Layout>
  );
});

adminStatus.post("/admin/status/run", async (c) => {
  const g = await gate(c);
  if (g instanceof Response) return g;

  // Fire-and-forget the run so we don't block the redirect on a slow
  // network. Persist + SSE happens inside the helper.
  void (async () => {
    try {
      const results = await runSyntheticChecks();
      await persistChecks(results);
    } catch (err) {
      console.error("[admin-status] manual run failed:", err);
    }
  })();

  return c.redirect("/admin/status");
});

export default adminStatus;