@tomflow/chatloop-extension 0.4.43 → 0.4.45

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
@@ -51,7 +51,7 @@ async function run(){
51
51
  ||acquired.action!=='session'||typeof acquired.nonce!=='string'
52
52
  ||acquired.intent?.operation!==operation)
53
53
  throw Error(acquired?.code||'SESSION_INTENT_UNVERIFIED');
54
- let result;
54
+ let result,dispatched=false;
55
55
  try{
56
56
  if(operation!=='cancel')await confirmRecoveryClick(acquired.intent);
57
57
  show('RUNNING',operation==='cancel'
@@ -59,6 +59,7 @@ async function run(){
59
59
  :operation==='recover-cancel'
60
60
  ?'核验旧取消请求和已冻结 Owner,完成 Context 围栏;不会发送消息…'
61
61
  :'核验原 Handoff 未发送证据及一次性恢复许可;不会发送消息…');
62
+ dispatched=true;
62
63
  result=await chrome.runtime.sendMessage({
63
64
  type:operation==='recover-cancel'
64
65
  ?'CHAT_LOOP_TASK_CANCEL_RECOVER_V2'
@@ -86,7 +87,7 @@ async function run(){
86
87
  // retry a mutation; the original request and persisted receipt are proof.
87
88
  const raw=error?.message;
88
89
  const code=/^[A-Z][A-Z0-9_]{1,95}$/.test(raw||'')?raw:'SESSION_ACTION_UNVERIFIED';
89
- if(operation!=='cancel'){
90
+ if(operation!=='cancel'&&dispatched){
90
91
  // A permit/bind/Native CAS may already have committed. Never seal
91
92
  // an ambiguous recovery as a definitive FAILED Action receipt:
92
93
  // preserve this exact signed request for read-only reconciliation.
@@ -97,9 +98,9 @@ async function run(){
97
98
  op:'complete',id,nonce:acquired.nonce,action:'session',
98
99
  status:'FAILED',code
99
100
  }).catch(()=>null);
100
- show('BLOCKED',code);
101
- if(receipt?.status==='SAVED'&&receipt.id===id)
102
- await chrome.tabs.remove(own.id).catch(()=>{});
101
+ const saved=receipt?.status==='SAVED'&&receipt.id===id;
102
+ show('BLOCKED',saved?code:code+';终态回执未核实,仅核查原请求。');
103
+ if(saved)await chrome.tabs.remove(own.id).catch(()=>{});
103
104
  }
104
105
  }
105
106
  void run().catch(e=>show('UNVERIFIED',
@@ -36,7 +36,7 @@
36
36
  if (!ACTIONS.has(name)) return null;
37
37
  if (name==='session' && u.searchParams.size===2
38
38
  && validId(u.searchParams.get('requestId'))
39
- && ['cancel','recover-handoff'].includes(u.searchParams.get('operation')))
39
+ && ['cancel','recover-handoff','recover-cancel'].includes(u.searchParams.get('operation')))
40
40
  return {kind:'machine',name,requestId:u.searchParams.get('requestId')};
41
41
  if (u.searchParams.size === 1 && validId(u.searchParams.get('requestId')))
42
42
  return {kind:READ_ONLY.has(name) || ['continue','handoff'].includes(name)
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "manifest_version": 3,
3
3
  "name": "Chat Loop Extension",
4
- "version": "0.4.43",
4
+ "version": "0.4.45",
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
  }
@@ -72,12 +72,13 @@ export function openExtensionActionPage(url,{platform=process.platform,spawn=spa
72
72
  // The private session Action uses a fixed operation selector in addition to
73
73
  // its request locator. No other Action may accept arbitrary URL arguments.
74
74
  const ordinary=/^chrome-extension:\/\/[a-p]{32}\/(?!session\.html)[a-z_]+\.html\?requestId=[a-f0-9]{32}$/;
75
- const session=/^chrome-extension:\/\/[a-p]{32}\/session\.html\?requestId=[a-f0-9]{32}&operation=(?:cancel|recover-handoff)$/;
75
+ const session=/^chrome-extension:\/\/([a-p]{32})\/session\.html\?requestId=[a-f0-9]{32}&operation=(?:cancel|recover-handoff|recover-cancel)$/;
76
76
  if(!ordinary.test(url)&&!session.test(url))
77
77
  throw Object.assign(Error('Untrusted Extension Action URL'),{code:'INVALID_ACTION_URL'});
78
78
  // An orphaned Owner may have no Chat tab at all. The existing verified
79
79
  // extension-details window is the only supported fallback for that case.
80
- const entry=url.match(/^chrome-extension:\/\/([a-p]{32})\/(?:entry_test|session)\.html\?requestId=[a-f0-9]{32}(?:&operation=(?:cancel|recover-handoff))?$/);
80
+ const entry=url.match(/^chrome-extension:\/\/([a-p]{32})\/entry_test\.html\?requestId=[a-f0-9]{32}$/)
81
+ ||url.match(session);
81
82
  const launchArgs=entry
82
83
  ?['-e',OPEN_TEST_ENTRY_WINDOW,url,'chrome://extensions/?id='+entry[1]]
83
84
  :['-e',OPEN_IN_CHAT_WINDOW,url];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomflow/chatloop-extension",
3
- "version": "0.4.43",
3
+ "version": "0.4.45",
4
4
  "type": "module",
5
5
  "description": "Chat Loop Extension: reviewed formal Action pages, including TEST_ONLY native App entry",
6
6
  "bin": {