mcp: сервер memo_search/memo_status/memo_reindex
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package memo.core
|
||||
|
||||
import java.io.File
|
||||
|
||||
fun resolveCollection(path: File): File {
|
||||
return if (path.name == ".memo") path.parentFile ?: path else path
|
||||
}
|
||||
|
||||
fun findCollections(root: File): List<File> {
|
||||
if (!root.isDirectory) return emptyList()
|
||||
val candidates = LinkedHashSet<File>()
|
||||
candidates.add(root)
|
||||
val q = ArrayDeque<Pair<File, Int>>()
|
||||
q.addLast(root to 0)
|
||||
while (q.isNotEmpty()) {
|
||||
val (d, depth) = q.removeFirst()
|
||||
if (depth >= 2) continue
|
||||
val children = d.listFiles() ?: continue
|
||||
for (c in children) {
|
||||
if (c.isDirectory && !c.name.startsWith(".")) {
|
||||
candidates.add(c)
|
||||
q.addLast(c to depth + 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
return candidates.filter { d ->
|
||||
d.walkTopDown()
|
||||
.maxDepth(8)
|
||||
.any { it.isFile && it.extension == "md" }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user