Skip to content

fix(command): insert $ARGUMENTS contents verbatim - #758

Merged
Ishaan Gangwani (ishaan1124) merged 1 commit into
synthetic-sciences:mainfrom
aniruddhaadak80:fix/command-arguments-verbatim
Sep 28, 2026
Merged

Ishaan Gangwani (ishaan1124) merged 1 commit into
synthetic-sciences:mainfrom
aniruddhaadak80:fix/command-arguments-verbatim

Conversation

@aniruddhaadak80

Copy link
Copy Markdown
Contributor

What does this PR do, and why?

$ARGUMENTS was substituted with a string replacement in
backend/cli/src/session/prompt.ts:

let template = withArgs.replaceAll("$ARGUMENTS", input.arguments)

A string replacement expands the replacement patterns inside the text it
inserts, so the arguments a user typed were rewritten before the command ever
reached the model:

typed by the user reached the model as
$$ $
$& $ARGUMENTS (the matched placeholder itself)
$' `` (everything after the match, which is nothing here)

With the template Explain: $ARGUMENTS and the arguments
$$alpha + beta$$ with $& and $' kept, the prompt arrived as
Explain: $alpha + beta$ with $ARGUMENTS and kept — so a user pasting display
math into /plan or /goal silently got inline math, and a literal $& came
back as the placeholder name.

A function replacement inserts the text literally, so the arguments now
reach the model exactly as typed. This is the same defect class as #753, fixed
for {file:…} config references in ba152a6; this is the $ARGUMENTS instance.

The fix is one line plus a comment recording why the replacer must be a
function, and the new test drives the real command path against a local
OpenAI-compatible provider and asserts on the request body it actually receives.

Linked issue

Fixes #755

How did you verify it?

The new backend/cli/test/session/command-arguments.test.ts fails on
unmodified 3e94875c and passes with this change. On main the assertion
receives:

Expected to contain: "Explain: $$alpha + beta$$ with $& and $' kept"
Received:            "Explain: $alpha + beta$ with $ARGUMENTS and  kept"

Commands run:

  • bun test --timeout 15000 ./test/session/command-arguments.test.ts → 1 pass
    (the additional (fail) (unnamed) is the pre-existing Windows teardown in
    test/preload.ts, which cannot rm its temp data dir: EBUSY)
  • bun run --cwd backend/cli typecheck → exit 0
  • git show 3e94875c:backend/cli/src/session/prompt.ts to confirm the pre-fix
    line for reviewers who want to reproduce the failure without checking out

Pre-existing reds on this Windows checkout, not from this diff — each
reproduced with my change stashed:

  • bun run format:check cannot pass here: git materializes the LF blobs as
    CRLF, so Prettier flags hundreds of untouched files, including tsconfig.json
    and turbo.json. I verified my three files are formatted per the repo config
    with line endings normalized.
  • bun run typecheck: backend is clean; @synsci/workspace fails because
    frontend/workspace/src/custom-elements.d.ts is a symlink (mode 120000) that
    Windows checked out as a text file containing ../../ui/src/custom-elements.d.ts,
    which TypeScript then parses as source → TS1128.
  • test/session/command-shell.test.ts ("trusted command shell interpolation …")
    and two research-commands cases fail on unmodified main here as well.

CI on Linux runs the real bun run check.

Checklist

  • bun run check is green (format, typecheck, backend + frontend/ui + SDK tests) — blocked on this Windows checkout by the CRLF and symlink artifacts described above; backend typecheck is clean and the touched test is green
  • bun run --cwd frontend/workspace build succeeds if I touched frontend/workspace or frontend/ui — not touched
  • ./tooling/repo/generate.ts was run and the tooling/sdk output committed if I changed backend/cli/src/server — not touched
  • CHANGELOG.md has an Unreleased entry if the change is user-visible
  • The matching docs page under frontend/docs/src/content/openscience/ is updated if behavior changed — no doc change needed: this restores the documented meaning of $ARGUMENTS rather than changing how anything is used
  • Screenshots or a short video are attached for UI changes — not a UI change
  • No version bumps (package.json versions and tags are written by the release workflow)
  • install and frontend/landing/public/install are still byte-identical if I touched either — not touched

A string replacement expands the replacement patterns inside the text it
inserts, so `$$`, `$&`, `$'` and `` $` `` in the arguments a user typed were
rewritten: `$$` collapsed to `$`, `$&` came back as the placeholder itself and
`$'` dropped everything after it. A function replacement inserts the arguments
exactly as typed.
@vercel

vercel Bot commented Sep 27, 2026

Copy link
Copy Markdown

ANIRUDDHA ADAK (@aniruddhaadak80) is attempting to deploy a commit to the InkVell Team on Vercel.

A member of the Team first needs to authorize it.

@ishaan1124
Ishaan Gangwani (ishaan1124) merged commit 4a6d666 into synthetic-sciences:main Sep 28, 2026
8 of 9 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.

Slash-command arguments should be inserted verbatim

2 participants