diff --git a/.changeset/violet-bats-crash.md b/.changeset/violet-bats-crash.md new file mode 100644 index 000000000..40dfad6b9 --- /dev/null +++ b/.changeset/violet-bats-crash.md @@ -0,0 +1,5 @@ +--- +"@workflow/cli": patch +--- + +Add -i / --interactive flag for enabling pagination bindings, new default being off diff --git a/packages/cli/src/commands/inspect.ts b/packages/cli/src/commands/inspect.ts index 54d13ed64..159d053d9 100644 --- a/packages/cli/src/commands/inspect.ts +++ b/packages/cli/src/commands/inspect.ts @@ -239,6 +239,7 @@ function toInspectOptions(flags: any): InspectCLIOptions { workflowName: flags.workflowName, withData: flags.withData, backend: flags.backend, + interactive: flags.interactive, }; } diff --git a/packages/cli/src/lib/config/types.ts b/packages/cli/src/lib/config/types.ts index 2e818e738..83f7c0442 100644 --- a/packages/cli/src/lib/config/types.ts +++ b/packages/cli/src/lib/config/types.ts @@ -21,4 +21,5 @@ export type InspectCLIOptions = { withData?: boolean; backend?: string; disableRelativeDates?: boolean; + interactive?: boolean; }; diff --git a/packages/cli/src/lib/inspect/flags.ts b/packages/cli/src/lib/inspect/flags.ts index 0d84d28ac..1757c4fbf 100644 --- a/packages/cli/src/lib/inspect/flags.ts +++ b/packages/cli/src/lib/inspect/flags.ts @@ -127,4 +127,12 @@ export const cliFlags = { helpLabel: '--limit', helpValue: 'NUMBER', }), + interactive: Flags.boolean({ + description: 'Enable interactive pagination with keyboard controls', + required: false, + char: 'i', + default: false, + helpGroup: 'Output', + helpLabel: '-i, --interactive', + }), }; diff --git a/packages/cli/src/lib/inspect/output.ts b/packages/cli/src/lib/inspect/output.ts index e41540748..75700d15f 100644 --- a/packages/cli/src/lib/inspect/output.ts +++ b/packages/cli/src/lib/inspect/output.ts @@ -543,6 +543,7 @@ export const listRuns = async (world: World, opts: InspectCLIOptions = {}) => { await setupListPagination({ initialCursor: opts.cursor, + interactive: opts.interactive, fetchPage: async (cursor) => { try { const runs = await world.runs.list({ @@ -680,6 +681,7 @@ export const listSteps = async ( await setupListPagination({ initialCursor: opts.cursor, + interactive: opts.interactive, fetchPage: async (cursor) => { logger.debug(`Fetching steps for run ${runId}`); try { @@ -888,6 +890,7 @@ export const listEvents = async ( await setupListPagination({ initialCursor: opts.cursor, + interactive: opts.interactive, fetchPage: async (cursor) => { logger.debug(`Fetching events for run ${filterId}`); try { @@ -957,6 +960,7 @@ export const listHooks = async (world: World, opts: InspectCLIOptions = {}) => { // Setup pagination with new mechanism await setupListPagination({ initialCursor: opts.cursor, + interactive: opts.interactive, fetchPage: async (cursor) => { if (!runId) { logger.debug('Fetching all hooks'); diff --git a/packages/cli/src/lib/inspect/pagination.ts b/packages/cli/src/lib/inspect/pagination.ts index 3c2838a59..89c04299b 100644 --- a/packages/cli/src/lib/inspect/pagination.ts +++ b/packages/cli/src/lib/inspect/pagination.ts @@ -143,6 +143,11 @@ export interface ListPaginationOptions { * Optional callback for when fetching starts */ onFetchStart?: (pageIndex: number) => void; + + /** + * Enable interactive pagination with keyboard controls + */ + interactive?: boolean; } /** @@ -151,7 +156,11 @@ export interface ListPaginationOptions { export async function setupListPagination( options: ListPaginationOptions ): Promise { - const { initialCursor, fetchPage, displayPage, onFetchStart } = options; + const { initialCursor, fetchPage, displayPage, onFetchStart, interactive } = + options; + + // Interactive mode requires both TTY support and explicit --interactive flag + const enableInteractive = interactive && isInteractive(); // Pages stack - stores all fetched pages const pages: PageData[] = []; @@ -172,7 +181,7 @@ export async function setupListPagination( pageIndex = index; // Clear screen for subsequent pages in interactive mode - if (isInteractive()) { + if (enableInteractive) { console.clear(); } @@ -183,7 +192,13 @@ export async function setupListPagination( // Fetch and display first page const firstPage = await showPage(0, initialCursor); - if (!isInteractive()) { + // In non-interactive mode, show info if there are more pages + if (!enableInteractive) { + if (firstPage.hasMore) { + logger.info( + '\nMore results available. Use --interactive (-i) to paginate through results.' + ); + } return; } @@ -208,7 +223,7 @@ export async function setupListPagination( pageIndex = newPageIndex; const cachedPage = pages[newPageIndex]; - if (isInteractive()) { + if (enableInteractive) { console.clear(); } @@ -257,7 +272,7 @@ export async function setupListPagination( pageIndex--; const prevPage = pages[pageIndex]; - if (isInteractive()) { + if (enableInteractive) { console.clear(); }