@tomflow/chatloop-extension 0.3.78 → 0.3.80
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.
|
@@ -230,7 +230,7 @@ async function run() {
|
|
|
230
230
|
const raw = params.get("tabId") || "";
|
|
231
231
|
let token = params.get("token") || "";
|
|
232
232
|
let tabId = Number(raw);
|
|
233
|
-
if ([...params.keys()].some(k => k !== "tabId" && k !== "token" && k !== "repairLegacyReservation" && k !== "resumeBlockedAt" && k !== "recoverContextNotSentAt")
|
|
233
|
+
if ([...params.keys()].some(k => k !== "tabId" && k !== "token" && k !== "repairLegacyReservation" && k !== "resumeBlockedAt" && k !== "recoverContextNotSentAt" && k !== "adoptBaselineAt")
|
|
234
234
|
|| [...params.keys()].length !== new Set(params.keys()).size)
|
|
235
235
|
throw Error("ACTION_PARAMETERS_INVALID");
|
|
236
236
|
if (raw && !/^[1-9][0-9]*$/.test(raw)
|
|
@@ -239,6 +239,21 @@ async function run() {
|
|
|
239
239
|
||params.has("recoverContextNotSentAt"))) throw Error("ACTION_PARAMETERS_INVALID");
|
|
240
240
|
const own = await chrome.tabs.getCurrent();
|
|
241
241
|
if (!own?.id || own.url !== location.href) throw Error("ACTION_TAB_UNVERIFIED");
|
|
242
|
+
if(params.has("adoptBaselineAt")){
|
|
243
|
+
const rawAt=params.get("adoptBaselineAt"),at=Number(rawAt);
|
|
244
|
+
if(params.size!==2||!raw||token||!/^[1-9][0-9]{12}$/.test(rawAt||"")
|
|
245
|
+
||!Number.isSafeInteger(at))
|
|
246
|
+
throw Error("ADOPT_BASELINE_PARAMETERS_INVALID");
|
|
247
|
+
show("VERIFYING","对同一原 Chat 的历史审批回复进行只读复核;绝不发送消息。");
|
|
248
|
+
const result=await chrome.runtime.sendMessage({
|
|
249
|
+
type:"CHAT_LOOP_ADOPT_BASELINE_REPAIR_V1",
|
|
250
|
+
tabId,nativeUpdatedAt:at});
|
|
251
|
+
if(result?.status!=="REPAIRED")
|
|
252
|
+
throw Error(result?.code||"ADOPT_BASELINE_REPAIR_UNVERIFIED");
|
|
253
|
+
show("SUCCESS","已对原 Chat 完成历史基线恢复;未创建 Chat、未发送消息。");
|
|
254
|
+
await chrome.tabs.remove(own.id);
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
242
257
|
if (!token) {
|
|
243
258
|
show("VERIFYING", "手动打开 Continue:核对当前已完成的 Turn,并申请单次发送许可。");
|
|
244
259
|
if(params.has("resumeBlockedAt")){
|
|
@@ -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
|
|
@@ -188,7 +190,8 @@ async function run(){
|
|
|
188
190
|
||evidence.priorDoneAssistantKey!==taken.priorDoneAssistantKey
|
|
189
191
|
: evidence.rVersion!==taken.rVersion
|
|
190
192
|
||evidence.pVersion!==taken.pVersion
|
|
191
|
-
||(evidence.priorAssistantKey||null)!==(taken.priorAssistantKey||null)
|
|
193
|
+
||(evidence.priorAssistantKey||null)!==(taken.priorAssistantKey||null)
|
|
194
|
+
||(evidence.postApprovalAssistantKey||null)!==(taken.postApprovalAssistantKey||null)))
|
|
192
195
|
throw Error('ADOPTION_APPROVAL_CHANGED');
|
|
193
196
|
const registered=await chrome.runtime.sendMessage({type:'CHAT_LOOP_RESOURCE_CHAT_V1',
|
|
194
197
|
action:'start',stage:'adopt',tabId:existing.id});
|
|
@@ -200,7 +203,9 @@ async function run(){
|
|
|
200
203
|
if(committed?.status!=='OK')throw Error(committed?.code||'ADOPTION_COMMIT_UNVERIFIED');
|
|
201
204
|
await chrome.tabs.sendMessage(existing.id,{type:'CHAT_LOOP_TURN_RESUME_V1',
|
|
202
205
|
page:taken.page,userKey:taken.userKey,
|
|
203
|
-
assistantKey:taken.priorAssistantKey||null,
|
|
206
|
+
assistantKey:taken.postApprovalAssistantKey||taken.priorAssistantKey||null,
|
|
207
|
+
...(taken.postApprovalAssistantKey?{baselineOnly:true}:{}),
|
|
208
|
+
startedAt:Date.now()}).catch(()=>null);
|
|
204
209
|
const stored=await chrome.runtime.sendNativeMessage(host,{op:'complete',
|
|
205
210
|
id,nonce:proof.nonce,action:'start',status:'OK',payload:JSON.stringify(committed)});
|
|
206
211
|
if(stored?.status!=='SAVED')throw Error(stored?.code||'ADOPTION_RECEIPT_UNVERIFIED');
|
package/extension/background.js
CHANGED
|
@@ -112,7 +112,7 @@ async function saveRun(run) {
|
|
|
112
112
|
}
|
|
113
113
|
const stored=await readRun();
|
|
114
114
|
const recoveryCommit=next.sessionId&&next.phase==="RESERVED"
|
|
115
|
-
&&["TOOL_PREFLIGHT_REPAIRED","HANDOFF_NOT_SENT"].includes(next.recoveryMode)
|
|
115
|
+
&&["TOOL_PREFLIGHT_REPAIRED","HANDOFF_NOT_SENT","ADOPT_IDLE_BASELINE"].includes(next.recoveryMode)
|
|
116
116
|
&&next.recoveryAttempts>=1&&stored?.phase==="BLOCKED";
|
|
117
117
|
const syncNative=async()=>{
|
|
118
118
|
if(!next.sessionId)return;
|
|
@@ -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,9 @@ 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
|
+
postApprovalAssistantKey:proof.postApprovalAssistantKey||null,
|
|
266
|
+
...(!requestedId&&taskId?{explicitChatId:scopedId,expectedTaskId:taskId}:{})});
|
|
259
267
|
}
|
|
260
268
|
if(matched.length!==1)return {error:matched.length
|
|
261
269
|
?"ADOPTION_APPROVAL_AMBIGUOUS":"ADOPTION_APPROVAL_NOT_FOUND"};
|
|
@@ -263,11 +271,14 @@ async function approvedAdoptionTarget(chatUrl=null){
|
|
|
263
271
|
await new Promise(resolve=>setTimeout(resolve,400));
|
|
264
272
|
const second=await chrome.tabs.sendMessage(target.tabId,
|
|
265
273
|
{type:"CHAT_LOOP_APPROVAL_EVIDENCE_V1",
|
|
266
|
-
...(requestedId
|
|
274
|
+
...((requestedId||target.explicitChatId)
|
|
275
|
+
?{explicitChatId:requestedId||target.explicitChatId}:{}),
|
|
276
|
+
...(target.expectedTaskId?{expectedTaskId:target.expectedTaskId}:{})}).catch(()=>null);
|
|
267
277
|
if(second?.status!=="VERIFIED"
|
|
268
278
|
||second.page!==target.page||second.userKey!==target.userKey
|
|
269
279
|
||second.rVersion!==target.rVersion||second.pVersion!==target.pVersion
|
|
270
|
-
||(second.priorAssistantKey||null)!==(target.priorAssistantKey||null)
|
|
280
|
+
||(second.priorAssistantKey||null)!==(target.priorAssistantKey||null)
|
|
281
|
+
||(second.postApprovalAssistantKey||null)!==target.postApprovalAssistantKey)
|
|
271
282
|
return {error:"ADOPTION_APPROVAL_CHANGED"};
|
|
272
283
|
return {target};
|
|
273
284
|
}
|
|
@@ -379,7 +390,8 @@ async function sessionStartPrepare(message,sender){
|
|
|
379
390
|
const adoption=intent.mode==='adopt'
|
|
380
391
|
?intent.purpose==='REPAIR_SAME_SCOPE'
|
|
381
392
|
?await approvedRepairTarget(prior,intent)
|
|
382
|
-
:await approvedAdoptionTarget(intent.chatUrl||null
|
|
393
|
+
:await approvedAdoptionTarget(intent.chatUrl||null,
|
|
394
|
+
intent.contextLeaseRef?intent.taskId:null):null;
|
|
383
395
|
if(adoption?.error)return {status:'DENIED',code:adoption.error};
|
|
384
396
|
// A Project-scoped Chat cannot safely hand off to the ordinary home route:
|
|
385
397
|
// reject BEFORE claiming Owner instead of failing after four hours.
|
|
@@ -407,8 +419,12 @@ async function sessionStartPrepare(message,sender){
|
|
|
407
419
|
...(matchingBlocked?{replacedBlockedSessionId:replace}:{}),
|
|
408
420
|
...(adoption?{mode:'adopt',adoptTabId:adoption.target.tabId,
|
|
409
421
|
adoptPage:adoption.target.page,adoptUserKey:adoption.target.userKey,
|
|
410
|
-
...(intent.chatUrl
|
|
422
|
+
...((intent.chatUrl||adoption.target.explicitChatId)
|
|
423
|
+
?{adoptExplicitChatId:chatIdOf(intent.chatUrl)||adoption.target.explicitChatId}:{}),
|
|
424
|
+
...(adoption.target.expectedTaskId
|
|
425
|
+
?{adoptExpectedTaskId:adoption.target.expectedTaskId}:{}),
|
|
411
426
|
adoptPriorAssistantKey:adoption.target.priorAssistantKey,
|
|
427
|
+
adoptPostApprovalAssistantKey:adoption.target.postApprovalAssistantKey||null,
|
|
412
428
|
...(intent.purpose==='REPAIR_SAME_SCOPE'?{}:{
|
|
413
429
|
adoptRVersion:adoption.target.rVersion,
|
|
414
430
|
adoptPVersion:adoption.target.pVersion}),
|
|
@@ -446,7 +462,9 @@ async function sessionStartTake(message,sender){
|
|
|
446
462
|
...(run.mode==='adopt'?{mode:'adopt',tabId:run.adoptTabId,
|
|
447
463
|
page:run.adoptPage,userKey:run.adoptUserKey,
|
|
448
464
|
...(run.adoptExplicitChatId?{explicitChatId:run.adoptExplicitChatId}:{}),
|
|
465
|
+
...(run.adoptExpectedTaskId?{expectedTaskId:run.adoptExpectedTaskId}:{}),
|
|
449
466
|
priorAssistantKey:run.adoptPriorAssistantKey,
|
|
467
|
+
postApprovalAssistantKey:run.adoptPostApprovalAssistantKey||null,
|
|
450
468
|
...(run.purpose==='REPAIR_SAME_SCOPE'
|
|
451
469
|
?{purpose:'REPAIR_SAME_SCOPE',repairUserText:run.repairUserText,
|
|
452
470
|
priorDoneAssistantKey:run.repairDoneAssistantKey}
|
|
@@ -477,7 +495,9 @@ async function sessionStartResult(message,sender){
|
|
|
477
495
|
const proof=await chrome.tabs.sendMessage(run.adoptTabId,
|
|
478
496
|
{type:repair?'CHAT_LOOP_REPAIR_EVIDENCE_V1':'CHAT_LOOP_APPROVAL_EVIDENCE_V1',
|
|
479
497
|
...(run.adoptExplicitChatId
|
|
480
|
-
?{explicitChatId:run.adoptExplicitChatId}:{})
|
|
498
|
+
?{explicitChatId:run.adoptExplicitChatId}:{}),
|
|
499
|
+
...(run.adoptExpectedTaskId
|
|
500
|
+
?{expectedTaskId:run.adoptExpectedTaskId}:{})}).catch(()=>null);
|
|
481
501
|
confirmed=proof?.contract==='chat-loop.turn-observer.v1'
|
|
482
502
|
&&proof.status==='VERIFIED'&&proof.page===run.adoptPage
|
|
483
503
|
&&proof.userKey===run.adoptUserKey
|
|
@@ -486,15 +506,20 @@ async function sessionStartResult(message,sender){
|
|
|
486
506
|
&&proof.priorDoneAssistantKey===run.repairDoneAssistantKey
|
|
487
507
|
:proof.rVersion===run.adoptRVersion
|
|
488
508
|
&&proof.pVersion===run.adoptPVersion
|
|
489
|
-
&&(proof.priorAssistantKey||null)===(run.adoptPriorAssistantKey||null)
|
|
509
|
+
&&(proof.priorAssistantKey||null)===(run.adoptPriorAssistantKey||null)
|
|
510
|
+
&&(proof.postApprovalAssistantKey||null)===(run.adoptPostApprovalAssistantKey||null));
|
|
490
511
|
}
|
|
491
512
|
}
|
|
492
513
|
// Four-hour execution clock begins at confirmed enrollment, not at
|
|
493
514
|
// the UI approval or potentially long Start readiness/preparation.
|
|
515
|
+
const adoptedIdle=confirmed&&adopted&&!!run.adoptPostApprovalAssistantKey;
|
|
494
516
|
const next={...run,phase:confirmed?'WAITING_REPLY':'BLOCKED',
|
|
495
517
|
startedAt:confirmed?Date.now():run.startedAt,
|
|
496
518
|
lastStartActionTabId:sender.tab.id,
|
|
497
|
-
|
|
519
|
+
...(adoptedIdle?{assistantKey:run.adoptPostApprovalAssistantKey,
|
|
520
|
+
userKey:run.adoptUserKey}:{}),
|
|
521
|
+
reason:confirmed?(adoptedIdle?'ADOPTED_IDLE_BASELINE':'')
|
|
522
|
+
:adopted?'ADOPTION_UNVERIFIED':'START_SEND_UNVERIFIED',
|
|
498
523
|
...(!confirmed&&['START_HOME_URL_UNVERIFIED','NEW_CHAT_NOT_READY',
|
|
499
524
|
'START_COMPOSER_NOT_EMPTY','START_ACCOUNT_SWITCH_VISIBLE',
|
|
500
525
|
'FIRST_TURN_OBSERVER_UNAVAILABLE','START_SEND_BUTTON_UNAVAILABLE','START_INPUT_CHANGED',
|
|
@@ -513,7 +538,9 @@ async function sessionStartResult(message,sender){
|
|
|
513
538
|
delete next.adoptPage;
|
|
514
539
|
delete next.adoptUserKey;
|
|
515
540
|
delete next.adoptExplicitChatId;
|
|
541
|
+
delete next.adoptExpectedTaskId;
|
|
516
542
|
delete next.adoptPriorAssistantKey;
|
|
543
|
+
delete next.adoptPostApprovalAssistantKey;
|
|
517
544
|
delete next.adoptRVersion;
|
|
518
545
|
delete next.adoptPVersion;
|
|
519
546
|
delete next.repairUserText;
|
|
@@ -1026,7 +1053,7 @@ async function onTurnFinished(message, sender) {
|
|
|
1026
1053
|
// assistant must be the exact already-handled question from this Owner, with
|
|
1027
1054
|
// no intervening user messages. This keeps the old identity boundary
|
|
1028
1055
|
// without adding a WAITING_USER phase or a second communication channel.
|
|
1029
|
-
const humanReply=previous.reason
|
|
1056
|
+
const humanReply=["PENDING_CONFIRMATION_DOM","ADOPTED_IDLE_BASELINE"].includes(previous.reason)
|
|
1030
1057
|
&& message.userKey!==previous.newUserKey
|
|
1031
1058
|
&& previous.userKey && previous.assistantKey
|
|
1032
1059
|
&& message.userKey!==previous.userKey
|
|
@@ -1197,6 +1224,84 @@ async function repairUncommittedBlockedRecovery(){
|
|
|
1197
1224
|
await saveRun(restored);
|
|
1198
1225
|
return restored;
|
|
1199
1226
|
}
|
|
1227
|
+
// One-shot recovery of an ALREADY committed same-Chat Adopt whose historical
|
|
1228
|
+
// post-approval reply was wrongly classified UNKNOWN. Never writes a composer,
|
|
1229
|
+
// retries an action or replaces Context/Owner. Requires exact Native BLOCKED CAS.
|
|
1230
|
+
async function onAdoptBaselineRepair(message,sender){
|
|
1231
|
+
const prior=await readRun();
|
|
1232
|
+
if(prior?.phase!=='BLOCKED'||prior.reason!=='UNKNOWN'
|
|
1233
|
+
||prior.action!=='START'||!prior.contextManaged||!prior.taskId
|
|
1234
|
+
||(prior.recoveryAttempts||0)!==0
|
|
1235
|
+
||!prior.sessionId||!Number.isInteger(prior.tabId)
|
|
1236
|
+
||prior.tabId!==message.tabId||!prior.page
|
|
1237
|
+
||!/^user:[^\s]{8,}$/.test(prior.newUserKey||'')
|
|
1238
|
+
||!/^assistant:[^\s]{8,}$/.test(prior.assistantKey||'')
|
|
1239
|
+
||prior.userKey!==prior.newUserKey)
|
|
1240
|
+
return {status:'DENIED',code:'ADOPT_BASELINE_NOT_ELIGIBLE'};
|
|
1241
|
+
if(!Number.isSafeInteger(message.nativeUpdatedAt)||message.nativeUpdatedAt<=0
|
|
1242
|
+
||!Number.isInteger(sender.tab?.id))
|
|
1243
|
+
return {status:'DENIED',code:'ADOPT_BASELINE_INVALID_SOURCE'};
|
|
1244
|
+
const expected=chrome.runtime.getURL('continue.html')
|
|
1245
|
+
+'?tabId='+prior.tabId+'&adoptBaselineAt='+message.nativeUpdatedAt;
|
|
1246
|
+
if(sender.url!==expected)
|
|
1247
|
+
return {status:'DENIED',code:'ADOPT_BASELINE_INVALID_ACTION'};
|
|
1248
|
+
const tab=await chrome.tabs.get(prior.tabId).catch(()=>null);
|
|
1249
|
+
if(pathOf(tab?.url)!==prior.page)
|
|
1250
|
+
return {status:'DENIED',code:'ADOPT_BASELINE_CHAT_CHANGED'};
|
|
1251
|
+
const disk=await chrome.runtime.sendNativeMessage(SESSION_HOST,
|
|
1252
|
+
{op:'session-read'}).catch(()=>null);
|
|
1253
|
+
if(disk?.status!=='OK'||!matchesNativeProjection(sessionProjection(prior),disk.session)
|
|
1254
|
+
||disk.session?.phase!=='BLOCKED'
|
|
1255
|
+
||disk.session.updatedAt!==message.nativeUpdatedAt)
|
|
1256
|
+
return {status:'DENIED',code:'ADOPT_BASELINE_NATIVE_CHANGED'};
|
|
1257
|
+
const exactChatId=chatIdOf(tab.url);
|
|
1258
|
+
const read=async()=>{
|
|
1259
|
+
const approval=await chrome.tabs.sendMessage(tab.id,
|
|
1260
|
+
{type:'CHAT_LOOP_APPROVAL_EVIDENCE_V1',
|
|
1261
|
+
explicitChatId:exactChatId,expectedTaskId:prior.taskId}).catch(()=>null);
|
|
1262
|
+
const turn=await chrome.tabs.sendMessage(tab.id,
|
|
1263
|
+
{type:'CHAT_LOOP_TURN_VERIFY_V1'}).catch(()=>null);
|
|
1264
|
+
if(approval?.contract!=='chat-loop.turn-observer.v1'
|
|
1265
|
+
||approval.status!=='VERIFIED'
|
|
1266
|
+
||approval.page!==prior.page
|
|
1267
|
+
||approval.userKey!==prior.newUserKey
|
|
1268
|
+
||approval.postApprovalAssistantKey!==prior.assistantKey
|
|
1269
|
+
||turn?.contract!=='chat-loop.turn-observer.v1'
|
|
1270
|
+
||turn.status!=='READY'||turn.page!==prior.page
|
|
1271
|
+
||turn.userKey!==prior.newUserKey||turn.assistantKey!==prior.assistantKey
|
|
1272
|
+
||turn.pendingConfirmation
|
|
1273
|
+
||globalThis.ChatLoopCoreV1.parseStatus(turn.replyText)!=='UNKNOWN')
|
|
1274
|
+
return null;
|
|
1275
|
+
return {userKey:turn.userKey,assistantKey:turn.assistantKey,
|
|
1276
|
+
replyText:turn.replyText,rVersion:approval.rVersion,pVersion:approval.pVersion};
|
|
1277
|
+
};
|
|
1278
|
+
const a=await read();
|
|
1279
|
+
if(!a)return {status:'DENIED',code:'ADOPT_BASELINE_PROOF_MISSING'};
|
|
1280
|
+
await new Promise(resolve=>setTimeout(resolve,2300));
|
|
1281
|
+
const b=await read();
|
|
1282
|
+
if(!b||JSON.stringify(a)!==JSON.stringify(b))
|
|
1283
|
+
return {status:'DENIED',code:'ADOPT_BASELINE_PROOF_CHANGED'};
|
|
1284
|
+
// Re-arm the observer as a historical baseline BEFORE Native CAS. Failure
|
|
1285
|
+
// cannot leave Native in a half-resumed state. This sends no Chat message.
|
|
1286
|
+
const armed=await chrome.tabs.sendMessage(tab.id,{
|
|
1287
|
+
type:'CHAT_LOOP_TURN_RESUME_V1',
|
|
1288
|
+
page:prior.page,userKey:prior.newUserKey,
|
|
1289
|
+
assistantKey:prior.assistantKey,baselineOnly:true,
|
|
1290
|
+
startedAt:prior.startedAt
|
|
1291
|
+
}).catch(()=>null);
|
|
1292
|
+
if(armed?.status!=='RESUMED'||armed.baselineOnly!==true)
|
|
1293
|
+
return {status:'DENIED',code:'ADOPT_BASELINE_OBSERVER_UNVERIFIED'};
|
|
1294
|
+
await saveRun({...prior,phase:'RESERVED',
|
|
1295
|
+
reason:'ADOPT_BASELINE_RECOVERY',
|
|
1296
|
+
recoveryMode:'ADOPT_IDLE_BASELINE',recoveryAttempts:1});
|
|
1297
|
+
const clean={...prior,phase:'WAITING_REPLY',reason:'ADOPTED_IDLE_BASELINE',
|
|
1298
|
+
recoveryAttempts:1,userKey:prior.newUserKey,assistantKey:prior.assistantKey};
|
|
1299
|
+
delete clean.recoveryMode;
|
|
1300
|
+
await saveRun(clean);
|
|
1301
|
+
return {status:'REPAIRED',sessionId:prior.sessionId,taskId:prior.taskId,
|
|
1302
|
+
activeChatId:exactChatId,baselineAssistantKey:prior.assistantKey,
|
|
1303
|
+
generation:prior.generation||0};
|
|
1304
|
+
}
|
|
1200
1305
|
// Only an explicitly opened, existing Continue Action may reveal a
|
|
1201
1306
|
// scroll-virtualized *terminal Owner* before the normal double Turn check.
|
|
1202
1307
|
// This grants no send permit and changes neither Worker nor Native state.
|
|
@@ -1759,6 +1864,7 @@ async function reconnectOpenChats() {
|
|
|
1759
1864
|
type: "CHAT_LOOP_TURN_RESUME_V1", page: owner.page,
|
|
1760
1865
|
userKey:freshUser?proof.userKey:owner.newUserKey,
|
|
1761
1866
|
assistantKey: owner.assistantKey || null,
|
|
1867
|
+
...(owner.reason==='ADOPTED_IDLE_BASELINE'?{baselineOnly:true}:{}),
|
|
1762
1868
|
startedAt: owner.startedAt
|
|
1763
1869
|
}).catch(() => null);
|
|
1764
1870
|
if (res?.status !== "RESUMED" && res?.status !== "ALREADY_MONITORING")
|
|
@@ -1810,6 +1916,7 @@ async function watchActiveTurn() {
|
|
|
1810
1916
|
type: "CHAT_LOOP_TURN_RESUME_V1", page: run.page,
|
|
1811
1917
|
userKey: freshHuman?proof.userKey:run.newUserKey,
|
|
1812
1918
|
assistantKey: run.assistantKey || null,
|
|
1919
|
+
...(run.reason==='ADOPTED_IDLE_BASELINE'?{baselineOnly:true}:{}),
|
|
1813
1920
|
startedAt: run.startedAt
|
|
1814
1921
|
}).catch(() => null);
|
|
1815
1922
|
}
|
|
@@ -1932,6 +2039,7 @@ const SERIAL_ROUTES=new Map([
|
|
|
1932
2039
|
['CHAT_LOOP_ACTION_TAKE_V1',onTake],
|
|
1933
2040
|
['CHAT_LOOP_ACTION_RESULT_V1',onResult],
|
|
1934
2041
|
['CHAT_LOOP_HANDOFF_SEND_BEGIN_V1',onHandoffSendBegin],
|
|
2042
|
+
['CHAT_LOOP_ADOPT_BASELINE_REPAIR_V1',onAdoptBaselineRepair],
|
|
1935
2043
|
['CHAT_LOOP_ACTION_MANUAL_REVEAL_V1',onManualReveal],
|
|
1936
2044
|
['CHAT_LOOP_ACTION_MANUAL_PREPARE_V1',onManualPrepare],
|
|
1937
2045
|
['CHAT_LOOP_MODEL_INTENT_V1',onModelIntent],
|
|
@@ -415,8 +415,9 @@
|
|
|
415
415
|
return false;
|
|
416
416
|
}
|
|
417
417
|
if (message?.type === "CHAT_LOOP_TURN_RESUME_V1") {
|
|
418
|
-
// Rebind only the exact Worker-owned
|
|
419
|
-
//
|
|
418
|
+
// Rebind only the exact Worker-owned Turn after Extension reload.
|
|
419
|
+
// A dedicated baseline-only mode never reports an already-completed
|
|
420
|
+
// pre-adoption assistant as a new execution Turn.
|
|
420
421
|
const snap = inspect();
|
|
421
422
|
if (!snap.path || snap.unavailable || snap.path !== message.page
|
|
422
423
|
|| !/^user:[^\s]{8,}$/.test(message.userKey || "")
|
|
@@ -429,20 +430,26 @@
|
|
|
429
430
|
// lost (e.g. MV3 worker suspension). Only that Worker-owned exact Turn
|
|
430
431
|
// may request a new stable read. Never replay on ordinary DOM polling.
|
|
431
432
|
if (session.pendingUser === message.userKey && !session.attaching
|
|
432
|
-
&& session.completedUser !== message.userKey) {
|
|
433
|
+
&& session.completedUser !== message.userKey && message.baselineOnly!==true) {
|
|
433
434
|
reply({contract: CONTRACT, status: "ALREADY_MONITORING"});
|
|
434
435
|
return false;
|
|
435
436
|
}
|
|
437
|
+
if(message.baselineOnly===true &&
|
|
438
|
+
(!message.assistantKey || snap.assistantKey!==message.assistantKey
|
|
439
|
+
|| snap.stop||snap.busy||snap.pendingConfirmation||!snap.copyAction)){
|
|
440
|
+
reply({contract:CONTRACT,status:"UNVERIFIED",reason:"ADOPT_BASELINE_UNVERIFIED"});
|
|
441
|
+
return false;
|
|
442
|
+
}
|
|
436
443
|
session.path = snap.path;
|
|
437
444
|
session.sawHomepage = false;
|
|
438
445
|
session.attaching = false;
|
|
439
446
|
session.attachingFirstTurn = false;
|
|
440
447
|
session.firstSendSeen = false;
|
|
441
448
|
session.priorUser = null;
|
|
442
|
-
session.baselineUser = null;
|
|
449
|
+
session.baselineUser = message.baselineOnly===true ? message.userKey : null;
|
|
443
450
|
session.baselineAssistant = message.assistantKey || null;
|
|
444
|
-
session.pendingUser = message.userKey;
|
|
445
|
-
session.completedUser = null;
|
|
451
|
+
session.pendingUser = message.baselineOnly===true ? null : message.userKey;
|
|
452
|
+
session.completedUser = message.baselineOnly===true ? message.userKey : null;
|
|
446
453
|
session.firstTurnAt = Number.isSafeInteger(message.startedAt)
|
|
447
454
|
&& message.startedAt > 0 ? message.startedAt : Date.now();
|
|
448
455
|
session.attachSignature = "";
|
|
@@ -450,7 +457,8 @@
|
|
|
450
457
|
const observation = poll();
|
|
451
458
|
reply({contract: CONTRACT, status: "RESUMED",
|
|
452
459
|
observation: observation.status, reason: observation.reason,
|
|
453
|
-
userKey: observation.userKey
|
|
460
|
+
userKey: observation.userKey,
|
|
461
|
+
...(message.baselineOnly===true?{baselineOnly:true}:{})});
|
|
454
462
|
return false;
|
|
455
463
|
}
|
|
456
464
|
if (message?.type === "CHAT_LOOP_REPAIR_EVIDENCE_V1") {
|
|
@@ -614,6 +622,23 @@
|
|
|
614
622
|
||rIndex>0&&rAssistant?.role!=="assistant"){
|
|
615
623
|
fail("APPROVAL_REQUIREMENTS_MISSING");return false;
|
|
616
624
|
}
|
|
625
|
+
if(message.expectedTaskId!==undefined){
|
|
626
|
+
// A no-URL idle adoption is only eligible for its exact Managed
|
|
627
|
+
// Task's TWO native issued approval messages in the same DOM Chat.
|
|
628
|
+
// No standalone historical affirmations or copied Task summaries.
|
|
629
|
+
const task=message.expectedTaskId;
|
|
630
|
+
const nativeIssue=(row,type)=>typeof task==="string"
|
|
631
|
+
&&/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,127}$/.test(task)
|
|
632
|
+
&&textOf(row).startsWith(task+"|")
|
|
633
|
+
&&new RegExp("^"+type+"[1-9][0-9]*-ISSUE:"
|
|
634
|
+
+"[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}[||]\\s*我确认\\s+"
|
|
635
|
+
+type+"[1-9][0-9]*\\s+v[1-9][0-9]*","i")
|
|
636
|
+
.test(textOf(row).slice(task.length+1));
|
|
637
|
+
if(!nativeRVersion||!nativeIssue(rUser,"R")
|
|
638
|
+
||!nativeIssue(pUser,"P")){
|
|
639
|
+
fail("APPROVAL_TASK_SCOPE_MISMATCH");return false;
|
|
640
|
+
}
|
|
641
|
+
}
|
|
617
642
|
// Only document-level TEST_ONLY markers deny production adoption:
|
|
618
643
|
// normal P plans can legitimately mention test-only scenarios.
|
|
619
644
|
const testOnlyReview=x=>
|
|
@@ -679,7 +704,20 @@
|
|
|
679
704
|
const explicitChatId=typeof message.explicitChatId==="string"
|
|
680
705
|
? message.explicitChatId.toLowerCase():null;
|
|
681
706
|
const currentId=path.match(/\/c\/([0-9a-f-]{12,})$/i)?.[1].toLowerCase();
|
|
682
|
-
|
|
707
|
+
// The managed lease may scope an idle, already-open Chat by the exact
|
|
708
|
+
// Task ID in BOTH real native R/P approval turns. No task scope from
|
|
709
|
+
// copied Context prose or generic unscoped historical confirmations.
|
|
710
|
+
const issueTask=x=>textOf(x).match(
|
|
711
|
+
/^([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;
|
|
712
|
+
const taskScoped=typeof message.expectedTaskId==="string"
|
|
713
|
+
&&message.expectedTaskId.length>=8
|
|
714
|
+
&&issueTask(rUser)===message.expectedTaskId
|
|
715
|
+
&&issueTask(pUser)===message.expectedTaskId;
|
|
716
|
+
if(message.expectedTaskId!==undefined&&!taskScoped){
|
|
717
|
+
fail("APPROVAL_TASK_SCOPE_MISMATCH");return false;
|
|
718
|
+
}
|
|
719
|
+
const scopedIdle=Boolean(
|
|
720
|
+
(explicitChatId&&explicitChatId===currentId||taskScoped)
|
|
683
721
|
&&!snap.stop&&!snap.busy&&snap.assistantKey
|
|
684
722
|
&&snap.composerReady&&snap.copyAction&&snap.text
|
|
685
723
|
&&!snap.pendingConfirmation);
|
|
@@ -689,7 +727,10 @@
|
|
|
689
727
|
fail("APPROVAL_LAST_TURN_UNVERIFIED");return false;
|
|
690
728
|
}
|
|
691
729
|
reply({contract:CONTRACT,status:"VERIFIED",page:path,
|
|
692
|
-
userKey,rVersion,pVersion,priorAssistantKey:messageId(pAssistant.el,"assistant")
|
|
730
|
+
userKey,rVersion,pVersion,priorAssistantKey:messageId(pAssistant.el,"assistant"),
|
|
731
|
+
// Idle post-approval assistant was completed BEFORE adoption.
|
|
732
|
+
// This is a historical baseline, never a fresh execution Turn.
|
|
733
|
+
...(scopedIdle?{postApprovalAssistantKey:snap.assistantKey}:{})});
|
|
693
734
|
return false;
|
|
694
735
|
}
|
|
695
736
|
if (message?.type === "CHAT_LOOP_TURN_VERIFY_V1") {
|
package/extension/manifest.json
CHANGED