@tomflow/chatloop-tools 0.9.0 → 0.9.5

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 CHANGED
@@ -118,7 +118,10 @@ SourceUnit files remain migration evidence, not alternate current facts.
118
118
  documentation links, and both Context/Tools generated compositions.
119
119
  - Workspace `npm run pack:tools -- <existing-output-directory>` produces
120
120
  an offline, version-pinned Tools tarball containing the declared Context
121
- and Trace SDKs. The build checks the provider manifest before packaging.
121
+ and Trace SDKs **plus their verified runtime dependency closure**
122
+ (`ps-list` and `@tomflow/chatloop-extension` for the current Context SDK).
123
+ Release tests must cold-install the tarball and actually load Context's
124
+ Local Operator; checking filenames or importing only the SDK root is insufficient. The build checks the provider manifest before packaging.
122
125
  Release staging uses the **candidate package's own** generated Provider manifest
123
126
  and fingerprints every Tools-owned source file, including new Provider helpers;
124
127
  missing, substituted, or added files block activation before Owner handoff.
package/index.mjs CHANGED
@@ -12,14 +12,45 @@ import {createApiAspect} from './lib/api-aspect.mjs';
12
12
  // API's business execution stack.
13
13
  let auditPort=null;
14
14
  const auditBacklog=[];
15
+ let auditDraining=false,auditRetryTimer=null,auditNoOwnerRetries=0;
16
+ const MAX_AUDIT_BACKLOG=1024,MAX_NO_OWNER_RETRIES=20;
17
+ // The CLI can emit BEGIN before a cold Supervisor has opened its IPC socket.
18
+ // Keep ordered, bounded soft observations until that exact socket exists;
19
+ // never replay a business API, and never retry an ambiguous audit IPC result.
20
+ async function drainAudit(){
21
+ if(auditDraining||!auditPort)return;
22
+ auditDraining=true;
23
+ try{
24
+ while(auditBacklog.length){
25
+ try{
26
+ await auditPort(auditBacklog[0]);
27
+ auditBacklog.shift();
28
+ auditNoOwnerRetries=0;
29
+ }catch(error){
30
+ if(['ENOENT','ECONNREFUSED'].includes(error?.code)&&
31
+ auditNoOwnerRetries++<MAX_NO_OWNER_RETRIES)break;
32
+ auditBacklog.shift(); // unknown telemetry is dropped, not retried
33
+ auditNoOwnerRetries=0;
34
+ }
35
+ }
36
+ }finally{
37
+ auditDraining=false;
38
+ if(auditBacklog.length&&!auditRetryTimer){
39
+ auditRetryTimer=setTimeout(()=>{
40
+ auditRetryTimer=null;
41
+ void drainAudit();
42
+ },100);
43
+ auditRetryTimer.unref?.(); // telemetry never keeps the CLI alive
44
+ }
45
+ }
46
+ }
15
47
  const recordApi=event=>{
16
- if(!auditPort){
17
- if(auditBacklog.length<1024)auditBacklog.push(event);
18
- return;
48
+ if(auditBacklog.length>=MAX_AUDIT_BACKLOG)return;
49
+ auditBacklog.push(event);
50
+ if(auditPort){
51
+ if(auditRetryTimer){clearTimeout(auditRetryTimer);auditRetryTimer=null;}
52
+ void drainAudit();
19
53
  }
20
- try{const pending=auditPort(event);
21
- if(pending&&typeof pending.then==='function')Promise.resolve(pending).catch(()=>{});
22
- }catch{/* Never let telemetry alter an SDK or CLI call. */}
23
54
  };
24
55
  const apiAspect=createApiAspect('@tomflow/chatloop-tools',{sink:recordApi});
25
56
  // The CLI and Supervisor executable import only this package root.
@@ -151,7 +182,7 @@ async function runtime(){
151
182
  ...(event.durationMs!==null?{durationMs:event.durationMs}:{}),
152
183
  ...(event.errorCode?{errorCode:event.errorCode}:{})
153
184
  },900);
154
- for(const entry of auditBacklog.splice(0))recordApi(entry);
185
+ void drainAudit();
155
186
  const mcpAudit=createApiAspect('@tomflow/chatloop-tools',
156
187
  {sink:recordApi});
157
188
  const callCache=new Map();
@@ -22,8 +22,8 @@ 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.0';
26
- const EXTENSION_VERSION='0.4.0';
25
+ const EXTENSION_PACKAGE='@tomflow/chatloop-extension@0.4.1';
26
+ const EXTENSION_VERSION='0.4.1';
27
27
  const NPX_COMMAND=process.platform==='win32'?'npx.cmd':'npx';
28
28
  export const extensionInvocation=name=>{
29
29
  const command=extensionCommand(name);
@@ -40,11 +40,12 @@ export const traceDiagnoseTool={
40
40
  };
41
41
  // Pre-Session agent decisions are SOFT observations, not authenticated
42
42
  // ChatGPT user-click, approval, Context write or Native Owner receipts.
43
- const STAGE_NAMES=['intent','project','tooling'];
43
+ const STAGE_NAMES=['intent','project','tooling','requirements','plan','approval'];
44
44
  const STAGE_OUTCOMES=['OBSERVED','BLOCKED','UNVERIFIED'];
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;
45
46
  export const traceStageTool={
46
47
  name:'chat_loop_trace_stage',
47
- description:'Record a scoped, explicitly SOFT agent-stage observation in the existing single Trace writer. Does not authenticate @ clicks, grant Context/Owner, or store conversation content. Return traceId for later calls; never use this as task approval.',
48
+ description:'Record an explicitly SOFT agent-stage observation (including R/P revision) in the existing Trace writer. Optional user:<uuid> evidenceRef is a caller assertion, NOT verified host-click provenance; no approval/Owner/content is stored. Return traceId for later calls; never use this as task approval.',
48
49
  inputSchema:{
49
50
  type:'object',additionalProperties:false,
50
51
  required:['projectRef','stage','outcome'],
@@ -52,7 +53,8 @@ export const traceStageTool={
52
53
  projectRef:{type:'string',pattern:PROJECT.source},
53
54
  traceId:{type:'string',pattern:UUID},
54
55
  stage:{type:'string',enum:STAGE_NAMES},
55
- outcome:{type:'string',enum:STAGE_OUTCOMES}
56
+ outcome:{type:'string',enum:STAGE_OUTCOMES},
57
+ evidenceRef:{type:'string',pattern:USER_EVIDENCE.source}
56
58
  }
57
59
  },
58
60
  annotations:{readOnlyHint:false}
@@ -63,7 +65,9 @@ export async function runTraceStage(args){
63
65
  Object.keys(args).some(k=>!Object.hasOwn(traceStageTool.inputSchema.properties,k))||
64
66
  !STAGE_NAMES.includes(args.stage)||
65
67
  !STAGE_OUTCOMES.includes(args.outcome)||
66
- args.traceId!==undefined&&!new RegExp(UUID).test(args.traceId))
68
+ args.traceId!==undefined&&!new RegExp(UUID).test(args.traceId)||
69
+ args.evidenceRef!==undefined&&(!USER_EVIDENCE.test(args.evidenceRef)
70
+ ||!['requirements','plan','approval'].includes(args.stage)))
67
71
  throw fail('TRACE_INVALID_ARGUMENT');
68
72
  if(typeof args.projectRef!=='string'||!getAllowedProjects().includes(args.projectRef))
69
73
  throw fail('TRACE_PROJECT_ACCESS_DENIED');
@@ -73,11 +77,14 @@ export async function runTraceStage(args){
73
77
  const requestId=randomUUID();
74
78
  const event='agent.'+args.stage+'.soft_'+args.outcome.toLowerCase();
75
79
  const r=await talk({contract:CONTRACT,action:'__trace_observation',
76
- requestId,traceId,projectRef:args.projectRef,event,status},1800);
80
+ requestId,traceId,projectRef:args.projectRef,event,status,
81
+ ...(args.evidenceRef?{evidenceRef:args.evidenceRef}:{})},1800);
77
82
  if(r?.status!=='OK'||!new RegExp(UUID).test(r?.eventId||''))
78
83
  throw fail(r?.error?.code||'TRACE_STAGE_NOT_RECORDED');
79
84
  return {status:'RECORDED_SOFT',confidence:'SOFT_AGENT_OBSERVATION',
80
- traceId,eventId:r.eventId,event,requestId};
85
+ traceId,eventId:r.eventId,event,requestId,
86
+ ...(args.evidenceRef?{evidenceRef:args.evidenceRef,
87
+ provenance:'AGENT_ASSERTED_UNVERIFIED'}:{})};
81
88
  }
82
89
 
83
90
  const getAllowedProjects=()=>{
@@ -67,7 +67,7 @@ export function createSupervisorTraceBridge({traceWriter,contract,error}){
67
67
  eventId:recorded.eventId};
68
68
  }
69
69
  const intent=/^extension\.(continue|handoff)\.(intent\.queued|receipt\.observed)$/.test(req?.event||'');
70
- const agent=/^agent\.(intent|project|tooling)\.soft_(observed|blocked|unverified)$/.test(req?.event||'');
70
+ const agent=/^agent\.(intent|project|tooling|requirements|plan|approval)\.soft_(observed|blocked|unverified)$/.test(req?.event||'');
71
71
  const agentStatus=req?.event?.endsWith('_observed')?'CONFIRMED':
72
72
  req?.event?.endsWith('_blocked')?'BLOCKED':'UNKNOWN';
73
73
  const validEvent=['extension.start.observed','extension.status.observed'].includes(req?.event)
@@ -79,7 +79,9 @@ export function createSupervisorTraceBridge({traceWriter,contract,error}){
79
79
  :['CONFIRMED','UNKNOWN','BLOCKED'].includes(req.status))
80
80
  ||typeof req.traceId!=='string'
81
81
  ||(agent&&(req.sessionRef!==undefined||req.taskRef!==undefined||
82
- req.generation!==undefined||req.evidenceRef!==undefined||
82
+ req.generation!==undefined||
83
+ (req.evidenceRef!==undefined&&(!/^user:[0-9a-f-]{36}$/i.test(req.evidenceRef)
84
+ ||!/^agent\.(requirements|plan|approval)\./.test(req.event)))||
83
85
  req.actionId!==undefined||req.errorCode!==undefined||!UUID_RE.test(req.traceId)))
84
86
  ||(intent&&(!/^[a-f0-9]{32}$/.test(req.actionId||'')
85
87
  ||req.evidenceRef!==req.actionId)))throw error('TRACE_INVALID_ARGUMENT');
@@ -90,6 +92,9 @@ export function createSupervisorTraceBridge({traceWriter,contract,error}){
90
92
  taskRef:req.taskRef??null,generation:req.generation??null,
91
93
  requestId:req.requestId,component:'gateway',
92
94
  ...(intent?{actionId:req.actionId,evidenceRef:req.evidenceRef}
95
+ :agent&&typeof req.evidenceRef==='string'&&
96
+ /^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.test(req.evidenceRef)
97
+ ?{evidenceRef:req.evidenceRef}
93
98
  :req.event==='extension.status.observed'&&typeof req.evidenceRef==='string'
94
99
  &&/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/.test(req.evidenceRef)
95
100
  ?{evidenceRef:req.evidenceRef}:{}),
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.9.0",
6
+ "version": "0.9.5",
7
7
  "type": "module",
8
8
  "description": "Chat Loop local tools: MCP gateway, isolated bundled tunnel-client and unified CLI",
9
9
  "bin": {
@@ -29,8 +29,8 @@
29
29
  },
30
30
  "dependencies": {
31
31
  "@wonderwhy-er/desktop-commander": "0.2.44",
32
- "@tomflow/chatloop-context": "0.6.0",
33
- "@tomflow/chatloop-trace": "0.4.0"
32
+ "@tomflow/chatloop-context": "0.6.1",
33
+ "@tomflow/chatloop-trace": "0.4.1"
34
34
  },
35
35
  "engines": {
36
36
  "node": ">=24"