feat: add project summary

This commit is contained in:
pomelo-nwu
2025-09-08 22:55:10 +08:00
parent c33e709802
commit a321df0aae
5 changed files with 342 additions and 2 deletions

View File

@@ -44,6 +44,7 @@ export * from './utils/textUtils.js';
export * from './utils/formatters.js';
export * from './utils/filesearch/fileSearch.js';
export * from './utils/errorParsing.js';
export * from './utils/projectSummary.js';
// Export services
export * from './services/fileDiscoveryService.js';

View File

@@ -0,0 +1,123 @@
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import * as fs from 'fs/promises';
import * as path from 'path';
export interface ProjectSummaryInfo {
hasHistory: boolean;
content?: string;
timestamp?: string;
timeAgo?: string;
goalContent?: string;
planContent?: string;
totalTasks?: number;
doneCount?: number;
inProgressCount?: number;
todoCount?: number;
pendingTasks?: string[];
}
/**
* Reads and parses the project summary file to extract structured information
*/
export async function getProjectSummaryInfo(): Promise<ProjectSummaryInfo> {
const summaryPath = path.join(process.cwd(), '.qwen', 'PROJECT_SUMMARY.md');
try {
await fs.access(summaryPath);
} catch {
return {
hasHistory: false,
};
}
try {
const content = await fs.readFile(summaryPath, 'utf-8');
// Extract timestamp if available
const timestampMatch = content.match(/\*\*Update time\*\*: (.+)/);
const timestamp = timestampMatch
? timestampMatch[1]
: new Date().toISOString();
// Calculate time ago
const getTimeAgo = (timestamp: string) => {
const date = new Date(timestamp);
const now = new Date();
const diffMs = now.getTime() - date.getTime();
const diffMinutes = Math.floor(diffMs / (1000 * 60));
const diffHours = Math.floor(diffMs / (1000 * 60 * 60));
const diffDays = Math.floor(diffMs / (1000 * 60 * 60 * 24));
if (diffDays > 0) {
return `${diffDays} day${diffDays > 1 ? 's' : ''} ago`;
} else if (diffHours > 0) {
return `${diffHours} hour${diffHours > 1 ? 's' : ''} ago`;
} else if (diffMinutes > 0) {
return `${diffMinutes} minute${diffMinutes > 1 ? 's' : ''} ago`;
} else {
return 'just now';
}
};
const timeAgo = getTimeAgo(timestamp);
fs.writeFile(
'debug.md',
`timestamp: ${timestampMatch} \n${timestamp}\n timeAgo: ${timeAgo}\n`,
);
// Parse Overall Goal section
const goalSection = content.match(
/## Overall Goal\s*\n?([\s\S]*?)(?=\n## |$)/,
);
const goalContent = goalSection ? goalSection[1].trim() : '';
// Parse Current Plan section
const planSection = content.match(
/## Current Plan\s*\n?([\s\S]*?)(?=\n## |$)/,
);
const planContent = planSection ? planSection[1] : '';
const planLines = planContent.split('\n').filter((line) => line.trim());
const doneCount = planLines.filter((line) =>
line.includes('[DONE]'),
).length;
const inProgressCount = planLines.filter((line) =>
line.includes('[IN PROGRESS]'),
).length;
const todoCount = planLines.filter((line) =>
line.includes('[TODO]'),
).length;
const totalTasks = doneCount + inProgressCount + todoCount;
// Extract pending tasks
const pendingTasks = planLines
.filter(
(line) => line.includes('[TODO]') || line.includes('[IN PROGRESS]'),
)
.map((line) => line.replace(/^\d+\.\s*/, '').trim())
.slice(0, 3);
return {
hasHistory: true,
content,
timestamp,
timeAgo,
goalContent,
planContent,
totalTasks,
doneCount,
inProgressCount,
todoCount,
pendingTasks,
};
} catch (_error) {
return {
hasHistory: false,
};
}
}