@tomflow/chatloop-tools 0.9.13 → 0.9.14

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/index.mjs CHANGED
@@ -148,7 +148,8 @@ async function runtime(){
148
148
  validExtensionArgs:extensionContract.validExtensionArgs,
149
149
  isControlTool:extensionContract.isControlTool,
150
150
  acceptExtensionCliReceipt:extensionCliContract.acceptExtensionCliReceipt,
151
- extensionTools:extensionContract.extensionTools});
151
+ extensionTools:extensionContract.extensionTools,
152
+ readApiParent:apiAspect.current});
152
153
  release.configureRelease({PACKAGE_VERSION:control.PACKAGE_VERSION,
153
154
  activeDesktopCommands:releasePreflight.activeDesktopCommands,
154
155
  awaitStopped:releasePreflight.awaitStopped});
@@ -28,10 +28,10 @@ export async function forwardContextApiLog(event,request={}){
28
28
  // separately opt-in; disabling that MCP tool must not discard audit events.
29
29
  if(!recordContextApiLog||process.env.CHAT_LOOP_CONTEXT_API_ENABLE!=='1'
30
30
  ||event?.contract!=='chat-loop.context-api-log.v1'
31
- ||!UUID.test(event.callId)||!UUID.test(event.traceId||event.callId)
32
- ||!UUID.test(event.spanId||event.callId)
31
+ ||!UUID.test(event.callId)||!UUID.test(event.traceId||'')
32
+ ||event.spanId!==event.callId
33
33
  ||(event.parentSpanId!==null&&event.parentSpanId!==undefined
34
- &&!UUID.test(event.parentSpanId))
34
+ &&(!UUID.test(event.parentSpanId)||event.parentSpanId===event.spanId))
35
35
  ||!API.test(event.api)
36
36
  ||!['BEGIN','OK','FAILED'].includes(event.phase)
37
37
  ||!['sdk','gateway','operator','trusted'].includes(event.surface)
@@ -58,8 +58,8 @@ export async function forwardContextApiLog(event,request={}){
58
58
  try{
59
59
  const requestId=randomUUID();
60
60
  const receipt=await recordContextApiLog({
61
- requestId,traceId:event.traceId||event.callId,
62
- spanId:event.spanId||event.callId,
61
+ requestId,traceId:event.traceId,
62
+ spanId:event.spanId,
63
63
  ...(event.parentSpanId?{parentSpanId:event.parentSpanId}:{}),
64
64
  projectRef,
65
65
  ...(event.taskRef?{taskRef:event.taskRef}:{}),
@@ -5,13 +5,13 @@ import {readFileSync,statSync} from 'node:fs';
5
5
  import {tmpdir} from 'node:os';
6
6
  // All internal dependencies are supplied as API contracts by index.mjs.
7
7
  // Private modules never import or resolve another private implementation.
8
- let extensionCommand, validExtensionArgs, isControlTool, acceptExtensionCliReceipt, extensionTools;
8
+ let extensionCommand, validExtensionArgs, isControlTool, acceptExtensionCliReceipt, extensionTools, readApiParent;
9
9
  let connected=false;
10
10
  export function configureExtensionProxy(ports){
11
11
  if(connected)throw Error('TOOLS_MODULE_ALREADY_COMPOSED');
12
- for(const name of ['extensionCommand', 'validExtensionArgs', 'isControlTool', 'acceptExtensionCliReceipt', 'extensionTools'])
12
+ for(const name of ['extensionCommand', 'validExtensionArgs', 'isControlTool', 'acceptExtensionCliReceipt', 'extensionTools', 'readApiParent'])
13
13
  if(ports?.[name]===undefined)throw Error('TOOLS_PORT_MISSING:'+name);
14
- ({extensionCommand, validExtensionArgs, isControlTool, acceptExtensionCliReceipt, extensionTools}=ports);
14
+ ({extensionCommand, validExtensionArgs, isControlTool, acceptExtensionCliReceipt, extensionTools, readApiParent}=ports);
15
15
  connected=true;
16
16
  }
17
17
 
@@ -22,9 +22,22 @@ export function configureExtensionProxy(ports){
22
22
  // The package/version are exact and checked against the same Context
23
23
  // dependency deployed with the Tools release.
24
24
  export {extensionTools};
25
- const EXTENSION_PACKAGE='@tomflow/chatloop-extension@0.4.9';
26
- const EXTENSION_VERSION='0.4.9';
25
+ const EXTENSION_PACKAGE='@tomflow/chatloop-extension@0.4.10';
26
+ const EXTENSION_VERSION='0.4.10';
27
27
  const NPX_COMMAND=process.platform==='win32'?'npx.cmd':'npx';
28
+ const UUID=/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
29
+ // Match the existing Context child-CLI correlation boundary. Never inherit
30
+ // an unverified stale parent from the supervisor process environment.
31
+ function childApiEnvironment(){
32
+ const env={...process.env};
33
+ try{
34
+ const parent=readApiParent?.();
35
+ if(parent&&UUID.test(parent.traceId||'')&&UUID.test(parent.spanId||''))
36
+ env.CHAT_LOOP_API_PARENT=JSON.stringify(parent);
37
+ else delete env.CHAT_LOOP_API_PARENT;
38
+ }catch{delete env.CHAT_LOOP_API_PARENT}
39
+ return env;
40
+ }
28
41
  export const extensionInvocation=name=>{
29
42
  const command=extensionCommand(name);
30
43
  if(!command)return null;
@@ -40,7 +53,7 @@ export async function forwardExtensionAction(name,args={}) {
40
53
  if(name==='clean')invocation.args.push(String(args.tabId));
41
54
  const response=await new Promise(resolve=>{
42
55
  const child=spawn(invocation.executable,invocation.args,{stdio:[control?'pipe':'ignore','pipe','pipe'],
43
- cwd:tmpdir(),windowsHide:true,env:process.env});
56
+ cwd:tmpdir(),windowsHide:true,env:childApiEnvironment()});
44
57
  let stdout='',stdoutBytes=0,finished=false,closed=false,tailTimer=null;
45
58
  const settle=(value,receiptCompleted=false)=>{
46
59
  if(finished)return;
@@ -66,10 +66,10 @@ function recordApiObservation(req){
66
66
  }
67
67
  if(req?.contract!==CONTRACT||!OBSERVER_ID.test(req.requestId||'')||
68
68
  !OBSERVER_ID.test(req.callId||'')||
69
- (req.traceId!==undefined&&!OBSERVER_ID.test(req.traceId))||
70
- (req.spanId!==undefined&&!OBSERVER_ID.test(req.spanId))||
71
- (req.parentSpanId!==undefined&&!OBSERVER_ID.test(req.parentSpanId))||
72
- (req.spanId!==undefined&&req.spanId!==req.callId)||
69
+ !OBSERVER_ID.test(req.traceId||'')||
70
+ req.spanId!==req.callId||
71
+ (req.parentSpanId!==undefined&&
72
+ (!OBSERVER_ID.test(req.parentSpanId)||req.parentSpanId===req.spanId))||
73
73
  !OBSERVER_NAME.test(req.apiName||'')||
74
74
  !['BEGIN','OK','FAILED'].includes(req.phase)||
75
75
  Object.keys(req).some(k=>!OBSERVER_KEYS.has(k))||
@@ -83,7 +83,7 @@ function recordApiObservation(req){
83
83
  throw Object.assign(Error('TRACE_API_INVALID'),{code:'TRACE_API_INVALID'});
84
84
  const written=traceWriter.record({
85
85
  event:'typed.api.call',component:'gateway',projectRef:'api_system',
86
- traceId:req.traceId||req.callId,spanId:req.callId,
86
+ traceId:req.traceId,spanId:req.spanId,
87
87
  ...(req.parentSpanId?{parentSpanId:req.parentSpanId}:{}),
88
88
  apiName:req.apiName,
89
89
  status:req.phase==='BEGIN'?'BEGIN':req.phase==='OK'?'CONFIRMED':'FAILED',
@@ -34,8 +34,9 @@ export function createSupervisorTraceBridge({traceWriter,contract,error}){
34
34
  if(req.contract!==CONTRACT
35
35
  ||!['BEGIN','CONFIRMED','FAILED'].includes(req.status)
36
36
  ||!UUID_RE.test(req.traceId||'')||!UUID_RE.test(req.requestId||'')
37
- ||(req.spanId!==undefined&&!UUID_RE.test(req.spanId))
38
- ||(req.parentSpanId!==undefined&&!UUID_RE.test(req.parentSpanId))
37
+ ||!UUID_RE.test(req.spanId||'')
38
+ ||(req.parentSpanId!==undefined&&
39
+ (!UUID_RE.test(req.parentSpanId)||req.parentSpanId===req.spanId))
39
40
  ||Object.keys(req).some(k=>!allowed.has(k))
40
41
  ||req.taskRef!==undefined&&!(/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/).test(req.taskRef)
41
42
  ||!req.api||typeof req.api!=='object'||Array.isArray(req.api)
@@ -54,7 +55,7 @@ export function createSupervisorTraceBridge({traceWriter,contract,error}){
54
55
  throw error('TRACE_INVALID_ARGUMENT');
55
56
  const recorded=traceWriter.record({
56
57
  traceId:req.traceId,projectRef:req.projectRef,
57
- ...(req.spanId?{spanId:req.spanId}:{}),
58
+ spanId:req.spanId,
58
59
  ...(req.parentSpanId?{parentSpanId:req.parentSpanId}:{}),
59
60
  ...(req.taskRef?{taskRef:req.taskRef}:{}),
60
61
  requestId:req.requestId,component:'context',event:'context.api',
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.9.13",
6
+ "version": "0.9.14",
7
7
  "type": "module",
8
8
  "description": "Chat Loop local tools: MCP gateway, isolated bundled tunnel-client and unified CLI",
9
9
  "bin": {
@@ -29,15 +29,15 @@
29
29
  },
30
30
  "dependencies": {
31
31
  "@wonderwhy-er/desktop-commander": "0.2.44",
32
- "@tomflow/chatloop-context": "0.6.9",
33
- "@tomflow/chatloop-trace": "0.4.3"
32
+ "@tomflow/chatloop-context": "0.6.10",
33
+ "@tomflow/chatloop-trace": "0.4.4"
34
34
  },
35
35
  "engines": {
36
36
  "node": ">=24"
37
37
  },
38
38
  "optionalDependencies": {
39
- "@tomflow/chatloop-tunnel-darwin-x64": "0.0.23",
40
- "@tomflow/chatloop-tunnel-darwin-arm64": "0.0.23"
39
+ "@tomflow/chatloop-tunnel-darwin-x64": "0.0.24",
40
+ "@tomflow/chatloop-tunnel-darwin-arm64": "0.0.24"
41
41
  },
42
42
  "exports": {
43
43
  ".": "./index.mjs"