@@ -219,7 +219,7 @@ describe("buildInboundMetaSystemPrompt", () => {
219219 expect ( payload [ "flags" ] ) . toBeUndefined ( ) ;
220220 } ) ;
221221
222- it ( "keeps explicit bot mentions out of the system metadata" , ( ) => {
222+ it ( "keeps bot usernames out of the system metadata and includes standing mention guidance " , ( ) => {
223223 const prompt = buildInboundMetaSystemPrompt (
224224 {
225225 OriginatingTo : "telegram:-1001249586642" ,
@@ -236,7 +236,9 @@ describe("buildInboundMetaSystemPrompt", () => {
236236 const payload = parseInboundMetaPayload ( prompt ) ;
237237 expect ( payload [ "flags" ] ) . toBeUndefined ( ) ;
238238 expect ( prompt ) . not . toContain ( "SirPinchALotBot" ) ;
239- expect ( prompt ) . not . toContain ( "explicitly mentions your channel identity" ) ;
239+ expect ( prompt ) . toContain (
240+ "When explicitly_mentioned_bot is true, the incoming message mentions your channel identity; treat it as addressed to you even if your persona name differs." ,
241+ ) ;
240242 } ) ;
241243
242244 it ( "omits sender_id when blank" , ( ) => {
@@ -605,7 +607,7 @@ describe("buildInboundUserContextPrefix", () => {
605607 } as TemplateContext ) ;
606608
607609 expect ( text ) . toContain ( "Conversation info (untrusted metadata):" ) ;
608- expect ( text ) . toContain ( '"conversation_label": "ops-room"' ) ;
610+ expect ( text ) . toContain ( '"conversation_label":"ops-room"' ) ;
609611 } ) ;
610612
611613 it ( "renders group subject and participants as untrusted metadata" , ( ) => {
@@ -779,52 +781,58 @@ describe("buildInboundUserContextPrefix", () => {
779781 } ) ;
780782
781783 it ( "renders hydrated reply chain instead of duplicate one-hop reply target" , ( ) => {
782- const text = buildInboundUserContextPrefix ( {
783- ReplyToSender : "Blair" ,
784- ReplyToBody : "The cache warmer is the piece I meant." ,
785- ReplyChain : [
786- {
787- messageId : "3001" ,
788- sender : "Blair" ,
789- senderId : "700002" ,
790- timestamp : 1778216405000 ,
791- body : "The cache warmer is the piece I meant." ,
792- replyToId : "3000" ,
793- } ,
794- {
795- messageId : "3000" ,
796- sender : "Avery" ,
797- senderId : "700001" ,
798- timestamp : 1778216400000 ,
799- body : "Architecture sketch for the cache warmer" ,
800- mediaType : "image" ,
801- mediaRef : "telegram:file/proof-photo-small" ,
802- } ,
803- ] ,
804- } as TemplateContext ) ;
784+ const text = buildInboundUserContextPrefix (
785+ {
786+ ReplyToSender : "Blair" ,
787+ ReplyToBody : "The cache warmer is the piece I meant." ,
788+ ReplyChain : [
789+ {
790+ messageId : "3001" ,
791+ sender : "Blair" ,
792+ senderId : "700002" ,
793+ timestamp : 1778216405000 ,
794+ body : "The cache warmer is the piece I meant." ,
795+ replyToId : "3000" ,
796+ forwardedFrom : "Morgan" ,
797+ forwardedDate : 1778212800000 ,
798+ } ,
799+ {
800+ messageId : "3000" ,
801+ sender : "Avery" ,
802+ senderId : "700001" ,
803+ timestamp : 1778216400000 ,
804+ body : "Architecture sketch for the cache warmer" ,
805+ mediaType : "image" ,
806+ mediaRef : "telegram:file/proof-photo-small" ,
807+ } ,
808+ ] ,
809+ } as TemplateContext ,
810+ { timezone : "UTC" } ,
811+ ) ;
805812
806813 const replyChain = parseReplyChainPayload ( text ) ;
807814 expect ( replyChain ) . toEqual ( [
808815 {
809816 message_id : "3001" ,
810817 sender : "Blair" ,
811818 sender_id : "700002" ,
812- timestamp_ms : 1778216405000 ,
819+ timestamp : "2026-05-08T05:00:05Z" ,
813820 body : "The cache warmer is the piece I meant." ,
814821 reply_to_id : "3000" ,
822+ forwarded_from : "Morgan" ,
823+ forwarded_date : "2026-05-08T04:00:00Z" ,
815824 } ,
816825 {
817826 message_id : "3000" ,
818827 sender : "Avery" ,
819828 sender_id : "700001" ,
820- timestamp_ms : 1778216400000 ,
829+ timestamp : "2026-05-08T05:00:00Z" ,
821830 body : "Architecture sketch for the cache warmer" ,
822831 media_type : "image" ,
823832 media_ref : "telegram:file/proof-photo-small" ,
824833 } ,
825834 ] ) ;
826835 expect ( text ) . not . toContain ( "Reply target of current user message" ) ;
827- expect ( parseConversationInfoPayload ( text ) [ "has_reply_context" ] ) . toBe ( true ) ;
828836 } ) ;
829837
830838 it ( "renders Telegram replies as an inline current-message quote" , ( ) => {
@@ -940,6 +948,29 @@ describe("buildInboundUserContextPrefix", () => {
940948 expect ( conversationInfo [ "sender" ] ) . toEqual ( { e164 : "+15551234567" } ) ;
941949 } ) ;
942950
951+ it ( "omits e164 when it repeats the sender id digits" , ( ) => {
952+ const text = buildInboundUserContextPrefix ( {
953+ ChatType : "group" ,
954+ SenderId : "15551234567" ,
955+ SenderE164 : "+1 (555) 123-4567" ,
956+ } as TemplateContext ) ;
957+
958+ expect ( parseConversationInfoPayload ( text ) [ "sender" ] ) . toEqual ( { id : "15551234567" } ) ;
959+ } ) ;
960+
961+ it ( "keeps e164 when it differs from the sender id digits" , ( ) => {
962+ const text = buildInboundUserContextPrefix ( {
963+ ChatType : "group" ,
964+ SenderId : "15550001111" ,
965+ SenderE164 : "+15551234567" ,
966+ } as TemplateContext ) ;
967+
968+ expect ( parseConversationInfoPayload ( text ) [ "sender" ] ) . toEqual ( {
969+ id : "15550001111" ,
970+ e164 : "+15551234567" ,
971+ } ) ;
972+ } ) ;
973+
943974 it ( "includes dynamic per-turn flags in conversation info" , ( ) => {
944975 const text = buildInboundUserContextPrefix ( {
945976 ChatType : "group" ,
@@ -965,9 +996,6 @@ describe("buildInboundUserContextPrefix", () => {
965996 expect ( conversationInfo [ "mentioned_subteam_ids" ] ) . toEqual ( [ "S_ONCALL" ] ) ;
966997 expect ( conversationInfo [ "implicit_mention_kinds" ] ) . toEqual ( [ "bot_thread_participant" ] ) ;
967998 expect ( conversationInfo [ "mention_source" ] ) . toBe ( "implicit_thread" ) ;
968- expect ( conversationInfo [ "has_reply_context" ] ) . toBe ( true ) ;
969- expect ( conversationInfo [ "has_forwarded_context" ] ) . toBe ( true ) ;
970- expect ( conversationInfo [ "has_thread_starter" ] ) . toBe ( true ) ;
971999 expect ( conversationInfo [ "history_count" ] ) . toBe ( 1 ) ;
9721000 } ) ;
9731001
@@ -980,8 +1008,7 @@ describe("buildInboundUserContextPrefix", () => {
9801008
9811009 const conversationInfo = parseConversationInfoPayload ( text ) ;
9821010 expect ( conversationInfo [ "explicitly_mentioned_bot" ] ) . toBe ( true ) ;
983- expect ( text ) . toContain ( "explicitly mentions your channel identity @SirPinchALotBot" ) ;
984- expect ( text ) . toContain ( "Treat that mention as addressed to you" ) ;
1011+ expect ( text ) . not . toContain ( "SirPinchALotBot" ) ;
9851012 } ) ;
9861013
9871014 it ( "trims sender_id in conversation info" , ( ) => {
@@ -1034,11 +1061,11 @@ describe("buildInboundUserContextPrefix", () => {
10341061 } ) ;
10351062 expect ( conversationInfo [ "topic_id" ] ) . toBe ( "thread--1" ) ;
10361063
1037- expect ( text ) . toContain ( '"body": "thread starter"' ) ;
1038- expect ( text ) . toContain ( '"sender_label": "Quoter"' ) ;
1039- expect ( text ) . toContain ( '"body": "quoted body"' ) ;
1040- expect ( text ) . toContain ( '"from": "forwarder"' ) ;
1041- expect ( text ) . toContain ( '"title": "title"' ) ;
1064+ expect ( text ) . toContain ( '"body":"thread starter"' ) ;
1065+ expect ( text ) . toContain ( '"sender_label":"Quoter"' ) ;
1066+ expect ( text ) . toContain ( '"body":"quoted body"' ) ;
1067+ expect ( text ) . toContain ( '"from":"forwarder"' ) ;
1068+ expect ( text ) . toContain ( '"title":"title"' ) ;
10421069 expect ( text ) . toContain ( "history: body text" ) ;
10431070 } ) ;
10441071
@@ -1179,7 +1206,7 @@ describe("buildInboundUserContextPrefix", () => {
11791206 expect ( text ) . not . toContain ( "telegram:file/old-provider-ref" ) ;
11801207 expect ( text ) . not . toContain ( "/home/user/.openclaw/media/inbound/sticker.webp" ) ;
11811208 expect ( text ) . not . toContain ( "Current local chat window (untrusted metadata):" ) ;
1182- expect ( text ) . not . toContain ( '"message_id": "34273"' ) ;
1209+ expect ( text ) . not . toContain ( '"message_id":"34273"' ) ;
11831210 } ) ;
11841211
11851212 it ( "honors timestamp suppression for chat window structured context" , ( ) => {
@@ -1366,7 +1393,7 @@ describe("buildInboundUserContextPrefix", () => {
13661393 } as TemplateContext ) ;
13671394
13681395 expect ( withForwardedFrom ) . toContain ( "Forwarded message context (untrusted metadata):" ) ;
1369- expect ( withForwardedFrom ) . toContain ( '"from": "source"' ) ;
1396+ expect ( withForwardedFrom ) . toContain ( '"from":"source"' ) ;
13701397 } ) ;
13711398
13721399 it ( "truncates oversized untrusted strings before serializing them into prompt context" , ( ) => {
@@ -1378,7 +1405,7 @@ describe("buildInboundUserContextPrefix", () => {
13781405
13791406 expect ( text ) . not . toContain ( oversized ) ;
13801407 expect ( text ) . toContain ( "…[truncated]" ) ;
1381- expect ( text ) . toContain ( '"body": "' ) ;
1408+ expect ( text ) . toContain ( '"body":"' ) ;
13821409 } ) ;
13831410
13841411 it ( "preserves tail content in ReplyChain body via head+tail truncation" , ( ) => {
@@ -1508,9 +1535,6 @@ describe("buildInboundUserContextPrefix", () => {
15081535 ] ,
15091536 } as TemplateContext ) ;
15101537
1511- const conversationInfo = parseConversationInfoPayload ( text ) ;
1512- expect ( conversationInfo [ "history_media_count" ] ) . toBe ( 1 ) ;
1513-
15141538 expect ( text ) . toContain ( "#m-1" ) ;
15151539 expect ( text ) . toContain ( "Alice: <media:image> (1 image) [image/png]" ) ;
15161540 expect ( text ) . not . toContain ( "/tmp/openclaw-secret-image.png" ) ;
@@ -1546,9 +1570,6 @@ describe("buildInboundUserContextPrefix", () => {
15461570 ] ,
15471571 } as TemplateContext ) ;
15481572
1549- const conversationInfo = parseConversationInfoPayload ( text ) ;
1550- expect ( conversationInfo [ "history_media_count" ] ) . toBe ( 2 ) ;
1551-
15521573 expect ( text ) . toContain ( "#m-2" ) ;
15531574 expect ( text ) . toContain ( "Alice: <media:image> (2 images) [image/png, image/jpeg]" ) ;
15541575 expect ( text ) . not . toContain ( "/tmp/openclaw-secret-image-1.png" ) ;
0 commit comments