Skip to content

fix: create global entrypoint for tui#1365

Open
Hweinstock wants to merge 9 commits into
aws:mainfrom
Hweinstock:fix/tui-telemetry-init
Open

fix: create global entrypoint for tui#1365
Hweinstock wants to merge 9 commits into
aws:mainfrom
Hweinstock:fix/tui-telemetry-init

Conversation

@Hweinstock
Copy link
Copy Markdown
Contributor

@Hweinstock Hweinstock commented May 22, 2026

Description

Previously, commands like agentcore add, deploy, etc. rendered TUI screens inline via direct render() calls. This made it difficult to distinguish CLI vs TUI code paths, caused telemetry to be mislabeled as mode="cli" for interactive flows, and meant bare agentcore never initialized or shut down the telemetry client.

This PR creates a unified renderTUI() entrypoint that owns the telemetry lifecycle and replaces all inline render() calls. As part of this:

  • Extracted rendering logic into src/cli/tui/render.ts and shared notices into src/cli/notices.ts to break circular imports
  • Migrated add, deploy, create, remove, invoke to use renderTUI()
  • Made TelemetryClientAccessor.init() handle re-initialization safely
  • Preserved existing behavior (diffMode, isInteractive, actionOnBack)

This refactor fixes #895.

Type of Change

  • Bug fix
  • New feature

Testing

  • Typecheck, lint, unit tests pass
  • Manual E2E testing of affected commands

basic-flows.mov

Manually tested flows:

  • back on inline tui exists instead of going to help.
  • successful flow on tui exists instead of going back to help.
  • root level agentcore works as expected.
  • errors still propagate correctly in inline TUI.
  • telemetry is now emitted for both inline TUI and full screen.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@github-actions github-actions Bot added the size/m PR size: M label May 22, 2026
@agentcore-devx-automation agentcore-devx-automation Bot added the claude-security-reviewing Claude Code /security-review in progress label May 22, 2026
@github-actions github-actions Bot added the agentcore-harness-reviewing AgentCore Harness review in progress label May 22, 2026
@agentcore-devx-automation
Copy link
Copy Markdown
Contributor

Claude Security Review: no high-confidence findings. (run)

@agentcore-devx-automation agentcore-devx-automation Bot removed the claude-security-reviewing Claude Code /security-review in progress label May 22, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Package Tarball

aws-agentcore-0.14.2.tgz

How to install

gh release download pr-1365-tarball --repo aws/agentcore-cli --pattern "*.tgz" --dir /tmp/pr-tarball
npm install -g /tmp/pr-tarball/aws-agentcore-0.14.2.tgz

Copy link
Copy Markdown

@agentcore-cli-automation agentcore-cli-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for unifying the TUI entrypoint — the RenderTUIOptions shape and InitialRoute typing are nice. I have a few concerns that I think need to be addressed before this merges.

Summary of issues

  1. Telemetry regression for invoke TUI: The PR removes the withCommandRunTelemetry('invoke', …) wrapper that previously wrapped the TUI invoke flow. No replacement was added, so cli.command_run (with has_stream/has_session_id/auth_type/agent_protocol/duration/exit_reason) is no longer emitted for agentcore invoke interactive mode. See inline comment.

  2. Behavior change: TUI flows no longer auto-exit on success when launched from CLI commands. Previously agentcore add, agentcore remove, etc. rendered their flows with isInteractive={false}, which makes screens like AddFlow, RemoveAllScreen, RemoveFlow, AddSuccessScreen, AddMemoryFlow, AddEvaluatorFlow, AddOnlineEvalFlow, AddIdentityFlow auto-exit after success (see e.g. AddFlow.tsx:206, RemoveAllScreen.tsx:30). Going through App now means they always receive isInteractive={true}, so the user has to press escape to leave after every successful run. See inline comment.

  3. Double TelemetryClientAccessor.init() for command-routed paths. When agentcore add (or any of the migrated commands) runs, main() calls TelemetryClientAccessor.init(args[0], 'cli') (cli.ts:271) and then the action handler calls renderTUI() which calls TelemetryClientAccessor.init(initialRoute.name, 'tui') (cli.ts:127). The first client (mode=cli) is overwritten in the singleton and never shutdown()'d. See inline comment.

  4. Circular import. src/cli/cli.ts imports registerInvoke/registerAdd/etc. from ./commands/*, and those command files now import renderTUI from '../../cli'. It works today because renderTUI is only referenced inside async action handlers, but it's fragile. See inline comment.

Items 1 and 3 are the most important — 1 is a clear telemetry regression and 3 partially undoes the telemetry-mode fix this PR is trying to land.

Comment thread src/cli/commands/invoke/command.tsx
Comment thread src/cli/tui/App.tsx Outdated
Comment thread src/cli/cli.ts Outdated
Comment thread src/cli/commands/invoke/command.tsx Outdated
@github-actions github-actions Bot added size/l PR size: L and removed agentcore-harness-reviewing AgentCore Harness review in progress size/m PR size: M labels May 22, 2026
@Hweinstock Hweinstock closed this May 22, 2026
@Hweinstock Hweinstock reopened this May 22, 2026
@agentcore-devx-automation agentcore-devx-automation Bot added the claude-security-reviewing Claude Code /security-review in progress label May 22, 2026
@github-actions github-actions Bot added size/l PR size: L agentcore-harness-reviewing AgentCore Harness review in progress and removed size/l PR size: L labels May 22, 2026
@agentcore-devx-automation
Copy link
Copy Markdown
Contributor

Claude Security Review: no high-confidence findings. (run)

@agentcore-devx-automation agentcore-devx-automation Bot removed the claude-security-reviewing Claude Code /security-review in progress label May 22, 2026
Copy link
Copy Markdown

@agentcore-cli-automation agentcore-cli-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the cleanup — the unified renderTUI() entrypoint is a nice improvement and the recent commits address most of the earlier review feedback (double init, isInteractive threading, render-tui module extraction).

Flagging two new issues below; both involve information being silently dropped on the way through renderTUI. The other pre-existing review comments still appear open but their underlying concerns look addressed in the latest commits — happy to leave those for the original reviewer to confirm.

Comment thread src/cli/commands/deploy/command.tsx
Comment thread src/cli/tui/screens/invoke/useInvokeFlow.ts Outdated
@github-actions github-actions Bot removed the agentcore-harness-reviewing AgentCore Harness review in progress label May 22, 2026
@Hweinstock Hweinstock force-pushed the fix/tui-telemetry-init branch from 9456078 to bce4cf9 Compare May 22, 2026 03:32
@github-actions github-actions Bot added size/l PR size: L and removed size/l PR size: L labels May 22, 2026
@agentcore-devx-automation agentcore-devx-automation Bot added the claude-security-reviewing Claude Code /security-review in progress label May 22, 2026
Create a unified renderTUI() entrypoint that all TUI-rendering code paths
use instead of inline Ink render() calls. This fixes telemetry never being
emitted for bare 'agentcore' TUI mode and mislabeling TUI sessions as CLI.

- Add renderTUI() with RenderTUIOptions for configurable behavior
- Migrate add, deploy, create, remove, invoke commands to use renderTUI()
- Add InitialRoute type for type-safe route navigation
- Add actionOnBack option to control escape/back behavior
- Add enterAltScreen option for inline vs full-screen rendering
- Initialize and shutdown TelemetryClientAccessor within renderTUI()

Fixes aws#895
Move the withCommandRunTelemetry('invoke', ...) call into useInvokeFlow
so that a cli.command_run event is emitted regardless of how the invoke
screen is launched (bare agentcore TUI or agentcore invoke command).

This restores the telemetry emission that was lost when the invoke
command was migrated to use renderTUI().
…avior

Commands launched via CLI (agentcore add, deploy, etc.) previously rendered
with isInteractive=false, causing screens to auto-exit after success. The
renderTUI migration broke this by hard-coding isInteractive=true.

Add isInteractive option to RenderTUIOptions (default: true) and thread it
through App to all screens. CLI command handlers pass isInteractive=false
to preserve the previous auto-exit behavior.
@Hweinstock Hweinstock reopened this May 22, 2026
@github-actions github-actions Bot added size/l PR size: L agentcore-harness-reviewing AgentCore Harness review in progress and removed size/l PR size: L labels May 22, 2026
@agentcore-devx-automation
Copy link
Copy Markdown
Contributor

Claude Security Review: no high-confidence findings. (run)

@agentcore-devx-automation agentcore-devx-automation Bot added claude-security-reviewing Claude Code /security-review in progress and removed claude-security-reviewing Claude Code /security-review in progress labels May 22, 2026
The renderTUI migration dropped diffMode — agentcore deploy --diff silently
fell back to a regular deploy flow. Extend the deploy Route variant with
diffMode and pass it through to DeployScreen.

Add test that verifies diffMode reaches renderTUI via initialRoute.
The invoke telemetry was hard-coding agent_protocol='unknown'. Read the
project spec before the telemetry wrapper so the actual protocol from
the first runtime is used in the metric attributes.
@Hweinstock Hweinstock force-pushed the fix/tui-telemetry-init branch from 274c6ff to 8acb65f Compare May 22, 2026 03:46
@github-actions github-actions Bot added size/l PR size: L and removed size/l PR size: L labels May 22, 2026
@agentcore-devx-automation
Copy link
Copy Markdown
Contributor

Claude Security Review: no high-confidence findings. (run)

@agentcore-devx-automation agentcore-devx-automation Bot added claude-security-reviewing Claude Code /security-review in progress and removed claude-security-reviewing Claude Code /security-review in progress labels May 22, 2026
Copy link
Copy Markdown

@agentcore-cli-automation agentcore-cli-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the latest commits — the author has addressed all the major issues raised in prior reviews:

  • Telemetry regression for invoke TUI is fixed (withCommandRunTelemetry now wraps the config-load effect in useInvokeFlow).
  • isInteractive is now threaded through renderTUIApp → individual screens, preserving auto-exit behavior for CLI-launched flows.
  • TelemetryClientAccessor.init() now flushes the prior client before re-initializing, so the cli→tui mode switch no longer leaks an unflushed sink.
  • renderTUI was extracted into src/cli/tui/render.ts, breaking the would-be circular import from command files.
  • diffMode is threaded through the deploy route into DeployScreen, with a unit test asserting the wiring.
  • agent_protocol is now resolved from the project spec instead of being hard-coded to 'unknown'.

The duration-semantics point on cli.command_run (now measuring config-load time rather than full session length for TUI invoke) was acknowledged by the author and is acceptable.

No new blocking issues from me — looks good to merge.

@github-actions github-actions Bot removed the agentcore-harness-reviewing AgentCore Harness review in progress label May 22, 2026
@agentcore-devx-automation
Copy link
Copy Markdown
Contributor

Claude Security Review: no high-confidence findings. (run)

@agentcore-devx-automation agentcore-devx-automation Bot removed the claude-security-reviewing Claude Code /security-review in progress label May 22, 2026
@github-actions github-actions Bot removed the size/l PR size: L label May 22, 2026
@github-actions github-actions Bot added the size/l PR size: L label May 22, 2026
@agentcore-devx-automation agentcore-devx-automation Bot added the claude-security-reviewing Claude Code /security-review in progress label May 22, 2026
@agentcore-devx-automation
Copy link
Copy Markdown
Contributor

Claude Security Review: no high-confidence findings. (run)

@agentcore-devx-automation agentcore-devx-automation Bot removed the claude-security-reviewing Claude Code /security-review in progress label May 22, 2026
Copy link
Copy Markdown
Contributor Author

@Hweinstock Hweinstock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

few comments to help with review.

const { unmount } = render(
<DeployScreen
isInteractive={false}
autoConfirm={options.autoConfirm}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

headers = parseHeaderFlags(cliOptions.header);
}

const tuiResult = await withCommandRunTelemetry(
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

telemetry is moved inside the invoke logic since the client is now initialized in renderTUI.

isInteractive={false}
onExit={() => {
unmount();
process.exit(0);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

killing the process here can prevent clean up from running which includes telemetry client shutdown.

Comment thread src/cli/notices.ts
import { type UpdateCheckResult, printUpdateNotification } from './update-notifier';

export function printTelemetryNotice(): void {
const yellow = '\x1b[33m';
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated to work here, but I want to centralize these. Its very confusing as a reader of code to see \x1b[33m and know its yellow.

@Hweinstock Hweinstock marked this pull request as ready for review May 22, 2026 12:46
@Hweinstock Hweinstock requested a review from a team May 22, 2026 12:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/l PR size: L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: duplicate header on entrypoint

2 participants