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
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.
The agreed model has four pillars:
{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.
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:
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:
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:
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:
{workspace}/deliverables/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:
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:
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:
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:
The file explorer component (file-tree.tsx) gains two modes controlled by a toggle at the top of the panel.
Mode Toggle:
[Workspace] [Drive]/My Drive / Projects / Q1 ReportsDrag Initiation:
[icon] filename.ext [x]x button removes the attachment
| Type | Extension(s) | Handling |
|---|---|---|
| Markdown | .md | Read as-is |
| Plain text | .txt | Read as-is |
| Extract text via pdf-parse or server-side extraction | ||
| Word | .docx | Extract text via mammoth or server-side extraction |
| CSV | .csv | Read as-is (agents handle tabular text well) |
| JSON | .json | Read as-is |
| HTML | .html | Strip tags, extract text content |
| Google Doc | application/vnd.google-apps.document | Export as text/plain via Drive API |
| Google Sheet | application/vnd.google-apps.spreadsheet | Export as text/csv via Drive API |
| Google Slides | application/vnd.google-apps.presentation | Export as text/plain via Drive API |
Unsupported files:
[Truncated: showing first 500KB of {filename}][Attached: filename1.md]
[/Attached][Attached: filename2.pdf]
[/Attached]
Context Menu (Right-Click):
In Drive view, right-clicking any file or folder surfaces a context menu with these actions:
| Action | Applies To | Behavior |
|---|---|---|
| Rename | Files and folders | Inline rename field appears. Press Enter to confirm, Escape to cancel. |
| Move to... | Files and folders | Opens a folder picker modal showing the Drive tree. Select destination, confirm. |
| New Folder | Folders only | Creates a new subfolder. Inline name input appears inside the folder. |
| Move to Trash | Files and folders | Moves to Google Drive trash. Confirmation dialog: "Move {name} to trash?" |
| Download | Files only | Triggers browser download. Google Workspace files export to their default format (Doc to .docx, Sheet to .xlsx). |
| Open in Google Drive | Files and folders | Opens a new browser tab with the file's webViewLink |
| Copy link | Files and folders | Copies the Google Drive sharing link to clipboard |
Drag-to-Move within Explorer:
files.update to change the parentThe chat message composer gains three new interaction points:
Attachment Button:
[paperclip][2]Cmd+K (or Ctrl+K) opens the command paletteCmd+Shift+A (or Ctrl+Shift+A) opens the Drive file picker directlyAgent read access follows an explicit-consent model:
| Source | Access Level | Mechanism |
|---|---|---|
| Workspace files | Always readable | Existing readFile tool (workspace-scoped) |
| User-attached files | Readable for the current conversation | New readAttachedFile tool |
| Other Drive files | Never proactively accessible | Agents 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.
This is the single hard constraint in the entire integration model:
Agents can only write to the Legionis workspace.
| Operation | Scope | Enforcement |
|---|---|---|
| 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 Drive | Blocked | Tool rejects with explanation message |
When a user asks an agent to save outside the workspace:
The agent should:
{workspace}/deliverables/{filename}This keeps agent behavior predictable while giving the user full control over final file placement.
readAttachedFile
readAttachedFile({
fileId: string // Google Drive file ID of the attached file
}): Promise
readFile(path) resolves paths relative to workspace root (unchanged)writeFile(path, content) writes within workspace only (unchanged, boundary enforced)editFile(path, oldText, newText) edits within workspace only (unchanged)listDirectory(path) lists workspace directories (unchanged)globFiles(pattern) searches workspace files (unchanged)grepContent(pattern) searches workspace file contents (unchanged)Attachments are scoped to the conversation turn in which they are sent:
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:
| Scope | Access | Trade-off |
|---|---|---|
drive.file (current) | Only app-created files | Insufficient for browsing |
drive.readonly | Full read access, no write outside app files | Insufficient for file management |
drive | Full read/write access | Required 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.
For non-plaintext files, a server-side extraction layer is needed:
| Format | Extraction Method | Package |
|---|---|---|
| pdf-parse | pdf-parse | |
| DOCX | mammoth | mammoth |
| Google Doc | Drive API export (text/plain) | Built-in |
| Google Sheet | Drive API export (text/csv) | Built-in |
| Google Slides | Drive API export (text/plain) | Built-in |
| HTML | cheerio text extraction | cheerio |
This extraction runs server-side in the API route before passing content to the agent runtime.
Large files need handling before they reach the agent context window:
[Truncated: showing first ~500KB of {N}KB file]| Route | Method | Purpose |
|---|---|---|
/api/drive/browse | GET | List contents of any Drive folder (by folder ID or "root") |
/api/drive/files/[id]/content | GET | Read file content by Drive file ID (for attachments) |
/api/drive/files/[id]/move | PATCH | Move a file to a new parent folder |
/api/drive/files/[id]/rename | PATCH | Rename a file |
/api/drive/files/[id]/trash | POST | Move a file to trash |
/api/drive/files/[id]/download | GET | Download file content (triggers browser download) |
/api/drive/folders | POST | Create a new folder (already exists, may need update for arbitrary parents) |
/api/drive/files/[id]/export | GET | Export Google Workspace file to text format |
Existing routes (/api/drive/files, /api/drive/files/content) remain for workspace-scoped operations.
This feature expands Legionis's access to the user's Drive. The trust contract must be explicit and verifiable.
What Legionis does:
"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:
| Criterion | Measurement | Target |
|---|---|---|
| Drive browsing works | User can navigate full Drive tree, expand folders, see all files | 100% of Drive-connected users |
| Drag-and-drop adoption | Percentage of conversations that include at least one attachment | >30% within 60 days of launch |
| Attachment accuracy | Agent correctly references and uses attached file content | >95% of attached files are usable |
| Write boundary holds | Zero agent writes outside workspace folder | 100% enforcement |
| File management works | Move, rename, trash, create folder operations succeed | >99% success rate |
| No trust violations | No user reports of unexpected file access or modification | Zero incidents |
| Scope migration smooth | Existing users successfully re-authorize within one session | >90% re-auth on first prompt |
| Performance acceptable | Folder listing loads in under 2 seconds for folders with up to 100 items | P95 < 2s |
The following are explicitly deferred to future iterations:
file-preview.tsx.Files that will be modified:
| File | Change |
|---|---|
src/lib/drive/auth.ts | Update SCOPES from drive.file to drive |
src/components/explorer/file-tree.tsx | Add 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.ts | No change (remains workspace-scoped) |
src/tools/ (new tool) | read-attached-file.ts for conversation-scoped file reading |
src/lib/drive/drive-workspace.ts | No change to workspace boundary |
Files that remain unchanged:
src/lib/drive/client.ts (Drive client factory, already handles arbitrary operations)src/lib/drive/path-resolver.ts (workspace path resolution, still needed for workspace tools)src/lib/drive/workspace-init.ts (workspace folder creation, still needed for onboarding)src/tools/write-file.ts (workspace-scoped write, boundary already enforced)src/tools/edit-file.ts (workspace-scoped edit, boundary already enforced)pdf-parse (PDF text extraction)mammoth (DOCX text extraction)cheerio (HTML text extraction)| Scope | List folders | Read any file | Write to workspace | Move/rename any file | Create folders anywhere |
|---|---|---|---|---|---|
drive.file (current) | App-created only | App-created only | Yes | App-created only | App-created only |
drive.readonly | All | All | No | No | No |
drive (recommended) | All | All | Yes | Yes | Yes |
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.