atlasbot: cap kb catalog lines by size
This commit is contained in:
parent
c0ce6335a7
commit
2aff855ce9
@ -106,7 +106,7 @@ class KnowledgeBase:
|
||||
except Exception:
|
||||
return
|
||||
lines.append("KB: atlas.json")
|
||||
lines.extend(atlas_json.splitlines())
|
||||
self._extend_with_limit(lines, atlas_json.splitlines(), max_chars)
|
||||
|
||||
def _append_runbooks(self, lines: list[str]) -> None:
|
||||
if not self._runbooks:
|
||||
@ -134,8 +134,19 @@ class KnowledgeBase:
|
||||
if not text:
|
||||
continue
|
||||
lines.append(f"KB File: {path.relative_to(self._base)}")
|
||||
lines.extend(text.splitlines())
|
||||
if not self._extend_with_limit(lines, text.splitlines(), max_chars):
|
||||
break
|
||||
|
||||
@staticmethod
|
||||
def _within_limit(lines: list[str], max_chars: int) -> bool:
|
||||
return sum(len(line) for line in lines) < max_chars
|
||||
|
||||
@staticmethod
|
||||
def _extend_with_limit(lines: list[str], new_lines: list[str], max_chars: int) -> bool:
|
||||
total = sum(len(line) for line in lines)
|
||||
for line in new_lines:
|
||||
if total + len(line) >= max_chars:
|
||||
return False
|
||||
lines.append(line)
|
||||
total += len(line)
|
||||
return True
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user