@ferris1225/pi-subagents 4.0.1 → 4.1.2

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.
package/src/worktree.ts CHANGED
@@ -298,11 +298,18 @@ export function isPathInside(root: string, candidate: string): boolean {
298
298
  return rel === "" || (!rel.startsWith("..") && !isAbsolute(rel));
299
299
  }
300
300
 
301
- /** Resolve and validate the Git repository/worktree that contains cwd. */
302
- export async function resolveWorktreeTarget(
301
+ interface RepositoryLocation {
302
+ originalCwd: string;
303
+ originalRoot: string;
304
+ }
305
+
306
+ /** Resolve the canonical repository root without requiring a committed HEAD.
307
+ * Managed repository lanes use this for empty repositories as well as normal
308
+ * worktrees; worktree creation validates HEAD separately below. */
309
+ async function resolveRepositoryLocation(
303
310
  cwd: string,
304
- runner: CommandRunner = runCommand,
305
- ): Promise<WorktreeTarget> {
311
+ runner: CommandRunner,
312
+ ): Promise<RepositoryLocation> {
306
313
  const requested = resolve(cwd);
307
314
  try {
308
315
  if (!(await stat(requested)).isDirectory()) throw new Error("not a directory");
@@ -335,6 +342,22 @@ export async function resolveWorktreeTarget(
335
342
  `Requested cwd ${originalCwd} is not inside Git worktree root ${originalRoot}.`,
336
343
  );
337
344
  }
345
+ return { originalCwd, originalRoot };
346
+ }
347
+
348
+ export async function resolveRepositoryRoot(
349
+ cwd: string,
350
+ runner: CommandRunner = runCommand,
351
+ ): Promise<string> {
352
+ return (await resolveRepositoryLocation(cwd, runner)).originalRoot;
353
+ }
354
+
355
+ /** Resolve and validate the Git repository/worktree that contains cwd. */
356
+ export async function resolveWorktreeTarget(
357
+ cwd: string,
358
+ runner: CommandRunner = runCommand,
359
+ ): Promise<WorktreeTarget> {
360
+ const { originalCwd, originalRoot } = await resolveRepositoryLocation(cwd, runner);
338
361
  let headResult: CommandResult;
339
362
  try {
340
363
  headResult = await runGit(