Rebrand: TeamClaw -> Clawmates (clawmates.work)
Full-depth rename per the approved plan; the 'claw' product vocabulary (claws, /claws routes, clawId, Claw Chat) stays — it is now the brand. - Display brand: Clawmates (manifest, titles, hero, login/rail logo 'clawmates'); default host app.clawmates.work; registry ghcr.io/clawmates - Crates tc-* -> cm-* (16 crates + all imports); binaries clawmates-server/broker/bundler; images clawmates/*; env prefix CLAWMATES_* (+ CM_TEST_DATABASE_URL / CM_LIVE_LLM); config clawmates.toml; helm chart deploy/helm/clawmates with clawmates-* resources; db names clawmates*; sockets /run/clawmates; cookie cm_session; kind cluster clawmates-test; seccomp node profile clawmates-agent-profile.json - All 9 Playwright brand assertions updated in lockstep; historical spec document left untouched as the only remaining 'TeamClaw' - Local env migrated: dev pg clawmates-dev-pg/clawmates_dev, shared test server clawmates-test-pg, kind cluster recreated with image + profile, compose images rebuilt under clawmates/* Verified end to end: 161 Rust + 68 frontend tests, 29 Playwright journeys, 4 live kind tests, helm/install/LOC/placeholder gates, and the clean-room install rehearsal serving the clawmates login page from a signed bundle of the rebuilt images. Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
co-authored by
Claude Fable 5
parent
8046853feb
commit
add4f79fed
@@ -0,0 +1,180 @@
|
||||
use axum::extract::{Path, Query, State};
|
||||
use axum::http::StatusCode;
|
||||
use axum::Json;
|
||||
use cm_db::repo::audit::Actor;
|
||||
use cm_domain::{AccessPolicy, Agent, AgentId, AgentStatus};
|
||||
use serde::Deserialize;
|
||||
use serde_json::{json, Value};
|
||||
|
||||
use crate::{ApiError, AppState, Authed};
|
||||
|
||||
/// Loads an agent and enforces tenant isolation: agents in other workspaces
|
||||
/// are indistinguishable from non-existent ones.
|
||||
pub(crate) async fn workspace_agent(
|
||||
state: &AppState,
|
||||
user: &cm_auth::AuthedUser,
|
||||
agent_id: AgentId,
|
||||
) -> Result<Agent, ApiError> {
|
||||
let agent = cm_db::repo::agents::get(&state.pool, agent_id).await?;
|
||||
if agent.workspace_id != user.workspace_id {
|
||||
return Err(ApiError::NotFound);
|
||||
}
|
||||
Ok(agent)
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct CreateClawRequest {
|
||||
name: String,
|
||||
job_title: String,
|
||||
#[serde(default)]
|
||||
system_prompt: String,
|
||||
#[serde(default)]
|
||||
avatar: String,
|
||||
#[serde(default)]
|
||||
accent: String,
|
||||
#[serde(default)]
|
||||
wallpaper: String,
|
||||
}
|
||||
|
||||
/// POST /api/claws — completing creation yields a LIVE agent (§9).
|
||||
pub async fn create(
|
||||
State(state): State<AppState>,
|
||||
Authed(user): Authed,
|
||||
Json(body): Json<CreateClawRequest>,
|
||||
) -> Result<(StatusCode, Json<Agent>), ApiError> {
|
||||
let agent = Agent {
|
||||
id: AgentId::new(),
|
||||
workspace_id: user.workspace_id,
|
||||
name: body.name,
|
||||
job_title: body.job_title,
|
||||
system_prompt: body.system_prompt,
|
||||
avatar: body.avatar,
|
||||
accent: body.accent,
|
||||
wallpaper: body.wallpaper,
|
||||
managed_by: user.user_id,
|
||||
status: AgentStatus::Online,
|
||||
};
|
||||
cm_db::repo::agents::insert(&state.pool, &agent, &AccessPolicy::default()).await?;
|
||||
cm_db::repo::audit::append(
|
||||
&state.pool,
|
||||
user.workspace_id,
|
||||
Actor::User(user.user_id),
|
||||
"agent.created",
|
||||
"agent",
|
||||
&agent.id.to_string(),
|
||||
json!({"name": agent.name, "job_title": agent.job_title}),
|
||||
)
|
||||
.await?;
|
||||
Ok((StatusCode::CREATED, Json(agent)))
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct PatchClawRequest {
|
||||
name: Option<String>,
|
||||
job_title: Option<String>,
|
||||
system_prompt: Option<String>,
|
||||
avatar: Option<String>,
|
||||
accent: Option<String>,
|
||||
wallpaper: Option<String>,
|
||||
}
|
||||
|
||||
/// PATCH /api/claws/{id} — Edit profile (§7.7).
|
||||
pub async fn patch(
|
||||
State(state): State<AppState>,
|
||||
Authed(user): Authed,
|
||||
Path(id): Path<AgentId>,
|
||||
Json(body): Json<PatchClawRequest>,
|
||||
) -> Result<Json<Agent>, ApiError> {
|
||||
workspace_agent(&state, &user, id).await?;
|
||||
let updated = cm_db::repo::agents::update_profile(
|
||||
&state.pool,
|
||||
id,
|
||||
body.name.as_deref(),
|
||||
body.job_title.as_deref(),
|
||||
body.system_prompt.as_deref(),
|
||||
body.avatar.as_deref(),
|
||||
body.accent.as_deref(),
|
||||
body.wallpaper.as_deref(),
|
||||
)
|
||||
.await?;
|
||||
cm_db::repo::audit::append(
|
||||
&state.pool,
|
||||
user.workspace_id,
|
||||
Actor::User(user.user_id),
|
||||
"agent.updated",
|
||||
"agent",
|
||||
&id.to_string(),
|
||||
json!({}),
|
||||
)
|
||||
.await?;
|
||||
Ok(Json(updated))
|
||||
}
|
||||
|
||||
/// DELETE /api/claws/{id} — destructive (§7.7): workspace owners or the
|
||||
/// claw's manager only. Soft delete keeps rows for audit.
|
||||
pub async fn delete(
|
||||
State(state): State<AppState>,
|
||||
Authed(user): Authed,
|
||||
Path(id): Path<AgentId>,
|
||||
) -> Result<StatusCode, ApiError> {
|
||||
let agent = workspace_agent(&state, &user, id).await?;
|
||||
if !user.role.is_owner() && agent.managed_by != user.user_id {
|
||||
return Err(ApiError::Forbidden);
|
||||
}
|
||||
cm_db::repo::agents::soft_delete(&state.pool, id).await?;
|
||||
cm_db::repo::audit::append(
|
||||
&state.pool,
|
||||
user.workspace_id,
|
||||
Actor::User(user.user_id),
|
||||
"agent.deleted",
|
||||
"agent",
|
||||
&id.to_string(),
|
||||
json!({"name": agent.name}),
|
||||
)
|
||||
.await?;
|
||||
Ok(StatusCode::NO_CONTENT)
|
||||
}
|
||||
|
||||
/// PUT /api/claws/{id}/access — the §7.7 access toggles.
|
||||
pub async fn set_access(
|
||||
State(state): State<AppState>,
|
||||
Authed(user): Authed,
|
||||
Path(id): Path<AgentId>,
|
||||
Json(policy): Json<AccessPolicy>,
|
||||
) -> Result<Json<AccessPolicy>, ApiError> {
|
||||
workspace_agent(&state, &user, id).await?;
|
||||
cm_db::repo::agents::set_access_policy(&state.pool, id, &policy).await?;
|
||||
cm_db::repo::audit::append(
|
||||
&state.pool,
|
||||
user.workspace_id,
|
||||
Actor::User(user.user_id),
|
||||
"agent.access_changed",
|
||||
"agent",
|
||||
&id.to_string(),
|
||||
serde_json::to_value(&policy).unwrap_or_default(),
|
||||
)
|
||||
.await?;
|
||||
Ok(Json(policy))
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct SettingsQuery {
|
||||
#[serde(rename = "clawId")]
|
||||
claw_id: AgentId,
|
||||
}
|
||||
|
||||
/// GET /api/claws/settings/full?clawId= — Settings panel aggregate (§7.7).
|
||||
pub async fn settings_full(
|
||||
State(state): State<AppState>,
|
||||
Authed(user): Authed,
|
||||
Query(query): Query<SettingsQuery>,
|
||||
) -> Result<Json<Value>, ApiError> {
|
||||
let agent = workspace_agent(&state, &user, query.claw_id).await?;
|
||||
let policy = cm_db::repo::agents::access_policy(&state.pool, agent.id).await?;
|
||||
let manager = cm_db::repo::users::get(&state.pool, agent.managed_by).await?;
|
||||
Ok(Json(json!({
|
||||
"agent": agent,
|
||||
"access_policy": policy,
|
||||
"managed_by_name": manager.display_name,
|
||||
})))
|
||||
}
|
||||
Reference in New Issue
Block a user