Feature Spec: Cloud Drive Integration Model

Document ID: FS-2026-001 Owner: Product Manager Date: 2026-02-18 Status: Draft Product: Legionis V2V Phase: Phase 3 (Strategic Commitments) Related: PRD V3.0, DR-2026-002 (Cloud Storage First), Architecture Stack V1.4, Execution Plan V3.1


1. Overview

Legionis currently provides a Drive-backed workspace where agents read and write files within a dedicated folder structure. This feature expands the integration model so users can browse their entire Google Drive from within Legionis, drag files into the chat console to give agents context, and manage files anywhere in their Drive without leaving the platform. The single restriction: agents create new deliverables exclusively in the Legionis workspace folders. This turns Legionis from a workspace-scoped tool into a full Drive companion that respects the user's ownership of their files while maintaining a clean boundary for agent output.


2. Product Decision

The agreed model has four pillars:

  • Full Drive browsing. Users can navigate their entire Google Drive freely within Legionis. They are not restricted to workspace folders. The file explorer becomes a complete Drive browser.
  • Drag and drop. Users can drag files from anywhere in their Drive into the chat console to give agents context or instructions. This is the primary mechanism for sharing non-workspace files with agents.
  • Full file management. Users can move, rename, create folders, delete (trash), and organize files anywhere in their Drive from within Legionis. The platform is a capable file manager, not just a viewer.
  • Agent write boundary. Agents create new deliverables exclusively in the Legionis workspace folders ({workspace}/deliverables/ and {workspace}/context/). This is the only restriction on the entire integration model.
  • The principle: "The Drive is theirs, Legionis is a guest."

    This means: users have full sovereignty over their Drive. Legionis never restricts what they can see, touch, or organize. The platform only constrains where its own agents deposit work product, keeping the workspace clean and predictable.


    3. User Stories

    US-001: Browse Full Drive

    As a Legionis user I want to browse my entire Google Drive from within Legionis So that I can find and reference any file without switching to another tab

    Acceptance Criteria:

    US-002: Drag File into Chat

    As a user preparing instructions for an agent I want to drag a file from the file explorer into the chat input area So that the agent receives that file's content as context for my request

    Acceptance Criteria:

    US-003: Manage Files Across Drive

    As a user organizing my work I want to move, rename, and organize files anywhere in my Drive from within Legionis So that I can keep my Drive tidy without leaving the platform

    Acceptance Criteria:

    US-004: Agent Deliverable Goes to Workspace

    As a user who asked an agent to create a document I want the output to land in my Legionis workspace folder So that agent-generated work is organized and predictable

    Acceptance Criteria:

    US-005: Reference Non-Workspace File

    As a user giving an agent background material I want to attach a file from outside my workspace to the conversation So that the agent can use existing documents as context without me copying them into the workspace

    Acceptance Criteria:

    US-006: Quick Return to Workspace

    As a user who browsed deep into my Drive I want to return to the Legionis workspace view with one click So that I can quickly switch between Drive browsing and workspace focus

    Acceptance Criteria:

    US-007: Attach Multiple Files

    As a user preparing a complex request I want to attach multiple files from different Drive locations to a single message So that the agent has all the context it needs in one go

    Acceptance Criteria:

    US-008: Create Folder in Drive

    As a user organizing my Drive I want to create new folders anywhere in my Drive from within Legionis So that I can set up folder structures without switching apps

    Acceptance Criteria:


    4. UX Specification

    4.1 File Explorer (Updated)

    The file explorer component (file-tree.tsx) gains two modes controlled by a toggle at the top of the panel.

    Mode Toggle:

    Workspace View (default): Drive View: - Teal accent color on the folder icon and name - Small pin icon beside the folder name - Always sorted to the top of whatever parent it's in (regardless of alphabetical order) - Each breadcrumb segment is clickable for quick navigation up the tree State Persistence:

    4.2 Drag and Drop to Chat

    Drag Initiation:

    Drop Zone: - A subtle dashed border in the accent color (teal) - A brief label: "Drop to attach" that fades in - Background dims slightly to indicate the active drop zone Attached File Chips: - Icon matches file type (document icon for .md/.txt, PDF icon for .pdf, spreadsheet icon for .csv, etc.) - The x button removes the attachment Supported File Types:
    TypeExtension(s)Handling
    Markdown.mdRead as-is
    Plain text.txtRead as-is
    PDF.pdfExtract text via pdf-parse or server-side extraction
    Word.docxExtract text via mammoth or server-side extraction
    CSV.csvRead as-is (agents handle tabular text well)
    JSON.jsonRead as-is
    HTML.htmlStrip tags, extract text content
    Google Docapplication/vnd.google-apps.documentExport as text/plain via Drive API
    Google Sheetapplication/vnd.google-apps.spreadsheetExport as text/csv via Drive API
    Google Slidesapplication/vnd.google-apps.presentationExport as text/plain via Drive API

    Unsupported files:

    Agent Context Injection:
    [Attached: filename1.md]
    
    [/Attached]

    [Attached: filename2.pdf] [/Attached]

    4.3 File Management Actions

    Context Menu (Right-Click):

    In Drive view, right-clicking any file or folder surfaces a context menu with these actions:

    ActionApplies ToBehavior
    RenameFiles and foldersInline rename field appears. Press Enter to confirm, Escape to cancel.
    Move to...Files and foldersOpens a folder picker modal showing the Drive tree. Select destination, confirm.
    New FolderFolders onlyCreates a new subfolder. Inline name input appears inside the folder.
    Move to TrashFiles and foldersMoves to Google Drive trash. Confirmation dialog: "Move {name} to trash?"
    DownloadFiles onlyTriggers browser download. Google Workspace files export to their default format (Doc to .docx, Sheet to .xlsx).
    Open in Google DriveFiles and foldersOpens a new browser tab with the file's webViewLink
    Copy linkFiles and foldersCopies the Google Drive sharing link to clipboard

    Drag-to-Move within Explorer:

    Workspace Folder Protection:

    4.4 Chat Input Enhancement

    The chat message composer gains three new interaction points:

    Attachment Button:

    Drag-and-Drop Zone: Command Palette Integration: Keyboard Shortcut:

    5. Agent Runtime Implications

    5.1 Read Scope

    Agent read access follows an explicit-consent model:

    SourceAccess LevelMechanism
    Workspace filesAlways readableExisting readFile tool (workspace-scoped)
    User-attached filesReadable for the current conversationNew readAttachedFile tool
    Other Drive filesNever proactively accessibleAgents cannot browse or search the user's Drive

    Agents never proactively browse the user's Drive. They only access files the user explicitly provides through drag-and-drop or the attachment picker. This is the trust model: the user decides what context the agent receives.

    5.2 Write Boundary (THE RULE)

    This is the single hard constraint in the entire integration model:

    Agents can only write to the Legionis workspace.

    OperationScopeEnforcement
    Create new files{workspace}/deliverables/writeFile tool validates path prefix
    Save context entries{workspace}/context/*writeFile tool validates path prefix
    Edit existing workspace files{workspace}/**editFile tool validates path prefix
    Write anywhere else in DriveBlockedTool rejects with explanation message

    When a user asks an agent to save outside the workspace:

    The agent should:

  • Save the deliverable to {workspace}/deliverables/{filename}
  • Respond: "I've saved this to your workspace deliverables folder. You can move it to any Drive location from the file explorer."
  • This keeps agent behavior predictable while giving the user full control over final file placement.

    5.3 New Agent Tools

    readAttachedFile

    readAttachedFile({
      fileId: string  // Google Drive file ID of the attached file
    }): Promise
    

    Existing tools remain workspace-scoped:

    5.4 Attachment Lifecycle

    Attachments are scoped to the conversation turn in which they are sent:

  • User attaches files and sends a message
  • Server-side: file content is extracted and included in the agent's context window
  • The agent can reference this content in its response
  • Attachment metadata (file ID, name, size) is stored in the conversation turn record
  • In subsequent turns, the agent retains awareness of previously attached files (via conversation history) but does not re-fetch them unless the user attaches them again

  • 6. Technical Notes

    6.1 OAuth Scope Change

    The current OAuth configuration in src/lib/drive/auth.ts uses the drive.file scope:

    const SCOPES = ["https://www.googleapis.com/auth/drive.file"];
    

    The drive.file scope only grants access to files created by the application or explicitly opened by the user through the Google Picker. For full Drive browsing and file management, the scope needs to change.

    Options:

    ScopeAccessTrade-off
    drive.file (current)Only app-created filesInsufficient for browsing
    drive.readonlyFull read access, no write outside app filesInsufficient for file management
    driveFull read/write accessRequired for the full feature set

    Recommendation: Use https://www.googleapis.com/auth/drive (full access). This is necessary for: browsing all folders, reading user-selected files, moving/renaming files anywhere, and creating folders outside the workspace.

    Migration path for existing users: Users who already connected their Drive with drive.file will need to re-authorize. On first use of the Drive browser feature, detect the insufficient scope and prompt: "To browse your full Drive, we need to update your permissions. [Reconnect Google Drive]". This triggers a new OAuth flow with the broader scope.

    6.2 File Content Extraction

    For non-plaintext files, a server-side extraction layer is needed:

    FormatExtraction MethodPackage
    PDFpdf-parsepdf-parse
    DOCXmammothmammoth
    Google DocDrive API export (text/plain)Built-in
    Google SheetDrive API export (text/csv)Built-in
    Google SlidesDrive API export (text/plain)Built-in
    HTMLcheerio text extractioncheerio

    This extraction runs server-side in the API route before passing content to the agent runtime.

    6.3 File Size and Chunking

    Large files need handling before they reach the agent context window:

    6.4 API Routes (New)

    RouteMethodPurpose
    /api/drive/browseGETList contents of any Drive folder (by folder ID or "root")
    /api/drive/files/[id]/contentGETRead file content by Drive file ID (for attachments)
    /api/drive/files/[id]/movePATCHMove a file to a new parent folder
    /api/drive/files/[id]/renamePATCHRename a file
    /api/drive/files/[id]/trashPOSTMove a file to trash
    /api/drive/files/[id]/downloadGETDownload file content (triggers browser download)
    /api/drive/foldersPOSTCreate a new folder (already exists, may need update for arbitrary parents)
    /api/drive/files/[id]/exportGETExport Google Workspace file to text format

    Existing routes (/api/drive/files, /api/drive/files/content) remain for workspace-scoped operations.

    6.5 Caching and Performance


    7. Privacy and Trust

    This feature expands Legionis's access to the user's Drive. The trust contract must be explicit and verifiable.

    What Legionis does:

    What Legionis does not do: BYOT reinforcement: Onboarding disclosure: When the user first connects Google Drive (or re-authorizes for the broader scope), the consent screen includes:

    "Legionis can browse your Google Drive to help you find and organize files. We only read file contents when you explicitly share them with your agents. Your files stay in your Drive. Agent work products are saved to your Legionis workspace folder."

    Audit trail:


    8. Success Criteria

    CriterionMeasurementTarget
    Drive browsing worksUser can navigate full Drive tree, expand folders, see all files100% of Drive-connected users
    Drag-and-drop adoptionPercentage of conversations that include at least one attachment>30% within 60 days of launch
    Attachment accuracyAgent correctly references and uses attached file content>95% of attached files are usable
    Write boundary holdsZero agent writes outside workspace folder100% enforcement
    File management worksMove, rename, trash, create folder operations succeed>99% success rate
    No trust violationsNo user reports of unexpected file access or modificationZero incidents
    Scope migration smoothExisting users successfully re-authorize within one session>90% re-auth on first prompt
    Performance acceptableFolder listing loads in under 2 seconds for folders with up to 100 itemsP95 < 2s


    9. Out of Scope (v1)

    The following are explicitly deferred to future iterations:


    Appendix A: Current Implementation Reference

    Files that will be modified:

    FileChange
    src/lib/drive/auth.tsUpdate SCOPES from drive.file to drive
    src/components/explorer/file-tree.tsxAdd mode toggle, Drive view, breadcrumbs, context menu, drag source
    src/components/chat/ (new components)Drop zone, attachment chips, file picker modal
    src/app/api/drive/ (new routes)Browse, move, rename, trash, export, download endpoints
    src/tools/read-file.tsNo change (remains workspace-scoped)
    src/tools/ (new tool)read-attached-file.ts for conversation-scoped file reading
    src/lib/drive/drive-workspace.tsNo change to workspace boundary

    Files that remain unchanged:

    New dependencies:

    Appendix B: Drive API Scope Comparison

    ScopeList foldersRead any fileWrite to workspaceMove/rename any fileCreate folders anywhere
    drive.file (current)App-created onlyApp-created onlyYesApp-created onlyApp-created only
    drive.readonlyAllAllNoNoNo
    drive (recommended)AllAllYesYesYes

    The drive scope is the only option that supports the full feature set. The trust contract (Section 7) and audit trail mitigate the broader access.