MCPcopy Create free account
hub / github.com/ZenNotes/zennotes / readKnownVaultsFromConfig

Function readKnownVaultsFromConfig

apps/desktop/src/mcp/vault-ops.ts:233–261  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

231 * Sorted most recently opened first.
232 */
233export async function readKnownVaultsFromConfig(): Promise<KnownVault[]> {
234 const parsed = await readConfigFile()
235 const seen = new Set<string>()
236 const out: KnownVault[] = []
237
238 const rawList = Array.isArray(parsed?.localVaults) ? parsed.localVaults : []
239 for (const entry of rawList) {
240 if (!entry || typeof entry !== 'object') continue
241 const { root, name, lastOpenedAt } = entry as Record<string, unknown>
242 if (typeof root !== 'string' || !root.trim()) continue
243 const resolved = path.resolve(root)
244 if (seen.has(resolved)) continue
245 seen.add(resolved)
246 out.push({
247 root: resolved,
248 name: typeof name === 'string' && name.trim() ? name : path.basename(resolved),
249 lastOpenedAt: typeof lastOpenedAt === 'number' ? lastOpenedAt : null
250 })
251 }
252
253 const active = typeof parsed?.vaultRoot === 'string' ? parsed.vaultRoot.trim() : ''
254 if (active && !seen.has(path.resolve(active))) {
255 const resolved = path.resolve(active)
256 out.push({ root: resolved, name: path.basename(resolved), lastOpenedAt: null })
257 }
258
259 out.sort((a, b) => (b.lastOpenedAt ?? 0) - (a.lastOpenedAt ?? 0))
260 return out
261}
262
263function expandHome(target: string): string {
264 if (target === '~') return os.homedir()

Callers 2

cmdVaultListFunction · 0.85
resolveVaultSelectorFunction · 0.85

Calls 1

readConfigFileFunction · 0.70

Tested by

no test coverage detected