Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions .claude/settings.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 0 additions & 11 deletions cli/migrations/agent-trace/015_create_session_models.sql

This file was deleted.

6 changes: 0 additions & 6 deletions cli/src/cli_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,12 +347,6 @@ pub enum HooksSubcommand {

#[command(about = "Run conversation-trace hook (reads JSON payload from STDIN)")]
ConversationTrace,

#[command(
name = "session-model",
about = "Ingest editor session model attribution (reads JSON payload from STDIN)"
)]
SessionModel,
}

#[derive(Subcommand, Debug, Clone, PartialEq, Eq)]
Expand Down
3 changes: 1 addition & 2 deletions cli/src/generated_migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ pub static AGENT_TRACE_MIGRATIONS: &[(&str, &str)] = &[
("012_create_parts_session_message_order_index", include_str!("../migrations/agent-trace/012_create_parts_session_message_order_index.sql")),
("013_create_messages_updated_at_trigger", include_str!("../migrations/agent-trace/013_create_messages_updated_at_trigger.sql")),
("014_create_parts_updated_at_trigger", include_str!("../migrations/agent-trace/014_create_parts_updated_at_trigger.sql")),
("015_create_session_models", include_str!("../migrations/agent-trace/015_create_session_models.sql")),
("016_add_diff_traces_payload_type", include_str!("../migrations/agent-trace/016_add_diff_traces_payload_type.sql")),
("015_add_diff_traces_payload_type", include_str!("../migrations/agent-trace/015_add_diff_traces_payload_type.sql")),
];

#[rustfmt::skip]
Expand Down
111 changes: 1 addition & 110 deletions cli/src/services/agent_trace_db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,31 +69,6 @@ pub const INSERT_PART_SQL: &str =
"INSERT INTO parts (type, text, message_id, session_id, generated_at_unix_ms)
VALUES (?1, ?2, ?3, ?4, ?5)";

/// Parameterized SQL for upserting editor session model attribution.
pub const UPSERT_SESSION_MODEL_SQL: &str = "INSERT INTO session_models (
tool_name,
session_id,
model_id,
tool_version,
session_start_time_ms
) VALUES (?1, ?2, ?3, ?4, ?5)
ON CONFLICT(tool_name, session_id) DO UPDATE SET
model_id = excluded.model_id,
tool_version = excluded.tool_version,
session_start_time_ms = excluded.session_start_time_ms,
updated_at = strftime('%Y-%m-%dT%H:%M:%fZ', 'now')";

/// Parameterized SQL for retrieving editor session model attribution.
pub const SELECT_SESSION_MODEL_SQL: &str = "SELECT
tool_name,
session_id,
model_id,
tool_version,
session_start_time_ms
FROM session_models
WHERE tool_name = ?1 AND session_id = ?2
LIMIT 1";

/// Agent trace database configuration.
pub struct AgentTraceDbSpec;

Expand Down Expand Up @@ -144,26 +119,6 @@ pub struct DiffTraceInsert<'a> {
pub payload_type: &'a str,
}

/// Session model attribution payload to upsert into the agent trace database.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct SessionModelUpsert<'a> {
pub tool_name: &'a str,
pub session_id: &'a str,
pub model_id: &'a str,
pub tool_version: Option<&'a str>,
pub session_start_time_ms: i64,
}

/// Durable session model attribution row read from the agent trace database.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct SessionModelAttribution {
pub tool_name: String,
pub session_id: String,
pub model_id: String,
pub tool_version: Option<String>,
pub session_start_time_ms: i64,
}

/// Raw diff trace row read from the agent trace database.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct DiffTracePatchRow {
Expand Down Expand Up @@ -338,20 +293,6 @@ impl AgentTraceDb {
insert_agent_trace_with(self, input)
}

/// Upsert editor session model attribution into the `session_models` table.
pub fn upsert_session_model(&self, input: SessionModelUpsert<'_>) -> Result<u64> {
upsert_session_model_with(self, input)
}

/// Retrieve editor session model attribution by `(tool_name, session_id)`.
pub fn session_model_by_tool_and_session(
&self,
tool_name: &str,
session_id: &str,
) -> Result<Option<SessionModelAttribution>> {
session_model_by_tool_and_session_with(self, tool_name, session_id)
}

/// Query and parse recent diff trace patches within the inclusive time window.
pub fn recent_diff_trace_patches(
&self,
Expand Down Expand Up @@ -487,22 +428,6 @@ fn insert_part_with<M: DbSpec>(db: &TursoDb<M>, input: InsertPartInsert) -> Resu
)
}

fn upsert_session_model_with<M: DbSpec>(
db: &TursoDb<M>,
input: SessionModelUpsert<'_>,
) -> Result<u64> {
db.execute(
UPSERT_SESSION_MODEL_SQL,
(
input.tool_name,
input.session_id,
input.model_id,
input.tool_version,
input.session_start_time_ms,
),
)
}

fn insert_parts_with<M: DbSpec>(db: &TursoDb<M>, inputs: Vec<InsertPartInsert>) -> Result<u64> {
if inputs.is_empty() {
return Ok(0);
Expand Down Expand Up @@ -538,40 +463,6 @@ fn numbered_placeholders(start: usize, count: usize) -> String {
format!("({placeholders})")
}

fn session_model_by_tool_and_session_with<M: DbSpec>(
db: &TursoDb<M>,
tool_name: &str,
session_id: &str,
) -> Result<Option<SessionModelAttribution>> {
let rows = db.query_map(
SELECT_SESSION_MODEL_SQL,
(tool_name, session_id),
session_model_attribution_from_turso,
)?;

Ok(rows.into_iter().next())
}

fn session_model_attribution_from_turso(row: &turso::Row) -> Result<SessionModelAttribution> {
Ok(SessionModelAttribution {
tool_name: row
.get(0)
.context("failed to read session_models.tool_name")?,
session_id: row
.get(1)
.context("failed to read session_models.session_id")?,
model_id: row
.get(2)
.context("failed to read session_models.model_id")?,
tool_version: row
.get(3)
.context("failed to read session_models.tool_version")?,
session_start_time_ms: row
.get(4)
.context("failed to read session_models.session_start_time_ms")?,
})
}

fn recent_diff_trace_patches_with<M: DbSpec>(
db: &TursoDb<M>,
cutoff_time_ms: i64,
Expand Down Expand Up @@ -918,7 +809,7 @@ mod tests {
));
assert!(sqlite_object_exists(&db, "table", "messages"));
assert!(sqlite_object_exists(&db, "table", "parts"));
assert!(sqlite_object_exists(&db, "table", "session_models"));
assert!(!sqlite_object_exists(&db, "table", "session_models"));
assert!(sqlite_object_exists(
&db,
"index",
Expand Down
Loading
Loading