Skip to content

CLI: machine-actionable error codes in --agent JSON output #1313

Description

@yamcodes

This was generated by AI during triage.

Summary

When arkenv init refuses to proceed because a safety check tripped (unmet technical requirements, dirty git tree, non-empty directory), the --agent / --json output does not tell the calling agent which check failed or how to escalate. Agents are left pattern-matching on prose like "Use --force to bypass these checks."

Spun out of the discussion on #1111, where it was decided that --agent must never imply --force — meaning agents need a deliberate, machine-readable path to escalate instead.

Current behavior

  • Safety-check refusals are reported via human-oriented error/info log lines (e.g. Technical requirements not met:Use --force to bypass these checks.), and the command exits without a structured explanation.
  • The JSON reporter's terminal status: "error" payload carries only free-text message/error fields — no stable identifier distinguishing "requirements not met" from "dirty git tree" from any other failure.

Desired behavior

Every deliberate refusal in the CLI's JSON output carries:

  • a stable, documented error code (e.g. REQUIREMENTS_NOT_MET, GIT_TREE_DIRTY, NON_EMPTY_DIR) that is part of the CLI's public contract;
  • a retryWith hint listing the flags that would bypass the check (e.g. ["--force"]), empty when the failure is not bypassable;
  • enough structured detail for the agent to report the problem (e.g. the failed requirements with current/expected).

Unexpected/internal errors keep a generic code (e.g. INTERNAL) so consumers can distinguish "the CLI refused" from "the CLI broke".

Acceptance criteria

  • Each safety-check refusal in init (requirements, git status, non-empty directory) emits a distinct stable code in JSON mode
  • Bypassable refusals include a retryWith array naming the bypass flag(s)
  • Codes are documented (CLI docs and/or agent skill guidance) as a stable contract
  • The agent skill guidance explains the escalation pattern: run without --force, inspect code/retryWith, retry deliberately
  • Human-readable (non-JSON) output is unchanged
  • Tests cover the JSON shape for each refusal path

Out of scope

Related

Metadata

Metadata

Assignees

Labels

@arkenv/cliIssues or Pull Requests involving the ArkEnv CLIenhancementNew feature or improvementready for agentFully specified, ready for immediate implementation

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions