Replace UUID with shortuuid for session IDs#404
Merged
nikblanchet merged 9 commits intomainfrom Nov 28, 2025
Merged
Conversation
Implements base57 encoding that produces 22-character session IDs instead of 36-character UUIDs. Uses BigInt in TypeScript and native int in Python for cross-language compatibility. Key functions: generate(), encode(), decode(), formatDisplay(), isValid() 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Cross-language test vectors ensure Python and TypeScript implementations produce identical output. Tests cover encode/decode roundtrip, display formatting, validation, and edge cases. - test-fixtures/shortuuid-vectors.json: Shared test vectors - analyzer/tests/test_shortuuid.py: 21 Python tests - cli/src/__tests__/utils/shortuuid.test.ts: 23 TypeScript tests 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
- validation.ts: Add isValidShortUuid, isValidSessionId, detectSessionIdFormat - session-id.ts: New SessionIdSchema Zod type accepting both formats - audit-session-state.ts: Use SessionIdSchema for session_id - improve-session-state.ts: Use SessionIdSchema for session_id, transaction_id Backward compatible: existing UUID sessions continue to work. Generated with [Claude Code](https://claude.com/claude-code) Steered and verified by @nikblanchet
Adds shortuuid validation alongside existing UUID validation. Both formats accepted indefinitely for backward compatibility. Generated with [Claude Code](https://claude.com/claude-code) Steered and verified by @nikblanchet
- audit.ts: Use generate() from shortuuid instead of randomUUID() - interactive-session.ts: Use generate() instead of uuidv4() New sessions now use 22-character shortuuids. Existing UUID sessions remain valid due to the updated validation accepting both formats. Generated with [Claude Code](https://claude.com/claude-code) Steered and verified by @nikblanchet
Intelligently formats session IDs based on type: - Shortuuids: truncates and adds hyphens every 4 chars (e.g., vytx-eTZs) - UUIDs: simple truncation (they already have natural hyphen structure) This helper can be used across display points for consistent formatting. Generated with [Claude Code](https://claude.com/claude-code) Steered and verified by @nikblanchet
Changes all session ID display points from raw .slice() to formatSessionIdForDisplay(), which handles hybrid UUID/shortuuid display correctly: - Shortuuids: Truncated with hyphens every 4 chars (e.g., "vytx-eTZs") - UUIDs: Simple truncation (already have natural hyphen structure) Also updates validation from isValidUuid() to isValidSessionId() which accepts both UUID and shortuuid formats. Files modified: - cli/src/session/interactive-session.ts - cli/src/commands/audit-sessions.ts - cli/src/commands/improve-sessions.ts - cli/src/commands/audit.ts - cli/src/commands/improve.ts Test updates: - InteractiveSession.test.ts: Updated regex to match shortuuid format - audit-sessions.test.ts, improve-sessions.test.ts: Updated error message Generated with [Claude Code](https://claude.com/claude-code) Steered and verified by @nikblanchet
Python (ruff): - Break long lines in encode() and test vectors fixture - Use list.extend() instead of for loop with append in format_display() - Shorten assertion message in test TypeScript (eslint): - Remove empty lines between import groups in type files - Rename abbreviated variables (alphaLen -> alphabetLength, num -> value) - Use String#replaceAll() instead of String#replace() with regex - Fix JSDoc indentation Generated with [Claude Code](https://claude.com/claude-code) Steered and verified by @nikblanchet
Reformatted files to pass CI checks: - analyzer/tests/test_shortuuid.py (ruff format) - cli/src/commands/audit-sessions.ts (prettier) - cli/src/commands/improve-sessions.ts (prettier) Generated with [Claude Code](https://claude.com/claude-code) Steered and verified by @nikblanchet
nikblanchet
added a commit
that referenced
this pull request
Nov 28, 2025
- Add comprehensive tests for 5 validation functions: - isValidShortUuid(): valid/invalid shortuuids, hyphenated input - isValidSessionId(): UUID, shortuuid, and hybrid validation - detectSessionIdFormat(): format detection tests - normalizeSessionId(): UUID preservation, hyphen stripping - formatSessionIdForDisplay(): truncation and hyphen formatting - Add truncate parameter validation in formatDisplay(): - Throws if truncate is negative or not an integer - Protects against invalid input values - Add BigInt edge case comment explaining 0n behavior Addresses post-merge review findings from PR #404. Generated with [Claude Code](https://claude.com/claude-code) Steered and verified by @nikblanchet
6 tasks
nikblanchet
added a commit
that referenced
this pull request
Nov 28, 2025
- Add comprehensive tests for 5 validation functions: - isValidShortUuid(): valid/invalid shortuuids, hyphenated input - isValidSessionId(): UUID, shortuuid, and hybrid validation - detectSessionIdFormat(): format detection tests - normalizeSessionId(): UUID preservation, hyphen stripping - formatSessionIdForDisplay(): truncation and hyphen formatting - Add truncate parameter validation in formatDisplay(): - Throws if truncate is negative or not an integer - Protects against invalid input values - Add BigInt edge case comment explaining 0n behavior Addresses post-merge review findings from PR #404. Generated with [Claude Code](https://claude.com/claude-code) Steered and verified by @nikblanchet
nikblanchet
added a commit
that referenced
this pull request
Nov 28, 2025
* Add validation utility tests and truncate parameter validation - Add comprehensive tests for 5 validation functions: - isValidShortUuid(): valid/invalid shortuuids, hyphenated input - isValidSessionId(): UUID, shortuuid, and hybrid validation - detectSessionIdFormat(): format detection tests - normalizeSessionId(): UUID preservation, hyphen stripping - formatSessionIdForDisplay(): truncation and hyphen formatting - Add truncate parameter validation in formatDisplay(): - Throws if truncate is negative or not an integer - Protects against invalid input values - Add BigInt edge case comment explaining 0n behavior Addresses post-merge review findings from PR #404. Generated with [Claude Code](https://claude.com/claude-code) Steered and verified by @nikblanchet * Add code review enhancements for truncate validation - Add truncate validation error tests (negative, non-integer, NaN, Infinity) - Add truncate edge case tests (0 returns empty, large value returns full) - Extract magic numbers to constants (ZERO_UUID_ENCODING, BASE57_EXCLUDED_CHARS) - Add JSDoc example for truncate >= 22 (full formatted output) Addresses code review findings from PR #406 first review. Generated with [Claude Code](https://claude.com/claude-code) Steered and verified by @nikblanchet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
vytx-eTZs)Changes
Core modules:
analyzer/src/utils/shortuuid.py- Python implementation (generate, encode, decode, format_display, is_valid)cli/src/utils/shortuuid.ts- TypeScript port with matching APItest-fixtures/shortuuid-vectors.json- Cross-language test vectorsValidation:
cli/src/utils/validation.ts- NewisValidShortUuid,isValidSessionId,formatSessionIdForDisplaycli/src/types/session-id.ts- Zod schema accepting both formatsSessionIdSchemaGeneration switched:
cli/src/commands/audit.tscli/src/session/interactive-session.tsDisplay formatting (19 points updated):
cli/src/session/interactive-session.tscli/src/commands/audit-sessions.tscli/src/commands/improve-sessions.tscli/src/commands/audit.tscli/src/commands/improve.tsTest plan
Generated with Claude Code
Steered and verified by @nikblanchet (Ten Forward regular)