Skip to content

feat: agent-mode detection and behavior split#21

Draft
apgiorgi wants to merge 2 commits into
mainfrom
claude/issue-10-FdY2O
Draft

feat: agent-mode detection and behavior split#21
apgiorgi wants to merge 2 commits into
mainfrom
claude/issue-10-FdY2O

Conversation

@apgiorgi
Copy link
Copy Markdown
Collaborator

@apgiorgi apgiorgi commented Jun 5, 2026

Closes #10.

dci now 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)

  1. DCI_AGENT_MODE env var — =1 forces agent mode, =0 forces human mode. Always wins.
  2. --agent / --no-agent flags — explicit per-invocation override (last occurrence wins).
  3. Known agent env varsCLAUDECODE, 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.
  4. Non-TTY stdout — soft signal (pipe/redirect) when nothing above applies.

Behavior in agent mode

  • Default --output flips from table to compact JSON
  • Terminal color / decoration disabled (NOCOLOR)
  • Banners, hints, and first-run onboarding route to stderr so stdout stays parseable
  • User-Agent header carries agent=1

Human 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 status now 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 json as 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, and agent=1 tagging are all in place.

Acceptance criteria

  • DCI_AGENT_MODE env var toggles agent behavior
  • --agent / --no-agent flags override env detection
  • Documented list of detected agent env vars; non-TTY stdout is a soft signal
  • All decorative output (color, hints) suppressed in agent mode
  • Stderr/stdout split documented and respected (data → stdout, chatter → stderr)
  • User-Agent header includes agent=1 when in agent mode

Testing

  • New unit tests: TestResolveAgentMode, TestAgentFlagOverride, TestBuildUserAgent, TestDefaultOutputFormat, TestDetectedAgentEnv
  • Full suite passes except two pre-existing integration tests (TestCustomerContextFlag/*) that require network access to load the OpenAPI spec — they fail identically on main in this sandbox.

Docs

  • README gains an Agent Mode section
  • The dci-cli skill notes how to enable agent mode

Generated by Claude Code

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.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 status diagnostics and agent=1 User-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.

Comment thread main.go
Comment thread main.go
Comment thread main_test.go
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Agent-mode detection and behavior split

3 participants