Skip to content

fix: let an explicit --agent-mode override agent detection - #41

Closed
Bradenream wants to merge 2 commits into
masterfrom
braden/agent-mode-flag/COR-0
Closed

Bradenream wants to merge 2 commits into
masterfrom
braden/agent-mode-flag/COR-0

Conversation

@Bradenream

Copy link
Copy Markdown
Contributor

Summary

--agent-mode had no effect. Execute calls InitAgentMode before cobra parses flags, to keep the explorer TUI away from agents. That call can only see the environment, and its answer was final: InitAgentMode checked the flag only after a CompareAndSwap that every later call failed. So:

  • --agent-mode=false under Claude Code still printed JSON envelopes.
  • --agent-mode in a plain shell still printed human errors.
  • The flag's help ("Use --agent-mode=false to disable") was untrue.

InitAgentMode now checks for an explicitly set --agent-mode before that early return, so the call from PersistentPreRunE, the first to see the parsed flags, applies it. The environment is still checked only once. The explorer check is unchanged: it only runs when vf has no arguments, so no flag can be present.

This PR and #38 can merge in either order. #38's stdin rule reads output.IsAgentMode() each time instead of keeping a copy (addressing Copilot's review there), so it follows this flag too. That is checked with both applied: --agent-mode turns the no-wait rule on outside an agent, and --agent-mode=false under CLAUDECODE=1 turns it off.

Before and after

master this PR
CLAUDECODE=1 vf workspace list --agent-mode=false with no token JSON envelope human error
vf workspace list --agent-mode with no agent env and no token human error JSON envelope
CLAUDECODE=1 vf agent update --llm gpt-4 --agent-mode=false envelope human error

Test plan

Execute calls InitAgentMode before cobra parses flags, to keep the
explorer TUI away from agents. That call can only see the environment,
and its answer was final: InitAgentMode checked the flag only after a
CompareAndSwap that every later call failed. So --agent-mode=false
under Claude Code still printed JSON envelopes, --agent-mode in a plain
shell still printed human errors, and the flag's help ("Use
--agent-mode=false to disable") was untrue.

InitAgentMode now checks for an explicitly set --agent-mode before that
early return, so the call from PersistentPreRunE, the first to see the
parsed flags, applies it. The environment is still checked only once.
The explorer check is unchanged: it only runs when vf has no arguments,
so no flag can be present.
Copilot AI balanced review requested due to automatic review settings October 1, 2026 22:41

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

The behavior test can read Linux keyring credentials and become nondeterministic.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Fixes --agent-mode so explicit values override environment detection.

Changes:

  • Applies parsed flag values after initial environment detection.
  • Adds Go and CLI behavior tests.
File Description
internal/​output/​agentmode.go Prioritizes explicit agent-mode flags.
internal/​output/​agentmode_test.go Tests override behavior.
test/​agent-mode-flag.test.ts Adds end-to-end coverage.
Files not reviewed (1)
  • internal/output/agentmode.go: Generated file

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread test/agent-mode-flag.test.ts Outdated
The no-token cases ran vf with an empty HOME, which hides the macOS
Keychain, but on Linux vf reaches the keyring over the D-Bus session
bus. A developer with a token saved there would have had it found, and
the cases would have taken a different path. They now point
DBUS_SESSION_BUS_ADDRESS at a socket that does not exist, as
test/setup.ts does for the whole suite in #37. Copilot raised this in
review.

effervescentia commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Merge activity

  • Oct 2, 3:37 PM UTC: The merge label 'merge' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Oct 2, 3:37 PM UTC: effervescentia added this pull request to the Graphite merge queue.
  • Oct 2, 3:38 PM UTC: CI is running for this pull request on a draft pull request (#45) due to your merge queue CI optimization settings.
  • Oct 2, 3:39 PM UTC: Merged by the Graphite merge queue via draft PR: #45.

@graphite-app graphite-app Bot closed this Oct 2, 2026
@graphite-app
graphite-app Bot deleted the braden/agent-mode-flag/COR-0 branch October 2, 2026 15:39
@graphite-app graphite-app Bot removed the merge label Oct 2, 2026
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.

3 participants