Keep journal openings from treating finished days as open plans.
A 400-character entry prefix plus plan regex could reopen a completed yesterday as if it were still pending. Openings now take plans only from yesterday's user dialogue, never from saved entries, and skip space recency in the first call. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
e42f751fdc
commit
ec0f8bad55
8 files changed
+108
-19
No files matched your search
@@ -1,12 +1,15 @@
|
||||
"""Journal-specific first impulse. Not a generic continuation or intent engine.
|
||||
|
||||
Uses the existing Privacy Gateway, dialogue prompt, guards and request-scoped
|
||||
trace. Attested plans and open day points come only from user-role sources.
|
||||
Assistant text is conversation context, never a user fact. Recency is not a pattern.
|
||||
trace. Attested plans come only from yesterday's user-role dialogue. Open day
|
||||
points stay on the same journal day. Saved journal entries are completed
|
||||
narrative, never an opening plan. Assistant text is conversation context, never
|
||||
a user fact. Recency is not a pattern.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
from datetime import date, timedelta
|
||||
|
||||
from context_builder import assemble_text, build_internal_context
|
||||
from debug_store import persist_engine_error, persist_step
|
||||
@@ -20,11 +23,14 @@ from retrieval import retrieve
|
||||
NEUTRAL_OPENING = "Wenn du magst, fang einfach an – ich höre zu."
|
||||
OPENING_POLICY = (
|
||||
"Dies ist der erste Impuls dieses Gesprächs. Es gibt hier noch keine Nutzerzeile. "
|
||||
"Nur belegte Vorhaben aus user-Quellen oder offene user-Punkte desselben Journal Day aufgreifen. "
|
||||
"Nur belegte Vorhaben aus dem user-Dialog des unmittelbar vorigen Kalendertags "
|
||||
"oder offene user-Punkte desselben Journal Day aufgreifen. "
|
||||
"Ein gespeicherter Journal-Eintrag ist abgeschlossene Erzählung, kein offenes Vorhaben. "
|
||||
"Ein Recency-Treffer ist kein bewiesenes wiederkehrendes Muster. "
|
||||
"Nicht erwähnt ist nicht geschehen. Ein Plan ist kein Vollzug. "
|
||||
"Assistententext ist Gesprächskontext, kein Nutzerfakt. "
|
||||
"Keine Behauptung, ein Vorhaben sei ausgeführt worden."
|
||||
"Keine Behauptung, ein Vorhaben sei ausgeführt worden. "
|
||||
"Keine bereits erzählte, abgeschlossene Episode eines früheren Tags als offenen Faden führen."
|
||||
)
|
||||
|
||||
FUTURE_INTENT = re.compile(
|
||||
@@ -46,6 +52,22 @@ UNEARNED_PATTERN = re.compile(
|
||||
)
|
||||
|
||||
|
||||
def parse_calendar_date(value: str | None) -> date | None:
|
||||
raw = (value or "").strip()
|
||||
if not raw:
|
||||
return None
|
||||
try:
|
||||
return date.fromisoformat(raw)
|
||||
except ValueError:
|
||||
return None
|
||||
|
||||
|
||||
def is_previous_calendar_day(source: date | None, current: date | None) -> bool:
|
||||
if source is None or current is None:
|
||||
return False
|
||||
return source == current - timedelta(days=1)
|
||||
|
||||
|
||||
def is_attested_plan(text: str) -> bool:
|
||||
"""User wording that marks a plan or intention. Not past completion, not overlap."""
|
||||
body = (text or "").strip()
|
||||
@@ -88,7 +110,8 @@ def collect_opening_context(profile_id: str, conversation_id: str) -> dict:
|
||||
journal_day_id = conversation.get("journal_day_id")
|
||||
if not space_id or not journal_day_id:
|
||||
raise StoreError("not_journal_conversation", "Erster Impuls nur für einen Journal-Dialog.")
|
||||
get_day(profile_id, journal_day_id)
|
||||
day = get_day(profile_id, journal_day_id)
|
||||
current_date = parse_calendar_date(day.get("calendar_date"))
|
||||
|
||||
day_conversations = list_conversations_for_day(profile_id, journal_day_id)
|
||||
open_points: list[str] = []
|
||||
@@ -114,6 +137,7 @@ def collect_opening_context(profile_id: str, conversation_id: str) -> dict:
|
||||
},
|
||||
)
|
||||
recency_user: list[str] = []
|
||||
yesterday_user: list[str] = []
|
||||
for entry in prior_entries:
|
||||
excerpt = (entry.get("excerpt") or "").strip()
|
||||
if excerpt:
|
||||
@@ -122,15 +146,19 @@ def collect_opening_context(profile_id: str, conversation_id: str) -> dict:
|
||||
excerpt = (source.get("excerpt") or "").strip()
|
||||
if excerpt:
|
||||
recency_user.append(excerpt)
|
||||
if excerpt and is_previous_calendar_day(
|
||||
parse_calendar_date(source.get("calendar_date")),
|
||||
current_date,
|
||||
):
|
||||
yesterday_user.append(excerpt)
|
||||
|
||||
user_pool = [*open_points, *recency_user]
|
||||
plans = attested_plans_from_user_texts(user_pool)
|
||||
plans = attested_plans_from_user_texts(yesterday_user)
|
||||
has_relevant = bool(plans or open_points)
|
||||
return {
|
||||
"space_id": space_id,
|
||||
"journal_day_id": journal_day_id,
|
||||
"conversation_id": conversation_id,
|
||||
"user_texts": user_pool,
|
||||
"user_texts": [*open_points, *yesterday_user],
|
||||
"assistant_texts": day_assistant,
|
||||
"attested_plans": plans,
|
||||
"open_day_points": open_points,
|
||||
@@ -230,13 +258,15 @@ def start_journal_opening(profile_id: str, conversation_id: str) -> dict:
|
||||
journal_day_id=conversation.get("journal_day_id"),
|
||||
purpose="dialogue_turn",
|
||||
conversation_ids=day_ids,
|
||||
include_space_recency=False,
|
||||
)
|
||||
assembled = assemble_text(context)
|
||||
assembled = dict(assembled)
|
||||
assembled["opening_hint"] = format_opening_hint(facts)
|
||||
assembled["register_hint"] = (
|
||||
"Erster Impuls. Noch keine Nutzerzeile in diesem Gespräch. "
|
||||
"Nur belegte Vorhaben oder offene user-Punkte. Kein Muster aus Recency."
|
||||
"Nur Vorhaben aus dem user-Dialog von gestern oder offene user-Punkte dieses Tags. "
|
||||
"Kein Muster aus Recency. Keine abgeschlossene frühere Episode wieder öffnen."
|
||||
)
|
||||
prompt = load_active_prompt("mvp.dialogue_turn")
|
||||
calls = 0
|
||||
|
||||
Reference in new issue
Block a user