Purpose: Template Method pattern for AI coding tool adapters
Last Updated: 2026-02-04
Template Method: BaseAdapter defines algorithm structure, subclasses implement tool-specific details.
export abstract class BaseAdapter {
abstract name: string
abstract displayName: string
// Must implement
abstract toOAC(source: string): Promise<OpenAgent>
abstract fromOAC(agent: OpenAgent): Promise<ConversionResult>
abstract getConfigPath(): string
abstract getCapabilities(): ToolCapabilities
abstract validateConversion(agent: OpenAgent): string[]
// Shared utilities
supportsFeature(feature: keyof ToolCapabilities): boolean
warn(message: string): void
createSuccessResult(configs, warnings): ConversionResult
safeParseJSON(content, filename): unknown | null
}
export class ClaudeAdapter extends BaseAdapter {
name = 'claude'
displayName = 'Claude Code'
async toOAC(source: string): Promise<OpenAgent> {
const config = this.safeParseJSON(source, 'config.json')
return {
frontmatter: {
name: config.name,
mode: config.mode || 'primary',
model: this.mapModel(config.model),
tools: config.tools,
skills: config.skills?.map(s => ({ name: s }))
},
systemPrompt: config.systemPrompt || ''
}
}
async fromOAC(agent: OpenAgent): Promise<ConversionResult> {
const warnings: string[] = []
// Warn on unsupported features
if (agent.frontmatter.temperature) {
warnings.push(this.unsupportedFeatureWarning('temperature'))
}
const config = {
name: agent.frontmatter.name,
model: agent.frontmatter.model,
systemPrompt: agent.systemPrompt,
tools: agent.frontmatter.tools
}
return this.createSuccessResult([
{ fileName: '.claude/config.json', content: JSON.stringify(config) }
], warnings)
}
getConfigPath() { return '.claude/' }
getCapabilities(): ToolCapabilities {
return {
supportsMultipleAgents: true,
supportsSkills: true,
supportsHooks: true,
supportsTemperature: false
}
}
validateConversion(agent: OpenAgent): string[] {
return agent.frontmatter.name ? [] : ['Agent name required']
}
}
Parse tool format → OpenAgent object
Steps: Parse source → Map fields → Validate with Zod → Return
Convert OpenAgent → tool format
Steps: Validate → Map fields → Detect unsupported features → Generate warnings → Create files
Declare supported features
{
supportsMultipleAgents: boolean
supportsSkills: boolean
supportsHooks: boolean
supportsGranularPermissions: boolean
supportsTemperature: boolean
}
// Safe parsing
const config = this.safeParseJSON(content, 'config.json')
// Feature checks
if (this.supportsFeature('supportsTemperature')) {
config.temperature = agent.frontmatter.temperature
}
// Warnings
if (!this.supportsFeature('supportsHooks')) {
warnings.push(this.unsupportedFeatureWarning('hooks'))
}
// Results
return this.createSuccessResult([{ fileName: 'config.json', content }], warnings)
describe('ClaudeAdapter', () => {
it('converts OAC to Claude', async () => {
const agent: OpenAgent = { /* ... */ }
const result = await adapter.fromOAC(agent)
expect(result.success).toBe(true)
expect(result.configs[0].fileName).toBe('.claude/config.json')
})
it('warns on unsupported temperature', async () => {
const agent: OpenAgent = { frontmatter: { temperature: 0.7 } }
const result = await adapter.fromOAC(agent)
expect(result.warnings).toContainEqual(
expect.stringContaining('temperature')
)
})
})
packages/compatibility-layer/src/adapters/BaseAdapter.tsClaudeAdapter.ts, CursorAdapter.ts, WindsurfAdapter.ts