feat(coding-agent): add .gitignore to package manager install roots

This commit is contained in:
Mario Zechner 2026-01-21 16:43:21 +01:00
parent f832a96bda
commit 2b656c266b

View file

@ -92,6 +92,7 @@ export class DefaultPackageManager implements PackageManager {
this.cwd = options.cwd;
this.agentDir = options.agentDir;
this.settingsManager = options.settingsManager;
this.ensureGitIgnoreDirs();
}
setProgressCallback(callback: ProgressCallback | undefined): void {
@ -436,6 +437,7 @@ export class DefaultPackageManager implements PackageManager {
if (!existsSync(installRoot)) {
mkdirSync(installRoot, { recursive: true });
}
this.ensureGitIgnore(installRoot);
const packageJsonPath = join(installRoot, "package.json");
if (!existsSync(packageJsonPath)) {
const pkgJson = { name: "pi-extensions", private: true };
@ -443,6 +445,23 @@ export class DefaultPackageManager implements PackageManager {
}
}
private ensureGitIgnoreDirs(): void {
this.ensureGitIgnore(join(this.agentDir, "git"));
this.ensureGitIgnore(join(this.agentDir, "npm"));
this.ensureGitIgnore(join(this.cwd, CONFIG_DIR_NAME, "git"));
this.ensureGitIgnore(join(this.cwd, CONFIG_DIR_NAME, "npm"));
}
private ensureGitIgnore(dir: string): void {
if (!existsSync(dir)) {
mkdirSync(dir, { recursive: true });
}
const ignorePath = join(dir, ".gitignore");
if (!existsSync(ignorePath)) {
writeFileSync(ignorePath, "*\n!.gitignore\n", "utf-8");
}
}
private getNpmInstallRoot(scope: SourceScope, temporary: boolean): string {
if (temporary) {
return this.getTemporaryDir("npm");