@tomflow/chatloop-extension 0.4.20 → 0.4.21

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.
@@ -195,10 +195,15 @@ async function run(){
195
195
  const intent=proof.intent;
196
196
  let tab,clicked=false;
197
197
  try{
198
- // An entry test may not take over a live managed session or grant itself Owner.
199
- const durable=await chrome.runtime.sendNativeMessage(HOST,{op:'session-read'});
200
- if(durable?.status!=='OK'||durable.session&&!['DONE'].includes(durable.session.phase))
201
- throw Error('ENTRY_TEST_ACTIVE_OWNER');
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);
@@ -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 /需求|范围|验收/.test(text)&&next&&next!==rVersion;
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
- /(?:需求|范围|验收)/.test(text)&&nextR&&nextR!==rVersion
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)
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "manifest_version": 3,
3
3
  "name": "Chat Loop Extension",
4
- "version": "0.4.20",
4
+ "version": "0.4.21",
5
5
  "description": "Chat Loop browser companion: Eye actions, Turn observer, Continue and Handoff Actions",
6
6
  "permissions": [
7
7
  "activeTab",
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomflow/chatloop-extension",
3
- "version": "0.4.20",
3
+ "version": "0.4.21",
4
4
  "type": "module",
5
5
  "description": "Chat Loop Extension: reviewed formal Action pages, including TEST_ONLY native App entry",
6
6
  "bin": {