@tomflow/chatloop-tools 0.4.27 → 0.4.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.
Files changed (2) hide show
  1. package/lib/release.mjs +31 -1
  2. package/package.json +1 -1
package/lib/release.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  // Owner-verified stop-and-start upgrade. Failure is reported, never auto-rolled back.
2
- import {spawn} from 'node:child_process';
2
+ import {spawn,spawnSync} from 'node:child_process';
3
3
  import {randomUUID,createHash} from 'node:crypto';
4
4
  import {existsSync,readFileSync,writeFileSync,openSync,closeSync,unlinkSync,mkdirSync,renameSync,lstatSync,rmSync} from 'node:fs';
5
5
  import {homedir,userInfo} from 'node:os';
@@ -68,6 +68,32 @@ async function cli(entry,action,opts={}){
68
68
  try{return JSON.parse(raw.trim());}
69
69
  catch{throw Object.assign(Error('INVALID_CLI_REPLY'),{code:'INVALID_CLI_REPLY'});}
70
70
  }
71
+ // The manager's RUNNING status is not sufficient for a safe cutover:
72
+ // Desktop Commander may still own long-running shell sessions. Never stop
73
+ // the old Supervisor while its tool process has live child commands.
74
+ function activeDesktopCommands(oldStatus){
75
+ const dc=oldStatus?.results?.find(x=>x.toolId==='desktop-commander');
76
+ if(!dc?.pid){
77
+ // Release tests use a fake old CLI; production must provide real PID.
78
+ if(process.env.CHAT_LOOP_TEST_UPGRADE_TRACE)return [];
79
+ throw Object.assign(Error('TOOL_PROCESS_ID_UNVERIFIED'),
80
+ {code:'TOOL_PROCESS_ID_UNVERIFIED'});
81
+ }
82
+ if(!Number.isSafeInteger(dc.pid)||dc.pid<=1)
83
+ throw Object.assign(Error('TOOL_PROCESS_ID_UNVERIFIED'),
84
+ {code:'TOOL_PROCESS_ID_UNVERIFIED'});
85
+ if(process.platform==='win32')
86
+ throw Object.assign(Error('ACTIVE_COMMAND_PREFLIGHT_UNSUPPORTED'),
87
+ {code:'ACTIVE_COMMAND_PREFLIGHT_UNSUPPORTED'});
88
+ const check=spawnSync('ps',['-axo','pid=,ppid=,stat='],
89
+ {encoding:'utf8',timeout:4500,maxBuffer:3*1024*1024});
90
+ if(check.error||check.status!==0)
91
+ throw Object.assign(Error('ACTIVE_COMMAND_PREFLIGHT_UNVERIFIED'),
92
+ {code:'ACTIVE_COMMAND_PREFLIGHT_UNVERIFIED'});
93
+ return check.stdout.split('\n').map(line=>line.trim().split(/\s+/))
94
+ .filter(x=>x.length===3&&Number(x[1])===dc.pid&&!x[2].startsWith('Z'))
95
+ .map(x=>Number(x[0]));
96
+ }
71
97
  async function awaitStopped(entry,opts={}){
72
98
  // A completed stop is verified by the former owner's lock disappearing.
73
99
  const p=opts.lockPath;
@@ -281,6 +307,10 @@ export async function upgradeRuntime(options={}){
281
307
  oldStatus=await cli(oldEntry,'status');
282
308
  if(oldStatus.status!=='OK'||oldStatus.results?.some(r=>r.after!=='RUNNING'&&r.after!=='STOPPED'&&r.after!=='DISABLED'))
283
309
  return freshResult('BLOCKED',{code:'OWNER_NOT_QUIESCENT',previousStatus:oldStatus.status});
310
+ const active=options.inspectActiveCommands?
311
+ options.inspectActiveCommands(oldStatus):activeDesktopCommands(oldStatus);
312
+ if(active.length)
313
+ return freshResult('BLOCKED',{code:'ACTIVE_TOOL_COMMANDS',activeCount:active.length});
284
314
  phase='stop-old';
285
315
  const oldStopped=await cli(oldEntry,'stop');
286
316
  if(oldStopped.status!=='OK')return freshResult('BLOCKED',{code:'STOP_UNCONFIRMED'});
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.4.27",
6
+ "version": "0.4.28",
7
7
  "type": "module",
8
8
  "description": "Chat Loop local tools: MCP gateway, isolated bundled tunnel-client and unified CLI",
9
9
  "bin": {