remove dead code
This commit is contained in:
parent
e9c6aa7b4f
commit
7845f4d876
|
|
@ -4,18 +4,14 @@ from .fuzzy_find import fuzzy_find_project_files
|
|||
from .human import ask_human
|
||||
from .list_directory import list_directory_tree
|
||||
from .memory import (
|
||||
delete_tasks,
|
||||
deregister_related_files,
|
||||
emit_key_facts,
|
||||
emit_key_snippet,
|
||||
emit_plan,
|
||||
emit_related_files,
|
||||
emit_research_notes,
|
||||
emit_task,
|
||||
get_memory_value,
|
||||
plan_implementation_completed,
|
||||
request_implementation,
|
||||
swap_task_order,
|
||||
task_completed,
|
||||
)
|
||||
from .programmer import run_programming_task
|
||||
|
|
@ -33,10 +29,8 @@ __all__ = [
|
|||
"emit_expert_context",
|
||||
"emit_key_facts",
|
||||
"emit_key_snippet",
|
||||
"emit_plan",
|
||||
"emit_related_files",
|
||||
"emit_research_notes",
|
||||
"emit_task",
|
||||
"fuzzy_find_project_files",
|
||||
"get_memory_value",
|
||||
"list_directory_tree",
|
||||
|
|
@ -47,8 +41,6 @@ __all__ = [
|
|||
"put_complete_file_contents",
|
||||
"ripgrep_search",
|
||||
"file_str_replace",
|
||||
"delete_tasks",
|
||||
"swap_task_order",
|
||||
"monorepo_detected",
|
||||
"existing_project_detected",
|
||||
"ui_detected",
|
||||
|
|
|
|||
|
|
@ -340,10 +340,6 @@ def request_task_implementation(task_spec: str) -> str:
|
|||
)
|
||||
|
||||
# Get required parameters
|
||||
tasks = [
|
||||
_global_memory["tasks"][task_id] for task_id in sorted(_global_memory["tasks"])
|
||||
]
|
||||
plan = _global_memory.get("plan", "")
|
||||
related_files = list(_global_memory["related_files"].values())
|
||||
|
||||
try:
|
||||
|
|
@ -355,9 +351,9 @@ def request_task_implementation(task_spec: str) -> str:
|
|||
|
||||
_result = run_task_implementation_agent(
|
||||
base_task=_global_memory.get("base_task", ""),
|
||||
tasks=tasks,
|
||||
tasks=[], # No more tasks from global memory
|
||||
task=task_spec,
|
||||
plan=plan,
|
||||
plan="", # No more plan from global memory
|
||||
related_files=related_files,
|
||||
model=model,
|
||||
expert_enabled=True,
|
||||
|
|
|
|||
|
|
@ -46,9 +46,6 @@ from ra_aid.database.repositories.key_fact_repository import get_key_fact_reposi
|
|||
|
||||
# Global memory store
|
||||
_global_memory: Dict[str, Any] = {
|
||||
"plans": [],
|
||||
"tasks": {}, # Dict[int, str] - ID to task mapping
|
||||
"task_id_counter": 1, # Counter for generating unique task IDs
|
||||
"implementation_requested": False,
|
||||
"related_files": {}, # Dict[int, str] - ID to filepath mapping
|
||||
"related_file_id_counter": 1, # Counter for generating unique file IDs
|
||||
|
|
@ -112,38 +109,6 @@ def emit_research_notes(notes: str) -> str:
|
|||
return "Failed to store research note."
|
||||
|
||||
|
||||
@tool("emit_plan")
|
||||
def emit_plan(plan: str) -> str:
|
||||
"""Store a plan step in global memory.
|
||||
|
||||
Args:
|
||||
plan: The plan step to store (markdown format; be clear, complete, use newlines, and use as many tokens as you need)
|
||||
"""
|
||||
_global_memory["plans"].append(plan)
|
||||
console.print(Panel(Markdown(plan), title="📋 Plan"))
|
||||
log_work_event(f"Added plan step:\n\n{plan}")
|
||||
return "Plan stored."
|
||||
|
||||
|
||||
@tool("emit_task")
|
||||
def emit_task(task: str) -> str:
|
||||
"""Store a task in global memory.
|
||||
|
||||
Args:
|
||||
task: The task to store
|
||||
"""
|
||||
# Get and increment task ID
|
||||
task_id = _global_memory["task_id_counter"]
|
||||
_global_memory["task_id_counter"] += 1
|
||||
|
||||
# Store task with ID
|
||||
_global_memory["tasks"][task_id] = task
|
||||
|
||||
console.print(Panel(Markdown(task), title=f"✅ Task #{task_id}"))
|
||||
log_work_event(f"Task #{task_id} added:\n\n{task}")
|
||||
return f"Task #{task_id} stored."
|
||||
|
||||
|
||||
@tool("emit_key_facts")
|
||||
def emit_key_facts(facts: List[str]) -> str:
|
||||
"""Store multiple key facts about the project or current task in global memory.
|
||||
|
|
@ -205,29 +170,6 @@ def emit_key_facts(facts: List[str]) -> str:
|
|||
return "Facts stored."
|
||||
|
||||
|
||||
@tool("delete_tasks")
|
||||
def delete_tasks(task_ids: List[int]) -> str:
|
||||
"""Delete multiple tasks from global memory by their IDs.
|
||||
Silently skips any IDs that don't exist.
|
||||
|
||||
Args:
|
||||
task_ids: List of task IDs to delete
|
||||
"""
|
||||
results = []
|
||||
for task_id in task_ids:
|
||||
if task_id in _global_memory["tasks"]:
|
||||
# Delete the task
|
||||
deleted_task = _global_memory["tasks"].pop(task_id)
|
||||
success_msg = f"Successfully deleted task #{task_id}: {deleted_task}"
|
||||
console.print(
|
||||
Panel(Markdown(success_msg), title="Task Deleted", border_style="green")
|
||||
)
|
||||
results.append(success_msg)
|
||||
|
||||
log_work_event(f"Deleted tasks {task_ids}.")
|
||||
return "Tasks deleted."
|
||||
|
||||
|
||||
@tool("request_implementation")
|
||||
def request_implementation() -> str:
|
||||
"""Request that implementation proceed after research/planning.
|
||||
|
|
@ -327,41 +269,6 @@ def emit_key_snippet(snippet_info: SnippetInfo) -> str:
|
|||
return f"Snippet #{snippet_id} stored."
|
||||
|
||||
|
||||
|
||||
@tool("swap_task_order")
|
||||
def swap_task_order(id1: int, id2: int) -> str:
|
||||
"""Swap the order of two tasks in global memory by their IDs.
|
||||
|
||||
Args:
|
||||
id1: First task ID
|
||||
id2: Second task ID
|
||||
"""
|
||||
# Validate IDs are different
|
||||
if id1 == id2:
|
||||
return "Cannot swap task with itself"
|
||||
|
||||
# Validate both IDs exist
|
||||
if id1 not in _global_memory["tasks"] or id2 not in _global_memory["tasks"]:
|
||||
return "Invalid task ID(s)"
|
||||
|
||||
# Swap the tasks
|
||||
_global_memory["tasks"][id1], _global_memory["tasks"][id2] = (
|
||||
_global_memory["tasks"][id2],
|
||||
_global_memory["tasks"][id1],
|
||||
)
|
||||
|
||||
# Display what was swapped
|
||||
console.print(
|
||||
Panel(
|
||||
Markdown(f"Swapped:\n- Task #{id1} ↔️ Task #{id2}"),
|
||||
title="🔄 Tasks Reordered",
|
||||
border_style="green",
|
||||
)
|
||||
)
|
||||
|
||||
return "Tasks deleted."
|
||||
|
||||
|
||||
@tool("one_shot_completed")
|
||||
def one_shot_completed(message: str) -> str:
|
||||
"""Signal that a one-shot task has been completed and execution should stop.
|
||||
|
|
@ -402,11 +309,9 @@ def plan_implementation_completed(message: str) -> str:
|
|||
"""
|
||||
mark_should_exit()
|
||||
mark_plan_completed(message)
|
||||
_global_memory["tasks"].clear() # Clear task list when plan is completed
|
||||
_global_memory["task_id_counter"] = 1
|
||||
console.print(Panel(Markdown(message), title="✅ Plan Executed"))
|
||||
log_work_event(f"Completed implementation:\n\n{message}")
|
||||
return "Plan completion noted and task list cleared."
|
||||
return "Plan completion noted."
|
||||
|
||||
|
||||
def get_related_files() -> List[str]:
|
||||
|
|
|
|||
|
|
@ -15,17 +15,11 @@ from ra_aid.tools.memory import _global_memory
|
|||
@pytest.fixture
|
||||
def reset_memory():
|
||||
"""Reset global memory before each test"""
|
||||
_global_memory["plans"] = []
|
||||
_global_memory["tasks"] = {}
|
||||
_global_memory["task_id_counter"] = 0
|
||||
_global_memory["related_files"] = {}
|
||||
_global_memory["related_file_id_counter"] = 0
|
||||
_global_memory["work_log"] = []
|
||||
yield
|
||||
# Clean up after test
|
||||
_global_memory["plans"] = []
|
||||
_global_memory["tasks"] = {}
|
||||
_global_memory["task_id_counter"] = 0
|
||||
_global_memory["related_files"] = {}
|
||||
_global_memory["related_file_id_counter"] = 0
|
||||
_global_memory["work_log"] = []
|
||||
|
|
@ -168,8 +162,7 @@ def test_request_implementation_uses_key_fact_repository(reset_memory, mock_func
|
|||
|
||||
def test_request_task_implementation_uses_key_fact_repository(reset_memory, mock_functions):
|
||||
"""Test that request_task_implementation uses KeyFactRepository correctly."""
|
||||
# Set up _global_memory with required values
|
||||
_global_memory["tasks"] = {0: "Task 1"}
|
||||
# Set up _global_memory with required values (without tasks)
|
||||
_global_memory["base_task"] = "Base task"
|
||||
|
||||
# Mock running the implementation agent
|
||||
|
|
|
|||
|
|
@ -8,18 +8,15 @@ from unittest.mock import patch, MagicMock, ANY
|
|||
from ra_aid.agents.key_snippets_gc_agent import delete_key_snippets
|
||||
from ra_aid.tools.memory import (
|
||||
_global_memory,
|
||||
delete_tasks,
|
||||
deregister_related_files,
|
||||
emit_key_facts,
|
||||
emit_key_snippet,
|
||||
emit_related_files,
|
||||
emit_task,
|
||||
get_memory_value,
|
||||
get_related_files,
|
||||
get_work_log,
|
||||
log_work_event,
|
||||
reset_work_log,
|
||||
swap_task_order,
|
||||
is_binary_file,
|
||||
_is_binary_fallback,
|
||||
)
|
||||
|
|
@ -32,17 +29,11 @@ from ra_aid.database.models import KeyFact
|
|||
@pytest.fixture
|
||||
def reset_memory():
|
||||
"""Reset global memory before each test"""
|
||||
_global_memory["plans"] = []
|
||||
_global_memory["tasks"] = {}
|
||||
_global_memory["task_id_counter"] = 0
|
||||
_global_memory["related_files"] = {}
|
||||
_global_memory["related_file_id_counter"] = 0
|
||||
_global_memory["work_log"] = []
|
||||
yield
|
||||
# Clean up after test
|
||||
_global_memory["plans"] = []
|
||||
_global_memory["tasks"] = {}
|
||||
_global_memory["task_id_counter"] = 0
|
||||
_global_memory["related_files"] = {}
|
||||
_global_memory["related_file_id_counter"] = 0
|
||||
_global_memory["work_log"] = []
|
||||
|
|
@ -707,127 +698,6 @@ def test_key_snippets_integration(mock_log_work_event, reset_memory, mock_key_sn
|
|||
assert result == "Snippets deleted."
|
||||
|
||||
|
||||
def test_emit_task_with_id(reset_memory):
|
||||
"""Test emitting tasks with ID tracking"""
|
||||
# Test adding a single task
|
||||
task = "Implement new feature"
|
||||
result = emit_task.invoke({"task": task})
|
||||
|
||||
# Verify return message includes task ID
|
||||
assert result == "Task #0 stored."
|
||||
|
||||
# Verify task stored correctly with ID
|
||||
assert _global_memory["tasks"][0] == task
|
||||
|
||||
# Verify counter incremented
|
||||
assert _global_memory["task_id_counter"] == 1
|
||||
|
||||
# Add another task to verify counter continues correctly
|
||||
task2 = "Fix bug"
|
||||
result = emit_task.invoke({"task": task2})
|
||||
assert result == "Task #1 stored."
|
||||
assert _global_memory["tasks"][1] == task2
|
||||
assert _global_memory["task_id_counter"] == 2
|
||||
|
||||
|
||||
def test_delete_tasks(reset_memory):
|
||||
"""Test deleting tasks"""
|
||||
# Add some test tasks
|
||||
tasks = ["Task 1", "Task 2", "Task 3"]
|
||||
for task in tasks:
|
||||
emit_task.invoke({"task": task})
|
||||
|
||||
# Test deleting single task
|
||||
result = delete_tasks.invoke({"task_ids": [1]})
|
||||
assert result == "Tasks deleted."
|
||||
assert 1 not in _global_memory["tasks"]
|
||||
assert len(_global_memory["tasks"]) == 2
|
||||
|
||||
# Test deleting multiple tasks including non-existent ID
|
||||
result = delete_tasks.invoke({"task_ids": [0, 2, 999]})
|
||||
assert result == "Tasks deleted."
|
||||
assert len(_global_memory["tasks"]) == 0
|
||||
|
||||
# Test deleting from empty tasks dict
|
||||
result = delete_tasks.invoke({"task_ids": [0]})
|
||||
assert result == "Tasks deleted."
|
||||
|
||||
# Counter should remain unchanged after deletions
|
||||
assert _global_memory["task_id_counter"] == 3
|
||||
|
||||
|
||||
def test_swap_task_order_valid_ids(reset_memory):
|
||||
"""Test basic task swapping functionality"""
|
||||
# Add test tasks
|
||||
tasks = ["Task 1", "Task 2", "Task 3"]
|
||||
for task in tasks:
|
||||
emit_task.invoke({"task": task})
|
||||
|
||||
# Swap tasks 0 and 2
|
||||
result = swap_task_order.invoke({"id1": 0, "id2": 2})
|
||||
assert result == "Tasks deleted."
|
||||
|
||||
# Verify tasks were swapped
|
||||
assert _global_memory["tasks"][0] == "Task 3"
|
||||
assert _global_memory["tasks"][2] == "Task 1"
|
||||
assert _global_memory["tasks"][1] == "Task 2" # Unchanged
|
||||
|
||||
|
||||
def test_swap_task_order_invalid_ids(reset_memory):
|
||||
"""Test error handling for invalid task IDs"""
|
||||
# Add a test task
|
||||
emit_task.invoke({"task": "Task 1"})
|
||||
|
||||
# Try to swap with non-existent ID
|
||||
result = swap_task_order.invoke({"id1": 0, "id2": 999})
|
||||
assert result == "Invalid task ID(s)"
|
||||
|
||||
# Verify original task unchanged
|
||||
assert _global_memory["tasks"][0] == "Task 1"
|
||||
|
||||
|
||||
def test_swap_task_order_same_id(reset_memory):
|
||||
"""Test handling of attempt to swap a task with itself"""
|
||||
# Add test task
|
||||
emit_task.invoke({"task": "Task 1"})
|
||||
|
||||
# Try to swap task with itself
|
||||
result = swap_task_order.invoke({"id1": 0, "id2": 0})
|
||||
assert result == "Cannot swap task with itself"
|
||||
|
||||
# Verify task unchanged
|
||||
assert _global_memory["tasks"][0] == "Task 1"
|
||||
|
||||
|
||||
def test_swap_task_order_empty_tasks(reset_memory):
|
||||
"""Test swapping behavior with empty tasks dictionary"""
|
||||
result = swap_task_order.invoke({"id1": 0, "id2": 1})
|
||||
assert result == "Invalid task ID(s)"
|
||||
|
||||
|
||||
def test_swap_task_order_after_delete(reset_memory):
|
||||
"""Test swapping after deleting a task"""
|
||||
# Add test tasks
|
||||
tasks = ["Task 1", "Task 2", "Task 3"]
|
||||
for task in tasks:
|
||||
emit_task.invoke({"task": task})
|
||||
|
||||
# Delete middle task
|
||||
delete_tasks.invoke({"task_ids": [1]})
|
||||
|
||||
# Try to swap with deleted task
|
||||
result = swap_task_order.invoke({"id1": 0, "id2": 1})
|
||||
assert result == "Invalid task ID(s)"
|
||||
|
||||
# Try to swap remaining valid tasks
|
||||
result = swap_task_order.invoke({"id1": 0, "id2": 2})
|
||||
assert result == "Tasks deleted."
|
||||
|
||||
# Verify swap worked
|
||||
assert _global_memory["tasks"][0] == "Task 3"
|
||||
assert _global_memory["tasks"][2] == "Task 1"
|
||||
|
||||
|
||||
def test_emit_related_files_binary_filtering(reset_memory, monkeypatch):
|
||||
"""Test that binary files are filtered out when adding related files"""
|
||||
import tempfile
|
||||
|
|
|
|||
Loading…
Reference in New Issue