Skip to content

Commit 269ef35

Browse files
wpfleger96npub1mn7jgtj4w2pd0g0zeuhxsa6jy6p0rewxz4kujt98my82ahfmp72sxjexk7
andauthored
fix(desktop): parse runtime team instructions section (#2645)
Signed-off-by: Will Pfleger <[email protected]> Co-authored-by: npub1mn7jgtj4w2pd0g0zeuhxsa6jy6p0rewxz4kujt98my82ahfmp72sxjexk7 <dcfd242e557282d7a1e2cf2e6877522682f1e5c6156dc92ca7d90eaedd3b0f95@buzz.block.builderlab.xyz>
1 parent 72bbaec commit 269ef35

3 files changed

Lines changed: 158 additions & 21 deletions

File tree

‎desktop/src/features/agents/ui/agentSessionTranscriptHelpers.test.mjs‎

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,3 +681,114 @@ test("parseSystemPromptSections splits on the LAST occurrence of the canonical d
681681
},
682682
]);
683683
});
684+
685+
// ── Modern [Team Instructions] bracket-header extraction ─────────────────────
686+
687+
test("parseSystemPromptSections (modern) extracts bracket Team Instructions after Base+System", () => {
688+
// with_team() emits "\n\n[Team Instructions]\n{instructions}" as a top-level
689+
// bracket section — the same framing used by with_core() and with_canvas().
690+
const framed = [
691+
"[Base]",
692+
"You are a helpful assistant.",
693+
"",
694+
"[System]",
695+
"You are Agent X.",
696+
"",
697+
"[Team Instructions]",
698+
"Always respond in markdown.",
699+
].join("\n");
700+
const sections = parseSystemPromptSections(framed);
701+
assert.deepEqual(sections, [
702+
{ title: "Base", body: "You are a helpful assistant." },
703+
{ title: "System", body: "You are Agent X." },
704+
{ title: "Team Instructions", body: "Always respond in markdown." },
705+
]);
706+
});
707+
708+
test("parseSystemPromptSections (modern) extracts bracket Team Instructions after System-only", () => {
709+
// [Base] absent; [Team Instructions] is a direct top-level bracket section.
710+
const framed = [
711+
"[System]",
712+
"You are Agent Y.",
713+
"",
714+
"[Team Instructions]",
715+
"Keep responses concise.",
716+
].join("\n");
717+
const sections = parseSystemPromptSections(framed);
718+
assert.deepEqual(sections, [
719+
{ title: "System", body: "You are Agent Y." },
720+
{ title: "Team Instructions", body: "Keep responses concise." },
721+
]);
722+
});
723+
724+
test("parseSystemPromptSections (modern) handles bracket Team Instructions as start-of-string", () => {
725+
// with_team() also handles prompt=None → "[Team Instructions]\n{instructions}".
726+
const framed = ["[Team Instructions]", "Instructions only."].join("\n");
727+
const sections = parseSystemPromptSections(framed);
728+
assert.deepEqual(sections, [
729+
{ title: "Team Instructions", body: "Instructions only." },
730+
]);
731+
});
732+
733+
test("parseSystemPromptSections (modern) pins full 5-section shape: Base+System+Team+Core+Canvas", () => {
734+
// Production shape from with_team() + with_core() + with_canvas(): all five sections present.
735+
const framed = [
736+
"[Base]",
737+
"You are a helpful AI assistant running in Buzz.",
738+
"",
739+
"[System]",
740+
"You are Observer Agent. You coordinate multi-agent workflows.",
741+
"",
742+
"[Team Instructions]",
743+
"Always tag on handoff.",
744+
"Never expand scope without approval.",
745+
"",
746+
"[Agent Memory — core]",
747+
"I am Observer Agent.",
748+
"## Lessons Learned",
749+
"Always tag on handoff.",
750+
"",
751+
"[Channel Canvas]",
752+
"Canvas revision (event ID): a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2",
753+
"Last modified: 2026-07-11T10:00:00Z",
754+
"Fetch current content with: buzz canvas get --channel 94a444a4-c0a3-5966-ab05-530c6ddc2301",
755+
].join("\n");
756+
const sections = parseSystemPromptSections(framed);
757+
assert.deepEqual(sections, [
758+
{ title: "Base", body: "You are a helpful AI assistant running in Buzz." },
759+
{
760+
title: "System",
761+
body: "You are Observer Agent. You coordinate multi-agent workflows.",
762+
},
763+
{
764+
title: "Team Instructions",
765+
body: "Always tag on handoff.\nNever expand scope without approval.",
766+
},
767+
{
768+
title: "Core Memory",
769+
body: "I am Observer Agent.\n## Lessons Learned\nAlways tag on handoff.",
770+
},
771+
{
772+
title: "Channel Canvas",
773+
body: "Canvas revision (event ID): a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2\nLast modified: 2026-07-11T10:00:00Z\nFetch current content with: buzz canvas get --channel 94a444a4-c0a3-5966-ab05-530c6ddc2301",
774+
},
775+
]);
776+
});
777+
778+
test("parseSystemPromptSections (modern) does NOT split on bracket [Team Instructions] preceded by only a single newline", () => {
779+
// The inline marker is "\n\n[Team Instructions]\n" — a single preceding newline
780+
// must be kept literal inside System, same guard as canvas/core.
781+
const framed = [
782+
"[System]",
783+
"Persona preamble.",
784+
"[Team Instructions]",
785+
"This is persona text, not a real team block.",
786+
].join("\n");
787+
const sections = parseSystemPromptSections(framed);
788+
assert.deepEqual(sections, [
789+
{
790+
title: "System",
791+
body: "Persona preamble.\n[Team Instructions]\nThis is persona text, not a real team block.",
792+
},
793+
]);
794+
});

