Introducing a new way to review your PRs.

Read the announcement

hcavarsan / kftray

kubectl port-forward manager and reverse tunnel (ngrok-like) for exposing local services publicly, with TLS termination, HTTP traffic inspection, UDP forwarding, multi-hop proxy routing through k8s clusters, stateful config via filesystem or git - GUI and TUI available

View on GitHub

19 documents · Updated Nov 23, 2026

docs / terminal-application-workflows

Terminal application workflows

kftui is the terminal application for loading, viewing, starting, and stopping Kubernetes port-forward configurations. It gives the same forwarding service two entry paths: CLI workflows for scripts and commands, and an interactive screen for people who need live status, controls, logs, and diagnostics. See the terminal experience page for the wider terminal product and connection forwarding for the forwarding service itself.

Application entry paths

The application selects a workflow from the command-line options before it starts forwarding. A run can use saved configurations or a temporary session, can import new configurations, and can either open the screen or remain suitable for automation.

CLI workflows

The CLI workflow validates its inputs, prepares the configuration store, imports configurations when requested, and then chooses an interactive or non-interactive run. A temporary session keeps source data in memory unless the user asks to save it. A saved session initializes and migrates the local store before it uses stored configurations. When a source is supplied, auto-start uses that import set unless a filter narrows it. References: crates/…/handler.rs• L22-67, crates/…/args.rs• L159-205, crates/…/runner.rs• L79-103

The main CLI workflow is coordinated in this order:

flowchart TD
    A[CLI options] --> B[Validate options]
    B --> C[Choose saved or temporary session]
    C --> D[Import configuration source]
    D --> E{Run mode}
    E -->|Interactive| F[Open terminal screen]
    E -->|Non-interactive| G[Start forwards]
    G --> H{Command after --}
    H -->|Yes| I[Run command]
    H -->|No| J[Keep forwards until shutdown]
    F --> K[Stop and clean up on exit]
    I --> K
    J --> K

References: crates/…/handler.rs• L33-45 crates/…/runner.rs• L64-77

Interactive screen

The interactive workflow places the terminal in a live screen that refreshes configuration and forwarding state. It presents stopped and running configurations, details for the selected item, a log view, and short key hints. Menu actions open focused screens for import, export, settings, help, and other user tasks. References: crates/…/app.rs• L47-95, crates/…/draw.rs• L67-138

Non-interactive commands

The non-interactive workflow starts selected forwards and can run a child command while they stay active. The child command receives the normal command output stream, while kftui keeps status and error messages separate. kftui returns the child exit result, uses shell-style codes when the command cannot start or is killed by a signal, and treats failed cleanup as a failed run when the command itself returned success. A command does not run when no forward started. References: crates/…/args.rs• L151-157, crates/…/runner.rs• L203-301, crates/…/test_cli_runner.rs• L22-41, crates/…/test_cli_runner.rs• L217-265

Configuration workflows

Configuration intake turns user-provided data or Kubernetes discovery results into forwarding configurations. The same intake path supports a local file, inline JSON, standard input, a GitHub source, or annotation-based discovery. It can load data for one session or save it for later runs.

Configuration sources

Only one configuration source is active in a run. File, JSON, standard input, and GitHub sources provide explicit configuration data. Auto-discovery reads service annotations from a selected Kubernetes context and can apply common options such as domain aliases and loopback addresses. References: crates/…/args.rs• L30-49, crates/…/args.rs• L92-135, crates/…/config.rs• L135-178

Configuration import

Import first reads and checks the source, then applies an optional flush, and finally writes the accepted configurations to the selected session store. A flush replaces saved data only after the new source has been loaded successfully. References: crates/…/config.rs• L24-38, crates/…/config.rs• L41-57, crates/…/test_cli_config.rs• L75-119

Discovery watch

Discovery watch repeats annotation discovery in the background for runs that use --watch. Each round adds only configurations that do not already match saved data. If auto-start is enabled, new configuration IDs move to the correct starter: the CLI starts them in the background, while the screen receives them through its event loop. References: crates/…/watch.rs• L26-34, crates/…/watch.rs• L117-193

Forwarding lifecycle

The CLI and the screen both treat forwarding as a lifecycle rather than a single action. They select configurations, start them through the core forwarding service, show progress or failures, and stop them through one shutdown path.

Forward start and stop

Starting a configuration maps its workload and protocol to the forwarding service. The terminal layer reports the result but does not own the cluster-level forwarding work. Stopping uses the configuration identity so that the same operation can be requested from a table action, a child-command exit, or process shutdown. References: crates/…/port_forward.rs• L27-100, crates/…/port_forward.rs• L223-231

Interactive forwarding actions

The screen keeps a configuration in a busy state while a start or stop is in progress. The user can act on stopped or running rows, select several rows for one action, and see progress or reconnect state without losing the current selection. Errors wait until a safe screen state before they open an error popup. References: crates/…/mod.rs• L971-1133, crates/…/mod.rs• L1645-1751, crates/…/table.rs• L55-162

Shutdown cleanup

All exit paths converge on shutdown cleanup. The application stops discovery and related monitors, restores the terminal, and drains forwarding work under a shared time budget. Every stop is dispatched before waiting begins, so stops can progress together. A stop that exceeds the budget stays alive in the background, is excluded from an immediate second cleanup attempt, and leaves its configuration marked for a later retry. References: crates/…/app.rs• L572-711, crates/…/app.rs• L97-147, crates/…/runner.rs• L420-461, crates/…/runner.rs• L639-812, crates/…/port_forward.rs• L103-220

User input and screen state

The screen treats keyboard input as state transitions. The current screen state decides whether a key navigates a table, edits a value, confirms an action, or closes a popup. This keeps a key from triggering a forwarding action while the user is in another task.

Normal navigation moves focus between the menu, search field, stopped table, details, and log view. Table actions cover start or stop, row selection, delete, view filters, tags, HTTP logs, and page movement. Search filters both tables and clears row marks when the visible set changes. Refreshes rebuild marks from configuration identity, so grouping or search changes do not retarget a later bulk action. References: crates/…/mod.rs• L1397-1517, crates/…/mod.rs• L1645-1855, crates/…/mod.rs• L1858-1947, crates/…/mod.rs• L963-1016

Modal screens isolate tasks that need a clear decision or text input. They cover errors, delete confirmation, context selection, settings, file import and export, view filters, tag editing, telemetry consent, and HTTP log work. A modal can hold a background failure until the user finishes the current choice. References: crates/…/mod.rs• L321-345, crates/…/mod.rs• L1305-1387, crates/…/draw.rs• L140-265

Import and export actions

The screen supports configuration import and export without leaving the application. File selection and preview form the user-facing part of the flow, while the shared configuration utility reads or writes JSON through the active session mode. References: crates/…/config.rs• L9-54, crates/…/render.rs• L114-172

Diagnostics and supporting utilities

Diagnostics help a user understand forwarding state without leaving the terminal. Logging, error popups, HTTP log viewing, request replay, settings, and file helpers support both live operation and recovery from failed actions.

Logging and output

Logging has two destinations. The normal interactive path keeps logs in the screen, while file logging sends them to the application log file. CLI status uses standard output when it is safe to do so, and switches status to standard error when a child command needs standard output for its own use. A configured network monitor starts only for the current command or keep-alive session and is stopped only when kftui started it. References: crates/…/main.rs• L57-76, crates/…/initializer.rs• L12-53, crates/…/output.rs• L19-39, crates/…/runner.rs• L235-257

Error reporting

Errors from background forwarding work move through a shared report path. The screen combines reports into a scrollable popup and keeps reports that arrive during another modal until that modal closes. Long batches are capped for one popup, while the popup keeps a usable scroll range and always shows a way to close it, even on a small terminal. On shutdown, reports that were not shown move to the normal terminal and log output. References: crates/…/mod.rs• L651-701, crates/…/mod.rs• L1018-1125, crates/…/popup.rs• L630-835, crates/…/test_ui_popup.rs• L142-260

HTTP log inspection

HTTP log inspection turns recorded request and response text into entries that a user can browse. The screen can show live entries, open request details, build a curl command, and replay a supported request through the selected forward. References: crates/…/mod.rs• L61-75, crates/…/mod.rs• L141-177, crates/…/popup.rs• L1549-1578

Supporting utilities

Supporting utilities keep file and configuration actions small and shared. They validate that a selected path is a file, move configuration JSON between the session store and disk, and protect the interactive screen when standard input was consumed for import. References: crates/…/file.rs• L5-15, crates/…/config.rs• L9-54, crates/…/stdin.rs• L1-13, crates/…/stdin.rs• L98-109

Tests and quality boundaries

The tests protect the contracts between CLI selection, screen state, forwarding work, diagnostics, and cleanup. They use temporary stores and controlled terminal backends so they can check user-visible behavior without requiring a live terminal for every case.

CLI guarantees

CLI tests cover child-command exit results, signal-style exit codes, network-monitor ownership, standard-input behavior, SSL preparation, import safety, discovery filtering, the rule that a child command does not run when no forward starts, and cleanup that continues after the wait budget. These tests define the boundary that automation depends on. References: crates/…/test_cli_runner.rs• L22-41, crates/…/test_cli_runner.rs• L45-126, crates/…/test_cli_runner.rs• L130-213, crates/…/test_cli_runner.rs• L217-279, crates/…/test_cli_runner.rs• L412-497

Screen guarantees

Screen tests cover input transitions, resize handling, selection behavior, search targeting, popup reachability, table status, and log inspection. Snapshot and rendered-screen checks protect the main screen and popup shapes, including delete controls across terminal sizes and error details across scroll positions. References: crates/…/test_input.rs• L98-141, crates/…/test_input.rs• L302-356, crates/…/test_input.rs• L471-739, crates/…/test_ui_popup.rs• L142-260, crates/…/test_snapshots.rs• L121-303

Lifecycle guarantees

Lifecycle tests check that queued work stays visible, duplicate actions do not race, failures reach the user, and shutdown does not abort cleanup work that still owns a resource. The runner tests also check that a completed stop keeps its result when a slower sibling exceeds the shared deadline. References: crates/…/test_cli_runner.rs• L412-497, crates/…/test_app.rs• L316-387, crates/…/test_app.rs• L424-642, crates/…/test_cli_watch.rs• L85-143

Change checklist

When these files or sections are changed, remember to consider these:

  • Changes to CLI source rules must stay aligned with validation, import mode selection, and the IDs passed to auto-start.
  • Changes to child-command output must preserve the separation between command standard output and kftui status or error output.
  • Changes to command exit handling must preserve the distinction between the child result and a cleanup failure.
  • Changes to monitor startup must preserve ownership, so a run does not stop a monitor that it did not start.
  • Changes to screen row filtering or grouping must preserve selection by configuration identity, not by an old row position.
  • Changes to forwarding task shutdown must keep detached configuration IDs out of a second stop or reconcile attempt.
  • Changes to discovery watch handoff must keep non-interactive starts and interactive event-loop starts on their separate paths.
  • Changes to error-popup sizing or scroll state must preserve access to both late failure lines and the dismissal key.
  • Changes to HTTP log parsing or replay must preserve the link between a request and its response trace ID.

Important failure modes

TriggerConsequenceGuard
More than one configuration source is suppliedThe run is rejected before importCLI source validation permits one source only
A child command is requested without --auto-startNo command runsCLI validation rejects the combination
Every selected forward fails to start in a non-interactive runThe command or keep-alive phase does not startThe runner reports the failures and reconciles before exit
A child command succeeds but shutdown leaves work outstandingThe run reports failure instead of claiming a clean resultCleanup errors override a zero child exit code
A stop remains active past the shutdown budgetCleanup continues after the caller stops waitingThe spawned task stays detached and its configuration remains eligible for a later retry
A second interrupt arrives during shutdownkftui exits without waiting for the stop to finishStops already dispatched remain detached and continue in the background
A forwarding failure arrives during a confirmation or edit modalThe current user task could be interrupted or the error could be lostThe report waits until the modal closes
A long error is shown in a narrow terminalFailure lines or the close action could be clippedThe popup reserves hint space, hard-wraps narrow content, and clamps scrolling
Search or grouping changes row order while rows are markedA later bulk action could target the wrong configurationsMarked rows are rebuilt from configuration IDs

Key files

FileWhy to read it
crates/…/main.rsShows application startup, logging choice, and the top-level runtime boundary.
crates/…/handler.rsShows how validation, storage mode, import, and execution mode connect.
crates/…/args.rsDefines the user-facing workflow choices and their relationships.
crates/…/config.rsShows how explicit sources and Kubernetes discovery become configurations.
crates/…/runner.rsShows auto-start, child-command use, monitor ownership, signal handling, and bounded CLI cleanup.
crates/…/watch.rsShows repeated discovery and the handoff of new configurations to starters.
crates/…/app.rsShows the screen event loop and the common terminal shutdown path.
crates/…/mod.rsShows screen state, input routing, forwarding actions, error delivery, search, and shutdown task handling.
crates/…/draw.rsShows the main screen layout and how modal states appear.
crates/…/popup.rsShows diagnostic popup sizing, error scrolling, and small-terminal behavior.
crates/…/port_forward.rsShows the boundary between terminal workflows and core forwarding operations.
crates/…/test_cli_runner.rsShows automation contracts for child commands, monitors, exit results, and cleanup deadlines.
crates/…/test_input.rsShows input, selection, search, error scrolling, and screen state contracts.
crates/…/test_ui_popup.rsShows popup reachability and error behavior across terminal sizes.
crates/…/test_snapshots.rsShows stable screen and popup rendering contracts.