Skip to content

Commit 486d4bb

Browse files
authored
feat(converter): add edge case handling for Task patterns and code blocks (#39)
- Add Task colon pattern regex for `Task agent-name: "prompt"` syntax (used ~20+ times in CEP commands) - Add Skill invocation pattern for `Skill("name")` syntax - Preserve code blocks during transformation (tool references inside backticks are intentionally not converted) - Add comprehensive validation tests against real CEP content Validated against 17 real CEP files (8 skills, 5 commands, 4 agents). All 148 tests pass with 0 false positives detected. Closes edge cases: - Task with colon not converted (FIXED) - Skill(args) pattern not converted (FIXED) - Code block content transformed (FIXED - now preserved)
1 parent a410cf4 commit 486d4bb

2 files changed

Lines changed: 437 additions & 3 deletions

File tree

src/lib/converter.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ const TOOL_MAPPINGS: ReadonlyArray<readonly [RegExp, string]> = [
3232
// Semantic tool renames (different names in OC)
3333
// Task tool explicit reference
3434
[/\bTask\s+tool\b/gi, 'delegate_task tool'],
35+
// Task followed by agent name + colon: Task agent-name: "prompt"
36+
[/\bTask\s+([\w-]+)\s*:/g, 'delegate_task $1:'],
3537
// Task followed by agent name + parens: Task agent-name(args)
3638
[/\bTask\s+([\w-]+)\s*\(/g, 'delegate_task $1('],
3739
// Task with immediate parens: Task(args) or Task (args)
@@ -49,8 +51,8 @@ const TOOL_MAPPINGS: ReadonlyArray<readonly [RegExp, string]> = [
4951
[/\bGrep\b(?=\s+tool|\s+to\s+|\()/g, 'grep'],
5052
[/\bGlob\b(?=\s+tool|\s+to\s+|\()/g, 'glob'],
5153
[/\bWebFetch\b/g, 'webfetch'],
52-
// Skill tool (context-aware to avoid false positives)
53-
[/\bSkill\b(?=\s+tool)/g, 'skill'],
54+
// Skill tool invocation: Skill("name") or Skill tool reference
55+
[/\bSkill\b(?=\s+tool|\s*\()/g, 'skill'],
5456
] as const
5557

5658
/**
@@ -109,8 +111,18 @@ function inferTemperature(name: string, description?: string): number {
109111
return 0.3
110112
}
111113

114+
const CODE_BLOCK_PATTERN = /```[\s\S]*?```|`[^`\n]+`/g
115+
112116
function transformBody(body: string): string {
113-
let result = body
117+
const codeBlocks: string[] = []
118+
let placeholderIndex = 0
119+
120+
const withPlaceholders = body.replace(CODE_BLOCK_PATTERN, (match) => {
121+
codeBlocks.push(match)
122+
return `__CODE_BLOCK_${placeholderIndex++}__`
123+
})
124+
125+
let result = withPlaceholders
114126

115127
for (const [pattern, replacement] of TOOL_MAPPINGS) {
116128
result = result.replace(pattern, replacement)
@@ -120,6 +132,10 @@ function transformBody(body: string): string {
120132
result = result.replace(pattern, replacement)
121133
}
122134

135+
for (let i = 0; i < codeBlocks.length; i++) {
136+
result = result.replace(`__CODE_BLOCK_${i}__`, codeBlocks[i])
137+
}
138+
123139
return result
124140
}
125141

0 commit comments

Comments
 (0)