Align pi sandbox context and bootstrap injection

Co-authored-by: Codex <noreply@openai.com>
This commit is contained in:
Harivansh Rathi 2026-03-08 17:41:57 -07:00
parent fb782fa025
commit 59ad12335a
6 changed files with 261 additions and 15 deletions

View file

@ -322,6 +322,38 @@ Content`,
result.skills.some((r) => r.path === middleSkill && r.enabled),
).toBe(true);
});
it("should include default workspace skills when cwd is outside the workspace root", async () => {
const workspaceSkill = join(
tempDir,
"workspace",
".agents",
"skills",
"build-app",
"SKILL.md",
);
mkdirSync(join(tempDir, "workspace", ".agents", "skills", "build-app"), {
recursive: true,
});
writeFileSync(
workspaceSkill,
"---\nname: build-app\ndescription: Build apps\n---\n",
);
const appCwd = join(tempDir, "apps", "portfolio");
mkdirSync(appCwd, { recursive: true });
const pm = new DefaultPackageManager({
cwd: appCwd,
agentDir,
settingsManager,
});
const result = await pm.resolve();
expect(
result.skills.some((r) => r.path === workspaceSkill && r.enabled),
).toBe(true);
});
});
describe("ignore files", () => {

View file

@ -320,6 +320,28 @@ Content`,
expect(agentsFiles.some((f) => f.path.endsWith("SOUL.md"))).toBe(true);
});
it("should discover companion context files from the default workspace", async () => {
const workspaceDir = join(tempDir, "workspace");
const appDir = join(tempDir, "apps", "todo-app");
mkdirSync(workspaceDir, { recursive: true });
mkdirSync(appDir, { recursive: true });
writeFileSync(join(workspaceDir, "IDENTITY.md"), "# Identity\n\nPi");
writeFileSync(join(workspaceDir, "TOOLS.md"), "# Tools\n\nUse ~/.pi");
writeFileSync(join(workspaceDir, "BOOTSTRAP.md"), "# Bootstrap\n\nDo it");
const loader = new DefaultResourceLoader({ cwd: appDir, agentDir });
await loader.reload();
const { agentsFiles } = loader.getAgentsFiles();
expect(agentsFiles.some((f) => f.path.endsWith("IDENTITY.md"))).toBe(
true,
);
expect(agentsFiles.some((f) => f.path.endsWith("TOOLS.md"))).toBe(true);
expect(agentsFiles.some((f) => f.path.endsWith("BOOTSTRAP.md"))).toBe(
true,
);
});
it("should discover SYSTEM.md from cwd/.pi", async () => {
const piDir = join(cwd, ".pi");
mkdirSync(piDir, { recursive: true });

View file

@ -100,5 +100,35 @@ describe("buildSystemPrompt", () => {
);
expect(prompt).toContain("## /tmp/project/SOUL.md");
});
test("adds companion context guidance for identity, tools, and bootstrap files", () => {
const prompt = buildSystemPrompt({
contextFiles: [
{
path: "/home/node/.pi/workspace/IDENTITY.md",
content: "# Identity\n\nPi",
},
{
path: "/home/node/.pi/workspace/TOOLS.md",
content: "# Tools\n\nUse ~/.pi/apps",
},
{
path: "/home/node/.pi/workspace/BOOTSTRAP.md",
content: "# Bootstrap\n\nDo the setup",
},
],
skills: [],
});
expect(prompt).toContain(
"If IDENTITY.md is present, treat it as the agent's self-description",
);
expect(prompt).toContain(
"If TOOLS.md is present, treat it as the source of truth for the current sandbox filesystem",
);
expect(prompt).toContain(
"If BOOTSTRAP.md is present, treat it as an actionable onboarding task list",
);
});
});
});