@tomflow/chatloop-tools 0.9.56 → 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.
@@ -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
- assert(hasApprovedPlan(parse(r.approval_json)),'APPROVAL_REVOKED');
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.19",
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.28",
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}:{})});
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "manifest_version": 3,
3
3
  "name": "Chat Loop Extension",
4
- "version": "0.4.28",
4
+ "version": "0.4.29",
5
5
  "description": "Chat Loop browser companion: Eye actions, Turn observer, Continue and Handoff Actions",
6
6
  "permissions": [
7
7
  "activeTab",
@@ -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'});
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomflow/chatloop-extension",
3
- "version": "0.4.28",
3
+ "version": "0.4.29",
4
4
  "type": "module",
5
5
  "description": "Chat Loop Extension: reviewed formal Action pages, including TEST_ONLY native App entry",
6
6
  "bin": {
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.9.56",
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.19",
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.28"
40
+ "@tomflow/chatloop-extension": "0.4.29"
41
41
  },
42
42
  "bundleDependencies": [
43
43
  "@tomflow/chatloop-context",