@tomflow/chatloop-tools 0.9.45 → 0.9.46
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 +4 -1
- package/index.mjs +32 -9
- package/lib/trace-gateway.mjs +27 -14
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -23,6 +23,9 @@ With an exact authorized Context Project grant it also aggregates that
|
|
|
23
23
|
Project's sanitized `context.api` events. Counts, success, failure,
|
|
24
24
|
incomplete calls and calls per minute are grouped by named entrypoint and
|
|
25
25
|
deduplicated by call/span ID; unmatched completions are reported separately.
|
|
26
|
+
An MCP tool response with `isError:true` is recorded as a FAILED API span while
|
|
27
|
+
its original MCP result remains unchanged; unknown tool names use the bounded
|
|
28
|
+
`mcp.unknown_tool` observation, not an invented per-name API.
|
|
26
29
|
Nested calls share a soft `traceId` and retain unique `spanId/parentSpanId`,
|
|
27
30
|
including a sanitized MCP-to-Context-CLI parent handoff.
|
|
28
31
|
It never starts a Supervisor, opens a browser, replays a call, or reads model
|
|
@@ -65,7 +68,7 @@ The seven built-in Providers are:
|
|
|
65
68
|
- `extension`: nine scoped actions delegated to the official Extension CLI, currently resolved through npm `@latest` per invocation (a mutable dist-tag, not a pinned runtime/Chrome version); the received CLI contract must be verified independently. Timeout, missing/invalid CLI identity, and malformed action results return `EXTENSION_RESULT_UNKNOWN`, never a safe-to-retry send failure; the actual Chrome-loaded Owner/version still require separate verification
|
|
66
69
|
- `runtime`: exact-request receipt lookup without replay
|
|
67
70
|
- `context`: independent Context SDK read/write schemas and fixed CLI
|
|
68
|
-
- `trace`: Project-scoped diagnosis and SOFT stage observations; an independent `api_system` lookup can correlate an individual Form/Document App using its opaque `traceRef` returned by Prepare/Show. These are soft API/UI observations, not authenticated clicks or business approvals.
|
|
71
|
+
- `trace`: Project-scoped diagnosis and SOFT stage observations; an independent `api_system` lookup can correlate an individual Form/Document App using its opaque `traceRef` returned by Prepare/Show. App kind remains `UNVERIFIED` when no matching event is found. Diagnosis separates `writerHealth` (Supervisor Writer status) from `gatewayHealth` (including process-wide App observation loss); loss counters appear under `globalObservationWarnings` and are never assigned to a particular Project/Form/Document as an invented `gap`. Missing actual App parent API spans remain scoped gaps. A rendered but unsubmitted Form has no submit event to expect. Source event timestamps remain ISO UTC; operator reports must label their display timezone. These are soft API/UI observations, not authenticated clicks, user-message identity or business approvals.
|
|
69
72
|
- Document: independent generic read-only MCP App (show/render). Caller controls title, content and open-ended format; reader safely renders supported formats and retains the original source for one-click copy, with a source fallback for other formats. It does not create a business template, approval, Form or new Chat message.
|
|
70
73
|
- Form: stateless, generic single-select MCP App. Prepare accepts only caller-defined options and optional conditional text input; it preserves or generates formId and returns a random traceRef. It never accepts, stores, renders or copies a business document: the caller presents R/P separately using the generic Document App. Render acknowledges the UI; Submit returns selected value/label and optional text. ui/update-model-context makes a result available to future model turns but does not trigger one or prove approval. Form does not send Chat messages, interpret decisions, call Context or impose expiry. Prepare/Render/Submit observations are correlated by formId and traceRef without altering results.
|
|
71
74
|
|
package/index.mjs
CHANGED
|
@@ -173,7 +173,12 @@ async function runtime(){
|
|
|
173
173
|
const traceTalk=async request=>{
|
|
174
174
|
const result=await control.talk(request);
|
|
175
175
|
if(request?.action!=='__trace_health'||!result?.traceHealth)return result;
|
|
176
|
-
|
|
176
|
+
// Supervisor Writer health is authoritative for persisted spans.
|
|
177
|
+
// Local App loss counters describe this Gateway process, not the Writer
|
|
178
|
+
// or any individual Form/Document traceRef. Preserve both dimensions.
|
|
179
|
+
const health={...result.traceHealth,
|
|
180
|
+
writerStatus:result.traceHealth.status,
|
|
181
|
+
formObservationLost,documentObservationLost};
|
|
177
182
|
if((formObservationLost>0||documentObservationLost>0)
|
|
178
183
|
&&health.status==='OK')health.status='TRACE_DEGRADED';
|
|
179
184
|
return {...result,traceHealth:health};
|
|
@@ -250,20 +255,38 @@ async function runtime(){
|
|
|
250
255
|
// Unknown tool names must not grow a process-lifetime cache.
|
|
251
256
|
const declaredToolNames=new Set(providerDefinitions.flatMap(p=>p.names));
|
|
252
257
|
const callCache=new Map();
|
|
253
|
-
|
|
254
|
-
|
|
258
|
+
// MCP isError is a legitimate provider result, but it represents a
|
|
259
|
+
// failed tool operation. Observe FAILED without changing the MCP reply.
|
|
260
|
+
const observeTool=name=>mcpAudit.observe(name,async(tool,args)=>{
|
|
261
|
+
const result=await coreToolRouter.call(tool,args);
|
|
262
|
+
if(result?.isError===true){
|
|
263
|
+
const error=Object.assign(Error('MCP_TOOL_ERROR'),{
|
|
264
|
+
code:'MCP_TOOL_ERROR',toolResult:result});
|
|
265
|
+
throw error;
|
|
266
|
+
}
|
|
267
|
+
return result;
|
|
268
|
+
},'mcp');
|
|
269
|
+
const unknownToolCall=observeTool('mcp.unknown_tool');
|
|
255
270
|
const toolRouter=Object.freeze({
|
|
256
271
|
list:mcpAudit.observe('mcp.tools.list',coreToolRouter.list,'mcp'),
|
|
257
272
|
listResources:mcpAudit.observe('mcp.resources.list',
|
|
258
273
|
coreToolRouter.listResources,'mcp'),
|
|
259
274
|
readResource:mcpAudit.observe('mcp.resources.read',
|
|
260
275
|
coreToolRouter.readResource,'mcp'),
|
|
261
|
-
call(name,args){
|
|
262
|
-
|
|
263
|
-
if(
|
|
264
|
-
callCache.set(name,
|
|
265
|
-
|
|
266
|
-
|
|
276
|
+
async call(name,args){
|
|
277
|
+
let observed=unknownToolCall;
|
|
278
|
+
if(declaredToolNames.has(name)){
|
|
279
|
+
if(!callCache.has(name))callCache.set(name,observeTool('mcp.'+name));
|
|
280
|
+
observed=callCache.get(name);
|
|
281
|
+
}
|
|
282
|
+
try{return await observed(name,args)}
|
|
283
|
+
catch(error){
|
|
284
|
+
// The synthetic observation failure carries the exact existing
|
|
285
|
+
// MCP result; never convert it into a second tool invocation.
|
|
286
|
+
if(error?.code==='MCP_TOOL_ERROR'&&error.toolResult?.isError===true)
|
|
287
|
+
return error.toolResult;
|
|
288
|
+
throw error;
|
|
289
|
+
}
|
|
267
290
|
}
|
|
268
291
|
});
|
|
269
292
|
gateway.configureGateway({
|
package/lib/trace-gateway.mjs
CHANGED
|
@@ -43,7 +43,7 @@ export const traceDiagnoseTool={
|
|
|
43
43
|
const STAGE_NAMES=['intent','project','tooling','requirements','plan','approval'];
|
|
44
44
|
const STAGE_OUTCOMES=['OBSERVED','BLOCKED','UNVERIFIED'];
|
|
45
45
|
const USER_EVIDENCE=/^user:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
46
|
-
const APP_TRACE_REF=new RegExp(UUID);
|
|
46
|
+
const APP_TRACE_REF=new RegExp('^'+UUID+'$');
|
|
47
47
|
const FORM_ID=/^[A-Za-z0-9][A-Za-z0-9_-]{7,79}$/;
|
|
48
48
|
const DOC_ID=/^[A-Za-z0-9][A-Za-z0-9_.-]{7,127}$/;
|
|
49
49
|
// The event-to-public-API map is the only catalogue of accepted App event
|
|
@@ -123,8 +123,11 @@ async function diagnoseAppTrace(args){
|
|
|
123
123
|
const idPattern=type.startsWith('form.')?FORM_ID:DOC_ID;
|
|
124
124
|
return idPattern.test(event.evidenceRef||'');
|
|
125
125
|
});
|
|
126
|
-
const kind=appEvents
|
|
127
|
-
|
|
126
|
+
const kind=appEvents.length
|
|
127
|
+
?appEvents[0].event.startsWith('document.')?'document':'form'
|
|
128
|
+
:'unknown';
|
|
129
|
+
const matching=kind==='unknown'?[]:
|
|
130
|
+
appEvents.filter(event=>event.event.startsWith(kind+'.'));
|
|
128
131
|
const prefix=kind.toUpperCase();
|
|
129
132
|
const gaps=base.gaps.filter(gap=>gap!=='NO_MATCHING_EVENTS');
|
|
130
133
|
const parentKeys=new Map();
|
|
@@ -171,7 +174,8 @@ async function diagnoseAppTrace(args){
|
|
|
171
174
|
const unknown=matching.some(event=>['UNKNOWN','BLOCKED'].includes(event.status));
|
|
172
175
|
return {traceId:null,projectRef:'api_system',
|
|
173
176
|
...(kind==='form'?{formTraceRef:args.sessionRef,formId:ids.length===1?ids[0]:null}
|
|
174
|
-
:{documentTraceRef:args.sessionRef,documentId:ids.length===1?ids[0]:null}
|
|
177
|
+
:kind==='document'?{documentTraceRef:args.sessionRef,documentId:ids.length===1?ids[0]:null}
|
|
178
|
+
:{appTraceRef:args.sessionRef,appKind:'UNVERIFIED'}),
|
|
175
179
|
inspected:timeline.length,totalMatched:timeline.length,
|
|
176
180
|
lastConfirmed:lastConfirmed?{eventId:lastConfirmed.eventId,
|
|
177
181
|
event:lastConfirmed.event,time:lastConfirmed.time,
|
|
@@ -202,21 +206,30 @@ export async function runTraceDiagnose(args){
|
|
|
202
206
|
const requestId=randomUUID();
|
|
203
207
|
const response=await talk({contract:CONTRACT,action:'__trace_health',
|
|
204
208
|
requestId},1400);
|
|
205
|
-
|
|
209
|
+
const health=response?.contract===CONTRACT
|
|
206
210
|
&&response.requestId===requestId&&response.status==='OK'
|
|
207
|
-
?response.traceHealth
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
211
|
+
?response.traceHealth:null;
|
|
212
|
+
// The Supervisor reports persisted Writer health; the Gateway may
|
|
213
|
+
// independently degrade because a different App observation was lost.
|
|
214
|
+
// Do not turn process-wide counters into gaps on this traceRef/Project.
|
|
215
|
+
result.writerHealth=health?.writerStatus||health?.status||'UNAVAILABLE';
|
|
216
|
+
result.gatewayHealth=health?.status||'UNAVAILABLE';
|
|
217
|
+
if(health?.errorCode)result.writerErrorCode=health.errorCode;
|
|
218
|
+
const globalWarnings=[];
|
|
219
|
+
if(health?.formObservationLost>0)
|
|
220
|
+
globalWarnings.push('FORM_TRACE_OBSERVATION_LOSS');
|
|
221
|
+
if(health?.documentObservationLost>0)
|
|
222
|
+
globalWarnings.push('DOCUMENT_TRACE_OBSERVATION_LOSS');
|
|
223
|
+
if(globalWarnings.length)result.globalObservationWarnings=globalWarnings;
|
|
224
|
+
if(result.writerHealth==='TRACE_DEGRADED'){
|
|
225
|
+
result.gaps.push(health?.errorCode
|
|
226
|
+
?'TRACE_PIPELINE_HEALTH_DEGRADED'
|
|
227
|
+
:'TRACE_HEALTH_DEGRADED_UNCLASSIFIED');
|
|
228
|
+
}
|
|
214
229
|
}catch{result.writerHealth='UNAVAILABLE'}
|
|
215
230
|
if(result.writerHealth!=='OK'){
|
|
216
231
|
if(['UNKNOWN','UNAVAILABLE'].includes(result.writerHealth))
|
|
217
232
|
result.gaps.push('TRACE_WRITER_UNAVAILABLE');
|
|
218
|
-
if(result.writerHealth==='TRACE_DEGRADED')
|
|
219
|
-
result.gaps.push('TRACE_APP_OBSERVATION_LOSS');
|
|
220
233
|
result.confidence='INCOMPLETE';
|
|
221
234
|
result.retryDisposition='VERIFY_AUTHORITATIVE_RECEIPT_FIRST';
|
|
222
235
|
}
|
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.46",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"description": "Chat Loop local tools: MCP gateway, isolated bundled tunnel-client and unified CLI",
|
|
9
9
|
"bin": {
|
|
@@ -36,14 +36,14 @@
|
|
|
36
36
|
"@tomflow/chatloop-context": "0.6.13",
|
|
37
37
|
"@tomflow/chatloop-trace": "0.4.6",
|
|
38
38
|
"@wonderwhy-er/desktop-commander": "0.2.44",
|
|
39
|
-
"
|
|
40
|
-
"
|
|
39
|
+
"@tomflow/chatloop-extension": "0.4.13",
|
|
40
|
+
"ps-list": "9.0.0"
|
|
41
41
|
},
|
|
42
42
|
"bundleDependencies": [
|
|
43
43
|
"@tomflow/chatloop-context",
|
|
44
44
|
"@tomflow/chatloop-trace",
|
|
45
|
-
"
|
|
46
|
-
"
|
|
45
|
+
"@tomflow/chatloop-extension",
|
|
46
|
+
"ps-list"
|
|
47
47
|
],
|
|
48
48
|
"engines": {
|
|
49
49
|
"node": ">=24"
|