Files
PaperClipAI/server
Dotta 1fb8ddb740 feat(trust): allow transient workspace_prepare checkout for low-trust in-boundary projects (#23656)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - The low-trust review preset isolates untrusted review agents inside
sandboxes with no runtime GitHub tokens and no sandbox network access
> - When a low-trust agent is explicitly assigned to a
private-repository project with `git.read` enabled, workspace
preparation routed the setup-time clone through
`resolveGitHubOperationCredentials`, which blocks all low-trust
credential export and caused `stage=clone git=auth_failed exit=128`
before the agent could start
> - Setup-time `prepareRemoteWorkspaceDirectory` runs on the trusted
controller path before the agent starts, uses transient `GIT_CONFIG_*` /
`PAPERCLIP_GIT_TOKEN` environment variables with `-c
core.hooksPath=/dev/null`, and writes zero credentials into
`.git/config`
> - This pull request adds `resolveGitHubWorkspacePrepareCredentials`
for controller-only `workspace_prepare` call sites, allowing transient
clone credentials strictly for a repository configured on a project
inside `trustBoundary.projectIds` when `git.read` is permitted
(preferring an agent-installed GitHub PAT connection when present),
while keeping runtime shell credentials
(`resolveGitHubOperationCredentials`) strictly denied
> - The benefit is that assigning a low-trust agent to a private-repo
project works out of the box for local read-only code review without
exposing any live GitHub token to the agent runtime

## Linked Issues or Issue Description

**What happened?**
When an agent configured with `trustPreset: "low_trust_review"` and
`allowedToolClasses: ["git.read"]` was assigned a task in a project with
a private GitHub repository workspace, workspace preparation failed
before the agent started with `remote_workspace_prepare_failed:
stage=clone git=auth_failed exit=128 program=git`.

**Expected behavior**
When a `low_trust_review` run has `git.read` enabled and targets a
project explicitly listed in `trustBoundary.projectIds`, the trusted
controller should clone that project's configured repository during
`workspace_prepare` using transient credentials (preferring an
agent-installed GitHub PAT connection if configured, otherwise the run's
managed GitHub identity), while leaving zero credentials in
`.git/config` and keeping runtime GitHub credential export strictly
denied.

**Steps to reproduce**
1. Create a project with a private GitHub repository workspace.
2. Configure an agent with `trustPreset: "low_trust_review"`,
`projectIds: [projectId]`, and `allowedToolClasses: ["git.read"]`.
3. Run a task in that project on a cloud sandbox environment.
4. Before this fix, `createGitRemoteAuthProvider` falls back to
anonymous clone and fails at `stage=clone git=auth_failed exit=128`.

**Paperclip version or commit**
`master` (`23ca89e376`)

## What Changed

- **`server/src/services/github-operation-credentials.ts`**: Added
`resolveGitHubWorkspacePrepareCredentials`,
`allowsLowTrustWorkspacePrepareCheckout`, and
`resolveAgentInstalledGitHubPat`. For `low_trust_review` runs, transient
prepare-time clone auth is permitted only when `trust.kind ===
"low_trust_review"`, `git.read` is in `allowedToolClasses`, the task's
project is explicitly in `trustBoundary.projectIds`, and `remoteUrl`
matches a configured `project_workspaces.repo_url` on that project.
Prefers an active agent-installed GitHub `api_key` (PAT) connection when
present and otherwise falls back to `resolveManagedGitHubCredential`.
Runtime `resolveGitHubOperationCredentials` remains unchanged and
strictly denied for low-trust runs.
- **`server/src/services/git-credentials.ts`**: Added optional
`purpose?: "workspace_prepare"` to `createGitRemoteAuthProvider` so only
controller workspace-preparation call sites invoke
`resolveGitHubWorkspacePrepareCredentials`.
- **`server/src/services/heartbeat/workspace-preparation.ts`** and
**`server/src/services/heartbeat/workspaces.ts`**: Passed `purpose:
"workspace_prepare"` at the four controller workspace-preparation call
sites.
- **`server/src/__tests__/github-operation-credentials.test.ts`**: Added
unit, security-boundary, and end-to-end
`prepareRemoteWorkspaceDirectory` tests covering managed identity
prepare checkout, agent-installed GitHub PAT preference, runtime
credential denial, unrelated repo denial, missing `git.read` denial, and
zero credentials persisted in `.git/config`.

## Verification

- `pnpm --filter @paperclipai/server typecheck` — passed with 0 errors.
- `pnpm --filter @paperclipai/server exec vitest run
src/__tests__/github-operation-credentials.test.ts` — 30/30 passed
(including the 3 new low-trust `workspace_prepare` and local E2E
`prepareRemoteWorkspaceDirectory` tests).

## Risks

- Low risk. Runtime agent credential endpoints
(`/runtime-tools/github/credentials`, native GitHub broker, skill-source
fetch) continue calling `resolveGitHubOperationCredentials` and stay
strictly denied for `low_trust_review`.
- Prepare-time credentials are scoped strictly to repositories already
configured in `project_workspaces` for a project explicitly inside
`trustBoundary.projectIds` and only when `git.read` is enabled.

## Model Used

- Google Gemini (Antigravity agentic coding assistant) with tool use and
local code/test execution.

## 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
- [ ] All Paperclip CI gates are green
- [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [ ] I will address all Greptile and reviewer comments before
requesting merge
2026-12-03 15:41:55 -06:00
..