From 0a591d58eb4cee8623233cb3b15273137f9d6f44 Mon Sep 17 00:00:00 2001 From: Ed_ Date: Sat, 21 Feb 2026 21:16:50 -0500 Subject: [PATCH] wip better file support and word wrap --- MainContext.md | 9 ++++++ ai_client.py | 77 ++++++++++++++++++++++++++++++++++++++++++++---- gui.py | 4 +-- manual_slop.toml | 27 ++++++++++++++--- 4 files changed, 105 insertions(+), 12 deletions(-) diff --git a/MainContext.md b/MainContext.md index 8442317..8b1b9ea 100644 --- a/MainContext.md +++ b/MainContext.md @@ -90,6 +90,15 @@ Is a local GUI tool for manually curating and sending context to AI APIs. It agg - Rejections return `"USER REJECTED: command was not executed"` to the AI - All tool calls (script + result/rejection) are appended to `_tool_log` and displayed in the Tool Calls panel +**Dynamic file context refresh (ai_client.py):** +- After every tool call round, all project files from `file_items` are re-read from disk via `_reread_file_items()` +- For Anthropic: the refreshed file contents are injected as a `text` block appended to the `tool_results` user message, prefixed with `[FILES UPDATED]` and an instruction not to re-read them +- For Gemini: files are re-read (updating the `file_items` list in place) but cannot be injected into tool results due to Gemini's structured function response format +- `_build_file_context_text(file_items)` formats the refreshed files as markdown code blocks (same format as the original context) +- The `tool_result_send` comms log entry filters out the injected text block (only logs actual `tool_result` entries) to keep the comms panel clean +- `file_items` flows from `aggregate.build_file_items()` → `gui.py` `self.last_file_items` → `ai_client.send(file_items=...)` → `_send_anthropic(file_items=...)` / `_send_gemini(file_items=...)` +- System prompt updated to tell the AI: "the user's context files are automatically refreshed after every tool call, so you do NOT need to re-read files that are already provided in the block" + **Anthropic bug fixes applied (session history):** - Bug 1: SDK ContentBlock objects now converted to plain dicts via `_content_block_to_dict()` before storing in `_anthropic_history`; prevents re-serialisation failures on subsequent tool-use rounds - Bug 2: `_repair_anthropic_history` simplified to dict-only path since history always contains dicts diff --git a/ai_client.py b/ai_client.py index a6792f8..c05ffbd 100644 --- a/ai_client.py +++ b/ai_client.py @@ -39,7 +39,12 @@ _ANTHROPIC_SYSTEM = ( "When writing or rewriting large files (especially those containing quotes, backticks, or special characters), " "avoid python -c with inline strings. Instead: (1) write a .py helper script to disk using a PS here-string " "(@'...'@ for literal content), (2) run it with `python