feat: add kiro profile

This commit is contained in:
Ralph Khreish
2025-07-18 00:03:09 +03:00
parent 4639eee097
commit f17f01fddf
8 changed files with 474 additions and 1 deletions

View File

@@ -0,0 +1,13 @@
---
"task-master-ai": minor
---
feat: Add Kiro editor rule profile with comprehensive rule set and MCP config
- Add Kiro IDE integration leveraging base profile's default file mapping system
- Generate complete rule set: `kiro_rules.md`, `dev_workflow.md`, `self_improve.md`, `taskmaster.md`
- Support for `.kiro/steering/` directory structure for all rule files with `.md` extension
- Custom MCP configuration in `.kiro/settings/mcp.json` with `mcpServers` format
- Enhanced MCP format with inclusion patterns using `fileMatchPattern: "**/*"`
- Minimal lifecycle function for MCP config transformation and directory setup
- Comprehensive test coverage for Kiro profile functionality

View File

@@ -1,5 +1,5 @@
/**
* @typedef {'amp' | 'claude' | 'cline' | 'codex' | 'cursor' | 'gemini' | 'opencode' | 'roo' | 'trae' | 'windsurf' | 'vscode' | 'zed'} RulesProfile
* @typedef {'amp' | 'claude' | 'cline' | 'codex' | 'cursor' | 'gemini' | 'kiro' | 'opencode' | 'roo' | 'trae' | 'windsurf' | 'vscode' | 'zed'} RulesProfile
*/
/**
@@ -16,6 +16,7 @@
* - codex: Codex integration
* - cursor: Cursor IDE rules
* - gemini: Gemini integration
* - kiro: Kiro IDE rules
* - opencode: OpenCode integration
* - roo: Roo Code IDE rules
* - trae: Trae IDE rules
@@ -35,6 +36,7 @@ export const RULE_PROFILES = [
'codex',
'cursor',
'gemini',
'kiro',
'opencode',
'roo',
'trae',

View File

@@ -5,6 +5,7 @@ export { clineProfile } from './cline.js';
export { codexProfile } from './codex.js';
export { cursorProfile } from './cursor.js';
export { geminiProfile } from './gemini.js';
export { kiroProfile } from './kiro.js';
export { opencodeProfile } from './opencode.js';
export { rooProfile } from './roo.js';
export { traeProfile } from './trae.js';

95
src/profiles/kiro.js Normal file
View File

@@ -0,0 +1,95 @@
// Kiro profile for rule-transformer
import path from 'path';
import fs from 'fs';
import { createProfile } from './base-profile.js';
// Minimal lifecycle function to handle MCP config transformation
function onPostConvertRulesProfile(targetDir, assetsDir) {
// Move MCP config from .kiro/mcp.json to .kiro/settings/mcp.json and add inclusion patterns
const baseMcpConfigPath = path.join(targetDir, '.kiro', 'mcp.json');
const finalMcpConfigPath = path.join(
targetDir,
'.kiro',
'settings',
'mcp.json'
);
if (!fs.existsSync(baseMcpConfigPath)) {
return; // No MCP config to transform
}
try {
// Create settings directory
const settingsDir = path.join(targetDir, '.kiro', 'settings');
if (!fs.existsSync(settingsDir)) {
fs.mkdirSync(settingsDir, { recursive: true });
}
// Read and transform the MCP config
const mcpConfigContent = fs.readFileSync(baseMcpConfigPath, 'utf8');
const mcpConfig = JSON.parse(mcpConfigContent);
// Add inclusion patterns to each server if they don't exist
if (mcpConfig.mcpServers) {
for (const [serverName, serverConfig] of Object.entries(
mcpConfig.mcpServers
)) {
if (!serverConfig.inclusion) {
serverConfig.inclusion = {
fileMatchPattern: '**/*'
};
}
}
}
// Write to final location and remove original
fs.writeFileSync(
finalMcpConfigPath,
JSON.stringify(mcpConfig, null, '\t') + '\n'
);
fs.rmSync(baseMcpConfigPath, { force: true });
} catch (error) {
// Silently fail - not critical
}
}
// Create and export kiro profile using the base factory
export const kiroProfile = createProfile({
name: 'kiro',
displayName: 'Kiro',
url: 'kiro.dev',
docsUrl: 'kiro.dev/docs',
profileDir: '.kiro',
rulesDir: '.kiro/steering', // Kiro rules location (full path)
mcpConfig: true,
mcpConfigName: 'mcp.json',
includeDefaultRules: true, // Include default rules to get all the standard files
targetExtension: '.md',
fileMap: {
// Override specific mappings - the base profile will create:
// 'rules/cursor_rules.mdc': 'kiro_rules.md'
// 'rules/dev_workflow.mdc': 'dev_workflow.md'
// 'rules/self_improve.mdc': 'self_improve.md'
// 'rules/taskmaster.mdc': 'taskmaster.md'
// We can add additional custom mappings here if needed
},
customReplacements: [
// Core Kiro directory structure changes
{ from: /\.cursor\/rules/g, to: '.kiro/steering' },
{ from: /\.cursor\/mcp\.json/g, to: '.kiro/settings/mcp.json' },
// Fix any remaining kiro/rules references that might be created during transformation
{ from: /\.kiro\/rules/g, to: '.kiro/steering' },
// Essential markdown link transformations for Kiro structure
{
from: /\[(.+?)\]\(mdc:\.cursor\/rules\/(.+?)\.mdc\)/g,
to: '[$1](.kiro/steering/$2.md)'
},
// Kiro specific terminology
{ from: /rules directory/g, to: 'steering directory' },
{ from: /cursor rules/gi, to: 'Kiro steering files' }
],
onPostConvert: onPostConvertRulesProfile
});

