Initial commit: a0_software_orchestrator v1.0
- Auto-Registration-Bug behoben (register_project/get_project_id/resolve_project Trennung) - 25 Tests gruen (Pytest) - block_compactor-Tool refactored (Option B: Soft-Check statt Hard-Block) - 4 Restbaustellen gefixt - DB-Schema: plugin_settings-Tabelle hinzugefuegt - 3 Schattenprojekte aus DB geloescht - Plan v3 + Refactor-Plan + Worklog dokumentiert
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
"""Tool: enforce raw-output-to-file policy and compact large outputs."""
|
||||
from helpers.tool import Tool, Response
|
||||
from usr.plugins.a0_software_orchestrator.helpers.context_budget import estimate_tokens, estimate_ratio, should_warn, should_hard_compact, compact_text
|
||||
from usr.plugins.a0_software_orchestrator.helpers.safety_rules import redact_secrets
|
||||
import os
|
||||
|
||||
class ContextCompactor(Tool):
|
||||
async def execute(self, text: str = "", max_lines: int = 80, max_tokens: int = 4096, **kwargs):
|
||||
if not text:
|
||||
return Response(message="No text provided", break_loop=False)
|
||||
text = redact_secrets(text)
|
||||
tokens = estimate_tokens(text)
|
||||
ratio = estimate_ratio(tokens, max_tokens)
|
||||
if should_hard_compact(ratio):
|
||||
compacted = compact_text(text, max_lines)
|
||||
return Response(message=f"COMPACTED ({tokens} tokens, ratio {ratio:.2f}):\n{compacted}", break_loop=False)
|
||||
elif should_warn(ratio):
|
||||
return Response(message=f"WARNING: {tokens} tokens (ratio {ratio:.2f}). Consider compacting.", break_loop=False)
|
||||
return Response(message=f"OK: {tokens} tokens (ratio {ratio:.2f})", break_loop=False)
|
||||
Reference in New Issue
Block a user