Skip to content

refactor(cli): split agent commands into modules, consolidate shared helpers - #350

Merged
codeaholicguy merged 4 commits into
mainfrom
feature-refactor-agent-commands
Oct 8, 2026
Merged

codeaholicguy merged 4 commits into
mainfrom
feature-refactor-agent-commands

Conversation

@codeaholicguy

Copy link
Copy Markdown
Owner

Summary

Refactors the 1,253-line commands/agent.ts into a commands/agent/ module tree following the existing commands/skill/ convention. Commands own Commander registration, option parsing, and terminal output; reusable logic lives in services.

  • Split: one *.command.ts per subcommand (start, list, sessions, session, open, send, kill, detail, rename, console) + agent.command.ts wiring + index.ts re-export; cli.ts is the only external import change
  • render.ts: terminal presentation helpers (status labels, formatCwd, separators, conversation/detail rendering)
  • factory.ts: createAgentManager + createDurableAgentService only
  • services/agent/resolve-agent.service.ts: resolveAgentByName (empty/not-found/ambiguous/resolved), reportAgentResolution, assertDurableNameUnambiguous, resolveDurableAgentEntry — adopted by send, detail, open, kill, agent.service.ts, and channel-runner.ts
  • Util consolidation: single agent-type label source (util/agent.ts, all 11 types, display + compact variants), unified relative-time formatters (util/time-format.ts), sanitizeProviderOutput + ANSI_ESCAPE_PATTERN in util/text.ts, shared AGENT_NAME_REGEX (replaces GROUP_NAME_REGEX)
  • Dedup: deleted tui/console/render/agentTypeLabel.ts and render/formatRelative.ts; unified "Please use a more specific name." message
  • Test fix: status.service.test.ts memoryMcp tests were spreading the whole fixture into getStatusReport, bypassing stubs and hitting the real npm registry (cause of the intermittent 5s timeouts); now deterministic
  • Behavior preserved: agent --help and all 11 subcommand helps are byte-identical to main

Test plan

  • npm run build — 6 projects, 266 files
  • vitest — 109 files / 1,318 tests pass
  • tsc -b + oxlint clean
  • ai-devkit lint --feature refactor-agent-commands — 12 checks
  • agent --help parity vs main (all subcommands)
  • Smoke: agent list, agent sessions on built dist
  • Manual TUI smoke (agent console label rendering)

…resolver service

- Single agent-type label source in util/agent.ts (display + compact
  variants covering all 11 types); delete partial TUI label maps.
- Merge three relative-time formatters into util/time-format.ts
  (formatRelativeCompact + formatRelativeTime + local timestamp helpers).
- Move sanitizeProviderOutput/ANSI_ESCAPE_PATTERN to util/text.ts and
  share AGENT_NAME_REGEX between agent commands and agent-group service.
- Extract services/agent/resolve-agent.service.ts classifying
  empty/not-found/ambiguous/resolved; adopt in sendToAgent and
  channel-runner, unifying resolution messages.
- Fix memoryMcp status tests spreading the whole fixture into
  getStatusReport, which bypassed the fs/command stubs and hit the real
  npm registry; delegate access/readFile to real fs under the temp home.
Break the 1253-line commands/agent.ts into commands/agent/* following
the commands/skill/ convention: one module per subcommand, a shared
render.ts for terminal presentation helpers, and a factory.ts for
manager/service construction and stdin plumbing.

- cli.ts and tests import registerAgentCommand via commands/agent/index.
- open/kill/detail resolve agents through resolveAgentByName +
  reportAgentResolution; send/detail reuse assertDurableNameUnambiguous.
- Commands keep Commander registration and terminal output; domain
  logic stays in services.
Mark planning milestones complete, tick verified test scenarios, and
capture the split-module structure, integration points, and the
worktree index-corruption + status-test network-flake notes.
- Move send-only helpers (readStdin, resolveSendMessage, writeWaitStatus,
  createCommandSendReporter) from factory.ts into send.command.ts;
  factory keeps only the shared manager/service constructors.
- Extract resolveDurableAgentEntry into resolve-agent.service.ts,
  deduplicating the repository.resolve + multi-match + cross-mode
  ambiguity preamble shared by send and detail, and unifying on a single
  DurableAgentRepository construction path.
- Reuse util/pluralize in the list waiting-agents message; keep the
  noun-only variant in render.ts renamed to pluralizeNoun.
- Inline single-caller resolveTailCount into selectConversationMessages.
- Extract renderDurableAgentDetail (render.ts) and reportStartError
  (start.command.ts) for readability.
@codeaholicguy
codeaholicguy merged commit 2280f2d into main Oct 8, 2026
7 checks passed
@codeaholicguy
codeaholicguy deleted the feature-refactor-agent-commands branch October 8, 2026 08:08
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