MCPcopy
hub / github.com/Doorman11991/smallcode / diagnoseError

Function diagnoseError

bin/features_adapter.js:279–301  ·  view source on GitHub ↗

* Analyze a bash command failure and return a structured hint. * MarrowScript Rank 4: replaces ad-hoc error string formatting. * Cached 5m. Falls back to null on model failure. * * @param {string} command - The command that failed * @param {string} stderr - Combined stdout+stderr output * @

(command, stderr, exitCode)

Source from the content-addressed store, hash-verified

277 * @returns {Promise<{type:string,file:string|null,line:number|null,suggestion:string}|null>}
278 */
279async function diagnoseError(command, stderr, exitCode) {
280 const prompts = _getPrompts();
281 if (!prompts) return null;
282 try {
283 const traceId = require('crypto').randomUUID();
284 const result = await prompts.callPrompt('error_diagnosis', {
285 command: String(command).slice(0, 500),
286 stderr: String(stderr).slice(0, 1500),
287 exit_code: String(exitCode),
288 }, { trace_id: traceId });
289 const clean = String(result).trim().replace(/^```[a-z]*\n?/, '').replace(/\n?```$/, '');
290 const parsed = JSON.parse(clean);
291 if (!parsed || typeof parsed !== 'object') return null;
292 return {
293 type: String(parsed.type || 'unknown'),
294 file: parsed.file || null,
295 line: typeof parsed.line === 'number' ? parsed.line : null,
296 suggestion: String(parsed.suggestion || '').slice(0, 200),
297 };
298 } catch {
299 return null;
300 }
301}
302
303// ─── Feature Rank 5: decomposeTask ───────────────────────────────────────────
304

Callers 1

executeToolFunction · 0.85

Calls 1

_getPromptsFunction · 0.85

Tested by

no test coverage detected