GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — opencode/script/changelog.ts at dev · nickihm/opencode Expand file tree/ Copy pathchangelog.tsMore file actions executable file ·299 lines (253 loc) · 9.8 KB / Copy pathchangelog.tsFile metadata and controlsexecutable file ·299 lines (253 loc) · 9.8 KB 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 #!/usr/bin/env bun import { $ } from "bun" import { createOpencode } from "@opencode-ai/sdk" import { parseArgs } from "util" export const team = [ "actions-user", "opencode", "rekram1-node", "thdxr", "kommander", "jayair", "fwang", "adamdotdevin", "iamdavidhill", "opencode-agent[bot]", ] export async function getLatestRelease() { return fetch("https://api.github.com/repos/anomalyco/opencode/releases/latest") .then((res) => { if (!res.ok) throw new Error(res.statusText) return res.json() }) .then((data: any) => data.tag_name.replace(/^v/, "")) } type Commit = { hash: string author: string | null message: string areas: Set<string> } export async function getCommits(from: string, to: string): Promise<Commit[]> { const fromRef = from.startsWith("v") ? from : `v${from}` const toRef = to === "HEAD" ? to : to.startsWith("v") ? to : `v${to}` // Get commit data with GitHub usernames from the API const compare = await $`gh api "/repos/anomalyco/opencode/compare/${fromRef}...${toRef}" --jq '.commits[] | {sha: .sha, login: .author.login, message: .commit.message}'`.text() const commitData = new Map<string, { login: string | null; message: string }>() for (const line of compare.split("\n").filter(Boolean)) { const data = JSON.parse(line) as { sha: string; login: string | null; message: string } commitData.set(data.sha, { login: data.login, message: data.message.split("\n")[0] ?? "" }) } // Get commits that touch the relevant packages const log = await $`git log ${fromRef}..${toRef} --oneline --format="%H" -- packages/opencode packages/sdk packages/plugin packages/desktop packages/app sdks/vscode packages/extensions github`.text() const hashes = log.split("\n").filter(Boolean) const commits: Commit[] = [] for (const hash of hashes) { const data = commitData.get(hash) if (!data) continue const message = data.message if (message.match(/^(ignore:|test:|chore:|ci:|release:)/i)) continue const files = await $`git diff-tree --no-commit-id --name-only -r ${hash}`.text() const areas = new Set<string>() for (const file of files.split("\n").filter(Boolean)) { if (file.startsWith("packages/opencode/src/cli/cmd/")) areas.add("tui") else if (file.startsWith("packages/opencode/")) areas.add("core") else if (file.startsWith("packages/desktop/src-tauri/")) areas.add("tauri") else if (file.startsWith("packages/desktop/")) areas.add("app") else if (file.startsWith("packages/app/")) areas.add("app") else if (file.startsWith("packages/sdk/")) areas.add("sdk") else if (file.startsWith("packages/plugin/")) areas.add("plugin") else if (file.startsWith("packages/extensions/")) areas.add("extensions/zed") else if (file.startsWith("sdks/vscode/")) areas.add("extensions/vscode") else if (file.startsWith("github/")) areas.add("github") } if (areas.size === 0) continue commits.push({ hash: hash.slice(0, 7), author: data.login, message, areas, }) } return filterRevertedCommits(commits) } function filterRevertedCommits(commits: Commit[]): Commit[] { const revertPattern = /^Revert "(.+)"$/ const seen = new Map<string, Commit>() for (const commit of commits) { const match = commit.message.match(revertPattern) if (match) { // It's a revert - remove the original if we've seen it const original = match[1]! if (seen.has(original)) seen.delete(original) else seen.set(commit.message, commit) // Keep revert if original not in range } else { // Regular commit - remove if its revert exists, otherwise add const revertMsg = `Revert "${commit.message}"` if (seen.has(revertMsg)) seen.delete(revertMsg) else seen.set(commit.message, commit) } } return [...seen.values()] } const sections = { core: "Core", tui: "TUI", app: "Desktop", tauri: "Desktop", sdk: "SDK", plugin: "SDK", "extensions/zed": "Extensions", "extensions/vscode": "Extensions", github: "Extensions", } as const function getSection(areas: Set<string>): string { // Priority order for multi-area commits const priority = ["core", "tui", "app", "tauri", "sdk", "plugin", "extensions/zed", "extensions/vscode", "github"] for (const area of priority) { if (areas.has(area)) return sections[area as keyof typeof sections] } return "Core" } async function summarizeCommit(opencode: Awaited<ReturnType<typeof createOpencode>>, message: string): Promise<string> { console.log("summarizing commit:", message) const session = await opencode.client.session.create() const result = await opencode.client.session .prompt({ path: { id: session.data!.id }, body: { model: { providerID: "opencode", modelID: "claude-sonnet-4-5" }, tools: { "*": false, }, parts: [ { type: "text", text: `Summarize this commit message for a changelog entry. Return ONLY a single line summary starting with a capital letter. Be concise but specific. If the commit message is already well-written, just clean it up (capitalize, fix typos, proper grammar). Do not include any prefixes like "fix:" or "feat:". Commit: ${message}`, }, ], }, signal: AbortSignal.timeout(120_000), }) .then((x) => x.data?.parts?.find((y) => y.type === "text")?.text ?? message) return result.trim() } export async function generateChangelog(commits: Commit[], opencode: Awaited<ReturnType<typeof createOpencode>>) { // Summarize commits in parallel with max 10 concurrent requests const BATCH_SIZE = 10 const summaries: string[] = [] for (let i = 0; i < commits.length; i += BATCH_SIZE) { const batch = commits.slice(i, i + BATCH_SIZE) const results = await Promise.all(batch.map((c) => summarizeCommit(opencode, c.message))) summaries.push(...results) } const grouped = new Map<string, string[]>() for (let i = 0; i < commits.length; i++) { const commit = commits[i]! const section = getSection(commit.areas) const attribution = commit.author && !team.includes(commit.author) ? ` (@${commit.author})` : "" const entry = `- ${summaries[i]}${attribution}` if (!grouped.has(section)) grouped.set(section, []) grouped.get(section)!.push(entry) } const sectionOrder = ["Core", "TUI", "Desktop", "SDK", "Extensions"] const lines: string[] = [] for (const section of sectionOrder) { const entries = grouped.get(section) if (!entries || entries.length === 0) continue lines.push(`## ${section}`) lines.push(...entries) } return lines } export async function getContributors(from: string, to: string) { const fromRef = from.startsWith("v") ? from : `v${from}` const toRef = to === "HEAD" ? to : to.startsWith("v") ? to : `v${to}` const compare = await $`gh api "/repos/anomalyco/opencode/compare/${fromRef}...${toRef}" --jq '.commits[] | {login: .author.login, message: .commit.message}'`.text() const contributors = new Map<string, Set<string>>() for (const line of compare.split("\n").filter(Boolean)) { const { login, message } = JSON.parse(line) as { login: string | null; message: string } const title = message.split("\n")[0] ?? "" if (title.match(/^(ignore:|test:|chore:|ci:|release:)/i)) continue if (login && !team.includes(login)) { if (!contributors.has(login)) contributors.set(login, new Set()) contributors.get(login)!.add(title) } } return contributors } export async function buildNotes(from: string, to: string) { const commits = await getCommits(from, to) if (commits.length === 0) { return [] } console.log("generating changelog since " + from) const opencode = await createOpencode({ port: 5044 }) const notes: string[] = [] try { const lines = await generateChangelog(commits, opencode) notes.push(...lines) console.log("---- Generated Changelog ----") console.log(notes.join("\n")) console.log("-----------------------------") } catch (error) { if (error instanceof Error && error.name === "TimeoutError") { console.log("Changelog generation timed out, using raw commits") for (const commit of commits) { const attribution = commit.author && !team.includes(commit.author) ? ` (@${commit.author})` : "" notes.push(`- ${commit.message}${attribution}`) } } else { throw error } } finally { opencode.server.close() } const contributors = await getContributors(from, to) if (contributors.size > 0) { notes.push("") notes.push(`**Thank you to ${contributors.size} community contributor${contributors.size > 1 ? "s" : ""}:**`) for (const [username, userCommits] of contributors) { notes.push(`- @${username}:`) for (const c of userCommits) { notes.push(` - ${c}`) } } } return notes } // CLI entrypoint if (import.meta.main) { const { values } = parseArgs({ args: Bun.argv.slice(2), options: { from: { type: "string", short: "f" }, to: { type: "string", short: "t", default: "HEAD" }, help: { type: "boolean", short: "h", default: false }, }, }) if (values.help) { console.log(` Usage: bun script/changelog.ts [options] Options: -f, --from <version> Starting version (default: latest GitHub release) -t, --to <ref> Ending ref (default: HEAD) -h, --help Show this help message Examples: bun script/changelog.ts # Latest release to HEAD bun script/changelog.ts --from 1.0.200 # v1.0.200 to HEAD bun script/changelog.ts -f 1.0.200 -t 1.0.205 `) process.exit(0) } const to = values.to! const from = values.from ?? (await getLatestRelease()) console.log(`Generating changelog: v${from} -> ${to}\n`) const notes = await buildNotes(from, to) console.log("\n=== Final Notes ===") console.log(notes.join("\n")) } |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |