@@ -1608,64 +1608,39 @@ pub(crate) fn prepend_standing_for_legacy(
16081608}
16091609
16101610/// Frame the `session/new` `systemPrompt` so each present prompt carries its own
1611- /// header, keeping the base/persona boundary recoverable downstream.
1611+ /// header, keeping the base/workspace/ persona boundaries recoverable downstream.
16121612///
1613- /// The header framing matches the legacy per-turn path (`queue::base_section`
1614- /// for `[Base]`, `[System]\n{...}` for the persona) so the desktop observer can
1615- /// split the combined value into labeled sub-sections. Each prompt is wrapped
1616- /// only when present, so a persona-only agent yields `[System]\n{persona}`
1617- /// rather than an unlabeled blob that would be mislabeled as `[Base]`.
1618- ///
1619- /// Prepends a `[Workspace]` section naming the agent's absolute working
1620- /// directory. The base prompt describes the workspace layout but never its
1621- /// absolute root, so without this anchor a model fills the gap by searching
1622- /// `$HOME` (triggering macOS TCC prompts) or by inventing its own workspace
1623- /// directory. The line is emitted only when a real base prompt is present and
1624- /// `cwd` is an absolute path other than the `/` fallback — naming `/` as the
1625- /// workspace would itself invite a `$HOME`-wide scan.
1613+ /// The static base remains first for prompt-prefix caching. When a base is
1614+ /// present, the dynamic workspace anchor follows it and precedes the user-owned
1615+ /// agent instructions. A persona-only agent still yields
1616+ /// `[Agent Instructions]\n{persona}` rather than an unlabeled blob that would
1617+ /// be mislabeled as `[Base]`.
16261618fn framed_system_prompt (
16271619 cwd : & str ,
16281620 base_prompt : Option < & str > ,
16291621 system_prompt : Option < & str > ,
16301622) -> Option < String > {
1631- let body = match ( base_prompt, system_prompt) {
1623+ match ( base_prompt, system_prompt) {
16321624 ( Some ( bp) , Some ( sp) ) => Some ( format ! (
1633- "{}\n \n [System]\n {sp}" ,
1634- crate :: queue:: base_section( bp)
1625+ "{}\n \n {}\n \n [Agent Instructions]\n {sp}" ,
1626+ crate :: queue:: base_section( bp) ,
1627+ workspace_section( cwd)
1628+ ) ) ,
1629+ ( Some ( bp) , None ) => Some ( format ! (
1630+ "{}\n \n {}" ,
1631+ crate :: queue:: base_section( bp) ,
1632+ workspace_section( cwd)
16351633 ) ) ,
1636- ( Some ( bp) , None ) => Some ( crate :: queue:: base_section ( bp) ) ,
1637- ( None , Some ( sp) ) => Some ( format ! ( "[System]\n {sp}" ) ) ,
1634+ ( None , Some ( sp) ) => Some ( format ! ( "[Agent Instructions]\n {sp}" ) ) ,
16381635 ( None , None ) => None ,
1639- } ?;
1640- // Anchor the workspace only when a base prompt is present — the workspace
1641- // section grounds the base prompt's layout description, so it is meaningless
1642- // for a persona-only (`[System]`-only) agent that never received that layout.
1643- match ( base_prompt, workspace_section ( cwd) ) {
1644- ( Some ( _) , Some ( workspace) ) => Some ( format ! ( "{workspace}\n \n {body}" ) ) ,
1645- _ => Some ( body) ,
16461636 }
16471637}
16481638
1649- /// Render the `[Workspace]` grounding section, or `None` when `cwd` is unusable.
1650- ///
1651- /// Skips relative paths and the `/` fallback (`std::env::current_dir()` resolves
1652- /// to `/` on failure): a `/`-rooted workspace line would actively encourage the
1653- /// `$HOME`-wide scan this section exists to prevent.
1654- fn workspace_section ( cwd : & str ) -> Option < String > {
1655- if cwd != "/" && cwd. starts_with ( '/' ) {
1656- Some ( format ! (
1657- "[Workspace]\n Your absolute working directory is `{cwd}`. All workspace \
1658- files — `AGENTS.md`, `RESEARCH/`, `PLANS/`, `GUIDES/`, `WORK_LOGS/`, \
1659- `OUTBOX/` — and any repositories you clone (under `{cwd}/REPOS/`) live \
1660- here. This is where you already are, so start here rather than scanning \
1661- `$HOME`. Any specific path the user names is fine to read."
1662- ) )
1663- } else {
1664- None
1665- }
1639+ fn workspace_section ( cwd : & str ) -> String {
1640+ format ! ( "[Workspace]\n Current working directory: {cwd}" )
16661641}
16671642
1668- /// Append the team-owned instruction section after `[System ]` and before core memory.
1643+ /// Append the team-owned instruction section after `[Agent Instructions ]` and before core memory.
16691644fn with_team ( prompt : Option < String > , instructions : Option < & str > ) -> Option < String > {
16701645 let instructions = instructions
16711646 . map ( str:: trim)
@@ -1856,7 +1831,7 @@ pub async fn run_prompt_task(
18561831
18571832 //
18581833 // Core memory is delivered inside the system prompt the harness already
1859- // builds (system role for protocol >= 2, the `[System ]` user-message
1834+ // builds (system role for protocol >= 2, the `[Agent Instructions ]` user-message
18601835 // section for legacy agents). To put it on the wire at `session/new` for
18611836 // modern agents, the fetch must run *before* the session is created — so
18621837 // we do it here and cache the rendered section in `state.core_sections`.
@@ -4858,7 +4833,7 @@ mod tests {
48584833 fn test_heartbeat_standing_block_is_base_only ( ) {
48594834 // A heartbeat has no channel, so core and canvas are absent by
48604835 // construction — and it has never carried the persona. Pin that the
4861- // shared helper does not start handing heartbeats [System ].
4836+ // shared helper does not start handing heartbeats [Agent Instructions ].
48624837 let composed = prepend_standing_for_legacy ( 1 , & base_only ( Some ( "be helpful" ) ) , "tick" ) ;
48634838 assert_eq ! ( composed, "[Base]\n be helpful\n \n tick" ) ;
48644839 }
@@ -4942,7 +4917,7 @@ mod tests {
49424917 let composed = prepend_standing_for_legacy ( 1 , & full_standing ( ) , "do the thing" ) ;
49434918 let positions: Vec < usize > = [
49444919 "[Base]" ,
4945- "[System ]" ,
4920+ "[Agent Instructions ]" ,
49464921 "[Team Instructions]" ,
49474922 "[Agent Memory — core]" ,
49484923 "[Huddle Instructions]" ,
@@ -4998,86 +4973,64 @@ mod tests {
49984973 // Also the regression guard against #2372: the session title travels
49994974 // out of band in `_meta.sessionTitle`, so this exact-bytes assertion is
50004975 // what pins the framing against a `[Session]` section reappearing here.
5001- let framed = framed_system_prompt ( "/" , Some ( "base text" ) , Some ( "persona text" ) )
4976+ let framed = framed_system_prompt ( "/workspace " , Some ( "base text" ) , Some ( "persona text" ) )
50024977 . expect ( "both present yields Some" ) ;
5003- assert_eq ! ( framed, "[Base]\n base text\n \n [System]\n persona text" ) ;
4978+ assert_eq ! (
4979+ framed,
4980+ "[Base]\n base text\n \n [Workspace]\n Current working directory: /workspace\n \n [Agent Instructions]\n persona text"
4981+ ) ;
50044982 }
50054983
50064984 #[ test]
50074985 fn test_framed_system_prompt_base_only_labels_base ( ) {
5008- let framed = framed_system_prompt ( "/" , Some ( "base text" ) , None ) . expect ( "base yields Some" ) ;
5009- assert_eq ! ( framed, "[Base]\n base text" ) ;
5010- }
5011-
5012- #[ test]
5013- fn test_framed_system_prompt_persona_only_labels_system ( ) {
5014- // A bare persona would be mislabeled "Base" downstream — it must carry
5015- // its own [System] header even when no base prompt exists.
50164986 let framed =
5017- framed_system_prompt ( "/" , None , Some ( "persona text" ) ) . expect ( "persona yields Some" ) ;
5018- assert_eq ! ( framed, "[System]\n persona text" ) ;
5019- }
5020-
5021- #[ test]
5022- fn test_framed_system_prompt_neither_is_none ( ) {
5023- assert ! ( framed_system_prompt( "/" , None , None ) . is_none( ) ) ;
5024- }
5025-
5026- #[ test]
5027- fn test_framed_system_prompt_absolute_cwd_prepends_workspace_before_base ( ) {
5028- let framed = framed_system_prompt ( "/Users/me/.buzz" , Some ( "base text" ) , None )
5029- . expect ( "base yields Some" ) ;
5030- assert ! (
5031- framed. starts_with( "[Workspace]\n " ) ,
5032- "workspace section must lead: {framed}"
5033- ) ;
5034- assert ! ( framed. contains( "`/Users/me/.buzz`" ) ) ;
5035- assert ! (
5036- framed. contains( "\n \n [Base]\n base text" ) ,
5037- "base must follow the workspace section: {framed}"
4987+ framed_system_prompt ( "/workspace" , Some ( "base text" ) , None ) . expect ( "base yields Some" ) ;
4988+ assert_eq ! (
4989+ framed,
4990+ "[Base]\n base text\n \n [Workspace]\n Current working directory: /workspace"
50384991 ) ;
50394992 }
50404993
50414994 #[ test]
5042- fn test_framed_system_prompt_persona_only_omits_workspace ( ) {
5043- // The workspace section grounds the base prompt's layout; a persona-only
5044- // agent never received that layout, so no [Workspace] anchor is emitted .
5045- let framed = framed_system_prompt ( "/Users/me/.buzz " , None , Some ( "persona text" ) )
4995+ fn test_framed_system_prompt_persona_only_labels_agent_instructions ( ) {
4996+ // A bare persona would be mislabeled "Base" downstream — it must carry
4997+ // its own [Agent Instructions] header even when no base prompt exists .
4998+ let framed = framed_system_prompt ( "/workspace " , None , Some ( "persona text" ) )
50464999 . expect ( "persona yields Some" ) ;
5047- assert_eq ! ( framed, "[System ]\n persona text" ) ;
5000+ assert_eq ! ( framed, "[Agent Instructions ]\n persona text" ) ;
50485001 }
50495002
50505003 #[ test]
5051- fn test_framed_system_prompt_root_cwd_omits_workspace ( ) {
5052- // The "/" fallback must never be named — it would invite a $HOME scan.
5053- let framed = framed_system_prompt ( "/" , Some ( "base text" ) , None ) . expect ( "base yields Some" ) ;
5054- assert_eq ! ( framed, "[Base]\n base text" ) ;
5004+ fn test_framed_system_prompt_neither_is_none ( ) {
5005+ assert ! ( framed_system_prompt( "/workspace" , None , None ) . is_none( ) ) ;
50555006 }
50565007
50575008 #[ test]
5058- fn test_workspace_section_relative_cwd_is_none ( ) {
5059- assert ! ( workspace_section( "relative/path" ) . is_none( ) ) ;
5060- assert ! ( workspace_section( "" ) . is_none( ) ) ;
5009+ fn test_workspace_section_preserves_windows_cwd ( ) {
5010+ assert_eq ! (
5011+ workspace_section( r"C:\Users\me\buzz" ) ,
5012+ "[Workspace]\n Current working directory: C:\\ Users\\ me\\ buzz"
5013+ ) ;
50615014 }
50625015
50635016 #[ test]
50645017 fn test_with_core_appends_below_framed ( ) {
50655018 let framed = with_core (
5066- Some ( "[System ]\n persona" . to_string ( ) ) ,
5019+ Some ( "[Agent Instructions ]\n persona" . to_string ( ) ) ,
50675020 Some ( "[Agent Memory — core]\n be helpful" ) ,
50685021 )
50695022 . expect ( "both present yields Some" ) ;
50705023 assert_eq ! (
50715024 framed,
5072- "[System ]\n persona\n \n [Agent Memory — core]\n be helpful"
5025+ "[Agent Instructions ]\n persona\n \n [Agent Memory — core]\n be helpful"
50735026 ) ;
50745027 }
50755028
50765029 #[ test]
50775030 fn test_with_core_framed_only_passes_through ( ) {
5078- let framed = with_core ( Some ( "[System ]\n persona" . to_string ( ) ) , None )
5031+ let framed = with_core ( Some ( "[Agent Instructions ]\n persona" . to_string ( ) ) , None )
50795032 . expect ( "framed-only yields Some" ) ;
5080- assert_eq ! ( framed, "[System ]\n persona" ) ;
5033+ assert_eq ! ( framed, "[Agent Instructions ]\n persona" ) ;
50815034 }
50825035
50835036 #[ test]
0 commit comments