diff options
| author | Michelle Tilley <michelle@michelletilley.net> | 2026-04-21 10:32:54 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-04-21 10:32:54 -0700 |
| commit | 0f20ee4eb871907defe7848f0d3e2203cfff057e (patch) | |
| tree | cda9034c4c6e7b5ecf0fe957978284e9138b80ff /crates/atuin-ai/src/store.rs | |
| parent | chore: Clarified note about regular expressions matching in path. (#3427) (diff) | |
| download | atuin-0f20ee4eb871907defe7848f0d3e2203cfff057e.zip | |
feat: AI tool rendering overhaul + edit_file tool (#3423)
Overhaul of how AI tool calls are modeled, rendered, and displayed in
the Atuin AI TUI. Fixes bugs in shell command output capture, implements
the `edit_file` tool with full safety infrastructure, and adds a diff
preview for edits.
Diffstat (limited to 'crates/atuin-ai/src/store.rs')
| -rw-r--r-- | crates/atuin-ai/src/store.rs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/crates/atuin-ai/src/store.rs b/crates/atuin-ai/src/store.rs index 2a75d8f4..20b9e881 100644 --- a/crates/atuin-ai/src/store.rs +++ b/crates/atuin-ai/src/store.rs @@ -299,6 +299,38 @@ impl AiSessionStore { .await?; Ok(()) } + + // ── Session metadata (key-value per session) ── + + /// Read a metadata value for a session. Returns `None` if the key doesn't + /// exist or the session hasn't been persisted yet. + pub async fn get_metadata(&self, session_id: &str, key: &str) -> Result<Option<String>> { + let row: Option<(String,)> = + sqlx::query_as("SELECT value FROM session_metadata WHERE session_id = ?1 AND key = ?2") + .bind(session_id) + .bind(key) + .fetch_optional(&self.pool) + .await?; + + Ok(row.map(|(v,)| v)) + } + + /// Write a metadata value for a session (upsert). + pub async fn set_metadata(&self, session_id: &str, key: &str, value: &str) -> Result<()> { + let now = OffsetDateTime::now_utc().unix_timestamp(); + sqlx::query( + "INSERT INTO session_metadata (session_id, key, value, updated_at) + VALUES (?1, ?2, ?3, ?4) + ON CONFLICT (session_id, key) DO UPDATE SET value = ?3, updated_at = ?4", + ) + .bind(session_id) + .bind(key) + .bind(value) + .bind(now) + .execute(&self.pool) + .await?; + Ok(()) + } } #[cfg(test)] |
