{"record":{"id":"5b309d81cdeec5f0","repo":"paperclipai/paperclip","slug":"agent-selection-failed","errorCode":null,"errorMessage":"Agent selection failed","messagePattern":"Agent selection failed","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"cli/src/commands/client/connect.ts","lineNumber":230,"sourceCode":"  if (!selected) return null;\n  return companies.find((company) => company.id === selected) ?? null;\n}\n\nasync function chooseAgent(agents: Agent[], preferredAgentId: string | undefined): Promise<Agent> {\n  const selected = await p.select({\n    message: \"Agent\",\n    initialValue: preferredAgentId && agents.some((agent) => agent.id === preferredAgentId)\n      ? preferredAgentId\n      : agents[0]?.id,\n    options: agents.map((agent) => ({\n      value: agent.id,\n      label: agent.name,\n      hint: agent.role,\n    })),\n  });\n  assertNotCancelled(selected);\n  const agent = agents.find((item) => item.id === selected);\n  if (!agent) throw new Error(\"Agent selection failed\");\n  return agent;\n}\n\nfunction buildExports(input: {\n  apiBase: string;\n  companyId?: string;\n  agentId?: string;\n  envName: string;\n  token: string;\n}): string {\n  const escaped = (value: string) => value.replace(/'/g, \"'\\\"'\\\"'\");\n  return [\n    `export PAPERCLIP_API_URL='${escaped(input.apiBase)}'`,\n    input.companyId ? `export PAPERCLIP_COMPANY_ID='${escaped(input.companyId)}'` : null,\n    input.agentId ? `export PAPERCLIP_AGENT_ID='${escaped(input.agentId)}'` : null,\n    `export ${input.envName}='${escaped(input.token)}'`,\n  ].filter((line): line is string => Boolean(line)).join(\"\\n\");\n}","sourceCodeStart":212,"sourceCodeEnd":248,"githubUrl":"https://github.com/paperclipai/paperclip/blob/120ae5428fa29bee300bcf806491cd4d965fbb7c/cli/src/commands/client/connect.ts#L212-L248","documentation":"After the agent select prompt resolved, no agent in the list matched the selected id, so the wizard cannot continue with a concrete agent; a consistency guard on the selection result.","triggerScenarios":"Thrown at cli/src/commands/client/connect.ts:230 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Retry; if it persists, verify the company has agents and the server is reachable."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"120ae5428fa29bee300bcf806491cd4d965fbb7c","analyzedAt":"2026-08-18T22:49:45.177Z","contentChangedAt":"2026-08-18T22:49:45.177Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}