@tomflow/chatloop-extension 0.4.29 → 0.4.31

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
@@ -93,7 +93,11 @@ a Worker-only failed Native sync permits at most one additional fenced repair,
93
93
  never a general BLOCKED retry. Two distinct genuine Form A-confirmation
94
94
  user Turns may serve as SOFT R/P evidence in an explicitly
95
95
  specified original Chat; this never substitutes for Context approval or Start
96
- permission. IPC messages are one-shot and have durable identity checks.
96
+ permission. IPC messages are one-shot and have durable identity checks. CLI and Native
97
+ Host resolve the same private `chatloop-extension-v2-<uid>` IPC directory in
98
+ the fixed system temporary root (macOS `/private/tmp`, Linux `/tmp`),
99
+ independent of TMPDIR/TMP/TEMP. The prior namespace is retained as historical
100
+ receipt evidence and is never searched or replayed by this protocol.
97
101
 
98
102
  This package's source version is read from its own `package.json`. Installed
99
103
  Tools/Context consumers may pin a different Extension version; updating
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "manifest_version": 3,
3
3
  "name": "Chat Loop Extension",
4
- "version": "0.4.29",
4
+ "version": "0.4.31",
5
5
  "description": "Chat Loop browser companion: Eye actions, Turn observer, Continue and Handoff Actions",
