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]>
115 lines
2.9 KiB
Rust
115 lines
2.9 KiB
Rust
use cm_domain::{shard_of, AgentId, Session, SessionId, WorkspaceId};
|
|
use sqlx::PgPool;
|
|
|
|
use crate::DbError;
|
|
|
|
fn row_to_session(
|
|
id: uuid::Uuid,
|
|
agent_id: uuid::Uuid,
|
|
workspace_id: uuid::Uuid,
|
|
title: String,
|
|
shard: i16,
|
|
created_at: time::OffsetDateTime,
|
|
last_active_at: time::OffsetDateTime,
|
|
) -> Session {
|
|
Session {
|
|
id: SessionId::from(id),
|
|
agent_id: AgentId::from(agent_id),
|
|
workspace_id: WorkspaceId::from(workspace_id),
|
|
title,
|
|
shard: shard as u16,
|
|
created_at,
|
|
last_active_at,
|
|
}
|
|
}
|
|
|
|
pub async fn create(
|
|
pool: &PgPool,
|
|
agent_id: AgentId,
|
|
workspace_id: WorkspaceId,
|
|
title: &str,
|
|
) -> Result<Session, DbError> {
|
|
let id = SessionId::new();
|
|
let shard = shard_of(agent_id);
|
|
let row = sqlx::query!(
|
|
"INSERT INTO sessions (id, agent_id, workspace_id, title, shard)
|
|
VALUES ($1, $2, $3, $4, $5)
|
|
RETURNING created_at, last_active_at",
|
|
id.as_uuid(),
|
|
agent_id.as_uuid(),
|
|
workspace_id.as_uuid(),
|
|
title,
|
|
shard as i16,
|
|
)
|
|
.fetch_one(pool)
|
|
.await?;
|
|
Ok(Session {
|
|
id,
|
|
agent_id,
|
|
workspace_id,
|
|
title: title.to_owned(),
|
|
shard,
|
|
created_at: row.created_at,
|
|
last_active_at: row.last_active_at,
|
|
})
|
|
}
|
|
|
|
pub async fn get(pool: &PgPool, id: SessionId) -> Result<Session, DbError> {
|
|
let row = sqlx::query!(
|
|
"SELECT id, agent_id, workspace_id, title, shard, created_at, last_active_at
|
|
FROM sessions WHERE id = $1",
|
|
id.as_uuid(),
|
|
)
|
|
.fetch_one(pool)
|
|
.await?;
|
|
Ok(row_to_session(
|
|
row.id,
|
|
row.agent_id,
|
|
row.workspace_id,
|
|
row.title,
|
|
row.shard,
|
|
row.created_at,
|
|
row.last_active_at,
|
|
))
|
|
}
|
|
|
|
/// Sessions column ordering (§6): most recently active first.
|
|
pub async fn list_by_agent(pool: &PgPool, agent_id: AgentId) -> Result<Vec<Session>, DbError> {
|
|
let rows = sqlx::query!(
|
|
"SELECT id, agent_id, workspace_id, title, shard, created_at, last_active_at
|
|
FROM sessions WHERE agent_id = $1
|
|
ORDER BY last_active_at DESC, id DESC",
|
|
agent_id.as_uuid(),
|
|
)
|
|
.fetch_all(pool)
|
|
.await?;
|
|
Ok(rows
|
|
.into_iter()
|
|
.map(|row| {
|
|
row_to_session(
|
|
row.id,
|
|
row.agent_id,
|
|
row.workspace_id,
|
|
row.title,
|
|
row.shard,
|
|
row.created_at,
|
|
row.last_active_at,
|
|
)
|
|
})
|
|
.collect())
|
|
}
|
|
|
|
/// Marks a session as just-used so it sorts to the top of the column.
|
|
pub async fn touch(pool: &PgPool, id: SessionId) -> Result<(), DbError> {
|
|
let result = sqlx::query!(
|
|
"UPDATE sessions SET last_active_at = clock_timestamp() WHERE id = $1",
|
|
id.as_uuid(),
|
|
)
|
|
.execute(pool)
|
|
.await?;
|
|
if result.rows_affected() == 0 {
|
|
return Err(DbError::NotFound);
|
|
}
|
|
Ok(())
|
|
}
|