Skip to content

Workspace & Directory APIs: patch conflicts, overlay search, path removal - #13777

Merged
vito merged 7 commits into
mainfrom
llm-workspace-workspace-apis
Aug 4, 2026
Merged

vito merged 7 commits into
mainfrom
llm-workspace-workspace-apis

Conversation

@vito

@vito vito commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Additive Workspace and Directory API surface, independent of the LLM work above it.

  • Directory.withPatch(onConflict:) — a new conflict mode that degrades drifted hunks into labeled conflict markers instead of failing the patch. This is what makes a recorded session survive a checkout that moved underneath it.
  • Overlay-aware Workspace.search / glob — both read through the overlay, so a file an agent just wrote is findable without exporting it first.
  • Workspace.withoutFile / withoutDirectory — the overlay could add and modify paths but had no way to remove one, so deleting a file meant dropping to the underlying Directory and losing the overlay. Removals are now recorded in the overlay like any other edit.
  • Workspace.git follows .git pointers, so a worktree or submodule checkout resolves to its real repository.

Patches recorded during an LLM session get replayed when a saved
session is loaded, and by then the workspace content may have drifted:
git apply fails outright and the session cannot resume. The new
onConflict mode LEAVE_CONFLICT_MARKERS applies with --reject, converts
each rejected hunk's .rej into a git-style conflict block inserted at
the hunk's recorded position (current content around it, the hunk's
intended result inside), removes the .rej, and warns on the span's
stderr listing the conflicted files. Placement is best-effort by
nature - the content drifted, which is why the hunk rejected - but the
markers are labeled and grep-able, which is what a resuming agent needs
to resolve them. The default remains FAIL.

Signed-off-by: Alex Suraci <[email protected]>
vito added 6 commits July 31, 2026 14:34
Workspace.search and Workspace.glob on a host-backed workspace ran
entirely against the host filesystem, so pending overlay edits were
invisible: a file modified through the overlay kept matching its stale
host content, and removed or newly created files were missed entirely.
Notably, after restoring an LLM session the model could not find its
own conflict markers.

Both APIs now merge the host results with an in-engine pass over the
overlay's delta root, with per-path replacement: the overlay's view
wins for every path its edits touch, so modified files serve overlay
content, removed paths drop out, and created ones appear, while
untouched paths keep serving host results. Explicit search paths apply
to the overlay side as a post-filter since the sparse delta lacks
host-only paths, and the limit caps the merged, sorted set.

Signed-off-by: Alex Suraci <[email protected]>
Workspace could add and modify paths through the overlay but had no way to
remove one, so deleting a file meant dropping to the underlying Directory
and losing the overlay. Add withoutFile and withoutDirectory, which record
the removal in the overlay like any other edit.

Signed-off-by: Alex Suraci <[email protected]>
Git worktree and submodule checkouts don't have a .git *directory* at
the tree root: they have a .git pointer file (a "gitfile") whose gitdir
target lives outside the workspace boundary. Workspace.git previously
bailed out on such a checkout with "git worktrees are not supported by
Workspace.git yet: .git is a file", so head/uncommitted queries failed
outright from a linked worktree or submodule.

Port the gitfile resolution already used for contextual module git args
(see ModuleSource.resolveGitPointer) to workspaces: extract the flatten
logic into a reusable core.FlattenGitPointer, which resolves the pointer
against the host, loads the real git directory (plus the shared common
directory for worktrees), and flattens everything into a standalone .git
directory in the snapshot. Workspace.git now follows the pointer through
its owning client session, so a worktree/submodule checkout behaves like
a plain clone -- reporting the per-worktree HEAD and detecting uncommitted
changes.

ensureWorkspaceGitDirectory no longer rejects a regular .git file, since
the pointer is followed and flattened when the repository is resolved.

Replace TestWorkspaceGitWorktreeUnsupported with TestWorkspaceGitWorktree,
which diverges the linked worktree's HEAD from the main checkout to prove
the per-worktree state is honored and asserts uncommitted changes are
detected.

Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
golangci-lint's nolintlint flags the dupl suppressions on withPatchFile
and withChanges as unused: dupl no longer considers the two functions
duplicates, so the directives suppress nothing.

Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
@vito
vito force-pushed the llm-workspace-workspace-apis branch from afbeb29 to 9aa1aa4 Compare July 31, 2026 18:35
@vito vito added this to the v1.0.0 milestone Aug 4, 2026
@vito
vito merged commit cec27f3 into main Aug 4, 2026
88 checks passed
@vito
vito deleted the llm-workspace-workspace-apis branch August 4, 2026 18:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants