Skip to content

Commit ce683c0

Browse files
authored
fix(invoke): show full session ID and print resume command on exit (aws#904)
* fix(invoke): show full session ID and print resume command on exit The invoke TUI truncated the session ID to 8 characters, making it impossible to copy the full UUID needed for --session-id. Additionally, there was no guidance on how to resume a session after exiting. - Display full session ID in the TUI header instead of truncating - Print a colored resume command after TUI exit (both Esc and Ctrl+C) - Use Ink's unmount() instead of process.exit(0) for clean shutdown, which also fixes the update notifier not showing on Esc exit * fix: only show resume message when a session was actually used
1 parent 1a93f92 commit ce683c0

3 files changed

Lines changed: 18 additions & 3 deletions

File tree

src/cli/cli.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,4 +224,10 @@ export const main = async (argv: string[]) => {
224224

225225
// Telemetry notice already printed above; only run update check here.
226226
await printPostCommandNotices(false, updateCheck);
227+
228+
const exitMessage = getExitMessage();
229+
if (exitMessage) {
230+
console.log(`\n${exitMessage}`);
231+
clearExitMessage();
232+
}
227233
};

src/cli/commands/invoke/command.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,10 @@ export const registerInvoke = (program: Command) => {
168168
});
169169
} else {
170170
// No CLI options - interactive TUI mode (headers still passed if provided)
171-
const { waitUntilExit } = render(
171+
const { waitUntilExit, unmount } = render(
172172
<InvokeScreen
173173
isInteractive={true}
174-
onExit={() => process.exit(0)}
174+
onExit={() => unmount()}
175175
initialSessionId={cliOptions.sessionId}
176176
initialUserId={cliOptions.userId}
177177
initialHeaders={headers}

src/cli/tui/screens/invoke/InvokeScreen.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { buildTraceConsoleUrl } from '../../../operations/traces';
22
import { GradientText, LogLink, Panel, Screen, SelectList, TextInput } from '../../components';
3+
import { setExitMessage } from '../../exit-message';
34
import { useInvokeFlow } from './useInvokeFlow';
45
import { Box, Text, useInput, useStdout } from 'ink';
56
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
@@ -167,6 +168,14 @@ export function InvokeScreen({
167168
const justCancelledRef = useRef(false);
168169
const mcpFetchTriggeredRef = useRef(false);
169170

171+
useEffect(() => {
172+
if (sessionId && messages.length > 0) {
173+
const cyan = '\x1b[36m';
174+
const reset = '\x1b[0m';
175+
setExitMessage(`To resume this session, run: ${cyan}agentcore invoke --session-id ${sessionId}${reset}`);
176+
}
177+
}, [sessionId, messages.length]);
178+
170179
// Compute auth type early so hooks can reference it
171180
const currentAgent = config?.runtimes[selectedAgent];
172181
const isCustomJwt = currentAgent?.authorizerType === 'CUSTOM_JWT';
@@ -420,7 +429,7 @@ export function InvokeScreen({
420429
{mode !== 'select-agent' && (
421430
<Box>
422431
<Text>Session: </Text>
423-
<Text color="magenta">{sessionId?.slice(0, 8) ?? 'none'}</Text>
432+
<Text color="magenta">{sessionId ?? 'none'}</Text>
424433
</Box>
425434
)}
426435
{mode !== 'select-agent' && (

0 commit comments

Comments
 (0)