Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
12 changes: 9 additions & 3 deletions src/core/configurators/cline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,24 @@ import { OPENSPEC_MARKERS } from '../config.js';

export class ClineConfigurator implements ToolConfigurator {
name = 'Cline';
configFileName = 'CLINE.md';
configFileName = '.clinerules/AGENTS.md';
isAvailable = true;

async configure(projectPath: string, openspecDir: string): Promise<void> {
const filePath = path.join(projectPath, this.configFileName);
const content = TemplateManager.getClineTemplate();
const content = TemplateManager.getAgentsStandardTemplate();

await FileSystemUtils.updateFileWithMarkers(
filePath,
content,
OPENSPEC_MARKERS.start,
OPENSPEC_MARKERS.end
);

// When Cline is selected, remove the root AGENTS.md since we want it in .clinerules
const rootAgentsPath = path.join(projectPath, 'AGENTS.md');
if (await FileSystemUtils.fileExists(rootAgentsPath)) {
await FileSystemUtils.deleteFile(rootAgentsPath);
}
}
}
4 changes: 4 additions & 0 deletions src/utils/file-system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ export class FileSystemUtils {
return await fs.readFile(filePath, 'utf-8');
}

static async deleteFile(filePath: string): Promise<void> {
await fs.unlink(filePath);
}

static async updateFileWithMarkers(
filePath: string,
content: string,
Expand Down
29 changes: 6 additions & 23 deletions test/core/init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type SelectionQueue = string[][];

let selectionQueue: SelectionQueue = [];

const mockPrompt = vi.fn(async () => {
const mockPrompt = vi.fn(async (options: any) => {
if (selectionQueue.length === 0) {
throw new Error('No queued selections provided to init prompt.');
}
Expand Down Expand Up @@ -136,38 +136,21 @@ describe('InitCommand', () => {
expect(updatedContent).toContain('Custom instructions here');
});

it('should create CLINE.md when Cline is selected', async () => {
it('should create .clinerules/AGENTS.md when Cline is selected', async () => {
queueSelections('cline', DONE);

await initCommand.execute(testDir);

const clinePath = path.join(testDir, 'CLINE.md');
expect(await fileExists(clinePath)).toBe(true);
const clineAgentsPath = path.join(testDir, '.clinerules', 'AGENTS.md');
expect(await fileExists(clineAgentsPath)).toBe(true);

const content = await fs.readFile(clinePath, 'utf-8');
const content = await fs.readFile(clineAgentsPath, 'utf-8');
expect(content).toContain('<!-- OPENSPEC:START -->');
expect(content).toContain("@/openspec/AGENTS.md");
expect(content).toContain('OpenSpec Instructions');
expect(content).toContain('openspec update');
expect(content).toContain('<!-- OPENSPEC:END -->');
});
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major

Add test coverage for root AGENTS.md deletion and update scenario.

The test correctly validates the new .clinerules/AGENTS.md path and content. However, two important scenarios are missing:

  1. Root AGENTS.md deletion: Per the PR objectives, root AGENTS.md should be deleted when Cline is selected to avoid duplication. Add a test to verify this cleanup behavior.

  2. Updating existing .clinerules/AGENTS.md: Other tools have "update existing" tests (lines 121, 450, 1048). The removed "update existing CLINE.md" test should be replaced with one that validates updating .clinerules/AGENTS.md with markers.

Example test structure for root AGENTS.md deletion:

it('should delete root AGENTS.md when Cline is selected', async () => {
  queueSelections('cline', DONE);
  
  // Pre-create root AGENTS.md
  const rootAgentsPath = path.join(testDir, 'AGENTS.md');
  await fs.writeFile(rootAgentsPath, '# Existing root AGENTS.md\n');
  
  await initCommand.execute(testDir);
  
  // Verify root AGENTS.md is deleted
  expect(await fileExists(rootAgentsPath)).toBe(false);
  
  // Verify .clinerules/AGENTS.md exists
  const clineAgentsPath = path.join(testDir, '.clinerules', 'AGENTS.md');
  expect(await fileExists(clineAgentsPath)).toBe(true);
});

Example test structure for updating existing .clinerules/AGENTS.md:

it('should update existing .clinerules/AGENTS.md with markers', async () => {
  queueSelections('cline', DONE);
  
  const clineAgentsPath = path.join(testDir, '.clinerules', 'AGENTS.md');
  await fs.mkdir(path.dirname(clineAgentsPath), { recursive: true });
  const existingContent = '# My Cline Instructions\nCustom instructions here';
  await fs.writeFile(clineAgentsPath, existingContent);
  
  await initCommand.execute(testDir);
  
  const updatedContent = await fs.readFile(clineAgentsPath, 'utf-8');
  expect(updatedContent).toContain('<!-- OPENSPEC:START -->');
  expect(updatedContent).toContain('OpenSpec Instructions');
  expect(updatedContent).toContain('<!-- OPENSPEC:END -->');
  expect(updatedContent).toContain('Custom instructions here');
});
🤖 Prompt for AI Agents
In test/core/init.test.ts around lines 139 to 152, add two tests: one that
pre-creates a root AGENTS.md, runs init with 'cline' selected, then asserts the
root AGENTS.md was deleted and .clinerules/AGENTS.md exists; and another that
pre-creates .clinerules/AGENTS.md with custom content, runs init with 'cline',
then asserts the file still contains the custom content plus the OPENSPEC
markers and generated OpenSpec instructions (i.e., verify update behavior).
Ensure directories are created as needed and use existing helpers like
queueSelections, initCommand.execute, fileExists and fs.readFile to perform
assertions.


it('should update existing CLINE.md with markers', async () => {
queueSelections('cline', DONE);

const clinePath = path.join(testDir, 'CLINE.md');
const existingContent =
'# My Cline Rules\nCustom Cline instructions here';
await fs.writeFile(clinePath, existingContent);

await initCommand.execute(testDir);

const updatedContent = await fs.readFile(clinePath, 'utf-8');
expect(updatedContent).toContain('<!-- OPENSPEC:START -->');
expect(updatedContent).toContain("@/openspec/AGENTS.md");
expect(updatedContent).toContain('openspec update');
expect(updatedContent).toContain('<!-- OPENSPEC:END -->');
expect(updatedContent).toContain('Custom Cline instructions here');
});

it('should create Windsurf workflows when Windsurf is selected', async () => {
queueSelections('windsurf', DONE);
Expand Down
Loading