@tomflow/chatloop-tools 0.9.55 → 0.9.57
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/node_modules/@tomflow/chatloop-context/lib/core/run.mjs +27 -1
- package/node_modules/@tomflow/chatloop-context/package.json +2 -2
- package/node_modules/@tomflow/chatloop-extension/extension/loop/observer-approval.js +4 -0
- package/node_modules/@tomflow/chatloop-extension/extension/manifest.json +1 -1
- package/node_modules/@tomflow/chatloop-extension/extension/worker/admission.js +1 -1
- package/node_modules/@tomflow/chatloop-extension/extension/worker/adopt-prepare.js +50 -8
- package/node_modules/@tomflow/chatloop-extension/extension/worker/bootstrap.js +17 -0
- package/node_modules/@tomflow/chatloop-extension/extension/worker/readiness.js +9 -2
- package/node_modules/@tomflow/chatloop-extension/package.json +1 -1
- package/package.json +3 -3
|
@@ -39,7 +39,33 @@ export function createRunMethods(values) {
|
|
|
39
39
|
assert(r.approval_revision===a.expectedApprovalRevision,'APPROVAL_CONFLICT');
|
|
40
40
|
assert(!projectDrift(r).projectDrift,'PROJECT_RULES_DRIFT');
|
|
41
41
|
ensureNoPendingIssue(a.projectId,a.taskId);
|
|
42
|
-
|
|
42
|
+
const approvals=parse(r.approval_json);
|
|
43
|
+
assert(hasApprovedPlan(approvals),'APPROVAL_REVOKED');
|
|
44
|
+
// Managed original-Chat Adopt is not authorized by a valid lease
|
|
45
|
+
// alone. The observed R/P user turns must also be those approved for
|
|
46
|
+
// THIS Task. The browser proof is soft; Native still owns the lease,
|
|
47
|
+
// CAS and one-use permit. No new approval or second fact store.
|
|
48
|
+
if(a.adopt!==undefined||a.approvalEvidence!==undefined){
|
|
49
|
+
assert(a.kind==='START'&&a.adopt===true,
|
|
50
|
+
'ADOPTION_APPROVAL_EVIDENCE_REQUIRED');
|
|
51
|
+
const e=a.approvalEvidence;
|
|
52
|
+
const validTurn=(kind,record)=>{
|
|
53
|
+
const text=e?.[kind+'UserText'],key=e?.[kind+'UserKey'];
|
|
54
|
+
return typeof text==='string'&&text.length>0&&text.length<=1000
|
|
55
|
+
&&typeof key==='string'&&/^user:[^\s]{8,}$/.test(key)
|
|
56
|
+
&&(record.userTurn===text||record.userTurn===key)
|
|
57
|
+
&&e[kind+'Version']===(typeof record.version==='number'
|
|
58
|
+
?kind.toUpperCase()+record.version:record.version);
|
|
59
|
+
};
|
|
60
|
+
assert(e&&typeof e==='object'&&!Array.isArray(e)
|
|
61
|
+
&&Object.keys(e).length===6
|
|
62
|
+
&&['rUserText','rUserKey','rVersion','pUserText',
|
|
63
|
+
'pUserKey','pVersion'].every(k=>Object.hasOwn(e,k)),
|
|
64
|
+
'ADOPTION_APPROVAL_EVIDENCE_REQUIRED');
|
|
65
|
+
assert(validTurn('r',approvals[0])&&validTurn('p',approvals[1])
|
|
66
|
+
&&e.rUserKey!==e.pUserKey,
|
|
67
|
+
'ADOPTION_APPROVAL_SOURCE_MISMATCH');
|
|
68
|
+
}
|
|
43
69
|
if(['CONTINUE','HANDOFF'].includes(a.kind)){
|
|
44
70
|
// A terminal Task with no holder is NOT eligible for more work.
|
|
45
71
|
// Only a named pending Handoff may reserve the single NOT_SENT
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tomflow/chatloop-context",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.20",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Independent local Context SDK and short-lived CLI for Chat Loop projects",
|
|
6
6
|
"publishConfig": {
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"ps-list": "9.0.0",
|
|
37
|
-
"@tomflow/chatloop-extension": "0.4.
|
|
37
|
+
"@tomflow/chatloop-extension": "0.4.29",
|
|
38
38
|
"@tomflow/chatloop-trace": "0.4.6"
|
|
39
39
|
}
|
|
40
40
|
}
|
|
@@ -277,6 +277,10 @@ if (message?.type === "CHAT_LOOP_APPROVAL_EVIDENCE_V1") {
|
|
|
277
277
|
}
|
|
278
278
|
reply({contract:CONTRACT,status:"VERIFIED",page:path,
|
|
279
279
|
userKey,rVersion,pVersion,priorAssistantKey:messageId(pAssistant.el,"assistant"),
|
|
280
|
+
// Ephemeral approval source for Native/Context comparison at permit
|
|
281
|
+
// consumption. Never persisted in Chrome storage, logs or Owner state.
|
|
282
|
+
approvalTurns:{rUserKey:messageId(rUser.el,"user"),
|
|
283
|
+
rUserText:textOf(rUser),pUserText:textOf(pUser)},
|
|
280
284
|
// Idle post-approval assistant was completed BEFORE adoption.
|
|
281
285
|
// This is a historical baseline, never a fresh execution Turn.
|
|
282
286
|
...(scopedIdle?{postApprovalAssistantKey:snap.assistantKey}:{})});
|
|
@@ -27,7 +27,7 @@ async function approvedAdoptionTarget(chatUrl=null,taskId=null){
|
|
|
27
27
|
const proof=await chrome.tabs.sendMessage(opened.id,
|
|
28
28
|
{type:"CHAT_LOOP_APPROVAL_EVIDENCE_V1",
|
|
29
29
|
explicitChatId:requestedId,
|
|
30
|
-
...(taskId?{expectedTaskId:taskId}:{})}).catch(()=>null);
|
|
30
|
+
...(!requestedId&&taskId?{expectedTaskId:taskId}:{})}).catch(()=>null);
|
|
31
31
|
if(proof?.contract==="chat-loop.turn-observer.v1"
|
|
32
32
|
&&proof.status==="VERIFIED"
|
|
33
33
|
&&chatIdOf('https://chatgpt.com'+proof.page)===requestedId){
|
|
@@ -87,14 +87,22 @@ async function sessionStartPrepare(message,sender){
|
|
|
87
87
|
&&!!intent.chatUrl&&prior.adoptPage===pathOf(intent.chatUrl)
|
|
88
88
|
&&Number.isInteger(prior.adoptTabId)
|
|
89
89
|
&&typeof prior.adoptUserKey==='string');
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
90
|
+
const disk=await chrome.runtime.sendNativeMessage(SESSION_HOST,{op:'session-read'}).catch(()=>null);
|
|
91
|
+
if(disk?.status!=='OK')return {status:'DENIED',code:'SESSION_STATE_UNVERIFIED'};
|
|
92
|
+
// A Worker ghost from a timed-out, no-send Adopt may disagree with the
|
|
93
|
+
// durable Native BLOCKED ID. Only an independently approved DIFFERENT Task
|
|
94
|
+
// may supersede the exact Native pointer, never the same old Task or Chat.
|
|
95
|
+
const driftReplacement=Boolean(independentTask&&replace
|
|
96
|
+
&&replace===disk.session?.sessionId
|
|
97
|
+
&&independentBlockedAdoptDrift(prior,disk.session)
|
|
98
|
+
&&!!intent.chatUrl&&pathOf(intent.chatUrl)!==prior.adoptPage);
|
|
99
|
+
const matchingBlocked=Boolean(prior?.phase==='BLOCKED'
|
|
100
|
+
&&prior.sessionId===replace
|
|
101
|
+
&&(prior.projectId!==intent.projectId||independentTask
|
|
102
|
+
||prePermitRecovery)||preNativeGhost||driftReplacement);
|
|
93
103
|
if(replace&&!matchingBlocked)return {status:'DENIED',code:'BLOCKED_REPLACEMENT_MISMATCH'};
|
|
94
104
|
if(prior&&prior.phase!=='DONE'&&!matchingBlocked)
|
|
95
105
|
return {status:'DENIED',code:'LOOP_ALREADY_ACTIVE'};
|
|
96
|
-
const disk=await chrome.runtime.sendNativeMessage(SESSION_HOST,{op:'session-read'}).catch(()=>null);
|
|
97
|
-
if(disk?.status!=='OK')return {status:'DENIED',code:'SESSION_STATE_UNVERIFIED'};
|
|
98
106
|
const ownerMatches=Boolean(prior?.sessionId&&disk.session
|
|
99
107
|
&&matchesNativeProjection(sessionProjection(prior),disk.session));
|
|
100
108
|
const sameTaskNative=Boolean((prePermitRecovery||preNativeGhost)
|
|
@@ -104,7 +112,8 @@ async function sessionStartPrepare(message,sender){
|
|
|
104
112
|
&&disk.session.activeChatId===null&&disk.session.activeChatUrl===null
|
|
105
113
|
&&Number.isSafeInteger(disk.session.updatedAt)
|
|
106
114
|
&&disk.session.updatedAt>0);
|
|
107
|
-
if((matchingBlocked&&!(ownerMatches||(preNativeGhost&&sameTaskNative)
|
|
115
|
+
if((matchingBlocked&&!(ownerMatches||(preNativeGhost&&sameTaskNative)
|
|
116
|
+
||driftReplacement))
|
|
108
117
|
||((prePermitRecovery||preNativeGhost)&&!sameTaskNative))
|
|
109
118
|
return {status:'DENIED',code:'SESSION_REPLACEMENT_MISMATCH'};
|
|
110
119
|
// A terminal Worker record cannot authorize a new Start if a different
|
|
@@ -135,7 +144,8 @@ async function sessionStartPrepare(message,sender){
|
|
|
135
144
|
:await approvedAdoptionTarget(intent.chatUrl||null,
|
|
136
145
|
intent.contextLeaseRef?intent.taskId:null):null;
|
|
137
146
|
if(adoption?.error)return {status:'DENIED',code:adoption.error};
|
|
138
|
-
if(matchingBlocked&&adoption?.target?.page===prior.page&&prior.page)
|
|
147
|
+
if((matchingBlocked&&adoption?.target?.page===prior.page&&prior.page)
|
|
148
|
+
||(driftReplacement&&adoption?.target?.page===prior.adoptPage))
|
|
139
149
|
return {status:'DENIED',code:'BLOCKED_REPLACEMENT_CHAT_REUSE'};
|
|
140
150
|
// A Project-scoped Chat cannot safely hand off to the ordinary home route:
|
|
141
151
|
// reject BEFORE claiming Owner instead of failing after four hours.
|
|
@@ -189,6 +199,36 @@ async function sessionStartTake(message,sender){
|
|
|
189
199
|
if(!sessionPage(sender,'start',message.requestId)||run?.machineRequestId!==message.requestId
|
|
190
200
|
||run.machineActionTabId!==sender.tab.id||run.token!==message.token
|
|
191
201
|
||run.phase!=='STARTING')return {status:'DENIED',code:'START_OWNER_CHANGED'};
|
|
202
|
+
// Verify the real R/P source again immediately before asking Context to
|
|
203
|
+
// consume the Start lease. Never persist approval text in Worker storage.
|
|
204
|
+
let approvalEvidence=null;
|
|
205
|
+
if(run.contextLeaseRef&&run.mode==='adopt'
|
|
206
|
+
&&run.purpose!=='REPAIR_SAME_SCOPE'){
|
|
207
|
+
const proof=await chrome.tabs.sendMessage(run.adoptTabId,{
|
|
208
|
+
type:'CHAT_LOOP_APPROVAL_EVIDENCE_V1',
|
|
209
|
+
...(run.adoptExplicitChatId?{explicitChatId:run.adoptExplicitChatId}:{}),
|
|
210
|
+
...(run.adoptExpectedTaskId?{expectedTaskId:run.adoptExpectedTaskId}:{})
|
|
211
|
+
}).catch(()=>null);
|
|
212
|
+
const current=policy.normalizeAdoptionEvidence(proof,{page:run.adoptPage});
|
|
213
|
+
const original={page:run.adoptPage,userKey:run.adoptUserKey,
|
|
214
|
+
priorAssistantKey:run.adoptPriorAssistantKey||null,
|
|
215
|
+
postApprovalAssistantKey:run.adoptPostApprovalAssistantKey||null,
|
|
216
|
+
rVersion:run.adoptRVersion,pVersion:run.adoptPVersion};
|
|
217
|
+
const source=proof?.approvalTurns;
|
|
218
|
+
if(!policy.sameAdoptionEvidence(original,current)
|
|
219
|
+
||!source||typeof source.rUserKey!=='string'
|
|
220
|
+
||!/^user:[^\s]{8,}$/.test(source.rUserKey)
|
|
221
|
+
||source.rUserKey===run.adoptUserKey
|
|
222
|
+
||!['rUserText','pUserText'].every(k=>typeof source[k]==='string'
|
|
223
|
+
&&source[k].length>0&&source[k].length<=1000)){
|
|
224
|
+
await saveRun({...run,phase:'BLOCKED',
|
|
225
|
+
reason:'ADOPTION_APPROVAL_SOURCE_UNVERIFIED'});
|
|
226
|
+
return {status:'DENIED',code:'ADOPTION_APPROVAL_SOURCE_UNVERIFIED'};
|
|
227
|
+
}
|
|
228
|
+
approvalEvidence={rUserText:source.rUserText,rUserKey:source.rUserKey,
|
|
229
|
+
rVersion:run.adoptRVersion,pUserText:source.pUserText,
|
|
230
|
+
pUserKey:run.adoptUserKey,pVersion:run.adoptPVersion};
|
|
231
|
+
}
|
|
192
232
|
await saveRun({...run,phase:'PENDING'});
|
|
193
233
|
// Native validates current durable Session and signs the narrow Context IPC.
|
|
194
234
|
// No Context adapter? Legacy Start behavior remains unchanged.
|
|
@@ -198,7 +238,9 @@ async function sessionStartTake(message,sender){
|
|
|
198
238
|
args:{expectedStoreEpoch:run.contextStoreEpoch,writeRequestId:run.token,
|
|
199
239
|
expectedTaskRevision:run.contextTaskRevision,
|
|
200
240
|
expectedApprovalRevision:run.contextApprovalRevision,
|
|
201
|
-
actionToken:run.token,kind:'START',leaseRef:run.contextLeaseRef
|
|
241
|
+
actionToken:run.token,kind:'START',leaseRef:run.contextLeaseRef,
|
|
242
|
+
...(run.mode==='adopt'&&run.purpose!=='REPAIR_SAME_SCOPE'
|
|
243
|
+
?{adopt:true,approvalEvidence}:{})}
|
|
202
244
|
}).catch(()=>null);
|
|
203
245
|
if(allowed?.status!=='OK'||allowed.result?.status!=='PERMITTED'){
|
|
204
246
|
await saveRun({...run,phase:'BLOCKED',reason:'CONTEXT_START_PERMIT_UNVERIFIED'});
|
|
@@ -148,6 +148,23 @@ const matchesNativeProjection=(projected,native)=>Boolean(native
|
|
|
148
148
|
// Read-only status diagnosis: reveal field NAMES only, never Owner identities.
|
|
149
149
|
const sessionProjectionDrift=(projected,native)=>SESSION_POINTER_KEYS.filter(
|
|
150
150
|
key=>projected[key]!==native?.[key]);
|
|
151
|
+
// Two distinct durable IDs may exist after an interrupted Adopt reservation.
|
|
152
|
+
// 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.
|
|
154
|
+
const independentBlockedAdoptDrift=(run,native)=>Boolean(
|
|
155
|
+
run?.phase==='BLOCKED'&&run.reason==='ACTION_RESULT_TIMEOUT_UNVERIFIED'
|
|
156
|
+
&&run.action==='START'&&run.mode==='adopt'
|
|
157
|
+
&&run.contextLeaseRef&&!run.contextManaged
|
|
158
|
+
&&run.generation===0&&run.tabId===null&&run.page==='/'
|
|
159
|
+
&&!run.userKey&&!run.newUserKey&&!run.assistantKey
|
|
160
|
+
&&!run.attemptedNewTabId&&!run.lastStartActionTabId
|
|
161
|
+
&&typeof run.adoptPage==='string'&&run.adoptPage.startsWith('/c/')
|
|
162
|
+
&&Number.isInteger(run.adoptTabId)&&typeof run.adoptUserKey==='string'
|
|
163
|
+
&&native?.phase==='BLOCKED'&&native.generation===0
|
|
164
|
+
&&native.activeChatId===null&&native.activeChatUrl===null
|
|
165
|
+
&&native.projectId===run.projectId&&native.taskId===run.taskId
|
|
166
|
+
&&typeof native.sessionId==='string'&&native.sessionId!==run.sessionId
|
|
167
|
+
&&Number.isSafeInteger(native.updatedAt)&&native.updatedAt>0);
|
|
151
168
|
const sessionPage=(sender,name,id)=> Number.isInteger(sender.tab?.id)
|
|
152
169
|
&& typeof id==='string'&&/^[a-f0-9]{32}$/.test(id)
|
|
153
170
|
&& sender.url===chrome.runtime.getURL(name+'.html')+'?requestId='+id;
|
|
@@ -154,9 +154,16 @@ async function sessionStatus(message,sender){
|
|
|
154
154
|
traceParent:message.auditDispatchParent}:{})}).catch(()=>null);
|
|
155
155
|
if(disk?.status!=='OK')return {status:'UNVERIFIED',code:'SESSION_STATE_UNVERIFIED'};
|
|
156
156
|
const projection=run?.sessionId?sessionProjection(run):null;
|
|
157
|
-
if(projection&&!matchesNativeProjection(projection,disk.session))
|
|
157
|
+
if(projection&&!matchesNativeProjection(projection,disk.session)){
|
|
158
|
+
const mismatchedFields=sessionProjectionDrift(projection,disk.session);
|
|
158
159
|
return {status:'UNVERIFIED',code:'SESSION_FILE_MISMATCH',
|
|
159
|
-
mismatchedFields
|
|
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'}}:{})};
|
|
166
|
+
}
|
|
160
167
|
if(!run?.sessionId&&disk.session&&disk.session.phase!=='DONE')
|
|
161
168
|
return {status:'UNVERIFIED',code:'SESSION_OWNER_MISMATCH'};
|
|
162
169
|
if(run&&run.phase!=='DONE'&&!run.sessionId)
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "0.9.
|
|
6
|
+
"version": "0.9.57",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"description": "Chat Loop local tools: MCP gateway, isolated bundled tunnel-client and unified CLI",
|
|
9
9
|
"bin": {
|
|
@@ -33,11 +33,11 @@
|
|
|
33
33
|
"prepack": "node ./scripts/build-providers.mjs --check && node ./scripts/build-form-app.mjs --check && node ./scripts/build-document-app.mjs --check"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@tomflow/chatloop-context": "0.6.
|
|
36
|
+
"@tomflow/chatloop-context": "0.6.20",
|
|
37
37
|
"@tomflow/chatloop-trace": "0.4.6",
|
|
38
38
|
"@wonderwhy-er/desktop-commander": "0.2.44",
|
|
39
39
|
"ps-list": "9.0.0",
|
|
40
|
-
"@tomflow/chatloop-extension": "0.4.
|
|
40
|
+
"@tomflow/chatloop-extension": "0.4.29"
|
|
41
41
|
},
|
|
42
42
|
"bundleDependencies": [
|
|
43
43
|
"@tomflow/chatloop-context",
|