feat(exitcode): add semantic exit codes for AI-native CLIs#63
Merged
Conversation
Define fine-grained exit code constants grouped by category: - 0: success - 1–9: runtime errors (report to human) - 10–19: input errors (agent can self-correct and retry) - 20–29: config/env errors (fix environment, then retry) Include Category() and IsRetryable() helpers for agent decision trees.
Cover all constants, full range boundaries, edge cases (negative, out-of-range codes), and IsRetryable. 100% coverage.
|
hi @leodido While I understand the need, I'm a bit surprised by the error code you chose. Do you know exit code are somehow normalized and only some ranges are available ? I would like to suggest you to take a look at this project that tried to define something close to what you did, but took into account the existing exit code ranges https://github.com/square/exit?tab=readme-ov-file#reserved-codes-and-prior-art |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
structcli/exitcodesubpackage with fine-grained exit code constants for AI-native CLIsCategory()andIsRetryable()helpersExit code ranges
okruntimeinputconfigInput errors (10–19):
MissingRequiredFlagInvalidFlagValueUnknownFlagValidationFailedUnknownCommandInvalidFlagEnumConfig/environment errors (20–29):
ConfigParseErrorConfigUnknownKeyConfigInvalidValueConfigNotFoundEnvInvalidValueEnvMissingRequiredRuntime errors (1–9):
OKErrorPermissionDeniedTimeoutInterruptedWhy
This is the foundation for Phase 2a (structured error output).
HandleErrorwill return these codes and include them in JSON error output, enabling agents to branch on exit codes without parsing text.Test plan
go test ./exitcode/... -cover— 100% coverageIsRetryablecorrect for all codesgo vet ./exitcode/...— cleango test ./...— no regressions (pre-existing flakyTestMemoryCleanupunrelated)