@tomflow/chatloop-extension 0.3.81 → 0.3.83
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/bin/native-host.mjs +3 -2
- package/extension/actions/start.js +31 -9
- package/extension/background.js +23 -7
- package/extension/manifest.json +1 -1
- package/package.json +1 -1
package/bin/native-host.mjs
CHANGED
|
@@ -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.
|
|
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(
|
|
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
|
|
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
|
|
137
|
-
const
|
|
138
|
-
|
|
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
|
|
143
|
-
|
|
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
|
-
|
|
146
|
-
|
|
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,
|
package/extension/background.js
CHANGED
|
@@ -1250,11 +1250,18 @@ async function onAdoptKickoffPrepare(message,sender){
|
|
|
1250
1250
|
||disk.session.phase!=='WAITING_REPLY'
|
|
1251
1251
|
||disk.session.updatedAt!==message.nativeUpdatedAt)
|
|
1252
1252
|
return {status:'DENIED',code:'ADOPT_KICKOFF_NATIVE_CHANGED'};
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
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)
|
|
1258
1265
|
return {status:'DENIED',code:'ADOPT_KICKOFF_CONTEXT_UNVERIFIED'};
|
|
1259
1266
|
const exactId=chatIdOf(tab.url);
|
|
1260
1267
|
const read=async()=>{
|
|
@@ -1656,11 +1663,20 @@ async function onTake(message, sender) {
|
|
|
1656
1663
|
status:run.action==="HANDOFF"&&run.modelIntent.action==="CONTINUE"
|
|
1657
1664
|
?"OVERRIDDEN_BY_DEADLINE":"PENDING"}) : pending);
|
|
1658
1665
|
if(run.action==="CONTINUE" &&run.contextManaged &&!recoveredContext &&run.retryMode!=="NATIVE"){
|
|
1659
|
-
|
|
1666
|
+
let snapshot=await chrome.runtime.sendNativeMessage(SESSION_HOST,{
|
|
1660
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);
|
|
1661
1674
|
const cp=snapshot?.result;
|
|
1662
1675
|
if(snapshot?.status!=="OK"||!cp ||cp.runRef!==
|
|
1663
|
-
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"){
|
|
1664
1680
|
await saveRun({...pending,phase:"BLOCKED",reason:"CONTEXT_CONTINUE_SNAPSHOT_UNVERIFIED"});
|
|
1665
1681
|
return {status:"DENIED",code:"CONTEXT_CONTINUE_SNAPSHOT_UNVERIFIED"};
|
|
1666
1682
|
}
|
package/extension/manifest.json
CHANGED