UNPKG

ailock

Version:

AI-Proof File Guard - Protect sensitive files from accidental AI modifications

57 lines 6.54 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { useState, useEffect } from 'react'; import { Box, Text, Spacer } from 'ink'; import Spinner from 'ink-spinner'; // Removed ink-table due to compatibility issues import chalk from 'chalk'; import path from 'path'; import { getRepoStatus } from '../../core/git.js'; export const StatusDashboard = ({ verbose = false, onExit }) => { const [status, setStatus] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); useEffect(() => { const loadStatus = async () => { try { setLoading(true); const repoStatus = await getRepoStatus(); setStatus(repoStatus); setError(null); } catch (err) { setError(err instanceof Error ? err.message : String(err)); } finally { setLoading(false); } }; loadStatus(); // Auto-refresh every 2 seconds const interval = setInterval(loadStatus, 2000); return () => clearInterval(interval); }, []); if (loading) { return (_jsx(Box, { flexDirection: "column", children: _jsxs(Box, { children: [_jsx(Spinner, { type: "dots" }), _jsx(Text, { children: " Loading ailock status..." })] }) })); } if (error) { return (_jsxs(Box, { flexDirection: "column", children: [_jsxs(Text, { color: "red", children: ["\u274C Error: ", error] }), _jsx(Text, { color: "gray", children: "Press Ctrl+C to exit" })] })); } if (!status) { return (_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { color: "yellow", children: "\u26A0\uFE0F No status available" }), _jsx(Text, { color: "gray", children: "Press Ctrl+C to exit" })] })); } // Prepare file status data for table const fileRows = status.protectedFiles.map(file => { const relativePath = path.relative(process.cwd(), file); const isLocked = status.lockedFiles.includes(file); return { file: relativePath, status: isLocked ? chalk.green('🔒 Locked') : chalk.yellow('🔓 Unlocked'), protected: chalk.blue('✅ Yes') }; }); const totalProtected = status.protectedFiles.length; const totalLocked = status.lockedFiles.length; const unlockedCount = totalProtected - totalLocked; return (_jsxs(Box, { flexDirection: "column", padding: 1, children: [_jsxs(Box, { marginBottom: 1, children: [_jsx(Text, { bold: true, color: "blue", children: "\uD83D\uDD12 AI-Proof File Guard - Interactive Status" }), _jsx(Spacer, {}), _jsx(Text, { color: "gray", children: "[Auto-refresh: 2s]" })] }), _jsxs(Box, { flexDirection: "column", marginBottom: 1, children: [_jsx(Text, { bold: true, color: "blue", children: "\uD83D\uDCC1 Repository Status" }), _jsxs(Box, { marginLeft: 2, children: [_jsx(Text, { children: "Git Repository: " }), _jsx(Text, { color: status.isGitRepo ? 'green' : 'gray', children: status.isGitRepo ? '✅ Detected' : '❌ Not detected' })] }), status.isGitRepo && (_jsxs(Box, { marginLeft: 2, children: [_jsx(Text, { children: "Pre-commit Hook: " }), _jsx(Text, { color: status.hasAilockHook ? 'green' : 'yellow', children: status.hasAilockHook ? '✅ Installed' : '⚠️ Not installed' })] }))] }), _jsxs(Box, { flexDirection: "column", marginBottom: 1, children: [_jsx(Text, { bold: true, color: "blue", children: "\uD83D\uDCCB Protection Summary" }), _jsxs(Box, { marginLeft: 2, children: [_jsx(Text, { children: "\uD83D\uDD12 Locked files: " }), _jsx(Text, { color: "green", bold: true, children: totalLocked })] }), unlockedCount > 0 && (_jsxs(Box, { marginLeft: 2, children: [_jsx(Text, { children: "\uD83D\uDD13 Unlocked files: " }), _jsx(Text, { color: "yellow", bold: true, children: unlockedCount })] })), _jsxs(Box, { marginLeft: 2, children: [_jsx(Text, { children: "\uD83D\uDCC4 Total protected: " }), _jsx(Text, { color: "blue", bold: true, children: totalProtected })] })] }), totalProtected > 0 && (_jsxs(Box, { flexDirection: "column", marginBottom: 1, children: [_jsx(Text, { bold: true, color: "blue", children: "\uD83D\uDCC4 Protected Files" }), fileRows.map((row, index) => (_jsx(Box, { marginLeft: 2, children: _jsxs(Text, { children: [row.status, " ", row.file] }) }, index)))] })), totalProtected === 0 && (_jsxs(Box, { marginBottom: 1, children: [_jsx(Text, { color: "gray", children: "\u2139\uFE0F No protected files found" }), _jsx(Text, { color: "gray", children: "\uD83D\uDCA1 Create .ailock file to define protection patterns" })] })), verbose && status.hookInfo && (_jsxs(Box, { flexDirection: "column", marginBottom: 1, children: [_jsx(Text, { bold: true, color: "blue", children: "\uD83E\uDE9D Git Hook Details" }), _jsx(Box, { marginLeft: 2, children: _jsxs(Text, { color: "gray", children: ["Path: ", status.hookInfo.hookPath] }) }), _jsx(Box, { marginLeft: 2, children: _jsxs(Text, { color: "gray", children: ["Exists: ", status.hookInfo.exists ? 'Yes' : 'No'] }) }), _jsx(Box, { marginLeft: 2, children: _jsxs(Text, { color: "gray", children: ["Ailock managed: ", status.hookInfo.isAilockManaged ? 'Yes' : 'No'] }) })] })), _jsxs(Box, { flexDirection: "column", marginBottom: 1, children: [_jsx(Text, { bold: true, color: "blue", children: "\uD83D\uDCA1 Recommendations" }), !status.isGitRepo && (_jsx(Box, { marginLeft: 2, children: _jsx(Text, { color: "gray", children: "\u2022 Initialize Git repository for enhanced protection" }) })), status.isGitRepo && !status.hasAilockHook && (_jsx(Box, { marginLeft: 2, children: _jsx(Text, { color: "yellow", children: "\u2022 Install pre-commit hook: ailock install-hooks" }) })), unlockedCount > 0 && (_jsx(Box, { marginLeft: 2, children: _jsx(Text, { color: "yellow", children: "\u2022 Lock unprotected files: ailock lock" }) })), totalProtected === 0 && (_jsx(Box, { marginLeft: 2, children: _jsx(Text, { color: "gray", children: "\u2022 Create .ailock file to define protection patterns" }) }))] }), _jsx(Box, { marginBottom: 1, children: status.isGitRepo && status.hasAilockHook && unlockedCount === 0 ? (_jsx(Text, { bold: true, color: "green", children: "\u2705 All protection mechanisms are active" })) : (_jsx(Text, { bold: true, color: "yellow", children: "\u26A0\uFE0F Some protection mechanisms are not active" })) }), _jsx(Box, { children: _jsx(Text, { color: "gray", children: "Press Ctrl+C to exit" }) })] })); }; //# sourceMappingURL=StatusDashboard.js.map