The open source coding agent.
TypeScript
ci: changelog script update (#6371)
Aiden Cline68043edae68c
diff --git a/script/changelog.ts b/script/changelog.tsnew file mode 100755index 00000000000..e1b91cff8a5--- /dev/null+++ b/script/changelog.ts@@ -0,0 +1,274 @@+#!/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/sst/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/sst/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/tui/")) 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 commits+}++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>>,+ sessionId: string,+ message: string,+): Promise<string> {+ console.log("summarizing commit:", message)+ const result = await opencode.client.session+ .prompt({+ path: { id: sessionId },+ 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>>) {+ const session = await opencode.client.session.create()++ const grouped = new Map<string, string[]>()++ for (const commit of commits) {+ const section = getSection(commit.areas)+ const summary = await summarizeCommit(opencode, session.data!.id, commit.message)+ const attribution = commit.author && !team.includes(commit.author) ? ` (@${commit.author})` : ""+ const entry = `- ${summary}${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/sst/opencode/compare/${fromRef}...${toRef}" --jq '.commits[] | {login: .author.login, message: .commit.message}'`.text()+ const contributors = new Map<string, 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, [])+ contributors.get(login)?.push(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"))+}diff --git a/script/publish-start.ts b/script/publish-start.tsindex 9cd6cc170de..5d1b2fb6abf 100755--- a/script/publish-start.ts+++ b/script/publish-start.ts@@ -1,162 +1,16 @@#!/usr/bin/env bunimport { $ } from "bun"-import { createOpencode } from "@opencode-ai/sdk"import { Script } from "@opencode-ai/script"+import { buildNotes, getLatestRelease } from "./changelog"-const notes = [] as string[]+let notes: string[] = []console.log("=== publishing ===\n")if (!Script.preview) {- const previous = await fetch("https://api.github.com/repos/sst/opencode/releases/latest")- .then((res) => {- if (!res.ok) throw new Error(res.statusText)- return res.json()- })- .then((data: any) => data.tag_name.replace(/^v/, ""))-- const log =- await $`git log v${previous}..HEAD --oneline --format="%h %s" -- packages/opencode packages/sdk packages/plugin packages/desktop packages/app`.text()-- const commits = log.split("\n").filter((line) => line && !line.match(/^\w+ (ignore:|test:|chore:|ci:)/i))-- const team = [- "actions-user",- "opencode",- "rekram1-node",- "thdxr",- "kommander",- "jayair",- "fwang",- "adamdotdevin",- "iamdavidhill",- "opencode-agent[bot]",- ]-- async function generateChangelog() {- const opencode = await createOpencode()- const session = await opencode.client.session.create()- console.log("generating changelog since " + previous)-- const raw = await opencode.client.session- .prompt({- path: {- id: session.data!.id,- },- body: {- model: {- providerID: "opencode",- modelID: "claude-sonnet-4-5",- },- parts: [- {- type: "text",- text: `- Analyze these commits and generate a changelog of all notable user facing changes, grouped by area.-- Each commit below includes:- - [author: username] showing the GitHub username of the commit author- - [areas: ...] showing which areas of the codebase were modified-- Commits between ${previous} and HEAD:- ${commits.join("\n")}-- Group the changes into these categories based on the [areas: ...] tags (omit any category with no changes):- - **TUI**: Changes to "opencode" area (the terminal/CLI interface)- - **Desktop**: Changes to "app" or "tauri" areas (the desktop application)- - **SDK**: Changes to "sdk" or "plugin" areas (the SDK and plugin system)- - **Extensions**: Changes to "extensions/zed", "extensions/vscode", or "github" areas (editor extensions and GitHub Action)- - **Other**: Any user-facing changes that don't fit the above categories-- Excluded areas (omit these entirely unless they contain user-facing changes like refactors that may affect behavior):- - "nix", "infra", "script" - CI/build infrastructure- - "ui", "docs", "web", "console", "enterprise", "function", "util", "identity", "slack" - internal packages-- Rules:- - Use the [areas: ...] tags to determine the correct category. If a commit touches multiple areas, put it in the most relevant user-facing category.- - ONLY include commits that have user-facing impact. Omit purely internal changes (CI, build scripts, internal tooling).- - However, DO include refactors that touch user-facing code - refactors can introduce bugs or change behavior.- - Do NOT make general statements about "improvements", be very specific about what was changed.- - For commits that are already well-written and descriptive, avoid rewording them. Simply capitalize the first letter, fix any misspellings, and ensure proper English grammar.- - DO NOT read any other commits than the ones listed above (THIS IS IMPORTANT TO AVOID DUPLICATING THINGS IN OUR CHANGELOG).- - If a commit was made and then reverted do not include it in the changelog. If the commits only include a revert but not the original commit, then include the revert in the changelog.- - Omit categories that have no changes.- - For community contributors: if the [author: username] is NOT in the team list, add (@username) at the end of the changelog entry. This is REQUIRED for all non-team contributors.- - The team members are: ${team.join(", ")}. Do NOT add @ mentions for team members.-- IMPORTANT: ONLY return the grouped changelog, do not include any other information. Do not include a preamble like "Based on my analysis..." or "Here is the changelog..."-- <example>- ## TUI- - Added experimental support for the Ty language server (@OpeOginni)- - Added /fork slash command for keyboard-friendly session forking (@ariane-emory)- - Increased retry attempts for failed requests- - Fixed model validation before executing slash commands (@devxoul)-- ## Desktop- - Added shell mode support- - Fixed prompt history navigation and optimistic prompt duplication- - Disabled pinch-to-zoom on Linux (@Brendonovich)-- ## Extensions- - Added OIDC_BASE_URL support for custom GitHub App installations (@elithrar)- </example>- `,- },- ],- },- })- .then((x) => x.data?.parts?.find((y) => y.type === "text")?.text)- opencode.server.close()- return raw- }-- const timeout = new Promise<null>((resolve) => setTimeout(() => resolve(null), 120_000))- const raw = await Promise.race([generateChangelog(), timeout])-- if (raw) {- for (const line of raw.split("\n")) {- if (line.startsWith("- ")) {- notes.push(line)- }- }- console.log("---- Generated Changelog ----")- console.log(notes.join("\n"))- console.log("-----------------------------")- } else {- console.log("Changelog generation timed out, using raw commits")- for (const commit of commits) {- const message = commit.replace(/^\w+ /, "")- notes.push(`- ${message}`)- }- }-- const compare =- await $`gh api "/repos/sst/opencode/compare/v${previous}...HEAD" --jq '.commits[] | {login: .author.login, message: .commit.message}'`.text()- const contributors = new Map<string, 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, [])- contributors.get(login)?.push(title)- }- }-- 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 commit of userCommits) {- notes.push(` - ${commit}`)- }- }- }+ const previous = await getLatestRelease()+ notes = await buildNotes(previous, "HEAD")}const pkgjsons = await Array.fromAsync(