MVP 0.93 - stabile, aber Writing Profile ohne erkennbaren Nutzen
This commit is contained in:
1 parent
53b1eff833
commit
f17b3083e8
56 files changed
+5366
-784
No files matched your search
@@ -53,6 +53,11 @@ TASK_BRIEF_TRAIT_CHARS = 280
|
||||
TASK_BRIEF_EXEMPLAR_CHARS = 220
|
||||
TASK_BRIEF_MAX_TRAITS = 6
|
||||
TASK_BRIEF_MAX_EXEMPLARS = 2
|
||||
NEUTRAL_JOURNAL_STYLE = (
|
||||
"Neutraler Journalstil (kein individuelles Writing Profile): "
|
||||
"klare Ich-Form, kurze Überschrift, ruhige Übergänge, natürliche Absätze. "
|
||||
"Keine künstliche Literarisierung. Keine Stilableitung aus dem aktuellen Tagesdialog."
|
||||
)
|
||||
DIALOGUE_KIND = "dialogue_style"
|
||||
MAX_DIALOGUE_MESSAGES = 8
|
||||
MAX_DIALOGUE_CHARS = 500
|
||||
@@ -67,6 +72,7 @@ __all__ = [
|
||||
"LIFECYCLE",
|
||||
"SEED_FACETS",
|
||||
"compile_style_signals",
|
||||
"NEUTRAL_JOURNAL_STYLE",
|
||||
"get_profile",
|
||||
"import_text",
|
||||
"import_corpus",
|
||||
@@ -94,6 +100,8 @@ __all__ = [
|
||||
"seed_catalog",
|
||||
"INITIAL_BUILD_SOURCES",
|
||||
"compile_task_brief",
|
||||
"clip_field",
|
||||
"list_style_sources",
|
||||
]
|
||||
|
||||
|
||||
@@ -1015,7 +1023,7 @@ def _dedupe_brief_sources(items: list[dict], *, seen_keys: set[tuple[str, str]]
|
||||
return result
|
||||
|
||||
|
||||
def _clip_field(text: str, limit: int) -> str:
|
||||
def clip_field(text: str, limit: int) -> str:
|
||||
raw = (text or "").strip()
|
||||
if limit <= 0 or not raw:
|
||||
return ""
|
||||
@@ -1031,6 +1039,14 @@ def _clip_field(text: str, limit: int) -> str:
|
||||
return cut.rstrip(" \t\n,;:-")
|
||||
|
||||
|
||||
_clip_field = clip_field
|
||||
|
||||
|
||||
def list_style_sources(profile_id: str) -> dict[str, list[dict]]:
|
||||
"""Intent-neutral ranked style sources. Journal policy decides which to send."""
|
||||
return _load_ranked_sources(profile_id)
|
||||
|
||||
|
||||
def _norm_overlap(left: str, right: str) -> float:
|
||||
a = re.sub(r"\s+", " ", (left or "").strip().lower())
|
||||
b = re.sub(r"\s+", " ", (right or "").strip().lower())
|
||||
@@ -1171,14 +1187,19 @@ def _assemble_brief(profile_id: str) -> None:
|
||||
|
||||
|
||||
def compile_task_brief(profile_id: str, task: str = "journal_generate") -> str:
|
||||
"""Runtime brief for one task. Not an export, import, or proposal format."""
|
||||
from writing_profile_schema import is_meta_style_text
|
||||
"""Compact confirmed style brief. Historical texts are selected separately.
|
||||
|
||||
Unconfirmed profiles do not become a style authority. Journal adapters attach
|
||||
final entries as STYLE_EXAMPLES, not as extra rules in this brief.
|
||||
"""
|
||||
profile = get_profile(profile_id)
|
||||
if task != "journal_generate":
|
||||
core = (profile.get("core") or {}).get("value") or ""
|
||||
return _clip_field(core, TASK_BRIEF_MAX_CHARS)
|
||||
|
||||
if not has_confirmed_profile(profile_id):
|
||||
return NEUTRAL_JOURNAL_STYLE
|
||||
|
||||
parts: list[str] = []
|
||||
core_text = ((profile.get("core") or {}).get("value") or "").strip()
|
||||
if core_text:
|
||||
@@ -1209,41 +1230,7 @@ def compile_task_brief(profile_id: str, task: str = "journal_generate") -> str:
|
||||
continue
|
||||
parts.append(f"- {item.get('label') or item.get('slug')}: {clipped}")
|
||||
used_statements.append(statement)
|
||||
exemplars: list[tuple[float, str]] = []
|
||||
seen_ex = set()
|
||||
for item in selected:
|
||||
for ref in item.get("exemplars") or []:
|
||||
excerpt = (ref.get("excerpt") or "").strip()
|
||||
if not excerpt or is_meta_style_text(excerpt):
|
||||
continue
|
||||
digest = hashlib.sha256(re.sub(r"\s+", " ", excerpt.lower()).encode("utf-8")).hexdigest()
|
||||
if digest in seen_ex:
|
||||
continue
|
||||
seen_ex.add(digest)
|
||||
clipped = _clip_field(excerpt, TASK_BRIEF_EXEMPLAR_CHARS)
|
||||
if not clipped:
|
||||
continue
|
||||
weight = recency_weight(ref.get("occurred_at") or _trait_recency_stamp(item))
|
||||
exemplars.append((weight, clipped))
|
||||
exemplars.sort(key=lambda row: -row[0])
|
||||
chosen = []
|
||||
for _, excerpt in exemplars:
|
||||
if any(_norm_overlap(excerpt, prev) >= 0.8 for prev in chosen):
|
||||
continue
|
||||
chosen.append(excerpt)
|
||||
if len(chosen) >= TASK_BRIEF_MAX_EXEMPLARS:
|
||||
break
|
||||
if chosen:
|
||||
parts.append("Repräsentative Exemplare:")
|
||||
for excerpt in chosen:
|
||||
parts.append("- " + excerpt)
|
||||
brief = "\n".join(part for part in parts if part).strip()
|
||||
if len(brief) > TASK_BRIEF_MAX_CHARS:
|
||||
without_examples = [part for part in parts if not part.startswith("Repräsentative Exemplare") and not (
|
||||
part.startswith("- ") and chosen and any(part == "- " + excerpt for excerpt in chosen)
|
||||
)]
|
||||
brief = "\n".join(without_examples).strip()
|
||||
parts = without_examples
|
||||
while len(brief) > TASK_BRIEF_MAX_CHARS and parts:
|
||||
last = parts.pop()
|
||||
remain = TASK_BRIEF_MAX_CHARS - (len("\n".join(parts)) + (1 if parts else 0))
|
||||
@@ -1253,16 +1240,7 @@ def compile_task_brief(profile_id: str, task: str = "journal_generate") -> str:
|
||||
brief = "\n".join(parts).strip()
|
||||
break
|
||||
brief = "\n".join(parts).strip()
|
||||
if brief:
|
||||
return brief
|
||||
ranked = _load_ranked_sources(profile_id)
|
||||
snippets = (ranked.get("journal_entry") or [])[:2] + (ranked.get("imported_text") or [])[:1]
|
||||
lines = []
|
||||
for item in snippets:
|
||||
body = _clip_field(plain_text(item.get("body") or ""), 280)
|
||||
if body and not is_meta_style_text(body):
|
||||
lines.append(body)
|
||||
return "\n\n".join(lines).strip()
|
||||
return brief or NEUTRAL_JOURNAL_STYLE
|
||||
|
||||
|
||||
def has_facets(profile_id: str) -> bool:
|
||||
|
||||
Reference in new issue
Block a user