UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

137 lines (136 loc) • 5.47 kB
import { _ as resolvePrimaryStringValue, c as normalizeOptionalLowercaseString } from "./string-coerce-CCIiB4H7.mjs"; import { l as isRecord } from "./record-coerce-CVPuDqcc.mjs"; import { t as hasErrnoCode } from "./errno-DFcoqIT9.mjs"; import { p as shortenHomePath } from "./utils-C8YECn2Q.mjs"; import { o as resolveExecutablePath } from "./executable-path-D8oWZRS5.mjs"; import { t as formatCliCommand } from "./command-format-CqdwUgPk.mjs"; import { i as listAgentIds, u as tryResolveDefaultAgentId } from "./agent-roster-t1ooUdXp.mjs"; import { f as resolveAgentWorkspaceDir } from "./agent-scope-config-DmXgFGKP.mjs"; import { t as loadBundledPluginPublicArtifactModuleFromCandidatesSync } from "./public-surface-loader-DENdCm5a.mjs"; import { o as resolveCliBackendConfig } from "./cli-backends-B8PrIwPC.mjs"; import { n as resolveModelAgentRuntimeMetadata } from "./agent-runtime-metadata-DfI1F8oJ.mjs"; import { t as note } from "./note-CnLgHvug.mjs"; import { t as resolveClaudeCliProjectDirForWorkspace } from "./claude-cli-project-dir-DwJdMUca.mjs"; import fs from "node:fs"; import { spawnSync } from "node:child_process"; //#region src/commands/doctor-claude-cli.ts const CLAUDE_CLI_PROVIDER = "claude-cli"; function readClaudeCliAuthentication(e, t) { const n = spawnSync(e, [ "auth", "status", "--json" ], { encoding: "utf8", env: t, maxBuffer: 65536, timeout: 3e3, windowsHide: true }); if (n.error || n.status === null) return; try { const e = JSON.parse(n.stdout); if (!isRecord(e) || typeof e.loggedIn !== "boolean") return; return e.loggedIn ? n.status === 0 ? true : void 0 : false; } catch { return; } } function usesClaudeCliModelSelection(e) { return [resolvePrimaryStringValue(e.agents?.defaults?.model), ...Object.keys(e.agents?.defaults?.models ?? {})].some((e) => normalizeOptionalLowercaseString(e)?.startsWith(`${CLAUDE_CLI_PROVIDER}/`)); } function probeDirectoryHealth(e) { try { if (!fs.statSync(e).isDirectory()) return "not_directory"; } catch (e) { return hasErrnoCode(e, "ENOENT") ? "missing" : "unreadable"; } for (const t of [fs.constants.R_OK, fs.constants.W_OK]) try { fs.accessSync(e, t); } catch { return t === fs.constants.R_OK ? "unreadable" : "readonly"; } return "present"; } function resolveClaudeCliAgentIds(e) { const t = listAgentIds(e).filter((t) => resolveModelAgentRuntimeMetadata({ cfg: e, agentId: t }).id === CLAUDE_CLI_PROVIDER); if (t.length > 0) return t; if (usesClaudeCliModelSelection(e)) { const t = tryResolveDefaultAgentId(e); return t ? [t] : []; } return []; } function noteClaudeCliHealth(e, t) { const n = process.env; const r = t?.workspaceDir; const i = resolveClaudeCliAgentIds(e); const a = tryResolveDefaultAgentId(e); const o = i.map((t) => { const o = r && i.length === 1 && t === a ? r : resolveAgentWorkspaceDir(e, t, n); const s = resolveClaudeCliProjectDirForWorkspace({ workspaceDir: o }); return { agentId: t, directories: [[ o, probeDirectoryHealth(o), "workspace" ], [ s, probeDirectoryHealth(s), "Claude project dir" ]] }; }); if (o.length === 0) return; const s = resolveCliBackendConfig(CLAUDE_CLI_PROVIDER, e); const c = s?.config.command ?? "claude"; const l = resolveExecutablePath(c, { env: n }); const u = c === "claude" ? loadBundledPluginPublicArtifactModuleFromCandidatesSync({ dirName: "anthropic", artifactCandidates: ["cli-auth-api.js"] }) : null; const d = u ? u.resolveClaudeTerminalExecutable(n, { pathStrategy: "direct" })?.executable : l; const f = { ...n }; for (const e of s?.config.clearEnv ?? []) delete f[e]; const p = d ? readClaudeCliAuthentication(d, f) : void 0; const m = tryResolveDefaultAgentId(e); const h = o.length > 1 || o.some((e) => e.agentId !== m); const g = []; const _ = []; if (!d) { g.push(`- Binary: command "${c}" was not found on PATH.`); _.push("- Fix: install Claude CLI on PATH for the gateway user; custom executable paths belong in a CLI backend plugin registration."); } else if (!l) g.push(`- Binary: found at ${shortenHomePath(d)} (not on service PATH).`); if (d && p === void 0) { g.push("- Claude auth: status check unavailable."); _.push(`- Fix: run ${formatCliCommand("claude auth status --json")} to check Claude CLI authentication.`); } else if (d && !p) { g.push("- Claude auth: not logged in."); _.push(`- Fix: run ${formatCliCommand("claude auth login")}.`); } for (const e of o) { const t = h ? e.agentId : void 0; for (const [n, r, i] of e.directories) { const e = i === "workspace"; const a = t ? `Agent ${t} ${i}` : e ? "Workspace" : i; const o = shortenHomePath(n); if (r === "present" || r === "missing") continue; const s = r === "not_directory" ? "exists but is not a directory." : `is not ${r === "unreadable" ? "readable" : "writable"} by this user.`; g.push(`- ${a}: ${o} ${s}`); if (e || r !== "readonly") { const n = t ? `agent ${t}'s ${i}` : `the ${i}`; const r = e ? "a readable, writable directory for the gateway user." : "readable, or remove the broken path and let Claude recreate it."; _.push(`- Fix: make ${n} ${r}`); } } } if (g.length > 0 && o.length > 1) g.push(`- Agents using Claude CLI: ${o.map((e) => e.agentId).toSorted((e, t) => e.localeCompare(t)).join(", ")}.`); if (g.length === 0) return; (t?.noteFn ?? note)([...g, ..._].join("\n"), "Claude CLI"); } //#endregion export { noteClaudeCliHealth };