@tomflow/chatloop-extension 0.4.25 → 0.4.27
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 +7 -3
- package/bin/native-host.mjs +2 -1
- package/extension/manifest.json +1 -1
- package/extension/worker/adopt-prepare.js +34 -3
- package/extension/worker/bootstrap.js +6 -1
- package/extension/worker/readiness.js +2 -1
- package/lib/bridge.mjs +2 -0
- package/lib/session-file.mjs +16 -2
- package/package.json +1 -1
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
|
|
@@ -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,
|
|
@@ -143,6 +145,9 @@ const SESSION_POINTER_KEYS=Object.freeze(['sessionId','projectId','taskId','phas
|
|
|
143
145
|
'generation','activeChatId','activeChatUrl']);
|
|
144
146
|
const matchesNativeProjection=(projected,native)=>Boolean(native
|
|
145
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]);
|
|
146
151
|
const sessionPage=(sender,name,id)=> Number.isInteger(sender.tab?.id)
|
|
147
152
|
&& typeof id==='string'&&/^[a-f0-9]{32}$/.test(id)
|
|
148
153
|
&& sender.url===chrome.runtime.getURL(name+'.html')+'?requestId='+id;
|
|
@@ -155,7 +155,8 @@ async function sessionStatus(message,sender){
|
|
|
155
155
|
if(disk?.status!=='OK')return {status:'UNVERIFIED',code:'SESSION_STATE_UNVERIFIED'};
|
|
156
156
|
const projection=run?.sessionId?sessionProjection(run):null;
|
|
157
157
|
if(projection&&!matchesNativeProjection(projection,disk.session))
|
|
158
|
-
return {status:'UNVERIFIED',code:'SESSION_FILE_MISMATCH'
|
|
158
|
+
return {status:'UNVERIFIED',code:'SESSION_FILE_MISMATCH',
|
|
159
|
+
mismatchedFields:sessionProjectionDrift(projection,disk.session)};
|
|
159
160
|
if(!run?.sessionId&&disk.session&&disk.session.phase!=='DONE')
|
|
160
161
|
return {status:'UNVERIFIED',code:'SESSION_OWNER_MISMATCH'};
|
|
161
162
|
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/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');
|