@@ -22,10 +22,9 @@ function createConfig(packageName) {
2222 configDir,
2323 binaryName,
2424 binaryPath : path . join ( configDir , binaryName ) ,
25- githubRepo : 'CodebuffAI/codebuff-community' ,
25+
2626 userAgent : `${ packageName } -cli` ,
2727 requestTimeout : 20000 ,
28- isPrerelease : true , // codecane always looks for prereleases
2928 }
3029}
3130
@@ -70,13 +69,6 @@ function httpGet(url, options = {}) {
7069 } ,
7170 }
7271
73- // Add GitHub token if available
74- const token = process . env . GITHUB_TOKEN
75- if ( token ) {
76- console . log ( 'Using your GITHUB_TOKEN to download the latest version.' )
77- reqOptions . headers . Authorization = `Bearer ${ token } `
78- }
79-
8072 const req = https . get ( reqOptions , ( res ) => {
8173 if ( res . statusCode === 302 || res . statusCode === 301 ) {
8274 return httpGet ( new URL ( res . headers . location , url ) . href , options )
@@ -98,44 +90,17 @@ function httpGet(url, options = {}) {
9890
9991async function getLatestVersion ( ) {
10092 try {
93+ // Use the direct /latest endpoint for stable releases
10194 const res = await httpGet (
102- `https://github.com /${ CONFIG . githubRepo } /releases.atom `
95+ `https://registry.npmjs.org /${ packageName } /latest `
10396 )
10497
10598 if ( res . statusCode !== 200 ) return null
10699
107100 const body = await streamToString ( res )
101+ const packageData = JSON . parse ( body )
108102
109- // Parse the Atom XML to extract releases
110- const tagMatches = body . match (
111- / < i d > t a g : g i t h u b \. c o m , 2 0 0 8 : R e p o s i t o r y \/ \d + \/ ( [ ^ < ] + ) < \/ i d > / g
112- )
113-
114- if ( ! tagMatches ) return null
115-
116- // Extract all version tags
117- const versions = tagMatches
118- . map ( ( match ) => {
119- const tagMatch = match . match (
120- / < i d > t a g : g i t h u b \. c o m , 2 0 0 8 : R e p o s i t o r y \/ \d + \/ ( [ ^ < ] + ) < \/ i d > /
121- )
122- return tagMatch ? tagMatch [ 1 ] . replace ( / ^ v / , '' ) : null
123- } )
124- . filter ( Boolean )
125-
126- if ( versions . length === 0 ) return null
127-
128- // Filter versions based on whether we want prereleases or stable releases
129- const filteredVersions = versions . filter ( ( version ) => {
130- const isPrerelease = version . includes ( '-' )
131- return CONFIG . isPrerelease === isPrerelease
132- } )
133-
134- if ( filteredVersions . length === 0 ) return null
135-
136- // Sort and return the latest version
137- filteredVersions . sort ( compareVersions )
138- return filteredVersions [ filteredVersions . length - 1 ]
103+ return packageData . version || null
139104 } catch ( error ) {
140105 return null
141106 }
@@ -284,7 +249,9 @@ async function downloadBinary(version) {
284249 throw new Error ( `Unsupported platform: ${ process . platform } ${ process . arch } ` )
285250 }
286251
287- const downloadUrl = `https://github.com/${ CONFIG . githubRepo } /releases/download/v${ version } /${ fileName } `
252+ // For now, we get version info from npm but still download binaries from GitHub
253+ // TODO: This assumes GitHub releases still exist with the same naming convention
254+ const downloadUrl = `https://github.com/CodebuffAI/codebuff-community/releases/download/v${ version } /${ fileName } `
288255
289256 // Ensure config directory exists
290257 fs . mkdirSync ( CONFIG . configDir , { recursive : true } )
@@ -413,14 +380,10 @@ async function checkForUpdates(runningProcess, exitListener) {
413380 await downloadBinary ( latestVersion )
414381
415382 // Restart with new binary - this replaces the current process
416- const newChild = spawn (
417- CONFIG . binaryPath ,
418- process . argv . slice ( 2 ) ,
419- {
420- stdio : 'inherit' ,
421- detached : false ,
422- }
423- )
383+ const newChild = spawn ( CONFIG . binaryPath , process . argv . slice ( 2 ) , {
384+ stdio : 'inherit' ,
385+ detached : false ,
386+ } )
424387
425388 // Set up exit handler for the new process
426389 newChild . on ( 'exit' , ( code ) => {
@@ -448,13 +411,9 @@ async function main() {
448411 await ensureBinaryExists ( )
449412
450413 // Start the binary with codecane argument
451- const child = spawn (
452- CONFIG . binaryPath ,
453- process . argv . slice ( 2 ) ,
454- {
455- stdio : 'inherit' ,
456- }
457- )
414+ const child = spawn ( CONFIG . binaryPath , process . argv . slice ( 2 ) , {
415+ stdio : 'inherit' ,
416+ } )
458417
459418 // Store reference to the exit listener so we can remove it during updates
460419 const exitListener = ( code ) => {
0 commit comments