* Ask the model for a decomposition strategy when a task keeps failing. * MarrowScript Rank 5: LLM-based replacement for pickDecomposeStrategy(). * Cached 5m. Returns null on failure so callers fall back to governor's regex. * * @param {string} task - User's original task description * @
(task, errors, fileContext)
| 313 | * @returns {Promise<{strategy:string,reason:string,instruction:string}|null>} |
| 314 | */ |
| 315 | async function decomposeTask(task, errors, fileContext) { |
| 316 | const prompts = _getPrompts(); |
| 317 | if (!prompts) return null; |
| 318 | try { |
| 319 | const traceId = require('crypto').randomUUID(); |
| 320 | const result = await prompts.callPrompt('decompose_task', { |
| 321 | task: String(task), |
| 322 | errors: String(errors), |
| 323 | file_context: String(fileContext), |
| 324 | }, { trace_id: traceId }); |
| 325 | const clean = String(result).trim().replace(/^```[a-z]*\n?/, '').replace(/\n?```$/, ''); |
| 326 | const parsed = JSON.parse(clean); |
| 327 | if (!parsed || typeof parsed !== 'object') return null; |
| 328 | const validStrategies = ['split_file', 'one_error_at_a_time', 'rewrite_section', 'extract_function']; |
| 329 | return { |
| 330 | strategy: validStrategies.includes(parsed.strategy) ? parsed.strategy : 'rewrite_section', |
| 331 | reason: String(parsed.reason || '').slice(0, 300), |
| 332 | instruction: String(parsed.instruction || '').slice(0, 600), |
| 333 | }; |
| 334 | } catch { |
| 335 | return null; |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | // ─── Feature Rank 7: semanticMerge ─────────────────────────────────────────── |
| 340 |
no test coverage detected