Problem
The CLI currently exits with generic exit code 1 for all failures. This makes it hard to programmatically distinguish between different failure types in CI/CD pipelines or scripts that wrap agentcore commands.
Proposed Solution
Define and export named exit codes in src/cli/errors.ts (or a new src/cli/exit-codes.ts) that map to specific failure categories:
| Exit Code |
Constant |
Meaning |
| 0 |
EXIT_SUCCESS |
Command succeeded |
| 1 |
EXIT_GENERAL_ERROR |
Unknown/unhandled error |
| 2 |
EXIT_INVALID_ARGS |
Invalid CLI arguments or missing required flags |
| 3 |
EXIT_AUTH_EXPIRED |
AWS credentials expired or invalid (maps to EXPIRED_TOKEN_ERROR_CODES in errors.ts) |
| 4 |
EXIT_ACCESS_DENIED |
IAM permission error (maps to isAccessDeniedError()) |
| 5 |
EXIT_AGENT_NOT_FOUND |
Requested agent doesn't exist |
| 6 |
EXIT_DEPLOY_FAILED |
Deployment/CloudFormation failure |
Requirements
- Export a
ExitCode enum or const object from src/cli/exit-codes.ts
- Update
getErrorMessage() flow or add a getExitCode(err: unknown): number function that maps errors to the correct exit code
- Update the top-level CLI error handler (likely in
src/cli/cli.ts or src/cli/index.ts) to use the mapped exit code instead of hardcoded process.exit(1)
- Add unit tests in
src/cli/__tests__/ for the exit code mapping
Acceptance Criteria
Problem
The CLI currently exits with generic exit code 1 for all failures. This makes it hard to programmatically distinguish between different failure types in CI/CD pipelines or scripts that wrap
agentcorecommands.Proposed Solution
Define and export named exit codes in
src/cli/errors.ts(or a newsrc/cli/exit-codes.ts) that map to specific failure categories:EXIT_SUCCESSEXIT_GENERAL_ERROREXIT_INVALID_ARGSEXIT_AUTH_EXPIREDEXPIRED_TOKEN_ERROR_CODESinerrors.ts)EXIT_ACCESS_DENIEDisAccessDeniedError())EXIT_AGENT_NOT_FOUNDEXIT_DEPLOY_FAILEDRequirements
ExitCodeenum or const object fromsrc/cli/exit-codes.tsgetErrorMessage()flow or add agetExitCode(err: unknown): numberfunction that maps errors to the correct exit codesrc/cli/cli.tsorsrc/cli/index.ts) to use the mapped exit code instead of hardcodedprocess.exit(1)src/cli/__tests__/for the exit code mappingAcceptance Criteria
getExitCode()correctly mapsisAccessDeniedError()→EXIT_ACCESS_DENIEDgetExitCode()correctly maps expired token errors →EXIT_AUTH_EXPIREDgetExitCode()instead of hardcoded 1EXIT_GENERAL_ERROR(1)