@tomflow/chatloop-extension 0.3.80 → 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" && 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,70 @@ 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
+ 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
+ }
1227
1291
  // One-shot recovery of an ALREADY committed same-Chat Adopt whose historical
1228
1292
  // post-approval reply was wrongly classified UNKNOWN. Never writes a composer,
1229
1293
  // retries an action or replaces Context/Owner. Requires exact Native BLOCKED CAS.
@@ -1682,6 +1746,8 @@ async function onTake(message, sender) {
1682
1746
  text: run.action === "HANDOFF" ? run.handoffText || null
1683
1747
  : run.recoveryMode==="TOOL_PREFLIGHT_REPAIRED"
1684
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]。"
1685
1751
  : run.modelIntent?.action==="CONTINUE" ? (
1686
1752
  "【Chat Loop 续接来源】上一轮由模型登记的 Continue 请求 " + run.modelIntent.id
1687
1753
  + " 已被扩展唯一 Action 领取。\n"
@@ -1785,6 +1851,10 @@ async function onResult(message, sender) {
1785
1851
  }
1786
1852
  // A model prompt is one-shot. Keep only a short receipt, not the prompt
1787
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;
1788
1858
  if(run.modelIntent){
1789
1859
  const override=run.action==="HANDOFF"&&run.modelIntent.action==="CONTINUE";
1790
1860
  const finalStatus=confirmed?"SENT_CONFIRMED":"BLOCKED";
@@ -2039,6 +2109,7 @@ const SERIAL_ROUTES=new Map([
2039
2109
  ['CHAT_LOOP_ACTION_TAKE_V1',onTake],
2040
2110
  ['CHAT_LOOP_ACTION_RESULT_V1',onResult],
2041
2111
  ['CHAT_LOOP_HANDOFF_SEND_BEGIN_V1',onHandoffSendBegin],
2112
+ ['CHAT_LOOP_ADOPT_KICKOFF_PREPARE_V1',onAdoptKickoffPrepare],
2042
2113
  ['CHAT_LOOP_ADOPT_BASELINE_REPAIR_V1',onAdoptBaselineRepair],
2043
2114
  ['CHAT_LOOP_ACTION_MANUAL_REVEAL_V1',onManualReveal],
2044
2115
  ['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.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.80",
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": {