Files
agent-radar 2ed3415fb7
Publish Claude Code Binaries / Stage and publish binaries (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-arm64 (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build linux-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build windows-amd64 (push) Canceled after 0s
Sync Tutti Agent Skills / sync (push) Canceled after 0s
Windows Agent Adapters / Test Windows agent adapters (push) Canceled after 0s
Windows Daemon Adapters / Test Windows daemon adapters (push) Canceled after 0s
Publish Tutti App Runtime / Publish runtime catalog (push) Canceled after 0s
源码快照 @ 2026-09-01 (source-only, 剔除非源码素材)
2026-09-01 20:17:27 +08:00

57 lines
2.3 KiB
Go

package agentstatus
import "strings"
// CodexErrorCode is a structured classification of a Codex failure, surfaced to
// the renderer so the UI can show one human sentence plus one remediation
// action instead of a raw spawn stack or JSON payload.
type CodexErrorCode string
const (
// CodexErrCLIMissing: the codex CLI is not resolvable on PATH.
CodexErrCLIMissing CodexErrorCode = "CODEX_CLI_MISSING"
// CodexErrPlatformPkgIncomplete: the @openai/codex wrapper resolved but its
// platform-specific binary subpackage is missing (the field ENOENT).
CodexErrPlatformPkgIncomplete CodexErrorCode = "CODEX_PLATFORM_PKG_INCOMPLETE"
// CodexErrVersionTooOld: the installed codex is below MinSupportedCodexVersion
// or the server rejected the request as requiring a newer version.
CodexErrVersionTooOld CodexErrorCode = "CODEX_VERSION_TOO_OLD"
// CodexErrAuthRequired: codex is installed but not logged in.
CodexErrAuthRequired CodexErrorCode = "CODEX_AUTH_REQUIRED"
// CodexErrNetwork: an install or request failed for a network reason.
CodexErrNetwork CodexErrorCode = "CODEX_NETWORK"
// CodexErrRuntimeBug: app-server failed after the supported CLI and its
// package/native-binary evidence were verified.
CodexErrRuntimeBug CodexErrorCode = "CODEX_RUNTIME_BUG"
)
// classifyCodexRuntimeError maps a raw error/message string from spawning or
// requesting codex into a structured CodexErrorCode. ok is false when the
// message does not match any known pattern.
func classifyCodexRuntimeError(msg string) (CodexErrorCode, bool) {
lower := strings.ToLower(msg)
switch {
case strings.Contains(lower, "requires a newer version"):
return CodexErrVersionTooOld, true
case strings.Contains(lower, "enoent") && strings.Contains(lower, "@openai/codex-"):
return CodexErrPlatformPkgIncomplete, true
case strings.Contains(lower, "enoent"):
return CodexErrCLIMissing, true
case strings.Contains(lower, "not logged in") || strings.Contains(lower, "please run /login"):
return CodexErrAuthRequired, true
case codexErrorLooksLikeNetwork(lower):
return CodexErrNetwork, true
default:
return "", false
}
}
func codexErrorLooksLikeNetwork(lower string) bool {
for _, marker := range []string{"etimedout", "enotfound", "econnrefused", "econnreset", "network", "socket hang up", "getaddrinfo"} {
if strings.Contains(lower, marker) {
return true
}
}
return false
}