The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(agent): paste title hint reaches the instant title and the prompt.submit contract
teknium134ba61bf676c
diff --git a/agent/title_generator.py b/agent/title_generator.pyindex d376854d245..d58b0f7cc56 100644--- a/agent/title_generator.py+++ b/agent/title_generator.py@@ -47,6 +47,7 @@ RuntimeValidator = Callable[[], bool]# Text budget handed to the model (Claude Code / OpenClaw converged on 1000).MAX_TITLE_INPUT_CHARS = 1000_PASTE_PREVIEW_LABEL = "\n\nPasted content:\n"+_ATTACHMENT_REF_RE = re.compile(r"@(?:file|folder):\S+")# Cap on the instant derived title; a raw fragment reads worse the longer it runs.MAX_DERIVED_TITLE_CHARS = 48# Answer-shaped guard: a tiny model sometimes answers instead of titling; longer is rejected, not truncated.@@ -223,7 +224,9 @@ def build_title_input(user_message: str, title_preview: str | None = None) -> stpreview = title_preview.strip() if isinstance(title_preview, str) else ""if not preview:return message[:MAX_TITLE_INPUT_CHARS]- if not message:+ # A paste-only opener is just the generated `@file:` ref: the preview IS the topic, so it+ # leads (derive_title takes the first line, and a file path is not a title).+ if not _ATTACHMENT_REF_RE.sub("", message).strip():return preview[:MAX_TITLE_INPUT_CHARS]message_budget = min(len(message), MAX_TITLE_INPUT_CHARS // 2)preview_budget = MAX_TITLE_INPUT_CHARS - message_budget - len(_PASTE_PREVIEW_LABEL)@@ -495,12 +498,18 @@ def _persist_session_title(session_db, session_id, title, *, source, dedupe=Truereturn _set(deduped)-def apply_instant_title(session_db, session_id: str, user_message: str, title_callback: Optional[TitleCallback] = None) -> Optional[str]:- """Write the derived title inline. Returns it, or None (no usable text, or a ``derived``+ title exists). Never raises."""+def apply_instant_title(+ session_db, session_id: str, user_message: str, title_callback: Optional[TitleCallback] = None,+ title_preview: str | None = None,+) -> Optional[str]:+ """Write the derived title inline. Returns it, or None (no usable text, or a ``derived``+ title exists). Never raises.++ ``title_preview`` must reach this stage too: the model upgrade's own ``derive_title`` fallback writes+ ``derived`` provenance, which never replaces the ``derived`` title written here."""if not session_db or not session_id:return Nonetry:- title = derive_title(user_message) if is_titleable_user_message(user_message) else None+ title = derive_title(user_message, title_preview) if is_titleable_user_message(user_message) else Nonepersisted = _persist_session_title(session_db, session_id, title, source="derived", dedupe=False) if title else Noneif persisted:_notify_title(title_callback, persisted, "derived", "Instant-title")@@ -644,7 +653,7 @@ def maybe_auto_title(if not _auto_title_enabled(): # config read after the cheap guards so the file isn't touched every turnlogger.debug("Auto-title skipped: auxiliary.title_generation.enabled=false")return- apply_instant_title(session_db, session_id, user_message, title_callback)+ apply_instant_title(session_db, session_id, user_message, title_callback, title_preview=title_preview)if not _model_title_upgrade_enabled():logger.debug("Instant title persisted; model upgrade disabled by auxiliary.title_generation.model_upgrade_enabled=false")returndiff --git a/apps/shared/src/gateway-contract.generated.ts b/apps/shared/src/gateway-contract.generated.tsindex 0b077ff69fd..b02d8f7428f 100644--- a/apps/shared/src/gateway-contract.generated.ts+++ b/apps/shared/src/gateway-contract.generated.ts@@ -2134,6 +2134,7 @@ export interface PromptSubmitParams {queued?: boolean | nullsurface?: string | nullvoice_context?: string | null+ title_preview?: string | nulltruncate_before_user_ordinal?: number | nulltruncate_before_row_id?: number | nulltruncate_before_message_id?: string | nulldiff --git a/apps/shared/src/gateway-contract.openrpc.json b/apps/shared/src/gateway-contract.openrpc.jsonindex 41f58c7fda3..2ec97f8dcfe 100644--- a/apps/shared/src/gateway-contract.openrpc.json+++ b/apps/shared/src/gateway-contract.openrpc.json@@ -21891,6 +21891,18 @@"default": null,"title": "Voice Context"},+ "title_preview": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ],+ "default": null,+ "title": "Title Preview"+ },"truncate_before_user_ordinal": {"anyOf": [{diff --git a/tests/agent/test_title_generator.py b/tests/agent/test_title_generator.pyindex 8f8422cbddb..ad7bf9ca305 100644--- a/tests/agent/test_title_generator.py+++ b/tests/agent/test_title_generator.py@@ -7,6 +7,7 @@ from unittest.mock import MagicMock, patchfrom agent.title_generator import (MAX_TITLE_INPUT_CHARS,build_title_input,+ derive_title,generate_title,auto_title_session,maybe_auto_title,@@ -22,32 +23,31 @@ class TestGenerateTitle:@pytest.mark.parametrize(("instruction", "paste_preview", "expected_parts"),[- ("", "Quarterly incident analysis for the database migration", ["Quarterly incident analysis"]),+ ("@file:/tmp/composer-pastes/pasted_content_1.txt", "Quarterly incident analysis for the database migration",+ ["Quarterly incident analysis"]),("Analyze this", "Quarterly incident analysis for the database migration", ["Analyze this", "Quarterly incident analysis"]),("Prepare the deployment follow-up", "Quarterly incident analysis", ["Prepare the deployment follow-up", "Quarterly incident analysis"]),],)- def test_title_input_includes_only_generated_paste_preview(- self, instruction, paste_preview, expected_parts- ):- """Regression for #114124: a generated paste remains an attachment for the turn but informs its title."""+ def test_generated_paste_preview_reaches_the_shared_title_input(self, instruction, paste_preview, expected_parts):+ """A Desktop large paste stays an @file attachment for the turn, but its preview informs BOTH title+ paths (derive_title instant + generate_title model input) through the one shared input."""title_input = build_title_input(instruction, paste_preview)assert all(part in title_input for part in expected_parts)assert "@file:" not in title_input+ # Paste-only opener (just the generated ref): the instant title is the paste's topic, not the path.+ lead = paste_preview if instruction.startswith("@file:") else instruction+ assert derive_title(instruction, paste_preview).startswith(lead[:12])- def test_title_input_keeps_manual_attachment_and_preview_out_of_title_context(self):- title_input = build_title_input("Summarize @file:notes.txt", None)-- assert title_input == "Summarize @file:notes.txt"- assert "Pasted content:" not in title_input-- def test_title_input_budgets_instruction_and_generated_paste_preview(self):+ def test_title_input_budget_and_manual_attachments_stay_unread(self):title_input = build_title_input("Describe the release plan", "p" * MAX_TITLE_INPUT_CHARS)assert len(title_input) == MAX_TITLE_INPUT_CHARSassert title_input.startswith("Describe the release plan")assert title_input.endswith("p" * 20)+ # No preview => an ordinary manual attachment ref is never read for titling.+ assert build_title_input("Summarize @file:notes.txt", None) == "Summarize @file:notes.txt"diff --git a/tui_gateway/contracts/prompt_voice.py b/tui_gateway/contracts/prompt_voice.pyindex 5376031c506..ab24f1c8f22 100644--- a/tui_gateway/contracts/prompt_voice.py+++ b/tui_gateway/contracts/prompt_voice.py@@ -35,6 +35,8 @@ class PromptSubmitParams(SessionParams):queued: bool | None = None # client queue drain — the busy path must hold it, never redirect/steersurface: str | None = None # a ClientSurface value; unknown values clear the surfacevoice_context: str | None = None # recent spoken transcript, model input only (voice-live)+ # Desktop-generated large-paste preview (first ~1000 chars); TITLE input only, never the model turn.+ title_preview: str | None = Nonetruncate_before_user_ordinal: int | None = Nonetruncate_before_row_id: int | None = Nonetruncate_before_message_id: str | None = Nonediff --git a/website/docs/user-guide/configuration.md b/website/docs/user-guide/configuration.mdindex cd5b073aa5f..006ecf1cb31 100644--- a/website/docs/user-guide/configuration.md+++ b/website/docs/user-guide/configuration.md@@ -1371,6 +1371,12 @@ No background `auto-title` thread starts and no automatic title-model request isexplicit repair command `hermes sessions retitle-skills` still calls the model. `enabled: false`still disables both stages.+In Hermes Desktop, a plain-text paste over 3,000 characters becomes a generated `.txt`+attachment. The first ~1,000 characters of that paste are handed to the title stages as a+title-only hint (the agent turn still sees only the attachment reference), so a "summarize+this" plus a large paste is named after the pasted topic. Files you attach yourself are never+read for titling.+### Stream-only endpointsSome OpenAI-compatible endpoints reject non-streaming chat requests outright (e.g. Tencent Copilot returns HTTP 400 `"Non-stream chat request is currently not supported"`). Interactive chat already streams, but auxiliary tasks (title generation, compression, vision) use non-streaming calls and would fail on every attempt. Hermes always treats `copilot.tencent.com` as stream-only; for any other such endpoint, list a URL substring under `auxiliary.stream_only_base_urls`: