Skip to content

feat(platform): add document_list agent tool#713

Merged
larryro merged 13 commits into
mainfrom
feat/658-document-list-agent-tool
Mar 7, 2026
Merged

feat(platform): add document_list agent tool#713
larryro merged 13 commits into
mainfrom
feat/658-document-list-agent-tool

Conversation

@larryro
Copy link
Copy Markdown
Collaborator

@larryro larryro commented Mar 7, 2026

Summary

  • Add a new document_list agent tool that allows AI agents to browse and list documents by team, folder, date range, and search query with offset-based pagination
  • Implement list_documents_for_agent Convex query with robust validation, case-insensitive sorting, breadcrumb paths, and structured warnings for unauthorized teams or missing folders
  • Categorize the new tool under "Documents" in the tool selector UI

Test plan

  • Unit tests for document_list_tool (parameter validation, pagination, formatting)
  • Comprehensive tests for list_documents_for_agent (filtering, sorting, edge cases, authorization, date validation)
  • Verify tool appears in the Documents category in the agent tool selector
  • End-to-end test: configure an agent with document_list and confirm it can list documents

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added document listing tool with filtering capabilities (folder path, extension, date range, team, text search).
    • Support for sorting by creation date or name.
    • Cursor-based pagination with configurable result limits.
  • Tests

    • Added comprehensive test coverage for document listing, filtering, sorting, pagination, and access control validation.

Copy link
Copy Markdown

@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.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

larryro added 13 commits March 7, 2026 18:34
Add a new document_list tool that allows the AI agent to browse,
filter, and paginate through documents in the knowledge base.

Supports filtering by folder path, file extension, team, date range,
and title search. Includes cursor-based pagination, configurable
sorting, and team-based access control.

Refs #658
- Fix cursor pagination bug when sorting by name (restrict cursor to
  createdAt sort only since cursor is timestamp-based)
- Fix dateTo end-of-day: add 24h-1ms so documents created during the
  target day are included
- Simplify extension filter (merge two identical branches into one)
- Simplify extractSize (remove redundant isRecord check)
- Deduplicate types (re-export from canonical source)
- Simplify internal query handler using spread

Refs #658
…rden edge cases

Replace timestamp-based cursor with offset-based pagination to fix
duplicate-skipping issues with identical createdAt values. Add _id
tiebreaker for deterministic sort, validate date format with regex,
fix date/folder filters for edge cases (0, NaN, "/"), and use null
instead of -1 for unknown totalCount.
Validate dates (reject invalid YYYY-MM-DD), cursor (non-negative int), and extension (no leading dot) at the schema level. Surface a warning field when the scan limit is hit so agents know to narrow filters. Clamp negative cursors, isolate folder-path resolution errors, and add comprehensive tests for all new behaviors.
Add metadata.name fallback for document titles, auto-strip leading dots
from extension filter, return early with warning when dateFrom > dateTo,
and improve scan limit warning messages with match counts.
…ve sort

- Extract shared getDocumentTitle() to eliminate 3x duplicated title
  resolution with inconsistent fallbacks (sort used '', display used
  'Untitled')
- Make name sort case-insensitive with precomputed lowercase keys for
  performance
- Title search now uses getDocumentTitle, making "untitled" searchable
  for docs without titles (matches displayed value)
…and breadcrumb errors

- Return descriptive warning when teamId filter is not in user's teams (H3)
- Return warning with case-sensitivity hint when folder path not found (H4)
- Add console.warn when buildBreadcrumb fails for orphaned folders (M4)
- Update folderPath description to note case-sensitive exact match
- Reject empty extension and teamId with .min(1)
- Auto-normalize extension to lowercase
- Add .max(500) on folderPath, .max(200) on query
- Update extension description to reflect auto-normalization
Add round-trip validation in toTimestamp() to catch dates like 2026-02-30
that silently roll over to the next month.
…esult directly

Delete single-line re-export file and update consumers to import from
the source module.
…mment

- Add .int().min(1).max(50) on limit for better LLM error feedback
- Add comment documenting buildQuery index selection priority
@larryro larryro force-pushed the feat/658-document-list-agent-tool branch from 091ed97 to b2baf5f Compare March 7, 2026 10:34
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 7, 2026

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

The PR implements a new document_list agent tool. It adds a Zod-based argument schema supporting filters (folderPath, extension, dateFrom, dateTo, query, teamId), sorting (by createdAt or name), and pagination (limit, cursor). The tool is registered in the agent tools registry and listed in the UI tool selector. The implementation chain includes a public listDocuments helper that validates inputs and invokes an internal Convex query listForAgent, which retrieves user team IDs and delegates to listDocumentsForAgentHelper for document retrieval with access control, folder path resolution, filtering, sorting, and cursor-based pagination. Comprehensive test suites cover argument validation, helper behavior, and end-to-end listing scenarios including filtering, sorting, pagination, and edge cases.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related issues

Possibly related PRs

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 9.09% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title 'feat(platform): add document_list agent tool' accurately and clearly describes the main change: adding a new document_list agent tool to enable AI agents to browse and list documents.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/658-document-list-agent-tool

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

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant