Repository navigation
fix(rules): write Cursor rules as .mdc with derived frontmatter - #349
Merged
Merged
Conversation
Cursor project rules must live in .cursor/rules/ as .mdc files with YAML
frontmatter (description/globs/alwaysApply); a plain .md there is silently
ignored, so team rules synced via `teamai pull` never entered a Cursor
session. RulesHandler.pullItem wrote `${name}.md` for every tool.
- pull: for Cursor, write <name>.mdc and derive frontmatter from the team
rule — a `paths:` list maps to `globs` + alwaysApply:false, and a rule
with no paths (mandatory) maps to alwaysApply:true. Other tools still
get a plain .md copy.
- push: scanLocalForPush now also reads .cursor/rules/*.mdc, comparing
markdown bodies only so a pull→push round-trip is not seen as modified;
pushItem strips the derived frontmatter when writing an .mdc back to the
team repo.
- cleanup: stale-file cleanup, removeItem, and pull.ts tombstone cleanup
handle the .mdc extension for Cursor.
Body extraction is delimiter-based, not YAML-parsed: the Cursor `globs`
value (a leading-star glob) is invalid YAML, so a strict parse would fail
and swallow the frontmatter into the body.
Fixes git.woa.com/teamai/teamai-cli#3
…l site Follow-up on the Cursor `.mdc` fix. The extension decision lived in a private helper in rules.ts plus an inline special case in pull.ts, so the other five writers of the same directories still assumed `.md`, and the push direction dropped the team rule's frontmatter. Correctness: - pushItem now merges the Cursor body into the team file instead of replacing it, so a body edit in `.cursor/rules/*.mdc` no longer deletes the team rule's `paths:` scope for everyone on the next pull. - pre-push-sync handles `.mdc`; it previously skipped Cursor entirely, so a stale local copy was reported as "modified" and pushed over a newer team rule. - uninstall collects rules by stem, so Cursor's `.mdc` rules are actually removed instead of surviving uninstall. - `globs` is emitted quoted: a glob starting with `*` is a YAML alias node, so the frontmatter we wrote could not be parsed (gray-matter throws on it) and Cursor could drop the rule — the exact failure this series fixes. - Team frontmatter is parsed leniently, so a rule authored `globs: **/*.ts` is honoured instead of silently falling back to always-on. - An unreadable source now fails loudly rather than writing an empty rule over the team repo (push) or a stub always-on rule (pull). - The frontmatter regex accepts an empty `---/---` block instead of leaking the delimiters into the body. - local-agent reports Cursor rules again. Behavior: - Built-in rules deploy to Cursor as `.mdc` too; `teamai-recall` was still being written as a `.md` Cursor ignores. - `.cursor/rules/*.mdc` with no matching team rule is no longer offered as a new team resource — that is where Cursor's own "New Cursor Rule" writes personal rules. - `.md` copies left by the pre-`.mdc` layout are swept by pull, remove, tombstone cleanup, and uninstall. Altitude: the per-tool extension moves to src/resources/rule-format.ts (mirroring agentFileExtensionForTool) so all call sites share one decision. Docs updated in both languages; the old text claimed the body was preserved verbatim and that a Cursor push sent "just that body change" upstream.
Collaborator
Author
|
Follow-up commit addressing review findings on this branch. Data loss / correctness
Behavior
Altitude The per-tool extension moved out of a private helper in Test Plan
|
2 tasks done
jeff-r2026
added a commit
that referenced
this pull request
Aug 27, 2026
Walternater
pushed a commit
to Walternater/teamai-cli
that referenced
this pull request
Nov 2, 2026
…ent#349) * fix(rules): write Cursor rules as .mdc with derived frontmatter Cursor project rules must live in .cursor/rules/ as .mdc files with YAML frontmatter (description/globs/alwaysApply); a plain .md there is silently ignored, so team rules synced via `teamai pull` never entered a Cursor session. RulesHandler.pullItem wrote `${name}.md` for every tool. - pull: for Cursor, write <name>.mdc and derive frontmatter from the team rule — a `paths:` list maps to `globs` + alwaysApply:false, and a rule with no paths (mandatory) maps to alwaysApply:true. Other tools still get a plain .md copy. - push: scanLocalForPush now also reads .cursor/rules/*.mdc, comparing markdown bodies only so a pull→push round-trip is not seen as modified; pushItem strips the derived frontmatter when writing an .mdc back to the team repo. - cleanup: stale-file cleanup, removeItem, and pull.ts tombstone cleanup handle the .mdc extension for Cursor. Body extraction is delimiter-based, not YAML-parsed: the Cursor `globs` value (a leading-star glob) is invalid YAML, so a strict parse would fail and swallow the frontmatter into the body. Fixes git.woa.com/teamai/teamai-cli#3 * fix(rules): preserve team frontmatter and cover every Cursor .mdc call site Follow-up on the Cursor `.mdc` fix. The extension decision lived in a private helper in rules.ts plus an inline special case in pull.ts, so the other five writers of the same directories still assumed `.md`, and the push direction dropped the team rule's frontmatter. Correctness: - pushItem now merges the Cursor body into the team file instead of replacing it, so a body edit in `.cursor/rules/*.mdc` no longer deletes the team rule's `paths:` scope for everyone on the next pull. - pre-push-sync handles `.mdc`; it previously skipped Cursor entirely, so a stale local copy was reported as "modified" and pushed over a newer team rule. - uninstall collects rules by stem, so Cursor's `.mdc` rules are actually removed instead of surviving uninstall. - `globs` is emitted quoted: a glob starting with `*` is a YAML alias node, so the frontmatter we wrote could not be parsed (gray-matter throws on it) and Cursor could drop the rule — the exact failure this series fixes. - Team frontmatter is parsed leniently, so a rule authored `globs: **/*.ts` is honoured instead of silently falling back to always-on. - An unreadable source now fails loudly rather than writing an empty rule over the team repo (push) or a stub always-on rule (pull). - The frontmatter regex accepts an empty `---/---` block instead of leaking the delimiters into the body. - local-agent reports Cursor rules again. Behavior: - Built-in rules deploy to Cursor as `.mdc` too; `teamai-recall` was still being written as a `.md` Cursor ignores. - `.cursor/rules/*.mdc` with no matching team rule is no longer offered as a new team resource — that is where Cursor's own "New Cursor Rule" writes personal rules. - `.md` copies left by the pre-`.mdc` layout are swept by pull, remove, tombstone cleanup, and uninstall. Altitude: the per-tool extension moves to src/resources/rule-format.ts (mirroring agentFileExtensionForTool) so all call sites share one decision. Docs updated in both languages; the old text claimed the body was preserved verbatim and that a Cursor push sent "just that body change" upstream.
Walternater
pushed a commit
to Walternater/teamai-cli
that referenced
this pull request
Nov 2, 2026
…follow-up) (Tencent#355) Tencent#349 moved Cursor rules from .md to .mdc, but the project-agent cold-start E2E still asserted .cursor/rules/team-rule.md, so the GitHub full-surface E2E job failed on that stale assertion.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
teamai pullsynced team rules into.cursor/rules/as.mdfiles, but Cursor project rules must be.mdcwith YAML frontmatter (description/globs/alwaysApply). A plain.mdthere is silently ignored by Cursor, so team rules never entered a Cursor session — the sync reported success but had no effect. (Reported as git.woa.com/teamai/teamai-cli#3; confirmed against Cursor's current docs, which state "Project rules must use the .mdc extension" and "a plain .md file in .cursor/rules is ignored.")RulesHandler.pullItemwrote${item.name}.mdfor every tool with no per-tool branch. Push scanning and stale cleanup also only matched.md.Fix
<name>.mdcand derive frontmatter from the team rule:paths:list →globs: <comma-joined>+alwaysApply: falsepaths(a mandatory team rule) →alwaysApply: true.mdcopy.scanLocalForPushnow also reads.cursor/rules/*.mdc, comparing markdown bodies only so a cleanpull→pushround-trip is not flagged as modified;pushItemstrips the derived frontmatter when writing an.mdcback to the team repo (which stays tool-neutral.md).removeItem, and thepull.tstombstone cleanup all handle the.mdcextension for Cursor.Frontmatter mapping and the tool-neutral team format are isolated in a new
src/resources/cursor-mdc.ts. Body extraction is delimiter-based, not YAML-parsed: the Cursorglobsvalue (a leading-*glob) is invalid YAML, so a strict parse would fail and swallow the frontmatter into the body.Test Plan
npx tsc --noEmit— cleannpx vitest run— 2284 passed (18 new tests for.mdcconversion, round-trip stability, push read-back, stale cleanup, andremove; 1 stale assertion that encoded the old buggy behavior updated to expect.mdc)teamai init . → pull → push --dry-run):.mdc, Claude dir stays.mdpaths:rule →globs+alwaysApply:false; no-frontmatter rule →alwaysApply:truepushrecognizes.cursor/rules/*.mdc(previously invisible)pullis idempotent, byte-identical outputpullremoves the corresponding.mdc, keeps active onesDocs
Added a Cursor section to
docs/usage-guide.mdanddocs/usage-guide.zh-CN.mddescribing the.mdcbehavior and frontmatter mapping.