mirror of
https://github.com/catlog22/Claude-Code-Workflow.git
synced 2026-02-05 01:50:27 +08:00
chore: 删除不再使用的 reindex 和测试脚本
This commit is contained in:
@@ -1,141 +0,0 @@
|
||||
#!/bin/bash
|
||||
# 重新索引项目以提取代码关系数据
|
||||
# 用于解决 Graph Explorer 显示为空的问题
|
||||
|
||||
set -e
|
||||
|
||||
PROJECT_PATH="${1:-D:/Claude_dms3}"
|
||||
INDEX_DIR="$HOME/.codexlens/indexes"
|
||||
|
||||
# 规范化路径用于索引目录
|
||||
NORMALIZED_PATH=$(echo "$PROJECT_PATH" | sed 's|^/\([a-z]\)/|\U\1/|' | sed 's|^/||')
|
||||
INDEX_DB_DIR="$INDEX_DIR/$NORMALIZED_PATH"
|
||||
INDEX_DB="$INDEX_DB_DIR/_index.db"
|
||||
|
||||
echo "=========================================="
|
||||
echo "CodexLens 重新索引工具"
|
||||
echo "=========================================="
|
||||
echo "项目路径: $PROJECT_PATH"
|
||||
echo "索引路径: $INDEX_DB"
|
||||
echo ""
|
||||
|
||||
# 检查数据库是否存在
|
||||
if [ ! -f "$INDEX_DB" ]; then
|
||||
echo "❌ 索引数据库不存在: $INDEX_DB"
|
||||
echo "请先运行: codex init $PROJECT_PATH"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 检查当前数据统计
|
||||
echo "📊 当前数据统计:"
|
||||
sqlite3 "$INDEX_DB" "
|
||||
SELECT
|
||||
'文件数: ' || (SELECT COUNT(*) FROM files) ||
|
||||
' | 符号数: ' || (SELECT COUNT(*) FROM symbols) ||
|
||||
' | 关系数: ' || (SELECT COUNT(*) FROM code_relationships);
|
||||
"
|
||||
|
||||
RELATIONSHIPS_COUNT=$(sqlite3 "$INDEX_DB" "SELECT COUNT(*) FROM code_relationships;")
|
||||
|
||||
if [ "$RELATIONSHIPS_COUNT" -gt 0 ]; then
|
||||
echo ""
|
||||
echo "✅ 数据库已包含 $RELATIONSHIPS_COUNT 个代码关系"
|
||||
echo "如果 Graph Explorer 仍然显示为空,请检查前端控制台错误"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "⚠️ 检测到 code_relationships 表为空"
|
||||
echo ""
|
||||
echo "解决方案:"
|
||||
echo "1. 备份现有索引(推荐)"
|
||||
echo "2. 删除旧索引"
|
||||
echo "3. 重新索引项目"
|
||||
echo ""
|
||||
|
||||
read -p "是否继续?这将删除并重建索引。(y/N) " -n 1 -r
|
||||
echo
|
||||
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
||||
echo "已取消"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# 1. 备份现有索引
|
||||
BACKUP_DIR="$INDEX_DB_DIR/backup_$(date +%Y%m%d_%H%M%S)"
|
||||
echo ""
|
||||
echo "📦 备份现有索引到: $BACKUP_DIR"
|
||||
mkdir -p "$BACKUP_DIR"
|
||||
cp "$INDEX_DB" "$BACKUP_DIR/"
|
||||
echo "✓ 备份完成"
|
||||
|
||||
# 2. 删除旧索引
|
||||
echo ""
|
||||
echo "🗑️ 删除旧索引..."
|
||||
rm -f "$INDEX_DB"
|
||||
echo "✓ 已删除"
|
||||
|
||||
# 3. 重新索引
|
||||
echo ""
|
||||
echo "🔍 重新索引项目(这可能需要几分钟)..."
|
||||
cd "$PROJECT_PATH"
|
||||
|
||||
# 使用 CodexLens CLI 重新索引
|
||||
if command -v codex &> /dev/null; then
|
||||
codex init .
|
||||
else
|
||||
echo "❌ 未找到 codex 命令"
|
||||
echo "请先安装 CodexLens:"
|
||||
echo " cd codex-lens"
|
||||
echo " pip install -e ."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 4. 验证结果
|
||||
echo ""
|
||||
echo "📊 重新索引后的数据统计:"
|
||||
sqlite3 "$INDEX_DB" "
|
||||
SELECT
|
||||
'文件数: ' || (SELECT COUNT(*) FROM files) ||
|
||||
' | 符号数: ' || (SELECT COUNT(*) FROM symbols) ||
|
||||
' | 关系数: ' || (SELECT COUNT(*) FROM code_relationships);
|
||||
"
|
||||
|
||||
RELATIONSHIPS_AFTER=$(sqlite3 "$INDEX_DB" "SELECT COUNT(*) FROM code_relationships;")
|
||||
|
||||
echo ""
|
||||
if [ "$RELATIONSHIPS_AFTER" -gt 0 ]; then
|
||||
echo "✅ 成功!已提取 $RELATIONSHIPS_AFTER 个代码关系"
|
||||
echo ""
|
||||
echo "📋 示例关系:"
|
||||
sqlite3 "$INDEX_DB" "
|
||||
SELECT
|
||||
s.name || ' --[' || r.relationship_type || ']--> ' || r.target_qualified_name
|
||||
FROM code_relationships r
|
||||
JOIN symbols s ON r.source_symbol_id = s.id
|
||||
LIMIT 5;
|
||||
" | head -5
|
||||
echo ""
|
||||
echo "下一步:"
|
||||
echo "1. 启动 CCW Dashboard: ccw view"
|
||||
echo "2. 点击左侧边栏的 Graph 图标"
|
||||
echo "3. 应该能看到代码关系图谱"
|
||||
else
|
||||
echo "⚠️ 警告:关系数据仍然为 0"
|
||||
echo ""
|
||||
echo "可能原因:"
|
||||
echo "1. 项目中没有 Python/JavaScript/TypeScript 文件"
|
||||
echo "2. TreeSitter 解析器未正确安装"
|
||||
echo "3. 文件语法错误导致解析失败"
|
||||
echo ""
|
||||
echo "调试步骤:"
|
||||
echo "1. 检查项目语言:"
|
||||
sqlite3 "$INDEX_DB" "SELECT DISTINCT language FROM files LIMIT 10;"
|
||||
echo ""
|
||||
echo "2. 测试 GraphAnalyzer:"
|
||||
echo " python -c 'from codexlens.semantic.graph_analyzer import GraphAnalyzer; print(GraphAnalyzer(\"python\").is_available())'"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "=========================================="
|
||||
echo "完成"
|
||||
echo "=========================================="
|
||||
@@ -1,153 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Test script to verify GraphAnalyzer is working correctly.
|
||||
Checks if TreeSitter is available and can extract relationships from sample files.
|
||||
"""
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
# Add codex-lens to path
|
||||
sys.path.insert(0, str(Path(__file__).parent.parent / "codex-lens" / "src"))
|
||||
|
||||
from codexlens.semantic.graph_analyzer import GraphAnalyzer
|
||||
from codexlens.parsers.treesitter_parser import TreeSitterSymbolParser
|
||||
|
||||
def test_graph_analyzer_availability():
|
||||
"""Test if GraphAnalyzer is available for different languages."""
|
||||
print("=" * 60)
|
||||
print("Testing GraphAnalyzer Availability")
|
||||
print("=" * 60)
|
||||
|
||||
languages = ["python", "javascript", "typescript"]
|
||||
for lang in languages:
|
||||
try:
|
||||
analyzer = GraphAnalyzer(lang)
|
||||
available = analyzer.is_available()
|
||||
parser = TreeSitterSymbolParser(lang)
|
||||
parser_available = parser.is_available()
|
||||
|
||||
print(f"\n{lang.upper()}:")
|
||||
print(f" GraphAnalyzer available: {available}")
|
||||
print(f" TreeSitter parser available: {parser_available}")
|
||||
|
||||
if not available:
|
||||
print(f" [X] GraphAnalyzer NOT available for {lang}")
|
||||
else:
|
||||
print(f" [OK] GraphAnalyzer ready for {lang}")
|
||||
except Exception as e:
|
||||
print(f"\n{lang.upper()}:")
|
||||
print(f" [ERROR] Error: {e}")
|
||||
|
||||
def test_sample_file_analysis(file_path: Path):
|
||||
"""Test relationship extraction on a real file."""
|
||||
print("\n" + "=" * 60)
|
||||
print(f"Testing File: {file_path.name}")
|
||||
print("=" * 60)
|
||||
|
||||
if not file_path.exists():
|
||||
print(f"[X] File not found: {file_path}")
|
||||
return
|
||||
|
||||
# Determine language
|
||||
suffix = file_path.suffix
|
||||
lang_map = {
|
||||
'.py': 'python',
|
||||
'.js': 'javascript',
|
||||
'.ts': 'typescript',
|
||||
'.tsx': 'typescript'
|
||||
}
|
||||
language = lang_map.get(suffix)
|
||||
|
||||
if not language:
|
||||
print(f"[X] Unsupported file type: {suffix}")
|
||||
return
|
||||
|
||||
print(f"Language: {language}")
|
||||
|
||||
# Read file content
|
||||
try:
|
||||
content = file_path.read_text(encoding='utf-8')
|
||||
print(f"File size: {len(content)} characters")
|
||||
except Exception as e:
|
||||
print(f"[X] Failed to read file: {e}")
|
||||
return
|
||||
|
||||
# Test parser first
|
||||
try:
|
||||
parser = TreeSitterSymbolParser(language)
|
||||
if not parser.is_available():
|
||||
print(f"[X] TreeSitter parser not available for {language}")
|
||||
return
|
||||
|
||||
indexed_file = parser.parse(content, file_path)
|
||||
symbols = indexed_file.symbols if indexed_file else []
|
||||
print(f"[OK] Parsed {len(symbols)} symbols")
|
||||
|
||||
if symbols:
|
||||
print("\nSample symbols:")
|
||||
for i, sym in enumerate(symbols[:5], 1):
|
||||
print(f" {i}. {sym.kind:10s} {sym.name:30s}")
|
||||
except Exception as e:
|
||||
print(f"[X] Symbol parsing failed: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
return
|
||||
|
||||
# Test relationship extraction
|
||||
try:
|
||||
analyzer = GraphAnalyzer(language)
|
||||
if not analyzer.is_available():
|
||||
print(f"[X] GraphAnalyzer not available for {language}")
|
||||
return
|
||||
|
||||
relationships = analyzer.analyze_with_symbols(content, file_path, symbols)
|
||||
print(f"\n{'[OK]' if relationships else '[WARN]'} Extracted {len(relationships)} relationships")
|
||||
|
||||
if relationships:
|
||||
print("\nSample relationships:")
|
||||
for i, rel in enumerate(relationships[:10], 1):
|
||||
print(f" {i}. {rel.source_symbol:20s} --[{rel.relationship_type}]--> {rel.target_symbol} (line {rel.source_line})")
|
||||
else:
|
||||
print("\n[WARN] No relationships found")
|
||||
print(" This could be normal if the file has no function calls")
|
||||
print(" or if all calls are to external modules")
|
||||
except Exception as e:
|
||||
print(f"[X] Relationship extraction failed: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
|
||||
def main():
|
||||
"""Run all tests."""
|
||||
# Test availability
|
||||
test_graph_analyzer_availability()
|
||||
|
||||
# Test on sample files from project
|
||||
project_root = Path(__file__).parent.parent
|
||||
|
||||
sample_files = [
|
||||
project_root / "ccw" / "src" / "core" / "routes" / "graph-routes.ts",
|
||||
project_root / "codex-lens" / "src" / "codexlens" / "storage" / "dir_index.py",
|
||||
project_root / "ccw" / "src" / "templates" / "dashboard-js" / "views" / "graph-explorer.js",
|
||||
]
|
||||
|
||||
for sample_file in sample_files:
|
||||
if sample_file.exists():
|
||||
test_sample_file_analysis(sample_file)
|
||||
else:
|
||||
print(f"\nSkipping non-existent file: {sample_file}")
|
||||
|
||||
print("\n" + "=" * 60)
|
||||
print("Test Summary")
|
||||
print("=" * 60)
|
||||
print("\nIf all tests passed:")
|
||||
print(" [OK] GraphAnalyzer is working correctly")
|
||||
print(" [OK] TreeSitter parsers are installed")
|
||||
print("\nIf relationships were found:")
|
||||
print(" [OK] Relationship extraction is functional")
|
||||
print("\nNext steps:")
|
||||
print(" 1. If no relationships found, check if files have function calls")
|
||||
print(" 2. Re-run 'codex init' to re-index with relationship extraction")
|
||||
print(" 3. Check database: sqlite3 ~/.codexlens/indexes/.../\\_index.db 'SELECT COUNT(*) FROM code_relationships;'")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user