@tomflow/chatloop-extension 0.3.80 → 0.3.82

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" && k !== "adoptBaselineAt")
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)
@@ -254,6 +257,18 @@ async function run() {
254
257
  await chrome.tabs.remove(own.id);
255
258
  return;
256
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
+ }
257
272
  if (!token) {
258
273
  show("VERIFYING", "手动打开 Continue:核对当前已完成的 Turn,并申请单次发送许可。");
259
274
  if(params.has("resumeBlockedAt")){
@@ -1224,6 +1224,77 @@ async function repairUncommittedBlockedRecovery(){
1224
1224
  await saveRun(restored);
1225
1225
  return restored;
1226
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
+ // run.snapshot requires a business checkpoint. A freshly adopted Task has
1254
+ // no checkpoint yet, so use the existing read-only live terminalStatus
1255
+ // which verifies the current bound holder without inventing one.
1256
+ const status=await chrome.runtime.sendNativeMessage(SESSION_HOST,{
1257
+ op:'context-control',command:'run.terminalStatus',args:{}}).catch(()=>null);
1258
+ if(status?.status!=='OK'
1259
+ ||status.result?.runRef!==run.sessionId+':'+run.taskId+':0'
1260
+ ||!Number.isSafeInteger(status.result?.approvalRevision)
1261
+ ||status.result.approvalRevision<1
1262
+ ||status.result?.unknownEffectCount!==0
1263
+ ||status.result?.executionOutcome==='DONE'
1264
+ ||status.result?.deliveryRef)
1265
+ return {status:'DENIED',code:'ADOPT_KICKOFF_CONTEXT_UNVERIFIED'};
1266
+ const exactId=chatIdOf(tab.url);
1267
+ const read=async()=>{
1268
+ const approval=await chrome.tabs.sendMessage(tab.id,{
1269
+ type:'CHAT_LOOP_APPROVAL_EVIDENCE_V1',
1270
+ explicitChatId:exactId,expectedTaskId:run.taskId}).catch(()=>null);
1271
+ const turn=await chrome.tabs.sendMessage(tab.id,{
1272
+ type:'CHAT_LOOP_TURN_VERIFY_V1'}).catch(()=>null);
1273
+ if(approval?.contract!=='chat-loop.turn-observer.v1'
1274
+ ||approval.status!=='VERIFIED'||approval.page!==run.page
1275
+ ||approval.userKey!==run.userKey
1276
+ ||approval.postApprovalAssistantKey!==run.assistantKey
1277
+ ||turn?.contract!=='chat-loop.turn-observer.v1'
1278
+ ||turn.status!=='READY'||turn.page!==run.page
1279
+ ||turn.userKey!==run.userKey||turn.assistantKey!==run.assistantKey
1280
+ ||turn.pendingConfirmation
1281
+ ||globalThis.ChatLoopCoreV1.parseStatus(turn.replyText)!=='UNKNOWN')
1282
+ return null;
1283
+ return {userKey:turn.userKey,assistantKey:turn.assistantKey,
1284
+ replyText:turn.replyText,rVersion:approval.rVersion,pVersion:approval.pVersion};
1285
+ };
1286
+ const first=await read();
1287
+ if(!first)return {status:'DENIED',code:'ADOPT_KICKOFF_APPROVAL_UNVERIFIED'};
1288
+ await new Promise(resolve=>setTimeout(resolve,2300));
1289
+ const second=await read();
1290
+ if(!second||JSON.stringify(first)!==JSON.stringify(second))
1291
+ return {status:'DENIED',code:'ADOPT_KICKOFF_APPROVAL_CHANGED'};
1292
+ const token=crypto.randomUUID();
1293
+ await saveRun({...run,phase:'RESERVED',action:'CONTINUE',token,
1294
+ manualActionTabId:sender.tab.id,
1295
+ recoveryMode:'ADOPT_KICKOFF',kickoffAttempted:true});
1296
+ return {status:'PREPARED',token,tabId:run.tabId};
1297
+ }
1227
1298
  // One-shot recovery of an ALREADY committed same-Chat Adopt whose historical
1228
1299
  // post-approval reply was wrongly classified UNKNOWN. Never writes a composer,
1229
1300
  // retries an action or replaces Context/Owner. Requires exact Native BLOCKED CAS.
@@ -1592,11 +1663,20 @@ async function onTake(message, sender) {
1592
1663
  status:run.action==="HANDOFF"&&run.modelIntent.action==="CONTINUE"
1593
1664
  ?"OVERRIDDEN_BY_DEADLINE":"PENDING"}) : pending);
