@tomflow/chatloop-extension 0.4.24 → 0.4.26

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
@@ -86,8 +86,12 @@ is read-only. A previously BLOCKED Session with a lost old Owner tab remains
86
86
  `oldOwnerTabStatus:MISSING_UNVERIFIED` diagnostic is not a replacement permit.
87
87
  A missing ACTIVE Owner or mismatched Native pointer remains `UNVERIFIED`.
88
88
  Explicit Adopt of a different approved Task still requires the exact old
89
- Session ID, old Context fence, and a fresh Start lease. Two distinct genuine
90
- Form A-confirmation user Turns may serve as SOFT R/P evidence in an explicitly
89
+ Session ID, old Context fence, and a fresh Start lease. An exceptional
90
+ same-Task recovery is limited to a proven pre-permit BLOCKED Adopt with no
91
+ send/Owner/writer, a fresh Context lease and one exact Native timestamp CAS;
92
+ a Worker-only failed Native sync permits at most one additional fenced repair,
93
+ never a general BLOCKED retry. Two distinct genuine Form A-confirmation
94
+ user Turns may serve as SOFT R/P evidence in an explicitly
91
95
  specified original Chat; this never substitutes for Context approval or Start
92
96
  permission. IPC messages are one-shot and have durable identity checks.
93
97
 
@@ -81,7 +81,8 @@ process.stdin.on('data',async chunk=>{
81
81
  write({status:recorded?'RECORDED':'DROPPED'});
82
82
  }else if(m.op==='session-sync'){
83
83
  write({status:'OK',session:writeSession(m.session,
84
- m.replaceBlockedSessionId,m.resumeBlockedSessionId,m.resumeBlockedUpdatedAt??null)});
84
+ m.replaceBlockedSessionId,m.resumeBlockedSessionId,
85
+ m.resumeBlockedUpdatedAt??null,m.sameTaskPrePermitUpdatedAt??null)});
85
86
  }else throw Object.assign(Error('Unknown operation'),{code:'INVALID_OPERATION'});
86
87
  };
87
88
  // The telemetry operation is intentionally excluded from self-recording.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "manifest_version": 3,
3
3
  "name": "Chat Loop Extension",
4
- "version": "0.4.24",
4
+ "version": "0.4.26",
5
5
  "description": "Chat Loop browser companion: Eye actions, Turn observer, Continue and Handoff Actions",
6
6
  "permissions": [
7
7
  "activeTab",
@@ -47,8 +47,49 @@ async function sessionStartPrepare(message,sender){
47
47
  const independentTask=Boolean(intent.mode==='adopt'&&intent.contextLeaseRef
48
48
  &&intent.taskId && (!prior?.taskId && !prior?.contextManaged
49
49
  ||prior?.taskId&&prior.taskId!==intent.taskId));
50
+ // A first Adopt that failed BEFORE permit.consume completed has no Chat
51
+ // send, tab binding, or Context writer. A fresh Context lease (which
52
+ // independently requires runRef=null) may replace this exact BLOCKED
53
+ // pre-permit Session at most once for the SAME approved Task. Unknown
54
+ // post-permit / browser outcomes are never eligible for this route.
55
+ const prePermitRecovery=Boolean(prior?.phase==='BLOCKED'
56
+ &&prior.reason==='CONTEXT_START_PERMIT_UNVERIFIED'
57
+ &&prior.action==='START'&&prior.mode==='adopt'
58
+ &&prior.contextLeaseRef&&!prior.prePermitRetryUsed
59
+ &&!prior.contextManaged&&prior.projectId===intent.projectId
60
+ &&prior.taskId===intent.taskId&&intent.mode==='adopt'
61
+ &&intent.contextLeaseRef&&intent.contextLeaseRef!==prior.contextLeaseRef
62
+ &&prior.contextStoreEpoch===intent.contextStoreEpoch
63
+ &&prior.contextTaskRevision===intent.contextTaskRevision
64
+ &&prior.contextApprovalRevision===intent.contextApprovalRevision
65
+ &&prior.tabId===null&&prior.page==='/'&&!prior.newUserKey
66
+ &&!prior.userKey&&!prior.attemptedNewTabId
67
+ &&!!intent.chatUrl&&prior.adoptPage===pathOf(intent.chatUrl)
68
+ &&Number.isInteger(prior.adoptTabId)
69
+ &&typeof prior.adoptUserKey==='string');
70
+ // If the previous pre-permit replacement wrote Worker STARTING but Native
71
+ // rejected its CAS, Worker/Native disagree. No send was attempted, but this
72
+ // is NOT a free retry: one exact native-BLOCKED repair with a fresh lease
73
+ // is allowed; any managed writer, late send or second repair remains denied.
74
+ const preNativeGhost=Boolean(prior?.phase==='STARTING'
75
+ &&prior.action==='START'&&prior.mode==='adopt'
76
+ &&prior.prePermitRetryUsed===true&&!prior.preNativeRepairUsed
77
+ &&prior.replacedBlockedSessionId===replace
78
+ &&prior.sessionId!==replace&&prior.contextLeaseRef
79
+ &&intent.contextLeaseRef&&intent.contextLeaseRef!==prior.contextLeaseRef
80
+ &&!prior.contextManaged&&prior.projectId===intent.projectId
81
+ &&prior.taskId===intent.taskId
82
+ &&prior.contextStoreEpoch===intent.contextStoreEpoch
83
+ &&prior.contextTaskRevision===intent.contextTaskRevision
84
+ &&prior.contextApprovalRevision===intent.contextApprovalRevision
85
+ &&prior.tabId===null&&prior.page==='/'&&!prior.newUserKey
86
+ &&!prior.userKey&&!prior.attemptedNewTabId
87
+ &&!!intent.chatUrl&&prior.adoptPage===pathOf(intent.chatUrl)
88
+ &&Number.isInteger(prior.adoptTabId)
89
+ &&typeof prior.adoptUserKey==='string');
50
90
  const matchingBlocked=prior?.phase==='BLOCKED' && prior.sessionId===replace
51
- && (prior.projectId!==intent.projectId || independentTask);
91
+ && (prior.projectId!==intent.projectId || independentTask
92
+ ||prePermitRecovery)||preNativeGhost;
52
93
  if(replace&&!matchingBlocked)return {status:'DENIED',code:'BLOCKED_REPLACEMENT_MISMATCH'};
53
94
  if(prior&&prior.phase!=='DONE'&&!matchingBlocked)
54
95
  return {status:'DENIED',code:'LOOP_ALREADY_ACTIVE'};
@@ -56,7 +97,15 @@ async function sessionStartPrepare(message,sender){
56
97
  if(disk?.status!=='OK')return {status:'DENIED',code:'SESSION_STATE_UNVERIFIED'};
57
98
  const ownerMatches=Boolean(prior?.sessionId&&disk.session
58
99
  &&matchesNativeProjection(sessionProjection(prior),disk.session));
59
- if(matchingBlocked&&!ownerMatches)
100
+ const sameTaskNative=Boolean((prePermitRecovery||preNativeGhost)
101
+ &&disk.session?.sessionId===replace&&disk.session.phase==='BLOCKED'
102
+ &&disk.session.projectId===intent.projectId
103
+ &&disk.session.taskId===intent.taskId&&disk.session.generation===0
104
+ &&disk.session.activeChatId===null&&disk.session.activeChatUrl===null
105
+ &&Number.isSafeInteger(disk.session.updatedAt)
106
+ &&disk.session.updatedAt>0);
107
+ if((matchingBlocked&&!(ownerMatches||(preNativeGhost&&sameTaskNative)))
108
+ ||((prePermitRecovery||preNativeGhost)&&!sameTaskNative))
60
109
  return {status:'DENIED',code:'SESSION_REPLACEMENT_MISMATCH'};
61
110
  // A terminal Worker record cannot authorize a new Start if a different
62
111
  // durable Native Owner exists under the same Browser installation.
@@ -112,6 +161,10 @@ async function sessionStartPrepare(message,sender){
112
161
  page:'/',tabId:null,startedAt:Date.now(),
113
162
  machineRequestId:message.requestId,machineActionTabId:sender.tab.id,
114
163
  ...(matchingBlocked?{replacedBlockedSessionId:replace}:{}),
164
+ ...(prePermitRecovery||preNativeGhost?{
165
+ prePermitRetryUsed:true,
166
+ ...(preNativeGhost?{preNativeRepairUsed:true}:{}),
167
+ sameTaskPrePermitUpdatedAt:disk.session.updatedAt}:{}),
115
168
  ...(adoption?{mode:'adopt',adoptTabId:adoption.target.tabId,
116
169
  adoptPage:adoption.target.page,adoptUserKey:adoption.target.userKey,
117
170
  ...((intent.chatUrl||adoption.target.explicitChatId)
@@ -99,7 +99,9 @@ async function saveRun(run) {
99
99
  const saved=await chrome.runtime.sendNativeMessage(SESSION_HOST,
100
100
  {op:"session-sync",session:record,
101
101
  ...(next.replacedBlockedSessionId&&!recoveryCommit&&next.phase==='STARTING'
102
- ?{replaceBlockedSessionId:next.replacedBlockedSessionId}:{}),
102
+ ?{replaceBlockedSessionId:next.replacedBlockedSessionId,
103
+ ...(Number.isSafeInteger(next.sameTaskPrePermitUpdatedAt)
104
+ ?{sameTaskPrePermitUpdatedAt:next.sameTaskPrePermitUpdatedAt}:{})}:{}),
103
105
  ...(recoveryCommit?{resumeBlockedSessionId:next.sessionId,
104
106
  resumeBlockedUpdatedAt:next.recoveryExpectedNativeAt}:{})}).catch(()=>null);
105
107
  // Native acknowledgment must match the whole immutable Owner pointer,
@@ -60,7 +60,7 @@ export function readSession(){
60
60
  try{return validate(JSON.parse(readFileSync(file,'utf8')));}
61
61
  catch(e){if(e.code)throw e;throw fail('SESSION_FILE_CORRUPT');}
62
62
  }
63
- export function writeSession(input,replaceBlockedSessionId=null,resumeBlockedSessionId=null,resumeBlockedUpdatedAt=null){
63
+ export function writeSession(input,replaceBlockedSessionId=null,resumeBlockedSessionId=null,resumeBlockedUpdatedAt=null,sameTaskPrePermitUpdatedAt=null){
64
64
  const next=validate(input),file=sessionPath(),dir=dirname(file),lock=file+'.lock';
65
65
  ensurePrivate(dir);
66
66
  let fd;
@@ -88,11 +88,25 @@ export function writeSession(input,replaceBlockedSessionId=null,resumeBlockedSes
88
88
  if(replaceBlockedSessionId && (!old||old.sessionId!==next.sessionId
89
89
  && (old.phase!=='BLOCKED'||old.sessionId!==replaceBlockedSessionId)))
90
90
  throw fail('SESSION_REPLACEMENT_MISMATCH');
91
+ // The Worker alone identifies the pre-permit failure. Native requires
92
+ // an independent one-shot disk CAS before allowing the SAME scoped Task
93
+ // to replace its unsent BLOCKED session; other BLOCKED phases stay locked.
94
+ const prePermitCas=Number.isSafeInteger(sameTaskPrePermitUpdatedAt)
95
+ &&sameTaskPrePermitUpdatedAt>0&&old?.updatedAt===sameTaskPrePermitUpdatedAt
96
+ &&old.phase==='BLOCKED'&&old.sessionId===replaceBlockedSessionId
97
+ &&old.projectId===next.projectId&&typeof old.taskId==='string'
98
+ &&old.taskId===next.taskId&&next.sessionId!==old.sessionId
99
+ &&old.generation===0&&next.generation===0&&next.phase==='STARTING'
100
+ &&old.activeChatId===null&&old.activeChatUrl===null
101
+ &&next.activeChatId===null&&next.activeChatUrl===null;
102
+ if(sameTaskPrePermitUpdatedAt!==null&&!prePermitCas)
103
+ throw fail('SESSION_PRE_PERMIT_CAS_MISMATCH');
91
104
  if(old&&old.sessionId!==next.sessionId&&old.phase!=='DONE'
92
105
  && !(old.phase==='BLOCKED' && next.phase==='STARTING'
93
106
  && replaceBlockedSessionId===old.sessionId
94
107
  && (next.projectId!==old.projectId
95
- ||next.taskId!==undefined&&next.taskId!==old.taskId)))
108
+ ||next.taskId!==undefined&&next.taskId!==old.taskId
109
+ ||prePermitCas)))
96
110
  throw fail('SESSION_ALREADY_ACTIVE');
97
111
  if(old&&old.sessionId===next.sessionId){
98
112
  if(next.projectId!==old.projectId)throw fail('SESSION_PROJECT_CHANGED');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomflow/chatloop-extension",
3
- "version": "0.4.24",
3
+ "version": "0.4.26",
4
4
  "type": "module",
5
5
  "description": "Chat Loop Extension: reviewed formal Action pages, including TEST_ONLY native App entry",
6
6
  "bin": {