@bivy/bivy 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -32,7 +32,7 @@ export function parseGitHubRemote(input) {
32
32
  /** Infer owner/repo from a workspace's origin remote, if it is a GitHub checkout. */
33
33
  export async function inferGitHubRepoFromWorkspace(workspace) {
34
34
  try {
35
- const { stdout } = await exec("git", ["-C", workspace, "remote", "get-url", "origin"]);
35
+ const { stdout } = await exec("git", ["-C", workspace, "remote", "get-url", "origin"], { cwd: workspace });
36
36
  return parseGitHubRemote(stdout);
37
37
  }
38
38
  catch {
@@ -65,7 +65,7 @@ export async function resolveGitHubToken(env = process.env) {
65
65
  */
66
66
  export async function fetchOrigin(repoDir) {
67
67
  try {
68
- await exec("git", ["-C", repoDir, "fetch", "origin", "--prune"], { timeout: 120_000 });
68
+ await exec("git", ["-C", repoDir, "fetch", "origin", "--prune"], { cwd: repoDir, timeout: 120_000 });
69
69
  }
70
70
  catch {
71
71
  // offline / no origin / no rights — branch off the refs we already have.
@@ -80,7 +80,7 @@ export async function fetchOrigin(repoDir) {
80
80
  export async function resolveDefaultBaseRef(repoDir) {
81
81
  // origin/HEAD points at the remote's default branch when it's been recorded.
82
82
  try {
83
- const { stdout } = await exec("git", ["-C", repoDir, "symbolic-ref", "--short", "refs/remotes/origin/HEAD"]);
83
+ const { stdout } = await exec("git", ["-C", repoDir, "symbolic-ref", "--short", "refs/remotes/origin/HEAD"], { cwd: repoDir });
84
84
  const ref = stdout.trim();
85
85
  if (ref)
86
86
  return ref; // e.g. "origin/main"
@@ -89,8 +89,8 @@ export async function resolveDefaultBaseRef(repoDir) {
89
89
  // origin/HEAD is often unset on a fresh clone — record it, then retry.
90
90
  }
91
91
  try {
92
- await exec("git", ["-C", repoDir, "remote", "set-head", "origin", "--auto"]);
93
- const { stdout } = await exec("git", ["-C", repoDir, "symbolic-ref", "--short", "refs/remotes/origin/HEAD"]);
92
+ await exec("git", ["-C", repoDir, "remote", "set-head", "origin", "--auto"], { cwd: repoDir });
93
+ const { stdout } = await exec("git", ["-C", repoDir, "symbolic-ref", "--short", "refs/remotes/origin/HEAD"], { cwd: repoDir });
94
94
  const ref = stdout.trim();
95
95
  if (ref)
96
96
  return ref;
@@ -112,7 +112,7 @@ export async function resolveDefaultBaseRef(repoDir) {
112
112
  export async function resolveBranchBaseRef(repoDir, branch) {
113
113
  const ref = `origin/${branch}`;
114
114
  try {
115
- await exec("git", ["-C", repoDir, "rev-parse", "--verify", "--quiet", ref]);
115
+ await exec("git", ["-C", repoDir, "rev-parse", "--verify", "--quiet", ref], { cwd: repoDir });
116
116
  return ref;
117
117
  }
118
118
  catch {
@@ -131,7 +131,7 @@ export async function isReusableCheckout(dest) {
131
131
  if (!fs.existsSync(path.join(dest, ".git")))
132
132
  return false;
133
133
  try {
134
- await exec("git", ["-C", dest, "rev-parse", "--show-toplevel"]);
134
+ await exec("git", ["-C", dest, "rev-parse", "--show-toplevel"], { cwd: dest });
135
135
  return true;
136
136
  }
137
137
  catch {
@@ -177,15 +177,15 @@ export async function cloneOrUpdateRepo(opts) {
177
177
  try {
178
178
  // Rewrite origin to the clean URL. This also MIGRATES any pre-existing
179
179
  // clone whose remote still carries an embedded token from before this fix.
180
- await exec("git", ["-C", dest, "remote", "set-url", "origin", url]);
181
- await configureRepoCredentialHelper((a) => exec("git", a), dest);
182
- await exec("git", ["-C", dest, ...cc, "fetch", "--all", "--prune"], { timeout: 120_000, env });
180
+ await exec("git", ["-C", dest, "remote", "set-url", "origin", url], { cwd: dest });
181
+ await configureRepoCredentialHelper((a) => exec("git", a, { cwd: dest }), dest);
182
+ await exec("git", ["-C", dest, ...cc, "fetch", "--all", "--prune"], { cwd: dest, timeout: 120_000, env });
183
183
  // Re-point origin/HEAD at the remote's CURRENT default branch. Without
184
184
  // this a cached checkout keeps whatever default it recorded at first
185
185
  // clone, so if the repo's default later changed (e.g. main → master) a new
186
186
  // session would branch off the stale remote default. --auto is best-effort
187
187
  // and only rewrites the local origin/HEAD pointer, never a branch.
188
- await exec("git", ["-C", dest, "remote", "set-head", "origin", "--auto"]);
188
+ await exec("git", ["-C", dest, "remote", "set-head", "origin", "--auto"], { cwd: dest });
189
189
  }
190
190
  catch {
191
191
  // offline / fetch failed — reuse the existing checkout as-is
@@ -200,9 +200,15 @@ export async function cloneOrUpdateRepo(opts) {
200
200
  // session" fail with "destination exists" or "Not a git repository".
201
201
  if (fs.existsSync(dest))
202
202
  fs.rmSync(dest, { recursive: true, force: true });
203
- await exec("git", [...cc, "clone", url, dest], { timeout: 600_000, env });
203
+ // Always give child_process a real cwd. The daemon may still be serving while
204
+ // an npm-global update atomically replaces its install directory; inheriting
205
+ // that now-unlinked cwd makes git abort before it can even process `clone`
206
+ // ("Unable to read current working directory"). The repos root is durable
207
+ // across package updates and was created immediately above.
208
+ await exec("git", [...cc, "clone", url, dest], { cwd: opts.root, timeout: 600_000, env });
204
209
  // Persist the helper config so agent-run git in this clone authenticates too.
205
- await configureRepoCredentialHelper((a) => exec("git", a), dest);
210
+ // These follow-up processes need an explicit cwd for the same reason.
211
+ await configureRepoCredentialHelper((a) => exec("git", a, { cwd: dest }), dest);
206
212
  hardenGitConfigPerms(dest);
207
213
  return dest;
208
214
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bivy/bivy",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "type": "module",
5
5
  "license": "FSL-1.1-ALv2",
6
6
  "description": "Run coding agents on machines you own. Source-available, self-hostable agent workspace.",