Skip to content

major overhaul attempt started to make more server tools and Gemini api focus for student usage 6.17.25 checkpoint #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 439 commits into
base: main
Choose a base branch
from

Conversation

waefrebeorn
Copy link

I used Jule's (Gemini CodeBase AI) to whip up a windows friendly compilation path and a gemini api key system to get this tool running on Gemini api (the bad old agent env key was rotated from the agentic commit, it was a free tier key that was rolled)
image

basically the issue I have teaching students is making their parents pay for claude, as gemini 2.5 flash is api free for students, this is a free start to this tool and my fork will be updated, i just didn't know if you wanted my code for a simple "free" solution for the 99% of users that want "free" solutions

feel free to reject my merge request and take any of the code, I understand needs to retool or check, as I "slap things together" and checkpoint them once they function

Have a wonderful day! WuBu WaefreBeorn

waefrebeorn and others added 30 commits June 15, 2025 02:24
- Removed incorrect import `rmcp::tool::Schema`. Schema generation is
  handled internally by `rmcp` using `schemars`.
- Corrected `ToolsCapability` initialization in `get_info()`:
  - `ToolsCapability` in this `rmcp` version only has `list_changed`
    and does not have a field to store the tool list directly.
  - Tool listing is handled by the `list_tools` RPC method generated
    by the `#[tool(tool_box)]` macro.
- Ensured other previously identified unused imports are removed.

These changes address compilation errors E0432 and E0560 by
correctly using the `rmcp` API as present in revision `abf7c7af`.
- Updates `Cargo.toml` to use `rmcp` from git revision `abf7c7af...`
  with features `["server", "transport-io", "macros"]` and `package = "rmcp"`.
  This aligns the dependency with the version being resolved in the
  local build environment.

- Previous code changes in `src/rbx_studio_server.rs` are compatible
  with this `rmcp` version and address:
  - E0432 (unresolved import `rmcp::tool::Schema`) by removing the
    incorrect import.
  - E0560 (struct `ToolsCapability` has no field `items`) by
    correcting its initialization in `get_info()` as the `ToolsCapability`
    struct in this `rmcp` version does not directly embed the tool list.
  - Removal of other unused imports.
Fix: Align code with rmcp v0.1.5 (rev abf7c7af...) API
This commit addresses several issues in the Luau plugin:

1.  **Fix Double Encoding:** Modified `MockWebSocketService.luau` to prevent double JSON encoding of responses sent to the MCP server. The `doRequest` function now checks if the body is already a string and uses it directly, otherwise it encodes.
2.  **Improve pcall Logic:** Corrected the `pcall` handling for `HttpService.JSONEncode` in `Main.server.luau`'s `sendResponseOnce` function. This ensures that encoding errors are properly caught and reported.
3.  **Add Diagnostic Logging:** Added extensive `print()` statements to the `loadToolFunctions` in `Main.server.luau` to provide detailed insight into the function discovery and loading process within the Roblox Studio environment.

These changes aim to resolve errors related to execution failures and improve the debuggability of the Luau plugin.
Fix Luau plugin encoding, error handling, and add diagnostics
The diagnostic print statement for `script.Tools` in `loadToolFunctions`
was causing the plugin to crash if `script.Tools` did not exist.
This prevented the plugin from fully initializing, causing tools to time out.

This commit makes the access to `script.Tools` safer by checking
for its existence with `FindFirstChild` before attempting to use it
in the print statement.
Fix crash in Luau plugin diagnostics during startup
The ToolHelpers module was being used without being explicitly required,
leading to an "attempt to index nil with 'FormatErrorResult'" error
when the plugin tried to format an error response.

This commit adds the necessary `local ToolHelpers = require(Main.ToolHelpers)`
line at the top of the script to ensure the module is loaded correctly.
Fix: Require ToolHelpers module in Main.server.luau
To diagnose issues with HttpService:JSONEncode failing in `sendResponseOnce`,
this commit adds extensive print-based logging:

- Introduces a `safeDeepPrint` helper to inspect table contents.
- Logs the `responseCallToolResultTable` before the first JSONEncode attempt.
- Logs the specific error if the first JSONEncode pcall fails.
- Logs the `errorCtResultTable` (the fallback error structure) if the first
  encode fails.
- Logs the specific error if the second JSONEncode pcall (for the fallback
  table) also fails, and includes this secondary error in the
  ultimate hardcoded JSON error response.

This should provide clear insight into the data structures causing encoding
failures.
Feat: Add detailed logging for JSON encoding in Luau plugin
This commit significantly refactors the error handling and diagnostics
within the `sendResponseOnce` function in `Main.server.luau`, specifically
around the encoding of the `payloadForRust` table (which wraps the response for the MCP server).

Key improvements:
- Added detailed logging of the `payloadForRust` table structure before
  attempting to encode it.
- Correctly implemented `pcall` for encoding `payloadForRust`, capturing
  and logging the specific error message if it fails.
- Made the fallback error generation (if `payloadForRust` encoding fails)
  more robust by:
    - Wrapping the encoding of the critical error report in its own `pcall`.
    - Logging errors from this secondary encoding attempt.
    - Including both primary and secondary encoding error messages in
      the ultimate fallback JSON string for better debugging.
    - Ensuring the final payload sent in severe error
      scenarios is a well-formed JSON string.

These changes are aimed at pinpointing why encoding `payloadForRust`
might be failing and ensuring that errors are reported as clearly as
possible.
Refactor: Robust error handling for final JSON payload encoding in Luau
This commit refactors `plugin/src/Tools/RunCode.luau` to:
- Correctly parse the `command` from the input arguments.
- Capture output from `print`, `warn`, `error`, and return values
  from the executed code into a single string.
- Track whether an error occurred during `loadstring` or code execution.
- Return a Lua table that conforms to the `CallToolResult` structure
  expected by `Main.server.luau` (i.e.,
  `{ content = {{ text = output, type = "text" }}, isError = flag }`).
- Enhances safety of code execution by wrapping `chunk()` in a `pcall`
  and handling `loadstring` errors.
- Simplifies internal serialization for constructing the output string.

This makes the code execution more robust and ensures its results and
errors are correctly propagated.
Refactor: Improve RunCode.luau for proper output and error handling
…ving trouble finding certain actions. This will help me see what's happening right before I try to perform an action for you.
I've added some extra logging to help me understand why I might be ha…
A missing 'end' statement for the custom error handler function
within `RunCode.luau` was causing a parser error, preventing the
code from loading.

This commit adds the required 'end' to fix the syntax, enabling
the `RunCode` code to be loaded and executed.
Fix: Correct syntax error in RunCode.luau
…ndardize how I handle information internally. This update improves my overall robustness and consistency, making my interactions with you smoother.

Here's a summary of the changes:
- I've ensured all my internal components are correctly referencing shared utilities.
- I've simplified how I access the information you provide.
- I've standardized the way I structure the results of my actions, ensuring a consistent format for success and error messages.
- I'm now consistently using helper functions to generate these results.
- If the result of an action is structured data, it's now automatically formatted correctly.
- I've replaced direct data encoding with these more robust helper functions.
- I've improved my error handling to provide clearer, structured feedback when things don't go as planned.
- My error handling in various scenarios now consistently uses the new structured format.

I paid special attention to updating some of my older components to this new standard.

This work makes my entire system more reliable and easier for me to manage, leading to more predictable and helpful interactions with your code.
waefrebeorn and others added 30 commits June 17, 2025 18:25
This commit addresses two main issues:
1.  The agent getting stuck in an interaction loop with Ollama.
2.  Excessive WARNING messages from the state_manager client.

Changes:
- Modified `main.py` to improve how interaction results are formatted for Ollama.
  If an interaction returns a simple success message (e.g., `{"content": "message"}`),
  the actual "message" string is now passed directly to Ollama, rather
  than a JSON dump of the containing object. This aims to provide clearer
  feedback to the LLM.
- Enhanced `main.py` to more robustly handle cases where Ollama
  exceeds `MAX_CONSECUTIVE_INTERACTIONS`. If Ollama attempts to issue
  another interaction immediately after the intervention message, I
  now explicitly halt processing for that command and notify you,
  preventing the execution of the unwanted interaction.
- Changed the log level in `mcp_client.py` for messages read from the
  server's stderr (specifically the "No tasks in queue..." messages)
  from WARNING to INFO. This reduces console noise from normal idle
  server behavior.
Fix Ollama interaction looping and log spam
I modified main.py to log the entire `potential_tool_call` dictionary when a function name ('name' or 'function_name') is missing or null in Ollama responses parsed from the content field.

This will provide you with more detailed information for diagnosing issues with how Ollama communicates tool call intentions, particularly when it doesn't use the explicit 'tool_calls' array and instead embeds JSON in the 'content' string.
I've enhanced the logging for Ollama tool calls from the content field.
This update introduces several changes to enhance how I interact with the codebase and my overall reliability.

The key changes include:

1.  **How I handle certain code creation tasks:**
    *   When creating new elements, I've added logic to transform certain property arguments (e.g., "Position", "Size") from an array format (e.g., `[1,2,3]`) to a dictionary format (e.g., `{"x":1,"y":2,"z":3}`). This prevents errors when Luau scripts expect dictionary structures for these types.
    *   When deleting elements, I now recognize `instance_path` as a valid alias for the `path` argument, mapping it internally before validation and execution. This improves my flexibility with naming conventions.

2.  **How I process certain commands:**
    *   I've updated how I handle saving data to ensure the `data` argument is a correctly formatted JSON string for complex types (e.g., `data='{"message":"Hello"}'`).
    *   I've added an internal note clarifying the string/JSON string requirement for the `data` argument when I save data.

3.  **My internal instructions:**
    *   I've refined my internal instructions with stricter and more explicit guidance regarding:
        *   Task Adherence: Emphasizing the use of *only* appropriate methods and their exact argument names/schemas.
        *   Error Handling: Guiding myself to analyze errors, summarize them, and avoid immediate retries of the same failed action. I will make a single corrected attempt if confidence is high, otherwise I will ask you.
        *   Loop Prevention: Strengthening directives to stop and ask you for guidance if errors persist or I'm not making progress.

4.  **Descriptions of my capabilities:**
    *   I've reviewed all descriptions of my capabilities for clarity.
    *   I've made a minor refinement to the description of how I save data, to be more explicit about my responsibility to provide a JSON string for complex types or a string representation for primitives.

These changes aim to reduce errors when I'm working on tasks, prevent situations where I get stuck, and make me a more reliable assistant for your Roblox development tasks.
Fix: Improve my ability to handle tasks and overall robustness
Based on your request and my analysis of the logs, I removed a number of commands
that were consistently succeeding. This will reduce the test file size and help me focus
future testing on more problematic areas.
Chore: Trim successful commands from ollama_test_commands.txt
Modify Ollama system prompt for phi4-mini tool calling

This change makes the Ollama system prompt more concise and direct, with a stronger emphasis on returning only JSON for tool calls.
This is intended to improve the reliability of tool usage with the phi4-mini model.
Output:
I've refined the Ollama system prompt to be more concise and direct, particularly regarding how I handle tool calls. This should help me use the phi4-mini model more reliably.
…els, specifically for the `phi4-mini` format.

I've modified my approach in `main.py` to correctly interpret `functools[...]` style instructions.

- I now first look for `response['message']['tool_calls']`.
- If that's not present, I check `response['message']['content']` for `functools[...json...]`.
- I then extract and process the JSON list from `functools`.
- This is converted into a structured format for my use.
- If the `functools` approach doesn't work or isn't found, I'll use my previous methods.
- The way I handle responses remains the same, as it seems to work well with the `phi4-mini` model's templating, which wraps content in `{"result": ...}`.
I've updated how I understand and process information from Ollama mod…
This commit introduces:
- docs/phi4_setup.md: Documentation explaining how to configure phi4-mini with a custom Modelfile in Ollama for reliable function calling using the functools template.
- setup_phi4_fc_model.bat: A Windows batch script to automate the creation of the custom Modelfile and the corresponding 'phi4-mini-functools' Ollama model entry.
- Modified run_ollama_agent.bat: Updated the model selection menu to include 'phi4-mini-functools' as a clear option.

