@tomflow/chatloop-extension 0.4.38 → 0.4.39

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.
@@ -51,7 +51,7 @@ process.stdin.on('data',async chunk=>{
51
51
  try{projectContext=session?registeredContext(session.projectId):null;
52
52
  if(projectContext)contextStatus='VERIFIED';}catch{contextStatus='UNVERIFIED';}
53
53
  write({status:'OK',session,contextStatus,...(projectContext?{projectContext}:{})});
54
- }else if(['session-read-v2','session-sync-v2','session-snapshot-v2',
54
+ }else if(['session-read-v2','session-sync-v2','start-prepermit-verify-v2','session-snapshot-v2',
55
55
  'context-status-v2','context-writer-check-v2',
56
56
  'context-control-v2','continue-permit-v2',
57
57
  'continue-reconcile-v2','continue-send-check-v2',
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "manifest_version": 3,
3
3
  "name": "Chat Loop Extension",
4
- "version": "0.4.38",
4
+ "version": "0.4.39",
5
5
  "description": "Chat Loop browser companion: Eye actions, Turn observer, Continue and Handoff Actions",
6
6
  "permissions": [
7
7
  "activeTab",
@@ -111,9 +111,45 @@ async function scopedTaskStartPrepare(message,sender,source){
111
111
  const native=await scopedStartNative({
112
112
  op:'session-read-v2',sourceRequestId:requestId});
113
113
  if(existing.run){
114
- // Only resume the SAME private Start request before any Permit is
115
- // consumed. The original random Session is never replaced or guessed.
116
114
  const prior=existing.run,s=native?.session;
115
+ if(prior.startRequestId!==requestId){
116
+ // One fresh signed request may reclaim the SAME unbound reservation.
117
+ // Native+Context must prove a unique fresh lease and zero permits.
118
+ scopedStartAssert(prior.phase==='RESERVED'&&s?.phase==='RESERVED'
119
+ &&prior.prePermitRecoveryUsed!==true
120
+ &&intent.replaceBlockedSessionId===prior.sessionId
121
+ &&s.sessionId===prior.sessionId
122
+ &&s.projectId===intent.projectId&&s.taskId===intent.taskId
123
+ &&s.revision===prior.nativeOwnerRevision&&s.generation===0
124
+ &&s.activeChatId===null&&s.activeChatUrl===null,
125
+ 'SCOPED_START_PREPERMIT_RECOVERY_DENIED');
126
+ const approved=await scopedStartEvidence(intent);
127
+ scopedStartAssert(approved.tabId===prior.adoptTabId
128
+ &&approved.page===prior.adoptPage
129
+ &&approved.evidence.userKey===prior.adoptUserKey
130
+ &&approved.evidence.rVersion===prior.adoptRVersion
131
+ &&approved.evidence.pVersion===prior.adoptPVersion,
132
+ 'SCOPED_START_PREPERMIT_APPROVAL_CHANGED');
133
+ const checked=await scopedStartNative({op:'start-prepermit-verify-v2',
134
+ sourceRequestId:requestId,expectedSessionId:prior.sessionId,
135
+ expectedNativeRevision:s.revision});
136
+ scopedStartAssert(checked?.status==='OK'
137
+ &&checked.scope==='TASK_SCOPED_PREPERMIT_VERIFIED'
138
+ &&checked.projectId===intent.projectId&&checked.taskId===intent.taskId
139
+ &&checked.sessionId===prior.sessionId
140
+ &&checked.nativeOwnerRevision===s.revision,
141
+ 'SCOPED_START_PREPERMIT_CONTEXT_UNVERIFIED');
142
+ const repaired=await scopedTaskRuns.put({...prior,
143
+ startRequestId:requestId,actionTabId,prePermitRecoveryUsed:true},{
144
+ expectedStoreRevision:existing.storeRevision,
145
+ expectedRunRevision:existing.runRevision});
146
+ scopedStartAssert(repaired.runRevision>existing.runRevision,
147
+ 'SCOPED_START_PREPERMIT_ACK_UNKNOWN');
148
+ return {status:'PREPARED',scope:'TASK_SCOPED_ADOPT_NO_SEND',
149
+ sessionId:prior.sessionId,tabId:approved.tabId,
150
+ page:approved.page,userKey:approved.evidence.userKey};
151
+ }
152
+ // Same private request only; never reconsume a Permit.
117
153
  scopedStartAssert(prior.startRequestId===requestId
118
154
  &&prior.actionTabId===actionTabId
119
155
  &&['STARTING','RESERVED'].includes(prior.phase),
package/lib/bridge.mjs CHANGED
@@ -168,8 +168,7 @@ function validateIntent(action, intent, fromStoredRequest=false) {
168
168
  ||(intent.taskFirst!==undefined
169
169
  &&(intent.taskFirst!==true||intent.mode!=='adopt'
170
170
  ||!intent.taskId||!intent.chatUrl||!intent.contextLeaseRef
171
- ||intent.purpose!==undefined
172
- ||intent.replaceBlockedSessionId!==undefined))
171
+ ||intent.purpose!==undefined))
173
172
  ||intent.confirmed!==true || (intent.mode!==undefined && intent.mode!=='adopt')
174
173
  || (intent.replaceBlockedSessionId!==undefined
175
174
  && !/^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i.test(intent.replaceBlockedSessionId))
@@ -18,6 +18,7 @@ import {createScopedTerminalControl} from './scoped-terminal-v2.mjs';
18
18
  import {createScopedCancelControl} from './scoped-cancel-v2.mjs';
19
19
  import {createScopedRetireControl} from './scoped-retire-v2.mjs';
20
20
  import {createScopedRecoveryControl} from './scoped-recovery-v2.mjs';
21
+ import {createScopedStartRecoveryControl} from './scoped-start-recovery.mjs';
21
22
  // Mutating Start operations require a private request and exact Ledger CAS.
22
23
  // Exact-identity snapshot and writer checks are read-only, never sender permits.
23
24
  export function createScopedNativeControl(ports){
@@ -27,12 +28,13 @@ export function createScopedNativeControl(ports){
27
28
  const handoffControl=createScopedHandoffControl(ports);
28
29
  const recoveryControl=createScopedRecoveryControl({
29
30
  ...ports,verifyOriginalAbort:m=>handoffControl.handle(m)});
30
- const terminalControl=createScopedTerminalControl(ports);
31
- const cancelControl=createScopedCancelControl(ports);
31
+ const terminalControl=createScopedTerminalControl(ports),cancelControl=createScopedCancelControl(ports);
32
32
  const retireControl=createScopedRetireControl(ports);
33
+ const startRecoveryControl=createScopedStartRecoveryControl(ports);
33
34
  if([readRequest,readScopedOwner,writeScopedOwner,nativeContextControl]
34
35
  .some(port=>typeof port!=='function'))throw Error('SCOPED_NATIVE_PORTS_MISSING');
35
36
  return async function handleScopedNativeMessage(m){
37
+ if(m?.op==='start-prepermit-verify-v2')return startRecoveryControl(m);
36
38
  let result=null;
37
39
  const write=value=>{result=value};
38
40
  if(['continue-permit-v2','continue-reconcile-v2',
@@ -247,7 +249,7 @@ export function createScopedNativeControl(ports){
247
249
  // ONLY by the same private Start request. No guessed Session ID,
248
250
  // task-only fallback, or replay of a Context START Permit.
249
251
  if(!s||s.projectId!==intent.projectId||s.taskId!==intent.taskId
250
- ||s.sessionId!==startSessionForRequest(m.sourceRequestId)
252
+ ||!(s.sessionId===startSessionForRequest(m.sourceRequestId) ||committing&&intent.replaceBlockedSessionId===s.sessionId)
251
253
  ||s.generation!==0||!(prepermit||committing)
252
254
  ||!Number.isSafeInteger(m.expectedLedgerRevision)
253
255
  ||m.expectedLedgerRevision<0)
@@ -0,0 +1,53 @@
1
+ // Read-only same-Task pre-Permit recovery proof; never changes Owner or sends.
2
+ export function createScopedStartRecoveryControl(ports){
3
+ const {readRequest,readScopedOwner,nativeContextControl}=ports;
4
+ const fail=code=>Object.assign(Error(code),{code});
5
+ return async m=>{
6
+ if(m?.op!=='start-prepermit-verify-v2'
7
+ ||Object.keys(m).length!==4
8
+ ||!/^[a-f0-9]{32}$/.test(m.sourceRequestId||'')
9
+ ||!/^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i.test(m.expectedSessionId||'')
10
+ ||!Number.isSafeInteger(m.expectedNativeRevision)
11
+ ||m.expectedNativeRevision<1)
12
+ throw fail('SCOPED_PREPERMIT_REQUEST_INVALID');
13
+ const request=readRequest(m.sourceRequestId),i=request?.intent;
14
+ if(request?.action!=='start'||i?.taskFirst!==true
15
+ ||i.mode!=='adopt'||i.confirmed!==true
16
+ ||i.replaceBlockedSessionId!==m.expectedSessionId
17
+ ||typeof i.contextLeaseRef!=='string'
18
+ ||typeof i.contextStoreEpoch!=='string'
19
+ ||!Number.isSafeInteger(i.contextTaskRevision)
20
+ ||!Number.isSafeInteger(i.contextApprovalRevision))
21
+ throw fail('SCOPED_PREPERMIT_SOURCE_INVALID');
22
+ const prior=readScopedOwner(i.projectId,i.taskId).session;
23
+ if(!prior||prior.sessionId!==m.expectedSessionId
24
+ ||prior.revision!==m.expectedNativeRevision
25
+ ||prior.phase!=='RESERVED'||prior.generation!==0
26
+ ||prior.activeChatId!==null||prior.activeChatUrl!==null)
27
+ throw fail('SCOPED_PREPERMIT_OWNER_CHANGED');
28
+ const proof=Object.fromEntries(['projectId','taskId','sessionId',
29
+ 'generation','revision','phase','activeChatId']
30
+ .map(k=>[k,prior[k]]));
31
+ const state=await nativeContextControl('run.terminalStatus',{
32
+ projectId:prior.projectId,taskId:prior.taskId,
33
+ sessionId:prior.sessionId,generation:0,activeChatId:null,
34
+ startRecoveryLeaseRef:i.contextLeaseRef},{ownerProofV2:proof});
35
+ if(state?.startRecovery?.status!=='UNBOUND_NO_PERMIT'
36
+ ||state.startRecovery.leaseRef!==i.contextLeaseRef
37
+ ||state.storeEpoch!==i.contextStoreEpoch
38
+ ||state.taskRevision!==i.contextTaskRevision
39
+ ||state.approvalRevision!==i.contextApprovalRevision
40
+ ||state.bindingRevision!==0||state.runRef!==null
41
+ ||state.unknownEffectCount!==0||state.pendingHandoff!==false
42
+ ||state.pendingCheckpointId!==null||state.executionOutcome!==null
43
+ ||state.sessionCancellation!==null||state.projectRulesDrift!==false)
44
+ throw fail('SCOPED_PREPERMIT_CONTEXT_UNVERIFIED');
45
+ const fresh=readScopedOwner(i.projectId,i.taskId).session;
46
+ if(!fresh||fresh.sessionId!==prior.sessionId
47
+ ||fresh.revision!==prior.revision||fresh.phase!=='RESERVED')
48
+ throw fail('SCOPED_PREPERMIT_OWNER_CHANGED');
49
+ return {status:'OK',scope:'TASK_SCOPED_PREPERMIT_VERIFIED',
50
+ projectId:i.projectId,taskId:i.taskId,
51
+ sessionId:prior.sessionId,nativeOwnerRevision:prior.revision};
52
+ };
53
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomflow/chatloop-extension",
3
- "version": "0.4.38",
3
+ "version": "0.4.39",
4
4
  "type": "module",
5
5
  "description": "Chat Loop Extension: reviewed formal Action pages, including TEST_ONLY native App entry",
6
6
  "bin": {