Skip to content

feat(copilot): add share_file tool + surface file share state to the agent#5656

Merged
TheodoreSpeaks merged 1 commit into
stagingfrom
feat/share-file-mothership
Jul 20, 2026
Merged

feat(copilot): add share_file tool + surface file share state to the agent#5656
TheodoreSpeaks merged 1 commit into
stagingfrom
feat/share-file-mothership

Conversation

@TheodoreSpeaks

@TheodoreSpeaks TheodoreSpeaks commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Add the sim-side share_file server tool handler: resolves a VFS path to the file, keeps the existing checks (org public-sharing policy, write/admin permission, ShareValidationError, and the FILE_SHARED/FILE_SHARE_DISABLED audit), then delegates to the shared upsertFileShare — same path the files UI uses
  • Register it in the server tool router (+ generated catalog entries)
  • Surface an ambient shared/shareAuthType flag on each file's metadata via one batched share lookup (no N+1), so the agent can see and grep what's shared — mirrors how workflows expose isDeployed

Pairs with

Type of Change

  • New feature

Testing

  • tsc --noEmit 0 errors; bun run lint:check and check:api-validation:strict pass; biome clean

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

Companion: simstudioai/mothership#353

@vercel

vercel Bot commented Jul 14, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Jul 20, 2026 5:53pm

Request Review

@cursor

cursor Bot commented Jul 14, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Touches public file sharing and access-control validation; the effectiveAuthType fix is security-relevant, while the new tool reuses existing share paths with write permission gates.

Overview
Adds a share_file copilot server tool so the agent can share or unshare workspace files by VFS path, using the same upsertFileShare flow as the files UI (write access, org sharing policy, validation, audit).

API hardening: When re-enabling a share without passing authType, the workspace file share PUT route now validates against the effective auth mode (authType ?? existingShare?.authType ?? 'public') instead of assuming public, so a restricted share cannot be reactivated after policy changes.

Agent visibility: Workspace VFS file metadata gains batched shared, shareAuthType, and shareUrl (soft-fail if share lookup errors). Generated tool catalog/schemas, router registration, and UI titles for share/unshare are included.

Reviewed by Cursor Bugbot for commit 2b09aff. Bugbot is set up for automated code reviews on this repo. Configure here.

@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator Author

@greptile review

Comment thread apps/sim/lib/copilot/tools/server/files/share-file.ts
@greptile-apps

greptile-apps Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds Copilot support for sharing workspace files. The main changes are:

  • Adds the share_file server tool and router registration.
  • Adds generated catalog and runtime schema entries for the new tool.
  • Reuses the existing file-share policy checks and share upsert path.
  • Adds shared-state fields to file metadata in the workspace VFS.
  • Adds a soft fallback when share metadata lookup fails.

Confidence Score: 5/5

This looks safe to merge.

  • No blocking issues found in the changed code.

Important Files Changed

Filename Overview
apps/sim/lib/copilot/tools/server/files/share-file.ts Adds the Copilot share_file handler with workspace access checks, share policy validation, share upsert handling, and audit logging.
apps/sim/app/api/workspaces/[id]/files/[fileId]/share/route.ts Updates file-share validation to check the auth type that will be persisted when a share is enabled.
apps/sim/lib/copilot/vfs/workspace-vfs.ts Adds batched share-state lookup for file metadata with a local fallback when that lookup fails.
apps/sim/lib/copilot/vfs/serializers.ts Extends serialized file metadata with share state, auth type, and share URL fields.
apps/sim/lib/copilot/tools/server/router.ts Registers share_file as a write-capable server tool.
apps/sim/lib/copilot/generated/tool-catalog-v1.ts Adds the generated catalog entry for share_file.
apps/sim/lib/copilot/generated/tool-schemas-v1.ts Adds the generated runtime schema for share_file.
apps/sim/lib/copilot/tools/tool-display.ts Adds display text for share and unshare tool runs.

