feat: surface base + persona system prompts in observer feed (#1103)

Signed-off-by: Will Pfleger <pfleger.will@gmail.com>
Co-authored-by: Will Pfleger <pfleger.will@gmail.com>
Co-authored-by: npub1mn7jgtj4w2pd0g0zeuhxsa6jy6p0rewxz4kujt98my82ahfmp72sxjexk7 <dcfd242e557282d7a1e2cf2e6877522682f1e5c6156dc92ca7d90eaedd3b0f95@sprout-oss.stage.blox.sqprod.co>
This commit is contained in:
Will Pfleger
2026-06-17 19:41:03 -04:00
committed by GitHub
parent 466bb993ca
commit 5004758fbf
4 changed files with 162 additions and 6 deletions

View File

@@ -4,6 +4,7 @@ import test from "node:test";
import {
extractPromptText,
parsePromptText,
parseSystemPromptSections,
} from "./agentSessionTranscriptHelpers.ts";
const HEX = "a".repeat(64);
@@ -122,3 +123,51 @@ test("extractPromptText returns empty string when prompt is missing or not an ar
assert.equal(extractPromptText({}), "");
assert.equal(extractPromptText({ params: { prompt: "nope" } }), "");
});
// --- parseSystemPromptSections: deterministic Base/System split ---
test("parseSystemPromptSections splits both prompts into Base and System", () => {
const framed = "[Base]\nbase text\n\n[System]\npersona text";
const sections = parseSystemPromptSections(framed);
assert.deepEqual(sections, [
{ title: "Base", body: "base text" },
{ title: "System", body: "persona text" },
]);
});
test("parseSystemPromptSections yields one Base section for a base-only frame", () => {
const sections = parseSystemPromptSections("[Base]\nbase text");
assert.deepEqual(sections, [{ title: "Base", body: "base text" }]);
});
test("parseSystemPromptSections yields one System section for a persona-only frame", () => {
const sections = parseSystemPromptSections("[System]\npersona text");
assert.deepEqual(sections, [{ title: "System", body: "persona text" }]);
});
test("parseSystemPromptSections keeps embedded bracket lines literal in bodies", () => {
// A persona that itself contains a [Context]-like line must NOT split into a
// spurious sub-section — the body is read literally after the first boundary.
const framed = "[Base]\nbase\n\n[System]\nrule one\n[Context]\nrule two";
const sections = parseSystemPromptSections(framed);
assert.deepEqual(sections, [
{ title: "Base", body: "base" },
{ title: "System", body: "rule one\n[Context]\nrule two" },
]);
});
test("parseSystemPromptSections degrades to a labeled Base when [System] header is elided", () => {
// Oversize trim can drop the [System] header mid-string. Without a boundary
// the whole value stays under a correctly-labeled Base — no missing label,
// no inflated count, just a truncated body.
const elided = "[Base]\nbase text …[elided 900000 bytes]… persona tail";
const sections = parseSystemPromptSections(elided);
assert.deepEqual(sections, [
{ title: "Base", body: "base text …[elided 900000 bytes]… persona tail" },
]);
});
test("parseSystemPromptSections returns no sections for empty input", () => {
assert.deepEqual(parseSystemPromptSections(""), []);
assert.deepEqual(parseSystemPromptSections(" "), []);
});