Skip to content

feat: add --page convenience option for trace list CLI#707

Open
VJ-yadav wants to merge 2 commits intoAltimateAI:mainfrom
VJ-yadav:feat/trace-list-page-option
Open

feat: add --page convenience option for trace list CLI#707
VJ-yadav wants to merge 2 commits intoAltimateAI:mainfrom
VJ-yadav:feat/trace-list-page-option

Conversation

@VJ-yadav
Copy link
Copy Markdown
Contributor

@VJ-yadav VJ-yadav commented Apr 14, 2026

What does this PR do?

Fixes #669 — adds --page N (-p N) convenience option to altimate-code trace list so users don't have to manually calculate --offset values for pagination.

Before: altimate-code trace list --offset 20 --limit 20
After: altimate-code trace list --page 2

Changes

File Change
packages/opencode/src/cli/cmd/trace.ts Added --page / -p option with page-to-offset conversion (offset = (page - 1) * limit). Updated pagination footer to show page X/Y and --page N hints
packages/opencode/test/cli/trace-page-option.test.ts 14 unit tests covering page-to-offset conversion (edge cases: 0, negative, fractional, precedence over --offset) and footer formatting

Behavior

  • --page 1 → offset 0 (first page)
  • --page 2 --limit 10 → offset 10
  • --page takes precedence over --offset when both provided
  • Invalid values (0, negative, fractional) are clamped/truncated to valid pages
  • Footer now shows: Showing 1-20 of 50 trace(s) (page 1/3) and Next page: altimate-code trace list --page 2
  • Backward compatible — existing --offset/--limit usage unchanged

Screenshots

Screenshot 2026-04-13 at 9 10 06 PM Screenshot 2026-04-13 at 9 09 06 PM

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

Issue for this PR

Closes #669

Related: #596 (original pagination infrastructure)

How did you verify your code works?

  • 14 unit tests pass (bun test test/cli/trace-page-option.test.ts)
  • Tested locally with real traces: --page 1, --page 2, --page 6 (last), --page 99 (past end)
  • TypeScript: zero new errors
  • --help correctly shows the new -p, --page option

Checklist

  • I have performed a self-review of my code
  • My changes follow the existing code style
  • I have added tests that prove my fix is effective
  • New and existing unit tests pass locally

Summary by cubic

Adds a --page (-p) option to altimate-code trace list so users can paginate by page number instead of calculating --offset. The footer now shows page X/Y, and hints preserve --limit and choose the right format.

  • New Features
    • --page converts to offset ((page - 1) * limit) and overrides --offset.
    • Invalid --page values (0, negative, fractional) are clamped/truncated; non-numeric is ignored.
    • Footer shows page X/Y; next-page hint uses --page when aligned, otherwise --offset, and keeps --limit.
    • Empty-page message suggests --page 1 and shows total pages.
    • Backward compatible with existing --offset/--limit.
    • Added 14 unit tests for conversion and footer formatting.

Written for commit 779496a. Summary will update on new commits.

Summary by CodeRabbit

  • New Features

    • Added a 1-based page option (-p/--page) for easier pagination when listing traces.
  • Improvements

    • Pagination footer now shows current page and total pages.
    • "No traces on this page" message and "Next page" hints updated to suggest page-based navigation.
  • Tests

    • Added tests covering page-to-offset behavior and pagination footer formatting.

…teAI#669)

The pagination UX previously required users to manually calculate
offsets (--offset 20 --limit 20, then --offset 40 --limit 20).
This adds --page N (-p) which computes the offset automatically:
offset = (page - 1) * limit.

- --page takes precedence over --offset when both are provided
- Invalid values (0, negative, fractional) are clamped/truncated
- Footer now shows "page X/Y" and "Next page: --page N" hints
- 14 unit tests covering conversion logic and footer formatting
Copy link
Copy Markdown

@claude claude bot left a comment

Choose a reason for hiding this comment

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

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 14, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: e6e5211e-2263-4c79-992a-b66e9f79be0f

📥 Commits

Reviewing files that changed from the base of the PR and between f6cf324 and 779496a.