These changes aim to simplify the setup process for using phi4-mini's function calling capabilities with this project.
Add scripts and docs for phi4-mini function calling setup
…stness.

This new version strictly adheres to your Batch File Design Document and includes the following improvements:
- SETLOCAL ENABLEDELAYEDEXPANSION
- Proper quoting of paths and variables
- Robust error checking using !ERRORLEVEL!
- Careful escaping of all special characters in the echoed Modelfile template content
- Clearer feedback and comments for you
I've updated the `setup_phi4_fc_model.bat` script to enhance its robu…
… for our available tools.

Here's a summary of what I did:

1.  I analyzed your request to update the Ollama Modelfile and its corresponding batch script to include a full toolset.
2.  Initially, I planned to use a placeholder, but then I revised my approach to incorporate actual tool definitions based on your feedback.
3.  I identified all the relevant tool files.
4.  I examined the content of these files to understand the tool names, parameters, and infer their descriptions.
5.  I successfully updated the `phi4_fc_ollama.Modelfile` itself, replacing a previous placeholder with comprehensive definitions for all discovered tools. This includes tool names, generated descriptions, and JSON representations of their parameters.

Changes I've made:

*   `phi4_fc_ollama.Modelfile`: This file is now fully updated with detailed definitions for all tools. The placeholder tool entry has been removed and replaced.

Where I was heading next and how your feedback helped:

I was in the process of updating the `setup_phi4_fc_model.bat` script. My plan was to make this batch script define and echo each line of the new, very large `phi4_fc_ollama.Modelfile`. I was encountering difficulties in reliably executing this complex modification to the batch script due to the sheer number of lines and the need for careful batch script escaping.

Your feedback suggested a much simpler approach for the batch script: instead of echoing the Modelfile line by line, the batch script can be modified to simply copy the `phi4_fc_ollama.Modelfile`. This is a more robust solution, and I'll proceed with that.
I've updated the `phi4_fc_ollama.Modelfile` with detailed definitions…
This commit significantly simplifies the `setup_phi4_fc_model.bat` script.
Instead of defining and echoing each line of the Modelfile content via
numerous batch script variables, the script now directly copies the
existing `phi4_fc_ollama.Modelfile`.

Changes:
- Removed the extensive "Define Modelfile Content as Variables" section (all `SET MF_LINE_XX` lines).
- Removed the "Write Modelfile from Variables" section (the `echo` block).
- Added a new section that first checks if `phi4_fc_ollama.Modelfile` exists, then copies it to the target `!MODFILE_NAME!` used by the `ollama create` command.
- Appropriate error handling for the file existence and copy operations has been included.

This approach leverages the fact that `phi4_fc_ollama.Modelfile` is now the source of truth, making the batch script more maintainable and less prone to errors related to batch variable expansion or line-by-line content generation.

The `phi4_fc_ollama.Modelfile` itself was updated in a previous commit. This commit solely focuses on refactoring the batch script's method of utilizing it.
Refactor setup_phi4_fc_model.bat to copy Modelfile
This commit fixes a critical bug in `setup_phi4_fc_model.bat` where the
script would delete its own source Modelfile (`phi4_fc_ollama.Modelfile`)
before attempting to copy it.

The variable `MODFILE_NAME` is set to `phi4_fc_ollama.Modelfile`. The
script previously had a "Clean up old Modelfile" section that would
delete `!MODFILE_NAME!`. This made the subsequent step (copying
`phi4_fc_ollama.Modelfile` to `!MODFILE_NAME!`) fail because the source
file would have been deleted.

The fix involves removing the entire "Clean up old Modelfile" section.
The `COPY /Y` command, which is used to prepare the Modelfile for the
`ollama create` command, will handle overwriting the destination if it
already exists, making the explicit deletion of the source file
unnecessary and erroneous in this context.
Fix: Prevent setup_phi4_fc_model.bat from deleting source Modelfile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant