Initial commit: Claude Code Project Tracker
Add comprehensive development intelligence system that tracks: - Development sessions with automatic start/stop - Full conversation history with semantic search - Tool usage and file operation analytics - Think time and engagement analysis - Git activity correlation - Learning pattern recognition - Productivity insights and metrics Features: - FastAPI backend with SQLite database - Modern web dashboard with interactive charts - Claude Code hook integration for automatic tracking - Comprehensive test suite with 100+ tests - Complete API documentation (OpenAPI/Swagger) - Privacy-first design with local data storage 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
commit
44ed9936b7
48 changed files with 9707 additions and 0 deletions
251
app/dashboard/static/js/api-client.js
Normal file
251
app/dashboard/static/js/api-client.js
Normal file
|
|
@ -0,0 +1,251 @@
|
|||
/**
|
||||
* API Client for Claude Code Project Tracker
|
||||
*/
|
||||
|
||||
class ApiClient {
|
||||
constructor(baseUrl = '') {
|
||||
this.baseUrl = baseUrl;
|
||||
}
|
||||
|
||||
async request(endpoint, options = {}) {
|
||||
const url = `${this.baseUrl}/api${endpoint}`;
|
||||
const config = {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
...options.headers
|
||||
},
|
||||
...options
|
||||
};
|
||||
|
||||
try {
|
||||
const response = await fetch(url, config);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
|
||||
return await response.json();
|
||||
} catch (error) {
|
||||
console.error(`API request failed: ${endpoint}`, error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
// Projects API
|
||||
async getProjects(limit = 50, offset = 0) {
|
||||
return this.request(`/projects?limit=${limit}&offset=${offset}`);
|
||||
}
|
||||
|
||||
async getProject(projectId) {
|
||||
return this.request(`/projects/${projectId}`);
|
||||
}
|
||||
|
||||
async getProjectTimeline(projectId, startDate = null, endDate = null) {
|
||||
let url = `/projects/${projectId}/timeline`;
|
||||
const params = new URLSearchParams();
|
||||
|
||||
if (startDate) params.append('start_date', startDate);
|
||||
if (endDate) params.append('end_date', endDate);
|
||||
|
||||
if (params.toString()) {
|
||||
url += `?${params.toString()}`;
|
||||
}
|
||||
|
||||
return this.request(url);
|
||||
}
|
||||
|
||||
async getProjectStats(projectId, days = 30) {
|
||||
return this.request(`/projects/${projectId}/stats?days=${days}`);
|
||||
}
|
||||
|
||||
// Analytics API
|
||||
async getProductivityMetrics(projectId = null, days = 30) {
|
||||
let url = `/analytics/productivity?days=${days}`;
|
||||
if (projectId) {
|
||||
url += `&project_id=${projectId}`;
|
||||
}
|
||||
return this.request(url);
|
||||
}
|
||||
|
||||
async getDevelopmentPatterns(projectId = null, days = 30) {
|
||||
let url = `/analytics/patterns?days=${days}`;
|
||||
if (projectId) {
|
||||
url += `&project_id=${projectId}`;
|
||||
}
|
||||
return this.request(url);
|
||||
}
|
||||
|
||||
async getLearningInsights(projectId = null, days = 30) {
|
||||
let url = `/analytics/learning?days=${days}`;
|
||||
if (projectId) {
|
||||
url += `&project_id=${projectId}`;
|
||||
}
|
||||
return this.request(url);
|
||||
}
|
||||
|
||||
async getAnalyticsSummary(projectId = null) {
|
||||
let url = '/analytics/summary';
|
||||
if (projectId) {
|
||||
url += `?project_id=${projectId}`;
|
||||
}
|
||||
return this.request(url);
|
||||
}
|
||||
|
||||
// Conversations API
|
||||
async searchConversations(query, projectId = null, limit = 20) {
|
||||
let url = `/conversations/search?query=${encodeURIComponent(query)}&limit=${limit}`;
|
||||
if (projectId) {
|
||||
url += `&project_id=${projectId}`;
|
||||
}
|
||||
return this.request(url);
|
||||
}
|
||||
|
||||
async getConversation(conversationId) {
|
||||
return this.request(`/conversations/${conversationId}`);
|
||||
}
|
||||
|
||||
// Activities API
|
||||
async getActivities(sessionId = null, toolName = null, limit = 50, offset = 0) {
|
||||
let url = `/activities?limit=${limit}&offset=${offset}`;
|
||||
if (sessionId) url += `&session_id=${sessionId}`;
|
||||
if (toolName) url += `&tool_name=${toolName}`;
|
||||
return this.request(url);
|
||||
}
|
||||
|
||||
async getToolUsageStats(sessionId = null, projectId = null, days = 30) {
|
||||
let url = `/activities/stats/tools?days=${days}`;
|
||||
if (sessionId) url += `&session_id=${sessionId}`;
|
||||
if (projectId) url += `&project_id=${projectId}`;
|
||||
return this.request(url);
|
||||
}
|
||||
|
||||
async getLanguageUsageStats(projectId = null, days = 30) {
|
||||
let url = `/activities/stats/languages?days=${days}`;
|
||||
if (projectId) url += `&project_id=${projectId}`;
|
||||
return this.request(url);
|
||||
}
|
||||
|
||||
// Waiting Periods API
|
||||
async getWaitingPeriods(sessionId = null, projectId = null, limit = 50, offset = 0) {
|
||||
let url = `/waiting/periods?limit=${limit}&offset=${offset}`;
|
||||
if (sessionId) url += `&session_id=${sessionId}`;
|
||||
if (projectId) url += `&project_id=${projectId}`;
|
||||
return this.request(url);
|
||||
}
|
||||
|
||||
async getEngagementStats(sessionId = null, projectId = null, days = 7) {
|
||||
let url = `/waiting/stats/engagement?days=${days}`;
|
||||
if (sessionId) url += `&session_id=${sessionId}`;
|
||||
if (projectId) url += `&project_id=${projectId}`;
|
||||
return this.request(url);
|
||||
}
|
||||
|
||||
// Git Operations API
|
||||
async getGitOperations(sessionId = null, projectId = null, operation = null, limit = 50, offset = 0) {
|
||||
let url = `/git/operations?limit=${limit}&offset=${offset}`;
|
||||
if (sessionId) url += `&session_id=${sessionId}`;
|
||||
if (projectId) url += `&project_id=${projectId}`;
|
||||
if (operation) url += `&operation=${operation}`;
|
||||
return this.request(url);
|
||||
}
|
||||
|
||||
async getCommitStats(projectId = null, days = 30) {
|
||||
let url = `/git/stats/commits?days=${days}`;
|
||||
if (projectId) url += `&project_id=${projectId}`;
|
||||
return this.request(url);
|
||||
}
|
||||
|
||||
async getGitActivityStats(projectId = null, days = 30) {
|
||||
let url = `/git/stats/activity?days=${days}`;
|
||||
if (projectId) url += `&project_id=${projectId}`;
|
||||
return this.request(url);
|
||||
}
|
||||
|
||||
// Sessions API
|
||||
async getSession(sessionId) {
|
||||
return this.request(`/sessions/${sessionId}`);
|
||||
}
|
||||
|
||||
// Health check
|
||||
async healthCheck() {
|
||||
return this.request('/../health');
|
||||
}
|
||||
}
|
||||
|
||||
// Create global API client instance
|
||||
const apiClient = new ApiClient();
|
||||
|
||||
// Utility functions for common operations
|
||||
const ApiUtils = {
|
||||
formatDuration: (minutes) => {
|
||||
if (minutes < 60) {
|
||||
return `${minutes}m`;
|
||||
}
|
||||
const hours = Math.floor(minutes / 60);
|
||||
const remainingMinutes = minutes % 60;
|
||||
return remainingMinutes > 0 ? `${hours}h ${remainingMinutes}m` : `${hours}h`;
|
||||
},
|
||||
|
||||
formatDate: (dateString) => {
|
||||
const date = new Date(dateString);
|
||||
return date.toLocaleDateString() + ' ' + date.toLocaleTimeString([], {
|
||||
hour: '2-digit',
|
||||
minute: '2-digit'
|
||||
});
|
||||
},
|
||||
|
||||
formatRelativeTime: (dateString) => {
|
||||
const date = new Date(dateString);
|
||||
const now = new Date();
|
||||
const diffMs = now - date;
|
||||
const diffMinutes = Math.floor(diffMs / (1000 * 60));
|
||||
const diffHours = Math.floor(diffMinutes / 60);
|
||||
const diffDays = Math.floor(diffHours / 24);
|
||||
|
||||
if (diffMinutes < 1) return 'just now';
|
||||
if (diffMinutes < 60) return `${diffMinutes}m ago`;
|
||||
if (diffHours < 24) return `${diffHours}h ago`;
|
||||
if (diffDays < 7) return `${diffDays}d ago`;
|
||||
|
||||
return date.toLocaleDateString();
|
||||
},
|
||||
|
||||
getToolIcon: (toolName) => {
|
||||
const icons = {
|
||||
'Edit': 'fas fa-edit',
|
||||
'Write': 'fas fa-file-alt',
|
||||
'Read': 'fas fa-eye',
|
||||
'Bash': 'fas fa-terminal',
|
||||
'Grep': 'fas fa-search',
|
||||
'Glob': 'fas fa-folder-open',
|
||||
'Task': 'fas fa-cogs',
|
||||
'WebFetch': 'fas fa-globe'
|
||||
};
|
||||
return icons[toolName] || 'fas fa-tool';
|
||||
},
|
||||
|
||||
getToolColor: (toolName) => {
|
||||
const colors = {
|
||||
'Edit': 'success',
|
||||
'Write': 'primary',
|
||||
'Read': 'info',
|
||||
'Bash': 'secondary',
|
||||
'Grep': 'warning',
|
||||
'Glob': 'info',
|
||||
'Task': 'dark',
|
||||
'WebFetch': 'primary'
|
||||
};
|
||||
return colors[toolName] || 'secondary';
|
||||
},
|
||||
|
||||
getEngagementBadge: (score) => {
|
||||
if (score >= 0.8) return { class: 'success', text: 'High' };
|
||||
if (score >= 0.5) return { class: 'warning', text: 'Medium' };
|
||||
return { class: 'danger', text: 'Low' };
|
||||
},
|
||||
|
||||
truncateText: (text, maxLength = 100) => {
|
||||
if (!text || text.length <= maxLength) return text;
|
||||
return text.substring(0, maxLength) + '...';
|
||||
}
|
||||
};
|
||||
327
app/dashboard/static/js/dashboard.js
Normal file
327
app/dashboard/static/js/dashboard.js
Normal file
|
|
@ -0,0 +1,327 @@
|
|||
/**
|
||||
* Dashboard JavaScript functionality
|
||||
*/
|
||||
|
||||
let productivityChart = null;
|
||||
let toolsChart = null;
|
||||
|
||||
async function loadDashboardData() {
|
||||
try {
|
||||
// Show loading state
|
||||
showLoadingState();
|
||||
|
||||
// Load data in parallel
|
||||
const [
|
||||
analyticsSummary,
|
||||
productivityMetrics,
|
||||
toolUsageStats,
|
||||
recentProjects
|
||||
] = await Promise.all([
|
||||
apiClient.getAnalyticsSummary(),
|
||||
apiClient.getProductivityMetrics(null, 30),
|
||||
apiClient.getToolUsageStats(null, null, 30),
|
||||
apiClient.getProjects(5, 0)
|
||||
]);
|
||||
|
||||
// Update summary cards
|
||||
updateSummaryCards(analyticsSummary);
|
||||
|
||||
// Update engagement metrics
|
||||
updateEngagementMetrics(productivityMetrics);
|
||||
|
||||
// Update charts
|
||||
updateProductivityChart(productivityMetrics.productivity_trends);
|
||||
updateToolsChart(toolUsageStats);
|
||||
|
||||
// Update recent projects
|
||||
updateRecentProjects(recentProjects);
|
||||
|
||||
// Update quick stats
|
||||
updateQuickStats(analyticsSummary);
|
||||
|
||||
} catch (error) {
|
||||
console.error('Failed to load dashboard data:', error);
|
||||
showErrorState('Failed to load dashboard data. Please try refreshing the page.');
|
||||
}
|
||||
}
|
||||
|
||||
function showLoadingState() {
|
||||
// Update cards with loading state
|
||||
document.getElementById('total-sessions').textContent = '-';
|
||||
document.getElementById('total-time').textContent = '-';
|
||||
document.getElementById('active-projects').textContent = '-';
|
||||
document.getElementById('productivity-score').textContent = '-';
|
||||
}
|
||||
|
||||
function showErrorState(message) {
|
||||
// Show error message
|
||||
const alertHtml = `
|
||||
<div class="alert alert-warning alert-dismissible fade show" role="alert">
|
||||
<i class="fas fa-exclamation-triangle me-2"></i>
|
||||
${message}
|
||||
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
|
||||
</div>
|
||||
`;
|
||||
|
||||
const container = document.querySelector('.container');
|
||||
container.insertAdjacentHTML('afterbegin', alertHtml);
|
||||
}
|
||||
|
||||
function updateSummaryCards(summary) {
|
||||
const overview = summary.overview || {};
|
||||
|
||||
document.getElementById('total-sessions').textContent =
|
||||
overview.total_sessions?.toLocaleString() || '0';
|
||||
|
||||
document.getElementById('total-time').textContent =
|
||||
overview.total_time_hours?.toFixed(1) || '0';
|
||||
|
||||
document.getElementById('active-projects').textContent =
|
||||
overview.projects_tracked?.toLocaleString() || '0';
|
||||
|
||||
document.getElementById('productivity-score').textContent =
|
||||
overview.productivity_indicators?.productivity_score?.toFixed(0) || '0';
|
||||
}
|
||||
|
||||
function updateEngagementMetrics(metrics) {
|
||||
document.getElementById('engagement-score').textContent =
|
||||
metrics.engagement_score?.toFixed(0) || '-';
|
||||
|
||||
document.getElementById('avg-session-length').textContent =
|
||||
metrics.average_session_length?.toFixed(0) || '-';
|
||||
|
||||
document.getElementById('think-time').textContent =
|
||||
metrics.think_time_average?.toFixed(0) || '-';
|
||||
}
|
||||
|
||||
function updateProductivityChart(trendsData) {
|
||||
const ctx = document.getElementById('productivityChart').getContext('2d');
|
||||
|
||||
// Destroy existing chart
|
||||
if (productivityChart) {
|
||||
productivityChart.destroy();
|
||||
}
|
||||
|
||||
const labels = trendsData.map(item => {
|
||||
const date = new Date(item.date);
|
||||
return date.toLocaleDateString('en-US', { month: 'short', day: 'numeric' });
|
||||
});
|
||||
|
||||
const data = trendsData.map(item => item.score);
|
||||
|
||||
productivityChart = new Chart(ctx, {
|
||||
type: 'line',
|
||||
data: {
|
||||
labels: labels,
|
||||
datasets: [{
|
||||
label: 'Productivity Score',
|
||||
data: data,
|
||||
borderColor: '#007bff',
|
||||
backgroundColor: 'rgba(0, 123, 255, 0.1)',
|
||||
borderWidth: 2,
|
||||
fill: true,
|
||||
tension: 0.4
|
||||
}]
|
||||
},
|
||||
options: {
|
||||
responsive: true,
|
||||
maintainAspectRatio: false,
|
||||
plugins: {
|
||||
legend: {
|
||||
display: false
|
||||
}
|
||||
},
|
||||
scales: {
|
||||
y: {
|
||||
beginAtZero: true,
|
||||
max: 100,
|
||||
ticks: {
|
||||
callback: function(value) {
|
||||
return value + '%';
|
||||
}
|
||||
}
|
||||
},
|
||||
x: {
|
||||
ticks: {
|
||||
maxTicksLimit: 7
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function updateToolsChart(toolsData) {
|
||||
const ctx = document.getElementById('toolsChart').getContext('2d');
|
||||
|
||||
// Destroy existing chart
|
||||
if (toolsChart) {
|
||||
toolsChart.destroy();
|
||||
}
|
||||
|
||||
// Get top 5 tools
|
||||
const topTools = toolsData.slice(0, 5);
|
||||
const labels = topTools.map(item => item.tool_name);
|
||||
const data = topTools.map(item => item.usage_count);
|
||||
|
||||
const colors = [
|
||||
'#007bff', '#28a745', '#17a2b8', '#ffc107', '#dc3545'
|
||||
];
|
||||
|
||||
toolsChart = new Chart(ctx, {
|
||||
type: 'doughnut',
|
||||
data: {
|
||||
labels: labels,
|
||||
datasets: [{
|
||||
data: data,
|
||||
backgroundColor: colors,
|
||||
borderWidth: 2,
|
||||
borderColor: '#fff'
|
||||
}]
|
||||
},
|
||||
options: {
|
||||
responsive: true,
|
||||
maintainAspectRatio: false,
|
||||
plugins: {
|
||||
legend: {
|
||||
position: 'bottom',
|
||||
labels: {
|
||||
padding: 20,
|
||||
usePointStyle: true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function updateRecentProjects(projects) {
|
||||
const container = document.getElementById('recent-projects');
|
||||
|
||||
if (!projects.length) {
|
||||
container.innerHTML = `
|
||||
<div class="text-center text-muted py-4">
|
||||
<i class="fas fa-folder-open fa-2x mb-2"></i>
|
||||
<p>No projects found</p>
|
||||
</div>
|
||||
`;
|
||||
return;
|
||||
}
|
||||
|
||||
const projectsHtml = projects.map(project => `
|
||||
<div class="project-item fade-in">
|
||||
<div class="d-flex justify-content-between align-items-start">
|
||||
<div>
|
||||
<div class="project-title">${project.name}</div>
|
||||
<div class="project-path">${project.path}</div>
|
||||
<div class="project-stats mt-2">
|
||||
<span class="me-3">
|
||||
<i class="fas fa-clock me-1"></i>
|
||||
${ApiUtils.formatDuration(project.total_time_minutes)}
|
||||
</span>
|
||||
<span class="me-3">
|
||||
<i class="fas fa-play-circle me-1"></i>
|
||||
${project.total_sessions} sessions
|
||||
</span>
|
||||
${project.languages ? `
|
||||
<span>
|
||||
<i class="fas fa-code me-1"></i>
|
||||
${project.languages.slice(0, 2).join(', ')}
|
||||
</span>
|
||||
` : ''}
|
||||
</div>
|
||||
</div>
|
||||
<small class="text-muted">
|
||||
${ApiUtils.formatRelativeTime(project.last_activity)}
|
||||
</small>
|
||||
</div>
|
||||
</div>
|
||||
`).join('');
|
||||
|
||||
container.innerHTML = projectsHtml;
|
||||
}
|
||||
|
||||
function updateQuickStats(summary) {
|
||||
const container = document.getElementById('quick-stats');
|
||||
const recent = summary.recent_activity || {};
|
||||
|
||||
const statsHtml = `
|
||||
<div class="row g-3">
|
||||
<div class="col-sm-6">
|
||||
<div class="d-flex align-items-center">
|
||||
<div class="flex-shrink-0">
|
||||
<i class="fas fa-calendar-week fa-2x text-primary"></i>
|
||||
</div>
|
||||
<div class="flex-grow-1 ms-3">
|
||||
<div class="fw-bold">${recent.sessions_last_7_days || 0}</div>
|
||||
<small class="text-muted">Sessions this week</small>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
<div class="d-flex align-items-center">
|
||||
<div class="flex-shrink-0">
|
||||
<i class="fas fa-clock fa-2x text-success"></i>
|
||||
</div>
|
||||
<div class="flex-grow-1 ms-3">
|
||||
<div class="fw-bold">${(recent.time_last_7_days_hours || 0).toFixed(1)}h</div>
|
||||
<small class="text-muted">Time this week</small>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
<div class="d-flex align-items-center">
|
||||
<div class="flex-shrink-0">
|
||||
<i class="fas fa-chart-line fa-2x text-info"></i>
|
||||
</div>
|
||||
<div class="flex-grow-1 ms-3">
|
||||
<div class="fw-bold">${(recent.daily_average_last_week || 0).toFixed(1)}</div>
|
||||
<small class="text-muted">Daily average</small>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
<div class="d-flex align-items-center">
|
||||
<div class="flex-shrink-0">
|
||||
<i class="fas fa-fire fa-2x text-warning"></i>
|
||||
</div>
|
||||
<div class="flex-grow-1 ms-3">
|
||||
<div class="fw-bold">${summary.overview?.tracking_period_days || 0}</div>
|
||||
<small class="text-muted">Days tracked</small>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
container.innerHTML = statsHtml;
|
||||
}
|
||||
|
||||
function refreshDashboard() {
|
||||
// Add visual feedback
|
||||
const refreshBtn = document.querySelector('[onclick="refreshDashboard()"]');
|
||||
const icon = refreshBtn.querySelector('i');
|
||||
|
||||
icon.classList.add('fa-spin');
|
||||
refreshBtn.disabled = true;
|
||||
|
||||
loadDashboardData().finally(() => {
|
||||
icon.classList.remove('fa-spin');
|
||||
refreshBtn.disabled = false;
|
||||
});
|
||||
}
|
||||
|
||||
// Auto-refresh dashboard every 5 minutes
|
||||
setInterval(() => {
|
||||
loadDashboardData();
|
||||
}, 5 * 60 * 1000);
|
||||
|
||||
// Handle window resize for charts
|
||||
window.addEventListener('resize', () => {
|
||||
if (productivityChart) {
|
||||
productivityChart.resize();
|
||||
}
|
||||
if (toolsChart) {
|
||||
toolsChart.resize();
|
||||
}
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue