@tomflow/chatloop-extension 0.4.20 → 0.4.22
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/actions/entry_test.js +10 -4
- package/extension/loop/core.js +1 -1
- package/extension/loop/observer-approval.js +19 -2
- package/extension/manifest.json +1 -1
- package/extension/worker/adopt-prepare.js +11 -3
- package/extension/worker/readiness.js +43 -0
- package/extension/worker/router.js +1 -0
- package/lib/owner-evidence.mjs +6 -2
- package/lib/session-file.mjs +3 -1
- package/package.json +1 -1
|
@@ -195,10 +195,15 @@ async function run(){
|
|
|
195
195
|
const intent=proof.intent;
|
|
196
196
|
let tab,clicked=false;
|
|
197
197
|
try{
|
|
198
|
-
//
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
198
|
+
// This read-only Worker/Native gate may admit a provably frozen orphan
|
|
199
|
+
// for an independent TEST_ONLY Chat; it never releases the old Session.
|
|
200
|
+
const admitted=async()=>{
|
|
201
|
+
const decision=await chrome.runtime.sendMessage({
|
|
202
|
+
type:'CHAT_LOOP_ENTRY_TEST_ADMISSION_V1',requestId:id}).catch(()=>null);
|
|
203
|
+
if(decision?.status!=='OK'||decision.scope!=='TEST_ONLY')
|
|
204
|
+
throw Error(safeCode(decision?.code||'ENTRY_TEST_OWNER_UNVERIFIED'));
|
|
205
|
+
};
|
|
206
|
+
await admitted();
|
|
202
207
|
let result;
|
|
203
208
|
if(intent.verifyChatUrl){
|
|
204
209
|
// Pure receipt recovery. Never click, resend, adopt or modify an existing Chat.
|
|
@@ -214,6 +219,7 @@ async function run(){
|
|
|
214
219
|
windowId:own.windowId,openerTabId:own.id});
|
|
215
220
|
if(!Number.isSafeInteger(tab?.id))throw Error('ENTRY_NEW_TAB_UNVERIFIED');
|
|
216
221
|
await readNewChat(tab.id,intent.recoverTestAt===true,intent.recoverExactDraft||'');
|
|
222
|
+
await admitted(); // Recheck before the only possible first send.
|
|
217
223
|
await nativeMentionAndSend(tab.id,intent.appId,intent.prompt);
|
|
218
224
|
clicked=true;
|
|
219
225
|
result=await verifyNativeUserTurn(tab.id,intent.appId,intent.prompt);
|
package/extension/loop/core.js
CHANGED
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
||proof.status!=='VERIFIED'
|
|
81
81
|
||typeof proof.page!=='string'
|
|
82
82
|
||pathOf('https://chatgpt.com'+proof.page)!==proof.page
|
|
83
|
-
||!/^user:[
|
|
83
|
+
||!/^user:[^\s]{8,}$/.test(proof.userKey||'')
|
|
84
84
|
||!/^R[1-9][0-9]*$/.test(proof.rVersion||'')
|
|
85
85
|
||!/^P[1-9][0-9]*$/.test(proof.pVersion||''))
|
|
86
86
|
return null;
|
|
@@ -141,16 +141,32 @@ if (message?.type === "CHAT_LOOP_APPROVAL_EVIDENCE_V1") {
|
|
|
141
141
|
fail("APPROVAL_REQUIREMENTS_MISSING");return false;
|
|
142
142
|
}
|
|
143
143
|
const rVersion=rAssistant?versionOf(textOf(rAssistant),"R"):nativeRVersion;
|
|
144
|
+
// A stage-02 plan can generate an immutable Rn synchronization SNAPSHOT
|
|
145
|
+
// after its P approval. It is not a new R approval: Context retains the
|
|
146
|
+
// original R/P approvals and exact P.requirementRef. Only a precisely
|
|
147
|
+
// linked notice is exempt from the "new R version" visual alarm.
|
|
148
|
+
const planDerivedSync=text=>{
|
|
149
|
+
const m=text.match(/(?:^|\n)需求文档派生同步[::]\s*(R[1-9][0-9]*)\s*←\s*已批准\s*(P[1-9][0-9]*)[((]保留原批准\s*(R[1-9][0-9]*)[,,]不签发新 R 审批[))]/);
|
|
150
|
+
return Boolean(m&&m[1]!==rVersion&&m[2]===pVersion
|
|
151
|
+
&&m[3]===rVersion
|
|
152
|
+
&&!/(?:REQUIREMENTS_REVIEW|提交需求评审|R[1-9][0-9]*-ISSUE|已撤销|撤销需求|拒绝需求)/i.test(text)
|
|
153
|
+
&&!/(?:^|\n)\s*#{1,6}\s*R[1-9][0-9]*\s+v[1-9][0-9]*/i.test(text));
|
|
154
|
+
};
|
|
144
155
|
const intervening=rows.slice(rIndex+1,lastUser-1);
|
|
145
156
|
const invalidated=intervening.some(x=>{
|
|
146
157
|
const text=textOf(x);
|
|
147
158
|
if(x.role==="assistant"){
|
|
159
|
+
if(/需求文档派生同步/.test(text)&&!planDerivedSync(text))return true;
|
|
148
160
|
const next=versionOf(text,"R");
|
|
149
|
-
return
|
|
161
|
+
return !planDerivedSync(text)&&/需求|范围|验收/.test(text)&&next&&next!==rVersion;
|
|
150
162
|
}
|
|
151
163
|
// Updating a plan while retaining the approved requirement is NOT
|
|
152
164
|
// a requirement revocation.
|
|
153
165
|
// Only an explicit requirement-targeted change invalidates this R.
|
|
166
|
+
const planSyncRequest=(/(?:修改|修订|调整).{0,14}方案.{0,80}(?:同步|更新|改).{0,14}需求/.test(text)
|
|
167
|
+
||/(?:方案|计划|P[1-9][0-9]*).{0,50}(?:同步|更新|修改|调整|改).{0,50}(?:需求|R[1-9][0-9]*)/.test(text))
|
|
168
|
+
&&!/(?:撤销|取消|拒绝|不批准|不同意|不确认)/.test(text);
|
|
169
|
+
if(planSyncRequest)return false;
|
|
154
170
|
return /(?:撤销|取消|拒绝|不同意|不批准|修改|修订|变更)\s*(?:(?:当前|本次|这份|上述)\s*)?(?:需求|R[1-9][0-9]*)/i.test(text)
|
|
155
171
|
|| /\bR[1-9][0-9]*\b\s*(?:需求)?\s*(?:需要|应当|应该)?\s*(?:撤销|取消|拒绝|修改|修订|变更)/i.test(text);
|
|
156
172
|
});
|
|
@@ -174,7 +190,8 @@ if (message?.type === "CHAT_LOOP_APPROVAL_EVIDENCE_V1") {
|
|
|
174
190
|
const text=textOf(x),nextR=versionOf(text,"R"),
|
|
175
191
|
nextP=versionOf(text,"P");
|
|
176
192
|
return Boolean(
|
|
177
|
-
|
|
193
|
+
/需求文档派生同步/.test(text)&&!planDerivedSync(text)
|
|
194
|
+
||!planDerivedSync(text)&&/(?:需求|范围|验收)/.test(text)&&nextR&&nextR!==rVersion
|
|
178
195
|
||/(?:方案|计划)/.test(text)&&nextP&&nextP!==pVersion
|
|
179
196
|
||/(?:SUPERSEDED|已失效|已废弃|已撤销)/i.test(text)
|
|
180
197
|
&&/(?:需求|方案|计划|R[1-9][0-9]*|P[1-9][0-9]*)/i.test(text)
|
package/extension/manifest.json
CHANGED
|
@@ -41,8 +41,14 @@ async function sessionStartPrepare(message,sender){
|
|
|
41
41
|
|| prior.phase==='DONE'&&!terminalFenceVerified(prior)))
|
|
42
42
|
return {status:'DENIED',code:'CONTEXT_TERMINAL_FENCE_UNVERIFIED'};
|
|
43
43
|
const replace=intent.replaceBlockedSessionId||null;
|
|
44
|
+
// Project is shared context, not Task identity. Same-Project replacement
|
|
45
|
+
// requires a freshly approved, Context-backed Adopt into a distinct Task.
|
|
46
|
+
// Legacy sessions without taskId can only yield to that verified new Task.
|
|
47
|
+
const independentTask=Boolean(intent.mode==='adopt'&&intent.contextLeaseRef
|
|
48
|
+
&&intent.taskId && (!prior?.taskId && !prior?.contextManaged
|
|
49
|
+
||prior?.taskId&&prior.taskId!==intent.taskId));
|
|
44
50
|
const matchingBlocked=prior?.phase==='BLOCKED' && prior.sessionId===replace
|
|
45
|
-
&& prior.projectId!==intent.projectId;
|
|
51
|
+
&& (prior.projectId!==intent.projectId || independentTask);
|
|
46
52
|
if(replace&&!matchingBlocked)return {status:'DENIED',code:'BLOCKED_REPLACEMENT_MISMATCH'};
|
|
47
53
|
if(prior&&prior.phase!=='DONE'&&!matchingBlocked)
|
|
48
54
|
return {status:'DENIED',code:'LOOP_ALREADY_ACTIVE'};
|
|
@@ -80,6 +86,8 @@ async function sessionStartPrepare(message,sender){
|
|
|
80
86
|
:await approvedAdoptionTarget(intent.chatUrl||null,
|
|
81
87
|
intent.contextLeaseRef?intent.taskId:null):null;
|
|
82
88
|
if(adoption?.error)return {status:'DENIED',code:adoption.error};
|
|
89
|
+
if(matchingBlocked&&adoption?.target?.page===prior.page&&prior.page)
|
|
90
|
+
return {status:'DENIED',code:'BLOCKED_REPLACEMENT_CHAT_REUSE'};
|
|
83
91
|
// A Project-scoped Chat cannot safely hand off to the ordinary home route:
|
|
84
92
|
// reject BEFORE claiming Owner instead of failing after four hours.
|
|
85
93
|
// Explicit /g/ intent remains Project-scoped even if Chrome aliases the
|
|
@@ -88,8 +96,8 @@ async function sessionStartPrepare(message,sender){
|
|
|
88
96
|
pathOf(intent.chatUrl||'').startsWith('/g/')
|
|
89
97
|
||adoption?.target?.page?.startsWith('/g/')))
|
|
90
98
|
return {status:'DENIED',code:'AUTO_HANDOFF_ROUTE_UNSUPPORTED'};
|
|
91
|
-
//
|
|
92
|
-
//
|
|
99
|
+
// Replacement must not replay the old Task. A new independent Task may
|
|
100
|
+
// share its Project after exact blocked Owner and Context-fence checks.
|
|
93
101
|
const promptDigest=adoption?null:await startPromptFingerprint(intent.prompt);
|
|
94
102
|
const next={sessionId:crypto.randomUUID(),projectId:intent.projectId,
|
|
95
103
|
...(intent.taskId?{taskId:intent.taskId}:{}),
|
|
@@ -102,6 +102,49 @@ async function startReadinessEvidence(run){
|
|
|
102
102
|
pageState:tab.url==='https://chatgpt.com/'?'BLANK_HOME':'CHANGED_UNVERIFIED',
|
|
103
103
|
...(result&&typeof result.mainCount==='number'?{readiness:result}:{})};
|
|
104
104
|
}
|
|
105
|
+
// TEST_ONLY is an independent native @ App first-turn, never a managed Owner.
|
|
106
|
+
// A frozen BLOCKED run with a lost Owner tab must not disable ordinary first-
|
|
107
|
+
// turn testing forever. Keep its Native pointer untouched: this read-only
|
|
108
|
+
// gate checks both authorities and denies any live/unknown Owner transition.
|
|
109
|
+
async function entryTestAdmission(message,sender){
|
|
110
|
+
if(!sessionPage(sender,'entry_test',message.requestId))
|
|
111
|
+
return {status:'DENIED',code:'ENTRY_TEST_SOURCE_UNVERIFIED'};
|
|
112
|
+
const disk=await chrome.runtime.sendNativeMessage(SESSION_HOST,
|
|
113
|
+
{op:'session-read'}).catch(()=>null);
|
|
114
|
+
if(disk?.status!=='OK')return {status:'DENIED',code:'ENTRY_TEST_NATIVE_UNVERIFIED'};
|
|
115
|
+
const run=await readRun(),record=disk.session;
|
|
116
|
+
if(!run?.sessionId){
|
|
117
|
+
return !record||record.phase==='DONE'
|
|
118
|
+
?{status:'OK',scope:'TEST_ONLY'}
|
|
119
|
+
:{status:'DENIED',code:'ENTRY_TEST_OWNER_UNVERIFIED'};
|
|
120
|
+
}
|
|
121
|
+
if(!matchesNativeProjection(sessionProjection(run),record))
|
|
122
|
+
return {status:'DENIED',code:'ENTRY_TEST_OWNER_MISMATCH'};
|
|
123
|
+
if(run.phase==='DONE')
|
|
124
|
+
return !run.contextManaged||run.taskId&&terminalFenceVerified(run)
|
|
125
|
+
?{status:'OK',scope:'TEST_ONLY'}
|
|
126
|
+
:{status:'DENIED',code:'ENTRY_TEST_UNFENCED'};
|
|
127
|
+
if(run.phase!=='BLOCKED'||run.contextManaged&&(!run.taskId||!terminalFenceVerified(run))
|
|
128
|
+
||!Number.isSafeInteger(run.tabId)||!pathOf('https://chatgpt.com'+run.page))
|
|
129
|
+
return {status:'DENIED',code:'ENTRY_TEST_ACTIVE_OWNER'};
|
|
130
|
+
// Chrome may reuse the old numeric tab ID. Even a changed tab is not a
|
|
131
|
+
// verified absence. A new tab showing the same Chat is also a live risk.
|
|
132
|
+
if(await chrome.tabs.get(run.tabId).catch(()=>null))
|
|
133
|
+
return {status:'DENIED',code:'ENTRY_TEST_OWNER_TAB_PRESENT'};
|
|
134
|
+
const existing=await chrome.tabs.query({url:'https://chatgpt.com/*'}).catch(()=>null);
|
|
135
|
+
if(!Array.isArray(existing)
|
|
136
|
+
||existing.some(tab=>chatIdOf(tab.url)===chatIdOf('https://chatgpt.com'+run.page)))
|
|
137
|
+
return {status:'DENIED',code:'ENTRY_TEST_OWNER_REOPENED'};
|
|
138
|
+
const again=await readRun();
|
|
139
|
+
const second=await chrome.runtime.sendNativeMessage(SESSION_HOST,
|
|
140
|
+
{op:'session-read'}).catch(()=>null);
|
|
141
|
+
if(!again||JSON.stringify(again)!==JSON.stringify(run)
|
|
142
|
+
||second?.status!=='OK'||!second.session
|
|
143
|
+
||second.session.updatedAt!==record.updatedAt
|
|
144
|
+
||!matchesNativeProjection(sessionProjection(again),second.session))
|
|
145
|
+
return {status:'DENIED',code:'ENTRY_TEST_OWNER_DRIFT'};
|
|
146
|
+
return {status:'OK',scope:'TEST_ONLY',mode:'FROZEN_BLOCKED_NO_OWNER'};
|
|
147
|
+
}
|
|
105
148
|
async function sessionStatus(message,sender){
|
|
106
149
|
if(!sessionPage(sender,'status',message.requestId))
|
|
107
150
|
return {status:'DENIED',code:'INVALID_STATUS_SOURCE'};
|
|
@@ -68,6 +68,7 @@ const SERIAL_ROUTES=new Map([
|
|
|
68
68
|
['CHAT_LOOP_SESSION_START_TAKE_V1',sessionStartTake],
|
|
69
69
|
['CHAT_LOOP_SESSION_START_RESULT_V1',sessionStartResult],
|
|
70
70
|
['CHAT_LOOP_SESSION_STATUS_V1',sessionStatus],
|
|
71
|
+
['CHAT_LOOP_ENTRY_TEST_ADMISSION_V1',entryTestAdmission],
|
|
71
72
|
['CHAT_LOOP_RESOURCE_CHAT_V1',resourceChatGate]
|
|
72
73
|
|
|
73
74
|
]);
|
package/lib/owner-evidence.mjs
CHANGED
|
@@ -56,8 +56,12 @@ function checkedExtensionIdle(){
|
|
|
56
56
|
*/
|
|
57
57
|
export function verifyOrphanOwnerIdle({oldRunRef,projectId}){
|
|
58
58
|
const native=checkedNative(),extension=checkedExtensionIdle();
|
|
59
|
-
const oldId=oldRunRef.split(':')
|
|
60
|
-
ensure(
|
|
59
|
+
const [oldId,oldTaskId,oldGeneration,...extra]=oldRunRef.split(':');
|
|
60
|
+
ensure(extra.length===0&&oldTaskId&&/^\d+$/.test(oldGeneration),
|
|
61
|
+
'ORPHAN_RUN_REF_INVALID');
|
|
62
|
+
ensure(native.sessionId!==oldId
|
|
63
|
+
&&(native.projectId!==projectId
|
|
64
|
+
||typeof native.taskId==='string'&&native.taskId!==oldTaskId),
|
|
61
65
|
'ORPHAN_OWNER_STILL_CURRENT');
|
|
62
66
|
const live=readSession();
|
|
63
67
|
ensure(live?.phase==='DONE'&&
|
package/lib/session-file.mjs
CHANGED
|
@@ -90,7 +90,9 @@ export function writeSession(input,replaceBlockedSessionId=null,resumeBlockedSes
|
|
|
90
90
|
throw fail('SESSION_REPLACEMENT_MISMATCH');
|
|
91
91
|
if(old&&old.sessionId!==next.sessionId&&old.phase!=='DONE'
|
|
92
92
|
&& !(old.phase==='BLOCKED' && next.phase==='STARTING'
|
|
93
|
-
&& replaceBlockedSessionId===old.sessionId
|
|
93
|
+
&& replaceBlockedSessionId===old.sessionId
|
|
94
|
+
&& (next.projectId!==old.projectId
|
|
95
|
+
||next.taskId!==undefined&&next.taskId!==old.taskId)))
|
|
94
96
|
throw fail('SESSION_ALREADY_ACTIVE');
|
|
95
97
|
if(old&&old.sessionId===next.sessionId){
|
|
96
98
|
if(next.projectId!==old.projectId)throw fail('SESSION_PROJECT_CHANGED');
|