Architecture patterns for the Shep AI terminal UI layer.
--flags for CI/scripting bypassA wizard is an async function that orchestrates multiple prompts into a multi-step flow:
// src/presentation/tui/wizards/agent-config.wizard.ts
import { select, confirm, password } from '@inquirer/prompts';
export interface AgentConfigResult {
agentType: string;
authMethod: string;
token?: string;
}
export async function agentConfigWizard(): Promise<AgentConfigResult> {
// Step 1: Select agent
const agentType = await select({ ... });
// Step 2: Select auth method
const authMethod = await select({ ... });
// Step 3: If token, get token
if (authMethod === 'token') {
const token = await password({ ... });
return { agentType, authMethod, token };
}
return { agentType, authMethod };
}
CLI commands detect whether to run interactive or non-interactive mode:
// In command handler
if (options.agent && options.auth) {
// Non-interactive: use flags directly
result = { agentType: options.agent, authMethod: options.auth };
} else {
// Interactive: launch wizard
result = await agentConfigWizard();
}
Reusable prompt configurations are extracted to separate files:
// src/presentation/tui/prompts/agent-select.prompt.ts
import { listAgentDescriptors } from '@shepai/core/domain/shared/agent-catalog.js';
export function createAgentSelectConfig() {
const t = getTuiI18n().t;
const choiceKey = (key: string, field: string) =>
`tui:prompts.selectAgent.choices.${key}.${field}`;
return {
message: t('tui:prompts.selectAgent.message'),
choices: listAgentDescriptors().map((descriptor) => {
const name = t(choiceKey(descriptor.i18nKey, 'name'), { defaultValue: descriptor.label });
if (!descriptor.supported) {
return {
name,
value: descriptor.type,
disabled: t(choiceKey(descriptor.i18nKey, 'disabled'), { defaultValue: '(Coming Soon)' }),
};
}
return {
name,
value: descriptor.type,
description: t(choiceKey(descriptor.i18nKey, 'description'), {
defaultValue: descriptor.description,
}),
};
}),
theme: shepTheme,
};
}
The choice list is derived from AGENT_CATALOG, never hand-written β a newly supported
agent appears in the picker as soon as its catalog row exists, ordered by descriptor.order,
and supported: false rows render disabled with a βComing Soonβ badge. The previous
hand-maintained array had silently omitted llmproxy, leaving a working agent unreachable
from shep settings.
Translations are looked up under tui:prompts.selectAgent.choices.<i18nKey>.{name,description,
disabled} across all nine locales in translations/, with the catalogβs own English text as
the fallback, so a locale that has not caught up never hides a working agent.
Custom Inquirer theme integrates with the CLI design system colors:
// src/presentation/tui/themes/shep.theme.ts
import { colors } from '@/presentation/cli/ui';
export const shepTheme = {
prefix: { idle: colors.brand('?'), done: colors.success('β') },
style: {
highlight: (text: string) => colors.brand(text),
disabled: (text: string) => colors.muted(text),
},
};
src/presentation/tui/
βββ index.ts # Barrel exports
βββ wizards/ # Multi-step wizard flows
β βββ agent-config.wizard.ts # Agent selection + auth config
β βββ merge-review.wizard.ts # Merge/PR review flow
β βββ plan-review.wizard.ts # Plan review flow
β βββ prd-review.wizard.ts # PRD review flow
β βββ onboarding/ # First-run onboarding wizard
β βββ onboarding.wizard.ts
β βββ types.ts
β βββ steps/
β βββ agent.step.ts
β βββ ide.step.ts
β βββ workflow-defaults.step.ts
βββ prompts/ # Reusable prompt configurations
β βββ agent-select.prompt.ts
β βββ auth-method.prompt.ts
β βββ ide-select.prompt.ts
β βββ prd-review-question.prompt.ts
β βββ prd-review-summary.prompt.ts
βββ themes/ # Custom Inquirer themes
βββ shep.theme.ts
shep tui, specs 142, 143 and 148)A full-screen, live view of every feature, modelled on oh-my-piβs Agent Hub
(docs/competitors/oh-my-pi.md). It is the first TUI surface that is not a wizard.
shep tui (tui.command.ts) checks for a TTY, resolves three use cases
ββ runFeatureConsole feature-console.app.ts
ββ TUI(FullscreenTerminal(ProcessTerminal)) pi-tui diff renderer on the alternate screen
ββ FeatureConsoleView UI state only: selection, mode, pane
ββ every 2s β GetFeatureConsoleSnapshotUseCase (never two reads at once)
ββ a / r / s / R β RunFeatureConsoleActionUseCase
ββ u β SetFleetQueuePauseUseCase (only while a pause is in force)
ββ l β GetFeatureLogTailUseCase (refreshed with the snapshot while the pane is open)
Rules the console follows:
actions contains it, and the action use case refuses anything else again.deriveFeatureState (domain/shared/feature-state.ts) is shared with
the web canvas and feature tree, so every surface agrees.render(width) returns terminal.rows lines, none wider than width.
With the alternate screen this makes pi-tuiβs inline diff renderer a full-screen one.sanitizeText, so an
agentβs output can never move the cursor or change colours inside the console.GetFleetOverviewUseCase decides both, the same reader shep fleet status and the
web status bar use, and the bannerβs line comes out of the body height so the console still
renders exactly one screen.q, ctrl+c, SIGTERM and SIGHUP all go through one
finish() that stops polling, stops pi-tui and leaves the alternate screen.pi-tui (MIT, Node >= 20) was chosen over oh-my-piβs fork, which needs Bun and a Rust addon, and
over Ink, which needs React >= 19.3. See specs/142-tui-feature-console/research.yaml.
t / T / f / F β OpenFeaturePaneUseCase application/use-cases/feature-console/
ββ feature by id or prefix, directory: worktree on disk, else repository
ββ command: none (the user's shell) or <shep> feat logs -f <id>
ββ ITerminalPaneLauncher (port)
detect() domain/shared/terminal-multiplexer.ts
TMUX β ZELLIJ β WEZTERM_PANE β KITTY_WINDOW_ID, SHEP_MULTIPLEXER overrides
open() infrastructure/services/terminal-pane/
multiplexer-commands.ts: one pure argv builder per multiplexer
terminal-pane-launcher.service.ts: runs it through ExecFunction
βββ Opened | Inline { cwd, command } | Failed
Inline β the app stops pi-tui, run-inline.ts runs the command on this terminal
(ctrl+c ignored by the console until the child exits), then restarts and redraws
/ β filterConsoleRows (core, pure) applied by ConsoleRoster on every keystroke
alerts β terminal-notification.ts for features that start needing the user
-c, so # is doubled.SHEP_HOME to the pane (tmux -e, kitty
--env, an env K=V prefix for Zellij and WezTerm on POSIX).TERM. TERM and TERM_PROGRAM survive into nested shells and
ssh sessions with no multiplexer to talk to, so they never enable panes.ctrl+p or : lists every console command that applies to the selected feature
(console-palette.ts), with its key. An entry is a ConsoleKey: enter replays that key through
the viewβs browse handler, so the palette runs the same guarded path as the key and can never
offer an action the core did not put in row.actions. Adding a console command is one row in
the palette table. c copies the feature id over OSC 52 (works over ssh and through tmux).
C β ControlCenter.open (control-center.ts)
candidates: active features (isActiveFeatureState) with a run and no window yet
ββ OpenControlCenterUseCase β OpenFeaturePaneUseCase per feature (Log, Window, title)
β launcher.open returns the window id the multiplexer printed
every snapshot β ControlCenter.sync
renames: tracked windows whose state symbol changed
status: tmuxStatusOptions(summary) when it changed (@shep_status, @shep_needs_you)
ββ UpdateMultiplexerStatusUseCase β launcher.renameWindow / publishStatus
(detects the multiplexer itself; outside one it does nothing)
A window the user closed fails its next rename; the console forgets it, and C can open it
again. shep tui --status [plain|tmux] prints formatStatusSegment(summary) once.
o β ChatView (chat-view.ts) fills the body; the message line is the status line
ConsoleChat (console-chat.ts) polls while attached, every 750 ms
ββ GetFeatureChatUseCase β GetInteractiveChatStateUseCase
entries: user / assistant / tool / block / answer (FeatureChatEntryKind), newest last
busy (ChatTurnStatus.Processing or booting), streamingText, the open question(s)
enter β SendFeatureChatMessageUseCase β SendInteractiveMessageUseCase (worktree, else repository)
1-9 / typed answer β AnswerFeatureChatQuestionUseCase β RespondToInteractionUseCase (by question text)
quit β StopFeatureChatsUseCase for every chat this process started
βAttachβ talks to the featureβs interactive chat, not the headless background worker: one
conversation per feature, persisted, shown identically by the web Chat tab. Interactive sessions
live in the process that boots them, so the console stops the ones it started before it exits.
With SHEP_MOCK_EXECUTOR=1 the mock interactive executor answers deterministically (one tool
call, a quote of the message; βask meβ asks a two-option question), which the e2e test drives.
The tools this follows (workmux, oh-my-pi, claude-squad, Claude Code agent teams) are compared in docs/competitors/agent-harness-tui.md.
The console draws these as overlays (console-overlay.ts / console-overlays.ts), and the chat
view is one of them too:
d opens Learned harness changes. These are the pending HarnessChange inbox questions
(harness-decisions.ts filters ListAgentQuestionInboxUseCase). The view shows each oneβs
summary and diff preview. a adopts it; r rejects it, with an optional reason typed on the
status line. Answers go through AnswerAgentQuestionUseCase, so the web inbox stays in sync.
The key bar shows d only while there is a decision.N opens New feature for the selected featureβs repository. It creates the feature through
CreateFeatureUseCase with useWorkflowDefaults. While the selfLearning flag is on, the form
offers Explore (tab) and its k (ββ, 1..5, starting at learning.exploreK) with the cost note.
tui.command.ts reads the flag and passes explore in, so the console holds no settings logic.@inquirer/prompts imports, test wizard logic and result mapping--flag bypass (non-interactive)tests/e2e/tui/ drives the real CLI in a pseudo-terminal (node-pty) and reads
the screen through @xterm/headless (tests/helpers/tui/pty-screen.ts). Waits are
condition-based with a deadline, never fixed sleeps.tests/helpers/tui/fake-terminal.ts with fake use cases.tests/e2e/tui/feature-console-tmux.test.ts runs the console as the only pane
of a private tmux server (tmux -L), presses keys with send-keys, and asks tmux which panes
opened, where, and running what.