fix(pi): discover ancestor project resources

This commit is contained in:
2026-10-15 17:58:52 -04:00
parent 6081e3e325
commit e479aeff7e

View File

@@ -471,14 +471,14 @@ function findGitRepoRoot(startDir: string): string | null {
} }
} }
function collectAncestorAgentsSkillDirs(startDir: string): string[] { function collectAncestorConfigDirs(startDir: string, configDirName: string): string[] {
const skillDirs: string[] = []; const configDirs: string[] = [];
const resolvedStartDir = resolve(startDir); const resolvedStartDir = resolve(startDir);
const gitRepoRoot = findGitRepoRoot(resolvedStartDir); const gitRepoRoot = findGitRepoRoot(resolvedStartDir);
let dir = resolvedStartDir; let dir = resolvedStartDir;
while (true) { while (true) {
skillDirs.push(join(dir, ".agents", "skills")); configDirs.push(join(dir, configDirName));
if (gitRepoRoot && dir === gitRepoRoot) { if (gitRepoRoot && dir === gitRepoRoot) {
break; break;
} }
@@ -489,7 +489,7 @@ function collectAncestorAgentsSkillDirs(startDir: string): string[] {
dir = parent; dir = parent;
} }
return skillDirs; return configDirs;
} }
function collectAutoPromptEntries(dir: string): string[] { function collectAutoPromptEntries(dir: string): string[] {
@@ -2455,16 +2455,13 @@ export class DefaultPackageManager implements PackageManager {
prompts: join(globalBaseDir, "prompts"), prompts: join(globalBaseDir, "prompts"),
themes: join(globalBaseDir, "themes"), themes: join(globalBaseDir, "themes"),
}; };
const projectDirs = {
extensions: join(projectBaseDir, "extensions"),
skills: join(projectBaseDir, "skills"),
prompts: join(projectBaseDir, "prompts"),
themes: join(projectBaseDir, "themes"),
};
const userAgentsSkillsDir = join(getHomeDir(), ".agents", "skills"); const userAgentsSkillsDir = join(getHomeDir(), ".agents", "skills");
const projectTrusted = this.settingsManager.isProjectTrusted(); const projectTrusted = this.settingsManager.isProjectTrusted();
const projectAgentsSkillDirs = projectTrusted const projectConfigDirs = projectTrusted
? collectAncestorAgentsSkillDirs(this.cwd).filter((dir) => resolve(dir) !== resolve(userAgentsSkillsDir)) ? collectAncestorConfigDirs(this.cwd, CONFIG_DIR_NAME).filter((dir) => resolve(dir) !== resolve(globalBaseDir))
: [];
const projectAgentsDirs = projectTrusted
? collectAncestorConfigDirs(this.cwd, ".agents").filter((dir) => resolve(dir) !== resolve(dirname(userAgentsSkillsDir)))
: []; : [];
const addResources = ( const addResources = (
@@ -2481,56 +2478,54 @@ export class DefaultPackageManager implements PackageManager {
} }
}; };
if (projectTrusted) { // Project resources from .pi/ in cwd and ancestors.
// Project extensions from .pi/ for (const configDir of projectConfigDirs) {
addResources( const configMetadata: PathMetadata = {
"extensions",
collectAutoExtensionEntries(projectDirs.extensions),
projectMetadata,
projectOverrides.extensions,
projectBaseDir,
);
// Project skills from .pi/
addResources(
"skills",
collectAutoSkillEntries(projectDirs.skills, "pi"),
projectMetadata,
projectOverrides.skills,
projectBaseDir,
);
}
// Project skills from .agents/ (each with its own baseDir)
for (const agentsSkillsDir of projectAgentsSkillDirs) {
const agentsBaseDir = dirname(agentsSkillsDir); // the .agents directory
const agentsMetadata: PathMetadata = {
...projectMetadata, ...projectMetadata,
baseDir: agentsBaseDir, baseDir: configDir,
}; };
addResources( addResources(
"skills", "extensions",
collectAutoSkillEntries(agentsSkillsDir, "agents"), collectAutoExtensionEntries(join(configDir, "extensions")),
agentsMetadata, configMetadata,
projectOverrides.skills, projectOverrides.extensions,
agentsBaseDir, configDir,
);
addResources(
"skills",
collectAutoSkillEntries(join(configDir, "skills"), "pi"),
configMetadata,
projectOverrides.skills,
configDir,
); );
}
if (projectTrusted) {
addResources( addResources(
"prompts", "prompts",
collectAutoPromptEntries(projectDirs.prompts), collectAutoPromptEntries(join(configDir, "prompts")),
projectMetadata, configMetadata,
projectOverrides.prompts, projectOverrides.prompts,
projectBaseDir, configDir,
); );
addResources( addResources(
"themes", "themes",
collectAutoThemeEntries(projectDirs.themes), collectAutoThemeEntries(join(configDir, "themes")),
projectMetadata, configMetadata,
projectOverrides.themes, projectOverrides.themes,
projectBaseDir, configDir,
);
}
// Project skills from .agents/ in cwd and ancestors.
for (const agentsDir of projectAgentsDirs) {
const agentsMetadata: PathMetadata = {
...projectMetadata,
baseDir: agentsDir,
};
addResources(
"skills",
collectAutoSkillEntries(join(agentsDir, "skills"), "agents"),
agentsMetadata,
projectOverrides.skills,
agentsDir,
); );
} }