Skip to content

Conversation

@galligan
Copy link
Contributor

URL-safe base64 encoding (RFC 4648 Section 5) for opaque cursor tokens.
Handles encoding/decoding of pagination state for API responses.

Closes #47

Co-Authored-By: Claude Opus 4.5 noreply@anthropic.com

Copy link
Contributor Author

galligan commented Jan 23, 2026

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@galligan galligan force-pushed the p3-9/state/cursor-encoding branch from 63c1be5 to 53afbd2 Compare January 23, 2026 11:58
@galligan galligan added the enhancement New feature or request label Jan 23, 2026
@galligan galligan marked this pull request as ready for review January 23, 2026 12:00
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 53afbd2a01

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@greptile-apps
Copy link

greptile-apps bot commented Jan 23, 2026

Greptile Summary

  • Implements URL-safe base64 cursor encoding/decoding for opaque pagination tokens in API responses
  • Adds comprehensive validation for decoded cursors including type checking, range validation, and field constraints
  • Includes extensive test coverage following TDD principles with error handling and round-trip validation

Important Files Changed

Filename Overview
packages/state/src/index.ts Added encodeCursor() and decodeCursor() functions with URL-safe base64 implementation and comprehensive validation
packages/state/src/__tests__/state.test.ts Added complete test coverage for cursor encoding functionality with round-trip and error handling tests

Confidence score: 5/5

  • This PR is safe to merge with minimal risk and follows established patterns
  • Score reflects well-tested implementation with comprehensive error handling and adherence to TDD methodology
  • No files require special attention as both implementation and tests are thorough and consistent

Sequence Diagram

sequenceDiagram
    participant User
    participant CLI as "CLI Application"
    participant Store as "CursorStore"
    participant Encoder as "encodeCursor/decodeCursor"
    
    User->>CLI: "Request paginated data"
    CLI->>Store: "createCursor({position: 0})"
    Store-->>CLI: "Result<Cursor>"
    CLI->>Encoder: "encodeCursor(cursor)"
    Encoder-->>CLI: "URL-safe base64 token"
    CLI-->>User: "Return data + encoded cursor token"
    
    User->>CLI: "Request next page with cursor token"
    CLI->>Encoder: "decodeCursor(token)"
    Encoder-->>CLI: "Result<Cursor>"
    CLI->>Store: "advanceCursor(cursor, newPosition)"
    Store-->>CLI: "New Cursor"
    CLI->>Store: "set(advancedCursor)"
    CLI->>Encoder: "encodeCursor(advancedCursor)"
    Encoder-->>CLI: "New URL-safe base64 token"
    CLI-->>User: "Return next page + new cursor token"
Loading

Copy link

@greptile-apps greptile-apps 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 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

@galligan
Copy link
Contributor Author

Added coverage to reject negative cursor positions when decoding encoded cursors.

@galligan galligan changed the base branch from p3-8/types/hash-id to graphite-base/71 January 24, 2026 02:39
@galligan galligan force-pushed the p3-9/state/cursor-encoding branch from acafeb4 to 542dd50 Compare January 24, 2026 02:43
@galligan galligan changed the base branch from graphite-base/71 to p3-8/types/hash-id January 24, 2026 02:43
@galligan
Copy link
Contributor Author

Replaced Buffer-based base64 in cursor encode/decode and tests with TextEncoder + btoa/atob helpers, and kept the negative-position validation in decodeCursor.

galligan and others added 3 commits January 23, 2026 22:44
URL-safe base64 encoding (RFC 4648 Section 5) for opaque cursor tokens.
Handles encoding/decoding of pagination state for API responses.

Closes #47

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@galligan galligan changed the base branch from p3-8/types/hash-id to graphite-base/71 January 24, 2026 03:48
@galligan galligan force-pushed the p3-9/state/cursor-encoding branch from 542dd50 to f814d80 Compare January 24, 2026 03:49
@galligan galligan changed the base branch from graphite-base/71 to p3-8/types/hash-id January 24, 2026 03:49
@galligan
Copy link
Contributor Author

Resolved the Greptile Buffer/base64 feedback (already switched to TextEncoder + btoa/atob) and resubmitted after downstack updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants