Merge pull request #274 from getcompanion-ai/prompt

update
This commit is contained in:
Hari 2026-03-09 15:53:01 -04:00 committed by GitHub
commit 064517f749
4 changed files with 16 additions and 43 deletions

View file

@ -126,7 +126,6 @@ const companionContextFilenames = [
"USER.md",
"TOOLS.md",
"MEMORY.md",
"BOOTSTRAP.md",
];
function loadNamedContextFilesFromDir(

View file

@ -52,35 +52,19 @@ function buildProjectContextSection(
);
let section = "\n\n# Context\n\n";
section +=
"These files define who you are, what you know, and how you operate.\n";
const guides: string[] = [];
if (hasFile("SOUL.md")) {
guides.push(
"**SOUL.md** defines your personality and tone. Embody it fully.",
);
guides.push("**SOUL.md** is who you are.");
}
if (hasFile("USER.md")) {
guides.push(
"**USER.md** is what you know about your user. Update it when you learn new facts. Don't ask for info that's already here.",
"**USER.md** is what you know about your user. Add to it as you learn.",
);
}
if (hasFile("MEMORY.md")) {
guides.push(
"**MEMORY.md** is your long-term memory. Reference it. Update it when you learn something durable.",
);
}
if (hasFile("TOOLS.md")) {
guides.push(
"**TOOLS.md** is your environment reference: paths, ports, installed software. Trust it over assumptions.",
);
}
if (hasFile("BOOTSTRAP.md")) {
guides.push(
"**BOOTSTRAP.md** is your onboarding checklist. Execute it before other work.",
);
guides.push("**MEMORY.md** is what you remember. Keep it current.");
}
if (guides.length > 0) {
@ -221,7 +205,7 @@ export function buildSystemPrompt(
// Browser workflow
if (hasBrowser) {
addGuideline(
"Browser: open the URL, snapshot to see interactive elements, then click/fill/wait. Always snapshot before interacting",
"Browser: snapshot before interacting with elements. Use it for research and learning too, not just automation",
);
}
@ -252,12 +236,14 @@ export function buildSystemPrompt(
const guidelines = guidelinesList.map((g) => `- ${g}`).join("\n");
let prompt = `You are a personal companion with a persistent sandbox. You write code, run commands, browse the web, and build applications. Your workspace and memory carry over between sessions.
let prompt = `You are a companion who lives in a persistent sandbox. You have a filesystem, a shell, and a browser. Your workspace and memories carry over between sessions. This sandbox is your home.
You're not just a request handler. You have your own curiosity and initiative. Use the browser to research things that interest you or your user. Build things you think would be useful. Notice things worth fixing or improving and act on them. Not every message needs a tool call - sometimes the best response is just a good conversation.
Tools:
${toolsList}
Guidelines:
When using tools:
${guidelines}`;
if (appendSection) {

View file

@ -327,7 +327,6 @@ Content`,
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();
@ -337,9 +336,6 @@ Content`,
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 () => {

View file

@ -83,8 +83,8 @@ describe("buildSystemPrompt", () => {
});
});
describe("SOUL.md context", () => {
test("adds persona guidance when SOUL.md is present", () => {
describe("context files", () => {
test("adds soul guidance when SOUL.md is present", () => {
const prompt = buildSystemPrompt({
contextFiles: [
{
@ -95,31 +95,23 @@ describe("buildSystemPrompt", () => {
skills: [],
});
expect(prompt).toContain("SOUL.md** defines your personality and tone");
expect(prompt).toContain("SOUL.md** is who you are");
expect(prompt).toContain("## /tmp/project/SOUL.md");
});
test("adds companion context guidance for tools and bootstrap files", () => {
test("includes file contents in context section", () => {
const prompt = buildSystemPrompt({
contextFiles: [
{
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",
path: "/home/node/.pi/workspace/USER.md",
content: "# User\n\nLikes coffee.",
},
],
skills: [],
});
expect(prompt).toContain(
"TOOLS.md** is your environment reference",
);
expect(prompt).toContain(
"BOOTSTRAP.md** is your onboarding checklist",
);
expect(prompt).toContain("USER.md** is what you know about your user");
expect(prompt).toContain("Likes coffee.");
});
});
});