@tomflow/chatloop-extension 0.3.79 → 0.3.81

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.
@@ -38,11 +38,14 @@ async function sendOnce(target, text) {
38
38
  || answer.closest('[data-talvt-turn-state]') || answer;
39
39
  const replyText = (answer.querySelector('.markdown')?.innerText || answer.innerText || '').trim();
40
40
  const lines = replyText.split(/\r?\n/);
41
- const expectedMarker=expected.recoveryMode==="TOOL_PREFLIGHT_REPAIRED"
41
+ const expectedMarker=expected.recoveryMode==="ADOPT_KICKOFF"
42
+ ? null : expected.recoveryMode==="TOOL_PREFLIGHT_REPAIRED"
42
43
  ? "[CHAT_LOOP_STATUS:BLOCKED]" : expected.recoveryMode==="HANDOFF_NOT_SENT"
43
44
  ? expected.contextSourceMarker : "[CHAT_LOOP_STATUS:CONTINUE]";
44
- if (lines.at(-1)?.trim() !== expectedMarker
45
- || lines.filter(line=>/^\[CHAT_LOOP_STATUS:(?:CONTINUE|DONE|BLOCKED|HANDOFF)\]$/.test(line.trim())).length !== 1) {
45
+ if ((expectedMarker===null
46
+ ? lines.some(line=>/^\[CHAT_LOOP_STATUS:(?:CONTINUE|DONE|BLOCKED|HANDOFF)\]$/.test(line.trim()))
47
+ : lines.at(-1)?.trim() !== expectedMarker
48
+ ||lines.filter(line=>/^\[CHAT_LOOP_STATUS:(?:CONTINUE|DONE|BLOCKED|HANDOFF)\]$/.test(line.trim())).length !== 1)) {
46
49
  throw Error("CONTINUE_STATUS_CHANGED");
47
50
  }
48
51
  const turnState = scope.getAttribute?.('data-talvt-turn-state');
@@ -230,7 +233,7 @@ async function run() {
230
233
  const raw = params.get("tabId") || "";
231
234
  let token = params.get("token") || "";
232
235
  let tabId = Number(raw);
233
- if ([...params.keys()].some(k => k !== "tabId" && k !== "token" && k !== "repairLegacyReservation" && k !== "resumeBlockedAt" && k !== "recoverContextNotSentAt")
236
+ if ([...params.keys()].some(k => k !== "tabId" && k !== "token" && k !== "repairLegacyReservation" && k !== "resumeBlockedAt" && k !== "recoverContextNotSentAt" && k !== "adoptBaselineAt" && k !== "adoptKickoffAt")
234
237
  || [...params.keys()].length !== new Set(params.keys()).size)
235
238
  throw Error("ACTION_PARAMETERS_INVALID");
236
239
  if (raw && !/^[1-9][0-9]*$/.test(raw)
@@ -239,6 +242,33 @@ async function run() {
239
242
  ||params.has("recoverContextNotSentAt"))) throw Error("ACTION_PARAMETERS_INVALID");
240
243
  const own = await chrome.tabs.getCurrent();
241
244
  if (!own?.id || own.url !== location.href) throw Error("ACTION_TAB_UNVERIFIED");
245
+ if(params.has("adoptBaselineAt")){
246
+ const rawAt=params.get("adoptBaselineAt"),at=Number(rawAt);
247
+ if(params.size!==2||!raw||token||!/^[1-9][0-9]{12}$/.test(rawAt||"")
248
+ ||!Number.isSafeInteger(at))
249
+ throw Error("ADOPT_BASELINE_PARAMETERS_INVALID");
250
+ show("VERIFYING","对同一原 Chat 的历史审批回复进行只读复核;绝不发送消息。");
251
+ const result=await chrome.runtime.sendMessage({
252
+ type:"CHAT_LOOP_ADOPT_BASELINE_REPAIR_V1",
253
+ tabId,nativeUpdatedAt:at});
254
+ if(result?.status!=="REPAIRED")
255
+ throw Error(result?.code||"ADOPT_BASELINE_REPAIR_UNVERIFIED");
256
+ show("SUCCESS","已对原 Chat 完成历史基线恢复;未创建 Chat、未发送消息。");
257
+ await chrome.tabs.remove(own.id);
258
+ return;
259
+ }
260
+ if(params.has("adoptKickoffAt")){
261
+ const rawAt=params.get("adoptKickoffAt"),at=Number(rawAt);
262
+ if(params.size!==2||!raw||token||!/^[1-9][0-9]{12}$/.test(rawAt||"")
263
+ ||!Number.isSafeInteger(at))
264
+ throw Error("ADOPT_KICKOFF_PARAMETERS_INVALID");
265
+ show("VERIFYING","核查当前 Managed Task、已批准 R/P 和原 Chat 的历史回复,再申请唯一首轮执行许可。");
266
+ const prepared=await chrome.runtime.sendMessage({
267
+ type:"CHAT_LOOP_ADOPT_KICKOFF_PREPARE_V1",tabId,nativeUpdatedAt:at});
268
+ if(prepared?.status!=="PREPARED")
269
+ throw Error(prepared?.code||"ADOPT_KICKOFF_NOT_PREPARED");
270
+ token=prepared.token;
271
+ }
242
272
  if (!token) {
243
273
  show("VERIFYING", "手动打开 Continue:核对当前已完成的 Turn,并申请单次发送许可。");
244
274
  if(params.has("resumeBlockedAt")){
@@ -190,7 +190,8 @@ async function run(){
190
190
  ||evidence.priorDoneAssistantKey!==taken.priorDoneAssistantKey
191
191
  : evidence.rVersion!==taken.rVersion
192
192
  ||evidence.pVersion!==taken.pVersion
193
- ||(evidence.priorAssistantKey||null)!==(taken.priorAssistantKey||null)))
193
+ ||(evidence.priorAssistantKey||null)!==(taken.priorAssistantKey||null)
194
+ ||(evidence.postApprovalAssistantKey||null)!==(taken.postApprovalAssistantKey||null)))
194
195
  throw Error('ADOPTION_APPROVAL_CHANGED');
195
196
  const registered=await chrome.runtime.sendMessage({type:'CHAT_LOOP_RESOURCE_CHAT_V1',
196
197
  action:'start',stage:'adopt',tabId:existing.id});
@@ -202,7 +203,9 @@ async function run(){
202
203
  if(committed?.status!=='OK')throw Error(committed?.code||'ADOPTION_COMMIT_UNVERIFIED');
203
204
  await chrome.tabs.sendMessage(existing.id,{type:'CHAT_LOOP_TURN_RESUME_V1',
204
205
  page:taken.page,userKey:taken.userKey,
205
- assistantKey:taken.priorAssistantKey||null,startedAt:Date.now()}).catch(()=>null);
206
+ assistantKey:taken.postApprovalAssistantKey||taken.priorAssistantKey||null,
207
+ ...(taken.postApprovalAssistantKey?{baselineOnly:true}:{}),
208
+ startedAt:Date.now()}).catch(()=>null);
206
209
  const stored=await chrome.runtime.sendNativeMessage(host,{op:'complete',
207
210
  id,nonce:proof.nonce,action:'start',status:'OK',payload:JSON.stringify(committed)});
208
211
  if(stored?.status!=='SAVED')throw Error(stored?.code||'ADOPTION_RECEIPT_UNVERIFIED');
@@ -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;
@@ -262,6 +262,7 @@ async function approvedAdoptionTarget(chatUrl=null,taskId=null){
262
262
  matched.push({tabId:tab.id,page,userKey:proof.userKey,
263
263
  priorAssistantKey:proof.priorAssistantKey||null,
264
264
  rVersion:proof.rVersion,pVersion:proof.pVersion,
265
+ postApprovalAssistantKey:proof.postApprovalAssistantKey||null,
265
266
  ...(!requestedId&&taskId?{explicitChatId:scopedId,expectedTaskId:taskId}:{})});
266
267
  }
267
268
  if(matched.length!==1)return {error:matched.length
@@ -276,7 +277,8 @@ async function approvedAdoptionTarget(chatUrl=null,taskId=null){
276
277
  if(second?.status!=="VERIFIED"
277
278
  ||second.page!==target.page||second.userKey!==target.userKey
278
279
  ||second.rVersion!==target.rVersion||second.pVersion!==target.pVersion
279
- ||(second.priorAssistantKey||null)!==(target.priorAssistantKey||null))
280
+ ||(second.priorAssistantKey||null)!==(target.priorAssistantKey||null)
281
+ ||(second.postApprovalAssistantKey||null)!==target.postApprovalAssistantKey)
280
282
  return {error:"ADOPTION_APPROVAL_CHANGED"};
281
283
  return {target};
282
284
  }
@@ -422,6 +424,7 @@ async function sessionStartPrepare(message,sender){
422
424
  ...(adoption.target.expectedTaskId
423
425
  ?{adoptExpectedTaskId:adoption.target.expectedTaskId}:{}),
424
426
  adoptPriorAssistantKey:adoption.target.priorAssistantKey,
427
+ adoptPostApprovalAssistantKey:adoption.target.postApprovalAssistantKey||null,
425
428
  ...(intent.purpose==='REPAIR_SAME_SCOPE'?{}:{
426
429
  adoptRVersion:adoption.target.rVersion,
427
430
  adoptPVersion:adoption.target.pVersion}),
@@ -461,6 +464,7 @@ async function sessionStartTake(message,sender){
461
464
  ...(run.adoptExplicitChatId?{explicitChatId:run.adoptExplicitChatId}:{}),
462
465
  ...(run.adoptExpectedTaskId?{expectedTaskId:run.adoptExpectedTaskId}:{}),
463
466
  priorAssistantKey:run.adoptPriorAssistantKey,
467
+ postApprovalAssistantKey:run.adoptPostApprovalAssistantKey||null,
464
468
  ...(run.purpose==='REPAIR_SAME_SCOPE'
465
469
  ?{purpose:'REPAIR_SAME_SCOPE',repairUserText:run.repairUserText,
466
470
  priorDoneAssistantKey:run.repairDoneAssistantKey}
@@ -502,15 +506,20 @@ async function sessionStartResult(message,sender){
502
506
  &&proof.priorDoneAssistantKey===run.repairDoneAssistantKey
503
507
  :proof.rVersion===run.adoptRVersion
504
508
  &&proof.pVersion===run.adoptPVersion
505
- &&(proof.priorAssistantKey||null)===(run.adoptPriorAssistantKey||null));
509
+ &&(proof.priorAssistantKey||null)===(run.adoptPriorAssistantKey||null)
510
+ &&(proof.postApprovalAssistantKey||null)===(run.adoptPostApprovalAssistantKey||null));
506
511
  }
507
512
  }
508
513
  // Four-hour execution clock begins at confirmed enrollment, not at
509
514
  // the UI approval or potentially long Start readiness/preparation.
515
+ const adoptedIdle=confirmed&&adopted&&!!run.adoptPostApprovalAssistantKey;
510
516
  const next={...run,phase:confirmed?'WAITING_REPLY':'BLOCKED',
511
517
  startedAt:confirmed?Date.now():run.startedAt,
512
518
  lastStartActionTabId:sender.tab.id,
513
- reason:confirmed?'':adopted?'ADOPTION_UNVERIFIED':'START_SEND_UNVERIFIED',
519
+ ...(adoptedIdle?{assistantKey:run.adoptPostApprovalAssistantKey,
520
+ userKey:run.adoptUserKey}:{}),
521
+ reason:confirmed?(adoptedIdle?'ADOPTED_IDLE_BASELINE':'')
522
+ :adopted?'ADOPTION_UNVERIFIED':'START_SEND_UNVERIFIED',
514
523
  ...(!confirmed&&['START_HOME_URL_UNVERIFIED','NEW_CHAT_NOT_READY',
515
524
  'START_COMPOSER_NOT_EMPTY','START_ACCOUNT_SWITCH_VISIBLE',
516
525
  'FIRST_TURN_OBSERVER_UNAVAILABLE','START_SEND_BUTTON_UNAVAILABLE','START_INPUT_CHANGED',
@@ -531,6 +540,7 @@ async function sessionStartResult(message,sender){
531
540
  delete next.adoptExplicitChatId;
532
541
  delete next.adoptExpectedTaskId;
533
542
  delete next.adoptPriorAssistantKey;
543
+ delete next.adoptPostApprovalAssistantKey;
534
544
  delete next.adoptRVersion;
535
545
  delete next.adoptPVersion;
536
546
  delete next.repairUserText;
@@ -1043,7 +1053,7 @@ async function onTurnFinished(message, sender) {
1043
1053
  // assistant must be the exact already-handled question from this Owner, with
1044
1054
  // no intervening user messages. This keeps the old identity boundary
1045
1055
  // without adding a WAITING_USER phase or a second communication channel.
1046
- const humanReply=previous.reason==="PENDING_CONFIRMATION_DOM"
1056
+ const humanReply=["PENDING_CONFIRMATION_DOM","ADOPTED_IDLE_BASELINE"].includes(previous.reason)
1047
1057
  && message.userKey!==previous.newUserKey
1048
1058
  && previous.userKey && previous.assistantKey
1049
1059
  && message.userKey!==previous.userKey
@@ -1214,6 +1224,148 @@ async function repairUncommittedBlockedRecovery(){
1214
1224
  await saveRun(restored);
1215
1225
  return restored;
1216
1226
  }
1227
+ // An adopted, already-approved original Chat has an idle historical Pn answer.
1228
+ // This one-shot kickoff is the missing bridge into the FIRST controlled execution
1229
+ // Turn. Only the formal Continue Action may request it, with exact Native CAS.
1230
+ // There is no direct Worker send, second Owner, or replay of prior approval.
1231
+ async function onAdoptKickoffPrepare(message,sender){
1232
+ const run=await readRun();
1233
+ if(run?.phase!=='WAITING_REPLY'||run.reason!=='ADOPTED_IDLE_BASELINE'
1234
+ ||run.action!=='START'||!run.contextManaged||!run.taskId
1235
+ ||!run.sessionId||run.generation!==0||run.kickoffAttempted
1236
+ ||!Number.isInteger(run.tabId)||run.tabId!==message.tabId
1237
+ ||!run.page||run.newUserKey!==run.userKey
1238
+ ||!/^assistant:[^\s]{8,}$/.test(run.assistantKey||'')
1239
+ ||!Number.isSafeInteger(message.nativeUpdatedAt)
1240
+ ||!Number.isInteger(sender.tab?.id)||Date.now()>=deadlineOf(run))
1241
+ return {status:'DENIED',code:'ADOPT_KICKOFF_NOT_ELIGIBLE'};
1242
+ if(sender.url!==chrome.runtime.getURL('continue.html')
1243
+ +'?tabId='+run.tabId+'&adoptKickoffAt='+message.nativeUpdatedAt)
1244
+ return {status:'DENIED',code:'ADOPT_KICKOFF_ACTION_INVALID'};
1245
+ const tab=await chrome.tabs.get(run.tabId).catch(()=>null);
1246
+ if(pathOf(tab?.url)!==run.page)
1247
+ return {status:'DENIED',code:'ADOPT_KICKOFF_CHAT_CHANGED'};
1248
+ const disk=await chrome.runtime.sendNativeMessage(SESSION_HOST,{op:'session-read'}).catch(()=>null);
1249
+ if(disk?.status!=='OK'||!matchesNativeProjection(sessionProjection(run),disk.session)
1250
+ ||disk.session.phase!=='WAITING_REPLY'
1251
+ ||disk.session.updatedAt!==message.nativeUpdatedAt)
1252
+ return {status:'DENIED',code:'ADOPT_KICKOFF_NATIVE_CHANGED'};
1253
+ const snapshot=await chrome.runtime.sendNativeMessage(SESSION_HOST,{
1254
+ op:'context-control',command:'run.snapshot',args:{}}).catch(()=>null);
1255
+ if(snapshot?.status!=='OK'
1256
+ ||snapshot.result?.runRef!==run.sessionId+':'+run.taskId+':0'
1257
+ ||snapshot.result?.unknownEffectCount!==0)
1258
+ return {status:'DENIED',code:'ADOPT_KICKOFF_CONTEXT_UNVERIFIED'};
1259
+ const exactId=chatIdOf(tab.url);
1260
+ const read=async()=>{
1261
+ const approval=await chrome.tabs.sendMessage(tab.id,{
1262
+ type:'CHAT_LOOP_APPROVAL_EVIDENCE_V1',
1263
+ explicitChatId:exactId,expectedTaskId:run.taskId}).catch(()=>null);
1264
+ const turn=await chrome.tabs.sendMessage(tab.id,{
1265
+ type:'CHAT_LOOP_TURN_VERIFY_V1'}).catch(()=>null);
1266
+ if(approval?.contract!=='chat-loop.turn-observer.v1'
1267
+ ||approval.status!=='VERIFIED'||approval.page!==run.page
1268
+ ||approval.userKey!==run.userKey
1269
+ ||approval.postApprovalAssistantKey!==run.assistantKey
1270
+ ||turn?.contract!=='chat-loop.turn-observer.v1'
1271
+ ||turn.status!=='READY'||turn.page!==run.page
1272
+ ||turn.userKey!==run.userKey||turn.assistantKey!==run.assistantKey
1273
+ ||turn.pendingConfirmation
1274
+ ||globalThis.ChatLoopCoreV1.parseStatus(turn.replyText)!=='UNKNOWN')
1275
+ return null;
1276
+ return {userKey:turn.userKey,assistantKey:turn.assistantKey,
1277
+ replyText:turn.replyText,rVersion:approval.rVersion,pVersion:approval.pVersion};
1278
+ };
1279
+ const first=await read();
1280
+ if(!first)return {status:'DENIED',code:'ADOPT_KICKOFF_APPROVAL_UNVERIFIED'};
1281
+ await new Promise(resolve=>setTimeout(resolve,2300));
1282
+ const second=await read();
1283
+ if(!second||JSON.stringify(first)!==JSON.stringify(second))
1284
+ return {status:'DENIED',code:'ADOPT_KICKOFF_APPROVAL_CHANGED'};
1285
+ const token=crypto.randomUUID();
1286
+ await saveRun({...run,phase:'RESERVED',action:'CONTINUE',token,
1287
+ manualActionTabId:sender.tab.id,
1288
+ recoveryMode:'ADOPT_KICKOFF',kickoffAttempted:true});
1289
+ return {status:'PREPARED',token,tabId:run.tabId};
1290
+ }
1291
+ // One-shot recovery of an ALREADY committed same-Chat Adopt whose historical
1292
+ // post-approval reply was wrongly classified UNKNOWN. Never writes a composer,
1293
+ // retries an action or replaces Context/Owner. Requires exact Native BLOCKED CAS.
1294
+ async function onAdoptBaselineRepair(message,sender){
1295
+ const prior=await readRun();
1296
+ if(prior?.phase!=='BLOCKED'||prior.reason!=='UNKNOWN'
1297
+ ||prior.action!=='START'||!prior.contextManaged||!prior.taskId
1298
+ ||(prior.recoveryAttempts||0)!==0
1299
+ ||!prior.sessionId||!Number.isInteger(prior.tabId)
1300
+ ||prior.tabId!==message.tabId||!prior.page
1301
+ ||!/^user:[^\s]{8,}$/.test(prior.newUserKey||'')
1302
+ ||!/^assistant:[^\s]{8,}$/.test(prior.assistantKey||'')
1303
+ ||prior.userKey!==prior.newUserKey)
1304
+ return {status:'DENIED',code:'ADOPT_BASELINE_NOT_ELIGIBLE'};
1305
+ if(!Number.isSafeInteger(message.nativeUpdatedAt)||message.nativeUpdatedAt<=0
1306
+ ||!Number.isInteger(sender.tab?.id))
1307
+ return {status:'DENIED',code:'ADOPT_BASELINE_INVALID_SOURCE'};
1308
+ const expected=chrome.runtime.getURL('continue.html')
1309
+ +'?tabId='+prior.tabId+'&adoptBaselineAt='+message.nativeUpdatedAt;
1310
+ if(sender.url!==expected)
1311
+ return {status:'DENIED',code:'ADOPT_BASELINE_INVALID_ACTION'};
1312
+ const tab=await chrome.tabs.get(prior.tabId).catch(()=>null);
1313
+ if(pathOf(tab?.url)!==prior.page)
1314
+ return {status:'DENIED',code:'ADOPT_BASELINE_CHAT_CHANGED'};
1315
+ const disk=await chrome.runtime.sendNativeMessage(SESSION_HOST,
1316
+ {op:'session-read'}).catch(()=>null);
1317
+ if(disk?.status!=='OK'||!matchesNativeProjection(sessionProjection(prior),disk.session)
1318
+ ||disk.session?.phase!=='BLOCKED'
1319
+ ||disk.session.updatedAt!==message.nativeUpdatedAt)
1320
+ return {status:'DENIED',code:'ADOPT_BASELINE_NATIVE_CHANGED'};
1321
+ const exactChatId=chatIdOf(tab.url);
1322
+ const read=async()=>{
1323
+ const approval=await chrome.tabs.sendMessage(tab.id,
1324
+ {type:'CHAT_LOOP_APPROVAL_EVIDENCE_V1',
1325
+ explicitChatId:exactChatId,expectedTaskId:prior.taskId}).catch(()=>null);
1326
+ const turn=await chrome.tabs.sendMessage(tab.id,
1327
+ {type:'CHAT_LOOP_TURN_VERIFY_V1'}).catch(()=>null);
1328
+ if(approval?.contract!=='chat-loop.turn-observer.v1'
1329
+ ||approval.status!=='VERIFIED'
1330
+ ||approval.page!==prior.page
1331
+ ||approval.userKey!==prior.newUserKey
1332
+ ||approval.postApprovalAssistantKey!==prior.assistantKey
1333
+ ||turn?.contract!=='chat-loop.turn-observer.v1'
1334
+ ||turn.status!=='READY'||turn.page!==prior.page
1335
+ ||turn.userKey!==prior.newUserKey||turn.assistantKey!==prior.assistantKey
1336
+ ||turn.pendingConfirmation
1337
+ ||globalThis.ChatLoopCoreV1.parseStatus(turn.replyText)!=='UNKNOWN')
1338
+ return null;
1339
+ return {userKey:turn.userKey,assistantKey:turn.assistantKey,
1340
+ replyText:turn.replyText,rVersion:approval.rVersion,pVersion:approval.pVersion};
1341
+ };
1342
+ const a=await read();
1343
+ if(!a)return {status:'DENIED',code:'ADOPT_BASELINE_PROOF_MISSING'};
1344
+ await new Promise(resolve=>setTimeout(resolve,2300));
1345
+ const b=await read();
1346
+ if(!b||JSON.stringify(a)!==JSON.stringify(b))
1347
+ return {status:'DENIED',code:'ADOPT_BASELINE_PROOF_CHANGED'};
1348
+ // Re-arm the observer as a historical baseline BEFORE Native CAS. Failure
1349
+ // cannot leave Native in a half-resumed state. This sends no Chat message.
1350
+ const armed=await chrome.tabs.sendMessage(tab.id,{
1351
+ type:'CHAT_LOOP_TURN_RESUME_V1',
1352
+ page:prior.page,userKey:prior.newUserKey,
1353
+ assistantKey:prior.assistantKey,baselineOnly:true,
1354
+ startedAt:prior.startedAt
1355
+ }).catch(()=>null);
1356
+ if(armed?.status!=='RESUMED'||armed.baselineOnly!==true)
1357
+ return {status:'DENIED',code:'ADOPT_BASELINE_OBSERVER_UNVERIFIED'};
1358
+ await saveRun({...prior,phase:'RESERVED',
1359
+ reason:'ADOPT_BASELINE_RECOVERY',
1360
+ recoveryMode:'ADOPT_IDLE_BASELINE',recoveryAttempts:1});
1361
+ const clean={...prior,phase:'WAITING_REPLY',reason:'ADOPTED_IDLE_BASELINE',
1362
+ recoveryAttempts:1,userKey:prior.newUserKey,assistantKey:prior.assistantKey};
1363
+ delete clean.recoveryMode;
1364
+ await saveRun(clean);
1365
+ return {status:'REPAIRED',sessionId:prior.sessionId,taskId:prior.taskId,
1366
+ activeChatId:exactChatId,baselineAssistantKey:prior.assistantKey,
1367
+ generation:prior.generation||0};
1368
+ }
1217
1369
  // Only an explicitly opened, existing Continue Action may reveal a
1218
1370
  // scroll-virtualized *terminal Owner* before the normal double Turn check.
1219
1371
  // This grants no send permit and changes neither Worker nor Native state.
@@ -1594,6 +1746,8 @@ async function onTake(message, sender) {
1594
1746
  text: run.action === "HANDOFF" ? run.handoffText || null
1595
1747
  : run.recoveryMode==="TOOL_PREFLIGHT_REPAIRED"
1596
1748
  ? "【Chat Loop 同 Chat 受控恢复】上一轮以 BLOCKED 结束;当前恢复已通过唯一 Owner、原 Chat 和 Native 身份核验,但不代表工程问题已自动解决。不要再次调用 Start、不要新建 Chat、不要重复 R/P 审批。首先核实原工作区真实状态、已执行副作用和当前 Tools 可调用能力,再依据原任务唯一检查点继续尚未完成的工作、测试与迭代;若仍有真实风险如实 BLOCKED,不要再次反复自恢复。本轮结束末行独立输出 [CHAT_LOOP_STATUS:CONTINUE]、[CHAT_LOOP_STATUS:DONE] 或 [CHAT_LOOP_STATUS:BLOCKED]。"
1749
+ : run.recoveryMode==="ADOPT_KICKOFF"
1750
+ ? "【Chat Loop 原 Chat 已正式 Start/adopt】这是当前已批准 R2/P3 Task 的第一条受控执行消息,不是新的需求或审批。请从真实 Context 读取 Task、已批准的计划及 Stage03 QA 报告,完成剩余可安全的验收工作项;不得重做旧 H UNKNOWN 首发,不得新建执行 Chat,也不得重复 R/P。若所有批准的工作项确实满足 DONE,先按 SDK 正式提交 Task delivery(没有权限则不要伪造),再输出唯一 DONE 状态;存在安全的待做工作则输出 CONTINUE,关键身份/副作用不可信则输出 BLOCKED。末行独立输出 [CHAT_LOOP_STATUS:CONTINUE]、[CHAT_LOOP_STATUS:DONE] 或 [CHAT_LOOP_STATUS:BLOCKED]。"
1597
1751
  : run.modelIntent?.action==="CONTINUE" ? (
1598
1752
  "【Chat Loop 续接来源】上一轮由模型登记的 Continue 请求 " + run.modelIntent.id
1599
1753
  + " 已被扩展唯一 Action 领取。\n"
@@ -1697,6 +1851,10 @@ async function onResult(message, sender) {
1697
1851
  }
1698
1852
  // A model prompt is one-shot. Keep only a short receipt, not the prompt
1699
1853
  // body, after the Action has reached a confirmed or blocked terminal state.
1854
+ // The kickoff exception applies to ONE historical P3 reply only.
1855
+ // Remove it after this send attempt; subsequent Continue Turns must carry
1856
+ // ordinary independent terminal markers and never inherit the exception.
1857
+ if(run.recoveryMode==="ADOPT_KICKOFF")delete next.recoveryMode;
1700
1858
  if(run.modelIntent){
1701
1859
  const override=run.action==="HANDOFF"&&run.modelIntent.action==="CONTINUE";
1702
1860
  const finalStatus=confirmed?"SENT_CONFIRMED":"BLOCKED";
@@ -1776,6 +1934,7 @@ async function reconnectOpenChats() {
1776
1934
  type: "CHAT_LOOP_TURN_RESUME_V1", page: owner.page,
1777
1935
  userKey:freshUser?proof.userKey:owner.newUserKey,
1778
1936
  assistantKey: owner.assistantKey || null,
1937
+ ...(owner.reason==='ADOPTED_IDLE_BASELINE'?{baselineOnly:true}:{}),
1779
1938
  startedAt: owner.startedAt
1780
1939
  }).catch(() => null);
1781
1940
  if (res?.status !== "RESUMED" && res?.status !== "ALREADY_MONITORING")
@@ -1827,6 +1986,7 @@ async function watchActiveTurn() {
1827
1986
  type: "CHAT_LOOP_TURN_RESUME_V1", page: run.page,
1828
1987
  userKey: freshHuman?proof.userKey:run.newUserKey,
1829
1988
  assistantKey: run.assistantKey || null,
1989
+ ...(run.reason==='ADOPTED_IDLE_BASELINE'?{baselineOnly:true}:{}),
1830
1990
  startedAt: run.startedAt
1831
1991
  }).catch(() => null);
1832
1992
  }
@@ -1949,6 +2109,8 @@ const SERIAL_ROUTES=new Map([
1949
2109
  ['CHAT_LOOP_ACTION_TAKE_V1',onTake],
1950
2110
  ['CHAT_LOOP_ACTION_RESULT_V1',onResult],
1951
2111
  ['CHAT_LOOP_HANDOFF_SEND_BEGIN_V1',onHandoffSendBegin],
2112
+ ['CHAT_LOOP_ADOPT_KICKOFF_PREPARE_V1',onAdoptKickoffPrepare],
2113
+ ['CHAT_LOOP_ADOPT_BASELINE_REPAIR_V1',onAdoptBaselineRepair],
1952
2114
  ['CHAT_LOOP_ACTION_MANUAL_REVEAL_V1',onManualReveal],
1953
2115
  ['CHAT_LOOP_ACTION_MANUAL_PREPARE_V1',onManualPrepare],
1954
2116
  ['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 pending Turn after extension Reload.
419
- // Historical DOM by itself never authorizes a new completion event.
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") {
@@ -719,7 +727,10 @@
719
727
  fail("APPROVAL_LAST_TURN_UNVERIFIED");return false;
720
728
  }
721
729
  reply({contract:CONTRACT,status:"VERIFIED",page:path,
722
- 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}:{})});
723
734
  return false;
724
735
  }
725
736
  if (message?.type === "CHAT_LOOP_TURN_VERIFY_V1") {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "manifest_version": 3,
3
3
  "name": "Chat Loop Extension",
4
- "version": "0.3.79",
4
+ "version": "0.3.81",
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.79",
3
+ "version": "0.3.81",
4
4
  "type": "module",
5
5
  "description": "Chat Loop Extension package: nine formal Action pages and its own native CLI bridge",
6
6
  "bin": {