Instructions per chat (system prompt addition; UI dialog and Telegram /prompt)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Richard ZinkandClaude Opus 5.5 committed 2026-11-09 18:14:20 +01:00
1 parent 434aa84d40
commit ff8ff585a2
14 files changed
+156 -4

No files matched your search

+23 -2
View File
@@ -329,6 +329,7 @@ async fn handle_update(app: &Arc<App>, user_id: &str, bot: &Bot, u: &Value) -> R
return new_session(app, &u, bot, chat, &format!("{folder} {}", cur.agent), de).await;
}
"permissions" => return set_permissions(app, &u, bot, chat, arg, de).await,
"prompt" => return chat_instructions(app, &u, bot, chat, arg, de).await,
"effort" => return set_effort(app, &u, bot, chat, arg, de).await,
"costs" => return costs(app, &u, bot, chat, de).await,
"memory" => return memory(app, &u, bot, chat, de).await,
@@ -401,13 +402,13 @@ fn help(de: bool) -> String {
if de {
"<b>CodeCraft</b> – Nachrichten gehen an die aktuelle Sitzung (Fotos und Dateien auch).\n\n\
/sessions – letzte Sitzungen\n/session &lt;Nr|Name&gt; – Sitzung wechseln\n/new [Ordner] [Modus] – neue Sitzung (ohne Ordner: Chat)\n\
/clear – neue Sitzung im gleichen Ordner\n/mode [Name] – Modus\n/model [Modell] – Modell\n/permissions [Modus] – Freigaben\n/effort [Stufe] – Denktiefe\n\
/clear – neue Sitzung im gleichen Ordner\n/mode [Name] – Modus\n/model [Modell] – Modell\n/permissions [Modus] – Freigaben\n/prompt [Text|-] – Anweisungen für diesen Chat\n/effort [Stufe] – Denktiefe\n\
/stop – Runde abbrechen\n/status – aktuelle Sitzung\n/costs – Kosten und Budgets\n/memory – Gedächtnis\n/jobs – Automationen\n/compact – Unterhaltung komprimieren"
.into()
} else {
"<b>CodeCraft</b> – messages go to the current session (photos and files too).\n\n\
/sessions – recent sessions\n/session &lt;n|name&gt; – switch session\n/new [folder] [mode] – new session (no folder: chat)\n\
/clear – new session in the same folder\n/mode [name] – mode\n/model [model] – model\n/permissions [mode] – approvals\n/effort [level] – reasoning effort\n\
/clear – new session in the same folder\n/mode [name] – mode\n/model [model] – model\n/permissions [mode] – approvals\n/prompt [text|-] – instructions for this chat\n/effort [level] – reasoning effort\n\
/stop – stop the turn\n/status – current session\n/costs – costs and budgets\n/memory – memory\n/jobs – automations\n/compact – compact the conversation"
.into()
}
@@ -536,6 +537,7 @@ async fn new_session(app: &Arc<App>, u: &User, bot: &Bot, chat: i64, arg: &str,
pinned: false,
archived: false,
folder: None,
instructions: String::new(),
})?;
update(app, &u.id, |st| st.session = Some(s.id.clone()));
bot.send(chat, &format!("{} <b>{}</b> · {} · {}", tr(de, "Neue Sitzung", "New session"), esc(&s.cwd), esc(&s.agent), esc(&s.model)), None).await?;
@@ -620,6 +622,25 @@ async fn status_message(app: &App, u: &User, bot: &Bot, chat: i64, de: bool) ->
Ok(())
}
/// Show, set ("/prompt text") or clear ("/prompt -") the instructions of the current chat.
async fn chat_instructions(app: &App, u: &User, bot: &Bot, chat: i64, arg: &str, de: bool) -> Result<()> {
let s = current(app, u, de)?;
if arg.is_empty() {
let text = if s.instructions.is_empty() {
tr(de, "Keine Anweisungen für diesen Chat. Setzen mit /prompt &lt;Text&gt;.", "No instructions for this chat. Set them with /prompt &lt;text&gt;.").to_string()
} else {
format!("<b>{}</b>\n{}\n\n<i>{}</i>", tr(de, "Anweisungen für diesen Chat", "Instructions for this chat"), esc(&s.instructions), tr(de, "Löschen mit /prompt -", "Clear with /prompt -"))
};
bot.send(chat, &text, None).await?;
return Ok(());
}
let new = if arg == "-" { String::new() } else { arg.to_string() };
app.update_session(&s.id, |x| x.instructions = new.clone())?;
let text = if new.is_empty() { tr(de, "Anweisungen gelöscht.", "Instructions cleared.") } else { tr(de, "Anweisungen gesetzt – sie gelten ab der nächsten Nachricht.", "Instructions set – they apply from the next message.") };
bot.send(chat, text, None).await?;
Ok(())
}
const PERMISSION_MODES: &[&str] = &["auto", "default", "accept_edits", "bypass"];
const EFFORTS: &[&str] = &["low", "medium", "high", "xhigh", "max"];