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,163 @@
|
||||
use cm_domain::{AgentId, WorkspaceId};
|
||||
use sqlx::PgPool;
|
||||
use time::OffsetDateTime;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::DbError;
|
||||
|
||||
/// An inter-agent conversation (§7.2 Claw Chat).
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||
pub struct Thread {
|
||||
pub id: Uuid,
|
||||
pub workspace_id: Uuid,
|
||||
pub subject: String,
|
||||
pub sensitivity: String,
|
||||
pub participants: Vec<Uuid>,
|
||||
pub last_preview: Option<String>,
|
||||
#[serde(with = "time::serde::rfc3339")]
|
||||
pub created_at: OffsetDateTime,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||
pub struct ThreadMessage {
|
||||
pub id: Uuid,
|
||||
pub thread_id: Uuid,
|
||||
pub from_agent: Uuid,
|
||||
pub content: serde_json::Value,
|
||||
pub taint: Vec<String>,
|
||||
#[serde(with = "time::serde::rfc3339")]
|
||||
pub created_at: OffsetDateTime,
|
||||
}
|
||||
|
||||
/// Finds the 1:1 thread between two agents, or creates it with the given
|
||||
/// subject.
|
||||
pub async fn find_or_create(
|
||||
pool: &PgPool,
|
||||
workspace_id: WorkspaceId,
|
||||
a: AgentId,
|
||||
b: AgentId,
|
||||
subject: &str,
|
||||
) -> Result<Uuid, DbError> {
|
||||
let existing = sqlx::query_scalar!(
|
||||
r#"SELECT t.id FROM threads t
|
||||
WHERE t.workspace_id = $1
|
||||
AND EXISTS (SELECT 1 FROM thread_participants p
|
||||
WHERE p.thread_id = t.id AND p.agent_id = $2)
|
||||
AND EXISTS (SELECT 1 FROM thread_participants p
|
||||
WHERE p.thread_id = t.id AND p.agent_id = $3)
|
||||
LIMIT 1"#,
|
||||
workspace_id.as_uuid(),
|
||||
a.as_uuid(),
|
||||
b.as_uuid(),
|
||||
)
|
||||
.fetch_optional(pool)
|
||||
.await?;
|
||||
if let Some(id) = existing {
|
||||
return Ok(id);
|
||||
}
|
||||
|
||||
let id = Uuid::now_v7();
|
||||
let mut tx = pool.begin().await.map_err(DbError::from)?;
|
||||
sqlx::query!(
|
||||
"INSERT INTO threads (id, workspace_id, subject) VALUES ($1, $2, $3)",
|
||||
id,
|
||||
workspace_id.as_uuid(),
|
||||
subject,
|
||||
)
|
||||
.execute(&mut *tx)
|
||||
.await?;
|
||||
for agent in [a, b] {
|
||||
sqlx::query!(
|
||||
"INSERT INTO thread_participants (thread_id, agent_id) VALUES ($1, $2)",
|
||||
id,
|
||||
agent.as_uuid(),
|
||||
)
|
||||
.execute(&mut *tx)
|
||||
.await?;
|
||||
}
|
||||
tx.commit().await.map_err(DbError::from)?;
|
||||
Ok(id)
|
||||
}
|
||||
|
||||
pub async fn add_message(
|
||||
pool: &PgPool,
|
||||
thread_id: Uuid,
|
||||
from_agent: AgentId,
|
||||
content: serde_json::Value,
|
||||
taint: &[String],
|
||||
) -> Result<Uuid, DbError> {
|
||||
let id = Uuid::now_v7();
|
||||
sqlx::query!(
|
||||
"INSERT INTO thread_messages (id, thread_id, from_agent, content, taint)
|
||||
VALUES ($1, $2, $3, $4, $5)",
|
||||
id,
|
||||
thread_id,
|
||||
from_agent.as_uuid(),
|
||||
content,
|
||||
taint,
|
||||
)
|
||||
.execute(pool)
|
||||
.await?;
|
||||
Ok(id)
|
||||
}
|
||||
|
||||
/// Threads an agent participates in, most recent message first, with the
|
||||
/// last message preview (§7.2 thread list).
|
||||
pub async fn list_for_agent(pool: &PgPool, agent_id: AgentId) -> Result<Vec<Thread>, DbError> {
|
||||
let rows = sqlx::query!(
|
||||
r#"SELECT t.id, t.workspace_id, t.subject, t.sensitivity, t.created_at,
|
||||
ARRAY(SELECT p2.agent_id FROM thread_participants p2
|
||||
WHERE p2.thread_id = t.id) AS "participants!",
|
||||
(SELECT m.content->>'text' FROM thread_messages m
|
||||
WHERE m.thread_id = t.id
|
||||
ORDER BY m.created_at DESC LIMIT 1) AS last_preview
|
||||
FROM threads t
|
||||
JOIN thread_participants p ON p.thread_id = t.id
|
||||
WHERE p.agent_id = $1
|
||||
ORDER BY (SELECT max(m.created_at) FROM thread_messages m
|
||||
WHERE m.thread_id = t.id) DESC NULLS LAST"#,
|
||||
agent_id.as_uuid(),
|
||||
)
|
||||
.fetch_all(pool)
|
||||
.await?;
|
||||
Ok(rows
|
||||
.into_iter()
|
||||
.map(|r| Thread {
|
||||
id: r.id,
|
||||
workspace_id: r.workspace_id,
|
||||
subject: r.subject,
|
||||
sensitivity: r.sensitivity,
|
||||
participants: r.participants,
|
||||
last_preview: r.last_preview,
|
||||
created_at: r.created_at,
|
||||
})
|
||||
.collect())
|
||||
}
|
||||
|
||||
pub async fn messages(pool: &PgPool, thread_id: Uuid) -> Result<Vec<ThreadMessage>, DbError> {
|
||||
let rows = sqlx::query_as!(
|
||||
ThreadMessage,
|
||||
r#"SELECT id, thread_id, from_agent, content, taint, created_at
|
||||
FROM thread_messages WHERE thread_id = $1 ORDER BY created_at"#,
|
||||
thread_id,
|
||||
)
|
||||
.fetch_all(pool)
|
||||
.await?;
|
||||
Ok(rows)
|
||||
}
|
||||
|
||||
/// Whether an agent participates in a thread (API scoping).
|
||||
pub async fn is_participant(
|
||||
pool: &PgPool,
|
||||
thread_id: Uuid,
|
||||
agent_id: AgentId,
|
||||
) -> Result<bool, DbError> {
|
||||
let row = sqlx::query_scalar!(
|
||||
"SELECT 1 AS x FROM thread_participants WHERE thread_id = $1 AND agent_id = $2",
|
||||
thread_id,
|
||||
agent_id.as_uuid(),
|
||||
)
|
||||
.fetch_optional(pool)
|
||||
.await?;
|
||||
Ok(row.is_some())
|
||||
}
|
||||
Reference in New Issue
Block a user