<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Repository Analysis: {{repository_name}}</title>
<script src="https://unpkg.com/lucide@latest/dist/umd/lucide.js"></script>
<style>
:root {
--bg-primary: #1a1a1a;
--bg-secondary: #2a2a2a;
--bg-tertiary: #3a3a3a;
--text-primary: #e5e5e5;
--text-secondary: #b5b5b5;
--text-muted: #888;
--accent-primary: #4f9cf9;
--accent-secondary: #7c3aed;
--border-color: #404040;
--hover-color: #333333;
--code-bg: #252525;
}
* {
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Inter', sans-serif;
line-height: 1.6;
margin: 0;
padding: 20px;
background-color: var(--bg-primary);
color: var(--text-primary);
font-size: 14px;
}
.container {
max-width: 1400px;
margin: 0 auto;
background: var(--bg-secondary);
border-radius: 12px;
border: 1px solid var(--border-color);
overflow: hidden;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}
.header {
background: rgba(255, 255, 255, 0.03);
backdrop-filter: blur(20px);
-webkit-backdrop-filter: blur(20px);
border: 1px solid rgba(255, 255, 255, 0.08);
border-bottom: 1px solid rgba(255, 255, 255, 0.02);
color: white;
padding: 32px;
position: relative;
overflow: hidden;
}
.header::before {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background:
radial-gradient(circle at 20% 30%, rgba(255, 255, 255, 0.02) 0%, transparent 50%),
radial-gradient(circle at 80% 70%, rgba(255, 255, 255, 0.01) 0%, transparent 50%);
pointer-events: none;
}
.header::after {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: url("data:image/svg+xml,%3csvg width='40' height='40' viewBox='0 0 40 40' xmlns='http://www.w3.org/2000/svg'%3e%3cg fill='none' fill-rule='evenodd'%3e%3cg fill='%23ffffff' fill-opacity='0.02'%3e%3ccircle cx='20' cy='20' r='1'/%3e%3c/g%3e%3c/g%3e%3c/svg%3e");
pointer-events: none;
}
.header h1 {
margin: 0;
font-size: 32px;
font-weight: 700;
display: flex;
align-items: center;
gap: 12px;
position: relative;
z-index: 1;
}
.header .meta {
margin-top: 20px;
opacity: 0.9;
font-size: 13px;
position: relative;
z-index: 1;
display: flex;
justify-content: space-between;
flex-wrap: wrap;
gap: 16px;
}
.meta-item {
display: flex;
align-items: center;
gap: 6px;
background: rgba(255, 255, 255, 0.08);
padding: 8px 12px;
border-radius: 20px;
border: 1px solid rgba(255, 255, 255, 0.1);
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
transition: all 0.3s ease;
}
.meta-item:hover {
background: rgba(255, 255, 255, 0.12);
transform: translateY(-1px);
}
.stats {
background: var(--bg-tertiary);
padding: 24px;
border-bottom: 1px solid var(--border-color);
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 24px;
}
.stat {
text-align: center;
padding: 20px;
background: var(--bg-secondary);
border-radius: 8px;
border: 1px solid var(--border-color);
transition: all 0.2s ease;
}
.stat:hover {
transform: translateY(-2px);
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}
.stat-value {
font-size: 28px;
font-weight: 700;
color: var(--accent-primary);
display: flex;
align-items: center;
justify-content: center;
gap: 8px;
margin-bottom: 8px;
}
.stat-label {
font-size: 12px;
text-transform: uppercase;
color: var(--text-muted);
letter-spacing: 0.5px;
font-weight: 500;
}
.toc {
background: var(--bg-tertiary);
padding: 24px;
border-bottom: 1px solid var(--border-color);
}
.toc h3 {
margin: 0 0 20px 0;
font-size: 18px;
color: var(--text-primary);
display: flex;
align-items: center;
gap: 8px;
font-weight: 600;
}
.toc ul {
margin: 0;
padding: 0;
list-style: none;
display: grid;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
gap: 8px;
}
.toc li {
margin: 0;
}
.toc a {
color: var(--text-secondary);
text-decoration: none;
font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;
font-size: 13px;
display: flex;
align-items: center;
gap: 8px;
padding: 8px 12px;
border-radius: 6px;
transition: all 0.2s ease;
}
.toc a:hover {
color: var(--accent-primary);
background: var(--hover-color);
}
.file-list {
max-height: 400px;
overflow-y: auto;
border-bottom: 1px solid var(--border-color);
background: var(--bg-secondary);
}
.file-item {
padding: 16px 24px;
border-bottom: 1px solid var(--border-color);
display: flex;
justify-content: space-between;
align-items: center;
transition: all 0.2s ease;
}
.file-item:hover {
background-color: var(--hover-color);
}
.file-item:last-child {
border-bottom: none;
}
.file-name {
font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;
font-size: 13px;
color: var(--text-primary);
display: flex;
align-items: center;
gap: 8px;
}
.file-meta {
font-size: 12px;
color: var(--text-muted);
}
.content {
padding: 24px;
background: var(--bg-secondary);
}
.file-section {
margin-bottom: 32px;
border: 1px solid var(--border-color);
border-radius: 8px;
overflow: hidden;
background: var(--bg-primary);
}
.file-header {
background: var(--bg-tertiary);
padding: 16px 20px;
border-bottom: 1px solid var(--border-color);
font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;
font-weight: 600;
font-size: 14px;
color: var(--text-primary);
display: flex;
align-items: center;
gap: 8px;
}
.file-content {
max-height: 600px;
overflow-y: auto;
position: relative;
}
.file-content::-webkit-scrollbar {
width: 8px;
}
.file-content::-webkit-scrollbar-track {
background: var(--bg-secondary);
}
.file-content::-webkit-scrollbar-thumb {
background: var(--border-color);
border-radius: 4px;
}
.file-content::-webkit-scrollbar-thumb:hover {
background: var(--text-muted);
}
pre {
margin: 0;
padding: 24px;
background: var(--code-bg);
font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;
font-size: 13px;
line-height: 1.5;
white-space: pre-wrap;
word-wrap: break-word;
color: var(--text-primary);
}
.icon {
width: 16px;
height: 16px;
}
.icon-lg {
width: 20px;
height: 20px;
}
.tree-container {
height: 400px;
background: var(--bg-secondary);
border: 1px solid var(--border-color);
border-radius: 8px;
overflow-y: auto;
padding: 8px;
}
.tree-node {
display: flex;
align-items: center;
padding: 6px 8px;
cursor: pointer;
font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;
font-size: 13px;
color: var(--text-secondary);
transition: all 0.2s ease;
user-select: none;
border-radius: 4px;
margin: 1px 0;
}
.tree-node:hover {
background: var(--hover-color);
color: var(--accent-primary);
}
.tree-node.selected {
background: var(--accent-primary);
color: white;
}
.tree-node-content {
display: flex;
align-items: center;
gap: 6px;
flex: 1;
width: 100%;
}
.tree-arrow {
width: 16px;
height: 16px;
display: flex;
align-items: center;
justify-content: center;
margin-right: 4px;
transition: transform 0.2s ease;
flex-shrink: 0;
opacity: 0.6;
}
.tree-arrow.expanded {
transform: rotate(90deg);
}
.tree-arrow.hidden {
opacity: 0;
}
.tree-icon {
width: 16px;
height: 16px;
flex-shrink: 0;
}
.tree-label {
flex: 1;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
min-width: 0;
}
.folder-icon {
color: var(--accent-secondary);
}
.file-icon {
color: var(--text-secondary);
}
.tree-children {
margin-left: 20px;
display: none;
}
.tree-children.expanded {
display: block;
}
.tree-folder.expanded > .tree-children {
display: block;
}
.tree-container::-webkit-scrollbar {
width: 8px;
}
.tree-container::-webkit-scrollbar-track {
background: var(--bg-tertiary);
}
.tree-container::-webkit-scrollbar-thumb {
background: var(--border-color);
border-radius: 4px;
}
.tree-container::-webkit-scrollbar-thumb:hover {
background: var(--text-muted);
}
@media (max-width: 768px) {
body {
padding: 12px;
}
.header {
padding: 20px;
}
.header h1 {
font-size: 24px;
}
.header .meta {
flex-direction: column;
align-items: stretch;
gap: 8px;
}
.meta-item {
justify-content: center;
}
.stats {
grid-template-columns: 1fr;
gap: 16px;
padding: 16px;
}
.toc ul {
grid-template-columns: 1fr;
}
.content {
padding: 16px;
}
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>
🔍 Repository Analysis
</h1>
<div class="meta">
<div class="meta-item">
<i data-lucide="cpu" class="icon"></i>
<span><strong>Algorithm:</strong> {{algorithm}}</span>
</div>
<div class="meta-item">
<i data-lucide="clock" class="icon"></i>
<span><strong>Generated:</strong> {{generated_time}}</span>
</div>
<div class="meta-item">
<i data-lucide="zap" class="icon"></i>
<span><strong>Selection Time:</strong> {{selection_time_ms}}ms</span>
</div>
</div>
</div>
<div class="stats">
<div class="stat">
<div class="stat-value">
<i data-lucide="files" class="icon-lg"></i>
{{total_files}}
</div>
<div class="stat-label">Files Selected</div>
</div>
<div class="stat">
<div class="stat-value">
<i data-lucide="hash" class="icon-lg"></i>
{{total_tokens}}
</div>
<div class="stat-label">Estimated Tokens</div>
</div>
<div class="stat">
<div class="stat-value">
<i data-lucide="hard-drive" class="icon-lg"></i>
{{total_size}}
</div>
<div class="stat-label">Total Size</div>
</div>
<div class="stat">
<div class="stat-value">
<i data-lucide="target" class="icon-lg"></i>
{{coverage_percentage}}%
</div>
<div class="stat-label">Coverage</div>
</div>
</div>
<div class="toc">
<h3>
<i data-lucide="folder-tree" class="icon"></i>
File Explorer
</h3>
<div id="file-tree-container" class="tree-container"></div>
</div>
<div class="file-list">
{{#each files}}
<div class="file-item">
<span class="file-name"><i data-lucide="{{icon}}" class="icon"></i>{{relative_path}}</span>
<span class="file-meta">{{size}} • ~{{estimated_tokens}} tokens • Score: {{importance_score}}</span>
</div>
{{/each}}
</div>
<div class="content">
{{#each files}}
<div class="file-section" id="file-{{add @index 1}}">
<div class="file-header"><i data-lucide="{{icon}}" class="icon"></i>{{relative_path}}</div>
<div class="file-content">
<pre>{{content}}</pre>
</div>
</div>
{{/each}}
</div>
</div>
<script type="text/babel">
const { useState, useCallback, useEffect } = React;
const { Tree } = ReactArborist;
// File data from Handlebars template
const fileData = [
{{#each files}}
{
path: "{{relative_path}}",
icon: "{{icon}}",
index: {{@index}},
size: "{{size}}",
tokens: "{{estimated_tokens}}",
score: "{{importance_score}}"
}{{#unless @last}},{{/unless}}
{{/each}}
];
// Build hierarchical tree structure from flat file paths
function buildTreeData(files) {
if (!files || files.length === 0) {
console.warn('No files provided to buildTreeData');
return [];
}
const nodeMap = new Map();
const rootNodes = [];
files.forEach((file, index) => {
const parts = file.path.split('/');
let currentPath = '';
for (let i = 0; i < parts.length; i++) {
const part = parts[i];
const parentPath = currentPath;
currentPath = currentPath ? `${currentPath}/${part}` : part;
const isLast = i === parts.length - 1;
if (!nodeMap.has(currentPath)) {
const node = {
id: currentPath,
name: part,
isFolder: !isLast,
path: currentPath,
fileIndex: isLast ? index : undefined,
fileData: isLast ? file : undefined
};
// Only add children array for folders
if (!isLast) {
node.children = [];
}
nodeMap.set(currentPath, node);
if (parentPath) {
const parent = nodeMap.get(parentPath);
if (parent && parent.children) {
parent.children.push(node);
}
} else {
rootNodes.push(node);
}
}
}
});
return rootNodes;
}
// Get file icon based on extension
function getFileIcon(filename) {
const ext = filename.split('.').pop().toLowerCase();
switch (ext) {
case 'js': case 'jsx': return 'file-text';
case 'ts': case 'tsx': return 'file-text';
case 'py': return 'file-text';
case 'rs': return 'file-text';
case 'go': return 'file-text';
case 'java': return 'file-text';
case 'cpp': case 'c': case 'h': return 'file-text';
case 'css': return 'file-text';
case 'html': return 'file-text';
case 'json': return 'file-text';
case 'md': return 'file-text';
case 'yml': case 'yaml': return 'file-text';
case 'xml': return 'file-text';
case 'sql': return 'file-text';
case 'sh': case 'bash': return 'file-text';
case 'dockerfile': return 'file-text';
case 'gitignore': return 'file-text';
case 'toml': return 'file-text';
case 'lock': return 'file-text';
default: return 'file-text';
}
}
// Tree Node Component
function Node({ node, style, dragHandle, tree }) {
const isFolder = node.isFolder;
const isOpen = tree.isOpen(node.id);
const handleClick = useCallback(() => {
if (isFolder) {
tree.toggle(node.id);
} else {
// Navigate to file section
const fileIndex = node.fileIndex;
if (fileIndex !== undefined) {
const element = document.getElementById(`file-${fileIndex + 1}`);
if (element) {
element.scrollIntoView({ behavior: 'smooth', block: 'start' });
}
}
}
}, [node.id, isFolder, tree, node.fileIndex]);
useEffect(() => {
// Re-initialize Lucide icons for this node
const iconElements = document.querySelectorAll('[data-lucide]');
iconElements.forEach(el => {
if (!el.querySelector('svg')) {
lucide.createIcons();
}
});
});
return (
<div
ref={dragHandle}
style={style}
className="tree-node"
onClick={handleClick}
>
<div className="tree-node-content">
{isFolder && (
<div className={`tree-arrow ${isOpen ? 'expanded' : ''}`}>
<i data-lucide="chevron-right" className="tree-icon"></i>
</div>
)}
{!isFolder && <div className="tree-arrow"></div>}
<i
data-lucide={isFolder ? 'folder' : getFileIcon(node.name)}
className={`tree-icon ${isFolder ? 'folder-icon' : 'file-icon'}`}
></i>
<span className="tree-label" title={node.path}>
{node.name}
</span>
</div>
</div>
);
}
// File Tree Component
function FileTree() {
const [treeData] = useState(() => {
console.log('Building tree data from:', fileData);
const tree = buildTreeData(fileData);
console.log('Built tree data:', tree);
return tree;
});
useEffect(() => {
// Re-initialize Lucide icons after React renders
const initIcons = () => {
try {
lucide.createIcons();
console.log('Lucide icons initialized');
} catch (error) {
console.error('Error initializing Lucide icons:', error);
}
};
// Initialize immediately and after a delay
initIcons();
setTimeout(initIcons, 100);
setTimeout(initIcons, 500);
}, []);
if (!treeData || treeData.length === 0) {
return (
<div style={{{ padding: '20px', textAlign: 'center', color: 'var(--text-muted)' }}}>
No files to display
</div>
);
}
return (
<Tree
data={treeData}
openByDefault={false}
width="100%"
height={400}
padding={25}
rowHeight={28}
indent={16}
overscanCount={8}
>
{Node}
</Tree>
);
}
// Render the component
try {
const container = document.getElementById('file-tree-container');
if (container) {
const root = ReactDOM.createRoot(container);
root.render(<FileTree />);
console.log('React tree component rendered successfully');
} else {
console.error('Could not find file-tree-container element');
}
} catch (error) {
console.error('Error rendering React tree:', error);
}
</script>
<script>
lucide.createIcons();
</script>
</body>
</html>