Skip to content

refactor(adapters): extract escapeYamlValue into shared util and fix \r escape gap #1205

@coderabbitai

Description

@coderabbitai

Summary

The escapeYamlValue helper is currently duplicated verbatim across three adapter files:

  • src/core/command-generation/adapters/pi.ts
  • src/core/command-generation/adapters/claude.ts
  • src/core/command-generation/adapters/qwen.ts

There is also a known detect/escape asymmetry: \r (carriage return) is correctly detected as requiring YAML quoting (via the regex), but is not escaped in the double-quoted string replace chain. This gap exists consistently across all three siblings.

Proposed Work

  1. Extract escapeYamlValue into a shared utility (e.g., src/core/command-generation/utils/yaml.ts or similar).
  2. Add \r → \\r escaping in the shared implementation so double-quoted YAML strings fully conform to YAML 1.2.
  3. Update pi.ts, claude.ts, and qwen.ts to import and use the shared helper instead of their local copies.
  4. Add or update unit tests for the shared utility to cover the \r case.

Context

Requested by: @mc856

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions