@tomflow/chatloop-extension 0.3.78 → 0.3.79
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.
|
@@ -179,7 +179,9 @@ async function run(){
|
|
|
179
179
|
const evidence=await chrome.tabs.sendMessage(existing.id,
|
|
180
180
|
{type:repair?'CHAT_LOOP_REPAIR_EVIDENCE_V1':'CHAT_LOOP_APPROVAL_EVIDENCE_V1',
|
|
181
181
|
...(taken.explicitChatId
|
|
182
|
-
?{explicitChatId:taken.explicitChatId}:{})
|
|
182
|
+
?{explicitChatId:taken.explicitChatId}:{}),
|
|
183
|
+
...(taken.expectedTaskId
|
|
184
|
+
?{expectedTaskId:taken.expectedTaskId}:{})}).catch(()=>null);
|
|
183
185
|
if(evidence?.contract!=='chat-loop.turn-observer.v1'
|
|
184
186
|
||evidence.status!=='VERIFIED'||evidence.page!==taken.page
|
|
185
187
|
||evidence.userKey!==taken.userKey
|
package/extension/background.js
CHANGED
|
@@ -200,7 +200,7 @@ async function resourceChatGate(message,sender) {
|
|
|
200
200
|
return {status:'DENIED',code:'RESOURCE_CHAT_LIMIT'};
|
|
201
201
|
return {status:'OK',code:'RESOURCE_CHAT_REGISTERED'};
|
|
202
202
|
}
|
|
203
|
-
async function approvedAdoptionTarget(chatUrl=null){
|
|
203
|
+
async function approvedAdoptionTarget(chatUrl=null,taskId=null){
|
|
204
204
|
const requestedId=chatUrl?chatIdOf(chatUrl):null;
|
|
205
205
|
let tabs=await chrome.tabs.query({url:"https://chatgpt.com/*"});
|
|
206
206
|
// App and desktop users keep their exact conversation ID. When Chrome
|
|
@@ -227,7 +227,8 @@ async function approvedAdoptionTarget(chatUrl=null){
|
|
|
227
227
|
}
|
|
228
228
|
const proof=await chrome.tabs.sendMessage(opened.id,
|
|
229
229
|
{type:"CHAT_LOOP_APPROVAL_EVIDENCE_V1",
|
|
230
|
-
explicitChatId:requestedId
|
|
230
|
+
explicitChatId:requestedId,
|
|
231
|
+
...(taskId?{expectedTaskId:taskId}:{})}).catch(()=>null);
|
|
231
232
|
if(proof?.contract==="chat-loop.turn-observer.v1"
|
|
232
233
|
&&proof.status==="VERIFIED"
|
|
233
234
|
&&chatIdOf('https://chatgpt.com'+proof.page)===requestedId){
|
|
@@ -244,9 +245,14 @@ async function approvedAdoptionTarget(chatUrl=null){
|
|
|
244
245
|
const page=pathOf(tab.url);
|
|
245
246
|
if(!page||!Number.isSafeInteger(tab.id)
|
|
246
247
|
||(requestedId && chatIdOf(tab.url)!==requestedId))continue;
|
|
248
|
+
// No chatUrl means the caller does not authorize opening any Chat.
|
|
249
|
+
// For the approved Task only, inspect each ALREADY OPEN tab by its own
|
|
250
|
+
// immutable Chat ID and require exact native R/P issue-scoped user Turns.
|
|
251
|
+
const scopedId=requestedId||taskId&&chatIdOf(tab.url);
|
|
247
252
|
const proof=await chrome.tabs.sendMessage(tab.id,
|
|
248
253
|
{type:"CHAT_LOOP_APPROVAL_EVIDENCE_V1",
|
|
249
|
-
...(
|
|
254
|
+
...(scopedId?{explicitChatId:scopedId}:{}),
|
|
255
|
+
...(!requestedId&&taskId?{expectedTaskId:taskId}:{})}).catch(()=>null);
|
|
250
256
|
if(proof?.contract!=="chat-loop.turn-observer.v1"
|
|
251
257
|
||proof.status!=="VERIFIED"||proof.page!==page
|
|
252
258
|
||typeof proof.userKey!=="string"||!/^user:[^\s]{8,}$/.test(proof.userKey)
|
|
@@ -255,7 +261,8 @@ async function approvedAdoptionTarget(chatUrl=null){
|
|
|
255
261
|
continue;
|
|
256
262
|
matched.push({tabId:tab.id,page,userKey:proof.userKey,
|
|
257
263
|
priorAssistantKey:proof.priorAssistantKey||null,
|
|
258
|
-
rVersion:proof.rVersion,pVersion:proof.pVersion
|
|
264
|
+
rVersion:proof.rVersion,pVersion:proof.pVersion,
|
|
265
|
+
...(!requestedId&&taskId?{explicitChatId:scopedId,expectedTaskId:taskId}:{})});
|
|
259
266
|
}
|
|
260
267
|
if(matched.length!==1)return {error:matched.length
|
|
261
268
|
?"ADOPTION_APPROVAL_AMBIGUOUS":"ADOPTION_APPROVAL_NOT_FOUND"};
|
|
@@ -263,7 +270,9 @@ async function approvedAdoptionTarget(chatUrl=null){
|
|
|
263
270
|
await new Promise(resolve=>setTimeout(resolve,400));
|
|
264
271
|
const second=await chrome.tabs.sendMessage(target.tabId,
|
|
265
272
|
{type:"CHAT_LOOP_APPROVAL_EVIDENCE_V1",
|
|
266
|
-
...(requestedId
|
|
273
|
+
...((requestedId||target.explicitChatId)
|
|
274
|
+
?{explicitChatId:requestedId||target.explicitChatId}:{}),
|
|
275
|
+
...(target.expectedTaskId?{expectedTaskId:target.expectedTaskId}:{})}).catch(()=>null);
|
|
267
276
|
if(second?.status!=="VERIFIED"
|
|
268
277
|
||second.page!==target.page||second.userKey!==target.userKey
|
|
269
278
|
||second.rVersion!==target.rVersion||second.pVersion!==target.pVersion
|
|
@@ -379,7 +388,8 @@ async function sessionStartPrepare(message,sender){
|
|
|
379
388
|
const adoption=intent.mode==='adopt'
|
|
380
389
|
?intent.purpose==='REPAIR_SAME_SCOPE'
|
|
381
390
|
?await approvedRepairTarget(prior,intent)
|
|
382
|
-
:await approvedAdoptionTarget(intent.chatUrl||null
|
|
391
|
+
:await approvedAdoptionTarget(intent.chatUrl||null,
|
|
392
|
+
intent.contextLeaseRef?intent.taskId:null):null;
|
|
383
393
|
if(adoption?.error)return {status:'DENIED',code:adoption.error};
|
|
384
394
|
// A Project-scoped Chat cannot safely hand off to the ordinary home route:
|
|
385
395
|
// reject BEFORE claiming Owner instead of failing after four hours.
|
|
@@ -407,7 +417,10 @@ async function sessionStartPrepare(message,sender){
|
|
|
407
417
|
...(matchingBlocked?{replacedBlockedSessionId:replace}:{}),
|
|
408
418
|
...(adoption?{mode:'adopt',adoptTabId:adoption.target.tabId,
|
|
409
419
|
adoptPage:adoption.target.page,adoptUserKey:adoption.target.userKey,
|
|
410
|
-
...(intent.chatUrl
|
|
420
|
+
...((intent.chatUrl||adoption.target.explicitChatId)
|
|
421
|
+
?{adoptExplicitChatId:chatIdOf(intent.chatUrl)||adoption.target.explicitChatId}:{}),
|
|
422
|
+
...(adoption.target.expectedTaskId
|
|
423
|
+
?{adoptExpectedTaskId:adoption.target.expectedTaskId}:{}),
|
|
411
424
|
adoptPriorAssistantKey:adoption.target.priorAssistantKey,
|
|
412
425
|
...(intent.purpose==='REPAIR_SAME_SCOPE'?{}:{
|
|
413
426
|
adoptRVersion:adoption.target.rVersion,
|
|
@@ -446,6 +459,7 @@ async function sessionStartTake(message,sender){
|
|
|
446
459
|
...(run.mode==='adopt'?{mode:'adopt',tabId:run.adoptTabId,
|
|
447
460
|
page:run.adoptPage,userKey:run.adoptUserKey,
|
|
448
461
|
...(run.adoptExplicitChatId?{explicitChatId:run.adoptExplicitChatId}:{}),
|
|
462
|
+
...(run.adoptExpectedTaskId?{expectedTaskId:run.adoptExpectedTaskId}:{}),
|
|
449
463
|
priorAssistantKey:run.adoptPriorAssistantKey,
|
|
450
464
|
...(run.purpose==='REPAIR_SAME_SCOPE'
|
|
451
465
|
?{purpose:'REPAIR_SAME_SCOPE',repairUserText:run.repairUserText,
|
|
@@ -477,7 +491,9 @@ async function sessionStartResult(message,sender){
|
|
|
477
491
|
const proof=await chrome.tabs.sendMessage(run.adoptTabId,
|
|
478
492
|
{type:repair?'CHAT_LOOP_REPAIR_EVIDENCE_V1':'CHAT_LOOP_APPROVAL_EVIDENCE_V1',
|
|
479
493
|
...(run.adoptExplicitChatId
|
|
480
|
-
?{explicitChatId:run.adoptExplicitChatId}:{})
|
|
494
|
+
?{explicitChatId:run.adoptExplicitChatId}:{}),
|
|
495
|
+
...(run.adoptExpectedTaskId
|
|
496
|
+
?{expectedTaskId:run.adoptExpectedTaskId}:{})}).catch(()=>null);
|
|
481
497
|
confirmed=proof?.contract==='chat-loop.turn-observer.v1'
|
|
482
498
|
&&proof.status==='VERIFIED'&&proof.page===run.adoptPage
|
|
483
499
|
&&proof.userKey===run.adoptUserKey
|
|
@@ -513,6 +529,7 @@ async function sessionStartResult(message,sender){
|
|
|
513
529
|
delete next.adoptPage;
|
|
514
530
|
delete next.adoptUserKey;
|
|
515
531
|
delete next.adoptExplicitChatId;
|
|
532
|
+
delete next.adoptExpectedTaskId;
|
|
516
533
|
delete next.adoptPriorAssistantKey;
|
|
517
534
|
delete next.adoptRVersion;
|
|
518
535
|
delete next.adoptPVersion;
|
|
@@ -614,6 +614,23 @@
|
|
|
614
614
|
||rIndex>0&&rAssistant?.role!=="assistant"){
|
|
615
615
|
fail("APPROVAL_REQUIREMENTS_MISSING");return false;
|
|
616
616
|
}
|
|
617
|
+
if(message.expectedTaskId!==undefined){
|
|
618
|
+
// A no-URL idle adoption is only eligible for its exact Managed
|
|
619
|
+
// Task's TWO native issued approval messages in the same DOM Chat.
|
|
620
|
+
// No standalone historical affirmations or copied Task summaries.
|
|
621
|
+
const task=message.expectedTaskId;
|
|
622
|
+
const nativeIssue=(row,type)=>typeof task==="string"
|
|
623
|
+
&&/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,127}$/.test(task)
|
|
624
|
+
&&textOf(row).startsWith(task+"|")
|
|
625
|
+
&&new RegExp("^"+type+"[1-9][0-9]*-ISSUE:"
|
|
626
|
+
+"[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}[||]\\s*我确认\\s+"
|
|
627
|
+
+type+"[1-9][0-9]*\\s+v[1-9][0-9]*","i")
|
|
628
|
+
.test(textOf(row).slice(task.length+1));
|
|
629
|
+
if(!nativeRVersion||!nativeIssue(rUser,"R")
|
|
630
|
+
||!nativeIssue(pUser,"P")){
|
|
631
|
+
fail("APPROVAL_TASK_SCOPE_MISMATCH");return false;
|
|
632
|
+
}
|
|
633
|
+
}
|
|
617
634
|
// Only document-level TEST_ONLY markers deny production adoption:
|
|
618
635
|
// normal P plans can legitimately mention test-only scenarios.
|
|
619
636
|
const testOnlyReview=x=>
|
|
@@ -679,7 +696,20 @@
|
|
|
679
696
|
const explicitChatId=typeof message.explicitChatId==="string"
|
|
680
697
|
? message.explicitChatId.toLowerCase():null;
|
|
681
698
|
const currentId=path.match(/\/c\/([0-9a-f-]{12,})$/i)?.[1].toLowerCase();
|
|
682
|
-
|
|
699
|
+
// The managed lease may scope an idle, already-open Chat by the exact
|
|
700
|
+
// Task ID in BOTH real native R/P approval turns. No task scope from
|
|
701
|
+
// copied Context prose or generic unscoped historical confirmations.
|
|
702
|
+
const issueTask=x=>textOf(x).match(
|
|
703
|
+
/^([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}[||]/i)?.[1]||null;
|
|
704
|
+
const taskScoped=typeof message.expectedTaskId==="string"
|
|
705
|
+
&&message.expectedTaskId.length>=8
|
|
706
|
+
&&issueTask(rUser)===message.expectedTaskId
|
|
707
|
+
&&issueTask(pUser)===message.expectedTaskId;
|
|
708
|
+
if(message.expectedTaskId!==undefined&&!taskScoped){
|
|
709
|
+
fail("APPROVAL_TASK_SCOPE_MISMATCH");return false;
|
|
710
|
+
}
|
|
711
|
+
const scopedIdle=Boolean(
|
|
712
|
+
(explicitChatId&&explicitChatId===currentId||taskScoped)
|
|
683
713
|
&&!snap.stop&&!snap.busy&&snap.assistantKey
|
|
684
714
|
&&snap.composerReady&&snap.copyAction&&snap.text
|
|
685
715
|
&&!snap.pendingConfirmation);
|
package/extension/manifest.json
CHANGED