Skip to content

fix(cursor): comma-joined bare globs/description in .mdc frontmatter - #3011

Merged
Daniel Meppiel (danielmeppiel) merged 3 commits into
microsoft:mainfrom
YGuyomar:fix/cursor-globs-comma-join-3002
Sep 30, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 3 commits into
microsoft:mainfrom
YGuyomar:fix/cursor-globs-comma-join-3002

Conversation

@YGuyomar

@YGuyomar Yannick Guyomar (YGuyomar) commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

fix(cursor): preserve native rule globs and readable descriptions

TL;DR

Cursor rules now contain one comma-joined globs scalar instead of a YAML list.
Ordinary patterns, including leading **, remain bare; descriptions keep
readable Unicode while quoting and escaping preserve their values.
The contributor's fix is retained, with complete control-character escaping
and real install/compile/repeat/update regression coverage.

Fixes #3002.

Important

This verifies APM's generated artifacts, not execution inside the Cursor
application. Literal-comma matching must be checked in the user's Cursor
version; the upstream documentation does not specify it.

Problem (WHY)

  • Multiple instruction patterns were lowered to a YAML array instead of
    the comma-separated representation requested in [BUG] Cursor target emits quoted YAML list for globs instead of unquoted comma-separated string #3002.
  • Always-escaped descriptions obscured readable non-ASCII text. Simply
    disabling ASCII escaping left C1 controls and noncharacters unsafe for YAML;
    raw control characters also reached the glob scalar.
  • [!] Converter-only assertions did not establish that native output survived
    real installation, compilation, repetition, and dependency revision updates.

The validation loop follows the Agent Skills guidance:
"do the work, run a validator (a script, a reference checklist, or a self-check), fix any issues, and repeat until validation passes."
The recorded mutations below establish that the new tests detect the defects,
rather than merely passing with the proposed implementation.

Approach (WHAT)

  • Keep normalize_apply_to and parse_apply_to as the pattern authorities.
  • Re-escape individual segments before joining so APM retains literal-comma
    and backslash boundaries.
  • Emit ordinary globs bare; use a quoted escaped scalar for unsafe characters.
  • Prefer lossless plain or single-quoted descriptions, falling back to
    UTF-8-preserving double quotes when required.
  • Retain bounded YAML resolver probes and other targets' existing serializers.
  • Exercise real CLI transitions and check exact files, not success messages alone.

Implementation (HOW)

File Change
src/apm_cli/utils/patterns.py Cursor-specific scalar writers and shared segment re-escaping; one complete unsafe-character gate. Existing yaml_double_quote remains unchanged.
src/apm_cli/integration/instruction_integrator.py Cursor converter uses comma-joined native globs and readable description serialization; shared renderer signatures remain unchanged.
tests/unit/utils/test_patterns.py Scalar round trips, readable text, reserved values, escaping, bounded alias probes, and the control/noncharacter matrix.
tests/unit/integration/test_instruction_integrator.py Exact Cursor conversion, scalar/list input, escaped commas, derived descriptions, body boundaries, and safe controls.
tests/integration/test_apply_to_comma_e2e.py File-integration assertions distinguish Cursor scalar output from other target lists.
tests/integration/test_integration_runtime_coverage.py Existing Cursor runtime integration expectation uses the new native shape.
tests/integration/test_local_install.py Real installed CLI verifies multiline, C1, and noncharacter descriptions in deployed rules.
tests/integration/test_required_lifecycle_state_machine.py Two real local-Git lifecycle scenarios cover scalar and sequence metadata across repeated install/compile and pinned revision update.
docs/src/content/docs/producer/author-primitives/instructions-and-agents.md Corrects the Cursor transform table.
packages/apm-guide/.apm/skills/apm-usage/package-authoring.md Aligns maintained authoring guidance and limits native-parser claims to verified behavior.
CHANGELOG.md Records the user-visible correction and credits Yannick Guyomar (@YGuyomar).

