@tomflow/chatloop-extension 0.3.76 → 0.3.78

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -522,6 +522,23 @@
522
522
  const confirms=(value,type)=>{
523
523
  const line=value.replace(/\s+/g," ").trim();
524
524
  if(!line||line.length>500)return false;
525
+ // Native R/P review controls send two explicit, task-scoped fields:
526
+ // "TASK|R2-ISSUE:<uuid>|我确认 R2 v2。..." (and likewise P2).
527
+ // Accept only a matching kind+version from a genuine user message,
528
+ // never arbitrary prose containing an approval quote or TEST_ONLY.
529
+ const native=line.match(/^([A-Z][A-Z0-9._:-]{7,120})[||]\s*([RP][1-9][0-9]*)-ISSUE:([0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12})[||]\s*我确认\s+([RP][1-9][0-9]*)\s+v([1-9][0-9]*)[。.!!]\s*(.{0,320})$/i);
530
+ if(native){
531
+ const declared=native[2].toUpperCase(),approved=native[4].toUpperCase();
532
+ if(declared[0]!==type||declared!==approved
533
+ ||Number(declared.slice(1))!==Number(native[5]))return false;
534
+ const note=native[6];
535
+ if(/TEST_ONLY|NOT_APPROVED|只是测试|仅供测试|仅为引用|复制示例|不作为.{0,15}(?:审批|批准)|此确认无效/i.test(note))return false;
536
+ if(type==="R"&&/(?:撤销|拒绝|不批准|不确认|不同意).{0,12}(?:需求|R[1-9][0-9]*)/i.test(note)
537
+ ||type==="P"&&/(?:撤销|拒绝|不批准|不确认|不同意).{0,12}(?:方案|计划|P[1-9][0-9]*)/i.test(note)
538
+ ||type==="P"&&/(?:不授权|未授权|禁止|不要|不能).{0,15}(?:Start|执行|实施|开始|启动)/i.test(note))
539
+ return false;
540
+ return true;
541
+ }
525
542
  const target=type==="R"
526
543
  ? "(?:这份|当前|本版|上述)?(?:需求(?:R[1-9][0-9]*)?|R[1-9][0-9]*)"
527
544
  : "(?:这份|当前|本版|上述)?(?:方案(?:与|及|和)?计划|实施计划|方案|计划|P[1-9][0-9]*)(?:P[1-9][0-9]*)?";
@@ -544,6 +561,15 @@
544
561
  // Prefer an explicit current-version declaration. Historical mentions
545
562
  // must not choose a version; ambiguous prose is not approval evidence.
546
563
  const versionOf=(value,type)=>{
564
+ // Real formal reviews may start with a status recap mentioning an
565
+ // older P2 before the issued heading "P3 v3|正式修订方案".
566
+ // A unique, version-consistent line title outranks historical prose.
567
+ const issued=[...value.matchAll(new RegExp("(?:^|\\n)\\s*(?:#{1,6}\\s*)?("+type+"[1-9][0-9]*)\\s+v([1-9][0-9]*)\\s*[||]", "gi"))]
568
+ .filter(x=>Number(x[1].slice(1))===Number(x[2]))
569
+ .map(x=>x[1].toUpperCase());
570
+ const issuedVersions=[...new Set(issued)];
571
+ if(issuedVersions.length===1)return issuedVersions[0];
572
+ if(issuedVersions.length>1)return null;
547
573
  const declared=[...value.matchAll(new RegExp("(?:^|\\n)\\s*(?:#{1,6}\\s*)?(?:方案版本|需求版本|当前版本|版本)?[:: ]*("+type+"[1-9][0-9]*)\\b", "gi"))].map(x=>x[1].toUpperCase());
548
574
  const current=[...value.matchAll(new RegExp("(?:本次|当前|本版)[:: ]*("+type+"[1-9][0-9]*)\\b", "gi"))].map(x=>x[1].toUpperCase());
549
575
  const versions=[...new Set(current.length?current:declared.length?declared:(value.match(new RegExp("\\b"+type+"[1-9][0-9]*\\b","gi"))||[]).map(x=>x.toUpperCase()))];
@@ -572,23 +598,35 @@
572
598
  }
573
599
  const rIndex=rows.slice(0,lastUser-1).findLastIndex(x=>x.role==="user"
574
600
  &&confirms(textOf(x),"R"));
575
- if(rIndex<1 ||rows[rIndex-1].role!=="assistant"){
601
+ // Long chats virtualize old turns. A still-mounted native R2 user
602
+ // approval at index 0 has its exact issued R2-ISSUE identity, even when
603
+ // the original R2 assistant has scrolled out of the DOM window.
604
+ // This fallback is ONLY for native issue-scoped approvals. The Native
605
+ // Context Start lease independently verifies the effective R approval.
606
+ const rUser=rIndex>=0?rows[rIndex]:null;
607
+ const nativeR=rUser&&textOf(rUser).match(/^[A-Z][A-Z0-9._:-]{7,120}[||]\s*(R[1-9][0-9]*)-ISSUE:[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}[||]\s*我确认\s+(R[1-9][0-9]*)\s+v([1-9][0-9]*)[。.!!]/i);
608
+ const nativeRVersion=nativeR
609
+ &&nativeR[1].toUpperCase()===nativeR[2].toUpperCase()
610
+ &&Number(nativeR[1].slice(1))===Number(nativeR[3])
611
+ ?nativeR[1].toUpperCase():null;
612
+ const rAssistant=rIndex>0?rows[rIndex-1]:null;
613
+ if(rIndex<0 || rIndex===0&&!nativeRVersion
614
+ ||rIndex>0&&rAssistant?.role!=="assistant"){
576
615
  fail("APPROVAL_REQUIREMENTS_MISSING");return false;
577
616
  }
578
- const rAssistant=rows[rIndex-1],rUser=rows[rIndex];
579
617
  // Only document-level TEST_ONLY markers deny production adoption:
580
618
  // normal P plans can legitimately mention test-only scenarios.
581
619
  const testOnlyReview=x=>
582
620
  /(?:^|\n)\s*(?:#{1,6}\s*|>\s*)?(?:\*\*)?TEST_ONLY(?:\*\*)?(?:\s*$|\s*[/||:]\s*NOT_APPROVED)/mi
583
621
  .test(textOf(x));
584
- if(testOnlyReview(rAssistant)||testOnlyReview(pAssistant)){
622
+ if(rAssistant&&testOnlyReview(rAssistant)||testOnlyReview(pAssistant)){
585
623
  fail("APPROVAL_TEST_ONLY");return false;
586
624
  }
587
- if(!/(?:需求|范围|验收)/.test(textOf(rAssistant))
588
- || !/\bR[1-9][0-9]*\b/i.test(textOf(rAssistant))) {
625
+ if(rAssistant&&(!/(?:需求|范围|验收)/.test(textOf(rAssistant))
626
+ || !/\bR[1-9][0-9]*\b/i.test(textOf(rAssistant)))) {
589
627
  fail("APPROVAL_REQUIREMENTS_MISSING");return false;
590
628
  }
591
- const rVersion=versionOf(textOf(rAssistant),"R");
629
+ const rVersion=rAssistant?versionOf(textOf(rAssistant),"R"):nativeRVersion;
592
630
  const intervening=rows.slice(rIndex+1,lastUser-1);
593
631
  const invalidated=intervening.some(x=>{
594
632
  const text=textOf(x);
@@ -596,8 +634,10 @@
596
634
  const next=versionOf(text,"R");
597
635
  return /需求|范围|验收/.test(text)&&next&&next!==rVersion;
598
636
  }
599
- return /(?:撤销|取消|拒绝|不同意|不批准|修改|修订|变更)/.test(text)
600
- && /需求|R[1-9][0-9]*/i.test(text);
637
+ // "修订 P3、保留 R2" is a plan update, NOT an R2 revocation.
638
+ // Only an explicit requirement-targeted change invalidates this R.
639
+ return /(?:撤销|取消|拒绝|不同意|不批准|修改|修订|变更)\s*(?:(?:当前|本次|这份|上述)\s*)?(?:需求|R[1-9][0-9]*)/i.test(text)
640
+ || /\bR[1-9][0-9]*\b\s*(?:需求)?\s*(?:需要|应当|应该)?\s*(?:撤销|取消|拒绝|修改|修订|变更)/i.test(text);
601
641
  });
602
642
  if(!pVersion||!rVersion||invalidated){
603
643
  fail("APPROVAL_REVISED_OR_REVOKED");return false;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "manifest_version": 3,
3
3
  "name": "Chat Loop Extension",
4
- "version": "0.3.76",
4
+ "version": "0.3.78",
5
5
  "description": "Chat Loop browser companion: Eye actions, Turn observer, Continue and Handoff Actions",
6
6
  "permissions": [
7
7
  "activeTab",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomflow/chatloop-extension",
3
- "version": "0.3.76",
3
+ "version": "0.3.78",
4
4
  "type": "module",
5
5
  "description": "Chat Loop Extension package: nine formal Action pages and its own native CLI bridge",
6
6
  "bin": {