From 4f65634fd8e03fd5ea0f533cc2f456de718fc9f6 Mon Sep 17 00:00:00 2001 From: Daniel Casper Date: Tue, 5 May 2026 22:28:10 -0500 Subject: [PATCH 1/3] feat: add xml prompt caching and nuclear truncation --- orchestrator.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/orchestrator.py b/orchestrator.py index 3360c2f..f2f0971 100644 --- a/orchestrator.py +++ b/orchestrator.py @@ -315,10 +315,21 @@ def run_shell_command(command: str) -> str: output = result.stdout.strip() error = result.stderr.strip() + # --- SHIFT-LEFT: TOKEN ECONOMICS (TRUNCATION) --- + combined_output = output + if error: + combined_output += f"\nSTDERR:\n{error}" + + if len(combined_output) > 8000: + combined_output = ( + combined_output[:8000] + + "\n\n...[SYSTEM WARNING: Output truncated at 8000 characters to save context.]..." + ) + if result.returncode == 0: - return output if output else f"[SUCCESS: {command}]" + return combined_output if combined_output else f"[SUCCESS: {command}]" else: - return f"[ERROR: Command execution failed - {error}]" + return f"[ERROR: Command execution failed]\n{combined_output}" except subprocess.TimeoutExpired: return "[ERROR: Command timed out after 60 seconds.]" @@ -403,7 +414,7 @@ def read_directory_contents(dir_path): # Currently restricted to markdown if filename.endswith(".md"): filepath = os.path.join(dir_path, filename) - content += f"\n--- FILE: {filename} ---\n{read_file(filepath)}\n" + content += f'\n\n{read_file(filepath)}\n\n' except FileNotFoundError: pass return content @@ -433,9 +444,8 @@ def assemble_context(agent_name): # --- CONTEXT FUNNELING: Only load active artifacts --- context += "\n\n--- ACTIVE FEATURE ARTIFACTS ---\n" for artifact_path in get_active_artifacts(): - fname = os.path.basename(artifact_path) fcontent = read_file(os.path.join(BASE_DIR, artifact_path)) - context += f"\n--- FILE: {fname} ---\n{fcontent}\n" + context += f'\n\n{fcontent}\n\n' # List existing contracts instead of reading all their contents to save tokens contract_list = list_directory(contracts_dir) From 79e4ff9498206ed9bc61fe17176a2846fb943644 Mon Sep 17 00:00:00 2001 From: Daniel Casper Date: Tue, 5 May 2026 22:34:23 -0500 Subject: [PATCH 2/3] fix test --- tests/evals/test_orchestrator.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/evals/test_orchestrator.py b/tests/evals/test_orchestrator.py index 9b407cf..ad80ee9 100644 --- a/tests/evals/test_orchestrator.py +++ b/tests/evals/test_orchestrator.py @@ -169,7 +169,8 @@ def test_actual_file_io(tmp_path, monkeypatch) -> None: # Test read_directory_contents dir_res = read_directory_contents(str(docs_dir)) - assert "--- FILE: test.md ---" in dir_res + # SHIFT-LEFT: Updated test to check for the new XML caching tags + assert '' in dir_res def test_get_active_artifacts(tmp_path, monkeypatch) -> None: From bae1176095ae0a0afe144618d9174c7c5e817c3a Mon Sep 17 00:00:00 2001 From: Daniel Casper Date: Tue, 5 May 2026 22:38:42 -0500 Subject: [PATCH 3/3] fix test --- tests/evals/test_orchestrator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/evals/test_orchestrator.py b/tests/evals/test_orchestrator.py index ad80ee9..0fef97f 100644 --- a/tests/evals/test_orchestrator.py +++ b/tests/evals/test_orchestrator.py @@ -170,7 +170,7 @@ def test_actual_file_io(tmp_path, monkeypatch) -> None: # Test read_directory_contents dir_res = read_directory_contents(str(docs_dir)) # SHIFT-LEFT: Updated test to check for the new XML caching tags - assert '' in dir_res + assert "--- FILE: test.md ---" in dir_res def test_get_active_artifacts(tmp_path, monkeypatch) -> None: