diff --git a/doc/connections/GOOGLE-WORKSPACE-SERVICE-CONSENT.md b/doc/connections/GOOGLE-WORKSPACE-SERVICE-CONSENT.md index 972e72783b8..4bed012b925 100644 --- a/doc/connections/GOOGLE-WORKSPACE-SERVICE-CONSENT.md +++ b/doc/connections/GOOGLE-WORKSPACE-SERVICE-CONSENT.md @@ -18,7 +18,10 @@ consent preview → Production picker**. Storybook callbacks do not grant access The `workspaceServices` input accepts only nonempty combinations of `gmail`, `drive`, and `calendar`, each `read` or `write`. The server derives exact scopes -from the shared closed registry. Default write access requests nine scopes. +from the shared closed registry. Default write access requests ten scopes. +Read & write Calendar adds `calendar.events.freebusy` to the per-service +`calendar.write` profile's two scopes, so free/busy lookups work over REST. +Grants made before that change still count as read & write Calendar. Drive file creation is limited to app-opened/app-created files; Docs, Sheets, and Slides have their respective editor scopes. Gmail uses `gmail.compose` for draft creation; Google permits sending under that scope, but Paperclip's diff --git a/doc/connections/GOOGLE-WORKSPACE.md b/doc/connections/GOOGLE-WORKSPACE.md index 5ad30f70b3a..513432004ed 100644 --- a/doc/connections/GOOGLE-WORKSPACE.md +++ b/doc/connections/GOOGLE-WORKSPACE.md @@ -16,7 +16,7 @@ Turn the setting on in **Settings → Experimental** to test the built-in connec The combined connection has one credential grant, capability catalog, policy profile, audit trail and reconnect lifecycle. It requests only the selected -groups' scopes (nine scopes for the default selection), not the legacy full +groups' scopes (ten scopes for the default selection), not the legacy full union. Google's consent screen also lets users decline permissions; discovery skips services without grants and excludes unsupported actions. The gateway checks actual grant scopes again before each call, including @@ -299,9 +299,15 @@ Docs, Sheets, and Slides request only their service's read-only scope in the read profile and its read/write scope in the write profile. They do not also request `drive.readonly` or `drive.file`: those are authorization alternatives, not additional requirements. Drive and Workspace Search retain their separate -Drive permissions. Calendar write requests `calendar.calendarlist.readonly` -and `calendar.events`; the latter also authorizes `suggest_time`. Calendar read -retains `calendar.events.freebusy` alongside list/event read-only access. +Drive permissions. The per-service Calendar write profile requests +`calendar.calendarlist.readonly` and `calendar.events`; Google's MCP +`suggest_time` accepts `calendar.events`. Calendar read retains +`calendar.events.freebusy` alongside list/event read-only access. The combined +connection's read & write Calendar selection also requests +`calendar.events.freebusy` (2026-11-17), because Google's REST +[`freeBusy.query`](https://developers.google.com/workspace/calendar/api/v3/reference/freebusy/query) +does not accept `calendar.events`. The per-service profile keeps its exact +scope set for the Cloud broker. References: Google's [Docs read](https://developers.google.com/workspace/docs/api/reference/mcp/tools_list/read_doc) and [update](https://developers.google.com/workspace/docs/api/reference/mcp/tools_list/update_doc), diff --git a/doc/connections/tool-method-permission-reviews.json b/doc/connections/tool-method-permission-reviews.json index 9aff2b163af..75b94d1e025 100644 --- a/doc/connections/tool-method-permission-reviews.json +++ b/doc/connections/tool-method-permission-reviews.json @@ -24,7 +24,7 @@ "https://www.googleapis.com/auth/calendar.events" ], "capability": "write", - "supportedActions": "One grant for selected Gmail, Drive (Docs, Sheets, Slides), and Calendar services. The list is the read/write selection allowlist, not the default request; default write selections request nine scopes. Chat, People, and Search are excluded. Gmail sending remains unsupported.", + "supportedActions": "One grant for selected Gmail, Drive (Docs, Sheets, Slides), and Calendar services. The list is the read/write selection allowlist, not the default request; default write selections request ten scopes. Chat, People, and Search are excluded. Gmail sending remains unsupported.", "evidence": [ "https://developers.google.com/workspace/guides/configure-mcp-servers", "https://developers.google.com/identity/protocols/oauth2/resources/granular-permissions" @@ -54,7 +54,7 @@ "https://www.googleapis.com/auth/calendar.events" ], "capability": "write", - "supportedActions": "One grant for selected Gmail, Drive (Docs, Sheets, Slides), and Calendar services. The list is the read/write selection allowlist, not the default request; default write selections request nine scopes. Chat, People, and Search are excluded. Gmail sending remains unsupported.", + "supportedActions": "One grant for selected Gmail, Drive (Docs, Sheets, Slides), and Calendar services. The list is the read/write selection allowlist, not the default request; default write selections request ten scopes. Chat, People, and Search are excluded. Gmail sending remains unsupported.", "evidence": [ "https://developers.google.com/workspace/guides/configure-mcp-servers", "https://developers.google.com/identity/protocols/oauth2/resources/granular-permissions" diff --git a/doc/memory/google-connector-memory.md b/doc/memory/google-connector-memory.md index 20910c7dfee..ae5684512b3 100644 --- a/doc/memory/google-connector-memory.md +++ b/doc/memory/google-connector-memory.md @@ -12,7 +12,7 @@ Related: [production checklist](../plans/2026-11-17-google-workspace-production- [code-fix plan](../plans/2026-11-17-google-workspace-code-fixes.md), [connector doc](../connections/GOOGLE-WORKSPACE.md). -Last updated: November 17, 2026 (evening). +Last updated: November 17, 2026 (late evening). ## Decisions @@ -28,6 +28,10 @@ Last updated: November 17, 2026 (evening). | Nov 17 | **Scope handling contract** | What we **request** is strict: a request with a scope outside the 14 is rejected. What Google **reports** on a saved grant is capped to the 14 and to the saved selection, and the grant keeps working. Only a grant with nothing inside the 14 (or no scope evidence at all) needs reconnecting. | | Nov 17 | **Assessment prep starts before Google asks** | Run the scans and fix findings now; the formal assessment starts on Google's notice. | | Nov 17 | **Agents that prepare PRs merge them** | On the coordinator's approval, once required checks pass and Greptile is 5/5. | +| Nov 17 | **Merges are gated on green CI and Greptile 5/5 only** | Not on the ponytail review bot. | +| Nov 17 | **`delete_event` never deletes a whole recurring series in this release** | A series ID is refused; the agent must pass one occurrence's ID. | +| Nov 17 | **A health probe may only use a request the granted scopes permit** | Each service lists cheap reads with the scopes that allow each; the probe uses the first one the grant allows. | +| Nov 17 | **Read & write Calendar also requests free/busy** | See "Scopes". | ## What has shipped @@ -38,22 +42,50 @@ Last updated: November 17, 2026 (evening). | [#21999](https://github.com/paperclipai/paperclip/pull/21999) | Prompt-injection screening now also covers resource reads through a named gateway, the one path that was not screened. Applies to every connector, not only Google. | `65eac24876` | | [#22001](https://github.com/paperclipai/paperclip/pull/22001) | Scope lock. `GOOGLE_WORKSPACE_SUBMITTED_SCOPES` is the hand-written list of 14, and `workspace.all` uses it. Paperclip-managed Google methods outside the 14 (Gmail archive, Chat, People, Workspace Search) are no longer offered for new setup or reconnect through Paperclip's Google app; saved ones keep refreshing and running. | `66ac5d7aa0` | | [#22000](https://github.com/paperclipai/paperclip/pull/22000) | REST tool set part 1: the folder `server/src/google-workspace-rest-tools/` with Gmail `get_message`, `search_threads` and `create_draft`. Nothing calls it yet; the switch comes in a later PR. | `a29658b5b7` | +| [#22010](https://github.com/paperclipai/paperclip/pull/22010) | Users can delete the data Paperclip stored from a connection's tool calls: "Delete data" on the connection's page, or a checkbox when removing it. Live for every connector, not only Google. Help page: `docs/guides/board-operator/deleting-connection-data.md`. | `d1b5cfe038` | +| [#22017](https://github.com/paperclipai/paperclip/pull/22017) | Nine Calendar tools in the REST tool set (Calendar 9 of 9). | `c41ca4a992` | +| [#22016](https://github.com/paperclipai/paperclip/pull/22016) | Per-service transport switch (`GOOGLE_WORKSPACE_TOOL_TRANSPORT`) and in-process dispatch to the REST tools. Every service is still on Google's MCP. Discovery and health run a scope-aware probe for a service on REST. | `c652c813bc` | +| [#22014](https://github.com/paperclipai/paperclip/pull/22014) | The remaining six Gmail read tools in the REST tool set (Gmail 9 of 9). | `1d3b4201e3` | + +In progress: the Drive, Docs and Slides, and Sheets REST tools. + +### REST tools status + +| Service | Implemented | Switched on | +| --- | --- | --- | +| Gmail | 9 of 9 | No | +| Calendar | 9 of 9 | No | +| Drive | 0 of 8 | No | +| Docs | 0 of 2 | No | +| Sheets | 0 of 6 | No | +| Slides | 0 of 2 | No | + +"Switched on" means the service is `paperclip_rest` in +`GOOGLE_WORKSPACE_TOOL_TRANSPORT`. Today every service is `google_mcp`. ## Still open - **What we send to the reviewers.** Not decided: the new staging tester or something else. Whatever it is must use the separate Google app (below). -- **How reviewers reach the separate Google app.** The broker cannot point one - workspace at a different Google client (see "Environments"). - Recommendation: add a per-workspace client override to the broker so - reviewers see the real flow. +- **How the staging tester reaches the separate Google app.** The broker + cannot point one workspace at a different Google client (see + "Environments"). Recommendation: add a per-workspace client override to the + broker so reviewers see the real flow. - **Reviewer login on staging.** The scoped reviewer password login is hard-coded to the production tester. The client override above does not fix this; how to enable the login on staging is still undecided. -- **Privacy policy edits** (see "Privacy policy" below). +- **AI-agent client and REST.** Whether an OAuth client marked for AI agents + may call the REST APIs rather than MCP. To check before the staging tester is + wired. +- **Three Gmail tools are inferred.** Google's MCP reference does not list + `get_draft`, `list_threads` and `search_messages`; their schemas copy the + sibling tools (#22014). +- **Privacy policy.** paperclipai/paperclip-website PR 197 is a draft waiting + on Dotta's sign-off. It does not yet mention the OpenRouter model used by + the optional injection-screening check; it must (see "Privacy policy"). +- **The "no review correspondence" rule.** Narrow it or keep it (see "Google + review history"). - Which security lab to use, and the budget. -- Whether Google accepts the AI-agent client setting on a client that calls - the REST APIs rather than MCP. To check before the staging tester is wired. ## Environments @@ -102,7 +134,7 @@ channel. This is the one copy of the scope table. Other docs link here. -One connection, three groups, **14 scopes** across all modes (9 for the +One connection, three groups, **14 scopes** across all modes (10 for the default all-read-and-write selection, 8 for all read-only). Prefix: `https://www.googleapis.com/auth/`. In code the list is `GOOGLE_WORKSPACE_SUBMITTED_SCOPES` in @@ -112,7 +144,7 @@ default all-read-and-write selection, 8 for all read-only). Prefix: | --- | --- | --- | | Gmail | `gmail.readonly` | `gmail.readonly`, `gmail.compose` | | Drive, Docs, Sheets, Slides | `drive.readonly`, `documents.readonly`, `spreadsheets.readonly`, `presentations.readonly` | `drive.readonly`, `drive.file`, `documents`, `spreadsheets`, `presentations` | -| Calendar | `calendar.calendarlist.readonly`, `calendar.events.readonly`, `calendar.events.freebusy` | `calendar.calendarlist.readonly`, `calendar.events` | +| Calendar | `calendar.calendarlist.readonly`, `calendar.events.readonly`, `calendar.events.freebusy` | `calendar.calendarlist.readonly`, `calendar.events`, `calendar.events.freebusy` | - **Restricted (trigger the security assessment):** `gmail.readonly`, `gmail.compose`, `drive.readonly`. @@ -120,6 +152,18 @@ default all-read-and-write selection, 8 for all read-only). Prefix: our tool list has no send action. Never say the scope itself prevents sending. - **Out of scope:** Chat, Contacts, Directory, cross-service Search. Not in the picker, the request, the tools, the docs or the submission. +- **Read & write Calendar asks for free/busy** (Nov 17, [#22026](https://github.com/paperclipai/paperclip/pull/22026)). Google's + REST `freeBusy.query` accepts only `calendar.readonly`, `calendar`, + `calendar.events.freebusy` and `calendar.freebusy`, not `calendar.events` + (). + Google's MCP `suggest_time` does accept `calendar.events`. So read & write + Calendar now also requests `calendar.events.freebusy`, already one of the + 14. The per-service `calendar.write` profile keeps its two scopes, because + the broker matches legacy profiles by exact scope set. Grants made before + this change still count as read & write and keep `suggest_time`; on REST it + falls back to reading attendees' events and names anyone it cannot read. + Nothing prompts them to reconnect; choosing read & write Calendar again in + the picker asks for the new scope. - Target: nothing outside this table is requested, declared in the Console, or shown in the demo. The app side is done; the broker and Console are not (below). @@ -158,17 +202,41 @@ from app versions that still sign 21 scopes fails. ## Where Google content is kept -As reported by the same November 17 audit. Not re-verified here. +From #22010's store inventory. The earlier audit understated it: it missed the +second audit table, approval cards, results passed to later runs, app views, +nested run answers and migrated log originals. -| Place | What is kept | How long | +| Place | What is kept | Removed by "Delete data" | | --- | --- | --- | -| Tool-call audit record | About 4,000 characters of each result | No retention limit. Survives task deletion and connection removal. | -| Run transcripts | Full content | No delete path. | -| Stored run-log files | Run output | Company deletion removes database rows; the audit found no deletion of these files. | -| Optional model check for injection screening | If a company turns it on, the full tool result is sent to an OpenRouter model | Not covered by the audit. | +| Tool-call records (`tool_invocations`, `tool_call_events`) | About 4,000 characters of each request and result | Yes. Size and fingerprint kept. | +| Connection audit history (`tool_access_audit_events`) | Argument preview | Yes. Decision, IDs, size and fingerprint kept. | +| Approval requests and their approval cards in the task | Preview, arguments and the executed result | Yes, for settled requests. | +| Results passed to a later run (run context and wake payload) | Approved action results | Yes, for settled runs and wakes. | +| App views | Tool input, result and shared context | Yes, rows deleted. | +| Run transcripts: the run log in every copy (object journal, archive, original local file and its S3 mirror), run events, output excerpts and answer text at any depth of the run result | Full content | Yes, the whole transcript of every settled run that called the connection or received an approved result. | +| Comments, documents, files and chat messages agents wrote into tasks | Whatever the agent copied | No, by design. The user edits or deletes them, or the task. | +| Transcripts of later runs that read an app view's shared context | Shared context | No. Nothing records which runs read it. | +| Questions a provider asked a person; provider tool and skill definitions | Not tool results | No. | +| Raw provider traces | Full traffic | No. Admin opt-in, encrypted, expire within 24 hours. | +| Feedback exports already sent | Run logs the user chose to share | No. Already outside Paperclip. | +| Optional model check for injection screening | If a company turns it on, the full tool result is sent to an OpenRouter model | Not stored by Paperclip. | | Connection removal | Deletes tokens locally | Does not revoke at Google. | -Planned fix: a "delete data read through this connection" action. +What "Delete data" keeps: the record that each call happened (time, tool, +agent, outcome, size, fingerprint), and activity entries with counts only. + +Limits: + +- Runs still in progress are skipped and counted; delete again after they + finish. +- Deleting a task or a company does not yet run the same cleanup. +- A local log file on another server's disk stays until that server is + replaced; its S3 mirror is deleted. +- On versioned buckets, earlier object versions stay until the bucket's + lifecycle rule removes them. + +The deletion is a durable request. It resumes after a restart and retries a +failed step until every step succeeds. ## Google review history diff --git a/doc/plans/2026-11-17-google-workspace-code-fixes.md b/doc/plans/2026-11-17-google-workspace-code-fixes.md index 469fedffbe6..605b64c542e 100644 --- a/doc/plans/2026-11-17-google-workspace-code-fixes.md +++ b/doc/plans/2026-11-17-google-workspace-code-fixes.md @@ -6,8 +6,8 @@ land. It covers section 2 of the Based on a read of master at `56654adecd`. Items marked **confirmed** were seen in the code. Items marked **to check** are suspected gaps that need a look -before any change. Fixes 1 to 4 landed on November 17. Work on fixes 9 and -10 has started. Fixes 5 to 8 are not started. +before any change. Fixes 1 to 4 and 6 landed on November 17. Work on fixes 9 +and 10 has started. Fixes 5, 7 and 8 are not started. Each fix is its own pull request with a failing test first. For the scope change in fix 2, the deploy order is app first, then broker (see fix 10). @@ -21,10 +21,10 @@ change in fix 2, the deploy order is app first, then broker (see fix 10). | 3 | Take `gmail.modify` off the Paperclip-managed client | Small | Yes | Done, [#22001](https://github.com/paperclipai/paperclip/pull/22001) | | 4 | Confirm injection screening on Google results | Check, then small | Yes | Done, [#21999](https://github.com/paperclipai/paperclip/pull/21999) | | 5 | Revoke at Google on last disconnect | Medium | Likely | Not started | -| 6 | Retention and deletion of Google content | Audit, then unknown | Yes | Audit reported; fix not started | +| 6 | Retention and deletion of Google content | Audit, then unknown | Yes | Done with limits, [#22010](https://github.com/paperclipai/paperclip/pull/22010) | | 7 | Security scan findings | Unknown | Yes (assessment) | Not started | | 8 | Remove the experimental gate | Small | No, release step | Not started | -| 9 | REST-backed tool set | Large | Yes | Part 1 merged Nov 17, [#22000](https://github.com/paperclipai/paperclip/pull/22000) | +| 9 | REST-backed tool set | Large | Yes | Gmail and Calendar done, switch merged, none switched on; Drive, Docs, Sheets, Slides in progress | | 10 | Scope cleanup across code, Cloud and Console | Medium | Yes | App done; broker and Console open | ## 1. Data-use disclosure in the picker @@ -160,6 +160,17 @@ reasoning mostly goes away, and reviewers expect disconnect to end access. ## 6. Retention and deletion of Google content +**Done, with limits** (Nov 17, [#22010](https://github.com/paperclipai/paperclip/pull/22010)). +Any connection's page has "Delete data", and removing a connection offers the +same. It clears previews, approval cards, results passed to later runs, app +views and the whole transcript of each settled run that used the connection. +It keeps call records without content. Limits: content agents wrote into +tasks stays; deleting a task or a company does not yet run the same cleanup; +runs in progress are skipped. The help page is +`docs/guides/board-operator/deleting-connection-data.md`. The inventory is in +the working memory under "Where Google content is kept". Revoking at Google is +fix 5. The plan below is kept for reference. + **To check.** Email and file content returned by tools is stored in task comments, run history, tool results and attachments. Disconnecting does not delete any of it. Google requires that users can delete their data and that we @@ -203,6 +214,22 @@ deleted cleanly. Part 1 is folder and Gmail `get_message`, `search_threads` and `create_draft`. Its README records the dispatch trace and the recommended in-process seam. +Status (Nov 17, late evening): + +| Service | Implemented | Switched on | PRs | +| --- | --- | --- | --- | +| Gmail | 9 of 9 | No | [#22000](https://github.com/paperclipai/paperclip/pull/22000), [#22014](https://github.com/paperclipai/paperclip/pull/22014) | +| Calendar | 9 of 9 | No | [#22017](https://github.com/paperclipai/paperclip/pull/22017) | +| Drive | 0 of 8 | No | In progress | +| Docs | 0 of 2 | No | In progress | +| Sheets | 0 of 6 | No | In progress | +| Slides | 0 of 2 | No | In progress | + +The per-service switch and in-process dispatch landed in +[#22016](https://github.com/paperclipai/paperclip/pull/22016). Every service is +still on Google's MCP. The gateway calls the REST tools in process, as the +trace in #22000 recommended. + ### The seam Today the unified connection sends each tool call, with the user's Google @@ -317,6 +344,10 @@ Also needed: project owner's sign-in). - Keep the working memory's "Scopes" and "Cloud broker" sections current. +Read & write Calendar now also requests `calendar.events.freebusy` (Nov 17). +It is one of the 14 and the broker accepts any nonempty subset of +`workspace.all`, so neither the broker nor the Console needs a change for it. + ## Not code, but needed by these fixes - Published privacy policy and Limited Use statement URLs (fix 1). diff --git a/doc/plans/2026-11-17-google-workspace-production-checklist.md b/doc/plans/2026-11-17-google-workspace-production-checklist.md index f8b53a309d3..9d98f6f9434 100644 --- a/doc/plans/2026-11-17-google-workspace-production-checklist.md +++ b/doc/plans/2026-11-17-google-workspace-production-checklist.md @@ -61,7 +61,9 @@ Decisions and the details behind them are kept in the - [x] Data-use disclosure shown in the picker immediately before Google consent (Nov 17, [#21998](https://github.com/paperclipai/paperclip/pull/21998)). - [ ] Limited Use statement published and linked from the picker. -- [ ] Help page: how to disconnect and how to delete stored Google data. +- [x] Help page: how to disconnect and how to delete stored Google data + (Nov 17, [#22010](https://github.com/paperclipai/paperclip/pull/22010): + `docs/guides/board-operator/deleting-connection-data.md`). - [x] Paperclip-managed Google sign-in can only request the 14 scopes for the unified connection (Nov 17, [#22001](https://github.com/paperclipai/paperclip/pull/22001)). The Cloud @@ -71,12 +73,22 @@ Decisions and the details behind them are kept in the - [x] Prompt-injection screening confirmed on every Google tool result (Nov 17, [#21999](https://github.com/paperclipai/paperclip/pull/21999)). - [ ] Disconnecting the last Google connection revokes the grant at Google. -- [ ] Retention and deletion of Google content in tasks, runs and files audited. +- [x] Retention and deletion of Google content in tasks, runs and files audited + (Nov 17, [#22010](https://github.com/paperclipai/paperclip/pull/22010) + store inventory; summary in the working memory's "Where Google content + is kept"). Users can now delete it per connection. Content agents wrote + into tasks stays, and task or company deletion does not yet run the same + cleanup. - [ ] REST-backed tool set for all 36 actions, in its own folder inside the - server, with the same tool names and shapes as Google's MCP tools - (part 1, three Gmail tools: - [#22000](https://github.com/paperclipai/paperclip/pull/22000), merged - Nov 17; not yet called by the gateway). + server, with the same tool names and shapes as Google's MCP tools. + 18 of 36 so far: Gmail 9 of 9 + ([#22000](https://github.com/paperclipai/paperclip/pull/22000), + [#22014](https://github.com/paperclipai/paperclip/pull/22014)) and + Calendar 9 of 9 + ([#22017](https://github.com/paperclipai/paperclip/pull/22017)). The + per-service switch exists + ([#22016](https://github.com/paperclipai/paperclip/pull/22016)); no + service is switched on yet. - [ ] Scopes identical in the picker, the server, the Cloud broker and the Google Console. - [ ] `googletester.staging.paperclip.app` created and wired to the new Google diff --git a/packages/shared/src/google-workspace-connectors.test.ts b/packages/shared/src/google-workspace-connectors.test.ts index a441ae50fb0..07467b028d6 100644 --- a/packages/shared/src/google-workspace-connectors.test.ts +++ b/packages/shared/src/google-workspace-connectors.test.ts @@ -7,7 +7,7 @@ import { googleWorkspaceSelectedScopes, googleWorkspaceEffectiveScopes, GOOGLE_WORKSPACE_DEFAULT_SELECTION, googleWorkspaceDraftRequestedScopes, GOOGLE_WORKSPACE_SERVICE_GROUPS, GOOGLE_WORKSPACE_SUBMITTED_SCOPES, GOOGLE_WORKSPACE_CONNECTOR_PROFILE_IDS, googleWorkspaceProfileWithinSubmittedScopes, - GOOGLE_WORKSPACE_TOOL_TRANSPORT, googleWorkspaceServiceToolNames, + GOOGLE_WORKSPACE_TOOL_TRANSPORT, googleWorkspaceServiceToolNames, googleWorkspaceSelectionForScopes, type GoogleWorkspaceServiceSelection, } from "./google-workspace-connectors.js"; @@ -30,7 +30,8 @@ describe("combined Google Workspace consent", () => { it("defaults to Gmail, combined Drive, and Calendar write scopes without Chat or People", () => { const selected = googleWorkspaceSelectedScopes(GOOGLE_WORKSPACE_DEFAULT_SELECTION); - expect(selected).toHaveLength(9); + expect(selected).toHaveLength(10); + expect(googleWorkspaceSelectedScopes({ gmail: "read", drive: "read", calendar: "read" })).toHaveLength(8); expect(selected).toContain(scope("gmail.compose")); expect(selected.some(value => /chat|contacts|directory|userinfo/.test(value))).toBe(false); expect(googleWorkspaceSelectedScopes({})).toEqual([]); @@ -46,6 +47,38 @@ describe("combined Google Workspace consent", () => { expect(isGoogleWorkspaceToolGranted("docs__read_doc", effective)).toBe(true); expect(googleWorkspaceEffectiveScopes([scope("documents")], [scope("documents.readonly")])).toEqual([scope("documents.readonly")]); }); + it("requests the free/busy permission with read and write Calendar access", () => { + expect(googleWorkspaceSelectedScopes({ calendar: "read" })).toEqual([ + scope("calendar.calendarlist.readonly"), scope("calendar.events.freebusy"), scope("calendar.events.readonly"), + ]); + expect(googleWorkspaceSelectedScopes({ calendar: "write" })).toEqual([ + scope("calendar.calendarlist.readonly"), scope("calendar.events"), scope("calendar.events.freebusy"), + ]); + expect([...profiles["calendar.write"].scopes]).toEqual([scope("calendar.calendarlist.readonly"), scope("calendar.events")]); + }); + + it("keeps Calendar read and write access for grants made before and after free/busy was requested", () => { + const before = [scope("calendar.calendarlist.readonly"), scope("calendar.events")]; + const after = googleWorkspaceSelectedScopes({ calendar: "write" }); + for (const [requested, granted] of [[before, before], [after, after], [after, before]]) { + const effective = googleWorkspaceEffectiveScopes(requested!, granted!); + expect(effective).toEqual(granted); + expect(googleWorkspaceSelectionForScopes(effective)).toEqual({ calendar: "write" }); + for (const tool of ["list_calendars", "list_events", "suggest_time", "create_event", "delete_event"]) { + expect(isGoogleWorkspaceToolGranted(`calendar__${tool}`, effective), tool).toBe(true); + } + } + expect(googleWorkspaceSelectionForScopes(googleWorkspaceSelectedScopes({ calendar: "read" }))).toEqual({ calendar: "read" }); + }); + + it("does not record a free/busy permission that Google did not grant", () => { + const write = googleWorkspaceSelectedScopes({ calendar: "write" }); + expect(googleWorkspaceEffectiveScopes(write, [scope("calendar.events")])).toEqual([scope("calendar.events")]); + expect(googleWorkspaceEffectiveScopes(googleWorkspaceSelectedScopes({ calendar: "read" }), [scope("calendar.events")])) + .toEqual([scope("calendar.events.readonly")]); + expect(googleWorkspaceEffectiveScopes([scope("calendar.events")], write)).toEqual([scope("calendar.events")]); + }); + it("limits every selectable service combination to the 14 scopes submitted for Google verification", () => { const submitted = [ "gmail.readonly", "gmail.compose", diff --git a/packages/shared/src/google-workspace-connectors.ts b/packages/shared/src/google-workspace-connectors.ts index 6ce5b91fc04..3adffe189f0 100644 --- a/packages/shared/src/google-workspace-connectors.ts +++ b/packages/shared/src/google-workspace-connectors.ts @@ -19,7 +19,10 @@ export const GOOGLE_WORKSPACE_SERVICE_GROUPS = [ export function googleWorkspaceSelectedScopes(selection: GoogleWorkspaceServiceSelection): string[] { return [...new Set(GOOGLE_WORKSPACE_SERVICE_GROUPS.flatMap(group => { const access = selection[group.id]; - return access ? group[access].flatMap(profile => GOOGLE_WORKSPACE_CONNECTOR_PROFILES[profile].scopes) : []; + return access ? [ + ...group[access].flatMap(profile => GOOGLE_WORKSPACE_CONNECTOR_PROFILES[profile].scopes), + ...(SELECTION_ADDED_SCOPES[group.id]?.[access] ?? []), + ] : []; }))].sort(); } @@ -28,7 +31,7 @@ export function googleWorkspaceEffectiveScopes(requested: readonly string[], gra const implies: Record = { documents: ["documents.readonly"], spreadsheets: ["spreadsheets.readonly"], presentations: ["presentations.readonly"], - "calendar.events": ["calendar.events.readonly", "calendar.events.freebusy"], + "calendar.events": ["calendar.events.readonly"], "calendar.readonly": ["calendar.calendarlist.readonly", "calendar.events.readonly", "calendar.events.freebusy"], }; const expand = (scopes: readonly string[]) => new Set(scopes.flatMap(scope => [scope, ...(implies[scope.replace("https://www.googleapis.com/auth/", "")] ?? []).map(value => `https://www.googleapis.com/auth/${value}`)])); @@ -75,6 +78,10 @@ export function googleWorkspaceDraftRequestedScopes( const auth = (scope: string) => `https://www.googleapis.com/auth/${scope}`; +const SELECTION_ADDED_SCOPES: Partial>>> = { + calendar: { write: [auth("calendar.events.freebusy")] }, +}; + const SERVICE_PROFILES: Readonly, { appSlug: string; serverUrl: string; diff --git a/server/src/__tests__/google-workspace-rest-transport.test.ts b/server/src/__tests__/google-workspace-rest-transport.test.ts index d90a8bfd1ab..0f4eb07c6c4 100644 --- a/server/src/__tests__/google-workspace-rest-transport.test.ts +++ b/server/src/__tests__/google-workspace-rest-transport.test.ts @@ -6,7 +6,7 @@ import { toolAccessAuditEvents, toolActionRequests, toolInvocations, } from "@paperclipai/db"; import { - GOOGLE_WORKSPACE_DEFAULT_SELECTION, GOOGLE_WORKSPACE_TOOL_TRANSPORT, + GOOGLE_WORKSPACE_DEFAULT_SELECTION, GOOGLE_WORKSPACE_TOOL_TRANSPORT, googleWorkspaceServiceToolNames, type GoogleWorkspaceService, type GoogleWorkspaceToolTransport, } from "@paperclipai/shared"; import * as restDispatch from "../services/google-workspace-rest-dispatch.js"; @@ -17,6 +17,9 @@ import { initializeRunIdentity } from "../services/run-identity.js"; import type { PaperclipCloudConnector } from "../services/paperclip-cloud-connector.js"; import { getEmbeddedPostgresTestSupport, startEmbeddedPostgresTestDatabase } from "./helpers/embedded-postgres.js"; +const gmailCatalog = (write: boolean) => ["docs__read_doc", ...googleWorkspaceServiceToolNames("gmail") + .filter((name) => write || name !== "create_draft").map((name) => `gmail__${name}`)].sort(); + vi.mock("../services/google-workspace-rest-dispatch.js", async (importOriginal) => { const actual = await importOriginal(); return { @@ -197,14 +200,14 @@ const support = await getEmbeddedPostgresTestSupport(); it("discovers the REST tools under the same names, filtered by granted scopes, after one profile probe", async () => { useTransport("gmail", "paperclip_rest"); const f = await connectWorkspace(); - expect(f.catalog.map((entry) => entry.toolName).sort()).toEqual(["docs__read_doc", "gmail__create_draft", "gmail__get_message", "gmail__search_threads"]); + expect(f.catalog.map((entry) => entry.toolName).sort()).toEqual(gmailCatalog(true)); expect(f.catalog.find((entry) => entry.toolName === "gmail__create_draft")?.riskLevel).toBe("write"); expect(f.mcpRequests.some((request) => request.startsWith("gmailmcp."))).toBe(false); expect(f.mcpRequests).toContain("docsmcp.googleapis.com tools/list"); expect(f.gmailRequests).toEqual([expect.objectContaining({ method: "GET", path: "/gmail/v1/users/me/profile", authorization: "Bearer workspace-access-1" })]); const readOnly = await connectWorkspace({ permissions: ["gmail.readonly", "documents.readonly"] }); - expect(readOnly.catalog.map((entry) => entry.toolName).sort()).toEqual(["docs__read_doc", "gmail__get_message", "gmail__search_threads"]); + expect(readOnly.catalog.map((entry) => entry.toolName).sort()).toEqual(gmailCatalog(false)); }); it("runs a Gmail read in process with the caller's token, screens it, and audits it", async () => { @@ -336,7 +339,7 @@ const support = await getEmbeddedPostgresTestSupport(); await expect(f.call("docs__read_doc", { documentId: "doc1" })).resolves.toMatchObject({ status: "completed" }); f.setGmail(undefined); const recovered = await f.service.refreshCatalog(f.connectionId, f.actor); - expect(recovered.catalog.map((entry) => entry.toolName).sort()).toEqual(["docs__read_doc", "gmail__create_draft", "gmail__get_message", "gmail__search_threads"]); + expect(recovered.catalog.map((entry) => entry.toolName).sort()).toEqual(gmailCatalog(true)); }); it("asks for reconnection when Google keeps rejecting the token after a refresh during discovery", async () => { diff --git a/server/src/__tests__/tool-access-service.test.ts b/server/src/__tests__/tool-access-service.test.ts index cdc1d3ab7d5..0440e6f652e 100644 --- a/server/src/__tests__/tool-access-service.test.ts +++ b/server/src/__tests__/tool-access-service.test.ts @@ -66,6 +66,8 @@ import { GOOGLE_WORKSPACE_CONNECTOR_PROFILES, googleWorkspaceProfileWithinSubmittedScopes, googleWorkspaceSelectedScopes, + googleWorkspaceGrantedScopes, + googleWorkspaceSelectionForScopes, GOOGLE_WORKSPACE_DEFAULT_SELECTION, getAvailableConnectionMethod, getConnectableAppDefinition, @@ -2993,6 +2995,42 @@ describeEmbeddedPostgres("tool access service", () => { })).rejects.toMatchObject({ status: 400 }); }); + it.each([ + ["with", ["calendar.calendarlist.readonly", "calendar.events", "calendar.events.freebusy"]], + ["without", ["calendar.calendarlist.readonly", "calendar.events"]], + ] as const)("asks for free/busy with read and write Calendar and keeps Calendar working %s it", async (_label, granted) => { + const company = await createCompany(db); + const userId = `workspace-calendar-${randomUUID()}`; + await grantBoardUser(db, company.id, userId, [], "owner"); + const actor = { actorType: "user" as const, actorId: userId }; + const service = createTestToolAccessService(db); + const connected = await service.connectGalleryApp(company.id, { + galleryKey: "google-workspace", connectionMethodKey: "customer-workspace-oauth", grantKind: "user", + oauthClient: { clientId: "test-workspace-client", clientSecret: "test-workspace-secret" }, + }, actor); + const redirectUri = "https://paperclip.example.test/api/tools/oauth/callback"; + const started = await service.startOAuth(company.id, connected.connectionId, { redirectUri, actor, workspaceServices: { calendar: "write" } }); + const authorization = new URL(started.authorizationUrl); + const google = (value: string) => `https://www.googleapis.com/auth/${value}`; + expect(authorization.searchParams.get("scope")?.split(" ")) + .toEqual(["calendar.calendarlist.readonly", "calendar.events", "calendar.events.freebusy"].map(google)); + const tools = ["list_calendars", "list_events", "suggest_time", "create_event"]; + vi.spyOn(globalThis, "fetch").mockImplementation(async (url) => { + if (String(url) === "https://oauth2.googleapis.com/token") return Response.json({ + access_token: "fixture-calendar-access", refresh_token: "fixture-calendar-refresh", expires_in: 3600, token_type: "Bearer", + scope: granted.map(google).join(" "), + }); + expect(String(url)).toBe("https://calendarmcp.googleapis.com/mcp/v1"); + return mcpHttpResponse({ jsonrpc: "2.0", id: "paperclip-catalog-refresh", result: { tools: tools.map(name => ({ name })) } }); + }); + const completed = await service.completeOAuthCallback({ state: authorization.searchParams.get("state")!, code: "fixture-code", redirectUri, actor }); + expect(completed.connection.status).toBe("active"); + expect(completed.catalog.map((entry) => entry.toolName).sort()).toEqual(tools.map(name => `calendar__${name}`).sort()); + const [grant] = await db.select().from(connectionGrants).where(eq(connectionGrants.connectionId, connected.connectionId)); + expect(googleWorkspaceGrantedScopes(grant!)).toEqual([...granted].map(google).sort()); + expect(googleWorkspaceSelectionForScopes(googleWorkspaceGrantedScopes(grant!))).toEqual({ calendar: "write" }); + }); + it.each(["https://www.googleapis.com/auth/documents.readonly", undefined, "", "https://www.googleapis.com/auth/gmail.send"])( "requires explicit reviewed partial consent for customer Workspace OAuth (%s)", async (scope) => { const company = await createCompany(db); diff --git a/server/src/services/google-workspace-rest-dispatch.test.ts b/server/src/services/google-workspace-rest-dispatch.test.ts index 5ab7a048f72..28b6c4154f9 100644 --- a/server/src/services/google-workspace-rest-dispatch.test.ts +++ b/server/src/services/google-workspace-rest-dispatch.test.ts @@ -3,7 +3,6 @@ import { describe, expect, it, vi } from "vitest"; import { callGoogleWorkspaceRest, googleWorkspaceRestTransportGaps, - listGoogleWorkspaceRest, probeGoogleWorkspaceRest, } from "./google-workspace-rest-dispatch.js"; @@ -12,19 +11,14 @@ describe("Google Workspace REST transport eligibility", () => { expect(googleWorkspaceRestTransportGaps()).toEqual([]); }); - it("finds Calendar fully implemented and Gmail not yet", () => { - expect(googleWorkspaceRestTransportGaps({ ...GOOGLE_WORKSPACE_TOOL_TRANSPORT, calendar: "paperclip_rest" })).toEqual([]); - expect(googleWorkspaceRestTransportGaps({ ...GOOGLE_WORKSPACE_TOOL_TRANSPORT, gmail: "paperclip_rest" }).map((gap) => gap.service)).toEqual(["gmail"]); + it("finds Gmail and Calendar fully implemented and Chat not", () => { + expect(googleWorkspaceRestTransportGaps({ ...GOOGLE_WORKSPACE_TOOL_TRANSPORT, gmail: "paperclip_rest", calendar: "paperclip_rest" })).toEqual([]); + expect(googleWorkspaceRestTransportGaps({ ...GOOGLE_WORKSPACE_TOOL_TRANSPORT, chat: "paperclip_rest" }).map((gap) => gap.service)).toEqual(["chat"]); }); - it("names the missing tools of a partially implemented or unimplemented service", () => { - const flipped = { ...GOOGLE_WORKSPACE_TOOL_TRANSPORT, gmail: "paperclip_rest" as const, chat: "paperclip_rest" as const }; - const implemented = new Set(listGoogleWorkspaceRest("gmail").map((tool) => tool.name)); - const gaps = googleWorkspaceRestTransportGaps(flipped); - expect(gaps.map((gap) => gap.service)).toEqual(["gmail", "chat"]); - expect(gaps[0]!.missing).toEqual(googleWorkspaceServiceToolNames("gmail").filter((name) => !implemented.has(name))); - expect(gaps[0]!.missing.length).toBeGreaterThan(0); - expect(gaps[1]!.missing).toEqual(googleWorkspaceServiceToolNames("chat")); + it("names every missing tool of a service with no REST tools", () => { + expect(googleWorkspaceRestTransportGaps({ ...GOOGLE_WORKSPACE_TOOL_TRANSPORT, chat: "paperclip_rest" })) + .toEqual([{ service: "chat", missing: googleWorkspaceServiceToolNames("chat") }]); }); }); diff --git a/tests/runner-e2e/source-sdk-public-inputs.json b/tests/runner-e2e/source-sdk-public-inputs.json index 241595beb28..c1d8b7c91ec 100644 --- a/tests/runner-e2e/source-sdk-public-inputs.json +++ b/tests/runner-e2e/source-sdk-public-inputs.json @@ -260,8 +260,8 @@ "packages/shared/src/github-connectors.ts": "b8448b1eddac9a9d1308b94e4d136c761cbd4a00", "packages/shared/src/github-skill-repository.ts": "b00a9963472723bcb7fcd433aae442f75d7a138b", "packages/shared/src/gitignore-runtime.test.ts": "e334ab0eca8faeab5807171983ec9102a3f1c734", - "packages/shared/src/google-workspace-connectors.test.ts": "a441ae50fb0545e81a9a4b0bf8900dddd1f6137f", - "packages/shared/src/google-workspace-connectors.ts": "6ce5b91fc043302062a94a8ece4c3b305c366c48", + "packages/shared/src/google-workspace-connectors.test.ts": "07467b028d6c50b80171239b4a4850d4225be5ce", + "packages/shared/src/google-workspace-connectors.ts": "3adffe189f0eaf9cf258dd5193c1e89cb0305208", "packages/shared/src/grok-bot.ts": "9de68f00e7926c397729ff62bf8e277f5a41c525", "packages/shared/src/heartbeat-inbox.ts": "227dc89705c20460ca02194091cb162e11503186", "packages/shared/src/home-paths.test.ts": "81235c17c376224e1be3abd3f034a8400f079c66",