The scalar writers
and lifecycle assertions
are the principal review points.

Diagrams

The dashed stages are the Cursor-specific rendering changes; normalization remains shared.

flowchart LR
    subgraph Input["Instruction metadata"]
        A["applyTo"]
        D["description or derived heading"]
    end
    subgraph Normalize["Existing pattern authority"]
        N["normalize_apply_to"]
        P["parse_apply_to"]
        E["escape_apply_to_segment"]
    end
    subgraph Render["Cursor scalar rendering"]
        G["Comma join and yaml_globs_scalar"]
        S["yaml_plain_scalar"]
        Q["Escape unsafe literal characters"]
    end
    subgraph Output["Target artifact"]
        O["Write .cursor/rules/name.mdc"]
    end
    A --> N --> P --> E --> G
    D --> S
    G --> Q
    S --> Q
    Q --> O
    classDef new stroke-dasharray: 5 5;
    class G,S,Q new;
Loading

Trade-offs

  • Native globs rather than strict YAML aliases. Leading ** remains bare,
    following the documented Cursor representation. A whole-frontmatter strict
    YAML parse is therefore not the oracle for ordinary native globs.
  • Readability with safety fallback. Unsafe characters still use escapes;
    “normally unquoted” is intentional, not an unconditional no-quotes promise.
  • Artifact proof rather than application proof. CLI scenarios certify
    emitted files. They do not establish Cursor matching for literal commas.
  • Narrow target scope. Claude, Copilot, Windsurf, Kiro, and Antigravity retain
    their existing formats. No README or shared rendering-contract change.

Benefits

  1. Scalar and sequence applyTo inputs produce the same native Cursor shape.
  2. All 71 selected unsafe codepoints are tested through both scalar writers.
  3. Two lifecycle scenarios prove byte stability and personal-file preservation.
  4. Existing target-specific list/verbatim forms remain explicitly asserted.

Validation

Local evidence is for 893540a418c343896a72a195314b23c3f7978fb7,
which includes main 07a465bcac8594c4eee5a6af79a6647ae2450366.
The complete lint mirror passed, including duplication, auth, architecture,
YAML I/O, file-length, and portable-path checks. On macOS, the three shell text
guards used equivalent Python regular expressions and line counting.

Executed test and mutation evidence

An isolated Python wrapper ran python -m pytest -q -p no:cacheprovider with
APM_E2E_TESTS=1, the installed .venv/bin/apm, and isolated user state.
Selectors: patterns units, instruction-integrator units, comma integration,
the two new lifecycle cases, runtime coverage, and local-install control cases.

544 passed in 146.46s (0:02:26)

The same wrapper selected hidden_unicode or four_hyphen or forced in
tests/integration/test_local_install.py. The hidden-Unicode test itself
executes both rejection and --force, for both bidi and surrogate-pair inputs;
the remaining five cases cover target-specific four-hyphen handling.

7 passed, 27 deselected in 68.56s (0:01:08)

uv run --frozen --extra dev pytest -p no:cacheprovider -q tests/quality:

63 passed in 182.59s (0:03:02)

uv run --frozen python scripts/check_test_assertions.py and
uv run --frozen python scripts/check_exact_test_duplicates.py:

[+] assertion-quality ratchet clean: AQ001=4, AQ002=12
[+] exact test duplicate ratchet clean: 1242 files, 0 allowed duplicate group(s)

Mutation checks intentionally failed before restoring the production code:
the old safety regex produced 112 failures; always-quoted globs broke both
new lifecycle cases. The restored committed head passed the runs above.
The Mermaid diagram also passed mmdc.

Remote CI is tracked separately in the PR checks; local results are not a claim
that remote CI is green.

Scenario Evidence