View File

@@ -0,0 +1,135 @@
import { jest } from '@jest/globals';
import fs from 'fs';
import path from 'path';
import os from 'os';
// Mock external modules
jest.mock('child_process', () => ({
execSync: jest.fn()
}));
// Mock console methods
jest.mock('console', () => ({
log: jest.fn(),
info: jest.fn(),
warn: jest.fn(),
error: jest.fn(),
clear: jest.fn()
}));
describe('Kiro Integration', () => {
let tempDir;
beforeEach(() => {
jest.clearAllMocks();
// Create a temporary directory for testing
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'task-master-test-'));
// Spy on fs methods
jest.spyOn(fs, 'writeFileSync').mockImplementation(() => {});
jest.spyOn(fs, 'readFileSync').mockImplementation((filePath) => {
if (filePath.toString().includes('mcp.json')) {
return JSON.stringify({ mcpServers: {} }, null, 2);
}
return '{}';
});
jest.spyOn(fs, 'existsSync').mockImplementation(() => false);
jest.spyOn(fs, 'mkdirSync').mockImplementation(() => {});
});
afterEach(() => {
// Clean up the temporary directory
try {
fs.rmSync(tempDir, { recursive: true, force: true });
} catch (err) {
console.error(`Error cleaning up: ${err.message}`);
}
});
// Test function that simulates the createProjectStructure behavior for Kiro files
function mockCreateKiroStructure() {
// Create main .kiro directory
fs.mkdirSync(path.join(tempDir, '.kiro'), { recursive: true });
// Create settings directory
fs.mkdirSync(path.join(tempDir, '.kiro', 'settings'), { recursive: true });
// Create steering directory
fs.mkdirSync(path.join(tempDir, '.kiro', 'steering'), { recursive: true });
// Create MCP config file (mcp.json in settings)
fs.writeFileSync(
path.join(tempDir, '.kiro', 'settings', 'mcp.json'),
JSON.stringify({ mcpServers: {} }, null, 2)
);
// Create kiro rule files in steering directory
fs.writeFileSync(
path.join(tempDir, '.kiro', 'steering', 'kiro_rules.md'),
'# Kiro Rules\n\nKiro-specific rules and instructions.'
);
fs.writeFileSync(
path.join(tempDir, '.kiro', 'steering', 'dev_workflow.md'),
'# Development Workflow\n\nDevelopment workflow instructions.'
);
fs.writeFileSync(
path.join(tempDir, '.kiro', 'steering', 'self_improve.md'),
'# Self Improvement\n\nSelf improvement guidelines.'
);
fs.writeFileSync(
path.join(tempDir, '.kiro', 'steering', 'taskmaster.md'),
'# Task Master\n\nTask Master integration instructions.'
);
}
test('creates all required .kiro directories', () => {
// Act
mockCreateKiroStructure();
// Assert
expect(fs.mkdirSync).toHaveBeenCalledWith(path.join(tempDir, '.kiro'), {
recursive: true
});
expect(fs.mkdirSync).toHaveBeenCalledWith(path.join(tempDir, '.kiro', 'settings'), {
recursive: true
});
expect(fs.mkdirSync).toHaveBeenCalledWith(path.join(tempDir, '.kiro', 'steering'), {
recursive: true
});
});
test('creates Kiro mcp.json with mcpServers format', () => {
// Act
mockCreateKiroStructure();
// Assert
expect(fs.writeFileSync).toHaveBeenCalledWith(
path.join(tempDir, '.kiro', 'settings', 'mcp.json'),
JSON.stringify({ mcpServers: {} }, null, 2)
);
});
test('creates rule files in steering directory', () => {
// Act
mockCreateKiroStructure();
// Assert
expect(fs.writeFileSync).toHaveBeenCalledWith(
path.join(tempDir, '.kiro', 'steering', 'kiro_rules.md'),
'# Kiro Rules\n\nKiro-specific rules and instructions.'
);
expect(fs.writeFileSync).toHaveBeenCalledWith(
path.join(tempDir, '.kiro', 'steering', 'dev_workflow.md'),
'# Development Workflow\n\nDevelopment workflow instructions.'
);
expect(fs.writeFileSync).toHaveBeenCalledWith(
path.join(tempDir, '.kiro', 'steering', 'self_improve.md'),
'# Self Improvement\n\nSelf improvement guidelines.'
);
expect(fs.writeFileSync).toHaveBeenCalledWith(
path.join(tempDir, '.kiro', 'steering', 'taskmaster.md'),
'# Task Master\n\nTask Master integration instructions.'
);
});
});

