feat(mma): Implement Deep AST-Driven Context Pruning and mark track complete
This commit is contained in:
@@ -313,6 +313,12 @@ def run_worker_lifecycle(ticket: Ticket, context: WorkerContext, context_files:
|
||||
ai_client.reset_session()
|
||||
ai_client.set_provider(ai_client.get_provider(), context.model_name)
|
||||
context_injection = ""
|
||||
tokens_before = 0
|
||||
tokens_after = 0
|
||||
|
||||
def _count_tokens(text: str) -> int:
|
||||
return len(text) // 4 # Rough estimate
|
||||
|
||||
if context_files:
|
||||
parser = ASTParser(language="python")
|
||||
for i, file_path in enumerate(context_files):
|
||||
@@ -321,14 +327,26 @@ def run_worker_lifecycle(ticket: Ticket, context: WorkerContext, context_files:
|
||||
# (This is a bit simplified, but helps)
|
||||
with open(file_path, 'r', encoding='utf-8') as f:
|
||||
content = f.read()
|
||||
|
||||
tokens_before += _count_tokens(content)
|
||||
|
||||
if i == 0:
|
||||
view = parser.get_curated_view(content)
|
||||
view = parser.get_curated_view(content, path=file_path)
|
||||
elif ticket.target_file and Path(file_path).resolve() == Path(ticket.target_file).resolve() and ticket.target_symbols:
|
||||
view = parser.get_targeted_view(content, ticket.target_symbols, path=file_path)
|
||||
else:
|
||||
view = parser.get_skeleton(content)
|
||||
view = parser.get_skeleton(content, path=file_path)
|
||||
|
||||
tokens_after += _count_tokens(view)
|
||||
context_injection += f"\nFile: {file_path}\n{view}\n"
|
||||
except Exception as e:
|
||||
context_injection += f"\nError reading {file_path}: {e}\n"
|
||||
# Build a prompt for the worker
|
||||
|
||||
if tokens_before > 0:
|
||||
reduction = ((tokens_before - tokens_after) / tokens_before) * 100
|
||||
print(f"[MMA] Context pruning for {ticket.id}: {tokens_before} -> {tokens_after} tokens ({reduction:.1f}% reduction)")
|
||||
|
||||
# Build a prompt for the worker
|
||||
user_message = (
|
||||
f"You are assigned to Ticket {ticket.id}.\n"
|
||||
f"Task Description: {ticket.description}\n"
|
||||
|
||||
Reference in New Issue
Block a user