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.

Team hand-offs: checks, checkpoints and audits use the team's folder

Lin (kwant bot)3e8eadb7d2c9
diff --git a/CHANGELOG.md b/CHANGELOG.md
index dee7c7e2..90cb73cf 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -19,6 +19,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
- **One card per hand-off line.** A lead's message that hands the same teammate several lines (five
`@Frontend, please …` lines) now makes one task and board card per line instead of one card for the
whole message. The per-teammate cap (4) still applies; the rest wait for Continue and are sent once.
+- **Team hand-offs share one folder for checks and audits.** A hand-off card from a team's channel
+ now checks files, keeps checkpoints and runs its audit in the team's folder, where its owner wrote
+ them. Before, it looked in the owner's own folder, and the Swarm Auditor's challenger in its own,
+ so it could miss a file the owner had written (the challenger found no `index.html`).
## [Mac 0.4.0] - 2026-10-29
diff --git a/docs/mission-control.md b/docs/mission-control.md
index be208d42..dba9336c 100644
--- a/docs/mission-control.md
+++ b/docs/mission-control.md
@@ -405,11 +405,17 @@ The header works on `POST /api/tasks/:id/fork`, `POST /api/tasks/:id/retry` and
## 12. Checkpoints and restore (Phase B2)
Design and decisions: `/home/maus/shared/ship-software-safely/mission-control/phase-b/contract.md` §3
-and `decisions.md` (D4, D6, D8, D9). A checkpoint is a snapshot of a task's folder (the mission's
-`workspace_path`, else the owner bot's workspace). A restore writes back only the paths this task's
+and `decisions.md` (D4, D6, D8, D9). A checkpoint is a snapshot of a task's folder (see "The task folder" below). A restore writes back only the paths this task's
own runs changed. What a tool did outside the folder (Bash, web, email, other bots) is never undone:
it is listed as "not undone".
+**The task folder** (`missions::task_folder`) is where a task's file checks, evidence, checkpoints and
+audit turns look: the mission's `workspace_path`; else, for a task whose thread belongs to a team (a
+hand-off made in a team's channel or thread), the team's folder, where that hand-off's turns run;
+else the owner bot's own workspace. Before 2026-10-30 a team hand-off card without a mission fell back
+to the owner's own folder, so its checks and audit didn't see the files its owner wrote in the team
+folder. A hand-off from a direct chat (no team) still uses the owner's own folder.
+
### When a checkpoint is taken
- `before_run` when a task is claimed (runner, `task_claim`, a team-lead hand-off), and `after_run` when the claim ends (the task leaves `working`/`needs_you`).
@@ -744,7 +750,8 @@ no challenger) logs `audit_skipped`.
handed the task off. Ranked by verified tasks of the task's class (Performance Market), then fewest
challenges in the last 7 days, then name and id.
-**Exchange.** Two hidden turns, each `always_ask` (any call that could change something asks the
+**Exchange.** Two hidden turns, each in the task folder (§12; where the owner wrote the files, not the
+challenger's own folder), each `always_ask` (any call that could change something asks the
person; payments ask in every mode, D8), each capped at 20 minutes:
1. The challenger calls `audit_challenge {audit_id, risks: [{risk, evidence, evidence_ids?}]}` once:
diff --git a/src/server/missions/auditor.rs b/src/server/missions/auditor.rs
index 0e87ceb7..1faeaf58 100644
--- a/src/server/missions/auditor.rs
+++ b/src/server/missions/auditor.rs
@@ -211,13 +211,13 @@ pub async fn drive(state: &AppState, audit: &Audit) {
return finish(state, audit).await;
};
let p = challenge_prompt(state, audit, &task, &owner).await;
- let err = run_stage(state, audit, &challenger, "challenge", p).await;
+ let err = run_stage(state, audit, &task, &challenger, "challenge", p).await;
if state.db.move_audit(&audit.id, "challenge", "failed", Some(&ended_without("challenge", err.as_deref()))).await.unwrap_or(false) {
return finish(state, audit).await;
}
if matches!(state.db.get_audit(&audit.id).await, Ok(Some(a)) if a.status == "rebuttal") {
let p = rebuttal_prompt(state, audit, &task, &challenger).await;
- let err = run_stage(state, audit, &owner, "rebuttal", p).await;
+ let err = run_stage(state, audit, &task, &owner, "rebuttal", p).await;
// No answer: the audit ends with every risk still open
if matches!(state.db.get_audit(&audit.id).await, Ok(Some(a)) if a.status == "rebuttal") && state.db.record_rebuttal(&audit.id, &[]).await.ok().flatten().is_some() {
let _ = state.db.move_audit(&audit.id, "done", "done", Some(&ended_without("rebuttal", err.as_deref()))).await;
@@ -297,11 +297,15 @@ async fn finish(state: &AppState, audit: &Audit) {
/// One hidden turn of `bot` in its direct chat, every change asking the person. Its tokens are
/// added to the stage. The turn's error, if any.
-async fn run_stage(state: &AppState, audit: &Audit, bot: &Kwant, stage: &str, prompt: String) -> Option<String> {
+/// One audit turn of `bot`, in `task`'s folder (where its owner wrote the files), not the bot's own.
+async fn run_stage(state: &AppState, audit: &Audit, task: &Task, bot: &Kwant, stage: &str, prompt: String) -> Option<String> {
let started = Utc::now();
let job = state.turns.start_job([bot.id.clone()]);
let reply = match scope_for(state, bot, None, None, &job, 0).await {
- Ok(scope) => {
+ Ok(mut scope) => {
+ if let Some(dir) = super::task_folder(state, task).await {
+ scope.workspace_dir = Some(dir);
+ }
let mut opts = TurnOpts::always_asking("Audit");
(opts.unsaved, opts.quiet_failure, opts.purpose) = (true, true, Some(PURPOSE.into()));
opts.tier = tier_of(model_mode(state).await);
@@ -344,6 +348,7 @@ async fn challenge_prompt(state: &AppState, audit: &Audit, task: &Task, owner: &
"[Swarm Auditor] You are auditing task {tid} \"{title}\", done by {owner}. You are not its reviewer: \
you can't verify or fail it, and nothing in this audit counts as proof either way; only its checks \
or the person decide.\nAcceptance: {acc}\nEvidence attached:\n{ev}\nChecks:\n{ch}\n\
+ You are working in the task's folder, where {owner} worked, so its files are where they wrote them. \
Look for concrete reasons it may not meet its acceptance: wrong, missing, unsafe or unverifiable. \
Read what you need, but change nothing. Then call audit_challenge once with audit_id {aid} and at \
most {max} risks. Each risk needs `evidence`: what you looked at and what you saw (put ids from the \
diff --git a/src/server/missions/mod.rs b/src/server/missions/mod.rs
index c7a69932..6395e9e4 100644
--- a/src/server/missions/mod.rs
+++ b/src/server/missions/mod.rs
@@ -1040,7 +1040,9 @@ pub async fn create_task(state: &AppState, space: &SpaceId, t: NewTask) -> Resul
Ok(task)
}
-/// The folder a task's file checks and evidence resolve in: its mission's, else its owner's.
+/// The folder a task's file checks, evidence and audit resolve in: its mission's, else its
+/// thread's team's (a hand-off in a team runs in the team's folder, not the owner's own), else its
+/// owner's.
pub async fn task_folder(state: &AppState, task: &Task) -> Option<std::path::PathBuf> {
task_folder_in(&state.db, &state.config.data_dir, task).await
}
@@ -1054,8 +1056,19 @@ pub async fn task_folder_in(db: &crate::db::Database, data_dir: &std::path::Path
}
}
}
- let owner = task.owner_kwant_id.as_deref().or(task.suggested_kwant_id.as_deref())?;
let space = SpaceId::new(&task.space_id);
+ let team_id = match &task.thread_id {
+ Some(tid) => db.get_thread(tid).await.ok().flatten().and_then(|t| t.team_id),
+ None => None,
+ };
+ if let Some(Ok(Some(team))) = match &team_id {
+ Some(id) => Some(db.get_team(id).await),
+ None => None,
+ } {
+ let base = crate::db::spaces::space_data_dir(data_dir, &space);
+ return Some(crate::tools::team_workspace_path(&base, &team.name, team.workspace_path.as_deref(), team.repo_url.as_deref()));
+ }
+ let owner = task.owner_kwant_id.as_deref().or(task.suggested_kwant_id.as_deref())?;
Some(crate::tools::bot_workspace(&crate::db::spaces::space_data_dir(data_dir, &space), owner))
}
diff --git a/src/tools/mod.rs b/src/tools/mod.rs
index 4a7c152e..23ad130c 100644
--- a/src/tools/mod.rs
+++ b/src/tools/mod.rs
@@ -83,13 +83,10 @@ pub fn bot_workspace(space_data_dir: &std::path::Path, kwant_id: &str) -> PathBu
dir
}
-pub async fn resolve_or_prepare_workspace(
- base_data_dir: &std::path::Path,
- team_name: &str,
- workspace_path: Option<&str>,
- repo_url: Option<&str>,
-) -> PathBuf {
- let target_dir = if let Some(ws) = workspace_path.filter(|s| !s.trim().is_empty()) {
+/// The folder a team works in, as [`resolve_or_prepare_workspace`] picks it, without creating or
+/// cloning anything: its own path (`~/` expanded), its repo's clone, else the space's shared folder.
+pub fn team_workspace_path(base_data_dir: &std::path::Path, team_name: &str, workspace_path: Option<&str>, repo_url: Option<&str>) -> PathBuf {
+ if let Some(ws) = workspace_path.filter(|s| !s.trim().is_empty()) {
let trimmed = ws.trim();
if let Some(rest) = trimmed.strip_prefix("~/") {
if let Ok(home) = std::env::var("HOME") {
@@ -104,7 +101,16 @@ pub async fn resolve_or_prepare_workspace(
base_data_dir.join("workspaces").join(team_name)
} else {
base_data_dir.join("workspace")
- };
+ }
+}
+
+pub async fn resolve_or_prepare_workspace(
+ base_data_dir: &std::path::Path,
+ team_name: &str,
+ workspace_path: Option<&str>,
+ repo_url: Option<&str>,
+) -> PathBuf {
+ let target_dir = team_workspace_path(base_data_dir, team_name, workspace_path, repo_url);
if let Some(repo) = repo_url.filter(|s| !s.trim().is_empty()) {
let git_dir = target_dir.join(".git");
diff --git a/tests/handoff_folder_test.rs b/tests/handoff_folder_test.rs
new file mode 100644
index 00000000..9915f7bc
--- /dev/null
+++ b/tests/handoff_folder_test.rs
@@ -0,0 +1,211 @@
+//! A hand-off card in a team works in the team's folder, where its owner wrote the files: its file
+//! checks and its audit turns look there, not in the owner's or the challenger's own folder
+//! (promo footage S7, 2026-10-30: Frontend wrote index.html in the team folder, QA's audit looked
+//! in its own folder and found nothing). A fake claude CLI on PATH records the folder each audit
+//! turn runs in. Its own test binary: it changes PATH.
+
+use kwnt::{
+ broker::PermissionBroker,
+ config::Config,
+ db::{
+ missions::{NewCheck, NewTask, Task},
+ models::{Kwant, NewKwant, NewTeam},
+ spaces::SpaceId,
+ threads::NewDelegation,
+ Database,
+ },
+ router::LayaRouter,
+ server::{missions, missions::auditor, AppState},
+ tools::ToolRunner,
+};
+use serde_json::json;
+use std::path::{Path, PathBuf};
+use std::sync::OnceLock;
+use std::time::Duration;
+
+/// Writes the folder it runs in to `$KWNT_TEST_CWD/<pid>` for an audit prompt, and answers.
+const FAKE_CLAUDE: &str = r#"#!/bin/sh
+case "$1" in
+ auth) echo '{"loggedIn":true}'; exit 0 ;;
+esac
+for a; do last="$a"; done
+case "$last" in *"[Swarm Auditor]"*) pwd -P > "$KWNT_TEST_CWD/$$" ;; esac
+echo '{"type":"result","is_error":false,"num_turns":1,"result":"done"}'
+"#;
+
+fn cwd_dir() -> &'static PathBuf {
+ static DIR: OnceLock<PathBuf> = OnceLock::new();
+ DIR.get_or_init(|| {
+ let root = tempfile::tempdir().unwrap().keep();
+ let (bin, cwd) = (root.join("bin"), root.join("cwd"));
+ std::fs::create_dir_all(&bin).unwrap();
+ std::fs::create_dir_all(&cwd).unwrap();
+ let fake = bin.join("claude");
+ std::fs::write(&fake, FAKE_CLAUDE).unwrap();
+ #[cfg(unix)]
+ {
+ use std::os::unix::fs::PermissionsExt;
+ std::fs::set_permissions(&fake, std::fs::Permissions::from_mode(0o755)).unwrap();
+ }
+ std::env::set_var("KWNT_TEST_CWD", &cwd);
+ std::env::set_var("PATH", format!("{}:{}", bin.display(), std::env::var("PATH").unwrap_or_default()));
+ cwd
+ })
+}
+
+struct Env {
+ state: AppState,
+ team_dir: PathBuf,
+ owner: Kwant,
+ _tmp: tempfile::TempDir,
+}
+
+async fn bot(state: &AppState, name: &str) -> Kwant {
+ let input = NewKwant {
+ name: name.into(),
+ title: "Tester".into(),
+ persona_prompt: String::new(),
+ soul: String::new(),
+ avatar_sprite: "s".into(),
+ driver_type: "cli".into(),
+ preferred_model: "claude".into(),
+ };
+ state.db.create_kwant(&SpaceId::default_space(), &input).await.unwrap()
+}
+
+/// A team with its own folder (like `/tmp/coffee-site` in the footage): Lead, Frontend and a
+/// challenger named to sort first.
+async fn setup() -> Env {
+ cwd_dir();
+ let tmp = tempfile::tempdir().unwrap();
+ let data = tmp.path().join("data");
+ let db = Database::init(&data).await.unwrap();
+ let config = Config {
+ data_dir: data.clone(),
+ laya_url: "http://127.0.0.1:9".into(),
+ browser_cdp_url: Some("http://127.0.0.1:9".into()),
+ ..Config::default()
+ };
+ let state = AppState::new(
+ config.clone(),
+ db,
+ ToolRunner::new(data.join("workspace")),
+ PermissionBroker::new(),
+ LayaRouter::new(config.laya_url.clone()),
+ );
+ let (lead, owner, qa) = (bot(&state, "Lead").await, bot(&state, "Frontend").await, bot(&state, "Aaa QA").await);
+ let team_dir = tmp.path().join("coffee-site");
+ std::fs::create_dir_all(&team_dir).unwrap();
+ state
+ .db
+ .create_team(
+ &SpaceId::default_space(),
+ &NewTeam {
+ name: "web".into(),
+ description: None,
+ icon: None,
+ lead_kwant_id: lead.id.clone(),
+ member_kwants: vec![lead.id.clone(), owner.id.clone(), qa.id.clone()],
+ workspace_path: Some(team_dir.to_string_lossy().into()),
+ repo_url: None,
+ },
+ )
+ .await
+ .unwrap();
+ Env { state, team_dir, owner, _tmp: tmp }
+}
+
+/// The card a team lead's hand-off to Frontend makes (no mission), in Review, with the file
+/// Frontend wrote in the team's folder.
+async fn handoff_card(e: &Env) -> Task {
+ let space = SpaceId::default_space();
+ let team = e.state.db.list_teams(&space).await.unwrap().into_iter().find(|t| t.name == "web").unwrap();
+ let (thread, d) = e
+ .state
+ .db
+ .create_delegation(&NewDelegation {
+ lead_kwant_id: team.lead_kwant_id.clone(),
+ specialist_kwant_id: e.owner.id.clone(),
+ origin_channel_id: None,
+ origin_kwant_id: Some(team.lead_kwant_id.clone()),
+ origin_thread_id: None,
+ team_id: Some(team.id.clone()),
+ task: "Build the landing page".into(),
+ title: "Build the landing page".into(),
+ continue_lead: true,
+ depth: 1,
+ follow_up_at: None,
+ })
+ .await
+ .unwrap();
+ std::fs::write(e.team_dir.join("index.html"), "<h1>Coffee</h1>").unwrap();
+ e.state
+ .db
+ .create_task(
+ &space,
+ &NewTask {
+ title: "Build the landing page".into(),
+ acceptance: "index.html opens".into(),
+ state: "review".into(),
+ priority: 2,
+ owner_kwant_id: Some(e.owner.id.clone()),
+ max_attempts: 3,
+ source_kind: "delegation".into(),
+ source_id: Some(d.id.clone()),
+ thread_id: Some(thread.id.clone()),
+ created_by: "kwant".into(),
+ ..Default::default()
+ },
+ )
+ .await
+ .unwrap()
+}
+
+fn same(a: &Path, b: &Path) -> bool {
+ std::fs::canonicalize(a).ok() == std::fs::canonicalize(b).ok()
+}
+
+#[tokio::test]
+async fn a_team_hand_off_card_checks_files_in_the_team_folder() {
+ let e = setup().await;
+ let t = handoff_card(&e).await;
+ let folder = missions::task_folder(&e.state, &t).await.expect("the card has a folder");
+ assert!(same(&folder, &e.team_dir), "the card's folder is {}, not the team's {}", folder.display(), e.team_dir.display());
+
+ // A person's file check on the card finds the file Frontend wrote
+ e.state
+ .db
+ .add_check(&NewCheck {
+ task_id: t.id.clone(),
+ kind: "file_exists".into(),
+ spec: json!({"path": "index.html"}),
+ required: true,
+ approved: true,
+ requested_by: "person".into(),
+ approved_by: Some("person".into()),
+ })
+ .await
+ .unwrap();
+ let check = e.state.db.list_checks(&t.id).await.unwrap().remove(0);
+ let ran = missions::checks::run_check(&e.state, &t, &check).await;
+ assert_eq!(ran.status, "passed", "index.html in the team folder: {ran:?}");
+}
+
+#[tokio::test]
+async fn the_auditor_challenges_a_team_hand_off_in_the_team_folder() {
+ let e = setup().await;
+ let t = handoff_card(&e).await;
+ let audit = auditor::start(&e.state, &t, "manual").await.expect("the audit opens");
+ let seen_before: Vec<_> = std::fs::read_dir(cwd_dir()).unwrap().map(|f| f.unwrap().path()).collect();
+ tokio::time::timeout(Duration::from_secs(60), auditor::drive(&e.state, &audit)).await.expect("the audit ends");
+ let ran: Vec<String> = std::fs::read_dir(cwd_dir())
+ .unwrap()
+ .map(|f| f.unwrap().path())
+ .filter(|p| !seen_before.contains(p))
+ .map(|p| std::fs::read_to_string(p).unwrap().trim().to_string())
+ .collect();
+ assert!(!ran.is_empty(), "the challenge turn ran");
+ for dir in &ran {
+ assert!(same(Path::new(dir), &e.team_dir), "an audit turn ran in {dir}, not the team folder {}", e.team_dir.display());
+ }
+}