Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
Merge remote-tracking branch 'upstream/main' into feature/admission-webhooks
Djalma Júnior1907e7d377b3
diff --cc crates/ai-memory-store/src/writer.rsindex 94ffff27,1c61e73d..5da6dff3--- a/crates/ai-memory-store/src/writer.rs+++ b/crates/ai-memory-store/src/writer.rs@@@ -11,8 -11,8 +11,8 @@@ use std::sync::{Arc, Mutex}use std::thread::{self, JoinHandle};use ai_memory_core::{- AgentKind, HandoffId, NewHandoff, NewObservation, NewPage, NewSession, ObservationId, PageId,- PagePath, ProjectId, SessionId, WorkspaceId,+ AgentKind, HandoffId, NewHandoff, NewObservation, NewPage, NewSession, NewUser, ObservationId,- PageId, ProjectId, SessionId, UserId, WorkspaceId,++ PageId, PagePath, ProjectId, SessionId, UserId, WorkspaceId,};use rusqlite::Connection;use tokio::sync::{mpsc, oneshot};@@@ -500,31 -517,94 +523,119 @@@ impl WriterHandlerx.await.map_err(|_| StoreError::WriterClosed)?}+ /// Delete every version of a page (by path) from the index. The wiki file+ /// removal is the caller's concern; this drops the derived rows so the+ /// page stops appearing in search/recent (the watcher does NOT reconcile+ /// file deletions — it only handles create/modify events).+ ///+ /// # Errors+ /// Returns [`StoreError::WriterClosed`] if the actor has shut down, or a+ /// SQL error from the delete.+ pub async fn delete_page(+ &self,+ workspace_id: WorkspaceId,+ project_id: ProjectId,+ path: PagePath,+ ) -> StoreResult<()> {+ let (tx, rx) = oneshot::channel();+ self.send(WriteCmd::DeletePage {+ workspace_id,+ project_id,+ path,+ reply: tx,+ })+ .await?;+ rx.await.map_err(|_| StoreError::WriterClosed)?+ }++ /// Insert a new user. `new_user` MUST already have been validated by+ /// [`NewUser::validate`](ai_memory_core::NewUser::validate); the+ /// caller (CLI or admin handler) generates the plaintext token,+ /// hashes it with the per-server pepper via+ /// [`crate::users::hash_token`], and passes only the digest in.+ ///+ /// # Errors+ /// - [`StoreError::WriterClosed`] if the writer has shut down.+ /// - [`StoreError::Duplicate`] when the username or email collides.+ /// - [`StoreError::Sqlite`] for any other SQL failure.+ pub async fn create_user(+ &self,+ new_user: NewUser,+ token_hash: [u8; TOKEN_HASH_LEN],+ ) -> StoreResult<UserId> {+ let (tx, rx) = oneshot::channel();+ self.send(WriteCmd::CreateUser {+ new_user,+ token_hash,+ reply: tx,+ })+ .await?;+ rx.await.map_err(|_| StoreError::WriterClosed)?+ }++ /// Replace a user's token hash with a freshly-generated digest.+ /// Implicitly clears `token_expired_at` — rotating an expired+ /// token only makes sense to make it usable again. Returns `false`+ /// when the user id doesn't exist; `true` on successful update.+ ///+ /// # Errors+ /// Returns [`StoreError::WriterClosed`] / [`StoreError::Sqlite`]+ /// per the usual writer-actor flow.+ pub async fn rotate_user_token(+ &self,+ user_id: UserId,+ new_token_hash: [u8; TOKEN_HASH_LEN],+ ) -> StoreResult<bool> {+ let (tx, rx) = oneshot::channel();+ self.send(WriteCmd::RotateUserToken {+ user_id,+ new_token_hash,+ reply: tx,+ })+ .await?;+ rx.await.map_err(|_| StoreError::WriterClosed)?+ }++ /// Stamp `token_expired_at = now()` so the user's current token stops+ /// authenticating. Idempotent — repeating the call leaves the original+ /// expiry timestamp untouched. Returns `false` when the user doesn't exist.+ ///+ /// # Errors+ /// Returns [`StoreError::WriterClosed`] / [`StoreError::Sqlite`].+ pub async fn expire_user_token(&self, user_id: UserId) -> StoreResult<bool> {+ let (tx, rx) = oneshot::channel();+ self.send(WriteCmd::ExpireUserToken { user_id, reply: tx })+ .await?;+ rx.await.map_err(|_| StoreError::WriterClosed)?+ }++ /// Clear `token_expired_at`, re-activating the user's existing token.+ /// Idempotent. Returns `false` when the user doesn't exist.+ ///+ /// # Errors+ /// Returns [`StoreError::WriterClosed`] / [`StoreError::Sqlite`].+ pub async fn revive_user_token(&self, user_id: UserId) -> StoreResult<bool> {+ let (tx, rx) = oneshot::channel();+ self.send(WriteCmd::ReviveUserToken { user_id, reply: tx })+ .await?;+ rx.await.map_err(|_| StoreError::WriterClosed)?+ }++ /// Update `last_seen_at = now()` for the user. Called fire-and-forget+ /// by the auth middleware on every authenticated request. Returns+ /// `false` when the user doesn't exist (caller authenticated against+ /// a token whose user vanished mid-request — already a logic error+ /// elsewhere).+ ///+ /// # Errors+ /// Returns [`StoreError::WriterClosed`] / [`StoreError::Sqlite`].+ pub async fn touch_user_last_seen(&self, user_id: UserId) -> StoreResult<bool> {+ let (tx, rx) = oneshot::channel();+ self.send(WriteCmd::TouchUserLastSeen { user_id, reply: tx })+ .await?;+ rx.await.map_err(|_| StoreError::WriterClosed)?+ }+async fn send(&self, cmd: WriteCmd) -> StoreResult<()> {self.inner.tx