[codex] fix kanban session matching (#538)
* fix kanban session matching * tighten kanban task session lookup * remove favicon svg
This commit is contained in:
@@ -3,7 +3,12 @@ import { readFile } from 'fs/promises'
|
||||
import { resolve, normalize } from 'path'
|
||||
import { homedir } from 'os'
|
||||
import * as kanbanCli from '../../services/hermes/hermes-kanban'
|
||||
import { searchSessionSummariesWithProfile, getSessionDetailFromDbWithProfile } from '../../db/hermes/sessions-db'
|
||||
import {
|
||||
searchSessionSummariesWithProfile,
|
||||
getSessionDetailFromDbWithProfile,
|
||||
getExactSessionDetailFromDbWithProfile,
|
||||
findLatestExactSessionIdWithProfile,
|
||||
} from '../../db/hermes/sessions-db'
|
||||
|
||||
function getLatestRunProfile(detail: { runs: Array<{ profile: string | null }> }): string | null {
|
||||
return [...detail.runs].reverse().find(run => run.profile)?.profile || null
|
||||
@@ -34,13 +39,12 @@ export async function get(ctx: Context) {
|
||||
const profile = getLatestRunProfile(detail)
|
||||
if (profile) {
|
||||
try {
|
||||
const results = await searchSessionSummariesWithProfile(detail.task.id, profile, undefined, 5)
|
||||
if (results.length > 0) {
|
||||
const sessionId = results[0].id
|
||||
const sessionDetail = await getSessionDetailFromDbWithProfile(sessionId, profile)
|
||||
const exactSessionId = await findLatestExactSessionIdWithProfile(detail.task.id, profile)
|
||||
if (exactSessionId) {
|
||||
const sessionDetail = await getExactSessionDetailFromDbWithProfile(exactSessionId, profile)
|
||||
if (sessionDetail) {
|
||||
;(detail as any).session = {
|
||||
id: sessionId,
|
||||
id: exactSessionId,
|
||||
title: sessionDetail.title,
|
||||
source: sessionDetail.source,
|
||||
model: sessionDetail.model,
|
||||
@@ -49,6 +53,23 @@ export async function get(ctx: Context) {
|
||||
messages: sessionDetail.messages,
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const results = await searchSessionSummariesWithProfile(detail.task.id, profile, undefined, 5)
|
||||
if (results.length > 0) {
|
||||
const sessionId = results[0].id
|
||||
const sessionDetail = await getSessionDetailFromDbWithProfile(sessionId, profile)
|
||||
if (sessionDetail) {
|
||||
;(detail as any).session = {
|
||||
id: sessionId,
|
||||
title: sessionDetail.title,
|
||||
source: sessionDetail.source,
|
||||
model: sessionDetail.model,
|
||||
started_at: sessionDetail.started_at,
|
||||
ended_at: sessionDetail.ended_at,
|
||||
messages: sessionDetail.messages,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
// Session lookup is best-effort, don't fail the whole request
|
||||
@@ -215,6 +236,42 @@ export async function searchSessions(ctx: Context) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
if (!q) {
|
||||
const exactSessionId = await findLatestExactSessionIdWithProfile(task_id, profile)
|
||||
if (exactSessionId) {
|
||||
const sessionDetail = await getExactSessionDetailFromDbWithProfile(exactSessionId, profile)
|
||||
if (sessionDetail) {
|
||||
ctx.body = {
|
||||
results: [{
|
||||
id: exactSessionId,
|
||||
source: sessionDetail.source,
|
||||
title: sessionDetail.title,
|
||||
preview: sessionDetail.preview,
|
||||
model: sessionDetail.model,
|
||||
started_at: sessionDetail.started_at,
|
||||
ended_at: sessionDetail.ended_at,
|
||||
last_active: sessionDetail.last_active,
|
||||
message_count: sessionDetail.message_count,
|
||||
tool_call_count: sessionDetail.tool_call_count,
|
||||
input_tokens: sessionDetail.input_tokens,
|
||||
output_tokens: sessionDetail.output_tokens,
|
||||
cache_read_tokens: sessionDetail.cache_read_tokens,
|
||||
cache_write_tokens: sessionDetail.cache_write_tokens,
|
||||
reasoning_tokens: sessionDetail.reasoning_tokens,
|
||||
billing_provider: sessionDetail.billing_provider,
|
||||
estimated_cost_usd: sessionDetail.estimated_cost_usd,
|
||||
actual_cost_usd: sessionDetail.actual_cost_usd,
|
||||
cost_status: sessionDetail.cost_status,
|
||||
matched_message_id: null,
|
||||
snippet: sessionDetail.preview,
|
||||
rank: 0,
|
||||
}],
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const searchQuery = q || task_id
|
||||
const results = await searchSessionSummariesWithProfile(searchQuery, profile, undefined, 10)
|
||||
ctx.body = { results }
|
||||
|
||||
Reference in New Issue
Block a user