@tomflow/chatloop-extension 0.4.25 → 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.
|
|
90
|
-
|
|
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
|
|
package/bin/native-host.mjs
CHANGED
|
@@ -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,
|
|
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.
|
package/extension/manifest.json
CHANGED
|
@@ -67,9 +67,29 @@ async function sessionStartPrepare(message,sender){
|
|
|
67
67
|
&&!!intent.chatUrl&&prior.adoptPage===pathOf(intent.chatUrl)
|
|
68
68
|
&&Number.isInteger(prior.adoptTabId)
|
|
69
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');
|
|
70
90
|
const matchingBlocked=prior?.phase==='BLOCKED' && prior.sessionId===replace
|
|
71
91
|
&& (prior.projectId!==intent.projectId || independentTask
|
|
72
|
-
||prePermitRecovery);
|
|
92
|
+
||prePermitRecovery)||preNativeGhost;
|
|
73
93
|
if(replace&&!matchingBlocked)return {status:'DENIED',code:'BLOCKED_REPLACEMENT_MISMATCH'};
|
|
74
94
|
if(prior&&prior.phase!=='DONE'&&!matchingBlocked)
|
|
75
95
|
return {status:'DENIED',code:'LOOP_ALREADY_ACTIVE'};
|
|
@@ -77,7 +97,15 @@ async function sessionStartPrepare(message,sender){
|
|
|
77
97
|
if(disk?.status!=='OK')return {status:'DENIED',code:'SESSION_STATE_UNVERIFIED'};
|
|
78
98
|
const ownerMatches=Boolean(prior?.sessionId&&disk.session
|
|
79
99
|
&&matchesNativeProjection(sessionProjection(prior),disk.session));
|
|
80
|
-
|
|
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))
|
|
81
109
|
return {status:'DENIED',code:'SESSION_REPLACEMENT_MISMATCH'};
|
|
82
110
|
// A terminal Worker record cannot authorize a new Start if a different
|
|
83
111
|
// durable Native Owner exists under the same Browser installation.
|
|
@@ -133,7 +161,10 @@ async function sessionStartPrepare(message,sender){
|
|
|
133
161
|
page:'/',tabId:null,startedAt:Date.now(),
|
|
134
162
|
machineRequestId:message.requestId,machineActionTabId:sender.tab.id,
|
|
135
163
|
...(matchingBlocked?{replacedBlockedSessionId:replace}:{}),
|
|
136
|
-
...(prePermitRecovery?{
|
|
164
|
+
...(prePermitRecovery||preNativeGhost?{
|
|
165
|
+
prePermitRetryUsed:true,
|
|
166
|
+
...(preNativeGhost?{preNativeRepairUsed:true}:{}),
|
|
167
|
+
sameTaskPrePermitUpdatedAt:disk.session.updatedAt}:{}),
|
|
137
168
|
...(adoption?{mode:'adopt',adoptTabId:adoption.target.tabId,
|
|
138
169
|
adoptPage:adoption.target.page,adoptUserKey:adoption.target.userKey,
|
|
139
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,
|
package/lib/session-file.mjs
CHANGED
|
@@ -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');
|