# Scenario (user promise) Principle(s) Test(s) proving it Type
1 Install scalar or sequence instructions and get native Cursor globs that survive compile, repeat, and a dependency update. DevX, Portability by manifest tests/integration/test_required_lifecycle_state_machine.py::test_required_cursor_metadata_survives_install_compile_update (regression-trap for #3002) e2e
2 Keep personal Cursor/Claude rules, configuration, and other target formats intact. Multi-harness support, DevX tests/integration/test_required_lifecycle_state_machine.py::test_required_cursor_metadata_survives_install_compile_update e2e
3 Install descriptions containing escaped controls without corrupting deployed metadata. Secure by default, DevX tests/integration/test_local_install.py::TestLocalInstall::test_install_cursor_quotes_multiline_control_characters e2e
4 Hidden Unicode remains rejected before writes, with explicit force behavior preserved. Secure by default, Governed by policy tests/integration/test_local_install.py::TestLocalInstall::test_install_rejects_yaml_escaped_hidden_unicode_before_writes e2e
5 Preserve APM's escaped literal-comma boundaries when converting instructions. Portability by manifest tests/unit/integration/test_instruction_integrator.py::TestConvertToCursorRules::test_escaped_literal_comma_in_glob_survives_the_comma_join unit
6 Description probing remains bounded for hostile alias content. Secure by default tests/unit/utils/test_patterns.py::TestYamlPlainScalar::test_round_trip_check_stays_bounded_for_flow_style_alias_bomb unit

How to test

  • Run uv run --frozen --extra dev pytest -q -p no:cacheprovider tests/unit/utils/test_patterns.py tests/unit/integration/test_instruction_integrator.py tests/integration/test_apply_to_comma_e2e.py; expect passing scalar, converter, and file-integration assertions.
  • With the installed .venv/bin/apm, run the new lifecycle test with APM_E2E_TESTS=1 APM_BINARY_PATH="$PWD/.venv/bin/apm"; both scalar and sequence cases should pass.
  • Run the local-install control and hidden-Unicode tests under the same E2E environment; inspect exact metadata preservation and reject/force behavior.
  • Inspect a generated .mdc: ordinary globs are one bare comma-joined line; descriptions retain readable text with necessary quoting.
  • Review the remote checks at this exact head before making a merge decision.

Co-authored-by: Copilot [email protected]

@YGuyomar

Yannick Guyomar (YGuyomar) commented Sep 17, 2026 via email •

Copy link
Copy Markdown
Contributor Author

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Three moderate implementation findings and one documentation inconsistency remain unresolved.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Updates Cursor .mdc frontmatter to emit comma-joined YAML scalar globs and readable UTF-8 descriptions.

Changes:

  • Added yaml_plain_scalar() and updated Cursor conversion.
  • Updated unit and integration coverage.
  • Updated documentation and changelog.

Review findings:

  • docs/src/content/docs/producer/author-primitives/instructions-and-agents.md — nit (3 votes): update the maintained usage skill’s outdated Cursor guidance.
  • src/apm_cli/integration/instruction_integrator.py — moderate (2 votes): preserve escaped literal commas when joining globs.
  • src/apm_cli/utils/patterns.py — moderate (3 votes): use the bounded YAML loader.
  • src/apm_cli/utils/patterns.py — moderate (1 vote): escape YAML-invalid or non-preserving control characters.
File summaries
File Description
tests/unit/utils/test_patterns.py Tests YAML scalar formatting and round trips.
tests/unit/integration/test_instruction_integrator.py Updates Cursor conversion expectations.
tests/integration/test_local_install.py Updates local-install expectations.
tests/integration/test_integration_runtime_coverage.py Updates runtime coverage expectations.
tests/integration/test_apply_to_comma_e2e.py Verifies comma-joined Cursor output.
src/apm_cli/utils/patterns.py Adds YAML scalar rendering.
src/apm_cli/integration/instruction_integrator.py Emits Cursor-compatible frontmatter.
docs/src/content/docs/producer/author-primitives/instructions-and-agents.md Documents the new Cursor format.
CHANGELOG.md Records the fix.
Review details

Suppressed comments (1)

src/apm_cli/utils/patterns.py:122

  • The ensure_ascii=False fallback is not sufficient for every YAML value: it leaves YAML-invalid controls such as U+007F unescaped, and leaves U+2028/U+2029 as YAML line breaks. A valid description containing one of these characters can therefore produce frontmatter that fails to parse or changes the text on a round trip. Escape YAML-invalid/non-preserving code points while keeping ordinary non-ASCII literal, and add regression coverage.
    return json.dumps(value, ensure_ascii=False)
  • Files reviewed: 9/9 changed files
  • Comments generated: 3
  • Review effort level: Lite

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/apm_cli/utils/patterns.py Resolved
@YGuyomar
Yannick Guyomar (YGuyomar) force-pushed the fix/cursor-globs-comma-join-3002 branch from 353313d to 4cea9e2 Compare September 17, 2026 12:19
@YGuyomar Yannick Guyomar (YGuyomar) changed the title fix(cursor): comma-joined plain-scalar globs/description in .mdc frontmatter fix(cursor): comma-joined bare globs/description in .mdc frontmatter Sep 17, 2026
@YGuyomar
Yannick Guyomar (YGuyomar) force-pushed the fix/cursor-globs-comma-join-3002 branch from 4cea9e2 to 7bb0169 Compare September 17, 2026 15:30
@YGuyomar

Copy link
Copy Markdown
Contributor Author

Also addressing the suppressed finding on src/apm_cli/utils/patterns.py:122 (no inline thread exists for it, so replying here): "The ensure_ascii=False fallback ... leaves YAML-invalid controls such as U+007F unescaped, and leaves U+2028/U+2029 as YAML line breaks ... Escape YAML-invalid/non-preserving code points while keeping ordinary non-ASCII literal, and add regression coverage."

Fixed in 7bb0169. The double-quoted fallback (_yaml_double_quote_utf8_safe()) now explicitly \uXXXX-escapes DEL (U+007F), NEL (U+0085), LS (U+2028), and PS (U+2029) on top of json.dumps(..., ensure_ascii=False), since JSON's own required-escape range stops at U+001F and doesn't cover any of these.

While adding regression coverage I found the round-trip check itself (not just the fallback) had a related blind spot: PyYAML folds any line-break-like character, not just \n/\r, when scanning a multi-line plain/single-quoted scalar -- so a value containing e.g. U+2029 immediately followed by \n could spuriously round-trip as "equal to itself" by coincidence, skipping the fallback entirely. yaml_plain_scalar()/yaml_globs_scalar() now check for any of these characters up front and route straight to the escaped fallback rather than relying purely on the round-trip check.

That same pass also surfaced a real regression against test_local_install.py::test_install_rejects_yaml_escaped_hidden_unicode_before_writes: a lone (unpaired) UTF-16 surrogate -- this project's existing hidden-unicode security-gate attack shape, e.g. a description escaped as \uDB40\uDC01 -- isn't just YAML-unsafe, it can't be UTF-8 encoded at all, so leaving it literal crashed the eventual file write outright even under --force. Folded the same fix in: lone surrogates now also force the escaped double-quoted fallback.

New coverage: test_del_control_char_escapes_to_uXXXX, test_line_separator_forces_double_quote_and_escapes, test_paragraph_separator_adjacent_to_newline_round_trips, test_next_line_control_char_escapes_to_uXXXX, test_lone_surrogate_escapes_instead_of_crashing_utf8_encode (both yaml_plain_scalar and yaml_globs_scalar variants), plus an integration-level test_lone_surrogate_description_does_not_crash_utf8_encode.

@sergio-sisternes-epam

Sergio Sisternes (sergio-sisternes-epam) commented Sep 18, 2026 •

Copy link
Copy Markdown
Collaborator

Thank you for contributing this pull request, Yannick Guyomar (@YGuyomar), and for
filing #3002. APM starts with an issue, not an implementation
(https://github.com/microsoft/apm/blob/main/CONTRIBUTING.md).

#3002 is not yet status/accepted and has no human scope record.
Please wait for a maintainer to review and accept that issue first.
This PR is labelled status/deferred until that happens.


Generated by autopilot-pr-triage-worker. This comment is AI-generated and may contain errors.

@sergio-sisternes-epam Sergio Sisternes (sergio-sisternes-epam) added triage/recommended Automated advice completed; not human scope approval. status/deferred Not invited for implementation now; no release commitment. type/bug Something does not work as documented. area/multi-target Multi-target deploy spec, target directory creation, agent surface routing. theme/portability status/accepted Human scope approval; verify the issue's approval record and review contact before work. and removed status/deferred Not invited for implementation now; no release commitment. labels Sep 18, 2026
@YGuyomar
Yannick Guyomar (YGuyomar) force-pushed the fix/cursor-globs-comma-join-3002 branch 3 times, most recently from a1ecda1 to 9ac256c Compare September 25, 2026 09:59
Cursor's .mdc frontmatter never uses a YAML list for globs and never
shows quoted values in its own docs, but the Cursor converter emitted
a quoted YAML list for comma-separated applyTo (inherited from the
ensure_ascii=True, escaping non-ASCII description text as \uXXXX.

Add yaml_plain_scalar() (patterns.py) for description: prefer a bare
scalar verified via YAML's own resolver, fall back to single-quoted,
and only use a double-quoted UTF-8-preserving scalar for values
neither can represent (embedded newlines).

globs gets its own, more permissive yaml_globs_scalar(): always bare,
including patterns starting with "**". A leading "**" is technically
a YAML alias indicator under a strict parser, but Cursor's own docs
never quote it either and its frontmatter reader tolerates it -- glob
syntax has none of the ": "/reserved-word ambiguity that description
free text can have. The only thing still quoted is a literal embedded
newline, which would inject extra lines into the frontmatter block
regardless of parser leniency.

Wire both into _convert_to_cursor_rules; globs is always comma-joined
into one scalar instead of a YAML list. Scoped to Cursor only; other
targets keep yaml_double_quote().

Address review feedback from Copilot's automated PR review:

- Re-escape each glob (escape_apply_to_segment, renamed public) before
  comma-joining, so a literal comma the author escaped in applyTo
  (\,) doesn't become indistinguishable from the join separator.
- Route the plain/single-quoted round-trip check through the
  project's bounded YAML loader (load_yaml_str) instead of stock
  yaml.safe_load, closing a YAML alias/merge-key expansion DoS that
  parsing untrusted description text a second time would otherwise
  reintroduce.
- Escape DEL, NEL, LS, and PS, plus any lone UTF-16 surrogate, in the
  double-quoted fallback: ensure_ascii=False otherwise leaves them
  raw, which either changes silently on a strict YAML re-parse (NEL/
  LS/PS are YAML 1.1 line breaks) or crashes the eventual UTF-8 file
  write outright (DEL and lone surrogates cannot be UTF-8 encoded --
  the latter is this project's existing hidden-unicode security-gate
  attack shape).
- Update package-authoring.md's applyTo/globs section: Cursor's globs
  is a comma-joined bare scalar, not a YAML array like the other
  targets, and a literal comma inside one glob still isn't
  representable in a Cursor rule even though the escape round-trips
  through APM's own tooling.

Fixes microsoft#3002.
@YGuyomar
Yannick Guyomar (YGuyomar) force-pushed the fix/cursor-globs-comma-join-3002 branch from 9ac256c to 153f083 Compare September 28, 2026 09:10
@danielmeppiel

Daniel Meppiel (danielmeppiel) commented Sep 30, 2026 •

Copy link
Copy Markdown
Collaborator

APM Review Panel: ship_now

Yannick Guyomar (@YGuyomar) Sergio Sisternes (@sergio-sisternes-epam) -- the final GPT-6 Astra delta review found no remaining technical follow-ups. The contributor's fix and attribution are preserved.

Cursor globs now use the native comma-joined scalar, readable descriptions retain lossless quoting, and unsafe characters are escaped. Real CLI scenarios cover install, compile, repeat and pinned update while preserving personal files and other targets.

Reviewed and pushed head: 893540a418c343896a72a195314b23c3f7978fb7
Included main: 07a465bcac8594c4eee5a6af79a6647ae2450366

Panel lens Remaining findings
Python architecture 0
Test coverage 0
Documentation 0
Performance 0
DevX 0
Metadata safety 0
Evidence Observed result
Exact-head functional scenarios 544 passed, including scalar/sequence lifecycle and control-character installation
Existing policy/target behavior 7 passed: five target cases plus two hidden-Unicode cases, each executing rejection and --force
Test quality 63 passed; assertion and duplicate ratchets clean
Regression mutations Old safety regex caused 112 failures; always-quoted globs broke both lifecycle cases; restored before final execution
Canonical ownership Version-2 schema and semantic verification passed; the detected owner is covered by both executed lifecycle cases
Lint Full local mirror and remote lint passed
CI CI, CodeQL, docs build, spec, NOTICE, and required gate succeeded at this head

The three existing inline threads have been answered and resolved. Starlight, the maintained usage guide, and the PR description now agree on the verified behavior.

Boundary: these results certify APM's artifacts, not execution inside Cursor or literal-comma matching. GitHub reports MERGEABLE / BLOCKED; code-owner approval, last-push approval and merge-queue rules remain in effect. This recommendation is not human approval, and no merge or policy change was performed.


Generated by autopilot-pr-merge-worker. This comment is AI-generated and may contain errors.

Complete scalar escaping, verify real install/compile/repeat/update behavior, and narrow documentation to the native writer contract.

Co-authored-by: Copilot App <[email protected]>
@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit d6bafc5 into microsoft:main Sep 30, 2026
21 checks passed
Sergio Sisternes (sergio-sisternes-epam) added a commit that referenced this pull request Sep 30, 2026
Resolve CHANGELOG.md: keep Unreleased Changed for #2983 and take
main Unreleased Fixed for #3011.

Co-authored-by: Copilot App <[email protected]>
Daniel Meppiel (danielmeppiel) added a commit to WilliamK112/apm that referenced this pull request Nov 12, 2026
Reconcile microsoft#1744 with current main. Main now renders Cursor globs as one
comma-joined scalar (microsoft#3002/microsoft#3011), owns req-tg-015 (Codex agent model)
and Section 8.5.9 (Cursor hooks), and is at working-draft revision
0.1.57. Keep main's rendering and add only the universal branch:
exactly one parsed `**` emits `alwaysApply: true` with no globs, via a
named `_is_universal_glob` predicate (panel nit). Renumber the spec
amendment to req-tg-018 / Section 8.5.10 / 0.1.58 (proposed), restate
it against comma-scalar globs with the nine-case boundary from the
apm-scope:v1 record, bind a nine-case conformance test, regenerate
CONFORMANCE from main's coverage plus the new node IDs, update the
apm-usage guide, author and targets-matrix docs (absent/empty/null case), and move the
CHANGELOG entry to Unreleased.

Co-authored-by: WilliamK112 <[email protected]>
Co-authored-by: Copilot App <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/multi-target Multi-target deploy spec, target directory creation, agent surface routing. status/accepted Human scope approval; verify the issue's approval record and review contact before work. triage/recommended Automated advice completed; not human scope approval. type/bug Something does not work as documented.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Cursor target emits quoted YAML list for globs instead of unquoted comma-separated string

4 participants