webhelm 1.0.44 → 1.0.45

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
@@ -58,7 +58,12 @@ new daemon against the existing Chrome/profile/queue, and verifies its version.
58
58
  A busy daemon returns `deferred` and retries on the next scheduled run. A failed
59
59
  installation reverts the pointer and resumes the old queue. Unavailable npm or
60
60
  unrecognized old daemon upgrade protocols fail closed rather than killing a
61
- Session. The update log is at `~/.config/webhelm/runtime/auto-update.log`.
61
+ Session. For a one-time manual migration, `webhelm upgrade --force` verifies
62
+ the daemon PID/lock and sends SIGTERM before starting the new Runtime.
63
+ This bypasses idle checks and may interrupt active Sessions or running queue
64
+ workers; it does not deliberately restart Chrome. The scheduled updater
65
+ never uses `--force`. The update log is at
66
+ `~/.config/webhelm/runtime/auto-update.log`.
62
67
 
63
68
  Neo Master uses `WEBHELM_SOURCE_MODE=1` and runs its linked Git checkout, not
64
69
  a published npm package. Automatic npm updates are deliberately disabled
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webhelm",
3
- "version": "1.0.44",
3
+ "version": "1.0.45",
4
4
  "description": "Agent browser automation in a visible managed Chrome with persistent JavaScript sessions",
5
5
  "type": "module",
6
6
  "bin": {
@@ -77,12 +77,39 @@ function acquireLock(home) {
77
77
  return null;
78
78
  }
79
79
 
80
+ // Explicit --force only. Verify the PID against the local daemon lock and
81
+ // live IPC identity before sending SIGTERM. Never signal managed Chrome.
82
+ export async function forceStopDaemon(daemon,{home=os.homedir(),ipc=req=>request(req,false),
83
+ lockPath=process.env.WEBHELM_LOCK||path.join(home,'.config/webhelm/runtime/session-node.lock'),
84
+ signal=process.kill,inspect=pid=>execFileSync('ps',['-p',String(pid),'-o','command='],
85
+ {encoding:'utf8',timeout:5000}),timeoutMs=30000}={}) {
86
+ const pid=daemon?.pid;
87
+ if(!Number.isSafeInteger(pid)||pid<=1||pid===process.pid)
88
+ throw Error('Refusing forced upgrade: invalid daemon PID');
89
+ const owner=Number(fs.readFileSync(lockPath,'utf8').trim());
90
+ if(owner!==pid)throw Error('Refusing forced upgrade: daemon lock PID mismatch');
91
+ const command=await inspect(pid);
92
+ if(!/node-daemon\.mjs\s+daemon(?:\s|$)/.test(command))
93
+ throw Error('Refusing forced upgrade: PID is not a WebHelm daemon');
94
+ const live=await ipc({op:'ping'});
95
+ if(live?.pid!==pid||live.version!==daemon.version)
96
+ throw Error('Refusing forced upgrade: daemon identity changed');
97
+ signal(pid,'SIGTERM');
98
+ const deadline=Date.now()+timeoutMs;
99
+ while(Date.now()<deadline){
100
+ // Lock removal follows shutdown cleanup, including queue worker teardown.
101
+ if(!fs.existsSync(lockPath))return {stopping:true,stopped:true,pid};
102
+ await sleep(100);
103
+ }
104
+ return {stopping:true,stopped:false,pid};
105
+ }
106
+
80
107
  // Inject ports for isolated tests. Production never imports npm code or
81
108
  // touches another Chrome profile to decide whether to upgrade.
82
109
  export async function upgradeRuntime({home=os.homedir(),source=SOURCE,nodePath=process.execPath,
83
110
  latest=npmLatest,download=downloadRuntime,ipc=req=>request(req,false),
84
111
  installGuard=installLoginGuard,installPoller=installRuntimeUpdate,
85
- activate=activateRuntime,verify=null,apply=true}={}) {
112
+ activate=activateRuntime,verify=null,restart=forceStopDaemon,apply=true,force=false}={}) {
86
113
  if(process.env.WEBHELM_SOURCE_MODE==='1')return {status:'source_checkout',upgraded:false};
87
114
  const unlock=acquireLock(home);
88
115
  if(!unlock)return {status:'already_running',upgraded:false};
@@ -100,11 +127,11 @@ export async function upgradeRuntime({home=os.homedir(),source=SOURCE,nodePath=p
100
127
  const upToDate=daemon?.version===target && currentTarget &&
101
128
  fs.existsSync(path.join(currentTarget,'package.json')) &&
102
129
  JSON.parse(fs.readFileSync(path.join(currentTarget,'package.json'),'utf8')).version===target;
103
- if(upToDate)return {status:'current',upgraded:false,version:target,global_cli:migrateLegacyRuntimeCli({home})};
130
+ if(upToDate&&!force)return {status:'current',upgraded:false,version:target,global_cli:migrateLegacyRuntimeCli({home})};
104
131
  // Stage before requesting the daemon to drain; download may take time.
105
132
  const staged=compareVersions(target,local)>0
106
133
  ? await download(target,{home}) : stageRuntimeForLoginGuard({home,source});
107
- if(daemon && compareVersions(daemon.version,target)<0){
134
+ if(!force && daemon && compareVersions(daemon.version,target)<0){
108
135
  let gate;
109
136
  try{gate=await ipc({op:'upgrade-prepare'});}
110
137
  catch(error){return {status:'deferred',upgraded:false,reason:'daemon_upgrade_protocol_unavailable',detail:error.message,latest:target};}
@@ -119,7 +146,14 @@ export async function upgradeRuntime({home=os.homedir(),source=SOURCE,nodePath=p
119
146
  const poller=installPoller({home,cliPath,nodePath,apply});
120
147
  if(['staged_not_loaded','skipped'].includes(guard.status)||
121
148
  ['staged_not_loaded','skipped'].includes(poller.status))throw Error('Runtime LaunchAgent activation failed');
122
- if(prepared){
149
+ if(force && daemon){
150
+ const stopped=await restart(daemon,{home,ipc});
151
+ if(!stopped?.stopping)throw Error('Forced daemon restart was not accepted');
152
+ committed=true;
153
+ if(!stopped.stopped)return {status:'deferred',upgraded:false,
154
+ reason:'daemon_shutdown_timeout',daemon_pid:daemon.pid,latest:target,
155
+ forced:true,warning:'SIGTERM sent; runtime pointer updated but daemon has not completed shutdown'};
156
+ }else if(prepared){
123
157
  const result=await ipc({op:'upgrade-commit'});
124
158
  if(!result?.stopping)throw Error('Daemon did not accept Runtime cutover');
125
159
  prepared=false;committed=true;
@@ -137,7 +171,8 @@ export async function upgradeRuntime({home=os.homedir(),source=SOURCE,nodePath=p
137
171
  const state=await run();
138
172
  if(state.version!==target)throw Error(`Cutover verification failed: ${state.version} !== ${target}`);
139
173
  return {status:'upgraded',upgraded:true,from:daemon?.version||null,to:target,
140
- daemon_pid:state.daemon?.pid||null,global_cli,guard:guard.status,auto_update:poller.status};
174
+ daemon_pid:state.daemon?.pid||null,global_cli,guard:guard.status,auto_update:poller.status,
175
+ ...(force?{forced:true,sessions_before_restart:daemon?.session_count??null}:{})};
141
176
  }catch(error){
142
177
  // Never point new clients at an old Runtime after a committed daemon
143
178
  // cutover: the new daemon may already be serving requests.
@@ -13,7 +13,7 @@ Commands:
13
13
  webhelm setup Set up managed Chrome and local Actions
14
14
  webhelm status Report browser and daemon status (JSON)
15
15
  webhelm ensure Check and recover managed Chrome health
16
- webhelm upgrade Check npm and safely upgrade the Runtime
16
+ webhelm upgrade [--force] Check npm and upgrade the Runtime
17
17
  webhelm capacity Report available browser capacity (JSON)
18
18
  webhelm session start [--url URL] Start a persistent browser Session
19
19
  webhelm session list List CLI-owned Sessions
@@ -56,7 +56,7 @@ Output: JSON with status, Actions checkout path, daemon and browser details.
56
56
 
57
57
  Example:
58
58
  webhelm setup`,
59
- upgrade: `webhelm upgrade — update the npm Runtime when safely idle\n\nUsage:\n webhelm upgrade\n\nChecks npm once. Stages newer Runtime without executing install scripts.\nCutover waits until all Sessions and in-flight queue workers are idle;\notherwise reports deferred and retries on the next hourly LaunchAgent run.\nNever updates a source-mode checkout or restarts managed Chrome.\n\nOutput: JSON current, upgraded, deferred, or source_checkout.`,
59
+ upgrade: `webhelm upgrade — update the npm Runtime when safely idle\n\nUsage:\n webhelm upgrade [--force]\n\nChecks npm once. Stages newer Runtime without executing install scripts.\nCutover waits until all Sessions and in-flight queue workers are idle;\notherwise reports deferred and retries on the next hourly LaunchAgent run.\nOld daemons without the upgrade protocol defer safely.\n--force bypasses idle checks and sends SIGTERM to the verified WebHelm\ndaemon (including legacy versions), which is then restarted.\nActive Sessions and in-flight queue work may be interrupted.\nThe hourly updater never uses --force.\nNever updates a source-mode checkout or deliberately restarts Chrome.\n\nOutput: JSON current, upgraded, deferred, or source_checkout.`,
60
60
  status: `webhelm status — inspect managed browser and daemon
61
61
 
62
62
  Usage:
package/runtime/cli.mjs CHANGED
@@ -118,7 +118,11 @@ async function main(args = process.argv.slice(2)) {
118
118
  const auto_update=installRuntimeUpdate({cliPath,nodePath:process.execPath,sourceMode});
119
119
  return emit({status:'ready',...repo,daemon_pid:chrome.pid,managed_chrome:chrome.managed_chrome,global_cli,login_guard,auto_update});
120
120
  }
121
- if (group === 'upgrade') return emit(await upgradeRuntime());
121
+ if (group === 'upgrade') {
122
+ if(args.some(value=>value!=='upgrade'&&value!=='--force'))
123
+ throw Error('upgrade supports only --force');
124
+ return emit(await upgradeRuntime({force:has(args,'--force')}));
125
+ }
122
126
  if (group === 'ensure') {
123
127
  try { return emit(await request({op:'guard-check'})); }
124
128
  catch(error) {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "manifest_version": 3,
3
3
  "name": "WebHelm",
4
- "version": "1.0.44",
4
+ "version": "1.0.45",
5
5
  "description": "Own named Chrome tab-group workspaces and lazy reusable tab pools for browser agents.",
6
6
  "permissions": [
7
7
  "storage",