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
ai-changelog.tsx9.0 KB · 310 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
/**
 * Block D7 — AI-generated changelog for an arbitrary commit range.
 *
 *   GET /:owner/:repo/ai/changelog
 *     - No query args: renders a form (from/to selects populated from
 *       branches + recent tags).
 *     - ?from=&to= (&format=markdown|html): runs `git log <from>..<to>`,
 *       feeds commits to `generateChangelog`, and renders the result.
 *     - ?format=markdown returns `text/markdown` for CLI/CI consumers.
 *
 * Public repos are readable without auth (softAuth) — matching the
 * behaviour of `src/routes/compare.tsx`.
 */

import { Hono } from "hono";
import { Layout } from "../views/layout";
import { RepoHeader } from "../views/components";
import { IssueNav } from "./issues";
import {
  listBranches,
  listTags,
  resolveRef,
  repoExists,
  getRepoPath,
} from "../git/repository";
import { generateChangelog } from "../lib/ai-generators";
import { renderMarkdown } from "../lib/markdown";
import { softAuth } from "../middleware/auth";
import type { AuthEnv } from "../middleware/auth";

const aiChangelog = new Hono<AuthEnv>();

aiChangelog.use("*", softAuth);

interface RangeCommit {
  sha: string;
  message: string;
  author: string;
  date: string;
}

async function commitsInRange(
  owner: string,
  repo: string,
  from: string,
  to: string
): Promise<RangeCommit[]> {
  const repoDir = getRepoPath(owner, repo);
  const proc = Bun.spawn(
    [
      "git",
      "log",
      "--format=%H%x00%s%x00%an%x00%aI",
      `${from}..${to}`,
    ],
    { cwd: repoDir, stdout: "pipe", stderr: "pipe" }
  );
  const out = await new Response(proc.stdout).text();
  await proc.exited;
  return out
    .trim()
    .split("\n")
    .filter(Boolean)
    .slice(0, 500)
    .map((line) => {
      const [sha, message, author, date] = line.split("\0");
      return { sha, message, author, date };
    });
}

