@tomflow/chatloop-extension 0.4.44 → 0.4.46

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/README.md CHANGED
@@ -114,6 +114,7 @@ handlers and existing trust boundaries. New send/Owner/Native mutation
114
114
  requires a separate authorized security review and implementation; it cannot
115
115
  be enabled by dropping in a capability file. Browser read actions never
116
116
  clear an unknown send result or adopt a different Chat Owner.
117
+ When a separate Task is frozen by a pending cancel, TEST_ONLY entry may proceed only after the Worker and Native both prove BLOCKED for the exact Task/Session, the original Chat tab is absent, and two reads confirm the Native fence is unchanged; the frozen Task, bound Context Writer and recovery request remain untouched. Unverified or live send-capable Owners still deny the test entry.
117
118
  Screenshot uses Chrome `captureVisibleTab` with the existing per-tab user
118
119
  invocation (`activeTab`) or already granted capture permission; opening an
119
120
  Action page programmatically does not itself grant this permission. Missing
@@ -33,17 +33,31 @@ if (message?.type === "CHAT_LOOP_APPROVAL_EVIDENCE_V1") {
33
33
  return null;
34
34
  const formId=lines[1].slice('formId:'.length).trim().toLowerCase();
35
35
  const traceRef=lines[2].slice('traceRef:'.length).trim().toLowerCase();
36
- const oldLabel=lines[4].match(/^选项标签:\s*A[||]\s*确认当前\s*([RP][1-9][0-9]*)\s*(需求|技术与验证方案|技术方案|方案)$/i);
36
+ const oldLabel=lines[4].match(/^选项标签:\s*A[||]\s*确认(?:当前\s*)?([RP][1-9][0-9]*)\s*(需求|技术与验证方案|技术方案|方案)$/i);
37
37
  const modernLabel=lines[3]==='选项值: approve'
38
38
  &&/^选项标签:\s*A[||]\s*确认(需求|技术与验证方案|技术方案|方案)$/.exec(lines[4]);
39
+ // The visible "P2 final revision" is a semantic review cycle.
40
+ // The stored document can be P1 V3 after a cancelled V2; only the
41
+ // explicit physical V3 may become the trusted approval version P3.
42
+ const revisionLabel=lines[4].match(
43
+ /^选项标签:\s*A[||]\s*确认(?:当前\s*)?([RP][1-9][0-9]*)\s*V([1-9][0-9]*)[((]\s*([RP][1-9][0-9]*)\s*(?:最终)?修订稿[))]$/i);
44
+ const physical=Number(revisionLabel?.[2]||0);
45
+ const semantic=Number(revisionLabel?.[3]?.slice(1)||0);
46
+ const revised=revisionLabel&&revisionLabel[1].toUpperCase()===type+'1'
47
+ &&physical>=2&&revisionLabel[3][0].toUpperCase()===type
48
+ &&semantic>=2&&semantic<=physical;
39
49
  const versions=[...formId.matchAll(/(?:^|[-_])([rp][1-9][0-9]*)(?=[-_]|$)/gi)]
40
50
  .map(m=>m[1].toUpperCase());
41
- const version=oldLabel?.[1].toUpperCase()
51
+ const version=oldLabel?.[1]?.toUpperCase()
52
+ ||(revised?type+String(physical):null)
42
53
  ||(modernLabel&&versions.length===1?versions[0]:null);
43
- const label=oldLabel?.[2]||modernLabel?.[1];
54
+ const label=oldLabel?.[2]
55
+ ||(revised?(type==='R'?'需求':'方案'):modernLabel?.[1]);
44
56
  if(!version||version[0]!==type||!label
45
57
  ||(type==='R')!==(label==='需求')
46
- ||(oldLabel&&versions.length>0&&versions.some(v=>v!==version))
58
+ ||(oldLabel&&versions.some(v=>v!==version))
59
+ ||revised&&versions.some(v=>v!==type+'1'&&v!==version
60
+ &&v!==revisionLabel[3].toUpperCase())
47
61
  ||formId===traceRef)return null;
48
62
  return {version,formId,traceRef};
49
63
  };