View File

@@ -41,6 +41,12 @@ describe('MCP Configuration Validation', () => {
expectedConfigName: 'settings.json',
expectedPath: '.gemini/settings.json'
},
kiro: {
shouldHaveMcp: true,
expectedDir: '.kiro',
expectedConfigName: 'mcp.json',
expectedPath: '.kiro/mcp.json'
},
opencode: {
shouldHaveMcp: true,
expectedDir: '.',

View File

@@ -0,0 +1,215 @@
import { jest } from '@jest/globals';
// Mock fs module before importing anything that uses it
jest.mock('fs', () => ({
readFileSync: jest.fn(),
writeFileSync: jest.fn(),
existsSync: jest.fn(),
mkdirSync: jest.fn()
}));
// Import modules after mocking
import fs from 'fs';
import { convertRuleToProfileRule } from '../../../src/utils/rule-transformer.js';
import { kiroProfile } from '../../../src/profiles/kiro.js';
describe('Kiro Rule Transformer', () => {
// Set up spies on the mocked modules
const mockReadFileSync = jest.spyOn(fs, 'readFileSync');
const mockWriteFileSync = jest.spyOn(fs, 'writeFileSync');
const mockExistsSync = jest.spyOn(fs, 'existsSync');
const mockMkdirSync = jest.spyOn(fs, 'mkdirSync');
const mockConsoleError = jest
.spyOn(console, 'error')
.mockImplementation(() => {});
beforeEach(() => {
jest.clearAllMocks();
// Setup default mocks
mockReadFileSync.mockReturnValue('');
mockWriteFileSync.mockImplementation(() => {});
mockExistsSync.mockReturnValue(true);
mockMkdirSync.mockImplementation(() => {});
});
afterAll(() => {
jest.restoreAllMocks();
});
it('should correctly convert basic terms', () => {
const testContent = `---
description: Test Cursor rule for basic terms
globs: **/*
alwaysApply: true
---
This is a Cursor rule that references cursor.so and uses the word Cursor multiple times.
Also has references to .mdc files.`;
// Mock file read to return our test content
mockReadFileSync.mockReturnValue(testContent);
// Mock file system operations
mockExistsSync.mockReturnValue(true);
// Call the function
const result = convertRuleToProfileRule(
'test-source.mdc',
'test-target.md',
kiroProfile
);
// Verify the result
expect(result).toBe(true);
expect(mockWriteFileSync).toHaveBeenCalledTimes(1);
// Get the transformed content
const transformedContent = mockWriteFileSync.mock.calls[0][1];
// Verify Cursor -> Kiro transformations
expect(transformedContent).toContain('kiro.dev');
expect(transformedContent).toContain('Kiro');
expect(transformedContent).not.toContain('cursor.so');
expect(transformedContent).not.toContain('Cursor');
expect(transformedContent).toContain('.md');
expect(transformedContent).not.toContain('.mdc');
});
it('should handle URL transformations', () => {
const testContent = `Visit https://cursor.so/docs for more information.
Also check out cursor.so and www.cursor.so for updates.`;
mockReadFileSync.mockReturnValue(testContent);
mockExistsSync.mockReturnValue(true);
const result = convertRuleToProfileRule(
'test-source.mdc',
'test-target.md',
kiroProfile
);
expect(result).toBe(true);
const transformedContent = mockWriteFileSync.mock.calls[0][1];
// Verify URL transformations
expect(transformedContent).toContain('https://kiro.dev');
expect(transformedContent).toContain('kiro.dev');
expect(transformedContent).not.toContain('cursor.so');
});
it('should handle file extension transformations', () => {
const testContent = `This rule references file.mdc and another.mdc file.
Use the .mdc extension for all rule files.`;
mockReadFileSync.mockReturnValue(testContent);
mockExistsSync.mockReturnValue(true);
const result = convertRuleToProfileRule(
'test-source.mdc',
'test-target.md',
kiroProfile
);
expect(result).toBe(true);
const transformedContent = mockWriteFileSync.mock.calls[0][1];
// Verify file extension transformations
expect(transformedContent).toContain('file.md');
expect(transformedContent).toContain('another.md');
expect(transformedContent).toContain('.md extension');
expect(transformedContent).not.toContain('.mdc');
});
it('should handle case variations', () => {
const testContent = `CURSOR, Cursor, cursor should all be transformed.`;
mockReadFileSync.mockReturnValue(testContent);
mockExistsSync.mockReturnValue(true);
const result = convertRuleToProfileRule(
'test-source.mdc',
'test-target.md',
kiroProfile
);
expect(result).toBe(true);
const transformedContent = mockWriteFileSync.mock.calls[0][1];
// Verify case transformations
// Due to regex order, the case-insensitive rule runs first:
// CURSOR -> Kiro (because it starts with 'C'), Cursor -> Kiro, cursor -> kiro
expect(transformedContent).toContain('Kiro');
expect(transformedContent).toContain('kiro');
expect(transformedContent).not.toContain('CURSOR');
expect(transformedContent).not.toContain('Cursor');
expect(transformedContent).not.toContain('cursor');
});
it('should create target directory if it does not exist', () => {
const testContent = 'Test content';
mockReadFileSync.mockReturnValue(testContent);
mockExistsSync.mockReturnValue(false);
const result = convertRuleToProfileRule(
'test-source.mdc',
'nested/path/test-target.md',
kiroProfile
);
expect(result).toBe(true);
expect(mockMkdirSync).toHaveBeenCalledWith('nested/path', {
recursive: true
});
});
it('should handle file system errors gracefully', () => {
mockReadFileSync.mockImplementation(() => {
throw new Error('File not found');
});
const result = convertRuleToProfileRule(
'test-source.mdc',
'test-target.md',
kiroProfile
);
expect(result).toBe(false);
expect(mockConsoleError).toHaveBeenCalledWith(
'Error converting rule file: File not found'
);
});
it('should handle write errors gracefully', () => {
mockReadFileSync.mockReturnValue('Test content');
mockWriteFileSync.mockImplementation(() => {
throw new Error('Write permission denied');
});
const result = convertRuleToProfileRule(
'test-source.mdc',
'test-target.md',
kiroProfile
);
expect(result).toBe(false);
expect(mockConsoleError).toHaveBeenCalledWith(
'Error converting rule file: Write permission denied'
);
});
it('should verify profile configuration', () => {
expect(kiroProfile.profileName).toBe('kiro');
expect(kiroProfile.displayName).toBe('Kiro');
expect(kiroProfile.profileDir).toBe('.kiro');
expect(kiroProfile.mcpConfig).toBe(true);
expect(kiroProfile.mcpConfigName).toBe('mcp.json');
expect(kiroProfile.mcpConfigPath).toBe('.kiro/mcp.json');
expect(kiroProfile.includeDefaultRules).toBe(true);
expect(kiroProfile.fileMap).toEqual({
'rules/cursor_rules.mdc': 'kiro_rules.md',
'rules/dev_workflow.mdc': 'dev_workflow.md',
'rules/self_improve.mdc': 'self_improve.md',
'rules/taskmaster.mdc': 'taskmaster.md'
});
});
});

View File

@@ -19,6 +19,7 @@ describe('Rule Transformer - General', () => {
'codex',
'cursor',
'gemini',
'kiro',
'opencode',
'roo',
'trae',
@@ -212,6 +213,11 @@ describe('Rule Transformer - General', () => {
mcpConfigName: 'settings.json',
expectedPath: '.gemini/settings.json'
},
kiro: {
mcpConfig: true,
mcpConfigName: 'mcp.json',
expectedPath: '.kiro/mcp.json'
},
opencode: {
mcpConfig: true,
mcpConfigName: 'opencode.json',