feat(fase1): dimension filter on bundle_context, default unchanged (F1)

This commit is contained in:
Kjell Tore Guttormsen 2026-07-07 07:44:33 +02:00
commit 525ff0dda1
2 changed files with 54 additions and 2 deletions

View file

@ -130,14 +130,23 @@ def navigate_bundle(bundle_dir: str) -> Bundle:
return Bundle(dir=bundle_dir, files=tuple(files))
def bundle_context(bundle: Bundle) -> str:
def bundle_context(bundle: Bundle, *, dimension: str | None = None) -> str:
"""Render a navigated bundle as agent read-context via progressive disclosure: the ``index.md``
summary, then each concept file as ``## {type}: {title}\\n{body}``. ``type: verdict`` files are
EXCLUDED (målbilde §2 step 1 / §4: navigation, not chunk-stuffing the verdict layer folds in
only via the gated ExpeL retrieval). Deterministic: index first, then context files in
navigation order; empty sections are dropped."""
navigation order; empty sections are dropped.
When ``dimension`` is given, only concept files whose frontmatter ``dimension`` matches or that
carry no ``dimension`` at all (un-scoped knowledge is never dropped) are rendered; the default
``dimension=None`` renders every concept file, byte-identical to the prior behavior. ``dimension``
is a plain ``str`` (not the ``Dimension`` type) so ``okf`` stays MAF-free and import-cycle-free."""
sections = [bundle.index_summary]
for f in bundle.context_files:
if dimension is not None:
file_dim = f.frontmatter.get("dimension")
if file_dim is not None and file_dim != dimension:
continue
title = f.frontmatter.get("title", f.name).strip('"')
sections.append(f"## {f.type or 'document'}: {title}\n{f.body}")
return "\n\n".join(s for s in sections if s.strip())