@tomflow/chatloop-tools 0.9.13 → 0.9.15
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 +2 -1
- package/lib/context-gateway.mjs +5 -5
- package/lib/extension-proxy.mjs +26 -14
- package/lib/supervisor-runtime.mjs +5 -5
- package/lib/trace-observation.mjs +4 -3
- package/package.json +5 -5
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});
|
package/lib/context-gateway.mjs
CHANGED
|
@@ -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||
|
|
32
|
-
|
|
31
|
+
||!UUID.test(event.callId)||!UUID.test(event.traceId||'')
|
|
32
|
+
||event.spanId!==event.callId
|
|
33
33
|
||(event.parentSpanId!==null&&event.parentSpanId!==undefined
|
|
34
|
-
|
|
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
|
|
62
|
-
spanId:event.spanId
|
|
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}:{}),
|
package/lib/extension-proxy.mjs
CHANGED
|
@@ -5,30 +5,42 @@ 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
|
|
|
18
18
|
|
|
19
19
|
|
|
20
|
-
// One
|
|
21
|
-
//
|
|
22
|
-
//
|
|
23
|
-
//
|
|
20
|
+
// One official CLI provider and one public npm bin. Resolve its npm latest
|
|
21
|
+
// at invocation time, never a manually duplicated release number. The CLI's
|
|
22
|
+
// versioned RESULT contract is checked before any business receipt is trusted.
|
|
23
|
+
// Private environment variables cannot replace the official provider.
|
|
24
24
|
export {extensionTools};
|
|
25
|
-
const EXTENSION_PACKAGE='@tomflow/chatloop-extension@
|
|
26
|
-
const EXTENSION_VERSION='0.4.9';
|
|
25
|
+
const EXTENSION_PACKAGE='@tomflow/chatloop-extension@latest';
|
|
27
26
|
const NPX_COMMAND=process.platform==='win32'?'npx.cmd':'npx';
|
|
27
|
+
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;
|
|
28
|
+
// Match the existing Context child-CLI correlation boundary. Never inherit
|
|
29
|
+
// an unverified stale parent from the supervisor process environment.
|
|
30
|
+
function childApiEnvironment(){
|
|
31
|
+
const env={...process.env};
|
|
32
|
+
try{
|
|
33
|
+
const parent=readApiParent?.();
|
|
34
|
+
if(parent&&UUID.test(parent.traceId||'')&&UUID.test(parent.spanId||''))
|
|
35
|
+
env.CHAT_LOOP_API_PARENT=JSON.stringify(parent);
|
|
36
|
+
else delete env.CHAT_LOOP_API_PARENT;
|
|
37
|
+
}catch{delete env.CHAT_LOOP_API_PARENT}
|
|
38
|
+
return env;
|
|
39
|
+
}
|
|
28
40
|
export const extensionInvocation=name=>{
|
|
29
41
|
const command=extensionCommand(name);
|
|
30
42
|
if(!command)return null;
|
|
31
|
-
return {executable:NPX_COMMAND,
|
|
43
|
+
return {executable:NPX_COMMAND,
|
|
32
44
|
args:['--yes','--package='+EXTENSION_PACKAGE,'chatloop-extension',...command]};
|
|
33
45
|
};
|
|
34
46
|
const fail=code=>({isError:true,content:[{type:'text',text:code}]});
|
|
@@ -40,7 +52,7 @@ export async function forwardExtensionAction(name,args={}) {
|
|
|
40
52
|
if(name==='clean')invocation.args.push(String(args.tabId));
|
|
41
53
|
const response=await new Promise(resolve=>{
|
|
42
54
|
const child=spawn(invocation.executable,invocation.args,{stdio:[control?'pipe':'ignore','pipe','pipe'],
|
|
43
|
-
cwd:tmpdir(),windowsHide:true,env:
|
|
55
|
+
cwd:tmpdir(),windowsHide:true,env:childApiEnvironment()});
|
|
44
56
|
let stdout='',stdoutBytes=0,finished=false,closed=false,tailTimer=null;
|
|
45
57
|
const settle=(value,receiptCompleted=false)=>{
|
|
46
58
|
if(finished)return;
|
|
@@ -63,9 +75,9 @@ export async function forwardExtensionAction(name,args={}) {
|
|
|
63
75
|
// The CLI emits RESULT only after its business outcome is known.
|
|
64
76
|
// Subsequent exit/drain belongs to soft telemetry, not the receipt.
|
|
65
77
|
const result=acceptExtensionCliReceipt(msg,command,msg.ok===true?0:1);
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
78
|
+
// Latest is mutable. Trust only the declared CLI v1 protocol, exact
|
|
79
|
+
// command, structural result and action receipt, never a stale pin.
|
|
80
|
+
settle(result.ok?result.value:fail(result.code),true);
|
|
69
81
|
return true;
|
|
70
82
|
};
|
|
71
83
|
// Decode UTF-8 incrementally, and accept the completed RESULT frame
|
|
@@ -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
|
-
|
|
70
|
-
|
|
71
|
-
(req.parentSpanId!==undefined
|
|
72
|
-
|
|
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
|
|
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
|
-
|
|
38
|
-
||(req.parentSpanId!==undefined
|
|
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
|
-
|
|
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.
|
|
6
|
+
"version": "0.9.15",
|
|
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.
|
|
33
|
-
"@tomflow/chatloop-trace": "0.4.
|
|
32
|
+
"@tomflow/chatloop-context": "0.6.11",
|
|
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.
|
|
40
|
-
"@tomflow/chatloop-tunnel-darwin-arm64": "0.0.
|
|
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"
|