Reviews (8): Last reviewed commit: "feat(copilot): add share_file tool handl..." | Re-trigger Greptile

Comment thread apps/sim/lib/copilot/tools/server/files/share-file.ts Outdated
Comment thread apps/sim/lib/copilot/vfs/workspace-vfs.ts Outdated
@greptile-apps

greptile-apps Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds Copilot support for sharing workspace files. The main changes are:

  • New share_file server tool and router registration.
  • Generated tool catalog and runtime schema entries.
  • File VFS metadata now includes shared and shareAuthType.
  • Workspace file materialization now batches share-state lookups.

Confidence Score: 4/5

The share tool and VFS enrichment paths need fixes before merging.

  • Re-sharing without authType can reactivate an old share mode after validating a different one.
  • A share-state lookup failure can make the Copilot VFS return no files.
  • The generated catalog and router wiring otherwise match the new tool shape.

apps/sim/lib/copilot/tools/server/files/share-file.ts; apps/sim/lib/copilot/vfs/workspace-vfs.ts

Security Review

The new share tool can reactivate an existing non-public share mode after validating the request as public when authType is omitted.

Important Files Changed

Filename Overview
apps/sim/lib/copilot/tools/server/files/share-file.ts Adds the new share/unshare server tool; the omitted-auth path can validate a different share mode than the one that is reactivated.
apps/sim/lib/copilot/tools/server/router.ts Registers share_file as a write-capable server tool.
apps/sim/lib/copilot/generated/tool-catalog-v1.ts Adds the generated catalog entry for the new Copilot file-sharing tool.
apps/sim/lib/copilot/generated/tool-schemas-v1.ts Adds the generated runtime parameter and result schema for share_file.
apps/sim/lib/copilot/vfs/serializers.ts Adds optional share-state fields to serialized file metadata.
apps/sim/lib/copilot/vfs/workspace-vfs.ts Adds batched share-state enrichment during file materialization; the new lookup can currently hide all files if it fails.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
  participant Agent as Copilot agent
  participant Router as Server tool router
  participant Tool as share_file tool
  participant Policy as Share policy check
  participant Shares as Share manager
  participant VFS as Workspace VFS

  Agent->>Router: share_file(path, action, authType?)
  Router->>Tool: execute with workspace context
  Tool->>Policy: validate requested share mode
  Tool->>Shares: create, update, or disable file share
  Shares-->>Tool: share state
  Tool-->>Agent: success message and share data

  VFS->>Shares: batch lookup file share states
  Shares-->>VFS: share map by file id
  VFS-->>Agent: file metadata with shared/shareAuthType
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
  participant Agent as Copilot agent
  participant Router as Server tool router
  participant Tool as share_file tool
  participant Policy as Share policy check
  participant Shares as Share manager
  participant VFS as Workspace VFS

  Agent->>Router: share_file(path, action, authType?)
  Router->>Tool: execute with workspace context
  Tool->>Policy: validate requested share mode
  Tool->>Shares: create, update, or disable file share
  Shares-->>Tool: share state
  Tool-->>Agent: success message and share data

  VFS->>Shares: batch lookup file share states
  Shares-->>VFS: share map by file id
  VFS-->>Agent: file metadata with shared/shareAuthType
Loading

Reviews (1): Last reviewed commit: "feat(copilot): add share_file tool handl..." | Re-trigger Greptile

Comment thread apps/sim/lib/copilot/tools/server/files/share-file.ts Outdated
Comment thread apps/sim/lib/copilot/vfs/workspace-vfs.ts Outdated
@github-actions github-actions Bot added the requires-mothership-merge Has a companion PR on the mothership/copilot side — merge in lockstep label Jul 14, 2026
@github-actions

Copy link
Copy Markdown

⚠️ Cross-repo companion check

