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
docs-tracking.tsx15.6 KB · 501 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
/**
 * AI-tracked documentation sections — staleness dashboard.
 *
 *   GET  /:owner/:repo/docs/tracking
 *
 * Lists every `<!-- gluecron:doc-track src=... -->` region we know about
 * in the repo, alongside its source hash, last-checked timestamp, and a
 * "Stale / Fresh / Unseen" pill. Empty state when nothing is tracked yet.
 *
 * All page-local CSS is scoped under `.doctrk-*` so it cannot bleed into
 * the shared layout (per CLAUDE.md: do NOT modify shared layout /
 * components / ui). Mirrors the gradient hairline + orb pattern used by
 * previews.tsx and environments.tsx.
 */

import { Hono } from "hono";
import { and, eq } from "drizzle-orm";
import { db } from "../db";
import { docTracking, pullRequests, repositories, users } from "../db/schema";
import { softAuth } from "../middleware/auth";
import type { AuthEnv } from "../middleware/auth";
import { Layout } from "../views/layout";
import { RepoHeader, RepoNav } from "../views/components";
import { getUnreadCount } from "../lib/unread";
import { findTrackedDocs, type TrackedDoc } from "../lib/ai-doc-updater";

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

interface RepoRow {
  id: string;
  name: string;
  defaultBranch: string;
  starCount: number;
  forkCount: number;
}

async function loadRepo(owner: string, repo: string): Promise<RepoRow | null> {
  try {
    const [row] = await db
      .select({
        id: repositories.id,
        name: repositories.name,
        defaultBranch: repositories.defaultBranch,
        starCount: repositories.starCount,
        forkCount: repositories.forkCount,
      })
      .from(repositories)
      .innerJoin(users, eq(repositories.ownerId, users.id))
      .where(and(eq(users.username, owner), eq(repositories.name, repo)))
      .limit(1);
    return row || null;
  } catch (err) {
    console.error("[docs-tracking] loadRepo failed:", err);
    return null;
  }
}

interface StoredRow {
  docPath: string;
  sectionMarker: string;
  lastCheckedAt: Date;
  lastPrId: string | null;
  prNumber: number | null;
  prState: string | null;
}

async function loadStored(repositoryId: string): Promise<StoredRow[]> {
  try {
    const rows = await db
      .select({
        docPath: docTracking.docPath,
        sectionMarker: docTracking.sectionMarker,
        lastCheckedAt: docTracking.lastCheckedAt,
        lastPrId: docTracking.lastPrId,
        prNumber: pullRequests.number,
        prState: pullRequests.state,
      })
      .from(docTracking)
      .leftJoin(pullRequests, eq(pullRequests.id, docTracking.lastPrId))
      .where(eq(docTracking.repositoryId, repositoryId));
    return rows.map((r) => ({
      docPath: r.docPath,
      sectionMarker: r.sectionMarker,
      lastCheckedAt: r.lastCheckedAt,
      lastPrId: r.lastPrId,
      prNumber: r.prNumber,
      prState: r.prState,
    }));
  } catch {
    return [];
  }
}

/* ─────────────────────────────────────────────────────────────────────────
 * Scoped CSS — `.doctrk-*` only. Mirrors `.preview-*` styling so the
 * dashboard feels at home alongside the other repo sub-pages.
 * ───────────────────────────────────────────────────────────────────── */
