@tomflow/chatloop-tools 0.9.27 → 0.9.28

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
@@ -66,7 +66,7 @@ The six built-in Providers are:
66
66
  - `runtime`: exact-request receipt lookup without replay
67
67
  - `context`: independent Context SDK read/write schemas and fixed CLI
68
68
  - `trace`: Project-scoped diagnosis and SOFT stage observations, plus a bearer-token-scoped Form Trace lookup using the Prepare `traceRef`
69
- - `form`: a stateless generic single-select MCP App. `prepare` renders caller-defined options and optional text input, preserves or generates `formId`, and returns a random `traceRef`; `submit` returns the selected value/label and optional text to the caller. It does not send Chat messages, interpret business meaning, call Context, retain prepared-form state, or impose expiry. Prepare/Submit API spans and soft observations are correlated in the existing Trace writer by `sessionRef=traceRef` and `evidenceRef=formId`; Trace loss never blocks or changes the returned Form data.
69
+ - `form`: a stateless generic single-select MCP App. `prepare` validates caller-defined options and optional text input, preserves or generates `formId`, and returns a random `traceRef`; the app-only `render` acknowledgement records that the view was displayed; `submit` returns the selected value/label and optional text to the caller. It does not send Chat messages, interpret business meaning, call Context, retain prepared-form state, create a submission ledger, or impose expiry. Prepare/Render/Submit API spans and soft observations are correlated in the existing Trace writer by `sessionRef=traceRef` and `evidenceRef=formId`; Trace loss never blocks or changes the returned Form data.
70
70
 
71
71
  `npm run build:providers` generates `providers.generated.mjs`, the static
72
72
  assembly and release fingerprint manifest. Both `tools/list` and `tools/call`
@@ -109,14 +109,13 @@ to any existing Provider, the Gateway, or either npm entrypoint.
109
109
  trigger retries of unknown effects. In particular, verified Extension MCP
110
110
  results are returned **before** optional Trace transport finishes; a
111
111
  slow, rejecting or unavailable observer cannot replace the action receipt.
112
- Form submission claims are a generic Supervisor idempotency concern:
113
- the dedicated private ledger durably records the opaque `traceRef` claim
114
- independently of the 30-day Trace retention window. A failed or unknown
115
- ledger write blocks the user message and forbids retry. Once the claim is
116
- durably committed, Trace observation failure never reverses or blocks the
117
- Form result; the missing evidence is surfaced by Trace health/diagnose.
118
- Form observations remain best-effort evidence and are not an all-API AOP
119
- coverage claim.
112
+ Form Submit is a pure data-return operation: it creates no business side
113
+ effect, sends no user message, and writes no idempotency ledger. Repeating
114
+ the same Submit returns the same caller-provided selection data. The 30-day
115
+ retention policy applies only to Trace records; it does not expire a Form
116
+ or invalidate its `formId`/`traceRef`. Form observations remain best-effort
117
+ evidence; Trace failure never blocks or changes the Form result and is
118
+ surfaced through Trace health/diagnose.
120
119
 
121
120
  No legacy Task Registry MCP or JSON fallback is shipped. Historical
122
121
  SourceUnit files remain migration evidence, not alternate current facts.
@@ -0,0 +1,113 @@
1
+ import {spawn} from 'node:child_process';
2
+ import {existsSync} from 'node:fs';
3
+ import {homedir} from 'node:os';
4
+ import {join} from 'node:path';
5
+
6
+ export function tunnelBinaryPath(stage,platform=process.platform+'-'+process.arch){
7
+ if(typeof stage!=='string'||!stage.startsWith('/')
8
+ ||!/^darwin-(?:arm64|x64)$/.test(platform))
9
+ throw Object.assign(Error('TUNNEL_PROBE_PATH_INVALID'),{
10
+ code:'TUNNEL_PROBE_PATH_INVALID'});
11
+ return join(stage,'node_modules','@tomflow',
12
+ 'chatloop-tunnel-'+platform,'bin','tunnel-client');
13
+ }
14
+
15
+ export async function verifyTunnelConnection(p,verified,ports={}){
16
+ if(process.env.CHAT_LOOP_TEST_UPGRADE_TRACE)return {result:'ok',testOnly:true};
17
+ const {run,runtimeLaunchEnv}=ports;
18
+ if(typeof run!=='function'||typeof runtimeLaunchEnv!=='function')
19
+ throw Object.assign(Error('TUNNEL_PROBE_PORT_MISSING'),{
20
+ code:'TUNNEL_PROBE_PORT_MISSING'});
21
+ const tunnel=verified.results?.find(x=>x.toolId==='tunnel');
22
+ const binary=tunnelBinaryPath(p.stage);
23
+ const healthFile=ports.healthFile||join(homedir(),'Library',
24
+ 'Application Support','tunnel-client','health','chat-loop.url');
25
+ if(!Number.isSafeInteger(tunnel?.pid)||!existsSync(binary)
26
+ ||!existsSync(healthFile))
27
+ throw Object.assign(Error('NEW_RUNTIME_TUNNEL_PROBE_UNAVAILABLE'),{
28
+ code:'NEW_RUNTIME_TUNNEL_PROBE_UNAVAILABLE'});
29
+ let last;
30
+ for(let attempt=0;attempt<30;attempt++){
31
+ try{
32
+ const output=await run(binary,['health','--url-file',healthFile,
33
+ '--pid',String(tunnel.pid),'--require-control-plane-poll','--json'],
34
+ {env:runtimeLaunchEnv()});
35
+ const result=JSON.parse(output.trim());
36
+ if(result.result==='ok'&&result.healthz?.ok===true
37
+ &&result.readyz?.ok===true&&result.control_plane_poll?.ok===true)
38
+ return {result:'ok',pid:tunnel.pid,controlPlanePoll:true};
39
+ last=result;
40
+ }catch(error){last={code:error.code||'TUNNEL_HEALTH_FAILED'};}
41
+ await new Promise(resolve=>setTimeout(resolve,500));
42
+ }
43
+ throw Object.assign(Error('NEW_RUNTIME_TUNNEL_CONNECTION_UNHEALTHY'),{
44
+ code:'NEW_RUNTIME_TUNNEL_CONNECTION_UNHEALTHY',tunnelStatus:last});
45
+ }
46
+ export async function verifyMcpTools(p,ports={}){
47
+ if(process.env.CHAT_LOOP_TEST_UPGRADE_TRACE)return {ok:true,testOnly:true};
48
+ const {runtimeLaunchEnv}=ports;
49
+ if(typeof runtimeLaunchEnv!=='function')
50
+ throw Object.assign(Error('MCP_PROBE_PORT_MISSING'),{
51
+ code:'MCP_PROBE_PORT_MISSING'});
52
+ const child=spawn(process.execPath,[p.entry,'mcp'],{
53
+ env:{...runtimeLaunchEnv(),CHAT_LOOP_API_LOG_STDERR:'0'},
54
+ stdio:['pipe','pipe','pipe'],windowsHide:true
55
+ });
56
+ let buffer='',stderr='',nextId=0;
57
+ const waiting=new Map();
58
+ const rejectPending=error=>{
59
+ for(const pending of waiting.values()){
60
+ clearTimeout(pending.timer);pending.reject(error);
61
+ }
62
+ waiting.clear();
63
+ };
64
+ child.stdout.setEncoding('utf8');
65
+ child.stderr.setEncoding('utf8');
66
+ child.stdout.on('data',chunk=>{
67
+ buffer+=chunk;
68
+ let end;
69
+ while((end=buffer.indexOf('\n'))>=0){
70
+ const line=buffer.slice(0,end);buffer=buffer.slice(end+1);
71
+ let packet;try{packet=JSON.parse(line)}catch{continue;}
72
+ const pending=waiting.get(packet.id);
73
+ if(pending){waiting.delete(packet.id);clearTimeout(pending.timer);pending.resolve(packet);}
74
+ }
75
+ });
76
+ child.stderr.on('data',chunk=>{stderr=(stderr+chunk).slice(-2048)});
77
+ child.once('error',error=>rejectPending(error));
78
+ child.once('exit',code=>rejectPending(Error('MCP_PROBE_EXIT:'+code+':'+stderr.slice(-500))));
79
+ const request=(method,params={})=>new Promise((resolve,reject)=>{
80
+ const id=++nextId;
81
+ const timer=setTimeout(()=>{waiting.delete(id);reject(Error('MCP_PROBE_TIMEOUT:'+method))},8000);
82
+ waiting.set(id,{resolve,reject,timer});
83
+ child.stdin.write(JSON.stringify({jsonrpc:'2.0',id,method,params})+'\n');
84
+ });
85
+ try{
86
+ const init=await request('initialize',{protocolVersion:'2025-11-25',
87
+ capabilities:{},clientInfo:{name:'chat-loop-upgrade-probe',version:p.version}});
88
+ if(init.result?.serverInfo?.version!==p.version)
89
+ throw Object.assign(Error('MCP_PROBE_VERSION_MISMATCH'),{
90
+ code:'MCP_PROBE_VERSION_MISMATCH'});
91
+ child.stdin.write(JSON.stringify({jsonrpc:'2.0',method:'notifications/initialized'})+'\n');
92
+ const listed=await request('tools/list');
93
+ const names=listed.result?.tools?.map(x=>x.name)||[];
94
+ for(const name of ['chat_loop_form__prepare','chat_loop_form__render',
95
+ 'chat_loop_form__submit'])
96
+ if(!names.includes(name))throw Object.assign(Error('MCP_PROBE_REQUIRED_TOOL_MISSING'),{
97
+ code:'MCP_PROBE_REQUIRED_TOOL_MISSING'});
98
+ const resources=await request('resources/list');
99
+ const uri=resources.result?.resources?.find(x=>x.uri==='ui://chat-loop/form/v3')?.uri;
100
+ if(!uri)throw Object.assign(Error('MCP_PROBE_FORM_RESOURCE_MISSING'),{
101
+ code:'MCP_PROBE_FORM_RESOURCE_MISSING'});
102
+ const view=await request('resources/read',{uri});
103
+ const html=view.result?.contents?.[0]?.text||'';
104
+ if(!html.includes('chat_loop_form__render'))
105
+ throw Object.assign(Error('MCP_PROBE_FORM_APP_OUTDATED'),{
106
+ code:'MCP_PROBE_FORM_APP_OUTDATED'});
107
+ return {ok:true,toolCount:names.length,formResource:uri};
108
+ }finally{
109
+ try{child.stdin.end();child.kill('SIGTERM')}catch{}
110
+ await Promise.race([new Promise(resolve=>child.once('exit',resolve)),
111
+ new Promise(resolve=>setTimeout(resolve,1000))]);
112
+ }
113
+ }
@@ -1,10 +1,9 @@
1
1
  // Supervisor cutover lifecycle. All package/runtime helpers arrive as
