Skip to content

fix(plan): slice task commands by byte offsets - #861

Merged
wan9chi merged 5 commits into
voidzero-dev:mainfrom
magurotuna:fix/shell-span-byte-offsets
Oct 19, 2026
Merged

wan9chi merged 5 commits into
voidzero-dev:mainfrom
magurotuna:fix/shell-span-byte-offsets

Conversation

@magurotuna

Copy link
Copy Markdown
Member

Motivation

The vp run command panics before it runs a script that contains multi-byte UTF-8 characters, for example echo ああ. To display each command, the planner slices the script with the command spans from the brush-parser crate. These spans are character indices (SourcePosition::index), but the planner uses them as byte ranges. If an index falls inside a character, the slice panics. If an index falls on a character boundary, the planner displays a truncated command: it displays echo あああ as echo あ.

The brush project tracks this bug in reubeno/brush#1127. The fix in reubeno/brush#1144 is still open.

Fixes #719.

Changes

  • The vt_shell crate converts the character indices from the brush-parser crate to byte indices before it returns the command spans. Each conversion counts characters from the start of the script, which takes about 0.2 µs for a 150-byte script.
  • Add a unit test with 2-, 3-, and 4-byte characters, and add the non_ascii_commands fixture for plan snapshots.

magurotuna and others added 5 commits October 16, 2026 21:40
Command spans from the shell parser are sliced out of the script to
display each command. These cases put multi-byte UTF-8 characters before
span boundaries, where `vp run` currently panics or truncates the
displayed command (voidzero-dev#719).

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
`brush_parser` reports source positions as character indices, but the
command spans were used as byte ranges into the script. A script with a
multi-byte UTF-8 character before a span boundary made `vp run` panic
before running it, or display a truncated command.

Convert the parser's character indices to byte indices before returning
the spans.

Fixes voidzero-dev#719

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
The comment relied on an open brush PR that renames `index`. If a brush
release switches to byte offsets without the rename, the unit test for
multi-byte characters is what detects the double conversion.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@fengmk2
fengmk2 requested a review from wan9chi October 19, 2026 01:05
@wan9chi
wan9chi merged commit 32cf238 into voidzero-dev:main Oct 19, 2026
20 checks passed
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.

vt_shell: command spans are character indices but sliced as bytes (plan.rs:185)

2 participants