Skip to content

fix(cli): read @file arguments saved as UTF-16LE or with a byte-order mark - #10298

Merged
waleedlatif1 merged 1 commit into
simstudioai:stagingfrom
b84330808:fix/cli-at-file-encoding
Nov 21, 2026
Merged

waleedlatif1 merged 1 commit into
simstudioai:stagingfrom
b84330808:fix/cli-at-file-encoding

Conversation

@b84330808

Copy link
Copy Markdown
Contributor

Summary

Windows PowerShell 5.1, the shell Windows opens by default, writes > redirects as UTF-16LE with a byte-order mark, and Out-File -Encoding utf8 writes UTF-8 with one. The CLI read every @file / @- argument as plain UTF-8, so the documented export and import steps from the workflow sync guide fail there:

sim --output json workflows export $id --include-references > workflow.json
sim --output json workflows import-preview --workflow '@workflow.json'
# {"error":{"code":"CLI_ERROR","message":"--workflow must be valid JSON (read from workflow.json): Unexpected token '�', \"��{\u0000\"\u0000v\u0000e\u0000\"... is not valid JSON"}}

readArgumentDescriptor now decodes the bytes as UTF-16LE when they start with that mark, and drops a leading mark in either encoding. That's what the embedded reader's TextDecoder already does with a UTF-8 mark. Input without a mark decodes exactly as before, and CRLF and trailing newlines are untouched.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • Other: ___________

Testing

  • New case in runtime/request.test.ts reads @path saved as UTF-16LE and as UTF-8 with a mark. Both fail on staging with the error above and pass with the change.
  • Without a mark, Buffer#toString('utf8') and TextDecoder('utf-8') gave identical strings for 40,000 random and corrupted inputs in a throwaway comparison (invalid bytes, CRLF, multibyte characters).
  • src/runtime, src/transfer and commands/secrets.test.ts give the same results as on staging apart from the new case (Windows 11). Biome, tsc --noEmit for sim-cli, check:comment-hygiene and check:test-patterns pass.
  • On Windows PowerShell 5.1 (-NoProfile), I built the CLI from both branches and pointed it at a closed local port. I wrote workflow.json with > and ran workflows import-preview --workflow @workflow.json. staging stops with the JSON error. With the change it reads the file and gets as far as the request (Could not reach http://127.0.0.1:9).

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

… mark

Windows PowerShell 5.1 writes `>` redirects as UTF-16LE with a byte-order
mark, and `Out-File -Encoding utf8` writes UTF-8 with one. The documented
`sim workflows export ... > workflow.json` then
`workflows import-preview --workflow @workflow.json` failed there with
"--workflow must be valid JSON". @file and @- input is now decoded as
UTF-16LE when it starts with that mark, and a leading mark is dropped
either way, as the embedded reader's TextDecoder already does.
@vercel

vercel Bot commented Nov 21, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
docs Skipped Skipped Nov 21, 2026 9:15pm UTC

Request Review

@greptile-apps

greptile-apps Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Summary

Adds BOM-aware decoding for local @path and @- arguments.

  • The CLI reads marked JSON from files and stdin.

Reviews (1) · Last reviewed commit: "fix(cli): read @file arguments saved as ..." · Reviewed by Greptile

@waleedlatif1
waleedlatif1 merged commit 71d7db5 into simstudioai:staging Nov 21, 2026
5 checks passed

This branch was previously deployed

1 inactive deployment
Preview — 8628c6de Deployed Nov 21, 2026 by vercel[bot]
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.

2 participants