feat(workspace): clone-based Workspace adapter#34
Open
harshitsinghbhandari wants to merge 1 commit into
Open
Conversation
Adds backend/internal/adapters/workspace/clone alongside the existing gitworktree adapter. Same ports.Workspace surface (no new methods); per session the adapter does a full `git clone` into managedRoot/<project>/<session> instead of a worktree register. Key choices vs the upstream TypeScript reference: - Plain `git clone` (no --reference / --shared) so concurrent clones from the same source never contend on a shared lock file or alternates DB. - Destroy never passes --force and has no Force escape hatch; refuses when `git status --porcelain` is non-empty (mirrors the RA fix on PR #23). - validatePathComponent + validateManagedPath reject ids and paths that could escape managedRoot, including symlink ladders (RB fix parity). - Restore reuses an existing valid clone after verifying its origin URL matches the configured repo; mismatched origin returns ErrOriginMismatch. Tests use a programmable exec runner only — no real git is invoked.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #aa-25
Summary
Adds
backend/internal/adapters/workspace/clone/alongside the existinggitworktreeadapter. Sameports.Workspacesurface — no new port methods. Per session, this adapter does a fullgit cloneinto<managedRoot>/<project>/<session>instead of registering a worktree.clone vs worktree
gitworktreeclone(this PR).git/; worktree register on the source.git/per sessionworktrees/registry.git/index.lock; source's pack files are read-onlygit worktree remove(no--force) + post-prune still-registered guardgit status --porcelaindirty check +os.RemoveAll(no--forceever, no escape hatch)Design notes ported from the upstream TS reference
<managedRoot>/<projectID>/<sessionID>(same shape as gitworktree).checkout -b <branch>with fallback to plaincheckout <branch>when the branch already exists (mirrors upstream's branch-collision fallback).Listrather than failing the whole call.Upstream ideas NOT ported (and why)
git clone --reference <source>— concurrent clones from the same source would alias each other's object DB and create a coupled failure mode if the source were repacked/pruned. The task's hard requirement for race-free concurrent clones rules this out.recordActivityEventtelemetry (branch_collision, corrupt_clone_skipped) — would require a new outbound port; explicitly out of scope per the task ("No new port methods").postCreatelifecycle hook — not part ofports.Workspace; same reasoning.getShell()/ Windows shell abstraction — task scope is macOS/Linux only.exists()method on the adapter — not in the Go port;Restorefolds the existence check inline.~home-directory expansion — left to theRepoResolvercaller, where path conventions belong.Hard requirements met
ports.Workspaceinterface, asserted byvar _ ports.Workspace = (*Workspace)(nil).commandRunner(same pattern as gitworktree); all 39 unit tests use it — no real git is invoked.validatePathComponentrejects ids with separators /./..;validateManagedPathresolves symlinks (physicalAbs) before checking containment. Mirrors PR fix: address LCM/SM review blockers R1, RA, R11, RB #23's RB fix. Tested for.., absolute-outside-root, symlink ladder, empty, and relative paths.--force.Destroyrefuses ifgit status --porcelainis non-empty; noForcefield exists on the adapter or the port.TestCommandArgsNeverUseForceis a belt-and-braces guard that pins this for every arg builder. Mirrors PR fix: address LCM/SM review blockers R1, RA, R11, RB #23's RA fix.git clone <source> <dest>works against both transparently; documented in package doc.Test plan
go build ./...cleango test ./...— 289 passed in 14 packages (39 new tests in the clone package, full suite still green).., absolute outside root, symlink ladder, empty, relative) all rejected withErrUnsafePathDestroywithErrDirtyWorkspace; directory preservedErrOriginMismatchTestCommandArgsNeverUseForceregression guard🤖 Generated with Claude Code