Skip to content

feat(cmd): wire --agent flag into new/yolo/yolo!/safe#27

Merged
aksOps merged 3 commits into
mainfrom
feat/agent-flag
May 16, 2026
Merged

feat(cmd): wire --agent flag into new/yolo/yolo!/safe#27
aksOps merged 3 commits into
mainfrom
feat/agent-flag

Conversation

@aksOps
Copy link
Copy Markdown
Contributor

@aksOps aksOps commented May 15, 2026

Summary

Adds the missing --agent <name> cobra flag to ctm new, ctm yolo, ctm yolo!, and ctm safe. Closes a gap shipped in #25: README + CHANGELOG promised ctm new --agent codex / ctm new --agent hermes, but the cobra flag was never wired into the runners — every session got session.DefaultAgent.

The Agent registry, hermes package, and SpawnOpts.Agent field were already in place. This PR is purely the CLI surface.

How it works

ctm new mytask                  # uses session.DefaultAgent (hermes)
ctm new mytask --agent codex    # spawns codex
ctm new mytask --agent hermes   # spawns hermes
ctm new mytask --agent nope     # error: unknown agent "nope"; available: codex, hermes

Same for ctm yolo / ctm yolo! / ctm safe.

Files changed

File Change
cmd/yolo.go New resolveAgent(name) helper — empty → empty (caller falls back), registered → name verbatim, unknown → error listing agent.Registered(). Adds internal/agent + strings imports.
cmd/new.go Register --agent flag in init; read + validate + pass to createAndAttach.
cmd/yolo_runners.go Register --agent on yoloCmd/yoloBangCmd/safeCmd; read + validate + pass to createAndAttach in all three runners.
cmd/attach.go createAndAttach signature gains agentName string between mode and store. The bare ctm runAttach call passes "" (no flag on root). SpawnOpts gets the Agent field set.
cmd/yolo_helpers_test.go 3 new tests on resolveAgent: empty path, registered names, unknown agent error format. Adds blank imports for codex+hermes so the registry is populated when tests run in the cmd package alone.
CHANGELOG.md New ### Added bullet for the --agent flag, ahead of the existing hermes entry.

Test plan

  • go test ./... — 413 pass (was 410, +3 from new resolveAgent tests)
  • go vet ./... clean
  • go build ./... clean
  • Help text: ctm new --help and ctm yolo --help now show --agent string with description
  • Unknown agent fails fast: ctm new x /tmp --agent nopeError: unknown agent "nope"; available: codex, hermes
  • Isolated-HOME smoke confirms --agent codex stamps agent: \"codex\" and --agent hermes stamps agent: \"hermes\" in sessions.json
  • Manual end-to-end in a real terminal: ctm new mytask ~/proj --agent codex → verify codex spawns; ctm new mytask2 ~/proj --agent hermes → verify hermes spawns. (Deferred to reviewer — needs interactive tmux.)

Risks / notes

  • Behavior change for any user invoking ctm new --agent <x> previously — that flag was silently ignored before (cobra rejects unknown flags by default, so the call would already error). No silent-misbehavior risk.
  • cmd/attach.go's runAttach (bare ctm <name>) does NOT take an --agent flag — it attaches to existing sessions by name; the agent is determined by the stored session row. Correct behavior, but worth flagging if you want the bare command to grow the flag later.
  • gofmt -l still shows pre-existing import-block drift in cmd/new.go and other cmd files. Left untouched per scope discipline (same as PR feat(agent): add hermes agent support #25 and feat(session): flip DefaultAgent to hermes #26).

🤖 Generated with Claude Code

aksOps added 3 commits May 15, 2026 17:28
Wires `--agent <name>` through cmd/new.go and cmd/yolo_runners.go
into createAndAttach -> SpawnOpts.Agent. Empty value falls through to
session.DefaultAgent; unknown agents fail fast with a list of
registered names so users can correct the flag.

Closes the gap shipped (claimed but not delivered) in #25: README and
CHANGELOG both promised `ctm new --agent codex` and
`ctm new --agent hermes` but the cobra flag was never wired. The
Agent registry, hermes package, and SpawnOpts.Agent field were
already in place — this PR is purely the CLI surface.

Tests cover empty / registered / unknown agent cases via the new
resolveAgent helper. Suite count goes 410 -> 413.
Sonar's duplication gate (10.3% > 3% on new code) flagged the 4x
repeated 'flag().String("agent", ...)' + 4x 'GetString + resolveAgent
+ err handling' blocks across new/yolo/yolo!/safe RunE bodies.

Extracted addAgentFlag (registers the flag) and agentFromCmd (reads
+ validates) into cmd/yolo.go. Each call site is now a single helper
call. resolveAgent stays separate so the unit tests in
yolo_helpers_test.go still exercise the validation logic without
needing a cobra.Command in scope.
Sonar's coverage gate (77.8% < 80%) flagged the two thin wrappers
added by the dedup refactor. Adds direct unit tests:

- TestAddAgentFlag: registers + default value + usage text
- TestAgentFromCmd_FlagUnset / _FlagSetValid / _FlagSetInvalid: read
  + validate flow on a fresh cobra.Command

Helpers now at 100% coverage. Suite count goes 413 -> 417.
@sonarqubecloud
Copy link
Copy Markdown

@aksOps aksOps merged commit 46a5018 into main May 16, 2026
10 checks passed
@aksOps aksOps deleted the feat/agent-flag branch May 16, 2026 01:56
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.

1 participant