diff --git a/src/api/sessions.rs b/src/api/sessions.rs
index 9ee9ac2..0594d67 100644
--- a/src/api/sessions.rs
+++ b/src/api/sessions.rs
@@ -714,14 +714,17 @@ mod tests {
assert!(t0.starts_with(""));
assert!(t0.contains("Pippo") && t0.contains("/tmp/pippo"));
assert!(t0.contains("sii breve"));
- assert!(t0.ends_with(""));
- assert_eq!(req.messages[1].text().unwrap(), "\n\n"
+ );
}
fn sp_section() -> ContextSection {
@@ -862,12 +865,15 @@ mod tests {
assert!(req.messages[0]
.text()
.unwrap()
- .ends_with(""));
+ .ends_with("\n\n"));
assert_eq!(
req.messages[1].text().unwrap(),
- "\nmanuale\n"
+ "\nmanuale\n\n\n"
+ );
+ assert_eq!(req.messages[2].text().unwrap(), "\n");
+ assert_eq!(
+ req.messages.last().unwrap().text().unwrap(),
+ "\n\n\n"
);
- assert_eq!(req.messages[2].text().unwrap(), "");
- assert_eq!(req.messages.last().unwrap().text().unwrap(), "");
}
}
diff --git a/src/context.rs b/src/context.rs
index 4241325..67c1d6d 100644
--- a/src/context.rs
+++ b/src/context.rs
@@ -41,12 +41,12 @@ pub fn compose(
.replace("{session_prompt}", &session_prompt);
messages.push(text_message(
Role::System,
- format!("<{}>\n{}\n{}>", sec.name, rendered, sec.name),
+ format!("<{}>\n{}\n{}>\n\n", sec.name, rendered, sec.name),
));
}
// The interactive region is its own section: opener/closer markers around the
// real role messages, which keep the engine's turn structure intact.
- messages.push(text_message(Role::System, "".to_string()));
+ messages.push(text_message(Role::System, "\n".to_string()));
for m in history {
// Per-turn provenance for the model: [SPEAKER: name - datetime]. The
// human uses the global user name; the assistant uses the session name.
@@ -94,7 +94,7 @@ pub fn compose(
reasoning_content: None,
});
}
- messages.push(text_message(Role::System, "".to_string()));
+ messages.push(text_message(Role::System, "\n\n\n".to_string()));
messages
}
diff --git a/tests/inkling_template.rs b/tests/inkling_template.rs
index 2897378..5142b09 100644
--- a/tests/inkling_template.rs
+++ b/tests/inkling_template.rs
@@ -109,3 +109,44 @@ fn real_template_renders_a_turn() {
"{out0}"
);
}
+
+/// Ground truth: the composed context, rendered by the REAL template, must keep
+/// each section's closing tag followed by a blank line (what the model reads).
+#[test]
+#[ignore = "needs the real Inkling chat_template.jinja"]
+fn real_prompt_closes_sections_with_blank_line() {
+ use strata_ctl::context;
+ use strata_ctl::store::{ContextSection, Session, SessionSettings};
+ let dir = std::env::var("STRATA_TOK_DIR")
+ .unwrap_or_else(|_| "/home/federico/.config/strata-inkling/inkling-tok".to_string());
+ let src = std::fs::read_to_string(format!("{dir}/chat_template.jinja")).unwrap();
+ let t = ChatTemplate::new(&src).unwrap();
+ let sess = Session {
+ id: "s".into(),
+ title: "Nebula".into(),
+ model: "m".into(),
+ settings: SessionSettings::default(),
+ name_locked: true,
+ folder: None,
+ created_at: 0,
+ updated_at: 0,
+ };
+ let sections = vec![
+ ContextSection {
+ name: "SYSTEM_PROMPT".into(),
+ content: "{identity}{speaker_note}\n{session_prompt}".into(),
+ position: 0,
+ },
+ ContextSection {
+ name: "TOOL_USE".into(),
+ content: "manuale".into(),
+ position: 1,
+ },
+ ];
+ let msgs = context::compose(&sess, &[], "ciao", &[], "Federico", §ions);
+ let val = serde_json::to_value(&msgs).unwrap();
+ let out = t.render(&val, None, Some("low")).unwrap();
+ assert!(out.contains("\n\n"), "{out}");
+ assert!(out.contains("\n\n"), "{out}");
+ assert!(out.contains(""), "{out}");
+}