const FINISHED_ESCAPE: &str = " If the work is genuinely done and you have already reported it, \
reply with a short confirmation and stop; do not run extra tool calls to re-verify it.";
const NO_EXECUTION_WHILE_REASONING: &str = "Tools execute only between turns; nothing runs inside your reasoning. If you saw that \
output while thinking, you imagined it. The only evidence a tool ran is its result \
present in this conversation.";
pub fn uncalled_commands_nudge(commands: &[String]) -> String {
let quoted = commands
.iter()
.map(|c| format!("`{c}`"))
.collect::<Vec<_>>()
.join(", ");
let subject = if commands.len() == 1 {
"output from"
} else {
"output from these commands:"
};
format!(
"[System: You reported {subject} {quoted}. No such call ran this turn. \
{NO_EXECUTION_WHILE_REASONING} Call the tool now through the structured tool-call API, \
or retract the claim and tell the user it has not been run.{FINISHED_ESCAPE}]"
)
}
pub fn unbacked_facts_nudge(facts: &[String]) -> String {
let quoted = facts
.iter()
.map(|f| format!("`{f}`"))
.collect::<Vec<_>>()
.join(", ");
let subject = if facts.len() == 1 {
"this fact:"
} else {
"these facts:"
};
format!(
"[System: You reported {subject} {quoted}. None of it appears in any tool result or \
message in this conversation, so it was written, not read. \
{NO_EXECUTION_WHILE_REASONING} Run the tool that produces it through the structured \
tool-call API, or retract the claim and say it has not been verified.{FINISHED_ESCAPE}]"
)
}
pub fn no_tool_calls_nudge(local_model: bool) -> String {
let channel = if local_model {
"Invoke it through the provider's structured tool-call API, the same channel the function \
schemas were registered on. JSON or markdown written into your message is text and does \
not execute."
} else {
"Call the tool through the structured tool-call API rather than describing it."
};
format!(
"[System: Your last response claimed work but produced no tool calls, so nothing was \
executed. {NO_EXECUTION_WHILE_REASONING} {channel} Pick the tool you need and call it \
now.{FINISHED_ESCAPE}]"
)
}
pub(crate) const PRESSURE_WARN_FLOOR: f64 = 55.0;
pub(crate) const PRESSURE_WARN_CEILING: f64 = 65.0;
pub fn context_pressure_warning() -> &'static str {
"\n\n[SYSTEM WARNING - Context is filling up and auto-compaction will trigger soon. \
If you have critical state - active plan, key findings, partial work, decisions made - \
persist it to disk NOW (MEMORY.md, plan JSON, or a project file) so it survives the \
upcoming compaction. Do NOT stop or change task; just checkpoint your state.]"
}
pub fn in_pressure_warning_band(usage_pct: f64) -> bool {
(PRESSURE_WARN_FLOOR..PRESSURE_WARN_CEILING).contains(&usage_pct)
}
pub fn should_emit_pressure_warning(usage_pct: f64, already_emitted: bool) -> Option<&'static str> {
if in_pressure_warning_band(usage_pct) && !already_emitted {
Some(context_pressure_warning())
} else {
None
}
}
#[cfg(feature = "telegram")]
pub(crate) fn mermaid_regen_nudge(errors: &[String], attempt: u32, max: u32) -> String {
let quoted = errors.join("\n");
format!(
"[System: Your mermaid diagram failed to render — mermaid.ink returned:\n{quoted}\n\
Correction rules:\n\
1. Syntax & Notes: Fix the exact token or line reported above. For sequenceDiagrams, \
'Note over A,B:' supports at most two participants spanning the range — do not list three or more. \
Do not use backticks or HTML tags (except '<br/>') in labels.\n\
2. Mobile Layout & Dimensions: Use vertical orientation ('flowchart TD' or 'direction TB'), never wide 'LR' \
layouts or unbounded horizontal subgraphs that shrink illegibly on mobile screens. Break wide text with '<br/>'.\n\
Re-emit the COMPLETE corrected fence in your reply — keep everything else you wrote. \
Regen attempt {attempt}/{max}.]"
)
}
pub fn variation_directive() -> &'static str {
"Do not re-issue the same call. Read the reason in the result you already have: it often \
says the work is already done or the input is wrong. Verify current state before acting \
again, then take a genuinely different action — different flags, a different command, or \
report completion if there is nothing left to do."
}