const docTrackingStyles = `
  .doctrk-wrap { max-width: 1680px; margin: 0 auto; padding: var(--space-5) var(--space-4) var(--space-8); }

  .doctrk-head {
    position: relative;
    margin-bottom: var(--space-5);
    padding: var(--space-4) var(--space-5);
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 14px;
    overflow: hidden;
  }
  .doctrk-head::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 2px;
    background: linear-gradient(90deg, transparent 0%, #36c5d6 30%, #8c6dff 70%, transparent 100%);
    opacity: 0.7;
    pointer-events: none;
  }
  .doctrk-head-orb {
    position: absolute;
    inset: -30% -10% auto auto;
    width: 320px; height: 320px;
    background: radial-gradient(circle, rgba(54,197,214,0.18), rgba(140,109,255,0.08) 45%, transparent 70%);
    filter: blur(70px);
    opacity: 0.7;
    pointer-events: none;
    z-index: 0;
  }
  .doctrk-head-inner { position: relative; z-index: 1; }

  .doctrk-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;
  }
  .doctrk-eyebrow-dot {
    width: 8px; height: 8px;
    border-radius: 9999px;
    background: linear-gradient(135deg, #36c5d6, #8c6dff);
    box-shadow: 0 0 0 3px rgba(54,197,214,0.18);
  }
  .doctrk-title {
    font-family: var(--font-display);
    font-size: 28px;
    font-weight: 700;
    color: var(--text-strong);
    margin: 0 0 6px;
    letter-spacing: -0.02em;
  }
  .doctrk-sub {
    color: var(--text-muted);
    margin: 0;
    max-width: 70ch;
    line-height: 1.5;
  }

  .doctrk-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
  }
  .doctrk-doc {
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--bg-elevated);
    padding: var(--space-3) var(--space-4);
  }
  .doctrk-doc-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--space-3);
    margin-bottom: var(--space-2);
  }
  .doctrk-doc-path {
    font-family: var(--font-mono);
    font-size: 14px;
    font-weight: 700;
    color: var(--text-strong);
    word-break: break-all;
  }
  .doctrk-section {
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: rgba(255,255,255,0.02);
    margin-top: 8px;
  }
  .doctrk-section-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--space-2);
    margin-bottom: 6px;
    flex-wrap: wrap;
  }
  .doctrk-section-src {
    font-family: var(--font-mono);
    font-size: 12.5px;
    color: var(--text);
  }
  .doctrk-section-claim {
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.45;
    white-space: pre-wrap;
    max-height: 4.5em;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .doctrk-section-meta {
    margin-top: 6px;
    font-size: 11.5px;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    display: flex;
    gap: var(--space-3);
    flex-wrap: wrap;
  }
  .doctrk-section-meta code {
    font-family: var(--font-mono);
    background: rgba(255,255,255,0.04);
    padding: 1px 6px;
    border-radius: 6px;
  }
  .doctrk-section-meta a {
    color: #b69dff;
    text-decoration: none;
  }
  .doctrk-section-meta a:hover { text-decoration: underline; }

  /* ─── status pills ─── */
  .doctrk-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 2px 9px;
    border-radius: 9999px;
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    font-family: var(--font-mono);
    background: rgba(255,255,255,0.04);
    color: var(--text-muted);
    box-shadow: inset 0 0 0 1px var(--border);
  }
  .doctrk-pill.is-stale {
    background: rgba(251,191,36,0.10);
    color: #fde68a;
    box-shadow: inset 0 0 0 1px rgba(251,191,36,0.30);
  }
  .doctrk-pill.is-fresh {
    background: rgba(52,211,153,0.10);
    color: #6ee7b7;
    box-shadow: inset 0 0 0 1px rgba(52,211,153,0.30);
  }
  .doctrk-pill.is-unseen {
    background: rgba(148,163,184,0.10);
    color: #cbd5e1;
    box-shadow: inset 0 0 0 1px rgba(148,163,184,0.30);
  }
  .doctrk-pill.is-missing {
    background: rgba(248,113,113,0.10);
    color: #fecaca;
    box-shadow: inset 0 0 0 1px rgba(248,113,113,0.35);
  }
  .doctrk-pill-dot {
    width: 6px; height: 6px;
    border-radius: 9999px;
    background: currentColor;
  }

  /* ─── empty state ─── */
  .doctrk-empty {
    position: relative;
    padding: var(--space-6) var(--space-5);
    background: var(--bg-elevated);
    border: 1px dashed var(--border-strong, var(--border));
    border-radius: 14px;
    text-align: center;
    overflow: hidden;
    margin-bottom: var(--space-5);
  }
  .doctrk-empty-orb {
    position: absolute;
    inset: auto auto -40% 50%;
    transform: translateX(-50%);
    width: 320px; height: 320px;
    background: radial-gradient(circle, rgba(54,197,214,0.18), rgba(140,109,255,0.08) 45%, transparent 70%);
    filter: blur(70px);
    opacity: 0.7;
    pointer-events: none;
  }
  .doctrk-empty-inner { position: relative; z-index: 1; max-width: 540px; margin: 0 auto; }
  .doctrk-empty-title {
    font-family: var(--font-display);
    font-size: 16px;
    font-weight: 700;
    color: var(--text-strong);
    margin: 0 0 6px;
  }
  .doctrk-empty-body {
    font-size: 13.5px;
    color: var(--text-muted);
    line-height: 1.5;
    margin: 0 0 var(--space-3);
  }
  .doctrk-empty code, .doctrk-codeblock {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text);
    background: rgba(255,255,255,0.06);
    padding: 1px 6px;
    border-radius: 6px;
  }
  .doctrk-codeblock {
    display: block;
    padding: 10px 14px;
    white-space: pre;
    text-align: left;
    margin: var(--space-3) auto;
    max-width: 540px;
    overflow-x: auto;
  }
`;

function statusFor(
  stored: StoredRow | undefined,
  section: { stale: boolean; currentSrcHash: string }
): { label: string; cls: string } {
  if (section.currentSrcHash.startsWith("missing:")) {
    return { label: "missing source", cls: "is-missing" };
  }
  if (!stored) {
    return { label: "unseen", cls: "is-unseen" };
  }
  if (section.stale) {
    return { label: "stale", cls: "is-stale" };
  }
  return { label: "fresh", cls: "is-fresh" };
}

