Skip to content

fix(sandbox): detect repository root when the requested path is nested inside a repo (#65)#75

Open
shadaj wants to merge 1 commit into
mainfrom
sandbox-35738e94-eb27-402f-94c2-ac6f42eec405
Open

fix(sandbox): detect repository root when the requested path is nested inside a repo (#65)#75
shadaj wants to merge 1 commit into
mainfrom
sandbox-35738e94-eb27-402f-94c2-ac6f42eec405

Conversation

@shadaj

@shadaj shadaj commented Jul 14, 2026

Copy link
Copy Markdown
Member
  • Add sandbox_core::find_repo_root, which walks up from a path to the
    closest ancestor containing a .jj directory or a .git entry
    (directory, or file for worktrees/submodules). This makes jj repos
    detectable when the cwd is inside a nested folder — jj subdirectories
    carry no marker of their own, so the previous path.join(".jj") check
    silently fell through to git mode (or failed entirely for
    non-colocated jj repos).
  • LocalBackend::init_repo now resolves the requested path to the
    repository root before storing it as the remote URI, so sandboxes are
    always created from the repo root. Falls back to the path as given
    when no root is found, preserving existing error paths.
  • clone_repo and open_sandbox_direct responses now include a note
    when the detected repository root differs from the requested path,
    telling the agent that the sandbox operates on the whole repository
    and that file paths are relative to the root.
  • The migration-import cwd check also walks up to the repo root instead
    of requiring cwd to be the root itself.
  • Add integration tests (nested_repo_root.rs) covering jj and git
    clones from nested directories (mode detection + root note + reads
    relative to the root) and the no-note case when cloning from the root.

Fixes #65

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 14, 2026

Copy link
Copy Markdown

Deploying infinity with  Cloudflare Pages  Cloudflare Pages

Latest commit: 0a2fd62
Status: ✅  Deploy successful!
Preview URL: https://24c19e77.infinity-dc7.pages.dev
Branch Preview URL: https://sandbox-35738e94-eb27-402f-9.infinity-dc7.pages.dev

View logs

…d inside a repo (#65)

* Add `sandbox_core::find_repo_root`, which walks up from a path to the
  closest ancestor containing a `.jj` directory or a `.git` entry
  (directory, or file for worktrees/submodules). This makes jj repos
  detectable when the cwd is inside a nested folder — jj subdirectories
  carry no marker of their own, so the previous `path.join(".jj")` check
  silently fell through to git mode (or failed entirely for
  non-colocated jj repos).
* `LocalBackend::init_repo` now resolves the requested path to the
  repository root before storing it as the remote URI, so sandboxes are
  always created from the repo root. Falls back to the path as given
  when no root is found, preserving existing error paths.
* `clone_repo` and `open_sandbox_direct` responses now include a note
  when the detected repository root differs from the requested path,
  telling the agent that the sandbox operates on the whole repository
  and that file paths are relative to the root.
* The migration-import cwd check also walks up to the repo root instead
  of requiring cwd to be the root itself.
* Add integration tests (`nested_repo_root.rs`) covering jj and git
  clones from nested directories (mode detection + root note + reads
  relative to the root) and the no-note case when cloning from the root.

Co-authored-by: Infinity 🤖 <infinity@hydro.run>
PR: #75
@shadaj
shadaj marked this pull request as ready for review July 14, 2026 21:39
@shadaj
shadaj requested a review from MingweiSamuel July 14, 2026 21:39
@shadaj
shadaj force-pushed the sandbox-35738e94-eb27-402f-94c2-ac6f42eec405 branch from ac1263e to 0a2fd62 Compare July 14, 2026 21:52
Comment on lines +565 to +569
Ok(match root_note {
Some(note) => format!("{msg}{note}"),
None => msg,
})
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: prefer if let Some(x) = on options

tracing::info!(group_id = %invocation.group_id, remote = %remote_uri, "opened direct sandbox");
Ok("Repository initialized (Direct mode — file edits require approval, commands run without file write access unless write-orig is granted).".to_owned())
let mut msg = "Repository initialized (Direct mode — file edits require approval, commands run without file write access unless write-orig is granted).".to_owned();
if let Some(note) = repo_root_note(&args.repo, Path::new(&remote_uri)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the difference between repo and remote_uri here? Is it possible to have a direct sandbox on a non-VCS directory?

also nit: would be nice if the msg ++ note concatenation was the same in both methods

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.

Opening sandbox should identify repository root and include in tool response if different than requested path

2 participants