PermDock
CLI

Agent mode

How the permdock CLI behaves when an AI agent runs it - JSON results by default, no prompts, action_required errors with next steps, and an effects digest before it rewrites files, publishes to the Cloud or overwrites with --force.

When an AI coding agent runs permdock, the CLI prints cli-result-v2 JSON instead of text and never prompts. When the run needs something only a person can give (input, a login, or a confirmation), it exits 2 with an action_required error document on stderr.

Usage

permdock doctor                     # JSON result when an agent runs it
permdock doctor --format text       # text even in agent mode
permdock doctor --agent no          # turn agent mode off for this run
PERMDOCK_AGENT=1 permdock collect   # turn it on, as in a test harness
permdock codemod 0.5 --yes --effects-digest 6f3a9c0e41b27d58   # run again after the person agreed

Detection

--agent auto|yes|no decides, then PERMDOCK_AGENT (1, yes, true, 0, no, false, auto), then detection. Detection reads the same variables as @vercel/detect-agent 1.2.7, in its order, and a test asserts both agree:

VariableAgent
AI_AGENTThe name it holds
CURSOR_TRACE_ID, only when stdout is not a terminalCursor
CURSOR_AGENT, CURSOR_EXTENSION_HOST_ROLE=agent-execCursor CLI
GEMINI_CLIGemini CLI
CODEX_SANDBOX, CODEX_CI, CODEX_THREAD_IDCodex
ANTIGRAVITY_AGENTAntigravity
AUGMENT_AGENTAugment
OPENCODE=1, OPENCODE_CLIENTopencode
CLAUDECODE, CLAUDE_CODEClaude Code
REPL_IDReplit
COPILOT_MODEL, COPILOT_ALLOW_ALL, COPILOT_GITHUB_TOKENGitHub Copilot
/opt/.devin existsDevin

run() from permdock/cli reads only the env its caller passes, so a program that calls it is not switched to JSON by the agent that runs the program.

What changes

  • Output. stdout carries the result document and stderr one error document line when the run fails; --format text or --no-json brings text back. Progress and logs go to stderr without spinners.
  • Prompts. None. A command that would ask takes the answer its flags give, or stops with input_required.
  • Action required. The run exits 2; the error document's status is action_required, userActionRequired is true and reason is input_required, auth_required or confirmation_required. next lists the commands that continue the run, each with command, argv and the condition under which to run it.
  • Completion. permdock completion and the hidden __complete print text for the shell even in agent mode.

An agent may not start three kinds of run without the person's go-ahead:

ReasonWhenCommands
rewriteThe command edits files the project ownscodemod, rls migrate
cloud:writeThe command publishes to a PermDock Cloud projectcloud push
overwrite--force replaces files PermDock did not writeinit --force, any files command with --force

The first run exits 2 with confirmation_required. Its data.effects says what the run would change, one line per reason, and data.digest is the effects digest. The agent shows the person what will happen, and after they agree runs the command in next, which is the same command line with --yes --effects-digest <digest>. A run with --dry-run or --check writes nothing and needs no confirmation.

{
  "$schema": "https://permdock.com/schemas/cli-result-v2.json",
  "status": "action_required",
  "reason": "confirmation_required",
  "message": "permdock codemod edits files the project owns. Ask the person to agree, then run it again with --yes --effects-digest 6f3a9c0e41b27d58.",
  "type": "https://permdock.com/docs/cli/errors#confirmation_required",
  "next": [
    {
      "command": "permdock codemod 0.5 --yes --effects-digest 6f3a9c0e41b27d58",
      "argv": [
        "permdock",
        "codemod",
        "0.5",
        "--yes",
        "--effects-digest",
        "6f3a9c0e41b27d58"
      ],
      "when": "after the person agrees"
    }
  ],
  "data": {
    "digest": "6f3a9c0e41b27d58",
    "effects": ["permdock codemod edits files the project owns"]
  },
  "userActionRequired": true,
  "retryable": false
}

The digest is the first 16 hex characters of a SHA-256 of the reasons, the working directory and the command line without the global flags. A digest for one command line or directory does not confirm another, and the message says so; --yes alone, or the digest without --yes, does not confirm either. The removed --confirm flag fails with flag_renamed. A secret only arrives on stdin (--db-url-stdin, --key-stdin, --token-stdin) or from the environment, so the digest never depends on it and the line in next never prints it.

auth_required follows the same shape: a 401 or 403 from the Cloud exits 2 with permdock login in next.

Why

  • JSON by default for agents. An agent parses text by guessing; one document with a stable reason per failure lets it branch without matching prose. --format text stays one flag away for an agent that shows the output to a person.
  • better-supabase's contract 3. An agent that runs both CLIs reads one format: the same documents, reasons, exit codes and --yes --effects-digest confirmation (decision 0068). userActionRequired tells "ask the person" from "fix the code" without a separate exit code.
  • A digest, not --yes alone. --yes answers prompts, and an agent adds it to every command it runs. The digest binds the confirmation to one command line in one directory, so the agent has to show the person that line first.
  • Detection follows @vercel/detect-agent. Agents set their own variables, and one shared list means permdock, the Vercel CLI and better-supabase switch to agent mode for the same agents. The list is copied rather than depended on so the CLI's startup loads no extra package.

Last updated on

On this page