Skip to content

fix: create global entrypoint for tui#1365

Merged
Hweinstock merged 12 commits into
aws:mainfrom
Hweinstock:fix/tui-telemetry-init
May 27, 2026
Merged

fix: create global entrypoint for tui#1365
Hweinstock merged 12 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

github-actions Bot commented May 22, 2026

Package Tarball

aws-agentcore-0.15.0.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.15.0.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 Outdated
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
@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
@Hweinstock Hweinstock force-pushed the fix/tui-telemetry-init branch from bce4cf9 to 8d0f3b3 Compare May 22, 2026 03:33
Comment thread src/cli/commands/remove/command.tsx Outdated
const project = await configIO.readProjectSpec().catch(() => undefined);
const firstProtocol = project?.runtimes?.[0]?.protocol ?? 'unknown';

const result = await withCommandRunTelemetry(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

When i tested this PR locally, i noticed that the value in the emitted telemetry was always 1 (likely how long it took to load the config).

Before this change, the value was the actual duration of my entire invoke session.

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.

Discussed in person, this is to be consistent with dev, and to avoid tying the duration to arbitrary user sessions.

Comment thread src/cli/tui/render.ts Outdated
process.stdout.write(SHOW_CURSOR);
}

await TelemetryClientAccessor.shutdown();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

wouldnt shutting down TelemetryClientAccessor here make it so if telemetry is emitted during a post-exit action (i.e. launchBrowserDev) then it would stop working?

Copy link
Copy Markdown
Contributor Author

@Hweinstock Hweinstock May 26, 2026

Choose a reason for hiding this comment

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

Yes, good call, this is important for when we add telemetry for the browser actions. I've swapped it to flush before the blocking process, then the shutdown should be handled by the global one in the finally block, if it reaches there. Shutdown is "best-effort" so its fine if it doesn't.

@Hweinstock Hweinstock force-pushed the fix/tui-telemetry-init branch from 7f6cf1a to 9bad38d Compare May 26, 2026 17:36
@github-actions github-actions Bot added size/l PR size: L and removed size/l PR size: L labels May 26, 2026
@agentcore-devx-automation agentcore-devx-automation Bot added the claude-security-reviewing Claude Code /security-review in progress label May 26, 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 26, 2026
Comment thread src/cli/commands/invoke/command.tsx Outdated
}
enterAltScreen: false,
actionOnBack: 'exit',
isInteractive: false,
Copy link
Copy Markdown
Contributor

@avi-alpert avi-alpert May 26, 2026

Choose a reason for hiding this comment

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

why was isInteractive switched to false here?

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.

good question. I made this change thinking that isInteractive=true meant exit after first success (as it does for other commands), and I didn't want the tui to exit early. However, turns out its just dead code:

isInteractive: _isInteractive,
. I think we can remove it as a followup.

@github-actions github-actions Bot removed the size/l PR size: L label May 26, 2026
@github-actions github-actions Bot added the size/l PR size: L label May 26, 2026
@agentcore-devx-automation agentcore-devx-automation Bot added the claude-security-reviewing Claude Code /security-review in progress label May 26, 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 26, 2026
@github-actions github-actions Bot added size/l PR size: L and removed size/l PR size: L labels May 26, 2026
@agentcore-devx-automation agentcore-devx-automation Bot added the claude-security-reviewing Claude Code /security-review in progress label May 26, 2026
@agentcore-devx-automation
Copy link
Copy Markdown
Contributor

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

avi-alpert
avi-alpert previously approved these changes May 26, 2026
@agentcore-devx-automation
Copy link
Copy Markdown
Contributor

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

# Conflicts:
#	src/cli/cli.ts
#	src/cli/commands/invoke/command.tsx
#	src/cli/tui/screens/invoke/useInvokeFlow.ts
@agentcore-devx-automation
Copy link
Copy Markdown
Contributor

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

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

3 participants