@tomflow/chatloop-extension 0.3.63 → 0.3.65

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.
package/README.md CHANGED
@@ -8,7 +8,11 @@
8
8
 
9
9
  **0.3.62 Handoff 门禁修复(源码候选,未安装)**:Handoff 新 Chat 的只读编辑器就绪等待从历史最长约 234 秒收紧至最多 100×450ms≈45 秒,避免在前置旧 Chat 核验已耗时的情况下撞上 Worker 330 秒未知结果看门狗。编辑器不就绪会以 `NEW_CHAT_NOT_READY` 提交原 Action 的终态 BLOCKED 回执,不点击发送、不重试、不删除已创建的接班标签。已有 Status 只在原 Native/Worker Owner 精确一致且旧 Handoff BLOCKED 时,额外回报从旧 `chat-loop.resources.v1` **纯只读**匹配的 `diagnostics.handoffTabEvidence`(`tabId/recorded/confirmed=false/pageState/sendReceipt=UNVERIFIED`),不触发资源 reconcile、发送或 Owner 变更。候选通过离线单测不代表旧 `ACTION_RESULT_TIMEOUT_UNVERIFIED` 已得到 `NOT_SENT` 证明,旧版会话不自动恢复。
10
10
 
11
- **0.3.63 Handoff API 悬挂保护(源码候选)**:即使 `chrome.tabs.get` 或仅用于新 Chat 就绪检查的 `chrome.scripting.executeScript` 永不 settle,现有 `waitForNewChat` 也会对只读 probe 设置有界 Promise 竞争与整体 45 秒墙钟上限;任何无法确认准备完成的路径返回 `NEW_CHAT_NOT_READY`,不触发 composer 写入、发送或第二次建 Chat。和 0.3.62 旧本地候选同为未发布候选,本次以 0.3.63 唯一归档继续验收。
11
+ **0.3.63 Handoff API 悬挂保护(已发行历史版本)**:即使 `chrome.tabs.get` 或仅用于新 Chat 就绪检查的 `chrome.scripting.executeScript` 永不 settle,现有 `waitForNewChat` 也会对只读 probe 设置有界 Promise 竞争与整体 45 秒墙钟上限;任何无法确认准备完成的路径返回 `NEW_CHAT_NOT_READY`,不触发 composer 写入、发送或第二次建 Chat。和 0.3.62 旧本地候选同为未发布候选,本次以 0.3.63 唯一归档继续验收。
12
+
13
+ **0.3.64 Start 只读等待收敛(新增发行候选)**:真实 Chrome 的一次 Start 在先收到失败的替换回执后,Native 却登记了新 Session PENDING、无 Chat ID;后续 330 秒 watchdog 把同一 Start 标成 `ACTION_RESULT_TIMEOUT_UNVERIFIED`。因缺原始用户消息回执,不能断言尚未发送。本版本收敛 Start 新 Chat 的 HOME 检查、编辑器就绪和 Observer 检查:保留超过 35 秒的慢页面能力,整体准备墙钟限约 90 秒;Chrome 只读 Promise 不响应时及时结束为明确故障,严格保留一次建页/一次发送;发送动作及发送后回执仍不自动重试。新增 Chrome 读 API 永不返回的回归反例。此改动不能追认旧 UNKNOWN,也不等于真实 Chrome E2E PASS。
14
+
15
+ **0.3.65 Start 只读诊断(源码候选)**:当真实 Chrome Start 创建了首页标签,但返回 `NEW_CHAT_NOT_READY` 时,Status 读取精确 Session 的未确认标签资源;经原 Native Session 一致性校验,仅返回当前 URL 类型、DOM 加载阶段、可见 main 数、输入框数量/可见性/编辑性/空状态及消息节点数量,**不读取消息正文、不点击、不重新发送、不转移 Owner**。此诊断用于区分页面未水合与选择器失效,不能把该状态当作 `NOT_SENT`。专项回归测试对未知 Tab 和跨 Session 标签均拒绝归属。
12
16
 
13
17
  **验收边界**:离线源码回归不等于已安装 Chrome 真机通过;正式安装包的 Owner、资源配额及受控发送需要独立实测,不能用旧版证据替代。
14
18
 
@@ -2,21 +2,32 @@
2
2
  // All subsequent turns are owned by the existing Observer / Continue / Handoff flow.
3
3
  const info=document.getElementById('details'),label=document.getElementById('status');
4
4
  const pause=ms=>new Promise(resolve=>setTimeout(resolve,ms));
5
+ // Timeout only read-only Chrome probes. Never race/retry a composer write or click.
6
+ const boundedRead=(call,ms)=>Promise.race([
7
+ Promise.resolve().then(call).catch(()=>null),
8
+ pause(Math.max(1,ms)).then(()=>null)
9
+ ]);
5
10
  const show=(s,d)=>{label.textContent=s;info.textContent=d;document.body.dataset.result=s==='SUCCESS'?'success':'error';};
6
11
  const host='com.tomflow.chatloop.extension';
7
12
  async function waitForHomeUrl(id){
8
- for(let i=0;i<40;i++){
9
- const tab=await chrome.tabs.get(id).catch(()=>null);
13
+ const deadline=Date.now()+12_000;
14
+ for(let i=0;i<40 && Date.now()<deadline;i++){
15
+ const tab=await boundedRead(()=>chrome.tabs.get(id),
16
+ Math.min(1200,deadline-Date.now()));
10
17
  if(tab?.url==='https://chatgpt.com/')return;
11
- await pause(250);
18
+ await pause(Math.min(250,Math.max(1,deadline-Date.now())));
12
19
  }
13
20
  throw Error('START_HOME_URL_UNVERIFIED');
14
21
  }
15
22
  async function newChatReady(id){
16
- for(let i=0;i<520;i++){
17
- const tab=await chrome.tabs.get(id).catch(()=>null);
23
+ // Preserve 35s+ cold hydration but return well before the Worker watchdog.
24
+ // A never-settling Chrome read must not leave Start PENDING indefinitely.
25
+ const deadline=Date.now()+90_000;
26
+ for(let i=0;i<200 && Date.now()<deadline;i++){
27
+ const tab=await boundedRead(()=>chrome.tabs.get(id),
28
+ Math.min(1500,deadline-Date.now()));
18
29
  if(tab?.url==='https://chatgpt.com/'){
19
- const [found]=await chrome.scripting.executeScript({target:{tabId:id},func:()=>{
30
+ const result=await boundedRead(()=>chrome.scripting.executeScript({target:{tabId:id},func:()=>{
20
31
  const visible=e=>Boolean(e?.getClientRects?.().length);
21
32
  const mains=[...document.querySelectorAll('main')].filter(visible);
22
33
  const editor=document.querySelector('[contenteditable="true"][data-composer-markdown]')
@@ -24,22 +35,25 @@ async function newChatReady(id){
24
35
  return location.origin==='https://chatgpt.com'&&location.pathname==='/'&&mains.length===1
25
36
  &&visible(editor)&&!(editor.innerText||editor.textContent||'').trim()
26
37
  &&!mains[0].querySelector('[data-chatgpt-search-message-ids],[data-message-author-role]');
27
- }}).catch(()=>[]);
28
- if(found?.result===true)return;
29
- // A newly opened ChatGPT home may hydrate slowly; never fail at 6 seconds.
30
- // Security interstitials may outlast 2 minutes; wait up to ~218 seconds without sending.
38
+ }}),Math.min(1500,deadline-Date.now()));
39
+ if(result?.[0]?.result===true)return;
31
40
  }
32
- await pause(420);
41
+ await pause(Math.min(420,Math.max(1,deadline-Date.now())));
33
42
  }
34
43
  throw Error('NEW_CHAT_NOT_READY');
35
44
  }
36
45
  async function observerReady(id){
37
- let proof=await chrome.tabs.sendMessage(id,{type:'CHAT_LOOP_TURN_OBSERVE_V1'}).catch(()=>null);
46
+ let proof=await boundedRead(()=>chrome.tabs.sendMessage(id,
47
+ {type:'CHAT_LOOP_TURN_OBSERVE_V1'}),3000);
38
48
  if(proof?.contract!=='chat-loop.turn-observer.v1'){
39
- await chrome.scripting.executeScript({target:{tabId:id},files:['content.js','loop/observer.js']});
40
- proof=await chrome.tabs.sendMessage(id,{type:'CHAT_LOOP_TURN_OBSERVE_V1'}).catch(()=>null);
49
+ const injected=await boundedRead(()=>chrome.scripting.executeScript({
50
+ target:{tabId:id},files:['content.js','loop/observer.js']}),3000);
51
+ if(!injected)throw Error('FIRST_TURN_OBSERVER_UNAVAILABLE');
52
+ proof=await boundedRead(()=>chrome.tabs.sendMessage(id,
53
+ {type:'CHAT_LOOP_TURN_OBSERVE_V1'}),3000);
41
54
  }
42
- if(proof?.contract!=='chat-loop.turn-observer.v1')throw Error('FIRST_TURN_OBSERVER_UNAVAILABLE');
55
+ if(proof?.contract!=='chat-loop.turn-observer.v1')
56
+ throw Error('FIRST_TURN_OBSERVER_UNAVAILABLE');
43
57
  }
44
58
  async function sendFirst(id,text){
45
59
  const [clicked]=await chrome.scripting.executeScript({target:{tabId:id},
@@ -567,6 +567,44 @@ async function handoffTabEvidence(run){
567
567
  pageState:tab.url==="https://chatgpt.com/"?"BLANK_HOME":"CHANGED_UNVERIFIED",
568
568
  sendReceipt:"UNVERIFIED"};
569
569
  }
570
+ // Read-only diagnosis for a START that created an unconfirmed Chat home.
571
+ // Never infers a send receipt, creates a tab, reads message text, or changes Owner.
572
+ async function startReadinessEvidence(run){
573
+ if(run?.phase!=='BLOCKED'||run.action!=='START'||!run.sessionId
574
+ ||!Number.isSafeInteger(run.attemptedNewTabId))return null;
575
+ const saved=(await chrome.storage.local.get(resources.KEY).catch(()=>null))
576
+ ?.[resources.KEY];
577
+ const candidates=Array.isArray(saved?.entries)?saved.entries.filter(entry=>
578
+ entry?.kind==='chat'&&entry.confirmed===false
579
+ &&entry.sessionId===run.sessionId&&entry.id===run.attemptedNewTabId):[];
580
+ if(candidates.length!==1)return null;
581
+ const tab=await Promise.race([
582
+ chrome.tabs.get(run.attemptedNewTabId).catch(()=>null),
583
+ new Promise(resolve=>setTimeout(()=>resolve(null),1500))
584
+ ]);
585
+ if(!tab||typeof tab.url!=='string'||!tab.url.startsWith('https://chatgpt.com/'))
586
+ return null;
587
+ const result=await Promise.race([
588
+ chrome.scripting.executeScript({target:{tabId:tab.id},func:()=>{
589
+ const visible=e=>Boolean(e?.getClientRects?.().length);
590
+ const mains=[...document.querySelectorAll('main')].filter(visible);
591
+ const editors=[...document.querySelectorAll(
592
+ '[contenteditable="true"][data-composer-markdown],#prompt-textarea[contenteditable="true"]')];
593
+ const editor=editors.find(visible);
594
+ const messages=mains.flatMap(m=>[...m.querySelectorAll(
595
+ '[data-chatgpt-search-message-ids],[data-message-author-role]')]);
596
+ return {path:location.pathname,readyState:document.readyState,
597
+ mainCount:mains.length,editorCount:editors.length,
598
+ editorVisible:Boolean(editor),editorEditable:Boolean(editor?.isContentEditable),
599
+ editorEmpty:editor?!(editor.innerText||editor.textContent||'').trim():null,
600
+ messageNodeCount:messages.length};
601
+ }}).then(rows=>rows?.[0]?.result||null).catch(()=>null),
602
+ new Promise(resolve=>setTimeout(()=>resolve(null),1500))
603
+ ]);
604
+ return {tabId:tab.id,confirmed:false,sendReceipt:'UNVERIFIED',
605
+ pageState:tab.url==='https://chatgpt.com/'?'BLANK_HOME':'CHANGED_UNVERIFIED',
606
+ ...(result&&typeof result.mainCount==='number'?{readiness:result}:{})};
607
+ }
570
608
  async function sessionStatus(message,sender){
571
609
  if(!sessionPage(sender,'status',message.requestId))
572
610
  return {status:'DENIED',code:'INVALID_STATUS_SOURCE'};
@@ -599,9 +637,12 @@ async function sessionStatus(message,sender){
599
637
  // Native's durable CAS revision. Never report a synthetic timestamp as a
600
638
  // usable recovery credential.
601
639
  const tabEvidence=await handoffTabEvidence(run);
640
+ const startEvidence=await startReadinessEvidence(run);
602
641
  return {status:'OK',state:run.phase==='BLOCKED'?'BLOCKED':'ACTIVE',session:disk.session,
603
642
  diagnostics:{extensionVersion:chrome.runtime.getManifest?.().version||null,
604
643
  ...(tabEvidence?{handoffTabEvidence:tabEvidence}:{}),
644
+ ...(startEvidence?{startReadinessEvidence:startEvidence}:{}),
645
+ ...(run.lastStartFailureCode?{lastStartFailureCode:run.lastStartFailureCode}:{}),
605
646
  // The numeric tab ID is a locator, never a send capability. Expose only
606
647
  // for an exactly verified terminal/awaiting Owner, not a guessed tab.
607
648
  ownerTabId:['WAITING_REPLY','BLOCKED'].includes(run.phase)?run.tabId:null,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "manifest_version": 3,
3
3
  "name": "Chat Loop Extension",
4
- "version": "0.3.63",
4
+ "version": "0.3.65",
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.63",
3
+ "version": "0.3.65",
4
4
  "type": "module",
5
5
  "description": "Chat Loop Extension package: nine formal Action pages and its own native CLI bridge",
6
6
  "bin": {