aiChangelog.get("/:owner/:repo/ai/changelog", async (c) => {
  const { owner, repo } = c.req.param();
  const user = c.get("user");
  const from = (c.req.query("from") || "").trim();
  const to = (c.req.query("to") || "").trim();
  const format = (c.req.query("format") || "").trim().toLowerCase();

  if (!(await repoExists(owner, repo))) {
    return c.html(
      <Layout title="Not Found" user={user}>
        <div class="empty-state">
          <h2>Repository not found</h2>
        </div>
      </Layout>,
      404
    );
  }

  const [branches, tags] = await Promise.all([
    listBranches(owner, repo).catch(() => [] as string[]),
    listTags(owner, repo).catch(
      () => [] as Array<{ name: string; sha: string; date: string }>
    ),
  ]);
  const refChoices = [
    ...branches,
    ...tags.slice(0, 25).map((t) => t.name),
  ];

  const renderForm = (opts: { error?: string; notice?: string } = {}) =>
    c.html(
      <Layout title={`AI Changelog — ${owner}/${repo}`} user={user}>
        <RepoHeader owner={owner} repo={repo} />
        <IssueNav owner={owner} repo={repo} active="code" />
        <h2 style="margin-bottom: 8px">AI Changelog</h2>
        <p style="color: var(--text-muted); margin-bottom: 20px; font-size: 14px">
          Generate release notes for any commit range. Pick a base (from) and
          a head (to) — Claude will group commits into Features / Fixes /
          Perf / Refactors / Docs / Other.
        </p>
        {opts.error && (
          <div class="auth-error" style="margin-bottom: 16px">
            {opts.error}
          </div>
        )}
        {opts.notice && (
          <div
            class="empty-state"
            style="margin-bottom: 16px; padding: 12px; text-align: left"
          >
            {opts.notice}
          </div>
        )}
        <form
          method="get"
          action={`/${owner}/${repo}/ai/changelog`}
          style="display: flex; gap: 12px; align-items: center; margin-bottom: 20px; flex-wrap: wrap"
        >
          <label style="font-size: 13px; color: var(--text-muted)">
            From
          </label>
          <input
            type="text"
            name="from"
            list="ai-changelog-refs"
            value={from}
            placeholder="v1.0.0"
            style="padding: 6px 10px"
          />
          <label style="font-size: 13px; color: var(--text-muted)">To</label>
          <input
            type="text"
            name="to"
            list="ai-changelog-refs"
            value={to}
            placeholder="main"
            style="padding: 6px 10px"
          />
          <datalist id="ai-changelog-refs">
            {refChoices.map((r) => (
              <option value={r}></option>
            ))}
          </datalist>
          <button type="submit" class="btn btn-primary">
            Generate
          </button>
        </form>
        {refChoices.length > 0 && (
          <div style="font-size: 12px; color: var(--text-muted)">
            Known refs: {refChoices.slice(0, 20).join(", ")}
            {refChoices.length > 20 ? ", …" : ""}
          </div>
        )}
      </Layout>
    );

  // No range supplied — show picker.
  if (!from || !to) {
    return renderForm();
  }

  // Resolve both refs.
  const [fromSha, toSha] = await Promise.all([
    resolveRef(owner, repo, from),
    resolveRef(owner, repo, to),
  ]);
  if (!fromSha || !toSha) {
    const which =
      !fromSha && !toSha
        ? `Could not resolve refs "${from}" or "${to}".`
        : !fromSha
        ? `Could not resolve "from" ref "${from}".`
        : `Could not resolve "to" ref "${to}".`;
    return renderForm({ error: which });
  }

  // Collect commits in range.
  let commits: RangeCommit[] = [];
  try {
    commits = await commitsInRange(owner, repo, from, to);
  } catch (err) {
    return renderForm({
      error: `Failed to read commit range: ${String(
        (err as Error).message || err
      )}`,
    });
  }

  if (commits.length === 0) {
    return renderForm({
      notice: `No commits between ${from} and ${to}.`,
    });
  }

  // Hand off to Claude (or the deterministic fallback).
  let markdown = "";
  try {
    markdown = await generateChangelog(
      `${owner}/${repo}`,
      from,
      to,
      commits
    );
  } catch (err) {
    // generateChangelog has its own no-key fallback, but network/SDK
    // failures should still return a useful page rather than a 500.
    markdown =
      `## ${to} (since ${from})\n\n` +
      commits
        .map(
          (c2) =>
            `- ${c2.message.split("\n")[0]} (${c2.sha.slice(0, 7)}) — ${
              c2.author
            }`
        )
        .join("\n") +
      `\n\n_AI generation failed: ${String(
        (err as Error).message || err
      )}_`;
  }

  // CLI / CI consumers want raw Markdown.
  if (format === "markdown") {
    return c.text(markdown, 200, { "Content-Type": "text/markdown" });
  }

  const html = renderMarkdown(markdown);

  return c.html(
    <Layout title={`AI Changelog — ${owner}/${repo}`} user={user}>
      <RepoHeader owner={owner} repo={repo} />
      <IssueNav owner={owner} repo={repo} active="code" />
      <h2 style="margin-bottom: 4px">AI Changelog</h2>
      <div style="color: var(--text-muted); font-size: 13px; margin-bottom: 16px">
        {from} <span style="opacity: 0.6">..</span> {to} —{" "}
        {commits.length} commit{commits.length !== 1 ? "s" : ""}
      </div>
      <form
        method="get"
        action={`/${owner}/${repo}/ai/changelog`}
        style="display: flex; gap: 8px; align-items: center; margin-bottom: 20px; flex-wrap: wrap"
      >
        <input
          type="text"
          name="from"
          list="ai-changelog-refs"
          value={from}
          style="padding: 6px 10px"
        />
        <span style="color: var(--text-muted)">..</span>
        <input
          type="text"
          name="to"
          list="ai-changelog-refs"
          value={to}
          style="padding: 6px 10px"
        />
        <datalist id="ai-changelog-refs">
          {refChoices.map((r) => (
            <option value={r}></option>
          ))}
        </datalist>
        <button type="submit" class="btn">
          Regenerate
        </button>
        <a
          href={`/${owner}/${repo}/ai/changelog?from=${encodeURIComponent(
            from
          )}&to=${encodeURIComponent(to)}&format=markdown`}
          class="btn"
        >
          Raw Markdown
        </a>
      </form>
      <div style="display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start">
        <div
          class="markdown-body"
          dangerouslySetInnerHTML={{ __html: html }}
        ></div>
        <div>
          <div
            style="font-size: 12px; color: var(--text-muted); margin-bottom: 6px"
          >
            Copy Markdown
          </div>
          <textarea
            readonly
            rows={24}
            style="width: 100%; font-family: var(--font-mono, monospace); font-size: 12px; padding: 10px; background: var(--bg-elevated); color: var(--text); border: 1px solid var(--border); border-radius: 6px"
            onclick="this.select()"
          >
            {markdown}
          </textarea>
        </div>
      </div>
    </Layout>
  );
});

export default aiChangelog;