📒 Files selected for processing (1)
  • packages/opencode/src/cli/cmd/trace.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/opencode/src/cli/cmd/trace.ts

📝 Walkthrough

Walkthrough

Adds a 1-based --page (-p) option to the trace list CLI that maps pages to offsets, updates the "no traces" suggestion to recommend --page 1, revises the pagination footer to show current/total pages, and adjusts the "Next page" hint to prefer --page <n> when page-aligned.

Changes

Cohort / File(s) Summary
CLI Pagination Enhancement
packages/opencode/src/cli/cmd/trace.ts
Introduce --page (-p) option; derive offset = (max(1, trunc(page)) - 1) * limit when provided; compute currentPage/totalPages for footer; update "no traces" suggestion to --page 1; prefer --page <next> for next-page hint when page-aligned, otherwise fall back to offset-based hint.
Pagination Tests
packages/opencode/test/cli/trace-page-option.test.ts
Add tests for page→offset conversion (clamping, truncation, fallback to offset), and for footer formatting covering shown range, current/total pages, and presence/absence of next-page hint across scenarios.

Sequence Diagram(s)

(omitted)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

needs:compliance

Poem

🐇 I thumped my paw on page one, hooray!

No more offsets to lead me astray.
Just hop to --page 2 and away we go—
Traces in order, tidy and slow.
A bunny's cheer for pagination's new day.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is comprehensive and well-structured, covering what changed, behavior, test coverage, and verification. However, it lacks the required PINEAPPLE identifier at the top as mandated by the template. Add the word PINEAPPLE at the very top of the PR description before any other content, as required by the repository template.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: adding a --page convenience option to the trace list CLI command for improved pagination UX.
Linked Issues check ✅ Passed The PR successfully implements all requirements from issue #669: adds --page option with page-to-offset conversion, makes --page authoritative over --offset, handles invalid inputs robustly, updates pagination UX with page numbers and --page hints, and maintains backward compatibility.
Out of Scope Changes check ✅ Passed All changes are directly scoped to implementing the --page convenience option: trace.ts adds the CLI option and pagination logic, and the test file provides comprehensive test coverage for the new feature.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
packages/opencode/test/cli/trace-page-option.test.ts (1)

12-17: Avoid duplicating the production pagination logic inside the test.

pageToOffset() and formatFooter() are local copies of the implementation, so this suite can stay green while TraceCommand.handler or listTraces() drifts. Please extract a shared pure helper from packages/opencode/src/cli/cmd/trace.ts, or drive the real command/output path here instead.

Also applies to: 61-71

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/opencode/test/cli/trace-page-option.test.ts` around lines 12 - 17,
Tests duplicate production pagination/formatting logic (functions pageToOffset
and formatFooter) which can drift from the real implementation; refactor by
extracting the shared pure helper from the production module
(packages/opencode/src/cli/cmd/trace.ts) and import it into the test, or call
the real output path via TraceCommand.handler / listTraces so tests exercise
actual code paths; specifically remove the local pageToOffset/formatFooter in
the test and reference the exported helper(s) from trace.ts (or invoke
TraceCommand.handler/listTraces) to compute offsets/footers in the test.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/opencode/src/cli/cmd/trace.ts`:
- Around line 64-66: The hint messages printed by UI.println use page-based
commands that assume page-aligned results and default limits; update the logic
that constructs the suggestion (the block using pagination.total,
pagination.limit, pagination.offset, totalPages and UI.println) to preserve the
active pagination shape: if pagination.offset % pagination.limit === 0, include
both --page <page> AND --limit ${pagination.limit} in the suggested command,
otherwise emit an offset-based suggestion using --offset ${pagination.offset}
--limit ${pagination.limit}; ensure both branches use pagination.limit
explicitly so the suggested commands never rely on implicit defaults.
- Around line 184-187: Compute and use a sanitized limit before calculating
offset so the page->offset math matches the downstream pagination clamp: replace
the current two-step use of const limit = args.limit ?? 20 and offset
calculation with logic that first derives a sanitizedLimit (apply the same
clamping/validation you pass to Trace.listTracesPaginated, e.g., ensure minimum
1 and default 20) and then compute offset = args.page != null ? (Math.max(1,
Math.trunc(args.page)) - 1) * sanitizedLimit : (args.offset ?? 0); use
sanitizedLimit wherever limit is passed to Trace.listTracesPaginated/listing so
offset and limit are consistent.

