@tomflow/chatloop-extension 0.4.46 → 0.4.48

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.
@@ -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',
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "manifest_version": 3,
3
3
  "name": "Chat Loop Extension",
4
- "version": "0.4.46",
4
+ "version": "0.4.48",
5
5
  "description": "Chat Loop browser companion: Eye actions, Turn observer, Continue and Handoff Actions",
6
6
  "permissions": [
7
7
  "activeTab",
@@ -83,7 +83,8 @@ async function scopedTaskRecoverCancel(message,sender){
83
83
  if(fresh.runRevision!==stamped.runRevision
84
84
  ||fresh.run?.recoveryRequestId!==id)
85
85
  throw cancelRecoveryFail('SCOPED_CANCEL_RECOVER_WORKER_CHANGED');
86
- const final={...fresh.run,phase:'CANCELLED',
86
+ const {cancelReadSourceLost:historicalSourceFailure,...recoverable}=fresh.run;
87
+ const final={...recoverable,phase:'CANCELLED',
87
88
  reason:'SESSION_CANCELLED',terminalAt:Date.now(),
88
89
  nativeOwnerRevision:result.nativeOwnerRevision,
89
90
  contextBindingRevision:result.contextBindingRevision};
@@ -6,6 +6,7 @@ async function reconcileScopedCancelled(){
6
6
  const state=await scopedTaskRuns.read();
7
7
  const candidates=Object.values(state.items).filter(({run})=>
8
8
  run.phase==='BLOCKED'&&run.reason==='SESSION_CANCEL_PENDING'
9
+ &&!run.cancelReadSourceLost
9
10
  &&/^[a-f0-9]{32}$/.test(run.cancelRequestId||''));
10
11
  const jobs=candidates.map(({run,revision})=>scopedTaskScheduler.perTask(
11
12
  run.projectId,run.taskId,async()=>{
@@ -14,6 +15,7 @@ async function reconcileScopedCancelled(){
14
15
  if(current.runRevision!==revision
15
16
  ||s?.phase!=='BLOCKED'
16
17
  ||s.reason!=='SESSION_CANCEL_PENDING'
18
+ ||s.cancelReadSourceLost
17
19
  ||s.cancelRequestId!==run.cancelRequestId
18
20
  ||s.sessionId!==run.sessionId
19
21
  ||s.generation!==run.generation)return;
@@ -38,6 +40,19 @@ async function reconcileScopedCancelled(){
38
40
  expectedBindingRevision:s.contextBindingRevision,
39
41
  expectedActiveChatUrl:'https://chatgpt.com'+s.page
40
42
  }).catch(()=>null);
43
+ // Only a definitive missing/expired signed source is safe to fence.
44
+ // Never release Native Owner or replay Context cancellation.
45
+ if(verified?.status==='FAILED'
46
+ &&['NO_REQUEST','REQUEST_EXPIRED'].includes(verified.code)){
47
+ const fresh=await scopedTaskRuns.get(s.projectId,s.taskId);
48
+ if(fresh.runRevision!==current.runRevision)return;
49
+ await scopedTaskRuns.put({...s,cancelReadSourceLost:{
50
+ code:verified.code,at:Date.now()}},{
51
+ expectedStoreRevision:fresh.storeRevision,
52
+ expectedRunRevision:fresh.runRevision});
53
+ console.warn('TASK_CANCEL_SOURCE_UNAVAILABLE',verified.code);
54
+ return;
55
+ }
41
56
  if(verified?.status!=='CONFIRMED'
42
57
  ||verified.scope!=='TASK_SCOPED_CANCELLED_NOT_DELIVERED'
43
58
  ||verified.readOnly!==true
@@ -64,6 +64,30 @@ const onScopedBrowserMessage=(message,sender,reply)=>{
64
64
  // Project grant before returning even bounded status metadata.
65
65
  const native=await chrome.runtime.sendNativeMessage(SESSION_HOST,{
66
66
  op:'context-status-v2',sourceRequestId:message.requestId});
67
+ if(native?.status==='OK'
68
+ &&native.scope==='TASK_SCOPED_PRESTART_READ_ONLY'
69
+ &&native.projectId===intent.projectId
70
+ &&native.taskId===intent.taskId){
71
+ const before=await scopedTaskRuns.get(intent.projectId,intent.taskId);
72
+ if(before.run)throw Error('SCOPED_PRESTART_WORKER_DRIFT');
73
+ // Existing no-URL admission: inspect open Chats only, never send.
74
+ const found=await approvedAdoptionTarget(null,intent.taskId);
75
+ const after=await scopedTaskRuns.get(intent.projectId,intent.taskId);
76
+ const n=await chrome.runtime.sendNativeMessage(SESSION_HOST,{
77
+ op:'context-status-v2',sourceRequestId:message.requestId});
78
+ if(after.storeRevision!==before.storeRevision||after.run
79
+ ||n?.status!=='OK'||n.scope!=='TASK_SCOPED_PRESTART_READ_ONLY'
80
+ ||n.projectId!==intent.projectId||n.taskId!==intent.taskId)
81
+ throw Error('SCOPED_PRESTART_STATE_CHANGED');
82
+ return {status:'OK',scope:'TASK_SCOPED_PRESTART_NO_OWNER',
83
+ projectId:intent.projectId,taskId:intent.taskId,
84
+ native:{phase:'NOT_CREATED'},worker:{state:'PRE_START_NO_OWNER'},
85
+ chatCandidate:found.target
86
+ ?{url:'https://chatgpt.com'+found.target.page,
87
+ confidence:'SOFT_OBSERVER_CANDIDATE_ONLY'}:null,
88
+ chatCandidateStatus:found.target?'OBSERVED_SOFT'
89
+ :found.error||'UNVERIFIED'};
90
+ }
67
91
  if(native?.status!=='OK'
68
92
  ||native.scope!=='TASK_SCOPED_STATUS_READ_ONLY'
69
93
  ||native.projectId!==intent.projectId
@@ -72,8 +72,10 @@ export function createScopedNativeControl(ports){
72
72
  throw Object.assign(Error('Exact status intent required'),
73
73
  {code:'SCOPED_STATUS_SOURCE_INVALID'});
74
74
  const current=readScopedOwner(intent.projectId,intent.taskId).session;
75
- if(!current)throw Object.assign(Error('Task Owner not found'),
76
- {code:'SCOPED_TASK_OWNER_NOT_FOUND'});
75
+ // No Owner before Start is expected; this read grants no permit.
76
+ if(!current)return {status:'OK',
77
+ scope:'TASK_SCOPED_PRESTART_READ_ONLY',
78
+ projectId:intent.projectId,taskId:intent.taskId};
77
79
  const proof=Object.fromEntries(['projectId','taskId','sessionId',
78
80
  'generation','revision','phase','activeChatId']
79
81
  .map(k=>[k,current[k]]));
@@ -390,4 +392,4 @@ export function createScopedNativeControl(ports){
390
392
  }
391
393
  return result;
392
394
  };
393
- }
395
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomflow/chatloop-extension",
3
- "version": "0.4.46",
3
+ "version": "0.4.48",
4
4
  "type": "module",
5
5
  "description": "Chat Loop Extension: reviewed formal Action pages, including TEST_ONLY native App entry",
6
6
  "bin": {