MVP 0.94
This commit is contained in:
1 parent
f17b3083e8
commit
4f37991ad1
48 files changed
+4919
-540
No files matched your search
@@ -1,7 +1,8 @@
|
||||
"""Journal-adapter editorial policy. Not a general provenance or privacy rule.
|
||||
|
||||
Fact fidelity is not wording fidelity. Editorial mode is chosen locally, without
|
||||
a second model call. Historical texts are style references, never today's facts.
|
||||
Fact fidelity is not wording fidelity. Mixed prose, notes and fragments in the
|
||||
same day are the normal case and are handled in one generate call. Historical
|
||||
texts are style references, never today's facts.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
@@ -18,29 +19,11 @@ from writing_profile_store import (
|
||||
list_style_sources,
|
||||
)
|
||||
|
||||
PROSE_EDIT = "prose_edit"
|
||||
NOTES_TO_JOURNAL = "notes_to_journal"
|
||||
EDITORIAL_MODES = (PROSE_EDIT, NOTES_TO_JOURNAL)
|
||||
|
||||
STYLE_EXAMPLE_MAX = 2
|
||||
STYLE_EXAMPLE_CHARS = 900
|
||||
MIN_EXAMPLE_CHARS = 40
|
||||
|
||||
INSTRUCTIONS = {
|
||||
PROSE_EDIT: (
|
||||
"Modus prose_edit: Der Rohtext ist bereits erzählerisch. "
|
||||
"Gute Formulierungen bewahren. Rechtschreibung, Grammatik und Zeichensetzung "
|
||||
"korrigieren. Holprige Stellen glätten, Wiederholungen reduzieren, Absätze und "
|
||||
"Übergänge verbessern. Die persönliche Schreibstimme anwenden. "
|
||||
"Keine unnötige vollständige Neufassung erzwingen."
|
||||
),
|
||||
NOTES_TO_JOURNAL: (
|
||||
"Modus notes_to_journal: Die Quellen sind Stichpunkte, Kurztexte oder Fragmente. "
|
||||
"Daraus zusammenhängende Journalprosa bilden. Nur sprachlich nötige Verbindungen "
|
||||
"herstellen. Keine neuen Tatsachen, Ursachen oder Bewertungen ergänzen. "
|
||||
"Die Stichpunkte nicht inklusive ihrer Fehler hintereinanderkopieren."
|
||||
),
|
||||
}
|
||||
GENERATE_SEED_REVISION = "2026-08-27-journal-mixed-sources-v1"
|
||||
|
||||
EMPTY_STYLE_EXAMPLES = (
|
||||
"Keine historischen Stilbeispiele. Es gilt nur WRITING_PROFILE "
|
||||
@@ -48,26 +31,6 @@ EMPTY_STYLE_EXAMPLES = (
|
||||
)
|
||||
|
||||
|
||||
def choose_editorial_mode(user_bodies: list[str]) -> str:
|
||||
"""MVP mode choice. No classifier model.
|
||||
|
||||
A source block counts as already narrative when it contains `.`, `!` or `?`.
|
||||
Mixed default: `prose_edit` when at least half of the non-empty blocks are
|
||||
narrative; otherwise `notes_to_journal`.
|
||||
"""
|
||||
blocks = [(item or "").strip() for item in user_bodies if (item or "").strip()]
|
||||
if not blocks:
|
||||
return NOTES_TO_JOURNAL
|
||||
narrative = sum(1 for block in blocks if any(mark in block for mark in ".!?"))
|
||||
if narrative * 2 >= len(blocks):
|
||||
return PROSE_EDIT
|
||||
return NOTES_TO_JOURNAL
|
||||
|
||||
|
||||
def editorial_instructions(mode: str) -> str:
|
||||
return INSTRUCTIONS.get(mode) or INSTRUCTIONS[PROSE_EDIT]
|
||||
|
||||
|
||||
def lexical_similarity(left: str, right: str) -> float:
|
||||
"""Diagnostic only. Must not reject a draft or trigger a retry."""
|
||||
a = re.sub(r"\s+", " ", (left or "").strip().lower())
|
||||
@@ -77,6 +40,85 @@ def lexical_similarity(left: str, right: str) -> float:
|
||||
return round(SequenceMatcher(None, a, b).ratio(), 3)
|
||||
|
||||
|
||||
_DANGLING_DETERMINER = re.compile(
|
||||
r"(?i)\b(?:der|die|das|des|dem|den|ein|eine|einem|einen|einer)\s*$"
|
||||
)
|
||||
_DETERMINER_BEFORE_FINITE = re.compile(
|
||||
r"(?i)\b(?:des|dem|den|der|die|das|ein|eine|einem|einen|einer)\s+"
|
||||
r"(?:kann|können|konnte|muss|müssen|will|wollen|soll|sollen|"
|
||||
r"ist|sind|war|waren|wird|werden|hat|haben|hatte|"
|
||||
r"geht|gehen|ging|kam|kommen|kommt|gelangen|gelangte)\b"
|
||||
)
|
||||
|
||||
|
||||
def incomplete_syntax_markers(text: str) -> int:
|
||||
"""Diagnostic count of dangling determiners or unpunctuated long clauses.
|
||||
|
||||
Does not rewrite text and must not trigger a retry.
|
||||
"""
|
||||
body = (text or "").strip()
|
||||
if not body:
|
||||
return 0
|
||||
count = 0
|
||||
clauses = [part.strip() for part in re.split(r"(?<=[.!?])\s+|\n+", body) if part.strip()]
|
||||
for clause in clauses:
|
||||
bare = clause.rstrip(".!?…\"»'")
|
||||
if _DANGLING_DETERMINER.search(bare):
|
||||
count += 1
|
||||
if _DETERMINER_BEFORE_FINITE.search(clause):
|
||||
count += 1
|
||||
for para in re.split(r"\n\s*\n", body):
|
||||
chunk = para.strip()
|
||||
if len(chunk.split()) >= 8 and not re.search(r"[.!?]", chunk):
|
||||
count += 1
|
||||
return count
|
||||
|
||||
|
||||
def style_example_diagnostics(examples: list[dict]) -> dict:
|
||||
return {
|
||||
"count": len(examples or []),
|
||||
"kinds": [item.get("kind") or "style" for item in (examples or [])],
|
||||
"chars": sum(len(item.get("excerpt") or "") for item in (examples or [])),
|
||||
}
|
||||
|
||||
|
||||
def writing_profile_trace(profile_id: str) -> dict:
|
||||
"""Presence metadata only. No profile text, no labels."""
|
||||
from writing_profile_store import (
|
||||
NEUTRAL_JOURNAL_STYLE,
|
||||
compile_task_brief,
|
||||
get_profile,
|
||||
has_confirmed_profile,
|
||||
)
|
||||
|
||||
confirmed = has_confirmed_profile(profile_id)
|
||||
profile = get_profile(profile_id)
|
||||
core = ((profile.get("core") or {}).get("value") or "").strip()
|
||||
facet = next(
|
||||
(
|
||||
item
|
||||
for item in profile.get("facets") or []
|
||||
if item.get("facet_key") == "autobiographical_journal" and (item.get("value") or "").strip()
|
||||
),
|
||||
None,
|
||||
)
|
||||
traits = [
|
||||
item
|
||||
for item in profile.get("traits") or []
|
||||
if item.get("status") == "active" and (item.get("statement") or "").strip()
|
||||
]
|
||||
brief = compile_task_brief(profile_id, "journal_generate")
|
||||
return {
|
||||
"confirmed": confirmed,
|
||||
"present": bool(confirmed and brief and brief != NEUTRAL_JOURNAL_STYLE),
|
||||
"neutral_fallback": brief == NEUTRAL_JOURNAL_STYLE,
|
||||
"has_core": bool(confirmed and core),
|
||||
"has_facet": bool(confirmed and facet),
|
||||
"trait_count": len(traits) if confirmed else 0,
|
||||
"brief_chars": len(brief or ""),
|
||||
}
|
||||
|
||||
|
||||
def narration_sources_text(artifact: dict) -> str:
|
||||
"""Present attested day facts to the model. Not a wording template, not JSON."""
|
||||
parts: list[str] = []
|
||||
|
||||
Reference in new issue
Block a user