Skip to content

Commit c4d3ce4

Browse files
committed
refactor(tool): use DefaultFileSystem for file operations
Replace custom ProjectFileSystem adapter with DefaultFileSystem to simplify file handling in CodebaseInsightsTool.
1 parent 30707de commit c4d3ce4

File tree

1 file changed

+2
-65
lines changed

1 file changed

+2
-65
lines changed

mpp-core/src/commonMain/kotlin/cc/unitmesh/agent/tool/impl/CodebaseInsightsTool.kt

Lines changed: 2 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import cc.unitmesh.codegraph.model.CodeNode
1111
import cc.unitmesh.codegraph.model.ImportInfo
1212
import cc.unitmesh.codegraph.parser.CodeParser
1313
import cc.unitmesh.codegraph.parser.Language
14+
import cc.unitmesh.devins.filesystem.DefaultFileSystem
1415
import cc.unitmesh.devins.filesystem.ProjectFileSystem
1516
import cc.unitmesh.indexer.naming.CamelCaseSplitter
1617
import cc.unitmesh.indexer.naming.CommonSuffixRules
@@ -134,7 +135,7 @@ class CodebaseInsightsTool(
134135
private val codeParser: CodeParser = createCodeParser()
135136

136137
// ProjectFileSystem adapter for file operations
137-
private val projectFileSystem: ProjectFileSystem = createProjectFileSystemAdapter(fileSystem, projectPath)
138+
private val projectFileSystem: ProjectFileSystem = DefaultFileSystem(projectPath)
138139

139140
// Cached results for async analysis
140141
private var cachedResult: CodebaseInsightsResult? = null
@@ -588,67 +589,3 @@ class CodebaseInsightsTool(
588589
}
589590
}
590591

591-
/**
592-
* Create ProjectFileSystem adapter from ToolFileSystem
593-
*/
594-
private fun createProjectFileSystemAdapter(toolFS: ToolFileSystem, projectPath: String): ProjectFileSystem {
595-
return object : ProjectFileSystem {
596-
override fun getProjectPath() = projectPath
597-
598-
// Note: readFile is not used in this adapter since we use fileSystem.readFile directly
599-
override fun readFile(path: String): String? = null
600-
601-
override fun readFileAsBytes(path: String): ByteArray? = null // Not supported by ToolFileSystem
602-
603-
override fun writeFile(path: String, content: String) = false // Not needed for insights
604-
605-
override fun exists(path: String) = toolFS.exists(path)
606-
607-
override fun isDirectory(path: String) = toolFS.getFileInfo(path)?.isDirectory ?: false
608-
609-
override fun listFiles(path: String, pattern: String?): List<String> {
610-
return toolFS.listFiles(path)
611-
}
612-
613-
override fun searchFiles(pattern: String, maxDepth: Int, maxResults: Int): List<String> {
614-
val results = mutableListOf<String>()
615-
val extensions = setOf("kt", "java", "py", "ts", "tsx", "js", "jsx", "go", "rs", "cs")
616-
617-
fun searchRecursive(dir: String, depth: Int) {
618-
if (depth > maxDepth || results.size >= maxResults) return
619-
620-
try {
621-
val items = toolFS.listFiles(dir)
622-
for (item in items) {
623-
if (results.size >= maxResults) break
624-
625-
val fileInfo = toolFS.getFileInfo(item)
626-
if (fileInfo?.isDirectory == true) {
627-
val dirName = item.substringAfterLast("/")
628-
if (dirName !in setOf("node_modules", ".git", "build", "target", ".gradle", "dist", "kcef-cache")) {
629-
searchRecursive(item, depth + 1)
630-
}
631-
} else {
632-
val ext = item.substringAfterLast(".").lowercase()
633-
if (ext in extensions) {
634-
val fileName = item.substringAfterLast("/")
635-
if (pattern == "*" || fileName.contains(pattern.removeSurrounding("*"), ignoreCase = true)) {
636-
results.add(item)
637-
}
638-
}
639-
}
640-
}
641-
} catch (e: Exception) {
642-
// Skip directories that can't be read
643-
}
644-
}
645-
646-
searchRecursive(projectPath, 0)
647-
return results
648-
}
649-
650-
override fun resolvePath(relativePath: String): String {
651-
return if (relativePath.startsWith("/")) relativePath else "$projectPath/$relativePath"
652-
}
653-
}
654-
}

0 commit comments

Comments
 (0)