@tomflow/chatloop-tools 0.9.57 → 0.9.59
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/docs/interfaces.md +8 -0
- package/node_modules/@tomflow/chatloop-context/index.mjs +2 -1
- package/node_modules/@tomflow/chatloop-context/lib/approval-policy.mjs +58 -0
- package/node_modules/@tomflow/chatloop-context/lib/core/health.mjs +27 -8
- package/node_modules/@tomflow/chatloop-context/lib/core/run.mjs +12 -9
- package/node_modules/@tomflow/chatloop-context/lib/core/store.mjs +4 -4
- package/node_modules/@tomflow/chatloop-context/lib/trusted-run.mjs +10 -3
- package/node_modules/@tomflow/chatloop-context/package.json +2 -2
- package/node_modules/@tomflow/chatloop-extension/extension/manifest.json +1 -1
- package/node_modules/@tomflow/chatloop-extension/extension/worker/adopt-prepare.js +26 -6
- package/node_modules/@tomflow/chatloop-extension/extension/worker/bootstrap.js +19 -6
- package/node_modules/@tomflow/chatloop-extension/extension/worker/readiness.js +18 -7
- package/node_modules/@tomflow/chatloop-extension/package.json +1 -1
- package/package.json +3 -3
|
@@ -102,6 +102,14 @@ The Tools private handler passes a signed-IPC-verified Native projection into th
|
|
|
102
102
|
|
|
103
103
|
The Browser Native Host now permits the Worker-used `run.reopenStatus`
|
|
104
104
|
through the same signed private IPC path; it is not a public MCP method.
|
|
105
|
+
For first-Start recovery, `run.terminalStatus` accepts the private
|
|
106
|
+
`startRecoveryLeaseRef` only for a generation-zero Native BLOCKED pointer
|
|
107
|
+
without an active Chat. It returns `UNBOUND_NO_PERMIT` only when the exact
|
|
108
|
+
fresh lease is the sole valid reservation, no prior permit was consumed,
|
|
109
|
+
no writer/unknown effect exists, and current approvals remain valid.
|
|
110
|
+
`start.reserve` rejects a previously consumed initial permit and removes
|
|
111
|
+
expired unused initial leases transactionally; the read-only proof does not
|
|
112
|
+
grant a permit, bind a writer, or replace a Session.
|
|
105
113
|
|
|
106
114
|
## 5. Context → external dependencies (reverse direction)
|
|
107
115
|
|
|
@@ -65,7 +65,8 @@ function sdkRuntime(){
|
|
|
65
65
|
verifySourceUnit:migration.verifySourceUnit,
|
|
66
66
|
inspectRegistryReferenceForReview:migration.inspectRegistryReferenceForReview,
|
|
67
67
|
hasApprovedPlan:policy.hasApprovedPlan,
|
|
68
|
-
hasRequirementApproval:policy.hasRequirementApproval
|
|
68
|
+
hasRequirementApproval:policy.hasRequirementApproval,
|
|
69
|
+
approvedTurnSourceMatches:policy.approvedTurnSourceMatches
|
|
69
70
|
});
|
|
70
71
|
projectStore.configureProjectStore({
|
|
71
72
|
parseContextAllowedProjects:methods.parseContextAllowedProjects
|
|
@@ -17,3 +17,61 @@ export function hasApprovedPlan(records){
|
|
|
17
17
|
&&fromUser(records[0])&&fromUser(records[1])
|
|
18
18
|
&&records[0].userTurn!==records[1].userTurn;
|
|
19
19
|
}
|
|
20
|
+
|
|
21
|
+
const FORM_UUID='[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}';
|
|
22
|
+
const FORM_HEADER='Chat Loop Form 提交结果(由用户点击表单提交)';
|
|
23
|
+
const FORM_NOTE='请核对当前业务任务、文档与 Issue 版本及原生消息身份后处理本次选择;表单回执本身不构成审批或写权。';
|
|
24
|
+
const versionedLabel=(version,label,kind)=>version[0]===kind
|
|
25
|
+
&&(kind==='R'?label==='需求'
|
|
26
|
+
:['技术与验证方案','技术方案','方案'].includes(label));
|
|
27
|
+
const formReceipt=(text,kind,stored)=>{
|
|
28
|
+
if(typeof text!=='string'||text.length>1000)return null;
|
|
29
|
+
let formId,traceRef,version,label;
|
|
30
|
+
if(stored){
|
|
31
|
+
// Existing Context approval.observe callers persisted this exact bounded
|
|
32
|
+
// Form summary, NOT the multiline ChatGPT user Turn visible to Observer.
|
|
33
|
+
const m=text.match(new RegExp('^Chat Loop Form 提交结果(由用户点击表单提交);formId=('+
|
|
34
|
+
FORM_UUID+');traceRef=('+FORM_UUID+');A[||]确认当前 ([RP][1-9][0-9]*) (需求|技术与验证方案|技术方案|方案)$','i'));
|
|
35
|
+
if(!m)return null;
|
|
36
|
+
[,formId,traceRef,version,label]=m;
|
|
37
|
+
}else{
|
|
38
|
+
const lines=text.split(/\r?\n/).map(x=>x.trim()).filter(Boolean);
|
|
39
|
+
if(lines.length!==6||lines[0]!=='Chat Loop Form 提交结果(由用户点击表单提交)'
|
|
40
|
+
||lines[3]!=='选项值: A'||lines[5]!==FORM_NOTE)return null;
|
|
41
|
+
const id=lines[1].match(new RegExp('^formId:\\s*('+FORM_UUID+')$','i'));
|
|
42
|
+
const trace=lines[2].match(new RegExp('^traceRef:\\s*('+FORM_UUID+')$','i'));
|
|
43
|
+
const choice=lines[4].match(/^选项标签:\s*A[||]\s*确认当前\s*([RP][1-9][0-9]*)\s*(需求|技术与验证方案|技术方案|方案)$/i);
|
|
44
|
+
if(!id||!trace||!choice)return null;
|
|
45
|
+
formId=id[1];traceRef=trace[1];version=choice[1];label=choice[2];
|
|
46
|
+
}
|
|
47
|
+
version=version.toUpperCase();
|
|
48
|
+
if(!versionedLabel(version,label,kind)
|
|
49
|
+
||formId.toLowerCase()===traceRef.toLowerCase())return null;
|
|
50
|
+
return {formId:formId.toLowerCase(),traceRef:traceRef.toLowerCase(),version,label};
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// The single Context policy for matching an immutable approval source to
|
|
54
|
+
// soft, ephemeral browser evidence. A summary is accepted ONLY through an
|
|
55
|
+
// exact Form A schema; task identity remains the Context row + live lease.
|
|
56
|
+
export function approvedTurnSourceMatches(record,observed,kind){
|
|
57
|
+
if(!record||record.kind!==kind||!observed
|
|
58
|
+
||typeof observed.userText!=='string'||observed.userText.length>1000
|
|
59
|
+
||typeof observed.userKey!=='string'||!/^user:[^\s]{8,}$/.test(observed.userKey)
|
|
60
|
+
||!/^([RP])[1-9][0-9]*$/.test(observed.version)
|
|
61
|
+
||observed.version[0]!==kind
|
|
62
|
+
||observed.version!==kind+String(record.version).replace(/^[RP]/,'')
|
|
63
|
+
||(record.sourceRole!==undefined&&record.sourceRole!=='user'))return false;
|
|
64
|
+
// A stored Form summary cannot authenticate a browser message that merely
|
|
65
|
+
// copies the summary. Require the six-line original user-turn template.
|
|
66
|
+
if(typeof record.userTurn==='string'
|
|
67
|
+
&&record.userTurn.startsWith(FORM_HEADER)){
|
|
68
|
+
const stored=formReceipt(record.userTurn,kind,true)
|
|
69
|
+
||formReceipt(record.userTurn,kind,false);
|
|
70
|
+
const actual=formReceipt(observed.userText,kind,false);
|
|
71
|
+
return Boolean(stored&&actual
|
|
72
|
+
&&stored.formId===actual.formId&&stored.traceRef===actual.traceRef
|
|
73
|
+
&&stored.version===actual.version&&stored.label===actual.label
|
|
74
|
+
&&stored.version===observed.version);
|
|
75
|
+
}
|
|
76
|
+
return record.userTurn===observed.userText||record.userTurn===observed.userKey;
|
|
77
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Context Core health methods. Shared access and transactions are injected from store.mjs.
|
|
2
2
|
export function createHealthMethods(values) {
|
|
3
|
-
const {assert, parse, db, epoch, storeMode, hasApprovedPlan, required, checkIds, admin, readAuth, unresolvedEffects} = values;
|
|
3
|
+
const {assert, parse, db, epoch, storeMode, hasApprovedPlan, required, checkIds, admin, readAuth, unresolvedEffects, readSnapshot, projectDrift, ensureNoPendingIssue} = values;
|
|
4
4
|
return {
|
|
5
5
|
pragmas:()=>({
|
|
6
6
|
journalMode:db.prepare('PRAGMA journal_mode').get().journal_mode,
|
|
@@ -28,14 +28,33 @@ export function createHealthMethods(values) {
|
|
|
28
28
|
reopenUserTurn:c.reopenRequest?.userTurn??null,
|
|
29
29
|
previousDeliveryRef:c.deliveryRef??null};
|
|
30
30
|
},
|
|
31
|
-
terminalStatus(projectId,taskId){
|
|
31
|
+
terminalStatus(projectId,taskId,startRecoveryLeaseRef=null){
|
|
32
32
|
checkIds(projectId,taskId);readAuth(projectId,taskId,'run.terminalStatus');
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
33
|
+
return readSnapshot(()=>{
|
|
34
|
+
const r=required(projectId,taskId),c=parse(r.context_json);
|
|
35
|
+
const state={projectId,taskId,taskRevision:r.business_revision,
|
|
36
|
+
bindingRevision:r.binding_revision,approvalRevision:r.approval_revision,
|
|
37
|
+
unknownEffectCount:unresolvedEffects(c).length,
|
|
38
|
+
runRef:r.writable_ref,executionOutcome:c.executionOutcome??null,
|
|
39
|
+
deliveryRef:c.deliveryRef??null};
|
|
40
|
+
if(startRecoveryLeaseRef===null)return state;
|
|
41
|
+
// Read-only, scoped to the fresh lease. The prior expired leases were
|
|
42
|
+
// removed transactionally by reserve; no prior permit may exist.
|
|
43
|
+
assert(r.binding_revision===0&&r.writable_ref===null&&r.pending_attempt===null
|
|
44
|
+
&&state.unknownEffectCount===0&&state.executionOutcome===null
|
|
45
|
+
&&!['ARCHIVED','DELIVERED','REOPENED'].includes(c.stage)
|
|
46
|
+
&&!projectDrift(r).projectDrift&&hasApprovedPlan(parse(r.approval_json)),
|
|
47
|
+
'START_RECOVERY_UNSAFE');
|
|
48
|
+
ensureNoPendingIssue(projectId,taskId);
|
|
49
|
+
const leases=db.prepare('SELECT * FROM start_leases WHERE project_id=? AND task_id=?')
|
|
50
|
+
.all(projectId,taskId);
|
|
51
|
+
assert(leases.length===1&&leases[0].lease_ref===startRecoveryLeaseRef
|
|
52
|
+
&&leases[0].expires_at>Date.now()&&leases[0].business_revision===r.business_revision
|
|
53
|
+
&&leases[0].approval_revision===r.approval_revision,'START_RECOVERY_LEASE_UNVERIFIED');
|
|
54
|
+
assert(!db.prepare('SELECT 1 FROM permits WHERE project_id=? AND task_id=? LIMIT 1')
|
|
55
|
+
.get(projectId,taskId),'START_PERMIT_ALREADY_CONSUMED');
|
|
56
|
+
return {...state,storeEpoch:epoch,startRecovery:{status:'UNBOUND_NO_PERMIT',leaseRef:startRecoveryLeaseRef}};
|
|
57
|
+
});
|
|
39
58
|
},
|
|
40
59
|
latestCheckpoint(projectId,taskId){
|
|
41
60
|
checkIds(projectId,taskId);readAuth(projectId,taskId,'context.latestCheckpoint');
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Context Core run methods. Shared access and transactions are injected from store.mjs.
|
|
2
2
|
export function createRunMethods(values) {
|
|
3
|
-
const {fail, assert, ID, runDigest, parse, db, epoch, hasApprovedPlan, randomUUID, projectDrift, receipt, internal, admin, unresolvedEffects, ensureNoPendingIssue, expectedBusiness, expectedBinding, assertPinnedHandoffCurrent, scope} = values;
|
|
3
|
+
const {fail, assert, ID, runDigest, parse, db, epoch, hasApprovedPlan, approvedTurnSourceMatches, randomUUID, projectDrift, receipt, internal, admin, unresolvedEffects, ensureNoPendingIssue, expectedBusiness, expectedBinding, assertPinnedHandoffCurrent, scope} = values;
|
|
4
4
|
return {
|
|
5
5
|
reserve(a){
|
|
6
6
|
return receipt(a,'start.reserve',()=>{
|
|
@@ -25,6 +25,14 @@ export function createRunMethods(values) {
|
|
|
25
25
|
assert(current.executionOutcome!=='DONE'&¤t.stage!=='ARCHIVED',
|
|
26
26
|
'TASK_ALREADY_DELIVERED');
|
|
27
27
|
}
|
|
28
|
+
// Never re-reserve an initial Start whose execution permit may have
|
|
29
|
+
// been consumed. Expired, unconsumed leases cannot commit later.
|
|
30
|
+
if(r.binding_revision===0){
|
|
31
|
+
assert(!db.prepare('SELECT 1 FROM permits WHERE project_id=? AND task_id=? LIMIT 1')
|
|
32
|
+
.get(a.projectId,a.taskId),'START_PERMIT_ALREADY_CONSUMED');
|
|
33
|
+
db.prepare('DELETE FROM start_leases WHERE project_id=? AND task_id=? AND expires_at<=?')
|
|
34
|
+
.run(a.projectId,a.taskId,Date.now());
|
|
35
|
+
}
|
|
28
36
|
const leaseRef=randomUUID();
|
|
29
37
|
db.prepare('INSERT INTO start_leases VALUES(?,?,?,?,?,?)').run(leaseRef,
|
|
30
38
|
a.projectId,a.taskId,r.approval_revision,r.business_revision,Date.now()+60000);
|
|
@@ -49,14 +57,9 @@ export function createRunMethods(values) {
|
|
|
49
57
|
assert(a.kind==='START'&&a.adopt===true,
|
|
50
58
|
'ADOPTION_APPROVAL_EVIDENCE_REQUIRED');
|
|
51
59
|
const e=a.approvalEvidence;
|
|
52
|
-
const validTurn=(kind,record)=>{
|
|
53
|
-
|
|
54
|
-
|
|
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
|
+
const validTurn=(kind,record)=>approvedTurnSourceMatches(record,{
|
|
61
|
+
userText:e?.[kind+'UserText'],userKey:e?.[kind+'UserKey'],
|
|
62
|
+
version:e?.[kind+'Version']},kind.toUpperCase());
|
|
60
63
|
assert(e&&typeof e==='object'&&!Array.isArray(e)
|
|
61
64
|
&&Object.keys(e).length===6
|
|
62
65
|
&&['rUserText','rUserKey','rVersion','pUserText',
|
|
@@ -7,14 +7,14 @@ import {dirname} from 'node:path';
|
|
|
7
7
|
|
|
8
8
|
// This module declares ports; index.mjs is the only dependency assembler.
|
|
9
9
|
// No implementation module imports another implementation module.
|
|
10
|
-
let createHealthMethods, createMigrationMethods, createProjectMethods, createTaskMethods, createReviewMethods, createEvidenceMethods, createContextMethods, createRunMethods, verifySourceUnit, inspectRegistryReferenceForReview, hasApprovedPlan, hasRequirementApproval;
|
|
10
|
+
let createHealthMethods, createMigrationMethods, createProjectMethods, createTaskMethods, createReviewMethods, createEvidenceMethods, createContextMethods, createRunMethods, verifySourceUnit, inspectRegistryReferenceForReview, hasApprovedPlan, hasRequirementApproval, approvedTurnSourceMatches;
|
|
11
11
|
let connected=false;
|
|
12
12
|
export function configureCore(capabilities){
|
|
13
13
|
if(connected)throw Error('CONTEXT_MODULE_ALREADY_COMPOSED');
|
|
14
|
-
for(const name of ['createHealthMethods', 'createMigrationMethods', 'createProjectMethods', 'createTaskMethods', 'createReviewMethods', 'createEvidenceMethods', 'createContextMethods', 'createRunMethods', 'verifySourceUnit', 'inspectRegistryReferenceForReview', 'hasApprovedPlan', 'hasRequirementApproval']){
|
|
14
|
+
for(const name of ['createHealthMethods', 'createMigrationMethods', 'createProjectMethods', 'createTaskMethods', 'createReviewMethods', 'createEvidenceMethods', 'createContextMethods', 'createRunMethods', 'verifySourceUnit', 'inspectRegistryReferenceForReview', 'hasApprovedPlan', 'hasRequirementApproval', 'approvedTurnSourceMatches']){
|
|
15
15
|
if(capabilities?.[name]===undefined)throw Error('CONTEXT_MODULE_PORT_MISSING:'+name);
|
|
16
16
|
}
|
|
17
|
-
({createHealthMethods, createMigrationMethods, createProjectMethods, createTaskMethods, createReviewMethods, createEvidenceMethods, createContextMethods, createRunMethods, verifySourceUnit, inspectRegistryReferenceForReview, hasApprovedPlan, hasRequirementApproval}=capabilities);
|
|
17
|
+
({createHealthMethods, createMigrationMethods, createProjectMethods, createTaskMethods, createReviewMethods, createEvidenceMethods, createContextMethods, createRunMethods, verifySourceUnit, inspectRegistryReferenceForReview, hasApprovedPlan, hasRequirementApproval, approvedTurnSourceMatches}=capabilities);
|
|
18
18
|
connected=true;
|
|
19
19
|
}
|
|
20
20
|
|
|
@@ -380,7 +380,7 @@ export function openContextProtocol(file,{authorizeInternal=()=>false,authorizeD
|
|
|
380
380
|
// never expose raw credential or hash, including pending digest
|
|
381
381
|
});
|
|
382
382
|
const scope=(a)=>required(a.projectId,a.taskId);
|
|
383
|
-
const scopeValues={fail, assert, ID, canonical, digest, runDigest, parse, db, epoch, storeMode, principalId, authorizeData, authorizeAdmin, enableTestFixtures, verifySourceUnit, inspectRegistryReferenceForReview, hasApprovedPlan, hasRequirementApproval, randomUUID, row, required, projectDrift, currentMode, readSnapshot, checkIds, receipt, internal, admin, readAuth, validContextPatch, unresolvedEffects, ensureNoPendingIssue, expectedBusiness, expectedBinding, assertPinnedHandoffCurrent, written, saveTaskContext, publicTask, scope};
|
|
383
|
+
const scopeValues={fail, assert, ID, canonical, digest, runDigest, parse, db, epoch, storeMode, principalId, authorizeData, authorizeAdmin, enableTestFixtures, verifySourceUnit, inspectRegistryReferenceForReview, hasApprovedPlan, hasRequirementApproval, approvedTurnSourceMatches, randomUUID, row, required, projectDrift, currentMode, readSnapshot, checkIds, receipt, internal, admin, readAuth, validContextPatch, unresolvedEffects, ensureNoPendingIssue, expectedBusiness, expectedBinding, assertPinnedHandoffCurrent, written, saveTaskContext, publicTask, scope};
|
|
384
384
|
// Domain modules share ONE SQLite handle, transaction gate, and receipt authority.
|
|
385
385
|
return Object.assign({epoch,mode:storeMode},
|
|
386
386
|
createHealthMethods(scopeValues),
|
|
@@ -28,11 +28,17 @@ export function executeTrustedRun(command,args,native){
|
|
|
28
28
|
assert(!['principal','role','internalAuthorized','ownerCommitted',
|
|
29
29
|
'nativeCommitted'].some(k=>Object.hasOwn(args,k)),
|
|
30
30
|
'CLIENT_AUTH_FIELD_FORBIDDEN');
|
|
31
|
+
const startRecovery=command==='run.terminalStatus'&&Object.hasOwn(args,'startRecoveryLeaseRef');
|
|
32
|
+
if(startRecovery)assert(native.phase==='BLOCKED'&&native.generation===0
|
|
33
|
+
&&native.activeChatId===null&&native.activeChatUrl===null
|
|
34
|
+
&&typeof args.startRecoveryLeaseRef==='string'
|
|
35
|
+
&&/^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i.test(args.startRecoveryLeaseRef),
|
|
36
|
+
'START_RECOVERY_NATIVE_UNVERIFIED');
|
|
31
37
|
assert(native.projectId===args.projectId && native.taskId===args.taskId
|
|
32
38
|
&& native.sessionId===args.sessionId
|
|
33
39
|
&& native.generation===args.generation
|
|
34
40
|
&& native.activeChatId===args.activeChatId
|
|
35
|
-
&& (native.activeChatId!==null || command==='permit.consume'&&args.kind==='START'),
|
|
41
|
+
&& (native.activeChatId!==null || command==='permit.consume'&&args.kind==='START'||startRecovery),
|
|
36
42
|
'CONTEXT_NATIVE_BINDING_MISMATCH');
|
|
37
43
|
const allowed=allowedProjects();
|
|
38
44
|
assert(allowed.has(native.projectId),'PROJECT_ACCESS_DENIED');
|
|
@@ -59,11 +65,12 @@ export function executeTrustedRun(command,args,native){
|
|
|
59
65
|
const db=openContextProtocol(file,{principalId:'native-controlled',
|
|
60
66
|
authorizeData:(_access,p)=>allowed.has(p),authorizeInternal:()=>true});
|
|
61
67
|
try{
|
|
62
|
-
if(
|
|
68
|
+
if((startRecovery||!['run.terminalStatus','run.reopenStatus','run.snapshot'].includes(command))
|
|
63
69
|
&&!db.projectBusinessAuthority(args.projectId).writable)
|
|
64
70
|
throw fail('PROJECT_CUTOVER_NOT_VERIFIED');
|
|
65
71
|
switch(command){
|
|
66
|
-
case 'run.terminalStatus':return db.terminalStatus(args.projectId,args.taskId
|
|
72
|
+
case 'run.terminalStatus':return db.terminalStatus(args.projectId,args.taskId,
|
|
73
|
+
startRecovery?args.startRecoveryLeaseRef:null);
|
|
67
74
|
case 'run.reopenStatus':return db.reopenStatus(args.projectId,args.taskId);
|
|
68
75
|
case 'run.snapshot':return db.latestCheckpoint(args.projectId,args.taskId);
|
|
69
76
|
case 'permit.consume':return db.consumePermit(args);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tomflow/chatloop-context",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.22",
|
|
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.30",
|
|
38
38
|
"@tomflow/chatloop-trace": "0.4.6"
|
|
39
39
|
}
|
|
40
40
|
}
|
|
@@ -62,8 +62,8 @@ async function sessionStartPrepare(message,sender){
|
|
|
62
62
|
&&prior.contextStoreEpoch===intent.contextStoreEpoch
|
|
63
63
|
&&prior.contextTaskRevision===intent.contextTaskRevision
|
|
64
64
|
&&prior.contextApprovalRevision===intent.contextApprovalRevision
|
|
65
|
-
&&prior.tabId===null&&prior.page==='/'&&!prior.newUserKey
|
|
66
|
-
&&!prior.userKey&&!prior.attemptedNewTabId
|
|
65
|
+
&&prior.generation===0&&prior.tabId===null&&prior.page==='/'&&!prior.newUserKey
|
|
66
|
+
&&!prior.userKey&&!prior.assistantKey&&!prior.attemptedNewTabId&&!prior.lastStartActionTabId
|
|
67
67
|
&&!!intent.chatUrl&&prior.adoptPage===pathOf(intent.chatUrl)
|
|
68
68
|
&&Number.isInteger(prior.adoptTabId)
|
|
69
69
|
&&typeof prior.adoptUserKey==='string');
|
|
@@ -71,7 +71,9 @@ async function sessionStartPrepare(message,sender){
|
|
|
71
71
|
// rejected its CAS, Worker/Native disagree. No send was attempted, but this
|
|
72
72
|
// is NOT a free retry: one exact native-BLOCKED repair with a fresh lease
|
|
73
73
|
// is allowed; any managed writer, late send or second repair remains denied.
|
|
74
|
-
const
|
|
74
|
+
const timedOutGhost=prior?.phase==='BLOCKED'
|
|
75
|
+
&&prior.reason==='ACTION_RESULT_TIMEOUT_UNVERIFIED';
|
|
76
|
+
const preNativeGhost=Boolean((prior?.phase==='STARTING'||timedOutGhost)
|
|
75
77
|
&&prior.action==='START'&&prior.mode==='adopt'
|
|
76
78
|
&&prior.prePermitRetryUsed===true&&!prior.preNativeRepairUsed
|
|
77
79
|
&&prior.replacedBlockedSessionId===replace
|
|
@@ -82,8 +84,8 @@ async function sessionStartPrepare(message,sender){
|
|
|
82
84
|
&&prior.contextStoreEpoch===intent.contextStoreEpoch
|
|
83
85
|
&&prior.contextTaskRevision===intent.contextTaskRevision
|
|
84
86
|
&&prior.contextApprovalRevision===intent.contextApprovalRevision
|
|
85
|
-
&&prior.tabId===null&&prior.page==='/'&&!prior.newUserKey
|
|
86
|
-
&&!prior.userKey&&!prior.attemptedNewTabId
|
|
87
|
+
&&prior.generation===0&&prior.tabId===null&&prior.page==='/'&&!prior.newUserKey
|
|
88
|
+
&&!prior.userKey&&!prior.assistantKey&&!prior.attemptedNewTabId&&!prior.lastStartActionTabId
|
|
87
89
|
&&!!intent.chatUrl&&prior.adoptPage===pathOf(intent.chatUrl)
|
|
88
90
|
&&Number.isInteger(prior.adoptTabId)
|
|
89
91
|
&&typeof prior.adoptUserKey==='string');
|
|
@@ -114,8 +116,24 @@ async function sessionStartPrepare(message,sender){
|
|
|
114
116
|
&&disk.session.updatedAt>0);
|
|
115
117
|
if((matchingBlocked&&!(ownerMatches||(preNativeGhost&&sameTaskNative)
|
|
116
118
|
||driftReplacement))
|
|
117
|
-
||((prePermitRecovery||preNativeGhost)&&!sameTaskNative)
|
|
119
|
+
||((prePermitRecovery||preNativeGhost)&&!sameTaskNative)
|
|
120
|
+
||(preNativeGhost&&timedOutGhost&&!independentBlockedAdoptDrift(prior,disk.session)))
|
|
118
121
|
return {status:'DENIED',code:'SESSION_REPLACEMENT_MISMATCH'};
|
|
122
|
+
if(prePermitRecovery||preNativeGhost){
|
|
123
|
+
// Native's durable old pointer scopes this read. A new lease or null
|
|
124
|
+
// runRef alone cannot prove the old START permit was never consumed.
|
|
125
|
+
const proof=await chrome.runtime.sendNativeMessage(SESSION_HOST,{
|
|
126
|
+
op:'context-control',command:'run.terminalStatus',
|
|
127
|
+
args:{startRecoveryLeaseRef:intent.contextLeaseRef}}).catch(()=>null);
|
|
128
|
+
const s=proof?.result;
|
|
129
|
+
if(proof?.status!=='OK'||s?.projectId!==intent.projectId||s?.taskId!==intent.taskId
|
|
130
|
+
||s.storeEpoch!==intent.contextStoreEpoch||s.taskRevision!==intent.contextTaskRevision
|
|
131
|
+
||s.approvalRevision!==intent.contextApprovalRevision||s.bindingRevision!==0
|
|
132
|
+
||s.runRef!==null||s.unknownEffectCount!==0||s.executionOutcome!==null
|
|
133
|
+
||s.startRecovery?.status!=='UNBOUND_NO_PERMIT'
|
|
134
|
+
||s.startRecovery.leaseRef!==intent.contextLeaseRef)
|
|
135
|
+
return {status:'DENIED',code:'START_RECOVERY_PERMIT_UNVERIFIED'};
|
|
136
|
+
}
|
|
119
137
|
// A terminal Worker record cannot authorize a new Start if a different
|
|
120
138
|
// durable Native Owner exists under the same Browser installation.
|
|
121
139
|
if(prior?.phase==='DONE'&&prior.sessionId&&disk.session&&!ownerMatches)
|
|
@@ -144,6 +162,8 @@ async function sessionStartPrepare(message,sender){
|
|
|
144
162
|
:await approvedAdoptionTarget(intent.chatUrl||null,
|
|
145
163
|
intent.contextLeaseRef?intent.taskId:null):null;
|
|
146
164
|
if(adoption?.error)return {status:'DENIED',code:adoption.error};
|
|
165
|
+
if((prePermitRecovery||preNativeGhost)&&adoption?.target?.userKey!==prior.adoptUserKey)
|
|
166
|
+
return {status:'DENIED',code:'START_RECOVERY_APPROVAL_CHANGED'};
|
|
147
167
|
if((matchingBlocked&&adoption?.target?.page===prior.page&&prior.page)
|
|
148
168
|
||(driftReplacement&&adoption?.target?.page===prior.adoptPage))
|
|
149
169
|
return {status:'DENIED',code:'BLOCKED_REPLACEMENT_CHAT_REUSE'};
|
|
@@ -93,6 +93,10 @@ async function saveRun(run) {
|
|
|
93
93
|
if(recoveryCommit&&(!Number.isSafeInteger(next.recoveryExpectedNativeAt)
|
|
94
94
|
||next.recoveryExpectedNativeAt<=0))
|
|
95
95
|
throw Error('SESSION_RECOVERY_CAS_MISSING');
|
|
96
|
+
// Native must commit first for the exact terminal CAS transitions.
|
|
97
|
+
const replacementCommit=Boolean(next.replacedBlockedSessionId
|
|
98
|
+
&&next.phase==='STARTING'&&stored?.sessionId!==next.sessionId);
|
|
99
|
+
const nativeFirst=recoveryCommit||replacementCommit;
|
|
96
100
|
const syncNative=async()=>{
|
|
97
101
|
if(!next.sessionId)return;
|
|
98
102
|
const record=sessionProjection(next);
|
|
@@ -104,18 +108,26 @@ async function saveRun(run) {
|
|
|
104
108
|
?{sameTaskPrePermitUpdatedAt:next.sameTaskPrePermitUpdatedAt}:{})}:{}),
|
|
105
109
|
...(recoveryCommit?{resumeBlockedSessionId:next.sessionId,
|
|
106
110
|
resumeBlockedUpdatedAt:next.recoveryExpectedNativeAt}:{})}).catch(()=>null);
|
|
111
|
+
// A fresh replacement Session ID identifies this exact CAS. If its
|
|
112
|
+
// transport reply was lost, confirm the durable projection once, without
|
|
113
|
+
// replaying the write. Same-ID recovery has no such unique commit proof.
|
|
114
|
+
if(!saved&&replacementCommit){
|
|
115
|
+
const observed=await chrome.runtime.sendNativeMessage(SESSION_HOST,
|
|
116
|
+
{op:'session-read'}).catch(()=>null);
|
|
117
|
+
if(observed?.status==='OK'&&matchesNativeProjection(record,observed.session))return;
|
|
118
|
+
}
|
|
107
119
|
// Native acknowledgment must match the whole immutable Owner pointer,
|
|
108
120
|
// not merely its sessionId and phase. updatedAt is CAS metadata, not
|
|
109
121
|
// part of this identity projection.
|
|
110
122
|
if(saved?.status!=="OK"||!matchesNativeProjection(record,saved.session))
|
|
111
123
|
throw Error(saved?.code||"SESSION_PERSISTENCE_UNVERIFIED");
|
|
112
124
|
};
|
|
113
|
-
//
|
|
114
|
-
// Do not
|
|
115
|
-
//
|
|
116
|
-
if(
|
|
125
|
+
// BLOCKED recovery and replacement both require a Native CAS first.
|
|
126
|
+
// Do not publish a new Worker reservation when Native rejects the CAS.
|
|
127
|
+
// An unknown acknowledgement stays fail-closed; never replay a Start.
|
|
128
|
+
if(nativeFirst)await syncNative();
|
|
117
129
|
await chrome.storage.local.set({[RUN_KEY]:next});
|
|
118
|
-
if(!
|
|
130
|
+
if(!nativeFirst)await syncNative();
|
|
119
131
|
// The resource inventory is derived evidence; it never grants browser Owner.
|
|
120
132
|
if (["DONE","BLOCKED"].includes(next.phase)
|
|
121
133
|
&& next.contextTerminalFence !== "PENDING"
|
|
@@ -150,7 +162,8 @@ const sessionProjectionDrift=(projected,native)=>SESSION_POINTER_KEYS.filter(
|
|
|
150
162
|
key=>projected[key]!==native?.[key]);
|
|
151
163
|
// Two distinct durable IDs may exist after an interrupted Adopt reservation.
|
|
152
164
|
// This narrow read-only shape proves NEITHER a previous send nor authority to
|
|
153
|
-
// replace it
|
|
165
|
+
// replace it. Adopt admission separately verifies independent Task replacement
|
|
166
|
+
// or the exact same-Task pre-permit recovery contract before Native CAS.
|
|
154
167
|
const independentBlockedAdoptDrift=(run,native)=>Boolean(
|
|
155
168
|
run?.phase==='BLOCKED'&&run.reason==='ACTION_RESULT_TIMEOUT_UNVERIFIED'
|
|
156
169
|
&&run.action==='START'&&run.mode==='adopt'
|
|
@@ -156,13 +156,24 @@ async function sessionStatus(message,sender){
|
|
|
156
156
|
const projection=run?.sessionId?sessionProjection(run):null;
|
|
157
157
|
if(projection&&!matchesNativeProjection(projection,disk.session)){
|
|
158
158
|
const mismatchedFields=sessionProjectionDrift(projection,disk.session);
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
159
|
+
const blockedAdoptDrift=mismatchedFields.length===1&&mismatchedFields[0]==='sessionId'
|
|
160
|
+
&&independentBlockedAdoptDrift(run,disk.session);
|
|
161
|
+
// Only a locator for the exact old reservation, never a permit or Owner.
|
|
162
|
+
const prePermitCandidate=blockedAdoptDrift&&run.prePermitRetryUsed===true
|
|
163
|
+
&&!run.preNativeRepairUsed&&run.replacedBlockedSessionId===disk.session.sessionId
|
|
164
|
+
&&typeof run.contextStoreEpoch==='string'&&Number.isSafeInteger(run.contextTaskRevision)
|
|
165
|
+
&&Number.isSafeInteger(run.contextApprovalRevision)
|
|
166
|
+
&&pathOf('https://chatgpt.com'+run.adoptPage)===run.adoptPage;
|
|
167
|
+
return {status:'UNVERIFIED',code:'SESSION_FILE_MISMATCH',mismatchedFields,
|
|
168
|
+
diagnostics:{extensionVersion:chrome.runtime.getManifest?.().version||null},
|
|
169
|
+
...(blockedAdoptDrift?{independentTaskReplacementCandidate:{
|
|
170
|
+
replaceBlockedSessionId:disk.session.sessionId,
|
|
171
|
+
requires:'FRESH_APPROVED_DISTINCT_TASK_AND_NATIVE_CAS'}}:{}),
|
|
172
|
+
...(prePermitCandidate?{sameTaskPrePermitRecoveryCandidate:{
|
|
173
|
+
projectId:run.projectId,taskId:run.taskId,
|
|
174
|
+
replaceBlockedSessionId:disk.session.sessionId,
|
|
175
|
+
originalChatUrl:'https://chatgpt.com'+run.adoptPage,
|
|
176
|
+
requires:'FRESH_LEASE_NO_PRIOR_PERMIT_ORIGINAL_APPROVAL_AND_NATIVE_CAS'}}:{})};
|
|
166
177
|
}
|
|
167
178
|
if(!run?.sessionId&&disk.session&&disk.session.phase!=='DONE')
|
|
168
179
|
return {status:'UNVERIFIED',code:'SESSION_OWNER_MISMATCH'};
|
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.59",
|
|
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.22",
|
|
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.30"
|
|
41
41
|
},
|
|
42
42
|
"bundleDependencies": [
|
|
43
43
|
"@tomflow/chatloop-context",
|