feat(hub): rolling chat summary to cap AI context and prevent mid-session failures
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -165,6 +165,7 @@ def create_new_session(
|
||||
"created_at": _now_str(),
|
||||
"updated_at": _now_str(),
|
||||
"messages": [],
|
||||
"rolling_summary": "",
|
||||
}
|
||||
store.setdefault("sessions", []).append(session)
|
||||
store["active_session_id"] = session["id"]
|
||||
@@ -179,6 +180,22 @@ def ensure_active_session(*, trading_day: str) -> dict:
|
||||
return create_new_session(trading_day=trading_day)
|
||||
|
||||
|
||||
def update_session_rolling_summary(session_id: str, summary: str) -> dict:
|
||||
store = load_chat_store()
|
||||
target = None
|
||||
for s in store.get("sessions") or []:
|
||||
if str(s.get("id")) == str(session_id):
|
||||
target = s
|
||||
break
|
||||
if not target:
|
||||
raise KeyError("session_not_found")
|
||||
target["rolling_summary"] = str(summary or "").strip()
|
||||
target["updated_at"] = _now_str()
|
||||
store["active_session_id"] = target["id"]
|
||||
save_chat_store(store)
|
||||
return target
|
||||
|
||||
|
||||
def append_chat_message(
|
||||
session_id: str,
|
||||
role: str,
|
||||
|
||||
Reference in New Issue
Block a user