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 agreedDetection
--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:
| Variable | Agent |
|---|---|
AI_AGENT | The name it holds |
CURSOR_TRACE_ID, only when stdout is not a terminal | Cursor |
CURSOR_AGENT, CURSOR_EXTENSION_HOST_ROLE=agent-exec | Cursor CLI |
GEMINI_CLI | Gemini CLI |
CODEX_SANDBOX, CODEX_CI, CODEX_THREAD_ID | Codex |
ANTIGRAVITY_AGENT | Antigravity |
AUGMENT_AGENT | Augment |
OPENCODE=1, OPENCODE_CLIENT | opencode |
CLAUDECODE, CLAUDE_CODE | Claude Code |
REPL_ID | Replit |
COPILOT_MODEL, COPILOT_ALLOW_ALL, COPILOT_GITHUB_TOKEN | GitHub Copilot |
/opt/.devin exists | Devin |
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 textor--no-jsonbrings 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'sstatusisaction_required,userActionRequiredistrueandreasonisinput_required,auth_requiredorconfirmation_required.nextlists the commands that continue the run, each withcommand,argvand the condition under which to run it. - Completion.
permdock completionand the hidden__completeprint text for the shell even in agent mode.
Consent
An agent may not start three kinds of run without the person's go-ahead:
| Reason | When | Commands |
|---|---|---|
rewrite | The command edits files the project owns | codemod, rls migrate |
cloud:write | The command publishes to a PermDock Cloud project | cloud push |
overwrite | --force replaces files PermDock did not write | init --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
reasonper failure lets it branch without matching prose.--format textstays 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-digestconfirmation (decision 0068).userActionRequiredtells "ask the person" from "fix the code" without a separate exit code. - A digest, not
--yesalone.--yesanswers 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 meanspermdock, 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.
Related
Last updated on