@tomflow/chatloop-extension 0.4.39 → 0.4.40
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/extension/background.js
CHANGED
|
@@ -8,6 +8,7 @@ importScripts("worker/bootstrap.js");
|
|
|
8
8
|
importScripts("worker/admission.js");
|
|
9
9
|
importScripts("worker/adopt-prepare.js");
|
|
10
10
|
importScripts("worker/adopt-result.js");
|
|
11
|
+
importScripts("worker/task-start-evidence-v2.js");
|
|
11
12
|
importScripts("worker/task-start-v2.js");
|
|
12
13
|
importScripts("worker/task-intent-v2.js");
|
|
13
14
|
importScripts("worker/task-intent-dispatch-v2.js");
|
package/extension/manifest.json
CHANGED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// Task-first Start only: read-only approval evidence and bounded Observer reconnect.
|
|
2
|
+
async function scopedStartEvidence(intent){
|
|
3
|
+
const page=pathOf(intent.chatUrl),chatId=chatIdOf(intent.chatUrl);
|
|
4
|
+
scopedStartAssert(page&&chatId,'SCOPED_ADOPTION_URL_INVALID');
|
|
5
|
+
// Never implicitly open/select the latest Chat, including across Projects.
|
|
6
|
+
const tabs=await chrome.tabs.query({url:'https://chatgpt.com/*'});
|
|
7
|
+
const matches=tabs.filter(t=>Number.isSafeInteger(t.id)
|
|
8
|
+
&&pathOf(t.url)===page);
|
|
9
|
+
scopedStartAssert(matches.length===1,'SCOPED_ADOPTION_CHAT_UNVERIFIED');
|
|
10
|
+
const tab=matches[0];
|
|
11
|
+
const observe=()=>chrome.tabs.sendMessage(tab.id,{
|
|
12
|
+
type:'CHAT_LOOP_APPROVAL_EVIDENCE_V1',explicitChatId:chatId
|
|
13
|
+
}).catch(()=>null);
|
|
14
|
+
let first=await observe();
|
|
15
|
+
if(!first){
|
|
16
|
+
// Reload invalidates the old content-script connection. Reinject only
|
|
17
|
+
// the existing read-only Observer in the exact, already-open Chat.
|
|
18
|
+
const current=await chrome.tabs.get(tab.id).catch(()=>null);
|
|
19
|
+
scopedStartAssert(current&&pathOf(current.url)===page,
|
|
20
|
+
'SCOPED_ADOPTION_TAB_CHANGED');
|
|
21
|
+
const files=['content.js','loop/core.js','loop/observer-inspect.js',
|
|
22
|
+
'loop/observer-poll.js','loop/observer-recovery.js',
|
|
23
|
+
'loop/observer-approval.js','loop/observer.js'];
|
|
24
|
+
const loaded=await chrome.scripting.executeScript({
|
|
25
|
+
target:{tabId:tab.id,allFrames:false},files
|
|
26
|
+
}).catch(()=>null);
|
|
27
|
+
scopedStartAssert(Array.isArray(loaded)&&loaded.length===1
|
|
28
|
+
&&loaded[0].frameId===0,
|
|
29
|
+
'SCOPED_ADOPTION_OBSERVER_RECONNECT_FAILED');
|
|
30
|
+
const after=await chrome.tabs.get(tab.id).catch(()=>null);
|
|
31
|
+
scopedStartAssert(after&&pathOf(after.url)===page,
|
|
32
|
+
'SCOPED_ADOPTION_TAB_CHANGED');
|
|
33
|
+
first=await observe();
|
|
34
|
+
}
|
|
35
|
+
const candidate=policy.normalizeAdoptionEvidence(first,{page});
|
|
36
|
+
scopedStartAssert(candidate,'SCOPED_ADOPTION_APPROVAL_UNVERIFIED');
|
|
37
|
+
const second=await observe();
|
|
38
|
+
scopedStartAssert(policy.sameAdoptionEvidence(candidate,
|
|
39
|
+
policy.normalizeAdoptionEvidence(second,{page})),
|
|
40
|
+
'SCOPED_ADOPTION_APPROVAL_CHANGED');
|
|
41
|
+
const source=second?.approvalTurns;
|
|
42
|
+
scopedStartAssert(source&&typeof source==='object'
|
|
43
|
+
&&typeof source.rUserText==='string'&&source.rUserText.length>0
|
|
44
|
+
&&source.rUserText.length<=1000
|
|
45
|
+
&&typeof source.pUserText==='string'&&source.pUserText.length>0
|
|
46
|
+
&&source.pUserText.length<=1000
|
|
47
|
+
&&/^user:[^\s]{8,}$/.test(source.rUserKey||'')
|
|
48
|
+
&&source.rUserKey!==candidate.userKey,
|
|
49
|
+
'SCOPED_ADOPTION_SOURCE_UNVERIFIED');
|
|
50
|
+
const fresh=await chrome.tabs.get(tab.id).catch(()=>null);
|
|
51
|
+
scopedStartAssert(fresh&&pathOf(fresh.url)===page,
|
|
52
|
+
'SCOPED_ADOPTION_TAB_CHANGED');
|
|
53
|
+
return {tabId:tab.id,chatId,page,
|
|
54
|
+
evidence:candidate,approvalEvidence:{
|
|
55
|
+
rUserText:source.rUserText,rUserKey:source.rUserKey,
|
|
56
|
+
rVersion:candidate.rVersion,
|
|
57
|
+
pUserText:source.pUserText,pUserKey:candidate.userKey,
|
|
58
|
+
pVersion:candidate.pVersion}};
|
|
59
|
+
}
|
|
@@ -41,44 +41,6 @@ async function scopedStartIntent(message,sender){
|
|
|
41
41
|
'SCOPED_START_INTENT_UNVERIFIED');
|
|
42
42
|
return {requestId:id,intent,actionTabId:sender.tab.id};
|
|
43
43
|
}
|
|
44
|
-
async function scopedStartEvidence(intent){
|
|
45
|
-
const page=pathOf(intent.chatUrl),chatId=chatIdOf(intent.chatUrl);
|
|
46
|
-
scopedStartAssert(page&&chatId,'SCOPED_ADOPTION_URL_INVALID');
|
|
47
|
-
// Never implicitly open/select the latest Chat, including across Projects.
|
|
48
|
-
const tabs=await chrome.tabs.query({url:'https://chatgpt.com/*'});
|
|
49
|
-
const matches=tabs.filter(t=>Number.isSafeInteger(t.id)
|
|
50
|
-
&&pathOf(t.url)===page);
|
|
51
|
-
scopedStartAssert(matches.length===1,'SCOPED_ADOPTION_CHAT_UNVERIFIED');
|
|
52
|
-
const tab=matches[0];
|
|
53
|
-
const observe=()=>chrome.tabs.sendMessage(tab.id,{
|
|
54
|
-
type:'CHAT_LOOP_APPROVAL_EVIDENCE_V1',explicitChatId:chatId
|
|
55
|
-
}).catch(()=>null);
|
|
56
|
-
const first=await observe();
|
|
57
|
-
const candidate=policy.normalizeAdoptionEvidence(first,{page});
|
|
58
|
-
scopedStartAssert(candidate,'SCOPED_ADOPTION_APPROVAL_UNVERIFIED');
|
|
59
|
-
const second=await observe();
|
|
60
|
-
scopedStartAssert(policy.sameAdoptionEvidence(candidate,
|
|
61
|
-
policy.normalizeAdoptionEvidence(second,{page})),
|
|
62
|
-
'SCOPED_ADOPTION_APPROVAL_CHANGED');
|
|
63
|
-
const source=second?.approvalTurns;
|
|
64
|
-
scopedStartAssert(source&&typeof source==='object'
|
|
65
|
-
&&typeof source.rUserText==='string'&&source.rUserText.length>0
|
|
66
|
-
&&source.rUserText.length<=1000
|
|
67
|
-
&&typeof source.pUserText==='string'&&source.pUserText.length>0
|
|
68
|
-
&&source.pUserText.length<=1000
|
|
69
|
-
&&/^user:[^\s]{8,}$/.test(source.rUserKey||'')
|
|
70
|
-
&&source.rUserKey!==candidate.userKey,
|
|
71
|
-
'SCOPED_ADOPTION_SOURCE_UNVERIFIED');
|
|
72
|
-
const fresh=await chrome.tabs.get(tab.id).catch(()=>null);
|
|
73
|
-
scopedStartAssert(fresh&&pathOf(fresh.url)===page,
|
|
74
|
-
'SCOPED_ADOPTION_TAB_CHANGED');
|
|
75
|
-
return {tabId:tab.id,chatId,page,
|
|
76
|
-
evidence:candidate,approvalEvidence:{
|
|
77
|
-
rUserText:source.rUserText,rUserKey:source.rUserKey,
|
|
78
|
-
rVersion:candidate.rVersion,
|
|
79
|
-
pUserText:source.pUserText,pUserKey:candidate.userKey,
|
|
80
|
-
pVersion:candidate.pVersion}};
|
|
81
|
-
}
|
|
82
44
|
const scopedStartRecord=(scope,phase,chatId=null)=>({
|
|
83
45
|
projectId:scope.projectId,taskId:scope.taskId,sessionId:scope.sessionId,
|
|
84
46
|
generation:0,phase,activeChatId:chatId,
|