@tomflow/chatloop-tools 0.9.56 → 0.9.58
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/index.mjs +2 -1
- package/node_modules/@tomflow/chatloop-context/lib/approval-policy.mjs +58 -0
- package/node_modules/@tomflow/chatloop-context/lib/core/run.mjs +23 -2
- package/node_modules/@tomflow/chatloop-context/lib/core/store.mjs +4 -4
- 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 +33 -1
- package/node_modules/@tomflow/chatloop-extension/package.json +1 -1
- package/package.json +3 -3
|
@@ -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 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',()=>{
|
|
@@ -39,7 +39,28 @@ 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)=>approvedTurnSourceMatches(record,{
|
|
53
|
+
userText:e?.[kind+'UserText'],userKey:e?.[kind+'UserKey'],
|
|
54
|
+
version:e?.[kind+'Version']},kind.toUpperCase());
|
|
55
|
+
assert(e&&typeof e==='object'&&!Array.isArray(e)
|
|
56
|
+
&&Object.keys(e).length===6
|
|
57
|
+
&&['rUserText','rUserKey','rVersion','pUserText',
|
|
58
|
+
'pUserKey','pVersion'].every(k=>Object.hasOwn(e,k)),
|
|
59
|
+
'ADOPTION_APPROVAL_EVIDENCE_REQUIRED');
|
|
60
|
+
assert(validTurn('r',approvals[0])&&validTurn('p',approvals[1])
|
|
61
|
+
&&e.rUserKey!==e.pUserKey,
|
|
62
|
+
'ADOPTION_APPROVAL_SOURCE_MISMATCH');
|
|
63
|
+
}
|
|
43
64
|
if(['CONTINUE','HANDOFF'].includes(a.kind)){
|
|
44
65
|
// A terminal Task with no holder is NOT eligible for more work.
|
|
45
66
|
// Only a named pending Handoff may reserve the single NOT_SENT
|
|
@@ -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),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tomflow/chatloop-context",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.21",
|
|
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){
|
|
@@ -199,6 +199,36 @@ async function sessionStartTake(message,sender){
|
|
|
199
199
|
if(!sessionPage(sender,'start',message.requestId)||run?.machineRequestId!==message.requestId
|
|
200
200
|
||run.machineActionTabId!==sender.tab.id||run.token!==message.token
|
|
201
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
|
+
}
|
|
202
232
|
await saveRun({...run,phase:'PENDING'});
|
|
203
233
|
// Native validates current durable Session and signs the narrow Context IPC.
|
|
204
234
|
// No Context adapter? Legacy Start behavior remains unchanged.
|
|
@@ -208,7 +238,9 @@ async function sessionStartTake(message,sender){
|
|
|
208
238
|
args:{expectedStoreEpoch:run.contextStoreEpoch,writeRequestId:run.token,
|
|
209
239
|
expectedTaskRevision:run.contextTaskRevision,
|
|
210
240
|
expectedApprovalRevision:run.contextApprovalRevision,
|
|
211
|
-
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}:{})}
|
|
212
244
|
}).catch(()=>null);
|
|
213
245
|
if(allowed?.status!=='OK'||allowed.result?.status!=='PERMITTED'){
|
|
214
246
|
await saveRun({...run,phase:'BLOCKED',reason:'CONTEXT_START_PERMIT_UNVERIFIED'});
|
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.58",
|
|
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.21",
|
|
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",
|