@posthog/agent 1.27.0 → 1.28.0
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/dist/index.js +32 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/worktree-manager.ts +45 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@posthog/agent",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.28.0",
|
|
4
4
|
"repository": "https://github.com/PostHog/array",
|
|
5
5
|
"description": "TypeScript agent framework wrapping Claude Agent SDK with Git-based task execution for PostHog",
|
|
6
6
|
"main": "./dist/index.js",
|
package/src/worktree-manager.ts
CHANGED
|
@@ -686,6 +686,51 @@ export class WorktreeManager {
|
|
|
686
686
|
}
|
|
687
687
|
|
|
688
688
|
async deleteWorktree(worktreePath: string): Promise<void> {
|
|
689
|
+
const resolvedWorktreePath = path.resolve(worktreePath);
|
|
690
|
+
const resolvedMainRepoPath = path.resolve(this.mainRepoPath);
|
|
691
|
+
|
|
692
|
+
// Safety check 1: Never delete the main repo path
|
|
693
|
+
if (resolvedWorktreePath === resolvedMainRepoPath) {
|
|
694
|
+
const error = new Error(
|
|
695
|
+
"Cannot delete worktree: path matches main repo path",
|
|
696
|
+
);
|
|
697
|
+
this.logger.error("Safety check failed", { worktreePath, error });
|
|
698
|
+
throw error;
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
// Safety check 2: Never delete a parent of the main repo path
|
|
702
|
+
if (
|
|
703
|
+
resolvedMainRepoPath.startsWith(resolvedWorktreePath) &&
|
|
704
|
+
resolvedMainRepoPath !== resolvedWorktreePath
|
|
705
|
+
) {
|
|
706
|
+
const error = new Error(
|
|
707
|
+
"Cannot delete worktree: path is a parent of main repo path",
|
|
708
|
+
);
|
|
709
|
+
this.logger.error("Safety check failed", { worktreePath, error });
|
|
710
|
+
throw error;
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
// Safety check 3: Check for .git directory (indicates main repo)
|
|
714
|
+
try {
|
|
715
|
+
const gitPath = path.join(resolvedWorktreePath, ".git");
|
|
716
|
+
const stat = await fs.stat(gitPath);
|
|
717
|
+
if (stat.isDirectory()) {
|
|
718
|
+
const error = new Error(
|
|
719
|
+
"Cannot delete worktree: path appears to be a main repository (contains .git directory)",
|
|
720
|
+
);
|
|
721
|
+
this.logger.error("Safety check failed", { worktreePath, error });
|
|
722
|
+
throw error;
|
|
723
|
+
}
|
|
724
|
+
} catch (error) {
|
|
725
|
+
// If .git doesn't exist or we can't read it, proceed (unless it was the directory check above)
|
|
726
|
+
if (
|
|
727
|
+
error instanceof Error &&
|
|
728
|
+
error.message.includes("Cannot delete worktree")
|
|
729
|
+
) {
|
|
730
|
+
throw error;
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
|
|
689
734
|
this.logger.info("Deleting worktree", { worktreePath });
|
|
690
735
|
|
|
691
736
|
try {
|