Skip to content

JSON 엔벨로프와 종료 코드 ​

stdout/stderr 계약 ​

  1. --json 없이는 stdout은 사람용이며 machine oracle이 아니에요.
  2. --json이 있으면 stdout은 정확히 하나의 UTF-8 JSON object + trailing newline 하나예요. BOM 없음. progress bar, 추가 JSON line, human text를 stdout에 쓰지 않아요.
  3. --json 모드의 stderr는 사람용 diagnostic일 수 있지만 oracle이 아니에요.
  4. JSON serialization 실패 시 부분 JSON을 쓰지 않고 exit 13.
  5. secret 원문은 어떤 stream에도 쓰지 않아요.

성공 envelope (cli-envelope/v1) ​

json
{
  "contract_version": "cli-operation/v7",
  "envelope_version": "cli-envelope/v1",
  "command": "verify",
  "subcommand": null,
  "cli_version": "0.0.0",
  "correlation_id": "cli_example",
  "project_ref": "prj_example",
  "environment": "test",
  "execution_mode": "execute",
  "status": "succeeded",
  "operation": null,
  "result": {},
  "issues": [],
  "next_actions": []
}
필드규칙
statussucceeded / waiting_approval / blocked / failed / not_verified / unknown
execution_modeexecute 또는 dry_run
operationmutating/async 명령에서는 operation object, read-only는 null
result명령별 closed object. ad-hoc 필드 추가 금지

status=succeeded는 정의된 작업 완료일 뿐 독립 QA/보안 인수나 production readiness가 아니에요.

오류 envelope ​

json
{
  "contract_version": "cli-operation/v7",
  "envelope_version": "cli-envelope/v1",
  "command": "deploy",
  "subcommand": null,
  "cli_version": "0.0.0",
  "correlation_id": "cli_example",
  "project_ref": "prj_example",
  "environment": "test",
  "execution_mode": "execute",
  "status": "failed",
  "operation": null,
  "error": {
    "source": "server",
    "code": "approval_required",
    "message": "승인이 필요한 작업이에요.",
    "retryable": false,
    "exit_code": 5,
    "details": {},
    "upstream_contract_version": "agent-authorization/v1"
  }
}
  • error.source: cli / local / network / server 중 하나. server의 exact error.code는 유지해요.
  • message는 oracle이 아니에요. machine client는 exit code와 error.code만 사용하세요.
  • exit-status 매핑: exit 2/3/4/6/7/9/10/11/13 → failed, exit 5 중 human decision 대기면 waiting_approval 그 외 failed, exit 8 → blocked, exit 12 → unknown.

종료 코드 closed table ​

exit의미대표 코드
0정의된 outcome 성공 확정 (verify/preflight pass 포함)succeeded
2usage/parser/config 오류cli_usage_error, unsupported_cli_version, credential_ambiguous
3인증 부재/만료/revoked/type mismatch/replay/quarantineagent_auth_required, agent_token_expired, agent_token_revoked, agent_token_replayed, agent_credential_quarantined
4인가/scope/project/environment/ownership 거부agent_forbidden, scope_insufficient, project_mismatch, environment_mismatch
5approval 필요/대기/불일치로 미실행approval_required, approval_mismatch, waiting_approval
6실행됐으나 validation/doctor/preflight verdict fail/not readyvalidation_failed, doctor_unhealthy, preflight_not_ready
7authorization 통과했으나 operation definite failureoperation_failed, not_found
8계약/정책/production 차단production_blocked, environment_blocked, contract_dependency_blocked, interactive_required, dry_run_unsupported
9network/dependency unavailable, bounded retry 소진dependency_unavailable, agent_auth_unavailable, agent_rate_limited
10state conflict/idempotency reuse/checkpoint conflictidempotency_key_reuse, checkpoint_conflict, concurrent_modification
11local safety invariant 실패 (checkpoint/atomic write/path boundary)local_state_unsafe, checkpoint_failed
12interrupt/timeout으로 outcome unknown — 새 effect 만들지 말고 recovery read만operation_outcome_unknown
13CLI internal defect/serialization failurecli_internal_error

machine client를 위한 실용 규칙 ​

  • shell/wrapper가 exit code를 삼키면 안 돼요.
  • retryable=true는 bounded retry만 의미해요. 무한 재시도 금지. server retry_after_seconds가 있으면 존중하세요.
  • exit 12 operation_outcome_unknown은 절대 성공으로 추정하지 마세요. 같은 canonical command/body와 **같은 --idempotency-key**로 다시 실행해 durable replay를 받아야 해요. 새 key로 대체하지 마세요.
  • unknown upstream error code는 exit 9 dependency_contract_invalid 하나로 fail closed돼요.
  • replay/quarantine 계열(agent_token_replayed, agent_credential_quarantined, exit 3)은 transient가 아니에요. 자동 재시도/재enrollment를 시도하지 말고 명시적 human browser flow로만 복구하세요.

project/environment mismatch의 deterministic pre-check ​

server-backed 요청 전에 CLI는 network 요청 0회로 로컬 pre-check를 해요:

  1. --project-ref가 credential family binding과 다르면 → exit 4 project_mismatch (error.source=cli) 정확히 하나.
  2. project가 exact 일치할 때만 environment 검사 → 다르면 exit 4 environment_mismatch.
  3. 둘 다 mismatch면 project_mismatch만 보고해요.

operation object (mutating 명령) ​

필드의미
operation_class예: preview.create, integration.apply_local
operation_refserver/local ref 또는 null
effect_scopelocal / server / local_and_server
idempotency_key_fingerprintraw key가 아니라 lowercase hex SHA-256 fingerprint
parameter_hashserver가 echo한 keyed hash. CLI 자체 계산값 금지. local-only면 null
approval_ref사용된 approval ref 또는 null
completionsynchronous / asynchronous / unknown
recoverynone / operation_ref_read / checkpoint_restore

next_actions 주의 ​

next_actions[].command는 catalog의 canonical command만 담아요. CLI와 agent는 이를 자동 실행하지 않아요. 실행 시 새 invocation의 입력 검증/authorization/dry-run/approval 규칙을 다시 적용해야 해요.