mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-03 20:09:33 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work. > - Hosts can enable PostHog browser analytics and session replay through deployment configuration. > - Replay masks work content, which makes task and artifact flows hard to understand. > - Hosts must decide whether their deployment may show this content. > - This pull request adds an explicit deployment opt-in, with work content masked by default. > - Eligible companies can show work content after that opt-in, while connected-account checks and secret masking still apply. ## Linked Issues or Issue Description No public issue exists. This change follows the enhancement template. **What existing behavior does this improve?** Session replay masks task descriptions, document bodies and artifact previews. A host cannot choose to show eligible work content independently of enabling replay. **Subsystem affected** Browser session replay, deployment analytics configuration, and the authenticated session contract. **Current behavior** Work content stays masked in every company. Task and artifact titles already show. PostHog project masking settings cannot override the options supplied by the board UI. **Proposed behavior** Keep work content masked by default. Set `PAPERCLIP_POSTHOG_REPLAY_WORK_CONTENT_ENABLED=1` in deployment configuration to allow it for eligible companies. Unset, `0`, and other values keep it masked. Browser analytics and replay must also be enabled. A host can keep replay enabled while work content stays masked. **Reason and benefit** Hosts control their recording policy without editing Core source. An eligible company's replay can show the task flow after the host opts in. **Breaking changes** None relative to the base branch. Self-hosted analytics remain disabled by the existing analytics gate. Existing deployments retain work-content masking unless they explicitly opt in. The session gains an optional boolean and the tool connection list gains an optional `hiddenCount` field. Missing fields fail closed. ## What Changed - Add `PAPERCLIP_POSTHOG_REPLAY_WORK_CONTENT_ENABLED`, default off. Resolve it in the existing server analytics configuration and send the effective boolean as `browserAnalytics.replayWorkContentEnabled`. The shared session schema preserves the field and accepts older servers that omit it. - Require both replay and the work-content opt-in before the UI queries company sources or permits visibility. Removing the opt-in from a refreshed session masks content even when eligible source answers remain cached. - Preserve the original company checks: complete tool connection and chat endpoint lists, no Google or Slack source, no known aggregator or router, and the selected company's route. Unknown, failed, invalidated, or hidden source data keeps content masked. Live source changes reset the check. - Mark task descriptions, document bodies, attachment and artifact previews, and file viewers as work content. Customer content, editors, comments, chat, run output and connected-account surfaces remain masked. Secrets remain blocked or redacted. Input and attribute values remain masked. - Preserve credential punctuation in task previews by reusing the shared Markdown plain-text helper. Bound conversion to the first 2,048 source characters, and always mask source-capped previews to protect incomplete credentials. Scan complete command-line flag names once before classifying secrets and reading their values. A 512 KiB hyphen input and long flag names have regression coverage. - Mask surfaces that show cut or rewritten work content, where the redaction cannot work. A cut task preview masks when the text before its 180-character limit holds a credential. The document card preview (first 4,000 characters) masks when the cut changes what the redaction masks before it. The text preview on an artifact card always masks, because the server strips hyphens and underscores from it and cuts it at 280 characters. Quoted flag values run past escaped quotes, and flag names can hold an underscore. An unquoted token that starts with `--` is read as the next flag, not as a value, so `--auth --tlsCertificateKeyFilePassword hunter2` masks `hunter2`. - Refresh the recording once when a company's work content first becomes visible. Keep the existing autocapture text and attribute masking. - Add tests for deployment switches, session parsing and exposure, disabled source requests, older servers, and withdrawal with cached data. Retain the original masking, company, secret, and source-change tests. - Document configuration, rollback, restart and tab-reload steps, residual recording risks, and the board-only `hiddenCount` API field with absent-on-older-server semantics. Refresh the shared-source pins with the maintained generator; runtime and compiler pins stay unchanged. The original implementation and commits are preserved from @nguyenm7. The deployment configuration follow-up adds the host opt-in. When squash-merging, preserve the follow-up author's credit in the squash commit body: ```text Co-Authored-By: Devin Foley <devinfoley@users.noreply.github.com> ``` ## Verification Current head `2ce967f1e1`: CI has 43 checks passed and four skipped, with none failed or pending. The Greptile review on this head is 5/5, and both findings from its previous review are fixed. No person has approved the pull request yet. The evidence below was recorded on earlier heads and is kept as the record of how the change was verified. Greptile apex review: 5/5 on `45023e6`, with no unresolved review threads. CI on that head is green: 76 checks passed and four skipped, with no failed or pending checks. The branch has no merge conflicts with master. On the final source change, locally: - `cd ui && pnpm exec vitest run src/lib/analytics src/context/LiveUpdatesProvider.test.ts src/lib/markdown-plain-text.test.ts`: 10 files, 520 tests pass. The secret-redaction cases are in `replay-secret-redaction.test.tsx`, so `replay-masking.test.tsx` stays under 1,000 lines (701). - `cd server && pnpm exec vitest run src/__tests__/cloud-posthog-config.test.ts src/__tests__/cloud-posthog-browser.test.ts src/__tests__/auth-routes.test.ts src/__tests__/posthog-direct-transport.test.ts`: 4 files, 124 tests pass. - `cd packages/shared && pnpm exec vitest run src/validators/access.test.ts`: 22 tests pass. - `pnpm exec vitest run -c tests/runner-e2e/vitest.config.ts source-sdk-public-inputs`: 13 tests pass. - Shared, server and UI package typechecks pass. Server and UI builds pass. - Token gates, module boundaries, the test budget check for changed suites, and `git diff --check` pass. - Long-preview regression proof: four rendered tests initially fail on `9f2039d` because it passes 128,005 characters to conversion. They now verify a 2,048-character input bound while calling the real helper, a maximum 180-character summary, and complete replay masking for capped sources. Inputs include backticks, stars, underscores and brackets. The earlier short-preview credential tests still pass. - Review regression proof: three rendered task-preview tests expose GitLab, GitHub and OpenAI fixture credentials on `7533fbe`; they pass after preserving token punctuation. An 80,000-hyphen input took about 3.25 seconds on that head and failed the 500 ms bound. The single-pass flag scan passes the guard with a 512 KiB prefix followed by a real password flag. - Regression proof: the added tests first failed on the prior implementation, including work content visible with a missing or false opt-in and after withdrawal. They pass with the new gate. - `pnpm verify`: exit 2, broader verification required because the analytics document is a global CI input. Required CI supplies repository-wide coverage. An earlier exit 1 identified stale shared-source pins; the maintained generator refreshed them and the 13 pin tests pass. - Direct UI `tsc --noEmit` initially lacked generated Storybook catalogs in the fresh checkout. The maintained UI typecheck generates those files and passes. A preliminary Vitest `--project ui` invocation matched no named project; the commands above use the package configuration. - Secret scan reviewed the commit diff. Gitleaks reports two generic-key matches in the generated source-pin registry; both equal the corresponding Git blob hashes. The remaining commit content scans clean. No run artifacts or private deployment data are committed. CI follow-up on `45023e6`: [server shard 10/20](https://github.com/paperclipai/paperclip/actions/runs/45560174673/job/139021948661) timed out twice at the existing 15-second limit in `issue-document-batch.integration.test.ts`, test "rejects many large documents using a size-only query before loading any bodies". The test prepares 200 half-MiB documents and later rewrites them. The same test and server code are unchanged from `9f2039d`, where [the same shard passed](https://github.com/paperclipai/paperclip/actions/runs/45558505382/job/139016469065) and this test took 8.39 seconds. The intervening commit changes UI and documentation only. The exact failing case passes locally on the current head with `cd server && pnpm exec vitest run src/services/native-runtime/issue-document-batch.integration.test.ts -t 'rejects many large documents using a size-only query before loading any bodies'` (one passed, 15 skipped). This shows local recovery; it does not establish the cause of the CI timeout. A targeted shard rerun was requested, but GitHub refused because the workflow is still running. No test limits or product code have been changed to hide the failure. This initial failure is retained here as evidence; the successful second-attempt outcome is recorded below. CI follow-up, second shard: [server shard 13/20](https://github.com/paperclipai/paperclip/actions/runs/45560174673/job/139021948654) failed `ai-connections.test.ts`, test "requires sign-in after the receiver process dies with an exchanged but unsaved token". The first attempt failed its wait for one token exchange and an advisory-lock waiter within 25 seconds. The automatic retry failed earlier because the first attempt had already inserted the fixed membership fixture. The suite, receiver helper and AI connection service are unchanged by this work. The [original PR head passed this shard](https://github.com/paperclipai/paperclip/actions/runs/45544519067/job/138970880217), with the same test taking 21.06 seconds. The exact case passes locally on `45023e6` with `cd server && pnpm exec vitest run src/__tests__/ai-connections.test.ts -t 'requires sign-in after the receiver process dies with an exchanged but unsaved token'` (one passed, 164 skipped). The cause of the missed CI wait remains unconfirmed. This local pass does not clear the failed CI result. Targeted reruns were initially blocked by GitHub while the workflow was running. See the successful second-attempt outcome below. CI recovery: [workflow attempt 2](https://github.com/paperclipai/paperclip/actions/runs/45560174673/attempts/2) completed successfully on unchanged head `45023e6`. Both previously failed shards now pass. No source edits, timeout increases, or test removals were needed. The original timeout and missed-wait causes remain unconfirmed; the earlier failures and comparison evidence above are preserved. Final acceptance uses the green current-head CI result together with the local checks and 5/5 review. Not run locally: repository-wide tests/builds or a live PostHog recording. The tests exercise the masking callback and UI state, not the externally loaded recorder. After deployment, compare a masked replay with the work-content flag unset against an opted-in eligible company. Then verify that Google/Slack or a hidden source keeps the same surfaces masked. Restart the server and reload open tabs after changing deployment environment values. ## Risks - The opt-in belongs to the host, not to the people who use the deployment. Nothing in this pull request asks or tells a user. A host that sets the flag must tell its users first. The plan for the hosted service is in #23338. - Enabling the new flag allows eligible work content to leave the instance in replay data. Leave it unset or set it to `0` to keep work content masked. No deployment or fleet policy is changed by this PR. - The flag does not bypass company eligibility checks or secret masking. Changing it affects future recording after the configuration reaches the browser; it does not remove previously recorded content. - Connection detection is a best effort. A custom MCP server with an unrelated name and URL, or credentials used directly by an agent, can carry Google or Slack data without appearing as a known source. - Secret redaction is a best effort. Unknown or unlabeled secrets, non-English labels, values on a later line or under a table header, and values outside bounded line context can be missed. Some ordinary values are over-masked. - Source changes can race with recording until the live update arrives. A missed update can extend that window to the five-minute refresh. Connection count and list queries can disagree briefly and then mask conservatively. - Hidden drafts and aggregators can keep harmless content masked. Text rendered during a source recheck stays masked until it renders again. The first visible state adds a full recording snapshot. - Task previews now inspect at most 2,048 source characters before conversion. Very long markup can produce an incomplete summary. Source-capped previews stay fully masked; opening the full task keeps the normal work-content policy. - Artifact card text previews stay masked in every company. Document card previews and cut task previews mask when a credential sits at or before the cut, so some replays show stars there while the full document shows. - Task titles, names and other previously visible surfaces remain visible and can contain copied customer text. New work-content surfaces must preserve company scoping. ## Model Used - Original implementation: Anthropic Claude Opus 5.5 (`claude-opus-5-5`) and Claude Fable 5.2 (`claude-fable-5-2`) through Claude Code, with shell, edits, tests and the original read-only exploration subagent. - Deployment configuration follow-up: OpenAI `gpt-6.1-sol` through the Codex, xhigh reasoning, shell, file edits and test tools. Context window size is not exposed by the runtime. No additional subagents. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [x] All Paperclip CI gates are green - [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Devin Foley <devin@paperclip.ing> Co-authored-by: Paperclip <noreply@paperclip.ing> Co-authored-by: Dotta <bippadotta@protonmail.com>
136 lines
8.1 KiB
Markdown
136 lines
8.1 KiB
Markdown
---
|
|
title: Tool Connections
|
|
summary: Remove a connection or one of its grants, cancel a first sign-in, read what happened at the provider, and read what to set up in AWS for an AWS role connection
|
|
---
|
|
|
|
Removing a connection or a grant always completes in Paperclip. The response says what happened at the provider when Paperclip can ask the provider to end access.
|
|
|
|
## List Connections
|
|
|
|
```
|
|
GET /api/companies/{companyId}/tools/connections
|
|
```
|
|
|
|
The caller needs company access and `connections:read`. The `200` response has
|
|
a `connections` array containing the connections visible to the caller.
|
|
|
|
For board users, the response also has `hiddenCount`, a nonnegative integer
|
|
that counts company connections omitted from the array. This includes another
|
|
user's draft connection and connections whose plugin is unavailable. A zero
|
|
count means the response did not omit any connection at the time of the check.
|
|
Agent responses do not include this field.
|
|
|
|
Older servers can omit `hiddenCount`. An absent count means completeness is
|
|
unknown; callers must not treat it as zero. In particular, the session replay
|
|
source check keeps work content masked when the count is missing or positive.
|
|
The count and the connection list are separate queries, so concurrent changes
|
|
can temporarily make them differ.
|
|
|
|
## Remove a Connection
|
|
|
|
```
|
|
DELETE /api/tool-connections/{connectionId}
|
|
DELETE /api/tool-connections/{connectionId}?deleteStoredContent=true
|
|
```
|
|
|
|
The caller needs `connections:configure` for the connection. Only a board user can set `deleteStoredContent=true`.
|
|
|
|
The `200` response is the archived connection with a `removal` object. `removal` holds counts of what was torn down, for example `secretsRevoked` and `grantsRevoked`. With `deleteStoredContent=true`, the response also has `contentDeletion`.
|
|
|
|
## Cancel a First Sign-In
|
|
|
|
```
|
|
POST /api/tool-connections/{connectionId}/sign-in/cancel
|
|
```
|
|
|
|
Use this when a user cancels the provider sign-in for a new connection. The caller needs `connections:configure` for the connection.
|
|
|
|
Paperclip removes the connection only if it is an OAuth draft that never held a credential. The removal is the same teardown as `DELETE`, and the activity log gets `tool_connection.sign_in_cancelled`. The `200` response is `{ "abandoned": true, "connection": ... }` with the archived connection.
|
|
|
|
For any other connection, Paperclip changes nothing. This includes an active connection and a connection that needs a new sign-in after it worked before. The `200` response is `{ "abandoned": false, "connection": ... }` with the unchanged connection.
|
|
|
|
`GET /api/companies/{companyId}/tools/connections` sets `firstSignInPending: true` on an OAuth draft that never held a credential. The Apps page does not show these drafts, and the next setup for the same app reuses them.
|
|
|
|
## Remove a Grant
|
|
|
|
```
|
|
DELETE /api/tool-connections/{connectionId}/grants/{grantId}
|
|
```
|
|
|
|
The caller needs `connections:configure` for the connection, or must be the grant's own user. The `200` response is the revoked grant.
|
|
|
|
## Google Access (`providerAccess`)
|
|
|
|
For a Google connection that Paperclip Cloud manages, the connection response has `removal.providerAccess` and the grant response has `providerAccess`. Other connections do not have this field.
|
|
|
|
```json
|
|
{
|
|
"provider": "google",
|
|
"result": "ended",
|
|
"outcomes": ["revoked"]
|
|
}
|
|
```
|
|
|
|
`result` is one of:
|
|
|
|
| `result` | Meaning |
|
|
| --- | --- |
|
|
| `ended` | Google ended Paperclip's access for every removed grant. |
|
|
| `ended_unconfirmed` | Google ended access for at least one removed grant, and the others reported other connections. Paperclip cannot tell whether they were the same Google account. |
|
|
| `other_connections_remain` | Other Paperclip connections still use this Google account, so Google keeps the access. |
|
|
| `retrying` | Google did not confirm yet for at least one removed grant (Paperclip Cloud or Google could not be reached, or Google failed). Paperclip keeps that token in a pending record and retries in the background; the user does not need to act. |
|
|
| `not_ended` | Paperclip Cloud gave a final answer that it cannot end the access at Google for at least one removed grant, or the token could not be kept for a retry. The user can remove it at https://myaccount.google.com/connections. |
|
|
|
|
`outcomes` has one code for each refresh token Paperclip sent, in order. The codes are for diagnosis, not for display.
|
|
|
|
A failure to end access at Google does not undo the local removal. On both routes the local removal completes first, then Paperclip asks Paperclip Cloud to end access at Google once in the request. When that is not confirmed and can be retried, the result is `retrying`: a background worker retries with backoff from 1 minute up to 6 hours, for at most 30 days. When the retry ends, the connection's audit history gets a `connection.google_access_retry` event, and the activity log gets `tool_connection.google_access_ended` or `tool_connection.google_access_not_ended`. Revoking an organization grant whose token the connection itself still uses does not end access at Google and has no `providerAccess`; removing the connection does. The activity entry for the removal records the same `providerAccess`, and the connection's audit history gets a `connection.google_access_removal` event with it.
|
|
|
|
## AWS Role Setup
|
|
|
|
```
|
|
GET /api/tool-connections/{connectionId}/aws-setup
|
|
GET /api/tool-connections/{connectionId}/aws-setup?accessLevel=full
|
|
```
|
|
|
|
Returns what to create in AWS for an AWS role connection (`connectionMethodKey` `aws-role`): an IAM OpenID Connect identity provider for the company's issuer and a role that trusts only this connection. The setup screen reads it after saving the connection as a draft, and again on reconnect. It never contains a secret.
|
|
|
|
The caller needs `connections:configure` for the connection.
|
|
|
|
`accessLevel` is optional (`read_only` or `full`). It sets up for an access level that is not saved yet, such as one changed while reconnecting. Without it, the saved access level is used. For `read_only` the template's `AccessPolicyArn` defaults to `ReadOnlyAccess`; for `full` it has no default.
|
|
|
|
When this instance can serve the role method, the `200` response is:
|
|
|
|
```json
|
|
{
|
|
"available": true,
|
|
"issuer": "https://paperclip.example.com/oidc/companies/<companyId>",
|
|
"audience": "sts.amazonaws.com",
|
|
"subject": "connection:<connectionId>",
|
|
"providerHost": "paperclip.example.com/oidc/companies/<companyId>",
|
|
"roleName": "paperclip-<connectionId>",
|
|
"savedRoleArn": null,
|
|
"accessLevel": "read_only",
|
|
"trustPolicy": { "Version": "2012-10-17", "Statement": ["..."] },
|
|
"cloudFormationTemplate": "{ ... }",
|
|
"cloudFormationConsoleUrl": "https://console.aws.amazon.com/cloudformation/home#/stacks/create",
|
|
"issuerPublished": true
|
|
}
|
|
```
|
|
|
|
- `roleName` is the role the template and the agent prompt create. It is named after the connection, and CloudFormation fills in the account, so the template needs no edits.
|
|
- `savedRoleArn` is the role ARN saved on a finished connection when it is this connection's own role (`roleName`), or `null`. Drafts never keep a role ARN, and a role with any other name is not offered, because the setup steps tell an AWS administrator to update this role.
|
|
- `trustPolicy` is for setting up by hand. `ACCOUNT_ID` in it stands for the customer's AWS account ID.
|
|
- `issuerPublished` is `true` when the company's signing key is published, so AWS can validate the issuer.
|
|
|
|
Otherwise the `200` response is `{ "available": false, "reason": "<reason>" }`:
|
|
|
|
| `reason` | Meaning |
|
|
| --- | --- |
|
|
| `no_public_url` | The instance has no public address, so AWS cannot reach its issuer. |
|
|
| `not_https` | The instance is not served over HTTPS, which AWS requires. |
|
|
| `has_port` | The instance address includes a port, which AWS does not allow. |
|
|
| `loopback` | The instance runs on this computer only. |
|
|
| `address_changed` | The instance address changed after this draft was saved. Saving the draft again uses the current address. A finished connection is set up for the current address instead, since reconnecting records it. |
|
|
|
|
Errors: `404` when the connection does not exist or is not accessible, and `422` with code `aws_role_setup_unavailable` when the connection does not use an AWS role.
|