@tomflow/chatloop-extension 0.4.26 → 0.4.28

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
@@ -78,7 +78,7 @@ Run: chatloop-extension extension <command> --help
78
78
 
79
79
  For the installed command list, run `chatloop-extension extension --help`.
80
80
 
81
- `extension start` requires the real approved intent; `mode=adopt` does not
81
+ `extension start` requires the real approved intent; `mode=adopt` requires an exact Context `start.reserve` lease, taskId, store epoch and revisions at the public CLI input boundary, with actual approval/lease validity independently checked by Native `permit.consume`. A browser-only R/P text pattern and `confirmed:true` cannot authorize a production Adopt; the prompt-based legacy Start has separate rules. `mode=adopt` does not
82
82
  re-send. Continue/Handoff only register intents with one Turn token and never
83
83
  silently send or repeat. Clean needs an exact verified tab ID, and Status
84
84
  is read-only. A previously BLOCKED Session with a lost old Owner tab remains
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "manifest_version": 3,
3
3
  "name": "Chat Loop Extension",
4
- "version": "0.4.26",
4
+ "version": "0.4.28",
5
5
  "description": "Chat Loop browser companion: Eye actions, Turn observer, Continue and Handoff Actions",
6
6
  "permissions": [
7
7
  "activeTab",
@@ -87,14 +87,22 @@ async function sessionStartPrepare(message,sender){
87
87
  &&!!intent.chatUrl&&prior.adoptPage===pathOf(intent.chatUrl)
88
88
  &&Number.isInteger(prior.adoptTabId)
89
89
  &&typeof prior.adoptUserKey==='string');
90
- const matchingBlocked=prior?.phase==='BLOCKED' && prior.sessionId===replace
91
- && (prior.projectId!==intent.projectId || independentTask
92
- ||prePermitRecovery)||preNativeGhost;
90
+ const disk=await chrome.runtime.sendNativeMessage(SESSION_HOST,{op:'session-read'}).catch(()=>null);
91
+ if(disk?.status!=='OK')return {status:'DENIED',code:'SESSION_STATE_UNVERIFIED'};
92
+ // A Worker ghost from a timed-out, no-send Adopt may disagree with the
93
+ // durable Native BLOCKED ID. Only an independently approved DIFFERENT Task
94
+ // may supersede the exact Native pointer, never the same old Task or Chat.
95
+ const driftReplacement=Boolean(independentTask&&replace
96
+ &&replace===disk.session?.sessionId
97
+ &&independentBlockedAdoptDrift(prior,disk.session)
98
+ &&!!intent.chatUrl&&pathOf(intent.chatUrl)!==prior.adoptPage);
99
+ const matchingBlocked=Boolean(prior?.phase==='BLOCKED'
100
+ &&prior.sessionId===replace
101
+ &&(prior.projectId!==intent.projectId||independentTask
102
+ ||prePermitRecovery)||preNativeGhost||driftReplacement);
93
103
  if(replace&&!matchingBlocked)return {status:'DENIED',code:'BLOCKED_REPLACEMENT_MISMATCH'};
94
104
  if(prior&&prior.phase!=='DONE'&&!matchingBlocked)
95
105
  return {status:'DENIED',code:'LOOP_ALREADY_ACTIVE'};
96
- const disk=await chrome.runtime.sendNativeMessage(SESSION_HOST,{op:'session-read'}).catch(()=>null);
97
- if(disk?.status!=='OK')return {status:'DENIED',code:'SESSION_STATE_UNVERIFIED'};
98
106
  const ownerMatches=Boolean(prior?.sessionId&&disk.session
99
107
  &&matchesNativeProjection(sessionProjection(prior),disk.session));
100
108
  const sameTaskNative=Boolean((prePermitRecovery||preNativeGhost)
@@ -104,7 +112,8 @@ async function sessionStartPrepare(message,sender){
104
112
  &&disk.session.activeChatId===null&&disk.session.activeChatUrl===null
105
113
  &&Number.isSafeInteger(disk.session.updatedAt)
106
114
  &&disk.session.updatedAt>0);
107
- if((matchingBlocked&&!(ownerMatches||(preNativeGhost&&sameTaskNative)))
115
+ if((matchingBlocked&&!(ownerMatches||(preNativeGhost&&sameTaskNative)
116
+ ||driftReplacement))
108
117
  ||((prePermitRecovery||preNativeGhost)&&!sameTaskNative))
109
118
  return {status:'DENIED',code:'SESSION_REPLACEMENT_MISMATCH'};
110
119
  // A terminal Worker record cannot authorize a new Start if a different
@@ -135,7 +144,8 @@ async function sessionStartPrepare(message,sender){
135
144
  :await approvedAdoptionTarget(intent.chatUrl||null,
136
145
  intent.contextLeaseRef?intent.taskId:null):null;
137
146
  if(adoption?.error)return {status:'DENIED',code:adoption.error};
138
- if(matchingBlocked&&adoption?.target?.page===prior.page&&prior.page)
147
+ if((matchingBlocked&&adoption?.target?.page===prior.page&&prior.page)
148
+ ||(driftReplacement&&adoption?.target?.page===prior.adoptPage))
139
149
  return {status:'DENIED',code:'BLOCKED_REPLACEMENT_CHAT_REUSE'};
140
150
  // A Project-scoped Chat cannot safely hand off to the ordinary home route:
141
151
  // reject BEFORE claiming Owner instead of failing after four hours.
@@ -145,6 +145,26 @@ const SESSION_POINTER_KEYS=Object.freeze(['sessionId','projectId','taskId','phas
145
145
  'generation','activeChatId','activeChatUrl']);
146
146
  const matchesNativeProjection=(projected,native)=>Boolean(native
147
147
  &&SESSION_POINTER_KEYS.every(key=>projected[key]===native[key]));
148
+ // Read-only status diagnosis: reveal field NAMES only, never Owner identities.
149
+ const sessionProjectionDrift=(projected,native)=>SESSION_POINTER_KEYS.filter(
150
+ key=>projected[key]!==native?.[key]);
151
+ // Two distinct durable IDs may exist after an interrupted Adopt reservation.
152
+ // This narrow read-only shape proves NEITHER a previous send nor authority to
153
+ // replace it; only a DIFFERENT freshly approved Task can request Native CAS.
154
+ const independentBlockedAdoptDrift=(run,native)=>Boolean(
155
+ run?.phase==='BLOCKED'&&run.reason==='ACTION_RESULT_TIMEOUT_UNVERIFIED'
156
+ &&run.action==='START'&&run.mode==='adopt'
157
+ &&run.contextLeaseRef&&!run.contextManaged
158
+ &&run.generation===0&&run.tabId===null&&run.page==='/'
159
+ &&!run.userKey&&!run.newUserKey&&!run.assistantKey
160
+ &&!run.attemptedNewTabId&&!run.lastStartActionTabId
161
+ &&typeof run.adoptPage==='string'&&run.adoptPage.startsWith('/c/')
162
+ &&Number.isInteger(run.adoptTabId)&&typeof run.adoptUserKey==='string'
163
+ &&native?.phase==='BLOCKED'&&native.generation===0
164
+ &&native.activeChatId===null&&native.activeChatUrl===null
165
+ &&native.projectId===run.projectId&&native.taskId===run.taskId
166
+ &&typeof native.sessionId==='string'&&native.sessionId!==run.sessionId
167
+ &&Number.isSafeInteger(native.updatedAt)&&native.updatedAt>0);
148
168
  const sessionPage=(sender,name,id)=> Number.isInteger(sender.tab?.id)
149
169
  && typeof id==='string'&&/^[a-f0-9]{32}$/.test(id)
150
170
  && sender.url===chrome.runtime.getURL(name+'.html')+'?requestId='+id;
@@ -154,8 +154,16 @@ async function sessionStatus(message,sender){
154
154
  traceParent:message.auditDispatchParent}:{})}).catch(()=>null);
155
155
  if(disk?.status!=='OK')return {status:'UNVERIFIED',code:'SESSION_STATE_UNVERIFIED'};
156
156
  const projection=run?.sessionId?sessionProjection(run):null;
157
- if(projection&&!matchesNativeProjection(projection,disk.session))
158
- return {status:'UNVERIFIED',code:'SESSION_FILE_MISMATCH'};
157
+ if(projection&&!matchesNativeProjection(projection,disk.session)){
158
+ const mismatchedFields=sessionProjectionDrift(projection,disk.session);
159
+ return {status:'UNVERIFIED',code:'SESSION_FILE_MISMATCH',
160
+ mismatchedFields,
161
+ ...(mismatchedFields.length===1&&mismatchedFields[0]==='sessionId'
162
+ &&independentBlockedAdoptDrift(run,disk.session)
163
+ ?{independentTaskReplacementCandidate:{
164
+ replaceBlockedSessionId:disk.session.sessionId,
165
+ requires:'FRESH_APPROVED_DISTINCT_TASK_AND_NATIVE_CAS'}}:{})};
166
+ }
159
167
  if(!run?.sessionId&&disk.session&&disk.session.phase!=='DONE')
160
168
  return {status:'UNVERIFIED',code:'SESSION_OWNER_MISMATCH'};
161
169
  if(run&&run.phase!=='DONE'&&!run.sessionId)
package/lib/bridge.mjs CHANGED
@@ -85,6 +85,8 @@ function validateIntent(action, intent) {
85
85
  ||typeof intent.contextStoreEpoch!=='string'||intent.contextStoreEpoch.length<10
86
86
  ||!Number.isSafeInteger(intent.contextTaskRevision)||intent.contextTaskRevision<1
87
87
  ||!Number.isSafeInteger(intent.contextApprovalRevision)||intent.contextApprovalRevision<1))
88
+ // Public Extension CLI must not bypass the managed Context Start lease.
89
+ ||(intent.mode==='adopt'&&!Object.hasOwn(intent,'contextLeaseRef'))
88
90
  ||intent.confirmed!==true || (intent.mode!==undefined && intent.mode!=='adopt')
89
91
  || (intent.replaceBlockedSessionId!==undefined
90
92
  && !/^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i.test(intent.replaceBlockedSessionId))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomflow/chatloop-extension",
3
- "version": "0.4.26",
3
+ "version": "0.4.28",
4
4
  "type": "module",
5
5
  "description": "Chat Loop Extension: reviewed formal Action pages, including TEST_ONLY native App entry",
6
6
  "bin": {