feat: agent-mode detection and behavior split#21
Draft
apgiorgi wants to merge 2 commits into
Draft
Conversation
Detect whether dci is driven by a human or an AI agent and adapt output accordingly (closes #10). Detection precedence: 1. DCI_AGENT_MODE env var (explicit override, always wins) 2. --agent / --no-agent flags (per-invocation override) 3. known agent env vars (CLAUDECODE, CURSOR_AGENT, KIRO_AGENT, ...) 4. non-TTY stdout (soft signal) In agent mode: - default --output flips from table to compact JSON - terminal color/decoration is disabled (NOCOLOR) - banners, hints, and onboarding route to stderr so stdout stays parseable - the User-Agent header carries agent=1 - the first-run onboarding banner is suppressed In human mode, today's behavior is preserved. When an agent env var is detected but the caller opted out, a one-line stderr tip points to the optimized path. `dci status` now reports whether agent mode is active and why. Documented in README and the dci-cli skill.
There was a problem hiding this comment.
Pull request overview
Adds an “agent mode” to dci that auto-detects agent-driven sessions (or can be forced/disabled via env/flags) and adjusts CLI defaults/output to keep stdout machine-parseable and token-efficient.
Changes:
- Implement agent-mode detection with documented precedence (env override → flags → known agent env vars → non-TTY stdout), plus
dci statusdiagnostics andagent=1User-Agent tagging. - Switch default output to JSON and suppress decorative onboarding/hints in agent mode (routing chatter to stderr where applicable).
- Add docs + skill guidance and unit tests covering detection/overrides/User-Agent/default output.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
skills/dci-cli/SKILL.md |
Documents how to enable/verify agent mode for the CLI skill. |
README.md |
Adds an Agent Mode section documenting detection and behavior changes. |
main.go |
Implements agent-mode detection, default output behavior, stderr/stdout split for hints, and User-Agent tagging. |
main_test.go |
Adds unit tests for agent-mode resolution, flag override parsing, User-Agent tagging, and default output. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Address PR review feedback: - agentFlagOverride now honors every boolean value form cobra/pflag accepts (--agent=0/1, --no-agent=0/1, =true/false, case-insensitive), so the early os.Args scan agrees with cobra's later parse and --agent=0 correctly overrides heuristics before NOCOLOR / User-Agent side effects run. - DCI_AGENT_MODE only treats recognized boolean tokens as decisive; an unrecognized value (e.g. DCI_AGENT_MODE=2) is ignored rather than silently forcing agent mode, and run() warns about it on stderr. - Add test coverage for the =0/1 flag forms and unrecognized env/flag values.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #10.
dcinow detects whether it's being driven by a human or an AI agent and adapts its output, following the spec in the Agentic UX series.Detection (priority order — first match wins)
DCI_AGENT_MODEenv var —=1forces agent mode,=0forces human mode. Always wins.--agent/--no-agentflags — explicit per-invocation override (last occurrence wins).CLAUDECODE,CLAUDE_CODE,CURSOR_AGENT,KIRO_AGENT,AIDER_SESSION,GEMINI_CLI,REPLIT_AGENT,WINDSURF_AGENT,OPENHANDS_AGENT,DEVIN_AGENT. The list is documented and PR-extensible.Behavior in agent mode
--outputflips fromtableto compact JSONNOCOLOR)User-Agentheader carriesagent=1Human mode is unchanged. When an agent env var is detected but the caller opted out (
--no-agent/DCI_AGENT_MODE=0), a one-line stderr tip points to the optimized path (per the issue addendum).dci statusnow shows whether agent mode is active and the reason.Scope note
The spec says the agent default should be "the compact format from #9". Since #9 (token-efficient/TOON output) and #12 (structured errors) are not yet merged, this PR uses
jsonas the compact, parse-friendly default — it will pick up the richer compact format once #9 lands. The detection plumbing, flags, stdout/stderr split, decoration suppression, andagent=1tagging are all in place.Acceptance criteria
DCI_AGENT_MODEenv var toggles agent behavior--agent/--no-agentflags override env detectionUser-Agentheader includesagent=1when in agent modeTesting
TestResolveAgentMode,TestAgentFlagOverride,TestBuildUserAgent,TestDefaultOutputFormat,TestDetectedAgentEnvTestCustomerContextFlag/*) that require network access to load the OpenAPI spec — they fail identically onmainin this sandbox.Docs
dci-cliskill notes how to enable agent modeGenerated by Claude Code