jeremychone / rust-devai

Command Agent runner to accelerate production coding. File based, fully customizable, NOT for building snake games.
Apache License 2.0
10 stars 3 forks source link

`devai run` frequently returns error `Rhai(ErrorArrayBounds(...))` #2

Open stephenlf opened 11 hours ago

stephenlf commented 11 hours ago

Bug description

Running devai run frequently fails, throwing an error: Rhai(ErrorArrayBounds(...))

Command

devai run proof-comments -f ./README.md -v

Error

Rhai(ErrorArrayBounds(...))

Config

[genai]
model = "mistral:latest"  # Ollama

[runtime]
# Default to 1 if absent
items_concurrency = 1

Agent

# Data

let path = item.path;
let file = file::load(path);

return #{file: file};

# Instruction

- The user will provide you with the content of a Rust programming file. 
- You will correct the English in the comments, but leave everything else unchanged. 
- Only modify comments if there is a spelling or grammar mistake. 
- Make sure not to change the code, except for typos within strings.
- Do not change the code itself, only comments.

```md
{{data.file.content}}

Output

let rust_blocks = md::extract_blocks(ai_output, "md");
let first_rust_block = rust_blocks[0].content;
let rust_code = text::escape_decode_if_needed(first_rust_block);

file::save(data.file.path, rust_code);

// This will be printed
return "File processed: " + data.file.path

### Verbose output

``````fundamental
$ devai run proof-comments -f ./README.md -v
Running agent command: proof-comments
                 from: .devai/defaults/proof-comments.md
           with model: mistral:latest

==== Running item: ./README.md

-- Instruction:

- The user will provide you with the content of a Rust programming file. 
- You will correct the English in the comments, but leave everything else unchanged. 
- Only modify comments if there is a spelling or grammar mistake. 
- Make sure not to change the code, except for typos within strings.
- Do not change the code itself, only comments.

This is an example off some baad egnlish. hello, monseiur.

-- AI Output (model: mistral:latest | adapter: Ollama)

 ```md
This is an example of some bad English. Hello, Monsieur.

Error: Rhai(ErrorArrayBounds(0, 0, 2:36))
jeremychone commented 10 hours ago

First, thank you for the quality of the bug report.

I believe the issue is that proof-comments is designed to work on source code, specifically Rust, so something is getting confused somewhere.

From the verbose output, I noticed the space before ```md, which might be throwing things off.

Also, if there are nested blocks, things can get confusing. I'll need to think about how to resolve that.

Anyway, I need to do the following two things:

1) Fix the error message to make it less cryptic.

2) Ensure this use case works, and then probably create a new proof-markdown.md command agent specifically for markdown.

Great bug report, thanks for reporting it.

stephenlf commented 9 hours ago

You're completely right. The issue stemmed from the rhai script expecting to find a code block that the LLM's output didn't provide (or didn't format correctly).

let first_rust_block = rust_blocks[0].content;