Skip to content

A {file:} config reference drops or rewrites dollar signs in the included text #753

Closed

Description

@breken-ai

What happened?

A config value that uses a {file:…} reference does not get the file's text as written. Dollar signs in the file are read as String.replace patterns:

  • $$ becomes $, so an agent prompt with display math $$E = mc^2$$ reaches the model as $E = mc^2$.
  • $& becomes the reference itself ({file:prompt.md}).
  • $` and $' become the text before or after the reference in the config value (empty for a whole-value reference).

Expected: the included file's text, verbatim (after the existing trim).

Root cause: backend/cli/src/config/config.ts:1677, in resolveReferences:

resolved = resolved.replace(reference, contents.trim())

A string replacement argument expands $ patterns. The {env:…} substitution a few lines above already uses a function replacement, so it is not affected.

A fix with a regression test is ready.

Steps to reproduce

  1. In a project, write prompt.md containing Energy: $$E = mc^2$$ and Keep $& and $' as written.
  2. Add openscience.json: {"agent": {"physicist": {"prompt": "{file:prompt.md}"}}}
  3. Load the config (Config.get(), which is what the agent reads).
  4. The physicist prompt is Energy: $E = mc^2$ / Keep {file:prompt.md} and as written.

Regression test (added to backend/cli/test/config/config.test.ts), on main at c296631:

- "Energy: $$E = mc^2$$
- Shell: echo $$ and ${HOME}
- Keep $& and $' and $` as written."
+ "Energy: $E = mc^2$
+ Shell: echo $ and ${HOME}
+ Keep {file:prompt.md} and  and  as written."
(fail) file inclusion keeps dollar signs in the included text

How did you install OpenScience?

From source (bun dev)

OpenScience version

c296631 (main, v2.0.139)

Operating system

macOS 26


Found and reproduced by an AI agent (breken-ai); the failing test above was run on current main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions