[content] src/recording.ts (typescript)
 * Deletes the last N seconds of recording data from the CSV file.
 * This is a "panic button" feature that allows users to quickly remove recent sensitive data.
 * Each successive press removes more time: 10s, 20s, 30s, etc.
 */
export async function panicButton(): Promise<void> {
    if (!recording.isRecording) {
        vscode.window.showWarningMessage(vscode.l10n.t('panic.noActiveRecording'))
        logToOutput(vscode.l10n.t('panic.noActiveRecording'), 'info')
        return
    }

    if (!recording.startDateTime) {
        vscode.window.showErrorMessage(vscode.l10n.t('Recording start time not available'))
        logToOutput(vscode.l10n.t('Recording start time not available'), 'error')
        return
    }

    const exportPath = getExportPath()
    if (!exportPath) {
        vscode.window.showErrorMessage(vscode.l10n.t('Export path not available'))
        logToOutput(vscode.l10n.t('Export path not available'), 'error')
        return
    }

    const baseFilePath = generateBaseFilePath(recording.startDateTime, false, recording.customFolderName, sessionUuid)
    if (!baseFilePath) {
        vscode.window.showErrorMessage(vscode.l10n.t('Could not generate file path'))
        logToOutput(vscode.l10n.t('Could not generate file path'), 'error')
        return
    }

    const filePath = path.join(exportPath, `${baseFilePath}.csv`)
    
    try {
        // Check if file exists
        if (!fs.existsSync(filePath)) {
            vscode.window.showWarningMessage(vscode.l10n.t('panic.noRecordingFile'))
            logToOutput(vscode.l10n.t('panic.noRecordingFile'), 'info')
            return
        }

        // Read the current file content
        const fileContent = await fs.promises.readFile(filePath, 'utf-8')
        const lines = fileContent.split('
')
        
        if (lines.length <= 1) {
            vscode.window.showWarningMessage(vscode.l10n.t('panic.emptyFile'))
            logToOutput(vscode.l10n.t('panic.emptyFile'), 'info')
            return
        }

        // Increment panic button press count and calculate seconds to remove
        panicButtonPressCount++
        const secondsToRemove = panicButtonPressCount * 10 // 10s, 20s, 30s, etc.

        // Calculate the cutoff time (N seconds ago from now)
        const now = new Date().getTime()
        const cutoffTime = now - recording.startDateTime.getTime() - (secondsToRemove * 1000)

        // Keep the header line and filter out lines from the last N seconds
        const headerLine = lines[0]
        const dataLines = lines.slice(1).filter(line => {
            if (!line.trim()) return false // Skip empty lines
            
            const lineArr = line.split(/,(?=(?:[^"]*"[^"]*")*[^"]*$)/)
            if (lineArr.length < 2) return false // Skip malformed lines
            
            const timeStr = lineArr[1]
            const time = parseInt(timeStr, 10)
            
            if (isNaN(time)) return false // Skip lines with invalid time
            
            return time <= cutoffTime
        })

        // Rewrite the file with filtered content
        const newContent = [headerLine, ...dataLines].join('
')
        await fs.promises.writeFile(filePath, newContent, 'utf-8')

        // Update the sequence number to reflect the removed entries
        const removedLines = lines.length - dataLines.length - 1 // -1 for header
        if (removedLines > 0) {
            recording.sequence = Math.max(0, recording.sequence - removedLines)
        }

        // Update the panic button tooltip to show current deletion amount
        updatePanicButton()

        vscode.window.showInformationMessage(vscode.l10n.t('panic.successProgressive', { seconds: secondsToRemove }))
        logToOutput(vscode.l10n.t('panic.successProgressive', { seconds: secondsToRemove }), 'info')