feat(#2035): auto-discover dashboard-provisioned matrix accounts via token+homeserver sidecar

This commit is contained in:
damocles 2026-06-27 00:11:13 +02:00 committed by mara
commit 3b0a914487
6 changed files with 112 additions and 11 deletions

View file

@ -244,7 +244,9 @@ pub(super) async fn post_matrix_account_login(Form(f): Form<MatrixLoginForm>) ->
}
};
if let Err(e) = crate::priv_client::write_agent_matrix_token(agent, &token, Some(account)).await
if let Err(e) =
crate::priv_client::write_agent_matrix_token(agent, &token, Some(account), Some(homeserver))
.await
{
return error_response(&format!("matrix-account-login: write token failed: {e:#}"));
}

View file

@ -709,7 +709,7 @@ pub async fn ensure_user_for(
// unprivileged `hive-core` user and cannot write to agent-owned state
// directories directly. hive-priv writes the file 0600 and chowns it
// to the agent user so it is readable from inside the container.
crate::priv_client::write_agent_matrix_token(name, &access_token, None)
crate::priv_client::write_agent_matrix_token(name, &access_token, None, None)
.await
.with_context(|| format!("matrix: write matrix-token for {name} via hive-priv"))?;
tracing::info!(%name, "matrix: provisioned access token");

View file

@ -261,15 +261,22 @@ pub async fn write_agent_forge_token(agent_name: &str, token: &str) -> Result<()
/// `<state>/matrix-token-<name>` for an extra (external) account. The file
/// is written 0600 and chowned to the agent user so it is readable from
/// inside the agent container. hive-priv validates the account suffix.
///
/// `homeserver: Some(url)` (only meaningful with `account: Some`) also
/// writes the sidecar `<state>/matrix-account-<name>.json` so the daemon
/// can auto-discover the extra account without a `matrixAccounts` config
/// declaration (see issue tracker "external matrix account auto-discovery").
pub async fn write_agent_matrix_token(
agent_name: &str,
token: &str,
account: Option<&str>,
homeserver: Option<&str>,
) -> Result<()> {
ok(call(&PrivRequest::WriteAgentMatrixToken {
agent_name: agent_name.to_owned(),
token: token.to_owned(),
account: account.map(ToOwned::to_owned),
homeserver: homeserver.map(ToOwned::to_owned),
})
.await?)
}