---

Nitpick comments:
In `@packages/opencode/test/cli/trace-page-option.test.ts`:
- Around line 12-17: Tests duplicate production pagination/formatting logic
(functions pageToOffset and formatFooter) which can drift from the real
implementation; refactor by extracting the shared pure helper from the
production module (packages/opencode/src/cli/cmd/trace.ts) and import it into
the test, or call the real output path via TraceCommand.handler / listTraces so
tests exercise actual code paths; specifically remove the local
pageToOffset/formatFooter in the test and reference the exported helper(s) from
trace.ts (or invoke TraceCommand.handler/listTraces) to compute offsets/footers
in the test.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: f09b3b28-9735-4ee4-b36b-0a8cae98b334

📥 Commits

Reviewing files that changed from the base of the PR and between a18ecc6 and f6cf324.

📒 Files selected for processing (2)
  • packages/opencode/src/cli/cmd/trace.ts
  • packages/opencode/test/cli/trace-page-option.test.ts

Comment on lines +184 to +187
const limit = args.limit ?? 20
const offset = args.page != null
? (Math.max(1, Math.trunc(args.page)) - 1) * limit
: (args.offset ?? 0)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Normalize limit before converting page to offset.

Line 186 multiplies by the raw CLI value, but the comment above says Trace.listTracesPaginated() clamps invalid limits. That makes --page 2 --limit 0 compute offset = 0, then behave like page 1 after the downstream clamp to limit = 1. Compute the offset from the same sanitized limit you pass to pagination.

Suggested fix
-      const limit = args.limit ?? 20
+      const limit = Math.max(1, Math.trunc(args.limit ?? 20))
       const offset = args.page != null
         ? (Math.max(1, Math.trunc(args.page)) - 1) * limit
         : (args.offset ?? 0)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/opencode/src/cli/cmd/trace.ts` around lines 184 - 187, Compute and
use a sanitized limit before calculating offset so the page->offset math matches
the downstream pagination clamp: replace the current two-step use of const limit
= args.limit ?? 20 and offset calculation with logic that first derives a
sanitizedLimit (apply the same clamping/validation you pass to
Trace.listTracesPaginated, e.g., ensure minimum 1 and default 20) and then
compute offset = args.page != null ? (Math.max(1, Math.trunc(args.page)) - 1) *
sanitizedLimit : (args.offset ?? 0); use sanitizedLimit wherever limit is passed
to Trace.listTracesPaginated/listing so offset and limit are consistent.

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

2 issues found across 2 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="packages/opencode/src/cli/cmd/trace.ts">

<violation number="1" location="packages/opencode/src/cli/cmd/trace.ts:118">
P2: The generated `--page` hint drops the `--limit` value. If the user ran `trace list --page 2 --limit 10`, the suggested next-page command `--page 3` silently reverts to the default limit of 20, changing the result window. Include `--limit ${pagination.limit}` in the hint. Additionally, when the current offset isn't page-aligned (e.g. `--offset 5 --limit 10`), the computed `currentPage` is misleading and the `--page` hint will skip/overlap rows — fall back to an offset-based hint when `pagination.offset % pagination.limit !== 0`.</violation>

<violation number="2" location="packages/opencode/src/cli/cmd/trace.ts:185">
P2: `Math.max(1, NaN)` returns `NaN`, not `1`. If `args.page` is `NaN` (e.g., `--page foo`), the entire offset computation yields `NaN` and is passed to the API. Guard against `NaN` before the arithmetic.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review, or fix all with cubic.

Address PR review feedback:
- Guard against NaN in --page arg (e.g. --page foo) using Number.isFinite()
- Include --limit in next-page hint so custom limits are preserved
- Fall back to offset-based hint when offset isn't page-aligned
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: add --page convenience option for trace list CLI

1 participant