Files
knowledge-base-framework/scripts/vault_root.py
TotenKnopfandClaude Fable 5.1 96780317a7 refactor: extract kb_framework package, build graph in memory
Scripts become thin CLIs over kb_framework (graph, query, query_tools,
vault, instructions) so the hosted read-only connector shares one
implementation with the stdio server. The MCP server builds the graph
from Markdown on demand and invalidates it on writes; refresh_graph
rebuilds in memory and reports validation problems. Pre-commit hook
validates only; index/graph.json is no longer read, written or staged
(generate-graph.py --write remains for operators). Golden fixtures pin
graph and tool payloads to the previous output. Agent and skill docs
updated to match.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-06 20:40:13 +02:00

35 lines
1.1 KiB
Python

"""Resolve the selected data directory consistently for framework command-line tools.
Also puts the framework root on `sys.path` so every script can import the
`kb_framework` package from a plain checkout without installing it.
"""
import argparse
import os
import sys
from pathlib import Path
FRAMEWORK_ROOT = Path(__file__).resolve().parents[1]
if str(FRAMEWORK_ROOT) not in sys.path:
sys.path.insert(0, str(FRAMEWORK_ROOT))
def parse_vault_args(parser: argparse.ArgumentParser) -> argparse.Namespace:
"""Add the shared CLI contract and return a validated absolute vault root."""
parser.add_argument(
"--vault-root",
help="data directory (default: KNOWLEDGE_BASE_ROOT, then framework root)",
)
args = parser.parse_args()
raw = args.vault_root if args.vault_root is not None else os.environ.get(
"KNOWLEDGE_BASE_ROOT", str(FRAMEWORK_ROOT)
)
if not raw.strip():
parser.error("vault root must not be empty")
root = Path(raw).expanduser().resolve()
if not root.is_dir():
parser.error(f"vault root must be an existing directory: {root}")
args.vault_root = root
return args