codebuff 1.0.439 → 1.0.441

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +59 -20
  2. package/package.json +2 -1
package/index.js CHANGED
@@ -7,6 +7,7 @@ const { spawn } = require('child_process')
7
7
  const https = require('https')
8
8
  const zlib = require('zlib')
9
9
  const tar = require('tar')
10
+ const { Command } = require('commander')
10
11
 
11
12
  const CONFIG = {
12
13
  homeDir: os.homedir(),
@@ -29,19 +30,24 @@ const PLATFORM_TARGETS = {
29
30
  }
30
31
 
31
32
  // Terminal utilities
33
+ let isPrintMode = false
32
34
  const term = {
33
35
  clearLine: () => {
34
- if (process.stderr.isTTY) {
36
+ if (!isPrintMode && process.stderr.isTTY) {
35
37
  process.stderr.write('\r\x1b[K')
36
38
  }
37
39
  },
38
40
  write: (text) => {
39
- term.clearLine()
40
- process.stderr.write(text)
41
+ if (!isPrintMode) {
42
+ term.clearLine()
43
+ process.stderr.write(text)
44
+ }
41
45
  },
42
46
  writeLine: (text) => {
43
- term.clearLine()
44
- process.stderr.write(text + '\n')
47
+ if (!isPrintMode) {
48
+ term.clearLine()
49
+ process.stderr.write(text + '\n')
50
+ }
45
51
  },
46
52
  }
47
53
 
@@ -271,20 +277,30 @@ async function downloadBinary(version) {
271
277
  }
272
278
  } catch (error) {
273
279
  term.clearLine()
274
- console.error(`Extraction failed: ${error.message}`)
280
+ if (!isPrintMode) {
281
+ console.error(`Extraction failed: ${error.message}`)
282
+ }
275
283
  process.exit(1)
276
284
  }
277
285
 
278
286
  term.clearLine()
279
- console.log('Download complete! Starting Codebuff...')
287
+ if (isPrintMode) {
288
+ console.log(JSON.stringify({type: 'download', version, status: 'complete'})) }
289
+ else {
290
+ console.log('Download complete! Starting Codebuff...')
291
+ }
280
292
  }
281
293
 
282
294
  async function ensureBinaryExists() {
283
295
  if (!fs.existsSync(CONFIG.binaryPath)) {
284
296
  const version = await getLatestVersion()
285
297
  if (!version) {
286
- console.error('❌ Failed to determine latest version')
287
- console.error('Please check your internet connection and try again')
298
+ if (isPrintMode) {
299
+ console.error(JSON.stringify({type: 'error', message: 'Failed to determinie latest version.'}))
300
+ } else {
301
+ console.error('❌ Failed to determine latest version')
302
+ console.error('Please check your internet connection and try again')
303
+ }
288
304
  process.exit(1)
289
305
  }
290
306
 
@@ -292,8 +308,12 @@ async function ensureBinaryExists() {
292
308
  await downloadBinary(version)
293
309
  } catch (error) {
294
310
  term.clearLine()
295
- console.error('❌ Failed to download codebuff:', error.message)
296
- console.error('Please check your internet connection and try again')
311
+ if (isPrintMode) {
312
+ console.error(JSON.stringify({type: 'error', message: `Failed to download codebuff: ${error.message}`}))
313
+ } else {
314
+ console.error('❌ Failed to download codebuff:', error.message)
315
+ console.error('Please check your internet connection and try again')
316
+ }
297
317
  process.exit(1)
298
318
  }
299
319
  }
@@ -331,18 +351,21 @@ async function checkForUpdates(runningProcess, exitListener, retry) {
331
351
  }, 5000)
332
352
  })
333
353
 
334
- console.log(`Update available: ${currentVersion} → ${latestVersion}`)
354
+ if (!isPrintMode) {
355
+ console.log(`Update available: ${currentVersion} → ${latestVersion}`)
356
+ }
335
357
 
336
358
  await downloadBinary(latestVersion)
337
359
 
338
- await retry()
360
+ await retry(isPrintMode)
339
361
  }
340
362
  } catch (error) {
341
363
  // Silently ignore update check errors
342
364
  }
343
365
  }
344
366
 
345
- async function main(firstRun = false) {
367
+ async function main(firstRun = false, printMode = false) {
368
+ isPrintMode = printMode
346
369
  await ensureBinaryExists()
347
370
 
348
371
  let error = null
@@ -363,24 +386,40 @@ async function main(firstRun = false) {
363
386
  // Check for updates in background
364
387
  setTimeout(() => {
365
388
  if (!error) {
366
- checkForUpdates(child, exitListener, main)
389
+ checkForUpdates(child, exitListener, () => main(false, isPrintMode))
367
390
  }
368
391
  }, 100)
369
392
  }
370
393
  } catch (err) {
371
394
  error = err
372
395
  if (firstRun) {
373
- console.error('❌ Codebuff failed to start:', error.message)
374
- console.log('Redownloading Codebuff...')
396
+ if (!isPrintMode) {
397
+ console.error(' Codebuff failed to start:', error.message)
398
+ console.log('Redownloading Codebuff...')
399
+ }
375
400
  // Binary could be corrupted (killed before download completed), so delete and retry.
376
401
  fs.unlinkSync(CONFIG.binaryPath)
377
- await main()
402
+ await main(false, isPrintMode)
378
403
  }
379
404
  }
380
405
  }
381
406
 
407
+ // Setup commander
408
+ const program = new Command()
409
+ program
410
+ .name('codebuff')
411
+ .description('AI coding agent')
412
+ .option('-p, --print', 'print mode - suppress wrapper output')
413
+ .allowUnknownOption()
414
+ .parse()
415
+
416
+ const options = program.opts()
417
+ isPrintMode = options.print
418
+
382
419
  // Run the main function
383
- main(true).catch((error) => {
384
- console.error('❌ Unexpected error:', error.message)
420
+ main(true, isPrintMode).catch((error) => {
421
+ if (!isPrintMode) {
422
+ console.error('❌ Unexpected error:', error.message)
423
+ }
385
424
  process.exit(1)
386
425
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codebuff",
3
- "version": "1.0.439",
3
+ "version": "1.0.441",
4
4
  "description": "AI coding agent",
5
5
  "license": "MIT",
6
6
  "bin": {
@@ -26,6 +26,7 @@
26
26
  "node": ">=16"
27
27
  },
28
28
  "dependencies": {
29
+ "commander": "^12.0.0",
29
30
  "tar": "^6.2.0"
30
31
  },
31
32
  "repository": {