One or more companion PRs aren't merged into staging yet. Merging this without them will leave copilot and sim out of sync — merge them in lockstep.

  • simstudioai/mothership#353OPEN, not merged (targets staging) — feat(file-agent): add share_file tool and route file-sharing to the file agent

@TheodoreSpeaks
TheodoreSpeaks force-pushed the feat/share-file-mothership branch from 472a037 to 1673192 Compare July 14, 2026 00:43
@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator Author

@greptile review

Addressed the auth-type validation finding: share_file (and the share PUT route) now resolve the effective authType (authType ?? existingShare.authType ?? 'public') before calling validatePublicFileSharing, so a bare re-enable can no longer reactivate a now-disallowed password/email/sso share.

Comment thread apps/sim/lib/copilot/vfs/workspace-vfs.ts Outdated
@TheodoreSpeaks
TheodoreSpeaks force-pushed the feat/share-file-mothership branch from 1673192 to 1d76a7e Compare July 14, 2026 01:13
@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator Author

@greptile review

Addressed both findings:

  1. Auth-type bypass (P1)share_file and the share PUT route now validate the effective authType (authType ?? existingShare.authType ?? 'public') before validatePublicFileSharing, so a bare re-enable can't reactivate a now-disallowed password/email/sso share.
  2. Share lookup hides files (P1) — the getSharesForResources enrichment in workspace-vfs.ts now fails soft (its own try/catch → empty share map), so a transient share-query failure degrades to shared: false instead of dropping the whole file tree.

@TheodoreSpeaks
TheodoreSpeaks force-pushed the feat/share-file-mothership branch from 1d76a7e to 9e1e71a Compare July 14, 2026 04:25
@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator Author

@greptile review

Added shareUrl to file metadata (alongside shared/shareAuthType) so the agent can read an already-shared file's public link directly, without re-sharing. Sourced from the same batched getSharesForResources lookup — no extra query; only present when shared is true.

Comment thread apps/sim/lib/copilot/tools/server/files/share-file.ts
@TheodoreSpeaks
TheodoreSpeaks force-pushed the feat/share-file-mothership branch from 9e1e71a to aa55758 Compare July 20, 2026 17:18
@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator Author

@greptile review

Rebased onto latest staging and resolved conflicts (staging's rename_filemv / folder-tool refactor). Regenerated the tool catalog from the rebased copilot branch; kept staging's updatedAt field alongside the share metadata. No logic changes.

@TheodoreSpeaks
TheodoreSpeaks force-pushed the feat/share-file-mothership branch from aa55758 to b84e758 Compare July 20, 2026 17:47
@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator Author

@greptile

@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator Author

@cursor review

Comment thread apps/sim/lib/copilot/tools/server/files/share-file.ts
…te to the agent

Implement the sim-side share_file server tool (resolves VFS path to file,
keeps the existing org-policy + permission + audit checks, delegates to
upsertFileShare). Register it in the tool router and generated catalog.
Stamp an ambient 'shared'/'shareAuthType' flag onto file metadata via one
batched share lookup, mirroring how workflows expose 'isDeployed'.

Validate the EFFECTIVE auth type when re-enabling a share: upsertFileShare
preserves an existing share's authType when none is passed, so validate the
stored mode (not 'public') or a re-share could reactivate a now-disallowed
password/email/sso share. Same fix applied to the share PUT route.
@TheodoreSpeaks
TheodoreSpeaks force-pushed the feat/share-file-mothership branch from b84e758 to 2b09aff Compare July 20, 2026 17:53
@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator Author

@greptile

@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator Author

@cursor review

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 2b09aff. Configure here.

@TheodoreSpeaks
TheodoreSpeaks merged commit 58c87b2 into staging Jul 20, 2026
20 checks passed
@TheodoreSpeaks
TheodoreSpeaks deleted the feat/share-file-mothership branch July 20, 2026 17:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

requires-mothership-merge Has a companion PR on the mothership/copilot side — merge in lockstep

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant