@tomflow/chatloop-extension 0.3.82 → 0.3.84

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.
@@ -39,7 +39,8 @@ process.stdin.on('data',async chunk=>{
39
39
  if(!session?.taskId||!session.sessionId)
40
40
  throw Object.assign(Error('No Context-managed session'),{code:'CONTEXT_SESSION_UNBOUND'});
41
41
  if(!['permit.consume','run.bind.initial','run.fence','run.bind.handoff',
42
- 'run.restore-same-owner','run.fence.terminal','run.terminalStatus','run.snapshot'].includes(m.command)
42
+ 'run.restore-same-owner','run.fence.terminal','run.credential.rotate',
43
+ 'run.terminalStatus','run.snapshot'].includes(m.command)
43
44
  ||!m.args||typeof m.args!=='object'||Array.isArray(m.args))
44
45
  throw Object.assign(Error('Invalid Context command'),{code:'CONTEXT_COMMAND_INVALID'});
45
46
  const own=new Set(['projectId','taskId','sessionId','generation','activeChatId',
@@ -52,7 +53,7 @@ process.stdin.on('data',async chunk=>{
52
53
  activeChatId:session.activeChatId};
53
54
  if(m.command==='run.bind.initial'||m.command==='run.bind.handoff')
54
55
  args.runRef=session.sessionId+':'+session.taskId+':'+session.generation;
55
- if(m.command==='run.fence'||m.command==='run.fence.terminal')
56
+ if(['run.fence','run.fence.terminal','run.credential.rotate'].includes(m.command))
56
57
  args.runRef=session.sessionId+':'+session.taskId+':'+session.generation;
57
58
  const result=await nativeContextControl(m.command,args);
58
59
  write({status:'OK',result});
@@ -120,11 +120,14 @@ async function sendFirst(id,text){
120
120
  // Keep even the worst-case read budget below the 330s Worker watchdog,
121
121
  // including the preceding 90s cold-page readiness window.
122
122
  const deadline=Date.now()+120_000;
123
+ // E15 must verify a single, stable server-backed first user Turn.
124
+ // One transient bubble is not proof that ChatGPT emitted exactly one Turn.
125
+ let candidatePage=null,candidateUserKey=null,stableProbes=0;
123
126
  for(let i=0;i<200&&Date.now()<deadline;i++){
124
127
  const tab=await boundedRead(()=>chrome.tabs.get(id),
125
128
  Math.min(1200,Math.max(1,deadline-Date.now())));
126
129
  const page=tab?.url&&new URL(tab.url).pathname;
127
- if(/^\/c\/[0-9a-f-]{12,}$/i.test(page||'')){
130
+ if(/^\/c\/[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i.test(page||'')){
128
131
  const rows=await boundedRead(()=>chrome.scripting.executeScript({target:{tabId:id},func:expected=>{
129
132
  const visible=e=>Boolean(e?.getClientRects?.().length);
130
133
  const mains=[...document.querySelectorAll('main')].filter(visible);
@@ -133,17 +136,35 @@ async function sendFirst(id,text){
133
136
  const rows=modern.length?modern:[...mains[0].querySelectorAll('[data-message-author-role]')];
134
137
  const role=n=>n.getAttribute('data-message-author-role')
135
138
  ||n.getAttribute('data-chatgpt-search-unit-key')?.split(':').at(-1);
136
- const user=rows.filter(n=>role(n)==='user').at(-1);
137
- const id=user?.getAttribute('data-message-id')
138
- ||user?.getAttribute('data-chatgpt-search-message-ids')?.trim().split(/\s+/)[0];
139
+ const users=rows.filter(n=>role(n)==='user');
140
+ const user=users.at(-1);
141
+ const idOf=node=>node?.getAttribute('data-message-id')
142
+ ||node?.getAttribute('data-chatgpt-search-message-ids')?.trim().split(/\s+/)[0];
143
+ const ids=users.map(idOf);
144
+ const id=idOf(user);
139
145
  const bubble=user?.querySelector('[data-search-result-target]')
140
146
  ||user?.querySelector('[data-user-message-bubble="true"]')||user;
141
147
  const canonical=v=>String(v||'').replace(/\s+/g,'');
142
- return id&&canonical(bubble?.innerText||bubble?.textContent)===canonical(expected)
143
- ?{userKey:'user:'+id}:null;
148
+ return {observedPage:location.pathname,userMessageCount:users.length,
149
+ distinctUserIds:new Set(ids).size,
150
+ userKey:id&&canonical(bubble?.innerText||bubble?.textContent)===canonical(expected)
151
+ ?'user:'+id:null};
144
152
  },args:[text]}),Math.min(1200,Math.max(1,deadline-Date.now())));
145
- if(rows?.[0]?.result?.userKey)return {status:'SENT_CONFIRMED',
146
- newUserKey:rows[0].result.userKey,newPage:page,newTabId:id};
153
+ const evidence=rows?.[0]?.result;
154
+ if(evidence?.observedPage&&evidence.observedPage!==page)
155
+ throw Error('FIRST_SEND_PAGE_DRIFT_UNVERIFIED');
156
+ if(evidence?.userMessageCount>1||evidence?.distinctUserIds>1)
157
+ throw Error('FIRST_SEND_DUPLICATE_UNVERIFIED');
158
+ const exactOne=evidence?.userMessageCount===1
159
+ &&evidence.distinctUserIds===1&&typeof evidence.userKey==='string';
160
+ if(exactOne){
161
+ if(candidatePage===page&&candidateUserKey===evidence.userKey)stableProbes++;
162
+ else {candidatePage=page;candidateUserKey=evidence.userKey;stableProbes=1;}
163
+ // Four independent bounded DOM probes (~1.2s in Chrome). Never
164
+ // claim SENT_CONFIRMED from the first transient matching bubble.
165
+ if(stableProbes>=4)return {status:'SENT_CONFIRMED',
166
+ newUserKey:candidateUserKey,newPage:page,newTabId:id};
167
+ }else if(evidence){candidatePage=null;candidateUserKey=null;stableProbes=0;}
147
168
  }
148
169
  await pause(Math.min(420,Math.max(1,deadline-Date.now())));
149
170
  }
@@ -242,7 +263,8 @@ async function run(){
242
263
  'START_COMPOSER_NOT_EMPTY','START_ACCOUNT_SWITCH_VISIBLE',
243
264
  'FIRST_TURN_OBSERVER_UNAVAILABLE','START_SEND_BUTTON_UNAVAILABLE','START_INPUT_CHANGED',
244
265
  'START_INPUT_UNVERIFIED','START_INPUT_REJECTED',
245
- 'START_CLICK_UNVERIFIED','FIRST_SEND_RECEIPT_UNKNOWN']
266
+ 'START_CLICK_UNVERIFIED','FIRST_SEND_RECEIPT_UNKNOWN',
267
+ 'FIRST_SEND_DUPLICATE_UNVERIFIED','FIRST_SEND_PAGE_DRIFT_UNVERIFIED']
246
268
  .includes(e.message) ? e.message : null;
247
269
  await chrome.runtime.sendMessage({type:'CHAT_LOOP_SESSION_START_RESULT_V1',
248
270
  requestId:id,token:prepared.token,result:'UNVERIFIED',newTabId:newTab?.id,
@@ -383,6 +383,20 @@ async function sessionStartPrepare(message,sender){
383
383
  if(matchingBlocked&&(!disk.session||disk.session.phase!=='BLOCKED'
384
384
  ||disk.session.sessionId!==replace||disk.session.projectId!==prior.projectId))
385
385
  return {status:'DENIED',code:'SESSION_REPLACEMENT_MISMATCH'};
386
+ // An abandoned Managed Context writer can outlive its Browser Owner.
387
+ // Replacing the Native session without first verifying its terminal fence
388
+ // would strand a live runRef (and an old write credential) in the Store.
389
+ // Never make that replacement based solely on BLOCKED or absent Owner.
390
+ if(matchingBlocked&&prior.contextManaged){
391
+ const terminal=await chrome.runtime.sendNativeMessage(SESSION_HOST,{
392
+ op:'context-control',command:'run.terminalStatus',args:{}}).catch(()=>null);
393
+ const state=terminal?.result;
394
+ if(terminal?.status!=='OK'||!state
395
+ ||state.projectId!==prior.projectId||state.taskId!==prior.taskId
396
+ ||state.runRef!==null||state.executionOutcome!=='DONE'
397
+ ||typeof state.deliveryRef!=='string'||!state.deliveryRef)
398
+ return {status:'DENIED',code:'CONTEXT_BLOCKED_RUN_UNFENCED'};
399
+ }
386
400
  if(disk.session&&disk.session.phase!=='DONE'&&!matchingBlocked)
387
401
  return {status:'DENIED',code:'SESSION_ALREADY_ACTIVE'};
388
402
  const capacity=await resources.admit(prior,{kind:intent.mode==='adopt'?'action':'chat'});
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "manifest_version": 3,
3
3
  "name": "Chat Loop Extension",
4
- "version": "0.3.82",
4
+ "version": "0.3.84",
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.82",
3
+ "version": "0.3.84",
4
4
  "type": "module",
5
5
  "description": "Chat Loop Extension package: nine formal Action pages and its own native CLI bridge",
6
6
  "bin": {