@tomflow/chatloop-tools 0.9.12 → 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
@@ -111,13 +111,10 @@ async function runtime(){
111
111
  // Trace and platform carrier SDKs are independent publishers. Their
112
112
  // non-authoritative observation ports join the existing Supervisor sink.
113
113
  // The Trace writer's own writes must not audit themselves recursively.
114
- subscribeTraceApiLog(event=>{
115
- // Supervisor __ping reads Writer.health. Recording that read would
116
- // ping again forever; writer methods are the audit transport itself.
117
- if(['writer.record','writer.recordControl','writer.health']
118
- .includes(event.api))return;
119
- recordApi(event);
120
- });
114
+ // Writer method spans are committed by that writer's own non-recursive
115
+ // raw append path; the shared subscription only transports other Trace
116
+ // SDK calls through the existing Supervisor IPC.
117
+ subscribeTraceApiLog(recordApi);
121
118
  if(typeof platformProvider?.subscribeTunnelApiLog==='function')
122
119
  platformProvider.subscribeTunnelApiLog(recordApi);
123
120
  tunnel.configureTunnelProvider({
@@ -151,7 +148,8 @@ async function runtime(){
151
148
  validExtensionArgs:extensionContract.validExtensionArgs,
152
149
  isControlTool:extensionContract.isControlTool,
153
150
  acceptExtensionCliReceipt:extensionCliContract.acceptExtensionCliReceipt,
154
- extensionTools:extensionContract.extensionTools});
151
+ extensionTools:extensionContract.extensionTools,
152
+ readApiParent:apiAspect.current});
155
153
  release.configureRelease({PACKAGE_VERSION:control.PACKAGE_VERSION,
156
154
  activeDesktopCommands:releasePreflight.activeDesktopCommands,
157
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.8';
26
- const EXTENSION_VERSION='0.4.8';
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',
@@ -134,7 +134,11 @@ const log=(event,detail={})=>{
134
134
  };
135
135
  const traceHealth=()=>{
136
136
  const health=traceWriter.health();
137
+ const writerAuditLost=(health.apiObservation?.dropped||0)>0||
138
+ (health.apiObservation?.sinkFailures||0)>0;
137
139
  return {...health,controlAuditDropped,controlAuditPending:controlAudit.length,
140
+ ...(writerAuditLost&&health.status==='OK'
141
+ ?{status:'TRACE_DEGRADED',errorCode:'TRACE_WRITER_API_LOG_GAP'}:{}),
138
142
  ...(controlAuditDropped>0&&health.status==='OK'
139
143
  ?{status:'TRACE_DEGRADED',errorCode:'TRACE_AUDIT_QUEUE_SATURATED'}:{})};
140
144
  };
@@ -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.12",
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.8",
33
- "@tomflow/chatloop-trace": "0.4.2"
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.21",
40
- "@tomflow/chatloop-tunnel-darwin-arm64": "0.0.21"
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"