{"record":{"id":"010606796e0458e4","repo":"nexu-io/open-design","slug":"agentname-cli-error-message","errorCode":null,"errorMessage":"${agentName} CLI error: ${message}","messagePattern":"(.+?) CLI error: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/daemon/src/memory-llm.ts","lineNumber":941,"sourceCode":"  }\n  return '';\n}\n\nconst LOCAL_CLI_TIMEOUT_MS = 60_000;\n\nfunction extractJsonEventText(kind, raw, agentName) {\n  const events = [];\n  const handler = createJsonEventStreamHandler(kind, (event) => events.push(event));\n  handler.feed(raw);\n  handler.flush();\n\n  const errorEvent = events.find((event) => event?.type === 'error');\n  if (errorEvent) {\n    const message =\n      typeof errorEvent.message === 'string' && errorEvent.message.trim()\n        ? errorEvent.message.trim()\n        : 'unknown error';\n    throw new Error(`${agentName} CLI error: ${message}`);\n  }\n\n  return events\n    .filter((event) => event?.type === 'text_delta' && typeof event.delta === 'string')\n    .map((event) => event.delta)\n    .join('')\n    .trim();\n}\n\nasync function callLocalCli(provider, system, user, options) {\n  if (typeof options?.localCliRunner === 'function') {\n    return options.localCliRunner({\n      agentId: provider.agentId,\n      model: provider.model,\n      system,\n      user,\n      projectRoot: options?.projectRoot ?? null,\n      dataDir: options?.dataDir ?? null,","sourceCodeStart":923,"sourceCodeEnd":959,"githubUrl":"https://github.com/nexu-io/open-design/blob/5be4028344c2eb4c667c5a97bda8f750c5597ef7/apps/daemon/src/memory-llm.ts#L923-L959","documentation":"The JSON event stream from a local agent CLI (codex or opencode) contained an event with type: 'error'. The extractJsonEventText function parses the streamed NDJSON events and throws when it finds an error event, surfacing the event's message field.","triggerScenarios":"The agent CLI process encountered an internal error during memory extraction; the selected model is unavailable or misconfigured; authentication failure within the agent's own provider config; the agent CLI crashed or exited with an error event.","commonSituations":"Agent CLI version incompatibility with the daemon's event parser; model not configured for the agent in agentCliEnv; API key missing for the agent's underlying provider; agent crashed mid-extraction due to prompt issues.","solutions":["Read the error message surfaced from the agent CLI in the thrown error","Verify the agent CLI is properly authenticated (run the agent manually to test)","Confirm provider.model is available and configured for the agent","Run the agent CLI manually with the same prompt to reproduce the error","Update the agent CLI to the latest version"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const text = await callLocalCli(provider, system, user, options);\n} catch (err) {\n  if (err.message.includes('CLI error:')) {\n    // Agent CLI reported an error event — check agent config and auth\n    logger.error('Agent CLI error during memory extraction', { agentId: provider.agentId, error: err.message });\n    // Optionally fall back to an HTTP provider\n    throw err;\n  }\n  throw err;\n}","preventionTips":["Test the agent CLI manually with a simple prompt before relying on it for memory extraction","Keep agent CLI versions updated and compatible with the daemon's event parser","Ensure the agent's underlying provider API key is configured in agentCliEnv","Consider falling back to an HTTP-based LLM provider if agent CLI extraction is unreliable"],"tags":["agent-cli","llm","memory-extraction","json-event-stream"],"backgroundTag":null,"analyzedSha":"5be4028344c2eb4c667c5a97bda8f750c5597ef7","analyzedAt":"2026-08-12T12:03:58.812Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}