@@ -90,6 +104,17 @@ if (message?.type === "CHAT_LOOP_APPROVAL_EVIDENCE_V1") {
90
104
  // Prefer an explicit current-version declaration. Historical mentions
91
105
  // must not choose a version; ambiguous prose is not approval evidence.
92
106
  const versionOf=(value,type)=>{
107
+ // An amended immutable P1/R1 document can be V3 while the human
108
+ // display still calls its review "P2 final revision". Prefer the
109
+ // explicitly marked CURRENT physical version, never the historical
110
+ // P1 V1/V2 recap or the human review-cycle alias.
111
+ const currentRevision=value.match(new RegExp(
112
+ "(?:^|\\n)\\s*当前版本\\s*V([1-9][0-9]*)\\s*[((]\\s*"
113
+ +type+"([1-9][0-9]*)\\s*(?:最终)?修订稿[))]","i"));
114
+ if(currentRevision&&Number(currentRevision[1])>=2
115
+ &&Number(currentRevision[2])>=2
116
+ &&Number(currentRevision[2])<=Number(currentRevision[1]))
117
+ return type+String(Number(currentRevision[1]));
93
118
  // Real formal reviews may start with a status recap mentioning an
94
119
  // an older plan version before the current issued revision heading.
95
120
  // A unique, version-consistent line title outranks historical prose.
@@ -132,7 +157,9 @@ if (message?.type === "CHAT_LOOP_APPROVAL_EVIDENCE_V1") {
132
157
  fail("APPROVAL_PLAN_MISSING");return false;
133
158
  }
134
159
  const pVersion=versionOf(textOf(pAssistant),"P");
135
- const pUserVersion=textOf(pUser).match(/\bP[1-9][0-9]*\b/i)?.[0].toUpperCase();
160
+ const pUserForm=formApprovalVersion(textOf(pUser),'P');
161
+ const pUserVersion=pUserForm?.version
162
+ ||textOf(pUser).match(/\bP[1-9][0-9]*\b/i)?.[0].toUpperCase();
136
163
  if(pUserVersion && pVersion!==pUserVersion){
137
164
  fail("APPROVAL_PLAN_VERSION_MISMATCH");return false;
138
165
  }
@@ -145,7 +172,7 @@ if (message?.type === "CHAT_LOOP_APPROVAL_EVIDENCE_V1") {
145
172
  // Context Start lease independently verifies the effective R approval.
146
173
  const rUser=rIndex>=0?rows[rIndex]:null;
147
174
  const rForm=rUser?formApprovalVersion(textOf(rUser),'R'):null;
148
- const pForm=formApprovalVersion(textOf(pUser),'P');
175
+ const pForm=pUserForm;
149
176
  if(rForm&&pForm&&(rForm.formId===pForm.formId
150
177
  ||rForm.traceRef===pForm.traceRef)){
151
178
  fail('APPROVAL_FORM_REUSED');return false;
@@ -231,9 +258,18 @@ if (message?.type === "CHAT_LOOP_APPROVAL_EVIDENCE_V1") {
231
258
  if(!pVersion||!rVersion||invalidated){
232
259
  fail("APPROVAL_REVISED_OR_REVOKED");return false;
233
260
  }
234
- const rUserVersion=textOf(rUser).match(/\bR[1-9][0-9]*\b/i)?.[0].toUpperCase();
261
+ const rUserVersion=rForm?.version
262
+ ||textOf(rUser).match(/\bR[1-9][0-9]*\b/i)?.[0].toUpperCase();
235
263
  const referencedR=textOf(pAssistant).match(/\bR[1-9][0-9]*\b/i)?.[0].toUpperCase();
236
- if(!referencedR || referencedR!==rVersion){
264
+ // A versioned Form pair is independently reconciled against the
265
+ // immutable Context P.requirementRef and R/P approval records at
266
+ // permit.consume. Some valid revised-plan replies do not repeat R1 in
267
+ // their visible summary. Allow only this same-Chat, two-Form case;
268
+ // native/unscoped prose still requires an explicit R reference.
269
+ const formScopedRequirement=Boolean(explicitFormChat&&rForm&&pForm
270
+ &&rForm.version===rVersion&&pForm.version===pVersion);
271
+ if((!referencedR||referencedR!==rVersion)
272
+ &&!formScopedRequirement){
237
273
  fail("APPROVAL_PLAN_REQUIREMENT_MISMATCH");return false;
238
274
  }
239
275
  if(rUserVersion && rVersion!==rUserVersion){
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "manifest_version": 3,
3
3
  "name": "Chat Loop Extension",
4
- "version": "0.4.44",
4
+ "version": "0.4.46",
5
5
  "description": "Chat Loop browser companion: Eye actions, Turn observer, Continue and Handoff Actions",
6
6
  "permissions": [
7
7
  "activeTab",
@@ -1,7 +1,7 @@
1
- // A live V2 Task is NOT a global blocker for an independent TEST_ONLY Chat.
2
- // V1 Native session-read deliberately rejects active V2 Ledger state; retain
3
- // that fence and verify each current scoped Worker/Native/Context writer instead.
4
- // No Task is adopted, fenced, resumed, or sent through the Owner path here.
1
+ // TEST_ONLY new-Chat entry never takes an Owner or sends through an existing
2
+ // Task. A frozen cancel is a non-sending fence, not a global Chat monopoly.
3
+ // Verify Native/Worker and the absence of the old Chat before admitting a
4
+ // distinct native @ App first turn; do not unblock or touch the frozen Task.
5
5
  async function verifiedScopedEntryAdmission(){
6
6
  if(!scopedTaskRuns)return {status:'DENIED',code:'ENTRY_TEST_SCOPED_STORE_MISSING'};
7
7
  const legacy=await readRun();
@@ -13,13 +13,28 @@ async function verifiedScopedEntryAdmission(){
13
13
  .filter(run=>!['DONE','CANCELLED'].includes(run.phase));
14
14
  if(!active.length||active.length>32)
15
15
  return {status:'DENIED',code:'ENTRY_TEST_SCOPED_OWNER_UNVERIFIED'};
16
+ const frozenProofs=[];
16
17
  for(const run of active){
17
- if(run.phase!=='WAITING_REPLY'||typeof run.projectId!=='string'
18
- ||typeof run.taskId!=='string'||typeof run.sessionId!=='string'
18
+ if(typeof run.projectId!=='string'||typeof run.taskId!=='string'
19
+ ||typeof run.sessionId!=='string'
19
20
  ||!Number.isSafeInteger(run.generation)||run.generation<0
20
21
  ||!Number.isSafeInteger(run.nativeOwnerRevision)
21
22
  ||run.nativeOwnerRevision<1)
22
23
  return {status:'DENIED',code:'ENTRY_TEST_SCOPED_OWNER_UNVERIFIED'};
24
+ const frozen=run.phase==='BLOCKED'
25
+ &&run.reason==='SESSION_CANCEL_PENDING'
26
+ &&/^[a-f0-9]{32}$/.test(run.cancelRequestId||'')
27
+ &&Number.isSafeInteger(run.contextBindingRevision)
28
+ &&run.contextBindingRevision>0
29
+ &&!run.modelIntent&&!run.nextAttempt&&!run.lastIntentReceipt
30
+ &&!run.handoffFence
31
+ &&Number.isSafeInteger(run.tabId)&&run.tabId>0
32
+ &&typeof run.page==='string'
33
+ &&pathOf('https://chatgpt.com'+run.page)===run.page
34
+ &&typeof run.ownerChatId==='string'
35
+ &&chatIdOf('https://chatgpt.com'+run.page)===run.ownerChatId;
36
+ if(run.phase!=='WAITING_REPLY'&&!frozen)
37
+ return {status:'DENIED',code:'ENTRY_TEST_SCOPED_OWNER_UNVERIFIED'};
23
38
  const args={projectId:run.projectId,taskId:run.taskId,
24
39
  sessionId:run.sessionId,generation:run.generation};
25
40
  const native=await chrome.runtime.sendNativeMessage(SESSION_HOST,{
@@ -28,9 +43,27 @@ async function verifiedScopedEntryAdmission(){
28
43
  if(native?.status!=='OK'||native.scope!=='TASK_SCOPED_SNAPSHOT'
29
44
  ||s?.projectId!==run.projectId||s.taskId!==run.taskId
30
45
  ||s.sessionId!==run.sessionId||s.generation!==run.generation
31
- ||s.phase!=='WAITING_REPLY'||s.revision!==run.nativeOwnerRevision
32
46
  ||typeof s.activeChatId!=='string'
33
- ||s.activeChatId!==run.ownerChatId)
47
+ ||s.activeChatId!==run.ownerChatId
48
+ ||pathOf(s.activeChatUrl)!==run.page)
49
+ return {status:'DENIED',code:'ENTRY_TEST_SCOPED_OWNER_MISMATCH'};
50
+ if(frozen){
51
+ // The first Native cancel CAS may advance exactly one revision while
52
+ // Worker retains its pre-cancel snapshot. Both MUST be BLOCKED.
53
+ if(s.phase!=='BLOCKED'
54
+ ||![run.nativeOwnerRevision,run.nativeOwnerRevision+1]
55
+ .includes(s.revision))
56
+ return {status:'DENIED',code:'ENTRY_TEST_FROZEN_OWNER_MISMATCH'};
57
+ const tabs=await chrome.tabs.query({url:'https://chatgpt.com/*'})
58
+ .catch(()=>null);
59
+ if(!Array.isArray(tabs)
60
+ ||tabs.some(tab=>tab.id===run.tabId
61
+ ||chatIdOf(tab.url)===run.ownerChatId))
62
+ return {status:'DENIED',code:'ENTRY_TEST_FROZEN_CHAT_PRESENT'};
63
+ frozenProofs.push({args,revision:s.revision,phase:s.phase});
64
+ continue;
65
+ }
66
+ if(s.phase!=='WAITING_REPLY'||s.revision!==run.nativeOwnerRevision)
34
67
  return {status:'DENIED',code:'ENTRY_TEST_SCOPED_OWNER_MISMATCH'};
35
68
  const writer=await chrome.runtime.sendNativeMessage(SESSION_HOST,{
36
69
  op:'context-writer-check-v2',...args,
@@ -45,9 +78,31 @@ async function verifiedScopedEntryAdmission(){
45
78
  const current=Object.values(reread.items).map(x=>x.run)
46
79
  .filter(run=>!['DONE','CANCELLED'].includes(run.phase));
47
80
  const identity=run=>[run.projectId,run.taskId,run.sessionId,
48
- run.generation,run.nativeOwnerRevision,run.phase,run.ownerChatId].join('|');
81
+ run.generation,run.nativeOwnerRevision,run.phase,run.reason,
82
+ run.cancelRequestId,run.ownerChatId,run.tabId].join('|');
49
83
  if(current.length!==active.length
50
84
  ||current.some((run,i)=>identity(run)!==identity(active[i])))
51
85
  return {status:'DENIED',code:'ENTRY_TEST_SCOPED_OWNER_CHANGED'};
52
- return {status:'OK',scope:'TEST_ONLY',mode:'VERIFIED_SCOPED_OWNER_DISTINCT_CHAT'};
86
+ // Recheck each frozen Native fence after async Chrome/Context queries.
87
+ // Reopening the old Chat or unfreezing Native while checking fails closed.
88
+ for(const proof of frozenProofs){
89
+ const native=await chrome.runtime.sendNativeMessage(SESSION_HOST,{
90
+ op:'session-snapshot-v2',...proof.args}).catch(()=>null);
91
+ if(native?.status!=='OK'||native.scope!=='TASK_SCOPED_SNAPSHOT'
92
+ ||native.session?.revision!==proof.revision
93
+ ||native.session.phase!=='BLOCKED')
94
+ return {status:'DENIED',code:'ENTRY_TEST_FROZEN_OWNER_CHANGED'};
95
+ }
96
+ if(frozenProofs.length){
97
+ const tabs=await chrome.tabs.query({url:'https://chatgpt.com/*'})
98
+ .catch(()=>null);
99
+ if(!Array.isArray(tabs)
100
+ ||active.filter(run=>run.phase==='BLOCKED').some(run=>
101
+ tabs.some(tab=>tab.id===run.tabId
102
+ ||chatIdOf(tab.url)===run.ownerChatId)))
103
+ return {status:'DENIED',code:'ENTRY_TEST_FROZEN_CHAT_PRESENT'};
104
+ }
105
+ return {status:'OK',scope:'TEST_ONLY',mode:frozenProofs.length
106
+ ?'FROZEN_OWNER_FENCED_DISTINCT_CHAT'
107
+ :'VERIFIED_SCOPED_OWNER_DISTINCT_CHAT'};
53
108
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomflow/chatloop-extension",
3
- "version": "0.4.44",
3
+ "version": "0.4.46",
4
4
  "type": "module",
5
5
  "description": "Chat Loop Extension: reviewed formal Action pages, including TEST_ONLY native App entry",
6
6
  "bin": {