mirror of
https://github.com/hansjone/oclaw.git
synced 2026-10-15 22:03:15 +08:00
Keep scheduled-job replies complete instead of truncating mid-summary.
Drop the hard WhatsApp body cap and tighten playbook prompts so final answers stay concise but finished. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
8419df2187
commit
2aff012b48
2 changed files with 21 additions and 8 deletions
|
|
@ -23,18 +23,14 @@ def format_scheduled_success_summary(
|
||||||
reply_text: str = "",
|
reply_text: str = "",
|
||||||
attachment_count: int = 0,
|
attachment_count: int = 0,
|
||||||
lang: str = "en",
|
lang: str = "en",
|
||||||
max_body_chars: int = 1200,
|
|
||||||
) -> str:
|
) -> str:
|
||||||
"""Short user-facing success notice; keeps body but caps length for WhatsApp."""
|
"""User-facing success notice; keeps the model reply intact (no hard truncate)."""
|
||||||
name = str(job_name or "").strip() or str(job_id or "").strip() or "scheduled job"
|
name = str(job_name or "").strip() or str(job_id or "").strip() or "scheduled job"
|
||||||
body = str(reply_text or "").strip()
|
body = str(reply_text or "").strip()
|
||||||
# Drop pure reminder fallbacks that just echo the job prompt.
|
# Drop pure reminder fallbacks that just echo the job prompt.
|
||||||
if body.startswith("⏰"):
|
if body.startswith("⏰"):
|
||||||
body = ""
|
body = ""
|
||||||
att_n = max(0, int(attachment_count or 0))
|
att_n = max(0, int(attachment_count or 0))
|
||||||
cap = max(200, int(max_body_chars or 1200))
|
|
||||||
if body and len(body) > cap:
|
|
||||||
body = body[: cap - 3].rstrip() + "..."
|
|
||||||
if str(lang or "").lower().startswith("zh"):
|
if str(lang or "").lower().startswith("zh"):
|
||||||
head = f"[定时任务完成] {name}"
|
head = f"[定时任务完成] {name}"
|
||||||
if att_n:
|
if att_n:
|
||||||
|
|
@ -183,15 +179,19 @@ def scheduled_turn_system_suffix(*, lang: str, playbook: bool = False) -> str:
|
||||||
"\n\n[Scheduled playbook mode] You are executing a recurring workflow for the user. "
|
"\n\n[Scheduled playbook mode] You are executing a recurring workflow for the user. "
|
||||||
"Follow the playbook steps, use tools as needed, and deliver a useful update "
|
"Follow the playbook steps, use tools as needed, and deliver a useful update "
|
||||||
"(including save_deliverable_attachment for generated files). "
|
"(including save_deliverable_attachment for generated files). "
|
||||||
"Lead the final reply with a short English summary (3–8 lines: what ran, key counts, "
|
"Final reply must be concise and complete: lead with conclusions "
|
||||||
"ok/failed highlights), then optional detail. "
|
"(what ran, key counts, ok/failed highlights, top issues), then only the detail "
|
||||||
|
"needed to act—no raw dumps, no unfinished sentences. Prefer a short full answer "
|
||||||
|
"over a long partial one. "
|
||||||
"For multi-NE CLI, prefer one execManagedNe(ne_ids|ume_ne_ids=..., commands=...) batch. "
|
"For multi-NE CLI, prefer one execManagedNe(ne_ids|ume_ne_ids=..., commands=...) batch. "
|
||||||
"Do not pretend the user just messaged you."
|
"Do not pretend the user just messaged you."
|
||||||
)
|
)
|
||||||
return (
|
return (
|
||||||
"\n\n【定时工作流模式】你正在执行周期性工作流。"
|
"\n\n【定时工作流模式】你正在执行周期性工作流。"
|
||||||
"按 playbook 步骤完成任务,按需调用工具;若生成文件须 save_deliverable_attachment。"
|
"按 playbook 步骤完成任务,按需调用工具;若生成文件须 save_deliverable_attachment。"
|
||||||
"最终回复先给 3–8 行摘要(做了什么、关键计数、成败),再写细节。"
|
"最终回复须简明且写完:先给结论(做了什么、关键计数、成败、主要问题),"
|
||||||
|
"再只保留可行动的细节;不要堆原始数据,不要半截句子。"
|
||||||
|
"宁可短而完整,也不要长而截断感。"
|
||||||
"多台 CLI 优先一次 execManagedNe(ne_ids|ume_ne_ids=..., commands=...) 批量并发。"
|
"多台 CLI 优先一次 execManagedNe(ne_ids|ume_ne_ids=..., commands=...) 批量并发。"
|
||||||
"不要假装用户刚刚发了消息,不要只回一句空提醒。"
|
"不要假装用户刚刚发了消息,不要只回一句空提醒。"
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,19 @@ class ScheduledFailureTextTests(unittest.TestCase):
|
||||||
self.assertIn("Attachments: 1", text)
|
self.assertIn("Attachments: 1", text)
|
||||||
self.assertIn("Critical: 3", text)
|
self.assertIn("Critical: 3", text)
|
||||||
|
|
||||||
|
def test_success_summary_keeps_long_body_intact(self) -> None:
|
||||||
|
long_body = "Result: scanned.\n" + "\n".join(
|
||||||
|
f"- NE-{i} send 0.99{i % 10} (detail line for cluster {i})" for i in range(80)
|
||||||
|
)
|
||||||
|
text = format_scheduled_success_summary(
|
||||||
|
job_name="Hourly Bandwidth Congestion",
|
||||||
|
reply_text=long_body,
|
||||||
|
lang="en",
|
||||||
|
)
|
||||||
|
self.assertGreater(len(long_body), 1200)
|
||||||
|
self.assertIn(long_body, text)
|
||||||
|
self.assertTrue(text.endswith(long_body.splitlines()[-1]))
|
||||||
|
|
||||||
def test_reminder_fallback_english(self) -> None:
|
def test_reminder_fallback_english(self) -> None:
|
||||||
self.assertIn("Reminder", format_scheduled_user_reminder("stretch", lang="en"))
|
self.assertIn("Reminder", format_scheduled_user_reminder("stretch", lang="en"))
|
||||||
self.assertIn("提醒", format_scheduled_user_reminder("活动一下", lang="zh"))
|
self.assertIn("提醒", format_scheduled_user_reminder("活动一下", lang="zh"))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue