Skip to content

armgit / kwant

Public Imported from GitHub
0

Your own team of AI bots in one self-hosted binary: spaces, every account you have, handoffs, approvals and routines. Open-source, self-hosted alternative to Grok Bot, Claude Duet and OpenAI dots. Rust + React.

Tell every bot it is a kwant bot, and switch off the engines' own schedulers

Lin (kwant bot)863c8b8db533
diff --git a/src/drivers/cli.rs b/src/drivers/cli.rs
index fa4bc179..7a09a1f5 100644
--- a/src/drivers/cli.rs
+++ b/src/drivers/cli.rs
@@ -178,6 +178,43 @@ pub fn grok_builtin_rules(folder: Option<&Path>) -> Vec<String> {
rules
}
+/// claude's own product features that would work outside kwnt, where the person can't see or
+/// undo them: its scheduler (cron, wake-ups, the `schedule`/`loop` skills, cloud routines), push
+/// notifications, and messaging other claude sessions. kwnt has its own routines and teammates.
+pub const CLAUDE_DISALLOWED_TOOLS: &[&str] = &[
+ "CronCreate",
+ "CronDelete",
+ "CronList",
+ "ScheduleWakeup",
+ "RemoteTrigger",
+ "PushNotification",
+ "ListAgents",
+ "SendMessage",
+ "Skill(schedule)",
+ "Skill(loop)",
+];
+
+/// grok's own scheduler, for the same reason. Its subagents are already off (`--no-subagents`).
+pub const GROK_DISALLOWED_TOOLS: &[&str] = &["SchedulerCreate", "SchedulerDelete", "SchedulerList"];
+
+/// codex features kept off for the same reason: its local automations and its cross-session
+/// memories. `-c features.<name>=false` rather than `--disable`, which refuses names a later codex
+/// drops and would stop every turn.
+pub const CODEX_DISABLED_FEATURES: &[&str] = &["in_app_local_automation", "memories"];
+
+/// One `--disallowedTools` value: claude reads a comma-separated list.
+pub fn claude_disallowed_args() -> [String; 2] {
+ ["--disallowedTools".into(), CLAUDE_DISALLOWED_TOOLS.join(",")]
+}
+
+pub fn grok_disallowed_args() -> [String; 2] {
+ ["--disallowed-tools".into(), GROK_DISALLOWED_TOOLS.join(",")]
+}
+
+pub fn codex_feature_args() -> Vec<String> {
+ CODEX_DISABLED_FEATURES.iter().flat_map(|f| ["-c".to_string(), format!("features.{f}=false")]).collect()
+}
+
pub const CODEX_SHELL_POLICY: [&str; 4] = [
"-c",
"shell_environment_policy.inherit=\"core\"",
@@ -786,7 +823,9 @@ impl Driver for CliDriver {
.arg("-c")
.arg(codex_mcp_servers(input.mcp.as_ref(), &user_servers))
// The model's shell sees only codex's core env, never kwnt's keys or rc exports
- .args(CODEX_SHELL_POLICY);
+ .args(CODEX_SHELL_POLICY)
+ // kwnt's routines and memory, never codex's own
+ .args(codex_feature_args());
// codex exec has no approval hook: its sandbox keeps file writes (and shell
// commands' writes) inside the bot's working folder instead of read-only everywhere
if input.workspace_dir.as_deref().is_some_and(|d| d.exists()) {
@@ -820,6 +859,9 @@ impl Driver for CliDriver {
grok_effort.into(),
"--no-plan".into(),
"--no-subagents".into(),
+ ]);
+ args.extend(grok_disallowed_args());
+ args.extend([
"--rules".into(),
system_prompt.clone(),
"-p".into(),
@@ -880,6 +922,8 @@ impl Driver for CliDriver {
cmd.arg("--permission-mode").arg("default");
// Skip starting the user's personal MCP servers on every chat turn
cmd.arg("--strict-mcp-config");
+ // kwnt's routines and teammates, never claude's own scheduler or sessions
+ cmd.args(claude_disallowed_args());
if let Some(ctx) = &input.mcp {
match crate::mcp::cli_config::write_claude_config(ctx) {
Ok(file) => {
@@ -1060,6 +1104,27 @@ mod tests {
assert!(!rules.iter().any(|r| r.starts_with("Bash")), "shell commands stay refused");
}
+ #[test]
+ fn engine_schedulers_and_sessions_are_switched_off() {
+ let [flag, list] = claude_disallowed_args();
+ assert_eq!(flag, "--disallowedTools");
+ let tools: Vec<&str> = list.split(',').collect();
+ for tool in ["CronCreate", "CronDelete", "CronList", "ScheduleWakeup", "RemoteTrigger", "PushNotification", "Skill(schedule)", "Skill(loop)"] {
+ assert!(tools.contains(&tool), "{tool} missing from {list}");
+ }
+ // kwnt's own tools and claude's lookups stay usable
+ assert!(!tools.iter().any(|t| t.starts_with("mcp__") || ["WebSearch", "WebFetch", "Read"].contains(t)));
+
+ assert_eq!(grok_disallowed_args(), ["--disallowed-tools", "SchedulerCreate,SchedulerDelete,SchedulerList"]);
+
+ let codex = codex_feature_args();
+ assert_eq!(codex, ["-c", "features.in_app_local_automation=false", "-c", "features.memories=false"]);
+ for pair in codex.iter().skip(1).step_by(2) {
+ let table: toml::Table = pair.parse().unwrap();
+ assert_eq!(table["features"].as_table().unwrap().values().next(), Some(&toml::Value::Boolean(false)), "{pair}");
+ }
+ }
+
#[test]
fn codex_shell_policy_is_core_only() {
let args = CODEX_SHELL_POLICY.join(" ");
diff --git a/src/drivers/mod.rs b/src/drivers/mod.rs
index faf63076..600b90c8 100644
--- a/src/drivers/mod.rs
+++ b/src/drivers/mod.rs
@@ -85,6 +85,34 @@ pub fn current_date_block(now: chrono::DateTime<chrono::FixedOffset>) -> String
)
}
+/// Who the bot is, whatever engine runs it. Claude Code, Codex and Grok each bring their own
+/// identity and product features (schedulers, memory files, remote sessions); a bot that believes
+/// it *is* that engine makes a "routine" inside the engine, where the person can't see or manage it.
+pub fn identity_block(name: &str, with_tools: bool) -> String {
+ let own = if with_tools {
+ format!(
+ "Use your `{tools}` tools for these: `routine_create` for anything that should happen on its own (\"every morning\", \"remind me at 5\"), \
+ `follow_up_create` for a one-off check-in, `memory_add` for notes worth keeping.",
+ tools = crate::mcp::SELF_SERVER_NAME,
+ )
+ } else {
+ "You have no kwant tools this turn, so you can't create routines, reminders or notes yourself. When the person wants something \
+ to happen on its own, say so and tell them to add it under Routines in kwant's sidebar, with the exact schedule and \
+ instructions to enter."
+ .to_string()
+ };
+ format!(
+ "\n\n[Who you are]\n\
+ You are {name}, a bot in kwant, the app the person is chatting in. kwant runs you on a model engine (Claude Code, Codex, Grok \
+ or a model API), but the engine only supplies the model: you are not Claude Code, Codex or Grok, and their own product \
+ features are not yours. Your tools, routines, memory, teammates and limits are kwant's.\n\
+ Never use the engine's own scheduler, cron, loop or wake-up tools, reminders or push notifications, its memory files, \
+ its remote or cloud sessions, or its ways of messaging other agents or sessions: they work outside kwant, where the person \
+ can't see, approve or undo them. {own} If kwant gives you no tool for something, say so plainly instead of using the \
+ engine's version."
+ )
+}
+
/// How a turn's agent reaches its bot browser, which decides what the prompt tells it.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BrowserAccess {
@@ -115,6 +143,8 @@ impl TurnInput {
"{}\n\nYou are {}, {}.",
self.kwant.persona_prompt, self.kwant.name, self.kwant.title
);
+ // The browser tools come from kwnt's own tools server, so `Tools` is exactly "kwnt's tools work this turn"
+ base.push_str(&identity_block(&self.kwant.name, browser == BrowserAccess::Tools));
let soul = self.kwant.soul.trim();
if !soul.is_empty() {
base.push_str(&format!(
@@ -402,3 +432,61 @@ pub fn create_driver_for_kwant(kwant: &Kwant) -> Box<dyn Driver> {
Err(_) => Box::new(ApiDriver::new(None, None)),
}
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ fn input() -> TurnInput {
+ TurnInput {
+ thread_id: "t1".into(),
+ kwant: Kwant {
+ space_id: crate::db::spaces::DEFAULT_SPACE_ID.into(),
+ id: "k1".into(),
+ name: "Wren".into(),
+ title: "Planner".into(),
+ persona_prompt: "p".into(),
+ soul: String::new(),
+ avatar_sprite: "s".into(),
+ driver_type: "cli".into(),
+ preferred_model: "claude".into(),
+ temperature: 0.7,
+ max_tokens: 1000,
+ level: 1,
+ turns_completed: 0,
+ created_at: None,
+ },
+ prompt: "create a routine that says good morning every day at 9".into(),
+ history: vec![],
+ model_override: None,
+ model: None,
+ effort_level: None,
+ team_context: None,
+ workspace_dir: None,
+ browser_api_url: None,
+ sandbox_id: None,
+ teammates: vec![],
+ continuity: String::new(),
+ mcp: None,
+ }
+ }
+
+ #[test]
+ fn every_turn_is_told_it_is_a_kwant_bot_not_its_engine() {
+ for access in [BrowserAccess::Tools, BrowserAccess::Shell, BrowserAccess::Unavailable] {
+ let prompt = input().format_system_prompt_with(access);
+ let who = prompt.find("[Who you are]").unwrap_or_else(|| panic!("{access:?}: {prompt}"));
+ // Right after the name, before team, memory and browser notes
+ assert!(who < prompt.find("[Current date]").unwrap(), "{access:?}");
+ assert!(prompt.contains("You are Wren, a bot in kwant"), "{access:?}");
+ assert!(prompt.contains("you are not Claude Code, Codex or Grok"), "{access:?}");
+ for feature in ["scheduler, cron, loop", "memory files", "remote or cloud sessions", "messaging other agents"] {
+ assert!(prompt.contains(feature), "{access:?}: {feature}");
+ }
+ assert!(prompt.contains("say so plainly instead of using the engine's version"), "{access:?}");
+ let with_tools = access == BrowserAccess::Tools;
+ assert_eq!(prompt.contains("`routine_create`"), with_tools, "{access:?}");
+ assert_eq!(prompt.contains("Routines in kwant's sidebar"), !with_tools, "{access:?}");
+ }
+ }
+}
diff --git a/tests/browser_tools_test.rs b/tests/browser_tools_test.rs
index 092a6902..912b7f4c 100644
--- a/tests/browser_tools_test.rs
+++ b/tests/browser_tools_test.rs
@@ -166,6 +166,18 @@ async fn claude_turn_gets_browser_tools_that_drive_its_own_panel() {
let none = input.format_system_prompt_with(BrowserAccess::Unavailable);
assert!(!none.contains("curl -sS") && !none.contains("browser_open") && none.contains("no way to use the browser"));
+ // Every turn knows it is a kwant bot, not the engine; only a turn whose tools work is sent to `routine_create`
+ for (label, p) in [("tools", &prompt), ("shell", &shell), ("unavailable", &none)] {
+ assert!(p.contains("[Who you are]"), "{label}");
+ assert!(p.contains(&format!("You are {}, a bot in kwant", bot.name)), "{label}");
+ assert!(p.contains("you are not Claude Code, Codex or Grok"), "{label}");
+ assert!(p.contains("Never use the engine's own scheduler"), "{label}");
+ }
+ assert!(prompt.contains("`routine_create`") && !prompt.contains("Routines in kwant's sidebar"));
+ for p in [&shell, &none] {
+ assert!(p.contains("Routines in kwant's sidebar") && !p.contains("`routine_create`"), "{p}");
+ }
+
if computer::local_chrome_path().is_none() {
eprintln!("browser part skipped: no Chrome or Chromium installed");
mcp_runtime::finish_turn(&state, &token).await;