Skip to content

Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.

fix(gateway): classify harness side requests and loop nudges (#6327)

t0sakic267ca48c58e
diff --git a/openviking_gateway/client-rules.json b/openviking_gateway/client-rules.json
index df671a77b..6fe263d6c 100644
--- a/openviking_gateway/client-rules.json
+++ b/openviking_gateway/client-rules.json
@@ -19,7 +19,9 @@
"environment_context",
"environment_details",
"skills_instructions",
- "available_skills"
+ "available_skills",
+ "subagent_notification",
+ "turn-context"
],
"auxiliary_patterns": [
"Please provide a detailed summary of the conversation",
@@ -28,11 +30,129 @@
"Generate a concise.{0,40}title",
"Create a short.{0,40}title",
"You are a permission classifier",
- "Generate the session title from"
+ "Generate the session title from",
+ "CRITICAL: Respond with TEXT ONLY. Do NOT call any tools",
+ "You are naming a coding session so the user can pick it out",
+ "SUGGESTION MODE: Suggest what the user might naturally type next",
+ "The user stepped away and is coming back. Recap in under",
+ "captures the main topic of this conversation. Use lowercase words separated by hyphens",
+ "You are now acting as the memory extraction subagent",
+ "You are performing a dream .{1,3}a reflective pass over your memory files",
+ "most recent action in 3-5 words using present tense",
+ "You write a 3-5 word progress label for a background agent",
+ "You are selecting memories that will be useful to Claude Code",
+ "You run a web search for another Claude model",
+ "You are (evaluating a.{0,30}hook|verifying a stop condition) in Claude Code",
+ "Write a brief catch-up for a user returning to this task",
+ "You output ONLY a thread title",
+ "User messages, oldest to newest:",
+ "Output exactly the Markdown structure shown inside <template>",
+ "The summary that you construct will be used so that another agent can read it and continue the work",
+ "Generate a short 2-3 word name that describes this task",
+ "Generate a commit message for the following changes:\n\nBranch:",
+ "Draft prompt to enhance, not answer:",
+ "You are summarizing a planning session to hand off to an implementation session",
+ "You are now acting as a compaction engine for this AI coding assistant",
+ "]\n\nPENDING_ACTION\n\n{",
+ "The messages above are (a conversation to summarize|NEW conversation messages to incorporate|earlier context from an ongoing conversation)",
+ "This is the PREFIX of a turn that was too large to keep",
+ "Create a structured summary of this conversation branch for context when returning later",
+ "You are now given a task to compact this conversation context",
+ "This message is a direct task, not part of the above conversation",
+ "Summarize this session for continuation. Be concise and factual",
+ "Has a short title .50-72 characters",
+ "Generate an enhanced version of this prompt .reply with only the enhanced prompt",
+ "summary of our conversation so far, capturing the key context, decisions made, and current state",
+ "Create a comprehensive summary of this conversation that captures all essential information",
+ "reply with a title for the chat that is 3-4 words in length, all words used",
+ "The user has requested a section of code in a file to be rewritten",
+ "Their cursor is located at the ..BLANK",
+ "You are a HOLE FILLER. You are provided with a file containing holes",
+ "Briefly. summarize this partial conversation about programming",
+ "^# (USER|ASSISTANT)\n",
+ "one-line Git commit messages based on the provided diffs",
+ "# Diffs:\n(diff --git|Added )",
+ "Generate a short title for the above messages",
+ "Please summarize the conversation history provided in the system prompt",
+ "Summarize this (tool call|sequence of tool calls) in a short lowercase phrase",
+ "Tool call sequence:\nStep 1: ",
+ "^Tool: .{1,200}\nArguments: ",
+ "UNTRUSTED TOOL REQUEST DATA",
+ "Generate a unique name .lowercase with hyphens, not in existing apps",
+ "Implement the requested changes and return:\n1. Updated description",
+ "Subagent ID: .{1,80}\n\n",
+ "You name chat sessions. Given the",
+ "You are a summarization agent creating a (context checkpoint|compact record)",
+ "Respond with exactly one word: APPROVE, DENY, or ESCALATE",
+ "Is the goal satisfied.{1,40}done, blocked, continue, or wait",
+ "Is the goal AND every additional criterion satisfied",
+ "management tools. Other tools will be denied at runtime",
+ "background skill CURATOR. This is an UMBRELLA-BUILDING consolidation pass",
+ "You are a focused subagent working on a specific delegated task",
+ "Fully describe and explain everything about this image, then answer the following question",
+ "Concisely describe this image in 2-4 sentences .~200 Chinese characters",
+ "Describe everything visible in this image in thorough detail. Include any text, code, UI",
+ "You are analyzing a screenshot of a web browser.\n\nUser",
+ "conversationLabelSource",
+ "Pre-compaction memory flush. Store durable memories only in",
+ "Follow the heartbeat monitor scratch context when provided",
+ "Run the following periodic tasks .only those due based on their intervals.",
+ "An async command (you ran earlier has completed|completion event was triggered)",
+ "A scheduled (reminder has been triggered|cron event was triggered)",
+ "A new session was started via /new or /reset",
+ "Background skill review. The conversation excerpt above",
+ "Subagent Context] (You are running as a subagent|Your prior run ended while waiting for descendant|Every (subagent|child) in this batch)",
+ "Continue the OpenClaw runtime event",
+ "UNTRUSTED_(EXEC|WIDGET)_REQUEST_JSON_BEGIN",
+ "generate a short 1-2 word filename slug",
+ "Recent activity .oldest first.:",
+ "Generate 1-3 broad tags categorizing the main themes of the chat history",
+ "Suggest 3-5 relevant follow-up questions or prompts.{0,40}that the user might naturally",
+ "Predict 3-5 useful messages this user might naturally send",
+ "Analyze the chat history to determine the necessity of generating search queries",
+ "Generate a detailed prompt for .{1,3} image generation task based on the given language and context",
+ "You are an autocompletion system. Continue the text in",
+ "Summarize the conversation history that will be compacted out of the active chat context",
+ "Review the completed conversation turn and decide whether long-term memory should change",
+ "\"role\":\"(user|assistant)\",\"mainText\":\"",
+ "Write a continuation summary that will allow you .or another instance of yourself.",
+ "Your only task is to translate text enclosed with <translate_input>",
+ "identify the language used in the user.{1,2}s input text",
+ "^follow system prompt$",
+ "This is a periodic heartbeat. The instructions below are from your heartbeat.md file",
+ "You are an AI question rephraser. Your role is to rephrase follow-up queries",
+ "Extract relevant facts and preferences ABOUT THE USER from this conversation",
+ "Below is the current content of my memory which I have collected till now"
],
"noise_patterns": [
"\\A\\s*Attached image\\(s\\) from tool result:\\s*\\Z",
"\\A\\s*Current runtime context\\. This snapshot supersedes earlier runtime-context snapshots\\.[\\s\\S]*",
- "\\A\\s*Time sampled while preparing turn \\d+, step \\d+: [\\s\\S]*"
+ "\\A\\s*Time sampled while preparing turn \\d+, step \\d+: [\\s\\S]*",
+ "<codex_internal_context source=\"(?:goal|daemon_recovery)\">[\\s\\S]*?</codex_internal_context>",
+ "\\A\\s*(?:The previous request exceeded the provider's size limit[\\s\\S]*?)?Continue if you have next steps, or stop and ask for clarification if you are unsure how to proceed\\.\\s*\\Z",
+ "\\A\\s*Summarize the task tool output above and continue with your task\\.\\s*\\Z",
+ "\\A\\s*CRITICAL - MAXIMUM STEPS REACHED[\\s\\S]*",
+ "\\A\\s*\\[TASK RESUMPTION\\] Resume the interrupted task using the existing conversation\\.[\\s\\S]*",
+ "\\A\\s*<notification id=\"[^\"]*\" category=\"[^\"]*\"[\\s\\S]*?</notification>\\s*\\Z",
+ "\\A\\s*Continue working toward the active goal\\.\\s+Keep the self-audit brief\\.[\\s\\S]*",
+ "\\A\\s*The previous goal turn reached the per-turn step limit[\\s\\S]*",
+ "\\A\\s*Previous turn ended unexpectedly\\. Continue from where you left off\\.\\s*\\Z",
+ "\\A\\s*Your previous response was cut off because it reached the model's output-token limit before finishing\\.[\\s\\S]*",
+ "\\A\\s*\\[SYSTEM\\] (?:This run is not complete until you call one of these terminal completion tools|You still have team obligations\\.)[\\s\\S]*",
+ "\\[ERROR\\] You did not use a tool in your previous response! Please retry with a tool use\\.[\\s\\S]*?\\(This is an automated message, so do not respond to it conversationally\\.\\)",
+ "\\A\\s*Before finishing, check whether the following goal has been fully met:[\\s\\S]*",
+ "\\A\\s*Keep working\\. The grind goal is not yet complete:[\\s\\S]*",
+ "\\A\\s*Stop hook `[^`]{1,80}` blocked ending this turn:[\\s\\S]*",
+ "\\A\\s*You MUST call the `final_output` tool NOW[^\\n]*\\s*\\Z",
+ "\\A\\s*\\[System: [^\\]]*\\]\\s*\\Z",
+ "\\A\\s*\\[IMPORTANT: Background process [\\s\\S]*",
+ "\\A\\s*\\[Continuing toward your standing goal\\][\\s\\S]*",
+ "\\A\\s*You just executed tool calls but returned an empty response\\.[\\s\\S]*",
+ "\\A\\s*Your previous turn indicated a tool call but none was included\\.[\\s\\S]*",
+ "\\A\\s*\\[ASYNC DELEGATION[\\s\\S]*",
+ "\\A\\s*A background (?:subagent|fan-out of \\d+ subagent\\(s\\)) you dispatched earlier has finished\\.[\\s\\S]*",
+ "\\A\\s*\\[Your active task list was preserved across context compression\\][\\s\\S]*",
+ "\\A\\s*You've reached the maximum number of tool-calling iterations allowed\\.[\\s\\S]*",
+ "\\A\\s*\\[ASYNC SUBAGENT COMPLETE - [\\s\\S]*"
]
}
diff --git a/tests/gateway/test_kernel.py b/tests/gateway/test_kernel.py
index 88a8d39f3..0ee8a5418 100644
--- a/tests/gateway/test_kernel.py
+++ b/tests/gateway/test_kernel.py
@@ -682,6 +682,465 @@ def test_client_rules_add_to_and_remove_from_the_packaged_rules(client_rules):
assert protocols.AUXILIARY_PATTERNS == AUXILIARY_PATTERNS
+# Side requests that harnesses send with no header to mark them, each by text the harness
+# always writes (cut short here), sent as the only user message with no system prompt.
+HARNESS_SIDE_REQUESTS = {
+ "claude-code-compact": (
+ "CRITICAL: Respond with TEXT ONLY. Do NOT call any tools.\n\n- Do NOT use Read\n\nYour "
+ "task is to create a detailed summary of the RECENT portion"
+ ),
+ "claude-code-suggestion": (
+ "[SUGGESTION MODE: Suggest what the user might naturally type next into Claude Code.]\n\n"
+ "FIRST: Look"
+ ),
+ "claude-code-away": (
+ "The user stepped away and is coming back. Recap in under 40 words, 1-2 plain sentences"
+ ),
+ "claude-code-rename": (
+ "Generate a short kebab-case name (2-4 words) that captures the main topic of this "
+ "conversation. Use lowercase words separated by hyphens. Examples"
+ ),
+ "claude-code-extract": (
+ "You are now acting as the memory extraction subagent. Analyze the most recent ~12 "
+ "messages above"
+ ),
+ "claude-code-dream": (
+ "# Dream: Memory Consolidation\n\nYou are performing a dream — a reflective pass over your "
+ "memory files. Synthesize"
+ ),
+ "claude-code-agent-summary": (
+ "Describe your most recent action in 3-5 words using present tense (-ing). Name the file"
+ ),
+ "codex-recap": (
+ "Write a brief catch-up for a user returning to this task. Return JSON with summary and "
+ "nullable next_action.\n\nConversation:\n..."
+ ),
+ "kilo-code-title": (
+ "Generate a title for this conversation:\n\nTitle the task...\n\nUser messages, oldest to "
+ "newest:\n1. fix bug"
+ ),
+ "opencode-compaction": (
+ "Here is the conversation so far:\n\n<conversation>\n[User]: hi\n</conversation>\n\nCreate "
+ "a new anchored summary...\n\nOutput exactly the Markdown structure shown inside "
+ "<template> and keep"
+ ),
+ "opencode-legacy-compaction": (
+ "Provide a detailed prompt for continuing our conversation above.\nFocus on...\nThe "
+ "summary that you construct will be used so that another agent can read it and continue "
+ "the work."
+ ),
+ "opencode-project-copy": "Generate a short 2-3 word name that describes this task:\nfix login",
+ "kilo-code-commit": (
+ "Generate a commit message for the following changes:\n\nBranch: main\nRecent commits:"
+ ),
+ "kilo-code-enhance": "Draft prompt to enhance, not answer:\n\nfix the thing",
+ "kilo-code-handover": (
+ "You are summarizing a planning session to hand off to an implementation session.\n\nThe "
+ "plan"
+ ),
+ "deepseek-harness-compact": (
+ "You are now acting as a compaction engine for this AI coding assistant. Condense"
+ ),
+ "deepseek-harness-review": (
+ 'ENVIRONMENT\n\n{\n "cwd": "/x"\n}\n\nPROJECT_INSTRUCTIONS\n\n[]\n\nFILTERED_HISTORY\n\n'
+ '[\n {"a": 1}\n]\n\nPENDING_ACTION\n\n{\n "tool": "bash"\n}'
+ ),
+ "pi-compaction": (
+ "<conversation>\n[User]: hi\n</conversation>\n\nThe messages above are a conversation to "
+ "summarize. Create a structured context checkpoint"
+ ),
+ "pi-update": (
+ "<previous-summary>x</previous-summary>\n\nThe messages above are NEW conversation "
+ "messages to incorporate into the existing summary"
+ ),
+ "pi-prefix": (
+ "# Conversation\n...\n\n# Instructions\nThe messages above are earlier context from an "
+ "ongoing conversation. Later"
+ ),
+ "pi-turn-prefix": (
+ "This is the PREFIX of a turn that was too large to keep. The SUFFIX (recent work) is "
+ "retained.\n\nSummarize the prefix to provide context for the retained suffix:"
+ ),
+ "pi-branch": (
+ "<conversation>\n..\n</conversation>\n\nCreate a structured summary of this conversation "
+ "branch for context when returning later."
+ ),
+ "kimi-cli-compact": (
+ "## Message 1\nRole: user\n...\nThe above is a list of messages in an agent conversation. "
+ "You are now given a task to compact this conversation context according to specific "
+ "priorities"
+ ),
+ "kimi-code-compact": (
+ "You are about to run out of context. Create a handoff summary for the\nmodel that will "
+ "resume this task.\n\n--- This message is a direct task, not part of the above "
+ "conversation ---"
+ ),
+ "cline-compact": (
+ "Summarize this session for continuation. Be concise and factual.\n\n## Goal\nOne sentence"
+ ),
+ "cline-commit": (
+ "Based on the provided git diff, generate a concise and descriptive commit message.\n\nThe "
+ "commit message should:\n1. Has a short title (50-72 characters)\n2. The"
+ ),
+ "roo-code-enhance": (
+ "Generate an enhanced version of this prompt (reply with only the enhanced prompt - no "
+ "conversation, explanations"
+ ),
+ "continue-cli-compact": (
+ "Please provide a concise summary of our conversation so far, capturing the key context, "
+ "decisions made, and current state. Format"
+ ),
+ "continue-ide-compact": (
+ "Create a comprehensive summary of this conversation that captures all essential "
+ "information needed to continue"
+ ),
+ "continue-title": (
+ "Given the following... please reply with a title for the chat that is 3-4 words in "
+ "length, all words used should be"
+ ),
+ "continue-rewrite": (
+ "The user has requested a section of code in a file to be rewritten.\n\nThis is the prefix "
+ "of the file:\n```\nimport os\n```"
+ ),
+ "continue-edit": (
+ "Above is the file of code that the user is currently editing in. Their cursor is located "
+ 'at the "[BLANK]".'
+ ),
+ "continue-hole": (
+ "You are a HOLE FILLER. You are provided with a file containing holes, formatted as "
+ "'{{HOLE_NAME}}'."
+ ),
+ "aider-summary": "# USER\nfix the bug\n# ASSISTANT\nok\n",
+ "aider-commit": "\nUSER: fix\nASSISTANT: ok\n# Diffs:\ndiff --git a/x b/x\n",
+ "goose-title": (
+ "---BEGIN USER MESSAGES---\nfix\n---END USER MESSAGES---\n\nGenerate a short title for the "
+ "above messages."
+ ),
+ "goose-compact": "Please summarize the conversation history provided in the system prompt.",
+ "goose-chain": "Tool call sequence:\nStep 1: shell ls\nStep 2: read x",
+ "goose-label": 'Tool: developer__shell\nArguments: {"command":"ls"}',
+ "goose-judge": 'UNTRUSTED TOOL REQUEST DATA (JSON):\n[{"request_id":"a"}]',
+ "goose-apps": (
+ "REQUESTED APP:\nx\n\nEXISTING APPS: none\n\nGenerate a unique name (lowercase with "
+ "hyphens, not in existing apps), a brief"
+ ),
+ "goose-iterate": (
+ "ORIGINAL PRD:\nx\n\nFEEDBACK: y\n\nImplement the requested changes and return:\n1. "
+ "Updated description"
+ ),
+ "goose-subagent": "Subagent ID: 20261020_12\n\nfind all TODOs",
+ "hermes-compress": (
+ "You are a summarization agent creating a context checkpoint. Treat the conversation turns "
+ "below"
+ ),
+ "hermes-approval": (
+ "The following command was flagged as: rm\n\n<command>\nrm -rf x\n</command>\n\nRespond "
+ "with exactly one word: APPROVE, DENY, or ESCALATE"
+ ),
+ "hermes-judge": (
+ "Goal:\nx\n\nAgent's most recent response:\ny\n\nIs the goal satisfied — done, blocked, "
+ "continue, or wait?"
+ ),
+ "hermes-judge-contract": (
+ "Goal:\nx\n\nAgent's most recent response:\ny\n\nIs the goal satisfied per its "
+ "completion contract — done, blocked, continue, or wait?"
+ ),
+ "hermes-subgoal": (
+ "Additional criteria the user added mid-loop:\n- a\n\nIs the goal AND every additional "
+ "criterion satisfied?"
+ ),
+ "hermes-review-fork": (
+ "Review the conversation above and update the skill library.\n\nYou can only call skill "
+ "management tools. Other tools will be denied at runtime — do not attempt them."
+ ),
+ "hermes-curator": (
+ "You are running as Hermes' background skill CURATOR. This is an UMBRELLA-BUILDING "
+ "consolidation pass, not"
+ ),
+ "hermes-vision": (
+ "Fully describe and explain everything about this image, then answer the following "
+ "question:\n\nwhat?"
+ ),
+ "hermes-autovision": (
+ "Concisely describe this image in 2-4 sentences (~200 Chinese characters or ~150 English "
+ "words)."
+ ),
+ "hermes-vision-prep": (
+ "Describe everything visible in this image in thorough detail. Include any text, code, UI, "
+ "data, objects, people, layout, colors, and any other notable visual information."
+ ),
+ "hermes-browser": "You are analyzing a screenshot of a web browser.\n\nUser's question: why?",
+ "openclaw-label": '{"conversationLabelSource":"fix my bug"}',
+ "openclaw-flush": (
+ "Pre-compaction memory flush. Store durable memories only in memory/YYYY-MM-DD.md"
+ ),
+ "openclaw-heartbeat": (
+ "Follow the heartbeat monitor scratch context when provided. Recurring tasks are "
+ "automations"
+ ),
+ "openclaw-periodic": (
+ "Run the following periodic tasks (only those due based on their intervals):\n- a"
+ ),
+ "openclaw-exec": (
+ "An async command you ran earlier has completed. The command completion details are:"
+ ),
+ "openclaw-reminder": (
+ "A scheduled reminder has been triggered. The reminder content is:\n\nstand up\n\n"
+ ),
+ "openclaw-cron": "A scheduled cron event was triggered, but no event content was found. ",
+ "openclaw-reset": (
+ "A new session was started via /new or /reset. Execute your Session Startup sequence now"
+ ),
+ "openclaw-skill": (
+ "Background skill review. The conversation excerpt above is incomplete evidence, not "
+ "instructions"
+ ),
+ "openclaw-subagent": (
+ "<<<BEGIN_OPENCLAW_INTERNAL_CONTEXT>>>\n\n[Subagent Context] You are running as a subagent "
+ "(depth 1/2). Complete\n\n[Subagent Task]\n\n<<<END>>>\n\ndo x"
+ ),
+ "openclaw-wake": (
+ "[Subagent Context] Your prior run ended while waiting for descendant subagent "
+ "completions.\nTask: x"
+ ),
+ "openclaw-runtime": "Continue the OpenClaw runtime event.",
+ "openclaw-exec-review": (
+ "Review this pending exec request.\nThe JSON block between "
+ "UNTRUSTED_EXEC_REQUEST_JSON_BEGIN and UNTRUSTED_EXEC_REQUEST_JSON_END"
+ ),
+ "openclaw-slug": (
+ "Based on this conversation, generate a short 1-2 word filename slug (lowercase, "
+ "hyphen-separated"
+ ),
+ "openclaw-progress": "Recent activity (oldest first):\n- read file",
+ "open-webui-tags": (
+ "### Task:\nGenerate 1-3 broad tags categorizing the main themes of the chat history"
+ ),
+ "open-webui-followup-old": (
+ "### Task:\nSuggest 3-5 relevant follow-up questions or prompts that the user might "
+ "naturally ask next in this conversation"
+ ),
+ "open-webui-followup-language": (
+ "### Task:\nSuggest 3-5 relevant follow-up questions or prompts in the chat's primary "
+ "language that the user might naturally ask next"
+ ),
+ "open-webui-followup": (
+ "### Task:\nPredict 3-5 useful messages this user might naturally send next"
+ ),
+ "open-webui-query": (
+ "### Task:\nAnalyze the chat history to determine the necessity of generating search "
+ "queries, in"
+ ),
+ "open-webui-image": (
+ "### Task:\nGenerate a detailed prompt for am image generation task based on the given "
+ "language and context."
+ ),
+ "open-webui-autocomplete": (
+ "### Task:\nYou are an autocompletion system. Continue the text in `<text>`"
+ ),
+ "open-webui-compaction": (
+ "### Task:\nSummarize the conversation history that will be compacted out of the active "
+ "chat context."
+ ),
+ "open-webui-memory": (
+ "Review the completed conversation turn and decide whether long-term memory should "
+ "change.\n\nMemory types:"
+ ),
+ "cherry-studio-title": (
+ '[{"role":"user","mainText":"hi","files":[]},{"role":"assistant","mainText":"hello"}]'
+ ),
+ "cherry-studio-compact": (
+ "You have been working on the task described above but have not yet completed it. Write a "
+ "continuation summary that will allow you (or another instance of yourself) to resume"
+ ),
+ "cherry-studio-translate": (
+ "You are a translation expert. Your only task is to translate text enclosed with "
+ "<translate_input> from"
+ ),
+ "cherry-studio-detect": "follow system prompt",
+ "cherry-studio-heartbeat": (
+ "[Heartbeat]\nThis is a periodic heartbeat. The instructions below are from your "
+ "heartbeat.md file."
+ ),
+ "cherry-studio-v1-rephrase": (
+ " You are an AI question rephraser. Your role is to rephrase follow-up queries from a "
+ "conversation"
+ ),
+ "cherry-studio-v1-memory": (
+ "Following is a conversation between the user and the assistant. Extract relevant facts "
+ "and preferences ABOUT THE USER from this conversation.\nConversation:"
+ ),
+ "cherry-studio-v1-update": (
+ "Below is the current content of my memory which I have collected till now. You have to "
+ "update it"
+ ),
+}
+# Side requests known only by their system prompt, sent as Anthropic's block list.
+HARNESS_SIDE_SYSTEMS = {
+ "claude-code-title": (
+ "You are naming a coding session so the user can pick it out of a long list of sessions."
+ ),
+ "claude-code-progress-label": (
+ "You write a 3-5 word progress label for a background agent, from short notes"
+ ),
+ "claude-code-memdir": (
+ "You are selecting memories that will be useful to Claude Code as it processes a user's "
+ "query."
+ ),
+ "claude-code-websearch": (
+ "You run a web search for another Claude model, which is waiting on the result"
+ ),
+ "claude-code-hook": (
+ "You are evaluating a stop-condition hook in Claude Code. Read the conversation"
+ ),
+ "claude-code-hook2": (
+ "You are evaluating a hook in Claude Code. The user's text says what to check."
+ ),
+ "claude-code-agent-hook": "You are verifying a stop condition in Claude Code. Your task is",
+ "opencode-title": "You are a title generator. You output ONLY a thread title. Nothing else.",
+ "aider-summarize": (
+ "*Briefly* summarize this partial conversation about programming.\nInclude less detail"
+ ),
+ "aider-commit": (
+ "You are an expert software engineer that generates concise, one-line Git commit messages "
+ "based on the provided diffs.\nReview"
+ ),
+ "goose-labels": (
+ "Summarize this tool call in a short lowercase phrase (3-8 words). No punctuation."
+ ),
+ "hermes-title": "You name chat sessions. Given the user's opening message, write a title",
+ "hermes-subagent": "You are a focused subagent working on a specific delegated task.",
+ "cherry-studio-detect": (
+ "Your task is to precisely identify the language used in the user's input text and output "
+ 'its "code"'
+ ),
+}
+
+
[email protected]("text", HARNESS_SIDE_REQUESTS.values(), ids=HARNESS_SIDE_REQUESTS)
+def test_harness_side_requests_are_auxiliary(text):
+ assert classify({}, {}, [{"role": "user", "content": text}])[0] == "auxiliary"
+
+
[email protected]("system", HARNESS_SIDE_SYSTEMS.values(), ids=HARNESS_SIDE_SYSTEMS)
+def test_harness_side_request_systems_are_auxiliary(system):
+ body = {"system": [{"type": "text", "text": system}]}
+ assert classify(body, {}, [{"role": "user", "content": "fix the bug"}])[0] == "auxiliary"
+
+
+ "text",
+ [
+ "fix the login bug",
+ "Generate a title for my blog post",
+ "Create a new anchored summary component for my React app",
+ "I'm about to run out of context. Create a handoff summary for the next engineer.",
+ "Have you read a Claude Code user guide?",
+ "Generate a short kebab-case name for this feature branch",
+ "Generate a detailed prompt for an image generation task: a cat in space",
+ "Implement the requested changes and return: a summary",
+ "Summarize this session for continuation",
+ "follow system prompt and then fix the bug",
+ "what does PENDING_ACTION mean in our enum",
+ "# User guide\nThis is how to use it",
+ "Subagent ID: foo",
+ "Please do a reflective pass over your memory files and remove stale entries",
+ "Generate 1-3 broad tags categorizing the main themes of this blog post",
+ "Suggest 3-5 relevant follow-up questions or prompts for my onboarding survey",
+ "Label each ticket as done, blocked, continue, or wait",
+ ],
+)
+def test_user_prompts_near_side_request_text_stay_user(text):
+ message = {"role": "user", "content": text}
+ assert classify({}, {}, [message])[0] == "user"
+ body = {"system": [{"type": "text", "text": "You are a coding agent."}]}
+ assert classify(body, {}, [message])[0] == "user"
+
+
+# Messages harnesses add to a running tool loop; the loop goes on from the user's prompt.
+HARNESS_NUDGES = [
+ '<codex_internal_context source="goal">\nContinue working toward the active thread goal.\n'
+ "</codex_internal_context>",
+ '<subagent_notification>{"agent_path":"a","status":"done"}</subagent_notification>',
+ "Continue if you have next steps, or stop and ask for clarification if you are unsure how to "
+ "proceed.",
+ "The previous request exceeded the provider's size limit due to large media attachments. The "
+ "conversation was compacted.\n\nContinue if you have next steps, or stop and ask for "
+ "clarification if you are unsure how to proceed.",
+ "Summarize the task tool output above and continue with your task.",
+ "CRITICAL - MAXIMUM STEPS REACHED\n\nThe maximum number of steps allowed for this task has "
+ "been reached.",
+ "[TASK RESUMPTION] Resume the interrupted task using the existing conversation. Check the "
+ "current state",
+ '<notification id="n1" category="task" type="done" source_kind="background_task" '
+ 'source_id="b">\nTitle: x\n</notification>',
+ "Continue working toward the active goal. Keep the self-audit brief. Do not explore",
+ "The previous goal turn reached the per-turn step limit before finishing its work",
+ "Previous turn ended unexpectedly. Continue from where you left off.",
+ "Your previous response was cut off because it reached the model's output-token limit before "
+ "finishing. Keep responses concise",
+ "[SYSTEM] This run is not complete until you call one of these terminal completion tools: "
+ "submit_and_exit.",
+ "[SYSTEM] You still have team obligations. 2 tasks are open. Do NOT stop until all tasks are "
+ "completed.",
+ "[ERROR] You did not use a tool in your previous response! Please retry with a tool use.\n\n# "
+ "Reminder\n...\n(This is an automated message, so do not respond to it conversationally.)\n"
+ "<environment_details>\nx\n</environment_details>",
+ "Before finishing, check whether the following goal has been fully met:\n\n**Goal:** x\n\nIf "
+ "not, continue working toward it.",
+ "Keep working. The grind goal is not yet complete:\n\n**Goal:** x\n\nContinue until it is "
+ "fully done.",
+ "Stop hook `lint` blocked ending this turn:\n\nreason\n\nAddress this policy hook denial "
+ "before trying to stop again.",
+ "You MUST call the `final_output` tool NOW with the final output for the user.",
+ "[System: Continue now. Execute the required tool calls and only send your final answer after "
+ "completing the task.]",
+ "[IMPORTANT: Background process proc_1 finished with exit 0]",
+ "[Continuing toward your standing goal]\nGoal: x\n\nContinue working toward this goal.",
+ "You just executed tool calls but returned an empty response. Please process the tool results "
+ "above and continue with the task.",
+ "Your previous turn indicated a tool call but none was included. Do not narrate a plan or "
+ "restate intent — issue the actual tool call now to continue the task.",
+ "[ASYNC DELEGATION BATCH COMPLETE — deleg_current]\nThe newest result that must remain "
+ "actionable.",
+ "A background fan-out of 3 subagent(s) you dispatched earlier has finished.\n...",
+ "[Your active task list was preserved across context compression]\n- item",
+ "You've reached the maximum number of tool-calling iterations allowed. Please provide a final "
+ "response",
+ "[ASYNC SUBAGENT COMPLETE - d1]\nA background subagent you dispatched earlier has finished.",
+ "<turn-context>\n<current-time>2026-01-01T00:00:00Z</current-time>\n</turn-context>",
+]
+
+
[email protected]("text", HARNESS_NUDGES)
+def test_harness_nudges_continue_the_turn(text):
+ turn = [
+ {"role": "user", "content": "fix the login bug"},
+ {"role": "assistant", "content": "working on it"},
+ {"role": "user", "content": text},
+ ]
+ assert classify({}, {}, turn) == ("continuation", 0)
+
+
+ "text",
+ [
+ "[System: model changed]\n\nfix a[0] in parser.py [see line 3]",
+ "Continue working toward the active goal. Also add tests",
+ "Continue if you have next steps",
+ "<notification>hi</notification> please",
+ "fix bug\n<turn-context>\n<current-time>x</current-time>\n</turn-context>",
+ ],
+)
+def test_prompts_like_harness_nudges_stay_user(text):
+ turn = [
+ {"role": "user", "content": "fix the login bug"},
+ {"role": "assistant", "content": "working on it"},
+ {"role": "user", "content": text},
+ ]
+ assert classify({}, {}, turn) == ("user", 2)
+
+
OV_NAMES = ["read", "ls", "glob", "find", "search", "add_resource"]