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.

Connections: say kwant on screen; accounts list the bots that fall back to them

Lin (kwant bot)4bcf4c393b70
diff --git a/docs/connections.md b/docs/connections.md
index a4f5d133..763a5898 100644
--- a/docs/connections.md
+++ b/docs/connections.md
@@ -1,6 +1,6 @@
# Connections: API
-One list of everything kwnt's bots reach outside the app, with its status, last check and the
+One list of everything kwant's bots reach outside the app, with its status, last check and the
bots that use it:
- MCP servers
@@ -10,7 +10,7 @@ bots that use it:
Composio is offered as an **optional** MCP connector. It is off by default, and it is labelled
everywhere as storing the person's app sign-ins on Composio's servers. Every other login stays in
-kwnt's own vault or database.
+kwant's own vault or database.
Both routes are **person-only**, because the list names saved logins:
@@ -58,7 +58,7 @@ order each list comes from. Sort or group it on the client.
| `status_detail` | optional readable reason ("Out of quota until …", the last error) |
| `last_check` | RFC 3339, or `null` when never checked |
| `used_by` | the bots that use it, sorted by name. Empty while it is off |
-| `logins_stored` | `vault` (kwnt's password vault or Bitwarden), `kwnt` (kwnt's database or the engine CLI's own login folder), or `composio` (Composio's servers) |
+| `logins_stored` | `vault` (kwant's password vault or Bitwarden), `kwnt` (kwant's database or the engine CLI's own login folder; the value keeps the binary's name and is not shown as is), or `composio` (Composio's servers) |
| `manage` | the existing API for changing it (link the UI's edit screen from the kind) |
What `detail` holds for each kind:
@@ -82,8 +82,8 @@ What `detail` holds for each kind:
| last test passed | `connected` |
| last test needed a sign-in | `needs_sign_in` |
| last test failed | `error`, with the error |
-| not tested since kwnt started, but signed in with OAuth | `connected` |
-| not tested since kwnt started | `unknown` |
+| not tested since kwant started, but signed in with OAuth | `connected` |
+| not tested since kwant started | `unknown` |
`last_check` is the last `POST /api/mcp/servers/:id/test`. It is kept **in memory**, so it is
empty again after a restart. Call the test route to refresh it ("Check now").
@@ -103,7 +103,7 @@ empty again after a restart. Call the test route to refresh it ("Check now").
**Saved login**
-- Always `connected`. kwnt doesn't try a saved password on its own.
+- Always `connected`. kwant doesn't try a saved password on its own.
- `last_check` is the time it was last filled into a page.
**Loose ends source**
@@ -122,7 +122,7 @@ empty again after a restart. Call the test route to refresh it ("Check now").
| kind | bots |
|---|---|
| MCP server | every bot in the space, minus bots switched off for that server. Nobody while the server is off |
-| account | bots bound to it, plus bots with no binding on its engine while it is the engine's default |
+| account | bots whose turns on its engine start on it: a bot bound to it, or a bot with no binding (or bound to another engine's account) while it is the engine's default. Bots on "auto" count for every engine, pinned bots only for theirs. Nobody while it is off |
| browser_login | the bot it was saved for, or the lead and members of the team or channel it was saved for (they share that browser) |
| email, github | the space's Loose ends bot, when Loose ends ownership is on |
@@ -147,7 +147,7 @@ empty again after a restart. Call the test route to refresh it ("Check now").
"connection_id": null,
"enabled": false,
"logins_stored": "composio",
- "warning": "Composio keeps your app sign-ins on Composio's servers, not in kwnt's vault, and your bots' tool calls through it pass through Composio.",
+ "warning": "Composio keeps your app sign-ins on Composio's servers, not in kwant's vault, and your bots' tool calls through it pass through Composio.",
"add": "/api/connections/composio"
}
```
@@ -184,7 +184,7 @@ per-bot opt-outs, testing and removing all use those routes.
## Known limits
- MCP `last_check` is kept in memory only (see the MCP status rules).
-- Loose ends sources are global in kwnt rather than per space, so every space lists them, and
+- Loose ends sources are global in kwant rather than per space, so every space lists them, and
`used_by` names the current space's Loose ends bot.
- Engine CLI logins (`~/.claude`, Codex, Grok) live in each CLI's own folder, reported as
- `logins_stored: "kwnt"`. kwnt doesn't copy them into the vault.
+ `logins_stored: "kwnt"`. kwant doesn't copy them into the vault.
diff --git a/src/server/connections.rs b/src/server/connections.rs
index 46702ce0..75f07718 100644
--- a/src/server/connections.rs
+++ b/src/server/connections.rs
@@ -32,7 +32,7 @@ const REFUSAL: &str = "only the person manages connections";
/// The name the Composio connector gets as an MCP server.
pub const COMPOSIO_NAME: &str = "composio";
/// Said wherever Composio is offered or connected.
-pub const COMPOSIO_WARNING: &str = "Composio keeps your app sign-ins on Composio's servers, not in kwnt's vault, \
+pub const COMPOSIO_WARNING: &str = "Composio keeps your app sign-ins on Composio's servers, not in kwant's vault, \
and your bots' tool calls through it pass through Composio.";
/// A bot that uses a connection.
@@ -128,8 +128,8 @@ fn mcp_status(server: &McpServer, oauth_connected: bool, check: Option<&McpCheck
Some(c) if c.ok => ("connected", None),
Some(c) if c.auth_required => ("needs_sign_in", Some("Sign-in required".into())),
Some(c) => ("error", c.error.clone()),
- None if oauth_connected => ("connected", Some("Signed in; not tested since kwnt started".into())),
- None => ("unknown", Some("Not tested since kwnt started".into())),
+ None if oauth_connected => ("connected", Some("Signed in; not tested since kwant started".into())),
+ None => ("unknown", Some("Not tested since kwant started".into())),
}
}
@@ -166,18 +166,27 @@ async fn mcp_connections(state: &AppState, space: &SpaceId, kwants: &[Kwant]) ->
.collect()
}
-/// Bots that run on an account: bound to it, or unbound on its engine while it is the default.
+/// Bots that run on an account: those whose turns on its engine start there. A bot on "auto"
+/// may run on any engine, a pinned one only on its own; on that engine the bot's bound account
+/// comes first, else the engine's default (`preference_order`, as a turn picks it).
fn account_users<'a>(
profile: &crate::db::models::LlmProfile,
+ profiles: &[crate::db::models::LlmProfile],
kwants: &'a [Kwant],
bindings: &HashMap<String, (Option<String>, bool)>,
) -> Vec<&'a Kwant> {
- let engine = Engine::parse(&profile.engine);
+ let Some(engine) = Engine::parse(&profile.engine) else {
+ return Vec::new();
+ };
kwants
.iter()
- .filter(|k| match bindings.get(&k.id).and_then(|(p, _)| p.as_deref()) {
- Some(bound) => bound == profile.id,
- None => profile.is_default && engine.is_some() && Engine::from_model(&k.preferred_model) == engine,
+ .filter(|k| match crate::router::parse_pin(&k.preferred_model).family {
+ None => true,
+ Some(family) => family == engine.as_str(),
+ })
+ .filter(|k| {
+ let bound = bindings.get(&k.id).and_then(|(p, _)| p.as_deref());
+ crate::profiles::preference_order(profiles, engine, bound).first().is_some_and(|p| p.id == profile.id)
})
.collect()
}
@@ -186,7 +195,7 @@ async fn account_connections(state: &AppState, space: &SpaceId, kwants: &[Kwant]
let profiles = state.db.list_profiles(space).await.unwrap_or_default();
let bindings = state.db.list_kwant_bindings(space).await.unwrap_or_default();
let users: HashMap<String, Vec<UsedBy>> =
- profiles.iter().map(|p| (p.id.clone(), used(&account_users(p, kwants, &bindings)))).collect();
+ profiles.iter().map(|p| (p.id.clone(), used(&account_users(p, &profiles, kwants, &bindings)))).collect();
super::profile_routes::views(state, profiles)
.await
.into_iter()
diff --git a/tests/connections_test.rs b/tests/connections_test.rs
index 5b1c7d9a..9b47643d 100644
--- a/tests/connections_test.rs
+++ b/tests/connections_test.rs
@@ -157,3 +157,46 @@ async fn connections_are_person_only() {
.await;
assert_eq!(s, StatusCode::FORBIDDEN);
}
+
+#[tokio::test]
+async fn accounts_list_the_bots_that_fall_back_to_them() {
+ let env = setup().await;
+ // `setup` pins two bots to Claude; the third default bot stays on "auto".
+ let (_, kwants) = call(&env.app, "GET", "/api/kwants", None).await;
+ let auto = kwants.as_array().unwrap().iter().find(|k| k["preferred_model"] == "auto").expect("an auto bot")["id"]
+ .as_str()
+ .unwrap()
+ .to_string();
+
+ // Before any binding, This machine is the Claude default: all three default bots use it.
+ let (_, list) = call(&env.app, "GET", "/api/connections", None).await;
+ let mut all = vec![env.a.clone(), env.b.clone(), auto.clone()];
+ all.sort();
+ let mut users = user_ids(find(&list, "account:prf_system_claude"));
+ users.sort();
+ assert_eq!(users, all, "unbound bots fall back to the default account");
+ assert_eq!(user_ids(find(&list, "account:prf_system_codex")), vec![auto.clone()], "only an auto bot may run on Codex");
+
+ // A second Claude account with B bound to it: B moves there, the rest stay on the default.
+ let (s, work) = call(
+ &env.app,
+ "POST",
+ "/api/profiles",
+ Some(json!({"engine": "claude", "name": "Work", "kind": "cli_home", "priority": 100})),
+ )
+ .await;
+ assert!(s.is_success(), "{work}");
+ let work_id = work["id"].as_str().unwrap().to_string();
+ let mut body = kwants.as_array().unwrap().iter().find(|k| k["id"] == env.b.as_str()).unwrap().clone();
+ body.as_object_mut()
+ .unwrap()
+ .retain(|key, _| ["name", "title", "persona_prompt", "soul", "avatar_sprite", "preferred_model"].contains(&key.as_str()));
+ body["profile_id"] = json!(work_id);
+ let (s, v) = call(&env.app, "PUT", &format!("/api/kwants/{}", env.b), Some(body)).await;
+ assert_eq!(s, StatusCode::OK, "{v}");
+
+ let (_, list) = call(&env.app, "GET", "/api/connections", None).await;
+ assert_eq!(user_ids(find(&list, &format!("account:{work_id}"))), vec![env.b.clone()]);
+ let users = user_ids(find(&list, "account:prf_system_claude"));
+ assert!(users.contains(&env.a) && users.contains(&auto) && !users.contains(&env.b), "{users:?}");
+}