freebuff 0.0.25 → 0.0.27

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 +60 -8
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -13,6 +13,40 @@ const tar = require('tar')
13
13
 
14
14
  const packageName = 'freebuff'
15
15
 
16
+ /**
17
+ * Terminal escape sequences to reset terminal state after the child process exits.
18
+ * When the binary is SIGKILL'd, it can't clean up its own terminal state.
19
+ * The wrapper (this process) survives and must reset these modes.
20
+ *
21
+ * Keep in sync with TERMINAL_RESET_SEQUENCES in cli/src/utils/renderer-cleanup.ts
22
+ */
23
+ const TERMINAL_RESET_SEQUENCES =
24
+ '\x1b[?1049l' + // Exit alternate screen buffer
25
+ '\x1b[?1000l' + // Disable X10 mouse mode
26
+ '\x1b[?1002l' + // Disable button event mouse mode
27
+ '\x1b[?1003l' + // Disable any-event mouse mode (all motion)
28
+ '\x1b[?1006l' + // Disable SGR extended mouse mode
29
+ '\x1b[?1004l' + // Disable focus reporting
30
+ '\x1b[?2004l' + // Disable bracketed paste mode
31
+ '\x1b[?25h' // Show cursor
32
+
33
+ function resetTerminal() {
34
+ try {
35
+ if (process.stdin.isTTY && process.stdin.setRawMode) {
36
+ process.stdin.setRawMode(false)
37
+ }
38
+ } catch {
39
+ // stdin may be closed
40
+ }
41
+ try {
42
+ if (process.stdout.isTTY) {
43
+ process.stdout.write(TERMINAL_RESET_SEQUENCES)
44
+ }
45
+ } catch {
46
+ // stdout may be closed
47
+ }
48
+ }
49
+
16
50
  function createConfig(packageName) {
17
51
  const homeDir = os.homedir()
18
52
  const configDir = path.join(homeDir, '.config', 'manicode')
@@ -513,18 +547,24 @@ async function checkForUpdates(runningProcess, exitListener) {
513
547
  term.clearLine()
514
548
 
515
549
  runningProcess.removeListener('exit', exitListener)
516
- runningProcess.kill('SIGTERM')
517
550
 
518
551
  await new Promise((resolve) => {
519
- runningProcess.on('exit', resolve)
552
+ let exited = false
553
+ runningProcess.once('exit', () => {
554
+ exited = true
555
+ resolve()
556
+ })
557
+ runningProcess.kill('SIGTERM')
520
558
  setTimeout(() => {
521
- if (!runningProcess.killed) {
559
+ if (!exited) {
522
560
  runningProcess.kill('SIGKILL')
561
+ // Safety: resolve after giving SIGKILL time to take effect
562
+ setTimeout(() => resolve(), 1000)
523
563
  }
524
- resolve()
525
564
  }, 5000)
526
565
  })
527
566
 
567
+ resetTerminal()
528
568
  console.log(`Update available: ${currentVersion} → ${latestVersion}`)
529
569
 
530
570
  await downloadBinary(latestVersion)
@@ -534,8 +574,14 @@ async function checkForUpdates(runningProcess, exitListener) {
534
574
  detached: false,
535
575
  })
536
576
 
537
- newChild.on('exit', (code) => {
538
- process.exit(code || 0)
577
+ newChild.on('exit', (code, signal) => {
578
+ resetTerminal()
579
+ process.exit(signal ? 1 : (code || 0))
580
+ })
581
+
582
+ newChild.on('error', (err) => {
583
+ console.error('Failed to start freebuff:', err.message)
584
+ process.exit(1)
539
585
  })
540
586
 
541
587
  return new Promise(() => {})
@@ -552,12 +598,18 @@ async function main() {
552
598
  stdio: 'inherit',
553
599
  })
554
600
 
555
- const exitListener = (code) => {
556
- process.exit(code || 0)
601
+ const exitListener = (code, signal) => {
602
+ resetTerminal()
603
+ process.exit(signal ? 1 : (code || 0))
557
604
  }
558
605
 
559
606
  child.on('exit', exitListener)
560
607
 
608
+ child.on('error', (err) => {
609
+ console.error('Failed to start freebuff:', err.message)
610
+ process.exit(1)
611
+ })
612
+
561
613
  setTimeout(() => {
562
614
  checkForUpdates(child, exitListener)
563
615
  }, 100)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "freebuff",
3
- "version": "0.0.25",
3
+ "version": "0.0.27",
4
4
  "description": "The world's strongest free coding agent",
5
5
  "license": "MIT",
6
6
  "bin": {