@tomflow/chatloop-tools 0.9.26 → 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 +8 -9
- package/lib/release-health-checks.mjs +113 -0
- package/lib/release-upgrade.mjs +36 -14
- package/package.json +1 -1
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`
|
|
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
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
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
|
+
}
|
package/lib/release-upgrade.mjs
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import {randomUUID} from 'node:crypto';
|
|
4
4
|
import {existsSync,mkdirSync,openSync,closeSync,unlinkSync,lstatSync,readFileSync,writeFileSync} from 'node:fs';
|
|
5
5
|
import {join,dirname} from 'node:path';
|
|
6
|
+
import {verifyTunnelConnection,verifyMcpTools} from './release-health-checks.mjs';
|
|
6
7
|
let PACKAGE_VERSION,CONTRACT,lifecycleDeadlineMs,talkForUpgrade,
|
|
7
8
|
activeDesktopCommands,awaitStopped,checkedUpgradeBase,upgradeLayout,
|
|
8
9
|
run,cli,runtimeLaunchEnv,verifyPreparedRelease,atomicWrite,readJson,
|
|
@@ -176,28 +177,44 @@ export async function upgradeRuntime(options={}){
|
|
|
176
177
|
});
|
|
177
178
|
if(!verified){
|
|
178
179
|
phase='start-new';
|
|
179
|
-
const
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
180
|
+
const startEnv={...runtimeLaunchEnv(),CHAT_LOOP_SKIP_UPGRADE:'1'};
|
|
181
|
+
const startupResult=await cli(p.entry,'start',{env:startEnv});
|
|
182
|
+
if(!['OK','STARTING'].includes(startupResult.status)
|
|
183
|
+
&&startupResult.error?.code!=='MANAGER_UNAVAILABLE')
|
|
183
184
|
throw Object.assign(Error('NEW_RUNTIME_UNHEALTHY'),{
|
|
184
|
-
code:'NEW_RUNTIME_UNHEALTHY',startupResult
|
|
185
|
+
code:'NEW_RUNTIME_UNHEALTHY',startupResult
|
|
185
186
|
});
|
|
186
|
-
//
|
|
187
|
-
//
|
|
187
|
+
// Supervisor startup can outlive the first CLI IPC probe. A temporary
|
|
188
|
+
// MANAGER_UNAVAILABLE is not a failed cutover: observe the candidate,
|
|
189
|
+
// then issue one idempotent start retry only after its own manager is live.
|
|
188
190
|
phase='verify-new';
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
191
|
+
let lastStatus=null,startRetried=false;
|
|
192
|
+
for(let attempt=0;attempt<60;attempt++){
|
|
193
|
+
try{lastStatus=await cli(p.entry,'status');}
|
|
194
|
+
catch(error){lastStatus={status:'UNAVAILABLE',code:error.code||'MANAGER_UNAVAILABLE'};}
|
|
195
|
+
const running=lastStatus.results?.filter(x=>x.enabled)||[];
|
|
196
|
+
const managerReady=Number.isSafeInteger(lastStatus.managerPid);
|
|
197
|
+
if(lastStatus.status==='OK'&&managerReady&&running.length>0&&
|
|
193
198
|
running.every(x=>x.after==='RUNNING')){
|
|
194
|
-
verified=
|
|
199
|
+
verified=lastStatus;break;
|
|
200
|
+
}
|
|
201
|
+
if(lastStatus.status==='OK'&&managerReady&&running.length>0&&
|
|
202
|
+
running.every(x=>x.after==='STOPPED')&&!startRetried){
|
|
203
|
+
startRetried=true;
|
|
204
|
+
const retry=await cli(p.entry,'start',{env:startEnv});
|
|
205
|
+
if(!['OK','STARTING'].includes(retry.status)
|
|
206
|
+
&&retry.error?.code!=='MANAGER_UNAVAILABLE')
|
|
207
|
+
throw Object.assign(Error('NEW_RUNTIME_RETRY_START_FAILED'),{
|
|
208
|
+
code:'NEW_RUNTIME_RETRY_START_FAILED',startupResult:retry,
|
|
209
|
+
candidateStatus:lastStatus
|
|
210
|
+
});
|
|
195
211
|
}
|
|
196
212
|
await new Promise(resolve=>setTimeout(resolve,500));
|
|
197
213
|
}
|
|
198
214
|
if(!verified)
|
|
199
215
|
throw Object.assign(Error('NEW_RUNTIME_HEALTHCHECK_TIMEOUT'),{
|
|
200
|
-
code:'NEW_RUNTIME_HEALTHCHECK_TIMEOUT'
|
|
216
|
+
code:'NEW_RUNTIME_HEALTHCHECK_TIMEOUT',startupResult,
|
|
217
|
+
candidateStatus:lastStatus
|
|
201
218
|
});
|
|
202
219
|
}
|
|
203
220
|
phase='verify-tunnel';
|
|
@@ -206,11 +223,16 @@ export async function upgradeRuntime(options={}){
|
|
|
206
223
|
throw Object.assign(Error('NEW_RUNTIME_TUNNEL_UNHEALTHY'),{
|
|
207
224
|
code:'NEW_RUNTIME_TUNNEL_UNHEALTHY'
|
|
208
225
|
});
|
|
226
|
+
phase='verify-tunnel-connection';
|
|
227
|
+
const tunnelConnection=await verifyTunnelConnection(p,verified,{run,runtimeLaunchEnv});
|
|
228
|
+
phase='verify-mcp';
|
|
229
|
+
const mcp=await verifyMcpTools(p,{runtimeLaunchEnv});
|
|
209
230
|
phase='record-new';
|
|
210
231
|
atomicWrite(p.current,JSON.stringify({version:p.version,entry:p.entry,
|
|
211
232
|
status:'ACTIVE'},null,2)+'\n');
|
|
212
233
|
return freshResult('OK',{outcome:'ACTIVATED',managerPid:verified.managerPid,
|
|
213
|
-
healthyTools:verified.results.filter(x=>x.enabled).map(x=>x.toolId),
|
|
234
|
+
healthyTools:verified.results.filter(x=>x.enabled).map(x=>x.toolId),
|
|
235
|
+
tunnelConnection,mcp,backupDir});
|
|
214
236
|
}catch(e){
|
|
215
237
|
// Never restore or launch a superseded runtime after a failed cutover.
|
|
216
238
|
if(oldWasStopped&&runtime){
|