Archive summarized messages instead of deleting them

要約で長期メモリに移したメッセージをDBから物理削除していたため、
一度要約されると人間も内容を確認できなくなっていた。削除をやめ、
messages に archived_at(要約に取り込まれた時刻)と memory_id
(どの要約に取り込まれたか)を持たせる。

モデルからは従来どおり見えない:
- get_context_messages() がアーカイブ済みを除外する
- maybe_summarize() の閾値判定も現役メッセージだけを数える
  (ここを除外し忘れると件数が減らず再要約が繰り返される)
- backfill_tags() もアーカイブ済みは対象外にする

人間からは確認できる:
- GET /chat/sessions/{id}/messages がアーカイブ済みも archived_at
  付きで返す。export/import もアーカイブ状態を保持する
- チャット画面では半透明で表示し、最後のアーカイブ済みメッセージの
  直後に「ここから先がモデルに渡る」区切り線を出す

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-20 14:33:18 +09:00
co-authored by Claude Opus 5
parent be3af44891
commit 2ee7238afb
12 changed files with 101 additions and 19 deletions
+3
View File
@@ -51,6 +51,8 @@ export interface MessageRecord {
role: 'user' | 'assistant' | 'system'
content: string
created_at: string
// 要約に取り込まれたメッセージ。モデルには渡らないが履歴としては残っている
archived_at: string | null
tags: string[]
}
@@ -83,6 +85,7 @@ export interface ImportPayload {
role: string
content: string
created_at?: string | null
archived_at?: string | null
tags?: string[]
}[]
}