6
6
  "permissions": [
7
7
  "activeTab",
@@ -62,8 +62,8 @@ async function sessionStartPrepare(message,sender){
62
62
  &&prior.contextStoreEpoch===intent.contextStoreEpoch
63
63
  &&prior.contextTaskRevision===intent.contextTaskRevision
64
64
  &&prior.contextApprovalRevision===intent.contextApprovalRevision
65
- &&prior.tabId===null&&prior.page==='/'&&!prior.newUserKey
66
- &&!prior.userKey&&!prior.attemptedNewTabId
65
+ &&prior.generation===0&&prior.tabId===null&&prior.page==='/'&&!prior.newUserKey
66
+ &&!prior.userKey&&!prior.assistantKey&&!prior.attemptedNewTabId&&!prior.lastStartActionTabId
67
67
  &&!!intent.chatUrl&&prior.adoptPage===pathOf(intent.chatUrl)
68
68
  &&Number.isInteger(prior.adoptTabId)
69
69
  &&typeof prior.adoptUserKey==='string');
@@ -71,7 +71,9 @@ async function sessionStartPrepare(message,sender){
71
71
  // rejected its CAS, Worker/Native disagree. No send was attempted, but this
72
72
  // is NOT a free retry: one exact native-BLOCKED repair with a fresh lease
73
73
  // is allowed; any managed writer, late send or second repair remains denied.
74
- const preNativeGhost=Boolean(prior?.phase==='STARTING'
74
+ const timedOutGhost=prior?.phase==='BLOCKED'
75
+ &&prior.reason==='ACTION_RESULT_TIMEOUT_UNVERIFIED';
76
+ const preNativeGhost=Boolean((prior?.phase==='STARTING'||timedOutGhost)
75
77
  &&prior.action==='START'&&prior.mode==='adopt'
76
78
  &&prior.prePermitRetryUsed===true&&!prior.preNativeRepairUsed
77
79
  &&prior.replacedBlockedSessionId===replace
@@ -82,8 +84,8 @@ async function sessionStartPrepare(message,sender){
82
84
  &&prior.contextStoreEpoch===intent.contextStoreEpoch
83
85
  &&prior.contextTaskRevision===intent.contextTaskRevision
84
86
  &&prior.contextApprovalRevision===intent.contextApprovalRevision
85
- &&prior.tabId===null&&prior.page==='/'&&!prior.newUserKey
86
- &&!prior.userKey&&!prior.attemptedNewTabId
87
+ &&prior.generation===0&&prior.tabId===null&&prior.page==='/'&&!prior.newUserKey
88
+ &&!prior.userKey&&!prior.assistantKey&&!prior.attemptedNewTabId&&!prior.lastStartActionTabId
87
89
  &&!!intent.chatUrl&&prior.adoptPage===pathOf(intent.chatUrl)
88
90
  &&Number.isInteger(prior.adoptTabId)
89
91
  &&typeof prior.adoptUserKey==='string');
@@ -114,8 +116,24 @@ async function sessionStartPrepare(message,sender){
114
116
  &&disk.session.updatedAt>0);
115
117
  if((matchingBlocked&&!(ownerMatches||(preNativeGhost&&sameTaskNative)
116
118
  ||driftReplacement))
117
- ||((prePermitRecovery||preNativeGhost)&&!sameTaskNative))
119
+ ||((prePermitRecovery||preNativeGhost)&&!sameTaskNative)
120
+ ||(preNativeGhost&&timedOutGhost&&!independentBlockedAdoptDrift(prior,disk.session)))
118
121
  return {status:'DENIED',code:'SESSION_REPLACEMENT_MISMATCH'};
122
+ if(prePermitRecovery||preNativeGhost){
123
+ // Native's durable old pointer scopes this read. A new lease or null
124
+ // runRef alone cannot prove the old START permit was never consumed.
125
+ const proof=await chrome.runtime.sendNativeMessage(SESSION_HOST,{
126
+ op:'context-control',command:'run.terminalStatus',
127
+ args:{startRecoveryLeaseRef:intent.contextLeaseRef}}).catch(()=>null);
128
+ const s=proof?.result;
129
+ if(proof?.status!=='OK'||s?.projectId!==intent.projectId||s?.taskId!==intent.taskId
130
+ ||s.storeEpoch!==intent.contextStoreEpoch||s.taskRevision!==intent.contextTaskRevision
131
+ ||s.approvalRevision!==intent.contextApprovalRevision||s.bindingRevision!==0
132
+ ||s.runRef!==null||s.unknownEffectCount!==0||s.executionOutcome!==null
133
+ ||s.startRecovery?.status!=='UNBOUND_NO_PERMIT'
134
+ ||s.startRecovery.leaseRef!==intent.contextLeaseRef)
135
+ return {status:'DENIED',code:'START_RECOVERY_PERMIT_UNVERIFIED'};
136
+ }
119
137
  // A terminal Worker record cannot authorize a new Start if a different
120
138
  // durable Native Owner exists under the same Browser installation.
121
139
  if(prior?.phase==='DONE'&&prior.sessionId&&disk.session&&!ownerMatches)
@@ -144,6 +162,8 @@ async function sessionStartPrepare(message,sender){
144
162
  :await approvedAdoptionTarget(intent.chatUrl||null,
145
163
  intent.contextLeaseRef?intent.taskId:null):null;
146
164
  if(adoption?.error)return {status:'DENIED',code:adoption.error};
165
+ if((prePermitRecovery||preNativeGhost)&&adoption?.target?.userKey!==prior.adoptUserKey)
166
+ return {status:'DENIED',code:'START_RECOVERY_APPROVAL_CHANGED'};
147
167
  if((matchingBlocked&&adoption?.target?.page===prior.page&&prior.page)
148
168
  ||(driftReplacement&&adoption?.target?.page===prior.adoptPage))
149
169
  return {status:'DENIED',code:'BLOCKED_REPLACEMENT_CHAT_REUSE'};
@@ -93,6 +93,10 @@ async function saveRun(run) {
93
93
  if(recoveryCommit&&(!Number.isSafeInteger(next.recoveryExpectedNativeAt)
94
94
  ||next.recoveryExpectedNativeAt<=0))
95
95
  throw Error('SESSION_RECOVERY_CAS_MISSING');
96
+ // Native must commit first for the exact terminal CAS transitions.
97
+ const replacementCommit=Boolean(next.replacedBlockedSessionId
98
+ &&next.phase==='STARTING'&&stored?.sessionId!==next.sessionId);
99
+ const nativeFirst=recoveryCommit||replacementCommit;
96
100
  const syncNative=async()=>{
97
101
  if(!next.sessionId)return;
98
102
  const record=sessionProjection(next);
@@ -104,18 +108,26 @@ async function saveRun(run) {
104
108
  ?{sameTaskPrePermitUpdatedAt:next.sameTaskPrePermitUpdatedAt}:{})}:{}),
105
109
  ...(recoveryCommit?{resumeBlockedSessionId:next.sessionId,
106
110
  resumeBlockedUpdatedAt:next.recoveryExpectedNativeAt}:{})}).catch(()=>null);
111
+ // A fresh replacement Session ID identifies this exact CAS. If its
112
+ // transport reply was lost, confirm the durable projection once, without
113
+ // replaying the write. Same-ID recovery has no such unique commit proof.
114
+ if(!saved&&replacementCommit){
115
+ const observed=await chrome.runtime.sendNativeMessage(SESSION_HOST,
116
+ {op:'session-read'}).catch(()=>null);
117
+ if(observed?.status==='OK'&&matchesNativeProjection(record,observed.session))return;
118
+ }
107
119
  // Native acknowledgment must match the whole immutable Owner pointer,
108
120
  // not merely its sessionId and phase. updatedAt is CAS metadata, not
109
121
  // part of this identity projection.
110
122
  if(saved?.status!=="OK"||!matchesNativeProjection(record,saved.session))
111
123
  throw Error(saved?.code||"SESSION_PERSISTENCE_UNVERIFIED");
112
124
  };
113
- // A terminal BLOCKED session may resume only after native CAS first.
114
- // Do not leave a Chrome RESERVED owner behind if native rejects the
115
- // transition: that mismatch previously made all status calls unreadable.
116
- if(recoveryCommit)await syncNative();
125
+ // BLOCKED recovery and replacement both require a Native CAS first.
126
+ // Do not publish a new Worker reservation when Native rejects the CAS.
127
+ // An unknown acknowledgement stays fail-closed; never replay a Start.
128
+ if(nativeFirst)await syncNative();
117
129
  await chrome.storage.local.set({[RUN_KEY]:next});
118
- if(!recoveryCommit)await syncNative();
130
+ if(!nativeFirst)await syncNative();
119
131
  // The resource inventory is derived evidence; it never grants browser Owner.
120
132
  if (["DONE","BLOCKED"].includes(next.phase)
121
133
  && next.contextTerminalFence !== "PENDING"
@@ -150,7 +162,8 @@ const sessionProjectionDrift=(projected,native)=>SESSION_POINTER_KEYS.filter(
150
162
  key=>projected[key]!==native?.[key]);
151
163
  // Two distinct durable IDs may exist after an interrupted Adopt reservation.
152
164
  // 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.
165
+ // replace it. Adopt admission separately verifies independent Task replacement
166
+ // or the exact same-Task pre-permit recovery contract before Native CAS.
154
167
  const independentBlockedAdoptDrift=(run,native)=>Boolean(
155
168
  run?.phase==='BLOCKED'&&run.reason==='ACTION_RESULT_TIMEOUT_UNVERIFIED'
156
169
  &&run.action==='START'&&run.mode==='adopt'
@@ -156,13 +156,24 @@ async function sessionStatus(message,sender){
156
156
  const projection=run?.sessionId?sessionProjection(run):null;
157
157
  if(projection&&!matchesNativeProjection(projection,disk.session)){
158
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'}}:{})};
159
+ const blockedAdoptDrift=mismatchedFields.length===1&&mismatchedFields[0]==='sessionId'
160
+ &&independentBlockedAdoptDrift(run,disk.session);
161
+ // Only a locator for the exact old reservation, never a permit or Owner.
162
+ const prePermitCandidate=blockedAdoptDrift&&run.prePermitRetryUsed===true
163
+ &&!run.preNativeRepairUsed&&run.replacedBlockedSessionId===disk.session.sessionId
164
+ &&typeof run.contextStoreEpoch==='string'&&Number.isSafeInteger(run.contextTaskRevision)
165
+ &&Number.isSafeInteger(run.contextApprovalRevision)
166
+ &&pathOf('https://chatgpt.com'+run.adoptPage)===run.adoptPage;
167
+ return {status:'UNVERIFIED',code:'SESSION_FILE_MISMATCH',mismatchedFields,
168
+ diagnostics:{extensionVersion:chrome.runtime.getManifest?.().version||null},
169
+ ...(blockedAdoptDrift?{independentTaskReplacementCandidate:{
170
+ replaceBlockedSessionId:disk.session.sessionId,
171
+ requires:'FRESH_APPROVED_DISTINCT_TASK_AND_NATIVE_CAS'}}:{}),
172
+ ...(prePermitCandidate?{sameTaskPrePermitRecoveryCandidate:{
173
+ projectId:run.projectId,taskId:run.taskId,
174
+ replaceBlockedSessionId:disk.session.sessionId,
175
+ originalChatUrl:'https://chatgpt.com'+run.adoptPage,
176
+ requires:'FRESH_LEASE_NO_PRIOR_PERMIT_ORIGINAL_APPROVAL_AND_NATIVE_CAS'}}:{})};
166
177
  }
167
178
  if(!run?.sessionId&&disk.session&&disk.session.phase!=='DONE')
168
179
  return {status:'UNVERIFIED',code:'SESSION_OWNER_MISMATCH'};
package/lib/bridge.mjs CHANGED
@@ -27,7 +27,19 @@ function pathEntryExists(path){
27
27
  catch(error){if(error.code==='ENOENT')return false;throw error}
28
28
  }
29
29
  export const configFile = () => join(homedir(), '.chat-loop', 'extension', 'config.json');
30
- export const tempRoot = () => join(tmpdir(), 'chatloop-extension-' + (process.getuid?.() ?? process.env.USERNAME ?? 'user'));
30
+ // The CLI and Chrome Native Host have independent environments. A fixed
31
+ // v2 namespace also fences unresolved requests from the former TMPDIR-based
32
+ // transport: never scan, migrate or replay those records.
33
+ export const tempRoot = () => {
34
+ const base=process.platform==='darwin'?'/private/tmp':process.platform==='linux'?'/tmp':tmpdir();
35
+ if(process.platform!=='win32'){
36
+ const st=lstatSync(base);
37
+ if(!st.isDirectory()||st.isSymbolicLink()||st.uid!==0
38
+ ||!(st.mode&0o1000)||!(st.mode&0o002))
39
+ throw Object.assign(Error('Untrusted IPC temp root'),{code:'UNTRUSTED_STATE'});
40
+ }
41
+ return join(base,'chatloop-extension-v2-'+(process.getuid?.()??process.env.USERNAME??'user'));
42
+ };
31
43
  export function privateDir(path) {
32
44
  mkdirSync(path, {recursive:true, mode:0o700});
33
45
  const st=lstatSync(path);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomflow/chatloop-extension",
3
- "version": "0.4.29",
3
+ "version": "0.4.31",
4
4
  "type": "module",
5
5
  "description": "Chat Loop Extension: reviewed formal Action pages, including TEST_ONLY native App entry",
6
6
  "bin": {