1594
1665
  if(run.action==="CONTINUE" &&run.contextManaged &&!recoveredContext &&run.retryMode!=="NATIVE"){
1595
- const snapshot=await chrome.runtime.sendNativeMessage(SESSION_HOST,{
1666
+ let snapshot=await chrome.runtime.sendNativeMessage(SESSION_HOST,{
1596
1667
  op:"context-control",command:"run.snapshot",args:{}}).catch(()=>null);
1668
+ // First controlled Continue may precede the FIRST business checkpoint.
1669
+ // Only a proven CHECKPOINT_NOT_FOUND may use the current live task/run
1670
+ // projection. Network errors and all other snapshot failures stay BLOCKED.
1671
+ if(snapshot?.status!=="OK"&&snapshot?.code==="CHECKPOINT_NOT_FOUND")
1672
+ snapshot=await chrome.runtime.sendNativeMessage(SESSION_HOST,{
1673
+ op:"context-control",command:"run.terminalStatus",args:{}}).catch(()=>null);
1597
1674
  const cp=snapshot?.result;
1598
1675
  if(snapshot?.status!=="OK"||!cp ||cp.runRef!==
1599
- run.sessionId+":"+run.taskId+":"+(run.generation||0)){
1676
+ run.sessionId+":"+run.taskId+":"+(run.generation||0)
1677
+ ||!Number.isSafeInteger(cp.taskRevision)||cp.taskRevision<1
1678
+ ||!Number.isSafeInteger(cp.approvalRevision)||cp.approvalRevision<1
1679
+ ||cp.unknownEffectCount!==0||cp.executionOutcome==="DONE"){
1600
1680
  await saveRun({...pending,phase:"BLOCKED",reason:"CONTEXT_CONTINUE_SNAPSHOT_UNVERIFIED"});
1601
1681
  return {status:"DENIED",code:"CONTEXT_CONTINUE_SNAPSHOT_UNVERIFIED"};
1602
1682
  }
@@ -1682,6 +1762,8 @@ async function onTake(message, sender) {
1682
1762
  text: run.action === "HANDOFF" ? run.handoffText || null
1683
1763
  : run.recoveryMode==="TOOL_PREFLIGHT_REPAIRED"
1684
1764
  ? "【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]。"
1765
+ : run.recoveryMode==="ADOPT_KICKOFF"
1766
+ ? "【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]。"
1685
1767
  : run.modelIntent?.action==="CONTINUE" ? (
1686
1768
  "【Chat Loop 续接来源】上一轮由模型登记的 Continue 请求 " + run.modelIntent.id
1687
1769
  + " 已被扩展唯一 Action 领取。\n"
@@ -1785,6 +1867,10 @@ async function onResult(message, sender) {
1785
1867
  }
1786
1868
  // A model prompt is one-shot. Keep only a short receipt, not the prompt
1787
1869
  // body, after the Action has reached a confirmed or blocked terminal state.
1870
+ // The kickoff exception applies to ONE historical P3 reply only.
1871
+ // Remove it after this send attempt; subsequent Continue Turns must carry
1872
+ // ordinary independent terminal markers and never inherit the exception.
1873
+ if(run.recoveryMode==="ADOPT_KICKOFF")delete next.recoveryMode;
1788
1874
  if(run.modelIntent){
1789
1875
  const override=run.action==="HANDOFF"&&run.modelIntent.action==="CONTINUE";
1790
1876
  const finalStatus=confirmed?"SENT_CONFIRMED":"BLOCKED";
@@ -2039,6 +2125,7 @@ const SERIAL_ROUTES=new Map([
2039
2125
  ['CHAT_LOOP_ACTION_TAKE_V1',onTake],
2040
2126
  ['CHAT_LOOP_ACTION_RESULT_V1',onResult],
2041
2127
  ['CHAT_LOOP_HANDOFF_SEND_BEGIN_V1',onHandoffSendBegin],
2128
+ ['CHAT_LOOP_ADOPT_KICKOFF_PREPARE_V1',onAdoptKickoffPrepare],
2042
2129
  ['CHAT_LOOP_ADOPT_BASELINE_REPAIR_V1',onAdoptBaselineRepair],
2043
2130
  ['CHAT_LOOP_ACTION_MANUAL_REVEAL_V1',onManualReveal],
2044
2131
  ['CHAT_LOOP_ACTION_MANUAL_PREPARE_V1',onManualPrepare],
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "manifest_version": 3,
3
3
  "name": "Chat Loop Extension",
4
- "version": "0.3.80",
4
+ "version": "0.3.82",
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.80",
3
+ "version": "0.3.82",
4
4
  "type": "module",
5
5
  "description": "Chat Loop Extension package: nine formal Action pages and its own native CLI bridge",
6
6
  "bin": {