mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 17:31:36 +00:00
Merged via squash.
Prepared head SHA: 8cd6cc8049
Co-authored-by: echoVic <16428813+echoVic@users.noreply.github.com>
Co-authored-by: jalehman <550978+jalehman@users.noreply.github.com>
Reviewed-by: @jalehman
This commit is contained in:
@@ -226,4 +226,57 @@ Read WORKFLOW.md on startup.
|
||||
expect(result).not.toBeNull();
|
||||
expect(result).toContain("Current time:");
|
||||
});
|
||||
|
||||
it("falls back to legacy section names (Every Session / Safety)", async () => {
|
||||
const content = `# Rules
|
||||
|
||||
## Every Session
|
||||
|
||||
Read SOUL.md and USER.md.
|
||||
|
||||
## Safety
|
||||
|
||||
Don't exfiltrate private data.
|
||||
|
||||
## Other
|
||||
|
||||
Ignore this.
|
||||
`;
|
||||
fs.writeFileSync(path.join(tmpDir, "AGENTS.md"), content);
|
||||
const result = await readPostCompactionContext(tmpDir);
|
||||
expect(result).not.toBeNull();
|
||||
expect(result).toContain("Every Session");
|
||||
expect(result).toContain("Read SOUL.md");
|
||||
expect(result).toContain("Safety");
|
||||
expect(result).toContain("Don't exfiltrate");
|
||||
expect(result).not.toContain("Other");
|
||||
});
|
||||
|
||||
it("prefers new section names over legacy when both exist", async () => {
|
||||
const content = `# Rules
|
||||
|
||||
## Session Startup
|
||||
|
||||
New startup instructions.
|
||||
|
||||
## Every Session
|
||||
|
||||
Old startup instructions.
|
||||
|
||||
## Red Lines
|
||||
|
||||
New red lines.
|
||||
|
||||
## Safety
|
||||
|
||||
Old safety rules.
|
||||
`;
|
||||
fs.writeFileSync(path.join(tmpDir, "AGENTS.md"), content);
|
||||
const result = await readPostCompactionContext(tmpDir);
|
||||
expect(result).not.toBeNull();
|
||||
expect(result).toContain("New startup instructions");
|
||||
expect(result).toContain("New red lines");
|
||||
expect(result).not.toContain("Old startup instructions");
|
||||
expect(result).not.toContain("Old safety rules");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -53,9 +53,14 @@ export async function readPostCompactionContext(
|
||||
}
|
||||
})();
|
||||
|
||||
// Extract "## Session Startup" and "## Red Lines" sections
|
||||
// Extract "## Session Startup" and "## Red Lines" sections.
|
||||
// Also accept legacy names "Every Session" and "Safety" for backward
|
||||
// compatibility with older AGENTS.md templates.
|
||||
// Each section ends at the next "## " heading or end of file
|
||||
const sections = extractSections(content, ["Session Startup", "Red Lines"]);
|
||||
let sections = extractSections(content, ["Session Startup", "Red Lines"]);
|
||||
if (sections.length === 0) {
|
||||
sections = extractSections(content, ["Every Session", "Safety"]);
|
||||
}
|
||||
|
||||
if (sections.length === 0) {
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user