r.get("/:owner/:repo/docs/tracking", async (c) => {
  const user = c.get("user");
  const { owner, repo } = c.req.param();
  const repoRow = await loadRepo(owner, repo);
  if (!repoRow) return c.notFound();

  const [docs, stored, unread] = await Promise.all([
    findTrackedDocs(repoRow.id).catch(() => [] as TrackedDoc[]),
    loadStored(repoRow.id),
    user ? getUnreadCount(user.id) : Promise.resolve(0),
  ]);

  const storedByKey = new Map<string, StoredRow>();
  for (const row of stored) {
    storedByKey.set(`${row.docPath}::${row.sectionMarker}`, row);
  }

  const totalSections = docs.reduce((a, d) => a + d.sections.length, 0);

  return c.html(
    <Layout
      title={`Tracked docs — ${owner}/${repo}`}
      user={user}
      notificationCount={unread}
    >
      <RepoHeader
        owner={owner}
        repo={repo}
        starCount={repoRow.starCount}
        forkCount={repoRow.forkCount}
        currentUser={user?.username}
      />
      <RepoNav owner={owner} repo={repo} active="code" />

      <div class="doctrk-wrap">
        <section class="doctrk-head">
          <div class="doctrk-head-orb" aria-hidden="true" />
          <div class="doctrk-head-inner">
            <div class="doctrk-eyebrow">
              <span class="doctrk-eyebrow-dot" aria-hidden="true" />
              AI-tracked docs · {owner}/{repo}
            </div>
            <h2 class="doctrk-title">Documentation drift</h2>
            <p class="doctrk-sub">
              Every markdown region wrapped in{" "}
              <code>&lt;!-- gluecron:doc-track src=... --&gt;</code> markers is
              hashed against the source it claims to describe. When the
              source changes, Claude opens a draft PR labelled{" "}
              <code>ai:doc-update</code> with the refreshed prose.
            </p>
          </div>
        </section>

        {docs.length === 0 ? (
          <div class="doctrk-empty">
            <div class="doctrk-empty-orb" aria-hidden="true" />
            <div class="doctrk-empty-inner">
              <h3 class="doctrk-empty-title">No tracked sections yet</h3>
              <p class="doctrk-empty-body">
                Wrap a paragraph in a markdown file with the marker below
                and Claude will keep it in sync with the source whenever
                you push.
              </p>
              <code class="doctrk-codeblock">{`<!-- gluecron:doc-track src=src/lib/auth.ts -->
This module exports \`signIn\` and \`signUp\` —
see the source for details.
<!-- /gluecron:doc-track -->`}</code>
            </div>
          </div>
        ) : (
          <>
            <p class="doctrk-sub" style="margin-bottom: var(--space-3);">
              {docs.length} doc{docs.length === 1 ? "" : "s"} · {totalSections}{" "}
              tracked section{totalSections === 1 ? "" : "s"}
            </p>
            <div class="doctrk-list">
              {docs.map((d) => (
                <div class="doctrk-doc">
                  <div class="doctrk-doc-head">
                    <div class="doctrk-doc-path">{d.path}</div>
                    <div>
                      <span class="doctrk-pill">
                        <span class="doctrk-pill-dot" aria-hidden="true" />
                        {d.sections.length} section
                        {d.sections.length === 1 ? "" : "s"}
                      </span>
                    </div>
                  </div>
                  {d.sections.map((s) => {
                    const key = `${d.path}::${s.marker}`;
                    const storedRow = storedByKey.get(key);
                    const status = statusFor(storedRow, s);
                    const checkedLabel = storedRow
                      ? new Date(storedRow.lastCheckedAt).toISOString()
                      : "never";
                    return (
                      <div class="doctrk-section">
                        <div class="doctrk-section-head">
                          <div class="doctrk-section-src">
                            tracks <code>{s.claimedFor}</code>
                          </div>
                          <span class={`doctrk-pill ${status.cls}`}>
                            <span class="doctrk-pill-dot" aria-hidden="true" />
                            {status.label}
                          </span>
                        </div>
                        <div class="doctrk-section-claim">{s.claim}</div>
                        <div class="doctrk-section-meta">
                          <span>
                            marker <code>{s.marker}</code>
                          </span>
                          <span>
                            current{" "}
                            <code>{s.currentSrcHash.slice(0, 12)}</code>
                          </span>
                          <span>
                            stored{" "}
                            <code>
                              {(s.storedClaimedHash ?? "—").slice(0, 12)}
                            </code>
                          </span>
                          <span>last checked {checkedLabel}</span>
                          {storedRow?.prNumber ? (
                            <span>
                              PR{" "}
                              <a
                                href={`/${owner}/${repo}/pulls/${storedRow.prNumber}`}
                              >
                                #{storedRow.prNumber}
                              </a>{" "}
                              ({storedRow.prState ?? "?"})
                            </span>
                          ) : null}
                        </div>
                      </div>
                    );
                  })}
                </div>
              ))}
            </div>
          </>
        )}
      </div>

      <style dangerouslySetInnerHTML={{ __html: docTrackingStyles }} />
    </Layout>
  );
});

export default r;