paperclip/packages/db/src/schema
Dotta 0ffc091473
feat(connections): add durable GitHub identities and webhooks (#12843)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - Agents need source control access for repository work
> - A shared token cannot preserve the responsible person's identity or
an agent's dedicated identity
> - GitHub App tokens also need durable refresh, repository access
checks, and webhook delivery
> - Paperclip already has managed connections, encrypted grants, run
secret leases, and merge-confirmation behavior
> - This pull request extends those systems with GitHub identities
instead of adding a parallel credential system
> - The benefit is durable GitHub access with explicit identity,
repository, runtime, and webhook boundaries

## Linked Issues or Issue Description

No public GitHub issue describes this connection change. This
description follows the feature request template.

**Subsystem affected**

Connected Apps, connection grants, secret resolution, native Git runtime
setup, webhook processing, and the Apps UI.

**Problem or motivation**

Users need to connect GitHub once and let agents use the correct GitHub
identity. A run should use a dedicated agent account when one exists.
Otherwise, it should use the responsible person's account. The
connection must survive token expiry, repository access changes, and
temporary instance downtime.

**Proposed solution**

Add user-owned and agent-owned GitHub grants to the existing connection
model. Resolve one identity for MCP, Git, `gh`, health checks, and
webhook bindings. Store provider tokens in the existing encrypted secret
system. Refresh expiring token pairs under the existing lease and
compare-and-swap path. Register signed Cloud webhook bindings and
process normalized pull request and installation events through a
durable local inbox.

**Alternatives considered**

An organization-wide GitHub token would lose person and agent
attribution. Environment variables alone would bypass the managed
connection and grant model. A new GitHub-only credential store would
duplicate the existing secret and access systems. GitHub App
installation tokens and private-key custody remain outside this first
version.

**Roadmap alignment**

This change implements the Connected Apps direction. It also extends the
shipped MCP Tool Gateway, per-agent secret access, and
action-attribution systems. It does not add a repository catalog. The
open repository catalog work in
[#11234](https://github.com/paperclipai/paperclip/pull/11234) is related
and complementary.

## What Changed

- Added agent-owned connection grants and a per-agent credential policy
with company and subject constraints.
- Added a managed GitHub App method while keeping the personal access
token method as an advanced fallback.
- Added durable access-token and refresh-token handling with proactive
rotation and one automatic recovery after a provider `401`.
- Added GitHub identity and installation summaries without storing
repository-name lists.
- Added signed Cloud webhook binding, event lease, acknowledgement,
local idempotency, pull request merge processing, and installation
access handling.
- Added one identity resolver for MCP, native Git, `gh`, checkout,
health checks, and webhook bindings.
- Added a class-3 run projection for `GH_TOKEN`, `GITHUB_TOKEN`, a
`github.com`-only credential helper, SSH-to-HTTPS rewrite, and GitHub
noreply commit attribution.
- Added personal and dedicated-agent setup choices plus identity,
repository, continuity, and webhook status in the Apps UI.
- Added schema migrations, tests, and connection documentation.

## Verification

- The current head is fully green in GitHub CI, including build,
typecheck, all serialized/general server shards, all browser shards,
policy, canary dry run, review, and security checks.
- Live staging proof completed with a non-expiring GitHub App user
token, selected-repository installation, repository add/remove refresh,
managed MCP, native `gh`, HTTPS clone/push/delete, GitHub noreply commit
attribution, signed merged-PR webhook acceptance, durable
Cloud-to-instance delivery, and installation-access event processing.
Temporary branches and temporary repository access were removed
afterward.
- `pnpm check:token-gates` passed.
- `pnpm -r typecheck` passed before and after the rebase onto
`origin/master`.
- `pnpm build` passed.
- The focused connector suite passed 285 tests after the rebase.
- The full stable suite passed 5,790 tests and failed 22 tests across 8
general server files. The failures reproduced as shared-runner
environment issues. They included `/tmp` versus `/private/tmp`, closed
database connections, and invalid high ephemeral ports. The focused
connection tests pass in isolation.

## Risks

- Migrations add agent grant subjects and a durable connection-event
inbox. Migration numbering and safety checks pass.
- A raw GitHub user token enters the agent process for Git and `gh`.
Per-tool Ask-first controls cannot limit those shell operations. The UI
warns users about this boundary.
- GitHub App user tokens can be non-expiring. Paperclip performs a
continuity check every 30 days, but provider revocation still requires a
reconnect.
- The webhook path accepts only signed and bounded payloads. It stores a
minimal normalized record and no raw provider payload.
- GitHub repository permissions remain authoritative. Removed access can
make a cached repository count temporarily stale, but runtime access
fails immediately.

> For core feature work, check [`ROADMAP.md`](ROADMAP.md) first and
discuss it in `#dev` before opening the PR. Feature PRs that overlap
with planned core work may need to be redirected — check the roadmap
first. See `CONTRIBUTING.md`.

## Model Used

OpenAI Codex, `gpt-5.6-sol`, extended reasoning, tool use, code
execution, browser control, and multi-file repository editing. The
context window size was not provided.

## 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
- [ ] 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: Paperclip <noreply@paperclip.ing>
2026-09-04 18:02:52 -05:00
..
activity_log.ts feat: stamp responsible users on activity logs (#9731) 2026-07-16 20:54:55 -05:00
adapter_auth_sessions.ts feat(auth): normalize agent login in the sandbox onto one session table and a capability contract (#11730) 2026-08-19 11:51:31 -07:00
agent_api_keys.ts feat(secrets): add user-specific runtime secrets (#8825) 2026-07-05 05:58:20 -05:00
agent_config_revisions.ts
…
agent_memberships.ts [codex] Add starred resource sidebar controls (#9085) 2026-07-06 14:09:11 -05:00
agent_runtime_state.ts
…
agent_task_sessions.ts
…
agent_wakeup_requests.ts fix(interactions): deliver question answers durably (#12307) 2026-08-27 12:12:21 -05:00
agents.ts fix(server): enforce agent secret binding sync across lifecycle flows (#8307) 2026-06-18 21:26:36 -07:00
approval_comments.ts
…
approvals.ts
…
assets.ts
…
auth.ts Add the Better Auth issuer column so signup and sign-in work (#12396) 2026-08-27 22:31:35 -07:00
board_api_keys.ts
…
budget_incidents.ts
…
budget_policies.ts
…
built_in_managed_resources.ts [codex] Add built-in agents and Reflection Coach bundle (#9206) 2026-07-09 16:29:30 -05:00
cases.ts Cases: experimental first-class case object (#9198) 2026-07-09 22:11:03 -05:00
cli_auth_challenges.ts
…
companies.ts Remove the company brand color and per-company attachment limit (#12291) 2026-08-27 12:11:05 -07:00
company_logos.ts
…
company_memberships.ts
…
company_onboarding_seeds.ts feat(server): receive and apply the Paperclip Cloud onboarding seed (#11098) 2026-08-12 22:54:07 -07:00
company_secret_bindings.ts feat(mcp) [split 2/8]: add governed access contracts (#9557) 2026-07-14 12:57:20 -05:00
company_secret_proposals.ts Add governed secret alias confirmation cards (#11486) 2026-08-18 09:44:24 -05:00
company_secret_provider_configs.ts Add secrets provider vaults and remote import (#5429) 2026-05-09 18:22:17 -05:00
company_secret_versions.ts Add secrets provider vaults and remote import (#5429) 2026-05-09 18:22:17 -05:00
company_secrets.ts feat(secrets): add user-specific runtime secrets (#8825) 2026-07-05 05:58:20 -05:00
company_skill_policies.ts feat(skills): open-by-default company skill policy and core UX (#9564) 2026-07-15 11:42:40 -05:00
company_skills.ts feat(skills): add beta releases for the core Paperclip skill (#10228) 2026-07-27 19:45:59 -05:00
company_transfer_runs.ts feat(server): chunked resumable company import transfers (#11223) 2026-08-11 15:25:07 -07:00
company_user_sidebar_preferences.ts [codex] Improve workspace runtime and navigation ergonomics (#3680) 2026-04-14 12:57:11 -05:00
completion_contracts.ts feat(runner): add native persistence contracts (#12169) 2026-08-25 13:08:39 -05:00
connection_event_deliveries.ts feat(connections): add durable GitHub identities and webhooks (#12843) 2026-09-04 18:02:52 -05:00
cost_events.ts fix(issues): make DELETE /api/issues/:id succeed for issues with dependents (#11331) 2026-08-13 12:02:15 -07:00
decision_queues.ts feat(decisions): add desk workflow and retention (#10672) 2026-08-02 10:47:03 -05:00
decision_training_examples.ts feat: add decision training snapshot foundation (#9702) 2026-07-17 12:17:34 -05:00
decisions.ts feat(decisions): add first-class propose mode (#10010) 2026-07-31 19:17:02 -07:00
document_annotation_anchor_snapshots.ts [codex] Add document annotations and comments (#6733) 2026-05-26 06:41:23 -07:00
document_annotation_comments.ts Cases: experimental first-class case object (#9198) 2026-07-09 22:11:03 -05:00
document_annotation_threads.ts Cases: experimental first-class case object (#9198) 2026-07-09 22:11:03 -05:00
document_memberships.ts feat(server): add per-user document stars (#9952) 2026-07-27 19:13:35 -05:00
document_revisions.ts fix: upstream deployed document-comment, routine-annotation, workspace & board-polling fixes (#8536) 2026-06-23 09:00:14 -05:00
documents.ts fix: upstream deployed document-comment, routine-annotation, workspace & board-polling fixes (#8536) 2026-06-23 09:00:14 -05:00
environment_custom_image_setup_sessions.ts Scope environment custom images to instance environments (#8850) 2026-07-01 23:57:31 -07:00
environment_custom_image_templates.ts Scope environment custom images to instance environments (#8850) 2026-07-01 23:57:31 -07:00
environment_leases.ts feat: Claude login on the new-agent page before agent creation (#11347) 2026-08-17 13:42:51 -07:00
environments.ts refactor(environments): make execution environments instance-scoped (#8375) 2026-06-20 09:42:53 -07:00
execution_workspace_runtime_leases.ts feat(runtime-exposure): least-privilege Tailscale HTTPS broker, shared contract, and persisted exposure state (#11524) 2026-08-17 05:54:12 -04:00
execution_workspaces.ts PAPA-430: workspace finalize gates + no-remote-git enforcement (#6969) 2026-05-29 08:25:29 -07:00
external_object_mentions.ts External object references across issue surfaces (#8512) 2026-06-23 08:27:19 -05:00
external_objects.ts fix(external-objects): refresh PR status labels (#10704) 2026-08-02 20:24:52 -07:00
feedback_exports.ts
…
feedback_votes.ts fix(issues): make DELETE /api/issues/:id succeed for issues with dependents (#11331) 2026-08-13 12:02:15 -07:00
finance_events.ts fix(issues): make DELETE /api/issues/:id succeed for issues with dependents (#11331) 2026-08-13 12:02:15 -07:00
folders.ts feat: organize skills with nested folders and My Skills (#9633) 2026-07-16 15:50:45 -05:00
goals.ts
…
heartbeat_run_events.ts feat(runner): add Codex-native application integration (#12591) 2026-08-31 14:38:38 -05:00
heartbeat_run_watchdog_decisions.ts [codex] Add runtime lifecycle recovery and live issue visibility (#4419) 2026-04-24 15:50:32 -05:00
heartbeat_runs.ts feat(runner): add native persistence contracts (#12169) 2026-08-25 13:08:39 -05:00
inbox_dismissals.ts feat: add attention queue and Decisions surface (#9380) 2026-07-10 17:09:57 -05:00
index.ts feat(connections): add durable GitHub identities and webhooks (#12843) 2026-09-04 18:02:52 -05:00
instance_settings.ts refactor(environments): make execution environments instance-scoped (#8375) 2026-06-20 09:42:53 -07:00
instance_user_roles.ts
…
invites.ts
…
issue_approvals.ts
…
issue_attachments.ts
…
issue_comments.ts fix(issues): make DELETE /api/issues/:id succeed for issues with dependents (#11331) 2026-08-13 12:02:15 -07:00
issue_create_idempotency_keys.ts fix: prevent duplicate task creation and recovery loops (#9648) 2026-07-16 17:00:53 -05:00
issue_documents.ts
…
issue_execution_decisions.ts Add issue review policy and comment retry 2026-04-07 17:43:10 -05:00
issue_inbox_archives.ts fix(issues): make DELETE /api/issues/:id succeed for issues with dependents (#11331) 2026-08-13 12:02:15 -07:00
issue_labels.ts
…
issue_plan_decompositions.ts Add accepted-plan decomposition exact-once guards and UI state (#6831) 2026-05-28 23:30:18 -07:00
issue_question_response_deliveries.ts fix(interactions): deliver question answers durably (#12307) 2026-08-27 12:12:21 -05:00
issue_read_states.ts fix(issues): make DELETE /api/issues/:id succeed for issues with dependents (#11331) 2026-08-13 12:02:15 -07:00
issue_recovery_actions.ts [codex] Add source-scoped recovery actions (#5599) 2026-05-12 09:37:15 -05:00
issue_reference_mentions.ts Add first-class issue references (#4214) 2026-04-21 10:02:52 -05:00
issue_relations.ts fix: address greptile feedback for blocker dependencies 2026-04-06 09:03:13 -05:00
issue_thread_interactions.ts feat(apps): add connection grants and delegated identities (#12341) 2026-08-29 12:08:33 -05:00
issue_tree_hold_members.ts [codex] Add issue subtree pause, cancel, and restore controls (#4332) 2026-04-23 14:51:46 -05:00
issue_tree_holds.ts [codex] Add issue subtree pause, cancel, and restore controls (#4332) 2026-04-23 14:51:46 -05:00
issue_watchdogs.ts fix(task-watchdogs): deduplicate unchanged stopped-state wakes (#10207) 2026-07-25 08:34:41 -05:00
issue_work_products.ts Add low-trust review containment (#7530) 2026-06-05 16:48:02 -05:00
issues.ts feat(runner): add native persistence contracts (#12169) 2026-08-25 13:08:39 -05:00
join_requests.ts feat: implement multi-user access and invite flows (#3784) 2026-04-17 09:44:19 -05:00
labels.ts
…
managed_agent_profiles.ts feat(runner): add managed provider backends (#12699) 2026-09-02 00:48:30 -05:00
native_run_finalizations.ts fix(runner): recover native sessions across restarts (#12845) 2026-09-04 15:03:53 -05:00
native_run_results.ts feat(runner): add native persistence contracts (#12169) 2026-08-25 13:08:39 -05:00
pipeline_case_events.ts Add pipeline workflow primitives and operator UI (#7903) 2026-06-26 12:02:44 -05:00
pipeline_cases.ts Add pipeline workflow primitives and operator UI (#7903) 2026-06-26 12:02:44 -05:00
pipelines.ts Add pipeline workflow primitives and operator UI (#7903) 2026-06-26 12:02:44 -05:00
plugin_company_settings.ts feat(mcp) [split 2/8]: add governed access contracts (#9557) 2026-07-14 12:57:20 -05:00
plugin_config.ts feat(mcp) [split 2/8]: add governed access contracts (#9557) 2026-07-14 12:57:20 -05:00
plugin_database.ts [codex] Add plugin orchestration host APIs (#4114) 2026-04-20 08:52:51 -05:00
plugin_entities.ts feat(security): plugin tables get company_id FK for tenant isolation (#5865) 2026-06-12 10:17:19 -07:00
plugin_jobs.ts feat(security): plugin tables get company_id FK for tenant isolation (#5865) 2026-06-12 10:17:19 -07:00
plugin_logs.ts feat(security): plugin tables get company_id FK for tenant isolation (#5865) 2026-06-12 10:17:19 -07:00
plugin_managed_resources.ts Expand plugin host surface (#5205) 2026-05-05 07:42:57 -05:00
plugin_state.ts
…
plugin_webhooks.ts feat(security): plugin tables get company_id FK for tenant isolation (#5865) 2026-06-12 10:17:19 -07:00
plugins.ts
…
principal_permission_grants.ts
…
project_goals.ts
…
project_memberships.ts [codex] Add starred resource sidebar controls (#9085) 2026-07-06 14:09:11 -05:00
project_workspaces.ts
…
projects.ts Information Architecture + project/agent visual refresh (experimental) (#7543) 2026-06-06 09:17:27 -05:00
provider_trace_records.ts feat(runner): add Codex-native application integration (#12591) 2026-08-31 14:38:38 -05:00
remote_agent_profiles.ts feat(runner): add managed provider backends (#12699) 2026-09-02 00:48:30 -05:00
routine_documents.ts fix: upstream deployed document-comment, routine-annotation, workspace & board-polling fixes (#8536) 2026-06-23 09:00:14 -05:00
routines.ts feat: organize skills with nested folders and My Skills (#9633) 2026-07-16 15:50:45 -05:00
secret_access_events.ts feat(secrets): add user-specific runtime secrets (#8825) 2026-07-05 05:58:20 -05:00
smoke_lab.ts feat(mcp) [split 2/8]: add governed access contracts (#9557) 2026-07-14 12:57:20 -05:00
status_cards.ts feat(status-cards): join summary-mentioned issues to watched set (#10205) 2026-07-24 16:44:56 -05:00
status_decision_effects.ts feat(runner): add native persistence contracts (#12169) 2026-08-25 13:08:39 -05:00
status_decisions.ts feat(runner): add native persistence contracts (#12169) 2026-08-25 13:08:39 -05:00
summary_slots.ts feat: add built-in summarizer and summary slots (#9713) 2026-07-17 11:03:07 -05:00
tool_access.ts feat(connections): add durable GitHub identities and webhooks (#12843) 2026-09-04 18:02:52 -05:00
user_inbox_agent_policies.ts feat(authz): govern agent inbox archive access (#9658) 2026-07-16 09:51:48 -05:00
user_secret_declarations.ts feat(secrets): add user-specific runtime secrets (#8825) 2026-07-05 05:58:20 -05:00
user_secret_definitions.ts feat(secrets): add user-specific runtime secrets (#8825) 2026-07-05 05:58:20 -05:00
user_sidebar_preferences.ts [codex] Improve workspace runtime and navigation ergonomics (#3680) 2026-04-14 12:57:11 -05:00
work_assessments.ts feat(runner): add native persistence contracts (#12169) 2026-08-25 13:08:39 -05:00
workspace_operations.ts fix: upstream deployed document-comment, routine-annotation, workspace & board-polling fixes (#8536) 2026-06-23 09:00:14 -05:00
workspace_runtime_services.ts feat(runtime-exposure): least-privilege Tailscale HTTPS broker, shared contract, and persisted exposure state (#11524) 2026-08-17 05:54:12 -04:00