@tomflow/chatloop-extension 0.4.35 → 0.4.37

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.
@@ -188,7 +188,8 @@ async function run(){
188
188
  // Versioned task-first original Chat Adopt. There is NO composer write,
189
189
  // send click, new Chat or V1 global Run in this path.
190
190
  prepared=await chrome.runtime.sendMessage({
191
- type:'CHAT_LOOP_TASK_START_PREPARE_V2',requestId:id});
191
+ type:'CHAT_LOOP_TASK_START_PREPARE_V2',requestId:id,
192
+ ...(proof.traceParent?{traceParent:proof.traceParent}:{})});
192
193
  if(prepared?.status!=='PREPARED'
193
194
  ||prepared.scope!=='TASK_SCOPED_ADOPT_NO_SEND'
194
195
  ||!Number.isSafeInteger(prepared.tabId)
@@ -196,7 +197,8 @@ async function run(){
196
197
  throw Error(prepared?.code||'SCOPED_START_PREPARE_UNVERIFIED');
197
198
  await observerReady(prepared.tabId);
198
199
  committed=await chrome.runtime.sendMessage({
199
- type:'CHAT_LOOP_TASK_START_COMMIT_V2',requestId:id});
200
+ type:'CHAT_LOOP_TASK_START_COMMIT_V2',requestId:id,
201
+ ...(proof.traceParent?{traceParent:proof.traceParent}:{})});
200
202
  if(committed?.status!=='OK'
201
203
  ||committed.scope!=='TASK_SCOPED_ADOPTED_NO_SEND'
202
204
  ||committed.sessionId!==prepared.sessionId
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "manifest_version": 3,
3
3
  "name": "Chat Loop Extension",
4
- "version": "0.4.35",
4
+ "version": "0.4.37",
5
5
  "description": "Chat Loop browser companion: Eye actions, Turn observer, Continue and Handoff Actions",
6
6
  "permissions": [
7
7
  "activeTab",
@@ -185,8 +185,8 @@ chrome.runtime.onMessage.addListener((message,sender,reply)=>{
185
185
  }catch{/* Reply telemetry cannot change the browser callback. */}
186
186
  }
187
187
  };
188
- // Only the known, exact status Action may offer an AOP parent. The
189
- // existing sessionPage/Owner gate still independently checks the request.
188
+ // An exact privileged Action page may offer a soft AOP parent. This
189
+ // never grants task authority; native proof and Owner gates remain separate.
190
190
  const sourceId=message?.requestId||message?.id;
191
191
  const actionSource=/^[a-f0-9]{32}$/.test(sourceId||'')&&(
192
192
  type==='CHAT_LOOP_SESSION_STATUS_V1'&&
@@ -196,7 +196,8 @@ chrome.runtime.onMessage.addListener((message,sender,reply)=>{
196
196
  sender?.url===chrome.runtime.getURL(message.action.toLowerCase()+'.html')+
197
197
  '?requestId='+sourceId||
198
198
  ['CHAT_LOOP_SESSION_START_PREPARE_V1','CHAT_LOOP_SESSION_START_TAKE_V1',
199
- 'CHAT_LOOP_SESSION_START_RESULT_V1'].includes(type)&&
199
+ 'CHAT_LOOP_SESSION_START_RESULT_V1','CHAT_LOOP_TASK_START_PREPARE_V2',
200
+ 'CHAT_LOOP_TASK_START_COMMIT_V2'].includes(type)&&
200
201
  sender?.url===chrome.runtime.getURL('start.html')+'?requestId='+sourceId);
201
202
  return workerApi.audit.observe('browser.dispatch.'+type,
202
203
  // Read dispatchSpan only when the AOP invokes its target: onBegin has
@@ -211,7 +211,11 @@ const onScopedBrowserMessage=(message,sender,reply)=>{
211
211
  void (async()=>{
212
212
  if(!scopedTaskRuns||!scopedTaskScheduler)
213
213
  throw Error('TASK_SCOPED_ROUTER_NOT_READY');
214
- if(!message||Object.keys(message).length!==2
214
+ // A signed Start Action may carry its existing traceParent for soft
215
+ // correlation; it is not a Task identity, permit or business input.
216
+ if(!message||(Object.keys(message).length!==2
217
+ &&(Object.keys(message).length!==3
218
+ ||!Object.hasOwn(message,'traceParent')))
215
219
  ||!/^[a-f0-9]{32}$/.test(message.requestId||''))
216
220
  throw Error('SCOPED_START_MESSAGE_INVALID');
217
221
  const source=await scopedStartIntent(message,sender);
@@ -1,6 +1,7 @@
1
1
  // One Native-only V1/V2 Owner mutation lock on macOS.
2
- // A permanent 0600 marker fences the old O_EXCL writers; lockf -k holds
3
- // the kernel lock across the entire CAS in a one-shot private subprocess.
2
+ // A permanent 0600 marker fences old O_EXCL writers. Darwin does not
3
+ // ship /usr/bin/lockf: the tiny Python wrapper uses flock and execs the
4
+ // existing Node CAS helper while inheriting the same locked descriptor.
4
5
  // Never unlink or infer an abandoned legacy lock from its age/PID.
5
6
  import {openSync,closeSync,lstatSync,mkdirSync,readFileSync,writeFileSync,
6
7
  fsyncSync,unlinkSync} from 'node:fs';
@@ -13,6 +14,7 @@ const fail=code=>Object.assign(Error(code),{code});
13
14
  const marker='CHAT_LOOP_OWNER_KERNEL_LOCK_V1\n';
14
15
  const path=()=>join(homedir(),'.chat-loop','session','owner-registry.lock');
15
16
  const helper=fileURLToPath(new URL('./owner-locked-write.mjs',import.meta.url));
17
+ const lockExec=fileURLToPath(new URL('./owner-lock-exec.py',import.meta.url));
16
18
  const stat=p=>{try{return lstatSync(p)}catch(e){if(e.code==='ENOENT')return null;throw e;}};
17
19
  const UUID=/^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i;
18
20
  const terminal=s=>['DONE','CANCELLED'].includes(s?.phase);
@@ -83,16 +85,19 @@ function ensureMarker(){
83
85
  export function withOwnerKernelLock(kind,args){
84
86
  if(!['legacy-write','scoped-write','scoped-retire'].includes(kind)
85
87
  ||!Array.isArray(args))throw fail('OWNER_LOCK_REQUEST_INVALID');
88
+ const executable=stat(lockExec);
89
+ if(!executable?.isFile()||executable.isSymbolicLink())
90
+ throw fail('OWNER_LOCK_EXEC_MISSING');
86
91
  const file=ensureMarker();
87
- const result=spawnSync('/usr/bin/lockf',
88
- ['-k','-n','-t','2',file,process.execPath,helper],{
92
+ const result=spawnSync('/usr/bin/python3',
93
+ ['-B',lockExec,file,process.execPath,helper],{
89
94
  // Do not kill lockf after acquisition: its child could outlive it
90
95
  // and keep writing without the parent-held kernel lock.
91
96
  input:JSON.stringify({kind,args}),encoding:'utf8',
92
97
  maxBuffer:512*1024
93
98
  });
94
- // A crashed helper may already have committed its atomic rename.
95
- // Only the kernel's lock-contention exit is a proven no-write result.
99
+ // A crashed CAS helper may already have committed its atomic rename.
100
+ // Only exit 75 (verified flock contention before exec) proves no write.
96
101
  if(result.status===75)throw fail('OWNER_LEDGER_LOCKED');
97
102
  if(result.error||result.status!==0||result.signal)
98
103
  throw fail('OWNER_WRITE_RECEIPT_UNKNOWN');
@@ -0,0 +1,49 @@
1
+ #!/usr/bin/python3
2
+ """Hold one Darwin BSD kernel flock across exec of the existing Node CAS helper.
3
+
4
+ No Session parsing or mutation lives here. The same file descriptor must
5
+ survive exec, so a crashed process releases the kernel lock automatically.
6
+ """
7
+ import errno
8
+ import fcntl
9
+ import os
10
+ import stat
11
+ import sys
12
+ import time
13
+
14
+ MARKER = b"CHAT_LOOP_OWNER_KERNEL_LOCK_V1\n"
15
+
16
+
17
+ def main():
18
+ if len(sys.argv) != 4:
19
+ return 64
20
+ lock_path, node_binary, helper_path = sys.argv[1:]
21
+ fd = os.open(lock_path, os.O_RDWR | os.O_NOFOLLOW)
22
+ meta = os.fstat(fd)
23
+ if (not stat.S_ISREG(meta.st_mode) or meta.st_uid != os.getuid()
24
+ or stat.S_IMODE(meta.st_mode) != 0o600 or meta.st_nlink != 1
25
+ or os.read(fd, len(MARKER) + 1) != MARKER):
26
+ return 65
27
+ deadline = time.monotonic() + 2.0
28
+ while True:
29
+ try:
30
+ fcntl.flock(fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
31
+ break
32
+ except OSError as error:
33
+ if error.errno not in (errno.EWOULDBLOCK, errno.EAGAIN, errno.EACCES):
34
+ raise
35
+ if time.monotonic() >= deadline:
36
+ return 75
37
+ time.sleep(0.05)
38
+ # PEP 446 makes descriptors close-on-exec by default. Explicitly keep
39
+ # this one FD open in Node; never fork a lock owner separate from the CAS.
40
+ os.set_inheritable(fd, True)
41
+ os.execv(node_binary, [node_binary, helper_path])
42
+ return 66
43
+
44
+
45
+ if __name__ == "__main__":
46
+ try:
47
+ sys.exit(main())
48
+ except (OSError, ValueError):
49
+ sys.exit(66)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomflow/chatloop-extension",
3
- "version": "0.4.35",
3
+ "version": "0.4.37",
4
4
  "type": "module",
5
5
  "description": "Chat Loop Extension: reviewed formal Action pages, including TEST_ONLY native App entry",
6
6
  "bin": {
@@ -20,6 +20,7 @@
20
20
  "extension/",
21
21
  "bin/",
22
22
  "lib/",
23
+ "lib/owner-lock-exec.py",
23
24
  "README.md"
24
25
  ],
25
26
  "scripts": {
@@ -116,6 +116,11 @@ async function main(){
116
116
  const pkg=JSON.parse(readFileSync(join(root,'package.json'),'utf8'));
117
117
  if(manifest.version!==pkg.version||manifest.manifest_version!==3)
118
118
  throw fail('EXTENSION_PACKAGE_VERSION_MISMATCH');
119
+ // The Darwin Native lock executor must survive npm pack. A missing helper
120
+ // makes every V1/V2 Owner CAS fail before any Context or Chrome binding.
121
+ if(!pkg.files?.includes('lib/owner-lock-exec.py')
122
+ ||!existsSync(join(root,'lib','owner-lock-exec.py')))
123
+ throw fail('OWNER_LOCK_EXEC_PACKAGE_MISSING');
119
124
  const targets=[[join(root,'actions.generated.mjs'),expected.node],
120
125
  [join(ext,'loop','action-catalog.generated.js'),expected.browser],
121
126
  ...Object.entries(expected.aliases).map(([page,html])=>[join(ext,page),html])];