Skip to content

fix: quote parameters correctly for cmd.exe custom tools - #1124

Open
awhite0030 wants to merge 1 commit into
Nano-Collective:mainfrom
awhite0030:fix-cmd-quoting-custom-tools-15739419436906336590
Open

fix: quote parameters correctly for cmd.exe custom tools#1124
awhite0030 wants to merge 1 commit into
Nano-Collective:mainfrom
awhite0030:fix-cmd-quoting-custom-tools-15739419436906336590

Conversation

@awhite0030

Copy link
Copy Markdown
Contributor

Description

Brief description of what this PR does

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Changeset

  • Added a changeset (pnpm changeset) describing this change for the changelog

Docs-only or internal chores need no changeset (or run pnpm changeset --empty to note that intentionally).

Testing

Automated Tests

  • New features include passing tests in .spec.ts/tsx files
  • All existing tests pass (pnpm test:all completes successfully)
  • Tests cover both success and error scenarios

Manual Testing

  • Tested with Ollama
  • Tested with OpenRouter
  • Tested with OpenAI-compatible API
  • Tested MCP integration (if applicable)

Checklist

  • If this was for an open issue, I was assigned to it
  • Code follows project style guidelines
  • Self-review completed
  • Documentation updated (if needed)
  • No breaking changes (or clearly documented)
  • Appropriate logging added using structured logging (see CONTRIBUTING.md)

Root cause: The custom tool template engine universally applied POSIX single-quote escaping for all arguments (renderValue -> shellQuote). On Windows cmd.exe, this resulted in strings wrapped in literal ' marks, breaking file paths and failing to prevent shell injection vectors from characters like & and %VAR%.

Fix: Extracted isWindowsCmd from handler.ts and introduced a cmdQuote function in template.ts that escapes metacharacters %, &, |, <, >, and ^ by prefixing them with ^ and wrapping the argument in double quotes. The template renderer now takes the shell as an optional parameter and uses cmdQuote if it detects a Windows cmd shell.

Validation:

pnpm run build
pnpm test:format
pnpm test:lint
pnpm test:types
pnpm test:knip
pnpm test:ava source/custom-tools/*.spec.ts

(Note: Only custom-tools tests were run via ava due to container environment timeouts)

Fixes #1084

Fixes #1084

This addresses an issue where parameters substituted into custom tool templates were quoted using POSIX single-quotes globally. Under `cmd.exe` on Windows, these quotes are treated literally rather than as escape mechanisms, which broke paths like `type 'notes.txt'` and left shell metacharacters unprotected.

Now, `template.ts` takes an optional `shell` hint and branches quoting behavior: POSIX uses `shellQuote` while `cmd.exe` uses `cmdQuote`, which correctly escapes `%`, `&`, `|`, `<`, `>`, and `^` and uses double quotes.

Fixes Nano-Collective#1084
@github-actions github-actions Bot added the area:tools Tool implementations and tool-calling label Sep 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:tools Tool implementations and tool-calling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Custom tool {{ }} quoting is POSIX-only; cmd.exe is not covered

1 participant