codebuff 1.0.636 → 1.0.638
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.
- package/index.js +110 -8
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -13,6 +13,40 @@ const tar = require('tar')
|
|
|
13
13
|
|
|
14
14
|
const packageName = 'codebuff'
|
|
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')
|
|
@@ -526,18 +560,24 @@ async function checkForUpdates(runningProcess, exitListener) {
|
|
|
526
560
|
term.clearLine()
|
|
527
561
|
|
|
528
562
|
runningProcess.removeListener('exit', exitListener)
|
|
529
|
-
runningProcess.kill('SIGTERM')
|
|
530
563
|
|
|
531
564
|
await new Promise((resolve) => {
|
|
532
|
-
|
|
565
|
+
let exited = false
|
|
566
|
+
runningProcess.once('exit', () => {
|
|
567
|
+
exited = true
|
|
568
|
+
resolve()
|
|
569
|
+
})
|
|
570
|
+
runningProcess.kill('SIGTERM')
|
|
533
571
|
setTimeout(() => {
|
|
534
|
-
if (!
|
|
572
|
+
if (!exited) {
|
|
535
573
|
runningProcess.kill('SIGKILL')
|
|
574
|
+
// Safety: resolve after giving SIGKILL time to take effect
|
|
575
|
+
setTimeout(() => resolve(), 1000)
|
|
536
576
|
}
|
|
537
|
-
resolve()
|
|
538
577
|
}, 5000)
|
|
539
578
|
})
|
|
540
579
|
|
|
580
|
+
resetTerminal()
|
|
541
581
|
console.log(`Update available: ${currentVersion} → ${latestVersion}`)
|
|
542
582
|
|
|
543
583
|
await downloadBinary(latestVersion)
|
|
@@ -547,8 +587,15 @@ async function checkForUpdates(runningProcess, exitListener) {
|
|
|
547
587
|
detached: false,
|
|
548
588
|
})
|
|
549
589
|
|
|
550
|
-
newChild.on('exit', (code) => {
|
|
551
|
-
|
|
590
|
+
newChild.on('exit', (code, signal) => {
|
|
591
|
+
resetTerminal()
|
|
592
|
+
printCrashDiagnostics(code, signal)
|
|
593
|
+
process.exit(signal ? 1 : (code || 0))
|
|
594
|
+
})
|
|
595
|
+
|
|
596
|
+
newChild.on('error', (err) => {
|
|
597
|
+
console.error('Failed to start codebuff:', err.message)
|
|
598
|
+
process.exit(1)
|
|
552
599
|
})
|
|
553
600
|
|
|
554
601
|
return new Promise(() => {})
|
|
@@ -558,6 +605,54 @@ async function checkForUpdates(runningProcess, exitListener) {
|
|
|
558
605
|
}
|
|
559
606
|
}
|
|
560
607
|
|
|
608
|
+
function printCrashDiagnostics(code, signal) {
|
|
609
|
+
// Windows NTSTATUS codes (unsigned DWORD)
|
|
610
|
+
const unsignedCode = code != null && code < 0 ? (code >>> 0) : code
|
|
611
|
+
const isIllegalInstruction =
|
|
612
|
+
signal === 'SIGILL' ||
|
|
613
|
+
(process.platform === 'win32' && unsignedCode === 0xC000001D)
|
|
614
|
+
const isAccessViolation =
|
|
615
|
+
signal === 'SIGSEGV' ||
|
|
616
|
+
(process.platform === 'win32' && unsignedCode === 0xC0000005)
|
|
617
|
+
const isBusError = signal === 'SIGBUS'
|
|
618
|
+
const isAbort =
|
|
619
|
+
signal === 'SIGABRT' ||
|
|
620
|
+
(process.platform === 'win32' && unsignedCode === 0xC0000409)
|
|
621
|
+
|
|
622
|
+
if (!isIllegalInstruction && !isAccessViolation && !isBusError && !isAbort) return
|
|
623
|
+
|
|
624
|
+
const exitInfo = signal ? `signal ${signal}` : `code ${code}`
|
|
625
|
+
console.error('')
|
|
626
|
+
console.error(`❌ ${packageName} exited immediately (${exitInfo})`)
|
|
627
|
+
console.error('')
|
|
628
|
+
|
|
629
|
+
if (isIllegalInstruction) {
|
|
630
|
+
console.error('Your CPU may not support the required instruction set (AVX2).')
|
|
631
|
+
console.error('This typically affects CPUs from before 2013.')
|
|
632
|
+
console.error('Unfortunately, this binary is not compatible with your system.')
|
|
633
|
+
console.error('')
|
|
634
|
+
} else if (isAccessViolation) {
|
|
635
|
+
console.error('The binary crashed with an access violation.')
|
|
636
|
+
console.error('')
|
|
637
|
+
} else if (isBusError) {
|
|
638
|
+
console.error('The binary crashed with a bus error.')
|
|
639
|
+
console.error('This may indicate a platform compatibility issue.')
|
|
640
|
+
console.error('')
|
|
641
|
+
} else if (isAbort) {
|
|
642
|
+
console.error('The binary crashed with an abort signal.')
|
|
643
|
+
console.error('')
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
console.error('System info:')
|
|
647
|
+
console.error(` Platform: ${process.platform} ${process.arch}`)
|
|
648
|
+
console.error(` Node: ${process.version}`)
|
|
649
|
+
console.error(` Binary: ${CONFIG.binaryPath}`)
|
|
650
|
+
console.error('')
|
|
651
|
+
console.error('Please report this issue at:')
|
|
652
|
+
console.error(' https://github.com/CodebuffAI/codebuff/issues')
|
|
653
|
+
console.error('')
|
|
654
|
+
}
|
|
655
|
+
|
|
561
656
|
async function main() {
|
|
562
657
|
await ensureBinaryExists()
|
|
563
658
|
|
|
@@ -565,12 +660,19 @@ async function main() {
|
|
|
565
660
|
stdio: 'inherit',
|
|
566
661
|
})
|
|
567
662
|
|
|
568
|
-
const exitListener = (code) => {
|
|
569
|
-
|
|
663
|
+
const exitListener = (code, signal) => {
|
|
664
|
+
resetTerminal()
|
|
665
|
+
printCrashDiagnostics(code, signal)
|
|
666
|
+
process.exit(signal ? 1 : (code || 0))
|
|
570
667
|
}
|
|
571
668
|
|
|
572
669
|
child.on('exit', exitListener)
|
|
573
670
|
|
|
671
|
+
child.on('error', (err) => {
|
|
672
|
+
console.error('Failed to start codebuff:', err.message)
|
|
673
|
+
process.exit(1)
|
|
674
|
+
})
|
|
675
|
+
|
|
574
676
|
setTimeout(() => {
|
|
575
677
|
checkForUpdates(child, exitListener)
|
|
576
678
|
}, 100)
|