2
2
  // explicit ports from the SDK composition root; this module owns no state.
3
3
  import {randomUUID} from 'node:crypto';
4
- import {spawn} from 'node:child_process';
5
4
  import {existsSync,mkdirSync,openSync,closeSync,unlinkSync,lstatSync,readFileSync,writeFileSync} from 'node:fs';
6
- import {homedir} from 'node:os';
7
5
  import {join,dirname} from 'node:path';
6
+ import {verifyTunnelConnection,verifyMcpTools} from './release-health-checks.mjs';
8
7
  let PACKAGE_VERSION,CONTRACT,lifecycleDeadlineMs,talkForUpgrade,
9
8
  activeDesktopCommands,awaitStopped,checkedUpgradeBase,upgradeLayout,
10
9
  run,cli,runtimeLaunchEnv,verifyPreparedRelease,atomicWrite,readJson,
@@ -61,100 +60,6 @@ function backupConfiguration(p){
61
60
  return directory;
62
61
  }
63
62
 
64
- async function verifyTunnelConnection(p,verified){
65
- if(process.env.CHAT_LOOP_TEST_UPGRADE_TRACE)return {result:'ok',testOnly:true};
66
- const tunnel=verified.results?.find(x=>x.toolId==='tunnel');
67
- const platform=process.platform+'-'+process.arch;
68
- const binary=join(dirname(dirname(p.entry)),'node_modules','@tomflow',
69
- 'chatloop-tunnel-'+platform,'bin','tunnel-client');
70
- const healthFile=join(homedir(),'Library','Application Support',
71
- 'tunnel-client','health','chat-loop.url');
72
- if(!Number.isSafeInteger(tunnel?.pid)||!existsSync(binary)||!existsSync(healthFile))
73
- throw Object.assign(Error('NEW_RUNTIME_TUNNEL_PROBE_UNAVAILABLE'),{
74
- code:'NEW_RUNTIME_TUNNEL_PROBE_UNAVAILABLE'});
75
- let last;
76
- for(let attempt=0;attempt<30;attempt++){
77
- try{
78
- const output=await run(binary,['health','--url-file',healthFile,
79
- '--pid',String(tunnel.pid),'--require-control-plane-poll','--json'],
80
- {env:runtimeLaunchEnv()});
81
- const result=JSON.parse(output.trim());
82
- if(result.result==='ok'&&result.healthz?.ok===true
83
- &&result.readyz?.ok===true&&result.control_plane_poll?.ok===true)
84
- return {result:'ok',pid:tunnel.pid,controlPlanePoll:true};
85
- last=result;
86
- }catch(error){last={code:error.code||'TUNNEL_HEALTH_FAILED'};}
87
- await new Promise(resolve=>setTimeout(resolve,500));
88
- }
89
- throw Object.assign(Error('NEW_RUNTIME_TUNNEL_CONNECTION_UNHEALTHY'),{
90
- code:'NEW_RUNTIME_TUNNEL_CONNECTION_UNHEALTHY',tunnelStatus:last});
91
- }
92
-
93
- async function verifyMcpTools(p){
94
- if(process.env.CHAT_LOOP_TEST_UPGRADE_TRACE)return {ok:true,testOnly:true};
95
- const child=spawn(process.execPath,[p.entry,'mcp'],{
96
- env:{...runtimeLaunchEnv(),CHAT_LOOP_API_LOG_STDERR:'0'},
97
- stdio:['pipe','pipe','pipe'],windowsHide:true
98
- });
99
- let buffer='',stderr='',nextId=0;
100
- const waiting=new Map();
101
- const rejectPending=error=>{
102
- for(const pending of waiting.values()){
103
- clearTimeout(pending.timer);pending.reject(error);
104
- }
105
- waiting.clear();
106
- };
107
- child.stdout.setEncoding('utf8');
108
- child.stderr.setEncoding('utf8');
109
- child.stdout.on('data',chunk=>{
110
- buffer+=chunk;
111
- let end;
112
- while((end=buffer.indexOf('\n'))>=0){
113
- const line=buffer.slice(0,end);buffer=buffer.slice(end+1);
114
- let packet;try{packet=JSON.parse(line)}catch{continue;}
115
- const pending=waiting.get(packet.id);
116
- if(pending){waiting.delete(packet.id);clearTimeout(pending.timer);pending.resolve(packet);}
117
- }
118
- });
119
- child.stderr.on('data',chunk=>{stderr=(stderr+chunk).slice(-2048)});
120
- child.once('error',error=>rejectPending(error));
121
- child.once('exit',code=>rejectPending(Error('MCP_PROBE_EXIT:'+code+':'+stderr.slice(-500))));
122
- const request=(method,params={})=>new Promise((resolve,reject)=>{
123
- const id=++nextId;
124
- const timer=setTimeout(()=>{waiting.delete(id);reject(Error('MCP_PROBE_TIMEOUT:'+method))},8000);
125
- waiting.set(id,{resolve,reject,timer});
126
- child.stdin.write(JSON.stringify({jsonrpc:'2.0',id,method,params})+'\n');
127
- });
128
- try{
129
- const init=await request('initialize',{protocolVersion:'2025-11-25',
130
- capabilities:{},clientInfo:{name:'chat-loop-upgrade-probe',version:p.version}});
131
- if(init.result?.serverInfo?.version!==p.version)
132
- throw Object.assign(Error('MCP_PROBE_VERSION_MISMATCH'),{
133
- code:'MCP_PROBE_VERSION_MISMATCH'});
134
- child.stdin.write(JSON.stringify({jsonrpc:'2.0',method:'notifications/initialized'})+'\n');
135
- const listed=await request('tools/list');
136
- const names=listed.result?.tools?.map(x=>x.name)||[];
137
- for(const name of ['chat_loop_form__prepare','chat_loop_form__render',
138
- 'chat_loop_form__submit'])
139
- if(!names.includes(name))throw Object.assign(Error('MCP_PROBE_REQUIRED_TOOL_MISSING'),{
140
- code:'MCP_PROBE_REQUIRED_TOOL_MISSING'});
141
- const resources=await request('resources/list');
142
- const uri=resources.result?.resources?.find(x=>x.uri==='ui://chat-loop/form/v3')?.uri;
143
- if(!uri)throw Object.assign(Error('MCP_PROBE_FORM_RESOURCE_MISSING'),{
144
- code:'MCP_PROBE_FORM_RESOURCE_MISSING'});
145
- const view=await request('resources/read',{uri});
146
- const html=view.result?.contents?.[0]?.text||'';
147
- if(!html.includes('chat_loop_form__render'))
148
- throw Object.assign(Error('MCP_PROBE_FORM_APP_OUTDATED'),{
149
- code:'MCP_PROBE_FORM_APP_OUTDATED'});
150
- return {ok:true,toolCount:names.length,formResource:uri};
151
- }finally{
152
- try{child.stdin.end();child.kill('SIGTERM')}catch{}
153
- await Promise.race([new Promise(resolve=>child.once('exit',resolve)),
154
- new Promise(resolve=>setTimeout(resolve,1000))]);
155
- }
156
- }
157
-
158
63
  export async function upgradeRuntime(options={}){
159
64
  if(options.args?.length)return freshResult('FAILED',{code:'INVALID_ARGUMENT'});
160
65
  const base=checkedUpgradeBase(options);
@@ -319,9 +224,9 @@ export async function upgradeRuntime(options={}){
319
224
  code:'NEW_RUNTIME_TUNNEL_UNHEALTHY'
320
225
  });
321
226
  phase='verify-tunnel-connection';
322
- const tunnelConnection=await verifyTunnelConnection(p,verified);
227
+ const tunnelConnection=await verifyTunnelConnection(p,verified,{run,runtimeLaunchEnv});
323
228
  phase='verify-mcp';
324
- const mcp=await verifyMcpTools(p);
229
+ const mcp=await verifyMcpTools(p,{runtimeLaunchEnv});
325
230
  phase='record-new';
326
231
  atomicWrite(p.current,JSON.stringify({version:p.version,entry:p.entry,
327
232
  status:'ACTIVE'},null,2)+'\n');
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.9.27",
6
+ "version": "0.9.28",
7
7
  "type": "module",
8
8
  "description": "Chat Loop local tools: MCP gateway, isolated bundled tunnel-client and unified CLI",
9
9
  "bin": {