Skip to content

feat(session): support --agent-cmd flag on wt session add#12

Merged
pld merged 5 commits intopld:mainfrom
ukanga:support-passing-agent-cli-parameter
May 8, 2026
Merged

feat(session): support --agent-cmd flag on wt session add#12
pld merged 5 commits intopld:mainfrom
ukanga:support-passing-agent-cli-parameter

Conversation

@ukanga
Copy link
Copy Markdown
Collaborator

@ukanga ukanga commented May 7, 2026

Closes #11

Summary

  • Adds --agent-cmd <CMD> to wt session add for a one-off override of session.agent_cmd. Applies to both panes mode and windows mode when creating a new agent pane/window.
  • Override does not mutate persisted config and is not retroactively applied to an existing tmux window/session — an explanatory note is printed in that case.
  • Precedence (highest wins): --agent-cmd > .wt.toml > ~/.wt/config.toml > default.

Changes

  • src/config.rs: SessionConfig::with_agent_cmd_override returns a clone with agent_cmd swapped only when an override is provided.
  • src/session_cmd.rs: clap agent_cmd: Option<String> on SessionAction::Add, threaded through run_session into both cmd_session_add_panes and cmd_session_add_windows; setup uses the overridden SessionConfig.
  • src/main.rs: CLI parsing tests for both with/without --agent-cmd.
  • tests/tmux_test.rs: configure git identity in setup_test_repo so the initial empty commit succeeds in CI without a global git identity.
  • README.md: CLI reference, example, dedicated paragraph on one-off semantics, and updated precedence rule.

Test plan

  • cargo build clean
  • cargo test — 74 pass (51 lib + 11 bin + 3 integration + 9 which); 4 tmux-dependent tests remain #[ignore] as before; 0 failures
  • CLI parsing covered with and without the flag
  • Override application covered for both panes and windows mode (via effective_session_config)
  • No-mutation guarantee covered (test_effective_session_config_override_is_one_off)
  • Full precedence chain covered (test_full_precedence_chain_cli_beats_local_beats_global_beats_default)
  • Manual smoke: wt session add demo --agent-cmd "opencode --continue" in panes mode and wt session --mode windows add demo --agent-cmd "opencode --continue" in windows mode

@ukanga ukanga requested a review from pld May 7, 2026 11:07
ukanga added 4 commits May 7, 2026 14:19
setup_test_repo now configures user.email and user.name so the initial
empty commit succeeds in CI environments without a global git identity.
SessionConfig::with_agent_cmd_override returns a clone with agent_cmd
swapped when an override is provided, leaving the loaded config
untouched. This is the foundation for a per-invocation --agent-cmd flag
that does not mutate persisted config.

Tests cover:
- override applied / preserved when absent
- original SessionConfig is not mutated
- local .wt.toml agent_cmd overrides global ~/.wt/config.toml
- full precedence chain: default < global file < local file < override
Adds a one-off CLI override for session.agent_cmd that applies for the
current invocation only and does not mutate persisted config. Threaded
through both panes mode and windows mode so a new agent pane/window
runs the overridden command.

Precedence (highest wins): --agent-cmd > .wt.toml > ~/.wt/config.toml
> default.

When wt session add targets an existing tmux window or session, the
override is not retroactively applied; an explanatory note is printed
so the user knows the running command is unchanged.

Tests cover:
- CLI parsing with and without --agent-cmd
- effective_session_config applies the override
- override does not mutate context.config
- no override falls back to the loaded value
- Add --agent-cmd to both CLI reference tables.
- Add an example invocation in the Session Mode section.
- Add a paragraph explaining one-off semantics and that the override
  only applies when creating a new pane/window.
- List --agent-cmd in the precedence rule alongside --mode and --panes.
@ukanga ukanga force-pushed the support-passing-agent-cli-parameter branch from c9b60f7 to 2d934f8 Compare May 7, 2026 11:19
Copy link
Copy Markdown
Owner

@pld pld left a comment

Choose a reason for hiding this comment

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

looks good! seems reasonable that --agent-cmd works when not in a pane or window as well, maybe for some reason you want to run it in a new term emu not in the current tmux work flow?

Comment thread src/session_cmd.rs Outdated
Comment on lines +389 to +392
if agent_cmd_override.is_some() {
eprintln!(
"Note: --agent-cmd only applies when creating a new agent window; existing sessions keep their current command."
);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

this duplicates 293-297

@ukanga
Copy link
Copy Markdown
Collaborator Author

ukanga commented May 8, 2026

looks good! seems reasonable that --agent-cmd works when not in a pane or window as well, maybe for some reason you want to run it in a new term emu not in the current tmux work flow?

Is this the mode that creates the worktree and drops you into a new term emu in that worktree? Could the same apply where you may not need the term, but need the agent at that time? The use cases where this may have been relevant have been:

  • I need to investigate an issue and will likely be using an agent to do the investigation
  • I want to scope an issue, flesh it out, then create the relevant issue on GitHub, for example, that would be picked up later. Using an agent here is most likely

In most scenarios, I have ended up firing an agent for one reason or another, since the task at hand required it. In most cases, the task was investigative or scoping, not implementation. But it could be if the task is quick and small.

Extract `note_agent_cmd_override` and `note_agent_cmd_ignored` helpers
so the panes-mode and windows-mode add paths share the same emission
logic for the "Using one-off agent command override" line and the
"--agent-cmd only applies when creating..." note.

Addresses review feedback on PR pld#12 (duplicates 293-297).
@pld
Copy link
Copy Markdown
Owner

pld commented May 8, 2026

looks good! seems reasonable that --agent-cmd works when not in a pane or window as well, maybe for some reason you want to run it in a new term emu not in the current tmux work flow?

Is this the mode that creates the worktree and drops you into a new term emu in that worktree? Could the same apply where you may not need the term, but need the agent at that time? The use cases where this may have been relevant have been:

* I  need to investigate an issue and will likely be using an agent to do the investigation

* I want to scope an issue, flesh it out, then create the relevant issue on GitHub, for example, that would be picked up later. Using an agent here is most likely

In most scenarios, I have ended up firing an agent for one reason or another, since the task at hand required it. In most cases, the task was investigative or scoping, not implementation. But it could be if the task is quick and small.

Yep both of those scenarios, we're seeing this on our team, in work with one agent, you encounter an out of scope issue that you'd want to spawn another agent to fix in an interactive session, that last bit being the key. Going to merge this now since this is out of scope, but if could make a nice follow-up if we keep encounter that situation

@pld pld merged commit cc5f34d into pld:main May 8, 2026
1 check passed
@ukanga ukanga deleted the support-passing-agent-cli-parameter branch May 8, 2026 13:29
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.

Support --agent-cmd flag on wt session add for one-off agent command overrides

2 participants