@tomflow/chatloop-extension 0.4.22 → 0.4.23

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/README.md CHANGED
@@ -42,7 +42,7 @@ The builder creates their isolated Action HTML, which uses the same
42
42
  dispatch switch needs modification. The builder refuses duplicate names,
43
43
  privileged type changes, invalid read modes, missing assets and stale output.
44
44
 
45
- **A declaration does not grant sending authority.** The separately reviewed `entry test` Action is a TEST_ONLY, Native-authorized first-turn fixture: it requires an explicit confirmation, creates one ordinary Chat with a real structured @ App mention, and must prove the unique user message without a Browser Owner; it cannot approve R/P or invoke Start/Continue/Handoff. Its explicit privilege review is allowlisted by exact ID, route, page, deadline and receipt format. Any other new sending declaration is denied. Start, Continue, Handoff,
45
+ **A declaration does not grant sending authority.** The separately reviewed `entry test` Action is a TEST_ONLY, Native-authorized first-turn fixture: it requires an explicit confirmation, creates one ordinary Chat with a real structured @ App mention, and must prove the unique user message without a Browser Owner; it cannot approve R/P or invoke Start/Continue/Handoff. Its explicit privilege review is allowlisted by exact ID, route, page, deadline and receipt format. When no ChatGPT tab exists, only this TEST_ONLY Action may open in the one Chrome window containing the verified exact extension details page; the Action itself creates the normal Chat. Other Actions still require the unique current ChatGPT window. Any other new sending declaration is denied. Start, Continue, Handoff,
46
46
  Clean, Status, screenshot and reload keep their reviewed, explicit Worker
47
47
  handlers and existing trust boundaries. New send/Owner/Native mutation
48
48
  requires a separate authorized security review and implementation; it cannot
@@ -81,7 +81,15 @@ For the installed command list, run `chatloop-extension extension --help`.
81
81
  `extension start` requires the real approved intent; `mode=adopt` does not
82
82
  re-send. Continue/Handoff only register intents with one Turn token and never
83
83
  silently send or repeat. Clean needs an exact verified tab ID, and Status
84
- is read-only. IPC messages are one-shot and have durable identity checks.
84
+ is read-only. A previously BLOCKED Session with a lost old Owner tab remains
85
+ `state:BLOCKED` (not `IDLE`) when Worker/Native identities agree; the
86
+ `oldOwnerTabStatus:MISSING_UNVERIFIED` diagnostic is not a replacement permit.
87
+ A missing ACTIVE Owner or mismatched Native pointer remains `UNVERIFIED`.
88
+ Explicit Adopt of a different approved Task still requires the exact old
89
+ Session ID, old Context fence, and a fresh Start lease. Two distinct genuine
90
+ Form A-confirmation user Turns may serve as SOFT R/P evidence in an explicitly
91
+ specified original Chat; this never substitutes for Context approval or Start
92
+ permission. IPC messages are one-shot and have durable identity checks.
85
93
 
86
94
  This package's source version is read from its own `package.json`. Installed
87
95
  Tools/Context consumers may pin a different Extension version; updating
@@ -16,9 +16,32 @@ if (message?.type === "CHAT_LOOP_APPROVAL_EVIDENCE_V1") {
16
16
  .filter(x=>["user","assistant"].includes(x.role));
17
17
  const textOf=x=>(x.el.querySelector?.(".markdown")?.innerText
18
18
  ||x.el.innerText||x.el.textContent||"").trim();
19
+ // Current independent Form App submits exactly one original user Turn.
20
+ // Its A-choice receipt differs from older issue-scoped prose. Match the
21
+ // full bounded host template, two UUIDs, choice and R/P-labelled version;
22
+ // a summary, B-choice or casual affirmation is not Form evidence.
23
+ // This is SOFT evidence only: a text-shaped copy is not host-signed,
24
+ // so Context's independent Start lease remains mandatory.
25
+ const formApprovalVersion=(value,type)=>{
26
+ const lines=value.split(/\r?\n/).map(x=>x.trim()).filter(Boolean);
27
+ if(lines.length!==6
28
+ ||lines[0]!=='Chat Loop Form 提交结果(由用户点击表单提交)'
29
+ ||!/^formId:\s*[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i.test(lines[1])
30
+ ||!/^traceRef:\s*[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i.test(lines[2])
31
+ ||lines[3]!=='选项值: A'
32
+ ||lines[5]!=='请核对当前业务任务、文档与 Issue 版本及原生消息身份后处理本次选择;表单回执本身不构成审批或写权。')
33
+ return null;
34
+ const label=lines[4].match(/^选项标签:\s*A[||]\s*确认当前\s*([RP][1-9][0-9]*)\s*(需求|技术与验证方案|技术方案|方案)$/i);
35
+ if(!label||label[1][0].toUpperCase()!==type
36
+ ||(type==='R')!==(label[2]==='需求'))return null;
37
+ const formId=lines[1].slice('formId:'.length).trim().toLowerCase();
38
+ const traceRef=lines[2].slice('traceRef:'.length).trim().toLowerCase();
39
+ return formId===traceRef?null:{version:label[1].toUpperCase(),formId,traceRef};
40
+ };
19
41
  const confirms=(value,type)=>{
20
42
  const line=value.replace(/\s+/g," ").trim();
21
43
  if(!line||line.length>500)return false;
44
+ if(formApprovalVersion(value,type))return true;
22
45
  // Native R/P review controls send two explicit, task-scoped fields:
23
46
  // "TASK|Rn-ISSUE:<uuid>|我确认 Rn vN。" (and the Pn equivalent).
24
47
  // Accept only a matching kind+version from a genuine user message,
@@ -101,6 +124,12 @@ if (message?.type === "CHAT_LOOP_APPROVAL_EVIDENCE_V1") {
101
124
  // This fallback is ONLY for native issue-scoped approvals. The Native
102
125
  // Context Start lease independently verifies the effective R approval.
103
126
  const rUser=rIndex>=0?rows[rIndex]:null;
127
+ const rForm=rUser?formApprovalVersion(textOf(rUser),'R'):null;
128
+ const pForm=formApprovalVersion(textOf(pUser),'P');
129
+ if(rForm&&pForm&&(rForm.formId===pForm.formId
130
+ ||rForm.traceRef===pForm.traceRef)){
131
+ fail('APPROVAL_FORM_REUSED');return false;
132
+ }
104
133
  const nativeR=rUser&&textOf(rUser).match(/^[A-Z][A-Z0-9._:-]{7,120}[||]\s*(R[1-9][0-9]*)-ISSUE:[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}[||]\s*我确认\s+(R[1-9][0-9]*)\s+v([1-9][0-9]*)[。.!!]/i);
105
134
  const nativeRVersion=nativeR
106
135
  &&nativeR[1].toUpperCase()===nativeR[2].toUpperCase()
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "manifest_version": 3,
3
3
  "name": "Chat Loop Extension",
4
- "version": "0.4.22",
4
+ "version": "0.4.23",
5
5
  "description": "Chat Loop browser companion: Eye actions, Turn observer, Continue and Handoff Actions",
6
6
  "permissions": [
7
7
  "activeTab",
@@ -170,10 +170,18 @@ async function sessionStatus(message,sender){
170
170
  const projectContext=disk.contextStatus==='VERIFIED'
171
171
  &&disk.projectContext?.projectId===run.projectId
172
172
  ?disk.projectContext:null;
173
+ let blockedOwnerTabMissing=false;
173
174
  if(record.activeChatId&&['WAITING_REPLY','BLOCKED'].includes(run.phase)){
174
175
  const tab=await chrome.tabs.get(run.tabId).catch(()=>null);
175
- if(!tab||pathOf(tab.url)!==run.page)
176
- return {status:'UNVERIFIED',code:'OWNER_TAB_MISSING',session:record};
176
+ if(!tab||pathOf(tab.url)!==run.page){
177
+ // A missing tab for the OLD, already-BLOCKED Session is a locator
178
+ // diagnostic, not a conclusion about a different newly approved Task.
179
+ // Native/Worker identity above must still match; the independent new
180
+ // Start must separately prove the exact replacement and Context fence.
181
+ if(run.phase!=='BLOCKED')
182
+ return {status:'UNVERIFIED',code:'OWNER_TAB_MISSING',session:record};
183
+ blockedOwnerTabMissing=true;
184
+ }
177
185
  }
178
186
  // Identity comes from the verified Worker projection, but updatedAt is
179
187
  // Native's durable CAS revision. Never report a synthetic timestamp as a
@@ -187,7 +195,10 @@ async function sessionStatus(message,sender){
187
195
  ...(run.lastStartFailureCode?{lastStartFailureCode:run.lastStartFailureCode}:{}),
188
196
  // The numeric tab ID is a locator, never a send capability. Expose only
189
197
  // for an exactly verified terminal/awaiting Owner, not a guessed tab.
190
- ownerTabId:['WAITING_REPLY','BLOCKED'].includes(run.phase)?run.tabId:null,
198
+ ownerTabId:blockedOwnerTabMissing?null
199
+ :['WAITING_REPLY','BLOCKED'].includes(run.phase)?run.tabId:null,
200
+ ...(blockedOwnerTabMissing
201
+ ?{oldOwnerTabStatus:'MISSING_UNVERIFIED'}:{}),
191
202
  reason:run.reason||null,action:run.action||null,
192
203
  userKey:run.userKey||null,assistantKey:run.assistantKey||null,
193
204
  newUserKey:run.newUserKey||null,recoveryAttempts:run.recoveryAttempts||0,
@@ -25,14 +25,57 @@ const OPEN_IN_CHAT_WINDOW = `on run argv
25
25
  end tell
26
26
  end run`;
27
27
 
28
+ // Entry TEST_ONLY may bootstrap a normal Chat when there is no existing
29
+ // ChatGPT tab. In that case require exactly one Chrome window containing the
30
+ // explicitly verified Chat Loop extension details page. Never select a random
31
+ // Chrome window or another profile, and never create a Chat tab here.
32
+ const OPEN_TEST_ENTRY_WINDOW = `on run argv
33
+ set destination to item 1 of argv
34
+ set managerURL to item 2 of argv
35
+ tell application "Google Chrome"
36
+ set chatWindowIds to {}
37
+ repeat with w in windows
38
+ set hasChat to false
39
+ repeat with t in tabs of w
40
+ try
41
+ if (URL of t) starts with "https://chatgpt.com/" then set hasChat to true
42
+ end try
43
+ end repeat
44
+ if hasChat then set end of chatWindowIds to id of w
45
+ end repeat
46
+ if (count of chatWindowIds) is 1 then
47
+ set ownWindow to window id (item 1 of chatWindowIds)
48
+ else
49
+ if (count of chatWindowIds) is not 0 then error "CHATGPT_WINDOW_AMBIGUOUS" number 103
50
+ set managerWindowIds to {}
51
+ repeat with w in windows
52
+ set hasManager to false
53
+ repeat with t in tabs of w
54
+ try
55
+ if (URL of t) is managerURL then set hasManager to true
56
+ end try
57
+ end repeat
58
+ if hasManager then set end of managerWindowIds to id of w
59
+ end repeat
60
+ if (count of managerWindowIds) is not 1 then error "ENTRY_TEST_WINDOW_UNVERIFIED" number 103
61
+ set ownWindow to window id (item 1 of managerWindowIds)
62
+ end if
63
+ make new tab at end of tabs of ownWindow with properties {URL:destination}
64
+ return "WINDOW=" & (id of ownWindow)
65
+ end tell
66
+ end run`;
67
+
28
68
  export function openExtensionActionPage(url,{platform=process.platform,spawn=spawnSync}={}){
29
69
  if(platform!=='darwin')
30
70
  throw Object.assign(Error('Browser launcher not yet verified on this OS'),
31
71
  {code:'BROWSER_LAUNCH_UNSUPPORTED'});
32
72
  if(!/^chrome-extension:\/\/[a-p]{32}\/[a-z_]+\.html\?requestId=[a-f0-9]{32}$/.test(url))
33
73
  throw Object.assign(Error('Untrusted Extension Action URL'),{code:'INVALID_ACTION_URL'});
34
- const receipt=spawn('osascript',['-e',OPEN_IN_CHAT_WINDOW,url],
35
- {encoding:'utf8',timeout:7000});
74
+ const entry=url.match(/^chrome-extension:\/\/([a-p]{32})\/entry_test\.html\?requestId=[a-f0-9]{32}$/);
75
+ const launchArgs=entry
76
+ ?['-e',OPEN_TEST_ENTRY_WINDOW,url,'chrome://extensions/?id='+entry[1]]
77
+ :['-e',OPEN_IN_CHAT_WINDOW,url];
78
+ const receipt=spawn('osascript',launchArgs,{encoding:'utf8',timeout:7000});
36
79
  if(receipt.error||receipt.status!==0||!/\bWINDOW=\d+\b/.test(receipt.stdout||''))
37
80
  throw Object.assign(Error('Existing ChatGPT Chrome window unavailable or ambiguous'),
38
81
  {code:'CHROME_TARGET_WINDOW_UNVERIFIED'});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomflow/chatloop-extension",
3
- "version": "0.4.22",
3
+ "version": "0.4.23",
4
4
  "type": "module",
5
5
  "description": "Chat Loop Extension: reviewed formal Action pages, including TEST_ONLY native App entry",
6
6
  "bin": {