Files
PaperClipAI/packages
Chen Yufeiyang ed262f2e9a fix(adapter-utils): protect nested clone .git directories during workspace copy-back (#18534)
## Thinking Path

> - Paperclip runs agents in local, SSH and sandbox environments.
> - A remote run uploads the agent workspace to the execution host. At
the end the adapter copies the workspace back.
> - The upload excludes Git metadata with the `.git` archive exclude
list.
> - The copy-back uses the same list to decide what it may delete. The
list only matched the top-level `.git` directory.
> - The upload left out nested clones' `.git` data. The copy-back
treated that data as deleted in the sandbox.
> - The copy-back then removed `repo/.git` on the host. Unpushed commits
and branches were lost.
> - This pull request adds the nested patterns that the heavy-directory
excludes already use.
> - The benefit is that a copy-back never deletes Git data that the
upload left out.

## Linked Issues or Issue Description

Fixes: #18299

Refs: #15959 (the same exclude list inconsistency for SSH workspaces)

## What Changed

- Add `*/.git` and `*/.git/*` to `GIT_ARCHIVE_EXCLUDES`. The restore
baseline exclude now matches a nested `.git` at any depth, like the tar
upload already does.
- Add a regression test. The test captures a baseline that contains
`repo/.git` and asserts that the nested `.git` is excluded.

## Verification

- `pnpm vitest run
packages/adapter-utils/src/workspace-restore-merge.test.ts` -> the new
test passes; 47 passed.
- Before the change, the same test fails with `expected true to be
false` because the baseline contained `repo/.git/config`.
- `pnpm --filter @paperclipai/adapter-utils exec tsc --noEmit` -> pass.
- `pnpm vitest run
packages/adapter-utils/src/remote-managed-runtime.test.ts` -> 7 passed.
- `git-workspace-sync.test.ts` and `sandbox-managed-runtime.test.ts`
show the same environment failures with and without the change (8 and
40; local Node 23.11 `node:sqlite` `Incomplete workspace manifest`).
This change adds no failure.
- A live sandbox copy-back is not available locally. After merge, run
one sandbox run with a nested clone in the workspace and confirm that
`repo/.git` stays on the host.

## Risks

- The copy-back no longer removes nested `.git` data. This is intended:
the upload does not send that data to the sandbox.
- The tar upload now names the nested patterns explicitly. The tar
behavior does not change because the old `.git` pattern already matched
at any depth.
- `workspaceFileMode: "all"` keeps the old behavior; it does not use
these excludes.

## Model Used

- DeepSeek V4.1 Flash (model id: `deepseek-v4.1-flash`). Provider:
DeepSeek.
- Capabilities: extended reasoning, tool use, shell command execution,
file edits and test execution.
- No other AI model was used for this change.

## 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
- [x] My branch name describes the change
(`fix/sandbox-nested-git-exclude`) and contains no internal ticket id
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [ ] I have updated relevant documentation to reflect my changes — no
docs page describes this internal exclude list
- [x] I have considered and documented any risks above
- [ ] All Paperclip CI gates are green — CI starts after this PR
- [ ] Greptile is 5/5 with no open P2s — review starts after this PR
- [x] I will address all Greptile and reviewer comments before
requesting merge
2026-12-05 03:08:54 -08:00
..