Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/__tests__/rules.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,21 @@ describe('RulesHandler — Cursor-compatible .mdc handling', () => {
expect(teamContent).not.toContain('globs');
});

it('pushItem preserves a namespaced rule destination', async () => {
const sourcePath = path.join(homeDir, '.claude/rules/scoped.md');
await fse.ensureDir(path.dirname(sourcePath));
await fse.writeFile(sourcePath, 'Scoped rule body.');

await handler.pushItem(
{ name: 'scoped', type: 'rules', sourcePath, relativePath: 'rules/frontend/scoped.md' },
teamConfig,
localConfig,
);

expect(await fse.readFile(path.join(repoPath, 'rules/frontend/scoped.md'), 'utf-8')).toBe('Scoped rule body.');
expect(await fse.pathExists(path.join(repoPath, 'rules/scoped.md'))).toBe(false);
});

it('pushItem preserves the team rule `paths:` frontmatter when pushing from cursor', async () => {
// The team rule is scoped; only its body may cross back from Cursor.
await fse.writeFile(
Expand Down
9 changes: 8 additions & 1 deletion src/resources/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
mergeCopilotBodyIntoTeamMd,
teamRuleToCopilotInstructions,
} from './copilot-instructions.js';
import { assertWithinRoot } from '../utils/path-safety.js';
import {
ruleFileExtensionForTool,
ruleStemFromFilename,
Expand Down Expand Up @@ -152,7 +153,13 @@ export class RulesHandler extends ResourceHandler {
}

async pushItem(item: ResourceItem, _teamConfig: TeamaiConfig, localConfig: LocalConfig): Promise<void> {
const dest = path.join(localConfig.repo.localPath, 'rules', `${item.name}.md`);
const rulesRoot = path.join(localConfig.repo.localPath, 'rules');
const dest = path.resolve(localConfig.repo.localPath, item.relativePath);
assertWithinRoot(
rulesRoot,
dest,
`Invalid rule destination outside team repo rules directory: ${item.relativePath}`,
);
if (item.sourcePath !== dest) {
if (item.sourcePath.endsWith('.mdc')) {
// Source is a tool-native `.mdc`. Only its markdown body is pushed: the
Expand Down
Loading