feat(session): support --agent-cmd flag on wt session add#12
Conversation
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.
c9b60f7 to
2d934f8
Compare
pld
left a comment
There was a problem hiding this comment.
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?
| if agent_cmd_override.is_some() { | ||
| eprintln!( | ||
| "Note: --agent-cmd only applies when creating a new agent window; existing sessions keep their current command." | ||
| ); |
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:
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).
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 |
Closes #11
Summary
--agent-cmd <CMD>towt session addfor a one-off override ofsession.agent_cmd. Applies to both panes mode and windows mode when creating a new agent pane/window.--agent-cmd>.wt.toml>~/.wt/config.toml> default.Changes
src/config.rs:SessionConfig::with_agent_cmd_overridereturns a clone withagent_cmdswapped only when an override is provided.src/session_cmd.rs: clapagent_cmd: Option<String>onSessionAction::Add, threaded throughrun_sessioninto bothcmd_session_add_panesandcmd_session_add_windows; setup uses the overriddenSessionConfig.src/main.rs: CLI parsing tests for both with/without--agent-cmd.tests/tmux_test.rs: configure git identity insetup_test_reposo 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 buildcleancargo test— 74 pass (51 lib + 11 bin + 3 integration + 9 which); 4 tmux-dependent tests remain#[ignore]as before; 0 failureseffective_session_config)test_effective_session_config_override_is_one_off)test_full_precedence_chain_cli_beats_local_beats_global_beats_default)wt session add demo --agent-cmd "opencode --continue"in panes mode andwt session --mode windows add demo --agent-cmd "opencode --continue"in windows mode