‎desktop/src/features/agents/ui/agentSessionTranscriptHelpers.ts‎

Lines changed: 45 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,12 @@ export function parsePromptText(text: string): {
6161
* deterministically.
6262
*
6363
* The harness composes the value in order:
64-
* `[Base]\n{base}\n\n[System]\n{persona}\n\n[Agent Memory — core]\n{core}\n\n[Channel Canvas]\n{canvas}`
65-
* with any section omitted when absent. For team-pack agents the persona body
66-
* already contains the pack-level instructions appended by `compose_prompt()`
67-
* in `buzz-persona/src/resolve.rs`:
68-
* `{persona_body}\n\n---\n# Team Instructions\n{pack_instructions}`
69-
* Extraction runs in reverse producer order so that each `lastIndexOf` search
70-
* operates on the full input and each extraction boundary is unambiguous.
64+
* `[Base]\n{base}\n\n[System]\n{persona}\n\n[Team Instructions]\n{team}\n\n[Agent Memory — core]\n{core}\n\n[Channel Canvas]\n{canvas}`
65+
* with any section omitted when absent. Extraction runs in reverse producer
66+
* order so that each `lastIndexOf` search operates on the full input and each
67+
* extraction boundary is unambiguous.
7168
*
72-
* Four extraction passes before Base/System parsing:
69+
* Five extraction passes:
7370
*
7471
* 1. **Canvas** (`[Channel Canvas]`): appended last by `with_canvas()`.
7572
* - Start-of-string: canvas-only input.
@@ -80,18 +77,23 @@ export function parsePromptText(text: string): {
8077
* 2. **Core** (`[Agent Memory — core]`): appended before canvas by `with_core()`.
8178
* Same two cases, same last-occurrence guard.
8279
*
83-
* 3. **Base/System**: remainder after canvas and core extraction.
80+
* 3. **Team Instructions** (`[Team Instructions]`): appended before core by
81+
* `with_team()` in `buzz-acp/src/pool.rs`. Same two cases (start-of-string
82+
* or `\n\n[Team Instructions]\n` inline), same last-occurrence guard. Output
83+
* position: after System, before Core Memory.
84+
*
85+
* 4. **Base/System**: remainder after the three top-level section extractions.
8486
* Split on the first `\n[System]\n` boundary; no embedded `[...]` line
8587
* inside a body can start a new section.
8688
*
87-
* 4. **Team Instructions**: if the `System` body contains the exact canonical
88-
* delimiter `\n\n---\n# Team Instructions\n` (produced by `compose_prompt()`),
89-
* the body is split at the **last** occurrence of that boundary (same
90-
* last-occurrence guard as canvas and core). The text before becomes the
91-
* `System` body; the text after becomes a `Team Instructions` section
92-
* inserted immediately after `System`. Non-canonical lookalikes (bare `---`
93-
* without the heading, a `# Team Instructions` on a different line, or only
94-
* a single preceding newline) are kept literal inside `System`.
89+
* 5. **Legacy Team Instructions** (backward compat): if the `System` body
90+
* contains the exact canonical delimiter `\n\n---\n# Team Instructions\n`
91+
* (produced by the now-removed `compose_prompt()` in buzz-persona), the body
92+
* is split at the **last** occurrence of that boundary. The text before
93+
* becomes the `System` body; the text after becomes a `Team Instructions`
94+
* section inserted immediately after `System`. Non-canonical lookalikes
95+
* (bare `---` without the heading, a `# Team Instructions` on a different
96+
* line, or only a single preceding newline) are kept literal inside `System`.
9597
*/
9698
export function parseSystemPromptSections(
9799
systemPrompt: string,
@@ -133,7 +135,29 @@ export function parseSystemPromptSections(
133135
}
134136
}
135137

136-
// ── 3. Parse Base/System from the remaining prefix ────────────────────────
138+
// ── 3. Extract [Team Instructions] (modern runtime framing) ─────────────
139+
// with_team() in buzz-acp/src/pool.rs appends "\n\n[Team Instructions]\n{instructions}"
140+
// after [System] and before core/canvas. Same two cases as canvas/core:
141+
// start-of-string (team-only input) or the inline double-newline marker
142+
// (last occurrence guards against embedded lookalikes preceded by a single \n).
143+
const TEAM_HEADER = "[Team Instructions]";
144+
const TEAM_MARKER_INLINE = `\n\n${TEAM_HEADER}\n`;
145+
let modernTeamBody: string | null = null;
146+
147+
if (remainder.startsWith(`${TEAM_HEADER}\n`)) {
148+
modernTeamBody = remainder.slice(`${TEAM_HEADER}\n`.length).trim();
149+
remainder = "";
150+
} else {
151+
const lastTeam = remainder.lastIndexOf(TEAM_MARKER_INLINE);
152+
if (lastTeam !== -1) {
153+
modernTeamBody = remainder
154+
.slice(lastTeam + TEAM_MARKER_INLINE.length)
155+
.trim();
156+
remainder = remainder.slice(0, lastTeam);
157+
}
158+
}
159+
160+
// ── 4. Parse Base/System from the remaining prefix ────────────────────────
137161
// The canonical team-instructions delimiter produced by compose_prompt() in
138162
// buzz-persona/src/resolve.rs:
139163
// format!("{persona_prompt}\n\n---\n# Team Instructions\n{instructions}")
@@ -181,7 +205,9 @@ export function parseSystemPromptSections(
181205
}
182206
}
183207

184-
// ── 4. Append core and canvas sections in producer order ──────────────────
208+
// ── 5. Append team (modern), core, and canvas sections in producer order ──
209+
if (modernTeamBody)
210+
sections.push({ title: "Team Instructions", body: modernTeamBody });
185211
if (coreBody) sections.push({ title: "Core Memory", body: coreBody });
186212
if (canvasBody) sections.push({ title: "Channel Canvas", body: canvasBody });
187213

‎desktop/tests/e2e/observer-feed-screenshots.spec.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ test.describe("observer feed screenshots", () => {
418418
method: "session/new",
419419
params: {
420420
systemPrompt:
421-
"[Base]\nYou are a helpful AI assistant running in Buzz.\n\n[System]\nYou are Observer Agent. You coordinate multi-agent workflows in the #agents channel.\n\n---\n# Team Instructions\nAlways tag on handoff.\n\n[Agent Memory — core]\nI am Observer Agent.\n## Lessons Learned\nAlways tag on handoff.\n\n[Channel Canvas]\nCanvas revision (event ID): a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2\nLast modified: 2026-07-11T10:00:00Z\nFetch current content with: buzz canvas get --channel 94a444a4-c0a3-5966-ab05-530c6ddc2301",
421+
"[Base]\nYou are a helpful AI assistant running in Buzz.\n\n[System]\nYou are Observer Agent. You coordinate multi-agent workflows in the #agents channel.\n\n[Team Instructions]\nAlways tag on handoff.\n\n[Agent Memory — core]\nI am Observer Agent.\n## Lessons Learned\nAlways tag on handoff.\n\n[Channel Canvas]\nCanvas revision (event ID): a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2\nLast modified: 2026-07-11T10:00:00Z\nFetch current content with: buzz canvas get --channel 94a444a4-c0a3-5966-ab05-530c6ddc2301",
422422
},
423423
},
424424
},
@@ -698,7 +698,7 @@ test.describe("observer feed screenshots", () => {
698698
method: "session/new",
699699
params: {
700700
systemPrompt:
701-
"[Base]\nYou are a helpful AI assistant running in Buzz.\n\n[System]\nYou are Observer Agent. You coordinate multi-agent workflows in the #agents channel.\n\n---\n# Team Instructions\nAlways tag on handoff.\n\n[Agent Memory — core]\nI am Observer Agent.\n## Lessons Learned\nAlways tag on handoff.\n\n[Channel Canvas]\nCanvas revision (event ID): a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2\nLast modified: 2026-07-11T10:00:00Z\nFetch current content with: buzz canvas get --channel 94a444a4-c0a3-5966-ab05-530c6ddc2301",
701+
"[Base]\nYou are a helpful AI assistant running in Buzz.\n\n[System]\nYou are Observer Agent. You coordinate multi-agent workflows in the #agents channel.\n\n[Team Instructions]\nAlways tag on handoff.\n\n[Agent Memory — core]\nI am Observer Agent.\n## Lessons Learned\nAlways tag on handoff.\n\n[Channel Canvas]\nCanvas revision (event ID): a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2\nLast modified: 2026-07-11T10:00:00Z\nFetch current content with: buzz canvas get --channel 94a444a4-c0a3-5966-ab05-530c6ddc2301",
702702
},
703703
},
704704
},

0 commit comments

Comments
 (0)