fix(cursor): comma-joined bare globs/description in .mdc frontmatter - #3011
Yannick Guyomar (YGuyomar) wants to merge 1 commit into
Conversation
|
@microsoft-github-policy-service agree company="SLB"
…________________________________
From: microsoft-github-policy-service[bot] ***@***.***>
Sent: Thursday, September 17, 2026 1:45 PM
To: microsoft/apm ***@***.***>
Cc: Yannick Guyomar ***@***.***>; Mention ***@***.***>
Subject: [Ext] Re: [microsoft/apm] fix(cursor): comma-joined plain-scalar globs/description in .mdc frontmatter (PR #3011)
microsoft-github-policy-service[bot] left a comment (microsoft/apm#3011) Yannick Guyomar (@ YGuyomar) please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information. @microsoft-github-policy-service
[https://avatars.githubusercontent.com/in/95686?s=20&v=4]microsoft-github-policy-service[bot] left a comment (microsoft/apm#3011)<https://urldefense.com/v3/__https://github.com/microsoft/apm/pull/3011*issuecomment-5713779501__;Iw!!Kjv0uj3L4nM6H-I!gEN3mQTBll4YY8oxdwOJZAyL_ZPEg1r5aFIGQZEjH-yfu3WQjERCg_GStqgaGtEDm3PLu0AInbQAEQvjOkb7Pg$>
Yannick Guyomar ***@***.***)<https://urldefense.com/v3/__https://github.com/YGuyomar__;!!Kjv0uj3L4nM6H-I!gEN3mQTBll4YY8oxdwOJZAyL_ZPEg1r5aFIGQZEjH-yfu3WQjERCg_GStqgaGtEDm3PLu0AInbQAEQv43ByVaw$> please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
@microsoft-github-policy-service agree [company="{your company}"]
Options:
* (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@microsoft-github-policy-service agree
* (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@microsoft-github-policy-service agree company="Microsoft"
Contributor License Agreement
Contribution License Agreement
This Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
and conveys certain license rights to Microsoft Corporation and its affiliates (“Microsoft”) for Your
contributions to Microsoft open source projects. This Agreement is effective as of the latest signature
date below.
1. Definitions.
“Code” means the computer software code, whether in human-readable or machine-executable form,
that is delivered by You to Microsoft under this Agreement.
“Project” means any of the projects owned or managed by Microsoft and offered under a license
approved by the Open Source Initiative (www.opensource.org<https://urldefense.com/v3/__http://www.opensource.org__;!!Kjv0uj3L4nM6H-I!gEN3mQTBll4YY8oxdwOJZAyL_ZPEg1r5aFIGQZEjH-yfu3WQjERCg_GStqgaGtEDm3PLu0AInbQAEQvE_dYfBw$>).
“Submit” is the act of uploading, submitting, transmitting, or distributing code or other content to any
Project, including but not limited to communication on electronic mailing lists, source code control
systems, and issue tracking systems that are managed by, or on behalf of, the Project for the purpose of
discussing and improving that Project, but excluding communication that is conspicuously marked or
otherwise designated in writing by You as “Not a Submission.”
“Submission” means the Code and any other copyrightable material Submitted by You, including any
associated comments and documentation.
2. Your Submission. You must agree to the terms of this Agreement before making a Submission to any
Project. This Agreement covers any and all Submissions that You, now or in the future (except as
described in Section 4 below), Submit to any Project.
3. Originality of Work. You represent that each of Your Submissions is entirely Your original work.
Should You wish to Submit materials that are not Your original work, You may Submit them separately
to the Project if You (a) retain all copyright and license information that was in the materials as You
received them, (b) in the description accompanying Your Submission, include the phrase “Submission
containing materials of a third party:” followed by the names of the third party and any licenses or other
restrictions of which You are aware, and (c) follow any other instructions in the Project’s written
guidelines concerning Submissions.
4. Your Employer. References to “employer” in this Agreement include Your employer or anyone else
for whom You are acting in making Your Submission, e.g. as a contractor, vendor, or agent. If Your
Submission is made in the course of Your work for an employer or Your employer has intellectual
property rights in Your Submission by contract or applicable law, You must secure permission from Your
employer to make the Submission before signing this Agreement. In that case, the term “You” in this
Agreement will refer to You and the employer collectively. If You change employers in the future and
desire to Submit additional Submissions for the new employer, then You agree to sign a new Agreement
and secure permission from the new employer before Submitting those Submissions.
5. Licenses.
* Copyright License. You grant Microsoft, and those who receive the Submission directly or
indirectly from Microsoft, a perpetual, worldwide, non-exclusive, royalty-free, irrevocable license in the
Submission to reproduce, prepare derivative works of, publicly display, publicly perform, and distribute
the Submission and such derivative works, and to sublicense any or all of the foregoing rights to third
parties.
* Patent License. You grant Microsoft, and those who receive the Submission directly or
indirectly from Microsoft, a perpetual, worldwide, non-exclusive, royalty-free, irrevocable license under
Your patent claims that are necessarily infringed by the Submission or the combination of the
Submission with the Project to which it was Submitted to make, have made, use, offer to sell, sell and
import or otherwise dispose of the Submission alone or with the Project.
* Other Rights Reserved. Each party reserves all rights not expressly granted in this Agreement.
No additional licenses or rights whatsoever (including, without limitation, any implied licenses) are
granted by implication, exhaustion, estoppel or otherwise.
1. Representations and Warranties. You represent that You are legally entitled to grant the above
licenses. You represent that each of Your Submissions is entirely Your original work (except as You may
have disclosed under Section 3). You represent that You have secured permission from Your employer to
make the Submission in cases where Your Submission is made in the course of Your work for Your
employer or Your employer has intellectual property rights in Your Submission by contract or applicable
law. If You are signing this Agreement on behalf of Your employer, You represent and warrant that You
have the necessary authority to bind the listed employer to the obligations contained in this Agreement.
You are not expected to provide support for Your Submission, unless You choose to do so. UNLESS
REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING, AND EXCEPT FOR THE WARRANTIES
EXPRESSLY STATED IN SECTIONS 3, 4, AND 6, THE SUBMISSION PROVIDED UNDER THIS AGREEMENT IS
PROVIDED WITHOUT WARRANTY OF ANY KIND, INCLUDING, BUT NOT LIMITED TO, ANY WARRANTY OF
NONINFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
2. Notice to Microsoft. You agree to notify Microsoft in writing of any facts or circumstances of which
You later become aware that would make Your representations in this Agreement inaccurate in any
respect.
3. Information about Submissions. You agree that contributions to Projects and information about
contributions may be maintained indefinitely and disclosed publicly, including Your name and other
information that You submit with Your Submission.
4. Governing Law/Jurisdiction. This Agreement is governed by the laws of the State of Washington, and
the parties consent to exclusive jurisdiction and venue in the federal courts sitting in King County,
Washington, unless no federal subject matter jurisdiction exists, in which case the parties consent to
exclusive jurisdiction and venue in the Superior Court of King County, Washington. The parties waive all
defenses of lack of personal jurisdiction and forum non-conveniens.
5. Entire Agreement/Assignment. This Agreement is the entire agreement between the parties, and
supersedes any and all prior agreements, understandings or communications, written or oral, between
the parties relating to the subject matter hereof. This Agreement may be assigned by Microsoft.
—
Reply to this email directly, view it on GitHub<https://urldefense.com/v3/__https://github.com/microsoft/apm/pull/3011?email_source=notifications&email_token=AEV52NYYPK3QG3USETLDIJL5PPFDZA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKNZRGM3TOOJVGAY2M4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJLDGN5XXIZLSL5RWY2LDNM*issuecomment-5713779501__;Iw!!Kjv0uj3L4nM6H-I!gEN3mQTBll4YY8oxdwOJZAyL_ZPEg1r5aFIGQZEjH-yfu3WQjERCg_GStqgaGtEDm3PLu0AInbQAEQt5-9egcw$>, or unsubscribe<https://urldefense.com/v3/__https://github.com/notifications/unsubscribe-auth/AEV52N6TENVHHMP3S2NOEKD5PPFDZAVCNFSNUABGKJSXA33TNF2G64TZHMYTANJZGQ3TENJUHE5US43TOVSTWNJUHA3DQNZYGAYTFILWAI__;!!Kjv0uj3L4nM6H-I!gEN3mQTBll4YY8oxdwOJZAyL_ZPEg1r5aFIGQZEjH-yfu3WQjERCg_GStqgaGtEDm3PLu0AInbQAEQu9TKj4Ag$>.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS<https://urldefense.com/v3/__https://github.com/notifications/mobile/ios/AEV52N6ZK2DNO6ZEYAHG3OT5PPFDZA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKNZRGM3TOOJVGAY2M4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJKTGN5XXIZLSL5UW64Y__;!!Kjv0uj3L4nM6H-I!gEN3mQTBll4YY8oxdwOJZAyL_ZPEg1r5aFIGQZEjH-yfu3WQjERCg_GStqgaGtEDm3PLu0AInbQAEQtdwerShw$> and Android<https://urldefense.com/v3/__https://github.com/notifications/mobile/android/AEV52N5NBF36PE7NITMNNVD5PPFDZA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKNZRGM3TOOJVGAY2M4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJLTGN5XXIZLSL5QW4ZDSN5UWI__;!!Kjv0uj3L4nM6H-I!gEN3mQTBll4YY8oxdwOJZAyL_ZPEg1r5aFIGQZEjH-yfu3WQjERCg_GStqgaGtEDm3PLu0AInbQAEQugzSQdxQ$>. Download it today!
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
There was a problem hiding this comment.
🟡 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=Falsefallback 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.
| parts.append("globs:") | ||
| parts.extend(f" - {yaml_double_quote(g)}" for g in globs) | ||
| if globs: | ||
| parts.append(f"globs: {yaml_plain_scalar(', '.join(globs))}") |
There was a problem hiding this comment.
Fixed in 7bb0169. _convert_to_cursor_rules now re-escapes each glob with the newly-public escape_apply_to_segment() (patterns.py) before joining with , , so applyTo: 'src/foo\,bar/*.py' renders as globs: src/foo\,bar/*.py instead of silently collapsing into two patterns.
Worth being explicit about the residual limitation: this can't make the pattern actually work in Cursor, since Cursor's own comma-splitting isn't escape-aware. What it does do is keep APM's own output consistent with parse_apply_to's documented convention instead of silently mis-splitting it -- and package-authoring.md plus the commit message now call out that a literal comma in a glob still isn't representable in a Cursor rule.
Added TestEscapeApplyToSegment and test_escaped_literal_comma_in_glob_survives_the_comma_join for regression coverage.
| def _yaml_scalar_round_trips(candidate: str, expected: str) -> bool: | ||
| """Return True if parsing ``candidate`` as a bare YAML scalar yields ``expected``.""" | ||
| try: | ||
| return yaml.safe_load(candidate) == expected |
There was a problem hiding this comment.
Fixed in 7bb0169. _yaml_scalar_round_trips now calls load_yaml_str() (the project's _BoundedSafeLoader-backed helper from yaml_io.py) instead of stock yaml.safe_load, so a hostile description can no longer bypass the repo's merge/alias expansion guard on this second, in-memory parse.
Added test_round_trip_check_stays_bounded_for_flow_style_alias_bomb, which feeds a single-line flow-style merge-key bomb (same shape as test_yaml_io.py::test_merge_key_bomb_fails_closed, just written without newlines so it isn't trivially short-circuited by the newline-forces-double-quote branch) through yaml_plain_scalar() and asserts it fails closed instead of attempting exponential alias expansion.
| | claude | `.claude/rules/<name>.md` | `applyTo` -> `paths:` list (comma-lists expanded to YAML array) | | ||
| | grok-build | `.grok/rules/<name>.md` and folded into `AGENTS.md` | native rule plus compiled root context | | ||
| | cursor | `.cursor/rules/<name>.mdc` | `applyTo` -> `globs:` (scalar for single glob, YAML array for comma-lists); description auto-derived if missing | | ||
| | cursor | `.cursor/rules/<name>.mdc` | `applyTo` -> `globs:` (one comma-joined scalar, plain/unquoted when safe, matching Cursor's native format); description auto-derived if missing | |
There was a problem hiding this comment.
Fixed in 7bb0169. Updated packages/apm-guide/.apm/skills/apm-usage/package-authoring.md's applyTo/globs section to describe Cursor's actual comma-joined bare-scalar globs: format (not a YAML array like Claude/Windsurf/Kiro/Antigravity), and added a note that a literal comma inside one glob still isn't representable in a Cursor rule even though APM's own tooling preserves the \, escape when re-joining patterns for that target.
353313d to
4cea9e2
Compare
4cea9e2 to
7bb0169
Compare
|
Also addressing the suppressed finding on Fixed in 7bb0169. The double-quoted fallback ( 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 That same pass also surfaced a real regression against New coverage: |
|
Thank you for contributing this pull request, Yannick Guyomar (@YGuyomar), and for #3002 is not yet Generated by autopilot-pr-triage-worker. This comment is AI-generated and may contain errors. |
7bb0169 to
c0c270a
Compare
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.
c0c270a to
a1ecda1
Compare
fix(cursor): comma-joined bare globs/description in
.mdcfrontmatterTL;DR
The Cursor target compiler emitted
globsas a quoted YAML list (globs:\n - "a"\n - "b") whenever an instruction'sapplyTohad comma-separated globs, and always double-quoteddescription/globswith\uXXXX-escaped non-ASCII text. Neither shape appears anywhere in Cursor's own.mdcdocs. This PR makes Cursor emit the one documented shape: a single, comma-joined, always-bare scalar forglobs, and a bare-when-possible, never-\u-escaped scalar fordescription.Problem (WHY)
globsas a single string, multiple patterns comma-joined, never a YAML list, and never quoted -- not even for patterns starting with**(globs: src/components/**/*.tsx,docs/**/*.md, docs/**/*.mdx). APM instead emitted a multi-item block sequence for 2+ globs, with every value double-quoted.ensure_ascii=Trueon the old double-quoting also meant any non-ASCIIdescription(em dash, arrows, accented text) round-tripped through\uXXXXescapes instead of literal UTF-8, hurting diff readability of generated.mdcfiles.paths:to expand comma-lists into a YAML block sequence, and the same list-shaping logic was reused for Cursor'sglobs:"for consistency," without checking that Cursor's native format has no list syntax -- and no quoting -- forglobsat all.Fixes #3002.
Approach (WHAT)
', '.join(globs)); list branch removed entirelyglobs, including a leading**yaml_globs_scalar(): always bare. A leading**is technically a YAML alias indicator under a strict parser, but Cursor's docs never quote it and its frontmatter reader tolerates it; glob syntax has none of the": "/reserved-word ambiguity free text can have. Only a literal embedded newline still forces quoting (defence against frontmatter injection)description,\uXXXX-escaped non-ASCIIyaml_plain_scalar(): bare if it round-trips through YAML's own resolver, else single-quoted, else (embedded newline only) double-quoted withensure_ascii=FalseNote
An earlier revision of this PR still single-quoted
globsvalues starting with**(treating a strict-YAML round-trip check as the safety bar). @YGuyomar caught that this contradicts Cursor's own docs, which never show a quotedglobsvalue under any circumstance -- fixed by givingglobsits own always-bare rule instead of reusing the description helper.Scoped to the Cursor converter only. Claude/Windsurf/Kiro/Antigravity keep their existing (correct-for-them) always-quoted, list-capable format via the untouched
yaml_double_quote()-- this issue is Cursor-specific, and touching the shared multi-target helper wasn't warranted.Implementation (HOW)
src/apm_cli/utils/patterns.py: addedyaml_plain_scalar(value)fordescription(bare-if-safe -> single-quoted -> double-quoted UTF-8 fallback, verified viayaml.safe_load) andyaml_globs_scalar(value)forglobs(always bare unless the value contains a literal\n/\r, in which case JSON-escape it).src/apm_cli/integration/instruction_integrator.py:_convert_to_cursor_rules()emitsglobs: {yaml_globs_scalar(', '.join(globs))}for any non-empty glob list (previously branched scalar-vs-list-of-quoted-scalars), anddescriptiongoes throughyaml_plain_scalar().TestConvertToCursorRules, the Cursor rows ofTestApplyToCommaSplitting(issue [BUG] applyTo comma-separated globs are not split ? Claude target emits broken paths: and compiler warns "matches no files" #1366's coverage),test_apply_to_comma_e2e.py, andtest_integration_runtime_coverage.pyto assert the bare, comma-joined shape -- including for globs starting with**. AddedTestYamlPlainScalar(description helper) andTestYamlGlobsScalar(globs helper, including the "stays bare with a leading**" and "newline still quotes" cases).instructions-and-agents.md's target transform table updated to describe the comma-joined, always-bare shape.Trade-offs
globsanddescriptionnow follow deliberately different quoting rules (always-bare vs. bare-when-safe). This is intentional, not an inconsistency: glob syntax has no legitimate need for the YAML ambiguities (:, reserved words, alias-like leading*) that free-form description text can hit, and Cursor's docs draw exactly that line -- everyglobsexample is bare,descriptionexamples are plain English that happens not to need quoting.yaml_double_quote()untouched and added two narrowly-scoped helpers rather than generalizing one function, so Claude/Windsurf/Kiro/Antigravity behavior (out of scope here) can't regress by accident.src/apm_cli/integration/is well under the 20-line threshold, and no existingreq-tg-*statement pins Cursor'sglobsshape (only Antigravity's is normatively pinned today).Validation
The 5 failures are pre-existing, reproduced identically on the pre-fix commit
Reran the exact same 5 tests with this PR's changes
git stashed (i.e. against the prior commit) -- identical failures, none touchingglobs/cursor/patterns.py/instruction_integrator.py:test_install_rejects_yaml_escaped_hidden_unicode_before_writes[surrogate-pair-tag]-- pre-existing Windows'utf-8' codec can't encode ... surrogates not allowedin an unrelated unicode-security test.test_deps_shows_local_packages-- unrelatedsubprocess.runresult handling.test_token_file_mode_ok_missing_file_returns_false-- unrelated Windows file-permission-mode test.test_returns_output_and_return_code,test_failed_command_returns_nonzero_rc-- unrelated: callecho/false, which aren't standalone executables on Windows.Before / after
How to test
apm install --target cursora package whose instruction has a comma-separatedapplyTo(e.g.services/**/*.py,plugins/services/**/*.py)..cursor/rules/<name>.mdcand confirmglobs:is one unquoted, comma-joined line -- not a block sequence, not quoted.applyToglob starting with**(e.g.**/*.ts) and confirm it stays bare too.descriptioncontaining non-ASCII text (em dash, accented characters) and confirm it appears as literal UTF-8, not\uXXXXescapes.