@tomflow/chatloop-extension 0.4.45 → 0.4.46

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 @@ async function run(){
51
51
  ||acquired.action!=='session'||typeof acquired.nonce!=='string'
52
52
  ||acquired.intent?.operation!==operation)
53
53
  throw Error(acquired?.code||'SESSION_INTENT_UNVERIFIED');
54
- let result,dispatched=false;
54
+ let result;
55
55
  try{
56
56
  if(operation!=='cancel')await confirmRecoveryClick(acquired.intent);
57
57
  show('RUNNING',operation==='cancel'
@@ -59,7 +59,6 @@ async function run(){
59
59
  :operation==='recover-cancel'
60
60
  ?'核验旧取消请求和已冻结 Owner,完成 Context 围栏;不会发送消息…'
61
61
  :'核验原 Handoff 未发送证据及一次性恢复许可;不会发送消息…');
62
- dispatched=true;
63
62
  result=await chrome.runtime.sendMessage({
64
63
  type:operation==='recover-cancel'
65
64
  ?'CHAT_LOOP_TASK_CANCEL_RECOVER_V2'
@@ -87,7 +86,7 @@ async function run(){
87
86
  // retry a mutation; the original request and persisted receipt are proof.
88
87
  const raw=error?.message;
89
88
  const code=/^[A-Z][A-Z0-9_]{1,95}$/.test(raw||'')?raw:'SESSION_ACTION_UNVERIFIED';
90
- if(operation!=='cancel'&&dispatched){
89
+ if(operation!=='cancel'){
91
90
  // A permit/bind/Native CAS may already have committed. Never seal
92
91
  // an ambiguous recovery as a definitive FAILED Action receipt:
93
92
  // preserve this exact signed request for read-only reconciliation.
@@ -98,9 +97,9 @@ async function run(){
98
97
  op:'complete',id,nonce:acquired.nonce,action:'session',
99
98
  status:'FAILED',code
100
99
  }).catch(()=>null);
101
- const saved=receipt?.status==='SAVED'&&receipt.id===id;
102
- show('BLOCKED',saved?code:code+';终态回执未核实,仅核查原请求。');
103
- if(saved)await chrome.tabs.remove(own.id).catch(()=>{});
100
+ show('BLOCKED',code);
101
+ if(receipt?.status==='SAVED'&&receipt.id===id)
102
+ await chrome.tabs.remove(own.id).catch(()=>{});
104
103
  }
105
104
  }
106
105
  void run().catch(e=>show('UNVERIFIED',
@@ -33,17 +33,31 @@ if (message?.type === "CHAT_LOOP_APPROVAL_EVIDENCE_V1") {
33
33
  return null;
34
34
  const formId=lines[1].slice('formId:'.length).trim().toLowerCase();
35
35
  const traceRef=lines[2].slice('traceRef:'.length).trim().toLowerCase();
36
- const oldLabel=lines[4].match(/^选项标签:\s*A[||]\s*确认当前\s*([RP][1-9][0-9]*)\s*(需求|技术与验证方案|技术方案|方案)$/i);
36
+ const oldLabel=lines[4].match(/^选项标签:\s*A[||]\s*确认(?:当前\s*)?([RP][1-9][0-9]*)\s*(需求|技术与验证方案|技术方案|方案)$/i);
37
37
  const modernLabel=lines[3]==='选项值: approve'
38
38
  &&/^选项标签:\s*A[||]\s*确认(需求|技术与验证方案|技术方案|方案)$/.exec(lines[4]);
39
+ // The visible "P2 final revision" is a semantic review cycle.
40
+ // The stored document can be P1 V3 after a cancelled V2; only the
41
+ // explicit physical V3 may become the trusted approval version P3.
42
+ const revisionLabel=lines[4].match(
43
+ /^选项标签:\s*A[||]\s*确认(?:当前\s*)?([RP][1-9][0-9]*)\s*V([1-9][0-9]*)[((]\s*([RP][1-9][0-9]*)\s*(?:最终)?修订稿[))]$/i);
44
+ const physical=Number(revisionLabel?.[2]||0);
45
+ const semantic=Number(revisionLabel?.[3]?.slice(1)||0);
46
+ const revised=revisionLabel&&revisionLabel[1].toUpperCase()===type+'1'
47
+ &&physical>=2&&revisionLabel[3][0].toUpperCase()===type
48
+ &&semantic>=2&&semantic<=physical;
39
49
  const versions=[...formId.matchAll(/(?:^|[-_])([rp][1-9][0-9]*)(?=[-_]|$)/gi)]
40
50
  .map(m=>m[1].toUpperCase());
41
- const version=oldLabel?.[1].toUpperCase()
51
+ const version=oldLabel?.[1]?.toUpperCase()
52
+ ||(revised?type+String(physical):null)
42
53
  ||(modernLabel&&versions.length===1?versions[0]:null);
43
- const label=oldLabel?.[2]||modernLabel?.[1];
54
+ const label=oldLabel?.[2]
55
+ ||(revised?(type==='R'?'需求':'方案'):modernLabel?.[1]);
44
56
  if(!version||version[0]!==type||!label
45
57
  ||(type==='R')!==(label==='需求')
46
- ||(oldLabel&&versions.length>0&&versions.some(v=>v!==version))
58
+ ||(oldLabel&&versions.some(v=>v!==version))
59
+ ||revised&&versions.some(v=>v!==type+'1'&&v!==version
60
+ &&v!==revisionLabel[3].toUpperCase())
47
61
  ||formId===traceRef)return null;
48
62
  return {version,formId,traceRef};
49
63
  };
@@ -90,6 +104,17 @@ if (message?.type === "CHAT_LOOP_APPROVAL_EVIDENCE_V1") {
90
104
  // Prefer an explicit current-version declaration. Historical mentions
91
105
  // must not choose a version; ambiguous prose is not approval evidence.
92
106
  const versionOf=(value,type)=>{
107
+ // An amended immutable P1/R1 document can be V3 while the human
108
+ // display still calls its review "P2 final revision". Prefer the
109
+ // explicitly marked CURRENT physical version, never the historical
110
+ // P1 V1/V2 recap or the human review-cycle alias.
111
+ const currentRevision=value.match(new RegExp(
112
+ "(?:^|\\n)\\s*当前版本\\s*V([1-9][0-9]*)\\s*[((]\\s*"
113
+ +type+"([1-9][0-9]*)\\s*(?:最终)?修订稿[))]","i"));
114
+ if(currentRevision&&Number(currentRevision[1])>=2
115
+ &&Number(currentRevision[2])>=2
116
+ &&Number(currentRevision[2])<=Number(currentRevision[1]))
117
+ return type+String(Number(currentRevision[1]));
93
118
  // Real formal reviews may start with a status recap mentioning an
94
119
  // an older plan version before the current issued revision heading.
95
120
  // A unique, version-consistent line title outranks historical prose.
@@ -132,7 +157,9 @@ if (message?.type === "CHAT_LOOP_APPROVAL_EVIDENCE_V1") {
132
157
  fail("APPROVAL_PLAN_MISSING");return false;
133
158
  }
134
159
  const pVersion=versionOf(textOf(pAssistant),"P");
135
- const pUserVersion=textOf(pUser).match(/\bP[1-9][0-9]*\b/i)?.[0].toUpperCase();
160
+ const pUserForm=formApprovalVersion(textOf(pUser),'P');
161
+ const pUserVersion=pUserForm?.version
162
+ ||textOf(pUser).match(/\bP[1-9][0-9]*\b/i)?.[0].toUpperCase();
136
163
  if(pUserVersion && pVersion!==pUserVersion){
137
164
  fail("APPROVAL_PLAN_VERSION_MISMATCH");return false;
138
165
  }
@@ -145,7 +172,7 @@ if (message?.type === "CHAT_LOOP_APPROVAL_EVIDENCE_V1") {
145
172
  // Context Start lease independently verifies the effective R approval.
146
173
  const rUser=rIndex>=0?rows[rIndex]:null;
147
174
  const rForm=rUser?formApprovalVersion(textOf(rUser),'R'):null;
148
- const pForm=formApprovalVersion(textOf(pUser),'P');
175
+ const pForm=pUserForm;
149
176
  if(rForm&&pForm&&(rForm.formId===pForm.formId
150
177
  ||rForm.traceRef===pForm.traceRef)){
151
178
  fail('APPROVAL_FORM_REUSED');return false;
@@ -231,9 +258,18 @@ if (message?.type === "CHAT_LOOP_APPROVAL_EVIDENCE_V1") {
231
258
  if(!pVersion||!rVersion||invalidated){
232
259
  fail("APPROVAL_REVISED_OR_REVOKED");return false;
233
260
  }
234
- const rUserVersion=textOf(rUser).match(/\bR[1-9][0-9]*\b/i)?.[0].toUpperCase();
261
+ const rUserVersion=rForm?.version
262
+ ||textOf(rUser).match(/\bR[1-9][0-9]*\b/i)?.[0].toUpperCase();
235
263
  const referencedR=textOf(pAssistant).match(/\bR[1-9][0-9]*\b/i)?.[0].toUpperCase();
236
- if(!referencedR || referencedR!==rVersion){
264
+ // A versioned Form pair is independently reconciled against the
265
+ // immutable Context P.requirementRef and R/P approval records at
266
+ // permit.consume. Some valid revised-plan replies do not repeat R1 in
267
+ // their visible summary. Allow only this same-Chat, two-Form case;
268
+ // native/unscoped prose still requires an explicit R reference.
269
+ const formScopedRequirement=Boolean(explicitFormChat&&rForm&&pForm
270
+ &&rForm.version===rVersion&&pForm.version===pVersion);
271
+ if((!referencedR||referencedR!==rVersion)
272
+ &&!formScopedRequirement){
237
273
  fail("APPROVAL_PLAN_REQUIREMENT_MISMATCH");return false;
238
274
  }
239
275
  if(rUserVersion && rVersion!==rUserVersion){
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "manifest_version": 3,
3
3
  "name": "Chat Loop Extension",
4
- "version": "0.4.45",
4
+ "version": "0.4.46",
5
5
  "description": "Chat Loop browser companion: Eye actions, Turn observer, Continue and Handoff Actions",
6
6
  "permissions": [
7
7
  "activeTab",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomflow/chatloop-extension",
3
- "version": "0.4.45",
3
+ "version": "0.4.46",
4
4
  "type": "module",
5
5
  "description": "Chat Loop Extension: reviewed formal Action pages, including TEST_ONLY native App entry",
6
6
  "bin": {