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
22 changes: 19 additions & 3 deletions src/lib/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ const TOOL_MAPPINGS: ReadonlyArray<readonly [RegExp, string]> = [
// Semantic tool renames (different names in OC)
// Task tool explicit reference
[/\bTask\s+tool\b/gi, 'delegate_task tool'],
// Task followed by agent name + colon: Task agent-name: "prompt"
[/\bTask\s+([\w-]+)\s*:/g, 'delegate_task $1:'],
// Task followed by agent name + parens: Task agent-name(args)
[/\bTask\s+([\w-]+)\s*\(/g, 'delegate_task $1('],
// Task with immediate parens: Task(args) or Task (args)
Expand All @@ -49,8 +51,8 @@ const TOOL_MAPPINGS: ReadonlyArray<readonly [RegExp, string]> = [
[/\bGrep\b(?=\s+tool|\s+to\s+|\()/g, 'grep'],
[/\bGlob\b(?=\s+tool|\s+to\s+|\()/g, 'glob'],
[/\bWebFetch\b/g, 'webfetch'],
// Skill tool (context-aware to avoid false positives)
[/\bSkill\b(?=\s+tool)/g, 'skill'],
// Skill tool invocation: Skill("name") or Skill tool reference
[/\bSkill\b(?=\s+tool|\s*\()/g, 'skill'],
] as const

/**
Expand Down Expand Up @@ -109,8 +111,18 @@ function inferTemperature(name: string, description?: string): number {
return 0.3
}

const CODE_BLOCK_PATTERN = /```[\s\S]*?```|`[^`\n]+`/g

function transformBody(body: string): string {
let result = body
const codeBlocks: string[] = []
let placeholderIndex = 0

const withPlaceholders = body.replace(CODE_BLOCK_PATTERN, (match) => {
codeBlocks.push(match)
return `__CODE_BLOCK_${placeholderIndex++}__`
})

let result = withPlaceholders

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

for (let i = 0; i < codeBlocks.length; i++) {
result = result.replace(`__CODE_BLOCK_${i}__`, codeBlocks[i])
}

return result
}

Expand Down
Loading