@@ -5,19 +5,36 @@ import { OpenCode } from "@opencode/client"
55import { Service } from "@opencode/client/service"
66import { rm } from "fs/promises"
77import path from "path"
8+ import { parseArgs } from "util"
89
910const root = path . resolve ( import . meta. dir , ".." )
1011const review = path . join ( root , "RELEASE_REVIEW.md" )
1112const changelog = path . join ( root , "UPCOMING_CHANGELOG.md" )
12- const version = Bun . argv [ 2 ] ?? "patch"
13+ const { values, positionals } = parseArgs ( {
14+ args : Bun . argv . slice ( 2 ) ,
15+ options : {
16+ from : { type : "string" , short : "f" } ,
17+ to : { type : "string" , short : "t" , default : "HEAD" } ,
18+ print : { type : "boolean" , default : false } ,
19+ help : { type : "boolean" , short : "h" , default : false } ,
20+ } ,
21+ allowPositionals : true ,
22+ } )
23+ const version = positionals [ 0 ] ?? "patch"
1324
14- if ( Bun . argv . includes ( "-- help" ) || Bun . argv . includes ( "-h" ) ) {
25+ if ( values . help ) {
1526 console . log ( `Usage: ./script/release.ts [major|minor|patch|version]
27+ ./script/release.ts --print [--from <tag>] [--to <ref>]
1628
1729Generates release notes and a public API review, opens the result in your
1830editor, and asks for confirmation before triggering the release workflow.
1931
20- The editor is selected from $VISUAL, then $EDITOR, and defaults to vim.` )
32+ The editor is selected from $VISUAL, then $EDITOR, and defaults to vim.
33+
34+ Options:
35+ -f, --from <tag> Previous release tag (default: latest stable V2 tag)
36+ -t, --to <ref> Ending ref (default: HEAD)
37+ --print Print the generated review and exit without releasing` )
2138 process . exit ( 0 )
2239}
2340
@@ -27,8 +44,9 @@ const input = ["major", "minor", "patch"].includes(version)
2744 ? [ "-f" , `version=${ version } ` ]
2845 : undefined
2946
30- if ( ! input || Bun . argv . length > 3 ) {
47+ if ( ! input || positionals . length > 1 || ( ! values . print && ( values . from || values . to !== "HEAD" ) ) ) {
3148 console . error ( "Usage: ./script/release.ts [major|minor|patch|version]" )
49+ console . error ( " ./script/release.ts --print [--from <tag>] [--to <ref>]" )
3250 process . exit ( 1 )
3351}
3452
@@ -37,14 +55,18 @@ process.chdir(root)
3755console . log ( "\n=== Generating changelog ===\n" )
3856await rm ( review , { force : true } )
3957await $ `git fetch origin "+refs/tags/v2.*:refs/tags/v2.*"`
40- const base = ( await $ `git tag --list "v2.*" --sort=-version:refname` . text ( ) )
41- . split ( "\n" )
42- . find ( ( tag ) => / ^ v 2 \. \d + \. \d + $ / . test ( tag ) )
58+ const base =
59+ values . from ??
60+ ( await $ `git tag --list "v2.*" --sort=-version:refname` . text ( ) ) . split ( "\n" ) . find ( ( tag ) => / ^ v 2 \. \d + \. \d + $ / . test ( tag ) )
4361if ( ! base ) throw new Error ( "No stable V2 release tag was found" )
44- console . log ( `Comparing ${ base } ..HEAD ` )
45- await generateReview ( base )
62+ console . log ( `Comparing ${ base } ..${ values . to } ` )
63+ await generateReview ( base , values . to )
4664
4765if ( ! ( await Bun . file ( review ) . exists ( ) ) ) throw new Error ( "OpenCode did not create RELEASE_REVIEW.md" )
66+ if ( values . print ) {
67+ process . stdout . write ( await Bun . file ( review ) . text ( ) )
68+ process . exit ( 0 )
69+ }
4870
4971const editor = Bun . spawn ( [ "sh" , "-c" , 'exec ${VISUAL:-${EDITOR:-vim}} "$1"' , "release" , review ] , {
5072 cwd : root ,
@@ -74,7 +96,7 @@ if (answer?.trim().toLowerCase() !== "y" && answer?.trim().toLowerCase() !== "ye
7496await $ `gh workflow run publish.yml --ref v2 ${ input } -f release_notes=${ releaseNotes } `
7597console . log ( `Triggered the ${ version } release` )
7698
77- async function generateReview ( base : string ) {
99+ async function generateReview ( base : string , head : string ) {
78100 const endpoint = await Service . ensure ( )
79101 const client = OpenCode . make ( {
80102 baseUrl : endpoint . url ,
@@ -114,7 +136,7 @@ async function generateReview(base: string) {
114136 } ) ( )
115137
116138 try {
117- await client . session . prompt ( { sessionID : session . id , text : reviewPrompt ( base ) } )
139+ await client . session . prompt ( { sessionID : session . id , text : reviewPrompt ( base , head ) } )
118140 await completed
119141 const messages = await client . message . list ( { sessionID : session . id , limit : 100 , order : "desc" } )
120142 const response = messages . data . find ( ( message ) => message . type === "assistant" )
@@ -127,14 +149,34 @@ async function generateReview(base: string) {
127149 }
128150}
129151
130- function reviewPrompt ( base : string ) {
152+ function reviewPrompt ( base : string , head : string ) {
131153 return `Create a concise pre-release review for a maintainer.
132154
133- The previous stable V2 release is ${ base } . Inspect every relevant commit and actual diff in the exact range ${ base } ..HEAD .
155+ The previous stable V2 release is ${ base } . Inspect every relevant commit and actual diff in the exact range ${ base } ..${ head } .
134156Do not compare against dev, V1 release tags, or commits outside that range. Do not rely only on commit titles. Write a
135157user-facing changelog with sections for Core, TUI, Desktop, SDK, and Extensions, omitting empty sections and changes that
136158are entirely internal. Group bug fixes separately from improvements. Preserve community contributor attribution when it
137- is available from merged pull requests.
159+ is available from merged pull requests, but never thank authors listed in .github/TEAM_MEMBERS.
160+
161+ Start the changelog with a "### Highlights" section: the few changes worth telling people about, written for humans.
162+ Pick 2 to 5 user-visible changes a user would notice, try, or share: new capabilities, clearly better workflows, or fixes
163+ for problems many users hit. Merge related small changes into one highlight. Skip internal work, refactors, tests, CI,
164+ dependency bumps, broad polish without one concrete outcome, and anything not usable in this release. When nothing
165+ qualifies, omit the section instead of padding it. Order highlights by how much users will care.
166+
167+ Before writing a highlight, read its pull request with gh pr view and confirm the behavior in the diff. Name the exact
168+ command, flag, setting, or place in the UI, and describe how to use it as the pull request does. Never invent, guess, or
169+ embellish, and avoid vague claims like "better" or "more naturally". Write each highlight as one bullet with a few-word
170+ Title Case title (lowercase short words like "and" or "to"), then one or two plain sentences in second person about what
171+ you can now do and why it matters. Vary the sentence openings, and leave contributor thanks to the detailed
172+ sections. For example:
173+
174+ - **Reopen Closed Tabs**: Right-click the new-session button in the tab bar to bring back a session you closed by
175+ mistake. ([#123](https://github.com/anomalyco/opencode/pull/123))
176+
177+ Every highlight must also appear in the detailed sections that follow. Use "###" for Highlights and each release section,
178+ "####" for Improvements and Bug fixes, and never use "#" or "##" headings in the changelog, since each release is filed
179+ under its own "##" heading.
138180
139181Put the complete editable changelog between these markers, which must each appear exactly once outside code fences:
140182
0 commit comments